anki/ts/editor/FormatBlockButtons.svelte

151 lines
5.4 KiB
Svelte
Raw Normal View History

<!--
Copyright: Ankitects Pty Ltd and contributors
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
-->
<script lang="typescript">
import * as tr from "lib/i18n";
import ButtonGroup from "components/ButtonGroup.svelte";
import ButtonGroupItem from "components/ButtonGroupItem.svelte";
import IconButton from "components/IconButton.svelte";
import ButtonDropdown from "components/ButtonDropdown.svelte";
import Item from "components/Item.svelte";
import WithDropdown from "components/WithDropdown.svelte";
import OnlyEditable from "./OnlyEditable.svelte";
import CommandIconButton from "./CommandIconButton.svelte";
import { getCurrentField, getListItem } from "./helpers";
import {
ulIcon,
olIcon,
listOptionsIcon,
justifyFullIcon,
justifyLeftIcon,
justifyRightIcon,
justifyCenterIcon,
indentIcon,
outdentIcon,
} from "./icons";
export let api = {};
function outdentListItem() {
const currentField = getCurrentField();
if (getListItem(currentField.editableContainer.shadowRoot!)) {
document.execCommand("outdent");
} else {
alert("Indent/unindent currently only works with lists.");
}
}
function indentListItem() {
const currentField = getCurrentField();
if (getListItem(currentField.editableContainer.shadowRoot!)) {
document.execCommand("indent");
} else {
alert("Indent/unindent currently only works with lists.");
}
}
</script>
<ButtonGroup {api}>
<ButtonGroupItem>
<CommandIconButton
key="insertUnorderedList"
tooltip={tr.editingUnorderedList()}
withoutShortcut>{@html ulIcon}</CommandIconButton
>
</ButtonGroupItem>
<ButtonGroupItem>
<CommandIconButton
key="insertOrderedList"
tooltip={tr.editingOrderedList()}
withoutShortcut>{@html olIcon}</CommandIconButton
>
</ButtonGroupItem>
2021-05-06 23:04:38 +02:00
<ButtonGroupItem>
<WithDropdown let:createDropdown>
<OnlyEditable let:disabled>
<IconButton
{disabled}
on:mount={(event) => createDropdown(event.detail.button)}
>
{@html listOptionsIcon}
</IconButton>
</OnlyEditable>
<ButtonDropdown>
<Item id="justify">
2021-05-06 23:04:38 +02:00
<ButtonGroup>
<ButtonGroupItem>
<CommandIconButton
2021-05-06 23:04:38 +02:00
key="justifyLeft"
tooltip={tr.editingAlignLeft()}
withoutShortcut
>{@html justifyLeftIcon}</CommandIconButton
>
2021-05-06 23:04:38 +02:00
</ButtonGroupItem>
2021-05-06 23:04:38 +02:00
<ButtonGroupItem>
<CommandIconButton
2021-05-06 23:04:38 +02:00
key="justifyCenter"
tooltip={tr.editingCenter()}
withoutShortcut
>{@html justifyCenterIcon}</CommandIconButton
>
2021-05-06 23:04:38 +02:00
</ButtonGroupItem>
2021-05-06 23:04:38 +02:00
<ButtonGroupItem>
<CommandIconButton
2021-05-06 23:04:38 +02:00
key="justifyRight"
tooltip={tr.editingAlignRight()}
withoutShortcut
>{@html justifyRightIcon}</CommandIconButton
>
2021-05-06 23:04:38 +02:00
</ButtonGroupItem>
2021-05-06 23:04:38 +02:00
<ButtonGroupItem>
<CommandIconButton
2021-05-06 23:04:38 +02:00
key="justifyFull"
tooltip={tr.editingJustify()}
withoutShortcut
>{@html justifyFullIcon}</CommandIconButton
>
2021-05-06 23:04:38 +02:00
</ButtonGroupItem>
</ButtonGroup>
</Item>
<Item id="indentation">
2021-05-06 23:04:38 +02:00
<ButtonGroup>
<ButtonGroupItem>
<OnlyEditable let:disabled>
<IconButton
on:click={outdentListItem}
tooltip={tr.editingOutdent()}
{disabled}
>
{@html outdentIcon}
</IconButton>
</OnlyEditable>
2021-05-06 23:04:38 +02:00
</ButtonGroupItem>
2021-05-06 23:04:38 +02:00
<ButtonGroupItem>
<OnlyEditable let:disabled>
<IconButton
on:click={indentListItem}
tooltip={tr.editingIndent()}
{disabled}
>
{@html indentIcon}
</IconButton>
</OnlyEditable>
2021-05-06 23:04:38 +02:00
</ButtonGroupItem>
</ButtonGroup>
</Item>
2021-05-06 23:04:38 +02:00
</ButtonDropdown>
</WithDropdown>
2021-05-06 23:04:38 +02:00
</ButtonGroupItem>
</ButtonGroup>