schummar-table 0.5.3 → 0.6.0

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