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 +43 -45
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +43 -45
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -725,10 +725,9 @@ var DocxDiffEditor = forwardRef(
|
|
|
725
725
|
hiddenContainer.style.cssText = "position:absolute;top:-9999px;left:-9999px;width:800px;height:600px;visibility:hidden;pointer-events:none;";
|
|
726
726
|
document.body.appendChild(hiddenContainer);
|
|
727
727
|
return new Promise((resolve, reject) => {
|
|
728
|
+
let resolved = false;
|
|
728
729
|
let tempSuperdoc = null;
|
|
729
|
-
let timeoutId;
|
|
730
730
|
const cleanup = () => {
|
|
731
|
-
clearTimeout(timeoutId);
|
|
732
731
|
try {
|
|
733
732
|
tempSuperdoc?.destroy?.();
|
|
734
733
|
} catch {
|
|
@@ -742,40 +741,43 @@ var DocxDiffEditor = forwardRef(
|
|
|
742
741
|
documentMode: "editing",
|
|
743
742
|
rulers: false,
|
|
744
743
|
user: { name: "Converter", email: "converter@local" },
|
|
745
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
746
744
|
onReady: async ({ superdoc: sd }) => {
|
|
745
|
+
if (resolved) return;
|
|
747
746
|
try {
|
|
748
747
|
const json = sd?.activeEditor?.getJSON() || { type: "doc", content: [] };
|
|
749
|
-
|
|
750
|
-
cleanup();
|
|
751
|
-
reject(new Error("exportDocx method not available"));
|
|
752
|
-
return;
|
|
753
|
-
}
|
|
754
|
-
const blob = await sd.activeEditor.exportDocx({ isFinalDoc: false });
|
|
748
|
+
const blob = await sd?.activeEditor?.exportDocx({ isFinalDoc: true });
|
|
755
749
|
if (!blob) {
|
|
756
|
-
|
|
757
|
-
reject(new Error("Export returned no data"));
|
|
758
|
-
return;
|
|
750
|
+
throw new Error("Export returned no data");
|
|
759
751
|
}
|
|
752
|
+
resolved = true;
|
|
760
753
|
cleanup();
|
|
761
754
|
resolve({ blob, json });
|
|
762
755
|
} catch (err) {
|
|
756
|
+
resolved = true;
|
|
763
757
|
cleanup();
|
|
764
758
|
reject(err);
|
|
765
759
|
}
|
|
766
760
|
},
|
|
767
761
|
onException: ({ error: err }) => {
|
|
762
|
+
if (resolved) return;
|
|
763
|
+
resolved = true;
|
|
768
764
|
cleanup();
|
|
769
765
|
reject(err);
|
|
770
766
|
}
|
|
771
767
|
});
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
768
|
+
setTimeout(() => {
|
|
769
|
+
if (!resolved) {
|
|
770
|
+
resolved = true;
|
|
771
|
+
cleanup();
|
|
772
|
+
reject(new Error("HTML to DOCX conversion timed out"));
|
|
773
|
+
}
|
|
775
774
|
}, TIMEOUTS.PARSE_TIMEOUT);
|
|
776
775
|
} catch (err) {
|
|
777
|
-
|
|
778
|
-
|
|
776
|
+
if (!resolved) {
|
|
777
|
+
resolved = true;
|
|
778
|
+
cleanup();
|
|
779
|
+
reject(err);
|
|
780
|
+
}
|
|
779
781
|
}
|
|
780
782
|
});
|
|
781
783
|
},
|
|
@@ -798,31 +800,18 @@ var DocxDiffEditor = forwardRef(
|
|
|
798
800
|
if (toolbarRef.current) {
|
|
799
801
|
toolbarRef.current.id = toolbarId;
|
|
800
802
|
}
|
|
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
803
|
return new Promise((resolve, reject) => {
|
|
812
804
|
let resolved = false;
|
|
813
805
|
try {
|
|
814
806
|
const superdoc = new SuperDocRef.current({
|
|
815
807
|
selector: `#${editorId}`,
|
|
816
808
|
toolbar: showToolbar ? `#${toolbarId}` : void 0,
|
|
817
|
-
document:
|
|
818
|
-
html: options.html,
|
|
809
|
+
document: options.document,
|
|
819
810
|
documentMode: "editing",
|
|
820
811
|
role: "editor",
|
|
821
812
|
rulers: showRulers,
|
|
822
813
|
user: DEFAULT_SUPERDOC_USER,
|
|
823
814
|
permissionResolver,
|
|
824
|
-
// Enable comments module for track changes sidebar
|
|
825
|
-
modules: { comments: {} },
|
|
826
815
|
onReady: ({ superdoc: sd }) => {
|
|
827
816
|
if (resolved) return;
|
|
828
817
|
resolved = true;
|
|
@@ -903,9 +892,9 @@ var DocxDiffEditor = forwardRef(
|
|
|
903
892
|
onSourceLoaded?.(initialSource);
|
|
904
893
|
}
|
|
905
894
|
} else {
|
|
906
|
-
const
|
|
907
|
-
setSourceJson(
|
|
908
|
-
onSourceLoaded?.(
|
|
895
|
+
const sourceJsonToUse = extractedJson || json;
|
|
896
|
+
setSourceJson(sourceJsonToUse);
|
|
897
|
+
onSourceLoaded?.(sourceJsonToUse);
|
|
909
898
|
}
|
|
910
899
|
setIsLoading(false);
|
|
911
900
|
onReady?.();
|
|
@@ -942,9 +931,8 @@ var DocxDiffEditor = forwardRef(
|
|
|
942
931
|
/**
|
|
943
932
|
* Set the source/base document.
|
|
944
933
|
*
|
|
945
|
-
* For HTML content, we convert to DOCX first using a hidden
|
|
946
|
-
* This is
|
|
947
|
-
* track bubbles) is only properly initialized when loading from a DOCX file.
|
|
934
|
+
* IMPORTANT: For HTML content, we convert to DOCX first using a hidden
|
|
935
|
+
* SuperDoc instance. This is required for track bubbles to work properly.
|
|
948
936
|
*/
|
|
949
937
|
async setSource(content) {
|
|
950
938
|
if (!SuperDocRef.current) {
|
|
@@ -960,15 +948,9 @@ var DocxDiffEditor = forwardRef(
|
|
|
960
948
|
const result = await createSuperdoc({ document: content });
|
|
961
949
|
json = result.json;
|
|
962
950
|
} else if (contentType === "html") {
|
|
963
|
-
const { blob, json:
|
|
951
|
+
const { blob, json: htmlJson } = await convertHtmlToDocxBlob(content);
|
|
964
952
|
const result = await createSuperdoc({ document: blob });
|
|
965
|
-
json =
|
|
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
|
-
}
|
|
953
|
+
json = htmlJson;
|
|
972
954
|
} else {
|
|
973
955
|
const result = await createSuperdoc(templateDocx ? { document: templateDocx } : {});
|
|
974
956
|
if (result.superdoc?.activeEditor && isProseMirrorJSON(content)) {
|
|
@@ -1065,6 +1047,22 @@ var DocxDiffEditor = forwardRef(
|
|
|
1065
1047
|
if (superdocRef.current?.activeEditor) {
|
|
1066
1048
|
setEditorContent(superdocRef.current.activeEditor, merged);
|
|
1067
1049
|
enableReviewMode(superdocRef.current);
|
|
1050
|
+
const sd = superdocRef.current;
|
|
1051
|
+
if (sd.commentsStore?.processLoadedDocxComments) {
|
|
1052
|
+
setTimeout(() => {
|
|
1053
|
+
try {
|
|
1054
|
+
sd.commentsStore.processLoadedDocxComments({
|
|
1055
|
+
superdoc: sd,
|
|
1056
|
+
editor: sd.activeEditor,
|
|
1057
|
+
comments: [],
|
|
1058
|
+
// Empty array - we just want to trigger createCommentForTrackChanges
|
|
1059
|
+
documentId: sd.activeEditor?.options?.documentId || "primary"
|
|
1060
|
+
});
|
|
1061
|
+
} catch (err) {
|
|
1062
|
+
console.warn("[DocxDiffEditor] Failed to process track changes for bubbles:", err);
|
|
1063
|
+
}
|
|
1064
|
+
}, 50);
|
|
1065
|
+
}
|
|
1068
1066
|
}
|
|
1069
1067
|
const insertions = diff.segments.filter((s) => s.type === "insert").length;
|
|
1070
1068
|
const deletions = diff.segments.filter((s) => s.type === "delete").length;
|