@cronocode/react-box 3.1.1 → 3.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components/dataGrid/components/dataGridCell.d.ts +1 -1
- package/components/dataGrid/components/dataGridCellRowSelection.d.ts +6 -0
- package/components/dataGrid/components/dataGridCellText.d.ts +6 -0
- package/components/dataGrid/contracts/dataGridContract.d.ts +9 -1
- package/components/dataGrid/models/cellModel.d.ts +1 -1
- package/components/dataGrid/models/columnModel.d.ts +6 -3
- package/components/dataGrid/models/gridModel.d.ts +4 -3
- package/components/dataGrid/models/groupRowModel.d.ts +3 -1
- package/components/dataGrid/models/rowModel.d.ts +1 -1
- package/components/dataGrid.cjs +1 -1
- package/components/dataGrid.mjs +391 -348
- package/components/dropdown.cjs +1 -1
- package/components/dropdown.mjs +10 -10
- package/components/semantics.d.ts +25 -25
- package/core/boxStyles.d.ts +1 -0
- package/core/extends/boxComponents.d.ts +41 -32
- package/core/extends/useComponents.d.ts +1 -1
- package/core.cjs +4 -4
- package/core.mjs +162 -155
- package/package.json +3 -1
- package/types.d.ts +1 -1
package/components/dataGrid.mjs
CHANGED
|
@@ -1,30 +1,38 @@
|
|
|
1
|
-
import { jsxs as h, jsx as s, Fragment as
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import { F as
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import { Span as
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
function
|
|
13
|
-
const { grid: e } =
|
|
14
|
-
return /* @__PURE__ */ h(
|
|
15
|
-
/* @__PURE__ */ h(
|
|
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: [
|
|
16
16
|
"Rows: ",
|
|
17
17
|
e.props.data.length
|
|
18
18
|
] }),
|
|
19
|
-
e.props.def.rowSelection && /* @__PURE__ */ h(
|
|
19
|
+
e.props.def.rowSelection && /* @__PURE__ */ h(p, { children: [
|
|
20
20
|
"Selected: ",
|
|
21
21
|
e.selectedRows.size
|
|
22
22
|
] })
|
|
23
23
|
] });
|
|
24
24
|
}
|
|
25
|
-
|
|
25
|
+
function ue(l) {
|
|
26
|
+
const { cell: e } = l, t = X(() => {
|
|
27
|
+
e.grid.toggleRowSelection(e.row.key);
|
|
28
|
+
}, [e.grid, e.row.key]);
|
|
29
|
+
return /* @__PURE__ */ s(q, { variant: "datagrid", checked: e.row.selected, onChange: t });
|
|
30
|
+
}
|
|
31
|
+
ue.displayName = "DataGridCellRowSelection";
|
|
32
|
+
const Ee = "NO_PIN";
|
|
33
|
+
class S {
|
|
26
34
|
constructor(e, t, i) {
|
|
27
|
-
this.def = e, this.grid = t, this.parent = i, this.columns = e.columns?.map((
|
|
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);
|
|
28
36
|
}
|
|
29
37
|
columns = [];
|
|
30
38
|
get visibleColumns() {
|
|
@@ -42,6 +50,9 @@ class D {
|
|
|
42
50
|
get isLeaf() {
|
|
43
51
|
return this.columns.length === 0;
|
|
44
52
|
}
|
|
53
|
+
get Cell() {
|
|
54
|
+
return this.def.Cell;
|
|
55
|
+
}
|
|
45
56
|
_pin;
|
|
46
57
|
get pin() {
|
|
47
58
|
if (this.isLeaf) return this._pin;
|
|
@@ -54,10 +65,10 @@ class D {
|
|
|
54
65
|
getPinnedColumn(e) {
|
|
55
66
|
if (this.hasPin(e)) {
|
|
56
67
|
if (this.isLeaf) return this;
|
|
57
|
-
const t = new
|
|
68
|
+
const t = new S({ ...this.def, pin: e }, this.grid, this.parent);
|
|
58
69
|
return t.columns = this.columns.filter((i) => i.hasPin(e)).map((i) => {
|
|
59
|
-
const
|
|
60
|
-
return
|
|
70
|
+
const n = i.getPinnedColumn(e);
|
|
71
|
+
return n.parent = t, n;
|
|
61
72
|
}).filter((i) => !!i), t;
|
|
62
73
|
}
|
|
63
74
|
}
|
|
@@ -81,22 +92,22 @@ class D {
|
|
|
81
92
|
get left() {
|
|
82
93
|
let e = 0;
|
|
83
94
|
if (this.parent) {
|
|
84
|
-
const { visibleColumns: t, left: i } = this.parent,
|
|
85
|
-
e += t.sumBy((
|
|
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;
|
|
86
97
|
} else {
|
|
87
|
-
const t = this.grid.columns.value.left.filter((
|
|
88
|
-
e += t.sumBy((
|
|
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);
|
|
89
100
|
}
|
|
90
101
|
return e;
|
|
91
102
|
}
|
|
92
103
|
get right() {
|
|
93
104
|
let e = 0;
|
|
94
105
|
if (this.parent) {
|
|
95
|
-
const { visibleColumns: t } = this.parent, i = t.reverse(),
|
|
96
|
-
e += i.sumBy((
|
|
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;
|
|
97
108
|
} else {
|
|
98
|
-
const i = this.grid.columns.value.right.filter((
|
|
99
|
-
e += i.sumBy((
|
|
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);
|
|
100
111
|
}
|
|
101
112
|
return e;
|
|
102
113
|
}
|
|
@@ -132,16 +143,16 @@ class D {
|
|
|
132
143
|
}
|
|
133
144
|
resizeColumn = (e) => {
|
|
134
145
|
this.grid.isResizeMode = !0;
|
|
135
|
-
const t = e.pageX, { MIN_COLUMN_WIDTH_PX: i, update:
|
|
136
|
-
const
|
|
137
|
-
this.leafs.forEach((
|
|
138
|
-
const
|
|
139
|
-
|
|
140
|
-
}), this.grid.sizes.clear(),
|
|
141
|
-
}, 40),
|
|
142
|
-
|
|
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);
|
|
148
|
+
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();
|
|
143
154
|
};
|
|
144
|
-
window.addEventListener("mousemove",
|
|
155
|
+
window.addEventListener("mousemove", u, a), window.addEventListener("mouseup", c, a);
|
|
145
156
|
};
|
|
146
157
|
pinColumn = (e) => {
|
|
147
158
|
this.isLeaf ? this._pin = e : this.columns.forEach((t) => t.pinColumn(e)), this.grid.pinColumn(this.uniqueKey, e);
|
|
@@ -161,62 +172,15 @@ class D {
|
|
|
161
172
|
this.grid.toggleColumnVisibility(this.key);
|
|
162
173
|
};
|
|
163
174
|
}
|
|
164
|
-
class
|
|
175
|
+
class Me {
|
|
165
176
|
constructor(e, t, i) {
|
|
166
177
|
this.grid = e, this.row = t, this.column = i;
|
|
167
178
|
}
|
|
168
179
|
get value() {
|
|
169
|
-
return this.column.key ===
|
|
180
|
+
return this.column.key === C ? this.row.rowIndex + 1 : this.row.data[this.column.key];
|
|
170
181
|
}
|
|
171
182
|
}
|
|
172
183
|
class oe {
|
|
173
|
-
constructor(e, t, i, o, n) {
|
|
174
|
-
this.grid = e, this.groupColumn = t, this.rows = i, this.rowIndex = o, this.groupValue = n, i.forEach((r) => r.parentRow = this);
|
|
175
|
-
}
|
|
176
|
-
get key() {
|
|
177
|
-
return `${this.parentRow?.key ?? ""}${this.groupColumn.key}${this.groupValue}`;
|
|
178
|
-
}
|
|
179
|
-
parentRow;
|
|
180
|
-
get cells() {
|
|
181
|
-
return this.grid.columns.value.visibleLeafs.map((e) => new Le(this.grid, this, e));
|
|
182
|
-
}
|
|
183
|
-
get expanded() {
|
|
184
|
-
return this.grid.expandedGroupRow.has(this.key);
|
|
185
|
-
}
|
|
186
|
-
get depth() {
|
|
187
|
-
return this.parentRow ? this.parentRow.depth + 1 : 0;
|
|
188
|
-
}
|
|
189
|
-
get count() {
|
|
190
|
-
return this.rows.sumBy((e) => e.count, 0);
|
|
191
|
-
}
|
|
192
|
-
get flatRows() {
|
|
193
|
-
return this.expanded ? [this, ...this.rows.flatMap((e) => e.flatRows)] : [this];
|
|
194
|
-
}
|
|
195
|
-
get allRows() {
|
|
196
|
-
return this.rows.flatMap((e) => e.allRows);
|
|
197
|
-
}
|
|
198
|
-
get groupingColumn() {
|
|
199
|
-
return this.grid.columns.value.leafs.findOrThrow((e) => e.key === f);
|
|
200
|
-
}
|
|
201
|
-
get groupingColumnGridColumn() {
|
|
202
|
-
const { visibleLeafs: e } = this.grid.columns.value, { groupingColumn: t } = this;
|
|
203
|
-
return e.sumBy(
|
|
204
|
-
(o) => o.pin === t.pin && o.key !== T && o.key !== _ && o.key !== v ? 1 : 0
|
|
205
|
-
);
|
|
206
|
-
}
|
|
207
|
-
toggleRow() {
|
|
208
|
-
this.grid.toggleGroupRow(this.key);
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
class De {
|
|
212
|
-
constructor(e, t, i) {
|
|
213
|
-
this.grid = e, this.row = t, this.column = i;
|
|
214
|
-
}
|
|
215
|
-
get value() {
|
|
216
|
-
return this.column.key === T ? null : this.column.key === v ? this.row.rowIndex + 1 : this.row.data[this.column.key];
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
class K {
|
|
220
184
|
constructor(e, t, i) {
|
|
221
185
|
this.grid = e, this.data = t, this.rowIndex = i, this.grid = e, this.data = t, this.key = this.grid.getRowKey(t);
|
|
222
186
|
}
|
|
@@ -224,7 +188,7 @@ class K {
|
|
|
224
188
|
parentRow;
|
|
225
189
|
count = 1;
|
|
226
190
|
get cells() {
|
|
227
|
-
return this.grid.columns.value.visibleLeafs.map((e) => new
|
|
191
|
+
return this.grid.columns.value.visibleLeafs.map((e) => new Me(this.grid, this, e));
|
|
228
192
|
}
|
|
229
193
|
get selected() {
|
|
230
194
|
return this.grid.selectedRows.has(this.key);
|
|
@@ -236,83 +200,89 @@ class K {
|
|
|
236
200
|
return this;
|
|
237
201
|
}
|
|
238
202
|
}
|
|
239
|
-
const
|
|
240
|
-
class
|
|
203
|
+
const E = "empty-cell", C = "row-number-cell", se = 70, _ = "row-selection-cell", x = "grouping-cell";
|
|
204
|
+
class Ne {
|
|
241
205
|
constructor(e, t) {
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
206
|
+
this.props = e, this.update = t, console.debug("\x1B[32m%s\x1B[0m", "[react-box]: DataGrid GridModel ctor");
|
|
207
|
+
}
|
|
208
|
+
sourceColumns = P(() => {
|
|
209
|
+
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) {
|
|
211
|
+
const i = typeof e.rowSelection == "object" && e.rowSelection.pinned ? "LEFT" : void 0;
|
|
212
|
+
t.unshift(
|
|
213
|
+
new S({ key: _, pin: i, width: 50, align: "center", Cell: ue }, this)
|
|
214
|
+
);
|
|
245
215
|
}
|
|
246
|
-
if (e.
|
|
247
|
-
|
|
248
|
-
|
|
216
|
+
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));
|
|
249
219
|
}
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
columns =
|
|
220
|
+
return t;
|
|
221
|
+
});
|
|
222
|
+
columns = P(() => {
|
|
253
223
|
console.debug("\x1B[36m%s\x1B[0m", "[react-box]: DataGrid columns memo");
|
|
254
|
-
const e = this.
|
|
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;
|
|
255
225
|
return {
|
|
256
226
|
left: e,
|
|
257
227
|
middle: t,
|
|
258
228
|
right: i,
|
|
259
|
-
flat:
|
|
260
|
-
leafs:
|
|
229
|
+
flat: n,
|
|
230
|
+
leafs: o,
|
|
261
231
|
visibleLeafs: r,
|
|
262
|
-
maxDeath:
|
|
232
|
+
maxDeath: u
|
|
263
233
|
};
|
|
264
234
|
});
|
|
265
|
-
headerRows =
|
|
266
|
-
const i = t.values.groupBy((
|
|
235
|
+
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]);
|
|
267
237
|
return [
|
|
268
|
-
...i.LEFT?.filter((
|
|
269
|
-
...i.NO_PIN?.filter((
|
|
270
|
-
...i.RIGHT?.filter((
|
|
238
|
+
...i.LEFT?.filter((n) => n.isVisible) ?? [],
|
|
239
|
+
...i.NO_PIN?.filter((n) => n.isVisible) ?? [],
|
|
240
|
+
...i.RIGHT?.filter((n) => n.isVisible) ?? []
|
|
271
241
|
];
|
|
272
242
|
})));
|
|
273
|
-
gridTemplateColumns =
|
|
243
|
+
gridTemplateColumns = P(() => {
|
|
274
244
|
console.debug("\x1B[36m%s\x1B[0m", "[react-box]: DataGrid gridTemplateColumns memo");
|
|
275
|
-
const { visibleLeafs: e } = this.columns.value, t = e.sumBy((r) => r.pin === "RIGHT" ? 1 : 0), i = e.length - t - 1,
|
|
276
|
-
return `${
|
|
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}`;
|
|
277
247
|
});
|
|
278
|
-
rows =
|
|
248
|
+
rows = P(() => {
|
|
279
249
|
console.debug("\x1B[36m%s\x1B[0m", "[react-box]: DataGrid rows memo");
|
|
280
250
|
let e = this.props.data;
|
|
281
251
|
if (this._sortColumn && (e = e.sortBy((t) => t[this._sortColumn], this._sortDirection)), this.groupColumns.size > 0) {
|
|
282
|
-
const t = (i,
|
|
283
|
-
const r =
|
|
284
|
-
|
|
285
|
-
const
|
|
286
|
-
return this._sortColumn ===
|
|
287
|
-
let
|
|
288
|
-
|
|
289
|
-
const
|
|
290
|
-
return
|
|
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;
|
|
291
261
|
});
|
|
292
262
|
};
|
|
293
263
|
return t(e, new Set(this.groupColumns), 0);
|
|
294
264
|
}
|
|
295
|
-
return e.map((t, i) => new
|
|
265
|
+
return e.map((t, i) => new oe(this, t, i));
|
|
296
266
|
});
|
|
297
|
-
flatRows =
|
|
267
|
+
flatRows = P(() => (console.debug("\x1B[36m%s\x1B[0m", "[react-box]: DataGrid flatRows memo"), this.rows.value.flatMap((e) => e.flatRows)));
|
|
298
268
|
get rowHeight() {
|
|
299
269
|
return this.props.def.rowHeight ?? this.DEFAULT_ROW_HEIGHT_PX;
|
|
300
270
|
}
|
|
301
|
-
sizes =
|
|
271
|
+
sizes = P(() => {
|
|
302
272
|
console.debug("\x1B[36m%s\x1B[0m", "[react-box]: DataGrid sizes memo");
|
|
303
|
-
const e = this.columns.value.flat.reduce((
|
|
304
|
-
const { inlineWidth: r } =
|
|
305
|
-
return typeof r == "number" && (o
|
|
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;
|
|
306
276
|
}, {});
|
|
307
277
|
e[this.rowHeightVarName] = `${this.rowHeight}px`, e[this.leftEdgeVarName] = `${this.leftEdge}px`;
|
|
308
|
-
const { visibleLeafs: t } = this.columns.value, i = t.find((
|
|
278
|
+
const { visibleLeafs: t } = this.columns.value, i = t.find((n) => n.key === x);
|
|
309
279
|
if (i) {
|
|
310
|
-
const
|
|
311
|
-
e[i.groupColumnWidthVarName] = `${
|
|
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`;
|
|
312
282
|
}
|
|
313
|
-
return this.groupColumns.forEach((
|
|
314
|
-
const
|
|
315
|
-
e[
|
|
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`;
|
|
316
286
|
}), e;
|
|
317
287
|
});
|
|
318
288
|
DEFAULT_ROW_HEIGHT_PX = 48;
|
|
@@ -338,26 +308,20 @@ class Be {
|
|
|
338
308
|
if (t.length > 0)
|
|
339
309
|
[this._sortDirection] = t, this._sortColumn = this._sortDirection ? e : void 0;
|
|
340
310
|
else {
|
|
341
|
-
const { _sortColumn: i, _sortDirection:
|
|
342
|
-
this._sortColumn = i === e &&
|
|
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";
|
|
343
313
|
}
|
|
344
314
|
this.headerRows.clear(), this.rows.clear(), this.flatRows.clear(), this.update();
|
|
345
315
|
};
|
|
346
316
|
pinColumn = (e, t) => {
|
|
347
|
-
const i = this.columns.value.flat.findOrThrow((
|
|
317
|
+
const i = this.columns.value.flat.findOrThrow((n) => n.uniqueKey === e);
|
|
348
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();
|
|
349
319
|
};
|
|
350
320
|
toggleGrouping = (e) => {
|
|
351
|
-
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));
|
|
352
|
-
const t = this._sourceColumns.find((i) => i.key === f);
|
|
353
|
-
if (this.groupColumns.size > 0 && !t) {
|
|
354
|
-
const i = this._sourceColumns.sumBy((o) => o.key === v || o.key === _ ? 1 : 0);
|
|
355
|
-
this._sourceColumns.splice(i, 0, new D({ key: f }, this));
|
|
356
|
-
} else this.groupColumns.size === 0 && t && (this._sourceColumns = this._sourceColumns.removeBy((i) => i.key === f));
|
|
357
|
-
this.columns.clear(), this.headerRows.clear(), this.gridTemplateColumns.clear(), this.rows.clear(), this.flatRows.clear(), this.sizes.clear(), this.update();
|
|
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();
|
|
358
322
|
};
|
|
359
323
|
unGroupAll = () => {
|
|
360
|
-
this.groupColumns = /* @__PURE__ */ new Set(), this.
|
|
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();
|
|
361
325
|
};
|
|
362
326
|
toggleGroupRow = (e) => {
|
|
363
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();
|
|
@@ -382,10 +346,10 @@ class Be {
|
|
|
382
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();
|
|
383
347
|
};
|
|
384
348
|
setWidth = (e, t) => {
|
|
385
|
-
const i = this.columns.value.leafs.find((
|
|
349
|
+
const i = this.columns.value.leafs.find((o) => o.key === e);
|
|
386
350
|
if (!i)
|
|
387
351
|
throw new Error("Leaf column not found.");
|
|
388
|
-
i.setWidth(t), this.
|
|
352
|
+
i.setWidth(t), this.sourceColumns.value.flatMap((o) => o.flatColumns).findOrThrow((o) => o.key === e).setWidth(t);
|
|
389
353
|
};
|
|
390
354
|
groupColumns = /* @__PURE__ */ new Set();
|
|
391
355
|
hiddenColumns = /* @__PURE__ */ new Set();
|
|
@@ -398,161 +362,232 @@ class Be {
|
|
|
398
362
|
return this._sortDirection;
|
|
399
363
|
}
|
|
400
364
|
}
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
365
|
+
class We {
|
|
366
|
+
constructor(e, t, i) {
|
|
367
|
+
this.grid = e, this.row = t, this.column = i;
|
|
368
|
+
}
|
|
369
|
+
get value() {
|
|
370
|
+
return this.column.key === C ? this.row.rowIndex + 1 : this.column.key === x ? `${this.row.groupValue} (${this.row.count})` : null;
|
|
371
|
+
}
|
|
372
|
+
}
|
|
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);
|
|
376
|
+
}
|
|
377
|
+
get key() {
|
|
378
|
+
return `${this.parentRow?.key ?? ""}${this.groupColumn.key}${this.groupValue}`;
|
|
379
|
+
}
|
|
380
|
+
parentRow;
|
|
381
|
+
get cells() {
|
|
382
|
+
return this.grid.columns.value.visibleLeafs.map((e) => new We(this.grid, this, e));
|
|
383
|
+
}
|
|
384
|
+
get selected() {
|
|
385
|
+
return this.allRows.every((e) => e.selected);
|
|
386
|
+
}
|
|
387
|
+
get indeterminate() {
|
|
388
|
+
return !this.selected && this.allRows.some((e) => e.selected);
|
|
389
|
+
}
|
|
390
|
+
get expanded() {
|
|
391
|
+
return this.grid.expandedGroupRow.has(this.key);
|
|
392
|
+
}
|
|
393
|
+
get depth() {
|
|
394
|
+
return this.parentRow ? this.parentRow.depth + 1 : 0;
|
|
395
|
+
}
|
|
396
|
+
get count() {
|
|
397
|
+
return this.rows.sumBy((e) => e.count, 0);
|
|
398
|
+
}
|
|
399
|
+
get flatRows() {
|
|
400
|
+
return this.expanded ? [this, ...this.rows.flatMap((e) => e.flatRows)] : [this];
|
|
401
|
+
}
|
|
402
|
+
get allRows() {
|
|
403
|
+
return this.rows.flatMap((e) => e.allRows);
|
|
404
|
+
}
|
|
405
|
+
get groupingColumn() {
|
|
406
|
+
return this.grid.columns.value.leafs.findOrThrow((e) => e.key === x);
|
|
407
|
+
}
|
|
408
|
+
get groupingColumnGridColumn() {
|
|
409
|
+
const { visibleLeafs: e } = this.grid.columns.value, { groupingColumn: t } = this;
|
|
410
|
+
return e.sumBy(
|
|
411
|
+
(n) => n.pin === t.pin && n.key !== E && n.key !== _ && n.key !== C ? 1 : 0
|
|
412
|
+
);
|
|
413
|
+
}
|
|
414
|
+
toggleRow() {
|
|
415
|
+
this.grid.toggleGroupRow(this.key);
|
|
416
|
+
}
|
|
417
|
+
}
|
|
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,
|
|
405
424
|
{
|
|
406
|
-
component: "datagrid.cell",
|
|
425
|
+
component: "datagrid.body.cell",
|
|
407
426
|
props: { role: "cell" },
|
|
408
|
-
variant: {
|
|
409
|
-
|
|
427
|
+
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
|
|
435
|
+
},
|
|
410
436
|
style: {
|
|
411
|
-
width: `var(${
|
|
437
|
+
width: `var(${m})`,
|
|
412
438
|
height: `var(${t.grid.rowHeightVarName})`,
|
|
413
|
-
left:
|
|
414
|
-
right:
|
|
439
|
+
left: G ? `var(${f})` : void 0,
|
|
440
|
+
right: b ? `var(${R})` : void 0,
|
|
415
441
|
...i
|
|
416
442
|
},
|
|
417
|
-
...
|
|
418
|
-
children:
|
|
419
|
-
A && /* @__PURE__ */ s(m, { px: 4, textOverflow: "ellipsis", overflow: "hidden", textWrap: "nowrap", children: e }),
|
|
420
|
-
G && e
|
|
421
|
-
]
|
|
443
|
+
...n,
|
|
444
|
+
children: e
|
|
422
445
|
}
|
|
423
446
|
);
|
|
424
447
|
}
|
|
425
|
-
|
|
426
|
-
function
|
|
427
|
-
const { row: e } =
|
|
428
|
-
e.grid.toggleRowsSelection(e.allRows.map((
|
|
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));
|
|
429
452
|
}, []);
|
|
430
|
-
return /* @__PURE__ */ s(
|
|
431
|
-
const { key:
|
|
432
|
-
if (
|
|
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)
|
|
433
456
|
return /* @__PURE__ */ s(
|
|
434
|
-
|
|
457
|
+
A,
|
|
435
458
|
{
|
|
436
|
-
column:
|
|
459
|
+
column: d.column,
|
|
437
460
|
style: {
|
|
438
|
-
width: `var(${
|
|
439
|
-
right:
|
|
461
|
+
width: `var(${R})`,
|
|
462
|
+
right: y ? "0" : void 0
|
|
440
463
|
},
|
|
441
|
-
br:
|
|
442
|
-
gridColumn:
|
|
443
|
-
pl: 4 *
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
464
|
+
br: o.pin === "LEFT" ? 1 : void 0,
|
|
465
|
+
gridColumn: r,
|
|
466
|
+
pl: 4 * u,
|
|
467
|
+
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
|
|
471
|
+
] }) })
|
|
448
472
|
},
|
|
449
|
-
|
|
473
|
+
m
|
|
450
474
|
);
|
|
451
|
-
if (
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
if (n !== e.groupingColumn.pin || o === T || o === v)
|
|
456
|
-
return /* @__PURE__ */ s(W, { column: i.column, children: i.value }, o);
|
|
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);
|
|
457
479
|
}) });
|
|
458
480
|
}
|
|
459
|
-
|
|
460
|
-
function
|
|
461
|
-
const {
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
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 }) });
|
|
485
|
+
}
|
|
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)) });
|
|
465
490
|
}
|
|
466
|
-
|
|
467
|
-
const
|
|
468
|
-
function
|
|
469
|
-
const { grid: e, scrollTop: t } =
|
|
470
|
-
console.debug("\x1B[36m%s\x1B[0m", "[react-box]: DataGrid render rows")
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
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(() => {
|
|
495
|
+
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,
|
|
476
502
|
{
|
|
477
503
|
style: {
|
|
478
504
|
height: `${i * e.rowHeight}px`
|
|
479
505
|
},
|
|
480
506
|
children: /* @__PURE__ */ s(
|
|
481
|
-
|
|
507
|
+
ce,
|
|
482
508
|
{
|
|
509
|
+
component: "datagrid.body",
|
|
483
510
|
width: "max-content",
|
|
484
511
|
minWidth: "fit",
|
|
485
512
|
transition: "none",
|
|
486
513
|
style: {
|
|
487
|
-
transform: `translateY(${
|
|
514
|
+
transform: `translateY(${n * e.rowHeight}px)`,
|
|
488
515
|
gridTemplateColumns: e.gridTemplateColumns.value
|
|
489
516
|
},
|
|
490
|
-
children:
|
|
517
|
+
children: u
|
|
491
518
|
}
|
|
492
519
|
)
|
|
493
520
|
}
|
|
494
521
|
) });
|
|
495
522
|
}
|
|
496
|
-
|
|
497
|
-
function
|
|
498
|
-
const { column: e } =
|
|
499
|
-
return /* @__PURE__ */ s(
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
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,
|
|
528
|
+
{
|
|
529
|
+
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 },
|
|
532
|
+
children: [
|
|
533
|
+
/* @__PURE__ */ s(D, { component: "datagrid.header.cell.contextMenu.icon", children: /* @__PURE__ */ s(Se, { fill: "currentColor" }) }),
|
|
534
|
+
m && /* @__PURE__ */ h(
|
|
535
|
+
he,
|
|
536
|
+
{
|
|
537
|
+
component: "datagrid.header.cell.contextMenu.tooltip",
|
|
538
|
+
variant: { openLeft: G },
|
|
539
|
+
onPositionChange: k,
|
|
540
|
+
ref: R,
|
|
541
|
+
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" }) }),
|
|
544
|
+
"Sort Ascending"
|
|
545
|
+
] }),
|
|
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 }) }),
|
|
548
|
+
"Sort Descending"
|
|
549
|
+
] }),
|
|
550
|
+
v && /* @__PURE__ */ h(w, { component: "datagrid.header.cell.contextMenu.tooltip.item", onClick: () => e.sortColumn(void 0), children: [
|
|
551
|
+
/* @__PURE__ */ s(p, { width: 4 }),
|
|
552
|
+
"Clear Sort"
|
|
553
|
+
] }),
|
|
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" }) }),
|
|
557
|
+
"Pin Left"
|
|
558
|
+
] }),
|
|
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 }) }),
|
|
561
|
+
"Pin Right"
|
|
562
|
+
] }),
|
|
563
|
+
N && /* @__PURE__ */ h(w, { component: "datagrid.header.cell.contextMenu.tooltip.item", onClick: () => e.pinColumn(), children: [
|
|
564
|
+
/* @__PURE__ */ s(p, { width: 4 }),
|
|
565
|
+
"Unpin"
|
|
566
|
+
] }),
|
|
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: [
|
|
571
|
+
"Group by ",
|
|
572
|
+
c ?? t
|
|
573
|
+
] })
|
|
574
|
+
] }),
|
|
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" })
|
|
578
|
+
] })
|
|
579
|
+
]
|
|
580
|
+
}
|
|
581
|
+
)
|
|
582
|
+
]
|
|
583
|
+
}
|
|
584
|
+
) });
|
|
550
585
|
}
|
|
551
|
-
|
|
552
|
-
function
|
|
553
|
-
const { column: e } =
|
|
586
|
+
Ce.displayName = "DataGridHeaderCellContextMenu";
|
|
587
|
+
function Re(l) {
|
|
588
|
+
const { column: e } = l;
|
|
554
589
|
return /* @__PURE__ */ s(
|
|
555
|
-
|
|
590
|
+
g,
|
|
556
591
|
{
|
|
557
592
|
height: "fit",
|
|
558
593
|
ai: "center",
|
|
@@ -561,129 +596,131 @@ function ae(a) {
|
|
|
561
596
|
left: e.pin !== "RIGHT" ? void 0 : 0,
|
|
562
597
|
py: 3,
|
|
563
598
|
children: /* @__PURE__ */ s(
|
|
564
|
-
|
|
599
|
+
p,
|
|
565
600
|
{
|
|
566
601
|
cursor: "col-resize",
|
|
567
602
|
px: 0.75,
|
|
568
603
|
className: "resizer",
|
|
569
604
|
height: "fit",
|
|
570
605
|
props: { onMouseDown: e.resizeColumn, onTouchStart: e.resizeColumn },
|
|
571
|
-
children: /* @__PURE__ */ s(
|
|
606
|
+
children: /* @__PURE__ */ s(p, { component: "datagrid.header.cell.resizer" })
|
|
572
607
|
}
|
|
573
608
|
)
|
|
574
609
|
}
|
|
575
610
|
);
|
|
576
611
|
}
|
|
577
|
-
|
|
578
|
-
function
|
|
579
|
-
const { column: e } =
|
|
580
|
-
|
|
581
|
-
}, []),
|
|
582
|
-
if (
|
|
583
|
-
if (
|
|
584
|
-
const
|
|
585
|
-
return /* @__PURE__ */ s(
|
|
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 });
|
|
586
621
|
}
|
|
587
622
|
if (b) {
|
|
588
|
-
if (
|
|
589
|
-
const
|
|
590
|
-
return
|
|
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;
|
|
591
626
|
}
|
|
592
627
|
return "Group";
|
|
593
628
|
}
|
|
594
|
-
return
|
|
595
|
-
}, [
|
|
629
|
+
return d ?? t;
|
|
630
|
+
}, [c.groupColumns, c.selectedRows, z]);
|
|
596
631
|
return /* @__PURE__ */ s(
|
|
597
|
-
|
|
632
|
+
g,
|
|
598
633
|
{
|
|
634
|
+
props: { role: "columnheader" },
|
|
599
635
|
component: "datagrid.header.cell",
|
|
600
|
-
variant: {
|
|
601
|
-
gridRow:
|
|
602
|
-
gridColumn:
|
|
636
|
+
variant: { isPinned: N, isFirstLeftPinned: W, isLastLeftPinned: H, isFirstRightPinned: F, isLastRightPinned: O, isSortable: $, isRowNumber: L },
|
|
637
|
+
gridRow: m,
|
|
638
|
+
gridColumn: Y,
|
|
603
639
|
style: {
|
|
604
|
-
width: `var(${
|
|
605
|
-
left:
|
|
606
|
-
right:
|
|
640
|
+
width: `var(${f})`,
|
|
641
|
+
left: T ? `var(${R})` : void 0,
|
|
642
|
+
right: B ? `var(${y})` : void 0
|
|
607
643
|
},
|
|
608
|
-
children: !G && /* @__PURE__ */ h(
|
|
609
|
-
/* @__PURE__ */ s(
|
|
610
|
-
|
|
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,
|
|
611
647
|
{
|
|
612
648
|
overflow: "hidden",
|
|
613
|
-
position:
|
|
649
|
+
position: u ? void 0 : "sticky",
|
|
614
650
|
ai: "center",
|
|
615
651
|
transition: "none",
|
|
616
|
-
pl:
|
|
652
|
+
pl: J,
|
|
653
|
+
pr: V,
|
|
617
654
|
style: {
|
|
618
|
-
left: i ? void 0 : `var(${
|
|
655
|
+
left: i ? void 0 : `var(${c.leftEdgeVarName})`
|
|
619
656
|
},
|
|
620
657
|
children: [
|
|
621
|
-
/* @__PURE__ */ s(
|
|
622
|
-
t ===
|
|
623
|
-
|
|
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 })
|
|
624
661
|
]
|
|
625
662
|
}
|
|
626
663
|
) }),
|
|
627
|
-
|
|
628
|
-
|
|
664
|
+
K && /* @__PURE__ */ s(Re, { column: e }),
|
|
665
|
+
I && /* @__PURE__ */ s(Ce, { column: e })
|
|
629
666
|
] })
|
|
630
667
|
}
|
|
631
668
|
);
|
|
632
669
|
}
|
|
633
|
-
|
|
634
|
-
function
|
|
635
|
-
const { grid: e } =
|
|
636
|
-
return /* @__PURE__ */ s(
|
|
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))) });
|
|
637
674
|
}
|
|
638
|
-
|
|
639
|
-
function
|
|
640
|
-
const { grid: e } =
|
|
641
|
-
|
|
642
|
-
i(
|
|
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);
|
|
643
680
|
}, 100),
|
|
644
681
|
[]
|
|
645
682
|
);
|
|
646
|
-
return /* @__PURE__ */ h(
|
|
647
|
-
/* @__PURE__ */ s(
|
|
648
|
-
/* @__PURE__ */ s(
|
|
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 })
|
|
649
686
|
] });
|
|
650
687
|
}
|
|
651
|
-
|
|
652
|
-
function
|
|
653
|
-
const { grid: e } =
|
|
654
|
-
return e.groupColumns.size === 0 ? null : /* @__PURE__ */ h(
|
|
655
|
-
/* @__PURE__ */ s(
|
|
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" }) }),
|
|
656
693
|
Array.from(e.groupColumns, (t) => {
|
|
657
|
-
const i = e.columns.value.leafs.findOrThrow((
|
|
658
|
-
return /* @__PURE__ */ h(
|
|
659
|
-
/* @__PURE__ */ s(
|
|
660
|
-
/* @__PURE__ */ h(
|
|
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: [
|
|
661
698
|
i.header ?? i.key,
|
|
662
|
-
/* @__PURE__ */ s(
|
|
699
|
+
/* @__PURE__ */ s(w, { component: "datagrid.topBar.columnGroups.item.icon", onClick: () => e.toggleGrouping(i.key), children: /* @__PURE__ */ s(_e, { fill: "currentColor", width: "100%" }) })
|
|
663
700
|
] })
|
|
664
701
|
] }, t);
|
|
665
702
|
})
|
|
666
703
|
] });
|
|
667
704
|
}
|
|
668
|
-
|
|
669
|
-
function
|
|
670
|
-
const { grid: e } =
|
|
705
|
+
Ge.displayName = "DataGridColumnGroups";
|
|
706
|
+
function be(l) {
|
|
707
|
+
const { grid: e } = l, [t, i, n] = de({ event: "mousedown" }), o = j(
|
|
671
708
|
() => e.columns.value.leafs.filter(
|
|
672
|
-
(r) => ![
|
|
709
|
+
(r) => ![E, C, _, x].includes(r.key)
|
|
673
710
|
),
|
|
674
711
|
[e.columns.value.leafs]
|
|
675
712
|
);
|
|
676
|
-
return /* @__PURE__ */ h(
|
|
677
|
-
/* @__PURE__ */ s(
|
|
678
|
-
t && /* @__PURE__ */ s(
|
|
679
|
-
|
|
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,
|
|
680
717
|
{
|
|
681
718
|
component: "datagrid.topBar.contextMenu.tooltip.item",
|
|
682
|
-
onClick: (
|
|
683
|
-
|
|
719
|
+
onClick: (u) => {
|
|
720
|
+
u.stopPropagation(), r.toggleVisibility();
|
|
684
721
|
},
|
|
685
722
|
children: [
|
|
686
|
-
/* @__PURE__ */ s(
|
|
723
|
+
/* @__PURE__ */ s(q, { variant: "datagrid", checked: r.isVisible, onChange: () => {
|
|
687
724
|
}, focus: { outline: 0 } }),
|
|
688
725
|
r.header ?? r.key
|
|
689
726
|
]
|
|
@@ -692,28 +729,34 @@ function me(a) {
|
|
|
692
729
|
)) })
|
|
693
730
|
] });
|
|
694
731
|
}
|
|
695
|
-
|
|
696
|
-
function
|
|
697
|
-
const { grid: e } =
|
|
698
|
-
return /* @__PURE__ */ h(
|
|
699
|
-
/* @__PURE__ */ s(
|
|
700
|
-
/* @__PURE__ */ s(
|
|
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 })
|
|
701
738
|
] });
|
|
702
739
|
}
|
|
703
|
-
|
|
704
|
-
function
|
|
705
|
-
const [e, t] =
|
|
706
|
-
return i.current || (i.current = new
|
|
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;
|
|
707
750
|
}
|
|
708
|
-
function
|
|
709
|
-
const e =
|
|
710
|
-
return console.debug("\x1B[36m%s\x1B[0m", "[react-box]: DataGrid render"), /* @__PURE__ */ h(
|
|
711
|
-
/* @__PURE__ */ s(
|
|
712
|
-
/* @__PURE__ */ s(
|
|
713
|
-
/* @__PURE__ */ s(
|
|
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 })
|
|
714
757
|
] });
|
|
715
758
|
}
|
|
716
|
-
|
|
759
|
+
Ve.displayName = "DataGrid";
|
|
717
760
|
export {
|
|
718
|
-
|
|
761
|
+
Ve as default
|
|
719
762
|
};
|