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-10-26 04:35:49 +02:00
|
|
|
import { onMount } from "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-09-05 09:20:00 +02:00
|
|
|
import ButtonToolbar from "../../components/ButtonToolbar.svelte";
|
2022-02-04 09:36:34 +01:00
|
|
|
import DynamicallySlottable from "../../components/DynamicallySlottable.svelte";
|
|
|
|
import IconButton from "../../components/IconButton.svelte";
|
2022-09-05 09:20:00 +02:00
|
|
|
import Popover from "../../components/Popover.svelte";
|
|
|
|
import WithFloating from "../../components/WithFloating.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-10-26 04:35:49 +02:00
|
|
|
import { preventDefault } from "../../lib/events";
|
2022-02-04 09:36:34 +01:00
|
|
|
import * as tr from "../../lib/ftl";
|
2022-10-26 04:35:49 +02:00
|
|
|
import { getPlatformString, registerShortcut } 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-10-26 04:35:49 +02:00
|
|
|
onMount(() => {
|
|
|
|
registerShortcut((event: KeyboardEvent) => {
|
|
|
|
preventDefault(event);
|
|
|
|
indentListItem();
|
|
|
|
}, indentKeyCombination);
|
|
|
|
registerShortcut((event: KeyboardEvent) => {
|
|
|
|
preventDefault(event);
|
|
|
|
outdentListItem();
|
|
|
|
}, outdentKeyCombination);
|
|
|
|
});
|
|
|
|
|
2022-02-03 05:52:11 +01:00
|
|
|
const { focusedInput } = context.get();
|
2022-09-05 09:20:00 +02:00
|
|
|
|
2022-10-27 01:11:36 +02:00
|
|
|
$: disabled = !$focusedInput || !editingInputIsRichText($focusedInput);
|
2022-09-05 09:20:00 +02:00
|
|
|
|
|
|
|
let showFloating = false;
|
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>
|
2022-09-05 09:20:00 +02:00
|
|
|
<WithFloating
|
|
|
|
show={showFloating && !disabled}
|
|
|
|
inline
|
|
|
|
on:close={() => (showFloating = false)}
|
|
|
|
let:asReference
|
|
|
|
>
|
|
|
|
<span class="block-buttons" use:asReference>
|
|
|
|
<IconButton
|
|
|
|
{disabled}
|
|
|
|
on:click={() => (showFloating = !showFloating)}
|
|
|
|
>
|
|
|
|
{@html listOptionsIcon}
|
|
|
|
</IconButton>
|
|
|
|
</span>
|
|
|
|
|
2022-09-10 10:46:59 +02:00
|
|
|
<Popover slot="floating" --popover-padding-inline="0">
|
2022-09-05 09:20:00 +02:00
|
|
|
<ButtonToolbar wrap={false}>
|
|
|
|
<ButtonGroup>
|
|
|
|
<CommandIconButton
|
|
|
|
key="justifyLeft"
|
|
|
|
tooltip={tr.editingAlignLeft()}
|
|
|
|
--border-left-radius="5px"
|
|
|
|
--border-right-radius="0px"
|
|
|
|
>{@html justifyLeftIcon}</CommandIconButton
|
|
|
|
>
|
|
|
|
|
|
|
|
<CommandIconButton
|
|
|
|
key="justifyCenter"
|
|
|
|
tooltip={tr.editingCenter()}
|
|
|
|
>{@html justifyCenterIcon}</CommandIconButton
|
|
|
|
>
|
|
|
|
|
|
|
|
<CommandIconButton
|
|
|
|
key="justifyRight"
|
|
|
|
tooltip={tr.editingAlignRight()}
|
|
|
|
>{@html justifyRightIcon}</CommandIconButton
|
|
|
|
>
|
|
|
|
|
|
|
|
<CommandIconButton
|
|
|
|
key="justifyFull"
|
|
|
|
tooltip={tr.editingJustify()}
|
|
|
|
--border-right-radius="5px"
|
|
|
|
>{@html justifyFullIcon}</CommandIconButton
|
|
|
|
>
|
|
|
|
</ButtonGroup>
|
|
|
|
|
|
|
|
<ButtonGroup>
|
|
|
|
<IconButton
|
|
|
|
tooltip="{tr.editingOutdent()} ({getPlatformString(
|
|
|
|
outdentKeyCombination,
|
|
|
|
)})"
|
|
|
|
{disabled}
|
|
|
|
on:click={outdentListItem}
|
|
|
|
--border-left-radius="5px"
|
|
|
|
--border-right-radius="0px"
|
|
|
|
>
|
|
|
|
{@html outdentIcon}
|
|
|
|
</IconButton>
|
|
|
|
|
|
|
|
<IconButton
|
|
|
|
tooltip="{tr.editingIndent()} ({getPlatformString(
|
|
|
|
indentKeyCombination,
|
|
|
|
)})"
|
|
|
|
{disabled}
|
|
|
|
on:click={indentListItem}
|
|
|
|
--border-right-radius="5px"
|
|
|
|
>
|
|
|
|
{@html indentIcon}
|
|
|
|
</IconButton>
|
|
|
|
</ButtonGroup>
|
|
|
|
</ButtonToolbar>
|
|
|
|
</Popover>
|
|
|
|
</WithFloating>
|
2022-02-03 05:52:11 +01:00
|
|
|
</ButtonGroupItem>
|
|
|
|
</DynamicallySlottable>
|
2021-04-28 02:27:38 +02:00
|
|
|
</ButtonGroup>
|
2022-09-05 09:20:00 +02:00
|
|
|
|
|
|
|
<style lang="scss">
|
|
|
|
.block-buttons {
|
|
|
|
line-height: 1;
|
|
|
|
}
|
|
|
|
</style>
|