@tristan2828/ui-foundation 4.85.0 → 4.87.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 +34 -17
- package/conventions/docs/cell-patterns.md +165 -37
- package/conventions/docs/design-language.md +30 -3
- package/dist/components/app/app-shell-nav.d.ts +24 -0
- package/dist/components/app/app-shell-nav.js +30 -0
- package/dist/components/app/app-shell.d.ts +12 -1
- package/dist/components/app/app-shell.js +19 -5
- package/dist/components/app/data-table-tools.d.ts +98 -0
- package/dist/components/app/data-table-tools.js +59 -0
- package/dist/components/app/data-table.d.ts +60 -2
- package/dist/components/app/data-table.js +97 -20
- package/dist/components/app/entity-view.d.ts +11 -1
- package/dist/components/app/entity-view.js +14 -1
- package/dist/components/app/filter-bar.d.ts +55 -0
- package/dist/components/app/filter-bar.js +28 -0
- package/dist/components/app/multi-choice.d.ts +9 -1
- package/dist/components/app/multi-choice.js +3 -3
- package/dist/components/app/page-trail-context.d.ts +18 -0
- package/dist/components/app/page-trail-context.js +28 -0
- package/dist/components/app/page-trail.d.ts +1 -1
- package/dist/components/app/page-trail.js +1 -1
- package/dist/components/app/pill-filter.d.ts +3 -1
- package/dist/components/app/pill-filter.js +3 -2
- package/dist/components/app/related-table.d.ts +11 -0
- package/dist/components/app/related-table.js +28 -0
- package/dist/components/app/search-palette.d.ts +29 -0
- package/dist/components/app/search-palette.js +160 -0
- package/dist/components/app/secondary-filters.d.ts +3 -1
- package/dist/components/app/secondary-filters.js +5 -4
- package/dist/components/app/table-columns.d.ts +15 -0
- package/dist/components/app/table-columns.js +50 -0
- package/dist/hooks/table-url-changes.d.ts +2 -0
- package/dist/hooks/use-columns-pick.d.ts +3 -0
- package/dist/hooks/use-columns-pick.js +18 -0
- package/dist/hooks/use-is-phone.d.ts +1 -0
- package/dist/hooks/use-is-phone.js +18 -0
- package/dist/hooks/use-recent-record.d.ts +10 -0
- package/dist/hooks/use-recent-record.js +20 -0
- package/dist/index.d.ts +6 -1
- package/dist/index.js +5 -0
- package/dist/lib/search-palette.d.ts +50 -0
- package/dist/lib/search-palette.js +119 -0
- package/package.json +1 -1
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { type NavEntry } from '../components/app/app-shell-nav.js';
|
|
2
|
+
/**
|
|
3
|
+
* One record the app's `findRecords` found: its title, the page it opens
|
|
4
|
+
* (`to`, through the router), the heading it's listed under (`kind`,
|
|
5
|
+
* "Exercises"; "Records" without one), and a grey word beside it
|
|
6
|
+
* (`detail`, the module it's in, say).
|
|
7
|
+
*/
|
|
8
|
+
export type SearchRecord = {
|
|
9
|
+
title: string;
|
|
10
|
+
to: string;
|
|
11
|
+
kind?: string;
|
|
12
|
+
detail?: string;
|
|
13
|
+
};
|
|
14
|
+
/** A record opened lately (`useRecentRecord`), as the palette lists it before you type. */
|
|
15
|
+
export type RecentRecord = {
|
|
16
|
+
title: string;
|
|
17
|
+
to: string;
|
|
18
|
+
/** A grey word beside it, as a found record's `detail`. */
|
|
19
|
+
detail?: string;
|
|
20
|
+
};
|
|
21
|
+
/** A nav page as the palette lists it: "Finance · Accounts" for a module's own page. */
|
|
22
|
+
export type SearchPage = {
|
|
23
|
+
label: string;
|
|
24
|
+
name: string;
|
|
25
|
+
to: string;
|
|
26
|
+
};
|
|
27
|
+
/** Every page in the nav, each once, a module's own pages named with their module. */
|
|
28
|
+
export declare function searchPages(nav: readonly NavEntry[]): SearchPage[];
|
|
29
|
+
/**
|
|
30
|
+
* The pages whose name (or module and name) has the text in it, the
|
|
31
|
+
* closest first, then the nav's order; at most `limit`. No text: the
|
|
32
|
+
* first `limit` pages.
|
|
33
|
+
*/
|
|
34
|
+
export declare function matchPages(pages: readonly SearchPage[], query: string, limit: number): SearchPage[];
|
|
35
|
+
/** The records under their kinds, each kind once, in the order its first record came. */
|
|
36
|
+
export declare function groupRecords(records: readonly SearchRecord[]): {
|
|
37
|
+
kind: string;
|
|
38
|
+
records: SearchRecord[];
|
|
39
|
+
}[];
|
|
40
|
+
export declare const RECENT_RECORDS_KEY = "ui-foundation:recent-records";
|
|
41
|
+
/** How many are kept; the palette shows its `recent` of them. */
|
|
42
|
+
export declare const RECENT_RECORDS_KEPT = 20;
|
|
43
|
+
type StorageLike = Pick<Storage, 'getItem' | 'setItem' | 'removeItem'>;
|
|
44
|
+
/** The records opened lately, the latest first. Nothing when storage is missing or holds something else. */
|
|
45
|
+
export declare function readRecentRecords(store?: StorageLike | null): RecentRecord[];
|
|
46
|
+
/** Puts a record first among the recent ones (once, by its `to`), keeping the latest RECENT_RECORDS_KEPT. */
|
|
47
|
+
export declare function rememberRecentRecord(record: RecentRecord, store?: StorageLike | null): void;
|
|
48
|
+
/** Forgets every recent record (AppShell does on logout, so the next person doesn't see them). */
|
|
49
|
+
export declare function clearRecentRecords(store?: StorageLike | null): void;
|
|
50
|
+
export {};
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
// The search palette's logic (src/components/app/search-palette.tsx,
|
|
2
|
+
// AppShell's `search`, #N6): the nav's pages filtered by name, the app's
|
|
3
|
+
// records grouped by kind, and the records opened lately, remembered on
|
|
4
|
+
// the device. Pure, apart from the storage the recent records are kept in.
|
|
5
|
+
import { childItems, isNavSection } from '../components/app/app-shell-nav.js';
|
|
6
|
+
/** Every page in the nav, each once, a module's own pages named with their module. */
|
|
7
|
+
export function searchPages(nav) {
|
|
8
|
+
const seen = new Set();
|
|
9
|
+
const pages = [];
|
|
10
|
+
const add = (page) => {
|
|
11
|
+
if (seen.has(page.to))
|
|
12
|
+
return;
|
|
13
|
+
seen.add(page.to);
|
|
14
|
+
pages.push(page);
|
|
15
|
+
};
|
|
16
|
+
for (const entry of nav) {
|
|
17
|
+
for (const item of isNavSection(entry) ? entry.items : [entry]) {
|
|
18
|
+
add({ label: item.label, name: item.label, to: item.to });
|
|
19
|
+
for (const child of childItems(item))
|
|
20
|
+
add({ label: `${item.label} · ${child.label}`, name: child.label, to: child.to });
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return pages;
|
|
24
|
+
}
|
|
25
|
+
// How close a name is to the text: the whole name, then a name starting
|
|
26
|
+
// with it, then a word starting with it, then anywhere. -1 is no match.
|
|
27
|
+
function closeness(name, text) {
|
|
28
|
+
const lower = name.toLowerCase();
|
|
29
|
+
if (lower === text)
|
|
30
|
+
return 0;
|
|
31
|
+
if (lower.startsWith(text))
|
|
32
|
+
return 1;
|
|
33
|
+
if (lower.split(/[\s·/-]+/).some((word) => word.startsWith(text)))
|
|
34
|
+
return 2;
|
|
35
|
+
return lower.includes(text) ? 3 : -1;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* The pages whose name (or module and name) has the text in it, the
|
|
39
|
+
* closest first, then the nav's order; at most `limit`. No text: the
|
|
40
|
+
* first `limit` pages.
|
|
41
|
+
*/
|
|
42
|
+
export function matchPages(pages, query, limit) {
|
|
43
|
+
const text = query.trim().toLowerCase();
|
|
44
|
+
if (!text)
|
|
45
|
+
return pages.slice(0, limit);
|
|
46
|
+
return pages
|
|
47
|
+
.map((page, index) => {
|
|
48
|
+
const own = closeness(page.name, text);
|
|
49
|
+
const full = closeness(page.label, text);
|
|
50
|
+
// The page's own name counts first; its module's name next.
|
|
51
|
+
const score = own >= 0 ? own : full >= 0 ? full + 4 : -1;
|
|
52
|
+
return { page, index, score };
|
|
53
|
+
})
|
|
54
|
+
.filter((match) => match.score >= 0)
|
|
55
|
+
.sort((a, b) => a.score - b.score || a.index - b.index)
|
|
56
|
+
.slice(0, limit)
|
|
57
|
+
.map((match) => match.page);
|
|
58
|
+
}
|
|
59
|
+
/** The records under their kinds, each kind once, in the order its first record came. */
|
|
60
|
+
export function groupRecords(records) {
|
|
61
|
+
const groups = new Map();
|
|
62
|
+
for (const record of records) {
|
|
63
|
+
const kind = record.kind?.trim() || 'Records';
|
|
64
|
+
const group = groups.get(kind);
|
|
65
|
+
if (group)
|
|
66
|
+
group.push(record);
|
|
67
|
+
else
|
|
68
|
+
groups.set(kind, [record]);
|
|
69
|
+
}
|
|
70
|
+
return [...groups].map(([kind, list]) => ({ kind, records: list }));
|
|
71
|
+
}
|
|
72
|
+
// ---- The records opened lately, on this device ----
|
|
73
|
+
export const RECENT_RECORDS_KEY = 'ui-foundation:recent-records';
|
|
74
|
+
/** How many are kept; the palette shows its `recent` of them. */
|
|
75
|
+
export const RECENT_RECORDS_KEPT = 20;
|
|
76
|
+
function storage() {
|
|
77
|
+
try {
|
|
78
|
+
return window.localStorage;
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
function isRecent(value) {
|
|
85
|
+
if (typeof value !== 'object' || value === null)
|
|
86
|
+
return false;
|
|
87
|
+
const { title, to, detail } = value;
|
|
88
|
+
return typeof title === 'string' && typeof to === 'string' && (detail === undefined || typeof detail === 'string');
|
|
89
|
+
}
|
|
90
|
+
/** The records opened lately, the latest first. Nothing when storage is missing or holds something else. */
|
|
91
|
+
export function readRecentRecords(store = storage()) {
|
|
92
|
+
try {
|
|
93
|
+
const parsed = JSON.parse(store?.getItem(RECENT_RECORDS_KEY) ?? '[]');
|
|
94
|
+
return Array.isArray(parsed) ? parsed.filter(isRecent) : [];
|
|
95
|
+
}
|
|
96
|
+
catch {
|
|
97
|
+
return [];
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
/** Puts a record first among the recent ones (once, by its `to`), keeping the latest RECENT_RECORDS_KEPT. */
|
|
101
|
+
export function rememberRecentRecord(record, store = storage()) {
|
|
102
|
+
const entry = { title: record.title, to: record.to, ...(record.detail ? { detail: record.detail } : {}) };
|
|
103
|
+
const next = [entry, ...readRecentRecords(store).filter((other) => other.to !== record.to)].slice(0, RECENT_RECORDS_KEPT);
|
|
104
|
+
try {
|
|
105
|
+
store?.setItem(RECENT_RECORDS_KEY, JSON.stringify(next));
|
|
106
|
+
}
|
|
107
|
+
catch {
|
|
108
|
+
// Not remembered: storage is full or refused (a private window).
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
/** Forgets every recent record (AppShell does on logout, so the next person doesn't see them). */
|
|
112
|
+
export function clearRecentRecords(store = storage()) {
|
|
113
|
+
try {
|
|
114
|
+
store?.removeItem(RECENT_RECORDS_KEY);
|
|
115
|
+
}
|
|
116
|
+
catch {
|
|
117
|
+
// Nothing to forget.
|
|
118
|
+
}
|
|
119
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tristan2828/ui-foundation",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.87.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": {
|