@tristan2828/ui-foundation 4.86.0 → 4.88.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 +52 -23
- package/conventions/docs/cell-patterns.md +49 -24
- package/conventions/docs/design-language.md +30 -3
- package/dist/components/app/app-shell-nav.d.ts +24 -0
- package/dist/components/app/app-shell-nav.js +30 -0
- package/dist/components/app/app-shell.d.ts +12 -1
- package/dist/components/app/app-shell.js +19 -5
- package/dist/components/app/choice-buttons.d.ts +25 -0
- package/dist/components/app/choice-buttons.js +17 -0
- package/dist/components/app/date-field.d.ts +28 -9
- package/dist/components/app/date-field.js +103 -10
- package/dist/components/app/edit-in-place-controls.d.ts +1 -3
- package/dist/components/app/edit-in-place-controls.js +4 -58
- package/dist/components/app/edit-in-place-presets.d.ts +38 -4
- package/dist/components/app/edit-in-place-presets.js +48 -27
- package/dist/components/app/edit-row.d.ts +7 -0
- package/dist/components/app/edit-row.js +23 -0
- package/dist/components/app/editable-value.d.ts +8 -1
- package/dist/components/app/editable-value.js +36 -4
- package/dist/components/app/entity-view.d.ts +11 -1
- package/dist/components/app/entity-view.js +19 -2
- package/dist/components/app/multi-pick.d.ts +8 -1
- package/dist/components/app/multi-pick.js +19 -5
- package/dist/components/app/multi-reference.d.ts +8 -1
- package/dist/components/app/multi-reference.js +44 -6
- package/dist/components/app/page-trail-context.d.ts +18 -0
- package/dist/components/app/page-trail-context.js +28 -0
- package/dist/components/app/page-trail.d.ts +1 -1
- package/dist/components/app/page-trail.js +1 -1
- package/dist/components/app/reference-combobox.d.ts +37 -0
- package/dist/components/app/reference-combobox.js +96 -0
- package/dist/components/app/search-palette.d.ts +29 -0
- package/dist/components/app/search-palette.js +160 -0
- package/dist/components/ui/field.d.ts +2 -2
- package/dist/components/ui/field.js +2 -1
- package/dist/hooks/use-recent-record.d.ts +10 -0
- package/dist/hooks/use-recent-record.js +20 -0
- package/dist/index.d.ts +7 -2
- package/dist/index.js +6 -1
- package/dist/lib/names-record.d.ts +4 -0
- package/dist/lib/names-record.js +7 -0
- package/dist/lib/plain-date.d.ts +20 -0
- package/dist/lib/plain-date.js +72 -0
- package/dist/lib/search-palette.d.ts +50 -0
- package/dist/lib/search-palette.js +119 -0
- package/package.json +1 -1
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
// Search in AppShell's bar (#N6): a box in the header (a button on a
|
|
3
|
+
// phone) and Ctrl K (⌘K on a Mac) open a palette that finds a page or a
|
|
4
|
+
// record by name, and Enter opens it. Before you type it lists the
|
|
5
|
+
// records you opened lately (useRecentRecord), then the first pages.
|
|
6
|
+
//
|
|
7
|
+
// A combobox over a listbox in a dialog (WAI-ARIA's "combobox with
|
|
8
|
+
// listbox popup"): focus stays in the box, the arrows move the
|
|
9
|
+
// highlighted option (aria-activedescendant), Enter opens it, Esc
|
|
10
|
+
// closes. Hand-rolled because shadcn's Command needs cmdk, which isn't
|
|
11
|
+
// on the package's allowlist; the dialog is the foundation's own.
|
|
12
|
+
import { SearchIcon } from 'lucide-react';
|
|
13
|
+
import { useEffect, useId, useMemo, useRef, useState } from 'react';
|
|
14
|
+
import { useNavigate } from 'react-router';
|
|
15
|
+
import { cn } from 'cn';
|
|
16
|
+
import { useDebouncedValue } from '../../hooks/use-debounced-value.js';
|
|
17
|
+
import { groupRecords, matchPages, readRecentRecords, searchPages, } from '../../lib/search-palette.js';
|
|
18
|
+
import { Button } from '../ui/button.js';
|
|
19
|
+
import { Dialog, DialogContent, DialogDescription, DialogTitle } from '../ui/dialog.js';
|
|
20
|
+
import { Spinner } from '../ui/spinner.js';
|
|
21
|
+
// How long typing pauses before findRecords is asked.
|
|
22
|
+
const SEARCH_DELAY_MS = 150;
|
|
23
|
+
const PAGES_BEFORE_TYPING = 5;
|
|
24
|
+
const PAGES_MATCHED = 6;
|
|
25
|
+
function isMac() {
|
|
26
|
+
return typeof navigator !== 'undefined' && /Mac|iPhone|iPad/.test(navigator.platform || navigator.userAgent);
|
|
27
|
+
}
|
|
28
|
+
/** The box (md and up) and the button (a phone) that open the palette, and the palette. */
|
|
29
|
+
export function SearchPalette({ search, nav }) {
|
|
30
|
+
const [open, setOpen] = useState(false);
|
|
31
|
+
const placeholder = search.placeholder ?? 'Search';
|
|
32
|
+
const shortcut = isMac() ? '⌘K' : 'Ctrl K';
|
|
33
|
+
// Ctrl K or ⌘K from anywhere, unless something on the page (an
|
|
34
|
+
// editor's link shortcut) has already taken it.
|
|
35
|
+
useEffect(() => {
|
|
36
|
+
const onKeyDown = (event) => {
|
|
37
|
+
if (event.defaultPrevented || event.altKey || event.shiftKey)
|
|
38
|
+
return;
|
|
39
|
+
if (event.key.toLowerCase() !== 'k' || !(event.ctrlKey || event.metaKey))
|
|
40
|
+
return;
|
|
41
|
+
event.preventDefault();
|
|
42
|
+
setOpen((current) => !current);
|
|
43
|
+
};
|
|
44
|
+
window.addEventListener('keydown', onKeyDown);
|
|
45
|
+
return () => window.removeEventListener('keydown', onKeyDown);
|
|
46
|
+
}, []);
|
|
47
|
+
return (_jsxs(_Fragment, { children: [_jsxs("button", { type: "button", "data-slot": "app-shell-search", "aria-keyshortcuts": "Control+K Meta+K", "aria-haspopup": "dialog", onClick: () => setOpen(true), className: "hidden h-8 w-56 shrink-0 items-center gap-2 rounded-lg border border-input bg-background px-2.5 text-sm text-muted-foreground transition-colors outline-none hover:bg-muted hover:text-foreground focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 md:flex lg:w-64", children: [_jsx(SearchIcon, { "aria-hidden": "true", className: "size-4 shrink-0" }), _jsx("span", { className: "min-w-0 flex-1 truncate text-left", children: placeholder }), _jsx("kbd", { className: "shrink-0 rounded-sm border border-border px-1 font-mono text-xs text-muted-foreground", children: shortcut })] }), _jsx(Button, { variant: "ghost", size: "icon-sm", "data-slot": "app-shell-search-button", "aria-label": placeholder, "aria-haspopup": "dialog", className: "md:hidden", onClick: () => setOpen(true), children: _jsx(SearchIcon, {}) }), _jsx(Dialog, { open: open, onOpenChange: setOpen, children: open && _jsx(Palette, { search: search, nav: nav, placeholder: placeholder, onClose: () => setOpen(false) }) })] }));
|
|
48
|
+
}
|
|
49
|
+
function Palette({ search, nav, placeholder, onClose, }) {
|
|
50
|
+
const navigate = useNavigate();
|
|
51
|
+
const id = useId();
|
|
52
|
+
const listId = `${id}-list`;
|
|
53
|
+
const [query, setQuery] = useState('');
|
|
54
|
+
const [active, setActive] = useState(0);
|
|
55
|
+
const [found, setFound] = useState(null);
|
|
56
|
+
// Read once, as the palette opens: the record you just left is there.
|
|
57
|
+
const [recent] = useState(() => search.recent === false ? [] : readRecentRecords().slice(0, search.recent ?? 5));
|
|
58
|
+
const pages = useMemo(() => searchPages(nav), [nav]);
|
|
59
|
+
const text = query.trim();
|
|
60
|
+
const debounced = useDebouncedValue(text, SEARCH_DELAY_MS);
|
|
61
|
+
const findRecords = search.findRecords;
|
|
62
|
+
// The latest findRecords without re-asking when only its identity changes.
|
|
63
|
+
const findRef = useRef(findRecords);
|
|
64
|
+
useEffect(() => {
|
|
65
|
+
findRef.current = findRecords;
|
|
66
|
+
}, [findRecords]);
|
|
67
|
+
const canFind = findRecords !== undefined;
|
|
68
|
+
useEffect(() => {
|
|
69
|
+
const find = findRef.current;
|
|
70
|
+
if (!find || !debounced)
|
|
71
|
+
return;
|
|
72
|
+
const controller = new AbortController();
|
|
73
|
+
// Through a microtask, so the effect itself doesn't set state.
|
|
74
|
+
void Promise.resolve()
|
|
75
|
+
.then(() => {
|
|
76
|
+
if (!controller.signal.aborted)
|
|
77
|
+
setFound({ query: debounced, status: 'loading' });
|
|
78
|
+
return find(debounced, { signal: controller.signal });
|
|
79
|
+
})
|
|
80
|
+
.then((records) => {
|
|
81
|
+
if (!controller.signal.aborted)
|
|
82
|
+
setFound({ query: debounced, status: 'success', records });
|
|
83
|
+
}, () => {
|
|
84
|
+
if (!controller.signal.aborted)
|
|
85
|
+
setFound({ query: debounced, status: 'error' });
|
|
86
|
+
});
|
|
87
|
+
return () => controller.abort();
|
|
88
|
+
}, [debounced]);
|
|
89
|
+
// What the records part says for the text on screen: found, still
|
|
90
|
+
// looking (typing, or asked), or couldn't look.
|
|
91
|
+
const records = !canFind || !text ? null : found?.query === text ? found : { query: text, status: 'loading' };
|
|
92
|
+
const groups = [];
|
|
93
|
+
if (!text && recent.length > 0)
|
|
94
|
+
groups.push({
|
|
95
|
+
heading: 'Recent',
|
|
96
|
+
options: recent.map((record, index) => ({ id: `${id}-recent-${index}`, label: record.title, detail: record.detail, to: record.to })),
|
|
97
|
+
});
|
|
98
|
+
const matched = matchPages(pages, text, text ? PAGES_MATCHED : PAGES_BEFORE_TYPING);
|
|
99
|
+
if (matched.length > 0)
|
|
100
|
+
groups.push({
|
|
101
|
+
heading: 'Pages',
|
|
102
|
+
options: matched.map((page, index) => ({ id: `${id}-page-${index}`, label: page.label, to: page.to })),
|
|
103
|
+
});
|
|
104
|
+
if (records?.status === 'success')
|
|
105
|
+
groupRecords(records.records).forEach((group, groupIndex) => groups.push({
|
|
106
|
+
heading: group.kind,
|
|
107
|
+
options: group.records.map((record, index) => ({
|
|
108
|
+
id: `${id}-record-${groupIndex}-${index}`,
|
|
109
|
+
label: record.title,
|
|
110
|
+
detail: record.detail,
|
|
111
|
+
to: record.to,
|
|
112
|
+
})),
|
|
113
|
+
}));
|
|
114
|
+
const options = groups.flatMap((group) => group.options);
|
|
115
|
+
const activeIndex = options.length === 0 ? -1 : Math.min(active, options.length - 1);
|
|
116
|
+
const activeOption = activeIndex >= 0 ? options[activeIndex] : undefined;
|
|
117
|
+
useEffect(() => {
|
|
118
|
+
if (activeOption)
|
|
119
|
+
document.getElementById(activeOption.id)?.scrollIntoView({ block: 'nearest' });
|
|
120
|
+
}, [activeOption]);
|
|
121
|
+
const go = (option) => {
|
|
122
|
+
onClose();
|
|
123
|
+
void navigate(option.to);
|
|
124
|
+
};
|
|
125
|
+
const onKeyDown = (event) => {
|
|
126
|
+
if (options.length === 0)
|
|
127
|
+
return;
|
|
128
|
+
const move = (to) => {
|
|
129
|
+
event.preventDefault();
|
|
130
|
+
setActive((to + options.length) % options.length);
|
|
131
|
+
};
|
|
132
|
+
if (event.key === 'ArrowDown')
|
|
133
|
+
move(activeIndex + 1);
|
|
134
|
+
else if (event.key === 'ArrowUp')
|
|
135
|
+
move(activeIndex - 1);
|
|
136
|
+
else if (event.key === 'Home' && event.ctrlKey)
|
|
137
|
+
move(0);
|
|
138
|
+
else if (event.key === 'End' && event.ctrlKey)
|
|
139
|
+
move(options.length - 1);
|
|
140
|
+
else if (event.key === 'Enter' && activeOption) {
|
|
141
|
+
event.preventDefault();
|
|
142
|
+
go(activeOption);
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
const nothing = text && options.length === 0 && records?.status !== 'loading';
|
|
146
|
+
return (_jsxs(DialogContent, { showCloseButton: false, "data-slot": "search-palette", className: "top-[12vh] max-h-[76vh] translate-y-0 grid-rows-[auto_minmax(0,1fr)] gap-0 overflow-hidden p-0 sm:max-w-lg", children: [_jsx(DialogTitle, { className: "sr-only", children: placeholder }), _jsx(DialogDescription, { className: "sr-only", children: "Type a page or a record's name; the arrows move through what's found and Enter opens it." }), _jsxs("div", { className: "flex items-center gap-2 border-b border-border px-3", children: [_jsx(SearchIcon, { "aria-hidden": "true", className: "size-4 shrink-0 text-muted-foreground" }), _jsx("input", { role: "combobox", "aria-label": placeholder, "aria-expanded": options.length > 0, "aria-controls": listId, "aria-autocomplete": "list", "aria-activedescendant": activeOption?.id, autoComplete: "off", spellCheck: false, value: query, placeholder: "Go to a page or find a record\u2026", onChange: (event) => {
|
|
147
|
+
setQuery(event.target.value);
|
|
148
|
+
setActive(0);
|
|
149
|
+
}, onKeyDown: onKeyDown, className: "h-11 min-w-0 flex-1 bg-transparent text-base outline-none placeholder:text-muted-foreground md:text-sm" }), records?.status === 'loading' && _jsx(Spinner, { "aria-label": "Searching", className: "size-4 text-muted-foreground" })] }), _jsxs("div", { className: "min-h-0 overflow-y-auto p-1", children: [_jsx("div", { role: "listbox", id: listId, "aria-label": placeholder, children: groups.map((group, groupIndex) => (_jsxs("div", { role: "group", "aria-labelledby": `${id}-group-${groupIndex}`, children: [_jsx("div", { id: `${id}-group-${groupIndex}`, className: "px-2 pt-2 pb-1 type-caption text-muted-foreground", children: group.heading }), group.options.map((option) => {
|
|
150
|
+
const selected = option.id === activeOption?.id;
|
|
151
|
+
return (_jsxs("div", { id: option.id, role: "option", "aria-selected": selected, "data-slot": "search-palette-option",
|
|
152
|
+
// A pointer moving over an option highlights it; a
|
|
153
|
+
// click opens it, focus staying in the box.
|
|
154
|
+
onPointerMove: () => {
|
|
155
|
+
const index = options.indexOf(option);
|
|
156
|
+
if (index !== activeIndex)
|
|
157
|
+
setActive(index);
|
|
158
|
+
}, onMouseDown: (event) => event.preventDefault(), onClick: () => go(option), className: cn('flex min-h-9 cursor-pointer items-center gap-2 rounded-md px-2 py-1.5 text-sm text-foreground', selected && 'bg-muted'), children: [_jsx("span", { className: "min-w-0 flex-1 truncate", children: option.label }), option.detail && (_jsx("span", { className: cn('shrink-0 type-caption', selected ? 'text-foreground' : 'text-muted-foreground'), children: option.detail }))] }, option.id));
|
|
159
|
+
})] }, `${groupIndex}:${group.heading}`))) }), records?.status === 'error' && (_jsx("p", { role: "status", className: "px-2 py-2 text-sm text-muted-foreground", children: "Couldn't search records. Pages are still listed; try again in a moment." })), nothing && (_jsxs("p", { role: "status", className: "px-2 py-6 text-center text-sm text-muted-foreground", children: ["Nothing found for \u201C", text, "\u201D."] })), !text && options.length === 0 && (_jsx("p", { className: "px-2 py-6 text-center text-sm text-muted-foreground", children: "Type to find a page or a record." }))] })] }));
|
|
160
|
+
}
|
|
@@ -21,8 +21,8 @@ declare function Field({ className, orientation, size, solo, kind, ...props }: R
|
|
|
21
21
|
solo?: boolean;
|
|
22
22
|
/**
|
|
23
23
|
* A date or a number: two of a kind stay side by side on a phone.
|
|
24
|
-
* Found by itself for a date or number `<input
|
|
25
|
-
* control of your own
|
|
24
|
+
* Found by itself for a date or number `<input>` and for DateField
|
|
25
|
+
* (which marks itself, 4.88); say it for a control of your own.
|
|
26
26
|
*/
|
|
27
27
|
kind?: FieldKind;
|
|
28
28
|
}): import("react").JSX.Element;
|
|
@@ -27,7 +27,8 @@ function FieldLegend({ className, variant = "legend", ...props }) {
|
|
|
27
27
|
}
|
|
28
28
|
// What a Field holds, when it doesn't say (`kind`): a date or a number
|
|
29
29
|
// box keeps its partner on a phone.
|
|
30
|
-
|
|
30
|
+
// DateField marks its own box (`data-kind="date"`, 4.88).
|
|
31
|
+
const DATE_CONTROL = "input[type=date], [data-kind=date]";
|
|
31
32
|
const NUMBER_CONTROL = "input[type=number], input[inputmode=numeric], input[inputmode=decimal]";
|
|
32
33
|
function kindOf(field) {
|
|
33
34
|
const said = field.dataset.kind;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type RecentRecord } from '../lib/search-palette.js';
|
|
2
|
+
/**
|
|
3
|
+
* Remembers a record as opened, on this device, for AppShell's search
|
|
4
|
+
* palette, which lists the last few before you type (#N6). Call it in a
|
|
5
|
+
* record's view once the record has loaded; pass nothing while it
|
|
6
|
+
* loads. Kept in localStorage (the latest 20), forgotten on logout.
|
|
7
|
+
*
|
|
8
|
+
* useRecentRecord(task && { title: task.title, to: `/tasks/${task.id}`, detail: 'Task' })
|
|
9
|
+
*/
|
|
10
|
+
export declare function useRecentRecord(record: RecentRecord | null | undefined | false): void;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
import { rememberRecentRecord } from '../lib/search-palette.js';
|
|
3
|
+
/**
|
|
4
|
+
* Remembers a record as opened, on this device, for AppShell's search
|
|
5
|
+
* palette, which lists the last few before you type (#N6). Call it in a
|
|
6
|
+
* record's view once the record has loaded; pass nothing while it
|
|
7
|
+
* loads. Kept in localStorage (the latest 20), forgotten on logout.
|
|
8
|
+
*
|
|
9
|
+
* useRecentRecord(task && { title: task.title, to: `/tasks/${task.id}`, detail: 'Task' })
|
|
10
|
+
*/
|
|
11
|
+
export function useRecentRecord(record) {
|
|
12
|
+
const title = record ? record.title : undefined;
|
|
13
|
+
const to = record ? record.to : undefined;
|
|
14
|
+
const detail = record ? record.detail : undefined;
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
if (title === undefined || to === undefined || !title.trim())
|
|
17
|
+
return;
|
|
18
|
+
rememberRecentRecord({ title, to, detail });
|
|
19
|
+
}, [title, to, detail]);
|
|
20
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { AppShell, type AppShellProps, type AppShellVersion, type BottomBarItem, type NavEntry, type NavItem, type NavSection, } from './components/app/app-shell.js';
|
|
1
|
+
export { AppShell, type AppShellProps, type AppShellSearch, type RecentRecord, type SearchRecord, type AppShellVersion, type BottomBarItem, type NavEntry, type NavItem, type NavSection, } from './components/app/app-shell.js';
|
|
2
2
|
export type { IconComponent } from './components/app/icon-component.js';
|
|
3
3
|
export { Board, type BoardColumn, type BoardMoveTarget, type BoardProps } from './components/app/board.js';
|
|
4
4
|
export { SpinWheel, type SpinWheelProps } from './components/app/spin-wheel.js';
|
|
@@ -18,6 +18,8 @@ export { EntityForm, type EntityFormProps } from './components/app/entity-form.j
|
|
|
18
18
|
export { countFormErrors } from './lib/form-errors.js';
|
|
19
19
|
export { FormSection, type FormSectionProps } from './components/app/form-section.js';
|
|
20
20
|
export { OptionSelect, type OptionSelectOption, type OptionSelectProps } from './components/app/option-select.js';
|
|
21
|
+
export { ChoiceButtons, type ChoiceButtonsOption, type ChoiceButtonsProps } from './components/app/choice-buttons.js';
|
|
22
|
+
export { ReferenceCombobox, type ReferenceComboboxProps, type ReferenceRecord } from './components/app/reference-combobox.js';
|
|
21
23
|
export { fieldRows, type FieldKind, type FieldRowItem, type FieldRowPlace, type FieldSize } from './lib/field-rows.js';
|
|
22
24
|
export { KeyStats, type KeyStat, type KeyStatsProps } from './components/app/key-stats.js';
|
|
23
25
|
export { IconAction, type IconActionProps } from './components/app/icon-action.js';
|
|
@@ -32,11 +34,14 @@ export { inPlace, type InPlaceDateConfig, type InPlaceFieldsOptions, type InPlac
|
|
|
32
34
|
export { linkHost, linkHref, linkRule } from './lib/link-href.js';
|
|
33
35
|
export { DataEnvironmentBanner } from './components/app/data-environment-banner.js';
|
|
34
36
|
export { EditableValue, type EditableValueProps } from './components/app/editable-value.js';
|
|
37
|
+
export { editRowClass, onEditRowClick, SAVED_FOR_MS } from './components/app/edit-row.js';
|
|
35
38
|
export { ErrorState } from './components/app/error-state.js';
|
|
36
39
|
export { InlineCreate, type InlineCreateProps } from './components/app/inline-create.js';
|
|
37
40
|
export { FoundationProviders } from './components/app/foundation-providers.js';
|
|
38
41
|
export { Markdown, type MarkdownProps } from './components/app/markdown.js';
|
|
39
42
|
export { PageTrail, type PageCrumb, type PageTrailProps } from './components/app/page-trail.js';
|
|
43
|
+
export { usePageTrail } from './components/app/page-trail-context.js';
|
|
44
|
+
export { useRecentRecord } from './hooks/use-recent-record.js';
|
|
40
45
|
export type { CreatePage, PageLinkInfo, PageLinkResolver } from './lib/page-link.js';
|
|
41
46
|
export { countTasks, toggleTaskAt, type TaskCount } from './lib/markdown-tasks.js';
|
|
42
47
|
export { NotesOutline, type NotesOutlineProps } from './components/app/notes-outline.js';
|
|
@@ -74,7 +79,7 @@ export { EmojiField, type EmojiFieldProps } from './components/app/emoji-field.j
|
|
|
74
79
|
export { MonthDayField, type MonthDayFieldProps } from './components/app/month-day-field.js';
|
|
75
80
|
export { ImageField, type ImageFieldProps } from './components/app/image-field.js';
|
|
76
81
|
export { DEFAULT_IMAGE_TYPES, type ImageUpload, type ImageUploadResult } from './lib/image-file.js';
|
|
77
|
-
export { formatPlainDate, type PlainDate } from './lib/plain-date.js';
|
|
82
|
+
export { formatPlainDate, parsePlainDate, plainDateExamples, unreadableDateMessage, type ParsePlainDateOptions, type PlainDate, } from './lib/plain-date.js';
|
|
78
83
|
export { formatMonthDay, isMonthDay, monthDayProblem, type MonthDay } from './lib/month-day.js';
|
|
79
84
|
export { ChoiceCell, LinkCell, LinkOut, NameCell, type ChoiceCellProps, type LinkCellProps, type NameCellProps, } from './components/app/row-edit-cells.js';
|
|
80
85
|
export { ModuleCard, ModuleStrip, type CategorySlot, type ModuleCardLink, type ModuleCardPlace, type ModuleCardProps, type ModuleStripMobile, type ModuleStripProps, } from './components/app/module-card.js';
|
package/dist/index.js
CHANGED
|
@@ -22,6 +22,8 @@ export { EntityForm } from './components/app/entity-form.js';
|
|
|
22
22
|
export { countFormErrors } from './lib/form-errors.js';
|
|
23
23
|
export { FormSection } from './components/app/form-section.js';
|
|
24
24
|
export { OptionSelect } from './components/app/option-select.js';
|
|
25
|
+
export { ChoiceButtons } from './components/app/choice-buttons.js';
|
|
26
|
+
export { ReferenceCombobox } from './components/app/reference-combobox.js';
|
|
25
27
|
export { fieldRows } from './lib/field-rows.js';
|
|
26
28
|
export { KeyStats } from './components/app/key-stats.js';
|
|
27
29
|
export { IconAction } from './components/app/icon-action.js';
|
|
@@ -36,11 +38,14 @@ export { inPlace, } from './components/app/edit-in-place-presets.js';
|
|
|
36
38
|
export { linkHost, linkHref, linkRule } from './lib/link-href.js';
|
|
37
39
|
export { DataEnvironmentBanner } from './components/app/data-environment-banner.js';
|
|
38
40
|
export { EditableValue } from './components/app/editable-value.js';
|
|
41
|
+
export { editRowClass, onEditRowClick, SAVED_FOR_MS } from './components/app/edit-row.js';
|
|
39
42
|
export { ErrorState } from './components/app/error-state.js';
|
|
40
43
|
export { InlineCreate } from './components/app/inline-create.js';
|
|
41
44
|
export { FoundationProviders } from './components/app/foundation-providers.js';
|
|
42
45
|
export { Markdown } from './components/app/markdown.js';
|
|
43
46
|
export { PageTrail } from './components/app/page-trail.js';
|
|
47
|
+
export { usePageTrail } from './components/app/page-trail-context.js';
|
|
48
|
+
export { useRecentRecord } from './hooks/use-recent-record.js';
|
|
44
49
|
export { countTasks, toggleTaskAt } from './lib/markdown-tasks.js';
|
|
45
50
|
export { NotesOutline } from './components/app/notes-outline.js';
|
|
46
51
|
export { MockModeBanner } from './components/app/mock-mode-banner.js';
|
|
@@ -76,7 +81,7 @@ export { EmojiField } from './components/app/emoji-field.js';
|
|
|
76
81
|
export { MonthDayField } from './components/app/month-day-field.js';
|
|
77
82
|
export { ImageField } from './components/app/image-field.js';
|
|
78
83
|
export { DEFAULT_IMAGE_TYPES } from './lib/image-file.js';
|
|
79
|
-
export { formatPlainDate } from './lib/plain-date.js';
|
|
84
|
+
export { formatPlainDate, parsePlainDate, plainDateExamples, unreadableDateMessage, } from './lib/plain-date.js';
|
|
80
85
|
export { formatMonthDay, isMonthDay, monthDayProblem } from './lib/month-day.js';
|
|
81
86
|
export { ChoiceCell, LinkCell, LinkOut, NameCell, } from './components/app/row-edit-cells.js';
|
|
82
87
|
export { ModuleCard, ModuleStrip, } from './components/app/module-card.js';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// Whether a typed name is already one of the records (a reference picker's
|
|
2
|
+
// Create "<typed>" is offered only when it isn't).
|
|
3
|
+
/** Whether `name` is one of the records' names, ignoring case and spaces at the ends. */
|
|
4
|
+
export function namesRecord(records, name) {
|
|
5
|
+
const wanted = name.trim().toLowerCase();
|
|
6
|
+
return records.some((record) => record.label.trim().toLowerCase() === wanted);
|
|
7
|
+
}
|
package/dist/lib/plain-date.d.ts
CHANGED
|
@@ -10,3 +10,23 @@ export declare function formatPlainDate(value: PlainDate, options?: Intl.DateTim
|
|
|
10
10
|
export declare function plainDateToLocal(value: PlainDate): Date | undefined;
|
|
11
11
|
/** A local Date's own calendar day, as `'YYYY-MM-DD'`. */
|
|
12
12
|
export declare function localToPlainDate(date: Date): PlainDate;
|
|
13
|
+
/** Whether the locale writes the day before the month (3/14 in en-US, 14/3 in en-GB). */
|
|
14
|
+
export declare function dayFirst(locale?: string): boolean;
|
|
15
|
+
/** What `parsePlainDate` is told: today's day (for "today" and a day with no year) and the locale. */
|
|
16
|
+
export type ParsePlainDateOptions = {
|
|
17
|
+
/** Today, `'YYYY-MM-DD'`. Defaults to the browser's own today. */
|
|
18
|
+
today?: PlainDate;
|
|
19
|
+
/** Decides `3/4`'s order: month first in en-US, day first in en-GB. */
|
|
20
|
+
locale?: string;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Reads a day typed by hand: `3/14`, `3/14/26`, `Mar 14`, `March 14 2026`,
|
|
24
|
+
* `14 Mar`, `2026-03-14`, `today`, `yesterday`, `tomorrow`. A day with no
|
|
25
|
+
* year is in today's year. Gives `'YYYY-MM-DD'`, `''` for blank, or
|
|
26
|
+
* `null` for something that isn't a day (`Feb 30`, `soon`).
|
|
27
|
+
*/
|
|
28
|
+
export declare function parsePlainDate(text: string, options?: ParsePlainDateOptions): PlainDate | null;
|
|
29
|
+
/** Two days typed the way the locale writes them, for an empty box: "3/14 or Mar 14" (en-US), "14/3 or 14 Mar" (en-GB). */
|
|
30
|
+
export declare function plainDateExamples(locale?: string): string;
|
|
31
|
+
/** What a typed day says when it can't be read: "Try a date like 3/14 or Mar 14". */
|
|
32
|
+
export declare function unreadableDateMessage(locale?: string): string;
|
package/dist/lib/plain-date.js
CHANGED
|
@@ -35,3 +35,75 @@ export function localToPlainDate(date) {
|
|
|
35
35
|
const pad = (n) => String(n).padStart(2, '0');
|
|
36
36
|
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}`;
|
|
37
37
|
}
|
|
38
|
+
const MONTHS = ['jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec'];
|
|
39
|
+
/** Whether the locale writes the day before the month (3/14 in en-US, 14/3 in en-GB). */
|
|
40
|
+
export function dayFirst(locale) {
|
|
41
|
+
const order = new Intl.DateTimeFormat(locale, { day: 'numeric', month: 'numeric', timeZone: 'UTC' })
|
|
42
|
+
.formatToParts(Date.UTC(2026, 2, 14))
|
|
43
|
+
.filter((part) => part.type === 'day' || part.type === 'month');
|
|
44
|
+
return order[0]?.type === 'day';
|
|
45
|
+
}
|
|
46
|
+
function dayOf(year, month, day) {
|
|
47
|
+
const pad = (n) => String(n).padStart(2, '0');
|
|
48
|
+
const value = `${String(year).padStart(4, '0')}-${pad(month)}-${pad(day)}`;
|
|
49
|
+
return parts(value) ? value : null;
|
|
50
|
+
}
|
|
51
|
+
const fullYear = (typed, fallback) => {
|
|
52
|
+
if (typed === undefined)
|
|
53
|
+
return fallback;
|
|
54
|
+
return typed.length <= 2 ? 2000 + Number(typed) : Number(typed);
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* Reads a day typed by hand: `3/14`, `3/14/26`, `Mar 14`, `March 14 2026`,
|
|
58
|
+
* `14 Mar`, `2026-03-14`, `today`, `yesterday`, `tomorrow`. A day with no
|
|
59
|
+
* year is in today's year. Gives `'YYYY-MM-DD'`, `''` for blank, or
|
|
60
|
+
* `null` for something that isn't a day (`Feb 30`, `soon`).
|
|
61
|
+
*/
|
|
62
|
+
export function parsePlainDate(text, options = {}) {
|
|
63
|
+
const typed = text.trim().toLowerCase().replace(/\s+/g, ' ');
|
|
64
|
+
if (typed === '')
|
|
65
|
+
return '';
|
|
66
|
+
const today = options.today && parts(options.today) ? options.today : localToPlainDate(new Date());
|
|
67
|
+
const [year, month, day] = parts(today);
|
|
68
|
+
const shift = (days) => localToPlainDate(new Date(year, month - 1, day + days));
|
|
69
|
+
if (typed === 'today')
|
|
70
|
+
return today;
|
|
71
|
+
if (typed === 'yesterday')
|
|
72
|
+
return shift(-1);
|
|
73
|
+
if (typed === 'tomorrow')
|
|
74
|
+
return shift(1);
|
|
75
|
+
let match = /^(\d{4})-(\d{1,2})-(\d{1,2})$/.exec(typed);
|
|
76
|
+
if (match)
|
|
77
|
+
return dayOf(Number(match[1]), Number(match[2]), Number(match[3]));
|
|
78
|
+
match = /^(\d{1,2})[/.-](\d{1,2})(?:[/.-](\d{2}|\d{4}))?$/.exec(typed);
|
|
79
|
+
if (match) {
|
|
80
|
+
const [a, b] = [Number(match[1]), Number(match[2])];
|
|
81
|
+
const [m, d] = dayFirst(options.locale) ? [b, a] : [a, b];
|
|
82
|
+
return dayOf(fullYear(match[3], year), m, d);
|
|
83
|
+
}
|
|
84
|
+
const monthOf = (word) => {
|
|
85
|
+
const at = MONTHS.indexOf(word.slice(0, 3));
|
|
86
|
+
return at !== -1 && word.length >= 3 ? at + 1 : null;
|
|
87
|
+
};
|
|
88
|
+
// Mar 14, March 14 2026, Mar 14, 2026
|
|
89
|
+
match = /^([a-z]+)\.? (\d{1,2})(?:st|nd|rd|th)?(?:,? (\d{4}))?$/.exec(typed);
|
|
90
|
+
if (match) {
|
|
91
|
+
const m = monthOf(match[1]);
|
|
92
|
+
return m ? dayOf(fullYear(match[3], year), m, Number(match[2])) : null;
|
|
93
|
+
}
|
|
94
|
+
// 14 Mar, 14 March 2026
|
|
95
|
+
match = /^(\d{1,2})(?:st|nd|rd|th)? ([a-z]+)\.?(?:,? (\d{4}))?$/.exec(typed);
|
|
96
|
+
if (match) {
|
|
97
|
+
const m = monthOf(match[2]);
|
|
98
|
+
return m ? dayOf(fullYear(match[3], year), m, Number(match[1])) : null;
|
|
99
|
+
}
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
/** Two days typed the way the locale writes them, for an empty box: "3/14 or Mar 14" (en-US), "14/3 or 14 Mar" (en-GB). */
|
|
103
|
+
export function plainDateExamples(locale) {
|
|
104
|
+
return dayFirst(locale) ? '14/3 or 14 Mar' : '3/14 or Mar 14';
|
|
105
|
+
}
|
|
106
|
+
/** What a typed day says when it can't be read: "Try a date like 3/14 or Mar 14". */
|
|
107
|
+
export function unreadableDateMessage(locale) {
|
|
108
|
+
return `Try a date like ${plainDateExamples(locale)}`;
|
|
109
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { type NavEntry } from '../components/app/app-shell-nav.js';
|
|
2
|
+
/**
|
|
3
|
+
* One record the app's `findRecords` found: its title, the page it opens
|
|
4
|
+
* (`to`, through the router), the heading it's listed under (`kind`,
|
|
5
|
+
* "Exercises"; "Records" without one), and a grey word beside it
|
|
6
|
+
* (`detail`, the module it's in, say).
|
|
7
|
+
*/
|
|
8
|
+
export type SearchRecord = {
|
|
9
|
+
title: string;
|
|
10
|
+
to: string;
|
|
11
|
+
kind?: string;
|
|
12
|
+
detail?: string;
|
|
13
|
+
};
|
|
14
|
+
/** A record opened lately (`useRecentRecord`), as the palette lists it before you type. */
|
|
15
|
+
export type RecentRecord = {
|
|
16
|
+
title: string;
|
|
17
|
+
to: string;
|
|
18
|
+
/** A grey word beside it, as a found record's `detail`. */
|
|
19
|
+
detail?: string;
|
|
20
|
+
};
|
|
21
|
+
/** A nav page as the palette lists it: "Finance · Accounts" for a module's own page. */
|
|
22
|
+
export type SearchPage = {
|
|
23
|
+
label: string;
|
|
24
|
+
name: string;
|
|
25
|
+
to: string;
|
|
26
|
+
};
|
|
27
|
+
/** Every page in the nav, each once, a module's own pages named with their module. */
|
|
28
|
+
export declare function searchPages(nav: readonly NavEntry[]): SearchPage[];
|
|
29
|
+
/**
|
|
30
|
+
* The pages whose name (or module and name) has the text in it, the
|
|
31
|
+
* closest first, then the nav's order; at most `limit`. No text: the
|
|
32
|
+
* first `limit` pages.
|
|
33
|
+
*/
|
|
34
|
+
export declare function matchPages(pages: readonly SearchPage[], query: string, limit: number): SearchPage[];
|
|
35
|
+
/** The records under their kinds, each kind once, in the order its first record came. */
|
|
36
|
+
export declare function groupRecords(records: readonly SearchRecord[]): {
|
|
37
|
+
kind: string;
|
|
38
|
+
records: SearchRecord[];
|
|
39
|
+
}[];
|
|
40
|
+
export declare const RECENT_RECORDS_KEY = "ui-foundation:recent-records";
|
|
41
|
+
/** How many are kept; the palette shows its `recent` of them. */
|
|
42
|
+
export declare const RECENT_RECORDS_KEPT = 20;
|
|
43
|
+
type StorageLike = Pick<Storage, 'getItem' | 'setItem' | 'removeItem'>;
|
|
44
|
+
/** The records opened lately, the latest first. Nothing when storage is missing or holds something else. */
|
|
45
|
+
export declare function readRecentRecords(store?: StorageLike | null): RecentRecord[];
|
|
46
|
+
/** Puts a record first among the recent ones (once, by its `to`), keeping the latest RECENT_RECORDS_KEPT. */
|
|
47
|
+
export declare function rememberRecentRecord(record: RecentRecord, store?: StorageLike | null): void;
|
|
48
|
+
/** Forgets every recent record (AppShell does on logout, so the next person doesn't see them). */
|
|
49
|
+
export declare function clearRecentRecords(store?: StorageLike | null): void;
|
|
50
|
+
export {};
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
// The search palette's logic (src/components/app/search-palette.tsx,
|
|
2
|
+
// AppShell's `search`, #N6): the nav's pages filtered by name, the app's
|
|
3
|
+
// records grouped by kind, and the records opened lately, remembered on
|
|
4
|
+
// the device. Pure, apart from the storage the recent records are kept in.
|
|
5
|
+
import { childItems, isNavSection } from '../components/app/app-shell-nav.js';
|
|
6
|
+
/** Every page in the nav, each once, a module's own pages named with their module. */
|
|
7
|
+
export function searchPages(nav) {
|
|
8
|
+
const seen = new Set();
|
|
9
|
+
const pages = [];
|
|
10
|
+
const add = (page) => {
|
|
11
|
+
if (seen.has(page.to))
|
|
12
|
+
return;
|
|
13
|
+
seen.add(page.to);
|
|
14
|
+
pages.push(page);
|
|
15
|
+
};
|
|
16
|
+
for (const entry of nav) {
|
|
17
|
+
for (const item of isNavSection(entry) ? entry.items : [entry]) {
|
|
18
|
+
add({ label: item.label, name: item.label, to: item.to });
|
|
19
|
+
for (const child of childItems(item))
|
|
20
|
+
add({ label: `${item.label} · ${child.label}`, name: child.label, to: child.to });
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return pages;
|
|
24
|
+
}
|
|
25
|
+
// How close a name is to the text: the whole name, then a name starting
|
|
26
|
+
// with it, then a word starting with it, then anywhere. -1 is no match.
|
|
27
|
+
function closeness(name, text) {
|
|
28
|
+
const lower = name.toLowerCase();
|
|
29
|
+
if (lower === text)
|
|
30
|
+
return 0;
|
|
31
|
+
if (lower.startsWith(text))
|
|
32
|
+
return 1;
|
|
33
|
+
if (lower.split(/[\s·/-]+/).some((word) => word.startsWith(text)))
|
|
34
|
+
return 2;
|
|
35
|
+
return lower.includes(text) ? 3 : -1;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* The pages whose name (or module and name) has the text in it, the
|
|
39
|
+
* closest first, then the nav's order; at most `limit`. No text: the
|
|
40
|
+
* first `limit` pages.
|
|
41
|
+
*/
|
|
42
|
+
export function matchPages(pages, query, limit) {
|
|
43
|
+
const text = query.trim().toLowerCase();
|
|
44
|
+
if (!text)
|
|
45
|
+
return pages.slice(0, limit);
|
|
46
|
+
return pages
|
|
47
|
+
.map((page, index) => {
|
|
48
|
+
const own = closeness(page.name, text);
|
|
49
|
+
const full = closeness(page.label, text);
|
|
50
|
+
// The page's own name counts first; its module's name next.
|
|
51
|
+
const score = own >= 0 ? own : full >= 0 ? full + 4 : -1;
|
|
52
|
+
return { page, index, score };
|
|
53
|
+
})
|
|
54
|
+
.filter((match) => match.score >= 0)
|
|
55
|
+
.sort((a, b) => a.score - b.score || a.index - b.index)
|
|
56
|
+
.slice(0, limit)
|
|
57
|
+
.map((match) => match.page);
|
|
58
|
+
}
|
|
59
|
+
/** The records under their kinds, each kind once, in the order its first record came. */
|
|
60
|
+
export function groupRecords(records) {
|
|
61
|
+
const groups = new Map();
|
|
62
|
+
for (const record of records) {
|
|
63
|
+
const kind = record.kind?.trim() || 'Records';
|
|
64
|
+
const group = groups.get(kind);
|
|
65
|
+
if (group)
|
|
66
|
+
group.push(record);
|
|
67
|
+
else
|
|
68
|
+
groups.set(kind, [record]);
|
|
69
|
+
}
|
|
70
|
+
return [...groups].map(([kind, list]) => ({ kind, records: list }));
|
|
71
|
+
}
|
|
72
|
+
// ---- The records opened lately, on this device ----
|
|
73
|
+
export const RECENT_RECORDS_KEY = 'ui-foundation:recent-records';
|
|
74
|
+
/** How many are kept; the palette shows its `recent` of them. */
|
|
75
|
+
export const RECENT_RECORDS_KEPT = 20;
|
|
76
|
+
function storage() {
|
|
77
|
+
try {
|
|
78
|
+
return window.localStorage;
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
function isRecent(value) {
|
|
85
|
+
if (typeof value !== 'object' || value === null)
|
|
86
|
+
return false;
|
|
87
|
+
const { title, to, detail } = value;
|
|
88
|
+
return typeof title === 'string' && typeof to === 'string' && (detail === undefined || typeof detail === 'string');
|
|
89
|
+
}
|
|
90
|
+
/** The records opened lately, the latest first. Nothing when storage is missing or holds something else. */
|
|
91
|
+
export function readRecentRecords(store = storage()) {
|
|
92
|
+
try {
|
|
93
|
+
const parsed = JSON.parse(store?.getItem(RECENT_RECORDS_KEY) ?? '[]');
|
|
94
|
+
return Array.isArray(parsed) ? parsed.filter(isRecent) : [];
|
|
95
|
+
}
|
|
96
|
+
catch {
|
|
97
|
+
return [];
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
/** Puts a record first among the recent ones (once, by its `to`), keeping the latest RECENT_RECORDS_KEPT. */
|
|
101
|
+
export function rememberRecentRecord(record, store = storage()) {
|
|
102
|
+
const entry = { title: record.title, to: record.to, ...(record.detail ? { detail: record.detail } : {}) };
|
|
103
|
+
const next = [entry, ...readRecentRecords(store).filter((other) => other.to !== record.to)].slice(0, RECENT_RECORDS_KEPT);
|
|
104
|
+
try {
|
|
105
|
+
store?.setItem(RECENT_RECORDS_KEY, JSON.stringify(next));
|
|
106
|
+
}
|
|
107
|
+
catch {
|
|
108
|
+
// Not remembered: storage is full or refused (a private window).
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
/** Forgets every recent record (AppShell does on logout, so the next person doesn't see them). */
|
|
112
|
+
export function clearRecentRecords(store = storage()) {
|
|
113
|
+
try {
|
|
114
|
+
store?.removeItem(RECENT_RECORDS_KEY);
|
|
115
|
+
}
|
|
116
|
+
catch {
|
|
117
|
+
// Nothing to forget.
|
|
118
|
+
}
|
|
119
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tristan2828/ui-foundation",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.88.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": {
|