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.mjs CHANGED
@@ -670,6 +670,30 @@ function groupReplacements(changes) {
670
670
  var permissionResolver = ({ permission }) => {
671
671
  return TRACK_CHANGE_PERMISSIONS.includes(permission) ? true : void 0;
672
672
  };
673
+ function acceptAllChangesInJson(node) {
674
+ if (!node) return null;
675
+ if (node.type === "text") {
676
+ const marks = node.marks || [];
677
+ if (marks.some((m) => m.type === "trackDelete")) {
678
+ return null;
679
+ }
680
+ const cleanMarks = marks.filter(
681
+ (m) => !["trackInsert", "trackDelete", "trackFormat"].includes(m.type)
682
+ );
683
+ return {
684
+ ...node,
685
+ marks: cleanMarks.length > 0 ? cleanMarks : void 0
686
+ };
687
+ }
688
+ if (node.content && Array.isArray(node.content)) {
689
+ const cleanContent = node.content.map((child) => acceptAllChangesInJson(child)).filter((child) => child !== null);
690
+ return {
691
+ ...node,
692
+ content: cleanContent.length > 0 ? cleanContent : void 0
693
+ };
694
+ }
695
+ return node;
696
+ }
673
697
  var DocxDiffEditor = forwardRef(
674
698
  function DocxDiffEditor2({
675
699
  initialSource,
@@ -1111,16 +1135,20 @@ var DocxDiffEditor = forwardRef(
1111
1135
  }
1112
1136
  const editorAny = editor;
1113
1137
  const sdAny = sd;
1138
+ let cleanJson;
1114
1139
  if (typeof editorAny.commands?.acceptAllChanges === "function") {
1115
1140
  editorAny.commands.acceptAllChanges();
1141
+ cleanJson = editor.getJSON();
1116
1142
  } else if (typeof sdAny.commands?.acceptAllChanges === "function") {
1117
1143
  sdAny.commands.acceptAllChanges();
1144
+ cleanJson = editor.getJSON();
1118
1145
  } else if (typeof sdAny.acceptAllChanges === "function") {
1119
1146
  sdAny.acceptAllChanges();
1147
+ cleanJson = editor.getJSON();
1120
1148
  } else {
1121
- sd.setTrackedChangesPreferences?.({ mode: "final", enabled: true });
1149
+ const currentJson = editor.getJSON();
1150
+ cleanJson = acceptAllChangesInJson(currentJson) || { type: "doc", content: [] };
1122
1151
  }
1123
- const cleanJson = editor.getJSON();
1124
1152
  setMergedJson(null);
1125
1153
  setDiffResult(null);
1126
1154
  return cleanJson;