Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 4 additions & 20 deletions packages/super-editor/src/components/toolbar/Toolbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { undoDepth, redoDepth } from 'prosemirror-history';
const props = defineProps({
editorInstance: {
type: Object,
required: true,
required: false,
},
updateTransaction: {
type: Object,
Expand Down Expand Up @@ -332,7 +332,8 @@ const alignment = makeToolbarItem({
markName: 'textAlign',
labelAttr: 'textAlign',
getIcon(self) {
const attrs = self.editor.getAttributes('paragraph').textAlign;
let attrs = self.editor?.getAttributes('paragraph').textAlign;
if (!attrs) attrs = 'left';
return `fa-align-${attrs}`;
},
onTextMarkSelection(self, mark) {
Expand Down Expand Up @@ -570,8 +571,8 @@ const toolbarItems = ref([
alignment,
bulletedList,
numberedList,
indentRight,
indentLeft,
indentRight,
separator,
search,
overflow,
Expand Down Expand Up @@ -762,23 +763,6 @@ defineExpose({
<template>
<div class="toolbar">

<!-- TODO: delete this (examples of how to handle active state)-->
<div
style="display: none;"
:class="{
'is-bold-active': editorInstance.isActive('bold'),
'is-italic-active': editorInstance.isActive('italic'),
'is-undeline-active': editorInstance.isActive('underline'),
'is-arial-font-active': editorInstance.isActive('textStyle', { fontFamily: 'Arial, sans-serif' }),
'is-purple-color-active': editorInstance.isActive('textStyle', { color: 'purple' }),
'is-orange-color-active': editorInstance.getAttributes('textStyle').color === 'orange',
'is-bullet-list-active': editorInstance.isActive('bulletList'),
'is-center-align': editorInstance.isActive({ textAlign: 'center' }),
}"
:data-current-color="editorInstance.getAttributes('textStyle').color"
:data-current-font-size="editorInstance.getAttributes('textStyle').fontSize">
</div>

<div v-for="item, index in toolbarItems"
:key="index"
:class="{
Expand Down
8 changes: 2 additions & 6 deletions packages/super-editor/src/components/toolbar/ToolbarItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ export class ToolbarItem {
throw new Error('Invalid toolbar item name - ' + options.name);
}

if (!options.editor) {
throw new Error('Invalid toolbar item editor - ' + options.editor);
}

this.type = options.type
this.name = options.name
this.editor = options.editor
Expand Down Expand Up @@ -94,11 +90,11 @@ export class ToolbarItem {

// handlers
_getActiveState() {
return this.editor.isActive(this.name)
return this.editor?.isActive(this.name)
}
_getAttr(attr) {
if (!this.markName || !attr) return null;
return this.editor.getAttributes(this.markName)[attr];
return this.editor?.getAttributes(this.markName)[attr];
}
_getLabel() {
return this._getAttr(this.labelAttr) || this.defaultLabel;
Expand Down
2 changes: 1 addition & 1 deletion packages/superdoc/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@harbour-enterprises/superdoc",
"type": "module",
"version": "1.0.0-alpha.35",
"version": "1.0.0-alpha.36",
"files": [
"dist"
],
Expand Down
16 changes: 11 additions & 5 deletions packages/superdoc/src/Superdoc.vue
Original file line number Diff line number Diff line change
Expand Up @@ -171,16 +171,22 @@ const onCreate = ({ editor }) => {
console.debug('[Superdoc] Page styles (pixels)', editor.getPageStyles());
proxy.$superdoc.broadcastLoaded();
}

const onFocus = ({ editor }) => {
proxy.$superdoc.activeEditor = editor;
proxy.$superdoc.addToolbar(proxy.$superdoc);
}
const onSelectionUpdate = ({ editor, transaction }) => {
const { selection } = editor.view.state;
const marks = selection.$head.marks();
proxy.$superdoc.toolbar.onTextSelectionChange(marks);
proxy.$superdoc.onSelectionUpdate({ editor, transaction });
// const { selection } = editor.view.state;
// const marks = selection.$head.marks();
// proxy.$superdoc.toolbar.onTextSelectionChange(marks);
// proxy.$superdoc.onSelectionUpdate({ editor, transaction });
}

const editorOptions = {
onCreate,
onSelectionUpdate
// onSelectionUpdate,
onFocus
}

</script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import 'super-editor/style.css';
import { getCurrentInstance, ref, onMounted } from 'vue';
import { Toolbar } from 'super-editor';
import { watch } from 'vue';

const { proxy } = getCurrentInstance();
const toolbar = ref(null);
Expand All @@ -11,15 +12,11 @@ const handleToolbarCommand = (command) => {
proxy.$superdoc.onToolbarCommand(command);
}

onMounted(() => {
// This sets $superdoc.toolbar to the Toolbar component from super-editor
proxy.$superdoc.setToolbar(toolbar.value);
})
</script>

<template>
<div>
<Toolbar class="toolbar" @command="handleToolbarCommand" ref="toolbar"/>
<div ref="toolbar">
<Toolbar class="toolbar" :editorInstance="$superdoc.activeEditor" @command="handleToolbarCommand" />
</div>
</template>

Expand Down
13 changes: 0 additions & 13 deletions packages/superdoc/src/dev/SuperdocDev.vue
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,6 @@ const initializeApp = async () => {
}
}
superdoc = new Superdoc(config);
superdoc.on('selection-update', ({ editor, transaction }) => {
console.debug('[Superdoc] Selection update', editor, transaction);
activeEditor = editor;
});
}

const handleToolbarCommand = (command) => {
console.debug('[SuperEditor dev] Toolbar command', command, activeEditor?.commands);
const commands = activeEditor?.commands;
if (!!commands && command in commands){
activeEditor?.commands[command]();
}
}

onMounted(() => {
initializeApp();
Expand Down
11 changes: 7 additions & 4 deletions packages/superdoc/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,19 @@ class Superdoc extends EventEmitter {
this.emit('selection-update', { editor, transaction });
}

setToolbar(component) {
this.toolbar = component;
}

addToolbar(instance) {
if (!this.toolbarElement) return;

if (this.toolbar) {
console.debug('[superdoc] Unmounting existing toolbar');
this.toolbar.unmount();
}

const el = document.getElementById(this.toolbarElement);
if (!el) return;

const app = createApp(SuperToolbar);
this.toolbar = app;
app.config.globalProperties.$superdoc = instance;
app.mount(el);
}
Expand Down