docx-diff-editor 1.0.29 → 1.0.31

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,
@@ -1113,11 +1137,26 @@ var DocxDiffEditor = react.forwardRef(
1113
1137
  */
1114
1138
  async acceptAllChanges() {
1115
1139
  const editor = superdocRef.current?.activeEditor;
1116
- if (!editor) {
1140
+ const sd = superdocRef.current;
1141
+ if (!editor || !sd) {
1117
1142
  throw new Error("Editor not ready");
1118
1143
  }
1119
- editor.commands.acceptAllChanges();
1120
- const cleanJson = editor.getJSON();
1144
+ const editorAny = editor;
1145
+ const sdAny = sd;
1146
+ let cleanJson;
1147
+ if (typeof editorAny.commands?.acceptAllChanges === "function") {
1148
+ editorAny.commands.acceptAllChanges();
1149
+ cleanJson = editor.getJSON();
1150
+ } else if (typeof sdAny.commands?.acceptAllChanges === "function") {
1151
+ sdAny.commands.acceptAllChanges();
1152
+ cleanJson = editor.getJSON();
1153
+ } else if (typeof sdAny.acceptAllChanges === "function") {
1154
+ sdAny.acceptAllChanges();
1155
+ cleanJson = editor.getJSON();
1156
+ } else {
1157
+ const currentJson = editor.getJSON();
1158
+ cleanJson = acceptAllChangesInJson(currentJson) || { type: "doc", content: [] };
1159
+ }
1121
1160
  setMergedJson(null);
1122
1161
  setDiffResult(null);
1123
1162
  return cleanJson;