@tristan2828/ui-foundation 4.69.0 → 4.71.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,25 +3,26 @@
|
|
|
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
|
-
- [How a list opens a record](#how-a-list-opens-a-record) · lines
|
|
19
|
-
- [The record view](#the-record-view) · lines
|
|
20
|
-
- [What not to copy](#what-not-to-copy) · lines
|
|
21
|
-
- [After a commit, in the backend](#after-a-commit-in-the-backend) · lines
|
|
22
|
-
- [Deleting](#deleting) · lines
|
|
23
|
-
- [Fields only a script writes](#fields-only-a-script-writes) · lines
|
|
24
|
-
- [Searching one part of the app](#searching-one-part-of-the-app) · lines
|
|
6
|
+
- [The reference files](#the-reference-files) · lines 41–63
|
|
7
|
+
- [Before anything: the entity plan](#before-anything-the-entity-plan) · lines 65–752
|
|
8
|
+
- Step 1: Add `<Entity>` to `openapi.yaml` · lines 107–114
|
|
9
|
+
- Step 2: `npm run gen:api` · lines 115–116
|
|
10
|
+
- Step 3: Add gateway tests in `tests/gateway/<entity>.test.ts`, derived from the spec · lines 117–128
|
|
11
|
+
- Step 4: Add MSW handlers in `src/mocks/<entity>.ts` · lines 129–138
|
|
12
|
+
- Step 5: Add a gateway module in `src/api/gateway/<entity>.ts` · lines 139–143
|
|
13
|
+
- Step 6: Copy the reference files, one for one, not just the two screens · lines 144–639
|
|
14
|
+
- Step 7: Register routes · lines 640–655
|
|
15
|
+
- Step 8: Add Playwright specs for all three screens · lines 656–734
|
|
16
|
+
- Step 9: Register the nav entry and route names · lines 735–749
|
|
17
|
+
- Step 10: `npm run verify`. · lines 750–752
|
|
18
|
+
- [How a list opens a record](#how-a-list-opens-a-record) · lines 754–892
|
|
19
|
+
- [The record view](#the-record-view) · lines 867–892
|
|
20
|
+
- [What not to copy](#what-not-to-copy) · lines 894–920
|
|
21
|
+
- [After a commit, in the backend](#after-a-commit-in-the-backend) · lines 922–939
|
|
22
|
+
- [Deleting](#deleting) · lines 941–970
|
|
23
|
+
- [Fields only a script writes](#fields-only-a-script-writes) · lines 972–993
|
|
24
|
+
- [Searching one part of the app](#searching-one-part-of-the-app) · lines 995–1004
|
|
25
|
+
- [What a chat is told about an entity](#what-a-chat-is-told-about-an-entity) · lines 1007–1046
|
|
25
26
|
|
|
26
27
|
<!-- /index -->
|
|
27
28
|
|
|
@@ -649,7 +650,9 @@ is a filled-in example while the Widgets demo is still here).
|
|
|
649
650
|
it shows under the module while you're in it.
|
|
650
651
|
If the plan says records **open in a dialog** over the list (`opens`
|
|
651
652
|
kind `dialog` or `dialog-only`), the view's route is the list route's
|
|
652
|
-
child instead
|
|
653
|
+
child instead (or, for a list at `/<entity>/list`, its sibling under
|
|
654
|
+
`listPath`; a sub-record opens over its parent's page the same way):
|
|
655
|
+
see [How a list opens a record](#how-a-list-opens-a-record).
|
|
653
656
|
8. **Add Playwright specs for all three screens**, one test per state
|
|
654
657
|
(`loading`, `empty`, `error`, `validation`, `success`), forced through
|
|
655
658
|
MSW overrides — `forceMswOverride`, `waitForMswReady` and the
|
|
@@ -789,6 +792,41 @@ plan allows it.
|
|
|
789
792
|
<Board renderCard={(item) => <RecordLink to={`/<entity>/${item.id}`}>{item.name}</RecordLink>} … />
|
|
790
793
|
```
|
|
791
794
|
|
|
795
|
+
**A list that isn't the record's parent route** (4.71: the list at
|
|
796
|
+
`/<entity>/list`, the record at `/<entity>/:id`): the route the two share
|
|
797
|
+
wraps them, with `listPath`. The list's own route has no element (the
|
|
798
|
+
`list` prop draws it), and every other child is a record. Opened from
|
|
799
|
+
the list, the record is the dialog over it; closing goes back to
|
|
800
|
+
`/<entity>/list`; a deep link is the full page, as above.
|
|
801
|
+
|
|
802
|
+
```tsx
|
|
803
|
+
{
|
|
804
|
+
path: '<entity>',
|
|
805
|
+
element: <RecordDialogRoute list={<<Entity>sTableRoute />} listPath="list" label="<Entity>" />,
|
|
806
|
+
children: [{ path: 'list' }, { path: ':id', element: <<Entity>ViewRoute /> }],
|
|
807
|
+
},
|
|
808
|
+
```
|
|
809
|
+
|
|
810
|
+
**A sub-record over its parent's page** (4.71: a parent's documents,
|
|
811
|
+
`/<parents>/7/<children>/31`): the same dialog one level down. The
|
|
812
|
+
parent's page is the `list`, the sub-record its child, and
|
|
813
|
+
`fullPage={false}`, so a reload of the sub-record's address is the dialog
|
|
814
|
+
over the parent again. The parent's table of sub-records says
|
|
815
|
+
`` opens={{ kind: 'dialog-only', to: (row) => `/<parents>/${row.parentId}/<children>/${row.id}` }} ``,
|
|
816
|
+
and the sub-record's view is its ordinary `EntityView` (`back` to the
|
|
817
|
+
parent). Keep the parent's other routes (its `edit`) siblings of
|
|
818
|
+
`<parents>/:id`, not its children: every child of the route is drawn in
|
|
819
|
+
the dialog.
|
|
820
|
+
|
|
821
|
+
```tsx
|
|
822
|
+
{
|
|
823
|
+
path: '<parents>/:id',
|
|
824
|
+
element: <RecordDialogRoute list={<<Parent>ViewRoute />} label="<Child>" fullPage={false} />,
|
|
825
|
+
children: [{ path: '<children>/:childId', element: <<Child>ViewRoute /> }],
|
|
826
|
+
},
|
|
827
|
+
{ path: '<parents>/:id/edit', element: <<Parent>FormRoute /> }, // a sibling, not a child
|
|
828
|
+
```
|
|
829
|
+
|
|
792
830
|
- **The row opens it**: a click on the row, Enter on it, ↑/↓ between
|
|
793
831
|
rows. So does a click on a link in the row to the record's own address
|
|
794
832
|
(the name cell can stay a plain `<Link>`), and in a card layout a click
|
|
@@ -964,3 +1002,45 @@ question isn't handed purchases and comics too. The tool's description
|
|
|
964
1002
|
lists each group's entities, and `group` is offered only when some entity
|
|
965
1003
|
has one; an unknown group is a refusal naming the ones there are. An
|
|
966
1004
|
entity with no group is searched only when no group is given.
|
|
1005
|
+
|
|
1006
|
+
|
|
1007
|
+
## What a chat is told about an entity
|
|
1008
|
+
|
|
1009
|
+
Four more things an app sets for AI chats (4.71), each in
|
|
1010
|
+
`backend/app/mcp_entities.py`:
|
|
1011
|
+
|
|
1012
|
+
- **`description`** on the `McpEntity`: what the entity is, in a sentence
|
|
1013
|
+
(`description="A purchase: what was bought, where and for how much"`).
|
|
1014
|
+
It's shown beside the entity's name in the `search`, `list` and
|
|
1015
|
+
`create` tools, so a chat picks the right one.
|
|
1016
|
+
- **`text_edits`**: the wire names of its long-text fields (notes, a body)
|
|
1017
|
+
that a chat changes in part with the `edit_text` tool
|
|
1018
|
+
(`text_edits=("notes",)`): `old` and `new` replace one passage, which
|
|
1019
|
+
must be found exactly once (missing, or found twice, is a refusal that
|
|
1020
|
+
says so and saves nothing), or `append` adds text on a new line at the
|
|
1021
|
+
end. It saves and logs as `update` does, so a long note isn't sent back
|
|
1022
|
+
whole to change a line. Each must be a text field of `update_schema`
|
|
1023
|
+
and not `script_only`; the backend refuses to start otherwise.
|
|
1024
|
+
- **The server's instructions** a chat gets when it connects:
|
|
1025
|
+
`register_entities(ENTITIES, instructions="…")` (or
|
|
1026
|
+
`register_instructions("…")`) adds the app's own words after the
|
|
1027
|
+
built-in ones; `register_instructions("…", replace=True)` sends only
|
|
1028
|
+
the app's. The built-in ones are written from the entities: which can
|
|
1029
|
+
be deleted (soft only, with restore; "Nothing can be deleted" only when
|
|
1030
|
+
none can) and which texts `edit_text` changes.
|
|
1031
|
+
- **An answer note**, `register_answer_note(note)`: a function given the
|
|
1032
|
+
caller, the tool's name, its arguments and the entities whose records
|
|
1033
|
+
the answer shows, which returns text appended to the answer after a
|
|
1034
|
+
blank line, or `None`. Plain or async. It runs after every answer (not
|
|
1035
|
+
a refusal); one that raises is reported and left out, and the answer
|
|
1036
|
+
stands.
|
|
1037
|
+
|
|
1038
|
+
```python
|
|
1039
|
+
def note(caller, tool, arguments, entities):
|
|
1040
|
+
if any(e.group == "health" for e in entities):
|
|
1041
|
+
return "Health records are the person's own notes, not medical advice."
|
|
1042
|
+
return None
|
|
1043
|
+
|
|
1044
|
+
register_entities(ENTITIES, instructions="Amounts are in the account's currency.")
|
|
1045
|
+
register_answer_note(note)
|
|
1046
|
+
```
|
|
@@ -26,16 +26,16 @@
|
|
|
26
26
|
- [A variant: a pressed icon inside another value's cell](#a-variant-a-pressed-icon-inside-another-values-cell) · lines 566–649
|
|
27
27
|
- [16. Title linking to the record's view](#16-title-linking-to-the-records-view) · lines 651–686
|
|
28
28
|
- [17. Quick action on the view](#17-quick-action-on-the-view) · lines 688–761
|
|
29
|
-
- [18. Editable value](#18-editable-value) · lines 763–
|
|
30
|
-
- [A list of sub-items](#a-list-of-sub-items) · lines
|
|
31
|
-
- [In a table's rows](#in-a-tables-rows) · lines
|
|
32
|
-
- [A table of a few short columns: `width="content"`](#a-table-of-a-few-short-columns-widthcontent) · lines
|
|
33
|
-
- [19. Stage circle for an ordered status](#19-stage-circle-for-an-ordered-status) · lines
|
|
34
|
-
- [20. Count linking to the related records](#20-count-linking-to-the-related-records) · lines
|
|
35
|
-
- [21. Rows grouped under headings, and a pill filter](#21-rows-grouped-under-headings-and-a-pill-filter) · lines
|
|
36
|
-
- [22. A highlighted row, and rows that are done](#22-a-highlighted-row-and-rows-that-are-done) · lines
|
|
37
|
-
- [23. A Group menu, and a record read beside the list](#23-a-group-menu-and-a-record-read-beside-the-list) · lines
|
|
38
|
-
- [24. A stored colour beside its name](#24-a-stored-colour-beside-its-name) · lines
|
|
29
|
+
- [18. Editable value](#18-editable-value) · lines 763–1228
|
|
30
|
+
- [A list of sub-items](#a-list-of-sub-items) · lines 1044–1129
|
|
31
|
+
- [In a table's rows](#in-a-tables-rows) · lines 1131–1216
|
|
32
|
+
- [A table of a few short columns: `width="content"`](#a-table-of-a-few-short-columns-widthcontent) · lines 1218–1228
|
|
33
|
+
- [19. Stage circle for an ordered status](#19-stage-circle-for-an-ordered-status) · lines 1230–1296
|
|
34
|
+
- [20. Count linking to the related records](#20-count-linking-to-the-related-records) · lines 1298–1362
|
|
35
|
+
- [21. Rows grouped under headings, and a pill filter](#21-rows-grouped-under-headings-and-a-pill-filter) · lines 1364–1432
|
|
36
|
+
- [22. A highlighted row, and rows that are done](#22-a-highlighted-row-and-rows-that-are-done) · lines 1434–1462
|
|
37
|
+
- [23. A Group menu, and a record read beside the list](#23-a-group-menu-and-a-record-read-beside-the-list) · lines 1464–1540
|
|
38
|
+
- [24. A stored colour beside its name](#24-a-stored-colour-beside-its-name) · lines 1542–1565
|
|
39
39
|
|
|
40
40
|
<!-- /index -->
|
|
41
41
|
|
|
@@ -913,8 +913,9 @@ to open, and it never closes. Ctrl/Cmd+Enter or Esc saves now and leaves
|
|
|
913
913
|
the caret where it is. It sits beside the one open value rather than
|
|
914
914
|
being it: opening another value leaves it alone. Don't give its control
|
|
915
915
|
`autoFocus`. The cost: at rest the page shows the editor, not the read
|
|
916
|
-
view,
|
|
917
|
-
|
|
916
|
+
view, and the editor loads on every visit. A click on a link in the
|
|
917
|
+
notes still opens it in a new tab (4.70.0); its words are edited from the
|
|
918
|
+
keyboard or by dragging over them, and Ctrl/Cmd+K edits its address. Use it where the notes are what the page is
|
|
918
919
|
for; elsewhere `autosave` alone keeps the read view at rest.
|
|
919
920
|
|
|
920
921
|
**Edited where it's read (`inline: true`, implies `alwaysEditable`)**,
|
|
@@ -33,8 +33,10 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
|
|
|
33
33
|
// - Edited blocks are written in the document's own bullet and rule marks.
|
|
34
34
|
// - Markdown pasted as plain text arrives formatted (still no HTML), and a
|
|
35
35
|
// copy out of the editor is Markdown.
|
|
36
|
-
// -
|
|
37
|
-
//
|
|
36
|
+
// - A click on a link opens it in a new tab, as the read view's links do,
|
|
37
|
+
// so notes that are always the editor still follow their links
|
|
38
|
+
// (followLink). Ctrl/Cmd+K adds or edits a link (a box at the caret: web
|
|
39
|
+
// and email addresses only); Ctrl/Cmd+Shift+Enter ticks the task item the caret is
|
|
38
40
|
// in. `[] ` at a line's start makes a task item, and Enter in one the
|
|
39
41
|
// next, unticked (rich-text-tasks.ts). Ctrl/Cmd+Enter stays the field's
|
|
40
42
|
// save, in a table too. Notion's block keys (Ctrl+Shift+1 for a
|
|
@@ -373,6 +375,30 @@ function linkTarget(state) {
|
|
|
373
375
|
});
|
|
374
376
|
return target;
|
|
375
377
|
}
|
|
378
|
+
// A plain click (or a tap) on a link opens it in a new tab, the way the
|
|
379
|
+
// read view's links open (markdown.tsx), so notes that are always the
|
|
380
|
+
// editor still work as notes. Not when the click chose words (a drag ends
|
|
381
|
+
// in a click too), extends the selection (Shift) or is Alt's; the address
|
|
382
|
+
// goes through linkHref again, so a link that came in with the Markdown
|
|
383
|
+
// can't run code (`javascript:`) either: that one stays text to click
|
|
384
|
+
// into. Read-only too, where the browser would otherwise follow it in this
|
|
385
|
+
// tab. To edit a link's words, put the caret in them from the keyboard or
|
|
386
|
+
// drag over them; Ctrl/Cmd+K edits its address.
|
|
387
|
+
function followLink(view, event) {
|
|
388
|
+
if (event.button !== 0 || event.shiftKey || event.altKey)
|
|
389
|
+
return false;
|
|
390
|
+
const anchor = event.target instanceof Element ? event.target.closest('a[href]') : null;
|
|
391
|
+
if (!anchor || !view.dom.contains(anchor))
|
|
392
|
+
return false;
|
|
393
|
+
if (!view.state.selection.empty)
|
|
394
|
+
return false;
|
|
395
|
+
const href = linkHref(anchor.getAttribute('href') ?? '');
|
|
396
|
+
if (!href)
|
|
397
|
+
return false;
|
|
398
|
+
event.preventDefault();
|
|
399
|
+
window.open(href, '_blank', 'noopener,noreferrer');
|
|
400
|
+
return true;
|
|
401
|
+
}
|
|
376
402
|
// Sets (or, with `href` empty, removes) the link on the target. With
|
|
377
403
|
// nothing selected and no link there, the address goes in as the link's
|
|
378
404
|
// own text.
|
|
@@ -668,6 +694,8 @@ export default function MilkdownEditor({ id, defaultValue, onChange, onProblem,
|
|
|
668
694
|
setFocused(false);
|
|
669
695
|
return false;
|
|
670
696
|
},
|
|
697
|
+
// A click on a link follows it (followLink).
|
|
698
|
+
click: (view, event) => followLink(view, event),
|
|
671
699
|
// The floating toolbar waits for the mouse to be up: a drag
|
|
672
700
|
// is still choosing the words.
|
|
673
701
|
mousedown: (_view, event) => {
|
|
@@ -1048,7 +1076,7 @@ export default function MilkdownEditor({ id, defaultValue, onChange, onProblem,
|
|
|
1048
1076
|
'[&_mark]:rounded-sm [&_mark]:text-foreground [&_mark[data-color=amber]]:bg-highlight-amber [&_mark[data-color=yellow]]:bg-highlight-yellow [&_mark[data-color=green]]:bg-highlight-green [&_mark[data-color=red]]:bg-highlight-red', '[&_li[data-item-type=task]>input]:mt-1 [&_li[data-item-type=task]>input]:size-4 [&_li[data-item-type=task]>input]:accent-primary',
|
|
1049
1077
|
// Headings, callouts and tables are drawn by their node views;
|
|
1050
1078
|
// these are the elements Milkdown draws itself.
|
|
1051
|
-
'[&_a]:text-link [&_a]:underline [&_a]:decoration-link/40 [&_a]:underline-offset-4', '[&_blockquote]:border-l-2 [&_blockquote]:border-border [&_blockquote]:pl-4 [&_blockquote]:text-muted-foreground', '[&_pre]:overflow-x-auto [&_pre]:rounded-lg [&_pre]:bg-muted [&_pre]:p-3 [&_pre]:font-mono', '[&_:not(pre)>code]:rounded [&_:not(pre)>code]:bg-muted [&_:not(pre)>code]:px-1 [&_:not(pre)>code]:font-mono', '[&_hr]:my-2 [&_hr]:h-0.5 [&_hr]:rounded-full [&_hr]:border-0 [&_hr]:bg-rule', '[&_hr.ProseMirror-selectednode]:outline-2 [&_hr.ProseMirror-selectednode]:outline-offset-4 [&_hr.ProseMirror-selectednode]:outline-ring',
|
|
1079
|
+
'[&_a]:cursor-pointer [&_a]:text-link [&_a]:underline [&_a]:decoration-link/40 [&_a]:underline-offset-4', '[&_blockquote]:border-l-2 [&_blockquote]:border-border [&_blockquote]:pl-4 [&_blockquote]:text-muted-foreground', '[&_pre]:overflow-x-auto [&_pre]:rounded-lg [&_pre]:bg-muted [&_pre]:p-3 [&_pre]:font-mono', '[&_:not(pre)>code]:rounded [&_:not(pre)>code]:bg-muted [&_:not(pre)>code]:px-1 [&_:not(pre)>code]:font-mono', '[&_hr]:my-2 [&_hr]:h-0.5 [&_hr]:rounded-full [&_hr]:border-0 [&_hr]:bg-rule', '[&_hr.ProseMirror-selectednode]:outline-2 [&_hr.ProseMirror-selectednode]:outline-offset-4 [&_hr.ProseMirror-selectednode]:outline-ring',
|
|
1052
1080
|
// An image, as <Markdown> shows it: never wider than the field.
|
|
1053
1081
|
// (ProseMirror's own separator images, around an image alone on
|
|
1054
1082
|
// its line, are left alone.)
|
|
@@ -17,8 +17,17 @@ export type RecordDialogRouteProps = {
|
|
|
17
17
|
* over the list. True by default.
|
|
18
18
|
*/
|
|
19
19
|
fullPage?: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Where the list lives when it isn't this route's own address: a child
|
|
22
|
+
* route of this one with no element (`'list'` for `/things/list`), or
|
|
23
|
+
* an absolute path under it. This route's other children are its
|
|
24
|
+
* records (`/things/12`), drawn over the list when opened from it. Left
|
|
25
|
+
* out, the list is this route's own address and its children are the
|
|
26
|
+
* records (the nested pattern).
|
|
27
|
+
*/
|
|
28
|
+
listPath?: string;
|
|
20
29
|
};
|
|
21
|
-
export declare function RecordDialogRoute({ list, label, className, fullPage }: RecordDialogRouteProps): import("react").JSX.Element;
|
|
30
|
+
export declare function RecordDialogRoute({ list, label, className, fullPage, listPath: listAt }: RecordDialogRouteProps): import("react").JSX.Element | null;
|
|
22
31
|
export type RecordLinkProps = Omit<ComponentProps<typeof Link>, 'state'>;
|
|
23
32
|
/**
|
|
24
33
|
* A link to a record that opens it over the current list (a board's card,
|
|
@@ -28,6 +28,25 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
|
|
|
28
28
|
// another page opens the dialog over its own list, at the list's plain
|
|
29
29
|
// address.
|
|
30
30
|
//
|
|
31
|
+
// A list that isn't the record's parent route (`listPath`, 4.71): the
|
|
32
|
+
// list at /things/list, the record at /things/12, siblings. The route the
|
|
33
|
+
// two share wraps them, its `list` drawn at `listPath` (whose own route
|
|
34
|
+
// has no element) and every other child the record:
|
|
35
|
+
//
|
|
36
|
+
// { path: 'things', element: <RecordDialogRoute list={<ThingsList />} listPath="list" label="Thing" />,
|
|
37
|
+
// children: [{ path: 'list' }, { path: ':id', element: <ThingView /> }] }
|
|
38
|
+
//
|
|
39
|
+
// Opened from the list, /things/12 is the dialog over /things/list, and
|
|
40
|
+
// closing goes back to it; a deep link is the full page, as above.
|
|
41
|
+
//
|
|
42
|
+
// A sub-record over its parent's page (4.71) is the same route one level
|
|
43
|
+
// down: the parent's page is the `list`, the sub-record its child, and
|
|
44
|
+
// `fullPage={false}`, so a reload of /parents/7/children/31 is the dialog
|
|
45
|
+
// over the parent again:
|
|
46
|
+
//
|
|
47
|
+
// { path: 'parents/:id', element: <RecordDialogRoute list={<ParentView />} label="Document" fullPage={false} />,
|
|
48
|
+
// children: [{ path: 'children/:childId', element: <ChildView /> }] }
|
|
49
|
+
//
|
|
31
50
|
// Inside, the record's route renders as it always does. EntityView sees
|
|
32
51
|
// the dialog (useRecordDialog): its heading names the dialog, its back link
|
|
33
52
|
// gives way to the dialog's own bar, and not found's way out closes the
|
|
@@ -40,19 +59,24 @@ import { Button, buttonVariants } from '../ui/button.js';
|
|
|
40
59
|
import { Dialog, DialogClose, DialogContent } from '../ui/dialog.js';
|
|
41
60
|
import { escapePassedThrough } from './escape-passthrough.js';
|
|
42
61
|
import { backgroundOf, recordDialogState, RecordDialogContext } from './record-dialog-context.js';
|
|
43
|
-
|
|
62
|
+
// Two paths are the same address, give or take a trailing slash.
|
|
63
|
+
const samePath = (a, b) => a.replace(/\/+$/, '') === b.replace(/\/+$/, '');
|
|
64
|
+
export function RecordDialogRoute({ list, label, className, fullPage = true, listPath: listAt }) {
|
|
44
65
|
const location = useLocation();
|
|
45
66
|
const navigationType = useNavigationType();
|
|
46
67
|
const navigate = useNavigate();
|
|
47
|
-
const
|
|
68
|
+
const childOutlet = useOutlet();
|
|
48
69
|
const titleId = useId();
|
|
49
|
-
const listPath = useResolvedPath('.').pathname;
|
|
70
|
+
const listPath = useResolvedPath(listAt ?? '.').pathname;
|
|
71
|
+
// With `listPath`, its own (element-less) child is the list, not a record.
|
|
72
|
+
const atList = listAt !== undefined && samePath(location.pathname, listPath);
|
|
73
|
+
const outlet = atList ? null : childOutlet;
|
|
50
74
|
const opened = backgroundOf(location.state);
|
|
51
75
|
// Over its own list only: opened from anywhere else, the list under it
|
|
52
76
|
// would be a page the user wasn't on.
|
|
53
77
|
// With no full page, a record opened any other way is the dialog over
|
|
54
78
|
// the list's plain address, with nothing to go back over.
|
|
55
|
-
const background = opened && opened.pathname
|
|
79
|
+
const background = opened && samePath(opened.pathname, listPath)
|
|
56
80
|
? opened
|
|
57
81
|
: !fullPage && outlet !== null
|
|
58
82
|
? { pathname: listPath, search: '', hash: '', depth: 0 }
|
|
@@ -77,6 +101,10 @@ export function RecordDialogRoute({ list, label, className, fullPage = true }) {
|
|
|
77
101
|
// The record's full page: a deep link, or "Open full page".
|
|
78
102
|
if (outlet !== null && !open)
|
|
79
103
|
return outlet;
|
|
104
|
+
// `listPath` given and this route's own address (no index route): there
|
|
105
|
+
// is no list here to draw.
|
|
106
|
+
if (listAt !== undefined && outlet === null && !atList)
|
|
107
|
+
return null;
|
|
80
108
|
return (_jsxs(_Fragment, { children: [_jsx(LocationContext.Provider, { value: listContext, children: list }), _jsx(Dialog, { open: open, onOpenChange: (next, details) => {
|
|
81
109
|
if (next)
|
|
82
110
|
return;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tristan2828/ui-foundation",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.71.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": {
|