@tristan2828/ui-foundation 4.122.0 → 4.124.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 +25 -16
- package/conventions/docs/cell-patterns.md +112 -42
- package/conventions/docs/design-language.md +48 -25
- package/dist/components/app/color-field.d.ts +22 -0
- package/dist/components/app/color-field.js +84 -0
- package/dist/components/app/data-table.d.ts +10 -1
- package/dist/components/app/data-table.js +3 -3
- package/dist/components/app/delete-action.js +3 -2
- package/dist/components/app/entity-view-facts.d.ts +8 -0
- package/dist/components/app/entity-view-facts.js +10 -4
- package/dist/components/app/filter-bar.d.ts +7 -1
- package/dist/components/app/filter-bar.js +3 -2
- package/dist/components/app/filter-date.js +2 -1
- package/dist/components/app/filter-name.d.ts +1 -0
- package/dist/components/app/filter-name.js +11 -0
- package/dist/components/app/icon-action.d.ts +8 -2
- package/dist/components/app/icon-action.js +20 -3
- package/dist/components/app/list-header.d.ts +2 -0
- package/dist/components/app/list-header.js +1 -1
- package/dist/components/app/milkdown-editor.js +19 -3
- package/dist/components/app/rich-text-editor.d.ts +2 -1
- package/dist/components/app/rich-text-editor.js +8 -4
- package/dist/components/app/rich-text-slash.d.ts +9 -3
- package/dist/components/app/rich-text-slash.js +17 -4
- package/dist/components/ui/field.js +4 -2
- package/dist/components/ui/radio-group.d.ts +5 -0
- package/dist/components/ui/radio-group.js +11 -0
- package/dist/hooks/table-url-changes.js +2 -1
- package/dist/hooks/use-table-url-state.js +15 -4
- package/dist/index.d.ts +3 -1
- package/dist/index.js +2 -0
- package/dist/lib/color-choices.d.ts +31 -0
- package/dist/lib/color-choices.js +57 -0
- package/openapi/foundation.yaml +1 -1
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ReactNode } from 'react';
|
|
1
|
+
import type { KeyboardEvent, ReactNode } from 'react';
|
|
2
2
|
import { type ActiveFilter } from './secondary-filters.js';
|
|
3
3
|
export type FilterBarSearch = {
|
|
4
4
|
value: string;
|
|
@@ -7,6 +7,12 @@ export type FilterBarSearch = {
|
|
|
7
7
|
placeholder?: string;
|
|
8
8
|
/** The box's accessible name: "Search" unless set. */
|
|
9
9
|
label?: string;
|
|
10
|
+
/**
|
|
11
|
+
* A key pressed in the box (4.123): Enter opening the one match, or
|
|
12
|
+
* "#12" going straight to record 12. Called before the box's own
|
|
13
|
+
* handling; `event.preventDefault()` keeps the key from it.
|
|
14
|
+
*/
|
|
15
|
+
onKeyDown?: (event: KeyboardEvent<HTMLInputElement>) => void;
|
|
10
16
|
};
|
|
11
17
|
export type FilterBarProps = {
|
|
12
18
|
search?: FilterBarSearch;
|
|
@@ -3,11 +3,12 @@ import { SearchIcon } from 'lucide-react';
|
|
|
3
3
|
import { InputGroup, InputGroupAddon, InputGroupInput } from '../ui/input-group.js';
|
|
4
4
|
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '../ui/select.js';
|
|
5
5
|
import { useIsPhone } from '../../hooks/use-is-phone.js';
|
|
6
|
+
import { filterName } from './filter-name.js';
|
|
6
7
|
import { SecondaryFilters } from './secondary-filters.js';
|
|
7
8
|
const SEARCH_CLASS = 'w-56 max-w-full';
|
|
8
9
|
export function FilterBar({ search, primary, primaryActive = [], secondary, active = [], onClear, onClearAll, filtersLabel = 'Filters', }) {
|
|
9
10
|
const isMobile = useIsPhone();
|
|
10
|
-
const searchBox = search ? (_jsxs(InputGroup, { className: isMobile ? 'min-w-0 flex-1 basis-40' : SEARCH_CLASS, "data-slot": "filter-bar-search", children: [_jsx(InputGroupAddon, { children: _jsx(SearchIcon, { "aria-hidden": "true" }) }), _jsx(InputGroupInput, { type: "search", value: search.value, onChange: (event) => search.onChange(event.target.value), placeholder: search.placeholder, "aria-label": search.label ?? 'Search' })] })) : null;
|
|
11
|
+
const searchBox = search ? (_jsxs(InputGroup, { className: isMobile ? 'min-w-0 flex-1 basis-40' : SEARCH_CLASS, "data-slot": "filter-bar-search", children: [_jsx(InputGroupAddon, { children: _jsx(SearchIcon, { "aria-hidden": "true" }) }), _jsx(InputGroupInput, { type: "search", value: search.value, onChange: (event) => search.onChange(event.target.value), placeholder: search.placeholder, "aria-label": search.label ?? 'Search', onKeyDown: search.onKeyDown })] })) : null;
|
|
11
12
|
if (isMobile) {
|
|
12
13
|
const hasSheet = Boolean(primary || secondary);
|
|
13
14
|
return (_jsxs("div", { "data-slot": "filter-bar", "data-layout": "phone", className: "flex flex-wrap items-center gap-2", children: [searchBox, hasSheet && (_jsxs(SecondaryFilters, { className: "contents", label: filtersLabel, active: [...primaryActive, ...active], onClear: onClearAll ?? onClear ?? (() => { }), children: [primary, secondary] }))] }));
|
|
@@ -24,5 +25,5 @@ export function FilterSelect({ label, options, value, onValueChange, anyLabel, c
|
|
|
24
25
|
const any = anyLabel ?? `Any ${label}`;
|
|
25
26
|
const picked = options.find((option) => option.value === value);
|
|
26
27
|
const shown = picked ? `${label}: ${picked.label}` : any;
|
|
27
|
-
return (_jsxs(Select, { value: picked ? picked.value : ANY, onValueChange: (next) => onValueChange(next === ANY || next === null ? '' : String(next)), children: [_jsx(SelectTrigger, { "aria-label": shown, "data-slot": "filter-select", "data-active": picked ? true : undefined, className: className, children: _jsx(SelectValue, { children: () => shown }) }), _jsxs(SelectContent, { children: [_jsx(SelectItem, { value: ANY, children: any }), options.map((option) => (_jsx(SelectItem, { value: option.value, children: option.label }, option.value)))] })] }));
|
|
28
|
+
return (_jsxs(Select, { value: picked ? picked.value : ANY, onValueChange: (next) => onValueChange(next === ANY || next === null ? '' : String(next)), children: [_jsx(SelectTrigger, { "aria-label": filterName(label, shown), "data-slot": "filter-select", "data-active": picked ? true : undefined, className: className, children: _jsx(SelectValue, { children: () => shown }) }), _jsxs(SelectContent, { children: [_jsx(SelectItem, { value: ANY, children: any }), options.map((option) => (_jsx(SelectItem, { value: option.value, children: option.label }, option.value)))] })] }));
|
|
28
29
|
}
|
|
@@ -11,6 +11,7 @@ import { cn } from 'cn';
|
|
|
11
11
|
import { Select, SelectContent, SelectItem, SelectSeparator, SelectTrigger, SelectValue } from '../ui/select.js';
|
|
12
12
|
import { DATE_FILTER_PRESETS, DATE_FILTER_PRESET_LABELS, dateFilterText, dateRangeValue, parseDateFilter, } from '../../lib/date-filter.js';
|
|
13
13
|
import { DateField } from './date-field.js';
|
|
14
|
+
import { filterName } from './filter-name.js';
|
|
14
15
|
// Base UI's Select needs a value for "any" that isn't empty.
|
|
15
16
|
const ANY = '__any__';
|
|
16
17
|
const RANGE = '__range__';
|
|
@@ -41,5 +42,5 @@ export function FilterDate({ label, value, onValueChange, presets = DATE_FILTER_
|
|
|
41
42
|
const setEnd = (end, day) => {
|
|
42
43
|
onValueChange(dateRangeValue({ ...bounds, [end]: day || undefined }));
|
|
43
44
|
};
|
|
44
|
-
return (_jsxs("div", { "data-slot": "filter-date", className: cn('flex flex-wrap items-center gap-2', className), children: [_jsxs(Select, { value: picked, onValueChange: (next) => pick(next === null ? ANY : String(next)), children: [_jsx(SelectTrigger, { "aria-label": shown, "data-slot": "filter-date-select", "data-active": filter ? true : undefined, children: _jsx(SelectValue, { children: () => shown }) }), _jsxs(SelectContent, { children: [_jsx(SelectItem, { value: ANY, children: any }), presets.map((preset) => (_jsx(SelectItem, { value: preset, children: DATE_FILTER_PRESET_LABELS[preset] }, preset))), range && (_jsxs(_Fragment, { children: [_jsx(SelectSeparator, {}), _jsx(SelectItem, { value: RANGE, children: "Between dates" })] }))] })] }), showRange && (_jsxs("div", { "data-slot": "filter-date-range", className: "flex flex-wrap items-center gap-2", children: [_jsx(DateField, { value: bounds?.from ?? '', onChange: (day) => setEnd('from', day), "aria-label": `${label} From`, placeholder: "From", format: format, locale: locale, className: "w-40" }), _jsx(DateField, { value: bounds?.to ?? '', onChange: (day) => setEnd('to', day), "aria-label": `${label} To`, placeholder: "To", format: format, locale: locale, className: "w-40" })] }))] }));
|
|
45
|
+
return (_jsxs("div", { "data-slot": "filter-date", className: cn('flex flex-wrap items-center gap-2', className), children: [_jsxs(Select, { value: picked, onValueChange: (next) => pick(next === null ? ANY : String(next)), children: [_jsx(SelectTrigger, { "aria-label": filterName(label, shown), "data-slot": "filter-date-select", "data-active": filter ? true : undefined, children: _jsx(SelectValue, { children: () => shown }) }), _jsxs(SelectContent, { children: [_jsx(SelectItem, { value: ANY, children: any }), presets.map((preset) => (_jsx(SelectItem, { value: preset, children: DATE_FILTER_PRESET_LABELS[preset] }, preset))), range && (_jsxs(_Fragment, { children: [_jsx(SelectSeparator, {}), _jsx(SelectItem, { value: RANGE, children: "Between dates" })] }))] })] }), showRange && (_jsxs("div", { "data-slot": "filter-date-range", className: "flex flex-wrap items-center gap-2", children: [_jsx(DateField, { value: bounds?.from ?? '', onChange: (day) => setEnd('from', day), "aria-label": `${label} From`, placeholder: "From", format: format, locale: locale, className: "w-40" }), _jsx(DateField, { value: bounds?.to ?? '', onChange: (day) => setEnd('to', day), "aria-label": `${label} To`, placeholder: "To", format: format, locale: locale, className: "w-40" })] }))] }));
|
|
45
46
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function filterName(label: string, shown: string): string;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// A filter select's accessible name (4.123, FilterSelect and FilterDate):
|
|
2
|
+
// what it filters first, so it's found by its label ("Status") whatever it
|
|
3
|
+
// shows, then the words shown unless they already say the label, so voice
|
|
4
|
+
// control can say them too. "Status" while it shows "Any status", "Status:
|
|
5
|
+
// Active" with a value, "Status: All reminders" for an `anyLabel` that
|
|
6
|
+
// doesn't say it.
|
|
7
|
+
export function filterName(label, shown) {
|
|
8
|
+
if (shown.startsWith(`${label}:`))
|
|
9
|
+
return shown;
|
|
10
|
+
return shown.toLowerCase().includes(label.toLowerCase()) ? label : `${label}: ${shown}`;
|
|
11
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type ComponentProps } from 'react';
|
|
2
2
|
import { Button } from '../ui/button.js';
|
|
3
3
|
import type { IconComponent } from './icon-component.js';
|
|
4
4
|
export type IconActionProps = Omit<ComponentProps<typeof Button>, 'children' | 'size' | 'aria-label'> & {
|
|
@@ -6,9 +6,15 @@ export type IconActionProps = Omit<ComponentProps<typeof Button>, 'children' | '
|
|
|
6
6
|
icon: IconComponent;
|
|
7
7
|
/** What the action does ("Delete", "Print notes"): its tooltip and accessible name. */
|
|
8
8
|
label: string;
|
|
9
|
+
/**
|
|
10
|
+
* The accessible name, when it says more than the tooltip (4.123):
|
|
11
|
+
* "Delete The Long Walk" for a tooltip of "Delete", so several on a page
|
|
12
|
+
* are told apart. Start it with `label`, so what's seen is what's said.
|
|
13
|
+
*/
|
|
14
|
+
accessibleName?: string;
|
|
9
15
|
/** `destructive` draws the icon in the destructive tone (Delete). Defaults to `default`. */
|
|
10
16
|
tone?: 'default' | 'destructive';
|
|
11
17
|
/** The button's size: `default` (36px, beside the header's other buttons) or `sm` (32px). */
|
|
12
18
|
size?: 'default' | 'sm';
|
|
13
19
|
};
|
|
14
|
-
export declare function IconAction({ icon: Icon, label, tone, size, variant, className, ...props }: IconActionProps): import("react").JSX.Element;
|
|
20
|
+
export declare function IconAction({ icon: Icon, label, accessibleName, tone, size, variant, className, render, ...props }: IconActionProps): import("react").JSX.Element;
|
|
@@ -1,7 +1,24 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
// A command drawn as its icon alone (record page standard 3.2, #R3): an
|
|
3
|
+
// outline icon button at the header's button size, its `label` both the
|
|
4
|
+
// tooltip shown on hover or focus and the button's accessible name. For
|
|
5
|
+
// the universal actions only (Delete, Print notes, Copy link, Pin, Open
|
|
6
|
+
// site, Restore, More), each with one icon across the app; a record's own
|
|
7
|
+
// commands (New visit, Mark done) stay in words.
|
|
8
|
+
//
|
|
9
|
+
// It takes every Button prop, so it can be a dialog's trigger as it is:
|
|
10
|
+
// `<DialogTrigger render={<IconAction icon={Trash2Icon} label="Delete" tone="destructive" />} />`.
|
|
11
|
+
//
|
|
12
|
+
// A link (4.123): `render={<Link to="/print" />}` or `render={<a href=… />}`
|
|
13
|
+
// draws the icon as that link, its tooltip and name kept: the link is the
|
|
14
|
+
// tooltip's trigger itself, drawn as the button, so it stays a link with
|
|
15
|
+
// its href. A link takes no Button props.
|
|
16
|
+
import { isValidElement } from 'react';
|
|
2
17
|
import { cn } from 'cn';
|
|
3
|
-
import { Button } from '../ui/button.js';
|
|
18
|
+
import { Button, buttonVariants } from '../ui/button.js';
|
|
4
19
|
import { Tooltip, TooltipContent, TooltipTrigger } from '../ui/tooltip.js';
|
|
5
|
-
export function IconAction({ icon: Icon, label, tone = 'default', size = 'default', variant = 'outline', className, ...props }) {
|
|
6
|
-
|
|
20
|
+
export function IconAction({ icon: Icon, label, accessibleName, tone = 'default', size = 'default', variant = 'outline', className, render, ...props }) {
|
|
21
|
+
const look = cn(buttonVariants({ variant, size: size === 'sm' ? 'icon-sm' : 'icon' }), className);
|
|
22
|
+
const icon = _jsx(Icon, { "aria-hidden": "true", className: cn('size-4', tone === 'destructive' && 'text-destructive-text') });
|
|
23
|
+
return (_jsxs(Tooltip, { children: [render && isValidElement(render) ? (_jsx(TooltipTrigger, { render: render, "data-slot": "icon-action", "data-variant": variant, "aria-label": accessibleName ?? label, className: look, children: icon })) : (_jsx(TooltipTrigger, { render: _jsx(Button, { ...props, render: render, "data-slot": "icon-action", variant: variant, size: size === 'sm' ? 'icon-sm' : 'icon', "aria-label": accessibleName ?? label, className: className }), children: icon })), _jsx(TooltipContent, { children: label })] }));
|
|
7
24
|
}
|
|
@@ -9,6 +9,8 @@ export type ListHeaderAction = {
|
|
|
9
9
|
label: string;
|
|
10
10
|
onSelect: () => void;
|
|
11
11
|
icon?: IconComponent;
|
|
12
|
+
/** Can't be used now (4.123): an import already running, nothing to export. The item stays in ⋯, greyed. */
|
|
13
|
+
disabled?: boolean;
|
|
12
14
|
};
|
|
13
15
|
/** The one button beside New (4.117): a link to a page, or a function. */
|
|
14
16
|
export type ListHeaderSecondaryAction = {
|
|
@@ -64,7 +64,7 @@ export function ListHeader({ title, count, description, links = [], newAction, s
|
|
|
64
64
|
// A hint line under the button lines the row up by its tops (the title
|
|
65
65
|
// and the buttons level), the line hanging below.
|
|
66
66
|
const hinted = Boolean(secondaryAction?.hint);
|
|
67
|
-
return (_jsxs("div", { "data-slot": "list-header", className: cn('flex flex-col', className), children: [_jsxs("div", { className: cn('flex flex-wrap justify-between gap-x-4 gap-y-2', hinted ? 'items-start' : 'items-center'), children: [_jsxs("h1", { className: "flex items-baseline gap-2 type-page-title text-foreground", children: [title, count !== undefined && (_jsxs("span", { className: "type-body font-normal tabular-nums text-muted-foreground", children: [_jsx("span", { className: "sr-only", children: ", " }), count] }))] }), siblings.length > 1 && _jsx(SiblingSwitch, { siblings: siblings, label: siblingsLabel ?? `${title} Lists` }), _jsxs("div", { className: cn('ml-auto flex flex-wrap gap-2', hinted ? 'items-start' : 'items-center'), children: [outLink && (_jsxs(Button, { size: "sm", variant: "outline", nativeButton: false, render: _jsx(Link, { to: outLink.to }), children: [outLink.icon && _jsx(outLink.icon, { "aria-hidden": "true" }), outLink.label] })), hasMenu && (_jsxs(DropdownMenu, { children: [_jsx(DropdownMenuTrigger, { render: _jsx(Button, { size: "icon-sm", variant: "outline", "aria-label": `More for ${title}`, "data-slot": "list-header-more", className: hasOwnMenu ? undefined : 'md:hidden' }), children: _jsx(EllipsisIcon, { "aria-hidden": "true" }) }), _jsxs(DropdownMenuContent, { align: "end", className: "w-max max-w-(--available-width) whitespace-nowrap", children: [secondaryAction && (_jsxs(_Fragment, { children: [_jsxs(DropdownMenuItem, { "data-slot": "list-header-secondary-item", className: "md:hidden", disabled: secondaryAction.disabled, render: secondaryAction.to !== undefined ? _jsx(Link, { to: secondaryAction.to }) : undefined, onClick: secondaryAction.onClick, children: [SecondaryIcon && _jsx(SecondaryIcon, { "aria-hidden": "true" }), secondaryAction.hint ? (_jsxs("span", { className: "flex flex-col", children: [secondaryAction.label, _jsx("span", { className: "sr-only", children: ", " }), _jsx("span", { "data-slot": "list-header-secondary-item-hint", className: "type-caption text-muted-foreground", children: secondaryAction.hint })] })) : (secondaryAction.label)] }), hasOwnMenu && _jsx(DropdownMenuSeparator, { className: "md:hidden" })] })), menuLinks.map((link) => (_jsxs(DropdownMenuItem, { render: _jsx(Link, { to: link.to }), children: [link.icon && _jsx(link.icon, { "aria-hidden": "true" }), link.label] }, link.label))), more.map((action) => (_jsxs(DropdownMenuItem, { onClick: action.onSelect, children: [action.icon && _jsx(action.icon, { "aria-hidden": "true" }), action.label] }, action.label))), deleted && (menuLinks.length > 0 || more.length > 0) && _jsx(DropdownMenuSeparator, {}), deleted && (_jsxs(DropdownMenuCheckboxItem, { closeOnClick: true, checked: deleted.shown, onCheckedChange: deleted.onShownChange, children: [_jsx(Trash2Icon, { "aria-hidden": "true" }), "Show Deleted"] }))] })] })), secondaryButton &&
|
|
67
|
+
return (_jsxs("div", { "data-slot": "list-header", className: cn('flex flex-col', className), children: [_jsxs("div", { className: cn('flex flex-wrap justify-between gap-x-4 gap-y-2', hinted ? 'items-start' : 'items-center'), children: [_jsxs("h1", { className: "flex items-baseline gap-2 type-page-title text-foreground", children: [title, count !== undefined && (_jsxs("span", { className: "type-body font-normal tabular-nums text-muted-foreground", children: [_jsx("span", { className: "sr-only", children: ", " }), count] }))] }), siblings.length > 1 && _jsx(SiblingSwitch, { siblings: siblings, label: siblingsLabel ?? `${title} Lists` }), _jsxs("div", { className: cn('ml-auto flex flex-wrap gap-2', hinted ? 'items-start' : 'items-center'), children: [outLink && (_jsxs(Button, { size: "sm", variant: "outline", nativeButton: false, render: _jsx(Link, { to: outLink.to }), children: [outLink.icon && _jsx(outLink.icon, { "aria-hidden": "true" }), outLink.label] })), hasMenu && (_jsxs(DropdownMenu, { children: [_jsx(DropdownMenuTrigger, { render: _jsx(Button, { size: "icon-sm", variant: "outline", "aria-label": `More for ${title}`, "data-slot": "list-header-more", className: hasOwnMenu ? undefined : 'md:hidden' }), children: _jsx(EllipsisIcon, { "aria-hidden": "true" }) }), _jsxs(DropdownMenuContent, { align: "end", className: "w-max max-w-(--available-width) whitespace-nowrap", children: [secondaryAction && (_jsxs(_Fragment, { children: [_jsxs(DropdownMenuItem, { "data-slot": "list-header-secondary-item", className: "md:hidden", disabled: secondaryAction.disabled, render: secondaryAction.to !== undefined ? _jsx(Link, { to: secondaryAction.to }) : undefined, onClick: secondaryAction.onClick, children: [SecondaryIcon && _jsx(SecondaryIcon, { "aria-hidden": "true" }), secondaryAction.hint ? (_jsxs("span", { className: "flex flex-col", children: [secondaryAction.label, _jsx("span", { className: "sr-only", children: ", " }), _jsx("span", { "data-slot": "list-header-secondary-item-hint", className: "type-caption text-muted-foreground", children: secondaryAction.hint })] })) : (secondaryAction.label)] }), hasOwnMenu && _jsx(DropdownMenuSeparator, { className: "md:hidden" })] })), menuLinks.map((link) => (_jsxs(DropdownMenuItem, { render: _jsx(Link, { to: link.to }), children: [link.icon && _jsx(link.icon, { "aria-hidden": "true" }), link.label] }, link.label))), more.map((action) => (_jsxs(DropdownMenuItem, { onClick: action.onSelect, disabled: action.disabled, children: [action.icon && _jsx(action.icon, { "aria-hidden": "true" }), action.label] }, action.label))), deleted && (menuLinks.length > 0 || more.length > 0) && _jsx(DropdownMenuSeparator, {}), deleted && (_jsxs(DropdownMenuCheckboxItem, { closeOnClick: true, checked: deleted.shown, onCheckedChange: deleted.onShownChange, children: [_jsx(Trash2Icon, { "aria-hidden": "true" }), "Show Deleted"] }))] })] })), secondaryButton &&
|
|
68
68
|
(secondaryAction?.hint ? (_jsx(ActionHint, { hint: secondaryAction.hint, className: "max-md:hidden", children: secondaryButton })) : (_jsx("span", { className: "contents max-md:hidden", children: secondaryButton }))), newAction &&
|
|
69
69
|
(newAction.to !== undefined ? (_jsxs(Button, { size: "sm", nativeButton: false, render: _jsx(Link, { to: newAction.to }), children: [_jsx(PlusIcon, { "aria-hidden": "true" }), newAction.label] })) : (_jsxs(Button, { size: "sm", onClick: newAction.onClick, children: [_jsx(PlusIcon, { "aria-hidden": "true" }), newAction.label] })))] })] }), description && (_jsx("p", { "data-slot": "list-header-description", className: "mt-1 max-w-prose type-body text-muted-foreground contain-inline-size", children: description })), _jsx("div", { role: "status", "data-slot": "list-header-notice", className: "not-empty:mt-3", children: deleted?.shown && (_jsxs(Notice, { tone: "info", icon: Trash2Icon, action: _jsx(Button, { size: "sm", variant: "outline", onClick: () => deleted.onShownChange(false), children: "Back to the List" }), children: ["Showing deleted ", deleted.noun ?? 'records', "."] })) })] }));
|
|
70
70
|
}
|
|
@@ -114,7 +114,7 @@ import { withEmptyParagraphChildren } from './rich-text-empty-paragraph.js';
|
|
|
114
114
|
import { toggleHeadingInputRule, toggleHeadingRemark, withToggle } from './rich-text-toggle-heading.js';
|
|
115
115
|
import { addRowAtEnd, colorTableCells, fitAllColumns, handleTableKey, previewColumnWidth, runTableAction, setColumnWidth, tableLook as tableLookPlugin, tableWidthsOf } from './rich-text-table.js';
|
|
116
116
|
import { TABLE_MENU_EVENT, TableGrips } from './rich-text-table-grips.js';
|
|
117
|
-
import { applySlash, closeSlash, slashItems, slashOptionId, slashPlugin, slashQuery, } from './rich-text-slash.js';
|
|
117
|
+
import { applySlash, clearSlash, closeSlash, slashItems, slashOptionId, slashPlugin, slashQuery, } from './rich-text-slash.js';
|
|
118
118
|
import { RichTextSlashMenu } from './rich-text-slash-menu.js';
|
|
119
119
|
import { RichTextToolbar } from './rich-text-toolbar.js';
|
|
120
120
|
import { RichTextToolsBar } from './rich-text-tools-bar.js';
|
|
@@ -511,6 +511,7 @@ export default function MilkdownEditor({ id, defaultValue, onChange, onProblem,
|
|
|
511
511
|
const [pageBusy, setPageBusy] = useState(false);
|
|
512
512
|
// Opens the title box: from the slash menu's keys (set up once) too.
|
|
513
513
|
const startPageRef = useRef(() => { });
|
|
514
|
+
const pickSlashImageRef = useRef(() => { });
|
|
514
515
|
// The router's navigate, for a page link's click (NavigateBridge).
|
|
515
516
|
const navigateRef = useRef(null);
|
|
516
517
|
const inRouter = useInRouterContext();
|
|
@@ -598,7 +599,7 @@ export default function MilkdownEditor({ id, defaultValue, onChange, onProblem,
|
|
|
598
599
|
// The slash menu: open while a "/" typed at a line's start is followed
|
|
599
600
|
// by something some block answers to, and the field has focus.
|
|
600
601
|
const slash = menus && !readOnly && focused && editorState ? slashQuery(editorState) : null;
|
|
601
|
-
const slashMatches = slash ? slashItems(slash.query, { page: Boolean(onCreatePage) }) : [];
|
|
602
|
+
const slashMatches = slash ? slashItems(slash.query, { page: Boolean(onCreatePage), image: Boolean(upload) }) : [];
|
|
602
603
|
const slashOpen = slash !== null && slashMatches.length > 0;
|
|
603
604
|
const slashMenuKey = slash ? `${slash.from}:${slash.query}` : '';
|
|
604
605
|
const slashIndex = slashActive.key === slashMenuKey ? Math.min(slashActive.index, slashMatches.length - 1) : 0;
|
|
@@ -898,6 +899,8 @@ export default function MilkdownEditor({ id, defaultValue, onChange, onProblem,
|
|
|
898
899
|
const item = menu.items[menu.index];
|
|
899
900
|
if (item.id === 'page')
|
|
900
901
|
startPageRef.current(view, menu.span, '');
|
|
902
|
+
else if (item.id === 'image')
|
|
903
|
+
pickSlashImageRef.current(view, menu.span);
|
|
901
904
|
else
|
|
902
905
|
applySlash(view, menu.span, item.id);
|
|
903
906
|
return true;
|
|
@@ -1020,6 +1023,14 @@ export default function MilkdownEditor({ id, defaultValue, onChange, onProblem,
|
|
|
1020
1023
|
// The toolbar's Image button: the file picker, then each file picked
|
|
1021
1024
|
// uploaded in place of the selection, and focus back in the text.
|
|
1022
1025
|
const pickImages = () => imageInputRef.current?.click();
|
|
1026
|
+
// The slash menu's Image (4.123): the "/…" goes, then the file picker;
|
|
1027
|
+
// the images go in at the caret, where the "/" was.
|
|
1028
|
+
// A tick later: Chrome opens no picker for a click made inside the
|
|
1029
|
+
// editor's own keydown (Enter on the item); the key's activation lasts.
|
|
1030
|
+
const pickSlashImage = (view, span) => {
|
|
1031
|
+
clearSlash(view, span);
|
|
1032
|
+
setTimeout(pickImages, 0);
|
|
1033
|
+
};
|
|
1023
1034
|
const imagesPicked = (files) => {
|
|
1024
1035
|
const send = latest.current.upload;
|
|
1025
1036
|
if (!editorView || !send || files.length === 0)
|
|
@@ -1182,6 +1193,7 @@ export default function MilkdownEditor({ id, defaultValue, onChange, onProblem,
|
|
|
1182
1193
|
};
|
|
1183
1194
|
useEffect(() => {
|
|
1184
1195
|
startPageRef.current = startPage;
|
|
1196
|
+
pickSlashImageRef.current = pickSlashImage;
|
|
1185
1197
|
});
|
|
1186
1198
|
// Selected words in one block (a double-click takes the space after a
|
|
1187
1199
|
// word too: the link gets the words, the spaces stay).
|
|
@@ -1284,7 +1296,11 @@ export default function MilkdownEditor({ id, defaultValue, onChange, onProblem,
|
|
|
1284
1296
|
editorView &&
|
|
1285
1297
|
createPortal(_jsx(TableGrips, { view: editorView, state: editorState, getPos: widget.getPos, frame: widget.frame, box: widget.box, table: widget.table, readOnly: readOnly, focused: focused, onAction: (cell, action) => runTableAt(widget.getPos, cell, action), onColor: (cell, scope, color) => colorTableAt(widget.getPos, cell, scope, color), onWidth: (column, width) => widthTableAt(widget.getPos, column, width), onPreviewWidth: (column, width) => previewTableWidth(widget.getPos, column, width), text: textElement }), widget.grips, `${widget.key}-grips`),
|
|
1286
1298
|
];
|
|
1287
|
-
}), slashOpen && slash && editorView && (_jsx(RichTextSlashMenu, { id: slashListId, view: editorView, at: slash.to, field: field, items: slashMatches, active: slashIndex, onHighlight: (index) => setSlashActive({ key: slashMenuKey, index }), onPick: (item) =>
|
|
1299
|
+
}), slashOpen && slash && editorView && (_jsx(RichTextSlashMenu, { id: slashListId, view: editorView, at: slash.to, field: field, items: slashMatches, active: slashIndex, onHighlight: (index) => setSlashActive({ key: slashMenuKey, index }), onPick: (item) => item === 'page'
|
|
1300
|
+
? startPage(editorView, slash, '')
|
|
1301
|
+
: item === 'image'
|
|
1302
|
+
? pickSlashImage(editorView, slash)
|
|
1303
|
+
: applySlash(editorView, slash, item) })), toolsOpen && (_jsx(RichTextToolsBar, { ref: toolsRef, state: editorState, readOnly: readOnly, fullScreen: fullScreen, controls: editableId, onFormat: runFormat, onFullScreen: toggleFullScreen, onReturn: returnToText, onBlur: (event) => {
|
|
1288
1304
|
const next = event.relatedTarget;
|
|
1289
1305
|
if (editorView && !editorView.dom.contains(next) && !inFloating(next))
|
|
1290
1306
|
setFocused(false);
|
|
@@ -45,7 +45,8 @@ export type RichTextEditorProps = {
|
|
|
45
45
|
inline?: boolean;
|
|
46
46
|
/**
|
|
47
47
|
* Images uploaded into the text: pasted, dropped, or picked with an
|
|
48
|
-
* Image button on the fixed toolbar
|
|
48
|
+
* Image button on the fixed toolbar or the slash menu's Image ("/image",
|
|
49
|
+
* 4.123, the way to pick one with only the floating toolbar). Each file goes through this (the
|
|
49
50
|
* app's own storage: the package knows no endpoint) and goes in as
|
|
50
51
|
* ``, from the result's `url`, else its `thumbUrl`. A
|
|
51
52
|
* placeholder shows where it will go while it uploads (it isn't saved);
|
|
@@ -1,4 +1,4 @@
|
|
|
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
|
// Long text written as Markdown, edited as formatted text where it's read
|
|
3
3
|
// (Notion-style), not as Markdown syntax in a textarea. The control for a
|
|
4
4
|
// `long text` field marked Markdown, on the form and in place on the view.
|
|
@@ -50,11 +50,13 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
50
50
|
// where it is. A caller that never feeds `onChange` back keeps its text.
|
|
51
51
|
//
|
|
52
52
|
// The editor (Milkdown) is loaded on first use, so a page that only reads
|
|
53
|
-
// Markdown never downloads it. Until it arrives
|
|
54
|
-
// the field
|
|
53
|
+
// Markdown never downloads it. Until it arrives the text shows as
|
|
54
|
+
// <Markdown> draws it (4.123), the field's size, so nothing moves when the
|
|
55
|
+
// editor takes its place; an empty one shows skeleton lines.
|
|
55
56
|
import { lazy, Suspense, useState } from 'react';
|
|
56
57
|
import { cn } from 'cn';
|
|
57
58
|
import { Skeleton } from '../ui/skeleton.js';
|
|
59
|
+
import { Markdown } from './markdown.js';
|
|
58
60
|
const MilkdownEditor = lazy(() => import('./milkdown-editor.js'));
|
|
59
61
|
// When the editor opens again: each time `defaultValue` changes to
|
|
60
62
|
// Markdown it didn't report. Adjusted while rendering (React's "storing
|
|
@@ -76,7 +78,9 @@ function useOpenings(defaultValue) {
|
|
|
76
78
|
export function RichTextEditor(props) {
|
|
77
79
|
const { opening, report } = useOpenings(props.defaultValue);
|
|
78
80
|
const { onChange } = props;
|
|
79
|
-
return (_jsx(Suspense, { fallback: _jsxs("div", { "data-slot": "rich-text-editor", "data-state": "loading", className: cn('flex w-full flex-col', !props.inline && 'rounded-lg border border-input', props.className), children: [(props.toolbar ?? true) === true && _jsx("div", { className: "h-9 border-b border-input" }),
|
|
81
|
+
return (_jsx(Suspense, { fallback: _jsxs("div", { "data-slot": "rich-text-editor", "data-state": "loading", className: cn('flex w-full flex-col', !props.inline && 'rounded-lg border border-input', props.className), children: [(props.toolbar ?? true) === true && _jsx("div", { className: "h-9 border-b border-input" }), _jsx("div", { "aria-busy": "true", className: cn('flex flex-col gap-2', props.inline ? 'py-0.5' : 'min-h-24 px-2.5 py-2',
|
|
82
|
+
// The room of the add-row bar the editor draws under a table.
|
|
83
|
+
!props.readOnly && '[&_table]:mb-5'), children: props.defaultValue.trim() ? (_jsx(Markdown, { headingLevel: props.headingLevel, headingFrom: props.headingFrom, foldKey: props.foldable === false ? undefined : props.foldKey, children: props.defaultValue })) : (_jsxs(_Fragment, { children: [_jsx(Skeleton, { className: "h-4 w-3/4" }), _jsx(Skeleton, { className: "h-4 w-1/2" })] })) })] }), children: _jsx(MilkdownEditor, { ...props, onChange: (markdown) => {
|
|
80
84
|
report(markdown);
|
|
81
85
|
onChange(markdown);
|
|
82
86
|
}, foldKey: props.foldable === false ? undefined : props.foldKey }, opening) }));
|
|
@@ -20,17 +20,23 @@ export declare function closeSlash(state: EditorState): Transaction;
|
|
|
20
20
|
export declare function slashOptionId(listId: string, index: number): string;
|
|
21
21
|
/** The plugin: opens on a typed "/", follows the text, closes once the span stops qualifying. */
|
|
22
22
|
export declare function slashPlugin(): Plugin<SlashState>;
|
|
23
|
-
/**
|
|
23
|
+
/**
|
|
24
|
+
* A slash menu item: a block, an image (only with the editor's `upload`,
|
|
25
|
+
* 4.123) or the new page (only with the app's `onCreatePage`).
|
|
26
|
+
*/
|
|
24
27
|
export type SlashItem = Omit<FormatItem, 'id'> & {
|
|
25
|
-
id: FormatId | 'page';
|
|
28
|
+
id: FormatId | 'image' | 'page';
|
|
26
29
|
};
|
|
27
30
|
/**
|
|
28
31
|
* The blocks matching what's typed after the "/": in the name, or the
|
|
29
|
-
* start of a keyword. With `page`, the new page
|
|
32
|
+
* start of a keyword. With `image`, an image too; with `page`, the new page.
|
|
30
33
|
*/
|
|
31
34
|
export declare function slashItems(query: string, options?: {
|
|
32
35
|
page?: boolean;
|
|
36
|
+
image?: boolean;
|
|
33
37
|
}): SlashItem[];
|
|
38
|
+
/** Picks the image item: the "/…" goes and the menu closes, the caret where it was, for the picked images. */
|
|
39
|
+
export declare function clearSlash(view: EditorView, span: SlashQuery): void;
|
|
34
40
|
/**
|
|
35
41
|
* Picks an item: the "/…" goes and the paragraph becomes that block, in one
|
|
36
42
|
* transaction (one undo step, which brings the "/…" back).
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
// `/usr/bin`) never does, and neither does a "/" mid-line or inside a
|
|
9
9
|
// list, a quote or a code block.
|
|
10
10
|
import { Plugin, PluginKey } from '@milkdown/kit/prose/state';
|
|
11
|
-
import { FileTextIcon } from 'lucide-react';
|
|
11
|
+
import { FileTextIcon, ImageIcon } from 'lucide-react';
|
|
12
12
|
import { CALLOUT_VARIANTS, FORMAT_GROUPS, HIGHLIGHT_VARIANTS, TOGGLE_HEADING_VARIANTS } from './rich-text-format-items.js';
|
|
13
13
|
import { toggleFormat } from './rich-text-formats.js';
|
|
14
14
|
const slashKey = new PluginKey('rich-text-slash');
|
|
@@ -109,26 +109,39 @@ const KEYWORDS = {
|
|
|
109
109
|
// once something's typed ("/warn"), so the list "/" opens with stays short.
|
|
110
110
|
const BLOCKS = FORMAT_GROUPS.flat().filter((item) => KEYWORDS[item.id]);
|
|
111
111
|
BLOCKS.splice(BLOCKS.findIndex((item) => item.id === 'heading3') + 1, 0, ...TOGGLE_HEADING_VARIANTS);
|
|
112
|
+
// An image (4.123): the file picker, the image going where the "/" was.
|
|
113
|
+
// The Image button's job for an editor with no fixed toolbar
|
|
114
|
+
// (`toolbar="floating"`), and a quicker way with one.
|
|
115
|
+
const IMAGE_ITEM = { id: 'image', label: 'Image', icon: ImageIcon };
|
|
116
|
+
const IMAGE_KEYWORDS = ['image', 'picture', 'photo', 'img', 'upload'];
|
|
112
117
|
// A page of its own, linked from here (src/lib/page-link.ts): last, since
|
|
113
118
|
// it's the only item that leaves the editor (a title box, then the app).
|
|
114
119
|
const PAGE_ITEM = { id: 'page', label: 'Page', icon: FileTextIcon };
|
|
115
120
|
const PAGE_KEYWORDS = ['page', 'subpage', 'child', 'link', 'new'];
|
|
116
121
|
/**
|
|
117
122
|
* The blocks matching what's typed after the "/": in the name, or the
|
|
118
|
-
* start of a keyword. With `page`, the new page
|
|
123
|
+
* start of a keyword. With `image`, an image too; with `page`, the new page.
|
|
119
124
|
*/
|
|
120
125
|
export function slashItems(query, options = {}) {
|
|
121
126
|
const typed = query.trim().toLowerCase();
|
|
122
127
|
const page = options.page && (!typed || 'page'.includes(typed) || PAGE_KEYWORDS.some((word) => word.startsWith(typed))) ? [PAGE_ITEM] : [];
|
|
128
|
+
const image = options.image && (!typed || IMAGE_KEYWORDS.some((word) => word.startsWith(typed))) ? [IMAGE_ITEM] : [];
|
|
123
129
|
if (!typed)
|
|
124
|
-
return [...BLOCKS, ...page];
|
|
130
|
+
return [...BLOCKS, ...image, ...page];
|
|
125
131
|
const blocks = [...BLOCKS];
|
|
126
132
|
blocks.splice(BLOCKS.findIndex((item) => item.id === 'callout') + 1, 0, ...CALLOUT_VARIANTS);
|
|
127
133
|
blocks.push(...HIGHLIGHT_VARIANTS);
|
|
128
|
-
const matches =
|
|
134
|
+
const matches = [
|
|
135
|
+
...blocks.filter((item) => item.label.toLowerCase().includes(typed) || KEYWORDS[item.id].some((word) => word.startsWith(typed))),
|
|
136
|
+
...image,
|
|
137
|
+
];
|
|
129
138
|
// "/page" puts the page first: it's what was asked for by name.
|
|
130
139
|
return typed.length >= 2 && 'page'.startsWith(typed) ? [...page, ...matches] : [...matches, ...page];
|
|
131
140
|
}
|
|
141
|
+
/** Picks the image item: the "/…" goes and the menu closes, the caret where it was, for the picked images. */
|
|
142
|
+
export function clearSlash(view, span) {
|
|
143
|
+
view.dispatch(view.state.tr.delete(span.from, span.to).setMeta(slashKey, 'close'));
|
|
144
|
+
}
|
|
132
145
|
/**
|
|
133
146
|
* Picks an item: the "/…" goes and the paragraph becomes that block, in one
|
|
134
147
|
* transaction (one undo step, which brings the "/…" back).
|
|
@@ -32,8 +32,10 @@ function FieldLegend({ className, variant = "legend", ...props }) {
|
|
|
32
32
|
// DateField marks its own box (`data-kind="date"`, 4.88).
|
|
33
33
|
const DATE_CONTROL = "input[type=date], [data-kind=date]";
|
|
34
34
|
const NUMBER_CONTROL = "input[type=number], input[inputmode=numeric], input[inputmode=decimal]";
|
|
35
|
-
// A row of choice buttons (ChoiceButtons, 4.98): two to a row (9C).
|
|
36
|
-
|
|
35
|
+
// A row of choice buttons (ChoiceButtons, 4.98): two to a row (9C). A
|
|
36
|
+
// ToggleGroup that is the field's own control (4.123) is one too; one
|
|
37
|
+
// nested deeper (a RecurrenceField's weekdays) isn't.
|
|
38
|
+
const CHOICE_CONTROL = "[data-slot=choice-buttons], :scope > [data-slot=toggle-group]";
|
|
37
39
|
function kindOf(field) {
|
|
38
40
|
const said = field.dataset.kind;
|
|
39
41
|
if (said === "date" || said === "number" || said === "choice")
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Radio as RadioPrimitive } from "@base-ui/react/radio";
|
|
2
|
+
import { RadioGroup as RadioGroupPrimitive } from "@base-ui/react/radio-group";
|
|
3
|
+
declare function RadioGroup({ className, ...props }: RadioGroupPrimitive.Props): import("react").JSX.Element;
|
|
4
|
+
declare function RadioGroupItem({ className, ...props }: RadioPrimitive.Root.Props): import("react").JSX.Element;
|
|
5
|
+
export { RadioGroup, RadioGroupItem };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Radio as RadioPrimitive } from "@base-ui/react/radio";
|
|
3
|
+
import { RadioGroup as RadioGroupPrimitive } from "@base-ui/react/radio-group";
|
|
4
|
+
import { cn } from "cn";
|
|
5
|
+
function RadioGroup({ className, ...props }) {
|
|
6
|
+
return (_jsx(RadioGroupPrimitive, { "data-slot": "radio-group", className: cn("grid w-full gap-2", className), ...props }));
|
|
7
|
+
}
|
|
8
|
+
function RadioGroupItem({ className, ...props }) {
|
|
9
|
+
return (_jsx(RadioPrimitive.Root, { "data-slot": "radio-group-item", className: cn("group/radio-group-item peer relative flex aspect-square size-4 shrink-0 rounded-full border border-input outline-none group-has-[:focus-visible]/field-label:ring-0 group-has-[:focus-visible]/field-label:not-data-checked:border-input after:absolute after:-inset-x-3 after:-inset-y-2 focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 aria-invalid:aria-checked:border-primary dark:bg-input/30 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 data-checked:border-primary data-checked:bg-primary data-checked:text-primary-foreground group-has-[:focus-visible]/field-label:data-checked:border-primary dark:data-checked:bg-primary", className), ...props, children: _jsx(RadioPrimitive.Indicator, { "data-slot": "radio-group-indicator", className: "flex size-4 items-center justify-center", children: _jsx("span", { className: "absolute top-1/2 left-1/2 size-2 -translate-x-1/2 -translate-y-1/2 rounded-full bg-primary-foreground" }) }) }));
|
|
10
|
+
}
|
|
11
|
+
export { RadioGroup, RadioGroupItem };
|
|
@@ -33,7 +33,8 @@ export function viewToUrlChanges(filterNames, multiFilterNames, view, asDefault
|
|
|
33
33
|
[NO_VIEW_PARAM]: null,
|
|
34
34
|
...Object.fromEntries(filterNames.map((name) => [name, own[name] ?? ''])),
|
|
35
35
|
...Object.fromEntries(multiFilterNames.map((name) => [name, asDefault ? [] : (view.multiFilters?.[name] ?? [])])),
|
|
36
|
-
|
|
36
|
+
// The default view's sort is its plain address's (4.123): not written.
|
|
37
|
+
sort: view.sort && !asDefault ? serializeSort(view.sort) : null,
|
|
37
38
|
...(view.group === undefined ? {} : { group: view.group || null }),
|
|
38
39
|
page: null,
|
|
39
40
|
};
|
|
@@ -53,15 +53,25 @@ export function useTableUrlState(filterNames, multiFilterNames = [], views = {},
|
|
|
53
53
|
browserStore.set(groupStorageKey, next);
|
|
54
54
|
};
|
|
55
55
|
const page = Math.max(1, Math.floor(Number(params.get('page'))) || 1);
|
|
56
|
-
const [sortField, sortDir] = (params.get('sort') ?? '').split(':');
|
|
57
|
-
const sorting = sortField ? [{ id: sortField, desc: sortDir === 'desc' }] : [];
|
|
58
56
|
const fallback = defaultView === undefined ? undefined : views[defaultView];
|
|
59
57
|
const state = readFilterState(params, filterNames, multiFilterNames, fallback);
|
|
60
58
|
const { filters, multiFilters } = state;
|
|
59
|
+
// The URL's sort, else the default view's at the list's plain address
|
|
60
|
+
// (4.123): pressing the default view writes no `?sort=`, as it writes no
|
|
61
|
+
// filters, and its sort still holds.
|
|
62
|
+
const urlSort = params.get('sort');
|
|
63
|
+
const [sortField, sortDir] = (urlSort ?? '').split(':');
|
|
64
|
+
const sorting = sortField && urlSort !== 'none'
|
|
65
|
+
? [{ id: sortField, desc: sortDir === 'desc' }]
|
|
66
|
+
: urlSort === null && state.atDefault && fallback?.sort
|
|
67
|
+
? [...fallback.sort]
|
|
68
|
+
: [];
|
|
69
|
+
// Leaving the plain address (a filter changed by hand) keeps the sort it showed.
|
|
70
|
+
const keptSort = urlSort === null && state.atDefault && fallback?.sort ? { sort: serializeSort(fallback.sort) } : {};
|
|
61
71
|
const activeView = activeViewOf(views, filters, multiFilters);
|
|
62
72
|
const ruleNames = ruleFilterNames(views);
|
|
63
73
|
// The reader changing filters by hand: see filterChanges.
|
|
64
|
-
const changeFilters = (changes) => update(filterChanges(state, changes, ruleNames, fallback !== undefined));
|
|
74
|
+
const changeFilters = (changes) => update({ ...keptSort, ...filterChanges(state, changes, ruleNames, fallback !== undefined) });
|
|
65
75
|
function update(changes) {
|
|
66
76
|
setParams((previous) => applyUrlChanges(previous, changes), { replace: true });
|
|
67
77
|
}
|
|
@@ -84,7 +94,8 @@ export function useTableUrlState(filterNames, multiFilterNames = [], views = {},
|
|
|
84
94
|
update({ group: next || null });
|
|
85
95
|
},
|
|
86
96
|
setPage: (next) => update({ page: next > 1 ? String(next) : null }),
|
|
87
|
-
|
|
97
|
+
// Unsorting where the default view's sort would come back writes `sort=none`.
|
|
98
|
+
setSorting: (next) => update({ sort: serializeSort(next) ?? (fallback?.sort && state.atDefault ? 'none' : null), page: null }),
|
|
88
99
|
setFilter: (name, value) => changeFilters({ [name]: value }),
|
|
89
100
|
// Several filters in one call — for any user action that changes more
|
|
90
101
|
// than one (both ends of a date range, "clear filters"). Two setters in
|
package/dist/index.d.ts
CHANGED
|
@@ -8,6 +8,8 @@ export { FillInField, FillInInput, FillInSelect, type FillInFieldKind, type Fill
|
|
|
8
8
|
export { Artwork, ArtworkTag, ArtworkToggle, type ArtworkAspect, type ArtworkProps, type ArtworkToggleProps, } from './components/app/artwork.js';
|
|
9
9
|
export { ColorSwatch, type ColorSwatchProps } from './components/app/color-swatch.js';
|
|
10
10
|
export { storedColor } from './lib/stored-color.js';
|
|
11
|
+
export { ColorField, type ColorFieldProps } from './components/app/color-field.js';
|
|
12
|
+
export { COLOR_CHOICES, type ColorChoice } from './lib/color-choices.js';
|
|
11
13
|
export { CountLink, type CountLinkProps } from './components/app/count-link.js';
|
|
12
14
|
export { DataTable, type DataTableCardLayout, type DataTableOpens, type DataTableOpensKind, type DataTableGrouping, type DataTableLook, type DataTableProps, type DataTableTotals, type DataTableWidth, type SortingState, } from './components/app/data-table.js';
|
|
13
15
|
export { type DataTableColumnsMenu, type DataTablePhoneRow, type DataTableRowAction, type DataTableView, type DataTableViewAll, } from './components/app/data-table-tools.js';
|
|
@@ -29,7 +31,7 @@ export { EmptyText, type EmptyTextProps } from './components/app/empty-value.js'
|
|
|
29
31
|
export { isEmptyValue } from './lib/empty-value.js';
|
|
30
32
|
export { IconAction, type IconActionProps } from './components/app/icon-action.js';
|
|
31
33
|
export { EntityView, type EntityViewEmptyFields, type EntityViewField, type EntityViewLayout, type EntityViewMobileOrder, type EntityViewPlacement, type EntityViewProps, type EntityViewRailFields, type EntityViewSection, } from './components/app/entity-view.js';
|
|
32
|
-
export { type EntityViewFact, type EntityViewFactAction, type EntityViewFactBadge, type EntityViewFactListItem, type EntityViewFactRatingLook, type EntityViewFactValue, } from './components/app/entity-view-facts.js';
|
|
34
|
+
export { type EntityViewFact, type EntityViewFactAction, type EntityViewFactBadge, type EntityViewFactBadgeTone, type EntityViewFactListItem, type EntityViewFactRatingLook, type EntityViewFactValue, } from './components/app/entity-view-facts.js';
|
|
33
35
|
export { entityViewTabSlug } from './lib/entity-view-tab.js';
|
|
34
36
|
export { usePrinting } from './components/app/print-context.js';
|
|
35
37
|
export { RecordDialogRoute, RecordLink, type RecordDialogRouteProps, type RecordLinkProps, } from './components/app/record-dialog.js';
|
package/dist/index.js
CHANGED
|
@@ -12,6 +12,8 @@ export { FillInField, FillInInput, FillInSelect, } from './components/app/fill-i
|
|
|
12
12
|
export { Artwork, ArtworkTag, ArtworkToggle, } from './components/app/artwork.js';
|
|
13
13
|
export { ColorSwatch } from './components/app/color-swatch.js';
|
|
14
14
|
export { storedColor } from './lib/stored-color.js';
|
|
15
|
+
export { ColorField } from './components/app/color-field.js';
|
|
16
|
+
export { COLOR_CHOICES } from './lib/color-choices.js';
|
|
15
17
|
export { CountLink } from './components/app/count-link.js';
|
|
16
18
|
export { DataTable, } from './components/app/data-table.js';
|
|
17
19
|
export {} from './components/app/data-table-tools.js';
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/** One named colour a ColorField offers: its name is shown and is its accessible label. */
|
|
2
|
+
export type ColorChoice = {
|
|
3
|
+
name: string;
|
|
4
|
+
color: string;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* ColorField's default set: twelve hues at a middle lightness, so each fill
|
|
8
|
+
* clears 3:1 against `card` in light, dark and every dark palette, and 2.3:1
|
|
9
|
+
* on Palm LCD's mid-light panel (measured in e2e/fixtures-visual.spec.ts).
|
|
10
|
+
* The swatch's ring shows its edge on any surface either way. An app with
|
|
11
|
+
* its own names or colours passes its own `colors`.
|
|
12
|
+
*/
|
|
13
|
+
export declare const COLOR_CHOICES: readonly ColorChoice[];
|
|
14
|
+
/**
|
|
15
|
+
* A stored colour in full: `storedColor`'s form with a 3- or 4-digit hex
|
|
16
|
+
* spelt out (`#fff` → `#ffffff`, `#fff8` → `#ffffff88`), so two spellings of
|
|
17
|
+
* one colour compare equal. `null` when it isn't a colour.
|
|
18
|
+
*/
|
|
19
|
+
export declare function fullHex(value: string | null | undefined): string | null;
|
|
20
|
+
/**
|
|
21
|
+
* The index of the choice a stored value is, or `-1` when it's none of them
|
|
22
|
+
* (Custom), compared in full so `#FFF`, `fff` and `#ffffff` are one colour.
|
|
23
|
+
* A value that isn't a colour (missing, empty, a typo) is `-1` too.
|
|
24
|
+
*/
|
|
25
|
+
export declare function choiceIndex(value: string | null | undefined, colors: readonly ColorChoice[]): number;
|
|
26
|
+
/**
|
|
27
|
+
* What `<input type="color">` can show for a stored value: `#rrggbb` only,
|
|
28
|
+
* so a short hex is spelt out and an alpha dropped. Black when there's no
|
|
29
|
+
* colour, the input's own default.
|
|
30
|
+
*/
|
|
31
|
+
export declare function pickerHex(value: string | null | undefined): string;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// The value handling behind ColorField: which of a set of named colours a
|
|
2
|
+
// stored value is, and what the browser's own colour picker can show. Its
|
|
3
|
+
// own file so it's tested without a browser (tests/color-field.test.tsx).
|
|
4
|
+
import { storedColor } from './stored-color.js';
|
|
5
|
+
/**
|
|
6
|
+
* ColorField's default set: twelve hues at a middle lightness, so each fill
|
|
7
|
+
* clears 3:1 against `card` in light, dark and every dark palette, and 2.3:1
|
|
8
|
+
* on Palm LCD's mid-light panel (measured in e2e/fixtures-visual.spec.ts).
|
|
9
|
+
* The swatch's ring shows its edge on any surface either way. An app with
|
|
10
|
+
* its own names or colours passes its own `colors`.
|
|
11
|
+
*/
|
|
12
|
+
export const COLOR_CHOICES = [
|
|
13
|
+
{ name: 'Red', color: '#dc2626' },
|
|
14
|
+
{ name: 'Orange', color: '#dd5208' },
|
|
15
|
+
{ name: 'Amber', color: '#c27006' },
|
|
16
|
+
{ name: 'Olive', color: '#5f8a12' },
|
|
17
|
+
{ name: 'Green', color: '#16883f' },
|
|
18
|
+
{ name: 'Teal', color: '#0d8a80' },
|
|
19
|
+
{ name: 'Cyan', color: '#0b86a8' },
|
|
20
|
+
{ name: 'Blue', color: '#2563eb' },
|
|
21
|
+
{ name: 'Indigo', color: '#5b5ee8' },
|
|
22
|
+
{ name: 'Purple', color: '#9b3fec' },
|
|
23
|
+
{ name: 'Pink', color: '#d62a74' },
|
|
24
|
+
{ name: 'Grey', color: '#737373' },
|
|
25
|
+
];
|
|
26
|
+
/**
|
|
27
|
+
* A stored colour in full: `storedColor`'s form with a 3- or 4-digit hex
|
|
28
|
+
* spelt out (`#fff` → `#ffffff`, `#fff8` → `#ffffff88`), so two spellings of
|
|
29
|
+
* one colour compare equal. `null` when it isn't a colour.
|
|
30
|
+
*/
|
|
31
|
+
export function fullHex(value) {
|
|
32
|
+
const hex = storedColor(value);
|
|
33
|
+
if (!hex)
|
|
34
|
+
return null;
|
|
35
|
+
if (hex.length > 5)
|
|
36
|
+
return hex;
|
|
37
|
+
return `#${[...hex.slice(1)].map((digit) => digit + digit).join('')}`;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* The index of the choice a stored value is, or `-1` when it's none of them
|
|
41
|
+
* (Custom), compared in full so `#FFF`, `fff` and `#ffffff` are one colour.
|
|
42
|
+
* A value that isn't a colour (missing, empty, a typo) is `-1` too.
|
|
43
|
+
*/
|
|
44
|
+
export function choiceIndex(value, colors) {
|
|
45
|
+
const hex = fullHex(value);
|
|
46
|
+
if (!hex)
|
|
47
|
+
return -1;
|
|
48
|
+
return colors.findIndex((choice) => fullHex(choice.color) === hex);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* What `<input type="color">` can show for a stored value: `#rrggbb` only,
|
|
52
|
+
* so a short hex is spelt out and an alpha dropped. Black when there's no
|
|
53
|
+
* colour, the input's own default.
|
|
54
|
+
*/
|
|
55
|
+
export function pickerHex(value) {
|
|
56
|
+
return fullHex(value)?.slice(0, 7) ?? '#000000';
|
|
57
|
+
}
|
package/openapi/foundation.yaml
CHANGED
|
@@ -349,7 +349,7 @@ components:
|
|
|
349
349
|
minLength: 1
|
|
350
350
|
maxLength: 200
|
|
351
351
|
pattern: "^FREQ=(DAILY|WEEKLY|MONTHLY|YEARLY)(;(INTERVAL|BYMONTH|BYMONTHDAY|BYDAY|UNTIL|COUNT|WKST)=[A-Z0-9,+-]+)*$"
|
|
352
|
-
# The pattern before WKST (4.95 to 4.
|
|
352
|
+
# The pattern before WKST (4.95 to 4.118). check-contract still
|
|
353
353
|
# accepts an app's copy with it: such an app can't store WKST,
|
|
354
354
|
# and needn't copy this one until it wants to.
|
|
355
355
|
x-earlier-patterns:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tristan2828/ui-foundation",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.124.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": {
|