mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-11-24 19:59:02 +08:00
Merge branch 'develop' of github.com:ueberdosis/tiptap into develop
This commit is contained in:
commit
2c5dd77b3a
662
package-lock.json
generated
662
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -207,7 +207,7 @@ export class ExtensionManager {
|
|||||||
const { editor } = this
|
const { editor } = this
|
||||||
|
|
||||||
// With ProseMirror, first plugins within an array are executed first.
|
// 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.
|
// so it feels more natural to run plugins at the end of an array first.
|
||||||
// That’s why we have to reverse the `extensions` array and sort again
|
// That’s why we have to reverse the `extensions` array and sort again
|
||||||
// based on the `priority` option.
|
// based on the `priority` option.
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import { Extension } from '@tiptap/core'
|
import { Extension } from '@tiptap/core'
|
||||||
|
import { EditorView } from '@tiptap/pm/view'
|
||||||
import {
|
import {
|
||||||
redo,
|
redo,
|
||||||
undo,
|
undo,
|
||||||
@ -37,7 +38,7 @@ export interface CollaborationOptions {
|
|||||||
*/
|
*/
|
||||||
fragment: any,
|
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,
|
onFirstRender?: () => void,
|
||||||
}
|
}
|
||||||
@ -109,13 +110,43 @@ export const Collaboration = Extension.create<CollaborationOptions>({
|
|||||||
? this.options.fragment
|
? this.options.fragment
|
||||||
: this.options.document.getXmlFragment(this.options.field)
|
: this.options.document.getXmlFragment(this.options.field)
|
||||||
|
|
||||||
return [
|
// Quick fix until there is an official implementation (thanks to @hamflx).
|
||||||
ySyncPlugin(fragment, {
|
// See https://github.com/yjs/y-prosemirror/issues/114 and https://github.com/yjs/y-prosemirror/issues/102
|
||||||
onFirstRender: () => {
|
const yUndoPluginInstance = yUndoPlugin()
|
||||||
this.options.onFirstRender?.apply(this)
|
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]
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user