docx-diff-editor 1.0.33 → 1.0.37

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/README.md CHANGED
@@ -132,6 +132,12 @@ interface DocxDiffEditorRef {
132
132
 
133
133
  // Check if ready
134
134
  isReady(): boolean;
135
+
136
+ // Get current page count
137
+ getPages(): number;
138
+
139
+ // Get document metadata and statistics
140
+ getDocumentInfo(): DocumentInfo | null;
135
141
  }
136
142
  ```
137
143
 
@@ -148,6 +154,22 @@ interface ComparisonResult {
148
154
  }
149
155
  ```
150
156
 
157
+ ### DocumentInfo
158
+
159
+ ```tsx
160
+ interface DocumentInfo {
161
+ // Metadata
162
+ documentGuid: string | null;
163
+ isModified: boolean;
164
+ version: number | null;
165
+ // Statistics
166
+ words: number;
167
+ characters: number;
168
+ paragraphs: number;
169
+ pages: number;
170
+ }
171
+ ```
172
+
151
173
  ## Getting LLM Context
152
174
 
153
175
  Extract enriched changes with semantic context for AI/LLM processing:
package/dist/index.d.mts CHANGED
@@ -109,6 +109,25 @@ interface TrackChangeAuthor {
109
109
  name: string;
110
110
  email: string;
111
111
  }
112
+ /**
113
+ * Combined document metadata and statistics
114
+ */
115
+ interface DocumentInfo {
116
+ /** Document unique identifier */
117
+ documentGuid: string | null;
118
+ /** Whether the document has unsaved changes */
119
+ isModified: boolean;
120
+ /** Document version number */
121
+ version: number | null;
122
+ /** Word count */
123
+ words: number;
124
+ /** Character count */
125
+ characters: number;
126
+ /** Paragraph count */
127
+ paragraphs: number;
128
+ /** Page count */
129
+ pages: number;
130
+ }
112
131
  /**
113
132
  * Props for DocxDiffEditor component
114
133
  */
@@ -142,8 +161,10 @@ interface DocxDiffEditorProps {
142
161
  * Ref methods exposed by DocxDiffEditor
143
162
  */
144
163
  interface DocxDiffEditorRef {
145
- /** Set the source/base document */
164
+ /** Set the source/base document (destroys and recreates SuperDoc instance) */
146
165
  setSource(content: DocxContent): Promise<void>;
166
+ /** Update content in the existing editor without recreating SuperDoc instance */
167
+ updateContent(json: ProseMirrorJSON): void;
147
168
  /** Compare source with new content, show track changes */
148
169
  compareWith(content: DocxContent): Promise<ComparisonResult>;
149
170
  /** Get raw diff segments */
@@ -162,6 +183,10 @@ interface DocxDiffEditorRef {
162
183
  acceptAllChanges(): Promise<ProseMirrorJSON>;
163
184
  /** Check if editor is ready */
164
185
  isReady(): boolean;
186
+ /** Get the current page count from the presentation editor */
187
+ getPages(): number;
188
+ /** Get combined document metadata and statistics */
189
+ getDocumentInfo(): DocumentInfo | null;
165
190
  }
166
191
 
167
192
  /**
@@ -309,4 +334,4 @@ declare function getBlankTemplateBlob(): Blob;
309
334
  */
310
335
  declare function isValidDocxFile(file: File): boolean;
311
336
 
312
- export { CSS_PREFIX, type ChangeLocation, type ComparisonResult, DEFAULT_AUTHOR, DEFAULT_SUPERDOC_USER, type DiffResult, type DiffSegment, type DocxContent, DocxDiffEditor, type DocxDiffEditorProps, type DocxDiffEditorRef, type EnrichedChange, type FormatChange, type FormatDetails, type ProseMirrorJSON, type ProseMirrorMark, type ProseMirrorNode, type TrackChangeAuthor, createTrackDeleteMark, createTrackFormatMark, createTrackInsertMark, DocxDiffEditor as default, detectContentType, diffDocuments, extractEnrichedChanges, getBlankTemplateBlob, getBlankTemplateFile, isProseMirrorJSON, isValidDocxFile, mergeDocuments, parseDocxFile };
337
+ export { CSS_PREFIX, type ChangeLocation, type ComparisonResult, DEFAULT_AUTHOR, DEFAULT_SUPERDOC_USER, type DiffResult, type DiffSegment, type DocumentInfo, type DocxContent, DocxDiffEditor, type DocxDiffEditorProps, type DocxDiffEditorRef, type EnrichedChange, type FormatChange, type FormatDetails, type ProseMirrorJSON, type ProseMirrorMark, type ProseMirrorNode, type TrackChangeAuthor, createTrackDeleteMark, createTrackFormatMark, createTrackInsertMark, DocxDiffEditor as default, detectContentType, diffDocuments, extractEnrichedChanges, getBlankTemplateBlob, getBlankTemplateFile, isProseMirrorJSON, isValidDocxFile, mergeDocuments, parseDocxFile };
package/dist/index.d.ts CHANGED
@@ -109,6 +109,25 @@ interface TrackChangeAuthor {
109
109
  name: string;
110
110
  email: string;
111
111
  }
112
+ /**
113
+ * Combined document metadata and statistics
114
+ */
115
+ interface DocumentInfo {
116
+ /** Document unique identifier */
117
+ documentGuid: string | null;
118
+ /** Whether the document has unsaved changes */
119
+ isModified: boolean;
120
+ /** Document version number */
121
+ version: number | null;
122
+ /** Word count */
123
+ words: number;
124
+ /** Character count */
125
+ characters: number;
126
+ /** Paragraph count */
127
+ paragraphs: number;
128
+ /** Page count */
129
+ pages: number;
130
+ }
112
131
  /**
113
132
  * Props for DocxDiffEditor component
114
133
  */
@@ -142,8 +161,10 @@ interface DocxDiffEditorProps {
142
161
  * Ref methods exposed by DocxDiffEditor
143
162
  */
144
163
  interface DocxDiffEditorRef {
145
- /** Set the source/base document */
164
+ /** Set the source/base document (destroys and recreates SuperDoc instance) */
146
165
  setSource(content: DocxContent): Promise<void>;
166
+ /** Update content in the existing editor without recreating SuperDoc instance */
167
+ updateContent(json: ProseMirrorJSON): void;
147
168
  /** Compare source with new content, show track changes */
148
169
  compareWith(content: DocxContent): Promise<ComparisonResult>;
149
170
  /** Get raw diff segments */
@@ -162,6 +183,10 @@ interface DocxDiffEditorRef {
162
183
  acceptAllChanges(): Promise<ProseMirrorJSON>;
163
184
  /** Check if editor is ready */
164
185
  isReady(): boolean;
186
+ /** Get the current page count from the presentation editor */
187
+ getPages(): number;
188
+ /** Get combined document metadata and statistics */
189
+ getDocumentInfo(): DocumentInfo | null;
165
190
  }
166
191
 
167
192
  /**
@@ -309,4 +334,4 @@ declare function getBlankTemplateBlob(): Blob;
309
334
  */
310
335
  declare function isValidDocxFile(file: File): boolean;
311
336
 
312
- export { CSS_PREFIX, type ChangeLocation, type ComparisonResult, DEFAULT_AUTHOR, DEFAULT_SUPERDOC_USER, type DiffResult, type DiffSegment, type DocxContent, DocxDiffEditor, type DocxDiffEditorProps, type DocxDiffEditorRef, type EnrichedChange, type FormatChange, type FormatDetails, type ProseMirrorJSON, type ProseMirrorMark, type ProseMirrorNode, type TrackChangeAuthor, createTrackDeleteMark, createTrackFormatMark, createTrackInsertMark, DocxDiffEditor as default, detectContentType, diffDocuments, extractEnrichedChanges, getBlankTemplateBlob, getBlankTemplateFile, isProseMirrorJSON, isValidDocxFile, mergeDocuments, parseDocxFile };
337
+ export { CSS_PREFIX, type ChangeLocation, type ComparisonResult, DEFAULT_AUTHOR, DEFAULT_SUPERDOC_USER, type DiffResult, type DiffSegment, type DocumentInfo, type DocxContent, DocxDiffEditor, type DocxDiffEditorProps, type DocxDiffEditorRef, type EnrichedChange, type FormatChange, type FormatDetails, type ProseMirrorJSON, type ProseMirrorMark, type ProseMirrorNode, type TrackChangeAuthor, createTrackDeleteMark, createTrackFormatMark, createTrackInsertMark, DocxDiffEditor as default, detectContentType, diffDocuments, extractEnrichedChanges, getBlankTemplateBlob, getBlankTemplateFile, isProseMirrorJSON, isValidDocxFile, mergeDocuments, parseDocxFile };
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) => {
@@ -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) {
@@ -1166,6 +1177,65 @@ var DocxDiffEditor = react.forwardRef(
1166
1177
  */
1167
1178
  isReady() {
1168
1179
  return readyRef.current;
1180
+ },
1181
+ /**
1182
+ * Get the current page count from the presentation editor.
1183
+ * Returns 0 if editor is not ready or pages are unavailable.
1184
+ */
1185
+ getPages() {
1186
+ if (!readyRef.current || !superdocRef.current) {
1187
+ return 0;
1188
+ }
1189
+ try {
1190
+ const sd = superdocRef.current;
1191
+ const doc = sd.superdocStore?.documents?.[0];
1192
+ if (!doc) {
1193
+ return 0;
1194
+ }
1195
+ const presentationEditor = doc.getPresentationEditor?.();
1196
+ const pages = presentationEditor?.getPages?.();
1197
+ return pages?.length ?? 0;
1198
+ } catch (err) {
1199
+ console.warn("[DocxDiffEditor] Failed to get page count:", err);
1200
+ return 0;
1201
+ }
1202
+ },
1203
+ /**
1204
+ * Get combined document metadata and statistics.
1205
+ * Returns null if editor is not ready.
1206
+ */
1207
+ getDocumentInfo() {
1208
+ if (!readyRef.current || !superdocRef.current) {
1209
+ return null;
1210
+ }
1211
+ try {
1212
+ const sd = superdocRef.current;
1213
+ const doc = sd.superdocStore?.documents?.[0];
1214
+ if (!doc) {
1215
+ return null;
1216
+ }
1217
+ const editor = doc.getEditor?.();
1218
+ const metadata = editor?.getMetadata?.() ?? {};
1219
+ const stats = editor?.commands?.getDocumentStats?.() ?? {};
1220
+ const presentationEditor = doc.getPresentationEditor?.();
1221
+ const pages = presentationEditor?.getPages?.();
1222
+ const pageCount = pages?.length ?? 0;
1223
+ return {
1224
+ // Metadata
1225
+ documentGuid: metadata.documentGuid ?? null,
1226
+ isModified: metadata.isModified ?? false,
1227
+ version: metadata.version ?? null,
1228
+ // Stats
1229
+ words: stats.words ?? 0,
1230
+ characters: stats.characters ?? 0,
1231
+ paragraphs: stats.paragraphs ?? 0,
1232
+ // Pages
1233
+ pages: pageCount
1234
+ };
1235
+ } catch (err) {
1236
+ console.warn("[DocxDiffEditor] Failed to get document info:", err);
1237
+ return null;
1238
+ }
1169
1239
  }
1170
1240
  }),
1171
1241
  [