mirror of
https://github.com/ankitects/anki.git
synced 2025-09-22 07:52:24 -04:00
Move toolbar initialization into toolbar.ts
This commit is contained in:
parent
37ea39f779
commit
731f9d109f
3 changed files with 47 additions and 29 deletions
4
ts/editor-toolbar/editorToolbar.d.ts
vendored
4
ts/editor-toolbar/editorToolbar.d.ts
vendored
|
@ -1,5 +1,5 @@
|
||||||
import type { EditorToolbar } from ".";
|
import type { EditorToolbar } from ".";
|
||||||
|
|
||||||
declare global {
|
declare namespace globalThis {
|
||||||
var $editorToolbar: EditorToolbar;
|
const $editorToolbar: EditorToolbar;
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@ import { EditorField } from "./editorField";
|
||||||
import { LabelContainer } from "./labelContainer";
|
import { LabelContainer } from "./labelContainer";
|
||||||
import { EditingArea } from "./editingArea";
|
import { EditingArea } from "./editingArea";
|
||||||
import { Editable } from "./editable";
|
import { Editable } from "./editable";
|
||||||
|
import { initToolbar } from "./toolbar";
|
||||||
|
|
||||||
export { setNoteId, getNoteId } from "./noteId";
|
export { setNoteId, getNoteId } from "./noteId";
|
||||||
export { saveNow } from "./changeTimer";
|
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] });
|
const i18n = setupI18n({ modules: [ModuleName.EDITING] });
|
||||||
|
|
||||||
document.addEventListener("DOMContentLoaded", () => {
|
initToolbar(i18n);
|
||||||
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;
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
43
ts/editor/toolbar.ts
Normal file
43
ts/editor/toolbar.ts
Normal file
|
@ -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>): void {
|
||||||
|
document.addEventListener("DOMContentLoaded", () => {
|
||||||
|
i18n.then(() => {
|
||||||
|
globalThis.$editorToolbar.buttonsPromise.then(
|
||||||
|
(
|
||||||
|
buttons: Writable<
|
||||||
|
(ToolbarItem<typeof ButtonGroup> & ButtonGroupProps)[]
|
||||||
|
>
|
||||||
|
): Writable<(ToolbarItem<typeof ButtonGroup> & ButtonGroupProps)[]> => {
|
||||||
|
buttons.update(() => [
|
||||||
|
getNotetypeGroup(),
|
||||||
|
getFormatInlineGroup(),
|
||||||
|
getFormatBlockGroup(),
|
||||||
|
getColorGroup(),
|
||||||
|
getTemplateGroup(),
|
||||||
|
]);
|
||||||
|
return buttons;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
globalThis.$editorToolbar.menusPromise.then(
|
||||||
|
(menus: Writable<ToolbarItem[]>): Writable<ToolbarItem[]> => {
|
||||||
|
menus.update(() => [
|
||||||
|
...getFormatBlockMenus(),
|
||||||
|
...getTemplateMenus(),
|
||||||
|
]);
|
||||||
|
return menus;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
Loading…
Reference in a new issue