-
Notifications
You must be signed in to change notification settings - Fork 110
chore(migrate): useEditorMixin to useEditor composable #7313
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
881ce5b
chore(migrate): useEditorMixin to useEditor composable
max-nextcloud 8d998f0
chore(migrate): setContent mixin...
max-nextcloud 13a5ce1
chore(migrate): to useEditorFlags composable
max-nextcloud d958a4d
chore(cleanup): fix small review remarks
max-nextcloud b0790dc
chore(migrate): use.find instead of deprecated .contains
max-nextcloud 8b4e635
enh(editor): store session in separate extension
max-nextcloud 9d3cc87
chore(refactor): configure mention in rich text extension
max-nextcloud c4f863f
chore(types): collaborationCursor extension to typescript
max-nextcloud 354ad41
chore(simplify): rely on updateUser command
max-nextcloud 022e483
chore(simplify): replace computed fileExtension with temp
max-nextcloud 0809c8e
enh(code): start to load syntax highlighting during setup
max-nextcloud b326875
chore(refactor): load editor in mounted
max-nextcloud 3e5cfd8
chore(refactor): create editor in created instead of mounted
max-nextcloud ab26032
chore(refactor): create ydoc in setup
max-nextcloud 2831462
fix(character-count): always provide the current editors doc
max-nextcloud d7df4c0
fix(character-count): use the NcActionTexts name prop
max-nextcloud e24d90a
fix(loading): only show main container when content loaded
max-nextcloud 0d5f4f7
fix(mention): use shallowRef for connection
max-nextcloud 057a682
fix(load): create initial YjsState with dir
max-nextcloud fae62fc
chore(refactor): extract useEditor into its own file
max-nextcloud 17f0d62
chore(refactor): extract useEditorFlags into its own file
max-nextcloud 90b1d84
test(RichTextReader): basic test
max-nextcloud fabc79e
test(RichTextReader): update content
max-nextcloud File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
enh(editor): store session in separate extension
The `Session` extension provides the `setSession` and `clearSession` commands. Session data is made available via `editor.storage.session`. This way session data can be provided after initializing the editor. Signed-off-by: Max <[email protected]>
- Loading branch information
commit 8b4e6359d0829a0e0a505b44caed85184c228c81
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| /** | ||
| * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
|
|
||
| import { Extension } from '@tiptap/core' | ||
|
|
||
| declare module '@tiptap/core' { | ||
| interface Commands<ReturnType> { | ||
| session: { | ||
| setSession: (session: { | ||
| documentId: number | ||
| id: number | ||
| token: string | ||
| }) => ReturnType | ||
| clearSession: () => ReturnType | ||
| } | ||
| } | ||
| } | ||
|
|
||
| interface StoredSession { | ||
| documentId: number | ||
| sessionId: number | ||
| sessionToken: string | ||
| } | ||
|
|
||
| const emptySession = { | ||
| documentId: 0, | ||
| sessionId: 0, | ||
| sessionToken: '', | ||
| } | ||
|
|
||
| export const Session = Extension.create({ | ||
| name: 'session', | ||
|
|
||
| addStorage(): StoredSession { | ||
| return { ...emptySession } | ||
| }, | ||
|
|
||
| addCommands() { | ||
| return { | ||
| setSession: (session) => () => { | ||
max-nextcloud marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| this.storage.documentId = session.documentId | ||
| this.storage.sessionId = session.id | ||
| this.storage.sessionToken = session.token | ||
| return true | ||
| }, | ||
| clearSession: | ||
| () => | ||
| ({ commands }) => { | ||
| return commands.setSession({ documentId: 0, id: 0, token: '' }) | ||
| }, | ||
| } | ||
| }, | ||
| }) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| /** | ||
| * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
|
|
||
| import { expect, test as baseTest } from 'vitest' | ||
| import createCustomEditor from '../testHelpers/createCustomEditor' | ||
| import { Session } from '../../extensions/Session' | ||
| import type { Editor } from '@tiptap/core' | ||
|
|
||
| interface EditorFixture { | ||
| editor: Editor | ||
| } | ||
|
|
||
| const test = baseTest.extend<EditorFixture>({ | ||
| editor: async ({ task: _ }, use) => { | ||
| const editor = createCustomEditor('', [Session]) | ||
| await use(editor) | ||
| editor.destroy() | ||
| } | ||
| }) | ||
|
|
||
| test('start with empty session', ({ editor }) => { | ||
| expect(editor.storage.session).toEqual({ | ||
| "documentId": 0, | ||
| "sessionId": 0, | ||
| "sessionToken": "", | ||
| }) | ||
| }) | ||
|
|
||
| test('set a session', ({ editor }) => { | ||
| editor.commands.setSession({ documentId: 123, id: 456, token: 'myToken'}) | ||
| expect(editor.storage.session).toEqual({ | ||
| "documentId": 123, | ||
| "sessionId": 456, | ||
| "sessionToken": "myToken", | ||
| }) | ||
| }) | ||
|
|
||
| test('clear the session', ({ editor }) => { | ||
| editor.commands.setSession({ documentId: 123, id: 456, token: 'myToken'}) | ||
| editor.commands.clearSession() | ||
| expect(editor.storage.session).toEqual({ | ||
| "documentId": 0, | ||
| "sessionId": 0, | ||
| "sessionToken": "", | ||
| }) | ||
| }) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh no... this will require tiptap v3 as previously the extension storage is a singleton and therefor used by all loaded editor instances at the same time. ( See ueberdosis/tiptap#6060 )