@azrico/reactgrid 1.4.1 → 1.5.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.
@@ -19,6 +19,7 @@ var _useGridEvents = require("../hooks/useGridEvents");
19
19
  var _useColumnData = require("../hooks/useColumnData");
20
20
  var _useDatasource = require("../hooks/useDatasource");
21
21
  var _useGridSearch = require("../hooks/useGridSearch");
22
+ var _func_a11y = require("../func/func_a11y");
22
23
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
23
24
  /* -------------------------------------------------------------------------- */
24
25
  /* -------------------------------------------------------------------------- */
@@ -39,29 +40,40 @@ const forcedOptions = {
39
40
  theme: 'default-light'
40
41
  };
41
42
  const dynamic_option_names = ['selected', 'cellSelection', 'loading', 'limit', 'skip'];
43
+ // consumer callbacks forwarded to the grid; wrapped so a new function doesn't re-render the grid
44
+ const callback_option_names = ['onSkipChange', 'onLimitChange', 'onEditComplete', 'onSelectionChange', 'onCellSelectionChange'];
45
+ // props DataGridCore renders from, other props don't need to re-render the grid
46
+ const core_prop_names = ['className', 'static_gridOptions', 'dynamic_gridOptions', 'columns', 'dataSource', 'gridRef', 'liveGridRef', 'allowChildRows', 'theme', 'dark', 'children'];
42
47
  /* -------------------------------------------------------------------------- */
43
48
  function AzGrid(props) {
44
49
  const gridRefBackup = _react.default.useRef(null);
45
50
  const gridRef = props.gridRef || gridRefBackup;
51
+ const liveGridRef = _react.default.useRef(null);
52
+ const latestProps = _react.default.useRef(props);
53
+ latestProps.current = props;
46
54
  /* -------------------------------------------------------------------------- */
47
55
  /* Columns */
48
56
  /* -------------------------------------------------------------------------- */
49
57
  const cached_columns = (0, _useColumnData.useColumnData)(props);
50
58
  const dataSource = (0, _useDatasource.useDataSource)(props.dataSource, props);
59
+ const a11y_columns = _react.default.useMemo(() => cached_columns.map(col => (0, _func_a11y.apply_column_a11y)(col, {
60
+ gridEditable: !!props.editable
61
+ })), [cached_columns, props.editable]);
51
62
  /* -------------------------------------------------------------------------- */
52
63
  /* Row changes */
53
64
  /* -------------------------------------------------------------------------- */
54
65
  const base_gridOptions = _react.default.useMemo(() => {
55
66
  const firstcolumn = cached_columns[0];
56
67
  const licenseKey = props.licenseKey || (0, _func_grid.get_default_key)();
57
- const events = {
58
- onSkipChange: props.onSkipChange,
59
- onLimitChange: props.onLimitChange,
60
- onEditComplete: props.onEditComplete
61
- };
68
+ // call the latest consumer callback, only passed when the consumer gave one
69
+ const events = {};
70
+ callback_option_names.forEach(name => {
71
+ if (props[name]) events[name] = (...args) => {
72
+ var _latestProps$current$, _latestProps$current;
73
+ return (_latestProps$current$ = (_latestProps$current = latestProps.current)[name]) === null || _latestProps$current$ === void 0 ? void 0 : _latestProps$current$.call(_latestProps$current, ...args);
74
+ };
75
+ });
62
76
  const extra_ops = {
63
- onSelectionChange: props.onSelectionChange,
64
- onCellSelectionChange: props.onCellSelectionChange,
65
77
  licenseKey: licenseKey,
66
78
  editable: props.editable,
67
79
  treeColumn: props.allowChildRows ? firstcolumn.name : undefined,
@@ -72,7 +84,7 @@ function AzGrid(props) {
72
84
  ...events,
73
85
  ...extra_ops
74
86
  };
75
- }, [cached_columns, props.allowChildRows, props.editable, props.RowDetail, props.onEditComplete]);
87
+ }, [cached_columns, props.allowChildRows, props.editable, props.RowDetail, props.licenseKey, ...callback_option_names.map(name => !!props[name])]);
76
88
  const static_gridOptions = _react.default.useMemo(() => {
77
89
  const finalres = {
78
90
  ...base_gridOptions,
@@ -93,9 +105,10 @@ function AzGrid(props) {
93
105
  return _react.default.createElement(DataGridEventsWrapper, {
94
106
  ...props,
95
107
  gridRef: gridRef,
108
+ liveGridRef: liveGridRef,
96
109
  static_gridOptions: static_gridOptions,
97
110
  dynamic_gridOptions: dynamic_gridOptions,
98
- columns: cached_columns,
111
+ columns: a11y_columns,
99
112
  dataSource: dataSource,
100
113
  highlightedRow: props.highlightedRow
101
114
  });
@@ -126,6 +139,7 @@ function DataGridEventsWrapper(props) {
126
139
  onRowClick,
127
140
  onRowContextMenu,
128
141
  onRenderRow,
142
+ onRenderLoadMask,
129
143
  update_menuRow,
130
144
  menuAnchorEl,
131
145
  menuRow
@@ -135,19 +149,47 @@ function DataGridEventsWrapper(props) {
135
149
  * Merge click events into grid options
136
150
  */
137
151
  const static_gridOptions = _react.default.useMemo(() => {
152
+ const opts = props.static_gridOptions || {};
138
153
  const events = {
139
154
  onRowClick: onRowClick,
140
155
  onRowContextMenu: onRowContextMenu
141
156
  };
157
+ // internal row attributes first, consumer's onRenderRow last so it can override them
158
+ const consumerOnRenderRow = opts.onRenderRow;
142
159
  const renderProps = {
143
- onRenderRow: onRenderRow
160
+ onRenderRow: consumerOnRenderRow ? rowProps => {
161
+ onRenderRow(rowProps);
162
+ consumerOnRenderRow(rowProps);
163
+ } : onRenderRow,
164
+ // track loading for aria-busy, the consumer's renderLoadMask (if any) still renders the mask
165
+ renderLoadMask: maskProps => {
166
+ onRenderLoadMask(maskProps);
167
+ return opts.renderLoadMask ? opts.renderLoadMask(maskProps) : undefined;
168
+ }
144
169
  };
170
+ const gridEditable = !!props.editable;
171
+ const a11yProps = {
172
+ headerProps: {
173
+ role: 'row',
174
+ 'aria-rowindex': 1,
175
+ ...opts.headerProps
176
+ },
177
+ rowIndexColumn: (0, _func_a11y.apply_column_a11y)(typeof opts.rowIndexColumn === 'object' ? opts.rowIndexColumn : {}, {
178
+ role: 'rowheader',
179
+ gridEditable
180
+ })
181
+ };
182
+ if (opts.checkboxColumn) a11yProps.checkboxColumn = (0, _func_a11y.apply_column_a11y)(typeof opts.checkboxColumn === 'object' ? opts.checkboxColumn : {}, {
183
+ gridEditable,
184
+ markReadonly: false
185
+ });
145
186
  return {
146
- ...props.static_gridOptions,
187
+ ...opts,
147
188
  ...events,
148
- ...renderProps
189
+ ...renderProps,
190
+ ...a11yProps
149
191
  };
150
- }, [props.static_gridOptions]);
192
+ }, [props.static_gridOptions, props.editable, onRowClick, onRowContextMenu, onRenderRow, onRenderLoadMask]);
151
193
  /* -------------------------------------------------------------------------- */
152
194
  //TODO ContextMenu not from mui...
153
195
  return _react.default.createElement("div", {
@@ -242,7 +284,7 @@ function DataGridSearchWrapper(props) {
242
284
  const {
243
285
  element,
244
286
  filteredData
245
- } = (0, _useGridSearch.useGridSearch)(props.gridRef.current, props);
287
+ } = (0, _useGridSearch.useGridSearch)(props);
246
288
  return _react.default.createElement("div", {
247
289
  className: 'azgrid-flexed azgrid-flexlayout azgrid-nooverflow'
248
290
  }, element, _react.default.createElement(DataGridCore, {
@@ -250,17 +292,24 @@ function DataGridSearchWrapper(props) {
250
292
  dataSource: filteredData
251
293
  }));
252
294
  }
253
- function DataGridCore(props) {
295
+ const DataGridCore = _react.default.memo(DataGridCoreView, (prev, next) => core_prop_names.every(name => prev[name] === next[name]));
296
+ function DataGridCoreView(props) {
254
297
  var _props$theme3;
298
+ const {
299
+ gridRef,
300
+ liveGridRef
301
+ } = props;
302
+ const handle = _react.default.useCallback(ref => {
303
+ if (ref) gridRef.current = ref.current;
304
+ if (liveGridRef) liveGridRef.current = ref;
305
+ }, [gridRef, liveGridRef]);
255
306
  return _react.default.createElement("div", {
256
307
  className: (0, _clsx.default)(props.className, 'azgrid-flexed', 'azgrid-flexlayout')
257
308
  }, _react.default.createElement(_reactdatagridEnterprise.default, {
258
309
  ...props.static_gridOptions,
259
310
  ...props.dynamic_gridOptions,
260
- rowIndexColumn: true,
261
- handle: ref => {
262
- if (ref) props.gridRef.current = ref.current;
263
- },
311
+ rowIndexColumn: props.static_gridOptions.rowIndexColumn || true,
312
+ handle: handle,
264
313
  theme: "default-light",
265
314
  className: (0, _clsx.default)('azgrid azgrid-flexed', props.allowChildRows && 'azgrid-tree', `azgrid-theme-${(_props$theme3 = props.theme) !== null && _props$theme3 !== void 0 ? _props$theme3 : props.dark ? 'dark' : 'light'}`),
266
315
  columns: props.columns,
package/package.json CHANGED
@@ -1,68 +1,68 @@
1
- {
2
- "name": "@azrico/reactgrid",
3
- "version": "1.4.1",
4
- "main": "dist/index.js",
5
- "description": "React Datagrid",
6
- "author": "Azrideus <MehrdadTavangar@gmail.com>",
7
- "homepage": ".",
8
- "scripts": {
9
- "start": "react-scripts start",
10
- "build": "tsc && yarn cp_themes && babel dist --out-dir dist",
11
- "test": "rem",
12
- "check:theme": "node config/check-theme.cjs",
13
- "theme:generate": "node config/generate-theme.cjs",
14
- "cp_themes": "copyfiles ./src/themes/* ./dist/"
15
- },
16
- "config-overrides-path": "../../config/config-overrides.js",
17
- "devDependencies": {
18
- "@babel/cli": "^7.13.14",
19
- "@babel/core": "^7.13.15",
20
- "@babel/eslint-parser": "^7.12.17",
21
- "@babel/node": "^7.13.13",
22
- "@babel/plugin-proposal-class-properties": "^7.12.13",
23
- "@babel/plugin-proposal-nullish-coalescing-operator": "^7.14.5",
24
- "@babel/preset-env": "^7.13.15",
25
- "@babel/preset-typescript": "^7.14.5",
26
- "@mui/material": "*",
27
- "@types/react": "^18.0.25",
28
- "@types/react-dom": "^18.0.8",
29
- "react-dom": "^18.2.0",
30
- "react-scripts": "^5.0.1",
31
- "typescript": "^4.8.4"
32
- },
33
- "dependencies": {
34
- "@azrico/controls": "1.6.1",
35
- "@azrico/object": "^1.4.97",
36
- "@emotion/react": "^11.9.3",
37
- "@emotion/styled": "^11.9.3",
38
- "@inovua/reactdatagrid-enterprise": "^5.10.2",
39
- "clsx": "^2.0.0",
40
- "lodash.debounce": "^4.0.8",
41
- "react": "^18.2.0",
42
- "react-use-size": "^3.0.1"
43
- },
44
- "peerDependencies": {
45
- "@azrico/controls": ">=1.6.1",
46
- "@azrico/object": ">=1.4.97",
47
- "@emotion/react": ">=11.9.3",
48
- "@emotion/styled": ">=11.9.3",
49
- "@inovua/reactdatagrid-enterprise": ">=5.10.2",
50
- "@mui/material": ">=5.0.0 <8.0.0",
51
- "clsx": ">=1.2.1",
52
- "react": ">=18.2.0",
53
- "react-use-size": ">=3.0.1"
54
- },
55
- "browserslist": {
56
- "production": [
57
- ">0.2%",
58
- "not dead",
59
- "not op_mini all"
60
- ],
61
- "development": [
62
- "last 1 chrome version",
63
- "last 1 firefox version",
64
- "last 1 safari version"
65
- ]
66
- },
67
- "packageManager": "yarn@4.10.2"
1
+ {
2
+ "name": "@azrico/reactgrid",
3
+ "version": "1.5.2",
4
+ "main": "dist/index.js",
5
+ "description": "React Datagrid",
6
+ "author": "Azrideus <MehrdadTavangar@gmail.com>",
7
+ "homepage": ".",
8
+ "scripts": {
9
+ "start": "react-scripts start",
10
+ "build": "tsc && yarn cp_themes && babel dist --out-dir dist",
11
+ "test": "rem",
12
+ "check:theme": "node config/check-theme.cjs",
13
+ "theme:generate": "node config/generate-theme.cjs",
14
+ "cp_themes": "copyfiles ./src/themes/* ./dist/"
15
+ },
16
+ "config-overrides-path": "../../config/config-overrides.js",
17
+ "devDependencies": {
18
+ "@babel/cli": "^7.13.14",
19
+ "@babel/core": "^7.13.15",
20
+ "@babel/eslint-parser": "^7.12.17",
21
+ "@babel/node": "^7.13.13",
22
+ "@babel/plugin-proposal-class-properties": "^7.12.13",
23
+ "@babel/plugin-proposal-nullish-coalescing-operator": "^7.14.5",
24
+ "@babel/preset-env": "^7.13.15",
25
+ "@babel/preset-typescript": "^7.14.5",
26
+ "@mui/material": "*",
27
+ "@types/react": "^18.0.25",
28
+ "@types/react-dom": "^18.0.8",
29
+ "react-dom": "^18.2.0",
30
+ "react-scripts": "^5.0.1",
31
+ "typescript": "^4.8.4"
32
+ },
33
+ "dependencies": {
34
+ "@azrico/controls": "1.6.1",
35
+ "@azrico/object": "^1.4.97",
36
+ "@emotion/react": "^11.9.3",
37
+ "@emotion/styled": "^11.9.3",
38
+ "@inovua/reactdatagrid-enterprise": "^5.10.2",
39
+ "clsx": "^2.0.0",
40
+ "lodash.debounce": "^4.0.8",
41
+ "react": "^18.2.0",
42
+ "react-use-size": "^3.0.1"
43
+ },
44
+ "peerDependencies": {
45
+ "@azrico/controls": ">=1.6.1",
46
+ "@azrico/object": ">=1.4.97",
47
+ "@emotion/react": ">=11.9.3",
48
+ "@emotion/styled": ">=11.9.3",
49
+ "@inovua/reactdatagrid-enterprise": ">=5.10.2",
50
+ "@mui/material": ">=5.0.0 <8.0.0",
51
+ "clsx": ">=1.2.1",
52
+ "react": ">=18.2.0",
53
+ "react-use-size": ">=3.0.1"
54
+ },
55
+ "browserslist": {
56
+ "production": [
57
+ ">0.2%",
58
+ "not dead",
59
+ "not op_mini all"
60
+ ],
61
+ "development": [
62
+ "last 1 chrome version",
63
+ "last 1 firefox version",
64
+ "last 1 safari version"
65
+ ]
66
+ },
67
+ "packageManager": "yarn@4.10.2"
68
68
  }