docx-diff-editor 1.0.41 → 1.0.42
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 +20 -0
- package/dist/index.d.mts +7 -1
- package/dist/index.d.ts +7 -1
- package/dist/index.js +81 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +81 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -149,6 +149,9 @@ interface DocxDiffEditorRef {
|
|
|
149
149
|
|
|
150
150
|
// Set document core properties (partial update)
|
|
151
151
|
setProperties(properties: Partial<DocumentProperties>): Promise<boolean>;
|
|
152
|
+
|
|
153
|
+
// Parse HTML to ProseMirror JSON
|
|
154
|
+
parseHtml(html: string): Promise<ProseMirrorJSON>;
|
|
152
155
|
}
|
|
153
156
|
```
|
|
154
157
|
|
|
@@ -251,6 +254,23 @@ await editorRef.current?.setProperties({
|
|
|
251
254
|
});
|
|
252
255
|
```
|
|
253
256
|
|
|
257
|
+
## Parsing HTML to JSON
|
|
258
|
+
|
|
259
|
+
Convert HTML strings to ProseMirror JSON without visible rendering:
|
|
260
|
+
|
|
261
|
+
```tsx
|
|
262
|
+
// Using the ref method (requires editor to be initialized)
|
|
263
|
+
const json = await editorRef.current?.parseHtml('<h1>Title</h1><p>Content here</p>');
|
|
264
|
+
console.log(json); // { type: 'doc', content: [...] }
|
|
265
|
+
|
|
266
|
+
// Use with other methods
|
|
267
|
+
await editorRef.current?.updateContent(json);
|
|
268
|
+
|
|
269
|
+
// Or use the standalone function (requires SuperDoc class)
|
|
270
|
+
import { parseHtmlToJson } from 'docx-diff-editor';
|
|
271
|
+
const json = await parseHtmlToJson(htmlString, SuperDocClass);
|
|
272
|
+
```
|
|
273
|
+
|
|
254
274
|
## Customization
|
|
255
275
|
|
|
256
276
|
### CSS Variables
|
package/dist/index.d.mts
CHANGED
|
@@ -362,6 +362,8 @@ interface DocxDiffEditorRef {
|
|
|
362
362
|
getProperties(): Promise<DocumentProperties | null>;
|
|
363
363
|
/** Set document core properties (partial update) */
|
|
364
364
|
setProperties(properties: Partial<DocumentProperties>): Promise<boolean>;
|
|
365
|
+
/** Parse HTML string to ProseMirror JSON (uses hidden SuperDoc instance) */
|
|
366
|
+
parseHtml(html: string): Promise<ProseMirrorJSON>;
|
|
365
367
|
}
|
|
366
368
|
|
|
367
369
|
/**
|
|
@@ -420,6 +422,10 @@ declare function detectContentType(content: DocxContent): 'file' | 'html' | 'jso
|
|
|
420
422
|
* Validate that content looks like ProseMirror JSON
|
|
421
423
|
*/
|
|
422
424
|
declare function isProseMirrorJSON(content: unknown): boolean;
|
|
425
|
+
/**
|
|
426
|
+
* Parse an HTML string into ProseMirror JSON using a hidden SuperDoc instance.
|
|
427
|
+
*/
|
|
428
|
+
declare function parseHtmlToJson(html: string, SuperDoc: SuperDocConstructor): Promise<ProseMirrorJSON>;
|
|
423
429
|
/**
|
|
424
430
|
* Parse a DOCX File into ProseMirror JSON using a hidden SuperDoc instance.
|
|
425
431
|
*/
|
|
@@ -710,4 +716,4 @@ declare function getBlankTemplateBlob(): Blob;
|
|
|
710
716
|
*/
|
|
711
717
|
declare function isValidDocxFile(file: File): boolean;
|
|
712
718
|
|
|
713
|
-
export { type AttrDiff, type AttributeChange, 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 FingerprintedNode, type FormatChange, type FormatDetails, type HybridDiffResult, type NodeMatch, type ProseMirrorJSON, type ProseMirrorMark, type ProseMirrorNode, type StructuralChange, type StructuralChangeInfo, type StructuralChangeType, StructuralChangesPane, type StructuralPanePosition, type TrackChangeAuthor, alignDocuments, createTrackDeleteMark, createTrackFormatMark, createTrackInsertMark, DocxDiffEditor as default, detectContentType, diffDocuments, diffImages, diffLists, diffTables, extractEnrichedChanges, extractEnrichedChangesWithStructural, generateFingerprint, generateStructuralChangeSummary, getBlankTemplateBlob, getBlankTemplateFile, isAtomicNode, isImage, isList, isProseMirrorJSON, isTable, isValidDocxFile, mergeDocuments, parseDocxFile, processStructuralChanges };
|
|
719
|
+
export { type AttrDiff, type AttributeChange, 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 FingerprintedNode, type FormatChange, type FormatDetails, type HybridDiffResult, type NodeMatch, type ProseMirrorJSON, type ProseMirrorMark, type ProseMirrorNode, type StructuralChange, type StructuralChangeInfo, type StructuralChangeType, StructuralChangesPane, type StructuralPanePosition, type TrackChangeAuthor, alignDocuments, createTrackDeleteMark, createTrackFormatMark, createTrackInsertMark, DocxDiffEditor as default, detectContentType, diffDocuments, diffImages, diffLists, diffTables, extractEnrichedChanges, extractEnrichedChangesWithStructural, generateFingerprint, generateStructuralChangeSummary, getBlankTemplateBlob, getBlankTemplateFile, isAtomicNode, isImage, isList, isProseMirrorJSON, isTable, isValidDocxFile, mergeDocuments, parseDocxFile, parseHtmlToJson, processStructuralChanges };
|
package/dist/index.d.ts
CHANGED
|
@@ -362,6 +362,8 @@ interface DocxDiffEditorRef {
|
|
|
362
362
|
getProperties(): Promise<DocumentProperties | null>;
|
|
363
363
|
/** Set document core properties (partial update) */
|
|
364
364
|
setProperties(properties: Partial<DocumentProperties>): Promise<boolean>;
|
|
365
|
+
/** Parse HTML string to ProseMirror JSON (uses hidden SuperDoc instance) */
|
|
366
|
+
parseHtml(html: string): Promise<ProseMirrorJSON>;
|
|
365
367
|
}
|
|
366
368
|
|
|
367
369
|
/**
|
|
@@ -420,6 +422,10 @@ declare function detectContentType(content: DocxContent): 'file' | 'html' | 'jso
|
|
|
420
422
|
* Validate that content looks like ProseMirror JSON
|
|
421
423
|
*/
|
|
422
424
|
declare function isProseMirrorJSON(content: unknown): boolean;
|
|
425
|
+
/**
|
|
426
|
+
* Parse an HTML string into ProseMirror JSON using a hidden SuperDoc instance.
|
|
427
|
+
*/
|
|
428
|
+
declare function parseHtmlToJson(html: string, SuperDoc: SuperDocConstructor): Promise<ProseMirrorJSON>;
|
|
423
429
|
/**
|
|
424
430
|
* Parse a DOCX File into ProseMirror JSON using a hidden SuperDoc instance.
|
|
425
431
|
*/
|
|
@@ -710,4 +716,4 @@ declare function getBlankTemplateBlob(): Blob;
|
|
|
710
716
|
*/
|
|
711
717
|
declare function isValidDocxFile(file: File): boolean;
|
|
712
718
|
|
|
713
|
-
export { type AttrDiff, type AttributeChange, 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 FingerprintedNode, type FormatChange, type FormatDetails, type HybridDiffResult, type NodeMatch, type ProseMirrorJSON, type ProseMirrorMark, type ProseMirrorNode, type StructuralChange, type StructuralChangeInfo, type StructuralChangeType, StructuralChangesPane, type StructuralPanePosition, type TrackChangeAuthor, alignDocuments, createTrackDeleteMark, createTrackFormatMark, createTrackInsertMark, DocxDiffEditor as default, detectContentType, diffDocuments, diffImages, diffLists, diffTables, extractEnrichedChanges, extractEnrichedChangesWithStructural, generateFingerprint, generateStructuralChangeSummary, getBlankTemplateBlob, getBlankTemplateFile, isAtomicNode, isImage, isList, isProseMirrorJSON, isTable, isValidDocxFile, mergeDocuments, parseDocxFile, processStructuralChanges };
|
|
719
|
+
export { type AttrDiff, type AttributeChange, 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 FingerprintedNode, type FormatChange, type FormatDetails, type HybridDiffResult, type NodeMatch, type ProseMirrorJSON, type ProseMirrorMark, type ProseMirrorNode, type StructuralChange, type StructuralChangeInfo, type StructuralChangeType, StructuralChangesPane, type StructuralPanePosition, type TrackChangeAuthor, alignDocuments, createTrackDeleteMark, createTrackFormatMark, createTrackInsertMark, DocxDiffEditor as default, detectContentType, diffDocuments, diffImages, diffLists, diffTables, extractEnrichedChanges, extractEnrichedChangesWithStructural, generateFingerprint, generateStructuralChangeSummary, getBlankTemplateBlob, getBlankTemplateFile, isAtomicNode, isImage, isList, isProseMirrorJSON, isTable, isValidDocxFile, mergeDocuments, parseDocxFile, parseHtmlToJson, processStructuralChanges };
|
package/dist/index.js
CHANGED
|
@@ -468,6 +468,76 @@ function isProseMirrorJSON(content) {
|
|
|
468
468
|
const obj = content;
|
|
469
469
|
return typeof obj.type === "string" && (obj.type === "doc" || Array.isArray(obj.content));
|
|
470
470
|
}
|
|
471
|
+
async function parseHtmlToJson(html, SuperDoc) {
|
|
472
|
+
const container = document.createElement("div");
|
|
473
|
+
container.style.cssText = "position:absolute;top:-9999px;left:-9999px;width:800px;height:600px;visibility:hidden;";
|
|
474
|
+
document.body.appendChild(container);
|
|
475
|
+
return new Promise((resolve, reject) => {
|
|
476
|
+
let superdoc = null;
|
|
477
|
+
let resolved = false;
|
|
478
|
+
const cleanup = () => {
|
|
479
|
+
setTimeout(() => {
|
|
480
|
+
if (superdoc) {
|
|
481
|
+
try {
|
|
482
|
+
const sd = superdoc;
|
|
483
|
+
superdoc = null;
|
|
484
|
+
sd.destroy?.();
|
|
485
|
+
} catch {
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
if (container.parentNode) {
|
|
489
|
+
container.parentNode.removeChild(container);
|
|
490
|
+
}
|
|
491
|
+
}, TIMEOUTS.CLEANUP_DELAY);
|
|
492
|
+
};
|
|
493
|
+
setTimeout(async () => {
|
|
494
|
+
if (resolved) return;
|
|
495
|
+
try {
|
|
496
|
+
superdoc = new SuperDoc({
|
|
497
|
+
selector: container,
|
|
498
|
+
html,
|
|
499
|
+
documentMode: "viewing",
|
|
500
|
+
rulers: false,
|
|
501
|
+
user: { name: "Parser", email: "parser@local" },
|
|
502
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
503
|
+
onReady: ({ superdoc: sd }) => {
|
|
504
|
+
if (resolved) return;
|
|
505
|
+
try {
|
|
506
|
+
const editor = sd?.activeEditor;
|
|
507
|
+
if (!editor) {
|
|
508
|
+
throw new Error("No active editor found");
|
|
509
|
+
}
|
|
510
|
+
const json = editor.getJSON();
|
|
511
|
+
resolved = true;
|
|
512
|
+
cleanup();
|
|
513
|
+
resolve(json);
|
|
514
|
+
} catch (err) {
|
|
515
|
+
resolved = true;
|
|
516
|
+
cleanup();
|
|
517
|
+
reject(err);
|
|
518
|
+
}
|
|
519
|
+
},
|
|
520
|
+
onException: ({ error: err }) => {
|
|
521
|
+
if (resolved) return;
|
|
522
|
+
resolved = true;
|
|
523
|
+
cleanup();
|
|
524
|
+
reject(err);
|
|
525
|
+
}
|
|
526
|
+
});
|
|
527
|
+
setTimeout(() => {
|
|
528
|
+
if (!resolved) {
|
|
529
|
+
resolved = true;
|
|
530
|
+
cleanup();
|
|
531
|
+
reject(new Error("HTML parsing timed out"));
|
|
532
|
+
}
|
|
533
|
+
}, TIMEOUTS.PARSE_TIMEOUT);
|
|
534
|
+
} catch (err) {
|
|
535
|
+
cleanup();
|
|
536
|
+
reject(err);
|
|
537
|
+
}
|
|
538
|
+
}, 50);
|
|
539
|
+
});
|
|
540
|
+
}
|
|
471
541
|
async function parseDocxFile(file, SuperDoc) {
|
|
472
542
|
const container = document.createElement("div");
|
|
473
543
|
container.style.cssText = "position:absolute;top:-9999px;left:-9999px;width:800px;height:600px;visibility:hidden;";
|
|
@@ -2873,6 +2943,16 @@ var DocxDiffEditor = react.forwardRef(
|
|
|
2873
2943
|
console.warn("[DocxDiffEditor] Failed to set properties:", err);
|
|
2874
2944
|
return false;
|
|
2875
2945
|
}
|
|
2946
|
+
},
|
|
2947
|
+
/**
|
|
2948
|
+
* Parse HTML string to ProseMirror JSON using a hidden SuperDoc instance.
|
|
2949
|
+
* Useful for converting HTML content before using with other methods.
|
|
2950
|
+
*/
|
|
2951
|
+
async parseHtml(html) {
|
|
2952
|
+
if (!SuperDocRef.current) {
|
|
2953
|
+
throw new Error("Editor not initialized");
|
|
2954
|
+
}
|
|
2955
|
+
return parseHtmlToJson(html, SuperDocRef.current);
|
|
2876
2956
|
}
|
|
2877
2957
|
}),
|
|
2878
2958
|
[
|
|
@@ -3019,6 +3099,7 @@ exports.isTable = isTable;
|
|
|
3019
3099
|
exports.isValidDocxFile = isValidDocxFile;
|
|
3020
3100
|
exports.mergeDocuments = mergeDocuments;
|
|
3021
3101
|
exports.parseDocxFile = parseDocxFile;
|
|
3102
|
+
exports.parseHtmlToJson = parseHtmlToJson;
|
|
3022
3103
|
exports.processStructuralChanges = processStructuralChanges;
|
|
3023
3104
|
//# sourceMappingURL=index.js.map
|
|
3024
3105
|
//# sourceMappingURL=index.js.map
|