2021-04-15 15:59:52 +02:00
|
|
|
// Copyright: Ankitects Pty Ltd and contributors
|
|
|
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
2021-04-20 02:07:15 +02:00
|
|
|
import IconButton from "editor-toolbar/IconButton.svelte";
|
|
|
|
import type { IconButtonProps } from "editor-toolbar/IconButton";
|
|
|
|
import DropdownMenu from "editor-toolbar/DropdownMenu.svelte";
|
|
|
|
import type { DropdownMenuProps } from "editor-toolbar/DropdownMenu";
|
|
|
|
import DropdownItem from "editor-toolbar/DropdownItem.svelte";
|
|
|
|
import type { DropdownItemProps } from "editor-toolbar/DropdownItem";
|
|
|
|
import WithDropdownMenu from "editor-toolbar/WithDropdownMenu.svelte";
|
|
|
|
import type { WithDropdownMenuProps } from "editor-toolbar/WithDropdownMenu";
|
|
|
|
import ButtonGroup from "editor-toolbar/ButtonGroup.svelte";
|
|
|
|
import type { ButtonGroupProps } from "editor-toolbar/ButtonGroup";
|
2021-04-01 01:22:06 +02:00
|
|
|
|
|
|
|
import { bridgeCommand } from "anki/bridgecommand";
|
2021-04-15 02:49:46 +02:00
|
|
|
import { DynamicSvelteComponent, dynamicComponent } from "sveltelib/dynamicComponent";
|
2021-04-01 01:22:06 +02:00
|
|
|
import * as tr from "anki/i18n";
|
2021-03-30 02:53:57 +02:00
|
|
|
|
2021-04-20 03:24:08 +02:00
|
|
|
import { wrap } from "./wrap";
|
|
|
|
|
2021-03-30 01:23:39 +02:00
|
|
|
import paperclipIcon from "./paperclip.svg";
|
|
|
|
import micIcon from "./mic.svg";
|
2021-03-30 02:53:57 +02:00
|
|
|
import functionIcon from "./function-variant.svg";
|
|
|
|
import xmlIcon from "./xml.svg";
|
2021-03-30 01:53:27 +02:00
|
|
|
|
2021-04-09 18:42:41 +02:00
|
|
|
import { getClozeButton } from "./cloze";
|
2021-04-08 23:08:36 +02:00
|
|
|
|
2021-03-30 01:53:27 +02:00
|
|
|
function onAttachment(): void {
|
|
|
|
bridgeCommand("attach");
|
|
|
|
}
|
|
|
|
|
|
|
|
function onRecord(): void {
|
|
|
|
bridgeCommand("record");
|
|
|
|
}
|
|
|
|
|
2021-03-31 03:34:08 +02:00
|
|
|
function onHtmlEdit(): void {
|
|
|
|
bridgeCommand("htmlEdit");
|
2021-03-30 01:53:27 +02:00
|
|
|
}
|
|
|
|
|
2021-04-09 18:42:41 +02:00
|
|
|
const mathjaxMenuId = "mathjaxMenu";
|
2021-04-08 16:29:28 +02:00
|
|
|
|
2021-04-09 18:42:41 +02:00
|
|
|
const iconButton = dynamicComponent<typeof IconButton, IconButtonProps>(IconButton);
|
|
|
|
const withDropdownMenu = dynamicComponent<
|
|
|
|
typeof WithDropdownMenu,
|
|
|
|
WithDropdownMenuProps
|
|
|
|
>(WithDropdownMenu);
|
|
|
|
const dropdownMenu = dynamicComponent<typeof DropdownMenu, DropdownMenuProps>(
|
|
|
|
DropdownMenu
|
|
|
|
);
|
|
|
|
const dropdownItem = dynamicComponent<typeof DropdownItem, DropdownItemProps>(
|
|
|
|
DropdownItem
|
|
|
|
);
|
|
|
|
const buttonGroup = dynamicComponent<typeof ButtonGroup, ButtonGroupProps>(ButtonGroup);
|
2021-04-08 16:29:28 +02:00
|
|
|
|
2021-04-15 14:58:13 +02:00
|
|
|
export function getTemplateGroup(): DynamicSvelteComponent<typeof ButtonGroup> &
|
|
|
|
ButtonGroupProps {
|
2021-04-09 18:42:41 +02:00
|
|
|
const attachmentButton = iconButton({
|
2021-04-01 01:38:50 +02:00
|
|
|
icon: paperclipIcon,
|
|
|
|
onClick: onAttachment,
|
2021-04-09 18:42:41 +02:00
|
|
|
tooltip: tr.editingAttachPicturesaudiovideoF3(),
|
|
|
|
});
|
2021-04-01 01:38:50 +02:00
|
|
|
|
2021-04-09 18:42:41 +02:00
|
|
|
const recordButton = iconButton({
|
|
|
|
icon: micIcon,
|
|
|
|
onClick: onRecord,
|
|
|
|
tooltip: tr.editingRecordAudioF5(),
|
|
|
|
});
|
2021-04-01 01:38:50 +02:00
|
|
|
|
2021-04-09 18:42:41 +02:00
|
|
|
const mathjaxButton = iconButton({
|
2021-04-08 16:29:28 +02:00
|
|
|
icon: functionIcon,
|
2021-04-09 18:42:41 +02:00
|
|
|
foo: 5,
|
|
|
|
});
|
2021-04-08 16:29:28 +02:00
|
|
|
|
2021-04-09 18:42:41 +02:00
|
|
|
const mathjaxButtonWithMenu = withDropdownMenu({
|
2021-04-08 16:29:28 +02:00
|
|
|
button: mathjaxButton,
|
|
|
|
menuId: mathjaxMenuId,
|
2021-04-09 18:42:41 +02:00
|
|
|
});
|
2021-04-08 16:29:28 +02:00
|
|
|
|
2021-04-09 18:42:41 +02:00
|
|
|
const htmlButton = iconButton({
|
2021-04-01 01:38:50 +02:00
|
|
|
icon: xmlIcon,
|
|
|
|
onClick: onHtmlEdit,
|
2021-04-08 16:40:42 +02:00
|
|
|
tooltip: tr.editingHtmlEditor,
|
2021-04-09 18:42:41 +02:00
|
|
|
});
|
2021-04-01 01:22:06 +02:00
|
|
|
|
2021-04-09 18:42:41 +02:00
|
|
|
return buttonGroup({
|
2021-04-08 18:28:43 +02:00
|
|
|
id: "template",
|
|
|
|
buttons: [
|
|
|
|
attachmentButton,
|
|
|
|
recordButton,
|
2021-04-09 18:42:41 +02:00
|
|
|
getClozeButton(),
|
2021-04-08 18:28:43 +02:00
|
|
|
mathjaxButtonWithMenu,
|
|
|
|
htmlButton,
|
|
|
|
],
|
2021-04-09 18:42:41 +02:00
|
|
|
});
|
|
|
|
}
|
2021-04-01 00:45:02 +02:00
|
|
|
|
2021-04-15 14:58:13 +02:00
|
|
|
export function getTemplateMenus(): (DynamicSvelteComponent<typeof DropdownMenu> &
|
|
|
|
DropdownMenuProps)[] {
|
2021-04-15 15:20:37 +02:00
|
|
|
const mathjaxMenuItems = [
|
|
|
|
dropdownItem({
|
|
|
|
onClick: () => wrap("\\(", "\\)"),
|
|
|
|
label: tr.editingMathjaxInline(),
|
|
|
|
endLabel: "Ctrl+M, M",
|
|
|
|
}),
|
|
|
|
dropdownItem({
|
|
|
|
onClick: () => wrap("\\[", "\\]"),
|
|
|
|
label: tr.editingMathjaxBlock(),
|
|
|
|
endLabel: "Ctrl+M, E",
|
|
|
|
}),
|
|
|
|
dropdownItem({
|
|
|
|
onClick: () => wrap("\\(\\ce{", "}\\)"),
|
|
|
|
label: tr.editingMathjaxChemistry(),
|
|
|
|
endLabel: "Ctrl+M, C",
|
|
|
|
}),
|
|
|
|
];
|
|
|
|
|
|
|
|
const latexMenuItems = [
|
|
|
|
dropdownItem({
|
|
|
|
onClick: () => wrap("[latex]", "[/latex]"),
|
|
|
|
label: tr.editingLatex(),
|
|
|
|
endLabel: "Ctrl+T, T",
|
|
|
|
}),
|
|
|
|
dropdownItem({
|
|
|
|
onClick: () => wrap("[$]", "[/$]"),
|
|
|
|
label: tr.editingLatexEquation(),
|
|
|
|
endLabel: "Ctrl+T, E",
|
|
|
|
}),
|
|
|
|
dropdownItem({
|
|
|
|
onClick: () => wrap("[$$]", "[/$$]"),
|
|
|
|
label: tr.editingLatexMathEnv(),
|
|
|
|
endLabel: "Ctrl+T, M",
|
|
|
|
}),
|
|
|
|
];
|
|
|
|
|
2021-04-09 18:42:41 +02:00
|
|
|
const mathjaxMenu = dropdownMenu({
|
|
|
|
id: mathjaxMenuId,
|
2021-04-15 15:20:37 +02:00
|
|
|
menuItems: [...mathjaxMenuItems, ...latexMenuItems],
|
2021-04-09 18:42:41 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
return [mathjaxMenu];
|
|
|
|
}
|