@etsoo/materialui 1.5.71 → 1.5.73

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 (61) hide show
  1. package/__tests__/ReactAppTests.tsx +12 -7
  2. package/__tests__/{ResponsePage.tsx → ResponsivePage.tsx} +11 -5
  3. package/__tests__/SelectEx.tsx +1 -1
  4. package/lib/cjs/DataGridEx.d.ts +8 -1
  5. package/lib/cjs/DataGridEx.js +71 -56
  6. package/lib/cjs/DataGridRenderers.d.ts +1 -1
  7. package/lib/cjs/DataGridRenderers.js +1 -1
  8. package/lib/cjs/MUUtils.d.ts +0 -9
  9. package/lib/cjs/MUUtils.js +0 -26
  10. package/lib/cjs/MobileListItemRenderer.d.ts +2 -2
  11. package/lib/cjs/MobileListItemRenderer.js +3 -4
  12. package/lib/cjs/ResponsibleContainer.d.ts +9 -13
  13. package/lib/cjs/ResponsibleContainer.js +19 -58
  14. package/lib/cjs/ScrollerListEx.d.ts +23 -23
  15. package/lib/cjs/ScrollerListEx.js +32 -84
  16. package/lib/cjs/TableEx.d.ts +7 -0
  17. package/lib/cjs/TableEx.js +6 -12
  18. package/lib/cjs/pages/DataGridPage.js +3 -32
  19. package/lib/cjs/pages/FixedListPage.js +5 -34
  20. package/lib/cjs/pages/ListPage.js +1 -29
  21. package/lib/cjs/pages/ResponsivePage.d.ts +9 -13
  22. package/lib/cjs/uses/useGridCacheInitLoad.d.ts +2 -0
  23. package/lib/cjs/uses/useGridCacheInitLoad.js +41 -0
  24. package/lib/cjs/uses/useListCacheInitLoad.d.ts +2 -0
  25. package/lib/cjs/uses/useListCacheInitLoad.js +38 -0
  26. package/lib/mjs/DataGridEx.d.ts +8 -1
  27. package/lib/mjs/DataGridEx.js +71 -56
  28. package/lib/mjs/DataGridRenderers.d.ts +1 -1
  29. package/lib/mjs/DataGridRenderers.js +1 -1
  30. package/lib/mjs/MUUtils.d.ts +0 -9
  31. package/lib/mjs/MUUtils.js +0 -26
  32. package/lib/mjs/MobileListItemRenderer.d.ts +2 -2
  33. package/lib/mjs/MobileListItemRenderer.js +3 -4
  34. package/lib/mjs/ResponsibleContainer.d.ts +9 -13
  35. package/lib/mjs/ResponsibleContainer.js +19 -58
  36. package/lib/mjs/ScrollerListEx.d.ts +23 -23
  37. package/lib/mjs/ScrollerListEx.js +32 -84
  38. package/lib/mjs/TableEx.d.ts +7 -0
  39. package/lib/mjs/TableEx.js +6 -12
  40. package/lib/mjs/pages/DataGridPage.js +3 -32
  41. package/lib/mjs/pages/FixedListPage.js +5 -34
  42. package/lib/mjs/pages/ListPage.js +1 -29
  43. package/lib/mjs/pages/ResponsivePage.d.ts +9 -13
  44. package/lib/mjs/uses/useGridCacheInitLoad.d.ts +2 -0
  45. package/lib/mjs/uses/useGridCacheInitLoad.js +35 -0
  46. package/lib/mjs/uses/useListCacheInitLoad.d.ts +2 -0
  47. package/lib/mjs/uses/useListCacheInitLoad.js +32 -0
  48. package/package.json +18 -19
  49. package/src/DataGridEx.tsx +155 -109
  50. package/src/DataGridRenderers.tsx +2 -1
  51. package/src/MUUtils.ts +0 -33
  52. package/src/MobileListItemRenderer.tsx +4 -4
  53. package/src/ResponsibleContainer.tsx +50 -111
  54. package/src/ScrollerListEx.tsx +141 -229
  55. package/src/TableEx.tsx +20 -12
  56. package/src/pages/DataGridPage.tsx +3 -49
  57. package/src/pages/FixedListPage.tsx +5 -49
  58. package/src/pages/ListPage.tsx +0 -43
  59. package/src/pages/ResponsivePage.tsx +16 -21
  60. package/src/uses/useGridCacheInitLoad.ts +55 -0
  61. package/src/uses/useListCacheInitLoad.ts +51 -0
@@ -10,7 +10,9 @@ const react_1 = require("@etsoo/react");
10
10
  const shared_1 = require("@etsoo/shared");
11
11
  const react_2 = __importDefault(require("react"));
12
12
  const MUGlobal_1 = require("./MUGlobal");
13
- const styles_1 = require("@mui/material/styles");
13
+ const GridUtils_1 = require("./GridUtils");
14
+ const useListCacheInitLoad_1 = require("./uses/useListCacheInitLoad");
15
+ const Box_1 = __importDefault(require("@mui/material/Box"));
14
16
  // Scroll bar size
15
17
  const scrollbarSize = 16;
16
18
  // Selected class name
@@ -45,28 +47,9 @@ const createGridStyle = (alternatingColors, selectedColor) => {
45
47
  }
46
48
  });
47
49
  };
48
- // Default margin
49
- // horizon: null means full horizontal margin, -1 means all half, >=0 means left/right
50
- const defaultMargin = (margin, horizon) => {
51
- const half = MUGlobal_1.MUGlobal.half(margin);
52
- if (horizon == null) {
53
- const half = MUGlobal_1.MUGlobal.half(margin);
54
- return {
55
- marginLeft: margin,
56
- marginRight: margin,
57
- marginTop: half,
58
- marginBottom: half
59
- };
60
- }
61
- if ((typeof horizon === "number" && horizon >= 0) ||
62
- (typeof horizon === "string" && /^-?\d+/.test(horizon))) {
63
- return {
64
- marginLeft: horizon,
65
- marginRight: horizon,
66
- marginTop: half,
67
- marginBottom: half
68
- };
69
- }
50
+ // Default margins
51
+ const defaultMargins = () => {
52
+ const half = MUGlobal_1.MUGlobal.half(MUGlobal_1.MUGlobal.pagePaddings);
70
53
  return {
71
54
  marginLeft: half,
72
55
  marginRight: half,
@@ -74,24 +57,6 @@ const defaultMargin = (margin, horizon) => {
74
57
  marginBottom: half
75
58
  };
76
59
  };
77
- // Default itemRenderer
78
- function defaultItemRenderer({ index, innerItemRenderer, data, onMouseDown, selected, style, itemHeight, onClick, onDoubleClick, space, margins }) {
79
- // Child
80
- const child = innerItemRenderer({
81
- index,
82
- data,
83
- style,
84
- selected,
85
- itemHeight,
86
- space,
87
- margins
88
- });
89
- let rowClass = `ScrollerListEx-Row${index % 2}`;
90
- if (selected)
91
- rowClass += ` ${selectedClassName}`;
92
- // Layout
93
- return ((0, jsx_runtime_1.jsx)("div", { className: rowClass, style: style, onMouseDown: (event) => onMouseDown(event.currentTarget, data), onClick: (event) => onClick && onClick(event, data), onDoubleClick: (event) => onDoubleClick && onDoubleClick(event, data), children: child }));
94
- }
95
60
  /**
96
61
  * Extended ScrollerList
97
62
  * @param props Props
@@ -119,48 +84,31 @@ function ScrollerListEx(props) {
119
84
  return selected;
120
85
  };
121
86
  // Destruct
122
- const { alternatingColors = [undefined, undefined], className, idField = "id", innerItemRenderer, itemSize, itemRenderer = (itemProps) => {
123
- const [itemHeight, space, margins] = calculateItemSize(itemProps.index);
124
- return defaultItemRenderer({
125
- itemHeight,
126
- innerItemRenderer,
127
- onMouseDown,
128
- onClick,
129
- onDoubleClick,
130
- space,
131
- margins,
132
- selected: isSelected(itemProps.data),
133
- ...itemProps
134
- });
135
- }, onClick, onDoubleClick, onSelectChange, selectedColor = "#edf4fb", ...rest } = props;
136
- // Theme
137
- const theme = (0, styles_1.useTheme)();
138
- // Cache calculation
139
- const itemSizeResult = react_2.default.useMemo(() => {
140
- if (typeof itemSize === "function")
141
- return undefined;
142
- const [size, spaces, h] = itemSize;
143
- if (typeof spaces === "number")
144
- return [size, spaces, defaultMargin(MUGlobal_1.MUGlobal.pagePaddings, undefined)];
145
- return [size, MUGlobal_1.MUGlobal.getSpace(spaces, theme), defaultMargin(spaces, h)];
146
- }, [itemSize]);
147
- // Calculate size
148
- const calculateItemSize = (index) => {
149
- // Callback function
150
- if (typeof itemSize === "function") {
151
- const result = itemSize(index);
152
- if (result.length == 2)
153
- return [...result, defaultMargin(MUGlobal_1.MUGlobal.pagePaddings)];
154
- return result;
155
- }
156
- // Calculation
157
- return itemSizeResult;
158
- };
159
- // Local item size
160
- const itemSizeLocal = (index) => {
161
- const [size, space] = calculateItemSize(index);
162
- return size + space;
163
- };
87
+ const { alternatingColors = [undefined, undefined], className, cacheKey, cacheMinutes = 15, cellMargins = defaultMargins(), idField = "id", itemRenderer = ({ data, margins, style }) => ((0, jsx_runtime_1.jsx)(Box_1.default, { component: "pre", sx: {
88
+ ...margins
89
+ }, style: style, children: JSON.stringify(data) })), onClick, onDoubleClick, onUpdateRows, onSelectChange, rowHeight = 116, selectedColor = "#edf4fb", ...rest } = props;
90
+ // Init handler
91
+ const initHandler = (0, useListCacheInitLoad_1.useListCacheInitLoad)(cacheKey, cacheMinutes);
92
+ const onUpdateRowsHandler = react_2.default.useCallback((rows, state) => {
93
+ GridUtils_1.GridUtils.getUpdateRowsHandler(cacheKey)?.(rows, state);
94
+ onUpdateRows?.(rows, state);
95
+ }, [onUpdateRows, cacheKey]);
164
96
  // Layout
165
- return ((0, jsx_runtime_1.jsx)(react_1.ScrollerList, { className: shared_1.Utils.mergeClasses("ScrollerListEx-Body", className, createGridStyle(alternatingColors, selectedColor)), idField: idField, itemRenderer: itemRenderer, itemSize: itemSizeLocal, ...rest }));
97
+ return ((0, jsx_runtime_1.jsx)(react_1.ScrollerList, { className: shared_1.Utils.mergeClasses("ScrollerListEx-Body", className, createGridStyle(alternatingColors, selectedColor)), idField: idField, onRowsRendered: cacheKey
98
+ ? (visibleRows) => sessionStorage.setItem(`${cacheKey}-scroll`, JSON.stringify(visibleRows))
99
+ : undefined, onInitLoad: initHandler, onUpdateRows: onUpdateRowsHandler, rowComponent: (cellProps) => {
100
+ const { index, style, items } = cellProps;
101
+ const data = items[index];
102
+ const selected = isSelected(data);
103
+ const rowClass = `ScrollerListEx-Row${index % 2}${selected ? ` ${selectedClassName}` : ""}`;
104
+ // Child
105
+ const child = itemRenderer({
106
+ index,
107
+ data,
108
+ style,
109
+ selected,
110
+ margins: cellMargins
111
+ });
112
+ return ((0, jsx_runtime_1.jsx)("div", { className: rowClass, style: style, onMouseDown: (event) => onMouseDown(event.currentTarget, data), onClick: (event) => onClick && onClick(event, data), onDoubleClick: (event) => onDoubleClick && onDoubleClick(event, data), children: child }));
113
+ }, rowHeight: rowHeight, ...rest }));
166
114
  }
@@ -43,6 +43,13 @@ export type TableExProps<T extends object, D extends DataTypes.Keys<T>> = TableP
43
43
  * Methods
44
44
  */
45
45
  mRef?: React.Ref<TableExMethodRef<T>>;
46
+ /**
47
+ * Data change handler
48
+ * @param rows Rows
49
+ * @param rowIndex Row index
50
+ * @param columnIndex Column index
51
+ */
52
+ onDataChange?: (rows: T[], rowIndex: number, columnIndex: number) => void;
46
53
  /**
47
54
  * On items select change
48
55
  */
@@ -34,7 +34,7 @@ function TableEx(props) {
34
34
  // Theme
35
35
  const theme = (0, styles_1.useTheme)();
36
36
  // Destruct
37
- const { alternatingColors = [theme.palette.action.hover, undefined], autoLoad = true, columns, defaultOrderBy, headerColors = [undefined, undefined], idField = "id", loadBatchSize, loadData, maxHeight, mRef, onSelectChange, rowHeight = 53, otherHeight = 110, threshold, ...rest } = props;
37
+ const { alternatingColors = [theme.palette.action.hover, undefined], autoLoad = true, columns, defaultOrderBy, headerColors = [undefined, undefined], idField = "id", loadBatchSize, loadData, maxHeight, mRef, onDataChange, onSelectChange, rowHeight = 53, otherHeight = 110, threshold, ...rest } = props;
38
38
  const selectable = onSelectChange != null;
39
39
  // Rows per page
40
40
  let rowsPerPageLocal;
@@ -90,6 +90,9 @@ function TableEx(props) {
90
90
  });
91
91
  };
92
92
  react_2.default.useImperativeHandle(mRef, () => ({
93
+ get element() {
94
+ return null;
95
+ },
93
96
  delete(index) {
94
97
  const item = rows.at(index);
95
98
  if (item) {
@@ -104,20 +107,11 @@ function TableEx(props) {
104
107
  newRows.splice(start, 0, item);
105
108
  setRows(newRows);
106
109
  },
107
- /**
108
- * Refresh data
109
- */
110
110
  refresh() {
111
111
  loadDataLocal();
112
112
  },
113
- /**
114
- * Reset
115
- */
116
113
  reset,
117
- scrollToRef(scrollOffset) {
118
- // Not implemented
119
- },
120
- scrollToItemRef(index) {
114
+ scrollToRow(param) {
121
115
  // Not implemented
122
116
  }
123
117
  }), []);
@@ -291,7 +285,7 @@ function TableEx(props) {
291
285
  rowIndex,
292
286
  columnIndex,
293
287
  cellProps,
294
- setItems
288
+ triggerChange: () => onDataChange?.(rows, rowIndex, columnIndex)
295
289
  })) : ((0, jsx_runtime_1.jsx)(react_2.default.Fragment, { children: "\u00A0" }));
296
290
  return ((0, jsx_runtime_1.jsx)(TableCell_1.default, { ...cellProps, children: child }, `${rowId}${columnIndex}`));
297
291
  })] }, rowId));
@@ -33,9 +33,10 @@ function DataGridPage(props) {
33
33
  if (ref == null)
34
34
  return;
35
35
  states.ref = ref;
36
+ if (ref.element)
37
+ setStates({ element: ref.element });
36
38
  //setStates({ ref });
37
39
  });
38
- const initLoadedRef = react_2.default.useRef(null);
39
40
  // On submit callback
40
41
  const onSubmit = (data, _reset) => {
41
42
  setStates({ data });
@@ -45,33 +46,6 @@ function DataGridPage(props) {
45
46
  };
46
47
  // Search data
47
48
  const searchData = (0, react_1.useSearchParamsWithCache)(cacheKey);
48
- const onInitLoad = (ref) => {
49
- // Avoid repeatedly load from cache
50
- if (initLoadedRef.current || !cacheKey)
51
- return undefined;
52
- // Cache data
53
- const cacheData = GridUtils_1.GridUtils.getCacheData(cacheKey, cacheMinutes);
54
- if (cacheData) {
55
- const { rows, state } = cacheData;
56
- GridUtils_1.GridUtils.mergeSearchData(state, searchData);
57
- // Scroll position
58
- const scrollData = sessionStorage.getItem(`${cacheKey}-scroll`);
59
- if (scrollData) {
60
- const { scrollLeft, scrollTop } = JSON.parse(scrollData);
61
- globalThis.setTimeout(() => ref.scrollTo({ scrollLeft, scrollTop }), 0);
62
- }
63
- // Update flag value
64
- initLoadedRef.current = true;
65
- // Return cached rows and state
66
- return [rows, state];
67
- }
68
- return undefined;
69
- };
70
- const onGridScroll = (props) => {
71
- if (!cacheKey || !initLoadedRef.current)
72
- return;
73
- sessionStorage.setItem(`${cacheKey}-scroll`, JSON.stringify(props));
74
- };
75
49
  // Watch container
76
50
  const { dimensions } = (0, react_1.useDimensions)(1, undefined, sizeReadyMiliseconds);
77
51
  const rect = dimensions[0][2];
@@ -96,10 +70,7 @@ function DataGridPage(props) {
96
70
  const gridHeight = states.height;
97
71
  if (gridHeight == null)
98
72
  return;
99
- return ((0, jsx_runtime_1.jsx)(DataGridEx_1.DataGridEx, { autoLoad: false, height: gridHeight, loadData: localLoadData, mRef: refs, onUpdateRows: GridUtils_1.GridUtils.getUpdateRowsHandler(cacheKey), onInitLoad: onInitLoad, onScroll: onGridScroll, outerRef: (element) => {
100
- if (element != null)
101
- setStates({ element });
102
- }, ...rest }));
73
+ return ((0, jsx_runtime_1.jsx)(DataGridEx_1.DataGridEx, { autoLoad: false, height: gridHeight, loadData: localLoadData, mRef: refs, ...rest }));
103
74
  }, [states.height]);
104
75
  const { ref, data } = states;
105
76
  react_2.default.useEffect(() => {
@@ -25,7 +25,6 @@ function FixedListPage(props) {
25
25
  pageProps.paddings ??= MUGlobal_1.MUGlobal.pagePaddings;
26
26
  // States
27
27
  const [states] = react_2.default.useState({});
28
- const initLoadedRef = react_2.default.useRef(null);
29
28
  // Scroll container
30
29
  const [scrollContainer, updateScrollContainer] = react_2.default.useState();
31
30
  const refs = (0, react_1.useCombinedRefs)(mRef, (ref) => {
@@ -33,6 +32,8 @@ function FixedListPage(props) {
33
32
  return;
34
33
  const first = states.ref == null;
35
34
  states.ref = ref;
35
+ if (ref.element)
36
+ updateScrollContainer(ref.element);
36
37
  if (first)
37
38
  reset();
38
39
  });
@@ -49,35 +50,6 @@ function FixedListPage(props) {
49
50
  const localLoadData = (props, lastItem) => {
50
51
  return loadData(GridUtils_1.GridUtils.createLoader(props, fieldTemplate, cacheKey, false), lastItem);
51
52
  };
52
- // Search data
53
- const searchData = (0, react_1.useSearchParamsWithCache)(cacheKey);
54
- const onInitLoad = (ref) => {
55
- // Avoid repeatedly load from cache
56
- if (initLoadedRef.current || !cacheKey)
57
- return undefined;
58
- // Cache data
59
- const cacheData = GridUtils_1.GridUtils.getCacheData(cacheKey, cacheMinutes);
60
- if (cacheData) {
61
- const { rows, state } = cacheData;
62
- GridUtils_1.GridUtils.mergeSearchData(state, searchData);
63
- // Scroll position
64
- const scrollData = sessionStorage.getItem(`${cacheKey}-scroll`);
65
- if (scrollData) {
66
- const { scrollOffset } = JSON.parse(scrollData);
67
- globalThis.setTimeout(() => ref.scrollTo(scrollOffset), 0);
68
- }
69
- // Update flag value
70
- initLoadedRef.current = true;
71
- // Return cached rows and state
72
- return [rows, state];
73
- }
74
- return undefined;
75
- };
76
- const onListScroll = (props) => {
77
- if (!cacheKey || !initLoadedRef.current)
78
- return;
79
- sessionStorage.setItem(`${cacheKey}-scroll`, JSON.stringify(props));
80
- };
81
53
  // Watch container
82
54
  const { dimensions } = (0, react_1.useDimensions)(1, undefined, sizeReadyMiliseconds);
83
55
  const rect = dimensions[0][2];
@@ -92,12 +64,11 @@ function FixedListPage(props) {
92
64
  : adjustHeight(height, rect);
93
65
  return ((0, jsx_runtime_1.jsx)(Box_1.default, { id: "list-container", sx: {
94
66
  height: height + "px"
95
- }, children: (0, jsx_runtime_1.jsx)(ScrollerListEx_1.ScrollerListEx, { autoLoad: false, height: height, loadData: localLoadData, mRef: refs, onUpdateRows: GridUtils_1.GridUtils.getUpdateRowsHandler(cacheKey), onInitLoad: onInitLoad, onScroll: onListScroll, oRef: (element) => {
96
- if (element != null)
97
- updateScrollContainer(element);
98
- }, ...rest }) }));
67
+ }, children: (0, jsx_runtime_1.jsx)(ScrollerListEx_1.ScrollerListEx, { autoLoad: false, height: height, loadData: localLoadData, mRef: refs, ...rest }) }));
99
68
  }
100
69
  }, [rect]);
70
+ // Search data
71
+ const searchData = (0, react_1.useSearchParamsWithCache)(cacheKey);
101
72
  const f = typeof fields == "function" ? fields(searchData ?? {}) : fields;
102
73
  const { paddings, ...pageRest } = pageProps;
103
74
  // Layout
@@ -33,7 +33,6 @@ function ListPage(props) {
33
33
  if (first)
34
34
  reset();
35
35
  });
36
- const initLoadedRef = react_2.default.useRef(null);
37
36
  const reset = () => {
38
37
  if (states.data == null || states.ref == null)
39
38
  return;
@@ -52,36 +51,9 @@ function ListPage(props) {
52
51
  const rect = dimensions[0][2];
53
52
  // Search data
54
53
  const searchData = (0, react_1.useSearchParamsWithCache)(cacheKey);
55
- const onInitLoad = (ref) => {
56
- // Avoid repeatedly load from cache
57
- if (initLoadedRef.current || !cacheKey)
58
- return undefined;
59
- // Cache data
60
- const cacheData = GridUtils_1.GridUtils.getCacheData(cacheKey, cacheMinutes);
61
- if (cacheData) {
62
- const { rows, state } = cacheData;
63
- GridUtils_1.GridUtils.mergeSearchData(state, searchData);
64
- // Scroll position
65
- const scrollData = sessionStorage.getItem(`${cacheKey}-scroll`);
66
- if (scrollData) {
67
- const { scrollOffset } = JSON.parse(scrollData);
68
- globalThis.setTimeout(() => ref.scrollTo(scrollOffset), 0);
69
- }
70
- // Update flag value
71
- initLoadedRef.current = true;
72
- // Return cached rows and state
73
- return [rows, state];
74
- }
75
- return undefined;
76
- };
77
- const onListScroll = (props) => {
78
- if (!cacheKey || !initLoadedRef.current)
79
- return;
80
- sessionStorage.setItem(`${cacheKey}-scroll`, JSON.stringify(props));
81
- };
82
54
  const f = typeof fields == "function" ? fields(searchData ?? {}) : fields;
83
55
  // Layout
84
56
  return ((0, jsx_runtime_1.jsx)(CommonPage_1.CommonPage, { ...pageProps, scrollContainer: globalThis, children: (0, jsx_runtime_1.jsxs)(Stack_1.default, { children: [(0, jsx_runtime_1.jsx)(Box_1.default, { ref: dimensions[0][0], sx: {
85
57
  paddingBottom: pageProps.paddings
86
- }, children: rect && rect.width > 100 && ((0, jsx_runtime_1.jsx)(SearchBar_1.SearchBar, { fields: f, onSubmit: onSubmit, top: searchBarTop, width: rect.width })) }), (0, jsx_runtime_1.jsx)(ScrollerListEx_1.ScrollerListEx, { autoLoad: false, loadData: localLoadData, onUpdateRows: GridUtils_1.GridUtils.getUpdateRowsHandler(cacheKey), onInitLoad: onInitLoad, onScroll: onListScroll, mRef: refs, ...rest })] }) }));
58
+ }, children: rect && rect.width > 100 && ((0, jsx_runtime_1.jsx)(SearchBar_1.SearchBar, { fields: f, onSubmit: onSubmit, top: searchBarTop, width: rect.width })) }), (0, jsx_runtime_1.jsx)(ScrollerListEx_1.ScrollerListEx, { autoLoad: false, loadData: localLoadData, mRef: refs, ...rest })] }) }));
87
59
  }
@@ -1,13 +1,13 @@
1
1
  import React from "react";
2
+ import { ResponsibleContainerProps } from "../ResponsibleContainer";
2
3
  import type { DataGridPageProps } from "./DataGridPageProps";
3
- import type { ScrollerListExInnerItemRendererProps, ScrollerListExItemSize } from "../ScrollerListEx";
4
- import { ListChildComponentProps } from "react-window";
4
+ import type { ScrollerListExProps } from "../ScrollerListEx";
5
5
  import { GridMethodRef } from "@etsoo/react";
6
6
  import type { OperationMessageHandlerAll } from "../messages/OperationMessageHandler";
7
7
  /**
8
8
  * Response page props
9
9
  */
10
- export type ResponsePageProps<T extends object, F> = DataGridPageProps<T, F> & {
10
+ export type ResponsePageProps<T extends object, F> = Omit<DataGridPageProps<T, F>, "mRef" | "rowHeight"> & {
11
11
  /**
12
12
  *
13
13
  * @param height Current height
@@ -19,22 +19,14 @@ export type ResponsePageProps<T extends object, F> = DataGridPageProps<T, F> & {
19
19
  * Min width to show Datagrid
20
20
  */
21
21
  dataGridMinWidth?: number;
22
- /**
23
- * Inner item renderer
24
- */
25
- innerItemRenderer: (props: ScrollerListExInnerItemRendererProps<T>) => React.ReactNode;
26
22
  /**
27
23
  * Item renderer
28
24
  */
29
- itemRenderer?: (props: ListChildComponentProps<T>) => React.ReactElement;
30
- /**
31
- * Item size, a function indicates its a variable size list
32
- */
33
- itemSize: ScrollerListExItemSize;
25
+ itemRenderer?: ScrollerListExProps<T>["itemRenderer"];
34
26
  /**
35
27
  * Methods
36
28
  */
37
- mRef?: React.MutableRefObject<GridMethodRef<T> | undefined>;
29
+ mRef?: React.RefObject<GridMethodRef<T> | undefined>;
38
30
  /**
39
31
  * Pull to refresh data
40
32
  */
@@ -47,6 +39,10 @@ export type ResponsePageProps<T extends object, F> = DataGridPageProps<T, F> & {
47
39
  * Operation message handler
48
40
  */
49
41
  operationMessageHandler?: OperationMessageHandlerAll;
42
+ /**
43
+ * Row height
44
+ */
45
+ rowHeight?: ResponsibleContainerProps<T, F>["rowHeight"];
50
46
  };
51
47
  /**
52
48
  * Fixed height list page
@@ -0,0 +1,2 @@
1
+ import { ScrollerGridProps } from "@etsoo/react";
2
+ export declare function useGridCacheInitLoad<T extends object>(cacheKey: string | undefined, cacheMinutes: number): ScrollerGridProps<T>["onInitLoad"];
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.useGridCacheInitLoad = useGridCacheInitLoad;
7
+ const react_1 = require("@etsoo/react");
8
+ const react_2 = __importDefault(require("react"));
9
+ const GridUtils_1 = require("../GridUtils");
10
+ const shared_1 = require("@etsoo/shared");
11
+ function useGridCacheInitLoad(cacheKey, cacheMinutes) {
12
+ // Reference
13
+ const ref = react_2.default.useRef(null);
14
+ // Search data
15
+ const searchData = (0, react_1.useSearchParamsWithCache)(cacheKey);
16
+ // Avoid repeatedly load from cache
17
+ if (ref.current || !cacheKey)
18
+ return undefined;
19
+ // Cache data
20
+ const cacheData = GridUtils_1.GridUtils.getCacheData(cacheKey, cacheMinutes);
21
+ if (cacheData) {
22
+ const { rows, state } = cacheData;
23
+ GridUtils_1.GridUtils.mergeSearchData(state, searchData);
24
+ // Update flag value
25
+ ref.current = true;
26
+ return (ref) => {
27
+ // Scroll position
28
+ const scrollData = sessionStorage.getItem(`${cacheKey}-scroll`);
29
+ if (scrollData) {
30
+ const data = JSON.parse(scrollData);
31
+ shared_1.ExtendUtils.waitFor(() => ref.scrollToCell({
32
+ rowIndex: data.rowStartIndex,
33
+ columnIndex: data.columnStartIndex
34
+ }), 100);
35
+ }
36
+ // Return cached rows and state
37
+ return [rows, state];
38
+ };
39
+ }
40
+ return undefined;
41
+ }
@@ -0,0 +1,2 @@
1
+ import { ScrollerListProps } from "@etsoo/react";
2
+ export declare function useListCacheInitLoad<T extends object>(cacheKey: string | undefined, cacheMinutes: number): ScrollerListProps<T>["onInitLoad"];
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.useListCacheInitLoad = useListCacheInitLoad;
7
+ const react_1 = require("@etsoo/react");
8
+ const react_2 = __importDefault(require("react"));
9
+ const GridUtils_1 = require("../GridUtils");
10
+ const shared_1 = require("@etsoo/shared");
11
+ function useListCacheInitLoad(cacheKey, cacheMinutes) {
12
+ // Reference
13
+ const ref = react_2.default.useRef(null);
14
+ // Search data
15
+ const searchData = (0, react_1.useSearchParamsWithCache)(cacheKey);
16
+ // Avoid repeatedly load from cache
17
+ if (ref.current || !cacheKey)
18
+ return undefined;
19
+ // Cache data
20
+ const cacheData = GridUtils_1.GridUtils.getCacheData(cacheKey, cacheMinutes);
21
+ if (cacheData) {
22
+ const { rows, state } = cacheData;
23
+ GridUtils_1.GridUtils.mergeSearchData(state, searchData);
24
+ // Update flag value
25
+ ref.current = true;
26
+ return (ref) => {
27
+ // Scroll position
28
+ const scrollData = sessionStorage.getItem(`${cacheKey}-scroll`);
29
+ if (scrollData) {
30
+ const data = JSON.parse(scrollData);
31
+ shared_1.ExtendUtils.waitFor(() => ref.scrollToRow({ index: data.startIndex }), 100);
32
+ }
33
+ // Return cached rows and state
34
+ return [rows, state];
35
+ };
36
+ }
37
+ return undefined;
38
+ }
@@ -14,7 +14,7 @@ export type DataGridExFooterItemRendererProps<T extends object> = {
14
14
  /**
15
15
  * Extended DataGrid with VariableSizeGrid props
16
16
  */
17
- export type DataGridExProps<T extends object, P extends GridJsonData = GridLoadDataProps> = Omit<ScrollerGridProps<T, P>, "itemRenderer" | "columnCount" | "columnWidth" | "width"> & {
17
+ export type DataGridExProps<T extends object, P extends GridJsonData = GridLoadDataProps> = Omit<ScrollerGridProps<T, P>, "cellComponent" | "columnCount" | "columnWidth" | "onClick" | "onDoubleClick" | "onInitLoad" | "rowHeight" | "width"> & Partial<Pick<ScrollerGridProps<T, P>, "rowHeight">> & {
18
18
  /**
19
19
  * Alternating colors for odd/even rows
20
20
  */
@@ -70,6 +70,13 @@ export type DataGridExProps<T extends object, P extends GridJsonData = GridLoadD
70
70
  * Click handler
71
71
  */
72
72
  onClick?: MouseEventWithDataHandler<T>;
73
+ /**
74
+ * Data change handler
75
+ * @param rows Rows
76
+ * @param rowIndex Row index
77
+ * @param columnIndex Column index
78
+ */
79
+ onDataChange?: (rows: T[], rowIndex: number, columnIndex: number) => void;
73
80
  /**
74
81
  * Selectable to support hover over and out effect and row clickable
75
82
  * @default true