diff --git a/ts/editor-toolbar/editorToolbar.d.ts b/ts/editor-toolbar/editorToolbar.d.ts index d26bebd5e..4fd9afb11 100644 --- a/ts/editor-toolbar/editorToolbar.d.ts +++ b/ts/editor-toolbar/editorToolbar.d.ts @@ -1,5 +1,5 @@ import type { EditorToolbar } from "."; -declare global { - var $editorToolbar: EditorToolbar; +declare namespace globalThis { + const $editorToolbar: EditorToolbar; } diff --git a/ts/editor/index.ts b/ts/editor/index.ts index b08025a39..a08fcbc3c 100644 --- a/ts/editor/index.ts +++ b/ts/editor/index.ts @@ -14,6 +14,7 @@ import { EditorField } from "./editorField"; import { LabelContainer } from "./labelContainer"; import { EditingArea } from "./editingArea"; import { Editable } from "./editable"; +import { initToolbar } from "./toolbar"; export { setNoteId, getNoteId } from "./noteId"; export { saveNow } from "./changeTimer"; @@ -167,32 +168,6 @@ export function setFormat(cmd: string, arg?: any, nosave: boolean = false): void } } -////////// EDITOR TOOLBAR - -import { getNotetypeGroup } from "./notetype"; -import { getFormatInlineGroup } from "./formatInline"; -import { getFormatBlockGroup, getFormatBlockMenus } from "./formatBlock"; -import { getColorGroup } from "./color"; -import { getTemplateGroup, getTemplateMenus } from "./template"; - const i18n = setupI18n({ modules: [ModuleName.EDITING] }); -document.addEventListener("DOMContentLoaded", () => { - i18n.then(() => { - $editorToolbar.buttonsPromise.then((buttons) => { - buttons.update(() => [ - getNotetypeGroup(), - getFormatInlineGroup(), - getFormatBlockGroup(), - getColorGroup(), - getTemplateGroup(), - ]); - return buttons; - }); - - $editorToolbar.menusPromise.then((menus) => { - menus.update(() => [...getFormatBlockMenus(), ...getTemplateMenus()]); - return menus; - }); - }); -}); +initToolbar(i18n); diff --git a/ts/editor/toolbar.ts b/ts/editor/toolbar.ts new file mode 100644 index 000000000..e2eaca08e --- /dev/null +++ b/ts/editor/toolbar.ts @@ -0,0 +1,43 @@ +import type { ToolbarItem } from "editor-toolbar/types"; +import type ButtonGroup from "editor-toolbar/ButtonGroup.svelte"; +import type { ButtonGroupProps } from "editor-toolbar/ButtonGroup"; +import type { Writable } from "svelte/store"; + +import { getNotetypeGroup } from "./notetype"; +import { getFormatInlineGroup } from "./formatInline"; +import { getFormatBlockGroup, getFormatBlockMenus } from "./formatBlock"; +import { getColorGroup } from "./color"; +import { getTemplateGroup, getTemplateMenus } from "./template"; + +export function initToolbar(i18n: Promise): void { + document.addEventListener("DOMContentLoaded", () => { + i18n.then(() => { + globalThis.$editorToolbar.buttonsPromise.then( + ( + buttons: Writable< + (ToolbarItem & ButtonGroupProps)[] + > + ): Writable<(ToolbarItem & ButtonGroupProps)[]> => { + buttons.update(() => [ + getNotetypeGroup(), + getFormatInlineGroup(), + getFormatBlockGroup(), + getColorGroup(), + getTemplateGroup(), + ]); + return buttons; + } + ); + + globalThis.$editorToolbar.menusPromise.then( + (menus: Writable): Writable => { + menus.update(() => [ + ...getFormatBlockMenus(), + ...getTemplateMenus(), + ]); + return menus; + } + ); + }); + }); +}