From 4e08b75040b8322afdc129a4b45cfc0be7b64852 Mon Sep 17 00:00:00 2001 From: Anna No Date: Tue, 10 Oct 2023 00:26:09 +0700 Subject: [PATCH] QMS: Update inline comments extensions (#3814) * update documents inline comments extensions Signed-off-by: Anna No * update qms documents inline comments Signed-off-by: Anna No * qms: update document inline comments extensions Signed-off-by: Anna No * qms: move highlight to prose mirror decorations Signed-off-by: Anna No * fix formatting issues Signed-off-by: Anna No * fix formatting issues Signed-off-by: Anna No * fix formatting issues Signed-off-by: Anna No * fix formatting issues Signed-off-by: Anna No --------- Signed-off-by: Anna No --- .../src/components/CollaboratorEditor.svelte | 51 ++++---- .../src/components/TextEditor.svelte | 21 +--- .../components/TextEditorStyleToolbar.svelte | 2 +- .../src/components/extension/inlinePopup.ts | 16 +++ .../extension/inlineStyleToolbar.ts | 103 +++++++++++----- .../src/components/extension/nodeHighlight.ts | 115 +++++++++++++----- .../src/components/extension/nodeUuid.ts | 87 +++++++++---- packages/text-editor/src/index.ts | 7 ++ packages/theme/styles/_colors.scss | 5 +- packages/theme/styles/_text-editor.scss | 10 +- 10 files changed, 282 insertions(+), 135 deletions(-) create mode 100644 packages/text-editor/src/components/extension/inlinePopup.ts diff --git a/packages/text-editor/src/components/CollaboratorEditor.svelte b/packages/text-editor/src/components/CollaboratorEditor.svelte index 4b75f4997e..b748a8b5ee 100644 --- a/packages/text-editor/src/components/CollaboratorEditor.svelte +++ b/packages/text-editor/src/components/CollaboratorEditor.svelte @@ -35,7 +35,7 @@ import { calculateDecorations } from './diff/decorations' import { defaultEditorAttributes } from './editor/editorProps' import { completionConfig, defaultExtensions } from './extensions' - import { InlineStyleToolbar } from './extension/inlineStyleToolbar' + import { InlineStyleToolbarExtension } from './extension/inlineStyleToolbar' import { NodeUuidExtension } from './extension/nodeUuid' import StyleButton from './StyleButton.svelte' import TextEditorStyleToolbar from './TextEditorStyleToolbar.svelte' @@ -47,7 +47,6 @@ export let token: string export let collaboratorURL: string - export let isFormatting = true export let buttonSize: IconSize = 'small' export let focusable: boolean = false export let placeholder: IntlString = textEditorPlugin.string.EditorPlaceholder @@ -90,7 +89,6 @@ let editor: Editor let inlineToolbar: HTMLElement - let showInlineToolbar = false let placeHolderStr: string = '' @@ -136,7 +134,6 @@ } const [$start, $end] = [doc.resolve(range.from), doc.resolve(range.to)] - editor.view.dispatch(tr.setSelection(new TextSelection($start, $end))) needFocus = true }) @@ -146,6 +143,22 @@ provider.copyContent(documentId, snapshotId) } + export function unregisterPlugin (nameOrPluginKey: string | PluginKey) { + if (!editor) { + return + } + + editor.unregisterPlugin(nameOrPluginKey) + } + + export function registerPlugin (plugin: Plugin) { + if (!editor) { + return + } + + editor.registerPlugin(plugin) + } + let needFocus = false let focused = false @@ -201,6 +214,7 @@ }) $: updateEditor(editor, field, comparedVersion) + $: if (editor) dispatch('editor', editor) onMount(() => { ph.then(() => { @@ -211,10 +225,10 @@ extensions: [ ...defaultExtensions, Placeholder.configure({ placeholder: placeHolderStr }), - InlineStyleToolbar.configure({ + InlineStyleToolbarExtension.configure({ element: inlineToolbar, - getEditorElement: () => element, - isShown: () => !readonly && showInlineToolbar + isSupported: () => !readonly, + isSelectionOnly: () => false }), Collaboration.configure({ document: ydoc, @@ -247,22 +261,14 @@ onFocus: () => { focused = true }, - onUpdate: ({ editor, transaction }) => { - showInlineToolbar = false - + onUpdate: ({ transaction }) => { // ignore non-document changes if (!transaction.docChanged) return - // TODO this is heavy and should be replaced with more lightweight event - dispatch('content', editor.getHTML()) - // ignore non-local changes if (isChangeOrigin(transaction)) return dispatch('update') - }, - onSelectionUpdate: () => { - showInlineToolbar = false } }) @@ -283,16 +289,11 @@ } }) - function onEditorClick () { - if (!editor.isEmpty) { - showInlineToolbar = true - } - } - let showDiff = true - + + {#if visible} {#if comparedVersion !== undefined || $$slots.tools}
@@ -336,7 +337,7 @@ needFocus = true }} on:action={(event) => { - dispatch('action', { action: event.detail, editor }) + dispatch('action', event.detail) needFocus = true }} /> @@ -344,7 +345,7 @@
-
+
{/if} diff --git a/packages/text-editor/src/components/TextEditor.svelte b/packages/text-editor/src/components/TextEditor.svelte index 59c43c860e..e8666b8110 100644 --- a/packages/text-editor/src/components/TextEditor.svelte +++ b/packages/text-editor/src/components/TextEditor.svelte @@ -28,7 +28,7 @@ import { themeStore } from '@hcengineering/ui' import TextEditorStyleToolbar from './TextEditorStyleToolbar.svelte' import { TextFormatCategory } from '../types' - import { InlineStyleToolbar } from './extension/inlineStyleToolbar' + import { InlineStyleToolbarExtension } from './extension/inlineStyleToolbar' import { defaultEditorAttributes } from './editor/editorProps' export let content: string = '' @@ -77,7 +77,6 @@ let needFocus = false let focused = false let posFocus: FocusPosition | undefined = undefined - let showContextMenu = false let textEditorToolbar: HTMLElement export function focus (position?: FocusPosition): void { @@ -137,10 +136,10 @@ ...(supportSubmit ? [Handle] : []), // order important Placeholder.configure({ placeholder: placeHolderStr }), ...extensions, - InlineStyleToolbar.configure({ + InlineStyleToolbarExtension.configure({ element: textEditorToolbar, - getEditorElement: () => element, - isShown: () => showContextMenu + isSupported: () => true, + isSelectionOnly: () => false }) ], parseOptions: { @@ -160,12 +159,8 @@ }, onUpdate: () => { content = editor.getHTML() - showContextMenu = false dispatch('value', content) dispatch('update', content) - }, - onSelectionUpdate: () => { - showContextMenu = false } }) }) @@ -177,12 +172,6 @@ } }) - function onEditorClick () { - if (!editor.isEmpty) { - showContextMenu = true - } - } - /** * @public */ @@ -209,7 +198,7 @@ }} />
-
+