@etsoo/react 1.7.94 → 1.7.96

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
@@ -1,7 +1,7 @@
1
- import { IAction, ICulture } from '@etsoo/appscript';
2
- import { DataTypes } from '@etsoo/shared';
3
- import { IProviderProps, IUpdate } from './IState';
4
- import { State } from './State';
1
+ import { IAction, ICulture } from "@etsoo/appscript";
2
+ import { DataTypes } from "@etsoo/shared";
3
+ import { IProviderProps, IUpdate } from "./IState";
4
+ import { State } from "./State";
5
5
 
6
6
  /**
7
7
  * Culture action to manage resources
@@ -12,11 +12,11 @@ export interface CultureAction extends ICulture, IAction {}
12
12
  * Culture calls with the state
13
13
  */
14
14
  export interface CultureCalls extends IUpdate<ICulture, CultureAction> {
15
- /**
16
- * Key value
17
- * @param key Item key
18
- */
19
- get<T = string>(key: string): T | undefined;
15
+ /**
16
+ * Key value
17
+ * @param key Item key
18
+ */
19
+ get<T = string>(key: string): T | undefined;
20
20
  }
21
21
 
22
22
  /**
@@ -26,17 +26,16 @@ export type CultureProviderProps = IProviderProps<CultureAction>;
26
26
 
27
27
  // Calls
28
28
  const calls = {
29
- /**
30
- * Key value
31
- * @param key Item key
32
- */
33
- get<T = string>(key: string) {
34
- const resources = this.state.resources;
35
- const value =
36
- typeof resources === 'object' ? resources[key] : undefined;
37
- if (value == null) return undefined;
38
- return value as T;
39
- }
29
+ /**
30
+ * Key value
31
+ * @param key Item key
32
+ */
33
+ get<T = string>(key: string) {
34
+ const resources = this.state.resources;
35
+ const value = typeof resources === "object" ? resources[key] : undefined;
36
+ if (value == null) return undefined;
37
+ return value as T;
38
+ }
40
39
  } as CultureCalls;
41
40
 
42
41
  /**
@@ -45,42 +44,42 @@ const calls = {
45
44
  * Cannot update a component (`provider`) while rendering a different component
46
45
  */
47
46
  export class CultureState {
48
- /**
49
- * Context
50
- */
51
- readonly context;
47
+ /**
48
+ * Context
49
+ */
50
+ readonly context;
52
51
 
53
- /**
54
- * Provider
55
- */
56
- readonly provider;
52
+ /**
53
+ * Provider
54
+ */
55
+ readonly provider;
57
56
 
58
- /**
59
- * Constructor
60
- */
61
- constructor(item?: DataTypes.CultureDefinition) {
62
- // Default
63
- const defaultItem = item ?? ({} as ICulture);
57
+ /**
58
+ * Constructor
59
+ */
60
+ constructor(item?: DataTypes.CultureDefinition) {
61
+ // Default
62
+ const defaultItem = item ?? ({} as ICulture);
64
63
 
65
- // Load resources
66
- if (item != null && typeof item.resources !== 'object')
67
- item.resources().then((result) => (item.resources = result));
64
+ // Load resources
65
+ if (item != null && typeof item.resources !== "object")
66
+ item.resources().then((result) => (item.resources = result));
68
67
 
69
- // Act
70
- const { context, provider } = State.create(
71
- (state: ICulture, action: CultureAction) => {
72
- // Language reducer
73
- if (state.name !== action.name) {
74
- return { ...action };
75
- }
68
+ // Act
69
+ const { context, provider } = State.create(
70
+ (state: ICulture, action: CultureAction) => {
71
+ // Language reducer
72
+ if (state.name !== action.name) {
73
+ return { ...action };
74
+ }
76
75
 
77
- return state;
78
- },
79
- defaultItem,
80
- calls
81
- );
76
+ return state;
77
+ },
78
+ defaultItem,
79
+ calls
80
+ );
82
81
 
83
- this.context = context;
84
- this.provider = provider;
85
- }
82
+ this.context = context;
83
+ this.provider = provider;
84
+ }
86
85
  }
@@ -1,56 +1,56 @@
1
- import { IAction, IState, UserKey } from '@etsoo/appscript';
2
- import React, { ReactNode } from 'react';
1
+ import { IAction, IState, UserKey } from "@etsoo/appscript";
2
+ import React, { ReactNode } from "react";
3
3
 
4
4
  /**
5
5
  * State UI creator
6
6
  */
7
7
  export interface IUICreator<S extends IState, A extends IAction, P = object> {
8
- (state: S, dispatch: React.Dispatch<A>, props: P): React.ReactElement;
8
+ (state: S, dispatch: React.Dispatch<A>, props: P): React.ReactElement;
9
9
  }
10
10
 
11
11
  /**
12
12
  * State update interface
13
13
  */
14
14
  export interface IUpdate<S extends IState, A extends IAction> {
15
- state: S;
16
- dispatch: React.Dispatch<A>;
15
+ state: S;
16
+ dispatch: React.Dispatch<A>;
17
17
  }
18
18
 
19
19
  /**
20
20
  * State update interface
21
21
  */
22
22
  export interface IStateUpdate {
23
- (authorized?: boolean, matchedFields?: string[]): PromiseLike<void> | void;
23
+ (authorized?: boolean, matchedFields?: string[]): PromiseLike<void> | void;
24
24
  }
25
25
 
26
26
  /**
27
27
  * State update props
28
28
  */
29
29
  export interface IStateProps {
30
- /**
31
- * State last changed fields
32
- */
33
- targetFields?: UserKey[];
30
+ /**
31
+ * State last changed fields
32
+ */
33
+ targetFields?: UserKey[];
34
34
 
35
- /**
36
- * State update callback
37
- */
38
- update: IStateUpdate;
35
+ /**
36
+ * State update callback
37
+ */
38
+ update: IStateUpdate;
39
39
  }
40
40
 
41
41
  /**
42
42
  * State provider update callback
43
43
  */
44
44
  export interface IProviderUpdate<A extends IAction> {
45
- (dispatch: React.Dispatch<A>): void;
45
+ (dispatch: React.Dispatch<A>): void;
46
46
  }
47
47
 
48
48
  /**
49
49
  * State provider props
50
50
  */
51
51
  export interface IProviderProps<A extends IAction> {
52
- /**
53
- * Update callback
54
- */
55
- update?: IProviderUpdate<A>;
52
+ /**
53
+ * Update callback
54
+ */
55
+ update?: IProviderUpdate<A>;
56
56
  }
@@ -1,108 +1,105 @@
1
- import { IAction, IState } from '@etsoo/appscript';
2
- import { IProviderProps, IUpdate } from './IState';
3
- import { State } from './State';
1
+ import { IAction, IState } from "@etsoo/appscript";
2
+ import { IProviderProps, IUpdate } from "./IState";
3
+ import { State } from "./State";
4
4
 
5
5
  /**
6
6
  * Page data interface
7
7
  */
8
8
  export interface IPageData extends IState {
9
- /**
10
- * Page title
11
- */
12
- title?: string;
9
+ /**
10
+ * Page title
11
+ */
12
+ title?: string;
13
13
 
14
- /**
15
- * Page subtitle
16
- */
17
- subtitle?: string;
14
+ /**
15
+ * Page subtitle
16
+ */
17
+ subtitle?: string;
18
18
  }
19
19
 
20
20
  /**
21
21
  * Page action type
22
22
  */
23
23
  export enum PageActionType {
24
- // Update data
25
- Data = 'DATA',
24
+ // Update data
25
+ Data = "DATA",
26
26
 
27
- // Update title
28
- Title = 'TITLE'
27
+ // Update title
28
+ Title = "TITLE"
29
29
  }
30
30
 
31
31
  /**
32
32
  * Page action
33
33
  */
34
34
  export interface PageAction<D extends IPageData> extends IAction {
35
- /**
36
- * Action type
37
- */
38
- type: PageActionType;
35
+ /**
36
+ * Action type
37
+ */
38
+ type: PageActionType;
39
39
 
40
- /**
41
- * Action data
42
- */
43
- data: D;
40
+ /**
41
+ * Action data
42
+ */
43
+ data: D;
44
44
  }
45
45
 
46
46
  /**
47
47
  * Page provider props
48
48
  */
49
49
  export type PageProviderProps<D extends IPageData> = IProviderProps<
50
- PageAction<D>
50
+ PageAction<D>
51
51
  >;
52
52
 
53
53
  /**
54
54
  * Page calls with the state
55
55
  */
56
56
  export interface PageCalls<D extends IPageData>
57
- extends IUpdate<D, PageAction<D>> {}
57
+ extends IUpdate<D, PageAction<D>> {}
58
58
 
59
59
  /**
60
60
  * User state
61
61
  */
62
62
  export class PageState<D extends IPageData> {
63
- /**
64
- * Context
65
- */
66
- readonly context;
63
+ /**
64
+ * Context
65
+ */
66
+ readonly context;
67
67
 
68
- /**
69
- * Provider
70
- */
71
- readonly provider;
68
+ /**
69
+ * Provider
70
+ */
71
+ readonly provider;
72
72
 
73
- /**
74
- * Constructor
75
- */
76
- constructor() {
77
- // Act
78
- const { context, provider } = State.create(
79
- (state: D, { type, data }: PageAction<D>) => {
80
- switch (type) {
81
- case PageActionType.Data:
82
- // Set page data
83
- return { ...state, ...data };
84
- case PageActionType.Title:
85
- // Same title
86
- if (
87
- state.title === data.title &&
88
- state.subtitle === data.subtitle
89
- )
90
- return state;
73
+ /**
74
+ * Constructor
75
+ */
76
+ constructor() {
77
+ // Act
78
+ const { context, provider } = State.create(
79
+ (state: D, { type, data }: PageAction<D>) => {
80
+ switch (type) {
81
+ case PageActionType.Data:
82
+ // Set page data
83
+ return { ...state, ...data };
84
+ case PageActionType.Title:
85
+ // Same title
86
+ if (state.title === data.title && state.subtitle === data.subtitle)
87
+ return state;
91
88
 
92
- // Set page title
93
- return {
94
- ...state,
95
- ...data
96
- };
97
- default:
98
- return state;
99
- }
100
- },
101
- {} as D,
102
- {} as PageCalls<D>
103
- );
89
+ // Set page title
90
+ return {
91
+ ...state,
92
+ ...data
93
+ };
94
+ default:
95
+ return state;
96
+ }
97
+ },
98
+ {} as D,
99
+ {} as PageCalls<D>
100
+ );
104
101
 
105
- this.context = context;
106
- this.provider = provider;
107
- }
102
+ this.context = context;
103
+ this.provider = provider;
104
+ }
108
105
  }
@@ -1,63 +1,59 @@
1
- import { IAction, IState } from '@etsoo/appscript';
2
- import React from 'react';
3
- import { IProviderProps, IUICreator, IUpdate } from './IState';
1
+ import { IAction, IState } from "@etsoo/appscript";
2
+ import React from "react";
3
+ import { IProviderProps, IUICreator, IUpdate } from "./IState";
4
4
 
5
5
  /**
6
6
  * State
7
7
  */
8
8
  export class State {
9
- /**
10
- * Generic to create state context and provider
11
- * @param reducer Reduce function
12
- * @param initState Init state
13
- * @param uiCreator Additional UI creator
14
- */
15
- public static create<
16
- S extends IState,
17
- A extends IAction,
18
- U extends IUpdate<S, A>,
19
- P extends IProviderProps<A>
20
- >(
21
- reducer: React.Reducer<S, A>,
22
- initState: S,
23
- calls: U,
24
- uiCreator?: IUICreator<S, A, P>
25
- ) {
26
- // State context
27
- const context = React.createContext(calls);
9
+ /**
10
+ * Generic to create state context and provider
11
+ * @param reducer Reduce function
12
+ * @param initState Init state
13
+ * @param uiCreator Additional UI creator
14
+ */
15
+ public static create<
16
+ S extends IState,
17
+ A extends IAction,
18
+ U extends IUpdate<S, A>,
19
+ P extends IProviderProps<A>
20
+ >(
21
+ reducer: React.Reducer<S, A>,
22
+ initState: S,
23
+ calls: U,
24
+ uiCreator?: IUICreator<S, A, P>
25
+ ) {
26
+ // State context
27
+ const context = React.createContext(calls);
28
28
 
29
- // State context provider
30
- const provider: React.FunctionComponent<React.PropsWithChildren<P>> = (
31
- props
32
- ) => {
33
- // Destruct
34
- const { children, update } = props;
29
+ // State context provider
30
+ const provider: React.FunctionComponent<React.PropsWithChildren<P>> = (
31
+ props
32
+ ) => {
33
+ // Destruct
34
+ const { children, update } = props;
35
35
 
36
- // Update reducer
37
- const [state, dispatch] = React.useReducer(reducer, initState);
36
+ // Update reducer
37
+ const [state, dispatch] = React.useReducer(reducer, initState);
38
38
 
39
- // Callback
40
- if (update != null) update(dispatch);
39
+ // Callback
40
+ if (update != null) update(dispatch);
41
41
 
42
- if (uiCreator) {
43
- // Custom renderer
44
- return uiCreator(state, dispatch, props);
45
- } else {
46
- // Context new value
47
- const value = { ...calls, state, dispatch };
42
+ if (uiCreator) {
43
+ // Custom renderer
44
+ return uiCreator(state, dispatch, props);
45
+ } else {
46
+ // Context new value
47
+ const value = { ...calls, state, dispatch };
48
48
 
49
- return (
50
- <context.Provider value={value}>
51
- {children}
52
- </context.Provider>
53
- );
54
- }
55
- };
49
+ return <context.Provider value={value}>{children}</context.Provider>;
50
+ }
51
+ };
56
52
 
57
- // Return
58
- return {
59
- context,
60
- provider
61
- };
62
- }
53
+ // Return
54
+ return {
55
+ context,
56
+ provider
57
+ };
58
+ }
63
59
  }