schummar-table 0.5.5 → 0.6.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 +1277 -799
- 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 +2054 -1576
- 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 +0 -2
- package/dist/types/components/dateInput.d.ts +5 -0
- package/dist/types/components/datePicker.d.ts +2 -0
- package/dist/types/hooks/useTheme.d.ts +2 -1
- 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 +1 -2
- 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,177 @@ var __objRest = (source, exclude) => {
|
|
|
29
29
|
}
|
|
30
30
|
return target;
|
|
31
31
|
};
|
|
32
|
-
import {
|
|
33
|
-
import {
|
|
34
|
-
|
|
32
|
+
import { useState, useEffect, useMemo, useRef, createContext, useCallback, memo, useContext, cloneElement, useLayoutEffect, 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, m as mergeThemes, g as globalTableTheme, T as TableThemeContext, 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
|
+
class Queue {
|
|
42
|
+
constructor() {
|
|
43
|
+
this.q = new Array();
|
|
44
|
+
this.isRunning = false;
|
|
45
|
+
}
|
|
46
|
+
run(job, replace) {
|
|
47
|
+
return new Promise((resolve, reject) => {
|
|
48
|
+
if (replace) {
|
|
49
|
+
this.q = [];
|
|
50
|
+
}
|
|
51
|
+
this.q.push({ job, resolve, reject });
|
|
52
|
+
if (!this.isRunning)
|
|
53
|
+
this.start();
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
async start() {
|
|
57
|
+
this.isRunning = true;
|
|
58
|
+
let next;
|
|
59
|
+
while (next = this.q.shift()) {
|
|
60
|
+
try {
|
|
61
|
+
const result = await next.job();
|
|
62
|
+
next.resolve(result);
|
|
63
|
+
} catch (e2) {
|
|
64
|
+
next.reject(e2);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
this.isRunning = false;
|
|
68
|
+
}
|
|
44
69
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
70
|
+
const KEYS = ["sort", "selection", "expanded", "hiddenColumns", "filterValues", "columnWidths", "columnOrder"];
|
|
71
|
+
const storageName = (id) => `schummar-table_state-v1_${id}`;
|
|
72
|
+
function stringify(value) {
|
|
73
|
+
function prepare(value2) {
|
|
74
|
+
if (value2 instanceof Date) {
|
|
75
|
+
return { __date: value2.toJSON() };
|
|
49
76
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
const {
|
|
53
|
-
visible
|
|
54
|
-
} = useContext(PopoverContext);
|
|
55
|
-
useLayoutEffect(() => {
|
|
56
|
-
if (visible && ref.current) {
|
|
57
|
-
ref.current.focus();
|
|
77
|
+
if (value2 instanceof Set) {
|
|
78
|
+
return { __set: Array.from(value2).map(prepare) };
|
|
58
79
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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
|
-
}));
|
|
75
|
-
}
|
|
76
|
-
const weekDays = [0, 1, 2, 3, 4, 5, 6];
|
|
77
|
-
const months = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11];
|
|
78
|
-
const startOfDay = (d) => new Date(d.getFullYear(), d.getMonth(), d.getDate());
|
|
79
|
-
const endOfDay = (d) => new Date(d.getFullYear(), d.getMonth(), d.getDate() + 1, 0, 0, 0, -1);
|
|
80
|
-
function dateIntersect(a2, b) {
|
|
81
|
-
if (a2 instanceof Date) {
|
|
82
|
-
a2 = {
|
|
83
|
-
min: a2,
|
|
84
|
-
max: a2
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
if (b instanceof Date) {
|
|
88
|
-
b = {
|
|
89
|
-
min: b,
|
|
90
|
-
max: b
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
if (!(a2 == null ? void 0 : a2.min) || !a2.max || !(b == null ? void 0 : b.min) || !b.max) {
|
|
94
|
-
return false;
|
|
80
|
+
if (value2 instanceof Map) {
|
|
81
|
+
return { __map: Array.from(value2.entries()).map((entry) => entry.map(prepare)) };
|
|
82
|
+
}
|
|
83
|
+
if (value2 instanceof Array) {
|
|
84
|
+
return value2.map(prepare);
|
|
85
|
+
}
|
|
86
|
+
if (value2 instanceof Object) {
|
|
87
|
+
return Object.fromEntries(Object.entries(value2).map(([k, v]) => [k, prepare(v)]));
|
|
88
|
+
}
|
|
89
|
+
return value2;
|
|
95
90
|
}
|
|
96
|
-
return
|
|
91
|
+
return JSON.stringify(prepare(value));
|
|
97
92
|
}
|
|
98
|
-
function
|
|
99
|
-
value,
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
locale,
|
|
103
|
-
firstDayOfWeek = 0
|
|
104
|
-
}) {
|
|
105
|
-
const {
|
|
106
|
-
components: {
|
|
107
|
-
IconButton
|
|
108
|
-
},
|
|
109
|
-
icons: {
|
|
110
|
-
ChevronRight
|
|
93
|
+
function parse(value) {
|
|
94
|
+
return JSON.parse(value, (_key, value2) => {
|
|
95
|
+
if (value2 instanceof Object && "__date" in value2) {
|
|
96
|
+
return new Date(value2.__date);
|
|
111
97
|
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
const {
|
|
120
|
-
calendars,
|
|
121
|
-
getBackProps,
|
|
122
|
-
getForwardProps,
|
|
123
|
-
getDateProps
|
|
124
|
-
} = useDayzed({
|
|
125
|
-
onDateSelected: () => void 0,
|
|
126
|
-
firstDayOfWeek,
|
|
127
|
-
showOutsideDays: true,
|
|
128
|
-
date: dateInView,
|
|
129
|
-
onOffsetChanged: (offset) => setDateInView(new Date(dateInView.getFullYear(), dateInView.getMonth() + offset)),
|
|
130
|
-
offset: 0
|
|
98
|
+
if (value2 instanceof Object && "__set" in value2) {
|
|
99
|
+
return new Set(value2.__set);
|
|
100
|
+
}
|
|
101
|
+
if (value2 instanceof Object && "__map" in value2) {
|
|
102
|
+
return new Map(value2.__map);
|
|
103
|
+
}
|
|
104
|
+
return value2;
|
|
131
105
|
});
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
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
|
-
});
|
|
106
|
+
}
|
|
107
|
+
function useTableStateStorage() {
|
|
108
|
+
const table = useTableContext();
|
|
109
|
+
const [isHydrated, setIsHydrated] = useState(false);
|
|
110
|
+
useEffect(() => {
|
|
111
|
+
const { persist } = table.getState().props;
|
|
112
|
+
if (!persist) {
|
|
113
|
+
setIsHydrated(true);
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
let isCanceled = false;
|
|
117
|
+
(async () => {
|
|
118
|
+
var _a, _b;
|
|
119
|
+
try {
|
|
120
|
+
const { storage, id, include, exclude } = persist;
|
|
121
|
+
const json = await storage.getItem(storageName(id));
|
|
122
|
+
if (isCanceled || !json)
|
|
123
|
+
return;
|
|
124
|
+
const data = parse(json);
|
|
125
|
+
(_b = (_a = table.getState().props).debug) == null ? void 0 : _b.call(_a, "load", json, data);
|
|
126
|
+
table.update((state) => {
|
|
127
|
+
var _a2, _b2, _c, _d;
|
|
128
|
+
for (const key of KEYS) {
|
|
129
|
+
if ((!include || include.includes(key)) && !(exclude == null ? void 0 : exclude.includes(key)) && key in data) {
|
|
130
|
+
if (key === "filterValues") {
|
|
131
|
+
for (const [id2, value] of data[key]) {
|
|
132
|
+
if ((_b2 = (_a2 = state.filters.get(id2)) == null ? void 0 : _a2.persist) != null ? _b2 : true) {
|
|
133
|
+
state.filterValues.set(id2, value);
|
|
134
|
+
}
|
|
249
135
|
}
|
|
250
136
|
} else {
|
|
251
|
-
|
|
137
|
+
state[key] = data[key];
|
|
138
|
+
if (key === "expanded" || key === "hiddenColumns" || key === "selection" || key === "sort") {
|
|
139
|
+
(_d = (_c = state.props)[`on${key.slice(0, 1).toUpperCase() + key.slice(1)}Change`]) == null ? void 0 : _d.call(_c, data[key]);
|
|
140
|
+
}
|
|
252
141
|
}
|
|
253
|
-
},
|
|
254
|
-
onPointerOver: () => setHovered(date),
|
|
255
|
-
onPointerOut: () => setHovered(void 0),
|
|
256
|
-
children: date.getDate()
|
|
257
|
-
}), `${index}-${dayIndex}`);
|
|
258
|
-
}))]
|
|
259
|
-
})]
|
|
260
|
-
}, `${month}${year}`))
|
|
261
|
-
});
|
|
262
|
-
}
|
|
263
|
-
function MonthSelector({
|
|
264
|
-
value,
|
|
265
|
-
onChange,
|
|
266
|
-
locale
|
|
267
|
-
}) {
|
|
268
|
-
const {
|
|
269
|
-
components: {
|
|
270
|
-
Popover
|
|
271
|
-
}
|
|
272
|
-
} = useTheme();
|
|
273
|
-
const cssVariables = useCssVariables();
|
|
274
|
-
const [anchor, setAnchor] = useState();
|
|
275
|
-
const formatMonth = useMemo(() => {
|
|
276
|
-
const {
|
|
277
|
-
format
|
|
278
|
-
} = new Intl.DateTimeFormat(locale, {
|
|
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
142
|
}
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
})
|
|
318
|
-
})]
|
|
319
|
-
});
|
|
320
|
-
}
|
|
321
|
-
function YearSelector({
|
|
322
|
-
value,
|
|
323
|
-
onChange,
|
|
324
|
-
locale
|
|
325
|
-
}) {
|
|
326
|
-
const [input, setInput] = useState();
|
|
327
|
-
const ref = useRef(null);
|
|
328
|
-
function apply() {
|
|
329
|
-
onChange(Number(input));
|
|
330
|
-
setInput(void 0);
|
|
331
|
-
}
|
|
332
|
-
const formatYear = useMemo(() => {
|
|
333
|
-
const {
|
|
334
|
-
format
|
|
335
|
-
} = new Intl.DateTimeFormat(locale, {
|
|
336
|
-
year: "numeric"
|
|
337
|
-
});
|
|
338
|
-
return (year) => format(new Date(year, 0, 1));
|
|
339
|
-
}, [locale]);
|
|
340
|
-
useLayoutEffect(() => {
|
|
341
|
-
var _a;
|
|
342
|
-
return (_a = ref.current) == null ? void 0 : _a.focus();
|
|
343
|
-
}, [ref.current]);
|
|
344
|
-
if (input === void 0) {
|
|
345
|
-
return jsx("div", {
|
|
346
|
-
onClick: () => setInput(String(value)),
|
|
347
|
-
children: formatYear(value)
|
|
348
|
-
});
|
|
349
|
-
}
|
|
350
|
-
return jsx("input", {
|
|
351
|
-
ref,
|
|
352
|
-
css: {
|
|
353
|
-
width: "4ch"
|
|
354
|
-
},
|
|
355
|
-
value: input,
|
|
356
|
-
onChange: (e) => {
|
|
357
|
-
if (e.target.value.match(/^\d{0,4}$/)) {
|
|
358
|
-
setInput(e.target.value);
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
} catch (e2) {
|
|
146
|
+
console.error("Failed to load table state:", e2);
|
|
147
|
+
} finally {
|
|
148
|
+
setIsHydrated(true);
|
|
359
149
|
}
|
|
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)
|
|
150
|
+
})();
|
|
151
|
+
return () => {
|
|
152
|
+
isCanceled = true;
|
|
377
153
|
};
|
|
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
|
-
});
|
|
154
|
+
}, []);
|
|
155
|
+
useEffect(() => {
|
|
156
|
+
if (!isHydrated)
|
|
157
|
+
return;
|
|
158
|
+
const q = new Queue();
|
|
159
|
+
return table.subscribe((state) => {
|
|
160
|
+
var _a, _b;
|
|
161
|
+
if (!state.props.persist)
|
|
162
|
+
return;
|
|
163
|
+
const { storage, id, include, exclude } = state.props.persist;
|
|
164
|
+
const data = {};
|
|
165
|
+
for (const key of KEYS) {
|
|
166
|
+
if ((!include || include.includes(key)) && !(exclude == null ? void 0 : exclude.includes(key))) {
|
|
167
|
+
if (key === "filterValues") {
|
|
168
|
+
data[key] = /* @__PURE__ */ new Map();
|
|
169
|
+
for (const [id2, value] of state.filterValues) {
|
|
170
|
+
if ((_b = (_a = state.filters.get(id2)) == null ? void 0 : _a.persist) != null ? _b : true) {
|
|
171
|
+
data.filterValues.set(id2, value);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
} else {
|
|
175
|
+
data[key] = state[key];
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
return { storage, id, data };
|
|
180
|
+
}, (props) => {
|
|
181
|
+
var _a, _b;
|
|
182
|
+
if (!props)
|
|
183
|
+
return;
|
|
184
|
+
const { storage, id, data } = props;
|
|
185
|
+
(_b = (_a = table.getState().props).debug) == null ? void 0 : _b.call(_a, "save", data, stringify(data));
|
|
186
|
+
q.run(async () => {
|
|
187
|
+
await storage.setItem(storageName(id), stringify(data));
|
|
188
|
+
}, true);
|
|
189
|
+
}, { throttle: 1e3 });
|
|
190
|
+
}, [isHydrated]);
|
|
191
|
+
return isHydrated;
|
|
466
192
|
}
|
|
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
193
|
const flatMap = (arr, flatMap2) => {
|
|
490
194
|
return [...arr].reduce((out, cur) => out.concat(flatMap2(cur)), []);
|
|
491
195
|
};
|
|
492
196
|
const orderBy = (arr, selectors = [], direction = []) => {
|
|
493
197
|
if (selectors.length === 0)
|
|
494
198
|
selectors = [(t) => t];
|
|
495
|
-
return [...arr].sort((
|
|
199
|
+
return [...arr].sort((a, b) => {
|
|
496
200
|
var _a, _b;
|
|
497
201
|
for (let i = 0; i < selectors.length; i++) {
|
|
498
|
-
const _a2 = (_a = selectors[i]) == null ? void 0 : _a.call(selectors,
|
|
202
|
+
const _a2 = (_a = selectors[i]) == null ? void 0 : _a.call(selectors, a);
|
|
499
203
|
const _b2 = (_b = selectors[i]) == null ? void 0 : _b.call(selectors, b);
|
|
500
204
|
const dir = direction[i] === "desc" ? -1 : 1;
|
|
501
205
|
if (_a2 > _b2)
|
|
@@ -512,9 +216,9 @@ const uniq = (arr) => {
|
|
|
512
216
|
set.add(t);
|
|
513
217
|
return Array.from(set);
|
|
514
218
|
};
|
|
515
|
-
const intersect = (
|
|
219
|
+
const intersect = (a, b) => {
|
|
516
220
|
const result = /* @__PURE__ */ new Set();
|
|
517
|
-
for (const x of
|
|
221
|
+
for (const x of a)
|
|
518
222
|
if (b.has(x))
|
|
519
223
|
result.add(x);
|
|
520
224
|
return result;
|
|
@@ -556,191 +260,14 @@ const asStringOrArray = (x) => {
|
|
|
556
260
|
return x.map(asString);
|
|
557
261
|
return asString(x);
|
|
558
262
|
};
|
|
559
|
-
const castArray = (
|
|
263
|
+
const castArray = (a) => a instanceof Array ? a : [a];
|
|
560
264
|
const cx = (...classNames) => classNames.flatMap((entry) => {
|
|
561
265
|
if (!entry)
|
|
562
266
|
return [];
|
|
563
267
|
if (typeof entry === "string")
|
|
564
268
|
return [entry];
|
|
565
|
-
return Object.entries(entry).filter(([, predicate]) => predicate).map(([
|
|
269
|
+
return Object.entries(entry).filter(([, predicate]) => predicate).map(([className2]) => className2);
|
|
566
270
|
}).join(" ");
|
|
567
|
-
function FormControlLabel({
|
|
568
|
-
control,
|
|
569
|
-
label,
|
|
570
|
-
disabled
|
|
571
|
-
}) {
|
|
572
|
-
return jsxs("label", {
|
|
573
|
-
css: [{
|
|
574
|
-
display: "flex",
|
|
575
|
-
alignItems: "center",
|
|
576
|
-
cursor: "pointer",
|
|
577
|
-
userSelect: "none",
|
|
578
|
-
"& > *": {
|
|
579
|
-
cursor: "pointer"
|
|
580
|
-
}
|
|
581
|
-
}, disabled && {
|
|
582
|
-
color: "rgba(0, 0, 0, 0.26)"
|
|
583
|
-
}],
|
|
584
|
-
children: [control, jsx("span", {
|
|
585
|
-
css: {
|
|
586
|
-
marginLeft: "var(--spacing)"
|
|
587
|
-
},
|
|
588
|
-
children: label
|
|
589
|
-
})]
|
|
590
|
-
});
|
|
591
|
-
}
|
|
592
|
-
class Queue {
|
|
593
|
-
constructor() {
|
|
594
|
-
this.q = new Array();
|
|
595
|
-
this.isRunning = false;
|
|
596
|
-
}
|
|
597
|
-
run(job, replace) {
|
|
598
|
-
return new Promise((resolve, reject) => {
|
|
599
|
-
if (replace) {
|
|
600
|
-
this.q = [];
|
|
601
|
-
}
|
|
602
|
-
this.q.push({ job, resolve, reject });
|
|
603
|
-
if (!this.isRunning)
|
|
604
|
-
this.start();
|
|
605
|
-
});
|
|
606
|
-
}
|
|
607
|
-
async start() {
|
|
608
|
-
this.isRunning = true;
|
|
609
|
-
let next;
|
|
610
|
-
while (next = this.q.shift()) {
|
|
611
|
-
try {
|
|
612
|
-
const result = await next.job();
|
|
613
|
-
next.resolve(result);
|
|
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
271
|
function calcItems(state) {
|
|
745
272
|
useEffect(() => state.addReaction((state2) => [
|
|
746
273
|
state2.props.items,
|
|
@@ -1003,12 +530,10 @@ function syncSelections(table) {
|
|
|
1003
530
|
}
|
|
1004
531
|
function useTableState(_props) {
|
|
1005
532
|
const props = calcProps(_props);
|
|
1006
|
-
const theme = useTableTheme(props);
|
|
1007
533
|
const state = useMemo(() => {
|
|
1008
534
|
var _a, _b, _c, _d;
|
|
1009
535
|
return new Store({
|
|
1010
536
|
props,
|
|
1011
|
-
theme,
|
|
1012
537
|
sort: (_a = props.defaultSort) != null ? _a : [],
|
|
1013
538
|
selection: (_b = props.defaultSelection) != null ? _b : /* @__PURE__ */ new Set(),
|
|
1014
539
|
expanded: (_c = props.defaultExpanded) != null ? _c : /* @__PURE__ */ new Set(),
|
|
@@ -1027,1044 +552,1997 @@ function useTableState(_props) {
|
|
|
1027
552
|
lastSelectedId: void 0
|
|
1028
553
|
});
|
|
1029
554
|
}, []);
|
|
1030
|
-
filterColumns(state);
|
|
1031
|
-
calcItems(state);
|
|
1032
|
-
syncSelections(state);
|
|
1033
|
-
cleanupState(state);
|
|
1034
|
-
useEffect(() => {
|
|
1035
|
-
state.update((state2) => {
|
|
1036
|
-
state2.props = castDraft(props);
|
|
1037
|
-
if (props.sort)
|
|
1038
|
-
state2.sort = props.sort;
|
|
1039
|
-
if (props.selection)
|
|
1040
|
-
state2.selection = props.selection;
|
|
1041
|
-
if (props.expanded)
|
|
1042
|
-
state2.expanded = props.expanded;
|
|
1043
|
-
if (props.hiddenColumns)
|
|
1044
|
-
state2.hiddenColumns = props.hiddenColumns;
|
|
1045
|
-
for (const column of props.columns) {
|
|
1046
|
-
if (!state2.columnOrder.includes(column.id)) {
|
|
1047
|
-
const index = props.columns.indexOf(column);
|
|
1048
|
-
state2.columnOrder.splice(index, 0, column.id);
|
|
1049
|
-
}
|
|
1050
|
-
}
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
555
|
+
filterColumns(state);
|
|
556
|
+
calcItems(state);
|
|
557
|
+
syncSelections(state);
|
|
558
|
+
cleanupState(state);
|
|
559
|
+
useEffect(() => {
|
|
560
|
+
state.update((state2) => {
|
|
561
|
+
state2.props = castDraft(props);
|
|
562
|
+
if (props.sort)
|
|
563
|
+
state2.sort = props.sort;
|
|
564
|
+
if (props.selection)
|
|
565
|
+
state2.selection = props.selection;
|
|
566
|
+
if (props.expanded)
|
|
567
|
+
state2.expanded = props.expanded;
|
|
568
|
+
if (props.hiddenColumns)
|
|
569
|
+
state2.hiddenColumns = props.hiddenColumns;
|
|
570
|
+
for (const column of props.columns) {
|
|
571
|
+
if (!state2.columnOrder.includes(column.id)) {
|
|
572
|
+
const index = props.columns.indexOf(column);
|
|
573
|
+
state2.columnOrder.splice(index, 0, column.id);
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
});
|
|
577
|
+
}, [state, props]);
|
|
578
|
+
return state;
|
|
579
|
+
}
|
|
580
|
+
function useCssVariables() {
|
|
581
|
+
const theme = useTheme();
|
|
582
|
+
return {
|
|
583
|
+
"--spacing": theme.spacing,
|
|
584
|
+
"--primaryMain": theme.colors.primary.main,
|
|
585
|
+
"--primaryLight": theme.colors.primary.light,
|
|
586
|
+
"--primaryContrastText": theme.colors.primary.contrastText,
|
|
587
|
+
"--secondaryMain": theme.colors.secondary.main,
|
|
588
|
+
"--secondaryLight": theme.colors.secondary.light,
|
|
589
|
+
"--secondaryContrastText": theme.colors.secondary.contrastText
|
|
590
|
+
};
|
|
591
|
+
}
|
|
592
|
+
const ColumnHeaderContext = new StoreScope({
|
|
593
|
+
items: /* @__PURE__ */ new Map()
|
|
594
|
+
});
|
|
595
|
+
function ColumnHeader(props) {
|
|
596
|
+
const ref = useRef(null);
|
|
597
|
+
const columnId = useColumnContext();
|
|
598
|
+
const table = useTableContext();
|
|
599
|
+
const enabled = table.useState("props.enableColumnReorder");
|
|
600
|
+
const store = ColumnHeaderContext.useStore();
|
|
601
|
+
const draggingStart = useRef();
|
|
602
|
+
const clone = useRef();
|
|
603
|
+
useEffect(() => {
|
|
604
|
+
const div = ref.current;
|
|
605
|
+
if (!div)
|
|
606
|
+
return;
|
|
607
|
+
store.update((state) => {
|
|
608
|
+
state.items.set(columnId, castDraft(div));
|
|
609
|
+
});
|
|
610
|
+
return () => {
|
|
611
|
+
store.update((state) => {
|
|
612
|
+
state.items.delete(columnId);
|
|
613
|
+
});
|
|
614
|
+
};
|
|
615
|
+
}, [ref.current, store, columnId]);
|
|
616
|
+
function calcTargetIndex(offsetLeft) {
|
|
617
|
+
var _a, _b, _c;
|
|
618
|
+
const cols = table.getState().columnOrder.map((id) => ({
|
|
619
|
+
id,
|
|
620
|
+
div: store.getState().items.get(id)
|
|
621
|
+
}));
|
|
622
|
+
const otherCols = cols.filter((col) => col.id !== columnId);
|
|
623
|
+
const firstOffsetleft = (_c = (_b = (_a = cols.find((col) => col.div)) == null ? void 0 : _a.div) == null ? void 0 : _b.offsetLeft) != null ? _c : 0;
|
|
624
|
+
let sum = 0;
|
|
625
|
+
const targetIndex = otherCols.findIndex((col) => {
|
|
626
|
+
var _a2, _b2;
|
|
627
|
+
const width = (_b2 = (_a2 = col.div) == null ? void 0 : _a2.offsetWidth) != null ? _b2 : 0;
|
|
628
|
+
if (sum + width / 2 > offsetLeft - firstOffsetleft)
|
|
629
|
+
return true;
|
|
630
|
+
sum += width;
|
|
631
|
+
return false;
|
|
632
|
+
});
|
|
633
|
+
return targetIndex === -1 ? otherCols.length : targetIndex;
|
|
634
|
+
}
|
|
635
|
+
function onPointerDown(e2) {
|
|
636
|
+
const div = ref.current;
|
|
637
|
+
if (!div)
|
|
638
|
+
return;
|
|
639
|
+
draggingStart.current = {
|
|
640
|
+
mouseX: e2.clientX,
|
|
641
|
+
bounds: div.getBoundingClientRect()
|
|
642
|
+
};
|
|
643
|
+
}
|
|
644
|
+
function onPointerMove(e2) {
|
|
645
|
+
table.update((state) => {
|
|
646
|
+
const div = ref.current;
|
|
647
|
+
if (!div || draggingStart.current === void 0 || Math.abs(e2.clientX - draggingStart.current.mouseX) < 5)
|
|
648
|
+
return;
|
|
649
|
+
e2.stopPropagation();
|
|
650
|
+
div.setPointerCapture(e2.pointerId);
|
|
651
|
+
if (!clone.current) {
|
|
652
|
+
clone.current = div.cloneNode(true);
|
|
653
|
+
document.body.append(clone.current);
|
|
654
|
+
for (const [key, value] of Object.entries(getComputedStyle(div))) {
|
|
655
|
+
try {
|
|
656
|
+
clone.current.style[key] = value;
|
|
657
|
+
} catch {
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
Object.assign(clone.current.style, {
|
|
661
|
+
pointerEvents: "none",
|
|
662
|
+
position: "fixed",
|
|
663
|
+
boxShadow: "0px 5px 5px -3px rgb(0 0 0 / 20%), 0px 8px 10px 1px rgb(0 0 0 / 14%), 0px 3px 14px 2px rgb(0 0 0 / 12%)",
|
|
664
|
+
left: `${draggingStart.current.bounds.left}px`,
|
|
665
|
+
top: `${draggingStart.current.bounds.top}px`
|
|
666
|
+
});
|
|
667
|
+
div.style.color = "rgba(0, 0, 0, 0.2)";
|
|
668
|
+
}
|
|
669
|
+
clone.current.style.left = `${draggingStart.current.bounds.left + e2.clientX - draggingStart.current.mouseX}px`;
|
|
670
|
+
const index = state.columnOrder.indexOf(columnId);
|
|
671
|
+
const targetIndex = calcTargetIndex(div.offsetLeft + e2.clientX - draggingStart.current.mouseX);
|
|
672
|
+
const columns = table.getState().columnOrder.map((id, index2) => {
|
|
673
|
+
var _a, _b;
|
|
674
|
+
return {
|
|
675
|
+
id,
|
|
676
|
+
index: index2,
|
|
677
|
+
width: (_b = (_a = store.getState().items.get(id)) == null ? void 0 : _a.offsetWidth) != null ? _b : 0
|
|
678
|
+
};
|
|
679
|
+
});
|
|
680
|
+
state.columnOrder.forEach((id, i) => {
|
|
681
|
+
let offset = 0;
|
|
682
|
+
if (i === index) {
|
|
683
|
+
if (targetIndex > index) {
|
|
684
|
+
offset = columns.slice(index + 1, targetIndex + 1).reduce((sum, col) => sum + col.width, 0);
|
|
685
|
+
} else if (targetIndex < index) {
|
|
686
|
+
offset = -columns.slice(targetIndex, index).reduce((sum, col) => sum + col.width, 0);
|
|
687
|
+
}
|
|
688
|
+
} else if (i >= targetIndex && i < index) {
|
|
689
|
+
offset = div.offsetWidth;
|
|
690
|
+
} else if (i > index && i <= targetIndex) {
|
|
691
|
+
offset = -div.offsetWidth;
|
|
692
|
+
}
|
|
693
|
+
state.columnStyleOverride.set(id, {
|
|
694
|
+
transition: "transform 500ms",
|
|
695
|
+
transform: `translate3d(${offset}px, 0, 0)`,
|
|
696
|
+
zIndex: i === index ? 1 : void 0
|
|
697
|
+
});
|
|
698
|
+
});
|
|
699
|
+
});
|
|
700
|
+
}
|
|
701
|
+
function onPointerUp(e2) {
|
|
702
|
+
table.update((state) => {
|
|
703
|
+
var _a;
|
|
704
|
+
const div = ref.current;
|
|
705
|
+
if (!div || draggingStart.current === void 0)
|
|
706
|
+
return;
|
|
707
|
+
const index = state.columnOrder.indexOf(columnId);
|
|
708
|
+
const targetIndex = calcTargetIndex(div.offsetLeft + e2.clientX - draggingStart.current.mouseX);
|
|
709
|
+
state.columnOrder.splice(index, 1);
|
|
710
|
+
state.columnOrder.splice(targetIndex, 0, columnId);
|
|
711
|
+
(_a = clone.current) == null ? void 0 : _a.remove();
|
|
712
|
+
div.style.color = "";
|
|
713
|
+
state.columnStyleOverride.clear();
|
|
714
|
+
draggingStart.current = void 0;
|
|
715
|
+
clone.current = void 0;
|
|
716
|
+
});
|
|
717
|
+
}
|
|
718
|
+
return jsx("div", __spreadProps(__spreadValues({}, props), {
|
|
719
|
+
css: {
|
|
720
|
+
position: "relative",
|
|
721
|
+
userSelect: "none"
|
|
722
|
+
},
|
|
723
|
+
ref,
|
|
724
|
+
onPointerDown: enabled ? onPointerDown : void 0,
|
|
725
|
+
onPointerMove: enabled ? onPointerMove : void 0,
|
|
726
|
+
onPointerUp: enabled ? onPointerUp : void 0,
|
|
727
|
+
children: props.children
|
|
728
|
+
}));
|
|
729
|
+
}
|
|
730
|
+
function FormControlLabel({
|
|
731
|
+
control,
|
|
732
|
+
label,
|
|
733
|
+
disabled
|
|
734
|
+
}) {
|
|
735
|
+
return jsxs("label", {
|
|
736
|
+
css: [{
|
|
737
|
+
display: "flex",
|
|
738
|
+
alignItems: "center",
|
|
739
|
+
cursor: "pointer",
|
|
740
|
+
userSelect: "none",
|
|
741
|
+
"& > *": {
|
|
742
|
+
cursor: "pointer"
|
|
743
|
+
}
|
|
744
|
+
}, disabled && {
|
|
745
|
+
color: "rgba(0, 0, 0, 0.26)"
|
|
746
|
+
}],
|
|
747
|
+
children: [control, jsx("span", {
|
|
748
|
+
css: {
|
|
749
|
+
marginLeft: "var(--spacing)"
|
|
750
|
+
},
|
|
751
|
+
children: label
|
|
752
|
+
})]
|
|
753
|
+
});
|
|
754
|
+
}
|
|
755
|
+
function ColumnSelection() {
|
|
756
|
+
const {
|
|
757
|
+
components: {
|
|
758
|
+
IconButton: IconButton2,
|
|
759
|
+
Popover: Popover2,
|
|
760
|
+
Checkbox: Checkbox2
|
|
761
|
+
},
|
|
762
|
+
icons: {
|
|
763
|
+
Settings: Settings2
|
|
764
|
+
},
|
|
765
|
+
text
|
|
766
|
+
} = useTheme();
|
|
767
|
+
const cssVariables = useCssVariables();
|
|
768
|
+
const table = useTableContext();
|
|
769
|
+
const columns = table.useState("props.columns");
|
|
770
|
+
const hiddenColumns = table.useState("hiddenColumns");
|
|
771
|
+
const [anchorEl, setAnchorEl] = useState(null);
|
|
772
|
+
const toggle2 = (column) => {
|
|
773
|
+
const {
|
|
774
|
+
props: {
|
|
775
|
+
hiddenColumns: controlledHiddenColumns,
|
|
776
|
+
onHiddenColumnsChange
|
|
777
|
+
}
|
|
778
|
+
} = table.getState();
|
|
779
|
+
const newValue = new Set(hiddenColumns);
|
|
780
|
+
if (hiddenColumns.has(column.id))
|
|
781
|
+
newValue.delete(column.id);
|
|
782
|
+
else
|
|
783
|
+
newValue.add(column.id);
|
|
784
|
+
if (!controlledHiddenColumns) {
|
|
785
|
+
table.update((state) => {
|
|
786
|
+
state.hiddenColumns = newValue;
|
|
787
|
+
});
|
|
788
|
+
}
|
|
789
|
+
onHiddenColumnsChange == null ? void 0 : onHiddenColumnsChange(newValue);
|
|
790
|
+
};
|
|
791
|
+
return jsxs(Fragment, {
|
|
792
|
+
children: [jsx(IconButton2, {
|
|
793
|
+
onClick: (e2) => setAnchorEl(anchorEl ? null : e2.currentTarget),
|
|
794
|
+
children: jsx(Settings2, {})
|
|
795
|
+
}), jsx(Popover2, {
|
|
796
|
+
anchorEl,
|
|
797
|
+
open: !!anchorEl,
|
|
798
|
+
onClose: () => setAnchorEl(null),
|
|
799
|
+
css: cssVariables,
|
|
800
|
+
children: jsxs("div", {
|
|
801
|
+
css: {
|
|
802
|
+
padding: `calc(var(--spacing) * 2)`,
|
|
803
|
+
display: "grid"
|
|
804
|
+
},
|
|
805
|
+
children: [jsx("div", {
|
|
806
|
+
css: {
|
|
807
|
+
marginBottom: "var(--spacing)"
|
|
808
|
+
},
|
|
809
|
+
children: text.selectColumns
|
|
810
|
+
}), columns.map((column) => jsx(FormControlLabel, {
|
|
811
|
+
control: jsx(Checkbox2, {
|
|
812
|
+
checked: !hiddenColumns.has(column.id),
|
|
813
|
+
onChange: () => toggle2(column),
|
|
814
|
+
disabled: column.cannotHide
|
|
815
|
+
}),
|
|
816
|
+
label: column.header
|
|
817
|
+
}, column.id))]
|
|
818
|
+
})
|
|
819
|
+
})]
|
|
820
|
+
});
|
|
821
|
+
}
|
|
822
|
+
function csvExport(data, { sepPrefix, separator = ",", quote = '"', eol = "\n" } = {}) {
|
|
823
|
+
const cells = data.map((line) => line.map((value) => {
|
|
824
|
+
if (typeof value === "number")
|
|
825
|
+
return String(value);
|
|
826
|
+
if (![separator, quote, eol].some((c) => value.includes(c)))
|
|
827
|
+
return value;
|
|
828
|
+
const clean = value.replace(new RegExp(quote, "g"), `${quote}${quote}`);
|
|
829
|
+
return `${quote}${clean}${quote}`;
|
|
830
|
+
}));
|
|
831
|
+
return (sepPrefix ? `SEP=${separator}
|
|
832
|
+
` : "") + cells.map((line) => line.join(separator)).join(eol);
|
|
833
|
+
}
|
|
834
|
+
function Export$1() {
|
|
835
|
+
const table = useTableContext();
|
|
836
|
+
const {
|
|
837
|
+
components: {
|
|
838
|
+
Button: Button2,
|
|
839
|
+
IconButton: IconButton2,
|
|
840
|
+
Popover: Popover2
|
|
841
|
+
},
|
|
842
|
+
icons: {
|
|
843
|
+
Export: Export2,
|
|
844
|
+
Clipboard: Clipboard2
|
|
845
|
+
},
|
|
846
|
+
text
|
|
847
|
+
} = useTheme();
|
|
848
|
+
const cssVariables = useCssVariables();
|
|
849
|
+
const [anchor, setAnchor] = useState(null);
|
|
850
|
+
const generate = (options) => {
|
|
851
|
+
const {
|
|
852
|
+
activeColumns,
|
|
853
|
+
activeItems
|
|
854
|
+
} = table.getState();
|
|
855
|
+
const data = [activeColumns.map((column) => String(column.id)), ...activeItems.map((item) => activeColumns.map((column) => column.exportCell(column.value(item), item)))];
|
|
856
|
+
return csvExport(data, options);
|
|
857
|
+
};
|
|
858
|
+
const copy = () => {
|
|
859
|
+
navigator.clipboard.writeText(generate(table.getState().props.enableExport.copy));
|
|
860
|
+
};
|
|
861
|
+
const download = () => {
|
|
862
|
+
const a = document.createElement("a");
|
|
863
|
+
a.href = "data:text/csv;charset=utf-8," + encodeURIComponent(generate(table.getState().props.enableExport.download));
|
|
864
|
+
a.download = "export.csv";
|
|
865
|
+
document.body.appendChild(a);
|
|
866
|
+
a.click();
|
|
867
|
+
document.body.removeChild(a);
|
|
868
|
+
};
|
|
869
|
+
return jsxs(Fragment, {
|
|
870
|
+
children: [jsx(IconButton2, {
|
|
871
|
+
onClick: (e2) => setAnchor(anchor ? null : e2.currentTarget),
|
|
872
|
+
children: jsx(Export2, {
|
|
873
|
+
css: !!anchor && {
|
|
874
|
+
color: "var(--primaryMain)"
|
|
875
|
+
}
|
|
876
|
+
})
|
|
877
|
+
}), jsx(Popover2, {
|
|
878
|
+
open: !!anchor,
|
|
879
|
+
onClose: () => setAnchor(null),
|
|
880
|
+
anchorEl: anchor,
|
|
881
|
+
css: cssVariables,
|
|
882
|
+
children: jsxs("div", {
|
|
883
|
+
css: {
|
|
884
|
+
padding: `calc(var(--spacing) * 2)`,
|
|
885
|
+
display: "grid",
|
|
886
|
+
justifyItems: "stretch",
|
|
887
|
+
gap: "var(--spacing)",
|
|
888
|
+
"& > *": {
|
|
889
|
+
justifyContent: "start"
|
|
890
|
+
}
|
|
891
|
+
},
|
|
892
|
+
children: [jsx("div", {
|
|
893
|
+
css: {
|
|
894
|
+
marginBottom: "var(--spacing)"
|
|
895
|
+
},
|
|
896
|
+
children: text.exportTitle
|
|
897
|
+
}), jsx(Button2, {
|
|
898
|
+
startIcon: jsx(Clipboard2, {}),
|
|
899
|
+
onClick: copy,
|
|
900
|
+
children: text.exportCopy
|
|
901
|
+
}), jsx(Button2, {
|
|
902
|
+
startIcon: jsx(Export2, {}),
|
|
903
|
+
onClick: download,
|
|
904
|
+
children: text.exportDownload
|
|
905
|
+
})]
|
|
906
|
+
})
|
|
907
|
+
})]
|
|
908
|
+
});
|
|
909
|
+
}
|
|
910
|
+
const FilterControlContext = createContext(() => void 0);
|
|
911
|
+
function FilterControl() {
|
|
912
|
+
const table = useTableContext();
|
|
913
|
+
const columnId = useColumnContext();
|
|
914
|
+
const {
|
|
915
|
+
components: {
|
|
916
|
+
IconButton: IconButton2,
|
|
917
|
+
Popover: Popover2
|
|
918
|
+
},
|
|
919
|
+
icons: {
|
|
920
|
+
FilterList: FilterList2,
|
|
921
|
+
ArrowDropDown: ArrowDropDown2
|
|
922
|
+
}
|
|
923
|
+
} = useTheme();
|
|
924
|
+
const cssVariables = useCssVariables();
|
|
925
|
+
const [anchor, setAnchor] = useState(null);
|
|
926
|
+
const isActive = table.useState((state) => {
|
|
927
|
+
const filter2 = state.filters.get(columnId);
|
|
928
|
+
const filterValue = state.filterValues.get(columnId);
|
|
929
|
+
return filter2 !== void 0 && filterValue !== void 0 && filter2.isActive(filterValue);
|
|
930
|
+
});
|
|
931
|
+
const filter = table.useState((state) => {
|
|
932
|
+
var _a;
|
|
933
|
+
return (_a = state.activeColumns.find((column) => column.id === columnId)) == null ? void 0 : _a.filter;
|
|
934
|
+
});
|
|
935
|
+
function reset() {
|
|
936
|
+
table.update((state) => {
|
|
937
|
+
state.filterValues.delete(columnId);
|
|
938
|
+
});
|
|
939
|
+
}
|
|
940
|
+
const close = useCallback(function() {
|
|
941
|
+
setAnchor(null);
|
|
942
|
+
}, []);
|
|
943
|
+
if (!filter)
|
|
944
|
+
return null;
|
|
945
|
+
return jsxs(FilterControlContext.Provider, {
|
|
946
|
+
value: close,
|
|
947
|
+
children: [jsx("div", {
|
|
948
|
+
onClick: (e2) => setAnchor(e2.currentTarget),
|
|
949
|
+
onContextMenu: (e2) => {
|
|
950
|
+
reset();
|
|
951
|
+
e2.preventDefault();
|
|
952
|
+
return false;
|
|
953
|
+
},
|
|
954
|
+
children: jsx(IconButton2, {
|
|
955
|
+
css: [{
|
|
956
|
+
color: "#b0bac9"
|
|
957
|
+
}, isActive && {
|
|
958
|
+
color: "var(--primaryMain) !important"
|
|
959
|
+
}],
|
|
960
|
+
children: isActive ? jsx(FilterList2, {}) : jsx(ArrowDropDown2, {})
|
|
961
|
+
})
|
|
962
|
+
}), jsx("div", {
|
|
963
|
+
onPointerDown: (e2) => {
|
|
964
|
+
e2.stopPropagation();
|
|
965
|
+
},
|
|
966
|
+
onPointerMove: (e2) => {
|
|
967
|
+
e2.stopPropagation();
|
|
968
|
+
},
|
|
969
|
+
children: jsx(Popover2, {
|
|
970
|
+
open: true,
|
|
971
|
+
hidden: !anchor,
|
|
972
|
+
onClose: () => setAnchor(null),
|
|
973
|
+
anchorEl: anchor != null ? anchor : document.body,
|
|
974
|
+
css: cssVariables,
|
|
975
|
+
children: filter
|
|
976
|
+
})
|
|
977
|
+
})]
|
|
978
|
+
});
|
|
1055
979
|
}
|
|
1056
|
-
|
|
1057
|
-
items: /* @__PURE__ */ new Map()
|
|
1058
|
-
});
|
|
1059
|
-
function ColumnHeader(props) {
|
|
1060
|
-
const ref = useRef(null);
|
|
1061
|
-
const columnId = useColumnContext();
|
|
980
|
+
function ResizeHandle() {
|
|
1062
981
|
const table = useTableContext();
|
|
1063
|
-
const
|
|
1064
|
-
const
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
if (!div)
|
|
1070
|
-
return;
|
|
1071
|
-
store.update((state) => {
|
|
1072
|
-
state.items.set(columnId, castDraft(div));
|
|
1073
|
-
});
|
|
1074
|
-
return () => {
|
|
1075
|
-
store.update((state) => {
|
|
1076
|
-
state.items.delete(columnId);
|
|
1077
|
-
});
|
|
1078
|
-
};
|
|
1079
|
-
}, [ref.current, store, columnId]);
|
|
1080
|
-
function calcTargetIndex(offsetLeft) {
|
|
1081
|
-
var _a, _b, _c;
|
|
1082
|
-
const cols = table.getState().columnOrder.map((id) => ({
|
|
1083
|
-
id,
|
|
1084
|
-
div: store.getState().items.get(id)
|
|
1085
|
-
}));
|
|
1086
|
-
const otherCols = cols.filter((col) => col.id !== columnId);
|
|
1087
|
-
const firstOffsetleft = (_c = (_b = (_a = cols.find((col) => col.div)) == null ? void 0 : _a.div) == null ? void 0 : _b.offsetLeft) != null ? _c : 0;
|
|
1088
|
-
let sum = 0;
|
|
1089
|
-
const targetIndex = otherCols.findIndex((col) => {
|
|
1090
|
-
var _a2, _b2;
|
|
1091
|
-
const width = (_b2 = (_a2 = col.div) == null ? void 0 : _a2.offsetWidth) != null ? _b2 : 0;
|
|
1092
|
-
if (sum + width / 2 > offsetLeft - firstOffsetleft)
|
|
1093
|
-
return true;
|
|
1094
|
-
sum += width;
|
|
1095
|
-
return false;
|
|
1096
|
-
});
|
|
1097
|
-
return targetIndex === -1 ? otherCols.length : targetIndex;
|
|
982
|
+
const columnId = useColumnContext();
|
|
983
|
+
const enabled = table.useState("props.enableColumnResize");
|
|
984
|
+
function onPointerDown(e2) {
|
|
985
|
+
e2.stopPropagation();
|
|
986
|
+
const div = e2.target;
|
|
987
|
+
div.setPointerCapture(e2.pointerId);
|
|
1098
988
|
}
|
|
1099
|
-
function
|
|
1100
|
-
|
|
1101
|
-
|
|
989
|
+
function onPointerMove(e2) {
|
|
990
|
+
e2.stopPropagation();
|
|
991
|
+
const div = e2.target;
|
|
992
|
+
if (!div.hasPointerCapture(e2.pointerId))
|
|
1102
993
|
return;
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
bounds: div.getBoundingClientRect()
|
|
1106
|
-
};
|
|
1107
|
-
}
|
|
1108
|
-
function onPointerMove(e) {
|
|
994
|
+
const parent = div.parentElement;
|
|
995
|
+
const width = Math.max(e2.clientX - parent.getBoundingClientRect().left + 5, 50);
|
|
1109
996
|
table.update((state) => {
|
|
1110
|
-
|
|
1111
|
-
if (!div || draggingStart.current === void 0 || Math.abs(e.clientX - draggingStart.current.mouseX) < 5)
|
|
1112
|
-
return;
|
|
1113
|
-
e.stopPropagation();
|
|
1114
|
-
div.setPointerCapture(e.pointerId);
|
|
1115
|
-
if (!clone.current) {
|
|
1116
|
-
clone.current = div.cloneNode(true);
|
|
1117
|
-
document.body.append(clone.current);
|
|
1118
|
-
for (const [key, value] of Object.entries(getComputedStyle(div))) {
|
|
1119
|
-
try {
|
|
1120
|
-
clone.current.style[key] = value;
|
|
1121
|
-
} catch {
|
|
1122
|
-
}
|
|
1123
|
-
}
|
|
1124
|
-
Object.assign(clone.current.style, {
|
|
1125
|
-
pointerEvents: "none",
|
|
1126
|
-
position: "fixed",
|
|
1127
|
-
boxShadow: "0px 5px 5px -3px rgb(0 0 0 / 20%), 0px 8px 10px 1px rgb(0 0 0 / 14%), 0px 3px 14px 2px rgb(0 0 0 / 12%)",
|
|
1128
|
-
left: `${draggingStart.current.bounds.left}px`,
|
|
1129
|
-
top: `${draggingStart.current.bounds.top}px`
|
|
1130
|
-
});
|
|
1131
|
-
div.style.color = "rgba(0, 0, 0, 0.2)";
|
|
1132
|
-
}
|
|
1133
|
-
clone.current.style.left = `${draggingStart.current.bounds.left + e.clientX - draggingStart.current.mouseX}px`;
|
|
1134
|
-
const index = state.columnOrder.indexOf(columnId);
|
|
1135
|
-
const targetIndex = calcTargetIndex(div.offsetLeft + e.clientX - draggingStart.current.mouseX);
|
|
1136
|
-
const columns = table.getState().columnOrder.map((id, index2) => {
|
|
1137
|
-
var _a, _b;
|
|
1138
|
-
return {
|
|
1139
|
-
id,
|
|
1140
|
-
index: index2,
|
|
1141
|
-
width: (_b = (_a = store.getState().items.get(id)) == null ? void 0 : _a.offsetWidth) != null ? _b : 0
|
|
1142
|
-
};
|
|
1143
|
-
});
|
|
1144
|
-
state.columnOrder.forEach((id, i) => {
|
|
1145
|
-
let offset = 0;
|
|
1146
|
-
if (i === index) {
|
|
1147
|
-
if (targetIndex > index) {
|
|
1148
|
-
offset = columns.slice(index + 1, targetIndex + 1).reduce((sum, col) => sum + col.width, 0);
|
|
1149
|
-
} else if (targetIndex < index) {
|
|
1150
|
-
offset = -columns.slice(targetIndex, index).reduce((sum, col) => sum + col.width, 0);
|
|
1151
|
-
}
|
|
1152
|
-
} else if (i >= targetIndex && i < index) {
|
|
1153
|
-
offset = div.offsetWidth;
|
|
1154
|
-
} else if (i > index && i <= targetIndex) {
|
|
1155
|
-
offset = -div.offsetWidth;
|
|
1156
|
-
}
|
|
1157
|
-
state.columnStyleOverride.set(id, {
|
|
1158
|
-
transition: "transform 500ms",
|
|
1159
|
-
transform: `translate3d(${offset}px, 0, 0)`,
|
|
1160
|
-
zIndex: i === index ? 1 : void 0
|
|
1161
|
-
});
|
|
1162
|
-
});
|
|
997
|
+
state.columnWidths.set(columnId, `${width}px`);
|
|
1163
998
|
});
|
|
1164
999
|
}
|
|
1165
|
-
function onPointerUp(
|
|
1000
|
+
function onPointerUp(e2) {
|
|
1001
|
+
e2.stopPropagation();
|
|
1002
|
+
const div = e2.target;
|
|
1003
|
+
div.releasePointerCapture(e2.pointerId);
|
|
1004
|
+
}
|
|
1005
|
+
function onDoubleClick(e2) {
|
|
1166
1006
|
table.update((state) => {
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
const targetIndex = calcTargetIndex(div.offsetLeft + e.clientX - draggingStart.current.mouseX);
|
|
1173
|
-
state.columnOrder.splice(index, 1);
|
|
1174
|
-
state.columnOrder.splice(targetIndex, 0, columnId);
|
|
1175
|
-
(_a = clone.current) == null ? void 0 : _a.remove();
|
|
1176
|
-
div.style.color = "";
|
|
1177
|
-
state.columnStyleOverride.clear();
|
|
1178
|
-
draggingStart.current = void 0;
|
|
1179
|
-
clone.current = void 0;
|
|
1007
|
+
if (e2.getModifierState("Control")) {
|
|
1008
|
+
state.columnWidths.delete(columnId);
|
|
1009
|
+
} else {
|
|
1010
|
+
state.columnWidths.set(columnId, "max-content");
|
|
1011
|
+
}
|
|
1180
1012
|
});
|
|
1181
1013
|
}
|
|
1182
|
-
return jsx(
|
|
1183
|
-
|
|
1184
|
-
position: "relative",
|
|
1185
|
-
userSelect: "none"
|
|
1186
|
-
},
|
|
1187
|
-
ref,
|
|
1014
|
+
return jsx(ResizeHandleView, {
|
|
1015
|
+
enabled,
|
|
1188
1016
|
onPointerDown: enabled ? onPointerDown : void 0,
|
|
1189
1017
|
onPointerMove: enabled ? onPointerMove : void 0,
|
|
1190
1018
|
onPointerUp: enabled ? onPointerUp : void 0,
|
|
1191
|
-
|
|
1192
|
-
})
|
|
1019
|
+
onDoubleClick: enabled ? onDoubleClick : void 0
|
|
1020
|
+
});
|
|
1193
1021
|
}
|
|
1194
|
-
function
|
|
1022
|
+
function ResizeHandleView(_a) {
|
|
1023
|
+
var _b = _a, {
|
|
1024
|
+
enabled
|
|
1025
|
+
} = _b, props = __objRest(_b, [
|
|
1026
|
+
"enabled"
|
|
1027
|
+
]);
|
|
1028
|
+
return jsx("div", __spreadValues({
|
|
1029
|
+
css: {
|
|
1030
|
+
alignSelf: "stretch",
|
|
1031
|
+
padding: "0 5px",
|
|
1032
|
+
cursor: enabled ? "col-resize" : "initial",
|
|
1033
|
+
display: "flex",
|
|
1034
|
+
alignItems: "center",
|
|
1035
|
+
"&:after": {
|
|
1036
|
+
content: '""',
|
|
1037
|
+
width: 1,
|
|
1038
|
+
height: "1.5em",
|
|
1039
|
+
background: "#c9cfda",
|
|
1040
|
+
transition: "transform 300ms"
|
|
1041
|
+
}
|
|
1042
|
+
}
|
|
1043
|
+
}, props));
|
|
1044
|
+
}
|
|
1045
|
+
const Cell = memo(function Cell2({
|
|
1046
|
+
itemId,
|
|
1047
|
+
rowIndex
|
|
1048
|
+
}) {
|
|
1049
|
+
var _a, _b;
|
|
1050
|
+
const table = useTableContext();
|
|
1051
|
+
const columnId = useColumnContext();
|
|
1052
|
+
const {
|
|
1053
|
+
classes
|
|
1054
|
+
} = useTheme();
|
|
1055
|
+
const column = table.useState((state) => state.activeColumns.find((column2) => column2.id === columnId));
|
|
1056
|
+
const item = table.useState((state) => state.activeItemsById.get(itemId));
|
|
1057
|
+
const columnStyleOverride = table.useState((state) => state.columnStyleOverride.get(columnId), {
|
|
1058
|
+
throttle: 16
|
|
1059
|
+
});
|
|
1060
|
+
if (!column || !item)
|
|
1061
|
+
return null;
|
|
1062
|
+
(_b = (_a = table.getState().props).debugRender) == null ? void 0 : _b.call(_a, "render cell", itemId, columnId);
|
|
1063
|
+
const classNames = [...calcClassNames(classes, item, rowIndex), ...calcClassNames(column == null ? void 0 : column.classes, item, rowIndex)];
|
|
1064
|
+
const content = column.renderCell(column.value(item), item);
|
|
1065
|
+
return jsx("div", {
|
|
1066
|
+
className: cx(...classNames),
|
|
1067
|
+
css: [defaultClasses.cell, classNames, columnStyleOverride],
|
|
1068
|
+
children: typeof content === "string" ? jsx("span", {
|
|
1069
|
+
css: defaultClasses.text,
|
|
1070
|
+
title: content,
|
|
1071
|
+
children: content
|
|
1072
|
+
}) : content
|
|
1073
|
+
});
|
|
1074
|
+
});
|
|
1075
|
+
function ExpandControl({
|
|
1076
|
+
itemId,
|
|
1077
|
+
hasDeferredChildren
|
|
1078
|
+
}) {
|
|
1195
1079
|
const {
|
|
1196
1080
|
components: {
|
|
1197
|
-
IconButton,
|
|
1198
|
-
|
|
1199
|
-
Checkbox
|
|
1081
|
+
IconButton: IconButton2,
|
|
1082
|
+
Spinner: Spinner2
|
|
1200
1083
|
},
|
|
1201
1084
|
icons: {
|
|
1202
|
-
|
|
1203
|
-
}
|
|
1204
|
-
text
|
|
1085
|
+
ChevronRight: ChevronRight2
|
|
1086
|
+
}
|
|
1205
1087
|
} = useTheme();
|
|
1206
|
-
const cssVariables = useCssVariables();
|
|
1207
1088
|
const table = useTableContext();
|
|
1208
|
-
const
|
|
1209
|
-
const
|
|
1210
|
-
|
|
1211
|
-
|
|
1089
|
+
const isExpanded = table.useState((state) => state.expanded.has(itemId));
|
|
1090
|
+
const hasChildren = table.useState((state) => {
|
|
1091
|
+
var _a;
|
|
1092
|
+
return !!((_a = state.activeItemsById.get(itemId)) == null ? void 0 : _a.children.length);
|
|
1093
|
+
});
|
|
1094
|
+
function toggle2() {
|
|
1212
1095
|
const {
|
|
1213
1096
|
props: {
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1097
|
+
expanded: controlledExpanded,
|
|
1098
|
+
expandOnlyOne,
|
|
1099
|
+
onExpandedChange
|
|
1100
|
+
},
|
|
1101
|
+
expanded,
|
|
1102
|
+
activeItemsById
|
|
1217
1103
|
} = table.getState();
|
|
1218
|
-
const
|
|
1219
|
-
if (
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1104
|
+
const newExpanded = new Set(expanded);
|
|
1105
|
+
if (expandOnlyOne)
|
|
1106
|
+
newExpanded.clear();
|
|
1107
|
+
if (isExpanded)
|
|
1108
|
+
newExpanded.delete(itemId);
|
|
1109
|
+
else {
|
|
1110
|
+
newExpanded.add(itemId);
|
|
1111
|
+
const item = activeItemsById.get(itemId);
|
|
1112
|
+
for (const ancestor of item ? getAncestors(activeItemsById, item) : []) {
|
|
1113
|
+
newExpanded.add(ancestor);
|
|
1114
|
+
}
|
|
1115
|
+
}
|
|
1116
|
+
onExpandedChange == null ? void 0 : onExpandedChange(newExpanded);
|
|
1117
|
+
if (!controlledExpanded) {
|
|
1224
1118
|
table.update((state) => {
|
|
1225
|
-
state.
|
|
1119
|
+
state.expanded = newExpanded;
|
|
1226
1120
|
});
|
|
1227
1121
|
}
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
})
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
marginBottom: "var(--spacing)"
|
|
1247
|
-
},
|
|
1248
|
-
children: text.selectColumns
|
|
1249
|
-
}), columns.map((column) => jsx(FormControlLabel, {
|
|
1250
|
-
control: jsx(Checkbox, {
|
|
1251
|
-
checked: !hiddenColumns.has(column.id),
|
|
1252
|
-
onChange: () => toggle2(column),
|
|
1253
|
-
disabled: column.cannotHide
|
|
1254
|
-
}),
|
|
1255
|
-
label: column.header
|
|
1256
|
-
}, column.id))]
|
|
1257
|
-
})
|
|
1258
|
-
})]
|
|
1122
|
+
}
|
|
1123
|
+
if (isExpanded && hasDeferredChildren && !hasChildren) {
|
|
1124
|
+
return jsx(Spinner2, {
|
|
1125
|
+
css: {
|
|
1126
|
+
margin: "0 var(--spacing)"
|
|
1127
|
+
}
|
|
1128
|
+
});
|
|
1129
|
+
}
|
|
1130
|
+
return jsx(IconButton2, {
|
|
1131
|
+
onClick: toggle2,
|
|
1132
|
+
children: jsx("span", {
|
|
1133
|
+
css: {
|
|
1134
|
+
display: "inline-flex",
|
|
1135
|
+
transition: "all 300ms",
|
|
1136
|
+
transform: isExpanded ? "rotate3d(0, 0, 1, 90deg)" : "rotate3d(0, 0, 1, 0deg)"
|
|
1137
|
+
},
|
|
1138
|
+
children: jsx(ChevronRight2, {})
|
|
1139
|
+
})
|
|
1259
1140
|
});
|
|
1260
1141
|
}
|
|
1261
|
-
function
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
return String(value);
|
|
1265
|
-
if (![separator, quote, eol].some((c2) => value.includes(c2)))
|
|
1266
|
-
return value;
|
|
1267
|
-
const clean = value.replace(new RegExp(quote, "g"), `${quote}${quote}`);
|
|
1268
|
-
return `${quote}${clean}${quote}`;
|
|
1269
|
-
}));
|
|
1270
|
-
return (sepPrefix ? `SEP=${separator}
|
|
1271
|
-
` : "") + cells.map((line) => line.join(separator)).join(eol);
|
|
1272
|
-
}
|
|
1273
|
-
function Export() {
|
|
1142
|
+
function SelectComponent({
|
|
1143
|
+
itemId
|
|
1144
|
+
}) {
|
|
1274
1145
|
const table = useTableContext();
|
|
1275
1146
|
const {
|
|
1276
1147
|
components: {
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
Popover
|
|
1280
|
-
},
|
|
1281
|
-
icons: {
|
|
1282
|
-
Export: Export2,
|
|
1283
|
-
Clipboard
|
|
1284
|
-
},
|
|
1285
|
-
text
|
|
1148
|
+
Checkbox: Checkbox2
|
|
1149
|
+
}
|
|
1286
1150
|
} = useTheme();
|
|
1287
|
-
const
|
|
1288
|
-
|
|
1289
|
-
|
|
1151
|
+
const isSelected = table.useState((state) => {
|
|
1152
|
+
const itemIds = itemId ? [itemId] : Array.from(state.activeItemsById.keys());
|
|
1153
|
+
return state.activeItemsById.size > 0 && itemIds.every((itemId2) => state.selection.has(itemId2));
|
|
1154
|
+
});
|
|
1155
|
+
function toggle2(e2) {
|
|
1156
|
+
const mouseEvent = e2.nativeEvent;
|
|
1290
1157
|
const {
|
|
1291
|
-
|
|
1292
|
-
|
|
1158
|
+
activeItems,
|
|
1159
|
+
activeItemsById,
|
|
1160
|
+
lastSelectedId,
|
|
1161
|
+
selection,
|
|
1162
|
+
props: {
|
|
1163
|
+
selectSyncChildren,
|
|
1164
|
+
selection: controlledSelection,
|
|
1165
|
+
onSelectionChange
|
|
1166
|
+
}
|
|
1293
1167
|
} = table.getState();
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1168
|
+
let range;
|
|
1169
|
+
if (mouseEvent.shiftKey && itemId) {
|
|
1170
|
+
const a = lastSelectedId ? activeItems.findIndex((i) => lastSelectedId === i.id) : 0;
|
|
1171
|
+
const b = activeItems.findIndex((item) => item.id === itemId);
|
|
1172
|
+
range = activeItems.slice(Math.min(a, b), Math.max(a, b) + 1);
|
|
1173
|
+
} else {
|
|
1174
|
+
const item = itemId ? activeItemsById.get(itemId) : void 0;
|
|
1175
|
+
range = item ? [item] : activeItems;
|
|
1176
|
+
}
|
|
1177
|
+
const newSelection = new Set(selection);
|
|
1178
|
+
for (const item of range) {
|
|
1179
|
+
if (isSelected)
|
|
1180
|
+
newSelection.delete(item.id);
|
|
1181
|
+
else
|
|
1182
|
+
newSelection.add(item.id);
|
|
1183
|
+
}
|
|
1184
|
+
if (selectSyncChildren && isSelected) {
|
|
1185
|
+
for (const ancestor of getAncestors(activeItemsById, ...range)) {
|
|
1186
|
+
newSelection.delete(ancestor);
|
|
1187
|
+
}
|
|
1188
|
+
for (const descendant of getDescendants(...range)) {
|
|
1189
|
+
newSelection.delete(descendant);
|
|
1190
|
+
}
|
|
1191
|
+
}
|
|
1192
|
+
onSelectionChange == null ? void 0 : onSelectionChange(newSelection);
|
|
1193
|
+
if (!controlledSelection) {
|
|
1194
|
+
table.update((state) => {
|
|
1195
|
+
state.selection = newSelection;
|
|
1196
|
+
});
|
|
1197
|
+
}
|
|
1198
|
+
table.update((state) => {
|
|
1199
|
+
state.lastSelectedId = itemId;
|
|
1200
|
+
});
|
|
1201
|
+
}
|
|
1202
|
+
return jsx(Checkbox2, {
|
|
1203
|
+
css: {
|
|
1204
|
+
justifySelf: "start",
|
|
1205
|
+
color: "#c9cfda"
|
|
1206
|
+
},
|
|
1207
|
+
checked: isSelected,
|
|
1208
|
+
onChange: toggle2
|
|
1209
|
+
});
|
|
1210
|
+
}
|
|
1211
|
+
function calcClassNames(classes, item, index) {
|
|
1212
|
+
return [(classes == null ? void 0 : classes.cell) instanceof Function ? classes.cell(item, index) : classes == null ? void 0 : classes.cell, index % 2 === 0 && (classes == null ? void 0 : classes.evenCell), index % 2 === 1 && (classes == null ? void 0 : classes.oddCell)];
|
|
1213
|
+
}
|
|
1214
|
+
const Row = memo(function Row2({
|
|
1215
|
+
itemId,
|
|
1216
|
+
rowIndex
|
|
1217
|
+
}) {
|
|
1218
|
+
var _a, _b;
|
|
1219
|
+
const table = useTableContext();
|
|
1220
|
+
const divRef = useRef(null);
|
|
1221
|
+
const {
|
|
1222
|
+
className: className2,
|
|
1223
|
+
indent,
|
|
1224
|
+
hasChildren,
|
|
1225
|
+
hasDeferredChildren,
|
|
1226
|
+
columnIds,
|
|
1227
|
+
enableSelection,
|
|
1228
|
+
rowAction
|
|
1229
|
+
} = table.useState((state) => {
|
|
1230
|
+
var _a2, _b2;
|
|
1231
|
+
const item = state.activeItemsById.get(itemId);
|
|
1232
|
+
const index = !item ? -1 : state.activeItems.indexOf(item);
|
|
1233
|
+
return {
|
|
1234
|
+
className: cx(...calcClassNames(state.props.classes, item, index)),
|
|
1235
|
+
indent: item ? getAncestors(state.activeItemsById, item).size : 0,
|
|
1236
|
+
hasChildren: !!(item == null ? void 0 : item.children.length),
|
|
1237
|
+
hasDeferredChildren: item && ((_b2 = (_a2 = state.props).hasDeferredChildren) == null ? void 0 : _b2.call(_a2, item)),
|
|
1238
|
+
columnIds: state.activeColumns.map((column) => column.id),
|
|
1239
|
+
enableSelection: state.props.enableSelection,
|
|
1240
|
+
rowAction: state.props.rowAction instanceof Function ? item ? state.props.rowAction(item, index) : null : state.props.rowAction
|
|
1241
|
+
};
|
|
1242
|
+
});
|
|
1243
|
+
useEffect(() => {
|
|
1244
|
+
const div = divRef.current;
|
|
1245
|
+
if (!div)
|
|
1246
|
+
return;
|
|
1247
|
+
const o = new ResizeObserver(() => {
|
|
1248
|
+
if (!document.contains(div))
|
|
1249
|
+
return;
|
|
1250
|
+
table.update((state) => {
|
|
1251
|
+
state.rowHeights.set(itemId, div.offsetHeight);
|
|
1252
|
+
});
|
|
1253
|
+
});
|
|
1254
|
+
o.observe(div);
|
|
1255
|
+
return () => o.disconnect();
|
|
1256
|
+
}, [divRef.current]);
|
|
1257
|
+
(_b = (_a = table.getState().props).debugRender) == null ? void 0 : _b.call(_a, "render row", itemId);
|
|
1258
|
+
return jsxs(Fragment, {
|
|
1259
|
+
children: [jsx("div", {
|
|
1260
|
+
className: className2,
|
|
1261
|
+
css: [defaultClasses.cellFill],
|
|
1262
|
+
ref: divRef
|
|
1263
|
+
}), jsxs("div", {
|
|
1264
|
+
className: className2,
|
|
1265
|
+
css: [defaultClasses.cell, defaultClasses.firstCell],
|
|
1266
|
+
children: [jsx("div", {
|
|
1267
|
+
css: {
|
|
1268
|
+
width: indent * 20
|
|
1269
|
+
}
|
|
1270
|
+
}), enableSelection && jsx(SelectComponent, {
|
|
1271
|
+
itemId
|
|
1272
|
+
}), (hasChildren || hasDeferredChildren) && jsx(ExpandControl, {
|
|
1273
|
+
itemId,
|
|
1274
|
+
hasDeferredChildren
|
|
1275
|
+
}), rowAction]
|
|
1276
|
+
}), columnIds.map((columnId) => jsx(ColumnContext.Provider, {
|
|
1277
|
+
value: columnId,
|
|
1278
|
+
children: jsx(Cell, {
|
|
1279
|
+
itemId,
|
|
1280
|
+
rowIndex
|
|
1345
1281
|
})
|
|
1282
|
+
}, columnId)), jsx("div", {
|
|
1283
|
+
className: className2,
|
|
1284
|
+
css: [defaultClasses.cellFill]
|
|
1346
1285
|
})]
|
|
1347
1286
|
});
|
|
1348
|
-
}
|
|
1349
|
-
|
|
1350
|
-
|
|
1287
|
+
});
|
|
1288
|
+
function SortComponent({
|
|
1289
|
+
children
|
|
1290
|
+
}) {
|
|
1351
1291
|
const table = useTableContext();
|
|
1352
1292
|
const columnId = useColumnContext();
|
|
1353
1293
|
const {
|
|
1354
1294
|
components: {
|
|
1355
|
-
|
|
1356
|
-
Popover
|
|
1295
|
+
Badge: Badge2
|
|
1357
1296
|
},
|
|
1358
1297
|
icons: {
|
|
1359
|
-
|
|
1360
|
-
ArrowDropDown
|
|
1298
|
+
ArrowUpward: ArrowUpward2
|
|
1361
1299
|
}
|
|
1362
1300
|
} = useTheme();
|
|
1363
|
-
const
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1301
|
+
const {
|
|
1302
|
+
direction,
|
|
1303
|
+
index
|
|
1304
|
+
} = table.useState((state) => {
|
|
1305
|
+
var _a, _b;
|
|
1306
|
+
const index2 = (_a = state.sort.findIndex((s) => s.columnId === columnId)) != null ? _a : -1;
|
|
1307
|
+
return {
|
|
1308
|
+
direction: (_b = state.sort[index2]) == null ? void 0 : _b.direction,
|
|
1309
|
+
index: index2 >= 0 && state.sort.length > 1 ? index2 + 1 : void 0
|
|
1310
|
+
};
|
|
1373
1311
|
});
|
|
1374
|
-
function
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1312
|
+
function toggle2(e2, off) {
|
|
1313
|
+
const {
|
|
1314
|
+
props: {
|
|
1315
|
+
sort: controlledSort,
|
|
1316
|
+
onSortChange
|
|
1317
|
+
}
|
|
1318
|
+
} = table.getState();
|
|
1319
|
+
const newDirection = direction === "asc" ? "desc" : "asc";
|
|
1320
|
+
const newSort = e2.getModifierState("Control") || off ? table.getState().sort.filter((s) => s.columnId !== columnId) : [];
|
|
1321
|
+
if (!off) {
|
|
1322
|
+
newSort.push({
|
|
1323
|
+
columnId,
|
|
1324
|
+
direction: newDirection
|
|
1325
|
+
});
|
|
1326
|
+
}
|
|
1327
|
+
onSortChange == null ? void 0 : onSortChange(newSort);
|
|
1328
|
+
if (!controlledSort) {
|
|
1329
|
+
table.update((state) => {
|
|
1330
|
+
state.sort = newSort;
|
|
1331
|
+
});
|
|
1332
|
+
}
|
|
1333
|
+
e2.preventDefault();
|
|
1334
|
+
return false;
|
|
1378
1335
|
}
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1336
|
+
return jsxs("div", {
|
|
1337
|
+
css: {
|
|
1338
|
+
userSelect: "none",
|
|
1339
|
+
display: "grid",
|
|
1340
|
+
gridTemplateColumns: "minmax(0, 1fr) max-content",
|
|
1341
|
+
alignItems: "center",
|
|
1342
|
+
cursor: "pointer",
|
|
1343
|
+
"& > div": {
|
|
1344
|
+
overflow: "hidden",
|
|
1345
|
+
textOverflow: "ellipsis"
|
|
1346
|
+
}
|
|
1347
|
+
},
|
|
1348
|
+
onClick: (e2) => toggle2(e2),
|
|
1349
|
+
onContextMenu: (e2) => toggle2(e2, true),
|
|
1386
1350
|
children: [jsx("div", {
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
return false;
|
|
1392
|
-
},
|
|
1393
|
-
children: jsx(IconButton, {
|
|
1351
|
+
children
|
|
1352
|
+
}), jsx(Badge2, {
|
|
1353
|
+
badgeContent: index,
|
|
1354
|
+
children: jsx("span", {
|
|
1394
1355
|
css: [{
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1356
|
+
transition: "all 300ms",
|
|
1357
|
+
fontSize: "0.8em"
|
|
1358
|
+
}, !direction && {
|
|
1359
|
+
opacity: 0
|
|
1360
|
+
}, direction === "desc" && {
|
|
1361
|
+
transform: "rotate3d(0, 0, 1, 180deg)"
|
|
1398
1362
|
}],
|
|
1399
|
-
children:
|
|
1400
|
-
})
|
|
1401
|
-
}), jsx("div", {
|
|
1402
|
-
onPointerDown: (e) => {
|
|
1403
|
-
e.stopPropagation();
|
|
1404
|
-
},
|
|
1405
|
-
onPointerMove: (e) => {
|
|
1406
|
-
e.stopPropagation();
|
|
1407
|
-
},
|
|
1408
|
-
children: jsx(Popover, {
|
|
1409
|
-
open: true,
|
|
1410
|
-
hidden: !anchor,
|
|
1411
|
-
onClose: () => setAnchor(null),
|
|
1412
|
-
anchorEl: anchor != null ? anchor : document.body,
|
|
1413
|
-
css: cssVariables,
|
|
1414
|
-
children: filter
|
|
1363
|
+
children: jsx(ArrowUpward2, {})
|
|
1415
1364
|
})
|
|
1416
1365
|
})]
|
|
1417
|
-
});
|
|
1366
|
+
});
|
|
1367
|
+
}
|
|
1368
|
+
function throttle(fn, ms) {
|
|
1369
|
+
let last = 0;
|
|
1370
|
+
let lastArgs;
|
|
1371
|
+
let timeout;
|
|
1372
|
+
function run() {
|
|
1373
|
+
const args = lastArgs;
|
|
1374
|
+
last = Date.now();
|
|
1375
|
+
lastArgs = void 0;
|
|
1376
|
+
timeout = void 0;
|
|
1377
|
+
fn(...args);
|
|
1378
|
+
}
|
|
1379
|
+
return Object.assign(function(...args) {
|
|
1380
|
+
const now = Date.now();
|
|
1381
|
+
lastArgs = args;
|
|
1382
|
+
if (timeout)
|
|
1383
|
+
;
|
|
1384
|
+
else if (now < last + ms) {
|
|
1385
|
+
timeout = setTimeout(run, last + ms - now);
|
|
1386
|
+
} else {
|
|
1387
|
+
run();
|
|
1388
|
+
}
|
|
1389
|
+
}, {
|
|
1390
|
+
flush() {
|
|
1391
|
+
if (lastArgs) {
|
|
1392
|
+
run();
|
|
1393
|
+
}
|
|
1394
|
+
}
|
|
1395
|
+
});
|
|
1396
|
+
}
|
|
1397
|
+
const findScrollRoot = (x) => {
|
|
1398
|
+
const parent = x.parentElement;
|
|
1399
|
+
if (!parent)
|
|
1400
|
+
return document.documentElement;
|
|
1401
|
+
if (parent.scrollHeight > parent.clientHeight && getComputedStyle(parent).overflowY !== "visible")
|
|
1402
|
+
return parent;
|
|
1403
|
+
return findScrollRoot(parent);
|
|
1404
|
+
};
|
|
1405
|
+
const relativeOffset = (x, y) => {
|
|
1406
|
+
if (x.offsetParent === y.offsetParent || !x.offsetParent)
|
|
1407
|
+
return x.offsetTop - y.offsetTop;
|
|
1408
|
+
if (x.offsetParent instanceof HTMLElement)
|
|
1409
|
+
return relativeOffset(x.offsetParent, y) + x.offsetTop;
|
|
1410
|
+
return 0;
|
|
1411
|
+
};
|
|
1412
|
+
function Virtualized(_c) {
|
|
1413
|
+
var _d = _c, {
|
|
1414
|
+
header,
|
|
1415
|
+
children
|
|
1416
|
+
} = _d, props = __objRest(_d, [
|
|
1417
|
+
"header",
|
|
1418
|
+
"children"
|
|
1419
|
+
]);
|
|
1420
|
+
var _a, _b, _c2, _d2;
|
|
1421
|
+
const table = useTableContext();
|
|
1422
|
+
const virtual = table.useState("props.virtual");
|
|
1423
|
+
const probeRef = useRef(null);
|
|
1424
|
+
const [, setCounter] = useState(0);
|
|
1425
|
+
const {
|
|
1426
|
+
itemIds = [],
|
|
1427
|
+
from = 0,
|
|
1428
|
+
to,
|
|
1429
|
+
before = 0,
|
|
1430
|
+
after = 0
|
|
1431
|
+
} = table.useState((state) => {
|
|
1432
|
+
var _a2;
|
|
1433
|
+
const itemIds2 = state.activeItems.map((item) => item.id);
|
|
1434
|
+
const root = probeRef.current && findScrollRoot(probeRef.current);
|
|
1435
|
+
if (!state.props.virtual)
|
|
1436
|
+
return {
|
|
1437
|
+
itemIds: itemIds2
|
|
1438
|
+
};
|
|
1439
|
+
if (!probeRef.current || !root || !document.contains(root))
|
|
1440
|
+
return {};
|
|
1441
|
+
const {
|
|
1442
|
+
rowHeight,
|
|
1443
|
+
initalRowHeight,
|
|
1444
|
+
overscan = 100,
|
|
1445
|
+
overscanTop,
|
|
1446
|
+
overscanBottom
|
|
1447
|
+
} = (_a2 = state.props.virtual instanceof Object ? state.props.virtual : void 0) != null ? _a2 : {};
|
|
1448
|
+
let totalHeight = 0;
|
|
1449
|
+
const rowHeights = itemIds2.map((itemId, index) => {
|
|
1450
|
+
var _a3, _b2;
|
|
1451
|
+
const h = (_b2 = (_a3 = rowHeight != null ? rowHeight : state.rowHeights.get(itemId)) != null ? _a3 : initalRowHeight) != null ? _b2 : index === 0 ? 100 : totalHeight / index;
|
|
1452
|
+
totalHeight += h;
|
|
1453
|
+
return h;
|
|
1454
|
+
});
|
|
1455
|
+
const probeOffset = relativeOffset(probeRef.current, root);
|
|
1456
|
+
const headerHeight = probeRef.current.offsetTop;
|
|
1457
|
+
const topOfTable = root.scrollTop - probeOffset + headerHeight;
|
|
1458
|
+
const bottomOfTable = topOfTable + root.clientHeight - headerHeight;
|
|
1459
|
+
let from2 = 0, to2 = itemIds2.length, before2 = 0, after2 = 0;
|
|
1460
|
+
for (const h of rowHeights) {
|
|
1461
|
+
if (before2 + h > topOfTable - (overscanTop != null ? overscanTop : overscan))
|
|
1462
|
+
break;
|
|
1463
|
+
from2++;
|
|
1464
|
+
before2 += h;
|
|
1465
|
+
}
|
|
1466
|
+
for (const h of rowHeights.reverse()) {
|
|
1467
|
+
if (after2 + h > totalHeight - bottomOfTable - (overscanBottom != null ? overscanBottom : overscan))
|
|
1468
|
+
break;
|
|
1469
|
+
to2--;
|
|
1470
|
+
after2 += h;
|
|
1471
|
+
}
|
|
1472
|
+
return {
|
|
1473
|
+
itemIds: itemIds2.slice(from2, to2),
|
|
1474
|
+
from: from2,
|
|
1475
|
+
to: to2,
|
|
1476
|
+
before: before2,
|
|
1477
|
+
after: after2
|
|
1478
|
+
};
|
|
1479
|
+
}, {
|
|
1480
|
+
throttle: 16
|
|
1481
|
+
});
|
|
1482
|
+
const throttleScroll = (_b = (_a = typeof virtual === "boolean" ? void 0 : virtual) == null ? void 0 : _a.throttleScroll) != null ? _b : 16;
|
|
1483
|
+
const incCounter = useMemo(() => throttle(() => setCounter((c) => c + 1), throttleScroll), [throttleScroll]);
|
|
1484
|
+
useEffect(() => {
|
|
1485
|
+
if (!virtual || !probeRef.current)
|
|
1486
|
+
return;
|
|
1487
|
+
window.addEventListener("scroll", incCounter, true);
|
|
1488
|
+
window.addEventListener("resize", incCounter, true);
|
|
1489
|
+
return () => {
|
|
1490
|
+
window.removeEventListener("scroll", incCounter, true);
|
|
1491
|
+
window.removeEventListener("resize", incCounter, true);
|
|
1492
|
+
};
|
|
1493
|
+
}, [probeRef.current, incCounter]);
|
|
1494
|
+
(_d2 = (_c2 = table.getState().props).debugRender) == null ? void 0 : _d2.call(_c2, `Virtualalized render ${from} to ${to}`);
|
|
1495
|
+
return jsxs("div", __spreadProps(__spreadValues({}, props), {
|
|
1496
|
+
children: [header, virtual && jsx("div", {
|
|
1497
|
+
style: {
|
|
1498
|
+
gridColumn: "1 / -1",
|
|
1499
|
+
height: before
|
|
1500
|
+
},
|
|
1501
|
+
ref: probeRef
|
|
1502
|
+
}), children(itemIds, from), virtual && jsx("div", {
|
|
1503
|
+
style: {
|
|
1504
|
+
gridColumn: "1 / -1",
|
|
1505
|
+
height: after
|
|
1506
|
+
}
|
|
1507
|
+
})]
|
|
1508
|
+
}));
|
|
1418
1509
|
}
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
const
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
e.stopPropagation();
|
|
1441
|
-
const div = e.target;
|
|
1442
|
-
div.releasePointerCapture(e.pointerId);
|
|
1443
|
-
}
|
|
1444
|
-
function onDoubleClick(e) {
|
|
1445
|
-
table.update((state) => {
|
|
1446
|
-
if (e.getModifierState("Control")) {
|
|
1447
|
-
state.columnWidths.delete(columnId);
|
|
1448
|
-
} else {
|
|
1449
|
-
state.columnWidths.set(columnId, "max-content");
|
|
1450
|
-
}
|
|
1451
|
-
});
|
|
1452
|
-
}
|
|
1453
|
-
return jsx(ResizeHandleView, {
|
|
1454
|
-
enabled,
|
|
1455
|
-
onPointerDown: enabled ? onPointerDown : void 0,
|
|
1456
|
-
onPointerMove: enabled ? onPointerMove : void 0,
|
|
1457
|
-
onPointerUp: enabled ? onPointerUp : void 0,
|
|
1458
|
-
onDoubleClick: enabled ? onDoubleClick : void 0
|
|
1510
|
+
const TableContext = createContext(null);
|
|
1511
|
+
const ColumnContext = createContext(null);
|
|
1512
|
+
function useTableContext() {
|
|
1513
|
+
const value = useContext(TableContext);
|
|
1514
|
+
if (!value)
|
|
1515
|
+
throw Error("No table context available");
|
|
1516
|
+
return value;
|
|
1517
|
+
}
|
|
1518
|
+
function useColumnContext() {
|
|
1519
|
+
const value = useContext(ColumnContext);
|
|
1520
|
+
if (value === null)
|
|
1521
|
+
throw Error("No column context available");
|
|
1522
|
+
return value;
|
|
1523
|
+
}
|
|
1524
|
+
function Table(props) {
|
|
1525
|
+
var _a, _b;
|
|
1526
|
+
const table = useTableState(props);
|
|
1527
|
+
(_b = (_a = table.getState().props).debugRender) == null ? void 0 : _b.call(_a, "render table");
|
|
1528
|
+
return jsx(TableContext.Provider, {
|
|
1529
|
+
value: table,
|
|
1530
|
+
children: jsx(TableLoadingState, {})
|
|
1459
1531
|
});
|
|
1460
1532
|
}
|
|
1461
|
-
function
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
} =
|
|
1465
|
-
|
|
1466
|
-
]);
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
background: "#c9cfda",
|
|
1479
|
-
transition: "transform 300ms"
|
|
1480
|
-
}
|
|
1481
|
-
}
|
|
1482
|
-
}, props));
|
|
1533
|
+
function TableLoadingState() {
|
|
1534
|
+
const {
|
|
1535
|
+
text
|
|
1536
|
+
} = useTheme();
|
|
1537
|
+
const isHydrated = useTableStateStorage();
|
|
1538
|
+
const [showLoading, setShowLoading] = useState(false);
|
|
1539
|
+
useEffect(() => {
|
|
1540
|
+
const handle = setTimeout(() => setShowLoading(true), 500);
|
|
1541
|
+
return () => clearTimeout(handle);
|
|
1542
|
+
});
|
|
1543
|
+
return jsxs(Fragment, {
|
|
1544
|
+
children: [!isHydrated && showLoading && jsx("div", {
|
|
1545
|
+
children: text.loading
|
|
1546
|
+
}), jsx(TableInner, {
|
|
1547
|
+
hidden: !isHydrated
|
|
1548
|
+
})]
|
|
1549
|
+
});
|
|
1483
1550
|
}
|
|
1484
|
-
const
|
|
1485
|
-
|
|
1486
|
-
rowIndex
|
|
1551
|
+
const TableInner = memo(function TableInner2({
|
|
1552
|
+
hidden
|
|
1487
1553
|
}) {
|
|
1488
1554
|
var _a, _b;
|
|
1489
1555
|
const table = useTableContext();
|
|
1490
|
-
const
|
|
1491
|
-
const {
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1556
|
+
const fullWidth = table.useState("props.fullWidth");
|
|
1557
|
+
const activeColumns = table.useState((state) => state.activeColumns.map((column) => ({
|
|
1558
|
+
id: column.id,
|
|
1559
|
+
width: column.width,
|
|
1560
|
+
classes: column.classes,
|
|
1561
|
+
header: column.header
|
|
1562
|
+
})));
|
|
1563
|
+
const columnWidths = table.useState("columnWidths", {
|
|
1497
1564
|
throttle: 16
|
|
1498
1565
|
});
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
const
|
|
1503
|
-
const
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1566
|
+
const columnStyleOverride = table.useState("columnStyleOverride", {
|
|
1567
|
+
throttle: 16
|
|
1568
|
+
});
|
|
1569
|
+
const defaultWidth = table.useState("props.defaultWidth");
|
|
1570
|
+
const classes = table.useState("props.classes");
|
|
1571
|
+
const stickyHeader = table.useState("props.stickyHeader");
|
|
1572
|
+
const enableSelection = table.useState("props.enableSelection");
|
|
1573
|
+
const enableColumnSelection = table.useState("props.enableColumnSelection");
|
|
1574
|
+
const enableExport = table.useState((state) => !!state.props.enableExport.copy || !!state.props.enableExport.download);
|
|
1575
|
+
const cssVariables = useCssVariables();
|
|
1576
|
+
(_b = (_a = table.getState().props).debugRender) == null ? void 0 : _b.call(_a, "render table inner");
|
|
1577
|
+
return jsx(Virtualized, {
|
|
1578
|
+
className: classes == null ? void 0 : classes.table,
|
|
1579
|
+
css: [cssVariables, defaultClasses.table, {
|
|
1580
|
+
gridTemplateColumns: [
|
|
1581
|
+
fullWidth === "right" || fullWidth === true ? "auto" : "0",
|
|
1582
|
+
"max-content",
|
|
1583
|
+
...activeColumns.map((column) => {
|
|
1584
|
+
var _a2, _b2, _c;
|
|
1585
|
+
return (_c = (_b2 = (_a2 = columnWidths.get(column.id)) != null ? _a2 : column.width) != null ? _b2 : defaultWidth) != null ? _c : "max-content";
|
|
1586
|
+
}),
|
|
1587
|
+
fullWidth === "left" || fullWidth === true ? "auto" : "0"
|
|
1588
|
+
].join(" ")
|
|
1589
|
+
}, hidden && {
|
|
1590
|
+
visibility: "hidden"
|
|
1591
|
+
}],
|
|
1592
|
+
header: jsxs(Fragment, {
|
|
1593
|
+
children: [jsx("div", {
|
|
1594
|
+
className: classes == null ? void 0 : classes.headerCell,
|
|
1595
|
+
css: [defaultClasses.headerFill, stickyHeader && defaultClasses.sticky, stickyHeader instanceof Object && stickyHeader]
|
|
1596
|
+
}), jsxs("div", {
|
|
1597
|
+
className: classes == null ? void 0 : classes.headerCell,
|
|
1598
|
+
css: [defaultClasses.headerCell, stickyHeader && defaultClasses.sticky, stickyHeader instanceof Object && stickyHeader],
|
|
1599
|
+
children: [enableSelection && jsx(SelectComponent, {}), enableColumnSelection && jsx(ColumnSelection, {}), enableExport && jsx(Export$1, {}), jsx(ResizeHandleView, {})]
|
|
1600
|
+
}), jsx(ColumnHeaderContext.Provider, {
|
|
1601
|
+
children: activeColumns.map((column) => {
|
|
1602
|
+
var _a2;
|
|
1603
|
+
return jsx(ColumnContext.Provider, {
|
|
1604
|
+
value: column.id,
|
|
1605
|
+
children: jsxs(ColumnHeader, {
|
|
1606
|
+
className: cx(classes == null ? void 0 : classes.headerCell, (_a2 = column.classes) == null ? void 0 : _a2.headerCell),
|
|
1607
|
+
css: [defaultClasses.headerCell, columnStyleOverride.get(column.id), stickyHeader && defaultClasses.sticky, stickyHeader instanceof Object && stickyHeader],
|
|
1608
|
+
children: [jsx(SortComponent, {
|
|
1609
|
+
children: column.header
|
|
1610
|
+
}), jsx("div", {
|
|
1611
|
+
css: {
|
|
1612
|
+
flex: 1
|
|
1613
|
+
}
|
|
1614
|
+
}), jsx(FilterControl, {}), jsx(ResizeHandle, {})]
|
|
1615
|
+
}, column.id)
|
|
1616
|
+
}, column.id);
|
|
1617
|
+
})
|
|
1618
|
+
}), jsx("div", {
|
|
1619
|
+
className: classes == null ? void 0 : classes.headerCell,
|
|
1620
|
+
css: [defaultClasses.headerFill, stickyHeader && defaultClasses.sticky, stickyHeader instanceof Object && stickyHeader]
|
|
1621
|
+
})]
|
|
1622
|
+
}),
|
|
1623
|
+
children: (itemIds, startIndex) => itemIds.map((itemId, index) => jsx(Row, {
|
|
1624
|
+
itemId,
|
|
1625
|
+
rowIndex: startIndex + index
|
|
1626
|
+
}, itemId))
|
|
1512
1627
|
});
|
|
1513
1628
|
});
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1629
|
+
const defaultColors = {
|
|
1630
|
+
primary: { main: "#1976d2", light: "#42a5f5", contrastText: "#fff" },
|
|
1631
|
+
secondary: { main: "#9c27b0", light: "#ba68c8", contrastText: "#fff" }
|
|
1632
|
+
};
|
|
1633
|
+
function Spinner({
|
|
1634
|
+
className: className2
|
|
1517
1635
|
}) {
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1636
|
+
return jsxs("div", {
|
|
1637
|
+
className: className2,
|
|
1638
|
+
css: css`
|
|
1639
|
+
display: inline-block;
|
|
1640
|
+
position: relative;
|
|
1641
|
+
width: 1em;
|
|
1642
|
+
height: 1em;
|
|
1643
|
+
|
|
1644
|
+
div {
|
|
1645
|
+
box-sizing: border-box;
|
|
1646
|
+
display: block;
|
|
1647
|
+
position: absolute;
|
|
1648
|
+
width: 0.8em;
|
|
1649
|
+
height: 0.8em;
|
|
1650
|
+
margin: 0.1em;
|
|
1651
|
+
border: 0.1em solid #fff;
|
|
1652
|
+
border-radius: 50%;
|
|
1653
|
+
animation: lds-ring 1.2s cubic-bezier(0.5, 0, 0.5, 1) infinite;
|
|
1654
|
+
border-color: currentColor transparent transparent transparent;
|
|
1655
|
+
}
|
|
1656
|
+
div:nth-of-type(1) {
|
|
1657
|
+
animation-delay: -0.45s;
|
|
1658
|
+
}
|
|
1659
|
+
div:nth-of-type(2) {
|
|
1660
|
+
animation-delay: -0.3s;
|
|
1661
|
+
}
|
|
1662
|
+
div:nth-of-type(3) {
|
|
1663
|
+
animation-delay: -0.15s;
|
|
1664
|
+
}
|
|
1665
|
+
@keyframes lds-ring {
|
|
1666
|
+
0% {
|
|
1667
|
+
transform: rotate(0deg);
|
|
1668
|
+
}
|
|
1669
|
+
100% {
|
|
1670
|
+
transform: rotate(360deg);
|
|
1671
|
+
}
|
|
1672
|
+
}
|
|
1673
|
+
`,
|
|
1674
|
+
children: [jsx("div", {}), jsx("div", {}), jsx("div", {})]
|
|
1675
|
+
});
|
|
1676
|
+
}
|
|
1677
|
+
const Badge = ({
|
|
1678
|
+
badgeContent,
|
|
1679
|
+
children
|
|
1680
|
+
}) => {
|
|
1681
|
+
if (!open)
|
|
1682
|
+
return null;
|
|
1683
|
+
return jsxs("span", {
|
|
1684
|
+
css: {
|
|
1685
|
+
display: "inline-flex",
|
|
1686
|
+
position: "relative",
|
|
1687
|
+
flexShrink: 0,
|
|
1688
|
+
verticalAlign: "middle"
|
|
1522
1689
|
},
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1690
|
+
children: [children, jsx("span", {
|
|
1691
|
+
css: [{
|
|
1692
|
+
top: 0,
|
|
1693
|
+
right: 0,
|
|
1694
|
+
transform: "scale(1) translate(50%, -50%)",
|
|
1695
|
+
transformOrigin: "100% 0%",
|
|
1696
|
+
height: 20,
|
|
1697
|
+
display: "flex",
|
|
1698
|
+
padding: "0 6px",
|
|
1699
|
+
zIndex: 1,
|
|
1700
|
+
position: "absolute",
|
|
1701
|
+
flexWrap: "wrap",
|
|
1702
|
+
minWidth: 20,
|
|
1703
|
+
transition: "transform 225ms cubic-bezier(0.4, 0, 0.2, 1) 0ms",
|
|
1704
|
+
alignItems: "center",
|
|
1705
|
+
lineHeight: 1,
|
|
1706
|
+
alignContent: "center",
|
|
1707
|
+
borderRadius: 10,
|
|
1708
|
+
justifyContent: "center",
|
|
1709
|
+
fontSize: "0.8em"
|
|
1710
|
+
}, !badgeContent && {
|
|
1711
|
+
transform: "scale(0) translate(50%, -50%)",
|
|
1712
|
+
transition: "transform 195ms cubic-bezier(0.4, 0, 0.2, 1) 0ms"
|
|
1713
|
+
}],
|
|
1714
|
+
children: badgeContent
|
|
1715
|
+
})]
|
|
1532
1716
|
});
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1717
|
+
};
|
|
1718
|
+
const Button = (_e) => {
|
|
1719
|
+
var _f = _e, {
|
|
1720
|
+
startIcon,
|
|
1721
|
+
children,
|
|
1722
|
+
variant = "text"
|
|
1723
|
+
} = _f, props = __objRest(_f, [
|
|
1724
|
+
"startIcon",
|
|
1725
|
+
"children",
|
|
1726
|
+
"variant"
|
|
1727
|
+
]);
|
|
1728
|
+
return jsxs("button", __spreadProps(__spreadValues({
|
|
1729
|
+
css: [{
|
|
1730
|
+
padding: `var(--spacing) calc(var(--spacing) * 2)`,
|
|
1731
|
+
display: "inline-flex",
|
|
1732
|
+
alignItems: "center",
|
|
1733
|
+
transition: "background-color 150ms",
|
|
1734
|
+
border: "none",
|
|
1735
|
+
cursor: "pointer",
|
|
1736
|
+
background: "transparent",
|
|
1737
|
+
borderRadius: 4,
|
|
1738
|
+
"&:active:not(:disabled)": {
|
|
1739
|
+
transform: "scale3d(0.95, 0.95, 1)"
|
|
1553
1740
|
}
|
|
1554
|
-
}
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
}
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1741
|
+
}, variant === "text" && {
|
|
1742
|
+
"&:hover": {
|
|
1743
|
+
background: "rgba(0, 0, 0, 0.1)"
|
|
1744
|
+
}
|
|
1745
|
+
}, variant === "outlined" && {
|
|
1746
|
+
border: `1px solid ${darkGray}`,
|
|
1747
|
+
"&:disabled": {
|
|
1748
|
+
borderColor: lightGray
|
|
1749
|
+
}
|
|
1750
|
+
}, variant === "contained" && {
|
|
1751
|
+
color: "var(--primaryContrastText)",
|
|
1752
|
+
backgroundColor: "var(--primaryMain)",
|
|
1753
|
+
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%)",
|
|
1754
|
+
"&:hover": {
|
|
1755
|
+
filter: "brightness(0.9)"
|
|
1756
|
+
},
|
|
1757
|
+
"&:disabled": {
|
|
1758
|
+
filter: "grayscale()",
|
|
1759
|
+
opacity: 0.5
|
|
1760
|
+
}
|
|
1761
|
+
}]
|
|
1762
|
+
}, props), {
|
|
1763
|
+
children: [startIcon && jsx("span", {
|
|
1564
1764
|
css: {
|
|
1565
|
-
|
|
1765
|
+
marginRight: `calc(var(--spacing) * 2)`
|
|
1766
|
+
},
|
|
1767
|
+
children: startIcon
|
|
1768
|
+
}), jsx("span", {
|
|
1769
|
+
children
|
|
1770
|
+
})]
|
|
1771
|
+
}));
|
|
1772
|
+
};
|
|
1773
|
+
const Checkbox = (_g) => {
|
|
1774
|
+
var _h = _g, {
|
|
1775
|
+
className: className2
|
|
1776
|
+
} = _h, props = __objRest(_h, [
|
|
1777
|
+
"className"
|
|
1778
|
+
]);
|
|
1779
|
+
return jsxs("label", {
|
|
1780
|
+
css: [{
|
|
1781
|
+
padding: "calc(var(--spacing) * 1.8)",
|
|
1782
|
+
display: "flex",
|
|
1783
|
+
color: "currentcolor",
|
|
1784
|
+
userSelect: "none",
|
|
1785
|
+
"& input": {
|
|
1786
|
+
appearance: "none",
|
|
1787
|
+
margin: 0
|
|
1566
1788
|
}
|
|
1567
|
-
}
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
children: jsx("
|
|
1789
|
+
}, props.disabled && {
|
|
1790
|
+
color: "rgba(0, 0, 0, 0.26)"
|
|
1791
|
+
}],
|
|
1792
|
+
className: className2,
|
|
1793
|
+
children: [jsx("input", __spreadValues({
|
|
1794
|
+
type: "checkbox"
|
|
1795
|
+
}, props)), props.checked ? jsx("svg", {
|
|
1572
1796
|
css: {
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1797
|
+
fontSize: "1.25rem",
|
|
1798
|
+
width: "1em",
|
|
1799
|
+
height: "1em",
|
|
1800
|
+
fill: "var(--primaryMain)"
|
|
1801
|
+
},
|
|
1802
|
+
focusable: "false",
|
|
1803
|
+
viewBox: "0 0 24 24",
|
|
1804
|
+
"aria-hidden": "true",
|
|
1805
|
+
children: jsx("path", {
|
|
1806
|
+
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"
|
|
1807
|
+
})
|
|
1808
|
+
}) : jsx("svg", {
|
|
1809
|
+
css: {
|
|
1810
|
+
fontSize: "1.25rem",
|
|
1811
|
+
width: "1em",
|
|
1812
|
+
height: "1em",
|
|
1813
|
+
fill: "currentColor"
|
|
1814
|
+
},
|
|
1815
|
+
focusable: "false",
|
|
1816
|
+
viewBox: "0 0 24 24",
|
|
1817
|
+
"aria-hidden": "true",
|
|
1818
|
+
children: jsx("path", {
|
|
1819
|
+
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"
|
|
1820
|
+
})
|
|
1821
|
+
})]
|
|
1822
|
+
});
|
|
1823
|
+
};
|
|
1824
|
+
const IconButton = (props) => {
|
|
1825
|
+
return jsx("button", __spreadValues({
|
|
1826
|
+
css: {
|
|
1827
|
+
padding: "var(--spacing)",
|
|
1828
|
+
borderRadius: "50%",
|
|
1829
|
+
display: "inline-flex",
|
|
1830
|
+
justifyContent: "center",
|
|
1831
|
+
alignItems: "center",
|
|
1832
|
+
transition: "background-color 150ms",
|
|
1833
|
+
border: "none",
|
|
1834
|
+
cursor: "pointer",
|
|
1835
|
+
color: "inherit",
|
|
1836
|
+
background: "transparent",
|
|
1837
|
+
"&:hover": {
|
|
1838
|
+
backgroundColor: "rgba(0, 0, 0, 0.04)"
|
|
1576
1839
|
},
|
|
1577
|
-
|
|
1840
|
+
"&:active": {
|
|
1841
|
+
transformColor: "scale3d(0.95, 0.95, 1)"
|
|
1842
|
+
}
|
|
1843
|
+
}
|
|
1844
|
+
}, props));
|
|
1845
|
+
};
|
|
1846
|
+
const TextField = (_i) => {
|
|
1847
|
+
var _j = _i, {
|
|
1848
|
+
endIcon,
|
|
1849
|
+
className: className2,
|
|
1850
|
+
inputRef
|
|
1851
|
+
} = _j, props = __objRest(_j, [
|
|
1852
|
+
"endIcon",
|
|
1853
|
+
"className",
|
|
1854
|
+
"inputRef"
|
|
1855
|
+
]);
|
|
1856
|
+
var _a;
|
|
1857
|
+
const [focus, setFocus] = useState(false);
|
|
1858
|
+
return jsx("div", {
|
|
1859
|
+
className: className2,
|
|
1860
|
+
css: {
|
|
1861
|
+
display: "flex"
|
|
1862
|
+
},
|
|
1863
|
+
children: jsxs("span", {
|
|
1864
|
+
css: [{
|
|
1865
|
+
flex: 1,
|
|
1866
|
+
display: "flex",
|
|
1867
|
+
alignItems: "center",
|
|
1868
|
+
border: `1px solid ${darkGray}`,
|
|
1869
|
+
borderRadius: 4
|
|
1870
|
+
}, focus && {
|
|
1871
|
+
border: "2px solid var(--primaryMain)",
|
|
1872
|
+
margin: -1
|
|
1873
|
+
}],
|
|
1874
|
+
children: [jsx("input", __spreadProps(__spreadValues({
|
|
1875
|
+
ref: inputRef
|
|
1876
|
+
}, props), {
|
|
1877
|
+
value: (_a = props.value) != null ? _a : "",
|
|
1878
|
+
onFocus: () => setFocus(true),
|
|
1879
|
+
onBlur: () => setFocus(false),
|
|
1880
|
+
css: {
|
|
1881
|
+
flex: 1,
|
|
1882
|
+
border: "none",
|
|
1883
|
+
outline: "none",
|
|
1884
|
+
borderRadius: 4,
|
|
1885
|
+
padding: "calc(var(--spacing) * 2)",
|
|
1886
|
+
paddingRight: 0,
|
|
1887
|
+
transition: "outline 500ms"
|
|
1888
|
+
}
|
|
1889
|
+
})), endIcon]
|
|
1578
1890
|
})
|
|
1579
1891
|
});
|
|
1892
|
+
};
|
|
1893
|
+
const defaultComponents = {
|
|
1894
|
+
IconButton,
|
|
1895
|
+
Checkbox,
|
|
1896
|
+
Popover,
|
|
1897
|
+
Button,
|
|
1898
|
+
Badge,
|
|
1899
|
+
TextField,
|
|
1900
|
+
Spinner
|
|
1901
|
+
};
|
|
1902
|
+
const IconDefaultStyle = css({
|
|
1903
|
+
width: "1.5em",
|
|
1904
|
+
height: "1.5em",
|
|
1905
|
+
color: "inherit"
|
|
1906
|
+
});
|
|
1907
|
+
function Icon(svg) {
|
|
1908
|
+
return (props) => jsx(ClassNames, {
|
|
1909
|
+
children: ({
|
|
1910
|
+
css: css2
|
|
1911
|
+
}) => cloneElement(svg, __spreadProps(__spreadValues({}, props), {
|
|
1912
|
+
className: css2(IconDefaultStyle, props.className)
|
|
1913
|
+
}))
|
|
1914
|
+
});
|
|
1580
1915
|
}
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1916
|
+
const Settings = Icon(jsxs("svg", {
|
|
1917
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
1918
|
+
height: "24px",
|
|
1919
|
+
viewBox: "0 0 24 24",
|
|
1920
|
+
width: "24px",
|
|
1921
|
+
fill: "currentColor",
|
|
1922
|
+
children: [jsx("path", {
|
|
1923
|
+
d: "M0 0h24v24H0V0z",
|
|
1924
|
+
fill: "none"
|
|
1925
|
+
}), jsx("path", {
|
|
1926
|
+
d: "M3 17v2h6v-2H3zM3 5v2h10V5H3zm10 16v-2h8v-2h-8v-2h-2v6h2zM7 9v2H3v2h4v2h2V9H7zm14 4v-2H11v2h10zm-6-4h2V7h4V5h-4V3h-2v6z"
|
|
1927
|
+
})]
|
|
1928
|
+
}));
|
|
1929
|
+
const Export = Icon(jsxs("svg", {
|
|
1930
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
1931
|
+
enableBackground: "new 0 0 24 24",
|
|
1932
|
+
height: "24px",
|
|
1933
|
+
viewBox: "0 0 24 24",
|
|
1934
|
+
width: "24px",
|
|
1935
|
+
fill: "currentColor",
|
|
1936
|
+
children: [jsx("g", {
|
|
1937
|
+
children: jsx("rect", {
|
|
1938
|
+
fill: "none",
|
|
1939
|
+
height: "24",
|
|
1940
|
+
width: "24"
|
|
1941
|
+
})
|
|
1942
|
+
}), jsx("g", {
|
|
1943
|
+
children: jsx("path", {
|
|
1944
|
+
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"
|
|
1945
|
+
})
|
|
1946
|
+
})]
|
|
1947
|
+
}));
|
|
1948
|
+
const Clipboard = Icon(jsxs("svg", {
|
|
1949
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
1950
|
+
height: "24px",
|
|
1951
|
+
viewBox: "0 0 24 24",
|
|
1952
|
+
width: "24px",
|
|
1953
|
+
fill: "currentColor",
|
|
1954
|
+
children: [jsx("path", {
|
|
1955
|
+
d: "M0 0h24v24H0V0z",
|
|
1956
|
+
fill: "none"
|
|
1957
|
+
}), jsx("path", {
|
|
1958
|
+
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"
|
|
1959
|
+
})]
|
|
1960
|
+
}));
|
|
1961
|
+
const ChevronRight = Icon(jsxs("svg", {
|
|
1962
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
1963
|
+
height: "24px",
|
|
1964
|
+
viewBox: "0 0 24 24",
|
|
1965
|
+
width: "24px",
|
|
1966
|
+
fill: "currentColor",
|
|
1967
|
+
children: [jsx("path", {
|
|
1968
|
+
d: "M0 0h24v24H0V0z",
|
|
1969
|
+
fill: "none"
|
|
1970
|
+
}), jsx("path", {
|
|
1971
|
+
d: "M10 6L8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6-6-6z"
|
|
1972
|
+
})]
|
|
1973
|
+
}));
|
|
1974
|
+
const Search = Icon(jsxs("svg", {
|
|
1975
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
1976
|
+
height: "24px",
|
|
1977
|
+
viewBox: "0 0 24 24",
|
|
1978
|
+
width: "24px",
|
|
1979
|
+
fill: "currentColor",
|
|
1980
|
+
children: [jsx("path", {
|
|
1981
|
+
d: "M0 0h24v24H0V0z",
|
|
1982
|
+
fill: "none"
|
|
1983
|
+
}), jsx("path", {
|
|
1984
|
+
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"
|
|
1985
|
+
})]
|
|
1986
|
+
}));
|
|
1987
|
+
const Clear = Icon(jsxs("svg", {
|
|
1988
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
1989
|
+
height: "24px",
|
|
1990
|
+
viewBox: "0 0 24 24",
|
|
1991
|
+
width: "24px",
|
|
1992
|
+
fill: "currentColor",
|
|
1993
|
+
children: [jsx("path", {
|
|
1994
|
+
d: "M0 0h24v24H0V0z",
|
|
1995
|
+
fill: "none"
|
|
1996
|
+
}), jsx("path", {
|
|
1997
|
+
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"
|
|
1998
|
+
})]
|
|
1999
|
+
}));
|
|
2000
|
+
const ArrowDropDown = Icon(jsxs("svg", {
|
|
2001
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
2002
|
+
height: "24px",
|
|
2003
|
+
viewBox: "0 0 24 24",
|
|
2004
|
+
width: "24px",
|
|
2005
|
+
fill: "currentColor",
|
|
2006
|
+
children: [jsx("path", {
|
|
2007
|
+
d: "M0 0h24v24H0V0z",
|
|
2008
|
+
fill: "none"
|
|
2009
|
+
}), jsx("path", {
|
|
2010
|
+
d: "M7 10l5 5 5-5H7z"
|
|
2011
|
+
})]
|
|
2012
|
+
}));
|
|
2013
|
+
const FilterList = Icon(jsx("svg", {
|
|
2014
|
+
viewBox: "0 0 24 24",
|
|
2015
|
+
children: jsx("path", {
|
|
2016
|
+
fill: "currentColor",
|
|
2017
|
+
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"
|
|
2018
|
+
})
|
|
2019
|
+
}));
|
|
2020
|
+
const ArrowUpward = Icon(jsxs("svg", {
|
|
2021
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
2022
|
+
height: "24px",
|
|
2023
|
+
viewBox: "0 0 24 24",
|
|
2024
|
+
width: "24px",
|
|
2025
|
+
fill: "currentColor",
|
|
2026
|
+
children: [jsx("path", {
|
|
2027
|
+
d: "M0 0h24v24H0V0z",
|
|
2028
|
+
fill: "none"
|
|
2029
|
+
}), jsx("path", {
|
|
2030
|
+
d: "M4 12l1.41 1.41L11 7.83V20h2V7.83l5.58 5.59L20 12l-8-8-8 8z"
|
|
2031
|
+
})]
|
|
2032
|
+
}));
|
|
2033
|
+
const defaultIcons = {
|
|
2034
|
+
Settings,
|
|
2035
|
+
Export,
|
|
2036
|
+
Clipboard,
|
|
2037
|
+
ChevronRight,
|
|
2038
|
+
Search,
|
|
2039
|
+
Clear,
|
|
2040
|
+
ArrowDropDown,
|
|
2041
|
+
FilterList,
|
|
2042
|
+
ArrowUpward
|
|
2043
|
+
};
|
|
2044
|
+
const defaultTexts = {
|
|
2045
|
+
selectColumns: "Select visible columns",
|
|
2046
|
+
noResults: "No results",
|
|
2047
|
+
exportTitle: "Export",
|
|
2048
|
+
exportCopy: "To clipboard",
|
|
2049
|
+
exportDownload: "Download",
|
|
2050
|
+
today: "Today",
|
|
2051
|
+
thisWeek: "This week",
|
|
2052
|
+
reset: "Reset",
|
|
2053
|
+
loading: "Loading",
|
|
2054
|
+
selected: (count) => `${count} selected`
|
|
2055
|
+
};
|
|
2056
|
+
const defaultTableTheme = {
|
|
2057
|
+
text: defaultTexts,
|
|
2058
|
+
components: defaultComponents,
|
|
2059
|
+
icons: defaultIcons,
|
|
2060
|
+
colors: defaultColors,
|
|
2061
|
+
spacing: "5px"
|
|
2062
|
+
};
|
|
2063
|
+
const emptyStore = new Store(void 0);
|
|
2064
|
+
function useTheme() {
|
|
2065
|
+
var _a, _b;
|
|
2066
|
+
const table = useContext(TableContext);
|
|
2067
|
+
const localTheme = (_b = (_a = table == null ? void 0 : table.useState((state) => ({
|
|
2068
|
+
text: state.props.text,
|
|
2069
|
+
classes: state.props.classes,
|
|
2070
|
+
components: state.props.components,
|
|
2071
|
+
icons: state.props.icons,
|
|
2072
|
+
colors: state.props.colors,
|
|
2073
|
+
spacing: state.props.spacing
|
|
2074
|
+
}))) != null ? _a : emptyStore.useState()) != null ? _b : {};
|
|
2075
|
+
const contextTableTheme = useContext(TableThemeContext);
|
|
2076
|
+
return mergeThemes(defaultTableTheme, globalTableTheme, contextTableTheme, localTheme);
|
|
2077
|
+
}
|
|
2078
|
+
function AutoFocusTextField(props) {
|
|
1585
2079
|
const {
|
|
1586
2080
|
components: {
|
|
1587
|
-
|
|
2081
|
+
TextField: TextField2
|
|
1588
2082
|
}
|
|
1589
2083
|
} = useTheme();
|
|
1590
|
-
const
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
});
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
activeItems,
|
|
1598
|
-
activeItemsById,
|
|
1599
|
-
lastSelectedId,
|
|
1600
|
-
selection,
|
|
1601
|
-
props: {
|
|
1602
|
-
selectSyncChildren,
|
|
1603
|
-
selection: controlledSelection,
|
|
1604
|
-
onSelectionChange
|
|
1605
|
-
}
|
|
1606
|
-
} = table.getState();
|
|
1607
|
-
let range;
|
|
1608
|
-
if (mouseEvent.shiftKey && itemId) {
|
|
1609
|
-
const a2 = lastSelectedId ? activeItems.findIndex((i) => lastSelectedId === i.id) : 0;
|
|
1610
|
-
const b = activeItems.findIndex((item) => item.id === itemId);
|
|
1611
|
-
range = activeItems.slice(Math.min(a2, b), Math.max(a2, b) + 1);
|
|
1612
|
-
} else {
|
|
1613
|
-
const item = itemId ? activeItemsById.get(itemId) : void 0;
|
|
1614
|
-
range = item ? [item] : activeItems;
|
|
2084
|
+
const ref = useRef(null);
|
|
2085
|
+
const {
|
|
2086
|
+
visible
|
|
2087
|
+
} = useContext(PopoverContext);
|
|
2088
|
+
useLayoutEffect(() => {
|
|
2089
|
+
if (visible && ref.current) {
|
|
2090
|
+
ref.current.focus();
|
|
1615
2091
|
}
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
2092
|
+
}, [visible]);
|
|
2093
|
+
return jsx(TextField2, __spreadProps(__spreadValues({}, props), {
|
|
2094
|
+
inputRef: ref
|
|
2095
|
+
}));
|
|
2096
|
+
}
|
|
2097
|
+
const className = "schummar-table-date-input";
|
|
2098
|
+
const defaultDate = new Date(1970, 0, 1);
|
|
2099
|
+
const isIncludedType = (type) => type === "day" || type === "month" || type === "year";
|
|
2100
|
+
const defaultLengths = {
|
|
2101
|
+
day: 2,
|
|
2102
|
+
month: 2,
|
|
2103
|
+
year: 4
|
|
2104
|
+
};
|
|
2105
|
+
const maxLengths = {
|
|
2106
|
+
day: 2,
|
|
2107
|
+
month: 2,
|
|
2108
|
+
year: Infinity
|
|
2109
|
+
};
|
|
2110
|
+
const length = (type, value) => Math.max(value.length, defaultLengths[type]);
|
|
2111
|
+
const tabNext = (e2) => {
|
|
2112
|
+
const all = Array.from(document.querySelectorAll(`.${className}`));
|
|
2113
|
+
const index = all.indexOf(e2);
|
|
2114
|
+
const next = all[(index + 1) % all.length];
|
|
2115
|
+
if (next instanceof HTMLElement) {
|
|
2116
|
+
next.focus();
|
|
2117
|
+
}
|
|
2118
|
+
};
|
|
2119
|
+
function DateInput({
|
|
2120
|
+
value,
|
|
2121
|
+
onChange,
|
|
2122
|
+
locale
|
|
2123
|
+
}) {
|
|
2124
|
+
const [override, setOverride] = useState();
|
|
2125
|
+
const commit = () => {
|
|
2126
|
+
if (!override) {
|
|
2127
|
+
return;
|
|
1622
2128
|
}
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
for (const descendant of getDescendants(...range)) {
|
|
1628
|
-
newSelection.delete(descendant);
|
|
1629
|
-
}
|
|
2129
|
+
setOverride(void 0);
|
|
2130
|
+
if (!override.value) {
|
|
2131
|
+
onChange(null);
|
|
2132
|
+
return;
|
|
1630
2133
|
}
|
|
1631
|
-
|
|
1632
|
-
if (
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
2134
|
+
const newValue = value ? new Date(value) : new Date();
|
|
2135
|
+
if (override.type === "day") {
|
|
2136
|
+
newValue.setDate(Number(override.value));
|
|
2137
|
+
} else if (override.type === "month") {
|
|
2138
|
+
newValue.setMonth(Number(override.value) - 1);
|
|
2139
|
+
} else if (override.type === "year") {
|
|
2140
|
+
newValue.setFullYear(Number(override.value));
|
|
1636
2141
|
}
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
2142
|
+
onChange(newValue);
|
|
2143
|
+
};
|
|
2144
|
+
const format = useMemo(() => new Intl.DateTimeFormat(locale, {
|
|
2145
|
+
day: "2-digit",
|
|
2146
|
+
month: "2-digit",
|
|
2147
|
+
year: "numeric"
|
|
2148
|
+
}), [locale]);
|
|
2149
|
+
const parts = format.formatToParts(value != null ? value : defaultDate);
|
|
2150
|
+
const isEmpty = !value;
|
|
2151
|
+
return jsx("div", {
|
|
1642
2152
|
css: {
|
|
1643
|
-
|
|
1644
|
-
|
|
2153
|
+
display: "flex",
|
|
2154
|
+
alignItems: "baseline"
|
|
1645
2155
|
},
|
|
1646
|
-
|
|
1647
|
-
|
|
2156
|
+
children: parts.map(({
|
|
2157
|
+
type,
|
|
2158
|
+
value: value2
|
|
2159
|
+
}, index) => jsx(Fragment$1, {
|
|
2160
|
+
children: isIncludedType(type) ? jsx("input", {
|
|
2161
|
+
className,
|
|
2162
|
+
css: {
|
|
2163
|
+
width: `${length(type, value2)}ch`,
|
|
2164
|
+
boxSizing: "content-box",
|
|
2165
|
+
overflow: "visible",
|
|
2166
|
+
border: "none",
|
|
2167
|
+
borderBottom: "2px solid transparent",
|
|
2168
|
+
outline: "none",
|
|
2169
|
+
fontSize: "inherit",
|
|
2170
|
+
"&:focus": {
|
|
2171
|
+
borderBottom: "2px solid var(--primaryMain)"
|
|
2172
|
+
}
|
|
2173
|
+
},
|
|
2174
|
+
placeholder: "".padEnd(length(type, value2), "0"),
|
|
2175
|
+
value: (override == null ? void 0 : override.type) === type ? override.value : !isEmpty ? value2 : "",
|
|
2176
|
+
onChange: (e2) => {
|
|
2177
|
+
setOverride({
|
|
2178
|
+
type,
|
|
2179
|
+
value: e2.target.value
|
|
2180
|
+
});
|
|
2181
|
+
if (e2.target.value.length >= maxLengths[type]) {
|
|
2182
|
+
setTimeout(() => tabNext(e2.target));
|
|
2183
|
+
}
|
|
2184
|
+
},
|
|
2185
|
+
onFocus: (e2) => e2.target.select(),
|
|
2186
|
+
onBlur: commit
|
|
2187
|
+
}) : type === "literal" ? jsx("span", {
|
|
2188
|
+
children: value2
|
|
2189
|
+
}) : null
|
|
2190
|
+
}, index))
|
|
1648
2191
|
});
|
|
1649
2192
|
}
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
const
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
2193
|
+
const weekDays = [0, 1, 2, 3, 4, 5, 6];
|
|
2194
|
+
const startOfDay = (d) => new Date(d.getFullYear(), d.getMonth(), d.getDate());
|
|
2195
|
+
const endOfDay = (d) => new Date(d.getFullYear(), d.getMonth(), d.getDate() + 1, 0, 0, 0, -1);
|
|
2196
|
+
const today = () => {
|
|
2197
|
+
const today2 = startOfDay(new Date());
|
|
2198
|
+
return {
|
|
2199
|
+
min: today2,
|
|
2200
|
+
max: today2
|
|
2201
|
+
};
|
|
2202
|
+
};
|
|
2203
|
+
const thisWeek = (firstDayOfWeek = 0) => {
|
|
2204
|
+
const now = new Date();
|
|
2205
|
+
const min = new Date(now);
|
|
2206
|
+
let diff = min.getDay() - firstDayOfWeek;
|
|
2207
|
+
if (diff < 0) {
|
|
2208
|
+
diff += 7;
|
|
2209
|
+
}
|
|
2210
|
+
min.setDate(min.getDate() - diff);
|
|
2211
|
+
const max = new Date(min);
|
|
2212
|
+
max.setDate(max.getDate() + 6);
|
|
2213
|
+
return {
|
|
2214
|
+
min: startOfDay(min),
|
|
2215
|
+
max: endOfDay(max)
|
|
2216
|
+
};
|
|
2217
|
+
};
|
|
2218
|
+
function dateIntersect(a, b) {
|
|
2219
|
+
if (a instanceof Date) {
|
|
2220
|
+
a = {
|
|
2221
|
+
min: a,
|
|
2222
|
+
max: a
|
|
1680
2223
|
};
|
|
1681
|
-
}
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
className,
|
|
1700
|
-
css: [defaultClasses.cellFill],
|
|
1701
|
-
ref: divRef
|
|
1702
|
-
}), jsxs("div", {
|
|
1703
|
-
className,
|
|
1704
|
-
css: [defaultClasses.cell, defaultClasses.firstCell],
|
|
1705
|
-
children: [jsx("div", {
|
|
1706
|
-
css: {
|
|
1707
|
-
width: indent * 20
|
|
1708
|
-
}
|
|
1709
|
-
}), enableSelection && jsx(SelectComponent, {
|
|
1710
|
-
itemId
|
|
1711
|
-
}), (hasChildren || hasDeferredChildren) && jsx(ExpandControl, {
|
|
1712
|
-
itemId,
|
|
1713
|
-
hasDeferredChildren
|
|
1714
|
-
}), rowAction]
|
|
1715
|
-
}), columnIds.map((columnId) => jsx(ColumnContext.Provider, {
|
|
1716
|
-
value: columnId,
|
|
1717
|
-
children: jsx(Cell, {
|
|
1718
|
-
itemId,
|
|
1719
|
-
rowIndex
|
|
1720
|
-
})
|
|
1721
|
-
}, columnId)), jsx("div", {
|
|
1722
|
-
className,
|
|
1723
|
-
css: [defaultClasses.cellFill]
|
|
1724
|
-
})]
|
|
1725
|
-
});
|
|
1726
|
-
});
|
|
1727
|
-
function SortComponent({
|
|
1728
|
-
children
|
|
2224
|
+
}
|
|
2225
|
+
if (b instanceof Date) {
|
|
2226
|
+
b = {
|
|
2227
|
+
min: b,
|
|
2228
|
+
max: b
|
|
2229
|
+
};
|
|
2230
|
+
}
|
|
2231
|
+
if (!(a == null ? void 0 : a.min) || !a.max || !(b == null ? void 0 : b.min) || !b.max) {
|
|
2232
|
+
return false;
|
|
2233
|
+
}
|
|
2234
|
+
return !(endOfDay(a.max) < startOfDay(b.min) || startOfDay(a.min) > endOfDay(b.max));
|
|
2235
|
+
}
|
|
2236
|
+
function DatePicker({
|
|
2237
|
+
value,
|
|
2238
|
+
onChange,
|
|
2239
|
+
rangeSelect,
|
|
2240
|
+
locale,
|
|
2241
|
+
firstDayOfWeek = 0
|
|
1729
2242
|
}) {
|
|
1730
|
-
const table = useTableContext();
|
|
1731
|
-
const columnId = useColumnContext();
|
|
1732
2243
|
const {
|
|
1733
2244
|
components: {
|
|
1734
|
-
|
|
2245
|
+
Button: Button2,
|
|
2246
|
+
IconButton: IconButton2
|
|
1735
2247
|
},
|
|
1736
2248
|
icons: {
|
|
1737
|
-
|
|
1738
|
-
}
|
|
2249
|
+
ChevronRight: ChevronRight2
|
|
2250
|
+
},
|
|
2251
|
+
text
|
|
1739
2252
|
} = useTheme();
|
|
2253
|
+
const [baseDate] = useState(new Date());
|
|
2254
|
+
const [dateInView, setDateInView] = useState(baseDate);
|
|
2255
|
+
const [dirty, setDirty] = useState();
|
|
2256
|
+
const [hovered, setHovered] = useState();
|
|
2257
|
+
const min = dirty ? dirty.min : value instanceof Date ? value : value == null ? void 0 : value.min;
|
|
2258
|
+
const max = dirty ? dirty.max : value instanceof Date ? value : value == null ? void 0 : value.max;
|
|
1740
2259
|
const {
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
2260
|
+
calendars,
|
|
2261
|
+
getBackProps,
|
|
2262
|
+
getForwardProps,
|
|
2263
|
+
getDateProps
|
|
2264
|
+
} = useDayzed({
|
|
2265
|
+
onDateSelected: () => void 0,
|
|
2266
|
+
firstDayOfWeek,
|
|
2267
|
+
showOutsideDays: true,
|
|
2268
|
+
date: dateInView,
|
|
2269
|
+
onOffsetChanged: (offset) => setDateInView(new Date(dateInView.getFullYear(), dateInView.getMonth() + offset)),
|
|
2270
|
+
offset: 0
|
|
1750
2271
|
});
|
|
1751
|
-
|
|
2272
|
+
const formatWeekday = useMemo(() => {
|
|
1752
2273
|
const {
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
direction: newDirection
|
|
1764
|
-
});
|
|
2274
|
+
format
|
|
2275
|
+
} = new Intl.DateTimeFormat(locale, {
|
|
2276
|
+
weekday: "short"
|
|
2277
|
+
});
|
|
2278
|
+
return (weekDay) => format(new Date(Date.UTC(2021, 5, weekDay)));
|
|
2279
|
+
}, [locale]);
|
|
2280
|
+
useEffect(() => setDateInView(value === null ? new Date() : value instanceof Date ? value : value.max), [value]);
|
|
2281
|
+
useEffect(() => {
|
|
2282
|
+
if (!rangeSelect) {
|
|
2283
|
+
setDirty(void 0);
|
|
1765
2284
|
}
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
2285
|
+
}, [rangeSelect]);
|
|
2286
|
+
function set(min2, max2, edit) {
|
|
2287
|
+
if (!rangeSelect) {
|
|
2288
|
+
onChange(min2 != null ? min2 : null);
|
|
2289
|
+
return;
|
|
1771
2290
|
}
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
gridTemplateColumns: "minmax(0, 1fr) max-content",
|
|
1780
|
-
alignItems: "center",
|
|
1781
|
-
cursor: "pointer",
|
|
1782
|
-
"& > div": {
|
|
1783
|
-
overflow: "hidden",
|
|
1784
|
-
textOverflow: "ellipsis"
|
|
2291
|
+
if (min2 && max2 && min2 > max2) {
|
|
2292
|
+
if (edit === "min") {
|
|
2293
|
+
max2 = min2;
|
|
2294
|
+
} else if (edit === "max") {
|
|
2295
|
+
min2 = max2;
|
|
2296
|
+
} else {
|
|
2297
|
+
[min2, max2] = [max2, min2];
|
|
1785
2298
|
}
|
|
1786
|
-
},
|
|
1787
|
-
onClick: (e) => toggle2(e),
|
|
1788
|
-
onContextMenu: (e) => toggle2(e, true),
|
|
1789
|
-
children: [jsx("div", {
|
|
1790
|
-
children
|
|
1791
|
-
}), jsx(Badge, {
|
|
1792
|
-
badgeContent: index,
|
|
1793
|
-
children: jsx("span", {
|
|
1794
|
-
css: [{
|
|
1795
|
-
transition: "all 300ms",
|
|
1796
|
-
fontSize: "0.8em"
|
|
1797
|
-
}, !direction && {
|
|
1798
|
-
opacity: 0
|
|
1799
|
-
}, direction === "desc" && {
|
|
1800
|
-
transform: "rotate3d(0, 0, 1, 180deg)"
|
|
1801
|
-
}],
|
|
1802
|
-
children: jsx(ArrowUpward, {})
|
|
1803
|
-
})
|
|
1804
|
-
})]
|
|
1805
|
-
});
|
|
1806
|
-
}
|
|
1807
|
-
function throttle(fn, ms) {
|
|
1808
|
-
let last = 0;
|
|
1809
|
-
let lastArgs;
|
|
1810
|
-
let timeout;
|
|
1811
|
-
function run() {
|
|
1812
|
-
const args = lastArgs;
|
|
1813
|
-
last = Date.now();
|
|
1814
|
-
lastArgs = void 0;
|
|
1815
|
-
timeout = void 0;
|
|
1816
|
-
fn(...args);
|
|
1817
|
-
}
|
|
1818
|
-
return Object.assign(function(...args) {
|
|
1819
|
-
const now = Date.now();
|
|
1820
|
-
lastArgs = args;
|
|
1821
|
-
if (timeout)
|
|
1822
|
-
;
|
|
1823
|
-
else if (now < last + ms) {
|
|
1824
|
-
timeout = setTimeout(run, last + ms - now);
|
|
1825
|
-
} else {
|
|
1826
|
-
run();
|
|
1827
2299
|
}
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
2300
|
+
if (!min2 === !max2) {
|
|
2301
|
+
setDirty(void 0);
|
|
2302
|
+
onChange(min2 && max2 ? {
|
|
2303
|
+
min: min2,
|
|
2304
|
+
max: max2
|
|
2305
|
+
} : null);
|
|
2306
|
+
} else {
|
|
2307
|
+
setDirty({
|
|
2308
|
+
min: min2,
|
|
2309
|
+
max: max2
|
|
2310
|
+
});
|
|
1833
2311
|
}
|
|
1834
|
-
}
|
|
1835
|
-
|
|
1836
|
-
const findScrollRoot = (x) => {
|
|
1837
|
-
const parent = x.parentElement;
|
|
1838
|
-
if (!parent)
|
|
1839
|
-
return document.documentElement;
|
|
1840
|
-
if (parent.scrollHeight > parent.clientHeight && getComputedStyle(parent).overflowY !== "visible")
|
|
1841
|
-
return parent;
|
|
1842
|
-
return findScrollRoot(parent);
|
|
1843
|
-
};
|
|
1844
|
-
const relativeOffset = (x, y) => {
|
|
1845
|
-
if (x.offsetParent === y.offsetParent || !x.offsetParent)
|
|
1846
|
-
return x.offsetTop - y.offsetTop;
|
|
1847
|
-
if (x.offsetParent instanceof HTMLElement)
|
|
1848
|
-
return relativeOffset(x.offsetParent, y) + x.offsetTop;
|
|
1849
|
-
return 0;
|
|
1850
|
-
};
|
|
1851
|
-
function Virtualized(_e) {
|
|
1852
|
-
var _f = _e, {
|
|
1853
|
-
header,
|
|
1854
|
-
children
|
|
1855
|
-
} = _f, props = __objRest(_f, [
|
|
1856
|
-
"header",
|
|
1857
|
-
"children"
|
|
1858
|
-
]);
|
|
1859
|
-
var _a, _b, _c, _d;
|
|
1860
|
-
const table = useTableContext();
|
|
1861
|
-
const virtual = table.useState("props.virtual");
|
|
1862
|
-
const probeRef = useRef(null);
|
|
1863
|
-
const [, setCounter] = useState(0);
|
|
1864
|
-
const {
|
|
1865
|
-
itemIds = [],
|
|
1866
|
-
from = 0,
|
|
1867
|
-
to,
|
|
1868
|
-
before = 0,
|
|
1869
|
-
after = 0
|
|
1870
|
-
} = table.useState((state) => {
|
|
1871
|
-
var _a2;
|
|
1872
|
-
const itemIds2 = state.activeItems.map((item) => item.id);
|
|
1873
|
-
const root = probeRef.current && findScrollRoot(probeRef.current);
|
|
1874
|
-
if (!state.props.virtual)
|
|
1875
|
-
return {
|
|
1876
|
-
itemIds: itemIds2
|
|
1877
|
-
};
|
|
1878
|
-
if (!probeRef.current || !root || !document.contains(root))
|
|
1879
|
-
return {};
|
|
2312
|
+
}
|
|
2313
|
+
const formatMonth = useMemo(() => {
|
|
1880
2314
|
const {
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
overscanTop,
|
|
1885
|
-
overscanBottom
|
|
1886
|
-
} = (_a2 = state.props.virtual instanceof Object ? state.props.virtual : void 0) != null ? _a2 : {};
|
|
1887
|
-
let totalHeight = 0;
|
|
1888
|
-
const rowHeights = itemIds2.map((itemId, index) => {
|
|
1889
|
-
var _a3, _b2;
|
|
1890
|
-
const h = (_b2 = (_a3 = rowHeight != null ? rowHeight : state.rowHeights.get(itemId)) != null ? _a3 : initalRowHeight) != null ? _b2 : index === 0 ? 100 : totalHeight / index;
|
|
1891
|
-
totalHeight += h;
|
|
1892
|
-
return h;
|
|
2315
|
+
format
|
|
2316
|
+
} = new Intl.DateTimeFormat(locale, {
|
|
2317
|
+
month: "long"
|
|
1893
2318
|
});
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
const
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
2319
|
+
return (month) => format(new Date(2021, month));
|
|
2320
|
+
}, [locale]);
|
|
2321
|
+
const formatYear = useMemo(() => {
|
|
2322
|
+
const {
|
|
2323
|
+
format
|
|
2324
|
+
} = new Intl.DateTimeFormat(locale, {
|
|
2325
|
+
year: "numeric"
|
|
2326
|
+
});
|
|
2327
|
+
return (year) => format(new Date(year, 0, 1));
|
|
2328
|
+
}, [locale]);
|
|
2329
|
+
return jsxs("div", {
|
|
2330
|
+
children: [jsxs("div", {
|
|
2331
|
+
css: {
|
|
2332
|
+
display: "grid",
|
|
2333
|
+
gridAutoFlow: "column",
|
|
2334
|
+
justifyContent: "center",
|
|
2335
|
+
alignItems: "baseline",
|
|
2336
|
+
gap: "var(--spacing)"
|
|
2337
|
+
},
|
|
2338
|
+
children: [jsx(DateInput, {
|
|
2339
|
+
value: min != null ? min : null,
|
|
2340
|
+
onChange: (date) => set(date != null ? date : void 0, max, "min"),
|
|
2341
|
+
locale
|
|
2342
|
+
}), rangeSelect && jsxs(Fragment, {
|
|
2343
|
+
children: [" - ", jsx(DateInput, {
|
|
2344
|
+
value: max != null ? max : null,
|
|
2345
|
+
onChange: (date) => set(min, date != null ? date : void 0, "max"),
|
|
2346
|
+
locale
|
|
2347
|
+
})]
|
|
2348
|
+
})]
|
|
2349
|
+
}), calendars.map(({
|
|
2350
|
+
month,
|
|
2351
|
+
year,
|
|
2352
|
+
weeks
|
|
2353
|
+
}) => jsxs("div", {
|
|
2354
|
+
css: {
|
|
2355
|
+
display: "grid"
|
|
2356
|
+
},
|
|
2357
|
+
children: [jsxs("div", {
|
|
2358
|
+
css: {
|
|
2359
|
+
margin: "calc(var(--spacing) * 4) 0",
|
|
2360
|
+
display: "grid",
|
|
2361
|
+
gridAutoFlow: "column",
|
|
2362
|
+
justifyContent: "space-between",
|
|
2363
|
+
alignItems: "center"
|
|
2364
|
+
},
|
|
2365
|
+
children: [jsx(IconButton2, __spreadProps(__spreadValues({}, getBackProps({
|
|
2366
|
+
calendars
|
|
2367
|
+
})), {
|
|
2368
|
+
children: jsx(ChevronRight2, {
|
|
2369
|
+
css: {
|
|
2370
|
+
transform: "rotate3d(0, 0, 1, 180deg)"
|
|
2371
|
+
}
|
|
2372
|
+
})
|
|
2373
|
+
})), jsxs("div", {
|
|
2374
|
+
css: {
|
|
2375
|
+
display: "flex"
|
|
2376
|
+
},
|
|
2377
|
+
children: [formatMonth(month), " ", formatYear(year)]
|
|
2378
|
+
}), jsx(IconButton2, __spreadProps(__spreadValues({}, getForwardProps({
|
|
2379
|
+
calendars
|
|
2380
|
+
})), {
|
|
2381
|
+
children: jsx(ChevronRight2, {})
|
|
2382
|
+
}))]
|
|
2383
|
+
}), jsxs("div", {
|
|
2384
|
+
css: {
|
|
2385
|
+
justifySelf: "center",
|
|
2386
|
+
display: "grid",
|
|
2387
|
+
gridTemplateColumns: "repeat(7, max-content)",
|
|
2388
|
+
fontWeight: "bold"
|
|
2389
|
+
},
|
|
2390
|
+
children: [weekDays.map((_v, weekDay) => jsx("div", {
|
|
2391
|
+
css: {
|
|
2392
|
+
justifySelf: "center",
|
|
2393
|
+
marginBottom: "var(--spacing)"
|
|
2394
|
+
},
|
|
2395
|
+
children: formatWeekday(weekDay)
|
|
2396
|
+
}, weekDay)), weeks.map((week, index) => week.map((dateObj, dayIndex) => {
|
|
2397
|
+
if (!dateObj) {
|
|
2398
|
+
return jsx("div", {});
|
|
2399
|
+
}
|
|
2400
|
+
const {
|
|
2401
|
+
prevMonth,
|
|
2402
|
+
nextMonth,
|
|
2403
|
+
date,
|
|
2404
|
+
today: today2
|
|
2405
|
+
} = dateObj;
|
|
2406
|
+
const selected = date.getTime() === (min == null ? void 0 : min.getTime()) || min && max && dateIntersect(date, {
|
|
2407
|
+
min,
|
|
2408
|
+
max
|
|
2409
|
+
});
|
|
2410
|
+
const preSelected = !selected && (date.getTime() === (hovered == null ? void 0 : hovered.getTime()) || min && !max && hovered && dateIntersect(date, min <= hovered ? {
|
|
2411
|
+
min,
|
|
2412
|
+
max: hovered
|
|
2413
|
+
} : {
|
|
2414
|
+
min: hovered,
|
|
2415
|
+
max: min
|
|
2416
|
+
}));
|
|
2417
|
+
return jsx("button", __spreadProps(__spreadValues({
|
|
2418
|
+
css: [{
|
|
2419
|
+
padding: 10,
|
|
2420
|
+
border: "1px solid transparent",
|
|
2421
|
+
background: "transparent",
|
|
2422
|
+
cursor: "pointer"
|
|
2423
|
+
}, (prevMonth || nextMonth) && {
|
|
2424
|
+
color: gray
|
|
2425
|
+
}, today2 && {
|
|
2426
|
+
border: "1px solid var(--secondaryMain)"
|
|
2427
|
+
}, selected && {
|
|
2428
|
+
background: "var(--primaryMain)",
|
|
2429
|
+
color: "var(--primaryContrastText)"
|
|
2430
|
+
}, preSelected && {
|
|
2431
|
+
background: "var(--primaryLight)",
|
|
2432
|
+
color: "var(--primaryContrastText)"
|
|
2433
|
+
}]
|
|
2434
|
+
}, getDateProps({
|
|
2435
|
+
dateObj
|
|
2436
|
+
})), {
|
|
2437
|
+
onClick: () => {
|
|
2438
|
+
if (dirty) {
|
|
2439
|
+
if (min)
|
|
2440
|
+
set(min, date);
|
|
2441
|
+
else
|
|
2442
|
+
set(date, max);
|
|
2443
|
+
} else {
|
|
2444
|
+
set(date);
|
|
2445
|
+
}
|
|
2446
|
+
},
|
|
2447
|
+
onPointerOver: () => setHovered(date),
|
|
2448
|
+
onPointerOut: () => setHovered(void 0),
|
|
2449
|
+
children: date.getDate()
|
|
2450
|
+
}), `${index}-${dayIndex}`);
|
|
2451
|
+
}))]
|
|
2452
|
+
})]
|
|
2453
|
+
}, `${month}${year}`)), jsxs("div", {
|
|
2454
|
+
css: {
|
|
2455
|
+
marginTop: "var(--spacing)",
|
|
2456
|
+
display: "grid",
|
|
2457
|
+
gridAutoFlow: "column",
|
|
2458
|
+
justifyContent: "center"
|
|
1939
2459
|
},
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
2460
|
+
children: [jsx(Button2, {
|
|
2461
|
+
variant: "text",
|
|
2462
|
+
onClick: () => {
|
|
2463
|
+
setDirty(void 0);
|
|
2464
|
+
onChange(today());
|
|
2465
|
+
},
|
|
2466
|
+
children: text.today
|
|
2467
|
+
}), jsx(Button2, {
|
|
2468
|
+
variant: "text",
|
|
2469
|
+
onClick: () => {
|
|
2470
|
+
setDirty(void 0);
|
|
2471
|
+
onChange(thisWeek(firstDayOfWeek));
|
|
2472
|
+
},
|
|
2473
|
+
children: text.thisWeek
|
|
2474
|
+
}), jsx(Button2, {
|
|
2475
|
+
variant: "text",
|
|
2476
|
+
onClick: () => {
|
|
2477
|
+
setDirty(void 0);
|
|
2478
|
+
onChange(null);
|
|
2479
|
+
},
|
|
2480
|
+
children: text.reset
|
|
2481
|
+
})]
|
|
1946
2482
|
})]
|
|
1947
|
-
})
|
|
2483
|
+
});
|
|
1948
2484
|
}
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
return value;
|
|
2485
|
+
function convertDate(x) {
|
|
2486
|
+
if (x instanceof Date)
|
|
2487
|
+
return x;
|
|
2488
|
+
if (typeof x === "number" || typeof x === "string")
|
|
2489
|
+
return new Date(x);
|
|
2490
|
+
return null;
|
|
1956
2491
|
}
|
|
1957
|
-
function
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
2492
|
+
function convertDateOrRange(x) {
|
|
2493
|
+
if (x instanceof Object && "min" in x && "max" in x) {
|
|
2494
|
+
const range = {
|
|
2495
|
+
min: convertDate(x.min),
|
|
2496
|
+
max: convertDate(x.max)
|
|
2497
|
+
};
|
|
2498
|
+
return range.min && range.max ? range : null;
|
|
2499
|
+
}
|
|
2500
|
+
return convertDate(x);
|
|
1962
2501
|
}
|
|
1963
|
-
function
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
return jsx(TableContext.Provider, {
|
|
1968
|
-
value: table,
|
|
1969
|
-
children: jsx(TableLoadingState, {})
|
|
1970
|
-
});
|
|
2502
|
+
function convertDateOrArray(x) {
|
|
2503
|
+
if (x instanceof Array)
|
|
2504
|
+
return x.map(convertDateOrRange).filter(Boolean);
|
|
2505
|
+
return convertDateOrRange(x);
|
|
1971
2506
|
}
|
|
1972
|
-
function
|
|
2507
|
+
function DateFilter(_k) {
|
|
2508
|
+
var _l = _k, {
|
|
2509
|
+
locale,
|
|
2510
|
+
firstDayOfWeek,
|
|
2511
|
+
singleSelect,
|
|
2512
|
+
filterBy = convertDateOrArray
|
|
2513
|
+
} = _l, props = __objRest(_l, [
|
|
2514
|
+
"locale",
|
|
2515
|
+
"firstDayOfWeek",
|
|
2516
|
+
"singleSelect",
|
|
2517
|
+
"filterBy"
|
|
2518
|
+
]);
|
|
1973
2519
|
const {
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
2520
|
+
value = null,
|
|
2521
|
+
onChange
|
|
2522
|
+
} = useFilter(__spreadProps(__spreadValues({}, props), {
|
|
2523
|
+
filterBy,
|
|
2524
|
+
id: "dateFilter",
|
|
2525
|
+
isActive(filterValue) {
|
|
2526
|
+
return !!filterValue;
|
|
2527
|
+
},
|
|
2528
|
+
test(filterValue, value2) {
|
|
2529
|
+
return dateIntersect(filterValue, value2);
|
|
2530
|
+
}
|
|
2531
|
+
}));
|
|
2532
|
+
return jsx("div", {
|
|
2533
|
+
css: {
|
|
2534
|
+
padding: "calc(var(--spacing) * 2)",
|
|
2535
|
+
display: "grid"
|
|
2536
|
+
},
|
|
2537
|
+
children: jsx(DatePicker, {
|
|
2538
|
+
rangeSelect: !singleSelect,
|
|
2539
|
+
value,
|
|
2540
|
+
onChange,
|
|
2541
|
+
locale,
|
|
2542
|
+
firstDayOfWeek
|
|
2543
|
+
})
|
|
1988
2544
|
});
|
|
1989
2545
|
}
|
|
1990
|
-
const TableInner = memo(function TableInner2({
|
|
1991
|
-
hidden
|
|
1992
|
-
}) {
|
|
1993
|
-
var _a, _b;
|
|
1994
|
-
const table = useTableContext();
|
|
1995
|
-
const fullWidth = table.useState("props.fullWidth");
|
|
1996
|
-
const activeColumns = table.useState((state) => state.activeColumns.map((column) => ({
|
|
1997
|
-
id: column.id,
|
|
1998
|
-
width: column.width,
|
|
1999
|
-
classes: column.classes,
|
|
2000
|
-
header: column.header
|
|
2001
|
-
})));
|
|
2002
|
-
const columnWidths = table.useState("columnWidths", {
|
|
2003
|
-
throttle: 16
|
|
2004
|
-
});
|
|
2005
|
-
const columnStyleOverride = table.useState("columnStyleOverride", {
|
|
2006
|
-
throttle: 16
|
|
2007
|
-
});
|
|
2008
|
-
const defaultWidth = table.useState("props.defaultWidth");
|
|
2009
|
-
const classes = table.useState("props.classes");
|
|
2010
|
-
const stickyHeader = table.useState("props.stickyHeader");
|
|
2011
|
-
const enableSelection = table.useState("props.enableSelection");
|
|
2012
|
-
const enableColumnSelection = table.useState("props.enableColumnSelection");
|
|
2013
|
-
const enableExport = table.useState((state) => !!state.props.enableExport.copy || !!state.props.enableExport.download);
|
|
2014
|
-
const cssVariables = useCssVariables();
|
|
2015
|
-
(_b = (_a = table.getState().props).debugRender) == null ? void 0 : _b.call(_a, "render table inner");
|
|
2016
|
-
return jsx(Virtualized, {
|
|
2017
|
-
className: classes == null ? void 0 : classes.table,
|
|
2018
|
-
css: [cssVariables, defaultClasses.table, {
|
|
2019
|
-
gridTemplateColumns: [
|
|
2020
|
-
fullWidth === "right" || fullWidth === true ? "auto" : "0",
|
|
2021
|
-
"max-content",
|
|
2022
|
-
...activeColumns.map((column) => {
|
|
2023
|
-
var _a2, _b2, _c;
|
|
2024
|
-
return (_c = (_b2 = (_a2 = columnWidths.get(column.id)) != null ? _a2 : column.width) != null ? _b2 : defaultWidth) != null ? _c : "max-content";
|
|
2025
|
-
}),
|
|
2026
|
-
fullWidth === "left" || fullWidth === true ? "auto" : "0"
|
|
2027
|
-
].join(" ")
|
|
2028
|
-
}, hidden && {
|
|
2029
|
-
visibility: "hidden"
|
|
2030
|
-
}],
|
|
2031
|
-
header: jsxs(Fragment, {
|
|
2032
|
-
children: [jsx("div", {
|
|
2033
|
-
className: classes == null ? void 0 : classes.headerCell,
|
|
2034
|
-
css: [defaultClasses.headerFill, stickyHeader && defaultClasses.sticky, stickyHeader instanceof Object && stickyHeader]
|
|
2035
|
-
}), jsxs("div", {
|
|
2036
|
-
className: classes == null ? void 0 : classes.headerCell,
|
|
2037
|
-
css: [defaultClasses.headerCell, stickyHeader && defaultClasses.sticky, stickyHeader instanceof Object && stickyHeader],
|
|
2038
|
-
children: [enableSelection && jsx(SelectComponent, {}), enableColumnSelection && jsx(ColumnSelection, {}), enableExport && jsx(Export, {}), jsx(ResizeHandleView, {})]
|
|
2039
|
-
}), jsx(ColumnHeaderContext.Provider, {
|
|
2040
|
-
children: activeColumns.map((column) => {
|
|
2041
|
-
var _a2;
|
|
2042
|
-
return jsx(ColumnContext.Provider, {
|
|
2043
|
-
value: column.id,
|
|
2044
|
-
children: jsxs(ColumnHeader, {
|
|
2045
|
-
className: cx(classes == null ? void 0 : classes.headerCell, (_a2 = column.classes) == null ? void 0 : _a2.headerCell),
|
|
2046
|
-
css: [defaultClasses.headerCell, columnStyleOverride.get(column.id), stickyHeader && defaultClasses.sticky, stickyHeader instanceof Object && stickyHeader],
|
|
2047
|
-
children: [jsx(SortComponent, {
|
|
2048
|
-
children: column.header
|
|
2049
|
-
}), jsx("div", {
|
|
2050
|
-
css: {
|
|
2051
|
-
flex: 1
|
|
2052
|
-
}
|
|
2053
|
-
}), jsx(FilterControl, {}), jsx(ResizeHandle, {})]
|
|
2054
|
-
}, column.id)
|
|
2055
|
-
}, column.id);
|
|
2056
|
-
})
|
|
2057
|
-
}), jsx("div", {
|
|
2058
|
-
className: classes == null ? void 0 : classes.headerCell,
|
|
2059
|
-
css: [defaultClasses.headerFill, stickyHeader && defaultClasses.sticky, stickyHeader instanceof Object && stickyHeader]
|
|
2060
|
-
})]
|
|
2061
|
-
}),
|
|
2062
|
-
children: (itemIds, startIndex) => itemIds.map((itemId, index) => jsx(Row, {
|
|
2063
|
-
itemId,
|
|
2064
|
-
rowIndex: startIndex + index
|
|
2065
|
-
}, itemId))
|
|
2066
|
-
});
|
|
2067
|
-
});
|
|
2068
2546
|
function toggle(set, value, singleSelect) {
|
|
2069
2547
|
const newSet = new Set(singleSelect ? [] : set);
|
|
2070
2548
|
if (set.has(value)) {
|
|
@@ -2074,13 +2552,13 @@ function toggle(set, value, singleSelect) {
|
|
|
2074
2552
|
}
|
|
2075
2553
|
return newSet;
|
|
2076
2554
|
}
|
|
2077
|
-
function SelectFilter(
|
|
2078
|
-
var
|
|
2555
|
+
function SelectFilter(_m) {
|
|
2556
|
+
var _n = _m, {
|
|
2079
2557
|
options: providedOptions,
|
|
2080
2558
|
stringValue = asString,
|
|
2081
2559
|
render = stringValue,
|
|
2082
2560
|
singleSelect
|
|
2083
|
-
} =
|
|
2561
|
+
} = _n, props = __objRest(_n, [
|
|
2084
2562
|
"options",
|
|
2085
2563
|
"stringValue",
|
|
2086
2564
|
"render",
|
|
@@ -2088,12 +2566,12 @@ function SelectFilter(_g) {
|
|
|
2088
2566
|
]);
|
|
2089
2567
|
const {
|
|
2090
2568
|
components: {
|
|
2091
|
-
IconButton,
|
|
2092
|
-
Checkbox
|
|
2569
|
+
IconButton: IconButton2,
|
|
2570
|
+
Checkbox: Checkbox2
|
|
2093
2571
|
},
|
|
2094
2572
|
icons: {
|
|
2095
|
-
Search,
|
|
2096
|
-
Clear
|
|
2573
|
+
Search: Search2,
|
|
2574
|
+
Clear: Clear2
|
|
2097
2575
|
},
|
|
2098
2576
|
text
|
|
2099
2577
|
} = useTheme();
|
|
@@ -2131,10 +2609,10 @@ function SelectFilter(_g) {
|
|
|
2131
2609
|
},
|
|
2132
2610
|
children: [jsx(AutoFocusTextField, {
|
|
2133
2611
|
value: query,
|
|
2134
|
-
onChange: (
|
|
2135
|
-
endIcon: jsx(
|
|
2612
|
+
onChange: (e2) => setQuery(e2.target.value),
|
|
2613
|
+
endIcon: jsx(IconButton2, {
|
|
2136
2614
|
onClick: () => setQuery(""),
|
|
2137
|
-
children: !query ? jsx(
|
|
2615
|
+
children: !query ? jsx(Search2, {}) : jsx(Clear2, {})
|
|
2138
2616
|
}),
|
|
2139
2617
|
css: {
|
|
2140
2618
|
marginBottom: "var(--spacing)"
|
|
@@ -2146,7 +2624,7 @@ function SelectFilter(_g) {
|
|
|
2146
2624
|
},
|
|
2147
2625
|
children: [jsx(FormControlLabel, {
|
|
2148
2626
|
disabled: value.size === 0,
|
|
2149
|
-
control: jsx(
|
|
2627
|
+
control: jsx(Checkbox2, {
|
|
2150
2628
|
disabled: value.size === 0,
|
|
2151
2629
|
checked: value.size > 0,
|
|
2152
2630
|
onChange: () => onChange(/* @__PURE__ */ new Set())
|
|
@@ -2155,7 +2633,7 @@ function SelectFilter(_g) {
|
|
|
2155
2633
|
children: ["<", text.selected(value.size), ">"]
|
|
2156
2634
|
})
|
|
2157
2635
|
}), filtered.map((option, index) => jsx(FormControlLabel, {
|
|
2158
|
-
control: jsx(
|
|
2636
|
+
control: jsx(Checkbox2, {
|
|
2159
2637
|
checked: value.has(option),
|
|
2160
2638
|
onChange: () => onChange(toggle(value, option, singleSelect))
|
|
2161
2639
|
}),
|
|
@@ -2262,21 +2740,21 @@ const termMatch = (text, query) => {
|
|
|
2262
2740
|
}
|
|
2263
2741
|
return true;
|
|
2264
2742
|
};
|
|
2265
|
-
function TextFilter(
|
|
2266
|
-
var
|
|
2743
|
+
function TextFilter(_o) {
|
|
2744
|
+
var _p = _o, {
|
|
2267
2745
|
compare = textMatch,
|
|
2268
2746
|
filterBy = asStringOrArray
|
|
2269
|
-
} =
|
|
2747
|
+
} = _p, props = __objRest(_p, [
|
|
2270
2748
|
"compare",
|
|
2271
2749
|
"filterBy"
|
|
2272
2750
|
]);
|
|
2273
2751
|
const {
|
|
2274
2752
|
components: {
|
|
2275
|
-
IconButton
|
|
2753
|
+
IconButton: IconButton2
|
|
2276
2754
|
},
|
|
2277
2755
|
icons: {
|
|
2278
|
-
Search,
|
|
2279
|
-
Clear
|
|
2756
|
+
Search: Search2,
|
|
2757
|
+
Clear: Clear2
|
|
2280
2758
|
}
|
|
2281
2759
|
} = useTheme();
|
|
2282
2760
|
const {
|
|
@@ -2299,10 +2777,10 @@ function TextFilter(_i) {
|
|
|
2299
2777
|
},
|
|
2300
2778
|
children: jsx(AutoFocusTextField, {
|
|
2301
2779
|
value,
|
|
2302
|
-
onChange: (
|
|
2303
|
-
endIcon: jsx(
|
|
2780
|
+
onChange: (e2) => onChange(e2.target.value),
|
|
2781
|
+
endIcon: jsx(IconButton2, {
|
|
2304
2782
|
onClick: () => onChange(""),
|
|
2305
|
-
children: !value ? jsx(
|
|
2783
|
+
children: !value ? jsx(Search2, {}) : jsx(Clear2, {})
|
|
2306
2784
|
})
|
|
2307
2785
|
})
|
|
2308
2786
|
});
|