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