From 4cdb4b2ffc44ea15c05a14bec62d4244728ed1f9 Mon Sep 17 00:00:00 2001 From: Anna No Date: Thu, 5 Oct 2023 01:13:42 +0700 Subject: [PATCH 1/8] update documents inline comments extensions Signed-off-by: Anna No --- .../src/components/CollaboratorEditor.svelte | 49 ++++----- .../src/components/TextEditor.svelte | 21 +--- .../components/TextEditorStyleToolbar.svelte | 2 +- .../src/components/extension/inlinePopup.ts | 16 +++ .../extension/inlineStyleToolbar.ts | 99 ++++++++++++++----- .../src/components/extension/nodeHighlight.ts | 49 +-------- .../src/components/extension/nodeUuid.ts | 16 ++- packages/text-editor/src/index.ts | 7 ++ packages/theme/styles/_colors.scss | 5 +- packages/theme/styles/_text-editor.scss | 10 +- 10 files changed, 155 insertions(+), 119 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 4b75f4997e2..99ae772a645 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 = '' @@ -144,6 +142,23 @@ export function takeSnapshot (snapshotId: string) { 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 @@ -201,6 +216,7 @@ }) $: updateEditor(editor, field, comparedVersion) + $: if (editor) dispatch('editor', editor) onMount(() => { ph.then(() => { @@ -211,10 +227,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 +263,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 +291,11 @@ } }) - function onEditorClick () { - if (!editor.isEmpty) { - showInlineToolbar = true - } - } - let showDiff = true - + + {#if visible} {#if comparedVersion !== undefined || $$slots.tools}
@@ -344,7 +347,7 @@
-
+
{/if} diff --git a/packages/text-editor/src/components/TextEditor.svelte b/packages/text-editor/src/components/TextEditor.svelte index 59c43c860e0..e8666b8110a 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 @@ }} />
-
+