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