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 +5 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +44 -8
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +44 -8
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1295,6 +1295,34 @@ function groupReplacements(changes) {
|
|
|
1295
1295
|
}
|
|
1296
1296
|
return result;
|
|
1297
1297
|
}
|
|
1298
|
+
function ensureValidCssColor(color) {
|
|
1299
|
+
if (typeof color !== "string" || !color) {
|
|
1300
|
+
return void 0;
|
|
1301
|
+
}
|
|
1302
|
+
if (/^[0-9a-fA-F]{6}$/.test(color)) {
|
|
1303
|
+
return `#${color}`;
|
|
1304
|
+
}
|
|
1305
|
+
if (/^[0-9a-fA-F]{3}$/.test(color)) {
|
|
1306
|
+
return `#${color}`;
|
|
1307
|
+
}
|
|
1308
|
+
return color;
|
|
1309
|
+
}
|
|
1310
|
+
function normalizeMark(mark) {
|
|
1311
|
+
const attrs = { ...mark.attrs || {} };
|
|
1312
|
+
if (attrs.color !== void 0) {
|
|
1313
|
+
attrs.color = ensureValidCssColor(attrs.color);
|
|
1314
|
+
}
|
|
1315
|
+
return {
|
|
1316
|
+
type: mark.type,
|
|
1317
|
+
attrs
|
|
1318
|
+
};
|
|
1319
|
+
}
|
|
1320
|
+
function normalizeMarks(marks) {
|
|
1321
|
+
return marks.map(normalizeMark);
|
|
1322
|
+
}
|
|
1323
|
+
function normalizeMarksForRendering(marks) {
|
|
1324
|
+
return normalizeMarks(marks);
|
|
1325
|
+
}
|
|
1298
1326
|
function createTrackInsertMark(author = DEFAULT_AUTHOR, id) {
|
|
1299
1327
|
return {
|
|
1300
1328
|
type: "trackInsert",
|
|
@@ -1320,6 +1348,8 @@ function createTrackDeleteMark(author = DEFAULT_AUTHOR, id) {
|
|
|
1320
1348
|
};
|
|
1321
1349
|
}
|
|
1322
1350
|
function createTrackFormatMark(before, after, author = DEFAULT_AUTHOR) {
|
|
1351
|
+
const normalizedBefore = normalizeMarks(before);
|
|
1352
|
+
const normalizedAfter = normalizeMarks(after);
|
|
1323
1353
|
return {
|
|
1324
1354
|
type: "trackFormat",
|
|
1325
1355
|
attrs: {
|
|
@@ -1328,8 +1358,8 @@ function createTrackFormatMark(before, after, author = DEFAULT_AUTHOR) {
|
|
|
1328
1358
|
authorEmail: author.email,
|
|
1329
1359
|
authorImage: "",
|
|
1330
1360
|
date: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1331
|
-
before,
|
|
1332
|
-
after
|
|
1361
|
+
before: normalizedBefore,
|
|
1362
|
+
after: normalizedAfter
|
|
1333
1363
|
}
|
|
1334
1364
|
};
|
|
1335
1365
|
}
|
|
@@ -1561,7 +1591,8 @@ function createInsertedTextNodes(text, posB, spansB, author, replacementId) {
|
|
|
1561
1591
|
}
|
|
1562
1592
|
if (span.relEnd > span.relStart) {
|
|
1563
1593
|
const spanText = text.substring(span.relStart, span.relEnd);
|
|
1564
|
-
const
|
|
1594
|
+
const normalizedSpanMarks = normalizeMarksForRendering(span.marks);
|
|
1595
|
+
const marks = [...normalizedSpanMarks, trackMark];
|
|
1565
1596
|
result.push({
|
|
1566
1597
|
type: "text",
|
|
1567
1598
|
text: spanText,
|
|
@@ -1669,7 +1700,8 @@ function mergeDocuments(docA, docB, diffResult, author = DEFAULT_AUTHOR) {
|
|
|
1669
1700
|
currentFormatChange.after,
|
|
1670
1701
|
author
|
|
1671
1702
|
);
|
|
1672
|
-
|
|
1703
|
+
const normalizedAfterMarks = normalizeMarksForRendering(currentFormatChange.after);
|
|
1704
|
+
marks = [...normalizedAfterMarks, trackFormatMark];
|
|
1673
1705
|
}
|
|
1674
1706
|
}
|
|
1675
1707
|
result.push({
|
|
@@ -2258,9 +2290,10 @@ function cloneNode2(node) {
|
|
|
2258
2290
|
}
|
|
2259
2291
|
function markAllTextAsInserted(node, sharedId, author) {
|
|
2260
2292
|
if (node.type === "text") {
|
|
2293
|
+
const existingMarks = normalizeMarksForRendering(node.marks || []);
|
|
2261
2294
|
return {
|
|
2262
2295
|
...node,
|
|
2263
|
-
marks: [...
|
|
2296
|
+
marks: [...existingMarks, createTrackInsertMark(author, sharedId)]
|
|
2264
2297
|
};
|
|
2265
2298
|
}
|
|
2266
2299
|
if (node.content && Array.isArray(node.content)) {
|
|
@@ -2275,9 +2308,10 @@ function markAllTextAsInserted(node, sharedId, author) {
|
|
|
2275
2308
|
}
|
|
2276
2309
|
function markAllTextAsDeleted(node, sharedId, author) {
|
|
2277
2310
|
if (node.type === "text") {
|
|
2311
|
+
const existingMarks = normalizeMarksForRendering(node.marks || []);
|
|
2278
2312
|
return {
|
|
2279
2313
|
...node,
|
|
2280
|
-
marks: [...
|
|
2314
|
+
marks: [...existingMarks, createTrackDeleteMark(author, sharedId)]
|
|
2281
2315
|
};
|
|
2282
2316
|
}
|
|
2283
2317
|
if (node.content && Array.isArray(node.content)) {
|
|
@@ -3538,9 +3572,10 @@ var DocxDiffEditor_default = DocxDiffEditor;
|
|
|
3538
3572
|
init_nodeFingerprint();
|
|
3539
3573
|
function markAllTextAsInserted2(node, sharedId, author) {
|
|
3540
3574
|
if (node.type === "text") {
|
|
3575
|
+
const existingMarks = normalizeMarksForRendering(node.marks || []);
|
|
3541
3576
|
return {
|
|
3542
3577
|
...node,
|
|
3543
|
-
marks: [...
|
|
3578
|
+
marks: [...existingMarks, createTrackInsertMark(author, sharedId)]
|
|
3544
3579
|
};
|
|
3545
3580
|
}
|
|
3546
3581
|
if (node.content && Array.isArray(node.content)) {
|
|
@@ -3555,9 +3590,10 @@ function markAllTextAsInserted2(node, sharedId, author) {
|
|
|
3555
3590
|
}
|
|
3556
3591
|
function markAllTextAsDeleted2(node, sharedId, author) {
|
|
3557
3592
|
if (node.type === "text") {
|
|
3593
|
+
const existingMarks = normalizeMarksForRendering(node.marks || []);
|
|
3558
3594
|
return {
|
|
3559
3595
|
...node,
|
|
3560
|
-
marks: [...
|
|
3596
|
+
marks: [...existingMarks, createTrackDeleteMark(author, sharedId)]
|
|
3561
3597
|
};
|
|
3562
3598
|
}
|
|
3563
3599
|
if (node.content && Array.isArray(node.content)) {
|