@aws-amplify/ui-react-storage 3.9.0 → 3.9.2

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 (118) hide show
  1. package/dist/browser.js +3 -1
  2. package/dist/{createAmplifyAuthAdapter-BcuxpEzi.js → createAmplifyAuthAdapter-BJjOYxQA.js} +541 -394
  3. package/dist/esm/browser.mjs +6 -0
  4. package/dist/esm/components/StorageBrowser/StorageBrowserAmplify.mjs +1 -0
  5. package/dist/esm/components/StorageBrowser/StorageBrowserDefault.mjs +3 -2
  6. package/dist/esm/components/StorageBrowser/actions/configs/defaults.mjs +10 -12
  7. package/dist/esm/components/StorageBrowser/actions/handlers/constants.mjs +4 -1
  8. package/dist/esm/components/StorageBrowser/actions/handlers/copy.mjs +4 -1
  9. package/dist/esm/components/StorageBrowser/actions/handlers/createFolder.mjs +4 -3
  10. package/dist/esm/components/StorageBrowser/actions/handlers/defaults.mjs +17 -0
  11. package/dist/esm/components/StorageBrowser/actions/handlers/delete.mjs +4 -1
  12. package/dist/esm/components/StorageBrowser/actions/handlers/download.mjs +4 -1
  13. package/dist/esm/components/StorageBrowser/actions/handlers/upload.mjs +6 -11
  14. package/dist/esm/components/StorageBrowser/actions/handlers/utils.mjs +4 -3
  15. package/dist/esm/components/StorageBrowser/adapters/createManagedAuthAdapter/createManagedAuthAdapter.mjs +2 -1
  16. package/dist/esm/components/StorageBrowser/componentsDefault.mjs +4 -4
  17. package/dist/esm/components/StorageBrowser/createStorageBrowser.mjs +7 -1
  18. package/dist/esm/components/StorageBrowser/displayText/libraries/en/shared.mjs +0 -1
  19. package/dist/esm/components/StorageBrowser/displayText/libraries/en/uploadView.mjs +3 -2
  20. package/dist/esm/components/StorageBrowser/displayText/utils.mjs +7 -0
  21. package/dist/esm/components/StorageBrowser/providers/store/locationItems/context.mjs +1 -0
  22. package/dist/esm/components/StorageBrowser/tasks/useProcessTasks.mjs +20 -22
  23. package/dist/esm/components/StorageBrowser/useAction/useAction.mjs +14 -7
  24. package/dist/esm/components/StorageBrowser/useAction/useHandler.mjs +26 -32
  25. package/dist/esm/components/StorageBrowser/useAction/useList.mjs +0 -1
  26. package/dist/esm/components/StorageBrowser/views/LocationActionView/CopyView/CopyViewProvider.mjs +8 -10
  27. package/dist/esm/components/StorageBrowser/views/LocationActionView/CopyView/useCopyView.mjs +1 -0
  28. package/dist/esm/components/StorageBrowser/views/LocationActionView/CopyView/useFolders.mjs +11 -13
  29. package/dist/esm/components/StorageBrowser/views/LocationActionView/CreateFolderView/useCreateFolderView.mjs +1 -0
  30. package/dist/esm/components/StorageBrowser/views/LocationActionView/DeleteView/DeleteViewProvider.mjs +6 -8
  31. package/dist/esm/components/StorageBrowser/views/LocationActionView/DeleteView/useDeleteView.mjs +6 -9
  32. package/dist/esm/components/StorageBrowser/views/LocationActionView/UploadView/UploadViewProvider.mjs +14 -10
  33. package/dist/esm/components/StorageBrowser/views/LocationActionView/UploadView/useUploadView.mjs +2 -1
  34. package/dist/esm/components/StorageBrowser/views/LocationDetailView/getLocationDetailViewTableData/getLocationDetailViewTableData.mjs +1 -0
  35. package/dist/esm/components/StorageBrowser/views/LocationDetailView/useLocationDetailView.mjs +7 -11
  36. package/dist/esm/components/StorageBrowser/views/LocationsView/useLocationsView.mjs +5 -5
  37. package/dist/esm/components/StorageBrowser/views/context/actionViews.mjs +3 -2
  38. package/dist/esm/components/StorageBrowser/views/context/getViews.mjs +4 -1
  39. package/dist/esm/components/StorageBrowser/views/context/primaryViews.mjs +3 -2
  40. package/dist/esm/components/StorageBrowser/views/hooks/usePaginate.mjs +19 -21
  41. package/dist/esm/components/StorageBrowser/views/hooks/useResolveTableData/useResolveTableData.mjs +15 -0
  42. package/dist/esm/components/StorageBrowser/views/useView.mjs +6 -7
  43. package/dist/esm/components/StorageBrowser/views/utils/tableResolvers/constants.mjs +18 -0
  44. package/dist/esm/components/StorageBrowser/views/utils/tableResolvers/copyResolvers.mjs +82 -0
  45. package/dist/esm/components/StorageBrowser/views/utils/tableResolvers/deleteResolvers.mjs +82 -0
  46. package/dist/esm/components/StorageBrowser/views/utils/tableResolvers/uploadResolvers.mjs +112 -0
  47. package/dist/esm/components/StorageBrowser/views/utils/tableResolvers/utils.mjs +49 -0
  48. package/dist/esm/version.mjs +1 -1
  49. package/dist/index.js +1 -1
  50. package/dist/types/components/StorageBrowser/ComponentsProvider.d.ts +4 -1
  51. package/dist/types/components/StorageBrowser/actions/configs/types.d.ts +41 -2
  52. package/dist/types/components/StorageBrowser/actions/handlers/constants.d.ts +1 -0
  53. package/dist/types/components/StorageBrowser/actions/handlers/copy.d.ts +4 -7
  54. package/dist/types/components/StorageBrowser/actions/handlers/createFolder.d.ts +1 -3
  55. package/dist/types/components/StorageBrowser/actions/handlers/defaults.d.ts +15 -0
  56. package/dist/types/components/StorageBrowser/actions/handlers/delete.d.ts +2 -2
  57. package/dist/types/components/StorageBrowser/actions/handlers/index.d.ts +1 -0
  58. package/dist/types/components/StorageBrowser/actions/handlers/listLocations.d.ts +4 -12
  59. package/dist/types/components/StorageBrowser/actions/handlers/types.d.ts +26 -17
  60. package/dist/types/components/StorageBrowser/actions/handlers/upload.d.ts +1 -4
  61. package/dist/types/components/StorageBrowser/actions/handlers/utils.d.ts +2 -2
  62. package/dist/types/components/StorageBrowser/actions/index.d.ts +1 -1
  63. package/dist/types/components/StorageBrowser/componentsDefault.d.ts +2 -2
  64. package/dist/types/components/StorageBrowser/createStorageBrowser.d.ts +6 -0
  65. package/dist/types/components/StorageBrowser/displayText/index.d.ts +1 -0
  66. package/dist/types/components/StorageBrowser/displayText/types.d.ts +16 -5
  67. package/dist/types/components/StorageBrowser/displayText/utils.d.ts +3 -0
  68. package/dist/types/components/StorageBrowser/index.d.ts +4 -3
  69. package/dist/types/components/StorageBrowser/providers/configuration/createConfigurationProvider.d.ts +1 -1
  70. package/dist/types/components/StorageBrowser/providers/configuration/types.d.ts +3 -3
  71. package/dist/types/components/StorageBrowser/providers/index.d.ts +1 -1
  72. package/dist/types/components/StorageBrowser/providers/store/actionType/types.d.ts +4 -0
  73. package/dist/types/components/StorageBrowser/providers/store/files/types.d.ts +1 -4
  74. package/dist/types/components/StorageBrowser/providers/store/index.d.ts +1 -1
  75. package/dist/types/components/StorageBrowser/providers/store/location/context.d.ts +6 -0
  76. package/dist/types/components/StorageBrowser/storage-internal.d.ts +1 -1
  77. package/dist/types/components/StorageBrowser/tasks/index.d.ts +1 -1
  78. package/dist/types/components/StorageBrowser/tasks/types.d.ts +41 -23
  79. package/dist/types/components/StorageBrowser/tasks/useProcessTasks.d.ts +3 -3
  80. package/dist/types/components/StorageBrowser/types.d.ts +191 -15
  81. package/dist/types/components/StorageBrowser/useAction/types.d.ts +60 -32
  82. package/dist/types/components/StorageBrowser/useAction/useHandler.d.ts +4 -3
  83. package/dist/types/components/StorageBrowser/useAction/useList.d.ts +10 -7
  84. package/dist/types/components/StorageBrowser/views/LocationActionView/CopyView/types.d.ts +5 -0
  85. package/dist/types/components/StorageBrowser/views/LocationActionView/UploadView/types.d.ts +2 -2
  86. package/dist/types/components/StorageBrowser/views/LocationActionView/types.d.ts +4 -4
  87. package/dist/types/components/StorageBrowser/views/LocationDetailView/index.d.ts +1 -1
  88. package/dist/types/components/StorageBrowser/views/LocationsView/index.d.ts +1 -1
  89. package/dist/types/components/StorageBrowser/views/context/getViews.d.ts +2 -2
  90. package/dist/types/components/StorageBrowser/views/context/views.d.ts +2 -2
  91. package/dist/types/components/StorageBrowser/views/hooks/usePaginate.d.ts +8 -8
  92. package/dist/types/components/StorageBrowser/views/hooks/useResolveTableData/index.d.ts +2 -0
  93. package/dist/types/components/StorageBrowser/views/hooks/useResolveTableData/types.d.ts +26 -0
  94. package/dist/types/components/StorageBrowser/views/hooks/useResolveTableData/useResolveTableData.d.ts +6 -0
  95. package/dist/types/components/StorageBrowser/views/types.d.ts +1 -1
  96. package/dist/types/components/StorageBrowser/views/useView.d.ts +16 -13
  97. package/dist/types/components/StorageBrowser/views/utils/index.d.ts +1 -0
  98. package/dist/types/components/StorageBrowser/views/utils/tableResolvers/__testUtils__/tasks.d.ts +23 -0
  99. package/dist/types/components/StorageBrowser/views/utils/tableResolvers/constants.d.ts +16 -0
  100. package/dist/types/components/StorageBrowser/views/utils/tableResolvers/copyResolvers.d.ts +3 -0
  101. package/dist/types/components/StorageBrowser/views/utils/tableResolvers/deleteResolvers.d.ts +3 -0
  102. package/dist/types/components/StorageBrowser/views/utils/tableResolvers/index.d.ts +3 -0
  103. package/dist/types/components/StorageBrowser/views/utils/tableResolvers/types.d.ts +36 -0
  104. package/dist/types/components/StorageBrowser/views/utils/tableResolvers/uploadResolvers.d.ts +3 -0
  105. package/dist/types/components/StorageBrowser/views/utils/tableResolvers/utils.d.ts +12 -0
  106. package/dist/types/version.d.ts +1 -1
  107. package/package.json +5 -5
  108. package/dist/esm/components/StorageBrowser/views/LocationActionView/getActionIcon.mjs +0 -25
  109. package/dist/esm/components/StorageBrowser/views/LocationActionView/getActionViewTableData.mjs +0 -155
  110. package/dist/esm/components/StorageBrowser/views/LocationActionView/getDefaultActionViewHeaders.mjs +0 -24
  111. package/dist/esm/components/StorageBrowser/views/LocationActionView/getFileTypeDisplayValue.mjs +0 -5
  112. package/dist/esm/components/StorageBrowser/views/LocationActionView/getPercentValue.mjs +0 -3
  113. package/dist/types/components/StorageBrowser/displayText/en.d.ts +0 -9
  114. package/dist/types/components/StorageBrowser/views/LocationActionView/getActionIcon.d.ts +0 -3
  115. package/dist/types/components/StorageBrowser/views/LocationActionView/getActionViewTableData.d.ts +0 -14
  116. package/dist/types/components/StorageBrowser/views/LocationActionView/getDefaultActionViewHeaders.d.ts +0 -5
  117. package/dist/types/components/StorageBrowser/views/LocationActionView/getFileTypeDisplayValue.d.ts +0 -1
  118. package/dist/types/components/StorageBrowser/views/LocationActionView/getPercentValue.d.ts +0 -1
@@ -1,5 +1,11 @@
1
1
  export { componentsDefault } from './components/StorageBrowser/componentsDefault.mjs';
2
2
  export { createStorageBrowser } from './components/StorageBrowser/createStorageBrowser.mjs';
3
+ import '@aws-amplify/storage/internals';
4
+ import '@aws-amplify/ui';
5
+ export { defaultHandlers } from './components/StorageBrowser/actions/handlers/defaults.mjs';
6
+ import 'aws-amplify/storage';
7
+ import './components/StorageBrowser/actions/configs/context.mjs';
8
+ export { defaultActionConfigs } from './components/StorageBrowser/actions/configs/defaults.mjs';
3
9
  export { createAmplifyAuthAdapter } from './components/StorageBrowser/adapters/createAmplifyAuthAdapter/createAmplifyAuthAdapter.mjs';
4
10
  export { createManagedAuthAdapter } from './components/StorageBrowser/adapters/createManagedAuthAdapter/createManagedAuthAdapter.mjs';
5
11
  import './components/StorageBrowser/displayText/context.mjs';
@@ -5,6 +5,7 @@ import '@aws-amplify/storage/internals';
5
5
  import '@aws-amplify/ui';
6
6
  import 'aws-amplify/storage';
7
7
  import './actions/configs/context.mjs';
8
+ import './actions/configs/defaults.mjs';
8
9
 
9
10
  function StorageBrowser(props) {
10
11
  const { StorageBrowser: StorageBrowserComponent } = React__default.useRef(createStorageBrowser({ config: createAmplifyAuthAdapter() })).current;
@@ -8,13 +8,14 @@ import './providers/store/actionType/context.mjs';
8
8
  import './providers/store/locationItems/context.mjs';
9
9
  import { useStore } from './providers/store/useStore.mjs';
10
10
  import './useAction/context.mjs';
11
- import './providers/configuration/context.mjs';
12
- import '@aws-amplify/ui-react-core';
13
11
  import '@aws-amplify/ui-react-core/elements';
14
12
  import './providers/configuration/credentials/context.mjs';
13
+ import './providers/configuration/context.mjs';
14
+ import '@aws-amplify/ui-react-core';
15
15
  import '@aws-amplify/storage/internals';
16
16
  import 'aws-amplify/storage';
17
17
  import './actions/configs/context.mjs';
18
+ import './actions/configs/defaults.mjs';
18
19
  import './views/LocationActionView/CreateFolderView/CreateFolderView.mjs';
19
20
  import './views/LocationActionView/DeleteView/DeleteView.mjs';
20
21
  import './views/context/actionViews.mjs';
@@ -1,11 +1,7 @@
1
- import { copyHandler } from '../handlers/copy.mjs';
2
- import { createFolderHandler } from '../handlers/createFolder.mjs';
3
- import { deleteHandler } from '../handlers/delete.mjs';
4
- import { downloadHandler } from '../handlers/download.mjs';
5
- import { listLocationItemsHandler } from '../handlers/listLocationItems.mjs';
6
1
  import '@aws-amplify/storage/internals';
7
2
  import '@aws-amplify/ui';
8
- import { uploadHandler } from '../handlers/upload.mjs';
3
+ import { defaultHandlers } from '../handlers/defaults.mjs';
4
+ import 'aws-amplify/storage';
9
5
 
10
6
  const copyActionConfig = {
11
7
  viewName: 'CopyView',
@@ -15,7 +11,7 @@ const copyActionConfig = {
15
11
  icon: 'copy-file',
16
12
  label: 'Copy',
17
13
  },
18
- handler: copyHandler,
14
+ handler: defaultHandlers.copy,
19
15
  };
20
16
  const deleteActionConfig = {
21
17
  viewName: 'DeleteView',
@@ -25,7 +21,7 @@ const deleteActionConfig = {
25
21
  icon: 'delete-file',
26
22
  label: 'Delete',
27
23
  },
28
- handler: deleteHandler,
24
+ handler: defaultHandlers.delete,
29
25
  };
30
26
  const createFolderActionConfig = {
31
27
  viewName: 'CreateFolderView',
@@ -34,7 +30,7 @@ const createFolderActionConfig = {
34
30
  icon: 'create-folder',
35
31
  label: 'Create folder',
36
32
  },
37
- handler: createFolderHandler,
33
+ handler: defaultHandlers.createFolder,
38
34
  };
39
35
  const uploadActionConfig = {
40
36
  viewName: 'UploadView',
@@ -43,12 +39,14 @@ const uploadActionConfig = {
43
39
  icon: 'upload-file',
44
40
  label: 'Upload',
45
41
  },
46
- handler: uploadHandler,
42
+ handler: defaultHandlers.upload,
47
43
  };
44
+ // Action view configs only, does not include `listLocationItems`
48
45
  const defaultActionViewConfigs = {
49
46
  copy: copyActionConfig,
50
47
  createFolder: createFolderActionConfig,
51
- download: downloadHandler,
48
+ // provide `download` handler only; `download` does not have a dedicated view/config
49
+ download: defaultHandlers.download,
52
50
  delete: deleteActionConfig,
53
51
  upload: uploadActionConfig,
54
52
  };
@@ -56,7 +54,7 @@ const DEFAULT_ACTION_VIEW_TYPES = Object.keys(defaultActionViewConfigs);
56
54
  const isDefaultActionViewType = (value) => DEFAULT_ACTION_VIEW_TYPES.some((type) => type === value);
57
55
  const defaultActionConfigs = {
58
56
  ...defaultActionViewConfigs,
59
- listLocationItems: listLocationItemsHandler,
57
+ listLocationItems: defaultHandlers.listLocationItems,
60
58
  };
61
59
 
62
60
  export { DEFAULT_ACTION_VIEW_TYPES, copyActionConfig, createFolderActionConfig, defaultActionConfigs, defaultActionViewConfigs, deleteActionConfig, isDefaultActionViewType, uploadActionConfig };
@@ -1,3 +1,6 @@
1
1
  const DEFAULT_CHECKSUM_ALGORITHM = 'crc-32';
2
+ // 5MiB for multipart upload
3
+ // https://github.com/aws-amplify/amplify-js/blob/1a5366d113c9af4ce994168653df3aadb142c581/packages/storage/src/providers/s3/utils/constants.ts#L16
4
+ const MULTIPART_UPLOAD_THRESHOLD_BYTES = 5 * 1024 * 1024;
2
5
 
3
- export { DEFAULT_CHECKSUM_ALGORITHM };
6
+ export { DEFAULT_CHECKSUM_ALGORITHM, MULTIPART_UPLOAD_THRESHOLD_BYTES };
@@ -34,7 +34,10 @@ const copyHandler = (input) => {
34
34
  status: 'COMPLETE',
35
35
  value: { key: path },
36
36
  }))
37
- .catch(({ message }) => ({ message, status: 'FAILED' })),
37
+ .catch((error) => {
38
+ const { message } = error;
39
+ return { error, message, status: 'FAILED' };
40
+ }),
38
41
  };
39
42
  };
40
43
 
@@ -31,11 +31,12 @@ const createFolderHandler = (input) => {
31
31
  status: 'COMPLETE',
32
32
  value: { key: path },
33
33
  }))
34
- .catch(({ message, name }) => {
34
+ .catch((error) => {
35
+ const { message, name } = error;
35
36
  if (name === 'PreconditionFailed') {
36
- return { message, status: 'OVERWRITE_PREVENTED' };
37
+ return { error, message, status: 'OVERWRITE_PREVENTED' };
37
38
  }
38
- return { message, status: 'FAILED' };
39
+ return { error, message, status: 'FAILED' };
39
40
  }),
40
41
  };
41
42
  };
@@ -0,0 +1,17 @@
1
+ import { copyHandler } from './copy.mjs';
2
+ import { createFolderHandler } from './createFolder.mjs';
3
+ import { deleteHandler } from './delete.mjs';
4
+ import { downloadHandler } from './download.mjs';
5
+ import { listLocationItemsHandler } from './listLocationItems.mjs';
6
+ import { uploadHandler } from './upload.mjs';
7
+
8
+ const defaultHandlers = {
9
+ copy: copyHandler,
10
+ createFolder: createFolderHandler,
11
+ delete: deleteHandler,
12
+ download: downloadHandler,
13
+ listLocationItems: listLocationItemsHandler,
14
+ upload: uploadHandler,
15
+ };
16
+
17
+ export { defaultHandlers };
@@ -17,7 +17,10 @@ const deleteHandler = ({ config, data, }) => {
17
17
  status: 'COMPLETE',
18
18
  value: { key: path },
19
19
  }))
20
- .catch(({ message }) => ({ message, status: 'FAILED' }));
20
+ .catch((error) => {
21
+ const { message } = error;
22
+ return { error, message, status: 'FAILED' };
23
+ });
21
24
  return { result };
22
25
  };
23
26
 
@@ -27,7 +27,10 @@ const downloadHandler = ({ config, data: { key }, }) => {
27
27
  downloadFromUrl(key, url.toString());
28
28
  return { status: 'COMPLETE', value: { url } };
29
29
  })
30
- .catch(({ message }) => ({ message, status: 'FAILED' }));
30
+ .catch((error) => {
31
+ const { message } = error;
32
+ return { error, message, status: 'FAILED' };
33
+ });
31
34
  return { result };
32
35
  };
33
36
 
@@ -1,12 +1,9 @@
1
1
  import { isCancelError } from 'aws-amplify/storage';
2
2
  import { isFunction } from '@aws-amplify/ui';
3
3
  import { uploadData } from '@aws-amplify/storage/internals';
4
- import { constructBucket, getProgress } from './utils.mjs';
4
+ import { isMultipartUpload, constructBucket, getProgress } from './utils.mjs';
5
5
  import { DEFAULT_CHECKSUM_ALGORITHM } from './constants.mjs';
6
6
 
7
- // 5MB for multipart upload
8
- // https://github.com/aws-amplify/amplify-js/blob/1a5366d113c9af4ce994168653df3aadb142c581/packages/storage/src/providers/s3/utils/constants.ts#L16
9
- const MULTIPART_UPLOAD_THRESHOLD_BYTES = 5 * 1024 * 1024;
10
7
  const UNDEFINED_CALLBACKS = {
11
8
  cancel: undefined,
12
9
  pause: undefined,
@@ -34,7 +31,7 @@ const uploadHandler = ({ config, data, options }) => {
34
31
  };
35
32
  const { cancel, pause, resume, result } = uploadData(input);
36
33
  return {
37
- ...(file.size > MULTIPART_UPLOAD_THRESHOLD_BYTES
34
+ ...(isMultipartUpload(file)
38
35
  ? { cancel, pause, resume }
39
36
  : UNDEFINED_CALLBACKS),
40
37
  result: result
@@ -45,14 +42,12 @@ const uploadHandler = ({ config, data, options }) => {
45
42
  .catch((error) => {
46
43
  const { message } = error;
47
44
  if (error.name === 'PreconditionFailed') {
48
- return { message, status: 'OVERWRITE_PREVENTED' };
45
+ return { error, message, status: 'OVERWRITE_PREVENTED' };
49
46
  }
50
- return {
51
- message,
52
- status: isCancelError(error) ? 'CANCELED' : 'FAILED',
53
- };
47
+ const status = isCancelError(error) ? 'CANCELED' : 'FAILED';
48
+ return { error, message, status };
54
49
  }),
55
50
  };
56
51
  };
57
52
 
58
- export { MULTIPART_UPLOAD_THRESHOLD_BYTES, UNDEFINED_CALLBACKS, uploadHandler };
53
+ export { UNDEFINED_CALLBACKS, uploadHandler };
@@ -1,3 +1,5 @@
1
+ import { MULTIPART_UPLOAD_THRESHOLD_BYTES } from './constants.mjs';
2
+
1
3
  const constructBucket = ({ bucket: bucketName, region, }) => ({ bucketName, region });
2
4
  const parseAccessGrantLocation = (location) => {
3
5
  const { permission, scope, type } = location;
@@ -82,8 +84,7 @@ const createFileDataItem = (data) => ({
82
84
  ...data,
83
85
  fileKey: getFileKey(data.key),
84
86
  });
85
- const isFileItem = (value) => !!value.file;
86
- const isFileDataItem = (item) => !!item.fileKey;
87
87
  const getProgress = ({ totalBytes, transferredBytes, }) => totalBytes ? transferredBytes / totalBytes : undefined;
88
+ const isMultipartUpload = (file) => file.size > MULTIPART_UPLOAD_THRESHOLD_BYTES;
88
89
 
89
- export { constructBucket, createFileDataItem, getFileKey, getFilteredLocations, getProgress, isFileDataItem, isFileItem, parseAccessGrantLocation, shouldExcludeLocation };
90
+ export { constructBucket, createFileDataItem, getFileKey, getFilteredLocations, getProgress, isMultipartUpload, parseAccessGrantLocation, shouldExcludeLocation };
@@ -1,9 +1,10 @@
1
1
  import { createLocationCredentialsHandler } from './createLocationCredentialsHandler.mjs';
2
2
  import '@aws-amplify/storage/internals';
3
3
  import '@aws-amplify/ui';
4
- import { listLocationsHandler } from '../../actions/handlers/listLocations.mjs';
5
4
  import 'aws-amplify/storage';
5
+ import { listLocationsHandler } from '../../actions/handlers/listLocations.mjs';
6
6
  import '../../actions/configs/context.mjs';
7
+ import '../../actions/configs/defaults.mjs';
7
8
 
8
9
  /**
9
10
  * Create configuration including handlers to call S3 Access Grant APIs to list and get
@@ -9,7 +9,7 @@ const OverwriteToggle = ({ isDisabled, isOverwritingEnabled, label = '', onToggl
9
9
  onToggle?.();
10
10
  } }));
11
11
  };
12
- const SearchSubfoldersToggle = ({ isSearchingSubfolders, label = '', onToggle, }) => {
12
+ const SearchSubfoldersToggle = ({ isSearchingSubfolders, label = '', onToggle }) => {
13
13
  return (React.createElement(CheckboxField, { name: label, label: label, labelPosition: "end", checked: isSearchingSubfolders, onChange: () => {
14
14
  onToggle?.();
15
15
  } }));
@@ -39,7 +39,7 @@ const Navigation = ({ items }) => {
39
39
  item.isCurrent ? null : React.createElement(Breadcrumbs.Separator, null)));
40
40
  })));
41
41
  };
42
- const LoadingIndicator = ({ isLoading }) => {
42
+ const LoadingIndicator = ({ isLoading, }) => {
43
43
  if (isLoading) {
44
44
  return (React.createElement(Loader, { className: "amplify-storage-browser__loader", variation: "linear", size: "small" }));
45
45
  }
@@ -54,7 +54,7 @@ const FolderNameField = ({ onChange, label, placeholder, validationMessage, onVa
54
54
  onChange?.(value);
55
55
  } }));
56
56
  };
57
- const DataRefresh = ({ onRefresh }) => {
57
+ const DataRefresh = ({ onRefresh, }) => {
58
58
  return (React.createElement(Button, { onClick: () => {
59
59
  onRefresh?.();
60
60
  }, "aria-label": "Refresh data" },
@@ -72,7 +72,7 @@ const ActionsList = ({ items, onActionSelect, isDisabled, }) => {
72
72
  label));
73
73
  })));
74
74
  };
75
- const StatusDisplay = ({ statuses, total }) => {
75
+ const StatusDisplay = ({ statuses, total, }) => {
76
76
  if (!statuses?.length) {
77
77
  return null;
78
78
  }
@@ -2,8 +2,8 @@ import React__default from 'react';
2
2
  import { setUserAgent } from '@aws-amplify/ui';
3
3
  import { VERSION } from '../../version.mjs';
4
4
  import '@aws-amplify/storage/internals';
5
- import { assertRegisterAuthListener } from './validators/assertRegisterAuthListener.mjs';
6
5
  import 'aws-amplify/storage';
6
+ import { assertRegisterAuthListener } from './validators/assertRegisterAuthListener.mjs';
7
7
  import { ActionConfigsProvider } from './actions/configs/context.mjs';
8
8
  import { defaultActionConfigs } from './actions/configs/defaults.mjs';
9
9
  import { getActionConfigs } from './actions/configs/utils.mjs';
@@ -38,6 +38,12 @@ import { LocationDetailView } from './views/LocationDetailView/LocationDetailVie
38
38
  import { LocationsView } from './views/LocationsView/LocationsView.mjs';
39
39
  import { useView } from './views/useView.mjs';
40
40
 
41
+ /**
42
+ * Creates a `StorageBrowser` component and utility hooks from provided configuration `input`.
43
+ *
44
+ * @param input - `StorageBrowser` auth, actions and ui configuration values
45
+ * @returns `StorageBrowser` component, `useAction` and `useView` hooks
46
+ */
41
47
  function createStorageBrowser(input) {
42
48
  assertRegisterAuthListener(input.config.registerAuthListener);
43
49
  const { accountId, customEndpoint, registerAuthListener, getLocationCredentials, region, } = input.config;
@@ -15,7 +15,6 @@ const DEFAULT_ACTION_VIEW_DISPLAY_TEXT = {
15
15
  tableColumnNameHeader: 'Name',
16
16
  tableColumnTypeHeader: 'Type',
17
17
  tableColumnSizeHeader: 'Size',
18
- tableColumnProgressHeader: 'Progress',
19
18
  };
20
19
  const DEFAULT_LIST_VIEW_DISPLAY_TEXT = {
21
20
  loadingIndicatorLabel: 'Loading',
@@ -4,7 +4,6 @@ import { isFileTooBig } from '../../../validators/isFileTooBig.mjs';
4
4
 
5
5
  const DEFAULT_UPLOAD_VIEW_DISPLAY_TEXT = {
6
6
  ...DEFAULT_ACTION_VIEW_DISPLAY_TEXT,
7
- title: 'Upload',
8
7
  actionStartLabel: 'Upload',
9
8
  addFilesLabel: 'Add files',
10
9
  addFolderLabel: 'Add folder',
@@ -80,8 +79,10 @@ const DEFAULT_UPLOAD_VIEW_DISPLAY_TEXT = {
80
79
  }
81
80
  return undefined;
82
81
  },
83
- statusDisplayOverwritePreventedLabel: 'Overwrite prevented',
84
82
  overwriteToggleLabel: 'Overwrite existing files',
83
+ statusDisplayOverwritePreventedLabel: 'Overwrite prevented',
84
+ tableColumnProgressHeader: 'Progress',
85
+ title: 'Upload',
85
86
  };
86
87
 
87
88
  export { DEFAULT_UPLOAD_VIEW_DISPLAY_TEXT };
@@ -0,0 +1,7 @@
1
+ import { DEFAULT_COPY_VIEW_DISPLAY_TEXT } from './libraries/en/copyView.mjs';
2
+ import { DEFAULT_DELETE_VIEW_DISPLAY_TEXT } from './libraries/en/deleteView.mjs';
3
+
4
+ const isCopyViewDisplayTextKey = (value) => !!DEFAULT_COPY_VIEW_DISPLAY_TEXT[value];
5
+ const isDeleteViewDisplayTextKey = (value) => !!DEFAULT_DELETE_VIEW_DISPLAY_TEXT[value];
6
+
7
+ export { isCopyViewDisplayTextKey, isDeleteViewDisplayTextKey };
@@ -5,6 +5,7 @@ import '@aws-amplify/storage/internals';
5
5
  import { createFileDataItem } from '../../../actions/handlers/utils.mjs';
6
6
  import 'aws-amplify/storage';
7
7
  import '../../../actions/configs/context.mjs';
8
+ import '../../../actions/configs/defaults.mjs';
8
9
 
9
10
  const DEFAULT_STATE = {
10
11
  fileDataItems: undefined,
@@ -9,8 +9,8 @@ const QUEUED_TASK_BASE = {
9
9
  status: 'QUEUED',
10
10
  };
11
11
  const isTaskHandlerInput = (input) => !!input.data;
12
- const useProcessTasks = (handler, items, options) => {
13
- const { concurrency, ...callbacks } = options ?? {};
12
+ function useProcessTasks(handler, options) {
13
+ const { concurrency, items, ...callbacks } = options ?? {};
14
14
  const callbacksRef = React__default.useRef(callbacks);
15
15
  if (callbacks) {
16
16
  callbacksRef.current = callbacks;
@@ -36,6 +36,7 @@ const useProcessTasks = (handler, items, options) => {
36
36
  tasksRef.current.set(id, { ...task, ...next });
37
37
  }
38
38
  flush();
39
+ return !next ? undefined : tasksRef.current.get(id);
39
40
  }, [flush]);
40
41
  const createTask = React__default.useCallback((data) => {
41
42
  const getTask = () => tasksRef.current.get(data.id);
@@ -44,9 +45,12 @@ const useProcessTasks = (handler, items, options) => {
44
45
  const task = getTask();
45
46
  if (!task || task?.status !== 'QUEUED')
46
47
  return;
47
- if (task && isFunction(onTaskCancel))
48
- onTaskCancel(task);
49
- updateTask(data.id, { cancel: undefined, status: 'CANCELED' });
48
+ const canceledTask = updateTask(data.id, {
49
+ cancel: undefined,
50
+ status: 'CANCELED',
51
+ });
52
+ if (canceledTask && isFunction(onTaskCancel))
53
+ onTaskCancel(canceledTask);
50
54
  }
51
55
  const task = { ...QUEUED_TASK_BASE, cancel, data };
52
56
  tasksRef.current.set(data.id, task);
@@ -91,16 +95,15 @@ const useProcessTasks = (handler, items, options) => {
91
95
  const { onTaskCancel, onTaskComplete, onTaskError, onTaskProgress, onTaskSuccess, } = callbacksRef.current;
92
96
  const getTask = () => tasksRef.current.get(data.id);
93
97
  const { options } = _input;
94
- const { onProgress: _onProgress, onSuccess, onError } = options ?? {};
98
+ const { onProgress: _onProgress } = options ?? {};
95
99
  const onProgress = ({ id }, progress) => {
96
- const task = getTask();
100
+ const task = updateTask(id, { progress });
97
101
  if (task && isFunction(onTaskProgress)) {
98
102
  onTaskProgress(task, progress);
99
103
  }
100
104
  if (task && isFunction(_onProgress)) {
101
105
  _onProgress(data, progress);
102
106
  }
103
- updateTask(id, { progress });
104
107
  };
105
108
  const input = { ..._input, data, options: { ...options, onProgress } };
106
109
  const { cancel: _cancel, result } = handler(input);
@@ -114,21 +117,16 @@ const useProcessTasks = (handler, items, options) => {
114
117
  };
115
118
  result
116
119
  .then((output) => {
117
- const task = getTask();
118
- if (task && isFunction(onTaskSuccess)) {
119
- onTaskSuccess(task, output?.value);
120
- }
121
- if (task && isFunction(onSuccess))
122
- onSuccess(data, output?.value);
123
- updateTask(data.id, output);
120
+ const task = updateTask(data.id, output);
121
+ const { value } = output;
122
+ if (task && isFunction(onTaskSuccess))
123
+ onTaskSuccess(task, value);
124
124
  })
125
- .catch((e) => {
126
- const task = getTask();
125
+ .catch((error) => {
126
+ const { message } = error;
127
+ const task = updateTask(data.id, { message, status: 'FAILED' });
127
128
  if (task && isFunction(onTaskError))
128
- onTaskError(task, e);
129
- if (task && isFunction(onError))
130
- onError(data, e?.message);
131
- updateTask(data.id, { message: e.message, status: 'FAILED' });
129
+ onTaskError(task, error);
132
130
  })
133
131
  .finally(() => {
134
132
  const task = getTask();
@@ -166,6 +164,6 @@ const useProcessTasks = (handler, items, options) => {
166
164
  { isProcessing, isProcessingComplete, reset, statusCounts, tasks },
167
165
  handleProcessTasks,
168
166
  ];
169
- };
167
+ }
170
168
 
171
169
  export { useProcessTasks };
@@ -2,17 +2,24 @@ import { useActionHandlers } from './context.mjs';
2
2
  import { useHandler } from './useHandler.mjs';
3
3
 
4
4
  const ERROR_MESSAGE = '`useAction` must be called from within `StorageBrowser.Provider`';
5
- const useAction = (key, options) => {
6
- if (key === 'listLocations' ||
7
- key === 'listLocationItems') {
5
+ function assertActionHandlerKey(key) {
6
+ if (key === 'listLocations' || key === 'listLocationItems') {
8
7
  throw new Error(`Value of \`${key}\` cannot be provided to \`useAction\``);
9
8
  }
10
- const { handlers } = useActionHandlers({ errorMessage: ERROR_MESSAGE });
11
- const handler = handlers?.[key];
12
- if (!handler) {
9
+ }
10
+ function assertActionHandler(handler, key) {
11
+ if (typeof handler !== 'function') {
13
12
  throw new Error(`No handler found for value of \`${key}\` provided to \`useAction\``);
14
13
  }
14
+ }
15
+ const useAction = ((key, options) => {
16
+ assertActionHandlerKey(key);
17
+ const { handlers } = useActionHandlers({ errorMessage: ERROR_MESSAGE });
18
+ const handler = handlers?.[key];
19
+ assertActionHandler(handler, key);
15
20
  return useHandler(handler, options);
16
- };
21
+ // casting to allow usage of `UseAction` interface which ensures that
22
+ // the `options` param receives the correct typing
23
+ });
17
24
 
18
25
  export { ERROR_MESSAGE, useAction };
@@ -1,40 +1,34 @@
1
1
  import React__default from 'react';
2
- import { isObject } from '@aws-amplify/ui';
2
+ import '@aws-amplify/ui-react-core/elements';
3
+ import '../providers/configuration/credentials/context.mjs';
3
4
  import { useGetActionInput } from '../providers/configuration/context.mjs';
4
- import '../providers/store/location/context.mjs';
5
- import '../providers/store/files/context.mjs';
6
- import '../providers/store/actionType/context.mjs';
7
- import '../providers/store/locationItems/context.mjs';
8
- import { useStore } from '../providers/store/useStore.mjs';
9
- import { useProcessTasks } from '../tasks/useProcessTasks.mjs';
10
5
  import { DEFAULT_ACTION_CONCURRENCY } from './constants.mjs';
6
+ import { useProcessTasks } from '../tasks/useProcessTasks.mjs';
11
7
 
12
- const isTasksOptions = (value) => isObject(value);
13
- const useHandler = (action, options) => {
14
- const hasOptions = isTasksOptions(options);
15
- const { items, onTaskSuccess } = options ?? {};
16
- const getConfig = useGetActionInput();
17
- const { location: { current }, } = useStore()[0];
18
- const [state, processTask] = useProcessTasks(action, items, {
19
- onTaskSuccess,
20
- ...(items ? { concurrency: DEFAULT_ACTION_CONCURRENCY } : undefined),
8
+ const isOptionsWithItems = (options) => !!options?.items;
9
+ const isHandleTaskInput = (value) => !!value?.data;
10
+ function useHandler(handler, options) {
11
+ const [state, handleProcessing] = useProcessTasks(handler, {
12
+ ...options,
13
+ concurrency: DEFAULT_ACTION_CONCURRENCY,
21
14
  });
22
- const { reset, isProcessing, tasks } = state;
23
- const handler = React__default.useCallback((input) => {
24
- const { location } = input ?? {};
25
- const config = getConfig(location ?? current);
26
- if (!hasOptions) {
27
- // clean up previous state
15
+ const getConfig = useGetActionInput();
16
+ const { reset, isProcessing, tasks, ...rest } = state;
17
+ const handleDispatch = React__default.useCallback((input) => {
18
+ const config = getConfig(input?.location);
19
+ const hasData = isHandleTaskInput(input);
20
+ // clean up previous state for atomic handler
21
+ if (hasData)
28
22
  reset();
29
- processTask({ ...input, config });
30
- return;
31
- }
32
- processTask({ config });
33
- }, [current, getConfig, hasOptions, processTask, reset]);
34
- return [
35
- hasOptions ? state : { isProcessing, task: tasks?.[0] },
36
- handler,
37
- ];
38
- };
23
+ handleProcessing({
24
+ config,
25
+ ...(hasData ? { data: input.data } : undefined),
26
+ });
27
+ }, [getConfig, handleProcessing, reset]);
28
+ if (isOptionsWithItems(options)) {
29
+ return [{ ...rest, isProcessing, reset, tasks }, handleDispatch];
30
+ }
31
+ return [{ isProcessing, task: tasks?.[0] }, handleDispatch];
32
+ }
39
33
 
40
34
  export { useHandler };
@@ -8,7 +8,6 @@ const LIST_ACTION_HOOKS = {
8
8
  locations: useListLocations,
9
9
  };
10
10
  const isListActionViewType = (value) => Object.keys(LIST_ACTION_HOOKS).includes(value);
11
- // @ts-expect-error
12
11
  const useList = (type) => {
13
12
  if (!isListActionViewType(type)) {
14
13
  throw new Error(`Value of \`${type}\` cannot be used to index \`useList\``);
@@ -2,23 +2,20 @@ import React__default from 'react';
2
2
  import { ControlsContextProvider } from '../../../controls/context.mjs';
3
3
  import { useDisplayText } from '../../../displayText/context.mjs';
4
4
  import '@aws-amplify/ui';
5
- import { getActionViewTableData } from '../getActionViewTableData.mjs';
5
+ import useResolveDataTable from '../../hooks/useResolveTableData/useResolveTableData.mjs';
6
+ import { COPY_TABLE_RESOLVERS, COPY_TABLE_KEYS } from '../../utils/tableResolvers/copyResolvers.mjs';
6
7
  import { FoldersMessageProvider } from './FoldersMessageControl.mjs';
7
8
  import { FoldersPaginationProvider } from './FoldersPaginationControl.mjs';
8
9
  import { FoldersTableProvider } from './FoldersTableControl.mjs';
9
10
 
10
11
  function CopyViewProvider({ children, ...props }) {
11
12
  const { CopyView: displayText } = useDisplayText();
12
- const { actionCancelLabel, actionDestinationLabel, actionExitLabel, actionStartLabel, getActionCompleteMessage, overwriteWarningMessage, searchPlaceholder, searchSubmitLabel, searchClearLabel, statusDisplayCanceledLabel, statusDisplayCompletedLabel, statusDisplayFailedLabel, statusDisplayQueuedLabel, } = displayText;
13
- const { destination, folders, isProcessing, isProcessingComplete, location, statusCounts, tasks, onActionCancel, onActionExit, onActionStart, onSelectDestination, onTaskRemove, } = props;
13
+ const { actionCancelLabel, actionDestinationLabel, actionExitLabel, actionStartLabel, getActionCompleteMessage, overwriteWarningMessage, searchPlaceholder, searchSubmitLabel, searchClearLabel, statusDisplayCanceledLabel, statusDisplayCompletedLabel, statusDisplayFailedLabel, statusDisplayQueuedLabel, title, } = displayText;
14
+ const { destination, folders, isProcessing, isProcessingComplete, statusCounts, tasks: items, onActionCancel, onActionExit, onActionStart, onSelectDestination, onTaskRemove, } = props;
14
15
  const { hasNextPage, highestPageVisited, hasError: hasFoldersError, message: foldersErrorMessage, query, hasExhaustedSearch, isLoading, page, pageItems, onPaginate, onQuery, onSearchClear, onSearch, onSelectFolder, } = folders;
15
- const { key: locationKey } = location ?? {};
16
- const tableData = getActionViewTableData({
17
- tasks,
18
- locationKey,
19
- isProcessing,
20
- displayText,
21
- onTaskRemove,
16
+ const tableData = useResolveDataTable(COPY_TABLE_KEYS, COPY_TABLE_RESOLVERS, {
17
+ items,
18
+ props: { displayText, isProcessing, onTaskRemove },
22
19
  });
23
20
  const isActionStartDisabled = isProcessing || isProcessingComplete || !destination?.current;
24
21
  const isActionCancelDisabled = !isProcessing || isProcessingComplete;
@@ -50,6 +47,7 @@ function CopyViewProvider({ children, ...props }) {
50
47
  statusDisplayFailedLabel,
51
48
  statusDisplayQueuedLabel,
52
49
  tableData,
50
+ title,
53
51
  }, onActionCancel: onActionCancel, onActionExit: onActionExit, onActionStart: onActionStart, onSearch: onSearch, onSearchClear: onSearchClear, onSearchQueryChange: onQuery, onSelectDestination: onSelectDestination },
54
52
  React__default.createElement(FoldersPaginationProvider, { hasNextPage: hasNextPage, highestPageVisited: highestPageVisited, page: page, onPaginate: onPaginate },
55
53
  React__default.createElement(FoldersTableProvider, { destination: destination, folders: pageItems, onSelectFolder: onSelectFolder },
@@ -14,6 +14,7 @@ import '../../../providers/configuration/context.mjs';
14
14
  import '@aws-amplify/storage/internals';
15
15
  import 'aws-amplify/storage';
16
16
  import '../../../actions/configs/context.mjs';
17
+ import '../../../actions/configs/defaults.mjs';
17
18
  import { useFolders } from './useFolders.mjs';
18
19
 
19
20
  const useCopyView = (options) => {