anki/ts/editor/formatInline.ts

79 lines
2.6 KiB
TypeScript
Raw Normal View History

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
import CommandIconButton from "editor-toolbar/CommandIconButton.svelte";
import type { CommandIconButtonProps } from "editor-toolbar/CommandIconButton";
import IconButton from "editor-toolbar/IconButton.svelte";
import type { IconButtonProps } from "editor-toolbar/IconButton";
import ButtonGroup from "editor-toolbar/ButtonGroup.svelte";
import type { ButtonGroupProps } from "editor-toolbar/ButtonGroup";
2021-04-15 02:49:46 +02:00
import { DynamicSvelteComponent, dynamicComponent } from "sveltelib/dynamicComponent";
import * as tr from "anki/i18n";
2021-03-29 21:05:30 +02:00
import boldIcon from "./type-bold.svg";
import italicIcon from "./type-italic.svg";
import underlineIcon from "./type-underline.svg";
import superscriptIcon from "./format-superscript.svg";
import subscriptIcon from "./format-subscript.svg";
import eraserIcon from "./eraser.svg";
const commandIconButton = dynamicComponent<
typeof CommandIconButton,
CommandIconButtonProps
>(CommandIconButton);
const iconButton = dynamicComponent<typeof IconButton, IconButtonProps>(IconButton);
const buttonGroup = dynamicComponent<typeof ButtonGroup, ButtonGroupProps>(ButtonGroup);
export function getFormatInlineGroup(): DynamicSvelteComponent<typeof ButtonGroup> &
2021-04-15 14:58:13 +02:00
ButtonGroupProps {
const boldButton = commandIconButton({
2021-04-01 01:38:50 +02:00
icon: boldIcon,
tooltip: tr.editingBoldTextCtrlandb(),
command: "bold",
});
2021-03-29 21:05:30 +02:00
const italicButton = commandIconButton({
2021-04-01 01:38:50 +02:00
icon: italicIcon,
tooltip: tr.editingItalicTextCtrlandi(),
command: "italic",
});
const underlineButton = commandIconButton({
2021-04-01 01:38:50 +02:00
icon: underlineIcon,
tooltip: tr.editingUnderlineTextCtrlandu(),
command: "underline",
});
2021-03-29 21:05:30 +02:00
const superscriptButton = commandIconButton({
2021-04-01 01:38:50 +02:00
icon: superscriptIcon,
tooltip: tr.editingSuperscriptCtrlandand(),
command: "superscript",
});
const subscriptButton = commandIconButton({
2021-04-01 01:38:50 +02:00
icon: subscriptIcon,
tooltip: tr.editingSubscriptCtrland(),
command: "subscript",
});
2021-03-29 21:05:30 +02:00
const removeFormatButton = iconButton({
2021-04-01 01:38:50 +02:00
icon: eraserIcon,
tooltip: tr.editingRemoveFormattingCtrlandr(),
onClick: () => {
document.execCommand("removeFormat");
},
});
return buttonGroup({
2021-04-19 16:31:35 +02:00
id: "inlineFormatting",
buttons: [
boldButton,
italicButton,
underlineButton,
superscriptButton,
subscriptButton,
removeFormatButton,
],
});
}