@faast-app/ui 0.0.0-stage → 0.7.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 +13 -2
- package/dist/components/Alert.d.ts +30 -0
- package/dist/components/Alert.js +19 -0
- package/dist/components/AppShell.d.ts +63 -0
- package/dist/components/AppShell.js +80 -0
- package/dist/components/Avatar.d.ts +18 -0
- package/dist/components/Avatar.js +21 -0
- package/dist/components/Badge.d.ts +24 -0
- package/dist/components/Badge.js +10 -0
- package/dist/components/Button.d.ts +71 -0
- package/dist/components/Button.js +40 -0
- package/dist/components/Card.d.ts +23 -0
- package/dist/components/Card.js +17 -0
- package/dist/components/Chip.d.ts +16 -0
- package/dist/components/Chip.js +9 -0
- package/dist/components/Choice.d.ts +38 -0
- package/dist/components/Choice.js +53 -0
- package/dist/components/Dialog.d.ts +44 -0
- package/dist/components/Dialog.js +51 -0
- package/dist/components/EmptyState.d.ts +16 -0
- package/dist/components/EmptyState.js +8 -0
- package/dist/components/FileDropArea.d.ts +62 -0
- package/dist/components/FileDropArea.js +90 -0
- package/dist/components/FormField.d.ts +35 -0
- package/dist/components/FormField.js +32 -0
- package/dist/components/HelpMenu.d.ts +46 -0
- package/dist/components/HelpMenu.js +104 -0
- package/dist/components/Icon.d.ts +24 -0
- package/dist/components/Icon.js +195 -0
- package/dist/components/Input.d.ts +37 -0
- package/dist/components/Input.js +31 -0
- package/dist/components/KpiStrip.d.ts +32 -0
- package/dist/components/KpiStrip.js +14 -0
- package/dist/components/LockScreen.d.ts +34 -0
- package/dist/components/LockScreen.js +22 -0
- package/dist/components/Logo.d.ts +27 -0
- package/dist/components/Logo.js +12 -0
- package/dist/components/Navigation.d.ts +37 -0
- package/dist/components/Navigation.js +29 -0
- package/dist/components/OptionList.d.ts +27 -0
- package/dist/components/OptionList.js +18 -0
- package/dist/components/OtpInput.d.ts +31 -0
- package/dist/components/OtpInput.js +102 -0
- package/dist/components/Pagination.d.ts +31 -0
- package/dist/components/Pagination.js +41 -0
- package/dist/components/PasswordField.d.ts +32 -0
- package/dist/components/PasswordField.js +29 -0
- package/dist/components/SegmentedControl.d.ts +35 -0
- package/dist/components/SegmentedControl.js +52 -0
- package/dist/components/Select.d.ts +15 -0
- package/dist/components/Select.js +10 -0
- package/dist/components/SessionTimeoutDialog.d.ts +39 -0
- package/dist/components/SessionTimeoutDialog.js +62 -0
- package/dist/components/Spinner.d.ts +25 -0
- package/dist/components/Spinner.js +15 -0
- package/dist/components/StatTiles.d.ts +35 -0
- package/dist/components/StatTiles.js +12 -0
- package/dist/components/Stepper.d.ts +26 -0
- package/dist/components/Stepper.js +26 -0
- package/dist/components/StickyActionBar.d.ts +28 -0
- package/dist/components/StickyActionBar.js +12 -0
- package/dist/components/Table.d.ts +69 -0
- package/dist/components/Table.js +73 -0
- package/dist/components/TenantMark.d.ts +27 -0
- package/dist/components/TenantMark.js +15 -0
- package/dist/components/Timeline.d.ts +31 -0
- package/dist/components/Timeline.js +18 -0
- package/dist/components/Toast.d.ts +43 -0
- package/dist/components/Toast.js +46 -0
- package/dist/components/Toggletip.d.ts +26 -0
- package/dist/components/Toggletip.js +47 -0
- package/dist/components/Tooltip.d.ts +24 -0
- package/dist/components/Tooltip.js +73 -0
- package/dist/components/Tour.d.ts +66 -0
- package/dist/components/Tour.js +161 -0
- package/dist/components/TourOffer.d.ts +22 -0
- package/dist/components/TourOffer.js +33 -0
- package/dist/components/WelcomeDialog.d.ts +45 -0
- package/dist/components/WelcomeDialog.js +38 -0
- package/dist/data-table/components/ClientDataTable.d.ts +22 -0
- package/dist/data-table/components/ClientDataTable.js +29 -0
- package/dist/data-table/components/DataTableFooter.d.ts +11 -0
- package/dist/data-table/components/DataTableFooter.js +16 -0
- package/dist/data-table/components/DataTableView.d.ts +9 -0
- package/dist/data-table/components/DataTableView.js +95 -0
- package/dist/data-table/components/ServerDataTable.d.ts +16 -0
- package/dist/data-table/components/ServerDataTable.js +17 -0
- package/dist/data-table/core/columnVisibility.d.ts +15 -0
- package/dist/data-table/core/columnVisibility.js +34 -0
- package/dist/data-table/core/constants.d.ts +20 -0
- package/dist/data-table/core/constants.js +21 -0
- package/dist/data-table/core/filters/registry.d.ts +33 -0
- package/dist/data-table/core/filters/registry.js +393 -0
- package/dist/data-table/core/filters/types.d.ts +88 -0
- package/dist/data-table/core/filters/types.js +1 -0
- package/dist/data-table/core/group.d.ts +15 -0
- package/dist/data-table/core/group.js +73 -0
- package/dist/data-table/core/paginate.d.ts +13 -0
- package/dist/data-table/core/paginate.js +27 -0
- package/dist/data-table/core/query.d.ts +65 -0
- package/dist/data-table/core/query.js +138 -0
- package/dist/data-table/core/search.d.ts +10 -0
- package/dist/data-table/core/search.js +35 -0
- package/dist/data-table/core/selection.d.ts +24 -0
- package/dist/data-table/core/selection.js +59 -0
- package/dist/data-table/core/sort.d.ts +14 -0
- package/dist/data-table/core/sort.js +41 -0
- package/dist/data-table/core/text.d.ts +5 -0
- package/dist/data-table/core/text.js +27 -0
- package/dist/data-table/core/types.d.ts +40 -0
- package/dist/data-table/core/types.js +1 -0
- package/dist/data-table/core/url.d.ts +43 -0
- package/dist/data-table/core/url.js +194 -0
- package/dist/data-table/hooks/common.d.ts +14 -0
- package/dist/data-table/hooks/common.js +30 -0
- package/dist/data-table/hooks/small-hooks.d.ts +12 -0
- package/dist/data-table/hooks/small-hooks.js +111 -0
- package/dist/data-table/hooks/useClientDataTable.d.ts +35 -0
- package/dist/data-table/hooks/useClientDataTable.js +311 -0
- package/dist/data-table/hooks/useServerDataTable.d.ts +38 -0
- package/dist/data-table/hooks/useServerDataTable.js +209 -0
- package/dist/data-table/hooks/useServerRows.d.ts +27 -0
- package/dist/data-table/hooks/useServerRows.js +82 -0
- package/dist/data-table/hooks/useTableState.d.ts +39 -0
- package/dist/data-table/hooks/useTableState.js +219 -0
- package/dist/data-table/index.d.ts +42 -0
- package/dist/data-table/index.js +22 -0
- package/dist/data-table/labels.d.ts +77 -0
- package/dist/data-table/labels.js +77 -0
- package/dist/data-table/toolbar/ActiveFilters.d.ts +10 -0
- package/dist/data-table/toolbar/ActiveFilters.js +53 -0
- package/dist/data-table/toolbar/BulkActionBar.d.ts +15 -0
- package/dist/data-table/toolbar/BulkActionBar.js +22 -0
- package/dist/data-table/toolbar/ColumnVisibilityDialog.d.ts +7 -0
- package/dist/data-table/toolbar/ColumnVisibilityDialog.js +15 -0
- package/dist/data-table/toolbar/DataTableToolbar.d.ts +19 -0
- package/dist/data-table/toolbar/DataTableToolbar.js +12 -0
- package/dist/data-table/toolbar/FilterFields.d.ts +11 -0
- package/dist/data-table/toolbar/FilterFields.js +58 -0
- package/dist/data-table/toolbar/FiltersControl.d.ts +34 -0
- package/dist/data-table/toolbar/FiltersControl.js +70 -0
- package/dist/data-table/toolbar/PageSizeSelect.d.ts +7 -0
- package/dist/data-table/toolbar/PageSizeSelect.js +12 -0
- package/dist/data-table/toolbar/QuickFilters.d.ts +7 -0
- package/dist/data-table/toolbar/QuickFilters.js +9 -0
- package/dist/data-table/toolbar/ResultsCount.d.ts +7 -0
- package/dist/data-table/toolbar/ResultsCount.js +9 -0
- package/dist/data-table/toolbar/SearchField.d.ts +36 -0
- package/dist/data-table/toolbar/SearchField.js +64 -0
- package/dist/data-table/toolbar/SortSelect.d.ts +10 -0
- package/dist/data-table/toolbar/SortSelect.js +30 -0
- package/dist/data-table/types.d.ts +334 -0
- package/dist/data-table/types.js +1 -0
- package/dist/index.d.ts +91 -0
- package/dist/index.js +49 -0
- package/dist/styles.css +4668 -0
- package/dist/theme/ThemeProvider.d.ts +33 -0
- package/dist/theme/ThemeProvider.js +77 -0
- package/dist/theme/ThemeToggle.d.ts +16 -0
- package/dist/theme/ThemeToggle.js +27 -0
- package/dist/utils/cx.d.ts +2 -0
- package/dist/utils/cx.js +4 -0
- package/dist/utils/devWarn.d.ts +2 -0
- package/dist/utils/devWarn.js +10 -0
- package/dist/utils/tourGeometry.d.ts +61 -0
- package/dist/utils/tourGeometry.js +135 -0
- package/dist/utils/useFloatingPosition.d.ts +9 -0
- package/dist/utils/useFloatingPosition.js +45 -0
- package/dist/utils/useModalDialog.d.ts +7 -0
- package/dist/utils/useModalDialog.js +49 -0
- package/dist/utils/useTourAnchorRect.d.ts +6 -0
- package/dist/utils/useTourAnchorRect.js +40 -0
- package/package.json +50 -4
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { type PageSize } from './constants.js';
|
|
2
|
+
import type { FilterValues, QueryChangeMeta, SortDirection, SortState, TableQuery } from './types.js';
|
|
3
|
+
/** Filter values live in prototype-less objects so ids like `__proto__` are plain keys. */
|
|
4
|
+
export declare function emptyFilterValues(entries?: Iterable<readonly [string, unknown]>): FilterValues;
|
|
5
|
+
export declare function createDefaultQuery(partial?: Partial<TableQuery>): TableQuery;
|
|
6
|
+
/**
|
|
7
|
+
* Makes an externally supplied (controlled) query safe: a page size outside the allowed list
|
|
8
|
+
* falls back to the default (or the first allowed size) and a page that is not a positive
|
|
9
|
+
* integer becomes 1. Returns the same object when nothing needs fixing.
|
|
10
|
+
*/
|
|
11
|
+
export declare function normalizeQuery(query: TableQuery, allowedSizes?: readonly PageSize[]): {
|
|
12
|
+
query: TableQuery;
|
|
13
|
+
fixed: boolean;
|
|
14
|
+
};
|
|
15
|
+
export type QueryAction = {
|
|
16
|
+
type: 'search';
|
|
17
|
+
value: string;
|
|
18
|
+
} | {
|
|
19
|
+
type: 'filters';
|
|
20
|
+
value: FilterValues;
|
|
21
|
+
} | {
|
|
22
|
+
type: 'quickFilter';
|
|
23
|
+
value: string;
|
|
24
|
+
} | {
|
|
25
|
+
type: 'sort';
|
|
26
|
+
value: SortState | null;
|
|
27
|
+
} | {
|
|
28
|
+
type: 'page';
|
|
29
|
+
value: number;
|
|
30
|
+
} | {
|
|
31
|
+
type: 'pageSize';
|
|
32
|
+
value: PageSize;
|
|
33
|
+
} | {
|
|
34
|
+
type: 'group';
|
|
35
|
+
value: string | null;
|
|
36
|
+
}
|
|
37
|
+
/** Clears search, filters and quick filter. */
|
|
38
|
+
| {
|
|
39
|
+
type: 'reset';
|
|
40
|
+
}
|
|
41
|
+
/** Clears only the filter fields (search and quick filter stay). */
|
|
42
|
+
| {
|
|
43
|
+
type: 'clearFilters';
|
|
44
|
+
}
|
|
45
|
+
/** Moves `page` down into range; never up. */
|
|
46
|
+
| {
|
|
47
|
+
type: 'clamp';
|
|
48
|
+
pageCount: number;
|
|
49
|
+
};
|
|
50
|
+
export interface QueryResult {
|
|
51
|
+
query: TableQuery;
|
|
52
|
+
meta: QueryChangeMeta;
|
|
53
|
+
changed: boolean;
|
|
54
|
+
}
|
|
55
|
+
export declare function sortEquals(a: SortState | null, b: SortState | null): boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Single source of the reset-to-page-1 and history rules (plan section 5.2). Pure; returns
|
|
58
|
+
* the same `query` reference when nothing changes.
|
|
59
|
+
*/
|
|
60
|
+
export declare function reduceQuery(query: TableQuery, action: QueryAction): QueryResult;
|
|
61
|
+
/** ascending -> descending -> back to the default sort. */
|
|
62
|
+
export declare function nextSort(current: SortState | null, columnId: string, fallback: SortState | null): SortState | null;
|
|
63
|
+
export declare function sortDirectionOf(sort: SortState | null, columnId: string): SortDirection | 'none';
|
|
64
|
+
/** Stable string identity of a query (equal queries give equal keys). */
|
|
65
|
+
export declare function queryKey(query: TableQuery): string;
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { ALL_QUICK_FILTER, DEFAULT_PAGE_SIZE, PAGE_SIZE_OPTIONS, isPageSize, } from './constants.js';
|
|
2
|
+
import { clampPage } from './paginate.js';
|
|
3
|
+
import { sanitizeSearch } from './text.js';
|
|
4
|
+
/** Filter values live in prototype-less objects so ids like `__proto__` are plain keys. */
|
|
5
|
+
export function emptyFilterValues(entries) {
|
|
6
|
+
const values = Object.create(null);
|
|
7
|
+
if (entries)
|
|
8
|
+
for (const [key, value] of entries)
|
|
9
|
+
values[key] = value;
|
|
10
|
+
return values;
|
|
11
|
+
}
|
|
12
|
+
export function createDefaultQuery(partial = {}) {
|
|
13
|
+
return {
|
|
14
|
+
search: sanitizeSearch(partial.search ?? ''),
|
|
15
|
+
filters: partial.filters ?? emptyFilterValues(),
|
|
16
|
+
quickFilter: partial.quickFilter ?? ALL_QUICK_FILTER,
|
|
17
|
+
sort: partial.sort ?? null,
|
|
18
|
+
groupBy: partial.groupBy ?? null,
|
|
19
|
+
page: partial.page && Number.isInteger(partial.page) && partial.page >= 1 ? partial.page : 1,
|
|
20
|
+
pageSize: partial.pageSize && isPageSize(partial.pageSize) ? partial.pageSize : DEFAULT_PAGE_SIZE,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Makes an externally supplied (controlled) query safe: a page size outside the allowed list
|
|
25
|
+
* falls back to the default (or the first allowed size) and a page that is not a positive
|
|
26
|
+
* integer becomes 1. Returns the same object when nothing needs fixing.
|
|
27
|
+
*/
|
|
28
|
+
export function normalizeQuery(query, allowedSizes = PAGE_SIZE_OPTIONS) {
|
|
29
|
+
const sizeOk = isPageSize(query.pageSize) && allowedSizes.includes(query.pageSize);
|
|
30
|
+
const pageOk = Number.isInteger(query.page) && query.page >= 1;
|
|
31
|
+
if (sizeOk && pageOk)
|
|
32
|
+
return { query, fixed: false };
|
|
33
|
+
const fallback = allowedSizes.includes(DEFAULT_PAGE_SIZE)
|
|
34
|
+
? DEFAULT_PAGE_SIZE
|
|
35
|
+
: (allowedSizes[0] ?? DEFAULT_PAGE_SIZE);
|
|
36
|
+
return {
|
|
37
|
+
query: {
|
|
38
|
+
...query,
|
|
39
|
+
pageSize: sizeOk ? query.pageSize : fallback,
|
|
40
|
+
page: pageOk ? query.page : 1,
|
|
41
|
+
},
|
|
42
|
+
fixed: true,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
export function sortEquals(a, b) {
|
|
46
|
+
if (a === b)
|
|
47
|
+
return true;
|
|
48
|
+
if (!a || !b)
|
|
49
|
+
return false;
|
|
50
|
+
return a.columnId === b.columnId && a.direction === b.direction;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Single source of the reset-to-page-1 and history rules (plan section 5.2). Pure; returns
|
|
54
|
+
* the same `query` reference when nothing changes.
|
|
55
|
+
*/
|
|
56
|
+
export function reduceQuery(query, action) {
|
|
57
|
+
const same = (reason, history) => ({
|
|
58
|
+
query,
|
|
59
|
+
meta: { reason, history },
|
|
60
|
+
changed: false,
|
|
61
|
+
});
|
|
62
|
+
const next = (value, reason, history) => ({ query: value, meta: { reason, history }, changed: true });
|
|
63
|
+
switch (action.type) {
|
|
64
|
+
case 'search': {
|
|
65
|
+
const search = sanitizeSearch(action.value);
|
|
66
|
+
if (search === query.search)
|
|
67
|
+
return same('search', 'replace');
|
|
68
|
+
return next({ ...query, search, page: 1 }, 'search', 'replace');
|
|
69
|
+
}
|
|
70
|
+
case 'filters':
|
|
71
|
+
return next({ ...query, filters: action.value, page: 1 }, 'filters', 'push');
|
|
72
|
+
case 'quickFilter':
|
|
73
|
+
if (action.value === query.quickFilter)
|
|
74
|
+
return same('quickFilter', 'push');
|
|
75
|
+
return next({ ...query, quickFilter: action.value, page: 1 }, 'quickFilter', 'push');
|
|
76
|
+
case 'sort':
|
|
77
|
+
if (sortEquals(action.value, query.sort))
|
|
78
|
+
return same('sort', 'push');
|
|
79
|
+
return next({ ...query, sort: action.value, page: 1 }, 'sort', 'push');
|
|
80
|
+
case 'page': {
|
|
81
|
+
const page = Number.isInteger(action.value) && action.value >= 1 ? action.value : 1;
|
|
82
|
+
if (page === query.page)
|
|
83
|
+
return same('page', 'push');
|
|
84
|
+
return next({ ...query, page }, 'page', 'push');
|
|
85
|
+
}
|
|
86
|
+
case 'pageSize':
|
|
87
|
+
if (!isPageSize(action.value) || action.value === query.pageSize) {
|
|
88
|
+
return same('pageSize', 'push');
|
|
89
|
+
}
|
|
90
|
+
return next({ ...query, pageSize: action.value, page: 1 }, 'pageSize', 'push');
|
|
91
|
+
case 'group':
|
|
92
|
+
if (action.value === query.groupBy)
|
|
93
|
+
return same('group', 'push');
|
|
94
|
+
return next({ ...query, groupBy: action.value, page: 1 }, 'group', 'push');
|
|
95
|
+
case 'reset':
|
|
96
|
+
return next({
|
|
97
|
+
...query,
|
|
98
|
+
search: '',
|
|
99
|
+
filters: emptyFilterValues(),
|
|
100
|
+
quickFilter: ALL_QUICK_FILTER,
|
|
101
|
+
page: 1,
|
|
102
|
+
}, 'reset', 'push');
|
|
103
|
+
case 'clearFilters':
|
|
104
|
+
return next({ ...query, filters: emptyFilterValues(), page: 1 }, 'filters', 'push');
|
|
105
|
+
case 'clamp': {
|
|
106
|
+
const page = clampPage(query.page, action.pageCount);
|
|
107
|
+
if (page >= query.page)
|
|
108
|
+
return same('clamp', 'replace');
|
|
109
|
+
return next({ ...query, page }, 'clamp', 'replace');
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
/** ascending -> descending -> back to the default sort. */
|
|
114
|
+
export function nextSort(current, columnId, fallback) {
|
|
115
|
+
if (!current || current.columnId !== columnId)
|
|
116
|
+
return { columnId, direction: 'ascending' };
|
|
117
|
+
if (current.direction === 'ascending')
|
|
118
|
+
return { columnId, direction: 'descending' };
|
|
119
|
+
return fallback && fallback.columnId !== columnId ? fallback : null;
|
|
120
|
+
}
|
|
121
|
+
export function sortDirectionOf(sort, columnId) {
|
|
122
|
+
return sort && sort.columnId === columnId ? sort.direction : 'none';
|
|
123
|
+
}
|
|
124
|
+
/** Stable string identity of a query (equal queries give equal keys). */
|
|
125
|
+
export function queryKey(query) {
|
|
126
|
+
const filters = Object.keys(query.filters)
|
|
127
|
+
.sort()
|
|
128
|
+
.map((id) => [id, query.filters[id]]);
|
|
129
|
+
return JSON.stringify([
|
|
130
|
+
query.search,
|
|
131
|
+
filters,
|
|
132
|
+
query.quickFilter,
|
|
133
|
+
query.sort,
|
|
134
|
+
query.groupBy,
|
|
135
|
+
query.page,
|
|
136
|
+
query.pageSize,
|
|
137
|
+
]);
|
|
138
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
type Accessor<TRow> = (row: TRow) => string | readonly string[];
|
|
2
|
+
/**
|
|
3
|
+
* Normalised search text of a row. Cached per (accessors, row) identity, so changing the
|
|
4
|
+
* search term never rebuilds it; primitives are computed without cache.
|
|
5
|
+
*/
|
|
6
|
+
export declare function buildSearchText<TRow>(row: TRow, accessors: readonly Accessor<TRow>[], cacheKey?: object): string;
|
|
7
|
+
export declare function searchTerms(search: string): string[];
|
|
8
|
+
/** Every term must appear in the row text (AND). No terms matches everything. */
|
|
9
|
+
export declare function matchesSearch(rowText: string, terms: readonly string[]): boolean;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { normalizeText } from './text.js';
|
|
2
|
+
const caches = new WeakMap();
|
|
3
|
+
/**
|
|
4
|
+
* Normalised search text of a row. Cached per (accessors, row) identity, so changing the
|
|
5
|
+
* search term never rebuilds it; primitives are computed without cache.
|
|
6
|
+
*/
|
|
7
|
+
export function buildSearchText(row, accessors, cacheKey) {
|
|
8
|
+
const compute = () => normalizeText(accessors
|
|
9
|
+
.flatMap((accessor) => {
|
|
10
|
+
const value = accessor(row);
|
|
11
|
+
return typeof value === 'string' ? [value] : [...value];
|
|
12
|
+
})
|
|
13
|
+
.join(' '));
|
|
14
|
+
if (!cacheKey || typeof row !== 'object' || row === null)
|
|
15
|
+
return compute();
|
|
16
|
+
let perRow = caches.get(cacheKey);
|
|
17
|
+
if (!perRow) {
|
|
18
|
+
perRow = new WeakMap();
|
|
19
|
+
caches.set(cacheKey, perRow);
|
|
20
|
+
}
|
|
21
|
+
const hit = perRow.get(row);
|
|
22
|
+
if (hit !== undefined)
|
|
23
|
+
return hit;
|
|
24
|
+
const text = compute();
|
|
25
|
+
perRow.set(row, text);
|
|
26
|
+
return text;
|
|
27
|
+
}
|
|
28
|
+
export function searchTerms(search) {
|
|
29
|
+
const text = normalizeText(search);
|
|
30
|
+
return text === '' ? [] : text.split(' ');
|
|
31
|
+
}
|
|
32
|
+
/** Every term must appear in the row text (AND). No terms matches everything. */
|
|
33
|
+
export function matchesSearch(rowText, terms) {
|
|
34
|
+
return terms.every((term) => rowText.includes(term));
|
|
35
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { RowId } from './types.js';
|
|
2
|
+
export type HeaderCheckState = 'none' | 'some' | 'all' | 'disabled';
|
|
3
|
+
export type RowSelectability = {
|
|
4
|
+
selectable: true;
|
|
5
|
+
} | {
|
|
6
|
+
selectable: false;
|
|
7
|
+
/** Full explanation: read as the description of the row checkbox. */
|
|
8
|
+
reason: string;
|
|
9
|
+
/** Compact label shown under the row header, with the full reason as a tooltip. */
|
|
10
|
+
shortReason?: string;
|
|
11
|
+
};
|
|
12
|
+
/** State of the header checkbox over a scope (client: all result rows; server: page rows). */
|
|
13
|
+
export declare function headerState(selected: ReadonlySet<RowId>, scopeIds: readonly RowId[]): HeaderCheckState;
|
|
14
|
+
/** Header click: everything selected -> remove exactly the scope; otherwise add the scope. */
|
|
15
|
+
export declare function toggleScope(selected: ReadonlySet<RowId>, scopeIds: readonly RowId[]): Set<string>;
|
|
16
|
+
export declare function selectScope(selected: ReadonlySet<RowId>, scopeIds: readonly RowId[]): Set<string>;
|
|
17
|
+
/** Drops ids that are not valid any more (row gone or no longer selectable). */
|
|
18
|
+
export declare function pruneSelection(selected: ReadonlySet<RowId>, validIds: ReadonlySet<RowId>): {
|
|
19
|
+
next: ReadonlySet<string>;
|
|
20
|
+
removed: number;
|
|
21
|
+
};
|
|
22
|
+
/** Selected ids that the current result does not show. */
|
|
23
|
+
export declare function hiddenSelectedCount(selected: ReadonlySet<RowId>, resultIds: ReadonlySet<RowId>): number;
|
|
24
|
+
export declare function setsEqual<T>(a: ReadonlySet<T>, b: ReadonlySet<T>): boolean;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/** State of the header checkbox over a scope (client: all result rows; server: page rows). */
|
|
2
|
+
export function headerState(selected, scopeIds) {
|
|
3
|
+
if (scopeIds.length === 0)
|
|
4
|
+
return 'disabled';
|
|
5
|
+
let count = 0;
|
|
6
|
+
for (const id of scopeIds)
|
|
7
|
+
if (selected.has(id))
|
|
8
|
+
count++;
|
|
9
|
+
if (count === 0)
|
|
10
|
+
return 'none';
|
|
11
|
+
return count === scopeIds.length ? 'all' : 'some';
|
|
12
|
+
}
|
|
13
|
+
/** Header click: everything selected -> remove exactly the scope; otherwise add the scope. */
|
|
14
|
+
export function toggleScope(selected, scopeIds) {
|
|
15
|
+
const next = new Set(selected);
|
|
16
|
+
if (headerState(selected, scopeIds) === 'all')
|
|
17
|
+
for (const id of scopeIds)
|
|
18
|
+
next.delete(id);
|
|
19
|
+
else
|
|
20
|
+
for (const id of scopeIds)
|
|
21
|
+
next.add(id);
|
|
22
|
+
return next;
|
|
23
|
+
}
|
|
24
|
+
export function selectScope(selected, scopeIds) {
|
|
25
|
+
const next = new Set(selected);
|
|
26
|
+
for (const id of scopeIds)
|
|
27
|
+
next.add(id);
|
|
28
|
+
return next;
|
|
29
|
+
}
|
|
30
|
+
/** Drops ids that are not valid any more (row gone or no longer selectable). */
|
|
31
|
+
export function pruneSelection(selected, validIds) {
|
|
32
|
+
let removed = 0;
|
|
33
|
+
const next = new Set();
|
|
34
|
+
for (const id of selected) {
|
|
35
|
+
if (validIds.has(id))
|
|
36
|
+
next.add(id);
|
|
37
|
+
else
|
|
38
|
+
removed++;
|
|
39
|
+
}
|
|
40
|
+
return { next: removed === 0 ? selected : next, removed };
|
|
41
|
+
}
|
|
42
|
+
/** Selected ids that the current result does not show. */
|
|
43
|
+
export function hiddenSelectedCount(selected, resultIds) {
|
|
44
|
+
let hidden = 0;
|
|
45
|
+
for (const id of selected)
|
|
46
|
+
if (!resultIds.has(id))
|
|
47
|
+
hidden++;
|
|
48
|
+
return hidden;
|
|
49
|
+
}
|
|
50
|
+
export function setsEqual(a, b) {
|
|
51
|
+
if (a === b)
|
|
52
|
+
return true;
|
|
53
|
+
if (a.size !== b.size)
|
|
54
|
+
return false;
|
|
55
|
+
for (const v of a)
|
|
56
|
+
if (!b.has(v))
|
|
57
|
+
return false;
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { SortDirection } from './types.js';
|
|
2
|
+
export type SortValue = string | number | null | undefined;
|
|
3
|
+
export interface SortSpec<TRow> {
|
|
4
|
+
value?: (row: TRow) => SortValue;
|
|
5
|
+
compare?: (a: TRow, b: TRow) => number;
|
|
6
|
+
}
|
|
7
|
+
export declare function createCollator(locale?: string): Intl.Collator;
|
|
8
|
+
/** Ascending comparison of two values. Callers handle empties first (always last). */
|
|
9
|
+
export declare function compareValues(a: string | number, b: string | number, collator: Intl.Collator): number;
|
|
10
|
+
/**
|
|
11
|
+
* Stable sort. Empty values (null, undefined, NaN) go last in both directions; ties keep the
|
|
12
|
+
* input order. Returns a new array; the input is never mutated.
|
|
13
|
+
*/
|
|
14
|
+
export declare function sortRows<TRow>(rows: readonly TRow[], spec: SortSpec<TRow>, direction: SortDirection, collator?: Intl.Collator): TRow[];
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export function createCollator(locale = 'es') {
|
|
2
|
+
return new Intl.Collator(locale, { numeric: true, sensitivity: 'base' });
|
|
3
|
+
}
|
|
4
|
+
const isEmptyValue = (v) => v === null || v === undefined || (typeof v === 'number' && Number.isNaN(v));
|
|
5
|
+
/** Ascending comparison of two values. Callers handle empties first (always last). */
|
|
6
|
+
export function compareValues(a, b, collator) {
|
|
7
|
+
if (typeof a === 'number' && typeof b === 'number')
|
|
8
|
+
return a - b;
|
|
9
|
+
return collator.compare(String(a), String(b));
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Stable sort. Empty values (null, undefined, NaN) go last in both directions; ties keep the
|
|
13
|
+
* input order. Returns a new array; the input is never mutated.
|
|
14
|
+
*/
|
|
15
|
+
export function sortRows(rows, spec, direction, collator = createCollator()) {
|
|
16
|
+
const sign = direction === 'descending' ? -1 : 1;
|
|
17
|
+
const { value, compare } = spec;
|
|
18
|
+
if (!value && !compare)
|
|
19
|
+
return [...rows];
|
|
20
|
+
const entries = rows.map((row, index) => ({
|
|
21
|
+
row,
|
|
22
|
+
index,
|
|
23
|
+
key: value ? value(row) : undefined,
|
|
24
|
+
}));
|
|
25
|
+
entries.sort((a, b) => {
|
|
26
|
+
if (compare) {
|
|
27
|
+
const result = compare(a.row, b.row) * sign;
|
|
28
|
+
return result !== 0 ? result : a.index - b.index;
|
|
29
|
+
}
|
|
30
|
+
const aEmpty = isEmptyValue(a.key);
|
|
31
|
+
const bEmpty = isEmptyValue(b.key);
|
|
32
|
+
if (aEmpty || bEmpty) {
|
|
33
|
+
if (aEmpty && bEmpty)
|
|
34
|
+
return a.index - b.index;
|
|
35
|
+
return aEmpty ? 1 : -1;
|
|
36
|
+
}
|
|
37
|
+
const result = compareValues(a.key, b.key, collator);
|
|
38
|
+
return result !== 0 ? result * sign : a.index - b.index;
|
|
39
|
+
});
|
|
40
|
+
return entries.map((entry) => entry.row);
|
|
41
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** Lower-case, strip diacritics, collapse whitespace. Used on both sides of every match. */
|
|
2
|
+
export declare function normalizeText(value: string): string;
|
|
3
|
+
/** Removes control/bidi characters, trims and caps the length of free text. */
|
|
4
|
+
export declare function sanitizeText(value: string, maxLength?: number): string;
|
|
5
|
+
export declare const sanitizeSearch: (value: string) => string;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { MAX_SEARCH_LENGTH } from './constants.js';
|
|
2
|
+
const rangeClass = (ranges) => new RegExp(`[${ranges.map(([a, b]) => `${String.fromCharCode(a)}-${String.fromCharCode(b)}`).join('')}]`, 'g');
|
|
3
|
+
const COMBINING_MARKS = rangeClass([[0x300, 0x36f]]);
|
|
4
|
+
const WHITESPACE = /\s+/g;
|
|
5
|
+
// C0/C1 controls plus bidi and zero-width formatting characters.
|
|
6
|
+
const UNSAFE_CHARS = rangeClass([
|
|
7
|
+
[0x0, 0x1f],
|
|
8
|
+
[0x7f, 0x9f],
|
|
9
|
+
[0x200b, 0x200f],
|
|
10
|
+
[0x202a, 0x202e],
|
|
11
|
+
[0x2066, 0x2069],
|
|
12
|
+
[0xfeff, 0xfeff],
|
|
13
|
+
]);
|
|
14
|
+
/** Lower-case, strip diacritics, collapse whitespace. Used on both sides of every match. */
|
|
15
|
+
export function normalizeText(value) {
|
|
16
|
+
return value
|
|
17
|
+
.normalize('NFD')
|
|
18
|
+
.replace(COMBINING_MARKS, '')
|
|
19
|
+
.toLowerCase()
|
|
20
|
+
.replace(WHITESPACE, ' ')
|
|
21
|
+
.trim();
|
|
22
|
+
}
|
|
23
|
+
/** Removes control/bidi characters, trims and caps the length of free text. */
|
|
24
|
+
export function sanitizeText(value, maxLength = MAX_SEARCH_LENGTH) {
|
|
25
|
+
return value.replace(UNSAFE_CHARS, '').trim().slice(0, maxLength);
|
|
26
|
+
}
|
|
27
|
+
export const sanitizeSearch = (value) => sanitizeText(value, MAX_SEARCH_LENGTH);
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { PageSize } from './constants.js';
|
|
2
|
+
export type RowId = string;
|
|
3
|
+
export type SortDirection = 'ascending' | 'descending';
|
|
4
|
+
export interface SortState {
|
|
5
|
+
columnId: string;
|
|
6
|
+
direction: SortDirection;
|
|
7
|
+
}
|
|
8
|
+
/** Applied filter values by filter id. Created with `Object.create(null)`; declared ids only. */
|
|
9
|
+
export type FilterValues = Readonly<Record<string, unknown>>;
|
|
10
|
+
export interface TableQuery {
|
|
11
|
+
search: string;
|
|
12
|
+
filters: FilterValues;
|
|
13
|
+
/** `'all'` when none. */
|
|
14
|
+
quickFilter: string;
|
|
15
|
+
sort: SortState | null;
|
|
16
|
+
groupBy: string | null;
|
|
17
|
+
/** 1-based. */
|
|
18
|
+
page: number;
|
|
19
|
+
pageSize: PageSize;
|
|
20
|
+
}
|
|
21
|
+
export type QueryChangeReason = 'search' | 'filters' | 'quickFilter' | 'sort' | 'page' | 'pageSize' | 'group' | 'clamp' | 'reset';
|
|
22
|
+
export interface QueryChangeMeta {
|
|
23
|
+
reason: QueryChangeReason;
|
|
24
|
+
/** History hint for URL-controlled screens: `replace` for search and clamp, `push` otherwise. */
|
|
25
|
+
history: 'push' | 'replace';
|
|
26
|
+
}
|
|
27
|
+
export interface PageGroup<TRow> {
|
|
28
|
+
key: string;
|
|
29
|
+
label: string;
|
|
30
|
+
/** Rows of this group on the current page. */
|
|
31
|
+
rows: readonly TRow[];
|
|
32
|
+
continuesFromPreviousPage: boolean;
|
|
33
|
+
continuesOnNextPage: boolean;
|
|
34
|
+
}
|
|
35
|
+
export type FilterErrorCode = 'invalid-number' | 'invalid-date' | 'invalid-range' | 'out-of-bounds' | 'too-long' | 'invalid-option' | 'custom';
|
|
36
|
+
export interface FilterError {
|
|
37
|
+
code: FilterErrorCode;
|
|
38
|
+
/** Only for `custom` filters, which supply their own text. */
|
|
39
|
+
message?: string;
|
|
40
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { type PageSize } from './constants.js';
|
|
2
|
+
import type { CoreFilterDef } from './filters/types.js';
|
|
3
|
+
import type { TableQuery } from './types.js';
|
|
4
|
+
export interface TableUrlSchema {
|
|
5
|
+
/** e.g. `docs.` when two tables share one URL. */
|
|
6
|
+
prefix?: string;
|
|
7
|
+
/** Sortable columns only. */
|
|
8
|
+
columns: readonly {
|
|
9
|
+
id: string;
|
|
10
|
+
}[];
|
|
11
|
+
filters: readonly CoreFilterDef<never>[];
|
|
12
|
+
quickFilters?: readonly {
|
|
13
|
+
id: string;
|
|
14
|
+
}[];
|
|
15
|
+
groups?: readonly {
|
|
16
|
+
id: string;
|
|
17
|
+
locked?: boolean;
|
|
18
|
+
}[];
|
|
19
|
+
pageSizeOptions?: readonly PageSize[];
|
|
20
|
+
defaults: TableQuery;
|
|
21
|
+
}
|
|
22
|
+
export interface UrlIssue {
|
|
23
|
+
key: string;
|
|
24
|
+
reason: string;
|
|
25
|
+
}
|
|
26
|
+
export interface ParsedTableQuery {
|
|
27
|
+
query: TableQuery;
|
|
28
|
+
issues: readonly UrlIssue[];
|
|
29
|
+
/** False when the URL differs from the serialised valid query (the app should `replace`). */
|
|
30
|
+
canonical: boolean;
|
|
31
|
+
}
|
|
32
|
+
/** Query parameter names this schema owns (all of them, whether or not they are in the URL). */
|
|
33
|
+
export declare function tableUrlKeys(schema: TableUrlSchema): string[];
|
|
34
|
+
/**
|
|
35
|
+
* Wire form of a query. Defaults are omitted and keys are sorted so URLs are stable. Only
|
|
36
|
+
* declared, valid values are written.
|
|
37
|
+
*/
|
|
38
|
+
export declare function serializeTableQuery(query: TableQuery, schema: TableUrlSchema): URLSearchParams;
|
|
39
|
+
/**
|
|
40
|
+
* Reads a query from untrusted URL parameters. Never throws; invalid values are dropped
|
|
41
|
+
* (reported in `issues`) and defaults apply. Unknown parameters are ignored. See plan section 8.
|
|
42
|
+
*/
|
|
43
|
+
export declare function parseTableQuery(params: URLSearchParams, schema: TableUrlSchema): ParsedTableQuery;
|