docx-diff-editor 1.0.10 → 1.0.15

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.mjs CHANGED
@@ -715,72 +715,6 @@ var DocxDiffEditor = forwardRef(
715
715
  }
716
716
  readyRef.current = false;
717
717
  }, []);
718
- const convertHtmlToDocxBlob = useCallback(
719
- async (html) => {
720
- if (!SuperDocRef.current) {
721
- throw new Error("SuperDoc not loaded");
722
- }
723
- const hiddenContainer = document.createElement("div");
724
- hiddenContainer.id = `dde-hidden-${Date.now()}`;
725
- hiddenContainer.style.cssText = "position:absolute;top:-9999px;left:-9999px;width:800px;height:600px;visibility:hidden;pointer-events:none;";
726
- document.body.appendChild(hiddenContainer);
727
- return new Promise((resolve, reject) => {
728
- let tempSuperdoc = null;
729
- let timeoutId;
730
- const cleanup = () => {
731
- clearTimeout(timeoutId);
732
- try {
733
- tempSuperdoc?.destroy?.();
734
- } catch {
735
- }
736
- hiddenContainer.parentNode?.removeChild(hiddenContainer);
737
- };
738
- try {
739
- tempSuperdoc = new SuperDocRef.current({
740
- selector: `#${hiddenContainer.id}`,
741
- html,
742
- documentMode: "editing",
743
- rulers: false,
744
- user: { name: "Converter", email: "converter@local" },
745
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
746
- onReady: async ({ superdoc: sd }) => {
747
- try {
748
- const json = sd?.activeEditor?.getJSON() || { type: "doc", content: [] };
749
- if (!sd?.activeEditor?.exportDocx) {
750
- cleanup();
751
- reject(new Error("exportDocx method not available"));
752
- return;
753
- }
754
- const blob = await sd.activeEditor.exportDocx({ isFinalDoc: false });
755
- if (!blob) {
756
- cleanup();
757
- reject(new Error("Export returned no data"));
758
- return;
759
- }
760
- cleanup();
761
- resolve({ blob, json });
762
- } catch (err) {
763
- cleanup();
764
- reject(err);
765
- }
766
- },
767
- onException: ({ error: err }) => {
768
- cleanup();
769
- reject(err);
770
- }
771
- });
772
- timeoutId = setTimeout(() => {
773
- cleanup();
774
- reject(new Error("HTML to DOCX conversion timed out"));
775
- }, TIMEOUTS.PARSE_TIMEOUT);
776
- } catch (err) {
777
- cleanup();
778
- reject(err);
779
- }
780
- });
781
- },
782
- []
783
- );
784
718
  const createSuperdoc = useCallback(
785
719
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
786
720
  async (options) => {
@@ -798,31 +732,25 @@ var DocxDiffEditor = forwardRef(
798
732
  if (toolbarRef.current) {
799
733
  toolbarRef.current.id = toolbarId;
800
734
  }
801
- let documentFile;
802
- if (options.document) {
803
- if (options.document instanceof File) {
804
- documentFile = options.document;
805
- } else {
806
- documentFile = new File([options.document], "document.docx", {
807
- type: "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
808
- });
809
- }
810
- }
811
735
  return new Promise((resolve, reject) => {
812
736
  let resolved = false;
813
737
  try {
814
- const superdoc = new SuperDocRef.current({
738
+ const superdocConfig = {
815
739
  selector: `#${editorId}`,
816
740
  toolbar: showToolbar ? `#${toolbarId}` : void 0,
817
- document: documentFile,
818
- html: options.html,
819
741
  documentMode: "editing",
820
742
  role: "editor",
821
743
  rulers: showRulers,
822
744
  user: DEFAULT_SUPERDOC_USER,
823
- permissionResolver,
824
- // Enable comments module for track changes sidebar
825
- modules: { comments: {} },
745
+ permissionResolver
746
+ };
747
+ if (options.document) {
748
+ superdocConfig.document = options.document;
749
+ } else if (options.html) {
750
+ superdocConfig.html = options.html;
751
+ }
752
+ const superdoc = new SuperDocRef.current({
753
+ ...superdocConfig,
826
754
  onReady: ({ superdoc: sd }) => {
827
755
  if (resolved) return;
828
756
  resolved = true;
@@ -880,15 +808,12 @@ var DocxDiffEditor = forwardRef(
880
808
  const { SuperDoc } = await import('superdoc');
881
809
  SuperDocRef.current = SuperDoc;
882
810
  let initOptions = {};
883
- let extractedJson = null;
884
811
  if (initialSource) {
885
812
  const contentType = detectContentType(initialSource);
886
813
  if (contentType === "file") {
887
814
  initOptions = { document: initialSource };
888
815
  } else if (contentType === "html") {
889
- const { blob, json: htmlJson } = await convertHtmlToDocxBlob(initialSource);
890
- initOptions = { document: blob };
891
- extractedJson = htmlJson;
816
+ initOptions = { html: initialSource };
892
817
  } else if (contentType === "json") {
893
818
  initOptions = templateDocx ? { document: templateDocx } : {};
894
819
  }
@@ -903,9 +828,8 @@ var DocxDiffEditor = forwardRef(
903
828
  onSourceLoaded?.(initialSource);
904
829
  }
905
830
  } else {
906
- const finalJson = extractedJson || json;
907
- setSourceJson(finalJson);
908
- onSourceLoaded?.(finalJson);
831
+ setSourceJson(json);
832
+ onSourceLoaded?.(json);
909
833
  }
910
834
  setIsLoading(false);
911
835
  onReady?.();
@@ -924,7 +848,6 @@ var DocxDiffEditor = forwardRef(
924
848
  onSourceLoaded,
925
849
  destroySuperdoc,
926
850
  createSuperdoc,
927
- convertHtmlToDocxBlob,
928
851
  setEditorContent,
929
852
  handleError
930
853
  ]);
@@ -941,10 +864,7 @@ var DocxDiffEditor = forwardRef(
941
864
  () => ({
942
865
  /**
943
866
  * Set the source/base document.
944
- *
945
- * For HTML content, we convert to DOCX first using a hidden SuperDoc instance.
946
- * This is critical because SuperDoc's track change infrastructure (including
947
- * track bubbles) is only properly initialized when loading from a DOCX file.
867
+ * Accepts File (DOCX), HTML string, or ProseMirror JSON.
948
868
  */
949
869
  async setSource(content) {
950
870
  if (!SuperDocRef.current) {
@@ -960,15 +880,8 @@ var DocxDiffEditor = forwardRef(
960
880
  const result = await createSuperdoc({ document: content });
961
881
  json = result.json;
962
882
  } else if (contentType === "html") {
963
- const { blob, json: extractedJson } = await convertHtmlToDocxBlob(content);
964
- const result = await createSuperdoc({ document: blob });
965
- json = extractedJson;
966
- if (result.superdoc?.activeEditor) {
967
- const editorJson = result.superdoc.activeEditor.getJSON();
968
- if (!extractedJson.content || extractedJson.content.length === 0) {
969
- json = editorJson;
970
- }
971
- }
883
+ const result = await createSuperdoc({ html: content });
884
+ json = result.json;
972
885
  } else {
973
886
  const result = await createSuperdoc(templateDocx ? { document: templateDocx } : {});
974
887
  if (result.superdoc?.activeEditor && isProseMirrorJSON(content)) {
@@ -1065,6 +978,22 @@ var DocxDiffEditor = forwardRef(
1065
978
  if (superdocRef.current?.activeEditor) {
1066
979
  setEditorContent(superdocRef.current.activeEditor, merged);
1067
980
  enableReviewMode(superdocRef.current);
981
+ const sd = superdocRef.current;
982
+ if (sd.commentsStore?.processLoadedDocxComments) {
983
+ setTimeout(() => {
984
+ try {
985
+ sd.commentsStore.processLoadedDocxComments({
986
+ superdoc: sd,
987
+ editor: sd.activeEditor,
988
+ comments: [],
989
+ // Empty array - we just want to trigger createCommentForTrackChanges
990
+ documentId: sd.activeEditor?.options?.documentId || "primary"
991
+ });
992
+ } catch (err) {
993
+ console.warn("[DocxDiffEditor] Failed to process track changes for bubbles:", err);
994
+ }
995
+ }, 50);
996
+ }
1068
997
  }
1069
998
  const insertions = diff.segments.filter((s) => s.type === "insert").length;
1070
999
  const deletions = diff.segments.filter((s) => s.type === "delete").length;
@@ -1155,7 +1084,6 @@ var DocxDiffEditor = forwardRef(
1155
1084
  author,
1156
1085
  destroySuperdoc,
1157
1086
  createSuperdoc,
1158
- convertHtmlToDocxBlob,
1159
1087
  setEditorContent,
1160
1088
  enableReviewMode,
1161
1089
  setEditingMode,