Skip to content

Commit 3a0d65f

Browse files
authored
Merge pull request #430 from Harbour-Enterprises/artem-HAR-9383
HAR-9383 - import and export tracked changes comments
2 parents ef1485f + aded815 commit 3a0d65f

3 files changed

Lines changed: 26 additions & 5 deletions

File tree

packages/super-editor/src/core/super-converter/v2/exporter/commentsExporter.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ export const prepareCommentParaIds = (comment) => {
9090
*/
9191
export const getCommentDefinition = (comment, commentId, allComments) => {
9292
const translatedText = translateParagraphNode({ node: comment.commentJSON });
93-
9493
const attributes = {
9594
'w:id': String(commentId),
9695
'w:author': comment.creatorName || comment.importedAuthor?.name,
@@ -100,6 +99,9 @@ export const getCommentDefinition = (comment, commentId, allComments) => {
10099
'w:done': comment.resolvedTime ? '1' : '0',
101100
'w15:paraId': comment.commentParaId,
102101
'custom:internalId': comment.commentId || comment.internalId,
102+
'custom:trackedChange': comment.trackedChange,
103+
'custom:trackedChangeText': comment.trackedChangeText,
104+
'custom:trackedChangeType': comment.trackedChangeType,
103105
};
104106

105107
// Add the w15:paraIdParent attribute if the comment has a parent
@@ -164,9 +166,13 @@ export const updateCommentsXml = (commentDefs = [], commentsXml) => {
164166
commentDef.attributes = {
165167
'w:id': commentDef.attributes['w:id'],
166168
'w:author': commentDef.attributes['w:author'],
169+
'w:email': commentDef.attributes['w:email'],
167170
'w:date': commentDef.attributes['w:date'],
168171
'w:initials': commentDef.attributes['w:initials'],
169172
'custom:internalId': commentDef.attributes['custom:internalId'],
173+
'custom:trackedChange': commentDef.attributes['custom:trackedChange'],
174+
'custom:trackedChangeText': commentDef.attributes['custom:trackedChangeText'],
175+
'custom:trackedChangeType': commentDef.attributes['custom:trackedChangeType'],
170176
'xmlns:custom': 'http://schemas.openxmlformats.org/wordprocessingml/2006/main',
171177
};
172178
});

packages/super-editor/src/core/super-converter/v2/importer/documentCommentsImporter.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,17 @@ export function importCommentData({ docx }) {
2222

2323
const { elements: allComments = [] } = elements[0];
2424
const extractedComments = allComments.map((el) => {
25-
2625
const { attributes } = el;
2726
const importedId = attributes['w:id'];
2827
const authorName = attributes['w:author'];
2928
const authorEmail = attributes['w:email'];
3029
const initials = attributes['w:initials'];
3130
const createdDate = attributes['w:date'];
3231
const internalId = attributes['custom:internalId'];
32+
const trackedChange = attributes['custom:trackedChange'] === 'true';
33+
const trackedChangeText = attributes['custom:trackedChangeText'];
34+
const trackedChangeType = attributes['custom:trackedChangeType'];
35+
3336
const date = new Date(createdDate);
3437
const unixTimestampMs = date.getTime();
3538

@@ -53,6 +56,9 @@ export function importCommentData({ docx }) {
5356
textJson: parsedComment[0],
5457
initials,
5558
paraId,
59+
trackedChange,
60+
trackedChangeText,
61+
trackedChangeType,
5662
};
5763
});
5864

packages/superdoc/src/stores/comments-store.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ export const useCommentsStore = defineStore('comments', () => {
122122
trackedChangeType,
123123
deletedText,
124124
createdTime: date,
125-
creatorNamne: authorName,
125+
creatorName: authorName,
126126
creatorEmail: authorEmail,
127127
isInternal: false,
128128
selection: {
@@ -448,15 +448,21 @@ export const useCommentsStore = defineStore('comments', () => {
448448

449449
comments.forEach((comment) => {
450450
const htmlContent = getHTmlFromComment(comment.textJson);
451-
if (!htmlContent) return;
452451

453-
const importedName = `${comment.creatorName.replace('(imported)', '')} (imported)`
452+
if (!htmlContent && !comment.trackedChange) {
453+
return;
454+
}
455+
456+
const creatorName = comment.creatorName.replace('(imported)', '');
457+
const importedName = `${creatorName} (imported)`;
454458
const newComment = useComment({
455459
fileId: documentId,
456460
fileType: document.type,
457461
commentId: comment.commentId,
458462
isInternal: false,
459463
parentCommentId: comment.parentCommentId,
464+
creatorName,
465+
creatorEmail: comment.creatorEmail,
460466
importedAuthor: {
461467
name: importedName,
462468
email: comment.creatorEmail,
@@ -465,6 +471,9 @@ export const useCommentsStore = defineStore('comments', () => {
465471
resolvedTime: comment.isDone ? Date.now() : null,
466472
resolvedByEmail: comment.isDone ? comment.creatorEmail : null,
467473
resolvedByName: comment.isDone ? importedName : null,
474+
trackedChange: comment.trackedChange || false,
475+
trackedChangeText: comment.trackedChangeText,
476+
trackedChangeType: comment.trackedChangeType,
468477
});
469478

470479
addComment({ superdoc, comment: newComment });

0 commit comments

Comments
 (0)