Skip to content

Commit 58cdf8c

Browse files
authored
Merge pull request #698 from Harbour-Enterprises/nick/update-ydoc-generate-collab-data
fix: update ydoc when generating collaborative data
2 parents 599b2c5 + 4c4413c commit 58cdf8c

3 files changed

Lines changed: 10 additions & 8 deletions

File tree

packages/super-editor/src/core/Editor.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -597,10 +597,10 @@ export class Editor extends EventEmitter {
597597

598598
/**
599599
* Export the yjs binary from the current state.
600-
* @returns {Uint8Array} The exported yjs binary
600+
* @returns {Promise<Uint8Array>} The exported yjs binary
601601
*/
602-
generateCollaborationUpdate() {
603-
return generateCollaborationData(this);
602+
async generateCollaborationUpdate() {
603+
return await generateCollaborationData(this);
604604
}
605605

606606
/**

packages/super-editor/src/extensions/collaboration/collaboration-helpers.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
* @param {Editor} editor The editor instance
55
* @returns {Promise<void>}
66
*/
7-
export const updateYdocDocxData = async (editor) => {
8-
if (!editor.options.ydoc) return;
7+
export const updateYdocDocxData = async (editor, ydoc) => {
8+
ydoc = ydoc || editor.options.ydoc;
9+
if (!ydoc) return;
910

10-
const metaMap = editor.options.ydoc.getMap('meta');
11+
const metaMap = ydoc.getMap('meta');
1112
const docx = [...metaMap.get('docx')];
1213
const newXml = await editor.exportDocx({ getUpdatedDocs: true });
1314

@@ -22,7 +23,7 @@ export const updateYdocDocxData = async (editor) => {
2223
});
2324
});
2425

25-
editor.options.ydoc.transact(
26+
ydoc.transact(
2627
() => {
2728
metaMap.set('docx', docx);
2829
},

packages/super-editor/src/extensions/collaboration/collaboration.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,9 @@ const initSyncListener = (ydoc, editor, extension) => {
186186
provider.on('synced', emit);
187187
};
188188

189-
export const generateCollaborationData = (editor) => {
189+
export const generateCollaborationData = async (editor) => {
190190
const ydoc = prosemirrorToYDoc(editor.state.doc, 'supereditor');
191191
initializeMetaMap(ydoc, editor);
192+
await updateYdocDocxData(editor, ydoc);
192193
return encodeStateAsUpdate(ydoc);
193194
};

0 commit comments

Comments
 (0)