Skip to content

Commit

Permalink
feat: Expose yjs debug function via OCA.Collectives
Browse files Browse the repository at this point in the history
Should make it easier to debug sync issues.

Signed-off-by: Jonas <[email protected]>
  • Loading branch information
mejo- committed Nov 6, 2024
1 parent 163d170 commit 4d60fa5
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/mixins/editorMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ export default {
},
})
: null
this.setupEditorDebug()
},

updateEditorContent(markdown) {
Expand All @@ -187,5 +188,31 @@ export default {
this.hide('outline')
}
},

setupEditorDebug() {
window.OCA.Collectives.editorApi = this.editor
if (!window.OCA.Collectives.editorApi.debugYjs) {
window.OCA.Collectives.editorApi.debugYjs = () => {
const editorComponent = window.OCA.Collectives.editorApi.vm.$children[0]
const yjsData = {
clientId: editorComponent.$ydoc.clientID,
pendingStructs: editorComponent.$ydoc.store.pendingStructs,
clientVectors: [],
documentState: editorComponent.$syncService.getDocumentState(),
}
for (const client of editorComponent.$ydoc.store.clients.values()) {
yjsData.clientVectors.push(client.at(-1).id)
}

const intro = 'Editor Yjs debug data. Copy the object above that starts with "clientId".'
const introChrome = '- In Chrome, select "Copy" at the end of the line.'
const introFirefox = '- In Firefox, right-click on the object and select "Copy object".'
const styleBold = 'font-weight: bold;'
const styleItalic = 'font-weight: normal; font-style: italic;'
console.warn(JSON.stringify(yjsData, null, ' '))
console.warn('%c%s\n%c%s\n%s', styleBold, intro, styleItalic, introChrome, introFirefox)
}
}
},
},
}

0 comments on commit 4d60fa5

Please sign in to comment.