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.js +32 -104
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +32 -104
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -723,72 +723,6 @@ var DocxDiffEditor = react.forwardRef(
|
|
|
723
723
|
}
|
|
724
724
|
readyRef.current = false;
|
|
725
725
|
}, []);
|
|
726
|
-
const convertHtmlToDocxBlob = react.useCallback(
|
|
727
|
-
async (html) => {
|
|
728
|
-
if (!SuperDocRef.current) {
|
|
729
|
-
throw new Error("SuperDoc not loaded");
|
|
730
|
-
}
|
|
731
|
-
const hiddenContainer = document.createElement("div");
|
|
732
|
-
hiddenContainer.id = `dde-hidden-${Date.now()}`;
|
|
733
|
-
hiddenContainer.style.cssText = "position:absolute;top:-9999px;left:-9999px;width:800px;height:600px;visibility:hidden;pointer-events:none;";
|
|
734
|
-
document.body.appendChild(hiddenContainer);
|
|
735
|
-
return new Promise((resolve, reject) => {
|
|
736
|
-
let tempSuperdoc = null;
|
|
737
|
-
let timeoutId;
|
|
738
|
-
const cleanup = () => {
|
|
739
|
-
clearTimeout(timeoutId);
|
|
740
|
-
try {
|
|
741
|
-
tempSuperdoc?.destroy?.();
|
|
742
|
-
} catch {
|
|
743
|
-
}
|
|
744
|
-
hiddenContainer.parentNode?.removeChild(hiddenContainer);
|
|
745
|
-
};
|
|
746
|
-
try {
|
|
747
|
-
tempSuperdoc = new SuperDocRef.current({
|
|
748
|
-
selector: `#${hiddenContainer.id}`,
|
|
749
|
-
html,
|
|
750
|
-
documentMode: "editing",
|
|
751
|
-
rulers: false,
|
|
752
|
-
user: { name: "Converter", email: "converter@local" },
|
|
753
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
754
|
-
onReady: async ({ superdoc: sd }) => {
|
|
755
|
-
try {
|
|
756
|
-
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 });
|
|
763
|
-
if (!blob) {
|
|
764
|
-
cleanup();
|
|
765
|
-
reject(new Error("Export returned no data"));
|
|
766
|
-
return;
|
|
767
|
-
}
|
|
768
|
-
cleanup();
|
|
769
|
-
resolve({ blob, json });
|
|
770
|
-
} catch (err) {
|
|
771
|
-
cleanup();
|
|
772
|
-
reject(err);
|
|
773
|
-
}
|
|
774
|
-
},
|
|
775
|
-
onException: ({ error: err }) => {
|
|
776
|
-
cleanup();
|
|
777
|
-
reject(err);
|
|
778
|
-
}
|
|
779
|
-
});
|
|
780
|
-
timeoutId = setTimeout(() => {
|
|
781
|
-
cleanup();
|
|
782
|
-
reject(new Error("HTML to DOCX conversion timed out"));
|
|
783
|
-
}, TIMEOUTS.PARSE_TIMEOUT);
|
|
784
|
-
} catch (err) {
|
|
785
|
-
cleanup();
|
|
786
|
-
reject(err);
|
|
787
|
-
}
|
|
788
|
-
});
|
|
789
|
-
},
|
|
790
|
-
[]
|
|
791
|
-
);
|
|
792
726
|
const createSuperdoc = react.useCallback(
|
|
793
727
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
794
728
|
async (options) => {
|
|
@@ -806,31 +740,25 @@ var DocxDiffEditor = react.forwardRef(
|
|
|
806
740
|
if (toolbarRef.current) {
|
|
807
741
|
toolbarRef.current.id = toolbarId;
|
|
808
742
|
}
|
|
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
743
|
return new Promise((resolve, reject) => {
|
|
820
744
|
let resolved = false;
|
|
821
745
|
try {
|
|
822
|
-
const
|
|
746
|
+
const superdocConfig = {
|
|
823
747
|
selector: `#${editorId}`,
|
|
824
748
|
toolbar: showToolbar ? `#${toolbarId}` : void 0,
|
|
825
|
-
document: documentFile,
|
|
826
|
-
html: options.html,
|
|
827
749
|
documentMode: "editing",
|
|
828
750
|
role: "editor",
|
|
829
751
|
rulers: showRulers,
|
|
830
752
|
user: DEFAULT_SUPERDOC_USER,
|
|
831
|
-
permissionResolver
|
|
832
|
-
|
|
833
|
-
|
|
753
|
+
permissionResolver
|
|
754
|
+
};
|
|
755
|
+
if (options.document) {
|
|
756
|
+
superdocConfig.document = options.document;
|
|
757
|
+
} else if (options.html) {
|
|
758
|
+
superdocConfig.html = options.html;
|
|
759
|
+
}
|
|
760
|
+
const superdoc = new SuperDocRef.current({
|
|
761
|
+
...superdocConfig,
|
|
834
762
|
onReady: ({ superdoc: sd }) => {
|
|
835
763
|
if (resolved) return;
|
|
836
764
|
resolved = true;
|
|
@@ -888,15 +816,12 @@ var DocxDiffEditor = react.forwardRef(
|
|
|
888
816
|
const { SuperDoc } = await import('superdoc');
|
|
889
817
|
SuperDocRef.current = SuperDoc;
|
|
890
818
|
let initOptions = {};
|
|
891
|
-
let extractedJson = null;
|
|
892
819
|
if (initialSource) {
|
|
893
820
|
const contentType = detectContentType(initialSource);
|
|
894
821
|
if (contentType === "file") {
|
|
895
822
|
initOptions = { document: initialSource };
|
|
896
823
|
} else if (contentType === "html") {
|
|
897
|
-
|
|
898
|
-
initOptions = { document: blob };
|
|
899
|
-
extractedJson = htmlJson;
|
|
824
|
+
initOptions = { html: initialSource };
|
|
900
825
|
} else if (contentType === "json") {
|
|
901
826
|
initOptions = templateDocx ? { document: templateDocx } : {};
|
|
902
827
|
}
|
|
@@ -911,9 +836,8 @@ var DocxDiffEditor = react.forwardRef(
|
|
|
911
836
|
onSourceLoaded?.(initialSource);
|
|
912
837
|
}
|
|
913
838
|
} else {
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
onSourceLoaded?.(finalJson);
|
|
839
|
+
setSourceJson(json);
|
|
840
|
+
onSourceLoaded?.(json);
|
|
917
841
|
}
|
|
918
842
|
setIsLoading(false);
|
|
919
843
|
onReady?.();
|
|
@@ -932,7 +856,6 @@ var DocxDiffEditor = react.forwardRef(
|
|
|
932
856
|
onSourceLoaded,
|
|
933
857
|
destroySuperdoc,
|
|
934
858
|
createSuperdoc,
|
|
935
|
-
convertHtmlToDocxBlob,
|
|
936
859
|
setEditorContent,
|
|
937
860
|
handleError
|
|
938
861
|
]);
|
|
@@ -949,10 +872,7 @@ var DocxDiffEditor = react.forwardRef(
|
|
|
949
872
|
() => ({
|
|
950
873
|
/**
|
|
951
874
|
* Set the source/base document.
|
|
952
|
-
*
|
|
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.
|
|
875
|
+
* Accepts File (DOCX), HTML string, or ProseMirror JSON.
|
|
956
876
|
*/
|
|
957
877
|
async setSource(content) {
|
|
958
878
|
if (!SuperDocRef.current) {
|
|
@@ -968,15 +888,8 @@ var DocxDiffEditor = react.forwardRef(
|
|
|
968
888
|
const result = await createSuperdoc({ document: content });
|
|
969
889
|
json = result.json;
|
|
970
890
|
} else if (contentType === "html") {
|
|
971
|
-
const
|
|
972
|
-
|
|
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
|
-
}
|
|
891
|
+
const result = await createSuperdoc({ html: content });
|
|
892
|
+
json = result.json;
|
|
980
893
|
} else {
|
|
981
894
|
const result = await createSuperdoc(templateDocx ? { document: templateDocx } : {});
|
|
982
895
|
if (result.superdoc?.activeEditor && isProseMirrorJSON(content)) {
|
|
@@ -1073,6 +986,22 @@ var DocxDiffEditor = react.forwardRef(
|
|
|
1073
986
|
if (superdocRef.current?.activeEditor) {
|
|
1074
987
|
setEditorContent(superdocRef.current.activeEditor, merged);
|
|
1075
988
|
enableReviewMode(superdocRef.current);
|
|
989
|
+
const sd = superdocRef.current;
|
|
990
|
+
if (sd.commentsStore?.processLoadedDocxComments) {
|
|
991
|
+
setTimeout(() => {
|
|
992
|
+
try {
|
|
993
|
+
sd.commentsStore.processLoadedDocxComments({
|
|
994
|
+
superdoc: sd,
|
|
995
|
+
editor: sd.activeEditor,
|
|
996
|
+
comments: [],
|
|
997
|
+
// Empty array - we just want to trigger createCommentForTrackChanges
|
|
998
|
+
documentId: sd.activeEditor?.options?.documentId || "primary"
|
|
999
|
+
});
|
|
1000
|
+
} catch (err) {
|
|
1001
|
+
console.warn("[DocxDiffEditor] Failed to process track changes for bubbles:", err);
|
|
1002
|
+
}
|
|
1003
|
+
}, 50);
|
|
1004
|
+
}
|
|
1076
1005
|
}
|
|
1077
1006
|
const insertions = diff.segments.filter((s) => s.type === "insert").length;
|
|
1078
1007
|
const deletions = diff.segments.filter((s) => s.type === "delete").length;
|
|
@@ -1163,7 +1092,6 @@ var DocxDiffEditor = react.forwardRef(
|
|
|
1163
1092
|
author,
|
|
1164
1093
|
destroySuperdoc,
|
|
1165
1094
|
createSuperdoc,
|
|
1166
|
-
convertHtmlToDocxBlob,
|
|
1167
1095
|
setEditorContent,
|
|
1168
1096
|
enableReviewMode,
|
|
1169
1097
|
setEditingMode,
|