docx-diff-editor 1.0.37 → 1.0.39
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 +47 -0
- package/dist/index.d.mts +30 -1
- package/dist/index.d.ts +30 -1
- package/dist/index.js +126 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +126 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -138,6 +138,12 @@ interface DocxDiffEditorRef {
|
|
|
138
138
|
|
|
139
139
|
// Get document metadata and statistics
|
|
140
140
|
getDocumentInfo(): DocumentInfo | null;
|
|
141
|
+
|
|
142
|
+
// Get document core properties
|
|
143
|
+
getProperties(): Promise<DocumentProperties | null>;
|
|
144
|
+
|
|
145
|
+
// Set document core properties (partial update)
|
|
146
|
+
setProperties(properties: Partial<DocumentProperties>): Promise<boolean>;
|
|
141
147
|
}
|
|
142
148
|
```
|
|
143
149
|
|
|
@@ -170,6 +176,23 @@ interface DocumentInfo {
|
|
|
170
176
|
}
|
|
171
177
|
```
|
|
172
178
|
|
|
179
|
+
### DocumentProperties
|
|
180
|
+
|
|
181
|
+
```tsx
|
|
182
|
+
interface DocumentProperties {
|
|
183
|
+
title?: string;
|
|
184
|
+
author?: string;
|
|
185
|
+
subject?: string;
|
|
186
|
+
description?: string;
|
|
187
|
+
keywords?: string;
|
|
188
|
+
category?: string;
|
|
189
|
+
lastModifiedBy?: string;
|
|
190
|
+
revision?: string;
|
|
191
|
+
created?: Date;
|
|
192
|
+
modified?: Date;
|
|
193
|
+
}
|
|
194
|
+
```
|
|
195
|
+
|
|
173
196
|
## Getting LLM Context
|
|
174
197
|
|
|
175
198
|
Extract enriched changes with semantic context for AI/LLM processing:
|
|
@@ -197,6 +220,30 @@ await fetch('/api/summarize', {
|
|
|
197
220
|
// }
|
|
198
221
|
```
|
|
199
222
|
|
|
223
|
+
## Document Properties
|
|
224
|
+
|
|
225
|
+
Read and update document metadata (stored in `docProps/core.xml`):
|
|
226
|
+
|
|
227
|
+
```tsx
|
|
228
|
+
// Get current properties
|
|
229
|
+
const props = await editorRef.current?.getProperties();
|
|
230
|
+
if (props) {
|
|
231
|
+
console.log(`Title: ${props.title}`);
|
|
232
|
+
console.log(`Author: ${props.author}`);
|
|
233
|
+
console.log(`Created: ${props.created?.toLocaleDateString()}`);
|
|
234
|
+
console.log(`Modified: ${props.modified?.toLocaleDateString()}`);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// Update properties (partial update - only specified fields are changed)
|
|
238
|
+
await editorRef.current?.setProperties({
|
|
239
|
+
title: 'Quarterly Report Q4 2026',
|
|
240
|
+
author: 'Jane Smith',
|
|
241
|
+
subject: 'Financial Summary',
|
|
242
|
+
keywords: 'report, quarterly, finance, 2026',
|
|
243
|
+
modified: new Date(),
|
|
244
|
+
});
|
|
245
|
+
```
|
|
246
|
+
|
|
200
247
|
## Customization
|
|
201
248
|
|
|
202
249
|
### CSS Variables
|
package/dist/index.d.mts
CHANGED
|
@@ -109,6 +109,31 @@ interface TrackChangeAuthor {
|
|
|
109
109
|
name: string;
|
|
110
110
|
email: string;
|
|
111
111
|
}
|
|
112
|
+
/**
|
|
113
|
+
* Document core properties (stored in docProps/core.xml)
|
|
114
|
+
*/
|
|
115
|
+
interface DocumentProperties {
|
|
116
|
+
/** Document title (dc:title) */
|
|
117
|
+
title?: string;
|
|
118
|
+
/** Original author (dc:creator) */
|
|
119
|
+
author?: string;
|
|
120
|
+
/** Subject/topic (dc:subject) */
|
|
121
|
+
subject?: string;
|
|
122
|
+
/** Comments/description (dc:description) */
|
|
123
|
+
description?: string;
|
|
124
|
+
/** Keywords/tags (cp:keywords) */
|
|
125
|
+
keywords?: string;
|
|
126
|
+
/** Category (cp:category) */
|
|
127
|
+
category?: string;
|
|
128
|
+
/** Last modified by (cp:lastModifiedBy) */
|
|
129
|
+
lastModifiedBy?: string;
|
|
130
|
+
/** Revision number (cp:revision) */
|
|
131
|
+
revision?: string;
|
|
132
|
+
/** Creation date (dcterms:created) */
|
|
133
|
+
created?: Date;
|
|
134
|
+
/** Last modified date (dcterms:modified) */
|
|
135
|
+
modified?: Date;
|
|
136
|
+
}
|
|
112
137
|
/**
|
|
113
138
|
* Combined document metadata and statistics
|
|
114
139
|
*/
|
|
@@ -187,6 +212,10 @@ interface DocxDiffEditorRef {
|
|
|
187
212
|
getPages(): number;
|
|
188
213
|
/** Get combined document metadata and statistics */
|
|
189
214
|
getDocumentInfo(): DocumentInfo | null;
|
|
215
|
+
/** Get document core properties (from docProps/core.xml) */
|
|
216
|
+
getProperties(): Promise<DocumentProperties | null>;
|
|
217
|
+
/** Set document core properties (partial update) */
|
|
218
|
+
setProperties(properties: Partial<DocumentProperties>): Promise<boolean>;
|
|
190
219
|
}
|
|
191
220
|
|
|
192
221
|
/**
|
|
@@ -334,4 +363,4 @@ declare function getBlankTemplateBlob(): Blob;
|
|
|
334
363
|
*/
|
|
335
364
|
declare function isValidDocxFile(file: File): boolean;
|
|
336
365
|
|
|
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 };
|
|
366
|
+
export { CSS_PREFIX, type ChangeLocation, type ComparisonResult, DEFAULT_AUTHOR, DEFAULT_SUPERDOC_USER, type DiffResult, type DiffSegment, type DocumentInfo, type DocumentProperties, 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,31 @@ interface TrackChangeAuthor {
|
|
|
109
109
|
name: string;
|
|
110
110
|
email: string;
|
|
111
111
|
}
|
|
112
|
+
/**
|
|
113
|
+
* Document core properties (stored in docProps/core.xml)
|
|
114
|
+
*/
|
|
115
|
+
interface DocumentProperties {
|
|
116
|
+
/** Document title (dc:title) */
|
|
117
|
+
title?: string;
|
|
118
|
+
/** Original author (dc:creator) */
|
|
119
|
+
author?: string;
|
|
120
|
+
/** Subject/topic (dc:subject) */
|
|
121
|
+
subject?: string;
|
|
122
|
+
/** Comments/description (dc:description) */
|
|
123
|
+
description?: string;
|
|
124
|
+
/** Keywords/tags (cp:keywords) */
|
|
125
|
+
keywords?: string;
|
|
126
|
+
/** Category (cp:category) */
|
|
127
|
+
category?: string;
|
|
128
|
+
/** Last modified by (cp:lastModifiedBy) */
|
|
129
|
+
lastModifiedBy?: string;
|
|
130
|
+
/** Revision number (cp:revision) */
|
|
131
|
+
revision?: string;
|
|
132
|
+
/** Creation date (dcterms:created) */
|
|
133
|
+
created?: Date;
|
|
134
|
+
/** Last modified date (dcterms:modified) */
|
|
135
|
+
modified?: Date;
|
|
136
|
+
}
|
|
112
137
|
/**
|
|
113
138
|
* Combined document metadata and statistics
|
|
114
139
|
*/
|
|
@@ -187,6 +212,10 @@ interface DocxDiffEditorRef {
|
|
|
187
212
|
getPages(): number;
|
|
188
213
|
/** Get combined document metadata and statistics */
|
|
189
214
|
getDocumentInfo(): DocumentInfo | null;
|
|
215
|
+
/** Get document core properties (from docProps/core.xml) */
|
|
216
|
+
getProperties(): Promise<DocumentProperties | null>;
|
|
217
|
+
/** Set document core properties (partial update) */
|
|
218
|
+
setProperties(properties: Partial<DocumentProperties>): Promise<boolean>;
|
|
190
219
|
}
|
|
191
220
|
|
|
192
221
|
/**
|
|
@@ -334,4 +363,4 @@ declare function getBlankTemplateBlob(): Blob;
|
|
|
334
363
|
*/
|
|
335
364
|
declare function isValidDocxFile(file: File): boolean;
|
|
336
365
|
|
|
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 };
|
|
366
|
+
export { CSS_PREFIX, type ChangeLocation, type ComparisonResult, DEFAULT_AUTHOR, DEFAULT_SUPERDOC_USER, type DiffResult, type DiffSegment, type DocumentInfo, type DocumentProperties, 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
|
@@ -1236,6 +1236,132 @@ var DocxDiffEditor = react.forwardRef(
|
|
|
1236
1236
|
console.warn("[DocxDiffEditor] Failed to get document info:", err);
|
|
1237
1237
|
return null;
|
|
1238
1238
|
}
|
|
1239
|
+
},
|
|
1240
|
+
/**
|
|
1241
|
+
* Get document core properties from docProps/core.xml.
|
|
1242
|
+
* Returns null if editor is not ready or properties unavailable.
|
|
1243
|
+
*/
|
|
1244
|
+
async getProperties() {
|
|
1245
|
+
if (!readyRef.current || !superdocRef.current) {
|
|
1246
|
+
return null;
|
|
1247
|
+
}
|
|
1248
|
+
try {
|
|
1249
|
+
const sd = superdocRef.current;
|
|
1250
|
+
const doc = sd.superdocStore?.documents?.[0];
|
|
1251
|
+
if (!doc) {
|
|
1252
|
+
return null;
|
|
1253
|
+
}
|
|
1254
|
+
const editor = doc.getEditor?.();
|
|
1255
|
+
if (!editor) {
|
|
1256
|
+
return null;
|
|
1257
|
+
}
|
|
1258
|
+
const coreXml = editor.converter?.convertedXml?.["docProps/core.xml"];
|
|
1259
|
+
if (!coreXml?.elements?.[0]?.elements) {
|
|
1260
|
+
return null;
|
|
1261
|
+
}
|
|
1262
|
+
const elements = coreXml.elements[0].elements;
|
|
1263
|
+
const xmlToKey = {
|
|
1264
|
+
"dc:title": "title",
|
|
1265
|
+
"dc:creator": "author",
|
|
1266
|
+
"dc:subject": "subject",
|
|
1267
|
+
"dc:description": "description",
|
|
1268
|
+
"cp:keywords": "keywords",
|
|
1269
|
+
"cp:category": "category",
|
|
1270
|
+
"cp:lastModifiedBy": "lastModifiedBy",
|
|
1271
|
+
"cp:revision": "revision",
|
|
1272
|
+
"dcterms:created": "created",
|
|
1273
|
+
"dcterms:modified": "modified"
|
|
1274
|
+
};
|
|
1275
|
+
const props = {};
|
|
1276
|
+
for (const el of elements) {
|
|
1277
|
+
const key = xmlToKey[el.name];
|
|
1278
|
+
if (key) {
|
|
1279
|
+
const textValue = el.elements?.[0]?.text;
|
|
1280
|
+
if (textValue !== void 0 && textValue !== null) {
|
|
1281
|
+
if (key === "created" || key === "modified") {
|
|
1282
|
+
props[key] = new Date(textValue);
|
|
1283
|
+
} else {
|
|
1284
|
+
props[key] = textValue;
|
|
1285
|
+
}
|
|
1286
|
+
}
|
|
1287
|
+
}
|
|
1288
|
+
}
|
|
1289
|
+
return props;
|
|
1290
|
+
} catch (err) {
|
|
1291
|
+
console.warn("[DocxDiffEditor] Failed to get properties:", err);
|
|
1292
|
+
return null;
|
|
1293
|
+
}
|
|
1294
|
+
},
|
|
1295
|
+
/**
|
|
1296
|
+
* Set document core properties (partial update).
|
|
1297
|
+
* Only provided properties will be updated; others are preserved.
|
|
1298
|
+
* Preserves XML namespaces and structure for valid DOCX output.
|
|
1299
|
+
* Returns true on success, false on failure.
|
|
1300
|
+
*/
|
|
1301
|
+
async setProperties(properties) {
|
|
1302
|
+
if (!readyRef.current || !superdocRef.current) {
|
|
1303
|
+
return false;
|
|
1304
|
+
}
|
|
1305
|
+
try {
|
|
1306
|
+
const sd = superdocRef.current;
|
|
1307
|
+
const doc = sd.superdocStore?.documents?.[0];
|
|
1308
|
+
if (!doc) {
|
|
1309
|
+
return false;
|
|
1310
|
+
}
|
|
1311
|
+
const editor = doc.getEditor?.();
|
|
1312
|
+
if (!editor) {
|
|
1313
|
+
return false;
|
|
1314
|
+
}
|
|
1315
|
+
const coreXml = editor.converter?.convertedXml?.["docProps/core.xml"];
|
|
1316
|
+
if (!coreXml?.elements?.[0]?.elements) {
|
|
1317
|
+
console.warn("[DocxDiffEditor] docProps/core.xml not found or invalid structure");
|
|
1318
|
+
return false;
|
|
1319
|
+
}
|
|
1320
|
+
const coreProperties = coreXml.elements[0];
|
|
1321
|
+
const elements = coreProperties.elements;
|
|
1322
|
+
const keyToXml = {
|
|
1323
|
+
title: "dc:title",
|
|
1324
|
+
author: "dc:creator",
|
|
1325
|
+
subject: "dc:subject",
|
|
1326
|
+
description: "dc:description",
|
|
1327
|
+
keywords: "cp:keywords",
|
|
1328
|
+
category: "cp:category",
|
|
1329
|
+
lastModifiedBy: "cp:lastModifiedBy",
|
|
1330
|
+
revision: "cp:revision",
|
|
1331
|
+
created: "dcterms:created",
|
|
1332
|
+
modified: "dcterms:modified"
|
|
1333
|
+
};
|
|
1334
|
+
for (const [key, value] of Object.entries(properties)) {
|
|
1335
|
+
if (value === void 0) continue;
|
|
1336
|
+
const xmlName = keyToXml[key];
|
|
1337
|
+
if (!xmlName) continue;
|
|
1338
|
+
const textValue = value instanceof Date ? value.toISOString() : String(value);
|
|
1339
|
+
const existingProp = elements.find((el) => el.name === xmlName);
|
|
1340
|
+
if (existingProp) {
|
|
1341
|
+
if (!existingProp.elements) {
|
|
1342
|
+
existingProp.elements = [];
|
|
1343
|
+
}
|
|
1344
|
+
if (existingProp.elements[0]) {
|
|
1345
|
+
existingProp.elements[0].text = textValue;
|
|
1346
|
+
} else {
|
|
1347
|
+
existingProp.elements.push({ type: "text", text: textValue });
|
|
1348
|
+
}
|
|
1349
|
+
} else {
|
|
1350
|
+
elements.push({
|
|
1351
|
+
type: "element",
|
|
1352
|
+
name: xmlName,
|
|
1353
|
+
elements: [{ type: "text", text: textValue }]
|
|
1354
|
+
});
|
|
1355
|
+
}
|
|
1356
|
+
}
|
|
1357
|
+
if (editor.converter) {
|
|
1358
|
+
editor.converter.documentModified = true;
|
|
1359
|
+
}
|
|
1360
|
+
return true;
|
|
1361
|
+
} catch (err) {
|
|
1362
|
+
console.warn("[DocxDiffEditor] Failed to set properties:", err);
|
|
1363
|
+
return false;
|
|
1364
|
+
}
|
|
1239
1365
|
}
|
|
1240
1366
|
}),
|
|
1241
1367
|
[
|