@tristan2828/ui-foundation 4.77.0 → 4.78.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.
@@ -4,25 +4,25 @@
4
4
  ## Index
5
5
 
6
6
  - [The reference files](#the-reference-files) · lines 41–63
7
- - [Before anything: the entity plan](#before-anything-the-entity-plan) · lines 65–782
7
+ - [Before anything: the entity plan](#before-anything-the-entity-plan) · lines 65–802
8
8
  - Step 1: Add `<Entity>` to `openapi.yaml` · lines 107–114
9
9
  - Step 2: `npm run gen:api` · lines 115–116
10
10
  - Step 3: Add gateway tests in `tests/gateway/<entity>.test.ts`, derived from the spec · lines 117–128
11
11
  - Step 4: Add MSW handlers in `src/mocks/<entity>.ts` · lines 129–138
12
12
  - Step 5: Add a gateway module in `src/api/gateway/<entity>.ts` · lines 139–143
13
- - Step 6: Copy the reference files, one for one, not just the two screens · lines 144–669
14
- - Step 7: Register routes · lines 670–685
15
- - Step 8: Add Playwright specs for all three screens · lines 686–764
16
- - Step 9: Register the nav entry and route names · lines 765–779
17
- - Step 10: `npm run verify`. · lines 780–782
18
- - [How a list opens a record](#how-a-list-opens-a-record) · lines 784–933
19
- - [The record view](#the-record-view) · lines 897–933
20
- - [What not to copy](#what-not-to-copy) · lines 935–961
21
- - [After a commit, in the backend](#after-a-commit-in-the-backend) · lines 963–980
22
- - [Deleting](#deleting) · lines 982–1011
23
- - [Fields only a script writes](#fields-only-a-script-writes) · lines 1013–1034
24
- - [Searching one part of the app](#searching-one-part-of-the-app) · lines 1036–1045
25
- - [What a chat is told about an entity](#what-a-chat-is-told-about-an-entity) · lines 1048–1087
13
+ - Step 6: Copy the reference files, one for one, not just the two screens · lines 144–689
14
+ - Step 7: Register routes · lines 690–705
15
+ - Step 8: Add Playwright specs for all three screens · lines 706–784
16
+ - Step 9: Register the nav entry and route names · lines 785–799
17
+ - Step 10: `npm run verify`. · lines 800–802
18
+ - [How a list opens a record](#how-a-list-opens-a-record) · lines 804–953
19
+ - [The record view](#the-record-view) · lines 917–953
20
+ - [What not to copy](#what-not-to-copy) · lines 955–981
21
+ - [After a commit, in the backend](#after-a-commit-in-the-backend) · lines 983–1000
22
+ - [Deleting](#deleting) · lines 1002–1031
23
+ - [Fields only a script writes](#fields-only-a-script-writes) · lines 1033–1054
24
+ - [Searching one part of the app](#searching-one-part-of-the-app) · lines 1056–1065
25
+ - [What a chat is told about an entity](#what-a-chat-is-told-about-an-entity) · lines 1068–1107
26
26
 
27
27
  <!-- /index -->
28
28
 
@@ -225,6 +225,26 @@ is a filled-in example while the Widgets demo is still here).
225
225
  Select is (the fixtures' `app/DateField` EditInPlace). The backend column
226
226
  is a SQL `date` (`datetime.date` in the model).
227
227
 
228
+ **A `month-day`** (a day that comes round every year, with no year:
229
+ when a season starts, a yearly deadline) is `type: string` with
230
+ `pattern: '^(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$'` in
231
+ `openapi.yaml`, so the wire, the generated type and the form all hold
232
+ `'MM-DD'` (`'03-14'`), and `''` on the form for an optional one not set
233
+ (sent as `null`). It sorts as text in calendar order. On the form it's
234
+ the foundation's `MonthDayField` in a `Controller` (`clearable` when
235
+ optional); the schema is the string with
236
+ `.refine((v) => v === '' || isMonthDay(v), 'Pick a month and day')`
237
+ (`isMonthDay`: February 29 is a day, February 30 isn't), `min(1, …)`
238
+ too when required. The table and the view show `formatMonthDay(value)`
239
+ ("Mar 14"), the not-set label when empty. Editing in place is
240
+ `inPlace.monthDay({ value, save })` (cell pattern 18, "Presets"). The
241
+ backend column is `varchar(5)` (`str` in the model) and the router
242
+ refuses a day the month can't have as a 422 on the field (the pattern
243
+ alone lets `02-30` through). Values typed before as free text are
244
+ rewritten to `'MM-DD'` by a migration; one it can't read stays as
245
+ written, and the field shows it as written with nothing picked, refused
246
+ until a day is picked.
247
+
228
248
  **An image on a record** (a photo of it) is the stored file's id on the
229
249
  wire (`string`, nullable), and on the form the foundation's
230
250
  `ImageField` in a `Controller` (`z.string().nullable()`): `value` and
@@ -26,19 +26,19 @@
26
26
  - [A variant: a pressed icon inside another value's cell](#a-variant-a-pressed-icon-inside-another-values-cell) · lines 598–681
27
27
  - [16. Title linking to the record's view](#16-title-linking-to-the-records-view) · lines 683–718
28
28
  - [17. Quick action on the view](#17-quick-action-on-the-view) · lines 720–793
29
- - [18. Editable value](#18-editable-value) · lines 795–1430
30
- - [Presets: one line per field](#presets-one-line-per-field) · lines 1080–1136
31
- - [Several fields edited as one](#several-fields-edited-as-one) · lines 1138–1170
32
- - [A link and its label](#a-link-and-its-label) · lines 1172–1196
33
- - [A list of sub-items](#a-list-of-sub-items) · lines 1198–1331
34
- - [In a table's rows](#in-a-tables-rows) · lines 1333–1418
35
- - [A table of a few short columns: `width="content"`](#a-table-of-a-few-short-columns-widthcontent) · lines 1420–1430
36
- - [19. Stage circle for an ordered status](#19-stage-circle-for-an-ordered-status) · lines 1432–1498
37
- - [20. Count linking to the related records](#20-count-linking-to-the-related-records) · lines 1500–1564
38
- - [21. Rows grouped under headings, and a pill filter](#21-rows-grouped-under-headings-and-a-pill-filter) · lines 1566–1664
39
- - [22. A highlighted row, and rows that are done](#22-a-highlighted-row-and-rows-that-are-done) · lines 1666–1694
40
- - [23. A Group menu, and a record read beside the list](#23-a-group-menu-and-a-record-read-beside-the-list) · lines 1696–1772
41
- - [24. A stored colour beside its name](#24-a-stored-colour-beside-its-name) · lines 1774–1797
29
+ - [18. Editable value](#18-editable-value) · lines 795–1436
30
+ - [Presets: one line per field](#presets-one-line-per-field) · lines 1080–1138
31
+ - [Several fields edited as one](#several-fields-edited-as-one) · lines 1140–1176
32
+ - [A link and its label](#a-link-and-its-label) · lines 1178–1202
33
+ - [A list of sub-items](#a-list-of-sub-items) · lines 1204–1337
34
+ - [In a table's rows](#in-a-tables-rows) · lines 1339–1424
35
+ - [A table of a few short columns: `width="content"`](#a-table-of-a-few-short-columns-widthcontent) · lines 1426–1436
36
+ - [19. Stage circle for an ordered status](#19-stage-circle-for-an-ordered-status) · lines 1438–1504
37
+ - [20. Count linking to the related records](#20-count-linking-to-the-related-records) · lines 1506–1570
38
+ - [21. Rows grouped under headings, and a pill filter](#21-rows-grouped-under-headings-and-a-pill-filter) · lines 1572–1670
39
+ - [22. A highlighted row, and rows that are done](#22-a-highlighted-row-and-rows-that-are-done) · lines 1672–1700
40
+ - [23. A Group menu, and a record read beside the list](#23-a-group-menu-and-a-record-read-beside-the-list) · lines 1702–1778
41
+ - [24. A stored colour beside its name](#24-a-stored-colour-beside-its-name) · lines 1780–1803
42
42
 
43
43
  <!-- /index -->
44
44
 
@@ -1094,6 +1094,7 @@ fields: [
1094
1094
  { label: 'Hours', edit: inPlace.number({ value: project.hours, min: 0, max: 200, unit: 'h', save: (hours) => save({ hours }) }) },
1095
1095
  { label: 'Budget', edit: inPlace.money({ value: project.budget, save: (budget) => save({ budget }) }) },
1096
1096
  { label: 'Due', edit: inPlace.date({ value: project.due, required: true, save: (due) => save({ due }) }) },
1097
+ { label: 'Renews on', edit: inPlace.monthDay({ value: project.renewsOn, save: (renewsOn) => save({ renewsOn }) }) },
1097
1098
  { label: 'Priority', edit: inPlace.select({ value: project.priority, options: PRIORITY_OPTIONS,
1098
1099
  render: (priority, label) => <Badge variant={PRIORITY_BADGE[priority]}>{label}</Badge>,
1099
1100
  save: (priority) => save({ priority }) }) },
@@ -1116,12 +1117,13 @@ fields: [
1116
1117
  | `number` | `1,234 h` (`unit`) | a number; blank is `null` | not a number, under `min`, over `max`, a fraction with `integer` |
1117
1118
  | `money` | `$1,234.56` (`currency`, `locale`) | the API's decimal string, two places (`"1234.50"`), built from the digits, never a float; `$` and commas typed are fine | a third decimal, words, under `min` (0 by default), over `max` |
1118
1119
  | `date` | `Sep 2, 2026` | `'YYYY-MM-DD'`; Clear is `null` | Clear when `required` |
1120
+ | `monthDay` | `Mar 14` (`format`, `locale`); a stored value that isn't a day, as written | `'MM-DD'`, no year; February 29 is a day; Clear is `null` | Clear when `required`, a day the month can't have ("February has 29 days") |
1119
1121
  | `select` | the option's label, or its `render` (a badge) | the option's value; "Not set" is `null` | "Not set" isn't offered when `required` |
1120
1122
  | `reference` | the record's `label` (the view's lookup by id) | the picked record's id | "Not set" isn't offered when `required` |
1121
1123
 
1122
1124
  - **They save the way their kind does** (the table above): `text`,
1123
- `number` and `money` on Enter or leaving them, `date`, `select` and
1124
- `reference` on the pick (the list opens with the field).
1125
+ `number` and `money` on Enter or leaving them, `date`, `monthDay`,
1126
+ `select` and `reference` on the pick (the list opens with the field).
1125
1127
  `required: true` types the save without `null`.
1126
1128
  - **`reference` searches through the app.** The package knows no
1127
1129
  endpoint: `search(text)` is the app's (its gateway's search by name,
@@ -1157,6 +1159,10 @@ value and save in one PATCH: `inPlace.fields`.
1157
1159
  table above, with its own `label`), side by side under a small caption
1158
1160
  of its label, and stacked when the row is narrow. At rest the parts
1159
1161
  read joined by " · " ("Small · Low"), or as `shown`.
1162
+ - **A yearly range** is two `monthDay` parts (`{ kind: 'monthDay',
1163
+ label: 'From' }`, `'By'`). The package sets no rule across them: a
1164
+ range can run over New Year (Nov 1 to Feb 28), so "by after from" is
1165
+ the app's `rule` if it holds for its data.
1160
1166
  - **Nothing saves until they agree.** Picking a part doesn't save it:
1161
1167
  the pair saves on leaving it or Ctrl/Cmd+Enter (and on Enter too when
1162
1168
  every part is typed into: numbers, money, text). Esc gives up both.
@@ -53,6 +53,8 @@ One or two sentences: what one record is, and who uses the screens.
53
53
  check).
54
54
  - *From the package, no Widget example:* `date` (a calendar day, no
55
55
  time: OpenAPI `format: date`; the foundation's `DateField`; say
56
+ whether it's optional), `month-day` (a day that comes round every
57
+ year, no year: `'MM-DD'`; the foundation's `MonthDayField`; say
56
58
  whether it's optional).
57
59
  - *Not supported yet:* a yes/no that can also be unset (three states),
58
60
  file, and anything else.
@@ -1,4 +1,5 @@
1
1
  import type { ReactNode } from 'react';
2
+ import { type MonthDay } from '../../lib/month-day.js';
2
3
  import { type PlainDate } from '../../lib/plain-date.js';
3
4
  import type { EditInPlace } from './edit-in-place.js';
4
5
  /** What the value saves as: with `required: true` never `null` (a blank is refused). */
@@ -58,6 +59,18 @@ export type InPlaceDateConfig<TRequired extends boolean = boolean> = {
58
59
  locale?: string;
59
60
  placeholder?: string;
60
61
  };
62
+ /**
63
+ * A month and day with no year, `'MM-DD'` (MonthDayField): something that
64
+ * comes round every year. Not `required`: Clear saves `null`. February 29
65
+ * is a day; a stored `'02-30'` is refused ("February has 29 days").
66
+ */
67
+ export type InPlaceMonthDayConfig<TRequired extends boolean = boolean> = {
68
+ required?: TRequired;
69
+ /** How the day reads. Defaults to `{ month: 'short', day: 'numeric' }` ("Mar 14"). */
70
+ format?: Pick<Intl.DateTimeFormatOptions, 'month' | 'day'>;
71
+ locale?: string;
72
+ placeholder?: string;
73
+ };
61
74
  /** One option of a select: its value and its words. */
62
75
  export type InPlaceOption<T> = {
63
76
  value: T;
@@ -121,6 +134,9 @@ export type InPlacePart = ({
121
134
  kind: 'date';
122
135
  label: string;
123
136
  } & InPlaceDateConfig) | ({
137
+ kind: 'monthDay';
138
+ label: string;
139
+ } & InPlaceMonthDayConfig) | ({
124
140
  kind: 'select';
125
141
  label: string;
126
142
  } & InPlaceSelectConfig<any>) | ({
@@ -163,6 +179,12 @@ export declare const inPlace: {
163
179
  money<R extends boolean = false>(options: Common<string | number | null | undefined, InPlaceSaved<string, R>> & InPlaceMoneyConfig<R>): EditInPlace;
164
180
  /** A plain day (`'YYYY-MM-DD'`) in DateField's calendar, which opens with the field; a pick saves. */
165
181
  date<R extends boolean = false>(options: Common<PlainDate | null | undefined, InPlaceSaved<PlainDate, R>> & InPlaceDateConfig<R>): EditInPlace;
182
+ /**
183
+ * A month and day with no year (`'MM-DD'`, every year's March 14) in
184
+ * MonthDayField's picker, which opens with the field; a pick saves.
185
+ * Reads as "Mar 14"; February 29 is a day, February 30 is refused.
186
+ */
187
+ monthDay<R extends boolean = false>(options: Common<MonthDay | null | undefined, InPlaceSaved<MonthDay, R>> & InPlaceMonthDayConfig<R>): EditInPlace;
166
188
  /** One of a fixed list; its list opens with the field and a pick saves. */
167
189
  select<T extends string | number, R extends boolean = false>(options: Common<T | null | undefined, InPlaceSaved<T, R>> & InPlaceSelectConfig<T, R>): EditInPlace;
168
190
  /** Another record, searched as you type through the app's `search`; a pick saves its id. */
@@ -3,8 +3,10 @@ import { Input } from '../ui/input.js';
3
3
  import { InputGroup, InputGroupAddon, InputGroupInput, InputGroupText } from '../ui/input-group.js';
4
4
  import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '../ui/select.js';
5
5
  import { linkHost, linkRule } from '../../lib/link-href.js';
6
+ import { formatMonthDay, monthDayProblem } from '../../lib/month-day.js';
6
7
  import { formatPlainDate } from '../../lib/plain-date.js';
7
8
  import { DateField } from './date-field.js';
9
+ import { MonthDayField } from './month-day-field.js';
8
10
  import { NONE, Parts, ReferencePicker } from './edit-in-place-controls.js';
9
11
  import { LinkOut } from './row-edit-cells.js';
10
12
  const REQUIRED = 'Required';
@@ -133,6 +135,29 @@ function dateKind(config) {
133
135
  : undefined, "aria-label": props.label, "aria-describedby": props.describedBy })),
134
136
  };
135
137
  }
138
+ function monthDayKind(config) {
139
+ return {
140
+ editKind: 'choice',
141
+ toDraft: (value) => value ?? '',
142
+ check: (draft) => {
143
+ if (draft === '')
144
+ return config.required ? { ok: false, message: REQUIRED } : { ok: true, value: null };
145
+ const problem = monthDayProblem(draft, config.locale);
146
+ return problem ? { ok: false, message: problem } : { ok: true, value: draft };
147
+ },
148
+ // A stored value that isn't a day of the year reads as written.
149
+ show: (value) => (value ? formatMonthDay(value, config.format, config.locale) || value : null),
150
+ control: (props, alone) => (_jsx(MonthDayField, { id: props.id, value: props.value,
151
+ // Alone, a pick saves and the picker opens with the field; closing
152
+ // it with nothing picked gives up (a pick has already saved by then).
153
+ 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
154
+ ? (open) => {
155
+ if (!open)
156
+ props.cancel();
157
+ }
158
+ : undefined, "aria-label": props.label, "aria-describedby": props.describedBy })),
159
+ };
160
+ }
136
161
  function selectKind(config) {
137
162
  const labelOf = (value) => config.options.find((option) => option.value === value)?.label ?? String(value);
138
163
  const shownOf = (value) => (config.render ? config.render(value, labelOf(value)) : labelOf(value));
@@ -198,6 +223,8 @@ function kindOf(part) {
198
223
  return moneyKind(part);
199
224
  case 'date':
200
225
  return dateKind(part);
226
+ case 'monthDay':
227
+ return monthDayKind(part);
201
228
  case 'select':
202
229
  return selectKind(part);
203
230
  case 'reference':
@@ -378,6 +405,14 @@ export const inPlace = {
378
405
  date(options) {
379
406
  return single(dateKind(options), { ...options, value: options.value || null });
380
407
  },
408
+ /**
409
+ * A month and day with no year (`'MM-DD'`, every year's March 14) in
410
+ * MonthDayField's picker, which opens with the field; a pick saves.
411
+ * Reads as "Mar 14"; February 29 is a day, February 30 is refused.
412
+ */
413
+ monthDay(options) {
414
+ return single(monthDayKind(options), { ...options, value: options.value || null });
415
+ },
381
416
  /** One of a fixed list; its list opens with the field and a pick saves. */
382
417
  select(options) {
383
418
  return single(selectKind(options), { ...options, value: options.value ?? null });
@@ -0,0 +1,31 @@
1
+ import { type MonthDay } from '../../lib/month-day.js';
2
+ export type MonthDayFieldProps = {
3
+ /** The trigger button's id, for the field's `<FieldLabel htmlFor>`. */
4
+ id?: string;
5
+ /** `'MM-DD'`, or `''` for not set. */
6
+ value: MonthDay;
7
+ /** Called with the picked day as `'MM-DD'`, or `''` when cleared. */
8
+ onChange: (value: MonthDay) => void;
9
+ /** What the button says with no day set. Defaults to "Pick a day". */
10
+ placeholder?: string;
11
+ /** Offer Clear in the picker, for an optional field. */
12
+ clearable?: boolean;
13
+ /** The value was refused: `aria-invalid` on the button. */
14
+ invalid?: boolean;
15
+ /** Saving: the button shows the day but won't open. */
16
+ readOnly?: boolean;
17
+ /** Open on mount: editing in place, where the picker opens with the field. */
18
+ defaultOpen?: boolean;
19
+ /** Passed to the Popover; `false` when editing in place, as for a Select. */
20
+ modal?: boolean;
21
+ /** Told when the picker opens or closes; editing in place gives up on a close with nothing picked. */
22
+ onOpenChange?: (open: boolean) => void;
23
+ /** How the day reads on the button. Defaults to `{ month: 'short', day: 'numeric' }` ("Mar 14"). */
24
+ format?: Pick<Intl.DateTimeFormatOptions, 'month' | 'day'>;
25
+ locale?: string;
26
+ className?: string;
27
+ 'aria-label'?: string;
28
+ 'aria-labelledby'?: string;
29
+ 'aria-describedby'?: string;
30
+ };
31
+ export declare function MonthDayField({ id, value, onChange, placeholder, clearable, invalid, readOnly, defaultOpen, modal, onOpenChange, format, locale, className, ...aria }: MonthDayFieldProps): import("react").JSX.Element;
@@ -0,0 +1,134 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ // A month and day with no year: something that comes round every year (a
3
+ // season's start, a yearly deadline). The value is `'MM-DD'`, or `''` for
4
+ // not set (`lib/month-day.ts`).
5
+ //
6
+ // A button showing the day ("Mar 14"), opening a picker in a Popover like
7
+ // DateField's: twelve months, then the chosen month's days. A calendar
8
+ // grid would need a year (its weekdays and leading blanks are a year's),
9
+ // so the days are 1 to the month's last in rows of seven, February
10
+ // running to the 29th. Only real days are offered, so the field can't
11
+ // make February 30; a stored value that isn't one (`'02-30'`, old text)
12
+ // shows as written, nothing selected. The arrow keys move through either
13
+ // grid (Home and End to its ends), Page Up and Page Down change the month,
14
+ // and every button is 36px or larger for a finger.
15
+ //
16
+ // One control for the form (a react-hook-form `Controller`) and for
17
+ // editing in place (`inPlace.monthDay`: picking a day saves, and the
18
+ // picker opens with the field). `clearable` adds Clear for an optional field.
19
+ import { useEffect, useId, useRef, useState } from 'react';
20
+ import { CalendarIcon, ChevronLeftIcon, ChevronRightIcon } from 'lucide-react';
21
+ import { cn } from 'cn';
22
+ import { Button } from '../ui/button.js';
23
+ import { Popover, PopoverContent, PopoverTrigger } from '../ui/popover.js';
24
+ import { daysInMonth, formatMonthDay, monthDayParts, monthName, toMonthDay } from '../../lib/month-day.js';
25
+ const MONTH_COLUMNS = 3;
26
+ const DAY_COLUMNS = 7;
27
+ // Where an arrow key moves in a grid of `count` cells, `columns` wide, or
28
+ // null for a key the grid doesn't use. Left and Right run on across rows.
29
+ function moveInGrid(key, at, count, columns) {
30
+ const next = key === 'ArrowLeft'
31
+ ? at - 1
32
+ : key === 'ArrowRight'
33
+ ? at + 1
34
+ : key === 'ArrowUp'
35
+ ? at - columns
36
+ : key === 'ArrowDown'
37
+ ? at + columns
38
+ : key === 'Home'
39
+ ? 0
40
+ : key === 'End'
41
+ ? count - 1
42
+ : null;
43
+ if (next === null)
44
+ return null;
45
+ return Math.min(Math.max(next, 0), count - 1);
46
+ }
47
+ // The month after (or before) one, round the year.
48
+ const nextMonth = (month, by) => ((month - 1 + by + 12) % 12) + 1;
49
+ export function MonthDayField({ id, value, onChange, placeholder = 'Pick a day', clearable = false, invalid = false, readOnly = false, defaultOpen = false, modal, onOpenChange, format, locale, className, ...aria }) {
50
+ const [open, setOpen] = useState(defaultOpen && !readOnly);
51
+ const popup = useRef(null);
52
+ const selected = monthDayParts(value);
53
+ // A value that isn't a day of the year reads as written, so nothing typed before is hidden.
54
+ const shown = formatMonthDay(value, format, locale) || value;
55
+ const changeOpen = (next) => {
56
+ if (next && readOnly)
57
+ return;
58
+ setOpen(next);
59
+ onOpenChange?.(next);
60
+ };
61
+ const pick = (next) => {
62
+ onChange(next);
63
+ changeOpen(false);
64
+ };
65
+ return (_jsxs(Popover, { open: open, onOpenChange: changeOpen, modal: modal, children: [_jsxs(PopoverTrigger, { render: _jsx(Button, { id: id, type: "button", variant: "outline", "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": "month-day-field-picker", "aria-label": "Month and day",
66
+ // The button the keyboard starts from (the chosen day, else this
67
+ // month): the one the grid makes tabbable. The popup would
68
+ // otherwise take focus itself.
69
+ initialFocus: () => popup.current?.querySelector('[data-cell][tabindex="0"]') ?? true, children: [open && (_jsx(Picker, { selected: selected, locale: locale, onPick: (month, day) => pick(toMonthDay(month, day)) })), 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" }) }))] })] }));
70
+ }
71
+ // The two steps: a month (when nothing is chosen yet, or from the day
72
+ // step's month button), then its days. It opens on the chosen day's month,
73
+ // else on the months with this one to start from.
74
+ function Picker({ selected, locale, onPick }) {
75
+ const today = new Date();
76
+ const [step, setStep] = useState(selected ? 'day' : 'month');
77
+ const [month, setMonth] = useState(selected?.month ?? today.getMonth() + 1);
78
+ // The cell the keyboard is on in the grid shown: a month (1–12) or a day.
79
+ const [active, setActive] = useState(selected ? selected.day : today.getMonth() + 1);
80
+ const grid = useRef(null);
81
+ // Focus follows `active` once the grid is drawn (a step or a month
82
+ // changed, an arrow key), never on a click elsewhere in the popup. On
83
+ // opening, the popup's own initial focus puts it there.
84
+ const focusWanted = useRef(false);
85
+ const monthsLabel = useId();
86
+ useEffect(() => {
87
+ if (!focusWanted.current)
88
+ return;
89
+ focusWanted.current = false;
90
+ grid.current?.querySelector(`[data-cell="${active}"]`)?.focus();
91
+ });
92
+ const days = daysInMonth(month);
93
+ const showMonth = (next, day) => {
94
+ setMonth(next);
95
+ setActive(Math.min(day, daysInMonth(next)));
96
+ focusWanted.current = true;
97
+ };
98
+ const onGridKeyDown = (event) => {
99
+ if (step === 'day' && (event.key === 'PageUp' || event.key === 'PageDown')) {
100
+ event.preventDefault();
101
+ showMonth(nextMonth(month, event.key === 'PageUp' ? -1 : 1), active);
102
+ return;
103
+ }
104
+ const [count, columns] = step === 'month' ? [12, MONTH_COLUMNS] : [days, DAY_COLUMNS];
105
+ const at = moveInGrid(event.key, active - 1, count, columns);
106
+ if (at === null)
107
+ return;
108
+ event.preventDefault();
109
+ if (at + 1 === active)
110
+ return;
111
+ setActive(at + 1);
112
+ focusWanted.current = true;
113
+ };
114
+ const name = monthName(month, 'long', locale);
115
+ if (step === 'month') {
116
+ return (_jsxs("div", { className: "p-3", children: [_jsx("p", { className: "mb-2 px-1 text-sm font-medium", id: monthsLabel, children: "Month" }), _jsx("div", { ref: grid, role: "group", "aria-labelledby": monthsLabel, className: "grid grid-cols-3 gap-1", onKeyDown: onGridKeyDown, children: Array.from({ length: 12 }, (_, index) => {
117
+ const each = index + 1;
118
+ const chosen = selected?.month === each;
119
+ return (_jsxs(Button, { type: "button", variant: chosen ? 'default' : 'ghost', className: "h-10 w-20 font-normal", "data-cell": each, tabIndex: each === active ? 0 : -1, "aria-pressed": chosen, onClick: () => {
120
+ setStep('day');
121
+ showMonth(each, selected?.month === each ? selected.day : 1);
122
+ }, children: [_jsx("span", { "aria-hidden": "true", children: monthName(each, 'short', locale) }), _jsx("span", { className: "sr-only", children: monthName(each, 'long', locale) })] }, each));
123
+ }) })] }));
124
+ }
125
+ return (_jsxs("div", { className: "p-3", children: [_jsxs("div", { className: "mb-2 flex items-center justify-between gap-1", children: [_jsx(Button, { type: "button", variant: "ghost", size: "icon", "aria-label": "Previous month", onClick: () => showMonth(nextMonth(month, -1), active), children: _jsx(ChevronLeftIcon, { "aria-hidden": "true" }) }), _jsx(Button, { type: "button", variant: "ghost", className: "font-medium", "aria-label": `${name}, pick another month`, onClick: () => {
126
+ setStep('month');
127
+ setActive(month);
128
+ focusWanted.current = true;
129
+ }, children: name }), _jsx(Button, { type: "button", variant: "ghost", size: "icon", "aria-label": "Next month", onClick: () => showMonth(nextMonth(month, 1), active), children: _jsx(ChevronRightIcon, { "aria-hidden": "true" }) })] }), _jsx("div", { ref: grid, role: "group", "aria-label": name, className: "grid grid-cols-7 gap-1", onKeyDown: onGridKeyDown, children: Array.from({ length: days }, (_, index) => {
130
+ const day = index + 1;
131
+ const chosen = selected?.month === month && selected.day === day;
132
+ return (_jsx(Button, { type: "button", variant: chosen ? 'default' : 'ghost', size: "icon", className: "font-normal tabular-nums", "data-cell": day, tabIndex: day === active ? 0 : -1, "aria-label": formatMonthDay(toMonthDay(month, day), { month: 'long', day: 'numeric' }, locale), "aria-pressed": chosen, onClick: () => onPick(month, day), children: day }, day));
133
+ }) })] }));
134
+ }
package/dist/index.d.ts CHANGED
@@ -20,7 +20,7 @@ export { usePrinting } from './components/app/print-context.js';
20
20
  export { RecordDialogRoute, RecordLink, type RecordDialogRouteProps, type RecordLinkProps, } from './components/app/record-dialog.js';
21
21
  export { recordDialogState, useOpenRecord, useRecordDialog, type RecordDialogBackground, type RecordDialogContextValue, type RecordDialogState, } from './components/app/record-dialog-context.js';
22
22
  export { editInPlace, type EditControlProps, type EditInPlace, type EditInPlaceList, type EditInPlaceListOptions, type EditInPlaceOptions, type EditKind, type EditListAddProps, type EditListItemProps, } from './components/app/edit-in-place.js';
23
- export { inPlace, type InPlaceDateConfig, type InPlaceFieldsOptions, type InPlaceLinkConfig, type InPlaceLinkValue, type InPlaceMoneyConfig, type InPlaceNumberConfig, type InPlaceOption, type InPlacePart, type InPlaceRecord, type InPlaceReferenceConfig, type InPlaceSaved, type InPlaceSelectConfig, type InPlaceTextConfig, } from './components/app/edit-in-place-presets.js';
23
+ export { inPlace, type InPlaceDateConfig, type InPlaceFieldsOptions, type InPlaceLinkConfig, type InPlaceLinkValue, type InPlaceMoneyConfig, type InPlaceMonthDayConfig, type InPlaceNumberConfig, type InPlaceOption, type InPlacePart, type InPlaceRecord, type InPlaceReferenceConfig, type InPlaceSaved, type InPlaceSelectConfig, type InPlaceTextConfig, } from './components/app/edit-in-place-presets.js';
24
24
  export { linkHost, linkHref, linkRule } from './lib/link-href.js';
25
25
  export { DataEnvironmentBanner } from './components/app/data-environment-banner.js';
26
26
  export { EditableValue, type EditableValueProps } from './components/app/editable-value.js';
@@ -55,9 +55,11 @@ export { StepBar, type StepBarProps } from './components/app/step-bar.js';
55
55
  export { RatingStar, type RatingStarProps, type RatingStarValue } from './components/app/rating-star.js';
56
56
  export { DateField, type DateFieldProps } from './components/app/date-field.js';
57
57
  export { EmojiField, type EmojiFieldProps } from './components/app/emoji-field.js';
58
+ export { MonthDayField, type MonthDayFieldProps } from './components/app/month-day-field.js';
58
59
  export { ImageField, type ImageFieldProps } from './components/app/image-field.js';
59
60
  export { DEFAULT_IMAGE_TYPES, type ImageUpload, type ImageUploadResult } from './lib/image-file.js';
60
61
  export { formatPlainDate, type PlainDate } from './lib/plain-date.js';
62
+ export { formatMonthDay, isMonthDay, monthDayProblem, type MonthDay } from './lib/month-day.js';
61
63
  export { ChoiceCell, LinkCell, LinkOut, NameCell, type ChoiceCellProps, type LinkCellProps, type NameCellProps, } from './components/app/row-edit-cells.js';
62
64
  export { ModuleCard, ModuleStrip, type CategorySlot, type ModuleCardLink, type ModuleCardPlace, type ModuleCardProps, type ModuleStripMobile, type ModuleStripProps, } from './components/app/module-card.js';
63
65
  export { WidgetCard, WidgetCardGroup, WidgetList, WidgetListItem, type WidgetCardGroupProps, type WidgetCardLink, type WidgetCardProps, type WidgetListItemProps, } from './components/app/widget-card.js';
package/dist/index.js CHANGED
@@ -57,9 +57,11 @@ export { StepBar } from './components/app/step-bar.js';
57
57
  export { RatingStar } from './components/app/rating-star.js';
58
58
  export { DateField } from './components/app/date-field.js';
59
59
  export { EmojiField } from './components/app/emoji-field.js';
60
+ export { MonthDayField } from './components/app/month-day-field.js';
60
61
  export { ImageField } from './components/app/image-field.js';
61
62
  export { DEFAULT_IMAGE_TYPES } from './lib/image-file.js';
62
63
  export { formatPlainDate } from './lib/plain-date.js';
64
+ export { formatMonthDay, isMonthDay, monthDayProblem } from './lib/month-day.js';
63
65
  export { ChoiceCell, LinkCell, LinkOut, NameCell, } from './components/app/row-edit-cells.js';
64
66
  export { ModuleCard, ModuleStrip, } from './components/app/module-card.js';
65
67
  export { WidgetCard, WidgetCardGroup, WidgetList, WidgetListItem, } from './components/app/widget-card.js';
@@ -0,0 +1,27 @@
1
+ /** A day of the year with no year, `'MM-DD'`, or `''` for not set. */
2
+ export type MonthDay = string;
3
+ /** How many days the month (1–12) can have: February's 29 counted. */
4
+ export declare function daysInMonth(month: number): number;
5
+ /** The month (1–12) and day of a real `'MM-DD'`, or null for anything else (`''`, `'02-30'`, `'3-14'`). */
6
+ export declare function monthDayParts(value: MonthDay): {
7
+ month: number;
8
+ day: number;
9
+ } | null;
10
+ /** Whether the value is a real day of the year as `'MM-DD'`: `'02-29'` is, `'02-30'` isn't. */
11
+ export declare function isMonthDay(value: MonthDay): boolean;
12
+ /** The month (1–12) and day as `'MM-DD'`. */
13
+ export declare function toMonthDay(month: number, day: number): MonthDay;
14
+ /**
15
+ * Shows a month and day ("Mar 14", or "14 March" in `en-GB` with
16
+ * `{ month: 'long', day: 'numeric' }`) in the locale's order, never a
17
+ * year or a weekday. `''` and anything that isn't a real `'MM-DD'` give `''`.
18
+ */
19
+ export declare function formatMonthDay(value: MonthDay, options?: Pick<Intl.DateTimeFormatOptions, 'month' | 'day'>, locale?: string): string;
20
+ /** A month's name ("March", or "Mar" with `'short'`), for a month 1–12. */
21
+ export declare function monthName(month: number, style?: 'long' | 'short', locale?: string): string;
22
+ /**
23
+ * Why a value isn't a day of the year, or null when it is (or is `''`):
24
+ * "February has 29 days" for `'02-30'`, "Pick a month and day" for
25
+ * anything not `'MM-DD'`.
26
+ */
27
+ export declare function monthDayProblem(value: MonthDay, locale?: string): string | null;
@@ -0,0 +1,62 @@
1
+ // A month and day with no year: something that comes round every year (a
2
+ // season's start, a yearly deadline). The value is `'MM-DD'` (`'03-14'`),
3
+ // or `''` for not set, so it sorts as text in calendar order. February 29
4
+ // is a day like any other (it comes round in leap years); February 30,
5
+ // April 31 and `13-01` are not days. MonthDayField edits one.
6
+ const MONTH_DAY = /^(\d{2})-(\d{2})$/;
7
+ // Days in each month of a leap year: February has its 29th.
8
+ const DAYS_IN_MONTH = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
9
+ /** How many days the month (1–12) can have: February's 29 counted. */
10
+ export function daysInMonth(month) {
11
+ return DAYS_IN_MONTH[month - 1] ?? 0;
12
+ }
13
+ /** The month (1–12) and day of a real `'MM-DD'`, or null for anything else (`''`, `'02-30'`, `'3-14'`). */
14
+ export function monthDayParts(value) {
15
+ const match = MONTH_DAY.exec(value);
16
+ if (!match)
17
+ return null;
18
+ const [month, day] = [Number(match[1]), Number(match[2])];
19
+ if (month < 1 || month > 12 || day < 1 || day > daysInMonth(month))
20
+ return null;
21
+ return { month, day };
22
+ }
23
+ /** Whether the value is a real day of the year as `'MM-DD'`: `'02-29'` is, `'02-30'` isn't. */
24
+ export function isMonthDay(value) {
25
+ return monthDayParts(value) !== null;
26
+ }
27
+ /** The month (1–12) and day as `'MM-DD'`. */
28
+ export function toMonthDay(month, day) {
29
+ return `${String(month).padStart(2, '0')}-${String(day).padStart(2, '0')}`;
30
+ }
31
+ // A leap year, so February 29 formats; the year is never shown.
32
+ const LEAP_YEAR = 2000;
33
+ /**
34
+ * Shows a month and day ("Mar 14", or "14 March" in `en-GB` with
35
+ * `{ month: 'long', day: 'numeric' }`) in the locale's order, never a
36
+ * year or a weekday. `''` and anything that isn't a real `'MM-DD'` give `''`.
37
+ */
38
+ export function formatMonthDay(value, options = { month: 'short', day: 'numeric' }, locale) {
39
+ const parts = monthDayParts(value);
40
+ if (!parts)
41
+ return '';
42
+ const { month = 'short', day = 'numeric' } = options;
43
+ return new Intl.DateTimeFormat(locale, { month, day, timeZone: 'UTC' }).format(Date.UTC(LEAP_YEAR, parts.month - 1, parts.day));
44
+ }
45
+ /** A month's name ("March", or "Mar" with `'short'`), for a month 1–12. */
46
+ export function monthName(month, style = 'long', locale) {
47
+ return new Intl.DateTimeFormat(locale, { month: style, timeZone: 'UTC' }).format(Date.UTC(LEAP_YEAR, month - 1, 1));
48
+ }
49
+ /**
50
+ * Why a value isn't a day of the year, or null when it is (or is `''`):
51
+ * "February has 29 days" for `'02-30'`, "Pick a month and day" for
52
+ * anything not `'MM-DD'`.
53
+ */
54
+ export function monthDayProblem(value, locale) {
55
+ if (value === '' || isMonthDay(value))
56
+ return null;
57
+ const match = MONTH_DAY.exec(value);
58
+ const [month, day] = match ? [Number(match[1]), Number(match[2])] : [0, 0];
59
+ if (month >= 1 && month <= 12 && day > daysInMonth(month))
60
+ return `${monthName(month, 'long', locale)} has ${daysInMonth(month)} days`;
61
+ return 'Pick a month and day';
62
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tristan2828/ui-foundation",
3
- "version": "4.77.0",
3
+ "version": "4.78.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": {