2021-04-28 02:27:38 +02:00
|
|
|
<!--
|
|
|
|
Copyright: Ankitects Pty Ltd and contributors
|
|
|
|
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|
|
|
-->
|
2021-10-26 00:43:02 +02:00
|
|
|
<script lang="ts">
|
2022-01-24 02:43:09 +01:00
|
|
|
import ButtonDropdown from "../../components/ButtonDropdown.svelte";
|
2022-02-04 09:36:34 +01:00
|
|
|
import ButtonGroup from "../../components/ButtonGroup.svelte";
|
2022-02-03 05:52:11 +01:00
|
|
|
import ButtonGroupItem, {
|
|
|
|
createProps,
|
|
|
|
setSlotHostContext,
|
2022-02-04 09:36:34 +01:00
|
|
|
updatePropsList,
|
2022-02-03 05:52:11 +01:00
|
|
|
} from "../../components/ButtonGroupItem.svelte";
|
2022-02-04 09:36:34 +01:00
|
|
|
import DynamicallySlottable from "../../components/DynamicallySlottable.svelte";
|
|
|
|
import IconButton from "../../components/IconButton.svelte";
|
|
|
|
import Shortcut from "../../components/Shortcut.svelte";
|
|
|
|
import WithDropdown from "../../components/WithDropdown.svelte";
|
2022-06-01 12:26:16 +02:00
|
|
|
import { execCommand } from "../../domlib";
|
2022-01-24 02:43:09 +01:00
|
|
|
import { getListItem } from "../../lib/dom";
|
2022-02-04 09:36:34 +01:00
|
|
|
import * as tr from "../../lib/ftl";
|
2022-01-24 02:43:09 +01:00
|
|
|
import { getPlatformString } from "../../lib/shortcuts";
|
2022-02-04 09:36:34 +01:00
|
|
|
import { context } from "../NoteEditor.svelte";
|
|
|
|
import { editingInputIsRichText } from "../rich-text-input";
|
|
|
|
import CommandIconButton from "./CommandIconButton.svelte";
|
2021-04-28 02:27:38 +02:00
|
|
|
import {
|
2022-02-04 09:36:34 +01:00
|
|
|
indentIcon,
|
|
|
|
justifyCenterIcon,
|
2021-04-28 02:27:38 +02:00
|
|
|
justifyFullIcon,
|
|
|
|
justifyLeftIcon,
|
|
|
|
justifyRightIcon,
|
2022-02-04 09:36:34 +01:00
|
|
|
listOptionsIcon,
|
|
|
|
olIcon,
|
2021-04-28 02:27:38 +02:00
|
|
|
outdentIcon,
|
2022-02-04 09:36:34 +01:00
|
|
|
ulIcon,
|
2021-04-28 02:27:38 +02:00
|
|
|
} from "./icons";
|
|
|
|
|
|
|
|
export let api = {};
|
|
|
|
|
2022-01-24 02:43:09 +01:00
|
|
|
const outdentKeyCombination = "Control+Shift+,";
|
2021-04-28 02:27:38 +02:00
|
|
|
function outdentListItem() {
|
2021-10-18 14:01:15 +02:00
|
|
|
if (getListItem(document.activeElement!.shadowRoot!)) {
|
2021-09-28 03:04:10 +02:00
|
|
|
execCommand("outdent");
|
2021-07-28 04:18:04 +02:00
|
|
|
} else {
|
|
|
|
alert("Indent/unindent currently only works with lists.");
|
2021-04-28 02:27:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-24 02:43:09 +01:00
|
|
|
const indentKeyCombination = "Control+Shift+.";
|
2021-04-28 02:27:38 +02:00
|
|
|
function indentListItem() {
|
2021-10-18 14:01:15 +02:00
|
|
|
if (getListItem(document.activeElement!.shadowRoot!)) {
|
2021-09-28 03:04:10 +02:00
|
|
|
execCommand("indent");
|
2021-07-28 04:18:04 +02:00
|
|
|
} else {
|
|
|
|
alert("Indent/unindent currently only works with lists.");
|
2021-04-28 02:27:38 +02:00
|
|
|
}
|
|
|
|
}
|
2021-10-18 14:01:15 +02:00
|
|
|
|
2022-02-03 05:52:11 +01:00
|
|
|
const { focusedInput } = context.get();
|
|
|
|
$: disabled = !editingInputIsRichText($focusedInput);
|
2021-04-28 02:27:38 +02:00
|
|
|
</script>
|
|
|
|
|
2022-02-03 05:52:11 +01:00
|
|
|
<ButtonGroup>
|
|
|
|
<DynamicallySlottable
|
|
|
|
slotHost={ButtonGroupItem}
|
|
|
|
{createProps}
|
|
|
|
{updatePropsList}
|
|
|
|
{setSlotHostContext}
|
|
|
|
{api}
|
|
|
|
>
|
|
|
|
<ButtonGroupItem>
|
|
|
|
<CommandIconButton
|
|
|
|
key="insertUnorderedList"
|
|
|
|
tooltip={tr.editingUnorderedList()}
|
|
|
|
shortcut="Control+,">{@html ulIcon}</CommandIconButton
|
2021-10-18 14:01:15 +02:00
|
|
|
>
|
2022-02-03 05:52:11 +01:00
|
|
|
</ButtonGroupItem>
|
2021-04-28 02:27:38 +02:00
|
|
|
|
2022-02-03 05:52:11 +01:00
|
|
|
<ButtonGroupItem>
|
|
|
|
<CommandIconButton
|
|
|
|
key="insertOrderedList"
|
|
|
|
tooltip={tr.editingOrderedList()}
|
|
|
|
shortcut="Control+.">{@html olIcon}</CommandIconButton
|
|
|
|
>
|
|
|
|
</ButtonGroupItem>
|
|
|
|
|
|
|
|
<ButtonGroupItem>
|
|
|
|
<WithDropdown let:createDropdown>
|
|
|
|
<IconButton
|
|
|
|
{disabled}
|
|
|
|
on:mount={(event) => createDropdown(event.detail.button)}
|
|
|
|
>
|
|
|
|
{@html listOptionsIcon}
|
|
|
|
</IconButton>
|
|
|
|
|
|
|
|
<ButtonDropdown>
|
2022-03-31 05:30:00 +02:00
|
|
|
<ButtonGroup>
|
|
|
|
<CommandIconButton
|
|
|
|
key="justifyLeft"
|
|
|
|
tooltip={tr.editingAlignLeft()}
|
|
|
|
--border-left-radius="5px"
|
|
|
|
--border-right-radius="0px"
|
|
|
|
>{@html justifyLeftIcon}</CommandIconButton
|
|
|
|
>
|
2021-04-28 02:27:38 +02:00
|
|
|
|
2022-03-31 05:30:00 +02:00
|
|
|
<CommandIconButton
|
|
|
|
key="justifyCenter"
|
|
|
|
tooltip={tr.editingCenter()}
|
|
|
|
>{@html justifyCenterIcon}</CommandIconButton
|
|
|
|
>
|
2021-04-28 02:27:38 +02:00
|
|
|
|
2022-03-31 05:30:00 +02:00
|
|
|
<CommandIconButton
|
|
|
|
key="justifyRight"
|
|
|
|
tooltip={tr.editingAlignRight()}
|
|
|
|
>{@html justifyRightIcon}</CommandIconButton
|
|
|
|
>
|
2021-04-28 02:27:38 +02:00
|
|
|
|
2022-03-31 05:30:00 +02:00
|
|
|
<CommandIconButton
|
|
|
|
key="justifyFull"
|
|
|
|
tooltip={tr.editingJustify()}
|
|
|
|
--border-right-radius="5px"
|
|
|
|
>{@html justifyFullIcon}</CommandIconButton
|
|
|
|
>
|
|
|
|
</ButtonGroup>
|
2021-04-28 02:27:38 +02:00
|
|
|
|
2022-03-31 05:30:00 +02:00
|
|
|
<ButtonGroup>
|
|
|
|
<IconButton
|
|
|
|
tooltip="{tr.editingOutdent()} ({getPlatformString(
|
|
|
|
outdentKeyCombination,
|
|
|
|
)})"
|
|
|
|
{disabled}
|
|
|
|
on:click={outdentListItem}
|
|
|
|
--border-left-radius="5px"
|
|
|
|
--border-right-radius="0px"
|
|
|
|
>
|
|
|
|
{@html outdentIcon}
|
|
|
|
</IconButton>
|
2022-01-24 02:43:09 +01:00
|
|
|
|
2022-03-31 05:30:00 +02:00
|
|
|
<Shortcut
|
|
|
|
keyCombination={outdentKeyCombination}
|
|
|
|
on:action={outdentListItem}
|
|
|
|
/>
|
2021-04-28 02:27:38 +02:00
|
|
|
|
2022-03-31 05:30:00 +02:00
|
|
|
<IconButton
|
|
|
|
tooltip="{tr.editingIndent()} ({getPlatformString(
|
|
|
|
indentKeyCombination,
|
|
|
|
)})"
|
|
|
|
{disabled}
|
|
|
|
on:click={indentListItem}
|
|
|
|
--border-right-radius="5px"
|
|
|
|
>
|
|
|
|
{@html indentIcon}
|
|
|
|
</IconButton>
|
2022-01-24 02:43:09 +01:00
|
|
|
|
2022-03-31 05:30:00 +02:00
|
|
|
<Shortcut
|
|
|
|
keyCombination={indentKeyCombination}
|
|
|
|
on:action={indentListItem}
|
|
|
|
/>
|
|
|
|
</ButtonGroup>
|
2022-02-03 05:52:11 +01:00
|
|
|
</ButtonDropdown>
|
|
|
|
</WithDropdown>
|
|
|
|
</ButtonGroupItem>
|
|
|
|
</DynamicallySlottable>
|
2021-04-28 02:27:38 +02:00
|
|
|
</ButtonGroup>
|