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