schummar-table 0.6.0 → 0.7.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 +251 -224
- package/dist/cjs/index.js.map +1 -1
- package/dist/es/index.js +253 -226
- package/dist/es/index.js.map +1 -1
- package/dist/types/components/row.d.ts +2 -2
- package/dist/types/hooks/useFilter.d.ts +1 -0
- package/dist/types/hooks/useMemoMap.d.ts +2 -0
- package/dist/types/hooks/useTableMemo.d.ts +6 -0
- package/dist/types/hooks/useTheme.d.ts +2 -2
- package/dist/types/misc/throttle.d.ts +1 -0
- package/dist/types/types.d.ts +28 -19
- package/package.json +1 -1
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 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();
|
|
@@ -295,8 +323,10 @@ function calcItems(state) {
|
|
|
295
323
|
const column = activeColumns.find((column2) => column2.id === sort2.columnId);
|
|
296
324
|
if (!column)
|
|
297
325
|
return [];
|
|
298
|
-
|
|
299
|
-
|
|
326
|
+
return column.sortBy.map((sortBy) => ({
|
|
327
|
+
selector: (item) => sortBy(column.value(item), item),
|
|
328
|
+
direction: sort2.direction
|
|
329
|
+
}));
|
|
300
330
|
}).filter(Boolean);
|
|
301
331
|
sorted = orderBy(tableItems, selectors.map((x) => x.selector), selectors.map((x) => x.direction));
|
|
302
332
|
}
|
|
@@ -368,20 +398,20 @@ function calcItems(state) {
|
|
|
368
398
|
}
|
|
369
399
|
const noopParentId = () => void 0;
|
|
370
400
|
function calcProps(props) {
|
|
371
|
-
const
|
|
401
|
+
const cache = useTableMemo();
|
|
372
402
|
return react.useMemo(() => {
|
|
373
|
-
var
|
|
403
|
+
var _e, _f, _g, _h, _i, _j;
|
|
374
404
|
let id;
|
|
375
|
-
if (props.id instanceof Function) {
|
|
376
|
-
id = props.id;
|
|
405
|
+
if (props.id instanceof Function || Array.isArray(props.id)) {
|
|
406
|
+
id = cache("id", props.id);
|
|
377
407
|
} else {
|
|
378
|
-
id = (item) => item[props.id];
|
|
408
|
+
id = cache("id", [(item) => item[props.id], props.id]);
|
|
379
409
|
}
|
|
380
410
|
let parentId;
|
|
381
|
-
if (props.parentId instanceof Function) {
|
|
382
|
-
parentId = props.parentId;
|
|
383
|
-
} else if (
|
|
384
|
-
parentId = (item) => item[props.parentId];
|
|
411
|
+
if (props.parentId instanceof Function || Array.isArray(props.parentId)) {
|
|
412
|
+
parentId = cache("parentId", props.parentId);
|
|
413
|
+
} else if (props.parentId !== void 0) {
|
|
414
|
+
parentId = cache("parentId", [(item) => item[props.parentId], props.parentId]);
|
|
385
415
|
} else {
|
|
386
416
|
parentId = noopParentId;
|
|
387
417
|
}
|
|
@@ -391,42 +421,37 @@ function calcProps(props) {
|
|
|
391
421
|
} else {
|
|
392
422
|
inputColumns = props.columns.map((column) => __spreadProps(__spreadValues({}, column), { dependecies: void 0 }));
|
|
393
423
|
}
|
|
394
|
-
const
|
|
395
|
-
const
|
|
396
|
-
|
|
424
|
+
const defCol = props.defaultColumnProps;
|
|
425
|
+
const mapColumn = ({
|
|
426
|
+
id: _id,
|
|
427
|
+
header = ((_a) => (_a = defCol == null ? void 0 : defCol.header) != null ? _a : null)(),
|
|
428
|
+
value,
|
|
429
|
+
renderCell = ((_b) => (_b = defCol == null ? void 0 : defCol.renderCell) != null ? _b : asString)(),
|
|
430
|
+
exportCell = ((_c) => (_c = defCol == null ? void 0 : defCol.exportCell) != null ? _c : asString)(),
|
|
431
|
+
sortBy = ((_d) => (_d = defCol == null ? void 0 : defCol.sortBy) != null ? _d : [(v) => typeof v === "number" || v instanceof Date ? v : String(v)])(),
|
|
432
|
+
cannotHide = defCol == null ? void 0 : defCol.cannotHide,
|
|
433
|
+
classes = defCol == null ? void 0 : defCol.classes,
|
|
434
|
+
filter = defCol == null ? void 0 : defCol.filter,
|
|
435
|
+
width = defCol == null ? void 0 : defCol.width
|
|
436
|
+
}, index) => {
|
|
437
|
+
const id2 = _id != null ? _id : index;
|
|
438
|
+
const cacheKey = typeof id2 === "string" ? `s${id2}` : `n${id2}`;
|
|
439
|
+
return {
|
|
397
440
|
id: id2,
|
|
398
|
-
header
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
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;
|
|
441
|
+
header,
|
|
442
|
+
value: cache(`columns.${cacheKey}.value`, value),
|
|
443
|
+
renderCell: cache(`columns.${cacheKey}.renderCell`, renderCell),
|
|
444
|
+
exportCell,
|
|
445
|
+
sortBy: sortBy.map((fn, i) => cache(`columns.${cacheKey}.sortBy.${i}`, fn)),
|
|
446
|
+
cannotHide,
|
|
447
|
+
classes,
|
|
448
|
+
filter,
|
|
449
|
+
width
|
|
450
|
+
};
|
|
451
|
+
};
|
|
452
|
+
const columns = inputColumns.map(mapColumn);
|
|
453
|
+
const wrapCell = props.wrapCell && cache("wrapCell", props.wrapCell);
|
|
454
|
+
const rowAction = props.rowAction instanceof Function || Array.isArray(props.rowAction) ? cache("rowAction", props.rowAction) : props.rowAction;
|
|
430
455
|
let copy;
|
|
431
456
|
if (props.enableExport === true || props.enableExport instanceof Object && props.enableExport.copy === true) {
|
|
432
457
|
copy = { separator: " " };
|
|
@@ -444,13 +469,15 @@ function calcProps(props) {
|
|
|
444
469
|
id,
|
|
445
470
|
parentId,
|
|
446
471
|
columns,
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
472
|
+
wrapCell,
|
|
473
|
+
rowAction,
|
|
474
|
+
enableSelection: (_e = props.enableSelection) != null ? _e : true,
|
|
475
|
+
selectSyncChildren: (_f = props.selectSyncChildren) != null ? _f : true,
|
|
476
|
+
stickyHeader: (_g = props.stickyHeader) != null ? _g : true,
|
|
450
477
|
enableExport,
|
|
451
|
-
enableColumnSelection: (
|
|
452
|
-
enableColumnResize: (
|
|
453
|
-
enableColumnReorder: (
|
|
478
|
+
enableColumnSelection: (_h = props.enableColumnSelection) != null ? _h : true,
|
|
479
|
+
enableColumnResize: (_i = props.enableColumnResize) != null ? _i : true,
|
|
480
|
+
enableColumnReorder: (_j = props.enableColumnReorder) != null ? _j : true
|
|
454
481
|
});
|
|
455
482
|
}, [props]);
|
|
456
483
|
}
|
|
@@ -580,16 +607,15 @@ function useTableState(_props) {
|
|
|
580
607
|
return state;
|
|
581
608
|
}
|
|
582
609
|
function useCssVariables() {
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
"--
|
|
586
|
-
"--
|
|
587
|
-
"--
|
|
588
|
-
"--
|
|
589
|
-
"--
|
|
590
|
-
"--
|
|
591
|
-
|
|
592
|
-
};
|
|
610
|
+
return useTheme(({ spacing, colors }) => ({
|
|
611
|
+
"--spacing": spacing,
|
|
612
|
+
"--primaryMain": colors.primary.main,
|
|
613
|
+
"--primaryLight": colors.primary.light,
|
|
614
|
+
"--primaryContrastText": colors.primary.contrastText,
|
|
615
|
+
"--secondaryMain": colors.secondary.main,
|
|
616
|
+
"--secondaryLight": colors.secondary.light,
|
|
617
|
+
"--secondaryContrastText": colors.secondary.contrastText
|
|
618
|
+
}));
|
|
593
619
|
}
|
|
594
620
|
const ColumnHeaderContext = new react$1.StoreScope({
|
|
595
621
|
items: /* @__PURE__ */ new Map()
|
|
@@ -755,17 +781,11 @@ function FormControlLabel({
|
|
|
755
781
|
});
|
|
756
782
|
}
|
|
757
783
|
function ColumnSelection() {
|
|
758
|
-
const
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
},
|
|
764
|
-
icons: {
|
|
765
|
-
Settings: Settings2
|
|
766
|
-
},
|
|
767
|
-
text
|
|
768
|
-
} = useTheme();
|
|
784
|
+
const IconButton2 = useTheme((t) => t.components.IconButton);
|
|
785
|
+
const Popover = useTheme((t) => t.components.Popover);
|
|
786
|
+
const Checkbox2 = useTheme((t) => t.components.Checkbox);
|
|
787
|
+
const Settings2 = useTheme((t) => t.icons.Settings);
|
|
788
|
+
const selectColumns = useTheme((t) => t.text.selectColumns);
|
|
769
789
|
const cssVariables = useCssVariables();
|
|
770
790
|
const table = useTableContext();
|
|
771
791
|
const columns = table.useState("props.columns");
|
|
@@ -808,7 +828,7 @@ function ColumnSelection() {
|
|
|
808
828
|
css: {
|
|
809
829
|
marginBottom: "var(--spacing)"
|
|
810
830
|
},
|
|
811
|
-
children:
|
|
831
|
+
children: selectColumns
|
|
812
832
|
}), columns.map((column) => jsxRuntime.jsx(FormControlLabel, {
|
|
813
833
|
control: jsxRuntime.jsx(Checkbox2, {
|
|
814
834
|
checked: !hiddenColumns.has(column.id),
|
|
@@ -835,18 +855,14 @@ function csvExport(data, { sepPrefix, separator = ",", quote = '"', eol = "\n" }
|
|
|
835
855
|
}
|
|
836
856
|
function Export$1() {
|
|
837
857
|
const table = useTableContext();
|
|
838
|
-
const
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
Clipboard: Clipboard2
|
|
847
|
-
},
|
|
848
|
-
text
|
|
849
|
-
} = useTheme();
|
|
858
|
+
const Button2 = useTheme((t) => t.components.Button);
|
|
859
|
+
const IconButton2 = useTheme((t) => t.components.IconButton);
|
|
860
|
+
const Popover = useTheme((t) => t.components.Popover);
|
|
861
|
+
const Export2 = useTheme((t) => t.icons.Export);
|
|
862
|
+
const Clipboard2 = useTheme((t) => t.icons.Clipboard);
|
|
863
|
+
const exportTitle = useTheme((t) => t.text.exportTitle);
|
|
864
|
+
const exportCopy = useTheme((t) => t.text.exportCopy);
|
|
865
|
+
const exportDownload = useTheme((t) => t.text.exportDownload);
|
|
850
866
|
const cssVariables = useCssVariables();
|
|
851
867
|
const [anchor, setAnchor] = react.useState(null);
|
|
852
868
|
const generate = (options) => {
|
|
@@ -895,15 +911,15 @@ function Export$1() {
|
|
|
895
911
|
css: {
|
|
896
912
|
marginBottom: "var(--spacing)"
|
|
897
913
|
},
|
|
898
|
-
children:
|
|
914
|
+
children: exportTitle
|
|
899
915
|
}), jsxRuntime.jsx(Button2, {
|
|
900
916
|
startIcon: jsxRuntime.jsx(Clipboard2, {}),
|
|
901
917
|
onClick: copy,
|
|
902
|
-
children:
|
|
918
|
+
children: exportCopy
|
|
903
919
|
}), jsxRuntime.jsx(Button2, {
|
|
904
920
|
startIcon: jsxRuntime.jsx(Export2, {}),
|
|
905
921
|
onClick: download,
|
|
906
|
-
children:
|
|
922
|
+
children: exportDownload
|
|
907
923
|
})]
|
|
908
924
|
})
|
|
909
925
|
})]
|
|
@@ -913,16 +929,10 @@ const FilterControlContext = react.createContext(() => void 0);
|
|
|
913
929
|
function FilterControl() {
|
|
914
930
|
const table = useTableContext();
|
|
915
931
|
const columnId = useColumnContext();
|
|
916
|
-
const
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
},
|
|
921
|
-
icons: {
|
|
922
|
-
FilterList: FilterList2,
|
|
923
|
-
ArrowDropDown: ArrowDropDown2
|
|
924
|
-
}
|
|
925
|
-
} = useTheme();
|
|
932
|
+
const IconButton2 = useTheme((t) => t.components.IconButton);
|
|
933
|
+
const Popover = useTheme((t) => t.components.Popover);
|
|
934
|
+
const FilterList2 = useTheme((t) => t.icons.FilterList);
|
|
935
|
+
const ArrowDropDown2 = useTheme((t) => t.icons.ArrowDropDown);
|
|
926
936
|
const cssVariables = useCssVariables();
|
|
927
937
|
const [anchor, setAnchor] = react.useState(null);
|
|
928
938
|
const isActive = table.useState((state) => {
|
|
@@ -1044,49 +1054,56 @@ function ResizeHandleView(_a) {
|
|
|
1044
1054
|
}
|
|
1045
1055
|
}, props));
|
|
1046
1056
|
}
|
|
1057
|
+
const defaultWrapCell = (content) => {
|
|
1058
|
+
if (typeof content === "string") {
|
|
1059
|
+
return jsxRuntime.jsx("span", {
|
|
1060
|
+
css: tableTheme.defaultClasses.text,
|
|
1061
|
+
title: content,
|
|
1062
|
+
children: content
|
|
1063
|
+
});
|
|
1064
|
+
}
|
|
1065
|
+
return content;
|
|
1066
|
+
};
|
|
1047
1067
|
const Cell = react.memo(function Cell2({
|
|
1048
1068
|
itemId,
|
|
1049
1069
|
rowIndex
|
|
1050
1070
|
}) {
|
|
1051
|
-
var _a
|
|
1071
|
+
var _a;
|
|
1052
1072
|
const table = useTableContext();
|
|
1053
1073
|
const columnId = useColumnContext();
|
|
1054
|
-
const {
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1074
|
+
const column = table.useState((state) => {
|
|
1075
|
+
const col = state.activeColumns.find((column2) => column2.id === columnId);
|
|
1076
|
+
return col && {
|
|
1077
|
+
value: col.value,
|
|
1078
|
+
renderCell: col.renderCell
|
|
1079
|
+
};
|
|
1080
|
+
});
|
|
1081
|
+
const wrapCell = (_a = table.useState((state) => state.props.wrapCell)) != null ? _a : defaultWrapCell;
|
|
1058
1082
|
const item = table.useState((state) => state.activeItemsById.get(itemId));
|
|
1059
1083
|
const columnStyleOverride = table.useState((state) => state.columnStyleOverride.get(columnId), {
|
|
1060
1084
|
throttle: 16
|
|
1061
1085
|
});
|
|
1086
|
+
react.useLayoutEffect(() => {
|
|
1087
|
+
var _a2, _b;
|
|
1088
|
+
return (_b = (_a2 = table.getState().props).debugRender) == null ? void 0 : _b.call(_a2, "render cell", itemId, columnId);
|
|
1089
|
+
});
|
|
1090
|
+
const className2 = useTheme((t) => cx(...calcClassNames(t.classes, item, rowIndex)));
|
|
1062
1091
|
if (!column || !item)
|
|
1063
1092
|
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
1093
|
const content = column.renderCell(column.value(item), item);
|
|
1067
1094
|
return jsxRuntime.jsx("div", {
|
|
1068
|
-
className:
|
|
1069
|
-
css: [tableTheme.defaultClasses.cell,
|
|
1070
|
-
children:
|
|
1071
|
-
css: tableTheme.defaultClasses.text,
|
|
1072
|
-
title: content,
|
|
1073
|
-
children: content
|
|
1074
|
-
}) : content
|
|
1095
|
+
className: className2,
|
|
1096
|
+
css: [tableTheme.defaultClasses.cell, columnStyleOverride],
|
|
1097
|
+
children: wrapCell(content, column.value(item), item, rowIndex)
|
|
1075
1098
|
});
|
|
1076
1099
|
});
|
|
1077
1100
|
function ExpandControl({
|
|
1078
1101
|
itemId,
|
|
1079
1102
|
hasDeferredChildren
|
|
1080
1103
|
}) {
|
|
1081
|
-
const
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
Spinner: Spinner2
|
|
1085
|
-
},
|
|
1086
|
-
icons: {
|
|
1087
|
-
ChevronRight: ChevronRight2
|
|
1088
|
-
}
|
|
1089
|
-
} = useTheme();
|
|
1104
|
+
const IconButton2 = useTheme((t) => t.components.IconButton);
|
|
1105
|
+
const Spinner2 = useTheme((t) => t.components.Spinner);
|
|
1106
|
+
const ChevronRight2 = useTheme((t) => t.icons.ChevronRight);
|
|
1090
1107
|
const table = useTableContext();
|
|
1091
1108
|
const isExpanded = table.useState((state) => state.expanded.has(itemId));
|
|
1092
1109
|
const hasChildren = table.useState((state) => {
|
|
@@ -1145,11 +1162,7 @@ function SelectComponent({
|
|
|
1145
1162
|
itemId
|
|
1146
1163
|
}) {
|
|
1147
1164
|
const table = useTableContext();
|
|
1148
|
-
const
|
|
1149
|
-
components: {
|
|
1150
|
-
Checkbox: Checkbox2
|
|
1151
|
-
}
|
|
1152
|
-
} = useTheme();
|
|
1165
|
+
const Checkbox2 = useTheme((t) => t.components.Checkbox);
|
|
1153
1166
|
const isSelected = table.useState((state) => {
|
|
1154
1167
|
const itemIds = itemId ? [itemId] : Array.from(state.activeItemsById.keys());
|
|
1155
1168
|
return state.activeItemsById.size > 0 && itemIds.every((itemId2) => state.selection.has(itemId2));
|
|
@@ -1217,9 +1230,9 @@ const Row = react.memo(function Row2({
|
|
|
1217
1230
|
itemId,
|
|
1218
1231
|
rowIndex
|
|
1219
1232
|
}) {
|
|
1220
|
-
var _a, _b;
|
|
1221
1233
|
const table = useTableContext();
|
|
1222
1234
|
const divRef = react.useRef(null);
|
|
1235
|
+
const classes = useTheme((t) => t.classes);
|
|
1223
1236
|
const {
|
|
1224
1237
|
className: className2,
|
|
1225
1238
|
indent,
|
|
@@ -1229,17 +1242,16 @@ const Row = react.memo(function Row2({
|
|
|
1229
1242
|
enableSelection,
|
|
1230
1243
|
rowAction
|
|
1231
1244
|
} = table.useState((state) => {
|
|
1232
|
-
var
|
|
1245
|
+
var _a, _b;
|
|
1233
1246
|
const item = state.activeItemsById.get(itemId);
|
|
1234
|
-
const index = !item ? -1 : state.activeItems.indexOf(item);
|
|
1235
1247
|
return {
|
|
1236
|
-
className: cx(...calcClassNames(
|
|
1248
|
+
className: cx(...calcClassNames(classes, item, rowIndex)),
|
|
1237
1249
|
indent: item ? getAncestors(state.activeItemsById, item).size : 0,
|
|
1238
1250
|
hasChildren: !!(item == null ? void 0 : item.children.length),
|
|
1239
|
-
hasDeferredChildren: item && ((
|
|
1251
|
+
hasDeferredChildren: item && ((_b = (_a = state.props).hasDeferredChildren) == null ? void 0 : _b.call(_a, item)),
|
|
1240
1252
|
columnIds: state.activeColumns.map((column) => column.id),
|
|
1241
1253
|
enableSelection: state.props.enableSelection,
|
|
1242
|
-
rowAction: state.props.rowAction instanceof Function ? item ? state.props.rowAction(item,
|
|
1254
|
+
rowAction: state.props.rowAction instanceof Function ? item ? state.props.rowAction(item, rowIndex) : null : state.props.rowAction
|
|
1243
1255
|
};
|
|
1244
1256
|
});
|
|
1245
1257
|
react.useEffect(() => {
|
|
@@ -1256,7 +1268,10 @@ const Row = react.memo(function Row2({
|
|
|
1256
1268
|
o.observe(div);
|
|
1257
1269
|
return () => o.disconnect();
|
|
1258
1270
|
}, [divRef.current]);
|
|
1259
|
-
(
|
|
1271
|
+
react.useLayoutEffect(() => {
|
|
1272
|
+
var _a, _b;
|
|
1273
|
+
return (_b = (_a = table.getState().props).debugRender) == null ? void 0 : _b.call(_a, "render row", itemId);
|
|
1274
|
+
});
|
|
1260
1275
|
return jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
|
1261
1276
|
children: [jsxRuntime.jsx("div", {
|
|
1262
1277
|
className: className2,
|
|
@@ -1292,14 +1307,8 @@ function SortComponent({
|
|
|
1292
1307
|
}) {
|
|
1293
1308
|
const table = useTableContext();
|
|
1294
1309
|
const columnId = useColumnContext();
|
|
1295
|
-
const
|
|
1296
|
-
|
|
1297
|
-
Badge: Badge2
|
|
1298
|
-
},
|
|
1299
|
-
icons: {
|
|
1300
|
-
ArrowUpward: ArrowUpward2
|
|
1301
|
-
}
|
|
1302
|
-
} = useTheme();
|
|
1310
|
+
const Badge2 = useTheme((t) => t.components.Badge);
|
|
1311
|
+
const ArrowUpward2 = useTheme((t) => t.icons.ArrowUpward);
|
|
1303
1312
|
const {
|
|
1304
1313
|
direction,
|
|
1305
1314
|
index
|
|
@@ -1393,6 +1402,11 @@ function throttle(fn, ms) {
|
|
|
1393
1402
|
if (lastArgs) {
|
|
1394
1403
|
run();
|
|
1395
1404
|
}
|
|
1405
|
+
},
|
|
1406
|
+
cancel() {
|
|
1407
|
+
if (timeout) {
|
|
1408
|
+
clearTimeout(timeout);
|
|
1409
|
+
}
|
|
1396
1410
|
}
|
|
1397
1411
|
});
|
|
1398
1412
|
}
|
|
@@ -1419,7 +1433,7 @@ function Virtualized(_c) {
|
|
|
1419
1433
|
"header",
|
|
1420
1434
|
"children"
|
|
1421
1435
|
]);
|
|
1422
|
-
var _a, _b
|
|
1436
|
+
var _a, _b;
|
|
1423
1437
|
const table = useTableContext();
|
|
1424
1438
|
const virtual = table.useState("props.virtual");
|
|
1425
1439
|
const probeRef = react.useRef(null);
|
|
@@ -1493,7 +1507,11 @@ function Virtualized(_c) {
|
|
|
1493
1507
|
window.removeEventListener("resize", incCounter, true);
|
|
1494
1508
|
};
|
|
1495
1509
|
}, [probeRef.current, incCounter]);
|
|
1496
|
-
(
|
|
1510
|
+
react.useEffect(() => incCounter.cancel, [incCounter]);
|
|
1511
|
+
react.useLayoutEffect(() => {
|
|
1512
|
+
var _a2, _b2;
|
|
1513
|
+
return (_b2 = (_a2 = table.getState().props).debugRender) == null ? void 0 : _b2.call(_a2, `Virtualalized render ${from} to ${to}`);
|
|
1514
|
+
});
|
|
1497
1515
|
return jsxRuntime.jsxs("div", __spreadProps(__spreadValues({}, props), {
|
|
1498
1516
|
children: [header, virtual && jsxRuntime.jsx("div", {
|
|
1499
1517
|
style: {
|
|
@@ -1524,18 +1542,20 @@ function useColumnContext() {
|
|
|
1524
1542
|
return value;
|
|
1525
1543
|
}
|
|
1526
1544
|
function Table(props) {
|
|
1527
|
-
var _a, _b;
|
|
1528
1545
|
const table = useTableState(props);
|
|
1529
|
-
(
|
|
1546
|
+
react.useLayoutEffect(() => {
|
|
1547
|
+
var _a, _b;
|
|
1548
|
+
return (_b = (_a = table.getState().props).debugRender) == null ? void 0 : _b.call(_a, "render table");
|
|
1549
|
+
});
|
|
1530
1550
|
return jsxRuntime.jsx(TableContext.Provider, {
|
|
1531
1551
|
value: table,
|
|
1532
|
-
children: jsxRuntime.jsx(
|
|
1552
|
+
children: jsxRuntime.jsx(TableMemoContextProvider, {
|
|
1553
|
+
children: jsxRuntime.jsx(TableLoadingState, {})
|
|
1554
|
+
})
|
|
1533
1555
|
});
|
|
1534
1556
|
}
|
|
1535
1557
|
function TableLoadingState() {
|
|
1536
|
-
const
|
|
1537
|
-
text
|
|
1538
|
-
} = useTheme();
|
|
1558
|
+
const loadingText = useTheme((t) => t.text.loading);
|
|
1539
1559
|
const isHydrated = useTableStateStorage();
|
|
1540
1560
|
const [showLoading, setShowLoading] = react.useState(false);
|
|
1541
1561
|
react.useEffect(() => {
|
|
@@ -1544,7 +1564,7 @@ function TableLoadingState() {
|
|
|
1544
1564
|
});
|
|
1545
1565
|
return jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
|
1546
1566
|
children: [!isHydrated && showLoading && jsxRuntime.jsx("div", {
|
|
1547
|
-
children:
|
|
1567
|
+
children: loadingText
|
|
1548
1568
|
}), jsxRuntime.jsx(TableInner, {
|
|
1549
1569
|
hidden: !isHydrated
|
|
1550
1570
|
})]
|
|
@@ -1553,7 +1573,6 @@ function TableLoadingState() {
|
|
|
1553
1573
|
const TableInner = react.memo(function TableInner2({
|
|
1554
1574
|
hidden
|
|
1555
1575
|
}) {
|
|
1556
|
-
var _a, _b;
|
|
1557
1576
|
const table = useTableContext();
|
|
1558
1577
|
const fullWidth = table.useState("props.fullWidth");
|
|
1559
1578
|
const activeColumns = table.useState((state) => state.activeColumns.map((column) => ({
|
|
@@ -1568,14 +1587,16 @@ const TableInner = react.memo(function TableInner2({
|
|
|
1568
1587
|
const columnStyleOverride = table.useState("columnStyleOverride", {
|
|
1569
1588
|
throttle: 16
|
|
1570
1589
|
});
|
|
1571
|
-
const defaultWidth = table.useState("props.defaultWidth");
|
|
1572
1590
|
const classes = table.useState("props.classes");
|
|
1573
1591
|
const stickyHeader = table.useState("props.stickyHeader");
|
|
1574
1592
|
const enableSelection = table.useState("props.enableSelection");
|
|
1575
1593
|
const enableColumnSelection = table.useState("props.enableColumnSelection");
|
|
1576
1594
|
const enableExport = table.useState((state) => !!state.props.enableExport.copy || !!state.props.enableExport.download);
|
|
1577
1595
|
const cssVariables = useCssVariables();
|
|
1578
|
-
(
|
|
1596
|
+
react.useLayoutEffect(() => {
|
|
1597
|
+
var _a, _b;
|
|
1598
|
+
return (_b = (_a = table.getState().props).debugRender) == null ? void 0 : _b.call(_a, "render table inner");
|
|
1599
|
+
});
|
|
1579
1600
|
return jsxRuntime.jsx(Virtualized, {
|
|
1580
1601
|
className: classes == null ? void 0 : classes.table,
|
|
1581
1602
|
css: [cssVariables, tableTheme.defaultClasses.table, {
|
|
@@ -1583,8 +1604,8 @@ const TableInner = react.memo(function TableInner2({
|
|
|
1583
1604
|
fullWidth === "right" || fullWidth === true ? "auto" : "0",
|
|
1584
1605
|
"max-content",
|
|
1585
1606
|
...activeColumns.map((column) => {
|
|
1586
|
-
var
|
|
1587
|
-
return (
|
|
1607
|
+
var _a, _b;
|
|
1608
|
+
return (_b = (_a = columnWidths.get(column.id)) != null ? _a : column.width) != null ? _b : "max-content";
|
|
1588
1609
|
}),
|
|
1589
1610
|
fullWidth === "left" || fullWidth === true ? "auto" : "0"
|
|
1590
1611
|
].join(" ")
|
|
@@ -1601,11 +1622,11 @@ const TableInner = react.memo(function TableInner2({
|
|
|
1601
1622
|
children: [enableSelection && jsxRuntime.jsx(SelectComponent, {}), enableColumnSelection && jsxRuntime.jsx(ColumnSelection, {}), enableExport && jsxRuntime.jsx(Export$1, {}), jsxRuntime.jsx(ResizeHandleView, {})]
|
|
1602
1623
|
}), jsxRuntime.jsx(ColumnHeaderContext.Provider, {
|
|
1603
1624
|
children: activeColumns.map((column) => {
|
|
1604
|
-
var
|
|
1625
|
+
var _a;
|
|
1605
1626
|
return jsxRuntime.jsx(ColumnContext.Provider, {
|
|
1606
1627
|
value: column.id,
|
|
1607
1628
|
children: jsxRuntime.jsxs(ColumnHeader, {
|
|
1608
|
-
className: cx(classes == null ? void 0 : classes.headerCell, (
|
|
1629
|
+
className: cx(classes == null ? void 0 : classes.headerCell, (_a = column.classes) == null ? void 0 : _a.headerCell),
|
|
1609
1630
|
css: [tableTheme.defaultClasses.headerCell, columnStyleOverride.get(column.id), stickyHeader && tableTheme.defaultClasses.sticky, stickyHeader instanceof Object && stickyHeader],
|
|
1610
1631
|
children: [jsxRuntime.jsx(SortComponent, {
|
|
1611
1632
|
children: column.header
|
|
@@ -2063,26 +2084,45 @@ const defaultTableTheme = {
|
|
|
2063
2084
|
spacing: "5px"
|
|
2064
2085
|
};
|
|
2065
2086
|
const emptyStore = new react$1.Store(void 0);
|
|
2066
|
-
function useTheme() {
|
|
2087
|
+
function useTheme(selector) {
|
|
2067
2088
|
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
2089
|
const contextTableTheme = react.useContext(tableTheme.TableThemeContext);
|
|
2078
|
-
|
|
2090
|
+
const table = react.useContext(TableContext);
|
|
2091
|
+
const columnId = react.useContext(ColumnContext);
|
|
2092
|
+
const memo = useTableMemo();
|
|
2093
|
+
const process = (t) => {
|
|
2094
|
+
var _a2;
|
|
2095
|
+
const cell = (_a2 = t.classes) == null ? void 0 : _a2.cell;
|
|
2096
|
+
const selected = t.text.selected;
|
|
2097
|
+
return __spreadProps(__spreadValues({}, t), {
|
|
2098
|
+
classes: __spreadProps(__spreadValues({}, t.classes), {
|
|
2099
|
+
cell: cell instanceof Function || Array.isArray(cell) ? memo("theme.classes.cell", cell) : cell
|
|
2100
|
+
}),
|
|
2101
|
+
text: __spreadProps(__spreadValues({}, t.text), {
|
|
2102
|
+
selected: selected instanceof Function || Array.isArray(selected) ? memo("theme.text.selected", selected) : selected
|
|
2103
|
+
})
|
|
2104
|
+
});
|
|
2105
|
+
};
|
|
2106
|
+
const theme = (_b = (_a = table == null ? void 0 : table.useState((state) => {
|
|
2107
|
+
const localTheme = {
|
|
2108
|
+
text: state.props.text,
|
|
2109
|
+
classes: state.props.classes,
|
|
2110
|
+
components: state.props.components,
|
|
2111
|
+
icons: state.props.icons,
|
|
2112
|
+
colors: state.props.colors,
|
|
2113
|
+
spacing: state.props.spacing
|
|
2114
|
+
};
|
|
2115
|
+
const column = state.activeColumns.find((column2) => column2.id === columnId);
|
|
2116
|
+
const columnsTheme = {
|
|
2117
|
+
classes: column == null ? void 0 : column.classes
|
|
2118
|
+
};
|
|
2119
|
+
const theme2 = tableTheme.mergeThemes(defaultTableTheme, tableTheme.globalTableTheme, contextTableTheme, localTheme, columnsTheme);
|
|
2120
|
+
return selector(process(theme2));
|
|
2121
|
+
})) != null ? _a : emptyStore.useState()) != null ? _b : selector(process(tableTheme.mergeThemes(defaultTableTheme, tableTheme.globalTableTheme, contextTableTheme)));
|
|
2122
|
+
return theme;
|
|
2079
2123
|
}
|
|
2080
2124
|
function AutoFocusTextField(props) {
|
|
2081
|
-
const
|
|
2082
|
-
components: {
|
|
2083
|
-
TextField: TextField2
|
|
2084
|
-
}
|
|
2085
|
-
} = useTheme();
|
|
2125
|
+
const TextField2 = useTheme((t) => t.components.TextField);
|
|
2086
2126
|
const ref = react.useRef(null);
|
|
2087
2127
|
const {
|
|
2088
2128
|
visible
|
|
@@ -2242,16 +2282,12 @@ function DatePicker({
|
|
|
2242
2282
|
locale,
|
|
2243
2283
|
firstDayOfWeek = 0
|
|
2244
2284
|
}) {
|
|
2245
|
-
const
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
ChevronRight: ChevronRight2
|
|
2252
|
-
},
|
|
2253
|
-
text
|
|
2254
|
-
} = useTheme();
|
|
2285
|
+
const Button2 = useTheme((t) => t.components.Button);
|
|
2286
|
+
const IconButton2 = useTheme((t) => t.components.IconButton);
|
|
2287
|
+
const ChevronRight2 = useTheme((t) => t.icons.ChevronRight);
|
|
2288
|
+
const textToday = useTheme((t) => t.text.today);
|
|
2289
|
+
const textThisWeek = useTheme((t) => t.text.thisWeek);
|
|
2290
|
+
const textReset = useTheme((t) => t.text.reset);
|
|
2255
2291
|
const [baseDate] = react.useState(new Date());
|
|
2256
2292
|
const [dateInView, setDateInView] = react.useState(baseDate);
|
|
2257
2293
|
const [dirty, setDirty] = react.useState();
|
|
@@ -2465,21 +2501,21 @@ function DatePicker({
|
|
|
2465
2501
|
setDirty(void 0);
|
|
2466
2502
|
onChange(today());
|
|
2467
2503
|
},
|
|
2468
|
-
children:
|
|
2504
|
+
children: textToday
|
|
2469
2505
|
}), jsxRuntime.jsx(Button2, {
|
|
2470
2506
|
variant: "text",
|
|
2471
2507
|
onClick: () => {
|
|
2472
2508
|
setDirty(void 0);
|
|
2473
2509
|
onChange(thisWeek(firstDayOfWeek));
|
|
2474
2510
|
},
|
|
2475
|
-
children:
|
|
2511
|
+
children: textThisWeek
|
|
2476
2512
|
}), jsxRuntime.jsx(Button2, {
|
|
2477
2513
|
variant: "text",
|
|
2478
2514
|
onClick: () => {
|
|
2479
2515
|
setDirty(void 0);
|
|
2480
2516
|
onChange(null);
|
|
2481
2517
|
},
|
|
2482
|
-
children:
|
|
2518
|
+
children: textReset
|
|
2483
2519
|
})]
|
|
2484
2520
|
})]
|
|
2485
2521
|
});
|
|
@@ -2566,34 +2602,18 @@ function SelectFilter(_m) {
|
|
|
2566
2602
|
"render",
|
|
2567
2603
|
"singleSelect"
|
|
2568
2604
|
]);
|
|
2569
|
-
const
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
Search: Search2,
|
|
2576
|
-
Clear: Clear2
|
|
2577
|
-
},
|
|
2578
|
-
text
|
|
2579
|
-
} = useTheme();
|
|
2605
|
+
const IconButton2 = useTheme((t) => t.components.IconButton);
|
|
2606
|
+
const Checkbox2 = useTheme((t) => t.components.Checkbox);
|
|
2607
|
+
const Search2 = useTheme((t) => t.icons.Search);
|
|
2608
|
+
const Clear2 = useTheme((t) => t.icons.Clear);
|
|
2609
|
+
const selected = useTheme((t) => t.text.selected);
|
|
2610
|
+
const noResults = useTheme((t) => t.text.noResults);
|
|
2580
2611
|
const table = useTableContext();
|
|
2581
2612
|
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
2613
|
const {
|
|
2595
2614
|
value = /* @__PURE__ */ new Set(),
|
|
2596
|
-
onChange
|
|
2615
|
+
onChange,
|
|
2616
|
+
filterBy
|
|
2597
2617
|
} = useFilter(__spreadProps(__spreadValues({}, props), {
|
|
2598
2618
|
id: "selectFilter",
|
|
2599
2619
|
isActive(filterValue) {
|
|
@@ -2603,6 +2623,16 @@ function SelectFilter(_m) {
|
|
|
2603
2623
|
return filterValue.has(value2);
|
|
2604
2624
|
}
|
|
2605
2625
|
}));
|
|
2626
|
+
const options = table.useState((state) => {
|
|
2627
|
+
if (providedOptions)
|
|
2628
|
+
return uniq(providedOptions);
|
|
2629
|
+
const column = state.activeColumns.find((column2) => column2.id === columnId);
|
|
2630
|
+
if (!column)
|
|
2631
|
+
return [];
|
|
2632
|
+
return uniq(flatMap(state.items, (item) => castArray(filterBy(column.value(item), item))));
|
|
2633
|
+
});
|
|
2634
|
+
const [query, setQuery] = react.useState("");
|
|
2635
|
+
const filtered = options.filter((option) => !query || stringValue(option).toLowerCase().includes(query.toLowerCase()));
|
|
2606
2636
|
return jsxRuntime.jsxs("div", {
|
|
2607
2637
|
css: {
|
|
2608
2638
|
padding: "calc(var(--spacing) * 2)",
|
|
@@ -2632,7 +2662,7 @@ function SelectFilter(_m) {
|
|
|
2632
2662
|
onChange: () => onChange(/* @__PURE__ */ new Set())
|
|
2633
2663
|
}),
|
|
2634
2664
|
label: jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
|
2635
|
-
children: ["<",
|
|
2665
|
+
children: ["<", selected(value.size), ">"]
|
|
2636
2666
|
})
|
|
2637
2667
|
}), filtered.map((option, index) => jsxRuntime.jsx(FormControlLabel, {
|
|
2638
2668
|
control: jsxRuntime.jsx(Checkbox2, {
|
|
@@ -2645,7 +2675,7 @@ function SelectFilter(_m) {
|
|
|
2645
2675
|
css: {
|
|
2646
2676
|
textAlign: "center"
|
|
2647
2677
|
},
|
|
2648
|
-
children:
|
|
2678
|
+
children: noResults
|
|
2649
2679
|
})]
|
|
2650
2680
|
});
|
|
2651
2681
|
}
|
|
@@ -2676,6 +2706,8 @@ function debounce(fn, ms) {
|
|
|
2676
2706
|
function useFilter(impl) {
|
|
2677
2707
|
const table = useTableContext();
|
|
2678
2708
|
const columnId = useColumnContext();
|
|
2709
|
+
const cache = useTableMemo();
|
|
2710
|
+
const filterBy = impl.filterBy && cache("", impl.filterBy);
|
|
2679
2711
|
react.useEffect(() => {
|
|
2680
2712
|
table.update((state) => {
|
|
2681
2713
|
if (impl.defaultValue !== void 0) {
|
|
@@ -2685,7 +2717,7 @@ function useFilter(impl) {
|
|
|
2685
2717
|
}, []);
|
|
2686
2718
|
react.useEffect(() => {
|
|
2687
2719
|
table.update((state) => {
|
|
2688
|
-
state.filters.set(columnId, immer.castDraft(impl));
|
|
2720
|
+
state.filters.set(columnId, immer.castDraft(__spreadProps(__spreadValues({}, impl), { filterBy })));
|
|
2689
2721
|
if (impl.value !== void 0) {
|
|
2690
2722
|
state.filterValues.set(columnId, impl.value);
|
|
2691
2723
|
}
|
|
@@ -2720,7 +2752,8 @@ function useFilter(impl) {
|
|
|
2720
2752
|
return {
|
|
2721
2753
|
value: dirtyValue != null ? dirtyValue : value,
|
|
2722
2754
|
onChange,
|
|
2723
|
-
close: react.useContext(FilterControlContext)
|
|
2755
|
+
close: react.useContext(FilterControlContext),
|
|
2756
|
+
filterBy: filterBy != null ? filterBy : (x) => x
|
|
2724
2757
|
};
|
|
2725
2758
|
}
|
|
2726
2759
|
const textMatch = (text, query) => {
|
|
@@ -2750,15 +2783,9 @@ function TextFilter(_o) {
|
|
|
2750
2783
|
"compare",
|
|
2751
2784
|
"filterBy"
|
|
2752
2785
|
]);
|
|
2753
|
-
const
|
|
2754
|
-
|
|
2755
|
-
|
|
2756
|
-
},
|
|
2757
|
-
icons: {
|
|
2758
|
-
Search: Search2,
|
|
2759
|
-
Clear: Clear2
|
|
2760
|
-
}
|
|
2761
|
-
} = useTheme();
|
|
2786
|
+
const IconButton2 = useTheme((t) => t.components.IconButton);
|
|
2787
|
+
const Search2 = useTheme((t) => t.icons.Search);
|
|
2788
|
+
const Clear2 = useTheme((t) => t.icons.Clear);
|
|
2762
2789
|
const {
|
|
2763
2790
|
value = "",
|
|
2764
2791
|
onChange
|