schummar-table 0.5.4 → 0.7.0
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 +1456 -946
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/mui4Theme.js +1 -1
- package/dist/cjs/mui4Theme.js.map +1 -1
- package/dist/cjs/mui5Theme.js +1 -1
- package/dist/cjs/mui5Theme.js.map +1 -1
- package/dist/cjs/tableTheme.js +9 -458
- package/dist/cjs/tableTheme.js.map +1 -1
- package/dist/es/index.js +1565 -1059
- package/dist/es/index.js.map +1 -1
- package/dist/es/mui4Theme.js +2 -2
- package/dist/es/mui4Theme.js.map +1 -1
- package/dist/es/mui5Theme.js +2 -2
- package/dist/es/mui5Theme.js.map +1 -1
- package/dist/es/tableTheme.js +8 -458
- package/dist/es/tableTheme.js.map +1 -1
- package/dist/types/components/dateFilter.d.ts +3 -2
- package/dist/types/components/dateInput.d.ts +5 -0
- package/dist/types/components/datePicker.d.ts +10 -0
- package/dist/types/components/row.d.ts +2 -2
- package/dist/types/components/selectFilter.d.ts +4 -0
- package/dist/types/components/textFilter.d.ts +4 -1
- package/dist/types/hooks/useFilter.d.ts +1 -0
- package/dist/types/hooks/useMemoMap.d.ts +2 -0
- package/dist/types/hooks/useTableMemo.d.ts +6 -0
- package/dist/types/hooks/useTheme.d.ts +2 -1
- package/dist/types/index.d.ts +3 -1
- package/dist/types/misc/throttle.d.ts +1 -0
- package/dist/types/theme/mui4Theme/index.d.ts +2 -2
- package/dist/types/theme/mui5Theme/index.d.ts +2 -2
- package/dist/types/theme/tableTheme.d.ts +2 -2
- package/dist/types/types.d.ts +53 -30
- package/package.json +1 -1
package/dist/es/index.js
CHANGED
|
@@ -5,18 +5,18 @@ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
|
5
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
6
|
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
7
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
-
var __spreadValues = (
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
9
|
for (var prop in b || (b = {}))
|
|
10
10
|
if (__hasOwnProp.call(b, prop))
|
|
11
|
-
__defNormalProp(
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
12
|
if (__getOwnPropSymbols)
|
|
13
13
|
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
14
|
if (__propIsEnum.call(b, prop))
|
|
15
|
-
__defNormalProp(
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
16
|
}
|
|
17
|
-
return
|
|
17
|
+
return a;
|
|
18
18
|
};
|
|
19
|
-
var __spreadProps = (
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
20
|
var __objRest = (source, exclude) => {
|
|
21
21
|
var target = {};
|
|
22
22
|
for (var prop in source)
|
|
@@ -29,473 +29,205 @@ var __objRest = (source, exclude) => {
|
|
|
29
29
|
}
|
|
30
30
|
return target;
|
|
31
31
|
};
|
|
32
|
-
import {
|
|
33
|
-
import {
|
|
34
|
-
|
|
32
|
+
import { createContext, useContext, useMemo, useState, useEffect, useRef, useCallback, memo, useLayoutEffect, cloneElement, Fragment as Fragment$1 } from "react";
|
|
33
|
+
import { Store, StoreScope } from "schummar-state/react";
|
|
34
|
+
import { d as defaultClasses, a as darkGray, l as lightGray, P as Popover, T as TableThemeContext, m as mergeThemes, g as globalTableTheme, b as PopoverContext, c as gray } from "./tableTheme.js";
|
|
35
|
+
export { T as TableThemeContext, f as TableThemeProvider, e as configureTableTheme, m as mergeThemes } from "./tableTheme.js";
|
|
35
36
|
import { jsx, jsxs, Fragment } from "@emotion/react/jsx-runtime";
|
|
36
37
|
import { useDayzed } from "dayzed";
|
|
37
38
|
import { castDraft } from "immer";
|
|
38
|
-
import {
|
|
39
|
-
import "@emotion/react";
|
|
39
|
+
import { css, ClassNames } from "@emotion/react";
|
|
40
40
|
import "react-dom";
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
const TableMemoContext = createContext(/* @__PURE__ */ new Map());
|
|
42
|
+
function TableMemoContextProvider({
|
|
43
|
+
children
|
|
44
|
+
}) {
|
|
45
|
+
return jsx(TableMemoContext.Provider, {
|
|
46
|
+
value: useMemo(() => /* @__PURE__ */ new Map(), []),
|
|
47
|
+
children
|
|
48
|
+
});
|
|
44
49
|
}
|
|
45
|
-
function
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
50
|
+
function useTableMemo() {
|
|
51
|
+
const memoCache = useContext(TableMemoContext);
|
|
52
|
+
return (key, fn) => {
|
|
53
|
+
let deps;
|
|
54
|
+
if (Array.isArray(fn)) {
|
|
55
|
+
deps = fn.slice(1);
|
|
56
|
+
fn = fn[0];
|
|
57
|
+
} else {
|
|
58
|
+
deps = [fn.toString()];
|
|
49
59
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
useLayoutEffect(() => {
|
|
56
|
-
if (visible && ref.current) {
|
|
57
|
-
ref.current.focus();
|
|
60
|
+
let cachedValue = memoCache.get(key);
|
|
61
|
+
const hit = cachedValue && cachedValue[1].length === deps.length && cachedValue[1].every((x, i) => x === deps[i]);
|
|
62
|
+
if (!cachedValue || !hit) {
|
|
63
|
+
cachedValue = [fn, deps];
|
|
64
|
+
memoCache.set(key, cachedValue);
|
|
58
65
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
inputRef: ref
|
|
62
|
-
}));
|
|
63
|
-
}
|
|
64
|
-
function useCssVariables() {
|
|
65
|
-
const table = useTableContext();
|
|
66
|
-
return table.useState((state) => ({
|
|
67
|
-
"--spacing": state.theme.spacing,
|
|
68
|
-
"--primaryMain": state.theme.colors.primary.main,
|
|
69
|
-
"--primaryLight": state.theme.colors.primary.light,
|
|
70
|
-
"--primaryContrastText": state.theme.colors.primary.contrastText,
|
|
71
|
-
"--secondaryMain": state.theme.colors.secondary.main,
|
|
72
|
-
"--secondaryLight": state.theme.colors.secondary.light,
|
|
73
|
-
"--secondaryContrastText": state.theme.colors.secondary.contrastText
|
|
74
|
-
}));
|
|
66
|
+
return cachedValue[0];
|
|
67
|
+
};
|
|
75
68
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
function dateIntersect(a2, b) {
|
|
81
|
-
if (a2 instanceof Date) {
|
|
82
|
-
a2 = {
|
|
83
|
-
min: a2,
|
|
84
|
-
max: a2
|
|
85
|
-
};
|
|
69
|
+
class Queue {
|
|
70
|
+
constructor() {
|
|
71
|
+
this.q = new Array();
|
|
72
|
+
this.isRunning = false;
|
|
86
73
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
74
|
+
run(job, replace) {
|
|
75
|
+
return new Promise((resolve, reject) => {
|
|
76
|
+
if (replace) {
|
|
77
|
+
this.q = [];
|
|
78
|
+
}
|
|
79
|
+
this.q.push({ job, resolve, reject });
|
|
80
|
+
if (!this.isRunning)
|
|
81
|
+
this.start();
|
|
82
|
+
});
|
|
92
83
|
}
|
|
93
|
-
|
|
94
|
-
|
|
84
|
+
async start() {
|
|
85
|
+
this.isRunning = true;
|
|
86
|
+
let next;
|
|
87
|
+
while (next = this.q.shift()) {
|
|
88
|
+
try {
|
|
89
|
+
const result = await next.job();
|
|
90
|
+
next.resolve(result);
|
|
91
|
+
} catch (e2) {
|
|
92
|
+
next.reject(e2);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
this.isRunning = false;
|
|
95
96
|
}
|
|
96
|
-
return !(endOfDay(a2.max) < startOfDay(b.min) || startOfDay(a2.min) > endOfDay(b.max));
|
|
97
97
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
}) {
|
|
105
|
-
const {
|
|
106
|
-
components: {
|
|
107
|
-
IconButton
|
|
108
|
-
},
|
|
109
|
-
icons: {
|
|
110
|
-
ChevronRight
|
|
98
|
+
const KEYS = ["sort", "selection", "expanded", "hiddenColumns", "filterValues", "columnWidths", "columnOrder"];
|
|
99
|
+
const storageName = (id) => `schummar-table_state-v1_${id}`;
|
|
100
|
+
function stringify(value) {
|
|
101
|
+
function prepare(value2) {
|
|
102
|
+
if (value2 instanceof Date) {
|
|
103
|
+
return { __date: value2.toJSON() };
|
|
111
104
|
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
showOutsideDays: true,
|
|
128
|
-
date: dateInView,
|
|
129
|
-
onOffsetChanged: (offset) => setDateInView(new Date(dateInView.getFullYear(), dateInView.getMonth() + offset)),
|
|
130
|
-
offset: 0
|
|
131
|
-
});
|
|
132
|
-
const formatWeekday = useMemo(() => {
|
|
133
|
-
const {
|
|
134
|
-
format
|
|
135
|
-
} = new Intl.DateTimeFormat(locale, {
|
|
136
|
-
weekday: "short"
|
|
137
|
-
});
|
|
138
|
-
return (weekDay) => format(new Date(Date.UTC(2021, 5, weekDay)));
|
|
139
|
-
}, [locale]);
|
|
140
|
-
useEffect(() => setDateInView(value === null ? new Date() : value instanceof Date ? value : value.max), [value]);
|
|
141
|
-
return jsx("div", {
|
|
142
|
-
children: calendars.map(({
|
|
143
|
-
month,
|
|
144
|
-
year,
|
|
145
|
-
weeks
|
|
146
|
-
}) => jsxs("div", {
|
|
147
|
-
children: [jsxs("div", {
|
|
148
|
-
css: {
|
|
149
|
-
margin: "calc(var(--spacing) * 4) 0",
|
|
150
|
-
display: "grid",
|
|
151
|
-
gridAutoFlow: "column",
|
|
152
|
-
justifyContent: "space-between",
|
|
153
|
-
alignItems: "center"
|
|
154
|
-
},
|
|
155
|
-
children: [jsx(IconButton, __spreadProps(__spreadValues({}, getBackProps({
|
|
156
|
-
calendars
|
|
157
|
-
})), {
|
|
158
|
-
children: jsx(ChevronRight, {
|
|
159
|
-
css: {
|
|
160
|
-
transform: "rotate3d(0, 0, 1, 180deg)"
|
|
161
|
-
}
|
|
162
|
-
})
|
|
163
|
-
})), jsxs("div", {
|
|
164
|
-
css: {
|
|
165
|
-
display: "flex"
|
|
166
|
-
},
|
|
167
|
-
children: [jsx(MonthSelector, {
|
|
168
|
-
value: month,
|
|
169
|
-
onChange: (month2) => setDateInView(new Date(year, month2)),
|
|
170
|
-
locale
|
|
171
|
-
}), jsx(YearSelector, {
|
|
172
|
-
value: year,
|
|
173
|
-
onChange: (year2) => setDateInView(new Date(year2, month))
|
|
174
|
-
})]
|
|
175
|
-
}), jsx(IconButton, __spreadProps(__spreadValues({}, getForwardProps({
|
|
176
|
-
calendars
|
|
177
|
-
})), {
|
|
178
|
-
children: jsx(ChevronRight, {})
|
|
179
|
-
}))]
|
|
180
|
-
}), jsxs("div", {
|
|
181
|
-
css: {
|
|
182
|
-
display: "grid",
|
|
183
|
-
gridTemplateColumns: "repeat(7, max-content)",
|
|
184
|
-
fontWeight: "bold"
|
|
185
|
-
},
|
|
186
|
-
children: [weekDays.map((_v, weekDay) => jsx("div", {
|
|
187
|
-
css: {
|
|
188
|
-
justifySelf: "center",
|
|
189
|
-
marginBottom: "var(--spacing)"
|
|
190
|
-
},
|
|
191
|
-
children: formatWeekday(weekDay)
|
|
192
|
-
}, weekDay)), weeks.map((week, index) => week.map((dateObj, dayIndex) => {
|
|
193
|
-
if (!dateObj) {
|
|
194
|
-
return jsx("div", {});
|
|
195
|
-
}
|
|
196
|
-
const {
|
|
197
|
-
prevMonth,
|
|
198
|
-
nextMonth,
|
|
199
|
-
date,
|
|
200
|
-
today: today2
|
|
201
|
-
} = dateObj;
|
|
202
|
-
const selected = date.getTime() === (min == null ? void 0 : min.getTime()) || min && max && dateIntersect(date, {
|
|
203
|
-
min,
|
|
204
|
-
max
|
|
205
|
-
});
|
|
206
|
-
const preSelected = !selected && (date.getTime() === (hovered == null ? void 0 : hovered.getTime()) || min && !max && hovered && dateIntersect(date, min <= hovered ? {
|
|
207
|
-
min,
|
|
208
|
-
max: hovered
|
|
209
|
-
} : {
|
|
210
|
-
min: hovered,
|
|
211
|
-
max: min
|
|
212
|
-
}));
|
|
213
|
-
return jsx("button", __spreadProps(__spreadValues({
|
|
214
|
-
css: [{
|
|
215
|
-
padding: 10,
|
|
216
|
-
border: "1px solid transparent",
|
|
217
|
-
background: "transparent",
|
|
218
|
-
cursor: "pointer"
|
|
219
|
-
}, (prevMonth || nextMonth) && {
|
|
220
|
-
color: gray
|
|
221
|
-
}, today2 && {
|
|
222
|
-
border: "1px solid var(--secondaryMain)"
|
|
223
|
-
}, selected && {
|
|
224
|
-
background: "var(--primaryMain)",
|
|
225
|
-
color: "var(--primaryContrastText)"
|
|
226
|
-
}, preSelected && {
|
|
227
|
-
background: "var(--primaryLight)",
|
|
228
|
-
color: "var(--primaryContrastText)"
|
|
229
|
-
}]
|
|
230
|
-
}, getDateProps({
|
|
231
|
-
dateObj
|
|
232
|
-
})), {
|
|
233
|
-
onClick: () => {
|
|
234
|
-
if (!rangeSelect) {
|
|
235
|
-
setCurrentMin(void 0);
|
|
236
|
-
onChange(date);
|
|
237
|
-
} else if (min && !max) {
|
|
238
|
-
setCurrentMin(void 0);
|
|
239
|
-
if (date > min) {
|
|
240
|
-
onChange({
|
|
241
|
-
min,
|
|
242
|
-
max: date
|
|
243
|
-
});
|
|
244
|
-
} else {
|
|
245
|
-
onChange({
|
|
246
|
-
min: date,
|
|
247
|
-
max: min
|
|
248
|
-
});
|
|
249
|
-
}
|
|
250
|
-
} else {
|
|
251
|
-
setCurrentMin(date);
|
|
252
|
-
}
|
|
253
|
-
},
|
|
254
|
-
onPointerOver: () => setHovered(date),
|
|
255
|
-
onPointerOut: () => setHovered(void 0),
|
|
256
|
-
children: date.getDate()
|
|
257
|
-
}), `${index}-${dayIndex}`);
|
|
258
|
-
}))]
|
|
259
|
-
})]
|
|
260
|
-
}, `${month}${year}`))
|
|
261
|
-
});
|
|
105
|
+
if (value2 instanceof Set) {
|
|
106
|
+
return { __set: Array.from(value2).map(prepare) };
|
|
107
|
+
}
|
|
108
|
+
if (value2 instanceof Map) {
|
|
109
|
+
return { __map: Array.from(value2.entries()).map((entry) => entry.map(prepare)) };
|
|
110
|
+
}
|
|
111
|
+
if (value2 instanceof Array) {
|
|
112
|
+
return value2.map(prepare);
|
|
113
|
+
}
|
|
114
|
+
if (value2 instanceof Object) {
|
|
115
|
+
return Object.fromEntries(Object.entries(value2).map(([k, v]) => [k, prepare(v)]));
|
|
116
|
+
}
|
|
117
|
+
return value2;
|
|
118
|
+
}
|
|
119
|
+
return JSON.stringify(prepare(value));
|
|
262
120
|
}
|
|
263
|
-
function
|
|
264
|
-
value,
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
}) {
|
|
268
|
-
const {
|
|
269
|
-
components: {
|
|
270
|
-
Popover
|
|
121
|
+
function parse(value) {
|
|
122
|
+
return JSON.parse(value, (_key, value2) => {
|
|
123
|
+
if (value2 instanceof Object && "__date" in value2) {
|
|
124
|
+
return new Date(value2.__date);
|
|
271
125
|
}
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
month: "long"
|
|
280
|
-
});
|
|
281
|
-
return (month) => format(new Date(2021, month));
|
|
282
|
-
}, [locale]);
|
|
283
|
-
return jsxs(Fragment, {
|
|
284
|
-
children: [jsx("button", {
|
|
285
|
-
css: {
|
|
286
|
-
border: "none",
|
|
287
|
-
background: "transparent",
|
|
288
|
-
fontSize: "inherit",
|
|
289
|
-
cursor: "pointer"
|
|
290
|
-
},
|
|
291
|
-
onClick: (e) => setAnchor(e.currentTarget),
|
|
292
|
-
children: formatMonth(value)
|
|
293
|
-
}), jsx(Popover, {
|
|
294
|
-
open: !!anchor,
|
|
295
|
-
anchorEl: anchor != null ? anchor : null,
|
|
296
|
-
onClose: () => setAnchor(void 0),
|
|
297
|
-
align: "center",
|
|
298
|
-
css: cssVariables,
|
|
299
|
-
children: jsx("div", {
|
|
300
|
-
css: {
|
|
301
|
-
display: "grid"
|
|
302
|
-
},
|
|
303
|
-
children: months.map((month) => jsx("button", {
|
|
304
|
-
css: [{
|
|
305
|
-
padding: "var(--spacing)",
|
|
306
|
-
border: "none",
|
|
307
|
-
background: "transparent",
|
|
308
|
-
"&:hover": {
|
|
309
|
-
background: "var(--primaryLight)"
|
|
310
|
-
}
|
|
311
|
-
}, month === value && {
|
|
312
|
-
background: "var(--primaryMain)"
|
|
313
|
-
}],
|
|
314
|
-
onClick: () => onChange(month),
|
|
315
|
-
children: formatMonth(month)
|
|
316
|
-
}, month))
|
|
317
|
-
})
|
|
318
|
-
})]
|
|
126
|
+
if (value2 instanceof Object && "__set" in value2) {
|
|
127
|
+
return new Set(value2.__set);
|
|
128
|
+
}
|
|
129
|
+
if (value2 instanceof Object && "__map" in value2) {
|
|
130
|
+
return new Map(value2.__map);
|
|
131
|
+
}
|
|
132
|
+
return value2;
|
|
319
133
|
});
|
|
320
134
|
}
|
|
321
|
-
function
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
})
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
135
|
+
function useTableStateStorage() {
|
|
136
|
+
const table = useTableContext();
|
|
137
|
+
const [isHydrated, setIsHydrated] = useState(false);
|
|
138
|
+
useEffect(() => {
|
|
139
|
+
const { persist } = table.getState().props;
|
|
140
|
+
if (!persist) {
|
|
141
|
+
setIsHydrated(true);
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
let isCanceled = false;
|
|
145
|
+
(async () => {
|
|
146
|
+
var _a, _b;
|
|
147
|
+
try {
|
|
148
|
+
const { storage, id, include, exclude } = persist;
|
|
149
|
+
const json = await storage.getItem(storageName(id));
|
|
150
|
+
if (isCanceled || !json)
|
|
151
|
+
return;
|
|
152
|
+
const data = parse(json);
|
|
153
|
+
(_b = (_a = table.getState().props).debug) == null ? void 0 : _b.call(_a, "load", json, data);
|
|
154
|
+
table.update((state) => {
|
|
155
|
+
var _a2, _b2, _c, _d;
|
|
156
|
+
for (const key of KEYS) {
|
|
157
|
+
if ((!include || include.includes(key)) && !(exclude == null ? void 0 : exclude.includes(key)) && key in data) {
|
|
158
|
+
if (key === "filterValues") {
|
|
159
|
+
for (const [id2, value] of data[key]) {
|
|
160
|
+
if ((_b2 = (_a2 = state.filters.get(id2)) == null ? void 0 : _a2.persist) != null ? _b2 : true) {
|
|
161
|
+
state.filterValues.set(id2, value);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
} else {
|
|
165
|
+
state[key] = data[key];
|
|
166
|
+
if (key === "expanded" || key === "hiddenColumns" || key === "selection" || key === "sort") {
|
|
167
|
+
(_d = (_c = state.props)[`on${key.slice(0, 1).toUpperCase() + key.slice(1)}Change`]) == null ? void 0 : _d.call(_c, data[key]);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
} catch (e2) {
|
|
174
|
+
console.error("Failed to load table state:", e2);
|
|
175
|
+
} finally {
|
|
176
|
+
setIsHydrated(true);
|
|
359
177
|
}
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
});
|
|
364
|
-
}
|
|
365
|
-
function convertDate(x) {
|
|
366
|
-
if (x instanceof Date)
|
|
367
|
-
return x;
|
|
368
|
-
if (typeof x === "number" || typeof x === "string")
|
|
369
|
-
return new Date(x);
|
|
370
|
-
return null;
|
|
371
|
-
}
|
|
372
|
-
function convertDateOrRange(x) {
|
|
373
|
-
if (x instanceof Object && "min" in x && "max" in x) {
|
|
374
|
-
const range = {
|
|
375
|
-
min: convertDate(x.min),
|
|
376
|
-
max: convertDate(x.max)
|
|
178
|
+
})();
|
|
179
|
+
return () => {
|
|
180
|
+
isCanceled = true;
|
|
377
181
|
};
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
},
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
}
|
|
417
|
-
}));
|
|
418
|
-
const formatDate = useMemo(() => {
|
|
419
|
-
const {
|
|
420
|
-
format
|
|
421
|
-
} = new Intl.DateTimeFormat(locale, {
|
|
422
|
-
dateStyle: "medium"
|
|
423
|
-
});
|
|
424
|
-
return format;
|
|
425
|
-
}, [locale]);
|
|
426
|
-
return jsxs("div", {
|
|
427
|
-
css: {
|
|
428
|
-
padding: "calc(var(--spacing) * 2)",
|
|
429
|
-
display: "grid"
|
|
430
|
-
},
|
|
431
|
-
children: [!singleSelect && jsxs("div", {
|
|
432
|
-
css: {
|
|
433
|
-
marginBottom: "var(--spacing)",
|
|
434
|
-
display: "flex",
|
|
435
|
-
justifyContent: "center"
|
|
436
|
-
},
|
|
437
|
-
children: [value ? formatDate(value instanceof Date ? value : value.min) : "", " -", " ", value ? formatDate(value instanceof Date ? value : value.max) : ""]
|
|
438
|
-
}), jsx(DatePicker, {
|
|
439
|
-
rangeSelect: !singleSelect,
|
|
440
|
-
value,
|
|
441
|
-
onChange,
|
|
442
|
-
locale,
|
|
443
|
-
firstDayOfWeek
|
|
444
|
-
}), jsxs("div", {
|
|
445
|
-
css: {
|
|
446
|
-
marginTop: "var(--spacing)",
|
|
447
|
-
display: "grid",
|
|
448
|
-
gridAutoFlow: "column",
|
|
449
|
-
justifyContent: "center"
|
|
450
|
-
},
|
|
451
|
-
children: [jsx(Button, {
|
|
452
|
-
variant: "text",
|
|
453
|
-
onClick: () => onChange(today()),
|
|
454
|
-
children: text.today
|
|
455
|
-
}), jsx(Button, {
|
|
456
|
-
variant: "text",
|
|
457
|
-
onClick: () => onChange(thisWeek(firstDayOfWeek)),
|
|
458
|
-
children: text.thisWeek
|
|
459
|
-
}), jsx(Button, {
|
|
460
|
-
variant: "text",
|
|
461
|
-
onClick: () => onChange(null),
|
|
462
|
-
children: text.reset
|
|
463
|
-
})]
|
|
464
|
-
})]
|
|
465
|
-
});
|
|
182
|
+
}, []);
|
|
183
|
+
useEffect(() => {
|
|
184
|
+
if (!isHydrated)
|
|
185
|
+
return;
|
|
186
|
+
const q = new Queue();
|
|
187
|
+
return table.subscribe((state) => {
|
|
188
|
+
var _a, _b;
|
|
189
|
+
if (!state.props.persist)
|
|
190
|
+
return;
|
|
191
|
+
const { storage, id, include, exclude } = state.props.persist;
|
|
192
|
+
const data = {};
|
|
193
|
+
for (const key of KEYS) {
|
|
194
|
+
if ((!include || include.includes(key)) && !(exclude == null ? void 0 : exclude.includes(key))) {
|
|
195
|
+
if (key === "filterValues") {
|
|
196
|
+
data[key] = /* @__PURE__ */ new Map();
|
|
197
|
+
for (const [id2, value] of state.filterValues) {
|
|
198
|
+
if ((_b = (_a = state.filters.get(id2)) == null ? void 0 : _a.persist) != null ? _b : true) {
|
|
199
|
+
data.filterValues.set(id2, value);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
} else {
|
|
203
|
+
data[key] = state[key];
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
return { storage, id, data };
|
|
208
|
+
}, (props) => {
|
|
209
|
+
var _a, _b;
|
|
210
|
+
if (!props)
|
|
211
|
+
return;
|
|
212
|
+
const { storage, id, data } = props;
|
|
213
|
+
(_b = (_a = table.getState().props).debug) == null ? void 0 : _b.call(_a, "save", data, stringify(data));
|
|
214
|
+
q.run(async () => {
|
|
215
|
+
await storage.setItem(storageName(id), stringify(data));
|
|
216
|
+
}, true);
|
|
217
|
+
}, { throttle: 1e3 });
|
|
218
|
+
}, [isHydrated]);
|
|
219
|
+
return isHydrated;
|
|
466
220
|
}
|
|
467
|
-
const today = () => {
|
|
468
|
-
const today2 = startOfDay(new Date());
|
|
469
|
-
return {
|
|
470
|
-
min: today2,
|
|
471
|
-
max: today2
|
|
472
|
-
};
|
|
473
|
-
};
|
|
474
|
-
const thisWeek = (firstDayOfWeek = 0) => {
|
|
475
|
-
const now = new Date();
|
|
476
|
-
const min = new Date(now);
|
|
477
|
-
let diff = min.getDay() - firstDayOfWeek;
|
|
478
|
-
if (diff < 0) {
|
|
479
|
-
diff += 7;
|
|
480
|
-
}
|
|
481
|
-
min.setDate(min.getDate() - diff);
|
|
482
|
-
const max = new Date(min);
|
|
483
|
-
max.setDate(max.getDate() + 6);
|
|
484
|
-
return {
|
|
485
|
-
min: startOfDay(min),
|
|
486
|
-
max: endOfDay(max)
|
|
487
|
-
};
|
|
488
|
-
};
|
|
489
221
|
const flatMap = (arr, flatMap2) => {
|
|
490
222
|
return [...arr].reduce((out, cur) => out.concat(flatMap2(cur)), []);
|
|
491
223
|
};
|
|
492
224
|
const orderBy = (arr, selectors = [], direction = []) => {
|
|
493
225
|
if (selectors.length === 0)
|
|
494
226
|
selectors = [(t) => t];
|
|
495
|
-
return [...arr].sort((
|
|
227
|
+
return [...arr].sort((a, b) => {
|
|
496
228
|
var _a, _b;
|
|
497
229
|
for (let i = 0; i < selectors.length; i++) {
|
|
498
|
-
const _a2 = (_a = selectors[i]) == null ? void 0 : _a.call(selectors,
|
|
230
|
+
const _a2 = (_a = selectors[i]) == null ? void 0 : _a.call(selectors, a);
|
|
499
231
|
const _b2 = (_b = selectors[i]) == null ? void 0 : _b.call(selectors, b);
|
|
500
232
|
const dir = direction[i] === "desc" ? -1 : 1;
|
|
501
233
|
if (_a2 > _b2)
|
|
@@ -512,9 +244,9 @@ const uniq = (arr) => {
|
|
|
512
244
|
set.add(t);
|
|
513
245
|
return Array.from(set);
|
|
514
246
|
};
|
|
515
|
-
const intersect = (
|
|
247
|
+
const intersect = (a, b) => {
|
|
516
248
|
const result = /* @__PURE__ */ new Set();
|
|
517
|
-
for (const x of
|
|
249
|
+
for (const x of a)
|
|
518
250
|
if (b.has(x))
|
|
519
251
|
result.add(x);
|
|
520
252
|
return result;
|
|
@@ -556,236 +288,61 @@ const asStringOrArray = (x) => {
|
|
|
556
288
|
return x.map(asString);
|
|
557
289
|
return asString(x);
|
|
558
290
|
};
|
|
559
|
-
const castArray = (
|
|
291
|
+
const castArray = (a) => a instanceof Array ? a : [a];
|
|
560
292
|
const cx = (...classNames) => classNames.flatMap((entry) => {
|
|
561
293
|
if (!entry)
|
|
562
294
|
return [];
|
|
563
295
|
if (typeof entry === "string")
|
|
564
296
|
return [entry];
|
|
565
|
-
return Object.entries(entry).filter(([, predicate]) => predicate).map(([
|
|
297
|
+
return Object.entries(entry).filter(([, predicate]) => predicate).map(([className2]) => className2);
|
|
566
298
|
}).join(" ");
|
|
567
|
-
function
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
}
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
} catch (e) {
|
|
615
|
-
next.reject(e);
|
|
616
|
-
}
|
|
617
|
-
}
|
|
618
|
-
this.isRunning = false;
|
|
619
|
-
}
|
|
620
|
-
}
|
|
621
|
-
const KEYS = ["sort", "selection", "expanded", "hiddenColumns", "filterValues", "columnWidths", "columnOrder"];
|
|
622
|
-
const storageName = (id) => `schummar-table_state-v1_${id}`;
|
|
623
|
-
function stringify(value) {
|
|
624
|
-
function prepare(value2) {
|
|
625
|
-
if (value2 instanceof Date) {
|
|
626
|
-
return { __date: value2.toJSON() };
|
|
627
|
-
}
|
|
628
|
-
if (value2 instanceof Set) {
|
|
629
|
-
return { __set: Array.from(value2).map(prepare) };
|
|
630
|
-
}
|
|
631
|
-
if (value2 instanceof Map) {
|
|
632
|
-
return { __map: Array.from(value2.entries()).map((entry) => entry.map(prepare)) };
|
|
633
|
-
}
|
|
634
|
-
if (value2 instanceof Array) {
|
|
635
|
-
return value2.map(prepare);
|
|
636
|
-
}
|
|
637
|
-
if (value2 instanceof Object) {
|
|
638
|
-
return Object.fromEntries(Object.entries(value2).map(([k, v]) => [k, prepare(v)]));
|
|
639
|
-
}
|
|
640
|
-
return value2;
|
|
641
|
-
}
|
|
642
|
-
return JSON.stringify(prepare(value));
|
|
643
|
-
}
|
|
644
|
-
function parse(value) {
|
|
645
|
-
return JSON.parse(value, (_key, value2) => {
|
|
646
|
-
if (value2 instanceof Object && "__date" in value2) {
|
|
647
|
-
return new Date(value2.__date);
|
|
648
|
-
}
|
|
649
|
-
if (value2 instanceof Object && "__set" in value2) {
|
|
650
|
-
return new Set(value2.__set);
|
|
651
|
-
}
|
|
652
|
-
if (value2 instanceof Object && "__map" in value2) {
|
|
653
|
-
return new Map(value2.__map);
|
|
654
|
-
}
|
|
655
|
-
return value2;
|
|
656
|
-
});
|
|
657
|
-
}
|
|
658
|
-
function useTableStateStorage() {
|
|
659
|
-
const table = useTableContext();
|
|
660
|
-
const [isHydrated, setIsHydrated] = useState(false);
|
|
661
|
-
useEffect(() => {
|
|
662
|
-
const { persist } = table.getState().props;
|
|
663
|
-
if (!persist) {
|
|
664
|
-
setIsHydrated(true);
|
|
665
|
-
return;
|
|
666
|
-
}
|
|
667
|
-
let isCanceled = false;
|
|
668
|
-
(async () => {
|
|
669
|
-
var _a, _b;
|
|
670
|
-
try {
|
|
671
|
-
const { storage, id, include, exclude } = persist;
|
|
672
|
-
const json = await storage.getItem(storageName(id));
|
|
673
|
-
if (isCanceled || !json)
|
|
674
|
-
return;
|
|
675
|
-
const data = parse(json);
|
|
676
|
-
(_b = (_a = table.getState().props).debug) == null ? void 0 : _b.call(_a, "load", json, data);
|
|
677
|
-
table.update((state) => {
|
|
678
|
-
var _a2, _b2, _c, _d;
|
|
679
|
-
for (const key of KEYS) {
|
|
680
|
-
if ((!include || include.includes(key)) && !(exclude == null ? void 0 : exclude.includes(key)) && key in data) {
|
|
681
|
-
if (key === "filterValues") {
|
|
682
|
-
for (const [id2, value] of data[key]) {
|
|
683
|
-
if ((_b2 = (_a2 = state.filters.get(id2)) == null ? void 0 : _a2.persist) != null ? _b2 : true) {
|
|
684
|
-
state.filterValues.set(id2, value);
|
|
685
|
-
}
|
|
686
|
-
}
|
|
687
|
-
} else {
|
|
688
|
-
state[key] = data[key];
|
|
689
|
-
if (key === "expanded" || key === "hiddenColumns" || key === "selection" || key === "sort") {
|
|
690
|
-
(_d = (_c = state.props)[`on${key.slice(0, 1).toUpperCase() + key.slice(1)}Change`]) == null ? void 0 : _d.call(_c, data[key]);
|
|
691
|
-
}
|
|
692
|
-
}
|
|
693
|
-
}
|
|
694
|
-
}
|
|
695
|
-
});
|
|
696
|
-
} catch (e) {
|
|
697
|
-
console.error("Failed to load table state:", e);
|
|
698
|
-
} finally {
|
|
699
|
-
setIsHydrated(true);
|
|
700
|
-
}
|
|
701
|
-
})();
|
|
702
|
-
return () => {
|
|
703
|
-
isCanceled = true;
|
|
704
|
-
};
|
|
705
|
-
}, []);
|
|
706
|
-
useEffect(() => {
|
|
707
|
-
if (!isHydrated)
|
|
708
|
-
return;
|
|
709
|
-
const q = new Queue();
|
|
710
|
-
return table.subscribe((state) => {
|
|
711
|
-
var _a, _b;
|
|
712
|
-
if (!state.props.persist)
|
|
713
|
-
return;
|
|
714
|
-
const { storage, id, include, exclude } = state.props.persist;
|
|
715
|
-
const data = {};
|
|
716
|
-
for (const key of KEYS) {
|
|
717
|
-
if ((!include || include.includes(key)) && !(exclude == null ? void 0 : exclude.includes(key))) {
|
|
718
|
-
if (key === "filterValues") {
|
|
719
|
-
data[key] = /* @__PURE__ */ new Map();
|
|
720
|
-
for (const [id2, value] of state.filterValues) {
|
|
721
|
-
if ((_b = (_a = state.filters.get(id2)) == null ? void 0 : _a.persist) != null ? _b : true) {
|
|
722
|
-
data.filterValues.set(id2, value);
|
|
723
|
-
}
|
|
724
|
-
}
|
|
725
|
-
} else {
|
|
726
|
-
data[key] = state[key];
|
|
727
|
-
}
|
|
728
|
-
}
|
|
729
|
-
}
|
|
730
|
-
return { storage, id, data };
|
|
731
|
-
}, (props) => {
|
|
732
|
-
var _a, _b;
|
|
733
|
-
if (!props)
|
|
734
|
-
return;
|
|
735
|
-
const { storage, id, data } = props;
|
|
736
|
-
(_b = (_a = table.getState().props).debug) == null ? void 0 : _b.call(_a, "save", data, stringify(data));
|
|
737
|
-
q.run(async () => {
|
|
738
|
-
await storage.setItem(storageName(id), stringify(data));
|
|
739
|
-
}, true);
|
|
740
|
-
}, { throttle: 1e3 });
|
|
741
|
-
}, [isHydrated]);
|
|
742
|
-
return isHydrated;
|
|
743
|
-
}
|
|
744
|
-
function calcItems(state) {
|
|
745
|
-
useEffect(() => state.addReaction((state2) => [
|
|
746
|
-
state2.props.items,
|
|
747
|
-
state2.props.id,
|
|
748
|
-
state2.props.parentId,
|
|
749
|
-
state2.props.revealFiltered,
|
|
750
|
-
state2.sort,
|
|
751
|
-
state2.filters,
|
|
752
|
-
state2.filterValues,
|
|
753
|
-
state2.activeColumns,
|
|
754
|
-
state2.expanded
|
|
755
|
-
], ([items = [], id, parentId, revealFiltered, sort, filters, filterValues, activeColumns], draft) => {
|
|
756
|
-
const tableItems = items.map((item) => __spreadProps(__spreadValues({}, item), {
|
|
757
|
-
id: id(item),
|
|
758
|
-
parentId: parentId == null ? void 0 : parentId(item),
|
|
759
|
-
children: []
|
|
760
|
-
}));
|
|
761
|
-
let sorted;
|
|
762
|
-
if (sort.length === 0) {
|
|
763
|
-
sorted = tableItems;
|
|
764
|
-
} else {
|
|
765
|
-
const selectors = flatMap(sort, (sort2) => {
|
|
766
|
-
const column = activeColumns.find((column2) => column2.id === sort2.columnId);
|
|
767
|
-
if (!column)
|
|
768
|
-
return [];
|
|
769
|
-
const sortBy = column.sortBy instanceof Array ? column.sortBy : [column.sortBy];
|
|
770
|
-
return sortBy.map((sortBy2) => ({ selector: (item) => sortBy2(column.value(item), item), direction: sort2.direction }));
|
|
771
|
-
}).filter(Boolean);
|
|
772
|
-
sorted = orderBy(tableItems, selectors.map((x) => x.selector), selectors.map((x) => x.direction));
|
|
773
|
-
}
|
|
774
|
-
const lookup = /* @__PURE__ */ new Map();
|
|
775
|
-
for (const item of sorted) {
|
|
776
|
-
lookup.set(item.id, item);
|
|
777
|
-
}
|
|
778
|
-
for (const item of sorted) {
|
|
779
|
-
const parent = item.parentId !== void 0 ? lookup.get(item.parentId) : void 0;
|
|
780
|
-
parent == null ? void 0 : parent.children.push(item);
|
|
781
|
-
}
|
|
782
|
-
const allItems = new Array();
|
|
783
|
-
const allItemsById = /* @__PURE__ */ new Map();
|
|
784
|
-
const traverse = (items2) => {
|
|
785
|
-
for (const item of items2) {
|
|
786
|
-
allItems.push(item);
|
|
787
|
-
allItemsById.set(item.id, item);
|
|
788
|
-
traverse(item.children);
|
|
299
|
+
function calcItems(state) {
|
|
300
|
+
useEffect(() => state.addReaction((state2) => [
|
|
301
|
+
state2.props.items,
|
|
302
|
+
state2.props.id,
|
|
303
|
+
state2.props.parentId,
|
|
304
|
+
state2.props.revealFiltered,
|
|
305
|
+
state2.sort,
|
|
306
|
+
state2.filters,
|
|
307
|
+
state2.filterValues,
|
|
308
|
+
state2.activeColumns,
|
|
309
|
+
state2.expanded
|
|
310
|
+
], ([items = [], id, parentId, revealFiltered, sort, filters, filterValues, activeColumns], draft) => {
|
|
311
|
+
const tableItems = items.map((item) => __spreadProps(__spreadValues({}, item), {
|
|
312
|
+
id: id(item),
|
|
313
|
+
parentId: parentId == null ? void 0 : parentId(item),
|
|
314
|
+
children: []
|
|
315
|
+
}));
|
|
316
|
+
let sorted;
|
|
317
|
+
if (sort.length === 0) {
|
|
318
|
+
sorted = tableItems;
|
|
319
|
+
} else {
|
|
320
|
+
const selectors = flatMap(sort, (sort2) => {
|
|
321
|
+
const column = activeColumns.find((column2) => column2.id === sort2.columnId);
|
|
322
|
+
if (!column)
|
|
323
|
+
return [];
|
|
324
|
+
return column.sortBy.map((sortBy) => ({
|
|
325
|
+
selector: (item) => sortBy(column.value(item), item),
|
|
326
|
+
direction: sort2.direction
|
|
327
|
+
}));
|
|
328
|
+
}).filter(Boolean);
|
|
329
|
+
sorted = orderBy(tableItems, selectors.map((x) => x.selector), selectors.map((x) => x.direction));
|
|
330
|
+
}
|
|
331
|
+
const lookup = /* @__PURE__ */ new Map();
|
|
332
|
+
for (const item of sorted) {
|
|
333
|
+
lookup.set(item.id, item);
|
|
334
|
+
}
|
|
335
|
+
for (const item of sorted) {
|
|
336
|
+
const parent = item.parentId !== void 0 ? lookup.get(item.parentId) : void 0;
|
|
337
|
+
parent == null ? void 0 : parent.children.push(item);
|
|
338
|
+
}
|
|
339
|
+
const allItems = new Array();
|
|
340
|
+
const allItemsById = /* @__PURE__ */ new Map();
|
|
341
|
+
const traverse = (items2) => {
|
|
342
|
+
for (const item of items2) {
|
|
343
|
+
allItems.push(item);
|
|
344
|
+
allItemsById.set(item.id, item);
|
|
345
|
+
traverse(item.children);
|
|
789
346
|
}
|
|
790
347
|
};
|
|
791
348
|
traverse(sorted.filter((item) => item.parentId === void 0));
|
|
@@ -839,20 +396,20 @@ function calcItems(state) {
|
|
|
839
396
|
}
|
|
840
397
|
const noopParentId = () => void 0;
|
|
841
398
|
function calcProps(props) {
|
|
842
|
-
const
|
|
399
|
+
const cache = useTableMemo();
|
|
843
400
|
return useMemo(() => {
|
|
844
|
-
var
|
|
401
|
+
var _e, _f, _g, _h, _i, _j;
|
|
845
402
|
let id;
|
|
846
|
-
if (props.id instanceof Function) {
|
|
847
|
-
id = props.id;
|
|
403
|
+
if (props.id instanceof Function || Array.isArray(props.id)) {
|
|
404
|
+
id = cache("id", props.id);
|
|
848
405
|
} else {
|
|
849
|
-
id = (item) => item[props.id];
|
|
406
|
+
id = cache("id", [(item) => item[props.id], props.id]);
|
|
850
407
|
}
|
|
851
408
|
let parentId;
|
|
852
|
-
if (props.parentId instanceof Function) {
|
|
853
|
-
parentId = props.parentId;
|
|
854
|
-
} else if (
|
|
855
|
-
parentId = (item) => item[props.parentId];
|
|
409
|
+
if (props.parentId instanceof Function || Array.isArray(props.parentId)) {
|
|
410
|
+
parentId = cache("parentId", props.parentId);
|
|
411
|
+
} else if (props.parentId !== void 0) {
|
|
412
|
+
parentId = cache("parentId", [(item) => item[props.parentId], props.parentId]);
|
|
856
413
|
} else {
|
|
857
414
|
parentId = noopParentId;
|
|
858
415
|
}
|
|
@@ -862,42 +419,37 @@ function calcProps(props) {
|
|
|
862
419
|
} else {
|
|
863
420
|
inputColumns = props.columns.map((column) => __spreadProps(__spreadValues({}, column), { dependecies: void 0 }));
|
|
864
421
|
}
|
|
865
|
-
const
|
|
866
|
-
const
|
|
867
|
-
|
|
422
|
+
const defCol = props.defaultColumnProps;
|
|
423
|
+
const mapColumn = ({
|
|
424
|
+
id: _id,
|
|
425
|
+
header = ((_a) => (_a = defCol == null ? void 0 : defCol.header) != null ? _a : null)(),
|
|
426
|
+
value,
|
|
427
|
+
renderCell = ((_b) => (_b = defCol == null ? void 0 : defCol.renderCell) != null ? _b : asString)(),
|
|
428
|
+
exportCell = ((_c) => (_c = defCol == null ? void 0 : defCol.exportCell) != null ? _c : asString)(),
|
|
429
|
+
sortBy = ((_d) => (_d = defCol == null ? void 0 : defCol.sortBy) != null ? _d : [(v) => typeof v === "number" || v instanceof Date ? v : String(v)])(),
|
|
430
|
+
cannotHide = defCol == null ? void 0 : defCol.cannotHide,
|
|
431
|
+
classes = defCol == null ? void 0 : defCol.classes,
|
|
432
|
+
filter = defCol == null ? void 0 : defCol.filter,
|
|
433
|
+
width = defCol == null ? void 0 : defCol.width
|
|
434
|
+
}, index) => {
|
|
435
|
+
const id2 = _id != null ? _id : index;
|
|
436
|
+
const cacheKey = typeof id2 === "string" ? `s${id2}` : `n${id2}`;
|
|
437
|
+
return {
|
|
868
438
|
id: id2,
|
|
869
|
-
header
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
const [depsInCache, columnInCache] = (_a2 = columnCache.current.get(id2 != null ? id2 : index)) != null ? _a2 : [];
|
|
884
|
-
let column;
|
|
885
|
-
if (depsInCache && columnInCache && depsInCache.length === dependencies.length && depsInCache.every((x, i) => dependencies[i] === x)) {
|
|
886
|
-
column = columnInCache;
|
|
887
|
-
} else {
|
|
888
|
-
column = __spreadValues({
|
|
889
|
-
id: id2 != null ? id2 : index,
|
|
890
|
-
header,
|
|
891
|
-
renderCell,
|
|
892
|
-
exportCell,
|
|
893
|
-
sortBy,
|
|
894
|
-
dependencies
|
|
895
|
-
}, props2);
|
|
896
|
-
}
|
|
897
|
-
newColumnCache.set(id2 != null ? id2 : index, [dependencies, column]);
|
|
898
|
-
return column;
|
|
899
|
-
});
|
|
900
|
-
columnCache.current = newColumnCache;
|
|
439
|
+
header,
|
|
440
|
+
value: cache(`columns.${cacheKey}.value`, value),
|
|
441
|
+
renderCell: cache(`columns.${cacheKey}.renderCell`, renderCell),
|
|
442
|
+
exportCell,
|
|
443
|
+
sortBy: sortBy.map((fn, i) => cache(`columns.${cacheKey}.sortBy.${i}`, fn)),
|
|
444
|
+
cannotHide,
|
|
445
|
+
classes,
|
|
446
|
+
filter,
|
|
447
|
+
width
|
|
448
|
+
};
|
|
449
|
+
};
|
|
450
|
+
const columns = inputColumns.map(mapColumn);
|
|
451
|
+
const wrapCell = props.wrapCell && cache("wrapCell", props.wrapCell);
|
|
452
|
+
const rowAction = props.rowAction instanceof Function || Array.isArray(props.rowAction) ? cache("rowAction", props.rowAction) : props.rowAction;
|
|
901
453
|
let copy;
|
|
902
454
|
if (props.enableExport === true || props.enableExport instanceof Object && props.enableExport.copy === true) {
|
|
903
455
|
copy = { separator: " " };
|
|
@@ -915,13 +467,15 @@ function calcProps(props) {
|
|
|
915
467
|
id,
|
|
916
468
|
parentId,
|
|
917
469
|
columns,
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
470
|
+
wrapCell,
|
|
471
|
+
rowAction,
|
|
472
|
+
enableSelection: (_e = props.enableSelection) != null ? _e : true,
|
|
473
|
+
selectSyncChildren: (_f = props.selectSyncChildren) != null ? _f : true,
|
|
474
|
+
stickyHeader: (_g = props.stickyHeader) != null ? _g : true,
|
|
921
475
|
enableExport,
|
|
922
|
-
enableColumnSelection: (
|
|
923
|
-
enableColumnResize: (
|
|
924
|
-
enableColumnReorder: (
|
|
476
|
+
enableColumnSelection: (_h = props.enableColumnSelection) != null ? _h : true,
|
|
477
|
+
enableColumnResize: (_i = props.enableColumnResize) != null ? _i : true,
|
|
478
|
+
enableColumnReorder: (_j = props.enableColumnReorder) != null ? _j : true
|
|
925
479
|
});
|
|
926
480
|
}, [props]);
|
|
927
481
|
}
|
|
@@ -1003,12 +557,10 @@ function syncSelections(table) {
|
|
|
1003
557
|
}
|
|
1004
558
|
function useTableState(_props) {
|
|
1005
559
|
const props = calcProps(_props);
|
|
1006
|
-
const theme = useTableTheme(props);
|
|
1007
560
|
const state = useMemo(() => {
|
|
1008
561
|
var _a, _b, _c, _d;
|
|
1009
562
|
return new Store({
|
|
1010
563
|
props,
|
|
1011
|
-
theme,
|
|
1012
564
|
sort: (_a = props.defaultSort) != null ? _a : [],
|
|
1013
565
|
selection: (_b = props.defaultSelection) != null ? _b : /* @__PURE__ */ new Set(),
|
|
1014
566
|
expanded: (_c = props.defaultExpanded) != null ? _c : /* @__PURE__ */ new Set(),
|
|
@@ -1048,11 +600,21 @@ function useTableState(_props) {
|
|
|
1048
600
|
state2.columnOrder.splice(index, 0, column.id);
|
|
1049
601
|
}
|
|
1050
602
|
}
|
|
1051
|
-
state2.theme = theme;
|
|
1052
603
|
});
|
|
1053
604
|
}, [state, props]);
|
|
1054
605
|
return state;
|
|
1055
606
|
}
|
|
607
|
+
function useCssVariables() {
|
|
608
|
+
return useTheme(({ spacing, colors }) => ({
|
|
609
|
+
"--spacing": spacing,
|
|
610
|
+
"--primaryMain": colors.primary.main,
|
|
611
|
+
"--primaryLight": colors.primary.light,
|
|
612
|
+
"--primaryContrastText": colors.primary.contrastText,
|
|
613
|
+
"--secondaryMain": colors.secondary.main,
|
|
614
|
+
"--secondaryLight": colors.secondary.light,
|
|
615
|
+
"--secondaryContrastText": colors.secondary.contrastText
|
|
616
|
+
}));
|
|
617
|
+
}
|
|
1056
618
|
const ColumnHeaderContext = new StoreScope({
|
|
1057
619
|
items: /* @__PURE__ */ new Map()
|
|
1058
620
|
});
|
|
@@ -1096,22 +658,22 @@ function ColumnHeader(props) {
|
|
|
1096
658
|
});
|
|
1097
659
|
return targetIndex === -1 ? otherCols.length : targetIndex;
|
|
1098
660
|
}
|
|
1099
|
-
function onPointerDown(
|
|
661
|
+
function onPointerDown(e2) {
|
|
1100
662
|
const div = ref.current;
|
|
1101
663
|
if (!div)
|
|
1102
664
|
return;
|
|
1103
665
|
draggingStart.current = {
|
|
1104
|
-
mouseX:
|
|
666
|
+
mouseX: e2.clientX,
|
|
1105
667
|
bounds: div.getBoundingClientRect()
|
|
1106
668
|
};
|
|
1107
669
|
}
|
|
1108
|
-
function onPointerMove(
|
|
670
|
+
function onPointerMove(e2) {
|
|
1109
671
|
table.update((state) => {
|
|
1110
672
|
const div = ref.current;
|
|
1111
|
-
if (!div || draggingStart.current === void 0 || Math.abs(
|
|
673
|
+
if (!div || draggingStart.current === void 0 || Math.abs(e2.clientX - draggingStart.current.mouseX) < 5)
|
|
1112
674
|
return;
|
|
1113
|
-
|
|
1114
|
-
div.setPointerCapture(
|
|
675
|
+
e2.stopPropagation();
|
|
676
|
+
div.setPointerCapture(e2.pointerId);
|
|
1115
677
|
if (!clone.current) {
|
|
1116
678
|
clone.current = div.cloneNode(true);
|
|
1117
679
|
document.body.append(clone.current);
|
|
@@ -1130,9 +692,9 @@ function ColumnHeader(props) {
|
|
|
1130
692
|
});
|
|
1131
693
|
div.style.color = "rgba(0, 0, 0, 0.2)";
|
|
1132
694
|
}
|
|
1133
|
-
clone.current.style.left = `${draggingStart.current.bounds.left +
|
|
695
|
+
clone.current.style.left = `${draggingStart.current.bounds.left + e2.clientX - draggingStart.current.mouseX}px`;
|
|
1134
696
|
const index = state.columnOrder.indexOf(columnId);
|
|
1135
|
-
const targetIndex = calcTargetIndex(div.offsetLeft +
|
|
697
|
+
const targetIndex = calcTargetIndex(div.offsetLeft + e2.clientX - draggingStart.current.mouseX);
|
|
1136
698
|
const columns = table.getState().columnOrder.map((id, index2) => {
|
|
1137
699
|
var _a, _b;
|
|
1138
700
|
return {
|
|
@@ -1162,14 +724,14 @@ function ColumnHeader(props) {
|
|
|
1162
724
|
});
|
|
1163
725
|
});
|
|
1164
726
|
}
|
|
1165
|
-
function onPointerUp(
|
|
727
|
+
function onPointerUp(e2) {
|
|
1166
728
|
table.update((state) => {
|
|
1167
729
|
var _a;
|
|
1168
730
|
const div = ref.current;
|
|
1169
731
|
if (!div || draggingStart.current === void 0)
|
|
1170
732
|
return;
|
|
1171
733
|
const index = state.columnOrder.indexOf(columnId);
|
|
1172
|
-
const targetIndex = calcTargetIndex(div.offsetLeft +
|
|
734
|
+
const targetIndex = calcTargetIndex(div.offsetLeft + e2.clientX - draggingStart.current.mouseX);
|
|
1173
735
|
state.columnOrder.splice(index, 1);
|
|
1174
736
|
state.columnOrder.splice(targetIndex, 0, columnId);
|
|
1175
737
|
(_a = clone.current) == null ? void 0 : _a.remove();
|
|
@@ -1191,18 +753,37 @@ function ColumnHeader(props) {
|
|
|
1191
753
|
children: props.children
|
|
1192
754
|
}));
|
|
1193
755
|
}
|
|
756
|
+
function FormControlLabel({
|
|
757
|
+
control,
|
|
758
|
+
label,
|
|
759
|
+
disabled
|
|
760
|
+
}) {
|
|
761
|
+
return jsxs("label", {
|
|
762
|
+
css: [{
|
|
763
|
+
display: "flex",
|
|
764
|
+
alignItems: "center",
|
|
765
|
+
cursor: "pointer",
|
|
766
|
+
userSelect: "none",
|
|
767
|
+
"& > *": {
|
|
768
|
+
cursor: "pointer"
|
|
769
|
+
}
|
|
770
|
+
}, disabled && {
|
|
771
|
+
color: "rgba(0, 0, 0, 0.26)"
|
|
772
|
+
}],
|
|
773
|
+
children: [control, jsx("span", {
|
|
774
|
+
css: {
|
|
775
|
+
marginLeft: "var(--spacing)"
|
|
776
|
+
},
|
|
777
|
+
children: label
|
|
778
|
+
})]
|
|
779
|
+
});
|
|
780
|
+
}
|
|
1194
781
|
function ColumnSelection() {
|
|
1195
|
-
const
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
},
|
|
1201
|
-
icons: {
|
|
1202
|
-
Settings
|
|
1203
|
-
},
|
|
1204
|
-
text
|
|
1205
|
-
} = useTheme();
|
|
782
|
+
const IconButton2 = useTheme((t) => t.components.IconButton);
|
|
783
|
+
const Popover2 = useTheme((t) => t.components.Popover);
|
|
784
|
+
const Checkbox2 = useTheme((t) => t.components.Checkbox);
|
|
785
|
+
const Settings2 = useTheme((t) => t.icons.Settings);
|
|
786
|
+
const selectColumns = useTheme((t) => t.text.selectColumns);
|
|
1206
787
|
const cssVariables = useCssVariables();
|
|
1207
788
|
const table = useTableContext();
|
|
1208
789
|
const columns = table.useState("props.columns");
|
|
@@ -1228,10 +809,10 @@ function ColumnSelection() {
|
|
|
1228
809
|
onHiddenColumnsChange == null ? void 0 : onHiddenColumnsChange(newValue);
|
|
1229
810
|
};
|
|
1230
811
|
return jsxs(Fragment, {
|
|
1231
|
-
children: [jsx(
|
|
1232
|
-
onClick: (
|
|
1233
|
-
children: jsx(
|
|
1234
|
-
}), jsx(
|
|
812
|
+
children: [jsx(IconButton2, {
|
|
813
|
+
onClick: (e2) => setAnchorEl(anchorEl ? null : e2.currentTarget),
|
|
814
|
+
children: jsx(Settings2, {})
|
|
815
|
+
}), jsx(Popover2, {
|
|
1235
816
|
anchorEl,
|
|
1236
817
|
open: !!anchorEl,
|
|
1237
818
|
onClose: () => setAnchorEl(null),
|
|
@@ -1245,9 +826,9 @@ function ColumnSelection() {
|
|
|
1245
826
|
css: {
|
|
1246
827
|
marginBottom: "var(--spacing)"
|
|
1247
828
|
},
|
|
1248
|
-
children:
|
|
829
|
+
children: selectColumns
|
|
1249
830
|
}), columns.map((column) => jsx(FormControlLabel, {
|
|
1250
|
-
control: jsx(
|
|
831
|
+
control: jsx(Checkbox2, {
|
|
1251
832
|
checked: !hiddenColumns.has(column.id),
|
|
1252
833
|
onChange: () => toggle2(column),
|
|
1253
834
|
disabled: column.cannotHide
|
|
@@ -1262,7 +843,7 @@ function csvExport(data, { sepPrefix, separator = ",", quote = '"', eol = "\n" }
|
|
|
1262
843
|
const cells = data.map((line) => line.map((value) => {
|
|
1263
844
|
if (typeof value === "number")
|
|
1264
845
|
return String(value);
|
|
1265
|
-
if (![separator, quote, eol].some((
|
|
846
|
+
if (![separator, quote, eol].some((c) => value.includes(c)))
|
|
1266
847
|
return value;
|
|
1267
848
|
const clean = value.replace(new RegExp(quote, "g"), `${quote}${quote}`);
|
|
1268
849
|
return `${quote}${clean}${quote}`;
|
|
@@ -1270,20 +851,16 @@ function csvExport(data, { sepPrefix, separator = ",", quote = '"', eol = "\n" }
|
|
|
1270
851
|
return (sepPrefix ? `SEP=${separator}
|
|
1271
852
|
` : "") + cells.map((line) => line.join(separator)).join(eol);
|
|
1272
853
|
}
|
|
1273
|
-
function Export() {
|
|
854
|
+
function Export$1() {
|
|
1274
855
|
const table = useTableContext();
|
|
1275
|
-
const
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
Clipboard
|
|
1284
|
-
},
|
|
1285
|
-
text
|
|
1286
|
-
} = useTheme();
|
|
856
|
+
const Button2 = useTheme((t) => t.components.Button);
|
|
857
|
+
const IconButton2 = useTheme((t) => t.components.IconButton);
|
|
858
|
+
const Popover2 = useTheme((t) => t.components.Popover);
|
|
859
|
+
const Export2 = useTheme((t) => t.icons.Export);
|
|
860
|
+
const Clipboard2 = useTheme((t) => t.icons.Clipboard);
|
|
861
|
+
const exportTitle = useTheme((t) => t.text.exportTitle);
|
|
862
|
+
const exportCopy = useTheme((t) => t.text.exportCopy);
|
|
863
|
+
const exportDownload = useTheme((t) => t.text.exportDownload);
|
|
1287
864
|
const cssVariables = useCssVariables();
|
|
1288
865
|
const [anchor, setAnchor] = useState(null);
|
|
1289
866
|
const generate = (options) => {
|
|
@@ -1298,22 +875,22 @@ function Export() {
|
|
|
1298
875
|
navigator.clipboard.writeText(generate(table.getState().props.enableExport.copy));
|
|
1299
876
|
};
|
|
1300
877
|
const download = () => {
|
|
1301
|
-
const
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
document.body.appendChild(
|
|
1305
|
-
|
|
1306
|
-
document.body.removeChild(
|
|
878
|
+
const a = document.createElement("a");
|
|
879
|
+
a.href = "data:text/csv;charset=utf-8," + encodeURIComponent(generate(table.getState().props.enableExport.download));
|
|
880
|
+
a.download = "export.csv";
|
|
881
|
+
document.body.appendChild(a);
|
|
882
|
+
a.click();
|
|
883
|
+
document.body.removeChild(a);
|
|
1307
884
|
};
|
|
1308
885
|
return jsxs(Fragment, {
|
|
1309
|
-
children: [jsx(
|
|
1310
|
-
onClick: (
|
|
886
|
+
children: [jsx(IconButton2, {
|
|
887
|
+
onClick: (e2) => setAnchor(anchor ? null : e2.currentTarget),
|
|
1311
888
|
children: jsx(Export2, {
|
|
1312
889
|
css: !!anchor && {
|
|
1313
890
|
color: "var(--primaryMain)"
|
|
1314
891
|
}
|
|
1315
892
|
})
|
|
1316
|
-
}), jsx(
|
|
893
|
+
}), jsx(Popover2, {
|
|
1317
894
|
open: !!anchor,
|
|
1318
895
|
onClose: () => setAnchor(null),
|
|
1319
896
|
anchorEl: anchor,
|
|
@@ -1332,15 +909,15 @@ function Export() {
|
|
|
1332
909
|
css: {
|
|
1333
910
|
marginBottom: "var(--spacing)"
|
|
1334
911
|
},
|
|
1335
|
-
children:
|
|
1336
|
-
}), jsx(
|
|
1337
|
-
startIcon: jsx(
|
|
912
|
+
children: exportTitle
|
|
913
|
+
}), jsx(Button2, {
|
|
914
|
+
startIcon: jsx(Clipboard2, {}),
|
|
1338
915
|
onClick: copy,
|
|
1339
|
-
children:
|
|
1340
|
-
}), jsx(
|
|
916
|
+
children: exportCopy
|
|
917
|
+
}), jsx(Button2, {
|
|
1341
918
|
startIcon: jsx(Export2, {}),
|
|
1342
919
|
onClick: download,
|
|
1343
|
-
children:
|
|
920
|
+
children: exportDownload
|
|
1344
921
|
})]
|
|
1345
922
|
})
|
|
1346
923
|
})]
|
|
@@ -1350,16 +927,10 @@ const FilterControlContext = createContext(() => void 0);
|
|
|
1350
927
|
function FilterControl() {
|
|
1351
928
|
const table = useTableContext();
|
|
1352
929
|
const columnId = useColumnContext();
|
|
1353
|
-
const
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
},
|
|
1358
|
-
icons: {
|
|
1359
|
-
FilterList,
|
|
1360
|
-
ArrowDropDown
|
|
1361
|
-
}
|
|
1362
|
-
} = useTheme();
|
|
930
|
+
const IconButton2 = useTheme((t) => t.components.IconButton);
|
|
931
|
+
const Popover2 = useTheme((t) => t.components.Popover);
|
|
932
|
+
const FilterList2 = useTheme((t) => t.icons.FilterList);
|
|
933
|
+
const ArrowDropDown2 = useTheme((t) => t.icons.ArrowDropDown);
|
|
1363
934
|
const cssVariables = useCssVariables();
|
|
1364
935
|
const [anchor, setAnchor] = useState(null);
|
|
1365
936
|
const isActive = table.useState((state) => {
|
|
@@ -1384,28 +955,28 @@ function FilterControl() {
|
|
|
1384
955
|
return jsxs(FilterControlContext.Provider, {
|
|
1385
956
|
value: close,
|
|
1386
957
|
children: [jsx("div", {
|
|
1387
|
-
onClick: (
|
|
1388
|
-
onContextMenu: (
|
|
958
|
+
onClick: (e2) => setAnchor(e2.currentTarget),
|
|
959
|
+
onContextMenu: (e2) => {
|
|
1389
960
|
reset();
|
|
1390
|
-
|
|
961
|
+
e2.preventDefault();
|
|
1391
962
|
return false;
|
|
1392
963
|
},
|
|
1393
|
-
children: jsx(
|
|
964
|
+
children: jsx(IconButton2, {
|
|
1394
965
|
css: [{
|
|
1395
966
|
color: "#b0bac9"
|
|
1396
967
|
}, isActive && {
|
|
1397
968
|
color: "var(--primaryMain) !important"
|
|
1398
969
|
}],
|
|
1399
|
-
children: isActive ? jsx(
|
|
970
|
+
children: isActive ? jsx(FilterList2, {}) : jsx(ArrowDropDown2, {})
|
|
1400
971
|
})
|
|
1401
972
|
}), jsx("div", {
|
|
1402
|
-
onPointerDown: (
|
|
1403
|
-
|
|
973
|
+
onPointerDown: (e2) => {
|
|
974
|
+
e2.stopPropagation();
|
|
1404
975
|
},
|
|
1405
|
-
onPointerMove: (
|
|
1406
|
-
|
|
976
|
+
onPointerMove: (e2) => {
|
|
977
|
+
e2.stopPropagation();
|
|
1407
978
|
},
|
|
1408
|
-
children: jsx(
|
|
979
|
+
children: jsx(Popover2, {
|
|
1409
980
|
open: true,
|
|
1410
981
|
hidden: !anchor,
|
|
1411
982
|
onClose: () => setAnchor(null),
|
|
@@ -1420,30 +991,30 @@ function ResizeHandle() {
|
|
|
1420
991
|
const table = useTableContext();
|
|
1421
992
|
const columnId = useColumnContext();
|
|
1422
993
|
const enabled = table.useState("props.enableColumnResize");
|
|
1423
|
-
function onPointerDown(
|
|
1424
|
-
|
|
1425
|
-
const div =
|
|
1426
|
-
div.setPointerCapture(
|
|
994
|
+
function onPointerDown(e2) {
|
|
995
|
+
e2.stopPropagation();
|
|
996
|
+
const div = e2.target;
|
|
997
|
+
div.setPointerCapture(e2.pointerId);
|
|
1427
998
|
}
|
|
1428
|
-
function onPointerMove(
|
|
1429
|
-
|
|
1430
|
-
const div =
|
|
1431
|
-
if (!div.hasPointerCapture(
|
|
999
|
+
function onPointerMove(e2) {
|
|
1000
|
+
e2.stopPropagation();
|
|
1001
|
+
const div = e2.target;
|
|
1002
|
+
if (!div.hasPointerCapture(e2.pointerId))
|
|
1432
1003
|
return;
|
|
1433
1004
|
const parent = div.parentElement;
|
|
1434
|
-
const width = Math.max(
|
|
1005
|
+
const width = Math.max(e2.clientX - parent.getBoundingClientRect().left + 5, 50);
|
|
1435
1006
|
table.update((state) => {
|
|
1436
1007
|
state.columnWidths.set(columnId, `${width}px`);
|
|
1437
1008
|
});
|
|
1438
1009
|
}
|
|
1439
|
-
function onPointerUp(
|
|
1440
|
-
|
|
1441
|
-
const div =
|
|
1442
|
-
div.releasePointerCapture(
|
|
1010
|
+
function onPointerUp(e2) {
|
|
1011
|
+
e2.stopPropagation();
|
|
1012
|
+
const div = e2.target;
|
|
1013
|
+
div.releasePointerCapture(e2.pointerId);
|
|
1443
1014
|
}
|
|
1444
|
-
function onDoubleClick(
|
|
1015
|
+
function onDoubleClick(e2) {
|
|
1445
1016
|
table.update((state) => {
|
|
1446
|
-
if (
|
|
1017
|
+
if (e2.getModifierState("Control")) {
|
|
1447
1018
|
state.columnWidths.delete(columnId);
|
|
1448
1019
|
} else {
|
|
1449
1020
|
state.columnWidths.set(columnId, "max-content");
|
|
@@ -1458,10 +1029,10 @@ function ResizeHandle() {
|
|
|
1458
1029
|
onDoubleClick: enabled ? onDoubleClick : void 0
|
|
1459
1030
|
});
|
|
1460
1031
|
}
|
|
1461
|
-
function ResizeHandleView(
|
|
1462
|
-
var
|
|
1032
|
+
function ResizeHandleView(_a) {
|
|
1033
|
+
var _b = _a, {
|
|
1463
1034
|
enabled
|
|
1464
|
-
} =
|
|
1035
|
+
} = _b, props = __objRest(_b, [
|
|
1465
1036
|
"enabled"
|
|
1466
1037
|
]);
|
|
1467
1038
|
return jsx("div", __spreadValues({
|
|
@@ -1481,49 +1052,56 @@ function ResizeHandleView(_c) {
|
|
|
1481
1052
|
}
|
|
1482
1053
|
}, props));
|
|
1483
1054
|
}
|
|
1055
|
+
const defaultWrapCell = (content) => {
|
|
1056
|
+
if (typeof content === "string") {
|
|
1057
|
+
return jsx("span", {
|
|
1058
|
+
css: defaultClasses.text,
|
|
1059
|
+
title: content,
|
|
1060
|
+
children: content
|
|
1061
|
+
});
|
|
1062
|
+
}
|
|
1063
|
+
return content;
|
|
1064
|
+
};
|
|
1484
1065
|
const Cell = memo(function Cell2({
|
|
1485
1066
|
itemId,
|
|
1486
1067
|
rowIndex
|
|
1487
1068
|
}) {
|
|
1488
|
-
var _a
|
|
1069
|
+
var _a;
|
|
1489
1070
|
const table = useTableContext();
|
|
1490
1071
|
const columnId = useColumnContext();
|
|
1491
|
-
const {
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1072
|
+
const column = table.useState((state) => {
|
|
1073
|
+
const col = state.activeColumns.find((column2) => column2.id === columnId);
|
|
1074
|
+
return col && {
|
|
1075
|
+
value: col.value,
|
|
1076
|
+
renderCell: col.renderCell
|
|
1077
|
+
};
|
|
1078
|
+
});
|
|
1079
|
+
const wrapCell = (_a = table.useState((state) => state.props.wrapCell)) != null ? _a : defaultWrapCell;
|
|
1495
1080
|
const item = table.useState((state) => state.activeItemsById.get(itemId));
|
|
1496
1081
|
const columnStyleOverride = table.useState((state) => state.columnStyleOverride.get(columnId), {
|
|
1497
1082
|
throttle: 16
|
|
1498
1083
|
});
|
|
1084
|
+
useLayoutEffect(() => {
|
|
1085
|
+
var _a2, _b;
|
|
1086
|
+
return (_b = (_a2 = table.getState().props).debugRender) == null ? void 0 : _b.call(_a2, "render cell", itemId, columnId);
|
|
1087
|
+
});
|
|
1088
|
+
const className2 = useTheme((t) => cx(...calcClassNames(t.classes, item, rowIndex)));
|
|
1499
1089
|
if (!column || !item)
|
|
1500
1090
|
return null;
|
|
1501
|
-
(_b = (_a = table.getState().props).debugRender) == null ? void 0 : _b.call(_a, "render cell", itemId, columnId);
|
|
1502
|
-
const classNames = [...calcClassNames(classes, item, rowIndex), ...calcClassNames(column == null ? void 0 : column.classes, item, rowIndex)];
|
|
1503
1091
|
const content = column.renderCell(column.value(item), item);
|
|
1504
1092
|
return jsx("div", {
|
|
1505
|
-
className:
|
|
1506
|
-
css: [defaultClasses.cell,
|
|
1507
|
-
children:
|
|
1508
|
-
css: defaultClasses.text,
|
|
1509
|
-
title: content,
|
|
1510
|
-
children: content
|
|
1511
|
-
}) : content
|
|
1093
|
+
className: className2,
|
|
1094
|
+
css: [defaultClasses.cell, columnStyleOverride],
|
|
1095
|
+
children: wrapCell(content, column.value(item), item, rowIndex)
|
|
1512
1096
|
});
|
|
1513
1097
|
});
|
|
1514
1098
|
function ExpandControl({
|
|
1515
1099
|
itemId,
|
|
1516
1100
|
hasDeferredChildren
|
|
1517
1101
|
}) {
|
|
1518
|
-
const
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
Spinner
|
|
1522
|
-
},
|
|
1523
|
-
icons: {
|
|
1524
|
-
ChevronRight
|
|
1525
|
-
}
|
|
1526
|
-
} = useTheme();
|
|
1102
|
+
const IconButton2 = useTheme((t) => t.components.IconButton);
|
|
1103
|
+
const Spinner2 = useTheme((t) => t.components.Spinner);
|
|
1104
|
+
const ChevronRight2 = useTheme((t) => t.icons.ChevronRight);
|
|
1527
1105
|
const table = useTableContext();
|
|
1528
1106
|
const isExpanded = table.useState((state) => state.expanded.has(itemId));
|
|
1529
1107
|
const hasChildren = table.useState((state) => {
|
|
@@ -1560,13 +1138,13 @@ function ExpandControl({
|
|
|
1560
1138
|
}
|
|
1561
1139
|
}
|
|
1562
1140
|
if (isExpanded && hasDeferredChildren && !hasChildren) {
|
|
1563
|
-
return jsx(
|
|
1141
|
+
return jsx(Spinner2, {
|
|
1564
1142
|
css: {
|
|
1565
1143
|
margin: "0 var(--spacing)"
|
|
1566
1144
|
}
|
|
1567
1145
|
});
|
|
1568
1146
|
}
|
|
1569
|
-
return jsx(
|
|
1147
|
+
return jsx(IconButton2, {
|
|
1570
1148
|
onClick: toggle2,
|
|
1571
1149
|
children: jsx("span", {
|
|
1572
1150
|
css: {
|
|
@@ -1574,7 +1152,7 @@ function ExpandControl({
|
|
|
1574
1152
|
transition: "all 300ms",
|
|
1575
1153
|
transform: isExpanded ? "rotate3d(0, 0, 1, 90deg)" : "rotate3d(0, 0, 1, 0deg)"
|
|
1576
1154
|
},
|
|
1577
|
-
children: jsx(
|
|
1155
|
+
children: jsx(ChevronRight2, {})
|
|
1578
1156
|
})
|
|
1579
1157
|
});
|
|
1580
1158
|
}
|
|
@@ -1582,17 +1160,13 @@ function SelectComponent({
|
|
|
1582
1160
|
itemId
|
|
1583
1161
|
}) {
|
|
1584
1162
|
const table = useTableContext();
|
|
1585
|
-
const
|
|
1586
|
-
components: {
|
|
1587
|
-
Checkbox
|
|
1588
|
-
}
|
|
1589
|
-
} = useTheme();
|
|
1163
|
+
const Checkbox2 = useTheme((t) => t.components.Checkbox);
|
|
1590
1164
|
const isSelected = table.useState((state) => {
|
|
1591
1165
|
const itemIds = itemId ? [itemId] : Array.from(state.activeItemsById.keys());
|
|
1592
1166
|
return state.activeItemsById.size > 0 && itemIds.every((itemId2) => state.selection.has(itemId2));
|
|
1593
1167
|
});
|
|
1594
|
-
function toggle2(
|
|
1595
|
-
const mouseEvent =
|
|
1168
|
+
function toggle2(e2) {
|
|
1169
|
+
const mouseEvent = e2.nativeEvent;
|
|
1596
1170
|
const {
|
|
1597
1171
|
activeItems,
|
|
1598
1172
|
activeItemsById,
|
|
@@ -1606,9 +1180,9 @@ function SelectComponent({
|
|
|
1606
1180
|
} = table.getState();
|
|
1607
1181
|
let range;
|
|
1608
1182
|
if (mouseEvent.shiftKey && itemId) {
|
|
1609
|
-
const
|
|
1183
|
+
const a = lastSelectedId ? activeItems.findIndex((i) => lastSelectedId === i.id) : 0;
|
|
1610
1184
|
const b = activeItems.findIndex((item) => item.id === itemId);
|
|
1611
|
-
range = activeItems.slice(Math.min(
|
|
1185
|
+
range = activeItems.slice(Math.min(a, b), Math.max(a, b) + 1);
|
|
1612
1186
|
} else {
|
|
1613
1187
|
const item = itemId ? activeItemsById.get(itemId) : void 0;
|
|
1614
1188
|
range = item ? [item] : activeItems;
|
|
@@ -1638,7 +1212,7 @@ function SelectComponent({
|
|
|
1638
1212
|
state.lastSelectedId = itemId;
|
|
1639
1213
|
});
|
|
1640
1214
|
}
|
|
1641
|
-
return jsx(
|
|
1215
|
+
return jsx(Checkbox2, {
|
|
1642
1216
|
css: {
|
|
1643
1217
|
justifySelf: "start",
|
|
1644
1218
|
color: "#c9cfda"
|
|
@@ -1654,11 +1228,11 @@ const Row = memo(function Row2({
|
|
|
1654
1228
|
itemId,
|
|
1655
1229
|
rowIndex
|
|
1656
1230
|
}) {
|
|
1657
|
-
var _a, _b;
|
|
1658
1231
|
const table = useTableContext();
|
|
1659
1232
|
const divRef = useRef(null);
|
|
1233
|
+
const classes = useTheme((t) => t.classes);
|
|
1660
1234
|
const {
|
|
1661
|
-
className,
|
|
1235
|
+
className: className2,
|
|
1662
1236
|
indent,
|
|
1663
1237
|
hasChildren,
|
|
1664
1238
|
hasDeferredChildren,
|
|
@@ -1666,17 +1240,16 @@ const Row = memo(function Row2({
|
|
|
1666
1240
|
enableSelection,
|
|
1667
1241
|
rowAction
|
|
1668
1242
|
} = table.useState((state) => {
|
|
1669
|
-
var
|
|
1243
|
+
var _a, _b;
|
|
1670
1244
|
const item = state.activeItemsById.get(itemId);
|
|
1671
|
-
const index = !item ? -1 : state.activeItems.indexOf(item);
|
|
1672
1245
|
return {
|
|
1673
|
-
className: cx(...calcClassNames(
|
|
1246
|
+
className: cx(...calcClassNames(classes, item, rowIndex)),
|
|
1674
1247
|
indent: item ? getAncestors(state.activeItemsById, item).size : 0,
|
|
1675
1248
|
hasChildren: !!(item == null ? void 0 : item.children.length),
|
|
1676
|
-
hasDeferredChildren: item && ((
|
|
1249
|
+
hasDeferredChildren: item && ((_b = (_a = state.props).hasDeferredChildren) == null ? void 0 : _b.call(_a, item)),
|
|
1677
1250
|
columnIds: state.activeColumns.map((column) => column.id),
|
|
1678
1251
|
enableSelection: state.props.enableSelection,
|
|
1679
|
-
rowAction: state.props.rowAction instanceof Function ? item ? state.props.rowAction(item,
|
|
1252
|
+
rowAction: state.props.rowAction instanceof Function ? item ? state.props.rowAction(item, rowIndex) : null : state.props.rowAction
|
|
1680
1253
|
};
|
|
1681
1254
|
});
|
|
1682
1255
|
useEffect(() => {
|
|
@@ -1693,14 +1266,17 @@ const Row = memo(function Row2({
|
|
|
1693
1266
|
o.observe(div);
|
|
1694
1267
|
return () => o.disconnect();
|
|
1695
1268
|
}, [divRef.current]);
|
|
1696
|
-
(
|
|
1269
|
+
useLayoutEffect(() => {
|
|
1270
|
+
var _a, _b;
|
|
1271
|
+
return (_b = (_a = table.getState().props).debugRender) == null ? void 0 : _b.call(_a, "render row", itemId);
|
|
1272
|
+
});
|
|
1697
1273
|
return jsxs(Fragment, {
|
|
1698
1274
|
children: [jsx("div", {
|
|
1699
|
-
className,
|
|
1275
|
+
className: className2,
|
|
1700
1276
|
css: [defaultClasses.cellFill],
|
|
1701
1277
|
ref: divRef
|
|
1702
1278
|
}), jsxs("div", {
|
|
1703
|
-
className,
|
|
1279
|
+
className: className2,
|
|
1704
1280
|
css: [defaultClasses.cell, defaultClasses.firstCell],
|
|
1705
1281
|
children: [jsx("div", {
|
|
1706
1282
|
css: {
|
|
@@ -1719,7 +1295,7 @@ const Row = memo(function Row2({
|
|
|
1719
1295
|
rowIndex
|
|
1720
1296
|
})
|
|
1721
1297
|
}, columnId)), jsx("div", {
|
|
1722
|
-
className,
|
|
1298
|
+
className: className2,
|
|
1723
1299
|
css: [defaultClasses.cellFill]
|
|
1724
1300
|
})]
|
|
1725
1301
|
});
|
|
@@ -1729,14 +1305,8 @@ function SortComponent({
|
|
|
1729
1305
|
}) {
|
|
1730
1306
|
const table = useTableContext();
|
|
1731
1307
|
const columnId = useColumnContext();
|
|
1732
|
-
const
|
|
1733
|
-
|
|
1734
|
-
Badge
|
|
1735
|
-
},
|
|
1736
|
-
icons: {
|
|
1737
|
-
ArrowUpward
|
|
1738
|
-
}
|
|
1739
|
-
} = useTheme();
|
|
1308
|
+
const Badge2 = useTheme((t) => t.components.Badge);
|
|
1309
|
+
const ArrowUpward2 = useTheme((t) => t.icons.ArrowUpward);
|
|
1740
1310
|
const {
|
|
1741
1311
|
direction,
|
|
1742
1312
|
index
|
|
@@ -1748,7 +1318,7 @@ function SortComponent({
|
|
|
1748
1318
|
index: index2 >= 0 && state.sort.length > 1 ? index2 + 1 : void 0
|
|
1749
1319
|
};
|
|
1750
1320
|
});
|
|
1751
|
-
function toggle2(
|
|
1321
|
+
function toggle2(e2, off) {
|
|
1752
1322
|
const {
|
|
1753
1323
|
props: {
|
|
1754
1324
|
sort: controlledSort,
|
|
@@ -1756,7 +1326,7 @@ function SortComponent({
|
|
|
1756
1326
|
}
|
|
1757
1327
|
} = table.getState();
|
|
1758
1328
|
const newDirection = direction === "asc" ? "desc" : "asc";
|
|
1759
|
-
const newSort =
|
|
1329
|
+
const newSort = e2.getModifierState("Control") || off ? table.getState().sort.filter((s) => s.columnId !== columnId) : [];
|
|
1760
1330
|
if (!off) {
|
|
1761
1331
|
newSort.push({
|
|
1762
1332
|
columnId,
|
|
@@ -1769,7 +1339,7 @@ function SortComponent({
|
|
|
1769
1339
|
state.sort = newSort;
|
|
1770
1340
|
});
|
|
1771
1341
|
}
|
|
1772
|
-
|
|
1342
|
+
e2.preventDefault();
|
|
1773
1343
|
return false;
|
|
1774
1344
|
}
|
|
1775
1345
|
return jsxs("div", {
|
|
@@ -1784,11 +1354,11 @@ function SortComponent({
|
|
|
1784
1354
|
textOverflow: "ellipsis"
|
|
1785
1355
|
}
|
|
1786
1356
|
},
|
|
1787
|
-
onClick: (
|
|
1788
|
-
onContextMenu: (
|
|
1357
|
+
onClick: (e2) => toggle2(e2),
|
|
1358
|
+
onContextMenu: (e2) => toggle2(e2, true),
|
|
1789
1359
|
children: [jsx("div", {
|
|
1790
1360
|
children
|
|
1791
|
-
}), jsx(
|
|
1361
|
+
}), jsx(Badge2, {
|
|
1792
1362
|
badgeContent: index,
|
|
1793
1363
|
children: jsx("span", {
|
|
1794
1364
|
css: [{
|
|
@@ -1799,7 +1369,7 @@ function SortComponent({
|
|
|
1799
1369
|
}, direction === "desc" && {
|
|
1800
1370
|
transform: "rotate3d(0, 0, 1, 180deg)"
|
|
1801
1371
|
}],
|
|
1802
|
-
children: jsx(
|
|
1372
|
+
children: jsx(ArrowUpward2, {})
|
|
1803
1373
|
})
|
|
1804
1374
|
})]
|
|
1805
1375
|
});
|
|
@@ -1830,6 +1400,11 @@ function throttle(fn, ms) {
|
|
|
1830
1400
|
if (lastArgs) {
|
|
1831
1401
|
run();
|
|
1832
1402
|
}
|
|
1403
|
+
},
|
|
1404
|
+
cancel() {
|
|
1405
|
+
if (timeout) {
|
|
1406
|
+
clearTimeout(timeout);
|
|
1407
|
+
}
|
|
1833
1408
|
}
|
|
1834
1409
|
});
|
|
1835
1410
|
}
|
|
@@ -1848,15 +1423,15 @@ const relativeOffset = (x, y) => {
|
|
|
1848
1423
|
return relativeOffset(x.offsetParent, y) + x.offsetTop;
|
|
1849
1424
|
return 0;
|
|
1850
1425
|
};
|
|
1851
|
-
function Virtualized(
|
|
1852
|
-
var
|
|
1426
|
+
function Virtualized(_c) {
|
|
1427
|
+
var _d = _c, {
|
|
1853
1428
|
header,
|
|
1854
1429
|
children
|
|
1855
|
-
} =
|
|
1430
|
+
} = _d, props = __objRest(_d, [
|
|
1856
1431
|
"header",
|
|
1857
1432
|
"children"
|
|
1858
1433
|
]);
|
|
1859
|
-
var _a, _b
|
|
1434
|
+
var _a, _b;
|
|
1860
1435
|
const table = useTableContext();
|
|
1861
1436
|
const virtual = table.useState("props.virtual");
|
|
1862
1437
|
const probeRef = useRef(null);
|
|
@@ -1919,150 +1494,1091 @@ function Virtualized(_e) {
|
|
|
1919
1494
|
throttle: 16
|
|
1920
1495
|
});
|
|
1921
1496
|
const throttleScroll = (_b = (_a = typeof virtual === "boolean" ? void 0 : virtual) == null ? void 0 : _a.throttleScroll) != null ? _b : 16;
|
|
1922
|
-
const incCounter = useMemo(() => throttle(() => setCounter((
|
|
1497
|
+
const incCounter = useMemo(() => throttle(() => setCounter((c) => c + 1), throttleScroll), [throttleScroll]);
|
|
1923
1498
|
useEffect(() => {
|
|
1924
1499
|
if (!virtual || !probeRef.current)
|
|
1925
1500
|
return;
|
|
1926
1501
|
window.addEventListener("scroll", incCounter, true);
|
|
1502
|
+
window.addEventListener("resize", incCounter, true);
|
|
1927
1503
|
return () => {
|
|
1928
1504
|
window.removeEventListener("scroll", incCounter, true);
|
|
1505
|
+
window.removeEventListener("resize", incCounter, true);
|
|
1929
1506
|
};
|
|
1930
1507
|
}, [probeRef.current, incCounter]);
|
|
1931
|
-
(
|
|
1508
|
+
useEffect(() => incCounter.cancel, [incCounter]);
|
|
1509
|
+
useLayoutEffect(() => {
|
|
1510
|
+
var _a2, _b2;
|
|
1511
|
+
return (_b2 = (_a2 = table.getState().props).debugRender) == null ? void 0 : _b2.call(_a2, `Virtualalized render ${from} to ${to}`);
|
|
1512
|
+
});
|
|
1932
1513
|
return jsxs("div", __spreadProps(__spreadValues({}, props), {
|
|
1933
1514
|
children: [header, virtual && jsx("div", {
|
|
1934
1515
|
style: {
|
|
1935
1516
|
gridColumn: "1 / -1",
|
|
1936
1517
|
height: before
|
|
1937
1518
|
},
|
|
1938
|
-
ref: probeRef
|
|
1939
|
-
}), children(itemIds, from), virtual && jsx("div", {
|
|
1940
|
-
style: {
|
|
1941
|
-
gridColumn: "1 / -1",
|
|
1942
|
-
height: after
|
|
1943
|
-
}
|
|
1519
|
+
ref: probeRef
|
|
1520
|
+
}), children(itemIds, from), virtual && jsx("div", {
|
|
1521
|
+
style: {
|
|
1522
|
+
gridColumn: "1 / -1",
|
|
1523
|
+
height: after
|
|
1524
|
+
}
|
|
1525
|
+
})]
|
|
1526
|
+
}));
|
|
1527
|
+
}
|
|
1528
|
+
const TableContext = createContext(null);
|
|
1529
|
+
const ColumnContext = createContext(null);
|
|
1530
|
+
function useTableContext() {
|
|
1531
|
+
const value = useContext(TableContext);
|
|
1532
|
+
if (!value)
|
|
1533
|
+
throw Error("No table context available");
|
|
1534
|
+
return value;
|
|
1535
|
+
}
|
|
1536
|
+
function useColumnContext() {
|
|
1537
|
+
const value = useContext(ColumnContext);
|
|
1538
|
+
if (value === null)
|
|
1539
|
+
throw Error("No column context available");
|
|
1540
|
+
return value;
|
|
1541
|
+
}
|
|
1542
|
+
function Table(props) {
|
|
1543
|
+
const table = useTableState(props);
|
|
1544
|
+
useLayoutEffect(() => {
|
|
1545
|
+
var _a, _b;
|
|
1546
|
+
return (_b = (_a = table.getState().props).debugRender) == null ? void 0 : _b.call(_a, "render table");
|
|
1547
|
+
});
|
|
1548
|
+
return jsx(TableContext.Provider, {
|
|
1549
|
+
value: table,
|
|
1550
|
+
children: jsx(TableMemoContextProvider, {
|
|
1551
|
+
children: jsx(TableLoadingState, {})
|
|
1552
|
+
})
|
|
1553
|
+
});
|
|
1554
|
+
}
|
|
1555
|
+
function TableLoadingState() {
|
|
1556
|
+
const loadingText = useTheme((t) => t.text.loading);
|
|
1557
|
+
const isHydrated = useTableStateStorage();
|
|
1558
|
+
const [showLoading, setShowLoading] = useState(false);
|
|
1559
|
+
useEffect(() => {
|
|
1560
|
+
const handle = setTimeout(() => setShowLoading(true), 500);
|
|
1561
|
+
return () => clearTimeout(handle);
|
|
1562
|
+
});
|
|
1563
|
+
return jsxs(Fragment, {
|
|
1564
|
+
children: [!isHydrated && showLoading && jsx("div", {
|
|
1565
|
+
children: loadingText
|
|
1566
|
+
}), jsx(TableInner, {
|
|
1567
|
+
hidden: !isHydrated
|
|
1568
|
+
})]
|
|
1569
|
+
});
|
|
1570
|
+
}
|
|
1571
|
+
const TableInner = memo(function TableInner2({
|
|
1572
|
+
hidden
|
|
1573
|
+
}) {
|
|
1574
|
+
const table = useTableContext();
|
|
1575
|
+
const fullWidth = table.useState("props.fullWidth");
|
|
1576
|
+
const activeColumns = table.useState((state) => state.activeColumns.map((column) => ({
|
|
1577
|
+
id: column.id,
|
|
1578
|
+
width: column.width,
|
|
1579
|
+
classes: column.classes,
|
|
1580
|
+
header: column.header
|
|
1581
|
+
})));
|
|
1582
|
+
const columnWidths = table.useState("columnWidths", {
|
|
1583
|
+
throttle: 16
|
|
1584
|
+
});
|
|
1585
|
+
const columnStyleOverride = table.useState("columnStyleOverride", {
|
|
1586
|
+
throttle: 16
|
|
1587
|
+
});
|
|
1588
|
+
const classes = table.useState("props.classes");
|
|
1589
|
+
const stickyHeader = table.useState("props.stickyHeader");
|
|
1590
|
+
const enableSelection = table.useState("props.enableSelection");
|
|
1591
|
+
const enableColumnSelection = table.useState("props.enableColumnSelection");
|
|
1592
|
+
const enableExport = table.useState((state) => !!state.props.enableExport.copy || !!state.props.enableExport.download);
|
|
1593
|
+
const cssVariables = useCssVariables();
|
|
1594
|
+
useLayoutEffect(() => {
|
|
1595
|
+
var _a, _b;
|
|
1596
|
+
return (_b = (_a = table.getState().props).debugRender) == null ? void 0 : _b.call(_a, "render table inner");
|
|
1597
|
+
});
|
|
1598
|
+
return jsx(Virtualized, {
|
|
1599
|
+
className: classes == null ? void 0 : classes.table,
|
|
1600
|
+
css: [cssVariables, defaultClasses.table, {
|
|
1601
|
+
gridTemplateColumns: [
|
|
1602
|
+
fullWidth === "right" || fullWidth === true ? "auto" : "0",
|
|
1603
|
+
"max-content",
|
|
1604
|
+
...activeColumns.map((column) => {
|
|
1605
|
+
var _a, _b;
|
|
1606
|
+
return (_b = (_a = columnWidths.get(column.id)) != null ? _a : column.width) != null ? _b : "max-content";
|
|
1607
|
+
}),
|
|
1608
|
+
fullWidth === "left" || fullWidth === true ? "auto" : "0"
|
|
1609
|
+
].join(" ")
|
|
1610
|
+
}, hidden && {
|
|
1611
|
+
visibility: "hidden"
|
|
1612
|
+
}],
|
|
1613
|
+
header: jsxs(Fragment, {
|
|
1614
|
+
children: [jsx("div", {
|
|
1615
|
+
className: classes == null ? void 0 : classes.headerCell,
|
|
1616
|
+
css: [defaultClasses.headerFill, stickyHeader && defaultClasses.sticky, stickyHeader instanceof Object && stickyHeader]
|
|
1617
|
+
}), jsxs("div", {
|
|
1618
|
+
className: classes == null ? void 0 : classes.headerCell,
|
|
1619
|
+
css: [defaultClasses.headerCell, stickyHeader && defaultClasses.sticky, stickyHeader instanceof Object && stickyHeader],
|
|
1620
|
+
children: [enableSelection && jsx(SelectComponent, {}), enableColumnSelection && jsx(ColumnSelection, {}), enableExport && jsx(Export$1, {}), jsx(ResizeHandleView, {})]
|
|
1621
|
+
}), jsx(ColumnHeaderContext.Provider, {
|
|
1622
|
+
children: activeColumns.map((column) => {
|
|
1623
|
+
var _a;
|
|
1624
|
+
return jsx(ColumnContext.Provider, {
|
|
1625
|
+
value: column.id,
|
|
1626
|
+
children: jsxs(ColumnHeader, {
|
|
1627
|
+
className: cx(classes == null ? void 0 : classes.headerCell, (_a = column.classes) == null ? void 0 : _a.headerCell),
|
|
1628
|
+
css: [defaultClasses.headerCell, columnStyleOverride.get(column.id), stickyHeader && defaultClasses.sticky, stickyHeader instanceof Object && stickyHeader],
|
|
1629
|
+
children: [jsx(SortComponent, {
|
|
1630
|
+
children: column.header
|
|
1631
|
+
}), jsx("div", {
|
|
1632
|
+
css: {
|
|
1633
|
+
flex: 1
|
|
1634
|
+
}
|
|
1635
|
+
}), jsx(FilterControl, {}), jsx(ResizeHandle, {})]
|
|
1636
|
+
}, column.id)
|
|
1637
|
+
}, column.id);
|
|
1638
|
+
})
|
|
1639
|
+
}), jsx("div", {
|
|
1640
|
+
className: classes == null ? void 0 : classes.headerCell,
|
|
1641
|
+
css: [defaultClasses.headerFill, stickyHeader && defaultClasses.sticky, stickyHeader instanceof Object && stickyHeader]
|
|
1642
|
+
})]
|
|
1643
|
+
}),
|
|
1644
|
+
children: (itemIds, startIndex) => itemIds.map((itemId, index) => jsx(Row, {
|
|
1645
|
+
itemId,
|
|
1646
|
+
rowIndex: startIndex + index
|
|
1647
|
+
}, itemId))
|
|
1648
|
+
});
|
|
1649
|
+
});
|
|
1650
|
+
const defaultColors = {
|
|
1651
|
+
primary: { main: "#1976d2", light: "#42a5f5", contrastText: "#fff" },
|
|
1652
|
+
secondary: { main: "#9c27b0", light: "#ba68c8", contrastText: "#fff" }
|
|
1653
|
+
};
|
|
1654
|
+
function Spinner({
|
|
1655
|
+
className: className2
|
|
1656
|
+
}) {
|
|
1657
|
+
return jsxs("div", {
|
|
1658
|
+
className: className2,
|
|
1659
|
+
css: css`
|
|
1660
|
+
display: inline-block;
|
|
1661
|
+
position: relative;
|
|
1662
|
+
width: 1em;
|
|
1663
|
+
height: 1em;
|
|
1664
|
+
|
|
1665
|
+
div {
|
|
1666
|
+
box-sizing: border-box;
|
|
1667
|
+
display: block;
|
|
1668
|
+
position: absolute;
|
|
1669
|
+
width: 0.8em;
|
|
1670
|
+
height: 0.8em;
|
|
1671
|
+
margin: 0.1em;
|
|
1672
|
+
border: 0.1em solid #fff;
|
|
1673
|
+
border-radius: 50%;
|
|
1674
|
+
animation: lds-ring 1.2s cubic-bezier(0.5, 0, 0.5, 1) infinite;
|
|
1675
|
+
border-color: currentColor transparent transparent transparent;
|
|
1676
|
+
}
|
|
1677
|
+
div:nth-of-type(1) {
|
|
1678
|
+
animation-delay: -0.45s;
|
|
1679
|
+
}
|
|
1680
|
+
div:nth-of-type(2) {
|
|
1681
|
+
animation-delay: -0.3s;
|
|
1682
|
+
}
|
|
1683
|
+
div:nth-of-type(3) {
|
|
1684
|
+
animation-delay: -0.15s;
|
|
1685
|
+
}
|
|
1686
|
+
@keyframes lds-ring {
|
|
1687
|
+
0% {
|
|
1688
|
+
transform: rotate(0deg);
|
|
1689
|
+
}
|
|
1690
|
+
100% {
|
|
1691
|
+
transform: rotate(360deg);
|
|
1692
|
+
}
|
|
1693
|
+
}
|
|
1694
|
+
`,
|
|
1695
|
+
children: [jsx("div", {}), jsx("div", {}), jsx("div", {})]
|
|
1696
|
+
});
|
|
1697
|
+
}
|
|
1698
|
+
const Badge = ({
|
|
1699
|
+
badgeContent,
|
|
1700
|
+
children
|
|
1701
|
+
}) => {
|
|
1702
|
+
if (!open)
|
|
1703
|
+
return null;
|
|
1704
|
+
return jsxs("span", {
|
|
1705
|
+
css: {
|
|
1706
|
+
display: "inline-flex",
|
|
1707
|
+
position: "relative",
|
|
1708
|
+
flexShrink: 0,
|
|
1709
|
+
verticalAlign: "middle"
|
|
1710
|
+
},
|
|
1711
|
+
children: [children, jsx("span", {
|
|
1712
|
+
css: [{
|
|
1713
|
+
top: 0,
|
|
1714
|
+
right: 0,
|
|
1715
|
+
transform: "scale(1) translate(50%, -50%)",
|
|
1716
|
+
transformOrigin: "100% 0%",
|
|
1717
|
+
height: 20,
|
|
1718
|
+
display: "flex",
|
|
1719
|
+
padding: "0 6px",
|
|
1720
|
+
zIndex: 1,
|
|
1721
|
+
position: "absolute",
|
|
1722
|
+
flexWrap: "wrap",
|
|
1723
|
+
minWidth: 20,
|
|
1724
|
+
transition: "transform 225ms cubic-bezier(0.4, 0, 0.2, 1) 0ms",
|
|
1725
|
+
alignItems: "center",
|
|
1726
|
+
lineHeight: 1,
|
|
1727
|
+
alignContent: "center",
|
|
1728
|
+
borderRadius: 10,
|
|
1729
|
+
justifyContent: "center",
|
|
1730
|
+
fontSize: "0.8em"
|
|
1731
|
+
}, !badgeContent && {
|
|
1732
|
+
transform: "scale(0) translate(50%, -50%)",
|
|
1733
|
+
transition: "transform 195ms cubic-bezier(0.4, 0, 0.2, 1) 0ms"
|
|
1734
|
+
}],
|
|
1735
|
+
children: badgeContent
|
|
1736
|
+
})]
|
|
1737
|
+
});
|
|
1738
|
+
};
|
|
1739
|
+
const Button = (_e) => {
|
|
1740
|
+
var _f = _e, {
|
|
1741
|
+
startIcon,
|
|
1742
|
+
children,
|
|
1743
|
+
variant = "text"
|
|
1744
|
+
} = _f, props = __objRest(_f, [
|
|
1745
|
+
"startIcon",
|
|
1746
|
+
"children",
|
|
1747
|
+
"variant"
|
|
1748
|
+
]);
|
|
1749
|
+
return jsxs("button", __spreadProps(__spreadValues({
|
|
1750
|
+
css: [{
|
|
1751
|
+
padding: `var(--spacing) calc(var(--spacing) * 2)`,
|
|
1752
|
+
display: "inline-flex",
|
|
1753
|
+
alignItems: "center",
|
|
1754
|
+
transition: "background-color 150ms",
|
|
1755
|
+
border: "none",
|
|
1756
|
+
cursor: "pointer",
|
|
1757
|
+
background: "transparent",
|
|
1758
|
+
borderRadius: 4,
|
|
1759
|
+
"&:active:not(:disabled)": {
|
|
1760
|
+
transform: "scale3d(0.95, 0.95, 1)"
|
|
1761
|
+
}
|
|
1762
|
+
}, variant === "text" && {
|
|
1763
|
+
"&:hover": {
|
|
1764
|
+
background: "rgba(0, 0, 0, 0.1)"
|
|
1765
|
+
}
|
|
1766
|
+
}, variant === "outlined" && {
|
|
1767
|
+
border: `1px solid ${darkGray}`,
|
|
1768
|
+
"&:disabled": {
|
|
1769
|
+
borderColor: lightGray
|
|
1770
|
+
}
|
|
1771
|
+
}, variant === "contained" && {
|
|
1772
|
+
color: "var(--primaryContrastText)",
|
|
1773
|
+
backgroundColor: "var(--primaryMain)",
|
|
1774
|
+
boxShadow: "0px 3px 1px -2px rgb(0 0 0 / 20%), 0px 2px 2px 0px rgb(0 0 0 / 14%), 0px 1px 5px 0px rgb(0 0 0 / 12%)",
|
|
1775
|
+
"&:hover": {
|
|
1776
|
+
filter: "brightness(0.9)"
|
|
1777
|
+
},
|
|
1778
|
+
"&:disabled": {
|
|
1779
|
+
filter: "grayscale()",
|
|
1780
|
+
opacity: 0.5
|
|
1781
|
+
}
|
|
1782
|
+
}]
|
|
1783
|
+
}, props), {
|
|
1784
|
+
children: [startIcon && jsx("span", {
|
|
1785
|
+
css: {
|
|
1786
|
+
marginRight: `calc(var(--spacing) * 2)`
|
|
1787
|
+
},
|
|
1788
|
+
children: startIcon
|
|
1789
|
+
}), jsx("span", {
|
|
1790
|
+
children
|
|
1791
|
+
})]
|
|
1792
|
+
}));
|
|
1793
|
+
};
|
|
1794
|
+
const Checkbox = (_g) => {
|
|
1795
|
+
var _h = _g, {
|
|
1796
|
+
className: className2
|
|
1797
|
+
} = _h, props = __objRest(_h, [
|
|
1798
|
+
"className"
|
|
1799
|
+
]);
|
|
1800
|
+
return jsxs("label", {
|
|
1801
|
+
css: [{
|
|
1802
|
+
padding: "calc(var(--spacing) * 1.8)",
|
|
1803
|
+
display: "flex",
|
|
1804
|
+
color: "currentcolor",
|
|
1805
|
+
userSelect: "none",
|
|
1806
|
+
"& input": {
|
|
1807
|
+
appearance: "none",
|
|
1808
|
+
margin: 0
|
|
1809
|
+
}
|
|
1810
|
+
}, props.disabled && {
|
|
1811
|
+
color: "rgba(0, 0, 0, 0.26)"
|
|
1812
|
+
}],
|
|
1813
|
+
className: className2,
|
|
1814
|
+
children: [jsx("input", __spreadValues({
|
|
1815
|
+
type: "checkbox"
|
|
1816
|
+
}, props)), props.checked ? jsx("svg", {
|
|
1817
|
+
css: {
|
|
1818
|
+
fontSize: "1.25rem",
|
|
1819
|
+
width: "1em",
|
|
1820
|
+
height: "1em",
|
|
1821
|
+
fill: "var(--primaryMain)"
|
|
1822
|
+
},
|
|
1823
|
+
focusable: "false",
|
|
1824
|
+
viewBox: "0 0 24 24",
|
|
1825
|
+
"aria-hidden": "true",
|
|
1826
|
+
children: jsx("path", {
|
|
1827
|
+
d: "M19 3H5c-1.11 0-2 .9-2 2v14c0 1.1.89 2 2 2h14c1.11 0 2-.9 2-2V5c0-1.1-.89-2-2-2zm-9 14l-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8l-9 9z"
|
|
1828
|
+
})
|
|
1829
|
+
}) : jsx("svg", {
|
|
1830
|
+
css: {
|
|
1831
|
+
fontSize: "1.25rem",
|
|
1832
|
+
width: "1em",
|
|
1833
|
+
height: "1em",
|
|
1834
|
+
fill: "currentColor"
|
|
1835
|
+
},
|
|
1836
|
+
focusable: "false",
|
|
1837
|
+
viewBox: "0 0 24 24",
|
|
1838
|
+
"aria-hidden": "true",
|
|
1839
|
+
children: jsx("path", {
|
|
1840
|
+
d: "M19 5v14H5V5h14m0-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2z"
|
|
1841
|
+
})
|
|
1842
|
+
})]
|
|
1843
|
+
});
|
|
1844
|
+
};
|
|
1845
|
+
const IconButton = (props) => {
|
|
1846
|
+
return jsx("button", __spreadValues({
|
|
1847
|
+
css: {
|
|
1848
|
+
padding: "var(--spacing)",
|
|
1849
|
+
borderRadius: "50%",
|
|
1850
|
+
display: "inline-flex",
|
|
1851
|
+
justifyContent: "center",
|
|
1852
|
+
alignItems: "center",
|
|
1853
|
+
transition: "background-color 150ms",
|
|
1854
|
+
border: "none",
|
|
1855
|
+
cursor: "pointer",
|
|
1856
|
+
color: "inherit",
|
|
1857
|
+
background: "transparent",
|
|
1858
|
+
"&:hover": {
|
|
1859
|
+
backgroundColor: "rgba(0, 0, 0, 0.04)"
|
|
1860
|
+
},
|
|
1861
|
+
"&:active": {
|
|
1862
|
+
transformColor: "scale3d(0.95, 0.95, 1)"
|
|
1863
|
+
}
|
|
1864
|
+
}
|
|
1865
|
+
}, props));
|
|
1866
|
+
};
|
|
1867
|
+
const TextField = (_i) => {
|
|
1868
|
+
var _j = _i, {
|
|
1869
|
+
endIcon,
|
|
1870
|
+
className: className2,
|
|
1871
|
+
inputRef
|
|
1872
|
+
} = _j, props = __objRest(_j, [
|
|
1873
|
+
"endIcon",
|
|
1874
|
+
"className",
|
|
1875
|
+
"inputRef"
|
|
1876
|
+
]);
|
|
1877
|
+
var _a;
|
|
1878
|
+
const [focus, setFocus] = useState(false);
|
|
1879
|
+
return jsx("div", {
|
|
1880
|
+
className: className2,
|
|
1881
|
+
css: {
|
|
1882
|
+
display: "flex"
|
|
1883
|
+
},
|
|
1884
|
+
children: jsxs("span", {
|
|
1885
|
+
css: [{
|
|
1886
|
+
flex: 1,
|
|
1887
|
+
display: "flex",
|
|
1888
|
+
alignItems: "center",
|
|
1889
|
+
border: `1px solid ${darkGray}`,
|
|
1890
|
+
borderRadius: 4
|
|
1891
|
+
}, focus && {
|
|
1892
|
+
border: "2px solid var(--primaryMain)",
|
|
1893
|
+
margin: -1
|
|
1894
|
+
}],
|
|
1895
|
+
children: [jsx("input", __spreadProps(__spreadValues({
|
|
1896
|
+
ref: inputRef
|
|
1897
|
+
}, props), {
|
|
1898
|
+
value: (_a = props.value) != null ? _a : "",
|
|
1899
|
+
onFocus: () => setFocus(true),
|
|
1900
|
+
onBlur: () => setFocus(false),
|
|
1901
|
+
css: {
|
|
1902
|
+
flex: 1,
|
|
1903
|
+
border: "none",
|
|
1904
|
+
outline: "none",
|
|
1905
|
+
borderRadius: 4,
|
|
1906
|
+
padding: "calc(var(--spacing) * 2)",
|
|
1907
|
+
paddingRight: 0,
|
|
1908
|
+
transition: "outline 500ms"
|
|
1909
|
+
}
|
|
1910
|
+
})), endIcon]
|
|
1911
|
+
})
|
|
1912
|
+
});
|
|
1913
|
+
};
|
|
1914
|
+
const defaultComponents = {
|
|
1915
|
+
IconButton,
|
|
1916
|
+
Checkbox,
|
|
1917
|
+
Popover,
|
|
1918
|
+
Button,
|
|
1919
|
+
Badge,
|
|
1920
|
+
TextField,
|
|
1921
|
+
Spinner
|
|
1922
|
+
};
|
|
1923
|
+
const IconDefaultStyle = css({
|
|
1924
|
+
width: "1.5em",
|
|
1925
|
+
height: "1.5em",
|
|
1926
|
+
color: "inherit"
|
|
1927
|
+
});
|
|
1928
|
+
function Icon(svg) {
|
|
1929
|
+
return (props) => jsx(ClassNames, {
|
|
1930
|
+
children: ({
|
|
1931
|
+
css: css2
|
|
1932
|
+
}) => cloneElement(svg, __spreadProps(__spreadValues({}, props), {
|
|
1933
|
+
className: css2(IconDefaultStyle, props.className)
|
|
1934
|
+
}))
|
|
1935
|
+
});
|
|
1936
|
+
}
|
|
1937
|
+
const Settings = Icon(jsxs("svg", {
|
|
1938
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
1939
|
+
height: "24px",
|
|
1940
|
+
viewBox: "0 0 24 24",
|
|
1941
|
+
width: "24px",
|
|
1942
|
+
fill: "currentColor",
|
|
1943
|
+
children: [jsx("path", {
|
|
1944
|
+
d: "M0 0h24v24H0V0z",
|
|
1945
|
+
fill: "none"
|
|
1946
|
+
}), jsx("path", {
|
|
1947
|
+
d: "M3 17v2h6v-2H3zM3 5v2h10V5H3zm10 16v-2h8v-2h-8v-2h-2v6h2zM7 9v2H3v2h4v2h2V9H7zm14 4v-2H11v2h10zm-6-4h2V7h4V5h-4V3h-2v6z"
|
|
1948
|
+
})]
|
|
1949
|
+
}));
|
|
1950
|
+
const Export = Icon(jsxs("svg", {
|
|
1951
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
1952
|
+
enableBackground: "new 0 0 24 24",
|
|
1953
|
+
height: "24px",
|
|
1954
|
+
viewBox: "0 0 24 24",
|
|
1955
|
+
width: "24px",
|
|
1956
|
+
fill: "currentColor",
|
|
1957
|
+
children: [jsx("g", {
|
|
1958
|
+
children: jsx("rect", {
|
|
1959
|
+
fill: "none",
|
|
1960
|
+
height: "24",
|
|
1961
|
+
width: "24"
|
|
1962
|
+
})
|
|
1963
|
+
}), jsx("g", {
|
|
1964
|
+
children: jsx("path", {
|
|
1965
|
+
d: "M18,15v3H6v-3H4v3c0,1.1,0.9,2,2,2h12c1.1,0,2-0.9,2-2v-3H18z M17,11l-1.41-1.41L13,12.17V4h-2v8.17L8.41,9.59L7,11l5,5 L17,11z"
|
|
1966
|
+
})
|
|
1967
|
+
})]
|
|
1968
|
+
}));
|
|
1969
|
+
const Clipboard = Icon(jsxs("svg", {
|
|
1970
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
1971
|
+
height: "24px",
|
|
1972
|
+
viewBox: "0 0 24 24",
|
|
1973
|
+
width: "24px",
|
|
1974
|
+
fill: "currentColor",
|
|
1975
|
+
children: [jsx("path", {
|
|
1976
|
+
d: "M0 0h24v24H0V0z",
|
|
1977
|
+
fill: "none"
|
|
1978
|
+
}), jsx("path", {
|
|
1979
|
+
d: "M19 2h-4.18C14.4.84 13.3 0 12 0S9.6.84 9.18 2H5c-1.1 0-2 .9-2 2v16c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2zm-7 0c.55 0 1 .45 1 1s-.45 1-1 1-1-.45-1-1 .45-1 1-1zm7 18H5V4h2v3h10V4h2v16z"
|
|
1980
|
+
})]
|
|
1981
|
+
}));
|
|
1982
|
+
const ChevronRight = Icon(jsxs("svg", {
|
|
1983
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
1984
|
+
height: "24px",
|
|
1985
|
+
viewBox: "0 0 24 24",
|
|
1986
|
+
width: "24px",
|
|
1987
|
+
fill: "currentColor",
|
|
1988
|
+
children: [jsx("path", {
|
|
1989
|
+
d: "M0 0h24v24H0V0z",
|
|
1990
|
+
fill: "none"
|
|
1991
|
+
}), jsx("path", {
|
|
1992
|
+
d: "M10 6L8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6-6-6z"
|
|
1993
|
+
})]
|
|
1994
|
+
}));
|
|
1995
|
+
const Search = Icon(jsxs("svg", {
|
|
1996
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
1997
|
+
height: "24px",
|
|
1998
|
+
viewBox: "0 0 24 24",
|
|
1999
|
+
width: "24px",
|
|
2000
|
+
fill: "currentColor",
|
|
2001
|
+
children: [jsx("path", {
|
|
2002
|
+
d: "M0 0h24v24H0V0z",
|
|
2003
|
+
fill: "none"
|
|
2004
|
+
}), jsx("path", {
|
|
2005
|
+
d: "M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"
|
|
2006
|
+
})]
|
|
2007
|
+
}));
|
|
2008
|
+
const Clear = Icon(jsxs("svg", {
|
|
2009
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
2010
|
+
height: "24px",
|
|
2011
|
+
viewBox: "0 0 24 24",
|
|
2012
|
+
width: "24px",
|
|
2013
|
+
fill: "currentColor",
|
|
2014
|
+
children: [jsx("path", {
|
|
2015
|
+
d: "M0 0h24v24H0V0z",
|
|
2016
|
+
fill: "none"
|
|
2017
|
+
}), jsx("path", {
|
|
2018
|
+
d: "M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12 19 6.41z"
|
|
2019
|
+
})]
|
|
2020
|
+
}));
|
|
2021
|
+
const ArrowDropDown = Icon(jsxs("svg", {
|
|
2022
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
2023
|
+
height: "24px",
|
|
2024
|
+
viewBox: "0 0 24 24",
|
|
2025
|
+
width: "24px",
|
|
2026
|
+
fill: "currentColor",
|
|
2027
|
+
children: [jsx("path", {
|
|
2028
|
+
d: "M0 0h24v24H0V0z",
|
|
2029
|
+
fill: "none"
|
|
2030
|
+
}), jsx("path", {
|
|
2031
|
+
d: "M7 10l5 5 5-5H7z"
|
|
2032
|
+
})]
|
|
2033
|
+
}));
|
|
2034
|
+
const FilterList = Icon(jsx("svg", {
|
|
2035
|
+
viewBox: "0 0 24 24",
|
|
2036
|
+
children: jsx("path", {
|
|
2037
|
+
fill: "currentColor",
|
|
2038
|
+
d: "M14,12V19.88C14.04,20.18 13.94,20.5 13.71,20.71C13.32,21.1 12.69,21.1 12.3,20.71L10.29,18.7C10.06,18.47 9.96,18.16 10,17.87V12H9.97L4.21,4.62C3.87,4.19 3.95,3.56 4.38,3.22C4.57,3.08 4.78,3 5,3V3H19V3C19.22,3 19.43,3.08 19.62,3.22C20.05,3.56 20.13,4.19 19.79,4.62L14.03,12H14Z"
|
|
2039
|
+
})
|
|
2040
|
+
}));
|
|
2041
|
+
const ArrowUpward = Icon(jsxs("svg", {
|
|
2042
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
2043
|
+
height: "24px",
|
|
2044
|
+
viewBox: "0 0 24 24",
|
|
2045
|
+
width: "24px",
|
|
2046
|
+
fill: "currentColor",
|
|
2047
|
+
children: [jsx("path", {
|
|
2048
|
+
d: "M0 0h24v24H0V0z",
|
|
2049
|
+
fill: "none"
|
|
2050
|
+
}), jsx("path", {
|
|
2051
|
+
d: "M4 12l1.41 1.41L11 7.83V20h2V7.83l5.58 5.59L20 12l-8-8-8 8z"
|
|
2052
|
+
})]
|
|
2053
|
+
}));
|
|
2054
|
+
const defaultIcons = {
|
|
2055
|
+
Settings,
|
|
2056
|
+
Export,
|
|
2057
|
+
Clipboard,
|
|
2058
|
+
ChevronRight,
|
|
2059
|
+
Search,
|
|
2060
|
+
Clear,
|
|
2061
|
+
ArrowDropDown,
|
|
2062
|
+
FilterList,
|
|
2063
|
+
ArrowUpward
|
|
2064
|
+
};
|
|
2065
|
+
const defaultTexts = {
|
|
2066
|
+
selectColumns: "Select visible columns",
|
|
2067
|
+
noResults: "No results",
|
|
2068
|
+
exportTitle: "Export",
|
|
2069
|
+
exportCopy: "To clipboard",
|
|
2070
|
+
exportDownload: "Download",
|
|
2071
|
+
today: "Today",
|
|
2072
|
+
thisWeek: "This week",
|
|
2073
|
+
reset: "Reset",
|
|
2074
|
+
loading: "Loading",
|
|
2075
|
+
selected: (count) => `${count} selected`
|
|
2076
|
+
};
|
|
2077
|
+
const defaultTableTheme = {
|
|
2078
|
+
text: defaultTexts,
|
|
2079
|
+
components: defaultComponents,
|
|
2080
|
+
icons: defaultIcons,
|
|
2081
|
+
colors: defaultColors,
|
|
2082
|
+
spacing: "5px"
|
|
2083
|
+
};
|
|
2084
|
+
const emptyStore = new Store(void 0);
|
|
2085
|
+
function useTheme(selector) {
|
|
2086
|
+
var _a, _b;
|
|
2087
|
+
const contextTableTheme = useContext(TableThemeContext);
|
|
2088
|
+
const table = useContext(TableContext);
|
|
2089
|
+
const columnId = useContext(ColumnContext);
|
|
2090
|
+
const memo2 = useTableMemo();
|
|
2091
|
+
const process = (t) => {
|
|
2092
|
+
var _a2;
|
|
2093
|
+
const cell = (_a2 = t.classes) == null ? void 0 : _a2.cell;
|
|
2094
|
+
const selected = t.text.selected;
|
|
2095
|
+
return __spreadProps(__spreadValues({}, t), {
|
|
2096
|
+
classes: __spreadProps(__spreadValues({}, t.classes), {
|
|
2097
|
+
cell: cell instanceof Function || Array.isArray(cell) ? memo2("theme.classes.cell", cell) : cell
|
|
2098
|
+
}),
|
|
2099
|
+
text: __spreadProps(__spreadValues({}, t.text), {
|
|
2100
|
+
selected: selected instanceof Function || Array.isArray(selected) ? memo2("theme.text.selected", selected) : selected
|
|
2101
|
+
})
|
|
2102
|
+
});
|
|
2103
|
+
};
|
|
2104
|
+
const theme = (_b = (_a = table == null ? void 0 : table.useState((state) => {
|
|
2105
|
+
const localTheme = {
|
|
2106
|
+
text: state.props.text,
|
|
2107
|
+
classes: state.props.classes,
|
|
2108
|
+
components: state.props.components,
|
|
2109
|
+
icons: state.props.icons,
|
|
2110
|
+
colors: state.props.colors,
|
|
2111
|
+
spacing: state.props.spacing
|
|
2112
|
+
};
|
|
2113
|
+
const column = state.activeColumns.find((column2) => column2.id === columnId);
|
|
2114
|
+
const columnsTheme = {
|
|
2115
|
+
classes: column == null ? void 0 : column.classes
|
|
2116
|
+
};
|
|
2117
|
+
const theme2 = mergeThemes(defaultTableTheme, globalTableTheme, contextTableTheme, localTheme, columnsTheme);
|
|
2118
|
+
return selector(process(theme2));
|
|
2119
|
+
})) != null ? _a : emptyStore.useState()) != null ? _b : selector(process(mergeThemes(defaultTableTheme, globalTableTheme, contextTableTheme)));
|
|
2120
|
+
return theme;
|
|
2121
|
+
}
|
|
2122
|
+
function AutoFocusTextField(props) {
|
|
2123
|
+
const TextField2 = useTheme((t) => t.components.TextField);
|
|
2124
|
+
const ref = useRef(null);
|
|
2125
|
+
const {
|
|
2126
|
+
visible
|
|
2127
|
+
} = useContext(PopoverContext);
|
|
2128
|
+
useLayoutEffect(() => {
|
|
2129
|
+
if (visible && ref.current) {
|
|
2130
|
+
ref.current.focus();
|
|
2131
|
+
}
|
|
2132
|
+
}, [visible]);
|
|
2133
|
+
return jsx(TextField2, __spreadProps(__spreadValues({}, props), {
|
|
2134
|
+
inputRef: ref
|
|
2135
|
+
}));
|
|
2136
|
+
}
|
|
2137
|
+
const className = "schummar-table-date-input";
|
|
2138
|
+
const defaultDate = new Date(1970, 0, 1);
|
|
2139
|
+
const isIncludedType = (type) => type === "day" || type === "month" || type === "year";
|
|
2140
|
+
const defaultLengths = {
|
|
2141
|
+
day: 2,
|
|
2142
|
+
month: 2,
|
|
2143
|
+
year: 4
|
|
2144
|
+
};
|
|
2145
|
+
const maxLengths = {
|
|
2146
|
+
day: 2,
|
|
2147
|
+
month: 2,
|
|
2148
|
+
year: Infinity
|
|
2149
|
+
};
|
|
2150
|
+
const length = (type, value) => Math.max(value.length, defaultLengths[type]);
|
|
2151
|
+
const tabNext = (e2) => {
|
|
2152
|
+
const all = Array.from(document.querySelectorAll(`.${className}`));
|
|
2153
|
+
const index = all.indexOf(e2);
|
|
2154
|
+
const next = all[(index + 1) % all.length];
|
|
2155
|
+
if (next instanceof HTMLElement) {
|
|
2156
|
+
next.focus();
|
|
2157
|
+
}
|
|
2158
|
+
};
|
|
2159
|
+
function DateInput({
|
|
2160
|
+
value,
|
|
2161
|
+
onChange,
|
|
2162
|
+
locale
|
|
2163
|
+
}) {
|
|
2164
|
+
const [override, setOverride] = useState();
|
|
2165
|
+
const commit = () => {
|
|
2166
|
+
if (!override) {
|
|
2167
|
+
return;
|
|
2168
|
+
}
|
|
2169
|
+
setOverride(void 0);
|
|
2170
|
+
if (!override.value) {
|
|
2171
|
+
onChange(null);
|
|
2172
|
+
return;
|
|
2173
|
+
}
|
|
2174
|
+
const newValue = value ? new Date(value) : new Date();
|
|
2175
|
+
if (override.type === "day") {
|
|
2176
|
+
newValue.setDate(Number(override.value));
|
|
2177
|
+
} else if (override.type === "month") {
|
|
2178
|
+
newValue.setMonth(Number(override.value) - 1);
|
|
2179
|
+
} else if (override.type === "year") {
|
|
2180
|
+
newValue.setFullYear(Number(override.value));
|
|
2181
|
+
}
|
|
2182
|
+
onChange(newValue);
|
|
2183
|
+
};
|
|
2184
|
+
const format = useMemo(() => new Intl.DateTimeFormat(locale, {
|
|
2185
|
+
day: "2-digit",
|
|
2186
|
+
month: "2-digit",
|
|
2187
|
+
year: "numeric"
|
|
2188
|
+
}), [locale]);
|
|
2189
|
+
const parts = format.formatToParts(value != null ? value : defaultDate);
|
|
2190
|
+
const isEmpty = !value;
|
|
2191
|
+
return jsx("div", {
|
|
2192
|
+
css: {
|
|
2193
|
+
display: "flex",
|
|
2194
|
+
alignItems: "baseline"
|
|
2195
|
+
},
|
|
2196
|
+
children: parts.map(({
|
|
2197
|
+
type,
|
|
2198
|
+
value: value2
|
|
2199
|
+
}, index) => jsx(Fragment$1, {
|
|
2200
|
+
children: isIncludedType(type) ? jsx("input", {
|
|
2201
|
+
className,
|
|
2202
|
+
css: {
|
|
2203
|
+
width: `${length(type, value2)}ch`,
|
|
2204
|
+
boxSizing: "content-box",
|
|
2205
|
+
overflow: "visible",
|
|
2206
|
+
border: "none",
|
|
2207
|
+
borderBottom: "2px solid transparent",
|
|
2208
|
+
outline: "none",
|
|
2209
|
+
fontSize: "inherit",
|
|
2210
|
+
"&:focus": {
|
|
2211
|
+
borderBottom: "2px solid var(--primaryMain)"
|
|
2212
|
+
}
|
|
2213
|
+
},
|
|
2214
|
+
placeholder: "".padEnd(length(type, value2), "0"),
|
|
2215
|
+
value: (override == null ? void 0 : override.type) === type ? override.value : !isEmpty ? value2 : "",
|
|
2216
|
+
onChange: (e2) => {
|
|
2217
|
+
setOverride({
|
|
2218
|
+
type,
|
|
2219
|
+
value: e2.target.value
|
|
2220
|
+
});
|
|
2221
|
+
if (e2.target.value.length >= maxLengths[type]) {
|
|
2222
|
+
setTimeout(() => tabNext(e2.target));
|
|
2223
|
+
}
|
|
2224
|
+
},
|
|
2225
|
+
onFocus: (e2) => e2.target.select(),
|
|
2226
|
+
onBlur: commit
|
|
2227
|
+
}) : type === "literal" ? jsx("span", {
|
|
2228
|
+
children: value2
|
|
2229
|
+
}) : null
|
|
2230
|
+
}, index))
|
|
2231
|
+
});
|
|
2232
|
+
}
|
|
2233
|
+
const weekDays = [0, 1, 2, 3, 4, 5, 6];
|
|
2234
|
+
const startOfDay = (d) => new Date(d.getFullYear(), d.getMonth(), d.getDate());
|
|
2235
|
+
const endOfDay = (d) => new Date(d.getFullYear(), d.getMonth(), d.getDate() + 1, 0, 0, 0, -1);
|
|
2236
|
+
const today = () => {
|
|
2237
|
+
const today2 = startOfDay(new Date());
|
|
2238
|
+
return {
|
|
2239
|
+
min: today2,
|
|
2240
|
+
max: today2
|
|
2241
|
+
};
|
|
2242
|
+
};
|
|
2243
|
+
const thisWeek = (firstDayOfWeek = 0) => {
|
|
2244
|
+
const now = new Date();
|
|
2245
|
+
const min = new Date(now);
|
|
2246
|
+
let diff = min.getDay() - firstDayOfWeek;
|
|
2247
|
+
if (diff < 0) {
|
|
2248
|
+
diff += 7;
|
|
2249
|
+
}
|
|
2250
|
+
min.setDate(min.getDate() - diff);
|
|
2251
|
+
const max = new Date(min);
|
|
2252
|
+
max.setDate(max.getDate() + 6);
|
|
2253
|
+
return {
|
|
2254
|
+
min: startOfDay(min),
|
|
2255
|
+
max: endOfDay(max)
|
|
2256
|
+
};
|
|
2257
|
+
};
|
|
2258
|
+
function dateIntersect(a, b) {
|
|
2259
|
+
if (a instanceof Date) {
|
|
2260
|
+
a = {
|
|
2261
|
+
min: a,
|
|
2262
|
+
max: a
|
|
2263
|
+
};
|
|
2264
|
+
}
|
|
2265
|
+
if (b instanceof Date) {
|
|
2266
|
+
b = {
|
|
2267
|
+
min: b,
|
|
2268
|
+
max: b
|
|
2269
|
+
};
|
|
2270
|
+
}
|
|
2271
|
+
if (!(a == null ? void 0 : a.min) || !a.max || !(b == null ? void 0 : b.min) || !b.max) {
|
|
2272
|
+
return false;
|
|
2273
|
+
}
|
|
2274
|
+
return !(endOfDay(a.max) < startOfDay(b.min) || startOfDay(a.min) > endOfDay(b.max));
|
|
2275
|
+
}
|
|
2276
|
+
function DatePicker({
|
|
2277
|
+
value,
|
|
2278
|
+
onChange,
|
|
2279
|
+
rangeSelect,
|
|
2280
|
+
locale,
|
|
2281
|
+
firstDayOfWeek = 0
|
|
2282
|
+
}) {
|
|
2283
|
+
const Button2 = useTheme((t) => t.components.Button);
|
|
2284
|
+
const IconButton2 = useTheme((t) => t.components.IconButton);
|
|
2285
|
+
const ChevronRight2 = useTheme((t) => t.icons.ChevronRight);
|
|
2286
|
+
const textToday = useTheme((t) => t.text.today);
|
|
2287
|
+
const textThisWeek = useTheme((t) => t.text.thisWeek);
|
|
2288
|
+
const textReset = useTheme((t) => t.text.reset);
|
|
2289
|
+
const [baseDate] = useState(new Date());
|
|
2290
|
+
const [dateInView, setDateInView] = useState(baseDate);
|
|
2291
|
+
const [dirty, setDirty] = useState();
|
|
2292
|
+
const [hovered, setHovered] = useState();
|
|
2293
|
+
const min = dirty ? dirty.min : value instanceof Date ? value : value == null ? void 0 : value.min;
|
|
2294
|
+
const max = dirty ? dirty.max : value instanceof Date ? value : value == null ? void 0 : value.max;
|
|
2295
|
+
const {
|
|
2296
|
+
calendars,
|
|
2297
|
+
getBackProps,
|
|
2298
|
+
getForwardProps,
|
|
2299
|
+
getDateProps
|
|
2300
|
+
} = useDayzed({
|
|
2301
|
+
onDateSelected: () => void 0,
|
|
2302
|
+
firstDayOfWeek,
|
|
2303
|
+
showOutsideDays: true,
|
|
2304
|
+
date: dateInView,
|
|
2305
|
+
onOffsetChanged: (offset) => setDateInView(new Date(dateInView.getFullYear(), dateInView.getMonth() + offset)),
|
|
2306
|
+
offset: 0
|
|
2307
|
+
});
|
|
2308
|
+
const formatWeekday = useMemo(() => {
|
|
2309
|
+
const {
|
|
2310
|
+
format
|
|
2311
|
+
} = new Intl.DateTimeFormat(locale, {
|
|
2312
|
+
weekday: "short"
|
|
2313
|
+
});
|
|
2314
|
+
return (weekDay) => format(new Date(Date.UTC(2021, 5, weekDay)));
|
|
2315
|
+
}, [locale]);
|
|
2316
|
+
useEffect(() => setDateInView(value === null ? new Date() : value instanceof Date ? value : value.max), [value]);
|
|
2317
|
+
useEffect(() => {
|
|
2318
|
+
if (!rangeSelect) {
|
|
2319
|
+
setDirty(void 0);
|
|
2320
|
+
}
|
|
2321
|
+
}, [rangeSelect]);
|
|
2322
|
+
function set(min2, max2, edit) {
|
|
2323
|
+
if (!rangeSelect) {
|
|
2324
|
+
onChange(min2 != null ? min2 : null);
|
|
2325
|
+
return;
|
|
2326
|
+
}
|
|
2327
|
+
if (min2 && max2 && min2 > max2) {
|
|
2328
|
+
if (edit === "min") {
|
|
2329
|
+
max2 = min2;
|
|
2330
|
+
} else if (edit === "max") {
|
|
2331
|
+
min2 = max2;
|
|
2332
|
+
} else {
|
|
2333
|
+
[min2, max2] = [max2, min2];
|
|
2334
|
+
}
|
|
2335
|
+
}
|
|
2336
|
+
if (!min2 === !max2) {
|
|
2337
|
+
setDirty(void 0);
|
|
2338
|
+
onChange(min2 && max2 ? {
|
|
2339
|
+
min: min2,
|
|
2340
|
+
max: max2
|
|
2341
|
+
} : null);
|
|
2342
|
+
} else {
|
|
2343
|
+
setDirty({
|
|
2344
|
+
min: min2,
|
|
2345
|
+
max: max2
|
|
2346
|
+
});
|
|
2347
|
+
}
|
|
2348
|
+
}
|
|
2349
|
+
const formatMonth = useMemo(() => {
|
|
2350
|
+
const {
|
|
2351
|
+
format
|
|
2352
|
+
} = new Intl.DateTimeFormat(locale, {
|
|
2353
|
+
month: "long"
|
|
2354
|
+
});
|
|
2355
|
+
return (month) => format(new Date(2021, month));
|
|
2356
|
+
}, [locale]);
|
|
2357
|
+
const formatYear = useMemo(() => {
|
|
2358
|
+
const {
|
|
2359
|
+
format
|
|
2360
|
+
} = new Intl.DateTimeFormat(locale, {
|
|
2361
|
+
year: "numeric"
|
|
2362
|
+
});
|
|
2363
|
+
return (year) => format(new Date(year, 0, 1));
|
|
2364
|
+
}, [locale]);
|
|
2365
|
+
return jsxs("div", {
|
|
2366
|
+
children: [jsxs("div", {
|
|
2367
|
+
css: {
|
|
2368
|
+
display: "grid",
|
|
2369
|
+
gridAutoFlow: "column",
|
|
2370
|
+
justifyContent: "center",
|
|
2371
|
+
alignItems: "baseline",
|
|
2372
|
+
gap: "var(--spacing)"
|
|
2373
|
+
},
|
|
2374
|
+
children: [jsx(DateInput, {
|
|
2375
|
+
value: min != null ? min : null,
|
|
2376
|
+
onChange: (date) => set(date != null ? date : void 0, max, "min"),
|
|
2377
|
+
locale
|
|
2378
|
+
}), rangeSelect && jsxs(Fragment, {
|
|
2379
|
+
children: [" - ", jsx(DateInput, {
|
|
2380
|
+
value: max != null ? max : null,
|
|
2381
|
+
onChange: (date) => set(min, date != null ? date : void 0, "max"),
|
|
2382
|
+
locale
|
|
2383
|
+
})]
|
|
2384
|
+
})]
|
|
2385
|
+
}), calendars.map(({
|
|
2386
|
+
month,
|
|
2387
|
+
year,
|
|
2388
|
+
weeks
|
|
2389
|
+
}) => jsxs("div", {
|
|
2390
|
+
css: {
|
|
2391
|
+
display: "grid"
|
|
2392
|
+
},
|
|
2393
|
+
children: [jsxs("div", {
|
|
2394
|
+
css: {
|
|
2395
|
+
margin: "calc(var(--spacing) * 4) 0",
|
|
2396
|
+
display: "grid",
|
|
2397
|
+
gridAutoFlow: "column",
|
|
2398
|
+
justifyContent: "space-between",
|
|
2399
|
+
alignItems: "center"
|
|
2400
|
+
},
|
|
2401
|
+
children: [jsx(IconButton2, __spreadProps(__spreadValues({}, getBackProps({
|
|
2402
|
+
calendars
|
|
2403
|
+
})), {
|
|
2404
|
+
children: jsx(ChevronRight2, {
|
|
2405
|
+
css: {
|
|
2406
|
+
transform: "rotate3d(0, 0, 1, 180deg)"
|
|
2407
|
+
}
|
|
2408
|
+
})
|
|
2409
|
+
})), jsxs("div", {
|
|
2410
|
+
css: {
|
|
2411
|
+
display: "flex"
|
|
2412
|
+
},
|
|
2413
|
+
children: [formatMonth(month), " ", formatYear(year)]
|
|
2414
|
+
}), jsx(IconButton2, __spreadProps(__spreadValues({}, getForwardProps({
|
|
2415
|
+
calendars
|
|
2416
|
+
})), {
|
|
2417
|
+
children: jsx(ChevronRight2, {})
|
|
2418
|
+
}))]
|
|
2419
|
+
}), jsxs("div", {
|
|
2420
|
+
css: {
|
|
2421
|
+
justifySelf: "center",
|
|
2422
|
+
display: "grid",
|
|
2423
|
+
gridTemplateColumns: "repeat(7, max-content)",
|
|
2424
|
+
fontWeight: "bold"
|
|
2425
|
+
},
|
|
2426
|
+
children: [weekDays.map((_v, weekDay) => jsx("div", {
|
|
2427
|
+
css: {
|
|
2428
|
+
justifySelf: "center",
|
|
2429
|
+
marginBottom: "var(--spacing)"
|
|
2430
|
+
},
|
|
2431
|
+
children: formatWeekday(weekDay)
|
|
2432
|
+
}, weekDay)), weeks.map((week, index) => week.map((dateObj, dayIndex) => {
|
|
2433
|
+
if (!dateObj) {
|
|
2434
|
+
return jsx("div", {});
|
|
2435
|
+
}
|
|
2436
|
+
const {
|
|
2437
|
+
prevMonth,
|
|
2438
|
+
nextMonth,
|
|
2439
|
+
date,
|
|
2440
|
+
today: today2
|
|
2441
|
+
} = dateObj;
|
|
2442
|
+
const selected = date.getTime() === (min == null ? void 0 : min.getTime()) || min && max && dateIntersect(date, {
|
|
2443
|
+
min,
|
|
2444
|
+
max
|
|
2445
|
+
});
|
|
2446
|
+
const preSelected = !selected && (date.getTime() === (hovered == null ? void 0 : hovered.getTime()) || min && !max && hovered && dateIntersect(date, min <= hovered ? {
|
|
2447
|
+
min,
|
|
2448
|
+
max: hovered
|
|
2449
|
+
} : {
|
|
2450
|
+
min: hovered,
|
|
2451
|
+
max: min
|
|
2452
|
+
}));
|
|
2453
|
+
return jsx("button", __spreadProps(__spreadValues({
|
|
2454
|
+
css: [{
|
|
2455
|
+
padding: 10,
|
|
2456
|
+
border: "1px solid transparent",
|
|
2457
|
+
background: "transparent",
|
|
2458
|
+
cursor: "pointer"
|
|
2459
|
+
}, (prevMonth || nextMonth) && {
|
|
2460
|
+
color: gray
|
|
2461
|
+
}, today2 && {
|
|
2462
|
+
border: "1px solid var(--secondaryMain)"
|
|
2463
|
+
}, selected && {
|
|
2464
|
+
background: "var(--primaryMain)",
|
|
2465
|
+
color: "var(--primaryContrastText)"
|
|
2466
|
+
}, preSelected && {
|
|
2467
|
+
background: "var(--primaryLight)",
|
|
2468
|
+
color: "var(--primaryContrastText)"
|
|
2469
|
+
}]
|
|
2470
|
+
}, getDateProps({
|
|
2471
|
+
dateObj
|
|
2472
|
+
})), {
|
|
2473
|
+
onClick: () => {
|
|
2474
|
+
if (dirty) {
|
|
2475
|
+
if (min)
|
|
2476
|
+
set(min, date);
|
|
2477
|
+
else
|
|
2478
|
+
set(date, max);
|
|
2479
|
+
} else {
|
|
2480
|
+
set(date);
|
|
2481
|
+
}
|
|
2482
|
+
},
|
|
2483
|
+
onPointerOver: () => setHovered(date),
|
|
2484
|
+
onPointerOut: () => setHovered(void 0),
|
|
2485
|
+
children: date.getDate()
|
|
2486
|
+
}), `${index}-${dayIndex}`);
|
|
2487
|
+
}))]
|
|
2488
|
+
})]
|
|
2489
|
+
}, `${month}${year}`)), jsxs("div", {
|
|
2490
|
+
css: {
|
|
2491
|
+
marginTop: "var(--spacing)",
|
|
2492
|
+
display: "grid",
|
|
2493
|
+
gridAutoFlow: "column",
|
|
2494
|
+
justifyContent: "center"
|
|
2495
|
+
},
|
|
2496
|
+
children: [jsx(Button2, {
|
|
2497
|
+
variant: "text",
|
|
2498
|
+
onClick: () => {
|
|
2499
|
+
setDirty(void 0);
|
|
2500
|
+
onChange(today());
|
|
2501
|
+
},
|
|
2502
|
+
children: textToday
|
|
2503
|
+
}), jsx(Button2, {
|
|
2504
|
+
variant: "text",
|
|
2505
|
+
onClick: () => {
|
|
2506
|
+
setDirty(void 0);
|
|
2507
|
+
onChange(thisWeek(firstDayOfWeek));
|
|
2508
|
+
},
|
|
2509
|
+
children: textThisWeek
|
|
2510
|
+
}), jsx(Button2, {
|
|
2511
|
+
variant: "text",
|
|
2512
|
+
onClick: () => {
|
|
2513
|
+
setDirty(void 0);
|
|
2514
|
+
onChange(null);
|
|
2515
|
+
},
|
|
2516
|
+
children: textReset
|
|
2517
|
+
})]
|
|
1944
2518
|
})]
|
|
1945
|
-
})
|
|
2519
|
+
});
|
|
1946
2520
|
}
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
return value;
|
|
2521
|
+
function convertDate(x) {
|
|
2522
|
+
if (x instanceof Date)
|
|
2523
|
+
return x;
|
|
2524
|
+
if (typeof x === "number" || typeof x === "string")
|
|
2525
|
+
return new Date(x);
|
|
2526
|
+
return null;
|
|
1954
2527
|
}
|
|
1955
|
-
function
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
2528
|
+
function convertDateOrRange(x) {
|
|
2529
|
+
if (x instanceof Object && "min" in x && "max" in x) {
|
|
2530
|
+
const range = {
|
|
2531
|
+
min: convertDate(x.min),
|
|
2532
|
+
max: convertDate(x.max)
|
|
2533
|
+
};
|
|
2534
|
+
return range.min && range.max ? range : null;
|
|
2535
|
+
}
|
|
2536
|
+
return convertDate(x);
|
|
1960
2537
|
}
|
|
1961
|
-
function
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
return jsx(TableContext.Provider, {
|
|
1966
|
-
value: table,
|
|
1967
|
-
children: jsx(TableLoadingState, {})
|
|
1968
|
-
});
|
|
2538
|
+
function convertDateOrArray(x) {
|
|
2539
|
+
if (x instanceof Array)
|
|
2540
|
+
return x.map(convertDateOrRange).filter(Boolean);
|
|
2541
|
+
return convertDateOrRange(x);
|
|
1969
2542
|
}
|
|
1970
|
-
function
|
|
2543
|
+
function DateFilter(_k) {
|
|
2544
|
+
var _l = _k, {
|
|
2545
|
+
locale,
|
|
2546
|
+
firstDayOfWeek,
|
|
2547
|
+
singleSelect,
|
|
2548
|
+
filterBy = convertDateOrArray
|
|
2549
|
+
} = _l, props = __objRest(_l, [
|
|
2550
|
+
"locale",
|
|
2551
|
+
"firstDayOfWeek",
|
|
2552
|
+
"singleSelect",
|
|
2553
|
+
"filterBy"
|
|
2554
|
+
]);
|
|
1971
2555
|
const {
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
2556
|
+
value = null,
|
|
2557
|
+
onChange
|
|
2558
|
+
} = useFilter(__spreadProps(__spreadValues({}, props), {
|
|
2559
|
+
filterBy,
|
|
2560
|
+
id: "dateFilter",
|
|
2561
|
+
isActive(filterValue) {
|
|
2562
|
+
return !!filterValue;
|
|
2563
|
+
},
|
|
2564
|
+
test(filterValue, value2) {
|
|
2565
|
+
return dateIntersect(filterValue, value2);
|
|
2566
|
+
}
|
|
2567
|
+
}));
|
|
2568
|
+
return jsx("div", {
|
|
2569
|
+
css: {
|
|
2570
|
+
padding: "calc(var(--spacing) * 2)",
|
|
2571
|
+
display: "grid"
|
|
2572
|
+
},
|
|
2573
|
+
children: jsx(DatePicker, {
|
|
2574
|
+
rangeSelect: !singleSelect,
|
|
2575
|
+
value,
|
|
2576
|
+
onChange,
|
|
2577
|
+
locale,
|
|
2578
|
+
firstDayOfWeek
|
|
2579
|
+
})
|
|
1986
2580
|
});
|
|
1987
2581
|
}
|
|
1988
|
-
const TableInner = memo(function TableInner2({
|
|
1989
|
-
hidden
|
|
1990
|
-
}) {
|
|
1991
|
-
var _a, _b;
|
|
1992
|
-
const table = useTableContext();
|
|
1993
|
-
const fullWidth = table.useState("props.fullWidth");
|
|
1994
|
-
const activeColumns = table.useState((state) => state.activeColumns.map((column) => ({
|
|
1995
|
-
id: column.id,
|
|
1996
|
-
width: column.width,
|
|
1997
|
-
classes: column.classes,
|
|
1998
|
-
header: column.header
|
|
1999
|
-
})));
|
|
2000
|
-
const columnWidths = table.useState("columnWidths", {
|
|
2001
|
-
throttle: 16
|
|
2002
|
-
});
|
|
2003
|
-
const columnStyleOverride = table.useState("columnStyleOverride", {
|
|
2004
|
-
throttle: 16
|
|
2005
|
-
});
|
|
2006
|
-
const defaultWidth = table.useState("props.defaultWidth");
|
|
2007
|
-
const classes = table.useState("props.classes");
|
|
2008
|
-
const stickyHeader = table.useState("props.stickyHeader");
|
|
2009
|
-
const enableSelection = table.useState("props.enableSelection");
|
|
2010
|
-
const enableColumnSelection = table.useState("props.enableColumnSelection");
|
|
2011
|
-
const enableExport = table.useState((state) => !!state.props.enableExport.copy || !!state.props.enableExport.download);
|
|
2012
|
-
const cssVariables = useCssVariables();
|
|
2013
|
-
(_b = (_a = table.getState().props).debugRender) == null ? void 0 : _b.call(_a, "render table inner");
|
|
2014
|
-
return jsx(Virtualized, {
|
|
2015
|
-
className: classes == null ? void 0 : classes.table,
|
|
2016
|
-
css: [cssVariables, defaultClasses.table, {
|
|
2017
|
-
gridTemplateColumns: [
|
|
2018
|
-
fullWidth === "right" || fullWidth === true ? "auto" : "0",
|
|
2019
|
-
"max-content",
|
|
2020
|
-
...activeColumns.map((column) => {
|
|
2021
|
-
var _a2, _b2, _c;
|
|
2022
|
-
return (_c = (_b2 = (_a2 = columnWidths.get(column.id)) != null ? _a2 : column.width) != null ? _b2 : defaultWidth) != null ? _c : "max-content";
|
|
2023
|
-
}),
|
|
2024
|
-
fullWidth === "left" || fullWidth === true ? "auto" : "0"
|
|
2025
|
-
].join(" ")
|
|
2026
|
-
}, hidden && {
|
|
2027
|
-
visibility: "hidden"
|
|
2028
|
-
}],
|
|
2029
|
-
header: jsxs(Fragment, {
|
|
2030
|
-
children: [jsx("div", {
|
|
2031
|
-
className: classes == null ? void 0 : classes.headerCell,
|
|
2032
|
-
css: [defaultClasses.headerFill, stickyHeader && defaultClasses.sticky, stickyHeader instanceof Object && stickyHeader]
|
|
2033
|
-
}), jsxs("div", {
|
|
2034
|
-
className: classes == null ? void 0 : classes.headerCell,
|
|
2035
|
-
css: [defaultClasses.headerCell, stickyHeader && defaultClasses.sticky, stickyHeader instanceof Object && stickyHeader],
|
|
2036
|
-
children: [enableSelection && jsx(SelectComponent, {}), enableColumnSelection && jsx(ColumnSelection, {}), enableExport && jsx(Export, {}), jsx(ResizeHandleView, {})]
|
|
2037
|
-
}), jsx(ColumnHeaderContext.Provider, {
|
|
2038
|
-
children: activeColumns.map((column) => {
|
|
2039
|
-
var _a2;
|
|
2040
|
-
return jsx(ColumnContext.Provider, {
|
|
2041
|
-
value: column.id,
|
|
2042
|
-
children: jsxs(ColumnHeader, {
|
|
2043
|
-
className: cx(classes == null ? void 0 : classes.headerCell, (_a2 = column.classes) == null ? void 0 : _a2.headerCell),
|
|
2044
|
-
css: [defaultClasses.headerCell, columnStyleOverride.get(column.id), stickyHeader && defaultClasses.sticky, stickyHeader instanceof Object && stickyHeader],
|
|
2045
|
-
children: [jsx(SortComponent, {
|
|
2046
|
-
children: column.header
|
|
2047
|
-
}), jsx("div", {
|
|
2048
|
-
css: {
|
|
2049
|
-
flex: 1
|
|
2050
|
-
}
|
|
2051
|
-
}), jsx(FilterControl, {}), jsx(ResizeHandle, {})]
|
|
2052
|
-
}, column.id)
|
|
2053
|
-
}, column.id);
|
|
2054
|
-
})
|
|
2055
|
-
}), jsx("div", {
|
|
2056
|
-
className: classes == null ? void 0 : classes.headerCell,
|
|
2057
|
-
css: [defaultClasses.headerFill, stickyHeader && defaultClasses.sticky, stickyHeader instanceof Object && stickyHeader]
|
|
2058
|
-
})]
|
|
2059
|
-
}),
|
|
2060
|
-
children: (itemIds, startIndex) => itemIds.map((itemId, index) => jsx(Row, {
|
|
2061
|
-
itemId,
|
|
2062
|
-
rowIndex: startIndex + index
|
|
2063
|
-
}, itemId))
|
|
2064
|
-
});
|
|
2065
|
-
});
|
|
2066
2582
|
function toggle(set, value, singleSelect) {
|
|
2067
2583
|
const newSet = new Set(singleSelect ? [] : set);
|
|
2068
2584
|
if (set.has(value)) {
|
|
@@ -2072,46 +2588,30 @@ function toggle(set, value, singleSelect) {
|
|
|
2072
2588
|
}
|
|
2073
2589
|
return newSet;
|
|
2074
2590
|
}
|
|
2075
|
-
function SelectFilter(
|
|
2076
|
-
var
|
|
2591
|
+
function SelectFilter(_m) {
|
|
2592
|
+
var _n = _m, {
|
|
2077
2593
|
options: providedOptions,
|
|
2078
2594
|
stringValue = asString,
|
|
2079
2595
|
render = stringValue,
|
|
2080
2596
|
singleSelect
|
|
2081
|
-
} =
|
|
2597
|
+
} = _n, props = __objRest(_n, [
|
|
2082
2598
|
"options",
|
|
2083
2599
|
"stringValue",
|
|
2084
2600
|
"render",
|
|
2085
2601
|
"singleSelect"
|
|
2086
2602
|
]);
|
|
2087
|
-
const
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
Search,
|
|
2094
|
-
Clear
|
|
2095
|
-
},
|
|
2096
|
-
text
|
|
2097
|
-
} = useTheme();
|
|
2603
|
+
const IconButton2 = useTheme((t) => t.components.IconButton);
|
|
2604
|
+
const Checkbox2 = useTheme((t) => t.components.Checkbox);
|
|
2605
|
+
const Search2 = useTheme((t) => t.icons.Search);
|
|
2606
|
+
const Clear2 = useTheme((t) => t.icons.Clear);
|
|
2607
|
+
const selected = useTheme((t) => t.text.selected);
|
|
2608
|
+
const noResults = useTheme((t) => t.text.noResults);
|
|
2098
2609
|
const table = useTableContext();
|
|
2099
2610
|
const columnId = useColumnContext();
|
|
2100
|
-
const options = table.useState((state) => {
|
|
2101
|
-
var _a;
|
|
2102
|
-
if (providedOptions)
|
|
2103
|
-
return uniq(providedOptions);
|
|
2104
|
-
const column = state.activeColumns.find((column2) => column2.id === columnId);
|
|
2105
|
-
if (!column)
|
|
2106
|
-
return [];
|
|
2107
|
-
const filterBy = (_a = props.filterBy) != null ? _a : (x) => x;
|
|
2108
|
-
return uniq(flatMap(state.items, (item) => castArray(filterBy(column.value(item), item))));
|
|
2109
|
-
});
|
|
2110
|
-
const [query, setQuery] = useState("");
|
|
2111
|
-
const filtered = options.filter((option) => !query || stringValue(option).toLowerCase().includes(query.toLowerCase()));
|
|
2112
2611
|
const {
|
|
2113
2612
|
value = /* @__PURE__ */ new Set(),
|
|
2114
|
-
onChange
|
|
2613
|
+
onChange,
|
|
2614
|
+
filterBy
|
|
2115
2615
|
} = useFilter(__spreadProps(__spreadValues({}, props), {
|
|
2116
2616
|
id: "selectFilter",
|
|
2117
2617
|
isActive(filterValue) {
|
|
@@ -2121,6 +2621,16 @@ function SelectFilter(_g) {
|
|
|
2121
2621
|
return filterValue.has(value2);
|
|
2122
2622
|
}
|
|
2123
2623
|
}));
|
|
2624
|
+
const options = table.useState((state) => {
|
|
2625
|
+
if (providedOptions)
|
|
2626
|
+
return uniq(providedOptions);
|
|
2627
|
+
const column = state.activeColumns.find((column2) => column2.id === columnId);
|
|
2628
|
+
if (!column)
|
|
2629
|
+
return [];
|
|
2630
|
+
return uniq(flatMap(state.items, (item) => castArray(filterBy(column.value(item), item))));
|
|
2631
|
+
});
|
|
2632
|
+
const [query, setQuery] = useState("");
|
|
2633
|
+
const filtered = options.filter((option) => !query || stringValue(option).toLowerCase().includes(query.toLowerCase()));
|
|
2124
2634
|
return jsxs("div", {
|
|
2125
2635
|
css: {
|
|
2126
2636
|
padding: "calc(var(--spacing) * 2)",
|
|
@@ -2129,10 +2639,10 @@ function SelectFilter(_g) {
|
|
|
2129
2639
|
},
|
|
2130
2640
|
children: [jsx(AutoFocusTextField, {
|
|
2131
2641
|
value: query,
|
|
2132
|
-
onChange: (
|
|
2133
|
-
endIcon: jsx(
|
|
2642
|
+
onChange: (e2) => setQuery(e2.target.value),
|
|
2643
|
+
endIcon: jsx(IconButton2, {
|
|
2134
2644
|
onClick: () => setQuery(""),
|
|
2135
|
-
children: !query ? jsx(
|
|
2645
|
+
children: !query ? jsx(Search2, {}) : jsx(Clear2, {})
|
|
2136
2646
|
}),
|
|
2137
2647
|
css: {
|
|
2138
2648
|
marginBottom: "var(--spacing)"
|
|
@@ -2144,16 +2654,16 @@ function SelectFilter(_g) {
|
|
|
2144
2654
|
},
|
|
2145
2655
|
children: [jsx(FormControlLabel, {
|
|
2146
2656
|
disabled: value.size === 0,
|
|
2147
|
-
control: jsx(
|
|
2657
|
+
control: jsx(Checkbox2, {
|
|
2148
2658
|
disabled: value.size === 0,
|
|
2149
2659
|
checked: value.size > 0,
|
|
2150
2660
|
onChange: () => onChange(/* @__PURE__ */ new Set())
|
|
2151
2661
|
}),
|
|
2152
2662
|
label: jsxs(Fragment, {
|
|
2153
|
-
children: ["<",
|
|
2663
|
+
children: ["<", selected(value.size), ">"]
|
|
2154
2664
|
})
|
|
2155
2665
|
}), filtered.map((option, index) => jsx(FormControlLabel, {
|
|
2156
|
-
control: jsx(
|
|
2666
|
+
control: jsx(Checkbox2, {
|
|
2157
2667
|
checked: value.has(option),
|
|
2158
2668
|
onChange: () => onChange(toggle(value, option, singleSelect))
|
|
2159
2669
|
}),
|
|
@@ -2163,7 +2673,7 @@ function SelectFilter(_g) {
|
|
|
2163
2673
|
css: {
|
|
2164
2674
|
textAlign: "center"
|
|
2165
2675
|
},
|
|
2166
|
-
children:
|
|
2676
|
+
children: noResults
|
|
2167
2677
|
})]
|
|
2168
2678
|
});
|
|
2169
2679
|
}
|
|
@@ -2192,9 +2702,10 @@ function debounce(fn, ms) {
|
|
|
2192
2702
|
});
|
|
2193
2703
|
}
|
|
2194
2704
|
function useFilter(impl) {
|
|
2195
|
-
var _a;
|
|
2196
2705
|
const table = useTableContext();
|
|
2197
2706
|
const columnId = useColumnContext();
|
|
2707
|
+
const cache = useTableMemo();
|
|
2708
|
+
const filterBy = impl.filterBy && cache("", impl.filterBy);
|
|
2198
2709
|
useEffect(() => {
|
|
2199
2710
|
table.update((state) => {
|
|
2200
2711
|
if (impl.defaultValue !== void 0) {
|
|
@@ -2204,7 +2715,7 @@ function useFilter(impl) {
|
|
|
2204
2715
|
}, []);
|
|
2205
2716
|
useEffect(() => {
|
|
2206
2717
|
table.update((state) => {
|
|
2207
|
-
state.filters.set(columnId, castDraft(impl));
|
|
2718
|
+
state.filters.set(columnId, castDraft(__spreadProps(__spreadValues({}, impl), { filterBy })));
|
|
2208
2719
|
if (impl.value !== void 0) {
|
|
2209
2720
|
state.filterValues.set(columnId, impl.value);
|
|
2210
2721
|
}
|
|
@@ -2214,7 +2725,7 @@ function useFilter(impl) {
|
|
|
2214
2725
|
state.filters.delete(columnId);
|
|
2215
2726
|
});
|
|
2216
2727
|
};
|
|
2217
|
-
}, [table, columnId,
|
|
2728
|
+
}, [table, columnId, impl]);
|
|
2218
2729
|
const value = table.useState((state) => state.filterValues.get(columnId));
|
|
2219
2730
|
const [dirtyValue, setDirtyValue] = useState();
|
|
2220
2731
|
const implRef = useRef(impl);
|
|
@@ -2239,7 +2750,8 @@ function useFilter(impl) {
|
|
|
2239
2750
|
return {
|
|
2240
2751
|
value: dirtyValue != null ? dirtyValue : value,
|
|
2241
2752
|
onChange,
|
|
2242
|
-
close: useContext(FilterControlContext)
|
|
2753
|
+
close: useContext(FilterControlContext),
|
|
2754
|
+
filterBy: filterBy != null ? filterBy : (x) => x
|
|
2243
2755
|
};
|
|
2244
2756
|
}
|
|
2245
2757
|
const textMatch = (text, query) => {
|
|
@@ -2261,23 +2773,17 @@ const termMatch = (text, query) => {
|
|
|
2261
2773
|
}
|
|
2262
2774
|
return true;
|
|
2263
2775
|
};
|
|
2264
|
-
function TextFilter(
|
|
2265
|
-
var
|
|
2776
|
+
function TextFilter(_o) {
|
|
2777
|
+
var _p = _o, {
|
|
2266
2778
|
compare = textMatch,
|
|
2267
2779
|
filterBy = asStringOrArray
|
|
2268
|
-
} =
|
|
2780
|
+
} = _p, props = __objRest(_p, [
|
|
2269
2781
|
"compare",
|
|
2270
2782
|
"filterBy"
|
|
2271
2783
|
]);
|
|
2272
|
-
const
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
},
|
|
2276
|
-
icons: {
|
|
2277
|
-
Search,
|
|
2278
|
-
Clear
|
|
2279
|
-
}
|
|
2280
|
-
} = useTheme();
|
|
2784
|
+
const IconButton2 = useTheme((t) => t.components.IconButton);
|
|
2785
|
+
const Search2 = useTheme((t) => t.icons.Search);
|
|
2786
|
+
const Clear2 = useTheme((t) => t.icons.Clear);
|
|
2281
2787
|
const {
|
|
2282
2788
|
value = "",
|
|
2283
2789
|
onChange
|
|
@@ -2298,13 +2804,13 @@ function TextFilter(_i) {
|
|
|
2298
2804
|
},
|
|
2299
2805
|
children: jsx(AutoFocusTextField, {
|
|
2300
2806
|
value,
|
|
2301
|
-
onChange: (
|
|
2302
|
-
endIcon: jsx(
|
|
2807
|
+
onChange: (e2) => onChange(e2.target.value),
|
|
2808
|
+
endIcon: jsx(IconButton2, {
|
|
2303
2809
|
onClick: () => onChange(""),
|
|
2304
|
-
children: !value ? jsx(
|
|
2810
|
+
children: !value ? jsx(Search2, {}) : jsx(Clear2, {})
|
|
2305
2811
|
})
|
|
2306
2812
|
})
|
|
2307
2813
|
});
|
|
2308
2814
|
}
|
|
2309
|
-
export { AutoFocusTextField, ColumnContext, DateFilter, SelectFilter, Table, TableContext, TextFilter, termMatch, textMatch, useColumnContext, useFilter, useTableContext, useTheme };
|
|
2815
|
+
export { AutoFocusTextField, ColumnContext, DateFilter, DatePicker, SelectFilter, Table, TableContext, TextFilter, dateIntersect, endOfDay, startOfDay, termMatch, textMatch, useColumnContext, useFilter, useTableContext, useTheme };
|
|
2310
2816
|
//# sourceMappingURL=index.js.map
|