move collab extension
This commit is contained in:
@@ -21,10 +21,13 @@
|
||||
"url": "https://github.com/scrumpy/tiptap/issues"
|
||||
},
|
||||
"dependencies": {
|
||||
"lodash-es": "^4.17.11",
|
||||
"lowlight": "^1.11.0",
|
||||
"prosemirror-collab": "^1.1.1",
|
||||
"prosemirror-history": "^1.0.4",
|
||||
"prosemirror-state": "^1.2.2",
|
||||
"prosemirror-tables": "^0.7.11",
|
||||
"prosemirror-transform": "^1.1.3",
|
||||
"prosemirror-utils": "^0.7.6",
|
||||
"prosemirror-view": "^1.8.9",
|
||||
"tiptap": "^1.17.0",
|
||||
|
||||
62
packages/tiptap-extensions/src/extensions/Collaboration.js
Normal file
62
packages/tiptap-extensions/src/extensions/Collaboration.js
Normal file
@@ -0,0 +1,62 @@
|
||||
import { debounce } from 'lodash-es'
|
||||
import { Extension } from 'tiptap'
|
||||
import { Step } from 'prosemirror-transform'
|
||||
import {
|
||||
collab,
|
||||
sendableSteps,
|
||||
getVersion,
|
||||
receiveTransaction,
|
||||
} from 'prosemirror-collab'
|
||||
|
||||
export default class CollaborationExtension extends Extension {
|
||||
|
||||
get name() {
|
||||
return 'collaboration'
|
||||
}
|
||||
|
||||
init() {
|
||||
this.editor.on('update', ({ state }) => {
|
||||
this.getSendableSteps(state)
|
||||
})
|
||||
}
|
||||
|
||||
get defaultOptions() {
|
||||
return {
|
||||
version: 0,
|
||||
clientID: Math.floor(Math.random() * 0xFFFFFFFF),
|
||||
debounce: 250,
|
||||
onSendable: () => {},
|
||||
onUpdate: ({ steps, version }) => {
|
||||
const { state, view, schema } = this.editor
|
||||
|
||||
if (getVersion(state) > version) {
|
||||
return
|
||||
}
|
||||
|
||||
view.dispatch(receiveTransaction(
|
||||
state,
|
||||
steps.map(item => Step.fromJSON(schema, item.step)),
|
||||
steps.map(item => item.clientID),
|
||||
))
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
get plugins() {
|
||||
return [
|
||||
collab({
|
||||
version: this.options.version,
|
||||
clientID: this.options.clientID,
|
||||
}),
|
||||
]
|
||||
}
|
||||
|
||||
getSendableSteps = debounce(state => {
|
||||
const sendable = sendableSteps(state)
|
||||
|
||||
if (sendable) {
|
||||
this.options.onSendable(sendable)
|
||||
}
|
||||
}, this.options.debounce)
|
||||
|
||||
}
|
||||
@@ -23,6 +23,7 @@ export { default as Link } from './marks/Link'
|
||||
export { default as Strike } from './marks/Strike'
|
||||
export { default as Underline } from './marks/Underline'
|
||||
|
||||
export { default as Collaboration } from './extensions/Collaboration'
|
||||
export { default as History } from './extensions/History'
|
||||
export { default as Placeholder } from './extensions/Placeholder'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user