superdoc 1.0.0-beta.15 → 1.0.0-beta.17

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.
Files changed (29) hide show
  1. package/dist/chunks/{PdfViewer-DltPlBWC.cjs → PdfViewer-BIlJaTm7.cjs} +1 -1
  2. package/dist/chunks/{PdfViewer-CjlHzt9e.es.js → PdfViewer-cvzMUtBh.es.js} +1 -1
  3. package/dist/chunks/{index-qg0AxQJC.es.js → index-CrIfBvBN.es.js} +3 -3
  4. package/dist/chunks/{index-BZnlco_f.cjs → index-DDx90Dl3.cjs} +3 -3
  5. package/dist/chunks/{index-Bds7gW4r-JPDW6c39.cjs → index-VCeRjVPO-DjkejB6t.cjs} +1 -1
  6. package/dist/chunks/{index-Bds7gW4r-Pk_xAuWe.es.js → index-VCeRjVPO-FBgR9qxX.es.js} +1 -1
  7. package/dist/chunks/{super-editor.es-CQTkj_nb.es.js → super-editor.es-00SpI-wK.es.js} +1909 -273
  8. package/dist/chunks/{super-editor.es-CuAhqbzW.cjs → super-editor.es-Mlj7AGyt.cjs} +1909 -273
  9. package/dist/style.css +6 -6
  10. package/dist/super-editor/ai-writer.es.js +2 -2
  11. package/dist/super-editor/chunks/{converter-qMoZOGGn.js → converter-B9zUZjYT.js} +71 -34
  12. package/dist/super-editor/chunks/{docx-zipper-QKiyORxV.js → docx-zipper-r5KdE_SA.js} +1 -1
  13. package/dist/super-editor/chunks/{editor-D8ZdjC2V.js → editor-D2k2BwSG.js} +1743 -232
  14. package/dist/super-editor/chunks/{index-Bds7gW4r.js → index-VCeRjVPO.js} +1 -1
  15. package/dist/super-editor/chunks/{toolbar-Spi7vpev.js → toolbar-8o_LgoiW.js} +2 -2
  16. package/dist/super-editor/converter.es.js +1 -1
  17. package/dist/super-editor/docx-zipper.es.js +2 -2
  18. package/dist/super-editor/editor.es.js +3 -3
  19. package/dist/super-editor/file-zipper.es.js +1 -1
  20. package/dist/super-editor/style.css +6 -6
  21. package/dist/super-editor/super-editor.es.js +131 -42
  22. package/dist/super-editor/toolbar.es.js +2 -2
  23. package/dist/super-editor.cjs +1 -1
  24. package/dist/super-editor.es.js +1 -1
  25. package/dist/superdoc.cjs +2 -2
  26. package/dist/superdoc.es.js +2 -2
  27. package/dist/superdoc.umd.js +1911 -275
  28. package/dist/superdoc.umd.js.map +1 -1
  29. package/package.json +1 -1
@@ -19784,7 +19784,7 @@ function decodeRPrFromMarks(marks) {
19784
19784
  return runProperties;
19785
19785
  }
19786
19786
  marks.forEach((mark) => {
19787
- switch (mark.type) {
19787
+ switch (mark.type.name ?? mark.type) {
19788
19788
  case "strike":
19789
19789
  case "italic":
19790
19790
  case "bold":
@@ -20850,6 +20850,11 @@ const decode$q = (params2, decodedAttrs = {}) => {
20850
20850
  runs.push(trackedClone);
20851
20851
  return;
20852
20852
  }
20853
+ if (child.name === "w:commentRangeStart" || child.name === "w:commentRangeEnd") {
20854
+ const commentRangeClone = cloneXmlNode(child);
20855
+ runs.push(commentRangeClone);
20856
+ return;
20857
+ }
20853
20858
  const runWrapper = { name: XML_NODE_NAME$i, elements: [] };
20854
20859
  applyBaseRunProps(runWrapper);
20855
20860
  if (!Array.isArray(runWrapper.elements)) runWrapper.elements = [];
@@ -27975,9 +27980,11 @@ function updateNumberingProperties(newNumberingProperties, paragraphNode, pos, e
27975
27980
  const newAttrs = {
27976
27981
  ...paragraphNode.attrs,
27977
27982
  paragraphProperties: newProperties,
27978
- numberingProperties: newProperties.numberingProperties,
27979
- listRendering: null
27983
+ numberingProperties: newProperties.numberingProperties
27980
27984
  };
27985
+ if (!newNumberingProperties) {
27986
+ newAttrs.listRendering = null;
27987
+ }
27981
27988
  tr.setNodeMarkup(pos, null, newAttrs);
27982
27989
  }
27983
27990
  const generateNewListDefinition = ({ numId, listType, level, start: start2, text, fmt, editor }) => {
@@ -28509,13 +28516,36 @@ const handleDocxPaste = (html, editor, view) => {
28509
28516
  extractAndRemoveConditionalPrefix(item);
28510
28517
  });
28511
28518
  transformWordLists(tempDiv, editor);
28512
- const doc2 = DOMParser$1.fromSchema(editor.schema).parse(tempDiv);
28519
+ let doc2 = DOMParser$1.fromSchema(editor.schema).parse(tempDiv);
28520
+ doc2 = wrapTextsInRuns(doc2);
28513
28521
  tempDiv.remove();
28514
28522
  const { dispatch } = editor.view;
28515
28523
  if (!dispatch) return false;
28516
28524
  dispatch(view.state.tr.replaceSelectionWith(doc2, true));
28517
28525
  return true;
28518
28526
  };
28527
+ const wrapTextsInRuns = (doc2) => {
28528
+ const runType = doc2.type?.schema?.nodes?.run;
28529
+ if (!runType) return doc2;
28530
+ const wrapNode = (node, parent) => {
28531
+ if (node.isText) {
28532
+ if (parent?.type?.name === "run") return node;
28533
+ const runProperties = decodeRPrFromMarks(node.marks);
28534
+ return runType.create({ runProperties }, [node]);
28535
+ }
28536
+ if (!node.childCount) return node;
28537
+ let changed = false;
28538
+ const wrappedChildren = [];
28539
+ node.forEach((child) => {
28540
+ const wrappedChild = wrapNode(child, node);
28541
+ if (wrappedChild !== child) changed = true;
28542
+ wrappedChildren.push(wrappedChild);
28543
+ });
28544
+ if (!changed) return node;
28545
+ return node.copy(Fragment.fromArray(wrappedChildren));
28546
+ };
28547
+ return wrapNode(doc2, null);
28548
+ };
28519
28549
  const transformWordLists = (container, editor) => {
28520
28550
  const listItems = Array.from(container.querySelectorAll("[data-num-id]"));
28521
28551
  const lists = {};
@@ -28945,7 +28975,8 @@ const handleGoogleDocsHtml = (html, editor, view) => {
28945
28975
  tempDiv.innerHTML = cleanedHtml;
28946
28976
  const htmlWithMergedLists = mergeSeparateLists(tempDiv);
28947
28977
  const flattenHtml = flattenListsInHtml(htmlWithMergedLists, editor);
28948
- const doc2 = DOMParser$1.fromSchema(editor.schema).parse(flattenHtml);
28978
+ let doc2 = DOMParser$1.fromSchema(editor.schema).parse(flattenHtml);
28979
+ doc2 = wrapTextsInRuns(doc2);
28949
28980
  tempDiv.remove();
28950
28981
  const { dispatch } = editor.view;
28951
28982
  if (!dispatch) return false;
@@ -29278,7 +29309,8 @@ function isGoogleDocsHtml(html) {
29278
29309
  function handleHtmlPaste(html, editor, source) {
29279
29310
  let cleanedHtml;
29280
29311
  cleanedHtml = htmlHandler(html, editor);
29281
- const doc2 = DOMParser$1.fromSchema(editor.schema).parse(cleanedHtml);
29312
+ let doc2 = DOMParser$1.fromSchema(editor.schema).parse(cleanedHtml);
29313
+ doc2 = wrapTextsInRuns(doc2);
29282
29314
  const { dispatch, state: state2 } = editor.view;
29283
29315
  if (!dispatch) return false;
29284
29316
  const { $from } = state2.selection;
@@ -29383,7 +29415,9 @@ function createDocFromHTML(content, editor, options = {}) {
29383
29415
  } else {
29384
29416
  parsedContent = content;
29385
29417
  }
29386
- return DOMParser$1.fromSchema(editor.schema).parse(parsedContent);
29418
+ let doc2 = DOMParser$1.fromSchema(editor.schema).parse(parsedContent);
29419
+ doc2 = wrapTextsInRuns(doc2);
29420
+ return doc2;
29387
29421
  }
29388
29422
  function L() {
29389
29423
  return { async: false, breaks: false, extensions: null, gfm: true, hooks: null, pedantic: false, renderer: null, silent: false, tokenizer: null, walkTokens: null };
@@ -30507,9 +30541,11 @@ function processContent({ content, type: type2, editor }) {
30507
30541
  para.textContent = content;
30508
30542
  wrapper.appendChild(para);
30509
30543
  doc2 = DOMParser$1.fromSchema(editor.schema).parse(wrapper);
30544
+ doc2 = wrapTextsInRuns(doc2);
30510
30545
  break;
30511
30546
  case "schema":
30512
30547
  doc2 = editor.schema.nodeFromJSON(content);
30548
+ doc2 = wrapTextsInRuns(doc2);
30513
30549
  break;
30514
30550
  default:
30515
30551
  throw new Error(`Unknown content type: ${type2}`);
@@ -36266,7 +36302,7 @@ const _SuperConverter = class _SuperConverter2 {
36266
36302
  static getStoredSuperdocVersion(docx) {
36267
36303
  return _SuperConverter2.getStoredCustomProperty(docx, "SuperdocVersion");
36268
36304
  }
36269
- static setStoredSuperdocVersion(docx = this.convertedXml, version2 = "1.0.0-beta.15") {
36305
+ static setStoredSuperdocVersion(docx = this.convertedXml, version2 = "1.0.0-beta.17") {
36270
36306
  return _SuperConverter2.setStoredCustomProperty(docx, "SuperdocVersion", version2, false);
36271
36307
  }
36272
36308
  /**
@@ -47677,6 +47713,83 @@ const insertTabChar = () => ({ tr }) => {
47677
47713
  tr.insertText(" ", tr.selection.from, tr.selection.to);
47678
47714
  return true;
47679
47715
  };
47716
+ const splitRunToParagraph = () => (props) => {
47717
+ const { state: state2, view, tr } = props;
47718
+ const { $from, empty: empty2 } = state2.selection;
47719
+ if (!empty2) return false;
47720
+ if ($from.parent.type.name !== "run") return false;
47721
+ const handled = splitBlockPatch(state2, (transaction) => {
47722
+ view.dispatch(transaction);
47723
+ });
47724
+ if (handled) {
47725
+ tr.setMeta("preventDispatch", true);
47726
+ }
47727
+ return handled;
47728
+ };
47729
+ function splitBlockPatch(state2, dispatch) {
47730
+ let { $from } = state2.selection;
47731
+ if (state2.selection instanceof NodeSelection && state2.selection.node.isBlock) {
47732
+ if (!$from.parentOffset || !canSplit(state2.doc, $from.pos)) return false;
47733
+ if (dispatch) dispatch(state2.tr.split($from.pos).scrollIntoView());
47734
+ return true;
47735
+ }
47736
+ if (!$from.depth) return false;
47737
+ let types2 = [];
47738
+ let splitDepth, deflt, atEnd = false, atStart = false;
47739
+ for (let d2 = $from.depth; ; d2--) {
47740
+ let node = $from.node(d2);
47741
+ if (node.isBlock) {
47742
+ atEnd = $from.end(d2) == $from.pos + ($from.depth - d2);
47743
+ atStart = $from.start(d2) == $from.pos - ($from.depth - d2);
47744
+ deflt = defaultBlockAt$1($from.node(d2 - 1).contentMatchAt($from.indexAfter(d2 - 1)));
47745
+ types2.unshift(null);
47746
+ splitDepth = d2;
47747
+ break;
47748
+ } else {
47749
+ if (d2 == 1) return false;
47750
+ types2.unshift(null);
47751
+ }
47752
+ }
47753
+ let tr = state2.tr;
47754
+ if (state2.selection instanceof TextSelection$1 || state2.selection instanceof AllSelection) tr.deleteSelection();
47755
+ let splitPos = tr.mapping.map($from.pos);
47756
+ let can = canSplit(tr.doc, splitPos, types2.length, types2);
47757
+ if (!can) {
47758
+ types2[0] = deflt ? { type: deflt } : null;
47759
+ can = canSplit(tr.doc, splitPos, types2.length, types2);
47760
+ }
47761
+ if (!can) return false;
47762
+ tr.split(splitPos, types2.length, types2);
47763
+ if (!atEnd && atStart && $from.node(splitDepth).type != deflt) {
47764
+ let first2 = tr.mapping.map($from.before(splitDepth)), $first = tr.doc.resolve(first2);
47765
+ if (deflt && $from.node(splitDepth - 1).canReplaceWith($first.index(), $first.index() + 1, deflt))
47766
+ tr.setNodeMarkup(tr.mapping.map($from.before(splitDepth)), deflt);
47767
+ }
47768
+ if (dispatch) dispatch(tr.scrollIntoView());
47769
+ return true;
47770
+ }
47771
+ const splitRunAtCursor = () => (props) => {
47772
+ let { state: state2, dispatch, tr } = props;
47773
+ const sel = state2.selection;
47774
+ if (!sel.empty) return false;
47775
+ const $pos = sel.$from;
47776
+ const runType = state2.schema.nodes.run;
47777
+ if ($pos.parent.type !== runType) return false;
47778
+ const run2 = $pos.parent;
47779
+ const offset2 = $pos.parentOffset;
47780
+ const runStart = $pos.before();
47781
+ const runEnd = runStart + run2.nodeSize;
47782
+ const leftFrag = run2.content.cut(0, offset2);
47783
+ const rightFrag = run2.content.cut(offset2);
47784
+ const leftRun = runType.create(run2.attrs, leftFrag, run2.marks);
47785
+ const rightRun = runType.create(run2.attrs, rightFrag, run2.marks);
47786
+ const gapPos = runStart + leftRun.nodeSize;
47787
+ tr.replaceWith(runStart, runEnd, [leftRun, rightRun]).setSelection(TextSelection$1.create(tr.doc, gapPos));
47788
+ if (dispatch) {
47789
+ dispatch(tr);
47790
+ }
47791
+ return true;
47792
+ };
47680
47793
  const insertTabCharacter = ({ tr, state: state2, dispatch }) => {
47681
47794
  const { from: from2 } = tr.selection;
47682
47795
  const tabText = state2.schema.text(" ");
@@ -47686,10 +47799,23 @@ const insertTabCharacter = ({ tr, state: state2, dispatch }) => {
47686
47799
  return true;
47687
47800
  };
47688
47801
  const insertTabNode = () => ({ tr, state: state2, dispatch }) => {
47689
- const newPos = tr.selection.from;
47802
+ let newPos = tr.selection.from;
47690
47803
  const tabNode = state2.schema?.nodes?.tab?.create();
47691
47804
  if (!tabNode) return insertTabCharacter({ tr, state: state2, dispatch });
47805
+ const { from: from2 } = tr.selection;
47806
+ const $pos = tr.doc.resolve(from2);
47807
+ if ($pos.parent.type === state2.schema.nodes.run) {
47808
+ if (from2 === $pos.end()) {
47809
+ newPos = $pos.end() + 1;
47810
+ } else if (from2 === $pos.start()) {
47811
+ newPos = $pos.start() - 1;
47812
+ } else {
47813
+ splitRunAtCursor()({ tr, state: state2 });
47814
+ newPos = tr.selection.from;
47815
+ }
47816
+ }
47692
47817
  tr.insert(newPos, tabNode);
47818
+ tr = tr.setSelection(TextSelection$1.create(tr.doc, newPos + tabNode.nodeSize));
47693
47819
  if (dispatch) dispatch(tr);
47694
47820
  return true;
47695
47821
  };
@@ -49145,6 +49271,139 @@ const unsetLineHeight = () => ({ commands: commands2 }) => {
49145
49271
  "paragraphProperties.spacing.lineRule"
49146
49272
  );
49147
49273
  };
49274
+ const backspaceEmptyRunParagraph = () => ({ state: state2, dispatch }) => {
49275
+ const { $from } = state2.selection;
49276
+ if (!state2.selection.empty) return false;
49277
+ const paraType = state2.schema.nodes.paragraph;
49278
+ const runType = state2.schema.nodes.run;
49279
+ const para = $from.parent;
49280
+ if (para.type !== paraType || para.childCount !== 1 || para.firstChild.type !== runType || para.firstChild.content.size)
49281
+ return false;
49282
+ if (state2.doc.childCount === 1 && $from.depth === 1) return false;
49283
+ if (dispatch) {
49284
+ const paraPos = $from.before();
49285
+ let tr = state2.tr.deleteRange(paraPos, paraPos + para.nodeSize).scrollIntoView();
49286
+ const targetPos = Math.max(1, Math.min(paraPos - 1, tr.doc.content.size));
49287
+ tr = tr.setSelection(TextSelection$1.create(tr.doc, targetPos));
49288
+ dispatch(tr);
49289
+ }
49290
+ return true;
49291
+ };
49292
+ const backspaceSkipEmptyRun = () => ({ state: state2, dispatch }) => {
49293
+ const sel = state2.selection;
49294
+ if (!sel.empty) return false;
49295
+ const runType = state2.schema.nodes.run;
49296
+ const $pos = sel.$from;
49297
+ const emptyRun = (n) => n && n.type === runType && n.content.size === 0;
49298
+ if ($pos.parent.type !== runType || $pos.pos !== $pos.end() || !emptyRun(state2.doc.nodeAt($pos.pos + 1))) {
49299
+ return false;
49300
+ }
49301
+ const leftTextSel = Selection.findFrom($pos, -1, true);
49302
+ if (!leftTextSel) return false;
49303
+ const pos = leftTextSel.$from.pos;
49304
+ if (dispatch) {
49305
+ dispatch(state2.tr.delete(pos - 1, pos).scrollIntoView());
49306
+ }
49307
+ return true;
49308
+ };
49309
+ const backspaceNextToRun = () => ({ state: state2, tr, dispatch }) => {
49310
+ const sel = state2.selection;
49311
+ if (!sel.empty) return false;
49312
+ const runType = state2.schema.nodes.run;
49313
+ const $pos = sel.$from;
49314
+ if ($pos.nodeBefore?.type !== runType && $pos.pos !== $pos.start()) return false;
49315
+ if ($pos.nodeBefore) {
49316
+ if ($pos.nodeBefore.content.size === 0) return false;
49317
+ tr.delete($pos.pos - 2, $pos.pos - 1).setSelection(Selection.near(tr.doc.resolve($pos.pos - 2)));
49318
+ if (dispatch) {
49319
+ dispatch(tr.scrollIntoView());
49320
+ }
49321
+ } else {
49322
+ const prevNode = state2.doc.resolve($pos.start() - 1).nodeBefore;
49323
+ if (prevNode?.type !== runType || prevNode.content.size === 0) return false;
49324
+ tr.delete($pos.pos - 3, $pos.pos - 2).setSelection(Selection.near(tr.doc.resolve($pos.pos - 3)));
49325
+ if (dispatch) {
49326
+ dispatch(tr.scrollIntoView());
49327
+ }
49328
+ }
49329
+ return true;
49330
+ };
49331
+ const deleteSkipEmptyRun = () => ({ state: state2, dispatch }) => {
49332
+ const sel = state2.selection;
49333
+ if (!sel.empty) return false;
49334
+ const runType = state2.schema.nodes.run;
49335
+ const $pos = sel.$from;
49336
+ const emptyRun = (n) => n && n.type === runType && n.content.size === 0;
49337
+ if ($pos.parent.type === runType && emptyRun(state2.doc.nodeAt($pos.end() + 1))) {
49338
+ if ($pos.pos === $pos.end()) {
49339
+ return deleteFromEndOfRun(state2, dispatch, $pos);
49340
+ } else if ($pos.pos === $pos.end() - 1) {
49341
+ return deleteFromLastCharacter(state2, dispatch, $pos);
49342
+ }
49343
+ return false;
49344
+ }
49345
+ return false;
49346
+ };
49347
+ function deleteFromEndOfRun(state2, dispatch, $pos) {
49348
+ const rightRun = state2.doc.nodeAt($pos.pos + 1);
49349
+ const $afterRightRunPos = state2.doc.resolve($pos.pos + 2 + rightRun.nodeSize);
49350
+ const rightTextSel = Selection.findFrom($afterRightRunPos, 1, true);
49351
+ if (!rightTextSel) return false;
49352
+ const pos = rightTextSel.$from.pos;
49353
+ if (dispatch) {
49354
+ dispatch(state2.tr.delete(pos, pos + 1).scrollIntoView());
49355
+ }
49356
+ return true;
49357
+ }
49358
+ function deleteFromLastCharacter(state2, dispatch, $pos) {
49359
+ if (dispatch) {
49360
+ dispatch(state2.tr.delete($pos.pos, $pos.pos + 1).scrollIntoView());
49361
+ }
49362
+ return true;
49363
+ }
49364
+ const deleteNextToRun = () => ({ state: state2, tr, dispatch }) => {
49365
+ const sel = state2.selection;
49366
+ if (!sel.empty) return false;
49367
+ const runType = state2.schema.nodes.run;
49368
+ const $pos = sel.$from;
49369
+ if ($pos.nodeAfter?.type !== runType && $pos.pos !== $pos.end()) return false;
49370
+ if ($pos.nodeAfter) {
49371
+ if ($pos.nodeAfter.content.size === 0) return false;
49372
+ tr.delete($pos.pos + 1, $pos.pos + 2).setSelection(Selection.near(tr.doc.resolve($pos.pos + 1)));
49373
+ if (dispatch) {
49374
+ dispatch(tr.scrollIntoView());
49375
+ }
49376
+ } else {
49377
+ const nextNode = state2.doc.resolve($pos.end() + 1).nodeAfter;
49378
+ if (nextNode?.type !== runType || nextNode.content.size === 0) return false;
49379
+ tr.delete($pos.pos + 2, $pos.pos + 3).setSelection(Selection.near(tr.doc.resolve($pos.pos + 2)));
49380
+ if (dispatch) {
49381
+ dispatch(tr.scrollIntoView());
49382
+ }
49383
+ }
49384
+ return true;
49385
+ };
49386
+ function skipTab(dir) {
49387
+ return ({ state: state2, dispatch }) => {
49388
+ const tab = state2.schema.nodes.tab;
49389
+ const run2 = state2.schema.nodes.run;
49390
+ const sel = state2.selection;
49391
+ if (!tab || !sel.empty) return false;
49392
+ const $pos = sel.$from;
49393
+ if ($pos.parent.type !== run2) return false;
49394
+ if (dir > 0 && $pos.pos < $pos.end()) return false;
49395
+ if (dir < 0 && $pos.pos > $pos.start()) return false;
49396
+ const step = dir > 0 ? 1 : -1;
49397
+ let $nextPos = state2.doc.resolve($pos.pos + step);
49398
+ const nextNode = dir > 0 ? $nextPos.nodeAfter : $nextPos.nodeBefore;
49399
+ if (!nextNode || nextNode.type !== tab) return false;
49400
+ const nextPos = dir > 0 ? Math.min($nextPos.pos + nextNode.nodeSize + 1, state2.doc.nodeSize) : Math.max(0, $nextPos.pos - nextNode.nodeSize - 1);
49401
+ if (dispatch) {
49402
+ dispatch(state2.tr.setSelection(TextSelection$1.create(state2.doc, nextPos)));
49403
+ }
49404
+ return true;
49405
+ };
49406
+ }
49148
49407
  const toggleList = (listType) => ({ editor, state: state2, tr, dispatch }) => {
49149
49408
  let predicate;
49150
49409
  if (listType === "orderedList") {
@@ -49220,6 +49479,13 @@ const toggleList = (listType) => ({ editor, state: state2, tr, dispatch }) => {
49220
49479
  }
49221
49480
  updateNumberingProperties(sharedNumberingProperties, node, pos, editor, tr);
49222
49481
  }
49482
+ const newTo = tr.mapping.map(to);
49483
+ if (newTo >= 0 && newTo <= tr.doc.content.size) {
49484
+ try {
49485
+ tr.setSelection(state2.selection.constructor.near(tr.doc.resolve(newTo)));
49486
+ } catch {
49487
+ }
49488
+ }
49223
49489
  if (dispatch) dispatch(tr);
49224
49490
  return true;
49225
49491
  };
@@ -49338,6 +49604,9 @@ const getSelectionMarks = () => ({ state: state2, tr }) => {
49338
49604
  };
49339
49605
  const commands$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
49340
49606
  __proto__: null,
49607
+ backspaceEmptyRunParagraph,
49608
+ backspaceNextToRun,
49609
+ backspaceSkipEmptyRun,
49341
49610
  changeListLevel,
49342
49611
  clearNodes,
49343
49612
  command,
@@ -49345,7 +49614,9 @@ const commands$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePr
49345
49614
  decreaseListIndent,
49346
49615
  decreaseTextIndent,
49347
49616
  defaultStyleDetector,
49617
+ deleteNextToRun,
49348
49618
  deleteSelection,
49619
+ deleteSkipEmptyRun,
49349
49620
  exitCode,
49350
49621
  first,
49351
49622
  getEffectiveStyleId,
@@ -49383,6 +49654,7 @@ const commands$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePr
49383
49654
  setSectionHeaderFooterAtSelection,
49384
49655
  setTextIndentation,
49385
49656
  setTextSelection,
49657
+ skipTab,
49386
49658
  splitBlock: splitBlock$1,
49387
49659
  toggleList,
49388
49660
  toggleMark,
@@ -49404,7 +49676,7 @@ const Commands = Extension.create({
49404
49676
  });
49405
49677
  const handleEnter = (editor) => {
49406
49678
  return editor.commands.first(({ commands: commands2 }) => [
49407
- () => commands2.splitRun(),
49679
+ () => commands2.splitRunToParagraph(),
49408
49680
  () => commands2.newlineInCode(),
49409
49681
  () => commands2.createParagraphNear(),
49410
49682
  () => commands2.liftEmptyBlock(),
@@ -49418,6 +49690,9 @@ const handleBackspace = (editor) => {
49418
49690
  tr.setMeta("inputType", "deleteContentBackward");
49419
49691
  return false;
49420
49692
  },
49693
+ () => commands2.backspaceEmptyRunParagraph(),
49694
+ () => commands2.backspaceSkipEmptyRun(),
49695
+ () => commands2.backspaceNextToRun(),
49421
49696
  () => commands2.deleteSelection(),
49422
49697
  () => commands2.removeNumberingProperties(),
49423
49698
  () => commands2.joinBackward(),
@@ -49426,6 +49701,8 @@ const handleBackspace = (editor) => {
49426
49701
  };
49427
49702
  const handleDelete = (editor) => {
49428
49703
  return editor.commands.first(({ commands: commands2 }) => [
49704
+ () => commands2.deleteSkipEmptyRun(),
49705
+ () => commands2.deleteNextToRun(),
49429
49706
  () => commands2.deleteSelection(),
49430
49707
  () => commands2.joinForward(),
49431
49708
  () => commands2.selectNodeForward()
@@ -49444,7 +49721,9 @@ const Keymap = Extension.create({
49444
49721
  Delete: () => handleDelete(this.editor),
49445
49722
  "Mod-Delete": () => handleDelete(this.editor),
49446
49723
  "Mod-a": () => this.editor.commands.selectAll(),
49447
- Tab: () => this.editor.commands.insertTabNode()
49724
+ Tab: () => this.editor.commands.insertTabNode(),
49725
+ ArrowLeft: () => this.editor.commands.skipTab(-1),
49726
+ ArrowRight: () => this.editor.commands.skipTab(1)
49448
49727
  };
49449
49728
  const pcBaseKeymap = {
49450
49729
  ...baseKeymap
@@ -52994,7 +53273,7 @@ const isHeadless = (editor) => {
52994
53273
  const shouldSkipNodeView = (editor) => {
52995
53274
  return isHeadless(editor);
52996
53275
  };
52997
- const summaryVersion = "1.0.0-beta.15";
53276
+ const summaryVersion = "1.0.0-beta.17";
52998
53277
  const nodeKeys = ["group", "content", "marks", "inline", "atom", "defining", "code", "tableRole", "summary"];
52999
53278
  const markKeys = ["group", "inclusive", "excludes", "spanning", "code"];
53000
53279
  function mapAttributes(attrs) {
@@ -53504,12 +53783,9 @@ const _Editor = class _Editor2 extends EventEmitter$1 {
53504
53783
  if (!this.schema) {
53505
53784
  throw new Error("Schema is not initialized.");
53506
53785
  }
53507
- const topNodeName = this.schema.topNodeType?.name || "doc";
53508
- const normalizedDoc = Array.isArray(doc2) ? { type: topNodeName, content: doc2 } : doc2 && typeof doc2 === "object" && doc2.type ? doc2.type === topNodeName || doc2.type === "doc" ? doc2 : { type: topNodeName, content: [doc2] } : (() => {
53509
- throw new Error("Invalid document shape: expected a node object or an array of node objects.");
53510
- })();
53511
53786
  try {
53512
- return this.schema.nodeFromJSON(normalizedDoc);
53787
+ if (Array.isArray(doc2)) return doc2.map((d2) => this.schema.nodeFromJSON(d2));
53788
+ return this.schema.nodeFromJSON(doc2);
53513
53789
  } catch (error) {
53514
53790
  const detail = error instanceof Error ? error.message : String(error);
53515
53791
  const validationError = new Error(`Invalid document for current schema: ${detail}`);
@@ -53773,7 +54049,7 @@ const _Editor = class _Editor2 extends EventEmitter$1 {
53773
54049
  { default: remarkStringify },
53774
54050
  { default: remarkGfm }
53775
54051
  ] = await Promise.all([
53776
- Promise.resolve().then(() => require("./index-Bds7gW4r-JPDW6c39.cjs")),
54052
+ Promise.resolve().then(() => require("./index-VCeRjVPO-DjkejB6t.cjs")),
53777
54053
  Promise.resolve().then(() => require("./index-DRCvimau-H4Ck3S9a.cjs")),
53778
54054
  Promise.resolve().then(() => require("./index-C_x_N6Uh-Db3CUJMX.cjs")),
53779
54055
  Promise.resolve().then(() => require("./index-D_sWOSiG-BtDZzJ6I.cjs")),
@@ -53978,7 +54254,7 @@ const _Editor = class _Editor2 extends EventEmitter$1 {
53978
54254
  * Process collaboration migrations
53979
54255
  */
53980
54256
  processCollaborationMigrations() {
53981
- console.debug("[checkVersionMigrations] Current editor version", "1.0.0-beta.15");
54257
+ console.debug("[checkVersionMigrations] Current editor version", "1.0.0-beta.17");
53982
54258
  if (!this.options.ydoc) return;
53983
54259
  const metaMap = this.options.ydoc.getMap("meta");
53984
54260
  let docVersion = metaMap.get("version");
@@ -55053,7 +55329,7 @@ const pickLang = (value) => {
55053
55329
  const normalized = value.trim().toLowerCase();
55054
55330
  return normalized || void 0;
55055
55331
  };
55056
- const normalizeColor = (value) => {
55332
+ const normalizeColor$1 = (value) => {
55057
55333
  if (typeof value !== "string") return void 0;
55058
55334
  const trimmed = value.trim();
55059
55335
  if (!trimmed || trimmed === "auto" || trimmed === "none") return void 0;
@@ -55693,14 +55969,14 @@ const resolveThemeColor = (attrs, themeColors) => {
55693
55969
  const resolveColorFromAttributes = (attrs, themeColors) => {
55694
55970
  if (!attrs) return void 0;
55695
55971
  if (typeof attrs.color === "string") {
55696
- const normalized = normalizeColor(attrs.color);
55972
+ const normalized = normalizeColor$1(attrs.color);
55697
55973
  if (normalized) {
55698
55974
  return normalized;
55699
55975
  }
55700
55976
  }
55701
55977
  const theme = resolveThemeColor(attrs, themeColors);
55702
55978
  if (theme) {
55703
- return normalizeColor(theme);
55979
+ return normalizeColor$1(theme);
55704
55980
  }
55705
55981
  return void 0;
55706
55982
  };
@@ -56135,13 +56411,8 @@ const MAX_BORDER_SIZE_PX = 100;
56135
56411
  const borderSizeToPx = (size2) => {
56136
56412
  if (!isFiniteNumber(size2)) return void 0;
56137
56413
  if (size2 <= 0) return 0;
56138
- let pixelValue;
56139
- if (size2 < EIGHTHS_PER_POINT) {
56140
- pixelValue = size2;
56141
- } else {
56142
- const points = size2 / EIGHTHS_PER_POINT;
56143
- pixelValue = points * PX_PER_PT;
56144
- }
56414
+ const points = size2 / EIGHTHS_PER_POINT;
56415
+ const pixelValue = points * PX_PER_PT;
56145
56416
  return Math.min(MAX_BORDER_SIZE_PX, Math.max(MIN_BORDER_SIZE_PX, pixelValue));
56146
56417
  };
56147
56418
  const normalizeColorWithDefault = (color) => {
@@ -56280,7 +56551,7 @@ const normalizeBorderSide = (value) => {
56280
56551
  if (style2 === "none") return void 0;
56281
56552
  const width = pickNumber(raw.size);
56282
56553
  const widthPx = borderSizeToPx(width);
56283
- const color = normalizeColor(raw.color);
56554
+ const color = normalizeColor$1(raw.color);
56284
56555
  const space = pickNumber(raw.space);
56285
56556
  if (!style2 && widthPx == null && space == null && !color) {
56286
56557
  return void 0;
@@ -56336,7 +56607,7 @@ const normalizeParagraphShading = (value) => {
56336
56607
  return Object.keys(shading).length > 0 ? shading : void 0;
56337
56608
  };
56338
56609
  const normalizeShadingColor = (value) => {
56339
- const normalized = normalizeColor(value);
56610
+ const normalized = normalizeColor$1(value);
56340
56611
  if (!normalized) return void 0;
56341
56612
  if (normalized.toLowerCase() === "#auto") {
56342
56613
  return void 0;
@@ -57499,11 +57770,11 @@ const buildMarkerLayout = ({
57499
57770
  baselineOffsetPx: markerRun.baselineShift ?? 0,
57500
57771
  gutterWidthPx: markerBoxWidthPx,
57501
57772
  justification: numbering.lvlJc ?? "left",
57502
- suffix: normalizeSuffix(numbering.suffix) ?? "tab",
57773
+ suffix: normalizeSuffix$1(numbering.suffix) ?? "tab",
57503
57774
  run: markerRun,
57504
57775
  path: numbering.path
57505
57776
  });
57506
- const normalizeSuffix = (suffix2) => {
57777
+ const normalizeSuffix$1 = (suffix2) => {
57507
57778
  if (suffix2 === "tab" || suffix2 === "space" || suffix2 === "nothing") {
57508
57779
  return suffix2;
57509
57780
  }
@@ -57957,6 +58228,154 @@ const cloneIfObject = (value) => {
57957
58228
  };
57958
58229
  const { resolveSpacingIndent } = Engines;
57959
58230
  const DEFAULT_DECIMAL_SEPARATOR$2 = ".";
58231
+ const asOoxmlElement = (value) => {
58232
+ if (!value || typeof value !== "object") return void 0;
58233
+ const element = value;
58234
+ if (element.name == null && element.attributes == null && element.elements == null) return void 0;
58235
+ return element;
58236
+ };
58237
+ const findChild = (parent, name) => {
58238
+ return parent?.elements?.find((child) => child?.name === name);
58239
+ };
58240
+ const getAttribute = (element, key2) => {
58241
+ if (!element?.attributes) return void 0;
58242
+ const attrs = element.attributes;
58243
+ return attrs[key2] ?? attrs[key2.startsWith("w:") ? key2.slice(2) : `w:${key2}`];
58244
+ };
58245
+ const parseNumberAttr = (value) => {
58246
+ if (value == null) return void 0;
58247
+ const num = typeof value === "number" ? value : Number.parseInt(String(value), 10);
58248
+ return Number.isFinite(num) ? num : void 0;
58249
+ };
58250
+ const normalizeNumFmt = (value) => {
58251
+ if (typeof value !== "string") return void 0;
58252
+ switch (value) {
58253
+ case "decimal":
58254
+ return "decimal";
58255
+ case "lowerLetter":
58256
+ return "lowerLetter";
58257
+ case "upperLetter":
58258
+ return "upperLetter";
58259
+ case "lowerRoman":
58260
+ return "lowerRoman";
58261
+ case "upperRoman":
58262
+ return "upperRoman";
58263
+ case "bullet":
58264
+ return "bullet";
58265
+ default:
58266
+ return void 0;
58267
+ }
58268
+ };
58269
+ const normalizeSuffix = (value) => {
58270
+ if (typeof value !== "string") return void 0;
58271
+ if (value === "tab" || value === "space" || value === "nothing") {
58272
+ return value;
58273
+ }
58274
+ return void 0;
58275
+ };
58276
+ const normalizeJustification = (value) => {
58277
+ if (typeof value !== "string") return void 0;
58278
+ if (value === "start") return "left";
58279
+ if (value === "end") return "right";
58280
+ if (value === "left" || value === "center" || value === "right") return value;
58281
+ return void 0;
58282
+ };
58283
+ const extractIndentFromLevel = (lvl) => {
58284
+ const pPr = findChild(lvl, "w:pPr");
58285
+ const ind = findChild(pPr, "w:ind");
58286
+ if (!ind) return void 0;
58287
+ const left2 = parseNumberAttr(getAttribute(ind, "w:left"));
58288
+ const right2 = parseNumberAttr(getAttribute(ind, "w:right"));
58289
+ const firstLine = parseNumberAttr(getAttribute(ind, "w:firstLine"));
58290
+ const hanging = parseNumberAttr(getAttribute(ind, "w:hanging"));
58291
+ const indent = {};
58292
+ if (left2 != null) indent.left = left2;
58293
+ if (right2 != null) indent.right = right2;
58294
+ if (firstLine != null) indent.firstLine = firstLine;
58295
+ if (hanging != null) indent.hanging = hanging;
58296
+ return Object.keys(indent).length ? indent : void 0;
58297
+ };
58298
+ const normalizeColor = (value) => {
58299
+ if (typeof value !== "string") return void 0;
58300
+ const trimmed = value.trim();
58301
+ if (!trimmed || trimmed.toLowerCase() === "auto") return void 0;
58302
+ const upper = trimmed.startsWith("#") ? trimmed.slice(1) : trimmed;
58303
+ return `#${upper.toUpperCase()}`;
58304
+ };
58305
+ const extractMarkerRun = (lvl) => {
58306
+ const rPr = findChild(lvl, "w:rPr");
58307
+ if (!rPr) return void 0;
58308
+ const run2 = {};
58309
+ const rFonts = findChild(rPr, "w:rFonts");
58310
+ const font = getAttribute(rFonts, "w:ascii") ?? getAttribute(rFonts, "w:hAnsi") ?? getAttribute(rFonts, "w:eastAsia");
58311
+ if (typeof font === "string" && font.trim()) {
58312
+ run2.fontFamily = font;
58313
+ }
58314
+ const sz = parseNumberAttr(getAttribute(findChild(rPr, "w:sz"), "w:val")) ?? parseNumberAttr(getAttribute(findChild(rPr, "w:szCs"), "w:val"));
58315
+ if (sz != null) {
58316
+ run2.fontSize = sz / 2;
58317
+ }
58318
+ const color = normalizeColor(getAttribute(findChild(rPr, "w:color"), "w:val"));
58319
+ if (color) run2.color = color;
58320
+ if (findChild(rPr, "w:b")) run2.bold = true;
58321
+ if (findChild(rPr, "w:i")) run2.italic = true;
58322
+ const spacingTwips = parseNumberAttr(getAttribute(findChild(rPr, "w:spacing"), "w:val"));
58323
+ if (spacingTwips != null && Number.isFinite(spacingTwips)) {
58324
+ run2.letterSpacing = twipsToPx$1(spacingTwips);
58325
+ }
58326
+ return Object.keys(run2).length ? run2 : void 0;
58327
+ };
58328
+ const findNumFmtElement = (lvl) => {
58329
+ if (!lvl) return void 0;
58330
+ const direct = findChild(lvl, "w:numFmt");
58331
+ if (direct) return direct;
58332
+ const alternate = findChild(lvl, "mc:AlternateContent");
58333
+ const choice = findChild(alternate, "mc:Choice");
58334
+ if (choice) {
58335
+ return findChild(choice, "w:numFmt");
58336
+ }
58337
+ return void 0;
58338
+ };
58339
+ const resolveNumberingFromContext = (numId, ilvl, numbering) => {
58340
+ const definitions = numbering?.definitions;
58341
+ const abstracts = numbering?.abstracts;
58342
+ if (!definitions || !abstracts) return void 0;
58343
+ const numDef = asOoxmlElement(definitions[String(numId)]);
58344
+ if (!numDef) return void 0;
58345
+ const abstractId = getAttribute(findChild(numDef, "w:abstractNumId"), "w:val");
58346
+ if (abstractId == null) return void 0;
58347
+ const abstract = asOoxmlElement(abstracts[String(abstractId)]);
58348
+ if (!abstract) return void 0;
58349
+ let levelDef = abstract.elements?.find(
58350
+ (el) => el?.name === "w:lvl" && parseNumberAttr(el.attributes?.["w:ilvl"]) === ilvl
58351
+ );
58352
+ const override = numDef.elements?.find(
58353
+ (el) => el?.name === "w:lvlOverride" && parseNumberAttr(el.attributes?.["w:ilvl"]) === ilvl
58354
+ );
58355
+ const overrideLvl = findChild(override, "w:lvl");
58356
+ if (overrideLvl) {
58357
+ levelDef = overrideLvl;
58358
+ }
58359
+ const startOverride = parseNumberAttr(getAttribute(findChild(override, "w:startOverride"), "w:val"));
58360
+ if (!levelDef) return void 0;
58361
+ const numFmtEl = findNumFmtElement(levelDef);
58362
+ const lvlText = getAttribute(findChild(levelDef, "w:lvlText"), "w:val");
58363
+ const start2 = startOverride ?? parseNumberAttr(getAttribute(findChild(levelDef, "w:start"), "w:val"));
58364
+ const suffix2 = normalizeSuffix(getAttribute(findChild(levelDef, "w:suff"), "w:val"));
58365
+ const lvlJc = normalizeJustification(getAttribute(findChild(levelDef, "w:lvlJc"), "w:val"));
58366
+ const indent = extractIndentFromLevel(levelDef);
58367
+ const markerRun = extractMarkerRun(levelDef);
58368
+ const numFmt = normalizeNumFmt(getAttribute(numFmtEl, "w:val"));
58369
+ return {
58370
+ format: numFmt,
58371
+ lvlText,
58372
+ start: start2,
58373
+ suffix: suffix2,
58374
+ lvlJc,
58375
+ resolvedLevelIndent: indent,
58376
+ resolvedMarkerRpr: markerRun
58377
+ };
58378
+ };
57960
58379
  const isTruthy = (value) => {
57961
58380
  if (value === true || value === 1) return true;
57962
58381
  if (typeof value === "string") {
@@ -58589,6 +59008,30 @@ const computeParagraphAttrs = (para, styleContext, listCounterContext, converter
58589
59008
  const ilvl = Number.isFinite(numberingProps.ilvl) ? Math.max(0, Math.floor(Number(numberingProps.ilvl))) : 0;
58590
59009
  const listRendering = normalizeListRenderingAttrs(attrs.listRendering);
58591
59010
  const numericNumId = typeof numId === "number" ? numId : void 0;
59011
+ const resolvedLevel = resolveNumberingFromContext(numId, ilvl, converterContext?.numbering);
59012
+ if (resolvedLevel) {
59013
+ if (resolvedLevel.format && numberingProps.format == null) {
59014
+ numberingProps.format = resolvedLevel.format;
59015
+ }
59016
+ if (resolvedLevel.lvlText && numberingProps.lvlText == null) {
59017
+ numberingProps.lvlText = resolvedLevel.lvlText;
59018
+ }
59019
+ if (resolvedLevel.start != null && numberingProps.start == null) {
59020
+ numberingProps.start = resolvedLevel.start;
59021
+ }
59022
+ if (resolvedLevel.suffix && numberingProps.suffix == null) {
59023
+ numberingProps.suffix = resolvedLevel.suffix;
59024
+ }
59025
+ if (resolvedLevel.lvlJc && numberingProps.lvlJc == null) {
59026
+ numberingProps.lvlJc = resolvedLevel.lvlJc;
59027
+ }
59028
+ if (resolvedLevel.resolvedLevelIndent && !numberingProps.resolvedLevelIndent) {
59029
+ numberingProps.resolvedLevelIndent = resolvedLevel.resolvedLevelIndent;
59030
+ }
59031
+ if (resolvedLevel.resolvedMarkerRpr && !numberingProps.resolvedMarkerRpr) {
59032
+ numberingProps.resolvedMarkerRpr = resolvedLevel.resolvedMarkerRpr;
59033
+ }
59034
+ }
58592
59035
  let counterValue = 1;
58593
59036
  if (listCounterContext && typeof numericNumId === "number") {
58594
59037
  counterValue = listCounterContext.incrementListCounter(numericNumId, ilvl);
@@ -59814,41 +60257,45 @@ function paragraphToFlowBlocks$1(para, nextBlockId, positions, defaultFont, defa
59814
60257
  }
59815
60258
  return;
59816
60259
  }
59817
- if (node.type === "hardBreak") {
59818
- flushParagraph();
59819
- blocks.push({
59820
- kind: "pageBreak",
59821
- id: nextId(),
59822
- attrs: node.attrs || {}
59823
- });
59824
- return;
59825
- }
59826
- if (node.type === "lineBreak") {
60260
+ if (node.type === "hardBreak" || node.type === "lineBreak") {
59827
60261
  const attrs = node.attrs ?? {};
59828
- if (attrs.lineBreakType === "column") {
60262
+ const breakType = attrs.pageBreakType ?? attrs.lineBreakType ?? "line";
60263
+ if (breakType === "page") {
60264
+ flushParagraph();
60265
+ blocks.push({
60266
+ kind: "pageBreak",
60267
+ id: nextId(),
60268
+ attrs: node.attrs || {}
60269
+ });
60270
+ return;
60271
+ }
60272
+ if (breakType === "column") {
59829
60273
  flushParagraph();
59830
60274
  blocks.push({
59831
60275
  kind: "columnBreak",
59832
60276
  id: nextId(),
59833
60277
  attrs: node.attrs || {}
59834
60278
  });
60279
+ return;
60280
+ }
60281
+ const lineBreakRun = { kind: "lineBreak", attrs: {} };
60282
+ const lbAttrs = {};
60283
+ if (attrs.lineBreakType) lbAttrs.lineBreakType = String(attrs.lineBreakType);
60284
+ if (attrs.clear) lbAttrs.clear = String(attrs.clear);
60285
+ if (Object.keys(lbAttrs).length > 0) {
60286
+ lineBreakRun.attrs = lbAttrs;
59835
60287
  } else {
59836
- const lineBreakRun = { kind: "lineBreak", attrs: {} };
59837
- const lbAttrs = {};
59838
- if (attrs.lineBreakType) lbAttrs.lineBreakType = String(attrs.lineBreakType);
59839
- if (attrs.clear) lbAttrs.clear = String(attrs.clear);
59840
- if (Object.keys(lbAttrs).length > 0) {
59841
- lineBreakRun.attrs = lbAttrs;
59842
- } else {
59843
- delete lineBreakRun.attrs;
59844
- }
59845
- const pos = positions.get(node);
59846
- if (pos) {
59847
- lineBreakRun.pmStart = pos.start;
59848
- lineBreakRun.pmEnd = pos.end;
59849
- }
59850
- currentRuns.push(lineBreakRun);
60288
+ delete lineBreakRun.attrs;
60289
+ }
60290
+ const pos = positions.get(node);
60291
+ if (pos) {
60292
+ lineBreakRun.pmStart = pos.start;
60293
+ lineBreakRun.pmEnd = pos.end;
59851
60294
  }
60295
+ if (activeSdt) {
60296
+ lineBreakRun.sdt = activeSdt;
60297
+ }
60298
+ currentRuns.push(lineBreakRun);
59852
60299
  return;
59853
60300
  }
59854
60301
  };
@@ -60441,6 +60888,22 @@ const normalizeTableWidth = (value) => {
60441
60888
  };
60442
60889
  const isTableRowNode = (node) => node.type === "tableRow" || node.type === "table_row";
60443
60890
  const isTableCellNode = (node) => node.type === "tableCell" || node.type === "table_cell" || node.type === "tableHeader" || node.type === "table_header";
60891
+ const normalizeRowHeight = (rowProps) => {
60892
+ if (!rowProps || typeof rowProps !== "object") return void 0;
60893
+ const rawRowHeight = rowProps.rowHeight;
60894
+ if (!rawRowHeight || typeof rawRowHeight !== "object") return void 0;
60895
+ const heightObj = rawRowHeight;
60896
+ const rawValue = pickNumber(heightObj.value ?? heightObj.val);
60897
+ if (rawValue == null) return void 0;
60898
+ const rawRule = heightObj.rule ?? heightObj.hRule;
60899
+ const rule = rawRule === "exact" || rawRule === "atLeast" || rawRule === "auto" ? rawRule : "atLeast";
60900
+ const isLikelyTwips = rawValue >= 300 || Math.abs(rawValue % 15) < 1e-6;
60901
+ const valuePx = isLikelyTwips ? twipsToPx$1(rawValue) : rawValue;
60902
+ return {
60903
+ value: valuePx,
60904
+ rule
60905
+ };
60906
+ };
60444
60907
  const parseTableCell = (args) => {
60445
60908
  const { cellNode, rowIndex, cellIndex, context, defaultCellPadding } = args;
60446
60909
  if (!isTableCellNode(cellNode) || !Array.isArray(cellNode.content)) {
@@ -60478,8 +60941,9 @@ const parseTableCell = (args) => {
60478
60941
  const padding = extractCellPadding(cellNode.attrs ?? {}) ?? (defaultCellPadding ? { ...defaultCellPadding } : void 0);
60479
60942
  if (padding) cellAttrs.padding = padding;
60480
60943
  const verticalAlign = cellNode.attrs?.verticalAlign;
60481
- if (verticalAlign === "top" || verticalAlign === "middle" || verticalAlign === "bottom") {
60482
- cellAttrs.verticalAlign = verticalAlign;
60944
+ const normalizedVerticalAlign = verticalAlign === "middle" ? "center" : verticalAlign === "center" ? "center" : verticalAlign;
60945
+ if (normalizedVerticalAlign === "top" || normalizedVerticalAlign === "center" || normalizedVerticalAlign === "bottom") {
60946
+ cellAttrs.verticalAlign = normalizedVerticalAlign;
60483
60947
  }
60484
60948
  const background = cellNode.attrs?.background;
60485
60949
  if (background && typeof background.color === "string") {
@@ -60522,15 +60986,89 @@ const parseTableRow = (args) => {
60522
60986
  });
60523
60987
  if (cells.length === 0) return null;
60524
60988
  const rowProps = rowNode.attrs?.tableRowProperties;
60989
+ const rowHeight = normalizeRowHeight(rowProps);
60525
60990
  const attrs = rowProps && typeof rowProps === "object" ? {
60526
- tableRowProperties: rowProps
60527
- } : void 0;
60991
+ tableRowProperties: rowProps,
60992
+ ...rowHeight ? { rowHeight } : {}
60993
+ } : rowHeight ? { rowHeight } : void 0;
60528
60994
  return {
60529
60995
  id: context.nextBlockId(`row-${rowIndex}`),
60530
60996
  cells,
60531
60997
  attrs
60532
60998
  };
60533
60999
  };
61000
+ function extractFloatingTableAnchorWrap(node) {
61001
+ const tableProperties = node.attrs?.tableProperties;
61002
+ const floatingProps = tableProperties?.floatingTableProperties;
61003
+ if (!floatingProps) {
61004
+ return {};
61005
+ }
61006
+ const hasPositioning = floatingProps.tblpX !== void 0 || floatingProps.tblpY !== void 0 || floatingProps.tblpXSpec !== void 0 || floatingProps.tblpYSpec !== void 0 || floatingProps.horzAnchor !== void 0 || floatingProps.vertAnchor !== void 0;
61007
+ if (!hasPositioning) {
61008
+ return {};
61009
+ }
61010
+ const mapHorzAnchor = (val) => {
61011
+ switch (val) {
61012
+ case "page":
61013
+ return "page";
61014
+ case "margin":
61015
+ return "margin";
61016
+ case "text":
61017
+ default:
61018
+ return "column";
61019
+ }
61020
+ };
61021
+ const mapVertAnchor = (val) => {
61022
+ switch (val) {
61023
+ case "page":
61024
+ return "page";
61025
+ case "margin":
61026
+ return "margin";
61027
+ case "text":
61028
+ default:
61029
+ return "paragraph";
61030
+ }
61031
+ };
61032
+ const anchor = {
61033
+ isAnchored: true,
61034
+ hRelativeFrom: mapHorzAnchor(floatingProps.horzAnchor),
61035
+ vRelativeFrom: mapVertAnchor(floatingProps.vertAnchor)
61036
+ };
61037
+ if (floatingProps.tblpXSpec) {
61038
+ anchor.alignH = floatingProps.tblpXSpec;
61039
+ }
61040
+ if (floatingProps.tblpYSpec) {
61041
+ anchor.alignV = floatingProps.tblpYSpec;
61042
+ }
61043
+ if (floatingProps.tblpX !== void 0) {
61044
+ anchor.offsetH = twipsToPx$1(floatingProps.tblpX);
61045
+ }
61046
+ if (floatingProps.tblpY !== void 0) {
61047
+ anchor.offsetV = twipsToPx$1(floatingProps.tblpY);
61048
+ }
61049
+ const hasDistances = floatingProps.leftFromText !== void 0 || floatingProps.rightFromText !== void 0 || floatingProps.topFromText !== void 0 || floatingProps.bottomFromText !== void 0;
61050
+ const wrap2 = {
61051
+ type: "Square",
61052
+ // Floating tables with text distances use square wrapping
61053
+ wrapText: "bothSides"
61054
+ // Default to text on both sides
61055
+ };
61056
+ if (hasDistances) {
61057
+ if (floatingProps.topFromText !== void 0) {
61058
+ wrap2.distTop = twipsToPx$1(floatingProps.topFromText);
61059
+ }
61060
+ if (floatingProps.bottomFromText !== void 0) {
61061
+ wrap2.distBottom = twipsToPx$1(floatingProps.bottomFromText);
61062
+ }
61063
+ if (floatingProps.leftFromText !== void 0) {
61064
+ wrap2.distLeft = twipsToPx$1(floatingProps.leftFromText);
61065
+ }
61066
+ if (floatingProps.rightFromText !== void 0) {
61067
+ wrap2.distRight = twipsToPx$1(floatingProps.rightFromText);
61068
+ }
61069
+ }
61070
+ return { anchor, wrap: wrap2 };
61071
+ }
60534
61072
  function tableNodeToBlock$1(node, nextBlockId, positions, defaultFont, defaultSize, _styleContext, trackedChanges, bookmarks, hyperlinkConfig, themeColors, paragraphToFlowBlocks2, converterContext) {
60535
61073
  if (!Array.isArray(node.content) || node.content.length === 0) return null;
60536
61074
  if (!paragraphToFlowBlocks2) return null;
@@ -60595,6 +61133,10 @@ function tableNodeToBlock$1(node, nextBlockId, positions, defaultFont, defaultSi
60595
61133
  if (tableLayout) {
60596
61134
  tableAttrs.tableLayout = tableLayout;
60597
61135
  }
61136
+ const tableProperties = node.attrs?.tableProperties;
61137
+ if (tableProperties && typeof tableProperties === "object") {
61138
+ tableAttrs.tableProperties = tableProperties;
61139
+ }
60598
61140
  let columnWidths = void 0;
60599
61141
  const twipsToPixels2 = (twips) => {
60600
61142
  const PIXELS_PER_INCH2 = 96;
@@ -60638,12 +61180,15 @@ function tableNodeToBlock$1(node, nextBlockId, positions, defaultFont, defaultSi
60638
61180
  columnWidths = void 0;
60639
61181
  }
60640
61182
  }
61183
+ const { anchor, wrap: wrap2 } = extractFloatingTableAnchorWrap(node);
60641
61184
  const tableBlock = {
60642
61185
  kind: "table",
60643
61186
  id: nextBlockId("table"),
60644
61187
  rows,
60645
61188
  attrs: Object.keys(tableAttrs).length > 0 ? tableAttrs : void 0,
60646
- columnWidths
61189
+ columnWidths,
61190
+ ...anchor ? { anchor } : {},
61191
+ ...wrap2 ? { wrap: wrap2 } : {}
60647
61192
  };
60648
61193
  return tableBlock;
60649
61194
  }
@@ -60979,7 +61524,7 @@ function getMeasurementContext() {
60979
61524
  return measurementCtx;
60980
61525
  }
60981
61526
  function getRunFontString(run2) {
60982
- if (run2.kind === "tab" || run2.kind === "lineBreak" || "src" in run2) {
61527
+ if (run2.kind === "tab" || run2.kind === "lineBreak" || run2.kind === "break" || "src" in run2) {
60983
61528
  return "normal normal 16px Arial";
60984
61529
  }
60985
61530
  const style2 = run2.italic ? "italic" : "normal";
@@ -61006,6 +61551,10 @@ function sliceRunsForLine$1(block, line) {
61006
61551
  result.push(run2);
61007
61552
  continue;
61008
61553
  }
61554
+ if (run2.kind === "break") {
61555
+ result.push(run2);
61556
+ continue;
61557
+ }
61009
61558
  const text = run2.text ?? "";
61010
61559
  const isFirstRun = runIndex === line.fromRun;
61011
61560
  const isLastRun = runIndex === line.toRun;
@@ -61039,7 +61588,7 @@ function measureCharacterX(block, line, charOffset) {
61039
61588
  1,
61040
61589
  runs2.reduce((sum, run2) => {
61041
61590
  if (isTabRun$1(run2)) return sum + TAB_CHAR_LENGTH;
61042
- if ("src" in run2 || run2.kind === "lineBreak") return sum;
61591
+ if ("src" in run2 || run2.kind === "lineBreak" || run2.kind === "break") return sum;
61043
61592
  return sum + (run2.text ?? "").length;
61044
61593
  }, 0)
61045
61594
  );
@@ -61060,7 +61609,7 @@ function measureCharacterX(block, line, charOffset) {
61060
61609
  currentCharOffset += runLength2;
61061
61610
  continue;
61062
61611
  }
61063
- const text = "src" in run2 || run2.kind === "lineBreak" ? "" : run2.text ?? "";
61612
+ const text = "src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" ? "" : run2.text ?? "";
61064
61613
  const runLength = text.length;
61065
61614
  if (currentCharOffset + runLength >= charOffset) {
61066
61615
  const offsetInRun = charOffset - currentCharOffset;
@@ -61103,7 +61652,7 @@ function measureCharacterXSegmentBased(block, line, charOffset, ctx2) {
61103
61652
  if (isTabRun$1(run2)) {
61104
61653
  return segmentBaseX + (offsetInSegment > 0 ? segment.width ?? 0 : 0);
61105
61654
  }
61106
- if ("src" in run2 || run2.kind === "lineBreak") {
61655
+ if ("src" in run2 || run2.kind === "lineBreak" || run2.kind === "break") {
61107
61656
  return segmentBaseX + (offsetInSegment >= segmentChars ? segment.width ?? 0 : 0);
61108
61657
  }
61109
61658
  const text = run2.text ?? "";
@@ -61126,7 +61675,7 @@ function findCharacterAtX(block, line, x2, pmStart) {
61126
61675
  1,
61127
61676
  runs2.reduce((sum, run2) => {
61128
61677
  if (isTabRun$1(run2)) return sum + TAB_CHAR_LENGTH;
61129
- if ("src" in run2 || run2.kind === "lineBreak") return sum;
61678
+ if ("src" in run2 || run2.kind === "lineBreak" || run2.kind === "break") return sum;
61130
61679
  return sum + (run2.text ?? "").length;
61131
61680
  }, 0)
61132
61681
  );
@@ -61161,7 +61710,7 @@ function findCharacterAtX(block, line, x2, pmStart) {
61161
61710
  currentCharOffset += TAB_CHAR_LENGTH;
61162
61711
  continue;
61163
61712
  }
61164
- const text = "src" in run2 || run2.kind === "lineBreak" ? "" : run2.text ?? "";
61713
+ const text = "src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" ? "" : run2.text ?? "";
61165
61714
  const runLength = text.length;
61166
61715
  if (runLength === 0) continue;
61167
61716
  ctx2.font = getRunFontString(run2);
@@ -61594,6 +62143,40 @@ function createFloatingObjectManager(columns, margins, pageWidth) {
61594
62143
  };
61595
62144
  zones.push(zone);
61596
62145
  },
62146
+ registerTable(tableBlock, measure, anchorY, columnIndex, pageNumber) {
62147
+ if (!tableBlock.anchor?.isAnchored) {
62148
+ return;
62149
+ }
62150
+ const { wrap: wrap2, anchor } = tableBlock;
62151
+ const wrapType = wrap2?.type ?? "None";
62152
+ if (wrapType === "None") {
62153
+ return;
62154
+ }
62155
+ const tableWidth = measure.totalWidth ?? 0;
62156
+ const tableHeight = measure.totalHeight ?? 0;
62157
+ const x2 = computeTableAnchorX(anchor, columnIndex, columns, tableWidth, margins, pageWidth);
62158
+ const y2 = anchorY + (anchor.offsetV ?? 0);
62159
+ const zone = {
62160
+ imageBlockId: tableBlock.id,
62161
+ // Reusing imageBlockId field for table id
62162
+ pageNumber,
62163
+ columnIndex,
62164
+ bounds: {
62165
+ x: x2,
62166
+ y: y2,
62167
+ width: tableWidth,
62168
+ height: tableHeight
62169
+ },
62170
+ distances: {
62171
+ top: wrap2?.distTop ?? 0,
62172
+ bottom: wrap2?.distBottom ?? 0,
62173
+ left: wrap2?.distLeft ?? 0,
62174
+ right: wrap2?.distRight ?? 0
62175
+ },
62176
+ wrapMode: computeTableWrapMode(wrap2)
62177
+ };
62178
+ zones.push(zone);
62179
+ },
61597
62180
  getExclusionsForLine(lineY, lineHeight2, columnIndex, pageNumber) {
61598
62181
  const result = zones.filter((zone) => {
61599
62182
  if (zone.pageNumber !== pageNumber || zone.columnIndex !== columnIndex) {
@@ -61701,6 +62284,49 @@ function computeWrapMode(wrap2, _anchor) {
61701
62284
  if (wrapText === "largest") return "largest";
61702
62285
  return "both";
61703
62286
  }
62287
+ function computeTableAnchorX(anchor, columnIndex, columns, tableWidth, margins, pageWidth) {
62288
+ const alignH = anchor.alignH ?? "left";
62289
+ const offsetH = anchor.offsetH ?? 0;
62290
+ const marginLeft = Math.max(0, margins?.left ?? 0);
62291
+ const marginRight = Math.max(0, margins?.right ?? 0);
62292
+ const contentWidth = pageWidth != null ? Math.max(1, pageWidth - (marginLeft + marginRight)) : columns.width;
62293
+ const contentLeft = marginLeft;
62294
+ const columnLeft = contentLeft + columnIndex * (columns.width + columns.gap);
62295
+ const relativeFrom = anchor.hRelativeFrom ?? "column";
62296
+ let baseX;
62297
+ let availableWidth;
62298
+ if (relativeFrom === "page") {
62299
+ if (columns.count === 1) {
62300
+ baseX = contentLeft;
62301
+ availableWidth = contentWidth;
62302
+ } else {
62303
+ baseX = 0;
62304
+ availableWidth = pageWidth != null ? pageWidth : contentWidth;
62305
+ }
62306
+ } else if (relativeFrom === "margin") {
62307
+ baseX = contentLeft;
62308
+ availableWidth = contentWidth;
62309
+ } else {
62310
+ baseX = columnLeft;
62311
+ availableWidth = columns.width;
62312
+ }
62313
+ let effectiveAlignH = alignH;
62314
+ if (alignH === "inside") effectiveAlignH = "left";
62315
+ if (alignH === "outside") effectiveAlignH = "right";
62316
+ const result = effectiveAlignH === "left" ? baseX + offsetH : effectiveAlignH === "right" ? baseX + availableWidth - tableWidth - offsetH : effectiveAlignH === "center" ? baseX + (availableWidth - tableWidth) / 2 + offsetH : baseX;
62317
+ return result;
62318
+ }
62319
+ function computeTableWrapMode(wrap2) {
62320
+ if (!wrap2) return "none";
62321
+ if (wrap2.type === "None") {
62322
+ return "none";
62323
+ }
62324
+ const wrapText = wrap2.wrapText ?? "bothSides";
62325
+ if (wrapText === "left") return "right";
62326
+ if (wrapText === "right") return "left";
62327
+ if (wrapText === "largest") return "largest";
62328
+ return "both";
62329
+ }
61704
62330
  function computeNextSectionPropsAtBreak(blocks) {
61705
62331
  const nextSectionPropsAtBreak = /* @__PURE__ */ new Map();
61706
62332
  const docxBreakIndexes = [];
@@ -62119,6 +62745,9 @@ function layoutParagraphBlock(ctx2, anchors) {
62119
62745
  };
62120
62746
  if (measure.marker) {
62121
62747
  fragment.markerWidth = measure.marker.markerWidth;
62748
+ if (measure.marker.markerTextWidth != null) {
62749
+ fragment.markerTextWidth = measure.marker.markerTextWidth;
62750
+ }
62122
62751
  }
62123
62752
  state2.page.fragments.push(fragment);
62124
62753
  state2.trailingSpacing = 0;
@@ -62220,6 +62849,12 @@ function layoutParagraphBlock(ctx2, anchors) {
62220
62849
  };
62221
62850
  if (measure.marker && fromLine === 0) {
62222
62851
  fragment.markerWidth = measure.marker.markerWidth;
62852
+ if (measure.marker.markerTextWidth != null) {
62853
+ fragment.markerTextWidth = measure.marker.markerTextWidth;
62854
+ }
62855
+ if (measure.kind === "paragraph" && measure.marker?.gutterWidth != null) {
62856
+ fragment.markerGutter = measure.marker.gutterWidth;
62857
+ }
62223
62858
  }
62224
62859
  if (fromLine > 0) fragment.continuesFromPrev = true;
62225
62860
  if (slice2.toLine < lines.length) fragment.continuesOnNext = true;
@@ -62397,6 +63032,206 @@ function generateColumnBoundaries(measure) {
62397
63032
  }
62398
63033
  return boundaries;
62399
63034
  }
63035
+ function countHeaderRows(block) {
63036
+ let count = 0;
63037
+ for (let i = 0; i < block.rows.length; i++) {
63038
+ const row = block.rows[i];
63039
+ const repeatHeader = row.attrs?.tableRowProperties?.repeatHeader;
63040
+ if (repeatHeader === true) {
63041
+ count++;
63042
+ } else {
63043
+ break;
63044
+ }
63045
+ }
63046
+ return count;
63047
+ }
63048
+ function sumRowHeights(rows, fromRow, toRow) {
63049
+ let total = 0;
63050
+ for (let i = fromRow; i < toRow && i < rows.length; i++) {
63051
+ total += rows[i].height;
63052
+ }
63053
+ return total;
63054
+ }
63055
+ function calculateFragmentHeight(fragment, measure, _headerCount) {
63056
+ let height = 0;
63057
+ if (fragment.repeatHeaderCount && fragment.repeatHeaderCount > 0) {
63058
+ height += sumRowHeights(measure.rows, 0, fragment.repeatHeaderCount);
63059
+ }
63060
+ height += sumRowHeights(measure.rows, fragment.fromRow, fragment.toRow);
63061
+ return height;
63062
+ }
63063
+ const MIN_PARTIAL_ROW_HEIGHT = 20;
63064
+ function getCellLines(cell) {
63065
+ if (cell.blocks && cell.blocks.length > 0) {
63066
+ const allLines = [];
63067
+ for (const block of cell.blocks) {
63068
+ if (block.kind === "paragraph") {
63069
+ if (block.kind === "paragraph" && "lines" in block) {
63070
+ const paraBlock = block;
63071
+ if (paraBlock.lines) {
63072
+ allLines.push(...paraBlock.lines);
63073
+ }
63074
+ }
63075
+ }
63076
+ }
63077
+ return allLines;
63078
+ }
63079
+ if (cell.paragraph?.lines) {
63080
+ return cell.paragraph.lines;
63081
+ }
63082
+ return [];
63083
+ }
63084
+ function getCellPadding(cellIdx, blockRow) {
63085
+ const padding = blockRow?.cells?.[cellIdx]?.attrs?.padding ?? {};
63086
+ return {
63087
+ top: padding.top ?? 2,
63088
+ bottom: padding.bottom ?? 2,
63089
+ left: padding.left ?? 4,
63090
+ right: padding.right ?? 4
63091
+ };
63092
+ }
63093
+ function getCellTotalLines(cell) {
63094
+ return getCellLines(cell).length;
63095
+ }
63096
+ function computePartialRow(rowIndex, blockRow, measure, availableHeight, fromLineByCell) {
63097
+ const row = measure.rows[rowIndex];
63098
+ if (!row) {
63099
+ throw new Error(`Invalid rowIndex ${rowIndex}: measure.rows has ${measure.rows.length} rows`);
63100
+ }
63101
+ const cellCount = row.cells.length;
63102
+ const startLines = fromLineByCell || new Array(cellCount).fill(0);
63103
+ const toLineByCell = [];
63104
+ const heightByCell = [];
63105
+ const cellPaddings = row.cells.map((_2, idx) => getCellPadding(idx, blockRow));
63106
+ for (let cellIdx = 0; cellIdx < cellCount; cellIdx++) {
63107
+ const cell = row.cells[cellIdx];
63108
+ const startLine = startLines[cellIdx] || 0;
63109
+ const cellPadding = cellPaddings[cellIdx];
63110
+ const availableForLines = Math.max(0, availableHeight - (cellPadding.top + cellPadding.bottom));
63111
+ const lines = getCellLines(cell);
63112
+ let cumulativeHeight = 0;
63113
+ let cutLine = startLine;
63114
+ for (let i = startLine; i < lines.length; i++) {
63115
+ const lineHeight2 = lines[i].lineHeight || 0;
63116
+ if (cumulativeHeight + lineHeight2 > availableForLines) {
63117
+ break;
63118
+ }
63119
+ cumulativeHeight += lineHeight2;
63120
+ cutLine = i + 1;
63121
+ }
63122
+ toLineByCell.push(cutLine);
63123
+ heightByCell.push(cumulativeHeight);
63124
+ }
63125
+ const positiveHeights = heightByCell.filter((h) => h > 0);
63126
+ const minHeight = positiveHeights.length > 0 ? Math.min(...positiveHeights) : 0;
63127
+ let actualPartialHeight = 0;
63128
+ let maxPaddingTotal = 0;
63129
+ for (let cellIdx = 0; cellIdx < cellCount; cellIdx++) {
63130
+ const cell = row.cells[cellIdx];
63131
+ const startLine = startLines[cellIdx] || 0;
63132
+ const lines = getCellLines(cell);
63133
+ const cellPadding = cellPaddings[cellIdx];
63134
+ const paddingTotal = cellPadding.top + cellPadding.bottom;
63135
+ maxPaddingTotal = Math.max(maxPaddingTotal, paddingTotal);
63136
+ let cumulativeHeight = 0;
63137
+ let cutLine = startLine;
63138
+ for (let i = startLine; i < lines.length; i++) {
63139
+ const lineHeight2 = lines[i].lineHeight || 0;
63140
+ if (cumulativeHeight + lineHeight2 > minHeight) {
63141
+ break;
63142
+ }
63143
+ cumulativeHeight += lineHeight2;
63144
+ cutLine = i + 1;
63145
+ }
63146
+ toLineByCell[cellIdx] = cutLine;
63147
+ actualPartialHeight = Math.max(actualPartialHeight, cumulativeHeight + paddingTotal);
63148
+ }
63149
+ const madeProgress = toLineByCell.some((cutLine, idx) => cutLine > (startLines[idx] || 0));
63150
+ const isFirstPart = startLines.every((l3) => l3 === 0);
63151
+ const allCellsExhausted = toLineByCell.every((cutLine, idx) => {
63152
+ const totalLines = getCellTotalLines(row.cells[idx]);
63153
+ return cutLine >= totalLines;
63154
+ });
63155
+ const isLastPart = allCellsExhausted || !madeProgress;
63156
+ if (actualPartialHeight === 0 && isFirstPart) {
63157
+ actualPartialHeight = maxPaddingTotal;
63158
+ }
63159
+ return {
63160
+ rowIndex,
63161
+ fromLineByCell: startLines,
63162
+ toLineByCell,
63163
+ isFirstPart,
63164
+ isLastPart,
63165
+ partialHeight: actualPartialHeight
63166
+ };
63167
+ }
63168
+ function findSplitPoint(block, measure, startRow, availableHeight, fullPageHeight, _pendingPartialRow) {
63169
+ let accumulatedHeight = 0;
63170
+ let lastFitRow = startRow;
63171
+ for (let i = startRow; i < block.rows.length; i++) {
63172
+ const row = block.rows[i];
63173
+ const rowHeight = measure.rows[i]?.height || 0;
63174
+ const cantSplit = row.attrs?.tableRowProperties?.cantSplit === true;
63175
+ if (accumulatedHeight + rowHeight <= availableHeight) {
63176
+ accumulatedHeight += rowHeight;
63177
+ lastFitRow = i + 1;
63178
+ } else {
63179
+ const remainingHeight = availableHeight - accumulatedHeight;
63180
+ if (fullPageHeight && rowHeight > fullPageHeight) {
63181
+ const partialRow = computePartialRow(i, block.rows[i], measure, remainingHeight);
63182
+ return { endRow: i + 1, partialRow };
63183
+ }
63184
+ if (cantSplit) {
63185
+ if (lastFitRow === startRow) {
63186
+ return { endRow: startRow, partialRow: null };
63187
+ }
63188
+ return { endRow: lastFitRow, partialRow: null };
63189
+ }
63190
+ if (remainingHeight >= MIN_PARTIAL_ROW_HEIGHT) {
63191
+ const partialRow = computePartialRow(i, block.rows[i], measure, remainingHeight);
63192
+ const hasContent = partialRow.toLineByCell.some(
63193
+ (cutLine, idx) => cutLine > (partialRow.fromLineByCell[idx] || 0)
63194
+ );
63195
+ if (hasContent) {
63196
+ return { endRow: i + 1, partialRow };
63197
+ }
63198
+ }
63199
+ return { endRow: lastFitRow, partialRow: null };
63200
+ }
63201
+ }
63202
+ return { endRow: block.rows.length, partialRow: null };
63203
+ }
63204
+ function generateFragmentMetadata(measure, _fromRow, _toRow, _repeatHeaderCount) {
63205
+ return {
63206
+ columnBoundaries: generateColumnBoundaries(measure),
63207
+ coordinateSystem: "fragment"
63208
+ };
63209
+ }
63210
+ function layoutMonolithicTable(context) {
63211
+ let state2 = context.ensurePage();
63212
+ if (state2.cursorY + context.measure.totalHeight > state2.contentBottom && state2.page.fragments.length > 0) {
63213
+ state2 = context.advanceColumn(state2);
63214
+ }
63215
+ state2 = context.ensurePage();
63216
+ const height = Math.min(context.measure.totalHeight, state2.contentBottom - state2.cursorY);
63217
+ const metadata = {
63218
+ columnBoundaries: generateColumnBoundaries(context.measure),
63219
+ coordinateSystem: "fragment"
63220
+ };
63221
+ const fragment = {
63222
+ kind: "table",
63223
+ blockId: context.block.id,
63224
+ fromRow: 0,
63225
+ toRow: context.block.rows.length,
63226
+ x: context.columnX(state2.columnIndex),
63227
+ y: state2.cursorY,
63228
+ width: Math.min(context.columnWidth, context.measure.totalWidth || context.columnWidth),
63229
+ height,
63230
+ metadata
63231
+ };
63232
+ state2.page.fragments.push(fragment);
63233
+ state2.cursorY += height;
63234
+ }
62400
63235
  function layoutTableBlock({
62401
63236
  block,
62402
63237
  measure,
@@ -62405,30 +63240,176 @@ function layoutTableBlock({
62405
63240
  advanceColumn,
62406
63241
  columnX
62407
63242
  }) {
63243
+ if (block.anchor?.isAnchored) {
63244
+ return;
63245
+ }
63246
+ const tableProps = block.attrs?.tableProperties;
63247
+ const floatingProps = tableProps?.floatingTableProperties;
63248
+ if (floatingProps && Object.keys(floatingProps).length > 0) {
63249
+ layoutMonolithicTable({ block, measure, columnWidth, ensurePage, advanceColumn, columnX });
63250
+ return;
63251
+ }
63252
+ const headerCount = countHeaderRows(block);
63253
+ const headerHeight = headerCount > 0 ? sumRowHeights(measure.rows, 0, headerCount) : 0;
62408
63254
  let state2 = ensurePage();
62409
- if (state2.cursorY + measure.totalHeight > state2.contentBottom && state2.page.fragments.length > 0) {
62410
- state2 = advanceColumn(state2);
63255
+ let currentRow = 0;
63256
+ let isTableContinuation = false;
63257
+ let pendingPartialRow = null;
63258
+ while (currentRow < block.rows.length || pendingPartialRow !== null) {
63259
+ state2 = ensurePage();
63260
+ const availableHeight = state2.contentBottom - state2.cursorY;
63261
+ let repeatHeaderCount = 0;
63262
+ if (currentRow === 0 && !pendingPartialRow) {
63263
+ repeatHeaderCount = 0;
63264
+ } else {
63265
+ if (headerCount > 0 && headerHeight <= availableHeight) {
63266
+ repeatHeaderCount = headerCount;
63267
+ } else if (headerCount > 0 && headerHeight > availableHeight) {
63268
+ repeatHeaderCount = 0;
63269
+ }
63270
+ }
63271
+ const availableForBody = repeatHeaderCount > 0 ? availableHeight - headerHeight : availableHeight;
63272
+ const fullPageHeight = state2.contentBottom;
63273
+ if (pendingPartialRow !== null) {
63274
+ const rowIndex = pendingPartialRow.rowIndex;
63275
+ const fromLineByCell = pendingPartialRow.toLineByCell;
63276
+ const continuationPartialRow = computePartialRow(
63277
+ rowIndex,
63278
+ block.rows[rowIndex],
63279
+ measure,
63280
+ availableForBody,
63281
+ fromLineByCell
63282
+ );
63283
+ const madeProgress = continuationPartialRow.toLineByCell.some(
63284
+ (toLine, idx) => toLine > (fromLineByCell[idx] || 0)
63285
+ );
63286
+ const hasRemainingLinesAfterContinuation = continuationPartialRow.toLineByCell.some(
63287
+ (toLine, idx) => {
63288
+ const totalLines = getCellTotalLines(measure.rows[rowIndex].cells[idx]);
63289
+ return toLine < totalLines;
63290
+ }
63291
+ );
63292
+ const hadRemainingLinesBefore = fromLineByCell.some((fromLine, idx) => {
63293
+ const totalLines = getCellTotalLines(measure.rows[rowIndex].cells[idx]);
63294
+ return fromLine < totalLines;
63295
+ });
63296
+ const fragmentHeight2 = continuationPartialRow.partialHeight + (repeatHeaderCount > 0 ? headerHeight : 0);
63297
+ if (fragmentHeight2 > 0) {
63298
+ const fragment2 = {
63299
+ kind: "table",
63300
+ blockId: block.id,
63301
+ fromRow: rowIndex,
63302
+ toRow: rowIndex + 1,
63303
+ x: columnX(state2.columnIndex),
63304
+ y: state2.cursorY,
63305
+ width: Math.min(columnWidth, measure.totalWidth || columnWidth),
63306
+ height: fragmentHeight2,
63307
+ continuesFromPrev: true,
63308
+ continuesOnNext: hasRemainingLinesAfterContinuation || rowIndex + 1 < block.rows.length,
63309
+ repeatHeaderCount,
63310
+ partialRow: continuationPartialRow,
63311
+ metadata: generateFragmentMetadata(measure)
63312
+ };
63313
+ state2.page.fragments.push(fragment2);
63314
+ state2.cursorY += fragmentHeight2;
63315
+ }
63316
+ const rowComplete = !hasRemainingLinesAfterContinuation;
63317
+ if (rowComplete) {
63318
+ currentRow = rowIndex + 1;
63319
+ pendingPartialRow = null;
63320
+ } else if (!madeProgress && hadRemainingLinesBefore) {
63321
+ state2 = advanceColumn(state2);
63322
+ } else {
63323
+ state2 = advanceColumn(state2);
63324
+ pendingPartialRow = continuationPartialRow;
63325
+ }
63326
+ isTableContinuation = true;
63327
+ continue;
63328
+ }
63329
+ const bodyStartRow = currentRow;
63330
+ const { endRow, partialRow } = findSplitPoint(block, measure, bodyStartRow, availableForBody, fullPageHeight);
63331
+ if (endRow === bodyStartRow && partialRow === null && state2.page.fragments.length > 0) {
63332
+ state2 = advanceColumn(state2);
63333
+ continue;
63334
+ }
63335
+ if (endRow === bodyStartRow && partialRow === null) {
63336
+ const forcedPartialRow = computePartialRow(bodyStartRow, block.rows[bodyStartRow], measure, availableForBody);
63337
+ const forcedEndRow = bodyStartRow + 1;
63338
+ const fragmentHeight2 = forcedPartialRow.partialHeight + (repeatHeaderCount > 0 ? headerHeight : 0);
63339
+ const fragment2 = {
63340
+ kind: "table",
63341
+ blockId: block.id,
63342
+ fromRow: bodyStartRow,
63343
+ toRow: forcedEndRow,
63344
+ x: columnX(state2.columnIndex),
63345
+ y: state2.cursorY,
63346
+ width: Math.min(columnWidth, measure.totalWidth || columnWidth),
63347
+ height: fragmentHeight2,
63348
+ continuesFromPrev: isTableContinuation,
63349
+ continuesOnNext: !forcedPartialRow.isLastPart || forcedEndRow < block.rows.length,
63350
+ repeatHeaderCount,
63351
+ partialRow: forcedPartialRow,
63352
+ metadata: generateFragmentMetadata(measure)
63353
+ };
63354
+ state2.page.fragments.push(fragment2);
63355
+ state2.cursorY += fragmentHeight2;
63356
+ pendingPartialRow = forcedPartialRow;
63357
+ isTableContinuation = true;
63358
+ continue;
63359
+ }
63360
+ let fragmentHeight;
63361
+ if (partialRow) {
63362
+ const fullRowsHeight = sumRowHeights(measure.rows, bodyStartRow, endRow - 1);
63363
+ fragmentHeight = fullRowsHeight + partialRow.partialHeight + (repeatHeaderCount > 0 ? headerHeight : 0);
63364
+ } else {
63365
+ fragmentHeight = calculateFragmentHeight(
63366
+ { fromRow: bodyStartRow, toRow: endRow, repeatHeaderCount },
63367
+ measure
63368
+ );
63369
+ }
63370
+ const fragment = {
63371
+ kind: "table",
63372
+ blockId: block.id,
63373
+ fromRow: bodyStartRow,
63374
+ toRow: endRow,
63375
+ x: columnX(state2.columnIndex),
63376
+ y: state2.cursorY,
63377
+ width: Math.min(columnWidth, measure.totalWidth || columnWidth),
63378
+ height: fragmentHeight,
63379
+ continuesFromPrev: isTableContinuation,
63380
+ continuesOnNext: endRow < block.rows.length || (partialRow ? !partialRow.isLastPart : false),
63381
+ repeatHeaderCount,
63382
+ partialRow: partialRow || void 0,
63383
+ metadata: generateFragmentMetadata(measure)
63384
+ };
63385
+ state2.page.fragments.push(fragment);
63386
+ state2.cursorY += fragmentHeight;
63387
+ if (partialRow && !partialRow.isLastPart) {
63388
+ pendingPartialRow = partialRow;
63389
+ currentRow = partialRow.rowIndex;
63390
+ } else {
63391
+ currentRow = endRow;
63392
+ pendingPartialRow = null;
63393
+ }
63394
+ isTableContinuation = true;
62411
63395
  }
62412
- state2 = ensurePage();
62413
- const height = Math.min(measure.totalHeight, state2.contentBottom - state2.cursorY);
63396
+ }
63397
+ function createAnchoredTableFragment(block, measure, x2, y2) {
62414
63398
  const metadata = {
62415
63399
  columnBoundaries: generateColumnBoundaries(measure),
62416
63400
  coordinateSystem: "fragment"
62417
- // rowBoundaries omitted - not needed for column resize, reduces DOM overhead
62418
63401
  };
62419
- const fragment = {
63402
+ return {
62420
63403
  kind: "table",
62421
63404
  blockId: block.id,
62422
63405
  fromRow: 0,
62423
63406
  toRow: block.rows.length,
62424
- x: columnX(state2.columnIndex),
62425
- y: state2.cursorY,
62426
- width: Math.min(columnWidth, measure.totalWidth || columnWidth),
62427
- height,
63407
+ x: x2,
63408
+ y: y2,
63409
+ width: measure.totalWidth ?? 0,
63410
+ height: measure.totalHeight ?? 0,
62428
63411
  metadata
62429
63412
  };
62430
- state2.page.fragments.push(fragment);
62431
- state2.cursorY += height;
62432
63413
  }
62433
63414
  function isPageRelativeAnchor(block) {
62434
63415
  const vRelativeFrom = block.anchor?.vRelativeFrom;
@@ -62455,9 +63436,6 @@ function collectPreRegisteredAnchors(blocks, measures) {
62455
63436
  function collectAnchoredDrawings(blocks, measures) {
62456
63437
  const map22 = /* @__PURE__ */ new Map();
62457
63438
  const len = Math.min(blocks.length, measures.length);
62458
- for (let i = 0; i < len; i += 1) {
62459
- if (blocks[i].kind === "paragraph") ;
62460
- }
62461
63439
  const nearestPrevParagraph = (fromIndex) => {
62462
63440
  for (let i = fromIndex - 1; i >= 0; i -= 1) {
62463
63441
  if (blocks[i].kind === "paragraph") return i;
@@ -62493,6 +63471,36 @@ function collectAnchoredDrawings(blocks, measures) {
62493
63471
  }
62494
63472
  return map22;
62495
63473
  }
63474
+ function collectAnchoredTables(blocks, measures) {
63475
+ const map22 = /* @__PURE__ */ new Map();
63476
+ const nearestPrevParagraph = (fromIndex) => {
63477
+ for (let i = fromIndex - 1; i >= 0; i -= 1) {
63478
+ if (blocks[i].kind === "paragraph") return i;
63479
+ }
63480
+ return null;
63481
+ };
63482
+ const nearestNextParagraph = (fromIndex) => {
63483
+ for (let i = fromIndex + 1; i < blocks.length; i += 1) {
63484
+ if (blocks[i].kind === "paragraph") return i;
63485
+ }
63486
+ return null;
63487
+ };
63488
+ for (let i = 0; i < blocks.length; i += 1) {
63489
+ const block = blocks[i];
63490
+ const measure = measures[i];
63491
+ if (block.kind !== "table" || measure?.kind !== "table") continue;
63492
+ const tableBlock = block;
63493
+ const tableMeasure = measure;
63494
+ if (!tableBlock.anchor?.isAnchored) continue;
63495
+ let anchorParaIndex = nearestPrevParagraph(i);
63496
+ if (anchorParaIndex == null) anchorParaIndex = nearestNextParagraph(i);
63497
+ if (anchorParaIndex == null) continue;
63498
+ const list = map22.get(anchorParaIndex) ?? [];
63499
+ list.push({ block: tableBlock, measure: tableMeasure });
63500
+ map22.set(anchorParaIndex, list);
63501
+ }
63502
+ return map22;
63503
+ }
62496
63504
  function createPaginator(opts) {
62497
63505
  const states = [];
62498
63506
  const pages = [];
@@ -63078,7 +64086,9 @@ function layoutDocument(blocks, measures, options = {}) {
63078
64086
  cachedColumnsState.state = null;
63079
64087
  };
63080
64088
  const anchoredByParagraph = collectAnchoredDrawings(blocks, measures);
64089
+ const anchoredTablesByParagraph = collectAnchoredTables(blocks, measures);
63081
64090
  const placedAnchoredIds = /* @__PURE__ */ new Set();
64091
+ const placedAnchoredTableIds = /* @__PURE__ */ new Set();
63082
64092
  const preRegisteredAnchors = collectPreRegisteredAnchors(blocks, measures);
63083
64093
  const preRegisteredPositions = /* @__PURE__ */ new Map();
63084
64094
  for (const entry of preRegisteredAnchors) {
@@ -63256,6 +64266,19 @@ function layoutDocument(blocks, measures, options = {}) {
63256
64266
  }
63257
64267
  }
63258
64268
  const anchorsForPara = anchoredByParagraph.get(index2);
64269
+ const tablesForPara = anchoredTablesByParagraph.get(index2);
64270
+ if (tablesForPara) {
64271
+ const state2 = paginator.ensurePage();
64272
+ for (const { block: tableBlock, measure: tableMeasure } of tablesForPara) {
64273
+ if (placedAnchoredTableIds.has(tableBlock.id)) continue;
64274
+ floatManager.registerTable(tableBlock, tableMeasure, state2.cursorY, state2.columnIndex, state2.page.number);
64275
+ const anchorX = tableBlock.anchor?.offsetH ?? columnX(state2.columnIndex);
64276
+ const anchorY = state2.cursorY + (tableBlock.anchor?.offsetV ?? 0);
64277
+ const tableFragment = createAnchoredTableFragment(tableBlock, tableMeasure, anchorX, anchorY);
64278
+ state2.page.fragments.push(tableFragment);
64279
+ placedAnchoredTableIds.add(tableBlock.id);
64280
+ }
64281
+ }
63259
64282
  layoutParagraphBlock(
63260
64283
  {
63261
64284
  block,
@@ -63527,7 +64550,9 @@ const hashRuns = (block) => {
63527
64550
  const trackedMode = block.attrs && "trackedChangesMode" in block.attrs && block.attrs.trackedChangesMode || "review";
63528
64551
  const trackedEnabled = resolveTrackedChangesEnabled(block.attrs, true);
63529
64552
  const runsHash = block.runs.map((run2) => {
63530
- const text = normalizeText("src" in run2 || run2.kind === "lineBreak" ? "" : run2.text ?? "");
64553
+ const text = normalizeText(
64554
+ "src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" ? "" : run2.text ?? ""
64555
+ );
63531
64556
  const bold = "bold" in run2 ? run2.bold : false;
63532
64557
  const italic = "italic" in run2 ? run2.italic : false;
63533
64558
  const color = "color" in run2 ? run2.color : void 0;
@@ -63541,7 +64566,22 @@ const hashRuns = (block) => {
63541
64566
  }
63542
64567
  return `${text}:${marks}${trackedKey}`;
63543
64568
  }).join("|");
63544
- return `${trackedMode}:${trackedEnabled ? "on" : "off"}|${runsHash}`;
64569
+ let numberingKey = "";
64570
+ if (block.attrs) {
64571
+ const attrs = block.attrs;
64572
+ if (attrs.numberingProperties) {
64573
+ const np = attrs.numberingProperties;
64574
+ let markerTextKey;
64575
+ if (!attrs.wordLayout?.marker) {
64576
+ markerTextKey = "<NULL>";
64577
+ } else {
64578
+ const markerText = attrs.wordLayout.marker.markerText;
64579
+ markerTextKey = markerText === "" ? "<EMPTY>" : markerText ?? "<NULL>";
64580
+ }
64581
+ numberingKey = `|num:${np.numId ?? ""}:${np.ilvl ?? 0}:${markerTextKey}`;
64582
+ }
64583
+ }
64584
+ return `${trackedMode}:${trackedEnabled ? "on" : "off"}|${runsHash}${numberingKey}`;
63545
64585
  };
63546
64586
  const createStats = () => ({
63547
64587
  hits: 0,
@@ -64187,7 +65227,7 @@ function fontString(run2) {
64187
65227
  return `${italic}${bold}${size2}px ${family}`.trim();
64188
65228
  }
64189
65229
  function runText(run2) {
64190
- return "src" in run2 || run2.kind === "lineBreak" ? "" : run2.text ?? "";
65230
+ return "src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" ? "" : run2.text ?? "";
64191
65231
  }
64192
65232
  function measureRunSliceWidth(run2, fromChar, toChar) {
64193
65233
  const context = getCtx();
@@ -64349,7 +65389,7 @@ const paragraphBlocksEqual = (a, b2) => {
64349
65389
  for (let i = 0; i < a.runs.length; i += 1) {
64350
65390
  const runA = a.runs[i];
64351
65391
  const runB = b2.runs[i];
64352
- if (("src" in runA || runA.kind === "lineBreak" ? "" : runA.text) !== ("src" in runB || runB.kind === "lineBreak" ? "" : runB.text) || ("bold" in runA ? runA.bold : false) !== ("bold" in runB ? runB.bold : false) || ("italic" in runA ? runA.italic : false) !== ("italic" in runB ? runB.italic : false) || ("color" in runA ? runA.color : void 0) !== ("color" in runB ? runB.color : void 0) || getTrackedChangeKey(runA) !== getTrackedChangeKey(runB)) {
65392
+ if (("src" in runA || runA.kind === "lineBreak" || runA.kind === "break" ? "" : runA.text) !== ("src" in runB || runB.kind === "lineBreak" || runB.kind === "break" ? "" : runB.text) || ("bold" in runA ? runA.bold : false) !== ("bold" in runB ? runB.bold : false) || ("italic" in runA ? runA.italic : false) !== ("italic" in runB ? runB.italic : false) || ("color" in runA ? runA.color : void 0) !== ("color" in runB ? runB.color : void 0) || getTrackedChangeKey(runA) !== getTrackedChangeKey(runB)) {
64353
65393
  return false;
64354
65394
  }
64355
65395
  }
@@ -64469,7 +65509,7 @@ function computeHeaderFooterContentHash(blocks) {
64469
65509
  parts.push(block.id);
64470
65510
  if (block.kind === "paragraph") {
64471
65511
  for (const run2 of block.runs) {
64472
- if (!("src" in run2) && run2.kind !== "lineBreak") {
65512
+ if (!("src" in run2) && run2.kind !== "lineBreak" && run2.kind !== "break") {
64473
65513
  parts.push(run2.text ?? "");
64474
65514
  }
64475
65515
  if ("bold" in run2 && run2.bold) parts.push("b");
@@ -65440,7 +66480,7 @@ function computeLinePmRange$1(block, line) {
65440
66480
  for (let runIndex = line.fromRun; runIndex <= line.toRun; runIndex += 1) {
65441
66481
  const run2 = block.runs[runIndex];
65442
66482
  if (!run2) continue;
65443
- const text = "src" in run2 || run2.kind === "lineBreak" ? "" : run2.text ?? "";
66483
+ const text = "src" in run2 || run2.kind === "lineBreak" || run2.kind === "break" ? "" : run2.text ?? "";
65444
66484
  const runLength = text.length;
65445
66485
  const runPmStart = run2.pmStart ?? null;
65446
66486
  const runPmEnd = run2.pmEnd ?? (runPmStart != null ? runPmStart + runLength : null);
@@ -68048,7 +69088,20 @@ const resolveTableCellBorders = (tableBorders, rowIndex, colIndex, totalRows, to
68048
69088
  };
68049
69089
  };
68050
69090
  const renderTableCell = (deps) => {
68051
- const { doc: doc2, x: x2, y: y2, rowHeight, cellMeasure, cell, borders, renderLine, context, applySdtDataset } = deps;
69091
+ const {
69092
+ doc: doc2,
69093
+ x: x2,
69094
+ y: y2,
69095
+ rowHeight,
69096
+ cellMeasure,
69097
+ cell,
69098
+ borders,
69099
+ renderLine,
69100
+ context,
69101
+ applySdtDataset,
69102
+ fromLine,
69103
+ toLine
69104
+ } = deps;
68052
69105
  const cellEl = doc2.createElement("div");
68053
69106
  cellEl.style.position = "absolute";
68054
69107
  cellEl.style.left = `${x2}px`;
@@ -68056,6 +69109,7 @@ const renderTableCell = (deps) => {
68056
69109
  cellEl.style.width = `${cellMeasure.width}px`;
68057
69110
  cellEl.style.height = `${rowHeight}px`;
68058
69111
  cellEl.style.boxSizing = "border-box";
69112
+ cellEl.style.overflow = "hidden";
68059
69113
  if (borders) {
68060
69114
  applyCellBorders(cellEl, borders);
68061
69115
  }
@@ -68069,36 +69123,87 @@ const renderTableCell = (deps) => {
68069
69123
  }
68070
69124
  let contentElement;
68071
69125
  const attrs = cell?.attrs;
68072
- const padding = attrs?.padding || { top: 2, left: 4, right: 4 };
69126
+ const padding = attrs?.padding || { top: 2, left: 4, right: 4, bottom: 2 };
68073
69127
  const paddingLeft = padding.left ?? 4;
68074
69128
  const paddingTop = padding.top ?? 2;
68075
69129
  const paddingRight = padding.right ?? 4;
69130
+ const paddingBottom = padding.bottom ?? 2;
68076
69131
  const cellBlocks = cell?.blocks ?? (cell?.paragraph ? [cell.paragraph] : []);
68077
- const blockMeasures = cellMeasure.blocks ?? (cellMeasure.paragraph ? [cellMeasure.paragraph] : []);
69132
+ const blockMeasures = cellMeasure?.blocks ?? (cellMeasure?.paragraph ? [cellMeasure.paragraph] : []);
68078
69133
  if (cellBlocks.length > 0 && blockMeasures.length > 0) {
68079
69134
  const content = doc2.createElement("div");
68080
69135
  content.style.position = "absolute";
68081
69136
  content.style.left = `${x2 + paddingLeft}px`;
68082
69137
  content.style.top = `${y2 + paddingTop}px`;
68083
- content.style.width = `${Math.max(0, cellMeasure.width - paddingLeft - paddingRight)}px`;
68084
- let blockY = 0;
69138
+ const contentWidth = Math.max(0, cellMeasure.width - paddingLeft - paddingRight);
69139
+ const contentHeight = Math.max(0, rowHeight - paddingTop - paddingBottom);
69140
+ content.style.width = `${contentWidth + 1}px`;
69141
+ content.style.height = `${contentHeight}px`;
69142
+ content.style.display = "flex";
69143
+ content.style.flexDirection = "column";
69144
+ content.style.overflowX = "visible";
69145
+ content.style.overflowY = "hidden";
69146
+ if (cell?.attrs?.verticalAlign === "center") {
69147
+ content.style.justifyContent = "center";
69148
+ } else if (cell?.attrs?.verticalAlign === "bottom") {
69149
+ content.style.justifyContent = "flex-end";
69150
+ } else {
69151
+ content.style.justifyContent = "flex-start";
69152
+ }
69153
+ const blockLineCounts = [];
69154
+ for (let i = 0; i < Math.min(blockMeasures.length, cellBlocks.length); i++) {
69155
+ const bm = blockMeasures[i];
69156
+ if (bm.kind === "paragraph") {
69157
+ blockLineCounts.push(bm.lines?.length || 0);
69158
+ } else {
69159
+ blockLineCounts.push(0);
69160
+ }
69161
+ }
69162
+ const totalLines = blockLineCounts.reduce((a, b2) => a + b2, 0);
69163
+ const globalFromLine = fromLine ?? 0;
69164
+ const globalToLine = toLine === -1 || toLine === void 0 ? totalLines : toLine;
69165
+ let cumulativeLineCount = 0;
68085
69166
  for (let i = 0; i < Math.min(blockMeasures.length, cellBlocks.length); i++) {
68086
69167
  const blockMeasure = blockMeasures[i];
68087
69168
  const block = cellBlocks[i];
68088
69169
  if (blockMeasure.kind === "paragraph" && block?.kind === "paragraph") {
69170
+ const lines = blockMeasure.lines;
69171
+ const blockLineCount = lines?.length || 0;
69172
+ const blockStartGlobal = cumulativeLineCount;
69173
+ const blockEndGlobal = cumulativeLineCount + blockLineCount;
69174
+ if (blockEndGlobal <= globalFromLine) {
69175
+ cumulativeLineCount += blockLineCount;
69176
+ continue;
69177
+ }
69178
+ if (blockStartGlobal >= globalToLine) {
69179
+ cumulativeLineCount += blockLineCount;
69180
+ continue;
69181
+ }
69182
+ const localStartLine = Math.max(0, globalFromLine - blockStartGlobal);
69183
+ const localEndLine = Math.min(blockLineCount, globalToLine - blockStartGlobal);
68089
69184
  const paraWrapper = doc2.createElement("div");
68090
- paraWrapper.style.position = "absolute";
68091
- paraWrapper.style.top = `${blockY}px`;
69185
+ paraWrapper.style.position = "relative";
68092
69186
  paraWrapper.style.left = "0";
68093
69187
  paraWrapper.style.width = "100%";
68094
69188
  applySdtDataset(paraWrapper, block.attrs?.sdt);
68095
- const lines = blockMeasure.lines;
68096
- lines.forEach((line) => {
69189
+ let renderedHeight = 0;
69190
+ for (let lineIdx = localStartLine; lineIdx < localEndLine && lineIdx < lines.length; lineIdx++) {
69191
+ const line = lines[lineIdx];
68097
69192
  const lineEl = renderLine(block, line, { ...context, section: "body" });
68098
69193
  paraWrapper.appendChild(lineEl);
68099
- });
69194
+ renderedHeight += line.lineHeight;
69195
+ }
69196
+ const renderedEntireBlock = localStartLine === 0 && localEndLine >= blockLineCount;
69197
+ if (renderedEntireBlock && blockMeasure.totalHeight && blockMeasure.totalHeight > renderedHeight) {
69198
+ renderedHeight = blockMeasure.totalHeight;
69199
+ }
68100
69200
  content.appendChild(paraWrapper);
68101
- blockY += blockMeasure.totalHeight;
69201
+ if (renderedHeight > 0) {
69202
+ paraWrapper.style.height = `${renderedHeight}px`;
69203
+ }
69204
+ cumulativeLineCount += blockLineCount;
69205
+ } else {
69206
+ cumulativeLineCount += 0;
68102
69207
  }
68103
69208
  }
68104
69209
  contentElement = content;
@@ -68119,7 +69224,10 @@ const renderTableRow = (deps) => {
68119
69224
  allRowHeights,
68120
69225
  context,
68121
69226
  renderLine,
68122
- applySdtDataset
69227
+ applySdtDataset,
69228
+ continuesFromPrev,
69229
+ continuesOnNext,
69230
+ partialRow
68123
69231
  } = deps;
68124
69232
  const calculateXPosition = (gridColumnStart) => {
68125
69233
  let x2 = 0;
@@ -68152,25 +69260,57 @@ const renderTableRow = (deps) => {
68152
69260
  const isLastRow = rowIndex === totalRows - 1;
68153
69261
  const isFirstCol = gridColIndex === 0;
68154
69262
  const isLastCol = gridColIndex === totalCols - 1;
69263
+ const treatAsFirstRow = isFirstRow || continuesFromPrev;
69264
+ const treatAsLastRow = isLastRow || continuesOnNext;
68155
69265
  resolvedBorders = {
68156
- // For top: use cell's if defined, otherwise use table's top for first row
68157
- top: cellBordersAttr.top ?? borderValueToSpec(isFirstRow ? tableBorders.top : tableBorders.insideH),
68158
- // For bottom: use cell's if defined, otherwise use table's bottom for last row only
68159
- bottom: cellBordersAttr.bottom ?? borderValueToSpec(isLastRow ? tableBorders.bottom : void 0),
69266
+ // For top: use cell's if defined, otherwise use table's top border for first row OR continuation
69267
+ top: cellBordersAttr.top ?? borderValueToSpec(treatAsFirstRow ? tableBorders.top : tableBorders.insideH),
69268
+ // For bottom: use cell's if defined, otherwise use table's bottom border for last row OR before continuation
69269
+ bottom: cellBordersAttr.bottom ?? borderValueToSpec(treatAsLastRow ? tableBorders.bottom : void 0),
68160
69270
  // For left: use cell's if defined, otherwise use table's left for first col
68161
69271
  left: cellBordersAttr.left ?? borderValueToSpec(isFirstCol ? tableBorders.left : tableBorders.insideV),
68162
69272
  // For right: use cell's if defined, otherwise use table's right for last col only
68163
69273
  right: cellBordersAttr.right ?? borderValueToSpec(isLastCol ? tableBorders.right : void 0)
68164
69274
  };
68165
69275
  } else if (hasExplicitBorders) {
68166
- resolvedBorders = cellBordersAttr;
69276
+ resolvedBorders = {
69277
+ top: cellBordersAttr.top,
69278
+ bottom: cellBordersAttr.bottom,
69279
+ left: cellBordersAttr.left,
69280
+ right: cellBordersAttr.right
69281
+ };
68167
69282
  } else if (tableBorders) {
68168
- resolvedBorders = resolveTableCellBorders(tableBorders, rowIndex, gridColIndex, totalRows, totalCols);
69283
+ const isFirstRow = rowIndex === 0;
69284
+ const isLastRow = rowIndex === totalRows - 1;
69285
+ const treatAsFirstRow = isFirstRow || continuesFromPrev;
69286
+ const treatAsLastRow = isLastRow || continuesOnNext;
69287
+ const baseBorders = resolveTableCellBorders(tableBorders, rowIndex, gridColIndex, totalRows, totalCols);
69288
+ if (baseBorders) {
69289
+ resolvedBorders = {
69290
+ // If this is a continuation (continuesFromPrev), use table's top border
69291
+ top: treatAsFirstRow ? borderValueToSpec(tableBorders.top) : baseBorders.top,
69292
+ // If this continues on next (continuesOnNext), use table's bottom border
69293
+ bottom: treatAsLastRow ? borderValueToSpec(tableBorders.bottom) : baseBorders.bottom,
69294
+ left: baseBorders.left,
69295
+ right: baseBorders.right
69296
+ };
69297
+ } else {
69298
+ resolvedBorders = void 0;
69299
+ }
68169
69300
  } else {
68170
69301
  resolvedBorders = void 0;
68171
69302
  }
68172
69303
  const rowSpan = cellMeasure.rowSpan ?? 1;
68173
- const cellHeight = rowSpan > 1 ? calculateRowspanHeight(rowIndex, rowSpan) : rowMeasure.height;
69304
+ let cellHeight;
69305
+ if (partialRow) {
69306
+ cellHeight = partialRow.partialHeight;
69307
+ } else if (rowSpan > 1) {
69308
+ cellHeight = calculateRowspanHeight(rowIndex, rowSpan);
69309
+ } else {
69310
+ cellHeight = rowMeasure.height;
69311
+ }
69312
+ const fromLine = partialRow?.fromLineByCell?.[cellIndex];
69313
+ const toLine = partialRow?.toLineByCell?.[cellIndex];
68174
69314
  const { cellElement, contentElement } = renderTableCell({
68175
69315
  doc: doc2,
68176
69316
  x: x2,
@@ -68181,7 +69321,9 @@ const renderTableRow = (deps) => {
68181
69321
  borders: resolvedBorders,
68182
69322
  renderLine,
68183
69323
  context,
68184
- applySdtDataset
69324
+ applySdtDataset,
69325
+ fromLine,
69326
+ toLine
68185
69327
  });
68186
69328
  container.appendChild(cellElement);
68187
69329
  if (contentElement) {
@@ -68295,11 +69437,46 @@ const renderTableFragment = (deps) => {
68295
69437
  if (borderCollapse === "separate" && block.attrs?.cellSpacing) {
68296
69438
  container.style.borderSpacing = `${block.attrs.cellSpacing}px`;
68297
69439
  }
68298
- const allRowHeights = measure.rows.map((r2) => r2.height);
69440
+ const allRowHeights = measure.rows.map((r2, idx) => {
69441
+ if (fragment.partialRow && fragment.partialRow.rowIndex === idx) {
69442
+ return fragment.partialRow.partialHeight;
69443
+ }
69444
+ return r2?.height ?? 0;
69445
+ });
68299
69446
  let y2 = 0;
69447
+ if (fragment.repeatHeaderCount && fragment.repeatHeaderCount > 0) {
69448
+ for (let r2 = 0; r2 < fragment.repeatHeaderCount; r2 += 1) {
69449
+ const rowMeasure = measure.rows[r2];
69450
+ if (!rowMeasure) break;
69451
+ renderTableRow({
69452
+ doc: doc2,
69453
+ container,
69454
+ rowIndex: r2,
69455
+ y: y2,
69456
+ rowMeasure,
69457
+ row: block.rows[r2],
69458
+ totalRows: block.rows.length,
69459
+ tableBorders,
69460
+ columnWidths: measure.columnWidths,
69461
+ allRowHeights,
69462
+ context,
69463
+ renderLine,
69464
+ applySdtDataset,
69465
+ // Headers are always rendered as-is (no border suppression)
69466
+ continuesFromPrev: false,
69467
+ continuesOnNext: false
69468
+ });
69469
+ y2 += rowMeasure.height;
69470
+ }
69471
+ }
68300
69472
  for (let r2 = fragment.fromRow; r2 < fragment.toRow; r2 += 1) {
68301
69473
  const rowMeasure = measure.rows[r2];
68302
69474
  if (!rowMeasure) break;
69475
+ const isFirstRenderedBodyRow = r2 === fragment.fromRow;
69476
+ const isLastRenderedBodyRow = r2 === fragment.toRow - 1;
69477
+ const isPartialRow = fragment.partialRow && fragment.partialRow.rowIndex === r2;
69478
+ const partialRowData = isPartialRow ? fragment.partialRow : void 0;
69479
+ const actualRowHeight = partialRowData ? partialRowData.partialHeight : rowMeasure.height;
68303
69480
  renderTableRow({
68304
69481
  doc: doc2,
68305
69482
  container,
@@ -68313,9 +69490,15 @@ const renderTableFragment = (deps) => {
68313
69490
  allRowHeights,
68314
69491
  context,
68315
69492
  renderLine,
68316
- applySdtDataset
69493
+ applySdtDataset,
69494
+ // Draw top border if table continues from previous fragment (MS Word behavior)
69495
+ continuesFromPrev: isFirstRenderedBodyRow && fragment.continuesFromPrev === true,
69496
+ // Draw bottom border if table continues on next fragment (MS Word behavior)
69497
+ continuesOnNext: isLastRenderedBodyRow && fragment.continuesOnNext === true,
69498
+ // Pass partial row data for mid-row splits
69499
+ partialRow: partialRowData
68317
69500
  });
68318
- y2 += rowMeasure.height;
69501
+ y2 += actualRowHeight;
68319
69502
  }
68320
69503
  return container;
68321
69504
  };
@@ -68410,6 +69593,7 @@ function assertFragmentPmPositions(fragment, context) {
68410
69593
  }
68411
69594
  }
68412
69595
  const LIST_MARKER_GAP$1 = 8;
69596
+ const DEFAULT_TAB_INTERVAL_PX$1 = 48;
68413
69597
  const COMMENT_EXTERNAL_COLOR = "#B1124B";
68414
69598
  const COMMENT_INTERNAL_COLOR = "#078383";
68415
69599
  const COMMENT_INACTIVE_ALPHA = "22";
@@ -69206,33 +70390,41 @@ const _DomPainter = class _DomPainter2 {
69206
70390
  const firstLineOffset = (paraIndent?.firstLine ?? 0) - (paraIndent?.hanging ?? 0);
69207
70391
  lines.forEach((line, index2) => {
69208
70392
  const lineEl = this.renderLine(block, line, context);
69209
- if (paraIndentLeft) {
70393
+ const isListFirstLine = index2 === 0 && !fragment.continuesFromPrev && fragment.markerWidth && wordLayout?.marker;
70394
+ if (paraIndentLeft && !isListFirstLine) {
69210
70395
  lineEl.style.paddingLeft = `${paraIndentLeft}px`;
69211
70396
  }
69212
70397
  if (paraIndentRight) {
69213
70398
  lineEl.style.paddingRight = `${paraIndentRight}px`;
69214
70399
  }
69215
- if (!fragment.continuesFromPrev && index2 === 0 && firstLineOffset) {
70400
+ if (!fragment.continuesFromPrev && index2 === 0 && firstLineOffset && !isListFirstLine) {
69216
70401
  lineEl.style.textIndent = `${firstLineOffset}px`;
69217
- } else if (firstLineOffset) {
70402
+ } else if (firstLineOffset && !isListFirstLine) {
69218
70403
  lineEl.style.textIndent = "0px";
69219
70404
  }
69220
- if (index2 === 0 && !fragment.continuesFromPrev && fragment.markerWidth && wordLayout?.marker) {
70405
+ if (isListFirstLine && wordLayout?.marker && fragment.markerWidth) {
70406
+ const markerStartPos = paraIndentLeft - (paraIndent?.hanging ?? 0);
70407
+ lineEl.style.paddingLeft = `${markerStartPos}px`;
69221
70408
  const markerContainer = this.doc.createElement("span");
69222
70409
  markerContainer.style.display = "inline-block";
69223
70410
  const markerEl = this.doc.createElement("span");
69224
70411
  markerEl.classList.add("superdoc-paragraph-marker");
69225
70412
  markerEl.textContent = wordLayout.marker.markerText ?? "";
69226
- markerEl.style.width = `${fragment.markerWidth}px`;
69227
- markerEl.style.textAlign = wordLayout.marker.justification ?? "right";
69228
- markerEl.style.paddingRight = `${LIST_MARKER_GAP$1}px`;
69229
70413
  markerEl.style.pointerEvents = "none";
69230
- const indentLeft = paraIndentLeft;
69231
- const hanging = paraIndent?.hanging ?? 0;
69232
- const textStartX = indentLeft - hanging;
69233
- const markerLeftX = textStartX - fragment.markerWidth;
69234
- markerEl.style.position = "relative";
69235
- markerEl.style.left = `${markerLeftX}px`;
70414
+ const markerJustification = wordLayout.marker.justification ?? "left";
70415
+ if (markerJustification !== "left") {
70416
+ markerEl.style.width = `${fragment.markerWidth}px`;
70417
+ markerEl.style.textAlign = wordLayout.marker.justification ?? "right";
70418
+ markerEl.style.paddingRight = `${LIST_MARKER_GAP$1}px`;
70419
+ }
70420
+ if (markerJustification === "left") {
70421
+ markerContainer.style.position = "relative";
70422
+ } else {
70423
+ const markerLeftX = markerStartPos - fragment.markerWidth;
70424
+ markerContainer.style.position = "absolute";
70425
+ markerContainer.style.left = `${markerLeftX}px`;
70426
+ markerContainer.style.top = "0";
70427
+ }
69236
70428
  markerEl.style.fontFamily = wordLayout.marker.run.fontFamily;
69237
70429
  markerEl.style.fontSize = `${wordLayout.marker.run.fontSize}px`;
69238
70430
  markerEl.style.fontWeight = wordLayout.marker.run.bold ? "bold" : "";
@@ -69249,12 +70441,25 @@ const _DomPainter = class _DomPainter2 {
69249
70441
  const tabEl = this.doc.createElement("span");
69250
70442
  tabEl.className = "superdoc-tab";
69251
70443
  tabEl.innerHTML = "&nbsp;";
69252
- const gutterWidth = typeof wordLayout.marker.gutterWidthPx === "number" && isFinite(wordLayout.marker.gutterWidthPx) && wordLayout.marker.gutterWidthPx > 0 ? wordLayout.marker.gutterWidthPx : LIST_MARKER_GAP$1;
70444
+ let tabWidth;
70445
+ const markerBoxWidth = fragment.markerWidth;
70446
+ const markerTextWidth = fragment.markerTextWidth != null && isFinite(fragment.markerTextWidth) && fragment.markerTextWidth >= 0 ? fragment.markerTextWidth : markerBoxWidth;
70447
+ if ((wordLayout.marker.justification ?? "left") === "left") {
70448
+ const currentPos = markerStartPos + markerTextWidth;
70449
+ const implicitTabStop = paraIndentLeft;
70450
+ tabWidth = implicitTabStop - currentPos;
70451
+ if (tabWidth < 1) {
70452
+ tabWidth = DEFAULT_TAB_INTERVAL_PX$1 - currentPos % DEFAULT_TAB_INTERVAL_PX$1;
70453
+ if (tabWidth === 0) tabWidth = DEFAULT_TAB_INTERVAL_PX$1;
70454
+ }
70455
+ } else {
70456
+ tabWidth = fragment.markerGutter != null && isFinite(fragment.markerGutter) ? fragment.markerGutter : typeof wordLayout.marker.gutterWidthPx === "number" && isFinite(wordLayout.marker.gutterWidthPx) && wordLayout.marker.gutterWidthPx > 0 ? wordLayout.marker.gutterWidthPx : LIST_MARKER_GAP$1;
70457
+ }
69253
70458
  tabEl.style.display = "inline-block";
69254
- tabEl.style.width = `${gutterWidth}px`;
69255
- markerContainer.appendChild(tabEl);
70459
+ tabEl.style.width = `${tabWidth}px`;
70460
+ lineEl.prepend(tabEl);
69256
70461
  } else if (suffix2 === "space") {
69257
- markerContainer.appendChild(this.doc.createTextNode(" "));
70462
+ lineEl.prepend(this.doc.createTextNode(" "));
69258
70463
  }
69259
70464
  lineEl.prepend(markerContainer);
69260
70465
  }
@@ -70103,6 +71308,12 @@ const _DomPainter = class _DomPainter2 {
70103
71308
  isLineBreakRun(run2) {
70104
71309
  return run2.kind === "lineBreak";
70105
71310
  }
71311
+ /**
71312
+ * Type guard to check if a run is a break run.
71313
+ */
71314
+ isBreakRun(run2) {
71315
+ return run2.kind === "break";
71316
+ }
70106
71317
  renderRun(run2, context, trackedConfig) {
70107
71318
  if (this.isImageRun(run2)) {
70108
71319
  return this.renderImageRun(run2);
@@ -70110,7 +71321,10 @@ const _DomPainter = class _DomPainter2 {
70110
71321
  if (this.isLineBreakRun(run2)) {
70111
71322
  return null;
70112
71323
  }
70113
- if (!run2.text || !this.doc) {
71324
+ if (this.isBreakRun(run2)) {
71325
+ return null;
71326
+ }
71327
+ if (!("text" in run2) || !run2.text || !this.doc) {
70114
71328
  return null;
70115
71329
  }
70116
71330
  const linkData = this.extractLinkData(run2);
@@ -70251,6 +71465,12 @@ const _DomPainter = class _DomPainter2 {
70251
71465
  if (styleId) {
70252
71466
  el.setAttribute("styleid", styleId);
70253
71467
  }
71468
+ const alignment2 = block.attrs?.alignment;
71469
+ if (alignment2 === "center" || alignment2 === "right" || alignment2 === "justify") {
71470
+ el.style.textAlign = alignment2 === "justify" ? "justify" : alignment2;
71471
+ } else {
71472
+ el.style.textAlign = "left";
71473
+ }
70254
71474
  const lineRange = computeLinePmRange(block, line);
70255
71475
  if (lineRange.pmStart != null) {
70256
71476
  el.dataset.pmStart = String(lineRange.pmStart);
@@ -70368,10 +71588,16 @@ const _DomPainter = class _DomPainter2 {
70368
71588
  if (this.isLineBreakRun(baseRun)) {
70369
71589
  continue;
70370
71590
  }
71591
+ if (this.isBreakRun(baseRun)) {
71592
+ continue;
71593
+ }
70371
71594
  const runSegments = segmentsByRun.get(runIndex);
70372
71595
  if (!runSegments || runSegments.length === 0) {
70373
71596
  continue;
70374
71597
  }
71598
+ if (!("text" in baseRun)) {
71599
+ continue;
71600
+ }
70375
71601
  const baseText = baseRun.text ?? "";
70376
71602
  const runPmStart = baseRun.pmStart ?? null;
70377
71603
  const fallbackPmEnd = runPmStart != null && baseRun.pmEnd == null ? runPmStart + baseText.length : baseRun.pmEnd ?? null;
@@ -70690,7 +71916,12 @@ const fragmentKey = (fragment) => {
70690
71916
  if (fragment.kind === "drawing") {
70691
71917
  return `drawing:${fragment.blockId}:${fragment.x}:${fragment.y}`;
70692
71918
  }
70693
- return `${fragment.kind}:${fragment.blockId}`;
71919
+ if (fragment.kind === "table") {
71920
+ const partialKey = fragment.partialRow ? `:${fragment.partialRow.fromLineByCell.join(",")}-${fragment.partialRow.toLineByCell.join(",")}` : "";
71921
+ return `table:${fragment.blockId}:${fragment.fromRow}:${fragment.toRow}${partialKey}`;
71922
+ }
71923
+ const _exhaustiveCheck = fragment;
71924
+ return _exhaustiveCheck;
70694
71925
  };
70695
71926
  const fragmentSignature = (fragment, lookup2) => {
70696
71927
  const base2 = lookup2.get(fragment.blockId)?.version ?? "missing";
@@ -70702,7 +71933,9 @@ const fragmentSignature = (fragment, lookup2) => {
70702
71933
  fragment.pmStart ?? "",
70703
71934
  fragment.pmEnd ?? "",
70704
71935
  fragment.continuesFromPrev ? 1 : 0,
70705
- fragment.continuesOnNext ? 1 : 0
71936
+ fragment.continuesOnNext ? 1 : 0,
71937
+ fragment.markerWidth ?? ""
71938
+ // Include markerWidth to trigger re-render when list status changes
70706
71939
  ].join("|");
70707
71940
  }
70708
71941
  if (fragment.kind === "list-item") {
@@ -70732,6 +71965,20 @@ const fragmentSignature = (fragment, lookup2) => {
70732
71965
  fragment.zIndex ?? ""
70733
71966
  ].join("|");
70734
71967
  }
71968
+ if (fragment.kind === "table") {
71969
+ const partialSig = fragment.partialRow ? `${fragment.partialRow.fromLineByCell.join(",")}-${fragment.partialRow.toLineByCell.join(",")}-${fragment.partialRow.partialHeight}` : "";
71970
+ return [
71971
+ base2,
71972
+ fragment.fromRow,
71973
+ fragment.toRow,
71974
+ fragment.width,
71975
+ fragment.height,
71976
+ fragment.continuesFromPrev ? 1 : 0,
71977
+ fragment.continuesOnNext ? 1 : 0,
71978
+ fragment.repeatHeaderCount ?? 0,
71979
+ partialSig
71980
+ ].join("|");
71981
+ }
70735
71982
  return base2;
70736
71983
  };
70737
71984
  const deriveBlockVersion = (block) => {
@@ -70877,7 +72124,7 @@ const deriveBlockVersion = (block) => {
70877
72124
  return block.id;
70878
72125
  };
70879
72126
  const applyRunStyles = (element, run2, isLink = false) => {
70880
- if (run2.kind === "tab" || run2.kind === "image" || run2.kind === "lineBreak") {
72127
+ if (run2.kind === "tab" || run2.kind === "image" || run2.kind === "lineBreak" || run2.kind === "break") {
70881
72128
  return;
70882
72129
  }
70883
72130
  element.style.fontFamily = run2.fontFamily;
@@ -71011,6 +72258,17 @@ const sliceRunsForLine = (block, line) => {
71011
72258
  result.push(run2);
71012
72259
  continue;
71013
72260
  }
72261
+ if (run2.kind === "break") {
72262
+ result.push(run2);
72263
+ continue;
72264
+ }
72265
+ if (run2.kind === "tab") {
72266
+ result.push(run2);
72267
+ continue;
72268
+ }
72269
+ if (!("text" in run2)) {
72270
+ continue;
72271
+ }
71014
72272
  const text = run2.text ?? "";
71015
72273
  const isFirstRun = runIndex === line.fromRun;
71016
72274
  const isLastRun = runIndex === line.toRun;
@@ -71024,20 +72282,14 @@ const sliceRunsForLine = (block, line) => {
71024
72282
  if (!slice2) continue;
71025
72283
  const pmSliceStart = runPmStart != null ? runPmStart + start2 : void 0;
71026
72284
  const pmSliceEnd = runPmStart != null ? runPmStart + end2 : fallbackPmEnd ?? void 0;
71027
- if (run2.kind === "tab") {
71028
- if (slice2.includes(" ")) {
71029
- result.push(run2);
71030
- }
71031
- } else {
71032
- const sliced = {
71033
- ...run2,
71034
- text: slice2,
71035
- pmStart: pmSliceStart,
71036
- pmEnd: pmSliceEnd,
71037
- comments: run2.comments ? [...run2.comments] : void 0
71038
- };
71039
- result.push(sliced);
71040
- }
72285
+ const sliced = {
72286
+ ...run2,
72287
+ text: slice2,
72288
+ pmStart: pmSliceStart,
72289
+ pmEnd: pmSliceEnd,
72290
+ comments: run2.comments ? [...run2.comments] : void 0
72291
+ };
72292
+ result.push(sliced);
71041
72293
  } else {
71042
72294
  result.push(run2);
71043
72295
  }
@@ -71080,6 +72332,39 @@ const computeLinePmRange = (block, line) => {
71080
72332
  }
71081
72333
  continue;
71082
72334
  }
72335
+ if (run2.kind === "break") {
72336
+ const runPmStart2 = run2.pmStart ?? null;
72337
+ const runPmEnd = run2.pmEnd ?? null;
72338
+ if (runPmStart2 == null || runPmEnd == null) {
72339
+ continue;
72340
+ }
72341
+ if (pmStart == null) {
72342
+ pmStart = runPmStart2;
72343
+ }
72344
+ pmEnd = runPmEnd;
72345
+ if (runIndex === line.toRun) {
72346
+ break;
72347
+ }
72348
+ continue;
72349
+ }
72350
+ if (run2.kind === "tab") {
72351
+ const runPmStart2 = run2.pmStart ?? null;
72352
+ const runPmEnd = run2.pmEnd ?? null;
72353
+ if (runPmStart2 == null || runPmEnd == null) {
72354
+ continue;
72355
+ }
72356
+ if (pmStart == null) {
72357
+ pmStart = runPmStart2;
72358
+ }
72359
+ pmEnd = runPmEnd;
72360
+ if (runIndex === line.toRun) {
72361
+ break;
72362
+ }
72363
+ continue;
72364
+ }
72365
+ if (!("text" in run2)) {
72366
+ continue;
72367
+ }
71083
72368
  const text = run2.text ?? "";
71084
72369
  const runLength = text.length;
71085
72370
  const runPmStart = run2.pmStart ?? null;
@@ -71121,6 +72406,12 @@ const resolveRunText = (run2, context) => {
71121
72406
  if (run2.kind === "lineBreak") {
71122
72407
  return "";
71123
72408
  }
72409
+ if (run2.kind === "break") {
72410
+ return "";
72411
+ }
72412
+ if (!("text" in run2)) {
72413
+ return "";
72414
+ }
71124
72415
  if (!runToken) {
71125
72416
  return run2.text ?? "";
71126
72417
  }
@@ -71318,6 +72609,7 @@ async function measureBlock(block, constraints) {
71318
72609
  async function measureParagraphBlock(block, maxWidth) {
71319
72610
  const ctx2 = getCanvasContext();
71320
72611
  const wordLayout = block.attrs?.wordLayout;
72612
+ const WIDTH_FUDGE_PX = 0.5;
71321
72613
  const lines = [];
71322
72614
  const indent = block.attrs?.indent;
71323
72615
  const spacing = block.attrs?.spacing;
@@ -71412,8 +72704,67 @@ async function measureParagraphBlock(block, maxWidth) {
71412
72704
  lastAppliedTabAlign = { target, val };
71413
72705
  pendingTabAlignment = null;
71414
72706
  };
71415
- for (let runIndex = 0; runIndex < block.runs.length; runIndex++) {
71416
- const run2 = block.runs[runIndex];
72707
+ const runsToProcess = [];
72708
+ for (const run2 of block.runs) {
72709
+ if (run2.text && typeof run2.text === "string" && run2.text.includes("\n")) {
72710
+ const textRun = run2;
72711
+ const segments = textRun.text.split("\n");
72712
+ let cursor = textRun.pmStart ?? 0;
72713
+ segments.forEach((seg, idx) => {
72714
+ runsToProcess.push({
72715
+ ...textRun,
72716
+ text: seg,
72717
+ pmStart: cursor,
72718
+ pmEnd: cursor + seg.length
72719
+ });
72720
+ cursor += seg.length;
72721
+ if (idx !== segments.length - 1) {
72722
+ runsToProcess.push({
72723
+ kind: "break",
72724
+ breakType: "line",
72725
+ pmStart: cursor,
72726
+ pmEnd: cursor + 1,
72727
+ sdt: run2.sdt
72728
+ });
72729
+ cursor += 1;
72730
+ }
72731
+ });
72732
+ } else {
72733
+ runsToProcess.push(run2);
72734
+ }
72735
+ }
72736
+ for (let runIndex = 0; runIndex < runsToProcess.length; runIndex++) {
72737
+ const run2 = runsToProcess[runIndex];
72738
+ if (run2.kind === "break") {
72739
+ if (currentLine) {
72740
+ const metrics = calculateTypographyMetrics(currentLine.maxFontSize, spacing);
72741
+ const completedLine = { ...currentLine, ...metrics };
72742
+ addBarTabsToLine(completedLine);
72743
+ lines.push(completedLine);
72744
+ currentLine = null;
72745
+ } else {
72746
+ const textRunWithSize = block.runs.find(
72747
+ (r2) => r2.kind !== "tab" && r2.kind !== "lineBreak" && r2.kind !== "break" && !("src" in r2) && "fontSize" in r2
72748
+ );
72749
+ const fallbackSize = textRunWithSize?.fontSize ?? 12;
72750
+ const metrics = calculateTypographyMetrics(fallbackSize, spacing);
72751
+ const emptyLine = {
72752
+ fromRun: runIndex,
72753
+ fromChar: 0,
72754
+ toRun: runIndex,
72755
+ toChar: 0,
72756
+ width: 0,
72757
+ segments: [],
72758
+ ...metrics
72759
+ };
72760
+ addBarTabsToLine(emptyLine);
72761
+ lines.push(emptyLine);
72762
+ }
72763
+ tabStopCursor = 0;
72764
+ pendingTabAlignment = null;
72765
+ lastAppliedTabAlign = null;
72766
+ continue;
72767
+ }
71417
72768
  if (isLineBreakRun(run2)) {
71418
72769
  if (currentLine) {
71419
72770
  const metrics = calculateTypographyMetrics(currentLine.maxFontSize, spacing);
@@ -71564,6 +72915,9 @@ async function measureParagraphBlock(block, maxWidth) {
71564
72915
  }
71565
72916
  continue;
71566
72917
  }
72918
+ if (!("text" in run2) || !("fontSize" in run2)) {
72919
+ continue;
72920
+ }
71567
72921
  lastFontSize = run2.fontSize;
71568
72922
  const { font } = buildFontString(run2);
71569
72923
  const tabSegments = run2.text.split(" ");
@@ -71603,18 +72957,18 @@ async function measureParagraphBlock(block, maxWidth) {
71603
72957
  segments: [{ runIndex, fromChar: wordStartChar, toChar: wordEndNoSpace, width: wordOnlyWidth }]
71604
72958
  };
71605
72959
  const ls = run2.letterSpacing ?? 0;
71606
- if (!isLastWord && currentLine.width + spaceWidth <= currentLine.maxWidth) {
72960
+ if (!isLastWord && currentLine.width + spaceWidth <= currentLine.maxWidth - WIDTH_FUDGE_PX) {
71607
72961
  currentLine.toChar = wordEndWithSpace;
71608
72962
  currentLine.width = roundValue(currentLine.width + spaceWidth + ls);
71609
72963
  charPosInRun = wordEndWithSpace;
71610
72964
  } else {
71611
- charPosInRun = wordEndNoSpace;
72965
+ charPosInRun = wordEndWithSpace;
71612
72966
  }
71613
72967
  continue;
71614
72968
  }
71615
72969
  const isTocEntry = block.attrs?.isTocEntry;
71616
72970
  const boundarySpacing = currentLine.width > 0 ? run2.letterSpacing ?? 0 : 0;
71617
- if (currentLine.width + boundarySpacing + wordOnlyWidth > currentLine.maxWidth && currentLine.width > 0 && !isTocEntry) {
72971
+ if (currentLine.width + boundarySpacing + wordOnlyWidth > currentLine.maxWidth - WIDTH_FUDGE_PX && currentLine.width > 0 && !isTocEntry) {
71618
72972
  const metrics = calculateTypographyMetrics(currentLine.maxFontSize, spacing);
71619
72973
  const completedLine = {
71620
72974
  ...currentLine,
@@ -71634,16 +72988,16 @@ async function measureParagraphBlock(block, maxWidth) {
71634
72988
  maxWidth: getEffectiveWidth(contentWidth),
71635
72989
  segments: [{ runIndex, fromChar: wordStartChar, toChar: wordEndNoSpace, width: wordOnlyWidth }]
71636
72990
  };
71637
- if (!isLastWord && currentLine.width + spaceWidth <= currentLine.maxWidth) {
72991
+ if (!isLastWord && currentLine.width + spaceWidth <= currentLine.maxWidth - WIDTH_FUDGE_PX) {
71638
72992
  currentLine.toChar = wordEndWithSpace;
71639
72993
  currentLine.width = roundValue(currentLine.width + spaceWidth + (run2.letterSpacing ?? 0));
71640
72994
  charPosInRun = wordEndWithSpace;
71641
72995
  } else {
71642
- charPosInRun = wordEndNoSpace;
72996
+ charPosInRun = wordEndWithSpace;
71643
72997
  }
71644
72998
  } else {
71645
72999
  currentLine.toRun = runIndex;
71646
- if (!isLastWord && currentLine.width + boundarySpacing + wordOnlyWidth + spaceWidth > currentLine.maxWidth) {
73000
+ if (!isLastWord && currentLine.width + boundarySpacing + wordOnlyWidth + spaceWidth > currentLine.maxWidth - WIDTH_FUDGE_PX) {
71647
73001
  currentLine.toChar = wordEndNoSpace;
71648
73002
  currentLine.width = roundValue(currentLine.width + boundarySpacing + wordOnlyWidth);
71649
73003
  currentLine.maxFontSize = Math.max(currentLine.maxFontSize, run2.fontSize);
@@ -71752,10 +73106,14 @@ async function measureParagraphBlock(block, maxWidth) {
71752
73106
  const { font: markerFont } = buildFontString(markerRun);
71753
73107
  const markerText = wordLayout.marker.markerText ?? "";
71754
73108
  const glyphWidth = markerText ? measureText(markerText, markerFont, ctx2) : 0;
73109
+ const gutter = typeof wordLayout.marker.gutterWidthPx === "number" && isFinite(wordLayout.marker.gutterWidthPx) && wordLayout.marker.gutterWidthPx >= 0 ? wordLayout.marker.gutterWidthPx : LIST_MARKER_GAP;
73110
+ const markerBoxWidth = Math.max(wordLayout.marker.markerBoxWidthPx ?? 0, glyphWidth + LIST_MARKER_GAP);
71755
73111
  markerInfo = {
71756
- markerWidth: Math.max(wordLayout.marker.markerBoxWidthPx ?? 0, glyphWidth + LIST_MARKER_GAP),
73112
+ markerWidth: markerBoxWidth,
71757
73113
  markerTextWidth: glyphWidth,
71758
- indentLeft: wordLayout.indentLeftPx ?? 0
73114
+ indentLeft: wordLayout.indentLeftPx ?? 0,
73115
+ // For tab sizing in the renderer: expose gutter for word-layout lists
73116
+ gutterWidth: gutter
71759
73117
  };
71760
73118
  }
71761
73119
  return {
@@ -71769,6 +73127,34 @@ async function measureParagraphBlock(block, maxWidth) {
71769
73127
  async function measureTableBlock(block, constraints) {
71770
73128
  const maxWidth = typeof constraints === "number" ? constraints : constraints.maxWidth;
71771
73129
  let columnWidths;
73130
+ const scaleColumnWidths = (widths, targetWidth) => {
73131
+ const totalWidth2 = widths.reduce((a, b2) => a + b2, 0);
73132
+ if (totalWidth2 <= targetWidth || widths.length === 0) return widths;
73133
+ const scale = targetWidth / totalWidth2;
73134
+ const scaled = widths.map((w2) => Math.max(1, Math.round(w2 * scale)));
73135
+ const sum = scaled.reduce((a, b2) => a + b2, 0);
73136
+ if (sum !== targetWidth) {
73137
+ const adjust = (delta) => {
73138
+ let idx = 0;
73139
+ const direction = delta > 0 ? 1 : -1;
73140
+ delta = Math.abs(delta);
73141
+ while (delta > 0 && scaled.length > 0) {
73142
+ const i = idx % scaled.length;
73143
+ if (direction > 0) {
73144
+ scaled[i] += 1;
73145
+ delta -= 1;
73146
+ } else if (scaled[i] > 1) {
73147
+ scaled[i] -= 1;
73148
+ delta -= 1;
73149
+ }
73150
+ idx += 1;
73151
+ if (idx > scaled.length * 2 && delta > 0) break;
73152
+ }
73153
+ };
73154
+ adjust(targetWidth - sum);
73155
+ }
73156
+ return scaled;
73157
+ };
71772
73158
  const maxCellCount = Math.max(1, Math.max(...block.rows.map((r2) => r2.cells.length)));
71773
73159
  if (block.columnWidths && block.columnWidths.length > 0) {
71774
73160
  columnWidths = [...block.columnWidths];
@@ -71777,8 +73163,7 @@ async function measureTableBlock(block, constraints) {
71777
73163
  if (hasExplicitWidth || hasFixedLayout) {
71778
73164
  const totalWidth2 = columnWidths.reduce((a, b2) => a + b2, 0);
71779
73165
  if (totalWidth2 > maxWidth) {
71780
- const scale = maxWidth / totalWidth2;
71781
- columnWidths = columnWidths.map((w2) => Math.max(1, Math.floor(w2 * scale)));
73166
+ columnWidths = scaleColumnWidths(columnWidths, maxWidth);
71782
73167
  }
71783
73168
  } else {
71784
73169
  if (columnWidths.length < maxCellCount) {
@@ -71792,8 +73177,7 @@ async function measureTableBlock(block, constraints) {
71792
73177
  }
71793
73178
  const totalWidth2 = columnWidths.reduce((a, b2) => a + b2, 0);
71794
73179
  if (totalWidth2 > maxWidth) {
71795
- const scale = maxWidth / totalWidth2;
71796
- columnWidths = columnWidths.map((w2) => Math.max(1, Math.floor(w2 * scale)));
73180
+ columnWidths = scaleColumnWidths(columnWidths, maxWidth);
71797
73181
  }
71798
73182
  }
71799
73183
  } else {
@@ -71810,6 +73194,8 @@ async function measureTableBlock(block, constraints) {
71810
73194
  };
71811
73195
  const rowspanTracker = new Array(gridColumnCount).fill(0);
71812
73196
  const rows = [];
73197
+ const rowBaseHeights = new Array(block.rows.length).fill(0);
73198
+ const spanConstraints = [];
71813
73199
  for (let rowIndex = 0; rowIndex < block.rows.length; rowIndex++) {
71814
73200
  const row = block.rows[rowIndex];
71815
73201
  const cellMeasures = [];
@@ -71856,6 +73242,11 @@ async function measureTableBlock(block, constraints) {
71856
73242
  colSpan: colspan,
71857
73243
  rowSpan: rowspan
71858
73244
  });
73245
+ if (rowspan === 1) {
73246
+ rowBaseHeights[rowIndex] = Math.max(rowBaseHeights[rowIndex], totalCellHeight);
73247
+ } else {
73248
+ spanConstraints.push({ startRow: rowIndex, rowSpan: rowspan, requiredHeight: totalCellHeight });
73249
+ }
71859
73250
  gridColIndex += colspan;
71860
73251
  }
71861
73252
  for (let col = gridColIndex; col < gridColumnCount; col++) {
@@ -71863,10 +73254,39 @@ async function measureTableBlock(block, constraints) {
71863
73254
  rowspanTracker[col]--;
71864
73255
  }
71865
73256
  }
71866
- const rowHeight = Math.max(0, ...cellMeasures.map((c2) => c2.height));
71867
- rows.push({ cells: cellMeasures, height: rowHeight });
73257
+ rows.push({ cells: cellMeasures, height: 0 });
73258
+ }
73259
+ const rowHeights = [...rowBaseHeights];
73260
+ for (const constraint of spanConstraints) {
73261
+ const { startRow, rowSpan, requiredHeight } = constraint;
73262
+ if (rowSpan <= 0) continue;
73263
+ let currentHeight = 0;
73264
+ for (let i = 0; i < rowSpan && startRow + i < rowHeights.length; i++) {
73265
+ currentHeight += rowHeights[startRow + i];
73266
+ }
73267
+ if (currentHeight < requiredHeight) {
73268
+ const spanLength = Math.min(rowSpan, rowHeights.length - startRow);
73269
+ const increment = spanLength > 0 ? (requiredHeight - currentHeight) / spanLength : 0;
73270
+ for (let i = 0; i < spanLength; i++) {
73271
+ rowHeights[startRow + i] += increment;
73272
+ }
73273
+ }
73274
+ }
73275
+ block.rows.forEach((row, index2) => {
73276
+ const spec = row.attrs?.rowHeight;
73277
+ if (spec?.value != null && Number.isFinite(spec.value)) {
73278
+ const rule = spec.rule ?? "atLeast";
73279
+ if (rule === "exact") {
73280
+ rowHeights[index2] = spec.value;
73281
+ } else {
73282
+ rowHeights[index2] = Math.max(rowHeights[index2], spec.value);
73283
+ }
73284
+ }
73285
+ });
73286
+ for (let i = 0; i < rows.length; i++) {
73287
+ rows[i].height = Math.max(0, rowHeights[i]);
71868
73288
  }
71869
- const totalHeight = rows.reduce((sum, r2) => sum + r2.height, 0);
73289
+ const totalHeight = rowHeights.reduce((sum, h) => sum + h, 0);
71870
73290
  const totalWidth = columnWidths.reduce((a, b2) => a + b2, 0);
71871
73291
  return {
71872
73292
  kind: "table",
@@ -72072,7 +73492,7 @@ const resolveLineHeight = (spacing, baseLineHeight) => {
72072
73492
  if (spacing.lineRule === "atLeast") {
72073
73493
  return Math.max(baseLineHeight, raw);
72074
73494
  }
72075
- return raw;
73495
+ return Math.max(baseLineHeight, raw);
72076
73496
  };
72077
73497
  const sanitizePositive = (value) => typeof value === "number" && Number.isFinite(value) ? Math.max(0, value) : 0;
72078
73498
  const sanitizeDecimalSeparator = (value) => {
@@ -77962,6 +79382,17 @@ const structuredContentHelpers = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ O
77962
79382
  parseTagObject
77963
79383
  }, Symbol.toStringTag, { value: "Module" }));
77964
79384
  const STRUCTURED_CONTENT_NAMES = ["structuredContent", "structuredContentBlock"];
79385
+ const findFirstTextNode = (node) => {
79386
+ let firstTextNode = null;
79387
+ node.descendants((child) => {
79388
+ if (child.isText) {
79389
+ firstTextNode = child;
79390
+ return false;
79391
+ }
79392
+ return true;
79393
+ });
79394
+ return firstTextNode;
79395
+ };
77965
79396
  const StructuredContentCommands = Extension.create({
77966
79397
  name: "structuredContentCommands",
77967
79398
  addCommands() {
@@ -78102,7 +79533,7 @@ const StructuredContentCommands = Extension.create({
78102
79533
  * @param {string} id - Unique identifier of the field
78103
79534
  * @param {StructuredContentUpdate} options
78104
79535
  * @example
78105
- * editor.commands.updateStructuredContentById('123', { text: 'Jane Doe' });
79536
+ * editor.commands.updateStructuredContentById('123', { text: 'Jane Doe', keepTextNodeStyles: true });
78106
79537
  * editor.commands.updateStructuredContentById('123', {
78107
79538
  * json: { type: 'text', text: 'Jane Doe' },
78108
79539
  * });
@@ -78123,7 +79554,9 @@ const StructuredContentCommands = Extension.create({
78123
79554
  const posTo = pos + node.nodeSize;
78124
79555
  let content = null;
78125
79556
  if (options.text) {
78126
- content = schema.text(options.text);
79557
+ const firstTextNode = options.keepTextNodeStyles === true ? findFirstTextNode(node) : null;
79558
+ const textMarks = firstTextNode ? firstTextNode.marks : [];
79559
+ content = schema.text(options.text, textMarks);
78127
79560
  }
78128
79561
  if (options.html) {
78129
79562
  const html = htmlHandler(options.html, editor);
@@ -78137,6 +79570,13 @@ const StructuredContentCommands = Extension.create({
78137
79570
  content = node.content;
78138
79571
  }
78139
79572
  const updatedNode = node.type.create({ ...node.attrs, ...options.attrs }, content, node.marks);
79573
+ try {
79574
+ const nodeForValidation = editor.validateJSON(updatedNode.toJSON());
79575
+ nodeForValidation.check();
79576
+ } catch (error) {
79577
+ console.error("Invalid content.", "Passed value:", content, "Error:", error);
79578
+ return false;
79579
+ }
78140
79580
  tr.replaceWith(posFrom, posTo, updatedNode);
78141
79581
  }
78142
79582
  return true;
@@ -78221,7 +79661,7 @@ const StructuredContentCommands = Extension.create({
78221
79661
  * @param {StructuredContentUpdate} options
78222
79662
  * @example
78223
79663
  * // Update all fields in the customer-info group
78224
- * editor.commands.updateStructuredContentByGroup('customer-info', { text: 'Jane Doe' });
79664
+ * editor.commands.updateStructuredContentByGroup('customer-info', { text: 'Jane Doe', keepTextNodeStyles: true });
78225
79665
  *
78226
79666
  * // Update block content in a group
78227
79667
  * editor.commands.updateStructuredContentByGroup('terms-section', {
@@ -78235,13 +79675,14 @@ const StructuredContentCommands = Extension.create({
78235
79675
  }
78236
79676
  const { schema } = editor;
78237
79677
  if (dispatch) {
78238
- structuredContentTags.forEach((structuredContent) => {
79678
+ const updates = [];
79679
+ for (const structuredContent of structuredContentTags) {
78239
79680
  const { pos, node } = structuredContent;
78240
- const posFrom = tr.mapping.map(pos);
78241
- const posTo = tr.mapping.map(pos + node.nodeSize);
78242
79681
  let content = null;
78243
79682
  if (options.text) {
78244
- content = schema.text(options.text);
79683
+ const firstTextNode = options.keepTextNodeStyles === true ? findFirstTextNode(node) : null;
79684
+ const textMarks = firstTextNode ? firstTextNode.marks : [];
79685
+ content = schema.text(options.text, textMarks);
78245
79686
  }
78246
79687
  if (options.html) {
78247
79688
  const html = htmlHandler(options.html, editor);
@@ -78255,11 +79696,23 @@ const StructuredContentCommands = Extension.create({
78255
79696
  content = node.content;
78256
79697
  }
78257
79698
  const updatedNode = node.type.create({ ...node.attrs, ...options.attrs }, content, node.marks);
79699
+ try {
79700
+ const nodeForValidation = editor.validateJSON(updatedNode.toJSON());
79701
+ nodeForValidation.check();
79702
+ } catch (error) {
79703
+ console.error("Invalid content.", "Passed value:", content, "Error:", error);
79704
+ return false;
79705
+ }
79706
+ updates.push({ pos, node, updatedNode });
79707
+ }
79708
+ for (const { pos, node, updatedNode } of updates) {
79709
+ const posFrom = tr.mapping.map(pos);
79710
+ const posTo = tr.mapping.map(pos + node.nodeSize);
78258
79711
  const currentNode = tr.doc.nodeAt(posFrom);
78259
79712
  if (currentNode && node.eq(currentNode)) {
78260
79713
  tr.replaceWith(posFrom, posTo, updatedNode);
78261
79714
  }
78262
- });
79715
+ }
78263
79716
  }
78264
79717
  return true;
78265
79718
  },
@@ -78835,61 +80288,153 @@ const Text = Node$1.create({
78835
80288
  return {};
78836
80289
  }
78837
80290
  });
78838
- const splitRun = () => (props) => {
78839
- const { state: state2, view, tr } = props;
78840
- const { $from, empty: empty2 } = state2.selection;
78841
- if (!empty2) return false;
78842
- if ($from.parent.type.name !== "run") return false;
78843
- const handled = splitBlockPatch(state2, (transaction) => {
78844
- view.dispatch(transaction);
78845
- });
78846
- if (handled) {
78847
- tr.setMeta("preventDispatch", true);
78848
- }
78849
- return handled;
78850
- };
78851
- function splitBlockPatch(state2, dispatch) {
78852
- let { $from } = state2.selection;
78853
- if (state2.selection instanceof NodeSelection && state2.selection.node.isBlock) {
78854
- if (!$from.parentOffset || !canSplit(state2.doc, $from.pos)) return false;
78855
- if (dispatch) dispatch(state2.tr.split($from.pos).scrollIntoView());
78856
- return true;
80291
+ const cleanupEmptyRunsPlugin = new Plugin({
80292
+ appendTransaction(trs, oldState, newState) {
80293
+ if (!trs.some((tr2) => tr2.docChanged)) return null;
80294
+ const { run: run2, paragraph } = newState.schema.nodes;
80295
+ if (!run2) return null;
80296
+ const ranges = [];
80297
+ trs.forEach((tr2) => {
80298
+ tr2.mapping.maps.forEach((map22) => {
80299
+ map22.forEach((oldStart, oldEnd, newStart, newEnd) => {
80300
+ if (newStart !== oldStart || oldEnd !== newEnd) ranges.push({ from: newStart, to: newEnd });
80301
+ });
80302
+ });
80303
+ });
80304
+ if (!ranges.length) return null;
80305
+ ranges.sort((a, b2) => a.from - b2.from);
80306
+ const merged = [];
80307
+ for (const r2 of ranges) {
80308
+ const from2 = Math.max(0, r2.from - 1);
80309
+ const to = Math.min(newState.doc.content.size, r2.to + 1);
80310
+ const last = merged[merged.length - 1];
80311
+ if (last && from2 <= last.to) last.to = Math.max(last.to, to);
80312
+ else merged.push({ from: from2, to });
80313
+ }
80314
+ const toDelete = [];
80315
+ merged.forEach(({ from: from2, to }) => {
80316
+ newState.doc.nodesBetween(from2, to, (node, pos, parent) => {
80317
+ if (node.type === run2 && node.content.size === 0 && parent?.type === paragraph) {
80318
+ toDelete.push({ from: pos, to: pos + node.nodeSize });
80319
+ }
80320
+ });
80321
+ });
80322
+ if (!toDelete.length) return null;
80323
+ const tr = newState.tr;
80324
+ toDelete.sort((a, b2) => b2.from - a.from).forEach(({ from: from2, to }) => tr.deleteRange(from2, to));
80325
+ return tr.docChanged ? tr : null;
78857
80326
  }
78858
- if (!$from.depth) return false;
78859
- let types2 = [];
78860
- let splitDepth, deflt, atEnd = false, atStart = false;
78861
- for (let d2 = $from.depth; ; d2--) {
78862
- let node = $from.node(d2);
78863
- if (node.isBlock) {
78864
- atEnd = $from.end(d2) == $from.pos + ($from.depth - d2);
78865
- atStart = $from.start(d2) == $from.pos - ($from.depth - d2);
78866
- deflt = defaultBlockAt$1($from.node(d2 - 1).contentMatchAt($from.indexAfter(d2 - 1)));
78867
- types2.unshift(null);
78868
- splitDepth = d2;
78869
- break;
80327
+ });
80328
+ const mergeRanges$1 = (ranges, docSize) => {
80329
+ if (!ranges.length) return [];
80330
+ const sorted = ranges.map(({ from: from2, to }) => ({
80331
+ from: Math.max(0, from2),
80332
+ to: Math.min(docSize, to)
80333
+ })).filter(({ from: from2, to }) => from2 < to).sort((a, b2) => a.from - b2.from);
80334
+ const merged = [];
80335
+ for (const range2 of sorted) {
80336
+ const last = merged[merged.length - 1];
80337
+ if (last && range2.from <= last.to) {
80338
+ last.to = Math.max(last.to, range2.to);
78870
80339
  } else {
78871
- if (d2 == 1) return false;
78872
- types2.unshift(null);
80340
+ merged.push({ ...range2 });
78873
80341
  }
78874
80342
  }
78875
- let tr = state2.tr;
78876
- if (state2.selection instanceof TextSelection$1 || state2.selection instanceof AllSelection) tr.deleteSelection();
78877
- let splitPos = tr.mapping.map($from.pos);
78878
- let can = canSplit(tr.doc, splitPos, types2.length, types2);
78879
- if (!can) {
78880
- types2[0] = deflt ? { type: deflt } : null;
78881
- can = canSplit(tr.doc, splitPos, types2.length, types2);
78882
- }
78883
- if (!can) return false;
78884
- tr.split(splitPos, types2.length, types2);
78885
- if (!atEnd && atStart && $from.node(splitDepth).type != deflt) {
78886
- let first2 = tr.mapping.map($from.before(splitDepth)), $first = tr.doc.resolve(first2);
78887
- if (deflt && $from.node(splitDepth - 1).canReplaceWith($first.index(), $first.index() + 1, deflt))
78888
- tr.setNodeMarkup(tr.mapping.map($from.before(splitDepth)), deflt);
78889
- }
78890
- if (dispatch) dispatch(tr.scrollIntoView());
78891
- return true;
78892
- }
80343
+ return merged;
80344
+ };
80345
+ const collectChangedRanges = (trs, docSize) => {
80346
+ const ranges = [];
80347
+ trs.forEach((tr) => {
80348
+ if (!tr.docChanged) return;
80349
+ tr.mapping.maps.forEach((map22) => {
80350
+ map22.forEach((oldStart, oldEnd, newStart, newEnd) => {
80351
+ if (newStart !== oldStart || oldEnd !== newEnd) {
80352
+ ranges.push({ from: newStart, to: newEnd });
80353
+ }
80354
+ });
80355
+ });
80356
+ });
80357
+ return mergeRanges$1(ranges, docSize);
80358
+ };
80359
+ const mapRangesThroughTransactions = (ranges, transactions, docSize) => {
80360
+ let mapped = ranges;
80361
+ transactions.forEach((tr) => {
80362
+ mapped = mapped.map(({ from: from2, to }) => {
80363
+ const mappedFrom = tr.mapping.map(from2, -1);
80364
+ const mappedTo = tr.mapping.map(to, 1);
80365
+ if (mappedFrom >= mappedTo) return null;
80366
+ return { from: mappedFrom, to: mappedTo };
80367
+ }).filter(Boolean);
80368
+ });
80369
+ return mergeRanges$1(mapped, docSize);
80370
+ };
80371
+ const buildWrapTransaction = (state2, ranges, runType) => {
80372
+ if (!ranges.length) return null;
80373
+ const replacements = [];
80374
+ ranges.forEach(({ from: from2, to }) => {
80375
+ state2.doc.nodesBetween(from2, to, (node, pos, parent, index2) => {
80376
+ if (!node.isText || !parent || parent.type === runType) return;
80377
+ const match = parent.contentMatchAt ? parent.contentMatchAt(index2) : null;
80378
+ if (match && !match.matchType(runType)) return;
80379
+ if (!match && !parent.type.contentMatch.matchType(runType)) return;
80380
+ const runProperties = decodeRPrFromMarks(node.marks);
80381
+ const runNode = runType.create({ runProperties }, node);
80382
+ replacements.push({ from: pos, to: pos + node.nodeSize, runNode });
80383
+ });
80384
+ });
80385
+ if (!replacements.length) return null;
80386
+ const tr = state2.tr;
80387
+ replacements.sort((a, b2) => b2.from - a.from).forEach(({ from: from2, to, runNode }) => tr.replaceWith(from2, to, runNode));
80388
+ return tr.docChanged ? tr : null;
80389
+ };
80390
+ const wrapTextInRunsPlugin = () => {
80391
+ let view = null;
80392
+ let pendingRanges = [];
80393
+ const flush = () => {
80394
+ if (!view) return;
80395
+ const runType = view.state.schema.nodes.run;
80396
+ if (!runType) {
80397
+ pendingRanges = [];
80398
+ return;
80399
+ }
80400
+ const tr = buildWrapTransaction(view.state, pendingRanges, runType);
80401
+ pendingRanges = [];
80402
+ if (tr) {
80403
+ view.dispatch(tr);
80404
+ }
80405
+ };
80406
+ const onCompositionEnd = () => {
80407
+ if (typeof globalThis === "undefined") return;
80408
+ globalThis.queueMicrotask(flush);
80409
+ };
80410
+ return new Plugin({
80411
+ view(editorView) {
80412
+ view = editorView;
80413
+ editorView.dom.addEventListener("compositionend", onCompositionEnd);
80414
+ return {
80415
+ destroy() {
80416
+ editorView.dom.removeEventListener("compositionend", onCompositionEnd);
80417
+ view = null;
80418
+ pendingRanges = [];
80419
+ }
80420
+ };
80421
+ },
80422
+ appendTransaction(transactions, _oldState, newState) {
80423
+ const docSize = newState.doc.content.size;
80424
+ const runType = newState.schema.nodes.run;
80425
+ if (!runType) return null;
80426
+ pendingRanges = mapRangesThroughTransactions(pendingRanges, transactions, docSize);
80427
+ const changedRanges = collectChangedRanges(transactions, docSize);
80428
+ pendingRanges = mergeRanges$1([...pendingRanges, ...changedRanges], docSize);
80429
+ if (view?.composing) {
80430
+ return null;
80431
+ }
80432
+ const tr = buildWrapTransaction(newState, pendingRanges, runType);
80433
+ pendingRanges = [];
80434
+ return tr;
80435
+ }
80436
+ });
80437
+ };
78893
80438
  const Run = OxmlNode.create({
78894
80439
  name: "run",
78895
80440
  oXmlName: "w:r",
@@ -78932,7 +80477,8 @@ const Run = OxmlNode.create({
78932
80477
  // @ts-expect-error - Command signatures will be fixed in TS migration
78933
80478
  addCommands() {
78934
80479
  return {
78935
- splitRun
80480
+ splitRunToParagraph,
80481
+ splitRunAtCursor
78936
80482
  };
78937
80483
  },
78938
80484
  parseDOM() {
@@ -78941,6 +80487,9 @@ const Run = OxmlNode.create({
78941
80487
  renderDOM({ htmlAttributes }) {
78942
80488
  const base2 = Attribute2.mergeAttributes(this.options.htmlAttributes, htmlAttributes);
78943
80489
  return ["span", base2, 0];
80490
+ },
80491
+ addPmPlugins() {
80492
+ return [wrapTextInRunsPlugin(), cleanupEmptyRunsPlugin];
78944
80493
  }
78945
80494
  });
78946
80495
  const restartNumbering = ({ editor, tr, state: state2, dispatch }) => {
@@ -79683,20 +81232,15 @@ function createNumberingPlugin(editor) {
79683
81232
  } else {
79684
81233
  markerText = docxNumberingHelpers.normalizeLvlTextChar(lvlText);
79685
81234
  }
79686
- if (JSON.stringify(node.attrs.listRendering) !== JSON.stringify({
81235
+ const newListRendering = {
79687
81236
  markerText,
79688
81237
  suffix: suffix2,
79689
81238
  justification,
79690
81239
  path,
79691
81240
  numberingType: listNumberingType
79692
- })) {
79693
- tr.setNodeAttribute(pos, "listRendering", {
79694
- markerText,
79695
- suffix: suffix2,
79696
- justification,
79697
- path,
79698
- numberingType: listNumberingType
79699
- });
81241
+ };
81242
+ if (JSON.stringify(node.attrs.listRendering) !== JSON.stringify(newListRendering)) {
81243
+ tr.setNodeAttribute(pos, "listRendering", newListRendering);
79700
81244
  }
79701
81245
  return false;
79702
81246
  });
@@ -79997,7 +81541,7 @@ const Paragraph = OxmlNode.create({
79997
81541
  return null;
79998
81542
  }
79999
81543
  const { tr } = state2;
80000
- tr.delete(range2.from, range2.to);
81544
+ tr.delete(range2.from, range2.to).setSelection(TextSelection$1.create(tr.doc, range2.from));
80001
81545
  ListHelpers.createNewList({
80002
81546
  listType: type2,
80003
81547
  tr,
@@ -83427,7 +84971,10 @@ const Table = Node$1.create({
83427
84971
  insertTable: ({ rows = 3, cols = 3, withHeaderRow = false } = {}) => ({ tr, dispatch, editor }) => {
83428
84972
  const node = createTable(editor.schema, rows, cols, withHeaderRow);
83429
84973
  if (dispatch) {
83430
- const offset2 = tr.selection.from + 1;
84974
+ let offset2 = tr.selection.$from.end() + 1;
84975
+ if (tr.selection.$from.parent?.type?.name === "run") {
84976
+ offset2 = tr.selection.$from.after(tr.selection.$from.depth - 1);
84977
+ }
83431
84978
  tr.replaceSelectionWith(node).scrollIntoView().setSelection(TextSelection$1.near(tr.doc.resolve(offset2)));
83432
84979
  }
83433
84980
  return true;
@@ -110765,6 +112312,12 @@ const _sfc_main$4 = {
110765
112312
  };
110766
112313
  const GenericPopover = /* @__PURE__ */ _export_sfc(_sfc_main$4, [["__scopeId", "data-v-cbddcc0f"]]);
110767
112314
  const _hoisted_1$3 = ["data-boundary-index", "data-boundary-type", "onMousedown"];
112315
+ const RESIZE_HANDLE_WIDTH_PX = 9;
112316
+ const RESIZE_HANDLE_OFFSET_PX = 4;
112317
+ const DRAG_OVERLAY_EXTENSION_PX = 1e3;
112318
+ const MIN_DRAG_OVERLAY_WIDTH_PX = 2e3;
112319
+ const THROTTLE_INTERVAL_MS = 16;
112320
+ const MIN_RESIZE_DELTA_PX = 1;
110768
112321
  const _sfc_main$3 = {
110769
112322
  __name: "TableResizeOverlay",
110770
112323
  props: {
@@ -110788,26 +112341,73 @@ const _sfc_main$3 = {
110788
112341
  setup(__props, { emit: __emit }) {
110789
112342
  const props = __props;
110790
112343
  const emit = __emit;
112344
+ const overlayRect = vue.ref(null);
110791
112345
  const tableMetadata = vue.ref(null);
110792
112346
  const dragState = vue.ref(null);
110793
112347
  const forcedCleanup = vue.ref(false);
112348
+ let rafId = null;
112349
+ let isUnmounted = false;
112350
+ function startOverlayTracking() {
112351
+ if (rafId !== null) return;
112352
+ const step = () => {
112353
+ updateOverlayRect();
112354
+ rafId = requestAnimationFrame(step);
112355
+ };
112356
+ rafId = requestAnimationFrame(step);
112357
+ }
112358
+ function stopOverlayTracking() {
112359
+ if (rafId !== null) {
112360
+ cancelAnimationFrame(rafId);
112361
+ rafId = null;
112362
+ }
112363
+ }
110794
112364
  const overlayStyle = vue.computed(() => {
110795
- if (!props.tableElement) return {};
110796
- const rect = props.tableElement.getBoundingClientRect();
112365
+ if (!overlayRect.value || !props.tableElement) return {};
112366
+ const rect = overlayRect.value;
110797
112367
  let overlayWidth = rect.width;
110798
112368
  if (dragState.value) {
110799
- overlayWidth = Math.max(rect.width + 1e3, 2e3);
112369
+ overlayWidth = Math.max(rect.width + DRAG_OVERLAY_EXTENSION_PX, MIN_DRAG_OVERLAY_WIDTH_PX);
110800
112370
  }
110801
112371
  return {
110802
112372
  position: "absolute",
110803
- left: `${props.tableElement.offsetLeft}px`,
110804
- top: `${props.tableElement.offsetTop}px`,
112373
+ left: `${rect.left}px`,
112374
+ top: `${rect.top}px`,
110805
112375
  width: `${overlayWidth}px`,
110806
112376
  height: `${rect.height}px`,
110807
112377
  pointerEvents: dragState.value ? "auto" : "none",
110808
112378
  zIndex: 10
110809
112379
  };
110810
112380
  });
112381
+ function updateOverlayRect() {
112382
+ if (!props.tableElement) {
112383
+ overlayRect.value = null;
112384
+ return;
112385
+ }
112386
+ const parent = props.tableElement.offsetParent;
112387
+ const tableRect = props.tableElement.getBoundingClientRect();
112388
+ if (tableRect.width === 0 || tableRect.height === 0) {
112389
+ overlayRect.value = null;
112390
+ return;
112391
+ }
112392
+ if (parent) {
112393
+ const parentRect = parent.getBoundingClientRect();
112394
+ const left2 = tableRect.left - parentRect.left + (parent.scrollLeft || 0);
112395
+ const top2 = tableRect.top - parentRect.top + (parent.scrollTop || 0);
112396
+ overlayRect.value = {
112397
+ left: left2,
112398
+ top: top2,
112399
+ width: tableRect.width,
112400
+ height: tableRect.height
112401
+ };
112402
+ } else {
112403
+ overlayRect.value = {
112404
+ left: props.tableElement.offsetLeft,
112405
+ top: props.tableElement.offsetTop,
112406
+ width: tableRect.width,
112407
+ height: tableRect.height
112408
+ };
112409
+ }
112410
+ }
110811
112411
  const resizableBoundaries = vue.computed(() => {
110812
112412
  if (!tableMetadata.value?.columns) {
110813
112413
  return [];
@@ -110846,9 +112446,9 @@ const _sfc_main$3 = {
110846
112446
  if (!colSegments || colSegments.length === 0) {
110847
112447
  return [];
110848
112448
  }
110849
- return colSegments.map((seg) => ({
110850
- y: seg.y,
110851
- h: seg.h
112449
+ return colSegments.filter((seg) => seg && typeof seg === "object").map((seg) => ({
112450
+ y: typeof seg.y === "number" ? seg.y : 0,
112451
+ h: seg.h !== null && typeof seg.h === "number" ? seg.h : null
110852
112452
  }));
110853
112453
  }
110854
112454
  function getSegmentHandleStyle(boundary, segment) {
@@ -110856,16 +112456,16 @@ const _sfc_main$3 = {
110856
112456
  position: "absolute",
110857
112457
  left: `${boundary.x}px`,
110858
112458
  top: segment.y != null ? `${segment.y}px` : "0",
110859
- width: "9px",
112459
+ width: `${RESIZE_HANDLE_WIDTH_PX}px`,
110860
112460
  height: segment.h != null ? `${segment.h}px` : "100%",
110861
- transform: "translateX(-4px)",
112461
+ transform: `translateX(-${RESIZE_HANDLE_OFFSET_PX}px)`,
110862
112462
  cursor: "col-resize",
110863
112463
  pointerEvents: "auto"
110864
112464
  };
110865
112465
  }
110866
112466
  const guidelineStyle = vue.computed(() => {
110867
112467
  if (!dragState.value || !tableMetadata.value) return { display: "none" };
110868
- const initialBoundary = resizableBoundaries.value[dragState.value.boundaryIndex];
112468
+ const initialBoundary = resizableBoundaries.value[dragState.value.resizableBoundaryIndex];
110869
112469
  if (!initialBoundary) return { display: "none" };
110870
112470
  const newX = initialBoundary.x + dragState.value.constrainedDelta;
110871
112471
  return {
@@ -110922,11 +112522,11 @@ const _sfc_main$3 = {
110922
112522
  });
110923
112523
  }
110924
112524
  }
110925
- function onHandleMouseDown(event, boundaryIndex) {
112525
+ function onHandleMouseDown(event, resizableBoundaryIndex) {
110926
112526
  event.preventDefault();
110927
112527
  event.stopPropagation();
110928
112528
  if (!tableMetadata.value?.columns) return;
110929
- const boundary = resizableBoundaries.value[boundaryIndex];
112529
+ const boundary = resizableBoundaries.value[resizableBoundaryIndex];
110930
112530
  if (!boundary) return;
110931
112531
  const columns = tableMetadata.value.columns;
110932
112532
  const isRightEdge = boundary.type === "right-edge";
@@ -110934,7 +112534,7 @@ const _sfc_main$3 = {
110934
112534
  const rightColumn = isRightEdge ? null : columns[boundary.index + 1];
110935
112535
  dragState.value = {
110936
112536
  columnIndex: boundary.index,
110937
- boundaryIndex,
112537
+ resizableBoundaryIndex,
110938
112538
  isRightEdge,
110939
112539
  initialX: event.clientX,
110940
112540
  initialWidths: columns.map((col) => col.w),
@@ -110948,15 +112548,28 @@ const _sfc_main$3 = {
110948
112548
  } : null,
110949
112549
  constrainedDelta: 0
110950
112550
  };
112551
+ if (!props.editor?.view?.dom) {
112552
+ emit("resize-error", { error: "Editor view not available" });
112553
+ dragState.value = null;
112554
+ return;
112555
+ }
110951
112556
  const pmView = props.editor.view.dom;
110952
112557
  pmView.style.pointerEvents = "none";
110953
- document.addEventListener("mousemove", onDocumentMouseMove2);
110954
- document.addEventListener("mouseup", onDocumentMouseUp);
110955
- emit("resize-start", {
110956
- columnIndex: boundary.index,
110957
- isRightEdge,
110958
- initialWidths: dragState.value.initialWidths
110959
- });
112558
+ try {
112559
+ document.addEventListener("mousemove", onDocumentMouseMove2);
112560
+ document.addEventListener("mouseup", onDocumentMouseUp);
112561
+ emit("resize-start", {
112562
+ columnIndex: boundary.index,
112563
+ isRightEdge,
112564
+ initialWidths: dragState.value.initialWidths
112565
+ });
112566
+ } catch (error) {
112567
+ document.removeEventListener("mousemove", onDocumentMouseMove2);
112568
+ document.removeEventListener("mouseup", onDocumentMouseUp);
112569
+ pmView.style.pointerEvents = "auto";
112570
+ dragState.value = null;
112571
+ emit("resize-error", { error: error instanceof Error ? error.message : String(error) });
112572
+ }
110960
112573
  }
110961
112574
  function throttle2(func, limit) {
110962
112575
  let inThrottle;
@@ -110981,7 +112594,7 @@ const _sfc_main$3 = {
110981
112594
  return { throttled, cancel };
110982
112595
  }
110983
112596
  const mouseMoveThrottle = throttle2((event) => {
110984
- if (!dragState.value) return;
112597
+ if (isUnmounted || !dragState.value) return;
110985
112598
  const delta = event.clientX - dragState.value.initialX;
110986
112599
  const minDelta = -(dragState.value.leftColumn.width - dragState.value.leftColumn.minWidth);
110987
112600
  let maxDelta;
@@ -111007,7 +112620,7 @@ const _sfc_main$3 = {
111007
112620
  columnIndex: dragState.value.columnIndex,
111008
112621
  delta: constrainedDelta
111009
112622
  });
111010
- }, 16);
112623
+ }, THROTTLE_INTERVAL_MS);
111011
112624
  const onDocumentMouseMove2 = mouseMoveThrottle.throttled;
111012
112625
  function onDocumentMouseUp(event) {
111013
112626
  if (!dragState.value) return;
@@ -111022,13 +112635,11 @@ const _sfc_main$3 = {
111022
112635
  }
111023
112636
  document.removeEventListener("mousemove", onDocumentMouseMove2);
111024
112637
  document.removeEventListener("mouseup", onDocumentMouseUp);
111025
- if (props.editor?.view) {
112638
+ if (props.editor?.view?.dom) {
111026
112639
  const pmView = props.editor.view.dom;
111027
- if (pmView && pmView.style) {
111028
- pmView.style.pointerEvents = "auto";
111029
- }
112640
+ pmView.style.pointerEvents = "auto";
111030
112641
  }
111031
- if (!forcedCleanup.value && Math.abs(finalDelta) > 1) {
112642
+ if (!forcedCleanup.value && Math.abs(finalDelta) > MIN_RESIZE_DELTA_PX) {
111032
112643
  dispatchResizeTransaction(columnIndex, newWidths);
111033
112644
  emit("resize-end", {
111034
112645
  columnIndex,
@@ -111091,7 +112702,14 @@ const _sfc_main$3 = {
111091
112702
  if (!pmElement) {
111092
112703
  return null;
111093
112704
  }
111094
- const pmStart = parseInt(pmElement.getAttribute("data-pm-start"), 10);
112705
+ const pmStartAttr = pmElement.getAttribute("data-pm-start");
112706
+ if (!pmStartAttr) {
112707
+ return null;
112708
+ }
112709
+ const pmStart = parseInt(pmStartAttr, 10);
112710
+ if (!Number.isFinite(pmStart)) {
112711
+ return null;
112712
+ }
111095
112713
  let tablePos = null;
111096
112714
  state2.doc.descendants((node, pos) => {
111097
112715
  if (node.type.name === "table") {
@@ -111143,6 +112761,12 @@ const _sfc_main$3 = {
111143
112761
  () => props.tableElement,
111144
112762
  () => {
111145
112763
  parseTableMetadata();
112764
+ updateOverlayRect();
112765
+ if (props.visible && props.tableElement) {
112766
+ startOverlayTracking();
112767
+ } else if (!props.tableElement) {
112768
+ stopOverlayTracking();
112769
+ }
111146
112770
  },
111147
112771
  { immediate: true }
111148
112772
  );
@@ -111151,7 +112775,10 @@ const _sfc_main$3 = {
111151
112775
  (visible) => {
111152
112776
  if (visible) {
111153
112777
  parseTableMetadata();
112778
+ updateOverlayRect();
112779
+ startOverlayTracking();
111154
112780
  } else {
112781
+ stopOverlayTracking();
111155
112782
  if (dragState.value) {
111156
112783
  forcedCleanup.value = true;
111157
112784
  onDocumentMouseUp(new MouseEvent("mouseup"));
@@ -111160,8 +112787,15 @@ const _sfc_main$3 = {
111160
112787
  }
111161
112788
  }
111162
112789
  );
112790
+ vue.onMounted(() => {
112791
+ window.addEventListener("scroll", updateOverlayRect, true);
112792
+ window.addEventListener("resize", updateOverlayRect);
112793
+ updateOverlayRect();
112794
+ });
111163
112795
  vue.onBeforeUnmount(() => {
112796
+ isUnmounted = true;
111164
112797
  mouseMoveThrottle.cancel();
112798
+ stopOverlayTracking();
111165
112799
  if (dragState.value) {
111166
112800
  document.removeEventListener("mousemove", onDocumentMouseMove2);
111167
112801
  document.removeEventListener("mouseup", onDocumentMouseUp);
@@ -111169,6 +112803,8 @@ const _sfc_main$3 = {
111169
112803
  props.editor.view.dom.style.pointerEvents = "auto";
111170
112804
  }
111171
112805
  }
112806
+ window.removeEventListener("scroll", updateOverlayRect, true);
112807
+ window.removeEventListener("resize", updateOverlayRect);
111172
112808
  });
111173
112809
  return (_ctx, _cache) => {
111174
112810
  return __props.visible && tableMetadata.value ? (vue.openBlock(), vue.createElementBlock("div", {
@@ -111178,21 +112814,21 @@ const _sfc_main$3 = {
111178
112814
  onMousedown: _cache[0] || (_cache[0] = vue.withModifiers(() => {
111179
112815
  }, ["stop"]))
111180
112816
  }, [
111181
- (vue.openBlock(true), vue.createElementBlock(vue.Fragment, null, vue.renderList(resizableBoundaries.value, (boundary, boundaryIndex) => {
112817
+ (vue.openBlock(true), vue.createElementBlock(vue.Fragment, null, vue.renderList(resizableBoundaries.value, (boundary, resizableBoundaryIndex) => {
111182
112818
  return vue.openBlock(), vue.createElementBlock(vue.Fragment, {
111183
- key: `boundary-${boundaryIndex}`
112819
+ key: `boundary-${resizableBoundaryIndex}`
111184
112820
  }, [
111185
112821
  (vue.openBlock(true), vue.createElementBlock(vue.Fragment, null, vue.renderList(getBoundarySegments(boundary), (segment, segmentIndex) => {
111186
112822
  return vue.openBlock(), vue.createElementBlock("div", {
111187
112823
  key: `handle-${boundary.type}-${boundary.index}-${segmentIndex}`,
111188
112824
  class: vue.normalizeClass(["resize-handle", {
111189
- "resize-handle--active": dragState.value && dragState.value.boundaryIndex === boundaryIndex,
112825
+ "resize-handle--active": dragState.value && dragState.value.resizableBoundaryIndex === resizableBoundaryIndex,
111190
112826
  "resize-handle--edge": boundary.type === "right-edge"
111191
112827
  }]),
111192
- "data-boundary-index": boundaryIndex,
112828
+ "data-boundary-index": resizableBoundaryIndex,
111193
112829
  "data-boundary-type": boundary.type,
111194
112830
  style: vue.normalizeStyle(getSegmentHandleStyle(boundary, segment)),
111195
- onMousedown: ($event) => onHandleMouseDown($event, boundaryIndex)
112831
+ onMousedown: ($event) => onHandleMouseDown($event, resizableBoundaryIndex)
111196
112832
  }, null, 46, _hoisted_1$3);
111197
112833
  }), 128))
111198
112834
  ], 64);
@@ -111206,7 +112842,7 @@ const _sfc_main$3 = {
111206
112842
  };
111207
112843
  }
111208
112844
  };
111209
- const TableResizeOverlay = /* @__PURE__ */ _export_sfc(_sfc_main$3, [["__scopeId", "data-v-3f4a506b"]]);
112845
+ const TableResizeOverlay = /* @__PURE__ */ _export_sfc(_sfc_main$3, [["__scopeId", "data-v-2fdf7836"]]);
111210
112846
  const _hoisted_1$2 = ["data-handle-position", "onMousedown"];
111211
112847
  const OVERLAY_EXPANSION_PX = 2e3;
111212
112848
  const RESIZE_HANDLE_SIZE_PX = 12;