@etsoo/react 1.7.94 → 1.7.95

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 (93) hide show
  1. package/README.md +2 -1
  2. package/__tests__/EventWatcher.tsx +21 -21
  3. package/__tests__/ReactUtils.ts +4 -4
  4. package/__tests__/tsconfig.json +17 -17
  5. package/babel.config.json +8 -8
  6. package/lib/app/CoreConstants.js +2 -2
  7. package/lib/app/EventWatcher.d.ts +1 -1
  8. package/lib/app/EventWatcher.js +3 -5
  9. package/lib/app/InputDialogProps.d.ts +2 -2
  10. package/lib/app/ReactUtils.d.ts +2 -2
  11. package/lib/app/ReactUtils.js +20 -19
  12. package/lib/components/DnDList.d.ts +3 -3
  13. package/lib/components/DnDList.js +4 -4
  14. package/lib/components/DynamicRouter.d.ts +2 -2
  15. package/lib/components/DynamicRouter.js +2 -2
  16. package/lib/components/GridColumn.d.ts +6 -6
  17. package/lib/components/GridColumn.js +7 -7
  18. package/lib/components/GridLoader.d.ts +4 -4
  19. package/lib/components/GridLoader.js +2 -2
  20. package/lib/components/GridMethodRef.d.ts +2 -2
  21. package/lib/components/ListItemReact.d.ts +2 -2
  22. package/lib/components/ScrollRestoration.js +3 -3
  23. package/lib/components/ScrollerGrid.d.ts +7 -12
  24. package/lib/components/ScrollerGrid.js +13 -17
  25. package/lib/components/ScrollerList.d.ts +6 -10
  26. package/lib/components/ScrollerList.js +15 -14
  27. package/lib/custom/CustomFieldReact.d.ts +1 -1
  28. package/lib/index.d.ts +32 -32
  29. package/lib/index.js +31 -31
  30. package/lib/notifier/Notifier.d.ts +5 -5
  31. package/lib/notifier/Notifier.js +7 -7
  32. package/lib/states/CultureState.d.ts +3 -3
  33. package/lib/states/CultureState.js +3 -3
  34. package/lib/states/IState.d.ts +2 -2
  35. package/lib/states/PageState.d.ts +2 -2
  36. package/lib/states/PageState.js +2 -3
  37. package/lib/states/State.d.ts +3 -3
  38. package/lib/states/State.js +2 -2
  39. package/lib/states/UserState.d.ts +2 -2
  40. package/lib/states/UserState.js +5 -5
  41. package/lib/uses/useAsyncState.d.ts +1 -1
  42. package/lib/uses/useAsyncState.js +1 -1
  43. package/lib/uses/useCombinedRefs.js +2 -2
  44. package/lib/uses/useDelayedExecutor.d.ts +1 -1
  45. package/lib/uses/useDelayedExecutor.js +2 -2
  46. package/lib/uses/useDimensions.d.ts +1 -1
  47. package/lib/uses/useDimensions.js +3 -3
  48. package/lib/uses/useParamsEx.d.ts +1 -1
  49. package/lib/uses/useParamsEx.js +2 -2
  50. package/lib/uses/useRefs.d.ts +2 -2
  51. package/lib/uses/useRefs.js +1 -1
  52. package/lib/uses/useSearchParamsEx.d.ts +1 -1
  53. package/lib/uses/useSearchParamsEx.js +3 -3
  54. package/lib/uses/useTimeout.js +2 -2
  55. package/lib/uses/useWindowScroll.js +3 -3
  56. package/lib/uses/useWindowSize.js +4 -5
  57. package/package.json +72 -74
  58. package/src/app/CoreConstants.ts +8 -8
  59. package/src/app/EventWatcher.ts +50 -52
  60. package/src/app/InputDialogProps.ts +16 -16
  61. package/src/app/ReactUtils.ts +206 -208
  62. package/src/components/DnDList.tsx +268 -283
  63. package/src/components/DynamicRouter.tsx +35 -35
  64. package/src/components/GridColumn.ts +201 -201
  65. package/src/components/GridLoader.ts +121 -121
  66. package/src/components/GridMethodRef.ts +26 -26
  67. package/src/components/ListItemReact.ts +2 -2
  68. package/src/components/ScrollRestoration.tsx +24 -24
  69. package/src/components/ScrollerGrid.tsx +428 -448
  70. package/src/components/ScrollerList.tsx +320 -332
  71. package/src/custom/CustomFieldReact.ts +12 -12
  72. package/src/index.ts +35 -35
  73. package/src/notifier/Notifier.ts +229 -240
  74. package/src/states/CultureState.ts +51 -52
  75. package/src/states/IState.ts +19 -19
  76. package/src/states/PageState.ts +63 -66
  77. package/src/states/State.tsx +47 -51
  78. package/src/states/UserState.ts +98 -98
  79. package/src/uses/useAsyncState.ts +37 -39
  80. package/src/uses/useCombinedRefs.ts +16 -16
  81. package/src/uses/useDelayedExecutor.ts +8 -8
  82. package/src/uses/useDimensions.ts +102 -103
  83. package/src/uses/useParamsEx.ts +6 -6
  84. package/src/uses/useRefs.ts +6 -6
  85. package/src/uses/useSearchParamsEx.ts +13 -13
  86. package/src/uses/useTimeout.ts +17 -17
  87. package/src/uses/useWindowScroll.ts +43 -43
  88. package/src/uses/useWindowSize.ts +46 -49
  89. package/tsconfig.json +17 -17
  90. package/.eslintignore +0 -3
  91. package/.eslintrc.json +0 -38
  92. package/.prettierignore +0 -5
  93. package/.prettierrc +0 -6
package/README.md CHANGED
@@ -1,4 +1,5 @@
1
1
  # AppReact
2
+
2
3
  **TypeScript ReactJs UI Independent Framework**
3
4
 
4
5
  ## Installing
@@ -15,4 +16,4 @@ Using yarn:
15
16
  $ yarn add @etsoo/react
16
17
  ```
17
18
 
18
- ## React UI Implmentation
19
+ ## React UI Implmentation
@@ -1,27 +1,27 @@
1
- import { render, screen } from '@testing-library/react';
2
- import React from 'react';
3
- import { EventWatcher } from '../src/app/EventWatcher';
1
+ import { render, screen } from "@testing-library/react";
2
+ import React from "react";
3
+ import { EventWatcher } from "../src/app/EventWatcher";
4
4
 
5
5
  function App(props: { callback: () => void }) {
6
- const { callback } = props;
7
- const watcher = new EventWatcher();
6
+ const { callback } = props;
7
+ const watcher = new EventWatcher();
8
8
 
9
- React.useEffect(() => {
10
- watcher.add({
11
- type: 'click',
12
- action: (_event) => callback(),
13
- once: true
14
- });
15
- }, []);
16
- return <button onClick={(event) => watcher.do(event)}></button>;
9
+ React.useEffect(() => {
10
+ watcher.add({
11
+ type: "click",
12
+ action: (_event) => callback(),
13
+ once: true
14
+ });
15
+ }, []);
16
+ return <button onClick={(event) => watcher.do(event)}></button>;
17
17
  }
18
18
 
19
- test('Tests for EventWatcher', () => {
20
- const callback = jest.fn();
21
- render(<App callback={callback} />);
22
- const button = screen.getByRole<HTMLButtonElement>('button');
23
- button.click();
24
- expect(callback).toHaveBeenCalled();
25
- button.click();
26
- expect(callback).toHaveBeenCalledTimes(1);
19
+ test("Tests for EventWatcher", () => {
20
+ const callback = jest.fn();
21
+ render(<App callback={callback} />);
22
+ const button = screen.getByRole<HTMLButtonElement>("button");
23
+ button.click();
24
+ expect(callback).toHaveBeenCalled();
25
+ button.click();
26
+ expect(callback).toHaveBeenCalledTimes(1);
27
27
  });
@@ -1,6 +1,6 @@
1
- import { ReactUtils } from '../src/app/ReactUtils';
1
+ import { ReactUtils } from "../src/app/ReactUtils";
2
2
 
3
- test('Tests for ReactUtils.formatInputValue', () => {
4
- expect(ReactUtils.formatInputValue([1, 'a'])).toEqual([1, 'a']);
5
- expect(ReactUtils.formatInputValue(true)).toEqual('true');
3
+ test("Tests for ReactUtils.formatInputValue", () => {
4
+ expect(ReactUtils.formatInputValue([1, "a"])).toEqual([1, "a"]);
5
+ expect(ReactUtils.formatInputValue(true)).toEqual("true");
6
6
  });
@@ -1,19 +1,19 @@
1
1
  {
2
- "compilerOptions": {
3
- "target": "ES2020",
4
- "module": "ESNext",
5
- "moduleResolution": "Node10",
6
- "allowJs": false,
7
- "skipLibCheck": true,
8
- "esModuleInterop": true,
9
- "allowSyntheticDefaultImports": true,
10
- "strict": true,
11
- "forceConsistentCasingInFileNames": true,
12
- "resolveJsonModule": true,
13
- "isolatedModules": true,
14
- "noEmit": true,
15
- "jsx": "react",
16
- "declaration": true
17
- },
18
- "include": [".."]
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "module": "ESNext",
5
+ "moduleResolution": "Node10",
6
+ "allowJs": false,
7
+ "skipLibCheck": true,
8
+ "esModuleInterop": true,
9
+ "allowSyntheticDefaultImports": true,
10
+ "strict": true,
11
+ "forceConsistentCasingInFileNames": true,
12
+ "resolveJsonModule": true,
13
+ "isolatedModules": true,
14
+ "noEmit": true,
15
+ "jsx": "react",
16
+ "declaration": true
17
+ },
18
+ "include": [".."]
19
19
  }
package/babel.config.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
- "presets": [["@babel/env"]],
3
- "plugins": [
4
- [
5
- "@babel/plugin-transform-runtime",
6
- {
7
- "corejs": 3
8
- }
9
- ]
2
+ "presets": [["@babel/env"]],
3
+ "plugins": [
4
+ [
5
+ "@babel/plugin-transform-runtime",
6
+ {
7
+ "corejs": 3
8
+ }
10
9
  ]
10
+ ]
11
11
  }
@@ -6,9 +6,9 @@ export var CoreConstants;
6
6
  /**
7
7
  * User id saved field
8
8
  */
9
- CoreConstants.FieldUserIdSaved = 'UserIdSaved';
9
+ CoreConstants.FieldUserIdSaved = "UserIdSaved";
10
10
  /**
11
11
  * Rresh token cache field
12
12
  */
13
- CoreConstants.FieldRefreshToken = 'RefreshToken';
13
+ CoreConstants.FieldRefreshToken = "RefreshToken";
14
14
  })(CoreConstants || (CoreConstants = {}));
@@ -1,4 +1,4 @@
1
- import React from 'react';
1
+ import React from "react";
2
2
  /**
3
3
  * Event watcher action
4
4
  */
@@ -18,7 +18,7 @@ export class EventWatcher {
18
18
  */
19
19
  do(event) {
20
20
  // Type
21
- const type = typeof event === 'string' ? event : event.type;
21
+ const type = typeof event === "string" ? event : event.type;
22
22
  // Execute
23
23
  const removeIndices = [];
24
24
  this.actions.forEach((item, index) => {
@@ -29,14 +29,12 @@ export class EventWatcher {
29
29
  removeIndices.push(index);
30
30
  });
31
31
  // Remove all once actions
32
- removeIndices
33
- .reverse()
34
- .forEach((index) => this.actions.splice(index, 1));
32
+ removeIndices.reverse().forEach((index) => this.actions.splice(index, 1));
35
33
  }
36
34
  isMatch(action, type) {
37
35
  if (action.type == null)
38
36
  return true;
39
- if (typeof action.type === 'string')
37
+ if (typeof action.type === "string")
40
38
  return action.type === type;
41
39
  return action.type.includes(type);
42
40
  }
@@ -1,5 +1,5 @@
1
- import { NotificationContent, NotificationReturn } from '@etsoo/notificationbase';
2
- import { NotificationReactCallProps } from '../notifier/Notifier';
1
+ import { NotificationContent, NotificationReturn } from "@etsoo/notificationbase";
2
+ import { NotificationReactCallProps } from "../notifier/Notifier";
3
3
  /**
4
4
  * Input dialog props
5
5
  */
@@ -1,5 +1,5 @@
1
- import { DataTypes } from '@etsoo/shared';
2
- import React from 'react';
1
+ import { DataTypes } from "@etsoo/shared";
2
+ import React from "react";
3
3
  /**
4
4
  * React utils
5
5
  */
@@ -1,4 +1,4 @@
1
- import { DateUtils, DomUtils, Utils } from '@etsoo/shared';
1
+ import { DateUtils, DomUtils, Utils } from "@etsoo/shared";
2
2
  /**
3
3
  * React utils
4
4
  */
@@ -12,9 +12,9 @@ export var ReactUtils;
12
12
  function formatInputValue(value) {
13
13
  if (value === null)
14
14
  return undefined;
15
- if (typeof value === 'number')
15
+ if (typeof value === "number")
16
16
  return value;
17
- if (typeof value === 'string')
17
+ if (typeof value === "string")
18
18
  return value;
19
19
  if (Array.isArray(value))
20
20
  return value;
@@ -37,10 +37,10 @@ export var ReactUtils;
37
37
  return false;
38
38
  while (target != null && target != event.currentTarget) {
39
39
  const nodeName = target.nodeName.toUpperCase();
40
- if (nodeName === 'INPUT' ||
41
- nodeName === 'BUTTON' ||
42
- nodeName === 'A' ||
43
- target.hasAttribute('onClick'))
40
+ if (nodeName === "INPUT" ||
41
+ nodeName === "BUTTON" ||
42
+ nodeName === "A" ||
43
+ target.hasAttribute("onClick"))
44
44
  return false;
45
45
  target = target.parentElement;
46
46
  }
@@ -55,12 +55,12 @@ export var ReactUtils;
55
55
  */
56
56
  function triggerChange(input, value, cancelable = false) {
57
57
  // Radio type not supported
58
- if (input.type === 'radio')
58
+ if (input.type === "radio")
59
59
  return;
60
60
  // checked?
61
- const checked = input.type === 'checkbox';
61
+ const checked = input.type === "checkbox";
62
62
  // Property name
63
- const property = checked ? 'checked' : 'value';
63
+ const property = checked ? "checked" : "value";
64
64
  // input.value = newValue will not trigger the change event
65
65
  // input type = 'hidden' will also not trigger the event
66
66
  // https://coryrylan.com/blog/trigger-input-updates-with-react-controlled-inputs
@@ -68,7 +68,7 @@ export var ReactUtils;
68
68
  if (checked) {
69
69
  const checkedValue = input.value == value;
70
70
  nativeInputValueSetter?.call(input, checkedValue);
71
- const clickEvent = new Event('click', {
71
+ const clickEvent = new Event("click", {
72
72
  bubbles: true,
73
73
  cancelable
74
74
  });
@@ -76,7 +76,7 @@ export var ReactUtils;
76
76
  }
77
77
  else {
78
78
  nativeInputValueSetter?.call(input, value);
79
- const inputEvent = new Event('change', {
79
+ const inputEvent = new Event("change", {
80
80
  bubbles: true,
81
81
  cancelable
82
82
  });
@@ -93,7 +93,7 @@ export var ReactUtils;
93
93
  function updateRefs(refs, data, callback) {
94
94
  const local = callback == null
95
95
  ? undefined
96
- : typeof callback === 'function'
96
+ : typeof callback === "function"
97
97
  ? callback
98
98
  : (item, value) => {
99
99
  item[callback] = value;
@@ -111,13 +111,14 @@ export var ReactUtils;
111
111
  item instanceof HTMLTextAreaElement ||
112
112
  item instanceof HTMLSelectElement) {
113
113
  const value = Utils.getNestedValue(data, item.name || k);
114
- const isDateTime = item.type === 'datetime-local';
115
- if (isDateTime || item.type === 'date') {
114
+ const isDateTime = item.type === "datetime-local";
115
+ if (isDateTime || item.type === "date") {
116
116
  item.value =
117
- DateUtils.formatForInput(value, isDateTime ? false : undefined) ?? '';
117
+ DateUtils.formatForInput(value, isDateTime ? false : undefined) ??
118
+ "";
118
119
  }
119
120
  else {
120
- item.value = `${value ?? ''}`;
121
+ item.value = `${value ?? ""}`;
121
122
  }
122
123
  }
123
124
  else {
@@ -136,11 +137,11 @@ export var ReactUtils;
136
137
  function updateRefValues(refs, data, callback, ignoreEmpty = true) {
137
138
  const local = callback == null
138
139
  ? undefined
139
- : typeof callback === 'function'
140
+ : typeof callback === "function"
140
141
  ? callback
141
142
  : (item) => item[callback];
142
143
  const formatValue = (value) => {
143
- if (ignoreEmpty && value === '')
144
+ if (ignoreEmpty && value === "")
144
145
  return null;
145
146
  return value;
146
147
  };
@@ -1,6 +1,6 @@
1
- import { UniqueIdentifier } from '@dnd-kit/core';
2
- import { DataTypes } from '@etsoo/shared';
3
- import React, { CSSProperties } from 'react';
1
+ import { UniqueIdentifier } from "@dnd-kit/core";
2
+ import { DataTypes } from "@etsoo/shared";
3
+ import React, { CSSProperties } from "react";
4
4
  /**
5
5
  * DnD list forward ref
6
6
  */
@@ -1,8 +1,8 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import { DndContext } from '@dnd-kit/core';
3
- import { SortableContext, useSortable, verticalListSortingStrategy } from '@dnd-kit/sortable';
4
- import { CSS } from '@dnd-kit/utilities';
5
- import React from 'react';
2
+ import { DndContext } from "@dnd-kit/core";
3
+ import { SortableContext, useSortable, verticalListSortingStrategy } from "@dnd-kit/sortable";
4
+ import { CSS } from "@dnd-kit/utilities";
5
+ import React from "react";
6
6
  function SortableItem(props) {
7
7
  // Destruct
8
8
  const { id, itemRenderer, style = {} } = props;
@@ -1,5 +1,5 @@
1
- import React from 'react';
2
- import { RouteObject } from 'react-router-dom';
1
+ import React from "react";
2
+ import { RouteObject } from "react-router-dom";
3
3
  /**
4
4
  * Dynamic router props
5
5
  */
@@ -1,6 +1,6 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import { BridgeUtils } from '@etsoo/appscript';
3
- import { BrowserRouter, createBrowserRouter, createMemoryRouter, MemoryRouter } from 'react-router-dom';
2
+ import { BridgeUtils } from "@etsoo/appscript";
3
+ import { BrowserRouter, createBrowserRouter, createMemoryRouter, MemoryRouter } from "react-router-dom";
4
4
  function getEntries(host) {
5
5
  const startUrl = host.getStartUrl();
6
6
  return startUrl == null ? undefined : [startUrl];
@@ -1,8 +1,8 @@
1
- import { EntityStatus } from '@etsoo/appscript';
2
- import { DataTypes } from '@etsoo/shared';
3
- import React from 'react';
4
- import { GridLoaderStates } from './GridLoader';
5
- import { ScrollerGridForwardRef } from './ScrollerGrid';
1
+ import { EntityStatus } from "@etsoo/appscript";
2
+ import { DataTypes } from "@etsoo/shared";
3
+ import React from "react";
4
+ import { GridLoaderStates } from "./GridLoader";
5
+ import { ScrollerGridForwardRef } from "./ScrollerGrid";
6
6
  /**
7
7
  * Grid data type
8
8
  */
@@ -11,7 +11,7 @@ export { GridDataType };
11
11
  /**
12
12
  * Grid align
13
13
  */
14
- export type GridAlign = 'center' | 'inherit' | 'justify' | 'left' | 'right';
14
+ export type GridAlign = "center" | "inherit" | "justify" | "left" | "right";
15
15
  /**
16
16
  * Data align get
17
17
  * @param align Align
@@ -1,5 +1,5 @@
1
- import { EntityStatus } from '@etsoo/appscript';
2
- import { DataTypes } from '@etsoo/shared';
1
+ import { EntityStatus } from "@etsoo/appscript";
2
+ import { DataTypes } from "@etsoo/shared";
3
3
  /**
4
4
  * Grid data type
5
5
  */
@@ -16,9 +16,9 @@ export const GridAlignGet = (align, type) => {
16
16
  type === GridDataType.IntMoney ||
17
17
  type === GridDataType.Int ||
18
18
  type === GridDataType.Number)
19
- return 'right';
19
+ return "right";
20
20
  else if (type === GridDataType.Boolean)
21
- return 'center';
21
+ return "center";
22
22
  }
23
23
  return align;
24
24
  };
@@ -30,12 +30,12 @@ export const GridAlignGet = (align, type) => {
30
30
  export const GridDeletedCellBoxStyle = (data) => {
31
31
  if (data == null)
32
32
  return {};
33
- const status = 'status' in data
33
+ const status = "status" in data
34
34
  ? data.status
35
- : 'entityStatus' in data
35
+ : "entityStatus" in data
36
36
  ? data.entityStatus
37
37
  : EntityStatus.Normal;
38
38
  if (status === EntityStatus.Inactivated || status === EntityStatus.Deleted)
39
- return { textDecoration: 'line-through' };
39
+ return { textDecoration: "line-through" };
40
40
  return {};
41
41
  };
@@ -1,5 +1,5 @@
1
- import { QueryPagingData } from '@etsoo/appscript';
2
- import { DataTypes } from '@etsoo/shared';
1
+ import { QueryPagingData } from "@etsoo/appscript";
2
+ import { DataTypes } from "@etsoo/shared";
3
3
  /**
4
4
  * Grid size
5
5
  */
@@ -29,7 +29,7 @@ export declare function GridDataGetData<F extends DataTypes.BasicTemplate>(data?
29
29
  /**
30
30
  * Grid Json data
31
31
  */
32
- export type GridJsonData = Omit<GridLoadDataProps, 'data'>;
32
+ export type GridJsonData = Omit<GridLoadDataProps, "data">;
33
33
  /**
34
34
  * Grid data load props
35
35
  */
@@ -68,7 +68,7 @@ export interface GridLoader<T extends object> {
68
68
  /**
69
69
  * Default order by
70
70
  */
71
- defaultOrderBy?: string;
71
+ defaultOrderBy?: Record<string, boolean>;
72
72
  /**
73
73
  * Batch size when load data, default will be calcuated with height and itemSize
74
74
  */
@@ -1,11 +1,11 @@
1
- import { DomUtils } from '@etsoo/shared';
1
+ import { DomUtils } from "@etsoo/shared";
2
2
  /**
3
3
  * Grid size calculation
4
4
  * @param size Size
5
5
  * @param input Input
6
6
  */
7
7
  export const GridSizeGet = (size, input) => {
8
- if (typeof size === 'function')
8
+ if (typeof size === "function")
9
9
  return size(input);
10
10
  return size;
11
11
  };
@@ -1,5 +1,5 @@
1
- import { Align } from 'react-window';
2
- import { GridLoaderPartialStates } from './GridLoader';
1
+ import { Align } from "react-window";
2
+ import { GridLoaderPartialStates } from "./GridLoader";
3
3
  /**
4
4
  * Grid method ref
5
5
  */
@@ -1,5 +1,5 @@
1
- import { ListItem } from '@etsoo/appscript';
2
- import React from 'react';
1
+ import { ListItem } from "@etsoo/appscript";
2
+ import React from "react";
3
3
  /**
4
4
  * React list item
5
5
  */
@@ -1,7 +1,7 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import React from 'react';
3
- import { useLocation } from 'react-router-dom';
4
- import { useWindowScroll } from '../uses/useWindowScroll';
2
+ import React from "react";
3
+ import { useLocation } from "react-router-dom";
4
+ import { useWindowScroll } from "../uses/useWindowScroll";
5
5
  const urls = {};
6
6
  /**
7
7
  * Scroll restoration
@@ -1,9 +1,9 @@
1
- import { DataTypes } from '@etsoo/shared';
2
- import React from 'react';
3
- import { Align, GridChildComponentProps, VariableSizeGridProps } from 'react-window';
4
- import { GridLoader, GridLoaderStates } from './GridLoader';
5
- import { GridMethodRef } from './GridMethodRef';
6
- export type ScrollerGridItemRendererProps<T> = Omit<GridChildComponentProps<T>, 'data'> & {
1
+ import { DataTypes } from "@etsoo/shared";
2
+ import React from "react";
3
+ import { Align, GridChildComponentProps, VariableSizeGridProps } from "react-window";
4
+ import { GridLoader, GridLoaderStates } from "./GridLoader";
5
+ import { GridMethodRef } from "./GridMethodRef";
6
+ export type ScrollerGridItemRendererProps<T> = Omit<GridChildComponentProps<T>, "data"> & {
7
7
  /**
8
8
  * Selected items
9
9
  */
@@ -21,12 +21,7 @@ export type ScrollerGridItemRendererProps<T> = Omit<GridChildComponentProps<T>,
21
21
  /**
22
22
  * Scroller vertical grid props
23
23
  */
24
- export interface ScrollerGridProps<T extends object> extends GridLoader<T>, Omit<VariableSizeGridProps<T>, 'children' | 'rowCount' | 'rowHeight'> {
25
- /**
26
- * Default order by asc
27
- * @default true
28
- */
29
- defaultOrderByAsc?: boolean;
24
+ export interface ScrollerGridProps<T extends object> extends GridLoader<T>, Omit<VariableSizeGridProps<T>, "children" | "rowCount" | "rowHeight"> {
30
25
  /**
31
26
  * Footer renderer
32
27
  */
@@ -1,6 +1,6 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import React from 'react';
3
- import { VariableSizeGrid } from 'react-window';
2
+ import React from "react";
3
+ import { VariableSizeGrid } from "react-window";
4
4
  /**
5
5
  * Scroller vertical grid
6
6
  * @param props Props
@@ -8,7 +8,7 @@ import { VariableSizeGrid } from 'react-window';
8
8
  */
9
9
  export const ScrollerGrid = (props) => {
10
10
  // Destruct
11
- const { autoLoad = true, defaultOrderBy, defaultOrderByAsc, footerRenderer, headerRenderer, itemRenderer, idField = 'id', loadBatchSize, loadData, mRef, onItemsRendered, onSelectChange, rowHeight = 53, threshold = 6, width, onInitLoad, onUpdateRows, ...rest } = props;
11
+ const { autoLoad = true, defaultOrderBy, footerRenderer, headerRenderer, itemRenderer, idField = "id", loadBatchSize, loadData, mRef, onItemsRendered, onSelectChange, rowHeight = 53, threshold = 6, width, onInitLoad, onUpdateRows, ...rest } = props;
12
12
  // Rows
13
13
  const [rows, updateRows] = React.useState([]);
14
14
  const setRows = (rows, reset = false) => {
@@ -22,7 +22,6 @@ export const ScrollerGrid = (props) => {
22
22
  queryPaging: {
23
23
  currentPage: 0,
24
24
  orderBy: defaultOrderBy,
25
- orderByAsc: defaultOrderByAsc,
26
25
  batchSize: 10
27
26
  },
28
27
  autoLoad,
@@ -54,8 +53,7 @@ export const ScrollerGrid = (props) => {
54
53
  const newItems = result.length;
55
54
  refs.current.lastLoadedItems = newItems;
56
55
  refs.current.isNextPageLoading = false;
57
- refs.current.hasNextPage =
58
- newItems >= refs.current.queryPaging.batchSize;
56
+ refs.current.hasNextPage = newItems >= refs.current.queryPaging.batchSize;
59
57
  if (pageAdd === 0) {
60
58
  // New items
61
59
  const newRows = refs.current.lastLoadedItems
@@ -73,7 +71,10 @@ export const ScrollerGrid = (props) => {
73
71
  }
74
72
  else {
75
73
  // Set current page
76
- refs.current.queryPaging.currentPage += pageAdd;
74
+ if (refs.current.queryPaging.currentPage == null)
75
+ refs.current.queryPaging.currentPage = pageAdd;
76
+ else
77
+ refs.current.queryPaging.currentPage += pageAdd;
77
78
  // Update rows, avoid duplicate items
78
79
  const newRows = [...rows];
79
80
  for (const item of result) {
@@ -89,9 +90,7 @@ export const ScrollerGrid = (props) => {
89
90
  // Item renderer
90
91
  const itemRendererLocal = (itemProps, state) => {
91
92
  // Custom render
92
- const data = itemProps.rowIndex < rows.length
93
- ? rows[itemProps.rowIndex]
94
- : undefined;
93
+ const data = itemProps.rowIndex < rows.length ? rows[itemProps.rowIndex] : undefined;
95
94
  return itemRenderer({
96
95
  ...itemProps,
97
96
  data,
@@ -108,8 +107,7 @@ export const ScrollerGrid = (props) => {
108
107
  const onItemsRenderedLocal = (props) => {
109
108
  // No items, means no necessary to load more data during reset
110
109
  const itemCount = rows.length;
111
- if (itemCount > 0 &&
112
- props.visibleRowStopIndex + threshold > itemCount) {
110
+ if (itemCount > 0 && props.visibleRowStopIndex + threshold > itemCount) {
113
111
  // Auto load next page
114
112
  loadDataLocal();
115
113
  }
@@ -240,10 +238,8 @@ export const ScrollerGrid = (props) => {
240
238
  // Layout
241
239
  return (_jsxs(React.Fragment, { children: [headerRenderer && headerRenderer(refs.current), _jsx(VariableSizeGrid, { itemKey: ({ columnIndex, rowIndex, data }) => {
242
240
  if (data == null)
243
- return [rowIndex, columnIndex].join(',');
241
+ return [rowIndex, columnIndex].join(",");
244
242
  // ${data[idField]}-${rowIndex} always unique but no cache for the same item
245
- return [`${data[idField]}`, columnIndex].join(',');
246
- }, onItemsRendered: onItemsRenderedLocal, ref: ref, rowCount: rowCount, rowHeight: typeof rowHeight === 'function'
247
- ? rowHeight
248
- : () => rowHeight, style: { overflowX: 'hidden' }, width: width, ...rest, children: (props) => itemRendererLocal(props, refs.current) }), footerRenderer && footerRenderer(rows, refs.current)] }));
243
+ return [`${data[idField]}`, columnIndex].join(",");
244
+ }, onItemsRendered: onItemsRenderedLocal, ref: ref, rowCount: rowCount, rowHeight: typeof rowHeight === "function" ? rowHeight : () => rowHeight, style: { overflowX: "hidden" }, width: width, ...rest, children: (props) => itemRendererLocal(props, refs.current) }), footerRenderer && footerRenderer(rows, refs.current)] }));
249
245
  };
@@ -1,16 +1,12 @@
1
- import { DataTypes } from '@etsoo/shared';
2
- import React from 'react';
3
- import { Align, ListChildComponentProps, ListProps } from 'react-window';
4
- import { GridLoader } from './GridLoader';
5
- import { GridMethodRef } from './GridMethodRef';
1
+ import { DataTypes } from "@etsoo/shared";
2
+ import React from "react";
3
+ import { Align, ListChildComponentProps, ListProps } from "react-window";
4
+ import { GridLoader } from "./GridLoader";
5
+ import { GridMethodRef } from "./GridMethodRef";
6
6
  /**
7
7
  * Scroller vertical list props
8
8
  */
9
- export interface ScrollerListProps<T extends object> extends GridLoader<T>, Omit<ListProps<T>, 'outerRef' | 'height' | 'width' | 'children' | 'itemCount'> {
10
- /**
11
- * Default order by asc/desc
12
- */
13
- defaultOrderByAsc?: boolean;
9
+ export interface ScrollerListProps<T extends object> extends GridLoader<T>, Omit<ListProps<T>, "outerRef" | "height" | "width" | "children" | "itemCount"> {
14
10
  /**
15
11
  * Methods ref
16
12
  */