anki/ts/editor-toolbar/index.ts

58 lines
1.6 KiB
TypeScript
Raw Normal View History

2021-03-25 21:11:40 +01:00
import type { SvelteComponent } from "svelte";
2021-03-25 21:11:40 +01:00
import { checkNightMode } from "anki/nightmode";
import { setupI18n, ModuleName } from "anki/i18n";
2021-03-25 21:11:40 +01:00
import EditorToolbarSvelte from "./EditorToolbar.svelte";
// @ts-ignore
export { updateActiveButtons, clearActiveButtons } from "./CommandIconButton.svelte";
import { writable } from "svelte/store";
import { notetypeButtons } from "./notetype";
import { formatButtons } from "./format";
import { colorButtons } from "./color";
import { templateButtons, templateMenus } from "./template";
const defaultButtons = [notetypeButtons, formatButtons, colorButtons, templateButtons];
const defaultMenus = [...templateMenus];
2021-03-25 21:11:40 +01:00
class EditorToolbar extends HTMLElement {
component?: SvelteComponent;
buttons = defaultButtons;
menus = defaultMenus;
disabled? = writable(false);
connectedCallback(): void {
2021-03-31 22:05:24 +02:00
setupI18n({ modules: [ModuleName.EDITING] }).then(() => {
this.component = new EditorToolbarSvelte({
target: this,
props: {
buttons: this.buttons,
menus: this.menus,
2021-03-31 22:05:24 +02:00
disabled: this.disabled,
nightMode: checkNightMode(),
2021-03-31 22:05:24 +02:00
},
});
});
}
update(): void {
this.component?.$set({
button: this.buttons,
menus: this.menus,
});
}
enableButtons(): void {
this.disabled?.set(false);
}
disableButtons(): void {
this.disabled?.set(true);
2021-03-25 21:11:40 +01:00
}
}
customElements.define("anki-editor-toolbar", EditorToolbar);