2021-03-25 21:11:40 +01:00
|
|
|
import type { SvelteComponent } from "svelte";
|
2021-04-01 02:26:56 +02:00
|
|
|
import { writable } from "svelte/store";
|
2021-03-30 06:14:00 +02:00
|
|
|
|
2021-03-25 21:11:40 +01:00
|
|
|
import EditorToolbarSvelte from "./EditorToolbar.svelte";
|
|
|
|
|
2021-04-01 02:26:56 +02:00
|
|
|
import { checkNightMode } from "anki/nightmode";
|
|
|
|
import { setupI18n, ModuleName } from "anki/i18n";
|
2021-03-30 06:14:00 +02:00
|
|
|
|
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 02:26:56 +02:00
|
|
|
// @ts-ignore
|
|
|
|
export { updateActiveButtons, clearActiveButtons } from "./CommandIconButton.svelte";
|
|
|
|
|
2021-04-01 00:45:02 +02:00
|
|
|
const defaultButtons = [notetypeButtons, formatButtons, colorButtons, templateButtons];
|
2021-04-01 02:18:04 +02:00
|
|
|
const defaultMenus = [...templateMenus];
|
2021-03-30 01:23:39 +02:00
|
|
|
|
2021-03-25 21:11:40 +01:00
|
|
|
class EditorToolbar extends HTMLElement {
|
|
|
|
component?: SvelteComponent;
|
|
|
|
|
2021-04-01 02:18:04 +02:00
|
|
|
buttons = defaultButtons;
|
|
|
|
menus = defaultMenus;
|
|
|
|
disabled? = writable(false);
|
2021-03-30 06:14:00 +02:00
|
|
|
|
2021-04-01 02:18:04 +02:00
|
|
|
connectedCallback(): void {
|
2021-03-31 22:05:24 +02:00
|
|
|
setupI18n({ modules: [ModuleName.EDITING] }).then(() => {
|
|
|
|
this.component = new EditorToolbarSvelte({
|
|
|
|
target: this,
|
|
|
|
props: {
|
2021-04-01 02:18:04 +02:00
|
|
|
buttons: this.buttons,
|
|
|
|
menus: this.menus,
|
2021-03-31 22:05:24 +02:00
|
|
|
disabled: this.disabled,
|
2021-04-01 02:18:04 +02:00
|
|
|
nightMode: checkNightMode(),
|
2021-03-31 22:05:24 +02:00
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
2021-03-30 06:14:00 +02:00
|
|
|
}
|
|
|
|
|
2021-04-01 02:18:04 +02:00
|
|
|
update(): void {
|
|
|
|
this.component?.$set({
|
|
|
|
button: this.buttons,
|
|
|
|
menus: this.menus,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
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);
|
2021-04-01 02:26:56 +02:00
|
|
|
|
|
|
|
/* Exports for add-ons */
|
|
|
|
export { default as LabelButton } from "./LabelButton.svelte";
|
|
|
|
export { default as IconButton } from "./IconButton.svelte";
|
|
|
|
export { default as CommandIconButton } from "./CommandIconButton.svelte";
|
|
|
|
export { default as SelectButton } from "./SelectButton.svelte";
|
|
|
|
|
|
|
|
export { default as DropdownMenu } from "./DropdownMenu.svelte";
|
|
|
|
export { default as DropdownItem } from "./DropdownItem.svelte";
|
|
|
|
export { default as WithDropdownMenu } from "./WithDropdownMenu.svelte";
|