@tristan2828/ui-foundation 4.81.0 → 4.83.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/README.md +1 -1
- package/conventions/docs/add-an-entity.md +88 -24
- package/conventions/docs/cell-patterns.md +111 -50
- package/conventions/docs/entity-plan-template.md +3 -3
- package/dist/components/app/data-table.d.ts +36 -8
- package/dist/components/app/data-table.js +142 -90
- package/dist/components/app/editable-value.js +8 -10
- package/dist/components/app/form-dialog.d.ts +29 -0
- package/dist/components/app/form-dialog.js +42 -0
- package/dist/components/app/record-dialog-context.d.ts +17 -0
- package/dist/components/app/record-dialog-context.js +10 -0
- package/dist/components/app/record-dialog.d.ts +9 -2
- package/dist/components/app/record-dialog.js +36 -9
- package/dist/components/ui/badge.d.ts +1 -1
- package/dist/components/ui/dialog.d.ts +32 -3
- package/dist/components/ui/dialog.js +63 -6
- package/dist/hooks/use-table-url-state.d.ts +19 -1
- package/dist/hooks/use-table-url-state.js +31 -3
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/package.json +1 -1
- package/styles/theme.css +6 -0
|
@@ -47,6 +47,22 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
|
|
|
47
47
|
// { path: 'parents/:id', element: <RecordDialogRoute list={<ParentView />} label="Document" fullPage={false} />,
|
|
48
48
|
// children: [{ path: 'children/:childId', element: <ChildView /> }] }
|
|
49
49
|
//
|
|
50
|
+
// A new record over its list (4.82, `newPath`): the list's `new` child
|
|
51
|
+
// route (`/widgets/new`) is the create form, drawn as its own FormDialog
|
|
52
|
+
// over the list, always: opened from the list, from anywhere else, or a
|
|
53
|
+
// deep link (a form of up to about 8 fields has no page of its own). It
|
|
54
|
+
// has no record dialog round it; FormDialog opens itself from the
|
|
55
|
+
// route's context (useNewRecordDialog), closing goes back as a record's
|
|
56
|
+
// dialog does, and `openRecord` after the save swaps the entry for the new
|
|
57
|
+
// record over the same list:
|
|
58
|
+
//
|
|
59
|
+
// { path: 'widgets', element: <RecordDialogRoute list={<WidgetsTableRoute />} label="Widget" newPath="new" />,
|
|
60
|
+
// children: [{ path: 'new', element: <NewWidgetRoute /> }, { path: ':id', element: <WidgetViewRoute /> }] }
|
|
61
|
+
//
|
|
62
|
+
// The record dialog is 1,120px (DialogContent `size="record"`, 4.82), so
|
|
63
|
+
// an EntityView with `layout="rail"` keeps its rail beside the main
|
|
64
|
+
// column, as on its page; a narrower screen stacks them.
|
|
65
|
+
//
|
|
50
66
|
// Inside, the record's route renders as it always does. EntityView sees
|
|
51
67
|
// the dialog (useRecordDialog): its heading names the dialog, its back link
|
|
52
68
|
// gives way to the dialog's own bar, and not found's way out closes the
|
|
@@ -58,16 +74,19 @@ import { cn } from 'cn';
|
|
|
58
74
|
import { Button, buttonVariants } from '../ui/button.js';
|
|
59
75
|
import { Dialog, DialogClose, DialogContent } from '../ui/dialog.js';
|
|
60
76
|
import { escapePassedThrough } from './escape-passthrough.js';
|
|
61
|
-
import { backgroundOf, recordDialogState, RecordDialogContext } from './record-dialog-context.js';
|
|
77
|
+
import { backgroundOf, NewRecordDialogContext, recordDialogState, RecordDialogContext, } from './record-dialog-context.js';
|
|
62
78
|
// Two paths are the same address, give or take a trailing slash.
|
|
63
79
|
const samePath = (a, b) => a.replace(/\/+$/, '') === b.replace(/\/+$/, '');
|
|
64
|
-
export function RecordDialogRoute({ list, label, className, fullPage = true, listPath: listAt }) {
|
|
80
|
+
export function RecordDialogRoute({ list, label, className, fullPage = true, listPath: listAt, newPath: newAt, }) {
|
|
65
81
|
const location = useLocation();
|
|
66
82
|
const navigationType = useNavigationType();
|
|
67
83
|
const navigate = useNavigate();
|
|
68
84
|
const childOutlet = useOutlet();
|
|
69
85
|
const titleId = useId();
|
|
70
86
|
const listPath = useResolvedPath(listAt ?? '.').pathname;
|
|
87
|
+
// Resolved from the list's address: `/widgets/new` beside `/widgets/12`.
|
|
88
|
+
const newPathname = useResolvedPath(newAt === undefined ? '.' : `${listPath}/${newAt}`).pathname;
|
|
89
|
+
const atNew = newAt !== undefined && samePath(location.pathname, newPathname);
|
|
71
90
|
// With `listPath`, its own (element-less) child is the list, not a record.
|
|
72
91
|
const atList = listAt !== undefined && samePath(location.pathname, listPath);
|
|
73
92
|
const outlet = atList ? null : childOutlet;
|
|
@@ -76,16 +95,19 @@ export function RecordDialogRoute({ list, label, className, fullPage = true, lis
|
|
|
76
95
|
// would be a page the user wasn't on.
|
|
77
96
|
// With no full page, a record opened any other way is the dialog over
|
|
78
97
|
// the list's plain address, with nothing to go back over.
|
|
98
|
+
// The new record's form is always over the list.
|
|
99
|
+
const plainList = { pathname: listPath, search: '', hash: '', depth: 0 };
|
|
79
100
|
const background = opened && samePath(opened.pathname, listPath)
|
|
80
101
|
? opened
|
|
81
|
-
: !fullPage && outlet !== null
|
|
82
|
-
?
|
|
102
|
+
: (!fullPage || atNew) && outlet !== null
|
|
103
|
+
? plainList
|
|
83
104
|
: null;
|
|
84
|
-
const
|
|
105
|
+
const over = outlet !== null && background !== null;
|
|
106
|
+
const open = over && !atNew;
|
|
85
107
|
// The list sees the address it was opened from, not the record's, so
|
|
86
108
|
// its URL state (filters, sort, page) stays as it was under the dialog.
|
|
87
109
|
const { pathname, search, hash } = background ?? location;
|
|
88
|
-
const listLocation = useMemo(() => ({ pathname, search, hash, state: null, key:
|
|
110
|
+
const listLocation = useMemo(() => ({ pathname, search, hash, state: null, key: over ? 'record-dialog-list' : location.key }), [pathname, search, hash, over, location.key]);
|
|
89
111
|
const listContext = useMemo(() => ({ location: listLocation, navigationType }), [listLocation, navigationType]);
|
|
90
112
|
const depth = background?.depth ?? 0;
|
|
91
113
|
const close = useCallback(() => {
|
|
@@ -98,14 +120,19 @@ export function RecordDialogRoute({ list, label, className, fullPage = true, lis
|
|
|
98
120
|
void navigate(-depth);
|
|
99
121
|
}, [navigate, location.key, depth, pathname, search, hash]);
|
|
100
122
|
const dialog = useMemo(() => ({ titleId, close }), [titleId, close]);
|
|
123
|
+
// After the save: the new record over the same list, in this entry.
|
|
124
|
+
const created = useMemo(() => ({
|
|
125
|
+
close,
|
|
126
|
+
openRecord: (to) => void navigate(to, { replace: true, state: { recordDialog: { pathname, search, hash, depth } } }),
|
|
127
|
+
}), [close, navigate, pathname, search, hash, depth]);
|
|
101
128
|
// The record's full page: a deep link, or "Open full page".
|
|
102
|
-
if (outlet !== null && !
|
|
129
|
+
if (outlet !== null && !over)
|
|
103
130
|
return outlet;
|
|
104
131
|
// `listPath` given and this route's own address (no index route): there
|
|
105
132
|
// is no list here to draw.
|
|
106
133
|
if (listAt !== undefined && outlet === null && !atList)
|
|
107
134
|
return null;
|
|
108
|
-
return (_jsxs(_Fragment, { children: [_jsx(LocationContext.Provider, { value: listContext, children: list }), _jsx(Dialog, { open: open, onOpenChange: (next, details) => {
|
|
135
|
+
return (_jsxs(_Fragment, { children: [_jsx(LocationContext.Provider, { value: listContext, children: list }), atNew && _jsx(NewRecordDialogContext.Provider, { value: created, children: outlet }), _jsx(Dialog, { open: open, onOpenChange: (next, details) => {
|
|
109
136
|
if (next)
|
|
110
137
|
return;
|
|
111
138
|
// An Esc something inside already used (a field edited in place
|
|
@@ -118,7 +145,7 @@ export function RecordDialogRoute({ list, label, className, fullPage = true, lis
|
|
|
118
145
|
return;
|
|
119
146
|
}
|
|
120
147
|
close();
|
|
121
|
-
}, children: _jsxs(DialogContent, { showCloseButton: false, "aria-labelledby": titleId, "aria-label": label, "data-slot": "record-dialog", className: cn('
|
|
148
|
+
}, children: _jsxs(DialogContent, { showCloseButton: false, "aria-labelledby": titleId, "aria-label": label, "data-slot": "record-dialog", size: "record", className: cn('gap-0 overflow-hidden p-0 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 }) })] }) })] }));
|
|
122
149
|
}
|
|
123
150
|
/**
|
|
124
151
|
* A link to a record that opens it over the current list (a board's card,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useRender } from "@base-ui/react/use-render";
|
|
2
2
|
import { type VariantProps } from "class-variance-authority";
|
|
3
3
|
declare const badgeVariants: (props?: ({
|
|
4
|
-
variant?: "link" | "success" | "default" | "outline" | "secondary" | "ghost" | "destructive" | "solid" | "
|
|
4
|
+
variant?: "link" | "success" | "default" | "outline" | "secondary" | "ghost" | "destructive" | "solid" | "info" | "warning" | "outline-success" | "outline-warning" | "outline-info" | "outline-destructive" | "tinted-success" | "tinted-warning" | "tinted-info" | "tinted-destructive" | null | undefined;
|
|
5
5
|
} & import("class-variance-authority/types").ClassProp) | undefined) => string;
|
|
6
6
|
declare function Badge({ className, variant, render, ...props }: useRender.ComponentProps<"span"> & VariantProps<typeof badgeVariants>): import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
7
7
|
export { Badge, badgeVariants };
|
|
@@ -1,12 +1,26 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import { Dialog as DialogPrimitive } from "@base-ui/react/dialog";
|
|
3
|
-
declare function Dialog({ ...props }: DialogPrimitive.Root.Props): React.JSX.Element;
|
|
3
|
+
declare function Dialog({ onOpenChange, actionsRef: actionsRefProp, children, ...props }: DialogPrimitive.Root.Props): React.JSX.Element;
|
|
4
4
|
declare function DialogTrigger({ ...props }: DialogPrimitive.Trigger.Props): React.JSX.Element;
|
|
5
5
|
declare function DialogPortal({ ...props }: DialogPrimitive.Portal.Props): React.JSX.Element;
|
|
6
6
|
declare function DialogClose({ ...props }: DialogPrimitive.Close.Props): React.JSX.Element;
|
|
7
7
|
declare function DialogOverlay({ className, ...props }: DialogPrimitive.Backdrop.Props): React.JSX.Element;
|
|
8
|
-
|
|
8
|
+
/**
|
|
9
|
+
* The dialog's width: `confirm` 420px (a question with two buttons; a
|
|
10
|
+
* bottom sheet on a phone), `form` 640px (a small form; the whole screen
|
|
11
|
+
* on a phone), `record` 1,120px (a record over its list, as wide as its
|
|
12
|
+
* page). Left out, shadcn's 384px.
|
|
13
|
+
*/
|
|
14
|
+
type DialogSize = "confirm" | "form" | "record";
|
|
15
|
+
declare function DialogContent({ className, children, showCloseButton, size, dirty, ...props }: DialogPrimitive.Popup.Props & {
|
|
9
16
|
showCloseButton?: boolean;
|
|
17
|
+
/** One of the three widths (see DialogSize). Left out, 384px. */
|
|
18
|
+
size?: DialogSize;
|
|
19
|
+
/**
|
|
20
|
+
* Something was typed and not saved: closing (Esc, the close button, a
|
|
21
|
+
* click outside, a DialogClose) asks "Discard your changes?" first.
|
|
22
|
+
*/
|
|
23
|
+
dirty?: boolean;
|
|
10
24
|
}): React.JSX.Element;
|
|
11
25
|
declare function DialogHeader({ className, ...props }: React.ComponentProps<"div">): React.JSX.Element;
|
|
12
26
|
declare function DialogFooter({ className, showCloseButton, children, ...props }: React.ComponentProps<"div"> & {
|
|
@@ -14,4 +28,19 @@ declare function DialogFooter({ className, showCloseButton, children, ...props }
|
|
|
14
28
|
}): React.JSX.Element;
|
|
15
29
|
declare function DialogTitle({ className, ...props }: DialogPrimitive.Title.Props): React.JSX.Element;
|
|
16
30
|
declare function DialogDescription({ className, ...props }: DialogPrimitive.Description.Props): React.JSX.Element;
|
|
17
|
-
|
|
31
|
+
/**
|
|
32
|
+
* "Discard your changes?": the one prompt for leaving with something typed
|
|
33
|
+
* and not saved (a dialog's `dirty`, a form's leave guard, a value edited
|
|
34
|
+
* in place). A confirm: 420px, a bottom sheet on a phone. Esc or a click
|
|
35
|
+
* outside keeps editing.
|
|
36
|
+
*/
|
|
37
|
+
declare function DiscardChangesDialog({ open, onKeepEditing, onDiscard, description, ...props }: {
|
|
38
|
+
open: boolean;
|
|
39
|
+
/** Keep editing, Esc or a click outside: the prompt closes and nothing is lost. */
|
|
40
|
+
onKeepEditing: () => void;
|
|
41
|
+
/** Discard: throw away what was typed and leave. */
|
|
42
|
+
onDiscard: () => void;
|
|
43
|
+
/** The line under the question. Defaults to "What you typed will be lost." */
|
|
44
|
+
description?: React.ReactNode;
|
|
45
|
+
} & Omit<DialogPrimitive.Popup.Props, "children">): React.JSX.Element;
|
|
46
|
+
export { Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogOverlay, DialogPortal, DialogTitle, DialogTrigger, DiscardChangesDialog, type DialogSize, };
|
|
@@ -1,11 +1,35 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import * as React from "react";
|
|
3
3
|
import { Dialog as DialogPrimitive } from "@base-ui/react/dialog";
|
|
4
4
|
import { cn } from "cn";
|
|
5
5
|
import { Button } from "./button.js";
|
|
6
6
|
import { XIcon } from "lucide-react";
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
const DialogGuardContext = React.createContext(null);
|
|
8
|
+
const IMPERATIVE = "imperative-action";
|
|
9
|
+
function Dialog({ onOpenChange, actionsRef: actionsRefProp, children, ...props }) {
|
|
10
|
+
const ownActions = React.useRef(null);
|
|
11
|
+
const actionsRef = actionsRefProp ?? ownActions;
|
|
12
|
+
const dirty = React.useRef(false);
|
|
13
|
+
const [asking, setAsking] = React.useState(false);
|
|
14
|
+
const guard = React.useMemo(() => ({
|
|
15
|
+
setDirty: (next) => {
|
|
16
|
+
dirty.current = next;
|
|
17
|
+
},
|
|
18
|
+
}), []);
|
|
19
|
+
const discard = () => {
|
|
20
|
+
setAsking(false);
|
|
21
|
+
dirty.current = false;
|
|
22
|
+
actionsRef.current?.close();
|
|
23
|
+
};
|
|
24
|
+
const ask = (_jsx(DiscardChangesDialog, { open: asking, onKeepEditing: () => setAsking(false), onDiscard: discard }));
|
|
25
|
+
return (_jsx(DialogGuardContext.Provider, { value: guard, children: _jsx(DialogPrimitive.Root, { "data-slot": "dialog", actionsRef: actionsRef, onOpenChange: (open, details) => {
|
|
26
|
+
if (!open && dirty.current && details.reason !== IMPERATIVE) {
|
|
27
|
+
details.cancel();
|
|
28
|
+
setAsking(true);
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
onOpenChange?.(open, details);
|
|
32
|
+
}, ...props, children: typeof children === "function" ? ((payload) => (_jsxs(_Fragment, { children: [children(payload), ask] }))) : (_jsxs(_Fragment, { children: [children, ask] })) }) }));
|
|
9
33
|
}
|
|
10
34
|
function DialogTrigger({ ...props }) {
|
|
11
35
|
return _jsx(DialogPrimitive.Trigger, { "data-slot": "dialog-trigger", ...props });
|
|
@@ -19,8 +43,27 @@ function DialogClose({ ...props }) {
|
|
|
19
43
|
function DialogOverlay({ className, ...props }) {
|
|
20
44
|
return (_jsx(DialogPrimitive.Backdrop, { "data-slot": "dialog-overlay", className: cn("fixed inset-0 isolate z-50 bg-black/20 duration-100 supports-backdrop-filter:backdrop-blur-sm dark:bg-black/40 data-open:animate-in data-open:fade-in-0 data-closed:animate-out data-closed:fade-out-0", className), ...props }));
|
|
21
45
|
}
|
|
22
|
-
|
|
23
|
-
|
|
46
|
+
// Written phone first, the laptop's look from `md:` (48rem), so nothing
|
|
47
|
+
// in the base classes' `sm:` (40rem) leaks into a phone's layout between
|
|
48
|
+
// the two. cn() drops each base class these replace.
|
|
49
|
+
const DIALOG_SIZE = {
|
|
50
|
+
// A phone: a sheet across the bottom, its footer's buttons full width
|
|
51
|
+
// and 40px, stacked with the action (the footer's last child) on top,
|
|
52
|
+
// clear of the home indicator.
|
|
53
|
+
confirm: cn("top-auto bottom-0 left-0 max-w-none translate-x-0 translate-y-0 rounded-t-2xl rounded-b-none sm:max-w-none data-open:slide-in-from-bottom-8 data-closed:slide-out-to-bottom-8", "max-md:[&_[data-slot=dialog-footer]]:flex-col-reverse max-md:[&_[data-slot=dialog-footer]]:pb-[calc(1rem+env(safe-area-inset-bottom))] max-md:[&_[data-slot=dialog-footer]>*]:h-10 max-md:[&_[data-slot=dialog-footer]>*]:w-full", "md:top-1/2 md:bottom-auto md:left-1/2 md:max-w-[26.25rem] md:-translate-x-1/2 md:-translate-y-1/2 md:rounded-xl md:data-open:slide-in-from-bottom-0 md:data-closed:slide-out-to-bottom-0"),
|
|
54
|
+
// A column whose children decide what scrolls (FormDialog's body). A
|
|
55
|
+
// phone: the whole screen.
|
|
56
|
+
form: cn("inset-0 flex h-dvh max-h-none max-w-none translate-x-0 translate-y-0 flex-col rounded-none ring-0 sm:max-w-none", "md:inset-auto md:top-1/2 md:left-1/2 md:h-auto md:max-h-[calc(100dvh-2rem)] md:max-w-[40rem] md:-translate-x-1/2 md:-translate-y-1/2 md:rounded-xl md:ring-1"),
|
|
57
|
+
// A phone keeps the 1rem margin round it, the rail under the main column.
|
|
58
|
+
record: "flex max-h-[calc(100dvh-2rem)] flex-col sm:max-w-[70rem]",
|
|
59
|
+
};
|
|
60
|
+
function DialogContent({ className, children, showCloseButton = true, size, dirty = false, ...props }) {
|
|
61
|
+
const guard = React.useContext(DialogGuardContext);
|
|
62
|
+
React.useEffect(() => {
|
|
63
|
+
guard?.setDirty(dirty);
|
|
64
|
+
}, [guard, dirty]);
|
|
65
|
+
React.useEffect(() => () => guard?.setDirty(false), [guard]);
|
|
66
|
+
return (_jsxs(DialogPortal, { children: [_jsx(DialogOverlay, {}), _jsxs(DialogPrimitive.Popup, { "data-slot": "dialog-content", "data-size": size, className: cn("fixed top-1/2 left-1/2 z-50 grid w-full max-w-[calc(100%-2rem)] -translate-x-1/2 -translate-y-1/2 gap-4 rounded-xl bg-popover p-4 text-sm text-popover-foreground ring-1 ring-foreground/10 duration-100 outline-none sm:max-w-sm data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95", size && DIALOG_SIZE[size], className), ...props, children: [children, showCloseButton && (_jsxs(DialogPrimitive.Close, { "data-slot": "dialog-close", render: _jsx(Button, { variant: "ghost", className: "absolute top-2 right-2", size: "icon-sm" }), children: [_jsx(XIcon, {}), _jsx("span", { className: "sr-only", children: "Close" })] }))] })] }));
|
|
24
67
|
}
|
|
25
68
|
function DialogHeader({ className, ...props }) {
|
|
26
69
|
return (_jsx("div", { "data-slot": "dialog-header", className: cn("flex flex-col gap-2", className), ...props }));
|
|
@@ -34,4 +77,18 @@ function DialogTitle({ className, ...props }) {
|
|
|
34
77
|
function DialogDescription({ className, ...props }) {
|
|
35
78
|
return (_jsx(DialogPrimitive.Description, { "data-slot": "dialog-description", className: cn("text-sm text-muted-foreground *:[a]:underline *:[a]:underline-offset-3 *:[a]:hover:text-foreground", className), ...props }));
|
|
36
79
|
}
|
|
37
|
-
|
|
80
|
+
/**
|
|
81
|
+
* "Discard your changes?": the one prompt for leaving with something typed
|
|
82
|
+
* and not saved (a dialog's `dirty`, a form's leave guard, a value edited
|
|
83
|
+
* in place). A confirm: 420px, a bottom sheet on a phone. Esc or a click
|
|
84
|
+
* outside keeps editing.
|
|
85
|
+
*/
|
|
86
|
+
function DiscardChangesDialog({ open, onKeepEditing, onDiscard, description = "What you typed will be lost.", ...props }) {
|
|
87
|
+
// Its own Root, outside any guard: rendered inside a dirty dialog, its
|
|
88
|
+
// content mustn't tell that dialog's guard it's clean.
|
|
89
|
+
return (_jsx(DialogGuardContext.Provider, { value: null, children: _jsx(DialogPrimitive.Root, { open: open, onOpenChange: (next) => {
|
|
90
|
+
if (!next)
|
|
91
|
+
onKeepEditing();
|
|
92
|
+
}, children: _jsxs(DialogContent, { size: "confirm", showCloseButton: false, "data-discard-changes": "", ...props, children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { children: "Discard your changes?" }), _jsx(DialogDescription, { children: description })] }), _jsxs(DialogFooter, { children: [_jsx(DialogClose, { render: _jsx(Button, { variant: "outline" }), children: "Keep editing" }), _jsx(Button, { variant: "destructive", onClick: onDiscard, children: "Discard" })] })] }) }) }));
|
|
93
|
+
}
|
|
94
|
+
export { Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogOverlay, DialogPortal, DialogTitle, DialogTrigger, DiscardChangesDialog, };
|
|
@@ -7,14 +7,30 @@ export type TableUrlStateOptions = {
|
|
|
7
7
|
* useTableLayout remembers a layout. Without one it lives only in the URL.
|
|
8
8
|
*/
|
|
9
9
|
groupStorageKey?: string;
|
|
10
|
+
/**
|
|
11
|
+
* The rows-per-page choices, for DataTable's `pageSizes`: `[25, 50, 100]`
|
|
12
|
+
* unless set. A size from the URL or storage that isn't one of them is
|
|
13
|
+
* ignored.
|
|
14
|
+
*/
|
|
15
|
+
pageSizes?: readonly number[];
|
|
16
|
+
/** The rows per page until one is picked: 50 unless set (one of `pageSizes`). */
|
|
17
|
+
defaultPageSize?: number;
|
|
18
|
+
/**
|
|
19
|
+
* Where the rows per page are remembered on this device, one key per table
|
|
20
|
+
* (`"my-app:tasks:page-size"`). Without one the pick lives only in the URL.
|
|
21
|
+
*/
|
|
22
|
+
pageSizeStorageKey?: string;
|
|
10
23
|
};
|
|
11
|
-
export declare function useTableUrlState<F extends string, M extends string = never, V extends string = never>(filterNames: readonly F[], multiFilterNames?: readonly M[], views?: Readonly<Record<V, TableView<NoInfer<F>, NoInfer<M>>>>, { groupStorageKey }?: TableUrlStateOptions): {
|
|
24
|
+
export declare function useTableUrlState<F extends string, M extends string = never, V extends string = never>(filterNames: readonly F[], multiFilterNames?: readonly M[], views?: Readonly<Record<V, TableView<NoInfer<F>, NoInfer<M>>>>, { groupStorageKey, pageSizes, defaultPageSize, pageSizeStorageKey, }?: TableUrlStateOptions): {
|
|
12
25
|
page: number;
|
|
13
26
|
sorting: SortingState;
|
|
14
27
|
filters: Record<F, string>;
|
|
15
28
|
multiFilters: Record<M, string[]>;
|
|
16
29
|
activeView: V | null;
|
|
17
30
|
grouping: string;
|
|
31
|
+
pageSize: number;
|
|
32
|
+
pageSizes: readonly number[];
|
|
33
|
+
setPageSize: (next: number) => void;
|
|
18
34
|
setGrouping: (next: string) => void;
|
|
19
35
|
setPage: (next: number) => void;
|
|
20
36
|
setSorting: (next: SortingState) => void;
|
|
@@ -23,3 +39,5 @@ export declare function useTableUrlState<F extends string, M extends string = ne
|
|
|
23
39
|
setMultiFilter: (name: M, values: string[]) => void;
|
|
24
40
|
applyView: (view: TableView<F, M>) => void;
|
|
25
41
|
};
|
|
42
|
+
/** The rows per page: the URL's if it's one of the choices, then the remembered one, then the default. */
|
|
43
|
+
export declare function resolvePageSize(pageSizes: readonly number[], fromUrl: string | null, remembered: string | null, defaultPageSize: number): number;
|
|
@@ -2,6 +2,7 @@ import { useCallback, useSyncExternalStore } from 'react';
|
|
|
2
2
|
import { useSearchParams } from 'react-router';
|
|
3
3
|
import { activeViewOf, applyUrlChanges, serializeSort, viewToUrlChanges, } from './table-url-changes.js';
|
|
4
4
|
import { browserStore } from './use-table-layout.js';
|
|
5
|
+
const DEFAULT_PAGE_SIZES = [25, 50, 100];
|
|
5
6
|
// A table's page, sort and filters, kept in the URL query string
|
|
6
7
|
// (`?page=2&sort=name:asc&search=mouse&tags=fragile&tags=bulky`) instead of
|
|
7
8
|
// component state, so they survive going to the edit form and back, a
|
|
@@ -17,6 +18,11 @@ import { browserStore } from './use-table-layout.js';
|
|
|
17
18
|
// counts as active); pass that view's `columns` to DataTable. A view is
|
|
18
19
|
// pressed with applyView().
|
|
19
20
|
//
|
|
21
|
+
// `pageSize` is the rows per page, for the query and DataTable: `?size=` in
|
|
22
|
+
// the URL, then the one remembered under `pageSizeStorageKey`, then
|
|
23
|
+
// `defaultPageSize`; `setPageSize` (DataTable's `onPageSizeChange`) picks
|
|
24
|
+
// one and returns to page 1. `pageSizes` is the menu's choices.
|
|
25
|
+
//
|
|
20
26
|
// `grouping` is DataTable's: a grouping's id, or '' for None. It's
|
|
21
27
|
// `?group=` in the URL, then the one remembered under `groupStorageKey`,
|
|
22
28
|
// then None. Like the sort it doesn't change which rows are shown, so it
|
|
@@ -24,10 +30,11 @@ import { browserStore } from './use-table-layout.js';
|
|
|
24
30
|
// names a `group` sets it when pressed.
|
|
25
31
|
//
|
|
26
32
|
// Every setter is one update(), and must stay one: see setFilters.
|
|
27
|
-
export function useTableUrlState(filterNames, multiFilterNames = [], views = {}, { groupStorageKey } = {}) {
|
|
33
|
+
export function useTableUrlState(filterNames, multiFilterNames = [], views = {}, { groupStorageKey, pageSizes = DEFAULT_PAGE_SIZES, defaultPageSize = 50, pageSizeStorageKey, } = {}) {
|
|
28
34
|
const [params, setParams] = useSearchParams();
|
|
29
|
-
const
|
|
30
|
-
const
|
|
35
|
+
const rememberedPageSize = useRemembered(pageSizeStorageKey);
|
|
36
|
+
const pageSize = resolvePageSize(pageSizes, params.get('size'), rememberedPageSize, defaultPageSize);
|
|
37
|
+
const rememberedGrouping = useRemembered(groupStorageKey);
|
|
31
38
|
const grouping = params.get('group') ?? rememberedGrouping ?? '';
|
|
32
39
|
const rememberGrouping = (next) => {
|
|
33
40
|
if (groupStorageKey !== undefined)
|
|
@@ -49,6 +56,13 @@ export function useTableUrlState(filterNames, multiFilterNames = [], views = {},
|
|
|
49
56
|
multiFilters,
|
|
50
57
|
activeView,
|
|
51
58
|
grouping,
|
|
59
|
+
pageSize,
|
|
60
|
+
pageSizes,
|
|
61
|
+
setPageSize: (next) => {
|
|
62
|
+
if (pageSizeStorageKey !== undefined)
|
|
63
|
+
browserStore.set(pageSizeStorageKey, String(next));
|
|
64
|
+
update({ size: next === defaultPageSize ? null : String(next), page: null });
|
|
65
|
+
},
|
|
52
66
|
setGrouping: (next) => {
|
|
53
67
|
rememberGrouping(next);
|
|
54
68
|
update({ group: next || null });
|
|
@@ -73,3 +87,17 @@ export function useTableUrlState(filterNames, multiFilterNames = [], views = {},
|
|
|
73
87
|
},
|
|
74
88
|
};
|
|
75
89
|
}
|
|
90
|
+
// A value remembered on this device under `key`, or null (none, or no key).
|
|
91
|
+
function useRemembered(key) {
|
|
92
|
+
const subscribe = useCallback((listener) => (key === undefined ? () => { } : browserStore.subscribe(key, listener)), [key]);
|
|
93
|
+
return useSyncExternalStore(subscribe, () => (key === undefined ? null : browserStore.get(key)), () => null);
|
|
94
|
+
}
|
|
95
|
+
/** The rows per page: the URL's if it's one of the choices, then the remembered one, then the default. */
|
|
96
|
+
export function resolvePageSize(pageSizes, fromUrl, remembered, defaultPageSize) {
|
|
97
|
+
for (const candidate of [fromUrl, remembered]) {
|
|
98
|
+
const size = candidate === null ? NaN : Number(candidate);
|
|
99
|
+
if (pageSizes.includes(size))
|
|
100
|
+
return size;
|
|
101
|
+
}
|
|
102
|
+
return defaultPageSize;
|
|
103
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -19,7 +19,8 @@ export { EntityView, type EntityViewEmptyFields, type EntityViewField, type Enti
|
|
|
19
19
|
export { entityViewTabSlug } from './lib/entity-view-tab.js';
|
|
20
20
|
export { usePrinting } from './components/app/print-context.js';
|
|
21
21
|
export { RecordDialogRoute, RecordLink, type RecordDialogRouteProps, type RecordLinkProps, } from './components/app/record-dialog.js';
|
|
22
|
-
export { recordDialogState, useOpenRecord, useRecordDialog, type RecordDialogBackground, type RecordDialogContextValue, type RecordDialogState, } from './components/app/record-dialog-context.js';
|
|
22
|
+
export { recordDialogState, useNewRecordDialog, useOpenRecord, useRecordDialog, type NewRecordDialogContextValue, type RecordDialogBackground, type RecordDialogContextValue, type RecordDialogState, } from './components/app/record-dialog-context.js';
|
|
23
|
+
export { FormDialog, type FormDialogProps } from './components/app/form-dialog.js';
|
|
23
24
|
export { editInPlace, type EditControlProps, type EditInPlace, type EditInPlaceList, type EditInPlaceListOptions, type EditInPlaceOptions, type EditKind, type EditListAddProps, type EditListItemProps, } from './components/app/edit-in-place.js';
|
|
24
25
|
export { inPlace, type InPlaceDateConfig, type InPlaceFieldsOptions, type InPlaceLinkConfig, type InPlaceLinkValue, type InPlaceMoneyConfig, type InPlaceMonthDayConfig, type InPlaceNumberConfig, type InPlaceOption, type InPlacePart, type InPlaceRecord, type InPlaceReferenceConfig, type InPlaceSaved, type InPlaceSelectConfig, type InPlaceTextConfig, } from './components/app/edit-in-place-presets.js';
|
|
25
26
|
export { linkHost, linkHref, linkRule } from './lib/link-href.js';
|
package/dist/index.js
CHANGED
|
@@ -23,7 +23,8 @@ export { EntityView, } from './components/app/entity-view.js';
|
|
|
23
23
|
export { entityViewTabSlug } from './lib/entity-view-tab.js';
|
|
24
24
|
export { usePrinting } from './components/app/print-context.js';
|
|
25
25
|
export { RecordDialogRoute, RecordLink, } from './components/app/record-dialog.js';
|
|
26
|
-
export { recordDialogState, useOpenRecord, useRecordDialog, } from './components/app/record-dialog-context.js';
|
|
26
|
+
export { recordDialogState, useNewRecordDialog, useOpenRecord, useRecordDialog, } from './components/app/record-dialog-context.js';
|
|
27
|
+
export { FormDialog } from './components/app/form-dialog.js';
|
|
27
28
|
export { editInPlace, } from './components/app/edit-in-place.js';
|
|
28
29
|
export { inPlace, } from './components/app/edit-in-place-presets.js';
|
|
29
30
|
export { linkHost, linkHref, linkRule } from './lib/link-href.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tristan2828/ui-foundation",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.83.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": {
|
package/styles/theme.css
CHANGED
|
@@ -672,6 +672,11 @@
|
|
|
672
672
|
6.75:1. In dark the usual muted already clears it (6.61:1). */
|
|
673
673
|
--table-highlight: color-mix(in srgb, var(--info) 10%, var(--background));
|
|
674
674
|
--table-highlight-muted-foreground: var(--gray-600);
|
|
675
|
+
/* A body row under the pointer (DataTable, 4.83): the muted fill, solid
|
|
676
|
+
so pinned cells can wear it. Muted text measures 4.34:1 on it, so the
|
|
677
|
+
row takes --table-highlight-muted-foreground's darker grey (7.0:1).
|
|
678
|
+
In dark the usual muted clears it (5.9:1); a palette's dim, 5.8. */
|
|
679
|
+
--table-hover: var(--muted);
|
|
675
680
|
--border: var(--gray-200);
|
|
676
681
|
--input: var(--gray-200);
|
|
677
682
|
--ring: var(--gray-400);
|
|
@@ -962,6 +967,7 @@
|
|
|
962
967
|
--category-12-depth-5-foreground: var(--black);
|
|
963
968
|
--table-stripe: color-mix(in srgb, var(--muted) 40%, var(--background));
|
|
964
969
|
--table-highlight: color-mix(in srgb, var(--info) 20%, var(--background));
|
|
970
|
+
--table-hover: var(--muted);
|
|
965
971
|
--table-highlight-muted-foreground: var(--gray-400); /* the usual muted: not var(--muted-foreground), which the row redefines from this */
|
|
966
972
|
--border: var(--white-a10);
|
|
967
973
|
--input: var(--white-a15);
|