docx-diff-editor 1.0.52 → 1.0.53

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/README.md CHANGED
@@ -51,6 +51,10 @@ function App() {
51
51
  );
52
52
 
53
53
  console.log(`Found ${result.totalChanges} changes`);
54
+
55
+ // Note: Subsequent compareWith calls compare against current editor state
56
+ // (with track changes accepted), not the original source.
57
+ // To compare against original again, call setSource() first.
54
58
  };
55
59
 
56
60
  return (
@@ -117,7 +121,8 @@ interface DocxDiffEditorRef {
117
121
  // Set the source/base document
118
122
  setSource(content: DocxContent): Promise<void>;
119
123
 
120
- // Compare and show track changes
124
+ // Compare current editor content with new content, show track changes
125
+ // Note: Compares against current editor state (not original source)
121
126
  compareWith(content: DocxContent): Promise<ComparisonResult>;
122
127
 
123
128
  // Get diff data
package/dist/index.js CHANGED
@@ -3185,17 +3185,27 @@ var DocxDiffEditor = react.forwardRef(
3185
3185
  }
3186
3186
  },
3187
3187
  /**
3188
- * Compare source with new content, show track changes
3188
+ * Compare current editor content with new content, show track changes.
3189
+ *
3190
+ * The comparison uses the current editor state (with any existing track
3191
+ * changes accepted/stripped) as the baseline. This means if you've made
3192
+ * edits or accepted previous comparisons, those become the new baseline.
3193
+ *
3194
+ * To compare against the original source document, call setSource() again
3195
+ * before compareWith().
3189
3196
  */
3190
3197
  async compareWith(content) {
3191
3198
  if (!SuperDocRef.current) {
3192
3199
  throw new Error("Editor not initialized");
3193
3200
  }
3194
- if (!sourceJson) {
3195
- throw new Error("No source document set. Call setSource() first.");
3201
+ if (!superdocRef.current?.activeEditor) {
3202
+ throw new Error("Editor not ready. Ensure a document is loaded first.");
3196
3203
  }
3197
3204
  setIsLoading(true);
3198
3205
  try {
3206
+ const currentEditorJson = superdocRef.current.activeEditor.getJSON();
3207
+ const cleanBaseline = acceptAllChangesInJson(currentEditorJson) || { type: "doc", content: [] };
3208
+ setSourceJson(cleanBaseline);
3199
3209
  const contentType = detectContentType(content);
3200
3210
  let newJson;
3201
3211
  if (contentType === "file") {
@@ -3254,14 +3264,14 @@ var DocxDiffEditor = react.forwardRef(
3254
3264
  }
3255
3265
  const normalizedNewJson = normalizeRunProperties(newJson);
3256
3266
  const structuralResult = mergeWithStructuralAwareness(
3257
- sourceJson,
3267
+ cleanBaseline,
3258
3268
  normalizedNewJson,
3259
3269
  author
3260
3270
  );
3261
3271
  const merged = structuralResult.mergedDoc;
3262
3272
  const structInfos = structuralResult.structuralInfos;
3263
3273
  setMergedJson(merged);
3264
- const diff = diffDocuments(sourceJson, newJson);
3274
+ const diff = diffDocuments(cleanBaseline, newJson);
3265
3275
  setDiffResult(diff);
3266
3276
  if (superdocRef.current?.activeEditor) {
3267
3277
  setEditorContent(superdocRef.current.activeEditor, merged);