@aws-amplify/ui-react-core 3.0.12 → 3.0.14

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.
@@ -0,0 +1,38 @@
1
+ import * as React from 'react';
2
+ import { getUrl } from 'aws-amplify/storage';
3
+ import { isFunction } from '@aws-amplify/ui';
4
+
5
+ const INIT_STATE = {
6
+ url: undefined,
7
+ expiresAt: undefined,
8
+ isLoading: true,
9
+ };
10
+ function useGetUrl(input) {
11
+ const [result, setResult] = React.useState(() => INIT_STATE);
12
+ React.useEffect(() => {
13
+ const { onError, ...getUrlInput } = input;
14
+ let ignore = false;
15
+ getUrl(getUrlInput)
16
+ .then((response) => {
17
+ if (ignore) {
18
+ return;
19
+ }
20
+ setResult({ ...response, isLoading: false });
21
+ })
22
+ .catch((error) => {
23
+ if (ignore) {
24
+ return;
25
+ }
26
+ if (isFunction(onError)) {
27
+ onError(error);
28
+ }
29
+ setResult({ ...INIT_STATE, isLoading: false });
30
+ });
31
+ return () => {
32
+ ignore = true;
33
+ };
34
+ }, [input]);
35
+ return result;
36
+ }
37
+
38
+ export { useGetUrl as default };
@@ -10,6 +10,7 @@ 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
12
  export { default as useDeprecationWarning } from './hooks/useDeprecationWarning.mjs';
13
+ export { default as useGetUrl } from './hooks/useGetUrl.mjs';
13
14
  export { default as useHasValueUpdated } from './hooks/useHasValueUpdated.mjs';
14
15
  export { default as usePreviousValue } from './hooks/usePreviousValue.mjs';
15
16
  export { default as useSetUserAgent } from './hooks/useSetUserAgent.mjs';
package/dist/index.js CHANGED
@@ -7,6 +7,7 @@ var react = require('@xstate/react');
7
7
  var auth = require('aws-amplify/auth');
8
8
  var ui = require('@aws-amplify/ui');
9
9
  var reactHookForm = require('react-hook-form');
10
+ var storage = require('aws-amplify/storage');
10
11
 
11
12
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
12
13
 
@@ -573,6 +574,39 @@ const useDeprecationWarning = ({ shouldWarn, message, }) => {
573
574
  }, [shouldWarn, message]);
574
575
  };
575
576
 
577
+ const INIT_STATE = {
578
+ url: undefined,
579
+ expiresAt: undefined,
580
+ isLoading: true,
581
+ };
582
+ function useGetUrl(input) {
583
+ const [result, setResult] = React__namespace.useState(() => INIT_STATE);
584
+ React__namespace.useEffect(() => {
585
+ const { onError, ...getUrlInput } = input;
586
+ let ignore = false;
587
+ storage.getUrl(getUrlInput)
588
+ .then((response) => {
589
+ if (ignore) {
590
+ return;
591
+ }
592
+ setResult({ ...response, isLoading: false });
593
+ })
594
+ .catch((error) => {
595
+ if (ignore) {
596
+ return;
597
+ }
598
+ if (ui.isFunction(onError)) {
599
+ onError(error);
600
+ }
601
+ setResult({ ...INIT_STATE, isLoading: false });
602
+ });
603
+ return () => {
604
+ ignore = true;
605
+ };
606
+ }, [input]);
607
+ return result;
608
+ }
609
+
576
610
  function usePreviousValue(value) {
577
611
  const previous = React.useRef();
578
612
  // update ref post render
@@ -722,6 +756,7 @@ exports.useAuthenticatorRoute = useAuthenticatorRoute;
722
756
  exports.useDeprecationWarning = useDeprecationWarning;
723
757
  exports.useField = useField;
724
758
  exports.useForm = useForm;
759
+ exports.useGetUrl = useGetUrl;
725
760
  exports.useHasValueUpdated = useHasValueUpdated;
726
761
  exports.usePreviousValue = usePreviousValue;
727
762
  exports.useSetUserAgent = useSetUserAgent;
@@ -1,4 +1,5 @@
1
1
  export { default as useDeprecationWarning, UseDeprecationWarning, } from './useDeprecationWarning';
2
+ export { default as useGetUrl } from './useGetUrl';
2
3
  export { default as useHasValueUpdated } from './useHasValueUpdated';
3
4
  export { default as usePreviousValue } from './usePreviousValue';
4
5
  export { default as useSetUserAgent } from './useSetUserAgent';
@@ -0,0 +1,11 @@
1
+ import { GetUrlInput, GetUrlWithPathInput } from 'aws-amplify/storage';
2
+ export type UseGetUrlInput = (GetUrlInput | GetUrlWithPathInput) & {
3
+ onError?: (error: Error) => void;
4
+ };
5
+ interface UseGetUrlOutput {
6
+ isLoading: boolean;
7
+ url: URL | undefined;
8
+ expiresAt: Date | undefined;
9
+ }
10
+ export default function useGetUrl(input: UseGetUrlInput): UseGetUrlOutput;
11
+ export {};
@@ -1,5 +1,5 @@
1
1
  export { AuthenticatorComponentDefaults, AuthenticatorComponentDefaultProps, AuthenticatorComponentOverrides, AuthenticatorFooterComponent, AuthenticatorFormFieldsComponent, AuthenticatorHeaderComponent, AuthenticatorLegacyField, AuthenticatorMachineContext, AuthenticatorProvider, AuthenticatorRouteComponentKey, AuthenticatorRouteComponentName, isAuthenticatorComponentRouteKey, resolveAuthenticatorComponents, useAuthenticator, useAuthenticatorRoute, UseAuthenticator, useAuthenticatorInitMachine, UseAuthenticatorRoute, } from './Authenticator';
2
2
  export { FormProvider, FormProviderProps, RenderNothing, FormValues, FormHandle, useField, useForm, UseForm, Validate, Validator, withFormProvider, } from './components';
3
- export { useDeprecationWarning, UseDeprecationWarning, useHasValueUpdated, usePreviousValue, useSetUserAgent, useTimeout, } from './hooks';
3
+ export { useDeprecationWarning, UseDeprecationWarning, useGetUrl, useHasValueUpdated, usePreviousValue, useSetUserAgent, useTimeout, } from './hooks';
4
4
  export { MergeProps } from './types';
5
5
  export { createContextUtilities } from './utils';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aws-amplify/ui-react-core",
3
- "version": "3.0.12",
3
+ "version": "3.0.14",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/esm/index.mjs",
6
6
  "react-native": "src/index.ts",
@@ -33,14 +33,14 @@
33
33
  "typecheck": "tsc --noEmit"
34
34
  },
35
35
  "dependencies": {
36
- "@aws-amplify/ui": "6.0.12",
36
+ "@aws-amplify/ui": "6.0.14",
37
37
  "@xstate/react": "^3.2.2",
38
38
  "lodash": "4.17.21",
39
39
  "react-hook-form": "^7.43.5",
40
40
  "xstate": "^4.33.6"
41
41
  },
42
42
  "peerDependencies": {
43
- "aws-amplify": "^6.0.2",
43
+ "aws-amplify": "^6.2.0",
44
44
  "react": "^16.14.0 || ^17.0 || ^18.0"
45
45
  },
46
46
  "sideEffects": false
@@ -2,6 +2,7 @@ export {
2
2
  default as useDeprecationWarning,
3
3
  UseDeprecationWarning,
4
4
  } from './useDeprecationWarning';
5
+ export { default as useGetUrl } from './useGetUrl';
5
6
  export { default as useHasValueUpdated } from './useHasValueUpdated';
6
7
  export { default as usePreviousValue } from './usePreviousValue';
7
8
  export { default as useSetUserAgent } from './useSetUserAgent';
@@ -0,0 +1,63 @@
1
+ import * as React from 'react';
2
+
3
+ import {
4
+ getUrl,
5
+ GetUrlInput,
6
+ GetUrlOutput,
7
+ GetUrlWithPathInput,
8
+ } from 'aws-amplify/storage';
9
+
10
+ import { isFunction } from '@aws-amplify/ui';
11
+
12
+ export type UseGetUrlInput = (GetUrlInput | GetUrlWithPathInput) & {
13
+ onError?: (error: Error) => void;
14
+ };
15
+ interface UseGetUrlOutput {
16
+ isLoading: boolean;
17
+ url: URL | undefined;
18
+ expiresAt: Date | undefined;
19
+ }
20
+
21
+ const INIT_STATE: UseGetUrlOutput = {
22
+ url: undefined,
23
+ expiresAt: undefined,
24
+ isLoading: true,
25
+ };
26
+
27
+ type GetUrl = (
28
+ input: GetUrlInput | GetUrlWithPathInput
29
+ ) => Promise<GetUrlOutput>;
30
+
31
+ export default function useGetUrl(input: UseGetUrlInput): UseGetUrlOutput {
32
+ const [result, setResult] = React.useState(() => INIT_STATE);
33
+ React.useEffect(() => {
34
+ const { onError, ...getUrlInput } = input;
35
+ let ignore = false;
36
+
37
+ (getUrl as GetUrl)(getUrlInput)
38
+ .then((response) => {
39
+ if (ignore) {
40
+ return;
41
+ }
42
+
43
+ setResult({ ...response, isLoading: false });
44
+ })
45
+ .catch((error: Error) => {
46
+ if (ignore) {
47
+ return;
48
+ }
49
+
50
+ if (isFunction(onError)) {
51
+ onError(error);
52
+ }
53
+
54
+ setResult({ ...INIT_STATE, isLoading: false });
55
+ });
56
+
57
+ return () => {
58
+ ignore = true;
59
+ };
60
+ }, [input]);
61
+
62
+ return result;
63
+ }
package/src/index.ts CHANGED
@@ -37,6 +37,7 @@ export {
37
37
  export {
38
38
  useDeprecationWarning,
39
39
  UseDeprecationWarning,
40
+ useGetUrl,
40
41
  useHasValueUpdated,
41
42
  usePreviousValue,
42
43
  useSetUserAgent,