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 14:23:28 +02:00
|
|
|
import type ButtonGroup from "editor-toolbar/ButtonGroup.svelte";
|
2021-04-20 02:07:15 +02:00
|
|
|
import type { ButtonGroupProps } from "editor-toolbar/ButtonGroup";
|
2021-04-20 14:23:28 +02:00
|
|
|
import type { DynamicSvelteComponent } from "sveltelib/dynamicComponent";
|
2021-04-01 01:22:06 +02:00
|
|
|
|
|
|
|
import * as tr from "anki/i18n";
|
2021-04-20 14:23:28 +02:00
|
|
|
import {
|
|
|
|
commandIconButton,
|
|
|
|
iconButton,
|
|
|
|
buttonGroup,
|
2021-04-22 17:52:27 +02:00
|
|
|
withShortcut,
|
2021-04-20 14:23:28 +02:00
|
|
|
} from "editor-toolbar/dynamicComponents";
|
2021-04-01 01:22:06 +02:00
|
|
|
|
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";
|
|
|
|
|
2021-04-16 03:46:37 +02:00
|
|
|
export function getFormatInlineGroup(): DynamicSvelteComponent<typeof ButtonGroup> &
|
2021-04-15 14:58:13 +02:00
|
|
|
ButtonGroupProps {
|
2021-04-22 17:52:27 +02:00
|
|
|
const boldButton = withShortcut({
|
|
|
|
shortcut: "Control+KeyB",
|
2021-04-22 02:36:54 +02:00
|
|
|
button: commandIconButton({
|
|
|
|
icon: boldIcon,
|
2021-04-22 13:38:37 +02:00
|
|
|
tooltip: tr.editingBoldText(),
|
2021-04-22 02:36:54 +02:00
|
|
|
command: "bold",
|
|
|
|
}),
|
2021-04-09 18:42:41 +02:00
|
|
|
});
|
2021-03-29 21:05:30 +02:00
|
|
|
|
2021-04-22 17:52:27 +02:00
|
|
|
const italicButton = withShortcut({
|
|
|
|
shortcut: "Control+KeyI",
|
2021-04-22 02:36:54 +02:00
|
|
|
button: commandIconButton({
|
|
|
|
icon: italicIcon,
|
2021-04-22 13:38:37 +02:00
|
|
|
tooltip: tr.editingItalicText(),
|
2021-04-22 02:36:54 +02:00
|
|
|
command: "italic",
|
|
|
|
}),
|
2021-04-09 18:42:41 +02:00
|
|
|
});
|
2021-04-01 01:22:06 +02:00
|
|
|
|
2021-04-22 17:52:27 +02:00
|
|
|
const underlineButton = withShortcut({
|
|
|
|
shortcut: "Control+KeyU",
|
2021-04-22 02:36:54 +02:00
|
|
|
button: commandIconButton({
|
|
|
|
icon: underlineIcon,
|
2021-04-22 13:38:37 +02:00
|
|
|
tooltip: tr.editingUnderlineText(),
|
2021-04-22 02:36:54 +02:00
|
|
|
command: "underline",
|
|
|
|
}),
|
2021-04-09 18:42:41 +02:00
|
|
|
});
|
2021-03-29 21:05:30 +02:00
|
|
|
|
2021-04-22 17:52:27 +02:00
|
|
|
const superscriptButton = withShortcut({
|
|
|
|
shortcut: "Control+Shift+Equal",
|
2021-04-22 03:25:31 +02:00
|
|
|
button: commandIconButton({
|
|
|
|
icon: superscriptIcon,
|
2021-04-22 13:38:37 +02:00
|
|
|
tooltip: tr.editingSuperscript(),
|
2021-04-22 03:25:31 +02:00
|
|
|
command: "superscript",
|
|
|
|
}),
|
2021-04-09 18:42:41 +02:00
|
|
|
});
|
2021-04-01 01:22:06 +02:00
|
|
|
|
2021-04-22 17:52:27 +02:00
|
|
|
const subscriptButton = withShortcut({
|
|
|
|
shortcut: "Control+Equal",
|
2021-04-22 03:25:31 +02:00
|
|
|
button: commandIconButton({
|
|
|
|
icon: subscriptIcon,
|
2021-04-22 13:38:37 +02:00
|
|
|
tooltip: tr.editingSubscript(),
|
2021-04-22 03:25:31 +02:00
|
|
|
command: "subscript",
|
|
|
|
}),
|
2021-04-09 18:42:41 +02:00
|
|
|
});
|
2021-03-29 21:05:30 +02:00
|
|
|
|
2021-04-22 17:52:27 +02:00
|
|
|
const removeFormatButton = withShortcut({
|
|
|
|
shortcut: "Control+KeyR",
|
2021-04-22 02:36:54 +02:00
|
|
|
button: iconButton({
|
|
|
|
icon: eraserIcon,
|
2021-04-22 13:38:37 +02:00
|
|
|
tooltip: tr.editingRemoveFormatting(),
|
2021-04-22 02:36:54 +02:00
|
|
|
onClick: () => {
|
|
|
|
document.execCommand("removeFormat");
|
|
|
|
},
|
|
|
|
}),
|
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-19 16:31:35 +02:00
|
|
|
id: "inlineFormatting",
|
2021-04-08 18:28:43 +02:00
|
|
|
buttons: [
|
|
|
|
boldButton,
|
|
|
|
italicButton,
|
|
|
|
underlineButton,
|
|
|
|
superscriptButton,
|
|
|
|
subscriptButton,
|
|
|
|
removeFormatButton,
|
|
|
|
],
|
2021-04-09 18:42:41 +02:00
|
|
|
});
|
|
|
|
}
|