@etsoo/react 1.6.62 → 1.6.64

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.
@@ -81,7 +81,7 @@ export type GridCellRendererProps<T, P = any> = GridCellFormatterProps<T> & {
81
81
  * Set items for rerenderer
82
82
  * @param callback Callback
83
83
  */
84
- setItems: (callback: (items: T[]) => T[] | undefined, ref?: React.Ref<ScrollerGridForwardRef<T>>) => void;
84
+ setItems: (callback: ((items: T[]) => T[] | undefined | void) | ((items: T[], ref: ScrollerGridForwardRef<T>) => T[] | undefined | void)) => void;
85
85
  };
86
86
  /**
87
87
  * Grid header cell renderer props
@@ -12,7 +12,7 @@ export type ScrollerGridItemRendererProps<T> = Omit<GridChildComponentProps<T>,
12
12
  * Set items for rerenderer
13
13
  * @param callback Callback
14
14
  */
15
- setItems: (callback: (items: T[]) => T[] | undefined, ref?: React.Ref<ScrollerGridForwardRef<T>>) => void;
15
+ setItems: (callback: (items: T[], ref: ScrollerGridForwardRef<T>) => T[] | undefined | void) => void;
16
16
  /**
17
17
  * Data
18
18
  */
@@ -95,7 +95,7 @@ export const ScrollerGrid = (props) => {
95
95
  data,
96
96
  selectedItems: state.selectedItems,
97
97
  setItems: (callback) => {
98
- const result = callback(rows, mRef);
98
+ const result = callback(rows, instance);
99
99
  if (result == null)
100
100
  return;
101
101
  setRows(result);
@@ -131,7 +131,7 @@ export const ScrollerGrid = (props) => {
131
131
  if (state.isMounted !== false)
132
132
  setRows([]);
133
133
  };
134
- React.useImperativeHandle(mRef, () => ({
134
+ const instance = {
135
135
  scrollTo(params) {
136
136
  var _a;
137
137
  (_a = ref.current) === null || _a === void 0 ? void 0 : _a.scrollTo(params);
@@ -189,7 +189,8 @@ export const ScrollerGrid = (props) => {
189
189
  var _a;
190
190
  (_a = ref.current) === null || _a === void 0 ? void 0 : _a.resetAfterRowIndex(index, shouldForceUpdate);
191
191
  }
192
- }), [rows]);
192
+ };
193
+ React.useImperativeHandle(mRef, () => instance, [rows]);
193
194
  React.useEffect(() => {
194
195
  return () => {
195
196
  state.isMounted = false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/react",
3
- "version": "1.6.62",
3
+ "version": "1.6.64",
4
4
  "description": "TypeScript ReactJs UI Independent Framework",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -121,8 +121,12 @@ export type GridCellRendererProps<T, P = any> = GridCellFormatterProps<T> & {
121
121
  * @param callback Callback
122
122
  */
123
123
  setItems: (
124
- callback: (items: T[]) => T[] | undefined,
125
- ref?: React.Ref<ScrollerGridForwardRef<T>>
124
+ callback:
125
+ | ((items: T[]) => T[] | undefined | void)
126
+ | ((
127
+ items: T[],
128
+ ref: ScrollerGridForwardRef<T>
129
+ ) => T[] | undefined | void)
126
130
  ) => void;
127
131
  };
128
132
 
@@ -24,8 +24,10 @@ export type ScrollerGridItemRendererProps<T> = Omit<
24
24
  * @param callback Callback
25
25
  */
26
26
  setItems: (
27
- callback: (items: T[]) => T[] | undefined,
28
- ref?: React.Ref<ScrollerGridForwardRef<T>>
27
+ callback: (
28
+ items: T[],
29
+ ref: ScrollerGridForwardRef<T>
30
+ ) => T[] | undefined | void
29
31
  ) => void;
30
32
 
31
33
  /**
@@ -291,10 +293,10 @@ export const ScrollerGrid = <
291
293
  setItems: (
292
294
  callback: (
293
295
  items: T[],
294
- ref?: React.Ref<ScrollerGridForwardRef<T>>
295
- ) => T[] | undefined
296
+ ref: ScrollerGridForwardRef<T>
297
+ ) => T[] | undefined | void
296
298
  ) => {
297
- const result = callback(rows, mRef);
299
+ const result = callback(rows, instance);
298
300
  if (result == null) return;
299
301
  setRows(result);
300
302
  }
@@ -334,74 +336,72 @@ export const ScrollerGrid = <
334
336
  if (state.isMounted !== false) setRows([]);
335
337
  };
336
338
 
337
- React.useImperativeHandle(
338
- mRef,
339
- () => ({
340
- scrollTo(params: { scrollLeft: number; scrollTop: number }) {
341
- ref.current?.scrollTo(params);
342
- },
343
- scrollToItem(params: {
344
- align?: Align | undefined;
345
- columnIndex?: number | undefined;
346
- rowIndex?: number | undefined;
347
- }) {
348
- ref.current?.scrollToItem(params);
349
- },
350
- select(rowIndex: number) {
351
- // Select only one item
352
- const selectedItems = state.selectedItems;
353
- selectedItems[0] = rows[rowIndex];
354
-
355
- if (onSelectChange) onSelectChange(selectedItems);
356
- },
357
- selectAll(checked: boolean) {
358
- const selectedItems = state.selectedItems;
359
-
360
- rows.forEach((row) => {
361
- const index = selectedItems.findIndex(
362
- (selectedItem) => selectedItem[idField] === row[idField]
363
- );
364
-
365
- if (checked) {
366
- if (index === -1) selectedItems.push(row);
367
- } else if (index !== -1) {
368
- selectedItems.splice(index, 1);
369
- }
370
- });
371
-
372
- if (onSelectChange) onSelectChange(selectedItems);
373
- },
374
- selectItem(item: T, checked: boolean) {
375
- const selectedItems = state.selectedItems;
339
+ const instance: ScrollerGridForwardRef<T> = {
340
+ scrollTo(params: { scrollLeft: number; scrollTop: number }) {
341
+ ref.current?.scrollTo(params);
342
+ },
343
+ scrollToItem(params: {
344
+ align?: Align | undefined;
345
+ columnIndex?: number | undefined;
346
+ rowIndex?: number | undefined;
347
+ }) {
348
+ ref.current?.scrollToItem(params);
349
+ },
350
+ select(rowIndex: number) {
351
+ // Select only one item
352
+ const selectedItems = state.selectedItems;
353
+ selectedItems[0] = rows[rowIndex];
354
+
355
+ if (onSelectChange) onSelectChange(selectedItems);
356
+ },
357
+ selectAll(checked: boolean) {
358
+ const selectedItems = state.selectedItems;
359
+
360
+ rows.forEach((row) => {
376
361
  const index = selectedItems.findIndex(
377
- (selectedItem) => selectedItem[idField] === item[idField]
362
+ (selectedItem) => selectedItem[idField] === row[idField]
378
363
  );
379
364
 
380
365
  if (checked) {
381
- if (index === -1) selectedItems.push(item);
382
- } else {
383
- if (index !== -1) selectedItems.splice(index, 1);
366
+ if (index === -1) selectedItems.push(row);
367
+ } else if (index !== -1) {
368
+ selectedItems.splice(index, 1);
384
369
  }
385
-
386
- if (onSelectChange) onSelectChange(selectedItems);
387
- },
388
- reset,
389
- resetAfterColumnIndex(index: number, shouldForceUpdate?: boolean) {
390
- ref.current?.resetAfterColumnIndex(index, shouldForceUpdate);
391
- },
392
- resetAfterIndices(params: {
393
- columnIndex: number;
394
- rowIndex: number;
395
- shouldForceUpdate?: boolean | undefined;
396
- }) {
397
- ref.current?.resetAfterIndices(params);
398
- },
399
- resetAfterRowIndex(index: number, shouldForceUpdate?: boolean) {
400
- ref.current?.resetAfterRowIndex(index, shouldForceUpdate);
370
+ });
371
+
372
+ if (onSelectChange) onSelectChange(selectedItems);
373
+ },
374
+ selectItem(item: T, checked: boolean) {
375
+ const selectedItems = state.selectedItems;
376
+ const index = selectedItems.findIndex(
377
+ (selectedItem) => selectedItem[idField] === item[idField]
378
+ );
379
+
380
+ if (checked) {
381
+ if (index === -1) selectedItems.push(item);
382
+ } else {
383
+ if (index !== -1) selectedItems.splice(index, 1);
401
384
  }
402
- }),
403
- [rows]
404
- );
385
+
386
+ if (onSelectChange) onSelectChange(selectedItems);
387
+ },
388
+ reset,
389
+ resetAfterColumnIndex(index: number, shouldForceUpdate?: boolean) {
390
+ ref.current?.resetAfterColumnIndex(index, shouldForceUpdate);
391
+ },
392
+ resetAfterIndices(params: {
393
+ columnIndex: number;
394
+ rowIndex: number;
395
+ shouldForceUpdate?: boolean | undefined;
396
+ }) {
397
+ ref.current?.resetAfterIndices(params);
398
+ },
399
+ resetAfterRowIndex(index: number, shouldForceUpdate?: boolean) {
400
+ ref.current?.resetAfterRowIndex(index, shouldForceUpdate);
401
+ }
402
+ };
403
+
404
+ React.useImperativeHandle(mRef, () => instance, [rows]);
405
405
 
406
406
  React.useEffect(() => {
407
407
  return () => {