From 89bfabb37d94dc9462edfee327d7e20b0f31eca9 Mon Sep 17 00:00:00 2001 From: Alexander Onnikov Date: Fri, 17 Nov 2023 20:00:13 +0700 Subject: [PATCH] EZQMS-359 Add update highlight command to nodeHighlight plugin (#3997) Signed-off-by: Alexander Onnikov --- packages/text-editor/package.json | 29 +-- packages/text-editor/src/changeSet.ts | 4 +- packages/text-editor/src/commands.ts | 38 ++++ .../components/CollaborationDiffViewer.svelte | 10 +- .../src/components/CollaboratorEditor.svelte | 15 +- .../src/components/diff/decorations.ts | 8 +- .../src/components/diff/recreate.ts | 4 +- .../src/components/editor/collaboration.ts | 2 +- .../extension/inlineStyleToolbar.ts | 2 +- .../src/components/extension/nodeHighlight.ts | 176 ++++++++++++++---- .../src/components/extension/nodeUuid.ts | 4 +- packages/text-editor/src/index.ts | 3 +- packages/text-editor/src/types.ts | 22 +++ 13 files changed, 236 insertions(+), 81 deletions(-) create mode 100644 packages/text-editor/src/commands.ts diff --git a/packages/text-editor/package.json b/packages/text-editor/package.json index 52f26baa46..b8430fdcd2 100644 --- a/packages/text-editor/package.json +++ b/packages/text-editor/package.json @@ -44,34 +44,16 @@ "@tiptap/core": "^2.1.12", "@tiptap/pm": "^2.1.12", "@tiptap/starter-kit": "^2.1.12", + "@tiptap/suggestion": "^2.1.12", "@tiptap/extension-highlight": "^2.1.12", "@tiptap/extension-placeholder": "^2.1.12", "@tiptap/extension-mention": "^2.1.12", "@tiptap/extension-typography": "^2.1.12", "@tiptap/extension-link": "^2.1.12", - "@tiptap/suggestion": "^2.1.12", "@tiptap/extension-task-list": "^2.1.12", "@tiptap/extension-task-item": "^2.1.12", "@tiptap/extension-collaboration": "^2.1.12", "@tiptap/extension-collaboration-cursor": "^2.1.12", - "@tiptap/prosemirror-tables": "^1.1.4", - "prosemirror-gapcursor": "^1.3.2", - "prosemirror-dropcursor": "^1.8.1", - "prosemirror-collab": "^1.3.1", - "prosemirror-state": "^1.4.3", - "prosemirror-transform": "^1.7.3", - "prosemirror-schema-list": "^1.3.0", - "prosemirror-commands": "^1.5.2", - "yjs": "^13.5.52", - "y-websocket": "^1.5.0", - "y-prosemirror": "^1.2.1", - "prosemirror-changeset": "^2.2.1", - "prosemirror-model": "^1.19.2", - "prosemirror-view": "^1.31.4", - "prosemirror-history": "^1.3.2", - "prosemirror-keymap": "^1.2.2", - "rfc6902": "^5.0.1", - "diff": "^5.1.0", "@tiptap/extension-code-block": "^2.1.12", "@tiptap/extension-gapcursor": "^2.1.12", "@tiptap/extension-heading": "^2.1.12", @@ -84,7 +66,12 @@ "@tiptap/extension-underline": "^2.1.12", "@tiptap/extension-list-keymap": "^2.1.12", "@hocuspocus/provider": "^2.5.0", - "slugify": "^1.6.6", - "prosemirror-codemark": "^0.4.2" + "prosemirror-codemark": "^0.4.2", + "yjs": "^13.5.52", + "y-websocket": "^1.5.0", + "y-prosemirror": "^1.2.1", + "rfc6902": "^5.0.1", + "diff": "^5.1.0", + "slugify": "^1.6.6" } } diff --git a/packages/text-editor/src/changeSet.ts b/packages/text-editor/src/changeSet.ts index 3c1862fc45..2a58e749e6 100644 --- a/packages/text-editor/src/changeSet.ts +++ b/packages/text-editor/src/changeSet.ts @@ -1,6 +1,6 @@ import { Extension, Mark, mergeAttributes } from '@tiptap/core' -import { ChangeSet } from 'prosemirror-changeset' -import { Plugin } from 'prosemirror-state' +import { ChangeSet } from '@tiptap/pm/changeset' +import { Plugin } from '@tiptap/pm/state' export interface ChangeHighlightOptions { multicolor: boolean diff --git a/packages/text-editor/src/commands.ts b/packages/text-editor/src/commands.ts new file mode 100644 index 0000000000..4bdc7c3170 --- /dev/null +++ b/packages/text-editor/src/commands.ts @@ -0,0 +1,38 @@ +// +// Copyright © 2023 Hardcore Engineering Inc. +// +// Licensed under the Eclipse Public License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. You may +// obtain a copy of the License at https://www.eclipse.org/legal/epl-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// +// See the License for the specific language governing permissions and +// limitations under the License. +// +import { Editor } from '@tiptap/core' +import { TextEditorCommand, TextEditorCommandHandler } from './types' + +export function textEditorCommandHandler (editor: Editor | undefined): TextEditorCommandHandler | undefined { + return editor !== undefined ? new TextEditorCommandHandlerImpl(editor) : undefined +} + +class TextEditorCommandHandlerImpl implements TextEditorCommandHandler { + constructor (private readonly editor: Editor) {} + + chain (...commands: TextEditorCommand[]): boolean { + let chain = this.editor.chain() + + for (const command of commands) { + chain = chain.command(({ editor, commands }) => command({ editor, commands })) + } + + return chain.run() + } + + command (command: TextEditorCommand): boolean { + return this.editor.commands.command(({ editor, commands }) => command({ editor, commands })) + } +} diff --git a/packages/text-editor/src/components/CollaborationDiffViewer.svelte b/packages/text-editor/src/components/CollaborationDiffViewer.svelte index 86f6589e4e..44e484c42e 100644 --- a/packages/text-editor/src/components/CollaborationDiffViewer.svelte +++ b/packages/text-editor/src/components/CollaborationDiffViewer.svelte @@ -16,20 +16,18 @@ -->