@viewkitjs/views 0.3.0 → 0.5.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 (288) hide show
  1. package/CHANGELOG.md +641 -0
  2. package/README.md +3 -3
  3. package/dist/atoms/CommandMenu.d.ts +1 -1
  4. package/dist/atoms/CommandMenu.js +7 -3
  5. package/dist/atoms/DrillRows.d.ts +3 -0
  6. package/dist/atoms/DrillRows.js +25 -0
  7. package/dist/atoms/PanelRows.d.ts +5 -0
  8. package/dist/atoms/PanelRows.js +40 -0
  9. package/dist/atoms/PanelSearch.d.ts +2 -0
  10. package/dist/atoms/PanelSearch.js +21 -0
  11. package/dist/atoms/RelationRoles.d.ts +2 -0
  12. package/dist/atoms/RelationRoles.js +6 -0
  13. package/dist/atoms/Row.js +2 -1
  14. package/dist/atoms/RowMenu.js +2 -1
  15. package/dist/atoms/SelectionSheet.d.ts +3 -0
  16. package/dist/atoms/SelectionSheet.js +30 -0
  17. package/dist/atoms/StatusMarker.js +3 -1
  18. package/dist/atoms/Tag.js +2 -1
  19. package/dist/atoms/defaults.js +14 -0
  20. package/dist/atoms/types.d.ts +146 -8
  21. package/dist/cells/cell-values.js +4 -2
  22. package/dist/cells/relation-wrap.js +3 -1
  23. package/dist/contract.d.ts +212 -17
  24. package/dist/contract.js +208 -6
  25. package/dist/display/boolean.js +3 -1
  26. package/dist/display/date.d.ts +1 -1
  27. package/dist/display/date.js +4 -2
  28. package/dist/display/format.js +20 -4
  29. package/dist/display/link.js +4 -3
  30. package/dist/display/multi-value.js +2 -1
  31. package/dist/display/percent.js +2 -1
  32. package/dist/display/phone.js +2 -1
  33. package/dist/display/range.js +3 -13
  34. package/dist/display/relation.js +23 -8
  35. package/dist/display/rich-text.js +2 -1
  36. package/dist/editors/ChipsEditor.d.ts +5 -1
  37. package/dist/editors/ChipsEditor.js +15 -2
  38. package/dist/editors/DateEditor.d.ts +2 -0
  39. package/dist/editors/DateEditor.js +76 -10
  40. package/dist/editors/EditorPanel.d.ts +14 -4
  41. package/dist/editors/EditorPanel.js +21 -4
  42. package/dist/editors/LocationEditor.js +35 -3
  43. package/dist/editors/NumberEditor.js +3 -2
  44. package/dist/editors/RangeEditor.d.ts +8 -0
  45. package/dist/editors/RangeEditor.js +3 -2
  46. package/dist/editors/RelationEditor.d.ts +2 -0
  47. package/dist/editors/RelationEditor.js +16 -2
  48. package/dist/editors/RelationSetEditor.d.ts +4 -2
  49. package/dist/editors/RelationSetEditor.js +36 -2
  50. package/dist/editors/SelectEditor.d.ts +5 -2
  51. package/dist/editors/SelectEditor.js +31 -4
  52. package/dist/editors/TextEditor.js +3 -1
  53. package/dist/editors/ValueListEditor.d.ts +3 -0
  54. package/dist/editors/ValueListEditor.js +10 -4
  55. package/dist/editors/edit-session.d.ts +14 -2
  56. package/dist/editors/edit-session.js +13 -5
  57. package/dist/editors/escape-rule.d.ts +12 -0
  58. package/dist/editors/escape-rule.js +8 -0
  59. package/dist/editors/open-value.js +2 -1
  60. package/dist/editors/picker-slot.d.ts +25 -0
  61. package/dist/editors/picker-slot.js +37 -0
  62. package/dist/editors/relation-picker.d.ts +44 -0
  63. package/dist/editors/relation-picker.js +49 -0
  64. package/dist/editors/relation-source.d.ts +1 -0
  65. package/dist/editors/relation-source.js +7 -1
  66. package/dist/field-row/FieldNoteLine.js +2 -1
  67. package/dist/field-row/FieldRow.js +41 -6
  68. package/dist/field-row/FieldRowLane.js +3 -1
  69. package/dist/field-row/editors/RowChipsEditor.js +1 -1
  70. package/dist/field-row/editors/RowDateEditor.js +1 -1
  71. package/dist/field-row/editors/RowEditor.js +2 -1
  72. package/dist/field-row/editors/RowRangeEditor.js +2 -1
  73. package/dist/field-row/editors/RowRelationEditor.js +2 -2
  74. package/dist/field-row/editors/RowSelectEditor.d.ts +1 -1
  75. package/dist/field-row/editors/RowSelectEditor.js +2 -2
  76. package/dist/field-row/editors/RowValueListEditor.js +1 -1
  77. package/dist/field-row/editors/host.d.ts +3 -0
  78. package/dist/field-row/editors/row-session.js +4 -1
  79. package/dist/fields/menus.d.ts +2 -0
  80. package/dist/fields/range-unit.d.ts +7 -0
  81. package/dist/fields/range-unit.js +13 -0
  82. package/dist/figures.d.ts +5 -48
  83. package/dist/figures.js +1 -63
  84. package/dist/grid/chrome/GridAddColumn.d.ts +8 -0
  85. package/dist/grid/chrome/GridAddColumn.js +66 -9
  86. package/dist/grid/chrome/GridAggregateMenu.d.ts +5 -2
  87. package/dist/grid/chrome/GridAggregateMenu.js +33 -4
  88. package/dist/grid/chrome/GridCellEditors.d.ts +9 -2
  89. package/dist/grid/chrome/GridCellEditors.js +24 -5
  90. package/dist/grid/chrome/GridCellOutline.d.ts +3 -2
  91. package/dist/grid/chrome/GridCellOutline.js +11 -1
  92. package/dist/grid/chrome/GridChipsEditor.js +1 -1
  93. package/dist/grid/chrome/GridColumnColorSection.d.ts +2 -0
  94. package/dist/grid/chrome/GridColumnColorSection.js +2 -2
  95. package/dist/grid/chrome/GridColumnDateSection.d.ts +4 -0
  96. package/dist/grid/chrome/GridColumnDateSection.js +2 -2
  97. package/dist/grid/chrome/GridColumnDurationSection.d.ts +4 -0
  98. package/dist/grid/chrome/GridColumnDurationSection.js +2 -2
  99. package/dist/grid/chrome/GridColumnMenu.d.ts +10 -6
  100. package/dist/grid/chrome/GridColumnMenu.js +62 -24
  101. package/dist/grid/chrome/GridColumnNumberSection.d.ts +4 -0
  102. package/dist/grid/chrome/GridColumnNumberSection.js +2 -2
  103. package/dist/grid/chrome/GridColumnPercentSection.d.ts +1 -0
  104. package/dist/grid/chrome/GridColumnPercentSection.js +1 -1
  105. package/dist/grid/chrome/GridColumnSortSection.d.ts +3 -3
  106. package/dist/grid/chrome/GridDateEditor.js +1 -1
  107. package/dist/grid/chrome/GridFooter.js +7 -48
  108. package/dist/grid/chrome/GridGroupMenu.d.ts +11 -5
  109. package/dist/grid/chrome/GridGroupMenu.js +28 -13
  110. package/dist/grid/chrome/GridHeader.d.ts +3 -1
  111. package/dist/grid/chrome/GridHeader.js +8 -8
  112. package/dist/grid/chrome/GridNumberEditor.js +3 -24
  113. package/dist/grid/chrome/GridRangeEditor.js +3 -2
  114. package/dist/grid/chrome/GridRelationEditor.js +2 -2
  115. package/dist/grid/chrome/GridRow.d.ts +2 -1
  116. package/dist/grid/chrome/GridRow.js +13 -37
  117. package/dist/grid/chrome/GridRowActions.js +2 -1
  118. package/dist/grid/chrome/GridRowCells.js +9 -4
  119. package/dist/grid/chrome/GridSelectEditor.js +30 -20
  120. package/dist/grid/chrome/GridStructure.d.ts +11 -4
  121. package/dist/grid/chrome/GridStructure.js +19 -7
  122. package/dist/grid/chrome/GridTable.js +138 -16
  123. package/dist/grid/chrome/GridTableSurface.d.ts +25 -12
  124. package/dist/grid/chrome/GridTableSurface.js +13 -6
  125. package/dist/grid/chrome/GridTextEditor.js +3 -1
  126. package/dist/grid/chrome/GridValueListEditor.js +1 -1
  127. package/dist/grid/chrome/cell-clipboard.d.ts +1 -1
  128. package/dist/grid/chrome/cell-clipboard.js +1 -1
  129. package/dist/grid/chrome/checks.d.ts +10 -2
  130. package/dist/grid/chrome/checks.js +17 -11
  131. package/dist/grid/chrome/column-glyph.d.ts +2 -2
  132. package/dist/grid/chrome/column-glyph.js +4 -0
  133. package/dist/grid/chrome/grid-add-column-items.d.ts +13 -0
  134. package/dist/grid/chrome/grid-add-column-items.js +40 -0
  135. package/dist/grid/chrome/grid-cell-classes.d.ts +2 -0
  136. package/dist/grid/chrome/grid-cell-classes.js +10 -4
  137. package/dist/grid/chrome/grid-column-menu-items.d.ts +75 -0
  138. package/dist/grid/chrome/grid-column-menu-items.js +263 -0
  139. package/dist/grid/chrome/grid-edit-escape.d.ts +4 -0
  140. package/dist/grid/chrome/grid-edit-escape.js +12 -0
  141. package/dist/grid/chrome/grid-edit-session.d.ts +2 -1
  142. package/dist/grid/chrome/grid-edit-session.js +14 -1
  143. package/dist/grid/chrome/grid-figure-value.d.ts +25 -0
  144. package/dist/grid/chrome/grid-figure-value.js +40 -0
  145. package/dist/grid/chrome/grid-fitted-box.d.ts +15 -0
  146. package/dist/grid/chrome/grid-fitted-box.js +26 -0
  147. package/dist/grid/chrome/grid-group-menu-items.d.ts +31 -0
  148. package/dist/grid/chrome/grid-group-menu-items.js +75 -0
  149. package/dist/grid/chrome/grid-group-menu-parts.d.ts +27 -0
  150. package/dist/grid/chrome/grid-group-menu-parts.js +19 -0
  151. package/dist/grid/chrome/grid-hover.d.ts +1 -0
  152. package/dist/grid/chrome/grid-hover.js +13 -1
  153. package/dist/grid/chrome/grid-lab.d.ts +7 -0
  154. package/dist/grid/chrome/grid-lab.js +7 -0
  155. package/dist/grid/chrome/grid-menu-focus.d.ts +12 -0
  156. package/dist/grid/chrome/grid-menu-focus.js +13 -0
  157. package/dist/grid/chrome/{useGridRowContextMenu.d.ts → grid-row-menu-items.d.ts} +15 -4
  158. package/dist/grid/chrome/{useGridRowContextMenu.js → grid-row-menu-items.js} +15 -18
  159. package/dist/grid/chrome/grid-row-props.d.ts +3 -1
  160. package/dist/grid/chrome/grid-row-window.d.ts +15 -5
  161. package/dist/grid/chrome/grid-row-window.js +44 -10
  162. package/dist/grid/chrome/grid-rows-menu.d.ts +38 -0
  163. package/dist/grid/chrome/grid-rows-menu.js +83 -0
  164. package/dist/grid/chrome/grid-table-props.d.ts +53 -8
  165. package/dist/grid/chrome/useGridBandFigures.d.ts +26 -0
  166. package/dist/grid/chrome/useGridBandFigures.js +50 -0
  167. package/dist/grid/chrome/useGridBoxes.d.ts +22 -0
  168. package/dist/grid/chrome/useGridBoxes.js +22 -0
  169. package/dist/grid/chrome/useGridColumnLayout.js +29 -4
  170. package/dist/grid/chrome/useGridKeyboard.js +7 -2
  171. package/dist/grid/chrome/useGridPartColumns.d.ts +5 -0
  172. package/dist/grid/chrome/useGridPartColumns.js +9 -0
  173. package/dist/grid/chrome/useGridRangeGestures.js +2 -1
  174. package/dist/grid/chrome/useGridRecorder.d.ts +16 -0
  175. package/dist/grid/chrome/useGridRecorder.js +144 -0
  176. package/dist/grid/chrome/useGridRowOpener.d.ts +41 -0
  177. package/dist/grid/chrome/useGridRowOpener.js +83 -0
  178. package/dist/grid/chrome/useGridScrollArea.d.ts +38 -12
  179. package/dist/grid/chrome/useGridScrollArea.js +70 -17
  180. package/dist/grid/chrome/useGridTableInteractionModel.d.ts +1 -0
  181. package/dist/grid/chrome/useGridTableInteractionModel.js +67 -9
  182. package/dist/grid/core/clipboard-model.d.ts +11 -3
  183. package/dist/grid/core/clipboard-model.js +9 -4
  184. package/dist/grid/core/commit-model.d.ts +7 -0
  185. package/dist/grid/core/editing-controller.d.ts +31 -1
  186. package/dist/grid/core/editing-controller.js +65 -0
  187. package/dist/grid/core/grid-recorder.d.ts +111 -0
  188. package/dist/grid/core/grid-recorder.js +223 -0
  189. package/dist/grid/core/part-edits.d.ts +18 -0
  190. package/dist/grid/core/part-edits.js +48 -0
  191. package/dist/grid/core/pending-reconciliation.js +12 -3
  192. package/dist/grid/core/refusal-sentence.d.ts +3 -0
  193. package/dist/grid/core/refusal-sentence.js +15 -0
  194. package/dist/grid/core/row-opened-from.d.ts +21 -0
  195. package/dist/grid/core/row-opened-from.js +11 -0
  196. package/dist/grid/core/useGridEditing.d.ts +16 -2
  197. package/dist/grid/core/useGridEditing.js +10 -4
  198. package/dist/grid/core/value-equality.d.ts +19 -1
  199. package/dist/grid/core/value-equality.js +24 -0
  200. package/dist/grid/index.d.ts +4 -1
  201. package/dist/grid/index.js +1 -0
  202. package/dist/grid/useGridTablePrefs.d.ts +1 -1
  203. package/dist/grid-lab.d.ts +18 -0
  204. package/dist/grid-lab.js +16 -0
  205. package/dist/grouping/sort-groups.d.ts +6 -7
  206. package/dist/index.d.ts +1 -0
  207. package/dist/index.js +1 -0
  208. package/dist/internal/reset.d.ts +9 -0
  209. package/dist/internal/reset.js +1 -0
  210. package/dist/model/aggregates.d.ts +3 -3
  211. package/dist/model/aggregates.js +17 -71
  212. package/dist/model/column-capabilities.d.ts +29 -2
  213. package/dist/model/column-capabilities.js +27 -3
  214. package/dist/model/column-filters.js +24 -4
  215. package/dist/model/column-inspect.d.ts +2 -1
  216. package/dist/model/column-order.d.ts +2 -2
  217. package/dist/model/column-schema.d.ts +18 -7
  218. package/dist/model/column-state.d.ts +9 -20
  219. package/dist/model/column-state.js +1 -4
  220. package/dist/model/column-types.d.ts +1 -15
  221. package/dist/model/column-types.js +1 -1
  222. package/dist/model/part-columns.d.ts +17 -0
  223. package/dist/model/part-columns.js +67 -0
  224. package/dist/model/part-rows.d.ts +3 -10
  225. package/dist/model/part-rows.js +6 -11
  226. package/dist/model/part-write.d.ts +11 -0
  227. package/dist/model/part-write.js +52 -0
  228. package/dist/model/preferences.d.ts +3 -23
  229. package/dist/model/preferences.js +1 -17
  230. package/dist/model/prefs-buckets.d.ts +0 -27
  231. package/dist/model/prefs-buckets.js +1 -1
  232. package/dist/model/relation-filters.d.ts +0 -1
  233. package/dist/model/relation-filters.js +1 -1
  234. package/dist/model/row-icon.d.ts +5 -9
  235. package/dist/model/view-rules.d.ts +32 -6
  236. package/dist/model/view-rules.js +101 -21
  237. package/dist/provider/ViewsProvider.d.ts +22 -2
  238. package/dist/provider/ViewsProvider.js +21 -2
  239. package/dist/provider/components.d.ts +197 -9
  240. package/dist/provider/context.d.ts +12 -1
  241. package/dist/provider/desktop.d.ts +3 -0
  242. package/dist/provider/desktop.js +7 -4
  243. package/dist/provider/menu-groups.d.ts +3 -2
  244. package/dist/provider/menu-groups.js +13 -7
  245. package/dist/provider/missing-slot.d.ts +10 -0
  246. package/dist/provider/missing-slot.js +15 -0
  247. package/dist/provider/plain-input.d.ts +3 -2
  248. package/dist/provider/plain-input.js +3 -1
  249. package/dist/react.d.ts +3 -2
  250. package/dist/selection/SelectionBar.d.ts +18 -0
  251. package/dist/selection/SelectionBar.js +92 -0
  252. package/dist/selection/SelectionBarPhone.d.ts +3 -0
  253. package/dist/selection/SelectionBarPhone.js +14 -0
  254. package/dist/selection/bar-overflow.d.ts +12 -0
  255. package/dist/selection/bar-overflow.js +42 -0
  256. package/dist/selection/bar-parts.d.ts +15 -0
  257. package/dist/selection/bar-parts.js +17 -0
  258. package/dist/selection/index.d.ts +2 -0
  259. package/dist/selection/index.js +1 -0
  260. package/dist/selection/types.d.ts +3 -2
  261. package/dist/selection/verbs.d.ts +34 -0
  262. package/dist/selection/verbs.js +1 -0
  263. package/docs/contract.md +142 -39
  264. package/docs/getting-started.md +1 -1
  265. package/docs/guides/atoms.md +32 -4
  266. package/docs/guides/columns.md +1 -1
  267. package/docs/guides/display.md +1 -1
  268. package/docs/guides/editors.md +3 -3
  269. package/docs/guides/ports.md +1 -1
  270. package/docs/guides/selection.md +32 -20
  271. package/docs/guides/the-grid.md +43 -21
  272. package/docs/guides/the-provider.md +14 -4
  273. package/docs/index.md +2 -0
  274. package/docs/install.md +8 -1
  275. package/docs/reference/editors-date.md +2 -0
  276. package/docs/reference/editors-panel.md +4 -4
  277. package/docs/reference/editors-range.md +1 -1
  278. package/docs/reference/editors-relation.md +3 -3
  279. package/docs/reference/editors-select.md +1 -1
  280. package/docs/reference/editors-session.md +3 -2
  281. package/docs/reference/editors-value-list.md +1 -1
  282. package/docs/reference/field-row.md +2 -2
  283. package/docs/reference/grid.md +25 -6
  284. package/docs/reference/react.md +30 -8
  285. package/docs/reference/selection.md +10 -2
  286. package/docs/reference/views.md +42 -36
  287. package/package.json +22 -3
  288. package/skills/views/SKILL.md +3 -3
@@ -3,19 +3,19 @@ import { gridRowIdFromKey } from "./coordinates.js";
3
3
  import { GridEditingController } from "./editing-controller.js";
4
4
  import { sameListValue } from "@viewkitjs/fields";
5
5
  import { prepareGridCommitCells, } from "./editing-model.js";
6
- export function useGridEditing(onCellCommit, onCellsCommit) {
6
+ export function useGridEditing(onCellCommit, onCellsCommit, onRefused) {
7
7
  const [focused, setFocused] = useState(null);
8
8
  const [editing, setEditing] = useState(null);
9
9
  const [pendingByRow, setPendingByRow] = useState(() => new Map());
10
10
  const [settlementByRow, setSettlementByRow] = useState(() => new Map());
11
- const [controller] = useState(() => new GridEditingController({ onCellCommit, onCellsCommit }, (pending, settlement) => {
11
+ const [controller] = useState(() => new GridEditingController({ onCellCommit, onCellsCommit, onRefused }, (pending, settlement) => {
12
12
  setPendingByRow(pending);
13
13
  setSettlementByRow(settlement);
14
14
  }));
15
15
  useEffect(() => {
16
- const callbacks = { onCellCommit, onCellsCommit };
16
+ const callbacks = { onCellCommit, onCellsCommit, onRefused };
17
17
  controller.setCallbacks(callbacks);
18
- }, [controller, onCellCommit, onCellsCommit]);
18
+ }, [controller, onCellCommit, onCellsCommit, onRefused]);
19
19
  const focusCell = useCallback((rowId, columnId) => {
20
20
  setFocused({ rowId, columnId });
21
21
  setEditing(null);
@@ -72,6 +72,9 @@ export function useGridEditing(onCellCommit, onCellsCommit) {
72
72
  const reconcile = useCallback((matchedKeys) => controller.reconcile(matchedKeys), [controller]);
73
73
  const hasInflight = useCallback((rowId, columnId) => controller.hasInflight(rowId, columnId), [controller]);
74
74
  const pendingBaseline = useCallback((rowId, columnId) => controller.pendingBaseline(rowId, columnId), [controller]);
75
+ const sent = useCallback((rowId, columnId) => controller.sent(rowId, columnId), [controller]);
76
+ const sentCells = useCallback(() => controller.sentCells(), [controller]);
77
+ const forgetSent = useCallback((rowId, columnId) => controller.forgetSent(rowId, columnId), [controller]);
75
78
  return {
76
79
  focused,
77
80
  editing,
@@ -89,5 +92,8 @@ export function useGridEditing(onCellCommit, onCellsCommit) {
89
92
  reconcile,
90
93
  hasInflight,
91
94
  pendingBaseline,
95
+ sent,
96
+ sentCells,
97
+ forgetSent,
92
98
  };
93
99
  }
@@ -22,7 +22,9 @@
22
22
  *
23
23
  * A third, `sameKeptValue` at the end, reads only a value a save handed back as
24
24
  * what it kept, by structure, so an answer that never says what it kept keeps
25
- * the two rules above unchanged.
25
+ * the two rules above unchanged. And `sameInstantMinute` reads a datetime cell's two spellings of
26
+ * one minute (the editor's local minute, the row's stored instant) as one value, as `sameCalendarDay`
27
+ * reads a day cell's two (the bare day, a local midnight for it).
26
28
  */
27
29
  /**
28
30
  * Nothing, however it is spelled: `null`, `undefined`, a blank text, an empty list. An emptied cell
@@ -41,6 +43,22 @@ export declare function isEmptyValue(value: unknown): boolean;
41
43
  * `["a","a"]` and `["a","b"]` stay different.
42
44
  */
43
45
  export declare function looselyEqualValue(a: unknown, b: unknown): boolean;
46
+ /**
47
+ * THE SAME MINUTE, for a datetime cell. Its editor writes the minute in the viewer's own time
48
+ * ("YYYY-MM-DDTHH:MM", no offset) and a row stores the instant in its own spelling (seconds, an
49
+ * offset, UTC), so the two are one value when they fall in the same minute. Seconds an app kept
50
+ * from the old value are no difference: the editor never shows them.
51
+ */
52
+ export declare function sameInstantMinute(a: unknown, b: unknown): boolean;
53
+ /**
54
+ * THE DAY, for a calendar-day (`date`) field's value: the `YYYY-MM-DD` key it names, or null. An app may hand a day
55
+ * field's editor the day as its local midnight (`YYYY-MM-DDT00:00:00`), so a bare day never opens a day early west of
56
+ * Greenwich; the editor, a paste and a fill write the bare day. Both spellings are the one day. An instant with a zone
57
+ * (`Z`, an offset) or a time of day is not a day, so nothing moves a day across a time zone.
58
+ */
59
+ export declare function calendarDayOf(value: unknown): string | null;
60
+ /** THE SAME DAY, for a calendar-day cell: the editor's bare day and a row's local midnight for it are one value. */
61
+ export declare function sameCalendarDay(a: unknown, b: unknown): boolean;
44
62
  /** Note a value a save said it kept. A primitive needs no note: the rules above already read it. */
45
63
  export declare function markGridKeptValue(value: unknown): void;
46
64
  /** Is this overlay value one a save said it kept? */
@@ -1,3 +1,4 @@
1
+ import { fromDayKey } from "@viewkitjs/fields/query";
1
2
  function looselyEqualScalar(a, b) {
2
3
  if (Object.is(a, b))
3
4
  return true;
@@ -43,6 +44,29 @@ export function looselyEqualValue(a, b) {
43
44
  }
44
45
  return looselyEqualScalar(a, b);
45
46
  }
47
+ function instantTime(value) {
48
+ if (value instanceof Date)
49
+ return value.getTime();
50
+ return typeof value === "string" && value.trim() !== "" ? Date.parse(value) : Number.NaN;
51
+ }
52
+ export function sameInstantMinute(a, b) {
53
+ const left = instantTime(a);
54
+ const right = instantTime(b);
55
+ if (Number.isNaN(left) || Number.isNaN(right))
56
+ return false;
57
+ return Math.floor(left / 60_000) === Math.floor(right / 60_000);
58
+ }
59
+ const DAY_OR_LOCAL_MIDNIGHT = /^(\d{4}-\d{2}-\d{2})(?:T00:00(?::00(?:\.0+)?)?)?$/;
60
+ export function calendarDayOf(value) {
61
+ if (typeof value !== "string")
62
+ return null;
63
+ const day = DAY_OR_LOCAL_MIDNIGHT.exec(value.trim())?.[1];
64
+ return day && fromDayKey(day) ? day : null;
65
+ }
66
+ export function sameCalendarDay(a, b) {
67
+ const left = calendarDayOf(a);
68
+ return left != null && left === calendarDayOf(b);
69
+ }
46
70
  const keptValues = new WeakSet();
47
71
  export function markGridKeptValue(value) {
48
72
  if (typeof value === "object" && value !== null)
@@ -11,8 +11,11 @@ export { useGridTablePrefs } from "./useGridTablePrefs.js";
11
11
  export { GridTable, type GridTableProps } from "./chrome/GridTable.js";
12
12
  export type { GridGroupByState, GridSortState } from "./chrome/GridColumnMenu.js";
13
13
  export type { GridGroupSortOption } from "./chrome/GridGroupMenu.js";
14
- export type { GridGroupFigure, GroupCountNoun } from "./chrome/grid-table-props.js";
14
+ export type { GridGroupMenuPart } from "./chrome/grid-group-menu-parts.js";
15
+ export type { GridRowOpenedFrom } from "./core/row-opened-from.js";
16
+ export type { GridDeclaredFigure, GridDrawnFigure, GridGroupFigure, GroupCountNoun, } from "./chrome/grid-table-props.js";
15
17
  export type { GridCellCommitFn, GridCellsCommitFn, GridCommitContext, GridCommitOutcome, } from "./core/commit-model.js";
16
18
  export { deriveGridRelationValues, deriveGridSelectValues } from "./core/column-values.js";
17
19
  export { cellCopyText, cellEditBaseline } from "./core/clipboard-model.js";
18
20
  export { GRID_TITLE_LINK_CLASS } from "./chrome/grid-cell-classes.js";
21
+ export { GRID_RECORDER_CAPS, type GridRecording, type GridRecordingContext, type GridRecordingSummary, type GridScrollSample, type GridSpread, type GridTouchKind, type GridTouchSample, } from "./core/grid-recorder.js";
@@ -3,3 +3,4 @@ export { GridTable } from "./chrome/GridTable.js";
3
3
  export { deriveGridRelationValues, deriveGridSelectValues } from "./core/column-values.js";
4
4
  export { cellCopyText, cellEditBaseline } from "./core/clipboard-model.js";
5
5
  export { GRID_TITLE_LINK_CLASS } from "./chrome/grid-cell-classes.js";
6
+ export { GRID_RECORDER_CAPS, } from "./core/grid-recorder.js";
@@ -37,7 +37,7 @@ export declare function useGridTablePrefs<Row>({ prefs, setPrefs, columns, viewB
37
37
  onColumnStateChange: (next: ListColumnState) => void;
38
38
  groupSummary: ListGroupSummaryPart[];
39
39
  onGroupSummaryChange: (part: ListGroupSummaryPart, next: boolean) => void;
40
- aggregates: Record<string, ListAggregateKind>;
40
+ aggregates: Record<string, import("@viewkitjs/fields/query").FigureKind>;
41
41
  onAggregateChange: (columnId: string, kind: ListAggregateKind) => void;
42
42
  viewBacked: boolean;
43
43
  numberFormats: ListNumberFormatOverrides;
@@ -0,0 +1,18 @@
1
+ /**
2
+ * THE GRID'S LAB, its store: what an app turns on, for one page, to measure a grid on a device: a recorder that
3
+ * hands each recording to the app, and the two-box lock to try on a touch screen. Null, the default, is the grid
4
+ * exactly as without it. One store for the page, not a context, so an app sets it from anywhere (its shell
5
+ * included: this file reaches no rendering and no React) and every grid on the page reads it.
6
+ */
7
+ import type { GridRecording } from "./grid/core/grid-recorder.js";
8
+ export type GridLab = {
9
+ /** Receives each recording; absent: nothing is recorded. */
10
+ record?: (recording: GridRecording) => void;
11
+ /** 2: on a touch screen the rows scroll up and down in their own box, inside one that scrolls the table
12
+ * sideways, so a flick moves one way only. Absent or 1: one box both ways, the grid as without a lab. A device
13
+ * that hovers with a fine pointer keeps one box either way. */
14
+ boxes?: 1 | 2;
15
+ };
16
+ export declare function setGridLab(lab: GridLab | null): void;
17
+ export declare function getGridLab(): GridLab | null;
18
+ export declare function subscribeGridLab(listener: () => void): () => void;
@@ -0,0 +1,16 @@
1
+ let current = null;
2
+ const listeners = new Set();
3
+ export function setGridLab(lab) {
4
+ current = lab;
5
+ for (const listener of [...listeners])
6
+ listener();
7
+ }
8
+ export function getGridLab() {
9
+ return current;
10
+ }
11
+ export function subscribeGridLab(listener) {
12
+ listeners.add(listener);
13
+ return () => {
14
+ listeners.delete(listener);
15
+ };
16
+ }
@@ -1,13 +1,12 @@
1
- /** `manual`: the reader's own order, by stored positions (POR-498). Only the
2
- * source list orders by it; `sortGroupEntries` below treats it as `name`. */
3
- export type OrderMode = "lifecycle" | "count" | "name" | "manual";
4
- export type OrderDir = "asc" | "desc";
1
+ import type { BucketOrderMode, SortDirection } from "@viewkitjs/fields/query";
2
+ /** How a grouping orders its sections, and which way. `manual`: the reader's own order, by stored positions
3
+ * (POR-498); only the source list orders by it, and `sortGroupEntries` below treats it as `name`. */
5
4
  export type OrderChoice = {
6
- mode: OrderMode;
7
- dir: OrderDir;
5
+ mode: BucketOrderMode;
6
+ dir: SortDirection;
8
7
  };
9
8
  /** The natural direction for a mode. Used to seed dir when a user picks a new mode. */
10
- export declare function defaultDirFor(mode: OrderMode): OrderDir;
9
+ export declare function defaultDirFor(mode: BucketOrderMode): SortDirection;
11
10
  type Entry<K extends string> = [key: K, items: unknown[]];
12
11
  export declare function sortGroupEntries<K extends string>(entries: Entry<K>[], opts: {
13
12
  order: OrderChoice;
package/dist/index.d.ts CHANGED
@@ -27,3 +27,4 @@ export * from "./fields/number-edit.js";
27
27
  export * from "./fields/format-knobs.js";
28
28
  export * from "./fields/relation-source-types.js";
29
29
  export * from "./fields/menus.js";
30
+ export { setGridLab, type GridLab } from "./grid-lab.js";
package/dist/index.js CHANGED
@@ -27,3 +27,4 @@ export * from "./fields/number-edit.js";
27
27
  export * from "./fields/format-knobs.js";
28
28
  export * from "./fields/relation-source-types.js";
29
29
  export * from "./fields/menus.js";
30
+ export { setGridLab } from "./grid-lab.js";
@@ -0,0 +1,9 @@
1
+ /**
2
+ * What Tailwind's base reset (preflight) sets on a button, an input, a textarea and a link, for every
3
+ * one of those the package draws itself, so it looks the same in an app that loads no base reset
4
+ * (VK-308). Each class sits behind `[:where(&)]:`, which Tailwind compiles to `:where(.class)`: zero
5
+ * specificity, so every class the element carries wins, the browser's own look loses, and nothing of
6
+ * the app's is touched. Written out whole so Tailwind's scanner, which reads the package's source,
7
+ * sees each class. `element-reset.test.ts` fails an element that doesn't carry it.
8
+ */
9
+ export declare const ELEMENT_RESET = "[:where(&)]:m-0 [:where(&)]:p-0 [:where(&)]:border-0 [:where(&)]:border-solid [:where(&)]:rounded-none [:where(&)]:bg-transparent [:where(&)]:[font:inherit] [:where(&)]:[letter-spacing:inherit] [:where(&)]:[color:inherit] [:where(&)]:[text-decoration:inherit] [:where(&)]:[appearance:none]";
@@ -0,0 +1 @@
1
+ export const ELEMENT_RESET = "[:where(&)]:m-0 [:where(&)]:p-0 [:where(&)]:border-0 [:where(&)]:border-solid [:where(&)]:rounded-none [:where(&)]:bg-transparent [:where(&)]:[font:inherit] [:where(&)]:[letter-spacing:inherit] [:where(&)]:[color:inherit] [:where(&)]:[text-decoration:inherit] [:where(&)]:[appearance:none]";
@@ -3,9 +3,6 @@ import { type DisplayCurrency } from "../fields/currency.js";
3
3
  import type { ListAggregateKind, ListColumn } from "./column-schema.js";
4
4
  /** A figure's name, as the app words it: `views.grid.figure`. */
5
5
  export declare function aggregateLabel(kind: ListAggregateKind, messages?: ViewsMessageResolver): string;
6
- /** The figures' names in the package's English. A grid reads `aggregateLabel` with the provider's `messages`. */
7
- export declare const LIST_AGGREGATE_LABELS: Record<Exclude<ListAggregateKind, "none">, string>;
8
- export declare function gridColumnIsNumericAgg<Row>(col: ListColumn<Row>): boolean;
9
6
  /** A source list's footer (POR-470, POR-472): the keys whose figures the
10
7
  * database answered, and the reader's default currency — the key a money
11
8
  * column read in Original is totalled under. */
@@ -27,6 +24,9 @@ export declare function figureKeyOf<Row>(col: ListColumn<Row>, defaultCurrency:
27
24
  */
28
25
  export declare function aggregateOptions<Row>(col: ListColumn<Row>, sourced?: SourcedAggregates): ListAggregateKind[];
29
26
  export declare function resolveAggregateKind<Row>(col: ListColumn<Row>, prefs?: Readonly<Record<string, ListAggregateKind>>, sourced?: SourcedAggregates): ListAggregateKind;
27
+ /** A column's figure over some rows, worked out by `@viewkitjs/fields` (`figureOfValues`, `ratioOf`) from what the
28
+ * column reads: its cells for a count, the filled and the different ones; the figure it says to total
29
+ * (`aggAccessor`, else the cell) for the numbers; its two readers for a ratio. */
30
30
  export declare function computeAggregate<Row>(kind: ListAggregateKind, col: ListColumn<Row>, rows: readonly Row[]): number | null;
31
31
  /** One figure, and the currency it is in. */
32
32
  export type MoneyTotal = {
@@ -1,5 +1,5 @@
1
- import { isMultipleType, locationText, nameText, presentedDef, scalarOf, valueItems, valueKey, } from "@viewkitjs/fields";
2
- import { phoneMatchText } from "@viewkitjs/fields/phone";
1
+ import { presentedDef } from "@viewkitjs/fields";
2
+ import { figureNumber, figureOfNumbers, figureOfValues, ratioOf } from "@viewkitjs/fields/query";
3
3
  import { resolveViewsMessage } from "../contract.js";
4
4
  import { COLUMN_WIDE_CODE } from "../fields/denomination.js";
5
5
  import { convertMoney } from "../fields/money.js";
@@ -9,18 +9,8 @@ import { fieldKeyOf } from "./view-rules.js";
9
9
  export function aggregateLabel(kind, messages = resolveViewsMessage) {
10
10
  return messages({ key: "views.grid.figure", values: { kind } });
11
11
  }
12
- export const LIST_AGGREGATE_LABELS = {
13
- sum: aggregateLabel("sum"),
14
- avg: aggregateLabel("avg"),
15
- min: aggregateLabel("min"),
16
- max: aggregateLabel("max"),
17
- count: aggregateLabel("count"),
18
- filled: aggregateLabel("filled"),
19
- unique: aggregateLabel("unique"),
20
- ratio: aggregateLabel("ratio"),
21
- };
22
12
  const NUMERIC = new Set(["number", "percent", "currency"]);
23
- export function gridColumnIsNumericAgg(col) {
13
+ function gridColumnIsNumericAgg(col) {
24
14
  return !!col.aggAccessor || NUMERIC.has(fieldTypeOf(col));
25
15
  }
26
16
  export function figureKeyOf(col, defaultCurrency) {
@@ -85,74 +75,30 @@ export function resolveAggregateKind(col, prefs, sourced) {
85
75
  export function computeAggregate(kind, col, rows) {
86
76
  if (kind === "none")
87
77
  return null;
88
- if (kind === "count")
89
- return rows.length;
90
- if (kind === "filled" || kind === "unique") {
91
- const type = fieldTypeOf(col);
92
- if (col.multiple && isMultipleType(type)) {
93
- const lists = rows
94
- .map((row) => {
95
- const value = col.accessor?.(row);
96
- const one = Array.isArray(value) ? valueItems(value) : valueItems([value]);
97
- return one.map((item) => valueKey(item.value, type));
98
- })
99
- .filter((keys) => keys.length > 0);
100
- if (kind === "filled")
101
- return lists.length;
102
- return new Set(lists.map((keys) => [...keys].sort().join("|"))).size;
103
- }
104
- const asText = type === "location" ? locationText : type === "name" ? nameText : type === "phone" ? phoneMatchText : undefined;
105
- const written = (value) => !asText ? value : Array.isArray(value) ? value.map((item) => asText(item)).filter(Boolean) : asText(value);
106
- const values = rows
107
- .map((row) => written(col.accessor?.(row)))
108
- .filter((value) => value != null && value !== "" && !(Array.isArray(value) && value.length === 0));
109
- if (kind === "filled")
110
- return values.length;
111
- return new Set(values.map((value) => Array.isArray(value) ? value.map(String).sort().join("|") : String(value))).size;
112
- }
113
78
  if (kind === "ratio") {
114
- if (!col.ratio)
115
- return null;
116
- let num = 0;
117
- let den = 0;
118
- for (const row of rows) {
119
- num += col.ratio.numerator(row) ?? 0;
120
- den += col.ratio.denominator(row) ?? 0;
121
- }
122
- return den > 0 ? Math.round((num / den) * 100) : null;
79
+ const ratio = col.ratio;
80
+ return ratio ? ratioOf(rows.map((row) => [ratio.numerator(row), ratio.denominator(row)])) : null;
123
81
  }
124
- return reduceNumbers(kind, totalledNumbers(col, rows));
82
+ const reading = { type: fieldTypeOf(col), multiple: col.multiple, field: col.field };
83
+ if (NUMERIC_AGGREGATES.has(kind))
84
+ return figureOfValues(kind, totalledValues(col, rows), reading);
85
+ if (kind === "count")
86
+ return rows.length;
87
+ return figureOfValues(kind, rows.map((row) => col.accessor?.(row)), reading);
125
88
  }
126
89
  const NUMERIC_AGGREGATES = new Set(["sum", "avg", "min", "max"]);
127
- function totalledNumber(col, row) {
128
- const read = col.aggAccessor ? col.aggAccessor(row) : col.accessor?.(row);
129
- const value = col.field ? scalarOf(col.field, read) : read;
130
- const number = typeof value === "number" ? value : value == null || value === "" ? NaN : Number(value);
131
- return Number.isNaN(number) ? null : number;
90
+ function totalledValues(col, rows) {
91
+ return rows.map((row) => (col.aggAccessor ? col.aggAccessor(row) : col.accessor?.(row)));
132
92
  }
133
93
  function totalledNumbers(col, rows) {
134
94
  const numbers = [];
135
- for (const row of rows) {
136
- const number = totalledNumber(col, row);
95
+ for (const value of totalledValues(col, rows)) {
96
+ const number = figureNumber(value, col.field);
137
97
  if (number != null)
138
98
  numbers.push(number);
139
99
  }
140
100
  return numbers;
141
101
  }
142
- function reduceNumbers(kind, numbers) {
143
- if (numbers.length === 0)
144
- return null;
145
- switch (kind) {
146
- case "sum":
147
- return numbers.reduce((sum, value) => sum + value, 0);
148
- case "avg":
149
- return numbers.reduce((sum, value) => sum + value, 0) / numbers.length;
150
- case "min":
151
- return Math.min(...numbers);
152
- default:
153
- return Math.max(...numbers);
154
- }
155
- }
156
102
  export function moneyTotal(kind, col, rows, defaultCurrency) {
157
103
  if (!NUMERIC_AGGREGATES.has(kind) || fieldTypeOf(col) !== "currency")
158
104
  return undefined;
@@ -165,12 +111,12 @@ export function moneyTotal(kind, col, rows, defaultCurrency) {
165
111
  if (converted != null)
166
112
  numbers.push(converted);
167
113
  }
168
- const amount = reduceNumbers(kind, numbers);
114
+ const amount = figureOfNumbers(kind, numbers);
169
115
  return amount == null ? null : { amount, code: defaultCurrency };
170
116
  }
171
117
  if (col.currencyAccessor && !money)
172
118
  return null;
173
- const amount = reduceNumbers(kind, totalledNumbers(col, rows));
119
+ const amount = figureOfNumbers(kind, totalledNumbers(col, rows));
174
120
  if (amount == null)
175
121
  return null;
176
122
  const code = col.format?.currency;
@@ -76,7 +76,7 @@ export declare function columnManagedByView<Row>(col: ListColumn<Row>): boolean;
76
76
  * the column has a field, or is a computed column (`custom`): the view stores
77
77
  * a computed column under its id, which its list's source names (`computed`,
78
78
  * POR-496). Filtering and totals stay `columnManagedByView`'s: a computed
79
- * column never filters, sorts, groups or totals. */
79
+ * column never filters, sorts, groups or totals. A part column (`partOf`) is placed as its whole is. */
80
80
  export declare function columnPlacedByView<Row>(col: ListColumn<Row>): boolean;
81
81
  export declare const VIEW_FIELDLESS_FILTER_REASON = "Not a field of this list; a view cannot filter on it.";
82
82
  /** Reorder the columns a view places while leaving the rest in their declared
@@ -85,7 +85,8 @@ export declare const VIEW_FIELDLESS_FILTER_REASON = "Not a field of this list; a
85
85
  * follows the ones it does; a COMPUTED column it does not name keeps its
86
86
  * declared slot, exactly as a column the view cannot place does — every view
87
87
  * stored before POR-496 names none, and must draw them where it always did.
88
- * Once the view names one (a drag, a hide), it is placed like a field. */
88
+ * Once the view names one (a drag, a hide), it is placed like a field. A part column the view does not name sits
89
+ * right after its whole. */
89
90
  export declare function resolveViewColumnOrder<Row>(columns: ListColumn<Row>[], requested?: readonly string[]): string[];
90
91
  /** The complete order a Move or a header drag rewrites: the order the grid
91
92
  * DRAWS. On a saved view that is `resolveViewColumnOrder` — a column the view
@@ -145,6 +146,32 @@ export type GridWriteResult = {
145
146
  ok: false;
146
147
  reason: string;
147
148
  };
149
+ /**
150
+ * COERCION — the grid's half of the write gate: read a pasted "yes" as `true`,
151
+ * "a, b" as a list, a relation's object as its id. Called through
152
+ * `gridNormalizeWrite` below, so every write path — keyboard, menu, fill,
153
+ * paste, the marker's own button — passes through here exactly once.
154
+ *
155
+ * The rules are keyed off the column's TYPE (`GRID_TYPE_RULES[type].value`)
156
+ * rather than re-derived per call site, which is what lets a new constrained
157
+ * type state its shape once and have every route honour it.
158
+ *
159
+ * - **boolean** — a commit must be a real `false`, never the grid's internal
160
+ * `""` for "cleared". `""` would defeat the `next === prev` no-op check AND
161
+ * deadlock the pending overlay (reconcile compares `accessor(row) === value`,
162
+ * and `false === ""` is never true — the cell would stay overridden for the
163
+ * life of the mount). A `marker` is additionally ONE-WAY: rejecting truthy
164
+ * here is what stops a fill-drag from a flagged row, or a pasted "true",
165
+ * from RAISING exceptions across a column.
166
+ * - **email / url** — the value has to be the shape it claims. Before this,
167
+ * the gate knew only booleans, so an `email` cell took `"not an email"` and
168
+ * rendered `mailto:not an email`. Both also TRIM, because a trailing space
169
+ * off a paste is the common case and refusing it would be pedantry.
170
+ *
171
+ * Undo/redo deliberately bypass all of it: core re-applies a recorded value
172
+ * verbatim, which is what lets ⌘Z put a cleared marker back.
173
+ */
174
+ export declare function coerceWrite<Row>(col: ListColumn<Row>, next: unknown, messages: ViewsMessageResolver): GridWriteResult;
148
175
  /**
149
176
  * THE write gate: coerce (the grid's rules, by column type), then — when the
150
177
  * column presents a registry field — accept (the field's rules, by value).
@@ -6,6 +6,8 @@ import { fieldKeyOf } from "./view-rules.js";
6
6
  export function gridEditorKind(col) {
7
7
  if (!col.editable || !col.type)
8
8
  return null;
9
+ if (col.partOf?.part === "countryCode")
10
+ return "select";
9
11
  if (col.multiple)
10
12
  return col.field && col.type && isMultipleType(col.type) ? "values" : null;
11
13
  if (col.type === "title" && col.field && valueTypeOf(col.field) === "name")
@@ -61,10 +63,31 @@ export function columnManagedByView(col) {
61
63
  return col.field != null;
62
64
  }
63
65
  export function columnPlacedByView(col) {
64
- return col.field != null || col.custom != null;
66
+ return col.field != null || col.custom != null || col.partOf != null;
65
67
  }
66
68
  export const VIEW_FIELDLESS_FILTER_REASON = "Not a field of this list; a view cannot filter on it.";
67
69
  export function resolveViewColumnOrder(columns, requested = []) {
70
+ const named = new Set(requested);
71
+ const loose = columns.filter((column) => column.partOf && !named.has(column.id));
72
+ if (loose.length === 0)
73
+ return resolvePlacedOrder(columns, requested);
74
+ const order = resolvePlacedOrder(columns.filter((column) => !loose.includes(column)), requested);
75
+ const wholeOf = new Map(columns.map((column) => [column.id, column.partOf?.column]));
76
+ for (const part of loose) {
77
+ const whole = part.partOf.column;
78
+ let at = order.indexOf(whole);
79
+ if (at < 0) {
80
+ order.push(part.id);
81
+ continue;
82
+ }
83
+ at += 1;
84
+ while (at < order.length && wholeOf.get(order[at]) === whole)
85
+ at += 1;
86
+ order.splice(at, 0, part.id);
87
+ }
88
+ return order;
89
+ }
90
+ function resolvePlacedOrder(columns, requested) {
68
91
  const managedIds = new Set(columns.filter(columnPlacedByView).map((column) => column.id));
69
92
  const seen = new Set();
70
93
  const managed = requested.filter((id) => {
@@ -88,7 +111,7 @@ export function baseColumnOrder(columns, order, viewBacked) {
88
111
  : resolveColumnOrder(columns, order ? [...order] : undefined).map((column) => column.id);
89
112
  }
90
113
  export function lockKeyOf(col) {
91
- return fieldKeyOf(col);
114
+ return col.partOf?.field.key ?? fieldKeyOf(col);
92
115
  }
93
116
  export function gridColumnLocked(col, config) {
94
117
  if (!config)
@@ -114,6 +137,7 @@ export function columnClearRefusal(col, messages = resolveViewsMessage) {
114
137
  export function columnEditRefusal(col, conventions, messages = resolveViewsMessage) {
115
138
  return (col.reasons?.editable ??
116
139
  (col.field ? lockReason(col.field, conventions) : undefined) ??
140
+ (col.partOf ? lockReason(col.partOf.field, conventions) : undefined) ??
117
141
  (col.custom
118
142
  ? messages({ key: "views.grid.computed", values: { from: col.custom.from } })
119
143
  : undefined));
@@ -144,7 +168,7 @@ const URL_SHAPE = /^https?:\/\/\S+\.\S+/i;
144
168
  function isCleared(next) {
145
169
  return next == null || (typeof next === "string" && next.trim() === "");
146
170
  }
147
- function coerceWrite(col, next, messages) {
171
+ export function coerceWrite(col, next, messages) {
148
172
  if (col.multiple) {
149
173
  if (isCleared(next) || Array.isArray(next))
150
174
  return { ok: true, value: next };
@@ -1,5 +1,7 @@
1
1
  import { actorKey, COUNTRY_CODES, countryName, isIntegerField, isMultipleType, isOpenVocabulary, presentedDef, relationKey, scalarOf, valueItems, valueTypeOf, } from "@viewkitjs/fields";
2
2
  import { matchesRule, operatorsFor } from "@viewkitjs/fields/query";
3
+ import { rangeUnit } from "../fields/range-unit.js";
4
+ import { rangeEndFormat } from "./part-columns.js";
3
5
  import { FILTER_PART_ROWS, parsePartKey, partKey, partLabel } from "./part-rows.js";
4
6
  import { phoneFilterOperand, phoneMatchText, readPhone } from "@viewkitjs/fields/phone";
5
7
  import { isTextRuleActive, matchesTextRule } from "../filters/text-filter.js";
@@ -48,6 +50,9 @@ function numberUnit(col) {
48
50
  return col.format?.currency;
49
51
  return undefined;
50
52
  }
53
+ function rangeEndDecimals(field, key, overrides) {
54
+ return overrides?.[key] ?? rangeEndFormat(field).decimals ?? 2;
55
+ }
51
56
  export function booleanFilterOptions(col) {
52
57
  const display = col.format?.booleanDisplay ?? "checkbox";
53
58
  if (display === "marker") {
@@ -200,7 +205,8 @@ export function buildColumnFilters({ columns, order, declared = [], icon, rules
200
205
  return [];
201
206
  if (declaredByKey.has(col.id) || capabilities?.[col.id]?.mode === "unavailable")
202
207
  return [];
203
- const type = valueTypeOf(col.field);
208
+ const field = col.field;
209
+ const type = valueTypeOf(field);
204
210
  return (FILTER_PART_ROWS[type] ?? []).map((part) => {
205
211
  const key = partKey(col.id, part);
206
212
  const label = partLabel(columnLabel(col), type, part, messages);
@@ -221,6 +227,19 @@ export function buildColumnFilters({ columns, order, declared = [], icon, rules
221
227
  onChange: (next) => onRuleChange?.(key, next.length ? { editor: "options", values: next } : null),
222
228
  };
223
229
  }
230
+ if (type === "range") {
231
+ const rule = stored?.editor === "number" ? stored : null;
232
+ return {
233
+ key,
234
+ label,
235
+ icon: icon?.(col),
236
+ editor: "number",
237
+ value: rule ? { operator: rule.operator, value: rule.value, value2: rule.value2 } : null,
238
+ decimals: rangeEndDecimals(field, key, decimals),
239
+ unit: rangeUnit(field),
240
+ onChange: (next) => onRuleChange?.(key, next ? { editor: "number", ...next } : null),
241
+ };
242
+ }
224
243
  const rule = stored?.editor === "text" ? stored : null;
225
244
  return {
226
245
  key,
@@ -260,7 +279,7 @@ function textRuleHolds(col, value, rule, holds) {
260
279
  return values.length > 0;
261
280
  return rule.operator === "is_not" || rule.operator === "not_contains" ? values.every(holds) : values.some(holds);
262
281
  }
263
- function partRuleMatches(row, key, rule, columns, conventions) {
282
+ function partRuleMatches(row, key, rule, columns, decimals, conventions) {
264
283
  const { id, part } = parsePartKey(key);
265
284
  if (part === undefined)
266
285
  return true;
@@ -271,7 +290,8 @@ function partRuleMatches(row, key, rule, columns, conventions) {
271
290
  if (!FILTER_PART_ROWS[type]?.includes(part))
272
291
  return true;
273
292
  const filterRule = fromListFilterRule(fieldKeyOf(col), type, rule, part);
274
- return !filterRule || matchesRule(type, col.accessor(row), filterRule, { conventions });
293
+ const shown = type === "range" ? { decimals: rangeEndDecimals(col.field, key, decimals) } : {};
294
+ return !filterRule || matchesRule(type, col.accessor(row), filterRule, { ...shown, conventions });
275
295
  }
276
296
  export function rowMatchesRules(row, rules, columns, decimals, conventions) {
277
297
  const ids = Object.keys(rules);
@@ -281,7 +301,7 @@ export function rowMatchesRules(row, rules, columns, decimals, conventions) {
281
301
  const rule = rules[id];
282
302
  const col = columns.find((c) => c.id === id);
283
303
  if (!col) {
284
- if (!partRuleMatches(row, id, rule, columns, conventions))
304
+ if (!partRuleMatches(row, id, rule, columns, decimals, conventions))
285
305
  return false;
286
306
  continue;
287
307
  }
@@ -19,7 +19,8 @@ export declare function isLongTextColumn<Row>(col: ListColumn<Row>): boolean;
19
19
  export declare function gridColumnInspectable<Row>(col: ListColumn<Row>): boolean;
20
20
  /** A text that opens WHOLE in the panel when the cell cuts it off: plain text, and a name that is
21
21
  * text (not a person's name, which edits in its own boxes). Links, emails, phones and domains keep
22
- * their one-line box. Whether it IS cut off is the cell's to measure (`gridCellCutOff`). */
22
+ * their one-line box, which grows to fit what is typed in it. Whether it IS cut off is the cell's to
23
+ * measure (`gridCellCutOff`). */
23
24
  export declare function isWholeTextColumn<Row>(col: ListColumn<Row>): boolean;
24
25
  /** Whether an open text cell is drawn in the panel over the cell rather than in the cell: a
25
26
  * paragraph always, a line when it opened `whole` (cut off when it was opened). */
@@ -1,5 +1,5 @@
1
1
  import { type FieldDef } from "@viewkitjs/fields";
2
- import type { OrderDir } from "../grouping/sort-groups.js";
2
+ import { type SortDirection } from "@viewkitjs/fields/query";
3
3
  import type { ListColumn } from "./column-schema.js";
4
4
  /** Whether a column offers Group by on a saved view: it presents a field of a type that splits a list, and the
5
5
  * list has not taken it out (`bucketable: false`). */
@@ -33,4 +33,4 @@ export declare function groupableOrders<Row>(columns: readonly ListColumn<Row>[]
33
33
  }): GroupableEntry<Row>[];
34
34
  /** The direction a sort by `field` opens in: a date newest first, a number or a yes/no largest first, text and
35
35
  * options A to Z; a date that looks ahead (a due date) soonest first. */
36
- export declare function sortDirFor(field: FieldDef): OrderDir;
36
+ export declare function sortDirFor(field: FieldDef): SortDirection;