@etsoo/react 1.6.63 → 1.6.65

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[], ref?: React.Ref<ScrollerGridForwardRef<T>>) => T[] | undefined | void) => void;
84
+ setItems: (callback: (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[], ref?: React.Ref<ScrollerGridForwardRef<T>>) => T[] | undefined | void) => 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.63",
3
+ "version": "1.6.65",
4
4
  "description": "TypeScript ReactJs UI Independent Framework",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -123,7 +123,7 @@ export type GridCellRendererProps<T, P = any> = GridCellFormatterProps<T> & {
123
123
  setItems: (
124
124
  callback: (
125
125
  items: T[],
126
- ref?: React.Ref<ScrollerGridForwardRef<T>>
126
+ ref?: ScrollerGridForwardRef<T>
127
127
  ) => T[] | undefined | void
128
128
  ) => void;
129
129
  };
@@ -26,7 +26,7 @@ export type ScrollerGridItemRendererProps<T> = Omit<
26
26
  setItems: (
27
27
  callback: (
28
28
  items: T[],
29
- ref?: React.Ref<ScrollerGridForwardRef<T>>
29
+ ref: ScrollerGridForwardRef<T>
30
30
  ) => T[] | undefined | void
31
31
  ) => void;
32
32
 
@@ -293,10 +293,10 @@ export const ScrollerGrid = <
293
293
  setItems: (
294
294
  callback: (
295
295
  items: T[],
296
- ref?: React.Ref<ScrollerGridForwardRef<T>>
296
+ ref: ScrollerGridForwardRef<T>
297
297
  ) => T[] | undefined | void
298
298
  ) => {
299
- const result = callback(rows, mRef);
299
+ const result = callback(rows, instance);
300
300
  if (result == null) return;
301
301
  setRows(result);
302
302
  }
@@ -336,74 +336,72 @@ export const ScrollerGrid = <
336
336
  if (state.isMounted !== false) setRows([]);
337
337
  };
338
338
 
339
- React.useImperativeHandle(
340
- mRef,
341
- () => ({
342
- scrollTo(params: { scrollLeft: number; scrollTop: number }) {
343
- ref.current?.scrollTo(params);
344
- },
345
- scrollToItem(params: {
346
- align?: Align | undefined;
347
- columnIndex?: number | undefined;
348
- rowIndex?: number | undefined;
349
- }) {
350
- ref.current?.scrollToItem(params);
351
- },
352
- select(rowIndex: number) {
353
- // Select only one item
354
- const selectedItems = state.selectedItems;
355
- selectedItems[0] = rows[rowIndex];
356
-
357
- if (onSelectChange) onSelectChange(selectedItems);
358
- },
359
- selectAll(checked: boolean) {
360
- const selectedItems = state.selectedItems;
361
-
362
- rows.forEach((row) => {
363
- const index = selectedItems.findIndex(
364
- (selectedItem) => selectedItem[idField] === row[idField]
365
- );
366
-
367
- if (checked) {
368
- if (index === -1) selectedItems.push(row);
369
- } else if (index !== -1) {
370
- selectedItems.splice(index, 1);
371
- }
372
- });
373
-
374
- if (onSelectChange) onSelectChange(selectedItems);
375
- },
376
- selectItem(item: T, checked: boolean) {
377
- 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) => {
378
361
  const index = selectedItems.findIndex(
379
- (selectedItem) => selectedItem[idField] === item[idField]
362
+ (selectedItem) => selectedItem[idField] === row[idField]
380
363
  );
381
364
 
382
365
  if (checked) {
383
- if (index === -1) selectedItems.push(item);
384
- } else {
385
- if (index !== -1) selectedItems.splice(index, 1);
366
+ if (index === -1) selectedItems.push(row);
367
+ } else if (index !== -1) {
368
+ selectedItems.splice(index, 1);
386
369
  }
387
-
388
- if (onSelectChange) onSelectChange(selectedItems);
389
- },
390
- reset,
391
- resetAfterColumnIndex(index: number, shouldForceUpdate?: boolean) {
392
- ref.current?.resetAfterColumnIndex(index, shouldForceUpdate);
393
- },
394
- resetAfterIndices(params: {
395
- columnIndex: number;
396
- rowIndex: number;
397
- shouldForceUpdate?: boolean | undefined;
398
- }) {
399
- ref.current?.resetAfterIndices(params);
400
- },
401
- resetAfterRowIndex(index: number, shouldForceUpdate?: boolean) {
402
- 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);
403
384
  }
404
- }),
405
- [rows]
406
- );
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]);
407
405
 
408
406
  React.useEffect(() => {
409
407
  return () => {