docx-diff-editor 1.0.24 → 1.0.27
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 +6 -2
- package/dist/index.d.ts +6 -2
- package/dist/index.js +28 -13
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +28 -13
- package/dist/index.mjs.map +1 -1
- package/dist/styles.css +5462 -7
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -272,11 +272,11 @@ function diffDocuments(docA, docB) {
|
|
|
272
272
|
summary
|
|
273
273
|
};
|
|
274
274
|
}
|
|
275
|
-
function createTrackInsertMark(author = DEFAULT_AUTHOR) {
|
|
275
|
+
function createTrackInsertMark(author = DEFAULT_AUTHOR, id) {
|
|
276
276
|
return {
|
|
277
277
|
type: "trackInsert",
|
|
278
278
|
attrs: {
|
|
279
|
-
id: v4(),
|
|
279
|
+
id: id ?? v4(),
|
|
280
280
|
author: author.name,
|
|
281
281
|
authorEmail: author.email,
|
|
282
282
|
authorImage: "",
|
|
@@ -284,11 +284,11 @@ function createTrackInsertMark(author = DEFAULT_AUTHOR) {
|
|
|
284
284
|
}
|
|
285
285
|
};
|
|
286
286
|
}
|
|
287
|
-
function createTrackDeleteMark(author = DEFAULT_AUTHOR) {
|
|
287
|
+
function createTrackDeleteMark(author = DEFAULT_AUTHOR, id) {
|
|
288
288
|
return {
|
|
289
289
|
type: "trackDelete",
|
|
290
290
|
attrs: {
|
|
291
|
-
id: v4(),
|
|
291
|
+
id: id ?? v4(),
|
|
292
292
|
author: author.name,
|
|
293
293
|
authorEmail: author.email,
|
|
294
294
|
authorImage: "",
|
|
@@ -329,17 +329,30 @@ function mergeDocuments(docA, docB, diffResult, author = DEFAULT_AUTHOR) {
|
|
|
329
329
|
return null;
|
|
330
330
|
}
|
|
331
331
|
let docAOffset = 0;
|
|
332
|
-
|
|
332
|
+
const segments = diffResult.segments;
|
|
333
|
+
for (let segIdx = 0; segIdx < segments.length; segIdx++) {
|
|
334
|
+
const segment = segments[segIdx];
|
|
333
335
|
if (segment.type === "equal") {
|
|
334
336
|
for (let i = 0; i < segment.text.length; i++) {
|
|
335
337
|
charStates[docAOffset + i] = { type: "equal" };
|
|
336
338
|
}
|
|
337
339
|
docAOffset += segment.text.length;
|
|
338
340
|
} else if (segment.type === "delete") {
|
|
341
|
+
const nextSegment = segments[segIdx + 1];
|
|
342
|
+
const isReplacement = nextSegment && nextSegment.type === "insert";
|
|
343
|
+
const replacementId = isReplacement ? v4() : void 0;
|
|
339
344
|
for (let i = 0; i < segment.text.length; i++) {
|
|
340
|
-
charStates[docAOffset + i] = { type: "delete" };
|
|
345
|
+
charStates[docAOffset + i] = { type: "delete", replacementId };
|
|
341
346
|
}
|
|
342
347
|
docAOffset += segment.text.length;
|
|
348
|
+
if (isReplacement && nextSegment) {
|
|
349
|
+
insertions.push({
|
|
350
|
+
afterOffset: docAOffset,
|
|
351
|
+
text: nextSegment.text,
|
|
352
|
+
replacementId
|
|
353
|
+
});
|
|
354
|
+
segIdx++;
|
|
355
|
+
}
|
|
343
356
|
} else if (segment.type === "insert") {
|
|
344
357
|
insertions.push({
|
|
345
358
|
afterOffset: docAOffset,
|
|
@@ -360,7 +373,7 @@ function mergeDocuments(docA, docB, diffResult, author = DEFAULT_AUTHOR) {
|
|
|
360
373
|
result.push({
|
|
361
374
|
type: "text",
|
|
362
375
|
text: ins.text,
|
|
363
|
-
marks: [...node.marks || [], createTrackInsertMark(author)]
|
|
376
|
+
marks: [...node.marks || [], createTrackInsertMark(author, ins.replacementId)]
|
|
364
377
|
});
|
|
365
378
|
}
|
|
366
379
|
const currentFormatChange = getFormatChangeAt(nodeOffset + i);
|
|
@@ -376,7 +389,7 @@ function mergeDocuments(docA, docB, diffResult, author = DEFAULT_AUTHOR) {
|
|
|
376
389
|
const chunk = text.substring(i, j);
|
|
377
390
|
let marks = [...node.marks || []];
|
|
378
391
|
if (charState.type === "delete") {
|
|
379
|
-
marks.push(createTrackDeleteMark(author));
|
|
392
|
+
marks.push(createTrackDeleteMark(author, charState.replacementId));
|
|
380
393
|
} else if (charState.type === "equal") {
|
|
381
394
|
if (currentFormatChange) {
|
|
382
395
|
const trackFormatMark = createTrackFormatMark(
|
|
@@ -400,7 +413,7 @@ function mergeDocuments(docA, docB, diffResult, author = DEFAULT_AUTHOR) {
|
|
|
400
413
|
result.push({
|
|
401
414
|
type: "text",
|
|
402
415
|
text: ins.text,
|
|
403
|
-
marks: [...node.marks || [], createTrackInsertMark(author)]
|
|
416
|
+
marks: [...node.marks || [], createTrackInsertMark(author, ins.replacementId)]
|
|
404
417
|
});
|
|
405
418
|
}
|
|
406
419
|
insertions = insertions.filter(
|
|
@@ -445,7 +458,7 @@ function mergeDocuments(docA, docB, diffResult, author = DEFAULT_AUTHOR) {
|
|
|
445
458
|
{
|
|
446
459
|
type: "text",
|
|
447
460
|
text: ins.text,
|
|
448
|
-
marks: [createTrackInsertMark(author)]
|
|
461
|
+
marks: [createTrackInsertMark(author, ins.replacementId)]
|
|
449
462
|
}
|
|
450
463
|
]
|
|
451
464
|
}
|
|
@@ -837,8 +850,8 @@ var DocxDiffEditor = forwardRef(
|
|
|
837
850
|
console.error("Failed to initialize SuperDoc:", err);
|
|
838
851
|
handleError(err instanceof Error ? err : new Error("Failed to load editor"));
|
|
839
852
|
setIsLoading(false);
|
|
853
|
+
initRef.current = false;
|
|
840
854
|
}
|
|
841
|
-
initRef.current = false;
|
|
842
855
|
}, [
|
|
843
856
|
initialSource,
|
|
844
857
|
showRulers,
|
|
@@ -853,12 +866,14 @@ var DocxDiffEditor = forwardRef(
|
|
|
853
866
|
]);
|
|
854
867
|
useEffect(() => {
|
|
855
868
|
mountedRef.current = true;
|
|
856
|
-
|
|
869
|
+
if (!initRef.current) {
|
|
870
|
+
initialize();
|
|
871
|
+
}
|
|
857
872
|
return () => {
|
|
858
873
|
mountedRef.current = false;
|
|
859
874
|
destroySuperdoc();
|
|
860
875
|
};
|
|
861
|
-
}, [
|
|
876
|
+
}, []);
|
|
862
877
|
useImperativeHandle(
|
|
863
878
|
ref,
|
|
864
879
|
() => ({
|