anki/ts/editor-toolbar/template.ts

116 lines
2.6 KiB
TypeScript
Raw Normal View History

import IconButton from "./IconButton.svelte";
import DropdownMenu from "./DropdownMenu.svelte";
import DropdownItem from "./DropdownItem.svelte";
import WithDropdownMenu from "./WithDropdownMenu.svelte";
import { bridgeCommand } from "anki/bridgecommand";
2021-04-01 01:38:50 +02:00
import { withLazyProperties } from "anki/lazy";
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
}
2021-04-01 01:38:50 +02:00
const attachmentButton = withLazyProperties(
{
component: IconButton,
icon: paperclipIcon,
onClick: onAttachment,
},
{
title: tr.editingAttachPicturesaudiovideoF3,
}
);
const recordButton = withLazyProperties(
{ component: IconButton, icon: micIcon, onClick: onRecord },
{
title: tr.editingRecordAudioF5,
}
);
const clozeButton = withLazyProperties(
{
component: IconButton,
icon: bracketsIcon,
onClick: onCloze,
},
{
title: tr.editingClozeDeletionCtrlandshiftandc,
}
);
const mathjaxButton = {
2021-03-30 01:53:27 +02:00
component: IconButton,
icon: functionIcon,
2021-03-30 01:53:27 +02:00
};
const mathjaxMenuId = "mathjaxMenu";
const mathjaxMenu = {
component: DropdownMenu,
id: mathjaxMenuId,
menuItems: [
2021-04-01 01:38:50 +02:00
withLazyProperties(
{ component: DropdownItem, onClick: () => bridgeCommand("mathjaxInline") },
{ label: tr.editingMathjaxInline }
),
withLazyProperties(
{ component: DropdownItem, onClick: () => bridgeCommand("mathjaxBlock") },
{ label: tr.editingMathjaxBlock }
),
withLazyProperties(
{
component: DropdownItem,
onClick: () => bridgeCommand("mathjaxChemistry"),
},
{ label: tr.editingMathjaxChemistry }
),
],
};
const mathjaxButtonWithMenu = {
component: WithDropdownMenu,
button: mathjaxButton,
menuId: mathjaxMenuId,
};
2021-04-01 01:38:50 +02:00
const htmlButton = withLazyProperties(
{
component: IconButton,
icon: xmlIcon,
onClick: onHtmlEdit,
},
{
title: tr.editingHtmlEditor,
}
);
export const templateButtons = [
attachmentButton,
recordButton,
clozeButton,
mathjaxButtonWithMenu,
htmlButton,
];
export const templateMenus = [mathjaxMenu];