@tristan2828/ui-foundation 4.63.3 → 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.
- package/conventions/docs/add-an-entity.md +98 -47
- package/conventions/docs/cell-patterns.md +1 -1
- package/conventions/docs/design-language.md +15 -7
- package/conventions/docs/entity-plan-template.md +11 -4
- package/dist/components/app/data-table.d.ts +32 -1
- package/dist/components/app/data-table.js +59 -13
- package/dist/components/app/line-chart.d.ts +7 -1
- package/dist/components/app/line-chart.js +21 -7
- package/dist/components/app/record-dialog.d.ts +8 -1
- package/dist/components/app/record-dialog.js +16 -4
- package/dist/index.d.ts +1 -1
- package/dist/lib/line-chart-layout.d.ts +10 -1
- package/dist/lib/line-chart-layout.js +14 -3
- package/eslint/index.d.ts +6 -1
- package/eslint/index.js +18 -2
- package/package.json +1 -1
|
@@ -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
|
|
7
|
-
- [Before anything: the entity plan](#before-anything-the-entity-plan) · lines
|
|
8
|
-
- Step 1: Add `<Entity>` to `openapi.yaml` · lines
|
|
9
|
-
- Step 2: `npm run gen:api` · lines
|
|
10
|
-
- Step 3: Add gateway tests in `tests/gateway/<entity>.test.ts`, derived from the spec · lines
|
|
11
|
-
- Step 4: Add MSW handlers in `src/mocks/<entity>.ts` · lines
|
|
12
|
-
- Step 5: Add a gateway module in `src/api/gateway/<entity>.ts` · lines
|
|
13
|
-
- Step 6: Copy the reference files, one for one, not just the two screens · lines
|
|
14
|
-
- Step 7: Register routes · lines
|
|
15
|
-
- Step 8: Add Playwright specs for all three screens · lines
|
|
16
|
-
- Step 9: Register the nav entry and route names · lines
|
|
17
|
-
- Step 10: `npm run verify`. · lines
|
|
18
|
-
- [
|
|
19
|
-
- [
|
|
20
|
-
- [
|
|
21
|
-
- [
|
|
22
|
-
- [
|
|
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
|
|
645
|
-
|
|
646
|
-
instead: see [
|
|
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
|
-
##
|
|
750
|
+
## How a list opens a record
|
|
746
751
|
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
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
|
-
//
|
|
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
|
-
//
|
|
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
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
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
|
|
784
|
-
opened it.
|
|
785
|
-
- **Open full page**, in the dialog's bar
|
|
786
|
-
address as the full page; Back from there
|
|
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 "
|
|
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.
|
|
@@ -18,13 +18,13 @@
|
|
|
18
18
|
- [Widget cards (hub pages)](#widget-cards-hub-pages) · lines 516–630
|
|
19
19
|
- [Module cards (a hub's places)](#module-cards-a-hubs-places) · lines 632–701
|
|
20
20
|
- [Notices](#notices) · lines 703–731
|
|
21
|
-
- [A value over time](#a-value-over-time) · lines 733–
|
|
22
|
-
- [Several values over time](#several-values-over-time) · lines
|
|
23
|
-
- [A list as a board](#a-list-as-a-board) · lines
|
|
24
|
-
- [A list as cards](#a-list-as-cards) · lines
|
|
25
|
-
- [Key numbers on a record](#key-numbers-on-a-record) · lines
|
|
26
|
-
- [Picking at random](#picking-at-random) · lines
|
|
27
|
-
- [Filling in what's missing](#filling-in-whats-missing) · lines
|
|
21
|
+
- [A value over time](#a-value-over-time) · lines 733–819
|
|
22
|
+
- [Several values over time](#several-values-over-time) · lines 782–819
|
|
23
|
+
- [A list as a board](#a-list-as-a-board) · lines 821–872
|
|
24
|
+
- [A list as cards](#a-list-as-cards) · lines 874–920
|
|
25
|
+
- [Key numbers on a record](#key-numbers-on-a-record) · lines 922–944
|
|
26
|
+
- [Picking at random](#picking-at-random) · lines 946–977
|
|
27
|
+
- [Filling in what's missing](#filling-in-whats-missing) · lines 979–1046
|
|
28
28
|
|
|
29
29
|
<!-- /index -->
|
|
30
30
|
|
|
@@ -768,6 +768,14 @@ or `'last'`) with its value.
|
|
|
768
768
|
measured. Its points come after the last of `points`; the mark stays on
|
|
769
769
|
`points`, and a screen reader gets the projection's end in the summary
|
|
770
770
|
and its rows in the table, each named by `label`.
|
|
771
|
+
- **Levels** (4.64): for a value that is one of a few named steps and
|
|
772
|
+
holds until it changes (a confidence, a severity, a stage), pass
|
|
773
|
+
`levels`, lowest first, and give each point its step's index as y:
|
|
774
|
+
`levels={['Very low', 'Low', 'Moderate', 'High']}`. The steps are named
|
|
775
|
+
down the plot's left, the range is all of them (so one step looks like
|
|
776
|
+
one step), and the line steps instead of sloping. Values read by name
|
|
777
|
+
in the mark, the summary and the table; don't pass `formatY` unless the
|
|
778
|
+
names need more.
|
|
771
779
|
- One series and a few dozen points. Zoom or tooltips are a request for
|
|
772
780
|
the foundation, not a hand-drawn chart in the app.
|
|
773
781
|
|
|
@@ -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
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
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
|
|
400
|
-
const rowsOpen = Boolean(detailPanel ||
|
|
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]')
|
|
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 (
|
|
437
|
-
const row = rows.find((candidate) => candidate.id === place.rowId);
|
|
468
|
+
if (openRow) {
|
|
438
469
|
if (row)
|
|
439
|
-
|
|
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 (
|
|
512
|
+
if (openRow) {
|
|
469
513
|
const row = rows.find((candidate) => candidate.id === place.rowId);
|
|
470
514
|
if (row)
|
|
471
|
-
|
|
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",
|
|
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);
|
|
@@ -21,6 +21,12 @@ export type LineChartProps = {
|
|
|
21
21
|
};
|
|
22
22
|
/** Which point to mark with a dot and its value: the lowest, the highest or the latest. */
|
|
23
23
|
mark?: LineChartMark;
|
|
24
|
+
/**
|
|
25
|
+
* Named steps, lowest first: `['Very low', 'Low', 'Moderate', 'High']`.
|
|
26
|
+
* Each point's y is its step's index. The steps are named on the plot's
|
|
27
|
+
* left, the range is all of them, and the line steps (4.64).
|
|
28
|
+
*/
|
|
29
|
+
levels?: readonly string[];
|
|
24
30
|
/** A value as shown: `usd`. Defaults to the number as the browser writes it. */
|
|
25
31
|
formatY?: (y: number) => string;
|
|
26
32
|
/** A point's x as shown: `formatPlainDate`. Defaults to x as given. */
|
|
@@ -32,4 +38,4 @@ export type LineChartProps = {
|
|
|
32
38
|
emptyMessage?: string;
|
|
33
39
|
className?: string;
|
|
34
40
|
};
|
|
35
|
-
export declare function LineChart({ label, points, target, projection, mark, formatY, formatX, height, isLoading, emptyMessage, className, }: LineChartProps): import("react").JSX.Element;
|
|
41
|
+
export declare function LineChart({ label, points, target, projection, mark, levels, formatY: formatYGiven, formatX, height, isLoading, emptyMessage, className, }: LineChartProps): import("react").JSX.Element;
|
|
@@ -18,12 +18,19 @@ import { jsxs as _jsxs, jsx as _jsx, Fragment as _Fragment } from "react/jsx-run
|
|
|
18
18
|
// A `projection` (4.51) carries the line on past its last point, dashed in
|
|
19
19
|
// the same colour: where a balance may go, not where it went. It shares
|
|
20
20
|
// the plot's x and y ranges, so the target and the projection meet where
|
|
21
|
-
// they would.
|
|
21
|
+
// they would.
|
|
22
|
+
//
|
|
23
|
+
// `levels` (4.64) is for a value that is one of a few named steps (a
|
|
24
|
+
// confidence, Very low to High): each y is its step's index. The steps
|
|
25
|
+
// are named down the plot's left with a faint rule at each, the range is
|
|
26
|
+
// every step, and the line holds each value until the next point, then
|
|
27
|
+
// steps. A value reads by its name, in the summary and the table too,
|
|
28
|
+
// unless `formatY` says otherwise. The four states: a skeleton at
|
|
22
29
|
// `height` while loading, one quiet line with no points, a dot (no line)
|
|
23
30
|
// for one point, and the chart.
|
|
24
31
|
import { cn } from 'cn';
|
|
25
32
|
import { Skeleton } from '../ui/skeleton.js';
|
|
26
|
-
import { chartLayout } from '../../lib/line-chart-layout.js';
|
|
33
|
+
import { chartLayout, steppedPlaces } from '../../lib/line-chart-layout.js';
|
|
27
34
|
const defaultY = (y) => y.toLocaleString();
|
|
28
35
|
const defaultX = (x) => String(x);
|
|
29
36
|
const percent = (fraction) => `${fraction * 100}%`;
|
|
@@ -34,7 +41,8 @@ const PLATE = 'rounded-sm bg-card px-1';
|
|
|
34
41
|
function besides(x) {
|
|
35
42
|
return x > 0.75 ? '-translate-x-full -ml-1.5' : 'ml-1.5';
|
|
36
43
|
}
|
|
37
|
-
export function LineChart({ label, points, target, projection, mark, formatY
|
|
44
|
+
export function LineChart({ label, points, target, projection, mark, levels, formatY: formatYGiven, formatX = defaultX, height = 160, isLoading = false, emptyMessage = 'No points yet', className, }) {
|
|
45
|
+
const formatY = formatYGiven ?? (levels ? (y) => levels[Math.round(y)] ?? String(y) : defaultY);
|
|
38
46
|
if (isLoading) {
|
|
39
47
|
return (_jsxs("div", { "data-slot": "line-chart", "data-state": "loading", "aria-busy": "true", className: cn('min-w-0', className), children: [_jsxs("span", { className: "sr-only", children: ["Loading ", label] }), _jsx(Skeleton, { style: { height }, className: "w-full" })] }));
|
|
40
48
|
}
|
|
@@ -42,13 +50,18 @@ export function LineChart({ label, points, target, projection, mark, formatY = d
|
|
|
42
50
|
return (_jsx("figure", { "data-slot": "line-chart", "data-state": "empty", "aria-label": label, className: cn('min-w-0', className), children: _jsx("p", { style: { height }, className: "flex items-center justify-center rounded-md border border-dashed border-border type-body text-muted-foreground", children: emptyMessage }) }));
|
|
43
51
|
}
|
|
44
52
|
const ahead = projection?.points ?? [];
|
|
45
|
-
const
|
|
53
|
+
const steps = levels && levels.length > 0 ? levels.length : undefined;
|
|
54
|
+
const layout = {
|
|
55
|
+
...chartLayout([...points, ...ahead], target?.y, undefined, steps),
|
|
56
|
+
markIndex: chartLayout(points, undefined, mark).markIndex,
|
|
57
|
+
};
|
|
58
|
+
const toLine = (places) => (steps ? steppedPlaces(places) : places).map((place) => `${place.x * 100},${place.y * 100}`).join(' ');
|
|
46
59
|
const projected = ahead.length > 0 ? layout.places.slice(points.length - 1) : [];
|
|
47
60
|
const lastX = ahead.length > 0 ? ahead[ahead.length - 1].x : points[points.length - 1].x;
|
|
48
61
|
const values = points.map((point) => point.y);
|
|
49
62
|
const lowest = values.indexOf(Math.min(...values));
|
|
50
63
|
const highest = values.indexOf(Math.max(...values));
|
|
51
|
-
const line = layout.places.slice(0, points.length)
|
|
64
|
+
const line = toLine(layout.places.slice(0, points.length));
|
|
52
65
|
const marked = layout.markIndex === undefined ? undefined : layout.places[layout.markIndex];
|
|
53
66
|
const single = points.length === 1 ? layout.places[0] : undefined;
|
|
54
67
|
const dot = marked ?? single;
|
|
@@ -62,7 +75,8 @@ export function LineChart({ label, points, target, projection, mark, formatY = d
|
|
|
62
75
|
]
|
|
63
76
|
.filter(Boolean)
|
|
64
77
|
.join('; ');
|
|
65
|
-
return (_jsxs("figure", { "data-slot": "line-chart", "data-state": "success", "aria-label": label, className: cn('
|
|
78
|
+
return (_jsxs("figure", { "data-slot": "line-chart", "data-state": "success", "aria-label": label, className: cn('grid min-w-0 gap-x-2 gap-y-1.5', steps ? 'grid-cols-[auto_minmax(0,1fr)]' : 'grid-cols-1', className), children: [steps && (_jsxs("div", { "aria-hidden": "true", "data-slot": "line-chart-levels", className: "relative", style: { height }, children: [levels.map((name, index) => (_jsx("span", { className: "absolute right-0 -translate-y-1/2 type-caption whitespace-nowrap text-muted-foreground", style: { top: percent(layout.levelYs[index]) }, children: name }, name))), _jsx("span", { className: "invisible flex h-0 flex-col overflow-hidden type-caption whitespace-nowrap", children: levels.map((name) => (_jsx("span", { children: name }, name))) })] })), _jsxs("div", { "aria-hidden": "true", className: "relative border-b border-border", style: { height }, children: [steps &&
|
|
79
|
+
layout.levelYs.map((y, index) => (_jsx("span", { "data-slot": "line-chart-level-rule", className: "absolute inset-x-0 border-t border-dashed border-border", style: { top: percent(y) } }, index))), target && layout.targetY !== undefined && (_jsxs(_Fragment, { children: [_jsx("svg", { viewBox: "0 0 100 100", preserveAspectRatio: "none", className: "absolute inset-0 size-full overflow-visible text-success-text", children: _jsx("line", { x1: "0", x2: "100", y1: layout.targetY * 100, y2: layout.targetY * 100, strokeWidth: 1.5, strokeDasharray: "6 4", vectorEffect: "non-scaling-stroke", className: "stroke-current" }) }), _jsxs("span", { className: cn('absolute right-0 -translate-y-full type-caption text-success-text tabular-nums', PLATE), style: { top: percent(layout.targetY) }, children: [target.label, " ", formatY(target.y)] })] })), points.length > 1 && (_jsx("svg", { viewBox: "0 0 100 100", preserveAspectRatio: "none", className: "absolute inset-0 size-full overflow-visible text-info-text", children: _jsx("polyline", { points: line, fill: "none", strokeWidth: 2, strokeLinejoin: "round", strokeLinecap: "round", vectorEffect: "non-scaling-stroke", className: "stroke-current" }) })), projected.length > 1 && (_jsx("svg", { "data-slot": "line-chart-projection", viewBox: "0 0 100 100", preserveAspectRatio: "none", className: "absolute inset-0 size-full overflow-visible text-info-text", children: _jsx("polyline", { points: toLine(projected), fill: "none", strokeWidth: 2, strokeDasharray: "6 4", strokeLinejoin: "round", vectorEffect: "non-scaling-stroke", className: "stroke-current" }) })), dot && (_jsxs(_Fragment, { children: [_jsx("span", { "data-slot": "line-chart-mark", className: "absolute size-2.5 -translate-x-1/2 -translate-y-1/2 rounded-full bg-info-text ring-2 ring-card", style: { left: percent(dot.x), top: percent(dot.y) } }), _jsx("span", { className: cn('absolute type-caption font-medium text-foreground tabular-nums', PLATE, besides(dot.x),
|
|
66
80
|
// Under the lowest point, where the line isn't; over any other.
|
|
67
|
-
mark === 'min' ? 'mt-1' : '-translate-y-full -mt-1'), style: { left: percent(dot.x), top: percent(dot.y) }, children: formatY(points[marked ? layout.markIndex : 0].y) })] }))] }), _jsxs("div", { "aria-hidden": "true", className:
|
|
81
|
+
mark === 'min' ? 'mt-1' : '-translate-y-full -mt-1'), style: { left: percent(dot.x), top: percent(dot.y) }, children: formatY(points[marked ? layout.markIndex : 0].y) })] }))] }), _jsxs("div", { "aria-hidden": "true", className: cn('flex justify-between gap-3 type-caption text-muted-foreground tabular-nums', steps && 'col-start-2'), children: [_jsx("span", { children: formatX(points[0].x) }), (points.length > 1 || ahead.length > 0) && _jsx("span", { children: formatX(lastX) })] }), _jsx("figcaption", { className: "sr-only", children: steps ? `${summary}; one of ${levels.join(', ')}` : summary }), _jsxs("table", { className: "sr-only", children: [_jsx("caption", { children: label }), _jsx("thead", { children: _jsxs("tr", { children: [_jsx("th", { scope: "col", children: "When" }), _jsx("th", { scope: "col", children: "Value" })] }) }), _jsxs("tbody", { children: [points.map((point, index) => (_jsxs("tr", { children: [_jsx("th", { scope: "row", children: formatX(point.x) }), _jsx("td", { children: formatY(point.y) })] }, index))), ahead.map((point, index) => (_jsxs("tr", { children: [_jsx("th", { scope: "row", children: formatX(point.x) }), _jsxs("td", { children: [formatY(point.y), " (", projection.label, ")"] })] }, `ahead-${index}`)))] })] })] }));
|
|
68
82
|
}
|
|
@@ -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 "
|
|
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
|
-
|
|
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:
|
|
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';
|
|
@@ -19,8 +19,17 @@ export type ChartLayout = {
|
|
|
19
19
|
targetY?: number;
|
|
20
20
|
/** Which point the mark is on, if any. */
|
|
21
21
|
markIndex?: number;
|
|
22
|
+
/** With levels: each level's height, lowest level first. */
|
|
23
|
+
levelYs?: number[];
|
|
22
24
|
};
|
|
23
|
-
export declare function chartLayout(points: readonly LineChartPoint[], target?: number, mark?: LineChartMark): ChartLayout;
|
|
25
|
+
export declare function chartLayout(points: readonly LineChartPoint[], target?: number, mark?: LineChartMark, levels?: number): ChartLayout;
|
|
26
|
+
export declare function steppedPlaces(places: readonly {
|
|
27
|
+
x: number;
|
|
28
|
+
y: number;
|
|
29
|
+
}[]): {
|
|
30
|
+
x: number;
|
|
31
|
+
y: number;
|
|
32
|
+
}[];
|
|
24
33
|
export type SeriesLayout = {
|
|
25
34
|
/** Each series' places, in the order given, each in its points' order. */
|
|
26
35
|
places: {
|
|
@@ -10,11 +10,15 @@ function along(x) {
|
|
|
10
10
|
// Room above and below the values, as a share of their range, so the line
|
|
11
11
|
// never runs along the plot's edge.
|
|
12
12
|
const PAD = 0.1;
|
|
13
|
-
|
|
13
|
+
// `levels` (4.64): the count of named steps a value is one of (a
|
|
14
|
+
// confidence, Very low to High), each value its step's index. The range is
|
|
15
|
+
// then every step, whatever the values, so a move from one step to the
|
|
16
|
+
// next looks as big as it is, not the plot's whole height.
|
|
17
|
+
export function chartLayout(points, target, mark, levels) {
|
|
14
18
|
const values = points.map((point) => point.y);
|
|
15
19
|
const all = target === undefined ? values : [...values, target];
|
|
16
|
-
let min = Math.min(...all);
|
|
17
|
-
let max = Math.max(...all);
|
|
20
|
+
let min = levels ? 0 : Math.min(...all);
|
|
21
|
+
let max = levels ? levels - 1 : Math.max(...all);
|
|
18
22
|
// One value (or all the same): a band around it, so the line sits mid-plot.
|
|
19
23
|
const spread = max - min || Math.abs(max) || 1;
|
|
20
24
|
min -= spread * PAD;
|
|
@@ -40,8 +44,15 @@ export function chartLayout(points, target, mark) {
|
|
|
40
44
|
domain: { min, max },
|
|
41
45
|
targetY: target === undefined ? undefined : height(target),
|
|
42
46
|
markIndex,
|
|
47
|
+
levelYs: levels ? Array.from({ length: levels }, (_, index) => height(index)) : undefined,
|
|
43
48
|
};
|
|
44
49
|
}
|
|
50
|
+
// A line that holds each value until the next point, then steps to it:
|
|
51
|
+
// for values that change on a day and stay (a confidence), not drift.
|
|
52
|
+
// Places in, polyline places out.
|
|
53
|
+
export function steppedPlaces(places) {
|
|
54
|
+
return places.flatMap((place, index) => (index === 0 ? [place] : [{ x: place.x, y: places[index - 1].y }, place]));
|
|
55
|
+
}
|
|
45
56
|
// Several series on one plot (MultiLineChart): one y range over all their
|
|
46
57
|
// values and the target, and one x range over all their points, so a
|
|
47
58
|
// series that starts later starts further right. When an x isn't a time
|
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?: {
|
|
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
|
|
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': [
|
|
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.
|
|
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": {
|