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 +42 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +42 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
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,
|
|
@@ -1105,11 +1129,26 @@ var DocxDiffEditor = forwardRef(
|
|
|
1105
1129
|
*/
|
|
1106
1130
|
async acceptAllChanges() {
|
|
1107
1131
|
const editor = superdocRef.current?.activeEditor;
|
|
1108
|
-
|
|
1132
|
+
const sd = superdocRef.current;
|
|
1133
|
+
if (!editor || !sd) {
|
|
1109
1134
|
throw new Error("Editor not ready");
|
|
1110
1135
|
}
|
|
1111
|
-
editor
|
|
1112
|
-
const
|
|
1136
|
+
const editorAny = editor;
|
|
1137
|
+
const sdAny = sd;
|
|
1138
|
+
let cleanJson;
|
|
1139
|
+
if (typeof editorAny.commands?.acceptAllChanges === "function") {
|
|
1140
|
+
editorAny.commands.acceptAllChanges();
|
|
1141
|
+
cleanJson = editor.getJSON();
|
|
1142
|
+
} else if (typeof sdAny.commands?.acceptAllChanges === "function") {
|
|
1143
|
+
sdAny.commands.acceptAllChanges();
|
|
1144
|
+
cleanJson = editor.getJSON();
|
|
1145
|
+
} else if (typeof sdAny.acceptAllChanges === "function") {
|
|
1146
|
+
sdAny.acceptAllChanges();
|
|
1147
|
+
cleanJson = editor.getJSON();
|
|
1148
|
+
} else {
|
|
1149
|
+
const currentJson = editor.getJSON();
|
|
1150
|
+
cleanJson = acceptAllChangesInJson(currentJson) || { type: "doc", content: [] };
|
|
1151
|
+
}
|
|
1113
1152
|
setMergedJson(null);
|
|
1114
1153
|
setDiffResult(null);
|
|
1115
1154
|
return cleanJson;
|