@cronocode/react-box 3.0.12 → 3.0.14
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/README.md +8 -7
- package/array.d.ts +13 -0
- package/box.cjs +1 -1
- package/box.d.ts +8 -9
- package/box.mjs +16 -16
- package/components/button.d.ts +7 -6
- package/components/checkbox.d.ts +5 -3
- package/components/checkbox.mjs +4 -4
- package/components/dataGrid/contracts/dataGridContract.d.ts +36 -0
- package/components/dataGrid/dataGridCell.d.ts +8 -0
- package/components/dataGrid/dataGridGroupRow.d.ts +6 -0
- package/components/dataGrid/dataGridHeaderCell.d.ts +6 -0
- package/components/dataGrid/dataGridPagination.d.ts +6 -0
- package/components/dataGrid/dataGridRow.d.ts +6 -0
- package/components/dataGrid/models/cellModel.d.ts +10 -0
- package/components/dataGrid/models/columnModel.d.ts +36 -0
- package/components/dataGrid/models/gridModel.d.ts +44 -0
- package/components/dataGrid/models/groupRowCellModel.d.ts +10 -0
- package/components/dataGrid/models/groupRowModel.d.ts +23 -0
- package/components/dataGrid/models/rowModel.d.ts +16 -0
- package/components/dataGrid/useGrid.d.ts +3 -0
- package/components/dataGrid.cjs +1 -1
- package/components/dataGrid.d.ts +2 -7
- package/components/dataGrid.mjs +656 -18
- package/components/dropdown.cjs +1 -1
- package/components/dropdown.d.ts +2 -2
- package/components/dropdown.mjs +63 -62
- package/components/flex.d.ts +2 -1
- package/components/form.cjs +1 -1
- package/components/form.mjs +11 -8
- package/components/grid.d.ts +2 -1
- package/components/radioButton.cjs +1 -1
- package/components/radioButton.d.ts +7 -6
- package/components/radioButton.mjs +9 -9
- package/components/semantics.cjs +1 -1
- package/components/semantics.d.ts +27 -25
- package/components/semantics.mjs +26 -25
- package/components/textarea.d.ts +7 -6
- package/components/textbox.d.ts +7 -6
- package/components/tooltip.cjs +1 -1
- package/components/tooltip.d.ts +1 -1
- package/components/tooltip.mjs +20 -22
- package/core/boxConstants.d.ts +1 -0
- package/core/boxStyles.d.ts +112 -37
- package/core/boxStylesFormatters.d.ts +1 -1
- package/core/classNames.d.ts +1 -1
- package/core/extends/boxComponents.d.ts +391 -0
- package/core/{boxExtends.d.ts → extends/boxExtends.d.ts} +4 -1
- package/core/extends/useComponents.d.ts +2 -0
- package/core/theme/theme.d.ts +1 -3
- package/core/theme/themeContext.d.ts +2 -4
- package/core/useStyles.d.ts +2 -2
- package/core/variables.d.ts +1 -0
- package/core.cjs +4 -4
- package/core.mjs +634 -511
- package/hooks/useVisibility.d.ts +9 -1
- package/icons/arrowIcon.d.ts +2 -0
- package/icons/dotsIcon.d.ts +2 -0
- package/icons/groupingIcon.d.ts +2 -0
- package/icons/pinIcon.d.ts +2 -0
- package/package.json +1 -1
- package/types.d.ts +35 -6
- package/utils/fn/fnUtils.d.ts +4 -0
- package/utils/memo.d.ts +5 -0
- package/utils/object/objectUtils.d.ts +1 -1
- package/components/dataGrid/dataGridContract.d.ts +0 -24
- package/components/dataGrid/useGridData.d.ts +0 -7
- package/components/label.cjs +0 -1
- package/components/label.d.ts +0 -5
- package/components/label.mjs +0 -10
- package/core/theme/defaultTheme.d.ts +0 -3
- package/core/theme/themeContract.d.ts +0 -25
- package/core/theme/useTheme.d.ts +0 -2
package/components/dataGrid.mjs
CHANGED
|
@@ -1,21 +1,659 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import s from "
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
1
|
+
var ot = Object.defineProperty;
|
|
2
|
+
var st = (u, t, e) => t in u ? ot(u, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : u[t] = e;
|
|
3
|
+
var l = (u, t, e) => st(u, typeof t != "symbol" ? t + "" : t, e);
|
|
4
|
+
import { jsx as s, jsxs as g, Fragment as rt } from "react/jsx-runtime";
|
|
5
|
+
import p from "../box.mjs";
|
|
6
|
+
import X from "./grid.mjs";
|
|
7
|
+
import { useMemo as N, useState as H, forwardRef as lt, useRef as ut, useCallback as at, useImperativeHandle as ht } from "react";
|
|
8
|
+
import { F as j, m as I, A as B, b as ct, D as dt, P as K, G as pt, d as gt } from "../core.mjs";
|
|
9
|
+
import _ from "./button.mjs";
|
|
10
|
+
import b from "./flex.mjs";
|
|
11
|
+
import mt from "./tooltip.mjs";
|
|
12
|
+
import V from "./checkbox.mjs";
|
|
13
|
+
const ft = "NO_PIN";
|
|
14
|
+
class T {
|
|
15
|
+
constructor(t, e, i) {
|
|
16
|
+
l(this, "columns", []);
|
|
17
|
+
l(this, "_pin");
|
|
18
|
+
l(this, "_inlineWidth");
|
|
19
|
+
l(this, "resizeColumn", (t) => {
|
|
20
|
+
this.grid.isResizeMode = !0;
|
|
21
|
+
const e = t.pageX, { MIN_COLUMN_WIDTH_PX: i, update: n } = this.grid, o = this.leafs.sumBy((h) => h.inlineWidth) - this.leafs.length * i, r = this.leafs.toRecord((h) => [h.key, h.inlineWidth]), d = j.throttle((h) => {
|
|
22
|
+
const m = (h.pageX - e) * (this.pin === "RIGHT" ? -1 : 1);
|
|
23
|
+
this.leafs.forEach((f) => {
|
|
24
|
+
const y = r[f.key], v = o > 0 ? (y - i) / o * m : m / this.leafs.length, R = Math.round(y + v);
|
|
25
|
+
f.setWidth(R < i ? i : R);
|
|
26
|
+
}), this.grid.headerRows.clear(), this.grid.sizes.clear(), n();
|
|
27
|
+
}, 20), a = new AbortController(), c = (h) => {
|
|
28
|
+
a.abort(), this.grid.isResizeMode = !1, n();
|
|
29
|
+
};
|
|
30
|
+
window.addEventListener("mousemove", d, a), window.addEventListener("mouseup", c, a);
|
|
31
|
+
});
|
|
32
|
+
l(this, "pinColumn", (t) => {
|
|
33
|
+
this.isLeaf ? this._pin = t : this.columns.forEach((e) => e.pinColumn(t)), this.grid.pinColumn(this.uniqueKey, t);
|
|
34
|
+
});
|
|
35
|
+
l(this, "toggleGrouping", () => {
|
|
36
|
+
this.grid.toggleGrouping(this.key);
|
|
37
|
+
});
|
|
38
|
+
l(this, "sortColumn", (...t) => {
|
|
39
|
+
this.grid.setSortColumn(this.key, ...t);
|
|
40
|
+
});
|
|
41
|
+
l(this, "setWidth", (t) => {
|
|
42
|
+
if (!this.isLeaf)
|
|
43
|
+
throw new Error("Cannot set width for a parent column.");
|
|
44
|
+
this._inlineWidth !== t && (this._inlineWidth = t, this.grid.setWidth(this.key, t));
|
|
45
|
+
});
|
|
46
|
+
var n;
|
|
47
|
+
this.def = t, this.grid = e, this.parent = i, this.columns = ((n = t.columns) == null ? void 0 : n.map((o) => new T(t.pin ? { ...o, pin: t.pin } : o, e, this))) ?? [], this.isLeaf && (this._inlineWidth = this.key == E ? void 0 : this.def.width ?? this.grid.DEFAULT_COLUMN_WIDTH_PX, this._pin = t.pin);
|
|
48
|
+
}
|
|
49
|
+
get key() {
|
|
50
|
+
return this.def.key;
|
|
51
|
+
}
|
|
52
|
+
get header() {
|
|
53
|
+
return this.def.header;
|
|
54
|
+
}
|
|
55
|
+
get align() {
|
|
56
|
+
return this.def.align;
|
|
57
|
+
}
|
|
58
|
+
get isLeaf() {
|
|
59
|
+
return this.columns.length === 0;
|
|
60
|
+
}
|
|
61
|
+
get pin() {
|
|
62
|
+
if (this.isLeaf) return this._pin;
|
|
63
|
+
const t = [...new Set(this.columns.flatMap((e) => e.pin))];
|
|
64
|
+
if (t.length === 1) return t[0];
|
|
65
|
+
}
|
|
66
|
+
get uniqueKey() {
|
|
67
|
+
return `${this.key}${this.pin ?? ""}`;
|
|
68
|
+
}
|
|
69
|
+
getPinnedColumn(t) {
|
|
70
|
+
if (this.hasPin(t)) {
|
|
71
|
+
if (this.isLeaf) return this;
|
|
72
|
+
const e = new T({ ...this.def, pin: t }, this.grid, this.parent);
|
|
73
|
+
return e.columns = this.columns.filter((i) => i.hasPin(t)).map((i) => {
|
|
74
|
+
const n = i.getPinnedColumn(t);
|
|
75
|
+
return n.parent = e, n;
|
|
76
|
+
}).filter((i) => !!i), e;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
hasPin(t) {
|
|
80
|
+
return this.isLeaf ? this._pin === t : this.columns.some((e) => e.hasPin(t));
|
|
81
|
+
}
|
|
82
|
+
get death() {
|
|
83
|
+
return this.parent ? this.parent.death + 1 : 0;
|
|
84
|
+
}
|
|
85
|
+
get flatColumns() {
|
|
86
|
+
const t = [this];
|
|
87
|
+
return t.push(...this.columns.flatMap((e) => e.flatColumns)), t;
|
|
88
|
+
}
|
|
89
|
+
get inlineWidth() {
|
|
90
|
+
if (this.isLeaf) return this._inlineWidth;
|
|
91
|
+
const t = this.columns.map((e) => e.inlineWidth).filter((e) => typeof e == "number");
|
|
92
|
+
if (t.length !== 0)
|
|
93
|
+
return t.sumBy((e) => e);
|
|
94
|
+
}
|
|
95
|
+
get left() {
|
|
96
|
+
let t = 0;
|
|
97
|
+
if (this.parent) {
|
|
98
|
+
const e = this.parent.columns.findIndex((i) => i === this);
|
|
99
|
+
t += this.parent.columns.sumBy((i, n) => n < e ? i.inlineWidth ?? 0 : 0), t += this.parent.left;
|
|
100
|
+
} else {
|
|
101
|
+
const e = this.grid.columns.value.left.findIndex((i) => i === this);
|
|
102
|
+
t += this.grid.columns.value.left.sumBy((i, n) => n < e ? i.inlineWidth ?? 0 : 0);
|
|
103
|
+
}
|
|
104
|
+
return t;
|
|
105
|
+
}
|
|
106
|
+
get right() {
|
|
107
|
+
let t = 0;
|
|
108
|
+
if (this.parent) {
|
|
109
|
+
const e = [...this.parent.columns].reverse(), i = e.findIndex((n) => n === this);
|
|
110
|
+
t += e.sumBy((n, o) => o < i ? n.inlineWidth ?? 0 : 0), t += this.parent.right;
|
|
111
|
+
} else {
|
|
112
|
+
const e = [...this.grid.columns.value.right].reverse(), i = e.findIndex((n) => n === this);
|
|
113
|
+
t += e.sumBy((n, o) => o < i ? n.inlineWidth ?? 0 : 0);
|
|
114
|
+
}
|
|
115
|
+
return t;
|
|
116
|
+
}
|
|
117
|
+
get isEdge() {
|
|
118
|
+
return this.pin ? this.parent ? (this.pin === "LEFT" ? this.parent.columns.at(-1) : this.parent.columns.at(0)) === this && this.parent.isEdge : (this.pin === "LEFT" ? this.grid.columns.value.left.at(-1) : this.grid.columns.value.right.at(0)) === this : !1;
|
|
119
|
+
}
|
|
120
|
+
// Approved
|
|
121
|
+
get leafs() {
|
|
122
|
+
return this.isLeaf ? [this] : this.columns.flatMap((t) => t.leafs);
|
|
123
|
+
}
|
|
124
|
+
get groupColumnWidthVarName() {
|
|
125
|
+
return `--${this.uniqueKey}-group-width`;
|
|
126
|
+
}
|
|
127
|
+
get widthVarName() {
|
|
128
|
+
return `--${this.uniqueKey}-width`;
|
|
129
|
+
}
|
|
130
|
+
get leftVarName() {
|
|
131
|
+
return `--${this.uniqueKey}-left`;
|
|
132
|
+
}
|
|
133
|
+
get rightVarName() {
|
|
134
|
+
return `--${this.uniqueKey}-right`;
|
|
135
|
+
}
|
|
136
|
+
get gridRows() {
|
|
137
|
+
return this.isLeaf ? this.grid.headerRows.value.length - this.death : 1;
|
|
138
|
+
}
|
|
18
139
|
}
|
|
140
|
+
class wt {
|
|
141
|
+
constructor(t, e, i) {
|
|
142
|
+
this.grid = t, this.row = e, this.column = i;
|
|
143
|
+
}
|
|
144
|
+
get value() {
|
|
145
|
+
return this.column.key === L ? this.row.rowIndex + 1 : this.column.key === C ? `> ${this.row.groupValue} (${this.row.count})` : null;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
class q {
|
|
149
|
+
constructor(t, e, i, n, o) {
|
|
150
|
+
l(this, "parentRow");
|
|
151
|
+
this.grid = t, this.groupColumn = e, this.rows = i, this.rowIndex = n, this.groupValue = o, i.forEach((r) => r.parentRow = this);
|
|
152
|
+
}
|
|
153
|
+
get rowKey() {
|
|
154
|
+
var t;
|
|
155
|
+
return `${((t = this.parentRow) == null ? void 0 : t.rowKey) ?? ""}${this.groupColumn.key}${this.groupValue}`;
|
|
156
|
+
}
|
|
157
|
+
get cells() {
|
|
158
|
+
return this.grid.columns.value.leafs.map((t) => new wt(this.grid, this, t));
|
|
159
|
+
}
|
|
160
|
+
get expanded() {
|
|
161
|
+
return this.grid.expandedGroupRow[this.rowKey];
|
|
162
|
+
}
|
|
163
|
+
get depth() {
|
|
164
|
+
return this.parentRow ? this.parentRow.depth + 1 : 0;
|
|
165
|
+
}
|
|
166
|
+
get count() {
|
|
167
|
+
return this.rows.sumBy((t) => t.count, 0);
|
|
168
|
+
}
|
|
169
|
+
get flatRows() {
|
|
170
|
+
return this.expanded ? [this, ...this.rows.flatMap((t) => t.flatRows)] : [this];
|
|
171
|
+
}
|
|
172
|
+
get groupingColumn() {
|
|
173
|
+
return this.grid.columns.value.leafs.findOrThrow((t) => t.key === C);
|
|
174
|
+
}
|
|
175
|
+
get groupingColumnGridColumn() {
|
|
176
|
+
const { leafs: t } = this.grid.columns.value, { groupingColumn: e } = this;
|
|
177
|
+
return t.sumBy(
|
|
178
|
+
(n) => n.pin === e.pin && n.key !== E && n.key !== x && n.key !== L ? 1 : 0
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
toggleRow() {
|
|
182
|
+
this.grid.toggleGroupRow(this.rowKey);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
class Ct {
|
|
186
|
+
constructor(t, e, i) {
|
|
187
|
+
this.grid = t, this.row = e, this.column = i;
|
|
188
|
+
}
|
|
189
|
+
get value() {
|
|
190
|
+
return this.column.key === E ? null : this.column.key === L ? this.row.rowIndex + 1 : this.row.row[this.column.key];
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
class U {
|
|
194
|
+
constructor(t, e, i) {
|
|
195
|
+
l(this, "parentRow");
|
|
196
|
+
this.grid = t, this.row = e, this.rowIndex = i, this.grid = t, this.row = e;
|
|
197
|
+
}
|
|
198
|
+
get rowKey() {
|
|
199
|
+
return this.getRowKey();
|
|
200
|
+
}
|
|
201
|
+
get cells() {
|
|
202
|
+
return this.grid.columns.value.leafs.map((t) => new Ct(this.grid, this, t));
|
|
203
|
+
}
|
|
204
|
+
get count() {
|
|
205
|
+
return 1;
|
|
206
|
+
}
|
|
207
|
+
get flatRows() {
|
|
208
|
+
return [this];
|
|
209
|
+
}
|
|
210
|
+
getRowKey() {
|
|
211
|
+
var i;
|
|
212
|
+
const { rowKey: t } = this.grid.props.def, e = t ? typeof t == "function" ? t(this.row) : this.row[t] : this.rowIndex;
|
|
213
|
+
return `${((i = this.parentRow) == null ? void 0 : i.rowKey) ?? ""}${e}`;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
const E = "empty-cell", L = "row-number-cell", x = "row-selection-cell", C = "grouping-cell";
|
|
217
|
+
class yt {
|
|
218
|
+
constructor(t, e) {
|
|
219
|
+
l(this, "_sourceColumns", []);
|
|
220
|
+
l(this, "columns", I(() => {
|
|
221
|
+
const t = this._sourceColumns.map((r) => r.getPinnedColumn("LEFT")).filter((r) => !!r), e = this._sourceColumns.map((r) => r.getPinnedColumn()).filter((r) => !!r), i = this._sourceColumns.map((r) => r.getPinnedColumn("RIGHT")).filter((r) => !!r), n = [...t, ...e, ...i].flatMap((r) => r.flatColumns), o = n.filter((r) => r.isLeaf);
|
|
222
|
+
return {
|
|
223
|
+
left: t,
|
|
224
|
+
middle: e,
|
|
225
|
+
right: i,
|
|
226
|
+
flat: n,
|
|
227
|
+
leafs: o
|
|
228
|
+
};
|
|
229
|
+
}));
|
|
230
|
+
l(this, "headerRows", I(() => this.columns.value.flat.groupBy((e) => e.death).sortBy((e) => e.key).map((e) => {
|
|
231
|
+
const i = e.values.groupBy((n) => n.pin ?? ft).toRecord((n) => [n.key, n.values]);
|
|
232
|
+
return [...i.LEFT ?? [], ...i.NO_PIN ?? [], ...i.RIGHT ?? []];
|
|
233
|
+
})));
|
|
234
|
+
l(this, "gridTemplateColumns", I(() => {
|
|
235
|
+
const t = this.columns.value.leafs.sumBy((o) => o.pin === "RIGHT" ? 1 : 0), e = this.columns.value.leafs.length - t - 1, i = e > 0 ? `repeat(${e}, max-content)` : "", n = t > 0 ? `repeat(${t}, max-content)` : "";
|
|
236
|
+
return `${i} auto ${n}`;
|
|
237
|
+
}));
|
|
238
|
+
l(this, "rows", I(() => {
|
|
239
|
+
let t = this.props.data;
|
|
240
|
+
if (this._sortColumn && (t = t.sortBy((e) => e[this._sortColumn], this._sortDirection)), this.groupColumns.length > 0) {
|
|
241
|
+
const e = (i, n, o) => {
|
|
242
|
+
const r = n[0];
|
|
243
|
+
n = n.removeBy((a) => a === r);
|
|
244
|
+
const d = this.columns.value.leafs.findOrThrow((a) => a.key === r);
|
|
245
|
+
return this._sortColumn === C && (i = i.sortBy((a) => a[r], this._sortDirection)), i.groupBy((a) => a[r]).map((a) => {
|
|
246
|
+
let c;
|
|
247
|
+
n.length > 0 ? c = e(a.values, n, o + 1) : c = a.values.map((m, f) => new U(this, m, o + 1 + f));
|
|
248
|
+
const h = new q(this, d, c, o, a.key);
|
|
249
|
+
return o += 1, h.expanded && (o += c.length), h;
|
|
250
|
+
});
|
|
251
|
+
};
|
|
252
|
+
return e(t, this.groupColumns, 0);
|
|
253
|
+
}
|
|
254
|
+
return t.map((e, i) => new U(this, e, i));
|
|
255
|
+
}));
|
|
256
|
+
l(this, "flatRows", I(() => this.rows.value.flatMap((t) => t.flatRows)));
|
|
257
|
+
l(this, "sizes", I(() => {
|
|
258
|
+
console.log("sizes");
|
|
259
|
+
const t = this.columns.value.flat.reduce((i, n) => {
|
|
260
|
+
const { inlineWidth: o } = n;
|
|
261
|
+
return typeof o == "number" && (i[n.widthVarName] = `${n.inlineWidth}px`), n.pin === "LEFT" && (i[n.leftVarName] = `${n.left}px`), n.pin === "RIGHT" && (i[n.rightVarName] = `${n.right}px`), i;
|
|
262
|
+
}, {});
|
|
263
|
+
t[this.leftEdgeVarName] = `${this.leftEdge}px`;
|
|
264
|
+
const e = this.columns.value.leafs.find((i) => i.key === C);
|
|
265
|
+
return e && (t[e.groupColumnWidthVarName] = `${this.columns.value.leafs.sumBy((i) => i.pin === e.pin && i.key !== L && i.key !== x ? i.inlineWidth ?? 0 : 0)}px`), this.groupColumns.forEach((i) => {
|
|
266
|
+
const n = this.columns.value.leafs.findOrThrow((o) => o.key === i);
|
|
267
|
+
t[n.groupColumnWidthVarName] = `${this.columns.value.leafs.sumBy((o) => o.pin === n.pin ? o.inlineWidth ?? 0 : 0)}px`;
|
|
268
|
+
}), t;
|
|
269
|
+
}));
|
|
270
|
+
l(this, "ROW_HEIGHT", 12);
|
|
271
|
+
l(this, "MIN_COLUMN_WIDTH_PX", 48);
|
|
272
|
+
l(this, "DEFAULT_COLUMN_WIDTH_PX", 200);
|
|
273
|
+
l(this, "isResizeMode", !1);
|
|
274
|
+
l(this, "expandedGroupRow", {});
|
|
275
|
+
l(this, "leftEdgeVarName", "--left-edge");
|
|
276
|
+
l(this, "setSortColumn", (t, ...e) => {
|
|
277
|
+
if (e.length > 0)
|
|
278
|
+
[this._sortDirection] = e, this._sortColumn = this._sortDirection ? t : void 0;
|
|
279
|
+
else {
|
|
280
|
+
const { _sortColumn: i, _sortDirection: n } = this;
|
|
281
|
+
this._sortColumn = i === t && n === "DESC" ? void 0 : t, this._sortDirection = i === t && n === "ASC" ? "DESC" : "ASC";
|
|
282
|
+
}
|
|
283
|
+
this.headerRows.clear(), this.rows.clear(), this.flatRows.clear(), this.update();
|
|
284
|
+
});
|
|
285
|
+
l(this, "pinColumn", (t, e) => {
|
|
286
|
+
const i = this.columns.value.flat.findOrThrow((n) => n.uniqueKey === t);
|
|
287
|
+
i.pin !== e && i.pinColumn(e), this.columns.clear(), this.headerRows.clear(), this.gridTemplateColumns.clear(), this.rows.clear(), this.flatRows.clear(), this.sizes.clear(), this.update();
|
|
288
|
+
});
|
|
289
|
+
l(this, "toggleGrouping", (t) => {
|
|
290
|
+
this.groupColumns.includes(t) ? this.groupColumns = this.groupColumns.removeBy((i) => i === t) : this.groupColumns = this.groupColumns.add(t);
|
|
291
|
+
const e = this._sourceColumns.find((i) => i.key === C);
|
|
292
|
+
if (this.groupColumns.length > 0 && !e) {
|
|
293
|
+
const i = this._sourceColumns.sumBy((n) => n.key === L || n.key === x ? 1 : 0);
|
|
294
|
+
this._sourceColumns.splice(i, 0, new T({ key: C }, this));
|
|
295
|
+
} else this.groupColumns.length === 0 && e && (this._sourceColumns = this._sourceColumns.removeBy((i) => i.key === C));
|
|
296
|
+
this.columns.clear(), this.headerRows.clear(), this.gridTemplateColumns.clear(), this.rows.clear(), this.flatRows.clear(), this.sizes.clear(), this.update();
|
|
297
|
+
});
|
|
298
|
+
l(this, "toggleGroupRow", (t) => {
|
|
299
|
+
t in this.expandedGroupRow ? delete this.expandedGroupRow[t] : this.expandedGroupRow[t] = !0, this.rows.clear(), this.flatRows.clear(), this.update();
|
|
300
|
+
});
|
|
301
|
+
l(this, "setWidth", (t, e) => {
|
|
302
|
+
const i = this.columns.value.leafs.find((o) => o.key === t);
|
|
303
|
+
if (!i)
|
|
304
|
+
throw new Error("Leaf column not found.");
|
|
305
|
+
i.setWidth(e), this._sourceColumns.flatMap((o) => o.flatColumns).findOrThrow((o) => o.key === t).setWidth(e);
|
|
306
|
+
});
|
|
307
|
+
l(this, "groupColumns", []);
|
|
308
|
+
l(this, "_sortColumn");
|
|
309
|
+
l(this, "_sortDirection", "ASC");
|
|
310
|
+
this.props = t, this.update = e, this._sourceColumns = t.def.columns.map((i) => new T(i, this)), this._sourceColumns.push(new T({ key: E }, this)), this._sourceColumns.unshift(new T({ key: x, width: 50, align: "center" }, this)), this._sourceColumns.unshift(new T({ key: L, pin: "LEFT", width: 70, align: "right" }, this));
|
|
311
|
+
}
|
|
312
|
+
get leftEdge() {
|
|
313
|
+
return this.columns.value.left.sumBy((t) => t.inlineWidth ?? 0);
|
|
314
|
+
}
|
|
315
|
+
get rightEdge() {
|
|
316
|
+
return this.columns.value.right.sumBy((t) => t.inlineWidth ?? 0);
|
|
317
|
+
}
|
|
318
|
+
get sortColumn() {
|
|
319
|
+
return this._sortColumn;
|
|
320
|
+
}
|
|
321
|
+
get sortDirection() {
|
|
322
|
+
return this._sortDirection;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
function vt(u) {
|
|
326
|
+
const t = N(() => new yt(u, () => i((o) => o + 1)), [u]), [e, i] = H(0);
|
|
327
|
+
return N(() => Object.create(Object.getPrototypeOf(t), Object.getOwnPropertyDescriptors(t)), [t, e]);
|
|
328
|
+
}
|
|
329
|
+
function Rt(u) {
|
|
330
|
+
const { column: t } = u, { key: e, pin: i, left: n, right: o, isEdge: r, isLeaf: d, leafs: a, grid: c, header: h, gridRows: m, widthVarName: f, leftVarName: y, rightVarName: v, inlineWidth: R } = t, k = e === E, G = e === C, w = e === L, P = e === x, W = i === "LEFT", D = i === "RIGHT", M = W || i === "RIGHT", S = W && n === 0, O = W && r, Q = D && r, Z = D && o === 0, z = d && !k && !w && !P, tt = d ? 1 : a.length, et = !w && !P, A = !w && !P, it = N(() => {
|
|
331
|
+
if (w) return null;
|
|
332
|
+
if (P) return /* @__PURE__ */ s(V, { m: 1 });
|
|
333
|
+
if (G) {
|
|
334
|
+
if (c.groupColumns.length === 1) {
|
|
335
|
+
const F = c.columns.value.leafs.findOrThrow((nt) => nt.key === c.groupColumns[0]);
|
|
336
|
+
return F.header ?? F.key;
|
|
337
|
+
}
|
|
338
|
+
return "Group";
|
|
339
|
+
}
|
|
340
|
+
return h ?? e;
|
|
341
|
+
}, [c.groupColumns]);
|
|
342
|
+
return /* @__PURE__ */ s(
|
|
343
|
+
b,
|
|
344
|
+
{
|
|
345
|
+
component: "datagrid.header.cell",
|
|
346
|
+
variant: { isRowNumber: w, isPinned: M, isFirstLeftPinned: S, isLastLeftPinned: O, isFirstRightPinned: Q, isLastRightPinned: Z, isSortable: z },
|
|
347
|
+
gridRow: m,
|
|
348
|
+
gridColumn: tt,
|
|
349
|
+
style: {
|
|
350
|
+
width: `var(${f})`,
|
|
351
|
+
left: W ? `var(${y})` : void 0,
|
|
352
|
+
right: D ? `var(${v})` : void 0
|
|
353
|
+
},
|
|
354
|
+
children: !k && /* @__PURE__ */ g(rt, { children: [
|
|
355
|
+
/* @__PURE__ */ s(b, { width: "fit", height: "fit", jc: t.align, props: { onClick: z ? () => t.sortColumn() : void 0 }, children: /* @__PURE__ */ g(
|
|
356
|
+
b,
|
|
357
|
+
{
|
|
358
|
+
overflow: "hidden",
|
|
359
|
+
position: d ? void 0 : "sticky",
|
|
360
|
+
ai: "center",
|
|
361
|
+
transition: "none",
|
|
362
|
+
pl: t.align ? void 0 : 4,
|
|
363
|
+
style: {
|
|
364
|
+
left: i ? void 0 : `var(${c.leftEdgeVarName})`
|
|
365
|
+
},
|
|
366
|
+
children: [
|
|
367
|
+
/* @__PURE__ */ s(p, { overflow: "hidden", textOverflow: "ellipsis", textWrap: "nowrap", children: it }),
|
|
368
|
+
e === c.sortColumn && /* @__PURE__ */ s(p, { pl: (R ?? 0) < 58 ? 0 : 2, children: /* @__PURE__ */ s(B, { width: "16px", rotate: c.sortDirection === "ASC" ? 0 : 180, fill: "violet-950" }) }),
|
|
369
|
+
A && /* @__PURE__ */ s(p, { minWidth: 12 })
|
|
370
|
+
]
|
|
371
|
+
}
|
|
372
|
+
) }),
|
|
373
|
+
et && /* @__PURE__ */ s(kt, { column: t }),
|
|
374
|
+
A && /* @__PURE__ */ s(_t, { column: t })
|
|
375
|
+
] })
|
|
376
|
+
}
|
|
377
|
+
);
|
|
378
|
+
}
|
|
379
|
+
function kt(u) {
|
|
380
|
+
const { column: t } = u;
|
|
381
|
+
return /* @__PURE__ */ s(
|
|
382
|
+
b,
|
|
383
|
+
{
|
|
384
|
+
height: "fit",
|
|
385
|
+
ai: "center",
|
|
386
|
+
position: "absolute",
|
|
387
|
+
right: t.pin === "RIGHT" ? void 0 : 0,
|
|
388
|
+
left: t.pin !== "RIGHT" ? void 0 : 0,
|
|
389
|
+
py: 3,
|
|
390
|
+
children: /* @__PURE__ */ s(
|
|
391
|
+
p,
|
|
392
|
+
{
|
|
393
|
+
cursor: "col-resize",
|
|
394
|
+
px: 0.75,
|
|
395
|
+
className: "resizer",
|
|
396
|
+
height: "fit",
|
|
397
|
+
props: { onMouseDown: t.resizeColumn, onTouchStart: t.resizeColumn },
|
|
398
|
+
children: /* @__PURE__ */ s(p, { width: 0.5, height: "fit", bgColor: "gray-400", hoverGroup: { resizer: { bgColor: "gray-600" } } })
|
|
399
|
+
}
|
|
400
|
+
)
|
|
401
|
+
}
|
|
402
|
+
);
|
|
403
|
+
}
|
|
404
|
+
function _t(u) {
|
|
405
|
+
const { column: t } = u, [e, i, n] = ct({ hideOnScroll: !0, event: "mousedown" }), [o, r] = H({ top: 0, left: 0 }), d = N(() => o.left > window.innerWidth / 2, [o.left]), a = t.isLeaf && (t.grid.sortColumn !== t.key || t.grid.sortDirection === "DESC"), c = t.isLeaf && (t.grid.sortColumn !== t.key || t.grid.sortDirection === "ASC"), h = t.isLeaf && t.grid.sortColumn === t.key, m = t.pin !== "LEFT", f = t.pin !== "RIGHT", y = !!t.pin, v = t.isLeaf && t.key !== C, R = a || c || h, k = m || f || y;
|
|
406
|
+
return /* @__PURE__ */ s(b, { position: "absolute", right: t.pin === "RIGHT" ? 2.5 : 4, top: "1/2", translateY: -3, ai: "center", children: /* @__PURE__ */ g(
|
|
407
|
+
_,
|
|
408
|
+
{
|
|
409
|
+
clean: !0,
|
|
410
|
+
onClick: () => i(!e),
|
|
411
|
+
width: 6,
|
|
412
|
+
height: 6,
|
|
413
|
+
cursor: "pointer",
|
|
414
|
+
userSelect: "none",
|
|
415
|
+
borderRadius: 1,
|
|
416
|
+
borderColor: "gray-200",
|
|
417
|
+
display: "flex",
|
|
418
|
+
jc: "center",
|
|
419
|
+
ai: "center",
|
|
420
|
+
transition: "none",
|
|
421
|
+
bgColor: "gray-200",
|
|
422
|
+
hover: { bgColor: "gray-300" },
|
|
423
|
+
children: [
|
|
424
|
+
/* @__PURE__ */ s(dt, { fill: "violet-950" }),
|
|
425
|
+
e && /* @__PURE__ */ g(
|
|
426
|
+
mt,
|
|
427
|
+
{
|
|
428
|
+
bgColor: "white",
|
|
429
|
+
width: 56,
|
|
430
|
+
b: 1,
|
|
431
|
+
borderColor: "gray-300",
|
|
432
|
+
borderRadius: 1,
|
|
433
|
+
display: "flex",
|
|
434
|
+
d: "column",
|
|
435
|
+
mt: 4,
|
|
436
|
+
py: 2,
|
|
437
|
+
overflow: "hidden",
|
|
438
|
+
translateX: d ? -55 : -5,
|
|
439
|
+
onPositionChange: r,
|
|
440
|
+
ref: n,
|
|
441
|
+
shadow: "medium-shadow",
|
|
442
|
+
children: [
|
|
443
|
+
a && /* @__PURE__ */ g(
|
|
444
|
+
_,
|
|
445
|
+
{
|
|
446
|
+
clean: !0,
|
|
447
|
+
display: "flex",
|
|
448
|
+
gap: 2,
|
|
449
|
+
p: 3,
|
|
450
|
+
cursor: "pointer",
|
|
451
|
+
hover: { bgColor: "gray-200" },
|
|
452
|
+
onClick: () => t.sortColumn("ASC"),
|
|
453
|
+
children: [
|
|
454
|
+
/* @__PURE__ */ s(B, { width: "1rem", fill: "violet-950" }),
|
|
455
|
+
"Sort Ascending"
|
|
456
|
+
]
|
|
457
|
+
}
|
|
458
|
+
),
|
|
459
|
+
c && /* @__PURE__ */ g(
|
|
460
|
+
_,
|
|
461
|
+
{
|
|
462
|
+
clean: !0,
|
|
463
|
+
display: "flex",
|
|
464
|
+
gap: 2,
|
|
465
|
+
p: 3,
|
|
466
|
+
cursor: "pointer",
|
|
467
|
+
hover: { bgColor: "gray-200" },
|
|
468
|
+
onClick: () => t.sortColumn("DESC"),
|
|
469
|
+
children: [
|
|
470
|
+
/* @__PURE__ */ s(B, { width: "1rem", fill: "violet-950", rotate: 180 }),
|
|
471
|
+
"Sort Descending"
|
|
472
|
+
]
|
|
473
|
+
}
|
|
474
|
+
),
|
|
475
|
+
h && /* @__PURE__ */ g(
|
|
476
|
+
_,
|
|
477
|
+
{
|
|
478
|
+
clean: !0,
|
|
479
|
+
display: "flex",
|
|
480
|
+
gap: 2,
|
|
481
|
+
p: 3,
|
|
482
|
+
cursor: "pointer",
|
|
483
|
+
hover: { bgColor: "gray-200" },
|
|
484
|
+
onClick: () => t.sortColumn(void 0),
|
|
485
|
+
children: [
|
|
486
|
+
/* @__PURE__ */ s(p, { width: 4 }),
|
|
487
|
+
"Clear Sort"
|
|
488
|
+
]
|
|
489
|
+
}
|
|
490
|
+
),
|
|
491
|
+
R && (k || v) && /* @__PURE__ */ s(p, { bb: 1, my: 2, borderColor: "gray-300" }),
|
|
492
|
+
m && /* @__PURE__ */ g(
|
|
493
|
+
_,
|
|
494
|
+
{
|
|
495
|
+
clean: !0,
|
|
496
|
+
display: "flex",
|
|
497
|
+
gap: 2,
|
|
498
|
+
p: 3,
|
|
499
|
+
cursor: "pointer",
|
|
500
|
+
hover: { bgColor: "gray-200" },
|
|
501
|
+
onClick: () => t.pinColumn("LEFT"),
|
|
502
|
+
children: [
|
|
503
|
+
/* @__PURE__ */ s(K, { width: "1rem", fill: "violet-950" }),
|
|
504
|
+
"Pin Left"
|
|
505
|
+
]
|
|
506
|
+
}
|
|
507
|
+
),
|
|
508
|
+
f && /* @__PURE__ */ g(
|
|
509
|
+
_,
|
|
510
|
+
{
|
|
511
|
+
clean: !0,
|
|
512
|
+
display: "flex",
|
|
513
|
+
gap: 2,
|
|
514
|
+
p: 3,
|
|
515
|
+
cursor: "pointer",
|
|
516
|
+
hover: { bgColor: "gray-200" },
|
|
517
|
+
onClick: () => t.pinColumn("RIGHT"),
|
|
518
|
+
children: [
|
|
519
|
+
/* @__PURE__ */ s(K, { width: "1rem", fill: "violet-950", rotate: -90 }),
|
|
520
|
+
"Pin Right"
|
|
521
|
+
]
|
|
522
|
+
}
|
|
523
|
+
),
|
|
524
|
+
y && /* @__PURE__ */ g(
|
|
525
|
+
_,
|
|
526
|
+
{
|
|
527
|
+
clean: !0,
|
|
528
|
+
display: "flex",
|
|
529
|
+
gap: 2,
|
|
530
|
+
p: 3,
|
|
531
|
+
cursor: "pointer",
|
|
532
|
+
hover: { bgColor: "gray-200" },
|
|
533
|
+
onClick: () => t.pinColumn(),
|
|
534
|
+
children: [
|
|
535
|
+
/* @__PURE__ */ s(p, { width: 4 }),
|
|
536
|
+
"Unpin"
|
|
537
|
+
]
|
|
538
|
+
}
|
|
539
|
+
),
|
|
540
|
+
R && k && v && /* @__PURE__ */ s(p, { bb: 1, my: 2, borderColor: "gray-300" }),
|
|
541
|
+
v && /* @__PURE__ */ g(_, { clean: !0, display: "flex", gap: 2, p: 3, cursor: "pointer", hover: { bgColor: "gray-200" }, onClick: t.toggleGrouping, children: [
|
|
542
|
+
/* @__PURE__ */ s(p, { children: /* @__PURE__ */ s(pt, { width: "1rem", fill: "violet-950" }) }),
|
|
543
|
+
/* @__PURE__ */ g(p, { textWrap: "nowrap", children: [
|
|
544
|
+
" Group by ",
|
|
545
|
+
t.header ?? t.key
|
|
546
|
+
] })
|
|
547
|
+
] })
|
|
548
|
+
]
|
|
549
|
+
}
|
|
550
|
+
)
|
|
551
|
+
]
|
|
552
|
+
}
|
|
553
|
+
) });
|
|
554
|
+
}
|
|
555
|
+
function $(u) {
|
|
556
|
+
const { children: t, column: e, style: i, ...n } = u, { key: o, pin: r, left: d, right: a, isEdge: c, align: h, widthVarName: m, leftVarName: f, rightVarName: y } = e, v = o === E, R = o === L, k = o === x, G = r === "LEFT", w = r === "RIGHT", P = G || w, W = G && d === 0, D = G && c, M = w && c, S = w && a === 0, O = !k && !v;
|
|
557
|
+
return /* @__PURE__ */ g(
|
|
558
|
+
b,
|
|
559
|
+
{
|
|
560
|
+
component: "datagrid.cell",
|
|
561
|
+
props: { role: "cell" },
|
|
562
|
+
variant: { isRowNumber: R, isRowSelection: k, isPinned: P, isFirstLeftPinned: W, isLastLeftPinned: D, isFirstRightPinned: M, isLastRightPinned: S },
|
|
563
|
+
jc: h,
|
|
564
|
+
style: {
|
|
565
|
+
width: `var(${m})`,
|
|
566
|
+
left: G ? `var(${f})` : void 0,
|
|
567
|
+
right: w ? `var(${y})` : void 0,
|
|
568
|
+
...i
|
|
569
|
+
},
|
|
570
|
+
...n,
|
|
571
|
+
children: [
|
|
572
|
+
O && /* @__PURE__ */ s(p, { px: 4, textOverflow: "ellipsis", overflow: "hidden", textWrap: "nowrap", children: t }),
|
|
573
|
+
k && t
|
|
574
|
+
]
|
|
575
|
+
}
|
|
576
|
+
);
|
|
577
|
+
}
|
|
578
|
+
function Lt(u) {
|
|
579
|
+
const { row: t } = u;
|
|
580
|
+
return /* @__PURE__ */ s(b, { className: "grid-row", display: "contents", props: { role: "rowgroup" }, children: t.cells.map((e) => {
|
|
581
|
+
if (e.column.key === C)
|
|
582
|
+
return /* @__PURE__ */ s(
|
|
583
|
+
$,
|
|
584
|
+
{
|
|
585
|
+
column: e.column,
|
|
586
|
+
style: {
|
|
587
|
+
width: `var(${e.column.groupColumnWidthVarName})`
|
|
588
|
+
},
|
|
589
|
+
br: t.groupingColumn.pin === "LEFT" ? 1 : void 0,
|
|
590
|
+
gridColumn: t.groupingColumnGridColumn,
|
|
591
|
+
pl: 4 * t.depth,
|
|
592
|
+
children: /* @__PURE__ */ s(_, { display: "contents", clean: !0, onClick: () => t.toggleRow(), cursor: "pointer", children: e.value })
|
|
593
|
+
},
|
|
594
|
+
e.column.key
|
|
595
|
+
);
|
|
596
|
+
if (e.column.key === x)
|
|
597
|
+
return /* @__PURE__ */ s($, { column: e.column, children: /* @__PURE__ */ s(V, { m: 1 }) }, e.column.key);
|
|
598
|
+
if (e.column.pin !== t.groupingColumn.pin || e.column.key === E || e.column.key === L)
|
|
599
|
+
return /* @__PURE__ */ s($, { column: e.column, children: e.value }, e.column.key);
|
|
600
|
+
}) });
|
|
601
|
+
}
|
|
602
|
+
function Tt(u) {
|
|
603
|
+
const { row: t } = u;
|
|
604
|
+
return /* @__PURE__ */ s(b, { className: "grid-row", display: "contents", props: { role: "row" }, children: t.cells.map((e) => /* @__PURE__ */ s($, { column: e.column, children: e.column.key === x ? /* @__PURE__ */ s(V, {}) : e.value }, e.column.key)) });
|
|
605
|
+
}
|
|
606
|
+
function Bt(u) {
|
|
607
|
+
const t = vt(u), { isResizeMode: e } = t, i = N(() => (console.log("render - headers"), t.headerRows.value.map((r) => r.map((d) => /* @__PURE__ */ s(Rt, { column: d }, d.uniqueKey)))), [t.headerRows.value]), n = ut(null), o = at(
|
|
608
|
+
j.throttle((r) => {
|
|
609
|
+
var d;
|
|
610
|
+
(d = n.current) == null || d.setScrollTop(r.target.scrollTop);
|
|
611
|
+
}, 100),
|
|
612
|
+
[n.current]
|
|
613
|
+
);
|
|
614
|
+
return console.log("render - data grid"), /* @__PURE__ */ g(p, { component: "datagrid", style: t.sizes.value, props: { role: "presentation" }, children: [
|
|
615
|
+
/* @__PURE__ */ s(p, { p: 3, bb: 1, borderColor: "gray-400", children: t.groupColumns.length > 0 ? t.groupColumns.join(" > ") : "No grouping" }),
|
|
616
|
+
/* @__PURE__ */ g(p, { overflowX: "scroll", props: { onScroll: o }, children: [
|
|
617
|
+
/* @__PURE__ */ s(X, { component: "datagrid.header", variant: { isResizeMode: e }, style: { gridTemplateColumns: t.gridTemplateColumns.value }, children: i }),
|
|
618
|
+
/* @__PURE__ */ s(Et, { ref: n, grid: t })
|
|
619
|
+
] }),
|
|
620
|
+
/* @__PURE__ */ g(p, { p: 3, bgColor: "gray-200", children: [
|
|
621
|
+
"Rows: ",
|
|
622
|
+
t.rows.value.length
|
|
623
|
+
] })
|
|
624
|
+
] });
|
|
625
|
+
}
|
|
626
|
+
const Y = 10, J = 25, bt = Y + J * 2;
|
|
627
|
+
function xt(u, t) {
|
|
628
|
+
const { grid: e } = u, i = gt * e.ROW_HEIGHT, [n, o] = H(0), r = Math.max(0, Math.floor(n / i) - J), d = N(() => (console.log("render - rows"), e.flatRows.value.take(bt, r).map((h) => h instanceof q ? /* @__PURE__ */ s(Lt, { row: h }, h.rowKey) : /* @__PURE__ */ s(Tt, { row: h }, h.rowKey))), [e.flatRows.value, r]);
|
|
629
|
+
ht(t, () => ({
|
|
630
|
+
setScrollTop: o
|
|
631
|
+
}));
|
|
632
|
+
const a = e.flatRows.value.length;
|
|
633
|
+
return /* @__PURE__ */ s(p, { height: e.ROW_HEIGHT * Y, children: /* @__PURE__ */ s(
|
|
634
|
+
p,
|
|
635
|
+
{
|
|
636
|
+
style: {
|
|
637
|
+
height: `${a * i}px`
|
|
638
|
+
},
|
|
639
|
+
children: /* @__PURE__ */ s(
|
|
640
|
+
X,
|
|
641
|
+
{
|
|
642
|
+
props: { role: "presentation" },
|
|
643
|
+
width: "max-content",
|
|
644
|
+
minWidth: "fit",
|
|
645
|
+
transition: "none",
|
|
646
|
+
style: {
|
|
647
|
+
transform: `translateY(${r * i}px)`,
|
|
648
|
+
gridTemplateColumns: e.gridTemplateColumns.value
|
|
649
|
+
},
|
|
650
|
+
children: d
|
|
651
|
+
}
|
|
652
|
+
)
|
|
653
|
+
}
|
|
654
|
+
) });
|
|
655
|
+
}
|
|
656
|
+
const Et = lt(xt);
|
|
19
657
|
export {
|
|
20
|
-
|
|
658
|
+
Bt as default
|
|
21
659
|
};
|