docx-diff-editor 1.0.58 → 1.0.60
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/README.md +13 -0
- package/dist/index.js +105 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +105 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -962,6 +962,92 @@ async function parseHtmlToJson(html, SuperDoc) {
|
|
|
962
962
|
}, 50);
|
|
963
963
|
});
|
|
964
964
|
}
|
|
965
|
+
function syncNumberingToParent(childEditor, parentEditor) {
|
|
966
|
+
try {
|
|
967
|
+
const childNumbering = childEditor?.converter?.numbering;
|
|
968
|
+
const parentNumbering = parentEditor?.converter?.numbering;
|
|
969
|
+
if (!childNumbering || !parentNumbering) {
|
|
970
|
+
return;
|
|
971
|
+
}
|
|
972
|
+
if (childNumbering.definitions) {
|
|
973
|
+
parentNumbering.definitions = {
|
|
974
|
+
...parentNumbering.definitions,
|
|
975
|
+
...childNumbering.definitions
|
|
976
|
+
};
|
|
977
|
+
}
|
|
978
|
+
if (childNumbering.abstracts) {
|
|
979
|
+
parentNumbering.abstracts = {
|
|
980
|
+
...parentNumbering.abstracts,
|
|
981
|
+
...childNumbering.abstracts
|
|
982
|
+
};
|
|
983
|
+
}
|
|
984
|
+
parentEditor.converter.numbering = parentNumbering;
|
|
985
|
+
} catch (err) {
|
|
986
|
+
console.warn("[syncNumberingToParent] Failed to sync numbering definitions:", err);
|
|
987
|
+
}
|
|
988
|
+
}
|
|
989
|
+
async function parseHtmlWithLinkedEditor(html, mainEditor) {
|
|
990
|
+
const container = document.createElement("div");
|
|
991
|
+
container.style.cssText = "position:absolute;top:-9999px;left:-9999px;width:800px;height:600px;visibility:hidden;";
|
|
992
|
+
document.body.appendChild(container);
|
|
993
|
+
return new Promise((resolve, reject) => {
|
|
994
|
+
let resolved = false;
|
|
995
|
+
let childEditor = null;
|
|
996
|
+
const cleanup = () => {
|
|
997
|
+
setTimeout(() => {
|
|
998
|
+
if (childEditor) {
|
|
999
|
+
try {
|
|
1000
|
+
childEditor.destroy?.();
|
|
1001
|
+
} catch {
|
|
1002
|
+
}
|
|
1003
|
+
childEditor = null;
|
|
1004
|
+
}
|
|
1005
|
+
if (container.parentNode) {
|
|
1006
|
+
container.parentNode.removeChild(container);
|
|
1007
|
+
}
|
|
1008
|
+
}, TIMEOUTS.CLEANUP_DELAY);
|
|
1009
|
+
};
|
|
1010
|
+
try {
|
|
1011
|
+
mainEditor.createChildEditor({
|
|
1012
|
+
element: container,
|
|
1013
|
+
html,
|
|
1014
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1015
|
+
onCreate: ({ editor: localEditor }) => {
|
|
1016
|
+
if (resolved) return;
|
|
1017
|
+
try {
|
|
1018
|
+
childEditor = localEditor;
|
|
1019
|
+
syncNumberingToParent(localEditor, mainEditor);
|
|
1020
|
+
const json = localEditor.getJSON();
|
|
1021
|
+
const normalizedJson = normalizeRunProperties(json);
|
|
1022
|
+
resolved = true;
|
|
1023
|
+
cleanup();
|
|
1024
|
+
resolve(normalizedJson);
|
|
1025
|
+
} catch (err) {
|
|
1026
|
+
resolved = true;
|
|
1027
|
+
cleanup();
|
|
1028
|
+
reject(err);
|
|
1029
|
+
}
|
|
1030
|
+
},
|
|
1031
|
+
onError: (error) => {
|
|
1032
|
+
if (resolved) return;
|
|
1033
|
+
resolved = true;
|
|
1034
|
+
cleanup();
|
|
1035
|
+
reject(error);
|
|
1036
|
+
}
|
|
1037
|
+
});
|
|
1038
|
+
setTimeout(() => {
|
|
1039
|
+
if (!resolved) {
|
|
1040
|
+
resolved = true;
|
|
1041
|
+
cleanup();
|
|
1042
|
+
reject(new Error("Linked HTML parsing timed out"));
|
|
1043
|
+
}
|
|
1044
|
+
}, TIMEOUTS.PARSE_TIMEOUT);
|
|
1045
|
+
} catch (err) {
|
|
1046
|
+
cleanup();
|
|
1047
|
+
reject(err);
|
|
1048
|
+
}
|
|
1049
|
+
});
|
|
1050
|
+
}
|
|
965
1051
|
async function parseDocxFile(file, SuperDoc) {
|
|
966
1052
|
const container = document.createElement("div");
|
|
967
1053
|
container.style.cssText = "position:absolute;top:-9999px;left:-9999px;width:800px;height:600px;visibility:hidden;";
|
|
@@ -3664,13 +3750,30 @@ var DocxDiffEditor = forwardRef(
|
|
|
3664
3750
|
}
|
|
3665
3751
|
},
|
|
3666
3752
|
/**
|
|
3667
|
-
* Parse HTML string to ProseMirror JSON
|
|
3668
|
-
*
|
|
3753
|
+
* Parse HTML string to ProseMirror JSON.
|
|
3754
|
+
*
|
|
3755
|
+
* When the main editor is ready, this uses a linked child editor approach
|
|
3756
|
+
* which ensures list numbering definitions are synced to the main document.
|
|
3757
|
+
* This prevents crashes when parsed content with lists is spliced into
|
|
3758
|
+
* the main document via compareWith().
|
|
3759
|
+
*
|
|
3760
|
+
* Falls back to an isolated SuperDoc instance if the main editor isn't ready.
|
|
3669
3761
|
*/
|
|
3670
3762
|
async parseHtml(html) {
|
|
3671
3763
|
if (!SuperDocRef.current) {
|
|
3672
3764
|
throw new Error("Editor not initialized");
|
|
3673
3765
|
}
|
|
3766
|
+
const mainEditor = superdocRef.current?.activeEditor;
|
|
3767
|
+
if (mainEditor?.createChildEditor) {
|
|
3768
|
+
try {
|
|
3769
|
+
return await parseHtmlWithLinkedEditor(html, mainEditor);
|
|
3770
|
+
} catch (err) {
|
|
3771
|
+
console.warn(
|
|
3772
|
+
"[DocxDiffEditor] Linked HTML parsing failed, falling back to isolated approach:",
|
|
3773
|
+
err
|
|
3774
|
+
);
|
|
3775
|
+
}
|
|
3776
|
+
}
|
|
3674
3777
|
return parseHtmlToJson(html, SuperDocRef.current);
|
|
3675
3778
|
}
|
|
3676
3779
|
}),
|