add support for raw Y.js fragments to the collaboration extension

This commit is contained in:
Hans Pagel
2021-01-11 18:37:30 +01:00
parent 7809aa13f5
commit ecd0a6669a
4 changed files with 48 additions and 27 deletions

View File

@@ -12,9 +12,13 @@ export interface CollaborationOptions {
*/
document: any,
/**
* A string to determine the fragment that should be used.
* Name of a Y.js fragment, can be changed to sync multiple fields with one Y.js document.
*/
fragment: string,
field: string,
/**
* A raw Y.js fragment, can be used instead of `document` and `field`.
*/
fragment: any,
}
export const Collaboration = Extension.create({
@@ -22,7 +26,8 @@ export const Collaboration = Extension.create({
defaultOptions: <CollaborationOptions>{
document: null,
fragment: 'default',
field: 'default',
fragment: null,
},
addCommands() {
@@ -55,12 +60,12 @@ export const Collaboration = Extension.create({
},
addProseMirrorPlugins() {
const fragment = this.options.fragment
? this.options.fragment
: this.options.document.getXmlFragment(this.options.field)
return [
ySyncPlugin(
this.options.document.getXmlFragment(
this.options.fragment,
),
),
ySyncPlugin(fragment),
yUndoPlugin(),
]
},