@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.
Files changed (84) hide show
  1. package/README.md +39 -0
  2. package/dist/esm/Authenticator/hooks/useAuthenticator/useAuthenticator.mjs +1 -1
  3. package/dist/esm/Authenticator/hooks/useAuthenticator/utils.mjs +1 -1
  4. package/dist/esm/hooks/useAsyncReducer.mjs +78 -0
  5. package/dist/esm/index.mjs +1 -1
  6. package/dist/index.js +75 -45
  7. package/dist/types/Authenticator/context/AuthenticatorContext.d.ts +1 -1
  8. package/dist/types/Authenticator/context/AuthenticatorProvider.d.ts +2 -1
  9. package/dist/types/Authenticator/hooks/constants.d.ts +1 -1
  10. package/dist/types/Authenticator/hooks/types.d.ts +3 -3
  11. package/dist/types/Authenticator/hooks/useAuthenticator/__mock__/useAuthenticator.d.ts +2 -2
  12. package/dist/types/Authenticator/hooks/useAuthenticator/index.d.ts +1 -1
  13. package/dist/types/Authenticator/hooks/useAuthenticator/types.d.ts +1 -1
  14. package/dist/types/Authenticator/hooks/useAuthenticator/useAuthenticator.d.ts +1 -1
  15. package/dist/types/Authenticator/hooks/useAuthenticator/utils.d.ts +3 -3
  16. package/dist/types/Authenticator/hooks/useAuthenticatorInitMachine/useAuthenticatorInitMachine.d.ts +2 -2
  17. package/dist/types/Authenticator/hooks/useAuthenticatorRoute/constants.d.ts +2 -2
  18. package/dist/types/Authenticator/hooks/useAuthenticatorRoute/types.d.ts +1 -1
  19. package/dist/types/Authenticator/hooks/useAuthenticatorRoute/useAuthenticatorRoute.d.ts +1 -1
  20. package/dist/types/Authenticator/hooks/useAuthenticatorRoute/utils.d.ts +4 -4
  21. package/dist/types/Authenticator/hooks/utils.d.ts +2 -2
  22. package/dist/types/Authenticator/index.d.ts +4 -2
  23. package/dist/types/components/FormCore/FormProvider.d.ts +1 -1
  24. package/dist/types/components/FormCore/index.d.ts +1 -1
  25. package/dist/types/components/FormCore/types.d.ts +2 -2
  26. package/dist/types/components/FormCore/useControlledField.d.ts +1 -1
  27. package/dist/types/components/FormCore/useField.d.ts +1 -1
  28. package/dist/types/components/FormCore/useForm.d.ts +1 -1
  29. package/dist/types/components/FormCore/withFormProvider.d.ts +2 -2
  30. package/dist/types/components/index.d.ts +2 -1
  31. package/dist/types/elements/ElementsContext.d.ts +1 -1
  32. package/dist/types/elements/defineBaseElement.d.ts +1 -1
  33. package/dist/types/elements/types.d.ts +1 -1
  34. package/dist/types/elements/utils.d.ts +1 -1
  35. package/dist/types/elements/withBaseElementProps.d.ts +1 -1
  36. package/dist/types/hooks/index.d.ts +6 -3
  37. package/dist/types/hooks/useAsyncReducer.d.ts +55 -0
  38. package/dist/types/hooks/useGetUrl.d.ts +1 -1
  39. package/dist/types/hooks/useSetUserAgent.d.ts +1 -1
  40. package/dist/types/index.d.ts +7 -4
  41. package/dist/types/types/index.d.ts +1 -1
  42. package/package.json +3 -3
  43. package/src/Authenticator/context/AuthenticatorContext.tsx +1 -1
  44. package/src/Authenticator/context/AuthenticatorProvider.tsx +3 -3
  45. package/src/Authenticator/hooks/constants.ts +1 -1
  46. package/src/Authenticator/hooks/types.ts +3 -3
  47. package/src/Authenticator/hooks/useAuthenticator/__mock__/useAuthenticator.ts +2 -2
  48. package/src/Authenticator/hooks/useAuthenticator/index.ts +1 -1
  49. package/src/Authenticator/hooks/useAuthenticator/types.ts +1 -1
  50. package/src/Authenticator/hooks/useAuthenticator/useAuthenticator.ts +3 -2
  51. package/src/Authenticator/hooks/useAuthenticator/utils.ts +12 -7
  52. package/src/Authenticator/hooks/useAuthenticatorInitMachine/useAuthenticatorInitMachine.tsx +3 -5
  53. package/src/Authenticator/hooks/useAuthenticatorRoute/constants.ts +2 -2
  54. package/src/Authenticator/hooks/useAuthenticatorRoute/types.ts +1 -1
  55. package/src/Authenticator/hooks/useAuthenticatorRoute/useAuthenticatorRoute.ts +1 -1
  56. package/src/Authenticator/hooks/useAuthenticatorRoute/utils.ts +4 -4
  57. package/src/Authenticator/hooks/utils.ts +6 -2
  58. package/src/Authenticator/index.ts +3 -4
  59. package/src/components/FormCore/FormProvider.tsx +1 -1
  60. package/src/components/FormCore/index.ts +1 -1
  61. package/src/components/FormCore/types.ts +5 -5
  62. package/src/components/FormCore/useControlledField.ts +1 -1
  63. package/src/components/FormCore/useField.ts +7 -2
  64. package/src/components/FormCore/useForm.ts +2 -2
  65. package/src/components/FormCore/withFormProvider.tsx +2 -2
  66. package/src/components/index.ts +2 -5
  67. package/src/elements/ElementsContext.tsx +1 -1
  68. package/src/elements/defineBaseElement.tsx +1 -1
  69. package/src/elements/types.ts +1 -1
  70. package/src/elements/utils.ts +1 -1
  71. package/src/elements/withBaseElementProps.tsx +1 -1
  72. package/src/hooks/index.ts +6 -12
  73. package/src/hooks/useAsyncReducer.ts +111 -0
  74. package/src/hooks/useGetUrl.ts +2 -2
  75. package/src/hooks/useSetUserAgent.ts +2 -1
  76. package/src/index.ts +22 -17
  77. package/src/types/index.ts +1 -1
  78. package/dist/esm/hooks/useDataState/useDataState.mjs +0 -48
  79. package/dist/types/hooks/useDataState/index.d.ts +0 -2
  80. package/dist/types/hooks/useDataState/types.d.ts +0 -8
  81. package/dist/types/hooks/useDataState/useDataState.d.ts +0 -8
  82. package/src/hooks/useDataState/index.ts +0 -2
  83. package/src/hooks/useDataState/types.ts +0 -13
  84. package/src/hooks/useDataState/useDataState.ts +0 -70
package/README.md CHANGED
@@ -1,3 +1,42 @@
1
1
  # Amplify UI React Core
2
2
 
3
3
  `@aws-amplify/ui-react-core` is a React platform agnostic utility library for Amplify UI internal usage in `@aws-amplify/ui-react*` and `@aws-amplify/ui-react-native*` namespaced packages.
4
+
5
+ ## Contents
6
+
7
+ ### Authenticator
8
+
9
+ - `AuthenticatorProvider` - Provider component for Authenticator context
10
+ - `useAuthenticator` - Hook for accessing Authenticator functionality
11
+ - `useAuthenticatorRoute` - Hook for accessing Authenticator route information
12
+ - `useAuthenticatorInitMachine` - Hook for initializing Authenticator state machine
13
+ - `isAuthenticatorComponentRouteKey` - Utility function for checking route keys
14
+ - `resolveAuthenticatorComponents` - Utility function for resolving Authenticator components
15
+
16
+ ### Form Components and Hooks
17
+
18
+ - `FormProvider` - Provider component for form context
19
+ - `useField` - Hook for accessing form field functionality
20
+ - `useForm` - Hook for accessing form functionality
21
+ - `withFormProvider` - Higher-order component for adding form provider capabilities
22
+ - `RenderNothing` - Utility component for rendering nothing
23
+
24
+ ### Utility Hooks
25
+
26
+ - `useAsyncReducer` - Hook for async state management
27
+ - `useControlledReducer` - Hook for controlled state management
28
+ - `useDeprecationWarning` - Hook for displaying deprecation warnings
29
+ - `useDropZone` - Hook for drag and drop functionality
30
+ - `useGetUrl` - Hook for getting URLs
31
+ - `useHasValueUpdated` - Hook for checking if a value has updated
32
+ - `usePreviousValue` - Hook for accessing previous value
33
+ - `useSetUserAgent` - Hook for setting user agent
34
+ - `useTimeout` - Hook for timeout functionality
35
+
36
+ ### Utility Functions
37
+
38
+ - `createContextUtilities` - Utility function for creating context utilities
39
+
40
+ ### Type Definitions
41
+
42
+ - Various type definitions for Authenticator, Form, and utility components
@@ -4,7 +4,7 @@ import { getServiceFacade } from '@aws-amplify/ui';
4
4
  import 'aws-amplify/auth';
5
5
  import { AuthenticatorContext } from '../../context/AuthenticatorContext.mjs';
6
6
  import { USE_AUTHENTICATOR_ERROR } from './constants.mjs';
7
- import { getQRFields, getMachineFields, getComparator, defaultComparator } from './utils.mjs';
7
+ import { getComparator, defaultComparator, getQRFields, getMachineFields } from './utils.mjs';
8
8
 
9
9
  /**
10
10
  * [📖 Docs](https://ui.docs.amplify.aws/react/connected-components/authenticator/headless#useauthenticator-hook)
@@ -1,4 +1,4 @@
1
- import { getActorContext, getSortedFormFields, isString, authenticatorTextUtil, areEmptyArrays, areEmptyObjects } from '@aws-amplify/ui';
1
+ import { getActorContext, getSortedFormFields, areEmptyArrays, areEmptyObjects, isString, authenticatorTextUtil } from '@aws-amplify/ui';
2
2
  import { isComponentRouteKey } from '../utils.mjs';
3
3
 
4
4
  const defaultComparator = () => false;
@@ -0,0 +1,78 @@
1
+ import React__default from 'react';
2
+ import { isFunction } from '@aws-amplify/ui';
3
+
4
+ // async state constants
5
+ const INITIAL = { hasError: false, isLoading: false, message: undefined };
6
+ const LOADING = { hasError: false, isLoading: true, message: undefined };
7
+ const ERROR = { hasError: true, isLoading: false };
8
+ /**
9
+ * @internal may be updated in future versions
10
+ *
11
+ * @description like `useReducer` but make it async
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * import fetchData from './fetchData';
16
+ *
17
+ * type MyState = { data: string[] | undefined }
18
+ * const initialState: MyState = { data: undefined }
19
+ *
20
+ * type MyAction = { type: 'fetch' | 'clear' }
21
+ *
22
+ * const asyncReducer = async (state: MyState, action: MyAction): Promise<MyState> => {
23
+ * switch(action.type) {
24
+ * case 'fetch':
25
+ * const data = await fetchData();
26
+ * return { data: state.data ? state.data.concat(data) : data }
27
+ * case 'clear':
28
+ * return { data: undefined }
29
+ * }
30
+ * }
31
+ *
32
+ * const FetchDataButton = () => {
33
+ * const [state, dispatch] = useAsyncReducer(asyncReducer, initialState);
34
+ *
35
+ * const { value: { data }, isLoading } = state;
36
+ *
37
+ * return (
38
+ * <button onClick={() => isLoading ? null : dispatch({ type: 'fetch'})}>
39
+ * Fetch Data
40
+ * </button>
41
+ * )
42
+ * }
43
+ * ```
44
+ */
45
+ function useAsyncReducer(reducer, initialValue, options) {
46
+ const [state, setAsyncState] = React__default.useState(() => ({
47
+ ...INITIAL,
48
+ value: initialValue,
49
+ }));
50
+ const prevValue = React__default.useRef(initialValue);
51
+ const pendingId = React__default.useRef();
52
+ const { onSuccess, onError } = options ?? {};
53
+ const dispatch = React__default.useCallback((input) => {
54
+ const id = Symbol();
55
+ pendingId.current = id;
56
+ setAsyncState(({ value }) => ({ ...LOADING, value }));
57
+ reducer(prevValue.current, input)
58
+ .then((value) => {
59
+ if (pendingId.current !== id)
60
+ return;
61
+ prevValue.current = value;
62
+ if (isFunction(onSuccess))
63
+ onSuccess(value);
64
+ setAsyncState({ ...INITIAL, value });
65
+ })
66
+ .catch((error) => {
67
+ if (pendingId.current !== id)
68
+ return;
69
+ if (isFunction(onError))
70
+ onError(error);
71
+ const { message } = error;
72
+ setAsyncState(({ value }) => ({ ...ERROR, value, message }));
73
+ });
74
+ }, [onError, onSuccess, reducer]);
75
+ return [state, dispatch];
76
+ }
77
+
78
+ export { useAsyncReducer as default };
@@ -9,9 +9,9 @@ export { default as useForm } from './components/FormCore/useForm.mjs';
9
9
  export { default as FormProvider } from './components/FormCore/FormProvider.mjs';
10
10
  export { default as withFormProvider } from './components/FormCore/withFormProvider.mjs';
11
11
  export { default as RenderNothing } from './components/RenderNothing/RenderNothing.mjs';
12
- export { default as useDataState } from './hooks/useDataState/useDataState.mjs';
13
12
  export { default as useControlledReducer } from './hooks/useControlledReducer.mjs';
14
13
  export { default as useDropZone } from './hooks/useDropZone.mjs';
14
+ export { default as useAsyncReducer } from './hooks/useAsyncReducer.mjs';
15
15
  export { default as useDeprecationWarning } from './hooks/useDeprecationWarning.mjs';
16
16
  export { default as useGetUrl } from './hooks/useGetUrl.mjs';
17
17
  export { default as useHasValueUpdated } from './hooks/useHasValueUpdated.mjs';
package/dist/index.js CHANGED
@@ -605,50 +605,6 @@ function useAuthenticatorInitMachine(data) {
605
605
  }, [initializeMachine, route, data]);
606
606
  }
607
607
 
608
- // default state
609
- const INITIAL_STATE = { hasError: false, isLoading: false, message: undefined };
610
- const LOADING_STATE = { hasError: false, isLoading: true, message: undefined };
611
- const ERROR_STATE = { hasError: true, isLoading: false };
612
- const resolveMaybeAsync = async (value) => {
613
- const awaited = await value;
614
- return awaited;
615
- };
616
- /**
617
- * @internal may be updated in future versions
618
- */
619
- function useDataState(action, initialData, options) {
620
- const [dataState, setDataState] = React__namespace["default"].useState(() => ({
621
- ...INITIAL_STATE,
622
- data: initialData,
623
- }));
624
- const prevData = React__namespace["default"].useRef(initialData);
625
- const pendingId = React__namespace["default"].useRef();
626
- const { onSuccess, onError } = options ?? {};
627
- const handleAction = React__namespace["default"].useCallback((input) => {
628
- const id = Symbol();
629
- pendingId.current = id;
630
- setDataState(({ data }) => ({ ...LOADING_STATE, data }));
631
- resolveMaybeAsync(action(prevData.current, input))
632
- .then((data) => {
633
- if (pendingId.current !== id)
634
- return;
635
- prevData.current = data;
636
- if (ui.isFunction(onSuccess))
637
- onSuccess(data);
638
- setDataState({ ...INITIAL_STATE, data });
639
- })
640
- .catch((error) => {
641
- if (pendingId.current !== id)
642
- return;
643
- if (ui.isFunction(onError))
644
- onError(error);
645
- const { message } = error;
646
- setDataState(({ data }) => ({ ...ERROR_STATE, data, message }));
647
- });
648
- }, [action, onError, onSuccess]);
649
- return [dataState, handleAction];
650
- }
651
-
652
608
  function usePreviousValue(value) {
653
609
  const previous = React.useRef(undefined);
654
610
  // update ref post render
@@ -868,6 +824,80 @@ function useDropZone({ onDropComplete, onDragEnter: _onDragEnter, onDragLeave: _
868
824
  };
869
825
  }
870
826
 
827
+ // async state constants
828
+ const INITIAL = { hasError: false, isLoading: false, message: undefined };
829
+ const LOADING = { hasError: false, isLoading: true, message: undefined };
830
+ const ERROR = { hasError: true, isLoading: false };
831
+ /**
832
+ * @internal may be updated in future versions
833
+ *
834
+ * @description like `useReducer` but make it async
835
+ *
836
+ * @example
837
+ * ```ts
838
+ * import fetchData from './fetchData';
839
+ *
840
+ * type MyState = { data: string[] | undefined }
841
+ * const initialState: MyState = { data: undefined }
842
+ *
843
+ * type MyAction = { type: 'fetch' | 'clear' }
844
+ *
845
+ * const asyncReducer = async (state: MyState, action: MyAction): Promise<MyState> => {
846
+ * switch(action.type) {
847
+ * case 'fetch':
848
+ * const data = await fetchData();
849
+ * return { data: state.data ? state.data.concat(data) : data }
850
+ * case 'clear':
851
+ * return { data: undefined }
852
+ * }
853
+ * }
854
+ *
855
+ * const FetchDataButton = () => {
856
+ * const [state, dispatch] = useAsyncReducer(asyncReducer, initialState);
857
+ *
858
+ * const { value: { data }, isLoading } = state;
859
+ *
860
+ * return (
861
+ * <button onClick={() => isLoading ? null : dispatch({ type: 'fetch'})}>
862
+ * Fetch Data
863
+ * </button>
864
+ * )
865
+ * }
866
+ * ```
867
+ */
868
+ function useAsyncReducer(reducer, initialValue, options) {
869
+ const [state, setAsyncState] = React__namespace["default"].useState(() => ({
870
+ ...INITIAL,
871
+ value: initialValue,
872
+ }));
873
+ const prevValue = React__namespace["default"].useRef(initialValue);
874
+ const pendingId = React__namespace["default"].useRef();
875
+ const { onSuccess, onError } = options ?? {};
876
+ const dispatch = React__namespace["default"].useCallback((input) => {
877
+ const id = Symbol();
878
+ pendingId.current = id;
879
+ setAsyncState(({ value }) => ({ ...LOADING, value }));
880
+ reducer(prevValue.current, input)
881
+ .then((value) => {
882
+ if (pendingId.current !== id)
883
+ return;
884
+ prevValue.current = value;
885
+ if (ui.isFunction(onSuccess))
886
+ onSuccess(value);
887
+ setAsyncState({ ...INITIAL, value });
888
+ })
889
+ .catch((error) => {
890
+ if (pendingId.current !== id)
891
+ return;
892
+ if (ui.isFunction(onError))
893
+ onError(error);
894
+ const { message } = error;
895
+ setAsyncState(({ value }) => ({ ...ERROR, value, message }));
896
+ });
897
+ }, [onError, onSuccess, reducer]);
898
+ return [state, dispatch];
899
+ }
900
+
871
901
  /**
872
902
  * Logs a deprecation warning message.
873
903
  *
@@ -1031,11 +1061,11 @@ exports.RenderNothing = RenderNothing;
1031
1061
  exports.createContextUtilities = createContextUtilities;
1032
1062
  exports.isAuthenticatorComponentRouteKey = isComponentRouteKey;
1033
1063
  exports.resolveAuthenticatorComponents = resolveAuthenticatorComponents;
1064
+ exports.useAsyncReducer = useAsyncReducer;
1034
1065
  exports.useAuthenticator = useAuthenticator;
1035
1066
  exports.useAuthenticatorInitMachine = useAuthenticatorInitMachine;
1036
1067
  exports.useAuthenticatorRoute = useAuthenticatorRoute;
1037
1068
  exports.useControlledReducer = useControlledReducer;
1038
- exports.useDataState = useDataState;
1039
1069
  exports.useDeprecationWarning = useDeprecationWarning;
1040
1070
  exports.useDropZone = useDropZone;
1041
1071
  exports.useField = useField;
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { AuthInterpreter, AuthStatus } from '@aws-amplify/ui';
2
+ import type { AuthInterpreter, AuthStatus } from '@aws-amplify/ui';
3
3
  /**
4
4
  * Authenticator React.Context type
5
5
  */
@@ -1,4 +1,5 @@
1
- import React, { ReactNode } from 'react';
1
+ import type { ReactNode } from 'react';
2
+ import React from 'react';
2
3
  export default function AuthenticatorProvider({ children, }: {
3
4
  children: ReactNode;
4
5
  }): React.JSX.Element;
@@ -1,3 +1,3 @@
1
- import { AuthenticatorRouteComponentKey, AuthenticatorRouteComponentName } from './types';
1
+ import type { AuthenticatorRouteComponentKey, AuthenticatorRouteComponentName } from './types';
2
2
  export declare const COMPONENT_ROUTE_KEYS: AuthenticatorRouteComponentKey[];
3
3
  export declare const COMPONENT_ROUTE_NAMES: AuthenticatorRouteComponentName[];
@@ -1,6 +1,6 @@
1
- import React from 'react';
2
- import { ChallengeName, AuthenticatorServiceFacade, LegacyFormFieldOptions } from '@aws-amplify/ui';
3
- import { UseAuthenticator } from './useAuthenticator';
1
+ import type React from 'react';
2
+ import type { ChallengeName, AuthenticatorServiceFacade, LegacyFormFieldOptions } from '@aws-amplify/ui';
3
+ import type { UseAuthenticator } from './useAuthenticator';
4
4
  export type AuthenticatorRouteComponentKey = 'confirmResetPassword' | 'confirmSignIn' | 'confirmSignUp' | 'confirmVerifyUser' | 'forceNewPassword' | 'forgotPassword' | 'selectMfaType' | 'setupEmail' | 'setupTotp' | 'signIn' | 'signUp' | 'verifyUser';
5
5
  export type AuthenticatorLegacyField = LegacyFormFieldOptions;
6
6
  export type AuthenticatorLegacyFields = AuthenticatorLegacyField[];
@@ -1,4 +1,4 @@
1
- import { AuthenticatorMachineContext } from '../../types';
2
- import { UseAuthenticator } from '../types';
1
+ import type { AuthenticatorMachineContext } from '../../types';
2
+ import type { UseAuthenticator } from '../types';
3
3
  export declare const mockMachineContext: AuthenticatorMachineContext;
4
4
  export declare const mockUseAuthenticatorOutput: UseAuthenticator;
@@ -1,2 +1,2 @@
1
1
  export { default as useAuthenticator } from './useAuthenticator';
2
- export { UseAuthenticator, UseAuthenticatorSelector } from './types';
2
+ export type { UseAuthenticator, UseAuthenticatorSelector } from './types';
@@ -1,4 +1,4 @@
1
- import { AuthenticatorServiceFacade, LegacyFormFieldOptions } from '@aws-amplify/ui';
1
+ import type { AuthenticatorServiceFacade, LegacyFormFieldOptions } from '@aws-amplify/ui';
2
2
  /**
3
3
  * These are the "facades" that we provide, which contains contexts respective
4
4
  * to current authenticator state.
@@ -1,4 +1,4 @@
1
- import { UseAuthenticatorSelector, UseAuthenticator } from './types';
1
+ import type { UseAuthenticatorSelector, UseAuthenticator } from './types';
2
2
  /**
3
3
  * [📖 Docs](https://ui.docs.amplify.aws/react/connected-components/authenticator/headless#useauthenticator-hook)
4
4
  */
@@ -1,6 +1,6 @@
1
- import { AuthenticatorRoute, AuthMachineState } from '@aws-amplify/ui';
2
- import { AuthenticatorLegacyFields } from '../types';
3
- import { Comparator, UseAuthenticatorSelector } from './types';
1
+ import type { AuthenticatorRoute, AuthMachineState } from '@aws-amplify/ui';
2
+ import type { AuthenticatorLegacyFields } from '../types';
3
+ import type { Comparator, UseAuthenticatorSelector } from './types';
4
4
  export declare const defaultComparator: () => false;
5
5
  /**
6
6
  * Does an ordering and shallow comparison of each array value,
@@ -1,4 +1,4 @@
1
- import { AuthenticatorMachineOptions } from '@aws-amplify/ui';
2
- import { UseAuthenticatorSelector } from '../useAuthenticator';
1
+ import type { AuthenticatorMachineOptions } from '@aws-amplify/ui';
2
+ import type { UseAuthenticatorSelector } from '../useAuthenticator';
3
3
  export declare const routeSelector: UseAuthenticatorSelector;
4
4
  export default function useAuthenticatorInitMachine(data: AuthenticatorMachineOptions): void;
@@ -1,4 +1,4 @@
1
- import { AuthenticatorMachineContextKey, AuthenticatorRouteComponentKey } from '../types';
2
- import { FormEventHandlerMachineKey, FormEventHandlerPropKey } from './types';
1
+ import type { AuthenticatorMachineContextKey, AuthenticatorRouteComponentKey } from '../types';
2
+ import type { FormEventHandlerMachineKey, FormEventHandlerPropKey } from './types';
3
3
  export declare const EVENT_HANDLER_KEY_MAP: Record<FormEventHandlerMachineKey, FormEventHandlerPropKey>;
4
4
  export declare const MACHINE_PROP_KEYS: Record<AuthenticatorRouteComponentKey, AuthenticatorMachineContextKey[]>;
@@ -1,4 +1,4 @@
1
- import { AuthenticatorMachineContext, AuthenticatorMachineContextKey, AuthenticatorRouteComponentName, CommonRouteProps, ConfirmResetPasswordBaseProps, ConfirmSignInBaseProps, ConfirmSignUpBaseProps, Defaults, DefaultProps, ForceResetPasswordBaseProps, ResetPasswordBaseProps, SelectMfaTypeBaseProps, SetupEmailBaseProps, SetupTotpBaseProps, SignInBaseProps, SignUpBaseProps, VerifyUserProps, ConfirmVerifyUserProps } from '../types';
1
+ import type { AuthenticatorMachineContext, AuthenticatorMachineContextKey, AuthenticatorRouteComponentName, CommonRouteProps, ConfirmResetPasswordBaseProps, ConfirmSignInBaseProps, ConfirmSignUpBaseProps, Defaults, DefaultProps, ForceResetPasswordBaseProps, ResetPasswordBaseProps, SelectMfaTypeBaseProps, SetupEmailBaseProps, SetupTotpBaseProps, SignInBaseProps, SignUpBaseProps, VerifyUserProps, ConfirmVerifyUserProps } from '../types';
2
2
  export type UseAuthenticatorRouteParams<FieldType> = {
3
3
  components: Defaults<FieldType>;
4
4
  };
@@ -1,4 +1,4 @@
1
- import { UseAuthenticatorRoute, UseAuthenticatorRouteParams } from './types';
1
+ import type { UseAuthenticatorRoute, UseAuthenticatorRouteParams } from './types';
2
2
  export default function useAuthenticatorRoute<FieldType>(params: UseAuthenticatorRouteParams<FieldType>): UseAuthenticatorRoute<'ConfirmResetPassword'>;
3
3
  export default function useAuthenticatorRoute<FieldType>(params: UseAuthenticatorRouteParams<FieldType>): UseAuthenticatorRoute<'ConfirmSignIn'>;
4
4
  export default function useAuthenticatorRoute<FieldType>(params: UseAuthenticatorRouteParams<FieldType>): UseAuthenticatorRoute<'ConfirmSignUp'>;
@@ -1,7 +1,7 @@
1
- import { AuthenticatorRoute } from '@aws-amplify/ui';
2
- import { Defaults } from '../types';
3
- import { UseAuthenticator, UseAuthenticatorSelector } from '../useAuthenticator';
4
- import { UseAuthenticatorRoute, UseAuthenticatorRouteDefault } from './types';
1
+ import type { AuthenticatorRoute } from '@aws-amplify/ui';
2
+ import type { Defaults } from '../types';
3
+ import type { UseAuthenticator, UseAuthenticatorSelector } from '../useAuthenticator';
4
+ import type { UseAuthenticatorRoute, UseAuthenticatorRouteDefault } from './types';
5
5
  export declare const routeSelector: UseAuthenticatorSelector;
6
6
  export declare const getRouteMachineSelector: (route: AuthenticatorRoute) => UseAuthenticatorSelector;
7
7
  export declare function resolveConfirmResetPasswordRoute<FieldType = {}>(Component: Defaults<FieldType>['ConfirmResetPassword'], props: UseAuthenticator): UseAuthenticatorRoute<'ConfirmResetPassword', FieldType>;
@@ -1,4 +1,4 @@
1
- import { AuthenticatorRoute } from '@aws-amplify/ui';
2
- import { AuthenticatorRouteComponentKey, Defaults, Overrides } from './types';
1
+ import type { AuthenticatorRoute } from '@aws-amplify/ui';
2
+ import type { AuthenticatorRouteComponentKey, Defaults, Overrides } from './types';
3
3
  export declare const isComponentRouteKey: (route: AuthenticatorRoute) => route is AuthenticatorRouteComponentKey;
4
4
  export declare function resolveAuthenticatorComponents<FieldType>(defaults: Defaults<FieldType>, overrides?: Overrides<FieldType>): Defaults<FieldType>;
@@ -1,3 +1,5 @@
1
1
  export { AuthenticatorProvider, AuthenticatorContext } from './context';
2
- export { resolveAuthenticatorComponents, useAuthenticator, useAuthenticatorRoute, UseAuthenticator, useAuthenticatorInitMachine, UseAuthenticatorRoute, } from './hooks';
3
- export { Overrides as AuthenticatorComponentOverrides, Defaults as AuthenticatorComponentDefaults, DefaultProps as AuthenticatorComponentDefaultProps, FooterComponent as AuthenticatorFooterComponent, FormFieldsComponent as AuthenticatorFormFieldsComponent, HeaderComponent as AuthenticatorHeaderComponent, isComponentRouteKey as isAuthenticatorComponentRouteKey, AuthenticatorRouteComponentKey, AuthenticatorRouteComponentName, AuthenticatorLegacyField, AuthenticatorMachineContext, FormFieldsComponent, } from './hooks';
2
+ export type { UseAuthenticator, UseAuthenticatorRoute } from './hooks';
3
+ export { resolveAuthenticatorComponents, useAuthenticator, useAuthenticatorRoute, useAuthenticatorInitMachine, } from './hooks';
4
+ export type { Overrides as AuthenticatorComponentOverrides, Defaults as AuthenticatorComponentDefaults, DefaultProps as AuthenticatorComponentDefaultProps, FooterComponent as AuthenticatorFooterComponent, FormFieldsComponent as AuthenticatorFormFieldsComponent, HeaderComponent as AuthenticatorHeaderComponent, AuthenticatorRouteComponentKey, AuthenticatorRouteComponentName, AuthenticatorLegacyField, AuthenticatorMachineContext, FormFieldsComponent, } from './hooks';
5
+ export { isComponentRouteKey as isAuthenticatorComponentRouteKey } from './hooks';
@@ -1,4 +1,4 @@
1
1
  import React from 'react';
2
- import { FormValues, FormHandle, FormProviderProps } from './types';
2
+ import type { FormValues, FormHandle, FormProviderProps } from './types';
3
3
  declare const FormProvider: React.ForwardRefExoticComponent<FormProviderProps<FormValues> & React.RefAttributes<FormHandle>>;
4
4
  export default FormProvider;
@@ -1,4 +1,4 @@
1
- export { FormProviderProps, FormValues, FormHandle, SubmitHandler, UseForm, Validate, Validator, } from './types';
1
+ export type { FormProviderProps, FormValues, FormHandle, SubmitHandler, UseForm, Validate, Validator, } from './types';
2
2
  export { default as useField } from './useField';
3
3
  export { default as useForm } from './useForm';
4
4
  export { default as FormProvider } from './FormProvider';
@@ -1,5 +1,5 @@
1
- import React from 'react';
2
- import { DefaultValues } from 'react-hook-form';
1
+ import type React from 'react';
2
+ import type { DefaultValues } from 'react-hook-form';
3
3
  export interface FormValues {
4
4
  [k: string]: string;
5
5
  }
@@ -1,4 +1,4 @@
1
- import { FocusHandler, UseControlledField, UseControlledFieldParams } from './types';
1
+ import type { FocusHandler, UseControlledField, UseControlledFieldParams } from './types';
2
2
  export declare const DEFAULT_ERROR_MESSAGE = "`useControlledField` must be used within a `FormProvider`";
3
3
  /**
4
4
  * `Field` integration hook for usage with React Native `Field` components
@@ -1,4 +1,4 @@
1
- import { ChangeHandler, FocusHandler, UseField, UseFieldParams } from './types';
1
+ import type { ChangeHandler, FocusHandler, UseField, UseFieldParams } from './types';
2
2
  export declare const DEFAULT_ERROR_MESSAGE = "`useField` must be used within a `FormProvider`";
3
3
  /**
4
4
  * `Field` integration hook for usage with React `Field` components.
@@ -1,4 +1,4 @@
1
- import { FormValues, SubmitHandler, UseForm, UseFormParams } from './types';
1
+ import type { FormValues, SubmitHandler, UseForm, UseFormParams } from './types';
2
2
  export declare const DEFAULT_ERROR_MESSAGE = "`useForm` must be called inside a `FormProvider`";
3
3
  /**
4
4
  * Utility hook corresponding to `FormProvider`, must be used within a `FormProvider`
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
- import { AnyComponent } from '../../types';
3
- import { FormHandle, FormProviderProps } from './types';
2
+ import type { AnyComponent } from '../../types';
3
+ import type { FormHandle, FormProviderProps } from './types';
4
4
  /**
5
5
  * @param Child `Form` base component wrapped inside `FormProvider`
6
6
  * @returns Composed `Form` component exposing `FormContext` values to descendents
@@ -1,2 +1,3 @@
1
- export { FormProvider, FormProviderProps, FormValues, FormHandle, SubmitHandler, useField, useForm, UseForm, Validate, Validator, withFormProvider, } from './FormCore';
1
+ export type { FormProviderProps, FormValues, FormHandle, SubmitHandler, UseForm, Validate, Validator, } from './FormCore';
2
+ export { FormProvider, useField, useForm, withFormProvider } from './FormCore';
2
3
  export { RenderNothing } from './RenderNothing';
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { ElementDisplayName } from './types';
2
+ import type { ElementDisplayName } from './types';
3
3
  /**
4
4
  * @internal @unstable
5
5
  */
@@ -1,4 +1,4 @@
1
- import { BaseElement, BaseElementProps, BaseElementWithRef, BaseElementWithRefProps, ElementDisplayName, ElementRefType, ReactElementProps, ReactElementType } from './types';
1
+ import type { BaseElement, BaseElementProps, BaseElementWithRef, BaseElementWithRefProps, ElementDisplayName, ElementRefType, ReactElementProps, ReactElementType } from './types';
2
2
  /**
3
3
  * @internal @unstable
4
4
  */
@@ -1,4 +1,4 @@
1
- import React from 'react';
1
+ import type React from 'react';
2
2
  /**
3
3
  * @internal @unstable
4
4
  *
@@ -1,3 +1,3 @@
1
- import React from 'react';
1
+ import type React from 'react';
2
2
  export declare function isComponent<T>(component?: React.ComponentType<T> | React.ForwardRefExoticComponent<T>): component is React.ComponentType<T>;
3
3
  export declare function isForwardRefExoticComponent<T>(component: React.ComponentType<T> | React.ForwardRefExoticComponent<T>): component is React.ForwardRefExoticComponent<T>;
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { BaseElementWithRef, ElementRefType } from './types';
2
+ import type { BaseElementWithRef, ElementRefType } from './types';
3
3
  /**
4
4
  * @internal @unstable
5
5
  *
@@ -1,7 +1,10 @@
1
- export { useDataState, AsyncDataAction, DataAction, DataState, } from './useDataState';
2
1
  export { default as useControlledReducer } from './useControlledReducer';
3
- export { default as useDropZone, UseDropZoneParams } from './useDropZone';
4
- export { default as useDeprecationWarning, UseDeprecationWarning, } from './useDeprecationWarning';
2
+ export type { UseDropZoneParams } from './useDropZone';
3
+ export { default as useDropZone } from './useDropZone';
4
+ export type { AsyncReducer, AsyncReducerState } from './useAsyncReducer';
5
+ export { default as useAsyncReducer } from './useAsyncReducer';
6
+ export type { UseDeprecationWarning } from './useDeprecationWarning';
7
+ export { default as useDeprecationWarning } from './useDeprecationWarning';
5
8
  export { default as useGetUrl } from './useGetUrl';
6
9
  export { default as useHasValueUpdated } from './useHasValueUpdated';
7
10
  export { default as usePreviousValue } from './usePreviousValue';
@@ -0,0 +1,55 @@
1
+ import React from 'react';
2
+ export interface AsyncReducerState<T> {
3
+ /**
4
+ * current value
5
+ */
6
+ value: T;
7
+ hasError: boolean;
8
+ isLoading: boolean;
9
+ /**
10
+ * error message, if any
11
+ */
12
+ message: string | undefined;
13
+ }
14
+ export type AsyncReducer<S, A> = (prevValue: S, action: A) => Promise<S>;
15
+ /**
16
+ * @internal may be updated in future versions
17
+ *
18
+ * @description like `useReducer` but make it async
19
+ *
20
+ * @example
21
+ * ```ts
22
+ * import fetchData from './fetchData';
23
+ *
24
+ * type MyState = { data: string[] | undefined }
25
+ * const initialState: MyState = { data: undefined }
26
+ *
27
+ * type MyAction = { type: 'fetch' | 'clear' }
28
+ *
29
+ * const asyncReducer = async (state: MyState, action: MyAction): Promise<MyState> => {
30
+ * switch(action.type) {
31
+ * case 'fetch':
32
+ * const data = await fetchData();
33
+ * return { data: state.data ? state.data.concat(data) : data }
34
+ * case 'clear':
35
+ * return { data: undefined }
36
+ * }
37
+ * }
38
+ *
39
+ * const FetchDataButton = () => {
40
+ * const [state, dispatch] = useAsyncReducer(asyncReducer, initialState);
41
+ *
42
+ * const { value: { data }, isLoading } = state;
43
+ *
44
+ * return (
45
+ * <button onClick={() => isLoading ? null : dispatch({ type: 'fetch'})}>
46
+ * Fetch Data
47
+ * </button>
48
+ * )
49
+ * }
50
+ * ```
51
+ */
52
+ export default function useAsyncReducer<T, K>(reducer: AsyncReducer<T, K>, initialValue: T, options?: {
53
+ onSuccess?: (data: T) => void;
54
+ onError?: (error: Error) => void;
55
+ }): [AsyncReducerState<T>, React.Dispatch<K>];
@@ -1,4 +1,4 @@
1
- import { GetUrlInput, GetUrlWithPathInput } from 'aws-amplify/storage';
1
+ import type { GetUrlInput, GetUrlWithPathInput } from 'aws-amplify/storage';
2
2
  export type UseGetUrlInput = (GetUrlInput | GetUrlWithPathInput) & {
3
3
  onError?: (error: Error) => void;
4
4
  };
@@ -1,2 +1,2 @@
1
- import { SetUserAgentOptions } from '@aws-amplify/ui';
1
+ import type { SetUserAgentOptions } from '@aws-amplify/ui';
2
2
  export default function useSetUserAgent({ componentName, packageName, version, }: SetUserAgentOptions): void;
@@ -1,5 +1,8 @@
1
- export { AuthenticatorComponentDefaults, AuthenticatorComponentDefaultProps, AuthenticatorComponentOverrides, AuthenticatorFooterComponent, AuthenticatorFormFieldsComponent, AuthenticatorHeaderComponent, AuthenticatorLegacyField, AuthenticatorMachineContext, AuthenticatorProvider, AuthenticatorRouteComponentKey, AuthenticatorRouteComponentName, isAuthenticatorComponentRouteKey, resolveAuthenticatorComponents, useAuthenticator, useAuthenticatorRoute, UseAuthenticator, useAuthenticatorInitMachine, UseAuthenticatorRoute, } from './Authenticator';
2
- export { FormProvider, FormProviderProps, RenderNothing, FormValues, FormHandle, useField, useForm, UseForm, Validate, Validator, withFormProvider, } from './components';
3
- export { AsyncDataAction, DataAction, useControlledReducer, useDeprecationWarning, UseDeprecationWarning, useGetUrl, useHasValueUpdated, usePreviousValue, useSetUserAgent, useTimeout, useDataState, DataState, useDropZone, UseDropZoneParams, } from './hooks';
4
- export { MergeProps } from './types';
1
+ export type { AuthenticatorComponentDefaults, AuthenticatorComponentDefaultProps, AuthenticatorComponentOverrides, AuthenticatorFooterComponent, AuthenticatorFormFieldsComponent, AuthenticatorHeaderComponent, AuthenticatorLegacyField, AuthenticatorMachineContext, AuthenticatorRouteComponentKey, AuthenticatorRouteComponentName, UseAuthenticator, UseAuthenticatorRoute, } from './Authenticator';
2
+ export { AuthenticatorProvider, isAuthenticatorComponentRouteKey, resolveAuthenticatorComponents, useAuthenticator, useAuthenticatorRoute, useAuthenticatorInitMachine, } from './Authenticator';
3
+ export type { FormProviderProps, FormValues, FormHandle, UseForm, Validate, Validator, } from './components';
4
+ export { FormProvider, RenderNothing, useField, useForm, withFormProvider, } from './components';
5
+ export type { AsyncReducer, AsyncReducerState, UseDeprecationWarning, UseDropZoneParams, } from './hooks';
6
+ export { useAsyncReducer, useControlledReducer, useDeprecationWarning, useDropZone, useGetUrl, useHasValueUpdated, usePreviousValue, useSetUserAgent, useTimeout, } from './hooks';
7
+ export type { MergeProps } from './types';
5
8
  export { createContextUtilities } from './utils';