From f534dbb8e54a2e8b47e055b91124b0a65420db1d Mon Sep 17 00:00:00 2001 From: Henrik Giesel Date: Mon, 24 Jan 2022 02:43:09 +0100 Subject: [PATCH] Separate input components into their own directories / Remove `WithShortcut` (#1613) * Put PlainTextInput into its own directory * Create a directory for RichTextInput * Create editor-toolbar directory * Move PreviewButton into editor-toolbar * The time to refactor this is not quite yet here * Create tag-editor directory * Remove some of the uses of WithShortcut * Remove all uses of WithShortcut from editor package * Remove last uses of WithShortcut * Fix typo --- ts/change-notetype/SaveButton.svelte | 21 +-- ts/components/Shortcut.svelte | 11 +- ts/components/WithShortcut.svelte | 25 --- ts/deck-options/SaveButton.svelte | 21 +-- ts/editor/ColorButtons.svelte | 107 ----------- ts/editor/CommandIconButton.svelte | 82 -------- ts/editor/MathjaxElement.svelte | 2 +- ts/editor/NoteTypeButtons.svelte | 39 ---- ts/editor/OldEditorAdapter.svelte | 14 +- ts/editor/PreviewButton.svelte | 30 --- ts/editor/SelectedTagBadge.svelte | 72 ------- ts/editor/TemplateButtons.svelte | 178 ------------------ ts/editor/base.ts | 6 +- .../{ => editor-toolbar}/AddonButtons.svelte | 4 +- .../{ => editor-toolbar}/BoldButton.svelte | 18 +- .../{ => editor-toolbar}/ClozeButton.svelte | 37 ++-- ts/editor/editor-toolbar/ColorButtons.svelte | 121 ++++++++++++ .../editor-toolbar/CommandIconButton.svelte | 66 +++++++ .../{ => editor-toolbar}/EditorToolbar.svelte | 14 +- .../FormatBlockButtons.svelte | 82 ++++---- .../FormatInlineButtons.svelte | 12 +- .../{ => editor-toolbar}/ItalicButton.svelte | 18 +- ts/editor/editor-toolbar/LatexButton.svelte | 79 ++++++++ .../editor-toolbar/NoteTypeButtons.svelte | 41 ++++ ts/editor/editor-toolbar/PreviewButton.svelte | 34 ++++ .../editor-toolbar/TemplateButtons.svelte | 70 +++++++ .../UnderlineButton.svelte | 18 +- .../WithColorHelper.svelte | 0 ts/editor/editor-toolbar/icons.ts | 34 ++++ ts/editor/editor-toolbar/index.ts | 5 + ts/editor/icons.ts | 37 ---- ts/editor/image-overlay/ImageHandle.svelte | 8 +- .../mathjax-overlay/MathjaxHandle.svelte | 12 +- .../PlainTextInput.svelte | 16 +- ts/editor/plain-text-input/index.ts | 8 + .../{ => rich-text-input}/CustomStyles.svelte | 0 .../RichTextInput.svelte | 38 ++-- .../RichTextStyles.svelte | 9 +- .../{ => rich-text-input}/SetContext.svelte | 0 .../{ => rich-text-input}/StyleLink.svelte | 0 .../{ => rich-text-input}/StyleTag.svelte | 0 ts/editor/rich-text-input/index.ts | 5 + ts/editor/surround.ts | 2 +- ts/editor/{ => tag-editor}/AddTagBadge.svelte | 39 ++-- .../{ => tag-editor}/AutocompleteItem.svelte | 2 +- ts/editor/tag-editor/SelectedTagBadge.svelte | 79 ++++++++ ts/editor/{ => tag-editor}/Tag.svelte | 2 +- .../{ => tag-editor}/TagDeleteBadge.svelte | 2 +- ts/editor/{ => tag-editor}/TagEditMode.svelte | 0 ts/editor/{ => tag-editor}/TagEditor.svelte | 10 +- ts/editor/{ => tag-editor}/TagInput.svelte | 0 .../{ => tag-editor}/TagOptionsBadge.svelte | 2 +- .../{ => tag-editor}/TagStickyBadge.svelte | 2 +- .../{ => tag-editor}/TagWithTooltip.svelte | 6 +- .../{ => tag-editor}/WithAutocomplete.svelte | 6 +- ts/editor/tag-editor/icons.ts | 9 + ts/editor/tag-editor/index.ts | 4 + ts/editor/{ => tag-editor}/tags.ts | 0 ts/editor/tsconfig.json | 10 +- 59 files changed, 779 insertions(+), 790 deletions(-) delete mode 100644 ts/components/WithShortcut.svelte delete mode 100644 ts/editor/ColorButtons.svelte delete mode 100644 ts/editor/CommandIconButton.svelte delete mode 100644 ts/editor/NoteTypeButtons.svelte delete mode 100644 ts/editor/PreviewButton.svelte delete mode 100644 ts/editor/SelectedTagBadge.svelte delete mode 100644 ts/editor/TemplateButtons.svelte rename ts/editor/{ => editor-toolbar}/AddonButtons.svelte (71%) rename ts/editor/{ => editor-toolbar}/BoldButton.svelte (81%) rename ts/editor/{ => editor-toolbar}/ClozeButton.svelte (66%) create mode 100644 ts/editor/editor-toolbar/ColorButtons.svelte create mode 100644 ts/editor/editor-toolbar/CommandIconButton.svelte rename ts/editor/{ => editor-toolbar}/EditorToolbar.svelte (84%) rename ts/editor/{ => editor-toolbar}/FormatBlockButtons.svelte (63%) rename ts/editor/{ => editor-toolbar}/FormatInlineButtons.svelte (82%) rename ts/editor/{ => editor-toolbar}/ItalicButton.svelte (81%) create mode 100644 ts/editor/editor-toolbar/LatexButton.svelte create mode 100644 ts/editor/editor-toolbar/NoteTypeButtons.svelte create mode 100644 ts/editor/editor-toolbar/PreviewButton.svelte create mode 100644 ts/editor/editor-toolbar/TemplateButtons.svelte rename ts/editor/{ => editor-toolbar}/UnderlineButton.svelte (77%) rename ts/editor/{ => editor-toolbar}/WithColorHelper.svelte (100%) create mode 100644 ts/editor/editor-toolbar/icons.ts create mode 100644 ts/editor/editor-toolbar/index.ts rename ts/editor/{ => plain-text-input}/PlainTextInput.svelte (88%) create mode 100644 ts/editor/plain-text-input/index.ts rename ts/editor/{ => rich-text-input}/CustomStyles.svelte (100%) rename ts/editor/{ => rich-text-input}/RichTextInput.svelte (88%) rename ts/editor/{ => rich-text-input}/RichTextStyles.svelte (96%) rename ts/editor/{ => rich-text-input}/SetContext.svelte (100%) rename ts/editor/{ => rich-text-input}/StyleLink.svelte (100%) rename ts/editor/{ => rich-text-input}/StyleTag.svelte (100%) create mode 100644 ts/editor/rich-text-input/index.ts rename ts/editor/{ => tag-editor}/AddTagBadge.svelte (54%) rename ts/editor/{ => tag-editor}/AutocompleteItem.svelte (97%) create mode 100644 ts/editor/tag-editor/SelectedTagBadge.svelte rename ts/editor/{ => tag-editor}/Tag.svelte (97%) rename ts/editor/{ => tag-editor}/TagDeleteBadge.svelte (87%) rename ts/editor/{ => tag-editor}/TagEditMode.svelte (100%) rename ts/editor/{ => tag-editor}/TagEditor.svelte (98%) rename ts/editor/{ => tag-editor}/TagInput.svelte (100%) rename ts/editor/{ => tag-editor}/TagOptionsBadge.svelte (98%) rename ts/editor/{ => tag-editor}/TagStickyBadge.svelte (87%) rename ts/editor/{ => tag-editor}/TagWithTooltip.svelte (94%) rename ts/editor/{ => tag-editor}/WithAutocomplete.svelte (97%) create mode 100644 ts/editor/tag-editor/icons.ts create mode 100644 ts/editor/tag-editor/index.ts rename ts/editor/{ => tag-editor}/tags.ts (100%) diff --git a/ts/change-notetype/SaveButton.svelte b/ts/change-notetype/SaveButton.svelte index 83b2e94c9..e5f79007b 100644 --- a/ts/change-notetype/SaveButton.svelte +++ b/ts/change-notetype/SaveButton.svelte @@ -5,13 +5,12 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html - - save()} - tooltip={shortcutLabel} - on:mount={withButton(createShortcut)}>{tr.actionsSave()} - + {tr.actionsSave()} + diff --git a/ts/components/Shortcut.svelte b/ts/components/Shortcut.svelte index 42e54ba4b..8547cb964 100644 --- a/ts/components/Shortcut.svelte +++ b/ts/components/Shortcut.svelte @@ -5,17 +5,16 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html diff --git a/ts/components/WithShortcut.svelte b/ts/components/WithShortcut.svelte deleted file mode 100644 index 369f5b1cf..000000000 --- a/ts/components/WithShortcut.svelte +++ /dev/null @@ -1,25 +0,0 @@ - - - - diff --git a/ts/deck-options/SaveButton.svelte b/ts/deck-options/SaveButton.svelte index fca32e7b8..790ab50db 100644 --- a/ts/deck-options/SaveButton.svelte +++ b/ts/deck-options/SaveButton.svelte @@ -7,7 +7,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html import { createEventDispatcher } from "svelte"; import type { DeckOptionsState } from "./lib"; import type Dropdown from "bootstrap/js/dist/dropdown"; - import { withButton } from "../components/helpers"; + import { getPlatformString } from "../lib/shortcuts"; import { withCollapsedWhitespace } from "../lib/i18n"; import ButtonGroup from "../components/ButtonGroup.svelte"; @@ -18,7 +18,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html import DropdownItem from "../components/DropdownItem.svelte"; import DropdownDivider from "../components/DropdownDivider.svelte"; import WithDropdown from "../components/WithDropdown.svelte"; - import WithShortcut from "../components/WithShortcut.svelte"; + import Shortcut from "../components/Shortcut.svelte"; const dispatch = createEventDispatcher(); @@ -58,19 +58,18 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html } let dropdown: Dropdown; + const saveKeyCombination = "Control+Enter"; - - save(false)} - tooltip={shortcutLabel} - on:mount={withButton(createShortcut)} - >{tr.deckConfigSaveButton()} - + save(false)} + tooltip={getPlatformString(saveKeyCombination)} + >{tr.deckConfigSaveButton()} + save(false)} /> diff --git a/ts/editor/ColorButtons.svelte b/ts/editor/ColorButtons.svelte deleted file mode 100644 index 600ad54b7..000000000 --- a/ts/editor/ColorButtons.svelte +++ /dev/null @@ -1,107 +0,0 @@ - - - - - - - - - {@html textColorIcon} - {@html colorHelperIcon} - - - - - - - - {@html arrowIcon} - { - const textColor = setColor(event); - bridgeCommand(`lastTextColor:${textColor}`); - forecolorWrap = wrapWithForecolor(setColor(event)); - forecolorWrap(); - }} - on:mount={withButton(createShortcut)} - /> - - - - - - - - - {@html highlightColorIcon} - {@html colorHelperIcon} - - - - - - {@html arrowIcon} - { - const highlightColor = setColor(event); - bridgeCommand(`lastHighlightColor:${highlightColor}`); - backcolorWrap = wrapWithBackcolor(highlightColor); - backcolorWrap(); - }} - /> - - - - diff --git a/ts/editor/CommandIconButton.svelte b/ts/editor/CommandIconButton.svelte deleted file mode 100644 index 4404b7c8d..000000000 --- a/ts/editor/CommandIconButton.svelte +++ /dev/null @@ -1,82 +0,0 @@ - - - -{#if withoutShortcut && withoutState} - execCommand(key)}> - - -{:else if withoutShortcut} - queryCommandState(key)} - let:state={active} - let:updateState - > - { - execCommand(key); - updateState(event); - }} - > - - - -{:else if withoutState} - - execCommand(key)} - on:mount={withButton(createShortcut)} - > - - - -{:else} - - queryCommandState(key)} - let:state={active} - let:updateState - > - { - execCommand(key); - updateState(event); - }} - on:mount={withButton(createShortcut)} - > - - - - -{/if} diff --git a/ts/editor/MathjaxElement.svelte b/ts/editor/MathjaxElement.svelte index 8e6794248..774f42222 100644 --- a/ts/editor/MathjaxElement.svelte +++ b/ts/editor/MathjaxElement.svelte @@ -9,7 +9,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html const decoratedElements = getDecoratedElements(); decoratedElements.push(Mathjax); - import { parsingInstructions } from "./PlainTextInput.svelte"; + import { parsingInstructions } from "./plain-text-input"; parsingInstructions.push(""); diff --git a/ts/editor/NoteTypeButtons.svelte b/ts/editor/NoteTypeButtons.svelte deleted file mode 100644 index a95e4e768..000000000 --- a/ts/editor/NoteTypeButtons.svelte +++ /dev/null @@ -1,39 +0,0 @@ - - - - - - bridgeCommand("fields")} - > - {tr.editingFields()}... - - - - - - bridgeCommand("cards")} - on:mount={withButton(createShortcut)} - > - {tr.editingCards()}... - - - - diff --git a/ts/editor/OldEditorAdapter.svelte b/ts/editor/OldEditorAdapter.svelte index 5cacd0e67..1a5ea8099 100644 --- a/ts/editor/OldEditorAdapter.svelte +++ b/ts/editor/OldEditorAdapter.svelte @@ -4,9 +4,9 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html --> - - - - - bridgeCommand("preview")} - on:mount={withButton(createShortcut)} - > - {tr.actionsPreview()} - - diff --git a/ts/editor/SelectedTagBadge.svelte b/ts/editor/SelectedTagBadge.svelte deleted file mode 100644 index 795ad3a81..000000000 --- a/ts/editor/SelectedTagBadge.svelte +++ /dev/null @@ -1,72 +0,0 @@ - - - - -
- {@html dotsIcon} - - - - { - dispatch("tagselectall"); - event.stopImmediatePropagation(); - }} - on:mount={withButton(createShortcut)} - >{allLabel} ({shortcutLabel}) - - - dispatch("tagcopy")} - on:mount={withButton(createShortcut)} - >{copyLabel} ({shortcutLabel}) - - - dispatch("tagdelete")} - on:mount={withButton(createShortcut)} - >{removeLabel} ({shortcutLabel}) - - -
-
- - diff --git a/ts/editor/TemplateButtons.svelte b/ts/editor/TemplateButtons.svelte deleted file mode 100644 index cd7683786..000000000 --- a/ts/editor/TemplateButtons.svelte +++ /dev/null @@ -1,178 +0,0 @@ - - - - - - - - {@html paperclipIcon} - - - - - - - - {@html micIcon} - - - - - - - - - - - - {@html functionIcon} - - - - - - surround("", "")} - on:mount={withButton(createShortcut)} - > - {tr.editingMathjaxInline()} - {shortcutLabel} - - - - - - surround( - '', - "", - )} - on:mount={withButton(createShortcut)} - > - {tr.editingMathjaxBlock()} - {shortcutLabel} - - - - - - surround( - "\\ce{", - "}", - )} - on:mount={withButton(createShortcut)} - > - {tr.editingMathjaxChemistry()} - {shortcutLabel} - - - - - surround("[latex]", "[/latex]")} - on:mount={withButton(createShortcut)} - > - {tr.editingLatex()} - {shortcutLabel} - - - - - surround("[$]", "[/$]")} - on:mount={withButton(createShortcut)} - > - {tr.editingLatexEquation()} - {shortcutLabel} - - - - - surround("[$$]", "[/$$]")} - on:mount={withButton(createShortcut)} - > - {tr.editingLatexMathEnv()} - {shortcutLabel} - - - - - - diff --git a/ts/editor/base.ts b/ts/editor/base.ts index a6963991a..7159f2e80 100644 --- a/ts/editor/base.ts +++ b/ts/editor/base.ts @@ -28,11 +28,8 @@ export const editorModules = [ ModuleName.BROWSING, ]; -export { editorToolbar } from "./EditorToolbar.svelte"; - import IconButton from "../components/IconButton.svelte"; import LabelButton from "../components/LabelButton.svelte"; -import WithShortcut from "../components/WithShortcut.svelte"; import WithContext from "../components/WithContext.svelte"; import WithState from "../components/WithState.svelte"; @@ -42,8 +39,9 @@ import * as editorContextKeys from "./NoteEditor.svelte"; export const components = { IconButton, LabelButton, - WithShortcut, WithContext, WithState, contextKeys: { ...contextKeys, ...editorContextKeys }, }; + +export { editorToolbar } from "./editor-toolbar"; diff --git a/ts/editor/AddonButtons.svelte b/ts/editor/editor-toolbar/AddonButtons.svelte similarity index 71% rename from ts/editor/AddonButtons.svelte rename to ts/editor/editor-toolbar/AddonButtons.svelte index 4fd6201ae..8c38b60c9 100644 --- a/ts/editor/AddonButtons.svelte +++ b/ts/editor/editor-toolbar/AddonButtons.svelte @@ -3,8 +3,8 @@ Copyright: Ankitects Pty Ltd and contributors License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html --> diff --git a/ts/editor/BoldButton.svelte b/ts/editor/editor-toolbar/BoldButton.svelte similarity index 81% rename from ts/editor/BoldButton.svelte rename to ts/editor/editor-toolbar/BoldButton.svelte index e7092b215..4b83a70f3 100644 --- a/ts/editor/BoldButton.svelte +++ b/ts/editor/editor-toolbar/BoldButton.svelte @@ -3,16 +3,16 @@ Copyright: Ankitects Pty Ltd and contributors License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html --> - - - {@html ellipseIcon} - - + + {@html ellipseIcon} + + + onCloze(event.detail.originalEvent)} /> diff --git a/ts/editor/editor-toolbar/ColorButtons.svelte b/ts/editor/editor-toolbar/ColorButtons.svelte new file mode 100644 index 000000000..c061e0250 --- /dev/null +++ b/ts/editor/editor-toolbar/ColorButtons.svelte @@ -0,0 +1,121 @@ + + + + + + + + {@html textColorIcon} + {@html colorHelperIcon} + + + + + + + {@html arrowIcon} + { + const textColor = setColor(event); + bridgeCommand(`lastTextColor:${textColor}`); + forecolorWrap = wrapWithForecolor(setColor(event)); + forecolorWrap(); + }} + /> + + { + const textColor = setColor(event); + bridgeCommand(`lastTextColor:${textColor}`); + forecolorWrap = wrapWithForecolor(setColor(event)); + forecolorWrap(); + }} + /> + + + + + + + {@html highlightColorIcon} + {@html colorHelperIcon} + + + + + + {@html arrowIcon} + { + const highlightColor = setColor(event); + bridgeCommand(`lastHighlightColor:${highlightColor}`); + backcolorWrap = wrapWithBackcolor(highlightColor); + backcolorWrap(); + }} + /> + + + + diff --git a/ts/editor/editor-toolbar/CommandIconButton.svelte b/ts/editor/editor-toolbar/CommandIconButton.svelte new file mode 100644 index 000000000..595fec729 --- /dev/null +++ b/ts/editor/editor-toolbar/CommandIconButton.svelte @@ -0,0 +1,66 @@ + + + +{#if withoutState} + + + + + {#if !withoutShortcut} + + {/if} +{:else} + queryCommandState(key)} + let:state={active} + let:updateState + > + { + action(); + updateState(event); + }} + > + + + + {#if !withoutShortcut} + { + action(); + updateState(event); + }} + /> + {/if} + +{/if} diff --git a/ts/editor/EditorToolbar.svelte b/ts/editor/editor-toolbar/EditorToolbar.svelte similarity index 84% rename from ts/editor/EditorToolbar.svelte rename to ts/editor/editor-toolbar/EditorToolbar.svelte index 1011f689b..fa3e0b990 100644 --- a/ts/editor/EditorToolbar.svelte +++ b/ts/editor/editor-toolbar/EditorToolbar.svelte @@ -3,11 +3,9 @@ Copyright: Ankitects Pty Ltd and contributors License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html --> + + + + {@html functionIcon} + + + + {#each dropdownItems as [callback, keyCombination, label]} + + {label} + {getPlatformString(keyCombination)} + + + {/each} + + diff --git a/ts/editor/editor-toolbar/NoteTypeButtons.svelte b/ts/editor/editor-toolbar/NoteTypeButtons.svelte new file mode 100644 index 000000000..4f211ce71 --- /dev/null +++ b/ts/editor/editor-toolbar/NoteTypeButtons.svelte @@ -0,0 +1,41 @@ + + + + + + bridgeCommand("fields")} + > + {tr.editingFields()}... + + + + + bridgeCommand("cards")} + > + {tr.editingCards()}... + + bridgeCommand("cards")} /> + + diff --git a/ts/editor/editor-toolbar/PreviewButton.svelte b/ts/editor/editor-toolbar/PreviewButton.svelte new file mode 100644 index 000000000..e6ee03f60 --- /dev/null +++ b/ts/editor/editor-toolbar/PreviewButton.svelte @@ -0,0 +1,34 @@ + + + + + + + {tr.actionsPreview()} + + + diff --git a/ts/editor/editor-toolbar/TemplateButtons.svelte b/ts/editor/editor-toolbar/TemplateButtons.svelte new file mode 100644 index 000000000..fafff458b --- /dev/null +++ b/ts/editor/editor-toolbar/TemplateButtons.svelte @@ -0,0 +1,70 @@ + + + + + + + {@html paperclipIcon} + + + + + + + {@html micIcon} + + + + + + + + + + + + diff --git a/ts/editor/UnderlineButton.svelte b/ts/editor/editor-toolbar/UnderlineButton.svelte similarity index 77% rename from ts/editor/UnderlineButton.svelte rename to ts/editor/editor-toolbar/UnderlineButton.svelte index 607963c4f..6346205ef 100644 --- a/ts/editor/UnderlineButton.svelte +++ b/ts/editor/editor-toolbar/UnderlineButton.svelte @@ -3,16 +3,16 @@ Copyright: Ankitects Pty Ltd and contributors License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html --> - -
- - {@html tagIcon} - {@html addTagIcon} - -
-
+
+ + {@html tagIcon} + {@html addTagIcon} + + + +
diff --git a/ts/editor/Tag.svelte b/ts/editor/tag-editor/Tag.svelte similarity index 97% rename from ts/editor/Tag.svelte rename to ts/editor/tag-editor/Tag.svelte index 3b73fe0e6..89934a8f3 100644 --- a/ts/editor/Tag.svelte +++ b/ts/editor/tag-editor/Tag.svelte @@ -4,7 +4,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html -->