docx-diff-editor 1.0.32 → 1.0.35

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.d.mts CHANGED
@@ -142,8 +142,10 @@ interface DocxDiffEditorProps {
142
142
  * Ref methods exposed by DocxDiffEditor
143
143
  */
144
144
  interface DocxDiffEditorRef {
145
- /** Set the source/base document */
145
+ /** Set the source/base document (destroys and recreates SuperDoc instance) */
146
146
  setSource(content: DocxContent): Promise<void>;
147
+ /** Update content in the existing editor without recreating SuperDoc instance */
148
+ updateContent(json: ProseMirrorJSON): void;
147
149
  /** Compare source with new content, show track changes */
148
150
  compareWith(content: DocxContent): Promise<ComparisonResult>;
149
151
  /** Get raw diff segments */
package/dist/index.d.ts CHANGED
@@ -142,8 +142,10 @@ interface DocxDiffEditorProps {
142
142
  * Ref methods exposed by DocxDiffEditor
143
143
  */
144
144
  interface DocxDiffEditorRef {
145
- /** Set the source/base document */
145
+ /** Set the source/base document (destroys and recreates SuperDoc instance) */
146
146
  setSource(content: DocxContent): Promise<void>;
147
+ /** Update content in the existing editor without recreating SuperDoc instance */
148
+ updateContent(json: ProseMirrorJSON): void;
147
149
  /** Compare source with new content, show track changes */
148
150
  compareWith(content: DocxContent): Promise<ComparisonResult>;
149
151
  /** Get raw diff segments */
package/dist/index.js CHANGED
@@ -733,17 +733,11 @@ var DocxDiffEditor = react.forwardRef(
733
733
  const editorId = `dde-editor-${instanceId.current}`;
734
734
  const toolbarId = `dde-toolbar-${instanceId.current}`;
735
735
  const setEditorContent = react.useCallback((editor, json) => {
736
- if (editor.commands?.setContent) {
737
- editor.commands.setContent(json);
738
- } else if (editor.setContent) {
739
- editor.setContent(json);
740
- } else {
741
- const { state, view } = editor;
742
- if (state?.doc && view && json.content) {
743
- const newDoc = state.schema.nodeFromJSON(json);
744
- const tr = state.tr.replaceWith(0, state.doc.content.size, newDoc.content);
745
- view.dispatch(tr);
746
- }
736
+ const { state, view } = editor;
737
+ if (state?.doc && view && json.content) {
738
+ const newDoc = state.schema.nodeFromJSON(json);
739
+ const tr = state.tr.replaceWith(0, state.doc.content.size, newDoc.content);
740
+ view.dispatch(tr);
747
741
  }
748
742
  }, []);
749
743
  const enableReviewMode = react.useCallback((sd) => {
@@ -755,7 +749,7 @@ var DocxDiffEditor = react.forwardRef(
755
749
  }, []);
756
750
  const setEditingMode = react.useCallback((sd) => {
757
751
  if (sd.setTrackedChangesPreferences) {
758
- sd.setTrackedChangesPreferences({ mode: "simple", enabled: false });
752
+ sd.setTrackedChangesPreferences({ mode: "off", enabled: false });
759
753
  }
760
754
  }, []);
761
755
  const handleError = react.useCallback(
@@ -925,9 +919,26 @@ var DocxDiffEditor = react.forwardRef(
925
919
  react.useImperativeHandle(
926
920
  ref,
927
921
  () => ({
922
+ /**
923
+ * Update content in the existing editor without recreating SuperDoc instance.
924
+ * Preserves the DOCX template/styling. Ideal for replacing content with translated JSON.
925
+ */
926
+ updateContent(json) {
927
+ const editor = superdocRef.current?.activeEditor;
928
+ if (!editor) {
929
+ throw new Error("Editor not ready");
930
+ }
931
+ setEditorContent(editor, json);
932
+ setSourceJson(json);
933
+ setMergedJson(null);
934
+ setDiffResult(null);
935
+ onSourceLoaded?.(json);
936
+ },
928
937
  /**
929
938
  * Set the source/base document.
930
939
  * Accepts File (DOCX), HTML string, or ProseMirror JSON.
940
+ * Note: This destroys and recreates the SuperDoc instance.
941
+ * For JSON content updates, prefer updateContent() to preserve the existing template.
931
942
  */
932
943
  async setSource(content) {
933
944
  if (!SuperDocRef.current) {