@gemologic/sheen-table 0.1.0-rc.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/LICENSE +19 -0
- package/README.md +19 -0
- package/dist/DataTable.d.ts +159 -0
- package/dist/DataTable.js +2724 -0
- package/dist/DataTableToolbar.d.ts +28 -0
- package/dist/DataTableToolbar.js +132 -0
- package/dist/FilterBar.d.ts +24 -0
- package/dist/FilterBar.js +681 -0
- package/dist/QueryBuilder.d.ts +11 -0
- package/dist/QueryBuilder.js +693 -0
- package/dist/cell-edit.d.ts +50 -0
- package/dist/cell-edit.js +178 -0
- package/dist/client-state.d.ts +28 -0
- package/dist/client-state.js +57 -0
- package/dist/client-view.d.ts +31 -0
- package/dist/client-view.js +30 -0
- package/dist/column-layout.d.ts +10 -0
- package/dist/column-layout.js +34 -0
- package/dist/columns.d.ts +108 -0
- package/dist/columns.js +217 -0
- package/dist/core.d.ts +54 -0
- package/dist/core.js +28 -0
- package/dist/export.d.ts +14 -0
- package/dist/export.js +27 -0
- package/dist/facets.d.ts +15 -0
- package/dist/facets.js +41 -0
- package/dist/filter-bar-state.d.ts +22 -0
- package/dist/filter-bar-state.js +128 -0
- package/dist/filter-client.d.ts +9 -0
- package/dist/filter-client.js +69 -0
- package/dist/filter.d.ts +64 -0
- package/dist/filter.js +132 -0
- package/dist/grouping.d.ts +37 -0
- package/dist/grouping.js +126 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +31 -0
- package/dist/messages.d.ts +115 -0
- package/dist/messages.js +121 -0
- package/dist/pagination.d.ts +36 -0
- package/dist/pagination.js +102 -0
- package/dist/query-builder-state.d.ts +28 -0
- package/dist/query-builder-state.js +128 -0
- package/dist/requests.d.ts +26 -0
- package/dist/requests.js +106 -0
- package/dist/row-hierarchy.d.ts +32 -0
- package/dist/row-hierarchy.js +170 -0
- package/dist/row-identity.d.ts +11 -0
- package/dist/row-identity.js +36 -0
- package/dist/saved-views.d.ts +52 -0
- package/dist/saved-views.js +153 -0
- package/dist/search-controller.d.ts +22 -0
- package/dist/search-controller.js +75 -0
- package/dist/search.d.ts +28 -0
- package/dist/search.js +111 -0
- package/dist/selection-client.d.ts +9 -0
- package/dist/selection-client.js +14 -0
- package/dist/selection.d.ts +25 -0
- package/dist/selection.js +60 -0
- package/dist/server-export.d.ts +27 -0
- package/dist/server-export.js +105 -0
- package/dist/sorting.d.ts +17 -0
- package/dist/sorting.js +58 -0
- package/dist/table-state-changes.d.ts +27 -0
- package/dist/table-state-changes.js +67 -0
- package/dist/table-state.d.ts +20 -0
- package/dist/table-state.js +77 -0
- package/dist/text-normalization.d.ts +2 -0
- package/dist/text-normalization.js +12 -0
- package/dist/url-state.d.ts +39 -0
- package/dist/url-state.js +75 -0
- package/package.json +66 -0
- package/src/DataTable.tsx +2322 -0
- package/src/DataTableToolbar.tsx +69 -0
- package/src/FilterBar.tsx +396 -0
- package/src/QueryBuilder.tsx +274 -0
- package/src/cell-edit.ts +187 -0
- package/src/client-state.ts +52 -0
- package/src/client-view.ts +61 -0
- package/src/column-layout.ts +47 -0
- package/src/columns.ts +271 -0
- package/src/core.ts +54 -0
- package/src/export.ts +39 -0
- package/src/facets.ts +46 -0
- package/src/filter-bar-state.ts +118 -0
- package/src/filter-client.ts +79 -0
- package/src/filter.ts +113 -0
- package/src/grouping.ts +185 -0
- package/src/index.ts +7 -0
- package/src/messages.ts +29 -0
- package/src/pagination.ts +81 -0
- package/src/query-builder-state.ts +105 -0
- package/src/requests.ts +85 -0
- package/src/row-hierarchy.ts +280 -0
- package/src/row-identity.ts +39 -0
- package/src/saved-views.ts +143 -0
- package/src/search-controller.ts +61 -0
- package/src/search.ts +137 -0
- package/src/selection-client.ts +23 -0
- package/src/selection.ts +62 -0
- package/src/server-export.ts +89 -0
- package/src/sorting.ts +63 -0
- package/src/styles.css +197 -0
- package/src/table-state-changes.ts +51 -0
- package/src/table-state.ts +72 -0
- package/src/text-normalization.ts +14 -0
- package/src/url-state.ts +62 -0
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
export type CellEditValue = string | number | boolean | null;
|
|
2
|
+
export interface CellCommitRequest<Value extends CellEditValue> {
|
|
3
|
+
readonly commitId: bigint;
|
|
4
|
+
readonly value: Value;
|
|
5
|
+
readonly previous: Value;
|
|
6
|
+
}
|
|
7
|
+
export type CellCommitResult<Value extends CellEditValue, Conflict> = {
|
|
8
|
+
readonly kind: "accepted";
|
|
9
|
+
readonly value: Value;
|
|
10
|
+
} | {
|
|
11
|
+
readonly kind: "conflict";
|
|
12
|
+
readonly current: Value;
|
|
13
|
+
readonly detail: Conflict;
|
|
14
|
+
};
|
|
15
|
+
export type CellCommitAttempt<Value extends CellEditValue> = CellCommitRequest<Value>;
|
|
16
|
+
export interface CellEditConflict<Value extends CellEditValue, Conflict> {
|
|
17
|
+
readonly commitId: bigint;
|
|
18
|
+
readonly attempted: Value;
|
|
19
|
+
readonly current: Value;
|
|
20
|
+
readonly detail: Conflict;
|
|
21
|
+
}
|
|
22
|
+
export interface CellEditSnapshot<Value extends CellEditValue, Conflict> {
|
|
23
|
+
readonly committed: Value;
|
|
24
|
+
readonly draft: {
|
|
25
|
+
readonly value: Value;
|
|
26
|
+
} | null;
|
|
27
|
+
readonly editing: boolean;
|
|
28
|
+
readonly pending: boolean;
|
|
29
|
+
readonly invalid: string | null;
|
|
30
|
+
readonly stale: boolean;
|
|
31
|
+
readonly error: unknown;
|
|
32
|
+
readonly attempt: CellCommitAttempt<Value> | null;
|
|
33
|
+
readonly conflict: CellEditConflict<Value, Conflict> | null;
|
|
34
|
+
}
|
|
35
|
+
export type CellCommitOutcome = "accepted" | "conflict" | "invalid" | "failed" | "busy" | "superseded" | "changed" | "inactive" | "disposed";
|
|
36
|
+
export interface CellEditOptions<Value extends CellEditValue> {
|
|
37
|
+
readonly validate?: (value: Value) => string | null;
|
|
38
|
+
readonly equals?: (left: Value, right: Value) => boolean;
|
|
39
|
+
}
|
|
40
|
+
/** Framework-neutral single-cell ownership. UIs publish snapshots around awaited methods. */
|
|
41
|
+
export declare function createCellEdit<Value extends CellEditValue, Conflict = unknown>(initial: Value, onCellCommit: (request: CellCommitRequest<Value>, signal: AbortSignal) => Promise<CellCommitResult<Value, Conflict>>, options?: CellEditOptions<Value>): {
|
|
42
|
+
getSnapshot: () => CellEditSnapshot<Value, Conflict>;
|
|
43
|
+
begin: () => boolean;
|
|
44
|
+
setDraft: (value: Value) => void;
|
|
45
|
+
commit: () => Promise<CellCommitOutcome>;
|
|
46
|
+
retry: () => Promise<CellCommitOutcome>;
|
|
47
|
+
acceptRefetch: (value: Value) => boolean;
|
|
48
|
+
discard: () => void;
|
|
49
|
+
dispose(): void;
|
|
50
|
+
};
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
//#region src/cell-edit.ts
|
|
2
|
+
function e(e) {
|
|
3
|
+
if (e !== null && typeof e != "string" && typeof e != "number" && typeof e != "boolean") throw Error("Cell edit values must be strings, finite numbers, booleans, or null");
|
|
4
|
+
if (typeof e == "number" && !Number.isFinite(e)) throw Error("Cell edit numbers must be finite");
|
|
5
|
+
}
|
|
6
|
+
function t(t, n, r = {}) {
|
|
7
|
+
e(t);
|
|
8
|
+
let i = r.equals ?? ((e, t) => Object.is(e, t)), a = Object.freeze({
|
|
9
|
+
committed: t,
|
|
10
|
+
draft: null,
|
|
11
|
+
editing: !1,
|
|
12
|
+
pending: !1,
|
|
13
|
+
invalid: null,
|
|
14
|
+
stale: !1,
|
|
15
|
+
error: null,
|
|
16
|
+
attempt: null,
|
|
17
|
+
conflict: null
|
|
18
|
+
}), o = null, s = 0n, c = 0n, l = 0n, u = null, d = null, f, p = !1, m = !1, h = (e) => Object.freeze({ value: e }), g = (e, t, n) => Object.freeze({
|
|
19
|
+
commitId: e,
|
|
20
|
+
value: t,
|
|
21
|
+
previous: n
|
|
22
|
+
});
|
|
23
|
+
function _(e) {
|
|
24
|
+
a = Object.freeze(e);
|
|
25
|
+
}
|
|
26
|
+
function v() {
|
|
27
|
+
return p || m || a.editing ? !1 : (o = h(a.committed), s++, u = null, _({
|
|
28
|
+
...a,
|
|
29
|
+
draft: h(a.committed),
|
|
30
|
+
editing: !0,
|
|
31
|
+
invalid: null,
|
|
32
|
+
stale: !1,
|
|
33
|
+
error: null,
|
|
34
|
+
attempt: null,
|
|
35
|
+
conflict: null
|
|
36
|
+
}), !0);
|
|
37
|
+
}
|
|
38
|
+
function y(t) {
|
|
39
|
+
if (e(t), p || m || !a.editing) throw Error("Cell is not available for editing");
|
|
40
|
+
s++, _({
|
|
41
|
+
...a,
|
|
42
|
+
draft: h(t),
|
|
43
|
+
invalid: null
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
async function b() {
|
|
47
|
+
if (p) return "disposed";
|
|
48
|
+
if (m) return "superseded";
|
|
49
|
+
let t = a.draft;
|
|
50
|
+
if (!a.editing || !t) return "inactive";
|
|
51
|
+
let i = s;
|
|
52
|
+
if (a.pending && d === i) return "busy";
|
|
53
|
+
let h = ++c, v = f;
|
|
54
|
+
if (f = void 0, v?.abort(), p) return "disposed";
|
|
55
|
+
if (h !== c) return "superseded";
|
|
56
|
+
let y;
|
|
57
|
+
try {
|
|
58
|
+
y = r.validate?.(t.value) ?? null;
|
|
59
|
+
} catch (e) {
|
|
60
|
+
return u = null, d = null, _({
|
|
61
|
+
...a,
|
|
62
|
+
pending: !1,
|
|
63
|
+
error: e,
|
|
64
|
+
attempt: null
|
|
65
|
+
}), "failed";
|
|
66
|
+
}
|
|
67
|
+
if (y !== null) {
|
|
68
|
+
if (typeof y != "string" || !y.trim()) throw Error("Cell validation messages must be nonempty strings");
|
|
69
|
+
return u = null, d = null, _({
|
|
70
|
+
...a,
|
|
71
|
+
pending: !1,
|
|
72
|
+
invalid: y,
|
|
73
|
+
error: null,
|
|
74
|
+
attempt: null
|
|
75
|
+
}), "invalid";
|
|
76
|
+
}
|
|
77
|
+
let b = ++l, x = g(b, t.value, a.committed), S = new AbortController();
|
|
78
|
+
f = S, u = null, d = i, _({
|
|
79
|
+
...a,
|
|
80
|
+
pending: !0,
|
|
81
|
+
invalid: null,
|
|
82
|
+
error: null,
|
|
83
|
+
attempt: x,
|
|
84
|
+
conflict: null
|
|
85
|
+
});
|
|
86
|
+
try {
|
|
87
|
+
let r = await n(x, S.signal);
|
|
88
|
+
if (p) return "disposed";
|
|
89
|
+
if (h !== c) return "superseded";
|
|
90
|
+
if (e(r.kind === "accepted" ? r.value : r.current), r.kind === "conflict") return d = null, u = i, _({
|
|
91
|
+
...a,
|
|
92
|
+
committed: r.current,
|
|
93
|
+
pending: !1,
|
|
94
|
+
stale: !0,
|
|
95
|
+
error: null,
|
|
96
|
+
conflict: Object.freeze({
|
|
97
|
+
commitId: b,
|
|
98
|
+
attempted: t.value,
|
|
99
|
+
current: r.current,
|
|
100
|
+
detail: r.detail
|
|
101
|
+
})
|
|
102
|
+
}), "conflict";
|
|
103
|
+
let l = s !== i;
|
|
104
|
+
return u = null, d = null, o = l ? o : null, _({
|
|
105
|
+
...a,
|
|
106
|
+
committed: r.value,
|
|
107
|
+
draft: l ? a.draft : null,
|
|
108
|
+
editing: l,
|
|
109
|
+
pending: !1,
|
|
110
|
+
invalid: null,
|
|
111
|
+
stale: l,
|
|
112
|
+
error: null,
|
|
113
|
+
attempt: null,
|
|
114
|
+
conflict: null
|
|
115
|
+
}), "accepted";
|
|
116
|
+
} catch (e) {
|
|
117
|
+
return p ? "disposed" : h === c ? (u = i, d = null, _({
|
|
118
|
+
...a,
|
|
119
|
+
pending: !1,
|
|
120
|
+
error: e
|
|
121
|
+
}), "failed") : "superseded";
|
|
122
|
+
} finally {
|
|
123
|
+
h === c && (f = void 0);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
function x() {
|
|
127
|
+
return p ? Promise.resolve("disposed") : u === null || !a.attempt ? Promise.resolve("inactive") : u === s ? b() : Promise.resolve("changed");
|
|
128
|
+
}
|
|
129
|
+
function S(t) {
|
|
130
|
+
if (e(t), p || m) return !1;
|
|
131
|
+
if (!a.editing) return o = null, _({
|
|
132
|
+
...a,
|
|
133
|
+
committed: t,
|
|
134
|
+
stale: !1
|
|
135
|
+
}), !0;
|
|
136
|
+
let n = o !== null && !i(o.value, t);
|
|
137
|
+
return _({
|
|
138
|
+
...a,
|
|
139
|
+
committed: t,
|
|
140
|
+
stale: a.stale || n
|
|
141
|
+
}), !0;
|
|
142
|
+
}
|
|
143
|
+
function C() {
|
|
144
|
+
if (m) return;
|
|
145
|
+
m = !0, c++;
|
|
146
|
+
let e = f;
|
|
147
|
+
f = void 0, u = null, d = null, o = null, _({
|
|
148
|
+
...a,
|
|
149
|
+
draft: null,
|
|
150
|
+
editing: !1,
|
|
151
|
+
pending: !1,
|
|
152
|
+
invalid: null,
|
|
153
|
+
stale: !1,
|
|
154
|
+
error: null,
|
|
155
|
+
attempt: null,
|
|
156
|
+
conflict: null
|
|
157
|
+
});
|
|
158
|
+
try {
|
|
159
|
+
e?.abort();
|
|
160
|
+
} finally {
|
|
161
|
+
m = !1;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return {
|
|
165
|
+
getSnapshot: () => a,
|
|
166
|
+
begin: v,
|
|
167
|
+
setDraft: y,
|
|
168
|
+
commit: b,
|
|
169
|
+
retry: x,
|
|
170
|
+
acceptRefetch: S,
|
|
171
|
+
discard: C,
|
|
172
|
+
dispose() {
|
|
173
|
+
p = !0, C();
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
//#endregion
|
|
178
|
+
export { t as createCellEdit };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { ClientViewState } from "./client-view.ts";
|
|
2
|
+
import type { FilterColumn, FilterNode } from "./filter.ts";
|
|
3
|
+
import type { TablePagination } from "./pagination.ts";
|
|
4
|
+
import type { SortColumn, SortState } from "./sorting.ts";
|
|
5
|
+
export interface ClientStateSchema {
|
|
6
|
+
readonly filterColumns: readonly FilterColumn[];
|
|
7
|
+
readonly sortColumns: readonly SortColumn[];
|
|
8
|
+
}
|
|
9
|
+
export type ClientStateChange = {
|
|
10
|
+
readonly kind: "search";
|
|
11
|
+
readonly value: string;
|
|
12
|
+
} | {
|
|
13
|
+
readonly kind: "filter";
|
|
14
|
+
readonly value: FilterNode;
|
|
15
|
+
} | {
|
|
16
|
+
readonly kind: "sorting";
|
|
17
|
+
readonly value: SortState;
|
|
18
|
+
} | {
|
|
19
|
+
readonly kind: "pagination";
|
|
20
|
+
readonly value: TablePagination;
|
|
21
|
+
} | {
|
|
22
|
+
readonly kind: "pageSize";
|
|
23
|
+
readonly value: number;
|
|
24
|
+
};
|
|
25
|
+
/** Query-state fragment only; column layout, selection, and saved-view envelopes are separate. */
|
|
26
|
+
export declare function parseClientViewState(value: unknown, schema: ClientStateSchema): ClientViewState;
|
|
27
|
+
/** Changes requested state only. Accepted rows/state remain owned by the result controller. */
|
|
28
|
+
export declare function changeClientViewState(state: ClientViewState, change: ClientStateChange, schema: ClientStateSchema): ClientViewState;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { parsePagination as e, resetPagination as t, resizePagination as n } from "./pagination.js";
|
|
2
|
+
import { parseFilter as r } from "./filter.js";
|
|
3
|
+
import { parseSorting as i } from "./sorting.js";
|
|
4
|
+
//#region src/client-state.ts
|
|
5
|
+
function a(t, n) {
|
|
6
|
+
if (typeof t != "object" || !t || Array.isArray(t)) throw Error("Invalid client state: expected an object");
|
|
7
|
+
if (Object.keys(t).some((e) => ![
|
|
8
|
+
"search",
|
|
9
|
+
"filter",
|
|
10
|
+
"sorting",
|
|
11
|
+
"pagination"
|
|
12
|
+
].includes(e))) throw Error("Invalid client state: unknown field");
|
|
13
|
+
if (!("search" in t) || typeof t.search != "string") throw Error("Invalid client state: search must be a string");
|
|
14
|
+
if (!("filter" in t) || !("sorting" in t) || !("pagination" in t)) throw Error("Invalid client state: missing query field");
|
|
15
|
+
return Object.freeze({
|
|
16
|
+
search: t.search,
|
|
17
|
+
filter: r(t.filter, n.filterColumns),
|
|
18
|
+
sorting: i(t.sorting, n.sortColumns),
|
|
19
|
+
pagination: e(t.pagination)
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
function o(r, i, o) {
|
|
23
|
+
let s = a(r, o);
|
|
24
|
+
switch (i.kind) {
|
|
25
|
+
case "search": return a({
|
|
26
|
+
...s,
|
|
27
|
+
search: i.value,
|
|
28
|
+
pagination: t(s.pagination)
|
|
29
|
+
}, o);
|
|
30
|
+
case "filter": return a({
|
|
31
|
+
...s,
|
|
32
|
+
filter: i.value,
|
|
33
|
+
pagination: t(s.pagination)
|
|
34
|
+
}, o);
|
|
35
|
+
case "sorting": return a({
|
|
36
|
+
...s,
|
|
37
|
+
sorting: i.value,
|
|
38
|
+
pagination: t(s.pagination)
|
|
39
|
+
}, o);
|
|
40
|
+
case "pagination": {
|
|
41
|
+
let n = e(i.value), r = n !== !1 && s.pagination !== !1 && n.pageSize !== s.pagination.pageSize;
|
|
42
|
+
return a({
|
|
43
|
+
...s,
|
|
44
|
+
pagination: r ? t(n) : n
|
|
45
|
+
}, o);
|
|
46
|
+
}
|
|
47
|
+
case "pageSize":
|
|
48
|
+
if (s.pagination === !1) throw Error("Page-size changes require pagination to be enabled");
|
|
49
|
+
return a({
|
|
50
|
+
...s,
|
|
51
|
+
pagination: n(s.pagination, i.value)
|
|
52
|
+
}, o);
|
|
53
|
+
default: throw Error("Unknown client state change");
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
//#endregion
|
|
57
|
+
export { o as changeClientViewState, a as parseClientViewState };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { ColumnFacet } from "./facets.ts";
|
|
2
|
+
import type { FilterColumn, FilterNode } from "./filter.ts";
|
|
3
|
+
import type { TablePagination } from "./pagination.ts";
|
|
4
|
+
import type { SortColumn, SortState } from "./sorting.ts";
|
|
5
|
+
export interface ClientViewState {
|
|
6
|
+
readonly search: string;
|
|
7
|
+
readonly filter: FilterNode;
|
|
8
|
+
readonly sorting: SortState;
|
|
9
|
+
readonly pagination: TablePagination;
|
|
10
|
+
}
|
|
11
|
+
export interface ClientViewOptions<Row> {
|
|
12
|
+
readonly locale: string;
|
|
13
|
+
readonly searchColumns: readonly string[];
|
|
14
|
+
/** Enables the leading-apostrophe exact-match syntax for global search. */
|
|
15
|
+
readonly exactMatch?: boolean;
|
|
16
|
+
readonly filterColumns: readonly FilterColumn[];
|
|
17
|
+
readonly sortColumns: readonly SortColumn[];
|
|
18
|
+
readonly getValue: (row: Row, column: string) => unknown;
|
|
19
|
+
/** Optional search-only projection. Filters and sorting continue to use getValue. */
|
|
20
|
+
readonly getSearchValue?: (row: Row, column: string) => unknown;
|
|
21
|
+
}
|
|
22
|
+
export interface ClientView<Row> {
|
|
23
|
+
/** Complete transformed view for export and continuous rendering, never just a page. */
|
|
24
|
+
readonly view: readonly Row[];
|
|
25
|
+
readonly rows: readonly Row[];
|
|
26
|
+
readonly total: number;
|
|
27
|
+
readonly pagination: TablePagination;
|
|
28
|
+
readonly facets: readonly ColumnFacet[];
|
|
29
|
+
}
|
|
30
|
+
/** Search -> filter -> facets -> explicit sort -> page. No network, cache, or state mutation. */
|
|
31
|
+
export declare function createClientView<Row>(rows: readonly Row[], state: ClientViewState, options: ClientViewOptions<Row>): ClientView<Row>;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { paginateClientRows as e, parsePagination as t } from "./pagination.js";
|
|
2
|
+
import { removeFilterColumnConditions as n } from "./filter-bar-state.js";
|
|
3
|
+
import { filterClientRows as r } from "./filter-client.js";
|
|
4
|
+
import { sortClientRows as i } from "./sorting.js";
|
|
5
|
+
import { countClientFacets as a } from "./facets.js";
|
|
6
|
+
import { searchClientRowValues as o } from "./search.js";
|
|
7
|
+
//#region src/client-view.ts
|
|
8
|
+
function s(s, c, l) {
|
|
9
|
+
let u = t(c.pagination), d = o(s, c.search, {
|
|
10
|
+
locale: l.locale,
|
|
11
|
+
columns: l.searchColumns,
|
|
12
|
+
getValue: l.getSearchValue ?? l.getValue,
|
|
13
|
+
exactMatch: l.exactMatch ?? !1
|
|
14
|
+
}), f = r(d, c.filter, l.filterColumns, l), p = /* @__PURE__ */ new Map();
|
|
15
|
+
for (let e of l.filterColumns) {
|
|
16
|
+
if (e.type !== "enum") continue;
|
|
17
|
+
let t = n(c.filter, e.id), r = p.get(t);
|
|
18
|
+
r ? r.push(e) : p.set(t, [e]);
|
|
19
|
+
}
|
|
20
|
+
let m = Object.freeze([...p].flatMap(([e, t]) => a(r(d, e, l.filterColumns, l), t, l))), h = i(f, c.sorting, l.sortColumns, l), g = e(h, u);
|
|
21
|
+
return {
|
|
22
|
+
view: h,
|
|
23
|
+
rows: g.rows,
|
|
24
|
+
total: g.total,
|
|
25
|
+
pagination: g.pagination,
|
|
26
|
+
facets: m
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
//#endregion
|
|
30
|
+
export { s as createClientView };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ColumnState } from "./table-state.ts";
|
|
2
|
+
export type ColumnMoveDirection = "toward-start" | "toward-end";
|
|
3
|
+
export type ColumnDropPlacement = "before" | "after";
|
|
4
|
+
/** Resolve logical pin regions while retaining the user's order inside each region. */
|
|
5
|
+
export declare function orderColumnStates(columns: readonly ColumnState[]): readonly ColumnState[];
|
|
6
|
+
/** Reorder one column relative to another without allowing a drag to change pin regions. */
|
|
7
|
+
export declare function placeColumn(columns: readonly ColumnState[], sourceId: string, targetId: string, placement: ColumnDropPlacement): readonly ColumnState[];
|
|
8
|
+
/** Keyboard/menu equivalent for a one-position logical drag. */
|
|
9
|
+
export declare function moveColumn(columns: readonly ColumnState[], id: string, direction: ColumnMoveDirection): readonly ColumnState[];
|
|
10
|
+
export declare function canMoveColumn(columns: readonly ColumnState[], id: string, direction: ColumnMoveDirection): boolean;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
//#region src/column-layout.ts
|
|
2
|
+
function e(e) {
|
|
3
|
+
return [
|
|
4
|
+
...e.filter((e) => e.pin === "start"),
|
|
5
|
+
...e.filter((e) => e.pin === !1),
|
|
6
|
+
...e.filter((e) => e.pin === "end")
|
|
7
|
+
];
|
|
8
|
+
}
|
|
9
|
+
function t(e, t, n, r) {
|
|
10
|
+
if (t === n) return e;
|
|
11
|
+
let i = e.find((e) => e.id === t), a = e.find((e) => e.id === n);
|
|
12
|
+
if (!i || !a) throw Error("Cannot reorder an unknown table column");
|
|
13
|
+
if (i.pin !== a.pin) throw Error("Cannot reorder columns across pin regions");
|
|
14
|
+
let o = e.filter((e) => e.id !== t), s = o.findIndex((e) => e.id === n);
|
|
15
|
+
return o.splice(s + +(r === "after"), 0, i), o;
|
|
16
|
+
}
|
|
17
|
+
function n(n, r, i) {
|
|
18
|
+
let a = e(n), o = a.findIndex((e) => e.id === r);
|
|
19
|
+
if (o < 0) throw Error(`Cannot move unknown table column: ${r}`);
|
|
20
|
+
let s = a[o];
|
|
21
|
+
if (!s) throw Error(`Cannot move unknown table column: ${r}`);
|
|
22
|
+
let c = i === "toward-start" ? -1 : 1, l = o + c;
|
|
23
|
+
for (; l >= 0 && l < a.length;) {
|
|
24
|
+
let e = a[l];
|
|
25
|
+
if (e?.pin === s.pin) return t(n, r, e.id, i === "toward-start" ? "before" : "after");
|
|
26
|
+
l += c;
|
|
27
|
+
}
|
|
28
|
+
return n;
|
|
29
|
+
}
|
|
30
|
+
function r(e, t, r) {
|
|
31
|
+
return n(e, t, r) !== e;
|
|
32
|
+
}
|
|
33
|
+
//#endregion
|
|
34
|
+
export { r as canMoveColumn, n as moveColumn, e as orderColumnStates, t as placeColumn };
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import type { FilterColumn } from "./filter.ts";
|
|
2
|
+
import type { SortColumn } from "./sorting.ts";
|
|
3
|
+
import type { TableStateSchema } from "./table-state.ts";
|
|
4
|
+
import type { JSX } from "solid-js";
|
|
5
|
+
export type ColumnValue = string | number | boolean | null;
|
|
6
|
+
export type ColumnPin = "start" | "end" | false;
|
|
7
|
+
export type ColumnAlign = "start" | "center" | "end";
|
|
8
|
+
export type ColumnWidth = number | "fill" | "content";
|
|
9
|
+
export type ColumnAggregate = "sum" | "average" | "min" | "max" | "count";
|
|
10
|
+
export type ColumnSort = SortColumn["type"] | false;
|
|
11
|
+
export type ColumnSearchProjection<Row extends object> = (row: Row) => string | number | null;
|
|
12
|
+
interface ColumnEditorBase<Row extends object> {
|
|
13
|
+
readonly nullable?: boolean;
|
|
14
|
+
readonly validate?: (value: ColumnValue, row: Row) => string | null;
|
|
15
|
+
}
|
|
16
|
+
export type ColumnEditor<Row extends object> = (ColumnEditorBase<Row> & {
|
|
17
|
+
readonly type: "text" | "number" | "boolean";
|
|
18
|
+
}) | (ColumnEditorBase<Row> & {
|
|
19
|
+
readonly type: "select";
|
|
20
|
+
readonly options: readonly string[];
|
|
21
|
+
});
|
|
22
|
+
export type ColumnFilter = {
|
|
23
|
+
readonly type: "text";
|
|
24
|
+
} | {
|
|
25
|
+
readonly type: "number";
|
|
26
|
+
} | {
|
|
27
|
+
readonly type: "date";
|
|
28
|
+
} | {
|
|
29
|
+
readonly type: "enum";
|
|
30
|
+
readonly options: readonly string[];
|
|
31
|
+
readonly faceted?: boolean;
|
|
32
|
+
};
|
|
33
|
+
export interface UnsafeTanStackColumnOptions {
|
|
34
|
+
readonly [option: string]: unknown;
|
|
35
|
+
}
|
|
36
|
+
interface ColumnBase<Row extends object> {
|
|
37
|
+
readonly id: string;
|
|
38
|
+
readonly header: string;
|
|
39
|
+
readonly footer?: string | ((rows: readonly Row[]) => JSX.Element);
|
|
40
|
+
readonly width?: ColumnWidth;
|
|
41
|
+
readonly minWidth?: number;
|
|
42
|
+
readonly maxWidth?: number;
|
|
43
|
+
readonly align?: ColumnAlign;
|
|
44
|
+
readonly numeric?: boolean;
|
|
45
|
+
readonly pin?: ColumnPin;
|
|
46
|
+
readonly visible?: boolean;
|
|
47
|
+
readonly __unsafe_tanstack?: UnsafeTanStackColumnOptions;
|
|
48
|
+
}
|
|
49
|
+
export interface SheenAccessorColumn<Row extends object> extends ColumnBase<Row> {
|
|
50
|
+
readonly accessor: (row: Row) => ColumnValue;
|
|
51
|
+
readonly cell?: (value: ColumnValue, row: Row) => JSX.Element;
|
|
52
|
+
/** Search the accessor value, or return a dedicated searchable text/number projection. */
|
|
53
|
+
readonly search?: true | ColumnSearchProjection<Row>;
|
|
54
|
+
/** Sensitive columns cannot participate in global search. */
|
|
55
|
+
readonly sensitive?: boolean;
|
|
56
|
+
readonly editor?: ColumnEditor<Row>;
|
|
57
|
+
readonly filter?: ColumnFilter;
|
|
58
|
+
/** Omit to infer number/date from filter or numeric, otherwise text. */
|
|
59
|
+
readonly sort?: ColumnSort;
|
|
60
|
+
readonly aggregate?: ColumnAggregate;
|
|
61
|
+
}
|
|
62
|
+
export interface SheenDisplayColumn<Row extends object> extends ColumnBase<Row> {
|
|
63
|
+
readonly accessor?: never;
|
|
64
|
+
/** Display columns receive null because they have no accessor value. */
|
|
65
|
+
readonly cell: (value: ColumnValue, row: Row) => JSX.Element;
|
|
66
|
+
readonly search?: never;
|
|
67
|
+
readonly sensitive?: never;
|
|
68
|
+
readonly filter?: never;
|
|
69
|
+
readonly sort?: never;
|
|
70
|
+
readonly aggregate?: never;
|
|
71
|
+
readonly editor?: never;
|
|
72
|
+
}
|
|
73
|
+
export type SheenColumnInput<Row extends object> = SheenAccessorColumn<Row> | SheenDisplayColumn<Row>;
|
|
74
|
+
interface ResolvedColumn<Row extends object> {
|
|
75
|
+
readonly id: string;
|
|
76
|
+
readonly header: string;
|
|
77
|
+
readonly accessor: ((row: Row) => ColumnValue) | null;
|
|
78
|
+
readonly cell: ((value: ColumnValue, row: Row) => JSX.Element) | null;
|
|
79
|
+
readonly footer: string | ((rows: readonly Row[]) => JSX.Element) | null;
|
|
80
|
+
readonly width: ColumnWidth;
|
|
81
|
+
readonly minWidth: number | null;
|
|
82
|
+
readonly maxWidth: number | null;
|
|
83
|
+
readonly align: ColumnAlign;
|
|
84
|
+
readonly numeric: boolean;
|
|
85
|
+
readonly pin: ColumnPin;
|
|
86
|
+
readonly visible: boolean;
|
|
87
|
+
readonly search: ColumnSearchProjection<Row> | null;
|
|
88
|
+
readonly sensitive: boolean;
|
|
89
|
+
readonly editor: ColumnEditor<Row> | null;
|
|
90
|
+
readonly filter: FilterColumn | null;
|
|
91
|
+
readonly faceted: boolean;
|
|
92
|
+
readonly sort: SortColumn | null;
|
|
93
|
+
readonly aggregate: ColumnAggregate | null;
|
|
94
|
+
readonly unsafeTanStack: UnsafeTanStackColumnOptions | null;
|
|
95
|
+
}
|
|
96
|
+
declare const columnsBrand: unique symbol;
|
|
97
|
+
declare const inspectColumns: unique symbol;
|
|
98
|
+
export interface SheenColumns<Row extends object> {
|
|
99
|
+
readonly [columnsBrand]: Row;
|
|
100
|
+
readonly [inspectColumns]: () => readonly ResolvedColumn<Row>[];
|
|
101
|
+
}
|
|
102
|
+
/** Validate and seal app definitions behind a non-enumerable type/runtime boundary. */
|
|
103
|
+
export declare function defineColumns<Row extends object>(values: readonly SheenColumnInput<Row>[]): SheenColumns<Row>;
|
|
104
|
+
/** Package-internal bridge used by the DataTable/TanStack adapter. */
|
|
105
|
+
export declare function readColumnDefinitions<Row extends object>(columns: SheenColumns<Row>): readonly ResolvedColumn<Row>[];
|
|
106
|
+
/** Package-internal schema projection; apps never construct TanStack definitions. */
|
|
107
|
+
export declare function columnStateSchema<Row extends object>(columns: SheenColumns<Row>): TableStateSchema;
|
|
108
|
+
export {};
|