@tristan2828/ui-foundation 4.76.0 → 4.78.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 +34 -14
- package/conventions/docs/cell-patterns.md +89 -37
- package/conventions/docs/design-language.md +112 -27
- package/conventions/docs/entity-plan-template.md +2 -0
- package/dist/components/app/data-table.d.ts +11 -1
- package/dist/components/app/data-table.js +16 -6
- package/dist/components/app/edit-in-place-presets.d.ts +22 -0
- package/dist/components/app/edit-in-place-presets.js +35 -0
- package/dist/components/app/markdown.d.ts +13 -1
- package/dist/components/app/markdown.js +44 -2
- package/dist/components/app/month-day-field.d.ts +31 -0
- package/dist/components/app/month-day-field.js +134 -0
- package/dist/components/ui/table.d.ts +2 -1
- package/dist/components/ui/table.js +3 -3
- package/dist/index.d.ts +3 -1
- package/dist/index.js +2 -0
- package/dist/lib/markdown-inline.d.ts +10 -0
- package/dist/lib/markdown-inline.js +204 -0
- package/dist/lib/month-day.d.ts +27 -0
- package/dist/lib/month-day.js +62 -0
- package/package.json +1 -1
- package/styles/index.css +120 -0
- package/styles/theme.css +391 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
// Long text written as Markdown, rendered to read: headings, lists, links,
|
|
3
3
|
// tables (GitHub-flavoured), code and quotes, in the design language's
|
|
4
4
|
// type roles and tokens. A record's notes on its view (EntityView) are the
|
|
@@ -62,6 +62,14 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
62
62
|
// the app reports removed shows "Page removed", with Restore when the app
|
|
63
63
|
// gives one. Every other link is as it was; the text is never changed.
|
|
64
64
|
//
|
|
65
|
+
// With `inline`, it's a one-line value's Markdown (a table cell, a card's
|
|
66
|
+
// line): bold, italic, code and links on one run of words, in the font and
|
|
67
|
+
// colour of wherever it sits, with no block margins, so a row it's in
|
|
68
|
+
// keeps its height. Blocks written in it become their words, joined so
|
|
69
|
+
// they still read (a list's items with " · ", a table's rows as
|
|
70
|
+
// `Header: value` pairs: src/lib/markdown-inline.ts). A link's click and
|
|
71
|
+
// Enter stay its own: they never reach a row or card it sits in.
|
|
72
|
+
//
|
|
65
73
|
// A task item (`- [ ] to do`, `- [x] done`) shows its box as a glyph
|
|
66
74
|
// with its state in words: read-only text has nothing to tick. With
|
|
67
75
|
// `onTasksChange`, each box is a real checkbox, named for its item's
|
|
@@ -77,6 +85,7 @@ import { Checkbox } from '../ui/checkbox.js';
|
|
|
77
85
|
import { useFolds } from '../../hooks/fold-store.js';
|
|
78
86
|
import { CALLOUT_KINDS, remarkCallouts } from '../../lib/markdown-callout.js';
|
|
79
87
|
import { rehypeFold, toggleFold } from '../../lib/markdown-fold.js';
|
|
88
|
+
import { rehypeInline } from '../../lib/markdown-inline.js';
|
|
80
89
|
import { isHighlightColor, remarkHighlights } from '../../lib/markdown-highlight.js';
|
|
81
90
|
import { rehypeTables } from '../../lib/markdown-table.js';
|
|
82
91
|
import { remarkToggleHeadings } from '../../lib/markdown-toggle.js';
|
|
@@ -177,6 +186,29 @@ function MarkdownParagraph(props) {
|
|
|
177
186
|
return _jsx("p", { ...rest, "data-page-line": "", className: "page-line" });
|
|
178
187
|
return _jsx("p", { ...rest });
|
|
179
188
|
}
|
|
189
|
+
// A link in `inline` text: an ordinary link, opening in a new tab, whose
|
|
190
|
+
// click and Enter never reach what the text sits in (a row that opens
|
|
191
|
+
// its record, a card), so following it doesn't also open the row.
|
|
192
|
+
function InlineLink(props) {
|
|
193
|
+
const { href, children, ...rest } = omitNode(props);
|
|
194
|
+
if (!href)
|
|
195
|
+
return _jsx(_Fragment, { children: children });
|
|
196
|
+
return (_jsxs("a", { ...rest, href: href, target: "_blank", rel: "noreferrer", className: PROSE.link, onClick: (event) => event.stopPropagation(), onKeyDown: (event) => {
|
|
197
|
+
if (event.key === 'Enter' || event.key === ' ')
|
|
198
|
+
event.stopPropagation();
|
|
199
|
+
}, children: [children, _jsx(ExternalLinkIcon, { "aria-hidden": "true", className: "ml-0.5 inline size-3 align-baseline" }), _jsx("span", { className: "sr-only", children: " (opens in a new tab)" })] }));
|
|
200
|
+
}
|
|
201
|
+
// `inline`: only what `rehypeInline` keeps, in the text's own font and colour.
|
|
202
|
+
// Code is the mono face alone, no wash: in the cell's own colour a wash
|
|
203
|
+
// would fail contrast (muted text on --muted is 4.34:1), and a row's own
|
|
204
|
+
// fill (the stripe, a hover, a pick) is already behind it. The face has
|
|
205
|
+
// taller metrics than the text's, so it adds no height to the line
|
|
206
|
+
// (`leading-[0]`).
|
|
207
|
+
const INLINE_COMPONENTS = {
|
|
208
|
+
a: InlineLink,
|
|
209
|
+
code: (props) => _jsx("code", { ...omitNode(props), className: "font-mono text-[0.9em] leading-[0]" }),
|
|
210
|
+
};
|
|
211
|
+
const INLINE_REHYPE = [rehypeInline];
|
|
180
212
|
// Folds a section by its heading's id: given only with `foldKey`.
|
|
181
213
|
const FoldContext = createContext(null);
|
|
182
214
|
// A heading by its Markdown level: the element the page's outline gives
|
|
@@ -273,7 +305,17 @@ function componentsFor(top, textTop) {
|
|
|
273
305
|
}
|
|
274
306
|
return components;
|
|
275
307
|
}
|
|
276
|
-
|
|
308
|
+
const BLOCK_ONLY = ['headingLevel', 'headingFrom', 'foldKey', 'foldable', 'onTasksChange', 'tableLook', 'pageLink'];
|
|
309
|
+
export function Markdown({ inline = false, ...props }) {
|
|
310
|
+
if (!inline)
|
|
311
|
+
return _jsx(BlockMarkdown, { ...props });
|
|
312
|
+
const { children, className, ...rest } = props;
|
|
313
|
+
// The block text's own props mean nothing on one line: none reach the span.
|
|
314
|
+
for (const key of BLOCK_ONLY)
|
|
315
|
+
delete rest[key];
|
|
316
|
+
return (_jsx("span", { "data-slot": "markdown", "data-inline": "", ...rest, className: cn('min-w-0 break-words', className), children: _jsx(ReactMarkdown, { remarkPlugins: REMARK_PLUGINS, rehypePlugins: INLINE_REHYPE, components: INLINE_COMPONENTS, children: children }) }));
|
|
317
|
+
}
|
|
318
|
+
function BlockMarkdown({ children, headingLevel = DEFAULT_HEADING_LEVEL, headingFrom = 'hash', foldKey: foldKeyProp, foldable = true, onTasksChange: onTasksChangeProp, tableLook = 'compact', pageLink, className, ...rest }) {
|
|
277
319
|
// On paper (EntityView's Print notes): every heading plain and open,
|
|
278
320
|
// every task box a picture.
|
|
279
321
|
const printing = usePrinting();
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type MonthDay } from '../../lib/month-day.js';
|
|
2
|
+
export type MonthDayFieldProps = {
|
|
3
|
+
/** The trigger button's id, for the field's `<FieldLabel htmlFor>`. */
|
|
4
|
+
id?: string;
|
|
5
|
+
/** `'MM-DD'`, or `''` for not set. */
|
|
6
|
+
value: MonthDay;
|
|
7
|
+
/** Called with the picked day as `'MM-DD'`, or `''` when cleared. */
|
|
8
|
+
onChange: (value: MonthDay) => void;
|
|
9
|
+
/** What the button says with no day set. Defaults to "Pick a day". */
|
|
10
|
+
placeholder?: string;
|
|
11
|
+
/** Offer Clear in the picker, for an optional field. */
|
|
12
|
+
clearable?: boolean;
|
|
13
|
+
/** The value was refused: `aria-invalid` on the button. */
|
|
14
|
+
invalid?: boolean;
|
|
15
|
+
/** Saving: the button shows the day but won't open. */
|
|
16
|
+
readOnly?: boolean;
|
|
17
|
+
/** Open on mount: editing in place, where the picker opens with the field. */
|
|
18
|
+
defaultOpen?: boolean;
|
|
19
|
+
/** Passed to the Popover; `false` when editing in place, as for a Select. */
|
|
20
|
+
modal?: boolean;
|
|
21
|
+
/** Told when the picker opens or closes; editing in place gives up on a close with nothing picked. */
|
|
22
|
+
onOpenChange?: (open: boolean) => void;
|
|
23
|
+
/** How the day reads on the button. Defaults to `{ month: 'short', day: 'numeric' }` ("Mar 14"). */
|
|
24
|
+
format?: Pick<Intl.DateTimeFormatOptions, 'month' | 'day'>;
|
|
25
|
+
locale?: string;
|
|
26
|
+
className?: string;
|
|
27
|
+
'aria-label'?: string;
|
|
28
|
+
'aria-labelledby'?: string;
|
|
29
|
+
'aria-describedby'?: string;
|
|
30
|
+
};
|
|
31
|
+
export declare function MonthDayField({ id, value, onChange, placeholder, clearable, invalid, readOnly, defaultOpen, modal, onOpenChange, format, locale, className, ...aria }: MonthDayFieldProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
// A month and day with no year: something that comes round every year (a
|
|
3
|
+
// season's start, a yearly deadline). The value is `'MM-DD'`, or `''` for
|
|
4
|
+
// not set (`lib/month-day.ts`).
|
|
5
|
+
//
|
|
6
|
+
// A button showing the day ("Mar 14"), opening a picker in a Popover like
|
|
7
|
+
// DateField's: twelve months, then the chosen month's days. A calendar
|
|
8
|
+
// grid would need a year (its weekdays and leading blanks are a year's),
|
|
9
|
+
// so the days are 1 to the month's last in rows of seven, February
|
|
10
|
+
// running to the 29th. Only real days are offered, so the field can't
|
|
11
|
+
// make February 30; a stored value that isn't one (`'02-30'`, old text)
|
|
12
|
+
// shows as written, nothing selected. The arrow keys move through either
|
|
13
|
+
// grid (Home and End to its ends), Page Up and Page Down change the month,
|
|
14
|
+
// and every button is 36px or larger for a finger.
|
|
15
|
+
//
|
|
16
|
+
// One control for the form (a react-hook-form `Controller`) and for
|
|
17
|
+
// editing in place (`inPlace.monthDay`: picking a day saves, and the
|
|
18
|
+
// picker opens with the field). `clearable` adds Clear for an optional field.
|
|
19
|
+
import { useEffect, useId, useRef, useState } from 'react';
|
|
20
|
+
import { CalendarIcon, ChevronLeftIcon, ChevronRightIcon } from 'lucide-react';
|
|
21
|
+
import { cn } from 'cn';
|
|
22
|
+
import { Button } from '../ui/button.js';
|
|
23
|
+
import { Popover, PopoverContent, PopoverTrigger } from '../ui/popover.js';
|
|
24
|
+
import { daysInMonth, formatMonthDay, monthDayParts, monthName, toMonthDay } from '../../lib/month-day.js';
|
|
25
|
+
const MONTH_COLUMNS = 3;
|
|
26
|
+
const DAY_COLUMNS = 7;
|
|
27
|
+
// Where an arrow key moves in a grid of `count` cells, `columns` wide, or
|
|
28
|
+
// null for a key the grid doesn't use. Left and Right run on across rows.
|
|
29
|
+
function moveInGrid(key, at, count, columns) {
|
|
30
|
+
const next = key === 'ArrowLeft'
|
|
31
|
+
? at - 1
|
|
32
|
+
: key === 'ArrowRight'
|
|
33
|
+
? at + 1
|
|
34
|
+
: key === 'ArrowUp'
|
|
35
|
+
? at - columns
|
|
36
|
+
: key === 'ArrowDown'
|
|
37
|
+
? at + columns
|
|
38
|
+
: key === 'Home'
|
|
39
|
+
? 0
|
|
40
|
+
: key === 'End'
|
|
41
|
+
? count - 1
|
|
42
|
+
: null;
|
|
43
|
+
if (next === null)
|
|
44
|
+
return null;
|
|
45
|
+
return Math.min(Math.max(next, 0), count - 1);
|
|
46
|
+
}
|
|
47
|
+
// The month after (or before) one, round the year.
|
|
48
|
+
const nextMonth = (month, by) => ((month - 1 + by + 12) % 12) + 1;
|
|
49
|
+
export function MonthDayField({ id, value, onChange, placeholder = 'Pick a day', clearable = false, invalid = false, readOnly = false, defaultOpen = false, modal, onOpenChange, format, locale, className, ...aria }) {
|
|
50
|
+
const [open, setOpen] = useState(defaultOpen && !readOnly);
|
|
51
|
+
const popup = useRef(null);
|
|
52
|
+
const selected = monthDayParts(value);
|
|
53
|
+
// A value that isn't a day of the year reads as written, so nothing typed before is hidden.
|
|
54
|
+
const shown = formatMonthDay(value, format, locale) || value;
|
|
55
|
+
const changeOpen = (next) => {
|
|
56
|
+
if (next && readOnly)
|
|
57
|
+
return;
|
|
58
|
+
setOpen(next);
|
|
59
|
+
onOpenChange?.(next);
|
|
60
|
+
};
|
|
61
|
+
const pick = (next) => {
|
|
62
|
+
onChange(next);
|
|
63
|
+
changeOpen(false);
|
|
64
|
+
};
|
|
65
|
+
return (_jsxs(Popover, { open: open, onOpenChange: changeOpen, modal: modal, children: [_jsxs(PopoverTrigger, { render: _jsx(Button, { id: id, type: "button", variant: "outline", "aria-invalid": invalid || undefined, "aria-readonly": readOnly || undefined, className: cn('w-full justify-start font-normal', !shown && 'text-muted-foreground', className), ...aria }), children: [_jsx(CalendarIcon, { "aria-hidden": "true", className: "size-4" }), shown || placeholder] }), _jsxs(PopoverContent, { ref: popup, className: "w-auto p-0", "data-slot": "month-day-field-picker", "aria-label": "Month and day",
|
|
66
|
+
// The button the keyboard starts from (the chosen day, else this
|
|
67
|
+
// month): the one the grid makes tabbable. The popup would
|
|
68
|
+
// otherwise take focus itself.
|
|
69
|
+
initialFocus: () => popup.current?.querySelector('[data-cell][tabindex="0"]') ?? true, children: [open && (_jsx(Picker, { selected: selected, locale: locale, onPick: (month, day) => pick(toMonthDay(month, day)) })), clearable && value && (_jsx("div", { className: "border-t border-border p-2", children: _jsx(Button, { type: "button", variant: "ghost", size: "sm", className: "w-full", onClick: () => pick(''), children: "Clear" }) }))] })] }));
|
|
70
|
+
}
|
|
71
|
+
// The two steps: a month (when nothing is chosen yet, or from the day
|
|
72
|
+
// step's month button), then its days. It opens on the chosen day's month,
|
|
73
|
+
// else on the months with this one to start from.
|
|
74
|
+
function Picker({ selected, locale, onPick }) {
|
|
75
|
+
const today = new Date();
|
|
76
|
+
const [step, setStep] = useState(selected ? 'day' : 'month');
|
|
77
|
+
const [month, setMonth] = useState(selected?.month ?? today.getMonth() + 1);
|
|
78
|
+
// The cell the keyboard is on in the grid shown: a month (1–12) or a day.
|
|
79
|
+
const [active, setActive] = useState(selected ? selected.day : today.getMonth() + 1);
|
|
80
|
+
const grid = useRef(null);
|
|
81
|
+
// Focus follows `active` once the grid is drawn (a step or a month
|
|
82
|
+
// changed, an arrow key), never on a click elsewhere in the popup. On
|
|
83
|
+
// opening, the popup's own initial focus puts it there.
|
|
84
|
+
const focusWanted = useRef(false);
|
|
85
|
+
const monthsLabel = useId();
|
|
86
|
+
useEffect(() => {
|
|
87
|
+
if (!focusWanted.current)
|
|
88
|
+
return;
|
|
89
|
+
focusWanted.current = false;
|
|
90
|
+
grid.current?.querySelector(`[data-cell="${active}"]`)?.focus();
|
|
91
|
+
});
|
|
92
|
+
const days = daysInMonth(month);
|
|
93
|
+
const showMonth = (next, day) => {
|
|
94
|
+
setMonth(next);
|
|
95
|
+
setActive(Math.min(day, daysInMonth(next)));
|
|
96
|
+
focusWanted.current = true;
|
|
97
|
+
};
|
|
98
|
+
const onGridKeyDown = (event) => {
|
|
99
|
+
if (step === 'day' && (event.key === 'PageUp' || event.key === 'PageDown')) {
|
|
100
|
+
event.preventDefault();
|
|
101
|
+
showMonth(nextMonth(month, event.key === 'PageUp' ? -1 : 1), active);
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
const [count, columns] = step === 'month' ? [12, MONTH_COLUMNS] : [days, DAY_COLUMNS];
|
|
105
|
+
const at = moveInGrid(event.key, active - 1, count, columns);
|
|
106
|
+
if (at === null)
|
|
107
|
+
return;
|
|
108
|
+
event.preventDefault();
|
|
109
|
+
if (at + 1 === active)
|
|
110
|
+
return;
|
|
111
|
+
setActive(at + 1);
|
|
112
|
+
focusWanted.current = true;
|
|
113
|
+
};
|
|
114
|
+
const name = monthName(month, 'long', locale);
|
|
115
|
+
if (step === 'month') {
|
|
116
|
+
return (_jsxs("div", { className: "p-3", children: [_jsx("p", { className: "mb-2 px-1 text-sm font-medium", id: monthsLabel, children: "Month" }), _jsx("div", { ref: grid, role: "group", "aria-labelledby": monthsLabel, className: "grid grid-cols-3 gap-1", onKeyDown: onGridKeyDown, children: Array.from({ length: 12 }, (_, index) => {
|
|
117
|
+
const each = index + 1;
|
|
118
|
+
const chosen = selected?.month === each;
|
|
119
|
+
return (_jsxs(Button, { type: "button", variant: chosen ? 'default' : 'ghost', className: "h-10 w-20 font-normal", "data-cell": each, tabIndex: each === active ? 0 : -1, "aria-pressed": chosen, onClick: () => {
|
|
120
|
+
setStep('day');
|
|
121
|
+
showMonth(each, selected?.month === each ? selected.day : 1);
|
|
122
|
+
}, children: [_jsx("span", { "aria-hidden": "true", children: monthName(each, 'short', locale) }), _jsx("span", { className: "sr-only", children: monthName(each, 'long', locale) })] }, each));
|
|
123
|
+
}) })] }));
|
|
124
|
+
}
|
|
125
|
+
return (_jsxs("div", { className: "p-3", children: [_jsxs("div", { className: "mb-2 flex items-center justify-between gap-1", children: [_jsx(Button, { type: "button", variant: "ghost", size: "icon", "aria-label": "Previous month", onClick: () => showMonth(nextMonth(month, -1), active), children: _jsx(ChevronLeftIcon, { "aria-hidden": "true" }) }), _jsx(Button, { type: "button", variant: "ghost", className: "font-medium", "aria-label": `${name}, pick another month`, onClick: () => {
|
|
126
|
+
setStep('month');
|
|
127
|
+
setActive(month);
|
|
128
|
+
focusWanted.current = true;
|
|
129
|
+
}, children: name }), _jsx(Button, { type: "button", variant: "ghost", size: "icon", "aria-label": "Next month", onClick: () => showMonth(nextMonth(month, 1), active), children: _jsx(ChevronRightIcon, { "aria-hidden": "true" }) })] }), _jsx("div", { ref: grid, role: "group", "aria-label": name, className: "grid grid-cols-7 gap-1", onKeyDown: onGridKeyDown, children: Array.from({ length: days }, (_, index) => {
|
|
130
|
+
const day = index + 1;
|
|
131
|
+
const chosen = selected?.month === month && selected.day === day;
|
|
132
|
+
return (_jsx(Button, { type: "button", variant: chosen ? 'default' : 'ghost', size: "icon", className: "font-normal tabular-nums", "data-cell": day, tabIndex: day === active ? 0 : -1, "aria-label": formatMonthDay(toMonthDay(month, day), { month: 'long', day: 'numeric' }, locale), "aria-pressed": chosen, onClick: () => onPick(month, day), children: day }, day));
|
|
133
|
+
}) })] }));
|
|
134
|
+
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
declare function Table({ className, containerRef, containerClassName, ...props }: React.ComponentProps<"table"> & {
|
|
2
|
+
declare function Table({ className, containerRef, containerClassName, containerStyle, ...props }: React.ComponentProps<"table"> & {
|
|
3
3
|
containerRef?: React.Ref<HTMLDivElement>;
|
|
4
4
|
containerClassName?: string;
|
|
5
|
+
containerStyle?: React.CSSProperties;
|
|
5
6
|
}): React.JSX.Element;
|
|
6
7
|
declare function TableHeader({ className, ...props }: React.ComponentProps<"thead">): React.JSX.Element;
|
|
7
8
|
declare function TableBody({ className, ...props }: React.ComponentProps<"tbody">): React.JSX.Element;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import * as React from "react";
|
|
3
3
|
import { cn } from "cn";
|
|
4
|
-
// `containerRef`/`containerClassName` are this repo's patch to the upstream
|
|
4
|
+
// `containerRef`/`containerClassName`/`containerStyle` are this repo's patch to the upstream
|
|
5
5
|
// primitive. Upstream wraps the <table> in a scroll container that nothing
|
|
6
6
|
// outside can reach, so anything keyed to the scroll viewport — a sticky
|
|
7
7
|
// scrollbar, a pinned column, an IntersectionObserver — had to find that
|
|
@@ -11,8 +11,8 @@ import { cn } from "cn";
|
|
|
11
11
|
//
|
|
12
12
|
// A local patch to a shadcn primitive: re-running `shadcn add table` here
|
|
13
13
|
// would overwrite it. Diff against upstream before taking a new version.
|
|
14
|
-
function Table({ className, containerRef, containerClassName, ...props }) {
|
|
15
|
-
return (_jsx("div", { ref: containerRef, "data-slot": "table-container", className: cn("relative w-full overflow-x-auto", containerClassName), children: _jsx("table", { "data-slot": "table", className: cn("w-full caption-bottom text-sm", className), ...props }) }));
|
|
14
|
+
function Table({ className, containerRef, containerClassName, containerStyle, ...props }) {
|
|
15
|
+
return (_jsx("div", { ref: containerRef, "data-slot": "table-container", className: cn("relative w-full overflow-x-auto", containerClassName), style: containerStyle, children: _jsx("table", { "data-slot": "table", className: cn("w-full caption-bottom text-sm", className), ...props }) }));
|
|
16
16
|
}
|
|
17
17
|
function TableHeader({ className, ...props }) {
|
|
18
18
|
return (_jsx("thead", { "data-slot": "table-header", className: cn("[&_tr]:border-b", className), ...props }));
|
package/dist/index.d.ts
CHANGED
|
@@ -20,7 +20,7 @@ export { usePrinting } from './components/app/print-context.js';
|
|
|
20
20
|
export { RecordDialogRoute, RecordLink, type RecordDialogRouteProps, type RecordLinkProps, } from './components/app/record-dialog.js';
|
|
21
21
|
export { recordDialogState, useOpenRecord, useRecordDialog, type RecordDialogBackground, type RecordDialogContextValue, type RecordDialogState, } from './components/app/record-dialog-context.js';
|
|
22
22
|
export { editInPlace, type EditControlProps, type EditInPlace, type EditInPlaceList, type EditInPlaceListOptions, type EditInPlaceOptions, type EditKind, type EditListAddProps, type EditListItemProps, } from './components/app/edit-in-place.js';
|
|
23
|
-
export { inPlace, type InPlaceDateConfig, type InPlaceFieldsOptions, type InPlaceLinkConfig, type InPlaceLinkValue, type InPlaceMoneyConfig, type InPlaceNumberConfig, type InPlaceOption, type InPlacePart, type InPlaceRecord, type InPlaceReferenceConfig, type InPlaceSaved, type InPlaceSelectConfig, type InPlaceTextConfig, } from './components/app/edit-in-place-presets.js';
|
|
23
|
+
export { inPlace, type InPlaceDateConfig, type InPlaceFieldsOptions, type InPlaceLinkConfig, type InPlaceLinkValue, type InPlaceMoneyConfig, type InPlaceMonthDayConfig, type InPlaceNumberConfig, type InPlaceOption, type InPlacePart, type InPlaceRecord, type InPlaceReferenceConfig, type InPlaceSaved, type InPlaceSelectConfig, type InPlaceTextConfig, } from './components/app/edit-in-place-presets.js';
|
|
24
24
|
export { linkHost, linkHref, linkRule } from './lib/link-href.js';
|
|
25
25
|
export { DataEnvironmentBanner } from './components/app/data-environment-banner.js';
|
|
26
26
|
export { EditableValue, type EditableValueProps } from './components/app/editable-value.js';
|
|
@@ -55,9 +55,11 @@ export { StepBar, type StepBarProps } from './components/app/step-bar.js';
|
|
|
55
55
|
export { RatingStar, type RatingStarProps, type RatingStarValue } from './components/app/rating-star.js';
|
|
56
56
|
export { DateField, type DateFieldProps } from './components/app/date-field.js';
|
|
57
57
|
export { EmojiField, type EmojiFieldProps } from './components/app/emoji-field.js';
|
|
58
|
+
export { MonthDayField, type MonthDayFieldProps } from './components/app/month-day-field.js';
|
|
58
59
|
export { ImageField, type ImageFieldProps } from './components/app/image-field.js';
|
|
59
60
|
export { DEFAULT_IMAGE_TYPES, type ImageUpload, type ImageUploadResult } from './lib/image-file.js';
|
|
60
61
|
export { formatPlainDate, type PlainDate } from './lib/plain-date.js';
|
|
62
|
+
export { formatMonthDay, isMonthDay, monthDayProblem, type MonthDay } from './lib/month-day.js';
|
|
61
63
|
export { ChoiceCell, LinkCell, LinkOut, NameCell, type ChoiceCellProps, type LinkCellProps, type NameCellProps, } from './components/app/row-edit-cells.js';
|
|
62
64
|
export { ModuleCard, ModuleStrip, type CategorySlot, type ModuleCardLink, type ModuleCardPlace, type ModuleCardProps, type ModuleStripMobile, type ModuleStripProps, } from './components/app/module-card.js';
|
|
63
65
|
export { WidgetCard, WidgetCardGroup, WidgetList, WidgetListItem, type WidgetCardGroupProps, type WidgetCardLink, type WidgetCardProps, type WidgetListItemProps, } from './components/app/widget-card.js';
|
package/dist/index.js
CHANGED
|
@@ -57,9 +57,11 @@ export { StepBar } from './components/app/step-bar.js';
|
|
|
57
57
|
export { RatingStar } from './components/app/rating-star.js';
|
|
58
58
|
export { DateField } from './components/app/date-field.js';
|
|
59
59
|
export { EmojiField } from './components/app/emoji-field.js';
|
|
60
|
+
export { MonthDayField } from './components/app/month-day-field.js';
|
|
60
61
|
export { ImageField } from './components/app/image-field.js';
|
|
61
62
|
export { DEFAULT_IMAGE_TYPES } from './lib/image-file.js';
|
|
62
63
|
export { formatPlainDate } from './lib/plain-date.js';
|
|
64
|
+
export { formatMonthDay, isMonthDay, monthDayProblem } from './lib/month-day.js';
|
|
63
65
|
export { ChoiceCell, LinkCell, LinkOut, NameCell, } from './components/app/row-edit-cells.js';
|
|
64
66
|
export { ModuleCard, ModuleStrip, } from './components/app/module-card.js';
|
|
65
67
|
export { WidgetCard, WidgetCardGroup, WidgetList, WidgetListItem, } from './components/app/widget-card.js';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
type Node = {
|
|
2
|
+
type: string;
|
|
3
|
+
tagName?: string;
|
|
4
|
+
value?: string;
|
|
5
|
+
properties?: Record<string, unknown>;
|
|
6
|
+
children?: Node[];
|
|
7
|
+
};
|
|
8
|
+
/** Flattens the whole text to one line of inline content (see above). */
|
|
9
|
+
export declare function rehypeInline(): (tree: Node) => void;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
// <Markdown inline>: a one-line value's Markdown (a table cell, a card's
|
|
2
|
+
// line, a summary) as one run of words, so it sits in a row without
|
|
3
|
+
// making it taller. Bold, italic, code and links keep their marks; every
|
|
4
|
+
// other mark is its words. Blocks have nowhere to go on one line, so each
|
|
5
|
+
// becomes its words, in order, joined so they still read:
|
|
6
|
+
//
|
|
7
|
+
// - paragraphs (and lines): a space
|
|
8
|
+
// - headings, quotes, rules and any other block: " · "
|
|
9
|
+
// - a list: its items, " · " between them; numbered with their numbers
|
|
10
|
+
// (`1. a · 2. b`); a task item done starts "✓ ", one to do "☐ "
|
|
11
|
+
// - a table: each row as `Header: value` pairs, ", " between them and
|
|
12
|
+
// " · " between rows (the header row itself isn't repeated); cells
|
|
13
|
+
// with no header, or no words, are left out
|
|
14
|
+
// - a code block: inline code
|
|
15
|
+
// - an image: its alt text, if any
|
|
16
|
+
// - a callout: its kind first ("Note: …")
|
|
17
|
+
//
|
|
18
|
+
// The text itself is never changed: this is how it's drawn on one line.
|
|
19
|
+
// A rehype plugin, on the HTML tree after remark-gfm and the package's
|
|
20
|
+
// own remark plugins, so what it flattens is what <Markdown> would draw.
|
|
21
|
+
const KEEP = new Set(['strong', 'em', 'code', 'a']);
|
|
22
|
+
const SEPARATOR = ' · ';
|
|
23
|
+
const text = (value) => ({ type: 'text', value });
|
|
24
|
+
// A node's words alone, marks dropped (a table cell's header, an alt).
|
|
25
|
+
function plain(node) {
|
|
26
|
+
if (node.type === 'text' || node.type === 'raw')
|
|
27
|
+
return node.value ?? '';
|
|
28
|
+
if (node.tagName === 'img')
|
|
29
|
+
return typeof node.properties?.alt === 'string' ? node.properties.alt : '';
|
|
30
|
+
return (node.children ?? []).map(plain).join('');
|
|
31
|
+
}
|
|
32
|
+
const hasWords = (nodes) => nodes.some((node) => plain(node).trim() !== '');
|
|
33
|
+
// Parts joined with a separator, leaving out the empty ones.
|
|
34
|
+
function join(parts, separator) {
|
|
35
|
+
const out = [];
|
|
36
|
+
for (const part of parts.filter(hasWords)) {
|
|
37
|
+
if (out.length > 0)
|
|
38
|
+
out.push(text(separator));
|
|
39
|
+
out.push(...part);
|
|
40
|
+
}
|
|
41
|
+
return out;
|
|
42
|
+
}
|
|
43
|
+
const capitalise = (word) => word.charAt(0).toUpperCase() + word.slice(1);
|
|
44
|
+
function rows(table) {
|
|
45
|
+
const out = [];
|
|
46
|
+
const walk = (node) => {
|
|
47
|
+
for (const child of node.children ?? []) {
|
|
48
|
+
if (child.tagName === 'tr')
|
|
49
|
+
out.push((child.children ?? []).filter((cell) => cell.tagName === 'td' || cell.tagName === 'th'));
|
|
50
|
+
else
|
|
51
|
+
walk(child);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
walk(table);
|
|
55
|
+
return out;
|
|
56
|
+
}
|
|
57
|
+
function flattenTable(table) {
|
|
58
|
+
const head = table.children?.find((child) => child.tagName === 'thead');
|
|
59
|
+
const all = rows(table);
|
|
60
|
+
const headers = head ? rows(head)[0]?.map((cell) => plain(cell).trim()) ?? [] : [];
|
|
61
|
+
const body = head ? all.slice(1) : all;
|
|
62
|
+
return join(body.map((cells) => join(cells.map((cell, index) => {
|
|
63
|
+
const words = inline(cell.children ?? []);
|
|
64
|
+
if (!hasWords(words))
|
|
65
|
+
return [];
|
|
66
|
+
return headers[index] ? [text(`${headers[index]}: `), ...words] : words;
|
|
67
|
+
}), ', ')), SEPARATOR);
|
|
68
|
+
}
|
|
69
|
+
function flattenList(list) {
|
|
70
|
+
const start = Number(list.properties?.start ?? 1) || 1;
|
|
71
|
+
const items = (list.children ?? []).filter((child) => child.tagName === 'li');
|
|
72
|
+
return join(items.map((item, index) => {
|
|
73
|
+
const box = findBox(item);
|
|
74
|
+
const lead = box ? (box.properties?.checked ? '✓ ' : '☐ ') : list.tagName === 'ol' ? `${start + index}. ` : '';
|
|
75
|
+
const words = blocks(item.children ?? []);
|
|
76
|
+
return hasWords(words) ? [text(lead), ...words] : [];
|
|
77
|
+
}), SEPARATOR);
|
|
78
|
+
}
|
|
79
|
+
// A task item's box: GFM puts it first in the item, or in its first paragraph.
|
|
80
|
+
function findBox(item) {
|
|
81
|
+
const first = item.children?.find((child) => child.type === 'element');
|
|
82
|
+
if (first?.tagName === 'input')
|
|
83
|
+
return first;
|
|
84
|
+
if (first?.tagName === 'p')
|
|
85
|
+
return first.children?.find((child) => child.tagName === 'input');
|
|
86
|
+
return undefined;
|
|
87
|
+
}
|
|
88
|
+
// Inline content: the four kept marks stay (their own content flattened),
|
|
89
|
+
// anything else is its words.
|
|
90
|
+
function inline(nodes) {
|
|
91
|
+
const out = [];
|
|
92
|
+
for (const node of nodes) {
|
|
93
|
+
// Raw HTML stays its characters, as <Markdown> shows it everywhere.
|
|
94
|
+
if (node.type === 'text' || node.type === 'raw')
|
|
95
|
+
out.push(text((node.value ?? '').replace(/\s*\n\s*/g, ' ')));
|
|
96
|
+
else if (node.type !== 'element')
|
|
97
|
+
continue;
|
|
98
|
+
else if (node.tagName === 'br')
|
|
99
|
+
out.push(text(' '));
|
|
100
|
+
else if (node.tagName === 'input')
|
|
101
|
+
continue;
|
|
102
|
+
else if (node.tagName === 'img') {
|
|
103
|
+
const alt = plain(node);
|
|
104
|
+
if (alt)
|
|
105
|
+
out.push(text(alt));
|
|
106
|
+
}
|
|
107
|
+
else if (KEEP.has(node.tagName ?? ''))
|
|
108
|
+
out.push({ ...node, children: node.tagName === 'code' ? [text(plain(node))] : inline(node.children ?? []) });
|
|
109
|
+
else if (isBlock(node))
|
|
110
|
+
out.push(...blocks([node]));
|
|
111
|
+
else
|
|
112
|
+
out.push(...inline(node.children ?? []));
|
|
113
|
+
}
|
|
114
|
+
return out;
|
|
115
|
+
}
|
|
116
|
+
const BLOCKS = new Set(['p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'ul', 'ol', 'li', 'table', 'blockquote', 'pre', 'hr', 'div', 'section']);
|
|
117
|
+
const isBlock = (node) => node.type === 'element' && BLOCKS.has(node.tagName ?? '');
|
|
118
|
+
// One block's words.
|
|
119
|
+
function block(node) {
|
|
120
|
+
switch (node.tagName) {
|
|
121
|
+
case 'ul':
|
|
122
|
+
case 'ol':
|
|
123
|
+
return flattenList(node);
|
|
124
|
+
case 'table':
|
|
125
|
+
return flattenTable(node);
|
|
126
|
+
case 'hr':
|
|
127
|
+
return [];
|
|
128
|
+
case 'pre': {
|
|
129
|
+
const code = node.children?.find((child) => child.tagName === 'code');
|
|
130
|
+
const words = plain(code ?? node).trim().replace(/\s*\n\s*/g, ' ');
|
|
131
|
+
return words ? [{ type: 'element', tagName: 'code', properties: {}, children: [text(words)] }] : [];
|
|
132
|
+
}
|
|
133
|
+
case 'div': {
|
|
134
|
+
const kind = node.properties?.dataCallout;
|
|
135
|
+
const words = blocks(node.children ?? []);
|
|
136
|
+
return typeof kind === 'string' && hasWords(words) ? [text(`${capitalise(kind)}: `), ...words] : words;
|
|
137
|
+
}
|
|
138
|
+
case 'p':
|
|
139
|
+
case 'h1':
|
|
140
|
+
case 'h2':
|
|
141
|
+
case 'h3':
|
|
142
|
+
case 'h4':
|
|
143
|
+
case 'h5':
|
|
144
|
+
case 'h6':
|
|
145
|
+
return inline(node.children ?? []);
|
|
146
|
+
default:
|
|
147
|
+
return blocks(node.children ?? []);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
// A run of siblings, some blocks and some inline: inline stretches stay
|
|
151
|
+
// as they are, blocks join with a space after a paragraph into another,
|
|
152
|
+
// else " · ".
|
|
153
|
+
function blocks(nodes) {
|
|
154
|
+
const out = [];
|
|
155
|
+
let previous = null;
|
|
156
|
+
let run = [];
|
|
157
|
+
const flush = () => {
|
|
158
|
+
if (!hasWords(run))
|
|
159
|
+
return (run = []);
|
|
160
|
+
if (previous !== null)
|
|
161
|
+
out.push(text(SEPARATOR));
|
|
162
|
+
out.push(...trim(run));
|
|
163
|
+
previous = 'inline';
|
|
164
|
+
run = [];
|
|
165
|
+
};
|
|
166
|
+
for (const node of nodes) {
|
|
167
|
+
if (!isBlock(node)) {
|
|
168
|
+
if (node.type === 'text' && !(node.value ?? '').trim() && run.length === 0)
|
|
169
|
+
continue;
|
|
170
|
+
run.push(...inline([node]));
|
|
171
|
+
continue;
|
|
172
|
+
}
|
|
173
|
+
flush();
|
|
174
|
+
const words = block(node);
|
|
175
|
+
// A rule has no words, but the blocks either side of it are apart.
|
|
176
|
+
if (!hasWords(words)) {
|
|
177
|
+
if (previous !== null)
|
|
178
|
+
previous = node.tagName ?? 'block';
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
|
+
if (previous !== null)
|
|
182
|
+
out.push(text(previous === 'p' && node.tagName === 'p' ? ' ' : SEPARATOR));
|
|
183
|
+
out.push(...words);
|
|
184
|
+
previous = node.tagName ?? 'block';
|
|
185
|
+
}
|
|
186
|
+
flush();
|
|
187
|
+
return trim(out);
|
|
188
|
+
}
|
|
189
|
+
// No space at either end of the line.
|
|
190
|
+
function trim(nodes) {
|
|
191
|
+
const out = [...nodes];
|
|
192
|
+
if (out[0]?.type === 'text')
|
|
193
|
+
out[0] = text((out[0].value ?? '').trimStart());
|
|
194
|
+
const last = out.length - 1;
|
|
195
|
+
if (out[last]?.type === 'text')
|
|
196
|
+
out[last] = text((out[last].value ?? '').trimEnd());
|
|
197
|
+
return out;
|
|
198
|
+
}
|
|
199
|
+
/** Flattens the whole text to one line of inline content (see above). */
|
|
200
|
+
export function rehypeInline() {
|
|
201
|
+
return (tree) => {
|
|
202
|
+
tree.children = blocks(tree.children ?? []);
|
|
203
|
+
};
|
|
204
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/** A day of the year with no year, `'MM-DD'`, or `''` for not set. */
|
|
2
|
+
export type MonthDay = string;
|
|
3
|
+
/** How many days the month (1–12) can have: February's 29 counted. */
|
|
4
|
+
export declare function daysInMonth(month: number): number;
|
|
5
|
+
/** The month (1–12) and day of a real `'MM-DD'`, or null for anything else (`''`, `'02-30'`, `'3-14'`). */
|
|
6
|
+
export declare function monthDayParts(value: MonthDay): {
|
|
7
|
+
month: number;
|
|
8
|
+
day: number;
|
|
9
|
+
} | null;
|
|
10
|
+
/** Whether the value is a real day of the year as `'MM-DD'`: `'02-29'` is, `'02-30'` isn't. */
|
|
11
|
+
export declare function isMonthDay(value: MonthDay): boolean;
|
|
12
|
+
/** The month (1–12) and day as `'MM-DD'`. */
|
|
13
|
+
export declare function toMonthDay(month: number, day: number): MonthDay;
|
|
14
|
+
/**
|
|
15
|
+
* Shows a month and day ("Mar 14", or "14 March" in `en-GB` with
|
|
16
|
+
* `{ month: 'long', day: 'numeric' }`) in the locale's order, never a
|
|
17
|
+
* year or a weekday. `''` and anything that isn't a real `'MM-DD'` give `''`.
|
|
18
|
+
*/
|
|
19
|
+
export declare function formatMonthDay(value: MonthDay, options?: Pick<Intl.DateTimeFormatOptions, 'month' | 'day'>, locale?: string): string;
|
|
20
|
+
/** A month's name ("March", or "Mar" with `'short'`), for a month 1–12. */
|
|
21
|
+
export declare function monthName(month: number, style?: 'long' | 'short', locale?: string): string;
|
|
22
|
+
/**
|
|
23
|
+
* Why a value isn't a day of the year, or null when it is (or is `''`):
|
|
24
|
+
* "February has 29 days" for `'02-30'`, "Pick a month and day" for
|
|
25
|
+
* anything not `'MM-DD'`.
|
|
26
|
+
*/
|
|
27
|
+
export declare function monthDayProblem(value: MonthDay, locale?: string): string | null;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// A month and day with no year: something that comes round every year (a
|
|
2
|
+
// season's start, a yearly deadline). The value is `'MM-DD'` (`'03-14'`),
|
|
3
|
+
// or `''` for not set, so it sorts as text in calendar order. February 29
|
|
4
|
+
// is a day like any other (it comes round in leap years); February 30,
|
|
5
|
+
// April 31 and `13-01` are not days. MonthDayField edits one.
|
|
6
|
+
const MONTH_DAY = /^(\d{2})-(\d{2})$/;
|
|
7
|
+
// Days in each month of a leap year: February has its 29th.
|
|
8
|
+
const DAYS_IN_MONTH = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
|
|
9
|
+
/** How many days the month (1–12) can have: February's 29 counted. */
|
|
10
|
+
export function daysInMonth(month) {
|
|
11
|
+
return DAYS_IN_MONTH[month - 1] ?? 0;
|
|
12
|
+
}
|
|
13
|
+
/** The month (1–12) and day of a real `'MM-DD'`, or null for anything else (`''`, `'02-30'`, `'3-14'`). */
|
|
14
|
+
export function monthDayParts(value) {
|
|
15
|
+
const match = MONTH_DAY.exec(value);
|
|
16
|
+
if (!match)
|
|
17
|
+
return null;
|
|
18
|
+
const [month, day] = [Number(match[1]), Number(match[2])];
|
|
19
|
+
if (month < 1 || month > 12 || day < 1 || day > daysInMonth(month))
|
|
20
|
+
return null;
|
|
21
|
+
return { month, day };
|
|
22
|
+
}
|
|
23
|
+
/** Whether the value is a real day of the year as `'MM-DD'`: `'02-29'` is, `'02-30'` isn't. */
|
|
24
|
+
export function isMonthDay(value) {
|
|
25
|
+
return monthDayParts(value) !== null;
|
|
26
|
+
}
|
|
27
|
+
/** The month (1–12) and day as `'MM-DD'`. */
|
|
28
|
+
export function toMonthDay(month, day) {
|
|
29
|
+
return `${String(month).padStart(2, '0')}-${String(day).padStart(2, '0')}`;
|
|
30
|
+
}
|
|
31
|
+
// A leap year, so February 29 formats; the year is never shown.
|
|
32
|
+
const LEAP_YEAR = 2000;
|
|
33
|
+
/**
|
|
34
|
+
* Shows a month and day ("Mar 14", or "14 March" in `en-GB` with
|
|
35
|
+
* `{ month: 'long', day: 'numeric' }`) in the locale's order, never a
|
|
36
|
+
* year or a weekday. `''` and anything that isn't a real `'MM-DD'` give `''`.
|
|
37
|
+
*/
|
|
38
|
+
export function formatMonthDay(value, options = { month: 'short', day: 'numeric' }, locale) {
|
|
39
|
+
const parts = monthDayParts(value);
|
|
40
|
+
if (!parts)
|
|
41
|
+
return '';
|
|
42
|
+
const { month = 'short', day = 'numeric' } = options;
|
|
43
|
+
return new Intl.DateTimeFormat(locale, { month, day, timeZone: 'UTC' }).format(Date.UTC(LEAP_YEAR, parts.month - 1, parts.day));
|
|
44
|
+
}
|
|
45
|
+
/** A month's name ("March", or "Mar" with `'short'`), for a month 1–12. */
|
|
46
|
+
export function monthName(month, style = 'long', locale) {
|
|
47
|
+
return new Intl.DateTimeFormat(locale, { month: style, timeZone: 'UTC' }).format(Date.UTC(LEAP_YEAR, month - 1, 1));
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Why a value isn't a day of the year, or null when it is (or is `''`):
|
|
51
|
+
* "February has 29 days" for `'02-30'`, "Pick a month and day" for
|
|
52
|
+
* anything not `'MM-DD'`.
|
|
53
|
+
*/
|
|
54
|
+
export function monthDayProblem(value, locale) {
|
|
55
|
+
if (value === '' || isMonthDay(value))
|
|
56
|
+
return null;
|
|
57
|
+
const match = MONTH_DAY.exec(value);
|
|
58
|
+
const [month, day] = match ? [Number(match[1]), Number(match[2])] : [0, 0];
|
|
59
|
+
if (month >= 1 && month <= 12 && day > daysInMonth(month))
|
|
60
|
+
return `${monthName(month, 'long', locale)} has ${daysInMonth(month)} days`;
|
|
61
|
+
return 'Pick a month and day';
|
|
62
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tristan2828/ui-foundation",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.78.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": {
|