diff --git a/ts/components/WithContext.svelte b/ts/components/WithContext.svelte index 111da8c1e..5cfba6123 100644 --- a/ts/components/WithContext.svelte +++ b/ts/components/WithContext.svelte @@ -6,7 +6,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html import type { Readable } from "svelte/store"; import { getContext } from "svelte"; - type T = unknown; + type T = boolean; export let key: Symbol | string; diff --git a/ts/editor/CommandIconButton.svelte b/ts/editor/CommandIconButton.svelte new file mode 100644 index 000000000..4781d2ccc --- /dev/null +++ b/ts/editor/CommandIconButton.svelte @@ -0,0 +1,79 @@ + + + + + {#if withoutShortcut && withoutState} + document.execCommand(key)}> + + + {:else if withoutShortcut} + document.queryCommandState(key)} + let:state={active} + let:updateState + > + { + document.execCommand(key); + updateState(event); + }} + > + + + + {:else if withoutState} + + document.execCommand(key)} + on:mount={createShortcut} + > + + + + {:else} + + document.queryCommandState(key)} + let:state={active} + let:updateState + > + { + document.execCommand(key); + updateState(event); + }} + on:mount={createShortcut} + > + + + + + {/if} + diff --git a/ts/editor/FormatBlockButtons.svelte b/ts/editor/FormatBlockButtons.svelte index 358b02ad5..f1d4376ea 100644 --- a/ts/editor/FormatBlockButtons.svelte +++ b/ts/editor/FormatBlockButtons.svelte @@ -11,8 +11,9 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html import IconButton from "components/IconButton.svelte"; import ButtonDropdown from "components/ButtonDropdown.svelte"; import ButtonToolbarItem from "components/ButtonToolbarItem.svelte"; - import WithState from "components/WithState.svelte"; import WithDropdownMenu from "components/WithDropdownMenu.svelte"; + import OnlyEditable from "./OnlyEditable.svelte"; + import CommandIconButton from "./CommandIconButton.svelte"; import { getListItem } from "./helpers"; import { @@ -46,134 +47,66 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html - document.queryCommandState("insertUnorderedList")} - let:state={active} - let:updateState + tooltip={tr.editingUnorderedList()} + withoutShortcut>{@html ulIcon} - { - document.execCommand("insertUnorderedList"); - updateState(event); - }} - > - {@html ulIcon} - - - document.queryCommandState("insertOrderedList")} - let:state={active} - let:updateState + tooltip={tr.editingOrderedList()} + withoutShortcut>{@html olIcon} - { - document.execCommand("insertOrderedList"); - updateState(event); - }} - > - {@html olIcon} - - - - {@html listOptionsIcon} - + + + {@html listOptionsIcon} + + - document.queryCommandState("justifyLeft")} - let:state={active} - let:updateState + tooltip={tr.editingAlignLeft()} + withoutShortcut + >{@html justifyLeftIcon} - { - document.execCommand("justifyLeft"); - updateState(event); - }} - > - {@html justifyLeftIcon} - - - - document.queryCommandState("justifyCenter")} - let:state={active} - let:updateState + tooltip={tr.editingCenter()} + withoutShortcut + >{@html justifyCenterIcon} - { - document.execCommand("justifyCenter"); - updateState(event); - }} - > - {@html justifyCenterIcon} - - - - document.queryCommandState("justifyRight")} - let:state={active} - let:updateState + tooltip={tr.editingAlignRight()} + withoutShortcut + >{@html justifyRightIcon} - { - document.execCommand("justifyRight"); - updateState(event); - }} - > - {@html justifyRightIcon} - - - document.queryCommandState("justifyFull")} - let:state={active} - let:updateState + tooltip={tr.editingJustify()} + withoutShortcut + >{@html justifyFullIcon} - { - document.execCommand("justifyFull"); - updateState(event); - }} - > - {@html justifyFullIcon} - - @@ -181,21 +114,27 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html - - {@html outdentIcon} - + + + {@html outdentIcon} + + - - {@html indentIcon} - + + + {@html indentIcon} + + diff --git a/ts/editor/FormatInlineButtons.svelte b/ts/editor/FormatInlineButtons.svelte index 1758ce1c5..47032b74e 100644 --- a/ts/editor/FormatInlineButtons.svelte +++ b/ts/editor/FormatInlineButtons.svelte @@ -7,10 +7,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html import ButtonGroup from "components/ButtonGroup.svelte"; import ButtonGroupItem from "components/ButtonGroupItem.svelte"; - import IconButton from "components/IconButton.svelte"; - import WithShortcut from "components/WithShortcut.svelte"; - import WithContext from "components/WithContext.svelte"; - import WithState from "components/WithState.svelte"; + import CommandIconButton from "./CommandIconButton.svelte"; import { boldIcon, @@ -20,157 +17,57 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html subscriptIcon, eraserIcon, } from "./icons"; - import { appendInParentheses } from "./helpers"; - import { disabledKey } from "components/contextKeys"; - import { inCodableKey } from "./contextKeys"; export let api = {}; - - - - document.queryCommandState("bold")} - let:state={active} - let:updateState - > - { - document.execCommand("bold"); - updateState(event); - }} - on:mount={createShortcut} - > - {@html boldIcon} - - - - - + {@html boldIcon} - - document.queryCommandState("italic")} - let:state={active} - let:updateState - > - { - document.execCommand("italic"); - updateState(event); - }} - on:mount={createShortcut} - > - {@html italicIcon} - - - + {@html italicIcon} - - document.queryCommandState("underline")} - let:state={active} - let:updateState - > - { - document.execCommand("underline"); - updateState(event); - }} - on:mount={createShortcut} - > - {@html underlineIcon} - - - + {@html underlineIcon} - - document.queryCommandState("superscript")} - let:state={active} - let:updateState - > - { - document.execCommand("superscript"); - updateState(event); - }} - on:mount={createShortcut} - > - {@html superscriptIcon} - - - + {@html superscriptIcon} - - document.queryCommandState("subscript")} - let:state={active} - let:updateState - > - { - document.execCommand("subscript"); - updateState(event); - }} - on:mount={createShortcut} - > - {@html subscriptIcon} - - - + {@html subscriptIcon} - - { - document.execCommand("removeFormat"); - }} - on:mount={createShortcut} - > - {@html eraserIcon} - - + {@html eraserIcon} diff --git a/ts/editor/OnlyEditable.svelte b/ts/editor/OnlyEditable.svelte new file mode 100644 index 000000000..c36bfa86d --- /dev/null +++ b/ts/editor/OnlyEditable.svelte @@ -0,0 +1,15 @@ + + + + + + + +