@tristan2828/ui-foundation 4.64.0 → 4.65.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.
@@ -3,23 +3,24 @@
3
3
  <!-- index: written by `npm run docs:index` in the package from the headings below; never edit it by hand -->
4
4
  ## Index
5
5
 
6
- - [The reference files](#the-reference-files) · lines 38–60
7
- - [Before anything: the entity plan](#before-anything-the-entity-plan) · lines 62–743
8
- - Step 1: Add `<Entity>` to `openapi.yaml` · lines 100–107
9
- - Step 2: `npm run gen:api` · lines 108–109
10
- - Step 3: Add gateway tests in `tests/gateway/<entity>.test.ts`, derived from the spec · lines 110–121
11
- - Step 4: Add MSW handlers in `src/mocks/<entity>.ts` · lines 122–131
12
- - Step 5: Add a gateway module in `src/api/gateway/<entity>.ts` · lines 132–136
13
- - Step 6: Copy the reference files, one for one, not just the two screens · lines 137–632
14
- - Step 7: Register routes · lines 633–646
15
- - Step 8: Add Playwright specs for all three screens · lines 647–725
16
- - Step 9: Register the nav entry and route names · lines 726–740
17
- - Step 10: `npm run verify`. · lines 741–743
18
- - [Opening a record over its list](#opening-a-record-over-its-list) · lines 745–801
19
- - [What not to copy](#what-not-to-copy) · lines 803–829
20
- - [After a commit, in the backend](#after-a-commit-in-the-backend) · lines 831–848
21
- - [Deleting](#deleting) · lines 850–879
22
- - [Fields only a script writes](#fields-only-a-script-writes) · lines 881–902
6
+ - [The reference files](#the-reference-files) · lines 39–61
7
+ - [Before anything: the entity plan](#before-anything-the-entity-plan) · lines 63–748
8
+ - Step 1: Add `<Entity>` to `openapi.yaml` · lines 105–112
9
+ - Step 2: `npm run gen:api` · lines 113–114
10
+ - Step 3: Add gateway tests in `tests/gateway/<entity>.test.ts`, derived from the spec · lines 115–126
11
+ - Step 4: Add MSW handlers in `src/mocks/<entity>.ts` · lines 127–136
12
+ - Step 5: Add a gateway module in `src/api/gateway/<entity>.ts` · lines 137–141
13
+ - Step 6: Copy the reference files, one for one, not just the two screens · lines 142–637
14
+ - Step 7: Register routes · lines 638–651
15
+ - Step 8: Add Playwright specs for all three screens · lines 652–730
16
+ - Step 9: Register the nav entry and route names · lines 731–745
17
+ - Step 10: `npm run verify`. · lines 746–748
18
+ - [How a list opens a record](#how-a-list-opens-a-record) · lines 750–852
19
+ - [The record view](#the-record-view) · lines 828–852
20
+ - [What not to copy](#what-not-to-copy) · lines 854–880
21
+ - [After a commit, in the backend](#after-a-commit-in-the-backend) · lines 882–899
22
+ - [Deleting](#deleting) · lines 901–930
23
+ - [Fields only a script writes](#fields-only-a-script-writes) · lines 932–953
23
24
 
24
25
  <!-- /index -->
25
26
 
@@ -84,6 +85,10 @@ is a filled-in example while the Widgets demo is still here).
84
85
  written before the view existed has neither: ask the developer whether
85
86
  to add them before step 1. The reference files build the table *with* a
86
87
  view, where Edit and Delete live, so the table has no row actions.
88
+ - **The plan's List screen says how a row opens its record**: a dialog,
89
+ a dialog only, its page, the panel, or edited in its rows (`DataTable`'s
90
+ `opens`, [How a list opens a record](#how-a-list-opens-a-record)). A
91
+ plan that doesn't say: ask the developer before step 1.
87
92
  - **`Screens: list, edited in the row`** is a small entity with no view
88
93
  and no form: build the contract, gateway, mocks and table as below, but
89
94
  no view, form or `/new`, `/:id`, `/:id/edit` routes. Its table follows
@@ -641,9 +646,9 @@ is a filled-in example while the Widgets demo is still here).
641
646
  belongs to a module already in the nav (its categories, its channels)
642
647
  goes in that module's entry's `children`, not a new top-level entry:
643
648
  it shows under the module while you're in it.
644
- If the plan says records **open over the list** (a board, a list read
645
- one record at a time), the view's route is the list route's child
646
- instead: see [Opening a record over its list](#opening-a-record-over-its-list).
649
+ If the plan says records **open in a dialog** over the list (`opens`
650
+ kind `dialog` or `dialog-only`), the view's route is the list route's
651
+ child instead: see [How a list opens a record](#how-a-list-opens-a-record).
647
652
  8. **Add Playwright specs for all three screens**, one test per state
648
653
  (`loading`, `empty`, `error`, `validation`, `success`), forced through
649
654
  MSW overrides — `forceMswOverride`, `waitForMswReady` and the
@@ -742,48 +747,72 @@ is a filled-in example while the Widgets demo is still here).
742
747
  anything beyond what this list covers; note ideas in the app's
743
748
  backlog instead.
744
749
 
745
- ## Opening a record over its list
750
+ ## How a list opens a record
746
751
 
747
- By default a record opens on its own page, `/<entity>/:id`. A list read
748
- one record at a time (a board's cards, a backlog) can open it in a
749
- centered dialog over the list instead (4.58): the address is still the
750
- record's, so it can be copied and shared, but the list stays underneath
751
- as it was. Only when the plan asks for it; the full page stays the
752
- default.
752
+ Every list opens its records one of a few ways, and says which on its
753
+ `DataTable` with `opens` (4.65), so a change to how the foundation opens
754
+ a record reaches every list on the next upgrade. With
755
+ `uiFoundation({ requireTableOpens: true })` in `eslint.config.js` (the
756
+ template has it), a `DataTable` without `opens` fails lint. The plan
757
+ picks one per list (`docs/entities/<entity>.md` "List screen"):
758
+
759
+ | `opens.kind` | The record opens | Use it for |
760
+ | --- | --- | --- |
761
+ | `dialog` | in a dialog over the list, with Open full page; the record also has its page | most records |
762
+ | `dialog-only` | in a dialog over the list, and has no page of its own | a small record with no notes, where a page would only repeat the dialog |
763
+ | `page` | on its own page, `/<entity>/:id` | a record too big for a dialog: a drawing, an ordered sub-list, long writing |
764
+ | `panel` | in the panel beside the list (`detailPanel`) | reading records one after another |
765
+ | `rows` | nowhere: every value is edited in its row (cell pattern 18) | a record of a field or two |
766
+
767
+ Whichever it is, the record edits in place (cell pattern 18, EntityView's
768
+ `edit`) rather than through an Edit button and a form page, wherever the
769
+ plan allows it.
753
770
 
754
771
  ```tsx
755
- // src/App.tsx: the list route wraps its element, and the view becomes its child.
772
+ // The list: `to` is the record's absolute address.
773
+ <DataTable opens={{ kind: 'dialog', to: (row) => `/<entity>/${row.id}` }} … />
774
+ <DataTable opens={{ kind: 'rows' }} … />
775
+
776
+ // src/App.tsx, for `dialog` and `dialog-only`: the list route wraps its
777
+ // element, and the view becomes its child.
756
778
  {
757
779
  path: '<entity>',
758
780
  element: <RecordDialogRoute list={<<Entity>sTableRoute />} label="<Entity>" />,
781
+ // dialog-only: <RecordDialogRoute fullPage={false} … />
759
782
  errorElement: <RouteErrorBoundary />,
760
783
  children: [{ path: ':id', element: <<Entity>ViewRoute />, errorElement: <RouteErrorBoundary /> }],
761
784
  },
762
785
  { path: '<entity>/new', element: <<Entity>FormRoute /> }, // unchanged siblings
763
- { path: '<entity>/:id/edit', element: <<Entity>FormRoute /> },
764
786
 
765
- // The list: a row click, or a link on a card, opens the record over it.
766
- const openRecord = useOpenRecord()
767
- <DataTable onRowClick={(row) => openRecord(`/<entity>/${row.id}`)} … />
787
+ // A list that isn't a DataTable (a board's cards): a link that opens over it.
768
788
  <Board renderCard={(item) => <RecordLink to={`/<entity>/${item.id}`}>{item.name}</RecordLink>} … />
769
789
  ```
770
790
 
771
- - **The history entry decides.** `useOpenRecord`, `<RecordLink>` (a
772
- `<Link>`) and `recordDialogState(location)` (for a `<Link>`'s own
773
- `state`) put the list's address in the entry's state; the record's
774
- route then draws as a dialog over the list. **A deep link** (pasted,
775
- bookmarked, reloaded in a new tab) has no such state and **is the full
776
- page**, back link and all, as is a record opened from a page other
777
- than its list (a link on the home page).
791
+ - **The row opens it**: a click on the row, Enter on it, ↑/↓ between
792
+ rows. So does a click on a link in the row to the record's own address
793
+ (the name cell can stay a plain `<Link>`), and in a card layout a click
794
+ on a card's link to it; a modified click still opens that link in a new
795
+ tab. Other links and controls in a row keep their own click.
796
+ `onRowClick`, when given, wins over `opens`.
797
+ - **The history entry decides dialog or page.** `opens`, `useOpenRecord`,
798
+ `<RecordLink>` (a `<Link>`) and `recordDialogState(location)` (for a
799
+ `<Link>`'s own `state`) put the list's address in the entry's state;
800
+ the record's route then draws as a dialog over the list. **A deep link**
801
+ (pasted, bookmarked, reloaded in a new tab) has no such state and **is
802
+ the full page**, back link and all, as is a record opened from a page
803
+ other than its list (a link on the home page). With `fullPage={false}`
804
+ there is no page: a deep link or a link from another page opens the
805
+ dialog over its list, at the list's plain address.
778
806
  - **The list stays as it was**: mounted underneath, reading the address
779
807
  it was opened from, so its search, filters, sort, page and scroll are
780
808
  unchanged when the dialog closes.
781
809
  - **Closing**: Back, Esc, the backdrop and the dialog's Close all go
782
810
  back to the list's entry (over every record opened inside the dialog,
783
- a linked one included). Focus goes back to the row or link that
784
- opened it.
785
- - **Open full page**, in the dialog's bar, swaps the entry for the same
786
- address as the full page; Back from there is the list.
811
+ a linked one included). Focus goes back to the row, on its own link
812
+ when it has one, or the link that opened it.
813
+ - **Open full page**, in the dialog's bar (not with `fullPage={false}`),
814
+ swaps the entry for the same address as the full page; Back from there
815
+ is the list.
787
816
  - **The view is unchanged.** `EntityView` sees the dialog: its title
788
817
  names the dialog (`label` names it while loading or on an error), the
789
818
  back link gives way to the dialog's bar, and not found's "Back to …"
@@ -792,14 +821,36 @@ const openRecord = useOpenRecord()
792
821
  `useRecordDialog()` (null on the full page) for its `close`, as a
793
822
  Delete should, rather than navigating to the list:
794
823
  `onDeleted={() => (dialog ? dialog.close() : navigate('/<entity>'))}`.
795
- - **Edit** still goes to `/<entity>/:id/edit`, the form's full page.
796
- - `DataTable`'s `onRowClick` alone makes rows open: a pointer, Enter,
797
- ↑/↓ between rows (4.58; it used to need a `detailPanel`). A link or
798
- control in a cell keeps its own click.
799
824
  - Specs: the package's own (`e2e/record-dialog.spec.ts`) cover the
800
825
  dialog. An app's spec opens a record from the list, checks the
801
826
  address, closes it with Escape, and checks the list's filter survived.
802
827
 
828
+ ### The record view
829
+
830
+ Every record a list opens is an `EntityView`, the same one in a dialog
831
+ and on its page, and every one has the same shape, so a change to the
832
+ view reaches them all. A record uses the parts it has, in this order:
833
+
834
+ - **Header**: the title, edited in place (`titleEdit`); under it a
835
+ one-line summary field, edited in place (`subtitle`: a goal, a
836
+ description); beside it the status as a quick action (a picker saved
837
+ at once) and other status-like fields as badges, edited in place.
838
+ `actions` holds Delete (soft, with Undo) and the record's own commands
839
+ (Run, Print), never Edit.
840
+ - **Strip**: the record's key numbers and ratings (`strip`, a
841
+ `KeyStats`), each edited in place where it's shown.
842
+ - **Sections**: with long text (notes, a body) `layout="rail"` and
843
+ `mobileOrder="main-first"`: the label/value facts in the rail, the long
844
+ text in the main column, folded by its headings (`foldKey`) with an
845
+ Outline for a long one and Print notes (`print`). Without long text,
846
+ one column. Every value edited in place (`edit`), a sub-item list
847
+ included (`editInPlace({ kind: 'list' })`).
848
+ - **A big record's own parts** (a drawing, a player, a checklist of
849
+ documents) are sections in the view, not a screen of their own.
850
+
851
+ Edit and its form page stay only for a field the view can't edit in
852
+ place yet; the plan says which, and the gap is raised for the package.
853
+
803
854
  ## What not to copy
804
855
 
805
856
  - `widget-quick-actions.tsx`, its `quick action: …` specs and
@@ -1533,6 +1533,6 @@ const { grouping, setGrouping, ...table } = useTableUrlState(FILTERS, MULTI, VIE
1533
1533
  announced as the link it is). Without `detailPanel` rows behave as they
1534
1534
  always have: the title link opens the record's page, or, with
1535
1535
  `onRowClick`, the row opens the record (a dialog over the list:
1536
- add-an-entity.md "Opening a record over its list").
1536
+ add-an-entity.md "How a list opens a record").
1537
1537
  - **The table layout's alone:** a card layout's cards don't open the
1538
1538
  panel.
@@ -121,6 +121,11 @@ per list; delete the section if there are none.
121
121
 
122
122
  ## List screen
123
123
 
124
+ - Opens a record: one of `dialog` (a dialog over the list, with its full
125
+ page), `dialog-only` (a small record with no notes: no page of its
126
+ own), `page` (too big for a dialog: say why), `panel`, or `rows`
127
+ (edited in its rows, no view). add-an-entity.md "How a list opens a
128
+ record".
124
129
  - Default sort:
125
130
  - Page size: 10 unless there's a reason.
126
131
  - Saved views (optional; delete if none): one row per view, a button
@@ -143,10 +148,12 @@ per list; delete the section if there are none.
143
148
 
144
149
  ## View screen
145
150
 
146
- The read-only page for one record (`/<entity>/:id`), opened by clicking
147
- its title in the table. Edit and Delete live in its header, so the table
148
- has no row actions. Every field it shows renders as its table cell does,
149
- except the quick actions, if any.
151
+ One record (`/<entity>/:id`), opened from its list as the List screen
152
+ says: the same view in a dialog or on its page. Its shape is the one in
153
+ add-an-entity.md "The record view": values edited in place, Delete in its
154
+ header, and no Edit unless a field can't be edited in place, so the
155
+ table has no row actions. Every field it shows renders as its table cell
156
+ does, except the quick actions, if any.
150
157
 
151
158
  - Title: the field that names a record, shown as the page heading and
152
159
  linked from the table: `title`.
@@ -107,6 +107,23 @@ export type DataTableProps<TData extends Record<string, unknown>> = {
107
107
  */
108
108
  grouping?: string;
109
109
  onGroupingChange?: (grouping: string) => void;
110
+ /**
111
+ * How a row opens its record: one of the foundation's ways, the same for
112
+ * every list (add-an-entity.md "How a list opens a record"). A dialog over
113
+ * the list (`dialog`: the record also has its full page; `dialog-only`:
114
+ * it has none, its route a `RecordDialogRoute` with `fullPage={false}`),
115
+ * its own page (`page`), the panel beside the list (`panel`, with
116
+ * `detailPanel`), or nothing to open, every value edited in its row
117
+ * (`rows`). `to` is the record's absolute address.
118
+ *
119
+ * A click on the row or Enter on it opens the record, and so does a click
120
+ * on a link in the row to that same address (the title's), so a name cell
121
+ * can stay a plain link: a modified click still opens it in a new tab.
122
+ * Other links and controls keep their own click. In a card layout, a
123
+ * click on a card's link to the record opens it the same way.
124
+ * `onRowClick`, when given, wins over it.
125
+ */
126
+ opens?: DataTableOpens<TData>;
110
127
  /**
111
128
  * A record read beside the list without leaving it. Clicking a row (its
112
129
  * title link too; a modified click still opens the link) or Enter on it
@@ -208,6 +225,20 @@ export type DataTableGrouping<TData> = {
208
225
  /** The heading over rows with no value, last: "Not set" unless set ("No category"). */
209
226
  emptyLabel?: string;
210
227
  };
228
+ /**
229
+ * How a list's rows open their records (`opens`): a dialog over the list
230
+ * with the record's full page behind it, a dialog only, its own page, the
231
+ * panel beside the list, or nothing to open (edited in its rows).
232
+ */
233
+ export type DataTableOpens<TData> = {
234
+ kind: 'dialog' | 'dialog-only' | 'page';
235
+ to: (row: TData) => string;
236
+ } | {
237
+ kind: 'panel';
238
+ } | {
239
+ kind: 'rows';
240
+ };
241
+ export type DataTableOpensKind = DataTableOpens<unknown>['kind'];
211
242
  /** One of DataTable's card layouts (`layouts`). */
212
243
  export type DataTableCardLayout<TData> = {
213
244
  /** In the URL (`?layout=covers`) and remembered, so keep it short and stable. */
@@ -243,4 +274,4 @@ export type DataTableTotals = {
243
274
  */
244
275
  cells?: Partial<Record<string, ReactNode>>;
245
276
  };
246
- export declare function DataTable<TData extends Record<string, unknown>>({ columns, data, total, page, pageSize, onPageChange, sorting, onSortingChange, isLoading, error, onRetry, emptyTitle, emptyDescription, emptyAction, toolbar, getRowId, pinFirstColumn, pinLastColumn, enableSortingRemoval, visibleColumns, width, groupBy, groupSummary, header: showHeader, highlightRow, totals, layouts, layout: layoutProp, onLayoutChange, tableLayout, groupings, grouping: groupingProp, onGroupingChange, detailPanel, onRowClick: onRowClickProp, detailRow, onDetailRowChange, detailLabel, }: DataTableProps<TData>): import("react").JSX.Element;
277
+ export declare function DataTable<TData extends Record<string, unknown>>({ columns, data, total, page, pageSize, onPageChange, sorting, onSortingChange, isLoading, error, onRetry, emptyTitle, emptyDescription, emptyAction, toolbar, getRowId, pinFirstColumn, pinLastColumn, enableSortingRemoval, visibleColumns, width, groupBy, groupSummary, header: showHeader, highlightRow, totals, layouts, layout: layoutProp, onLayoutChange, tableLayout, groupings, grouping: groupingProp, onGroupingChange, opens, detailPanel, onRowClick: onRowClickProp, detailRow, onDetailRowChange, detailLabel, }: DataTableProps<TData>): import("react").JSX.Element;
@@ -10,7 +10,8 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
10
10
  // pagination tree-shakeable and independently swappable, which buys nothing
11
11
  // here: every row model is manual (the server sorts and pages), so this
12
12
  // table never uses TanStack's own sorted/paginated row models at all.
13
- import { useEffect, useLayoutEffect, useRef, useState, useSyncExternalStore } from 'react';
13
+ import { useContext, useEffect, useLayoutEffect, useRef, useState, useSyncExternalStore, } from 'react';
14
+ import { UNSAFE_LocationContext as LocationContext, UNSAFE_NavigationContext as NavigationContext, } from 'react-router';
14
15
  import { flexRender } from '@tanstack/react-table';
15
16
  import { cn } from 'cn';
16
17
  import { getCoreRowModel, useLegacyTable } from '@tanstack/react-table/legacy';
@@ -25,8 +26,17 @@ import { ToggleGroup, ToggleGroupItem } from '../ui/toggle-group.js';
25
26
  import { EditInPlaceContext } from './edit-in-place.js';
26
27
  import { EditInPlaceStore } from './edit-in-place-store.js';
27
28
  import { LeaveGuard } from './editable-value.js';
29
+ import { recordDialogState } from './record-dialog-context.js';
28
30
  import { groupByValues, groupRuns } from './table-groups.js';
29
31
  import { Table, TableBody, TableCell, TableFooter, TableHead, TableHeader, TableRow, } from '../ui/table.js';
32
+ // Whether a link is to `to` (its path and query), the record the row opens.
33
+ function linksTo(link, to) {
34
+ if (!(link instanceof HTMLAnchorElement))
35
+ return false;
36
+ const target = new URL(to, link.href);
37
+ const href = new URL(link.href);
38
+ return href.origin === target.origin && href.pathname === target.pathname && href.search === target.search;
39
+ }
30
40
  // A column def's id as TanStack resolves it (constructColumn): `id`, then
31
41
  // `accessorKey` with dots as underscores, then a string header. Group
32
42
  // columns are looked through to their leaves, which visibility is keyed by.
@@ -260,7 +270,7 @@ function useBottomScrollbar(containerRef, isSuccessView) {
260
270
  }, [containerRef, isSuccessView, isOverflowing]);
261
271
  return { barRef, isOverflowing, scrollWidth };
262
272
  }
263
- export function DataTable({ columns, data, total, page, pageSize, onPageChange, sorting, onSortingChange, isLoading, error, onRetry, emptyTitle, emptyDescription, emptyAction, toolbar, getRowId, pinFirstColumn, pinLastColumn, enableSortingRemoval, visibleColumns, width = 'full', groupBy, groupSummary, header: showHeader = true, highlightRow, totals, layouts, layout: layoutProp, onLayoutChange, tableLayout, groupings, grouping: groupingProp, onGroupingChange, detailPanel, onRowClick: onRowClickProp, detailRow, onDetailRowChange, detailLabel = 'Details', }) {
273
+ export function DataTable({ columns, data, total, page, pageSize, onPageChange, sorting, onSortingChange, isLoading, error, onRetry, emptyTitle, emptyDescription, emptyAction, toolbar, getRowId, pinFirstColumn, pinLastColumn, enableSortingRemoval, visibleColumns, width = 'full', groupBy, groupSummary, header: showHeader = true, highlightRow, totals, layouts, layout: layoutProp, onLayoutChange, tableLayout, groupings, grouping: groupingProp, onGroupingChange, opens, detailPanel, onRowClick: onRowClickProp, detailRow, onDetailRowChange, detailLabel = 'Details', }) {
264
274
  // The switch's own state, for a table that doesn't pass `layout`.
265
275
  const [ownLayout, setOwnLayout] = useState('table');
266
276
  const requestedLayout = layoutProp ?? ownLayout;
@@ -271,6 +281,22 @@ export function DataTable({ columns, data, total, page, pageSize, onPageChange,
271
281
  setOwnLayout(next);
272
282
  onLayoutChange?.(next);
273
283
  };
284
+ // `opens`: the record a row opens, and opening it. Read through the
285
+ // router's contexts, not its hooks, so a table outside a router (a
286
+ // fixture, a widget) still renders; there, nothing opens.
287
+ const navigation = useContext(NavigationContext);
288
+ const routerLocation = useContext(LocationContext);
289
+ const opensTo = opens && 'to' in opens ? opens : null;
290
+ const openRecord = opensTo && navigation && routerLocation
291
+ ? (row) => {
292
+ const to = opensTo.to(row);
293
+ if (opensTo.kind === 'page')
294
+ void navigation.navigator.push(to);
295
+ else
296
+ void navigation.navigator.push(to, recordDialogState(routerLocation.location));
297
+ }
298
+ : undefined;
299
+ const openRow = onRowClickProp ?? openRecord;
274
300
  // The grouping on (`groupings`), the menu's own state for a table that
275
301
  // doesn't pass `grouping`.
276
302
  const [ownGrouping, setOwnGrouping] = useState('');
@@ -396,8 +422,8 @@ export function DataTable({ columns, data, total, page, pageSize, onPageChange,
396
422
  ? runs.flatMap((run) => folded.has(run.key) ? [] : run.rows.map((row) => ({ key: placeKey(run.key, row.id), rowId: row.id })))
397
423
  : rows.map((row) => ({ key: row.id, rowId: row.id }));
398
424
  // Rows that open on a click or Enter: picked for the panel, or the app's
399
- // own `onRowClick` (a record's page, or a dialog over the list).
400
- const rowsOpen = Boolean(detailPanel || onRowClickProp);
425
+ // own `onRowClick`, or the record `opens` names (a dialog or its page).
426
+ const rowsOpen = Boolean(detailPanel || openRow);
401
427
  const selectedRow = detailPanel && selection ? rows.find((row) => row.id === selection.rowId) : undefined;
402
428
  // The place marked picked: where it was picked, or (regrouped since) the
403
429
  // row's first place. None while its group is folded.
@@ -425,22 +451,40 @@ export function DataTable({ columns, data, total, page, pageSize, onPageChange,
425
451
  return;
426
452
  if (event.button !== 0 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey)
427
453
  return;
454
+ const row = rows.find((candidate) => candidate.id === place.rowId);
428
455
  const control = target.closest(ROW_CONTROL_SELECTOR);
429
456
  if (control && event.currentTarget.contains(control)) {
430
- if (!control.matches('a[href]') || onRowClickProp)
457
+ if (!control.matches('a[href]'))
458
+ return;
459
+ // A link keeps its click, unless it's the panel's row (a title link
460
+ // picks the row) or the record `opens` names (the title, again).
461
+ const ownLink = !onRowClickProp && opensTo && row ? linksTo(control, opensTo.to(row.original)) : false;
462
+ if (onRowClickProp || (openRecord && !ownLink))
431
463
  return;
432
464
  // In the capture phase, so react-router's Link sees it prevented and
433
465
  // doesn't navigate.
434
466
  event.preventDefault();
435
467
  }
436
- if (onRowClickProp) {
437
- const row = rows.find((candidate) => candidate.id === place.rowId);
468
+ if (openRow) {
438
469
  if (row)
439
- onRowClickProp(row.original);
470
+ openRow(row.original);
440
471
  return;
441
472
  }
442
473
  setSelection(place);
443
474
  };
475
+ // A card layout's card: a click on its link to the record `opens` names
476
+ // opens it the same way a row does (a dialog over the list, say).
477
+ const onCardClick = (event, row) => {
478
+ if (!openRecord || !opensTo || onRowClickProp)
479
+ return;
480
+ if (event.button !== 0 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey)
481
+ return;
482
+ const link = event.target.closest('a[href]');
483
+ if (!link || !event.currentTarget.contains(link) || !linksTo(link, opensTo.to(row)))
484
+ return;
485
+ event.preventDefault();
486
+ openRecord(row);
487
+ };
444
488
  const onListKeyDown = (event) => {
445
489
  const target = event.target;
446
490
  if (event.defaultPrevented || !event.currentTarget.contains(target) || target.closest(TYPING_SELECTOR))
@@ -465,10 +509,10 @@ export function DataTable({ columns, data, total, page, pageSize, onPageChange,
465
509
  if (!place)
466
510
  return;
467
511
  event.preventDefault();
468
- if (onRowClickProp) {
512
+ if (openRow) {
469
513
  const row = rows.find((candidate) => candidate.id === place.rowId);
470
514
  if (row)
471
- onRowClickProp(row.original);
515
+ openRow(row.original);
472
516
  return;
473
517
  }
474
518
  setSelection(place);
@@ -501,7 +545,7 @@ export function DataTable({ columns, data, total, page, pageSize, onPageChange,
501
545
  return;
502
546
  event.preventDefault();
503
547
  closeDetail();
504
- }, children: [_jsxs("div", { className: "flex items-center justify-between gap-2", children: [_jsx("h2", { className: "type-label text-muted-foreground", children: detailLabel }), _jsx(Button, { variant: "ghost", size: "icon-sm", "aria-label": "Close", onClick: closeDetail, children: _jsx(XIcon, { "aria-hidden": "true" }) })] }), detailPanel(selectedRow.original)] })) : null, children: [cardLayout ? (_jsx(Cards, { layout: cardLayout, runs: runs, rows: rows, folded: folded, onToggleFold: toggleFold, groupSummary: groupSummary, groupIcons: groupIcons })) : (_jsxs(Table, { "data-state": "success", containerRef: containerRef, onKeyDown: rowsOpen ? onListKeyDown : undefined,
548
+ }, children: [_jsxs("div", { className: "flex items-center justify-between gap-2", children: [_jsx("h2", { className: "type-label text-muted-foreground", children: detailLabel }), _jsx(Button, { variant: "ghost", size: "icon-sm", "aria-label": "Close", onClick: closeDetail, children: _jsx(XIcon, { "aria-hidden": "true" }) })] }), detailPanel(selectedRow.original)] })) : null, children: [cardLayout ? (_jsx(Cards, { layout: cardLayout, runs: runs, rows: rows, folded: folded, onToggleFold: toggleFold, groupSummary: groupSummary, groupIcons: groupIcons, onCardClick: onCardClick })) : (_jsxs(Table, { "data-state": "success", containerRef: containerRef, onKeyDown: rowsOpen ? onListKeyDown : undefined,
505
549
  // With the sticky bar below as the visible scrollbar, hide the
506
550
  // container's own. It stays overflow-x-auto and fully
507
551
  // scrollable (wheel, trackpad, drag, and the sync effect); it
@@ -558,8 +602,10 @@ function GroupLabel({ run, icon, isFolded, onToggle, }) {
558
602
  }
559
603
  return (_jsxs("button", { type: "button", "aria-expanded": !isFolded, onClick: onToggle, className: GROUP_TOGGLE_CLASS, children: [_jsx(ChevronDownIcon, { "aria-hidden": "true", className: cn('size-4 self-center text-muted-foreground transition-transform', isFolded && '-rotate-90') }), label, _jsx("span", { className: "type-caption text-muted-foreground tabular-nums", children: run.rows.length })] }));
560
604
  }
561
- function Cards({ layout, runs, rows, folded, onToggleFold, groupSummary, groupIcons, }) {
562
- const list = (items) => (_jsx("ul", { role: "list", className: cn(layout.arrange === 'list' ? CARD_LIST_CLASS : ['grid', CARD_GRID_CLASS[layout.size ?? 'md'], CARD_GRID_GAP_CLASS]), children: items.map((row) => (_jsx("li", { "data-slot": "data-table-card", className: "min-w-0 *:data-[slot=card]:glow-edge", children: layout.renderCard(row.original) }, row.id))) }));
605
+ function Cards({ layout, runs, rows, folded, onToggleFold, groupSummary, groupIcons, onCardClick, }) {
606
+ const list = (items) => (_jsx("ul", { role: "list", className: cn(layout.arrange === 'list' ? CARD_LIST_CLASS : ['grid', CARD_GRID_CLASS[layout.size ?? 'md'], CARD_GRID_GAP_CLASS]), children: items.map((row) => (_jsx("li", { "data-slot": "data-table-card", className: "min-w-0 *:data-[slot=card]:glow-edge",
607
+ // In the capture phase, so the card's own link sees it prevented.
608
+ onClickCapture: (event) => onCardClick(event, row.original), children: layout.renderCard(row.original) }, row.id))) }));
563
609
  return (_jsx("div", { className: "@container/data-table-cards flex flex-col gap-6", "data-state": "success", "data-slot": "data-table-cards", children: runs
564
610
  ? runs.map((run, runIndex) => {
565
611
  const isFolded = folded.has(run.key);
@@ -10,8 +10,15 @@ export type RecordDialogRouteProps = {
10
10
  label: string;
11
11
  /** Extra classes on the dialog's popup (its width, say: `sm:max-w-5xl`). */
12
12
  className?: string;
13
+ /**
14
+ * False: the record has no full page, only this dialog (DataTable's
15
+ * `opens` kind `dialog-only`). No Open full page, and its address opened
16
+ * any other way (a deep link, a link from another page) is the dialog
17
+ * over the list. True by default.
18
+ */
19
+ fullPage?: boolean;
13
20
  };
14
- export declare function RecordDialogRoute({ list, label, className }: RecordDialogRouteProps): import("react").JSX.Element;
21
+ export declare function RecordDialogRoute({ list, label, className, fullPage }: RecordDialogRouteProps): import("react").JSX.Element;
15
22
  export type RecordLinkProps = Omit<ComponentProps<typeof Link>, 'state'>;
16
23
  /**
17
24
  * A link to a record that opens it over the current list (a board's card,
@@ -1,6 +1,6 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  // A record opened in a centered dialog over its list, instead of going to
3
- // the record's page (add-an-entity.md "Opening a record over its list").
3
+ // the record's page (add-an-entity.md "How a list opens a record").
4
4
  //
5
5
  // RecordDialogRoute is the list route's element, and the record's route is
6
6
  // its child:
@@ -22,6 +22,12 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
22
22
  // full page, as is a record opened over a list other than its own
23
23
  // (a link on the home page).
24
24
  //
25
+ // `fullPage={false}` is a record with no page of its own (a dialog only:
26
+ // a small record with no notes, where a page would only repeat the
27
+ // dialog). There's no Open full page, and a deep link or a link from
28
+ // another page opens the dialog over its own list, at the list's plain
29
+ // address.
30
+ //
25
31
  // Inside, the record's route renders as it always does. EntityView sees
26
32
  // the dialog (useRecordDialog): its heading names the dialog, its back link
27
33
  // gives way to the dialog's own bar, and not found's way out closes the
@@ -34,7 +40,7 @@ import { Button, buttonVariants } from '../ui/button.js';
34
40
  import { Dialog, DialogClose, DialogContent } from '../ui/dialog.js';
35
41
  import { escapePassedThrough } from './escape-passthrough.js';
36
42
  import { backgroundOf, recordDialogState, RecordDialogContext } from './record-dialog-context.js';
37
- export function RecordDialogRoute({ list, label, className }) {
43
+ export function RecordDialogRoute({ list, label, className, fullPage = true }) {
38
44
  const location = useLocation();
39
45
  const navigationType = useNavigationType();
40
46
  const navigate = useNavigate();
@@ -44,7 +50,13 @@ export function RecordDialogRoute({ list, label, className }) {
44
50
  const opened = backgroundOf(location.state);
45
51
  // Over its own list only: opened from anywhere else, the list under it
46
52
  // would be a page the user wasn't on.
47
- const background = opened && opened.pathname === listPath ? opened : null;
53
+ // With no full page, a record opened any other way is the dialog over
54
+ // the list's plain address, with nothing to go back over.
55
+ const background = opened && opened.pathname === listPath
56
+ ? opened
57
+ : !fullPage && outlet !== null
58
+ ? { pathname: listPath, search: '', hash: '', depth: 0 }
59
+ : null;
48
60
  const open = outlet !== null && background !== null;
49
61
  // The list sees the address it was opened from, not the record's, so
50
62
  // its URL state (filters, sort, page) stays as it was under the dialog.
@@ -78,7 +90,7 @@ export function RecordDialogRoute({ list, label, className }) {
78
90
  return;
79
91
  }
80
92
  close();
81
- }, children: _jsxs(DialogContent, { showCloseButton: false, "aria-labelledby": titleId, "aria-label": label, "data-slot": "record-dialog", className: cn('flex max-h-[calc(100dvh-2rem)] flex-col gap-0 overflow-hidden p-0 sm:max-w-4xl data-closed:hidden', className), children: [_jsxs("div", { className: "flex items-center justify-between gap-2 border-b px-2 py-2", children: [_jsxs(Link, { to: { pathname: location.pathname, search: location.search, hash: location.hash }, replace: true, className: buttonVariants({ variant: 'ghost', size: 'sm' }), children: [_jsx(Maximize2Icon, { "aria-hidden": "true" }), "Open full page"] }), _jsxs(DialogClose, { render: _jsx(Button, { variant: "ghost", size: "icon-sm" }), children: [_jsx(XIcon, { "aria-hidden": "true" }), _jsx("span", { className: "sr-only", children: "Close" })] })] }), _jsx("div", { "data-slot": "record-dialog-body", className: "min-h-0 overflow-y-auto p-4 sm:p-6", children: _jsx(RecordDialogContext.Provider, { value: dialog, children: open && outlet }) })] }) })] }));
93
+ }, children: _jsxs(DialogContent, { showCloseButton: false, "aria-labelledby": titleId, "aria-label": label, "data-slot": "record-dialog", className: cn('flex max-h-[calc(100dvh-2rem)] flex-col gap-0 overflow-hidden p-0 sm:max-w-4xl data-closed:hidden', className), children: [_jsxs("div", { className: cn('flex items-center gap-2 border-b px-2 py-2', fullPage ? 'justify-between' : 'justify-end'), children: [fullPage && (_jsxs(Link, { to: { pathname: location.pathname, search: location.search, hash: location.hash }, replace: true, className: buttonVariants({ variant: 'ghost', size: 'sm' }), children: [_jsx(Maximize2Icon, { "aria-hidden": "true" }), "Open full page"] })), _jsxs(DialogClose, { render: _jsx(Button, { variant: "ghost", size: "icon-sm" }), children: [_jsx(XIcon, { "aria-hidden": "true" }), _jsx("span", { className: "sr-only", children: "Close" })] })] }), _jsx("div", { "data-slot": "record-dialog-body", className: "min-h-0 overflow-y-auto p-4 sm:p-6", children: _jsx(RecordDialogContext.Provider, { value: dialog, children: open && outlet }) })] }) })] }));
82
94
  }
83
95
  /**
84
96
  * A link to a record that opens it over the current list (a board's card,
package/dist/index.d.ts CHANGED
@@ -7,7 +7,7 @@ export { FillInChoice, FillInQueue, type FillInChoiceProps, type FillInQueueGrou
7
7
  export { FillInField, FillInInput, FillInSelect, type FillInFieldKind, type FillInFieldProps, type FillInFieldSpec, type FillInInputKind, type FillInInputProps, type FillInSelectProps, type FillInSuggestion, type FillInValue, } from './components/app/fill-in-field.js';
8
8
  export { Artwork, ArtworkTag, ArtworkToggle, type ArtworkAspect, type ArtworkProps, type ArtworkToggleProps, } from './components/app/artwork.js';
9
9
  export { CountLink, type CountLinkProps } from './components/app/count-link.js';
10
- export { DataTable, type DataTableCardLayout, type DataTableGrouping, type DataTableProps, type DataTableTotals, type DataTableWidth, type SortingState, } from './components/app/data-table.js';
10
+ export { DataTable, type DataTableCardLayout, type DataTableOpens, type DataTableOpensKind, type DataTableGrouping, type DataTableProps, type DataTableTotals, type DataTableWidth, type SortingState, } from './components/app/data-table.js';
11
11
  export { type RowGroup } from './components/app/table-groups.js';
12
12
  export { byDay, type ByDayOptions } from './lib/group-by-day.js';
13
13
  export { EntityForm, type EntityFormProps } from './components/app/entity-form.js';
package/eslint/index.d.ts CHANGED
@@ -4,8 +4,13 @@ export declare const PACKAGE_NAME: string
4
4
  export declare const PRIMITIVES: string[]
5
5
  export declare const TOKEN_SYNTAX_RULES: { selector: string; message: string }[]
6
6
  export declare const NO_BARE_FETCH: { selector: string; message: string }
7
+ export declare const TABLE_OPENS: { selector: string; message: string }
7
8
  export declare function baseConfig(): Linter.Config
8
9
  export declare function kebabCaseFilenames(files: string[], ignores?: string[]): Linter.Config
9
10
 
10
11
  /** The lint config for an app built on the foundation. */
11
- export default function uiFoundation(options?: { ignores?: string[] }): Linter.Config[]
12
+ export default function uiFoundation(options?: {
13
+ ignores?: string[]
14
+ /** Every DataTable must say how it opens a record (`opens`). */
15
+ requireTableOpens?: boolean
16
+ }): Linter.Config[]
package/eslint/index.js CHANGED
@@ -64,6 +64,16 @@ export const NO_BARE_FETCH = {
64
64
  'Do not call fetch directly. All server state goes through TanStack Query, which calls src/api/gateway/, which builds on the foundation gateway entry point.',
65
65
  }
66
66
 
67
+ // Every list says how its rows open their records (DataTable's `opens`:
68
+ // a dialog, a dialog only, its page, the panel, or edited in its rows), so
69
+ // a change to how the foundation opens a record reaches every list. On in
70
+ // an app with `uiFoundation({ requireTableOpens: true })`.
71
+ export const TABLE_OPENS = {
72
+ selector: "JSXOpeningElement[name.name='DataTable']:not(:has(JSXAttribute[name.name='opens']))",
73
+ message:
74
+ "Say how this list opens a record: DataTable's `opens` (dialog, dialog-only, page, panel or rows). See add-an-entity.md \"How a list opens a record\".",
75
+ }
76
+
67
77
  // The rules every TypeScript file gets, before any boundary rule.
68
78
  export function baseConfig() {
69
79
  return {
@@ -121,7 +131,8 @@ function appImportPatterns({ allowGateway }) {
121
131
 
122
132
  /**
123
133
  * The lint config for an app built on the foundation.
124
- * @param {{ ignores?: string[] }} [options] extra paths to ignore, on top of build output and generated files
134
+ * @param {{ ignores?: string[], requireTableOpens?: boolean }} [options] `ignores`: extra paths to ignore, on top
135
+ * of build output and generated files; `requireTableOpens`: every DataTable must say how it opens a record (`opens`)
125
136
  */
126
137
  export default function uiFoundation(options = {}) {
127
138
  return defineConfig([
@@ -140,7 +151,12 @@ export default function uiFoundation(options = {}) {
140
151
  {
141
152
  ...baseConfig(),
142
153
  rules: {
143
- 'no-restricted-syntax': ['error', ...TOKEN_SYNTAX_RULES, NO_BARE_FETCH],
154
+ 'no-restricted-syntax': [
155
+ 'error',
156
+ ...TOKEN_SYNTAX_RULES,
157
+ NO_BARE_FETCH,
158
+ ...(options.requireTableOpens ? [TABLE_OPENS] : []),
159
+ ],
144
160
  'no-restricted-imports': ['error', { patterns: appImportPatterns({ allowGateway: false }) }],
145
161
  },
146
162
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tristan2828/ui-foundation",
3
- "version": "4.64.0",
3
+ "version": "4.65.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": {