docx-diff-editor 1.0.47 → 1.0.48

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -513,6 +513,11 @@ declare function createTrackInsertMark(author?: TrackChangeAuthor, id?: string):
513
513
  declare function createTrackDeleteMark(author?: TrackChangeAuthor, id?: string): ProseMirrorMark;
514
514
  /**
515
515
  * Create a trackFormat mark.
516
+ *
517
+ * Note: SuperDoc's parseFormatList requires all marks in before/after arrays
518
+ * to have both `type` and `attrs` properties. Marks without `attrs` get filtered out,
519
+ * causing empty values in track change bubbles. We normalize marks here to ensure
520
+ * all have at least an empty `attrs` object.
516
521
  */
517
522
  declare function createTrackFormatMark(before: ProseMirrorMark[], after: ProseMirrorMark[], author?: TrackChangeAuthor): ProseMirrorMark;
518
523
 
package/dist/index.d.ts CHANGED
@@ -513,6 +513,11 @@ declare function createTrackInsertMark(author?: TrackChangeAuthor, id?: string):
513
513
  declare function createTrackDeleteMark(author?: TrackChangeAuthor, id?: string): ProseMirrorMark;
514
514
  /**
515
515
  * Create a trackFormat mark.
516
+ *
517
+ * Note: SuperDoc's parseFormatList requires all marks in before/after arrays
518
+ * to have both `type` and `attrs` properties. Marks without `attrs` get filtered out,
519
+ * causing empty values in track change bubbles. We normalize marks here to ensure
520
+ * all have at least an empty `attrs` object.
516
521
  */
517
522
  declare function createTrackFormatMark(before: ProseMirrorMark[], after: ProseMirrorMark[], author?: TrackChangeAuthor): ProseMirrorMark;
518
523
 
package/dist/index.js CHANGED
@@ -1303,6 +1303,34 @@ function groupReplacements(changes) {
1303
1303
  }
1304
1304
  return result;
1305
1305
  }
1306
+ function ensureValidCssColor(color) {
1307
+ if (typeof color !== "string" || !color) {
1308
+ return void 0;
1309
+ }
1310
+ if (/^[0-9a-fA-F]{6}$/.test(color)) {
1311
+ return `#${color}`;
1312
+ }
1313
+ if (/^[0-9a-fA-F]{3}$/.test(color)) {
1314
+ return `#${color}`;
1315
+ }
1316
+ return color;
1317
+ }
1318
+ function normalizeMark(mark) {
1319
+ const attrs = { ...mark.attrs || {} };
1320
+ if (attrs.color !== void 0) {
1321
+ attrs.color = ensureValidCssColor(attrs.color);
1322
+ }
1323
+ return {
1324
+ type: mark.type,
1325
+ attrs
1326
+ };
1327
+ }
1328
+ function normalizeMarks(marks) {
1329
+ return marks.map(normalizeMark);
1330
+ }
1331
+ function normalizeMarksForRendering(marks) {
1332
+ return normalizeMarks(marks);
1333
+ }
1306
1334
  function createTrackInsertMark(author = DEFAULT_AUTHOR, id) {
1307
1335
  return {
1308
1336
  type: "trackInsert",
@@ -1328,6 +1356,8 @@ function createTrackDeleteMark(author = DEFAULT_AUTHOR, id) {
1328
1356
  };
1329
1357
  }
1330
1358
  function createTrackFormatMark(before, after, author = DEFAULT_AUTHOR) {
1359
+ const normalizedBefore = normalizeMarks(before);
1360
+ const normalizedAfter = normalizeMarks(after);
1331
1361
  return {
1332
1362
  type: "trackFormat",
1333
1363
  attrs: {
@@ -1336,8 +1366,8 @@ function createTrackFormatMark(before, after, author = DEFAULT_AUTHOR) {
1336
1366
  authorEmail: author.email,
1337
1367
  authorImage: "",
1338
1368
  date: (/* @__PURE__ */ new Date()).toISOString(),
1339
- before,
1340
- after
1369
+ before: normalizedBefore,
1370
+ after: normalizedAfter
1341
1371
  }
1342
1372
  };
1343
1373
  }
@@ -1569,7 +1599,8 @@ function createInsertedTextNodes(text, posB, spansB, author, replacementId) {
1569
1599
  }
1570
1600
  if (span.relEnd > span.relStart) {
1571
1601
  const spanText = text.substring(span.relStart, span.relEnd);
1572
- const marks = [...span.marks, trackMark];
1602
+ const normalizedSpanMarks = normalizeMarksForRendering(span.marks);
1603
+ const marks = [...normalizedSpanMarks, trackMark];
1573
1604
  result.push({
1574
1605
  type: "text",
1575
1606
  text: spanText,
@@ -1677,7 +1708,8 @@ function mergeDocuments(docA, docB, diffResult, author = DEFAULT_AUTHOR) {
1677
1708
  currentFormatChange.after,
1678
1709
  author
1679
1710
  );
1680
- marks = [...currentFormatChange.after, trackFormatMark];
1711
+ const normalizedAfterMarks = normalizeMarksForRendering(currentFormatChange.after);
1712
+ marks = [...normalizedAfterMarks, trackFormatMark];
1681
1713
  }
1682
1714
  }
1683
1715
  result.push({
@@ -2266,9 +2298,10 @@ function cloneNode2(node) {
2266
2298
  }
2267
2299
  function markAllTextAsInserted(node, sharedId, author) {
2268
2300
  if (node.type === "text") {
2301
+ const existingMarks = normalizeMarksForRendering(node.marks || []);
2269
2302
  return {
2270
2303
  ...node,
2271
- marks: [...node.marks || [], createTrackInsertMark(author, sharedId)]
2304
+ marks: [...existingMarks, createTrackInsertMark(author, sharedId)]
2272
2305
  };
2273
2306
  }
2274
2307
  if (node.content && Array.isArray(node.content)) {
@@ -2283,9 +2316,10 @@ function markAllTextAsInserted(node, sharedId, author) {
2283
2316
  }
2284
2317
  function markAllTextAsDeleted(node, sharedId, author) {
2285
2318
  if (node.type === "text") {
2319
+ const existingMarks = normalizeMarksForRendering(node.marks || []);
2286
2320
  return {
2287
2321
  ...node,
2288
- marks: [...node.marks || [], createTrackDeleteMark(author, sharedId)]
2322
+ marks: [...existingMarks, createTrackDeleteMark(author, sharedId)]
2289
2323
  };
2290
2324
  }
2291
2325
  if (node.content && Array.isArray(node.content)) {
@@ -3546,9 +3580,10 @@ var DocxDiffEditor_default = DocxDiffEditor;
3546
3580
  init_nodeFingerprint();
3547
3581
  function markAllTextAsInserted2(node, sharedId, author) {
3548
3582
  if (node.type === "text") {
3583
+ const existingMarks = normalizeMarksForRendering(node.marks || []);
3549
3584
  return {
3550
3585
  ...node,
3551
- marks: [...node.marks || [], createTrackInsertMark(author, sharedId)]
3586
+ marks: [...existingMarks, createTrackInsertMark(author, sharedId)]
3552
3587
  };
3553
3588
  }
3554
3589
  if (node.content && Array.isArray(node.content)) {
@@ -3563,9 +3598,10 @@ function markAllTextAsInserted2(node, sharedId, author) {
3563
3598
  }
3564
3599
  function markAllTextAsDeleted2(node, sharedId, author) {
3565
3600
  if (node.type === "text") {
3601
+ const existingMarks = normalizeMarksForRendering(node.marks || []);
3566
3602
  return {
3567
3603
  ...node,
3568
- marks: [...node.marks || [], createTrackDeleteMark(author, sharedId)]
3604
+ marks: [...existingMarks, createTrackDeleteMark(author, sharedId)]
3569
3605
  };
3570
3606
  }
3571
3607
  if (node.content && Array.isArray(node.content)) {