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-08 18:28:43 +02:00
|
|
|
import { notetypeGroup } from "./notetype";
|
|
|
|
import { formatGroup } from "./format";
|
|
|
|
import { colorGroup } from "./color";
|
|
|
|
import { templateGroup, templateMenus } from "./template";
|
2021-03-30 01:23:39 +02:00
|
|
|
|
2021-04-07 23:53:09 +02:00
|
|
|
// @ts-expect-error
|
2021-04-01 02:26:56 +02:00
|
|
|
export { updateActiveButtons, clearActiveButtons } from "./CommandIconButton.svelte";
|
2021-04-07 23:53:09 +02:00
|
|
|
export { enableButtons, disableButtons } from "./EditorToolbar.svelte";
|
2021-04-01 02:26:56 +02:00
|
|
|
|
2021-04-08 18:28:43 +02:00
|
|
|
const defaultButtons = [notetypeGroup, formatGroup, colorGroup, templateGroup];
|
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 18:36:03 +02:00
|
|
|
buttons = writable(defaultButtons);
|
|
|
|
menus = writable(defaultMenus);
|
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,
|
|
|
|
nightMode: checkNightMode(),
|
2021-03-31 22:05:24 +02:00
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
2021-03-30 06:14:00 +02:00
|
|
|
}
|
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";
|
2021-04-01 16:29:24 +02:00
|
|
|
export { default as ButtonDropdown } from "./DropdownMenu.svelte";
|
2021-04-01 02:26:56 +02:00
|
|
|
export { default as WithDropdownMenu } from "./WithDropdownMenu.svelte";
|