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.mjs
CHANGED
|
@@ -715,74 +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 resolved = false;
|
|
729
|
-
let tempSuperdoc = null;
|
|
730
|
-
const cleanup = () => {
|
|
731
|
-
try {
|
|
732
|
-
tempSuperdoc?.destroy?.();
|
|
733
|
-
} catch {
|
|
734
|
-
}
|
|
735
|
-
hiddenContainer.parentNode?.removeChild(hiddenContainer);
|
|
736
|
-
};
|
|
737
|
-
try {
|
|
738
|
-
tempSuperdoc = new SuperDocRef.current({
|
|
739
|
-
selector: `#${hiddenContainer.id}`,
|
|
740
|
-
html,
|
|
741
|
-
documentMode: "editing",
|
|
742
|
-
rulers: false,
|
|
743
|
-
user: { name: "Converter", email: "converter@local" },
|
|
744
|
-
onReady: async ({ superdoc: sd }) => {
|
|
745
|
-
if (resolved) return;
|
|
746
|
-
try {
|
|
747
|
-
const json = sd?.activeEditor?.getJSON() || { type: "doc", content: [] };
|
|
748
|
-
const blob = await sd?.activeEditor?.exportDocx({ isFinalDoc: true });
|
|
749
|
-
if (!blob) {
|
|
750
|
-
throw new Error("Export returned no data");
|
|
751
|
-
}
|
|
752
|
-
resolved = true;
|
|
753
|
-
cleanup();
|
|
754
|
-
resolve({ blob, json });
|
|
755
|
-
} catch (err) {
|
|
756
|
-
resolved = true;
|
|
757
|
-
cleanup();
|
|
758
|
-
reject(err);
|
|
759
|
-
}
|
|
760
|
-
},
|
|
761
|
-
onException: ({ error: err }) => {
|
|
762
|
-
if (resolved) return;
|
|
763
|
-
resolved = true;
|
|
764
|
-
cleanup();
|
|
765
|
-
reject(err);
|
|
766
|
-
}
|
|
767
|
-
});
|
|
768
|
-
setTimeout(() => {
|
|
769
|
-
if (!resolved) {
|
|
770
|
-
resolved = true;
|
|
771
|
-
cleanup();
|
|
772
|
-
reject(new Error("HTML to DOCX conversion timed out"));
|
|
773
|
-
}
|
|
774
|
-
}, TIMEOUTS.PARSE_TIMEOUT);
|
|
775
|
-
} catch (err) {
|
|
776
|
-
if (!resolved) {
|
|
777
|
-
resolved = true;
|
|
778
|
-
cleanup();
|
|
779
|
-
reject(err);
|
|
780
|
-
}
|
|
781
|
-
}
|
|
782
|
-
});
|
|
783
|
-
},
|
|
784
|
-
[]
|
|
785
|
-
);
|
|
786
718
|
const createSuperdoc = useCallback(
|
|
787
719
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
788
720
|
async (options) => {
|
|
@@ -803,15 +735,22 @@ var DocxDiffEditor = forwardRef(
|
|
|
803
735
|
return new Promise((resolve, reject) => {
|
|
804
736
|
let resolved = false;
|
|
805
737
|
try {
|
|
806
|
-
const
|
|
738
|
+
const superdocConfig = {
|
|
807
739
|
selector: `#${editorId}`,
|
|
808
740
|
toolbar: showToolbar ? `#${toolbarId}` : void 0,
|
|
809
|
-
document: options.document,
|
|
810
741
|
documentMode: "editing",
|
|
811
742
|
role: "editor",
|
|
812
743
|
rulers: showRulers,
|
|
813
744
|
user: DEFAULT_SUPERDOC_USER,
|
|
814
|
-
permissionResolver
|
|
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,
|
|
815
754
|
onReady: ({ superdoc: sd }) => {
|
|
816
755
|
if (resolved) return;
|
|
817
756
|
resolved = true;
|
|
@@ -869,15 +808,12 @@ var DocxDiffEditor = forwardRef(
|
|
|
869
808
|
const { SuperDoc } = await import('superdoc');
|
|
870
809
|
SuperDocRef.current = SuperDoc;
|
|
871
810
|
let initOptions = {};
|
|
872
|
-
let extractedJson = null;
|
|
873
811
|
if (initialSource) {
|
|
874
812
|
const contentType = detectContentType(initialSource);
|
|
875
813
|
if (contentType === "file") {
|
|
876
814
|
initOptions = { document: initialSource };
|
|
877
815
|
} else if (contentType === "html") {
|
|
878
|
-
|
|
879
|
-
initOptions = { document: blob };
|
|
880
|
-
extractedJson = htmlJson;
|
|
816
|
+
initOptions = { html: initialSource };
|
|
881
817
|
} else if (contentType === "json") {
|
|
882
818
|
initOptions = templateDocx ? { document: templateDocx } : {};
|
|
883
819
|
}
|
|
@@ -892,9 +828,8 @@ var DocxDiffEditor = forwardRef(
|
|
|
892
828
|
onSourceLoaded?.(initialSource);
|
|
893
829
|
}
|
|
894
830
|
} else {
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
onSourceLoaded?.(sourceJsonToUse);
|
|
831
|
+
setSourceJson(json);
|
|
832
|
+
onSourceLoaded?.(json);
|
|
898
833
|
}
|
|
899
834
|
setIsLoading(false);
|
|
900
835
|
onReady?.();
|
|
@@ -913,7 +848,6 @@ var DocxDiffEditor = forwardRef(
|
|
|
913
848
|
onSourceLoaded,
|
|
914
849
|
destroySuperdoc,
|
|
915
850
|
createSuperdoc,
|
|
916
|
-
convertHtmlToDocxBlob,
|
|
917
851
|
setEditorContent,
|
|
918
852
|
handleError
|
|
919
853
|
]);
|
|
@@ -930,9 +864,7 @@ var DocxDiffEditor = forwardRef(
|
|
|
930
864
|
() => ({
|
|
931
865
|
/**
|
|
932
866
|
* Set the source/base document.
|
|
933
|
-
*
|
|
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.
|
|
867
|
+
* Accepts File (DOCX), HTML string, or ProseMirror JSON.
|
|
936
868
|
*/
|
|
937
869
|
async setSource(content) {
|
|
938
870
|
if (!SuperDocRef.current) {
|
|
@@ -948,9 +880,8 @@ var DocxDiffEditor = forwardRef(
|
|
|
948
880
|
const result = await createSuperdoc({ document: content });
|
|
949
881
|
json = result.json;
|
|
950
882
|
} else if (contentType === "html") {
|
|
951
|
-
const
|
|
952
|
-
|
|
953
|
-
json = htmlJson;
|
|
883
|
+
const result = await createSuperdoc({ html: content });
|
|
884
|
+
json = result.json;
|
|
954
885
|
} else {
|
|
955
886
|
const result = await createSuperdoc(templateDocx ? { document: templateDocx } : {});
|
|
956
887
|
if (result.superdoc?.activeEditor && isProseMirrorJSON(content)) {
|
|
@@ -1153,7 +1084,6 @@ var DocxDiffEditor = forwardRef(
|
|
|
1153
1084
|
author,
|
|
1154
1085
|
destroySuperdoc,
|
|
1155
1086
|
createSuperdoc,
|
|
1156
|
-
convertHtmlToDocxBlob,
|
|
1157
1087
|
setEditorContent,
|
|
1158
1088
|
enableReviewMode,
|
|
1159
1089
|
setEditingMode,
|