schummar-table 0.6.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cjs/index.js CHANGED
@@ -40,6 +40,34 @@ var dayzed = require("dayzed");
40
40
  var immer = require("immer");
41
41
  var react$2 = require("@emotion/react");
42
42
  require("react-dom");
43
+ const TableMemoContext = react.createContext(/* @__PURE__ */ new Map());
44
+ function TableMemoContextProvider({
45
+ children
46
+ }) {
47
+ return /* @__PURE__ */ jsxRuntime.jsx(TableMemoContext.Provider, {
48
+ value: react.useMemo(() => /* @__PURE__ */ new Map(), []),
49
+ children
50
+ });
51
+ }
52
+ function useTableMemo() {
53
+ const memoCache = react.useContext(TableMemoContext);
54
+ return (key, fn) => {
55
+ let deps;
56
+ if (Array.isArray(fn)) {
57
+ deps = fn.slice(1);
58
+ fn = fn[0];
59
+ } else {
60
+ deps = [fn.toString()];
61
+ }
62
+ let cachedValue = memoCache.get(key);
63
+ const hit = cachedValue && cachedValue[1].length === deps.length && cachedValue[1].every((x, i) => x === deps[i]);
64
+ if (!cachedValue || !hit) {
65
+ cachedValue = [fn, deps];
66
+ memoCache.set(key, cachedValue);
67
+ }
68
+ return cachedValue[0];
69
+ };
70
+ }
43
71
  class Queue {
44
72
  constructor() {
45
73
  this.q = new Array();
@@ -282,10 +310,11 @@ function calcItems(state) {
282
310
  state2.activeColumns,
283
311
  state2.expanded
284
312
  ], ([items = [], id, parentId, revealFiltered, sort, filters, filterValues, activeColumns], draft) => {
285
- const tableItems = items.map((item) => __spreadProps(__spreadValues({}, item), {
313
+ const tableItems = items.map((item) => ({
286
314
  id: id(item),
287
315
  parentId: parentId == null ? void 0 : parentId(item),
288
- children: []
316
+ children: [],
317
+ value: item
289
318
  }));
290
319
  let sorted;
291
320
  if (sort.length === 0) {
@@ -295,10 +324,12 @@ function calcItems(state) {
295
324
  const column = activeColumns.find((column2) => column2.id === sort2.columnId);
296
325
  if (!column)
297
326
  return [];
298
- const sortBy = column.sortBy instanceof Array ? column.sortBy : [column.sortBy];
299
- return sortBy.map((sortBy2) => ({ selector: (item) => sortBy2(column.value(item), item), direction: sort2.direction }));
327
+ return column.sortBy.map((sortBy) => ({
328
+ selector: (item) => sortBy(column.value(item), item),
329
+ direction: sort2.direction
330
+ }));
300
331
  }).filter(Boolean);
301
- sorted = orderBy(tableItems, selectors.map((x) => x.selector), selectors.map((x) => x.direction));
332
+ sorted = orderBy(tableItems, selectors.map((x) => (item) => x.selector(item.value)), selectors.map((x) => x.direction));
302
333
  }
303
334
  const lookup = /* @__PURE__ */ new Map();
304
335
  for (const item of sorted) {
@@ -332,7 +363,7 @@ function calcItems(state) {
332
363
  if (filterValue === void 0 || !filter.isActive(filterValue))
333
364
  return true;
334
365
  const filterBy = (_a = filter.filterBy) != null ? _a : (x) => x;
335
- const value = filterBy(column.value(item), item);
366
+ const value = filterBy(column.value(item.value), item.value);
336
367
  return castArray(value).some((value2) => filter.test(filterValue, value2));
337
368
  }));
338
369
  if (isActive && item.parentId !== void 0) {
@@ -368,20 +399,20 @@ function calcItems(state) {
368
399
  }
369
400
  const noopParentId = () => void 0;
370
401
  function calcProps(props) {
371
- const columnCache = react.useRef(/* @__PURE__ */ new Map());
402
+ const cache = useTableMemo();
372
403
  return react.useMemo(() => {
373
- var _c, _d, _e, _f, _g, _h;
404
+ var _f, _g, _h, _i, _j, _k, _l;
374
405
  let id;
375
- if (props.id instanceof Function) {
376
- id = props.id;
406
+ if (props.id instanceof Function || Array.isArray(props.id)) {
407
+ id = cache("id", props.id);
377
408
  } else {
378
- id = (item) => item[props.id];
409
+ id = cache("id", [(item) => item[props.id], props.id]);
379
410
  }
380
411
  let parentId;
381
- if (props.parentId instanceof Function) {
382
- parentId = props.parentId;
383
- } else if (typeof props.parentId === "string") {
384
- parentId = (item) => item[props.parentId];
412
+ if (props.parentId instanceof Function || Array.isArray(props.parentId)) {
413
+ parentId = cache("parentId", props.parentId);
414
+ } else if (props.parentId !== void 0) {
415
+ parentId = cache("parentId", [(item) => item[props.parentId], props.parentId]);
385
416
  } else {
386
417
  parentId = noopParentId;
387
418
  }
@@ -391,42 +422,39 @@ function calcProps(props) {
391
422
  } else {
392
423
  inputColumns = props.columns.map((column) => __spreadProps(__spreadValues({}, column), { dependecies: void 0 }));
393
424
  }
394
- const newColumnCache = /* @__PURE__ */ new Map();
395
- const columns = inputColumns.map(function(_a, index) {
396
- var _b = _a, {
425
+ const defCol = props.defaultColumnProps;
426
+ const mapColumn = ({
427
+ id: _id,
428
+ header = ((_a) => (_a = defCol == null ? void 0 : defCol.header) != null ? _a : null)(),
429
+ footer = ((_b) => (_b = defCol == null ? void 0 : defCol.footer) != null ? _b : null)(),
430
+ value,
431
+ renderCell = ((_c) => (_c = defCol == null ? void 0 : defCol.renderCell) != null ? _c : asString)(),
432
+ exportCell = ((_d) => (_d = defCol == null ? void 0 : defCol.exportCell) != null ? _d : asString)(),
433
+ sortBy = ((_e) => (_e = defCol == null ? void 0 : defCol.sortBy) != null ? _e : [(v) => typeof v === "number" || v instanceof Date ? v : String(v)])(),
434
+ cannotHide = defCol == null ? void 0 : defCol.cannotHide,
435
+ classes = defCol == null ? void 0 : defCol.classes,
436
+ filter = defCol == null ? void 0 : defCol.filter,
437
+ width = defCol == null ? void 0 : defCol.width
438
+ }, index) => {
439
+ const id2 = _id != null ? _id : index;
440
+ const cacheKey = typeof id2 === "string" ? `s${id2}` : `n${id2}`;
441
+ return {
397
442
  id: id2,
398
- header = null,
399
- renderCell = asString,
400
- exportCell = asString,
401
- sortBy = (v) => typeof v === "number" || v instanceof Date ? v : String(v),
402
- dependencies = []
403
- } = _b, props2 = __objRest(_b, [
404
- "id",
405
- "header",
406
- "renderCell",
407
- "exportCell",
408
- "sortBy",
409
- "dependencies"
410
- ]);
411
- var _a2;
412
- const [depsInCache, columnInCache] = (_a2 = columnCache.current.get(id2 != null ? id2 : index)) != null ? _a2 : [];
413
- let column;
414
- if (depsInCache && columnInCache && depsInCache.length === dependencies.length && depsInCache.every((x, i) => dependencies[i] === x)) {
415
- column = columnInCache;
416
- } else {
417
- column = __spreadValues({
418
- id: id2 != null ? id2 : index,
419
- header,
420
- renderCell,
421
- exportCell,
422
- sortBy,
423
- dependencies
424
- }, props2);
425
- }
426
- newColumnCache.set(id2 != null ? id2 : index, [dependencies, column]);
427
- return column;
428
- });
429
- columnCache.current = newColumnCache;
443
+ header: header instanceof Function ? cache(`columns.${cacheKey}.header`, header) : header,
444
+ footer: footer instanceof Function ? cache(`columns.${cacheKey}.footer`, footer) : footer,
445
+ value: cache(`columns.${cacheKey}.value`, value),
446
+ renderCell: cache(`columns.${cacheKey}.renderCell`, renderCell),
447
+ exportCell,
448
+ sortBy: sortBy.map((fn, i) => cache(`columns.${cacheKey}.sortBy.${i}`, fn)),
449
+ cannotHide,
450
+ classes,
451
+ filter,
452
+ width
453
+ };
454
+ };
455
+ const columns = inputColumns.map(mapColumn);
456
+ const wrapCell = props.wrapCell && cache("wrapCell", props.wrapCell);
457
+ const rowAction = props.rowAction instanceof Function || Array.isArray(props.rowAction) ? cache("rowAction", props.rowAction) : props.rowAction;
430
458
  let copy;
431
459
  if (props.enableExport === true || props.enableExport instanceof Object && props.enableExport.copy === true) {
432
460
  copy = { separator: " " };
@@ -444,13 +472,16 @@ function calcProps(props) {
444
472
  id,
445
473
  parentId,
446
474
  columns,
447
- enableSelection: (_c = props.enableSelection) != null ? _c : true,
448
- selectSyncChildren: (_d = props.selectSyncChildren) != null ? _d : true,
449
- stickyHeader: (_e = props.stickyHeader) != null ? _e : true,
475
+ wrapCell,
476
+ rowAction,
477
+ enableSelection: (_f = props.enableSelection) != null ? _f : true,
478
+ selectSyncChildren: (_g = props.selectSyncChildren) != null ? _g : true,
479
+ stickyHeader: (_h = props.stickyHeader) != null ? _h : true,
480
+ stickyFooter: (_i = props.stickyFooter) != null ? _i : true,
450
481
  enableExport,
451
- enableColumnSelection: (_f = props.enableColumnSelection) != null ? _f : true,
452
- enableColumnResize: (_g = props.enableColumnResize) != null ? _g : true,
453
- enableColumnReorder: (_h = props.enableColumnReorder) != null ? _h : true
482
+ enableColumnSelection: (_j = props.enableColumnSelection) != null ? _j : true,
483
+ enableColumnResize: (_k = props.enableColumnResize) != null ? _k : true,
484
+ enableColumnReorder: (_l = props.enableColumnReorder) != null ? _l : true
454
485
  });
455
486
  }, [props]);
456
487
  }
@@ -580,25 +611,269 @@ function useTableState(_props) {
580
611
  return state;
581
612
  }
582
613
  function useCssVariables() {
583
- const theme = useTheme();
584
- return {
585
- "--spacing": theme.spacing,
586
- "--primaryMain": theme.colors.primary.main,
587
- "--primaryLight": theme.colors.primary.light,
588
- "--primaryContrastText": theme.colors.primary.contrastText,
589
- "--secondaryMain": theme.colors.secondary.main,
590
- "--secondaryLight": theme.colors.secondary.light,
591
- "--secondaryContrastText": theme.colors.secondary.contrastText
592
- };
614
+ return useTheme(({ spacing, colors }) => ({
615
+ "--spacing": spacing,
616
+ "--primaryMain": colors.primary.main,
617
+ "--primaryLight": colors.primary.light,
618
+ "--primaryContrastText": colors.primary.contrastText,
619
+ "--secondaryMain": colors.secondary.main,
620
+ "--secondaryLight": colors.secondary.light,
621
+ "--secondaryContrastText": colors.secondary.contrastText
622
+ }));
623
+ }
624
+ function ColumnFooter() {
625
+ const table = useTableContext();
626
+ const columnId = useColumnContext();
627
+ const stickyFooter = table.useState("props.stickyFooter");
628
+ const columnStyleOverride = table.useState((state) => state.columnStyleOverride.get(columnId), {
629
+ throttle: 16
630
+ });
631
+ const columnClasses = table.useState((state) => {
632
+ var _a;
633
+ return (_a = state.activeColumns.find((column) => column.id === columnId)) == null ? void 0 : _a.classes;
634
+ });
635
+ const classes = useTheme((theme) => theme.classes);
636
+ const content = table.useState((state) => {
637
+ const column = state.activeColumns.find((column2) => column2.id === columnId);
638
+ if ((column == null ? void 0 : column.footer) instanceof Function) {
639
+ const items = state.activeItems;
640
+ const values = items.map((item) => column == null ? void 0 : column.value(item));
641
+ return column == null ? void 0 : column.footer(values, items);
642
+ }
643
+ return column == null ? void 0 : column.footer;
644
+ });
645
+ return /* @__PURE__ */ jsxRuntime.jsx("div", {
646
+ className: cx(classes == null ? void 0 : classes.footerCell, columnClasses == null ? void 0 : columnClasses.footerCell),
647
+ css: [tableTheme.defaultClasses.footerCell, columnStyleOverride, stickyFooter && tableTheme.defaultClasses.stickyBottom, stickyFooter instanceof Object && stickyFooter],
648
+ children: content
649
+ });
650
+ }
651
+ const FilterControlContext = react.createContext(() => void 0);
652
+ function FilterControl() {
653
+ const table = useTableContext();
654
+ const columnId = useColumnContext();
655
+ const IconButton2 = useTheme((t) => t.components.IconButton);
656
+ const Popover = useTheme((t) => t.components.Popover);
657
+ const FilterList2 = useTheme((t) => t.icons.FilterList);
658
+ const ArrowDropDown2 = useTheme((t) => t.icons.ArrowDropDown);
659
+ const cssVariables = useCssVariables();
660
+ const [anchor, setAnchor] = react.useState(null);
661
+ const isActive = table.useState((state) => {
662
+ const filter2 = state.filters.get(columnId);
663
+ const filterValue = state.filterValues.get(columnId);
664
+ return filter2 !== void 0 && filterValue !== void 0 && filter2.isActive(filterValue);
665
+ });
666
+ const filter = table.useState((state) => {
667
+ var _a;
668
+ return (_a = state.activeColumns.find((column) => column.id === columnId)) == null ? void 0 : _a.filter;
669
+ });
670
+ function reset() {
671
+ table.update((state) => {
672
+ state.filterValues.delete(columnId);
673
+ });
674
+ }
675
+ const close = react.useCallback(function() {
676
+ setAnchor(null);
677
+ }, []);
678
+ if (!filter)
679
+ return null;
680
+ return /* @__PURE__ */ jsxRuntime.jsxs(FilterControlContext.Provider, {
681
+ value: close,
682
+ children: [/* @__PURE__ */ jsxRuntime.jsx("div", {
683
+ onClick: (e) => setAnchor(e.currentTarget),
684
+ onContextMenu: (e) => {
685
+ reset();
686
+ e.preventDefault();
687
+ return false;
688
+ },
689
+ children: /* @__PURE__ */ jsxRuntime.jsx(IconButton2, {
690
+ css: [{
691
+ color: "#b0bac9"
692
+ }, isActive && {
693
+ color: "var(--primaryMain) !important"
694
+ }],
695
+ children: isActive ? /* @__PURE__ */ jsxRuntime.jsx(FilterList2, {}) : /* @__PURE__ */ jsxRuntime.jsx(ArrowDropDown2, {})
696
+ })
697
+ }), /* @__PURE__ */ jsxRuntime.jsx("div", {
698
+ onPointerDown: (e) => {
699
+ e.stopPropagation();
700
+ },
701
+ onPointerMove: (e) => {
702
+ e.stopPropagation();
703
+ },
704
+ children: /* @__PURE__ */ jsxRuntime.jsx(Popover, {
705
+ open: true,
706
+ hidden: !anchor,
707
+ onClose: () => setAnchor(null),
708
+ anchorEl: anchor != null ? anchor : document.body,
709
+ css: cssVariables,
710
+ children: filter
711
+ })
712
+ })]
713
+ });
714
+ }
715
+ function ResizeHandle() {
716
+ const table = useTableContext();
717
+ const columnId = useColumnContext();
718
+ const enabled = table.useState("props.enableColumnResize");
719
+ function onPointerDown(e) {
720
+ e.stopPropagation();
721
+ const div = e.target;
722
+ div.setPointerCapture(e.pointerId);
723
+ }
724
+ function onPointerMove(e) {
725
+ e.stopPropagation();
726
+ const div = e.target;
727
+ if (!div.hasPointerCapture(e.pointerId))
728
+ return;
729
+ const parent = div.parentElement;
730
+ const width = Math.max(e.clientX - parent.getBoundingClientRect().left + 5, 50);
731
+ table.update((state) => {
732
+ state.columnWidths.set(columnId, `${width}px`);
733
+ });
734
+ }
735
+ function onPointerUp(e) {
736
+ e.stopPropagation();
737
+ const div = e.target;
738
+ div.releasePointerCapture(e.pointerId);
739
+ }
740
+ function onDoubleClick(e) {
741
+ table.update((state) => {
742
+ if (e.getModifierState("Control")) {
743
+ state.columnWidths.delete(columnId);
744
+ } else {
745
+ state.columnWidths.set(columnId, "max-content");
746
+ }
747
+ });
748
+ }
749
+ return /* @__PURE__ */ jsxRuntime.jsx(ResizeHandleView, {
750
+ enabled,
751
+ onPointerDown: enabled ? onPointerDown : void 0,
752
+ onPointerMove: enabled ? onPointerMove : void 0,
753
+ onPointerUp: enabled ? onPointerUp : void 0,
754
+ onDoubleClick: enabled ? onDoubleClick : void 0
755
+ });
756
+ }
757
+ function ResizeHandleView(_a) {
758
+ var _b = _a, {
759
+ enabled
760
+ } = _b, props = __objRest(_b, [
761
+ "enabled"
762
+ ]);
763
+ return /* @__PURE__ */ jsxRuntime.jsx("div", __spreadValues({
764
+ css: {
765
+ alignSelf: "stretch",
766
+ padding: "0 5px",
767
+ cursor: enabled ? "col-resize" : "initial",
768
+ display: "flex",
769
+ alignItems: "center",
770
+ "&:after": {
771
+ content: '""',
772
+ width: 1,
773
+ height: "1.5em",
774
+ background: "#c9cfda",
775
+ transition: "transform 300ms"
776
+ }
777
+ }
778
+ }, props));
779
+ }
780
+ function SortComponent({
781
+ children
782
+ }) {
783
+ const table = useTableContext();
784
+ const columnId = useColumnContext();
785
+ const Badge2 = useTheme((t) => t.components.Badge);
786
+ const ArrowUpward2 = useTheme((t) => t.icons.ArrowUpward);
787
+ const {
788
+ direction,
789
+ index
790
+ } = table.useState((state) => {
791
+ var _a, _b;
792
+ const index2 = (_a = state.sort.findIndex((s) => s.columnId === columnId)) != null ? _a : -1;
793
+ return {
794
+ direction: (_b = state.sort[index2]) == null ? void 0 : _b.direction,
795
+ index: index2 >= 0 && state.sort.length > 1 ? index2 + 1 : void 0
796
+ };
797
+ });
798
+ function toggle2(e, off) {
799
+ const {
800
+ props: {
801
+ sort: controlledSort,
802
+ onSortChange
803
+ }
804
+ } = table.getState();
805
+ const newDirection = direction === "asc" ? "desc" : "asc";
806
+ const newSort = e.getModifierState("Control") || off ? table.getState().sort.filter((s) => s.columnId !== columnId) : [];
807
+ if (!off) {
808
+ newSort.push({
809
+ columnId,
810
+ direction: newDirection
811
+ });
812
+ }
813
+ onSortChange == null ? void 0 : onSortChange(newSort);
814
+ if (!controlledSort) {
815
+ table.update((state) => {
816
+ state.sort = newSort;
817
+ });
818
+ }
819
+ e.preventDefault();
820
+ return false;
821
+ }
822
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", {
823
+ css: {
824
+ userSelect: "none",
825
+ display: "grid",
826
+ gridTemplateColumns: "minmax(0, 1fr) max-content",
827
+ alignItems: "center",
828
+ cursor: "pointer",
829
+ "& > div": {
830
+ overflow: "hidden",
831
+ textOverflow: "ellipsis"
832
+ }
833
+ },
834
+ onClick: (e) => toggle2(e),
835
+ onContextMenu: (e) => toggle2(e, true),
836
+ children: [/* @__PURE__ */ jsxRuntime.jsx("div", {
837
+ children
838
+ }), /* @__PURE__ */ jsxRuntime.jsx(Badge2, {
839
+ badgeContent: index,
840
+ children: /* @__PURE__ */ jsxRuntime.jsx("span", {
841
+ css: [{
842
+ transition: "all 300ms",
843
+ fontSize: "0.8em"
844
+ }, !direction && {
845
+ opacity: 0
846
+ }, direction === "desc" && {
847
+ transform: "rotate3d(0, 0, 1, 180deg)"
848
+ }],
849
+ children: /* @__PURE__ */ jsxRuntime.jsx(ArrowUpward2, {})
850
+ })
851
+ })]
852
+ });
593
853
  }
594
854
  const ColumnHeaderContext = new react$1.StoreScope({
595
855
  items: /* @__PURE__ */ new Map()
596
856
  });
597
- function ColumnHeader(props) {
857
+ function ColumnHeader() {
598
858
  const ref = react.useRef(null);
599
859
  const columnId = useColumnContext();
600
860
  const table = useTableContext();
601
861
  const enabled = table.useState("props.enableColumnReorder");
862
+ const columnStyleOverride = table.useState((state) => state.columnStyleOverride.get(columnId), {
863
+ throttle: 16
864
+ });
865
+ const stickyHeader = table.useState("props.stickyHeader");
866
+ const classes = useTheme((theme) => theme.classes);
867
+ const {
868
+ header,
869
+ columnClasses
870
+ } = table.useState((state) => {
871
+ const column = state.activeColumns.find((column2) => column2.id === columnId);
872
+ return {
873
+ header: column == null ? void 0 : column.header,
874
+ columnClasses: column == null ? void 0 : column.classes
875
+ };
876
+ });
602
877
  const store = ColumnHeaderContext.useStore();
603
878
  const draggingStart = react.useRef();
604
879
  const clone = react.useRef();
@@ -717,24 +992,31 @@ function ColumnHeader(props) {
717
992
  clone.current = void 0;
718
993
  });
719
994
  }
720
- return jsxRuntime.jsx("div", __spreadProps(__spreadValues({}, props), {
721
- css: {
995
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", {
996
+ ref,
997
+ className: cx(classes == null ? void 0 : classes.headerCell, columnClasses == null ? void 0 : columnClasses.headerCell),
998
+ css: [{
722
999
  position: "relative",
723
1000
  userSelect: "none"
724
- },
725
- ref,
1001
+ }, tableTheme.defaultClasses.headerCell, columnStyleOverride, stickyHeader && tableTheme.defaultClasses.sticky, stickyHeader instanceof Object && stickyHeader],
726
1002
  onPointerDown: enabled ? onPointerDown : void 0,
727
1003
  onPointerMove: enabled ? onPointerMove : void 0,
728
1004
  onPointerUp: enabled ? onPointerUp : void 0,
729
- children: props.children
730
- }));
1005
+ children: [/* @__PURE__ */ jsxRuntime.jsx(SortComponent, {
1006
+ children: header
1007
+ }), /* @__PURE__ */ jsxRuntime.jsx("div", {
1008
+ css: {
1009
+ flex: 1
1010
+ }
1011
+ }), /* @__PURE__ */ jsxRuntime.jsx(FilterControl, {}), /* @__PURE__ */ jsxRuntime.jsx(ResizeHandle, {})]
1012
+ });
731
1013
  }
732
1014
  function FormControlLabel({
733
1015
  control,
734
1016
  label,
735
1017
  disabled
736
1018
  }) {
737
- return jsxRuntime.jsxs("label", {
1019
+ return /* @__PURE__ */ jsxRuntime.jsxs("label", {
738
1020
  css: [{
739
1021
  display: "flex",
740
1022
  alignItems: "center",
@@ -746,7 +1028,7 @@ function FormControlLabel({
746
1028
  }, disabled && {
747
1029
  color: "rgba(0, 0, 0, 0.26)"
748
1030
  }],
749
- children: [control, jsxRuntime.jsx("span", {
1031
+ children: [control, /* @__PURE__ */ jsxRuntime.jsx("span", {
750
1032
  css: {
751
1033
  marginLeft: "var(--spacing)"
752
1034
  },
@@ -755,17 +1037,11 @@ function FormControlLabel({
755
1037
  });
756
1038
  }
757
1039
  function ColumnSelection() {
758
- const {
759
- components: {
760
- IconButton: IconButton2,
761
- Popover,
762
- Checkbox: Checkbox2
763
- },
764
- icons: {
765
- Settings: Settings2
766
- },
767
- text
768
- } = useTheme();
1040
+ const IconButton2 = useTheme((t) => t.components.IconButton);
1041
+ const Popover = useTheme((t) => t.components.Popover);
1042
+ const Checkbox2 = useTheme((t) => t.components.Checkbox);
1043
+ const Settings2 = useTheme((t) => t.icons.Settings);
1044
+ const selectColumns = useTheme((t) => t.text.selectColumns);
769
1045
  const cssVariables = useCssVariables();
770
1046
  const table = useTableContext();
771
1047
  const columns = table.useState("props.columns");
@@ -790,27 +1066,27 @@ function ColumnSelection() {
790
1066
  }
791
1067
  onHiddenColumnsChange == null ? void 0 : onHiddenColumnsChange(newValue);
792
1068
  };
793
- return jsxRuntime.jsxs(jsxRuntime.Fragment, {
794
- children: [jsxRuntime.jsx(IconButton2, {
1069
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, {
1070
+ children: [/* @__PURE__ */ jsxRuntime.jsx(IconButton2, {
795
1071
  onClick: (e) => setAnchorEl(anchorEl ? null : e.currentTarget),
796
- children: jsxRuntime.jsx(Settings2, {})
797
- }), jsxRuntime.jsx(Popover, {
1072
+ children: /* @__PURE__ */ jsxRuntime.jsx(Settings2, {})
1073
+ }), /* @__PURE__ */ jsxRuntime.jsx(Popover, {
798
1074
  anchorEl,
799
1075
  open: !!anchorEl,
800
1076
  onClose: () => setAnchorEl(null),
801
1077
  css: cssVariables,
802
- children: jsxRuntime.jsxs("div", {
1078
+ children: /* @__PURE__ */ jsxRuntime.jsxs("div", {
803
1079
  css: {
804
1080
  padding: `calc(var(--spacing) * 2)`,
805
1081
  display: "grid"
806
1082
  },
807
- children: [jsxRuntime.jsx("div", {
1083
+ children: [/* @__PURE__ */ jsxRuntime.jsx("div", {
808
1084
  css: {
809
1085
  marginBottom: "var(--spacing)"
810
1086
  },
811
- children: text.selectColumns
812
- }), columns.map((column) => jsxRuntime.jsx(FormControlLabel, {
813
- control: jsxRuntime.jsx(Checkbox2, {
1087
+ children: selectColumns
1088
+ }), columns.map((column) => /* @__PURE__ */ jsxRuntime.jsx(FormControlLabel, {
1089
+ control: /* @__PURE__ */ jsxRuntime.jsx(Checkbox2, {
814
1090
  checked: !hiddenColumns.has(column.id),
815
1091
  onChange: () => toggle2(column),
816
1092
  disabled: column.cannotHide
@@ -835,18 +1111,14 @@ function csvExport(data, { sepPrefix, separator = ",", quote = '"', eol = "\n" }
835
1111
  }
836
1112
  function Export$1() {
837
1113
  const table = useTableContext();
838
- const {
839
- components: {
840
- Button: Button2,
841
- IconButton: IconButton2,
842
- Popover
843
- },
844
- icons: {
845
- Export: Export2,
846
- Clipboard: Clipboard2
847
- },
848
- text
849
- } = useTheme();
1114
+ const Button2 = useTheme((t) => t.components.Button);
1115
+ const IconButton2 = useTheme((t) => t.components.IconButton);
1116
+ const Popover = useTheme((t) => t.components.Popover);
1117
+ const Export2 = useTheme((t) => t.icons.Export);
1118
+ const Clipboard2 = useTheme((t) => t.icons.Clipboard);
1119
+ const exportTitle = useTheme((t) => t.text.exportTitle);
1120
+ const exportCopy = useTheme((t) => t.text.exportCopy);
1121
+ const exportDownload = useTheme((t) => t.text.exportDownload);
850
1122
  const cssVariables = useCssVariables();
851
1123
  const [anchor, setAnchor] = react.useState(null);
852
1124
  const generate = (options) => {
@@ -854,7 +1126,7 @@ function Export$1() {
854
1126
  activeColumns,
855
1127
  activeItems
856
1128
  } = table.getState();
857
- const data = [activeColumns.map((column) => String(column.id)), ...activeItems.map((item) => activeColumns.map((column) => column.exportCell(column.value(item), item)))];
1129
+ const data = [activeColumns.map((column) => String(column.id)), ...activeItems.map((item) => activeColumns.map((column) => column.exportCell(column.value(item.value), item.value)))];
858
1130
  return csvExport(data, options);
859
1131
  };
860
1132
  const copy = () => {
@@ -868,225 +1140,97 @@ function Export$1() {
868
1140
  a.click();
869
1141
  document.body.removeChild(a);
870
1142
  };
871
- return jsxRuntime.jsxs(jsxRuntime.Fragment, {
872
- children: [jsxRuntime.jsx(IconButton2, {
1143
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, {
1144
+ children: [/* @__PURE__ */ jsxRuntime.jsx(IconButton2, {
873
1145
  onClick: (e) => setAnchor(anchor ? null : e.currentTarget),
874
- children: jsxRuntime.jsx(Export2, {
1146
+ children: /* @__PURE__ */ jsxRuntime.jsx(Export2, {
875
1147
  css: !!anchor && {
876
1148
  color: "var(--primaryMain)"
877
1149
  }
878
1150
  })
879
- }), jsxRuntime.jsx(Popover, {
880
- open: !!anchor,
881
- onClose: () => setAnchor(null),
882
- anchorEl: anchor,
883
- css: cssVariables,
884
- children: jsxRuntime.jsxs("div", {
885
- css: {
886
- padding: `calc(var(--spacing) * 2)`,
887
- display: "grid",
888
- justifyItems: "stretch",
889
- gap: "var(--spacing)",
890
- "& > *": {
891
- justifyContent: "start"
892
- }
893
- },
894
- children: [jsxRuntime.jsx("div", {
895
- css: {
896
- marginBottom: "var(--spacing)"
897
- },
898
- children: text.exportTitle
899
- }), jsxRuntime.jsx(Button2, {
900
- startIcon: jsxRuntime.jsx(Clipboard2, {}),
901
- onClick: copy,
902
- children: text.exportCopy
903
- }), jsxRuntime.jsx(Button2, {
904
- startIcon: jsxRuntime.jsx(Export2, {}),
905
- onClick: download,
906
- children: text.exportDownload
907
- })]
908
- })
909
- })]
910
- });
911
- }
912
- const FilterControlContext = react.createContext(() => void 0);
913
- function FilterControl() {
914
- const table = useTableContext();
915
- const columnId = useColumnContext();
916
- const {
917
- components: {
918
- IconButton: IconButton2,
919
- Popover
920
- },
921
- icons: {
922
- FilterList: FilterList2,
923
- ArrowDropDown: ArrowDropDown2
924
- }
925
- } = useTheme();
926
- const cssVariables = useCssVariables();
927
- const [anchor, setAnchor] = react.useState(null);
928
- const isActive = table.useState((state) => {
929
- const filter2 = state.filters.get(columnId);
930
- const filterValue = state.filterValues.get(columnId);
931
- return filter2 !== void 0 && filterValue !== void 0 && filter2.isActive(filterValue);
932
- });
933
- const filter = table.useState((state) => {
934
- var _a;
935
- return (_a = state.activeColumns.find((column) => column.id === columnId)) == null ? void 0 : _a.filter;
936
- });
937
- function reset() {
938
- table.update((state) => {
939
- state.filterValues.delete(columnId);
940
- });
941
- }
942
- const close = react.useCallback(function() {
943
- setAnchor(null);
944
- }, []);
945
- if (!filter)
946
- return null;
947
- return jsxRuntime.jsxs(FilterControlContext.Provider, {
948
- value: close,
949
- children: [jsxRuntime.jsx("div", {
950
- onClick: (e) => setAnchor(e.currentTarget),
951
- onContextMenu: (e) => {
952
- reset();
953
- e.preventDefault();
954
- return false;
955
- },
956
- children: jsxRuntime.jsx(IconButton2, {
957
- css: [{
958
- color: "#b0bac9"
959
- }, isActive && {
960
- color: "var(--primaryMain) !important"
961
- }],
962
- children: isActive ? jsxRuntime.jsx(FilterList2, {}) : jsxRuntime.jsx(ArrowDropDown2, {})
963
- })
964
- }), jsxRuntime.jsx("div", {
965
- onPointerDown: (e) => {
966
- e.stopPropagation();
967
- },
968
- onPointerMove: (e) => {
969
- e.stopPropagation();
970
- },
971
- children: jsxRuntime.jsx(Popover, {
972
- open: true,
973
- hidden: !anchor,
974
- onClose: () => setAnchor(null),
975
- anchorEl: anchor != null ? anchor : document.body,
976
- css: cssVariables,
977
- children: filter
1151
+ }), /* @__PURE__ */ jsxRuntime.jsx(Popover, {
1152
+ open: !!anchor,
1153
+ onClose: () => setAnchor(null),
1154
+ anchorEl: anchor,
1155
+ css: cssVariables,
1156
+ children: /* @__PURE__ */ jsxRuntime.jsxs("div", {
1157
+ css: {
1158
+ padding: `calc(var(--spacing) * 2)`,
1159
+ display: "grid",
1160
+ justifyItems: "stretch",
1161
+ gap: "var(--spacing)",
1162
+ "& > *": {
1163
+ justifyContent: "start"
1164
+ }
1165
+ },
1166
+ children: [/* @__PURE__ */ jsxRuntime.jsx("div", {
1167
+ css: {
1168
+ marginBottom: "var(--spacing)"
1169
+ },
1170
+ children: exportTitle
1171
+ }), /* @__PURE__ */ jsxRuntime.jsx(Button2, {
1172
+ startIcon: /* @__PURE__ */ jsxRuntime.jsx(Clipboard2, {}),
1173
+ onClick: copy,
1174
+ children: exportCopy
1175
+ }), /* @__PURE__ */ jsxRuntime.jsx(Button2, {
1176
+ startIcon: /* @__PURE__ */ jsxRuntime.jsx(Export2, {}),
1177
+ onClick: download,
1178
+ children: exportDownload
1179
+ })]
978
1180
  })
979
1181
  })]
980
1182
  });
981
1183
  }
982
- function ResizeHandle() {
983
- const table = useTableContext();
984
- const columnId = useColumnContext();
985
- const enabled = table.useState("props.enableColumnResize");
986
- function onPointerDown(e) {
987
- e.stopPropagation();
988
- const div = e.target;
989
- div.setPointerCapture(e.pointerId);
990
- }
991
- function onPointerMove(e) {
992
- e.stopPropagation();
993
- const div = e.target;
994
- if (!div.hasPointerCapture(e.pointerId))
995
- return;
996
- const parent = div.parentElement;
997
- const width = Math.max(e.clientX - parent.getBoundingClientRect().left + 5, 50);
998
- table.update((state) => {
999
- state.columnWidths.set(columnId, `${width}px`);
1000
- });
1001
- }
1002
- function onPointerUp(e) {
1003
- e.stopPropagation();
1004
- const div = e.target;
1005
- div.releasePointerCapture(e.pointerId);
1006
- }
1007
- function onDoubleClick(e) {
1008
- table.update((state) => {
1009
- if (e.getModifierState("Control")) {
1010
- state.columnWidths.delete(columnId);
1011
- } else {
1012
- state.columnWidths.set(columnId, "max-content");
1013
- }
1184
+ const defaultWrapCell = (content) => {
1185
+ if (typeof content === "string") {
1186
+ return /* @__PURE__ */ jsxRuntime.jsx("span", {
1187
+ css: tableTheme.defaultClasses.text,
1188
+ title: content,
1189
+ children: content
1014
1190
  });
1015
1191
  }
1016
- return jsxRuntime.jsx(ResizeHandleView, {
1017
- enabled,
1018
- onPointerDown: enabled ? onPointerDown : void 0,
1019
- onPointerMove: enabled ? onPointerMove : void 0,
1020
- onPointerUp: enabled ? onPointerUp : void 0,
1021
- onDoubleClick: enabled ? onDoubleClick : void 0
1022
- });
1023
- }
1024
- function ResizeHandleView(_a) {
1025
- var _b = _a, {
1026
- enabled
1027
- } = _b, props = __objRest(_b, [
1028
- "enabled"
1029
- ]);
1030
- return jsxRuntime.jsx("div", __spreadValues({
1031
- css: {
1032
- alignSelf: "stretch",
1033
- padding: "0 5px",
1034
- cursor: enabled ? "col-resize" : "initial",
1035
- display: "flex",
1036
- alignItems: "center",
1037
- "&:after": {
1038
- content: '""',
1039
- width: 1,
1040
- height: "1.5em",
1041
- background: "#c9cfda",
1042
- transition: "transform 300ms"
1043
- }
1044
- }
1045
- }, props));
1046
- }
1192
+ return content;
1193
+ };
1047
1194
  const Cell = react.memo(function Cell2({
1048
1195
  itemId,
1049
1196
  rowIndex
1050
1197
  }) {
1051
- var _a, _b;
1198
+ var _a;
1052
1199
  const table = useTableContext();
1053
1200
  const columnId = useColumnContext();
1054
- const {
1055
- classes
1056
- } = useTheme();
1057
- const column = table.useState((state) => state.activeColumns.find((column2) => column2.id === columnId));
1201
+ const column = table.useState((state) => {
1202
+ const col = state.activeColumns.find((column2) => column2.id === columnId);
1203
+ return col && {
1204
+ value: col.value,
1205
+ renderCell: col.renderCell
1206
+ };
1207
+ });
1208
+ const wrapCell = (_a = table.useState((state) => state.props.wrapCell)) != null ? _a : defaultWrapCell;
1058
1209
  const item = table.useState((state) => state.activeItemsById.get(itemId));
1059
1210
  const columnStyleOverride = table.useState((state) => state.columnStyleOverride.get(columnId), {
1060
1211
  throttle: 16
1061
1212
  });
1213
+ react.useLayoutEffect(() => {
1214
+ var _a2, _b;
1215
+ return (_b = (_a2 = table.getState().props).debugRender) == null ? void 0 : _b.call(_a2, "render cell", itemId, columnId);
1216
+ });
1217
+ const className2 = useTheme((t) => cx(...calcClassNames(t.classes, item, rowIndex)));
1062
1218
  if (!column || !item)
1063
1219
  return null;
1064
- (_b = (_a = table.getState().props).debugRender) == null ? void 0 : _b.call(_a, "render cell", itemId, columnId);
1065
- const classNames = [...calcClassNames(classes, item, rowIndex), ...calcClassNames(column == null ? void 0 : column.classes, item, rowIndex)];
1066
- const content = column.renderCell(column.value(item), item);
1067
- return jsxRuntime.jsx("div", {
1068
- className: cx(...classNames),
1069
- css: [tableTheme.defaultClasses.cell, classNames, columnStyleOverride],
1070
- children: typeof content === "string" ? jsxRuntime.jsx("span", {
1071
- css: tableTheme.defaultClasses.text,
1072
- title: content,
1073
- children: content
1074
- }) : content
1220
+ const content = column.renderCell(column.value(item.value), item.value);
1221
+ return /* @__PURE__ */ jsxRuntime.jsx("div", {
1222
+ className: className2,
1223
+ css: [tableTheme.defaultClasses.cell, columnStyleOverride],
1224
+ children: wrapCell(content, column.value(item.value), item.value, rowIndex)
1075
1225
  });
1076
1226
  });
1077
1227
  function ExpandControl({
1078
1228
  itemId,
1079
1229
  hasDeferredChildren
1080
1230
  }) {
1081
- const {
1082
- components: {
1083
- IconButton: IconButton2,
1084
- Spinner: Spinner2
1085
- },
1086
- icons: {
1087
- ChevronRight: ChevronRight2
1088
- }
1089
- } = useTheme();
1231
+ const IconButton2 = useTheme((t) => t.components.IconButton);
1232
+ const Spinner2 = useTheme((t) => t.components.Spinner);
1233
+ const ChevronRight2 = useTheme((t) => t.icons.ChevronRight);
1090
1234
  const table = useTableContext();
1091
1235
  const isExpanded = table.useState((state) => state.expanded.has(itemId));
1092
1236
  const hasChildren = table.useState((state) => {
@@ -1123,21 +1267,21 @@ function ExpandControl({
1123
1267
  }
1124
1268
  }
1125
1269
  if (isExpanded && hasDeferredChildren && !hasChildren) {
1126
- return jsxRuntime.jsx(Spinner2, {
1270
+ return /* @__PURE__ */ jsxRuntime.jsx(Spinner2, {
1127
1271
  css: {
1128
1272
  margin: "0 var(--spacing)"
1129
1273
  }
1130
1274
  });
1131
1275
  }
1132
- return jsxRuntime.jsx(IconButton2, {
1276
+ return /* @__PURE__ */ jsxRuntime.jsx(IconButton2, {
1133
1277
  onClick: toggle2,
1134
- children: jsxRuntime.jsx("span", {
1278
+ children: /* @__PURE__ */ jsxRuntime.jsx("span", {
1135
1279
  css: {
1136
1280
  display: "inline-flex",
1137
1281
  transition: "all 300ms",
1138
1282
  transform: isExpanded ? "rotate3d(0, 0, 1, 90deg)" : "rotate3d(0, 0, 1, 0deg)"
1139
1283
  },
1140
- children: jsxRuntime.jsx(ChevronRight2, {})
1284
+ children: /* @__PURE__ */ jsxRuntime.jsx(ChevronRight2, {})
1141
1285
  })
1142
1286
  });
1143
1287
  }
@@ -1145,11 +1289,7 @@ function SelectComponent({
1145
1289
  itemId
1146
1290
  }) {
1147
1291
  const table = useTableContext();
1148
- const {
1149
- components: {
1150
- Checkbox: Checkbox2
1151
- }
1152
- } = useTheme();
1292
+ const Checkbox2 = useTheme((t) => t.components.Checkbox);
1153
1293
  const isSelected = table.useState((state) => {
1154
1294
  const itemIds = itemId ? [itemId] : Array.from(state.activeItemsById.keys());
1155
1295
  return state.activeItemsById.size > 0 && itemIds.every((itemId2) => state.selection.has(itemId2));
@@ -1201,7 +1341,7 @@ function SelectComponent({
1201
1341
  state.lastSelectedId = itemId;
1202
1342
  });
1203
1343
  }
1204
- return jsxRuntime.jsx(Checkbox2, {
1344
+ return /* @__PURE__ */ jsxRuntime.jsx(Checkbox2, {
1205
1345
  css: {
1206
1346
  justifySelf: "start",
1207
1347
  color: "#c9cfda"
@@ -1217,9 +1357,9 @@ const Row = react.memo(function Row2({
1217
1357
  itemId,
1218
1358
  rowIndex
1219
1359
  }) {
1220
- var _a, _b;
1221
1360
  const table = useTableContext();
1222
1361
  const divRef = react.useRef(null);
1362
+ const classes = useTheme((t) => t.classes);
1223
1363
  const {
1224
1364
  className: className2,
1225
1365
  indent,
@@ -1229,17 +1369,16 @@ const Row = react.memo(function Row2({
1229
1369
  enableSelection,
1230
1370
  rowAction
1231
1371
  } = table.useState((state) => {
1232
- var _a2, _b2;
1372
+ var _a, _b;
1233
1373
  const item = state.activeItemsById.get(itemId);
1234
- const index = !item ? -1 : state.activeItems.indexOf(item);
1235
1374
  return {
1236
- className: cx(...calcClassNames(state.props.classes, item, index)),
1375
+ className: cx(...calcClassNames(classes, item, rowIndex)),
1237
1376
  indent: item ? getAncestors(state.activeItemsById, item).size : 0,
1238
1377
  hasChildren: !!(item == null ? void 0 : item.children.length),
1239
- hasDeferredChildren: item && ((_b2 = (_a2 = state.props).hasDeferredChildren) == null ? void 0 : _b2.call(_a2, item)),
1378
+ hasDeferredChildren: item && ((_b = (_a = state.props).hasDeferredChildren) == null ? void 0 : _b.call(_a, item.value)),
1240
1379
  columnIds: state.activeColumns.map((column) => column.id),
1241
1380
  enableSelection: state.props.enableSelection,
1242
- rowAction: state.props.rowAction instanceof Function ? item ? state.props.rowAction(item, index) : null : state.props.rowAction
1381
+ rowAction: state.props.rowAction instanceof Function ? item ? state.props.rowAction(item.value, rowIndex) : null : state.props.rowAction
1243
1382
  };
1244
1383
  });
1245
1384
  react.useEffect(() => {
@@ -1256,117 +1395,40 @@ const Row = react.memo(function Row2({
1256
1395
  o.observe(div);
1257
1396
  return () => o.disconnect();
1258
1397
  }, [divRef.current]);
1259
- (_b = (_a = table.getState().props).debugRender) == null ? void 0 : _b.call(_a, "render row", itemId);
1260
- return jsxRuntime.jsxs(jsxRuntime.Fragment, {
1261
- children: [jsxRuntime.jsx("div", {
1398
+ react.useLayoutEffect(() => {
1399
+ var _a, _b;
1400
+ return (_b = (_a = table.getState().props).debugRender) == null ? void 0 : _b.call(_a, "render row", itemId);
1401
+ });
1402
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, {
1403
+ children: [/* @__PURE__ */ jsxRuntime.jsx("div", {
1262
1404
  className: className2,
1263
1405
  css: [tableTheme.defaultClasses.cellFill],
1264
1406
  ref: divRef
1265
- }), jsxRuntime.jsxs("div", {
1407
+ }), /* @__PURE__ */ jsxRuntime.jsxs("div", {
1266
1408
  className: className2,
1267
1409
  css: [tableTheme.defaultClasses.cell, tableTheme.defaultClasses.firstCell],
1268
- children: [jsxRuntime.jsx("div", {
1410
+ children: [/* @__PURE__ */ jsxRuntime.jsx("div", {
1269
1411
  css: {
1270
1412
  width: indent * 20
1271
1413
  }
1272
- }), enableSelection && jsxRuntime.jsx(SelectComponent, {
1414
+ }), enableSelection && /* @__PURE__ */ jsxRuntime.jsx(SelectComponent, {
1273
1415
  itemId
1274
- }), (hasChildren || hasDeferredChildren) && jsxRuntime.jsx(ExpandControl, {
1416
+ }), (hasChildren || hasDeferredChildren) && /* @__PURE__ */ jsxRuntime.jsx(ExpandControl, {
1275
1417
  itemId,
1276
1418
  hasDeferredChildren
1277
1419
  }), rowAction]
1278
- }), columnIds.map((columnId) => jsxRuntime.jsx(ColumnContext.Provider, {
1420
+ }), columnIds.map((columnId) => /* @__PURE__ */ jsxRuntime.jsx(ColumnContext.Provider, {
1279
1421
  value: columnId,
1280
- children: jsxRuntime.jsx(Cell, {
1422
+ children: /* @__PURE__ */ jsxRuntime.jsx(Cell, {
1281
1423
  itemId,
1282
1424
  rowIndex
1283
1425
  })
1284
- }, columnId)), jsxRuntime.jsx("div", {
1426
+ }, columnId)), /* @__PURE__ */ jsxRuntime.jsx("div", {
1285
1427
  className: className2,
1286
1428
  css: [tableTheme.defaultClasses.cellFill]
1287
1429
  })]
1288
1430
  });
1289
1431
  });
1290
- function SortComponent({
1291
- children
1292
- }) {
1293
- const table = useTableContext();
1294
- const columnId = useColumnContext();
1295
- const {
1296
- components: {
1297
- Badge: Badge2
1298
- },
1299
- icons: {
1300
- ArrowUpward: ArrowUpward2
1301
- }
1302
- } = useTheme();
1303
- const {
1304
- direction,
1305
- index
1306
- } = table.useState((state) => {
1307
- var _a, _b;
1308
- const index2 = (_a = state.sort.findIndex((s) => s.columnId === columnId)) != null ? _a : -1;
1309
- return {
1310
- direction: (_b = state.sort[index2]) == null ? void 0 : _b.direction,
1311
- index: index2 >= 0 && state.sort.length > 1 ? index2 + 1 : void 0
1312
- };
1313
- });
1314
- function toggle2(e, off) {
1315
- const {
1316
- props: {
1317
- sort: controlledSort,
1318
- onSortChange
1319
- }
1320
- } = table.getState();
1321
- const newDirection = direction === "asc" ? "desc" : "asc";
1322
- const newSort = e.getModifierState("Control") || off ? table.getState().sort.filter((s) => s.columnId !== columnId) : [];
1323
- if (!off) {
1324
- newSort.push({
1325
- columnId,
1326
- direction: newDirection
1327
- });
1328
- }
1329
- onSortChange == null ? void 0 : onSortChange(newSort);
1330
- if (!controlledSort) {
1331
- table.update((state) => {
1332
- state.sort = newSort;
1333
- });
1334
- }
1335
- e.preventDefault();
1336
- return false;
1337
- }
1338
- return jsxRuntime.jsxs("div", {
1339
- css: {
1340
- userSelect: "none",
1341
- display: "grid",
1342
- gridTemplateColumns: "minmax(0, 1fr) max-content",
1343
- alignItems: "center",
1344
- cursor: "pointer",
1345
- "& > div": {
1346
- overflow: "hidden",
1347
- textOverflow: "ellipsis"
1348
- }
1349
- },
1350
- onClick: (e) => toggle2(e),
1351
- onContextMenu: (e) => toggle2(e, true),
1352
- children: [jsxRuntime.jsx("div", {
1353
- children
1354
- }), jsxRuntime.jsx(Badge2, {
1355
- badgeContent: index,
1356
- children: jsxRuntime.jsx("span", {
1357
- css: [{
1358
- transition: "all 300ms",
1359
- fontSize: "0.8em"
1360
- }, !direction && {
1361
- opacity: 0
1362
- }, direction === "desc" && {
1363
- transform: "rotate3d(0, 0, 1, 180deg)"
1364
- }],
1365
- children: jsxRuntime.jsx(ArrowUpward2, {})
1366
- })
1367
- })]
1368
- });
1369
- }
1370
1432
  function throttle(fn, ms) {
1371
1433
  let last = 0;
1372
1434
  let lastArgs;
@@ -1393,6 +1455,11 @@ function throttle(fn, ms) {
1393
1455
  if (lastArgs) {
1394
1456
  run();
1395
1457
  }
1458
+ },
1459
+ cancel() {
1460
+ if (timeout) {
1461
+ clearTimeout(timeout);
1462
+ }
1396
1463
  }
1397
1464
  });
1398
1465
  }
@@ -1414,12 +1481,14 @@ const relativeOffset = (x, y) => {
1414
1481
  function Virtualized(_c) {
1415
1482
  var _d = _c, {
1416
1483
  header,
1484
+ footer,
1417
1485
  children
1418
1486
  } = _d, props = __objRest(_d, [
1419
1487
  "header",
1488
+ "footer",
1420
1489
  "children"
1421
1490
  ]);
1422
- var _a, _b, _c2, _d2;
1491
+ var _a, _b;
1423
1492
  const table = useTableContext();
1424
1493
  const virtual = table.useState("props.virtual");
1425
1494
  const probeRef = react.useRef(null);
@@ -1493,20 +1562,24 @@ function Virtualized(_c) {
1493
1562
  window.removeEventListener("resize", incCounter, true);
1494
1563
  };
1495
1564
  }, [probeRef.current, incCounter]);
1496
- (_d2 = (_c2 = table.getState().props).debugRender) == null ? void 0 : _d2.call(_c2, `Virtualalized render ${from} to ${to}`);
1497
- return jsxRuntime.jsxs("div", __spreadProps(__spreadValues({}, props), {
1498
- children: [header, virtual && jsxRuntime.jsx("div", {
1565
+ react.useEffect(() => incCounter.cancel, [incCounter]);
1566
+ react.useLayoutEffect(() => {
1567
+ var _a2, _b2;
1568
+ return (_b2 = (_a2 = table.getState().props).debugRender) == null ? void 0 : _b2.call(_a2, `Virtualalized render ${from} to ${to}`);
1569
+ });
1570
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", __spreadProps(__spreadValues({}, props), {
1571
+ children: [header, virtual && /* @__PURE__ */ jsxRuntime.jsx("div", {
1499
1572
  style: {
1500
1573
  gridColumn: "1 / -1",
1501
1574
  height: before
1502
1575
  },
1503
1576
  ref: probeRef
1504
- }), children(itemIds, from), virtual && jsxRuntime.jsx("div", {
1577
+ }), children(itemIds, from), virtual && /* @__PURE__ */ jsxRuntime.jsx("div", {
1505
1578
  style: {
1506
1579
  gridColumn: "1 / -1",
1507
1580
  height: after
1508
1581
  }
1509
- })]
1582
+ }), footer]
1510
1583
  }));
1511
1584
  }
1512
1585
  const TableContext = react.createContext(null);
@@ -1524,28 +1597,30 @@ function useColumnContext() {
1524
1597
  return value;
1525
1598
  }
1526
1599
  function Table(props) {
1527
- var _a, _b;
1528
1600
  const table = useTableState(props);
1529
- (_b = (_a = table.getState().props).debugRender) == null ? void 0 : _b.call(_a, "render table");
1530
- return jsxRuntime.jsx(TableContext.Provider, {
1601
+ react.useLayoutEffect(() => {
1602
+ var _a, _b;
1603
+ return (_b = (_a = table.getState().props).debugRender) == null ? void 0 : _b.call(_a, "render table");
1604
+ });
1605
+ return /* @__PURE__ */ jsxRuntime.jsx(TableContext.Provider, {
1531
1606
  value: table,
1532
- children: jsxRuntime.jsx(TableLoadingState, {})
1607
+ children: /* @__PURE__ */ jsxRuntime.jsx(TableMemoContextProvider, {
1608
+ children: /* @__PURE__ */ jsxRuntime.jsx(TableLoadingState, {})
1609
+ })
1533
1610
  });
1534
1611
  }
1535
1612
  function TableLoadingState() {
1536
- const {
1537
- text
1538
- } = useTheme();
1613
+ const loadingText = useTheme((t) => t.text.loading);
1539
1614
  const isHydrated = useTableStateStorage();
1540
1615
  const [showLoading, setShowLoading] = react.useState(false);
1541
1616
  react.useEffect(() => {
1542
1617
  const handle = setTimeout(() => setShowLoading(true), 500);
1543
1618
  return () => clearTimeout(handle);
1544
1619
  });
1545
- return jsxRuntime.jsxs(jsxRuntime.Fragment, {
1546
- children: [!isHydrated && showLoading && jsxRuntime.jsx("div", {
1547
- children: text.loading
1548
- }), jsxRuntime.jsx(TableInner, {
1620
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, {
1621
+ children: [!isHydrated && showLoading && /* @__PURE__ */ jsxRuntime.jsx("div", {
1622
+ children: loadingText
1623
+ }), /* @__PURE__ */ jsxRuntime.jsx(TableInner, {
1549
1624
  hidden: !isHydrated
1550
1625
  })]
1551
1626
  });
@@ -1553,76 +1628,77 @@ function TableLoadingState() {
1553
1628
  const TableInner = react.memo(function TableInner2({
1554
1629
  hidden
1555
1630
  }) {
1556
- var _a, _b;
1557
1631
  const table = useTableContext();
1558
1632
  const fullWidth = table.useState("props.fullWidth");
1559
1633
  const activeColumns = table.useState((state) => state.activeColumns.map((column) => ({
1560
1634
  id: column.id,
1561
1635
  width: column.width,
1562
- classes: column.classes,
1563
- header: column.header
1636
+ classes: column.classes
1564
1637
  })));
1565
1638
  const columnWidths = table.useState("columnWidths", {
1566
1639
  throttle: 16
1567
1640
  });
1568
- const columnStyleOverride = table.useState("columnStyleOverride", {
1569
- throttle: 16
1570
- });
1571
- const defaultWidth = table.useState("props.defaultWidth");
1572
- const classes = table.useState("props.classes");
1641
+ const hasFooter = table.useState((state) => state.activeColumns.some((column) => column.footer));
1642
+ const classes = useTheme((theme) => theme.classes);
1573
1643
  const stickyHeader = table.useState("props.stickyHeader");
1644
+ const stickyFooter = table.useState("props.stickyFooter");
1574
1645
  const enableSelection = table.useState("props.enableSelection");
1575
1646
  const enableColumnSelection = table.useState("props.enableColumnSelection");
1576
1647
  const enableExport = table.useState((state) => !!state.props.enableExport.copy || !!state.props.enableExport.download);
1577
1648
  const cssVariables = useCssVariables();
1578
- (_b = (_a = table.getState().props).debugRender) == null ? void 0 : _b.call(_a, "render table inner");
1579
- return jsxRuntime.jsx(Virtualized, {
1649
+ react.useLayoutEffect(() => {
1650
+ var _a, _b;
1651
+ return (_b = (_a = table.getState().props).debugRender) == null ? void 0 : _b.call(_a, "render table inner");
1652
+ });
1653
+ return /* @__PURE__ */ jsxRuntime.jsx(Virtualized, {
1580
1654
  className: classes == null ? void 0 : classes.table,
1581
1655
  css: [cssVariables, tableTheme.defaultClasses.table, {
1582
1656
  gridTemplateColumns: [
1583
1657
  fullWidth === "right" || fullWidth === true ? "auto" : "0",
1584
1658
  "max-content",
1585
1659
  ...activeColumns.map((column) => {
1586
- var _a2, _b2, _c;
1587
- return (_c = (_b2 = (_a2 = columnWidths.get(column.id)) != null ? _a2 : column.width) != null ? _b2 : defaultWidth) != null ? _c : "max-content";
1660
+ var _a, _b;
1661
+ return (_b = (_a = columnWidths.get(column.id)) != null ? _a : column.width) != null ? _b : "max-content";
1588
1662
  }),
1589
1663
  fullWidth === "left" || fullWidth === true ? "auto" : "0"
1590
1664
  ].join(" ")
1591
1665
  }, hidden && {
1592
1666
  visibility: "hidden"
1593
1667
  }],
1594
- header: jsxRuntime.jsxs(jsxRuntime.Fragment, {
1595
- children: [jsxRuntime.jsx("div", {
1668
+ header: /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, {
1669
+ children: [/* @__PURE__ */ jsxRuntime.jsx("div", {
1596
1670
  className: classes == null ? void 0 : classes.headerCell,
1597
1671
  css: [tableTheme.defaultClasses.headerFill, stickyHeader && tableTheme.defaultClasses.sticky, stickyHeader instanceof Object && stickyHeader]
1598
- }), jsxRuntime.jsxs("div", {
1672
+ }), /* @__PURE__ */ jsxRuntime.jsxs("div", {
1599
1673
  className: classes == null ? void 0 : classes.headerCell,
1600
1674
  css: [tableTheme.defaultClasses.headerCell, stickyHeader && tableTheme.defaultClasses.sticky, stickyHeader instanceof Object && stickyHeader],
1601
- children: [enableSelection && jsxRuntime.jsx(SelectComponent, {}), enableColumnSelection && jsxRuntime.jsx(ColumnSelection, {}), enableExport && jsxRuntime.jsx(Export$1, {}), jsxRuntime.jsx(ResizeHandleView, {})]
1602
- }), jsxRuntime.jsx(ColumnHeaderContext.Provider, {
1603
- children: activeColumns.map((column) => {
1604
- var _a2;
1605
- return jsxRuntime.jsx(ColumnContext.Provider, {
1606
- value: column.id,
1607
- children: jsxRuntime.jsxs(ColumnHeader, {
1608
- className: cx(classes == null ? void 0 : classes.headerCell, (_a2 = column.classes) == null ? void 0 : _a2.headerCell),
1609
- css: [tableTheme.defaultClasses.headerCell, columnStyleOverride.get(column.id), stickyHeader && tableTheme.defaultClasses.sticky, stickyHeader instanceof Object && stickyHeader],
1610
- children: [jsxRuntime.jsx(SortComponent, {
1611
- children: column.header
1612
- }), jsxRuntime.jsx("div", {
1613
- css: {
1614
- flex: 1
1615
- }
1616
- }), jsxRuntime.jsx(FilterControl, {}), jsxRuntime.jsx(ResizeHandle, {})]
1617
- }, column.id)
1618
- }, column.id);
1619
- })
1620
- }), jsxRuntime.jsx("div", {
1675
+ children: [enableSelection && /* @__PURE__ */ jsxRuntime.jsx(SelectComponent, {}), enableColumnSelection && /* @__PURE__ */ jsxRuntime.jsx(ColumnSelection, {}), enableExport && /* @__PURE__ */ jsxRuntime.jsx(Export$1, {}), /* @__PURE__ */ jsxRuntime.jsx(ResizeHandleView, {})]
1676
+ }), /* @__PURE__ */ jsxRuntime.jsx(ColumnHeaderContext.Provider, {
1677
+ children: activeColumns.map((column) => /* @__PURE__ */ jsxRuntime.jsx(ColumnContext.Provider, {
1678
+ value: column.id,
1679
+ children: /* @__PURE__ */ jsxRuntime.jsx(ColumnHeader, {})
1680
+ }, column.id))
1681
+ }), /* @__PURE__ */ jsxRuntime.jsx("div", {
1621
1682
  className: classes == null ? void 0 : classes.headerCell,
1622
1683
  css: [tableTheme.defaultClasses.headerFill, stickyHeader && tableTheme.defaultClasses.sticky, stickyHeader instanceof Object && stickyHeader]
1623
1684
  })]
1624
1685
  }),
1625
- children: (itemIds, startIndex) => itemIds.map((itemId, index) => jsxRuntime.jsx(Row, {
1686
+ footer: hasFooter && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, {
1687
+ children: [/* @__PURE__ */ jsxRuntime.jsx("div", {
1688
+ className: classes == null ? void 0 : classes.footerCell,
1689
+ css: [tableTheme.defaultClasses.footerFill, stickyFooter && tableTheme.defaultClasses.stickyBottom, stickyFooter instanceof Object && stickyFooter]
1690
+ }), /* @__PURE__ */ jsxRuntime.jsx("div", {
1691
+ className: classes == null ? void 0 : classes.footerCell,
1692
+ css: [tableTheme.defaultClasses.footerFill, stickyFooter && tableTheme.defaultClasses.stickyBottom, stickyFooter instanceof Object && stickyFooter]
1693
+ }), activeColumns.map((column) => /* @__PURE__ */ jsxRuntime.jsx(ColumnContext.Provider, {
1694
+ value: column.id,
1695
+ children: /* @__PURE__ */ jsxRuntime.jsx(ColumnFooter, {})
1696
+ }, column.id)), /* @__PURE__ */ jsxRuntime.jsx("div", {
1697
+ className: classes == null ? void 0 : classes.footerCell,
1698
+ css: [tableTheme.defaultClasses.footerFill, stickyFooter && tableTheme.defaultClasses.stickyBottom, stickyFooter instanceof Object && stickyFooter]
1699
+ })]
1700
+ }),
1701
+ children: (itemIds, startIndex) => itemIds.map((itemId, index) => /* @__PURE__ */ jsxRuntime.jsx(Row, {
1626
1702
  itemId,
1627
1703
  rowIndex: startIndex + index
1628
1704
  }, itemId))
@@ -1635,7 +1711,7 @@ const defaultColors = {
1635
1711
  function Spinner({
1636
1712
  className: className2
1637
1713
  }) {
1638
- return jsxRuntime.jsxs("div", {
1714
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", {
1639
1715
  className: className2,
1640
1716
  css: react$2.css`
1641
1717
  display: inline-block;
@@ -1673,7 +1749,7 @@ function Spinner({
1673
1749
  }
1674
1750
  }
1675
1751
  `,
1676
- children: [jsxRuntime.jsx("div", {}), jsxRuntime.jsx("div", {}), jsxRuntime.jsx("div", {})]
1752
+ children: [/* @__PURE__ */ jsxRuntime.jsx("div", {}), /* @__PURE__ */ jsxRuntime.jsx("div", {}), /* @__PURE__ */ jsxRuntime.jsx("div", {})]
1677
1753
  });
1678
1754
  }
1679
1755
  const Badge = ({
@@ -1682,14 +1758,14 @@ const Badge = ({
1682
1758
  }) => {
1683
1759
  if (!open)
1684
1760
  return null;
1685
- return jsxRuntime.jsxs("span", {
1761
+ return /* @__PURE__ */ jsxRuntime.jsxs("span", {
1686
1762
  css: {
1687
1763
  display: "inline-flex",
1688
1764
  position: "relative",
1689
1765
  flexShrink: 0,
1690
1766
  verticalAlign: "middle"
1691
1767
  },
1692
- children: [children, jsxRuntime.jsx("span", {
1768
+ children: [children, /* @__PURE__ */ jsxRuntime.jsx("span", {
1693
1769
  css: [{
1694
1770
  top: 0,
1695
1771
  right: 0,
@@ -1727,7 +1803,7 @@ const Button = (_e) => {
1727
1803
  "children",
1728
1804
  "variant"
1729
1805
  ]);
1730
- return jsxRuntime.jsxs("button", __spreadProps(__spreadValues({
1806
+ return /* @__PURE__ */ jsxRuntime.jsxs("button", __spreadProps(__spreadValues({
1731
1807
  css: [{
1732
1808
  padding: `var(--spacing) calc(var(--spacing) * 2)`,
1733
1809
  display: "inline-flex",
@@ -1762,12 +1838,12 @@ const Button = (_e) => {
1762
1838
  }
1763
1839
  }]
1764
1840
  }, props), {
1765
- children: [startIcon && jsxRuntime.jsx("span", {
1841
+ children: [startIcon && /* @__PURE__ */ jsxRuntime.jsx("span", {
1766
1842
  css: {
1767
1843
  marginRight: `calc(var(--spacing) * 2)`
1768
1844
  },
1769
1845
  children: startIcon
1770
- }), jsxRuntime.jsx("span", {
1846
+ }), /* @__PURE__ */ jsxRuntime.jsx("span", {
1771
1847
  children
1772
1848
  })]
1773
1849
  }));
@@ -1778,7 +1854,7 @@ const Checkbox = (_g) => {
1778
1854
  } = _h, props = __objRest(_h, [
1779
1855
  "className"
1780
1856
  ]);
1781
- return jsxRuntime.jsxs("label", {
1857
+ return /* @__PURE__ */ jsxRuntime.jsxs("label", {
1782
1858
  css: [{
1783
1859
  padding: "calc(var(--spacing) * 1.8)",
1784
1860
  display: "flex",
@@ -1792,9 +1868,9 @@ const Checkbox = (_g) => {
1792
1868
  color: "rgba(0, 0, 0, 0.26)"
1793
1869
  }],
1794
1870
  className: className2,
1795
- children: [jsxRuntime.jsx("input", __spreadValues({
1871
+ children: [/* @__PURE__ */ jsxRuntime.jsx("input", __spreadValues({
1796
1872
  type: "checkbox"
1797
- }, props)), props.checked ? jsxRuntime.jsx("svg", {
1873
+ }, props)), props.checked ? /* @__PURE__ */ jsxRuntime.jsx("svg", {
1798
1874
  css: {
1799
1875
  fontSize: "1.25rem",
1800
1876
  width: "1em",
@@ -1804,10 +1880,10 @@ const Checkbox = (_g) => {
1804
1880
  focusable: "false",
1805
1881
  viewBox: "0 0 24 24",
1806
1882
  "aria-hidden": "true",
1807
- children: jsxRuntime.jsx("path", {
1883
+ children: /* @__PURE__ */ jsxRuntime.jsx("path", {
1808
1884
  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"
1809
1885
  })
1810
- }) : jsxRuntime.jsx("svg", {
1886
+ }) : /* @__PURE__ */ jsxRuntime.jsx("svg", {
1811
1887
  css: {
1812
1888
  fontSize: "1.25rem",
1813
1889
  width: "1em",
@@ -1817,14 +1893,14 @@ const Checkbox = (_g) => {
1817
1893
  focusable: "false",
1818
1894
  viewBox: "0 0 24 24",
1819
1895
  "aria-hidden": "true",
1820
- children: jsxRuntime.jsx("path", {
1896
+ children: /* @__PURE__ */ jsxRuntime.jsx("path", {
1821
1897
  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"
1822
1898
  })
1823
1899
  })]
1824
1900
  });
1825
1901
  };
1826
1902
  const IconButton = (props) => {
1827
- return jsxRuntime.jsx("button", __spreadValues({
1903
+ return /* @__PURE__ */ jsxRuntime.jsx("button", __spreadValues({
1828
1904
  css: {
1829
1905
  padding: "var(--spacing)",
1830
1906
  borderRadius: "50%",
@@ -1857,12 +1933,12 @@ const TextField = (_i) => {
1857
1933
  ]);
1858
1934
  var _a;
1859
1935
  const [focus, setFocus] = react.useState(false);
1860
- return jsxRuntime.jsx("div", {
1936
+ return /* @__PURE__ */ jsxRuntime.jsx("div", {
1861
1937
  className: className2,
1862
1938
  css: {
1863
1939
  display: "flex"
1864
1940
  },
1865
- children: jsxRuntime.jsxs("span", {
1941
+ children: /* @__PURE__ */ jsxRuntime.jsxs("span", {
1866
1942
  css: [{
1867
1943
  flex: 1,
1868
1944
  display: "flex",
@@ -1873,7 +1949,7 @@ const TextField = (_i) => {
1873
1949
  border: "2px solid var(--primaryMain)",
1874
1950
  margin: -1
1875
1951
  }],
1876
- children: [jsxRuntime.jsx("input", __spreadProps(__spreadValues({
1952
+ children: [/* @__PURE__ */ jsxRuntime.jsx("input", __spreadProps(__spreadValues({
1877
1953
  ref: inputRef
1878
1954
  }, props), {
1879
1955
  value: (_a = props.value) != null ? _a : "",
@@ -1907,7 +1983,7 @@ const IconDefaultStyle = react$2.css({
1907
1983
  color: "inherit"
1908
1984
  });
1909
1985
  function Icon(svg) {
1910
- return (props) => jsxRuntime.jsx(react$2.ClassNames, {
1986
+ return (props) => /* @__PURE__ */ jsxRuntime.jsx(react$2.ClassNames, {
1911
1987
  children: ({
1912
1988
  css: css2
1913
1989
  }) => react.cloneElement(svg, __spreadProps(__spreadValues({}, props), {
@@ -1915,120 +1991,120 @@ function Icon(svg) {
1915
1991
  }))
1916
1992
  });
1917
1993
  }
1918
- const Settings = Icon(jsxRuntime.jsxs("svg", {
1994
+ const Settings = Icon(/* @__PURE__ */ jsxRuntime.jsxs("svg", {
1919
1995
  xmlns: "http://www.w3.org/2000/svg",
1920
1996
  height: "24px",
1921
1997
  viewBox: "0 0 24 24",
1922
1998
  width: "24px",
1923
1999
  fill: "currentColor",
1924
- children: [jsxRuntime.jsx("path", {
2000
+ children: [/* @__PURE__ */ jsxRuntime.jsx("path", {
1925
2001
  d: "M0 0h24v24H0V0z",
1926
2002
  fill: "none"
1927
- }), jsxRuntime.jsx("path", {
2003
+ }), /* @__PURE__ */ jsxRuntime.jsx("path", {
1928
2004
  d: "M3 17v2h6v-2H3zM3 5v2h10V5H3zm10 16v-2h8v-2h-8v-2h-2v6h2zM7 9v2H3v2h4v2h2V9H7zm14 4v-2H11v2h10zm-6-4h2V7h4V5h-4V3h-2v6z"
1929
2005
  })]
1930
2006
  }));
1931
- const Export = Icon(jsxRuntime.jsxs("svg", {
2007
+ const Export = Icon(/* @__PURE__ */ jsxRuntime.jsxs("svg", {
1932
2008
  xmlns: "http://www.w3.org/2000/svg",
1933
2009
  enableBackground: "new 0 0 24 24",
1934
2010
  height: "24px",
1935
2011
  viewBox: "0 0 24 24",
1936
2012
  width: "24px",
1937
2013
  fill: "currentColor",
1938
- children: [jsxRuntime.jsx("g", {
1939
- children: jsxRuntime.jsx("rect", {
2014
+ children: [/* @__PURE__ */ jsxRuntime.jsx("g", {
2015
+ children: /* @__PURE__ */ jsxRuntime.jsx("rect", {
1940
2016
  fill: "none",
1941
2017
  height: "24",
1942
2018
  width: "24"
1943
2019
  })
1944
- }), jsxRuntime.jsx("g", {
1945
- children: jsxRuntime.jsx("path", {
2020
+ }), /* @__PURE__ */ jsxRuntime.jsx("g", {
2021
+ children: /* @__PURE__ */ jsxRuntime.jsx("path", {
1946
2022
  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"
1947
2023
  })
1948
2024
  })]
1949
2025
  }));
1950
- const Clipboard = Icon(jsxRuntime.jsxs("svg", {
2026
+ const Clipboard = Icon(/* @__PURE__ */ jsxRuntime.jsxs("svg", {
1951
2027
  xmlns: "http://www.w3.org/2000/svg",
1952
2028
  height: "24px",
1953
2029
  viewBox: "0 0 24 24",
1954
2030
  width: "24px",
1955
2031
  fill: "currentColor",
1956
- children: [jsxRuntime.jsx("path", {
2032
+ children: [/* @__PURE__ */ jsxRuntime.jsx("path", {
1957
2033
  d: "M0 0h24v24H0V0z",
1958
2034
  fill: "none"
1959
- }), jsxRuntime.jsx("path", {
2035
+ }), /* @__PURE__ */ jsxRuntime.jsx("path", {
1960
2036
  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"
1961
2037
  })]
1962
2038
  }));
1963
- const ChevronRight = Icon(jsxRuntime.jsxs("svg", {
2039
+ const ChevronRight = Icon(/* @__PURE__ */ jsxRuntime.jsxs("svg", {
1964
2040
  xmlns: "http://www.w3.org/2000/svg",
1965
2041
  height: "24px",
1966
2042
  viewBox: "0 0 24 24",
1967
2043
  width: "24px",
1968
2044
  fill: "currentColor",
1969
- children: [jsxRuntime.jsx("path", {
2045
+ children: [/* @__PURE__ */ jsxRuntime.jsx("path", {
1970
2046
  d: "M0 0h24v24H0V0z",
1971
2047
  fill: "none"
1972
- }), jsxRuntime.jsx("path", {
2048
+ }), /* @__PURE__ */ jsxRuntime.jsx("path", {
1973
2049
  d: "M10 6L8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6-6-6z"
1974
2050
  })]
1975
2051
  }));
1976
- const Search = Icon(jsxRuntime.jsxs("svg", {
2052
+ const Search = Icon(/* @__PURE__ */ jsxRuntime.jsxs("svg", {
1977
2053
  xmlns: "http://www.w3.org/2000/svg",
1978
2054
  height: "24px",
1979
2055
  viewBox: "0 0 24 24",
1980
2056
  width: "24px",
1981
2057
  fill: "currentColor",
1982
- children: [jsxRuntime.jsx("path", {
2058
+ children: [/* @__PURE__ */ jsxRuntime.jsx("path", {
1983
2059
  d: "M0 0h24v24H0V0z",
1984
2060
  fill: "none"
1985
- }), jsxRuntime.jsx("path", {
2061
+ }), /* @__PURE__ */ jsxRuntime.jsx("path", {
1986
2062
  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"
1987
2063
  })]
1988
2064
  }));
1989
- const Clear = Icon(jsxRuntime.jsxs("svg", {
2065
+ const Clear = Icon(/* @__PURE__ */ jsxRuntime.jsxs("svg", {
1990
2066
  xmlns: "http://www.w3.org/2000/svg",
1991
2067
  height: "24px",
1992
2068
  viewBox: "0 0 24 24",
1993
2069
  width: "24px",
1994
2070
  fill: "currentColor",
1995
- children: [jsxRuntime.jsx("path", {
2071
+ children: [/* @__PURE__ */ jsxRuntime.jsx("path", {
1996
2072
  d: "M0 0h24v24H0V0z",
1997
2073
  fill: "none"
1998
- }), jsxRuntime.jsx("path", {
2074
+ }), /* @__PURE__ */ jsxRuntime.jsx("path", {
1999
2075
  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"
2000
2076
  })]
2001
2077
  }));
2002
- const ArrowDropDown = Icon(jsxRuntime.jsxs("svg", {
2078
+ const ArrowDropDown = Icon(/* @__PURE__ */ jsxRuntime.jsxs("svg", {
2003
2079
  xmlns: "http://www.w3.org/2000/svg",
2004
2080
  height: "24px",
2005
2081
  viewBox: "0 0 24 24",
2006
2082
  width: "24px",
2007
2083
  fill: "currentColor",
2008
- children: [jsxRuntime.jsx("path", {
2084
+ children: [/* @__PURE__ */ jsxRuntime.jsx("path", {
2009
2085
  d: "M0 0h24v24H0V0z",
2010
2086
  fill: "none"
2011
- }), jsxRuntime.jsx("path", {
2087
+ }), /* @__PURE__ */ jsxRuntime.jsx("path", {
2012
2088
  d: "M7 10l5 5 5-5H7z"
2013
2089
  })]
2014
2090
  }));
2015
- const FilterList = Icon(jsxRuntime.jsx("svg", {
2091
+ const FilterList = Icon(/* @__PURE__ */ jsxRuntime.jsx("svg", {
2016
2092
  viewBox: "0 0 24 24",
2017
- children: jsxRuntime.jsx("path", {
2093
+ children: /* @__PURE__ */ jsxRuntime.jsx("path", {
2018
2094
  fill: "currentColor",
2019
2095
  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"
2020
2096
  })
2021
2097
  }));
2022
- const ArrowUpward = Icon(jsxRuntime.jsxs("svg", {
2098
+ const ArrowUpward = Icon(/* @__PURE__ */ jsxRuntime.jsxs("svg", {
2023
2099
  xmlns: "http://www.w3.org/2000/svg",
2024
2100
  height: "24px",
2025
2101
  viewBox: "0 0 24 24",
2026
2102
  width: "24px",
2027
2103
  fill: "currentColor",
2028
- children: [jsxRuntime.jsx("path", {
2104
+ children: [/* @__PURE__ */ jsxRuntime.jsx("path", {
2029
2105
  d: "M0 0h24v24H0V0z",
2030
2106
  fill: "none"
2031
- }), jsxRuntime.jsx("path", {
2107
+ }), /* @__PURE__ */ jsxRuntime.jsx("path", {
2032
2108
  d: "M4 12l1.41 1.41L11 7.83V20h2V7.83l5.58 5.59L20 12l-8-8-8 8z"
2033
2109
  })]
2034
2110
  }));
@@ -2063,26 +2139,45 @@ const defaultTableTheme = {
2063
2139
  spacing: "5px"
2064
2140
  };
2065
2141
  const emptyStore = new react$1.Store(void 0);
2066
- function useTheme() {
2142
+ function useTheme(selector) {
2067
2143
  var _a, _b;
2068
- const table = react.useContext(TableContext);
2069
- const localTheme = (_b = (_a = table == null ? void 0 : table.useState((state) => ({
2070
- text: state.props.text,
2071
- classes: state.props.classes,
2072
- components: state.props.components,
2073
- icons: state.props.icons,
2074
- colors: state.props.colors,
2075
- spacing: state.props.spacing
2076
- }))) != null ? _a : emptyStore.useState()) != null ? _b : {};
2077
2144
  const contextTableTheme = react.useContext(tableTheme.TableThemeContext);
2078
- return tableTheme.mergeThemes(defaultTableTheme, tableTheme.globalTableTheme, contextTableTheme, localTheme);
2145
+ const table = react.useContext(TableContext);
2146
+ const columnId = react.useContext(ColumnContext);
2147
+ const memo = useTableMemo();
2148
+ const process = (t) => {
2149
+ var _a2;
2150
+ const cell = (_a2 = t.classes) == null ? void 0 : _a2.cell;
2151
+ const selected = t.text.selected;
2152
+ return __spreadProps(__spreadValues({}, t), {
2153
+ classes: __spreadProps(__spreadValues({}, t.classes), {
2154
+ cell: cell instanceof Function || Array.isArray(cell) ? memo("theme.classes.cell", cell) : cell
2155
+ }),
2156
+ text: __spreadProps(__spreadValues({}, t.text), {
2157
+ selected: selected instanceof Function || Array.isArray(selected) ? memo("theme.text.selected", selected) : selected
2158
+ })
2159
+ });
2160
+ };
2161
+ const theme = (_b = (_a = table == null ? void 0 : table.useState((state) => {
2162
+ const localTheme = {
2163
+ text: state.props.text,
2164
+ classes: state.props.classes,
2165
+ components: state.props.components,
2166
+ icons: state.props.icons,
2167
+ colors: state.props.colors,
2168
+ spacing: state.props.spacing
2169
+ };
2170
+ const column = state.activeColumns.find((column2) => column2.id === columnId);
2171
+ const columnsTheme = {
2172
+ classes: column == null ? void 0 : column.classes
2173
+ };
2174
+ const theme2 = tableTheme.mergeThemes(defaultTableTheme, tableTheme.globalTableTheme, contextTableTheme, localTheme, columnsTheme);
2175
+ return selector(process(theme2));
2176
+ })) != null ? _a : emptyStore.useState()) != null ? _b : selector(process(tableTheme.mergeThemes(defaultTableTheme, tableTheme.globalTableTheme, contextTableTheme)));
2177
+ return theme;
2079
2178
  }
2080
2179
  function AutoFocusTextField(props) {
2081
- const {
2082
- components: {
2083
- TextField: TextField2
2084
- }
2085
- } = useTheme();
2180
+ const TextField2 = useTheme((t) => t.components.TextField);
2086
2181
  const ref = react.useRef(null);
2087
2182
  const {
2088
2183
  visible
@@ -2092,7 +2187,7 @@ function AutoFocusTextField(props) {
2092
2187
  ref.current.focus();
2093
2188
  }
2094
2189
  }, [visible]);
2095
- return jsxRuntime.jsx(TextField2, __spreadProps(__spreadValues({}, props), {
2190
+ return /* @__PURE__ */ jsxRuntime.jsx(TextField2, __spreadProps(__spreadValues({}, props), {
2096
2191
  inputRef: ref
2097
2192
  }));
2098
2193
  }
@@ -2150,7 +2245,7 @@ function DateInput({
2150
2245
  }), [locale]);
2151
2246
  const parts = format.formatToParts(value != null ? value : defaultDate);
2152
2247
  const isEmpty = !value;
2153
- return jsxRuntime.jsx("div", {
2248
+ return /* @__PURE__ */ jsxRuntime.jsx("div", {
2154
2249
  css: {
2155
2250
  display: "flex",
2156
2251
  alignItems: "baseline"
@@ -2158,8 +2253,8 @@ function DateInput({
2158
2253
  children: parts.map(({
2159
2254
  type,
2160
2255
  value: value2
2161
- }, index) => jsxRuntime.jsx(react.Fragment, {
2162
- children: isIncludedType(type) ? jsxRuntime.jsx("input", {
2256
+ }, index) => /* @__PURE__ */ jsxRuntime.jsx(react.Fragment, {
2257
+ children: isIncludedType(type) ? /* @__PURE__ */ jsxRuntime.jsx("input", {
2163
2258
  className,
2164
2259
  css: {
2165
2260
  width: `${length(type, value2)}ch`,
@@ -2186,7 +2281,7 @@ function DateInput({
2186
2281
  },
2187
2282
  onFocus: (e) => e.target.select(),
2188
2283
  onBlur: commit
2189
- }) : type === "literal" ? jsxRuntime.jsx("span", {
2284
+ }) : type === "literal" ? /* @__PURE__ */ jsxRuntime.jsx("span", {
2190
2285
  children: value2
2191
2286
  }) : null
2192
2287
  }, index))
@@ -2242,16 +2337,12 @@ function DatePicker({
2242
2337
  locale,
2243
2338
  firstDayOfWeek = 0
2244
2339
  }) {
2245
- const {
2246
- components: {
2247
- Button: Button2,
2248
- IconButton: IconButton2
2249
- },
2250
- icons: {
2251
- ChevronRight: ChevronRight2
2252
- },
2253
- text
2254
- } = useTheme();
2340
+ const Button2 = useTheme((t) => t.components.Button);
2341
+ const IconButton2 = useTheme((t) => t.components.IconButton);
2342
+ const ChevronRight2 = useTheme((t) => t.icons.ChevronRight);
2343
+ const textToday = useTheme((t) => t.text.today);
2344
+ const textThisWeek = useTheme((t) => t.text.thisWeek);
2345
+ const textReset = useTheme((t) => t.text.reset);
2255
2346
  const [baseDate] = react.useState(new Date());
2256
2347
  const [dateInView, setDateInView] = react.useState(baseDate);
2257
2348
  const [dirty, setDirty] = react.useState();
@@ -2328,8 +2419,8 @@ function DatePicker({
2328
2419
  });
2329
2420
  return (year) => format(new Date(year, 0, 1));
2330
2421
  }, [locale]);
2331
- return jsxRuntime.jsxs("div", {
2332
- children: [jsxRuntime.jsxs("div", {
2422
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", {
2423
+ children: [/* @__PURE__ */ jsxRuntime.jsxs("div", {
2333
2424
  css: {
2334
2425
  display: "grid",
2335
2426
  gridAutoFlow: "column",
@@ -2337,12 +2428,12 @@ function DatePicker({
2337
2428
  alignItems: "baseline",
2338
2429
  gap: "var(--spacing)"
2339
2430
  },
2340
- children: [jsxRuntime.jsx(DateInput, {
2431
+ children: [/* @__PURE__ */ jsxRuntime.jsx(DateInput, {
2341
2432
  value: min != null ? min : null,
2342
2433
  onChange: (date) => set(date != null ? date : void 0, max, "min"),
2343
2434
  locale
2344
- }), rangeSelect && jsxRuntime.jsxs(jsxRuntime.Fragment, {
2345
- children: [" - ", jsxRuntime.jsx(DateInput, {
2435
+ }), rangeSelect && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, {
2436
+ children: [" - ", /* @__PURE__ */ jsxRuntime.jsx(DateInput, {
2346
2437
  value: max != null ? max : null,
2347
2438
  onChange: (date) => set(min, date != null ? date : void 0, "max"),
2348
2439
  locale
@@ -2352,11 +2443,11 @@ function DatePicker({
2352
2443
  month,
2353
2444
  year,
2354
2445
  weeks
2355
- }) => jsxRuntime.jsxs("div", {
2446
+ }) => /* @__PURE__ */ jsxRuntime.jsxs("div", {
2356
2447
  css: {
2357
2448
  display: "grid"
2358
2449
  },
2359
- children: [jsxRuntime.jsxs("div", {
2450
+ children: [/* @__PURE__ */ jsxRuntime.jsxs("div", {
2360
2451
  css: {
2361
2452
  margin: "calc(var(--spacing) * 4) 0",
2362
2453
  display: "grid",
@@ -2364,32 +2455,32 @@ function DatePicker({
2364
2455
  justifyContent: "space-between",
2365
2456
  alignItems: "center"
2366
2457
  },
2367
- children: [jsxRuntime.jsx(IconButton2, __spreadProps(__spreadValues({}, getBackProps({
2458
+ children: [/* @__PURE__ */ jsxRuntime.jsx(IconButton2, __spreadProps(__spreadValues({}, getBackProps({
2368
2459
  calendars
2369
2460
  })), {
2370
- children: jsxRuntime.jsx(ChevronRight2, {
2461
+ children: /* @__PURE__ */ jsxRuntime.jsx(ChevronRight2, {
2371
2462
  css: {
2372
2463
  transform: "rotate3d(0, 0, 1, 180deg)"
2373
2464
  }
2374
2465
  })
2375
- })), jsxRuntime.jsxs("div", {
2466
+ })), /* @__PURE__ */ jsxRuntime.jsxs("div", {
2376
2467
  css: {
2377
2468
  display: "flex"
2378
2469
  },
2379
2470
  children: [formatMonth(month), " ", formatYear(year)]
2380
- }), jsxRuntime.jsx(IconButton2, __spreadProps(__spreadValues({}, getForwardProps({
2471
+ }), /* @__PURE__ */ jsxRuntime.jsx(IconButton2, __spreadProps(__spreadValues({}, getForwardProps({
2381
2472
  calendars
2382
2473
  })), {
2383
- children: jsxRuntime.jsx(ChevronRight2, {})
2474
+ children: /* @__PURE__ */ jsxRuntime.jsx(ChevronRight2, {})
2384
2475
  }))]
2385
- }), jsxRuntime.jsxs("div", {
2476
+ }), /* @__PURE__ */ jsxRuntime.jsxs("div", {
2386
2477
  css: {
2387
2478
  justifySelf: "center",
2388
2479
  display: "grid",
2389
2480
  gridTemplateColumns: "repeat(7, max-content)",
2390
2481
  fontWeight: "bold"
2391
2482
  },
2392
- children: [weekDays.map((_v, weekDay) => jsxRuntime.jsx("div", {
2483
+ children: [weekDays.map((_v, weekDay) => /* @__PURE__ */ jsxRuntime.jsx("div", {
2393
2484
  css: {
2394
2485
  justifySelf: "center",
2395
2486
  marginBottom: "var(--spacing)"
@@ -2397,7 +2488,7 @@ function DatePicker({
2397
2488
  children: formatWeekday(weekDay)
2398
2489
  }, weekDay)), weeks.map((week, index) => week.map((dateObj, dayIndex) => {
2399
2490
  if (!dateObj) {
2400
- return jsxRuntime.jsx("div", {});
2491
+ return /* @__PURE__ */ jsxRuntime.jsx("div", {});
2401
2492
  }
2402
2493
  const {
2403
2494
  prevMonth,
@@ -2416,7 +2507,7 @@ function DatePicker({
2416
2507
  min: hovered,
2417
2508
  max: min
2418
2509
  }));
2419
- return jsxRuntime.jsx("button", __spreadProps(__spreadValues({
2510
+ return /* @__PURE__ */ jsxRuntime.jsx("button", __spreadProps(__spreadValues({
2420
2511
  css: [{
2421
2512
  padding: 10,
2422
2513
  border: "1px solid transparent",
@@ -2452,34 +2543,34 @@ function DatePicker({
2452
2543
  }), `${index}-${dayIndex}`);
2453
2544
  }))]
2454
2545
  })]
2455
- }, `${month}${year}`)), jsxRuntime.jsxs("div", {
2546
+ }, `${month}${year}`)), /* @__PURE__ */ jsxRuntime.jsxs("div", {
2456
2547
  css: {
2457
2548
  marginTop: "var(--spacing)",
2458
2549
  display: "grid",
2459
2550
  gridAutoFlow: "column",
2460
2551
  justifyContent: "center"
2461
2552
  },
2462
- children: [jsxRuntime.jsx(Button2, {
2553
+ children: [/* @__PURE__ */ jsxRuntime.jsx(Button2, {
2463
2554
  variant: "text",
2464
2555
  onClick: () => {
2465
2556
  setDirty(void 0);
2466
2557
  onChange(today());
2467
2558
  },
2468
- children: text.today
2469
- }), jsxRuntime.jsx(Button2, {
2559
+ children: textToday
2560
+ }), /* @__PURE__ */ jsxRuntime.jsx(Button2, {
2470
2561
  variant: "text",
2471
2562
  onClick: () => {
2472
2563
  setDirty(void 0);
2473
2564
  onChange(thisWeek(firstDayOfWeek));
2474
2565
  },
2475
- children: text.thisWeek
2476
- }), jsxRuntime.jsx(Button2, {
2566
+ children: textThisWeek
2567
+ }), /* @__PURE__ */ jsxRuntime.jsx(Button2, {
2477
2568
  variant: "text",
2478
2569
  onClick: () => {
2479
2570
  setDirty(void 0);
2480
2571
  onChange(null);
2481
2572
  },
2482
- children: text.reset
2573
+ children: textReset
2483
2574
  })]
2484
2575
  })]
2485
2576
  });
@@ -2531,12 +2622,12 @@ function DateFilter(_k) {
2531
2622
  return dateIntersect(filterValue, value2);
2532
2623
  }
2533
2624
  }));
2534
- return jsxRuntime.jsx("div", {
2625
+ return /* @__PURE__ */ jsxRuntime.jsx("div", {
2535
2626
  css: {
2536
2627
  padding: "calc(var(--spacing) * 2)",
2537
2628
  display: "grid"
2538
2629
  },
2539
- children: jsxRuntime.jsx(DatePicker, {
2630
+ children: /* @__PURE__ */ jsxRuntime.jsx(DatePicker, {
2540
2631
  rangeSelect: !singleSelect,
2541
2632
  value,
2542
2633
  onChange,
@@ -2566,34 +2657,18 @@ function SelectFilter(_m) {
2566
2657
  "render",
2567
2658
  "singleSelect"
2568
2659
  ]);
2569
- const {
2570
- components: {
2571
- IconButton: IconButton2,
2572
- Checkbox: Checkbox2
2573
- },
2574
- icons: {
2575
- Search: Search2,
2576
- Clear: Clear2
2577
- },
2578
- text
2579
- } = useTheme();
2660
+ const IconButton2 = useTheme((t) => t.components.IconButton);
2661
+ const Checkbox2 = useTheme((t) => t.components.Checkbox);
2662
+ const Search2 = useTheme((t) => t.icons.Search);
2663
+ const Clear2 = useTheme((t) => t.icons.Clear);
2664
+ const selected = useTheme((t) => t.text.selected);
2665
+ const noResults = useTheme((t) => t.text.noResults);
2580
2666
  const table = useTableContext();
2581
2667
  const columnId = useColumnContext();
2582
- const options = table.useState((state) => {
2583
- var _a;
2584
- if (providedOptions)
2585
- return uniq(providedOptions);
2586
- const column = state.activeColumns.find((column2) => column2.id === columnId);
2587
- if (!column)
2588
- return [];
2589
- const filterBy = (_a = props.filterBy) != null ? _a : (x) => x;
2590
- return uniq(flatMap(state.items, (item) => castArray(filterBy(column.value(item), item))));
2591
- });
2592
- const [query, setQuery] = react.useState("");
2593
- const filtered = options.filter((option) => !query || stringValue(option).toLowerCase().includes(query.toLowerCase()));
2594
2668
  const {
2595
2669
  value = /* @__PURE__ */ new Set(),
2596
- onChange
2670
+ onChange,
2671
+ filterBy
2597
2672
  } = useFilter(__spreadProps(__spreadValues({}, props), {
2598
2673
  id: "selectFilter",
2599
2674
  isActive(filterValue) {
@@ -2603,49 +2678,59 @@ function SelectFilter(_m) {
2603
2678
  return filterValue.has(value2);
2604
2679
  }
2605
2680
  }));
2606
- return jsxRuntime.jsxs("div", {
2681
+ const options = table.useState((state) => {
2682
+ if (providedOptions)
2683
+ return uniq(providedOptions);
2684
+ const column = state.activeColumns.find((column2) => column2.id === columnId);
2685
+ if (!column)
2686
+ return [];
2687
+ return uniq(flatMap(state.items, (item) => castArray(filterBy(column.value(item.value), item.value))));
2688
+ });
2689
+ const [query, setQuery] = react.useState("");
2690
+ const filtered = options.filter((option) => !query || stringValue(option).toLowerCase().includes(query.toLowerCase()));
2691
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", {
2607
2692
  css: {
2608
2693
  padding: "calc(var(--spacing) * 2)",
2609
2694
  display: "grid",
2610
2695
  gap: "var(--spacing)"
2611
2696
  },
2612
- children: [jsxRuntime.jsx(AutoFocusTextField, {
2697
+ children: [/* @__PURE__ */ jsxRuntime.jsx(AutoFocusTextField, {
2613
2698
  value: query,
2614
2699
  onChange: (e) => setQuery(e.target.value),
2615
- endIcon: jsxRuntime.jsx(IconButton2, {
2700
+ endIcon: /* @__PURE__ */ jsxRuntime.jsx(IconButton2, {
2616
2701
  onClick: () => setQuery(""),
2617
- children: !query ? jsxRuntime.jsx(Search2, {}) : jsxRuntime.jsx(Clear2, {})
2702
+ children: !query ? /* @__PURE__ */ jsxRuntime.jsx(Search2, {}) : /* @__PURE__ */ jsxRuntime.jsx(Clear2, {})
2618
2703
  }),
2619
2704
  css: {
2620
2705
  marginBottom: "var(--spacing)"
2621
2706
  }
2622
- }), jsxRuntime.jsxs("div", {
2707
+ }), /* @__PURE__ */ jsxRuntime.jsxs("div", {
2623
2708
  css: {
2624
2709
  maxHeight: "20em",
2625
2710
  overflowY: "auto"
2626
2711
  },
2627
- children: [jsxRuntime.jsx(FormControlLabel, {
2712
+ children: [/* @__PURE__ */ jsxRuntime.jsx(FormControlLabel, {
2628
2713
  disabled: value.size === 0,
2629
- control: jsxRuntime.jsx(Checkbox2, {
2714
+ control: /* @__PURE__ */ jsxRuntime.jsx(Checkbox2, {
2630
2715
  disabled: value.size === 0,
2631
2716
  checked: value.size > 0,
2632
2717
  onChange: () => onChange(/* @__PURE__ */ new Set())
2633
2718
  }),
2634
- label: jsxRuntime.jsxs(jsxRuntime.Fragment, {
2635
- children: ["<", text.selected(value.size), ">"]
2719
+ label: /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, {
2720
+ children: ["<", selected(value.size), ">"]
2636
2721
  })
2637
- }), filtered.map((option, index) => jsxRuntime.jsx(FormControlLabel, {
2638
- control: jsxRuntime.jsx(Checkbox2, {
2722
+ }), filtered.map((option, index) => /* @__PURE__ */ jsxRuntime.jsx(FormControlLabel, {
2723
+ control: /* @__PURE__ */ jsxRuntime.jsx(Checkbox2, {
2639
2724
  checked: value.has(option),
2640
2725
  onChange: () => onChange(toggle(value, option, singleSelect))
2641
2726
  }),
2642
2727
  label: render(option)
2643
2728
  }, index))]
2644
- }), filtered.length === 0 && jsxRuntime.jsx("span", {
2729
+ }), filtered.length === 0 && /* @__PURE__ */ jsxRuntime.jsx("span", {
2645
2730
  css: {
2646
2731
  textAlign: "center"
2647
2732
  },
2648
- children: text.noResults
2733
+ children: noResults
2649
2734
  })]
2650
2735
  });
2651
2736
  }
@@ -2676,6 +2761,8 @@ function debounce(fn, ms) {
2676
2761
  function useFilter(impl) {
2677
2762
  const table = useTableContext();
2678
2763
  const columnId = useColumnContext();
2764
+ const cache = useTableMemo();
2765
+ const filterBy = impl.filterBy && cache("", impl.filterBy);
2679
2766
  react.useEffect(() => {
2680
2767
  table.update((state) => {
2681
2768
  if (impl.defaultValue !== void 0) {
@@ -2685,7 +2772,7 @@ function useFilter(impl) {
2685
2772
  }, []);
2686
2773
  react.useEffect(() => {
2687
2774
  table.update((state) => {
2688
- state.filters.set(columnId, immer.castDraft(impl));
2775
+ state.filters.set(columnId, immer.castDraft(__spreadProps(__spreadValues({}, impl), { filterBy })));
2689
2776
  if (impl.value !== void 0) {
2690
2777
  state.filterValues.set(columnId, impl.value);
2691
2778
  }
@@ -2720,7 +2807,8 @@ function useFilter(impl) {
2720
2807
  return {
2721
2808
  value: dirtyValue != null ? dirtyValue : value,
2722
2809
  onChange,
2723
- close: react.useContext(FilterControlContext)
2810
+ close: react.useContext(FilterControlContext),
2811
+ filterBy: filterBy != null ? filterBy : (x) => x
2724
2812
  };
2725
2813
  }
2726
2814
  const textMatch = (text, query) => {
@@ -2750,15 +2838,9 @@ function TextFilter(_o) {
2750
2838
  "compare",
2751
2839
  "filterBy"
2752
2840
  ]);
2753
- const {
2754
- components: {
2755
- IconButton: IconButton2
2756
- },
2757
- icons: {
2758
- Search: Search2,
2759
- Clear: Clear2
2760
- }
2761
- } = useTheme();
2841
+ const IconButton2 = useTheme((t) => t.components.IconButton);
2842
+ const Search2 = useTheme((t) => t.icons.Search);
2843
+ const Clear2 = useTheme((t) => t.icons.Clear);
2762
2844
  const {
2763
2845
  value = "",
2764
2846
  onChange
@@ -2772,17 +2854,17 @@ function TextFilter(_o) {
2772
2854
  return compare(value2, filterValue);
2773
2855
  }
2774
2856
  }));
2775
- return jsxRuntime.jsx("div", {
2857
+ return /* @__PURE__ */ jsxRuntime.jsx("div", {
2776
2858
  css: {
2777
2859
  padding: `calc(var(--spacing) * 2)`,
2778
2860
  display: "grid"
2779
2861
  },
2780
- children: jsxRuntime.jsx(AutoFocusTextField, {
2862
+ children: /* @__PURE__ */ jsxRuntime.jsx(AutoFocusTextField, {
2781
2863
  value,
2782
2864
  onChange: (e) => onChange(e.target.value),
2783
- endIcon: jsxRuntime.jsx(IconButton2, {
2865
+ endIcon: /* @__PURE__ */ jsxRuntime.jsx(IconButton2, {
2784
2866
  onClick: () => onChange(""),
2785
- children: !value ? jsxRuntime.jsx(Search2, {}) : jsxRuntime.jsx(Clear2, {})
2867
+ children: !value ? /* @__PURE__ */ jsxRuntime.jsx(Search2, {}) : /* @__PURE__ */ jsxRuntime.jsx(Clear2, {})
2786
2868
  })
2787
2869
  })
2788
2870
  });