docx-diff-editor 1.0.14 → 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 +16 -86
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +16 -86
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -723,74 +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 resolved = false;
|
|
737
|
-
let tempSuperdoc = null;
|
|
738
|
-
const cleanup = () => {
|
|
739
|
-
try {
|
|
740
|
-
tempSuperdoc?.destroy?.();
|
|
741
|
-
} catch {
|
|
742
|
-
}
|
|
743
|
-
hiddenContainer.parentNode?.removeChild(hiddenContainer);
|
|
744
|
-
};
|
|
745
|
-
try {
|
|
746
|
-
tempSuperdoc = new SuperDocRef.current({
|
|
747
|
-
selector: `#${hiddenContainer.id}`,
|
|
748
|
-
html,
|
|
749
|
-
documentMode: "editing",
|
|
750
|
-
rulers: false,
|
|
751
|
-
user: { name: "Converter", email: "converter@local" },
|
|
752
|
-
onReady: async ({ superdoc: sd }) => {
|
|
753
|
-
if (resolved) return;
|
|
754
|
-
try {
|
|
755
|
-
const json = sd?.activeEditor?.getJSON() || { type: "doc", content: [] };
|
|
756
|
-
const blob = await sd?.activeEditor?.exportDocx({ isFinalDoc: true });
|
|
757
|
-
if (!blob) {
|
|
758
|
-
throw new Error("Export returned no data");
|
|
759
|
-
}
|
|
760
|
-
resolved = true;
|
|
761
|
-
cleanup();
|
|
762
|
-
resolve({ blob, json });
|
|
763
|
-
} catch (err) {
|
|
764
|
-
resolved = true;
|
|
765
|
-
cleanup();
|
|
766
|
-
reject(err);
|
|
767
|
-
}
|
|
768
|
-
},
|
|
769
|
-
onException: ({ error: err }) => {
|
|
770
|
-
if (resolved) return;
|
|
771
|
-
resolved = true;
|
|
772
|
-
cleanup();
|
|
773
|
-
reject(err);
|
|
774
|
-
}
|
|
775
|
-
});
|
|
776
|
-
setTimeout(() => {
|
|
777
|
-
if (!resolved) {
|
|
778
|
-
resolved = true;
|
|
779
|
-
cleanup();
|
|
780
|
-
reject(new Error("HTML to DOCX conversion timed out"));
|
|
781
|
-
}
|
|
782
|
-
}, TIMEOUTS.PARSE_TIMEOUT);
|
|
783
|
-
} catch (err) {
|
|
784
|
-
if (!resolved) {
|
|
785
|
-
resolved = true;
|
|
786
|
-
cleanup();
|
|
787
|
-
reject(err);
|
|
788
|
-
}
|
|
789
|
-
}
|
|
790
|
-
});
|
|
791
|
-
},
|
|
792
|
-
[]
|
|
793
|
-
);
|
|
794
726
|
const createSuperdoc = react.useCallback(
|
|
795
727
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
796
728
|
async (options) => {
|
|
@@ -811,15 +743,22 @@ var DocxDiffEditor = react.forwardRef(
|
|
|
811
743
|
return new Promise((resolve, reject) => {
|
|
812
744
|
let resolved = false;
|
|
813
745
|
try {
|
|
814
|
-
const
|
|
746
|
+
const superdocConfig = {
|
|
815
747
|
selector: `#${editorId}`,
|
|
816
748
|
toolbar: showToolbar ? `#${toolbarId}` : void 0,
|
|
817
|
-
document: options.document,
|
|
818
749
|
documentMode: "editing",
|
|
819
750
|
role: "editor",
|
|
820
751
|
rulers: showRulers,
|
|
821
752
|
user: DEFAULT_SUPERDOC_USER,
|
|
822
|
-
permissionResolver
|
|
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,
|
|
823
762
|
onReady: ({ superdoc: sd }) => {
|
|
824
763
|
if (resolved) return;
|
|
825
764
|
resolved = true;
|
|
@@ -877,15 +816,12 @@ var DocxDiffEditor = react.forwardRef(
|
|
|
877
816
|
const { SuperDoc } = await import('superdoc');
|
|
878
817
|
SuperDocRef.current = SuperDoc;
|
|
879
818
|
let initOptions = {};
|
|
880
|
-
let extractedJson = null;
|
|
881
819
|
if (initialSource) {
|
|
882
820
|
const contentType = detectContentType(initialSource);
|
|
883
821
|
if (contentType === "file") {
|
|
884
822
|
initOptions = { document: initialSource };
|
|
885
823
|
} else if (contentType === "html") {
|
|
886
|
-
|
|
887
|
-
initOptions = { document: blob };
|
|
888
|
-
extractedJson = htmlJson;
|
|
824
|
+
initOptions = { html: initialSource };
|
|
889
825
|
} else if (contentType === "json") {
|
|
890
826
|
initOptions = templateDocx ? { document: templateDocx } : {};
|
|
891
827
|
}
|
|
@@ -900,9 +836,8 @@ var DocxDiffEditor = react.forwardRef(
|
|
|
900
836
|
onSourceLoaded?.(initialSource);
|
|
901
837
|
}
|
|
902
838
|
} else {
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
onSourceLoaded?.(sourceJsonToUse);
|
|
839
|
+
setSourceJson(json);
|
|
840
|
+
onSourceLoaded?.(json);
|
|
906
841
|
}
|
|
907
842
|
setIsLoading(false);
|
|
908
843
|
onReady?.();
|
|
@@ -921,7 +856,6 @@ var DocxDiffEditor = react.forwardRef(
|
|
|
921
856
|
onSourceLoaded,
|
|
922
857
|
destroySuperdoc,
|
|
923
858
|
createSuperdoc,
|
|
924
|
-
convertHtmlToDocxBlob,
|
|
925
859
|
setEditorContent,
|
|
926
860
|
handleError
|
|
927
861
|
]);
|
|
@@ -938,9 +872,7 @@ var DocxDiffEditor = react.forwardRef(
|
|
|
938
872
|
() => ({
|
|
939
873
|
/**
|
|
940
874
|
* Set the source/base document.
|
|
941
|
-
*
|
|
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.
|
|
875
|
+
* Accepts File (DOCX), HTML string, or ProseMirror JSON.
|
|
944
876
|
*/
|
|
945
877
|
async setSource(content) {
|
|
946
878
|
if (!SuperDocRef.current) {
|
|
@@ -956,9 +888,8 @@ var DocxDiffEditor = react.forwardRef(
|
|
|
956
888
|
const result = await createSuperdoc({ document: content });
|
|
957
889
|
json = result.json;
|
|
958
890
|
} else if (contentType === "html") {
|
|
959
|
-
const
|
|
960
|
-
|
|
961
|
-
json = htmlJson;
|
|
891
|
+
const result = await createSuperdoc({ html: content });
|
|
892
|
+
json = result.json;
|
|
962
893
|
} else {
|
|
963
894
|
const result = await createSuperdoc(templateDocx ? { document: templateDocx } : {});
|
|
964
895
|
if (result.superdoc?.activeEditor && isProseMirrorJSON(content)) {
|
|
@@ -1161,7 +1092,6 @@ var DocxDiffEditor = react.forwardRef(
|
|
|
1161
1092
|
author,
|
|
1162
1093
|
destroySuperdoc,
|
|
1163
1094
|
createSuperdoc,
|
|
1164
|
-
convertHtmlToDocxBlob,
|
|
1165
1095
|
setEditorContent,
|
|
1166
1096
|
enableReviewMode,
|
|
1167
1097
|
setEditingMode,
|