@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.
- package/README.md +2 -1
- package/__tests__/EventWatcher.tsx +21 -21
- package/__tests__/ReactUtils.ts +4 -4
- package/__tests__/tsconfig.json +17 -17
- package/babel.config.json +8 -8
- package/lib/app/CoreConstants.js +2 -2
- package/lib/app/EventWatcher.d.ts +1 -1
- package/lib/app/EventWatcher.js +3 -5
- package/lib/app/InputDialogProps.d.ts +2 -2
- package/lib/app/ReactUtils.d.ts +2 -2
- package/lib/app/ReactUtils.js +20 -19
- package/lib/components/DnDList.d.ts +3 -3
- package/lib/components/DnDList.js +4 -4
- package/lib/components/DynamicRouter.d.ts +2 -2
- package/lib/components/DynamicRouter.js +2 -2
- package/lib/components/GridColumn.d.ts +6 -6
- package/lib/components/GridColumn.js +7 -7
- package/lib/components/GridLoader.d.ts +4 -4
- package/lib/components/GridLoader.js +2 -2
- package/lib/components/GridMethodRef.d.ts +2 -2
- package/lib/components/ListItemReact.d.ts +2 -2
- package/lib/components/ScrollRestoration.js +3 -3
- package/lib/components/ScrollerGrid.d.ts +7 -12
- package/lib/components/ScrollerGrid.js +13 -17
- package/lib/components/ScrollerList.d.ts +6 -10
- package/lib/components/ScrollerList.js +15 -14
- package/lib/custom/CustomFieldReact.d.ts +1 -1
- package/lib/index.d.ts +32 -32
- package/lib/index.js +31 -31
- package/lib/notifier/Notifier.d.ts +5 -5
- package/lib/notifier/Notifier.js +7 -7
- package/lib/states/CultureState.d.ts +3 -3
- package/lib/states/CultureState.js +3 -3
- package/lib/states/IState.d.ts +2 -2
- package/lib/states/PageState.d.ts +2 -2
- package/lib/states/PageState.js +2 -3
- package/lib/states/State.d.ts +3 -3
- package/lib/states/State.js +2 -2
- package/lib/states/UserState.d.ts +2 -2
- package/lib/states/UserState.js +5 -5
- package/lib/uses/useAsyncState.d.ts +1 -1
- package/lib/uses/useAsyncState.js +1 -1
- package/lib/uses/useCombinedRefs.js +2 -2
- package/lib/uses/useDelayedExecutor.d.ts +1 -1
- package/lib/uses/useDelayedExecutor.js +2 -2
- package/lib/uses/useDimensions.d.ts +1 -1
- package/lib/uses/useDimensions.js +3 -3
- package/lib/uses/useParamsEx.d.ts +1 -1
- package/lib/uses/useParamsEx.js +2 -2
- package/lib/uses/useRefs.d.ts +2 -2
- package/lib/uses/useRefs.js +1 -1
- package/lib/uses/useSearchParamsEx.d.ts +1 -1
- package/lib/uses/useSearchParamsEx.js +3 -3
- package/lib/uses/useTimeout.js +2 -2
- package/lib/uses/useWindowScroll.js +3 -3
- package/lib/uses/useWindowSize.js +4 -5
- package/package.json +72 -74
- package/src/app/CoreConstants.ts +8 -8
- package/src/app/EventWatcher.ts +50 -52
- package/src/app/InputDialogProps.ts +16 -16
- package/src/app/ReactUtils.ts +206 -208
- package/src/components/DnDList.tsx +268 -283
- package/src/components/DynamicRouter.tsx +35 -35
- package/src/components/GridColumn.ts +201 -201
- package/src/components/GridLoader.ts +121 -121
- package/src/components/GridMethodRef.ts +26 -26
- package/src/components/ListItemReact.ts +2 -2
- package/src/components/ScrollRestoration.tsx +24 -24
- package/src/components/ScrollerGrid.tsx +428 -448
- package/src/components/ScrollerList.tsx +320 -332
- package/src/custom/CustomFieldReact.ts +12 -12
- package/src/index.ts +35 -35
- package/src/notifier/Notifier.ts +229 -240
- package/src/states/CultureState.ts +51 -52
- package/src/states/IState.ts +19 -19
- package/src/states/PageState.ts +63 -66
- package/src/states/State.tsx +47 -51
- package/src/states/UserState.ts +98 -98
- package/src/uses/useAsyncState.ts +37 -39
- package/src/uses/useCombinedRefs.ts +16 -16
- package/src/uses/useDelayedExecutor.ts +8 -8
- package/src/uses/useDimensions.ts +102 -103
- package/src/uses/useParamsEx.ts +6 -6
- package/src/uses/useRefs.ts +6 -6
- package/src/uses/useSearchParamsEx.ts +13 -13
- package/src/uses/useTimeout.ts +17 -17
- package/src/uses/useWindowScroll.ts +43 -43
- package/src/uses/useWindowSize.ts +46 -49
- package/tsconfig.json +17 -17
- package/.eslintignore +0 -3
- package/.eslintrc.json +0 -38
- package/.prettierignore +0 -5
- package/.prettierrc +0 -6
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { IAction, ICulture } from
|
|
2
|
-
import { DataTypes } from
|
|
3
|
-
import { IProviderProps, IUpdate } from
|
|
4
|
-
import { State } from
|
|
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
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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
|
-
|
|
50
|
-
|
|
51
|
-
|
|
47
|
+
/**
|
|
48
|
+
* Context
|
|
49
|
+
*/
|
|
50
|
+
readonly context;
|
|
52
51
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
52
|
+
/**
|
|
53
|
+
* Provider
|
|
54
|
+
*/
|
|
55
|
+
readonly provider;
|
|
57
56
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
57
|
+
/**
|
|
58
|
+
* Constructor
|
|
59
|
+
*/
|
|
60
|
+
constructor(item?: DataTypes.CultureDefinition) {
|
|
61
|
+
// Default
|
|
62
|
+
const defaultItem = item ?? ({} as ICulture);
|
|
64
63
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
64
|
+
// Load resources
|
|
65
|
+
if (item != null && typeof item.resources !== "object")
|
|
66
|
+
item.resources().then((result) => (item.resources = result));
|
|
68
67
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
76
|
+
return state;
|
|
77
|
+
},
|
|
78
|
+
defaultItem,
|
|
79
|
+
calls
|
|
80
|
+
);
|
|
82
81
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
82
|
+
this.context = context;
|
|
83
|
+
this.provider = provider;
|
|
84
|
+
}
|
|
86
85
|
}
|
package/src/states/IState.ts
CHANGED
|
@@ -1,56 +1,56 @@
|
|
|
1
|
-
import { IAction, IState, UserKey } from
|
|
2
|
-
import React, { ReactNode } from
|
|
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
|
-
|
|
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
|
-
|
|
16
|
-
|
|
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
|
-
|
|
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
|
-
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
/**
|
|
31
|
+
* State last changed fields
|
|
32
|
+
*/
|
|
33
|
+
targetFields?: UserKey[];
|
|
34
34
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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
|
-
|
|
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
|
-
|
|
54
|
-
|
|
55
|
-
|
|
52
|
+
/**
|
|
53
|
+
* Update callback
|
|
54
|
+
*/
|
|
55
|
+
update?: IProviderUpdate<A>;
|
|
56
56
|
}
|
package/src/states/PageState.ts
CHANGED
|
@@ -1,108 +1,105 @@
|
|
|
1
|
-
import { IAction, IState } from
|
|
2
|
-
import { IProviderProps, IUpdate } from
|
|
3
|
-
import { State } from
|
|
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
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
/**
|
|
10
|
+
* Page title
|
|
11
|
+
*/
|
|
12
|
+
title?: string;
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
-
|
|
25
|
-
|
|
24
|
+
// Update data
|
|
25
|
+
Data = "DATA",
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
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
|
-
|
|
37
|
-
|
|
38
|
-
|
|
35
|
+
/**
|
|
36
|
+
* Action type
|
|
37
|
+
*/
|
|
38
|
+
type: PageActionType;
|
|
39
39
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
65
|
-
|
|
66
|
-
|
|
63
|
+
/**
|
|
64
|
+
* Context
|
|
65
|
+
*/
|
|
66
|
+
readonly context;
|
|
67
67
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
68
|
+
/**
|
|
69
|
+
* Provider
|
|
70
|
+
*/
|
|
71
|
+
readonly provider;
|
|
72
72
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
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
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
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
|
-
|
|
106
|
-
|
|
107
|
-
|
|
102
|
+
this.context = context;
|
|
103
|
+
this.provider = provider;
|
|
104
|
+
}
|
|
108
105
|
}
|
package/src/states/State.tsx
CHANGED
|
@@ -1,63 +1,59 @@
|
|
|
1
|
-
import { IAction, IState } from
|
|
2
|
-
import React from
|
|
3
|
-
import { IProviderProps, IUICreator, IUpdate } from
|
|
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
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
|
-
|
|
37
|
-
|
|
36
|
+
// Update reducer
|
|
37
|
+
const [state, dispatch] = React.useReducer(reducer, initState);
|
|
38
38
|
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
// Callback
|
|
40
|
+
if (update != null) update(dispatch);
|
|
41
41
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
</context.Provider>
|
|
53
|
-
);
|
|
54
|
-
}
|
|
55
|
-
};
|
|
49
|
+
return <context.Provider value={value}>{children}</context.Provider>;
|
|
50
|
+
}
|
|
51
|
+
};
|
|
56
52
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
53
|
+
// Return
|
|
54
|
+
return {
|
|
55
|
+
context,
|
|
56
|
+
provider
|
|
57
|
+
};
|
|
58
|
+
}
|
|
63
59
|
}
|