-
Notifications
You must be signed in to change notification settings - Fork 111
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
chore(migrate): setContent mixin...
to useEditorMethods composable and setInitialYjsState helper method. Signed-off-by: Max <[email protected]>
- Loading branch information
commit 8d998f059f2748c78863c0a6b048beebe724b8ca
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
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,37 @@ | ||
| /** | ||
| * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
|
|
||
| import type { Editor } from '@tiptap/core' | ||
| import escapeHtml from 'escape-html' | ||
| import { unref, type ShallowRef } from 'vue' | ||
| import markdownit from '../markdownit/index.js' | ||
|
|
||
| export const useEditorMethods = (editor: ShallowRef<Editor | undefined>) => { | ||
| const setEditable = (val: boolean) => { | ||
| const ed = unref(editor) | ||
max-nextcloud marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if (ed && ed.isEditable !== val) { | ||
| ed.setEditable(val) | ||
| } | ||
| } | ||
|
|
||
| const setContent: ( | ||
| content: string, | ||
| options: { isRichEditor?: boolean; addToHistory?: boolean }, | ||
| ) => void = (content, { isRichEditor, addToHistory = true } = {}) => { | ||
| const html = isRichEditor | ||
| ? markdownit.render(content) + '<p/>' | ||
| : `<pre>${escapeHtml(content)}</pre>` | ||
| editor.value | ||
| ?.chain() | ||
| .setContent(html, addToHistory) | ||
| .command(({ tr }) => { | ||
| tr.setMeta('addToHistory', addToHistory) | ||
| return true | ||
| }) | ||
| .run() | ||
| } | ||
|
|
||
| return { setContent, setEditable } | ||
| } | ||
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,46 @@ | ||
| /** | ||
| * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
|
|
||
| import escapeHtml from 'escape-html' | ||
| import markdownit from '../markdownit/index.js' | ||
| import { Doc, encodeStateAsUpdate, XmlFragment, applyUpdate } from 'yjs' | ||
| import { generateJSON } from '@tiptap/core' | ||
| import { prosemirrorToYXmlFragment } from 'y-prosemirror' | ||
| import { Node } from '@tiptap/pm/model' | ||
| import { createRichEditor, createPlainEditor } from '../EditorFactory.js' | ||
|
|
||
| export const setInitialYjsState = (ydoc, content, { isRichEditor }) => { | ||
| const html = isRichEditor | ||
| ? markdownit.render(content) + '<p/>' | ||
| : `<pre>${escapeHtml(content)}</pre>` | ||
|
|
||
| const editor = isRichEditor ? createRichEditor() : createPlainEditor() | ||
|
|
||
| const json = generateJSON(html, editor.options.extensions) | ||
|
|
||
| const node = Node.fromJSON(editor.schema, json) | ||
| const getBaseDoc = (node) => { | ||
| const baseDoc = new Doc() | ||
| // In order to make the initial document state idempotent, we need to reset the clientID | ||
| // While this is not recommended, we cannot avoid it here as we lack another mechanism | ||
| // to generate the initial state on the server side | ||
| // The only other option to avoid this could be to generate the initial state once and push | ||
| // it to the server immediately, however this would require read only sessions to be able | ||
| // to still push a state | ||
| baseDoc.clientID = 0 | ||
| const type = /** @type {XmlFragment} */ (baseDoc.get('default', XmlFragment)) | ||
| if (!type.doc) { | ||
| // This should not happen but is aligned with the upstream implementation | ||
| // https://github.com/yjs/y-prosemirror/blob/8db24263770c2baaccb08e08ea9ef92dbcf8a9da/src/lib.js#L209 | ||
| return baseDoc | ||
| } | ||
|
|
||
| prosemirrorToYXmlFragment(node, type) | ||
| return baseDoc | ||
| } | ||
|
|
||
| const baseUpdate = encodeStateAsUpdate(getBaseDoc(node)) | ||
| applyUpdate(ydoc, baseUpdate) | ||
| } |
This file was deleted.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.