anki/ts/editor/FormatBlockButtons.svelte

206 lines
7.8 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 type { EditingArea } from "./editingArea";
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";
2021-05-06 23:04:38 +02:00
import ButtonToolbarItem from "components/ButtonToolbarItem.svelte";
import WithState from "components/WithState.svelte";
import WithDropdownMenu from "components/WithDropdownMenu.svelte";
import { getListItem } from "./helpers";
import {
ulIcon,
olIcon,
listOptionsIcon,
justifyFullIcon,
justifyLeftIcon,
justifyRightIcon,
justifyCenterIcon,
indentIcon,
outdentIcon,
} from "./icons";
export let api = {};
function outdentListItem() {
const currentField = document.activeElement as EditingArea;
if (getListItem(currentField.shadowRoot!)) {
document.execCommand("outdent");
}
}
function indentListItem() {
const currentField = document.activeElement as EditingArea;
if (getListItem(currentField.shadowRoot!)) {
document.execCommand("indent");
}
}
</script>
<ButtonGroup {api}>
<ButtonGroupItem>
<WithState
key="insertUnorderedList"
update={() => document.queryCommandState("insertUnorderedList")}
let:state={active}
let:updateState
>
<IconButton
tooltip={tr.editingUnorderedList()}
{active}
on:click={(event) => {
document.execCommand("insertUnorderedList");
updateState(event);
}}
>
{@html ulIcon}
</IconButton>
</WithState>
</ButtonGroupItem>
<ButtonGroupItem>
<WithState
key="insertOrderedList"
update={() => document.queryCommandState("insertOrderedList")}
let:state={active}
let:updateState
>
<IconButton
tooltip={tr.editingOrderedList()}
{active}
on:click={(event) => {
document.execCommand("insertOrderedList");
updateState(event);
}}
>
{@html olIcon}
</IconButton>
</WithState>
</ButtonGroupItem>
2021-05-06 23:04:38 +02:00
<ButtonGroupItem>
<WithDropdownMenu let:createDropdown let:menuId>
<IconButton on:mount={createDropdown}>
{@html listOptionsIcon}
</IconButton>
2021-05-06 23:04:38 +02:00
<ButtonDropdown id={menuId}>
<ButtonToolbarItem id="justify">
<ButtonGroup>
<ButtonGroupItem>
<WithState
key="justifyLeft"
update={() => document.queryCommandState("justifyLeft")}
2021-05-06 23:04:38 +02:00
let:state={active}
let:updateState
>
2021-05-06 23:04:38 +02:00
<IconButton
tooltip={tr.editingAlignLeft()}
{active}
on:click={(event) => {
document.execCommand("justifyLeft");
2021-05-06 23:04:38 +02:00
updateState(event);
}}
>
2021-05-06 23:04:38 +02:00
{@html justifyLeftIcon}
</IconButton>
</WithState>
</ButtonGroupItem>
2021-05-06 23:04:38 +02:00
<ButtonGroupItem>
<WithState
key="justifyCenter"
update={() =>
document.queryCommandState("justifyCenter")}
2021-05-06 23:04:38 +02:00
let:state={active}
let:updateState
>
2021-05-06 23:04:38 +02:00
<IconButton
tooltip={tr.editingCenter()}
{active}
on:click={(event) => {
document.execCommand("justifyCenter");
2021-05-06 23:04:38 +02:00
updateState(event);
}}
>
2021-05-06 23:04:38 +02:00
{@html justifyCenterIcon}
</IconButton>
</WithState>
</ButtonGroupItem>
2021-05-06 23:04:38 +02:00
<ButtonGroupItem>
<WithState
key="justifyRight"
update={() =>
document.queryCommandState("justifyRight")}
2021-05-06 23:04:38 +02:00
let:state={active}
let:updateState
>
2021-05-06 23:04:38 +02:00
<IconButton
tooltip={tr.editingAlignRight()}
{active}
on:click={(event) => {
document.execCommand("justifyRight");
2021-05-06 23:04:38 +02:00
updateState(event);
}}
>
2021-05-06 23:04:38 +02:00
{@html justifyRightIcon}
</IconButton>
</WithState>
</ButtonGroupItem>
2021-05-06 23:04:38 +02:00
<ButtonGroupItem>
<WithState
key="justifyFull"
update={() => document.queryCommandState("justifyFull")}
2021-05-06 23:04:38 +02:00
let:state={active}
let:updateState
>
2021-05-06 23:04:38 +02:00
<IconButton
tooltip={tr.editingJustify()}
{active}
on:click={(event) => {
document.execCommand("justifyFull");
2021-05-06 23:04:38 +02:00
updateState(event);
}}
>
2021-05-06 23:04:38 +02:00
{@html justifyFullIcon}
</IconButton>
</WithState>
</ButtonGroupItem>
</ButtonGroup>
</ButtonToolbarItem>
2021-05-06 23:04:38 +02:00
<ButtonToolbarItem id="indentation">
<ButtonGroup>
<ButtonGroupItem>
<IconButton
on:click={outdentListItem}
tooltip={tr.editingOutdent()}
>
2021-05-06 23:04:38 +02:00
{@html outdentIcon}
</IconButton>
</ButtonGroupItem>
2021-05-06 23:04:38 +02:00
<ButtonGroupItem>
<IconButton
on:click={indentListItem}
tooltip={tr.editingIndent()}
>
2021-05-06 23:04:38 +02:00
{@html indentIcon}
</IconButton>
</ButtonGroupItem>
</ButtonGroup>
</ButtonToolbarItem>
</ButtonDropdown>
</WithDropdownMenu>
</ButtonGroupItem>
</ButtonGroup>