Merge branch 'develop' of github.com:ueberdosis/tiptap into develop

This commit is contained in:
Dominik Biedebach 2023-03-28 16:00:39 +02:00
commit 2c5dd77b3a
3 changed files with 371 additions and 340 deletions

662
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -207,7 +207,7 @@ export class ExtensionManager {
const { editor } = this
// With ProseMirror, first plugins within an array are executed first.
// In tiptap, we provide the ability to override plugins,
// In Tiptap, we provide the ability to override plugins,
// so it feels more natural to run plugins at the end of an array first.
// Thats why we have to reverse the `extensions` array and sort again
// based on the `priority` option.

View File

@ -1,4 +1,5 @@
import { Extension } from '@tiptap/core'
import { EditorView } from '@tiptap/pm/view'
import {
redo,
undo,
@ -37,7 +38,7 @@ export interface CollaborationOptions {
*/
fragment: any,
/**
* Fired when the content from Yjs is initially rendered to tiptap.
* Fired when the content from Yjs is initially rendered to Tiptap.
*/
onFirstRender?: () => void,
}
@ -109,13 +110,43 @@ export const Collaboration = Extension.create<CollaborationOptions>({
? this.options.fragment
: this.options.document.getXmlFragment(this.options.field)
return [
ySyncPlugin(fragment, {
onFirstRender: () => {
this.options.onFirstRender?.apply(this)
// Quick fix until there is an official implementation (thanks to @hamflx).
// See https://github.com/yjs/y-prosemirror/issues/114 and https://github.com/yjs/y-prosemirror/issues/102
const yUndoPluginInstance = yUndoPlugin()
const originalUndoPluginView = yUndoPluginInstance.spec.view
yUndoPluginInstance.spec.view = (view: EditorView) => {
const { undoManager } = yUndoPluginKey.getState(view.state)
if (undoManager.restore) {
undoManager.restore()
// eslint-disable-next-line
undoManager.restore = () => {}
}
const viewRet = originalUndoPluginView(view)
return {
destroy: () => {
const hasUndoManSelf = undoManager.trackedOrigins.has(undoManager)
// eslint-disable-next-line
const observers = undoManager._observers
undoManager.restore = () => {
if (hasUndoManSelf) {
undoManager.trackedOrigins.add(undoManager)
}
undoManager.doc.on('afterTransaction', undoManager.afterTransactionHandler)
// eslint-disable-next-line
undoManager._observers = observers
}
viewRet.destroy()
},
}),
yUndoPlugin(),
]
}
}
return [ySyncPlugin(fragment), yUndoPluginInstance]
},
})