2021-04-16 03:46:37 +02:00
|
|
|
// Copyright: Ankitects Pty Ltd and contributors
|
|
|
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
2021-04-16 15:26:49 +02:00
|
|
|
import ButtonGroup from "./ButtonGroup.svelte";
|
|
|
|
import type { ButtonGroupProps } from "./ButtonGroup";
|
|
|
|
import ButtonDropdown from "./ButtonDropdown.svelte";
|
|
|
|
import type { ButtonDropdownProps } from "./ButtonDropdown";
|
|
|
|
import WithDropdownMenu from "./WithDropdownMenu.svelte";
|
|
|
|
import type { WithDropdownMenuProps } from "./WithDropdownMenu";
|
|
|
|
|
2021-04-16 03:46:37 +02:00
|
|
|
import CommandIconButton from "./CommandIconButton.svelte";
|
|
|
|
import type { CommandIconButtonProps } from "./CommandIconButton";
|
|
|
|
import IconButton from "./IconButton.svelte";
|
|
|
|
import type { IconButtonProps } from "./IconButton";
|
|
|
|
|
|
|
|
import { DynamicSvelteComponent, dynamicComponent } from "sveltelib/dynamicComponent";
|
|
|
|
import * as tr from "anki/i18n";
|
|
|
|
|
|
|
|
import ulIcon from "./list-ul.svg";
|
|
|
|
import olIcon from "./list-ol.svg";
|
|
|
|
import listOptionsIcon from "./text-paragraph.svg";
|
|
|
|
|
2021-04-16 15:26:49 +02:00
|
|
|
import justifyFullIcon from "./justify.svg";
|
2021-04-16 03:46:37 +02:00
|
|
|
import justifyLeftIcon from "./text-left.svg";
|
|
|
|
import justifyRightIcon from "./text-right.svg";
|
|
|
|
import justifyCenterIcon from "./text-center.svg";
|
|
|
|
|
|
|
|
import indentIcon from "./text-indent-left.svg";
|
|
|
|
import outdentIcon from "./text-indent-right.svg";
|
|
|
|
|
|
|
|
const commandIconButton = dynamicComponent<
|
|
|
|
typeof CommandIconButton,
|
|
|
|
CommandIconButtonProps
|
|
|
|
>(CommandIconButton);
|
2021-04-16 15:26:49 +02:00
|
|
|
|
2021-04-16 03:46:37 +02:00
|
|
|
const buttonGroup = dynamicComponent<typeof ButtonGroup, ButtonGroupProps>(ButtonGroup);
|
2021-04-16 15:26:49 +02:00
|
|
|
const buttonDropdown = dynamicComponent<typeof ButtonDropdown, ButtonDropdownProps>(
|
|
|
|
ButtonDropdown
|
|
|
|
);
|
|
|
|
|
|
|
|
const withDropdownMenu = dynamicComponent<
|
|
|
|
typeof WithDropdownMenu,
|
|
|
|
WithDropdownMenuProps
|
|
|
|
>(WithDropdownMenu);
|
|
|
|
|
|
|
|
export function getFormatBlockMenus(): (DynamicSvelteComponent<typeof ButtonDropdown> &
|
|
|
|
ButtonDropdownProps)[] {
|
|
|
|
const justifyLeftButton = commandIconButton({
|
|
|
|
icon: justifyLeftIcon,
|
|
|
|
command: "justifyLeft",
|
2021-04-16 16:08:00 +02:00
|
|
|
tooltip: tr.editingAlignLeft(),
|
2021-04-16 15:26:49 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
const justifyCenterButton = commandIconButton({
|
|
|
|
icon: justifyCenterIcon,
|
|
|
|
command: "justifyCenter",
|
2021-04-16 16:08:00 +02:00
|
|
|
tooltip: tr.editingCenter(),
|
2021-04-16 15:26:49 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
const justifyRightButton = commandIconButton({
|
|
|
|
icon: justifyRightIcon,
|
|
|
|
command: "justifyRight",
|
2021-04-16 16:08:00 +02:00
|
|
|
tooltip: tr.editingAlignRight(),
|
|
|
|
});
|
|
|
|
|
|
|
|
const justifyFullButton = commandIconButton({
|
|
|
|
icon: justifyFullIcon,
|
|
|
|
command: "justifyFull",
|
|
|
|
tooltip: tr.editingJustify(),
|
2021-04-16 15:26:49 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
const justifyGroup = buttonGroup({
|
|
|
|
id: "justify",
|
|
|
|
buttons: [
|
|
|
|
justifyLeftButton,
|
|
|
|
justifyCenterButton,
|
|
|
|
justifyRightButton,
|
2021-04-16 16:08:00 +02:00
|
|
|
justifyFullButton,
|
2021-04-16 15:26:49 +02:00
|
|
|
],
|
|
|
|
});
|
|
|
|
|
|
|
|
const outdentButton = commandIconButton({
|
|
|
|
icon: outdentIcon,
|
|
|
|
command: "outdent",
|
2021-04-16 16:08:00 +02:00
|
|
|
tooltip: tr.editingOutdent(),
|
2021-04-16 16:11:53 +02:00
|
|
|
activatable: false,
|
2021-04-16 16:08:00 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
const indentButton = commandIconButton({
|
|
|
|
icon: indentIcon,
|
|
|
|
command: "indent",
|
|
|
|
tooltip: tr.editingIndent(),
|
2021-04-16 16:11:53 +02:00
|
|
|
activatable: false,
|
2021-04-16 15:26:49 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
const indentationGroup = buttonGroup({
|
|
|
|
id: "indentation",
|
2021-04-16 16:08:00 +02:00
|
|
|
buttons: [outdentButton, indentButton],
|
2021-04-16 15:26:49 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
const formattingOptions = buttonDropdown({
|
|
|
|
id: "listFormatting",
|
|
|
|
buttons: [justifyGroup, indentationGroup],
|
|
|
|
});
|
|
|
|
|
|
|
|
return [formattingOptions];
|
|
|
|
}
|
|
|
|
|
|
|
|
const iconButton = dynamicComponent<typeof IconButton, IconButtonProps>(IconButton);
|
2021-04-16 03:46:37 +02:00
|
|
|
|
|
|
|
export function getFormatBlockGroup(): DynamicSvelteComponent<typeof ButtonGroup> &
|
|
|
|
ButtonGroupProps {
|
|
|
|
const ulButton = commandIconButton({
|
|
|
|
icon: ulIcon,
|
|
|
|
command: "insertUnorderedList",
|
2021-04-16 16:08:00 +02:00
|
|
|
tooltip: tr.editingUnorderedList(),
|
2021-04-16 03:46:37 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
const olButton = commandIconButton({
|
|
|
|
icon: olIcon,
|
|
|
|
command: "insertOrderedList",
|
2021-04-16 16:08:00 +02:00
|
|
|
tooltip: tr.editingOrderedList(),
|
2021-04-16 03:46:37 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
const listFormattingButton = iconButton({
|
|
|
|
icon: listOptionsIcon,
|
|
|
|
});
|
|
|
|
|
2021-04-16 15:26:49 +02:00
|
|
|
const listFormatting = withDropdownMenu({
|
|
|
|
button: listFormattingButton,
|
|
|
|
menuId: "listFormatting",
|
|
|
|
});
|
|
|
|
|
2021-04-16 03:46:37 +02:00
|
|
|
return buttonGroup({
|
2021-04-16 16:08:00 +02:00
|
|
|
id: "formatBlock",
|
2021-04-16 15:26:49 +02:00
|
|
|
buttons: [ulButton, olButton, listFormatting],
|
2021-04-16 03:46:37 +02:00
|
|
|
});
|
|
|
|
}
|