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
3 changes: 3 additions & 0 deletions packages/super-editor/src/core/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -1313,6 +1313,7 @@ export class Editor extends EventEmitter {
*/
#dispatchTransaction(transaction) {
if (this.isDestroyed) return;
const start = Date.now();
Comment thread
harbournick marked this conversation as resolved.

let state;
try {
Expand All @@ -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) {
Expand Down
7 changes: 7 additions & 0 deletions packages/superdoc/src/SuperDoc.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 (
Expand Down
3 changes: 2 additions & 1 deletion packages/superdoc/src/core/SuperDoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
* @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
Expand Down Expand Up @@ -182,7 +183,7 @@
onCommentsListChange: () => null,
onException: () => null,
onListDefinitionsChange: () => null,

onTransaction: () => null,
Comment thread
harbournick marked this conversation as resolved.
// Image upload handler
// async (file) => url;
handleImageUpload: null,
Expand Down Expand Up @@ -402,7 +403,7 @@
/**
* Initialize telemetry service.
*/
#initTelemetry() {

Check warning on line 406 in packages/superdoc/src/core/SuperDoc.js

View workflow job for this annotation

GitHub Actions / Lint & Format Check

'#initTelemetry' is defined but never used
this.telemetry = new Telemetry({
enabled: this.config.telemetry?.enabled ?? true,
licenseKey: this.config.telemetry?.licenseKey,
Expand Down