schummar-table 0.5.0-beta-1 → 0.5.0-beta-4
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/dist/cjs/index.js +2275 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/mui4Theme.js +95 -4
- package/dist/cjs/mui4Theme.js.map +1 -1
- package/dist/cjs/mui5Theme.js +99 -4
- package/dist/cjs/mui5Theme.js.map +1 -1
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/tableTheme.js +648 -0
- package/dist/cjs/tableTheme.js.map +1 -0
- package/dist/es/index.js +2258 -0
- package/dist/es/index.js.map +1 -0
- package/dist/es/mui4Theme.js +94 -0
- package/dist/es/mui4Theme.js.map +1 -0
- package/dist/es/mui5Theme.js +98 -0
- package/dist/es/mui5Theme.js.map +1 -0
- package/dist/es/tableTheme.js +640 -0
- package/dist/es/tableTheme.js.map +1 -0
- package/dist/types/components/row.d.ts +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/misc/helpers.d.ts +1 -0
- package/dist/types/types.d.ts +7 -7
- package/package.json +21 -17
- package/dist/assets/tableTheme.0eb513b0.js +0 -215
- package/dist/assets/tableTheme.0eb513b0.js.map +0 -1
- package/dist/assets/tableTheme.65fea986.js +0 -214
- package/dist/assets/tableTheme.65fea986.js.map +0 -1
- package/dist/assets/vendor.a5ec605d.js +0 -2475
- package/dist/assets/vendor.a5ec605d.js.map +0 -1
- package/dist/assets/vendor.c9c3328b.js +0 -2464
- package/dist/assets/vendor.c9c3328b.js.map +0 -1
- package/dist/cjs/schummar-table.js +0 -1042
- package/dist/cjs/schummar-table.js.map +0 -1
- package/dist/esm/mui4Theme.js +0 -6
- package/dist/esm/mui4Theme.js.map +0 -1
- package/dist/esm/mui5Theme.js +0 -6
- package/dist/esm/mui5Theme.js.map +0 -1
- package/dist/esm/schummar-table.js +0 -1041
- package/dist/esm/schummar-table.js.map +0 -1
|
@@ -0,0 +1,2275 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defProps = Object.defineProperties;
|
|
4
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
5
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
8
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
9
|
+
var __spreadValues = (a, b) => {
|
|
10
|
+
for (var prop in b || (b = {}))
|
|
11
|
+
if (__hasOwnProp.call(b, prop))
|
|
12
|
+
__defNormalProp(a, prop, b[prop]);
|
|
13
|
+
if (__getOwnPropSymbols)
|
|
14
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
15
|
+
if (__propIsEnum.call(b, prop))
|
|
16
|
+
__defNormalProp(a, prop, b[prop]);
|
|
17
|
+
}
|
|
18
|
+
return a;
|
|
19
|
+
};
|
|
20
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
21
|
+
var __objRest = (source, exclude) => {
|
|
22
|
+
var target = {};
|
|
23
|
+
for (var prop in source)
|
|
24
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
25
|
+
target[prop] = source[prop];
|
|
26
|
+
if (source != null && __getOwnPropSymbols)
|
|
27
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
28
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
29
|
+
target[prop] = source[prop];
|
|
30
|
+
}
|
|
31
|
+
return target;
|
|
32
|
+
};
|
|
33
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
34
|
+
exports[Symbol.toStringTag] = "Module";
|
|
35
|
+
var react = require("react");
|
|
36
|
+
var dayzed = require("dayzed");
|
|
37
|
+
var tableTheme = require("./tableTheme.js");
|
|
38
|
+
var jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
39
|
+
var immer = require("immer");
|
|
40
|
+
var react$1 = require("schummar-state/react");
|
|
41
|
+
require("@emotion/react");
|
|
42
|
+
require("react-dom");
|
|
43
|
+
function useCssVariables() {
|
|
44
|
+
const table = useTableContext();
|
|
45
|
+
return table.useState((state) => ({
|
|
46
|
+
"--spacing": state.theme.spacing,
|
|
47
|
+
"--primaryMain": state.theme.colors.primary.main,
|
|
48
|
+
"--primaryLight": state.theme.colors.primary.light,
|
|
49
|
+
"--primaryContrastText": state.theme.colors.primary.contrastText,
|
|
50
|
+
"--secondaryMain": state.theme.colors.secondary.main,
|
|
51
|
+
"--secondaryLight": state.theme.colors.secondary.light,
|
|
52
|
+
"--secondaryContrastText": state.theme.colors.secondary.contrastText
|
|
53
|
+
}));
|
|
54
|
+
}
|
|
55
|
+
const weekDays = [0, 1, 2, 3, 4, 5, 6];
|
|
56
|
+
const months = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11];
|
|
57
|
+
const startOfDay = (d) => new Date(d.getFullYear(), d.getMonth(), d.getDate());
|
|
58
|
+
const endOfDay = (d) => new Date(d.getFullYear(), d.getMonth(), d.getDate() + 1, 0, 0, 0, -1);
|
|
59
|
+
const today = () => {
|
|
60
|
+
const today2 = startOfDay(new Date());
|
|
61
|
+
return {
|
|
62
|
+
min: today2,
|
|
63
|
+
max: today2
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
function dateIntersect(a, b) {
|
|
67
|
+
if (a instanceof Date) {
|
|
68
|
+
a = {
|
|
69
|
+
min: a,
|
|
70
|
+
max: a
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
if (b instanceof Date) {
|
|
74
|
+
b = {
|
|
75
|
+
min: b,
|
|
76
|
+
max: b
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
if (!(a == null ? void 0 : a.min) || !a.max || !(b == null ? void 0 : b.min) || !b.max) {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
return !(endOfDay(a.max) < startOfDay(b.min) || startOfDay(a.min) > endOfDay(b.max));
|
|
83
|
+
}
|
|
84
|
+
function DatePicker({
|
|
85
|
+
value,
|
|
86
|
+
onChange,
|
|
87
|
+
rangeSelect,
|
|
88
|
+
locale,
|
|
89
|
+
firstDayOfWeek = 0
|
|
90
|
+
}) {
|
|
91
|
+
const {
|
|
92
|
+
components: {
|
|
93
|
+
IconButton
|
|
94
|
+
},
|
|
95
|
+
icons: {
|
|
96
|
+
ChevronRight
|
|
97
|
+
}
|
|
98
|
+
} = useTheme();
|
|
99
|
+
const [baseDate] = react.useState(new Date());
|
|
100
|
+
const [dateInView, setDateInView] = react.useState(baseDate);
|
|
101
|
+
const [currentMin, setCurrentMin] = react.useState();
|
|
102
|
+
const [hovered, setHovered] = react.useState();
|
|
103
|
+
const min = currentMin != null ? currentMin : value instanceof Date ? value : value == null ? void 0 : value.min;
|
|
104
|
+
const max = currentMin ? void 0 : value instanceof Date ? value : value == null ? void 0 : value.max;
|
|
105
|
+
const {
|
|
106
|
+
calendars,
|
|
107
|
+
getBackProps,
|
|
108
|
+
getForwardProps,
|
|
109
|
+
getDateProps
|
|
110
|
+
} = dayzed.useDayzed({
|
|
111
|
+
onDateSelected: () => void 0,
|
|
112
|
+
firstDayOfWeek,
|
|
113
|
+
showOutsideDays: true,
|
|
114
|
+
date: dateInView,
|
|
115
|
+
onOffsetChanged: (offset) => setDateInView(new Date(dateInView.getFullYear(), dateInView.getMonth() + offset)),
|
|
116
|
+
offset: 0
|
|
117
|
+
});
|
|
118
|
+
const formatWeekday = react.useMemo(() => {
|
|
119
|
+
const {
|
|
120
|
+
format
|
|
121
|
+
} = new Intl.DateTimeFormat(locale, {
|
|
122
|
+
weekday: "short"
|
|
123
|
+
});
|
|
124
|
+
return (weekDay) => format(new Date(Date.UTC(2021, 5, weekDay)));
|
|
125
|
+
}, [locale]);
|
|
126
|
+
react.useEffect(() => setDateInView(value === null ? new Date() : value instanceof Date ? value : value.max), [value]);
|
|
127
|
+
return jsxRuntime.jsx("div", {
|
|
128
|
+
children: calendars.map(({
|
|
129
|
+
month,
|
|
130
|
+
year,
|
|
131
|
+
weeks
|
|
132
|
+
}) => jsxRuntime.jsxs("div", {
|
|
133
|
+
children: [jsxRuntime.jsxs("div", {
|
|
134
|
+
css: {
|
|
135
|
+
margin: "calc(var(--spacing) * 4) 0",
|
|
136
|
+
display: "grid",
|
|
137
|
+
gridAutoFlow: "column",
|
|
138
|
+
justifyContent: "space-between",
|
|
139
|
+
alignItems: "center"
|
|
140
|
+
},
|
|
141
|
+
children: [jsxRuntime.jsx(IconButton, __spreadProps(__spreadValues({}, getBackProps({
|
|
142
|
+
calendars
|
|
143
|
+
})), {
|
|
144
|
+
children: jsxRuntime.jsx(ChevronRight, {
|
|
145
|
+
css: {
|
|
146
|
+
transform: "rotate3d(0, 0, 1, 180deg)"
|
|
147
|
+
}
|
|
148
|
+
})
|
|
149
|
+
})), jsxRuntime.jsxs("div", {
|
|
150
|
+
css: {
|
|
151
|
+
display: "flex"
|
|
152
|
+
},
|
|
153
|
+
children: [jsxRuntime.jsx(MonthSelector, {
|
|
154
|
+
value: month,
|
|
155
|
+
onChange: (month2) => setDateInView(new Date(year, month2)),
|
|
156
|
+
locale
|
|
157
|
+
}), jsxRuntime.jsx(YearSelector, {
|
|
158
|
+
value: year,
|
|
159
|
+
onChange: (year2) => setDateInView(new Date(year2, month))
|
|
160
|
+
})]
|
|
161
|
+
}), jsxRuntime.jsx(IconButton, __spreadProps(__spreadValues({}, getForwardProps({
|
|
162
|
+
calendars
|
|
163
|
+
})), {
|
|
164
|
+
children: jsxRuntime.jsx(ChevronRight, {})
|
|
165
|
+
}))]
|
|
166
|
+
}), jsxRuntime.jsxs("div", {
|
|
167
|
+
css: {
|
|
168
|
+
display: "grid",
|
|
169
|
+
gridTemplateColumns: "repeat(7, max-content)",
|
|
170
|
+
fontWeight: "bold"
|
|
171
|
+
},
|
|
172
|
+
children: [weekDays.map((_v, weekDay) => jsxRuntime.jsx("div", {
|
|
173
|
+
css: {
|
|
174
|
+
justifySelf: "center",
|
|
175
|
+
marginBottom: "var(--spacing)"
|
|
176
|
+
},
|
|
177
|
+
children: formatWeekday(weekDay)
|
|
178
|
+
}, weekDay)), weeks.map((week, index) => week.map((dateObj, dayIndex) => {
|
|
179
|
+
if (!dateObj) {
|
|
180
|
+
return jsxRuntime.jsx("div", {});
|
|
181
|
+
}
|
|
182
|
+
const {
|
|
183
|
+
prevMonth,
|
|
184
|
+
nextMonth,
|
|
185
|
+
date,
|
|
186
|
+
today: today2
|
|
187
|
+
} = dateObj;
|
|
188
|
+
const selected = date.getTime() === (min == null ? void 0 : min.getTime()) || min && max && dateIntersect(date, {
|
|
189
|
+
min,
|
|
190
|
+
max
|
|
191
|
+
});
|
|
192
|
+
const preSelected = !selected && (date.getTime() === (hovered == null ? void 0 : hovered.getTime()) || min && !max && hovered && dateIntersect(date, min <= hovered ? {
|
|
193
|
+
min,
|
|
194
|
+
max: hovered
|
|
195
|
+
} : {
|
|
196
|
+
min: hovered,
|
|
197
|
+
max: min
|
|
198
|
+
}));
|
|
199
|
+
return jsxRuntime.jsx("button", __spreadProps(__spreadValues({
|
|
200
|
+
css: [{
|
|
201
|
+
padding: 10,
|
|
202
|
+
border: "1px solid transparent",
|
|
203
|
+
background: "transparent",
|
|
204
|
+
cursor: "pointer"
|
|
205
|
+
}, (prevMonth || nextMonth) && {
|
|
206
|
+
color: tableTheme.gray
|
|
207
|
+
}, today2 && {
|
|
208
|
+
border: "1px solid var(--secondaryMain)"
|
|
209
|
+
}, selected && {
|
|
210
|
+
background: "var(--primaryMain)",
|
|
211
|
+
color: "var(--primaryContrastText)"
|
|
212
|
+
}, preSelected && {
|
|
213
|
+
background: "var(--primaryLight)",
|
|
214
|
+
color: "var(--primaryContrastText)"
|
|
215
|
+
}]
|
|
216
|
+
}, getDateProps({
|
|
217
|
+
dateObj
|
|
218
|
+
})), {
|
|
219
|
+
onClick: () => {
|
|
220
|
+
if (!rangeSelect) {
|
|
221
|
+
setCurrentMin(void 0);
|
|
222
|
+
onChange(date);
|
|
223
|
+
} else if (min && !max) {
|
|
224
|
+
setCurrentMin(void 0);
|
|
225
|
+
if (date > min) {
|
|
226
|
+
onChange({
|
|
227
|
+
min,
|
|
228
|
+
max: date
|
|
229
|
+
});
|
|
230
|
+
} else {
|
|
231
|
+
onChange({
|
|
232
|
+
min: date,
|
|
233
|
+
max: min
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
} else {
|
|
237
|
+
setCurrentMin(date);
|
|
238
|
+
}
|
|
239
|
+
},
|
|
240
|
+
onPointerOver: () => setHovered(date),
|
|
241
|
+
onPointerOut: () => setHovered(void 0),
|
|
242
|
+
children: date.getDate()
|
|
243
|
+
}), `${index}-${dayIndex}`);
|
|
244
|
+
}))]
|
|
245
|
+
})]
|
|
246
|
+
}, `${month}${year}`))
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
function MonthSelector({
|
|
250
|
+
value,
|
|
251
|
+
onChange,
|
|
252
|
+
locale
|
|
253
|
+
}) {
|
|
254
|
+
const {
|
|
255
|
+
components: {
|
|
256
|
+
Popover
|
|
257
|
+
}
|
|
258
|
+
} = useTheme();
|
|
259
|
+
const cssVariables = useCssVariables();
|
|
260
|
+
const [anchor, setAnchor] = react.useState();
|
|
261
|
+
const formatMonth = react.useMemo(() => {
|
|
262
|
+
const {
|
|
263
|
+
format
|
|
264
|
+
} = new Intl.DateTimeFormat(locale, {
|
|
265
|
+
month: "long"
|
|
266
|
+
});
|
|
267
|
+
return (month) => format(new Date(2021, month));
|
|
268
|
+
}, [locale]);
|
|
269
|
+
return jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
|
270
|
+
children: [jsxRuntime.jsx("button", {
|
|
271
|
+
css: {
|
|
272
|
+
border: "none",
|
|
273
|
+
background: "transparent",
|
|
274
|
+
fontSize: "inherit",
|
|
275
|
+
cursor: "pointer"
|
|
276
|
+
},
|
|
277
|
+
onClick: (e) => setAnchor(e.currentTarget),
|
|
278
|
+
children: formatMonth(value)
|
|
279
|
+
}), jsxRuntime.jsx(Popover, {
|
|
280
|
+
open: !!anchor,
|
|
281
|
+
anchorEl: anchor != null ? anchor : null,
|
|
282
|
+
onClose: () => setAnchor(void 0),
|
|
283
|
+
align: "center",
|
|
284
|
+
css: cssVariables,
|
|
285
|
+
children: jsxRuntime.jsx("div", {
|
|
286
|
+
css: {
|
|
287
|
+
display: "grid"
|
|
288
|
+
},
|
|
289
|
+
children: months.map((month) => jsxRuntime.jsx("button", {
|
|
290
|
+
css: [{
|
|
291
|
+
padding: "var(--spacing)",
|
|
292
|
+
border: "none",
|
|
293
|
+
background: "transparent",
|
|
294
|
+
"&:hover": {
|
|
295
|
+
background: "var(--primaryLight)"
|
|
296
|
+
}
|
|
297
|
+
}, month === value && {
|
|
298
|
+
background: "var(--primaryMain)"
|
|
299
|
+
}],
|
|
300
|
+
onClick: () => onChange(month),
|
|
301
|
+
children: formatMonth(month)
|
|
302
|
+
}, month))
|
|
303
|
+
})
|
|
304
|
+
})]
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
function YearSelector({
|
|
308
|
+
value,
|
|
309
|
+
onChange,
|
|
310
|
+
locale
|
|
311
|
+
}) {
|
|
312
|
+
const [input, setInput] = react.useState();
|
|
313
|
+
function apply() {
|
|
314
|
+
onChange(Number(input));
|
|
315
|
+
setInput(void 0);
|
|
316
|
+
}
|
|
317
|
+
const formatYear = react.useMemo(() => {
|
|
318
|
+
const {
|
|
319
|
+
format
|
|
320
|
+
} = new Intl.DateTimeFormat(locale, {
|
|
321
|
+
year: "numeric"
|
|
322
|
+
});
|
|
323
|
+
return (year) => format(new Date(year, 0, 1));
|
|
324
|
+
}, [locale]);
|
|
325
|
+
if (input === void 0) {
|
|
326
|
+
return jsxRuntime.jsx("div", {
|
|
327
|
+
onClick: () => setInput(String(value)),
|
|
328
|
+
children: formatYear(value)
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
return jsxRuntime.jsx("input", {
|
|
332
|
+
css: {
|
|
333
|
+
width: "4ch"
|
|
334
|
+
},
|
|
335
|
+
value: input,
|
|
336
|
+
onChange: (e) => {
|
|
337
|
+
if (e.target.value.match(/^\d{0,4}$/)) {
|
|
338
|
+
setInput(e.target.value);
|
|
339
|
+
}
|
|
340
|
+
},
|
|
341
|
+
onBlur: apply,
|
|
342
|
+
onKeyPress: (e) => e.key === "Enter" && apply()
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
function convertDate(x) {
|
|
346
|
+
if (x instanceof Date)
|
|
347
|
+
return x;
|
|
348
|
+
if (typeof x === "number" || typeof x === "string")
|
|
349
|
+
return new Date(x);
|
|
350
|
+
return null;
|
|
351
|
+
}
|
|
352
|
+
function convertDateOrRange(x) {
|
|
353
|
+
if (x instanceof Object && "min" in x && "max" in x) {
|
|
354
|
+
const range = {
|
|
355
|
+
min: convertDate(x.min),
|
|
356
|
+
max: convertDate(x.max)
|
|
357
|
+
};
|
|
358
|
+
return range.min && range.max ? range : null;
|
|
359
|
+
}
|
|
360
|
+
return convertDate(x);
|
|
361
|
+
}
|
|
362
|
+
function convertDateOrArray(x) {
|
|
363
|
+
if (x instanceof Array)
|
|
364
|
+
return x.map(convertDateOrRange).filter(Boolean);
|
|
365
|
+
return convertDateOrRange(x);
|
|
366
|
+
}
|
|
367
|
+
function DateFilter(_a) {
|
|
368
|
+
var _b = _a, {
|
|
369
|
+
locale,
|
|
370
|
+
firstDayOfWeek,
|
|
371
|
+
singleSelect,
|
|
372
|
+
filterBy = convertDateOrArray
|
|
373
|
+
} = _b, props = __objRest(_b, [
|
|
374
|
+
"locale",
|
|
375
|
+
"firstDayOfWeek",
|
|
376
|
+
"singleSelect",
|
|
377
|
+
"filterBy"
|
|
378
|
+
]);
|
|
379
|
+
const {
|
|
380
|
+
components: {
|
|
381
|
+
Button
|
|
382
|
+
},
|
|
383
|
+
text
|
|
384
|
+
} = useTheme();
|
|
385
|
+
const {
|
|
386
|
+
value = null,
|
|
387
|
+
onChange
|
|
388
|
+
} = useFilter(__spreadProps(__spreadValues({}, props), {
|
|
389
|
+
filterBy,
|
|
390
|
+
id: "dateFilter",
|
|
391
|
+
isActive(filterValue) {
|
|
392
|
+
return !!filterValue;
|
|
393
|
+
},
|
|
394
|
+
test(filterValue, value2) {
|
|
395
|
+
return dateIntersect(filterValue, value2);
|
|
396
|
+
}
|
|
397
|
+
}));
|
|
398
|
+
const formatDate = react.useMemo(() => {
|
|
399
|
+
const {
|
|
400
|
+
format
|
|
401
|
+
} = new Intl.DateTimeFormat(locale, {
|
|
402
|
+
dateStyle: "medium"
|
|
403
|
+
});
|
|
404
|
+
return format;
|
|
405
|
+
}, [locale]);
|
|
406
|
+
return jsxRuntime.jsxs("div", {
|
|
407
|
+
css: {
|
|
408
|
+
padding: "calc(var(--spacing) * 2)",
|
|
409
|
+
display: "grid",
|
|
410
|
+
gap: "var(--spacing)",
|
|
411
|
+
justifyItems: "center"
|
|
412
|
+
},
|
|
413
|
+
children: [jsxRuntime.jsxs("div", {
|
|
414
|
+
css: {
|
|
415
|
+
marginBottom: "var(--spacing)",
|
|
416
|
+
display: "grid",
|
|
417
|
+
gridAutoFlow: "column",
|
|
418
|
+
gap: "calc(var(--spacing) * 4)",
|
|
419
|
+
justifyContent: "space-between",
|
|
420
|
+
alignItems: "center"
|
|
421
|
+
},
|
|
422
|
+
children: [jsxRuntime.jsx("div", {
|
|
423
|
+
css: {
|
|
424
|
+
minWidth: "22ch"
|
|
425
|
+
},
|
|
426
|
+
children: !value ? text.dateFilter : value instanceof Date ? formatDate(value) : [formatDate(value.min), formatDate(value.max)].join(" - ")
|
|
427
|
+
}), jsxRuntime.jsxs("div", {
|
|
428
|
+
css: {
|
|
429
|
+
display: "grid",
|
|
430
|
+
gridAutoFlow: "column",
|
|
431
|
+
gap: "var(--spacing)"
|
|
432
|
+
},
|
|
433
|
+
children: [jsxRuntime.jsx(Button, {
|
|
434
|
+
variant: "contained",
|
|
435
|
+
onClick: () => onChange(today()),
|
|
436
|
+
children: text.today
|
|
437
|
+
}), jsxRuntime.jsx(Button, {
|
|
438
|
+
variant: "contained",
|
|
439
|
+
onClick: () => onChange(null),
|
|
440
|
+
children: text.reset
|
|
441
|
+
})]
|
|
442
|
+
})]
|
|
443
|
+
}), jsxRuntime.jsx(DatePicker, {
|
|
444
|
+
rangeSelect: !singleSelect,
|
|
445
|
+
value,
|
|
446
|
+
onChange,
|
|
447
|
+
locale,
|
|
448
|
+
firstDayOfWeek
|
|
449
|
+
})]
|
|
450
|
+
});
|
|
451
|
+
}
|
|
452
|
+
const flatMap = (arr, flatMap2) => {
|
|
453
|
+
return [...arr].reduce((out, cur) => out.concat(flatMap2(cur)), []);
|
|
454
|
+
};
|
|
455
|
+
const orderBy = (arr, selectors = [], direction = []) => {
|
|
456
|
+
if (selectors.length === 0)
|
|
457
|
+
selectors = [(t) => t];
|
|
458
|
+
return [...arr].sort((a, b) => {
|
|
459
|
+
var _a, _b;
|
|
460
|
+
for (let i = 0; i < selectors.length; i++) {
|
|
461
|
+
const _a2 = (_a = selectors[i]) == null ? void 0 : _a.call(selectors, a);
|
|
462
|
+
const _b2 = (_b = selectors[i]) == null ? void 0 : _b.call(selectors, b);
|
|
463
|
+
const dir = direction[i] === "desc" ? -1 : 1;
|
|
464
|
+
if (_a2 > _b2)
|
|
465
|
+
return dir;
|
|
466
|
+
if (_a2 < _b2)
|
|
467
|
+
return -dir;
|
|
468
|
+
}
|
|
469
|
+
return 0;
|
|
470
|
+
});
|
|
471
|
+
};
|
|
472
|
+
const uniq = (arr) => {
|
|
473
|
+
const set = /* @__PURE__ */ new Set();
|
|
474
|
+
for (const t of arr)
|
|
475
|
+
set.add(t);
|
|
476
|
+
return Array.from(set);
|
|
477
|
+
};
|
|
478
|
+
const intersect = (a, b) => {
|
|
479
|
+
const result = /* @__PURE__ */ new Set();
|
|
480
|
+
for (const x of a)
|
|
481
|
+
if (b.has(x))
|
|
482
|
+
result.add(x);
|
|
483
|
+
return result;
|
|
484
|
+
};
|
|
485
|
+
const getAncestors = (activeItemsById, ...items) => {
|
|
486
|
+
const result = /* @__PURE__ */ new Set();
|
|
487
|
+
const find = ({ parentId }) => {
|
|
488
|
+
const parent = parentId ? activeItemsById.get(parentId) : void 0;
|
|
489
|
+
if (parent && !result.has(parent.id)) {
|
|
490
|
+
result.add(parent.id);
|
|
491
|
+
find(parent);
|
|
492
|
+
}
|
|
493
|
+
};
|
|
494
|
+
items.forEach(find);
|
|
495
|
+
return result;
|
|
496
|
+
};
|
|
497
|
+
const getDescendants = (...items) => {
|
|
498
|
+
const result = /* @__PURE__ */ new Set();
|
|
499
|
+
const find = (item) => {
|
|
500
|
+
for (const child of item.children) {
|
|
501
|
+
if (!result.has(child.id)) {
|
|
502
|
+
result.add(child.id);
|
|
503
|
+
find(child);
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
};
|
|
507
|
+
items.forEach(find);
|
|
508
|
+
return result;
|
|
509
|
+
};
|
|
510
|
+
const asString = (x) => {
|
|
511
|
+
if (x instanceof Array)
|
|
512
|
+
return x.map(asString).join(", ");
|
|
513
|
+
if (x instanceof Object)
|
|
514
|
+
return JSON.stringify(x);
|
|
515
|
+
return String(x != null ? x : "");
|
|
516
|
+
};
|
|
517
|
+
const asStringOrArray = (x) => {
|
|
518
|
+
if (x instanceof Array)
|
|
519
|
+
return x.map(asString);
|
|
520
|
+
return asString(x);
|
|
521
|
+
};
|
|
522
|
+
const castArray = (a) => a instanceof Array ? a : [a];
|
|
523
|
+
const cx = (...classNames) => classNames.flatMap((entry) => {
|
|
524
|
+
if (!entry)
|
|
525
|
+
return [];
|
|
526
|
+
if (typeof entry === "string")
|
|
527
|
+
return [entry];
|
|
528
|
+
return Object.entries(entry).filter(([, predicate]) => predicate).map(([className]) => className);
|
|
529
|
+
}).join(" ");
|
|
530
|
+
function FormControlLabel({
|
|
531
|
+
control,
|
|
532
|
+
label
|
|
533
|
+
}) {
|
|
534
|
+
return jsxRuntime.jsxs("label", {
|
|
535
|
+
css: {
|
|
536
|
+
display: "flex",
|
|
537
|
+
alignItems: "center",
|
|
538
|
+
cursor: "pointer",
|
|
539
|
+
userSelect: "none",
|
|
540
|
+
"& > *": {
|
|
541
|
+
cursor: "pointer"
|
|
542
|
+
}
|
|
543
|
+
},
|
|
544
|
+
children: [control, jsxRuntime.jsx("span", {
|
|
545
|
+
css: {
|
|
546
|
+
marginLeft: "var(--spacing)"
|
|
547
|
+
},
|
|
548
|
+
children: label
|
|
549
|
+
})]
|
|
550
|
+
});
|
|
551
|
+
}
|
|
552
|
+
class Queue {
|
|
553
|
+
constructor() {
|
|
554
|
+
this.q = new Array();
|
|
555
|
+
this.isRunning = false;
|
|
556
|
+
}
|
|
557
|
+
run(job, replace) {
|
|
558
|
+
return new Promise((resolve, reject) => {
|
|
559
|
+
if (replace) {
|
|
560
|
+
this.q = [];
|
|
561
|
+
}
|
|
562
|
+
this.q.push({ job, resolve, reject });
|
|
563
|
+
if (!this.isRunning)
|
|
564
|
+
this.start();
|
|
565
|
+
});
|
|
566
|
+
}
|
|
567
|
+
async start() {
|
|
568
|
+
this.isRunning = true;
|
|
569
|
+
let next;
|
|
570
|
+
while (next = this.q.shift()) {
|
|
571
|
+
try {
|
|
572
|
+
const result = await next.job();
|
|
573
|
+
next.resolve(result);
|
|
574
|
+
} catch (e) {
|
|
575
|
+
next.reject(e);
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
this.isRunning = false;
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
const KEYS = ["sort", "selection", "expanded", "hiddenColumns", "filterValues", "columnWidths", "columnOrder"];
|
|
582
|
+
function stringify(value) {
|
|
583
|
+
function prepare(value2) {
|
|
584
|
+
if (value2 instanceof Date) {
|
|
585
|
+
return { __date: value2.toJSON() };
|
|
586
|
+
}
|
|
587
|
+
if (value2 instanceof Set) {
|
|
588
|
+
return { __set: Array.from(value2).map(prepare) };
|
|
589
|
+
}
|
|
590
|
+
if (value2 instanceof Map) {
|
|
591
|
+
return { __map: Array.from(value2.entries()).map((entry) => entry.map(prepare)) };
|
|
592
|
+
}
|
|
593
|
+
if (value2 instanceof Array) {
|
|
594
|
+
return value2.map(prepare);
|
|
595
|
+
}
|
|
596
|
+
if (value2 instanceof Object) {
|
|
597
|
+
return Object.fromEntries(Object.entries(value2).map(([k, v]) => [k, prepare(v)]));
|
|
598
|
+
}
|
|
599
|
+
return value2;
|
|
600
|
+
}
|
|
601
|
+
return JSON.stringify(prepare(value));
|
|
602
|
+
}
|
|
603
|
+
function parse(value) {
|
|
604
|
+
return JSON.parse(value, (_key, value2) => {
|
|
605
|
+
if (value2 instanceof Object && "__date" in value2) {
|
|
606
|
+
return new Date(value2.__date);
|
|
607
|
+
}
|
|
608
|
+
if (value2 instanceof Object && "__set" in value2) {
|
|
609
|
+
return new Set(value2.__set);
|
|
610
|
+
}
|
|
611
|
+
if (value2 instanceof Object && "__map" in value2) {
|
|
612
|
+
return new Map(value2.__map);
|
|
613
|
+
}
|
|
614
|
+
return value2;
|
|
615
|
+
});
|
|
616
|
+
}
|
|
617
|
+
function useTableStateStorage() {
|
|
618
|
+
const table = useTableContext();
|
|
619
|
+
const [isHydrated, setIsHydrated] = react.useState(false);
|
|
620
|
+
react.useEffect(() => {
|
|
621
|
+
const { persist } = table.getState().props;
|
|
622
|
+
if (!persist) {
|
|
623
|
+
setIsHydrated(true);
|
|
624
|
+
return;
|
|
625
|
+
}
|
|
626
|
+
let isCanceled = false;
|
|
627
|
+
(async () => {
|
|
628
|
+
var _a, _b;
|
|
629
|
+
try {
|
|
630
|
+
const { storage, id = "table", include, exclude } = persist;
|
|
631
|
+
const json = await storage.getItem(`${id}_state`);
|
|
632
|
+
if (isCanceled || !json)
|
|
633
|
+
return;
|
|
634
|
+
const data = parse(json);
|
|
635
|
+
(_b = (_a = table.getState().props).debug) == null ? void 0 : _b.call(_a, "load", json, data);
|
|
636
|
+
table.update((state) => {
|
|
637
|
+
var _a2, _b2, _c, _d;
|
|
638
|
+
for (const key of KEYS) {
|
|
639
|
+
if ((!include || include.includes(key)) && !(exclude == null ? void 0 : exclude.includes(key)) && key in data) {
|
|
640
|
+
if (key === "filterValues") {
|
|
641
|
+
for (const [id2, value] of data[key]) {
|
|
642
|
+
if ((_b2 = (_a2 = state.filters.get(id2)) == null ? void 0 : _a2.persist) != null ? _b2 : true) {
|
|
643
|
+
state.filterValues.set(id2, value);
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
} else {
|
|
647
|
+
state[key] = data[key];
|
|
648
|
+
if (key === "expanded" || key === "hiddenColumns" || key === "selection" || key === "sort") {
|
|
649
|
+
(_d = (_c = state.props)[`on${key.slice(0, 1).toUpperCase() + key.slice(1)}Change`]) == null ? void 0 : _d.call(_c, data[key]);
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
});
|
|
655
|
+
} catch (e) {
|
|
656
|
+
console.error("Failed to load table state:", e);
|
|
657
|
+
} finally {
|
|
658
|
+
setIsHydrated(true);
|
|
659
|
+
}
|
|
660
|
+
})();
|
|
661
|
+
return () => {
|
|
662
|
+
isCanceled = true;
|
|
663
|
+
};
|
|
664
|
+
}, []);
|
|
665
|
+
react.useEffect(() => {
|
|
666
|
+
if (!isHydrated)
|
|
667
|
+
return;
|
|
668
|
+
const q = new Queue();
|
|
669
|
+
return table.subscribe((state) => {
|
|
670
|
+
var _a, _b;
|
|
671
|
+
if (!state.props.persist)
|
|
672
|
+
return;
|
|
673
|
+
const { storage, id = "table", include, exclude } = state.props.persist;
|
|
674
|
+
const data = {};
|
|
675
|
+
for (const key of KEYS) {
|
|
676
|
+
if ((!include || include.includes(key)) && !(exclude == null ? void 0 : exclude.includes(key))) {
|
|
677
|
+
if (key === "filterValues") {
|
|
678
|
+
data[key] = /* @__PURE__ */ new Map();
|
|
679
|
+
for (const [id2, value] of state.filterValues) {
|
|
680
|
+
if ((_b = (_a = state.filters.get(id2)) == null ? void 0 : _a.persist) != null ? _b : true) {
|
|
681
|
+
data.filterValues.set(id2, value);
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
} else {
|
|
685
|
+
data[key] = state[key];
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
return { storage, id, data };
|
|
690
|
+
}, (props) => {
|
|
691
|
+
var _a, _b;
|
|
692
|
+
if (!props)
|
|
693
|
+
return;
|
|
694
|
+
const { storage, id, data } = props;
|
|
695
|
+
(_b = (_a = table.getState().props).debug) == null ? void 0 : _b.call(_a, "save", data, stringify(data));
|
|
696
|
+
q.run(async () => {
|
|
697
|
+
await storage.setItem(`${id}_state`, stringify(data));
|
|
698
|
+
}, true);
|
|
699
|
+
}, { throttle: 1e3 });
|
|
700
|
+
}, [isHydrated]);
|
|
701
|
+
return isHydrated;
|
|
702
|
+
}
|
|
703
|
+
function calcItems(state) {
|
|
704
|
+
react.useEffect(() => state.addReaction((state2) => [
|
|
705
|
+
state2.props.items,
|
|
706
|
+
state2.props.id,
|
|
707
|
+
state2.props.parentId,
|
|
708
|
+
state2.props.revealFiltered,
|
|
709
|
+
state2.sort,
|
|
710
|
+
state2.filters,
|
|
711
|
+
state2.filterValues,
|
|
712
|
+
state2.activeColumns,
|
|
713
|
+
state2.expanded
|
|
714
|
+
], ([items = [], id, parentId, revealFiltered, sort, filters, filterValues, activeColumns], draft) => {
|
|
715
|
+
const tableItems = items.map((item) => __spreadProps(__spreadValues({}, item), {
|
|
716
|
+
id: id(item),
|
|
717
|
+
parentId: parentId == null ? void 0 : parentId(item),
|
|
718
|
+
children: []
|
|
719
|
+
}));
|
|
720
|
+
let sorted;
|
|
721
|
+
if (sort.length === 0) {
|
|
722
|
+
sorted = tableItems;
|
|
723
|
+
} else {
|
|
724
|
+
const selectors = flatMap(sort, (sort2) => {
|
|
725
|
+
const column = activeColumns.find((column2) => column2.id === sort2.columnId);
|
|
726
|
+
if (!column)
|
|
727
|
+
return [];
|
|
728
|
+
const sortBy = column.sortBy instanceof Array ? column.sortBy : [column.sortBy];
|
|
729
|
+
return sortBy.map((sortBy2) => ({ selector: (item) => sortBy2(column.value(item), item), direction: sort2.direction }));
|
|
730
|
+
}).filter(Boolean);
|
|
731
|
+
sorted = orderBy(tableItems, selectors.map((x) => x.selector), selectors.map((x) => x.direction));
|
|
732
|
+
}
|
|
733
|
+
const lookup = /* @__PURE__ */ new Map();
|
|
734
|
+
for (const item of sorted) {
|
|
735
|
+
lookup.set(item.id, item);
|
|
736
|
+
}
|
|
737
|
+
for (const item of sorted) {
|
|
738
|
+
const parent = item.parentId !== void 0 ? lookup.get(item.parentId) : void 0;
|
|
739
|
+
parent == null ? void 0 : parent.children.push(item);
|
|
740
|
+
}
|
|
741
|
+
const allItems = new Array();
|
|
742
|
+
const allItemsById = /* @__PURE__ */ new Map();
|
|
743
|
+
const traverse = (items2) => {
|
|
744
|
+
for (const item of items2) {
|
|
745
|
+
allItems.push(item);
|
|
746
|
+
allItemsById.set(item.id, item);
|
|
747
|
+
traverse(item.children);
|
|
748
|
+
}
|
|
749
|
+
};
|
|
750
|
+
traverse(sorted.filter((item) => item.parentId === void 0));
|
|
751
|
+
let expandedChanged = false;
|
|
752
|
+
const activeItemsById = /* @__PURE__ */ new Map();
|
|
753
|
+
const activeSet = /* @__PURE__ */ new Set();
|
|
754
|
+
const activeItems = [...allItems].reverse().filter((item) => {
|
|
755
|
+
let isActive = activeSet.has(item.id);
|
|
756
|
+
isActive || (isActive = activeColumns.every((column) => {
|
|
757
|
+
var _a;
|
|
758
|
+
const filter = filters.get(column.id);
|
|
759
|
+
if (!filter)
|
|
760
|
+
return true;
|
|
761
|
+
const filterValue = filterValues.get(column.id);
|
|
762
|
+
if (filterValue === void 0 || !filter.isActive(filterValue))
|
|
763
|
+
return true;
|
|
764
|
+
const filterBy = (_a = filter.filterBy) != null ? _a : (x) => x;
|
|
765
|
+
const value = filterBy(column.value(item), item);
|
|
766
|
+
return castArray(value).some((value2) => filter.test(filterValue, value2));
|
|
767
|
+
}));
|
|
768
|
+
if (isActive && item.parentId !== void 0) {
|
|
769
|
+
if (revealFiltered && Array.from(filters.entries()).some(([id2, filter]) => {
|
|
770
|
+
const filterValue = filterValues.get(id2);
|
|
771
|
+
return !!filter && filterValue !== void 0 && filter.isActive(filterValue);
|
|
772
|
+
})) {
|
|
773
|
+
expandedChanged || (expandedChanged = !draft.expanded.has(item.parentId));
|
|
774
|
+
draft.expanded.add(item.parentId);
|
|
775
|
+
} else if (!draft.expanded.has(item.parentId)) {
|
|
776
|
+
isActive = false;
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
if (isActive && item.parentId !== void 0) {
|
|
780
|
+
activeSet.add(item.parentId);
|
|
781
|
+
}
|
|
782
|
+
if (isActive) {
|
|
783
|
+
activeItemsById.set(item.id, item);
|
|
784
|
+
}
|
|
785
|
+
return isActive;
|
|
786
|
+
}).reverse();
|
|
787
|
+
draft.items = immer.castDraft(allItems);
|
|
788
|
+
draft.itemsById = immer.castDraft(allItemsById);
|
|
789
|
+
draft.activeItems = immer.castDraft(activeItems);
|
|
790
|
+
draft.activeItemsById = immer.castDraft(activeItemsById);
|
|
791
|
+
if (expandedChanged) {
|
|
792
|
+
setTimeout(() => {
|
|
793
|
+
var _a, _b;
|
|
794
|
+
(_b = (_a = state.getState().props).onExpandedChange) == null ? void 0 : _b.call(_a, state.getState().expanded);
|
|
795
|
+
});
|
|
796
|
+
}
|
|
797
|
+
}, { runNow: true }), [state]);
|
|
798
|
+
}
|
|
799
|
+
const noopParentId = () => void 0;
|
|
800
|
+
function calcProps(props) {
|
|
801
|
+
const columnCache = react.useRef(/* @__PURE__ */ new Map());
|
|
802
|
+
return react.useMemo(() => {
|
|
803
|
+
var _c, _d, _e, _f, _g, _h;
|
|
804
|
+
let id;
|
|
805
|
+
if (props.id instanceof Function) {
|
|
806
|
+
id = props.id;
|
|
807
|
+
} else {
|
|
808
|
+
id = (item) => item[props.id];
|
|
809
|
+
}
|
|
810
|
+
let parentId;
|
|
811
|
+
if (props.parentId instanceof Function) {
|
|
812
|
+
parentId = props.parentId;
|
|
813
|
+
} else if (typeof props.parentId === "string") {
|
|
814
|
+
parentId = (item) => item[props.parentId];
|
|
815
|
+
} else {
|
|
816
|
+
parentId = noopParentId;
|
|
817
|
+
}
|
|
818
|
+
let inputColumns;
|
|
819
|
+
if (props.columns instanceof Function) {
|
|
820
|
+
inputColumns = props.columns((value, column) => __spreadProps(__spreadValues({}, column), { value }));
|
|
821
|
+
} else {
|
|
822
|
+
inputColumns = props.columns.map((column) => __spreadProps(__spreadValues({}, column), { dependecies: void 0 }));
|
|
823
|
+
}
|
|
824
|
+
const newColumnCache = /* @__PURE__ */ new Map();
|
|
825
|
+
const columns = inputColumns.map(function(_a, index) {
|
|
826
|
+
var _b = _a, {
|
|
827
|
+
id: id2,
|
|
828
|
+
header = null,
|
|
829
|
+
renderCell = asString,
|
|
830
|
+
exportCell = asString,
|
|
831
|
+
sortBy = (v) => typeof v === "number" || v instanceof Date ? v : String(v),
|
|
832
|
+
dependencies = []
|
|
833
|
+
} = _b, props2 = __objRest(_b, [
|
|
834
|
+
"id",
|
|
835
|
+
"header",
|
|
836
|
+
"renderCell",
|
|
837
|
+
"exportCell",
|
|
838
|
+
"sortBy",
|
|
839
|
+
"dependencies"
|
|
840
|
+
]);
|
|
841
|
+
var _a2;
|
|
842
|
+
const [depsInCache, columnInCache] = (_a2 = columnCache.current.get(id2 != null ? id2 : index)) != null ? _a2 : [];
|
|
843
|
+
let column;
|
|
844
|
+
if (depsInCache && columnInCache && depsInCache.length === dependencies.length && depsInCache.every((x, i) => dependencies[i] === x)) {
|
|
845
|
+
column = columnInCache;
|
|
846
|
+
} else {
|
|
847
|
+
column = __spreadValues({
|
|
848
|
+
id: id2 != null ? id2 : index,
|
|
849
|
+
header,
|
|
850
|
+
renderCell,
|
|
851
|
+
exportCell,
|
|
852
|
+
sortBy,
|
|
853
|
+
dependencies
|
|
854
|
+
}, props2);
|
|
855
|
+
}
|
|
856
|
+
newColumnCache.set(id2 != null ? id2 : index, [dependencies, column]);
|
|
857
|
+
return column;
|
|
858
|
+
});
|
|
859
|
+
columnCache.current = newColumnCache;
|
|
860
|
+
let copy;
|
|
861
|
+
if (props.enableExport === true || props.enableExport instanceof Object && props.enableExport.copy === true) {
|
|
862
|
+
copy = { separator: " " };
|
|
863
|
+
} else if (props.enableExport && props.enableExport.copy instanceof Object) {
|
|
864
|
+
copy = props.enableExport.copy;
|
|
865
|
+
}
|
|
866
|
+
let download;
|
|
867
|
+
if (props.enableExport === true || props.enableExport instanceof Object && props.enableExport.download === true) {
|
|
868
|
+
download = { sepPrefix: true };
|
|
869
|
+
} else if (props.enableExport && props.enableExport.download instanceof Object) {
|
|
870
|
+
download = props.enableExport.download;
|
|
871
|
+
}
|
|
872
|
+
const enableExport = { copy, download };
|
|
873
|
+
return __spreadProps(__spreadValues({}, props), {
|
|
874
|
+
id,
|
|
875
|
+
parentId,
|
|
876
|
+
columns,
|
|
877
|
+
enableSelection: (_c = props.enableSelection) != null ? _c : true,
|
|
878
|
+
selectSyncChildren: (_d = props.selectSyncChildren) != null ? _d : true,
|
|
879
|
+
stickyHeader: (_e = props.stickyHeader) != null ? _e : true,
|
|
880
|
+
enableExport,
|
|
881
|
+
enableColumnSelection: (_f = props.enableColumnSelection) != null ? _f : true,
|
|
882
|
+
enableColumnResize: (_g = props.enableColumnResize) != null ? _g : true,
|
|
883
|
+
enableColumnReorder: (_h = props.enableColumnReorder) != null ? _h : true
|
|
884
|
+
});
|
|
885
|
+
}, [props]);
|
|
886
|
+
}
|
|
887
|
+
function cleanupState(state) {
|
|
888
|
+
react.useEffect(() => state.addReaction((state2) => [state2.props.columns, state2.itemsById, state2.activeItemsById, state2.activeColumns], ([columns, itemsById, activeItemsById, activeColumns], draft) => {
|
|
889
|
+
var _a, _b, _c, _d, _e, _f;
|
|
890
|
+
const columnIds = new Set(columns.map((column) => column.id));
|
|
891
|
+
const activeColumnIds = new Set(activeColumns.map((column) => column.id));
|
|
892
|
+
const newSort = draft.sort.filter((s) => activeColumnIds.has(s.columnId));
|
|
893
|
+
if (newSort.length < draft.sort.length) {
|
|
894
|
+
draft.sort = newSort;
|
|
895
|
+
(_b = (_a = draft.props).onSortChange) == null ? void 0 : _b.call(_a, newSort);
|
|
896
|
+
}
|
|
897
|
+
for (const id of draft.filters.keys()) {
|
|
898
|
+
if (!activeColumnIds.has(id))
|
|
899
|
+
draft.filters.delete(id);
|
|
900
|
+
}
|
|
901
|
+
for (const id of draft.filterValues.keys()) {
|
|
902
|
+
if (!activeColumnIds.has(id))
|
|
903
|
+
draft.filterValues.delete(id);
|
|
904
|
+
}
|
|
905
|
+
for (const id of draft.hiddenColumns.keys()) {
|
|
906
|
+
if (!columnIds.has(id))
|
|
907
|
+
draft.hiddenColumns.delete(id);
|
|
908
|
+
}
|
|
909
|
+
for (const id of draft.columnWidths.keys()) {
|
|
910
|
+
if (!columnIds.has(id))
|
|
911
|
+
draft.columnWidths.delete(id);
|
|
912
|
+
}
|
|
913
|
+
for (const id of draft.columnOrder) {
|
|
914
|
+
if (!columnIds.has(id))
|
|
915
|
+
draft.columnOrder = draft.columnOrder.filter((x) => x !== id);
|
|
916
|
+
}
|
|
917
|
+
if (draft.props.items) {
|
|
918
|
+
const newSelection = intersect(draft.selection, activeItemsById);
|
|
919
|
+
if (newSelection.size !== draft.selection.size) {
|
|
920
|
+
draft.selection = newSelection;
|
|
921
|
+
(_d = (_c = draft.props).onSelectionChange) == null ? void 0 : _d.call(_c, newSelection);
|
|
922
|
+
}
|
|
923
|
+
const newExpanded = intersect(draft.expanded, itemsById);
|
|
924
|
+
if (newExpanded.size < draft.expanded.size) {
|
|
925
|
+
draft.expanded = newExpanded;
|
|
926
|
+
(_f = (_e = draft.props).onExpandedChange) == null ? void 0 : _f.call(_e, newExpanded);
|
|
927
|
+
}
|
|
928
|
+
}
|
|
929
|
+
}, { runNow: true }), [state]);
|
|
930
|
+
}
|
|
931
|
+
function filterColumns(state) {
|
|
932
|
+
react.useEffect(() => state.addReaction((state2) => [state2.props.columns, state2.hiddenColumns, state2.columnOrder], ([columns, hiddenColumns, columnOrder], draft) => {
|
|
933
|
+
draft.activeColumns = orderBy(columns.filter((column) => !hiddenColumns.has(column.id)), [(column) => columnOrder.indexOf(column.id)]);
|
|
934
|
+
}, { runNow: true }), [state]);
|
|
935
|
+
}
|
|
936
|
+
function syncSelections(state) {
|
|
937
|
+
react.useEffect(() => state.addReaction((state2) => [state2.props.selectSyncChildren, state2.selection, state2.activeItems], ([selectSyncChildren, selection, activeItems], state2) => {
|
|
938
|
+
var _a, _b;
|
|
939
|
+
if (!selectSyncChildren)
|
|
940
|
+
return;
|
|
941
|
+
const newSelection = new Set(selection);
|
|
942
|
+
for (const item of activeItems) {
|
|
943
|
+
if (item.parentId !== void 0 && newSelection.has(item.parentId)) {
|
|
944
|
+
newSelection.add(item.id);
|
|
945
|
+
}
|
|
946
|
+
}
|
|
947
|
+
if (newSelection.size !== selection.size) {
|
|
948
|
+
state2.selection = newSelection;
|
|
949
|
+
(_b = (_a = state2.props).onSelectionChange) == null ? void 0 : _b.call(_a, newSelection);
|
|
950
|
+
}
|
|
951
|
+
}, { runNow: true }), [state]);
|
|
952
|
+
}
|
|
953
|
+
function useTableState(_props) {
|
|
954
|
+
const props = calcProps(_props);
|
|
955
|
+
const theme = tableTheme.useTableTheme(props);
|
|
956
|
+
const state = react.useMemo(() => {
|
|
957
|
+
var _a, _b, _c, _d;
|
|
958
|
+
return new react$1.Store({
|
|
959
|
+
props,
|
|
960
|
+
theme,
|
|
961
|
+
sort: (_a = props.defaultSort) != null ? _a : [],
|
|
962
|
+
selection: (_b = props.defaultSelection) != null ? _b : /* @__PURE__ */ new Set(),
|
|
963
|
+
expanded: (_c = props.defaultExpanded) != null ? _c : /* @__PURE__ */ new Set(),
|
|
964
|
+
rowHeights: /* @__PURE__ */ new Map(),
|
|
965
|
+
filters: /* @__PURE__ */ new Map(),
|
|
966
|
+
filterValues: /* @__PURE__ */ new Map(),
|
|
967
|
+
hiddenColumns: (_d = props.defaultHiddenColumns) != null ? _d : /* @__PURE__ */ new Set(),
|
|
968
|
+
columnWidths: /* @__PURE__ */ new Map(),
|
|
969
|
+
columnOrder: props.columns.map((column) => column.id),
|
|
970
|
+
columnStyleOverride: /* @__PURE__ */ new Map(),
|
|
971
|
+
activeColumns: [],
|
|
972
|
+
items: [],
|
|
973
|
+
itemsById: /* @__PURE__ */ new Map(),
|
|
974
|
+
activeItems: [],
|
|
975
|
+
activeItemsById: /* @__PURE__ */ new Map(),
|
|
976
|
+
lastSelectedId: void 0
|
|
977
|
+
});
|
|
978
|
+
}, []);
|
|
979
|
+
filterColumns(state);
|
|
980
|
+
calcItems(state);
|
|
981
|
+
syncSelections(state);
|
|
982
|
+
cleanupState(state);
|
|
983
|
+
react.useEffect(() => {
|
|
984
|
+
state.update((state2) => {
|
|
985
|
+
state2.props = immer.castDraft(props);
|
|
986
|
+
if (props.sort)
|
|
987
|
+
state2.sort = props.sort;
|
|
988
|
+
if (props.selection)
|
|
989
|
+
state2.selection = props.selection;
|
|
990
|
+
if (props.expanded)
|
|
991
|
+
state2.expanded = props.expanded;
|
|
992
|
+
if (props.hiddenColumns)
|
|
993
|
+
state2.hiddenColumns = props.hiddenColumns;
|
|
994
|
+
for (const column of props.columns) {
|
|
995
|
+
if (!state2.columnOrder.includes(column.id)) {
|
|
996
|
+
const index = props.columns.indexOf(column);
|
|
997
|
+
state2.columnOrder.splice(index, 0, column.id);
|
|
998
|
+
}
|
|
999
|
+
}
|
|
1000
|
+
state2.theme = theme;
|
|
1001
|
+
});
|
|
1002
|
+
}, [state, props]);
|
|
1003
|
+
return state;
|
|
1004
|
+
}
|
|
1005
|
+
const ColumnHeaderContext = new react$1.StoreScope({
|
|
1006
|
+
items: /* @__PURE__ */ new Map()
|
|
1007
|
+
});
|
|
1008
|
+
function ColumnHeader(props) {
|
|
1009
|
+
const ref = react.useRef(null);
|
|
1010
|
+
const columnId = useColumnContext();
|
|
1011
|
+
const table = useTableContext();
|
|
1012
|
+
const enabled = table.useState("props.enableColumnReorder");
|
|
1013
|
+
const store = ColumnHeaderContext.useStore();
|
|
1014
|
+
const draggingStart = react.useRef();
|
|
1015
|
+
const clone = react.useRef();
|
|
1016
|
+
react.useEffect(() => {
|
|
1017
|
+
const div = ref.current;
|
|
1018
|
+
if (!div)
|
|
1019
|
+
return;
|
|
1020
|
+
store.update((state) => {
|
|
1021
|
+
state.items.set(columnId, immer.castDraft(div));
|
|
1022
|
+
});
|
|
1023
|
+
return () => {
|
|
1024
|
+
store.update((state) => {
|
|
1025
|
+
state.items.delete(columnId);
|
|
1026
|
+
});
|
|
1027
|
+
};
|
|
1028
|
+
}, [ref.current, store, columnId]);
|
|
1029
|
+
function calcTargetIndex(offsetLeft) {
|
|
1030
|
+
var _a, _b, _c;
|
|
1031
|
+
const cols = table.getState().columnOrder.map((id) => ({
|
|
1032
|
+
id,
|
|
1033
|
+
div: store.getState().items.get(id)
|
|
1034
|
+
}));
|
|
1035
|
+
const otherCols = cols.filter((col) => col.id !== columnId);
|
|
1036
|
+
const firstOffsetleft = (_c = (_b = (_a = cols.find((col) => col.div)) == null ? void 0 : _a.div) == null ? void 0 : _b.offsetLeft) != null ? _c : 0;
|
|
1037
|
+
let sum = 0;
|
|
1038
|
+
const targetIndex = otherCols.findIndex((col) => {
|
|
1039
|
+
var _a2, _b2;
|
|
1040
|
+
const width = (_b2 = (_a2 = col.div) == null ? void 0 : _a2.offsetWidth) != null ? _b2 : 0;
|
|
1041
|
+
if (sum + width / 2 > offsetLeft - firstOffsetleft)
|
|
1042
|
+
return true;
|
|
1043
|
+
sum += width;
|
|
1044
|
+
return false;
|
|
1045
|
+
});
|
|
1046
|
+
return targetIndex === -1 ? otherCols.length : targetIndex;
|
|
1047
|
+
}
|
|
1048
|
+
function onPointerDown(e) {
|
|
1049
|
+
const div = ref.current;
|
|
1050
|
+
if (!div)
|
|
1051
|
+
return;
|
|
1052
|
+
draggingStart.current = {
|
|
1053
|
+
mouseX: e.clientX,
|
|
1054
|
+
bounds: div.getBoundingClientRect()
|
|
1055
|
+
};
|
|
1056
|
+
}
|
|
1057
|
+
function onPointerMove(e) {
|
|
1058
|
+
table.update((state) => {
|
|
1059
|
+
const div = ref.current;
|
|
1060
|
+
if (!div || draggingStart.current === void 0 || Math.abs(e.clientX - draggingStart.current.mouseX) < 5)
|
|
1061
|
+
return;
|
|
1062
|
+
e.stopPropagation();
|
|
1063
|
+
div.setPointerCapture(e.pointerId);
|
|
1064
|
+
if (!clone.current) {
|
|
1065
|
+
clone.current = div.cloneNode(true);
|
|
1066
|
+
document.body.append(clone.current);
|
|
1067
|
+
for (const [key, value] of Object.entries(getComputedStyle(div))) {
|
|
1068
|
+
try {
|
|
1069
|
+
clone.current.style[key] = value;
|
|
1070
|
+
} catch {
|
|
1071
|
+
}
|
|
1072
|
+
}
|
|
1073
|
+
Object.assign(clone.current.style, {
|
|
1074
|
+
pointerEvents: "none",
|
|
1075
|
+
position: "fixed",
|
|
1076
|
+
boxShadow: "0px 5px 5px -3px rgb(0 0 0 / 20%), 0px 8px 10px 1px rgb(0 0 0 / 14%), 0px 3px 14px 2px rgb(0 0 0 / 12%)",
|
|
1077
|
+
left: `${draggingStart.current.bounds.left}px`,
|
|
1078
|
+
top: `${draggingStart.current.bounds.top}px`
|
|
1079
|
+
});
|
|
1080
|
+
div.style.color = "rgba(0, 0, 0, 0.2)";
|
|
1081
|
+
}
|
|
1082
|
+
clone.current.style.left = `${draggingStart.current.bounds.left + e.clientX - draggingStart.current.mouseX}px`;
|
|
1083
|
+
const index = state.columnOrder.indexOf(columnId);
|
|
1084
|
+
const targetIndex = calcTargetIndex(div.offsetLeft + e.clientX - draggingStart.current.mouseX);
|
|
1085
|
+
const columns = table.getState().columnOrder.map((id, index2) => {
|
|
1086
|
+
var _a, _b;
|
|
1087
|
+
return {
|
|
1088
|
+
id,
|
|
1089
|
+
index: index2,
|
|
1090
|
+
width: (_b = (_a = store.getState().items.get(id)) == null ? void 0 : _a.offsetWidth) != null ? _b : 0
|
|
1091
|
+
};
|
|
1092
|
+
});
|
|
1093
|
+
state.columnOrder.forEach((id, i) => {
|
|
1094
|
+
let offset = 0;
|
|
1095
|
+
if (i === index) {
|
|
1096
|
+
if (targetIndex > index) {
|
|
1097
|
+
offset = columns.slice(index + 1, targetIndex + 1).reduce((sum, col) => sum + col.width, 0);
|
|
1098
|
+
} else if (targetIndex < index) {
|
|
1099
|
+
offset = -columns.slice(targetIndex, index).reduce((sum, col) => sum + col.width, 0);
|
|
1100
|
+
}
|
|
1101
|
+
} else if (i >= targetIndex && i < index) {
|
|
1102
|
+
offset = div.offsetWidth;
|
|
1103
|
+
} else if (i > index && i <= targetIndex) {
|
|
1104
|
+
offset = -div.offsetWidth;
|
|
1105
|
+
}
|
|
1106
|
+
state.columnStyleOverride.set(id, {
|
|
1107
|
+
transition: "transform 500ms",
|
|
1108
|
+
transform: `translate3d(${offset}px, 0, 0)`,
|
|
1109
|
+
zIndex: i === index ? 1 : void 0
|
|
1110
|
+
});
|
|
1111
|
+
});
|
|
1112
|
+
});
|
|
1113
|
+
}
|
|
1114
|
+
function onPointerUp(e) {
|
|
1115
|
+
table.update((state) => {
|
|
1116
|
+
var _a;
|
|
1117
|
+
const div = ref.current;
|
|
1118
|
+
if (!div || draggingStart.current === void 0)
|
|
1119
|
+
return;
|
|
1120
|
+
const index = state.columnOrder.indexOf(columnId);
|
|
1121
|
+
const targetIndex = calcTargetIndex(div.offsetLeft + e.clientX - draggingStart.current.mouseX);
|
|
1122
|
+
state.columnOrder.splice(index, 1);
|
|
1123
|
+
state.columnOrder.splice(targetIndex, 0, columnId);
|
|
1124
|
+
(_a = clone.current) == null ? void 0 : _a.remove();
|
|
1125
|
+
div.style.color = "";
|
|
1126
|
+
state.columnStyleOverride.clear();
|
|
1127
|
+
draggingStart.current = void 0;
|
|
1128
|
+
clone.current = void 0;
|
|
1129
|
+
});
|
|
1130
|
+
}
|
|
1131
|
+
return jsxRuntime.jsx("div", __spreadProps(__spreadValues({}, props), {
|
|
1132
|
+
css: {
|
|
1133
|
+
position: "relative",
|
|
1134
|
+
userSelect: "none"
|
|
1135
|
+
},
|
|
1136
|
+
ref,
|
|
1137
|
+
onPointerDown: enabled ? onPointerDown : void 0,
|
|
1138
|
+
onPointerMove: enabled ? onPointerMove : void 0,
|
|
1139
|
+
onPointerUp: enabled ? onPointerUp : void 0,
|
|
1140
|
+
children: props.children
|
|
1141
|
+
}));
|
|
1142
|
+
}
|
|
1143
|
+
function ColumnSelection() {
|
|
1144
|
+
const {
|
|
1145
|
+
components: {
|
|
1146
|
+
IconButton,
|
|
1147
|
+
Popover,
|
|
1148
|
+
Checkbox
|
|
1149
|
+
},
|
|
1150
|
+
icons: {
|
|
1151
|
+
Settings
|
|
1152
|
+
},
|
|
1153
|
+
text
|
|
1154
|
+
} = useTheme();
|
|
1155
|
+
const cssVariables = useCssVariables();
|
|
1156
|
+
const table = useTableContext();
|
|
1157
|
+
const columns = table.useState("props.columns");
|
|
1158
|
+
const hiddenColumns = table.useState("hiddenColumns");
|
|
1159
|
+
const [anchorEl, setAnchorEl] = react.useState(null);
|
|
1160
|
+
const toggle2 = (column) => {
|
|
1161
|
+
const {
|
|
1162
|
+
props: {
|
|
1163
|
+
hiddenColumns: controlledHiddenColumns,
|
|
1164
|
+
onHiddenColumnsChange
|
|
1165
|
+
}
|
|
1166
|
+
} = table.getState();
|
|
1167
|
+
const newValue = new Set(hiddenColumns);
|
|
1168
|
+
if (hiddenColumns.has(column.id))
|
|
1169
|
+
newValue.delete(column.id);
|
|
1170
|
+
else
|
|
1171
|
+
newValue.add(column.id);
|
|
1172
|
+
if (!controlledHiddenColumns) {
|
|
1173
|
+
table.update((state) => {
|
|
1174
|
+
state.hiddenColumns = newValue;
|
|
1175
|
+
});
|
|
1176
|
+
}
|
|
1177
|
+
onHiddenColumnsChange == null ? void 0 : onHiddenColumnsChange(newValue);
|
|
1178
|
+
};
|
|
1179
|
+
return jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
|
1180
|
+
children: [jsxRuntime.jsx(IconButton, {
|
|
1181
|
+
onClick: (e) => setAnchorEl(anchorEl ? null : e.currentTarget),
|
|
1182
|
+
children: jsxRuntime.jsx(Settings, {})
|
|
1183
|
+
}), jsxRuntime.jsx(Popover, {
|
|
1184
|
+
anchorEl,
|
|
1185
|
+
open: !!anchorEl,
|
|
1186
|
+
onClose: () => setAnchorEl(null),
|
|
1187
|
+
css: cssVariables,
|
|
1188
|
+
children: jsxRuntime.jsxs("div", {
|
|
1189
|
+
css: {
|
|
1190
|
+
padding: `calc(var(--spacing) * 2)`,
|
|
1191
|
+
display: "grid"
|
|
1192
|
+
},
|
|
1193
|
+
children: [jsxRuntime.jsx("div", {
|
|
1194
|
+
css: {
|
|
1195
|
+
marginBottom: "var(--spacing)"
|
|
1196
|
+
},
|
|
1197
|
+
children: text.selectColumns
|
|
1198
|
+
}), columns.map((column) => jsxRuntime.jsx(FormControlLabel, {
|
|
1199
|
+
control: jsxRuntime.jsx(Checkbox, {
|
|
1200
|
+
checked: !hiddenColumns.has(column.id),
|
|
1201
|
+
onChange: () => toggle2(column),
|
|
1202
|
+
disabled: column.cannotHide
|
|
1203
|
+
}),
|
|
1204
|
+
label: column.header
|
|
1205
|
+
}, column.id))]
|
|
1206
|
+
})
|
|
1207
|
+
})]
|
|
1208
|
+
});
|
|
1209
|
+
}
|
|
1210
|
+
function csvExport(data, { sepPrefix, separator = ",", quote = '"', eol = "\n" } = {}) {
|
|
1211
|
+
const cells = data.map((line) => line.map((value) => {
|
|
1212
|
+
if (typeof value === "number")
|
|
1213
|
+
return String(value);
|
|
1214
|
+
if (![separator, quote, eol].some((c) => value.includes(c)))
|
|
1215
|
+
return value;
|
|
1216
|
+
const clean = value.replace(new RegExp(quote, "g"), `${quote}${quote}`);
|
|
1217
|
+
return `${quote}${clean}${quote}`;
|
|
1218
|
+
}));
|
|
1219
|
+
return (sepPrefix ? `SEP=${separator}
|
|
1220
|
+
` : "") + cells.map((line) => line.join(separator)).join(eol);
|
|
1221
|
+
}
|
|
1222
|
+
function Export() {
|
|
1223
|
+
const table = useTableContext();
|
|
1224
|
+
const {
|
|
1225
|
+
components: {
|
|
1226
|
+
Button,
|
|
1227
|
+
IconButton,
|
|
1228
|
+
Popover
|
|
1229
|
+
},
|
|
1230
|
+
icons: {
|
|
1231
|
+
Export: Export2,
|
|
1232
|
+
Clipboard
|
|
1233
|
+
},
|
|
1234
|
+
text
|
|
1235
|
+
} = useTheme();
|
|
1236
|
+
const cssVariables = useCssVariables();
|
|
1237
|
+
const [anchor, setAnchor] = react.useState(null);
|
|
1238
|
+
const generate = (options) => {
|
|
1239
|
+
const {
|
|
1240
|
+
activeColumns,
|
|
1241
|
+
activeItems
|
|
1242
|
+
} = table.getState();
|
|
1243
|
+
const data = [activeColumns.map((column) => String(column.id)), ...activeItems.map((item) => activeColumns.map((column) => column.exportCell(column.value(item), item)))];
|
|
1244
|
+
return csvExport(data, options);
|
|
1245
|
+
};
|
|
1246
|
+
const copy = () => {
|
|
1247
|
+
navigator.clipboard.writeText(generate(table.getState().props.enableExport.copy));
|
|
1248
|
+
};
|
|
1249
|
+
const download = () => {
|
|
1250
|
+
const a = document.createElement("a");
|
|
1251
|
+
a.href = "data:text/csv;charset=utf-8," + encodeURIComponent(generate(table.getState().props.enableExport.download));
|
|
1252
|
+
a.download = "export.csv";
|
|
1253
|
+
document.body.appendChild(a);
|
|
1254
|
+
a.click();
|
|
1255
|
+
document.body.removeChild(a);
|
|
1256
|
+
};
|
|
1257
|
+
return jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
|
1258
|
+
children: [jsxRuntime.jsx(IconButton, {
|
|
1259
|
+
onClick: (e) => setAnchor(anchor ? null : e.currentTarget),
|
|
1260
|
+
children: jsxRuntime.jsx(Export2, {})
|
|
1261
|
+
}), jsxRuntime.jsx(Popover, {
|
|
1262
|
+
open: !!anchor,
|
|
1263
|
+
onClose: () => setAnchor(null),
|
|
1264
|
+
anchorEl: anchor,
|
|
1265
|
+
css: cssVariables,
|
|
1266
|
+
children: jsxRuntime.jsxs("div", {
|
|
1267
|
+
css: {
|
|
1268
|
+
padding: `calc(var(--spacing) * 2)`,
|
|
1269
|
+
display: "grid",
|
|
1270
|
+
justifyItems: "stretch",
|
|
1271
|
+
gap: "var(--spacing)",
|
|
1272
|
+
"& > *": {
|
|
1273
|
+
justifyContent: "start"
|
|
1274
|
+
}
|
|
1275
|
+
},
|
|
1276
|
+
children: [jsxRuntime.jsx("div", {
|
|
1277
|
+
css: {
|
|
1278
|
+
marginBottom: "var(--spacing)"
|
|
1279
|
+
},
|
|
1280
|
+
children: text.exportTitle
|
|
1281
|
+
}), jsxRuntime.jsx(Button, {
|
|
1282
|
+
startIcon: jsxRuntime.jsx(Clipboard, {}),
|
|
1283
|
+
onClick: copy,
|
|
1284
|
+
children: text.exportCopy
|
|
1285
|
+
}), jsxRuntime.jsx(Button, {
|
|
1286
|
+
startIcon: jsxRuntime.jsx(Export2, {}),
|
|
1287
|
+
onClick: download,
|
|
1288
|
+
children: text.exportDownload
|
|
1289
|
+
})]
|
|
1290
|
+
})
|
|
1291
|
+
})]
|
|
1292
|
+
});
|
|
1293
|
+
}
|
|
1294
|
+
function useTheme() {
|
|
1295
|
+
const table = useTableContext();
|
|
1296
|
+
return table.useState("theme");
|
|
1297
|
+
}
|
|
1298
|
+
function FilterControl() {
|
|
1299
|
+
const table = useTableContext();
|
|
1300
|
+
const columnId = useColumnContext();
|
|
1301
|
+
const {
|
|
1302
|
+
components: {
|
|
1303
|
+
IconButton,
|
|
1304
|
+
Popover
|
|
1305
|
+
},
|
|
1306
|
+
icons: {
|
|
1307
|
+
FilterList,
|
|
1308
|
+
ArrowDropDown
|
|
1309
|
+
}
|
|
1310
|
+
} = useTheme();
|
|
1311
|
+
const cssVariables = useCssVariables();
|
|
1312
|
+
const [anchor, setAnchor] = react.useState(null);
|
|
1313
|
+
const isActive = table.useState((state) => {
|
|
1314
|
+
const filter2 = state.filters.get(columnId);
|
|
1315
|
+
const filterValue = state.filterValues.get(columnId);
|
|
1316
|
+
return filter2 !== void 0 && filterValue !== void 0 && filter2.isActive(filterValue);
|
|
1317
|
+
});
|
|
1318
|
+
const filter = table.useState((state) => {
|
|
1319
|
+
var _a;
|
|
1320
|
+
return (_a = state.activeColumns.find((column) => column.id === columnId)) == null ? void 0 : _a.filter;
|
|
1321
|
+
});
|
|
1322
|
+
if (!filter)
|
|
1323
|
+
return null;
|
|
1324
|
+
return jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
|
1325
|
+
children: [jsxRuntime.jsx(IconButton, {
|
|
1326
|
+
onClick: (e) => setAnchor(e.currentTarget),
|
|
1327
|
+
css: [isActive && {
|
|
1328
|
+
color: "white !important",
|
|
1329
|
+
backgroundColor: "var(--primaryMain) !important"
|
|
1330
|
+
}],
|
|
1331
|
+
children: isActive ? jsxRuntime.jsx(FilterList, {}) : jsxRuntime.jsx(ArrowDropDown, {})
|
|
1332
|
+
}), jsxRuntime.jsx("div", {
|
|
1333
|
+
onPointerDown: (e) => {
|
|
1334
|
+
e.stopPropagation();
|
|
1335
|
+
},
|
|
1336
|
+
onPointerMove: (e) => {
|
|
1337
|
+
e.stopPropagation();
|
|
1338
|
+
},
|
|
1339
|
+
children: jsxRuntime.jsx(Popover, {
|
|
1340
|
+
open: true,
|
|
1341
|
+
hidden: !anchor,
|
|
1342
|
+
onClose: () => setAnchor(null),
|
|
1343
|
+
anchorEl: anchor != null ? anchor : document.body,
|
|
1344
|
+
css: cssVariables,
|
|
1345
|
+
children: filter
|
|
1346
|
+
})
|
|
1347
|
+
})]
|
|
1348
|
+
});
|
|
1349
|
+
}
|
|
1350
|
+
function ResizeHandle() {
|
|
1351
|
+
const table = useTableContext();
|
|
1352
|
+
const columnId = useColumnContext();
|
|
1353
|
+
const enabled = table.useState("props.enableColumnResize");
|
|
1354
|
+
function onPointerDown(e) {
|
|
1355
|
+
e.stopPropagation();
|
|
1356
|
+
const div = e.target;
|
|
1357
|
+
div.setPointerCapture(e.pointerId);
|
|
1358
|
+
}
|
|
1359
|
+
function onPointerMove(e) {
|
|
1360
|
+
e.stopPropagation();
|
|
1361
|
+
const div = e.target;
|
|
1362
|
+
if (!div.hasPointerCapture(e.pointerId))
|
|
1363
|
+
return;
|
|
1364
|
+
const parent = div.parentElement;
|
|
1365
|
+
const width = Math.max(e.clientX - parent.getBoundingClientRect().left + 5, 50);
|
|
1366
|
+
table.update((state) => {
|
|
1367
|
+
state.columnWidths.set(columnId, `${width}px`);
|
|
1368
|
+
});
|
|
1369
|
+
}
|
|
1370
|
+
function onPointerUp(e) {
|
|
1371
|
+
e.stopPropagation();
|
|
1372
|
+
const div = e.target;
|
|
1373
|
+
div.releasePointerCapture(e.pointerId);
|
|
1374
|
+
}
|
|
1375
|
+
function onDoubleClick(e) {
|
|
1376
|
+
table.update((state) => {
|
|
1377
|
+
if (e.getModifierState("Control")) {
|
|
1378
|
+
state.columnWidths.delete(columnId);
|
|
1379
|
+
} else {
|
|
1380
|
+
state.columnWidths.set(columnId, "max-content");
|
|
1381
|
+
}
|
|
1382
|
+
});
|
|
1383
|
+
}
|
|
1384
|
+
return jsxRuntime.jsx("div", {
|
|
1385
|
+
css: {
|
|
1386
|
+
alignSelf: "stretch",
|
|
1387
|
+
padding: "0 5px",
|
|
1388
|
+
cursor: enabled ? "col-resize" : "initial",
|
|
1389
|
+
display: "flex",
|
|
1390
|
+
alignItems: "center",
|
|
1391
|
+
"&:after": {
|
|
1392
|
+
content: '""',
|
|
1393
|
+
width: 1,
|
|
1394
|
+
height: "1.2em",
|
|
1395
|
+
background: "currentColor",
|
|
1396
|
+
transition: "transform 300ms"
|
|
1397
|
+
}
|
|
1398
|
+
},
|
|
1399
|
+
onPointerDown: enabled ? onPointerDown : void 0,
|
|
1400
|
+
onPointerMove: enabled ? onPointerMove : void 0,
|
|
1401
|
+
onPointerUp: enabled ? onPointerUp : void 0,
|
|
1402
|
+
onDoubleClick: enabled ? onDoubleClick : void 0
|
|
1403
|
+
});
|
|
1404
|
+
}
|
|
1405
|
+
const Cell = react.memo(function Cell2({
|
|
1406
|
+
itemId,
|
|
1407
|
+
rowIndex
|
|
1408
|
+
}) {
|
|
1409
|
+
var _a, _b;
|
|
1410
|
+
const table = useTableContext();
|
|
1411
|
+
const columnId = useColumnContext();
|
|
1412
|
+
const {
|
|
1413
|
+
classes
|
|
1414
|
+
} = useTheme();
|
|
1415
|
+
const column = table.useState((state) => state.activeColumns.find((column2) => column2.id === columnId));
|
|
1416
|
+
const item = table.useState((state) => state.activeItemsById.get(itemId));
|
|
1417
|
+
const columnStyleOverride = table.useState((state) => state.columnStyleOverride.get(columnId), {
|
|
1418
|
+
throttle: 16
|
|
1419
|
+
});
|
|
1420
|
+
if (!column || !item)
|
|
1421
|
+
return null;
|
|
1422
|
+
(_b = (_a = table.getState().props).debugRender) == null ? void 0 : _b.call(_a, "render cell", itemId, columnId);
|
|
1423
|
+
const classNames = [...calcClassNames(classes, item, rowIndex), ...calcClassNames(column == null ? void 0 : column.classes, item, rowIndex)];
|
|
1424
|
+
const content = column.renderCell(column.value(item), item);
|
|
1425
|
+
return jsxRuntime.jsx("div", {
|
|
1426
|
+
className: cx(...classNames),
|
|
1427
|
+
css: [tableTheme.defaultClasses.cell, classNames, columnStyleOverride],
|
|
1428
|
+
children: typeof content === "string" ? jsxRuntime.jsx("span", {
|
|
1429
|
+
css: tableTheme.defaultClasses.text,
|
|
1430
|
+
title: content,
|
|
1431
|
+
children: content
|
|
1432
|
+
}) : content
|
|
1433
|
+
});
|
|
1434
|
+
});
|
|
1435
|
+
function ExpandControl({
|
|
1436
|
+
itemId,
|
|
1437
|
+
hasDeferredChildren
|
|
1438
|
+
}) {
|
|
1439
|
+
const {
|
|
1440
|
+
components: {
|
|
1441
|
+
IconButton,
|
|
1442
|
+
Spinner
|
|
1443
|
+
},
|
|
1444
|
+
icons: {
|
|
1445
|
+
ChevronRight
|
|
1446
|
+
}
|
|
1447
|
+
} = useTheme();
|
|
1448
|
+
const table = useTableContext();
|
|
1449
|
+
const isExpanded = table.useState((state) => state.expanded.has(itemId));
|
|
1450
|
+
const hasChildren = table.useState((state) => {
|
|
1451
|
+
var _a;
|
|
1452
|
+
return !!((_a = state.activeItemsById.get(itemId)) == null ? void 0 : _a.children.length);
|
|
1453
|
+
});
|
|
1454
|
+
function toggle2() {
|
|
1455
|
+
const {
|
|
1456
|
+
props: {
|
|
1457
|
+
expanded: controlledExpanded,
|
|
1458
|
+
expandOnlyOne,
|
|
1459
|
+
onExpandedChange
|
|
1460
|
+
},
|
|
1461
|
+
expanded,
|
|
1462
|
+
activeItemsById
|
|
1463
|
+
} = table.getState();
|
|
1464
|
+
const newExpanded = new Set(expanded);
|
|
1465
|
+
if (expandOnlyOne)
|
|
1466
|
+
newExpanded.clear();
|
|
1467
|
+
if (isExpanded)
|
|
1468
|
+
newExpanded.delete(itemId);
|
|
1469
|
+
else {
|
|
1470
|
+
newExpanded.add(itemId);
|
|
1471
|
+
const item = activeItemsById.get(itemId);
|
|
1472
|
+
for (const ancestor of item ? getAncestors(activeItemsById, item) : []) {
|
|
1473
|
+
newExpanded.add(ancestor);
|
|
1474
|
+
}
|
|
1475
|
+
}
|
|
1476
|
+
onExpandedChange == null ? void 0 : onExpandedChange(newExpanded);
|
|
1477
|
+
if (!controlledExpanded) {
|
|
1478
|
+
table.update((state) => {
|
|
1479
|
+
state.expanded = newExpanded;
|
|
1480
|
+
});
|
|
1481
|
+
}
|
|
1482
|
+
}
|
|
1483
|
+
if (isExpanded && hasDeferredChildren && !hasChildren) {
|
|
1484
|
+
return jsxRuntime.jsx(Spinner, {
|
|
1485
|
+
css: {
|
|
1486
|
+
margin: "0 var(--spacing)"
|
|
1487
|
+
}
|
|
1488
|
+
});
|
|
1489
|
+
}
|
|
1490
|
+
return jsxRuntime.jsx(IconButton, {
|
|
1491
|
+
onClick: toggle2,
|
|
1492
|
+
children: jsxRuntime.jsx("span", {
|
|
1493
|
+
css: {
|
|
1494
|
+
display: "inline-flex",
|
|
1495
|
+
transition: "all 300ms",
|
|
1496
|
+
transform: isExpanded ? "rotate3d(0, 0, 1, 90deg)" : "rotate3d(0, 0, 1, 0deg)"
|
|
1497
|
+
},
|
|
1498
|
+
children: jsxRuntime.jsx(ChevronRight, {})
|
|
1499
|
+
})
|
|
1500
|
+
});
|
|
1501
|
+
}
|
|
1502
|
+
function SelectComponent({
|
|
1503
|
+
itemId
|
|
1504
|
+
}) {
|
|
1505
|
+
const table = useTableContext();
|
|
1506
|
+
const {
|
|
1507
|
+
components: {
|
|
1508
|
+
Checkbox
|
|
1509
|
+
}
|
|
1510
|
+
} = useTheme();
|
|
1511
|
+
const isSelected = table.useState((state) => {
|
|
1512
|
+
const itemIds = itemId ? [itemId] : Array.from(state.activeItemsById.keys());
|
|
1513
|
+
return state.activeItemsById.size > 0 && itemIds.every((itemId2) => state.selection.has(itemId2));
|
|
1514
|
+
});
|
|
1515
|
+
function toggle2(e) {
|
|
1516
|
+
const mouseEvent = e.nativeEvent;
|
|
1517
|
+
const {
|
|
1518
|
+
activeItems,
|
|
1519
|
+
activeItemsById,
|
|
1520
|
+
lastSelectedId,
|
|
1521
|
+
selection,
|
|
1522
|
+
props: {
|
|
1523
|
+
selectSyncChildren,
|
|
1524
|
+
selection: controlledSelection,
|
|
1525
|
+
onSelectionChange
|
|
1526
|
+
}
|
|
1527
|
+
} = table.getState();
|
|
1528
|
+
let range;
|
|
1529
|
+
if (mouseEvent.shiftKey && itemId) {
|
|
1530
|
+
const a = lastSelectedId ? activeItems.findIndex((i) => lastSelectedId === i.id) : 0;
|
|
1531
|
+
const b = activeItems.findIndex((item) => item.id === itemId);
|
|
1532
|
+
range = activeItems.slice(Math.min(a, b), Math.max(a, b) + 1);
|
|
1533
|
+
} else {
|
|
1534
|
+
const item = itemId ? activeItemsById.get(itemId) : void 0;
|
|
1535
|
+
range = item ? [item] : activeItems;
|
|
1536
|
+
}
|
|
1537
|
+
const newSelection = new Set(selection);
|
|
1538
|
+
for (const item of range) {
|
|
1539
|
+
if (isSelected)
|
|
1540
|
+
newSelection.delete(item.id);
|
|
1541
|
+
else
|
|
1542
|
+
newSelection.add(item.id);
|
|
1543
|
+
}
|
|
1544
|
+
if (selectSyncChildren && isSelected) {
|
|
1545
|
+
for (const ancestor of getAncestors(activeItemsById, ...range)) {
|
|
1546
|
+
newSelection.delete(ancestor);
|
|
1547
|
+
}
|
|
1548
|
+
for (const descendant of getDescendants(...range)) {
|
|
1549
|
+
newSelection.delete(descendant);
|
|
1550
|
+
}
|
|
1551
|
+
}
|
|
1552
|
+
onSelectionChange == null ? void 0 : onSelectionChange(newSelection);
|
|
1553
|
+
if (!controlledSelection) {
|
|
1554
|
+
table.update((state) => {
|
|
1555
|
+
state.selection = newSelection;
|
|
1556
|
+
});
|
|
1557
|
+
}
|
|
1558
|
+
table.update((state) => {
|
|
1559
|
+
state.lastSelectedId = itemId;
|
|
1560
|
+
});
|
|
1561
|
+
}
|
|
1562
|
+
return jsxRuntime.jsx(Checkbox, {
|
|
1563
|
+
css: {
|
|
1564
|
+
justifySelf: "start",
|
|
1565
|
+
color: "inherit"
|
|
1566
|
+
},
|
|
1567
|
+
checked: isSelected,
|
|
1568
|
+
onChange: toggle2
|
|
1569
|
+
});
|
|
1570
|
+
}
|
|
1571
|
+
function calcClassNames(classes, item, index) {
|
|
1572
|
+
return [(classes == null ? void 0 : classes.cell) instanceof Function ? classes.cell(item, index) : classes == null ? void 0 : classes.cell, index % 2 === 0 && (classes == null ? void 0 : classes.evenCell), index % 2 === 1 && (classes == null ? void 0 : classes.oddCell)];
|
|
1573
|
+
}
|
|
1574
|
+
const Row = react.memo(function Row2({
|
|
1575
|
+
itemId,
|
|
1576
|
+
rowIndex
|
|
1577
|
+
}) {
|
|
1578
|
+
var _a, _b;
|
|
1579
|
+
const table = useTableContext();
|
|
1580
|
+
const divRef = react.useRef(null);
|
|
1581
|
+
const {
|
|
1582
|
+
className,
|
|
1583
|
+
indent,
|
|
1584
|
+
hasChildren,
|
|
1585
|
+
hasDeferredChildren,
|
|
1586
|
+
columnIds,
|
|
1587
|
+
enableSelection,
|
|
1588
|
+
rowAction
|
|
1589
|
+
} = table.useState((state) => {
|
|
1590
|
+
var _a2, _b2;
|
|
1591
|
+
const item = state.activeItemsById.get(itemId);
|
|
1592
|
+
const index = !item ? -1 : state.activeItems.indexOf(item);
|
|
1593
|
+
return {
|
|
1594
|
+
className: cx(...calcClassNames(state.props.classes, item, index)),
|
|
1595
|
+
indent: item ? getAncestors(state.activeItemsById, item).size : 0,
|
|
1596
|
+
hasChildren: !!(item == null ? void 0 : item.children.length),
|
|
1597
|
+
hasDeferredChildren: item && ((_b2 = (_a2 = state.props).hasDeferredChildren) == null ? void 0 : _b2.call(_a2, item)),
|
|
1598
|
+
columnIds: state.activeColumns.map((column) => column.id),
|
|
1599
|
+
enableSelection: state.props.enableSelection,
|
|
1600
|
+
rowAction: state.props.rowAction instanceof Function ? item ? state.props.rowAction(item, index) : null : state.props.rowAction
|
|
1601
|
+
};
|
|
1602
|
+
});
|
|
1603
|
+
react.useEffect(() => {
|
|
1604
|
+
const div = divRef.current;
|
|
1605
|
+
if (!div)
|
|
1606
|
+
return;
|
|
1607
|
+
const o = new ResizeObserver(() => {
|
|
1608
|
+
if (!document.contains(div))
|
|
1609
|
+
return;
|
|
1610
|
+
table.update((state) => {
|
|
1611
|
+
state.rowHeights.set(itemId, div.offsetHeight);
|
|
1612
|
+
});
|
|
1613
|
+
});
|
|
1614
|
+
o.observe(div);
|
|
1615
|
+
return () => o.disconnect();
|
|
1616
|
+
}, [divRef.current]);
|
|
1617
|
+
(_b = (_a = table.getState().props).debugRender) == null ? void 0 : _b.call(_a, "render row", itemId);
|
|
1618
|
+
return jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
|
1619
|
+
children: [jsxRuntime.jsx("div", {
|
|
1620
|
+
className,
|
|
1621
|
+
css: [tableTheme.defaultClasses.cellFill],
|
|
1622
|
+
ref: divRef
|
|
1623
|
+
}), jsxRuntime.jsxs("div", {
|
|
1624
|
+
className,
|
|
1625
|
+
css: [tableTheme.defaultClasses.cell, tableTheme.defaultClasses.firstCell],
|
|
1626
|
+
children: [jsxRuntime.jsx("div", {
|
|
1627
|
+
css: {
|
|
1628
|
+
width: indent * 20
|
|
1629
|
+
}
|
|
1630
|
+
}), enableSelection && jsxRuntime.jsx(SelectComponent, {
|
|
1631
|
+
itemId
|
|
1632
|
+
}), (hasChildren || hasDeferredChildren) && jsxRuntime.jsx(ExpandControl, {
|
|
1633
|
+
itemId,
|
|
1634
|
+
hasDeferredChildren
|
|
1635
|
+
}), rowAction]
|
|
1636
|
+
}), columnIds.map((columnId) => jsxRuntime.jsx(ColumnContext.Provider, {
|
|
1637
|
+
value: columnId,
|
|
1638
|
+
children: jsxRuntime.jsx(Cell, {
|
|
1639
|
+
itemId,
|
|
1640
|
+
rowIndex
|
|
1641
|
+
})
|
|
1642
|
+
}, columnId)), jsxRuntime.jsx("div", {
|
|
1643
|
+
className,
|
|
1644
|
+
css: [tableTheme.defaultClasses.cellFill]
|
|
1645
|
+
})]
|
|
1646
|
+
});
|
|
1647
|
+
});
|
|
1648
|
+
function SortComponent({
|
|
1649
|
+
children
|
|
1650
|
+
}) {
|
|
1651
|
+
const table = useTableContext();
|
|
1652
|
+
const columnId = useColumnContext();
|
|
1653
|
+
const {
|
|
1654
|
+
components: {
|
|
1655
|
+
Badge
|
|
1656
|
+
},
|
|
1657
|
+
icons: {
|
|
1658
|
+
ArrowUpward
|
|
1659
|
+
}
|
|
1660
|
+
} = useTheme();
|
|
1661
|
+
const {
|
|
1662
|
+
direction,
|
|
1663
|
+
index
|
|
1664
|
+
} = table.useState((state) => {
|
|
1665
|
+
var _a, _b;
|
|
1666
|
+
const index2 = (_a = state.sort.findIndex((s) => s.columnId === columnId)) != null ? _a : -1;
|
|
1667
|
+
return {
|
|
1668
|
+
direction: (_b = state.sort[index2]) == null ? void 0 : _b.direction,
|
|
1669
|
+
index: index2 >= 0 && state.sort.length > 1 ? index2 + 1 : void 0
|
|
1670
|
+
};
|
|
1671
|
+
});
|
|
1672
|
+
function toggle2(e) {
|
|
1673
|
+
const {
|
|
1674
|
+
props: {
|
|
1675
|
+
sort: controlledSort,
|
|
1676
|
+
onSortChange
|
|
1677
|
+
}
|
|
1678
|
+
} = table.getState();
|
|
1679
|
+
const newDirection = direction === "asc" ? "desc" : "asc";
|
|
1680
|
+
const newSort = (e.getModifierState("Control") ? table.getState().sort.filter((s) => s.columnId !== columnId) : []).concat({
|
|
1681
|
+
columnId,
|
|
1682
|
+
direction: newDirection
|
|
1683
|
+
});
|
|
1684
|
+
onSortChange == null ? void 0 : onSortChange(newSort);
|
|
1685
|
+
if (!controlledSort) {
|
|
1686
|
+
table.update((state) => {
|
|
1687
|
+
state.sort = newSort;
|
|
1688
|
+
});
|
|
1689
|
+
}
|
|
1690
|
+
}
|
|
1691
|
+
return jsxRuntime.jsxs("div", {
|
|
1692
|
+
css: {
|
|
1693
|
+
userSelect: "none",
|
|
1694
|
+
display: "grid",
|
|
1695
|
+
gridTemplateColumns: "minmax(0, 1fr) max-content",
|
|
1696
|
+
alignItems: "center",
|
|
1697
|
+
cursor: "pointer",
|
|
1698
|
+
"& > div": {
|
|
1699
|
+
overflow: "hidden",
|
|
1700
|
+
textOverflow: "ellipsis"
|
|
1701
|
+
}
|
|
1702
|
+
},
|
|
1703
|
+
onClick: toggle2,
|
|
1704
|
+
children: [jsxRuntime.jsx("div", {
|
|
1705
|
+
children
|
|
1706
|
+
}), jsxRuntime.jsx(Badge, {
|
|
1707
|
+
badgeContent: index,
|
|
1708
|
+
children: jsxRuntime.jsx("span", {
|
|
1709
|
+
css: [{
|
|
1710
|
+
transition: "all 300ms",
|
|
1711
|
+
fontSize: "0.8em"
|
|
1712
|
+
}, !direction && {
|
|
1713
|
+
opacity: 0
|
|
1714
|
+
}, direction === "desc" && {
|
|
1715
|
+
transform: "rotate3d(0, 0, 1, 180deg)"
|
|
1716
|
+
}],
|
|
1717
|
+
children: jsxRuntime.jsx(ArrowUpward, {})
|
|
1718
|
+
})
|
|
1719
|
+
})]
|
|
1720
|
+
});
|
|
1721
|
+
}
|
|
1722
|
+
function throttle(fn, ms) {
|
|
1723
|
+
let last = 0;
|
|
1724
|
+
let lastArgs;
|
|
1725
|
+
let timeout;
|
|
1726
|
+
function run() {
|
|
1727
|
+
const args = lastArgs;
|
|
1728
|
+
last = Date.now();
|
|
1729
|
+
lastArgs = void 0;
|
|
1730
|
+
timeout = void 0;
|
|
1731
|
+
fn(...args);
|
|
1732
|
+
}
|
|
1733
|
+
return Object.assign(function(...args) {
|
|
1734
|
+
const now = Date.now();
|
|
1735
|
+
lastArgs = args;
|
|
1736
|
+
if (timeout)
|
|
1737
|
+
;
|
|
1738
|
+
else if (now < last + ms) {
|
|
1739
|
+
timeout = setTimeout(run, last + ms - now);
|
|
1740
|
+
} else {
|
|
1741
|
+
run();
|
|
1742
|
+
}
|
|
1743
|
+
}, {
|
|
1744
|
+
flush() {
|
|
1745
|
+
if (lastArgs) {
|
|
1746
|
+
run();
|
|
1747
|
+
}
|
|
1748
|
+
}
|
|
1749
|
+
});
|
|
1750
|
+
}
|
|
1751
|
+
const onAncestorScroll = (x, onScroll) => {
|
|
1752
|
+
const find = (x2) => x2.parentElement ? [x2.parentElement, ...find(x2.parentElement)] : [document];
|
|
1753
|
+
const ancestors = find(x);
|
|
1754
|
+
for (const ancestor of ancestors) {
|
|
1755
|
+
ancestor.addEventListener("scroll", onScroll);
|
|
1756
|
+
}
|
|
1757
|
+
return () => {
|
|
1758
|
+
for (const ancestor of ancestors) {
|
|
1759
|
+
ancestor.removeEventListener("scroll", onScroll);
|
|
1760
|
+
}
|
|
1761
|
+
};
|
|
1762
|
+
};
|
|
1763
|
+
const findScrollRoot = (x) => {
|
|
1764
|
+
const parent = x.parentElement;
|
|
1765
|
+
if (!parent)
|
|
1766
|
+
return document.documentElement;
|
|
1767
|
+
if (parent.scrollHeight > parent.clientHeight)
|
|
1768
|
+
return parent;
|
|
1769
|
+
return findScrollRoot(parent);
|
|
1770
|
+
};
|
|
1771
|
+
const relativeOffset = (x, y) => {
|
|
1772
|
+
if (x.offsetParent === y.offsetParent || !x.offsetParent)
|
|
1773
|
+
return x.offsetTop - y.offsetTop;
|
|
1774
|
+
if (x.offsetParent instanceof HTMLElement)
|
|
1775
|
+
return relativeOffset(x.offsetParent, y) + x.offsetTop;
|
|
1776
|
+
return 0;
|
|
1777
|
+
};
|
|
1778
|
+
function Virtualized(_c) {
|
|
1779
|
+
var _d = _c, {
|
|
1780
|
+
header,
|
|
1781
|
+
children
|
|
1782
|
+
} = _d, props = __objRest(_d, [
|
|
1783
|
+
"header",
|
|
1784
|
+
"children"
|
|
1785
|
+
]);
|
|
1786
|
+
var _a, _b, _c2, _d2;
|
|
1787
|
+
const table = useTableContext();
|
|
1788
|
+
const virtual = table.useState("props.virtual");
|
|
1789
|
+
const probeRef = react.useRef(null);
|
|
1790
|
+
const [, setCounter] = react.useState(0);
|
|
1791
|
+
const {
|
|
1792
|
+
itemIds = [],
|
|
1793
|
+
from = 0,
|
|
1794
|
+
to,
|
|
1795
|
+
before = 0,
|
|
1796
|
+
after = 0
|
|
1797
|
+
} = table.useState((state) => {
|
|
1798
|
+
var _a2;
|
|
1799
|
+
const itemIds2 = state.activeItems.map((item) => item.id);
|
|
1800
|
+
const root = probeRef.current && findScrollRoot(probeRef.current);
|
|
1801
|
+
if (!state.props.virtual)
|
|
1802
|
+
return {
|
|
1803
|
+
itemIds: itemIds2
|
|
1804
|
+
};
|
|
1805
|
+
if (!probeRef.current || !root || !document.contains(root))
|
|
1806
|
+
return {};
|
|
1807
|
+
const {
|
|
1808
|
+
rowHeight,
|
|
1809
|
+
initalRowHeight,
|
|
1810
|
+
overscan = 200,
|
|
1811
|
+
overscanTop,
|
|
1812
|
+
overscanBottom
|
|
1813
|
+
} = (_a2 = state.props.virtual instanceof Object ? state.props.virtual : void 0) != null ? _a2 : {};
|
|
1814
|
+
let totalHeight = 0;
|
|
1815
|
+
const rowHeights = itemIds2.map((itemId, index) => {
|
|
1816
|
+
var _a3, _b2;
|
|
1817
|
+
const h = (_b2 = (_a3 = rowHeight != null ? rowHeight : state.rowHeights.get(itemId)) != null ? _a3 : initalRowHeight) != null ? _b2 : index === 0 ? 100 : totalHeight / index;
|
|
1818
|
+
totalHeight += h;
|
|
1819
|
+
return h;
|
|
1820
|
+
});
|
|
1821
|
+
const probeOffset = relativeOffset(probeRef.current, root);
|
|
1822
|
+
const headerHeight = probeRef.current.offsetTop;
|
|
1823
|
+
const topOfTable = root.scrollTop - probeOffset + headerHeight;
|
|
1824
|
+
const bottomOfTable = topOfTable + root.clientHeight - headerHeight;
|
|
1825
|
+
let from2 = 0, to2 = itemIds2.length, before2 = 0, after2 = 0;
|
|
1826
|
+
for (const h of rowHeights) {
|
|
1827
|
+
if (before2 + h > topOfTable - (overscanTop != null ? overscanTop : overscan))
|
|
1828
|
+
break;
|
|
1829
|
+
from2++;
|
|
1830
|
+
before2 += h;
|
|
1831
|
+
}
|
|
1832
|
+
for (const h of rowHeights.reverse()) {
|
|
1833
|
+
if (after2 + h > totalHeight - bottomOfTable - (overscanBottom != null ? overscanBottom : overscan))
|
|
1834
|
+
break;
|
|
1835
|
+
to2--;
|
|
1836
|
+
after2 += h;
|
|
1837
|
+
}
|
|
1838
|
+
return {
|
|
1839
|
+
itemIds: itemIds2.slice(from2, to2),
|
|
1840
|
+
from: from2,
|
|
1841
|
+
to: to2,
|
|
1842
|
+
before: before2,
|
|
1843
|
+
after: after2
|
|
1844
|
+
};
|
|
1845
|
+
});
|
|
1846
|
+
const throttleScroll = (_b = (_a = typeof virtual === "boolean" ? void 0 : virtual) == null ? void 0 : _a.throttleScroll) != null ? _b : 500;
|
|
1847
|
+
const incCounter = react.useMemo(() => throttle(() => setCounter((c) => c + 1), throttleScroll), [throttleScroll]);
|
|
1848
|
+
react.useEffect(() => {
|
|
1849
|
+
if (!virtual || !probeRef.current)
|
|
1850
|
+
return;
|
|
1851
|
+
return onAncestorScroll(probeRef.current, incCounter);
|
|
1852
|
+
}, [probeRef.current, incCounter]);
|
|
1853
|
+
(_d2 = (_c2 = table.getState().props).debugRender) == null ? void 0 : _d2.call(_c2, `Virtualalized render ${from} to ${to}`);
|
|
1854
|
+
return jsxRuntime.jsxs("div", __spreadProps(__spreadValues({}, props), {
|
|
1855
|
+
children: [header, virtual && jsxRuntime.jsx("div", {
|
|
1856
|
+
style: {
|
|
1857
|
+
gridColumn: "1 / -1",
|
|
1858
|
+
height: before
|
|
1859
|
+
},
|
|
1860
|
+
ref: probeRef
|
|
1861
|
+
}), children(itemIds, from), virtual && jsxRuntime.jsx("div", {
|
|
1862
|
+
style: {
|
|
1863
|
+
gridColumn: "1 / -1",
|
|
1864
|
+
height: after
|
|
1865
|
+
}
|
|
1866
|
+
})]
|
|
1867
|
+
}));
|
|
1868
|
+
}
|
|
1869
|
+
const TableContext = react.createContext(null);
|
|
1870
|
+
const ColumnContext = react.createContext(null);
|
|
1871
|
+
function useTableContext() {
|
|
1872
|
+
const value = react.useContext(TableContext);
|
|
1873
|
+
if (!value)
|
|
1874
|
+
throw Error("No table context available");
|
|
1875
|
+
return value;
|
|
1876
|
+
}
|
|
1877
|
+
function useColumnContext() {
|
|
1878
|
+
const value = react.useContext(ColumnContext);
|
|
1879
|
+
if (value === null)
|
|
1880
|
+
throw Error("No column context available");
|
|
1881
|
+
return value;
|
|
1882
|
+
}
|
|
1883
|
+
function Table(props) {
|
|
1884
|
+
var _a, _b;
|
|
1885
|
+
const table = useTableState(props);
|
|
1886
|
+
(_b = (_a = table.getState().props).debugRender) == null ? void 0 : _b.call(_a, "render table");
|
|
1887
|
+
return jsxRuntime.jsx(TableContext.Provider, {
|
|
1888
|
+
value: table,
|
|
1889
|
+
children: jsxRuntime.jsx(TableLoadingState, {})
|
|
1890
|
+
});
|
|
1891
|
+
}
|
|
1892
|
+
function TableLoadingState() {
|
|
1893
|
+
const {
|
|
1894
|
+
text
|
|
1895
|
+
} = useTheme();
|
|
1896
|
+
const isHydrated = useTableStateStorage();
|
|
1897
|
+
const [showLoading, setShowLoading] = react.useState(false);
|
|
1898
|
+
react.useEffect(() => {
|
|
1899
|
+
const handle = setTimeout(() => setShowLoading(true), 500);
|
|
1900
|
+
return () => clearTimeout(handle);
|
|
1901
|
+
});
|
|
1902
|
+
return jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
|
1903
|
+
children: [!isHydrated && showLoading && jsxRuntime.jsx("div", {
|
|
1904
|
+
children: text.loading
|
|
1905
|
+
}), jsxRuntime.jsx(TableInner, {
|
|
1906
|
+
hidden: !isHydrated
|
|
1907
|
+
})]
|
|
1908
|
+
});
|
|
1909
|
+
}
|
|
1910
|
+
const TableInner = react.memo(function TableInner2({
|
|
1911
|
+
hidden
|
|
1912
|
+
}) {
|
|
1913
|
+
var _a, _b;
|
|
1914
|
+
const table = useTableContext();
|
|
1915
|
+
const fullWidth = table.useState("props.fullWidth");
|
|
1916
|
+
const activeColumns = table.useState((state) => state.activeColumns.map((column) => ({
|
|
1917
|
+
id: column.id,
|
|
1918
|
+
width: column.width,
|
|
1919
|
+
classes: column.classes,
|
|
1920
|
+
header: column.header
|
|
1921
|
+
})));
|
|
1922
|
+
const columnWidths = table.useState("columnWidths", {
|
|
1923
|
+
throttle: 16
|
|
1924
|
+
});
|
|
1925
|
+
const columnStyleOverride = table.useState("columnStyleOverride", {
|
|
1926
|
+
throttle: 16
|
|
1927
|
+
});
|
|
1928
|
+
const defaultWidth = table.useState("props.defaultWidth");
|
|
1929
|
+
const classes = table.useState("props.classes");
|
|
1930
|
+
const stickyHeader = table.useState("props.stickyHeader");
|
|
1931
|
+
const enableSelection = table.useState("props.enableSelection");
|
|
1932
|
+
const enableColumnSelection = table.useState("props.enableColumnSelection");
|
|
1933
|
+
const enableExport = table.useState((state) => !!state.props.enableExport.copy || !!state.props.enableExport.download);
|
|
1934
|
+
const cssVariables = useCssVariables();
|
|
1935
|
+
(_b = (_a = table.getState().props).debugRender) == null ? void 0 : _b.call(_a, "render table inner");
|
|
1936
|
+
return jsxRuntime.jsx(Virtualized, {
|
|
1937
|
+
className: `${classes == null ? void 0 : classes.table}`,
|
|
1938
|
+
css: [cssVariables, tableTheme.defaultClasses.table, {
|
|
1939
|
+
gridTemplateColumns: [
|
|
1940
|
+
fullWidth === "right" || fullWidth === true ? "auto" : "0",
|
|
1941
|
+
"max-content",
|
|
1942
|
+
...activeColumns.map((column) => {
|
|
1943
|
+
var _a2, _b2, _c;
|
|
1944
|
+
return (_c = (_b2 = (_a2 = columnWidths.get(column.id)) != null ? _a2 : column.width) != null ? _b2 : defaultWidth) != null ? _c : "max-content";
|
|
1945
|
+
}),
|
|
1946
|
+
fullWidth === "left" || fullWidth === true ? "auto" : "0"
|
|
1947
|
+
].join(" ")
|
|
1948
|
+
}, hidden && {
|
|
1949
|
+
visibility: "hidden"
|
|
1950
|
+
}],
|
|
1951
|
+
header: jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
|
1952
|
+
children: [jsxRuntime.jsx("div", {
|
|
1953
|
+
className: classes == null ? void 0 : classes.headerCell,
|
|
1954
|
+
css: [tableTheme.defaultClasses.headerFill, stickyHeader && tableTheme.defaultClasses.sticky]
|
|
1955
|
+
}), jsxRuntime.jsxs("div", {
|
|
1956
|
+
className: classes == null ? void 0 : classes.headerCell,
|
|
1957
|
+
css: [tableTheme.defaultClasses.headerCell, stickyHeader && tableTheme.defaultClasses.sticky],
|
|
1958
|
+
children: [enableSelection && jsxRuntime.jsx(SelectComponent, {}), enableColumnSelection && jsxRuntime.jsx(ColumnSelection, {}), enableExport && jsxRuntime.jsx(Export, {})]
|
|
1959
|
+
}), jsxRuntime.jsx(ColumnHeaderContext.Provider, {
|
|
1960
|
+
children: activeColumns.map((column) => {
|
|
1961
|
+
var _a2;
|
|
1962
|
+
return jsxRuntime.jsx(ColumnContext.Provider, {
|
|
1963
|
+
value: column.id,
|
|
1964
|
+
children: jsxRuntime.jsxs(ColumnHeader, {
|
|
1965
|
+
className: cx(classes == null ? void 0 : classes.headerCell, (_a2 = column.classes) == null ? void 0 : _a2.headerCell),
|
|
1966
|
+
css: [tableTheme.defaultClasses.headerCell, columnStyleOverride.get(column.id), stickyHeader && tableTheme.defaultClasses.sticky],
|
|
1967
|
+
children: [jsxRuntime.jsx(FilterControl, {}), jsxRuntime.jsx(SortComponent, {
|
|
1968
|
+
children: column.header
|
|
1969
|
+
}), jsxRuntime.jsx("div", {
|
|
1970
|
+
css: {
|
|
1971
|
+
flex: 1
|
|
1972
|
+
}
|
|
1973
|
+
}), jsxRuntime.jsx(ResizeHandle, {})]
|
|
1974
|
+
}, column.id)
|
|
1975
|
+
}, column.id);
|
|
1976
|
+
})
|
|
1977
|
+
}), jsxRuntime.jsx("div", {
|
|
1978
|
+
className: classes == null ? void 0 : classes.headerCell,
|
|
1979
|
+
css: [tableTheme.defaultClasses.headerFill, stickyHeader && tableTheme.defaultClasses.sticky]
|
|
1980
|
+
})]
|
|
1981
|
+
}),
|
|
1982
|
+
children: (itemIds, startIndex) => itemIds.map((itemId, index) => jsxRuntime.jsx(Row, {
|
|
1983
|
+
itemId,
|
|
1984
|
+
rowIndex: startIndex + index
|
|
1985
|
+
}, itemId))
|
|
1986
|
+
});
|
|
1987
|
+
});
|
|
1988
|
+
function toggle(set, value, singleSelect) {
|
|
1989
|
+
const newSet = new Set(singleSelect ? [] : set);
|
|
1990
|
+
if (set.has(value)) {
|
|
1991
|
+
newSet.delete(value);
|
|
1992
|
+
} else {
|
|
1993
|
+
newSet.add(value);
|
|
1994
|
+
}
|
|
1995
|
+
return newSet;
|
|
1996
|
+
}
|
|
1997
|
+
function SelectFilter(_e) {
|
|
1998
|
+
var _f = _e, {
|
|
1999
|
+
options: providedOptions,
|
|
2000
|
+
stringValue = asString,
|
|
2001
|
+
render = stringValue,
|
|
2002
|
+
singleSelect
|
|
2003
|
+
} = _f, props = __objRest(_f, [
|
|
2004
|
+
"options",
|
|
2005
|
+
"stringValue",
|
|
2006
|
+
"render",
|
|
2007
|
+
"singleSelect"
|
|
2008
|
+
]);
|
|
2009
|
+
const {
|
|
2010
|
+
components: {
|
|
2011
|
+
TextField,
|
|
2012
|
+
Button,
|
|
2013
|
+
IconButton,
|
|
2014
|
+
Checkbox
|
|
2015
|
+
},
|
|
2016
|
+
icons: {
|
|
2017
|
+
Search,
|
|
2018
|
+
Clear
|
|
2019
|
+
},
|
|
2020
|
+
text
|
|
2021
|
+
} = useTheme();
|
|
2022
|
+
const table = useTableContext();
|
|
2023
|
+
const columnId = useColumnContext();
|
|
2024
|
+
const options = table.useState((state) => {
|
|
2025
|
+
var _a;
|
|
2026
|
+
if (providedOptions)
|
|
2027
|
+
return uniq(providedOptions);
|
|
2028
|
+
const column = state.activeColumns.find((column2) => column2.id === columnId);
|
|
2029
|
+
if (!column)
|
|
2030
|
+
return [];
|
|
2031
|
+
const filterBy = (_a = props.filterBy) != null ? _a : (x) => x;
|
|
2032
|
+
return uniq(flatMap(state.items, (item) => castArray(filterBy(column.value(item), item))));
|
|
2033
|
+
});
|
|
2034
|
+
const [query, setQuery] = react.useState("");
|
|
2035
|
+
const filtered = options.filter((option) => !query || stringValue(option).toLowerCase().includes(query.toLowerCase()));
|
|
2036
|
+
const {
|
|
2037
|
+
value = /* @__PURE__ */ new Set(),
|
|
2038
|
+
onChange
|
|
2039
|
+
} = useFilter(__spreadProps(__spreadValues({}, props), {
|
|
2040
|
+
id: "selectFilter",
|
|
2041
|
+
isActive(filterValue) {
|
|
2042
|
+
return filterValue.size > 0;
|
|
2043
|
+
},
|
|
2044
|
+
test(filterValue, value2) {
|
|
2045
|
+
return filterValue.has(value2);
|
|
2046
|
+
}
|
|
2047
|
+
}));
|
|
2048
|
+
return jsxRuntime.jsxs("div", {
|
|
2049
|
+
css: {
|
|
2050
|
+
padding: "calc(var(--spacing) * 2)",
|
|
2051
|
+
display: "grid",
|
|
2052
|
+
gap: "var(--spacing)"
|
|
2053
|
+
},
|
|
2054
|
+
children: [jsxRuntime.jsxs("div", {
|
|
2055
|
+
css: {
|
|
2056
|
+
marginBottom: "var(--spacing)",
|
|
2057
|
+
display: "grid",
|
|
2058
|
+
gridAutoFlow: "column",
|
|
2059
|
+
gap: "var(--spacing)",
|
|
2060
|
+
justifyContent: "space-between",
|
|
2061
|
+
alignItems: "center"
|
|
2062
|
+
},
|
|
2063
|
+
children: [jsxRuntime.jsx("div", {
|
|
2064
|
+
children: text.selectFilter
|
|
2065
|
+
}), jsxRuntime.jsx(Button, {
|
|
2066
|
+
variant: "contained",
|
|
2067
|
+
onClick: () => onChange(/* @__PURE__ */ new Set()),
|
|
2068
|
+
disabled: value.size === 0,
|
|
2069
|
+
children: text.reset
|
|
2070
|
+
})]
|
|
2071
|
+
}), jsxRuntime.jsx(TextField, {
|
|
2072
|
+
value: query,
|
|
2073
|
+
onChange: (e) => setQuery(e.target.value),
|
|
2074
|
+
endIcon: jsxRuntime.jsx(IconButton, {
|
|
2075
|
+
onClick: () => setQuery(""),
|
|
2076
|
+
children: !query ? jsxRuntime.jsx(Search, {}) : jsxRuntime.jsx(Clear, {})
|
|
2077
|
+
}),
|
|
2078
|
+
css: {
|
|
2079
|
+
marginBottom: "var(--spacing)"
|
|
2080
|
+
}
|
|
2081
|
+
}), jsxRuntime.jsx("div", {
|
|
2082
|
+
css: {
|
|
2083
|
+
maxHeight: "20em",
|
|
2084
|
+
overflowY: "auto"
|
|
2085
|
+
},
|
|
2086
|
+
children: filtered.map((option, index) => jsxRuntime.jsx(FormControlLabel, {
|
|
2087
|
+
control: jsxRuntime.jsx(Checkbox, {
|
|
2088
|
+
checked: value.has(option),
|
|
2089
|
+
onChange: () => onChange(toggle(value, option, singleSelect))
|
|
2090
|
+
}),
|
|
2091
|
+
label: render(option)
|
|
2092
|
+
}, index))
|
|
2093
|
+
}), filtered.length === 0 && jsxRuntime.jsx("span", {
|
|
2094
|
+
css: {
|
|
2095
|
+
textAlign: "center"
|
|
2096
|
+
},
|
|
2097
|
+
children: text.noResults
|
|
2098
|
+
})]
|
|
2099
|
+
});
|
|
2100
|
+
}
|
|
2101
|
+
function debounce(fn, ms) {
|
|
2102
|
+
let lastArgs;
|
|
2103
|
+
let timeout;
|
|
2104
|
+
function run() {
|
|
2105
|
+
const args = lastArgs;
|
|
2106
|
+
lastArgs = void 0;
|
|
2107
|
+
timeout = void 0;
|
|
2108
|
+
fn(...args);
|
|
2109
|
+
}
|
|
2110
|
+
return Object.assign(function(...args) {
|
|
2111
|
+
lastArgs = args;
|
|
2112
|
+
if (timeout) {
|
|
2113
|
+
clearTimeout(timeout);
|
|
2114
|
+
}
|
|
2115
|
+
timeout = setTimeout(run, ms);
|
|
2116
|
+
}, {
|
|
2117
|
+
flush() {
|
|
2118
|
+
if (timeout) {
|
|
2119
|
+
clearTimeout(timeout);
|
|
2120
|
+
run();
|
|
2121
|
+
}
|
|
2122
|
+
}
|
|
2123
|
+
});
|
|
2124
|
+
}
|
|
2125
|
+
function useFilter(impl) {
|
|
2126
|
+
var _a;
|
|
2127
|
+
const table = useTableContext();
|
|
2128
|
+
const columnId = useColumnContext();
|
|
2129
|
+
react.useEffect(() => {
|
|
2130
|
+
table.update((state) => {
|
|
2131
|
+
if (impl.defaultValue !== void 0) {
|
|
2132
|
+
state.filterValues.set(columnId, impl.defaultValue);
|
|
2133
|
+
}
|
|
2134
|
+
});
|
|
2135
|
+
}, []);
|
|
2136
|
+
react.useEffect(() => {
|
|
2137
|
+
table.update((state) => {
|
|
2138
|
+
state.filters.set(columnId, immer.castDraft(impl));
|
|
2139
|
+
if (impl.value !== void 0) {
|
|
2140
|
+
state.filterValues.set(columnId, impl.value);
|
|
2141
|
+
}
|
|
2142
|
+
});
|
|
2143
|
+
return () => {
|
|
2144
|
+
table.update((state) => {
|
|
2145
|
+
state.filters.delete(columnId);
|
|
2146
|
+
});
|
|
2147
|
+
};
|
|
2148
|
+
}, [table, columnId, ...(_a = impl.dependencies) != null ? _a : [impl]]);
|
|
2149
|
+
const value = table.useState((state) => state.filterValues.get(columnId));
|
|
2150
|
+
const [dirtyValue, setDirtyValue] = react.useState();
|
|
2151
|
+
const implRef = react.useRef(impl);
|
|
2152
|
+
react.useLayoutEffect(() => {
|
|
2153
|
+
implRef.current = impl;
|
|
2154
|
+
});
|
|
2155
|
+
const delayedUpdate = react.useMemo(() => debounce((value2) => {
|
|
2156
|
+
const { value: controlledValue, onChange: onChange2 } = implRef.current;
|
|
2157
|
+
if (controlledValue === void 0) {
|
|
2158
|
+
table.update((state) => {
|
|
2159
|
+
state.filterValues.set(columnId, value2);
|
|
2160
|
+
});
|
|
2161
|
+
}
|
|
2162
|
+
onChange2 == null ? void 0 : onChange2(value2);
|
|
2163
|
+
}, 500), [table]);
|
|
2164
|
+
function onChange(value2) {
|
|
2165
|
+
setDirtyValue(value2);
|
|
2166
|
+
delayedUpdate(value2);
|
|
2167
|
+
}
|
|
2168
|
+
react.useEffect(() => delayedUpdate.flush(), [delayedUpdate]);
|
|
2169
|
+
return {
|
|
2170
|
+
value: dirtyValue != null ? dirtyValue : value,
|
|
2171
|
+
onChange
|
|
2172
|
+
};
|
|
2173
|
+
}
|
|
2174
|
+
const textMatch = (text, query) => {
|
|
2175
|
+
text = text.toLowerCase();
|
|
2176
|
+
query = query.toLowerCase();
|
|
2177
|
+
return query.split(/\s+/).every((part) => termMatch(text, part));
|
|
2178
|
+
};
|
|
2179
|
+
const termMatch = (text, query) => {
|
|
2180
|
+
let i = 0;
|
|
2181
|
+
outer:
|
|
2182
|
+
for (const char of query) {
|
|
2183
|
+
for (; i < text.length; i++) {
|
|
2184
|
+
if (text[i] === char) {
|
|
2185
|
+
i++;
|
|
2186
|
+
continue outer;
|
|
2187
|
+
}
|
|
2188
|
+
}
|
|
2189
|
+
return false;
|
|
2190
|
+
}
|
|
2191
|
+
return true;
|
|
2192
|
+
};
|
|
2193
|
+
function TextFilter(_g) {
|
|
2194
|
+
var _h = _g, {
|
|
2195
|
+
compare = textMatch,
|
|
2196
|
+
filterBy = asStringOrArray
|
|
2197
|
+
} = _h, props = __objRest(_h, [
|
|
2198
|
+
"compare",
|
|
2199
|
+
"filterBy"
|
|
2200
|
+
]);
|
|
2201
|
+
const {
|
|
2202
|
+
components: {
|
|
2203
|
+
TextField,
|
|
2204
|
+
IconButton,
|
|
2205
|
+
Button
|
|
2206
|
+
},
|
|
2207
|
+
icons: {
|
|
2208
|
+
Search,
|
|
2209
|
+
Clear
|
|
2210
|
+
},
|
|
2211
|
+
text
|
|
2212
|
+
} = useTheme();
|
|
2213
|
+
const {
|
|
2214
|
+
value = "",
|
|
2215
|
+
onChange
|
|
2216
|
+
} = useFilter(__spreadProps(__spreadValues({}, props), {
|
|
2217
|
+
filterBy,
|
|
2218
|
+
id: "textFilter",
|
|
2219
|
+
isActive(filterValue) {
|
|
2220
|
+
return !!filterValue;
|
|
2221
|
+
},
|
|
2222
|
+
test(filterValue, value2) {
|
|
2223
|
+
return compare(value2, filterValue);
|
|
2224
|
+
}
|
|
2225
|
+
}));
|
|
2226
|
+
return jsxRuntime.jsxs("div", {
|
|
2227
|
+
css: {
|
|
2228
|
+
padding: `calc(var(--spacing) * 2)`,
|
|
2229
|
+
display: "grid",
|
|
2230
|
+
gap: "var(--spacing)"
|
|
2231
|
+
},
|
|
2232
|
+
children: [jsxRuntime.jsxs("div", {
|
|
2233
|
+
css: {
|
|
2234
|
+
marginBottom: "var(--spacing)",
|
|
2235
|
+
display: "grid",
|
|
2236
|
+
gridAutoFlow: "column",
|
|
2237
|
+
gap: "var(--spacing)",
|
|
2238
|
+
justifyContent: "space-between",
|
|
2239
|
+
alignItems: "center"
|
|
2240
|
+
},
|
|
2241
|
+
children: [jsxRuntime.jsx("div", {
|
|
2242
|
+
children: text.textFilter
|
|
2243
|
+
}), jsxRuntime.jsx(Button, {
|
|
2244
|
+
variant: "contained",
|
|
2245
|
+
onClick: () => onChange(""),
|
|
2246
|
+
disabled: !value,
|
|
2247
|
+
children: text.reset
|
|
2248
|
+
})]
|
|
2249
|
+
}), jsxRuntime.jsx(TextField, {
|
|
2250
|
+
value,
|
|
2251
|
+
onChange: (e) => onChange(e.target.value),
|
|
2252
|
+
endIcon: jsxRuntime.jsx(IconButton, {
|
|
2253
|
+
onClick: () => onChange(""),
|
|
2254
|
+
children: !value ? jsxRuntime.jsx(Search, {}) : jsxRuntime.jsx(Clear, {})
|
|
2255
|
+
})
|
|
2256
|
+
})]
|
|
2257
|
+
});
|
|
2258
|
+
}
|
|
2259
|
+
exports.TableThemeContext = tableTheme.TableThemeContext;
|
|
2260
|
+
exports.TableThemeProvider = tableTheme.TableThemeProvider;
|
|
2261
|
+
exports.configureTableTheme = tableTheme.configureTableTheme;
|
|
2262
|
+
exports.mergeThemes = tableTheme.mergeThemes;
|
|
2263
|
+
exports.ColumnContext = ColumnContext;
|
|
2264
|
+
exports.DateFilter = DateFilter;
|
|
2265
|
+
exports.SelectFilter = SelectFilter;
|
|
2266
|
+
exports.Table = Table;
|
|
2267
|
+
exports.TableContext = TableContext;
|
|
2268
|
+
exports.TextFilter = TextFilter;
|
|
2269
|
+
exports.termMatch = termMatch;
|
|
2270
|
+
exports.textMatch = textMatch;
|
|
2271
|
+
exports.useColumnContext = useColumnContext;
|
|
2272
|
+
exports.useFilter = useFilter;
|
|
2273
|
+
exports.useTableContext = useTableContext;
|
|
2274
|
+
exports.useTheme = useTheme;
|
|
2275
|
+
//# sourceMappingURL=index.js.map
|