@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.
Files changed (106) hide show
  1. package/LICENSE +19 -0
  2. package/README.md +19 -0
  3. package/dist/DataTable.d.ts +159 -0
  4. package/dist/DataTable.js +2724 -0
  5. package/dist/DataTableToolbar.d.ts +28 -0
  6. package/dist/DataTableToolbar.js +132 -0
  7. package/dist/FilterBar.d.ts +24 -0
  8. package/dist/FilterBar.js +681 -0
  9. package/dist/QueryBuilder.d.ts +11 -0
  10. package/dist/QueryBuilder.js +693 -0
  11. package/dist/cell-edit.d.ts +50 -0
  12. package/dist/cell-edit.js +178 -0
  13. package/dist/client-state.d.ts +28 -0
  14. package/dist/client-state.js +57 -0
  15. package/dist/client-view.d.ts +31 -0
  16. package/dist/client-view.js +30 -0
  17. package/dist/column-layout.d.ts +10 -0
  18. package/dist/column-layout.js +34 -0
  19. package/dist/columns.d.ts +108 -0
  20. package/dist/columns.js +217 -0
  21. package/dist/core.d.ts +54 -0
  22. package/dist/core.js +28 -0
  23. package/dist/export.d.ts +14 -0
  24. package/dist/export.js +27 -0
  25. package/dist/facets.d.ts +15 -0
  26. package/dist/facets.js +41 -0
  27. package/dist/filter-bar-state.d.ts +22 -0
  28. package/dist/filter-bar-state.js +128 -0
  29. package/dist/filter-client.d.ts +9 -0
  30. package/dist/filter-client.js +69 -0
  31. package/dist/filter.d.ts +64 -0
  32. package/dist/filter.js +132 -0
  33. package/dist/grouping.d.ts +37 -0
  34. package/dist/grouping.js +126 -0
  35. package/dist/index.d.ts +7 -0
  36. package/dist/index.js +31 -0
  37. package/dist/messages.d.ts +115 -0
  38. package/dist/messages.js +121 -0
  39. package/dist/pagination.d.ts +36 -0
  40. package/dist/pagination.js +102 -0
  41. package/dist/query-builder-state.d.ts +28 -0
  42. package/dist/query-builder-state.js +128 -0
  43. package/dist/requests.d.ts +26 -0
  44. package/dist/requests.js +106 -0
  45. package/dist/row-hierarchy.d.ts +32 -0
  46. package/dist/row-hierarchy.js +170 -0
  47. package/dist/row-identity.d.ts +11 -0
  48. package/dist/row-identity.js +36 -0
  49. package/dist/saved-views.d.ts +52 -0
  50. package/dist/saved-views.js +153 -0
  51. package/dist/search-controller.d.ts +22 -0
  52. package/dist/search-controller.js +75 -0
  53. package/dist/search.d.ts +28 -0
  54. package/dist/search.js +111 -0
  55. package/dist/selection-client.d.ts +9 -0
  56. package/dist/selection-client.js +14 -0
  57. package/dist/selection.d.ts +25 -0
  58. package/dist/selection.js +60 -0
  59. package/dist/server-export.d.ts +27 -0
  60. package/dist/server-export.js +105 -0
  61. package/dist/sorting.d.ts +17 -0
  62. package/dist/sorting.js +58 -0
  63. package/dist/table-state-changes.d.ts +27 -0
  64. package/dist/table-state-changes.js +67 -0
  65. package/dist/table-state.d.ts +20 -0
  66. package/dist/table-state.js +77 -0
  67. package/dist/text-normalization.d.ts +2 -0
  68. package/dist/text-normalization.js +12 -0
  69. package/dist/url-state.d.ts +39 -0
  70. package/dist/url-state.js +75 -0
  71. package/package.json +66 -0
  72. package/src/DataTable.tsx +2322 -0
  73. package/src/DataTableToolbar.tsx +69 -0
  74. package/src/FilterBar.tsx +396 -0
  75. package/src/QueryBuilder.tsx +274 -0
  76. package/src/cell-edit.ts +187 -0
  77. package/src/client-state.ts +52 -0
  78. package/src/client-view.ts +61 -0
  79. package/src/column-layout.ts +47 -0
  80. package/src/columns.ts +271 -0
  81. package/src/core.ts +54 -0
  82. package/src/export.ts +39 -0
  83. package/src/facets.ts +46 -0
  84. package/src/filter-bar-state.ts +118 -0
  85. package/src/filter-client.ts +79 -0
  86. package/src/filter.ts +113 -0
  87. package/src/grouping.ts +185 -0
  88. package/src/index.ts +7 -0
  89. package/src/messages.ts +29 -0
  90. package/src/pagination.ts +81 -0
  91. package/src/query-builder-state.ts +105 -0
  92. package/src/requests.ts +85 -0
  93. package/src/row-hierarchy.ts +280 -0
  94. package/src/row-identity.ts +39 -0
  95. package/src/saved-views.ts +143 -0
  96. package/src/search-controller.ts +61 -0
  97. package/src/search.ts +137 -0
  98. package/src/selection-client.ts +23 -0
  99. package/src/selection.ts +62 -0
  100. package/src/server-export.ts +89 -0
  101. package/src/sorting.ts +63 -0
  102. package/src/styles.css +197 -0
  103. package/src/table-state-changes.ts +51 -0
  104. package/src/table-state.ts +72 -0
  105. package/src/text-normalization.ts +14 -0
  106. package/src/url-state.ts +62 -0
@@ -0,0 +1,102 @@
1
+ //#region src/pagination.ts
2
+ function e(e, t) {
3
+ if (typeof e != "number" || !Number.isSafeInteger(e) || e < 0) throw Error(`${t} must be a nonnegative safe integer`);
4
+ }
5
+ function t(t) {
6
+ if (t === !1) return !1;
7
+ if (typeof t != "object" || !t || Array.isArray(t) || !("pageIndex" in t) || !("pageSize" in t)) throw Error("pagination must be false or { pageIndex, pageSize }");
8
+ if (Object.keys(t).some((e) => e !== "pageIndex" && e !== "pageSize")) throw Error("pagination contains unknown fields");
9
+ if (e(t.pageIndex, "pageIndex"), e(t.pageSize, "pageSize"), t.pageSize === 0) throw Error("pageSize must be positive");
10
+ return Object.freeze({
11
+ pageIndex: t.pageIndex,
12
+ pageSize: t.pageSize
13
+ });
14
+ }
15
+ function n(e, n) {
16
+ if (e !== "client" && e !== "server") throw Error("Table mode must be client or server");
17
+ if (n === void 0) {
18
+ if (e === "server") throw Error("Server mode requires explicit pagination, including explicit false for complete results");
19
+ return !1;
20
+ }
21
+ return t(n);
22
+ }
23
+ function r(e) {
24
+ let n = t(e);
25
+ return n !== !1 && Object.freeze({
26
+ ...n,
27
+ pageIndex: 0
28
+ });
29
+ }
30
+ function i(n, r) {
31
+ if (t(n) === !1) throw Error("Page-size changes require paginated state");
32
+ if (e(r, "pageSize"), r === 0) throw Error("pageSize must be positive");
33
+ return Object.freeze({
34
+ pageIndex: 0,
35
+ pageSize: r
36
+ });
37
+ }
38
+ function a(n, r) {
39
+ let i = t(n);
40
+ if (i === !1) throw Error("Page ranges require paginated state");
41
+ e(r, "total");
42
+ let a = Math.ceil(r / i.pageSize), o = Math.min(i.pageIndex, Math.max(0, a - 1)), s = o * i.pageSize, c = s + Math.min(i.pageSize, r - s);
43
+ return Object.freeze({
44
+ pageIndex: o,
45
+ pageSize: i.pageSize,
46
+ pageCount: a,
47
+ start: s,
48
+ end: c
49
+ });
50
+ }
51
+ function o(e, n = !1) {
52
+ let r = t(n);
53
+ if (r === !1) return {
54
+ rows: e,
55
+ total: e.length,
56
+ pagination: !1
57
+ };
58
+ let i = a(r, e.length);
59
+ return {
60
+ rows: e.slice(i.start, i.end),
61
+ total: e.length,
62
+ pagination: Object.freeze({
63
+ pageIndex: i.pageIndex,
64
+ pageSize: i.pageSize
65
+ })
66
+ };
67
+ }
68
+ function s(n, r) {
69
+ let i = t(n);
70
+ if (e(r.total, "total"), !Array.isArray(r.rows)) throw Error("Server rows must be an array");
71
+ if (i === !1) {
72
+ if (r.rows.length !== r.total) throw Error("Non-paginated server results must be complete: rows.length must equal total");
73
+ return {
74
+ kind: "accepted",
75
+ pagination: !1,
76
+ result: r
77
+ };
78
+ }
79
+ let o = a(i, r.total);
80
+ if (o.pageIndex !== i.pageIndex && r.total > 0) {
81
+ if (r.rows.length) throw Error("Out-of-range server page must not contain rows");
82
+ return {
83
+ kind: "refetch",
84
+ pagination: Object.freeze({
85
+ pageIndex: o.pageIndex,
86
+ pageSize: o.pageSize
87
+ }),
88
+ total: r.total
89
+ };
90
+ }
91
+ if (r.rows.length !== o.end - o.start) throw Error("Server page row count does not match the requested page and total");
92
+ return {
93
+ kind: "accepted",
94
+ pagination: Object.freeze({
95
+ pageIndex: o.pageIndex,
96
+ pageSize: o.pageSize
97
+ }),
98
+ result: r
99
+ };
100
+ }
101
+ //#endregion
102
+ export { s as assessServerPage, a as getPageRange, o as paginateClientRows, t as parsePagination, r as resetPagination, i as resizePagination, n as resolvePagination };
@@ -0,0 +1,28 @@
1
+ import type { FilterColumn, FilterNode } from "./filter.ts";
2
+ export type QueryBuilderColumn = {
3
+ readonly id: string;
4
+ readonly label: string;
5
+ readonly type: "text";
6
+ } | {
7
+ readonly id: string;
8
+ readonly label: string;
9
+ readonly type: "number";
10
+ } | {
11
+ readonly id: string;
12
+ readonly label: string;
13
+ readonly type: "date";
14
+ } | {
15
+ readonly id: string;
16
+ readonly label: string;
17
+ readonly type: "enum";
18
+ readonly options: readonly string[];
19
+ };
20
+ export type QueryBuilderPath = readonly number[];
21
+ export declare function queryBuilderFilterColumns(columns: readonly QueryBuilderColumn[]): readonly FilterColumn[];
22
+ export declare function defaultQueryRule(column: QueryBuilderColumn): FilterNode;
23
+ export declare function queryNodeAt(filter: FilterNode, path: QueryBuilderPath): FilterNode;
24
+ export declare function replaceQueryNode(filter: FilterNode, path: QueryBuilderPath, replacement: FilterNode, columns: readonly FilterColumn[]): FilterNode;
25
+ export declare function appendQueryChild(filter: FilterNode, path: QueryBuilderPath, child: FilterNode, columns: readonly FilterColumn[]): FilterNode;
26
+ export declare function removeQueryNode(filter: FilterNode, path: QueryBuilderPath, columns: readonly FilterColumn[]): FilterNode;
27
+ export declare function moveQueryNode(filter: FilterNode, path: QueryBuilderPath, offset: -1 | 1, columns: readonly FilterColumn[]): FilterNode;
28
+ export declare function toggleQueryNegation(filter: FilterNode, path: QueryBuilderPath, columns: readonly FilterColumn[]): FilterNode;
@@ -0,0 +1,128 @@
1
+ import { parseFilter as e } from "./filter.js";
2
+ //#region src/query-builder-state.ts
3
+ function t(e) {
4
+ let t = /* @__PURE__ */ new Set();
5
+ return Object.freeze(e.map((e) => {
6
+ if (!e.id.trim() || !e.label.trim() || t.has(e.id)) throw Error("QueryBuilder columns require unique nonempty IDs and labels");
7
+ if (t.add(e.id), e.type === "enum") {
8
+ let t = [...new Set(e.options)];
9
+ if (t.length === 0 || t.length !== e.options.length || t.some((e) => !e.trim())) throw Error(`QueryBuilder enum column ${JSON.stringify(e.id)} requires unique nonempty options`);
10
+ return Object.freeze({
11
+ id: e.id,
12
+ type: "enum",
13
+ options: Object.freeze(t)
14
+ });
15
+ }
16
+ return Object.freeze({
17
+ id: e.id,
18
+ type: e.type
19
+ });
20
+ }));
21
+ }
22
+ function n(e) {
23
+ if (e.type === "text") return Object.freeze({
24
+ kind: "text",
25
+ column: e.id,
26
+ operator: "contains",
27
+ value: "",
28
+ caseSensitive: !1
29
+ });
30
+ if (e.type === "number") return Object.freeze({
31
+ kind: "number",
32
+ column: e.id,
33
+ operator: "eq",
34
+ value: 0
35
+ });
36
+ if (e.type === "date") return Object.freeze({
37
+ kind: "date",
38
+ column: e.id,
39
+ operator: "eq",
40
+ value: Date.UTC(2e3, 0, 1)
41
+ });
42
+ let t = e.options[0];
43
+ if (!t) throw Error(`QueryBuilder enum column ${JSON.stringify(e.id)} requires an option`);
44
+ return Object.freeze({
45
+ kind: "enum",
46
+ column: e.id,
47
+ operator: "in",
48
+ values: Object.freeze([t])
49
+ });
50
+ }
51
+ function r(e, t, n) {
52
+ if (t.length === 0) return n(e);
53
+ let [i, ...a] = t;
54
+ if (i === void 0 || !Number.isSafeInteger(i) || i < 0) throw Error("QueryBuilder path segments must be nonnegative integers");
55
+ if (e.kind === "and" || e.kind === "or") {
56
+ if (i >= e.children.length) throw Error("QueryBuilder path is outside the filter tree");
57
+ return Object.freeze({
58
+ ...e,
59
+ children: Object.freeze(e.children.map((e, t) => t === i ? r(e, a, n) : e))
60
+ });
61
+ }
62
+ if (e.kind === "not" && i === 0) return Object.freeze({
63
+ kind: "not",
64
+ child: r(e.child, a, n)
65
+ });
66
+ throw Error("QueryBuilder path is outside the filter tree");
67
+ }
68
+ function i(e, t) {
69
+ let n = e;
70
+ for (let e of t) {
71
+ if (!Number.isSafeInteger(e) || e < 0) throw Error("QueryBuilder path segments must be nonnegative integers");
72
+ if (n.kind === "and" || n.kind === "or") {
73
+ let t = n.children[e];
74
+ if (!t) throw Error("QueryBuilder path is outside the filter tree");
75
+ n = t;
76
+ } else if (n.kind === "not" && e === 0) n = n.child;
77
+ else throw Error("QueryBuilder path is outside the filter tree");
78
+ }
79
+ return n;
80
+ }
81
+ function a(t, n, i, a) {
82
+ return e(r(t, n, () => i), a);
83
+ }
84
+ function o(t, n, i, a) {
85
+ return e(r(t, n, (e) => {
86
+ if (e.kind !== "and" && e.kind !== "or") throw Error("QueryBuilder can add children only to a group");
87
+ return Object.freeze({
88
+ ...e,
89
+ children: Object.freeze([...e.children, i])
90
+ });
91
+ }), a);
92
+ }
93
+ function s(t, n, i) {
94
+ if (n.length === 0) throw Error("QueryBuilder cannot remove its root node");
95
+ let a = n.slice(0, -1), o = n.at(-1);
96
+ if (o === void 0) throw Error("QueryBuilder path is incomplete");
97
+ return e(r(t, a, (e) => {
98
+ if (e.kind !== "and" && e.kind !== "or") throw Error("QueryBuilder can remove only group children");
99
+ if (!e.children[o]) throw Error("QueryBuilder path is outside the filter tree");
100
+ return Object.freeze({
101
+ ...e,
102
+ children: Object.freeze(e.children.filter((e, t) => t !== o))
103
+ });
104
+ }), i);
105
+ }
106
+ function c(t, n, i, a) {
107
+ if (n.length === 0) throw Error("QueryBuilder cannot move its root node");
108
+ let o = n.slice(0, -1), s = n.at(-1);
109
+ if (s === void 0) throw Error("QueryBuilder path is incomplete");
110
+ return e(r(t, o, (e) => {
111
+ if (e.kind !== "and" && e.kind !== "or") throw Error("QueryBuilder can move only group children");
112
+ let t = s + i;
113
+ if (!e.children[s] || t < 0 || t >= e.children.length) return e;
114
+ let n = [...e.children], r = n[s], a = n[t];
115
+ return !r || !a ? e : (n[s] = a, n[t] = r, Object.freeze({
116
+ ...e,
117
+ children: Object.freeze(n)
118
+ }));
119
+ }), a);
120
+ }
121
+ function l(t, n, i) {
122
+ return e(r(t, n, (e) => e.kind === "not" ? e.child : Object.freeze({
123
+ kind: "not",
124
+ child: e
125
+ })), i);
126
+ }
127
+ //#endregion
128
+ export { o as appendQueryChild, n as defaultQueryRule, c as moveQueryNode, t as queryBuilderFilterColumns, i as queryNodeAt, s as removeQueryNode, a as replaceQueryNode, l as toggleQueryNegation };
@@ -0,0 +1,26 @@
1
+ import type { PageResult, TablePagination } from "./pagination.ts";
2
+ export interface TableRequestState {
3
+ readonly pagination: TablePagination;
4
+ }
5
+ export interface TableRequestSnapshot<State, Result> {
6
+ readonly accepted: {
7
+ readonly state: State;
8
+ readonly result: Result;
9
+ } | null;
10
+ readonly requested: State | null;
11
+ readonly pending: boolean;
12
+ readonly error: unknown;
13
+ }
14
+ export type TableRequestOutcome = "accepted" | "failed" | "superseded" | "disposed";
15
+ export interface InitialTableResult<State, Result> {
16
+ readonly state: State;
17
+ readonly result: Result;
18
+ }
19
+ /** Framework-neutral request ownership. Read snapshots before/after awaiting request in the UI adapter. */
20
+ export declare function createTableRequests<State extends TableRequestState, Result extends PageResult<unknown>>(onStateChange: (state: State, signal: AbortSignal) => Promise<Result>, initial?: InitialTableResult<State, Result>): {
21
+ getSnapshot: () => TableRequestSnapshot<State, Result>;
22
+ request: (value: State) => Promise<TableRequestOutcome>;
23
+ retry: () => Promise<TableRequestOutcome>;
24
+ clear: () => void;
25
+ dispose: () => void;
26
+ };
@@ -0,0 +1,106 @@
1
+ import { assessServerPage as e, resolvePagination as t } from "./pagination.js";
2
+ //#region src/requests.ts
3
+ function n(n, r) {
4
+ let i = {
5
+ accepted: null,
6
+ requested: null,
7
+ pending: !1,
8
+ error: null
9
+ };
10
+ if (r) {
11
+ let n = structuredClone(r.state);
12
+ t("server", n.pagination);
13
+ let a = e(n.pagination, r.result);
14
+ if (a.kind !== "accepted") throw Error("Initial table results must describe a valid accepted page, not a page requiring refetch");
15
+ i = {
16
+ accepted: {
17
+ state: {
18
+ ...n,
19
+ pagination: a.pagination
20
+ },
21
+ result: r.result
22
+ },
23
+ requested: null,
24
+ pending: !1,
25
+ error: null
26
+ };
27
+ }
28
+ let a = 0n, o, s = !1, c = !1;
29
+ async function l(r) {
30
+ if (s) return "disposed";
31
+ if (c) return "superseded";
32
+ let l = ++a;
33
+ if (o?.abort(), s) return "disposed";
34
+ if (l !== a) return "superseded";
35
+ let u = new AbortController();
36
+ o = u, i = {
37
+ ...i,
38
+ requested: null,
39
+ pending: !0,
40
+ error: null
41
+ };
42
+ try {
43
+ let o = structuredClone(r);
44
+ t("server", o.pagination), i = {
45
+ ...i,
46
+ requested: structuredClone(o),
47
+ pending: !0,
48
+ error: null
49
+ };
50
+ for (let t = 0; t < 4; t++) {
51
+ let t = await n(structuredClone(o), u.signal);
52
+ if (s) return "disposed";
53
+ if (l !== a) return "superseded";
54
+ let r = e(o.pagination, t);
55
+ if (o = {
56
+ ...o,
57
+ pagination: r.pagination
58
+ }, r.kind === "accepted") return i = {
59
+ accepted: {
60
+ state: o,
61
+ result: t
62
+ },
63
+ requested: null,
64
+ pending: !1,
65
+ error: null
66
+ }, "accepted";
67
+ }
68
+ throw Error("Server page kept moving during clamping; retry the latest query");
69
+ } catch (e) {
70
+ return s ? "disposed" : l === a ? (i = {
71
+ ...i,
72
+ pending: !1,
73
+ error: e
74
+ }, "failed") : "superseded";
75
+ } finally {
76
+ l === a && (o = void 0);
77
+ }
78
+ }
79
+ function u() {
80
+ if (c) return;
81
+ c = !0, a++;
82
+ let e = o;
83
+ o = void 0, i = {
84
+ accepted: null,
85
+ requested: null,
86
+ pending: !1,
87
+ error: null
88
+ };
89
+ try {
90
+ e?.abort();
91
+ } finally {
92
+ c = !1;
93
+ }
94
+ }
95
+ return {
96
+ getSnapshot: () => i,
97
+ request: l,
98
+ retry: () => i.requested ? l(i.requested) : Promise.resolve(s ? "disposed" : "failed"),
99
+ clear: u,
100
+ dispose: () => {
101
+ s = !0, u();
102
+ }
103
+ };
104
+ }
105
+ //#endregion
106
+ export { n as createTableRequests };
@@ -0,0 +1,32 @@
1
+ export type HierarchyLoadOutcome = "changed" | "loaded" | "failed" | "superseded" | "busy" | "unchanged" | "disposed";
2
+ export interface RowHierarchyOptions<Row extends object> {
3
+ readonly getRowId: (row: Row) => string;
4
+ /** Return known children synchronously. Undefined means children are not loaded. */
5
+ readonly getChildren?: (row: Row) => readonly Row[] | undefined;
6
+ /** Marks an unloaded row as a parent. Defaults true for every unloaded row when loadChildren exists. */
7
+ readonly canLoadChildren?: (row: Row) => boolean;
8
+ readonly loadChildren?: (row: Row, signal: AbortSignal) => Promise<readonly Row[]>;
9
+ readonly defaultExpanded?: boolean | readonly string[] | ((row: Row) => boolean);
10
+ }
11
+ export interface HierarchyRow<Row extends object> {
12
+ readonly id: string;
13
+ readonly row: Row;
14
+ readonly parentId: string | null;
15
+ readonly depth: number;
16
+ readonly position: number;
17
+ readonly setSize: number;
18
+ readonly canExpand: boolean;
19
+ readonly expanded: boolean;
20
+ readonly unloaded: boolean;
21
+ readonly pending: boolean;
22
+ readonly error: unknown;
23
+ }
24
+ /** Owns expansion and independent child-load lifecycles without mutating application rows. */
25
+ export declare function createRowHierarchy<Row extends object>(options: RowHierarchyOptions<Row>): {
26
+ updateRoots: (nextRoots: readonly Row[]) => void;
27
+ getSnapshot: () => readonly HierarchyRow<Row>[];
28
+ setExpanded: (id: string, expanded: boolean) => Promise<HierarchyLoadOutcome>;
29
+ retry: (id: string) => Promise<HierarchyLoadOutcome>;
30
+ reset: () => void;
31
+ dispose(): void;
32
+ };
@@ -0,0 +1,170 @@
1
+ //#region src/row-hierarchy.ts
2
+ function e(e, t) {
3
+ if (!Array.isArray(e)) throw Error(`${t} must be an array`);
4
+ let n = [];
5
+ for (let r = 0; r < e.length; r++) {
6
+ if (!Object.hasOwn(e, r) || typeof e[r] != "object" || e[r] === null) throw Error(`${t}[${r}] must be an object`);
7
+ n.push(e[r]);
8
+ }
9
+ return Object.freeze(n);
10
+ }
11
+ function t(t) {
12
+ if (typeof t.getRowId != "function") throw Error("Row hierarchy requires getRowId");
13
+ if (t.getChildren !== void 0 && typeof t.getChildren != "function") throw Error("getChildren must be a function");
14
+ if (t.canLoadChildren !== void 0 && typeof t.canLoadChildren != "function") throw Error("canLoadChildren must be a function");
15
+ if (t.loadChildren !== void 0 && typeof t.loadChildren != "function") throw Error("loadChildren must be a function");
16
+ let n = t.defaultExpanded, r = typeof n == "object" ? n : void 0, i = r ? /* @__PURE__ */ new Set() : void 0;
17
+ if (r && i) for (let e of r) {
18
+ if (typeof e != "string" || !e.trim() || i.has(e)) throw Error("defaultExpanded IDs must be unique nonempty strings");
19
+ i.add(e);
20
+ }
21
+ let a = Object.freeze([]), o = Object.freeze([]), s = /* @__PURE__ */ new Map(), c = /* @__PURE__ */ new WeakMap(), l = !1;
22
+ function u(e, n) {
23
+ return i ? i.has(n) : typeof t.defaultExpanded == "function" ? t.defaultExpanded(e) : t.defaultExpanded === !0;
24
+ }
25
+ function d(n, r) {
26
+ let i = e(n, "Hierarchy roots"), a = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Set(), l = [], u = /* @__PURE__ */ new Set();
27
+ function d(n, i, f) {
28
+ let p = [];
29
+ for (let m = 0; m < n.length; m++) {
30
+ let h = n[m];
31
+ if (u.has(h)) throw Error("Row hierarchy contains an object cycle");
32
+ let g = t.getRowId(h);
33
+ if (typeof g != "string" || !g.trim() || g.trim() !== g) throw Error(`Hierarchy row at depth ${f} position ${m + 1} has an invalid ID`);
34
+ if (o.has(g)) throw Error(`Duplicate hierarchy row ID: ${g}`);
35
+ o.add(g);
36
+ let _ = c.get(h);
37
+ if (_ !== void 0 && _ !== g) throw Error(`Hierarchy row identity changed from ${_} to ${g}`);
38
+ l.push({
39
+ row: h,
40
+ id: g
41
+ }), u.add(h);
42
+ let v = t.getChildren?.(h), y = v !== void 0, b = y ? e(v, `Children of ${g}`) : r?.get(g) ?? s.get(g)?.loaded, x = b === void 0 ? void 0 : e(b, `Children of ${g}`), S = x === void 0 ? void 0 : d(x, g, f + 1);
43
+ u.delete(h);
44
+ let C = !y && S === void 0 && !!(t.loadChildren && (t.canLoadChildren?.(h) ?? !0));
45
+ a.set(g, Object.freeze({
46
+ id: g,
47
+ row: h,
48
+ parentId: i,
49
+ depth: f,
50
+ position: m + 1,
51
+ setSize: n.length,
52
+ children: S,
53
+ loadable: C,
54
+ staticChildren: y
55
+ })), p.push(g);
56
+ }
57
+ return Object.freeze(p);
58
+ }
59
+ return {
60
+ roots: i,
61
+ rootIds: d(i, null, 1),
62
+ descriptors: a,
63
+ objectIds: Object.freeze(l)
64
+ };
65
+ }
66
+ function f(e, t) {
67
+ let n = new Set(e.descriptors.keys());
68
+ for (let [e, t] of s) n.has(e) || (t.token++, t.controller?.abort(), s.delete(e));
69
+ for (let n of e.descriptors.values()) {
70
+ let e = s.get(n.id);
71
+ e ? (Object.assign(e, n), n.staticChildren ? e.loaded = void 0 : t?.has(n.id) && (e.loaded = t.get(n.id))) : s.set(n.id, {
72
+ ...n,
73
+ expanded: u(n.row, n.id),
74
+ pending: !1,
75
+ error: null,
76
+ token: 0,
77
+ controller: void 0,
78
+ loaded: t?.get(n.id)
79
+ });
80
+ }
81
+ for (let t of e.objectIds) c.set(t.row, t.id);
82
+ a = e.roots, o = e.rootIds;
83
+ }
84
+ function p(e) {
85
+ l || f(d(e));
86
+ }
87
+ function m() {
88
+ let e = [];
89
+ function t(n) {
90
+ for (let r of n) {
91
+ let n = s.get(r);
92
+ if (!n) continue;
93
+ let i = !!n.children?.length || n.loadable || n.pending || n.error !== null;
94
+ e.push(Object.freeze({
95
+ id: n.id,
96
+ row: n.row,
97
+ parentId: n.parentId,
98
+ depth: n.depth,
99
+ position: n.position,
100
+ setSize: n.setSize,
101
+ canExpand: i,
102
+ expanded: i && n.expanded,
103
+ unloaded: n.children === void 0 && n.loadable,
104
+ pending: n.pending,
105
+ error: n.error
106
+ })), n.expanded && n.children && t(n.children);
107
+ }
108
+ }
109
+ return t(o), Object.freeze(e);
110
+ }
111
+ async function h(n) {
112
+ if (l) return "disposed";
113
+ let r = s.get(n), i = t.loadChildren;
114
+ if (!r || !r.loadable || !i) return "unchanged";
115
+ if (r.pending) return "busy";
116
+ let o = ++r.token, c = new AbortController();
117
+ r.controller = c, r.pending = !0, r.error = null;
118
+ let u = r.row;
119
+ try {
120
+ let t = e(await i(u, c.signal), `Loaded children of ${n}`);
121
+ if (l) return "disposed";
122
+ let r = s.get(n);
123
+ if (!r || r.token !== o) return "superseded";
124
+ let p = /* @__PURE__ */ new Map([[n, t]]), m = d(a, p);
125
+ r.loaded = t, f(m, p);
126
+ let h = s.get(n);
127
+ return h && (h.pending = !1, h.error = null, h.controller = void 0), "loaded";
128
+ } catch (e) {
129
+ if (l) return "disposed";
130
+ let t = s.get(n);
131
+ return !t || t.token !== o ? "superseded" : (t.pending = !1, t.error = e, t.controller = void 0, "failed");
132
+ }
133
+ }
134
+ function g(e, t) {
135
+ if (l) return Promise.resolve("disposed");
136
+ let n = s.get(e);
137
+ if (!n || !(n.children?.length || n.loadable || n.pending || n.error !== null)) return Promise.resolve("unchanged");
138
+ if (!t) {
139
+ if (!n.expanded && !n.pending) return Promise.resolve("unchanged");
140
+ if (n.expanded = !1, n.pending) {
141
+ n.token++, n.pending = !1;
142
+ let e = n.controller;
143
+ n.controller = void 0, e?.abort();
144
+ }
145
+ return Promise.resolve("changed");
146
+ }
147
+ return n.expanded = !0, n.children === void 0 ? h(e) : Promise.resolve("changed");
148
+ }
149
+ function _(e) {
150
+ if (l) return Promise.resolve("disposed");
151
+ let t = s.get(e);
152
+ return !t || t.error === null ? Promise.resolve("unchanged") : (t.expanded = !0, h(e));
153
+ }
154
+ function v() {
155
+ for (let e of s.values()) e.token++, e.controller?.abort();
156
+ s.clear(), a = Object.freeze([]), o = Object.freeze([]);
157
+ }
158
+ return {
159
+ updateRoots: p,
160
+ getSnapshot: m,
161
+ setExpanded: g,
162
+ retry: _,
163
+ reset: v,
164
+ dispose() {
165
+ l = !0, v();
166
+ }
167
+ };
168
+ }
169
+ //#endregion
170
+ export { t as createRowHierarchy };
@@ -0,0 +1,11 @@
1
+ export interface IdentifiedRow<Row extends object> {
2
+ readonly id: string;
3
+ readonly row: Row;
4
+ readonly index: number;
5
+ }
6
+ /** Validate IDs once per resolution and detect changes for reused row objects. */
7
+ export declare function createRowIdentity<Row extends object>(getRowId: (row: Row) => string): {
8
+ resolve: (rows: readonly Row[]) => readonly IdentifiedRow<Row>[];
9
+ resolveIds: (rows: readonly Row[]) => readonly string[];
10
+ clear(): void;
11
+ };
@@ -0,0 +1,36 @@
1
+ //#region src/row-identity.ts
2
+ function e(e) {
3
+ if (typeof e != "function") throw Error("getRowId must be a function");
4
+ let t = /* @__PURE__ */ new WeakMap();
5
+ function n(n) {
6
+ if (!Array.isArray(n)) throw Error("Table rows must be an array");
7
+ let r = /* @__PURE__ */ new Set(), i = [], a = 0;
8
+ for (let o of n) {
9
+ if (typeof o != "object" || !o) throw Error(`rows[${a}] must be an object`);
10
+ let n = e(o);
11
+ if (typeof n != "string" || !n || n.trim() !== n) throw Error(`rows[${a}] has an invalid stable ID`);
12
+ if (r.has(n)) throw Error(`rows[${a}] duplicates row ID ${n}`);
13
+ let s = t.get(o);
14
+ if (s !== void 0 && s !== n) throw Error(`rows[${a}] changed stable ID from ${s} to ${n}`);
15
+ r.add(n), t.set(o, n), i.push(n), a++;
16
+ }
17
+ return Object.freeze(i);
18
+ }
19
+ function r(e) {
20
+ let t = n(e);
21
+ return Object.freeze(e.map((e, n) => Object.freeze({
22
+ id: t[n],
23
+ row: e,
24
+ index: n
25
+ })));
26
+ }
27
+ return {
28
+ resolve: r,
29
+ resolveIds: n,
30
+ clear() {
31
+ t = /* @__PURE__ */ new WeakMap();
32
+ }
33
+ };
34
+ }
35
+ //#endregion
36
+ export { e as createRowIdentity };