@stll/folio-core 0.66.2 → 0.67.0

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 (119) hide show
  1. package/dist/ai-edits/apply.js +45 -10
  2. package/dist/ai-edits/batch-claims.js +5 -3
  3. package/dist/ai-edits/clean-text.js +4 -1
  4. package/dist/ai-edits/read.js +6 -4
  5. package/dist/ai-edits/snapshot.js +24 -14
  6. package/dist/ai-edits/table-cell-mutations.js +3 -2
  7. package/dist/ai-edits/table-row-column-mutations.js +20 -6
  8. package/dist/controller/canonicalComposition.d.ts +1 -1
  9. package/dist/controller/canonicalComposition.js +76 -18
  10. package/dist/controller/canonicalInput.d.ts +0 -1
  11. package/dist/controller/canonicalInput.js +19 -1
  12. package/dist/controller/canonicalSession.js +1 -2
  13. package/dist/controller/hiddenEditorManager.d.ts +6 -0
  14. package/dist/controller/hiddenEditorManager.js +3 -1
  15. package/dist/controller/layoutPipeline.d.ts +2 -0
  16. package/dist/controller/layoutPipeline.js +7 -3
  17. package/dist/controller/layoutSession.d.ts +1 -0
  18. package/dist/display-list/build/tablePrimitives.d.ts +3 -1
  19. package/dist/display-list/build/tablePrimitives.js +29 -13
  20. package/dist/docx/chartPreview.d.ts +4 -1
  21. package/dist/docx/chartPreview.js +26 -15
  22. package/dist/docx/mainDocumentPart.d.ts +6 -0
  23. package/dist/docx/mainDocumentPart.js +65 -0
  24. package/dist/docx/packageParts.d.ts +1 -1
  25. package/dist/docx/packageParts.js +10 -4
  26. package/dist/docx/previewBudget.d.ts +6 -0
  27. package/dist/docx/previewBudget.js +7 -1
  28. package/dist/docx/rezip.js +4 -4
  29. package/dist/docx/shapeAlternateContent.js +19 -0
  30. package/dist/docx/unzip.js +2 -0
  31. package/dist/i18n/messages/ar.gen.js +1 -0
  32. package/dist/i18n/messages/catalogs.gen.d.ts +17 -0
  33. package/dist/i18n/messages/catalogs.gen.js +17 -0
  34. package/dist/i18n/messages/cs.gen.js +1 -0
  35. package/dist/i18n/messages/de.gen.js +1 -0
  36. package/dist/i18n/messages/en.gen.js +1 -0
  37. package/dist/i18n/messages/es.gen.js +1 -0
  38. package/dist/i18n/messages/et.gen.js +1 -0
  39. package/dist/i18n/messages/fr.gen.js +1 -0
  40. package/dist/i18n/messages/he.gen.js +1 -0
  41. package/dist/i18n/messages/hi.gen.js +1 -0
  42. package/dist/i18n/messages/hu.gen.js +1 -0
  43. package/dist/i18n/messages/lt.gen.js +1 -0
  44. package/dist/i18n/messages/lv.gen.js +1 -0
  45. package/dist/i18n/messages/messages.gen.d.ts +1 -0
  46. package/dist/i18n/messages/pl.gen.js +1 -0
  47. package/dist/i18n/messages/pt-BR.gen.js +1 -0
  48. package/dist/i18n/messages/sk.gen.js +1 -0
  49. package/dist/i18n/messages/tr.gen.js +1 -0
  50. package/dist/i18n/messages/zh-CN.gen.js +1 -0
  51. package/dist/internal/wholeStoryRevisionResolution.js +57 -12
  52. package/dist/layout-bridge/convert/altChunkPlaceholder.d.ts +10 -0
  53. package/dist/layout-bridge/convert/altChunkPlaceholder.js +70 -0
  54. package/dist/layout-bridge/convert/fixedTableColumnWidths.js +2 -1
  55. package/dist/layout-bridge/convert/flowConversionShared.d.ts +10 -0
  56. package/dist/layout-bridge/convert/flowConversionShared.js +11 -1
  57. package/dist/layout-bridge/convert/footnoteLayout.d.ts +1 -0
  58. package/dist/layout-bridge/convert/footnoteLayout.js +4 -1
  59. package/dist/layout-bridge/convert/headerFooterLayout.d.ts +1 -0
  60. package/dist/layout-bridge/convert/headerFooterLayout.js +6 -1
  61. package/dist/layout-bridge/convert/tableConversion.js +6 -2
  62. package/dist/layout-bridge/convert/toFlowBlocks.js +4 -0
  63. package/dist/layout-bridge/engine/clickToPosition.js +5 -1
  64. package/dist/layout-engine/measure/tableCellFloating.d.ts +2 -0
  65. package/dist/layout-engine/measure/tableCellFloating.js +1 -0
  66. package/dist/layout-engine/measure/tableVisibleBand.d.ts +16 -0
  67. package/dist/layout-engine/measure/tableVisibleBand.js +28 -0
  68. package/dist/layout-engine/tableLayout.js +7 -4
  69. package/dist/layout-engine/tableRowBreak.d.ts +10 -0
  70. package/dist/layout-engine/tableRowBreak.js +151 -36
  71. package/dist/layout-engine/types.d.ts +7 -2
  72. package/dist/layout-painter/previewSvg.d.ts +8 -0
  73. package/dist/layout-painter/previewSvg.js +47 -0
  74. package/dist/layout-painter/renderImage.js +2 -1
  75. package/dist/layout-painter/renderPage.d.ts +1 -0
  76. package/dist/layout-painter/renderPage.js +6 -3
  77. package/dist/layout-painter/renderParagraph.js +3 -2
  78. package/dist/layout-painter/renderTable.d.ts +5 -2
  79. package/dist/layout-painter/renderTable.js +33 -19
  80. package/dist/prosemirror/anchoredTextBoxes.d.ts +2 -1
  81. package/dist/prosemirror/commands/comments.js +20 -7
  82. package/dist/prosemirror/commands/deleteBesideInlineAnchor.d.ts +9 -0
  83. package/dist/prosemirror/commands/deleteBesideInlineAnchor.js +36 -0
  84. package/dist/prosemirror/commands/pastePlainText.d.ts +6 -0
  85. package/dist/prosemirror/commands/pastePlainText.js +13 -3
  86. package/dist/prosemirror/commands/resolveAllTableChanges.js +30 -2
  87. package/dist/prosemirror/commentReferenceIntegrity.d.ts +8 -2
  88. package/dist/prosemirror/commentReferenceIntegrity.js +19 -4
  89. package/dist/prosemirror/conversion/fromProseDoc.js +39 -4
  90. package/dist/prosemirror/conversion/toProseDoc.js +6 -4
  91. package/dist/prosemirror/extensions/core/ParagraphExtension.d.ts +3 -1
  92. package/dist/prosemirror/extensions/core/ParagraphExtension.js +8 -9
  93. package/dist/prosemirror/extensions/features/AutoBidiDetectionExtension.js +46 -11
  94. package/dist/prosemirror/extensions/features/BaseKeymapExtension.js +3 -2
  95. package/dist/prosemirror/extensions/features/BidiShortcutExtension.js +2 -3
  96. package/dist/prosemirror/extensions/features/ListExtension.js +22 -1
  97. package/dist/prosemirror/extensions/marks/HyperlinkExtension.js +5 -0
  98. package/dist/prosemirror/extensions/marks/TextColorExtension.js +1 -1
  99. package/dist/prosemirror/extensions/marks/TrackedChangeExtensions.js +8 -4
  100. package/dist/prosemirror/extensions/nodes/BookmarkBoundaryExtension.js +5 -1
  101. package/dist/prosemirror/extensions/nodes/CommentRangeBoundaryExtension.js +2 -1
  102. package/dist/prosemirror/extensions/nodes/CommentReferenceExtension.js +4 -3
  103. package/dist/prosemirror/extensions/nodes/MoveRangeBoundaryExtension.js +2 -1
  104. package/dist/prosemirror/extensions/nodes/NoteMarkerExtension.js +2 -1
  105. package/dist/prosemirror/extensions/nodes/RangeAnchorExtension.js +2 -1
  106. package/dist/prosemirror/extensions/nodes/RenderedPageBreakExtension.js +2 -1
  107. package/dist/prosemirror/extensions/nodes/TableExtension.js +87 -7
  108. package/dist/prosemirror/extensions/nodes/inlineAnchorDom.d.ts +11 -0
  109. package/dist/prosemirror/extensions/nodes/inlineAnchorDom.js +21 -0
  110. package/dist/prosemirror/plugins/suggestionMode.d.ts +0 -8
  111. package/dist/prosemirror/plugins/suggestionMode.js +175 -21
  112. package/dist/prosemirror/rowGridOmissions.d.ts +11 -0
  113. package/dist/prosemirror/rowGridOmissions.js +21 -0
  114. package/dist/prosemirror/tableGridMutation.d.ts +19 -2
  115. package/dist/prosemirror/tableGridMutation.js +118 -15
  116. package/dist/prosemirror/tablePositionedBookmarks.d.ts +2 -0
  117. package/dist/prosemirror/tablePositionedBookmarks.js +80 -0
  118. package/dist/prosemirror/validation.js +1 -1
  119. package/package.json +2 -2
@@ -585,6 +585,11 @@ export type ParagraphAttrs = {
585
585
  export type ParagraphBlock = {
586
586
  kind: "paragraph";
587
587
  id: BlockId;
588
+ /**
589
+ * Set on a block that exists only in layout: its text is in no ProseMirror
590
+ * node, so a click anywhere in it resolves to this position.
591
+ */
592
+ fixedPosition?: number;
588
593
  /** Stable Word `w14:paraId` / PM `paraId`, when available. */
589
594
  paraId?: string;
590
595
  runs: Run[];
@@ -749,8 +754,8 @@ export type ImageBlock = {
749
754
  src: string;
750
755
  /**
751
756
  * Set instead of `src` for a drawing with no image data: the display list
752
- * rasterises it when it interns it. `src` is then empty, and a block with
753
- * neither paints nothing, as before.
757
+ * draws it as primitives and the legacy painter as an SVG source. `src` is
758
+ * then empty, and a block with neither paints nothing.
754
759
  */
755
760
  preview?: PreviewDescriptor;
756
761
  width: number;
@@ -0,0 +1,8 @@
1
+ import { document_d_exports } from "../types/document.js";
2
+ /** `preview` as an `<img>` source that fills whatever box the image has. */
3
+ export declare const previewToSvgDataUrl: (preview: document_d_exports.PreviewDescriptor) => string;
4
+ /** The source an image paints from: its bytes, or its drawn preview. */
5
+ export declare const paintedImageSource: (image: {
6
+ readonly src: string;
7
+ readonly preview?: document_d_exports.PreviewDescriptor;
8
+ }) => string;
@@ -0,0 +1,47 @@
1
+ import { paintPreview } from "../display-list/build/previewPrimitives.js";
2
+ import { svgPreviewDataUrl } from "../docx/previewBudget.js";
3
+ import { panic } from "better-result";
4
+ // src/layout-painter/previewSvg.ts
5
+ /**
6
+ * What the DOM painter shows for a drawing with no image data.
7
+ *
8
+ * Its marks come from the display list's own `paintPreview`, so the two painters
9
+ * cannot draw a preview differently. An SVG in an `<img>` runs no script and
10
+ * fetches nothing, and every value written here is a number.
11
+ */
12
+ const cssColor = ({ r, g, b, a }) => `rgba(${String(r)},${String(g)},${String(b)},${String(a)})`;
13
+ const svgPoints = (points) => points.map(({ xPx, yPx }) => `${String(xPx)},${String(yPx)}`).join(" ");
14
+ const svgMark = (primitive) => {
15
+ switch (primitive.kind) {
16
+ case "rect": {
17
+ const { xPx, yPx, widthPx, heightPx } = primitive.rect;
18
+ const fill = primitive.fill ? cssColor(primitive.fill) : "none";
19
+ return `<rect x="${String(xPx)}" y="${String(yPx)}" width="${String(widthPx)}" height="${String(heightPx)}" fill="${fill}"/>`;
20
+ }
21
+ case "polygon": return `<polygon points="${svgPoints(primitive.points)}" fill="${cssColor(primitive.fill)}"/>`;
22
+ case "polyline": return `<polyline points="${svgPoints(primitive.points)}" fill="none" stroke="${cssColor(primitive.stroke.color)}" stroke-width="${String(primitive.stroke.thicknessPx)}"/>`;
23
+ default: return panic(`a preview does not draw ${primitive.kind}`);
24
+ }
25
+ };
26
+ const dataUrls = /* @__PURE__ */ new WeakMap();
27
+ /** `preview` as an `<img>` source that fills whatever box the image has. */
28
+ const previewToSvgDataUrl = (preview) => {
29
+ const known = dataUrls.get(preview);
30
+ if (known !== void 0) return known;
31
+ const hasArea = preview.extent.width > 0 && preview.extent.height > 0;
32
+ const widthPx = hasArea ? preview.extent.width : 1;
33
+ const heightPx = hasArea ? preview.extent.height : 1;
34
+ const marks = paintPreview(preview, {
35
+ xPx: 0,
36
+ yPx: 0,
37
+ widthPx,
38
+ heightPx
39
+ });
40
+ const svg = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${String(widthPx)} ${String(heightPx)}" width="${String(widthPx)}" height="${String(heightPx)}" preserveAspectRatio="none">${marks.map(svgMark).join("")}</svg>`;
41
+ const url = svgPreviewDataUrl(svg);
42
+ dataUrls.set(preview, url);
43
+ return url;
44
+ };
45
+ /** The source an image paints from: its bytes, or its drawn preview. */
46
+ const paintedImageSource = (image) => image.preview ? previewToSvgDataUrl(image.preview) : image.src;
47
+ export { paintedImageSource, previewToSvgDataUrl };
@@ -1,6 +1,7 @@
1
1
  import { imageLuminanceFilter } from "../utils/imageLuminance.js";
2
2
  import { applySanitizedImageSrc } from "../utils/sanitizeImageSrc.js";
3
3
  import { anchorTargetAttrs, sanitizeExternalUrl } from "../utils/urlSecurity.js";
4
+ import { paintedImageSource } from "./previewSvg.js";
4
5
  // src/layout-painter/renderImage.ts
5
6
  /**
6
7
  * CSS class names for image elements
@@ -139,7 +140,7 @@ function renderImageFragment(fragment, block, _measure, _context, options = {})
139
140
  if (fragment.pmStart !== void 0) containerEl.dataset["pmStart"] = String(fragment.pmStart);
140
141
  if (fragment.pmEnd !== void 0) containerEl.dataset["pmEnd"] = String(fragment.pmEnd);
141
142
  const imgEl = doc.createElement("img");
142
- applySanitizedImageSrc(imgEl, block.src);
143
+ applySanitizedImageSrc(imgEl, paintedImageSource(block));
143
144
  imgEl.alt = block.alt ?? "";
144
145
  imgEl.style.width = "100%";
145
146
  imgEl.style.height = "100%";
@@ -10,6 +10,7 @@ import { BlockLookup } from "./index.js";
10
10
  */
11
11
  export type PageFloatingImage = {
12
12
  src: string;
13
+ preview?: document_d_exports.PreviewDescriptor;
13
14
  width: number;
14
15
  height: number;
15
16
  alt?: string;
@@ -17,6 +17,7 @@ import { pageHorizontalColumns, paragraphInlinePictureViewport } from "../utils/
17
17
  import { applySanitizedImageSrc } from "../utils/sanitizeImageSrc.js";
18
18
  import { eighthsToPixels, pointsToPixels } from "../utils/units.js";
19
19
  import { resolveAnchoredImagePosition as resolveAnchoredImagePosition$1 } from "./anchoredImagePosition.js";
20
+ import { paintedImageSource } from "./previewSvg.js";
20
21
  import { renderFragment } from "./renderFragment.js";
21
22
  import { applyImageVisualAttrs, hasImageVisualAttrs, renderImageFragment } from "./renderImage.js";
22
23
  import { renderParagraphFragment } from "./renderParagraph.js";
@@ -388,6 +389,7 @@ function extractFloatingImagesFromParagraph(block, fragmentY, geometry) {
388
389
  else if (imgRun.cssFloat === "right") wrapText = "left";
389
390
  floatingImages.push({
390
391
  src: imgRun.src,
392
+ ...imgRun.preview ? { preview: imgRun.preview } : {},
391
393
  width: imgRun.width,
392
394
  height: imgRun.height,
393
395
  ...imgRun.alt !== void 0 ? { alt: imgRun.alt } : {},
@@ -439,7 +441,7 @@ function renderFloatingImagesLayer(floatingImages, doc, layerMode = "front") {
439
441
  if (floatImg.pmStart !== void 0) container.dataset["pmStart"] = String(floatImg.pmStart);
440
442
  if (floatImg.pmEnd !== void 0) container.dataset["pmEnd"] = String(floatImg.pmEnd);
441
443
  const img = doc.createElement("img");
442
- applySanitizedImageSrc(img, floatImg.src);
444
+ applySanitizedImageSrc(img, paintedImageSource(floatImg));
443
445
  img.style.width = `${floatImg.width}px`;
444
446
  img.style.height = `${floatImg.height}px`;
445
447
  img.style.display = "block";
@@ -480,6 +482,7 @@ function renderHeaderFooterContent(content, context, options, layout) {
480
482
  const inlineRuns = [];
481
483
  for (const run of paragraphBlock.runs) if (run.kind === "image" && (isFloatingImageRun(run) || run.position)) floatingImages.push({
482
484
  src: run.src,
485
+ ...run.preview ? { preview: run.preview } : {},
483
486
  width: run.width,
484
487
  height: run.height,
485
488
  ...run.alt !== void 0 ? { alt: run.alt } : {},
@@ -584,7 +587,7 @@ function renderHeaderFooterContent(content, context, options, layout) {
584
587
  }
585
588
  for (const floatImg of floatingImages) {
586
589
  const img = doc.createElement("img");
587
- applySanitizedImageSrc(img, floatImg.src);
590
+ applySanitizedImageSrc(img, paintedImageSource(floatImg));
588
591
  img.width = floatImg.width;
589
592
  img.height = floatImg.height;
590
593
  if (floatImg.alt) img.alt = floatImg.alt;
@@ -1411,7 +1414,7 @@ function collectContentFingerprint(block, parts) {
1411
1414
  function runContentKey(run) {
1412
1415
  if (run.kind === "lineBreak") return "lb";
1413
1416
  if (run.kind === "renderedPageBreak") return "rpb";
1414
- if (run.kind === "image") return `img:${run.src}|${run.width}x${run.height}${run.transform ? `|tr:${run.transform}` : ""}`;
1417
+ if (run.kind === "image") return `img:${paintedImageSource(run)}|${run.width}x${run.height}${run.transform ? `|tr:${run.transform}` : ""}`;
1415
1418
  const parts = [run.kind];
1416
1419
  if (run.kind === "text") {
1417
1420
  parts.push(`t:${run.text}`);
@@ -27,6 +27,7 @@ import { anchorTargetAttrs, sanitizeExternalUrl } from "../utils/urlSecurity.js"
27
27
  import { borderStrokeToCss, resolveParagraphBorderHorizontalOutsets } from "./borderStroke.js";
28
28
  import { planCursiveJoiners, withCursiveJoiners } from "./cursiveJoiners.js";
29
29
  import { getAutomaticTextColorForBackground, setAuthoredBackgroundColor, setAuthoredTextColor } from "./documentColors.js";
30
+ import { paintedImageSource } from "./previewSvg.js";
30
31
  import { applyImageBorder, applyImageColorAttrs, applyImageVisualAttrs, hasImageCrop, hasImageVisualAttrs, wrapImageWithCrop } from "./renderImage.js";
31
32
  import { applySdtDataAttrs } from "./sdtBoundary.js";
32
33
  import { panic } from "better-result";
@@ -560,7 +561,7 @@ function getLeaderChar(leader) {
560
561
  function renderInlineImageRun({ run, doc, sizing }) {
561
562
  const img = doc.createElement("img");
562
563
  img.className = `${PARAGRAPH_CLASS_NAMES.run} ${PARAGRAPH_CLASS_NAMES.image}`;
563
- applyImageRunSource(img, run.src);
564
+ applyImageRunSource(img, paintedImageSource(run));
564
565
  img.width = run.width;
565
566
  img.height = run.height;
566
567
  img.style.width = `${run.width}px`;
@@ -629,7 +630,7 @@ function renderBlockImage(run, doc) {
629
630
  container.style.marginTop = `${run.distTop ?? 6}px`;
630
631
  container.style.marginBottom = `${run.distBottom ?? 6}px`;
631
632
  const img = doc.createElement("img");
632
- applyImageRunSource(img, run.src);
633
+ applyImageRunSource(img, paintedImageSource(run));
633
634
  img.width = run.width;
634
635
  img.height = run.height;
635
636
  if (run.alt) img.alt = run.alt;
@@ -1,6 +1,7 @@
1
1
  import { TableBlock, TableFragment, TableMeasure } from "../layout-engine/types.js";
2
2
  import { PageGeometry } from "./anchoredImagePosition.js";
3
3
  import { RenderContext } from "./renderUtils.js";
4
+ import { VisibleBand } from "../layout-engine/measure/tableVisibleBand.js";
4
5
  import { TextDirection } from "@stll/docx-core/model";
5
6
  /**
6
7
  * CSS class names for table elements
@@ -25,9 +26,11 @@ export type RenderTableFragmentOptions = {
25
26
  pageGeometry?: PageGeometry;
26
27
  };
27
28
  /**
28
- * Render a nested table (within a cell)
29
+ * Render a nested table (within a cell). A `visibleBand` builds only the rows
30
+ * that band shows; the table keeps its full height, so the rest of the cell
31
+ * flows the same.
29
32
  */
30
- export declare function renderNestedTable(block: TableBlock, measure: TableMeasure, context: RenderContext, doc: Document, frameWidth?: number): HTMLElement;
33
+ export declare function renderNestedTable(block: TableBlock, measure: TableMeasure, context: RenderContext, doc: Document, frameWidth?: number, visibleBand?: VisibleBand): HTMLElement;
31
34
  /**
32
35
  * Render a table fragment to DOM
33
36
  *
@@ -4,13 +4,15 @@ import { createTableCellFlowState, finishTableCellFlow, placeTableCellBlock } fr
4
4
  import { buildTableCellGrid, buildTableCellPlacements, getSourceCellAt, getTableCellSpacingInsetsY } from "../layout-engine/measure/tableCellGrid.js";
5
5
  import { tableFragmentBottomBorders } from "../layout-engine/measure/tableFragmentBorderGeometry.js";
6
6
  import { resolveTableInlineOffset, resolveTableInlinePlacement } from "../layout-engine/measure/tableInlinePlacement.js";
7
- import { isFloatingImageRun, isFloatingTextBoxBlock, resolveTableCellPadding, tableColumnsArePinned } from "../layout-engine/types.js";
7
+ import { bandFromOrigin, isOutsideBand, tableHasFloatingCellContent, tableRowPaintBottom } from "../layout-engine/measure/tableVisibleBand.js";
8
+ import { isFloatingTextBoxBlock, resolveTableCellPadding, tableColumnsArePinned } from "../layout-engine/types.js";
8
9
  import { paintsCssBorder } from "../utils/borderCss.js";
9
10
  import { applySanitizedImageSrc } from "../utils/sanitizeImageSrc.js";
10
11
  import { emuToPixels } from "../utils/units.js";
11
12
  import { resolveAnchoredImagePosition } from "./anchoredImagePosition.js";
12
13
  import { borderStrokeToCss, resolveCssBorderStroke } from "./borderStroke.js";
13
14
  import { getAutomaticTextColorForBackground, setAuthoredBackgroundColor, setAuthoredTextColor } from "./documentColors.js";
15
+ import { paintedImageSource } from "./previewSvg.js";
14
16
  import { applyImageVisualAttrs, hasImageCrop, hasImageVisualAttrs } from "./renderImage.js";
15
17
  import { renderParagraphFragment } from "./renderParagraph.js";
16
18
  import { renderTextBoxFragment } from "./renderTextBox.js";
@@ -63,7 +65,7 @@ const CELL_TEXT_ROTATION_DEGREES = {
63
65
  };
64
66
  /** The quarter turn a cell's `w:textDirection` puts on its content. */
65
67
  const cellTextRotationDegrees = (direction) => direction === void 0 ? 0 : CELL_TEXT_ROTATION_DEGREES[TEXT_DIRECTION_FLOW_BY_TOKEN[direction]];
66
- function renderCellContent({ cell, cellMeasure, context, doc, contentWidthOverride, pageContentPosition }) {
68
+ function renderCellContent({ cell, cellMeasure, context, doc, contentWidthOverride, pageContentPosition, visibleBand }) {
67
69
  const contentEl = doc.createElement("div");
68
70
  contentEl.className = TABLE_CLASS_NAMES.cellContent;
69
71
  contentEl.style.position = "relative";
@@ -101,7 +103,7 @@ function renderCellContent({ cell, cellMeasure, context, doc, contentWidthOverri
101
103
  if (img.pmStart !== void 0) imgContainer.dataset["pmStart"] = String(img.pmStart);
102
104
  if (img.pmEnd !== void 0) imgContainer.dataset["pmEnd"] = String(img.pmEnd);
103
105
  const imgEl = doc.createElement("img");
104
- applySanitizedImageSrc(imgEl, img.src);
106
+ applySanitizedImageSrc(imgEl, paintedImageSource(img));
105
107
  imgEl.style.width = `${img.width}px`;
106
108
  imgEl.style.height = `${img.height}px`;
107
109
  imgEl.style.display = "block";
@@ -184,9 +186,16 @@ function renderCellContent({ cell, cellMeasure, context, doc, contentWidthOverri
184
186
  } else if (block?.kind === "table" && measure?.kind === "table") {
185
187
  const tableBlock = block;
186
188
  const tableMeasure = measure;
187
- const nestedTableEl = renderNestedTable(tableBlock, tableMeasure, context, doc, contentWidth);
188
- nestedTableEl.style.position = "relative";
189
189
  const placement = placeTableCellBlock(flowState, tableBlock, tableMeasure);
190
+ if (isOutsideBand(visibleBand, placement.top, placement.contentTop + placement.contentHeight)) {
191
+ const unbuilt = doc.createElement("div");
192
+ unbuilt.style.height = `${placement.leadingSpacing + placement.contentHeight}px`;
193
+ contentEl.append(unbuilt);
194
+ anchorParagraphY = flowState.height;
195
+ continue;
196
+ }
197
+ const nestedTableEl = renderNestedTable(tableBlock, tableMeasure, context, doc, contentWidth, visibleBand && bandFromOrigin(visibleBand, placement.contentTop));
198
+ nestedTableEl.style.position = "relative";
190
199
  if (placement.leadingSpacing > 0) {
191
200
  const spacer = doc.createElement("div");
192
201
  spacer.style.height = `${placement.leadingSpacing}px`;
@@ -264,18 +273,12 @@ function resolveCellTextBoxY(block) {
264
273
  if (vertical?.posOffset !== void 0) return emuToPixels(vertical.posOffset);
265
274
  return 0;
266
275
  }
267
- function tableHasFloatingCellContent(block) {
268
- for (const row of block.rows) for (const cell of row.cells) for (const cellBlock of cell.blocks) {
269
- if (cellBlock.kind === "textBox" && isFloatingTextBoxBlock(cellBlock)) return true;
270
- if (cellBlock.kind === "paragraph" && cellBlock.runs.some((run) => run.kind === "image" && isFloatingImageRun(run))) return true;
271
- if (cellBlock.kind === "table" && tableHasFloatingCellContent(cellBlock)) return true;
272
- }
273
- return false;
274
- }
275
276
  /**
276
- * Render a nested table (within a cell)
277
+ * Render a nested table (within a cell). A `visibleBand` builds only the rows
278
+ * that band shows; the table keeps its full height, so the rest of the cell
279
+ * flows the same.
277
280
  */
278
- function renderNestedTable(block, measure, context, doc, frameWidth = context.contentWidth ?? measure.totalWidth) {
281
+ function renderNestedTable(block, measure, context, doc, frameWidth = context.contentWidth ?? measure.totalWidth, visibleBand) {
279
282
  const tableEl = doc.createElement("div");
280
283
  tableEl.className = `${TABLE_CLASS_NAMES.table} layout-nested-table`;
281
284
  tableEl.style.position = "relative";
@@ -313,11 +316,12 @@ function renderNestedTable(block, measure, context, doc, frameWidth = context.co
313
316
  cellSpacing: block.cellSpacing
314
317
  });
315
318
  let y = 0;
319
+ let paintedRow = false;
316
320
  for (let rowIndex = 0; rowIndex < block.rows.length; rowIndex++) {
317
321
  const row = block.rows[rowIndex];
318
322
  const rowMeasure = measure.rows[rowIndex];
319
323
  if (!row || !rowMeasure) continue;
320
- if (row.hidden) {
324
+ if (row.hidden || isOutsideBand(visibleBand, y, tableRowPaintBottom(row, rowIndex, rowYPositions))) {
321
325
  y += rowMeasure.height;
322
326
  continue;
323
327
  }
@@ -331,11 +335,13 @@ function renderNestedTable(block, measure, context, doc, frameWidth = context.co
331
335
  context,
332
336
  doc,
333
337
  rowYPositions,
338
+ isFirstRowInFragment: visibleBand !== void 0 && !paintedRow && y >= visibleBand.top,
334
339
  bidi: block.bidi === true,
335
340
  columnsPinned,
336
341
  cellGrid,
337
342
  cellPlacements,
338
343
  cellSpacing: block.cellSpacing,
344
+ ...visibleBand ? { visibleBand: bandFromOrigin(visibleBand, y) } : {},
339
345
  inlineOffset: resolveTableInlineOffset({
340
346
  table: block,
341
347
  rowJustification: row.justification,
@@ -344,6 +350,7 @@ function renderNestedTable(block, measure, context, doc, frameWidth = context.co
344
350
  }) - tableInlineOffset
345
351
  });
346
352
  tableEl.append(rowEl);
353
+ paintedRow = true;
347
354
  y += rowMeasure.height;
348
355
  }
349
356
  tableEl.style.height = `${y}px`;
@@ -391,7 +398,7 @@ function renderCellDiagonalBorder({ border, direction, cellWidth, cellHeight, do
391
398
  }
392
399
  return line;
393
400
  }
394
- function renderTableCell({ cell, cellMeasure, x, y = 0, width, rowHeight, borderFlags, columnsPinned, context, doc, contentClip, pageContentPosition }) {
401
+ function renderTableCell({ cell, cellMeasure, x, y = 0, width, rowHeight, borderFlags, columnsPinned, context, doc, contentClip, visibleBand, pageContentPosition }) {
395
402
  const cellEl = doc.createElement("div");
396
403
  cellEl.className = TABLE_CLASS_NAMES.cell;
397
404
  cellEl.style.position = "absolute";
@@ -430,11 +437,15 @@ function renderTableCell({ cell, cellMeasure, x, y = 0, width, rowHeight, border
430
437
  }
431
438
  const cellTextRotation = cellTextRotationDegrees(cell.textDirection);
432
439
  const contentWidthOverride = cellTextRotation === 0 ? void 0 : Math.max(1, rowHeight - padTop - padBottom);
440
+ const contentMovesInCell = contentClip === void 0 && (cell.verticalAlign === "center" || cell.verticalAlign === "bottom");
441
+ const topBorderHeight = borderFlags.drawTop && hasVisibleBorder(cell.borders?.top) ? cell.borders?.top?.width ?? 0 : 0;
442
+ const contentBand = visibleBand && cellTextRotation === 0 && !contentMovesInCell ? bandFromOrigin(visibleBand, padTop + topBorderHeight) : void 0;
433
443
  const renderedContent = renderCellContent({
434
444
  cell,
435
445
  cellMeasure,
436
446
  context,
437
447
  doc,
448
+ ...contentBand ? { visibleBand: contentBand } : {},
438
449
  ...contentWidthOverride !== void 0 ? { contentWidthOverride } : {},
439
450
  ...pageContentPosition ? { pageContentPosition: {
440
451
  geometry: pageContentPosition.geometry,
@@ -512,7 +523,7 @@ const continuationRowBottomBorderOffsets = (fragment, block, measure, cellGrid)
512
523
  snapAfterRow
513
524
  });
514
525
  };
515
- function renderTableRow({ row, rowMeasure, rowIndex, y, columnWidths, totalRows, context, doc, rowYPositions, isFirstRowInFragment, bidi = false, columnsPinned = false, cellGrid, cellPlacements, cellSpacing, contentClip, pageContentPosition, inlineOffset = 0, bottomBorderOffset = 0 }) {
526
+ function renderTableRow({ row, rowMeasure, rowIndex, y, columnWidths, totalRows, context, doc, rowYPositions, isFirstRowInFragment, bidi = false, columnsPinned = false, cellGrid, cellPlacements, cellSpacing, contentClip, visibleBand, pageContentPosition, inlineOffset = 0, bottomBorderOffset = 0 }) {
516
527
  const bordersSeparated = (cellSpacing ?? 0) > 0;
517
528
  const rowEl = doc.createElement("div");
518
529
  rowEl.className = TABLE_CLASS_NAMES.row;
@@ -572,6 +583,7 @@ function renderTableRow({ row, rowMeasure, rowIndex, y, columnWidths, totalRows,
572
583
  context,
573
584
  doc,
574
585
  ...boxClip ? { contentClip: boxClip } : {},
586
+ ...visibleBand ? { visibleBand: bandFromOrigin(visibleBand, spacing.top) } : {},
575
587
  ...pageContentPosition ? { pageContentPosition: {
576
588
  geometry: pageContentPosition.geometry,
577
589
  x: pageContentPosition.x + inlineOffset + cellLeft,
@@ -621,7 +633,8 @@ function renderTableFragment(fragment, block, measure, context, options = {}) {
621
633
  tableEl.style.position = "absolute";
622
634
  tableEl.style.width = `${fragment.width}px`;
623
635
  tableEl.style.height = `${fragment.height}px`;
624
- tableEl.style.overflow = tableHasFloatingCellContent(block) ? "visible" : "hidden";
636
+ const hasFloatingCellContent = tableHasFloatingCellContent(block);
637
+ tableEl.style.overflow = hasFloatingCellContent ? "visible" : "hidden";
625
638
  tableEl.dataset["blockId"] = String(fragment.blockId);
626
639
  tableEl.dataset["fromRow"] = String(fragment.fromRow);
627
640
  tableEl.dataset["toRow"] = String(fragment.toRow);
@@ -745,6 +758,7 @@ function renderTableFragment(fragment, block, measure, context, options = {}) {
745
758
  cellSpacing: block.cellSpacing,
746
759
  bottomBorderOffset: contentRowBottomBorderOffsets[rowIndex - fragment.fromRow] ?? 0,
747
760
  ...contentClip ? { contentClip } : {},
761
+ ...contentClip && !hasFloatingCellContent ? { visibleBand: contentClip } : {},
748
762
  ...tablePageContentPosition ? { pageContentPosition: {
749
763
  ...tablePageContentPosition,
750
764
  y: tablePageContentPosition.y + y
@@ -1,5 +1,6 @@
1
1
  import { Node } from "prosemirror-model";
2
2
  import { Transaction } from "prosemirror-state";
3
+ import { Transform } from "prosemirror-transform";
3
4
  /** The id a text box anchor names, or `undefined` for anything else. */
4
5
  export declare const textBoxAnchorIdOf: (node: Node) => string | undefined;
5
6
  /** The anchor ids of the text boxes drawn in `node`. */
@@ -31,4 +32,4 @@ export declare const textBoxAnchorIdsBetween: (doc: Node, from: number, to: numb
31
32
  * boxes drawn in it, which stand between the two, past that paragraph, where
32
33
  * they follow the joined one. Returns whether any moved.
33
34
  */
34
- export declare const moveTextBoxesPastNextParagraph: (tr: Transaction, position: number) => boolean;
35
+ export declare const moveTextBoxesPastNextParagraph: (tr: Transform, position: number) => boolean;
@@ -32,7 +32,7 @@ import { paragraphRunStyleContextAt } from "../runStyleFormatting.js";
32
32
  import { sectionRecordCopyPositions } from "../sectionCarrier.js";
33
33
  import { getTableCellMergeChange } from "../tableCellMergeRevision.js";
34
34
  import { isTableCellRetainedInReviewView } from "../tableCellRevisionVisibility.js";
35
- import { markRowEmptiedInBatch, reconcileTableGridAfterColumnRemoval, removeRowsWithoutCellsAfterBatch, removeTableRow } from "../tableGridMutation.js";
35
+ import { markRowEmptiedInBatch, reconcileOmittedGridSlots, reconcileTableGridAfterColumnRemoval, removeRowsWithoutCellsAfterBatch, removeTableRow, rowHoldsNoCells } from "../tableGridMutation.js";
36
36
  import { runInCellPending, runParagraphIntoTable } from "../tableRunIn.js";
37
37
  import { retainedTrackedRevisionMark, trackedRevisionPathOf } from "../trackedRevisionPath.js";
38
38
  import { extractTrackedChanges } from "../utils/extractTrackedChanges.js";
@@ -431,7 +431,7 @@ function resolveChange(from, to, mode, revisionIds) {
431
431
  follows,
432
432
  holdsContent: paragraphContentOf(paragraph),
433
433
  markWasAdded: op.markWasAdded,
434
- containerStillEndsWithParagraph: resolved.parent.maybeChild(resolved.index() - 1)?.type.name === "paragraph",
434
+ containerStillEndsWithParagraph: preceding?.type.name === "paragraph" || preceding !== void 0 && resolved.parent.type.name === "blockSdt",
435
435
  followingTableCanReceiveRunIn: follows === "table" && boundaries.length === 0 && !pendingTables.some((position) => tr.mapping.map(position) === nextPos) && !ownsSectionEndpoint(paragraph),
436
436
  needsFollowingCommentHost: follows === "table" && preceding?.type.name !== "paragraph" && retainedBoundaries.blocks.length === 0 && retainedBoundaries.comments.length > 0,
437
437
  removedSectionProperties: op.markWasAdded && sectionProperties != null,
@@ -576,10 +576,20 @@ const terminalTableDeletionIsPending = (tr) => {
576
576
  };
577
577
  /** Resolve the Folio-only receiver Word needs after a terminal deleted table. */
578
578
  const resolveTerminalTableReviewCarrier = (tr, mode) => {
579
- const carrier = tr.doc.lastChild;
579
+ let position = tr.doc.content.size;
580
+ let carrier = null;
581
+ for (let index = tr.doc.childCount - 1; index >= 0; index--) {
582
+ carrier = tr.doc.child(index);
583
+ position -= carrier.nodeSize;
584
+ if (carrier.type.name !== "textBox") break;
585
+ }
580
586
  if (carrier?.type.name !== "paragraph" || carrier.attrs["reviewCarrier"] !== REVIEW_CARRIERS.TERMINAL_TABLE) return;
581
- const position = tr.doc.content.size - carrier.nodeSize;
582
- if (mode === "accept") {
587
+ let pending = carrier.attrs["pPrMark"] != null;
588
+ carrier.forEach((child) => {
589
+ pending ||= child.marks.some(({ type }) => ["insertion", "deletion"].includes(type.name));
590
+ });
591
+ if (pending) return;
592
+ if (mode === "accept" || carrier.content.size > 0) {
583
593
  tr.setNodeAttribute(position, "reviewCarrier", void 0);
584
594
  return;
585
595
  }
@@ -739,13 +749,15 @@ function deleteTableCellAt(tr, cellPos, emptied) {
739
749
  const cellOffset = cellPos - resolved.start(tableDepth);
740
750
  const removedColumn = TableMap.get(table).findCell(cellOffset).left;
741
751
  const spansDown = Number(cell.attrs["rowspan"]) > 1;
742
- if (row.childCount > 1 || spansDown) {
743
- if (row.childCount === 1) markRowEmptiedInBatch({
752
+ const holdsOtherCells = !rowHoldsNoCells(row, cell);
753
+ if (holdsOtherCells || spansDown) {
754
+ if (!holdsOtherCells) markRowEmptiedInBatch({
744
755
  tr,
745
756
  rowPosition: resolved.start() - 1,
746
757
  emptied
747
758
  });
748
759
  tr.delete(cellPos, cellPos + cell.nodeSize);
760
+ reconcileOmittedGridSlots(tr, tablePosition, table, removedColumn);
749
761
  reconcileTableGridAfterColumnRemoval({
750
762
  tr,
751
763
  tablePosition,
@@ -759,6 +771,7 @@ function deleteTableCellAt(tr, cellPos, emptied) {
759
771
  return;
760
772
  }
761
773
  deleteTableRowAt(tr, resolved.start() - 1);
774
+ reconcileOmittedGridSlots(tr, tablePosition, table, removedColumn);
762
775
  reconcileTableGridAfterColumnRemoval({
763
776
  tr,
764
777
  tablePosition,
@@ -0,0 +1,9 @@
1
+ import { Command } from "prosemirror-state";
2
+ /**
3
+ * Delete what the caret reaches past the inline anchors beside it.
4
+ *
5
+ * Left to the browser, the key removes the anchor's element, and the next DOM
6
+ * read loses the node: a bookmark or comment range, with the other half of its
7
+ * pair, while the text stays. Suggesting mode tracks the key before it gets here.
8
+ */
9
+ export declare const deleteBesideInlineAnchor: (join: Command, direction: "backward" | "forward") => Command;
@@ -0,0 +1,36 @@
1
+ import { isInlineAnchor } from "../extensions/nodes/inlineAnchorDom.js";
2
+ import { EditorState, TextSelection } from "prosemirror-state";
3
+ // src/prosemirror/commands/deleteBesideInlineAnchor.ts
4
+ /** The length of the first or last user-perceived character of `text`. */
5
+ const characterLength = (text, backward) => {
6
+ const segments = [...new Intl.Segmenter().segment(text)];
7
+ return (backward ? segments.at(-1) : segments.at(0))?.segment.length ?? 1;
8
+ };
9
+ /**
10
+ * Delete what the caret reaches past the inline anchors beside it.
11
+ *
12
+ * Left to the browser, the key removes the anchor's element, and the next DOM
13
+ * read loses the node: a bookmark or comment range, with the other half of its
14
+ * pair, while the text stays. Suggesting mode tracks the key before it gets here.
15
+ */
16
+ const deleteBesideInlineAnchor = (join, direction) => (state, dispatch, view) => {
17
+ const { selection, doc } = state;
18
+ if (!(selection instanceof TextSelection) || !selection.empty) return false;
19
+ const backward = direction === "backward";
20
+ const adjacent = (position) => {
21
+ const $position = doc.resolve(position);
22
+ return backward ? $position.nodeBefore : $position.nodeAfter;
23
+ };
24
+ let cursor = selection.from;
25
+ for (let node = adjacent(cursor); node && isInlineAnchor(node); node = adjacent(cursor)) cursor += backward ? -node.nodeSize : node.nodeSize;
26
+ if (cursor === selection.from) return false;
27
+ const next = adjacent(cursor);
28
+ if (!next) return join(EditorState.create({
29
+ doc,
30
+ selection: TextSelection.create(doc, cursor)
31
+ }), dispatch, view);
32
+ const size = next.isText ? characterLength(next.text ?? "", backward) : next.nodeSize;
33
+ dispatch?.(state.tr.delete(backward ? cursor - size : cursor, backward ? cursor : cursor + size).scrollIntoView());
34
+ return true;
35
+ };
36
+ export { deleteBesideInlineAnchor };
@@ -1,5 +1,6 @@
1
1
  import { Schema, Slice } from "prosemirror-model";
2
2
  import { Command } from "prosemirror-state";
3
+ import { EditorView } from "prosemirror-view";
3
4
  /**
4
5
  * Dispatched on the editor view DOM when the clipboard read behind a
5
6
  * "paste without formatting" keystroke fails (e.g. clipboard-read permission
@@ -18,6 +19,11 @@ export declare const CLIPBOARD_READ_ERROR_EVENT = "folio:clipboard-read-error";
18
19
  * editor's default text paste flows into the current line.
19
20
  */
20
21
  export declare function buildPlainTextSlice(text: string, schema: Schema): Slice;
22
+ /**
23
+ * Put plain text in place of the selection: through the session that owns the
24
+ * view, or as a suggestion when suggesting, as a paste from the keyboard is.
25
+ */
26
+ export declare const pastePlainTextSlice: (view: EditorView, slice: Slice) => void;
21
27
  /**
22
28
  * Read the clipboard and insert it as unformatted text at the current selection.
23
29
  *
@@ -1,4 +1,5 @@
1
1
  import { dispatchClipboardIntent } from "../clipboardIntent.js";
2
+ import { handleSuggestionPaste, suggestionModeKey } from "../plugins/suggestionMode.js";
2
3
  import { Fragment, Slice } from "prosemirror-model";
3
4
  // src/prosemirror/commands/pastePlainText.ts
4
5
  /**
@@ -34,6 +35,16 @@ function buildPlainTextSlice(text, schema) {
34
35
  return Slice.maxOpen(Fragment.fromArray(paragraphs));
35
36
  }
36
37
  /**
38
+ * Put plain text in place of the selection: through the session that owns the
39
+ * view, or as a suggestion when suggesting, as a paste from the keyboard is.
40
+ */
41
+ const pastePlainTextSlice = (view, slice) => {
42
+ if (dispatchClipboardIntent(view, slice) !== void 0) return;
43
+ const suggesting = suggestionModeKey.getState(view.state);
44
+ if (suggesting?.active && handleSuggestionPaste(view, slice, suggesting)) return;
45
+ view.dispatch(view.state.tr.replaceSelection(slice).scrollIntoView());
46
+ };
47
+ /**
37
48
  * Read the clipboard and insert it as unformatted text at the current selection.
38
49
  *
39
50
  * Dry-runnable per the ProseMirror command convention: applicability does not
@@ -54,8 +65,7 @@ const pasteWithoutFormatting = (state, dispatch, view) => {
54
65
  const { schema } = state;
55
66
  navigator.clipboard.readText().then((text) => {
56
67
  if (!text || view.isDestroyed) return;
57
- const slice = buildPlainTextSlice(text, schema);
58
- if (dispatchClipboardIntent(view, slice) === void 0) view.dispatch(view.state.tr.replaceSelection(slice).scrollIntoView());
68
+ pastePlainTextSlice(view, buildPlainTextSlice(text, schema));
59
69
  }).catch((error) => {
60
70
  if (typeof CustomEvent === "function" && !view.isDestroyed) view.dom.dispatchEvent(new CustomEvent(CLIPBOARD_READ_ERROR_EVENT, {
61
71
  detail: { error },
@@ -64,4 +74,4 @@ const pasteWithoutFormatting = (state, dispatch, view) => {
64
74
  });
65
75
  return true;
66
76
  };
67
- export { CLIPBOARD_READ_ERROR_EVENT, buildPlainTextSlice, pasteWithoutFormatting };
77
+ export { CLIPBOARD_READ_ERROR_EVENT, buildPlainTextSlice, pastePlainTextSlice, pasteWithoutFormatting };
@@ -376,6 +376,7 @@ const resolvePureTableMerges = ({ table, mode, rowMetadata, tablePropertyTouched
376
376
  const widthRemovals = [];
377
377
  let currentWidth = map.width;
378
378
  let removedCell = false;
379
+ const removedColumns = [];
379
380
  const deletedRows = /* @__PURE__ */ new Set();
380
381
  const byPosition = /* @__PURE__ */ new Map();
381
382
  const ordered = [];
@@ -387,7 +388,7 @@ const resolvePureTableMerges = ({ table, mode, rowMetadata, tablePropertyTouched
387
388
  const node = row.child(cellIndex);
388
389
  const rectangle = cellRectangle(cellOffset);
389
390
  const left = rectangle.left;
390
- for (let coveredRow = rectangle.top; coveredRow < rectangle.bottom; coveredRow++) rowOccupancy[coveredRow] = elementAt(rowOccupancy, coveredRow) + (rectangle.right - rectangle.left);
391
+ for (let coveredRow = rectangle.top; coveredRow < rectangle.bottom && !node.attrs["_omittedGridSlot"]; coveredRow++) rowOccupancy[coveredRow] = elementAt(rowOccupancy, coveredRow) + (rectangle.right - rectangle.left);
391
392
  const initial = elementAt(elementAt(rowMetadata, rowIndex).cells, cellIndex);
392
393
  const entry = {
393
394
  node: mergeDecisions.origins.has(cellOffset) ? node.type.create(resolvedTableMergeOriginAttrs(node), node.content, node.marks) : node,
@@ -407,6 +408,9 @@ const resolvePureTableMerges = ({ table, mode, rowMetadata, tablePropertyTouched
407
408
  rowOffset += row.nodeSize;
408
409
  }
409
410
  for (const width of rowOccupancy) widthCounts.set(width, (widthCounts.get(width) ?? 0) + 1);
411
+ const spanOf = ({ node }) => Number(node.attrs["colspan"]) || 1;
412
+ const omittedIn = (rowIndex) => [...elementAt(rowCells, rowIndex).values()].filter(({ node }) => node.attrs["_omittedGridSlot"] != null);
413
+ currentWidth = Math.max(0, ...rowOccupancy);
410
414
  const changeRowWidth = (rowIndex, nextWidth) => {
411
415
  if (!elementAt(activeRows, rowIndex)) return;
412
416
  const previous = elementAt(rowOccupancy, rowIndex);
@@ -427,12 +431,13 @@ const resolvePureTableMerges = ({ table, mode, rowMetadata, tablePropertyTouched
427
431
  }, entry.node.content, entry.node.marks);
428
432
  } else {
429
433
  removedCell = true;
434
+ removedColumns.push(entry.left);
430
435
  const previousWidth = currentWidth;
431
436
  const rectangle = cellRectangle(entry.position);
432
437
  const colspan = rectangle.right - rectangle.left;
433
438
  for (let coveredRow = rectangle.top; coveredRow < rectangle.bottom; coveredRow++) changeRowWidth(coveredRow, elementAt(rowOccupancy, coveredRow) - colspan);
434
439
  elementAt(rowCells, entry.row).delete(entry.left);
435
- if (elementAt(rowCells, entry.row).size === 0) {
440
+ if ([...elementAt(rowCells, entry.row).values()].every(({ node }) => node.attrs["_omittedGridSlot"] != null)) {
436
441
  deletedRows.add(entry.row);
437
442
  activeRows[entry.row] = false;
438
443
  const rowWidth = elementAt(rowOccupancy, entry.row);
@@ -530,6 +535,29 @@ const resolvePureTableMerges = ({ table, mode, rowMetadata, tablePropertyTouched
530
535
  _docxVMergeContinuationCells: remaining.length > 0 ? remaining : null
531
536
  }, entry.node.content, entry.node.marks);
532
537
  }
538
+ for (let rowIndex = 0; rowIndex < rows.length; rowIndex++) {
539
+ if (deletedRows.has(rowIndex)) continue;
540
+ const slots = omittedIn(rowIndex);
541
+ let excess = elementAt(rowOccupancy, rowIndex) + slots.reduce((total, slot) => total + spanOf(slot), 0) - currentWidth;
542
+ const atRemoval = ({ left, node }) => removedColumns.some((column) => column >= left && column < left + (Number(node.attrs["colspan"]) || 1));
543
+ const order = [...slots.filter(atRemoval), ...slots.filter((slot) => !atRemoval(slot)).toReversed()];
544
+ for (const slot of order) {
545
+ if (excess <= 0) break;
546
+ const span = spanOf(slot);
547
+ if (span <= excess) {
548
+ elementAt(rowCells, rowIndex).delete(slot.left);
549
+ removedCell = true;
550
+ excess -= span;
551
+ continue;
552
+ }
553
+ slot.touched = true;
554
+ slot.node = slot.node.type.create({
555
+ ...slot.node.attrs,
556
+ colspan: span - excess
557
+ }, slot.node.content, slot.node.marks);
558
+ excess = 0;
559
+ }
560
+ }
533
561
  if (deletedRows.size === rows.length) return {
534
562
  node: null,
535
563
  changed: true,