diff --git a/packages/super-editor/src/core/Editor.js b/packages/super-editor/src/core/Editor.js index ef465e2e00..38725d3647 100644 --- a/packages/super-editor/src/core/Editor.js +++ b/packages/super-editor/src/core/Editor.js @@ -1313,6 +1313,7 @@ export class Editor extends EventEmitter { */ #dispatchTransaction(transaction) { if (this.isDestroyed) return; + const start = Date.now(); let state; try { @@ -1338,9 +1339,11 @@ export class Editor extends EventEmitter { const selectionHasChanged = !this.state.selection.eq(state.selection); this.view.updateState(state); + const end = Date.now(); this.emit('transaction', { editor: this, transaction, + duration: end - start, }); if (selectionHasChanged) { diff --git a/packages/superdoc/src/SuperDoc.vue b/packages/superdoc/src/SuperDoc.vue index be70b784ad..a17e22e92d 100644 --- a/packages/superdoc/src/SuperDoc.vue +++ b/packages/superdoc/src/SuperDoc.vue @@ -287,6 +287,7 @@ const editorOptions = (doc) => { onCommentsUpdate: onEditorCommentsUpdate, onCommentLocationsUpdate: onEditorCommentLocationsUpdate, onListDefinitionsChange: onEditorListdefinitionsChange, + onTransaction: onEditorTransaction, ydoc: doc.ydoc, collaborationProvider: doc.provider || null, isNewFile: doc.isNewFile || false, @@ -331,6 +332,12 @@ const onEditorCommentsUpdate = (params = {}) => { } }; +const onEditorTransaction = ({ editor, transaction, duration }) => { + if (typeof proxy.$superdoc.config.onTransaction === 'function') { + proxy.$superdoc.config.onTransaction({ editor, transaction, duration }); + } +}; + const isCommentsEnabled = computed(() => 'comments' in modules); const showCommentsSidebar = computed(() => { return ( diff --git a/packages/superdoc/src/core/SuperDoc.js b/packages/superdoc/src/core/SuperDoc.js index cb75d40285..38cb36a7af 100644 --- a/packages/superdoc/src/core/SuperDoc.js +++ b/packages/superdoc/src/core/SuperDoc.js @@ -80,6 +80,7 @@ import { initSuperdocYdoc, initCollaborationComments, makeDocumentsCollaborative * @property {TelemetryConfig} [telemetry] Telemetry configuration * @property {(editor: Editor) => void} [onEditorBeforeCreate] Callback before an editor is created * @property {(editor: Editor) => void} [onEditorCreate] Callback after an editor is created + * @property {(params: { editor: Editor, transaction: any, duration: number }) => void} [onTransaction] Callback when a transaction is made * @property {() => void} [onEditorDestroy] Callback after an editor is destroyed * @property {(params: { error: object, editor: Editor, documentId: string, file: File }) => void} [onContentError] Callback when there is an error in the content * @property {(editor: { superdoc: SuperDoc }) => void} [onReady] Callback when the SuperDoc is ready @@ -182,7 +183,7 @@ export class SuperDoc extends EventEmitter { onCommentsListChange: () => null, onException: () => null, onListDefinitionsChange: () => null, - + onTransaction: () => null, // Image upload handler // async (file) => url; handleImageUpload: null,