anki/ts/editor-toolbar/index.ts

53 lines
1.9 KiB
TypeScript
Raw Normal View History

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-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";
import { notetypeGroup } from "./notetype";
import { formatGroup } from "./format";
import { colorGroup } from "./color";
import { templateGroup, templateMenus } from "./template";
// @ts-expect-error
2021-04-01 02:26:56 +02:00
export { updateActiveButtons, clearActiveButtons } from "./CommandIconButton.svelte";
export { enableButtons, disableButtons } from "./EditorToolbar.svelte";
2021-04-01 02:26:56 +02:00
const defaultButtons = [notetypeGroup, formatGroup, colorGroup, templateGroup];
const defaultMenus = [...templateMenus];
2021-03-25 21:11:40 +01:00
class EditorToolbar extends HTMLElement {
component?: SvelteComponent;
buttons = writable(defaultButtons);
menus = writable(defaultMenus);
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,
nightMode: checkNightMode(),
2021-03-31 22:05:24 +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";
export { default as ButtonDropdown } from "./DropdownMenu.svelte";
2021-04-01 02:26:56 +02:00
export { default as WithDropdownMenu } from "./WithDropdownMenu.svelte";