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/dist/index.mjs CHANGED
@@ -460,6 +460,76 @@ function isProseMirrorJSON(content) {
460
460
  const obj = content;
461
461
  return typeof obj.type === "string" && (obj.type === "doc" || Array.isArray(obj.content));
462
462
  }
463
+ async function parseHtmlToJson(html, SuperDoc) {
464
+ const container = document.createElement("div");
465
+ container.style.cssText = "position:absolute;top:-9999px;left:-9999px;width:800px;height:600px;visibility:hidden;";
466
+ document.body.appendChild(container);
467
+ return new Promise((resolve, reject) => {
468
+ let superdoc = null;
469
+ let resolved = false;
470
+ const cleanup = () => {
471
+ setTimeout(() => {
472
+ if (superdoc) {
473
+ try {
474
+ const sd = superdoc;
475
+ superdoc = null;
476
+ sd.destroy?.();
477
+ } catch {
478
+ }
479
+ }
480
+ if (container.parentNode) {
481
+ container.parentNode.removeChild(container);
482
+ }
483
+ }, TIMEOUTS.CLEANUP_DELAY);
484
+ };
485
+ setTimeout(async () => {
486
+ if (resolved) return;
487
+ try {
488
+ superdoc = new SuperDoc({
489
+ selector: container,
490
+ html,
491
+ documentMode: "viewing",
492
+ rulers: false,
493
+ user: { name: "Parser", email: "parser@local" },
494
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
495
+ onReady: ({ superdoc: sd }) => {
496
+ if (resolved) return;
497
+ try {
498
+ const editor = sd?.activeEditor;
499
+ if (!editor) {
500
+ throw new Error("No active editor found");
501
+ }
502
+ const json = editor.getJSON();
503
+ resolved = true;
504
+ cleanup();
505
+ resolve(json);
506
+ } catch (err) {
507
+ resolved = true;
508
+ cleanup();
509
+ reject(err);
510
+ }
511
+ },
512
+ onException: ({ error: err }) => {
513
+ if (resolved) return;
514
+ resolved = true;
515
+ cleanup();
516
+ reject(err);
517
+ }
518
+ });
519
+ setTimeout(() => {
520
+ if (!resolved) {
521
+ resolved = true;
522
+ cleanup();
523
+ reject(new Error("HTML parsing timed out"));
524
+ }
525
+ }, TIMEOUTS.PARSE_TIMEOUT);
526
+ } catch (err) {
527
+ cleanup();
528
+ reject(err);
529
+ }
530
+ }, 50);
531
+ });
532
+ }
463
533
  async function parseDocxFile(file, SuperDoc) {
464
534
  const container = document.createElement("div");
465
535
  container.style.cssText = "position:absolute;top:-9999px;left:-9999px;width:800px;height:600px;visibility:hidden;";
@@ -2865,6 +2935,16 @@ var DocxDiffEditor = forwardRef(
2865
2935
  console.warn("[DocxDiffEditor] Failed to set properties:", err);
2866
2936
  return false;
2867
2937
  }
2938
+ },
2939
+ /**
2940
+ * Parse HTML string to ProseMirror JSON using a hidden SuperDoc instance.
2941
+ * Useful for converting HTML content before using with other methods.
2942
+ */
2943
+ async parseHtml(html) {
2944
+ if (!SuperDocRef.current) {
2945
+ throw new Error("Editor not initialized");
2946
+ }
2947
+ return parseHtmlToJson(html, SuperDocRef.current);
2868
2948
  }
2869
2949
  }),
2870
2950
  [
@@ -2982,6 +3062,6 @@ function isValidDocxFile(file) {
2982
3062
  return validTypes.includes(file.type) || file.name.endsWith(".docx");
2983
3063
  }
2984
3064
 
2985
- export { CSS_PREFIX, DEFAULT_AUTHOR, DEFAULT_SUPERDOC_USER, DocxDiffEditor, StructuralChangesPane, alignDocuments, createTrackDeleteMark, createTrackFormatMark, createTrackInsertMark, DocxDiffEditor_default as default, detectContentType, diffDocuments, diffImages, diffLists, diffTables, extractEnrichedChanges, extractEnrichedChangesWithStructural, generateFingerprint, generateStructuralChangeSummary, getBlankTemplateBlob, getBlankTemplateFile, isAtomicNode, isImage, isList, isProseMirrorJSON, isTable, isValidDocxFile, mergeDocuments, parseDocxFile, processStructuralChanges };
3065
+ export { CSS_PREFIX, DEFAULT_AUTHOR, DEFAULT_SUPERDOC_USER, DocxDiffEditor, StructuralChangesPane, alignDocuments, createTrackDeleteMark, createTrackFormatMark, createTrackInsertMark, DocxDiffEditor_default as default, detectContentType, diffDocuments, diffImages, diffLists, diffTables, extractEnrichedChanges, extractEnrichedChangesWithStructural, generateFingerprint, generateStructuralChangeSummary, getBlankTemplateBlob, getBlankTemplateFile, isAtomicNode, isImage, isList, isProseMirrorJSON, isTable, isValidDocxFile, mergeDocuments, parseDocxFile, parseHtmlToJson, processStructuralChanges };
2986
3066
  //# sourceMappingURL=index.mjs.map
2987
3067
  //# sourceMappingURL=index.mjs.map