@viewkitjs/views 0.1.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 (390) hide show
  1. package/CHANGELOG.md +767 -1
  2. package/README.md +92 -41
  3. package/dist/atoms/LoadMore.js +11 -1
  4. package/dist/atoms/Row.js +1 -1
  5. package/dist/atoms/RowMenu.d.ts +1 -1
  6. package/dist/atoms/RowMenu.js +20 -6
  7. package/dist/atoms/types.d.ts +4 -4
  8. package/dist/cells/cell-format.d.ts +3 -3
  9. package/dist/cells/cell-title.d.ts +1 -2
  10. package/dist/cells/cell-title.js +2 -2
  11. package/dist/cells/cell-values.js +6 -3
  12. package/dist/contract.d.ts +79 -8
  13. package/dist/contract.js +55 -8
  14. package/dist/display/converted.d.ts +19 -0
  15. package/dist/display/converted.js +12 -0
  16. package/dist/display/format.d.ts +16 -1
  17. package/dist/display/format.js +10 -1
  18. package/dist/display/index.d.ts +2 -1
  19. package/dist/display/index.js +2 -1
  20. package/dist/display/link-click.d.ts +11 -0
  21. package/dist/display/link-click.js +3 -0
  22. package/dist/display/link.js +12 -6
  23. package/dist/display/location.d.ts +4 -3
  24. package/dist/display/location.js +12 -5
  25. package/dist/display/multi-value.d.ts +1 -1
  26. package/dist/display/multi-value.js +1 -1
  27. package/dist/display/options.d.ts +8 -2
  28. package/dist/display/percent.js +10 -3
  29. package/dist/display/phone.d.ts +2 -1
  30. package/dist/display/phone.js +11 -2
  31. package/dist/display/relation.js +1 -1
  32. package/dist/editors/ChipsEditor.d.ts +9 -4
  33. package/dist/editors/ChipsEditor.js +7 -3
  34. package/dist/editors/DateEditor.d.ts +21 -6
  35. package/dist/editors/DateEditor.js +118 -30
  36. package/dist/editors/EditorPanel.d.ts +61 -0
  37. package/dist/editors/EditorPanel.js +54 -0
  38. package/dist/editors/LocationEditor.d.ts +3 -0
  39. package/dist/editors/LocationEditor.js +28 -21
  40. package/dist/editors/NameEditor.d.ts +3 -0
  41. package/dist/editors/NameEditor.js +15 -10
  42. package/dist/editors/NumberEditor.d.ts +3 -0
  43. package/dist/editors/NumberEditor.js +7 -7
  44. package/dist/editors/RangeEditor.d.ts +16 -1
  45. package/dist/editors/RangeEditor.js +22 -6
  46. package/dist/editors/RelationEditor.d.ts +13 -28
  47. package/dist/editors/RelationEditor.js +17 -40
  48. package/dist/editors/RelationSetEditor.d.ts +53 -0
  49. package/dist/editors/RelationSetEditor.js +112 -0
  50. package/dist/editors/SelectEditor.d.ts +21 -3
  51. package/dist/editors/SelectEditor.js +55 -9
  52. package/dist/editors/TextEditor.d.ts +51 -0
  53. package/dist/editors/TextEditor.js +81 -0
  54. package/dist/editors/ValueListEditor.d.ts +5 -2
  55. package/dist/editors/ValueListEditor.js +11 -9
  56. package/dist/editors/edit-cores.d.ts +13 -10
  57. package/dist/editors/edit-cores.js +7 -6
  58. package/dist/editors/edit-session.d.ts +21 -11
  59. package/dist/editors/edit-session.js +19 -5
  60. package/dist/editors/keep-inside.d.ts +12 -0
  61. package/dist/editors/keep-inside.js +20 -0
  62. package/dist/editors/open-value.d.ts +21 -0
  63. package/dist/editors/open-value.js +36 -0
  64. package/dist/editors/open-values.d.ts +4 -0
  65. package/dist/editors/open-values.js +7 -0
  66. package/dist/editors/relation-kinds.d.ts +7 -0
  67. package/dist/editors/relation-kinds.js +21 -0
  68. package/dist/editors/relation-panel.d.ts +69 -0
  69. package/dist/editors/relation-panel.js +40 -0
  70. package/dist/field-row/FieldNoteLine.d.ts +14 -0
  71. package/dist/field-row/FieldNoteLine.js +14 -0
  72. package/dist/field-row/FieldRow.d.ts +73 -0
  73. package/dist/field-row/FieldRow.js +157 -0
  74. package/dist/field-row/FieldRowLane.d.ts +19 -0
  75. package/dist/field-row/FieldRowLane.js +11 -0
  76. package/dist/field-row/editors/RowChipsEditor.d.ts +11 -0
  77. package/dist/field-row/editors/RowChipsEditor.js +25 -0
  78. package/dist/field-row/editors/RowDateEditor.d.ts +16 -0
  79. package/dist/field-row/editors/RowDateEditor.js +18 -0
  80. package/dist/field-row/editors/RowEditor.d.ts +39 -0
  81. package/dist/field-row/editors/RowEditor.js +64 -0
  82. package/dist/field-row/editors/RowNameEditor.d.ts +4 -0
  83. package/dist/field-row/editors/RowNameEditor.js +15 -0
  84. package/dist/field-row/editors/RowNumberEditor.d.ts +12 -0
  85. package/dist/field-row/editors/RowNumberEditor.js +18 -0
  86. package/dist/field-row/editors/RowPlaceEditor.d.ts +8 -0
  87. package/dist/field-row/editors/RowPlaceEditor.js +18 -0
  88. package/dist/field-row/editors/RowRangeEditor.d.ts +4 -0
  89. package/dist/field-row/editors/RowRangeEditor.js +15 -0
  90. package/dist/field-row/editors/RowRelationEditor.d.ts +20 -0
  91. package/dist/field-row/editors/RowRelationEditor.js +77 -0
  92. package/dist/field-row/editors/RowSelectEditor.d.ts +13 -0
  93. package/dist/field-row/editors/RowSelectEditor.js +23 -0
  94. package/dist/field-row/editors/RowTextEditor.d.ts +15 -0
  95. package/dist/field-row/editors/RowTextEditor.js +16 -0
  96. package/dist/field-row/editors/RowValueListEditor.d.ts +4 -0
  97. package/dist/field-row/editors/RowValueListEditor.js +21 -0
  98. package/dist/field-row/editors/host.d.ts +59 -0
  99. package/dist/field-row/editors/host.js +1 -0
  100. package/dist/field-row/editors/row-session.d.ts +49 -0
  101. package/dist/field-row/editors/row-session.js +49 -0
  102. package/dist/field-row/index.d.ts +5 -0
  103. package/dist/field-row/index.js +5 -0
  104. package/dist/field-row/row-target.d.ts +20 -0
  105. package/dist/field-row/row-target.js +3 -0
  106. package/dist/field-row/useFieldWrite.d.ts +45 -0
  107. package/dist/field-row/useFieldWrite.js +190 -0
  108. package/dist/field-row/useRowSettlement.d.ts +33 -0
  109. package/dist/field-row/useRowSettlement.js +23 -0
  110. package/dist/fields/binding.d.ts +7 -2
  111. package/dist/fields/binding.js +13 -6
  112. package/dist/fields/currency.d.ts +0 -10
  113. package/dist/fields/currency.js +0 -14
  114. package/dist/fields/edit-core-types.d.ts +9 -9
  115. package/dist/fields/edit-core-types.js +6 -6
  116. package/dist/fields/money.d.ts +6 -0
  117. package/dist/fields/money.js +11 -0
  118. package/dist/fields/number-edit.d.ts +6 -0
  119. package/dist/fields/number-edit.js +4 -0
  120. package/dist/fields/prepare-write.js +6 -1
  121. package/dist/fields/relation-source-types.d.ts +12 -0
  122. package/dist/fields/write-target.d.ts +50 -0
  123. package/dist/fields/write-target.js +10 -0
  124. package/dist/filters/filter-model.d.ts +0 -1
  125. package/dist/filters/registry.d.ts +3 -36
  126. package/dist/filters/registry.js +0 -38
  127. package/dist/grid/chrome/GridAddColumn.d.ts +11 -0
  128. package/dist/grid/chrome/GridAddColumn.js +29 -0
  129. package/dist/grid/chrome/GridAggregateMenu.d.ts +31 -0
  130. package/dist/grid/chrome/GridAggregateMenu.js +29 -0
  131. package/dist/grid/chrome/GridCellEditors.d.ts +71 -0
  132. package/dist/grid/chrome/GridCellEditors.js +126 -0
  133. package/dist/grid/chrome/GridCellOutline.d.ts +49 -0
  134. package/dist/grid/chrome/GridCellOutline.js +16 -0
  135. package/dist/grid/chrome/GridChipsEditor.d.ts +38 -0
  136. package/dist/grid/chrome/GridChipsEditor.js +35 -0
  137. package/dist/grid/chrome/GridColumnColorSection.d.ts +11 -0
  138. package/dist/grid/chrome/GridColumnColorSection.js +40 -0
  139. package/dist/grid/chrome/GridColumnDateSection.d.ts +23 -0
  140. package/dist/grid/chrome/GridColumnDateSection.js +23 -0
  141. package/dist/grid/chrome/GridColumnDurationSection.d.ts +19 -0
  142. package/dist/grid/chrome/GridColumnDurationSection.js +24 -0
  143. package/dist/grid/chrome/GridColumnMenu.d.ts +101 -0
  144. package/dist/grid/chrome/GridColumnMenu.js +103 -0
  145. package/dist/grid/chrome/GridColumnNumberSection.d.ts +25 -0
  146. package/dist/grid/chrome/GridColumnNumberSection.js +27 -0
  147. package/dist/grid/chrome/GridColumnPercentSection.d.ts +15 -0
  148. package/dist/grid/chrome/GridColumnPercentSection.js +16 -0
  149. package/dist/grid/chrome/GridColumnSortSection.d.ts +18 -0
  150. package/dist/grid/chrome/GridColumnSortSection.js +16 -0
  151. package/dist/grid/chrome/GridDateEditor.d.ts +34 -0
  152. package/dist/grid/chrome/GridDateEditor.js +19 -0
  153. package/dist/grid/chrome/GridFlyout.d.ts +44 -0
  154. package/dist/grid/chrome/GridFlyout.js +80 -0
  155. package/dist/grid/chrome/GridFooter.d.ts +33 -0
  156. package/dist/grid/chrome/GridFooter.js +85 -0
  157. package/dist/grid/chrome/GridGroupMenu.d.ts +37 -0
  158. package/dist/grid/chrome/GridGroupMenu.js +64 -0
  159. package/dist/grid/chrome/GridHeader.d.ts +66 -0
  160. package/dist/grid/chrome/GridHeader.js +42 -0
  161. package/dist/grid/chrome/GridLongTextEditor.d.ts +55 -0
  162. package/dist/grid/chrome/GridLongTextEditor.js +69 -0
  163. package/dist/grid/chrome/GridMenuRow.d.ts +15 -0
  164. package/dist/grid/chrome/GridMenuRow.js +15 -0
  165. package/dist/grid/chrome/GridNameEditor.d.ts +24 -0
  166. package/dist/grid/chrome/GridNameEditor.js +21 -0
  167. package/dist/grid/chrome/GridNumberEditor.d.ts +49 -0
  168. package/dist/grid/chrome/GridNumberEditor.js +51 -0
  169. package/dist/grid/chrome/GridPlaceEditor.d.ts +26 -0
  170. package/dist/grid/chrome/GridPlaceEditor.js +22 -0
  171. package/dist/grid/chrome/GridRangeEditor.d.ts +30 -0
  172. package/dist/grid/chrome/GridRangeEditor.js +21 -0
  173. package/dist/grid/chrome/GridRelationEditor.d.ts +45 -0
  174. package/dist/grid/chrome/GridRelationEditor.js +92 -0
  175. package/dist/grid/chrome/GridResizeHandle.d.ts +19 -0
  176. package/dist/grid/chrome/GridResizeHandle.js +19 -0
  177. package/dist/grid/chrome/GridRow.d.ts +31 -0
  178. package/dist/grid/chrome/GridRow.js +179 -0
  179. package/dist/grid/chrome/GridRowActions.d.ts +32 -0
  180. package/dist/grid/chrome/GridRowActions.js +25 -0
  181. package/dist/grid/chrome/GridRowCells.d.ts +4 -0
  182. package/dist/grid/chrome/GridRowCells.js +128 -0
  183. package/dist/grid/chrome/GridRowGlyph.d.ts +12 -0
  184. package/dist/grid/chrome/GridRowGlyph.js +13 -0
  185. package/dist/grid/chrome/GridSelectEditor.d.ts +33 -0
  186. package/dist/grid/chrome/GridSelectEditor.js +43 -0
  187. package/dist/grid/chrome/GridStructure.d.ts +47 -0
  188. package/dist/grid/chrome/GridStructure.js +41 -0
  189. package/dist/grid/chrome/GridTable.d.ts +4 -0
  190. package/dist/grid/chrome/GridTable.js +192 -0
  191. package/dist/grid/chrome/GridTableSurface.d.ts +52 -0
  192. package/dist/grid/chrome/GridTableSurface.js +15 -0
  193. package/dist/grid/chrome/GridTextEditor.d.ts +45 -0
  194. package/dist/grid/chrome/GridTextEditor.js +38 -0
  195. package/dist/grid/chrome/GridValueListEditor.d.ts +30 -0
  196. package/dist/grid/chrome/GridValueListEditor.js +19 -0
  197. package/dist/grid/chrome/StuckMarker.d.ts +16 -0
  198. package/dist/grid/chrome/StuckMarker.js +34 -0
  199. package/dist/grid/chrome/cell-clipboard.d.ts +9 -0
  200. package/dist/grid/chrome/cell-clipboard.js +28 -0
  201. package/dist/grid/chrome/cell-cut-off.d.ts +11 -0
  202. package/dist/grid/chrome/cell-cut-off.js +20 -0
  203. package/dist/grid/chrome/cells.d.ts +21 -0
  204. package/dist/grid/chrome/cells.js +19 -0
  205. package/dist/grid/chrome/checks.d.ts +32 -0
  206. package/dist/grid/chrome/checks.js +32 -0
  207. package/dist/grid/chrome/column-glyph.d.ts +14 -0
  208. package/dist/grid/chrome/column-glyph.js +44 -0
  209. package/dist/grid/chrome/editors.d.ts +9 -0
  210. package/dist/grid/chrome/editors.js +10 -0
  211. package/dist/grid/chrome/grid-cell-classes.d.ts +53 -0
  212. package/dist/grid/chrome/grid-cell-classes.js +32 -0
  213. package/dist/grid/chrome/grid-cell-link.d.ts +13 -0
  214. package/dist/grid/chrome/grid-cell-link.js +9 -0
  215. package/dist/grid/chrome/grid-edit-session.d.ts +63 -0
  216. package/dist/grid/chrome/grid-edit-session.js +118 -0
  217. package/dist/grid/chrome/grid-hover.d.ts +60 -0
  218. package/dist/grid/chrome/grid-hover.js +81 -0
  219. package/dist/grid/chrome/grid-menu-focus.d.ts +43 -0
  220. package/dist/grid/chrome/grid-menu-focus.js +93 -0
  221. package/dist/grid/chrome/grid-menu-search.d.ts +7 -0
  222. package/dist/grid/chrome/grid-menu-search.js +7 -0
  223. package/dist/grid/chrome/grid-row-menu-key.d.ts +15 -0
  224. package/dist/grid/chrome/grid-row-menu-key.js +36 -0
  225. package/dist/grid/chrome/grid-row-props.d.ts +143 -0
  226. package/dist/grid/chrome/grid-row-props.js +1 -0
  227. package/dist/grid/chrome/grid-row-window.d.ts +61 -0
  228. package/dist/grid/chrome/grid-row-window.js +212 -0
  229. package/dist/grid/chrome/grid-scroll-owner.d.ts +38 -0
  230. package/dist/grid/chrome/grid-scroll-owner.js +75 -0
  231. package/dist/grid/chrome/grid-styles.d.ts +40 -0
  232. package/dist/grid/chrome/grid-styles.js +9 -0
  233. package/dist/grid/chrome/grid-table-props.d.ts +172 -0
  234. package/dist/grid/chrome/grid-table-props.js +1 -0
  235. package/dist/grid/chrome/useGridBatchApi.d.ts +34 -0
  236. package/dist/grid/chrome/useGridBatchApi.js +35 -0
  237. package/dist/grid/chrome/useGridColumnLayout.d.ts +30 -0
  238. package/dist/grid/chrome/useGridColumnLayout.js +206 -0
  239. package/dist/grid/chrome/useGridFocus.d.ts +45 -0
  240. package/dist/grid/chrome/useGridFocus.js +122 -0
  241. package/dist/grid/chrome/useGridHeaderDrag.d.ts +20 -0
  242. package/dist/grid/chrome/useGridHeaderDrag.js +37 -0
  243. package/dist/grid/chrome/useGridKeyboard.d.ts +64 -0
  244. package/dist/grid/chrome/useGridKeyboard.js +450 -0
  245. package/dist/grid/chrome/useGridPendingReconciliation.d.ts +12 -0
  246. package/dist/grid/chrome/useGridPendingReconciliation.js +32 -0
  247. package/dist/grid/chrome/useGridRailReveal.d.ts +57 -0
  248. package/dist/grid/chrome/useGridRailReveal.js +67 -0
  249. package/dist/grid/chrome/useGridRangeActions.d.ts +51 -0
  250. package/dist/grid/chrome/useGridRangeActions.js +195 -0
  251. package/dist/grid/chrome/useGridRangeGestures.d.ts +32 -0
  252. package/dist/grid/chrome/useGridRangeGestures.js +237 -0
  253. package/dist/grid/chrome/useGridRowContextMenu.d.ts +37 -0
  254. package/dist/grid/chrome/useGridRowContextMenu.js +153 -0
  255. package/dist/grid/chrome/useGridScaleStyles.d.ts +3 -0
  256. package/dist/grid/chrome/useGridScaleStyles.js +28 -0
  257. package/dist/grid/chrome/useGridScrollArea.d.ts +21 -0
  258. package/dist/grid/chrome/useGridScrollArea.js +65 -0
  259. package/dist/grid/chrome/useGridTableInteractionModel.d.ts +78 -0
  260. package/dist/grid/chrome/useGridTableInteractionModel.js +249 -0
  261. package/dist/grid/chrome/useGridTableSelection.d.ts +29 -0
  262. package/dist/grid/chrome/useGridTableSelection.js +55 -0
  263. package/dist/grid/chrome/useHeaderDragReorder.d.ts +21 -0
  264. package/dist/grid/chrome/useHeaderDragReorder.js +216 -0
  265. package/dist/grid/core/clipboard-model.d.ts +83 -0
  266. package/dist/grid/core/clipboard-model.js +291 -0
  267. package/dist/grid/core/column-values.d.ts +27 -0
  268. package/dist/grid/core/column-values.js +76 -0
  269. package/dist/grid/core/commit-model.d.ts +41 -0
  270. package/dist/grid/core/commit-model.js +3 -0
  271. package/dist/grid/core/coordinates.d.ts +48 -0
  272. package/dist/grid/core/coordinates.js +27 -0
  273. package/dist/grid/core/edge-scroll.d.ts +21 -0
  274. package/dist/grid/core/edge-scroll.js +23 -0
  275. package/dist/grid/core/edit-values.d.ts +9 -0
  276. package/dist/grid/core/edit-values.js +1 -0
  277. package/dist/grid/core/editing-controller.d.ts +60 -0
  278. package/dist/grid/core/editing-controller.js +266 -0
  279. package/dist/grid/core/editing-model.d.ts +87 -0
  280. package/dist/grid/core/editing-model.js +148 -0
  281. package/dist/grid/core/flat-rows.d.ts +35 -0
  282. package/dist/grid/core/flat-rows.js +20 -0
  283. package/dist/grid/core/grid-aria.d.ts +27 -0
  284. package/dist/grid/core/grid-aria.js +39 -0
  285. package/dist/grid/core/grid-focus.d.ts +54 -0
  286. package/dist/grid/core/grid-focus.js +148 -0
  287. package/dist/grid/core/grid-scale.d.ts +14 -0
  288. package/dist/grid/core/grid-scale.js +8 -0
  289. package/dist/grid/core/nav.d.ts +94 -0
  290. package/dist/grid/core/nav.js +92 -0
  291. package/dist/grid/core/pending-reconciliation.d.ts +53 -0
  292. package/dist/grid/core/pending-reconciliation.js +51 -0
  293. package/dist/grid/core/range-model.d.ts +25 -0
  294. package/dist/grid/core/range-model.js +59 -0
  295. package/dist/grid/core/row-window.d.ts +40 -0
  296. package/dist/grid/core/row-window.js +43 -0
  297. package/dist/grid/core/spreadsheet-operations.d.ts +101 -0
  298. package/dist/grid/core/spreadsheet-operations.js +280 -0
  299. package/dist/grid/core/useGridEditing.d.ts +46 -0
  300. package/dist/grid/core/useGridEditing.js +93 -0
  301. package/dist/grid/core/useGridRange.d.ts +20 -0
  302. package/dist/grid/core/useGridRange.js +24 -0
  303. package/dist/grid/core/value-equality.d.ts +54 -0
  304. package/dist/grid/core/value-equality.js +80 -0
  305. package/dist/grid/index.d.ts +18 -0
  306. package/dist/grid/index.js +5 -0
  307. package/dist/grid/useGridTablePrefs.d.ts +49 -0
  308. package/dist/grid/useGridTablePrefs.js +99 -0
  309. package/dist/index.d.ts +1 -1
  310. package/dist/index.js +1 -1
  311. package/dist/internal/viewport.d.ts +3 -0
  312. package/dist/internal/viewport.js +15 -0
  313. package/dist/model/column-capabilities.d.ts +3 -2
  314. package/dist/model/column-capabilities.js +28 -8
  315. package/dist/model/column-from.js +3 -0
  316. package/dist/model/column-inspect.d.ts +10 -2
  317. package/dist/model/column-inspect.js +9 -0
  318. package/dist/model/column-schema.d.ts +6 -1
  319. package/dist/model/column-state.d.ts +1 -1
  320. package/dist/model/column-types.d.ts +3 -1
  321. package/dist/model/column-types.js +1 -1
  322. package/dist/model/density.js +3 -3
  323. package/dist/model/filter-capabilities.d.ts +1 -1
  324. package/dist/model/filter-capabilities.js +1 -1
  325. package/dist/model/index.d.ts +4 -6
  326. package/dist/model/index.js +0 -1
  327. package/dist/model/preferences.d.ts +7 -7
  328. package/dist/model/preferences.js +0 -1
  329. package/dist/model/prefs-buckets.d.ts +0 -1
  330. package/dist/model/prefs-buckets.js +0 -3
  331. package/dist/model/render-count.d.ts +6 -0
  332. package/dist/model/render-count.js +11 -0
  333. package/dist/provider/ViewsProvider.d.ts +6 -2
  334. package/dist/provider/ViewsProvider.js +12 -2
  335. package/dist/provider/components.d.ts +35 -9
  336. package/dist/provider/components.js +4 -2
  337. package/dist/provider/context.d.ts +8 -4
  338. package/dist/provider/desktop.d.ts +9 -0
  339. package/dist/provider/desktop.js +22 -0
  340. package/dist/provider/menu-groups.d.ts +8 -0
  341. package/dist/provider/menu-groups.js +38 -0
  342. package/dist/provider/plain-input.d.ts +8 -0
  343. package/dist/provider/plain-input.js +5 -0
  344. package/dist/provider/ports.d.ts +22 -0
  345. package/dist/provider/ports.js +1 -0
  346. package/dist/react.d.ts +3 -2
  347. package/dist/react.js +1 -0
  348. package/dist/selection/SelectCheckbox.d.ts +3 -1
  349. package/dist/selection/SelectCheckbox.js +2 -2
  350. package/dist/selection/useCheckDragSelect.js +6 -5
  351. package/docs/contract.md +202 -72
  352. package/docs/getting-started.md +250 -0
  353. package/docs/guides/atoms.md +245 -0
  354. package/docs/guides/cells.md +302 -0
  355. package/docs/guides/columns.md +413 -0
  356. package/docs/guides/display.md +204 -0
  357. package/docs/guides/editors.md +462 -0
  358. package/docs/guides/ports.md +246 -0
  359. package/docs/guides/selection.md +270 -0
  360. package/docs/guides/the-grid.md +696 -0
  361. package/docs/guides/the-provider.md +448 -0
  362. package/docs/index.md +52 -0
  363. package/docs/install.md +9 -47
  364. package/docs/reference/cells.md +28 -0
  365. package/docs/reference/display.md +44 -0
  366. package/docs/reference/editors-chips.md +6 -0
  367. package/docs/reference/editors-date.md +6 -0
  368. package/docs/reference/editors-location.md +10 -0
  369. package/docs/reference/editors-name.md +6 -0
  370. package/docs/reference/editors-number.md +11 -0
  371. package/docs/reference/editors-open-values.md +10 -0
  372. package/docs/reference/editors-panel.md +12 -0
  373. package/docs/reference/editors-range.md +6 -0
  374. package/docs/reference/editors-relation.md +12 -0
  375. package/docs/reference/editors-select.md +9 -0
  376. package/docs/reference/editors-session.md +11 -0
  377. package/docs/reference/editors-text.md +9 -0
  378. package/docs/reference/editors-value-list.md +6 -0
  379. package/docs/reference/editors.md +5 -0
  380. package/docs/reference/field-row.md +16 -0
  381. package/docs/reference/grid.md +39 -0
  382. package/docs/reference/react.md +89 -0
  383. package/docs/reference/selection.md +33 -0
  384. package/docs/reference/views.md +622 -0
  385. package/package.json +27 -4
  386. package/skills/views/SKILL.md +20 -5
  387. package/dist/filters/types.d.ts +0 -27
  388. package/dist/filters/types.js +0 -1
  389. package/dist/model/filter-pushdown.d.ts +0 -106
  390. package/dist/model/filter-pushdown.js +0 -147
@@ -0,0 +1,76 @@
1
+ import { actorKey, actorLabel, isActorValue, relationKey } from "@viewkitjs/fields";
2
+ export function deriveGridSelectValues(columns, rows, opts = {}) {
3
+ const valuesByColumn = {};
4
+ for (const col of columns) {
5
+ const offered = (col.options ?? []).filter((option) => opts.includeArchived || !option.archived);
6
+ if (col.type === "status") {
7
+ valuesByColumn[col.id] = offered.map((option) => option.value);
8
+ continue;
9
+ }
10
+ if (col.type !== "select" && col.type !== "multiselect")
11
+ continue;
12
+ const archived = new Set((col.options ?? []).filter((option) => option.archived).map((option) => option.value));
13
+ const seen = new Set();
14
+ const ordered = [];
15
+ const add = (value) => {
16
+ if (value == null || value === "")
17
+ return;
18
+ const normalized = String(value);
19
+ if (seen.has(normalized))
20
+ return;
21
+ if (!opts.includeArchived && archived.has(normalized))
22
+ return;
23
+ seen.add(normalized);
24
+ ordered.push(normalized);
25
+ };
26
+ for (const option of offered)
27
+ add(option.value);
28
+ if (col.accessor) {
29
+ for (const row of rows) {
30
+ const value = col.accessor(row);
31
+ if (Array.isArray(value))
32
+ value.forEach(add);
33
+ else
34
+ add(value);
35
+ }
36
+ }
37
+ valuesByColumn[col.id] = ordered;
38
+ }
39
+ return valuesByColumn;
40
+ }
41
+ export function deriveGridRelationValues(columns, rows) {
42
+ const valuesByColumn = {};
43
+ for (const col of columns) {
44
+ if ((col.type !== "relation" && col.type !== "user" && col.type !== "actor") || !col.accessor)
45
+ continue;
46
+ const seen = new Set();
47
+ const ordered = [];
48
+ const add = (value) => {
49
+ if (col.type === "actor") {
50
+ if (!isActorValue(value))
51
+ return;
52
+ const key = actorKey(value);
53
+ if (seen.has(key))
54
+ return;
55
+ seen.add(key);
56
+ ordered.push({ id: key, label: actorLabel(value) });
57
+ return;
58
+ }
59
+ const id = relationKey(value);
60
+ if (id == null || seen.has(id))
61
+ return;
62
+ seen.add(id);
63
+ ordered.push(value);
64
+ };
65
+ for (const row of rows) {
66
+ const value = col.accessor(row);
67
+ if (Array.isArray(value))
68
+ value.forEach(add);
69
+ else
70
+ add(value);
71
+ }
72
+ ordered.sort((a, b) => a.label.localeCompare(b.label));
73
+ valuesByColumn[col.id] = ordered;
74
+ }
75
+ return valuesByColumn;
76
+ }
@@ -0,0 +1,41 @@
1
+ import type { FieldSettlement } from "@viewkitjs/fields";
2
+ /** `reload: false`: the commit's own reload is skipped because its caller reloads once after a second
3
+ * write — a board drop under manual order saves the order next, and that reload shows both. */
4
+ export type GridCommitContext = {
5
+ kind: "commit";
6
+ reload?: false;
7
+ } | {
8
+ kind: "restore";
9
+ expected: unknown;
10
+ };
11
+ export type GridCommitOutcome = {
12
+ status: "confirmed";
13
+ history?: false | {
14
+ prev: unknown;
15
+ next: unknown;
16
+ };
17
+ /** `requested`: the row holds the value but its provider has not accepted
18
+ * it yet — the overlay stays and the cell says so (spec §11.2). */
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;
27
+ } | {
28
+ status: "unconfirmed";
29
+ history: false;
30
+ } | {
31
+ status: "failed";
32
+ error?: unknown;
33
+ };
34
+ export type GridCellCommitFn<Row> = (row: Row, columnId: string, value: unknown, context?: GridCommitContext) => Promise<void | GridCommitOutcome>;
35
+ export type GridCellsCommitFn<Row> = (edits: {
36
+ row: Row;
37
+ columnId: string;
38
+ value: unknown;
39
+ context?: GridCommitContext;
40
+ }[]) => Promise<void | GridCommitOutcome[]>;
41
+ export declare function gridCellKey(rowId: string, columnId: string): string;
@@ -0,0 +1,3 @@
1
+ export function gridCellKey(rowId, columnId) {
2
+ return `${rowId}:${columnId}`;
3
+ }
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Stable identity for one cell in the visible grid model.
3
+ *
4
+ * `rowId` here is a row KEY — the identity of a RENDERED row, not of the record
5
+ * behind it. The two differ whenever a row is drawn more than once: grouping by
6
+ * a multi-value column puts a row under each of its values, and every position
7
+ * in the grid (focus, the editor, arrows, a range) has to mean one of those
8
+ * copies rather than "whichever comes first". Writes, the optimistic overlay
9
+ * and selection use the DATA id instead, which is what makes an edit under one
10
+ * tag repaint the same row under the other.
11
+ */
12
+ export type GridCellPos = {
13
+ rowId: string;
14
+ columnId: string;
15
+ };
16
+ /** One rendered row: its position identity and the record behind it. */
17
+ export type GridRowEntry<Row> = {
18
+ key: string;
19
+ rowId: string;
20
+ row: Row;
21
+ };
22
+ /**
23
+ * The key for one rendered row. Composite because the same record legitimately
24
+ * appears under several groups; the separator is a control character so it can
25
+ * never collide with a group label or an id.
26
+ */
27
+ export declare function gridRowKey(groupKey: string, rowId: string): string;
28
+ /**
29
+ * The record a row key points at, read back out of the key itself.
30
+ *
31
+ * Needed because a key can go STALE in a way the record has not: committing a
32
+ * tag moves the row to another group, so `ops␟r1` stops existing while `r1` is
33
+ * still very much in the list. Anything asking "did this row actually leave"
34
+ * has to ask about the record, and by then the index no longer holds the old
35
+ * key to resolve it through — the key is the only thing left that knows.
36
+ */
37
+ export declare function gridRowIdFromKey(key: string): string;
38
+ /** Inclusive rectangle in visible row/column index space. */
39
+ export type GridCellRect = {
40
+ r1: number;
41
+ r2: number;
42
+ c1: number;
43
+ c2: number;
44
+ };
45
+ /** Resolve two id-based endpoints against the current visible order. */
46
+ export declare function resolveCellRect(anchor: GridCellPos, head: GridCellPos, visibleRowIds: readonly string[], visibleColIds: readonly string[]): GridCellRect | null;
47
+ export declare function gridRectIsMulti(rect: GridCellRect): boolean;
48
+ export declare function gridRectContains(rect: GridCellRect, rowIdx: number, colIdx: number): boolean;
@@ -0,0 +1,27 @@
1
+ export function gridRowKey(groupKey, rowId) {
2
+ return `${groupKey}\u241F${rowId}`;
3
+ }
4
+ export function gridRowIdFromKey(key) {
5
+ const separator = key.lastIndexOf("\u241F");
6
+ return separator < 0 ? key : key.slice(separator + 1);
7
+ }
8
+ export function resolveCellRect(anchor, head, visibleRowIds, visibleColIds) {
9
+ const ar = visibleRowIds.indexOf(anchor.rowId);
10
+ const hr = visibleRowIds.indexOf(head.rowId);
11
+ const ac = visibleColIds.indexOf(anchor.columnId);
12
+ const hc = visibleColIds.indexOf(head.columnId);
13
+ if (ar < 0 || hr < 0 || ac < 0 || hc < 0)
14
+ return null;
15
+ return {
16
+ r1: Math.min(ar, hr),
17
+ r2: Math.max(ar, hr),
18
+ c1: Math.min(ac, hc),
19
+ c2: Math.max(ac, hc),
20
+ };
21
+ }
22
+ export function gridRectIsMulti(rect) {
23
+ return rect.r1 !== rect.r2 || rect.c1 !== rect.c2;
24
+ }
25
+ export function gridRectContains(rect, rowIdx, colIdx) {
26
+ return rowIdx >= rect.r1 && rowIdx <= rect.r2 && colIdx >= rect.c1 && colIdx <= rect.c2;
27
+ }
@@ -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
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Commit payload shared by the number editor, clipboard, fill, and history.
3
+ *
4
+ * Defined as `NumberCommit` in `@viewkitjs/fields`
5
+ * (`packages/viewkit/fields/src/types.ts`) and re-exported here under the
6
+ * grid's own name (and from `grid/index.ts`), so the shape has exactly
7
+ * one definition.
8
+ */
9
+ export type { NumberCommit as GridNumberEditValue } from "@viewkitjs/fields";
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,60 @@
1
+ import { type GridCellCommitFn, type GridCellsCommitFn } from "./commit-model.js";
2
+ import type { GridCellPos } from "./coordinates.js";
3
+ import { type GridCommitCell, type GridSettlementByRow } from "./editing-model.js";
4
+ export type GridEditingCallbacks<Row> = {
5
+ onCellCommit?: GridCellCommitFn<Row>;
6
+ onCellsCommit?: GridCellsCommitFn<Row>;
7
+ };
8
+ type ResolveRow<Row> = (rowId: string) => Row | undefined;
9
+ /**
10
+ * Dependency-neutral asynchronous controller for optimistic commits and
11
+ * history. React owns focus/editor state; this class owns ordering guarantees.
12
+ */
13
+ export declare class GridEditingController<Row> {
14
+ private callbacks;
15
+ /** Fired with every overlay change: the values by row, and beside them the
16
+ * cells whose write is only `requested` of its provider (spec §11.2). */
17
+ private readonly onPendingChange;
18
+ private history;
19
+ private pending;
20
+ private readonly inflight;
21
+ private applyChain;
22
+ private nextHistoryId;
23
+ private nextPendingRevision;
24
+ constructor(callbacks: GridEditingCallbacks<Row>,
25
+ /** Fired with every overlay change: the values by row, and beside them the
26
+ * cells whose write is only `requested` of its provider (spec §11.2). */
27
+ onPendingChange: (pendingByRow: ReadonlyMap<string, Record<string, unknown>>, settlementByRow: GridSettlementByRow) => void);
28
+ setCallbacks(callbacks: GridEditingCallbacks<Row>): void;
29
+ canUndo(): boolean;
30
+ canRedo(): boolean;
31
+ getPendingByRow(): ReadonlyMap<string, Record<string, unknown>>;
32
+ /**
33
+ * Resolves TRUE once every cell has landed on the server, false if any
34
+ * failed (those overlays are already rolled back by then). Callers that own
35
+ * user-facing confirmation — a batch bar reporting "12 updated" — await it;
36
+ * the editors ignore it, because an optimistic edit's feedback is the cell
37
+ * itself. Nothing to write (every cell already held its target value) counts
38
+ * as success: a caller awaiting this should confirm, not report a failure.
39
+ */
40
+ commit(cells: GridCommitCell<Row>[]): Promise<boolean>;
41
+ reconcile(matchedKeys: readonly string[]): void;
42
+ undo(resolveRow: ResolveRow<Row>, onApply?: (pos: GridCellPos) => void): boolean;
43
+ redo(resolveRow: ResolveRow<Row>, onApply?: (pos: GridCellPos) => void): boolean;
44
+ private publishPending;
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. */
47
+ private settle;
48
+ /** Is a write for this cell still in flight? Reconciliation asks, so it can
49
+ * tell "the refetch hasn't caught up yet" apart from "the server disagrees". */
50
+ hasInflight(rowId: string, columnId: string): boolean;
51
+ /** What this cell held before the pending write. Reconciliation asks, so it
52
+ * can tell a value the SERVER normalised apart from one somebody else set. */
53
+ pendingBaseline(rowId: string, columnId: string): unknown;
54
+ private registerInflight;
55
+ private perform;
56
+ private performBatch;
57
+ private inflightFor;
58
+ private enqueueApply;
59
+ }
60
+ export {};
@@ -0,0 +1,266 @@
1
+ import { gridCellKey, } from "./commit-model.js";
2
+ import { applyGridPending, beginGridHistoryApply, createGridHistory, gridEditValue, gridHistoryValue, groupGridPendingByRow, groupGridPendingSettlement, keepGridPending, markGridPendingSettlement, planGridPendingAssignments, pruneGridHistoryEntry, reconcileGridPending, recordGridHistory, rollbackGridPending, settleGridHistoryApply, } from "./editing-model.js";
3
+ const confirmed = (outcome) => outcome ?? { status: "confirmed" };
4
+ export class GridEditingController {
5
+ callbacks;
6
+ onPendingChange;
7
+ history = createGridHistory();
8
+ pending = new Map();
9
+ inflight = new Map();
10
+ applyChain = Promise.resolve();
11
+ nextHistoryId = 1;
12
+ nextPendingRevision = 1;
13
+ constructor(callbacks, onPendingChange) {
14
+ this.callbacks = callbacks;
15
+ this.onPendingChange = onPendingChange;
16
+ }
17
+ setCallbacks(callbacks) {
18
+ this.callbacks = callbacks;
19
+ }
20
+ canUndo() {
21
+ return this.history.undo.length > 0;
22
+ }
23
+ canRedo() {
24
+ return this.history.redo.length > 0;
25
+ }
26
+ getPendingByRow() {
27
+ return groupGridPendingByRow(this.pending);
28
+ }
29
+ commit(cells) {
30
+ if (cells.length === 0)
31
+ return Promise.resolve(true);
32
+ const entry = {
33
+ id: this.nextHistoryId++,
34
+ edits: cells.map(({ cell }) => cell),
35
+ };
36
+ this.history = recordGridHistory(this.history, entry);
37
+ return this.performBatch(cells, "next", "commit").then((results) => {
38
+ const successes = results.map((result) => result.status === "confirmed");
39
+ entry.edits = entry.edits.map((cell, index) => {
40
+ const result = results[index];
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;
47
+ });
48
+ this.history = pruneGridHistoryEntry(this.history, entry.id, successes.map((ok, index) => {
49
+ const result = results[index];
50
+ return ok && result?.status === "confirmed" && result.history !== false;
51
+ }));
52
+ const ok = successes.every(Boolean);
53
+ return ok;
54
+ });
55
+ }
56
+ reconcile(matchedKeys) {
57
+ if (matchedKeys.length === 0)
58
+ return;
59
+ const next = reconcileGridPending(this.pending, matchedKeys);
60
+ if (next.size === this.pending.size)
61
+ return;
62
+ this.publishPending(next);
63
+ }
64
+ undo(resolveRow, onApply) {
65
+ if (!this.canUndo())
66
+ return false;
67
+ this.enqueueApply("undo", resolveRow, onApply);
68
+ return true;
69
+ }
70
+ redo(resolveRow, onApply) {
71
+ if (!this.canRedo())
72
+ return false;
73
+ this.enqueueApply("redo", resolveRow, onApply);
74
+ return true;
75
+ }
76
+ publishPending(next) {
77
+ this.pending = next;
78
+ this.onPendingChange(groupGridPendingByRow(next), groupGridPendingSettlement(next));
79
+ }
80
+ settle(keys, results, assignments) {
81
+ const storedByKey = new Map();
82
+ const requested = new Set();
83
+ keys.forEach((key, index) => {
84
+ const result = results[index];
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);
98
+ const owned = assignments.filter((assignment) => requested.has(assignment.key));
99
+ if (owned.length > 0)
100
+ next = markGridPendingSettlement(next, owned, "requested");
101
+ if (next !== this.pending)
102
+ this.publishPending(next);
103
+ }
104
+ hasInflight(rowId, columnId) {
105
+ return (this.inflight.get(gridCellKey(rowId, columnId))?.size ?? 0) > 0;
106
+ }
107
+ pendingBaseline(rowId, columnId) {
108
+ return this.pending.get(gridCellKey(rowId, columnId))?.baseline;
109
+ }
110
+ registerInflight(keys, promise) {
111
+ for (const key of keys) {
112
+ const promises = this.inflight.get(key) ?? new Set();
113
+ promises.add(promise);
114
+ this.inflight.set(key, promises);
115
+ }
116
+ void promise.finally(() => {
117
+ for (const key of keys) {
118
+ const promises = this.inflight.get(key);
119
+ promises?.delete(promise);
120
+ if (promises?.size === 0)
121
+ this.inflight.delete(key);
122
+ }
123
+ });
124
+ }
125
+ perform(row, rowId, columnId, value, overlay, baseline, context = "commit") {
126
+ const { onCellCommit } = this.callbacks;
127
+ if (!onCellCommit)
128
+ return Promise.resolve({ status: "failed" });
129
+ const key = gridCellKey(rowId, columnId);
130
+ const assignments = overlay
131
+ ? [{ key, value, baseline, revision: this.nextPendingRevision++ }]
132
+ : [];
133
+ if (assignments.length > 0) {
134
+ this.publishPending(applyGridPending(this.pending, assignments));
135
+ }
136
+ let commit;
137
+ try {
138
+ commit = Promise.resolve(context === "restore"
139
+ ? onCellCommit(row, columnId, value, { kind: "restore", expected: baseline })
140
+ : onCellCommit(row, columnId, value));
141
+ }
142
+ catch (error) {
143
+ commit = Promise.reject(error);
144
+ }
145
+ const promise = commit.then((outcome) => {
146
+ const result = confirmed(outcome);
147
+ this.settle([key], [result], assignments);
148
+ return result;
149
+ }, (error) => {
150
+ if (assignments.length > 0) {
151
+ this.publishPending(rollbackGridPending(this.pending, assignments));
152
+ }
153
+ return { status: "failed", error };
154
+ });
155
+ this.registerInflight([key], promise);
156
+ return promise;
157
+ }
158
+ performBatch(cells, side, context) {
159
+ if (cells.length === 0)
160
+ return Promise.resolve([]);
161
+ const { onCellsCommit } = this.callbacks;
162
+ if (cells.length === 1 || !onCellsCommit) {
163
+ return Promise.all(cells.map(({ row, cell }) => this.perform(row, cell.rowId, cell.columnId, context === "restore" ? gridHistoryValue(cell, side) : gridEditValue(cell, side), context === "restore" ? false : cell.overlay, context === "restore"
164
+ ? gridHistoryValue(cell, side === "next" ? "prev" : "next")
165
+ : gridEditValue(cell, side === "next" ? "prev" : "next"), context)));
166
+ }
167
+ const assignments = context === "restore"
168
+ ? []
169
+ : planGridPendingAssignments(cells, side, this.nextPendingRevision++);
170
+ if (assignments.length > 0) {
171
+ this.publishPending(applyGridPending(this.pending, assignments));
172
+ }
173
+ let commit;
174
+ try {
175
+ commit = Promise.resolve(onCellsCommit(cells.map(({ row, cell }) => ({
176
+ row,
177
+ columnId: cell.columnId,
178
+ value: context === "restore" ? gridHistoryValue(cell, side) : gridEditValue(cell, side),
179
+ ...(context === "restore"
180
+ ? {
181
+ context: {
182
+ kind: "restore",
183
+ expected: gridHistoryValue(cell, side === "next" ? "prev" : "next"),
184
+ },
185
+ }
186
+ : {}),
187
+ }))));
188
+ }
189
+ catch (error) {
190
+ commit = Promise.reject(error);
191
+ }
192
+ const promise = commit.then((outcomes) => {
193
+ const results = outcomes?.map((outcome) => confirmed(outcome)) ??
194
+ cells.map(() => ({ status: "confirmed" }));
195
+ const failedKeys = new Set(cells
196
+ .filter((_, index) => results[index]?.status === "failed")
197
+ .map(({ cell }) => gridCellKey(cell.rowId, cell.columnId)));
198
+ if (failedKeys.size > 0) {
199
+ this.publishPending(rollbackGridPending(this.pending, assignments.filter((assignment) => failedKeys.has(assignment.key))));
200
+ }
201
+ const settled = cells.map((_, index) => results[index] ?? { status: "failed" });
202
+ this.settle(cells.map(({ cell }) => gridCellKey(cell.rowId, cell.columnId)), settled, assignments);
203
+ return settled;
204
+ }, (error) => {
205
+ const carried = error && typeof error === "object" && "outcomes" in error && Array.isArray(error.outcomes)
206
+ ? error.outcomes
207
+ : null;
208
+ if (carried?.length === cells.length) {
209
+ const failedKeys = new Set(cells
210
+ .filter((_, index) => carried[index]?.status === "failed")
211
+ .map(({ cell }) => gridCellKey(cell.rowId, cell.columnId)));
212
+ if (failedKeys.size > 0) {
213
+ this.publishPending(rollbackGridPending(this.pending, assignments.filter((assignment) => failedKeys.has(assignment.key))));
214
+ }
215
+ return carried;
216
+ }
217
+ if (assignments.length > 0) {
218
+ this.publishPending(rollbackGridPending(this.pending, assignments));
219
+ }
220
+ return cells.map(() => ({ status: "failed", error }));
221
+ });
222
+ this.registerInflight(cells.map(({ cell }) => gridCellKey(cell.rowId, cell.columnId)), promise);
223
+ return promise;
224
+ }
225
+ inflightFor(entry) {
226
+ const promises = new Set();
227
+ for (const cell of entry.edits) {
228
+ for (const promise of this.inflight.get(gridCellKey(cell.rowId, cell.columnId)) ?? []) {
229
+ promises.add(promise);
230
+ }
231
+ }
232
+ return [...promises];
233
+ }
234
+ enqueueApply(kind, resolveRow, onApply) {
235
+ this.applyChain = this.applyChain.then(async () => {
236
+ const source = kind === "undo" ? this.history.undo : this.history.redo;
237
+ const candidate = source[source.length - 1];
238
+ if (!candidate)
239
+ return;
240
+ const inflight = this.inflightFor(candidate);
241
+ if (inflight.length > 0)
242
+ await Promise.allSettled(inflight);
243
+ const begun = beginGridHistoryApply(this.history, kind);
244
+ this.history = begun.state;
245
+ const entry = begun.entry;
246
+ if (!entry || entry.edits.length === 0)
247
+ return;
248
+ const first = entry.edits[0];
249
+ onApply?.({ rowId: first.rowId, columnId: first.columnId });
250
+ const cells = entry.edits.map((cell) => ({
251
+ row: resolveRow(cell.rowId) ?? cell.rowSnapshot,
252
+ cell,
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
+ });
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));
263
+ this.history = settleGridHistoryApply(this.history, kind, entry, results.every((result) => result.status === "confirmed"));
264
+ });
265
+ }
266
+ }
@@ -0,0 +1,87 @@
1
+ import { type FieldSettlement } from "@viewkitjs/fields";
2
+ export type GridEditCell<Row> = {
3
+ rowId: string;
4
+ columnId: string;
5
+ prev: unknown;
6
+ next: unknown;
7
+ /** Opaque reversible snapshots, distinct from editor values. */
8
+ historyPrev?: unknown;
9
+ historyNext?: unknown;
10
+ overlay: boolean;
11
+ rowSnapshot: Row;
12
+ };
13
+ export type GridCommitCell<Row> = {
14
+ row: Row;
15
+ cell: GridEditCell<Row>;
16
+ };
17
+ export type GridHistoryEntry<Row> = {
18
+ id: number;
19
+ edits: GridEditCell<Row>[];
20
+ };
21
+ export type GridHistoryState<Row> = {
22
+ undo: GridHistoryEntry<Row>[];
23
+ redo: GridHistoryEntry<Row>[];
24
+ };
25
+ export type GridHistoryKind = "undo" | "redo";
26
+ export declare function createGridHistory<Row>(): GridHistoryState<Row>;
27
+ export declare function prepareGridCommitCells<Row>(edits: readonly (GridEditCell<Row> & {
28
+ row: Row;
29
+ })[]): GridCommitCell<Row>[];
30
+ export declare function recordGridHistory<Row>(state: GridHistoryState<Row>, entry: GridHistoryEntry<Row>, maxEntries?: number): GridHistoryState<Row>;
31
+ /** Remove failed cells from an entry wherever it currently lives. */
32
+ export declare function pruneGridHistoryEntry<Row>(state: GridHistoryState<Row>, entryId: number, successes: readonly boolean[]): GridHistoryState<Row>;
33
+ export declare function beginGridHistoryApply<Row>(state: GridHistoryState<Row>, kind: GridHistoryKind): {
34
+ state: GridHistoryState<Row>;
35
+ entry: GridHistoryEntry<Row> | null;
36
+ };
37
+ export declare function settleGridHistoryApply<Row>(state: GridHistoryState<Row>, kind: GridHistoryKind, entry: GridHistoryEntry<Row>, success: boolean): GridHistoryState<Row>;
38
+ export declare function gridEditValue<Row>(cell: GridEditCell<Row>, side: "next" | "prev"): unknown;
39
+ export declare function gridHistoryValue<Row>(cell: GridEditCell<Row>, side: "next" | "prev"): unknown;
40
+ export type GridPendingEntry = {
41
+ value: unknown;
42
+ revision: number;
43
+ /**
44
+ * What the cell held BEFORE this write — the other side of the same edit.
45
+ *
46
+ * Carried so reconciliation can tell three cases apart that all look
47
+ * identical from the value alone: our write landed, our write is simply
48
+ * behind, or somebody else wrote a third value while ours was in flight.
49
+ * Without the baseline the last one is indistinguishable from the server
50
+ * normalising what we sent.
51
+ */
52
+ baseline?: unknown;
53
+ /**
54
+ * Set once the write has LANDED locally but its provider has not accepted it
55
+ * (spec §11.2). The overlay is kept — the value is real — and the cell draws
56
+ * the pending state until reconciliation finds the refetched row carrying it.
57
+ */
58
+ settlement?: Extract<FieldSettlement, "requested">;
59
+ };
60
+ type GridPendingState = ReadonlyMap<string, GridPendingEntry>;
61
+ export type GridSettlementByRow = ReadonlyMap<string, Record<string, "requested">>;
62
+ export type GridPendingAssignment = {
63
+ key: string;
64
+ value: unknown;
65
+ revision: number;
66
+ baseline?: unknown;
67
+ };
68
+ export declare function planGridPendingAssignments<Row>(cells: readonly GridCommitCell<Row>[], side: "next" | "prev", revision: number): GridPendingAssignment[];
69
+ export declare function applyGridPending(state: GridPendingState, assignments: readonly GridPendingAssignment[]): Map<string, GridPendingEntry>;
70
+ /** Roll back only values still owned by this commit; a later overlap survives. */
71
+ export declare function rollbackGridPending(state: GridPendingState, assignments: readonly GridPendingAssignment[]): Map<string, GridPendingEntry>;
72
+ /** Mark the overlays a `requested` outcome still owns; a later overlap is left alone. */
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>;
83
+ export declare function reconcileGridPending(state: GridPendingState, matchedKeys: readonly string[]): Map<string, GridPendingEntry>;
84
+ export declare function groupGridPendingByRow(state: GridPendingState): ReadonlyMap<string, Record<string, unknown>>;
85
+ /** The `requested` overlays only, by row — what the cell reads to draw its pending state. */
86
+ export declare function groupGridPendingSettlement(state: GridPendingState): GridSettlementByRow;
87
+ export {};