docx-diff-editor 1.0.59 → 1.0.61
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 +69 -19
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +69 -19
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -830,17 +830,6 @@ async function parseHtmlToJson(html, SuperDoc) {
|
|
|
830
830
|
}
|
|
831
831
|
}, TIMEOUTS.CLEANUP_DELAY);
|
|
832
832
|
};
|
|
833
|
-
const createMockPasteEvent = (htmlContent) => {
|
|
834
|
-
const dataTransfer = new DataTransfer();
|
|
835
|
-
dataTransfer.setData("text/html", htmlContent);
|
|
836
|
-
dataTransfer.setData("text/plain", "");
|
|
837
|
-
const event = new ClipboardEvent("paste", {
|
|
838
|
-
bubbles: true,
|
|
839
|
-
cancelable: true,
|
|
840
|
-
clipboardData: dataTransfer
|
|
841
|
-
});
|
|
842
|
-
return event;
|
|
843
|
-
};
|
|
844
833
|
const tryPasteApproach = (sd, onSuccess, onFail) => {
|
|
845
834
|
try {
|
|
846
835
|
const editor = sd?.activeEditor;
|
|
@@ -970,6 +959,40 @@ async function parseHtmlToJson(html, SuperDoc) {
|
|
|
970
959
|
}, 50);
|
|
971
960
|
});
|
|
972
961
|
}
|
|
962
|
+
function syncNumberingToParent(childEditor, parentEditor) {
|
|
963
|
+
try {
|
|
964
|
+
const childNumbering = childEditor?.converter?.numbering;
|
|
965
|
+
const parentNumbering = parentEditor?.converter?.numbering;
|
|
966
|
+
if (!childNumbering || !parentNumbering) {
|
|
967
|
+
return;
|
|
968
|
+
}
|
|
969
|
+
if (childNumbering.definitions) {
|
|
970
|
+
parentNumbering.definitions = {
|
|
971
|
+
...parentNumbering.definitions,
|
|
972
|
+
...childNumbering.definitions
|
|
973
|
+
};
|
|
974
|
+
}
|
|
975
|
+
if (childNumbering.abstracts) {
|
|
976
|
+
parentNumbering.abstracts = {
|
|
977
|
+
...parentNumbering.abstracts,
|
|
978
|
+
...childNumbering.abstracts
|
|
979
|
+
};
|
|
980
|
+
}
|
|
981
|
+
parentEditor.converter.numbering = parentNumbering;
|
|
982
|
+
} catch (err) {
|
|
983
|
+
console.warn("[syncNumberingToParent] Failed to sync numbering definitions:", err);
|
|
984
|
+
}
|
|
985
|
+
}
|
|
986
|
+
function createMockPasteEvent(htmlContent) {
|
|
987
|
+
const dataTransfer = new DataTransfer();
|
|
988
|
+
dataTransfer.setData("text/html", htmlContent);
|
|
989
|
+
dataTransfer.setData("text/plain", "");
|
|
990
|
+
return new ClipboardEvent("paste", {
|
|
991
|
+
bubbles: true,
|
|
992
|
+
cancelable: true,
|
|
993
|
+
clipboardData: dataTransfer
|
|
994
|
+
});
|
|
995
|
+
}
|
|
973
996
|
async function parseHtmlWithLinkedEditor(html, mainEditor) {
|
|
974
997
|
const container = document.createElement("div");
|
|
975
998
|
container.style.cssText = "position:absolute;top:-9999px;left:-9999px;width:800px;height:600px;visibility:hidden;";
|
|
@@ -991,16 +1014,26 @@ async function parseHtmlWithLinkedEditor(html, mainEditor) {
|
|
|
991
1014
|
}
|
|
992
1015
|
}, TIMEOUTS.CLEANUP_DELAY);
|
|
993
1016
|
};
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1017
|
+
const pasteAndExtract = (editor) => {
|
|
1018
|
+
try {
|
|
1019
|
+
if (!editor?.view?.pasteHTML) {
|
|
1020
|
+
throw new Error("pasteHTML not available on child editor");
|
|
1021
|
+
}
|
|
1022
|
+
editor.commands?.focus?.();
|
|
1023
|
+
if (editor.commands?.selectAll && editor.commands?.deleteSelection) {
|
|
1024
|
+
editor.commands.selectAll();
|
|
1025
|
+
editor.commands.deleteSelection();
|
|
1026
|
+
}
|
|
1027
|
+
const mockEvent = createMockPasteEvent(html);
|
|
1028
|
+
editor.view.pasteHTML(html, mockEvent);
|
|
1029
|
+
setTimeout(() => {
|
|
1000
1030
|
if (resolved) return;
|
|
1001
1031
|
try {
|
|
1002
|
-
|
|
1003
|
-
const json =
|
|
1032
|
+
syncNumberingToParent(editor, mainEditor);
|
|
1033
|
+
const json = editor.getJSON();
|
|
1034
|
+
if (!json?.content?.length) {
|
|
1035
|
+
throw new Error("Paste produced empty document");
|
|
1036
|
+
}
|
|
1004
1037
|
const normalizedJson = normalizeRunProperties(json);
|
|
1005
1038
|
resolved = true;
|
|
1006
1039
|
cleanup();
|
|
@@ -1010,6 +1043,23 @@ async function parseHtmlWithLinkedEditor(html, mainEditor) {
|
|
|
1010
1043
|
cleanup();
|
|
1011
1044
|
reject(err);
|
|
1012
1045
|
}
|
|
1046
|
+
}, 100);
|
|
1047
|
+
} catch (err) {
|
|
1048
|
+
resolved = true;
|
|
1049
|
+
cleanup();
|
|
1050
|
+
reject(err);
|
|
1051
|
+
}
|
|
1052
|
+
};
|
|
1053
|
+
try {
|
|
1054
|
+
mainEditor.createChildEditor({
|
|
1055
|
+
element: container,
|
|
1056
|
+
html: "<p></p>",
|
|
1057
|
+
// Minimal empty document - actual HTML pasted via pasteHTML
|
|
1058
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1059
|
+
onCreate: ({ editor: localEditor }) => {
|
|
1060
|
+
if (resolved) return;
|
|
1061
|
+
childEditor = localEditor;
|
|
1062
|
+
pasteAndExtract(localEditor);
|
|
1013
1063
|
},
|
|
1014
1064
|
onError: (error) => {
|
|
1015
1065
|
if (resolved) return;
|