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 <jonas@freesources.org>
  • Loading branch information
mejo- committed Nov 6, 2024
1 parent 163d170 commit 8ba19ad
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;"

Check failure on line 210 in src/mixins/editorMixin.js

View workflow job for this annotation

GitHub Actions / NPM lint

Strings must use singlequote
const styleItalic = "font-weight: normal; font-style: italic;"

Check failure on line 211 in src/mixins/editorMixin.js

View workflow job for this annotation

GitHub Actions / NPM lint

Strings must use singlequote
console.warn(JSON.stringify(yjsData, null, ' '))
console.warn('%c%s\n%c%s\n%s', styleBold, intro, styleItalic, introChrome, introFirefox)
}
}
},
},
}

0 comments on commit 8ba19ad

Please sign in to comment.