viewkitjs 0.27.0 → 0.28.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 (229) hide show
  1. package/CHANGELOG.md +71 -0
  2. package/MIGRATION.md +40 -3
  3. package/package.json +1 -1
  4. package/views/dist/cells/cell-format.d.ts +3 -1
  5. package/views/dist/cells/cell-format.js +2 -2
  6. package/views/dist/cells/use-cell-format.d.ts +8 -1
  7. package/views/dist/cells/use-cell-format.js +13 -2
  8. package/views/dist/contract.d.ts +70 -3
  9. package/views/dist/contract.js +76 -0
  10. package/views/dist/controls/alert/alert.d.ts +46 -0
  11. package/views/dist/controls/alert/alert.js +11 -0
  12. package/views/dist/controls/alert/looks.d.ts +4 -0
  13. package/views/dist/controls/alert/looks.js +19 -0
  14. package/views/dist/controls/alert/tokens.d.ts +92 -0
  15. package/views/dist/controls/alert/tokens.js +25 -0
  16. package/views/dist/controls/alert-dialog/alert-dialog.d.ts +50 -0
  17. package/views/dist/controls/alert-dialog/alert-dialog.js +67 -0
  18. package/views/dist/controls/alert-dialog/confirm.d.ts +13 -0
  19. package/views/dist/controls/alert-dialog/confirm.js +11 -0
  20. package/views/dist/controls/alert-dialog/looks.d.ts +4 -0
  21. package/views/dist/controls/alert-dialog/looks.js +17 -0
  22. package/views/dist/controls/alert-dialog/tokens.d.ts +119 -0
  23. package/views/dist/controls/alert-dialog/tokens.js +32 -0
  24. package/views/dist/controls/alert-dialog.css +95 -0
  25. package/views/dist/controls/alert.css +51 -0
  26. package/views/dist/controls/collapsible/collapsible.d.ts +39 -0
  27. package/views/dist/controls/collapsible/collapsible.js +18 -0
  28. package/views/dist/controls/collapsible/looks.d.ts +4 -0
  29. package/views/dist/controls/collapsible/looks.js +5 -0
  30. package/views/dist/controls/collapsible/map-collapse.d.ts +2 -0
  31. package/views/dist/controls/collapsible/map-collapse.js +6 -0
  32. package/views/dist/controls/collapsible/tokens.d.ts +68 -0
  33. package/views/dist/controls/collapsible/tokens.js +19 -0
  34. package/views/dist/controls/collapsible.css +83 -0
  35. package/views/dist/controls/compound-editor/place-parts.js +5 -1
  36. package/views/dist/controls/controls.d.ts +9 -0
  37. package/views/dist/controls/controls.js +9 -0
  38. package/views/dist/controls/date-editor/date-editor.d.ts +2 -1
  39. package/views/dist/controls/date-editor/map-calendar.js +3 -1
  40. package/views/dist/controls/filter-editor/filter-editor.d.ts +56 -0
  41. package/views/dist/controls/filter-editor/filter-editor.js +208 -0
  42. package/views/dist/controls/filter-editor/how.d.ts +23 -0
  43. package/views/dist/controls/filter-editor/how.js +13 -0
  44. package/views/dist/controls/filter-editor/map-filter-body.d.ts +18 -0
  45. package/views/dist/controls/filter-editor/map-filter-body.js +164 -0
  46. package/views/dist/controls/filter-editor/map-rules.d.ts +85 -0
  47. package/views/dist/controls/filter-editor/map-rules.js +273 -0
  48. package/views/dist/controls/filter-editor/parts.d.ts +46 -0
  49. package/views/dist/controls/filter-editor/parts.js +75 -0
  50. package/views/dist/controls/filter-editor/rules.d.ts +104 -0
  51. package/views/dist/controls/filter-editor/rules.js +148 -0
  52. package/views/dist/controls/filter-editor/tokens.d.ts +83 -0
  53. package/views/dist/controls/filter-editor/tokens.js +23 -0
  54. package/views/dist/controls/filter-editor/words.d.ts +59 -0
  55. package/views/dist/controls/filter-editor/words.js +40 -0
  56. package/views/dist/controls/filter-editor.css +124 -0
  57. package/views/dist/controls/group-editor/group-editor.d.ts +56 -0
  58. package/views/dist/controls/group-editor/group-editor.js +126 -0
  59. package/views/dist/controls/group-editor/map-group-body.d.ts +19 -0
  60. package/views/dist/controls/group-editor/map-group-body.js +106 -0
  61. package/views/dist/controls/group-editor/rules.d.ts +48 -0
  62. package/views/dist/controls/group-editor/rules.js +41 -0
  63. package/views/dist/controls/group-editor/tokens.d.ts +15 -0
  64. package/views/dist/controls/group-editor/tokens.js +6 -0
  65. package/views/dist/controls/group-editor/words.d.ts +39 -0
  66. package/views/dist/controls/group-editor/words.js +21 -0
  67. package/views/dist/controls/group-editor.css +20 -0
  68. package/views/dist/controls/index.d.ts +19 -1
  69. package/views/dist/controls/index.js +19 -1
  70. package/views/dist/controls/internal/editor-parts.d.ts +8 -1
  71. package/views/dist/controls/internal/editor-parts.js +5 -0
  72. package/views/dist/controls/internal/step-return.d.ts +9 -0
  73. package/views/dist/controls/internal/step-return.js +27 -0
  74. package/views/dist/controls/links-editor/links-editor.d.ts +5 -3
  75. package/views/dist/controls/links-editor/links-editor.js +38 -17
  76. package/views/dist/controls/links-editor/map-links-body.js +4 -1
  77. package/views/dist/controls/links-editor.css +1 -1
  78. package/views/dist/controls/menu-list/menu-list.d.ts +17 -2
  79. package/views/dist/controls/menu-list/menu-list.js +25 -16
  80. package/views/dist/controls/modal/looks.d.ts +4 -0
  81. package/views/dist/controls/modal/looks.js +25 -0
  82. package/views/dist/controls/modal/modal.d.ts +69 -0
  83. package/views/dist/controls/modal/modal.js +62 -0
  84. package/views/dist/controls/modal/tokens.d.ts +192 -0
  85. package/views/dist/controls/modal/tokens.js +50 -0
  86. package/views/dist/controls/modal.css +130 -0
  87. package/views/dist/controls/notice/notice.d.ts +49 -0
  88. package/views/dist/controls/notice/notice.js +35 -0
  89. package/views/dist/controls/notice/tokens.d.ts +99 -0
  90. package/views/dist/controls/notice/tokens.js +27 -0
  91. package/views/dist/controls/notice.css +100 -0
  92. package/views/dist/controls/number-editor/number-editor.js +1 -1
  93. package/views/dist/controls/pane/looks.d.ts +4 -0
  94. package/views/dist/controls/pane/looks.js +11 -0
  95. package/views/dist/controls/pane/pane.d.ts +63 -0
  96. package/views/dist/controls/pane/pane.js +98 -0
  97. package/views/dist/controls/pane/state.d.ts +14 -0
  98. package/views/dist/controls/pane/state.js +7 -0
  99. package/views/dist/controls/pane/tokens.d.ts +79 -0
  100. package/views/dist/controls/pane/tokens.js +22 -0
  101. package/views/dist/controls/pane.css +104 -0
  102. package/views/dist/controls/picker/rows.d.ts +4 -2
  103. package/views/dist/controls/picker/rows.js +4 -3
  104. package/views/dist/controls/sort-editor/map-sort-body.d.ts +9 -0
  105. package/views/dist/controls/sort-editor/map-sort-body.js +81 -0
  106. package/views/dist/controls/sort-editor/rules.d.ts +48 -0
  107. package/views/dist/controls/sort-editor/rules.js +24 -0
  108. package/views/dist/controls/sort-editor/sort-editor.d.ts +58 -0
  109. package/views/dist/controls/sort-editor/sort-editor.js +180 -0
  110. package/views/dist/controls/sort-editor/tokens.d.ts +79 -0
  111. package/views/dist/controls/sort-editor/tokens.js +22 -0
  112. package/views/dist/controls/sort-editor/words.d.ts +48 -0
  113. package/views/dist/controls/sort-editor/words.js +25 -0
  114. package/views/dist/controls/sort-editor.css +96 -0
  115. package/views/dist/controls/toast/toast.d.ts +75 -0
  116. package/views/dist/controls/toast/toast.js +99 -0
  117. package/views/dist/controls/toast/tokens.d.ts +100 -0
  118. package/views/dist/controls/toast/tokens.js +27 -0
  119. package/views/dist/controls/toast.css +93 -0
  120. package/views/dist/controls/tokens.js +20 -0
  121. package/views/dist/controls/values-editor/values-editor.js +7 -1
  122. package/views/dist/display/date.js +2 -2
  123. package/views/dist/display/format.js +10 -2
  124. package/views/dist/display/options.d.ts +3 -1
  125. package/views/dist/display/use-display-options.d.ts +3 -0
  126. package/views/dist/display/use-display-options.js +10 -2
  127. package/views/dist/display/viewer.d.ts +1 -1
  128. package/views/dist/display/viewer.js +1 -1
  129. package/views/dist/editors/DateEditor.js +11 -9
  130. package/views/dist/editors/relation-panel.js +7 -1
  131. package/views/dist/editors/relation-picker.d.ts +2 -1
  132. package/views/dist/editors/relation-picker.js +4 -3
  133. package/views/dist/editors/relation-source.d.ts +4 -1
  134. package/views/dist/editors/relation-source.js +5 -2
  135. package/views/dist/field-row/editors/RowNumberEditor.js +2 -2
  136. package/views/dist/fields/number-edit.d.ts +6 -0
  137. package/views/dist/fields/number-edit.js +8 -1
  138. package/views/dist/grid/chrome/GridCellEditors.js +2 -2
  139. package/views/dist/grid/chrome/GridColumnDateSection.d.ts +4 -3
  140. package/views/dist/grid/chrome/GridColumnDateSection.js +4 -4
  141. package/views/dist/grid/chrome/GridColumnDurationSection.js +2 -2
  142. package/views/dist/grid/chrome/GridColumnMenu.js +6 -4
  143. package/views/dist/grid/chrome/GridFooter.js +2 -2
  144. package/views/dist/grid/chrome/grid-column-menu-items.js +4 -2
  145. package/views/dist/grid/chrome/useGridBandFigures.js +2 -2
  146. package/views/dist/grid/chrome/useGridFittedWidths.d.ts +3 -0
  147. package/views/dist/grid/chrome/useGridFittedWidths.js +9 -3
  148. package/views/dist/grid/chrome/useGridKeyboard.d.ts +4 -1
  149. package/views/dist/grid/chrome/useGridKeyboard.js +5 -2
  150. package/views/dist/grid/chrome/useGridTableInteractionModel.js +2 -1
  151. package/views/dist/grid/core/commit-model.d.ts +7 -0
  152. package/views/dist/grid/core/commit-model.js +5 -1
  153. package/views/dist/grid/core/editing-controller.js +10 -2
  154. package/views/dist/grid/core/editing-model.js +3 -7
  155. package/views/dist/grid/core/undo-owner.d.ts +6 -0
  156. package/views/dist/grid/core/undo-owner.js +13 -0
  157. package/views/dist/grid/core/useGridEditing.d.ts +2 -0
  158. package/views/dist/grid/core/useGridEditing.js +4 -0
  159. package/views/dist/looks/index.d.ts +5 -0
  160. package/views/dist/looks/index.js +5 -0
  161. package/views/dist/looks/pieces.js +10 -0
  162. package/views/dist/panels/model.d.ts +6 -1
  163. package/views/dist/panels/react/customize-body.d.ts +4 -2
  164. package/views/dist/panels/react/customize-body.js +3 -3
  165. package/views/dist/panels/react/customize.js +4 -2
  166. package/views/dist/panels/react/filter/FilterEditor.js +2 -2
  167. package/views/dist/panels/react/filter/PhoneFilterEditor.d.ts +8 -2
  168. package/views/dist/panels/react/filter/PhoneFilterEditor.js +9 -6
  169. package/views/dist/panels/react/filter/filter-body.d.ts +8 -5
  170. package/views/dist/panels/react/filter/filter-body.js +17 -6
  171. package/views/dist/panels/react/filter/filter-part-body.d.ts +4 -1
  172. package/views/dist/panels/react/filter/filter-part-body.js +3 -1
  173. package/views/dist/panels/react/panel-sheet.d.ts +5 -1
  174. package/views/dist/panels/react/panel-sheet.js +6 -2
  175. package/views/dist/panels/react/panel-step.d.ts +12 -0
  176. package/views/dist/panels/react/panel-step.js +26 -0
  177. package/views/dist/panels/react/sort/SortEditor.d.ts +4 -0
  178. package/views/dist/panels/react/sort/SortEditor.js +5 -2
  179. package/views/dist/panels/react/toolbar/ReadyToolbar.d.ts +8 -0
  180. package/views/dist/panels/react/toolbar/ReadyToolbar.js +84 -2
  181. package/views/dist/panels/react/toolbar/ToolbarBarFilter.js +2 -2
  182. package/views/dist/panels/react/toolbar/ToolbarFilterAdd.d.ts +16 -0
  183. package/views/dist/panels/react/toolbar/ToolbarFilterAdd.js +49 -0
  184. package/views/dist/panels/react/toolbar/ToolbarFilterSheet.js +3 -1
  185. package/views/dist/panels/react/toolbar/ToolbarFilters.d.ts +4 -1
  186. package/views/dist/panels/react/toolbar/ToolbarFilters.js +36 -21
  187. package/views/dist/panels/react/toolbar/ToolbarQuickFilters.d.ts +4 -1
  188. package/views/dist/panels/react/toolbar/ToolbarQuickFilters.js +2 -2
  189. package/views/dist/panels/react/toolbar/ToolbarSortPill.d.ts +5 -0
  190. package/views/dist/panels/react/toolbar/ToolbarSortPill.js +15 -6
  191. package/views/dist/panels/react/toolbar/panel-part.d.ts +5 -1
  192. package/views/dist/panels/react/toolbar/panel-part.js +2 -2
  193. package/views/dist/panels/react/toolbar/use-filter-add.d.ts +16 -0
  194. package/views/dist/panels/react/toolbar/use-filter-add.js +32 -0
  195. package/views/dist/panels/react.d.ts +1 -0
  196. package/views/dist/panels/react.js +1 -0
  197. package/views/dist/panels/settings/filter-groups.js +35 -1
  198. package/views/dist/panels/settings/group-buckets.js +1 -0
  199. package/views/dist/provider/ViewsProvider.d.ts +7 -1
  200. package/views/dist/provider/ViewsProvider.js +23 -3
  201. package/views/dist/provider/components.d.ts +30 -4
  202. package/views/dist/provider/moment.d.ts +6 -0
  203. package/views/dist/provider/moment.js +10 -0
  204. package/views/dist/styles.css +847 -52
  205. package/views/dist/styles.unlayered.css +848 -52
  206. package/views/docs/contract.md +15 -9
  207. package/views/docs/controls/alert-dialog.md +37 -0
  208. package/views/docs/controls/alert.md +30 -0
  209. package/views/docs/controls/collapsible.md +22 -0
  210. package/views/docs/controls/filter-editor.md +28 -0
  211. package/views/docs/controls/group-editor.md +11 -0
  212. package/views/docs/controls/modal.md +55 -0
  213. package/views/docs/controls/notice.md +32 -0
  214. package/views/docs/controls/pane.md +25 -0
  215. package/views/docs/controls/sort-editor.md +27 -0
  216. package/views/docs/controls/toast.md +32 -0
  217. package/views/docs/guides/cells.md +1 -1
  218. package/views/docs/guides/display.md +1 -1
  219. package/views/docs/guides/the-grid.md +1 -1
  220. package/views/docs/guides/the-provider.md +19 -0
  221. package/views/docs/reference/cells.md +2 -2
  222. package/views/docs/reference/controls.md +213 -7
  223. package/views/docs/reference/display.md +2 -2
  224. package/views/docs/reference/editors-relation.md +1 -1
  225. package/views/docs/reference/looks.md +10 -0
  226. package/views/docs/reference/panels-react.md +7 -6
  227. package/views/docs/reference/panels.md +1 -1
  228. package/views/docs/reference/react.md +7 -7
  229. package/views/docs/reference/views.md +1 -0
@@ -1,14 +1,22 @@
1
1
  "use client";
2
2
  import { useMemo } from "react";
3
3
  import { useViews } from "../provider/context.js";
4
+ import { useMoment } from "../provider/moment.js";
4
5
  import { DEFAULT_FIELD_PRESENTATION } from "./format.js";
5
6
  import { viewerFrom } from "./viewer.js";
6
- export function useDisplayOptions(opts) {
7
+ function useDisplayOptionsAt(opts, now) {
7
8
  const { conventions, messages, presentation } = useViews();
8
9
  const appPresentation = useMemo(() => presentation?.(DEFAULT_FIELD_PRESENTATION), [presentation]);
10
+ const viewer = useMemo(() => viewerFrom(conventions, messages, now), [conventions, messages, now]);
9
11
  return {
10
12
  ...opts,
11
13
  presentation: opts?.presentation ?? appPresentation,
12
- viewer: opts?.viewer ?? viewerFrom(conventions, messages),
14
+ viewer: opts?.viewer ?? viewer,
13
15
  };
14
16
  }
17
+ export function useDisplayOptions(opts) {
18
+ return useDisplayOptionsAt(opts, null);
19
+ }
20
+ export function useDateDisplayOptions(opts) {
21
+ return useDisplayOptionsAt(opts, useMoment());
22
+ }
@@ -1,4 +1,4 @@
1
1
  import type { FieldConventions } from "viewkitjs/fields";
2
2
  import { type ViewsMessageResolver } from "../contract.js";
3
3
  import type { FieldViewerContext } from "./options.js";
4
- export declare function viewerFrom(conventions: FieldConventions, messages?: ViewsMessageResolver, now?: Date): FieldViewerContext;
4
+ export declare function viewerFrom(conventions: FieldConventions, messages?: ViewsMessageResolver, now?: Date | null): FieldViewerContext;
@@ -5,7 +5,7 @@ export function viewerFrom(conventions, messages = resolveViewsMessage, now = ne
5
5
  language: conventions.language,
6
6
  timeZone: conventions.timeZone,
7
7
  ...(conventions.region ? { region: conventions.region } : {}),
8
- now,
8
+ ...(now ? { now } : {}),
9
9
  fieldMessages: conventions.messages,
10
10
  messages,
11
11
  };
@@ -6,6 +6,7 @@ import { fromDayKey, toDayKey } from "viewkitjs/fields/query";
6
6
  import { cx } from "../internal/cx.js";
7
7
  import { ELEMENT_RESET } from "../internal/reset.js";
8
8
  import { useViews } from "../provider/context.js";
9
+ import { useMoment } from "../provider/moment.js";
9
10
  import { isDesktopNow } from "../provider/desktop.js";
10
11
  import { usePickerForm } from "./picker-slot.js";
11
12
  import { tabbable, tabEnds } from "./tab-ends.js";
@@ -16,11 +17,11 @@ const QUICK_DAYS = {
16
17
  "next-monday": { key: "date.next-monday", offset: (weekday) => (8 - weekday) % 7 || 7 },
17
18
  "in-a-week": { key: "date.in-a-week", offset: () => 7 },
18
19
  };
19
- function todayOf(timeZone) {
20
- return fromDayKey(todayIn(timeZone));
20
+ function todayOf(timeZone, now) {
21
+ return fromDayKey(todayIn(timeZone, now));
21
22
  }
22
- function quickDay(offset, timeZone) {
23
- const today = todayOf(timeZone);
23
+ function quickDay(offset, timeZone, now) {
24
+ const today = todayOf(timeZone, now);
24
25
  return new Date(today.getFullYear(), today.getMonth(), today.getDate() + offset(today.getDay()));
25
26
  }
26
27
  const CALENDAR_START = "1900-01";
@@ -65,6 +66,7 @@ export const DateEditor = forwardRef(function DateEditor({ initial, timeOptional
65
66
  const timeRef = useRef(null);
66
67
  const dateRef = useRef(null);
67
68
  const views = useViews();
69
+ const now = useMoment() ?? undefined;
68
70
  const words = message ?? views.conventions.messages;
69
71
  const { Calendar, Input, DateBody } = views.components;
70
72
  const { List, Row } = views.atoms;
@@ -125,7 +127,7 @@ export const DateEditor = forwardRef(function DateEditor({ initial, timeOptional
125
127
  }, []);
126
128
  const applyDateText = () => {
127
129
  const current = dayRef.current ?? valid;
128
- const typed = parseDateText(dateTextRef.current, (current ?? todayOf(timeZone)).getFullYear());
130
+ const typed = parseDateText(dateTextRef.current, (current ?? todayOf(timeZone, now)).getFullYear());
129
131
  if (typed) {
130
132
  dayRef.current = typed;
131
133
  setDay(typed);
@@ -141,7 +143,7 @@ export const DateEditor = forwardRef(function DateEditor({ initial, timeOptional
141
143
  return { kind: "cancel" };
142
144
  if (clearedRef.current)
143
145
  return valid ? { kind: "commit", payload: "" } : { kind: "noop" };
144
- const year = (dayRef.current ?? valid ?? todayOf(timeZone)).getFullYear();
146
+ const year = (dayRef.current ?? valid ?? todayOf(timeZone, now)).getFullYear();
145
147
  const typed = parseDateText(dateTextRef.current, year);
146
148
  const d = typed ?? dayRef.current ?? valid;
147
149
  if (dayOnly) {
@@ -239,7 +241,7 @@ export const DateEditor = forwardRef(function DateEditor({ initial, timeOptional
239
241
  }
240
242
  onTabOut(event);
241
243
  };
242
- return (_jsx("div", { "data-slot": "vk-date-editor", className: "contents", onKeyDownCapture: onBodyKey, onPointerDownCapture: () => (enteredRef.current = false), onBlurCapture: onTabAway, children: _jsx(DateBody, { label: label ?? words({ key: "date.label" }), value: bodyValue, onValueChange: takeBodyValue, onDone: () => onRequestClose(enteredRef.current ? "enter" : "pick"), time: !dayOnly, empty: clearable, picks: clearable ? [...quickPicks, "none"] : [...quickPicks], today: todayIn(timeZone), typed: seed, autoFocus: focusDate || seed != null, form: form }) }));
244
+ return (_jsx("div", { "data-slot": "vk-date-editor", className: "contents", onKeyDownCapture: onBodyKey, onPointerDownCapture: () => (enteredRef.current = false), onBlurCapture: onTabAway, children: _jsx(DateBody, { label: label ?? words({ key: "date.label" }), value: bodyValue, onValueChange: takeBodyValue, onDone: () => onRequestClose(enteredRef.current ? "enter" : "pick"), time: !dayOnly, empty: clearable, picks: clearable ? [...quickPicks, "none"] : [...quickPicks], today: todayIn(timeZone, now), typed: seed, autoFocus: focusDate || seed != null, form: form }) }));
243
245
  }
244
246
  return (_jsxs("div", { "data-slot": "vk-date-editor", className: "contents", onKeyDownCapture: onTabOut, onBlurCapture: onTabAway, children: [_jsxs("div", { className: "flex items-center gap-1.5 border-b border-(color:--vk-border) p-2", children: [_jsxs("div", { className: "flex h-8 min-w-0 flex-1 items-center gap-2 rounded-lg bg-(color:--vk-neutral) px-2.5 focus-within:bg-(color:--vk-neutral-hovered)", children: [_jsx(DateGlyph, { className: "h-3.5 w-3.5 shrink-0 text-(color:--vk-fg-subtlest)" }), _jsx(Input, { ref: dateRef, type: "text", value: dateVal, onChange: (e) => {
245
247
  touchedRef.current = true;
@@ -286,14 +288,14 @@ export const DateEditor = forwardRef(function DateEditor({ initial, timeOptional
286
288
  }, className: cx(ELEMENT_RESET, "w-full px-3 py-1.5 text-left text-sm tabular-nums hover:bg-(color:--vk-hovered)", active ? "bg-(color:--vk-neutral) font-medium text-(color:--vk-fg)" : "text-(color:--vk-fg-subtle)"), children: t }, t));
287
289
  }) }))] }))] }), _jsx("div", { className: "flex gap-1 px-2 pt-2", children: quickPicks.map((pick) => (_jsx("button", { type: "button", onClick: (e) => {
288
290
  e.stopPropagation();
289
- chooseDay(quickDay(QUICK_DAYS[pick].offset, timeZone));
291
+ chooseDay(quickDay(QUICK_DAYS[pick].offset, timeZone, now));
290
292
  }, className: cx(ELEMENT_RESET, "h-7 rounded-md bg-(color:--vk-neutral) px-2 text-xs text-(color:--vk-fg-subtle) hover:bg-(color:--vk-neutral-hovered) hover:text-(color:--vk-fg)"), children: words({ key: QUICK_DAYS[pick].key }) }, pick))) }), _jsx(Calendar, { locale: views.conventions.locale, ...(fill ? { className: "w-full" } : {}), value: (day ?? valid) ? toDayKey((day ?? valid)) : null, onChange: (picked) => {
291
293
  const d = picked ? fromDayKey(picked) : null;
292
294
  if (d)
293
295
  chooseDay(d);
294
296
  else if (dayOnly && dayRef.current)
295
297
  chooseDay(dayRef.current);
296
- }, month: toDayKey(month ?? todayOf(timeZone)).slice(0, 7), onMonthChange: (next) => setMonth(fromDayKey(`${next}-01`) ?? undefined), captionLayout: "dropdown", startMonth: CALENDAR_START, endMonth: CALENDAR_END }), clearable && (_jsx("div", { ref: clearRef, className: "border-t border-(color:--vk-border) py-1", children: _jsx(List, { children: _jsx(Row, { size: "compact", tone: "muted", label: words({ key: "date.clear" }), onClick: () => {
298
+ }, month: toDayKey(month ?? todayOf(timeZone, now)).slice(0, 7), onMonthChange: (next) => setMonth(fromDayKey(`${next}-01`) ?? undefined), captionLayout: "dropdown", startMonth: CALENDAR_START, endMonth: CALENDAR_END }), clearable && (_jsx("div", { ref: clearRef, className: "border-t border-(color:--vk-border) py-1", children: _jsx(List, { children: _jsx(Row, { size: "compact", tone: "muted", label: words({ key: "date.clear" }), onClick: () => {
297
299
  clearedRef.current = true;
298
300
  onRequestClose("pick");
299
301
  } }) }) }))] }));
@@ -36,5 +36,11 @@ export function RelationPanel({ candidates, query, onQueryChange, searchRef, onS
36
36
  : (value, search) => {
37
37
  const label = rows.find((candidate) => candidate.id === value)?.label ?? labels?.get(value) ?? "";
38
38
  return label.toLowerCase().includes(search.toLowerCase()) ? 1 : 0;
39
- }, children: [_jsx(Command.Input, { ref: searchRef, placeholder: words({ key: "editor.search" }), className: "h-9 text-(length:--vk-input-text,13px)", value: query, onValueChange: onQueryChange, onKeyDown: onSearchKeyDown }), _jsxs(Command.List, { className: "max-h-72 overscroll-contain scrollbar-overlay", children: [remote ? (status && (_jsx("div", { role: "status", className: "py-4 text-center text-xs text-(color:--vk-fg-subtle)", children: status }))) : (_jsx(Command.Empty, { className: "py-4 text-center text-xs text-(color:--vk-fg-subtle)", children: words({ key: "editor.nothing-matches" }) })), _jsx(Command.Group, { className: "p-0", children: _jsxs(List, { children: [before?.({ glyphs, glyph }), shown.map((candidate) => (_jsx(Command.Item, { value: candidate.id, onSelect: () => onSelect(candidate), chosen: isChosen(candidate.id), children: _jsx(RowContent, { size: "compact", leading: glyph(candidate.icon ?? kindGlyph), leadingLane: glyphs, label: candidate.label, description: candidate.sublabel, trailing: candidate.badge ? (_jsx("span", { className: "ml-2 shrink-0 rounded-sm border border-(color:--vk-border) px-1.5 py-0.5 text-(length:--vk-caption-text,10px) font-medium uppercase tracking-wide text-(color:--vk-fg-subtle)", children: candidate.badge })) : undefined, chosen: isChosen(candidate.id), chosenTint: false }) }, candidate.id)))] }) }), paging && _jsx(EndOfListSentinel, { onReveal: page.loadMore }), moreStatus && (_jsx("div", { role: "status", className: "py-3 text-center text-xs text-(color:--vk-fg-subtle)", children: moreStatus }))] }), creates && creates.length > 0 && (_jsx("div", { className: "border-t border-(color:--vk-border)", children: creates.map((create, index) => (_jsx(Row, { size: "compact", tone: "muted", leading: _jsx(Add, { className: "h-3.5 w-3.5 shrink-0" }), label: create.label(query.trim()), onClick: () => onCreate(create, query.trim()) }, index))) }))] }));
39
+ }, children: [_jsx(Command.Input, { ref: searchRef, placeholder: words({ key: "editor.search" }), className: "h-9 text-(length:--vk-input-text,13px)", value: query, onValueChange: onQueryChange, onKeyDown: (event) => {
40
+ if (remote && page.searching && event.key === "Enter") {
41
+ event.preventDefault();
42
+ return;
43
+ }
44
+ onSearchKeyDown?.(event);
45
+ } }), _jsxs(Command.List, { className: "max-h-72 overscroll-contain scrollbar-overlay", children: [remote ? (status && (_jsx("div", { role: "status", className: "py-4 text-center text-xs text-(color:--vk-fg-subtle)", children: status }))) : (_jsx(Command.Empty, { className: "py-4 text-center text-xs text-(color:--vk-fg-subtle)", children: words({ key: "editor.nothing-matches" }) })), _jsx(Command.Group, { className: "p-0", children: _jsxs(List, { children: [before?.({ glyphs, glyph }), shown.map((candidate) => (_jsx(Command.Item, { value: candidate.id, onSelect: () => onSelect(candidate), chosen: isChosen(candidate.id), children: _jsx(RowContent, { size: "compact", leading: glyph(candidate.icon ?? kindGlyph), leadingLane: glyphs, label: candidate.label, description: candidate.sublabel, trailing: candidate.badge ? (_jsx("span", { className: "ml-2 shrink-0 rounded-sm border border-(color:--vk-border) px-1.5 py-0.5 text-(length:--vk-caption-text,10px) font-medium uppercase tracking-wide text-(color:--vk-fg-subtle)", children: candidate.badge })) : undefined, chosen: isChosen(candidate.id), chosenTint: false }) }, candidate.id)))] }) }), paging && _jsx(EndOfListSentinel, { onReveal: page.loadMore }), moreStatus && (_jsx("div", { role: "status", className: "py-3 text-center text-xs text-(color:--vk-fg-subtle)", children: moreStatus }))] }), creates && creates.length > 0 && (_jsx("div", { className: "border-t border-(color:--vk-border)", children: creates.map((create, index) => (_jsx(Row, { size: "compact", tone: "muted", leading: _jsx(Add, { className: "h-3.5 w-3.5 shrink-0" }), label: create.label(query.trim()), onClick: () => onCreate(create, query.trim()) }, index))) }))] }));
40
46
  }
@@ -11,7 +11,8 @@ export type RelationHeld = {
11
11
  };
12
12
  /** What a relation's list hands the app's body, worked out once for its `Picker` and its `LinksBody`: the rows (held
13
13
  * records first, while they match the query), the ids it handed out, a handed id's candidate, the page's states and
14
- * the host's create rows as actions. ViewKit filters a static source and fetches a remote one. */
14
+ * the host's create rows as actions. ViewKit filters a static source and fetches a remote one. While a remote list searches,
15
+ * the rows are the held records that match alone: no row of the last answer is handed, so none can be picked. */
15
16
  export declare function useRelationRows({ candidates, query, held, kindGlyph, creates, onCreate, }: {
16
17
  candidates: RelationSource;
17
18
  query: string;
@@ -9,7 +9,8 @@ export function useRelationRows({ candidates, query, held, kindGlyph, creates, o
9
9
  const Add = views.icons.add;
10
10
  const remote = candidates.kind === "remote";
11
11
  const page = useRemotePage(candidates, query);
12
- const rows = candidates.kind === "static" ? candidates.items.filter((candidate) => matches(candidate.label, query)) : page.items;
12
+ const searching = remote && page.searching;
13
+ const rows = candidates.kind === "static" ? candidates.items.filter((candidate) => matches(candidate.label, query)) : searching ? [] : page.items;
13
14
  const heldIds = new Set(held.map((record) => record.id));
14
15
  const shownHeld = held.filter((record) => matches(record.label, query));
15
16
  const byId = new Map();
@@ -34,9 +35,9 @@ export function useRelationRows({ candidates, query, held, kindGlyph, creates, o
34
35
  items,
35
36
  handed: new Set([...items.map((item) => item.value), ...heldIds]),
36
37
  found: (id) => byId.get(id),
37
- doing: !remote ? undefined : page.searching ? "searching" : page.failed && page.items.length === 0 ? "failed" : undefined,
38
+ doing: !remote ? undefined : searching ? "searching" : page.failed && page.items.length === 0 ? "failed" : undefined,
38
39
  onRetry: remote && page.failed && page.items.length === 0 ? page.retry : undefined,
39
- onMore: remote && !page.exhausted && page.items.length > 0 ? page.loadMore : undefined,
40
+ onMore: remote && !searching && !page.exhausted && page.items.length > 0 ? page.loadMore : undefined,
40
41
  actions: creates?.map((create, index) => ({
41
42
  key: `create-${index}`,
42
43
  label: create.label(trimmed),
@@ -21,8 +21,11 @@ export type RemotePage = {
21
21
  /** Every row of every page loaded for the current query, in order. Kept on
22
22
  * screen while the next query's first page loads. */
23
23
  items: RelationCandidate[];
24
- /** The FIRST page of a query is in flight. */
24
+ /** The list on screen isn't the answer to the query typed: from the keystroke, through the debounce and the first
25
+ * page's request (VK-821). Its rows are the last query's meanwhile, so nothing may be taken from them. */
25
26
  searching: boolean;
27
+ /** The query whose first page was last asked; null before any. Required: every page state carries it. */
28
+ asked: string | null;
26
29
  /** A LATER page is in flight — the rows stay, a line appears under them. */
27
30
  loadingMore: boolean;
28
31
  /** The last request failed. A first page's failure clears the rows; a later
@@ -5,6 +5,7 @@ export const RELATION_SEARCH_DEBOUNCE_MS = 200;
5
5
  export const RELATION_PAGE_SIZE = 20;
6
6
  const EMPTY = {
7
7
  items: [],
8
+ asked: null,
8
9
  loadingMore: false,
9
10
  failed: false,
10
11
  offset: 0,
@@ -35,12 +36,14 @@ export function useRemotePage(source, query) {
35
36
  searching: !append,
36
37
  loadingMore: append,
37
38
  failed: false,
39
+ asked: append ? previous.asked : nextQuery,
38
40
  }));
39
41
  search(nextQuery, controller.signal, offset).then((items) => {
40
42
  if (controller.signal.aborted)
41
43
  return;
42
44
  setPage((previous) => ({
43
45
  items: append ? [...previous.items, ...items] : items,
46
+ asked: previous.asked,
44
47
  searching: false,
45
48
  loadingMore: false,
46
49
  failed: false,
@@ -74,7 +77,7 @@ export function useRemotePage(source, query) {
74
77
  }, [remote, query, run]);
75
78
  const loadMore = useCallback(() => {
76
79
  const current = pageRef.current;
77
- if (!remote || current.searching || current.loadingMore || current.exhausted)
80
+ if (!remote || current.searching || current.loadingMore || current.exhausted || queryRef.current !== current.asked)
78
81
  return;
79
82
  run(queryRef.current, current.offset);
80
83
  }, [remote, run]);
@@ -84,7 +87,7 @@ export function useRemotePage(source, query) {
84
87
  abortRef.current?.abort();
85
88
  run(queryRef.current, 0);
86
89
  }, [remote, run]);
87
- return { ...page, loadMore, retry };
90
+ return { ...page, searching: remote && (page.searching || query !== page.asked), loadMore, retry };
88
91
  }
89
92
  export function EndOfListSentinel({ onReveal }) {
90
93
  const ref = useRef(null);
@@ -6,7 +6,7 @@ import { ConversionLine } from "../../display/converted.js";
6
6
  import { EditorPanel } from "../../editors/EditorPanel.js";
7
7
  import { NumberEditor } from "../../editors/NumberEditor.js";
8
8
  import { numberBounds } from "../../editors/number-body.js";
9
- import { durationUnitOf, numberEditCode, numberEditDecimals } from "../../fields/number-edit.js";
9
+ import { durationUnitOf, numberEditCode, numberEditDecimals, numberEditInitial } from "../../fields/number-edit.js";
10
10
  import { useViews } from "../../provider/context.js";
11
11
  import { ROW_BOX_FRAME } from "./row-frame.js";
12
12
  import { RowRefusal, useRowEditSession } from "./row-session.js";
@@ -23,7 +23,7 @@ export function RowNumberEditor({ binding, row, field, initial, conversion, onAt
23
23
  const read = acceptFieldCommit(field, { value, ...(unit === undefined ? {} : { unit }) }, { conventions, unitOptions });
24
24
  return read.ok ? null : read.reason;
25
25
  };
26
- return (_jsxs(EditorPanel, { session: session, title: field.label, anchor: anchorRef, inPlace: true, children: [_jsx(NumberEditor, { ref: editorRef, boxClassName: ROW_BOX_FRAME, initial: typeof initial === "number" ? initial : Number.NaN, unit: binding.unit?.read(row), unitOptions: unitOptions, code: binding.unit ? undefined : numberEditCode(field), decimals: decimals, durationUnit: durationUnit, allowEmpty: !!field.nullable, align: "start", conventions: conventions, ...numberBounds(field), ...(body
26
+ return (_jsxs(EditorPanel, { session: session, title: field.label, anchor: anchorRef, inPlace: true, children: [_jsx(NumberEditor, { ref: editorRef, boxClassName: ROW_BOX_FRAME, initial: numberEditInitial(initial), unit: binding.unit?.read(row), unitOptions: unitOptions, code: binding.unit ? undefined : numberEditCode(field), decimals: decimals, durationUnit: durationUnit, allowEmpty: !!field.nullable, align: "start", conventions: conventions, ...numberBounds(field), ...(body
27
27
  ? {
28
28
  type: field.type,
29
29
  label: field.label,
@@ -15,3 +15,9 @@ export declare function numberEditDecimals(field: FieldDef): number;
15
15
  export declare function numberEditCode(field: FieldDef): string | undefined;
16
16
  /** The unit a duration field STORES (spec §8.4) — `undefined` for anything else. */
17
17
  export declare function durationUnitOf(field: FieldDef): DurationUnit | undefined;
18
+ /**
19
+ * What a number editor opens on: the number, or a stored decimal's text read as one (`"120.50"` → 120.5, a
20
+ * `storage: "decimal"` field's row value, VK-817); anything else is empty (NaN). The text is read for drawing the
21
+ * box, never for arithmetic: the save still goes through the field's own write.
22
+ */
23
+ export declare function numberEditInitial(value: unknown): number;
@@ -1,4 +1,4 @@
1
- import { isIntegerField, presentedDef, valueTypeOf, } from "viewkitjs/fields";
1
+ import { isIntegerField, numberOfDecimalText, presentedDef, valueTypeOf, } from "viewkitjs/fields";
2
2
  export function numberEditDecimals(field) {
3
3
  if (isIntegerField(field))
4
4
  return 0;
@@ -19,3 +19,10 @@ export function durationUnitOf(field) {
19
19
  ? (def.format.unit ?? "ms")
20
20
  : undefined;
21
21
  }
22
+ export function numberEditInitial(value) {
23
+ if (typeof value === "number")
24
+ return value;
25
+ if (typeof value === "string")
26
+ return numberOfDecimalText(value) ?? Number.NaN;
27
+ return Number.NaN;
28
+ }
@@ -1,7 +1,7 @@
1
1
  "use client";
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
3
  import { useMemo } from "react";
4
- import { numberEditCode, numberEditDecimals } from "../../fields/number-edit.js";
4
+ import { numberEditCode, numberEditDecimals, numberEditInitial } from "../../fields/number-edit.js";
5
5
  import { numberBounds } from "../../editors/number-body.js";
6
6
  import { convertedFromOf } from "../../fields/money.js";
7
7
  import { renderTypedCellValue } from "../../cells/cell-values.js";
@@ -53,7 +53,7 @@ function InlineEditor({ ctx }) {
53
53
  const durationUnit = col.format?.style === "duration" ? (col.format.unit ?? "ms") : undefined;
54
54
  const field = col.field ?? legacyFieldFromColumn(col);
55
55
  const valueType = valueTypeOf(field);
56
- return (_jsx(GridNumberEditor, { title: col.header, initial: typeof baseline === "number" ? baseline : Number.NaN, seed: ctx.editSeed ?? undefined, unit: col.editUnit?.value(row), unitOptions: col.editUnit?.options, code: col.editUnit ? undefined : numberEditCode(field), type: valueType === "currency" || valueType === "percent" ? valueType : "number", bounds: numberBounds(field), decimals: integer ? 0 : (ctx.decimals ?? fallback), durationUnit: durationUnit, allowEmpty: !!col.clearable, unitLeft: col.align === "right", conversion: convertedFromOf(col, row) ? renderTypedCellValue(col, row, { decimals: ctx.decimals }) : undefined, refuse: (payload) => refusal(payload, cellPrevPayload(col, baseline, col.editUnit?.value(row))), onCommit: (payload) => onCommitCell(row, rowId, col.id, cellPrevPayload(col, baseline, col.editUnit?.value(row)), payload, { overlay: gridFigureDrawsAtOnce(col, row, payload) ? "figure" : false }), onCancel: onCancel, onTab: onTab, onEnter: onEnter }));
56
+ return (_jsx(GridNumberEditor, { title: col.header, initial: numberEditInitial(baseline), seed: ctx.editSeed ?? undefined, unit: col.editUnit?.value(row), unitOptions: col.editUnit?.options, code: col.editUnit ? undefined : numberEditCode(field), type: valueType === "currency" || valueType === "percent" ? valueType : "number", bounds: numberBounds(field), decimals: integer ? 0 : (ctx.decimals ?? fallback), durationUnit: durationUnit, allowEmpty: !!col.clearable, unitLeft: col.align === "right", conversion: convertedFromOf(col, row) ? renderTypedCellValue(col, row, { decimals: ctx.decimals }) : undefined, refuse: (payload) => refusal(payload, cellPrevPayload(col, baseline, col.editUnit?.value(row))), onCommit: (payload) => onCommitCell(row, rowId, col.id, cellPrevPayload(col, baseline, col.editUnit?.value(row)), payload, { overlay: gridFigureDrawsAtOnce(col, row, payload) ? "figure" : false }), onCancel: onCancel, onTab: onTab, onEnter: onEnter }));
57
57
  }
58
58
  if (ctx.editorKind === "range") {
59
59
  const def = col.field?.type === "range" ? col.field : undefined;
@@ -2,9 +2,10 @@ import type { ListColumn } from "../../model/column-schema.js";
2
2
  import type { ListDateStyle } from "../../model/column-format.js";
3
3
  import { type GridFlyouts } from "./GridFlyout.js";
4
4
  export declare const DATE_STYLES: ListDateStyle[];
5
- /** The live sample beside each style: a few days back, so Relative reads as a
6
- * real "3d ago" rather than the "now" it would say of the moment it opened. */
7
- export declare const sampleDate: () => Date;
5
+ /** The live sample beside each style: a few days before the provider's moment, so Relative reads as a real "3d ago"
6
+ * rather than the "now" it would say of the moment it opened. None before the provider has a moment: the clock is
7
+ * never read while drawing. */
8
+ export declare const sampleDate: (now: Date | undefined) => Date | null;
8
9
  /**
9
10
  * The date-column row in the header menu — one Format row whose flyout holds
10
11
  * the styles (each beside a live sample) and, on a date-time, Show time —
@@ -8,15 +8,15 @@ import { useViews } from "../../provider/context.js";
8
8
  import { GridFlyoutRow } from "./GridFlyout.js";
9
9
  import { GridMenuSeparator, KnobGlyph } from "./GridMenuRow.js";
10
10
  export const DATE_STYLES = ["short", "long", "numeric", "relative"];
11
- export const sampleDate = () => new Date(Date.now() - 3 * 86_400_000);
11
+ export const sampleDate = (now) => now ? new Date(now.getTime() - 3 * 86_400_000) : null;
12
12
  export function GridColumnDateSection({ column, dateStyle, onDateStyleChange, showTime, onShowTimeChange, flyouts, onClose, }) {
13
13
  const activeDateStyle = dateStyle ?? column.format?.dateStyle ?? "short";
14
- const sample = sampleDate();
15
- const { viewer } = useCellFormat();
14
+ const { viewer, presentation } = useCellFormat();
15
+ const sample = sampleDate(viewer.now);
16
16
  const { atoms, messages } = useViews();
17
17
  const { Row } = atoms;
18
18
  const styleLabel = (style) => messages({ key: "views.menus.date-style", values: { style } });
19
- return (_jsxs(GridFlyoutRow, { id: "date-format", flyouts: flyouts, label: messages({ key: "views.menus.format" }), detail: styleLabel(activeDateStyle), leading: _jsx(KnobGlyph, { name: "calendar" }), children: [DATE_STYLES.map((style) => (_jsx(Row, { chosen: activeDateStyle === style, label: styleLabel(style), detail: _jsx("span", { className: "max-w-30 truncate", children: formatDate(sample, column, style, false, viewer) }), onClick: () => {
19
+ return (_jsxs(GridFlyoutRow, { id: "date-format", flyouts: flyouts, label: messages({ key: "views.menus.format" }), detail: styleLabel(activeDateStyle), leading: _jsx(KnobGlyph, { name: "calendar" }), children: [DATE_STYLES.map((style) => (_jsx(Row, { chosen: activeDateStyle === style, label: styleLabel(style), detail: _jsx("span", { className: "max-w-30 truncate", children: sample && formatDate(sample, column, style, false, viewer, presentation) }), onClick: () => {
20
20
  onDateStyleChange(fieldKeyOf(column), style);
21
21
  onClose();
22
22
  } }, style))), onShowTimeChange && temporalKindOf(column) === "datetime" && (_jsxs(_Fragment, { children: [_jsx(GridMenuSeparator, {}), _jsx(Row, { chosen: !!showTime, label: messages({ key: "views.menus.show-time" }), onClick: () => onShowTimeChange(fieldKeyOf(column), !showTime) })] }))] }));
@@ -2,7 +2,7 @@
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
3
  import { fieldKeyOf } from "../../model/view-rules.js";
4
4
  import { formatNumber } from "./cells.js";
5
- import { useCellFormat } from "../../cells/use-cell-format.js";
5
+ import { useUndatedCellFormat } from "../../cells/use-cell-format.js";
6
6
  import { useViews } from "../../provider/context.js";
7
7
  import { GridFlyoutRow } from "./GridFlyout.js";
8
8
  import { KnobGlyph } from "./GridMenuRow.js";
@@ -10,7 +10,7 @@ export const DURATION_STYLES = ["adaptive", "clock", "units"];
10
10
  export const DURATION_SAMPLE_MS = 5_904_000;
11
11
  export function GridColumnDurationSection({ column, durationStyle, onDurationStyleChange, flyouts, onClose, }) {
12
12
  const activeDurationStyle = durationStyle ?? column.format?.durationStyle ?? "adaptive";
13
- const cellFormat = useCellFormat();
13
+ const cellFormat = useUndatedCellFormat();
14
14
  const { atoms, messages } = useViews();
15
15
  const { Row } = atoms;
16
16
  const styleLabel = (style) => messages({ key: "views.menus.duration-style", values: { style } });
@@ -1,10 +1,11 @@
1
1
  "use client";
2
2
  import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
- import { cloneElement, useState, } from "react";
3
+ import { cloneElement, use, useState, } from "react";
4
4
  import { columnLabel } from "../../model/column-capabilities.js";
5
5
  import { columnKnobs } from "../../model/column-knobs.js";
6
- import { useCellFormat } from "../../cells/use-cell-format.js";
6
+ import { cellFormatAt, useUndatedCellFormat } from "../../cells/use-cell-format.js";
7
7
  import { useViews } from "../../provider/context.js";
8
+ import { MomentContext } from "../../provider/moment.js";
8
9
  import { columnMenuGates, gridColumnMenuItems } from "./grid-column-menu-items.js";
9
10
  import { GridColumnColorSection } from "./GridColumnColorSection.js";
10
11
  import { GridColumnDateSection } from "./GridColumnDateSection.js";
@@ -30,7 +31,8 @@ export function GridColumnMenu({ column, values, viewBacked = false, sort, group
30
31
  const [anchor, setAnchor] = useState(null);
31
32
  const menuFocus = useGridMenuFocus(open, anchor);
32
33
  const press = useGridMenuPress(open);
33
- const cellFormat = useCellFormat();
34
+ const cellFormat = useUndatedCellFormat();
35
+ const moment = open ? use(MomentContext) : null;
34
36
  const { atoms, components, icons, messages, menus } = useViews();
35
37
  const { Popover, Menu } = components;
36
38
  const { List } = atoms;
@@ -74,7 +76,7 @@ export function GridColumnMenu({ column, values, viewBacked = false, sort, group
74
76
  if (!offers)
75
77
  return _jsx(_Fragment, { children: children });
76
78
  const items = open
77
- ? gridColumnMenuItems(column, { ...offer, optionColors, dateStyle, showTime, durationStyle, percentDisplay, numberFormat, onHide, appItems }, gates, { messages, icons, cellFormat, close })
79
+ ? gridColumnMenuItems(column, { ...offer, optionColors, dateStyle, showTime, durationStyle, percentDisplay, numberFormat, onHide, appItems }, gates, { messages, icons, cellFormat: cellFormatAt(cellFormat, moment), close })
78
80
  : [];
79
81
  const menuTrigger = cloneElement(children, {
80
82
  ref: setAnchor,
@@ -4,7 +4,7 @@ import { cx } from "../../internal/cx.js";
4
4
  import { CellSuffix } from "../../display/format.js";
5
5
  import { aggregateLabel, aggregateOptions, resolveAggregateKind } from "../../model/aggregates.js";
6
6
  import { DEFAULT_DISPLAY_CURRENCY } from "../../fields/currency.js";
7
- import { useCellFormat } from "../../cells/use-cell-format.js";
7
+ import { useUndatedCellFormat } from "../../cells/use-cell-format.js";
8
8
  import { gridFigureValue } from "./grid-figure-value.js";
9
9
  import { useViews } from "../../provider/context.js";
10
10
  import { GridAggregateMenu } from "./GridAggregateMenu.js";
@@ -18,7 +18,7 @@ export function gridFooterShown({ interactive, hostCells, }) {
18
18
  }
19
19
  export function GridFooter({ group, columns, selecting, aggregates, numberFormats, renderAggregate, onAggregateChange, viewBacked = false, frozenCount = 0, frozenLeft, continuation, defaultCurrency = DEFAULT_DISPLAY_CURRENCY, pageOnly = false, pin, ariaRowIndex, ariaLevel, ariaColOffset = 0, }) {
20
20
  const interactive = !!onAggregateChange;
21
- const cellFormat = useCellFormat();
21
+ const cellFormat = useUndatedCellFormat();
22
22
  const { messages } = useViews();
23
23
  const hostCells = columns.map((column) => renderAggregate?.(column.id, group) ?? null);
24
24
  const sourced = group.figures
@@ -140,7 +140,7 @@ export function gridColumnMenuItems(column, props, gates, deps) {
140
140
  if (gates.canDate) {
141
141
  const active = props.dateStyle ?? column.format?.dateStyle ?? "short";
142
142
  const word = (style) => messages({ key: "views.menus.date-style", values: { style } });
143
- const sample = sampleDate();
143
+ const sample = sampleDate(cellFormat.viewer.now);
144
144
  knobs.push({
145
145
  key: "date-format",
146
146
  label: messages({ key: "views.menus.format" }),
@@ -150,7 +150,9 @@ export function gridColumnMenuItems(column, props, gates, deps) {
150
150
  children: DATE_STYLES.map((style) => ({
151
151
  key: `date-format:${style}`,
152
152
  label: word(style),
153
- detail: formatDate(sample, column, style, false, cellFormat.viewer),
153
+ detail: sample
154
+ ? formatDate(sample, column, style, false, cellFormat.viewer, cellFormat.presentation)
155
+ : undefined,
154
156
  checked: active === style,
155
157
  onSelect: then(() => props.onDateStyleChange(key, style)),
156
158
  })),
@@ -3,11 +3,11 @@ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-run
3
3
  import { columnLabel } from "../../model/column-capabilities.js";
4
4
  import { DEFAULT_DISPLAY_CURRENCY } from "../../fields/currency.js";
5
5
  import { CellSuffix } from "../../display/format.js";
6
- import { useCellFormat } from "../../cells/use-cell-format.js";
6
+ import { useUndatedCellFormat } from "../../cells/use-cell-format.js";
7
7
  import { gridFigureValue } from "./grid-figure-value.js";
8
8
  const words = (label) => typeof label === "string" || typeof label === "number" ? String(label) : undefined;
9
9
  export function useGridBandFigures(figures, { columns, numberFormats, defaultCurrency = DEFAULT_DISPLAY_CURRENCY, renderAggregate, }) {
10
- const cellFormat = useCellFormat();
10
+ const cellFormat = useUndatedCellFormat();
11
11
  const drawn = [];
12
12
  for (const figure of figures ?? []) {
13
13
  if ("render" in figure) {
@@ -17,6 +17,9 @@ export declare const GridFitContext: import("react").Context<(() => void) | null
17
17
  * A grid drawn where nothing is laid out (under a box `hidden` or `display: none` takes out of the page) reads every
18
18
  * box at 0: it keeps none of those reads, and fits once it is laid out, when its size first changes.
19
19
  *
20
+ * A date column waits for the provider's moment: until it is read its values draw in full ("15 Feb 2026"), then short
21
+ * ("15 Feb"), so it is fitted in the commit that draws them as they stay.
22
+ *
20
23
  * `skip`: columns left at their default (on a phone, the pinned ones). `fit` runs after the grid's own commits and,
21
24
  * through `GridFitContext`, after each group's.
22
25
  */
@@ -2,24 +2,30 @@
2
2
  import { createContext, useCallback, useLayoutEffect, useRef, useState } from "react";
3
3
  import { flushSync } from "react-dom";
4
4
  import { fittedColumnWidth } from "../../model/column-state.js";
5
+ import { fieldTypeOf } from "../../model/field-type-of.js";
6
+ import { useHasMoment } from "../../provider/moment.js";
7
+ const DATED = new Set(["date", "datetime"]);
5
8
  const NATURAL = { width: "max-content", minWidth: "0", maxWidth: "none", flex: "none" };
6
9
  export const GridFitContext = createContext(null);
7
10
  export function useGridFittedWidths({ rootRef, columns, stored, scale, skip, }) {
8
11
  const [fitted, setFitted] = useState({});
9
- const latest = useRef({ columns, stored, scale, skip });
12
+ const moment = useHasMoment();
13
+ const latest = useRef({ columns, stored, scale, skip, moment });
10
14
  const done = useRef({});
11
15
  useLayoutEffect(() => {
12
- latest.current = { columns, stored, scale, skip };
16
+ latest.current = { columns, stored, scale, skip, moment };
13
17
  });
14
18
  const fit = useCallback(() => {
15
19
  const root = rootRef.current;
16
20
  if (!root)
17
21
  return;
18
- const { columns, stored, scale, skip } = latest.current;
22
+ const { columns, stored, scale, skip, moment } = latest.current;
19
23
  const reads = [];
20
24
  for (const col of columns) {
21
25
  if (col.width != null || stored?.[col.id] != null || done.current[col.id] != null || skip?.has(col.id))
22
26
  continue;
27
+ if (!moment && DATED.has(fieldTypeOf(col) ?? ""))
28
+ continue;
23
29
  const id = CSS.escape(col.id);
24
30
  const cells = [...root.querySelectorAll(`[data-col-id="${id}"]`)];
25
31
  if (cells.length > 0)
@@ -5,7 +5,7 @@ import type { ListSettingsConfig } from "../../model/column-capabilities.js";
5
5
  import type { ListColumn } from "../../model/column-schema.js";
6
6
  import type { GridRangeVerbs } from "./useGridRangeActions.js";
7
7
  import { type GridChromeTarget, type GridFocusShape } from "../core/grid-focus.js";
8
- export declare function useGridKeyboard<Row>({ rootRef, focusedCell, editingCell, editingEnabled, listConfig, visibleRowIds, rowByKey, visibleColIds, visibleColumns, rows, getRowId, pendingByRow, rangeVerbsRef, focusCell, clearFocus, startEdit, cancelEdit, commitEdit, refuseEdit, undo, redo, rangeSetRect, rangeExtendTo, ranges, revealCell, releaseToFrame, lastCellRef, chrome, setChrome, shape, toggleGroup, }: {
8
+ export declare function useGridKeyboard<Row>({ rootRef, focusedCell, editingCell, editingEnabled, listConfig, visibleRowIds, rowByKey, visibleColIds, visibleColumns, rows, getRowId, pendingByRow, rangeVerbsRef, focusCell, clearFocus, startEdit, cancelEdit, commitEdit, refuseEdit, undo, redo, isLastEdited, rangeSetRect, rangeExtendTo, ranges, revealCell, releaseToFrame, lastCellRef, chrome, setChrome, shape, toggleGroup, }: {
9
9
  rootRef: RefObject<HTMLDivElement | null>;
10
10
  /** A column name, a footer cell, a bar or a checkbox holding the focus (`useGridFocus`); null: a data cell, or
11
11
  * nothing. */
@@ -58,6 +58,9 @@ export declare function useGridKeyboard<Row>({ rootRef, focusedCell, editingCell
58
58
  refuseEdit: (columnId: string) => boolean;
59
59
  undo: (resolveRow: (rowId: string) => Row | undefined, onApply?: (pos: GridCellPos) => void) => boolean;
60
60
  redo: (resolveRow: (rowId: string) => Row | undefined, onApply?: (pos: GridCellPos) => void) => boolean;
61
+ /** This grid is the one the page edited last (`useGridEditing`'s `isLastEdited`): with the focus in no grid's frame,
62
+ * only it answers ⌘Z. Absent: it always is. */
63
+ isLastEdited?: () => boolean;
61
64
  }): {
62
65
  onEditorTab: (rowId: string, columnId: string, backwards: boolean) => void;
63
66
  onEditorEnter: (rowId: string, columnId: string) => void;
@@ -30,7 +30,7 @@ function eventBelongsElsewhere(target, root) {
30
30
  return true;
31
31
  return !!target.closest(INTERACTIVE) && !root?.contains(target);
32
32
  }
33
- export function useGridKeyboard({ rootRef, focusedCell, editingCell, editingEnabled, listConfig, visibleRowIds, rowByKey, visibleColIds, visibleColumns, rows, getRowId, pendingByRow, rangeVerbsRef, focusCell, clearFocus, startEdit, cancelEdit, commitEdit, refuseEdit, undo, redo, rangeSetRect, rangeExtendTo, ranges, revealCell, releaseToFrame, lastCellRef, chrome = null, setChrome = () => { }, shape, toggleGroup, }) {
33
+ export function useGridKeyboard({ rootRef, focusedCell, editingCell, editingEnabled, listConfig, visibleRowIds, rowByKey, visibleColIds, visibleColumns, rows, getRowId, pendingByRow, rangeVerbsRef, focusCell, clearFocus, startEdit, cancelEdit, commitEdit, refuseEdit, undo, redo, isLastEdited = () => true, rangeSetRect, rangeExtendTo, ranges, revealCell, releaseToFrame, lastCellRef, chrome = null, setChrome = () => { }, shape, toggleGroup, }) {
34
34
  const { ports, messages } = useViews();
35
35
  const navFromEditorRef = useRef({ tab: () => { }, enter: () => { } });
36
36
  const onEditorTab = useCallback((rowId, columnId, backwards) => navFromEditorRef.current.tab(rowId, columnId, backwards), []);
@@ -75,6 +75,9 @@ export function useGridKeyboard({ rootRef, focusedCell, editingCell, editingEnab
75
75
  return;
76
76
  if (eventBelongsElsewhere(event.target, rootRef.current))
77
77
  return;
78
+ const holder = event.target?.closest?.('[data-slot="vk-grid"]') ?? null;
79
+ if (holder ? holder !== rootRef.current : !isLastEdited())
80
+ return;
78
81
  const resolveRow = (rowId) => rows.find((row) => getRowId(row) === rowId);
79
82
  const handled = event.shiftKey
80
83
  ? redo(resolveRow, scrollToCell)
@@ -84,7 +87,7 @@ export function useGridKeyboard({ rootRef, focusedCell, editingCell, editingEnab
84
87
  };
85
88
  window.addEventListener("keydown", onKeyDown, true);
86
89
  return () => window.removeEventListener("keydown", onKeyDown, true);
87
- }, [editingEnabled, focusCell, getRowId, redo, revealCell, rootRef, rowByKey, rows, rowsWait, undo, visibleRowIds]);
90
+ }, [editingEnabled, focusCell, getRowId, isLastEdited, redo, revealCell, rootRef, rowByKey, rows, rowsWait, undo, visibleRowIds]);
88
91
  const entryCell = useCallback(() => {
89
92
  const root = rootRef.current;
90
93
  const columnId = visibleColIds[0];
@@ -35,7 +35,7 @@ export function useGridTableInteractionModel({ rootRef, props, rows, visibleRows
35
35
  const columnById = useMemo(() => new Map([...columns, ...visibleColumns].map((column) => [column.id, column])), [columns, visibleColumns]);
36
36
  const partOfWhole = useCallback((wholeId) => [...columnById.values()].find((column) => column.partOf?.column === wholeId)?.partOf, [columnById]);
37
37
  const keepsSent = useCallback((columnId) => partOfWhole(columnId) != null, [partOfWhole]);
38
- const { focused: focusedCell, editing: editingCell, pendingByRow, pendingOf, settlementByRow, writeStateByRow, focusCell, clearFocus, startEdit, cancelEdit, closeEdit, commitEdit: commitEditRaw, commitBatch: commitBatchRaw, undo, redo, reconcile, hasInflight, pendingBaseline, sent, sentCells, forgetSent, } = useGridEditing(props.onCellCommit, props.onCellsCommit, sayRefusal, keepsSent);
38
+ const { focused: focusedCell, editing: editingCell, pendingByRow, pendingOf, settlementByRow, writeStateByRow, focusCell, clearFocus, startEdit, cancelEdit, closeEdit, commitEdit: commitEditRaw, commitBatch: commitBatchRaw, undo, redo, reconcile, hasInflight, pendingBaseline, sent, sentCells, forgetSent, isLastEdited, } = useGridEditing(props.onCellCommit, props.onCellsCommit, sayRefusal, keepsSent);
39
39
  const wholeStored = useCallback((rowId, wholeId, row) => {
40
40
  const part = partOfWhole(wholeId);
41
41
  const overlay = pendingOf(rowId);
@@ -293,6 +293,7 @@ export function useGridTableInteractionModel({ rootRef, props, rows, visibleRows
293
293
  refuseEdit,
294
294
  undo,
295
295
  redo,
296
+ isLastEdited,
296
297
  rangeSetRect,
297
298
  rangeExtendTo,
298
299
  ranges,
@@ -45,4 +45,11 @@ export type GridCellsCommitFn<Row> = (edits: {
45
45
  value: unknown;
46
46
  context?: GridCommitContext;
47
47
  }[]) => Promise<void | GridCommitOutcome[]>;
48
+ /** A cell's key: its row and column ids as one JSON pair. It is read back whole (`gridCellFromKey`), never split at a
49
+ * character, so no id can break it, whatever it holds. */
48
50
  export declare function gridCellKey(rowId: string, columnId: string): string;
51
+ /** The row and column a cell's key names (`gridCellKey`). */
52
+ export declare function gridCellFromKey(key: string): {
53
+ rowId: string;
54
+ columnId: string;
55
+ };
@@ -1,3 +1,7 @@
1
1
  export function gridCellKey(rowId, columnId) {
2
- return `${rowId}:${columnId}`;
2
+ return JSON.stringify([rowId, columnId]);
3
+ }
4
+ export function gridCellFromKey(key) {
5
+ const [rowId, columnId] = JSON.parse(key);
6
+ return { rowId, columnId };
3
7
  }