docx-diff-editor 1.0.60 → 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 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;
@@ -994,6 +983,16 @@ function syncNumberingToParent(childEditor, parentEditor) {
994
983
  console.warn("[syncNumberingToParent] Failed to sync numbering definitions:", err);
995
984
  }
996
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
+ }
997
996
  async function parseHtmlWithLinkedEditor(html, mainEditor) {
998
997
  const container = document.createElement("div");
999
998
  container.style.cssText = "position:absolute;top:-9999px;left:-9999px;width:800px;height:600px;visibility:hidden;";
@@ -1015,17 +1014,26 @@ async function parseHtmlWithLinkedEditor(html, mainEditor) {
1015
1014
  }
1016
1015
  }, TIMEOUTS.CLEANUP_DELAY);
1017
1016
  };
1018
- try {
1019
- mainEditor.createChildEditor({
1020
- element: container,
1021
- html,
1022
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1023
- onCreate: ({ editor: localEditor }) => {
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(() => {
1024
1030
  if (resolved) return;
1025
1031
  try {
1026
- childEditor = localEditor;
1027
- syncNumberingToParent(localEditor, mainEditor);
1028
- const json = localEditor.getJSON();
1032
+ syncNumberingToParent(editor, mainEditor);
1033
+ const json = editor.getJSON();
1034
+ if (!json?.content?.length) {
1035
+ throw new Error("Paste produced empty document");
1036
+ }
1029
1037
  const normalizedJson = normalizeRunProperties(json);
1030
1038
  resolved = true;
1031
1039
  cleanup();
@@ -1035,6 +1043,23 @@ async function parseHtmlWithLinkedEditor(html, mainEditor) {
1035
1043
  cleanup();
1036
1044
  reject(err);
1037
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);
1038
1063
  },
1039
1064
  onError: (error) => {
1040
1065
  if (resolved) return;