mirror of
https://github.com/ankitects/anki.git
synced 2025-11-07 13:17:12 -05:00
Move logic from index.ts to their individual files
This commit is contained in:
parent
3ddbc1e6c3
commit
4e6d5d9adb
6 changed files with 55 additions and 70 deletions
|
|
@ -17,15 +17,17 @@ function wrapWithForecolor(color: string): void {
|
||||||
document.execCommand("forecolor", false, color);
|
document.execCommand("forecolor", false, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
export const forecolorButton = {
|
const forecolorButton = {
|
||||||
component: IconButton,
|
component: IconButton,
|
||||||
icon: squareFillIcon,
|
icon: squareFillIcon,
|
||||||
className: "forecolor",
|
className: "forecolor",
|
||||||
onClick: () => wrapWithForecolor(getForecolor()),
|
onClick: () => wrapWithForecolor(getForecolor()),
|
||||||
};
|
};
|
||||||
|
|
||||||
export const colorpickerButton = {
|
const colorpickerButton = {
|
||||||
component: ColorPicker,
|
component: ColorPicker,
|
||||||
className: "rainbow",
|
className: "rainbow",
|
||||||
onChange: ({ currentTarget }) => setForegroundColor(currentTarget.value),
|
onChange: ({ currentTarget }) => setForegroundColor(currentTarget.value),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const colorButtons = [forecolorButton, colorpickerButton];
|
||||||
|
|
|
||||||
|
|
@ -7,39 +7,48 @@ import superscriptIcon from "./format-superscript.svg";
|
||||||
import subscriptIcon from "./format-subscript.svg";
|
import subscriptIcon from "./format-subscript.svg";
|
||||||
import eraserIcon from "./eraser.svg";
|
import eraserIcon from "./eraser.svg";
|
||||||
|
|
||||||
export const boldButton = {
|
const boldButton = {
|
||||||
component: CommandIconButton,
|
component: CommandIconButton,
|
||||||
icon: boldIcon,
|
icon: boldIcon,
|
||||||
command: "bold",
|
command: "bold",
|
||||||
};
|
};
|
||||||
|
|
||||||
export const italicButton = {
|
const italicButton = {
|
||||||
component: CommandIconButton,
|
component: CommandIconButton,
|
||||||
icon: italicIcon,
|
icon: italicIcon,
|
||||||
command: "italic",
|
command: "italic",
|
||||||
};
|
};
|
||||||
|
|
||||||
export const underlineButton = {
|
const underlineButton = {
|
||||||
component: CommandIconButton,
|
component: CommandIconButton,
|
||||||
icon: underlineIcon,
|
icon: underlineIcon,
|
||||||
command: "underline",
|
command: "underline",
|
||||||
};
|
};
|
||||||
|
|
||||||
export const superscriptButton = {
|
const superscriptButton = {
|
||||||
component: CommandIconButton,
|
component: CommandIconButton,
|
||||||
icon: superscriptIcon,
|
icon: superscriptIcon,
|
||||||
command: "superscript",
|
command: "superscript",
|
||||||
};
|
};
|
||||||
|
|
||||||
export const subscriptButton = {
|
const subscriptButton = {
|
||||||
component: CommandIconButton,
|
component: CommandIconButton,
|
||||||
icon: subscriptIcon,
|
icon: subscriptIcon,
|
||||||
command: "subscript",
|
command: "subscript",
|
||||||
};
|
};
|
||||||
|
|
||||||
export const eraserButton = {
|
const eraserButton = {
|
||||||
component: CommandIconButton,
|
component: CommandIconButton,
|
||||||
icon: eraserIcon,
|
icon: eraserIcon,
|
||||||
command: "removeFormat",
|
command: "removeFormat",
|
||||||
highlightable: false,
|
highlightable: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const formatButtons = [
|
||||||
|
boldButton,
|
||||||
|
italicButton,
|
||||||
|
underlineButton,
|
||||||
|
superscriptButton,
|
||||||
|
subscriptButton,
|
||||||
|
eraserButton,
|
||||||
|
];
|
||||||
|
|
|
||||||
|
|
@ -6,63 +6,18 @@ import * as tr from "anki/i18n";
|
||||||
|
|
||||||
import EditorToolbarSvelte from "./EditorToolbar.svelte";
|
import EditorToolbarSvelte from "./EditorToolbar.svelte";
|
||||||
|
|
||||||
import DropdownMenu from "./DropdownMenu.svelte";
|
|
||||||
import WithDropdownMenu from "./WithDropdownMenu.svelte";
|
|
||||||
import SelectButton from "./SelectButton.svelte";
|
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
export { updateActiveButtons, clearActiveButtons } from "./CommandIconButton.svelte";
|
export { updateActiveButtons, clearActiveButtons } from "./CommandIconButton.svelte";
|
||||||
import { Writable, writable } from "svelte/store";
|
import { Writable, writable } from "svelte/store";
|
||||||
|
|
||||||
import { fieldsButton, cardsButton } from "./notetype";
|
import { notetypeButtons } from "./notetype";
|
||||||
|
import { formatButtons } from "./format";
|
||||||
|
import { colorButtons } from "./color";
|
||||||
|
import { templateButtons, templateMenus } from "./template";
|
||||||
|
|
||||||
import {
|
const defaultMenus = [...templateMenus];
|
||||||
boldButton,
|
|
||||||
italicButton,
|
|
||||||
underlineButton,
|
|
||||||
superscriptButton,
|
|
||||||
subscriptButton,
|
|
||||||
eraserButton,
|
|
||||||
} from "./format";
|
|
||||||
|
|
||||||
import { forecolorButton, colorpickerButton } from "./color";
|
const defaultButtons = [notetypeButtons, formatButtons, colorButtons, templateButtons];
|
||||||
|
|
||||||
import {
|
|
||||||
attachmentButton,
|
|
||||||
recordButton,
|
|
||||||
clozeButton,
|
|
||||||
mathjaxButton,
|
|
||||||
htmlButton,
|
|
||||||
} from "./extra";
|
|
||||||
|
|
||||||
const defaultMenus = [
|
|
||||||
{
|
|
||||||
component: DropdownMenu,
|
|
||||||
id: "mathjaxMenu",
|
|
||||||
menuItems: [{ label: "Foo", onClick: () => console.log("foo") }],
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
const defaultButtons = [
|
|
||||||
[fieldsButton, cardsButton],
|
|
||||||
[
|
|
||||||
boldButton,
|
|
||||||
italicButton,
|
|
||||||
underlineButton,
|
|
||||||
superscriptButton,
|
|
||||||
subscriptButton,
|
|
||||||
eraserButton,
|
|
||||||
],
|
|
||||||
[forecolorButton, colorpickerButton],
|
|
||||||
[
|
|
||||||
attachmentButton,
|
|
||||||
recordButton,
|
|
||||||
clozeButton,
|
|
||||||
{ component: WithDropdownMenu, menuId: "mathjaxMenu", button: mathjaxButton },
|
|
||||||
htmlButton,
|
|
||||||
{ component: SelectButton, options: [{ label: "Test" }, { label: "Test2" }] },
|
|
||||||
],
|
|
||||||
];
|
|
||||||
|
|
||||||
class EditorToolbar extends HTMLElement {
|
class EditorToolbar extends HTMLElement {
|
||||||
component?: SvelteComponent;
|
component?: SvelteComponent;
|
||||||
|
|
|
||||||
|
|
@ -1,26 +1,28 @@
|
||||||
import { bridgeCommand } from "anki/bridgecommand";
|
import { bridgeCommand } from "anki/bridgecommand";
|
||||||
import { lazyLoaded } from "anki/lazy";
|
import { lazyProperties } from "anki/lazy";
|
||||||
import * as tr from "anki/i18n";
|
import * as tr from "anki/i18n";
|
||||||
import LabelButton from "./LabelButton.svelte";
|
import LabelButton from "./LabelButton.svelte";
|
||||||
|
|
||||||
export const fieldsButton = {
|
const fieldsButton = {
|
||||||
component: LabelButton,
|
component: LabelButton,
|
||||||
onClick: () => bridgeCommand("fields"),
|
onClick: () => bridgeCommand("fields"),
|
||||||
disables: false,
|
disables: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
lazyLoaded(fieldsButton, {
|
lazyProperties(fieldsButton, {
|
||||||
label: () => `${tr.editingFields()}...`,
|
label: () => `${tr.editingFields()}...`,
|
||||||
title: tr.editingCustomizeFields,
|
title: tr.editingCustomizeFields,
|
||||||
});
|
});
|
||||||
|
|
||||||
export const cardsButton = {
|
const cardsButton = {
|
||||||
component: LabelButton,
|
component: LabelButton,
|
||||||
onClick: () => bridgeCommand("cards"),
|
onClick: () => bridgeCommand("cards"),
|
||||||
disables: false,
|
disables: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
lazyLoaded(cardsButton, {
|
lazyProperties(cardsButton, {
|
||||||
label: () => `${tr.editingCards()}...`,
|
label: () => `${tr.editingCards()}...`,
|
||||||
title: tr.editingCustomizeCardTemplatesCtrlandl,
|
title: tr.editingCustomizeCardTemplatesCtrlandl,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export const notetypeButtons = [fieldsButton, cardsButton];
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import { bridgeCommand } from "anki/bridgecommand";
|
import { bridgeCommand } from "anki/bridgecommand";
|
||||||
|
|
||||||
import IconButton from "./IconButton.svelte";
|
import IconButton from "./IconButton.svelte";
|
||||||
|
import DropdownMenu from "./DropdownMenu.svelte";
|
||||||
|
|
||||||
import paperclipIcon from "./paperclip.svg";
|
import paperclipIcon from "./paperclip.svg";
|
||||||
import micIcon from "./mic.svg";
|
import micIcon from "./mic.svg";
|
||||||
|
|
@ -24,27 +25,43 @@ function onHtmlEdit(): void {
|
||||||
bridgeCommand("htmlEdit");
|
bridgeCommand("htmlEdit");
|
||||||
}
|
}
|
||||||
|
|
||||||
export const attachmentButton = {
|
const attachmentButton = {
|
||||||
component: IconButton,
|
component: IconButton,
|
||||||
icon: paperclipIcon,
|
icon: paperclipIcon,
|
||||||
onClick: onAttachment,
|
onClick: onAttachment,
|
||||||
};
|
};
|
||||||
|
|
||||||
export const recordButton = { component: IconButton, icon: micIcon, onClick: onRecord };
|
const recordButton = { component: IconButton, icon: micIcon, onClick: onRecord };
|
||||||
|
|
||||||
export const clozeButton = {
|
const clozeButton = {
|
||||||
component: IconButton,
|
component: IconButton,
|
||||||
icon: bracketsIcon,
|
icon: bracketsIcon,
|
||||||
onClick: onCloze,
|
onClick: onCloze,
|
||||||
};
|
};
|
||||||
|
|
||||||
export const mathjaxButton = {
|
const mathjaxButton = {
|
||||||
component: IconButton,
|
component: IconButton,
|
||||||
icon: functionIcon,
|
icon: functionIcon,
|
||||||
};
|
};
|
||||||
|
|
||||||
export const htmlButton = {
|
const mathjaxMenu = {
|
||||||
|
component: DropdownMenu,
|
||||||
|
id: "mathjaxMenu",
|
||||||
|
menuItems: [{ label: "Foo", onClick: () => console.log("foo") }],
|
||||||
|
};
|
||||||
|
|
||||||
|
const htmlButton = {
|
||||||
component: IconButton,
|
component: IconButton,
|
||||||
icon: xmlIcon,
|
icon: xmlIcon,
|
||||||
onClick: onHtmlEdit,
|
onClick: onHtmlEdit,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const templateButtons = [
|
||||||
|
attachmentButton,
|
||||||
|
recordButton,
|
||||||
|
clozeButton,
|
||||||
|
mathjaxButton,
|
||||||
|
htmlButton,
|
||||||
|
];
|
||||||
|
|
||||||
|
export const templateMenus = [mathjaxMenu];
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
export function lazyLoaded(
|
export function lazyProperties(
|
||||||
object: Record<string, unknown>,
|
object: Record<string, unknown>,
|
||||||
properties: Record<string, () => unknown>
|
properties: Record<string, () => unknown>
|
||||||
): void {
|
): void {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue