docx-diff-editor 1.0.10 → 1.0.14

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
@@ -733,10 +733,9 @@ var DocxDiffEditor = react.forwardRef(
733
733
  hiddenContainer.style.cssText = "position:absolute;top:-9999px;left:-9999px;width:800px;height:600px;visibility:hidden;pointer-events:none;";
734
734
  document.body.appendChild(hiddenContainer);
735
735
  return new Promise((resolve, reject) => {
736
+ let resolved = false;
736
737
  let tempSuperdoc = null;
737
- let timeoutId;
738
738
  const cleanup = () => {
739
- clearTimeout(timeoutId);
740
739
  try {
741
740
  tempSuperdoc?.destroy?.();
742
741
  } catch {
@@ -750,40 +749,43 @@ var DocxDiffEditor = react.forwardRef(
750
749
  documentMode: "editing",
751
750
  rulers: false,
752
751
  user: { name: "Converter", email: "converter@local" },
753
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
754
752
  onReady: async ({ superdoc: sd }) => {
753
+ if (resolved) return;
755
754
  try {
756
755
  const json = sd?.activeEditor?.getJSON() || { type: "doc", content: [] };
757
- if (!sd?.activeEditor?.exportDocx) {
758
- cleanup();
759
- reject(new Error("exportDocx method not available"));
760
- return;
761
- }
762
- const blob = await sd.activeEditor.exportDocx({ isFinalDoc: false });
756
+ const blob = await sd?.activeEditor?.exportDocx({ isFinalDoc: true });
763
757
  if (!blob) {
764
- cleanup();
765
- reject(new Error("Export returned no data"));
766
- return;
758
+ throw new Error("Export returned no data");
767
759
  }
760
+ resolved = true;
768
761
  cleanup();
769
762
  resolve({ blob, json });
770
763
  } catch (err) {
764
+ resolved = true;
771
765
  cleanup();
772
766
  reject(err);
773
767
  }
774
768
  },
775
769
  onException: ({ error: err }) => {
770
+ if (resolved) return;
771
+ resolved = true;
776
772
  cleanup();
777
773
  reject(err);
778
774
  }
779
775
  });
780
- timeoutId = setTimeout(() => {
781
- cleanup();
782
- reject(new Error("HTML to DOCX conversion timed out"));
776
+ setTimeout(() => {
777
+ if (!resolved) {
778
+ resolved = true;
779
+ cleanup();
780
+ reject(new Error("HTML to DOCX conversion timed out"));
781
+ }
783
782
  }, TIMEOUTS.PARSE_TIMEOUT);
784
783
  } catch (err) {
785
- cleanup();
786
- reject(err);
784
+ if (!resolved) {
785
+ resolved = true;
786
+ cleanup();
787
+ reject(err);
788
+ }
787
789
  }
788
790
  });
789
791
  },
@@ -806,31 +808,18 @@ var DocxDiffEditor = react.forwardRef(
806
808
  if (toolbarRef.current) {
807
809
  toolbarRef.current.id = toolbarId;
808
810
  }
809
- let documentFile;
810
- if (options.document) {
811
- if (options.document instanceof File) {
812
- documentFile = options.document;
813
- } else {
814
- documentFile = new File([options.document], "document.docx", {
815
- type: "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
816
- });
817
- }
818
- }
819
811
  return new Promise((resolve, reject) => {
820
812
  let resolved = false;
821
813
  try {
822
814
  const superdoc = new SuperDocRef.current({
823
815
  selector: `#${editorId}`,
824
816
  toolbar: showToolbar ? `#${toolbarId}` : void 0,
825
- document: documentFile,
826
- html: options.html,
817
+ document: options.document,
827
818
  documentMode: "editing",
828
819
  role: "editor",
829
820
  rulers: showRulers,
830
821
  user: DEFAULT_SUPERDOC_USER,
831
822
  permissionResolver,
832
- // Enable comments module for track changes sidebar
833
- modules: { comments: {} },
834
823
  onReady: ({ superdoc: sd }) => {
835
824
  if (resolved) return;
836
825
  resolved = true;
@@ -911,9 +900,9 @@ var DocxDiffEditor = react.forwardRef(
911
900
  onSourceLoaded?.(initialSource);
912
901
  }
913
902
  } else {
914
- const finalJson = extractedJson || json;
915
- setSourceJson(finalJson);
916
- onSourceLoaded?.(finalJson);
903
+ const sourceJsonToUse = extractedJson || json;
904
+ setSourceJson(sourceJsonToUse);
905
+ onSourceLoaded?.(sourceJsonToUse);
917
906
  }
918
907
  setIsLoading(false);
919
908
  onReady?.();
@@ -950,9 +939,8 @@ var DocxDiffEditor = react.forwardRef(
950
939
  /**
951
940
  * Set the source/base document.
952
941
  *
953
- * For HTML content, we convert to DOCX first using a hidden SuperDoc instance.
954
- * This is critical because SuperDoc's track change infrastructure (including
955
- * track bubbles) is only properly initialized when loading from a DOCX file.
942
+ * IMPORTANT: For HTML content, we convert to DOCX first using a hidden
943
+ * SuperDoc instance. This is required for track bubbles to work properly.
956
944
  */
957
945
  async setSource(content) {
958
946
  if (!SuperDocRef.current) {
@@ -968,15 +956,9 @@ var DocxDiffEditor = react.forwardRef(
968
956
  const result = await createSuperdoc({ document: content });
969
957
  json = result.json;
970
958
  } else if (contentType === "html") {
971
- const { blob, json: extractedJson } = await convertHtmlToDocxBlob(content);
959
+ const { blob, json: htmlJson } = await convertHtmlToDocxBlob(content);
972
960
  const result = await createSuperdoc({ document: blob });
973
- json = extractedJson;
974
- if (result.superdoc?.activeEditor) {
975
- const editorJson = result.superdoc.activeEditor.getJSON();
976
- if (!extractedJson.content || extractedJson.content.length === 0) {
977
- json = editorJson;
978
- }
979
- }
961
+ json = htmlJson;
980
962
  } else {
981
963
  const result = await createSuperdoc(templateDocx ? { document: templateDocx } : {});
982
964
  if (result.superdoc?.activeEditor && isProseMirrorJSON(content)) {
@@ -1073,6 +1055,22 @@ var DocxDiffEditor = react.forwardRef(
1073
1055
  if (superdocRef.current?.activeEditor) {
1074
1056
  setEditorContent(superdocRef.current.activeEditor, merged);
1075
1057
  enableReviewMode(superdocRef.current);
1058
+ const sd = superdocRef.current;
1059
+ if (sd.commentsStore?.processLoadedDocxComments) {
1060
+ setTimeout(() => {
1061
+ try {
1062
+ sd.commentsStore.processLoadedDocxComments({
1063
+ superdoc: sd,
1064
+ editor: sd.activeEditor,
1065
+ comments: [],
1066
+ // Empty array - we just want to trigger createCommentForTrackChanges
1067
+ documentId: sd.activeEditor?.options?.documentId || "primary"
1068
+ });
1069
+ } catch (err) {
1070
+ console.warn("[DocxDiffEditor] Failed to process track changes for bubbles:", err);
1071
+ }
1072
+ }, 50);
1073
+ }
1076
1074
  }
1077
1075
  const insertions = diff.segments.filter((s) => s.type === "insert").length;
1078
1076
  const deletions = diff.segments.filter((s) => s.type === "delete").length;