Skip to content

Commit 636b9c9

Browse files
authored
Merge pull request #301 from codex-team/feat/inline-toolbar
feat: inline-toolbar
2 parents c39437a + 4c58f30 commit 636b9c9

File tree

3 files changed

+26
-7
lines changed

3 files changed

+26
-7
lines changed

codex-ui/dev/pages/components/Editor.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
class: Header as any,
2929
config: {
3030
placeholder: 'Heading',
31-
inlineToolbar: true,
3231
},
32+
inlineToolbar: true,
3333
},
3434
list: {
3535
class: NestedList,
@@ -40,6 +40,7 @@
4040
placeholder="Write something or press / to select a tool"
4141
first-block-placeholder="Untitled"
4242
autofocus
43+
:inlineToolbar="true"
4344
/>
4445
</template>
4546

codex-ui/src/vue/components/editor/Editor.vue

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ const props = defineProps<{
4848
* Should the editor be focused on load
4949
*/
5050
autofocus?: boolean;
51+
52+
/**
53+
* Common Inline Toolbar settings
54+
* - if true (or not specified), the order from 'tool' property will be used (default)
55+
* - if an array of tool names, this order will be used
56+
*/
57+
inlineToolbar?: boolean;
5158
}>();
5259
5360
const emit = defineEmits<{
@@ -62,6 +69,7 @@ const editorConfig = computed<EditorConfig>(() => {
6269
tools: props.tools,
6370
placeholder: props.placeholder,
6471
autofocus: props.autofocus,
72+
inlineToolbar: props.inlineToolbar,
6573
};
6674
});
6775

src/application/services/useNoteEditor.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,13 @@ export const useNoteEditor = function useNoteEditor(options: UseNoteEditorOption
6868
* Loaded tools classes by grouped by tool.name
6969
* Undefined when tools are not loaded yet
7070
*/
71-
let toolsClasses: Record<string, EditorjsConfigTool> | undefined = undefined;
71+
let toolsUserConfig: Record<string, { class: EditorjsConfigTool; inlineToolbar: boolean }> | undefined = undefined;
7272

7373
/**
74-
* We can't make toolsClasses reactive since it contains excecutable js-classes, Vue can't handle that.
74+
* We can't make toolsUserConfig reactive since it contains excecutable js-classes, Vue can't handle that.
7575
* So we store reactive flag to indicate that tools are loaded
7676
*/
77-
const toolsClassesLoaded = ref<boolean>(false);
77+
const toolsUserConfigLoaded = ref<boolean>(false);
7878

7979
/**
8080
* Combine note and user tools
@@ -114,8 +114,17 @@ export const useNoteEditor = function useNoteEditor(options: UseNoteEditorOption
114114
*/
115115
const loadedToolsWithoutParagraph = loadedTools.filter(tool => tool.tool.name !== 'paragraph');
116116

117-
toolsClasses = Object.fromEntries(loadedToolsWithoutParagraph.map(toolClassAndInfo => [toolClassAndInfo.tool.name, toolClassAndInfo.class]));
118-
toolsClassesLoaded.value = true;
117+
toolsUserConfig = Object.fromEntries(
118+
loadedToolsWithoutParagraph
119+
.map(toolClassAndInfo => [
120+
toolClassAndInfo.tool.name,
121+
{
122+
class: toolClassAndInfo.class,
123+
inlineToolbar: true,
124+
},
125+
])
126+
);
127+
toolsUserConfigLoaded.value = true;
119128

120129
/**
121130
* Now all tools are loaded, we're ready to use the editor
@@ -148,8 +157,9 @@ export const useNoteEditor = function useNoteEditor(options: UseNoteEditorOption
148157
holderId: 'editorjs',
149158
data: options.noteContentResolver(),
150159
readOnly: toValue(options.canEdit) === false,
151-
tools: toolsClassesLoaded.value ? toolsClasses : undefined,
160+
tools: toolsUserConfigLoaded.value ? toolsUserConfig : undefined,
152161
placeholder: t('note.editor.placeholder'),
162+
inlineToolbar: true,
153163
};
154164
});
155165

0 commit comments

Comments
 (0)