Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/super-editor/src/core/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -597,10 +597,10 @@ export class Editor extends EventEmitter {

/**
* Export the yjs binary from the current state.
* @returns {Uint8Array} The exported yjs binary
* @returns {Promise<Uint8Array>} The exported yjs binary
*/
generateCollaborationUpdate() {
return generateCollaborationData(this);
async generateCollaborationUpdate() {
return await generateCollaborationData(this);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
* @param {Editor} editor The editor instance
* @returns {Promise<void>}
*/
export const updateYdocDocxData = async (editor) => {
if (!editor.options.ydoc) return;
export const updateYdocDocxData = async (editor, ydoc) => {
ydoc = ydoc || editor.options.ydoc;
if (!ydoc) return;

const metaMap = editor.options.ydoc.getMap('meta');
const metaMap = ydoc.getMap('meta');
const docx = [...metaMap.get('docx')];
const newXml = await editor.exportDocx({ getUpdatedDocs: true });

Expand All @@ -22,7 +23,7 @@ export const updateYdocDocxData = async (editor) => {
});
});

editor.options.ydoc.transact(
ydoc.transact(
() => {
metaMap.set('docx', docx);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,9 @@ const initSyncListener = (ydoc, editor, extension) => {
provider.on('synced', emit);
};

export const generateCollaborationData = (editor) => {
export const generateCollaborationData = async (editor) => {
const ydoc = prosemirrorToYDoc(editor.state.doc, 'supereditor');
initializeMetaMap(ydoc, editor);
await updateYdocDocxData(editor, ydoc);
return encodeStateAsUpdate(ydoc);
};
Loading