@gemologic/sheen-table 0.2.0 → 0.3.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/dist/DataTable.d.ts +7 -0
- package/dist/DataTable.js +1154 -1624
- package/dist/DataTableToolbar.js +1 -2
- package/dist/FilterBar.d.ts +3 -0
- package/dist/FilterBar.js +127 -108
- package/dist/QueryBuilder.js +72 -68
- package/dist/cell-edit.js +1 -2
- package/dist/client-state.js +20 -21
- package/dist/client-view.js +12 -13
- package/dist/column-layout.js +1 -2
- package/dist/columns.d.ts +5 -1
- package/dist/columns.js +7 -5
- package/dist/constrained-columns.js +1 -2
- package/dist/data-table-features.d.ts +129 -0
- package/dist/data-table-features.js +550 -0
- package/dist/export.js +1 -2
- package/dist/facets.js +5 -7
- package/dist/filter-bar-state.js +14 -18
- package/dist/filter-client.js +1 -2
- package/dist/filter.js +1 -2
- package/dist/grouping.js +1 -2
- package/dist/index.js +3 -3
- package/dist/messages.d.ts +1 -1
- package/dist/messages.js +2 -3
- package/dist/pagination.js +1 -2
- package/dist/query-builder-state.js +1 -2
- package/dist/requests.js +1 -2
- package/dist/row-hierarchy.js +1 -2
- package/dist/row-identity.js +1 -2
- package/dist/saved-views.js +1 -2
- package/dist/search-controller.js +1 -2
- package/dist/search.js +1 -2
- package/dist/selection-client.js +1 -2
- package/dist/selection.d.ts +3 -0
- package/dist/selection.js +9 -2
- package/dist/server-export.js +1 -2
- package/dist/sorting.js +1 -2
- package/dist/table-state-changes.js +1 -2
- package/dist/table-state.js +1 -2
- package/dist/text-normalization.js +1 -2
- package/dist/url-state.js +1 -2
- package/package.json +5 -5
- package/src/DataTable.tsx +285 -712
- package/src/FilterBar.tsx +17 -3
- package/src/QueryBuilder.tsx +5 -5
- package/src/columns.ts +9 -3
- package/src/data-table-features.tsx +579 -0
- package/src/messages.ts +1 -1
- package/src/selection.ts +8 -0
- package/src/styles.css +17 -11
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import type { Accessor, JSX } from "solid-js";
|
|
2
|
+
import type { ColumnValue, ResolvedColumn } from "./columns.ts";
|
|
3
|
+
import type { DataTableProps, DataTableResult } from "./DataTable.tsx";
|
|
4
|
+
import type { FilterColumn, FilterNode } from "./filter.ts";
|
|
5
|
+
import type { ClientRowGroup } from "./grouping.ts";
|
|
6
|
+
import type { TableMessages } from "./messages.ts";
|
|
7
|
+
/** One application row with a stable ID. The accessor follows the current source row for that ID. */
|
|
8
|
+
export interface StableRow<Row extends object> {
|
|
9
|
+
readonly id: string;
|
|
10
|
+
readonly value: Accessor<Row>;
|
|
11
|
+
}
|
|
12
|
+
export interface StableRows<Row extends object> {
|
|
13
|
+
readonly resolve: (row: Row, index: number) => StableRow<Row>;
|
|
14
|
+
}
|
|
15
|
+
export interface DisplayDataRow<Row extends object> {
|
|
16
|
+
readonly kind: "data";
|
|
17
|
+
readonly key: string;
|
|
18
|
+
readonly row: StableRow<Row>;
|
|
19
|
+
readonly parentId: string | null;
|
|
20
|
+
readonly depth: number;
|
|
21
|
+
readonly position: number;
|
|
22
|
+
readonly setSize: number;
|
|
23
|
+
readonly canExpand: boolean;
|
|
24
|
+
readonly expanded: boolean;
|
|
25
|
+
readonly unloaded: boolean;
|
|
26
|
+
readonly pending: boolean;
|
|
27
|
+
readonly error: unknown;
|
|
28
|
+
}
|
|
29
|
+
export interface DisplayGroupRow<Row extends object> {
|
|
30
|
+
readonly kind: "group";
|
|
31
|
+
readonly key: string;
|
|
32
|
+
readonly group: ClientRowGroup<Row>;
|
|
33
|
+
readonly label: string;
|
|
34
|
+
readonly position: number;
|
|
35
|
+
readonly setSize: number;
|
|
36
|
+
readonly expanded: boolean;
|
|
37
|
+
}
|
|
38
|
+
export type DisplayRow<Row extends object> = DisplayDataRow<Row> | DisplayGroupRow<Row>;
|
|
39
|
+
/** What a feature may read from, and ask of, the table that composes it. */
|
|
40
|
+
export interface DataTableFeatureContext<Row extends object> {
|
|
41
|
+
readonly props: DataTableProps<Row>;
|
|
42
|
+
readonly definitions: readonly ResolvedColumn<Row>[];
|
|
43
|
+
readonly filterColumns: readonly FilterColumn[];
|
|
44
|
+
readonly messages: Accessor<TableMessages>;
|
|
45
|
+
readonly locale: Accessor<string>;
|
|
46
|
+
/** A query is unsettled. Structural changes wait for accepted state. */
|
|
47
|
+
readonly pending: Accessor<boolean>;
|
|
48
|
+
/** Accepted rows, total, facets, and server groups. */
|
|
49
|
+
readonly result: Accessor<DataTableResult<Row>>;
|
|
50
|
+
readonly accepted: Accessor<boolean>;
|
|
51
|
+
readonly acceptedFilter: Accessor<FilterNode>;
|
|
52
|
+
readonly requestFilter: (filter: FilterNode) => void;
|
|
53
|
+
/** Stable rows for the table's own source (client data or the accepted server page). */
|
|
54
|
+
readonly stableRows: StableRows<Row>;
|
|
55
|
+
readonly createStableRows: (source: Accessor<readonly Row[]>) => StableRows<Row>;
|
|
56
|
+
readonly rowAt: (index: number) => DisplayRow<Row> | undefined;
|
|
57
|
+
readonly rowIndex: (key: string, hint?: number) => number;
|
|
58
|
+
readonly focusRow: (index: number) => void;
|
|
59
|
+
}
|
|
60
|
+
/** Replaces the flat row model with a structured treegrid presentation. At most one may be active. */
|
|
61
|
+
export interface DataTablePresentation<Row extends object> {
|
|
62
|
+
readonly rows: Accessor<readonly DisplayRow<Row>[]>;
|
|
63
|
+
readonly allowSelectAll: boolean;
|
|
64
|
+
/** Column that labels group rows when it is visible. */
|
|
65
|
+
readonly labelColumn?: string;
|
|
66
|
+
/** Returns true when the feature handled the key. Cards omit child/parent focus movement. */
|
|
67
|
+
readonly keyDown: (event: KeyboardEvent, row: DisplayRow<Row>, index: number, layout: "table" | "cards") => boolean;
|
|
68
|
+
/** Wraps the first visible data cell with tree indentation and expansion controls. */
|
|
69
|
+
readonly TreeCell: (props: {
|
|
70
|
+
readonly row: DisplayDataRow<Row>;
|
|
71
|
+
readonly children: JSX.Element;
|
|
72
|
+
}) => JSX.Element;
|
|
73
|
+
readonly GroupCell?: (props: {
|
|
74
|
+
readonly row: DisplayGroupRow<Row>;
|
|
75
|
+
readonly column: ResolvedColumn<Row>;
|
|
76
|
+
readonly label: boolean;
|
|
77
|
+
}) => JSX.Element;
|
|
78
|
+
}
|
|
79
|
+
export interface DataTableCellAttributes {
|
|
80
|
+
readonly "data-editable"?: "";
|
|
81
|
+
readonly "data-invalid"?: "";
|
|
82
|
+
readonly "data-stale"?: "";
|
|
83
|
+
readonly "data-pending"?: "";
|
|
84
|
+
readonly "data-conflict"?: "";
|
|
85
|
+
}
|
|
86
|
+
/** Per-cell extension bound inside the owning cell. */
|
|
87
|
+
export interface DataTableCellBinding<Row extends object> {
|
|
88
|
+
readonly active: Accessor<boolean>;
|
|
89
|
+
readonly attributes: Accessor<DataTableCellAttributes>;
|
|
90
|
+
readonly render: (row: Accessor<DisplayDataRow<Row>>) => JSX.Element;
|
|
91
|
+
}
|
|
92
|
+
export interface DataTableFeatureInstance<Row extends object> {
|
|
93
|
+
readonly presentation?: DataTablePresentation<Row>;
|
|
94
|
+
/** Toolbar query control rendered beside search. */
|
|
95
|
+
readonly query?: {
|
|
96
|
+
readonly visible: Accessor<boolean>;
|
|
97
|
+
readonly render: () => JSX.Element;
|
|
98
|
+
};
|
|
99
|
+
/** Returns undefined for columns the feature does not own. */
|
|
100
|
+
readonly cell?: (row: Accessor<DisplayDataRow<Row> | undefined>, column: ResolvedColumn<Row>) => DataTableCellBinding<Row> | undefined;
|
|
101
|
+
/** Rendered once at the end of the table section. */
|
|
102
|
+
readonly overlay?: () => JSX.Element;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Internal composition contract. A feature validates the props it owns and returns undefined when inactive.
|
|
106
|
+
* Features are row-agnostic so a later public `features` list can type-check against any DataTable.
|
|
107
|
+
*/
|
|
108
|
+
export type DataTableFeature = <Row extends object>(context: DataTableFeatureContext<Row>) => DataTableFeatureInstance<Row> | undefined;
|
|
109
|
+
export declare function defaultCell(value: ColumnValue): JSX.Element;
|
|
110
|
+
/**
|
|
111
|
+
* Holds a framework-neutral store's immutable snapshot in a signal. Stores publish by replacing their
|
|
112
|
+
* snapshot object, so equal references do not notify readers.
|
|
113
|
+
*/
|
|
114
|
+
export declare function createSnapshotSignal<Snapshot>(read: () => Snapshot): {
|
|
115
|
+
readonly snapshot: Accessor<Snapshot>;
|
|
116
|
+
readonly sync: () => void;
|
|
117
|
+
readonly track: <Value>(completion: Promise<Value>) => Promise<Value>;
|
|
118
|
+
};
|
|
119
|
+
/**
|
|
120
|
+
* Resolves stable row records lazily by ID. Each record reads the validated source index, so a changed row
|
|
121
|
+
* object reaches only the readers of that record without writing reactive state while deriving rows.
|
|
122
|
+
*/
|
|
123
|
+
export declare function createStableRows<Row extends object>(getRowId: (row: Row) => string, source: Accessor<readonly Row[]>): StableRows<Row>;
|
|
124
|
+
/** First-seen groups over complete client data or delegated server groups for the accepted page. */
|
|
125
|
+
export declare function groupingFeature<Row extends object>(context: DataTableFeatureContext<Row>): DataTableFeatureInstance<Row> | undefined;
|
|
126
|
+
/** Expandable parent rows with synchronous children or independently loaded subtrees. */
|
|
127
|
+
export declare function hierarchyFeature<Row extends object>(context: DataTableFeatureContext<Row>): DataTableFeatureInstance<Row> | undefined;
|
|
128
|
+
/** Inline editing for columns that declare an editor. Drafts survive virtualization until the reset boundary changes. */
|
|
129
|
+
export declare function cellEditingFeature<Row extends object>(context: DataTableFeatureContext<Row>): DataTableFeatureInstance<Row> | undefined;
|
|
@@ -0,0 +1,550 @@
|
|
|
1
|
+
import { createCellEdit as e } from "./cell-edit.js";
|
|
2
|
+
import { groupClientRows as t, normalizeServerGroups as n } from "./grouping.js";
|
|
3
|
+
import { createRowHierarchy as r } from "./row-hierarchy.js";
|
|
4
|
+
import { createRowIdentity as i } from "./row-identity.js";
|
|
5
|
+
import { createComponent as a, delegateEvents as o, effect as s, insert as c, setAttribute as l, setStyleProperty as u, template as d, use as f } from "solid-js/web";
|
|
6
|
+
import { Toaster as p, createToaster as m } from "@gemologic/sheen";
|
|
7
|
+
import { For as h, Show as g, createComputed as _, createEffect as v, createMemo as y, createSignal as b, createUniqueId as x, on as S, onCleanup as C, onMount as w, untrack as T } from "solid-js";
|
|
8
|
+
// src/data-table-features.tsx
|
|
9
|
+
var E = /*#__PURE__*/ d("<button type=button class=sheen-data-table-expander>"), D = /*#__PURE__*/ d("<span class=sheen-data-table-row-status role=status>"), O = /*#__PURE__*/ d("<span class=sheen-data-table-row-status role=alert> <button type=button>"), k = /*#__PURE__*/ d("<div class=sheen-data-table-tree-cell><span class=sheen-data-table-tree-value>"), A = /*#__PURE__*/ d("<span class=sheen-data-table-expander-space aria-hidden=true>"), j = /*#__PURE__*/ d("<div class=sheen-data-table-tree-cell style=--sheen-table-depth:0><span class=sheen-data-table-group-label> <span class=sheen-data-table-group-count>(<!>)"), M = /*#__PURE__*/ d("<input class=\"sheen-data-table-editor sheen-data-table-editor-boolean\"type=checkbox>"), N = /*#__PURE__*/ d("<option value>"), P = /*#__PURE__*/ d("<select class=sheen-data-table-editor>"), F = /*#__PURE__*/ d("<option>"), I = /*#__PURE__*/ d("<input class=sheen-data-table-editor type=number inputmode=decimal>"), L = /*#__PURE__*/ d("<input class=sheen-data-table-editor type=text>"), R = /*#__PURE__*/ d("<span class=sheen-data-table-edit-value>"), z = /*#__PURE__*/ d("<span class=sheen-data-table-edit-rest tabindex=0 aria-keyshortcuts=Enter>"), B = /*#__PURE__*/ d("<span class=sheen-data-table-edit-message>");
|
|
10
|
+
function V(e) {
|
|
11
|
+
return e === null ? "" : typeof e == "boolean" ? e ? "Yes" : "No" : String(e);
|
|
12
|
+
}
|
|
13
|
+
function H(e) {
|
|
14
|
+
let [t, n] = b(e()), r = () => {
|
|
15
|
+
n(() => e());
|
|
16
|
+
};
|
|
17
|
+
return {
|
|
18
|
+
snapshot: t,
|
|
19
|
+
sync: r,
|
|
20
|
+
track: (e) => (r(), e.finally(r))
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
function U(e, t) {
|
|
24
|
+
let n = i(e), r = /* @__PURE__ */ new Map(), a = y(() => {
|
|
25
|
+
let e = t(), i = n.resolveIds(e), a = /* @__PURE__ */ new Map();
|
|
26
|
+
for (let t = 0; t < e.length; t++) a.set(i[t], e[t]);
|
|
27
|
+
for (let e of r.keys()) a.has(e) || r.delete(e);
|
|
28
|
+
return a;
|
|
29
|
+
});
|
|
30
|
+
function o(e, t) {
|
|
31
|
+
let n = t, i = Object.freeze({
|
|
32
|
+
id: e,
|
|
33
|
+
value: () => {
|
|
34
|
+
let t = a().get(e);
|
|
35
|
+
return t !== void 0 && (n = t), n;
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
return r.set(e, i), i;
|
|
39
|
+
}
|
|
40
|
+
return Object.freeze({ resolve(t, n) {
|
|
41
|
+
let i = e(t);
|
|
42
|
+
if (!a().has(i)) throw Error(`Result row at index ${n} is not part of the supplied data`);
|
|
43
|
+
return r.get(i) ?? o(i, t);
|
|
44
|
+
} });
|
|
45
|
+
}
|
|
46
|
+
function W(e) {
|
|
47
|
+
return (() => {
|
|
48
|
+
var t = k(), n = t.firstChild;
|
|
49
|
+
return c(t, a(g, {
|
|
50
|
+
get when() {
|
|
51
|
+
return e.row.canExpand;
|
|
52
|
+
},
|
|
53
|
+
get fallback() {
|
|
54
|
+
return A();
|
|
55
|
+
},
|
|
56
|
+
get children() {
|
|
57
|
+
var t = E();
|
|
58
|
+
return t.$$click = () => e.onToggle(e.row), c(t, () => e.row.expanded ? "▾" : "▸"), s((n) => {
|
|
59
|
+
var r = `${e.row.expanded ? e.messages.collapse : e.messages.expand} ${e.row.row.id}`, i = e.row.expanded, a = e.pending;
|
|
60
|
+
return r !== n.e && l(t, "aria-label", n.e = r), i !== n.t && l(t, "aria-expanded", n.t = i), a !== n.a && (t.disabled = n.a = a), n;
|
|
61
|
+
}, {
|
|
62
|
+
e: void 0,
|
|
63
|
+
t: void 0,
|
|
64
|
+
a: void 0
|
|
65
|
+
}), t;
|
|
66
|
+
}
|
|
67
|
+
}), n), c(n, () => e.children), c(t, a(g, {
|
|
68
|
+
get when() {
|
|
69
|
+
return e.row.pending;
|
|
70
|
+
},
|
|
71
|
+
get children() {
|
|
72
|
+
var t = D();
|
|
73
|
+
return c(t, () => e.messages.loadingChildren), t;
|
|
74
|
+
}
|
|
75
|
+
}), null), c(t, a(g, {
|
|
76
|
+
get when() {
|
|
77
|
+
return e.row.error !== null;
|
|
78
|
+
},
|
|
79
|
+
get children() {
|
|
80
|
+
var t = O(), n = t.firstChild, r = n.nextSibling;
|
|
81
|
+
return c(t, () => e.messages.serverError, n), r.$$click = () => e.onRetry(e.row), c(r, () => e.messages.retry), t;
|
|
82
|
+
}
|
|
83
|
+
}), null), s((n) => u(t, "--sheen-table-depth", Math.max(0, e.row.depth - 1))), t;
|
|
84
|
+
})();
|
|
85
|
+
}
|
|
86
|
+
function G(e) {
|
|
87
|
+
return !e.ctrlKey && !e.metaKey && !e.shiftKey;
|
|
88
|
+
}
|
|
89
|
+
function K(e) {
|
|
90
|
+
let r = e.props, i = r.grouping;
|
|
91
|
+
if (!i) return;
|
|
92
|
+
if (r.mode !== "server" && r.pagination !== !1) throw Error("Client grouping requires complete continuous data with pagination=false");
|
|
93
|
+
if (typeof i.by != "string" || !i.by.trim()) throw Error("DataTable grouping requires a column ID");
|
|
94
|
+
if (i.getLabel !== void 0 && typeof i.getLabel != "function") throw Error("DataTable grouping getLabel must be a function");
|
|
95
|
+
let o = e.definitions.find((e) => e.id === i.by), u = o?.accessor;
|
|
96
|
+
if (!o || !u) throw Error(`Grouping column ${i.by} must be an accessor column`);
|
|
97
|
+
let d = e.definitions.flatMap((e) => e.aggregate && e.accessor ? [{
|
|
98
|
+
id: e.id,
|
|
99
|
+
aggregate: e.aggregate,
|
|
100
|
+
getValue: e.accessor
|
|
101
|
+
}] : []), [f, p] = b(/* @__PURE__ */ new Map()), m = /* @__PURE__ */ new Map(), h = y(() => new Intl.NumberFormat(e.locale()));
|
|
102
|
+
function _(e) {
|
|
103
|
+
let t = f().get(e);
|
|
104
|
+
if (t !== void 0) return t;
|
|
105
|
+
let n = m.get(e);
|
|
106
|
+
if (n !== void 0) return n;
|
|
107
|
+
let i = r.grouping?.collapsible === !1 || r.grouping?.defaultExpanded !== !1;
|
|
108
|
+
return m.set(e, i), i;
|
|
109
|
+
}
|
|
110
|
+
function v(t, n) {
|
|
111
|
+
e.pending() || r.grouping?.collapsible === !1 || _(t) === n || p((e) => new Map(e).set(t, n));
|
|
112
|
+
}
|
|
113
|
+
function x(t) {
|
|
114
|
+
let n = r.grouping?.getLabel?.(t.value) ?? (t.value === null ? e.messages().groupMissing : typeof t.value == "number" ? h().format(t.value) : String(t.value));
|
|
115
|
+
if (typeof n != "string" || !n.trim()) throw Error(`Group ${t.id} requires a nonempty label`);
|
|
116
|
+
return n;
|
|
117
|
+
}
|
|
118
|
+
let S = y(() => {
|
|
119
|
+
if (r.mode === "server" && !e.accepted()) return Object.freeze([]);
|
|
120
|
+
let i = e.result(), a = r.mode === "server" ? n(i.rows, i.groups, {
|
|
121
|
+
column: o.id,
|
|
122
|
+
aggregateColumns: d.map((e) => e.id),
|
|
123
|
+
getRowId: r.getRowId
|
|
124
|
+
}) : t(i.rows, {
|
|
125
|
+
column: o.id,
|
|
126
|
+
getValue: u,
|
|
127
|
+
aggregates: d
|
|
128
|
+
}), s = [], c = 0;
|
|
129
|
+
for (let t = 0; t < a.length; t++) {
|
|
130
|
+
let n = a[t], r = _(n.id);
|
|
131
|
+
s.push(Object.freeze({
|
|
132
|
+
kind: "group",
|
|
133
|
+
key: n.id,
|
|
134
|
+
group: n,
|
|
135
|
+
label: x(n),
|
|
136
|
+
position: t + 1,
|
|
137
|
+
setSize: a.length,
|
|
138
|
+
expanded: r
|
|
139
|
+
}));
|
|
140
|
+
for (let t = 0; t < n.rows.length; t++, c++) {
|
|
141
|
+
if (!r) continue;
|
|
142
|
+
let i = e.stableRows.resolve(n.rows[t], c);
|
|
143
|
+
s.push(Object.freeze({
|
|
144
|
+
kind: "data",
|
|
145
|
+
key: `row:${i.id}`,
|
|
146
|
+
row: i,
|
|
147
|
+
parentId: n.id,
|
|
148
|
+
depth: 2,
|
|
149
|
+
position: t + 1,
|
|
150
|
+
setSize: n.rows.length,
|
|
151
|
+
canExpand: !1,
|
|
152
|
+
expanded: !1,
|
|
153
|
+
unloaded: !1,
|
|
154
|
+
pending: !1,
|
|
155
|
+
error: null
|
|
156
|
+
}));
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
return Object.freeze(s);
|
|
160
|
+
}), C = () => void 0;
|
|
161
|
+
return { presentation: {
|
|
162
|
+
rows: S,
|
|
163
|
+
allowSelectAll: !0,
|
|
164
|
+
labelColumn: o.id,
|
|
165
|
+
keyDown(e, t) {
|
|
166
|
+
if (t.kind !== "group" || !G(e)) return !1;
|
|
167
|
+
if (e.key === " " || e.key === "Enter") v(t.group.id, !t.expanded);
|
|
168
|
+
else if (e.key === "ArrowRight" || e.key === "ArrowLeft") v(t.group.id, e.key === "ArrowRight");
|
|
169
|
+
else return !1;
|
|
170
|
+
return e.preventDefault(), !0;
|
|
171
|
+
},
|
|
172
|
+
TreeCell: (t) => a(W, {
|
|
173
|
+
get row() {
|
|
174
|
+
return t.row;
|
|
175
|
+
},
|
|
176
|
+
get messages() {
|
|
177
|
+
return e.messages();
|
|
178
|
+
},
|
|
179
|
+
get pending() {
|
|
180
|
+
return e.pending();
|
|
181
|
+
},
|
|
182
|
+
onToggle: C,
|
|
183
|
+
onRetry: C,
|
|
184
|
+
get children() {
|
|
185
|
+
return t.children;
|
|
186
|
+
}
|
|
187
|
+
}),
|
|
188
|
+
GroupCell: (t) => t.label ? (() => {
|
|
189
|
+
var n = j(), i = n.firstChild, o = i.firstChild, u = o.nextSibling, d = u.firstChild.nextSibling;
|
|
190
|
+
return d.nextSibling, c(n, a(g, {
|
|
191
|
+
get when() {
|
|
192
|
+
return r.grouping?.collapsible !== !1;
|
|
193
|
+
},
|
|
194
|
+
get fallback() {
|
|
195
|
+
return A();
|
|
196
|
+
},
|
|
197
|
+
get children() {
|
|
198
|
+
var n = E();
|
|
199
|
+
return n.$$click = () => v(t.row.group.id, !t.row.expanded), c(n, () => t.row.expanded ? "▾" : "▸"), s((r) => {
|
|
200
|
+
var i = e.pending(), a = `${t.row.expanded ? e.messages().collapse : e.messages().expand} ${t.row.label}`, o = t.row.expanded;
|
|
201
|
+
return i !== r.e && (n.disabled = r.e = i), a !== r.t && l(n, "aria-label", r.t = a), o !== r.a && l(n, "aria-expanded", r.a = o), r;
|
|
202
|
+
}, {
|
|
203
|
+
e: void 0,
|
|
204
|
+
t: void 0,
|
|
205
|
+
a: void 0
|
|
206
|
+
}), n;
|
|
207
|
+
}
|
|
208
|
+
}), i), c(i, () => t.row.label, o), c(u, () => h().format(t.row.group.count), d), n;
|
|
209
|
+
})() : V(t.row.group.aggregates.find((e) => e.column === t.column.id)?.value ?? null)
|
|
210
|
+
} };
|
|
211
|
+
}
|
|
212
|
+
function q(e) {
|
|
213
|
+
let t = e.props, n = t.hierarchy;
|
|
214
|
+
if (!n) return;
|
|
215
|
+
if (!n.getChildren && !n.onLoadChildren) throw Error("DataTable hierarchy requires getChildren or onLoadChildren");
|
|
216
|
+
if (n.onLoadChildren && !n.hasChildren) throw Error("Async DataTable hierarchy requires hasChildren");
|
|
217
|
+
if (typeof n.resetKey == "number" && !Number.isFinite(n.resetKey)) throw Error("DataTable hierarchy resetKey must be a finite number or string");
|
|
218
|
+
let i = r({
|
|
219
|
+
getRowId: t.getRowId,
|
|
220
|
+
...n.getChildren ? { getChildren: n.getChildren } : {},
|
|
221
|
+
...n.hasChildren ? { canLoadChildren: n.hasChildren } : {},
|
|
222
|
+
...n.onLoadChildren ? { loadChildren: n.onLoadChildren } : {},
|
|
223
|
+
...n.defaultExpanded === void 0 ? {} : { defaultExpanded: n.defaultExpanded }
|
|
224
|
+
});
|
|
225
|
+
C(() => i.dispose());
|
|
226
|
+
let { snapshot: o, sync: s, track: c } = H(i.getSnapshot), l = n.resetKey;
|
|
227
|
+
_(() => {
|
|
228
|
+
let n = e.result().rows, r = t.hierarchy?.resetKey;
|
|
229
|
+
T(() => {
|
|
230
|
+
Object.is(r, l) || i.reset(), l = r, i.updateRoots(n), s();
|
|
231
|
+
});
|
|
232
|
+
});
|
|
233
|
+
let u = e.createStableRows(() => o().map((e) => e.row)), d = y(() => Object.freeze(o().map((e, t) => {
|
|
234
|
+
let n = u.resolve(e.row, t);
|
|
235
|
+
return Object.freeze({
|
|
236
|
+
kind: "data",
|
|
237
|
+
key: `row:${e.id}`,
|
|
238
|
+
row: n,
|
|
239
|
+
parentId: e.parentId,
|
|
240
|
+
depth: e.depth,
|
|
241
|
+
position: e.position,
|
|
242
|
+
setSize: e.setSize,
|
|
243
|
+
canExpand: e.canExpand,
|
|
244
|
+
expanded: e.expanded,
|
|
245
|
+
unloaded: e.unloaded,
|
|
246
|
+
pending: e.pending,
|
|
247
|
+
error: e.error
|
|
248
|
+
});
|
|
249
|
+
})));
|
|
250
|
+
function f(t, n) {
|
|
251
|
+
e.pending() || c(i.setExpanded(t.row.id, n));
|
|
252
|
+
}
|
|
253
|
+
function p(t) {
|
|
254
|
+
e.pending() || c(i.retry(t.row.id));
|
|
255
|
+
}
|
|
256
|
+
let [m, h] = b(!1);
|
|
257
|
+
return w(() => {
|
|
258
|
+
h(!0);
|
|
259
|
+
}), v(() => {
|
|
260
|
+
if (m()) for (let e of d()) e.kind === "data" && e.expanded && e.unloaded && !e.pending && e.error === null && f(e, !0);
|
|
261
|
+
}), { presentation: {
|
|
262
|
+
rows: d,
|
|
263
|
+
allowSelectAll: !1,
|
|
264
|
+
keyDown(t, n, r, i) {
|
|
265
|
+
if (n.kind !== "data" || !G(t)) return !1;
|
|
266
|
+
if (i === "cards") return !n.canExpand || t.key !== "ArrowRight" && t.key !== "ArrowLeft" ? !1 : (t.preventDefault(), f(n, t.key === "ArrowRight"), !0);
|
|
267
|
+
if (n.canExpand && t.key === "ArrowRight") {
|
|
268
|
+
if (t.preventDefault(), !n.expanded) f(n, !0);
|
|
269
|
+
else {
|
|
270
|
+
let t = e.rowIndex(n.key, r), i = e.rowAt(t + 1);
|
|
271
|
+
i?.kind === "data" && i.parentId === n.row.id && e.focusRow(t + 1);
|
|
272
|
+
}
|
|
273
|
+
return !0;
|
|
274
|
+
}
|
|
275
|
+
if (t.key !== "ArrowLeft") return !1;
|
|
276
|
+
if (t.preventDefault(), n.expanded) f(n, !1);
|
|
277
|
+
else if (n.parentId) {
|
|
278
|
+
let t = d().findIndex((e) => e.kind === "data" && e.row.id === n.parentId);
|
|
279
|
+
t >= 0 && e.focusRow(t);
|
|
280
|
+
}
|
|
281
|
+
return !0;
|
|
282
|
+
},
|
|
283
|
+
TreeCell: (t) => a(W, {
|
|
284
|
+
get row() {
|
|
285
|
+
return t.row;
|
|
286
|
+
},
|
|
287
|
+
get messages() {
|
|
288
|
+
return e.messages();
|
|
289
|
+
},
|
|
290
|
+
get pending() {
|
|
291
|
+
return e.pending();
|
|
292
|
+
},
|
|
293
|
+
onToggle: (e) => f(e, !e.expanded),
|
|
294
|
+
onRetry: p,
|
|
295
|
+
get children() {
|
|
296
|
+
return t.children;
|
|
297
|
+
}
|
|
298
|
+
})
|
|
299
|
+
} };
|
|
300
|
+
}
|
|
301
|
+
function J(e, t) {
|
|
302
|
+
return t === null ? e.nullable === !0 : e.type === "text" ? typeof t == "string" : e.type === "number" ? typeof t == "number" : e.type === "boolean" ? typeof t == "boolean" : e.type === "select" && typeof t == "string" && e.options.includes(t);
|
|
303
|
+
}
|
|
304
|
+
function Y(t) {
|
|
305
|
+
let n = t.props, r = t.definitions.filter((e) => e.editor !== null);
|
|
306
|
+
if (r.length > 0 && !n.onCellCommit) throw Error("DataTable editable columns require onCellCommit");
|
|
307
|
+
if (r.length === 0 && n.onCellCommit) throw Error("DataTable onCellCommit requires at least one editable column");
|
|
308
|
+
for (let e of r) if (!e.accessor || !e.editor) throw Error(`Editable column ${e.id} requires an accessor and editor`);
|
|
309
|
+
let i = n.onCellCommit;
|
|
310
|
+
if (!i) return;
|
|
311
|
+
let o = m(), u = y(() => {
|
|
312
|
+
let e = n.editResetKey;
|
|
313
|
+
if (typeof e == "number" && !Number.isFinite(e)) throw Error("DataTable editResetKey must be a finite number or string");
|
|
314
|
+
let t = /* @__PURE__ */ new Map();
|
|
315
|
+
return C(() => {
|
|
316
|
+
for (let e of t.values()) e.controller.dispose();
|
|
317
|
+
}), t;
|
|
318
|
+
});
|
|
319
|
+
v(S(() => n.editResetKey, () => o.clear(), { defer: !0 }));
|
|
320
|
+
function d(n, r, a) {
|
|
321
|
+
let o = a.editor, s = a.accessor;
|
|
322
|
+
if (!o || !s || !i) return;
|
|
323
|
+
let c = `${r.id}\u0000${a.id}`, l = n.get(c);
|
|
324
|
+
if (l) return l;
|
|
325
|
+
let u = s(T(r.value));
|
|
326
|
+
if (!J(o, u)) throw Error(`Initial value for editable cell ${r.id}/${a.id} does not match its editor`);
|
|
327
|
+
let d = e(u, async (e, t) => {
|
|
328
|
+
let n = Object.freeze({
|
|
329
|
+
...e,
|
|
330
|
+
rowId: r.id,
|
|
331
|
+
row: T(r.value),
|
|
332
|
+
column: a.id
|
|
333
|
+
}), s = await i(n, t), c = s.kind === "accepted" ? s.value : s.current;
|
|
334
|
+
if (!J(o, c)) throw Error(`Committed value for ${r.id}/${a.id} does not match its editor`);
|
|
335
|
+
return s;
|
|
336
|
+
}, { validate: (e) => J(o, e) ? o.validate?.(e, T(r.value)) ?? null : e === null ? t.messages().cellValueRequired : t.messages().cellValueInvalid }), { snapshot: f, sync: p } = H(d.getSnapshot), m = Object.freeze({
|
|
337
|
+
controller: d,
|
|
338
|
+
snapshot: f,
|
|
339
|
+
sync: p
|
|
340
|
+
});
|
|
341
|
+
return n.set(c, m), m;
|
|
342
|
+
}
|
|
343
|
+
function _(e) {
|
|
344
|
+
let n = e.column.editor, r = e.column.accessor;
|
|
345
|
+
if (!n || !r) throw Error(`Editable cell ${e.row.row.id}/${e.column.id} is missing its editor`);
|
|
346
|
+
let i = n, u = x(), d, p, m = !1, _ = r(T(e.row.row.value)), y = () => e.record.snapshot(), b = () => y().draft?.value ?? y().committed, S = () => t.messages().editCell.replaceAll("{column}", e.column.header).replaceAll("{id}", e.row.row.id), C = () => {
|
|
347
|
+
let e = y();
|
|
348
|
+
return e.invalid ? e.invalid : e.conflict ? t.messages().cellConflict.replaceAll("{value}", e.conflict.current === null ? t.messages().noValue : String(e.conflict.current)) : e.error ? t.messages().cellUpdateFailedDescription : null;
|
|
349
|
+
}, w = () => e.column.cell?.(y().committed, e.row.row.value()) ?? V(y().committed);
|
|
350
|
+
v(() => {
|
|
351
|
+
let t = r(e.row.row.value());
|
|
352
|
+
Object.is(t, _) || (_ = t, e.record.controller.acceptRefetch(t), e.record.sync());
|
|
353
|
+
});
|
|
354
|
+
function E() {
|
|
355
|
+
queueMicrotask(() => d?.focus({ preventScroll: !0 }));
|
|
356
|
+
}
|
|
357
|
+
function D() {
|
|
358
|
+
queueMicrotask(() => {
|
|
359
|
+
m = !0;
|
|
360
|
+
try {
|
|
361
|
+
p?.focus({ preventScroll: !0 });
|
|
362
|
+
} finally {
|
|
363
|
+
m = !1;
|
|
364
|
+
}
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
function O() {
|
|
368
|
+
m || t.pending() || e.record.controller.begin() && (e.record.sync(), E());
|
|
369
|
+
}
|
|
370
|
+
function k(t) {
|
|
371
|
+
e.record.controller.setDraft(t), e.record.sync();
|
|
372
|
+
}
|
|
373
|
+
async function A(n, r, i = !0) {
|
|
374
|
+
e.record.sync();
|
|
375
|
+
let a = await n;
|
|
376
|
+
e.record.sync();
|
|
377
|
+
let s = y();
|
|
378
|
+
return a === "accepted" && !s.editing && r && D(), (a === "invalid" || a === "conflict") && r && E(), a === "failed" && i && o.show({
|
|
379
|
+
title: t.messages().cellUpdateFailed,
|
|
380
|
+
description: t.messages().cellUpdateFailedDescription,
|
|
381
|
+
tone: "danger",
|
|
382
|
+
priority: "assertive",
|
|
383
|
+
duration: null,
|
|
384
|
+
action: {
|
|
385
|
+
label: t.messages().retry,
|
|
386
|
+
retryLabel: t.messages().retry,
|
|
387
|
+
errorMessage: t.messages().retryFailed,
|
|
388
|
+
run: async () => {
|
|
389
|
+
let t = await A(e.record.controller.retry(), !1, !1);
|
|
390
|
+
if (t !== "accepted") throw Error(`Cell retry was not accepted: ${t}`);
|
|
391
|
+
D();
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
}), a;
|
|
395
|
+
}
|
|
396
|
+
function j(t) {
|
|
397
|
+
A(e.record.controller.commit(), t);
|
|
398
|
+
}
|
|
399
|
+
function H() {
|
|
400
|
+
let e = y();
|
|
401
|
+
(e.error === null && e.conflict === null || e.attempt === null || e.draft === null || !Object.is(e.attempt.value, e.draft.value)) && j(!1);
|
|
402
|
+
}
|
|
403
|
+
function U(t) {
|
|
404
|
+
t.key === "Enter" ? (t.preventDefault(), j(!0)) : t.key === "Escape" && (t.preventDefault(), e.record.controller.discard(), e.record.sync(), D());
|
|
405
|
+
}
|
|
406
|
+
function W() {
|
|
407
|
+
let e = () => y().invalid !== null || y().error !== null || void 0, n = () => C() ? `${u}-message` : void 0;
|
|
408
|
+
return i.type === "boolean" ? (() => {
|
|
409
|
+
var t = M();
|
|
410
|
+
return t.addEventListener("change", (e) => k(e.currentTarget.checked)), t.$$keydown = U, t.addEventListener("blur", H), f((e) => {
|
|
411
|
+
d = e, e.checked = b() === !0;
|
|
412
|
+
}, t), s((r) => {
|
|
413
|
+
var i = S(), a = n(), o = e(), s = y().pending || void 0;
|
|
414
|
+
return i !== r.e && l(t, "aria-label", r.e = i), a !== r.t && l(t, "aria-describedby", r.t = a), o !== r.a && l(t, "aria-invalid", r.a = o), s !== r.o && l(t, "aria-busy", r.o = s), r;
|
|
415
|
+
}, {
|
|
416
|
+
e: void 0,
|
|
417
|
+
t: void 0,
|
|
418
|
+
a: void 0,
|
|
419
|
+
o: void 0
|
|
420
|
+
}), t;
|
|
421
|
+
})() : i.type === "select" ? (() => {
|
|
422
|
+
var r = P();
|
|
423
|
+
return r.addEventListener("change", (e) => k(e.currentTarget.value === "" && i.nullable ? null : e.currentTarget.value)), r.$$keydown = U, r.addEventListener("blur", H), f((e) => {
|
|
424
|
+
d = e, e.value = b() === null ? "" : String(b());
|
|
425
|
+
}, r), c(r, a(g, {
|
|
426
|
+
get when() {
|
|
427
|
+
return i.nullable;
|
|
428
|
+
},
|
|
429
|
+
get children() {
|
|
430
|
+
var e = N();
|
|
431
|
+
return c(e, () => t.messages().noValue), e;
|
|
432
|
+
}
|
|
433
|
+
}), null), c(r, a(h, {
|
|
434
|
+
get each() {
|
|
435
|
+
return i.options;
|
|
436
|
+
},
|
|
437
|
+
children: (e) => (() => {
|
|
438
|
+
var t = F();
|
|
439
|
+
return t.value = e, c(t, e), t;
|
|
440
|
+
})()
|
|
441
|
+
}), null), s((t) => {
|
|
442
|
+
var i = S(), a = n(), o = e(), s = y().pending || void 0;
|
|
443
|
+
return i !== t.e && l(r, "aria-label", t.e = i), a !== t.t && l(r, "aria-describedby", t.t = a), o !== t.a && l(r, "aria-invalid", t.a = o), s !== t.o && l(r, "aria-busy", t.o = s), t;
|
|
444
|
+
}, {
|
|
445
|
+
e: void 0,
|
|
446
|
+
t: void 0,
|
|
447
|
+
a: void 0,
|
|
448
|
+
o: void 0
|
|
449
|
+
}), r;
|
|
450
|
+
})() : i.type === "number" ? (() => {
|
|
451
|
+
var t = I();
|
|
452
|
+
return t.$$input = (e) => k(e.currentTarget.value === "" ? null : e.currentTarget.valueAsNumber), t.$$keydown = U, t.addEventListener("blur", H), f((e) => {
|
|
453
|
+
d = e, e.value = b() === null ? "" : String(b());
|
|
454
|
+
}, t), s((r) => {
|
|
455
|
+
var i = S(), a = n(), o = e(), s = y().pending || void 0;
|
|
456
|
+
return i !== r.e && l(t, "aria-label", r.e = i), a !== r.t && l(t, "aria-describedby", r.t = a), o !== r.a && l(t, "aria-invalid", r.a = o), s !== r.o && l(t, "aria-busy", r.o = s), r;
|
|
457
|
+
}, {
|
|
458
|
+
e: void 0,
|
|
459
|
+
t: void 0,
|
|
460
|
+
a: void 0,
|
|
461
|
+
o: void 0
|
|
462
|
+
}), t;
|
|
463
|
+
})() : (() => {
|
|
464
|
+
var t = L();
|
|
465
|
+
return t.$$input = (e) => k(e.currentTarget.value === "" && i.nullable ? null : e.currentTarget.value), t.$$keydown = U, t.addEventListener("blur", H), f((e) => {
|
|
466
|
+
d = e, e.value = b() === null ? "" : String(b());
|
|
467
|
+
}, t), s((r) => {
|
|
468
|
+
var i = S(), a = n(), o = e(), s = y().pending || void 0;
|
|
469
|
+
return i !== r.e && l(t, "aria-label", r.e = i), a !== r.t && l(t, "aria-describedby", r.t = a), o !== r.a && l(t, "aria-invalid", r.a = o), s !== r.o && l(t, "aria-busy", r.o = s), r;
|
|
470
|
+
}, {
|
|
471
|
+
e: void 0,
|
|
472
|
+
t: void 0,
|
|
473
|
+
a: void 0,
|
|
474
|
+
o: void 0
|
|
475
|
+
}), t;
|
|
476
|
+
})();
|
|
477
|
+
}
|
|
478
|
+
return (() => {
|
|
479
|
+
var e = R();
|
|
480
|
+
return c(e, a(g, {
|
|
481
|
+
get when() {
|
|
482
|
+
return y().editing;
|
|
483
|
+
},
|
|
484
|
+
get fallback() {
|
|
485
|
+
return (() => {
|
|
486
|
+
var e = z();
|
|
487
|
+
return e.$$keydown = (e) => {
|
|
488
|
+
e.key === "Enter" && (e.preventDefault(), O());
|
|
489
|
+
}, e.$$click = O, f((e) => {
|
|
490
|
+
p = e, e.addEventListener("focus", O), e.ownerDocument.activeElement === e && queueMicrotask(O);
|
|
491
|
+
}, e), c(e, w), e;
|
|
492
|
+
})();
|
|
493
|
+
},
|
|
494
|
+
get children() {
|
|
495
|
+
return a(W, {});
|
|
496
|
+
}
|
|
497
|
+
}), null), c(e, a(g, {
|
|
498
|
+
get when() {
|
|
499
|
+
return C();
|
|
500
|
+
},
|
|
501
|
+
children: (e) => (() => {
|
|
502
|
+
var t = B();
|
|
503
|
+
return l(t, "id", `${u}-message`), c(t, e), s(() => l(t, "role", y().invalid !== null || y().conflict !== null ? "alert" : void 0)), t;
|
|
504
|
+
})()
|
|
505
|
+
}), null), e;
|
|
506
|
+
})();
|
|
507
|
+
}
|
|
508
|
+
return {
|
|
509
|
+
cell(e, t) {
|
|
510
|
+
if (!t.editor) return;
|
|
511
|
+
let n = y(() => {
|
|
512
|
+
let n = e();
|
|
513
|
+
return n ? d(u(), n.row, t) : void 0;
|
|
514
|
+
});
|
|
515
|
+
return {
|
|
516
|
+
active: () => n() !== void 0,
|
|
517
|
+
attributes: () => {
|
|
518
|
+
let e = n()?.snapshot();
|
|
519
|
+
return e ? {
|
|
520
|
+
"data-editable": "",
|
|
521
|
+
...e.invalid !== null || e.error !== null ? { "data-invalid": "" } : {},
|
|
522
|
+
...e.stale ? { "data-stale": "" } : {},
|
|
523
|
+
...e.pending ? { "data-pending": "" } : {},
|
|
524
|
+
...e.conflict ? { "data-conflict": "" } : {}
|
|
525
|
+
} : {};
|
|
526
|
+
},
|
|
527
|
+
render: (e) => a(g, {
|
|
528
|
+
get when() {
|
|
529
|
+
return n();
|
|
530
|
+
},
|
|
531
|
+
keyed: !0,
|
|
532
|
+
children: (n) => a(_, {
|
|
533
|
+
get row() {
|
|
534
|
+
return e();
|
|
535
|
+
},
|
|
536
|
+
column: t,
|
|
537
|
+
record: n
|
|
538
|
+
})
|
|
539
|
+
})
|
|
540
|
+
};
|
|
541
|
+
},
|
|
542
|
+
overlay: () => a(p, { controller: o })
|
|
543
|
+
};
|
|
544
|
+
}
|
|
545
|
+
o([
|
|
546
|
+
"click",
|
|
547
|
+
"keydown",
|
|
548
|
+
"input"
|
|
549
|
+
]);
|
|
550
|
+
export { Y as cellEditingFeature, H as createSnapshotSignal, U as createStableRows, V as defaultCell, K as groupingFeature, q as hierarchyFeature };
|
package/dist/export.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// src/export.ts
|
|
2
2
|
function e(e, t, n) {
|
|
3
3
|
if (e === null || typeof e == "string" || typeof e == "boolean" || typeof e == "number" && Number.isFinite(e)) return e;
|
|
4
4
|
throw Error(`Invalid export value at row ${t}, column ${n}: expected string, finite number, boolean, or null`);
|
|
@@ -23,5 +23,4 @@ function n(n, r) {
|
|
|
23
23
|
toJSON: () => JSON.stringify(c.map((e) => Object.fromEntries(s.map((t, n) => [t, e[n]]))))
|
|
24
24
|
});
|
|
25
25
|
}
|
|
26
|
-
//#endregion
|
|
27
26
|
export { n as createClientExport };
|