anki/ts/editor-toolbar/index.ts

60 lines
1.3 KiB
TypeScript
Raw Normal View History

2021-03-25 21:11:40 +01:00
import type { SvelteComponent } from "svelte";
import { checkNightMode } from "anki/nightmode";
import EditorToolbarSvelte from "./EditorToolbar.svelte";
import LabelButton from "./LabelButton.svelte";
import {
boldButton,
italicButton,
underlineButton,
superscriptButton,
subscriptButton,
eraserButton,
} from "./format";
import { forecolorButton, colorpickerButton } from "./color";
import {
attachmentButton,
recordButton,
clozeButton,
mathjaxButton,
htmlButton,
} from "./extra";
const defaultButtons = [
[
{ component: LabelButton, label: "Fields..." },
{ component: LabelButton, label: "Cards..." },
],
[
boldButton,
italicButton,
underlineButton,
superscriptButton,
subscriptButton,
eraserButton,
],
[forecolorButton, colorpickerButton],
[attachmentButton, recordButton, clozeButton, mathjaxButton, htmlButton],
];
2021-03-25 21:11:40 +01:00
class EditorToolbar extends HTMLElement {
component?: SvelteComponent;
2021-03-25 23:32:23 +01:00
connectedCallback(): void {
2021-03-25 21:11:40 +01:00
const nightMode = checkNightMode();
this.component = new EditorToolbarSvelte({
target: this,
props: {
nightMode,
buttons: defaultButtons,
2021-03-25 21:11:40 +01:00
},
});
}
}
customElements.define("anki-editor-toolbar", EditorToolbar);