docx-diff-editor 1.0.53 → 1.0.54
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 +26 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +26 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -2874,14 +2874,38 @@ var DocxDiffEditor = forwardRef(
|
|
|
2874
2874
|
const instanceId = useRef(`dde-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`);
|
|
2875
2875
|
const editorId = `dde-editor-${instanceId.current}`;
|
|
2876
2876
|
const toolbarId = `dde-toolbar-${instanceId.current}`;
|
|
2877
|
+
const sanitizeJson = useCallback((node) => {
|
|
2878
|
+
if (node.type === "text") {
|
|
2879
|
+
if (!node.text || node.text === "") {
|
|
2880
|
+
return null;
|
|
2881
|
+
}
|
|
2882
|
+
return node;
|
|
2883
|
+
}
|
|
2884
|
+
if (node.content && Array.isArray(node.content)) {
|
|
2885
|
+
const cleanedContent = node.content.map((child) => sanitizeJson(child)).filter((child) => child !== null);
|
|
2886
|
+
if (node.type === "run" && cleanedContent.length === 0) {
|
|
2887
|
+
return null;
|
|
2888
|
+
}
|
|
2889
|
+
return {
|
|
2890
|
+
...node,
|
|
2891
|
+
content: cleanedContent.length > 0 ? cleanedContent : void 0
|
|
2892
|
+
};
|
|
2893
|
+
}
|
|
2894
|
+
return node;
|
|
2895
|
+
}, []);
|
|
2877
2896
|
const setEditorContent = useCallback((editor, json) => {
|
|
2878
2897
|
const { state, view } = editor;
|
|
2879
2898
|
if (state?.doc && view && json.content) {
|
|
2880
|
-
const
|
|
2899
|
+
const sanitized = sanitizeJson(json);
|
|
2900
|
+
if (!sanitized || !sanitized.content) {
|
|
2901
|
+
console.warn("[DocxDiffEditor] Sanitized JSON has no content");
|
|
2902
|
+
return;
|
|
2903
|
+
}
|
|
2904
|
+
const newDoc = state.schema.nodeFromJSON(sanitized);
|
|
2881
2905
|
const tr = state.tr.replaceWith(0, state.doc.content.size, newDoc.content);
|
|
2882
2906
|
view.dispatch(tr);
|
|
2883
2907
|
}
|
|
2884
|
-
}, []);
|
|
2908
|
+
}, [sanitizeJson]);
|
|
2885
2909
|
const enableReviewMode = useCallback((sd) => {
|
|
2886
2910
|
if (sd.setTrackedChangesPreferences) {
|
|
2887
2911
|
sd.setTrackedChangesPreferences({ mode: "review", enabled: true });
|