anki/ts/editor/toolbar.ts
2021-04-25 19:15:00 +02:00

37 lines
1.2 KiB
TypeScript

// Copyright: Ankitects Pty Ltd and contributors
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import { editorToolbar, EditorToolbar } from "editor-toolbar";
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>) {
let toolbarResolve: (value: EditorToolbar) => void;
const toolbarPromise = new Promise<EditorToolbar>((resolve) => {
toolbarResolve = resolve;
});
document.addEventListener("DOMContentLoaded", () => {
i18n.then(() => {
const target = document.getElementById("editorToolbar")!;
const buttons = [
getNotetypeGroup(),
getFormatInlineGroup(),
getFormatBlockGroup(),
getColorGroup(),
getTemplateGroup(),
];
const menus = [...getFormatBlockMenus(), ...getTemplateMenus()];
toolbarResolve(editorToolbar(target, buttons, menus));
});
});
return toolbarPromise;
}