@tristan2828/ui-foundation 4.134.0 → 4.136.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,45 +3,46 @@
3
3
  <!-- index: written by `npm run docs:index` in the package from the headings below; never edit it by hand -->
4
4
  ## Index
5
5
 
6
- - [Palettes](#palettes) · lines 54–163
7
- - [Glow](#glow) · lines 165–184
8
- - [Semantic tones](#semantic-tones) · lines 186–214
9
- - [The three badge styles](#the-three-badge-styles) · lines 216–233
10
- - [Status marks](#status-marks) · lines 235–280
11
- - [Mapping an enum to tones](#mapping-an-enum-to-tones) · lines 282–311
12
- - [Glyphs and icons: 3:1](#glyphs-and-icons-31) · lines 313–326
13
- - [Logos and brand marks](#logos-and-brand-marks) · lines 328–372
14
- - [Categorical colour](#categorical-colour) · lines 374–444
15
- - [Heat scale](#heat-scale) · lines 446–507
16
- - [Depth ramps](#depth-ramps) · lines 509–594
17
- - [A stored colour](#a-stored-colour) · lines 596–653
18
- - [Shapes and sizes](#shapes-and-sizes) · lines 655–676
19
- - [Typography](#typography) · lines 678–849
20
- - [Words on screen: Title Case and sentence case](#words-on-screen-title-case-and-sentence-case) · lines 712–745
21
- - [Written text (notes)](#written-text-notes) · lines 747–849
22
- - [Density](#density) · lines 851–971
23
- - [Rows on this device](#rows-on-this-device) · lines 917–944
24
- - [Page width (a record on a wide screen)](#page-width-a-record-on-a-wide-screen) · lines 946–971
25
- - [Widget cards (hub pages)](#widget-cards-hub-pages) · lines 973–1087
26
- - [Module cards (a hub's places)](#module-cards-a-hubs-places) · lines 1089–1166
27
- - [Notices](#notices) · lines 1168–1196
28
- - [A value over time](#a-value-over-time) · lines 1198–1328
29
- - [Several values over time](#several-values-over-time) · lines 1247–1285
30
- - [Parts of a whole over time](#parts-of-a-whole-over-time) · lines 1287–1328
31
- - [A list as a board](#a-list-as-a-board) · lines 1330–1446
32
- - [Order, groups and the header (4.131)](#order-groups-and-the-header-4131) · lines 1383–1446
33
- - [A list as cards](#a-list-as-cards) · lines 1448–1494
34
- - [Images full screen](#images-full-screen) · lines 1496–1542
35
- - [Key numbers on a record](#key-numbers-on-a-record) · lines 1544–1580
36
- - [Parts of the page standards](#parts-of-the-page-standards) · lines 1582–1652
37
- - [A few equal things](#a-few-equal-things) · lines 1654–1774
38
- - [An overview page](#an-overview-page) · lines 1776–1847
39
- - [A record's header and empty values](#a-records-header-and-empty-values) · lines 1848–1914
40
- - [A record's tabs, mark and facts](#a-records-tabs-mark-and-facts) · lines 1916–2053
41
- - [Picking at random](#picking-at-random) · lines 2055–2086
42
- - [Filling in what's missing](#filling-in-whats-missing) · lines 2088–2155
43
- - [Values edited in place: the presets' looks](#values-edited-in-place-the-presets-looks) · lines 2157–2182
44
- - [The sidebar and the phone's bar](#the-sidebar-and-the-phones-bar) · lines 2184–2280
6
+ - [Palettes](#palettes) · lines 55–164
7
+ - [Glow](#glow) · lines 166–185
8
+ - [Semantic tones](#semantic-tones) · lines 187–215
9
+ - [The three badge styles](#the-three-badge-styles) · lines 217–234
10
+ - [Status marks](#status-marks) · lines 236–281
11
+ - [Mapping an enum to tones](#mapping-an-enum-to-tones) · lines 283–312
12
+ - [Glyphs and icons: 3:1](#glyphs-and-icons-31) · lines 314–327
13
+ - [Logos and brand marks](#logos-and-brand-marks) · lines 329–373
14
+ - [Categorical colour](#categorical-colour) · lines 375–445
15
+ - [Heat scale](#heat-scale) · lines 447–508
16
+ - [Depth ramps](#depth-ramps) · lines 510–595
17
+ - [A stored colour](#a-stored-colour) · lines 597–654
18
+ - [Shapes and sizes](#shapes-and-sizes) · lines 656–677
19
+ - [Typography](#typography) · lines 679–850
20
+ - [Words on screen: Title Case and sentence case](#words-on-screen-title-case-and-sentence-case) · lines 713–746
21
+ - [Written text (notes)](#written-text-notes) · lines 748–850
22
+ - [Density](#density) · lines 852–972
23
+ - [Rows on this device](#rows-on-this-device) · lines 918–945
24
+ - [Page width (a record on a wide screen)](#page-width-a-record-on-a-wide-screen) · lines 947–972
25
+ - [Widget cards (hub pages)](#widget-cards-hub-pages) · lines 974–1088
26
+ - [Module cards (a hub's places)](#module-cards-a-hubs-places) · lines 1090–1167
27
+ - [Notices](#notices) · lines 1169–1197
28
+ - [A value over time](#a-value-over-time) · lines 1199–1329
29
+ - [Several values over time](#several-values-over-time) · lines 1248–1286
30
+ - [Parts of a whole over time](#parts-of-a-whole-over-time) · lines 1288–1329
31
+ - [A list as a board](#a-list-as-a-board) · lines 1331–1447
32
+ - [Order, groups and the header (4.131)](#order-groups-and-the-header-4131) · lines 1384–1447
33
+ - [A list as cards](#a-list-as-cards) · lines 1449–1495
34
+ - [Images full screen](#images-full-screen) · lines 1497–1543
35
+ - [Key numbers on a record](#key-numbers-on-a-record) · lines 1545–1581
36
+ - [Parts of the page standards](#parts-of-the-page-standards) · lines 1583–1653
37
+ - [A few equal things](#a-few-equal-things) · lines 1655–1775
38
+ - [An overview page](#an-overview-page) · lines 1777–1848
39
+ - [A record's header and empty values](#a-records-header-and-empty-values) · lines 1849–1915
40
+ - [A record's tabs, mark and facts](#a-records-tabs-mark-and-facts) · lines 1917–2054
41
+ - [Picking at random](#picking-at-random) · lines 2056–2087
42
+ - [Filling in what's missing](#filling-in-whats-missing) · lines 2089–2156
43
+ - [Values edited in place: the presets' looks](#values-edited-in-place-the-presets-looks) · lines 2158–2183
44
+ - [A quick add line](#a-quick-add-line) · lines 2185–2213
45
+ - [The sidebar and the phone's bar](#the-sidebar-and-the-phones-bar) · lines 2215–2311
45
46
 
46
47
  <!-- /index -->
47
48
 
@@ -2181,6 +2182,36 @@ both themes and every palette.
2181
2182
  `type-label text-muted-foreground` (an `<h3>` under the section's
2182
2183
  title), with `gap-4` between groups and the list's own `gap-2` inside.
2183
2184
 
2185
+ ## A quick add line
2186
+
2187
+ One line that becomes a record ("pay rent tomorrow at 3pm #home"): the
2188
+ package's `QuickAddInput` over `parseQuickAdd` (4.136). Dates, times and
2189
+ repeats are typed in words; the app's own choices (a list, a place) are a
2190
+ symbol and a few letters, or a chip pressed.
2191
+
2192
+ - **What was read is marked in the box** as you type (a wash of `info`
2193
+ under the words), and shown under it as chips: Due (the day and time),
2194
+ Repeats, and one per token typed. A misread is seen where it was typed.
2195
+ - **✕ on a read chip gives its words back to the title**, for a word that
2196
+ only looked like a day ("the sun article"). They stay given back while
2197
+ they're in the line.
2198
+ - **The app's chips come after the read ones** (`chips`, usually
2199
+ `QuickAddChip`): dashed while they show a default ("List Home ▾", "+
2200
+ Place"), solid once pressed. The app drops its chip for a kind the line
2201
+ typed (`result.tokens`).
2202
+ - **No menu opens on a symbol.** A symbol that names nothing stays in the
2203
+ title; a few letters pick the first name that starts with them, then the
2204
+ first that holds them.
2205
+ - **Enter adds** (`onSubmit` with the reading). A line with nothing read
2206
+ is a title. Give the box a visible label and, the first times, a `hint`
2207
+ saying what can be typed.
2208
+
2209
+ What `parseQuickAdd` reads, and how a day with no year, a time with no
2210
+ day and a repeat with no day come out, is in its source's header
2211
+ (`src/lib/quick-add.ts`); `options.today` and `timeZone` come from the app's
2212
+ own day (`todayIn`). A repeat is a `Recurrence`, read by
2213
+ `parseRecurrencePhrase` (`every!` repeats from completion).
2214
+
2184
2215
  ## The sidebar and the phone's bar
2185
2216
 
2186
2217
  `AppShell`'s navigation (4.80), all set in the app's `nav` and
@@ -54,6 +54,24 @@ there is no push at all, so `usePushPermission` says `needs-install` and
54
54
  `AllowReminders` shows the steps. `pwa()`'s manifest (`display:
55
55
  standalone`) is what makes the Home Screen app an app.
56
56
 
57
+ ## Home-screen shortcuts
58
+
59
+ `pwa({ name, shortcuts: [{ name: 'Add To-Do', url: '/todo/add' }] })` writes
60
+ the manifest's `shortcuts`: actions on the installed icon that open the
61
+ app at a path. `url` is a path inside the app (it gets the Vite `base`);
62
+ `shortName` and a square `icon` PNG (192×192 or more) are optional. Left
63
+ out, the manifest is unchanged.
64
+
65
+ | Platform | What it does with them |
66
+ |---|---|
67
+ | Android (Chrome, installed app) | Long-press the icon: the shortcuts list above it, and can be dragged to the Home Screen. Most launchers show about four |
68
+ | Desktop Chrome and Edge | Right-click the installed app's icon (taskbar, dock or Start menu) |
69
+ | iPhone and iPad | Ignored: the Home Screen app's long-press menu has none from the manifest. Safari supports `shortcuts` only on macOS (since 17.4), per [firt.dev's iOS PWA compatibility notes](https://firt.dev/notes/pwa-ios/), updated October 2026. Give the action somewhere in the app too |
70
+
71
+ Treat a shortcut as a convenience, never the only way to an action. A
72
+ phone caches the manifest, so a changed list can take a reinstall or a day
73
+ to show.
74
+
57
75
  ## A reminder is the app's own row
58
76
 
59
77
  The reference backend has a `reminders` table and the job that sends it;
@@ -0,0 +1,50 @@
1
+ import { type ReactNode } from 'react';
2
+ import { type QuickAddOptions, type QuickAddResult } from '../../lib/quick-add.js';
3
+ export type QuickAddInputProps = {
4
+ /** The box's visible label ("Add To-Do"). */
5
+ label: ReactNode;
6
+ /** What it reads with: today, the zone and the app's tokens (parseQuickAdd's options, less `ignore`). */
7
+ options: Omit<QuickAddOptions, 'ignore'>;
8
+ /** The line, when the app holds it. Leave out to let the box hold it. */
9
+ value?: string;
10
+ onValueChange?: (value: string) => void;
11
+ /**
12
+ * Enter: the line as read. A box that holds its own line empties after
13
+ * it; one the app holds is emptied by the app.
14
+ */
15
+ onSubmit?: (result: QuickAddResult, text: string) => void;
16
+ /** Every new reading, for an Add button or the app's chips elsewhere. */
17
+ onResultChange?: (result: QuickAddResult) => void;
18
+ /** The app's own chips after the read ones, given the reading (usually QuickAddChip). */
19
+ chips?: (result: QuickAddResult) => ReactNode;
20
+ /** A line under the chips: what can be typed. */
21
+ hint?: ReactNode;
22
+ placeholder?: string;
23
+ /** The read chips' labels. Defaults: Due, Repeats. */
24
+ labels?: {
25
+ date?: string;
26
+ recurrence?: string;
27
+ };
28
+ autoFocus?: boolean;
29
+ disabled?: boolean;
30
+ id?: string;
31
+ className?: string;
32
+ };
33
+ export declare function QuickAddInput({ label, options, value, onValueChange, onSubmit, onResultChange, chips, hint, placeholder, labels, autoFocus, disabled, id, className, }: QuickAddInputProps): import("react").JSX.Element;
34
+ export type QuickAddChipProps = {
35
+ /** What it sets ("List"). */
36
+ label: string;
37
+ /** What it's set to now ("Personal"), or nothing for "+ List". */
38
+ value?: ReactNode;
39
+ onClick?: () => void;
40
+ /** Set by a press rather than typed: drawn solid. */
41
+ set?: boolean;
42
+ disabled?: boolean;
43
+ className?: string;
44
+ };
45
+ /**
46
+ * The app's own chip in QuickAddInput's row: pressed to set what wasn't
47
+ * typed (a list, a place). Dashed while it shows a default, solid once
48
+ * pressed. Put it in an `<li>`; `chips` returns them.
49
+ */
50
+ export declare function QuickAddChip({ label, value, onClick, set, disabled, className }: QuickAddChipProps): import("react").JSX.Element;
@@ -0,0 +1,138 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ // A quick add's one line (F1, look I4): what parseQuickAdd reads is
3
+ // marked in the box as you type and shown under it as chips, so a misread
4
+ // is seen at once. ✕ on a read chip gives its words back to the title
5
+ // (the "sun" that wasn't Sunday). The app passes its own chips, the ones
6
+ // pressed to set what wasn't typed (a list, a place), after the read ones,
7
+ // usually QuickAddChip. No menu opens on a symbol: `#ch` is read as you
8
+ // type it, and a symbol that names nothing stays in the title.
9
+ //
10
+ // The marks are a copy of the line behind the input, its text transparent
11
+ // and each read wrapped in a <mark>, kept on the input's own padding,
12
+ // font and scroll, so the highlight sits under the typed words. The input
13
+ // stays a plain text box for the keyboard, the screen reader and the
14
+ // phone's own keyboard; the chips are what a screen reader hears.
15
+ import { useCallback, useId, useLayoutEffect, useMemo, useRef, useState } from 'react';
16
+ import { ChevronDownIcon, XIcon } from 'lucide-react';
17
+ import { cn } from 'cn';
18
+ import { Input } from '../ui/input.js';
19
+ import { formatPlainDate } from '../../lib/plain-date.js';
20
+ import { parseQuickAdd } from '../../lib/quick-add.js';
21
+ import { formatRecurrence } from '../../lib/recurrence-format.js';
22
+ const DAY = { weekday: 'short', month: 'short', day: 'numeric' };
23
+ function clock(time, locale) {
24
+ const [hour, minute] = time.split(':').map(Number);
25
+ return new Intl.DateTimeFormat(locale, { hour: 'numeric', minute: '2-digit', timeZone: 'UTC' }).format(Date.UTC(2001, 0, 1, hour, minute));
26
+ }
27
+ /** Every place each ignored phrase now sits in the line. */
28
+ function ignoredSpans(text, phrases) {
29
+ const spans = [];
30
+ for (const phrase of phrases) {
31
+ for (let at = text.indexOf(phrase); at !== -1; at = text.indexOf(phrase, at + phrase.length)) {
32
+ spans.push({ start: at, end: at + phrase.length });
33
+ }
34
+ }
35
+ return spans;
36
+ }
37
+ export function QuickAddInput({ label, options, value, onValueChange, onSubmit, onResultChange, chips, hint, placeholder, labels, autoFocus, disabled, id, className, }) {
38
+ const ownId = useId();
39
+ const inputId = id ?? `${ownId}-input`;
40
+ const hintId = `${ownId}-hint`;
41
+ const [ownText, setOwnText] = useState('');
42
+ const text = value ?? ownText;
43
+ const [ignored, setIgnored] = useState([]);
44
+ const inputRef = useRef(null);
45
+ const marksRef = useRef(null);
46
+ // A phrase given back stays given back while its words are in the line.
47
+ const live = useMemo(() => ignored.filter((phrase) => text.includes(phrase)), [ignored, text]);
48
+ // Read again only when what it reads with changes, not each time an app
49
+ // passes a new options object with the same contents.
50
+ const optionsKey = JSON.stringify(options);
51
+ const result = useMemo(() => parseQuickAdd(text, { ...JSON.parse(optionsKey), ignore: ignoredSpans(text, live) }), [text, live, optionsKey]);
52
+ const lastResult = useRef(null);
53
+ useLayoutEffect(() => {
54
+ if (lastResult.current === result)
55
+ return;
56
+ lastResult.current = result;
57
+ onResultChange?.(result);
58
+ }, [result, onResultChange]);
59
+ const setText = useCallback((next) => {
60
+ if (value === undefined)
61
+ setOwnText(next);
62
+ onValueChange?.(next);
63
+ if (next === '')
64
+ setIgnored([]);
65
+ }, [value, onValueChange]);
66
+ // The marks follow the input's own scroll as the caret moves along a long line.
67
+ const follow = useCallback(() => {
68
+ const input = inputRef.current;
69
+ const marks = marksRef.current;
70
+ if (input && marks)
71
+ marks.style.transform = `translateX(${-input.scrollLeft}px)`;
72
+ }, []);
73
+ useLayoutEffect(follow, [text, result, follow]);
74
+ const readChips = [];
75
+ const locale = options.locale;
76
+ if (result.date || result.time) {
77
+ const day = result.date ? formatPlainDate(result.date.value, DAY, locale) : '';
78
+ const at = result.time ? clock(result.time.value, locale) : '';
79
+ const giveBack = [];
80
+ if (result.date?.span)
81
+ giveBack.push(text.slice(result.date.span.start, result.date.span.end));
82
+ if (result.time && result.time.span !== result.recurrence?.span) {
83
+ giveBack.push(text.slice(result.time.span.start, result.time.span.end));
84
+ }
85
+ readChips.push({ id: 'date', label: labels?.date ?? 'Due', value: [day, at].filter(Boolean).join(', '), giveBack });
86
+ }
87
+ if (result.recurrence) {
88
+ const span = result.recurrence.span;
89
+ readChips.push({
90
+ id: 'recurrence',
91
+ label: labels?.recurrence ?? 'Repeats',
92
+ value: formatRecurrence(result.recurrence.value, { locale, times: false, weekStart: options.weekStart }),
93
+ giveBack: [text.slice(span.start, span.end)],
94
+ });
95
+ }
96
+ for (const token of result.tokens) {
97
+ readChips.push({ id: `token-${token.key}`, label: token.label, value: token.name, giveBack: [token.text] });
98
+ }
99
+ function giveBack(chip) {
100
+ setIgnored((current) => [...current.filter((phrase) => text.includes(phrase)), ...chip.giveBack]);
101
+ inputRef.current?.focus();
102
+ }
103
+ function onKeyDown(event) {
104
+ if (event.key !== 'Enter' || event.nativeEvent.isComposing)
105
+ return;
106
+ event.preventDefault();
107
+ if (!result.title && !text.trim())
108
+ return;
109
+ onSubmit?.(result, text);
110
+ if (value === undefined) {
111
+ setOwnText('');
112
+ setIgnored([]);
113
+ }
114
+ }
115
+ // The line with each read in a <mark>, in the line's order.
116
+ const marked = [];
117
+ let at = 0;
118
+ for (const read of result.reads) {
119
+ if (read.start < at)
120
+ continue;
121
+ marked.push(text.slice(at, read.start));
122
+ marked.push(_jsx("mark", { "data-kind": read.kind, className: "rounded-sm bg-info/20 text-transparent ring-1 ring-info-text/40 dark:bg-info/30", children: text.slice(read.start, read.end) }, read.start));
123
+ at = read.end;
124
+ }
125
+ marked.push(text.slice(at));
126
+ const appChips = chips?.(result);
127
+ const hasChips = readChips.length > 0 || !!appChips;
128
+ return (_jsxs("div", { "data-slot": "quick-add-input", className: cn('flex flex-col gap-2', className), children: [_jsx("label", { htmlFor: inputId, className: "text-sm leading-none font-medium text-foreground", children: label }), _jsxs("div", { className: "relative", children: [_jsx("div", { "aria-hidden": "true", "data-slot": "quick-add-marks", className: "pointer-events-none absolute inset-0 flex items-center overflow-hidden rounded-md border border-transparent px-2.5 py-1 text-base whitespace-pre md:text-sm", children: _jsx("span", { ref: marksRef, className: "text-transparent", children: marked }) }), _jsx(Input, { ref: inputRef, id: inputId, type: "text", value: text, placeholder: placeholder, autoFocus: autoFocus, disabled: disabled, autoComplete: "off", spellCheck: false, enterKeyHint: "done", "aria-describedby": hint ? hintId : undefined, onChange: (event) => setText(event.target.value), onKeyDown: onKeyDown, onScroll: follow, onSelect: follow, className: "relative" })] }), hasChips && (_jsxs("ul", { "aria-label": "Read from the line", className: "flex flex-wrap items-center gap-1.5", children: [readChips.map((chip) => (_jsxs("li", { "data-slot": "quick-add-read", "data-read": chip.id, className: "inline-flex h-7 items-center gap-1.5 rounded-full bg-info/10 pr-1 pl-2.5 text-sm text-foreground dark:bg-info/20", children: [_jsx("span", { className: "text-xs text-foreground/80", children: chip.label }), _jsx("span", { children: chip.value }), chip.giveBack.length > 0 ? (_jsx("button", { type: "button", disabled: disabled, onClick: () => giveBack(chip), "aria-label": `Not a ${chip.label.toLowerCase()}: put “${chip.giveBack.join(' ')}” back in the title`, title: "Put the words back in the title", className: "inline-flex size-6 items-center justify-center rounded-full text-muted-foreground outline-none hover:bg-foreground/10 hover:text-foreground focus-visible:ring-3 focus-visible:ring-ring/50", children: _jsx(XIcon, { "aria-hidden": "true", className: "size-3.5" }) })) : (_jsx("span", { className: "w-1.5" }))] }, chip.id))), appChips] })), hint && (_jsx("p", { id: hintId, className: "text-xs text-muted-foreground", children: hint }))] }));
129
+ }
130
+ /**
131
+ * The app's own chip in QuickAddInput's row: pressed to set what wasn't
132
+ * typed (a list, a place). Dashed while it shows a default, solid once
133
+ * pressed. Put it in an `<li>`; `chips` returns them.
134
+ */
135
+ export function QuickAddChip({ label, value, onClick, set, disabled, className }) {
136
+ const empty = value === undefined || value === null || value === '';
137
+ return (_jsx("li", { className: "inline-flex", children: _jsx("button", { type: "button", "data-slot": "quick-add-chip", onClick: onClick, disabled: disabled, className: cn('inline-flex h-7 items-center gap-1.5 rounded-full border px-2.5 text-sm text-foreground outline-none hover:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 disabled:opacity-50', set ? 'border-transparent bg-primary/12 dark:bg-primary/20' : 'border-dashed border-border', className), children: empty ? (_jsxs("span", { className: "text-muted-foreground", children: ["+ ", label] })) : (_jsxs(_Fragment, { children: [_jsx("span", { className: "text-xs text-muted-foreground", children: label }), _jsx("span", { children: value }), _jsx(ChevronDownIcon, { "aria-hidden": "true", className: "size-3.5 text-muted-foreground" })] })) }) }));
138
+ }
package/dist/index.d.ts CHANGED
@@ -112,6 +112,8 @@ export { formatMonthDay, isMonthDay, monthDayProblem, type MonthDay } from './li
112
112
  export { RecurrenceField, type RecurrenceFieldProps } from './components/app/recurrence-field.js';
113
113
  export { atLocal, formatRule, nextAfterCompletion, nextOccurrence, nextOccurrences, normalizeRecurrence, parseRule, RecurrenceError, recurrenceFromWeekdays, recurrenceProblem, weekStartMatters, type Recurrence, type RuleParts, type WeekdayCode, } from './lib/recurrence.js';
114
114
  export { parseRecurrencePhrase, recurrencePhrase, type PhraseOptions, type PhraseResult, type RecurrencePhraseOptions, } from './lib/recurrence-phrase.js';
115
+ export { parseQuickAdd, type QuickAddOptions, type QuickAddRead, type QuickAddReadKind, type QuickAddResult, type QuickAddSpan, type QuickAddToken, type QuickAddTokenRead, } from './lib/quick-add.js';
116
+ export { QuickAddChip, QuickAddInput, type QuickAddChipProps, type QuickAddInputProps, } from './components/app/quick-add-input.js';
115
117
  export { formatOccurrence, formatRecurrence, todayIn, type OccurrenceFormatOptions, type RecurrenceFormatOptions, } from './lib/recurrence-format.js';
116
118
  export { ChoiceCell, LinkCell, LinkOut, NameCell, type ChoiceCellProps, type LinkCellProps, type NameCellProps, } from './components/app/row-edit-cells.js';
117
119
  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
@@ -122,6 +122,8 @@ export { formatMonthDay, isMonthDay, monthDayProblem } from './lib/month-day.js'
122
122
  export { RecurrenceField } from './components/app/recurrence-field.js';
123
123
  export { atLocal, formatRule, nextAfterCompletion, nextOccurrence, nextOccurrences, normalizeRecurrence, parseRule, RecurrenceError, recurrenceFromWeekdays, recurrenceProblem, weekStartMatters, } from './lib/recurrence.js';
124
124
  export { parseRecurrencePhrase, recurrencePhrase, } from './lib/recurrence-phrase.js';
125
+ export { parseQuickAdd, } from './lib/quick-add.js';
126
+ export { QuickAddChip, QuickAddInput, } from './components/app/quick-add-input.js';
125
127
  export { formatOccurrence, formatRecurrence, todayIn, } from './lib/recurrence-format.js';
126
128
  export { ChoiceCell, LinkCell, LinkOut, NameCell, } from './components/app/row-edit-cells.js';
127
129
  export { ModuleCard, ModuleStrip, } from './components/app/module-card.js';
@@ -0,0 +1,82 @@
1
+ import { type PlainDate } from './plain-date.js';
2
+ import { type Recurrence, type WeekdayCode } from './recurrence.js';
3
+ /** One kind of the app's own token: a symbol and the names it picks from. */
4
+ export type QuickAddToken = {
5
+ /** What it sets, as the app names it (`'list'`, `'place'`). */
6
+ key: string;
7
+ /** The character typed before it (`'#'`, `'@'`, `'/'`). */
8
+ symbol: string;
9
+ /** The chip's label (`'List'`). Defaults to the key. */
10
+ label?: string;
11
+ /** The names to pick from, best first: a few letters pick the first that fits. */
12
+ names: string[];
13
+ };
14
+ /** Where in the line a part was read: `text.slice(start, end)`. */
15
+ export type QuickAddSpan = {
16
+ start: number;
17
+ end: number;
18
+ };
19
+ export type QuickAddOptions = {
20
+ /** Today, `'YYYY-MM-DD'` in the app's zone (todayIn): where days count from. */
21
+ today: PlainDate;
22
+ /** The IANA zone a repeat is read in. */
23
+ timeZone: string;
24
+ /** The app's tokens. None: symbols stay in the title. */
25
+ tokens?: QuickAddToken[];
26
+ /** Spans never read (a chip's ✕): their words stay in the title. */
27
+ ignore?: QuickAddSpan[];
28
+ /** A repeat's times when neither it nor the line says one. Defaults to 09:00. */
29
+ times?: string[];
30
+ /** The day weeks start on, for a repeat (PhraseOptions' weekStart). */
31
+ weekStart?: WeekdayCode;
32
+ /** Decides `3/4`'s order: month first in en-US, day first in en-GB. */
33
+ locale?: string;
34
+ };
35
+ export type QuickAddReadKind = 'date' | 'time' | 'recurrence' | 'token';
36
+ /** One part read from the line, for marking it: its kind, span and words. */
37
+ export type QuickAddRead = QuickAddSpan & {
38
+ kind: QuickAddReadKind;
39
+ /** The words read, as typed. */
40
+ text: string;
41
+ /** A token's key. */
42
+ key?: string;
43
+ };
44
+ export type QuickAddTokenRead = {
45
+ key: string;
46
+ symbol: string;
47
+ label: string;
48
+ name: string;
49
+ span: QuickAddSpan;
50
+ text: string;
51
+ };
52
+ export type QuickAddResult = {
53
+ /** The line with what was read taken out, spaces tidied. */
54
+ title: string;
55
+ /**
56
+ * The day it's due. `span` is null when no day was typed and it comes
57
+ * from the time (today) or the repeat (its first day).
58
+ */
59
+ date: {
60
+ value: PlainDate;
61
+ span: QuickAddSpan | null;
62
+ } | null;
63
+ /** `'HH:MM'`, typed on its own or as the repeat's first "at". */
64
+ time: {
65
+ value: string;
66
+ span: QuickAddSpan;
67
+ } | null;
68
+ recurrence: {
69
+ value: Recurrence;
70
+ span: QuickAddSpan;
71
+ } | null;
72
+ /** One per token kind typed, in the line's order. */
73
+ tokens: QuickAddTokenRead[];
74
+ /** Every span read, in the line's order. */
75
+ reads: QuickAddRead[];
76
+ };
77
+ /**
78
+ * Reads a quick-add line into its title, day, time, repeat and tokens.
79
+ * Live as you type: call it on every change; a part it can't read is
80
+ * left in the title, never refused.
81
+ */
82
+ export declare function parseQuickAdd(text: string, options: QuickAddOptions): QuickAddResult;
@@ -0,0 +1,276 @@
1
+ // One line typed into a quick add ("pay rent tomorrow at 3pm #home",
2
+ // "water plants every! 3 days @out") read into its parts as you type: the
3
+ // title left over, a day, a time, a repeat and the app's own tokens, each
4
+ // with the span of the line it came from, so a box can mark what it read
5
+ // and give a misread back to the title.
6
+ //
7
+ // What it reads, anywhere in the line:
8
+ //
9
+ // - the app's tokens: a symbol and a few letters of a name (`#ch` for
10
+ // Chores, `@up` for "Up and Moving"); the name's start first, then
11
+ // anywhere in it, in the order the app gave the names
12
+ // - a repeat: `every …` / `every! …` (from completion) and `daily`,
13
+ // `weekly`, `monthly`, `yearly`, `weekdays`, read by
14
+ // parseRecurrencePhrase, as long a phrase as it takes ("every mon at
15
+ // 9am until mar 1")
16
+ // - a time: `3pm`, `3:30 pm`, `at 15:00`, `at noon`
17
+ // - a day: `today`, `tomorrow`, a weekday (`fri`, `friday`: the next one
18
+ // after today), `next friday` (the same day), `in 3 days`, `in 2
19
+ // weeks`, `Mar 14`, `14 Mar`, `3/14` (`14/3` where the locale writes the
20
+ // day first), each with an optional `on` before it. A day with no year
21
+ // is the next one on or after today.
22
+ //
23
+ // A time with no day is today. A repeat with no day is first due on the
24
+ // first day it falls (on or after today); a day typed beside a repeat is
25
+ // where it starts. A repeat with no "at" takes the line's time, else
26
+ // `options.times`. Each part is read once: a second date stays in the
27
+ // title. A span the caller marks as ignored (QuickAddInput's ✕) is never
28
+ // read, so its words stay in the title.
29
+ import { dayFirst, localToPlainDate } from './plain-date.js';
30
+ import { atLocal, nextOccurrence, wallClock } from './recurrence.js';
31
+ import { parseRecurrencePhrase } from './recurrence-phrase.js';
32
+ const WEEKDAYS = [
33
+ [/^mon(day)?$/, 1],
34
+ [/^tue(s|sday)?$/, 2],
35
+ [/^wed(s|nesday)?$/, 3],
36
+ [/^thu(r|rs|rsday)?$/, 4],
37
+ [/^fri(day)?$/, 5],
38
+ [/^sat(urday)?$/, 6],
39
+ [/^sun(day)?$/, 0],
40
+ ];
41
+ const WEEKDAY = String.raw `(?:mon(?:day)?|tue(?:s|sday)?|wed(?:s|nesday)?|thu(?:r|rs|rsday)?|fri(?:day)?|sat(?:urday)?|sun(?:day)?)`;
42
+ const MONTH = String.raw `(?:jan(?:uary)?|feb(?:ruary)?|mar(?:ch)?|apr(?:il)?|may|june?|july?|aug(?:ust)?|sep(?:t|tember)?|oct(?:ober)?|nov(?:ember)?|dec(?:ember)?)`;
43
+ const MONTHS = ['jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec'];
44
+ // A word's edges: no letter or digit on either side.
45
+ const START = String.raw `(?<![\p{L}\p{N}])`;
46
+ const END = String.raw `(?![\p{L}\p{N}])`;
47
+ const REPEAT_START = new RegExp(String.raw `${START}(?:every!?|daily|weekly|monthly|yearly|annually|weekdays)${END}`, 'giu');
48
+ // How many words a repeat may run to, past its first.
49
+ const REPEAT_WORDS = 14;
50
+ const pad = (value) => String(value).padStart(2, '0');
51
+ function addDays(day, count) {
52
+ const [year, month, date] = day.split('-').map(Number);
53
+ return localToPlainDate(new Date(year, month - 1, date + count));
54
+ }
55
+ function weekdayOf(day) {
56
+ const [year, month, date] = day.split('-').map(Number);
57
+ return new Date(Date.UTC(year, month - 1, date)).getUTCDay();
58
+ }
59
+ function realDay(year, month, day) {
60
+ const check = new Date(Date.UTC(year, month - 1, day));
61
+ if (check.getUTCMonth() !== month - 1 || check.getUTCDate() !== day)
62
+ return null;
63
+ return `${year}-${pad(month)}-${pad(day)}`;
64
+ }
65
+ /** A month and day with no year: the next one on or after today (Feb 29: the next leap year's). */
66
+ function nextMonthDay(month, day, today) {
67
+ if (month < 1 || month > 12 || day < 1 || day > 31)
68
+ return null;
69
+ const from = Number(today.slice(0, 4));
70
+ for (let year = from; year < from + 8; year++) {
71
+ const value = realDay(year, month, day);
72
+ if (value && value >= today)
73
+ return value;
74
+ }
75
+ return null;
76
+ }
77
+ const overlaps = (a, b) => a.start < b.end && b.start < a.end;
78
+ /** The flattened name (no spaces, dashes or underscores, lower case) a token's letters are matched on. */
79
+ const flat = (value) => value.toLowerCase().replace(/[\s_-]+/g, '');
80
+ function pickName(names, letters) {
81
+ const typed = flat(letters);
82
+ if (!typed)
83
+ return null;
84
+ return names.find((name) => flat(name).startsWith(typed)) ?? names.find((name) => flat(name).includes(typed)) ?? null;
85
+ }
86
+ /**
87
+ * Reads a quick-add line into its title, day, time, repeat and tokens.
88
+ * Live as you type: call it on every change; a part it can't read is
89
+ * left in the title, never refused.
90
+ */
91
+ export function parseQuickAdd(text, options) {
92
+ const taken = [...(options.ignore ?? [])];
93
+ const reads = [];
94
+ const free = (span) => !taken.some((other) => overlaps(other, span));
95
+ const take = (span, kind, key) => {
96
+ taken.push(span);
97
+ reads.push({ ...span, kind, text: text.slice(span.start, span.end), ...(key ? { key } : {}) });
98
+ };
99
+ // The first match of a pattern clear of everything taken, with `read`
100
+ // saying whether it means something (a 3/45 isn't a day).
101
+ function first(pattern, read) {
102
+ const expression = new RegExp(pattern.source, pattern.flags.includes('g') ? pattern.flags : `${pattern.flags}g`);
103
+ for (let match = expression.exec(text); match; match = expression.exec(text)) {
104
+ if (match[0] === '') {
105
+ expression.lastIndex++;
106
+ continue;
107
+ }
108
+ const span = { start: match.index, end: match.index + match[0].length };
109
+ if (!free(span))
110
+ continue;
111
+ const value = read(match);
112
+ if (value !== null)
113
+ return { value, span };
114
+ }
115
+ return null;
116
+ }
117
+ // 1. The app's tokens: one per kind, the first that names something.
118
+ const tokens = [];
119
+ for (const token of options.tokens ?? []) {
120
+ const symbol = token.symbol.replace(/[.*+?^${}()|[\]\\/]/g, '\\$&');
121
+ const found = first(new RegExp(String.raw `(?<![^\s(])${symbol}([\p{L}\p{N}_-]+)`, 'giu'), (match) => pickName(token.names, match[1]));
122
+ if (!found)
123
+ continue;
124
+ take(found.span, 'token', token.key);
125
+ tokens.push({
126
+ key: token.key,
127
+ symbol: token.symbol,
128
+ label: token.label ?? token.key,
129
+ name: found.value,
130
+ span: found.span,
131
+ text: text.slice(found.span.start, found.span.end),
132
+ });
133
+ }
134
+ tokens.sort((a, b) => a.span.start - b.span.start);
135
+ // 2. The time and day on their own, read before the repeat is fixed so
136
+ // the repeat can take them, but after it in the line's claim: a time
137
+ // inside "every mon at 9am" belongs to the repeat.
138
+ const repeatAt = findRepeat();
139
+ const outside = (span) => !repeatAt || !overlaps(span, repeatAt.span);
140
+ const ownTime = first(new RegExp(String.raw `${START}(?:at\s+(noon|midnight)|(?:at\s+)?(\d{1,2})(?::(\d{2}))?\s*(am|pm|a\.m\.|p\.m\.)|(?:at\s+)?(\d{1,2}):(\d{2}))(?![\p{L}\p{N}])`, 'giu'), (match) => {
141
+ if (!outside({ start: match.index, end: match.index + match[0].length }))
142
+ return null;
143
+ if (match[1])
144
+ return match[1].toLowerCase() === 'noon' ? '12:00' : '00:00';
145
+ if (match[4]) {
146
+ const hour = Number(match[2]);
147
+ const minute = match[3] ? Number(match[3]) : 0;
148
+ if (hour < 1 || hour > 12 || minute > 59)
149
+ return null;
150
+ return `${pad((hour % 12) + (match[4].toLowerCase().startsWith('p') ? 12 : 0))}:${pad(minute)}`;
151
+ }
152
+ const hour = Number(match[5]);
153
+ const minute = Number(match[6]);
154
+ return hour > 23 || minute > 59 ? null : `${pad(hour)}:${pad(minute)}`;
155
+ });
156
+ if (ownTime)
157
+ take(ownTime.span, 'time');
158
+ const date = readDate();
159
+ if (date)
160
+ take(date.span, 'date');
161
+ // 3. The repeat, with the day as its start and the line's time.
162
+ let recurrence = null;
163
+ let repeatTime = null;
164
+ if (repeatAt && free(repeatAt.span)) {
165
+ const parsed = parseRecurrencePhrase(repeatAt.phrase, {
166
+ today: options.today,
167
+ timeZone: options.timeZone,
168
+ times: ownTime ? [ownTime.value] : options.times,
169
+ start: date?.value,
170
+ weekStart: options.weekStart,
171
+ });
172
+ if (parsed.ok) {
173
+ recurrence = { value: parsed.value, span: repeatAt.span };
174
+ take(repeatAt.span, 'recurrence');
175
+ if (!ownTime && /(?<![\p{L}\p{N}])at(?![\p{L}\p{N}])/u.test(repeatAt.phrase)) {
176
+ repeatTime = { value: parsed.value.times[0], span: repeatAt.span };
177
+ }
178
+ }
179
+ }
180
+ reads.sort((a, b) => a.start - b.start);
181
+ let title = '';
182
+ let at = 0;
183
+ for (const read of reads) {
184
+ title += `${text.slice(at, read.start)} `;
185
+ at = read.end;
186
+ }
187
+ title = (title + text.slice(at)).replace(/\s+/g, ' ').trim();
188
+ const finalTime = ownTime ?? repeatTime;
189
+ let due = date ? { value: date.value, span: date.span } : null;
190
+ if (!due && recurrence)
191
+ due = { value: firstDay(recurrence.value), span: null };
192
+ if (!due && finalTime)
193
+ due = { value: options.today, span: null };
194
+ return { title, date: due, time: finalTime, recurrence, tokens, reads };
195
+ /** The longest repeat phrase from its first word that parseRecurrencePhrase reads. */
196
+ function findRepeat() {
197
+ REPEAT_START.lastIndex = 0;
198
+ for (let match = REPEAT_START.exec(text); match; match = REPEAT_START.exec(text)) {
199
+ const start = match.index;
200
+ if (!free({ start, end: start + match[0].length }))
201
+ continue;
202
+ // The words after it, each ending where its spaces stop.
203
+ const ends = [start + match[0].length];
204
+ const words = /\S+/g;
205
+ words.lastIndex = ends[0];
206
+ for (let word = words.exec(text); word && ends.length <= REPEAT_WORDS; word = words.exec(text)) {
207
+ const span = { start: word.index, end: word.index + word[0].length };
208
+ if (!free(span))
209
+ break;
210
+ ends.push(span.end);
211
+ }
212
+ for (let n = ends.length - 1; n >= 0; n--) {
213
+ // A trailing comma is the line's, not the phrase's.
214
+ const end = ends[n] - (/[,;]$/.test(text.slice(start, ends[n])) ? 1 : 0);
215
+ const phrase = text.slice(start, end);
216
+ const parsed = parseRecurrencePhrase(phrase, {
217
+ today: options.today,
218
+ timeZone: options.timeZone,
219
+ weekStart: options.weekStart,
220
+ });
221
+ if (parsed.ok)
222
+ return { phrase, span: { start, end } };
223
+ }
224
+ }
225
+ return null;
226
+ }
227
+ function readDate() {
228
+ const today = options.today;
229
+ const ON = String.raw `(?:on\s+)?`;
230
+ const candidates = [];
231
+ const consider = (found) => {
232
+ if (found && outside(found.span))
233
+ candidates.push(found);
234
+ };
235
+ const guard = (match) => outside({ start: match.index, end: match.index + match[0].length });
236
+ consider(first(new RegExp(String.raw `${START}(today|tonight|tomorrow|tmrw)${END}`, 'giu'), (match) => guard(match) ? (/^t(omorrow|mrw)$/i.test(match[1]) ? addDays(today, 1) : today) : null));
237
+ consider(first(new RegExp(String.raw `${START}${ON}(?:(next|this)\s+)?(${WEEKDAY})${END}`, 'giu'), (match) => {
238
+ if (!guard(match))
239
+ return null;
240
+ const weekday = WEEKDAYS.find(([pattern]) => pattern.test(match[2].toLowerCase()))[1];
241
+ const ahead = (weekday - weekdayOf(today) + 7) % 7 || 7;
242
+ return addDays(today, ahead);
243
+ }));
244
+ consider(first(new RegExp(String.raw `${START}in\s+(\d{1,3}|a|an|one)\s+(days?|weeks?)${END}`, 'giu'), (match) => {
245
+ if (!guard(match))
246
+ return null;
247
+ const count = /^\d/.test(match[1]) ? Number(match[1]) : 1;
248
+ return addDays(today, count * (/^w/i.test(match[2]) ? 7 : 1));
249
+ }));
250
+ consider(first(new RegExp(String.raw `${START}${ON}(?:(${MONTH})\.?\s+(\d{1,2})(?:st|nd|rd|th)?|(\d{1,2})(?:st|nd|rd|th)?\s+(${MONTH}))${END}`, 'giu'), (match) => {
251
+ if (!guard(match))
252
+ return null;
253
+ const month = MONTHS.indexOf((match[1] ?? match[4]).slice(0, 3).toLowerCase()) + 1;
254
+ return nextMonthDay(month, Number(match[2] ?? match[3]), today);
255
+ }));
256
+ consider(first(new RegExp(String.raw `${START}${ON}(\d{1,2})/(\d{1,2})(?:/(\d{2}|\d{4}))?${END}`, 'giu'), (match) => {
257
+ if (!guard(match))
258
+ return null;
259
+ const [a, b] = [Number(match[1]), Number(match[2])];
260
+ const [month, day] = dayFirst(options.locale) ? [b, a] : [a, b];
261
+ if (match[3]) {
262
+ const year = match[3].length === 2 ? 2000 + Number(match[3]) : Number(match[3]);
263
+ return realDay(year, month, day);
264
+ }
265
+ return nextMonthDay(month, day, today);
266
+ }));
267
+ // The first in the line wins; the rest stay in the title.
268
+ candidates.sort((a, b) => a.span.start - b.span.start);
269
+ return candidates[0] ?? null;
270
+ }
271
+ function firstDay(value) {
272
+ const before = new Date(atLocal(value.start, '00:00', value.timeZone).getTime() - 1);
273
+ const next = nextOccurrence(value, before);
274
+ return next ? wallClock(next, value.timeZone).day : value.start;
275
+ }
276
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tristan2828/ui-foundation",
3
- "version": "4.134.0",
3
+ "version": "4.136.0",
4
4
  "description": "Shared UI foundation for contract-first, database-backed React apps: shadcn primitives, DataTable/EntityForm composites, auth, the gateway error seam, design tokens, lint rules and the AI playbook.",
5
5
  "license": "MIT",
6
6
  "repository": {
package/vite/index.d.ts CHANGED
@@ -48,6 +48,23 @@ export type PwaOptions = {
48
48
  * root). Replaces the generated ones everywhere.
49
49
  */
50
50
  icon?: string
51
+ /**
52
+ * Home-screen shortcuts: actions offered when the installed icon is
53
+ * long-pressed (Android, Chrome and Edge on desktop). Left out, the manifest
54
+ * has none. iOS and iPadOS ignore them.
55
+ */
56
+ shortcuts?: PwaShortcut[]
57
+ }
58
+
59
+ export type PwaShortcut = {
60
+ /** The action's label, e.g. "Add To-Do". */
61
+ name: string
62
+ /** A shorter label where space is tight. */
63
+ shortName?: string
64
+ /** A path inside the app, starting with `/`, e.g. `/todo/add`. Prefixed with the base. */
65
+ url: string
66
+ /** A square PNG of at least 192×192 (path from the Vite root). Without one the OS uses the app's icon. */
67
+ icon?: string
51
68
  }
52
69
 
53
70
  /**
package/vite/pwa.js CHANGED
@@ -188,6 +188,28 @@ export function pwaFiles(options, base = '/', root = process.cwd()) {
188
188
  ]
189
189
  touchIcon = 'icons/apple-touch-icon.png'
190
190
  }
191
+ const shortcuts = (options.shortcuts ?? []).map((shortcut, index) => {
192
+ const label = shortcut?.name?.trim()
193
+ const url = shortcut?.url?.trim()
194
+ if (!label) throw new Error(`pwa: shortcuts[${index}] needs a \`name\`.`)
195
+ if (!url?.startsWith('/') || url.startsWith('//')) {
196
+ throw new Error(`pwa: shortcuts[${index}].url must be a path inside the app, starting with "/" (got "${shortcut?.url}").`)
197
+ }
198
+ let icon
199
+ if (shortcut.icon) {
200
+ const own = path.resolve(root, shortcut.icon)
201
+ if (!own.endsWith('.png') || !fs.existsSync(own)) throw new Error(`pwa: shortcuts[${index}].icon must be a PNG file; ${own} isn't one.`)
202
+ const file = `icons/shortcut-${index}.png`
203
+ files.set(file, { type: 'image/png', source: fs.readFileSync(own) })
204
+ icon = [{ src: at(file), sizes: '192x192', type: 'image/png' }]
205
+ }
206
+ return {
207
+ name: label,
208
+ ...(shortcut.shortName?.trim() ? { short_name: shortcut.shortName.trim() } : {}),
209
+ url: `${base.replace(/\/$/, '')}${url}`,
210
+ ...(icon ? { icons: icon } : {}),
211
+ }
212
+ })
191
213
  const manifest = {
192
214
  name,
193
215
  short_name: shortName,
@@ -198,6 +220,7 @@ export function pwaFiles(options, base = '/', root = process.cwd()) {
198
220
  theme_color: theme,
199
221
  background_color: background,
200
222
  icons,
223
+ ...(shortcuts.length ? { shortcuts } : {}),
201
224
  }
202
225
  files.set('manifest.webmanifest', {
203
226
  type: 'application/manifest+json',