@stll/folio-core 0.66.1 → 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 (170) hide show
  1. package/dist/ai-edits/apply.d.ts +13 -1
  2. package/dist/ai-edits/apply.js +572 -140
  3. package/dist/ai-edits/batch-claims.d.ts +26 -0
  4. package/dist/ai-edits/batch-claims.js +32 -5
  5. package/dist/ai-edits/clean-text.js +4 -1
  6. package/dist/ai-edits/headless.d.ts +6 -0
  7. package/dist/ai-edits/headless.js +25 -3
  8. package/dist/ai-edits/newListNumbering.d.ts +4 -1
  9. package/dist/ai-edits/newListNumbering.js +4 -2
  10. package/dist/ai-edits/read.js +6 -4
  11. package/dist/ai-edits/snapshot.js +24 -14
  12. package/dist/ai-edits/table-cell-mutations.js +3 -2
  13. package/dist/ai-edits/table-row-column-mutations.js +20 -6
  14. package/dist/ai-edits/types.d.ts +1 -1
  15. package/dist/controller/canonicalComposition.d.ts +1 -1
  16. package/dist/controller/canonicalComposition.js +76 -18
  17. package/dist/controller/canonicalInput.d.ts +0 -1
  18. package/dist/controller/canonicalInput.js +19 -1
  19. package/dist/controller/canonicalSession.js +1 -2
  20. package/dist/controller/hiddenEditorManager.d.ts +6 -0
  21. package/dist/controller/hiddenEditorManager.js +3 -1
  22. package/dist/controller/layoutPipeline.d.ts +2 -0
  23. package/dist/controller/layoutPipeline.js +7 -3
  24. package/dist/controller/layoutSession.d.ts +1 -0
  25. package/dist/display-list/build/tablePrimitives.d.ts +3 -1
  26. package/dist/display-list/build/tablePrimitives.js +29 -13
  27. package/dist/document-operations.d.ts +13 -1
  28. package/dist/document-operations.js +11 -4
  29. package/dist/docx/chartPreview.d.ts +4 -1
  30. package/dist/docx/chartPreview.js +26 -15
  31. package/dist/docx/listNumberingInstances.d.ts +6 -4
  32. package/dist/docx/listNumberingInstances.js +12 -11
  33. package/dist/docx/mainDocumentPart.d.ts +6 -0
  34. package/dist/docx/mainDocumentPart.js +65 -0
  35. package/dist/docx/numberingIds.d.ts +10 -0
  36. package/dist/docx/numberingIds.js +5 -1
  37. package/dist/docx/packageParts.d.ts +1 -1
  38. package/dist/docx/packageParts.js +10 -4
  39. package/dist/docx/paragraphParser.js +16 -3
  40. package/dist/docx/paragraphProperties.js +2 -1
  41. package/dist/docx/previewBudget.d.ts +6 -0
  42. package/dist/docx/previewBudget.js +7 -1
  43. package/dist/docx/rezip.js +4 -4
  44. package/dist/docx/serializer/paragraphSerializer.js +86 -66
  45. package/dist/docx/shapeAlternateContent.js +19 -0
  46. package/dist/docx/unzip.js +2 -0
  47. package/dist/i18n/messages/ar.gen.js +2 -0
  48. package/dist/i18n/messages/catalogs.gen.d.ts +34 -0
  49. package/dist/i18n/messages/catalogs.gen.js +34 -0
  50. package/dist/i18n/messages/cs.gen.js +2 -0
  51. package/dist/i18n/messages/de.gen.js +2 -0
  52. package/dist/i18n/messages/en.gen.js +2 -0
  53. package/dist/i18n/messages/es.gen.js +2 -0
  54. package/dist/i18n/messages/et.gen.js +2 -0
  55. package/dist/i18n/messages/fr.gen.js +2 -0
  56. package/dist/i18n/messages/he.gen.js +2 -0
  57. package/dist/i18n/messages/hi.gen.js +2 -0
  58. package/dist/i18n/messages/hu.gen.js +2 -0
  59. package/dist/i18n/messages/lt.gen.js +2 -0
  60. package/dist/i18n/messages/lv.gen.js +2 -0
  61. package/dist/i18n/messages/messages.gen.d.ts +2 -0
  62. package/dist/i18n/messages/pl.gen.js +2 -0
  63. package/dist/i18n/messages/pt-BR.gen.js +2 -0
  64. package/dist/i18n/messages/sk.gen.js +2 -0
  65. package/dist/i18n/messages/tr.gen.js +2 -0
  66. package/dist/i18n/messages/zh-CN.gen.js +2 -0
  67. package/dist/internal/wholeStoryRevisionResolution.d.ts +1 -1
  68. package/dist/internal/wholeStoryRevisionResolution.js +81 -21
  69. package/dist/layout-bridge/convert/altChunkPlaceholder.d.ts +10 -0
  70. package/dist/layout-bridge/convert/altChunkPlaceholder.js +70 -0
  71. package/dist/layout-bridge/convert/fixedTableColumnWidths.js +2 -1
  72. package/dist/layout-bridge/convert/flowConversionShared.d.ts +10 -0
  73. package/dist/layout-bridge/convert/flowConversionShared.js +11 -1
  74. package/dist/layout-bridge/convert/footnoteLayout.d.ts +1 -0
  75. package/dist/layout-bridge/convert/footnoteLayout.js +4 -1
  76. package/dist/layout-bridge/convert/headerFooterLayout.d.ts +1 -0
  77. package/dist/layout-bridge/convert/headerFooterLayout.js +6 -1
  78. package/dist/layout-bridge/convert/runMarkFormatting.js +1 -0
  79. package/dist/layout-bridge/convert/tableConversion.js +6 -2
  80. package/dist/layout-bridge/convert/toFlowBlocks.js +4 -0
  81. package/dist/layout-bridge/engine/clickToPosition.js +5 -1
  82. package/dist/layout-engine/measure/tableCellFloating.d.ts +2 -0
  83. package/dist/layout-engine/measure/tableCellFloating.js +1 -0
  84. package/dist/layout-engine/measure/tableVisibleBand.d.ts +16 -0
  85. package/dist/layout-engine/measure/tableVisibleBand.js +28 -0
  86. package/dist/layout-engine/tableLayout.js +7 -4
  87. package/dist/layout-engine/tableRowBreak.d.ts +10 -0
  88. package/dist/layout-engine/tableRowBreak.js +151 -36
  89. package/dist/layout-engine/types.d.ts +7 -2
  90. package/dist/layout-painter/previewSvg.d.ts +8 -0
  91. package/dist/layout-painter/previewSvg.js +47 -0
  92. package/dist/layout-painter/renderImage.js +2 -1
  93. package/dist/layout-painter/renderPage.d.ts +1 -0
  94. package/dist/layout-painter/renderPage.js +6 -3
  95. package/dist/layout-painter/renderParagraph.js +3 -2
  96. package/dist/layout-painter/renderTable.d.ts +5 -2
  97. package/dist/layout-painter/renderTable.js +33 -19
  98. package/dist/markdown/renderRuns.js +68 -12
  99. package/dist/prosemirror/anchoredTextBoxes.d.ts +2 -1
  100. package/dist/prosemirror/commands/comments.js +22 -7
  101. package/dist/prosemirror/commands/deleteBesideInlineAnchor.d.ts +9 -0
  102. package/dist/prosemirror/commands/deleteBesideInlineAnchor.js +36 -0
  103. package/dist/prosemirror/commands/pastePlainText.d.ts +6 -0
  104. package/dist/prosemirror/commands/pastePlainText.js +13 -3
  105. package/dist/prosemirror/commands/resolveAllTableChanges.js +30 -2
  106. package/dist/prosemirror/commands/resolveParagraphProperties.js +15 -2
  107. package/dist/prosemirror/commentReferenceIntegrity.d.ts +8 -2
  108. package/dist/prosemirror/commentReferenceIntegrity.js +19 -4
  109. package/dist/prosemirror/conversion/fromProseDoc.js +94 -22
  110. package/dist/prosemirror/conversion/hyphenTextCarriers.d.ts +23 -1
  111. package/dist/prosemirror/conversion/hyphenTextCarriers.js +46 -1
  112. package/dist/prosemirror/conversion/toProseDoc.js +21 -13
  113. package/dist/prosemirror/extensions/StarterKit.js +1 -1
  114. package/dist/prosemirror/extensions/core/ParagraphExtension.d.ts +3 -1
  115. package/dist/prosemirror/extensions/core/ParagraphExtension.js +8 -9
  116. package/dist/prosemirror/extensions/features/AutoBidiDetectionExtension.js +46 -11
  117. package/dist/prosemirror/extensions/features/BaseKeymapExtension.js +3 -2
  118. package/dist/prosemirror/extensions/features/BidiShortcutExtension.js +2 -3
  119. package/dist/prosemirror/extensions/features/ListExtension.js +22 -1
  120. package/dist/prosemirror/extensions/features/pasteCleanup.js +6 -0
  121. package/dist/prosemirror/extensions/features/pastedHtmlLists.js +2 -1
  122. package/dist/prosemirror/extensions/markRegistry.d.ts +3 -1
  123. package/dist/prosemirror/extensions/markRegistry.js +3 -0
  124. package/dist/prosemirror/extensions/marks/HyperlinkExtension.js +5 -0
  125. package/dist/prosemirror/extensions/marks/HyphenElementExtension.d.ts +6 -0
  126. package/dist/prosemirror/extensions/marks/HyphenElementExtension.js +54 -0
  127. package/dist/prosemirror/extensions/marks/TextColorExtension.js +1 -1
  128. package/dist/prosemirror/extensions/marks/TrackedChangeExtensions.js +8 -4
  129. package/dist/prosemirror/extensions/nodes/BookmarkBoundaryExtension.js +5 -1
  130. package/dist/prosemirror/extensions/nodes/CommentRangeBoundaryExtension.js +2 -1
  131. package/dist/prosemirror/extensions/nodes/CommentReferenceExtension.js +4 -3
  132. package/dist/prosemirror/extensions/nodes/MoveRangeBoundaryExtension.js +2 -1
  133. package/dist/prosemirror/extensions/nodes/NoteMarkerExtension.js +2 -1
  134. package/dist/prosemirror/extensions/nodes/RangeAnchorExtension.js +2 -1
  135. package/dist/prosemirror/extensions/nodes/RenderedPageBreakExtension.js +2 -1
  136. package/dist/prosemirror/extensions/nodes/TableExtension.js +87 -7
  137. package/dist/prosemirror/extensions/nodes/inlineAnchorDom.d.ts +11 -0
  138. package/dist/prosemirror/extensions/nodes/inlineAnchorDom.js +21 -0
  139. package/dist/prosemirror/fieldRepresentation.js +2 -1
  140. package/dist/prosemirror/hyphenElementAttrs.d.ts +10 -0
  141. package/dist/prosemirror/hyphenElementAttrs.js +32 -0
  142. package/dist/prosemirror/keptRangeBoundaries.d.ts +2 -0
  143. package/dist/prosemirror/keptRangeBoundaries.js +1 -1
  144. package/dist/prosemirror/listNumbering.js +3 -2
  145. package/dist/prosemirror/paragraphIndentation.js +2 -1
  146. package/dist/prosemirror/paragraphPropertyCarry.d.ts +1 -14
  147. package/dist/prosemirror/paragraphPropertyCarry.js +4 -28
  148. package/dist/prosemirror/plugins/suggestionMode.d.ts +0 -8
  149. package/dist/prosemirror/plugins/suggestionMode.js +194 -27
  150. package/dist/prosemirror/replacedAnnotations.d.ts +1 -0
  151. package/dist/prosemirror/replacedAnnotations.js +1 -0
  152. package/dist/prosemirror/rowGridOmissions.d.ts +11 -0
  153. package/dist/prosemirror/rowGridOmissions.js +21 -0
  154. package/dist/prosemirror/sectionCarrier.d.ts +8 -0
  155. package/dist/prosemirror/sectionCarrier.js +29 -1
  156. package/dist/prosemirror/styles/paragraphStyleCascade.d.ts +10 -0
  157. package/dist/prosemirror/styles/paragraphStyleCascade.js +12 -2
  158. package/dist/prosemirror/tableGridMutation.d.ts +19 -2
  159. package/dist/prosemirror/tableGridMutation.js +118 -15
  160. package/dist/prosemirror/tablePositionedBookmarks.d.ts +2 -0
  161. package/dist/prosemirror/tablePositionedBookmarks.js +80 -0
  162. package/dist/prosemirror/tableRunIn.d.ts +24 -9
  163. package/dist/prosemirror/tableRunIn.js +107 -21
  164. package/dist/prosemirror/textInput.js +3 -1
  165. package/dist/prosemirror/validation.js +7 -1
  166. package/dist/utils/createDocument.js +11 -8
  167. package/dist/utils/formatToStyle.js +2 -2
  168. package/dist/utils/units.d.ts +5 -0
  169. package/dist/utils/units.js +6 -1
  170. package/package.json +3 -3
@@ -13,6 +13,16 @@ export type ParagraphCascadeResolver = Pick<StyleEngine, "getStyle" | "getDocDef
13
13
  */
14
14
  type ParagraphDefaultFormattingResolver = Pick<StyleEngine, "getStyle" | "getDocDefaults" | "getDefaultParagraphStyle" | "getDefaultCharacterStyle" | "getRunStyleOwnProperties">;
15
15
  export declare function resolveRunFormattingWithoutDefaults(formatting: document_d_exports.TextFormatting | undefined, styleResolver: ParagraphDefaultFormattingResolver | null): document_d_exports.TextFormatting | undefined;
16
+ /**
17
+ * What a paragraph's mark lends its body runs: nothing when the paragraph has a
18
+ * style, and never the font or the mark-only decorations. One rule for a
19
+ * document read and for a paragraph whose properties a review restores.
20
+ */
21
+ export declare const inheritableParagraphMarkFormatting: ({ runProperties, styleId, styleResolver }: {
22
+ runProperties: document_d_exports.TextFormatting | undefined;
23
+ styleId: string | undefined;
24
+ styleResolver: Parameters<typeof resolveRunFormattingWithoutDefaults>[1];
25
+ }) => document_d_exports.TextFormatting | undefined;
16
26
  /** @internal Recompute a paragraph's inherited run defaults from authored package state. */
17
27
  export declare function resolveParagraphDefaultTextFormatting(styleId: string | undefined, formatting: document_d_exports.Paragraph["formatting"] | undefined, styleResolver: ParagraphDefaultFormattingResolver, options?: {
18
28
  includeParagraphMarkRunProperties?: boolean;
@@ -5,7 +5,7 @@ import { paragraphNumberingAttr } from "../numberingAttr.js";
5
5
  import { directionFromBidi } from "../paragraphDirection.js";
6
6
  import { styleResolvedParagraphFormatting } from "../paragraphFormattingProvenance.js";
7
7
  import { lineSpacingProvenanceFromSpacing } from "../paragraphSpacing.js";
8
- import { stripParagraphMarkOnlyFormatting } from "../runStyleFormatting.js";
8
+ import { stripParagraphMarkFormattingForBodyRuns, stripParagraphMarkOnlyFormatting } from "../runStyleFormatting.js";
9
9
  import { cascadeStyleTextFormatting } from "./styleToggleCascade.js";
10
10
  // src/prosemirror/styles/paragraphStyleCascade.ts
11
11
  /**
@@ -30,6 +30,16 @@ function resolveRunFormattingWithoutDefaults(formatting, styleResolver) {
30
30
  type: "direct"
31
31
  }]).formatting;
32
32
  }
33
+ /**
34
+ * What a paragraph's mark lends its body runs: nothing when the paragraph has a
35
+ * style, and never the font or the mark-only decorations. One rule for a
36
+ * document read and for a paragraph whose properties a review restores.
37
+ */
38
+ const inheritableParagraphMarkFormatting = ({ runProperties, styleId, styleResolver }) => {
39
+ if (styleId !== void 0) return void 0;
40
+ const formatting = resolveRunFormattingWithoutDefaults(runProperties, styleResolver);
41
+ return formatting ? stripParagraphMarkFormattingForBodyRuns(formatting) : void 0;
42
+ };
33
43
  /** @internal Recompute a paragraph's inherited run defaults from authored package state. */
34
44
  function resolveParagraphDefaultTextFormatting(styleId, formatting, styleResolver, options = {}) {
35
45
  const style = styleId ? styleResolver.getStyle(styleId) ?? styleResolver.getDefaultParagraphStyle() : styleResolver.getDefaultParagraphStyle();
@@ -155,4 +165,4 @@ function tableCellParagraphOverlay(styleResolver, tableStyleId, regions) {
155
165
  }
156
166
  return overlay;
157
167
  }
158
- export { extractTableParagraphOverlay, paragraphStyleCascadeAttrs, resolveParagraphDefaultTextFormatting, resolveRunFormattingWithoutDefaults, tableCellParagraphOverlay };
168
+ export { extractTableParagraphOverlay, inheritableParagraphMarkFormatting, paragraphStyleCascadeAttrs, resolveParagraphDefaultTextFormatting, resolveRunFormattingWithoutDefaults, tableCellParagraphOverlay };
@@ -18,6 +18,20 @@ type RemoveTableRowOptions = {
18
18
  * and the table is left one row shorter than that merge.
19
19
  */
20
20
  export declare const removeTableRow: (tr: Transaction, { map, table, tableStart }: RemoveTableRowOptions, row: number) => void;
21
+ /** A placeholder for an absent grid position is not a cell a row can keep. */
22
+ export declare const rowHoldsNoCells: (row: Node, besides?: Node) => boolean;
23
+ /**
24
+ * The placeholder a new column's place in a row falls to, if any. Nothing can
25
+ * stand after what a row omits at its end or before what it omits at its start:
26
+ * a cell there would move on save, so the omission grows instead.
27
+ */
28
+ export declare const omittedSlotTakingColumn: (map: TableMap, table: Node, row: number, column: number) => number | null;
29
+ /**
30
+ * Size what rows omit to the width their cells now reach. A column whose cells
31
+ * went takes the same column out of a row that omits it; removing a tracked
32
+ * column's last cell does not otherwise reach such a row.
33
+ */
34
+ export declare const reconcileOmittedGridSlots: (tr: Transaction, tablePosition: number, previousTable: Node, removedColumn: number) => void;
21
35
  /** Whether a batch of structural deletions may have emptied rows. */
22
36
  export type RowsEmptiedInBatch = {
23
37
  pending: boolean;
@@ -46,8 +60,11 @@ type RemoveRowsWithoutCellsInRangeOptions = {
46
60
  };
47
61
  /** Close marked rows before their owning cell is captured into a continuation payload. */
48
62
  export declare const removeRowsWithoutCellsInRange: ({ tr, from, to }: RemoveRowsWithoutCellsInRangeOptions) => void;
49
- /** Close all cell-less rows after an immediate structural edit. */
50
- export declare const removeRowsWithoutCells: (tr: Transaction, tablePosition: number) => void;
63
+ /**
64
+ * Close the rows an immediate structural edit left without cells. A row written
65
+ * with none is no row this edit emptied, and it stays.
66
+ */
67
+ export declare const removeRowsWithoutCells: (tr: Transaction, tablePosition: number, previousTable: Node) => void;
51
68
  type ReconcileTableGridAfterColumnRemovalOptions = {
52
69
  tr: Transaction;
53
70
  tablePosition: number;
@@ -44,6 +44,86 @@ const removeTableRow = (tr, { map, table, tableStart }, row) => {
44
44
  column += colspan;
45
45
  }
46
46
  };
47
+ /** A placeholder for an absent grid position is not a cell a row can keep. */
48
+ const rowHoldsNoCells = (row, besides) => {
49
+ let holdsCell = false;
50
+ row.forEach((cell) => {
51
+ holdsCell ||= cell !== besides && cell.attrs["_omittedGridSlot"] == null;
52
+ });
53
+ return !holdsCell;
54
+ };
55
+ const omittedSlotOf = (cell) => cell?.attrs["_omittedGridSlot"];
56
+ /**
57
+ * The placeholder a new column's place in a row falls to, if any. Nothing can
58
+ * stand after what a row omits at its end or before what it omits at its start:
59
+ * a cell there would move on save, so the omission grows instead.
60
+ */
61
+ const omittedSlotTakingColumn = (map, table, row, column) => {
62
+ const left = column > 0 ? map.map[row * map.width + column - 1] : void 0;
63
+ if (left !== void 0 && omittedSlotOf(table.nodeAt(left)) === "after") return left;
64
+ const right = column < map.width ? map.map[row * map.width + column] : void 0;
65
+ return right !== void 0 && omittedSlotOf(table.nodeAt(right)) === "before" ? right : null;
66
+ };
67
+ /**
68
+ * Size what rows omit to the width their cells now reach. A column whose cells
69
+ * went takes the same column out of a row that omits it; removing a tracked
70
+ * column's last cell does not otherwise reach such a row.
71
+ */
72
+ const reconcileOmittedGridSlots = (tr, tablePosition, previousTable, removedColumn) => {
73
+ const table = tr.doc.nodeAt(tablePosition);
74
+ if (!table || table.type.spec["tableRole"] !== "table") return;
75
+ const reached = Array.from({ length: table.childCount }, () => 0);
76
+ let omits = false;
77
+ table.forEach((row, _offset, rowIndex) => {
78
+ row.forEach((cell) => {
79
+ if (omittedSlotOf(cell)) {
80
+ omits = true;
81
+ return;
82
+ }
83
+ const colspan = Number(cell.attrs["colspan"]) || 1;
84
+ const rowspan = Number(cell.attrs["rowspan"]) || 1;
85
+ for (let at = rowIndex; at < rowIndex + rowspan; at++) if (at < reached.length) reached[at] = (reached[at] ?? 0) + colspan;
86
+ });
87
+ });
88
+ if (!omits) return;
89
+ const width = Math.max(...reached);
90
+ const previousMap = TableMap.get(previousTable);
91
+ const rowPositions = [];
92
+ table.forEach((_row, offset) => rowPositions.push(tablePosition + 1 + offset));
93
+ for (let rowIndex = table.childCount - 1; rowIndex >= 0; rowIndex--) {
94
+ const row = table.child(rowIndex);
95
+ let excess = -(width - (reached[rowIndex] ?? 0));
96
+ row.forEach((cell) => {
97
+ if (omittedSlotOf(cell)) excess += Number(cell.attrs["colspan"]) || 1;
98
+ });
99
+ if (excess <= 0) continue;
100
+ const atPlace = previousMap.map[rowIndex * previousMap.width + removedColumn];
101
+ const placeKind = atPlace === void 0 ? void 0 : omittedSlotOf(previousTable.nodeAt(atPlace));
102
+ const slots = [];
103
+ row.forEach((cell, offset) => {
104
+ if (omittedSlotOf(cell)) slots.push({
105
+ node: cell,
106
+ position: (rowPositions[rowIndex] ?? 0) + 1 + offset
107
+ });
108
+ });
109
+ const order = slots.toSorted((left, right) => Number(omittedSlotOf(right.node) === placeKind) - Number(omittedSlotOf(left.node) === placeKind) || right.position - left.position);
110
+ const changes = /* @__PURE__ */ new Map();
111
+ for (const { node, position } of order) {
112
+ if (excess <= 0) break;
113
+ const colspan = Number(node.attrs["colspan"]) || 1;
114
+ const taken = Math.min(colspan, excess);
115
+ changes.set(position, colspan - taken);
116
+ excess -= taken;
117
+ }
118
+ for (const { node, position } of slots.toReversed()) {
119
+ const next = changes.get(position);
120
+ if (next === void 0) continue;
121
+ if (next === 0) tr.delete(position, position + node.nodeSize);
122
+ else tr.setNodeAttribute(position, "colspan", next);
123
+ }
124
+ }
125
+ removeRowsWithoutCells(tr, tablePosition, previousTable);
126
+ };
47
127
  const ROW_CLEANUP_PENDING = "pending";
48
128
  /** A transient row attribute follows node moves; conversion never serializes it. */
49
129
  const markRowEmptiedInBatch = ({ tr, rowPosition, emptied }) => {
@@ -57,7 +137,7 @@ const markRowsEmptiedInBatch = ({ tr, tablePosition, previousTable, emptied }) =
57
137
  const table = tr.doc.nodeAt(tablePosition);
58
138
  if (!table || table.type.spec["tableRole"] !== "table") return;
59
139
  table.forEach((row, offset, index) => {
60
- if (row.childCount === 0 && previousTable.child(index).childCount > 0) markRowEmptiedInBatch({
140
+ if (rowHoldsNoCells(row) && !rowHoldsNoCells(previousTable.child(index))) markRowEmptiedInBatch({
61
141
  tr,
62
142
  rowPosition: tablePosition + 1 + offset,
63
143
  emptied
@@ -70,7 +150,7 @@ const removeEmptyRows = ({ tr, tablePosition, shouldRemove }) => {
70
150
  if (!table || table.type.spec["tableRole"] !== "table" || table.childCount < 2) return;
71
151
  let emptyRow = -1;
72
152
  table.forEach((row, _offset, index) => {
73
- if (emptyRow === -1 && row.childCount === 0 && shouldRemove(row)) emptyRow = index;
153
+ if (emptyRow === -1 && rowHoldsNoCells(row) && shouldRemove(row)) emptyRow = index;
74
154
  });
75
155
  if (emptyRow === -1) return;
76
156
  removeTableRow(tr, {
@@ -110,13 +190,27 @@ const removeRowsWithoutCellsInRange = ({ tr, from, to }) => {
110
190
  });
111
191
  for (const position of tables.toReversed()) removeBatchRows(tr, position);
112
192
  };
113
- /** Close all cell-less rows after an immediate structural edit. */
114
- const removeRowsWithoutCells = (tr, tablePosition) => {
115
- removeEmptyRows({
116
- tr,
117
- tablePosition,
118
- shouldRemove: () => true
193
+ /**
194
+ * Close the rows an immediate structural edit left without cells. A row written
195
+ * with none is no row this edit emptied, and it stays.
196
+ */
197
+ const removeRowsWithoutCells = (tr, tablePosition, previousTable) => {
198
+ const table = tr.doc.nodeAt(tablePosition);
199
+ if (!table || table.type.spec["tableRole"] !== "table") return;
200
+ const emptied = [];
201
+ table.forEach((row, _offset, index) => {
202
+ const before = previousTable.maybeChild(index);
203
+ if (rowHoldsNoCells(row) && before && !rowHoldsNoCells(before)) emptied.push(index);
119
204
  });
205
+ for (const rowIndex of emptied.toReversed()) {
206
+ const current = tr.doc.nodeAt(tablePosition);
207
+ if (!current || current.childCount < 2) return;
208
+ removeTableRow(tr, {
209
+ map: TableMap.get(current),
210
+ table: current,
211
+ tableStart: tablePosition + 1
212
+ }, rowIndex);
213
+ }
120
214
  };
121
215
  /**
122
216
  * Keep the editable table grid aligned with a physical column removal.
@@ -134,7 +228,7 @@ const reconcileTableGridAfterColumnRemoval = ({ tr, tablePosition, previousTable
134
228
  if (columnCount >= previousColumnCount) return;
135
229
  const removedColumnCount = previousColumnCount - columnCount;
136
230
  const previousWidths = expectTableAttrs(previousTable).columnWidths;
137
- const columnWidths = previousWidths?.length === previousColumnCount ? previousWidths.toSpliced(removedColumn, removedColumnCount) : void 0;
231
+ const columnWidths = previousWidths !== void 0 && previousWidths.length >= previousColumnCount ? previousWidths.toSpliced(removedColumn, removedColumnCount) : void 0;
138
232
  setTableGrid({
139
233
  tr,
140
234
  tablePosition,
@@ -159,7 +253,7 @@ const reconcileTableGridAfterColumnInsertion = ({ tr, tablePosition, previousTab
159
253
  const insertedColumnCount = columnCount - previousColumnCount;
160
254
  const previousWidths = expectTableAttrs(previousTable).columnWidths;
161
255
  const neighbourWidth = insertedColumnWidth(previousTable, insertedColumn);
162
- const columnWidths = previousWidths?.length === previousColumnCount && neighbourWidth !== void 0 ? previousWidths.toSpliced(insertedColumn, 0, ...Array.from({ length: insertedColumnCount }, () => neighbourWidth)) : void 0;
256
+ const columnWidths = previousWidths !== void 0 && previousWidths.length >= previousColumnCount && neighbourWidth !== void 0 ? previousWidths.toSpliced(insertedColumn, 0, ...Array.from({ length: insertedColumnCount }, () => neighbourWidth)) : void 0;
163
257
  setTableGrid({
164
258
  tr,
165
259
  tablePosition,
@@ -172,7 +266,7 @@ const reconcileTableGridAfterColumnInsertion = ({ tr, tablePosition, previousTab
172
266
  const insertedColumnWidth = (table, insertedColumn) => {
173
267
  const columnCount = TableMap.get(table).width;
174
268
  const widths = expectTableAttrs(table).columnWidths;
175
- if (widths?.length !== columnCount) return;
269
+ if (widths === void 0 || widths.length < columnCount) return;
176
270
  return widths[Math.max(0, Math.min(insertedColumn, columnCount) - 1)] ?? widths[0];
177
271
  };
178
272
  /**
@@ -196,7 +290,7 @@ const setTableGrid = ({ tr, tablePosition, table, columnWidths, columnCount }) =
196
290
  const originalFormatting = formatting ? { ...formatting } : void 0;
197
291
  if (originalFormatting) delete originalFormatting.gridSourceXml;
198
292
  tr.setNodeMarkup(tablePosition, void 0, mergeTableAttrs(table, {
199
- columnWidths: columnWidths?.length === columnCount ? columnWidths : void 0,
293
+ columnWidths: columnWidths !== void 0 && columnWidths.length >= columnCount ? columnWidths : void 0,
200
294
  _originalFormatting: originalFormatting
201
295
  }));
202
296
  };
@@ -216,6 +310,12 @@ const insertTableColumn = ({ tr, tablePosition, column, templateColumn, createCe
216
310
  for (let row = 0; row < map.height; row++) {
217
311
  const index = row * map.width + column;
218
312
  const position = map.map[index];
313
+ const omitted = omittedSlotTakingColumn(map, table, row, column);
314
+ if (omitted !== null) {
315
+ const slot = table.nodeAt(omitted);
316
+ tr.setNodeAttribute(tr.mapping.slice(mapFrom).map(tableStart + omitted), "colspan", (Number(slot?.attrs["colspan"]) || 1) + 1);
317
+ continue;
318
+ }
219
319
  const straddling = column > 0 && column < map.width && position !== void 0 && map.map[index - 1] === position ? table.nodeAt(position) : null;
220
320
  if (straddling && position !== void 0) {
221
321
  const offset = column - map.colCount(position);
@@ -231,7 +331,8 @@ const insertTableColumn = ({ tr, tablePosition, column, templateColumn, createCe
231
331
  continue;
232
332
  }
233
333
  const templatePosition = map.map[row * map.width + templateColumn];
234
- const template = templatePosition === void 0 ? null : table.nodeAt(templatePosition);
334
+ const templateCell = templatePosition === void 0 ? null : table.nodeAt(templatePosition);
335
+ const template = omittedSlotOf(templateCell) ? null : templateCell;
235
336
  tr.insert(tr.mapping.slice(mapFrom).map(tableStart + map.positionAt(row, column, table)), createCell(template));
236
337
  }
237
338
  reconcileTableGridAfterColumnInsertion({
@@ -247,6 +348,8 @@ const insertTableColumn = ({ tr, tablePosition, column, templateColumn, createCe
247
348
  * and a row left without a cell of its own goes too.
248
349
  */
249
350
  const removeTableColumns = (tr, tablePosition, left, right) => {
351
+ const previousTable = tr.doc.nodeAt(tablePosition);
352
+ if (!previousTable) return;
250
353
  for (let column = right - 1; column >= left; column--) {
251
354
  const table = tr.doc.nodeAt(tablePosition);
252
355
  if (!table || table.type.spec["tableRole"] !== "table") return;
@@ -277,6 +380,6 @@ const removeTableColumns = (tr, tablePosition, left, right) => {
277
380
  removedColumn: column
278
381
  });
279
382
  }
280
- removeRowsWithoutCells(tr, tablePosition);
383
+ removeRowsWithoutCells(tr, tablePosition, previousTable);
281
384
  };
282
- export { insertTableColumn, markRowEmptiedInBatch, markRowsEmptiedInBatch, reconcileTableGridAfterColumnInsertion, reconcileTableGridAfterColumnRemoval, removeRowsWithoutCells, removeRowsWithoutCellsAfterBatch, removeRowsWithoutCellsInRange, removeTableColumns, removeTableRow };
385
+ export { insertTableColumn, markRowEmptiedInBatch, markRowsEmptiedInBatch, omittedSlotTakingColumn, reconcileOmittedGridSlots, reconcileTableGridAfterColumnInsertion, reconcileTableGridAfterColumnRemoval, removeRowsWithoutCells, removeRowsWithoutCellsAfterBatch, removeRowsWithoutCellsInRange, removeTableColumns, removeTableRow, rowHoldsNoCells };
@@ -0,0 +1,2 @@
1
+ import { Plugin } from "prosemirror-state";
2
+ export declare const tablePositionedBookmarksPlugin: () => Plugin;
@@ -0,0 +1,80 @@
1
+ import { Mapping } from "prosemirror-transform";
2
+ import { Plugin, PluginKey } from "prosemirror-state";
3
+ // src/prosemirror/tablePositionedBookmarks.ts
4
+ const positionedBookmarksOf = (node) => {
5
+ const role = node.type.spec["tableRole"];
6
+ if (role !== "table" && role !== "row") return null;
7
+ const bookmarks = node.attrs["_bookmarks"];
8
+ return Array.isArray(bookmarks) && bookmarks.length > 0 ? bookmarks : null;
9
+ };
10
+ /** Where a boundary between the source's children falls among the new ones. */
11
+ const childIndexAt = (node, nodePosition, at) => {
12
+ let index = 0;
13
+ let end = nodePosition + 1;
14
+ while (index < node.childCount) {
15
+ end += node.child(index).nodeSize;
16
+ if (end > at) break;
17
+ index += 1;
18
+ }
19
+ return index;
20
+ };
21
+ const followingIndex = ({ source, sourcePosition, node, position, index, mapping }) => {
22
+ if (!source || source.type !== node.type || index > source.childCount) return Math.min(index, node.childCount);
23
+ if (index === source.childCount) return node.childCount;
24
+ let boundary = sourcePosition + 1;
25
+ for (let child = 0; child < index; child += 1) boundary += source.child(child).nodeSize;
26
+ return childIndexAt(node, position, mapping.map(boundary, -1));
27
+ };
28
+ const repairChanged = ({ before, after, offset, mapping, back, sourceDoc, tr }) => {
29
+ after.forEach((child, childOffset, index) => {
30
+ if (child === before.maybeChild(index) || child.isTextblock) return;
31
+ const position = offset + childOffset;
32
+ const bookmarks = positionedBookmarksOf(child);
33
+ if (bookmarks) {
34
+ const sourcePosition = back.map(position, 1);
35
+ const source = sourceDoc.nodeAt(sourcePosition);
36
+ const repaired = bookmarks.map((bookmark) => ({
37
+ ...bookmark,
38
+ index: followingIndex({
39
+ source,
40
+ sourcePosition,
41
+ node: child,
42
+ position,
43
+ index: bookmark.index,
44
+ mapping
45
+ })
46
+ }));
47
+ if (repaired.some(({ index: at }, i) => at !== bookmarks[i]?.index)) tr.setNodeAttribute(position, "_bookmarks", repaired);
48
+ }
49
+ repairChanged({
50
+ before: before.maybeChild(index) ?? child.type.create(),
51
+ after: child,
52
+ offset: position + 1,
53
+ mapping,
54
+ back,
55
+ sourceDoc,
56
+ tr
57
+ });
58
+ });
59
+ };
60
+ const tablePositionedBookmarksPlugin = () => new Plugin({
61
+ key: new PluginKey("tablePositionedBookmarks"),
62
+ appendTransaction(transactions, oldState, newState) {
63
+ if (!transactions.some(({ docChanged }) => docChanged)) return null;
64
+ const mapping = new Mapping();
65
+ for (const { mapping: each } of transactions) mapping.appendMapping(each);
66
+ const tr = newState.tr;
67
+ repairChanged({
68
+ before: oldState.doc,
69
+ after: newState.doc,
70
+ offset: 0,
71
+ mapping,
72
+ back: mapping.invert(),
73
+ sourceDoc: oldState.doc,
74
+ tr
75
+ });
76
+ if (!tr.docChanged) return null;
77
+ return tr.setMeta("addToHistory", false);
78
+ }
79
+ });
80
+ export { tablePositionedBookmarksPlugin };
@@ -1,20 +1,26 @@
1
1
  import { RunStyleResolver } from "./runStyleFormatting.js";
2
2
  import { ParagraphPropertySourceTransfer } from "../docx/paragraphPropertySource.js";
3
- import { MarkType, Node } from "prosemirror-model";
3
+ import { Node } from "prosemirror-model";
4
4
  import { StepMap, Transform } from "prosemirror-transform";
5
+ type ResolutionMode = "accept" | "reject";
5
6
  /**
6
7
  * Whether the cell a paragraph's words would run into is itself pending: its
7
8
  * row or the cell (through nested tables' first cells) is inserted, deleted
8
- * or merged, so resolving may not keep it. Pending rows or cells elsewhere in
9
- * the table leave that cell where it is.
9
+ * or merged, so resolving may not keep it. A deletion is not pending for a
10
+ * rejection of every change. Pending rows or cells elsewhere in the table leave
11
+ * that cell where it is.
10
12
  */
11
- export declare const runInCellPending: (table: Node) => boolean;
13
+ export declare const runInCellPending: (table: Node, everyChange?: ResolutionMode) => boolean;
12
14
  type RunParagraphIntoTableOptions = {
13
15
  tr: Transform;
14
16
  paragraphPos: number;
15
17
  styleResolver: RunStyleResolver | null;
16
- /** Content a resolution in progress removes: it does not count as words left. */
17
- removedMark?: MarkType | undefined;
18
+ /**
19
+ * Set when every change of the story resolves this way, not only some: what
20
+ * it removes does not count as words left, and a rejection takes a deleted
21
+ * row as staying.
22
+ */
23
+ everyChange?: ResolutionMode | undefined;
18
24
  };
19
25
  /**
20
26
  * Run the paragraph at `paragraphPos` on into the table right after it.
@@ -22,7 +28,7 @@ type RunParagraphIntoTableOptions = {
22
28
  * paragraph-property source it hands over, or null when it did not run in and
23
29
  * the caller keeps its own handling.
24
30
  */
25
- export declare const runParagraphIntoTable: ({ tr, paragraphPos, styleResolver, removedMark }: RunParagraphIntoTableOptions) => {
31
+ export declare const runParagraphIntoTable: ({ tr, paragraphPos, styleResolver, everyChange }: RunParagraphIntoTableOptions) => {
26
32
  position: number;
27
33
  map: StepMap;
28
34
  transfer: ParagraphPropertySourceTransfer;
@@ -34,8 +40,17 @@ export declare const runParagraphIntoTable: ({ tr, paragraphPos, styleResolver,
34
40
  type RunsIntoFollowingTableOptions = {
35
41
  parent: Node;
36
42
  index: number;
37
- mode: "accept" | "reject";
43
+ mode: ResolutionMode;
38
44
  };
45
+ /**
46
+ * Whether what stands right after a paragraph whose mark goes is itself removed
47
+ * by this resolution, so the paragraph runs on into what stands after that, as
48
+ * it would had the removed block never been there: a table it removes, or, when
49
+ * rejecting, an inserted paragraph it empties with a table after it. (Accepted,
50
+ * a deleted paragraph did stand there, and the join ended at it. Paragraphs join
51
+ * among themselves without help.)
52
+ */
53
+ export declare const paragraphBeforeRemovedBlock: ({ parent, index, mode }: RunsIntoFollowingTableOptions) => boolean;
39
54
  export declare const runsIntoFollowingTable: ({ parent, index, mode }: RunsIntoFollowingTableOptions) => boolean;
40
55
  /**
41
56
  * Before every change in a story is resolved: run each paragraph whose mark
@@ -43,7 +58,7 @@ export declare const runsIntoFollowingTable: ({ parent, index, mode }: RunsIntoF
43
58
  * paragraph that took words (its position after the step count given) and
44
59
  * the paragraph-property sources handed over.
45
60
  */
46
- export declare const runParagraphsIntoTables: (tr: Transform, mode: "accept" | "reject", styleResolver: RunStyleResolver | null) => {
61
+ export declare const runParagraphsIntoTables: (tr: Transform, mode: ResolutionMode, styleResolver: RunStyleResolver | null) => {
47
62
  targets: {
48
63
  position: number;
49
64
  step: number;