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.mjs CHANGED
@@ -185,6 +185,18 @@ function getMarksAtPosition(spans, pos) {
185
185
  }
186
186
  return [];
187
187
  }
188
+ function hasDefinedAttributes(marks) {
189
+ if (!marks || marks.length === 0) return false;
190
+ for (const mark of marks) {
191
+ if (!mark.attrs) continue;
192
+ for (const value of Object.values(mark.attrs)) {
193
+ if (value !== void 0 && value !== null) {
194
+ return true;
195
+ }
196
+ }
197
+ }
198
+ return marks.some((m) => !m.attrs);
199
+ }
188
200
  function detectFormatChanges(spansA, spansB, segments) {
189
201
  const formatChanges = [];
190
202
  let posA = 0;
@@ -208,13 +220,17 @@ function detectFormatChanges(spansA, spansB, segments) {
208
220
  break;
209
221
  }
210
222
  }
211
- formatChanges.push({
212
- from: posA + startI,
213
- to: posA + i,
214
- text: segment.text.substring(startI, i),
215
- before: startMarksA,
216
- after: startMarksB
217
- });
223
+ if (hasDefinedAttributes(startMarksB) || hasDefinedAttributes(startMarksA)) {
224
+ if (hasDefinedAttributes(startMarksB)) {
225
+ formatChanges.push({
226
+ from: posA + startI,
227
+ to: posA + i,
228
+ text: segment.text.substring(startI, i),
229
+ before: startMarksA,
230
+ after: startMarksB
231
+ });
232
+ }
233
+ }
218
234
  } else {
219
235
  i++;
220
236
  }
@@ -1084,6 +1100,20 @@ var DocxDiffEditor = forwardRef(
1084
1100
  setDiffResult(null);
1085
1101
  }
1086
1102
  },
1103
+ /**
1104
+ * Accept all track changes and return the clean document
1105
+ */
1106
+ async acceptAllChanges() {
1107
+ const editor = superdocRef.current?.activeEditor;
1108
+ if (!editor) {
1109
+ throw new Error("Editor not ready");
1110
+ }
1111
+ editor.commands.acceptAllChanges();
1112
+ const cleanJson = editor.getJSON();
1113
+ setMergedJson(null);
1114
+ setDiffResult(null);
1115
+ return cleanJson;
1116
+ },
1087
1117
  /**
1088
1118
  * Check if editor is ready
1089
1119
  */