@symply.io/basic-components 1.6.11-alpha.6 → 1.7.0-alpha.2

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.
Files changed (38) hide show
  1. package/DataTable/{TableCore/TableBody.d.ts → TableBody.d.ts} +1 -1
  2. package/DataTable/TableBody.js +32 -0
  3. package/DataTable/{TableCore/TableBodyRow.d.ts → TableBodyRow.d.ts} +1 -1
  4. package/DataTable/{TableCore/TableBodyRow.js → TableBodyRow.js} +14 -19
  5. package/DataTable/TableFooter.d.ts +3 -0
  6. package/DataTable/{TableCore/TableFooter.js → TableFooter.js} +5 -7
  7. package/DataTable/TableHeader.d.ts +3 -0
  8. package/DataTable/{TableCore/TableHeader.js → TableHeader.js} +5 -7
  9. package/DataTable/index.js +42 -16
  10. package/DataTable/types.d.ts +10 -23
  11. package/DataTable/useTable.d.ts +2 -2
  12. package/DataTable/useTable.js +3 -3
  13. package/README.md +71 -0
  14. package/VirtualGrid/GridCore/GridBody.d.ts +4 -0
  15. package/{DataTable/TableCore/TableBody.js → VirtualGrid/GridCore/GridBody.js} +8 -7
  16. package/VirtualGrid/GridCore/GridBodyRow.d.ts +4 -0
  17. package/VirtualGrid/GridCore/GridBodyRow.js +145 -0
  18. package/VirtualGrid/GridCore/GridFooter.d.ts +4 -0
  19. package/VirtualGrid/GridCore/GridFooter.js +109 -0
  20. package/VirtualGrid/GridCore/GridHeader.d.ts +4 -0
  21. package/VirtualGrid/GridCore/GridHeader.js +114 -0
  22. package/VirtualGrid/GridCore/index.d.ts +4 -0
  23. package/{DataTable/TableCore → VirtualGrid/GridCore}/index.js +10 -8
  24. package/VirtualGrid/GridVirtualizerContext.d.ts +3 -0
  25. package/{DataTable/VirtualizerContext.js → VirtualGrid/GridVirtualizerContext.js} +24 -16
  26. package/VirtualGrid/index.d.ts +6 -0
  27. package/VirtualGrid/index.js +36 -0
  28. package/VirtualGrid/types.d.ts +106 -0
  29. package/VirtualGrid/types.js +1 -0
  30. package/VirtualGrid/useVirtualGrid.d.ts +3 -0
  31. package/VirtualGrid/useVirtualGrid.js +103 -0
  32. package/index.d.ts +2 -0
  33. package/index.js +2 -0
  34. package/package.json +1 -1
  35. package/DataTable/TableCore/TableFooter.d.ts +0 -5
  36. package/DataTable/TableCore/TableHeader.d.ts +0 -5
  37. package/DataTable/TableCore/index.d.ts +0 -3
  38. package/DataTable/VirtualizerContext.d.ts +0 -3
@@ -0,0 +1,145 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
13
+ import { memo, cloneElement, useState, useMemo } from "react";
14
+ import TableRow from "@mui/material/TableRow";
15
+ import TableCell from "@mui/material/TableCell";
16
+ import useMediaQuery from "@mui/material/useMediaQuery";
17
+ import useTheme from "@mui/material/styles/useTheme";
18
+ import { useGridVirtualizer } from "../GridVirtualizerContext";
19
+ function VirtualGridBodyRow(props) {
20
+ var rows = props.rows, columns = props.columns, rowIndex = props.rowIndex, virtualRow = props.virtualRow, onRowClick = props.onRowClick, onContextMenu = props.onContextMenu, onCustomizeRowBgColor = props.onCustomizeRowBgColor;
21
+ console.log({ virtualRow: virtualRow });
22
+ var theme = useTheme();
23
+ var isUpMd = useMediaQuery(theme.breakpoints.up("md"));
24
+ var _a = useGridVirtualizer(), leftShadowVisible = _a.leftShadowVisible, rightShadowVisible = _a.rightShadowVisible, onMeasureElement = _a.onMeasureElement;
25
+ var row = useMemo(function () { return rows[virtualRow.index]; }, [rows, virtualRow]);
26
+ var _b = useMemo(function () {
27
+ if (isUpMd) {
28
+ var left = columns.filter(function (c) { return c.fixable === "left"; });
29
+ var right = columns.filter(function (c) { return c.fixable === "right"; });
30
+ var dynamic = columns.filter(function (c) { return !c.fixable; });
31
+ return [left, dynamic, right];
32
+ }
33
+ else {
34
+ return [[], columns, []];
35
+ }
36
+ }, [isUpMd, columns]), fixedLeftCols = _b[0], dynamicCols = _b[1], fixedRightCols = _b[2];
37
+ var _c = useMemo(function () {
38
+ if (onCustomizeRowBgColor) {
39
+ var regex = /^#(\d|[a-f]|[A-F]){6}/i;
40
+ var _a = onCustomizeRowBgColor({ row: row, columns: columns }), normal_1 = _a.normal, hover_1 = _a.hover;
41
+ return {
42
+ normal: normal_1 && regex.test(normal_1) ? normal_1 : "#FEFEFE",
43
+ hover: hover_1 && regex.test(hover_1) ? hover_1 : "#F2F1F3",
44
+ };
45
+ }
46
+ return { normal: "#FEFEFE", hover: "#F2F1F3" };
47
+ }, [row, columns, onCustomizeRowBgColor]), normal = _c.normal, hover = _c.hover;
48
+ var _d = useState(), rowEl = _d[0], setRowEl = _d[1];
49
+ return (_jsxs(TableRow, __assign({ sx: {
50
+ backgroundColor: normal,
51
+ width: "100%",
52
+ height: "".concat(virtualRow.size, "px"),
53
+ transform: "translateY(".concat(virtualRow.start - rowIndex * virtualRow.size, "px)"),
54
+ "&:hover": {
55
+ cursor: onRowClick ? "pointer" : "default",
56
+ backgroundColor: onRowClick ? hover : normal,
57
+ },
58
+ }, "data-index": virtualRow.index, onMouseEnter: function (event) {
59
+ setRowEl(event.currentTarget);
60
+ }, onMouseLeave: function () {
61
+ setRowEl(undefined);
62
+ }, onClick: onRowClick
63
+ ? function () {
64
+ onRowClick(row);
65
+ }
66
+ : undefined, onContextMenu: function (event) {
67
+ event.preventDefault();
68
+ if (onContextMenu) {
69
+ onContextMenu(event, row);
70
+ }
71
+ } }, { children: [fixedLeftCols.map(function (col, index) {
72
+ var accessor = col.accessor, Cell = col.Cell, width = col.width, _a = col.align, align = _a === void 0 ? "center" : _a;
73
+ var left = fixedLeftCols
74
+ .slice(0, index)
75
+ .reduce(function (w, t) { return w + (t.width || 0); }, 0);
76
+ return (_jsx(TableCell, __assign({ align: align, sx: {
77
+ left: left,
78
+ zIndex: 10,
79
+ position: "sticky",
80
+ width: width,
81
+ backgroundColor: onRowClick && rowEl ? hover : normal,
82
+ "&::after": index === fixedLeftCols.length - 1 && leftShadowVisible
83
+ ? {
84
+ position: "absolute",
85
+ top: 0,
86
+ right: 0,
87
+ bottom: "-1px",
88
+ width: "20px",
89
+ transform: "translateX(100%)",
90
+ transition: "box-shadow .3s",
91
+ content: "''",
92
+ boxShadow: "inset 10px 0 10px -8px rgba(0, 0, 0, 0.1)",
93
+ }
94
+ : undefined,
95
+ } }, { children: cloneElement(Cell, {
96
+ column: col,
97
+ rows: rows,
98
+ row: row,
99
+ rowIndex: virtualRow.index,
100
+ }) }), "Virtual_Grid_Body_Row_".concat(virtualRow.index, "_").concat(accessor)));
101
+ }), dynamicCols.map(function (col) {
102
+ var accessor = col.accessor, Cell = col.Cell, width = col.width, _a = col.align, align = _a === void 0 ? "center" : _a;
103
+ return (_jsx(TableCell, __assign({ align: align, sx: {
104
+ zIndex: 9,
105
+ width: width,
106
+ backgroundColor: onRowClick && rowEl ? hover : normal,
107
+ } }, { children: cloneElement(Cell, {
108
+ column: col,
109
+ rows: rows,
110
+ row: row,
111
+ rowIndex: virtualRow.index,
112
+ }) }), "Virtual_Grid_Body_Row_".concat(virtualRow.index, "_").concat(accessor)));
113
+ }), fixedRightCols.map(function (col, index) {
114
+ var accessor = col.accessor, Cell = col.Cell, width = col.width, _a = col.align, align = _a === void 0 ? "center" : _a;
115
+ var right = fixedRightCols
116
+ .slice(0, fixedRightCols.length - 1 - index)
117
+ .reduce(function (w, t) { return w + (t.width || 0); }, 0);
118
+ return (_jsx(TableCell, __assign({ align: align, sx: {
119
+ right: right,
120
+ width: width,
121
+ position: "sticky",
122
+ zIndex: 10,
123
+ backgroundColor: onRowClick && rowEl ? hover : normal,
124
+ "&::after": index === 0 && rightShadowVisible
125
+ ? {
126
+ position: "absolute",
127
+ top: 0,
128
+ left: 0,
129
+ bottom: "-1px",
130
+ width: "20px",
131
+ transform: "translateX(-100%)",
132
+ transition: "box-shadow .3s",
133
+ content: "''",
134
+ boxShadow: "inset -10px 0 10px -8px rgba(0, 0, 0, 0.1)",
135
+ }
136
+ : undefined,
137
+ } }, { children: cloneElement(Cell, {
138
+ column: col,
139
+ rows: rows,
140
+ row: row,
141
+ rowIndex: virtualRow.index,
142
+ }) }), "Virtual_Grid_Body_Row_".concat(virtualRow.index, "_").concat(accessor)));
143
+ })] })));
144
+ }
145
+ export default memo(VirtualGridBodyRow);
@@ -0,0 +1,4 @@
1
+ import type { VirtualGridFooterProps } from "../types";
2
+ declare function VirtualGridFooter<RowProps extends Record<string, any>, ExtendedProps extends Record<string, any>>(props: VirtualGridFooterProps<RowProps, ExtendedProps>): import("react/jsx-runtime").JSX.Element;
3
+ declare const _default: typeof VirtualGridFooter;
4
+ export default _default;
@@ -0,0 +1,109 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
13
+ import { memo, cloneElement, useMemo } from "react";
14
+ import TableRow from "@mui/material/TableRow";
15
+ import Footer from "@mui/material/TableFooter";
16
+ import TableCell from "@mui/material/TableCell";
17
+ import useMediaQuery from "@mui/material/useMediaQuery";
18
+ import useTheme from "@mui/material/styles/useTheme";
19
+ import { useGridVirtualizer } from "../GridVirtualizerContext";
20
+ function VirtualGridFooter(props) {
21
+ var _a = props.footers, footers = _a === void 0 ? [] : _a, footerBgColor = props.footerBgColor, footerTextColor = props.footerTextColor, noData = props.noData;
22
+ var theme = useTheme();
23
+ var isUpMd = useMediaQuery(theme.breakpoints.up("md"));
24
+ var _b = useGridVirtualizer(), leftShadowVisible = _b.leftShadowVisible, rightShadowVisible = _b.rightShadowVisible;
25
+ var _c = useMemo(function () {
26
+ if (isUpMd && !noData) {
27
+ var left = footers.filter(function (f) { return f.fixable === "left"; });
28
+ var right = footers.filter(function (f) { return f.fixable === "right"; });
29
+ var dynamic = footers.filter(function (f) { return !f.fixable; });
30
+ return [left, dynamic, right];
31
+ }
32
+ else {
33
+ return [[], footers, []];
34
+ }
35
+ }, [isUpMd, noData, footers]), fixedLeftFooters = _c[0], dynamicFooters = _c[1], fixedRightFooters = _c[2];
36
+ return (_jsx(Footer, __assign({ sx: {
37
+ position: "sticky",
38
+ bottom: "-1px",
39
+ zIndex: 20,
40
+ } }, { children: _jsxs(TableRow, __assign({ sx: {
41
+ backgroundColor: "".concat(footerBgColor || "#eaf0f6", " !important"),
42
+ color: "".concat(footerTextColor || "inherit", " !important"),
43
+ width: "100%",
44
+ } }, { children: [fixedLeftFooters.map(function (footer, index) {
45
+ var accessor = footer.accessor, Cell = footer.Cell, _a = footer.align, align = _a === void 0 ? "center" : _a, width = footer.width;
46
+ var left = fixedLeftFooters
47
+ .slice(0, index)
48
+ .reduce(function (w, t) { return w + (t.width || 0); }, 0);
49
+ return (_jsx(TableCell, __assign({ align: align, sx: {
50
+ position: "sticky",
51
+ backgroundColor: "".concat(footerBgColor || "#eaf0f6", " !important"),
52
+ color: "".concat(footerTextColor || "inherit", " !important"),
53
+ zIndex: 10,
54
+ left: left,
55
+ width: width,
56
+ userSelect: "none",
57
+ "&::after": index === fixedLeftFooters.length - 1 && leftShadowVisible
58
+ ? {
59
+ position: "absolute",
60
+ top: 0,
61
+ right: 0,
62
+ bottom: "-1px",
63
+ width: "20px",
64
+ transform: "translateX(100%)",
65
+ transition: "box-shadow .3s",
66
+ content: "''",
67
+ boxShadow: "inset 10px 0 10px -8px rgba(0, 0, 0, 0.1)",
68
+ }
69
+ : undefined,
70
+ } }, { children: cloneElement(Cell) }), "Virtual_Grid_Footer_Col_".concat(accessor)));
71
+ }), dynamicFooters.map(function (footer) {
72
+ var accessor = footer.accessor, Cell = footer.Cell, _a = footer.align, align = _a === void 0 ? "center" : _a, width = footer.width;
73
+ return (_jsx(TableCell, __assign({ align: align, sx: {
74
+ zIndex: 9,
75
+ width: width,
76
+ userSelect: "none",
77
+ backgroundColor: "".concat(footerBgColor || "#eaf0f6", " !important"),
78
+ color: "".concat(footerTextColor || "inherit", " !important"),
79
+ } }, { children: cloneElement(Cell) }), "Virtual_Grid_Footer_Col_".concat(accessor)));
80
+ }), fixedRightFooters.map(function (footer, index) {
81
+ var accessor = footer.accessor, Cell = footer.Cell, _a = footer.align, align = _a === void 0 ? "center" : _a, width = footer.width;
82
+ var right = fixedRightFooters
83
+ .slice(0, fixedRightFooters.length - 1 - index)
84
+ .reduce(function (w, t) { return w + (t.width || 0); }, 0);
85
+ return (_jsx(TableCell, __assign({ align: align, sx: {
86
+ position: "sticky",
87
+ zIndex: 10,
88
+ right: right,
89
+ width: width,
90
+ backgroundColor: "".concat(footerBgColor || "#eaf0f6", " !important"),
91
+ color: "".concat(footerTextColor || "inherit", " !important"),
92
+ userSelect: "none",
93
+ "&::after": index === 0 && rightShadowVisible
94
+ ? {
95
+ position: "absolute",
96
+ top: 0,
97
+ left: 0,
98
+ bottom: "-1px",
99
+ width: "20px",
100
+ transform: "translateX(-100%)",
101
+ transition: "box-shadow .3s",
102
+ content: "''",
103
+ boxShadow: "inset -10px 0 10px -8px rgba(0, 0, 0, 0.1)",
104
+ }
105
+ : undefined,
106
+ } }, { children: cloneElement(Cell) }), "Virtual_Grid_Footer_Col_".concat(accessor)));
107
+ })] })) })));
108
+ }
109
+ export default memo(VirtualGridFooter);
@@ -0,0 +1,4 @@
1
+ import type { VirtualGridHeaderProps } from "../types";
2
+ declare function VirtualGridHeader<RowProps extends Record<string, any>, ExtendedProps extends Record<string, any>>(props: VirtualGridHeaderProps<RowProps, ExtendedProps>): import("react/jsx-runtime").JSX.Element;
3
+ declare const _default: typeof VirtualGridHeader;
4
+ export default _default;
@@ -0,0 +1,114 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
13
+ import { memo, cloneElement, useMemo } from "react";
14
+ import TableRow from "@mui/material/TableRow";
15
+ import TableHead from "@mui/material/TableHead";
16
+ import TableCell from "@mui/material/TableCell";
17
+ import useMediaQuery from "@mui/material/useMediaQuery";
18
+ import useTheme from "@mui/material/styles/useTheme";
19
+ import { useGridVirtualizer } from "../GridVirtualizerContext";
20
+ function VirtualGridHeader(props) {
21
+ var headers = props.headers, headerBgColor = props.headerBgColor, headerTextColor = props.headerTextColor, noData = props.noData;
22
+ var theme = useTheme();
23
+ var isUpMd = useMediaQuery(theme.breakpoints.up("md"));
24
+ var _a = useGridVirtualizer(), leftShadowVisible = _a.leftShadowVisible, rightShadowVisible = _a.rightShadowVisible;
25
+ var _b = useMemo(function () {
26
+ if (isUpMd && !noData) {
27
+ var left = headers.filter(function (h) { return h.fixable === "left"; });
28
+ var right = headers.filter(function (h) { return h.fixable === "right"; });
29
+ var dynamic = headers.filter(function (h) { return !h.fixable; });
30
+ return [left, dynamic, right];
31
+ }
32
+ else {
33
+ return [[], headers, []];
34
+ }
35
+ }, [isUpMd, noData, headers]), fixedLeftHeaders = _b[0], dynamicHeaders = _b[1], fixedRightHeaders = _b[2];
36
+ return (_jsx(TableHead, __assign({ sx: { position: "sticky", top: 0, zIndex: 20 } }, { children: _jsxs(TableRow, __assign({ sx: {
37
+ backgroundColor: "".concat(headerBgColor || "#eaf0f6", " !important"),
38
+ color: "".concat(headerTextColor || "inherit", " !important"),
39
+ width: "100%",
40
+ } }, { children: [fixedLeftHeaders.map(function (header, index) {
41
+ var accessor = header.accessor, Cell = header.Cell, _a = header.align, align = _a === void 0 ? "center" : _a, width = header.width, title = header.title, _b = header.sortable, sortable = _b === void 0 ? false : _b, onSort = header.onSort;
42
+ var left = fixedLeftHeaders
43
+ .slice(0, index)
44
+ .reduce(function (w, t) { return w + (t.width || 0); }, 0);
45
+ return (_jsx(TableCell, __assign({ title: title, align: align, sx: {
46
+ position: "sticky",
47
+ backgroundColor: "".concat(headerBgColor || "#eaf0f6", " !important"),
48
+ color: "".concat(headerTextColor || "inherit", " !important"),
49
+ zIndex: 10,
50
+ left: left,
51
+ width: width,
52
+ userSelect: "none",
53
+ cursor: sortable ? "pointer" : "default",
54
+ "&::after": index === fixedLeftHeaders.length - 1 && leftShadowVisible
55
+ ? {
56
+ position: "absolute",
57
+ top: 0,
58
+ right: 0,
59
+ bottom: "-1px",
60
+ width: "20px",
61
+ transform: "translateX(100%)",
62
+ transition: "box-shadow .3s",
63
+ content: "''",
64
+ boxShadow: "inset 10px 0 10px -8px rgba(0, 0, 0, 0.1)",
65
+ }
66
+ : undefined,
67
+ }, onClick: function () {
68
+ onSort({ accessor: accessor });
69
+ } }, { children: cloneElement(Cell) }), "Virtual_Grid_Header_Col_".concat(accessor)));
70
+ }), dynamicHeaders.map(function (header) {
71
+ var accessor = header.accessor, Cell = header.Cell, _a = header.align, align = _a === void 0 ? "center" : _a, width = header.width, title = header.title, _b = header.sortable, sortable = _b === void 0 ? false : _b, onSort = header.onSort;
72
+ return (_jsx(TableCell, __assign({ title: title, align: align, sx: {
73
+ zIndex: 9,
74
+ width: width,
75
+ userSelect: "none",
76
+ cursor: sortable ? "pointer" : "default",
77
+ backgroundColor: "".concat(headerBgColor || "#eaf0f6", " !important"),
78
+ color: "".concat(headerTextColor || "inherit", " !important"),
79
+ }, onClick: function () {
80
+ onSort({ accessor: accessor });
81
+ } }, { children: cloneElement(Cell) }), "Virtual_Grid_Header_Col_".concat(accessor)));
82
+ }), fixedRightHeaders.map(function (header, index) {
83
+ var accessor = header.accessor, Cell = header.Cell, _a = header.align, align = _a === void 0 ? "center" : _a, width = header.width, title = header.title, _b = header.sortable, sortable = _b === void 0 ? false : _b, onSort = header.onSort;
84
+ var right = fixedRightHeaders
85
+ .slice(0, fixedRightHeaders.length - 1 - index)
86
+ .reduce(function (w, t) { return w + (t.width || 0); }, 0);
87
+ return (_jsx(TableCell, __assign({ title: title, align: align, sx: {
88
+ position: "sticky",
89
+ backgroundColor: "".concat(headerBgColor || "#eaf0f6", " !important"),
90
+ color: "".concat(headerTextColor || "inherit", " !important"),
91
+ zIndex: 10,
92
+ right: right,
93
+ width: width,
94
+ userSelect: "none",
95
+ cursor: sortable ? "pointer" : "default",
96
+ "&::after": index === 0 && rightShadowVisible
97
+ ? {
98
+ position: "absolute",
99
+ top: 0,
100
+ left: 0,
101
+ bottom: "-1px",
102
+ width: "20px",
103
+ transform: "translateX(-100%)",
104
+ transition: "box-shadow .3s",
105
+ content: "''",
106
+ boxShadow: "inset -10px 0 10px -8px rgba(0, 0, 0, 0.1)",
107
+ }
108
+ : undefined,
109
+ }, onClick: function () {
110
+ onSort({ accessor: accessor });
111
+ } }, { children: cloneElement(Cell) }), "Virtual_Grid_Header_Col_".concat(accessor)));
112
+ })] })) })));
113
+ }
114
+ export default memo(VirtualGridHeader);
@@ -0,0 +1,4 @@
1
+ import type { VirtualGridCoreProps } from "../types";
2
+ declare function VirtualGridCore<RowProps extends Record<string, any>, ExtendedProps extends Record<string, any>>(props: VirtualGridCoreProps<RowProps, ExtendedProps>): import("react/jsx-runtime").JSX.Element;
3
+ declare const _default: typeof VirtualGridCore;
4
+ export default _default;
@@ -10,15 +10,17 @@ var __assign = (this && this.__assign) || function () {
10
10
  return __assign.apply(this, arguments);
11
11
  };
12
12
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
13
+ import { memo } from "react";
14
+ import Grid from "@mui/material/Grid";
13
15
  import Table from "@mui/material/Table";
14
16
  import TableContainer from "@mui/material/TableContainer";
15
- import TableBody from "./TableBody";
16
- import TableHeader from "./TableHeader";
17
- import TableFooter from "./TableFooter";
18
- import { useTableVirtualizer } from "../VirtualizerContext";
19
- function TableCore(props) {
17
+ import TableBody from "./GridBody";
18
+ import TableHeader from "./GridHeader";
19
+ import TableFooter from "./GridFooter";
20
+ import { useGridVirtualizer } from "../GridVirtualizerContext";
21
+ function VirtualGridCore(props) {
20
22
  var dense = props.dense, _a = props.rows, rows = _a === void 0 ? [] : _a, _b = props.columns, columns = _b === void 0 ? [] : _b, _c = props.headers, headers = _c === void 0 ? [] : _c, _d = props.footers, footers = _d === void 0 ? [] : _d, _e = props.noDataText, noDataText = _e === void 0 ? "No Data!" : _e, headerBgColor = props.headerBgColor, headerTextColor = props.headerTextColor, footerBgColor = props.footerBgColor, footerTextColor = props.footerTextColor, onRowClick = props.onRowClick, onContextMenu = props.onContextMenu, onCustomizeRowBgColor = props.onCustomizeRowBgColor;
21
- var _f = useTableVirtualizer(), tableRef = _f.tableRef, onProcessShadowVisible = _f.onProcessShadowVisible;
23
+ var _f = useGridVirtualizer(), tableRef = _f.tableRef, getTotalSize = _f.getTotalSize, onProcessShadowVisible = _f.onProcessShadowVisible;
22
24
  return (_jsx(TableContainer, __assign({ ref: tableRef, onScroll: onProcessShadowVisible, sx: {
23
25
  maxHeight: "inherit",
24
26
  borderWidth: "thin",
@@ -27,6 +29,6 @@ function TableCore(props) {
27
29
  borderRadius: "4px",
28
30
  borderCollapse: "unset !important",
29
31
  transition: "all 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms",
30
- } }, { children: _jsxs(Table, __assign({ sx: { minWidth: 600, tableLayout: "fixed" }, size: dense ? "small" : "medium" }, { children: [_jsx(TableHeader, { headers: headers, headerBgColor: headerBgColor, headerTextColor: headerTextColor, noData: rows.length === 0 }), _jsx(TableBody, { rows: rows, columns: columns, noDataText: noDataText, onRowClick: onRowClick, onContextMenu: onContextMenu, onCustomizeRowBgColor: onCustomizeRowBgColor }), (footers === null || footers === void 0 ? void 0 : footers.length) > 0 ? (_jsx(TableFooter, { footers: footers, footerBgColor: footerBgColor, footerTextColor: footerTextColor, noData: rows.length === 0 })) : (_jsx(_Fragment, {}))] })) })));
32
+ } }, { children: _jsx(Grid, __assign({ sx: { height: "".concat(getTotalSize(), "px") } }, { children: _jsxs(Table, __assign({ sx: { minWidth: 600, tableLayout: "fixed" }, size: dense ? "small" : "medium" }, { children: [_jsx(TableHeader, { headers: headers, headerBgColor: headerBgColor, headerTextColor: headerTextColor, noData: rows.length === 0 }), _jsx(TableBody, { rows: rows, columns: columns, noDataText: noDataText, onRowClick: onRowClick, onContextMenu: onContextMenu, onCustomizeRowBgColor: onCustomizeRowBgColor }), (footers === null || footers === void 0 ? void 0 : footers.length) > 0 ? (_jsx(TableFooter, { footers: footers, footerBgColor: footerBgColor, footerTextColor: footerTextColor, noData: rows.length === 0 })) : (_jsx(_Fragment, {}))] })) })) })));
31
33
  }
32
- export default TableCore;
34
+ export default memo(VirtualGridCore);
@@ -0,0 +1,3 @@
1
+ import type { IGridVirtualizerContext, GridVirtualizerContextProviderProps } from "./types";
2
+ export declare function GridVirtualizerContextProvider<RowProps extends Record<string, any>, ExtendedProps extends Record<string, any>>(props: GridVirtualizerContextProviderProps<RowProps, ExtendedProps>): import("react/jsx-runtime").JSX.Element;
3
+ export declare const useGridVirtualizer: () => IGridVirtualizerContext;
@@ -10,26 +10,30 @@ var __assign = (this && this.__assign) || function () {
10
10
  return __assign.apply(this, arguments);
11
11
  };
12
12
  import { jsx as _jsx } from "react/jsx-runtime";
13
- import { useRef, useState, useEffect, useContext, useCallback, createContext, } from "react";
13
+ import { useRef, useMemo, useState, useEffect, useContext, useCallback, createContext, } from "react";
14
14
  import { useVirtualizer, elementScroll } from "@tanstack/react-virtual";
15
+ var PI = 3.1415965359;
15
16
  function easeInOutQuint(t) {
16
- return t < 0.5 ? 16 * t * t * t * t * t : 1 + 16 * --t * t * t * t * t;
17
+ return t < 0.5
18
+ ? 6 * PI * t * t * t * t * t
19
+ : 1 + 4 * PI * --t * t * t * t * t;
17
20
  }
18
- var VirtualizerContext = createContext({
21
+ var GridVirtualizerContext = createContext({
19
22
  tableRef: { current: null },
20
23
  virtualRows: [],
21
24
  leftShadowVisible: false,
22
25
  rightShadowVisible: false,
26
+ getTotalSize: function () { return 0; },
23
27
  onMeasureElement: function () { },
24
28
  onProcessShadowVisible: function () { },
25
29
  });
26
- export function VirtualizerContextProvider(props) {
27
- var children = props.children, rows = props.rows, columns = props.columns, dense = props.dense;
30
+ export function GridVirtualizerContextProvider(props) {
31
+ var children = props.children, rows = props.rows, columns = props.columns, dense = props.dense, estimateRowHeight = props.estimateRowHeight;
28
32
  var tableRef = useRef(null);
29
33
  var scrollingRef = useRef();
30
34
  var scrollToFn = useCallback(function (offset, canSmooth, instance) {
31
35
  var _a;
32
- var duration = 1000;
36
+ var duration = 2000;
33
37
  var start = ((_a = tableRef.current) === null || _a === void 0 ? void 0 : _a.scrollTop) || 0;
34
38
  var startTime = (scrollingRef.current = Date.now());
35
39
  var run = function () {
@@ -49,20 +53,23 @@ export function VirtualizerContextProvider(props) {
49
53
  };
50
54
  requestAnimationFrame(run);
51
55
  }, []);
56
+ var measureElementHeight = useMemo(function () {
57
+ return typeof window !== "undefined" &&
58
+ navigator.userAgent.indexOf("Firefox") === -1
59
+ ? function (element) { return element === null || element === void 0 ? void 0 : element.getBoundingClientRect().height; }
60
+ : undefined;
61
+ }, []);
52
62
  var rowVirtualizer = useVirtualizer({
53
63
  count: rows.length,
54
64
  getScrollElement: function () { return tableRef.current; },
55
- estimateSize: function () { return (dense ? 48 : 72); },
56
- measureElement: typeof window !== "undefined" &&
57
- navigator.userAgent.indexOf("Firefox") === -1
58
- ? function (element) { return element === null || element === void 0 ? void 0 : element.getBoundingClientRect().height; }
59
- : undefined,
60
- overscan: 12,
65
+ estimateSize: function () { return estimateRowHeight || (dense ? 48 : 72); },
66
+ measureElement: measureElementHeight,
67
+ overscan: Math.round(rows.length / (2 * PI)),
61
68
  scrollToFn: scrollToFn,
62
69
  });
63
70
  var _a = useState(false), leftShadowVisible = _a[0], setLeftShadowVisible = _a[1];
64
71
  var _b = useState(false), rightShadowVisible = _b[0], setRightShadowVisible = _b[1];
65
- var measureElement = rowVirtualizer.measureElement, getVirtualItems = rowVirtualizer.getVirtualItems;
72
+ var measureElement = rowVirtualizer.measureElement, getVirtualItems = rowVirtualizer.getVirtualItems, getTotalSize = rowVirtualizer.getTotalSize;
66
73
  var virtualRows = getVirtualItems();
67
74
  var onProcessShadowVisible = useCallback(function () {
68
75
  if (tableRef.current) {
@@ -86,15 +93,16 @@ export function VirtualizerContextProvider(props) {
86
93
  useEffect(function () { return function () {
87
94
  window.removeEventListener("scroll", onProcessShadowVisible);
88
95
  }; }, [onProcessShadowVisible]);
89
- return (_jsx(VirtualizerContext.Provider, __assign({ value: {
96
+ return (_jsx(GridVirtualizerContext.Provider, __assign({ value: {
90
97
  tableRef: tableRef,
91
98
  virtualRows: virtualRows,
92
99
  leftShadowVisible: leftShadowVisible,
93
100
  rightShadowVisible: rightShadowVisible,
101
+ getTotalSize: getTotalSize,
94
102
  onMeasureElement: measureElement,
95
103
  onProcessShadowVisible: onProcessShadowVisible,
96
104
  } }, { children: children })));
97
105
  }
98
- export var useTableVirtualizer = function () {
99
- return useContext(VirtualizerContext);
106
+ export var useGridVirtualizer = function () {
107
+ return useContext(GridVirtualizerContext);
100
108
  };
@@ -0,0 +1,6 @@
1
+ import useVirtualGrid from "./useVirtualGrid";
2
+ import type { VirtualGridProps } from "./types";
3
+ declare function VirtualGrid<RowProps extends Record<string, any>, ExtendedProps extends Record<string, any>>(props: VirtualGridProps<RowProps, ExtendedProps>): import("react/jsx-runtime").JSX.Element;
4
+ export default VirtualGrid;
5
+ export * from "./types";
6
+ export { useVirtualGrid };
@@ -0,0 +1,36 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ var __rest = (this && this.__rest) || function (s, e) {
13
+ var t = {};
14
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
15
+ t[p] = s[p];
16
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
17
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
18
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
19
+ t[p[i]] = s[p[i]];
20
+ }
21
+ return t;
22
+ };
23
+ import { jsx as _jsx } from "react/jsx-runtime";
24
+ import ThemeProvider from "@mui/material/styles/ThemeProvider";
25
+ import useCustomTheme from "../useCustomTheme";
26
+ import useVirtualGrid from "./useVirtualGrid";
27
+ import VirtualGridCore from "./GridCore";
28
+ import { GridVirtualizerContextProvider } from "./GridVirtualizerContext";
29
+ function VirtualGrid(props) {
30
+ var estimateRowHeight = props.estimateRowHeight, primaryColor = props.primaryColor, secondaryColor = props.secondaryColor, rows = props.rows, columns = props.columns, dense = props.dense, rest = __rest(props, ["estimateRowHeight", "primaryColor", "secondaryColor", "rows", "columns", "dense"]);
31
+ var theme = useCustomTheme({ primaryColor: primaryColor, secondaryColor: secondaryColor });
32
+ return (_jsx(ThemeProvider, __assign({ theme: theme }, { children: _jsx(GridVirtualizerContextProvider, __assign({ rows: rows, columns: columns, dense: dense, estimateRowHeight: estimateRowHeight }, { children: _jsx(VirtualGridCore, __assign({}, rest, { rows: rows, columns: columns, dense: dense })) })) })));
33
+ }
34
+ export default VirtualGrid;
35
+ export * from "./types";
36
+ export { useVirtualGrid };