anki/ts/editor-toolbar/index.ts

54 lines
1.5 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";
2021-03-31 22:05:24 +02:00
import { setupI18n, ModuleName, i18n } from "anki/i18n";
import * as tr 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, writable } from "svelte/store";
import { notetypeButtons } from "./notetype";
import { formatButtons } from "./format";
import { colorButtons } from "./color";
import { templateButtons, templateMenus } from "./template";
const defaultMenus = [...templateMenus];
2021-03-31 03:34:08 +02:00
const defaultButtons = [notetypeButtons, formatButtons, colorButtons, templateButtons];
2021-03-25 21:11:40 +01:00
class EditorToolbar extends HTMLElement {
component?: SvelteComponent;
disabled?: Writable<boolean>;
2021-03-25 21:11:40 +01:00
2021-03-25 23:32:23 +01:00
connectedCallback(): void {
this.disabled = writable(false);
2021-03-31 22:05:24 +02:00
setupI18n({ modules: [ModuleName.EDITING] }).then(() => {
console.log(i18n, tr);
this.component = new EditorToolbarSvelte({
target: this,
props: {
menus: defaultMenus,
buttons: defaultButtons,
nightMode: checkNightMode(),
disabled: this.disabled,
},
});
});
}
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);