@cronocode/react-box 3.1.3 → 3.1.7

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.
@@ -1,43 +1,57 @@
1
- import { jsxs as h, jsx as s, Fragment as ke } from "react/jsx-runtime";
2
- import p from "../box.mjs";
3
- import g from "./flex.mjs";
4
- import Te, { useCallback as X, useMemo as j, useState as te, useRef as De, useEffect as Q } from "react";
5
- import { F as le, m as P, E as ae, b as de, D as Se, S as Z, P as ne, G as ee, C as _e } from "../core.mjs";
6
- import ce from "./grid.mjs";
7
- import q from "./checkbox.mjs";
8
- import w from "./button.mjs";
9
- import { Span as D } from "./semantics.mjs";
10
- import he from "./tooltip.mjs";
11
- import Be from "./baseSvg.mjs";
12
- function Pe(l) {
13
- const { grid: e } = l;
14
- return /* @__PURE__ */ h(g, { component: "datagrid.bottomBar", children: [
15
- /* @__PURE__ */ h(p, { children: [
1
+ import { jsxs as d, jsx as n, Fragment as Be } from "react/jsx-runtime";
2
+ import Ee, { useCallback as k, useMemo as X, useState as M, useRef as O, useEffect as z, useLayoutEffect as Pe } from "react";
3
+ import g from "../box.mjs";
4
+ import m from "./flex.mjs";
5
+ import me from "./grid.mjs";
6
+ import { F as Ie, m as P, f as ae, E as ge, b as Me, D as He, S as oe, P as ce, G as se, d as ze } from "../core.mjs";
7
+ import le from "./checkbox.mjs";
8
+ import D from "./button.mjs";
9
+ import fe from "./baseSvg.mjs";
10
+ import b from "./dropdown.mjs";
11
+ import j from "./textbox.mjs";
12
+ import { Span as I } from "./semantics.mjs";
13
+ import Ae from "./tooltip.mjs";
14
+ function Oe(s) {
15
+ const { grid: e } = s, { filtered: t, total: i } = e.filterStats, r = e.hasActiveFilters;
16
+ return /* @__PURE__ */ d(m, { component: "datagrid.bottomBar", children: [
17
+ /* @__PURE__ */ d(g, { children: [
16
18
  "Rows: ",
17
- e.props.data.length
19
+ r ? `${t} / ${i}` : i
18
20
  ] }),
19
- e.props.def.rowSelection && /* @__PURE__ */ h(p, { children: [
21
+ e.props.def.rowSelection && /* @__PURE__ */ d(g, { children: [
20
22
  "Selected: ",
21
23
  e.selectedRows.size
22
- ] })
24
+ ] }),
25
+ r && /* @__PURE__ */ n(g, { color: "blue-600", cursor: "pointer", hover: { textDecoration: "underline" }, props: { onClick: e.clearAllFilters }, children: "Clear filters" })
23
26
  ] });
24
27
  }
25
- function ue(l) {
26
- const { cell: e } = l, t = X(() => {
28
+ function Ce(s) {
29
+ const { cell: e } = s, t = k(() => {
27
30
  e.grid.toggleRowSelection(e.row.key);
28
31
  }, [e.grid, e.row.key]);
29
- return /* @__PURE__ */ s(q, { variant: "datagrid", checked: e.row.selected, onChange: t });
32
+ return /* @__PURE__ */ n(le, { variant: "datagrid", checked: e.row.selected, onChange: t });
30
33
  }
31
- ue.displayName = "DataGridCellRowSelection";
32
- const Ee = "NO_PIN";
33
- class S {
34
+ Ce.displayName = "DataGridCellRowSelection";
35
+ const $e = "NO_PIN";
36
+ class A {
34
37
  constructor(e, t, i) {
35
- this.def = e, this.grid = t, this.parent = i, this.columns = e.columns?.map((n) => new S(e.pin ? { ...n, pin: e.pin } : n, t, this)) ?? [], this.isLeaf && (this._inlineWidth = this.key == E ? void 0 : this.def.width ?? this.grid.DEFAULT_COLUMN_WIDTH_PX, this._pin = e.pin);
38
+ if (this.def = e, this.grid = t, this.parent = i, this.columns = e.columns?.map((r) => new A(e.pin ? { ...r, pin: e.pin } : r, t, this)) ?? [], this.isLeaf) {
39
+ const r = this.grid.columnWidths.get(this.key);
40
+ this._inlineWidth = this.key == V ? void 0 : r ?? this.def.width ?? this.grid.DEFAULT_COLUMN_WIDTH_PX, this._pin = e.pin;
41
+ }
36
42
  }
37
43
  columns = [];
38
44
  get visibleColumns() {
39
45
  return this.columns.filter((e) => e.isVisible);
40
46
  }
47
+ get isFirstLeaf() {
48
+ const { leafs: e } = this;
49
+ return e.length > 0 && e.at(0) === this;
50
+ }
51
+ get isLastLeaf() {
52
+ const { leafs: e } = this;
53
+ return e.length > 0 && e.at(-1) === this;
54
+ }
41
55
  get key() {
42
56
  return this.def.key;
43
57
  }
@@ -53,6 +67,25 @@ class S {
53
67
  get Cell() {
54
68
  return this.def.Cell;
55
69
  }
70
+ get filterable() {
71
+ return this.def.filterable;
72
+ }
73
+ /** Whether sorting is enabled for this column. Column-level setting takes priority over grid-level. */
74
+ get sortable() {
75
+ return this.def.sortable !== void 0 ? this.def.sortable : this.grid.props.def.sortable !== !1;
76
+ }
77
+ /** Whether resizing is enabled for this column. Column-level setting takes priority over grid-level. */
78
+ get resizable() {
79
+ return this.def.resizable !== void 0 ? this.def.resizable : this.grid.props.def.resizable !== !1;
80
+ }
81
+ /** Whether column participates in flex distribution. Default true unless explicitly false. */
82
+ get isFlexible() {
83
+ return this.def.flexible !== !1;
84
+ }
85
+ /** The base width before flex calculation (what user set or DEFAULT). */
86
+ get baseWidth() {
87
+ return this._inlineWidth ?? this.grid.DEFAULT_COLUMN_WIDTH_PX;
88
+ }
56
89
  _pin;
57
90
  get pin() {
58
91
  if (this.isLeaf) return this._pin;
@@ -65,10 +98,10 @@ class S {
65
98
  getPinnedColumn(e) {
66
99
  if (this.hasPin(e)) {
67
100
  if (this.isLeaf) return this;
68
- const t = new S({ ...this.def, pin: e }, this.grid, this.parent);
101
+ const t = new A({ ...this.def, pin: e }, this.grid, this.parent);
69
102
  return t.columns = this.columns.filter((i) => i.hasPin(e)).map((i) => {
70
- const n = i.getPinnedColumn(e);
71
- return n.parent = t, n;
103
+ const r = i.getPinnedColumn(e);
104
+ return r.parent = t, r;
72
105
  }).filter((i) => !!i), t;
73
106
  }
74
107
  }
@@ -84,7 +117,8 @@ class S {
84
117
  }
85
118
  _inlineWidth;
86
119
  get inlineWidth() {
87
- if (this.isLeaf) return this._inlineWidth;
120
+ if (this.isLeaf)
121
+ return this.grid.getFlexWidth(this.key) ?? this._inlineWidth;
88
122
  const e = this.visibleColumns.map((t) => t.inlineWidth).filter((t) => typeof t == "number");
89
123
  if (e.length !== 0)
90
124
  return e.sumBy((t) => t);
@@ -92,22 +126,22 @@ class S {
92
126
  get left() {
93
127
  let e = 0;
94
128
  if (this.parent) {
95
- const { visibleColumns: t, left: i } = this.parent, n = t.findIndex((o) => o === this);
96
- e += t.sumBy((o, r) => r < n ? o.inlineWidth ?? 0 : 0), e += i;
129
+ const { visibleColumns: t, left: i } = this.parent, r = t.findIndex((o) => o === this);
130
+ e += t.sumBy((o, a) => a < r ? o.inlineWidth ?? 0 : 0), e += i;
97
131
  } else {
98
- const t = this.grid.columns.value.left.filter((n) => n.isVisible), i = t.findIndex((n) => n === this);
99
- e += t.sumBy((n, o) => o < i ? n.inlineWidth ?? 0 : 0);
132
+ const t = this.grid.columns.value.left.filter((r) => r.isVisible), i = t.findIndex((r) => r === this);
133
+ e += t.sumBy((r, o) => o < i ? r.inlineWidth ?? 0 : 0);
100
134
  }
101
135
  return e;
102
136
  }
103
137
  get right() {
104
138
  let e = 0;
105
139
  if (this.parent) {
106
- const { visibleColumns: t } = this.parent, i = t.reverse(), n = i.findIndex((o) => o === this);
107
- e += i.sumBy((o, r) => r < n ? o.inlineWidth ?? 0 : 0), e += this.parent.right;
140
+ const { visibleColumns: t } = this.parent, i = t.reverse(), r = i.findIndex((o) => o === this);
141
+ e += i.sumBy((o, a) => a < r ? o.inlineWidth ?? 0 : 0), e += this.parent.right;
108
142
  } else {
109
- const i = this.grid.columns.value.right.filter((o) => o.isVisible).reverse(), n = i.findIndex((o) => o === this);
110
- e += i.sumBy((o, r) => r < n ? o.inlineWidth ?? 0 : 0);
143
+ const i = this.grid.columns.value.right.filter((o) => o.isVisible).reverse(), r = i.findIndex((o) => o === this);
144
+ e += i.sumBy((o, a) => a < r ? o.inlineWidth ?? 0 : 0);
111
145
  }
112
146
  return e;
113
147
  }
@@ -142,17 +176,16 @@ class S {
142
176
  return this.isLeaf ? this.grid.columns.value.maxDeath - this.death : 1;
143
177
  }
144
178
  resizeColumn = (e) => {
145
- this.grid.isResizeMode = !0;
146
- const t = e.pageX, { MIN_COLUMN_WIDTH_PX: i, update: n } = this.grid, o = this.leafs.sumBy((d) => d.inlineWidth) - this.leafs.length * i, r = this.leafs.toRecord((d) => [d.key, d.inlineWidth]), u = le.throttle((d) => {
147
- const m = (d.pageX - t) * (this.pin === "RIGHT" ? -1 : 1);
179
+ const t = e.pageX, { MIN_COLUMN_WIDTH_PX: i, update: r } = this.grid, o = this.leafs.toRecord((c) => [c.key, c.inlineWidth ?? c.baseWidth]), a = this.leafs.sumBy((c) => o[c.key]) - this.leafs.length * i, h = Ie.throttle((c) => {
180
+ const p = (c.pageX - t) * (this.pin === "RIGHT" ? -1 : 1);
148
181
  this.leafs.forEach((f) => {
149
- const R = r[f.key], y = o > 0 ? (R - i) / o * m : m / this.leafs.length, k = Math.round(R + y);
150
- f.setWidth(k < i ? i : k);
151
- }), this.grid.sizes.clear(), n();
152
- }, 40), a = new AbortController(), c = (d) => {
153
- a.abort(), this.grid.isResizeMode = !1, n();
182
+ const y = o[f.key], v = a > 0 ? (y - i) / a * p : p / this.leafs.length, R = Math.round(y + v);
183
+ f.setWidth(R < i ? i : R);
184
+ }), this.grid.flexWidths.clear(), this.grid.sizes.clear(), r();
185
+ }, 40), u = new AbortController(), l = (c) => {
186
+ u.abort(), r();
154
187
  };
155
- window.addEventListener("mousemove", u, a), window.addEventListener("mouseup", c, a);
188
+ window.addEventListener("mousemove", h, u), window.addEventListener("mouseup", l, u);
156
189
  };
157
190
  pinColumn = (e) => {
158
191
  this.isLeaf ? this._pin = e : this.columns.forEach((t) => t.pinColumn(e)), this.grid.pinColumn(this.uniqueKey, e);
@@ -172,15 +205,15 @@ class S {
172
205
  this.grid.toggleColumnVisibility(this.key);
173
206
  };
174
207
  }
175
- class Me {
208
+ class Ue {
176
209
  constructor(e, t, i) {
177
210
  this.grid = e, this.row = t, this.column = i;
178
211
  }
179
212
  get value() {
180
- return this.column.key === C ? this.row.rowIndex + 1 : this.row.data[this.column.key];
213
+ return this.column.key === G ? this.row.rowIndex + 1 : this.row.data[this.column.key];
181
214
  }
182
215
  }
183
- class oe {
216
+ class ue {
184
217
  constructor(e, t, i) {
185
218
  this.grid = e, this.data = t, this.rowIndex = i, this.grid = e, this.data = t, this.key = this.grid.getRowKey(t);
186
219
  }
@@ -188,7 +221,7 @@ class oe {
188
221
  parentRow;
189
222
  count = 1;
190
223
  get cells() {
191
- return this.grid.columns.value.visibleLeafs.map((e) => new Me(this.grid, this, e));
224
+ return this.grid.columns.value.visibleLeafs.map((e) => new Ue(this.grid, this, e));
192
225
  }
193
226
  get selected() {
194
227
  return this.grid.selectedRows.has(this.key);
@@ -200,69 +233,200 @@ class oe {
200
233
  return this;
201
234
  }
202
235
  }
203
- const E = "empty-cell", C = "row-number-cell", se = 70, _ = "row-selection-cell", x = "grouping-cell";
204
- class Ne {
236
+ const V = "empty-cell", G = "row-number-cell", he = 70, _ = "row-selection-cell", T = "grouping-cell";
237
+ class je {
205
238
  constructor(e, t) {
206
239
  this.props = e, this.update = t, console.debug("\x1B[32m%s\x1B[0m", "[react-box]: DataGrid GridModel ctor");
207
240
  }
208
241
  sourceColumns = P(() => {
209
242
  const { def: e } = this.props, t = [];
210
- if (this.groupColumns.size > 0 && t.push(new S({ key: x }, this)), t.push(...e.columns.map((i) => new S(i, this))), t.push(new S({ key: E, Cell: () => null }, this)), e.rowSelection) {
243
+ if (this.groupColumns.size > 0 && t.push(new A({ key: T }, this)), t.push(...e.columns.map((i) => new A(i, this))), e.rowSelection) {
211
244
  const i = typeof e.rowSelection == "object" && e.rowSelection.pinned ? "LEFT" : void 0;
212
245
  t.unshift(
213
- new S({ key: _, pin: i, width: 50, align: "center", Cell: ue }, this)
246
+ new A({ key: _, pin: i, width: 50, align: "center", Cell: Ce }, this)
214
247
  );
215
248
  }
216
249
  if (e.showRowNumber) {
217
- let i, n = se;
218
- typeof e.showRowNumber == "object" && (e.showRowNumber.pinned && (i = "LEFT"), n = e.showRowNumber.width ?? se), t.unshift(new S({ key: C, pin: i, width: n, align: "right" }, this));
250
+ let i, r = he;
251
+ typeof e.showRowNumber == "object" && (e.showRowNumber.pinned && (i = "LEFT"), r = e.showRowNumber.width ?? he), t.unshift(new A({ key: G, pin: i, width: r, align: "right" }, this));
219
252
  }
220
253
  return t;
221
254
  });
222
255
  columns = P(() => {
223
256
  console.debug("\x1B[36m%s\x1B[0m", "[react-box]: DataGrid columns memo");
224
- const e = this.sourceColumns.value.map((a) => a.getPinnedColumn("LEFT")).filter((a) => !!a), t = this.sourceColumns.value.map((a) => a.getPinnedColumn()).filter((a) => !!a), i = this.sourceColumns.value.map((a) => a.getPinnedColumn("RIGHT")).filter((a) => !!a), n = [...e, ...t, ...i].flatMap((a) => a.flatColumns), o = n.filter((a) => a.isLeaf), r = n.filter((a) => a.isLeaf && a.isVisible), u = n.maxBy((a) => a.death) + 1;
257
+ const e = this.sourceColumns.value.map((l) => l.getPinnedColumn("LEFT")).filter((l) => !!l), t = this.sourceColumns.value.map((l) => l.getPinnedColumn()).filter((l) => !!l), i = this.sourceColumns.value.map((l) => l.getPinnedColumn("RIGHT")).filter((l) => !!l), r = [...e, ...t, ...i].flatMap((l) => l.flatColumns), o = r.filter((l) => l.isLeaf), a = r.filter((l) => l.isLeaf && l.isVisible), h = a.filter(
258
+ (l) => ![V, G, _, T].includes(l.key)
259
+ ), u = r.maxBy((l) => l.death) + 1;
225
260
  return {
226
261
  left: e,
227
262
  middle: t,
228
263
  right: i,
229
- flat: n,
264
+ flat: r,
230
265
  leafs: o,
231
- visibleLeafs: r,
266
+ visibleLeafs: a,
267
+ userVisibleLeafs: h,
232
268
  maxDeath: u
233
269
  };
234
270
  });
235
271
  headerRows = P(() => (console.debug("\x1B[36m%s\x1B[0m", "[react-box]: DataGrid headerRows memo"), this.columns.value.flat.groupBy((t) => t.death).sortBy((t) => t.key).map((t) => {
236
- const i = t.values.groupBy((n) => n.pin ?? Ee).toRecord((n) => [n.key, n.values]);
272
+ const i = t.values.groupBy((r) => r.pin ?? $e).toRecord((r) => [r.key, r.values]);
237
273
  return [
238
- ...i.LEFT?.filter((n) => n.isVisible) ?? [],
239
- ...i.NO_PIN?.filter((n) => n.isVisible) ?? [],
240
- ...i.RIGHT?.filter((n) => n.isVisible) ?? []
274
+ ...i.LEFT?.filter((r) => r.isVisible) ?? [],
275
+ ...i.NO_PIN?.filter((r) => r.isVisible) ?? [],
276
+ ...i.RIGHT?.filter((r) => r.isVisible) ?? []
241
277
  ];
242
278
  })));
243
279
  gridTemplateColumns = P(() => {
244
280
  console.debug("\x1B[36m%s\x1B[0m", "[react-box]: DataGrid gridTemplateColumns memo");
245
- const { visibleLeafs: e } = this.columns.value, t = e.sumBy((r) => r.pin === "RIGHT" ? 1 : 0), i = e.length - t - 1, n = i > 0 ? `repeat(${i}, max-content)` : "", o = t > 0 ? `repeat(${t}, max-content)` : "";
246
- return `${n} auto ${o}`;
281
+ const { visibleLeafs: e } = this.columns.value, t = e.sumBy((a) => a.pin === "RIGHT" ? 1 : 0), i = e.length - t, r = i > 0 ? `repeat(${i}, max-content)` : "", o = t > 0 ? `repeat(${t}, max-content)` : "";
282
+ return `${r} ${o}`.trim();
247
283
  });
284
+ // ========== Filtering ==========
285
+ _globalFilterValue = "";
286
+ get globalFilterValue() {
287
+ return this.props.globalFilterValue ?? this._globalFilterValue;
288
+ }
289
+ _columnFilters = {};
290
+ get columnFilters() {
291
+ return this.props.columnFilters ?? this._columnFilters;
292
+ }
293
+ /**
294
+ * Apply global filter (fuzzy search across all or specified columns)
295
+ */
296
+ applyGlobalFilter(e) {
297
+ const t = this.globalFilterValue.trim();
298
+ if (!t) return e;
299
+ const { globalFilterKeys: i } = this.props.def, r = i ?? this.columns.value.leafs.filter(
300
+ (o) => o.key !== V && o.key !== G && o.key !== _ && o.key !== T
301
+ ).map((o) => o.key);
302
+ return e.filter((o) => r.some((a) => {
303
+ const h = o[a];
304
+ return h == null ? !1 : ae(t, String(h));
305
+ }));
306
+ }
307
+ /**
308
+ * Apply column-level filters
309
+ */
310
+ applyColumnFilters(e) {
311
+ const t = this.columnFilters, i = Object.keys(t);
312
+ return i.length === 0 ? e : e.filter((r) => i.every((o) => {
313
+ const a = t[o];
314
+ if (!a) return !0;
315
+ const h = r[o];
316
+ return this.matchesFilter(h, a);
317
+ }));
318
+ }
319
+ /**
320
+ * Check if a cell value matches a filter
321
+ */
322
+ matchesFilter(e, t) {
323
+ switch (t.type) {
324
+ case "text":
325
+ return t.value.trim() ? e == null ? !1 : ae(t.value, String(e)) : !0;
326
+ case "number": {
327
+ if (e == null) return !1;
328
+ const i = typeof e == "number" ? e : parseFloat(String(e));
329
+ if (isNaN(i)) return !1;
330
+ switch (t.operator) {
331
+ case "eq":
332
+ return i === t.value;
333
+ case "ne":
334
+ return i !== t.value;
335
+ case "gt":
336
+ return i > t.value;
337
+ case "gte":
338
+ return i >= t.value;
339
+ case "lt":
340
+ return i < t.value;
341
+ case "lte":
342
+ return i <= t.value;
343
+ case "between":
344
+ return t.valueTo !== void 0 ? i >= t.value && i <= t.valueTo : i >= t.value;
345
+ default:
346
+ return !0;
347
+ }
348
+ }
349
+ case "multiselect":
350
+ return t.values.length === 0 ? !0 : t.values.includes(e);
351
+ default:
352
+ return !0;
353
+ }
354
+ }
355
+ /**
356
+ * Get filtered data (applies global filter then column filters)
357
+ */
358
+ get filteredData() {
359
+ let e = this.props.data;
360
+ return this.props.def.globalFilter && (e = this.applyGlobalFilter(e)), e = this.applyColumnFilters(e), e;
361
+ }
362
+ /**
363
+ * Set global filter value
364
+ */
365
+ setGlobalFilter = (e) => {
366
+ this.props.onGlobalFilterChange ? this.props.onGlobalFilterChange(e) : this._globalFilterValue = e, this.rows.clear(), this.flatRows.clear(), this.update();
367
+ };
368
+ /**
369
+ * Set a single column filter
370
+ */
371
+ setColumnFilter = (e, t) => {
372
+ const i = { ...this.columnFilters };
373
+ t === void 0 ? delete i[e] : i[e] = t, this.props.onColumnFiltersChange ? this.props.onColumnFiltersChange(i) : this._columnFilters = i, this.rows.clear(), this.flatRows.clear(), this.update();
374
+ };
375
+ /**
376
+ * Clear all column filters
377
+ */
378
+ clearColumnFilters = () => {
379
+ this.props.onColumnFiltersChange ? this.props.onColumnFiltersChange({}) : this._columnFilters = {}, this.rows.clear(), this.flatRows.clear(), this.update();
380
+ };
381
+ /**
382
+ * Clear all filters (global + column)
383
+ */
384
+ clearAllFilters = () => {
385
+ this.setGlobalFilter(""), this.clearColumnFilters();
386
+ };
387
+ /**
388
+ * Get unique values for a column (used for multiselect filter options)
389
+ */
390
+ getColumnUniqueValues = (e) => {
391
+ const t = /* @__PURE__ */ new Set();
392
+ return this.props.data.forEach((i) => {
393
+ const r = i[e];
394
+ r !== void 0 && t.add(r);
395
+ }), Array.from(t).sort((i, r) => i === null ? 1 : r === null ? -1 : typeof i == "string" && typeof r == "string" ? i.localeCompare(r) : typeof i == "number" && typeof r == "number" ? i - r : String(i).localeCompare(String(r)));
396
+ };
397
+ /**
398
+ * Check if any filter is active
399
+ */
400
+ get hasActiveFilters() {
401
+ return this.globalFilterValue.trim() !== "" || Object.keys(this.columnFilters).length > 0;
402
+ }
403
+ /**
404
+ * Get count of filtered rows vs total rows
405
+ */
406
+ get filterStats() {
407
+ return {
408
+ filtered: this.filteredData.length,
409
+ total: this.props.data.length
410
+ };
411
+ }
248
412
  rows = P(() => {
249
413
  console.debug("\x1B[36m%s\x1B[0m", "[react-box]: DataGrid rows memo");
250
- let e = this.props.data;
414
+ let e = this.filteredData;
251
415
  if (this._sortColumn && (e = e.sortBy((t) => t[this._sortColumn], this._sortDirection)), this.groupColumns.size > 0) {
252
- const t = (i, n, o) => {
253
- const r = n.values().next().value;
254
- n.delete(r);
255
- const u = this.columns.value.leafs.findOrThrow((a) => a.key === r);
256
- return this._sortColumn === x && (i = i.sortBy((a) => a[r], this._sortDirection)), i.groupBy((a) => a[r]).map((a) => {
257
- let c;
258
- n.size > 0 ? c = t(a.values, new Set(n), o + 1) : c = a.values.map((m, f) => new oe(this, m, o + 1 + f));
259
- const d = new me(this, u, c, o, a.key);
260
- return o += 1, d.expanded && (o += c.length), d;
416
+ const t = (i, r, o) => {
417
+ const a = r.values().next().value;
418
+ r.delete(a);
419
+ const h = this.columns.value.leafs.findOrThrow((u) => u.key === a);
420
+ return this._sortColumn === T && (i = i.sortBy((u) => u[a], this._sortDirection)), i.groupBy((u) => u[a]).map((u) => {
421
+ let l;
422
+ r.size > 0 ? l = t(u.values, new Set(r), o + 1) : l = u.values.map((p, f) => new ue(this, p, o + 1 + f));
423
+ const c = new we(this, h, l, o, u.key);
424
+ return o += 1, c.expanded && (o += l.length), c;
261
425
  });
262
426
  };
263
427
  return t(e, new Set(this.groupColumns), 0);
264
428
  }
265
- return e.map((t, i) => new oe(this, t, i));
429
+ return e.map((t, i) => new ue(this, t, i));
266
430
  });
267
431
  flatRows = P(() => (console.debug("\x1B[36m%s\x1B[0m", "[react-box]: DataGrid flatRows memo"), this.rows.value.flatMap((e) => e.flatRows)));
268
432
  get rowHeight() {
@@ -270,25 +434,53 @@ class Ne {
270
434
  }
271
435
  sizes = P(() => {
272
436
  console.debug("\x1B[36m%s\x1B[0m", "[react-box]: DataGrid sizes memo");
273
- const e = this.columns.value.flat.reduce((n, o) => {
274
- const { inlineWidth: r } = o;
275
- return typeof r == "number" && (n[o.widthVarName] = `${o.inlineWidth}px`), o.pin === "LEFT" && (n[o.leftVarName] = `${o.left}px`), o.pin === "RIGHT" && (n[o.rightVarName] = `${o.right}px`), n;
437
+ const e = this.columns.value.flat.reduce((r, o) => {
438
+ const { inlineWidth: a } = o;
439
+ return typeof a == "number" && (r[o.widthVarName] = `${o.inlineWidth}px`), o.pin === "LEFT" && (r[o.leftVarName] = `${o.left}px`), o.pin === "RIGHT" && (r[o.rightVarName] = `${o.right}px`), r;
276
440
  }, {});
277
441
  e[this.rowHeightVarName] = `${this.rowHeight}px`, e[this.leftEdgeVarName] = `${this.leftEdge}px`;
278
- const { visibleLeafs: t } = this.columns.value, i = t.find((n) => n.key === x);
442
+ const { visibleLeafs: t } = this.columns.value, i = t.find((r) => r.key === T);
279
443
  if (i) {
280
- const n = t.sumBy((o) => o.pin === i.pin && o.key !== C && o.key !== _ ? o.inlineWidth ?? 0 : 0);
281
- e[i.groupColumnWidthVarName] = `${n}px`;
444
+ const r = t.sumBy((o) => o.pin === i.pin && o.key !== G && o.key !== _ ? o.inlineWidth ?? 0 : 0);
445
+ e[i.groupColumnWidthVarName] = `${r}px`;
282
446
  }
283
- return this.groupColumns.forEach((n) => {
284
- const o = this.columns.value.leafs.findOrThrow((r) => r.key === n);
285
- e[o.groupColumnWidthVarName] = `${t.sumBy((r) => r.pin === o.pin ? r.inlineWidth ?? 0 : 0)}px`;
447
+ return this.groupColumns.forEach((r) => {
448
+ const o = this.columns.value.leafs.findOrThrow((a) => a.key === r);
449
+ e[o.groupColumnWidthVarName] = `${t.sumBy((a) => a.pin === o.pin ? a.inlineWidth ?? 0 : 0)}px`;
286
450
  }), e;
287
451
  });
452
+ // ========== Flexible Column Sizing ==========
453
+ _containerWidth = 0;
454
+ get containerWidth() {
455
+ return this._containerWidth;
456
+ }
457
+ setContainerWidth = (e) => {
458
+ this._containerWidth !== e && (this._containerWidth = e, this.flexWidths.clear(), this.sizes.clear(), this.update());
459
+ };
460
+ flexWidths = P(() => {
461
+ console.debug("\x1B[36m%s\x1B[0m", "[react-box]: DataGrid flexWidths memo");
462
+ const e = this._containerWidth;
463
+ if (e <= 0) return {};
464
+ const t = this.columns.value.visibleLeafs.filter((c) => c.key !== V), i = (c) => !c.isFlexible || this.columnWidths.has(c.key), r = t.filter(i).sumBy((c) => c.baseWidth), o = t.filter((c) => !i(c)), a = o.sumBy((c) => c.baseWidth), h = e - r;
465
+ if (h <= a)
466
+ return o.toRecord((c) => [c.key, c.baseWidth]);
467
+ const u = {};
468
+ let l = 0;
469
+ return o.forEach((c, p) => {
470
+ if (p === o.length - 1)
471
+ u[c.key] = h - l;
472
+ else {
473
+ const f = Math.floor(c.baseWidth / a * h);
474
+ u[c.key] = f, l += f;
475
+ }
476
+ }), u;
477
+ });
478
+ getFlexWidth(e) {
479
+ return this.flexWidths.value[e];
480
+ }
288
481
  DEFAULT_ROW_HEIGHT_PX = 48;
289
482
  MIN_COLUMN_WIDTH_PX = 48;
290
483
  DEFAULT_COLUMN_WIDTH_PX = 200;
291
- isResizeMode = !1;
292
484
  expandedGroupRow = /* @__PURE__ */ new Set();
293
485
  selectedRows = /* @__PURE__ */ new Set();
294
486
  get leftEdge() {
@@ -308,20 +500,21 @@ class Ne {
308
500
  if (t.length > 0)
309
501
  [this._sortDirection] = t, this._sortColumn = this._sortDirection ? e : void 0;
310
502
  else {
311
- const { _sortColumn: i, _sortDirection: n } = this;
312
- this._sortColumn = i === e && n === "DESC" ? void 0 : e, this._sortDirection = i === e && n === "ASC" ? "DESC" : "ASC";
503
+ const { _sortColumn: i, _sortDirection: r } = this;
504
+ this._sortColumn = i === e && r === "DESC" ? void 0 : e, this._sortDirection = i === e && r === "ASC" ? "DESC" : "ASC";
313
505
  }
314
506
  this.headerRows.clear(), this.rows.clear(), this.flatRows.clear(), this.update();
315
507
  };
316
508
  pinColumn = (e, t) => {
317
- const i = this.columns.value.flat.findOrThrow((n) => n.uniqueKey === e);
318
- i.pin !== t && i.pinColumn(t), this.columns.clear(), this.headerRows.clear(), this.gridTemplateColumns.clear(), this.rows.clear(), this.flatRows.clear(), this.sizes.clear(), this.update();
509
+ const i = this.columns.value.flat.findOrThrow((r) => r.uniqueKey === e);
510
+ i.pin !== t && i.pinColumn(t), this.columns.clear(), this.headerRows.clear(), this.gridTemplateColumns.clear(), this.rows.clear(), this.flatRows.clear(), this.flexWidths.clear(), this.sizes.clear(), this.update();
319
511
  };
320
512
  toggleGrouping = (e) => {
321
- this.groupColumns = new Set(this.groupColumns), this.hiddenColumns = new Set(this.hiddenColumns), this.groupColumns.has(e) ? (this.groupColumns.delete(e), this.hiddenColumns.delete(e)) : (this.groupColumns.add(e), this.hiddenColumns.add(e)), this.sourceColumns.clear(), this.columns.clear(), this.headerRows.clear(), this.gridTemplateColumns.clear(), this.rows.clear(), this.flatRows.clear(), this.sizes.clear(), this.update();
513
+ this.groupColumns = new Set(this.groupColumns), this.hiddenColumns = new Set(this.hiddenColumns), this.groupColumns.has(e) ? (this.groupColumns.delete(e), this.hiddenColumns.delete(e)) : (this.groupColumns.add(e), this.hiddenColumns.add(e)), this.sourceColumns.clear(), this.columns.clear(), this.headerRows.clear(), this.gridTemplateColumns.clear(), this.rows.clear(), this.flatRows.clear(), this.flexWidths.clear(), this.sizes.clear(), this.update();
322
514
  };
323
515
  unGroupAll = () => {
324
- this.groupColumns = /* @__PURE__ */ new Set(), this.sourceColumns.clear(), this.columns.clear(), this.headerRows.clear(), this.gridTemplateColumns.clear(), this.rows.clear(), this.flatRows.clear(), this.sizes.clear(), this.update();
516
+ const e = new Set(this.groupColumns);
517
+ this.groupColumns = /* @__PURE__ */ new Set(), this.hiddenColumns = new Set(Array.from(this.hiddenColumns).filter((t) => !e.has(t))), this.sourceColumns.clear(), this.columns.clear(), this.headerRows.clear(), this.gridTemplateColumns.clear(), this.rows.clear(), this.flatRows.clear(), this.flexWidths.clear(), this.sizes.clear(), this.update();
325
518
  };
326
519
  toggleGroupRow = (e) => {
327
520
  this.expandedGroupRow = new Set(this.expandedGroupRow), this.expandedGroupRow.has(e) ? this.expandedGroupRow.delete(e) : this.expandedGroupRow.add(e), this.rows.clear(), this.flatRows.clear(), this.update();
@@ -343,16 +536,14 @@ class Ne {
343
536
  this.toggleRowsSelection(this.props.data.map((e) => this.getRowKey(e)));
344
537
  };
345
538
  toggleColumnVisibility = (e) => {
346
- this.hiddenColumns = new Set(this.hiddenColumns), this.hiddenColumns.has(e) ? this.hiddenColumns.delete(e) : this.hiddenColumns.add(e), this.columns.clear(), this.headerRows.clear(), this.gridTemplateColumns.clear(), this.rows.clear(), this.flatRows.clear(), this.sizes.clear(), this.update();
539
+ this.hiddenColumns = new Set(this.hiddenColumns), this.hiddenColumns.has(e) ? this.hiddenColumns.delete(e) : this.hiddenColumns.add(e), this.columns.clear(), this.headerRows.clear(), this.gridTemplateColumns.clear(), this.rows.clear(), this.flatRows.clear(), this.flexWidths.clear(), this.sizes.clear(), this.update();
347
540
  };
348
541
  setWidth = (e, t) => {
349
- const i = this.columns.value.leafs.find((o) => o.key === e);
350
- if (!i)
351
- throw new Error("Leaf column not found.");
352
- i.setWidth(t), this.sourceColumns.value.flatMap((o) => o.flatColumns).findOrThrow((o) => o.key === e).setWidth(t);
542
+ this.columnWidths.set(e, t);
353
543
  };
354
544
  groupColumns = /* @__PURE__ */ new Set();
355
545
  hiddenColumns = /* @__PURE__ */ new Set();
546
+ columnWidths = /* @__PURE__ */ new Map();
356
547
  _sortColumn;
357
548
  get sortColumn() {
358
549
  return this._sortColumn;
@@ -362,24 +553,24 @@ class Ne {
362
553
  return this._sortDirection;
363
554
  }
364
555
  }
365
- class We {
556
+ class qe {
366
557
  constructor(e, t, i) {
367
558
  this.grid = e, this.row = t, this.column = i;
368
559
  }
369
560
  get value() {
370
- return this.column.key === C ? this.row.rowIndex + 1 : this.column.key === x ? `${this.row.groupValue} (${this.row.count})` : null;
561
+ return this.column.key === G ? this.row.rowIndex + 1 : this.column.key === T ? `${this.row.groupValue} (${this.row.count})` : null;
371
562
  }
372
563
  }
373
- class me {
374
- constructor(e, t, i, n, o) {
375
- this.grid = e, this.groupColumn = t, this.rows = i, this.rowIndex = n, this.groupValue = o, i.forEach((r) => r.parentRow = this);
564
+ class we {
565
+ constructor(e, t, i, r, o) {
566
+ this.grid = e, this.groupColumn = t, this.rows = i, this.rowIndex = r, this.groupValue = o, i.forEach((a) => a.parentRow = this);
376
567
  }
377
568
  get key() {
378
569
  return `${this.parentRow?.key ?? ""}${this.groupColumn.key}${this.groupValue}`;
379
570
  }
380
571
  parentRow;
381
572
  get cells() {
382
- return this.grid.columns.value.visibleLeafs.map((e) => new We(this.grid, this, e));
573
+ return this.grid.columns.value.visibleLeafs.map((e) => new qe(this.grid, this, e));
383
574
  }
384
575
  get selected() {
385
576
  return this.allRows.every((e) => e.selected);
@@ -403,178 +594,428 @@ class me {
403
594
  return this.rows.flatMap((e) => e.allRows);
404
595
  }
405
596
  get groupingColumn() {
406
- return this.grid.columns.value.leafs.findOrThrow((e) => e.key === x);
597
+ return this.grid.columns.value.leafs.findOrThrow((e) => e.key === T);
407
598
  }
408
599
  get groupingColumnGridColumn() {
409
600
  const { visibleLeafs: e } = this.grid.columns.value, { groupingColumn: t } = this;
410
601
  return e.sumBy(
411
- (n) => n.pin === t.pin && n.key !== E && n.key !== _ && n.key !== C ? 1 : 0
602
+ (r) => r.pin === t.pin && r.key !== V && r.key !== _ && r.key !== G ? 1 : 0
412
603
  );
413
604
  }
414
605
  toggleRow() {
415
606
  this.grid.toggleGroupRow(this.key);
416
607
  }
417
608
  }
418
- function A(l) {
419
- const { children: e, column: t, style: i, ...n } = l, { key: o, pin: r, left: u, right: a, isEdge: c, align: d, widthVarName: m, leftVarName: f, rightVarName: R } = t;
420
- "align" in t.def && (n.jc = d);
421
- const y = o === C, k = o === _, G = r === "LEFT", b = r === "RIGHT";
422
- return /* @__PURE__ */ s(
423
- g,
609
+ function q(s) {
610
+ const { children: e, column: t, style: i, ...r } = s, { key: o, pin: a, left: h, right: u, isEdge: l, align: c, widthVarName: p, leftVarName: f, rightVarName: y, isFirstLeaf: v, isLastLeaf: R } = t;
611
+ "align" in t.def && (r.jc = c);
612
+ const N = o === G, S = o === _, x = o === V, L = a === "LEFT", C = a === "RIGHT";
613
+ return /* @__PURE__ */ n(
614
+ m,
424
615
  {
425
616
  component: "datagrid.body.cell",
426
617
  props: { role: "cell" },
427
618
  variant: {
428
- isPinned: G || b,
429
- isFirstLeftPinned: G && u === 0,
430
- isLastLeftPinned: G && c,
431
- isFirstRightPinned: b && c,
432
- isLastRightPinned: b && a === 0,
433
- isRowSelection: k,
434
- isRowNumber: y
619
+ isPinned: L || C,
620
+ isFirstLeftPinned: L && h === 0,
621
+ isLastLeftPinned: L && l,
622
+ isFirstRightPinned: C && l,
623
+ isLastRightPinned: C && u === 0,
624
+ isRowSelection: S,
625
+ isRowNumber: N,
626
+ isFirstLeaf: v,
627
+ isLastLeaf: R,
628
+ isEmptyCell: x
435
629
  },
436
630
  style: {
437
- width: `var(${m})`,
631
+ width: `var(${p})`,
438
632
  height: `var(${t.grid.rowHeightVarName})`,
439
- left: G ? `var(${f})` : void 0,
440
- right: b ? `var(${R})` : void 0,
633
+ left: L ? `var(${f})` : void 0,
634
+ right: C ? `var(${y})` : void 0,
441
635
  ...i
442
636
  },
443
- ...n,
637
+ ...r,
444
638
  children: e
445
639
  }
446
640
  );
447
641
  }
448
- A.displayName = "DataGridCell";
449
- function pe(l) {
450
- const { row: e } = l, { selected: t, indeterminate: i, cells: n, groupingColumn: o, groupingColumnGridColumn: r, depth: u, expanded: a } = e, c = X(() => {
451
- e.grid.toggleRowsSelection(e.allRows.map((d) => d.key));
642
+ q.displayName = "DataGridCell";
643
+ function ye(s) {
644
+ const { row: e } = s, { selected: t, indeterminate: i, cells: r, groupingColumn: o, groupingColumnGridColumn: a, depth: h, expanded: u } = e, l = k(() => {
645
+ e.grid.toggleRowsSelection(e.allRows.map((c) => c.key));
452
646
  }, []);
453
- return /* @__PURE__ */ s(g, { className: "grid-row", selected: t, display: "contents", props: { role: "rowgroup" }, children: n.map((d) => {
454
- const { key: m, pin: f, groupColumnWidthVarName: R } = d.column, y = f === "RIGHT";
455
- if (m === x)
456
- return /* @__PURE__ */ s(
457
- A,
647
+ return /* @__PURE__ */ n(m, { className: "grid-row", selected: t, display: "contents", props: { role: "rowgroup" }, children: r.map((c) => {
648
+ const { key: p, pin: f, groupColumnWidthVarName: y } = c.column, v = f === "RIGHT";
649
+ if (p === T)
650
+ return /* @__PURE__ */ n(
651
+ q,
458
652
  {
459
- column: d.column,
653
+ column: c.column,
460
654
  style: {
461
- width: `var(${R})`,
462
- right: y ? "0" : void 0
655
+ width: `var(${y})`,
656
+ right: v ? "0" : void 0
463
657
  },
464
658
  br: o.pin === "LEFT" ? 1 : void 0,
465
- gridColumn: r,
466
- pl: 4 * u,
659
+ gridColumn: a,
660
+ pl: 4 * h,
467
661
  overflow: "auto",
468
- children: /* @__PURE__ */ s(p, { textWrap: "nowrap", px: 3, children: /* @__PURE__ */ h(w, { clean: !0, onClick: () => e.toggleRow(), cursor: "pointer", display: "flex", gap: 1, ai: "center", children: [
469
- /* @__PURE__ */ s(ae, { fill: "currentColor", width: "14px", height: "14px", rotate: a ? 0 : -90 }),
470
- d.value
662
+ children: /* @__PURE__ */ n(g, { textWrap: "nowrap", px: 3, children: /* @__PURE__ */ d(D, { clean: !0, onClick: () => e.toggleRow(), cursor: "pointer", display: "flex", gap: 1, ai: "center", children: [
663
+ /* @__PURE__ */ n(ge, { fill: "currentColor", width: "14px", height: "14px", rotate: u ? 0 : -90 }),
664
+ c.value
471
665
  ] }) })
472
666
  },
473
- m
667
+ p
474
668
  );
475
- if (m === _)
476
- return /* @__PURE__ */ s(A, { column: d.column, children: /* @__PURE__ */ s(q, { variant: "datagrid", m: 1, checked: t, indeterminate: i, onChange: c }) }, m);
477
- if (f !== o.pin || m === C || m === E)
478
- return /* @__PURE__ */ s(A, { column: d.column, px: m === C ? 3 : void 0, children: d.value }, m);
669
+ if (p === _)
670
+ return /* @__PURE__ */ n(q, { column: c.column, children: /* @__PURE__ */ n(le, { variant: "datagrid", m: 1, checked: t, indeterminate: i, onChange: l }) }, p);
671
+ if (f !== o.pin || p === G || p === V)
672
+ return /* @__PURE__ */ n(q, { column: c.column, px: p === G ? 3 : void 0, children: c.value }, p);
479
673
  }) });
480
674
  }
481
- pe.displayName = "DataGridGroupRow";
482
- function ge(l) {
483
- const { cell: e } = l;
484
- return /* @__PURE__ */ s(g, { height: "fit", width: "fit", overflow: "auto", ai: "center", jc: e.column.align, children: /* @__PURE__ */ s(p, { px: 3, textOverflow: "ellipsis", overflow: "hidden", textWrap: "nowrap", children: e.value }) });
675
+ ye.displayName = "DataGridGroupRow";
676
+ function ve(s) {
677
+ const { cell: e } = s;
678
+ return /* @__PURE__ */ n(m, { height: "fit", width: "fit", overflow: "auto", ai: "center", jc: e.column.align, children: /* @__PURE__ */ n(g, { px: 3, textOverflow: "ellipsis", overflow: "hidden", textWrap: "nowrap", children: e.value }) });
485
679
  }
486
- ge.displayName = "DataGridCellText";
487
- function fe(l) {
488
- const { row: e } = l, { selected: t } = e;
489
- return /* @__PURE__ */ s(g, { className: "grid-row", selected: t, display: "contents", props: { role: "row" }, children: e.cells.map((i) => /* @__PURE__ */ s(A, { column: i.column, children: i.column.Cell ? /* @__PURE__ */ s(i.column.Cell, { cell: i }) : /* @__PURE__ */ s(ge, { cell: i }) }, i.column.key)) });
680
+ ve.displayName = "DataGridCellText";
681
+ function be(s) {
682
+ const { row: e } = s, { selected: t } = e;
683
+ return /* @__PURE__ */ n(m, { className: "grid-row", selected: t, display: "contents", props: { role: "row" }, children: e.cells.map((i) => /* @__PURE__ */ n(q, { column: i.column, children: i.column.Cell ? /* @__PURE__ */ n(i.column.Cell, { cell: i }) : /* @__PURE__ */ n(ve, { cell: i }) }, i.column.key)) });
490
684
  }
491
- fe.displayName = "DataGridRow";
492
- const He = 10, re = 20;
493
- function we(l) {
494
- const { grid: e, scrollTop: t } = l, i = e.flatRows.value.length, n = Math.max(0, Math.floor(t / e.rowHeight) - re), o = e.props.def.visibleRowsCount ?? He, r = e.rowHeight * o + e.rowHeight / 5, u = j(() => {
685
+ be.displayName = "DataGridRow";
686
+ const Xe = 10, de = 20;
687
+ function Re(s) {
688
+ const { grid: e, scrollTop: t } = s, i = e.flatRows.value.length, r = Math.max(0, Math.floor(t / e.rowHeight) - de), o = e.props.def.visibleRowsCount ?? Xe, a = e.rowHeight * o + e.rowHeight / 5, h = X(() => {
495
689
  if (console.debug("\x1B[36m%s\x1B[0m", "[react-box]: DataGrid render rows"), e.props.data.length === 0)
496
- return /* @__PURE__ */ s(g, { jc: "center", ai: "center", gridColumn: "full-row", style: { height: r }, children: e.props.loading ? "loading..." : "empty" });
497
- const a = o + re * 2;
498
- return e.flatRows.value.take(a, n).map((d) => d instanceof me ? /* @__PURE__ */ s(pe, { row: d }, d.key) : /* @__PURE__ */ s(fe, { row: d }, d.key));
499
- }, [e.flatRows.value, e.props.data.length, e.props.loading, n, r, o]);
500
- return console.debug("\x1B[36m%s\x1B[0m", "[react-box]: DataGrid render DataGridBody"), /* @__PURE__ */ s(p, { style: { height: r }, children: /* @__PURE__ */ s(
501
- p,
690
+ return /* @__PURE__ */ n(m, { jc: "center", ai: "center", gridColumn: "full-row", style: { height: a }, children: e.props.loading ? "loading..." : "empty" });
691
+ const u = o + de * 2;
692
+ return e.flatRows.value.take(u, r).map((c) => c instanceof we ? /* @__PURE__ */ n(ye, { row: c }, c.key) : /* @__PURE__ */ n(be, { row: c }, c.key));
693
+ }, [e.flatRows.value, e.props.data.length, e.props.loading, r, a, o]);
694
+ return console.debug("\x1B[36m%s\x1B[0m", "[react-box]: DataGrid render DataGridBody"), /* @__PURE__ */ n(g, { style: { height: a }, children: /* @__PURE__ */ n(
695
+ g,
502
696
  {
503
697
  style: {
504
698
  height: `${i * e.rowHeight}px`
505
699
  },
506
- children: /* @__PURE__ */ s(
507
- ce,
700
+ children: /* @__PURE__ */ n(
701
+ me,
508
702
  {
509
703
  component: "datagrid.body",
510
704
  width: "max-content",
511
705
  minWidth: "fit",
512
706
  transition: "none",
513
707
  style: {
514
- transform: `translateY(${n * e.rowHeight}px)`,
708
+ transform: `translate3d(0, ${r * e.rowHeight}px, 0)`,
709
+ willChange: "transform",
515
710
  gridTemplateColumns: e.gridTemplateColumns.value
516
711
  },
517
- children: u
712
+ children: h
518
713
  }
519
714
  )
520
715
  }
521
716
  ) });
522
717
  }
523
- we.displayName = "DataGridBody";
524
- function Ce(l) {
525
- const { column: e } = l, { key: t, pin: i, left: n, right: o, isEdge: r, isLeaf: u, align: a, header: c, grid: d } = e, [m, f, R] = de({ hideOnScroll: !0, event: "mousedown" }), [y, k] = te({ top: 0, left: 0 }), G = j(() => y.left > window.innerWidth / 2, [y.left]), b = u && (d.sortColumn !== t || d.sortDirection === "DESC"), L = u && (d.sortColumn !== t || d.sortDirection === "ASC"), v = u && d.sortColumn === t, T = i !== "LEFT", B = i !== "RIGHT", N = !!i, W = u && t !== x, H = u && t === x, F = b || L || v, O = T || B || N, $ = a === "right" ? 2 : void 0, Y = a === "right" ? void 0 : i === "RIGHT" ? 2.5 : 4, K = t === E, I = t === C, J = t === _, V = i === "LEFT", z = i === "RIGHT";
526
- return /* @__PURE__ */ s(g, { position: "absolute", left: $, right: Y, top: "1/2", translateY: -3, ai: "center", children: /* @__PURE__ */ h(
527
- w,
718
+ Re.displayName = "DataGridBody";
719
+ function Ye() {
720
+ return /* @__PURE__ */ n(
721
+ m,
722
+ {
723
+ d: "column",
724
+ ai: "center",
725
+ jc: "center",
726
+ gap: 4,
727
+ py: 16,
728
+ px: 6,
729
+ bgColor: "gray-50",
730
+ borderRadius: 4,
731
+ theme: { dark: { bgColor: "gray-900" } },
732
+ children: /* @__PURE__ */ d(m, { d: "column", ai: "center", gap: 3, children: [
733
+ /* @__PURE__ */ n(
734
+ g,
735
+ {
736
+ width: 16,
737
+ height: 16,
738
+ borderRadius: 999,
739
+ bgColor: "gray-200",
740
+ theme: { dark: { bgColor: "gray-700" } },
741
+ display: "flex",
742
+ ai: "center",
743
+ jc: "center",
744
+ children: /* @__PURE__ */ n(fe, { viewBox: "0 0 24 24", width: "40", fill: "currentColor", color: "gray-400", theme: { dark: { color: "gray-500" } }, children: /* @__PURE__ */ n(
745
+ "path",
746
+ {
747
+ fillRule: "evenodd",
748
+ clipRule: "evenodd",
749
+ d: "M3 6a3 3 0 013-3h12a3 3 0 013 3v12a3 3 0 01-3 3H6a3 3 0 01-3-3V6zm3-1a1 1 0 00-1 1v12a1 1 0 001 1h12a1 1 0 001-1V6a1 1 0 00-1-1H6zm2 3a1 1 0 011-1h6a1 1 0 110 2H9a1 1 0 01-1-1zm0 4a1 1 0 011-1h6a1 1 0 110 2H9a1 1 0 01-1-1zm0 4a1 1 0 011-1h4a1 1 0 110 2H9a1 1 0 01-1-1z"
750
+ }
751
+ ) })
752
+ }
753
+ ),
754
+ /* @__PURE__ */ d(m, { d: "column", ai: "center", gap: 1, children: [
755
+ /* @__PURE__ */ n(g, { fontSize: 18, fontWeight: 600, color: "gray-900", theme: { dark: { color: "gray-50" } }, children: "No Columns Selected" }),
756
+ /* @__PURE__ */ n(g, { fontSize: 14, color: "gray-500", textAlign: "center", theme: { dark: { color: "gray-400" } }, children: "Select at least one column from the columns menu to display data" })
757
+ ] })
758
+ ] })
759
+ }
760
+ );
761
+ }
762
+ function pe({ column: s, grid: e }) {
763
+ const t = e.columnFilters[s.key], i = t?.type === "text" ? t.value : "", [r, o] = M(i), a = O(null);
764
+ z(() => () => {
765
+ a.current && clearTimeout(a.current);
766
+ }, []);
767
+ const h = k(
768
+ (c) => {
769
+ const p = c.target.value;
770
+ o(p), a.current && clearTimeout(a.current), a.current = setTimeout(() => {
771
+ p.trim() ? e.setColumnFilter(s.key, { type: "text", value: p }) : e.setColumnFilter(s.key, void 0), a.current = null;
772
+ }, 300);
773
+ },
774
+ [e, s.key]
775
+ ), u = k(() => {
776
+ o(""), e.setColumnFilter(s.key, void 0);
777
+ }, [e, s.key]), l = typeof s.def.filterable == "object" ? s.def.filterable : {};
778
+ return /* @__PURE__ */ d(m, { ai: "center", position: "relative", width: "fit", children: [
779
+ /* @__PURE__ */ n(j, { width: "fit", variant: "compact", placeholder: l.placeholder ?? "Filter...", value: r, onChange: h }),
780
+ r && /* @__PURE__ */ n(m, { position: "absolute", right: 2, top: "1/2", translateY: "-1/2", cursor: "pointer", props: { onClick: u }, children: /* @__PURE__ */ n(g, { fontSize: 10, color: "gray-400", hover: { color: "gray-600" }, children: "✕" }) })
781
+ ] });
782
+ }
783
+ function Ke({ column: s, grid: e }) {
784
+ const t = e.columnFilters[s.key], i = t?.type === "number" ? t.value : "", r = t?.type === "number" ? t.operator : "eq", o = t?.type === "number" ? t.valueTo : "", [a, h] = M(i), [u, l] = M(r), [c, p] = M(o ?? ""), f = O(null), y = O(null);
785
+ z(() => () => {
786
+ f.current && clearTimeout(f.current), y.current && clearTimeout(y.current);
787
+ }, []);
788
+ const v = typeof s.def.filterable == "object" ? s.def.filterable : {}, R = k(
789
+ (C, w, F) => {
790
+ const W = typeof w == "number" ? w : parseFloat(w);
791
+ if (isNaN(W) || w === "") {
792
+ e.setColumnFilter(s.key, void 0);
793
+ return;
794
+ }
795
+ const B = {
796
+ type: "number",
797
+ operator: C,
798
+ value: W
799
+ };
800
+ if (C === "between" && F !== void 0 && F !== "") {
801
+ const E = typeof F == "number" ? F : parseFloat(String(F));
802
+ isNaN(E) || (B.valueTo = E);
803
+ }
804
+ e.setColumnFilter(s.key, B);
805
+ },
806
+ [e, s.key]
807
+ ), N = k(
808
+ (C) => {
809
+ const w = C.target.value;
810
+ h(w), f.current && clearTimeout(f.current), f.current = setTimeout(() => {
811
+ R(u, w, c), f.current = null;
812
+ }, 300);
813
+ },
814
+ [u, c, R]
815
+ ), S = k(
816
+ (C) => {
817
+ l(C), R(C, a, c);
818
+ },
819
+ [a, c, R]
820
+ ), x = k(
821
+ (C) => {
822
+ const w = C.target.value;
823
+ p(w), y.current && clearTimeout(y.current), y.current = setTimeout(() => {
824
+ R(u, a, w), y.current = null;
825
+ }, 300);
826
+ },
827
+ [u, a, R]
828
+ ), L = k(() => {
829
+ h(""), p(""), l("eq"), e.setColumnFilter(s.key, void 0);
830
+ }, [e, s.key]);
831
+ return /* @__PURE__ */ d(m, { ai: u === "between" ? "start" : "center", gap: 1, width: "fit", children: [
832
+ /* @__PURE__ */ d(
833
+ b,
834
+ {
835
+ value: u,
836
+ variant: "compact",
837
+ onChange: (C) => C && S(C),
838
+ minWidth: 6,
839
+ hideIcon: !0,
840
+ children: [
841
+ /* @__PURE__ */ n(b.Item, { value: "eq", children: "=" }),
842
+ /* @__PURE__ */ n(b.Item, { value: "ne", children: "≠" }),
843
+ /* @__PURE__ */ n(b.Item, { value: "gt", children: ">" }),
844
+ /* @__PURE__ */ n(b.Item, { value: "gte", children: "≥" }),
845
+ /* @__PURE__ */ n(b.Item, { value: "lt", children: "<" }),
846
+ /* @__PURE__ */ n(b.Item, { value: "lte", children: "≤" }),
847
+ /* @__PURE__ */ n(b.Item, { value: "between", children: "↔" })
848
+ ]
849
+ }
850
+ ),
851
+ u === "between" ? /* @__PURE__ */ d(m, { d: "column", gap: 1, flex1: !0, children: [
852
+ /* @__PURE__ */ d(m, { ai: "center", position: "relative", flex1: !0, children: [
853
+ /* @__PURE__ */ n(
854
+ j,
855
+ {
856
+ type: "number",
857
+ variant: "compact",
858
+ placeholder: v.placeholder ?? "From",
859
+ value: a,
860
+ onChange: N,
861
+ width: "fit",
862
+ step: v.step
863
+ }
864
+ ),
865
+ (a !== "" || c !== "") && /* @__PURE__ */ n(m, { position: "absolute", right: 2, top: "1/2", translateY: "-1/2", cursor: "pointer", props: { onClick: L }, children: /* @__PURE__ */ n(g, { fontSize: 10, color: "gray-400", hover: { color: "gray-600" }, children: "✕" }) })
866
+ ] }),
867
+ /* @__PURE__ */ n(m, { ai: "center", flex1: !0, children: /* @__PURE__ */ n(
868
+ j,
869
+ {
870
+ type: "number",
871
+ variant: "compact",
872
+ placeholder: "To",
873
+ value: c,
874
+ onChange: x,
875
+ width: "fit",
876
+ step: v.step
877
+ }
878
+ ) })
879
+ ] }) : /* @__PURE__ */ d(m, { ai: "center", position: "relative", flex1: !0, children: [
880
+ /* @__PURE__ */ n(
881
+ j,
882
+ {
883
+ type: "number",
884
+ variant: "compact",
885
+ placeholder: v.placeholder ?? "Value",
886
+ value: a,
887
+ onChange: N,
888
+ width: "fit",
889
+ step: v.step
890
+ }
891
+ ),
892
+ a !== "" && /* @__PURE__ */ n(m, { position: "absolute", right: 2, top: "1/2", translateY: "-1/2", cursor: "pointer", props: { onClick: L }, children: /* @__PURE__ */ n(g, { fontSize: 10, color: "gray-400", hover: { color: "gray-600" }, children: "✕" }) })
893
+ ] })
894
+ ] });
895
+ }
896
+ function Je({ column: s, grid: e }) {
897
+ const t = e.columnFilters[s.key], i = t?.type === "multiselect" ? t.values : [], r = typeof s.def.filterable == "object" ? s.def.filterable : {}, o = X(() => r.options ? r.options : e.getColumnUniqueValues(s.key).map((u) => ({
898
+ label: u === null ? "(empty)" : String(u),
899
+ value: u
900
+ })), [r.options, e, s.key]), a = k(
901
+ (h, u) => {
902
+ u.length === 0 ? e.setColumnFilter(s.key, void 0) : e.setColumnFilter(s.key, { type: "multiselect", values: u });
903
+ },
904
+ [e, s.key]
905
+ );
906
+ return /* @__PURE__ */ d(
907
+ b,
908
+ {
909
+ multiple: !0,
910
+ showCheckbox: !0,
911
+ isSearchable: !0,
912
+ searchPlaceholder: "Search...",
913
+ value: i,
914
+ width: "fit",
915
+ minWidth: 0,
916
+ onChange: a,
917
+ variant: "compact",
918
+ children: [
919
+ /* @__PURE__ */ n(b.Unselect, { children: "Clear" }),
920
+ /* @__PURE__ */ n(b.SelectAll, { children: "Select All" }),
921
+ o.map((h) => /* @__PURE__ */ n(b.Item, { value: h.value, ai: "center", gap: 2, children: h.label }, String(h.value)))
922
+ ]
923
+ }
924
+ );
925
+ }
926
+ function xe(s) {
927
+ const { column: e, grid: t } = s, { filterable: i } = e.def;
928
+ if (!i) return null;
929
+ switch ((typeof i == "object" ? i : { type: "text" }).type) {
930
+ case "text":
931
+ return /* @__PURE__ */ n(pe, { column: e, grid: t });
932
+ case "number":
933
+ return /* @__PURE__ */ n(Ke, { column: e, grid: t });
934
+ case "multiselect":
935
+ return /* @__PURE__ */ n(Je, { column: e, grid: t });
936
+ default:
937
+ return /* @__PURE__ */ n(pe, { column: e, grid: t });
938
+ }
939
+ }
940
+ xe.displayName = "DataGridColumnFilter";
941
+ function Fe(s) {
942
+ const { column: e, grid: t } = s, { key: i, pin: r, left: o, right: a, isEdge: h, widthVarName: u, leftVarName: l, rightVarName: c, filterable: p } = e, f = i === V, N = f || i === T || i === G || i === _, S = r === "LEFT", x = r === "RIGHT";
943
+ return /* @__PURE__ */ n(
944
+ m,
945
+ {
946
+ component: "datagrid.filter.cell",
947
+ variant: { isPinned: S || x, isFirstLeftPinned: S && o === 0, isLastLeftPinned: S && h, isFirstRightPinned: x && h, isLastRightPinned: x && a === 0 },
948
+ px: f ? 0 : 2,
949
+ style: {
950
+ width: `var(${u})`,
951
+ left: S ? `var(${l})` : void 0,
952
+ right: x ? `var(${c})` : void 0
953
+ },
954
+ children: !N && p && /* @__PURE__ */ n(xe, { column: e, grid: t })
955
+ }
956
+ );
957
+ }
958
+ Fe.displayName = "DataGridFilterCell";
959
+ function ke(s) {
960
+ const { grid: e } = s, { visibleLeafs: t } = e.columns.value;
961
+ return t.some((r) => r.filterable) ? t.map((r) => /* @__PURE__ */ n(Fe, { column: r, grid: e }, r.uniqueKey)) : null;
962
+ }
963
+ ke.displayName = "DataGridFilterRow";
964
+ function Ge(s) {
965
+ const { column: e } = s, { key: t, pin: i, left: r, right: o, isEdge: a, isLeaf: h, align: u, header: l, grid: c } = e, [p, f, y] = Me({ hideOnScroll: !0, event: "mousedown" }), [v, R] = M({ top: 0, left: 0 }), N = X(() => v.left > window.innerWidth / 2, [v.left]), S = h && e.sortable && (c.sortColumn !== t || c.sortDirection === "DESC"), x = h && e.sortable && (c.sortColumn !== t || c.sortDirection === "ASC"), L = h && e.sortable && c.sortColumn === t, C = i !== "LEFT", w = i !== "RIGHT", F = !!i, W = h && t !== T, B = h && t === T, E = S || x || L, Y = C || w || F, ee = u === "right" ? 2 : void 0, te = u === "right" ? void 0 : i === "RIGHT" ? 2.5 : 4, K = t === V, J = t === G, ie = t === _, $ = i === "LEFT", Q = i === "RIGHT", re = $ || i === "RIGHT", Z = $ && r === 0, ne = $ && a, H = Q && a, U = Q && o === 0, Ne = h && !K && !J && !ie && e.sortable;
966
+ return /* @__PURE__ */ n(m, { position: "absolute", left: ee, right: te, top: "1/2", translateY: -3, ai: "center", children: /* @__PURE__ */ d(
967
+ D,
528
968
  {
529
969
  component: "datagrid.header.cell.contextMenu",
530
- onClick: () => f(!m),
531
- variant: { isPinned: V || i === "RIGHT", isFirstLeftPinned: V && n === 0, isLastLeftPinned: V && r, isFirstRightPinned: z && r, isLastRightPinned: z && o === 0, isSortable: u && !K && !I && !J, isRowNumber: I },
970
+ onClick: () => f(!p),
971
+ variant: { isPinned: re, isFirstLeftPinned: Z, isLastLeftPinned: ne, isFirstRightPinned: H, isLastRightPinned: U, isSortable: Ne, isRowNumber: J },
532
972
  children: [
533
- /* @__PURE__ */ s(D, { component: "datagrid.header.cell.contextMenu.icon", children: /* @__PURE__ */ s(Se, { fill: "currentColor" }) }),
534
- m && /* @__PURE__ */ h(
535
- he,
973
+ /* @__PURE__ */ n(I, { component: "datagrid.header.cell.contextMenu.icon", children: /* @__PURE__ */ n(He, { fill: "currentColor" }) }),
974
+ p && /* @__PURE__ */ d(
975
+ Ae,
536
976
  {
537
977
  component: "datagrid.header.cell.contextMenu.tooltip",
538
- variant: { openLeft: G },
539
- onPositionChange: k,
540
- ref: R,
978
+ onPositionChange: R,
979
+ ref: y,
980
+ adjustTranslateX: N ? "-100%" : "-21px",
981
+ adjustTranslateY: "16px",
541
982
  children: [
542
- b && /* @__PURE__ */ h(w, { component: "datagrid.header.cell.contextMenu.tooltip.item", onClick: () => e.sortColumn("ASC"), children: [
543
- /* @__PURE__ */ s(D, { component: "datagrid.header.cell.contextMenu.tooltip.item.icon", children: /* @__PURE__ */ s(Z, { width: "100%", fill: "currentColor" }) }),
983
+ S && /* @__PURE__ */ d(D, { component: "datagrid.header.cell.contextMenu.tooltip.item", onClick: () => e.sortColumn("ASC"), children: [
984
+ /* @__PURE__ */ n(I, { component: "datagrid.header.cell.contextMenu.tooltip.item.icon", children: /* @__PURE__ */ n(oe, { width: "100%", fill: "currentColor" }) }),
544
985
  "Sort Ascending"
545
986
  ] }),
546
- L && /* @__PURE__ */ h(w, { component: "datagrid.header.cell.contextMenu.tooltip.item", onClick: () => e.sortColumn("DESC"), children: [
547
- /* @__PURE__ */ s(D, { component: "datagrid.header.cell.contextMenu.tooltip.item.icon", children: /* @__PURE__ */ s(Z, { width: "100%", fill: "currentColor", rotate: 180 }) }),
987
+ x && /* @__PURE__ */ d(D, { component: "datagrid.header.cell.contextMenu.tooltip.item", onClick: () => e.sortColumn("DESC"), children: [
988
+ /* @__PURE__ */ n(I, { component: "datagrid.header.cell.contextMenu.tooltip.item.icon", children: /* @__PURE__ */ n(oe, { width: "100%", fill: "currentColor", rotate: 180 }) }),
548
989
  "Sort Descending"
549
990
  ] }),
550
- v && /* @__PURE__ */ h(w, { component: "datagrid.header.cell.contextMenu.tooltip.item", onClick: () => e.sortColumn(void 0), children: [
551
- /* @__PURE__ */ s(p, { width: 4 }),
991
+ L && /* @__PURE__ */ d(D, { component: "datagrid.header.cell.contextMenu.tooltip.item", onClick: () => e.sortColumn(void 0), children: [
992
+ /* @__PURE__ */ n(g, { width: 4 }),
552
993
  "Clear Sort"
553
994
  ] }),
554
- F && (O || W || H) && /* @__PURE__ */ s(p, { bb: 1, my: 2, borderColor: "gray-300" }),
555
- T && /* @__PURE__ */ h(w, { component: "datagrid.header.cell.contextMenu.tooltip.item", onClick: () => e.pinColumn("LEFT"), children: [
556
- /* @__PURE__ */ s(D, { component: "datagrid.header.cell.contextMenu.tooltip.item.icon", children: /* @__PURE__ */ s(ne, { width: "100%", fill: "currentColor" }) }),
995
+ E && (Y || W || B) && /* @__PURE__ */ n(g, { bb: 1, my: 2, borderColor: "gray-300", component: "datagrid.header.cell.contextMenu.tooltip.item.separator" }),
996
+ C && /* @__PURE__ */ d(D, { component: "datagrid.header.cell.contextMenu.tooltip.item", onClick: () => e.pinColumn("LEFT"), children: [
997
+ /* @__PURE__ */ n(I, { component: "datagrid.header.cell.contextMenu.tooltip.item.icon", children: /* @__PURE__ */ n(ce, { width: "100%", fill: "currentColor" }) }),
557
998
  "Pin Left"
558
999
  ] }),
559
- B && /* @__PURE__ */ h(w, { component: "datagrid.header.cell.contextMenu.tooltip.item", onClick: () => e.pinColumn("RIGHT"), children: [
560
- /* @__PURE__ */ s(D, { component: "datagrid.header.cell.contextMenu.tooltip.item.icon", children: /* @__PURE__ */ s(ne, { width: "100%", fill: "currentColor", rotate: -90 }) }),
1000
+ w && /* @__PURE__ */ d(D, { component: "datagrid.header.cell.contextMenu.tooltip.item", onClick: () => e.pinColumn("RIGHT"), children: [
1001
+ /* @__PURE__ */ n(I, { component: "datagrid.header.cell.contextMenu.tooltip.item.icon", children: /* @__PURE__ */ n(ce, { width: "100%", fill: "currentColor", rotate: -90 }) }),
561
1002
  "Pin Right"
562
1003
  ] }),
563
- N && /* @__PURE__ */ h(w, { component: "datagrid.header.cell.contextMenu.tooltip.item", onClick: () => e.pinColumn(), children: [
564
- /* @__PURE__ */ s(p, { width: 4 }),
1004
+ F && /* @__PURE__ */ d(D, { component: "datagrid.header.cell.contextMenu.tooltip.item", onClick: () => e.pinColumn(), children: [
1005
+ /* @__PURE__ */ n(g, { width: 4 }),
565
1006
  "Unpin"
566
1007
  ] }),
567
- F && O && (W || H) && /* @__PURE__ */ s(p, { bb: 1, my: 2, borderColor: "gray-300" }),
568
- W && /* @__PURE__ */ h(w, { component: "datagrid.header.cell.contextMenu.tooltip.item", onClick: e.toggleGrouping, children: [
569
- /* @__PURE__ */ s(D, { component: "datagrid.header.cell.contextMenu.tooltip.item.icon", children: /* @__PURE__ */ s(ee, { width: "100%", fill: "currentColor" }) }),
570
- /* @__PURE__ */ h(p, { textWrap: "nowrap", children: [
1008
+ E && Y && (W || B) && /* @__PURE__ */ n(g, { component: "datagrid.header.cell.contextMenu.tooltip.item.separator" }),
1009
+ W && /* @__PURE__ */ d(D, { component: "datagrid.header.cell.contextMenu.tooltip.item", onClick: e.toggleGrouping, children: [
1010
+ /* @__PURE__ */ n(I, { component: "datagrid.header.cell.contextMenu.tooltip.item.icon", children: /* @__PURE__ */ n(se, { width: "100%", fill: "currentColor" }) }),
1011
+ /* @__PURE__ */ d(g, { textWrap: "nowrap", children: [
571
1012
  "Group by ",
572
- c ?? t
1013
+ l ?? t
573
1014
  ] })
574
1015
  ] }),
575
- H && /* @__PURE__ */ h(w, { component: "datagrid.header.cell.contextMenu.tooltip.item", onClick: d.unGroupAll, children: [
576
- /* @__PURE__ */ s(D, { component: "datagrid.header.cell.contextMenu.tooltip.item.icon", children: /* @__PURE__ */ s(ee, { width: "100%", fill: "currentColor" }) }),
577
- /* @__PURE__ */ s(p, { textWrap: "nowrap", children: "Un-Group All" })
1016
+ B && /* @__PURE__ */ d(D, { component: "datagrid.header.cell.contextMenu.tooltip.item", onClick: c.unGroupAll, children: [
1017
+ /* @__PURE__ */ n(I, { component: "datagrid.header.cell.contextMenu.tooltip.item.icon", children: /* @__PURE__ */ n(se, { width: "100%", fill: "currentColor" }) }),
1018
+ /* @__PURE__ */ n(g, { textWrap: "nowrap", children: "Un-Group All" })
578
1019
  ] })
579
1020
  ]
580
1021
  }
@@ -583,11 +1024,11 @@ function Ce(l) {
583
1024
  }
584
1025
  ) });
585
1026
  }
586
- Ce.displayName = "DataGridHeaderCellContextMenu";
587
- function Re(l) {
588
- const { column: e } = l;
589
- return /* @__PURE__ */ s(
590
- g,
1027
+ Ge.displayName = "DataGridHeaderCellContextMenu";
1028
+ function Se(s) {
1029
+ const { column: e } = s;
1030
+ return /* @__PURE__ */ n(
1031
+ m,
591
1032
  {
592
1033
  height: "fit",
593
1034
  ai: "center",
@@ -595,168 +1036,304 @@ function Re(l) {
595
1036
  right: e.pin === "RIGHT" ? void 0 : 0,
596
1037
  left: e.pin !== "RIGHT" ? void 0 : 0,
597
1038
  py: 3,
598
- children: /* @__PURE__ */ s(
599
- p,
1039
+ children: /* @__PURE__ */ n(
1040
+ g,
600
1041
  {
601
1042
  cursor: "col-resize",
602
1043
  px: 0.75,
1044
+ mt: -6,
603
1045
  className: "resizer",
604
1046
  height: "fit",
605
1047
  props: { onMouseDown: e.resizeColumn, onTouchStart: e.resizeColumn },
606
- children: /* @__PURE__ */ s(p, { component: "datagrid.header.cell.resizer" })
1048
+ children: /* @__PURE__ */ n(g, { component: "datagrid.header.cell.resizer" })
607
1049
  }
608
1050
  )
609
1051
  }
610
1052
  );
611
1053
  }
612
- Re.displayName = "DataGridHeaderCellResizer";
613
- function ye(l) {
614
- const { column: e } = l, { key: t, pin: i, left: n, right: o, isEdge: r, isLeaf: u, leafs: a, grid: c, header: d, gridRows: m, widthVarName: f, leftVarName: R, rightVarName: y, inlineWidth: k } = e, G = t === E, b = t === x, L = t === C, v = t === _, T = i === "LEFT", B = i === "RIGHT", N = T || i === "RIGHT", W = T && n === 0, H = T && r, F = B && r, O = B && o === 0, $ = u && !G && !L && !v, Y = u ? 1 : a.length, K = !L && !v, I = !L && !v, J = v ? void 0 : e.align === "right" ? 10 : 3, V = v ? void 0 : e.align === "center" ? 3 : void 0, z = X(() => {
615
- c.toggleSelectAllRows();
616
- }, []), ie = j(() => {
617
- if (L) return null;
618
- if (v) {
619
- const M = c.selectedRows.size === c.props.data.length, U = !M && c.selectedRows.size > 0;
620
- return /* @__PURE__ */ s(q, { variant: "datagrid", m: 1, indeterminate: U, checked: M, onChange: z });
1054
+ Se.displayName = "DataGridHeaderCellResizer";
1055
+ function Le(s) {
1056
+ const { column: e } = s, {
1057
+ key: t,
1058
+ pin: i,
1059
+ left: r,
1060
+ right: o,
1061
+ isEdge: a,
1062
+ isLeaf: h,
1063
+ leafs: u,
1064
+ grid: l,
1065
+ header: c,
1066
+ gridRows: p,
1067
+ widthVarName: f,
1068
+ leftVarName: y,
1069
+ rightVarName: v,
1070
+ inlineWidth: R,
1071
+ isFirstLeaf: N,
1072
+ isLastLeaf: S
1073
+ } = e, x = t === V, L = t === T, C = t === G, w = t === _, F = i === "LEFT", W = i === "RIGHT", B = F || i === "RIGHT", E = F && r === 0, Y = F && a, ee = W && a, te = W && o === 0, K = h && !x && !C && !w && e.sortable, J = h ? 1 : u.length, ie = !C && !w && e.resizable, $ = !C && !w, Q = w ? void 0 : e.align === "right" ? 10 : 3, re = w ? void 0 : e.align === "center" ? 3 : void 0, Z = k(() => {
1074
+ l.toggleSelectAllRows();
1075
+ }, []), ne = X(() => {
1076
+ if (C) return null;
1077
+ if (w) {
1078
+ const H = l.selectedRows.size === l.props.data.length, U = !H && l.selectedRows.size > 0;
1079
+ return /* @__PURE__ */ n(le, { variant: "datagrid", m: 1, indeterminate: U, checked: H, onChange: Z });
621
1080
  }
622
- if (b) {
623
- if (c.groupColumns.size === 1) {
624
- const M = c.columns.value.leafs.findOrThrow((U) => U.key === c.groupColumns.values().next().value);
625
- return M.header ?? M.key;
1081
+ if (L) {
1082
+ if (l.groupColumns.size === 1) {
1083
+ const H = l.columns.value.leafs.findOrThrow((U) => U.key === l.groupColumns.values().next().value);
1084
+ return H.header ?? H.key;
626
1085
  }
627
1086
  return "Group";
628
1087
  }
629
- return d ?? t;
630
- }, [c.groupColumns, c.selectedRows, z]);
631
- return /* @__PURE__ */ s(
632
- g,
1088
+ return c ?? t;
1089
+ }, [l.groupColumns, l.selectedRows, Z]);
1090
+ return /* @__PURE__ */ n(
1091
+ m,
633
1092
  {
634
1093
  props: { role: "columnheader" },
635
1094
  component: "datagrid.header.cell",
636
- variant: { isPinned: N, isFirstLeftPinned: W, isLastLeftPinned: H, isFirstRightPinned: F, isLastRightPinned: O, isSortable: $, isRowNumber: L },
637
- gridRow: m,
638
- gridColumn: Y,
1095
+ variant: {
1096
+ isPinned: B,
1097
+ isFirstLeftPinned: E,
1098
+ isLastLeftPinned: Y,
1099
+ isFirstRightPinned: ee,
1100
+ isLastRightPinned: te,
1101
+ isSortable: K,
1102
+ isRowNumber: C,
1103
+ isFirstLeaf: N,
1104
+ isLastLeaf: S,
1105
+ isEmptyCell: x
1106
+ },
1107
+ gridRow: p,
1108
+ gridColumn: J,
639
1109
  style: {
640
1110
  width: `var(${f})`,
641
- left: T ? `var(${R})` : void 0,
642
- right: B ? `var(${y})` : void 0
1111
+ left: F ? `var(${y})` : void 0,
1112
+ right: W ? `var(${v})` : void 0
643
1113
  },
644
- children: !G && /* @__PURE__ */ h(ke, { children: [
645
- /* @__PURE__ */ s(g, { width: "fit", height: "fit", jc: e.align, props: { onClick: $ ? () => e.sortColumn() : void 0 }, children: /* @__PURE__ */ h(
646
- g,
1114
+ children: !x && /* @__PURE__ */ d(Be, { children: [
1115
+ /* @__PURE__ */ n(m, { width: "fit", height: "fit", jc: e.align, props: { onClick: K ? () => e.sortColumn() : void 0 }, children: /* @__PURE__ */ d(
1116
+ m,
647
1117
  {
648
1118
  overflow: "hidden",
649
- position: u ? void 0 : "sticky",
1119
+ position: h ? void 0 : "sticky",
650
1120
  ai: "center",
651
1121
  transition: "none",
652
- pl: J,
653
- pr: V,
1122
+ pl: Q,
1123
+ pr: re,
654
1124
  style: {
655
- left: i ? void 0 : `var(${c.leftEdgeVarName})`
1125
+ left: i ? void 0 : `var(${l.leftEdgeVarName})`
656
1126
  },
657
1127
  children: [
658
- /* @__PURE__ */ s(p, { overflow: "hidden", textOverflow: "ellipsis", textWrap: "nowrap", children: ie }),
659
- t === c.sortColumn && /* @__PURE__ */ s(p, { pl: (k ?? 0) < 58 ? 0 : 2, children: /* @__PURE__ */ s(Z, { width: "16px", rotate: c.sortDirection === "ASC" ? 0 : 180, fill: "currentColor" }) }),
660
- I && /* @__PURE__ */ s(p, { minWidth: e.align === "right" ? 4 : 10 })
1128
+ /* @__PURE__ */ n(g, { overflow: "hidden", textOverflow: "ellipsis", textWrap: "nowrap", children: ne }),
1129
+ t === l.sortColumn && /* @__PURE__ */ n(g, { pl: (R ?? 0) < 58 ? 0 : 2, children: /* @__PURE__ */ n(oe, { width: "16px", rotate: l.sortDirection === "ASC" ? 0 : 180, fill: "currentColor" }) }),
1130
+ $ && /* @__PURE__ */ n(g, { minWidth: e.align === "right" ? 4 : 10 })
661
1131
  ]
662
1132
  }
663
1133
  ) }),
664
- K && /* @__PURE__ */ s(Re, { column: e }),
665
- I && /* @__PURE__ */ s(Ce, { column: e })
1134
+ ie && /* @__PURE__ */ n(Se, { column: e }),
1135
+ $ && /* @__PURE__ */ n(Ge, { column: e })
666
1136
  ] })
667
1137
  }
668
1138
  );
669
1139
  }
670
- ye.displayName = "DataGridHeaderCell";
671
- function ve(l) {
672
- const { grid: e } = l, { isResizeMode: t } = e;
673
- return /* @__PURE__ */ s(ce, { component: "datagrid.header", variant: { isResizeMode: t }, style: { gridTemplateColumns: e.gridTemplateColumns.value }, children: e.headerRows.value.map((i) => i.map((n) => /* @__PURE__ */ s(ye, { column: n }, n.uniqueKey))) });
674
- }
675
- ve.displayName = "DataGridHeader";
676
- function xe(l) {
677
- const { grid: e } = l, [t, i] = te(0), n = X(
678
- le.throttle((o) => {
679
- i(o.target.scrollTop);
680
- }, 100),
681
- []
682
- );
683
- return /* @__PURE__ */ h(p, { overflowX: "scroll", props: { onScroll: n }, children: [
684
- /* @__PURE__ */ s(ve, { grid: e }),
685
- /* @__PURE__ */ s(we, { grid: e, scrollTop: t })
1140
+ Le.displayName = "DataGridHeaderCell";
1141
+ function Te(s) {
1142
+ const { grid: e } = s;
1143
+ return /* @__PURE__ */ d(me, { component: "datagrid.header", style: { gridTemplateColumns: e.gridTemplateColumns.value }, children: [
1144
+ e.headerRows.value.map((t) => t.map((i) => /* @__PURE__ */ n(Le, { column: i }, i.uniqueKey))),
1145
+ /* @__PURE__ */ n(ke, { grid: e })
686
1146
  ] });
687
1147
  }
688
- xe.displayName = "DataGridContent";
689
- function Ge(l) {
690
- const { grid: e } = l;
691
- return e.groupColumns.size === 0 ? null : /* @__PURE__ */ h(g, { component: "datagrid.topBar.columnGroups", children: [
692
- /* @__PURE__ */ s(D, { component: "datagrid.topBar.columnGroups.icon", children: /* @__PURE__ */ s(ee, { width: "100%", fill: "currentColor" }) }),
1148
+ Te.displayName = "DataGridHeader";
1149
+ function We(s) {
1150
+ const { grid: e } = s, [t, i] = M(0), r = O(null), o = k((h) => {
1151
+ r.current !== null && cancelAnimationFrame(r.current), r.current = requestAnimationFrame(() => {
1152
+ i(h.target.scrollTop), r.current = null;
1153
+ });
1154
+ }, []);
1155
+ return e.columns.value.userVisibleLeafs.length > 0 ? /* @__PURE__ */ d(g, { overflowX: "scroll", style: { willChange: "scroll-position" }, props: { onScroll: o }, children: [
1156
+ /* @__PURE__ */ n(Te, { grid: e }),
1157
+ /* @__PURE__ */ n(Re, { grid: e, scrollTop: t })
1158
+ ] }) : /* @__PURE__ */ n(Ye, {});
1159
+ }
1160
+ We.displayName = "DataGridContent";
1161
+ function De(s) {
1162
+ const { grid: e } = s;
1163
+ return e.groupColumns.size === 0 ? null : /* @__PURE__ */ d(m, { component: "datagrid.topBar.columnGroups", children: [
1164
+ /* @__PURE__ */ n(I, { component: "datagrid.topBar.columnGroups.icon", children: /* @__PURE__ */ n(se, { width: "100%", fill: "currentColor" }) }),
693
1165
  Array.from(e.groupColumns, (t) => {
694
- const i = e.columns.value.leafs.findOrThrow((n) => n.key === t);
695
- return /* @__PURE__ */ h(Te.Fragment, { children: [
696
- /* @__PURE__ */ s(ae, { fill: "currentColor", width: "14px", height: "14px", rotate: -90 }),
697
- /* @__PURE__ */ h(g, { component: "datagrid.topBar.columnGroups.item", children: [
1166
+ const i = e.columns.value.leafs.findOrThrow((r) => r.key === t);
1167
+ return /* @__PURE__ */ d(Ee.Fragment, { children: [
1168
+ /* @__PURE__ */ n(ge, { fill: "currentColor", width: "14px", height: "14px", rotate: -90 }),
1169
+ /* @__PURE__ */ d(m, { component: "datagrid.topBar.columnGroups.item", children: [
698
1170
  i.header ?? i.key,
699
- /* @__PURE__ */ s(w, { component: "datagrid.topBar.columnGroups.item.icon", onClick: () => e.toggleGrouping(i.key), children: /* @__PURE__ */ s(_e, { fill: "currentColor", width: "100%" }) })
1171
+ /* @__PURE__ */ n(D, { component: "datagrid.topBar.columnGroups.item.icon", onClick: () => e.toggleGrouping(i.key), children: /* @__PURE__ */ n(g, { fontSize: 10, color: "gray-400", hover: { color: "gray-600" }, children: "✕" }) })
700
1172
  ] })
701
1173
  ] }, t);
702
1174
  })
703
1175
  ] });
704
1176
  }
705
- Ge.displayName = "DataGridColumnGroups";
706
- function be(l) {
707
- const { grid: e } = l, [t, i, n] = de({ event: "mousedown" }), o = j(
1177
+ De.displayName = "DataGridColumnGroups";
1178
+ function Qe(s) {
1179
+ const { grid: e } = s, [t, i] = M(e.globalFilterValue), r = O(null);
1180
+ z(() => () => {
1181
+ r.current && clearTimeout(r.current);
1182
+ }, []);
1183
+ const o = k(
1184
+ (c) => {
1185
+ const p = c.target.value;
1186
+ i(p), r.current && clearTimeout(r.current), r.current = setTimeout(() => {
1187
+ e.setGlobalFilter(p), r.current = null;
1188
+ }, 300);
1189
+ },
1190
+ [e]
1191
+ ), a = k(() => {
1192
+ i(""), e.setGlobalFilter("");
1193
+ }, [e]), { filtered: h, total: u } = e.filterStats, l = e.hasActiveFilters && h !== u;
1194
+ return /* @__PURE__ */ d(m, { component: "datagrid.topBar.globalFilter", children: [
1195
+ l && /* @__PURE__ */ d(g, { component: "datagrid.topBar.globalFilter.stats", children: [
1196
+ h,
1197
+ "/",
1198
+ u
1199
+ ] }),
1200
+ /* @__PURE__ */ d(m, { position: "relative", ai: "center", children: [
1201
+ /* @__PURE__ */ n(m, { position: "absolute", left: 3, pointerEvents: "none", color: "gray-400", theme: { dark: { color: "gray-500" } }, children: /* @__PURE__ */ n(ze, { fill: "currentColor", width: "14px" }) }),
1202
+ /* @__PURE__ */ n(j, { placeholder: "Search...", variant: "compact", value: t, onChange: o, pl: 8, pr: t ? 8 : 3 }),
1203
+ t && /* @__PURE__ */ n(
1204
+ g,
1205
+ {
1206
+ position: "absolute",
1207
+ right: 2,
1208
+ cursor: "pointer",
1209
+ p: 1,
1210
+ color: "gray-400",
1211
+ hover: { color: "gray-600" },
1212
+ theme: { dark: { color: "gray-500", hover: { color: "gray-300" } } },
1213
+ props: { onClick: a },
1214
+ children: /* @__PURE__ */ n(g, { fontSize: 12, fontWeight: 600, children: "✕" })
1215
+ }
1216
+ )
1217
+ ] })
1218
+ ] });
1219
+ }
1220
+ function _e(s) {
1221
+ const { grid: e } = s, i = X(
708
1222
  () => e.columns.value.leafs.filter(
709
- (r) => ![E, C, _, x].includes(r.key)
1223
+ (l) => ![V, G, _, T].includes(l.key)
710
1224
  ),
711
1225
  [e.columns.value.leafs]
712
- );
713
- return /* @__PURE__ */ h(w, { component: "datagrid.topBar.contextMenu", onClick: () => i(!t), children: [
714
- /* @__PURE__ */ s(Be, { viewBox: "0 0 24 24", width: "20", fill: "currentColor", ...l, children: /* @__PURE__ */ s("path", { d: "M5 6h14M5 12h14M5 18h14", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round" }) }),
715
- t && /* @__PURE__ */ s(he, { component: "datagrid.topBar.contextMenu.tooltip", ref: n, children: o.map((r) => /* @__PURE__ */ h(
716
- w,
717
- {
718
- component: "datagrid.topBar.contextMenu.tooltip.item",
719
- onClick: (u) => {
720
- u.stopPropagation(), r.toggleVisibility();
721
- },
722
- children: [
723
- /* @__PURE__ */ s(q, { variant: "datagrid", checked: r.isVisible, onChange: () => {
724
- }, focus: { outline: 0 } }),
725
- r.header ?? r.key
726
- ]
1226
+ ).map((l) => ({
1227
+ id: String(l.key),
1228
+ label: l.header ?? l.key,
1229
+ leaf: l
1230
+ })), r = i.filter((l) => l.leaf.isVisible).map((l) => l.id), o = i.length, h = o - r.length > 0;
1231
+ return /* @__PURE__ */ d(
1232
+ b,
1233
+ {
1234
+ multiple: !0,
1235
+ showCheckbox: !0,
1236
+ hideIcon: !0,
1237
+ variant: "compact",
1238
+ value: r,
1239
+ onChange: (l, c) => {
1240
+ const p = new Set(c);
1241
+ i.forEach((f) => {
1242
+ const y = p.has(f.id);
1243
+ f.leaf.isVisible !== y && f.leaf.toggleVisibility();
1244
+ });
727
1245
  },
728
- r.key
729
- )) })
730
- ] });
1246
+ isSearchable: i.length > 6,
1247
+ searchPlaceholder: "Search columns...",
1248
+ display: "inline-flex",
1249
+ children: [
1250
+ /* @__PURE__ */ n(b.Display, { children: (l) => {
1251
+ const c = l.length === 0;
1252
+ return /* @__PURE__ */ d(m, { ai: "center", gap: 2, children: [
1253
+ /* @__PURE__ */ d(fe, { viewBox: "0 0 20 20", width: "18", height: "18", children: [
1254
+ /* @__PURE__ */ n("rect", { x: "2", y: "3", width: "4", height: "14", rx: "1", fill: "currentColor", opacity: 0.9 }),
1255
+ /* @__PURE__ */ n("rect", { x: "8", y: "3", width: "4", height: "14", rx: "1", fill: "currentColor", opacity: 0.6 }),
1256
+ /* @__PURE__ */ n("rect", { x: "14", y: "3", width: "4", height: "14", rx: "1", fill: "currentColor", opacity: 0.3 })
1257
+ ] }),
1258
+ h && /* @__PURE__ */ d(
1259
+ g,
1260
+ {
1261
+ tag: "span",
1262
+ fontSize: 11,
1263
+ lineHeight: 16,
1264
+ fontWeight: 500,
1265
+ px: 2,
1266
+ py: 0.5,
1267
+ borderRadius: 1,
1268
+ bgColor: c ? "red-100" : "amber-100",
1269
+ color: c ? "red-700" : "amber-700",
1270
+ theme: {
1271
+ dark: {
1272
+ bgColor: c ? "red-900" : "amber-900",
1273
+ color: c ? "red-300" : "amber-300"
1274
+ }
1275
+ },
1276
+ children: [
1277
+ l.length,
1278
+ "/",
1279
+ o
1280
+ ]
1281
+ }
1282
+ )
1283
+ ] });
1284
+ } }),
1285
+ /* @__PURE__ */ n(b.SelectAll, { children: "Show All" }),
1286
+ /* @__PURE__ */ n(b.Unselect, { children: "Hide All" }),
1287
+ i.map((l) => /* @__PURE__ */ n(b.Item, { value: l.id, textWrap: "nowrap", children: l.label }, l.id))
1288
+ ]
1289
+ }
1290
+ );
731
1291
  }
732
- be.displayName = "DataGridTopBarContextMenu";
733
- function Le(l) {
734
- const { grid: e } = l;
735
- return /* @__PURE__ */ h(g, { component: "datagrid.topBar", position: "relative", children: [
736
- /* @__PURE__ */ s(be, { grid: e }),
737
- /* @__PURE__ */ s(Ge, { grid: e })
1292
+ _e.displayName = "DataGridTopBarContextMenu";
1293
+ function Ve(s) {
1294
+ const { grid: e } = s, { title: t, topBarContent: i, globalFilter: r } = e.props.def;
1295
+ return /* @__PURE__ */ d(m, { component: "datagrid.topBar", position: "relative", ai: "center", jc: "space-between", gap: 4, flexWrap: "wrap", children: [
1296
+ /* @__PURE__ */ d(m, { ai: "center", gap: 3, flexWrap: "wrap", minWidth: 0, children: [
1297
+ /* @__PURE__ */ n(_e, { grid: e }),
1298
+ t && /* @__PURE__ */ n(g, { fontWeight: 600, fontSize: 16, color: "gray-800", theme: { dark: { color: "gray-100" } }, children: t }),
1299
+ /* @__PURE__ */ n(De, { grid: e })
1300
+ ] }),
1301
+ /* @__PURE__ */ d(m, { ai: "center", gap: 3, flexWrap: "wrap", jc: "flex-end", minWidth: 0, children: [
1302
+ i && /* @__PURE__ */ n(g, { children: i }),
1303
+ r && /* @__PURE__ */ n(Qe, { grid: e })
1304
+ ] })
738
1305
  ] });
739
1306
  }
740
- Le.displayName = "DataGridTopBar";
741
- function Ie(l) {
742
- const [e, t] = te(0), i = De();
743
- return i.current || (i.current = new Ne(l, () => t((n) => n + 1))), Q(() => {
744
- i.current.props = l, i.current.rows.clear(), i.current.flatRows.clear(), i.current.update();
745
- }, [l.data]), Q(() => {
746
- i.current.props = l, i.current.sourceColumns.clear(), i.current.columns.clear(), i.current.headerRows.clear(), i.current.gridTemplateColumns.clear(), i.current.rows.clear(), i.current.flatRows.clear(), i.current.sizes.clear(), i.current.update();
747
- }, [l.def]), Q(() => {
748
- i.current.props = l, i.current.update();
749
- }, [l.loading]), i.current;
1307
+ Ve.displayName = "DataGridTopBar";
1308
+ function Ze(s) {
1309
+ const [e, t] = M(0), i = O();
1310
+ return i.current || (i.current = new je(s, () => t((r) => r + 1))), z(() => {
1311
+ i.current.props = s, i.current.rows.clear(), i.current.flatRows.clear(), i.current.update();
1312
+ }, [s.data]), z(() => {
1313
+ i.current.props = s, i.current.sourceColumns.clear(), i.current.columns.clear(), i.current.headerRows.clear(), i.current.gridTemplateColumns.clear(), i.current.rows.clear(), i.current.flatRows.clear(), i.current.sizes.clear(), i.current.update();
1314
+ }, [s.def]), z(() => {
1315
+ i.current.props = s, i.current.update();
1316
+ }, [s.loading]), z(() => {
1317
+ i.current.props = s, i.current.rows.clear(), i.current.flatRows.clear(), i.current.update();
1318
+ }, [s.globalFilterValue, s.columnFilters]), i.current;
750
1319
  }
751
- function Ve(l) {
752
- const e = Ie(l);
753
- return console.debug("\x1B[36m%s\x1B[0m", "[react-box]: DataGrid render"), /* @__PURE__ */ h(p, { component: "datagrid", style: e.sizes.value, props: { role: "presentation" }, children: [
754
- e.props.def.topBar && /* @__PURE__ */ s(Le, { grid: e }),
755
- /* @__PURE__ */ s(xe, { grid: e }),
756
- e.props.def.bottomBar && /* @__PURE__ */ s(Pe, { grid: e })
1320
+ function et(s) {
1321
+ const e = Ze(s), t = O(null);
1322
+ return Pe(() => {
1323
+ const i = t.current;
1324
+ if (!i) return;
1325
+ const r = new ResizeObserver((o) => {
1326
+ const a = o[0]?.contentRect.width ?? 0;
1327
+ e.setContainerWidth(a);
1328
+ });
1329
+ return r.observe(i), () => r.disconnect();
1330
+ }, [e]), console.debug("\x1B[36m%s\x1B[0m", "[react-box]: DataGrid render"), /* @__PURE__ */ d(g, { ref: t, component: "datagrid", style: e.sizes.value, props: { role: "presentation" }, children: [
1331
+ e.props.def.topBar && /* @__PURE__ */ n(Ve, { grid: e }),
1332
+ /* @__PURE__ */ n(We, { grid: e }),
1333
+ e.props.def.bottomBar && /* @__PURE__ */ n(Oe, { grid: e })
757
1334
  ] });
758
1335
  }
759
- Ve.displayName = "DataGrid";
1336
+ et.displayName = "DataGrid";
760
1337
  export {
761
- Ve as default
1338
+ et as default
762
1339
  };