anki/ts/editor-toolbar/template.ts

147 lines
3.7 KiB
TypeScript
Raw Normal View History

import IconButton from "./IconButton.svelte";
import type { IconButtonProps } from "./IconButton";
import DropdownMenu from "./DropdownMenu.svelte";
import type { DropdownMenuProps } from "./DropdownMenu";
import DropdownItem from "./DropdownItem.svelte";
import type { DropdownItemProps } from "./DropdownItem";
import WithDropdownMenu from "./WithDropdownMenu.svelte";
import type { WithDropdownMenuProps } from "./WithDropdownMenu";
import ButtonGroup from "./ButtonGroup.svelte";
import type { ButtonGroupProps } from "./ButtonGroup";
import { bridgeCommand } from "anki/bridgecommand";
import { dynamicComponent } from "sveltelib/dynamicComponent";
import * as tr from "anki/i18n";
import paperclipIcon from "./paperclip.svg";
import micIcon from "./mic.svg";
import bracketsIcon from "./code-brackets.svg";
import functionIcon from "./function-variant.svg";
import xmlIcon from "./xml.svg";
2021-03-30 01:53:27 +02:00
function onAttachment(): void {
bridgeCommand("attach");
}
function onRecord(): void {
bridgeCommand("record");
}
function onCloze(): void {
bridgeCommand("cloze");
}
2021-03-31 03:34:08 +02:00
function onHtmlEdit(): void {
bridgeCommand("htmlEdit");
2021-03-30 01:53:27 +02:00
}
const iconButton = dynamicComponent(IconButton);
const withDropdownMenu = dynamicComponent(WithDropdownMenu);
const dropdownMenu = dynamicComponent(DropdownMenu);
const dropdownItem = dynamicComponent(DropdownItem);
const attachmentButton = iconButton<IconButtonProps, "tooltip">(
2021-04-01 01:38:50 +02:00
{
icon: paperclipIcon,
onClick: onAttachment,
},
{
tooltip: tr.editingAttachPicturesaudiovideoF3,
2021-04-01 01:38:50 +02:00
}
);
const recordButton = iconButton(
{ icon: micIcon, onClick: onRecord },
2021-04-01 01:38:50 +02:00
{
tooltip: tr.editingRecordAudioF5,
2021-04-01 01:38:50 +02:00
}
);
const clozeButton = iconButton<IconButtonProps, "tooltip">(
2021-04-01 01:38:50 +02:00
{
icon: bracketsIcon,
onClick: onCloze,
},
{
tooltip: tr.editingClozeDeletionCtrlandshiftandc,
2021-04-01 01:38:50 +02:00
}
);
const mathjaxButton = iconButton<Omit<IconButtonProps, "onClick" | "tooltip">>(
{
icon: functionIcon,
},
{}
);
const mathjaxMenuId = "mathjaxMenu";
const mathjaxMenu = dropdownMenu<DropdownMenuProps>(
{
id: mathjaxMenuId,
menuItems: [
dropdownItem<DropdownItemProps, "label">(
{
onClick: () => bridgeCommand("mathjaxInline"),
tooltip: "test",
endLabel: "test",
},
{ label: tr.editingMathjaxInline }
),
dropdownItem<DropdownItemProps, "label">(
{
onClick: () => bridgeCommand("mathjaxBlock"),
tooltip: "test",
endLabel: "test",
},
{ label: tr.editingMathjaxBlock }
),
dropdownItem<DropdownItemProps, "label">(
{
onClick: () => bridgeCommand("mathjaxChemistry"),
tooltip: "test",
endLabel: "test",
},
{ label: tr.editingMathjaxChemistry }
),
],
},
{}
);
const mathjaxButtonWithMenu = withDropdownMenu<WithDropdownMenuProps>(
{
button: mathjaxButton,
menuId: mathjaxMenuId,
},
{}
);
const htmlButton = iconButton<IconButtonProps, "tooltip">(
2021-04-01 01:38:50 +02:00
{
icon: xmlIcon,
onClick: onHtmlEdit,
},
{
tooltip: tr.editingHtmlEditor,
2021-04-01 01:38:50 +02:00
}
);
const buttonGroup = dynamicComponent(ButtonGroup);
export const templateGroup = buttonGroup<ButtonGroupProps>(
{
id: "template",
buttons: [
attachmentButton,
recordButton,
clozeButton,
mathjaxButtonWithMenu,
htmlButton,
],
},
{}
);
export const templateMenus = [mathjaxMenu];