@viewkitjs/views 0.2.0 → 0.3.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 (292) hide show
  1. package/CHANGELOG.md +571 -0
  2. package/README.md +5 -3
  3. package/dist/atoms/LoadMore.js +11 -1
  4. package/dist/atoms/RowMenu.js +5 -2
  5. package/dist/cells/cell-format.d.ts +3 -3
  6. package/dist/cells/cell-title.d.ts +1 -2
  7. package/dist/cells/cell-title.js +2 -2
  8. package/dist/cells/cell-values.js +6 -3
  9. package/dist/contract.d.ts +50 -9
  10. package/dist/contract.js +33 -5
  11. package/dist/display/converted.d.ts +19 -0
  12. package/dist/display/converted.js +12 -0
  13. package/dist/display/index.d.ts +1 -0
  14. package/dist/display/index.js +1 -0
  15. package/dist/display/link-click.d.ts +11 -0
  16. package/dist/display/link-click.js +3 -0
  17. package/dist/display/link.js +7 -3
  18. package/dist/display/multi-value.d.ts +1 -1
  19. package/dist/display/multi-value.js +1 -1
  20. package/dist/display/options.d.ts +7 -1
  21. package/dist/display/phone.js +3 -1
  22. package/dist/editors/ChipsEditor.d.ts +9 -4
  23. package/dist/editors/ChipsEditor.js +6 -2
  24. package/dist/editors/DateEditor.d.ts +21 -6
  25. package/dist/editors/DateEditor.js +118 -30
  26. package/dist/editors/EditorPanel.d.ts +61 -0
  27. package/dist/editors/EditorPanel.js +54 -0
  28. package/dist/editors/LocationEditor.d.ts +3 -0
  29. package/dist/editors/LocationEditor.js +14 -6
  30. package/dist/editors/NameEditor.d.ts +3 -0
  31. package/dist/editors/NameEditor.js +11 -7
  32. package/dist/editors/NumberEditor.d.ts +3 -0
  33. package/dist/editors/NumberEditor.js +6 -6
  34. package/dist/editors/RangeEditor.d.ts +16 -1
  35. package/dist/editors/RangeEditor.js +21 -5
  36. package/dist/editors/RelationEditor.d.ts +13 -28
  37. package/dist/editors/RelationEditor.js +17 -40
  38. package/dist/editors/RelationSetEditor.d.ts +53 -0
  39. package/dist/editors/RelationSetEditor.js +112 -0
  40. package/dist/editors/SelectEditor.d.ts +21 -3
  41. package/dist/editors/SelectEditor.js +55 -9
  42. package/dist/editors/TextEditor.d.ts +51 -0
  43. package/dist/editors/TextEditor.js +81 -0
  44. package/dist/editors/ValueListEditor.d.ts +3 -0
  45. package/dist/editors/ValueListEditor.js +4 -2
  46. package/dist/editors/edit-cores.d.ts +12 -9
  47. package/dist/editors/edit-cores.js +7 -6
  48. package/dist/editors/edit-session.d.ts +21 -11
  49. package/dist/editors/edit-session.js +19 -5
  50. package/dist/editors/keep-inside.d.ts +12 -0
  51. package/dist/editors/keep-inside.js +20 -0
  52. package/dist/editors/open-value.d.ts +21 -0
  53. package/dist/editors/open-value.js +36 -0
  54. package/dist/editors/open-values.d.ts +4 -0
  55. package/dist/editors/open-values.js +7 -0
  56. package/dist/editors/relation-kinds.d.ts +7 -0
  57. package/dist/editors/relation-kinds.js +21 -0
  58. package/dist/editors/relation-panel.d.ts +69 -0
  59. package/dist/editors/relation-panel.js +40 -0
  60. package/dist/field-row/FieldNoteLine.d.ts +14 -0
  61. package/dist/field-row/FieldNoteLine.js +14 -0
  62. package/dist/field-row/FieldRow.d.ts +73 -0
  63. package/dist/field-row/FieldRow.js +157 -0
  64. package/dist/field-row/FieldRowLane.d.ts +19 -0
  65. package/dist/field-row/FieldRowLane.js +11 -0
  66. package/dist/field-row/editors/RowChipsEditor.d.ts +11 -0
  67. package/dist/field-row/editors/RowChipsEditor.js +25 -0
  68. package/dist/field-row/editors/RowDateEditor.d.ts +16 -0
  69. package/dist/field-row/editors/RowDateEditor.js +18 -0
  70. package/dist/field-row/editors/RowEditor.d.ts +39 -0
  71. package/dist/field-row/editors/RowEditor.js +64 -0
  72. package/dist/field-row/editors/RowNameEditor.d.ts +4 -0
  73. package/dist/field-row/editors/RowNameEditor.js +15 -0
  74. package/dist/field-row/editors/RowNumberEditor.d.ts +12 -0
  75. package/dist/field-row/editors/RowNumberEditor.js +18 -0
  76. package/dist/field-row/editors/RowPlaceEditor.d.ts +8 -0
  77. package/dist/field-row/editors/RowPlaceEditor.js +18 -0
  78. package/dist/field-row/editors/RowRangeEditor.d.ts +4 -0
  79. package/dist/field-row/editors/RowRangeEditor.js +15 -0
  80. package/dist/field-row/editors/RowRelationEditor.d.ts +20 -0
  81. package/dist/field-row/editors/RowRelationEditor.js +77 -0
  82. package/dist/field-row/editors/RowSelectEditor.d.ts +13 -0
  83. package/dist/field-row/editors/RowSelectEditor.js +23 -0
  84. package/dist/field-row/editors/RowTextEditor.d.ts +15 -0
  85. package/dist/field-row/editors/RowTextEditor.js +16 -0
  86. package/dist/field-row/editors/RowValueListEditor.d.ts +4 -0
  87. package/dist/field-row/editors/RowValueListEditor.js +21 -0
  88. package/dist/field-row/editors/host.d.ts +59 -0
  89. package/dist/field-row/editors/host.js +1 -0
  90. package/dist/field-row/editors/row-session.d.ts +49 -0
  91. package/dist/field-row/editors/row-session.js +49 -0
  92. package/dist/field-row/index.d.ts +5 -0
  93. package/dist/field-row/index.js +5 -0
  94. package/dist/field-row/row-target.d.ts +20 -0
  95. package/dist/field-row/row-target.js +3 -0
  96. package/dist/field-row/useFieldWrite.d.ts +45 -0
  97. package/dist/field-row/useFieldWrite.js +190 -0
  98. package/dist/field-row/useRowSettlement.d.ts +33 -0
  99. package/dist/field-row/useRowSettlement.js +23 -0
  100. package/dist/fields/binding.d.ts +6 -1
  101. package/dist/fields/binding.js +13 -6
  102. package/dist/fields/edit-core-types.d.ts +9 -9
  103. package/dist/fields/edit-core-types.js +6 -6
  104. package/dist/fields/money.d.ts +5 -0
  105. package/dist/fields/money.js +10 -0
  106. package/dist/fields/number-edit.d.ts +6 -0
  107. package/dist/fields/number-edit.js +4 -0
  108. package/dist/fields/prepare-write.js +6 -1
  109. package/dist/fields/relation-source-types.d.ts +12 -0
  110. package/dist/fields/write-target.d.ts +50 -0
  111. package/dist/fields/write-target.js +10 -0
  112. package/dist/grid/chrome/GridAddColumn.js +1 -1
  113. package/dist/grid/chrome/GridAggregateMenu.d.ts +1 -1
  114. package/dist/grid/chrome/GridAggregateMenu.js +8 -6
  115. package/dist/grid/chrome/GridCellEditors.d.ts +7 -0
  116. package/dist/grid/chrome/GridCellEditors.js +87 -16
  117. package/dist/grid/chrome/GridCellOutline.d.ts +22 -43
  118. package/dist/grid/chrome/GridCellOutline.js +2 -7
  119. package/dist/grid/chrome/GridChipsEditor.d.ts +16 -6
  120. package/dist/grid/chrome/GridChipsEditor.js +21 -26
  121. package/dist/grid/chrome/GridColumnMenu.d.ts +1 -1
  122. package/dist/grid/chrome/GridColumnMenu.js +7 -3
  123. package/dist/grid/chrome/GridDateEditor.d.ts +23 -11
  124. package/dist/grid/chrome/GridDateEditor.js +13 -25
  125. package/dist/grid/chrome/GridFooter.d.ts +12 -2
  126. package/dist/grid/chrome/GridFooter.js +10 -6
  127. package/dist/grid/chrome/GridGroupMenu.js +20 -13
  128. package/dist/grid/chrome/GridHeader.d.ts +9 -4
  129. package/dist/grid/chrome/GridHeader.js +15 -10
  130. package/dist/grid/chrome/GridLongTextEditor.d.ts +28 -9
  131. package/dist/grid/chrome/GridLongTextEditor.js +16 -74
  132. package/dist/grid/chrome/GridNameEditor.d.ts +11 -6
  133. package/dist/grid/chrome/GridNameEditor.js +12 -27
  134. package/dist/grid/chrome/GridNumberEditor.d.ts +20 -6
  135. package/dist/grid/chrome/GridNumberEditor.js +46 -20
  136. package/dist/grid/chrome/GridPlaceEditor.d.ts +26 -0
  137. package/dist/grid/chrome/GridPlaceEditor.js +22 -0
  138. package/dist/grid/chrome/GridRangeEditor.d.ts +15 -5
  139. package/dist/grid/chrome/GridRangeEditor.js +16 -20
  140. package/dist/grid/chrome/GridRelationEditor.d.ts +38 -14
  141. package/dist/grid/chrome/GridRelationEditor.js +86 -24
  142. package/dist/grid/chrome/GridRow.d.ts +7 -1
  143. package/dist/grid/chrome/GridRow.js +57 -14
  144. package/dist/grid/chrome/GridRowActions.js +1 -1
  145. package/dist/grid/chrome/GridRowCells.js +18 -23
  146. package/dist/grid/chrome/GridSelectEditor.d.ts +19 -4
  147. package/dist/grid/chrome/GridSelectEditor.js +21 -27
  148. package/dist/grid/chrome/GridStructure.d.ts +9 -10
  149. package/dist/grid/chrome/GridStructure.js +10 -14
  150. package/dist/grid/chrome/GridTable.js +97 -30
  151. package/dist/grid/chrome/GridTableSurface.d.ts +39 -2
  152. package/dist/grid/chrome/GridTableSurface.js +12 -3
  153. package/dist/grid/chrome/GridTextEditor.d.ts +35 -1
  154. package/dist/grid/chrome/GridTextEditor.js +35 -37
  155. package/dist/grid/chrome/GridValueListEditor.d.ts +15 -3
  156. package/dist/grid/chrome/GridValueListEditor.js +10 -27
  157. package/dist/grid/chrome/cell-cut-off.d.ts +11 -0
  158. package/dist/grid/chrome/cell-cut-off.js +20 -0
  159. package/dist/grid/chrome/cells.js +1 -2
  160. package/dist/grid/chrome/checks.d.ts +2 -5
  161. package/dist/grid/chrome/checks.js +15 -5
  162. package/dist/grid/chrome/editors.d.ts +1 -1
  163. package/dist/grid/chrome/editors.js +1 -1
  164. package/dist/grid/chrome/grid-cell-classes.d.ts +2 -8
  165. package/dist/grid/chrome/grid-cell-classes.js +10 -8
  166. package/dist/grid/chrome/grid-cell-link.d.ts +13 -0
  167. package/dist/grid/chrome/grid-cell-link.js +9 -0
  168. package/dist/grid/chrome/grid-edit-session.d.ts +63 -0
  169. package/dist/grid/chrome/grid-edit-session.js +118 -0
  170. package/dist/grid/chrome/grid-hover.d.ts +60 -0
  171. package/dist/grid/chrome/grid-hover.js +81 -0
  172. package/dist/grid/chrome/grid-menu-focus.d.ts +43 -0
  173. package/dist/grid/chrome/grid-menu-focus.js +93 -0
  174. package/dist/grid/chrome/grid-row-menu-key.d.ts +15 -0
  175. package/dist/grid/chrome/grid-row-menu-key.js +36 -0
  176. package/dist/grid/chrome/grid-row-props.d.ts +16 -4
  177. package/dist/grid/chrome/grid-row-window.d.ts +61 -0
  178. package/dist/grid/chrome/grid-row-window.js +212 -0
  179. package/dist/grid/chrome/grid-scroll-owner.d.ts +38 -0
  180. package/dist/grid/chrome/grid-scroll-owner.js +75 -0
  181. package/dist/grid/chrome/grid-styles.d.ts +4 -1
  182. package/dist/grid/chrome/grid-styles.js +1 -0
  183. package/dist/grid/chrome/grid-table-props.d.ts +2 -3
  184. package/dist/grid/chrome/useGridFocus.d.ts +45 -0
  185. package/dist/grid/chrome/useGridFocus.js +122 -0
  186. package/dist/grid/chrome/useGridKeyboard.d.ts +21 -4
  187. package/dist/grid/chrome/useGridKeyboard.js +214 -38
  188. package/dist/grid/chrome/useGridRangeActions.d.ts +3 -1
  189. package/dist/grid/chrome/useGridRangeActions.js +17 -10
  190. package/dist/grid/chrome/useGridRangeGestures.js +68 -21
  191. package/dist/grid/chrome/useGridRowContextMenu.d.ts +4 -2
  192. package/dist/grid/chrome/useGridRowContextMenu.js +28 -2
  193. package/dist/grid/chrome/useGridScaleStyles.d.ts +3 -1
  194. package/dist/grid/chrome/useGridScaleStyles.js +6 -7
  195. package/dist/grid/chrome/useGridScrollArea.d.ts +21 -0
  196. package/dist/grid/chrome/useGridScrollArea.js +65 -0
  197. package/dist/grid/chrome/useGridTableInteractionModel.d.ts +28 -5
  198. package/dist/grid/chrome/useGridTableInteractionModel.js +66 -14
  199. package/dist/grid/chrome/useHeaderDragReorder.d.ts +2 -2
  200. package/dist/grid/core/clipboard-model.d.ts +2 -0
  201. package/dist/grid/core/clipboard-model.js +1 -1
  202. package/dist/grid/core/commit-model.d.ts +7 -0
  203. package/dist/grid/core/edge-scroll.d.ts +21 -0
  204. package/dist/grid/core/edge-scroll.js +23 -0
  205. package/dist/grid/core/editing-controller.d.ts +2 -1
  206. package/dist/grid/core/editing-controller.js +35 -9
  207. package/dist/grid/core/editing-model.d.ts +9 -0
  208. package/dist/grid/core/editing-model.js +12 -0
  209. package/dist/grid/core/flat-rows.d.ts +35 -0
  210. package/dist/grid/core/flat-rows.js +20 -0
  211. package/dist/grid/core/grid-aria.d.ts +27 -0
  212. package/dist/grid/core/grid-aria.js +39 -0
  213. package/dist/grid/core/grid-focus.d.ts +54 -0
  214. package/dist/grid/core/grid-focus.js +148 -0
  215. package/dist/grid/core/nav.d.ts +2 -2
  216. package/dist/grid/core/pending-reconciliation.d.ts +3 -0
  217. package/dist/grid/core/pending-reconciliation.js +5 -3
  218. package/dist/grid/core/row-window.d.ts +40 -0
  219. package/dist/grid/core/row-window.js +43 -0
  220. package/dist/grid/core/spreadsheet-operations.d.ts +17 -1
  221. package/dist/grid/core/spreadsheet-operations.js +33 -6
  222. package/dist/grid/core/useGridEditing.d.ts +3 -0
  223. package/dist/grid/core/useGridEditing.js +6 -3
  224. package/dist/grid/core/value-equality.d.ts +23 -1
  225. package/dist/grid/core/value-equality.js +46 -0
  226. package/dist/grid/useGridTablePrefs.d.ts +0 -1
  227. package/dist/grid/useGridTablePrefs.js +1 -3
  228. package/dist/index.d.ts +1 -0
  229. package/dist/index.js +1 -0
  230. package/dist/internal/viewport.d.ts +0 -2
  231. package/dist/internal/viewport.js +0 -14
  232. package/dist/model/column-capabilities.d.ts +2 -1
  233. package/dist/model/column-capabilities.js +28 -8
  234. package/dist/model/column-from.js +3 -0
  235. package/dist/model/column-inspect.d.ts +10 -2
  236. package/dist/model/column-inspect.js +9 -0
  237. package/dist/model/column-schema.d.ts +6 -1
  238. package/dist/model/column-types.d.ts +3 -1
  239. package/dist/model/column-types.js +1 -1
  240. package/dist/model/preferences.d.ts +0 -4
  241. package/dist/model/preferences.js +0 -1
  242. package/dist/model/prefs-buckets.d.ts +0 -1
  243. package/dist/model/prefs-buckets.js +0 -3
  244. package/dist/model/render-count.d.ts +6 -0
  245. package/dist/model/render-count.js +11 -0
  246. package/dist/provider/ViewsProvider.d.ts +5 -1
  247. package/dist/provider/ViewsProvider.js +9 -3
  248. package/dist/provider/components.d.ts +19 -1
  249. package/dist/provider/components.js +4 -2
  250. package/dist/provider/context.d.ts +5 -2
  251. package/dist/provider/desktop.d.ts +9 -0
  252. package/dist/provider/desktop.js +22 -0
  253. package/dist/provider/plain-input.d.ts +8 -0
  254. package/dist/provider/plain-input.js +5 -0
  255. package/dist/react.d.ts +2 -1
  256. package/dist/react.js +1 -0
  257. package/dist/selection/SelectCheckbox.d.ts +3 -1
  258. package/dist/selection/SelectCheckbox.js +2 -2
  259. package/dist/selection/useCheckDragSelect.js +6 -5
  260. package/docs/contract.md +93 -35
  261. package/docs/guides/atoms.md +1 -1
  262. package/docs/guides/cells.md +2 -2
  263. package/docs/guides/columns.md +3 -2
  264. package/docs/guides/display.md +1 -0
  265. package/docs/guides/editors.md +71 -13
  266. package/docs/guides/the-grid.md +32 -13
  267. package/docs/guides/the-provider.md +3 -1
  268. package/docs/index.md +3 -1
  269. package/docs/install.md +1 -1
  270. package/docs/reference/cells.md +1 -1
  271. package/docs/reference/display.md +3 -1
  272. package/docs/reference/editors-chips.md +2 -2
  273. package/docs/reference/editors-date.md +3 -3
  274. package/docs/reference/editors-location.md +1 -1
  275. package/docs/reference/editors-number.md +1 -1
  276. package/docs/reference/editors-open-values.md +1 -0
  277. package/docs/reference/editors-panel.md +12 -0
  278. package/docs/reference/editors-range.md +1 -1
  279. package/docs/reference/editors-relation.md +6 -3
  280. package/docs/reference/editors-select.md +3 -2
  281. package/docs/reference/editors-session.md +4 -2
  282. package/docs/reference/editors-text.md +9 -0
  283. package/docs/reference/editors-value-list.md +1 -1
  284. package/docs/reference/editors.md +2 -2
  285. package/docs/reference/field-row.md +16 -0
  286. package/docs/reference/grid.md +3 -3
  287. package/docs/reference/react.md +8 -5
  288. package/docs/reference/views.md +36 -15
  289. package/package.json +23 -4
  290. package/skills/views/SKILL.md +4 -4
  291. package/dist/grid/chrome/useGridScrollSync.d.ts +0 -38
  292. package/dist/grid/chrome/useGridScrollSync.js +0 -176
@@ -17,6 +17,13 @@ export type GridCommitOutcome = {
17
17
  /** `requested`: the row holds the value but its provider has not accepted
18
18
  * it yet — the overlay stays and the cell says so (spec §11.2). */
19
19
  settlement?: FieldSettlement;
20
+ /** What was kept, when the server stored something other than what the cell
21
+ * sent (an invisible character stripped, a label read as its key, `""` kept
22
+ * as null): the value as the row now reads it in this column. Present, even
23
+ * as null, the cell shows it in place of what was typed, undo and redo
24
+ * restore from it (unless `history` says otherwise), and the rows that carry
25
+ * it next clear the cell without a word. Ignored on an undo or a redo. */
26
+ stored?: unknown;
20
27
  } | {
21
28
  status: "unconfirmed";
22
29
  history: false;
@@ -0,0 +1,21 @@
1
+ /** A box on the screen, in client pixels. */
2
+ export type GridBox = {
3
+ top: number;
4
+ bottom: number;
5
+ left: number;
6
+ right: number;
7
+ };
8
+ /**
9
+ * How many pixels a drag at `y` scrolls `box`'s scroller in one frame: 0 in the middle; inside the `zone` px by the
10
+ * top edge a negative step that grows with the pointer's depth, `-max` at or past the edge; the same, positive, by
11
+ * the bottom edge. A whole pixel, and never 0 once inside a zone, so a pointer resting there always moves the scroller.
12
+ * A box shorter than two zones takes the nearer edge.
13
+ */
14
+ export declare function gridEdgeScrollStep(y: number, box: GridBox, zone?: number, max?: number): number;
15
+ /** The point inside `box`, `inset` px in from any edge it was past: where a drag outside the box hit-tests. */
16
+ export declare function clampIntoBox(x: number, y: number, box: GridBox, inset?: number): {
17
+ x: number;
18
+ y: number;
19
+ };
20
+ /** The part every box shares. Empty boxes come out with `bottom <= top` or `right <= left`. */
21
+ export declare function intersectBoxes(...boxes: GridBox[]): GridBox;
@@ -0,0 +1,23 @@
1
+ export function gridEdgeScrollStep(y, box, zone = 40, max = 28) {
2
+ const upDepth = (box.top + zone - y) / zone;
3
+ const downDepth = (y - (box.bottom - zone)) / zone;
4
+ const depth = Math.max(upDepth, downDepth);
5
+ if (depth <= 0)
6
+ return 0;
7
+ const step = depth >= 1 ? max : Math.max(1, Math.round(depth * max));
8
+ return upDepth >= downDepth ? -step : step;
9
+ }
10
+ export function clampIntoBox(x, y, box, inset = 1) {
11
+ return {
12
+ x: Math.min(Math.max(x, box.left + inset), box.right - inset),
13
+ y: Math.min(Math.max(y, box.top + inset), box.bottom - inset),
14
+ };
15
+ }
16
+ export function intersectBoxes(...boxes) {
17
+ return boxes.reduce((a, b) => ({
18
+ top: Math.max(a.top, b.top),
19
+ bottom: Math.min(a.bottom, b.bottom),
20
+ left: Math.max(a.left, b.left),
21
+ right: Math.min(a.right, b.right),
22
+ }));
23
+ }
@@ -42,7 +42,8 @@ export declare class GridEditingController<Row> {
42
42
  undo(resolveRow: ResolveRow<Row>, onApply?: (pos: GridCellPos) => void): boolean;
43
43
  redo(resolveRow: ResolveRow<Row>, onApply?: (pos: GridCellPos) => void): boolean;
44
44
  private publishPending;
45
- /** A `requested` outcome keeps its overlay and marks it; nothing else changes. */
45
+ /** A confirmed outcome that says what was `stored` lays it over the cell in place of what was
46
+ * typed; a `requested` one keeps its overlay and marks it. Nothing else changes. */
46
47
  private settle;
47
48
  /** Is a write for this cell still in flight? Reconciliation asks, so it can
48
49
  * tell "the refetch hasn't caught up yet" apart from "the server disagrees". */
@@ -1,5 +1,5 @@
1
1
  import { gridCellKey, } from "./commit-model.js";
2
- import { applyGridPending, beginGridHistoryApply, createGridHistory, gridEditValue, gridHistoryValue, groupGridPendingByRow, groupGridPendingSettlement, markGridPendingSettlement, planGridPendingAssignments, pruneGridHistoryEntry, reconcileGridPending, recordGridHistory, rollbackGridPending, settleGridHistoryApply, } from "./editing-model.js";
2
+ import { applyGridPending, beginGridHistoryApply, createGridHistory, gridEditValue, gridHistoryValue, groupGridPendingByRow, groupGridPendingSettlement, keepGridPending, markGridPendingSettlement, planGridPendingAssignments, pruneGridHistoryEntry, reconcileGridPending, recordGridHistory, rollbackGridPending, settleGridHistoryApply, } from "./editing-model.js";
3
3
  const confirmed = (outcome) => outcome ?? { status: "confirmed" };
4
4
  export class GridEditingController {
5
5
  callbacks;
@@ -38,8 +38,12 @@ export class GridEditingController {
38
38
  const successes = results.map((result) => result.status === "confirmed");
39
39
  entry.edits = entry.edits.map((cell, index) => {
40
40
  const result = results[index];
41
- const history = result?.status === "confirmed" ? result.history : false;
42
- return history ? { ...cell, historyPrev: history.prev, historyNext: history.next } : cell;
41
+ if (result?.status !== "confirmed")
42
+ return cell;
43
+ if (result.history) {
44
+ return { ...cell, historyPrev: result.history.prev, historyNext: result.history.next };
45
+ }
46
+ return "stored" in result ? { ...cell, historyNext: result.stored } : cell;
43
47
  });
44
48
  this.history = pruneGridHistoryEntry(this.history, entry.id, successes.map((ok, index) => {
45
49
  const result = results[index];
@@ -74,14 +78,28 @@ export class GridEditingController {
74
78
  this.onPendingChange(groupGridPendingByRow(next), groupGridPendingSettlement(next));
75
79
  }
76
80
  settle(keys, results, assignments) {
77
- const requested = new Set(keys.filter((_, index) => {
81
+ const storedByKey = new Map();
82
+ const requested = new Set();
83
+ keys.forEach((key, index) => {
78
84
  const result = results[index];
79
- return result?.status === "confirmed" && result.settlement === "requested";
80
- }));
85
+ if (result?.status !== "confirmed")
86
+ return;
87
+ if ("stored" in result)
88
+ storedByKey.set(key, result.stored);
89
+ if (result.settlement === "requested")
90
+ requested.add(key);
91
+ });
92
+ let next = this.pending;
93
+ const kept = assignments
94
+ .filter((assignment) => storedByKey.has(assignment.key))
95
+ .map((assignment) => ({ assignment, stored: storedByKey.get(assignment.key) }));
96
+ if (kept.length > 0)
97
+ next = keepGridPending(next, kept);
81
98
  const owned = assignments.filter((assignment) => requested.has(assignment.key));
82
- if (owned.length > 0) {
83
- this.publishPending(markGridPendingSettlement(this.pending, owned, "requested"));
84
- }
99
+ if (owned.length > 0)
100
+ next = markGridPendingSettlement(next, owned, "requested");
101
+ if (next !== this.pending)
102
+ this.publishPending(next);
85
103
  }
86
104
  hasInflight(rowId, columnId) {
87
105
  return (this.inflight.get(gridCellKey(rowId, columnId))?.size ?? 0) > 0;
@@ -233,7 +251,15 @@ export class GridEditingController {
233
251
  row: resolveRow(cell.rowId) ?? cell.rowSnapshot,
234
252
  cell,
235
253
  }));
254
+ const overwritten = cells.map(({ cell }) => {
255
+ const key = gridCellKey(cell.rowId, cell.columnId);
256
+ const held = this.pending.get(key);
257
+ return held ? { key, value: held.value, revision: held.revision } : null;
258
+ });
236
259
  const results = await this.performBatch(cells, kind === "undo" ? "prev" : "next", "restore");
260
+ const cleared = overwritten.filter((held, index) => held != null && results[index]?.status === "confirmed");
261
+ if (cleared.length > 0)
262
+ this.publishPending(rollbackGridPending(this.pending, cleared));
237
263
  this.history = settleGridHistoryApply(this.history, kind, entry, results.every((result) => result.status === "confirmed"));
238
264
  });
239
265
  }
@@ -71,6 +71,15 @@ export declare function applyGridPending(state: GridPendingState, assignments: r
71
71
  export declare function rollbackGridPending(state: GridPendingState, assignments: readonly GridPendingAssignment[]): Map<string, GridPendingEntry>;
72
72
  /** Mark the overlays a `requested` outcome still owns; a later overlap is left alone. */
73
73
  export declare function markGridPendingSettlement(state: GridPendingState, assignments: readonly GridPendingAssignment[], settlement: "requested"): Map<string, GridPendingEntry>;
74
+ /**
75
+ * Lay what the server kept over the overlays this commit still owns, in place of what was typed. The
76
+ * entry stays (its baseline, its settlement): the rows have to carry the kept value before it clears,
77
+ * and a later overlap is left alone. A kept object is marked, so reconciliation reads it by structure.
78
+ */
79
+ export declare function keepGridPending(state: GridPendingState, kept: readonly {
80
+ assignment: GridPendingAssignment;
81
+ stored: unknown;
82
+ }[]): Map<string, GridPendingEntry>;
74
83
  export declare function reconcileGridPending(state: GridPendingState, matchedKeys: readonly string[]): Map<string, GridPendingEntry>;
75
84
  export declare function groupGridPendingByRow(state: GridPendingState): ReadonlyMap<string, Record<string, unknown>>;
76
85
  /** The `requested` overlays only, by row — what the cell reads to draw its pending state. */
@@ -1,5 +1,6 @@
1
1
  import { gridCellKey } from "./commit-model.js";
2
2
  import { sameListValue } from "@viewkitjs/fields";
3
+ import { markGridKeptValue } from "./value-equality.js";
3
4
  const GRID_UNDO_MAX = 50;
4
5
  export function createGridHistory() {
5
6
  return { undo: [], redo: [] };
@@ -96,6 +97,17 @@ export function markGridPendingSettlement(state, assignments, settlement) {
96
97
  }
97
98
  return next;
98
99
  }
100
+ export function keepGridPending(state, kept) {
101
+ const next = new Map(state);
102
+ for (const { assignment, stored } of kept) {
103
+ const entry = next.get(assignment.key);
104
+ if (entry?.revision !== assignment.revision)
105
+ continue;
106
+ markGridKeptValue(stored);
107
+ next.set(assignment.key, { ...entry, value: stored });
108
+ }
109
+ return next;
110
+ }
99
111
  export function reconcileGridPending(state, matchedKeys) {
100
112
  if (matchedKeys.length === 0)
101
113
  return new Map(state);
@@ -0,0 +1,35 @@
1
+ import type { ListGroup } from "../../grouping/types.js";
2
+ /** Where one drawn row sits: its section's key and its index among that section's rows. */
3
+ export type GridRowPlace = {
4
+ groupKey: string;
5
+ index: number;
6
+ };
7
+ /** One list the grid draws: a group, or the one ungrouped list. */
8
+ export type GridFlatSection<Row> = {
9
+ groupKey: string;
10
+ items: Row[];
11
+ collapsed: boolean;
12
+ };
13
+ /**
14
+ * The grid's rows as one flat list behind the groups. It says what each section draws, the keyboard's order (the
15
+ * rows a person can see, group by group, as drawn) and where every row sits, so the window, the reveal and the
16
+ * screen reader's row numbers all read one answer.
17
+ */
18
+ export type GridFlatRows<Row> = {
19
+ /** One section per drawn list: every group, or the one ungrouped list. */
20
+ sections: GridFlatSection<Row>[];
21
+ /** Row KEYS the page holds, in the drawn order, a collapsed group's rows included: what an open edit or a focus is
22
+ * checked against, so collapsing a group never cancels an edit in it. */
23
+ order: string[];
24
+ /** Row KEYS of the open sections, in the drawn order: the keyboard's, the range's, the paste's and the fill's
25
+ * order, so each skips a collapsed group's rows as a spreadsheet skips filtered ones. */
26
+ visible: string[];
27
+ /** Every row key, collapsed or not → its section and index there. */
28
+ place: ReadonlyMap<string, GridRowPlace>;
29
+ };
30
+ export declare function gridFlatRows<Row>({ groups, grouped, isCollapsed, getRowId, }: {
31
+ groups: ListGroup<Row>[];
32
+ grouped: boolean;
33
+ isCollapsed?: (key: string) => boolean;
34
+ getRowId: (row: Row) => string;
35
+ }): GridFlatRows<Row>;
@@ -0,0 +1,20 @@
1
+ import { gridRowKey } from "./coordinates.js";
2
+ const UNGROUPED_KEY = "__all__";
3
+ export function gridFlatRows({ groups, grouped, isCollapsed, getRowId, }) {
4
+ const sections = grouped
5
+ ? groups.map((group) => ({ groupKey: group.key, items: group.items, collapsed: isCollapsed?.(group.key) ?? false }))
6
+ : [{ groupKey: groups[0]?.key ?? UNGROUPED_KEY, items: groups.flatMap((group) => group.items), collapsed: false }];
7
+ const order = [];
8
+ const visible = [];
9
+ const place = new Map();
10
+ for (const section of sections) {
11
+ section.items.forEach((row, index) => {
12
+ const key = gridRowKey(section.groupKey, getRowId(row));
13
+ place.set(key, { groupKey: section.groupKey, index });
14
+ order.push(key);
15
+ if (!section.collapsed)
16
+ visible.push(key);
17
+ });
18
+ }
19
+ return { sections, order, visible, place };
20
+ }
@@ -0,0 +1,27 @@
1
+ export type GridAriaSection = {
2
+ groupKey: string;
3
+ collapsed: boolean;
4
+ count: number;
5
+ footer: boolean;
6
+ };
7
+ export type GridAriaLayout = {
8
+ role: "grid" | "treegrid";
9
+ /** Every row the grid holds, bars, column names and footers included; -1 while more rows remain to load. */
10
+ rowCount: number;
11
+ /** The checkbox lane (when selectable) and every visible column. */
12
+ colCount: number;
13
+ /** 1-based; undefined for a part the section doesn't draw (a shut group's column names, rows and footer). */
14
+ barIndex: (groupKey: string) => number | undefined;
15
+ headIndex: (groupKey: string) => number | undefined;
16
+ rowIndex: (groupKey: string, index: number) => number | undefined;
17
+ footIndex: (groupKey: string) => number | undefined;
18
+ /** 1-based column index of a column id (GRID_RAIL_COLUMN included when selectable). */
19
+ colIndex: (columnId: string) => number | undefined;
20
+ };
21
+ export declare function gridAriaLayout(input: {
22
+ sections: readonly GridAriaSection[];
23
+ grouped: boolean;
24
+ selectable: boolean;
25
+ columnIds: readonly string[];
26
+ more: boolean;
27
+ }): GridAriaLayout;
@@ -0,0 +1,39 @@
1
+ import { GRID_RAIL_COLUMN } from "./grid-focus.js";
2
+ export function gridAriaLayout(input) {
3
+ const bySection = new Map();
4
+ let next = 1;
5
+ for (const section of input.sections) {
6
+ const rows = { count: section.count };
7
+ if (input.grouped)
8
+ rows.bar = next++;
9
+ if (!section.collapsed || !input.grouped) {
10
+ rows.head = next++;
11
+ rows.firstRow = next;
12
+ next += section.count;
13
+ if (section.footer)
14
+ rows.foot = next++;
15
+ }
16
+ bySection.set(section.groupKey, rows);
17
+ }
18
+ const columns = new Map();
19
+ let col = 1;
20
+ if (input.selectable)
21
+ columns.set(GRID_RAIL_COLUMN, col++);
22
+ for (const id of input.columnIds)
23
+ columns.set(id, col++);
24
+ return {
25
+ role: input.grouped ? "treegrid" : "grid",
26
+ rowCount: input.more ? -1 : next - 1,
27
+ colCount: columns.size,
28
+ barIndex: (groupKey) => bySection.get(groupKey)?.bar,
29
+ headIndex: (groupKey) => bySection.get(groupKey)?.head,
30
+ rowIndex: (groupKey, index) => {
31
+ const rows = bySection.get(groupKey);
32
+ if (rows?.firstRow == null || index < 0 || index >= rows.count)
33
+ return undefined;
34
+ return rows.firstRow + index;
35
+ },
36
+ footIndex: (groupKey) => bySection.get(groupKey)?.foot,
37
+ colIndex: (columnId) => columns.get(columnId),
38
+ };
39
+ }
@@ -0,0 +1,54 @@
1
+ import type { GridCellPos } from "./coordinates.js";
2
+ import { type GridNavDirection } from "./nav.js";
3
+ /** The checkbox lane's column id, on a row and on the column names' row. */
4
+ export declare const GRID_RAIL_COLUMN = "__rail__";
5
+ /** "+ Add column", the column names' row's last cell where the header draws it. */
6
+ export declare const GRID_ADD_COLUMN = "__add__";
7
+ export type GridChromeTarget = {
8
+ kind: "bar";
9
+ groupKey: string;
10
+ part: "name" | "menu";
11
+ } | {
12
+ kind: "head";
13
+ groupKey: string;
14
+ columnId: string;
15
+ } | {
16
+ kind: "foot";
17
+ groupKey: string;
18
+ columnId: string;
19
+ } | {
20
+ kind: "rail";
21
+ rowKey: string;
22
+ };
23
+ export type GridFocusTarget = {
24
+ kind: "cell";
25
+ pos: GridCellPos;
26
+ } | GridChromeTarget;
27
+ export type GridFocusSection = {
28
+ groupKey: string;
29
+ collapsed: boolean;
30
+ /** Its rows' keys in drawn order (a shut section's too; they are skipped). */
31
+ rowKeys: readonly string[];
32
+ /** The group's footer row is drawn (GridFooter draws one). */
33
+ footer: boolean;
34
+ /** Its bar carries a ⋯ menu. */
35
+ menu: boolean;
36
+ };
37
+ export type GridFocusShape = {
38
+ sections: readonly GridFocusSection[];
39
+ grouped: boolean;
40
+ selectable: boolean;
41
+ columnIds: readonly string[];
42
+ addColumn: boolean;
43
+ };
44
+ /** One arrow from `from`; null where nothing lies that way. A bar's ←/→ that collapse or open are not moves:
45
+ * `gridBarArrow` answers those first. */
46
+ export declare function gridFocusStep(from: GridFocusTarget, dir: GridNavDirection, shape: GridFocusShape): GridFocusTarget | null;
47
+ /** Tab (backwards: Shift+Tab). A data cell moves as `nextCellLinear` over the visible rows; null past the grid's
48
+ * last (or before its first) cell means "leave the grid". A chrome target moves along its own row, and leaves the
49
+ * grid at the row's ends, so Tab never traps a keyboard (an empty grid's column names included). */
50
+ export declare function gridFocusTab(from: GridFocusTarget, backwards: boolean, shape: GridFocusShape): GridFocusTarget | null;
51
+ /** What ← or → does on a bar's name: collapse, open, or move (to the ⋯ menu). */
52
+ export declare function gridBarArrow(collapsed: boolean, dir: "left" | "right", menu: boolean): "collapse" | "open" | "move" | "none";
53
+ /** The bar a section's row or chrome belongs to, for a focus whose group just shut. */
54
+ export declare function gridBarOf(groupKey: string): GridChromeTarget;
@@ -0,0 +1,148 @@
1
+ import { nextCellLinear, nextCellPos } from "./nav.js";
2
+ export const GRID_RAIL_COLUMN = "__rail__";
3
+ export const GRID_ADD_COLUMN = "__add__";
4
+ const cell = (rowId, columnId) => ({ kind: "cell", pos: { rowId, columnId } });
5
+ function locate(shape, rowKey) {
6
+ for (let s = 0; s < shape.sections.length; s++) {
7
+ const section = shape.sections[s];
8
+ if (section.collapsed)
9
+ continue;
10
+ const i = section.rowKeys.indexOf(rowKey);
11
+ if (i >= 0)
12
+ return { s, i };
13
+ }
14
+ return null;
15
+ }
16
+ function sectionIndex(shape, groupKey) {
17
+ return shape.sections.findIndex((section) => section.groupKey === groupKey);
18
+ }
19
+ function headColumns(shape) {
20
+ return [
21
+ ...(shape.selectable ? [GRID_RAIL_COLUMN] : []),
22
+ ...shape.columnIds,
23
+ ...(shape.addColumn ? [GRID_ADD_COLUMN] : []),
24
+ ];
25
+ }
26
+ function onRow(shape, rowKey, columnId) {
27
+ if (columnId === GRID_RAIL_COLUMN && shape.selectable)
28
+ return { kind: "rail", rowKey };
29
+ if (shape.columnIds.includes(columnId))
30
+ return cell(rowKey, columnId);
31
+ const last = shape.columnIds[shape.columnIds.length - 1];
32
+ return cell(rowKey, columnId === GRID_ADD_COLUMN && last != null ? last : (shape.columnIds[0] ?? columnId));
33
+ }
34
+ function onHead(shape, groupKey, columnId) {
35
+ return { kind: "head", groupKey, columnId: headColumns(shape).includes(columnId) ? columnId : (shape.columnIds[0] ?? columnId) };
36
+ }
37
+ function onFoot(shape, groupKey, columnId) {
38
+ if (shape.columnIds.includes(columnId))
39
+ return { kind: "foot", groupKey, columnId };
40
+ const last = shape.columnIds[shape.columnIds.length - 1];
41
+ return { kind: "foot", groupKey, columnId: columnId === GRID_ADD_COLUMN && last != null ? last : (shape.columnIds[0] ?? columnId) };
42
+ }
43
+ function nextTop(shape, s) {
44
+ const next = shape.sections[s + 1];
45
+ return next && shape.grouped ? gridBarOf(next.groupKey) : null;
46
+ }
47
+ function prevBottom(shape, s) {
48
+ const prev = shape.sections[s - 1];
49
+ if (!prev)
50
+ return null;
51
+ if (prev.collapsed && shape.grouped)
52
+ return gridBarOf(prev.groupKey);
53
+ const first = shape.columnIds[0] ?? "";
54
+ if (prev.footer)
55
+ return { kind: "foot", groupKey: prev.groupKey, columnId: first };
56
+ const last = prev.rowKeys[prev.rowKeys.length - 1];
57
+ if (last != null)
58
+ return cell(last, first);
59
+ return { kind: "head", groupKey: prev.groupKey, columnId: first };
60
+ }
61
+ function belowRows(shape, s, columnId) {
62
+ const section = shape.sections[s];
63
+ return section.footer ? onFoot(shape, section.groupKey, columnId) : nextTop(shape, s);
64
+ }
65
+ function stepAlong(columns, columnId, dir) {
66
+ const at = columns.indexOf(columnId);
67
+ if (at < 0)
68
+ return null;
69
+ return columns[at + (dir === "right" ? 1 : -1)] ?? null;
70
+ }
71
+ export function gridFocusStep(from, dir, shape) {
72
+ const horizontal = dir === "left" || dir === "right";
73
+ if (from.kind === "cell" || from.kind === "rail") {
74
+ const rowKey = from.kind === "cell" ? from.pos.rowId : from.rowKey;
75
+ const columnId = from.kind === "cell" ? from.pos.columnId : GRID_RAIL_COLUMN;
76
+ const at = locate(shape, rowKey);
77
+ if (!at)
78
+ return null;
79
+ const section = shape.sections[at.s];
80
+ const columns = columnId === GRID_RAIL_COLUMN ? [GRID_RAIL_COLUMN] : [...shape.columnIds];
81
+ const inside = nextCellPos({ rowId: rowKey, columnId }, dir, [...section.rowKeys], columns);
82
+ if (inside)
83
+ return onRow(shape, inside.rowId, inside.columnId);
84
+ if (horizontal) {
85
+ if (dir === "left" && columnId === shape.columnIds[0] && shape.selectable)
86
+ return { kind: "rail", rowKey };
87
+ if (dir === "right" && columnId === GRID_RAIL_COLUMN && shape.columnIds[0] != null) {
88
+ return cell(rowKey, shape.columnIds[0]);
89
+ }
90
+ return null;
91
+ }
92
+ return dir === "up" ? onHead(shape, section.groupKey, columnId) : belowRows(shape, at.s, columnId);
93
+ }
94
+ const s = sectionIndex(shape, from.groupKey);
95
+ if (s < 0)
96
+ return null;
97
+ const section = shape.sections[s];
98
+ if (from.kind === "head") {
99
+ if (horizontal) {
100
+ const next = stepAlong(headColumns(shape), from.columnId, dir);
101
+ return next == null ? null : { kind: "head", groupKey: from.groupKey, columnId: next };
102
+ }
103
+ if (dir === "up")
104
+ return shape.grouped ? gridBarOf(section.groupKey) : null;
105
+ const first = section.rowKeys[0];
106
+ return first != null ? onRow(shape, first, from.columnId) : belowRows(shape, s, from.columnId);
107
+ }
108
+ if (from.kind === "foot") {
109
+ if (horizontal) {
110
+ const next = stepAlong(shape.columnIds, from.columnId, dir);
111
+ return next == null ? null : { kind: "foot", groupKey: from.groupKey, columnId: next };
112
+ }
113
+ if (dir === "down")
114
+ return nextTop(shape, s);
115
+ const last = section.rowKeys[section.rowKeys.length - 1];
116
+ return last != null ? onRow(shape, last, from.columnId) : onHead(shape, section.groupKey, from.columnId);
117
+ }
118
+ if (horizontal) {
119
+ if (dir === "right" && from.part === "name" && section.menu)
120
+ return { kind: "bar", groupKey: from.groupKey, part: "menu" };
121
+ if (dir === "left" && from.part === "menu")
122
+ return gridBarOf(from.groupKey);
123
+ return null;
124
+ }
125
+ if (dir === "up")
126
+ return prevBottom(shape, s);
127
+ if (section.collapsed)
128
+ return nextTop(shape, s);
129
+ return { kind: "head", groupKey: section.groupKey, columnId: shape.columnIds[0] ?? "" };
130
+ }
131
+ export function gridFocusTab(from, backwards, shape) {
132
+ if (from.kind === "cell") {
133
+ const visible = shape.sections.flatMap((section) => (section.collapsed ? [] : section.rowKeys));
134
+ const next = nextCellLinear(from.pos, backwards, visible, [...shape.columnIds]);
135
+ return next ? { kind: "cell", pos: next } : null;
136
+ }
137
+ return gridFocusStep(from, backwards ? "left" : "right", shape);
138
+ }
139
+ export function gridBarArrow(collapsed, dir, menu) {
140
+ if (dir === "left")
141
+ return collapsed ? "none" : "collapse";
142
+ if (collapsed)
143
+ return "open";
144
+ return menu ? "move" : "none";
145
+ }
146
+ export function gridBarOf(groupKey) {
147
+ return { kind: "bar", groupKey, part: "name" };
148
+ }
@@ -76,8 +76,8 @@ export declare function activeRangeHead(ranges: readonly {
76
76
  * Both id arrays are the VISIBLE order — `visibleRowIds` already excludes rows
77
77
  * in collapsed groups and `visibleColIds` excludes hidden columns, so walking
78
78
  * them is what makes navigation skip collapsed groups. That has to be done by
79
- * DATA: collapsed rows stay mounted in the DOM (a `grid-template-rows: 0fr`
80
- * wrapper), so any DOM-visibility test would wrongly find them.
79
+ * DATA: only the rows on screen are drawn, and a focused row stays drawn even
80
+ * inside a shut group's clip, so no DOM-visibility test can answer it.
81
81
  *
82
82
  * Returns null when `pos` itself isn't in the visible order — e.g. the focused
83
83
  * row's group was just collapsed, or a refetch dropped the row. Same `< 0` bail
@@ -38,6 +38,9 @@ export declare function findGridPendingMatches<Row>(rows: readonly Row[], column
38
38
  * that story and already toasts it.
39
39
  * - a third value entirely → somebody else wrote while we were writing.
40
40
  *
41
+ * When the save answered what it kept (`stored`), the overlay already holds
42
+ * that value, so the first bucket catches it, read by structure for an object.
43
+ *
41
44
  * Pure, and separate from `findGridPendingMatches` on purpose: that answers
42
45
  * "which overlays are finished with", this answers "which of them were taken
43
46
  * from us". Two questions, and only the second is worth a word to the user.
@@ -1,6 +1,6 @@
1
1
  import { gridCellKey } from "./commit-model.js";
2
2
  import { sameListValue } from "@viewkitjs/fields";
3
- import { looselyEqualValue } from "./value-equality.js";
3
+ import { isEmptyValue, isGridKeptValue, looselyEqualValue, sameKeptValue } from "./value-equality.js";
4
4
  export function findGridPendingMatches(rows, columns, getRowId, pendingByRow, hasInflight) {
5
5
  const byId = new Map(rows.map((row) => [getRowId(row), row]));
6
6
  const byColumn = new Map(columns.map((column) => [column.id, column]));
@@ -14,7 +14,9 @@ export function findGridPendingMatches(rows, columns, getRowId, pendingByRow, ha
14
14
  const read = col?.editAccessor ?? col?.accessor;
15
15
  if (!read)
16
16
  continue;
17
- const landed = sameListValue(read(row), value);
17
+ const server = read(row);
18
+ const landed = (isGridKeptValue(value) ? sameKeptValue(server, value) : sameListValue(server, value)) ||
19
+ (isEmptyValue(value) && isEmptyValue(server));
18
20
  const superseded = !landed && hasInflight != null && !hasInflight(rowId, columnId);
19
21
  if (landed || superseded)
20
22
  matched.push(gridCellKey(rowId, columnId));
@@ -38,7 +40,7 @@ export function findSupersededCells(rows, columns, getRowId, pendingByRow, hasIn
38
40
  if (hasInflight(rowId, columnId))
39
41
  continue;
40
42
  const serverValue = read(row);
41
- if (looselyEqualValue(serverValue, value))
43
+ if (isGridKeptValue(value) ? sameKeptValue(serverValue, value) : looselyEqualValue(serverValue, value))
42
44
  continue;
43
45
  if (looselyEqualValue(serverValue, baselineOf(rowId, columnId)))
44
46
  continue;
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Which rows a group draws: the ones its scroll owner shows, plus a margin, plus the rows kept drawn wherever they
3
+ * are (the focused, the editing, a focused checkbox's and the last revealed). Pure arithmetic over one row height, so every row of the
4
+ * grid is the same height (cells never wrap) and a group's rows sit at `index × rowHeight` below its first.
5
+ */
6
+ /** Rows drawn beyond each edge of the view (the timed structures in `bench/pages/structures/` drew 10). */
7
+ export declare const GRID_WINDOW_OVERSCAN = 10;
8
+ /** Rows each open group draws from its top where nothing can be measured: no layout engine, a hidden box, the first render. */
9
+ export declare const GRID_WINDOW_FALLBACK_ROWS = 30;
10
+ /** Rows [start, end) a group draws; null: none. */
11
+ export type GridRowRange = {
12
+ start: number;
13
+ end: number;
14
+ } | null;
15
+ /** A group's rows region in the content's coordinates: where its first row starts, where its box (the clip) ends. */
16
+ export type GridRowRegion = {
17
+ top: number;
18
+ bottom: number;
19
+ };
20
+ export declare function gridGroupRange({ view, region, rowHeight, count, overscan, }: {
21
+ view: {
22
+ top: number;
23
+ bottom: number;
24
+ };
25
+ region: GridRowRegion;
26
+ rowHeight: number;
27
+ count: number;
28
+ overscan?: number;
29
+ }): GridRowRange;
30
+ export type GridRowSegment = {
31
+ kind: "rows";
32
+ start: number;
33
+ end: number;
34
+ } | {
35
+ kind: "gap";
36
+ start: number;
37
+ end: number;
38
+ };
39
+ /** The rows and gaps one group draws, in order, covering [0, count) once: the range, plus each kept index as its own run. */
40
+ export declare function gridRowSegments(count: number, range: GridRowRange, kept: readonly number[]): GridRowSegment[];
@@ -0,0 +1,43 @@
1
+ export const GRID_WINDOW_OVERSCAN = 10;
2
+ export const GRID_WINDOW_FALLBACK_ROWS = 30;
3
+ export function gridGroupRange({ view, region, rowHeight, count, overscan = GRID_WINDOW_OVERSCAN, }) {
4
+ if (rowHeight <= 0 || count <= 0)
5
+ return null;
6
+ const top = Math.max(view.top, region.top);
7
+ const bottom = Math.min(view.bottom, region.bottom, region.top + count * rowHeight);
8
+ if (bottom <= top)
9
+ return null;
10
+ const start = Math.max(0, Math.floor((top - region.top) / rowHeight) - overscan);
11
+ const end = Math.min(count, Math.ceil((bottom - region.top) / rowHeight) + overscan);
12
+ return end > start ? { start, end } : null;
13
+ }
14
+ export function gridRowSegments(count, range, kept) {
15
+ if (count <= 0)
16
+ return [];
17
+ const runs = [];
18
+ if (range)
19
+ runs.push({ start: Math.max(0, range.start), end: Math.min(count, range.end) });
20
+ for (const index of kept)
21
+ if (index >= 0 && index < count)
22
+ runs.push({ start: index, end: index + 1 });
23
+ runs.sort((a, b) => a.start - b.start);
24
+ const segments = [];
25
+ let at = 0;
26
+ for (const run of runs) {
27
+ if (run.end <= run.start)
28
+ continue;
29
+ const last = segments[segments.length - 1];
30
+ if (last?.kind === "rows" && run.start <= last.end) {
31
+ last.end = Math.max(last.end, run.end);
32
+ at = last.end;
33
+ continue;
34
+ }
35
+ if (run.start > at)
36
+ segments.push({ kind: "gap", start: at, end: run.start });
37
+ segments.push({ kind: "rows", start: run.start, end: run.end });
38
+ at = run.end;
39
+ }
40
+ if (at < count)
41
+ segments.push({ kind: "gap", start: at, end: count });
42
+ return segments;
43
+ }