2022-01-24 02:43:09 +01:00
|
|
|
<!--
|
|
|
|
Copyright: Ankitects Pty Ltd and contributors
|
|
|
|
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|
|
|
-->
|
|
|
|
<script lang="ts">
|
|
|
|
import IconButton from "../../components/IconButton.svelte";
|
|
|
|
import Shortcut from "../../components/Shortcut.svelte";
|
|
|
|
import WithState from "../../components/WithState.svelte";
|
|
|
|
import { execCommand, queryCommandState } from "../helpers";
|
2022-02-03 05:52:11 +01:00
|
|
|
import { context as noteEditorContext } from "../NoteEditor.svelte";
|
|
|
|
import { editingInputIsRichText } from "../rich-text-input";
|
2022-01-24 02:43:09 +01:00
|
|
|
|
|
|
|
export let key: string;
|
|
|
|
export let tooltip: string;
|
|
|
|
export let shortcut: string = "";
|
|
|
|
|
|
|
|
export let withoutShortcut = false;
|
|
|
|
export let withoutState = false;
|
|
|
|
|
2022-02-03 05:52:11 +01:00
|
|
|
const { focusedInput } = noteEditorContext.get();
|
2022-01-24 02:43:09 +01:00
|
|
|
|
|
|
|
function action() {
|
|
|
|
execCommand(key);
|
|
|
|
}
|
|
|
|
|
2022-02-03 05:52:11 +01:00
|
|
|
$: disabled = !editingInputIsRichText($focusedInput);
|
2022-01-24 02:43:09 +01:00
|
|
|
</script>
|
|
|
|
|
|
|
|
{#if withoutState}
|
|
|
|
<IconButton {tooltip} {disabled} on:click={action}>
|
|
|
|
<slot />
|
|
|
|
</IconButton>
|
|
|
|
|
|
|
|
{#if !withoutShortcut}
|
|
|
|
<Shortcut keyCombination={shortcut} on:click={action} />
|
|
|
|
{/if}
|
|
|
|
{:else}
|
|
|
|
<WithState
|
|
|
|
{key}
|
|
|
|
update={async () => queryCommandState(key)}
|
|
|
|
let:state={active}
|
|
|
|
let:updateState
|
|
|
|
>
|
|
|
|
<IconButton
|
|
|
|
{tooltip}
|
|
|
|
{active}
|
|
|
|
{disabled}
|
|
|
|
on:click={(event) => {
|
|
|
|
action();
|
|
|
|
updateState(event);
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<slot />
|
|
|
|
</IconButton>
|
|
|
|
|
|
|
|
{#if !withoutShortcut}
|
|
|
|
<Shortcut
|
|
|
|
keyCombination={shortcut}
|
|
|
|
on:action={(event) => {
|
|
|
|
action();
|
|
|
|
updateState(event);
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
{/if}
|
|
|
|
</WithState>
|
|
|
|
{/if}
|