2021-03-25 21:11:40 +01:00
|
|
|
import type { SvelteComponent } from "svelte";
|
2021-03-30 06:14:00 +02:00
|
|
|
|
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-30 06:14:00 +02:00
|
|
|
|
2021-03-25 21:11:40 +01:00
|
|
|
import EditorToolbarSvelte from "./EditorToolbar.svelte";
|
|
|
|
|
2021-03-30 06:14:00 +02:00
|
|
|
// @ts-ignore
|
|
|
|
export { updateActiveButtons, clearActiveButtons } from "./CommandIconButton.svelte";
|
|
|
|
import { Writable, writable } from "svelte/store";
|
|
|
|
|
2021-04-01 00:45:02 +02:00
|
|
|
import { notetypeButtons } from "./notetype";
|
|
|
|
import { formatButtons } from "./format";
|
|
|
|
import { colorButtons } from "./color";
|
|
|
|
import { templateButtons, templateMenus } from "./template";
|
2021-03-30 01:23:39 +02:00
|
|
|
|
2021-04-01 00:45:02 +02:00
|
|
|
const defaultMenus = [...templateMenus];
|
2021-03-31 03:34:08 +02:00
|
|
|
|
2021-04-01 00:45:02 +02:00
|
|
|
const defaultButtons = [notetypeButtons, formatButtons, colorButtons, templateButtons];
|
2021-03-30 01:23:39 +02:00
|
|
|
|
2021-03-25 21:11:40 +01:00
|
|
|
class EditorToolbar extends HTMLElement {
|
|
|
|
component?: SvelteComponent;
|
2021-03-30 06:14:00 +02:00
|
|
|
disabled?: Writable<boolean>;
|
2021-03-25 21:11:40 +01:00
|
|
|
|
2021-03-25 23:32:23 +01:00
|
|
|
connectedCallback(): void {
|
2021-03-30 06:14:00 +02:00
|
|
|
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,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
2021-03-30 06:14:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|