docx-diff-editor 1.0.30 → 1.0.32

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.js CHANGED
@@ -678,6 +678,30 @@ function groupReplacements(changes) {
678
678
  var permissionResolver = ({ permission }) => {
679
679
  return TRACK_CHANGE_PERMISSIONS.includes(permission) ? true : void 0;
680
680
  };
681
+ function acceptAllChangesInJson(node) {
682
+ if (!node) return null;
683
+ if (node.type === "text") {
684
+ const marks = node.marks || [];
685
+ if (marks.some((m) => m.type === "trackDelete")) {
686
+ return null;
687
+ }
688
+ const cleanMarks = marks.filter(
689
+ (m) => !["trackInsert", "trackDelete", "trackFormat"].includes(m.type)
690
+ );
691
+ return {
692
+ ...node,
693
+ marks: cleanMarks.length > 0 ? cleanMarks : void 0
694
+ };
695
+ }
696
+ if (node.content && Array.isArray(node.content)) {
697
+ const cleanContent = node.content.map((child) => acceptAllChangesInJson(child)).filter((child) => child !== null);
698
+ return {
699
+ ...node,
700
+ content: cleanContent.length > 0 ? cleanContent : void 0
701
+ };
702
+ }
703
+ return node;
704
+ }
681
705
  var DocxDiffEditor = react.forwardRef(
682
706
  function DocxDiffEditor2({
683
707
  initialSource,
@@ -1119,16 +1143,20 @@ var DocxDiffEditor = react.forwardRef(
1119
1143
  }
1120
1144
  const editorAny = editor;
1121
1145
  const sdAny = sd;
1146
+ let cleanJson;
1122
1147
  if (typeof editorAny.commands?.acceptAllChanges === "function") {
1123
1148
  editorAny.commands.acceptAllChanges();
1149
+ cleanJson = editor.getJSON();
1124
1150
  } else if (typeof sdAny.commands?.acceptAllChanges === "function") {
1125
1151
  sdAny.commands.acceptAllChanges();
1152
+ cleanJson = editor.getJSON();
1126
1153
  } else if (typeof sdAny.acceptAllChanges === "function") {
1127
1154
  sdAny.acceptAllChanges();
1155
+ cleanJson = editor.getJSON();
1128
1156
  } else {
1129
- sd.setTrackedChangesPreferences?.({ mode: "final", enabled: true });
1157
+ const currentJson = editor.getJSON();
1158
+ cleanJson = acceptAllChangesInJson(currentJson) || { type: "doc", content: [] };
1130
1159
  }
1131
- const cleanJson = editor.getJSON();
1132
1160
  setMergedJson(null);
1133
1161
  setDiffResult(null);
1134
1162
  return cleanJson;