@tristan2828/ui-foundation 4.87.0 → 4.89.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 +38 -23
- package/conventions/docs/cell-patterns.md +49 -24
- package/conventions/docs/design-language.md +97 -31
- 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.js +5 -1
- 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/overview-page.d.ts +44 -0
- package/dist/components/app/overview-page.js +63 -0
- package/dist/components/app/reference-combobox.d.ts +37 -0
- package/dist/components/app/reference-combobox.js +96 -0
- package/dist/components/app/widget-card.d.ts +15 -2
- package/dist/components/app/widget-card.js +15 -4
- package/dist/components/ui/field.d.ts +2 -2
- package/dist/components/ui/field.js +2 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.js +5 -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/package.json +1 -1
|
@@ -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
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tristan2828/ui-foundation",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.89.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": {
|