docx-diff-editor 1.0.27 → 1.0.29

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
@@ -158,6 +158,8 @@ interface DocxDiffEditorRef {
158
158
  exportDocx(): Promise<Blob>;
159
159
  /** Reset to source state (clear comparison) */
160
160
  resetComparison(): void;
161
+ /** Accept all track changes and return the clean document */
162
+ acceptAllChanges(): Promise<ProseMirrorJSON>;
161
163
  /** Check if editor is ready */
162
164
  isReady(): boolean;
163
165
  }
package/dist/index.d.ts CHANGED
@@ -158,6 +158,8 @@ interface DocxDiffEditorRef {
158
158
  exportDocx(): Promise<Blob>;
159
159
  /** Reset to source state (clear comparison) */
160
160
  resetComparison(): void;
161
+ /** Accept all track changes and return the clean document */
162
+ acceptAllChanges(): Promise<ProseMirrorJSON>;
161
163
  /** Check if editor is ready */
162
164
  isReady(): boolean;
163
165
  }
package/dist/index.js CHANGED
@@ -193,6 +193,18 @@ function getMarksAtPosition(spans, pos) {
193
193
  }
194
194
  return [];
195
195
  }
196
+ function hasDefinedAttributes(marks) {
197
+ if (!marks || marks.length === 0) return false;
198
+ for (const mark of marks) {
199
+ if (!mark.attrs) continue;
200
+ for (const value of Object.values(mark.attrs)) {
201
+ if (value !== void 0 && value !== null) {
202
+ return true;
203
+ }
204
+ }
205
+ }
206
+ return marks.some((m) => !m.attrs);
207
+ }
196
208
  function detectFormatChanges(spansA, spansB, segments) {
197
209
  const formatChanges = [];
198
210
  let posA = 0;
@@ -216,13 +228,17 @@ function detectFormatChanges(spansA, spansB, segments) {
216
228
  break;
217
229
  }
218
230
  }
219
- formatChanges.push({
220
- from: posA + startI,
221
- to: posA + i,
222
- text: segment.text.substring(startI, i),
223
- before: startMarksA,
224
- after: startMarksB
225
- });
231
+ if (hasDefinedAttributes(startMarksB) || hasDefinedAttributes(startMarksA)) {
232
+ if (hasDefinedAttributes(startMarksB)) {
233
+ formatChanges.push({
234
+ from: posA + startI,
235
+ to: posA + i,
236
+ text: segment.text.substring(startI, i),
237
+ before: startMarksA,
238
+ after: startMarksB
239
+ });
240
+ }
241
+ }
226
242
  } else {
227
243
  i++;
228
244
  }
@@ -1092,6 +1108,20 @@ var DocxDiffEditor = react.forwardRef(
1092
1108
  setDiffResult(null);
1093
1109
  }
1094
1110
  },
1111
+ /**
1112
+ * Accept all track changes and return the clean document
1113
+ */
1114
+ async acceptAllChanges() {
1115
+ const editor = superdocRef.current?.activeEditor;
1116
+ if (!editor) {
1117
+ throw new Error("Editor not ready");
1118
+ }
1119
+ editor.commands.acceptAllChanges();
1120
+ const cleanJson = editor.getJSON();
1121
+ setMergedJson(null);
1122
+ setDiffResult(null);
1123
+ return cleanJson;
1124
+ },
1095
1125
  /**
1096
1126
  * Check if editor is ready
1097
1127
  */