@cronocode/react-box 3.0.21 → 3.1.2

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 (56) hide show
  1. package/box.d.ts +6 -1
  2. package/box.mjs +4 -4
  3. package/components/baseSvg.cjs +1 -1
  4. package/components/baseSvg.d.ts +1 -1
  5. package/components/button.cjs +1 -1
  6. package/components/checkbox.cjs +1 -1
  7. package/components/dataGrid/components/dataGridBody.d.ts +7 -0
  8. package/components/dataGrid/components/dataGridBottomBar.d.ts +6 -0
  9. package/components/dataGrid/components/dataGridCellRowSelection.d.ts +6 -0
  10. package/components/dataGrid/components/dataGridCellText.d.ts +6 -0
  11. package/components/dataGrid/components/dataGridColumnGroups.d.ts +1 -1
  12. package/components/dataGrid/components/dataGridContent.d.ts +6 -0
  13. package/components/dataGrid/components/dataGridHeader.d.ts +6 -0
  14. package/components/dataGrid/components/dataGridHeaderCellContextMenu.d.ts +6 -0
  15. package/components/dataGrid/components/dataGridHeaderCellResizer.d.ts +6 -0
  16. package/components/dataGrid/components/dataGridPagination.d.ts +1 -1
  17. package/components/dataGrid/components/dataGridTopBar.d.ts +6 -0
  18. package/components/dataGrid/components/dataGridTopBarContextMenu.d.ts +6 -0
  19. package/components/dataGrid/contracts/dataGridContract.d.ts +22 -1
  20. package/components/dataGrid/models/cellModel.d.ts +1 -1
  21. package/components/dataGrid/models/columnModel.d.ts +5 -2
  22. package/components/dataGrid/models/gridModel.d.ts +16 -8
  23. package/components/dataGrid/models/groupRowModel.d.ts +2 -1
  24. package/components/dataGrid/models/rowModel.d.ts +7 -6
  25. package/components/dataGrid.cjs +1 -1
  26. package/components/dataGrid.d.ts +1 -1
  27. package/components/dataGrid.mjs +560 -604
  28. package/components/dropdown.cjs +1 -1
  29. package/components/dropdown.mjs +112 -136
  30. package/components/flex.cjs +1 -1
  31. package/components/form.cjs +1 -1
  32. package/components/form.mjs +1 -1
  33. package/components/grid.cjs +1 -1
  34. package/components/radioButton.cjs +1 -1
  35. package/components/radioButton.mjs +10 -10
  36. package/components/semantics.d.ts +25 -25
  37. package/components/semantics.mjs +1 -1
  38. package/components/textarea.cjs +1 -1
  39. package/components/textbox.cjs +1 -1
  40. package/components/tooltip.cjs +1 -1
  41. package/components/tooltip.d.ts +6 -3
  42. package/components/tooltip.mjs +34 -34
  43. package/core/boxStyles.d.ts +28 -4
  44. package/core/boxStylesFormatters.d.ts +1 -1
  45. package/core/coreTypes.d.ts +1 -1
  46. package/core/extends/boxComponents.d.ts +196 -19
  47. package/core/extends/useComponents.d.ts +1 -1
  48. package/core.cjs +3 -3
  49. package/core.mjs +477 -307
  50. package/icons/expandIcon.d.ts +2 -0
  51. package/icons/sortIcon.d.ts +2 -0
  52. package/package.json +24 -14
  53. package/ssg.cjs +1 -1
  54. package/ssg.mjs +17 -16
  55. package/utils/object/objectUtils.d.ts +2 -2
  56. package/icons/arrowIcon.d.ts +0 -2
@@ -1,56 +1,40 @@
1
- var ae = Object.defineProperty;
2
- var ue = (u, e, t) => e in u ? ae(u, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : u[e] = t;
3
- var a = (u, e, t) => ue(u, typeof e != "symbol" ? e + "" : e, t);
4
- import { jsx as r, jsxs as c, Fragment as he } from "react/jsx-runtime";
5
- import g from "../box.mjs";
6
- import j from "./grid.mjs";
7
- import de, { useMemo as E, useState as z, forwardRef as ce, useRef as me, useCallback as ge, useImperativeHandle as pe } from "react";
8
- import { F as q, m as D, A as $, b as Y, D as fe, P as K, G as H, C as Ce, S as we, d as ye } from "../core.mjs";
9
- import p from "./button.mjs";
10
- import V from "./checkbox.mjs";
11
- import C from "./flex.mjs";
12
- import J from "./tooltip.mjs";
13
- import ve from "./baseSvg.mjs";
14
- import Re from "./textbox.mjs";
15
- const be = "NO_PIN";
16
- class G {
1
+ import { jsxs as u, jsx as r, Fragment as Ge } from "react/jsx-runtime";
2
+ import h from "../box.mjs";
3
+ import g from "./flex.mjs";
4
+ import be, { useCallback as W, useMemo as H, useState as O, useRef as ke, useEffect as z } from "react";
5
+ import { F as J, m as S, E as Q, b as Z, D as Le, S as A, P as q, G as $, C as De } from "../core.mjs";
6
+ import ee from "./grid.mjs";
7
+ import I from "./checkbox.mjs";
8
+ import f from "./button.mjs";
9
+ import { Span as L } from "./semantics.mjs";
10
+ import te from "./tooltip.mjs";
11
+ import Te from "./baseSvg.mjs";
12
+ function Se(a) {
13
+ const { grid: e } = a;
14
+ return /* @__PURE__ */ u(g, { component: "datagrid.bottomBar", children: [
15
+ /* @__PURE__ */ u(h, { children: [
16
+ "Rows: ",
17
+ e.props.data.length
18
+ ] }),
19
+ e.props.def.rowSelection && /* @__PURE__ */ u(h, { children: [
20
+ "Selected: ",
21
+ e.selectedRows.size
22
+ ] })
23
+ ] });
24
+ }
25
+ function ie(a) {
26
+ const { cell: e } = a, t = W(() => {
27
+ e.grid.toggleRowSelection(e.row.key);
28
+ }, [e.grid, e.row.key]);
29
+ return /* @__PURE__ */ r(I, { variant: "datagrid", checked: e.row.selected, onChange: t });
30
+ }
31
+ ie.displayName = "DataGridCellRowSelection";
32
+ const Be = "NO_PIN";
33
+ class D {
17
34
  constructor(e, t, i) {
18
- a(this, "columns", []);
19
- a(this, "_pin");
20
- a(this, "_inlineWidth");
21
- a(this, "resizeColumn", (e) => {
22
- this.grid.isResizeMode = !0;
23
- const t = e.pageX, { MIN_COLUMN_WIDTH_PX: i, update: o } = this.grid, s = this.leafs.sumBy((d) => d.inlineWidth) - this.leafs.length * i, n = this.leafs.toRecord((d) => [d.key, d.inlineWidth]), h = q.throttle((d) => {
24
- const w = (d.pageX - t) * (this.pin === "RIGHT" ? -1 : 1);
25
- this.leafs.forEach((y) => {
26
- const k = n[y.key], x = s > 0 ? (k - i) / s * w : w / this.leafs.length, v = Math.round(k + x);
27
- y.setWidth(v < i ? i : v);
28
- }), this.grid.headerRows.clear(), this.grid.sizes.clear(), o();
29
- }, 20), l = new AbortController(), m = (d) => {
30
- l.abort(), this.grid.isResizeMode = !1, o();
31
- };
32
- window.addEventListener("mousemove", h, l), window.addEventListener("mouseup", m, l);
33
- });
34
- a(this, "pinColumn", (e) => {
35
- this.isLeaf ? this._pin = e : this.columns.forEach((t) => t.pinColumn(e)), this.grid.pinColumn(this.uniqueKey, e);
36
- });
37
- a(this, "toggleGrouping", () => {
38
- this.grid.toggleGrouping(this.key);
39
- });
40
- a(this, "sortColumn", (...e) => {
41
- this.grid.setSortColumn(this.key, ...e);
42
- });
43
- a(this, "setWidth", (e) => {
44
- if (!this.isLeaf)
45
- throw new Error("Cannot set width for a parent column.");
46
- this._inlineWidth !== e && (this._inlineWidth = e, this.grid.setWidth(this.key, e));
47
- });
48
- a(this, "toggleVisibility", () => {
49
- this.grid.toggleColumnVisibility(this.key);
50
- });
51
- var o;
52
- this.def = e, this.grid = t, this.parent = i, this.columns = ((o = e.columns) == null ? void 0 : o.map((s) => new G(e.pin ? { ...s, pin: e.pin } : s, t, this))) ?? [], this.isLeaf && (this._inlineWidth = this.key == P ? void 0 : this.def.width ?? this.grid.DEFAULT_COLUMN_WIDTH_PX, this._pin = e.pin);
35
+ this.def = e, this.grid = t, this.parent = i, this.columns = e.columns?.map((n) => new D(e.pin ? { ...n, pin: e.pin } : n, t, this)) ?? [], this.isLeaf && (this._inlineWidth = this.key == _ ? void 0 : this.def.width ?? this.grid.DEFAULT_COLUMN_WIDTH_PX, this._pin = e.pin);
53
36
  }
37
+ columns = [];
54
38
  get visibleColumns() {
55
39
  return this.columns.filter((e) => e.isVisible);
56
40
  }
@@ -66,6 +50,10 @@ class G {
66
50
  get isLeaf() {
67
51
  return this.columns.length === 0;
68
52
  }
53
+ get Cell() {
54
+ return this.def.Cell;
55
+ }
56
+ _pin;
69
57
  get pin() {
70
58
  if (this.isLeaf) return this._pin;
71
59
  const e = [...new Set(this.columns.flatMap((t) => t.pin))];
@@ -77,10 +65,10 @@ class G {
77
65
  getPinnedColumn(e) {
78
66
  if (this.hasPin(e)) {
79
67
  if (this.isLeaf) return this;
80
- const t = new G({ ...this.def, pin: e }, this.grid, this.parent);
68
+ const t = new D({ ...this.def, pin: e }, this.grid, this.parent);
81
69
  return t.columns = this.columns.filter((i) => i.hasPin(e)).map((i) => {
82
- const o = i.getPinnedColumn(e);
83
- return o.parent = t, o;
70
+ const n = i.getPinnedColumn(e);
71
+ return n.parent = t, n;
84
72
  }).filter((i) => !!i), t;
85
73
  }
86
74
  }
@@ -94,6 +82,7 @@ class G {
94
82
  const e = [this];
95
83
  return e.push(...this.columns.flatMap((t) => t.flatColumns)), e;
96
84
  }
85
+ _inlineWidth;
97
86
  get inlineWidth() {
98
87
  if (this.isLeaf) return this._inlineWidth;
99
88
  const e = this.visibleColumns.map((t) => t.inlineWidth).filter((t) => typeof t == "number");
@@ -103,22 +92,22 @@ class G {
103
92
  get left() {
104
93
  let e = 0;
105
94
  if (this.parent) {
106
- const { visibleColumns: t, left: i } = this.parent, o = t.findIndex((s) => s === this);
107
- e += t.sumBy((s, n) => n < o ? s.inlineWidth ?? 0 : 0), e += i;
95
+ const { visibleColumns: t, left: i } = this.parent, n = t.findIndex((o) => o === this);
96
+ e += t.sumBy((o, s) => s < n ? o.inlineWidth ?? 0 : 0), e += i;
108
97
  } else {
109
- const t = this.grid.columns.value.left.filter((o) => o.isVisible), i = t.findIndex((o) => o === this);
110
- e += t.sumBy((o, s) => s < i ? o.inlineWidth ?? 0 : 0);
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);
111
100
  }
112
101
  return e;
113
102
  }
114
103
  get right() {
115
104
  let e = 0;
116
105
  if (this.parent) {
117
- const { visibleColumns: t } = this.parent, i = t.reverse(), o = i.findIndex((s) => s === this);
118
- e += i.sumBy((s, n) => n < o ? s.inlineWidth ?? 0 : 0), e += this.parent.right;
106
+ const { visibleColumns: t } = this.parent, i = t.reverse(), n = i.findIndex((o) => o === this);
107
+ e += i.sumBy((o, s) => s < n ? o.inlineWidth ?? 0 : 0), e += this.parent.right;
119
108
  } else {
120
- const i = this.grid.columns.value.right.filter((s) => s.isVisible).reverse(), o = i.findIndex((s) => s === this);
121
- e += i.sumBy((s, n) => n < o ? s.inlineWidth ?? 0 : 0);
109
+ const i = this.grid.columns.value.right.filter((o) => o.isVisible).reverse(), n = i.findIndex((o) => o === this);
110
+ e += i.sumBy((o, s) => s < n ? o.inlineWidth ?? 0 : 0);
122
111
  }
123
112
  return e;
124
113
  }
@@ -131,7 +120,7 @@ class G {
131
120
  return (this.pin === "LEFT" ? this.grid.columns.value.left.filter((t) => t.isVisible).at(-1) : this.grid.columns.value.right.filter((t) => t.isVisible).at(0)) === this;
132
121
  }
133
122
  get isVisible() {
134
- return this.isLeaf ? !this.grid.hiddenColumns.includes(this.key) : this.leafs.some((e) => e.isVisible);
123
+ return this.isLeaf ? !this.grid.hiddenColumns.has(this.key) : this.leafs.some((e) => e.isVisible);
135
124
  }
136
125
  // Approved
137
126
  get leafs() {
@@ -152,268 +141,433 @@ class G {
152
141
  get gridRows() {
153
142
  return this.isLeaf ? this.grid.columns.value.maxDeath - this.death : 1;
154
143
  }
144
+ 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((c) => c.inlineWidth) - this.leafs.length * i, s = this.leafs.toRecord((c) => [c.key, c.inlineWidth]), m = J.throttle((c) => {
147
+ const p = (c.pageX - t) * (this.pin === "RIGHT" ? -1 : 1);
148
+ this.leafs.forEach((w) => {
149
+ const v = s[w.key], x = o > 0 ? (v - i) / o * p : p / this.leafs.length, C = Math.round(v + x);
150
+ w.setWidth(C < i ? i : C);
151
+ }), this.grid.sizes.clear(), n();
152
+ }, 40), l = new AbortController(), d = (c) => {
153
+ l.abort(), this.grid.isResizeMode = !1, n();
154
+ };
155
+ window.addEventListener("mousemove", m, l), window.addEventListener("mouseup", d, l);
156
+ };
157
+ pinColumn = (e) => {
158
+ this.isLeaf ? this._pin = e : this.columns.forEach((t) => t.pinColumn(e)), this.grid.pinColumn(this.uniqueKey, e);
159
+ };
160
+ toggleGrouping = () => {
161
+ this.grid.toggleGrouping(this.key);
162
+ };
163
+ sortColumn = (...e) => {
164
+ this.grid.setSortColumn(this.key, ...e);
165
+ };
166
+ setWidth = (e) => {
167
+ if (!this.isLeaf)
168
+ throw new Error("Cannot set width for a parent column.");
169
+ this._inlineWidth !== e && (this._inlineWidth = e, this.grid.setWidth(this.key, e));
170
+ };
171
+ toggleVisibility = () => {
172
+ this.grid.toggleColumnVisibility(this.key);
173
+ };
155
174
  }
156
- class ke {
175
+ class _e {
157
176
  constructor(e, t, i) {
158
177
  this.grid = e, this.row = t, this.column = i;
159
178
  }
160
179
  get value() {
161
- return this.column.key === b ? this.row.rowIndex + 1 : this.column.key === f ? `> ${this.row.groupValue} (${this.row.count})` : null;
180
+ return this.column.key === b ? this.row.rowIndex + 1 : this.row.data[this.column.key];
162
181
  }
163
182
  }
164
- class Q {
165
- constructor(e, t, i, o, s) {
166
- a(this, "parentRow");
167
- this.grid = e, this.groupColumn = t, this.rows = i, this.rowIndex = o, this.groupValue = s, i.forEach((n) => n.parentRow = this);
168
- }
169
- get rowKey() {
170
- var e;
171
- return `${((e = this.parentRow) == null ? void 0 : e.rowKey) ?? ""}${this.groupColumn.key}${this.groupValue}`;
183
+ class Y {
184
+ constructor(e, t, i) {
185
+ this.grid = e, this.data = t, this.rowIndex = i, this.grid = e, this.data = t, this.key = this.grid.getRowKey(t);
172
186
  }
187
+ key;
188
+ parentRow;
189
+ count = 1;
173
190
  get cells() {
174
- return this.grid.columns.value.visibleLeafs.map((e) => new ke(this.grid, this, e));
191
+ return this.grid.columns.value.visibleLeafs.map((e) => new _e(this.grid, this, e));
175
192
  }
176
- get expanded() {
177
- return this.grid.expandedGroupRow[this.rowKey];
193
+ get selected() {
194
+ return this.grid.selectedRows.has(this.key);
178
195
  }
179
- get depth() {
180
- return this.parentRow ? this.parentRow.depth + 1 : 0;
196
+ get flatRows() {
197
+ return this;
181
198
  }
182
- get count() {
183
- return this.rows.sumBy((e) => e.count, 0);
199
+ get allRows() {
200
+ return this;
184
201
  }
185
- get flatRows() {
186
- return this.expanded ? [this, ...this.rows.flatMap((e) => e.flatRows)] : [this];
202
+ }
203
+ const _ = "empty-cell", b = "row-number-cell", B = "row-selection-cell", y = "grouping-cell";
204
+ class Me {
205
+ constructor(e, t) {
206
+ this.props = e, this.update = t, console.debug("\x1B[32m%s\x1B[0m", "[react-box]: DataGrid GridModel ctor");
207
+ }
208
+ sourceColumns = S(() => {
209
+ const { def: e } = this.props, t = [];
210
+ if (this.groupColumns.size > 0 && t.push(new D({ key: y }, this)), t.push(...e.columns.map((i) => new D(i, this))), t.push(new D({ key: _, Cell: () => null }, this)), e.rowSelection) {
211
+ const i = typeof e.rowSelection == "object" && e.rowSelection.pinned ? "LEFT" : void 0;
212
+ t.unshift(
213
+ new D({ key: B, pin: i, width: 50, align: "center", Cell: ie }, this)
214
+ );
215
+ }
216
+ if (e.showRowNumber) {
217
+ const i = typeof e.showRowNumber == "object" && e.showRowNumber.pinned ? "LEFT" : void 0;
218
+ t.unshift(new D({ key: b, pin: i, width: 70, align: "right" }, this));
219
+ }
220
+ return t;
221
+ });
222
+ columns = S(() => {
223
+ console.debug("\x1B[36m%s\x1B[0m", "[react-box]: DataGrid columns memo");
224
+ 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), n = [...e, ...t, ...i].flatMap((l) => l.flatColumns), o = n.filter((l) => l.isLeaf), s = n.filter((l) => l.isLeaf && l.isVisible), m = n.maxBy((l) => l.death) + 1;
225
+ return {
226
+ left: e,
227
+ middle: t,
228
+ right: i,
229
+ flat: n,
230
+ leafs: o,
231
+ visibleLeafs: s,
232
+ maxDeath: m
233
+ };
234
+ });
235
+ headerRows = S(() => (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 ?? Be).toRecord((n) => [n.key, n.values]);
237
+ return [
238
+ ...i.LEFT?.filter((n) => n.isVisible) ?? [],
239
+ ...i.NO_PIN?.filter((n) => n.isVisible) ?? [],
240
+ ...i.RIGHT?.filter((n) => n.isVisible) ?? []
241
+ ];
242
+ })));
243
+ gridTemplateColumns = S(() => {
244
+ console.debug("\x1B[36m%s\x1B[0m", "[react-box]: DataGrid gridTemplateColumns memo");
245
+ const { visibleLeafs: e } = this.columns.value, t = e.sumBy((s) => s.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}`;
247
+ });
248
+ rows = S(() => {
249
+ console.debug("\x1B[36m%s\x1B[0m", "[react-box]: DataGrid rows memo");
250
+ let e = this.props.data;
251
+ if (this._sortColumn && (e = e.sortBy((t) => t[this._sortColumn], this._sortDirection)), this.groupColumns.size > 0) {
252
+ const t = (i, n, o) => {
253
+ const s = n.values().next().value;
254
+ n.delete(s);
255
+ const m = this.columns.value.leafs.findOrThrow((l) => l.key === s);
256
+ return this._sortColumn === y && (i = i.sortBy((l) => l[s], this._sortDirection)), i.groupBy((l) => l[s]).map((l) => {
257
+ let d;
258
+ n.size > 0 ? d = t(l.values, new Set(n), o + 1) : d = l.values.map((p, w) => new Y(this, p, o + 1 + w));
259
+ const c = new ne(this, m, d, o, l.key);
260
+ return o += 1, c.expanded && (o += d.length), c;
261
+ });
262
+ };
263
+ return t(e, new Set(this.groupColumns), 0);
264
+ }
265
+ return e.map((t, i) => new Y(this, t, i));
266
+ });
267
+ flatRows = S(() => (console.debug("\x1B[36m%s\x1B[0m", "[react-box]: DataGrid flatRows memo"), this.rows.value.flatMap((e) => e.flatRows)));
268
+ get rowHeight() {
269
+ return this.props.def.rowHeight ?? this.DEFAULT_ROW_HEIGHT_PX;
270
+ }
271
+ sizes = S(() => {
272
+ 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: s } = o;
275
+ return typeof s == "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;
276
+ }, {});
277
+ 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 === y);
279
+ if (i) {
280
+ const n = t.sumBy((o) => o.pin === i.pin && o.key !== b && o.key !== B ? o.inlineWidth ?? 0 : 0);
281
+ e[i.groupColumnWidthVarName] = `${n}px`;
282
+ }
283
+ return this.groupColumns.forEach((n) => {
284
+ const o = this.columns.value.leafs.findOrThrow((s) => s.key === n);
285
+ e[o.groupColumnWidthVarName] = `${t.sumBy((s) => s.pin === o.pin ? s.inlineWidth ?? 0 : 0)}px`;
286
+ }), e;
287
+ });
288
+ DEFAULT_ROW_HEIGHT_PX = 48;
289
+ MIN_COLUMN_WIDTH_PX = 48;
290
+ DEFAULT_COLUMN_WIDTH_PX = 200;
291
+ isResizeMode = !1;
292
+ expandedGroupRow = /* @__PURE__ */ new Set();
293
+ selectedRows = /* @__PURE__ */ new Set();
294
+ get leftEdge() {
295
+ return this.columns.value.left.sumBy((e) => e.inlineWidth ?? 0);
187
296
  }
188
- get groupingColumn() {
189
- return this.grid.columns.value.leafs.findOrThrow((e) => e.key === f);
297
+ get rightEdge() {
298
+ return this.columns.value.right.sumBy((e) => e.inlineWidth ?? 0);
190
299
  }
191
- get groupingColumnGridColumn() {
192
- const { visibleLeafs: e } = this.grid.columns.value, { groupingColumn: t } = this;
193
- return e.sumBy(
194
- (o) => o.pin === t.pin && o.key !== P && o.key !== T && o.key !== b ? 1 : 0
195
- );
300
+ leftEdgeVarName = "--left-edge";
301
+ rowHeightVarName = "--row-height";
302
+ _idMap = /* @__PURE__ */ new WeakMap();
303
+ getRowKey(e) {
304
+ const { rowKey: t } = this.props.def;
305
+ return t ? typeof t == "function" ? t(e) : e[t] : (this._idMap.has(e) || this._idMap.set(e, crypto.randomUUID()), this._idMap.get(e));
306
+ }
307
+ setSortColumn = (e, ...t) => {
308
+ if (t.length > 0)
309
+ [this._sortDirection] = t, this._sortColumn = this._sortDirection ? e : void 0;
310
+ 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";
313
+ }
314
+ this.headerRows.clear(), this.rows.clear(), this.flatRows.clear(), this.update();
315
+ };
316
+ 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();
319
+ };
320
+ 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();
322
+ };
323
+ 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();
325
+ };
326
+ toggleGroupRow = (e) => {
327
+ 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();
328
+ };
329
+ toggleRowSelection = (e) => {
330
+ this.toggleRowsSelection([e]);
331
+ };
332
+ toggleRowsSelection = (e) => {
333
+ this.selectedRows = new Set(this.selectedRows);
334
+ const t = e.every((i) => this.selectedRows.has(i));
335
+ t ? e.forEach((i) => this.selectedRows.delete(i)) : e.forEach((i) => this.selectedRows.add(i)), this.flatRows.clear(), this.update(), this.props.onSelectionChange?.({
336
+ action: t ? "deselect" : "select",
337
+ affectedRowKeys: e,
338
+ selectedRowKeys: Array.from(this.selectedRows),
339
+ isAllSelected: this.selectedRows.size === this.props.data.length
340
+ });
341
+ };
342
+ toggleSelectAllRows = () => {
343
+ this.toggleRowsSelection(this.props.data.map((e) => this.getRowKey(e)));
344
+ };
345
+ 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();
347
+ };
348
+ 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);
353
+ };
354
+ groupColumns = /* @__PURE__ */ new Set();
355
+ hiddenColumns = /* @__PURE__ */ new Set();
356
+ _sortColumn;
357
+ get sortColumn() {
358
+ return this._sortColumn;
196
359
  }
197
- toggleRow() {
198
- this.grid.toggleGroupRow(this.rowKey);
360
+ _sortDirection = "ASC";
361
+ get sortDirection() {
362
+ return this._sortDirection;
199
363
  }
200
364
  }
201
- class xe {
365
+ class Ne {
202
366
  constructor(e, t, i) {
203
367
  this.grid = e, this.row = t, this.column = i;
204
368
  }
205
369
  get value() {
206
- return this.column.key === P ? null : this.column.key === b ? this.row.rowIndex + 1 : this.row.row[this.column.key];
370
+ return this.column.key === b ? this.row.rowIndex + 1 : this.column.key === y ? `${this.row.groupValue} (${this.row.count})` : null;
207
371
  }
208
372
  }
209
- class X {
210
- constructor(e, t, i) {
211
- a(this, "parentRow");
212
- this.grid = e, this.row = t, this.rowIndex = i, this.grid = e, this.row = t;
373
+ class ne {
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((s) => s.parentRow = this);
213
376
  }
214
- get rowKey() {
215
- return this.getRowKey();
377
+ get key() {
378
+ return `${this.parentRow?.key ?? ""}${this.groupColumn.key}${this.groupValue}`;
216
379
  }
380
+ parentRow;
217
381
  get cells() {
218
- return this.grid.columns.value.visibleLeafs.map((e) => new xe(this.grid, this, e));
382
+ return this.grid.columns.value.visibleLeafs.map((e) => new Ne(this.grid, this, e));
219
383
  }
220
- get count() {
221
- return 1;
384
+ get expanded() {
385
+ return this.grid.expandedGroupRow.has(this.key);
222
386
  }
223
- get flatRows() {
224
- return [this];
387
+ get depth() {
388
+ return this.parentRow ? this.parentRow.depth + 1 : 0;
225
389
  }
226
- getRowKey() {
227
- var i;
228
- const { rowKey: e } = this.grid.props.def, t = e ? typeof e == "function" ? e(this.row) : this.row[e] : this.rowIndex;
229
- return `${((i = this.parentRow) == null ? void 0 : i.rowKey) ?? ""}${t}`;
390
+ get count() {
391
+ return this.rows.sumBy((e) => e.count, 0);
230
392
  }
231
- }
232
- const P = "empty-cell", b = "row-number-cell", T = "row-selection-cell", f = "grouping-cell";
233
- class Le {
234
- constructor(e, t) {
235
- a(this, "_sourceColumns", []);
236
- a(this, "columns", D(() => {
237
- const e = this._sourceColumns.map((l) => l.getPinnedColumn("LEFT")).filter((l) => !!l), t = this._sourceColumns.map((l) => l.getPinnedColumn()).filter((l) => !!l), i = this._sourceColumns.map((l) => l.getPinnedColumn("RIGHT")).filter((l) => !!l), o = [...e, ...t, ...i].flatMap((l) => l.flatColumns), s = o.filter((l) => l.isLeaf), n = o.filter((l) => l.isLeaf && l.isVisible), h = o.maxBy((l) => l.death) + 1;
238
- return {
239
- left: e,
240
- middle: t,
241
- right: i,
242
- flat: o,
243
- leafs: s,
244
- visibleLeafs: n,
245
- maxDeath: h
246
- };
247
- }));
248
- a(this, "headerRows", D(() => this.columns.value.flat.groupBy((t) => t.death).sortBy((t) => t.key).map((t) => {
249
- var o, s, n;
250
- const i = t.values.groupBy((h) => h.pin ?? be).toRecord((h) => [h.key, h.values]);
251
- return [
252
- ...((o = i.LEFT) == null ? void 0 : o.filter((h) => h.isVisible)) ?? [],
253
- ...((s = i.NO_PIN) == null ? void 0 : s.filter((h) => h.isVisible)) ?? [],
254
- ...((n = i.RIGHT) == null ? void 0 : n.filter((h) => h.isVisible)) ?? []
255
- ];
256
- })));
257
- a(this, "gridTemplateColumns", D(() => {
258
- const { visibleLeafs: e } = this.columns.value, t = e.sumBy((n) => n.pin === "RIGHT" ? 1 : 0), i = e.length - t - 1, o = i > 0 ? `repeat(${i}, max-content)` : "", s = t > 0 ? `repeat(${t}, max-content)` : "";
259
- return `${o} auto ${s}`;
260
- }));
261
- a(this, "rows", D(() => {
262
- let e = this.props.data;
263
- if (this._sortColumn && (e = e.sortBy((t) => t[this._sortColumn], this._sortDirection)), this.groupColumns.length > 0) {
264
- const t = (i, o, s) => {
265
- const n = o[0];
266
- o = o.removeBy((l) => l === n);
267
- const h = this.columns.value.leafs.findOrThrow((l) => l.key === n);
268
- return this._sortColumn === f && (i = i.sortBy((l) => l[n], this._sortDirection)), i.groupBy((l) => l[n]).map((l) => {
269
- let m;
270
- o.length > 0 ? m = t(l.values, o, s + 1) : m = l.values.map((w, y) => new X(this, w, s + 1 + y));
271
- const d = new Q(this, h, m, s, l.key);
272
- return s += 1, d.expanded && (s += m.length), d;
273
- });
274
- };
275
- return t(e, this.groupColumns, 0);
276
- }
277
- return e.map((t, i) => new X(this, t, i));
278
- }));
279
- a(this, "flatRows", D(() => this.rows.value.flatMap((e) => e.flatRows)));
280
- a(this, "sizes", D(() => {
281
- console.debug("\x1B[36m%s\x1B[0m", "[react-box]: DataGrid sizes memo");
282
- const e = this.columns.value.flat.reduce((o, s) => {
283
- const { inlineWidth: n } = s;
284
- return typeof n == "number" && (o[s.widthVarName] = `${s.inlineWidth}px`), s.pin === "LEFT" && (o[s.leftVarName] = `${s.left}px`), s.pin === "RIGHT" && (o[s.rightVarName] = `${s.right}px`), o;
285
- }, {});
286
- e[this.leftEdgeVarName] = `${this.leftEdge}px`;
287
- const { visibleLeafs: t } = this.columns.value, i = t.find((o) => o.key === f);
288
- if (i) {
289
- const o = t.sumBy((s) => s.pin === i.pin && s.key !== b && s.key !== T ? s.inlineWidth ?? 0 : 0);
290
- e[i.groupColumnWidthVarName] = `${o}px`;
291
- }
292
- return this.groupColumns.forEach((o) => {
293
- const s = this.columns.value.leafs.findOrThrow((n) => n.key === o);
294
- e[s.groupColumnWidthVarName] = `${t.sumBy((n) => n.pin === s.pin ? n.inlineWidth ?? 0 : 0)}px`;
295
- }), e;
296
- }));
297
- a(this, "ROW_HEIGHT", 12);
298
- a(this, "MIN_COLUMN_WIDTH_PX", 48);
299
- a(this, "DEFAULT_COLUMN_WIDTH_PX", 200);
300
- a(this, "isResizeMode", !1);
301
- a(this, "expandedGroupRow", {});
302
- a(this, "leftEdgeVarName", "--left-edge");
303
- a(this, "setSortColumn", (e, ...t) => {
304
- if (t.length > 0)
305
- [this._sortDirection] = t, this._sortColumn = this._sortDirection ? e : void 0;
306
- else {
307
- const { _sortColumn: i, _sortDirection: o } = this;
308
- this._sortColumn = i === e && o === "DESC" ? void 0 : e, this._sortDirection = i === e && o === "ASC" ? "DESC" : "ASC";
309
- }
310
- this.headerRows.clear(), this.rows.clear(), this.flatRows.clear(), this.update();
311
- });
312
- a(this, "pinColumn", (e, t) => {
313
- const i = this.columns.value.flat.findOrThrow((o) => o.uniqueKey === e);
314
- 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();
315
- });
316
- a(this, "toggleGrouping", (e) => {
317
- this.groupColumns.includes(e) ? (this.groupColumns = this.groupColumns.removeBy((i) => i === e), this.hiddenColumns = this.hiddenColumns.removeBy((i) => i === e)) : (this.groupColumns = this.groupColumns.add(e), this.hiddenColumns = this.hiddenColumns.add(e));
318
- const t = this._sourceColumns.find((i) => i.key === f);
319
- if (this.groupColumns.length > 0 && !t) {
320
- const i = this._sourceColumns.sumBy((o) => o.key === b || o.key === T ? 1 : 0);
321
- this._sourceColumns.splice(i, 0, new G({ key: f }, this));
322
- } else this.groupColumns.length === 0 && t && (this._sourceColumns = this._sourceColumns.removeBy((i) => i.key === f));
323
- this.columns.clear(), this.headerRows.clear(), this.gridTemplateColumns.clear(), this.rows.clear(), this.flatRows.clear(), this.sizes.clear(), this.update();
324
- });
325
- a(this, "unGroupAll", () => {
326
- this.groupColumns = [], this._sourceColumns = this._sourceColumns.removeBy((e) => e.key === f), this.columns.clear(), this.headerRows.clear(), this.gridTemplateColumns.clear(), this.rows.clear(), this.flatRows.clear(), this.sizes.clear(), this.update();
327
- });
328
- a(this, "toggleGroupRow", (e) => {
329
- e in this.expandedGroupRow ? delete this.expandedGroupRow[e] : this.expandedGroupRow[e] = !0, this.rows.clear(), this.flatRows.clear(), this.update();
330
- });
331
- a(this, "toggleColumnVisibility", (e) => {
332
- this.hiddenColumns.includes(e) ? this.hiddenColumns = this.hiddenColumns.removeBy((t) => t === e) : this.hiddenColumns = this.hiddenColumns.add(e), this.columns.clear(), this.headerRows.clear(), this.gridTemplateColumns.clear(), this.rows.clear(), this.flatRows.clear(), this.sizes.clear(), this.update();
333
- });
334
- a(this, "setWidth", (e, t) => {
335
- const i = this.columns.value.leafs.find((s) => s.key === e);
336
- if (!i)
337
- throw new Error("Leaf column not found.");
338
- i.setWidth(t), this._sourceColumns.flatMap((s) => s.flatColumns).findOrThrow((s) => s.key === e).setWidth(t);
339
- });
340
- a(this, "groupColumns", []);
341
- a(this, "hiddenColumns", []);
342
- a(this, "_sortColumn");
343
- a(this, "_sortDirection", "ASC");
344
- this.props = e, this.update = t, this._sourceColumns = e.def.columns.map((i) => new G(i, this)), this._sourceColumns.push(new G({ key: P }, this)), this._sourceColumns.unshift(new G({ key: T, width: 50, align: "center" }, this)), this._sourceColumns.unshift(new G({ key: b, pin: "LEFT", width: 70, align: "right" }, this));
393
+ get flatRows() {
394
+ return this.expanded ? [this, ...this.rows.flatMap((e) => e.flatRows)] : [this];
345
395
  }
346
- get leftEdge() {
347
- return this.columns.value.left.sumBy((e) => e.inlineWidth ?? 0);
396
+ get allRows() {
397
+ return this.rows.flatMap((e) => e.allRows);
348
398
  }
349
- get rightEdge() {
350
- return this.columns.value.right.sumBy((e) => e.inlineWidth ?? 0);
399
+ get groupingColumn() {
400
+ return this.grid.columns.value.leafs.findOrThrow((e) => e.key === y);
351
401
  }
352
- get sortColumn() {
353
- return this._sortColumn;
402
+ get groupingColumnGridColumn() {
403
+ const { visibleLeafs: e } = this.grid.columns.value, { groupingColumn: t } = this;
404
+ return e.sumBy(
405
+ (n) => n.pin === t.pin && n.key !== _ && n.key !== B && n.key !== b ? 1 : 0
406
+ );
354
407
  }
355
- get sortDirection() {
356
- return this._sortDirection;
408
+ toggleRow() {
409
+ this.grid.toggleGroupRow(this.key);
357
410
  }
358
411
  }
359
- function _e(u) {
360
- const e = E(() => new Le(u, () => i((s) => s + 1)), [u]), [t, i] = z(0);
361
- return E(() => Object.create(Object.getPrototypeOf(e), Object.getOwnPropertyDescriptors(e)), [e, t]);
362
- }
363
- function Te(u) {
364
- const { column: e } = u, { key: t, pin: i, left: o, right: s, isEdge: n, isLeaf: h, leafs: l, grid: m, header: d, gridRows: w, widthVarName: y, leftVarName: k, rightVarName: x, inlineWidth: v } = e, L = t === P, _ = t === f, R = t === b, W = t === T, I = i === "LEFT", B = i === "RIGHT", S = I || i === "RIGHT", M = I && o === 0, O = I && n, ie = B && n, se = B && s === 0, A = h && !L && !R && !W, oe = h ? 1 : l.length, re = !R && !W, F = !R && !W, ne = E(() => {
365
- if (R) return null;
366
- if (W) return /* @__PURE__ */ r(V, { m: 1 });
367
- if (_) {
368
- if (m.groupColumns.length === 1) {
369
- const U = m.columns.value.leafs.findOrThrow((le) => le.key === m.groupColumns[0]);
370
- return U.header ?? U.key;
371
- }
372
- return "Group";
373
- }
374
- return d ?? t;
375
- }, [m.groupColumns]);
412
+ function E(a) {
413
+ const { children: e, column: t, style: i, ...n } = a, { key: o, pin: s, left: m, right: l, isEdge: d, align: c, widthVarName: p, leftVarName: w, rightVarName: v } = t;
414
+ "align" in t.def && (n.jc = c);
415
+ const x = o === b, C = o === B, R = s === "LEFT", G = s === "RIGHT";
376
416
  return /* @__PURE__ */ r(
377
- C,
417
+ g,
378
418
  {
379
- component: "datagrid.header.cell",
380
- variant: { isRowNumber: R, isPinned: S, isFirstLeftPinned: M, isLastLeftPinned: O, isFirstRightPinned: ie, isLastRightPinned: se, isSortable: A },
381
- gridRow: w,
382
- gridColumn: oe,
419
+ component: "datagrid.cell",
420
+ props: { role: "cell" },
421
+ variant: { isPinned: R || G, isFirstLeftPinned: R && m === 0, isLastLeftPinned: R && d, isFirstRightPinned: G && d, isLastRightPinned: G && l === 0, isRowNumber: x, isRowSelection: C },
383
422
  style: {
384
- width: `var(${y})`,
385
- left: I ? `var(${k})` : void 0,
386
- right: B ? `var(${x})` : void 0
423
+ width: `var(${p})`,
424
+ height: `var(${t.grid.rowHeightVarName})`,
425
+ left: R ? `var(${w})` : void 0,
426
+ right: G ? `var(${v})` : void 0,
427
+ ...i
387
428
  },
388
- children: !L && /* @__PURE__ */ c(he, { children: [
389
- /* @__PURE__ */ r(C, { width: "fit", height: "fit", jc: e.align, props: { onClick: A ? () => e.sortColumn() : void 0 }, children: /* @__PURE__ */ c(
390
- C,
391
- {
392
- overflow: "hidden",
393
- position: h ? void 0 : "sticky",
394
- ai: "center",
395
- transition: "none",
396
- pl: e.align ? void 0 : 4,
397
- style: {
398
- left: i ? void 0 : `var(${m.leftEdgeVarName})`
399
- },
400
- children: [
401
- /* @__PURE__ */ r(g, { overflow: "hidden", textOverflow: "ellipsis", textWrap: "nowrap", children: ne }),
402
- t === m.sortColumn && /* @__PURE__ */ r(g, { pl: (v ?? 0) < 58 ? 0 : 2, children: /* @__PURE__ */ r($, { width: "16px", rotate: m.sortDirection === "ASC" ? 0 : 180, fill: "violet-950" }) }),
403
- F && /* @__PURE__ */ r(g, { minWidth: 10 })
404
- ]
405
- }
406
- ) }),
407
- re && /* @__PURE__ */ r(Ge, { column: e }),
408
- F && /* @__PURE__ */ r(Ee, { column: e })
409
- ] })
429
+ ...n,
430
+ children: e
410
431
  }
411
432
  );
412
433
  }
413
- function Ge(u) {
414
- const { column: e } = u;
434
+ E.displayName = "DataGridCell";
435
+ function oe(a) {
436
+ const { row: e } = a, t = W(() => {
437
+ e.grid.toggleRowsSelection(e.allRows.map((i) => i.key));
438
+ }, []);
439
+ return /* @__PURE__ */ r(g, { className: "grid-row", display: "contents", props: { role: "rowgroup" }, children: e.cells.map((i) => {
440
+ const { key: n, pin: o, groupColumnWidthVarName: s } = i.column, m = o === "RIGHT";
441
+ if (n === y)
442
+ return /* @__PURE__ */ r(
443
+ E,
444
+ {
445
+ column: i.column,
446
+ style: {
447
+ width: `var(${s})`,
448
+ right: m ? "0" : void 0
449
+ },
450
+ br: e.groupingColumn.pin === "LEFT" ? 1 : void 0,
451
+ gridColumn: e.groupingColumnGridColumn,
452
+ pl: 4 * e.depth,
453
+ overflow: "auto",
454
+ children: /* @__PURE__ */ r(h, { textWrap: "nowrap", px: 4, children: /* @__PURE__ */ u(f, { clean: !0, onClick: () => e.toggleRow(), cursor: "pointer", display: "flex", gap: 1, ai: "center", children: [
455
+ /* @__PURE__ */ r(Q, { fill: "currentColor", width: "14px", height: "14px", rotate: e.expanded ? 0 : -90 }),
456
+ i.value
457
+ ] }) })
458
+ },
459
+ n
460
+ );
461
+ if (n === B) {
462
+ const l = e.allRows, d = l.every((p) => p.selected), c = !d && l.some((p) => p.selected);
463
+ return /* @__PURE__ */ r(E, { column: i.column, children: /* @__PURE__ */ r(I, { variant: "datagrid", m: 1, checked: d, indeterminate: c, onChange: t }) }, n);
464
+ }
465
+ if (n === _) return /* @__PURE__ */ r(h, {}, n);
466
+ if (o !== e.groupingColumn.pin || n === b)
467
+ return /* @__PURE__ */ r(E, { column: i.column, px: 4, children: i.value }, n);
468
+ }) });
469
+ }
470
+ oe.displayName = "DataGridGroupRow";
471
+ function re(a) {
472
+ const { cell: e } = a;
473
+ return /* @__PURE__ */ r(g, { height: "fit", width: "fit", overflow: "auto", ai: "center", jc: e.column.align, children: /* @__PURE__ */ r(h, { px: 4, textOverflow: "ellipsis", overflow: "hidden", textWrap: "nowrap", children: e.value }) });
474
+ }
475
+ re.displayName = "DataGridCellText";
476
+ function se(a) {
477
+ const { row: e } = a;
478
+ return /* @__PURE__ */ r(g, { className: "grid-row", display: "contents", props: { role: "row" }, children: e.cells.map((t) => /* @__PURE__ */ r(E, { column: t.column, children: t.column.Cell ? /* @__PURE__ */ r(t.column.Cell, { cell: t }) : /* @__PURE__ */ r(re, { cell: t }) }, t.column.key)) });
479
+ }
480
+ se.displayName = "DataGridRow";
481
+ const Ee = 10, K = 20;
482
+ function le(a) {
483
+ const { grid: e, scrollTop: t } = a, i = e.flatRows.value.length, n = Math.max(0, Math.floor(t / e.rowHeight) - K), o = e.props.def.visibleRowsCount ?? Ee, s = e.rowHeight * o + e.rowHeight / 5, m = H(() => {
484
+ if (console.debug("\x1B[36m%s\x1B[0m", "[react-box]: DataGrid render rows"), e.props.data.length === 0)
485
+ return /* @__PURE__ */ r(g, { jc: "center", ai: "center", gridColumn: "full-row", style: { height: s }, children: e.props.loading ? "loading..." : "empty" });
486
+ const l = o + K * 2;
487
+ return e.flatRows.value.take(l, n).map((c) => c instanceof ne ? /* @__PURE__ */ r(oe, { row: c }, c.key) : /* @__PURE__ */ r(se, { row: c }, c.key));
488
+ }, [e.flatRows.value, e.props.data.length, e.props.loading, n, s, o]);
489
+ return console.debug("\x1B[36m%s\x1B[0m", "[react-box]: DataGrid render DataGridBody"), /* @__PURE__ */ r(h, { style: { height: s }, children: /* @__PURE__ */ r(
490
+ h,
491
+ {
492
+ style: {
493
+ height: `${i * e.rowHeight}px`
494
+ },
495
+ children: /* @__PURE__ */ r(
496
+ ee,
497
+ {
498
+ width: "max-content",
499
+ minWidth: "fit",
500
+ transition: "none",
501
+ style: {
502
+ transform: `translateY(${n * e.rowHeight}px)`,
503
+ gridTemplateColumns: e.gridTemplateColumns.value
504
+ },
505
+ children: m
506
+ }
507
+ )
508
+ }
509
+ ) });
510
+ }
511
+ le.displayName = "DataGridBody";
512
+ function ae(a) {
513
+ const { column: e } = a, [t, i, n] = Z({ hideOnScroll: !0, event: "mousedown" }), [o, s] = O({ top: 0, left: 0 }), m = H(() => o.left > window.innerWidth / 2, [o.left]), l = e.isLeaf && (e.grid.sortColumn !== e.key || e.grid.sortDirection === "DESC"), d = e.isLeaf && (e.grid.sortColumn !== e.key || e.grid.sortDirection === "ASC"), c = e.isLeaf && e.grid.sortColumn === e.key, p = e.pin !== "LEFT", w = e.pin !== "RIGHT", v = !!e.pin, x = e.isLeaf && e.key !== y, C = e.isLeaf && e.key === y, R = l || d || c, G = p || w || v, k = e.align === "right" ? 2 : void 0, T = e.align === "right" ? void 0 : e.pin === "RIGHT" ? 2.5 : 4;
514
+ return /* @__PURE__ */ r(g, { position: "absolute", left: k, right: T, top: "1/2", translateY: -3, ai: "center", children: /* @__PURE__ */ u(f, { component: "datagrid.header.cell.contextMenu", onClick: () => i(!t), children: [
515
+ /* @__PURE__ */ r(L, { component: "datagrid.header.cell.contextMenu.icon", children: /* @__PURE__ */ r(Le, { fill: "currentColor" }) }),
516
+ t && /* @__PURE__ */ u(
517
+ te,
518
+ {
519
+ component: "datagrid.header.cell.contextMenu.tooltip",
520
+ variant: { openLeft: m },
521
+ onPositionChange: s,
522
+ ref: n,
523
+ children: [
524
+ l && /* @__PURE__ */ u(f, { component: "datagrid.header.cell.contextMenu.tooltip.item", onClick: () => e.sortColumn("ASC"), children: [
525
+ /* @__PURE__ */ r(L, { component: "datagrid.header.cell.contextMenu.tooltip.item.icon", children: /* @__PURE__ */ r(A, { width: "100%", fill: "currentColor" }) }),
526
+ "Sort Ascending"
527
+ ] }),
528
+ d && /* @__PURE__ */ u(f, { component: "datagrid.header.cell.contextMenu.tooltip.item", onClick: () => e.sortColumn("DESC"), children: [
529
+ /* @__PURE__ */ r(L, { component: "datagrid.header.cell.contextMenu.tooltip.item.icon", children: /* @__PURE__ */ r(A, { width: "100%", fill: "currentColor", rotate: 180 }) }),
530
+ "Sort Descending"
531
+ ] }),
532
+ c && /* @__PURE__ */ u(f, { component: "datagrid.header.cell.contextMenu.tooltip.item", onClick: () => e.sortColumn(void 0), children: [
533
+ /* @__PURE__ */ r(h, { width: 4 }),
534
+ "Clear Sort"
535
+ ] }),
536
+ R && (G || x || C) && /* @__PURE__ */ r(h, { bb: 1, my: 2, borderColor: "gray-300" }),
537
+ p && /* @__PURE__ */ u(f, { component: "datagrid.header.cell.contextMenu.tooltip.item", onClick: () => e.pinColumn("LEFT"), children: [
538
+ /* @__PURE__ */ r(L, { component: "datagrid.header.cell.contextMenu.tooltip.item.icon", children: /* @__PURE__ */ r(q, { width: "100%", fill: "currentColor" }) }),
539
+ "Pin Left"
540
+ ] }),
541
+ w && /* @__PURE__ */ u(f, { component: "datagrid.header.cell.contextMenu.tooltip.item", onClick: () => e.pinColumn("RIGHT"), children: [
542
+ /* @__PURE__ */ r(L, { component: "datagrid.header.cell.contextMenu.tooltip.item.icon", children: /* @__PURE__ */ r(q, { width: "100%", fill: "currentColor", rotate: -90 }) }),
543
+ "Pin Right"
544
+ ] }),
545
+ v && /* @__PURE__ */ u(f, { component: "datagrid.header.cell.contextMenu.tooltip.item", onClick: () => e.pinColumn(), children: [
546
+ /* @__PURE__ */ r(h, { width: 4 }),
547
+ "Unpin"
548
+ ] }),
549
+ R && G && (x || C) && /* @__PURE__ */ r(h, { bb: 1, my: 2, borderColor: "gray-300" }),
550
+ x && /* @__PURE__ */ u(f, { component: "datagrid.header.cell.contextMenu.tooltip.item", onClick: e.toggleGrouping, children: [
551
+ /* @__PURE__ */ r(L, { component: "datagrid.header.cell.contextMenu.tooltip.item.icon", children: /* @__PURE__ */ r($, { width: "100%", fill: "currentColor" }) }),
552
+ /* @__PURE__ */ u(h, { textWrap: "nowrap", children: [
553
+ "Group by ",
554
+ e.header ?? e.key
555
+ ] })
556
+ ] }),
557
+ C && /* @__PURE__ */ u(f, { component: "datagrid.header.cell.contextMenu.tooltip.item", onClick: e.grid.unGroupAll, children: [
558
+ /* @__PURE__ */ r(L, { component: "datagrid.header.cell.contextMenu.tooltip.item.icon", children: /* @__PURE__ */ r($, { width: "100%", fill: "currentColor" }) }),
559
+ /* @__PURE__ */ r(h, { textWrap: "nowrap", children: "Un-Group All" })
560
+ ] })
561
+ ]
562
+ }
563
+ )
564
+ ] }) });
565
+ }
566
+ ae.displayName = "DataGridHeaderCellContextMenu";
567
+ function de(a) {
568
+ const { column: e } = a;
415
569
  return /* @__PURE__ */ r(
416
- C,
570
+ g,
417
571
  {
418
572
  height: "fit",
419
573
  ai: "center",
@@ -422,363 +576,165 @@ function Ge(u) {
422
576
  left: e.pin !== "RIGHT" ? void 0 : 0,
423
577
  py: 3,
424
578
  children: /* @__PURE__ */ r(
425
- g,
579
+ h,
426
580
  {
427
581
  cursor: "col-resize",
428
582
  px: 0.75,
429
583
  className: "resizer",
430
584
  height: "fit",
431
585
  props: { onMouseDown: e.resizeColumn, onTouchStart: e.resizeColumn },
432
- children: /* @__PURE__ */ r(g, { width: 0.5, height: "fit", bgColor: "gray-400", hoverGroup: { resizer: { bgColor: "gray-600" } } })
586
+ children: /* @__PURE__ */ r(h, { component: "datagrid.header.cell.resizer" })
433
587
  }
434
588
  )
435
589
  }
436
590
  );
437
591
  }
438
- function Ee(u) {
439
- const { column: e } = u, [t, i, o] = Y({ hideOnScroll: !0, event: "mousedown" }), [s, n] = z({ top: 0, left: 0 }), h = E(() => s.left > window.innerWidth / 2, [s.left]), l = e.isLeaf && (e.grid.sortColumn !== e.key || e.grid.sortDirection === "DESC"), m = e.isLeaf && (e.grid.sortColumn !== e.key || e.grid.sortDirection === "ASC"), d = e.isLeaf && e.grid.sortColumn === e.key, w = e.pin !== "LEFT", y = e.pin !== "RIGHT", k = !!e.pin, x = e.isLeaf && e.key !== f, v = e.isLeaf && e.key === f, L = l || m || d, _ = w || y || k;
440
- return /* @__PURE__ */ r(C, { position: "absolute", right: e.pin === "RIGHT" ? 2.5 : 4, top: "1/2", translateY: -3, ai: "center", children: /* @__PURE__ */ c(
441
- p,
592
+ de.displayName = "DataGridHeaderCellResizer";
593
+ function ce(a) {
594
+ const { column: e } = a, { key: t, pin: i, left: n, right: o, isEdge: s, isLeaf: m, leafs: l, grid: d, header: c, gridRows: p, widthVarName: w, leftVarName: v, rightVarName: x, inlineWidth: C } = e, R = t === _, G = t === y, k = t === b, T = t === B, M = i === "LEFT", P = i === "RIGHT", F = M || i === "RIGHT", fe = M && n === 0, we = M && s, Ce = P && s, Re = P && o === 0, U = m && !R && !k && !T, ye = m ? 1 : l.length, ve = !k && !T, X = !k && !T, j = W(() => {
595
+ d.toggleSelectAllRows();
596
+ }, []), xe = H(() => {
597
+ if (k) return null;
598
+ if (T) {
599
+ const N = d.selectedRows.size === d.props.data.length, V = !N && d.selectedRows.size > 0;
600
+ return /* @__PURE__ */ r(I, { variant: "datagrid", m: 1, indeterminate: V, checked: N, onChange: j });
601
+ }
602
+ if (G) {
603
+ if (d.groupColumns.size === 1) {
604
+ const N = d.columns.value.leafs.findOrThrow((V) => V.key === d.groupColumns.values().next().value);
605
+ return N.header ?? N.key;
606
+ }
607
+ return "Group";
608
+ }
609
+ return c ?? t;
610
+ }, [d.groupColumns, d.selectedRows, j]);
611
+ return /* @__PURE__ */ r(
612
+ g,
442
613
  {
443
- clean: !0,
444
- onClick: () => i(!t),
445
- width: 6,
446
- height: 6,
447
- cursor: "pointer",
448
- userSelect: "none",
449
- borderRadius: 1,
450
- borderColor: "gray-200",
451
- display: "flex",
452
- jc: "center",
453
- ai: "center",
454
- transition: "none",
455
- bgColor: "gray-200",
456
- hover: { bgColor: "gray-300" },
457
- children: [
458
- /* @__PURE__ */ r(fe, { fill: "violet-950" }),
459
- t && /* @__PURE__ */ c(
460
- J,
614
+ component: "datagrid.header.cell",
615
+ variant: { isRowNumber: k, isPinned: F, isFirstLeftPinned: fe, isLastLeftPinned: we, isFirstRightPinned: Ce, isLastRightPinned: Re, isSortable: U },
616
+ gridRow: p,
617
+ gridColumn: ye,
618
+ style: {
619
+ width: `var(${w})`,
620
+ left: M ? `var(${v})` : void 0,
621
+ right: P ? `var(${x})` : void 0
622
+ },
623
+ children: !R && /* @__PURE__ */ u(Ge, { children: [
624
+ /* @__PURE__ */ r(g, { width: "fit", height: "fit", jc: e.align, props: { onClick: U ? () => e.sortColumn() : void 0 }, children: /* @__PURE__ */ u(
625
+ g,
461
626
  {
462
- bgColor: "white",
463
- width: 56,
464
- b: 1,
465
- borderColor: "gray-300",
466
- borderRadius: 1,
467
- display: "flex",
468
- d: "column",
469
- mt: 4,
470
- py: 2,
471
627
  overflow: "hidden",
472
- translateX: h ? -55 : -5,
473
- onPositionChange: n,
474
- ref: o,
475
- shadow: "medium-shadow",
628
+ position: m ? void 0 : "sticky",
629
+ ai: "center",
630
+ transition: "none",
631
+ pl: e.align === "right" ? 10 : 4,
632
+ style: {
633
+ left: i ? void 0 : `var(${d.leftEdgeVarName})`
634
+ },
476
635
  children: [
477
- l && /* @__PURE__ */ c(
478
- p,
479
- {
480
- clean: !0,
481
- display: "flex",
482
- gap: 2,
483
- p: 3,
484
- cursor: "pointer",
485
- hover: { bgColor: "gray-200" },
486
- onClick: () => e.sortColumn("ASC"),
487
- children: [
488
- /* @__PURE__ */ r($, { width: "1rem", fill: "violet-950" }),
489
- "Sort Ascending"
490
- ]
491
- }
492
- ),
493
- m && /* @__PURE__ */ c(
494
- p,
495
- {
496
- clean: !0,
497
- display: "flex",
498
- gap: 2,
499
- p: 3,
500
- cursor: "pointer",
501
- hover: { bgColor: "gray-200" },
502
- onClick: () => e.sortColumn("DESC"),
503
- children: [
504
- /* @__PURE__ */ r($, { width: "1rem", fill: "violet-950", rotate: 180 }),
505
- "Sort Descending"
506
- ]
507
- }
508
- ),
509
- d && /* @__PURE__ */ c(
510
- p,
511
- {
512
- clean: !0,
513
- display: "flex",
514
- gap: 2,
515
- p: 3,
516
- cursor: "pointer",
517
- hover: { bgColor: "gray-200" },
518
- onClick: () => e.sortColumn(void 0),
519
- children: [
520
- /* @__PURE__ */ r(g, { width: 4 }),
521
- "Clear Sort"
522
- ]
523
- }
524
- ),
525
- L && (_ || x || v) && /* @__PURE__ */ r(g, { bb: 1, my: 2, borderColor: "gray-300" }),
526
- w && /* @__PURE__ */ c(
527
- p,
528
- {
529
- clean: !0,
530
- display: "flex",
531
- gap: 2,
532
- p: 3,
533
- cursor: "pointer",
534
- hover: { bgColor: "gray-200" },
535
- onClick: () => e.pinColumn("LEFT"),
536
- children: [
537
- /* @__PURE__ */ r(K, { width: "1rem", fill: "violet-950" }),
538
- "Pin Left"
539
- ]
540
- }
541
- ),
542
- y && /* @__PURE__ */ c(
543
- p,
544
- {
545
- clean: !0,
546
- display: "flex",
547
- gap: 2,
548
- p: 3,
549
- cursor: "pointer",
550
- hover: { bgColor: "gray-200" },
551
- onClick: () => e.pinColumn("RIGHT"),
552
- children: [
553
- /* @__PURE__ */ r(K, { width: "1rem", fill: "violet-950", rotate: -90 }),
554
- "Pin Right"
555
- ]
556
- }
557
- ),
558
- k && /* @__PURE__ */ c(
559
- p,
560
- {
561
- clean: !0,
562
- display: "flex",
563
- gap: 2,
564
- p: 3,
565
- cursor: "pointer",
566
- hover: { bgColor: "gray-200" },
567
- onClick: () => e.pinColumn(),
568
- children: [
569
- /* @__PURE__ */ r(g, { width: 4 }),
570
- "Unpin"
571
- ]
572
- }
573
- ),
574
- L && _ && (x || v) && /* @__PURE__ */ r(g, { bb: 1, my: 2, borderColor: "gray-300" }),
575
- x && /* @__PURE__ */ c(
576
- p,
577
- {
578
- clean: !0,
579
- display: "flex",
580
- ai: "center",
581
- gap: 2,
582
- p: 3,
583
- cursor: "pointer",
584
- hover: { bgColor: "gray-200" },
585
- onClick: e.toggleGrouping,
586
- children: [
587
- /* @__PURE__ */ r(g, { children: /* @__PURE__ */ r(H, { width: "1rem", fill: "violet-950" }) }),
588
- /* @__PURE__ */ c(g, { textWrap: "nowrap", children: [
589
- " Group by ",
590
- e.header ?? e.key
591
- ] })
592
- ]
593
- }
594
- ),
595
- v && /* @__PURE__ */ c(p, { clean: !0, display: "flex", gap: 2, p: 3, cursor: "pointer", hover: { bgColor: "gray-200" }, onClick: e.grid.unGroupAll, children: [
596
- /* @__PURE__ */ r(g, { children: /* @__PURE__ */ r(H, { width: "1rem", fill: "violet-950" }) }),
597
- /* @__PURE__ */ r(g, { textWrap: "nowrap", children: " Un-Group All" })
598
- ] })
636
+ /* @__PURE__ */ r(h, { overflow: "hidden", textOverflow: "ellipsis", textWrap: "nowrap", children: xe }),
637
+ t === d.sortColumn && /* @__PURE__ */ r(h, { pl: (C ?? 0) < 58 ? 0 : 2, children: /* @__PURE__ */ r(A, { width: "16px", rotate: d.sortDirection === "ASC" ? 0 : 180, fill: "currentColor" }) }),
638
+ X && /* @__PURE__ */ r(h, { minWidth: e.align === "right" ? 4 : 10 })
599
639
  ]
600
640
  }
601
- )
602
- ]
603
- }
604
- ) });
605
- }
606
- function N(u) {
607
- const { children: e, column: t, style: i, ...o } = u, { key: s, pin: n, left: h, right: l, isEdge: m, align: d, widthVarName: w, leftVarName: y, rightVarName: k } = t, x = s === P, v = s === b, L = s === T, _ = n === "LEFT", R = n === "RIGHT", W = _ || R, I = _ && h === 0, B = _ && m, S = R && m, M = R && l === 0, O = !L && !x;
608
- return /* @__PURE__ */ c(
609
- C,
610
- {
611
- component: "datagrid.cell",
612
- props: { role: "cell" },
613
- variant: { isPinned: W, isFirstLeftPinned: I, isLastLeftPinned: B, isFirstRightPinned: S, isLastRightPinned: M, isRowNumber: v, isRowSelection: L },
614
- jc: d,
615
- style: {
616
- width: `var(${w})`,
617
- left: _ ? `var(${y})` : void 0,
618
- right: R ? `var(${k})` : void 0,
619
- ...i
620
- },
621
- ...o,
622
- children: [
623
- O && /* @__PURE__ */ r(g, { px: 4, textOverflow: "ellipsis", overflow: "hidden", textWrap: "nowrap", children: e }),
624
- L && e
625
- ]
641
+ ) }),
642
+ ve && /* @__PURE__ */ r(de, { column: e }),
643
+ X && /* @__PURE__ */ r(ae, { column: e })
644
+ ] })
626
645
  }
627
646
  );
628
647
  }
629
- function Pe(u) {
630
- const { row: e } = u;
631
- return /* @__PURE__ */ r(C, { className: "grid-row", display: "contents", props: { role: "rowgroup" }, children: e.cells.map((t) => {
632
- const { key: i, pin: o, groupColumnWidthVarName: s } = t.column, n = o === "RIGHT";
633
- if (i === f)
634
- return /* @__PURE__ */ r(
635
- N,
636
- {
637
- column: t.column,
638
- style: {
639
- width: `var(${s})`,
640
- right: n ? "0" : void 0
641
- },
642
- br: e.groupingColumn.pin === "LEFT" ? 1 : void 0,
643
- gridColumn: e.groupingColumnGridColumn,
644
- pl: 4 * e.depth,
645
- children: /* @__PURE__ */ r(p, { display: "contents", clean: !0, onClick: () => e.toggleRow(), cursor: "pointer", children: t.value })
646
- },
647
- i
648
- );
649
- if (i === T)
650
- return /* @__PURE__ */ r(N, { column: t.column, children: /* @__PURE__ */ r(V, { m: 1 }) }, i);
651
- if (o !== e.groupingColumn.pin || i === P || i === b)
652
- return /* @__PURE__ */ r(N, { column: t.column, children: t.value }, i);
653
- }) });
648
+ ce.displayName = "DataGridHeaderCell";
649
+ function ue(a) {
650
+ const { grid: e } = a, { isResizeMode: t } = e;
651
+ return /* @__PURE__ */ r(ee, { component: "datagrid.header", variant: { isResizeMode: t }, style: { gridTemplateColumns: e.gridTemplateColumns.value }, children: e.headerRows.value.map((i) => i.map((n) => /* @__PURE__ */ r(ce, { column: n }, n.uniqueKey))) });
654
652
  }
655
- function We(u) {
656
- const { row: e } = u;
657
- return /* @__PURE__ */ r(C, { className: "grid-row", display: "contents", props: { role: "row" }, children: e.cells.map((t) => /* @__PURE__ */ r(N, { column: t.column, children: t.column.key === T ? /* @__PURE__ */ r(V, {}) : t.value }, t.column.key)) });
653
+ ue.displayName = "DataGridHeader";
654
+ function he(a) {
655
+ const { grid: e } = a, [t, i] = O(0), n = W(
656
+ J.throttle((o) => {
657
+ i(o.target.scrollTop);
658
+ }, 100),
659
+ []
660
+ );
661
+ return /* @__PURE__ */ u(h, { overflowX: "scroll", props: { onScroll: n }, children: [
662
+ /* @__PURE__ */ r(ue, { grid: e }),
663
+ /* @__PURE__ */ r(le, { grid: e, scrollTop: t })
664
+ ] });
658
665
  }
659
- function Ie(u) {
660
- const { grid: e } = u, t = E(() => e.groupColumns.length === 0 ? null : e.groupColumns.map((i, o) => {
661
- const s = e.columns.value.leafs.findOrThrow((n) => n.key === i);
662
- return /* @__PURE__ */ c(de.Fragment, { children: [
663
- ">",
664
- /* @__PURE__ */ c(C, { component: "datagrid.columnGroups.item", children: [
665
- s.header ?? s.key,
666
- /* @__PURE__ */ r(p, { component: "datagrid.columnGroups.item.icon", onClick: () => e.toggleGrouping(s.key), children: /* @__PURE__ */ r(Ce, { fill: "currentColor", width: "100%" }) })
667
- ] })
668
- ] }, i);
669
- }), [e.groupColumns]);
670
- return /* @__PURE__ */ c(C, { component: "datagrid.columnGroups", position: "relative", children: [
671
- /* @__PURE__ */ r(De, { grid: e }),
672
- t && /* @__PURE__ */ r(H, { width: "1rem", fill: "violet-950" }),
673
- t,
674
- /* @__PURE__ */ c(C, { position: "absolute", justifySelf: "flex-end", right: 2, top: 2, className: "parent", children: [
675
- /* @__PURE__ */ r(C, { position: "absolute", width: 8, height: 8, right: 0, jc: "center", children: /* @__PURE__ */ r(we, { fill: "violet-950", width: "1rem" }) }),
676
- /* @__PURE__ */ r(Re, { placeholder: "Search...", height: 8, width: 50, zIndex: 1, bgColor: "transparent" })
677
- ] })
666
+ he.displayName = "DataGridContent";
667
+ function me(a) {
668
+ const { grid: e } = a;
669
+ return e.groupColumns.size === 0 ? null : /* @__PURE__ */ u(g, { component: "datagrid.topBar.columnGroups", children: [
670
+ /* @__PURE__ */ r(L, { component: "datagrid.topBar.columnGroups.icon", children: /* @__PURE__ */ r($, { width: "100%", fill: "currentColor" }) }),
671
+ Array.from(e.groupColumns, (t) => {
672
+ const i = e.columns.value.leafs.findOrThrow((n) => n.key === t);
673
+ return /* @__PURE__ */ u(be.Fragment, { children: [
674
+ /* @__PURE__ */ r(Q, { fill: "currentColor", width: "14px", height: "14px", rotate: -90 }),
675
+ /* @__PURE__ */ u(g, { component: "datagrid.topBar.columnGroups.item", children: [
676
+ i.header ?? i.key,
677
+ /* @__PURE__ */ r(f, { component: "datagrid.topBar.columnGroups.item.icon", onClick: () => e.toggleGrouping(i.key), children: /* @__PURE__ */ r(De, { fill: "currentColor", width: "100%" }) })
678
+ ] })
679
+ ] }, t);
680
+ })
678
681
  ] });
679
682
  }
680
- function De(u) {
681
- const { grid: e } = u, [t, i, o] = Y({ event: "mousedown" }), s = E(
683
+ me.displayName = "DataGridColumnGroups";
684
+ function pe(a) {
685
+ const { grid: e } = a, [t, i, n] = Z({ event: "mousedown" }), o = H(
682
686
  () => e.columns.value.leafs.filter(
683
- (n) => ![P, b, T, f].includes(n.key)
687
+ (s) => ![_, b, B, y].includes(s.key)
684
688
  ),
685
689
  [e.columns.value.leafs]
686
690
  );
687
- return /* @__PURE__ */ c(p, { clean: !0, cursor: "pointer", p: 1, hover: { bgColor: "gray-200", borderRadius: 1 }, onClick: () => i(!t), children: [
688
- /* @__PURE__ */ r(ve, { viewBox: "0 0 24 24", width: "20", fill: "currentColor", ...u, children: /* @__PURE__ */ r("path", { d: "M5 6h14M5 12h14M5 18h14", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round" }) }),
689
- t && /* @__PURE__ */ r(
690
- J,
691
+ return /* @__PURE__ */ u(f, { component: "datagrid.topBar.contextMenu", onClick: () => i(!t), children: [
692
+ /* @__PURE__ */ r(Te, { viewBox: "0 0 24 24", width: "20", fill: "currentColor", ...a, children: /* @__PURE__ */ r("path", { d: "M5 6h14M5 12h14M5 18h14", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round" }) }),
693
+ t && /* @__PURE__ */ r(te, { component: "datagrid.topBar.contextMenu.tooltip", ref: n, children: o.map((s) => /* @__PURE__ */ u(
694
+ f,
691
695
  {
692
- bgColor: "white",
693
- width: 56,
694
- b: 1,
695
- borderColor: "gray-300",
696
- borderRadius: 1,
697
- display: "flex",
698
- d: "column",
699
- mt: 4,
700
- py: 2,
701
- translateX: -1,
702
- shadow: "medium-shadow",
703
- ref: o,
704
- overflow: "auto",
705
- maxHeight: 100,
706
- children: s.map((n) => /* @__PURE__ */ c(
707
- p,
708
- {
709
- clean: !0,
710
- display: "flex",
711
- gap: 2,
712
- p: 3,
713
- cursor: "pointer",
714
- hover: { bgColor: "gray-200" },
715
- onClick: (h) => {
716
- h.stopPropagation(), n.toggleVisibility();
717
- },
718
- children: [
719
- /* @__PURE__ */ r(V, { checked: n.isVisible, onChange: () => {
720
- }, focus: { outline: 0 } }),
721
- n.header ?? n.key
722
- ]
723
- },
724
- n.key
725
- ))
726
- }
727
- )
696
+ component: "datagrid.topBar.contextMenu.tooltip.item",
697
+ onClick: (m) => {
698
+ m.stopPropagation(), s.toggleVisibility();
699
+ },
700
+ children: [
701
+ /* @__PURE__ */ r(I, { variant: "datagrid", checked: s.isVisible, onChange: () => {
702
+ }, focus: { outline: 0 } }),
703
+ s.header ?? s.key
704
+ ]
705
+ },
706
+ s.key
707
+ )) })
728
708
  ] });
729
709
  }
730
- function Be(u) {
731
- const e = _e(u), { isResizeMode: t } = e, i = E(() => (console.debug("\x1B[36m%s\x1B[0m", "[react-box]: DataGrid render headers"), e.headerRows.value.map((n) => n.map((h) => /* @__PURE__ */ r(Te, { column: h }, h.uniqueKey)))), [e.headerRows.value]), o = me(null), s = ge(
732
- q.throttle((n) => {
733
- var h;
734
- (h = o.current) == null || h.setScrollTop(n.target.scrollTop);
735
- }, 100),
736
- [o.current]
737
- );
738
- return console.debug("\x1B[36m%s\x1B[0m", "[react-box]: DataGrid render"), /* @__PURE__ */ c(g, { component: "datagrid", style: e.sizes.value, props: { role: "presentation" }, children: [
739
- /* @__PURE__ */ r(Ie, { grid: e }),
740
- /* @__PURE__ */ c(g, { overflowX: "scroll", props: { onScroll: s }, children: [
741
- /* @__PURE__ */ r(j, { component: "datagrid.header", variant: { isResizeMode: t }, style: { gridTemplateColumns: e.gridTemplateColumns.value }, children: i }),
742
- /* @__PURE__ */ r(te, { ref: o, grid: e })
743
- ] }),
744
- /* @__PURE__ */ c(g, { p: 3, bgColor: "gray-200", bt: 1, borderColor: "gray-400", children: [
745
- "Rows: ",
746
- u.data.length
747
- ] })
710
+ pe.displayName = "DataGridTopBarContextMenu";
711
+ function ge(a) {
712
+ const { grid: e } = a;
713
+ return /* @__PURE__ */ u(g, { component: "datagrid.topBar", position: "relative", children: [
714
+ /* @__PURE__ */ r(pe, { grid: e }),
715
+ /* @__PURE__ */ r(me, { grid: e })
748
716
  ] });
749
717
  }
750
- Be.displayName = "DataGrid";
751
- const Z = 10, ee = 25, Ne = Z + ee * 2;
752
- function Ve(u, e) {
753
- const { grid: t } = u, i = ye * t.ROW_HEIGHT, [o, s] = z(0), n = Math.max(0, Math.floor(o / i) - ee), h = E(() => (console.debug("\x1B[36m%s\x1B[0m", "[react-box]: DataGrid render rows"), t.flatRows.value.take(Ne, n).map((d) => d instanceof Q ? /* @__PURE__ */ r(Pe, { row: d }, d.rowKey) : /* @__PURE__ */ r(We, { row: d }, d.rowKey))), [t.flatRows.value, n]);
754
- pe(e, () => ({
755
- setScrollTop: s
756
- }));
757
- const l = t.flatRows.value.length;
758
- return /* @__PURE__ */ r(g, { height: t.ROW_HEIGHT * Z + 4, children: /* @__PURE__ */ r(
759
- g,
760
- {
761
- style: {
762
- height: `${l * i}px`
763
- },
764
- children: /* @__PURE__ */ r(
765
- j,
766
- {
767
- width: "max-content",
768
- minWidth: "fit",
769
- transition: "none",
770
- style: {
771
- transform: `translateY(${n * i}px)`,
772
- gridTemplateColumns: t.gridTemplateColumns.value
773
- },
774
- children: h
775
- }
776
- )
777
- }
778
- ) });
718
+ ge.displayName = "DataGridTopBar";
719
+ function Pe(a) {
720
+ const [e, t] = O(0), i = ke();
721
+ return i.current || (i.current = new Me(a, () => t((n) => n + 1))), z(() => {
722
+ i.current.props = a, i.current.rows.clear(), i.current.flatRows.clear(), i.current.update();
723
+ }, [a.data]), z(() => {
724
+ i.current.props = a, 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();
725
+ }, [a.def]), z(() => {
726
+ i.current.props = a, i.current.update();
727
+ }, [a.loading]), i.current;
728
+ }
729
+ function We(a) {
730
+ const e = Pe(a);
731
+ return console.debug("\x1B[36m%s\x1B[0m", "[react-box]: DataGrid render"), /* @__PURE__ */ u(h, { component: "datagrid", style: e.sizes.value, props: { role: "presentation" }, children: [
732
+ /* @__PURE__ */ r(ge, { grid: e }),
733
+ /* @__PURE__ */ r(he, { grid: e }),
734
+ /* @__PURE__ */ r(Se, { grid: e })
735
+ ] });
779
736
  }
780
- const te = ce(Ve);
781
- te.displayName = "Rows";
737
+ We.displayName = "DataGrid";
782
738
  export {
783
- Be as default
739
+ We as default
784
740
  };