viewkitjs 0.38.0 → 0.40.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 (309) hide show
  1. package/CHANGELOG.md +134 -0
  2. package/MIGRATION.md +32 -0
  3. package/fields/dist/derived.d.ts +7 -0
  4. package/fields/dist/derived.js +4 -0
  5. package/fields/dist/index.d.ts +1 -1
  6. package/fields/dist/index.js +1 -1
  7. package/fields/dist/messages.d.ts +5 -1
  8. package/fields/dist/messages.js +3 -0
  9. package/fields/dist/query/evaluate.d.ts +7 -1
  10. package/fields/dist/query/evaluate.js +8 -5
  11. package/fields/dist/query/figure-kinds.d.ts +2 -2
  12. package/fields/dist/query/figure-kinds.js +3 -0
  13. package/fields/dist/query/figures.d.ts +5 -3
  14. package/fields/dist/query/figures.js +13 -0
  15. package/fields/dist/query/filter.d.ts +7 -0
  16. package/fields/dist/query/filter.js +7 -1
  17. package/fields/dist/query/kit.d.ts +3 -2
  18. package/fields/dist/query/kit.js +1 -1
  19. package/fields/dist/query/layer.d.ts +6 -0
  20. package/fields/dist/query/layer.js +3 -0
  21. package/fields/dist/query/number.d.ts +3 -2
  22. package/fields/dist/query/number.js +5 -3
  23. package/fields/dist/query/read-rule.d.ts +1 -1
  24. package/fields/dist/query/read-rule.js +3 -0
  25. package/fields/docs/guides/queries.md +28 -24
  26. package/fields/docs/reference/fields.md +1 -0
  27. package/fields/docs/reference/query.md +9 -7
  28. package/package.json +2 -4
  29. package/postgres/dist/check.js +3 -1
  30. package/postgres/dist/definitions/storage.d.ts +3 -1
  31. package/postgres/dist/definitions/storage.js +3 -1
  32. package/postgres/dist/definitions/stored.js +13 -2
  33. package/postgres/dist/map.d.ts +5 -1
  34. package/postgres/dist/map.js +4 -0
  35. package/postgres/dist/records.js +6 -1
  36. package/postgres/docs/guides/definitions.md +1 -1
  37. package/postgres/docs/guides/field-map.md +3 -3
  38. package/postgres/docs/reference/postgres.md +1 -1
  39. package/views/dist/atoms/HeaderChrome.d.ts +7 -0
  40. package/views/dist/atoms/HeaderChrome.js +15 -0
  41. package/views/dist/atoms/ToolbarButton.d.ts +1 -1
  42. package/views/dist/atoms/ToolbarButton.js +2 -2
  43. package/views/dist/atoms/defaults.js +4 -0
  44. package/views/dist/atoms/types.d.ts +39 -2
  45. package/views/dist/contract.d.ts +38 -9
  46. package/views/dist/contract.js +64 -6
  47. package/views/dist/controls/avatar.css +1 -1
  48. package/views/dist/controls/customize/map-customize-body.js +1 -1
  49. package/views/dist/controls/field/field.d.ts +2 -14
  50. package/views/dist/controls/field/field.js +4 -9
  51. package/views/dist/controls/field/looks.d.ts +1 -1
  52. package/views/dist/controls/field/looks.js +7 -3
  53. package/views/dist/controls/field/tokens.d.ts +4 -0
  54. package/views/dist/controls/field/tokens.js +1 -0
  55. package/views/dist/controls/field.css +33 -0
  56. package/views/dist/controls/filter-editor/block.d.ts +3 -1
  57. package/views/dist/controls/filter-editor/block.js +4 -3
  58. package/views/dist/controls/filter-editor/filter-editor.d.ts +15 -2
  59. package/views/dist/controls/filter-editor/filter-editor.js +49 -16
  60. package/views/dist/controls/filter-editor/how.d.ts +11 -1
  61. package/views/dist/controls/filter-editor/map-filter-body.d.ts +4 -2
  62. package/views/dist/controls/filter-editor/map-filter-body.js +21 -11
  63. package/views/dist/controls/filter-editor/map-rules.d.ts +6 -4
  64. package/views/dist/controls/filter-editor/map-rules.js +7 -4
  65. package/views/dist/controls/filter-editor/parts.d.ts +14 -1
  66. package/views/dist/controls/filter-editor/parts.js +14 -0
  67. package/views/dist/controls/filter-editor.css +4 -1
  68. package/views/dist/controls/index.d.ts +0 -3
  69. package/views/dist/controls/index.js +0 -3
  70. package/views/dist/controls/input.css +1 -1
  71. package/views/dist/controls/internal/menu-items.d.ts +2 -0
  72. package/views/dist/controls/internal/menu-items.js +1 -1
  73. package/views/dist/controls/internal/part-slot.d.ts +1 -1
  74. package/views/dist/controls/internal/part-slot.js +1 -1
  75. package/views/dist/controls/internal/row-actions.d.ts +33 -0
  76. package/views/dist/controls/internal/row-actions.js +28 -0
  77. package/views/dist/controls/menu/map-menu.js +1 -1
  78. package/views/dist/controls/menu-list.css +1 -1
  79. package/views/dist/controls/picker/looks.d.ts +1 -1
  80. package/views/dist/controls/picker.css +2 -2
  81. package/views/dist/controls/popover/map-popover.d.ts +1 -1
  82. package/views/dist/controls/popover/map-popover.js +2 -2
  83. package/views/dist/controls/press.css +0 -1
  84. package/views/dist/controls/radio/radio.d.ts +1 -1
  85. package/views/dist/controls/radio/radio.js +1 -16
  86. package/views/dist/controls/sheet/bottom-sheet.d.ts +2 -2
  87. package/views/dist/controls/sheet/bottom-sheet.js +31 -24
  88. package/views/dist/controls/sheet/map-sheet.js +9 -6
  89. package/views/dist/controls/sort-editor/map-sort-body.js +1 -0
  90. package/views/dist/controls/sort-editor/sort-editor.d.ts +5 -1
  91. package/views/dist/controls/sort-editor/sort-editor.js +41 -13
  92. package/views/dist/controls/text-editor.css +22 -0
  93. package/views/dist/controls/tokens.js +0 -6
  94. package/views/dist/controls/toolbar/toolbar.js +2 -2
  95. package/views/dist/controls/toolbar-button/atom-toolbar-button.d.ts +1 -1
  96. package/views/dist/controls/toolbar-button/atom-toolbar-button.js +2 -2
  97. package/views/dist/editors/EditorPanel.js +1 -1
  98. package/views/dist/field-row/FieldRow.js +38 -16
  99. package/views/dist/field-row/editors/RowChipsEditor.js +3 -1
  100. package/views/dist/field-row/editors/RowDateEditor.js +3 -1
  101. package/views/dist/field-row/editors/RowNameEditor.js +3 -1
  102. package/views/dist/field-row/editors/RowPlaceEditor.js +4 -2
  103. package/views/dist/field-row/editors/RowRangeEditor.js +3 -1
  104. package/views/dist/field-row/editors/RowRelationEditor.js +5 -2
  105. package/views/dist/field-row/editors/RowSelectEditor.js +3 -1
  106. package/views/dist/field-row/editors/RowTextEditor.d.ts +7 -1
  107. package/views/dist/field-row/editors/RowTextEditor.js +28 -4
  108. package/views/dist/field-row/editors/RowValueListEditor.js +4 -4
  109. package/views/dist/field-row/editors/row-place.d.ts +33 -0
  110. package/views/dist/field-row/editors/row-place.js +141 -0
  111. package/views/dist/field-row/field-row-button.d.ts +9 -6
  112. package/views/dist/field-row/field-row-button.js +3 -3
  113. package/views/dist/field-row/row-target.d.ts +4 -1
  114. package/views/dist/field-row/row-target.js +1 -1
  115. package/views/dist/filters/duration-bound.d.ts +7 -0
  116. package/views/dist/filters/duration-bound.js +9 -0
  117. package/views/dist/filters/filter-model.d.ts +4 -0
  118. package/views/dist/filters/number-refused.d.ts +8 -0
  119. package/views/dist/filters/number-refused.js +4 -0
  120. package/views/dist/grid/chrome/GridAggregateMenu.d.ts +12 -11
  121. package/views/dist/grid/chrome/GridAggregateMenu.js +4 -3
  122. package/views/dist/grid/chrome/GridFooter.d.ts +12 -4
  123. package/views/dist/grid/chrome/GridFooter.js +11 -9
  124. package/views/dist/grid/chrome/GridHeader.js +4 -3
  125. package/views/dist/grid/chrome/GridResizeHandle.d.ts +7 -3
  126. package/views/dist/grid/chrome/GridResizeHandle.js +2 -3
  127. package/views/dist/grid/chrome/GridTable.js +1 -1
  128. package/views/dist/grid/chrome/GridTableSurface.js +1 -1
  129. package/views/dist/grid/chrome/grid-body-place.d.ts +2 -4
  130. package/views/dist/grid/chrome/grid-body-place.js +4 -5
  131. package/views/dist/grid/chrome/grid-figure-value.js +10 -4
  132. package/views/dist/grid/chrome/grid-table-props.d.ts +15 -4
  133. package/views/dist/grid/chrome/useGridTableInteractionModel.js +12 -2
  134. package/views/dist/grid/core/clipboard-model.js +42 -8
  135. package/views/dist/grid/core/commit-model.d.ts +3 -0
  136. package/views/dist/grid/core/editing-controller.d.ts +29 -1
  137. package/views/dist/grid/core/editing-controller.js +142 -12
  138. package/views/dist/grid/core/pending-reconciliation.d.ts +14 -0
  139. package/views/dist/grid/core/pending-reconciliation.js +20 -8
  140. package/views/dist/grid/core/save-path.d.ts +4 -2
  141. package/views/dist/grid/core/save-path.js +1 -1
  142. package/views/dist/grid/core/spreadsheet-operations.js +43 -5
  143. package/views/dist/grid/core/useGridEditing.d.ts +5 -1
  144. package/views/dist/grid/core/useGridEditing.js +4 -4
  145. package/views/dist/grid/core/written-alongside.d.ts +16 -0
  146. package/views/dist/grid/core/written-alongside.js +30 -0
  147. package/views/dist/grid/grid.css +8 -4
  148. package/views/dist/grid/index.d.ts +1 -1
  149. package/views/dist/grid/looks.d.ts +2 -2
  150. package/views/dist/internal/before-paint.d.ts +5 -0
  151. package/views/dist/internal/before-paint.js +17 -0
  152. package/views/dist/internal/field-rows.d.ts +0 -8
  153. package/views/dist/internal/field-rows.js +1 -3
  154. package/views/dist/internal/over-cell.d.ts +8 -0
  155. package/views/dist/internal/over-cell.js +5 -0
  156. package/views/dist/list/bar-keys.d.ts +8 -0
  157. package/views/dist/list/bar-keys.js +3 -0
  158. package/views/dist/list/bar-parts.d.ts +27 -0
  159. package/views/dist/list/bar-parts.js +38 -0
  160. package/views/dist/list/buttons/clear-save.d.ts +7 -0
  161. package/views/dist/list/buttons/clear-save.js +19 -0
  162. package/views/dist/list/buttons/customize.d.ts +28 -0
  163. package/views/dist/list/buttons/customize.js +31 -0
  164. package/views/dist/list/buttons/filter.d.ts +32 -0
  165. package/views/dist/list/buttons/filter.js +60 -0
  166. package/views/dist/list/buttons/new.d.ts +18 -0
  167. package/views/dist/list/buttons/new.js +21 -0
  168. package/views/dist/list/buttons/quick.d.ts +15 -0
  169. package/views/dist/list/buttons/quick.js +24 -0
  170. package/views/dist/list/buttons/search.d.ts +18 -0
  171. package/views/dist/list/buttons/search.js +17 -0
  172. package/views/dist/list/buttons/shared.d.ts +97 -0
  173. package/views/dist/list/buttons/shared.js +137 -0
  174. package/views/dist/list/buttons/sort-filter.d.ts +6 -0
  175. package/views/dist/list/buttons/sort-filter.js +16 -0
  176. package/views/dist/list/buttons/sort.d.ts +17 -0
  177. package/views/dist/list/buttons/sort.js +34 -0
  178. package/views/dist/list/buttons/views.d.ts +21 -0
  179. package/views/dist/list/buttons/views.js +38 -0
  180. package/views/dist/list/editor-menus.d.ts +13 -0
  181. package/views/dist/list/editor-menus.js +13 -0
  182. package/views/dist/list/edits.d.ts +3 -1
  183. package/views/dist/list/index.d.ts +41 -0
  184. package/views/dist/list/index.js +19 -0
  185. package/views/dist/list/layer.d.ts +13 -3
  186. package/views/dist/list/layer.js +13 -3
  187. package/views/dist/list/line.d.ts +58 -0
  188. package/views/dist/list/line.js +229 -0
  189. package/views/dist/list/list.d.ts +7 -1
  190. package/views/dist/list/list.js +2 -2
  191. package/views/dist/list/pane-box.d.ts +6 -0
  192. package/views/dist/list/pane-box.js +15 -0
  193. package/views/dist/list/panels/customize.d.ts +8 -0
  194. package/views/dist/list/panels/customize.js +23 -0
  195. package/views/dist/list/panels/filter-bar.d.ts +12 -0
  196. package/views/dist/list/panels/filter-bar.js +73 -0
  197. package/views/dist/list/panels/filter.d.ts +8 -0
  198. package/views/dist/list/panels/filter.js +23 -0
  199. package/views/dist/list/panels/quick.d.ts +7 -0
  200. package/views/dist/list/panels/quick.js +16 -0
  201. package/views/dist/list/panels/shared.d.ts +26 -0
  202. package/views/dist/list/panels/shared.js +36 -0
  203. package/views/dist/list/panels/sort.d.ts +8 -0
  204. package/views/dist/list/panels/sort.js +19 -0
  205. package/views/dist/list/panels/views.d.ts +13 -0
  206. package/views/dist/list/panels/views.js +27 -0
  207. package/views/dist/list/ready.d.ts +35 -0
  208. package/views/dist/list/ready.js +7 -0
  209. package/views/dist/list/root-base.d.ts +19 -1
  210. package/views/dist/list/root-base.js +13 -3
  211. package/views/dist/list/root.d.ts +1 -1
  212. package/views/dist/list/root.js +2 -2
  213. package/views/dist/list/store.d.ts +29 -0
  214. package/views/dist/list/store.js +48 -2
  215. package/views/dist/list/toolbar-model.d.ts +99 -0
  216. package/views/dist/list/toolbar-model.js +195 -0
  217. package/views/dist/list/toolbar.js +142 -329
  218. package/views/dist/list/views-axis.js +15 -4
  219. package/views/dist/list/views.d.ts +1 -1
  220. package/views/dist/list/views.js +4 -1
  221. package/views/dist/looks/index.d.ts +0 -1
  222. package/views/dist/looks/index.js +0 -1
  223. package/views/dist/looks/looks.d.ts +1 -1
  224. package/views/dist/looks/pieces.js +0 -2
  225. package/views/dist/model/aggregates.d.ts +18 -8
  226. package/views/dist/model/aggregates.js +16 -22
  227. package/views/dist/model/column-filters.js +10 -3
  228. package/views/dist/model/view-rules.js +1 -0
  229. package/views/dist/panels/filter/NumberFilterBody.js +6 -8
  230. package/views/dist/panels/labels.js +7 -2
  231. package/views/dist/panels/model.d.ts +3 -0
  232. package/views/dist/panels/react/filter/FilterEditor.d.ts +3 -1
  233. package/views/dist/panels/react/filter/FilterEditor.js +2 -2
  234. package/views/dist/panels/react/filter/filter-body.d.ts +3 -1
  235. package/views/dist/panels/react/filter/filter-body.js +7 -3
  236. package/views/dist/panels/react/sort/SortEditor.d.ts +3 -1
  237. package/views/dist/panels/react/sort/SortEditor.js +4 -4
  238. package/views/dist/panels/react/toolbar/Toolbar.d.ts +80 -3
  239. package/views/dist/panels/react/toolbar/Toolbar.js +85 -52
  240. package/views/dist/panels/react/toolbar/ToolbarBarSorts.d.ts +9 -0
  241. package/views/dist/panels/react/toolbar/ToolbarBarSorts.js +84 -0
  242. package/views/dist/panels/react/toolbar/ToolbarButton.d.ts +1 -1
  243. package/views/dist/panels/react/toolbar/ToolbarButton.js +5 -3
  244. package/views/dist/panels/react/toolbar/ToolbarFilterAdd.d.ts +4 -1
  245. package/views/dist/panels/react/toolbar/ToolbarFilterAdd.js +2 -2
  246. package/views/dist/panels/react/toolbar/ToolbarOptions.d.ts +30 -0
  247. package/views/dist/panels/react/toolbar/ToolbarOptions.js +6 -1
  248. package/views/dist/panels/react/toolbar/ToolbarSortPill.d.ts +5 -0
  249. package/views/dist/panels/react/toolbar/ToolbarSortPill.js +6 -4
  250. package/views/dist/panels/react/toolbar/ToolbarViews.d.ts +7 -1
  251. package/views/dist/panels/react/toolbar/ToolbarViews.js +4 -4
  252. package/views/dist/panels/react/toolbar/context.d.ts +4 -0
  253. package/views/dist/panels/react/toolbar/context.js +1 -0
  254. package/views/dist/panels/react/toolbar/sheet-host.d.ts +3 -0
  255. package/views/dist/panels/react/toolbar/sheet-host.js +6 -0
  256. package/views/dist/panels/react/toolbar/use-give-way.d.ts +6 -0
  257. package/views/dist/panels/react/toolbar/use-give-way.js +10 -3
  258. package/views/dist/panels/react/views-row/ViewPicker.d.ts +8 -1
  259. package/views/dist/panels/react/views-row/ViewPicker.js +12 -7
  260. package/views/dist/panels/settings/filter-groups.js +12 -0
  261. package/views/dist/panels/settings/input.d.ts +11 -0
  262. package/views/dist/panels/settings/layout.js +26 -0
  263. package/views/dist/panels/settings/person.d.ts +15 -0
  264. package/views/dist/panels/settings/person.js +6 -0
  265. package/views/dist/panels/toolbar/page-resets.js +14 -3
  266. package/views/dist/provider/components.d.ts +47 -4
  267. package/views/dist/react.d.ts +1 -1
  268. package/views/dist/styles.css +116 -257
  269. package/views/dist/styles.unlayered.css +116 -257
  270. package/views/docs/contract.md +28 -18
  271. package/views/docs/controls/field.md +2 -1
  272. package/views/docs/controls/filter-editor.md +1 -1
  273. package/views/docs/controls/menu.md +1 -1
  274. package/views/docs/controls/sort-editor.md +1 -1
  275. package/views/docs/guides/atoms.md +1 -0
  276. package/views/docs/guides/looks.md +1 -1
  277. package/views/docs/guides/the-grid.md +6 -4
  278. package/views/docs/guides/toolbar-parts.md +337 -0
  279. package/views/docs/index.md +4 -0
  280. package/views/docs/reference/controls.md +6 -44
  281. package/views/docs/reference/field-row.md +1 -1
  282. package/views/docs/reference/grid.md +8 -7
  283. package/views/docs/reference/list.md +184 -11
  284. package/views/docs/reference/looks.md +13 -16
  285. package/views/docs/reference/panels-react.md +7 -7
  286. package/views/docs/reference/panels.md +1 -1
  287. package/views/docs/reference/react.md +14 -11
  288. package/views/docs/reference/views.md +9 -7
  289. package/views/skills/views/SKILL.md +2 -1
  290. package/views/dist/controls/setting-row/looks.d.ts +0 -10
  291. package/views/dist/controls/setting-row/looks.js +0 -22
  292. package/views/dist/controls/setting-row/setting-row.d.ts +0 -102
  293. package/views/dist/controls/setting-row/setting-row.js +0 -135
  294. package/views/dist/controls/setting-row/tokens.d.ts +0 -156
  295. package/views/dist/controls/setting-row/tokens.js +0 -41
  296. package/views/dist/controls/setting-row.css +0 -216
  297. package/views/dist/controls/switch-row/switch-row.d.ts +0 -1
  298. package/views/dist/controls/switch-row/switch-row.js +0 -1
  299. package/views/dist/controls/switch-row/tokens.d.ts +0 -39
  300. package/views/dist/controls/switch-row/tokens.js +0 -12
  301. package/views/dist/controls/switch-row.css +0 -35
  302. package/views/dist/controls/tag-field/tag-field.d.ts +0 -24
  303. package/views/dist/controls/tag-field/tag-field.js +0 -25
  304. package/views/dist/controls/tag-field/tokens.d.ts +0 -23
  305. package/views/dist/controls/tag-field/tokens.js +0 -8
  306. package/views/dist/controls/tag-field.css +0 -32
  307. package/views/docs/controls/setting-row.md +0 -44
  308. package/views/docs/controls/switch-row.md +0 -15
  309. package/views/docs/controls/tag-field.md +0 -11
@@ -1,3 +1,4 @@
1
+ import type { ReactNode } from "react";
1
2
  /**
2
3
  * The column-resize grab zone on a header cell's right edge. The header cell is
3
4
  * (usually) a Radix PopoverTrigger — every pointer/click event here stops
@@ -8,12 +9,15 @@
8
9
  * move/up here, so the passed handlers see the whole gesture without any
9
10
  * document listeners). Double-click clears the column's width override — but
10
11
  * only for true double-clicks; GridTable ignores it after a real drag.
12
+ *
13
+ * What it shows is `children`, the `HeaderResizeHandle` atom: ViewKit's hairline, or the app's own, which
14
+ * resizes from a press anywhere on it because its events reach this zone.
11
15
  */
12
- export declare function GridResizeHandle({ active, onResizeStart, onResizeMove, onResizeEnd, onReset, }: {
13
- /** True while THIS column is being dragged — pins the hairline visible. */
14
- active: boolean;
16
+ export declare function GridResizeHandle({ onResizeStart, onResizeMove, onResizeEnd, onReset, children, }: {
15
17
  onResizeStart: (e: React.PointerEvent<HTMLElement>) => void;
16
18
  onResizeMove: (e: React.PointerEvent<HTMLElement>) => void;
17
19
  onResizeEnd: (e: React.PointerEvent<HTMLElement>) => void;
18
20
  onReset: () => void;
21
+ /** What the zone shows: the `HeaderResizeHandle` atom. */
22
+ children: ReactNode;
19
23
  }): import("react/jsx-runtime").JSX.Element;
@@ -1,7 +1,6 @@
1
1
  "use client";
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
- import { cx } from "../../internal/cx.js";
4
- export function GridResizeHandle({ active, onResizeStart, onResizeMove, onResizeEnd, onReset, }) {
3
+ export function GridResizeHandle({ onResizeStart, onResizeMove, onResizeEnd, onReset, children, }) {
5
4
  return (_jsx("div", { "data-slot": "vk-grid-resize-handle", "data-no-nav": true, className: "group/gridresize absolute inset-y-0 right-0 z-10 w-[7px] cursor-col-resize touch-none", onPointerDown: (e) => {
6
5
  if (e.button !== 0)
7
6
  return;
@@ -15,5 +14,5 @@ export function GridResizeHandle({ active, onResizeStart, onResizeMove, onResize
15
14
  }, onPointerCancel: onResizeEnd, onClick: (e) => e.stopPropagation(), onDoubleClick: (e) => {
16
15
  e.stopPropagation();
17
16
  onReset();
18
- }, children: _jsx("div", { className: cx("absolute inset-y-0 right-0 w-[3px] rounded-full bg-(color:--vk-brand)", active ? "opacity-100" : "opacity-0 group-hover/gridresize:opacity-100") }) }));
17
+ }, children: children }));
19
18
  }
@@ -396,7 +396,7 @@ function GridTableContent(given) {
396
396
  const pinFooter = props.pinFooter && footerKey.includes("1")
397
397
  ? { pin: grouped ? "group" : "foot", flush: footerKey.endsWith("1") }
398
398
  : undefined;
399
- const footer = (group) => (_jsx(GridFooter, { group: group, ariaRowIndex: aria.footIndex(grouped ? group.key : (flat.sections[0]?.groupKey ?? group.key)), ariaLevel: grouped ? 2 : undefined, ariaColOffset: ariaColOffset, columns: visibleColumns, selecting: selecting, aggregates: aggregates, numberFormats: numberFormats, renderAggregate: renderAggregate, onAggregateChange: onAggregateChange, viewBacked: props.viewBacked, frozenCount: frozenCount, frozenLeft: frozenLeft, continuation: props.renderGroupFooter?.(group), defaultCurrency: props.defaultCurrency, pageOnly: paged, pin: pinFooter?.pin, verticalBorders: verticalBorders }));
399
+ const footer = (group) => (_jsx(GridFooter, { group: group, ariaRowIndex: aria.footIndex(grouped ? group.key : (flat.sections[0]?.groupKey ?? group.key)), ariaLevel: grouped ? 2 : undefined, ariaColOffset: ariaColOffset, columns: visibleColumns, selecting: selecting, aggregates: aggregates, numberFormats: numberFormats, renderAggregate: renderAggregate, onAggregateChange: onAggregateChange, viewBacked: props.viewBacked, frozenCount: frozenCount, frozenLeft: frozenLeft, continuation: props.renderGroupFooter?.(group), defaultCurrency: props.defaultCurrency, pageOnly: paged, pin: pinFooter?.pin, verticalBorders: verticalBorders, desktop: !phone, menus: props.menus }));
400
400
  const groupCheckbox = (items) => pickOnPhone ? (_jsx(GridHeadCheckBox, { ...groupSelection(items), "aria-label": messages({ key: "views.grid.select-group" }) })) : (_jsx(GridHeadCheck, { selecting: selecting, ...groupSelection(items), "aria-label": messages({ key: "views.grid.select-group" }) }));
401
401
  return (_jsx(EditLeaveContext.Provider, { value: leaveScope, children: _jsx(GridFitContext.Provider, { value: fit, children: _jsx(GridHoverContext.Provider, { value: hoverStore, children: _jsx(GridRowHighlightContext.Provider, { value: highlight, children: _jsx(GridRowWindowContext.Provider, { value: rowWindow.store, children: _jsx(GridTableSurface, { rootRef: rootRef, empty: empty, desktop: !phone, areaRef: areaRef, panRef: panRef, boxes: boxes, minWidth: minWidth, columnsTemplate: gridTemplate, gridAria: empty
402
402
  ? { role: "grid", rowCount: 2, colCount: ariaTailIndex }
@@ -15,7 +15,7 @@ export function GridTableSurface({ rootRef, areaRef, panRef, boxes, style, selec
15
15
  const scrollPaddingBottom = pinFooter
16
16
  ? "calc(var(--vk-scroll-inset-bottom,0px) + var(--vk-footer-h))"
17
17
  : "var(--vk-scroll-inset-bottom,0px)";
18
- const content = (_jsxs("div", { className: cx("relative", pinFooter?.pin === "foot" && "flex min-h-full flex-col"), role: gridAria?.role, "aria-rowcount": gridAria?.rowCount, "aria-colcount": gridAria?.colCount, "aria-multiselectable": gridAria ? true : undefined, style: {
18
+ const content = (_jsxs("div", { className: cx("relative", pinFooter?.pin === "foot" && !desktop && "flex min-h-full flex-col"), role: gridAria?.role, "aria-rowcount": gridAria?.rowCount, "aria-colcount": gridAria?.colCount, "aria-multiselectable": gridAria ? true : undefined, style: {
19
19
  minWidth,
20
20
  paddingBottom: footAt && pinFooter?.flush ? footAt : `calc(${foot} + 0.5rem)`,
21
21
  ...(footAt ? { "--vk-foot-at": footAt } : {}),
@@ -1,8 +1,6 @@
1
1
  import { type RefObject } from "react";
2
+ import { type OverOffsets } from "../../internal/over-cell.js";
2
3
  /** The offsets a grid editor hands the popover around the app's body. */
3
- export type GridBodyPlace = {
4
- sideOffset: number;
5
- alignOffset: number;
6
- };
4
+ export type GridBodyPlace = OverOffsets;
7
5
  /** The offsets a grid editor hands its panel around the app's body: over the cell, a step up and a step left of it. */
8
6
  export declare function useGridBodyPlace(anchor: RefObject<HTMLElement | null>): GridBodyPlace;
@@ -1,16 +1,15 @@
1
1
  "use client";
2
2
  import { useLayoutEffect, useState } from "react";
3
- import { lengthPx } from "../../internal/length.js";
3
+ import { overCellOffsets } from "../../internal/over-cell.js";
4
4
  const UNDER = 4;
5
- const stepOf = (el) => lengthPx(el, "--vk-spacing");
6
5
  export function useGridBodyPlace(anchor) {
7
6
  const [at, setAt] = useState(null);
8
7
  useLayoutEffect(() => {
9
8
  const el = anchor.current;
10
9
  if (!el)
11
10
  return;
12
- const height = el.getBoundingClientRect().height, step = stepOf(el);
13
- setAt((now) => (now && now.height === height && now.step === step ? now : { height, step }));
11
+ const next = overCellOffsets(el);
12
+ setAt((now) => (now && now.sideOffset === next.sideOffset && now.alignOffset === next.alignOffset ? now : next));
14
13
  }, [anchor]);
15
- return at ? { sideOffset: -(at.height + at.step), alignOffset: -at.step } : { sideOffset: UNDER, alignOffset: 0 };
14
+ return at ?? { sideOffset: UNDER, alignOffset: 0 };
16
15
  }
@@ -3,9 +3,12 @@ import { computeAggregate, figureKeyOf, moneyFigureCode, moneyTotal } from "../.
3
3
  import { fieldTypeOf } from "../../model/field-type-of.js";
4
4
  import { fieldKeyOf } from "../../model/view-rules.js";
5
5
  import { formatNumber } from "./cells.js";
6
+ const COUNTS_NUMBERS = new Set(["number", "percent", "currency"]);
6
7
  function countsRows(kind) {
7
- return kind === "count" || kind === "filled" || kind === "unique";
8
+ return kind === "count" || kind === "filled" || kind === "empty" || kind === "unique" || isPercentOfRows(kind);
8
9
  }
10
+ const isPercentOfRows = (kind) => kind === "percentEmpty" || kind === "percentFilled";
11
+ const countText = (kind, n) => (isPercentOfRows(kind) ? `${n}%` : String(n));
9
12
  export function gridFigureValue({ column, group, kind, numberFormats, defaultCurrency, cellFormat, }) {
10
13
  if (kind === "none")
11
14
  return null;
@@ -15,16 +18,19 @@ export function gridFigureValue({ column, group, kind, numberFormats, defaultCur
15
18
  const written = (text) => (text == null ? null : { text, suffix });
16
19
  if (group.figures) {
17
20
  const ratioParts = column.field?.type === "formula" ? column.field.ratio : undefined;
21
+ const key = figureKeyOf(column, defaultCurrency);
22
+ if (kind === "filled" && !COUNTS_NUMBERS.has(fieldTypeOf(column)) && !column.aggAccessor && group.figures.fields[key]?.filled === undefined)
23
+ return null;
18
24
  const fromSource = kind === "ratio" && ratioParts
19
25
  ? ratioFigure(group.figures, ratioParts.numerator, ratioParts.denominator)
20
- : figureFor(kind, group.figures, figureKeyOf(column, defaultCurrency));
26
+ : figureFor(kind, group.figures, key);
21
27
  const sourceCode = fromSource != null && !countLike && fieldTypeOf(column) === "currency"
22
28
  ? moneyFigureCode(column, defaultCurrency)
23
29
  : undefined;
24
30
  if (fromSource == null || sourceCode === null)
25
31
  return null;
26
32
  return written(countLike
27
- ? String(fromSource)
33
+ ? countText(kind, fromSource)
28
34
  : formatNumber(fromSource, column, { ...cellFormat, decimals, currency: sourceCode }));
29
35
  }
30
36
  const money = moneyTotal(kind, column, group.items, defaultCurrency);
@@ -36,5 +42,5 @@ export function gridFigureValue({ column, group, kind, numberFormats, defaultCur
36
42
  const computed = computeAggregate(kind, column, group.items);
37
43
  if (computed == null)
38
44
  return null;
39
- return written(countLike ? String(computed) : formatNumber(computed, column, { ...cellFormat, decimals }));
45
+ return written(countLike ? countText(kind, computed) : formatNumber(computed, column, { ...cellFormat, decimals }));
40
46
  }
@@ -14,14 +14,16 @@ import type { PercentDisplay } from "viewkitjs/fields";
14
14
  import type { ListGroupSummaryPart } from "../../model/preferences.js";
15
15
  import type { ListRowIconAccessor } from "../../model/row-icon.js";
16
16
  import type { GridRowOpenedFrom } from "../core/row-opened-from.js";
17
- import type { GridCellCommitFn, GridCellsCommitFn } from "../core/commit-model.js";
17
+ import type { GridCellCommitFn, GridCellValuesFn, GridCellsCommitFn } from "../core/commit-model.js";
18
18
  import type { GridGroupByState, GridSortState } from "./GridColumnMenu.js";
19
19
  import type { GridGroupSortOption } from "./GridGroupMenu.js";
20
20
  import type { GridGroupMenuPart } from "./grid-group-menu-parts.js";
21
21
  /** Each of the grid's menus as a function from its default items to the items it shows (`menu.drop`, `menu.rename`,
22
22
  * `menu.add` and `menu.move` on `viewkitjs/views/list` do the usual changes). `column` gets the column and its field,
23
23
  * `row` the row, `group` the group its band names, `addColumn` every column of the list, shown or hidden (+ Add column's
24
- * rows: each hidden column `add:<id>`, a field with parts `field:<id>`, or `all-shown`). Each reshapes a menu the grid opens: a column or band whose menu holds
24
+ * rows: each hidden column `add:<id>`, a field with parts `field:<id>`, or `all-shown`), `figure` a footer cell's calculation picker
25
+ * (its column, the group whose footer it is and the pick it shows; its rows keyed by their figure: `none`, `count`, `empty`,
26
+ * `filled`, `percentEmpty`, `percentFilled`, `sum`, `avg`, `min`, `max`, `ratio`). Each reshapes a menu the grid opens: a column or band whose menu holds
25
27
  * none of the grid's rows stays without one. Called while a menu draws: keep them pure and cheap.
26
28
  *
27
29
  * `row` is asked as a row's menu opens (a right-click, the row's ⋯, the menu key), never for a row drawn or pressed, and
@@ -43,6 +45,11 @@ export type GridMenus<Row> = {
43
45
  addColumn?: (items: ViewsMenuItem[], ctx: {
44
46
  columns: readonly ListColumnItem[];
45
47
  }) => ViewsMenuItem[];
48
+ figure?: (items: ViewsMenuItem[], ctx: {
49
+ column: ListColumn<Row>;
50
+ group: ListGroup<Row>;
51
+ current: ListAggregateKind;
52
+ }) => ViewsMenuItem[];
46
53
  };
47
54
  /** A group count's noun, singular and plural ("company", "companies"): "2 companies". None: a bare
48
55
  * count. */
@@ -271,6 +278,9 @@ export type GridTableProps<Row> = {
271
278
  scale?: number;
272
279
  onCellCommit?: GridCellCommitFn<Row>;
273
280
  onCellsCommit?: GridCellsCommitFn<Row>;
281
+ /** What a cell's change writes, as `gridSave` hands it (`cellValues`): every column it changes beside the edited one
282
+ * shows the new value as the save is sent, and rolls back with it. */
283
+ cellValues?: GridCellValuesFn<Row>;
274
284
  /** Per-user "Freeze identity columns" toggle: pins every column through the
275
285
  * title to the left edge while the rest scrolls under them. */
276
286
  freezeIdentity?: boolean;
@@ -284,8 +294,9 @@ export type GridTableProps<Row> = {
284
294
  oneHeader?: boolean;
285
295
  /** The footer pins at the foot of the grid's scroll area, `--vk-scroll-inset-bottom` above its edge (and, while rows are
286
296
  * selected, a step above the bar `renderBar` draws, measured where it stands; on the foot when it draws none), painted
287
- * the ground, and the rows pass under it. An ungrouped grid's footer
288
- * stands at the foot even when its rows don't fill the area (in pages too, just above the pager); a grouped grid's
297
+ * the ground under a line along its top, and the rows pass under it. On a computer it is never pushed below its last
298
+ * row: under a table shorter than the area it stands right after the last row. On a phone an ungrouped grid's footer
299
+ * stands at the foot even when its rows don't fill the area (in pages too, just above the pager). A grouped grid's
289
300
  * footers each pin while their group's rows run past the foot and close their group otherwise. Off by default: the
290
301
  * footer stands after the last row and scrolls with the rows. */
291
302
  pinFooter?: boolean;
@@ -5,6 +5,8 @@ import { useGridEditing } from "../core/useGridEditing.js";
5
5
  import { GridEditsSinkContext } from "../core/edits-sink.js";
6
6
  import { useGridRange } from "../core/useGridRange.js";
7
7
  import { gridRefusalSentence } from "../core/refusal-sentence.js";
8
+ import { gridWrittenAlongside } from "../core/written-alongside.js";
9
+ import { changedSinceEdit } from "../core/pending-reconciliation.js";
8
10
  import { columnEffectiveWritable, columnLabel, gridColumnLocked, gridEditRefusal, gridNormalizeWrite, } from "../../model/column-capabilities.js";
9
11
  import { gridPartWrite } from "../../model/part-write.js";
10
12
  import { foldPartEdits } from "../core/part-edits.js";
@@ -34,7 +36,16 @@ export function useGridTableInteractionModel({ rootRef, props, rows, visibleRows
34
36
  const columnById = useMemo(() => new Map([...columns, ...visibleColumns].map((column) => [column.id, column])), [columns, visibleColumns]);
35
37
  const partOfWhole = useCallback((wholeId) => [...columnById.values()].find((column) => column.partOf?.column === wholeId)?.partOf, [columnById]);
36
38
  const keepsSent = useCallback((columnId) => partOfWhole(columnId) != null, [partOfWhole]);
37
- const { focused: focusedCell, editing: editingCell, pendingByRow, pendingOf, settlementByRow, writeStateByRow, focusCell, clearFocus, dropFocus, startEdit, cancelEdit, closeEdit, commitEdit: commitEditRaw, commitBatch: commitBatchRaw, undo, redo, reconcile, canUndo: canUndoNow, canRedo: canRedoNow, saving: savingNow, hasInflight, pendingBaseline, sent, sentCells, forgetSent, isLastEdited, } = useGridEditing(props.onCellCommit, props.onCellsCommit, sayRefusal, keepsSent);
39
+ const editsSink = useContext(GridEditsSinkContext);
40
+ const more = useMemo(() => ({
41
+ alongside: gridWrittenAlongside([...columnById.values()], props.cellValues),
42
+ changedSince: (row, cell) => changedSinceEdit(columnById.get(cell.columnId), row, cell),
43
+ onChangedSince: () => {
44
+ editsSink?.changed();
45
+ ports.toast.warning(messages({ key: "views.grid.changed-since" }));
46
+ },
47
+ }), [columnById, props.cellValues, ports, messages, editsSink]);
48
+ const { focused: focusedCell, editing: editingCell, pendingByRow, pendingOf, settlementByRow, writeStateByRow, focusCell, clearFocus, dropFocus, startEdit, cancelEdit, closeEdit, commitEdit: commitEditRaw, commitBatch: commitBatchRaw, undo, redo, reconcile, canUndo: canUndoNow, canRedo: canRedoNow, saving: savingNow, hasInflight, pendingBaseline, sent, sentCells, forgetSent, isLastEdited, } = useGridEditing(props.onCellCommit, props.onCellsCommit, sayRefusal, keepsSent, more);
38
49
  const wholeStored = useCallback((rowId, wholeId, row) => {
39
50
  const part = partOfWhole(wholeId);
40
51
  const overlay = pendingOf(rowId);
@@ -295,7 +306,6 @@ export function useGridTableInteractionModel({ rootRef, props, rows, visibleRows
295
306
  finishFillRef.current = rangeActions.finishFill;
296
307
  }, [rangeActions.finishFill]);
297
308
  const editsState = useCallback(() => ({ saving: savingNow(), canUndo: canUndoNow(), canRedo: canRedoNow() }), [savingNow, canUndoNow, canRedoNow]);
298
- const editsSink = useContext(GridEditsSinkContext);
299
309
  useEffect(() => {
300
310
  editsSink?.changed();
301
311
  }, [editsSink, pendingByRow, writeStateByRow]);
@@ -79,7 +79,7 @@ function matchOption(col, text, value, offered) {
79
79
  .filter((option) => keys.includes(option.value))
80
80
  .map((option) => ({ key: option.value, label: optionLabelOf(col, option.value) }));
81
81
  const one = (found) => found.length === 0 ? undefined : found.length === 1 ? { key: found[0] } : { ambiguous: true };
82
- if (typeof value === "string" && keys.includes(value))
82
+ if (typeof value === "string" && keys.includes(value) && optionLabelOf(col, value) === text)
83
83
  return { key: value };
84
84
  const folded = text.toLowerCase();
85
85
  return (one(labelled.filter((option) => option.label === text).map((option) => option.key)) ??
@@ -87,6 +87,37 @@ function matchOption(col, text, value, offered) {
87
87
  one(labelled.filter((option) => option.label.toLowerCase() === folded).map((option) => option.key)) ??
88
88
  one(keys.filter((key) => key.toLowerCase() === folded)));
89
89
  }
90
+ function readOptionEntries(col, text, offered) {
91
+ const toKey = (entry) => {
92
+ const match = matchOption(col, entry, undefined, offered);
93
+ return match && "key" in match ? match.key : entry;
94
+ };
95
+ const whole = matchOption(col, text.trim(), undefined, offered);
96
+ if (whole && "key" in whole)
97
+ return [whole.key];
98
+ const keys = offered ?? (col.options ?? []).filter((option) => !option.archived).map((option) => option.value);
99
+ const labels = (col.options ?? [])
100
+ .filter((option) => keys.includes(option.value))
101
+ .map((option) => optionLabelOf(col, option.value))
102
+ .filter((label) => label !== "")
103
+ .sort((a, b) => b.length - a.length);
104
+ const entries = [];
105
+ let at = 0;
106
+ while (at < text.length) {
107
+ while (at < text.length && (text[at] === "," || /\s/.test(text[at])))
108
+ at++;
109
+ if (at >= text.length)
110
+ break;
111
+ const label = labels.find((each) => text.slice(at, at + each.length).toLowerCase() === each.toLowerCase() && /^\s*(,|$)/.test(text.slice(at + each.length)));
112
+ const comma = text.indexOf(",", at);
113
+ const end = label ? at + label.length : comma < 0 ? text.length : comma;
114
+ const entry = text.slice(at, end).trim();
115
+ if (entry)
116
+ entries.push(entry);
117
+ at = end;
118
+ }
119
+ return entries.map(toKey);
120
+ }
90
121
  export function parseTsvText(text) {
91
122
  const normalized = text.replace(/\r/g, "");
92
123
  if (normalized === "")
@@ -300,15 +331,18 @@ export function coercePaste(col, source, opts) {
300
331
  return { ok: true, next: matched.id, overlay };
301
332
  }
302
333
  case "list": {
303
- const pasted = Array.isArray(source.value)
334
+ const offeredKeys = opts.values ?? (col.options ?? []).filter((option) => !option.archived).map((option) => option.value);
335
+ const trusted = Array.isArray(source.value) &&
336
+ (!col.options?.length ||
337
+ (source.value.every((item) => typeof item !== "string" || offeredKeys.includes(item)) &&
338
+ cellCopyText(col, source.value) === source.text.trim()));
339
+ const single = typeof source.value === "string" ? matchOption(col, source.text.trim(), source.value, opts.values) : undefined;
340
+ const pasted = trusted
304
341
  ? source.value
305
342
  : col.options?.length
306
- ? source.text.split(",").map((raw, _index, entries) => {
307
- const entry = raw.trim();
308
- const value = entries.length === 1 ? source.value : undefined;
309
- const match = matchOption(col, entry, value, opts.values);
310
- return match && "key" in match ? match.key : entry;
311
- })
343
+ ? single && "key" in single
344
+ ? [single.key]
345
+ : readOptionEntries(col, source.text, opts.values)
312
346
  : source.text;
313
347
  const vetted = gridNormalizeWrite(col, pasted, opts.conventions, write);
314
348
  if (!vetted.ok)
@@ -63,6 +63,9 @@ export type GridCellsCommitFn<Row> = (edits: {
63
63
  value: unknown;
64
64
  context?: GridCommitContext;
65
65
  }[]) => Promise<void | GridCommitOutcome[]>;
66
+ /** One cell's change as the values its record's save sends (`gridSave`'s `values`, handed back as `cellValues`): the
67
+ * grid reads every other column over the row with them, and shows the ones they change as the save is sent. */
68
+ export type GridCellValuesFn<Row> = (row: Row, columnId: string, value: unknown, context: GridCommitContext) => Record<string, unknown>;
66
69
  /** A cell's key: its row and column ids as one JSON pair. It is read back whole (`gridCellFromKey`), never split at a
67
70
  * character, so no id can break it, whatever it holds. */
68
71
  export declare function gridCellKey(rowId: string, columnId: string): string;
@@ -1,7 +1,8 @@
1
1
  import { type GridCellCommitFn, type GridCellsCommitFn, type GridCommitRefusal } from "./commit-model.js";
2
2
  import type { GridCellPos } from "./coordinates.js";
3
- import { type GridCommitCell, type GridSettlementByRow } from "./editing-model.js";
3
+ import { type GridCommitCell, type GridEditCell, type GridSettlementByRow } from "./editing-model.js";
4
4
  import { type GridWriteStateByRow } from "./write-states.js";
5
+ import type { GridAlongside } from "./written-alongside.js";
5
6
  export type GridEditingCallbacks<Row> = {
6
7
  onCellCommit?: GridCellCommitFn<Row>;
7
8
  onCellsCommit?: GridCellsCommitFn<Row>;
@@ -11,6 +12,20 @@ export type GridEditingCallbacks<Row> = {
11
12
  /** Whether what a commit sends for a column's cells is kept for a part edit to build on (`sent`): the grid keeps
12
13
  * it only for a whole a part column builds on. Absent: every column. */
13
14
  keepsSent?: (columnId: string) => boolean;
15
+ /** The other columns a cell's save writes, with what each reads after it and before (`gridWrittenAlongside`): shown
16
+ * with the edit as it is sent, in flight with it, rolled back with it, kept until the rows show them. They carry no
17
+ * write state: a refusal is said on the edited cell. */
18
+ alongside?: GridAlongside<Row>;
19
+ /** Does the row in hand show a value in this edit's cell that is neither side of the edit: someone wrote it since?
20
+ * Asked as ⌘Z or ⌘⇧Z is pressed, only of the cells where nothing of the grid's own is still out (an overlay, a write,
21
+ * a waiting press), whose rows may lag behind it. A cell it says yes to is kept: the press leaves it as the rows show
22
+ * it and sends nothing for it, and it leaves the entry; an entry left with no cell leaves the history. */
23
+ changedSince?: (row: Row | undefined, cell: GridEditCell<Row>) => boolean;
24
+ /** Told once per press that kept any cell (`changedSince`), with those cells: the chrome says so. */
25
+ onChangedSince?: (cells: {
26
+ rowId: string;
27
+ columnId: string;
28
+ }[]) => void;
14
29
  };
15
30
  type ResolveRow<Row> = (rowId: string) => Row | undefined;
16
31
  /**
@@ -84,6 +99,12 @@ export declare class GridEditingController<Row> {
84
99
  /** A confirmed outcome that says what was `stored` lays it over the cell in place of what was
85
100
  * typed; a `requested` one keeps its overlay and marks it. Nothing else changes. */
86
101
  private settle;
102
+ /** The other columns a cell's save writes (`alongside`), as overlays of `revision` keyed by their cell, each with the
103
+ * cell's key it rides with: every one over a cell that draws an overlay now (an earlier save's, the rows not yet read
104
+ * again: this save owns the cell from here, so a refusal of the earlier one leaves its value standing), and every
105
+ * one whose value the row doesn't already read. None where the app wrote no `alongside`, or finding
106
+ * them throws; none over a cell the same write edits itself (`skip`). */
107
+ private alongsideFor;
87
108
  /** Is a write for this cell still in flight? Reconciliation asks, so it can
88
109
  * tell "the refetch hasn't caught up yet" apart from "the server disagrees". */
89
110
  hasInflight(rowId: string, columnId: string): boolean;
@@ -143,6 +164,13 @@ export declare class GridEditingController<Row> {
143
164
  private performBatch;
144
165
  private inflightFor;
145
166
  private enqueueApply;
167
+ /** Is anything of the grid's own still out on this cell: an overlay, a write, or a press that holds it? */
168
+ private ownWorkOn;
169
+ /** The cells of the entry about to be pressed that the rows show someone wrote since (`changedSince`) leave it, and
170
+ * the chrome is told once; an entry left empty leaves its stack, and the focus goes to the first cell it kept. True
171
+ * when nothing is left to press. Only a cell with an overlay is asked: one committed with none (a relation's id, a
172
+ * name's parts) holds a value no row reads back as equal. A callback that throws counts as no. */
173
+ private keepChangedSince;
146
174
  /** Takes a press's overlay off these cells where it still stands, putting back what it covered; a later press that
147
175
  * covered it covers what it covered instead. */
148
176
  private liftPress;
@@ -1,11 +1,20 @@
1
1
  import { gridCellKey, } from "./commit-model.js";
2
2
  import { applyGridPending, carryGridPutBack, createGridHistory, gridEditValue, gridOverlayValue, gridHistoryValue, gridKeptValue, gridRestoreShown, groupGridPendingByRow, groupGridPendingSettlement, keepGridPending, markGridPendingSettlement, planGridPendingAssignments, pressGridHistory, pruneGridEntry, pruneGridHistoryEntry, reconcileGridPending, recordGridHistory, revertGridHistoryPress, rollbackGridPending, } from "./editing-model.js";
3
+ import { sameListValue } from "viewkitjs/fields";
3
4
  import { setGridWriteStates } from "./write-states.js";
4
5
  import { refusalWords } from "./refusal-sentence.js";
5
6
  import { isPageClosing, onPageClose } from "../../internal/page-close.js";
6
7
  import { noteGridEdited } from "./undo-owner.js";
7
8
  import { markGridKeptValue } from "./value-equality.js";
8
9
  const confirmed = (outcome) => outcome ?? { status: "confirmed" };
10
+ const commitContext = () => (isPageClosing() ? { kind: "commit", closing: true } : { kind: "commit" });
11
+ const withAlongside = (keys, owners) => {
12
+ const all = new Set(keys);
13
+ for (const [key, owner] of owners)
14
+ if (keys.has(owner))
15
+ all.add(key);
16
+ return all;
17
+ };
9
18
  export class GridEditingController {
10
19
  callbacks;
11
20
  onPendingChange;
@@ -172,6 +181,27 @@ export class GridEditingController {
172
181
  if (next !== this.pending)
173
182
  this.publishPending(next);
174
183
  }
184
+ alongsideFor(row, rowId, columnId, value, context, revision, skip) {
185
+ const { alongside } = this.callbacks;
186
+ if (!alongside)
187
+ return [];
188
+ const owner = gridCellKey(rowId, columnId);
189
+ let written;
190
+ try {
191
+ written = alongside(row, columnId, value, context);
192
+ }
193
+ catch {
194
+ return [];
195
+ }
196
+ return written.flatMap((each) => {
197
+ const key = gridCellKey(rowId, each.columnId);
198
+ if (each.columnId === columnId || skip?.has(key))
199
+ return [];
200
+ if (!this.pending.has(key) && sameListValue(each.value, each.baseline))
201
+ return [];
202
+ return [{ assignment: { key, value: each.value, baseline: each.baseline, revision }, owner }];
203
+ });
204
+ }
175
205
  hasInflight(rowId, columnId) {
176
206
  const key = gridCellKey(rowId, columnId);
177
207
  return (this.inflight.get(key)?.size ?? 0) > 0 || this.unsentPressOn(key) != null;
@@ -352,14 +382,18 @@ export class GridEditingController {
352
382
  }
353
383
  });
354
384
  }
355
- perform(row, rowId, columnId, value, overlay, baseline, context = "commit", entryId) {
385
+ perform(row, rowId, columnId, value, overlay, baseline, context = "commit", entryId, alsoInflight = [], edited) {
356
386
  const { onCellCommit } = this.callbacks;
357
387
  if (!onCellCommit)
358
388
  return Promise.resolve({ status: "failed" });
359
389
  const key = gridCellKey(rowId, columnId);
360
390
  const sentToken = context === "commit" && entryId !== undefined ? this.noteSent({ rowId, columnId }, value, baseline, entryId) : null;
391
+ const revision = this.nextPendingRevision++;
392
+ const alongside = overlay
393
+ ? this.alongsideFor(row, rowId, columnId, value, commitContext(), revision, edited)
394
+ : [];
361
395
  const assignments = overlay
362
- ? [{ key, value: overlay.value, baseline: overlay.baseline, revision: this.nextPendingRevision++ }]
396
+ ? [{ key, value: overlay.value, baseline: overlay.baseline, revision }, ...alongside.map((each) => each.assignment)]
363
397
  : [];
364
398
  if (assignments.length > 0) {
365
399
  this.publishPending(applyGridPending(this.pending, assignments));
@@ -394,25 +428,40 @@ export class GridEditingController {
394
428
  this.settle([key], [result], assignments);
395
429
  return result;
396
430
  }, (error) => refuse({ status: "failed", error }));
397
- this.registerInflight([key], promise);
431
+ this.registerInflight([key, ...alongside.map((each) => each.assignment.key), ...alsoInflight], promise);
398
432
  this.trackWrite([{ rowId, columnId }], promise.then((result) => [result]));
399
433
  return promise;
400
434
  }
401
- performBatch(cells, side, context, entryId) {
435
+ performBatch(cells, side, context, entryId, alsoInflight = []) {
402
436
  if (cells.length === 0)
403
437
  return Promise.resolve([]);
404
438
  const { onCellsCommit } = this.callbacks;
405
439
  if (cells.length === 1 || !onCellsCommit) {
440
+ const edited = new Set(cells.map(({ cell }) => gridCellKey(cell.rowId, cell.columnId)));
406
441
  return Promise.all(cells.map(({ row, cell }) => this.perform(row, cell.rowId, cell.columnId, context === "restore" ? gridHistoryValue(cell, side) : gridEditValue(cell, side), context === "restore" || !cell.overlay
407
442
  ? false
408
443
  : { value: gridOverlayValue(cell, side), baseline: gridOverlayValue(cell, side === "next" ? "prev" : "next") }, context === "restore"
409
444
  ? gridHistoryValue(cell, side === "next" ? "prev" : "next")
410
- : gridEditValue(cell, side === "next" ? "prev" : "next"), context, entryId)));
445
+ : gridEditValue(cell, side === "next" ? "prev" : "next"), context, entryId, alsoInflight, edited)));
411
446
  }
412
- const assignments = context === "restore"
413
- ? []
414
- : planGridPendingAssignments(cells, side, this.nextPendingRevision++);
447
+ const revision = this.nextPendingRevision++;
448
+ const planned = context === "restore" ? [] : planGridPendingAssignments(cells, side, revision);
415
449
  const keys = cells.map(({ cell }) => gridCellKey(cell.rowId, cell.columnId));
450
+ const owners = new Map();
451
+ const alongside = new Map();
452
+ if (context === "commit") {
453
+ const edited = new Set(keys);
454
+ for (const { row, cell } of cells) {
455
+ if (!cell.overlay)
456
+ continue;
457
+ const value = gridEditValue(cell, side);
458
+ for (const { assignment, owner } of this.alongsideFor(row, cell.rowId, cell.columnId, value, commitContext(), revision, edited)) {
459
+ alongside.set(assignment.key, assignment);
460
+ owners.set(assignment.key, owner);
461
+ }
462
+ }
463
+ }
464
+ const assignments = [...planned, ...alongside.values()];
416
465
  const sentTokens = context === "commit" && entryId !== undefined
417
466
  ? cells.map(({ cell }) => this.noteSent(cell, gridEditValue(cell, side), gridEditValue(cell, side === "next" ? "prev" : "next"), entryId))
418
467
  : null;
@@ -449,7 +498,8 @@ export class GridEditingController {
449
498
  .filter((_, index) => results[index]?.status === "failed")
450
499
  .map(({ cell }) => gridCellKey(cell.rowId, cell.columnId)));
451
500
  if (failedKeys.size > 0) {
452
- const failed = assignments.filter((assignment) => failedKeys.has(assignment.key));
501
+ const failedAll = withAlongside(failedKeys, owners);
502
+ const failed = assignments.filter((assignment) => failedAll.has(assignment.key));
453
503
  this.publishPending(rollbackGridPending(this.pending, failed));
454
504
  this.reviseCovered(failed, "drop");
455
505
  }
@@ -471,7 +521,8 @@ export class GridEditingController {
471
521
  .filter((_, index) => carried[index]?.status === "failed")
472
522
  .map(({ cell }) => gridCellKey(cell.rowId, cell.columnId)));
473
523
  if (failedKeys.size > 0) {
474
- const failed = assignments.filter((assignment) => failedKeys.has(assignment.key));
524
+ const failedAll = withAlongside(failedKeys, owners);
525
+ const failed = assignments.filter((assignment) => failedAll.has(assignment.key));
475
526
  this.publishPending(rollbackGridPending(this.pending, failed));
476
527
  this.reviseCovered(failed, "drop");
477
528
  }
@@ -485,7 +536,7 @@ export class GridEditingController {
485
536
  }
486
537
  return cells.map(() => ({ status: "failed", error }));
487
538
  });
488
- this.registerInflight(cells.map(({ cell }) => gridCellKey(cell.rowId, cell.columnId)), promise);
539
+ this.registerInflight([...keys, ...alongside.keys(), ...alsoInflight], promise);
489
540
  this.trackWrite(cells.map(({ cell }) => ({ rowId: cell.rowId, columnId: cell.columnId })), promise);
490
541
  return promise;
491
542
  }
@@ -499,6 +550,8 @@ export class GridEditingController {
499
550
  return [...promises];
500
551
  }
501
552
  enqueueApply(kind, resolveRow, onApply) {
553
+ if (this.keepChangedSince(kind, resolveRow, onApply))
554
+ return true;
502
555
  const pressed = pressGridHistory(this.history, kind);
503
556
  const entry = pressed.entry;
504
557
  if (!entry)
@@ -511,6 +564,7 @@ export class GridEditingController {
511
564
  written: new Map(),
512
565
  notes: [],
513
566
  laid: [],
567
+ alongsideOf: new Map(),
514
568
  covered: new Map(),
515
569
  sent: false,
516
570
  heldBack: new Set(),
@@ -545,6 +599,26 @@ export class GridEditingController {
545
599
  });
546
600
  }
547
601
  }
602
+ const own = new Set(entry.edits.map((cell) => gridCellKey(cell.rowId, cell.columnId)));
603
+ for (const cell of entry.edits) {
604
+ if (!cell.overlay)
605
+ continue;
606
+ let row;
607
+ try {
608
+ row = resolveRow(cell.rowId) ?? cell.rowSnapshot;
609
+ }
610
+ catch {
611
+ row = cell.rowSnapshot;
612
+ }
613
+ const context = { kind: "restore", expected: gridHistoryValue(cell, other) };
614
+ for (const { assignment, owner } of this.alongsideFor(row, cell.rowId, cell.columnId, gridHistoryValue(cell, side), context, revision)) {
615
+ if (own.has(assignment.key))
616
+ continue;
617
+ pin.laid = pin.laid.filter((each) => each.key !== assignment.key);
618
+ pin.laid.push(assignment);
619
+ pin.alongsideOf.set(assignment.key, owner);
620
+ }
621
+ }
548
622
  if (pin.laid.length > 0) {
549
623
  for (const { key } of pin.laid)
550
624
  pin.covered.set(key, this.pending.get(key));
@@ -562,6 +636,58 @@ export class GridEditingController {
562
636
  this.applyChain = this.applyChain.then(() => this.applyPin(pin, resolveRow));
563
637
  return true;
564
638
  }
639
+ ownWorkOn(key) {
640
+ if (this.pending.has(key) || (this.inflight.get(key)?.size ?? 0) > 0)
641
+ return true;
642
+ for (const pin of this.pins) {
643
+ if (pin.laid.some((laid) => laid.key === key))
644
+ return true;
645
+ if (pin.entry?.edits.some((cell) => gridCellKey(cell.rowId, cell.columnId) === key))
646
+ return true;
647
+ }
648
+ return false;
649
+ }
650
+ keepChangedSince(kind, resolveRow, onApply) {
651
+ const { changedSince } = this.callbacks;
652
+ if (!changedSince)
653
+ return false;
654
+ const stack = kind === "undo" ? this.history.undo : this.history.redo;
655
+ const entry = stack.at(-1);
656
+ if (!entry)
657
+ return false;
658
+ const taken = new Set(entry.edits.filter((cell) => {
659
+ if (!cell.overlay || this.ownWorkOn(gridCellKey(cell.rowId, cell.columnId)))
660
+ return false;
661
+ try {
662
+ return changedSince(resolveRow(cell.rowId), cell);
663
+ }
664
+ catch {
665
+ return false;
666
+ }
667
+ }));
668
+ if (taken.size === 0)
669
+ return false;
670
+ const rest = entry.edits.filter((cell) => !taken.has(cell));
671
+ const kept = (entries) => entries.flatMap((each) => (each.id !== entry.id ? [each] : rest.length > 0 ? [{ ...entry, edits: rest }] : []));
672
+ this.history =
673
+ kind === "undo"
674
+ ? { undo: kept(this.history.undo), redo: this.history.redo }
675
+ : { undo: this.history.undo, redo: kept(this.history.redo) };
676
+ try {
677
+ this.callbacks.onChangedSince?.([...taken].map(({ rowId, columnId }) => ({ rowId, columnId })));
678
+ }
679
+ catch {
680
+ }
681
+ if (rest.length > 0)
682
+ return false;
683
+ const first = [...taken][0];
684
+ try {
685
+ onApply?.({ rowId: first.rowId, columnId: first.columnId });
686
+ }
687
+ catch {
688
+ }
689
+ return true;
690
+ }
565
691
  liftPress(pin, keys) {
566
692
  let next = null;
567
693
  for (const key of keys) {
@@ -635,6 +761,8 @@ export class GridEditingController {
635
761
  if (results[index]?.status === "confirmed")
636
762
  kept.add(gridCellKey(cell.rowId, cell.columnId));
637
763
  });
764
+ for (const key of withAlongside(kept, pin.alongsideOf))
765
+ kept.add(key);
638
766
  this.settle(cells.map(({ cell }) => gridCellKey(cell.rowId, cell.columnId)), results, pin.laid.filter((laid) => kept.has(laid.key)));
639
767
  const cleared = overwritten.filter((held, index) => held != null && results[index]?.status === "confirmed");
640
768
  if (cleared.length > 0)
@@ -686,7 +814,9 @@ export class GridEditingController {
686
814
  return held && !pressed.has(held.revision) ? { key, value: held.value, revision: held.revision } : null;
687
815
  });
688
816
  pin.sent = true;
689
- const results = await this.performBatch(cells, pin.kind === "undo" ? "prev" : "next", "restore");
817
+ const sentKeys = new Set(cells.map(({ cell }) => gridCellKey(cell.rowId, cell.columnId)));
818
+ const alongside = [...pin.alongsideOf].filter(([, owner]) => sentKeys.has(owner)).map(([key]) => key);
819
+ const results = await this.performBatch(cells, pin.kind === "undo" ? "prev" : "next", "restore", undefined, alongside);
690
820
  return { entry, cells, overwritten, results };
691
821
  }
692
822
  sendAtClose(pin, resolveRow) {