@aws-amplify/ui-react-core 3.4.1 → 3.4.3
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 +39 -0
- package/dist/esm/Authenticator/hooks/useAuthenticator/useAuthenticator.mjs +1 -1
- package/dist/esm/Authenticator/hooks/useAuthenticator/utils.mjs +1 -1
- package/dist/esm/hooks/useAsyncReducer.mjs +78 -0
- package/dist/esm/index.mjs +1 -1
- package/dist/index.js +75 -45
- package/dist/types/Authenticator/context/AuthenticatorContext.d.ts +1 -1
- package/dist/types/Authenticator/context/AuthenticatorProvider.d.ts +2 -1
- package/dist/types/Authenticator/hooks/constants.d.ts +1 -1
- package/dist/types/Authenticator/hooks/types.d.ts +3 -3
- package/dist/types/Authenticator/hooks/useAuthenticator/__mock__/useAuthenticator.d.ts +2 -2
- package/dist/types/Authenticator/hooks/useAuthenticator/index.d.ts +1 -1
- package/dist/types/Authenticator/hooks/useAuthenticator/types.d.ts +1 -1
- package/dist/types/Authenticator/hooks/useAuthenticator/useAuthenticator.d.ts +1 -1
- package/dist/types/Authenticator/hooks/useAuthenticator/utils.d.ts +3 -3
- package/dist/types/Authenticator/hooks/useAuthenticatorInitMachine/useAuthenticatorInitMachine.d.ts +2 -2
- package/dist/types/Authenticator/hooks/useAuthenticatorRoute/constants.d.ts +2 -2
- package/dist/types/Authenticator/hooks/useAuthenticatorRoute/types.d.ts +1 -1
- package/dist/types/Authenticator/hooks/useAuthenticatorRoute/useAuthenticatorRoute.d.ts +1 -1
- package/dist/types/Authenticator/hooks/useAuthenticatorRoute/utils.d.ts +4 -4
- package/dist/types/Authenticator/hooks/utils.d.ts +2 -2
- package/dist/types/Authenticator/index.d.ts +4 -2
- package/dist/types/components/FormCore/FormProvider.d.ts +1 -1
- package/dist/types/components/FormCore/index.d.ts +1 -1
- package/dist/types/components/FormCore/types.d.ts +2 -2
- package/dist/types/components/FormCore/useControlledField.d.ts +1 -1
- package/dist/types/components/FormCore/useField.d.ts +1 -1
- package/dist/types/components/FormCore/useForm.d.ts +1 -1
- package/dist/types/components/FormCore/withFormProvider.d.ts +2 -2
- package/dist/types/components/index.d.ts +2 -1
- package/dist/types/elements/ElementsContext.d.ts +1 -1
- package/dist/types/elements/defineBaseElement.d.ts +1 -1
- package/dist/types/elements/types.d.ts +1 -1
- package/dist/types/elements/utils.d.ts +1 -1
- package/dist/types/elements/withBaseElementProps.d.ts +1 -1
- package/dist/types/hooks/index.d.ts +6 -3
- package/dist/types/hooks/useAsyncReducer.d.ts +55 -0
- package/dist/types/hooks/useGetUrl.d.ts +1 -1
- package/dist/types/hooks/useSetUserAgent.d.ts +1 -1
- package/dist/types/index.d.ts +7 -4
- package/dist/types/types/index.d.ts +1 -1
- package/package.json +3 -3
- package/src/Authenticator/context/AuthenticatorContext.tsx +1 -1
- package/src/Authenticator/context/AuthenticatorProvider.tsx +3 -3
- package/src/Authenticator/hooks/constants.ts +1 -1
- package/src/Authenticator/hooks/types.ts +3 -3
- package/src/Authenticator/hooks/useAuthenticator/__mock__/useAuthenticator.ts +2 -2
- package/src/Authenticator/hooks/useAuthenticator/index.ts +1 -1
- package/src/Authenticator/hooks/useAuthenticator/types.ts +1 -1
- package/src/Authenticator/hooks/useAuthenticator/useAuthenticator.ts +3 -2
- package/src/Authenticator/hooks/useAuthenticator/utils.ts +12 -7
- package/src/Authenticator/hooks/useAuthenticatorInitMachine/useAuthenticatorInitMachine.tsx +3 -5
- package/src/Authenticator/hooks/useAuthenticatorRoute/constants.ts +2 -2
- package/src/Authenticator/hooks/useAuthenticatorRoute/types.ts +1 -1
- package/src/Authenticator/hooks/useAuthenticatorRoute/useAuthenticatorRoute.ts +1 -1
- package/src/Authenticator/hooks/useAuthenticatorRoute/utils.ts +4 -4
- package/src/Authenticator/hooks/utils.ts +6 -2
- package/src/Authenticator/index.ts +3 -4
- package/src/components/FormCore/FormProvider.tsx +1 -1
- package/src/components/FormCore/index.ts +1 -1
- package/src/components/FormCore/types.ts +5 -5
- package/src/components/FormCore/useControlledField.ts +1 -1
- package/src/components/FormCore/useField.ts +7 -2
- package/src/components/FormCore/useForm.ts +2 -2
- package/src/components/FormCore/withFormProvider.tsx +2 -2
- package/src/components/index.ts +2 -5
- package/src/elements/ElementsContext.tsx +1 -1
- package/src/elements/defineBaseElement.tsx +1 -1
- package/src/elements/types.ts +1 -1
- package/src/elements/utils.ts +1 -1
- package/src/elements/withBaseElementProps.tsx +1 -1
- package/src/hooks/index.ts +6 -12
- package/src/hooks/useAsyncReducer.ts +111 -0
- package/src/hooks/useGetUrl.ts +2 -2
- package/src/hooks/useSetUserAgent.ts +2 -1
- package/src/index.ts +22 -17
- package/src/types/index.ts +1 -1
- package/dist/esm/hooks/useDataState/useDataState.mjs +0 -48
- package/dist/types/hooks/useDataState/index.d.ts +0 -2
- package/dist/types/hooks/useDataState/types.d.ts +0 -8
- package/dist/types/hooks/useDataState/useDataState.d.ts +0 -8
- package/src/hooks/useDataState/index.ts +0 -2
- package/src/hooks/useDataState/types.ts +0 -13
- package/src/hooks/useDataState/useDataState.ts +0 -70
package/src/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// features
|
|
2
|
-
export {
|
|
2
|
+
export type {
|
|
3
3
|
AuthenticatorComponentDefaults,
|
|
4
4
|
AuthenticatorComponentDefaultProps,
|
|
5
5
|
AuthenticatorComponentOverrides,
|
|
@@ -8,49 +8,54 @@ export {
|
|
|
8
8
|
AuthenticatorHeaderComponent,
|
|
9
9
|
AuthenticatorLegacyField,
|
|
10
10
|
AuthenticatorMachineContext,
|
|
11
|
-
AuthenticatorProvider,
|
|
12
11
|
AuthenticatorRouteComponentKey,
|
|
13
12
|
AuthenticatorRouteComponentName,
|
|
13
|
+
UseAuthenticator,
|
|
14
|
+
UseAuthenticatorRoute,
|
|
15
|
+
} from './Authenticator';
|
|
16
|
+
export {
|
|
17
|
+
AuthenticatorProvider,
|
|
14
18
|
isAuthenticatorComponentRouteKey,
|
|
15
19
|
resolveAuthenticatorComponents,
|
|
16
20
|
useAuthenticator,
|
|
17
21
|
useAuthenticatorRoute,
|
|
18
|
-
UseAuthenticator,
|
|
19
22
|
useAuthenticatorInitMachine,
|
|
20
|
-
UseAuthenticatorRoute,
|
|
21
23
|
} from './Authenticator';
|
|
22
24
|
|
|
23
|
-
export {
|
|
24
|
-
FormProvider,
|
|
25
|
+
export type {
|
|
25
26
|
FormProviderProps,
|
|
26
|
-
RenderNothing,
|
|
27
27
|
FormValues,
|
|
28
28
|
FormHandle,
|
|
29
|
-
useField,
|
|
30
|
-
useForm,
|
|
31
29
|
UseForm,
|
|
32
30
|
Validate,
|
|
33
31
|
Validator,
|
|
32
|
+
} from './components';
|
|
33
|
+
export {
|
|
34
|
+
FormProvider,
|
|
35
|
+
RenderNothing,
|
|
36
|
+
useField,
|
|
37
|
+
useForm,
|
|
34
38
|
withFormProvider,
|
|
35
39
|
} from './components';
|
|
36
40
|
|
|
41
|
+
export type {
|
|
42
|
+
AsyncReducer,
|
|
43
|
+
AsyncReducerState,
|
|
44
|
+
UseDeprecationWarning,
|
|
45
|
+
UseDropZoneParams,
|
|
46
|
+
} from './hooks';
|
|
37
47
|
export {
|
|
38
|
-
|
|
39
|
-
DataAction,
|
|
48
|
+
useAsyncReducer,
|
|
40
49
|
useControlledReducer,
|
|
41
50
|
useDeprecationWarning,
|
|
42
|
-
|
|
51
|
+
useDropZone,
|
|
43
52
|
useGetUrl,
|
|
44
53
|
useHasValueUpdated,
|
|
45
54
|
usePreviousValue,
|
|
46
55
|
useSetUserAgent,
|
|
47
56
|
useTimeout,
|
|
48
|
-
useDataState,
|
|
49
|
-
DataState,
|
|
50
|
-
useDropZone,
|
|
51
|
-
UseDropZoneParams,
|
|
52
57
|
} from './hooks';
|
|
53
58
|
|
|
54
|
-
export { MergeProps } from './types';
|
|
59
|
+
export type { MergeProps } from './types';
|
|
55
60
|
|
|
56
61
|
export { createContextUtilities } from './utils';
|
package/src/types/index.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { AnyComponent, MergeProps } from './types';
|
|
1
|
+
export type { AnyComponent, MergeProps } from './types';
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import React__default from 'react';
|
|
2
|
-
import { isFunction } from '@aws-amplify/ui';
|
|
3
|
-
|
|
4
|
-
// default state
|
|
5
|
-
const INITIAL_STATE = { hasError: false, isLoading: false, message: undefined };
|
|
6
|
-
const LOADING_STATE = { hasError: false, isLoading: true, message: undefined };
|
|
7
|
-
const ERROR_STATE = { hasError: true, isLoading: false };
|
|
8
|
-
const resolveMaybeAsync = async (value) => {
|
|
9
|
-
const awaited = await value;
|
|
10
|
-
return awaited;
|
|
11
|
-
};
|
|
12
|
-
/**
|
|
13
|
-
* @internal may be updated in future versions
|
|
14
|
-
*/
|
|
15
|
-
function useDataState(action, initialData, options) {
|
|
16
|
-
const [dataState, setDataState] = React__default.useState(() => ({
|
|
17
|
-
...INITIAL_STATE,
|
|
18
|
-
data: initialData,
|
|
19
|
-
}));
|
|
20
|
-
const prevData = React__default.useRef(initialData);
|
|
21
|
-
const pendingId = React__default.useRef();
|
|
22
|
-
const { onSuccess, onError } = options ?? {};
|
|
23
|
-
const handleAction = React__default.useCallback((input) => {
|
|
24
|
-
const id = Symbol();
|
|
25
|
-
pendingId.current = id;
|
|
26
|
-
setDataState(({ data }) => ({ ...LOADING_STATE, data }));
|
|
27
|
-
resolveMaybeAsync(action(prevData.current, input))
|
|
28
|
-
.then((data) => {
|
|
29
|
-
if (pendingId.current !== id)
|
|
30
|
-
return;
|
|
31
|
-
prevData.current = data;
|
|
32
|
-
if (isFunction(onSuccess))
|
|
33
|
-
onSuccess(data);
|
|
34
|
-
setDataState({ ...INITIAL_STATE, data });
|
|
35
|
-
})
|
|
36
|
-
.catch((error) => {
|
|
37
|
-
if (pendingId.current !== id)
|
|
38
|
-
return;
|
|
39
|
-
if (isFunction(onError))
|
|
40
|
-
onError(error);
|
|
41
|
-
const { message } = error;
|
|
42
|
-
setDataState(({ data }) => ({ ...ERROR_STATE, data, message }));
|
|
43
|
-
});
|
|
44
|
-
}, [action, onError, onSuccess]);
|
|
45
|
-
return [dataState, handleAction];
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export { useDataState as default };
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export interface DataState<T> {
|
|
2
|
-
data: T;
|
|
3
|
-
hasError: boolean;
|
|
4
|
-
isLoading: boolean;
|
|
5
|
-
message: string | undefined;
|
|
6
|
-
}
|
|
7
|
-
export type DataAction<T = any, K = any> = (prevData: T, input: K) => T;
|
|
8
|
-
export type AsyncDataAction<T = any, K = any> = (prevData: T, input: K) => Promise<T>;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { AsyncDataAction, DataAction, DataState } from './types';
|
|
2
|
-
/**
|
|
3
|
-
* @internal may be updated in future versions
|
|
4
|
-
*/
|
|
5
|
-
export default function useDataState<T, K>(action: DataAction<T, K> | AsyncDataAction<T, K>, initialData: T, options?: {
|
|
6
|
-
onSuccess?: (data: T) => void;
|
|
7
|
-
onError?: (error: Error) => void;
|
|
8
|
-
}): [state: DataState<T>, handleAction: (input: K) => void];
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export interface DataState<T> {
|
|
2
|
-
data: T;
|
|
3
|
-
hasError: boolean;
|
|
4
|
-
isLoading: boolean;
|
|
5
|
-
message: string | undefined;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export type DataAction<T = any, K = any> = (prevData: T, input: K) => T;
|
|
9
|
-
|
|
10
|
-
export type AsyncDataAction<T = any, K = any> = (
|
|
11
|
-
prevData: T,
|
|
12
|
-
input: K
|
|
13
|
-
) => Promise<T>;
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { isFunction } from '@aws-amplify/ui';
|
|
3
|
-
|
|
4
|
-
import { AsyncDataAction, DataAction, DataState } from './types';
|
|
5
|
-
|
|
6
|
-
// default state
|
|
7
|
-
const INITIAL_STATE = { hasError: false, isLoading: false, message: undefined };
|
|
8
|
-
const LOADING_STATE = { hasError: false, isLoading: true, message: undefined };
|
|
9
|
-
const ERROR_STATE = { hasError: true, isLoading: false };
|
|
10
|
-
|
|
11
|
-
const resolveMaybeAsync = async <T>(
|
|
12
|
-
value: T | Promise<T>
|
|
13
|
-
): Promise<Awaited<T>> => {
|
|
14
|
-
const awaited = await value;
|
|
15
|
-
return awaited;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* @internal may be updated in future versions
|
|
20
|
-
*/
|
|
21
|
-
export default function useDataState<T, K>(
|
|
22
|
-
action: DataAction<T, K> | AsyncDataAction<T, K>,
|
|
23
|
-
initialData: T,
|
|
24
|
-
options?: {
|
|
25
|
-
onSuccess?: (data: T) => void;
|
|
26
|
-
onError?: (error: Error) => void;
|
|
27
|
-
}
|
|
28
|
-
): [state: DataState<T>, handleAction: (input: K) => void] {
|
|
29
|
-
const [dataState, setDataState] = React.useState<DataState<T>>(() => ({
|
|
30
|
-
...INITIAL_STATE,
|
|
31
|
-
data: initialData,
|
|
32
|
-
}));
|
|
33
|
-
|
|
34
|
-
const prevData = React.useRef(initialData);
|
|
35
|
-
const pendingId = React.useRef<Symbol | undefined>();
|
|
36
|
-
|
|
37
|
-
const { onSuccess, onError } = options ?? {};
|
|
38
|
-
|
|
39
|
-
const handleAction: (input: K) => void = React.useCallback(
|
|
40
|
-
(input) => {
|
|
41
|
-
const id = Symbol();
|
|
42
|
-
pendingId.current = id;
|
|
43
|
-
|
|
44
|
-
setDataState(({ data }) => ({ ...LOADING_STATE, data }));
|
|
45
|
-
|
|
46
|
-
resolveMaybeAsync(action(prevData.current, input))
|
|
47
|
-
.then((data: T) => {
|
|
48
|
-
if (pendingId.current !== id) return;
|
|
49
|
-
|
|
50
|
-
prevData.current = data;
|
|
51
|
-
|
|
52
|
-
if (isFunction(onSuccess)) onSuccess(data);
|
|
53
|
-
|
|
54
|
-
setDataState({ ...INITIAL_STATE, data });
|
|
55
|
-
})
|
|
56
|
-
.catch((error: Error) => {
|
|
57
|
-
if (pendingId.current !== id) return;
|
|
58
|
-
|
|
59
|
-
if (isFunction(onError)) onError(error);
|
|
60
|
-
|
|
61
|
-
const { message } = error;
|
|
62
|
-
|
|
63
|
-
setDataState(({ data }) => ({ ...ERROR_STATE, data, message }));
|
|
64
|
-
});
|
|
65
|
-
},
|
|
66
|
-
[action, onError, onSuccess]
|
|
67
|
-
);
|
|
68
|
-
|
|
69
|
-
return [dataState, handleAction];
|
|
70
|
-
}
|