@tristan2828/ui-foundation 4.139.0 → 4.141.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.
@@ -16,7 +16,7 @@
16
16
  - Step 8: Add Playwright specs for all three screens · lines 255–335
17
17
  - Step 9: Register the nav entry and route names · lines 336–349
18
18
  - Step 10: `npm run verify`. · lines 350–351
19
- - [Step 6 in detail](#step-6-in-detail) · lines 353–929
19
+ - [Step 6 in detail](#step-6-in-detail) · lines 353–933
20
20
  - [A `reference`](#a-reference) · lines 358–360
21
21
  - [A `single choice`](#a-single-choice) · lines 362–368
22
22
  - [A `date-time`](#a-date-time) · lines 370–373
@@ -25,32 +25,32 @@
25
25
  - [A `multi reference`](#a-multi-reference) · lines 393–405
26
26
  - [Sub-records](#sub-records) · lines 407–423
27
27
  - [A `computed` field](#a-computed-field) · lines 425–434
28
- - [A `date`](#a-date) · lines 436–453
29
- - [A `month-day`](#a-month-day) · lines 455–475
30
- - [A `recurrence`](#a-recurrence) · lines 477–498
31
- - [An image on a record](#an-image-on-a-record) · lines 500–528
32
- - [A `reference` inside a sub-record item](#a-reference-inside-a-sub-record-item) · lines 530–589
33
- - [A `yes/no` marked `toggle`](#a-yesno-marked-toggle) · lines 591–606
34
- - [Keep column definitions stable](#keep-column-definitions-stable) · lines 608–616
35
- - [The view](#the-view) · lines 618–736
36
- - [The view: long text and notes](#the-view-long-text-and-notes) · lines 738–792
37
- - [The view: quick actions and editing in place](#the-view-quick-actions-and-editing-in-place) · lines 794–852
38
- - [The table opens the view, and the form returns to it](#the-table-opens-the-view-and-the-form-returns-to-it) · lines 854–865
39
- - [`<SelectValue>` shows the value, not the label](#selectvalue-shows-the-value-not-the-label) · lines 867–913
40
- - [Choosing how each column looks](#choosing-how-each-column-looks) · lines 915–929
41
- - [How a list opens a record](#how-a-list-opens-a-record) · lines 931–1435
42
- - [The record view](#the-record-view) · lines 1074–1254
43
- - [Forms](#forms) · lines 1256–1339
44
- - [Dialogs](#dialogs) · lines 1341–1374
45
- - [Toasts and feedback](#toasts-and-feedback) · lines 1376–1435
46
- - [What not to copy](#what-not-to-copy) · lines 1437–1464
47
- - [After a commit, in the backend](#after-a-commit-in-the-backend) · lines 1466–1483
48
- - [Saves that don't overwrite](#saves-that-dont-overwrite) · lines 1485–1545
49
- - [Deleting](#deleting) · lines 1547–1577
50
- - [Fields only a script writes](#fields-only-a-script-writes) · lines 1579–1598
51
- - [Searching one part of the app](#searching-one-part-of-the-app) · lines 1600–1609
52
- - [What a chat is told about an entity](#what-a-chat-is-told-about-an-entity) · lines 1612–1654
53
- - [Behind a sign-in proxy](#behind-a-sign-in-proxy) · lines 1656–1689
28
+ - [A `date`](#a-date) · lines 436–457
29
+ - [A `month-day`](#a-month-day) · lines 459–479
30
+ - [A `recurrence`](#a-recurrence) · lines 481–502
31
+ - [An image on a record](#an-image-on-a-record) · lines 504–532
32
+ - [A `reference` inside a sub-record item](#a-reference-inside-a-sub-record-item) · lines 534–593
33
+ - [A `yes/no` marked `toggle`](#a-yesno-marked-toggle) · lines 595–610
34
+ - [Keep column definitions stable](#keep-column-definitions-stable) · lines 612–620
35
+ - [The view](#the-view) · lines 622–740
36
+ - [The view: long text and notes](#the-view-long-text-and-notes) · lines 742–796
37
+ - [The view: quick actions and editing in place](#the-view-quick-actions-and-editing-in-place) · lines 798–856
38
+ - [The table opens the view, and the form returns to it](#the-table-opens-the-view-and-the-form-returns-to-it) · lines 858–869
39
+ - [`<SelectValue>` shows the value, not the label](#selectvalue-shows-the-value-not-the-label) · lines 871–917
40
+ - [Choosing how each column looks](#choosing-how-each-column-looks) · lines 919–933
41
+ - [How a list opens a record](#how-a-list-opens-a-record) · lines 935–1439
42
+ - [The record view](#the-record-view) · lines 1078–1258
43
+ - [Forms](#forms) · lines 1260–1343
44
+ - [Dialogs](#dialogs) · lines 1345–1378
45
+ - [Toasts and feedback](#toasts-and-feedback) · lines 1380–1439
46
+ - [What not to copy](#what-not-to-copy) · lines 1441–1468
47
+ - [After a commit, in the backend](#after-a-commit-in-the-backend) · lines 1470–1487
48
+ - [Saves that don't overwrite](#saves-that-dont-overwrite) · lines 1489–1549
49
+ - [Deleting](#deleting) · lines 1551–1581
50
+ - [Fields only a script writes](#fields-only-a-script-writes) · lines 1583–1602
51
+ - [Searching one part of the app](#searching-one-part-of-the-app) · lines 1604–1613
52
+ - [What a chat is told about an entity](#what-a-chat-is-told-about-an-entity) · lines 1616–1658
53
+ - [Behind a sign-in proxy](#behind-a-sign-in-proxy) · lines 1660–1693
54
54
 
55
55
  <!-- /index -->
56
56
 
@@ -449,7 +449,11 @@ date like 3/14 or Mar 14" and gives `''`. Editing in place is
449
449
  `inPlace.date({ value, save })`: Enter or leaving saves the day typed,
450
450
  a day picked in the calendar saves at once. (`typing={false}` is the
451
451
  button alone; in place then `editInPlace({ kind: 'choice', ... })` with
452
- `defaultOpen`, `modal={false}` and `onChange={(day) => props.commit(day)}`.) The backend column
452
+ `defaultOpen`, `modal={false}` and `onChange={(day) => props.commit(day)}`.) The calendar's weeks
453
+ start on Monday. An app whose weeks start on Sunday gives `DateField`,
454
+ `inPlace.date`, `FilterDate` and `FillInField` `weekStart="SU"`, the
455
+ `weekStart` it gives `MonthCalendar` and `RecurrenceField` (a `Calendar`
456
+ of its own takes react-day-picker's `weekStartsOn={0}`). The backend column
453
457
  is a SQL `date` (`datetime.date` in the model).
454
458
 
455
459
  ### A `month-day`
@@ -41,10 +41,10 @@
41
41
  - [23. A Group menu, and a record read beside the list](#23-a-group-menu-and-a-record-read-beside-the-list) · lines 1843–1894
42
42
  - [24. A stored colour beside its name](#24-a-stored-colour-beside-its-name) · lines 1896–1970
43
43
  - [Picking one on a form: `ColorField`](#picking-one-on-a-form-colorfield) · lines 1916–1970
44
- - [25. A list's tools: views, filters, columns, row actions, a phone's rows](#25-a-lists-tools-views-filters-columns-row-actions-a-phones-rows) · lines 1972–2183
45
- - [The framed look, and sibling lists beside the title](#the-framed-look-and-sibling-lists-beside-the-title) · lines 2132–2183
46
- - [26. A record's related list, capped](#26-a-records-related-list-capped) · lines 2185–2219
47
- - [27. A repeat and its next time](#27-a-repeat-and-its-next-time) · lines 2221–2268
44
+ - [25. A list's tools: views, filters, columns, row actions, a phone's rows](#25-a-lists-tools-views-filters-columns-row-actions-a-phones-rows) · lines 1972–2184
45
+ - [The framed look, and sibling lists beside the title](#the-framed-look-and-sibling-lists-beside-the-title) · lines 2133–2184
46
+ - [26. A record's related list, capped](#26-a-records-related-list-capped) · lines 2186–2220
47
+ - [27. A repeat and its next time](#27-a-repeat-and-its-next-time) · lines 2222–2269
48
48
 
49
49
  <!-- /index -->
50
50
 
@@ -2094,7 +2094,8 @@ const { filters, multiFilters, setFilter, setFilters, setMultiFilter, activeView
2094
2094
  inclusive plain days (`{ to: yesterday }`, `{ from: today }`), read
2095
2095
  against today when the list loads; its chip's words are
2096
2096
  `dateFilterText(value)`. A list filtered in the browser (or a mock) uses
2097
- `dateFilterKeeps(value, day)`.
2097
+ `dateFilterKeeps(value, day)`. Its calendars' weeks start on Monday,
2098
+ `weekStart="SU"` for Sunday.
2098
2099
 
2099
2100
  ```tsx
2100
2101
  const VIEWS = {
@@ -43,7 +43,7 @@
43
43
  - [Values edited in place: the presets' looks](#values-edited-in-place-the-presets-looks) · lines 1970–1989
44
44
  - [A quick add line](#a-quick-add-line) · lines 1991–2019
45
45
  - [A month calendar](#a-month-calendar) · lines 2021–2051
46
- - [The sidebar and the phone's bar](#the-sidebar-and-the-phones-bar) · lines 2053–2105
46
+ - [The sidebar and the phone's bar](#the-sidebar-and-the-phones-bar) · lines 2053–2112
47
47
 
48
48
  <!-- /index -->
49
49
 
@@ -2069,6 +2069,7 @@ const nav: NavEntry[] = [
2069
2069
  const bottomBar: BottomBarItem[] = [
2070
2070
  { to: '/', label: 'Home', icon: HouseIcon },
2071
2071
  { group: 'Every day', icon: SunIcon, sheet: 'tiles' },
2072
+ { search: true, icon: SearchIcon },
2072
2073
  ]
2073
2074
  ```
2074
2075
 
@@ -2099,7 +2100,13 @@ const bottomBar: BottomBarItem[] = [
2099
2100
  the hub). It replaces a page's own back link; the bar sits outside
2100
2101
  `<main>`, so the page's links are still the only ones in it.
2101
2102
  - **Search in the bar** (`search={{ placeholder, findRecords, recent }}`):
2102
- a box from 48rem up, a search button on a phone, and the shortcut
2103
- (Ctrl K, ⌘K on a Mac) open a palette of the nav's pages, the records
2103
+ a box from 48rem up, a search button on a phone (the bar's instead,
2104
+ where it has Search), and the shortcut (Ctrl K, ⌘K on a Mac) open a palette of the nav's pages, the records
2104
2105
  opened lately on this device (`useRecentRecord`) and the app's records
2105
2106
  under their `kind`.
2107
+ - **Search on the phone's bar** (`{ search: true, icon: SearchIcon }` in
2108
+ `bottomBar`): a button named Search among the bar's items, opening the
2109
+ same palette in thumb reach. It is an action, not a place: never the
2110
+ current item and never counted. It takes the place of the header's
2111
+ button on a phone, so there is one Search. Without `search`, or past the
2112
+ bar's fifth item, it isn't drawn and the header is as without it.
@@ -52,7 +52,8 @@ One or two sentences: what one record is, and who uses the screens.
52
52
  check).
53
53
  - *From the package, no Widget example:* `date` (a calendar day, no
54
54
  time: OpenAPI `format: date`; the foundation's `DateField`; say
55
- whether it's optional), `month-day` (a day that comes round every
55
+ whether it's optional, and the day the app's weeks start on when it
56
+ isn't Monday (`weekStart`)), `month-day` (a day that comes round every
56
57
  year, no year: `'MM-DD'`; the foundation's `MonthDayField`; say
57
58
  whether it's optional), `recurrence` (how it repeats: the
58
59
  foundation's `Recurrence` schema and `RecurrenceField`; say whether
@@ -4,10 +4,13 @@ import { type BottomBarItem, type NavEntry, type NavLook } from './app-shell-nav
4
4
  * plus the bar (4rem and its 1px border) and the phone's safe area.
5
5
  */
6
6
  export declare const BOTTOM_BAR_PADDING = "max-md:pb-[calc(--spacing(22)+1px+env(safe-area-inset-bottom))]";
7
- export declare function BottomBar({ items, nav, activeTo, navLook, }: {
7
+ export declare function BottomBar({ items, nav, activeTo, navLook, onSearch, }: {
8
+ /** The items drawn (bottomBarItems). */
8
9
  items: readonly BottomBarItem[];
9
10
  nav: readonly NavEntry[];
10
11
  activeTo: string | undefined;
11
12
  /** The shell's `navLook`: a section's sheet follows its look when its item sets no `sheet`. */
12
13
  navLook?: NavLook;
14
+ /** Opens the search palette, for the button pressed. */
15
+ onSearch: (opener: HTMLElement) => void;
13
16
  }): import("react").JSX.Element;
@@ -6,7 +6,8 @@ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-run
6
6
  // their children, under them, by heading where they have them), or with
7
7
  // `sheet: 'tiles'` a grid of the entries as tiles, icon over label, like
8
8
  // a phone's home screen. The sheet closes on navigation, as the
9
- // sidebar's does. The item holding the current page is marked
9
+ // sidebar's does. Or an item is Search, a button that opens the header's
10
+ // own palette (search-palette.tsx), in place of the header's button. The item holding the current page is marked
10
11
  // (`aria-current`). An entry's `count` shows on the phone as it does in
11
12
  // the sidebar: a badge on a bar item's icon (a page's own, or the sum of a
12
13
  // section's), in a tile's corner, at a sheet link's end; nothing at 0 or
@@ -95,22 +96,23 @@ function SheetTiles({ items, activeTo, withPages, }) {
95
96
  return (_jsx("li", { className: "flex min-w-0", children: _jsxs(Link, { to: to, "aria-current": current, className: `${TILE_CLASS} flex-1`, children: [_jsx(Icon, { "aria-hidden": "true" }), _jsx(CountedLabel, { label: label, count: count, countLabel: countLabel, className: "max-w-full break-words" }), _jsx(TileCount, { count: count })] }) }, to));
96
97
  }) }), withPages && _jsx(SheetPageTiles, { items: items, activeTo: activeTo })] }));
97
98
  }
98
- export function BottomBar({ items, nav, activeTo, navLook = 'list', }) {
99
+ export function BottomBar({ items, nav, activeTo, navLook = 'list', onSearch, }) {
99
100
  // The section open, and the location it was opened at: following a link
100
101
  // in the sheet (or anywhere) moves to a new location, which closes it.
101
102
  const [opened, setOpened] = useState(null);
102
103
  const { key } = useLocation();
103
104
  const openGroup = opened?.at === key ? opened.group : null;
104
105
  const setOpenGroup = (group) => setOpened(group === null ? null : { group, at: key });
105
- // At most five: a sixth wouldn't fit a phone's width with its label.
106
- const shown = items.slice(0, 5);
107
- const current = bottomBarCurrent(shown, nav, activeTo);
106
+ const current = bottomBarCurrent(items, nav, activeTo);
108
107
  const section = openGroup === null ? undefined : bottomBarSection(nav, openGroup);
109
- const openItem = shown.find((item) => 'group' in item && item.group === openGroup);
108
+ const openItem = items.find((item) => 'group' in item && item.group === openGroup);
110
109
  const tiles = openItem !== undefined && bottomBarTiles(openItem, section, navLook);
111
110
  // The current entry's pages show under the tiles when the section's own look is tiles.
112
111
  const withPages = (section?.look ?? navLook) === 'tiles';
113
- return (_jsxs(_Fragment, { children: [_jsx("nav", { "aria-label": "Bottom Bar", "data-slot": "app-shell-bottom-bar", className: "fixed inset-x-0 bottom-0 z-20 border-t border-border bg-background pb-[env(safe-area-inset-bottom)] md:hidden", children: _jsx("ul", { className: "flex h-16 items-stretch gap-1 px-2 py-1.5", children: shown.map((item, index) => {
112
+ return (_jsxs(_Fragment, { children: [_jsx("nav", { "aria-label": "Bottom Bar", "data-slot": "app-shell-bottom-bar", className: "fixed inset-x-0 bottom-0 z-20 border-t border-border bg-background pb-[env(safe-area-inset-bottom)] md:hidden", children: _jsx("ul", { className: "flex h-16 items-stretch gap-1 px-2 py-1.5", children: items.map((item, index) => {
113
+ if ('search' in item) {
114
+ return (_jsx("li", { className: "flex min-w-0 flex-1", children: _jsxs("button", { type: "button", "data-slot": "bottom-bar-search", "aria-haspopup": "dialog", onClick: (event) => onSearch(event.currentTarget), className: ITEM_CLASS, children: [_jsx(BarIcon, { icon: item.icon }), _jsx("span", { className: "max-w-full truncate", children: "Search" })] }) }, "search"));
115
+ }
114
116
  const isCurrent = index === current;
115
117
  const { count, countLabel } = bottomBarCount(item, nav);
116
118
  if ('to' in item) {
@@ -179,9 +179,9 @@ export declare function trailBackTarget(nav: readonly NavEntry[], pathname: stri
179
179
  } | undefined;
180
180
  /**
181
181
  * One item of `AppShell`'s `bottomBar`, the phone's bar of shortcuts: a
182
- * page, or one of the nav's sections by its label, which opens a sheet of
183
- * that section's entries. `label` is a shorter name for the bar
184
- * ("Household" for "Home and money").
182
+ * page, one of the nav's sections by its label, which opens a sheet of
183
+ * that section's entries, or Search. A section's `label` is a shorter name
184
+ * for the bar ("Household" for "Home and money").
185
185
  */
186
186
  export type BottomBarItem = {
187
187
  to: string;
@@ -198,7 +198,23 @@ export type BottomBarItem = {
198
198
  * it, the section's look decides (`NavSection.look`, `navLook`).
199
199
  */
200
200
  sheet?: 'list' | 'tiles';
201
+ } | {
202
+ /**
203
+ * A button named Search that opens the shell's search palette, the
204
+ * one its header opens, in place of the header's own button on a
205
+ * phone. Never the current page, and never counted. Drawn only with
206
+ * the shell's `search`.
207
+ */
208
+ search: true;
209
+ /** The header's is lucide's `SearchIcon`. */
210
+ icon: IconComponent;
201
211
  };
212
+ /**
213
+ * The bar's items that are drawn: Search only when the shell has it, so
214
+ * without it an item after it takes its place, and a bar of Search alone
215
+ * is no bar.
216
+ */
217
+ export declare function bottomBarItems(items: readonly BottomBarItem[] | undefined, hasSearch: boolean): readonly BottomBarItem[];
202
218
  /**
203
219
  * Whether a bottom bar item's sheet is tiles: its own `sheet`, or else
204
220
  * its section's look (the section's `look`, or the shell's `navLook`).
@@ -218,8 +234,11 @@ export declare function bottomBarSection(nav: readonly NavEntry[], label: string
218
234
  /**
219
235
  * Which bar item holds the current page (`activeTo`, from activeNavTo):
220
236
  * the page's own link, or else the section it's in, children included.
237
+ * Never Search.
221
238
  */
222
239
  export declare function bottomBarCurrent(items: readonly BottomBarItem[], nav: readonly NavEntry[], activeTo: string | undefined): number | undefined;
240
+ /** Whether the bar draws Search, of its drawn items (bottomBarItems). */
241
+ export declare function bottomBarHasSearch(drawn: readonly BottomBarItem[]): boolean;
223
242
  /**
224
243
  * A count as drawn: nothing at 0, below it or while it's loading (no
225
244
  * count yet), and "99+" past 99, so a badge keeps its size.
@@ -235,6 +254,7 @@ export declare function navCountSpoken(count: number | undefined, countLabel?: s
235
254
  * A bottom bar item's count: a page's, from its nav entry, or a
236
255
  * section's, the sum of its entries' and their pages'. A section's
237
256
  * `countLabel` is its entries' when they share one, and none otherwise.
257
+ * Search has none.
238
258
  */
239
259
  export declare function bottomBarCount(item: BottomBarItem, nav: readonly NavEntry[]): {
240
260
  count?: number;
@@ -164,6 +164,15 @@ export function trailBackTarget(nav, pathname, trail) {
164
164
  .find((crumb) => crumb.href);
165
165
  return above?.href ? { label: above.label, to: above.href } : fromNav;
166
166
  }
167
+ /**
168
+ * The bar's items that are drawn: Search only when the shell has it, so
169
+ * without it an item after it takes its place, and a bar of Search alone
170
+ * is no bar.
171
+ */
172
+ export function bottomBarItems(items, hasSearch) {
173
+ // At most five: a sixth wouldn't fit a phone's width with its label.
174
+ return (items ?? []).filter((item) => hasSearch || !('search' in item)).slice(0, 5);
175
+ }
167
176
  /**
168
177
  * Whether a bottom bar item's sheet is tiles: its own `sheet`, or else
169
178
  * its section's look (the section's `look`, or the shell's `navLook`).
@@ -205,6 +214,7 @@ export function bottomBarSection(nav, label) {
205
214
  /**
206
215
  * Which bar item holds the current page (`activeTo`, from activeNavTo):
207
216
  * the page's own link, or else the section it's in, children included.
217
+ * Never Search.
208
218
  */
209
219
  export function bottomBarCurrent(items, nav, activeTo) {
210
220
  if (activeTo === undefined)
@@ -215,6 +225,10 @@ export function bottomBarCurrent(items, nav, activeTo) {
215
225
  const group = items.findIndex((item) => 'group' in item && withChildren(bottomBarSection(nav, item.group)?.items ?? []).some((entry) => entry.to === activeTo));
216
226
  return group === -1 ? undefined : group;
217
227
  }
228
+ /** Whether the bar draws Search, of its drawn items (bottomBarItems). */
229
+ export function bottomBarHasSearch(drawn) {
230
+ return drawn.some((item) => 'search' in item);
231
+ }
218
232
  /**
219
233
  * A count as drawn: nothing at 0, below it or while it's loading (no
220
234
  * count yet), and "99+" past 99, so a badge keeps its size.
@@ -239,8 +253,11 @@ export function navCountSpoken(count, countLabel) {
239
253
  * A bottom bar item's count: a page's, from its nav entry, or a
240
254
  * section's, the sum of its entries' and their pages'. A section's
241
255
  * `countLabel` is its entries' when they share one, and none otherwise.
256
+ * Search has none.
242
257
  */
243
258
  export function bottomBarCount(item, nav) {
259
+ if ('search' in item)
260
+ return {};
244
261
  if ('to' in item) {
245
262
  const entry = navItems(nav).find((other) => other.to === item.to);
246
263
  return entry ? { count: entry.count, countLabel: entry.countLabel } : {};
@@ -63,10 +63,12 @@ export type AppShellProps = {
63
63
  /**
64
64
  * A bar of shortcuts at the bottom of a phone's screen (below the md
65
65
  * breakpoint), in thumb reach: at most five, each a page
66
- * (`{ to, label, icon }`) or a nav section by its label
66
+ * (`{ to, label, icon }`), a nav section by its label
67
67
  * (`{ group: 'Every day', icon }`, with an optional shorter `label`),
68
68
  * which opens a sheet of that section's entries (as tiles with
69
- * `sheet: 'tiles'`). The item holding the
69
+ * `sheet: 'tiles'`), or Search (`{ search: true, icon: SearchIcon }`),
70
+ * a button that opens `search`'s palette, drawn only with `search` and
71
+ * in place of the header's button on a phone. The item holding the
70
72
  * current page is marked. The header's menu button stays, for
71
73
  * everything, except on a page below a nav entry, where the back arrow
72
74
  * takes its place. The shell pads its content so nothing sits under the bar.
@@ -86,8 +88,8 @@ export type AppShellProps = {
86
88
  navLook?: NavLook;
87
89
  /**
88
90
  * Search in the header: a box ("Search", or `placeholder`) from
89
- * md up and a button on a phone, both opening a palette (Ctrl K, ⌘K on
90
- * a Mac) that finds the nav's pages by name and, with `findRecords`,
91
+ * md up and a button on a phone (the bottom bar's Search instead, where
92
+ * `bottomBar` has it), both opening a palette (Ctrl K, ⌘K on a Mac) that finds the nav's pages by name and, with `findRecords`,
91
93
  * the app's records, listed under their kinds; Enter opens the one
92
94
  * highlighted. Before you type it lists the records opened lately
93
95
  * (`useRecentRecord`), `recent` of them. No search, no box.
@@ -1,11 +1,11 @@
1
1
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { ChevronLeftIcon, ChevronRightIcon, LogOutIcon, MoonIcon, PaletteIcon, Rows3Icon, SunIcon } from 'lucide-react';
3
3
  import { useTheme } from 'next-themes';
4
- import { useCallback, useEffect, useId, useMemo, useState } from 'react';
4
+ import { useCallback, useEffect, useId, useMemo, useRef, useState } from 'react';
5
5
  import { Link, Navigate, Outlet, useLocation } from 'react-router';
6
6
  import { useAuth } from '../../auth/use-auth.js';
7
7
  import { BottomBar, BOTTOM_BAR_PADDING } from './app-shell-bottom-bar.js';
8
- import { activeNavTo, childItems, childRuns, childrenOpen, isNavItemGroup, navCountSpoken, navCountText, navGroups, navPageLabel, navTooltip, navTrail, trailBackTarget, withChildren, } from './app-shell-nav.js';
8
+ import { activeNavTo, bottomBarHasSearch, bottomBarItems, childItems, childRuns, childrenOpen, isNavItemGroup, navCountSpoken, navCountText, navGroups, navPageLabel, navTooltip, navTrail, trailBackTarget, withChildren, } from './app-shell-nav.js';
9
9
  import { versionHref, versionLabel } from './app-shell-version.js';
10
10
  import { ErrorState } from './error-state.js';
11
11
  import { PageTrail } from './page-trail.js';
@@ -233,6 +233,8 @@ export function AppShell({ title, logo: Logo, nav, sidebarExtra, defaultSidebarO
233
233
  const [pageTrail, setPageTrail] = useState(null);
234
234
  const set = useCallback((owner, crumbs) => setPageTrail({ owner, crumbs }), []);
235
235
  const clear = useCallback((owner) => setPageTrail((current) => (current?.owner === owner ? null : current)), []);
236
+ // The header's palette, for the bottom bar's Search.
237
+ const paletteRef = useRef(null);
236
238
  const trailSlot = useMemo(() => ({ set, clear }), [set, clear]);
237
239
  if (status === 'loading') {
238
240
  return _jsx(AppShellSkeleton, {});
@@ -254,6 +256,8 @@ export function AppShell({ title, logo: Logo, nav, sidebarExtra, defaultSidebarO
254
256
  return _jsx(Navigate, { to: "/login", replace: true, state: isLoggingOut ? undefined : { from } });
255
257
  }
256
258
  const activeTo = activeNavTo(nav, location.pathname);
259
+ const barItems = bottomBarItems(bottomBar, search !== undefined);
260
+ const hasBar = barItems.length > 0;
257
261
  const ownTrail = pageTrail?.crumbs ?? null;
258
262
  const back = trailBackTarget(nav, location.pathname, ownTrail);
259
263
  const trail = ownTrail ?? navTrail(nav, location.pathname);
@@ -268,5 +272,5 @@ export function AppShell({ title, logo: Logo, nav, sidebarExtra, defaultSidebarO
268
272
  // (AuthProvider), so this stays a deliberate logout: a
269
273
  // clean /login, never the previous user's page as `from`.
270
274
  logout().catch(() => { });
271
- }, children: _jsx(LogOutIcon, {}) })] })] })] }) }), _jsx(PageTrailContext.Provider, { value: trailSlot, children: _jsxs("div", { "data-slot": "app-shell-column", className: "flex w-full min-w-0 flex-1 flex-col bg-background", children: [_jsxs("header", { className: "flex h-14 shrink-0 items-center gap-2 border-b border-border px-4", children: [back && _jsx(PhoneBack, { back: back }), _jsx(SidebarTrigger, { className: cn(back && bottomBar?.length && 'max-md:hidden') }), _jsx("div", { "data-slot": "app-shell-trail", className: "min-w-0 flex-1", children: trail.length > 0 && _jsx(PageTrail, { crumbs: trail, "aria-label": "You are here", className: "max-md:hidden" }) }), search && _jsx(SearchPalette, { search: search, nav: nav }), _jsx(LookControl, {})] }), _jsx(OfflineNotice, {}), _jsx(SidebarInset, { className: "min-w-0", children: _jsx("div", { className: cn('flex-1 p-6', bottomBar?.length && BOTTOM_BAR_PADDING), children: _jsx(Outlet, {}) }) })] }) }), bottomBar && bottomBar.length > 0 && _jsx(BottomBar, { items: bottomBar, nav: nav, activeTo: activeTo, navLook: navLook })] }), _jsx(Toaster, {})] }));
275
+ }, children: _jsx(LogOutIcon, {}) })] })] })] }) }), _jsx(PageTrailContext.Provider, { value: trailSlot, children: _jsxs("div", { "data-slot": "app-shell-column", className: "flex w-full min-w-0 flex-1 flex-col bg-background", children: [_jsxs("header", { className: "flex h-14 shrink-0 items-center gap-2 border-b border-border px-4", children: [back && _jsx(PhoneBack, { back: back }), _jsx(SidebarTrigger, { className: cn(back && hasBar && 'max-md:hidden') }), _jsx("div", { "data-slot": "app-shell-trail", className: "min-w-0 flex-1", children: trail.length > 0 && _jsx(PageTrail, { crumbs: trail, "aria-label": "You are here", className: "max-md:hidden" }) }), search && _jsx(SearchPalette, { ref: paletteRef, search: search, nav: nav, onBar: bottomBarHasSearch(barItems) }), _jsx(LookControl, {})] }), _jsx(OfflineNotice, {}), _jsx(SidebarInset, { className: "min-w-0", children: _jsx("div", { className: cn('flex-1 p-6', hasBar && BOTTOM_BAR_PADDING), children: _jsx(Outlet, {}) }) })] }) }), hasBar && (_jsx(BottomBar, { items: barItems, nav: nav, activeTo: activeTo, navLook: navLook, onSearch: (opener) => paletteRef.current?.openFrom(opener) }))] }), _jsx(Toaster, {})] }));
272
276
  }
@@ -1,4 +1,5 @@
1
1
  import { type PlainDate } from '../../lib/plain-date.js';
2
+ import type { WeekdayCode } from '../../lib/recurrence.js';
2
3
  export type DateFieldProps = {
3
4
  /** The box's id (the button's with `typing={false}`), for the field's `<FieldLabel htmlFor>`. */
4
5
  id?: string;
@@ -41,6 +42,8 @@ export type DateFieldProps = {
41
42
  onOpenChange?: (open: boolean) => void;
42
43
  /** How the day is shown. Defaults to `{ dateStyle: 'medium' }`. */
43
44
  format?: Intl.DateTimeFormatOptions;
45
+ /** The day the calendar's weeks start on (`'MO'` to `'SU'`; Monday when left out). */
46
+ weekStart?: WeekdayCode;
44
47
  locale?: string;
45
48
  className?: string;
46
49
  'aria-label'?: string;
@@ -14,6 +14,10 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
14
14
  // `clearable` adds Clear to the calendar for an optional field. Either way
15
15
  // the control carries `data-kind="date"`, so two dates keep sharing a row
16
16
  // on a phone without their Field saying `kind="date"`.
17
+ //
18
+ // The calendar's weeks start on Monday, MonthCalendar's and
19
+ // RecurrenceField's default; `weekStart="SU"` for an app whose weeks start
20
+ // on Sunday.
17
21
  import { useId, useRef, useState } from 'react';
18
22
  import { CalendarIcon } from 'lucide-react';
19
23
  import { cn } from 'cn';
@@ -25,7 +29,9 @@ import { formatPlainDate, localToPlainDate, parsePlainDate, plainDateExamples, p
25
29
  export function DateField({ typing = true, onProblem, ...props }) {
26
30
  return typing ? _jsx(TypedDate, { ...props, onProblem: onProblem }) : _jsx(DateButton, { ...props });
27
31
  }
28
- function TypedDate({ id, value, onChange, onPick, onProblem, placeholder, clearable = false, invalid = false, readOnly = false, defaultOpen = false, modal, onOpenChange, format, locale, className, 'aria-describedby': describedBy, ...aria }) {
32
+ // Calendar's `weekStartsOn` by code. Left out, it's Calendar's own default (Monday).
33
+ const WEEK_STARTS_ON = { SU: 0, MO: 1, TU: 2, WE: 3, TH: 4, FR: 5, SA: 6 };
34
+ function TypedDate({ id, value, onChange, onPick, onProblem, placeholder, clearable = false, invalid = false, readOnly = false, defaultOpen = false, modal, onOpenChange, format, weekStart, locale, className, 'aria-describedby': describedBy, ...aria }) {
29
35
  const messageId = useId();
30
36
  const [open, setOpen] = useState(defaultOpen && !readOnly);
31
37
  const box = useRef(null);
@@ -100,15 +106,15 @@ function TypedDate({ id, value, onChange, onPick, onProblem, placeholder, cleara
100
106
  };
101
107
  const selected = plainDateToLocal(given);
102
108
  const showProblem = told && problem !== null;
103
- return (_jsxs("div", { "data-slot": "date-field", "data-kind": "date", className: cn('flex w-full min-w-0 flex-col gap-1.5', className), children: [_jsxs(InputGroup, { ref: group, children: [_jsx(InputGroupInput, { ref: box, id: id, value: text, onChange: (event) => type(event.target.value), onBlur: settle, onKeyDown: onKeyDown, placeholder: placeholder ?? plainDateExamples(locale), readOnly: readOnly, autoComplete: "off", "aria-invalid": invalid || showProblem || undefined, "aria-describedby": [showProblem ? messageId : null, describedBy].filter(Boolean).join(' ') || undefined, ...aria }), _jsx(InputGroupAddon, { align: "inline-end", children: _jsxs(Popover, { open: open, onOpenChange: changeOpen, modal: modal, children: [_jsx(PopoverTrigger, { render: _jsx(InputGroupButton, { type: "button", size: "icon-xs", variant: "ghost", disabled: readOnly, "aria-label": "Open Calendar" }), children: _jsx(CalendarIcon, { "aria-hidden": "true" }) }), _jsxs(PopoverContent, { ref: popup, anchor: group, align: "start", className: "w-auto p-0", "data-slot": "date-field-calendar",
109
+ return (_jsxs("div", { "data-slot": "date-field", "data-kind": "date", className: cn('flex w-full min-w-0 flex-col gap-1.5', className), children: [_jsxs(InputGroup, { ref: group, children: [_jsx(InputGroupInput, { ref: box, id: id, value: text, onChange: (event) => type(event.target.value), onBlur: settle, onKeyDown: onKeyDown, placeholder: placeholder ?? plainDateExamples(locale), readOnly: readOnly, autoComplete: "off", "aria-invalid": invalid || showProblem || undefined, "aria-describedby": [showProblem ? messageId : null, describedBy].filter(Boolean).join(' ') || undefined, ...aria }), _jsx(InputGroupAddon, { align: "inline-end", children: _jsxs(Popover, { open: open, onOpenChange: changeOpen, modal: modal, children: [_jsx(PopoverTrigger, { render: _jsx(InputGroupButton, { type: "button", size: "icon-xs", variant: "ghost", disabled: readOnly, "aria-label": "Open Calendar" }), children: _jsx(CalendarIcon, { "aria-hidden": "true" }) }), _jsxs(PopoverContent, { ref: popup, anchor: group, align: "start", className: "w-auto p-0", "data-slot": "date-field-calendar", "aria-label": "Calendar",
104
110
  // The day the keyboard starts from (the chosen one, else today).
105
111
  initialFocus: () => popup.current?.querySelector('button[data-day][tabindex="0"]') ?? true,
106
112
  // Back to the box, where typing goes on.
107
113
  finalFocus: box, children: [_jsx(Calendar, { mode: "single",
108
114
  // Picking the chosen day again keeps it (and closes), never unsets it: Clear does that.
109
- required: true, selected: selected, defaultMonth: selected, onSelect: (date) => pick(localToPlainDate(date)) }), clearable && given && (_jsx("div", { className: "border-t border-border p-2", children: _jsx(Button, { type: "button", variant: "ghost", size: "sm", className: "w-full", onClick: () => pick(''), children: "Clear" }) }))] })] }) })] }), showProblem && (_jsx("p", { id: messageId, "data-slot": "date-field-problem", className: "type-caption text-destructive-text", children: problem }))] }));
115
+ required: true, selected: selected, defaultMonth: selected, weekStartsOn: weekStart && WEEK_STARTS_ON[weekStart], onSelect: (date) => pick(localToPlainDate(date)) }), clearable && given && (_jsx("div", { className: "border-t border-border p-2", children: _jsx(Button, { type: "button", variant: "ghost", size: "sm", className: "w-full", onClick: () => pick(''), children: "Clear" }) }))] })] }) })] }), showProblem && (_jsx("p", { id: messageId, "data-slot": "date-field-problem", className: "type-caption text-destructive-text", children: problem }))] }));
110
116
  }
111
- function DateButton({ id, value, onChange, onPick, placeholder = 'Pick a date', clearable = false, invalid = false, readOnly = false, defaultOpen = false, modal, onOpenChange, format, locale, className, ...aria }) {
117
+ function DateButton({ id, value, onChange, onPick, placeholder = 'Pick a date', clearable = false, invalid = false, readOnly = false, defaultOpen = false, modal, onOpenChange, format, weekStart, locale, className, ...aria }) {
112
118
  const [open, setOpen] = useState(defaultOpen && !readOnly);
113
119
  const popup = useRef(null);
114
120
  const selected = plainDateToLocal(value);
@@ -124,11 +130,11 @@ function DateButton({ id, value, onChange, onPick, placeholder = 'Pick a date',
124
130
  (onPick ?? onChange)(next);
125
131
  changeOpen(false);
126
132
  };
127
- return (_jsxs(Popover, { open: open, onOpenChange: changeOpen, modal: modal, children: [_jsxs(PopoverTrigger, { render: _jsx(Button, { id: id, type: "button", variant: "outline", "data-kind": "date", "aria-invalid": invalid || undefined, "aria-readonly": readOnly || undefined, className: cn('w-full justify-start font-normal', !shown && 'text-muted-foreground', className), ...aria }), children: [_jsx(CalendarIcon, { "aria-hidden": "true", className: "size-4" }), shown || placeholder] }), _jsxs(PopoverContent, { ref: popup, className: "w-auto p-0", "data-slot": "date-field-calendar",
133
+ return (_jsxs(Popover, { open: open, onOpenChange: changeOpen, modal: modal, children: [_jsxs(PopoverTrigger, { render: _jsx(Button, { id: id, type: "button", variant: "outline", "data-kind": "date", "aria-invalid": invalid || undefined, "aria-readonly": readOnly || undefined, className: cn('w-full justify-start font-normal', !shown && 'text-muted-foreground', className), ...aria }), children: [_jsx(CalendarIcon, { "aria-hidden": "true", className: "size-4" }), shown || placeholder] }), _jsxs(PopoverContent, { ref: popup, className: "w-auto p-0", "data-slot": "date-field-calendar", "aria-label": "Calendar",
128
134
  // The day the keyboard starts from (the chosen one, else today):
129
135
  // the one day react-day-picker makes tabbable. The popup would
130
136
  // otherwise take focus itself, past the Calendar's autoFocus.
131
137
  initialFocus: () => popup.current?.querySelector('button[data-day][tabindex="0"]') ?? true, children: [_jsx(Calendar, { mode: "single",
132
138
  // Picking the chosen day again keeps it (and closes), never unsets it: Clear does that.
133
- required: true, selected: selected, defaultMonth: selected, onSelect: (date) => pick(localToPlainDate(date)) }), clearable && value && (_jsx("div", { className: "border-t border-border p-2", children: _jsx(Button, { type: "button", variant: "ghost", size: "sm", className: "w-full", onClick: () => pick(''), children: "Clear" }) }))] })] }));
139
+ required: true, selected: selected, defaultMonth: selected, weekStartsOn: weekStart && WEEK_STARTS_ON[weekStart], onSelect: (date) => pick(localToPlainDate(date)) }), clearable && value && (_jsx("div", { className: "border-t border-border p-2", children: _jsx(Button, { type: "button", variant: "ghost", size: "sm", className: "w-full", onClick: () => pick(''), children: "Clear" }) }))] })] }));
134
140
  }
@@ -66,6 +66,8 @@ export type InPlaceDateConfig<TRequired extends boolean = boolean> = {
66
66
  typing?: boolean;
67
67
  /** How the day reads. Defaults to `{ dateStyle: 'medium' }`. */
68
68
  format?: Intl.DateTimeFormatOptions;
69
+ /** DateField's `weekStart`: `'SU'` for an app whose weeks start on Sunday. */
70
+ weekStart?: WeekdayCode;
69
71
  locale?: string;
70
72
  placeholder?: string;
71
73
  };
@@ -135,7 +135,7 @@ function dateKind(config) {
135
135
  control: (props, alone) => (_jsx(DateField, { id: props.id, value: props.value,
136
136
  // Alone, a pick saves and the calendar opens with the field; closing
137
137
  // it with nothing picked gives up (a pick has already saved by then).
138
- onChange: alone ? (day) => props.commit(day) : props.onChange, clearable: !config.required, placeholder: config.placeholder, format: config.format, locale: config.locale, invalid: props.invalid, readOnly: props.disabled, defaultOpen: alone, modal: alone ? false : undefined, onOpenChange: alone
138
+ onChange: alone ? (day) => props.commit(day) : props.onChange, clearable: !config.required, placeholder: config.placeholder, format: config.format, weekStart: config.weekStart, locale: config.locale, invalid: props.invalid, readOnly: props.disabled, defaultOpen: alone, modal: alone ? false : undefined, onOpenChange: alone
139
139
  ? (open) => {
140
140
  if (!open)
141
141
  props.cancel();
@@ -156,7 +156,7 @@ function typedDateKind(config) {
156
156
  return formatPlainDate(draft) === '' ? { ok: false, message: unreadableDateMessage(config.locale) } : { ok: true, value: draft };
157
157
  },
158
158
  show: (value) => (value ? formatPlainDate(value, config.format, config.locale) || value : null),
159
- control: (props, alone) => (_jsx(DateField, { id: props.id, value: props.value, onChange: props.onChange, onPick: alone ? (day) => props.commit(day) : props.onChange, onProblem: props.onProblem, clearable: !config.required, placeholder: config.placeholder, format: config.format, locale: config.locale, invalid: props.invalid, readOnly: props.disabled, modal: false, "aria-label": props.label, "aria-describedby": props.describedBy })),
159
+ control: (props, alone) => (_jsx(DateField, { id: props.id, value: props.value, onChange: props.onChange, onPick: alone ? (day) => props.commit(day) : props.onChange, onProblem: props.onProblem, clearable: !config.required, placeholder: config.placeholder, format: config.format, weekStart: config.weekStart, locale: config.locale, invalid: props.invalid, readOnly: props.disabled, modal: false, "aria-label": props.label, "aria-describedby": props.describedBy })),
160
160
  };
161
161
  }
162
162
  function monthDayKind(config) {
@@ -1,4 +1,5 @@
1
1
  import { type ReactNode } from 'react';
2
+ import type { WeekdayCode } from '../../lib/recurrence.js';
2
3
  export type FillInInputKind = 'text' | 'longText' | 'number' | 'money' | 'date';
3
4
  export interface FillInSuggestion<V> {
4
5
  value: V;
@@ -15,12 +16,14 @@ export interface FillInInputProps {
15
16
  suggestion?: FillInSuggestion<string>;
16
17
  /** The currency of a money value, for its symbol and the suggestion. Default "USD". */
17
18
  currency?: string;
19
+ /** DateField's `weekStart`, for a date's calendar. */
20
+ weekStart?: WeekdayCode;
18
21
  locale?: string;
19
22
  placeholder?: string;
20
23
  className?: string;
21
24
  }
22
25
  /** One text, number, money or date field of a FillInQueue record. */
23
- export declare function FillInInput({ label, kind, value, onChange, suggestion, currency, locale, placeholder, className, }: FillInInputProps): import("react").JSX.Element;
26
+ export declare function FillInInput({ label, kind, value, onChange, suggestion, currency, weekStart, locale, placeholder, className, }: FillInInputProps): import("react").JSX.Element;
24
27
  export interface FillInSelectProps<V extends string | number> {
25
28
  label: string;
26
29
  choices: readonly {
@@ -58,8 +61,10 @@ export interface FillInFieldProps {
58
61
  /** The number keys pick in this field when it's drawn as a row of choices. One per record. */
59
62
  shortcut?: boolean;
60
63
  currency?: string;
64
+ /** DateField's `weekStart`, for a date's calendar. */
65
+ weekStart?: WeekdayCode;
61
66
  locale?: string;
62
67
  className?: string;
63
68
  }
64
69
  /** The row a field's kind calls for: FillInChoice, FillInSelect or FillInInput. */
65
- export declare function FillInField({ field, value, onChange, shortcut, currency, locale, className }: FillInFieldProps): import("react").JSX.Element;
70
+ export declare function FillInField({ field, value, onChange, shortcut, currency, weekStart, locale, className }: FillInFieldProps): import("react").JSX.Element;
@@ -38,12 +38,12 @@ function shown(kind, value, currency, locale) {
38
38
  return value;
39
39
  }
40
40
  /** One text, number, money or date field of a FillInQueue record. */
41
- export function FillInInput({ label, kind, value, onChange, suggestion, currency = 'USD', locale, placeholder, className, }) {
41
+ export function FillInInput({ label, kind, value, onChange, suggestion, currency = 'USD', weekStart, locale, placeholder, className, }) {
42
42
  const id = useId();
43
43
  const control = (() => {
44
44
  switch (kind) {
45
45
  case 'date':
46
- return _jsx(DateField, { id: id, value: value, onChange: onChange, clearable: true, locale: locale });
46
+ return _jsx(DateField, { id: id, value: value, onChange: onChange, clearable: true, weekStart: weekStart, locale: locale });
47
47
  case 'longText':
48
48
  return _jsx(Textarea, { id: id, value: value, placeholder: placeholder, onChange: (event) => onChange(event.target.value) });
49
49
  case 'money':
@@ -70,7 +70,7 @@ function SuggestionButton({ text, note, used, onUse }) {
70
70
  const isNumeric = (kind) => kind === 'number' || kind === 'money';
71
71
  const toText = (value) => (value === null || value === undefined ? '' : String(value));
72
72
  /** The row a field's kind calls for: FillInChoice, FillInSelect or FillInInput. */
73
- export function FillInField({ field, value, onChange, shortcut, currency, locale, className }) {
73
+ export function FillInField({ field, value, onChange, shortcut, currency, weekStart, locale, className }) {
74
74
  const { kind, label, choices = [], suggestion } = field;
75
75
  // A number's text as typed ("1." on the way to "1.5"), kept while it
76
76
  // still reads as the draft's value; replaced when the draft changes.
@@ -95,5 +95,5 @@ export function FillInField({ field, value, onChange, shortcut, currency, locale
95
95
  setText(next);
96
96
  const number = Number(next);
97
97
  onChange(next.trim() === '' || !Number.isFinite(number) ? null : number);
98
- }, suggestion: suggestion === undefined ? undefined : { value: String(suggestion.value), note: suggestion.note }, currency: currency, locale: locale, className: className }));
98
+ }, suggestion: suggestion === undefined ? undefined : { value: String(suggestion.value), note: suggestion.note }, currency: currency, weekStart: weekStart, locale: locale, className: className }));
99
99
  }
@@ -1,4 +1,5 @@
1
1
  import { type DateFilterPreset } from '../../lib/date-filter.js';
2
+ import type { WeekdayCode } from '../../lib/recurrence.js';
2
3
  export type FilterDateProps = {
3
4
  /** What it filters ("Due"): the prefix of the value it shows ("Due: Before today"). */
4
5
  label: string;
@@ -13,6 +14,8 @@ export type FilterDateProps = {
13
14
  anyLabel?: string;
14
15
  /** How a range's days are shown. Defaults to `{ dateStyle: 'medium' }`. */
15
16
  format?: Intl.DateTimeFormatOptions;
17
+ /** DateField's `weekStart`, for the From and To days' calendars. */
18
+ weekStart?: WeekdayCode;
16
19
  locale?: string;
17
20
  className?: string;
18
21
  };
@@ -21,4 +24,4 @@ export type FilterDateProps = {
21
24
  * today" with a preset, "Due: Nov 1 – Nov 30, 2026" with a range, whose
22
25
  * From and To days show beside it.
23
26
  */
24
- export declare function FilterDate({ label, value, onValueChange, presets, range, anyLabel, format, locale, className, }: FilterDateProps): import("react").JSX.Element;
27
+ export declare function FilterDate({ label, value, onValueChange, presets, range, anyLabel, format, weekStart, locale, className, }: FilterDateProps): import("react").JSX.Element;
@@ -20,7 +20,7 @@ const RANGE = '__range__';
20
20
  * today" with a preset, "Due: Nov 1 – Nov 30, 2026" with a range, whose
21
21
  * From and To days show beside it.
22
22
  */
23
- export function FilterDate({ label, value, onValueChange, presets = DATE_FILTER_PRESETS, range = true, anyLabel, format, locale, className, }) {
23
+ export function FilterDate({ label, value, onValueChange, presets = DATE_FILTER_PRESETS, range = true, anyLabel, format, weekStart, locale, className, }) {
24
24
  const filter = parseDateFilter(value);
25
25
  // Between dates picked, before either day is: the days show, the value stays ''.
26
26
  const [ranging, setRanging] = useState(false);
@@ -42,5 +42,5 @@ export function FilterDate({ label, value, onValueChange, presets = DATE_FILTER_
42
42
  const setEnd = (end, day) => {
43
43
  onValueChange(dateRangeValue({ ...bounds, [end]: day || undefined }));
44
44
  };
45
- return (_jsxs("div", { "data-slot": "filter-date", className: cn('flex flex-wrap items-center gap-2', className), children: [_jsxs(Select, { value: picked, onValueChange: (next) => pick(next === null ? ANY : String(next)), children: [_jsx(SelectTrigger, { "aria-label": filterName(label, shown), "data-slot": "filter-date-select", "data-active": filter ? true : undefined, children: _jsx(SelectValue, { children: () => shown }) }), _jsxs(SelectContent, { children: [_jsx(SelectItem, { value: ANY, children: any }), presets.map((preset) => (_jsx(SelectItem, { value: preset, children: DATE_FILTER_PRESET_LABELS[preset] }, preset))), range && (_jsxs(_Fragment, { children: [_jsx(SelectSeparator, {}), _jsx(SelectItem, { value: RANGE, children: "Between dates" })] }))] })] }), showRange && (_jsxs("div", { "data-slot": "filter-date-range", className: "flex flex-wrap items-center gap-2", children: [_jsx(DateField, { value: bounds?.from ?? '', onChange: (day) => setEnd('from', day), "aria-label": `${label} From`, placeholder: "From", format: format, locale: locale, className: "w-40" }), _jsx(DateField, { value: bounds?.to ?? '', onChange: (day) => setEnd('to', day), "aria-label": `${label} To`, placeholder: "To", format: format, locale: locale, className: "w-40" })] }))] }));
45
+ return (_jsxs("div", { "data-slot": "filter-date", className: cn('flex flex-wrap items-center gap-2', className), children: [_jsxs(Select, { value: picked, onValueChange: (next) => pick(next === null ? ANY : String(next)), children: [_jsx(SelectTrigger, { "aria-label": filterName(label, shown), "data-slot": "filter-date-select", "data-active": filter ? true : undefined, children: _jsx(SelectValue, { children: () => shown }) }), _jsxs(SelectContent, { children: [_jsx(SelectItem, { value: ANY, children: any }), presets.map((preset) => (_jsx(SelectItem, { value: preset, children: DATE_FILTER_PRESET_LABELS[preset] }, preset))), range && (_jsxs(_Fragment, { children: [_jsx(SelectSeparator, {}), _jsx(SelectItem, { value: RANGE, children: "Between dates" })] }))] })] }), showRange && (_jsxs("div", { "data-slot": "filter-date-range", className: "flex flex-wrap items-center gap-2", children: [_jsx(DateField, { value: bounds?.from ?? '', onChange: (day) => setEnd('from', day), "aria-label": `${label} From`, placeholder: "From", format: format, weekStart: weekStart, locale: locale, className: "w-40" }), _jsx(DateField, { value: bounds?.to ?? '', onChange: (day) => setEnd('to', day), "aria-label": `${label} To`, placeholder: "To", format: format, weekStart: weekStart, locale: locale, className: "w-40" })] }))] }));
46
46
  }
@@ -1,3 +1,4 @@
1
+ import { type Ref } from 'react';
1
2
  import type { NavEntry } from './app-shell-nav.js';
2
3
  import { type SearchRecord } from '../../lib/search-palette.js';
3
4
  export type { RecentRecord, SearchRecord } from '../../lib/search-palette.js';
@@ -22,8 +23,18 @@ export type AppShellSearch = {
22
23
  */
23
24
  recent?: number | false;
24
25
  };
25
- /** The box (md and up) and the button (a phone) that open the palette, and the palette. */
26
- export declare function SearchPalette({ search, nav }: {
26
+ /** Opens the palette for a button elsewhere in the shell, where focus returns when it closes. */
27
+ export type SearchPaletteHandle = {
28
+ openFrom: (opener: HTMLElement) => void;
29
+ };
30
+ /**
31
+ * The header's box (md and up) and button (a phone, unless the bottom bar
32
+ * has Search: `onBar`) that open the palette, and the palette.
33
+ */
34
+ export declare function SearchPalette({ search, nav, onBar, ref, }: {
27
35
  search: AppShellSearch;
28
36
  nav: readonly NavEntry[];
37
+ /** The bottom bar draws Search, so the header's phone button isn't drawn. */
38
+ onBar: boolean;
39
+ ref?: Ref<SearchPaletteHandle>;
29
40
  }): import("react").JSX.Element;
@@ -1,8 +1,9 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
- // Search in AppShell's bar: a box in the header (a button on a
3
- // phone) and Ctrl K (⌘K on a Mac) open a palette that finds a page or a
4
- // record by name, and Enter opens it. Before you type it lists the
5
- // records you opened lately (useRecentRecord), then the first pages.
2
+ // Search in AppShell's bar: a box in the header (on a phone a button
3
+ // there, or the bottom bar's Search in its place) and Ctrl K (⌘K on a Mac)
4
+ // open a palette that finds a page or a record by name, and Enter opens
5
+ // it. Before you type it lists the records you opened lately
6
+ // (useRecentRecord), then the first pages.
6
7
  //
7
8
  // A combobox over a listbox in a dialog (WAI-ARIA's "combobox with
8
9
  // listbox popup"): focus stays in the box, the arrows move the
@@ -10,7 +11,7 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
10
11
  // closes. Hand-rolled because shadcn's Command needs cmdk, which isn't
11
12
  // on the package's allowlist; the dialog is the foundation's own.
12
13
  import { SearchIcon } from 'lucide-react';
13
- import { useEffect, useId, useMemo, useRef, useState } from 'react';
14
+ import { useEffect, useId, useImperativeHandle, useMemo, useRef, useState } from 'react';
14
15
  import { useNavigate } from 'react-router';
15
16
  import { cn } from 'cn';
16
17
  import { useDebouncedValue } from '../../hooks/use-debounced-value.js';
@@ -24,9 +25,33 @@ const PAGES_MATCHED = 6;
24
25
  function isMac() {
25
26
  return typeof navigator !== 'undefined' && /Mac|iPhone|iPad/.test(navigator.platform || navigator.userAgent);
26
27
  }
27
- /** The box (md and up) and the button (a phone) that open the palette, and the palette. */
28
- export function SearchPalette({ search, nav }) {
29
- const [open, setOpen] = useState(false);
28
+ const CLOSED = { open: false, opener: null };
29
+ // What opens the palette: the header's box, its phone button, and the
30
+ // bottom bar's Search (app-shell-bottom-bar.tsx). One is shown at a width.
31
+ const OPENERS = '[data-slot="app-shell-search"], [data-slot="app-shell-search-button"], [data-slot="bottom-bar-search"]';
32
+ const isShown = (element) => element.getClientRects().length > 0;
33
+ // Where focus goes as the palette closes: what opened it, or where that is
34
+ // hidden now (the window was resized across md meanwhile), the one shown
35
+ // in its place. `true` is the dialog's own default.
36
+ function focusAfter(opener) {
37
+ if (!opener?.isConnected)
38
+ return true;
39
+ if (isShown(opener))
40
+ return opener;
41
+ return [...document.querySelectorAll(OPENERS)].find(isShown) ?? true;
42
+ }
43
+ /**
44
+ * The header's box (md and up) and button (a phone, unless the bottom bar
45
+ * has Search: `onBar`) that open the palette, and the palette.
46
+ */
47
+ export function SearchPalette({ search, nav, onBar, ref, }) {
48
+ // `opener` is the button pressed, or for Ctrl K what had focus (null for
49
+ // nothing). Focus goes back to a pressed button itself: a tap doesn't
50
+ // focus one in every browser, so what had focus can't be relied on.
51
+ const [{ open, opener }, setState] = useState(CLOSED);
52
+ const openFrom = (from) => setState({ open: true, opener: from });
53
+ const close = () => setState(CLOSED);
54
+ useImperativeHandle(ref, () => ({ openFrom: (from) => setState({ open: true, opener: from }) }), []);
30
55
  const placeholder = search.placeholder ?? 'Search';
31
56
  const shortcut = isMac() ? '⌘K' : 'Ctrl K';
32
57
  // Ctrl K or ⌘K from anywhere, unless something on the page (an
@@ -38,14 +63,16 @@ export function SearchPalette({ search, nav }) {
38
63
  if (event.key.toLowerCase() !== 'k' || !(event.ctrlKey || event.metaKey))
39
64
  return;
40
65
  event.preventDefault();
41
- setOpen((current) => !current);
66
+ const focused = document.activeElement;
67
+ const from = focused instanceof HTMLElement && focused !== document.body ? focused : null;
68
+ setState((current) => (current.open ? CLOSED : { open: true, opener: from }));
42
69
  };
43
70
  window.addEventListener('keydown', onKeyDown);
44
71
  return () => window.removeEventListener('keydown', onKeyDown);
45
72
  }, []);
46
- return (_jsxs(_Fragment, { children: [_jsxs("button", { type: "button", "data-slot": "app-shell-search", "aria-keyshortcuts": "Control+K Meta+K", "aria-haspopup": "dialog", onClick: () => setOpen(true), className: "hidden h-8 w-56 shrink-0 items-center gap-2 rounded-lg border border-input bg-background px-2.5 text-sm text-muted-foreground transition-colors outline-none hover:bg-muted hover:text-foreground focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 md:flex lg:w-64", children: [_jsx(SearchIcon, { "aria-hidden": "true", className: "size-4 shrink-0" }), _jsx("span", { className: "min-w-0 flex-1 truncate text-left", children: placeholder }), _jsx("kbd", { className: "shrink-0 rounded-sm border border-border px-1 font-mono text-xs text-muted-foreground", children: shortcut })] }), _jsx(Button, { variant: "ghost", size: "icon-sm", "data-slot": "app-shell-search-button", "aria-label": placeholder, "aria-haspopup": "dialog", className: "md:hidden", onClick: () => setOpen(true), children: _jsx(SearchIcon, {}) }), _jsx(Dialog, { open: open, onOpenChange: setOpen, children: open && _jsx(Palette, { search: search, nav: nav, placeholder: placeholder, onClose: () => setOpen(false) }) })] }));
73
+ return (_jsxs(_Fragment, { children: [_jsxs("button", { type: "button", "data-slot": "app-shell-search", "aria-keyshortcuts": "Control+K Meta+K", "aria-haspopup": "dialog", onClick: (event) => openFrom(event.currentTarget), className: "hidden h-8 w-56 shrink-0 items-center gap-2 rounded-lg border border-input bg-background px-2.5 text-sm text-muted-foreground transition-colors outline-none hover:bg-muted hover:text-foreground focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 md:flex lg:w-64", children: [_jsx(SearchIcon, { "aria-hidden": "true", className: "size-4 shrink-0" }), _jsx("span", { className: "min-w-0 flex-1 truncate text-left", children: placeholder }), _jsx("kbd", { className: "shrink-0 rounded-sm border border-border px-1 font-mono text-xs text-muted-foreground", children: shortcut })] }), !onBar && (_jsx(Button, { variant: "ghost", size: "icon-sm", "data-slot": "app-shell-search-button", "aria-label": placeholder, "aria-haspopup": "dialog", className: "md:hidden", onClick: (event) => openFrom(event.currentTarget), children: _jsx(SearchIcon, {}) })), _jsx(Dialog, { open: open, onOpenChange: (next) => !next && close(), children: open && _jsx(Palette, { search: search, nav: nav, placeholder: placeholder, opener: opener, onClose: close }) })] }));
47
74
  }
48
- function Palette({ search, nav, placeholder, onClose, }) {
75
+ function Palette({ search, nav, placeholder, opener, onClose, }) {
49
76
  const navigate = useNavigate();
50
77
  const id = useId();
51
78
  const listId = `${id}-list`;
@@ -142,7 +169,7 @@ function Palette({ search, nav, placeholder, onClose, }) {
142
169
  }
143
170
  };
144
171
  const nothing = text && options.length === 0 && records?.status !== 'loading';
145
- return (_jsxs(DialogContent, { showCloseButton: false, "data-slot": "search-palette", className: "top-[12vh] max-h-[76vh] translate-y-0 grid-rows-[auto_minmax(0,1fr)] gap-0 overflow-hidden p-0 sm:max-w-lg", children: [_jsx(DialogTitle, { className: "sr-only", children: placeholder }), _jsx(DialogDescription, { className: "sr-only", children: "Type a page or a record's name; the arrows move through what's found and Enter opens it." }), _jsxs("div", { className: "flex items-center gap-2 border-b border-border px-3", children: [_jsx(SearchIcon, { "aria-hidden": "true", className: "size-4 shrink-0 text-muted-foreground" }), _jsx("input", { role: "combobox", "aria-label": placeholder, "aria-expanded": options.length > 0, "aria-controls": listId, "aria-autocomplete": "list", "aria-activedescendant": activeOption?.id, autoComplete: "off", spellCheck: false, value: query, placeholder: "Go to a page or find a record\u2026", onChange: (event) => {
172
+ return (_jsxs(DialogContent, { showCloseButton: false, finalFocus: () => focusAfter(opener), "data-slot": "search-palette", className: "top-[12vh] max-h-[76vh] translate-y-0 grid-rows-[auto_minmax(0,1fr)] gap-0 overflow-hidden p-0 sm:max-w-lg", children: [_jsx(DialogTitle, { className: "sr-only", children: placeholder }), _jsx(DialogDescription, { className: "sr-only", children: "Type a page or a record's name; the arrows move through what's found and Enter opens it." }), _jsxs("div", { className: "flex items-center gap-2 border-b border-border px-3", children: [_jsx(SearchIcon, { "aria-hidden": "true", className: "size-4 shrink-0 text-muted-foreground" }), _jsx("input", { role: "combobox", "aria-label": placeholder, "aria-expanded": options.length > 0, "aria-controls": listId, "aria-autocomplete": "list", "aria-activedescendant": activeOption?.id, autoComplete: "off", spellCheck: false, value: query, placeholder: "Go to a page or find a record\u2026", onChange: (event) => {
146
173
  setQuery(event.target.value);
147
174
  setActive(0);
148
175
  }, onKeyDown: onKeyDown, className: "h-11 min-w-0 flex-1 bg-transparent text-base outline-none placeholder:text-muted-foreground md:text-sm" }), records?.status === 'loading' && _jsx(Spinner, { "aria-label": "Searching", className: "size-4 text-muted-foreground" })] }), _jsxs("div", { className: "min-h-0 overflow-y-auto p-1", children: [_jsx("div", { role: "listbox", id: listId, "aria-label": placeholder, children: groups.map((group, groupIndex) => (_jsxs("div", { role: "group", "aria-labelledby": `${id}-group-${groupIndex}`, children: [_jsx("div", { id: `${id}-group-${groupIndex}`, className: "px-2 pt-2 pb-1 type-caption text-muted-foreground", children: group.heading }), group.options.map((option) => {
@@ -1,7 +1,7 @@
1
1
  import * as React from "react";
2
2
  import { DayPicker, type DayButton, type Locale } from "react-day-picker";
3
3
  import { Button } from "./button.js";
4
- declare function Calendar({ className, classNames, showOutsideDays, captionLayout, buttonVariant, locale, formatters, components, ...props }: React.ComponentProps<typeof DayPicker> & {
4
+ declare function Calendar({ className, classNames, showOutsideDays, captionLayout, buttonVariant, weekStartsOn, locale, formatters, components, ...props }: React.ComponentProps<typeof DayPicker> & {
5
5
  buttonVariant?: React.ComponentProps<typeof Button>["variant"];
6
6
  }): React.JSX.Element;
7
7
  declare function CalendarDayButton({ className, day, modifiers, locale, ...props }: React.ComponentProps<typeof DayButton> & {
@@ -5,9 +5,13 @@ import { cn } from "cn";
5
5
  import { DayPicker, getDefaultClassNames, } from "react-day-picker";
6
6
  import { Button, buttonVariants } from "./button.js";
7
7
  import { ChevronLeftIcon, ChevronRightIcon, ChevronDownIcon } from "lucide-react";
8
- function Calendar({ className, classNames, showOutsideDays = true, captionLayout = "label", buttonVariant = "ghost", locale, formatters, components, ...props }) {
8
+ function Calendar({ className, classNames, showOutsideDays = true, captionLayout = "label", buttonVariant = "ghost",
9
+ // Patched (ui-foundation): upstream leaves this to react-day-picker, which
10
+ // starts weeks on Sunday. Monday unless the caller says, the default of
11
+ // MonthCalendar, RecurrenceField and byDay; a `locale` doesn't change it.
12
+ weekStartsOn = 1, locale, formatters, components, ...props }) {
9
13
  const defaultClassNames = getDefaultClassNames();
10
- return (_jsx(DayPicker, { showOutsideDays: showOutsideDays, className: cn("group/calendar bg-background p-2 [--cell-radius:var(--radius-md)] [--cell-size:--spacing(7)] in-data-[slot=card-content]:bg-transparent in-data-[slot=popover-content]:bg-transparent", String.raw `rtl:**:[.rdp-button\_next>svg]:rotate-180`, String.raw `rtl:**:[.rdp-button\_previous>svg]:rotate-180`, className), captionLayout: captionLayout, locale: locale, formatters: {
14
+ return (_jsx(DayPicker, { showOutsideDays: showOutsideDays, className: cn("group/calendar bg-background p-2 [--cell-radius:var(--radius-md)] [--cell-size:--spacing(7)] in-data-[slot=card-content]:bg-transparent in-data-[slot=popover-content]:bg-transparent", String.raw `rtl:**:[.rdp-button\_next>svg]:rotate-180`, String.raw `rtl:**:[.rdp-button\_previous>svg]:rotate-180`, className), captionLayout: captionLayout, weekStartsOn: weekStartsOn, locale: locale, formatters: {
11
15
  formatMonthDropdown: (date) => date.toLocaleString(locale?.code, { month: "short" }),
12
16
  ...formatters,
13
17
  }, classNames: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tristan2828/ui-foundation",
3
- "version": "4.139.0",
3
+ "version": "4.141.0",
4
4
  "description": "Shared UI foundation for contract-first, database-backed React apps: shadcn primitives, DataTable/EntityForm composites, auth, the gateway error seam, design tokens, lint rules and the AI playbook.",
5
5
  "license": "MIT",
6
6
  "repository": {