From 363b14e0f22c5c21d25d5256aa01e80758df50a2 Mon Sep 17 00:00:00 2001 From: Jonas Date: Mon, 4 Nov 2024 13:40:22 +0100 Subject: [PATCH] feat: Expose yjs debug function via OCA.Collectives Should make it easier to debug sync issues. Signed-off-by: Jonas --- src/mixins/editorMixin.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/mixins/editorMixin.js b/src/mixins/editorMixin.js index bbdf45772..27e375c7e 100644 --- a/src/mixins/editorMixin.js +++ b/src/mixins/editorMixin.js @@ -166,6 +166,7 @@ export default { }, }) : null + this.setupEditorDebug() }, updateEditorContent(markdown) { @@ -188,5 +189,29 @@ export default { this.hide('outline') } }, + + setupEditorDebug() { + window.OCA.Collectives.editorApi = this.editor + window.OCA.Collectives.editorComponent = this.editor.vm.$children[0] + if (this.editor.debugYjs) { + window.OCA.Collectives.debugYjs = () => { + console.debug('Running debugYjs through editor API') + window.OCA.Collectives.editorApi.debugYjs() + } + } else { + window.OCA.Collectives.debugYjs = () => { + const yjsData = { + clientId: window.OCA.Collectives.editorComponent.$ydoc.clientID, + pendingStructs: window.OCA.Collectives.editorComponent.$ydoc.store.pendingStructs, + clientVectors: [], + documentState: window.OCA.Collectives.editorComponent.$syncService.getDocumentState(), + } + for (const client of window.OCA.Collectives.editorComponent.$ydoc.store.clients.values()) { + yjsData.clientVectors.push(client.at(-1).id) + } + console.debug('Yjs data', JSON.stringify(yjsData)) + } + } + }, }, }