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
11 changes: 10 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 16 additions & 3 deletions packages/super-editor/src/core/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,12 @@ export class Editor extends EventEmitter {
onDocumentLocked: () => null,
onFirstRender: () => null,
onCollaborationReady: () => null,
onException: () => null,
// async (file) => url;
handleImageUpload: null,

// telemetry
telemetry: null,
};

constructor(options) {
Expand All @@ -99,7 +103,7 @@ export class Editor extends EventEmitter {
};

let initMode = modes[this.options.mode] ?? modes.default;

initMode();
}

Expand All @@ -113,6 +117,7 @@ export class Editor extends EventEmitter {
this.on('beforeCreate', this.options.onBeforeCreate);
this.emit('beforeCreate', { editor: this });
this.on('contentError', this.options.onContentError);
this.on('exception', this.options.onException);

this.#createView();
this.initDefaultStyles();
Expand Down Expand Up @@ -438,6 +443,9 @@ export class Editor extends EventEmitter {
docx: this.options.content,
media: this.options.mediaFiles,
debug: true,
telemetry: this.options.telemetry,
fileSource: this.options.fileSource,
documentId: this.options.documentId,
});
}
}
Expand Down Expand Up @@ -495,9 +503,9 @@ export class Editor extends EventEmitter {

try {
const { mode, fragment, isHeadless, content, loadFromSchema } = this.options;

if (mode === 'docx') {
doc = createDocument(this.converter, this.schema);
doc = createDocument(this.converter, this.schema, this);

if (fragment && isHeadless) {
doc = yXmlFragmentToProseMirrorRootNode(fragment, this.schema);
Expand Down Expand Up @@ -838,6 +846,11 @@ export class Editor extends EventEmitter {
fonts: this.options.fonts,
isHeadless: this.options.isHeadless,
});

this.telemetry?.trackUsage('document_export', {
documentType: 'docx',
timestamp: new Date().toISOString()
});

return result;
}
Expand Down
21 changes: 21 additions & 0 deletions packages/super-editor/src/core/helpers/ErrorWithDetails.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* Custom error class which allows to pass additional details
* @param {string} name - Error name
* @param {string} message - Error message
* @param {object} details - additional details from the calling context
*/

function ErrorWithDetails(name, message, details) {
this.name = name;
this.message = message || '';
this.details = details;

const error = new Error(this.message);
this.stack = error.stack;
error.name = this.name;
}
ErrorWithDetails.prototype = Object.create(Error.prototype);

export {
ErrorWithDetails,
}
5 changes: 3 additions & 2 deletions packages/super-editor/src/core/helpers/createDocument.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
* Creates the document to pass to EditorState.
* @param converter SuperConverter instance.
* @param schema Schema.
* @param editor Editor
* @returns Document.
*/
export function createDocument(converter, schema) {
const documentData = converter.getSchema();
export function createDocument(converter, schema, editor) {
const documentData = converter.getSchema(editor);

if (documentData) {
return schema.nodeFromJSON(documentData);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ class SuperConverter {
this.tagsNotInSchema = ['w:body'];
this.savedTagsToRestore = [];

// Initialize telemetry
this.telemetry = params?.telemetry || null;
this.documentInternalId = null;

// Uploaded file
this.fileSource = params?.fileSource || null;
this.documentId = params?.documentId || null;

// Parse the initial XML, if provided
if (this.docx.length || this.xml) this.parseFromXml();
}
Expand Down Expand Up @@ -155,6 +163,15 @@ class SuperConverter {
return { fontSizePt, kern, typeface, panose };
}
}

getDocumentInternalId() {
const settings = this.convertedXml['word/settings.xml'];
if (!settings) return '';
// New versions of Word will have w15:docId
// It's possible to have w14:docId as well but Word(2013 and later) will convert it automatically when document opened
const w15DocId = settings.elements[0].elements.find((el) => el.name === 'w15:docId');
this.documentInternalId = w15DocId?.attributes['w15:val'];
Comment thread
caio-pizzol marked this conversation as resolved.
}

getThemeInfo(themeName) {
themeName = themeName.toLowerCase();
Expand All @@ -174,8 +191,10 @@ class SuperConverter {
return { typeface, panose };
}

getSchema() {
const result = createDocumentJson({...this.convertedXml, media: this.media }, this );
getSchema(editor) {
this.getDocumentInternalId();
const result = createDocumentJson({...this.convertedXml, media: this.media }, this, editor);

if (result) {
this.savedTagsToRestore.push({ ...result.savedTagsToRestore });
this.pageStyles = result.pageStyles;
Expand Down
Loading