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/dist/index.mjs CHANGED
@@ -3177,17 +3177,27 @@ var DocxDiffEditor = forwardRef(
3177
3177
  }
3178
3178
  },
3179
3179
  /**
3180
- * Compare source with new content, show track changes
3180
+ * Compare current editor content with new content, show track changes.
3181
+ *
3182
+ * The comparison uses the current editor state (with any existing track
3183
+ * changes accepted/stripped) as the baseline. This means if you've made
3184
+ * edits or accepted previous comparisons, those become the new baseline.
3185
+ *
3186
+ * To compare against the original source document, call setSource() again
3187
+ * before compareWith().
3181
3188
  */
3182
3189
  async compareWith(content) {
3183
3190
  if (!SuperDocRef.current) {
3184
3191
  throw new Error("Editor not initialized");
3185
3192
  }
3186
- if (!sourceJson) {
3187
- throw new Error("No source document set. Call setSource() first.");
3193
+ if (!superdocRef.current?.activeEditor) {
3194
+ throw new Error("Editor not ready. Ensure a document is loaded first.");
3188
3195
  }
3189
3196
  setIsLoading(true);
3190
3197
  try {
3198
+ const currentEditorJson = superdocRef.current.activeEditor.getJSON();
3199
+ const cleanBaseline = acceptAllChangesInJson(currentEditorJson) || { type: "doc", content: [] };
3200
+ setSourceJson(cleanBaseline);
3191
3201
  const contentType = detectContentType(content);
3192
3202
  let newJson;
3193
3203
  if (contentType === "file") {
@@ -3246,14 +3256,14 @@ var DocxDiffEditor = forwardRef(
3246
3256
  }
3247
3257
  const normalizedNewJson = normalizeRunProperties(newJson);
3248
3258
  const structuralResult = mergeWithStructuralAwareness(
3249
- sourceJson,
3259
+ cleanBaseline,
3250
3260
  normalizedNewJson,
3251
3261
  author
3252
3262
  );
3253
3263
  const merged = structuralResult.mergedDoc;
3254
3264
  const structInfos = structuralResult.structuralInfos;
3255
3265
  setMergedJson(merged);
3256
- const diff = diffDocuments(sourceJson, newJson);
3266
+ const diff = diffDocuments(cleanBaseline, newJson);
3257
3267
  setDiffResult(diff);
3258
3268
  if (superdocRef.current?.activeEditor) {
3259
3269
  setEditorContent(superdocRef.current.activeEditor, merged);