@webiny/app 6.3.0-beta.4 → 6.4.0-beta.0

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 (276) hide show
  1. package/App.js +70 -77
  2. package/App.js.map +1 -1
  3. package/AppContainer.js +3 -6
  4. package/AppContainer.js.map +1 -1
  5. package/apollo-client/InMemoryCache.js +11 -13
  6. package/apollo-client/InMemoryCache.js.map +1 -1
  7. package/apollo-client/IntrospectionFragmentMatcher.js +26 -38
  8. package/apollo-client/IntrospectionFragmentMatcher.js.map +1 -1
  9. package/components/Image.js +11 -17
  10. package/components/Image.js.map +1 -1
  11. package/components/index.js +0 -2
  12. package/config/RouterConfig/Route.js +23 -28
  13. package/config/RouterConfig/Route.js.map +1 -1
  14. package/config/RouterConfig.js +11 -10
  15. package/config/RouterConfig.js.map +1 -1
  16. package/config.js +19 -20
  17. package/config.js.map +1 -1
  18. package/contexts/Ui/index.js +26 -28
  19. package/contexts/Ui/index.js.map +1 -1
  20. package/core/Plugin.js +7 -9
  21. package/core/Plugin.js.map +1 -1
  22. package/core/Plugins.js +15 -34
  23. package/core/Plugins.js.map +1 -1
  24. package/core/Provider.js +5 -13
  25. package/core/Provider.js.map +1 -1
  26. package/core/createProvider.js +3 -6
  27. package/core/createProvider.js.map +1 -1
  28. package/core/createProviderPlugin.js +8 -13
  29. package/core/createProviderPlugin.js.map +1 -1
  30. package/errors/AuthenticationErrorEvent.js +8 -5
  31. package/errors/AuthenticationErrorEvent.js.map +1 -1
  32. package/errors/NetworkErrorEvent.js +8 -5
  33. package/errors/NetworkErrorEvent.js.map +1 -1
  34. package/errors/abstractions.js +3 -2
  35. package/errors/abstractions.js.map +1 -1
  36. package/errors/index.js +1 -4
  37. package/exports/admin/env-config.js +0 -2
  38. package/exports/admin/graphql-client.js +0 -2
  39. package/exports/admin/local-storage.js +0 -2
  40. package/exports/admin/router.js +0 -2
  41. package/exports/admin/security.js +0 -2
  42. package/exports/admin.js +0 -2
  43. package/features/envConfig/EnvConfig.js +12 -13
  44. package/features/envConfig/EnvConfig.js.map +1 -1
  45. package/features/envConfig/abstractions.js +2 -1
  46. package/features/envConfig/abstractions.js.map +1 -1
  47. package/features/envConfig/feature.js +9 -8
  48. package/features/envConfig/feature.js.map +1 -1
  49. package/features/envConfig/index.js +0 -2
  50. package/features/eventPublisher/EventPublisher.js +13 -21
  51. package/features/eventPublisher/EventPublisher.js.map +1 -1
  52. package/features/eventPublisher/abstractions.js +7 -9
  53. package/features/eventPublisher/abstractions.js.map +1 -1
  54. package/features/eventPublisher/feature.js +13 -12
  55. package/features/eventPublisher/feature.js.map +1 -1
  56. package/features/eventPublisher/index.js +1 -3
  57. package/features/graphqlClient/AuthenticationErrorPublishing.js +26 -26
  58. package/features/graphqlClient/AuthenticationErrorPublishing.js.map +1 -1
  59. package/features/graphqlClient/BatchingGraphQLClient.js +104 -149
  60. package/features/graphqlClient/BatchingGraphQLClient.js.map +1 -1
  61. package/features/graphqlClient/FetchGraphQLClient.js +41 -48
  62. package/features/graphqlClient/FetchGraphQLClient.js.map +1 -1
  63. package/features/graphqlClient/NetworkErrorPublishing.js +35 -42
  64. package/features/graphqlClient/NetworkErrorPublishing.js.map +1 -1
  65. package/features/graphqlClient/RequestValue.js +42 -41
  66. package/features/graphqlClient/RequestValue.js.map +1 -1
  67. package/features/graphqlClient/RetryGraphQLClient.js +36 -45
  68. package/features/graphqlClient/RetryGraphQLClient.js.map +1 -1
  69. package/features/graphqlClient/__tests__/GraphQLClient.test.js +383 -356
  70. package/features/graphqlClient/__tests__/GraphQLClient.test.js.map +1 -1
  71. package/features/graphqlClient/abstractions.js +2 -1
  72. package/features/graphqlClient/abstractions.js.map +1 -1
  73. package/features/graphqlClient/feature.js +14 -20
  74. package/features/graphqlClient/feature.js.map +1 -1
  75. package/features/graphqlClient/index.js +0 -2
  76. package/features/graphqlClient/types.js +0 -3
  77. package/features/localStorage/BrowserLocalStorageGateway.js +56 -63
  78. package/features/localStorage/BrowserLocalStorageGateway.js.map +1 -1
  79. package/features/localStorage/LocalStorage.js +27 -24
  80. package/features/localStorage/LocalStorage.js.map +1 -1
  81. package/features/localStorage/LocalStorageRepository.js +75 -88
  82. package/features/localStorage/LocalStorageRepository.js.map +1 -1
  83. package/features/localStorage/abstractions.js +5 -16
  84. package/features/localStorage/abstractions.js.map +1 -1
  85. package/features/localStorage/feature.js +17 -28
  86. package/features/localStorage/feature.js.map +1 -1
  87. package/features/localStorage/index.js +1 -3
  88. package/features/mainGraphQLClient/MainGraphQLClient.js +18 -14
  89. package/features/mainGraphQLClient/MainGraphQLClient.js.map +1 -1
  90. package/features/mainGraphQLClient/abstractions.js +2 -1
  91. package/features/mainGraphQLClient/abstractions.js.map +1 -1
  92. package/features/mainGraphQLClient/feature.js +11 -10
  93. package/features/mainGraphQLClient/feature.js.map +1 -1
  94. package/features/mainGraphQLClient/index.js +0 -2
  95. package/features/router/HistoryRouterGateway.js +75 -105
  96. package/features/router/HistoryRouterGateway.js.map +1 -1
  97. package/features/router/HistoryRouterGateway.test.js +184 -193
  98. package/features/router/HistoryRouterGateway.test.js.map +1 -1
  99. package/features/router/Route.js +38 -54
  100. package/features/router/Route.js.map +1 -1
  101. package/features/router/RouteUrl.js +84 -217
  102. package/features/router/RouteUrl.js.map +1 -1
  103. package/features/router/Router.js +67 -124
  104. package/features/router/Router.js.map +1 -1
  105. package/features/router/RouterPresenter.js +44 -49
  106. package/features/router/RouterPresenter.js.map +1 -1
  107. package/features/router/RouterRepository.js +103 -111
  108. package/features/router/RouterRepository.js.map +1 -1
  109. package/features/router/RouterRepository.test.js +119 -150
  110. package/features/router/RouterRepository.test.js.map +1 -1
  111. package/features/router/abstractions.js +4 -14
  112. package/features/router/abstractions.js.map +1 -1
  113. package/features/router/feature.js +13 -12
  114. package/features/router/feature.js.map +1 -1
  115. package/features/router/index.js +1 -3
  116. package/helpers/InterfaceGenerator/date.js +0 -3
  117. package/helpers/InterfaceGenerator/id.js +0 -3
  118. package/helpers/InterfaceGenerator/identity.js +0 -3
  119. package/helpers/InterfaceGenerator/index.js +0 -3
  120. package/helpers/InterfaceGenerator/numeric.js +0 -3
  121. package/helpers/InterfaceGenerator/truthful.js +0 -3
  122. package/hooks/useAutocomplete/index.js +0 -2
  123. package/hooks/useAutocomplete/useAutocomplete.js +12 -15
  124. package/hooks/useAutocomplete/useAutocomplete.js.map +1 -1
  125. package/hooks/useDataList/functions/getData.js +2 -1
  126. package/hooks/useDataList/functions/getData.js.map +1 -1
  127. package/hooks/useDataList/functions/getError.js +2 -1
  128. package/hooks/useDataList/functions/getError.js.map +1 -1
  129. package/hooks/useDataList/functions/getMeta.js +2 -1
  130. package/hooks/useDataList/functions/getMeta.js.map +1 -1
  131. package/hooks/useDataList/functions/index.js +0 -2
  132. package/hooks/useDataList/functions/searchDataByKey.js +9 -14
  133. package/hooks/useDataList/functions/searchDataByKey.js.map +1 -1
  134. package/hooks/useDataList/index.js +0 -2
  135. package/hooks/useDataList/useDataList.js +131 -152
  136. package/hooks/useDataList/useDataList.js.map +1 -1
  137. package/hooks/useDataList/utils/index.js +0 -2
  138. package/hooks/useDataList/utils/prepareLoadListParams.js +25 -34
  139. package/hooks/useDataList/utils/prepareLoadListParams.js.map +1 -1
  140. package/hooks/useHandler.js +12 -16
  141. package/hooks/useHandler.js.map +1 -1
  142. package/hooks/useHandlers.js +18 -20
  143. package/hooks/useHandlers.js.map +1 -1
  144. package/hooks/useRegisterLegacyPlugin.js +7 -6
  145. package/hooks/useRegisterLegacyPlugin.js.map +1 -1
  146. package/hooks/useUi.js +2 -3
  147. package/hooks/useUi.js.map +1 -1
  148. package/i18n/i18n.js +8 -4
  149. package/i18n/i18n.js.map +1 -1
  150. package/i18n/index.js +0 -2
  151. package/index.js +6 -11
  152. package/package.json +13 -13
  153. package/plugins/AddQuerySelectionPlugin.js +36 -61
  154. package/plugins/AddQuerySelectionPlugin.js.map +1 -1
  155. package/plugins/ApolloCacheObjectIdPlugin.js +12 -11
  156. package/plugins/ApolloCacheObjectIdPlugin.js.map +1 -1
  157. package/plugins/ApolloDynamicLink.js +20 -22
  158. package/plugins/ApolloDynamicLink.js.map +1 -1
  159. package/plugins/ApolloLinkPlugin.js +16 -15
  160. package/plugins/ApolloLinkPlugin.js.map +1 -1
  161. package/plugins/ConsoleLinkPlugin.js +19 -21
  162. package/plugins/ConsoleLinkPlugin.js.map +1 -1
  163. package/plugins/NetworkErrorLinkPlugin/ErrorOverlay.js +39 -45
  164. package/plugins/NetworkErrorLinkPlugin/ErrorOverlay.js.map +1 -1
  165. package/plugins/NetworkErrorLinkPlugin/GqlErrorOverlay.js +18 -22
  166. package/plugins/NetworkErrorLinkPlugin/GqlErrorOverlay.js.map +1 -1
  167. package/plugins/NetworkErrorLinkPlugin/LocalAwsLambdaTimeoutMessage.js +21 -29
  168. package/plugins/NetworkErrorLinkPlugin/LocalAwsLambdaTimeoutMessage.js.map +1 -1
  169. package/plugins/NetworkErrorLinkPlugin/StyledComponents.js +6 -15
  170. package/plugins/NetworkErrorLinkPlugin/StyledComponents.js.map +1 -1
  171. package/plugins/NetworkErrorLinkPlugin/Typography.js +9 -14
  172. package/plugins/NetworkErrorLinkPlugin/Typography.js.map +1 -1
  173. package/plugins/NetworkErrorLinkPlugin/assets/close_24px.js +19 -0
  174. package/plugins/NetworkErrorLinkPlugin/assets/close_24px.js.map +1 -0
  175. package/plugins/NetworkErrorLinkPlugin/createErrorOverlay.js +11 -18
  176. package/plugins/NetworkErrorLinkPlugin/createErrorOverlay.js.map +1 -1
  177. package/plugins/NetworkErrorLinkPlugin.js +41 -58
  178. package/plugins/NetworkErrorLinkPlugin.js.map +1 -1
  179. package/plugins/OmitTypenameLinkPlugin.js +9 -14
  180. package/plugins/OmitTypenameLinkPlugin.js.map +1 -1
  181. package/plugins/TenantHeaderLinkPlugin.js +23 -32
  182. package/plugins/TenantHeaderLinkPlugin.js.map +1 -1
  183. package/plugins/components/Image.js +8 -15
  184. package/plugins/components/Image.js.map +1 -1
  185. package/plugins/image.js +94 -133
  186. package/plugins/image.js.map +1 -1
  187. package/plugins/index.js +35 -59
  188. package/plugins/index.js.map +1 -1
  189. package/presentation/envConfig/useEnvConfig.js +4 -8
  190. package/presentation/envConfig/useEnvConfig.js.map +1 -1
  191. package/presentation/localStorage/index.js +0 -2
  192. package/presentation/localStorage/useLocalStorage.js +10 -16
  193. package/presentation/localStorage/useLocalStorage.js.map +1 -1
  194. package/presentation/localStorage/useLocalStorageValue.js +15 -13
  195. package/presentation/localStorage/useLocalStorageValue.js.map +1 -1
  196. package/presentation/localStorage/useLocalStorageValues.js +23 -30
  197. package/presentation/localStorage/useLocalStorageValues.js.map +1 -1
  198. package/presentation/router/RouteElementRegistry.js +22 -25
  199. package/presentation/router/RouteElementRegistry.js.map +1 -1
  200. package/presentation/router/abstractions.js +2 -1
  201. package/presentation/router/abstractions.js.map +1 -1
  202. package/presentation/router/components/Redirect.js +8 -10
  203. package/presentation/router/components/Redirect.js.map +1 -1
  204. package/presentation/router/components/RouteContent.js +14 -17
  205. package/presentation/router/components/RouteContent.js.map +1 -1
  206. package/presentation/router/components/RouteLink.js +11 -16
  207. package/presentation/router/components/RouteLink.js.map +1 -1
  208. package/presentation/router/components/SimpleLink.js +18 -24
  209. package/presentation/router/components/SimpleLink.js.map +1 -1
  210. package/presentation/router/hooks/useRoute.js +15 -23
  211. package/presentation/router/hooks/useRoute.js.map +1 -1
  212. package/presentation/router/hooks/useRouter.js +22 -23
  213. package/presentation/router/hooks/useRouter.js.map +1 -1
  214. package/presentation/router/index.js +0 -2
  215. package/presentation/router/types.js +0 -3
  216. package/react-butterfiles/Files.js +148 -217
  217. package/react-butterfiles/Files.js.map +1 -1
  218. package/react-butterfiles/index.js +2 -1
  219. package/react-butterfiles/index.js.map +1 -1
  220. package/react-butterfiles/utils/generateId.js +2 -3
  221. package/react-butterfiles/utils/generateId.js.map +1 -1
  222. package/react-butterfiles/utils/readFileContent.js +9 -13
  223. package/react-butterfiles/utils/readFileContent.js.map +1 -1
  224. package/renderApp.js +7 -6
  225. package/renderApp.js.map +1 -1
  226. package/router.js +0 -3
  227. package/rslib-runtime.js +14 -0
  228. package/rslib-runtime.js.map +1 -0
  229. package/shared/di/DiContainerProvider.js +8 -12
  230. package/shared/di/DiContainerProvider.js.map +1 -1
  231. package/shared/di/createFeature.js +7 -8
  232. package/shared/di/createFeature.js.map +1 -1
  233. package/shared/di/useFeature.js +7 -3
  234. package/shared/di/useFeature.js.map +1 -1
  235. package/static/svg/close_24px.33adaadc.svg +1 -0
  236. package/types.js +0 -3
  237. package/utils/createGenericContext.js +17 -21
  238. package/utils/createGenericContext.js.map +1 -1
  239. package/utils/createHashing.js +13 -16
  240. package/utils/createHashing.js.map +1 -1
  241. package/utils/index.js +0 -2
  242. package/utils/legacyPluginToReactComponent.js +11 -10
  243. package/utils/legacyPluginToReactComponent.js.map +1 -1
  244. package/components/index.js.map +0 -1
  245. package/errors/index.js.map +0 -1
  246. package/exports/admin/env-config.js.map +0 -1
  247. package/exports/admin/graphql-client.js.map +0 -1
  248. package/exports/admin/local-storage.js.map +0 -1
  249. package/exports/admin/router.js.map +0 -1
  250. package/exports/admin/security.js.map +0 -1
  251. package/exports/admin.js.map +0 -1
  252. package/features/envConfig/index.js.map +0 -1
  253. package/features/eventPublisher/index.js.map +0 -1
  254. package/features/graphqlClient/index.js.map +0 -1
  255. package/features/graphqlClient/types.js.map +0 -1
  256. package/features/localStorage/index.js.map +0 -1
  257. package/features/mainGraphQLClient/index.js.map +0 -1
  258. package/features/router/index.js.map +0 -1
  259. package/helpers/InterfaceGenerator/date.js.map +0 -1
  260. package/helpers/InterfaceGenerator/id.js.map +0 -1
  261. package/helpers/InterfaceGenerator/identity.js.map +0 -1
  262. package/helpers/InterfaceGenerator/index.js.map +0 -1
  263. package/helpers/InterfaceGenerator/numeric.js.map +0 -1
  264. package/helpers/InterfaceGenerator/truthful.js.map +0 -1
  265. package/hooks/useAutocomplete/index.js.map +0 -1
  266. package/hooks/useDataList/functions/index.js.map +0 -1
  267. package/hooks/useDataList/index.js.map +0 -1
  268. package/hooks/useDataList/utils/index.js.map +0 -1
  269. package/i18n/index.js.map +0 -1
  270. package/index.js.map +0 -1
  271. package/presentation/localStorage/index.js.map +0 -1
  272. package/presentation/router/index.js.map +0 -1
  273. package/presentation/router/types.js.map +0 -1
  274. package/router.js.map +0 -1
  275. package/types.js.map +0 -1
  276. package/utils/index.js.map +0 -1
@@ -1,227 +1,158 @@
1
- import React from "react";
1
+ import react from "react";
2
2
  import bytes from "bytes";
3
3
  import { minimatch } from "minimatch";
4
4
  import { readFileContent } from "./utils/readFileContent.js";
5
5
  import { generateId } from "./utils/generateId.js";
6
- export class Files extends React.Component {
7
- static defaultProps = {
8
- accept: [],
9
- multiple: false,
10
- maxSize: "2mb",
11
- multipleMaxSize: "10mb",
12
- multipleMaxCount: null,
13
- convertToBase64: false
14
- };
15
- input = null;
16
- browseFilesPassedParams = null;
17
- id = generateId();
18
- validateFiles = files => {
19
- const {
20
- multiple,
21
- multipleMaxSize,
22
- multipleMaxCount,
23
- accept,
24
- maxSize
25
- } = this.props;
26
- const errors = [];
27
- let multipleFileSize = 0;
28
- if (!multiple && files.length > 1) {
29
- errors.push({
30
- id: generateId(),
31
- type: "multipleNotAllowed"
32
- });
33
- return errors;
34
- }
35
- for (let index = 0; index < files.length; index++) {
36
- const file = files[index];
37
- if (Array.isArray(accept) && accept.length && !accept.some(type => minimatch(file.type, type))) {
38
- errors.push({
39
- id: generateId(),
40
- index,
41
- file,
42
- type: "unsupportedFileType"
43
- });
44
- } else if (maxSize) {
45
- const sizeAsBytes = bytes(maxSize);
46
- if (sizeAsBytes && file.size > sizeAsBytes) {
47
- errors.push({
48
- id: generateId(),
49
- index,
50
- file,
51
- type: "maxSizeExceeded"
52
- });
53
- }
54
- }
55
- if (multiple) {
56
- multipleFileSize += file.size;
57
- }
58
- }
59
- if (multiple) {
60
- const maxMultipleMaxSize = bytes(multipleMaxSize);
61
- if (maxMultipleMaxSize && multipleMaxSize && multipleFileSize > maxMultipleMaxSize) {
62
- errors.push({
63
- id: generateId(),
64
- type: "multipleMaxSizeExceeded",
65
- multipleFileSize,
66
- multipleMaxSize: maxMultipleMaxSize
67
- });
68
- }
69
- if (multipleMaxCount && files.length > multipleMaxCount) {
70
- errors.push({
71
- id: generateId(),
72
- type: "multipleMaxCountExceeded",
73
- multipleCount: files.length,
74
- multipleMaxCount
75
- });
76
- }
77
- }
78
- return errors;
79
- };
80
- processSelectedFiles = async eventFiles => {
81
- if (eventFiles.length === 0) {
82
- return;
83
- }
84
- const {
85
- convertToBase64,
86
- onSuccess,
87
- onError
88
- } = this.props;
89
- const {
90
- browseFilesPassedParams
91
- } = this;
92
- const callbacks = {
93
- onSuccess,
94
- onError
95
- };
96
- if (browseFilesPassedParams && browseFilesPassedParams.onSuccess) {
97
- callbacks.onSuccess = browseFilesPassedParams.onSuccess;
98
- }
99
- if (browseFilesPassedParams && browseFilesPassedParams.onError) {
100
- callbacks.onError = browseFilesPassedParams.onError;
101
- }
102
- const files = [...eventFiles].map(file => {
103
- return {
104
- id: generateId(),
105
- name: file.name,
106
- type: file.type,
107
- size: file.size,
108
- src: {
109
- file,
110
- base64: null
111
- }
112
- };
113
- });
114
- const errors = this.validateFiles(files);
115
- if (errors.length) {
116
- callbacks.onError && callbacks.onError(errors, files);
117
- } else {
118
- if (convertToBase64) {
119
- for (let i = 0; i < files.length; i++) {
120
- const file = files[i].src.file;
121
- files[i].src.base64 = await readFileContent(file);
122
- }
123
- }
124
- callbacks.onSuccess && callbacks.onSuccess(files);
6
+ class Files extends react.Component {
7
+ static{
8
+ this.defaultProps = {
9
+ accept: [],
10
+ multiple: false,
11
+ maxSize: "2mb",
12
+ multipleMaxSize: "10mb",
13
+ multipleMaxCount: null,
14
+ convertToBase64: false
15
+ };
125
16
  }
126
-
127
- // Reset the browseFiles arguments.
128
- if (this.input) {
129
- this.input.value = "";
17
+ render() {
18
+ const { multiple, accept, id } = this.props;
19
+ return /*#__PURE__*/ react.createElement(react.Fragment, null, this.props.children({
20
+ getLabelProps: (props)=>({
21
+ ...props,
22
+ htmlFor: id || this.id
23
+ }),
24
+ validateFiles: this.validateFiles,
25
+ browseFiles: ({ onSuccess, onError } = {})=>{
26
+ this.browseFilesHandler({
27
+ onSuccess,
28
+ onError
29
+ });
30
+ },
31
+ getDropZoneProps: ({ onSuccess, onError, onDragOver, onDrop, ...rest } = {})=>({
32
+ ...rest,
33
+ onDragOver: (e)=>{
34
+ e.preventDefault();
35
+ "function" == typeof onDragOver && onDragOver();
36
+ },
37
+ onDrop: async (e)=>{
38
+ e.preventDefault();
39
+ "function" == typeof onDrop && onDrop();
40
+ this.onDropFilesHandler({
41
+ e,
42
+ onSuccess,
43
+ onError
44
+ });
45
+ }
46
+ })
47
+ }), /*#__PURE__*/ react.createElement("input", {
48
+ id: id || this.id,
49
+ ref: (ref)=>{
50
+ if (ref) this.input = ref;
51
+ },
52
+ accept: accept.join(","),
53
+ style: {
54
+ display: "none"
55
+ },
56
+ type: "file",
57
+ multiple: multiple,
58
+ onChange: (e)=>this.processSelectedFiles(e.target.files ?? [])
59
+ }));
130
60
  }
131
- this.browseFilesPassedParams = null;
132
- };
133
-
134
- /**
135
- * Extracted into a separate method just for testing purposes.
136
- */
137
- onDropFilesHandler = async ({
138
- e,
139
- onSuccess,
140
- onError
141
- }) => {
142
- this.browseFilesPassedParams = {
143
- onSuccess,
144
- onError
145
- };
146
- e.dataTransfer && e.dataTransfer.files && (await this.processSelectedFiles(e.dataTransfer.files));
147
- };
148
-
149
- /**
150
- * Extracted into a separate method just for testing purposes.
151
- */
152
- browseFilesHandler = ({
153
- onSuccess,
154
- onError
155
- }) => {
156
- this.browseFilesPassedParams = {
157
- onSuccess,
158
- onError
159
- };
160
- this.input && this.input.click();
161
- };
162
- render() {
163
- const {
164
- multiple,
165
- accept,
166
- id
167
- } = this.props;
168
- return /*#__PURE__*/React.createElement(React.Fragment, null, this.props.children({
169
- getLabelProps: props => {
170
- return {
171
- ...props,
172
- htmlFor: id || this.id
173
- };
174
- },
175
- validateFiles: this.validateFiles,
176
- browseFiles: ({
177
- onSuccess,
178
- onError
179
- } = {}) => {
180
- this.browseFilesHandler({
181
- onSuccess,
182
- onError
183
- });
184
- },
185
- getDropZoneProps: ({
186
- onSuccess,
187
- onError,
188
- onDragOver,
189
- onDrop,
190
- ...rest
191
- } = {}) => {
192
- return {
193
- ...rest,
194
- onDragOver: e => {
195
- e.preventDefault();
196
- typeof onDragOver === "function" && onDragOver();
197
- },
198
- onDrop: async e => {
199
- e.preventDefault();
200
- typeof onDrop === "function" && onDrop();
201
- this.onDropFilesHandler({
202
- e,
203
- onSuccess,
204
- onError
205
- });
206
- }
61
+ constructor(...args){
62
+ super(...args), this.input = null, this.browseFilesPassedParams = null, this.id = generateId(), this.validateFiles = (files)=>{
63
+ const { multiple, multipleMaxSize, multipleMaxCount, accept, maxSize } = this.props;
64
+ const errors = [];
65
+ let multipleFileSize = 0;
66
+ if (!multiple && files.length > 1) {
67
+ errors.push({
68
+ id: generateId(),
69
+ type: "multipleNotAllowed"
70
+ });
71
+ return errors;
72
+ }
73
+ for(let index = 0; index < files.length; index++){
74
+ const file = files[index];
75
+ if (Array.isArray(accept) && accept.length && !accept.some((type)=>minimatch(file.type, type))) errors.push({
76
+ id: generateId(),
77
+ index,
78
+ file,
79
+ type: "unsupportedFileType"
80
+ });
81
+ else if (maxSize) {
82
+ const sizeAsBytes = bytes(maxSize);
83
+ if (sizeAsBytes && file.size > sizeAsBytes) errors.push({
84
+ id: generateId(),
85
+ index,
86
+ file,
87
+ type: "maxSizeExceeded"
88
+ });
89
+ }
90
+ if (multiple) multipleFileSize += file.size;
91
+ }
92
+ if (multiple) {
93
+ const maxMultipleMaxSize = bytes(multipleMaxSize);
94
+ if (maxMultipleMaxSize && multipleMaxSize && multipleFileSize > maxMultipleMaxSize) errors.push({
95
+ id: generateId(),
96
+ type: "multipleMaxSizeExceeded",
97
+ multipleFileSize,
98
+ multipleMaxSize: maxMultipleMaxSize
99
+ });
100
+ if (multipleMaxCount && files.length > multipleMaxCount) errors.push({
101
+ id: generateId(),
102
+ type: "multipleMaxCountExceeded",
103
+ multipleCount: files.length,
104
+ multipleMaxCount
105
+ });
106
+ }
107
+ return errors;
108
+ }, this.processSelectedFiles = async (eventFiles)=>{
109
+ if (0 === eventFiles.length) return;
110
+ const { convertToBase64, onSuccess, onError } = this.props;
111
+ const { browseFilesPassedParams } = this;
112
+ const callbacks = {
113
+ onSuccess,
114
+ onError
115
+ };
116
+ if (browseFilesPassedParams && browseFilesPassedParams.onSuccess) callbacks.onSuccess = browseFilesPassedParams.onSuccess;
117
+ if (browseFilesPassedParams && browseFilesPassedParams.onError) callbacks.onError = browseFilesPassedParams.onError;
118
+ const files = [
119
+ ...eventFiles
120
+ ].map((file)=>({
121
+ id: generateId(),
122
+ name: file.name,
123
+ type: file.type,
124
+ size: file.size,
125
+ src: {
126
+ file,
127
+ base64: null
128
+ }
129
+ }));
130
+ const errors = this.validateFiles(files);
131
+ if (errors.length) callbacks.onError && callbacks.onError(errors, files);
132
+ else {
133
+ if (convertToBase64) for(let i = 0; i < files.length; i++){
134
+ const file = files[i].src.file;
135
+ files[i].src.base64 = await readFileContent(file);
136
+ }
137
+ callbacks.onSuccess && callbacks.onSuccess(files);
138
+ }
139
+ if (this.input) this.input.value = "";
140
+ this.browseFilesPassedParams = null;
141
+ }, this.onDropFilesHandler = async ({ e, onSuccess, onError })=>{
142
+ this.browseFilesPassedParams = {
143
+ onSuccess,
144
+ onError
145
+ };
146
+ e.dataTransfer && e.dataTransfer.files && await this.processSelectedFiles(e.dataTransfer.files);
147
+ }, this.browseFilesHandler = ({ onSuccess, onError })=>{
148
+ this.browseFilesPassedParams = {
149
+ onSuccess,
150
+ onError
151
+ };
152
+ this.input && this.input.click();
207
153
  };
208
- }
209
- }), /*#__PURE__*/React.createElement("input", {
210
- id: id || this.id,
211
- ref: ref => {
212
- if (ref) {
213
- this.input = ref;
214
- }
215
- },
216
- accept: accept.join(","),
217
- style: {
218
- display: "none"
219
- },
220
- type: "file",
221
- multiple: multiple,
222
- onChange: e => this.processSelectedFiles(e.target.files ?? [])
223
- }));
224
- }
154
+ }
225
155
  }
156
+ export { Files };
226
157
 
227
158
  //# sourceMappingURL=Files.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["React","bytes","minimatch","readFileContent","generateId","Files","Component","defaultProps","accept","multiple","maxSize","multipleMaxSize","multipleMaxCount","convertToBase64","input","browseFilesPassedParams","id","validateFiles","files","props","errors","multipleFileSize","length","push","type","index","file","Array","isArray","some","sizeAsBytes","size","maxMultipleMaxSize","multipleCount","processSelectedFiles","eventFiles","onSuccess","onError","callbacks","map","name","src","base64","i","value","onDropFilesHandler","e","dataTransfer","browseFilesHandler","click","render","createElement","Fragment","children","getLabelProps","htmlFor","browseFiles","getDropZoneProps","onDragOver","onDrop","rest","preventDefault","ref","join","style","display","onChange","target"],"sources":["Files.tsx"],"sourcesContent":["import React from \"react\";\nimport bytes from \"bytes\";\nimport { minimatch } from \"minimatch\";\nimport { readFileContent } from \"./utils/readFileContent.js\";\nimport { generateId } from \"./utils/generateId.js\";\n\nexport type SelectedFile = {\n id: string;\n name: string;\n type: string;\n size: number;\n src: {\n file: File;\n base64: string | null;\n };\n};\n\nexport type FileError = {\n id: string;\n type:\n | \"unsupportedFileType\"\n | \"maxSizeExceeded\"\n | \"multipleMaxSizeExceeded\"\n | \"multipleMaxCountExceeded\"\n | \"multipleNotAllowed\";\n index?: number;\n file?: SelectedFile | File;\n multipleFileSize?: number;\n multipleMaxSize?: number;\n multipleMaxCount?: number;\n multipleCount?: number;\n};\n\nexport type BrowseFilesParams = {\n onSuccess?: (files: SelectedFile[]) => void;\n onError?: (errors: FileError[], files: SelectedFile[]) => void;\n};\n\nexport type RenderPropParams = {\n browseFiles: (params: BrowseFilesParams) => void;\n getDropZoneProps: (additionalProps: any) => any;\n getLabelProps: (additionalProps: any) => any;\n validateFiles: (files: SelectedFile[] | File[]) => FileError[];\n};\n\nexport type FilesRules = {\n accept: string[];\n multiple: boolean;\n maxSize: string;\n multipleMaxSize: string;\n multipleMaxCount: number | null;\n convertToBase64: boolean;\n onSuccess?: (files: SelectedFile[]) => void;\n onError?: (errors: FileError[], files: SelectedFile[]) => void;\n};\n\nexport type Props = FilesRules & {\n children: (params: RenderPropParams) => React.ReactNode;\n id?: string;\n};\n\nexport class Files extends React.Component<Props> {\n static defaultProps = {\n accept: [],\n multiple: false,\n maxSize: \"2mb\",\n multipleMaxSize: \"10mb\",\n multipleMaxCount: null,\n convertToBase64: false\n };\n\n input: HTMLInputElement | null = null;\n browseFilesPassedParams: BrowseFilesParams | null = null;\n id: string = generateId();\n\n validateFiles = (files: SelectedFile[] | File[]): FileError[] => {\n const { multiple, multipleMaxSize, multipleMaxCount, accept, maxSize } = this.props;\n\n const errors: FileError[] = [];\n let multipleFileSize = 0;\n\n if (!multiple && files.length > 1) {\n errors.push({\n id: generateId(),\n type: \"multipleNotAllowed\"\n });\n\n return errors;\n }\n\n for (let index = 0; index < files.length; index++) {\n const file = files[index];\n\n if (\n Array.isArray(accept) &&\n accept.length &&\n !accept.some(type => minimatch(file.type, type))\n ) {\n errors.push({\n id: generateId(),\n index,\n file,\n type: \"unsupportedFileType\"\n });\n } else if (maxSize) {\n const sizeAsBytes = bytes(maxSize);\n if (sizeAsBytes && file.size > sizeAsBytes) {\n errors.push({\n id: generateId(),\n index,\n file,\n type: \"maxSizeExceeded\"\n });\n }\n }\n\n if (multiple) {\n multipleFileSize += file.size;\n }\n }\n\n if (multiple) {\n const maxMultipleMaxSize = bytes(multipleMaxSize);\n\n if (maxMultipleMaxSize && multipleMaxSize && multipleFileSize > maxMultipleMaxSize) {\n errors.push({\n id: generateId(),\n type: \"multipleMaxSizeExceeded\",\n multipleFileSize,\n multipleMaxSize: maxMultipleMaxSize\n });\n }\n\n if (multipleMaxCount && files.length > multipleMaxCount) {\n errors.push({\n id: generateId(),\n type: \"multipleMaxCountExceeded\",\n multipleCount: files.length,\n multipleMaxCount\n });\n }\n }\n\n return errors;\n };\n\n processSelectedFiles = async (eventFiles: Array<File>) => {\n if (eventFiles.length === 0) {\n return;\n }\n\n const { convertToBase64, onSuccess, onError } = this.props;\n const { browseFilesPassedParams } = this;\n const callbacks = {\n onSuccess,\n onError\n };\n\n if (browseFilesPassedParams && browseFilesPassedParams.onSuccess) {\n callbacks.onSuccess = browseFilesPassedParams.onSuccess;\n }\n\n if (browseFilesPassedParams && browseFilesPassedParams.onError) {\n callbacks.onError = browseFilesPassedParams.onError;\n }\n\n const files: SelectedFile[] = [...eventFiles].map(file => {\n return {\n id: generateId(),\n name: file.name,\n type: file.type,\n size: file.size,\n src: {\n file,\n base64: null\n }\n };\n });\n\n const errors = this.validateFiles(files);\n\n if (errors.length) {\n callbacks.onError && callbacks.onError(errors, files);\n } else {\n if (convertToBase64) {\n for (let i = 0; i < files.length; i++) {\n const file = files[i].src.file;\n files[i].src.base64 = await readFileContent(file);\n }\n }\n\n callbacks.onSuccess && callbacks.onSuccess(files);\n }\n\n // Reset the browseFiles arguments.\n if (this.input) {\n this.input.value = \"\";\n }\n this.browseFilesPassedParams = null;\n };\n\n /**\n * Extracted into a separate method just for testing purposes.\n */\n onDropFilesHandler = async ({ e, onSuccess, onError }: any) => {\n this.browseFilesPassedParams = { onSuccess, onError };\n e.dataTransfer &&\n e.dataTransfer.files &&\n (await this.processSelectedFiles(e.dataTransfer.files));\n };\n\n /**\n * Extracted into a separate method just for testing purposes.\n */\n browseFilesHandler = ({ onSuccess, onError }: any) => {\n this.browseFilesPassedParams = { onSuccess, onError };\n this.input && this.input.click();\n };\n\n override render() {\n const { multiple, accept, id } = this.props;\n return (\n <React.Fragment>\n {this.props.children({\n getLabelProps: (props: any) => {\n return {\n ...props,\n htmlFor: id || this.id\n };\n },\n validateFiles: this.validateFiles,\n browseFiles: ({ onSuccess, onError }: BrowseFilesParams = {}) => {\n this.browseFilesHandler({ onSuccess, onError });\n },\n getDropZoneProps: ({\n onSuccess,\n onError,\n onDragOver,\n onDrop,\n ...rest\n }: any = {}) => {\n return {\n ...rest,\n onDragOver: (e: DragEvent) => {\n e.preventDefault();\n typeof onDragOver === \"function\" && onDragOver();\n },\n onDrop: async (e: DragEvent) => {\n e.preventDefault();\n typeof onDrop === \"function\" && onDrop();\n this.onDropFilesHandler({ e, onSuccess, onError });\n }\n };\n }\n })}\n\n <input\n id={id || this.id}\n ref={ref => {\n if (ref) {\n this.input = ref;\n }\n }}\n accept={accept.join(\",\")}\n style={{ display: \"none\" }}\n type=\"file\"\n multiple={multiple}\n onChange={e =>\n this.processSelectedFiles((e.target.files as any as Array<File>) ?? [])\n }\n />\n </React.Fragment>\n );\n }\n}\n"],"mappings":"AAAA,OAAOA,KAAK,MAAM,OAAO;AACzB,OAAOC,KAAK,MAAM,OAAO;AACzB,SAASC,SAAS,QAAQ,WAAW;AACrC,SAASC,eAAe;AACxB,SAASC,UAAU;AAyDnB,OAAO,MAAMC,KAAK,SAASL,KAAK,CAACM,SAAS,CAAQ;EAC9C,OAAOC,YAAY,GAAG;IAClBC,MAAM,EAAE,EAAE;IACVC,QAAQ,EAAE,KAAK;IACfC,OAAO,EAAE,KAAK;IACdC,eAAe,EAAE,MAAM;IACvBC,gBAAgB,EAAE,IAAI;IACtBC,eAAe,EAAE;EACrB,CAAC;EAEDC,KAAK,GAA4B,IAAI;EACrCC,uBAAuB,GAA6B,IAAI;EACxDC,EAAE,GAAWZ,UAAU,CAAC,CAAC;EAEzBa,aAAa,GAAIC,KAA8B,IAAkB;IAC7D,MAAM;MAAET,QAAQ;MAAEE,eAAe;MAAEC,gBAAgB;MAAEJ,MAAM;MAAEE;IAAQ,CAAC,GAAG,IAAI,CAACS,KAAK;IAEnF,MAAMC,MAAmB,GAAG,EAAE;IAC9B,IAAIC,gBAAgB,GAAG,CAAC;IAExB,IAAI,CAACZ,QAAQ,IAAIS,KAAK,CAACI,MAAM,GAAG,CAAC,EAAE;MAC/BF,MAAM,CAACG,IAAI,CAAC;Q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AAG,EAAEA,GAAG,IAAI;QACR,IAAIA,GAAG,EAAE;UACL,IAAI,CAAChD,KAAK,GAAGgD,GAAG;QACpB;MACJ,CAAE;MACFtD,MAAM,EAAEA,MAAM,CAACuD,IAAI,CAAC,GAAG,CAAE;MACzBC,KAAK,EAAE;QAAEC,OAAO,EAAE;MAAO,CAAE;MAC3BzC,IAAI,EAAC,MAAM;MACXf,QAAQ,EAAEA,QAAS;MACnByD,QAAQ,EAAEpB,CAAC,IACP,IAAI,CAACZ,oBAAoB,CAAEY,CAAC,CAACqB,MAAM,CAACjD,KAAK,IAA2B,EAAE;IACzE,CACJ,CACW,CAAC;EAEzB;AACJ","ignoreList":[]}
1
+ {"version":3,"file":"react-butterfiles/Files.js","sources":["../../src/react-butterfiles/Files.tsx"],"sourcesContent":["import React from \"react\";\nimport bytes from \"bytes\";\nimport { minimatch } from \"minimatch\";\nimport { readFileContent } from \"./utils/readFileContent.js\";\nimport { generateId } from \"./utils/generateId.js\";\n\nexport type SelectedFile = {\n id: string;\n name: string;\n type: string;\n size: number;\n src: {\n file: File;\n base64: string | null;\n };\n};\n\nexport type FileError = {\n id: string;\n type:\n | \"unsupportedFileType\"\n | \"maxSizeExceeded\"\n | \"multipleMaxSizeExceeded\"\n | \"multipleMaxCountExceeded\"\n | \"multipleNotAllowed\";\n index?: number;\n file?: SelectedFile | File;\n multipleFileSize?: number;\n multipleMaxSize?: number;\n multipleMaxCount?: number;\n multipleCount?: number;\n};\n\nexport type BrowseFilesParams = {\n onSuccess?: (files: SelectedFile[]) => void;\n onError?: (errors: FileError[], files: SelectedFile[]) => void;\n};\n\nexport type RenderPropParams = {\n browseFiles: (params: BrowseFilesParams) => void;\n getDropZoneProps: (additionalProps: any) => any;\n getLabelProps: (additionalProps: any) => any;\n validateFiles: (files: SelectedFile[] | File[]) => FileError[];\n};\n\nexport type FilesRules = {\n accept: string[];\n multiple: boolean;\n maxSize: string;\n multipleMaxSize: string;\n multipleMaxCount: number | null;\n convertToBase64: boolean;\n onSuccess?: (files: SelectedFile[]) => void;\n onError?: (errors: FileError[], files: SelectedFile[]) => void;\n};\n\nexport type Props = FilesRules & {\n children: (params: RenderPropParams) => React.ReactNode;\n id?: string;\n};\n\nexport class Files extends React.Component<Props> {\n static defaultProps = {\n accept: [],\n multiple: false,\n maxSize: \"2mb\",\n multipleMaxSize: \"10mb\",\n multipleMaxCount: null,\n convertToBase64: false\n };\n\n input: HTMLInputElement | null = null;\n browseFilesPassedParams: BrowseFilesParams | null = null;\n id: string = generateId();\n\n validateFiles = (files: SelectedFile[] | File[]): FileError[] => {\n const { multiple, multipleMaxSize, multipleMaxCount, accept, maxSize } = this.props;\n\n const errors: FileError[] = [];\n let multipleFileSize = 0;\n\n if (!multiple && files.length > 1) {\n errors.push({\n id: generateId(),\n type: \"multipleNotAllowed\"\n });\n\n return errors;\n }\n\n for (let index = 0; index < files.length; index++) {\n const file = files[index];\n\n if (\n Array.isArray(accept) &&\n accept.length &&\n !accept.some(type => minimatch(file.type, type))\n ) {\n errors.push({\n id: generateId(),\n index,\n file,\n type: \"unsupportedFileType\"\n });\n } else if (maxSize) {\n const sizeAsBytes = bytes(maxSize);\n if (sizeAsBytes && file.size > sizeAsBytes) {\n errors.push({\n id: generateId(),\n index,\n file,\n type: \"maxSizeExceeded\"\n });\n }\n }\n\n if (multiple) {\n multipleFileSize += file.size;\n }\n }\n\n if (multiple) {\n const maxMultipleMaxSize = bytes(multipleMaxSize);\n\n if (maxMultipleMaxSize && multipleMaxSize && multipleFileSize > maxMultipleMaxSize) {\n errors.push({\n id: generateId(),\n type: \"multipleMaxSizeExceeded\",\n multipleFileSize,\n multipleMaxSize: maxMultipleMaxSize\n });\n }\n\n if (multipleMaxCount && files.length > multipleMaxCount) {\n errors.push({\n id: generateId(),\n type: \"multipleMaxCountExceeded\",\n multipleCount: files.length,\n multipleMaxCount\n });\n }\n }\n\n return errors;\n };\n\n processSelectedFiles = async (eventFiles: Array<File>) => {\n if (eventFiles.length === 0) {\n return;\n }\n\n const { convertToBase64, onSuccess, onError } = this.props;\n const { browseFilesPassedParams } = this;\n const callbacks = {\n onSuccess,\n onError\n };\n\n if (browseFilesPassedParams && browseFilesPassedParams.onSuccess) {\n callbacks.onSuccess = browseFilesPassedParams.onSuccess;\n }\n\n if (browseFilesPassedParams && browseFilesPassedParams.onError) {\n callbacks.onError = browseFilesPassedParams.onError;\n }\n\n const files: SelectedFile[] = [...eventFiles].map(file => {\n return {\n id: generateId(),\n name: file.name,\n type: file.type,\n size: file.size,\n src: {\n file,\n base64: null\n }\n };\n });\n\n const errors = this.validateFiles(files);\n\n if (errors.length) {\n callbacks.onError && callbacks.onError(errors, files);\n } else {\n if (convertToBase64) {\n for (let i = 0; i < files.length; i++) {\n const file = files[i].src.file;\n files[i].src.base64 = await readFileContent(file);\n }\n }\n\n callbacks.onSuccess && callbacks.onSuccess(files);\n }\n\n // Reset the browseFiles arguments.\n if (this.input) {\n this.input.value = \"\";\n }\n this.browseFilesPassedParams = null;\n };\n\n /**\n * Extracted into a separate method just for testing purposes.\n */\n onDropFilesHandler = async ({ e, onSuccess, onError }: any) => {\n this.browseFilesPassedParams = { onSuccess, onError };\n e.dataTransfer &&\n e.dataTransfer.files &&\n (await this.processSelectedFiles(e.dataTransfer.files));\n };\n\n /**\n * Extracted into a separate method just for testing purposes.\n */\n browseFilesHandler = ({ onSuccess, onError }: any) => {\n this.browseFilesPassedParams = { onSuccess, onError };\n this.input && this.input.click();\n };\n\n override render() {\n const { multiple, accept, id } = this.props;\n return (\n <React.Fragment>\n {this.props.children({\n getLabelProps: (props: any) => {\n return {\n ...props,\n htmlFor: id || this.id\n };\n },\n validateFiles: this.validateFiles,\n browseFiles: ({ onSuccess, onError }: BrowseFilesParams = {}) => {\n this.browseFilesHandler({ onSuccess, onError });\n },\n getDropZoneProps: ({\n onSuccess,\n onError,\n onDragOver,\n onDrop,\n ...rest\n }: any = {}) => {\n return {\n ...rest,\n onDragOver: (e: DragEvent) => {\n e.preventDefault();\n typeof onDragOver === \"function\" && onDragOver();\n },\n onDrop: async (e: DragEvent) => {\n e.preventDefault();\n typeof onDrop === \"function\" && onDrop();\n this.onDropFilesHandler({ e, onSuccess, onError });\n }\n };\n }\n })}\n\n <input\n id={id || this.id}\n ref={ref => {\n if (ref) {\n this.input = ref;\n }\n }}\n accept={accept.join(\",\")}\n style={{ display: \"none\" }}\n type=\"file\"\n multiple={multiple}\n onChange={e =>\n this.processSelectedFiles((e.target.files as any as Array<File>) ?? [])\n }\n />\n </React.Fragment>\n );\n }\n}\n"],"names":["Files","React","multiple","accept","id","props","onSuccess","onError","onDragOver","onDrop","rest","e","ref","generateId","files","multipleMaxSize","multipleMaxCount","maxSize","errors","multipleFileSize","index","file","Array","type","minimatch","sizeAsBytes","bytes","maxMultipleMaxSize","eventFiles","convertToBase64","browseFilesPassedParams","callbacks","i","readFileContent"],"mappings":";;;;;AA6DO,MAAMA,cAAcC,MAAAA,SAAe;;aAC/B,YAAY,GAAG;YAClB,QAAQ,EAAE;YACV,UAAU;YACV,SAAS;YACT,iBAAiB;YACjB,kBAAkB;YAClB,iBAAiB;QACrB;;IAsJS,SAAS;QACd,MAAM,EAAEC,QAAQ,EAAEC,MAAM,EAAEC,EAAE,EAAE,GAAG,IAAI,CAAC,KAAK;QAC3C,OAAO,WAAP,GACI,oBAACH,MAAAA,QAAc,QACV,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC;YACjB,eAAe,CAACI,QACL;oBACH,GAAGA,KAAK;oBACR,SAASD,MAAM,IAAI,CAAC,EAAE;gBAC1B;YAEJ,eAAe,IAAI,CAAC,aAAa;YACjC,aAAa,CAAC,EAAEE,SAAS,EAAEC,OAAO,EAAqB,GAAG,CAAC,CAAC;gBACxD,IAAI,CAAC,kBAAkB,CAAC;oBAAED;oBAAWC;gBAAQ;YACjD;YACA,kBAAkB,CAAC,EACfD,SAAS,EACTC,OAAO,EACPC,UAAU,EACVC,MAAM,EACN,GAAGC,MACD,GAAG,CAAC,CAAC,GACA;o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I,CAAC,aAAa,CAACJ;YAElC,IAAII,OAAO,MAAM,EACba,UAAU,OAAO,IAAIA,UAAU,OAAO,CAACb,QAAQJ;iBAC5C;gBACH,IAAIe,iBACA,IAAK,IAAIG,IAAI,GAAGA,IAAIlB,MAAM,MAAM,EAAEkB,IAAK;oBACnC,MAAMX,OAAOP,KAAK,CAACkB,EAAE,CAAC,GAAG,CAAC,IAAI;oBAC9BlB,KAAK,CAACkB,EAAE,CAAC,GAAG,CAAC,MAAM,GAAG,MAAMC,gBAAgBZ;gBAChD;gBAGJU,UAAU,SAAS,IAAIA,UAAU,SAAS,CAACjB;YAC/C;YAGA,IAAI,IAAI,CAAC,KAAK,EACV,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG;YAEvB,IAAI,CAAC,uBAAuB,GAAG;QACnC,GAIC,KACD,kBAAkB,GAAG,OAAO,EAAEH,CAAC,EAAEL,SAAS,EAAEC,OAAO,EAAO;YACtD,IAAI,CAAC,uBAAuB,GAAG;gBAAED;gBAAWC;YAAQ;YACpDI,EAAE,YAAY,IACVA,EAAE,YAAY,CAAC,KAAK,IACnB,MAAM,IAAI,CAAC,oBAAoB,CAACA,EAAE,YAAY,CAAC,KAAK;QAC7D,GAIC,KACD,kBAAkB,GAAG,CAAC,EAAEL,SAAS,EAAEC,OAAO,EAAO;YAC7C,IAAI,CAAC,uBAAuB,GAAG;gBAAED;gBAAWC;YAAQ;YACpD,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,KAAK;QAClC;;AAyDJ"}
@@ -1,4 +1,5 @@
1
1
  import { Files } from "./Files.js";
2
- export default Files;
2
+ const react_butterfiles = Files;
3
+ export default react_butterfiles;
3
4
 
4
5
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["Files"],"sources":["index.ts"],"sourcesContent":["import { Files } from \"./Files.js\";\n\nexport default Files;\n"],"mappings":"AAAA,SAASA,KAAK;AAEd,eAAeA,KAAK","ignoreList":[]}
1
+ {"version":3,"file":"react-butterfiles/index.js","sources":["../../src/react-butterfiles/index.ts"],"sourcesContent":["import { Files } from \"./Files.js\";\n\nexport default Files;\n"],"names":["Files"],"mappings":";AAEA,0BAAeA"}
@@ -1,5 +1,4 @@
1
- export const generateId = () => {
2
- return "_" + Math.random().toString(36).substr(2, 9);
3
- };
1
+ const generateId = ()=>"_" + Math.random().toString(36).substr(2, 9);
2
+ export { generateId };
4
3
 
5
4
  //# sourceMappingURL=generateId.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["generateId","Math","random","toString","substr"],"sources":["generateId.ts"],"sourcesContent":["export const generateId = () => {\n return \"_\" + Math.random().toString(36).substr(2, 9);\n};\n"],"mappings":"AAAA,OAAO,MAAMA,UAAU,GAAGA,CAAA,KAAM;EAC5B,OAAO,GAAG,GAAGC,IAAI,CAACC,MAAM,CAAC,CAAC,CAACC,QAAQ,CAAC,EAAE,CAAC,CAACC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC;AACxD,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"react-butterfiles/utils/generateId.js","sources":["../../../src/react-butterfiles/utils/generateId.ts"],"sourcesContent":["export const generateId = () => {\n return \"_\" + Math.random().toString(36).substr(2, 9);\n};\n"],"names":["generateId","Math"],"mappings":"AAAO,MAAMA,aAAa,IACf,MAAMC,KAAK,MAAM,GAAG,QAAQ,CAAC,IAAI,MAAM,CAAC,GAAG"}
@@ -1,15 +1,11 @@
1
- export const readFileContent = async file => {
2
- return new Promise((resolve, reject) => {
3
- const reader = new window.FileReader();
4
- reader.onload = function (e) {
5
- if (e.target) {
6
- resolve(e.target.result);
7
- } else {
8
- reject(`Unable to read file contents!`);
9
- }
10
- };
11
- reader.readAsDataURL(file);
12
- });
13
- };
1
+ const readFileContent = async (file)=>new Promise((resolve, reject)=>{
2
+ const reader = new window.FileReader();
3
+ reader.onload = function(e) {
4
+ if (e.target) resolve(e.target.result);
5
+ else reject("Unable to read file contents!");
6
+ };
7
+ reader.readAsDataURL(file);
8
+ });
9
+ export { readFileContent };
14
10
 
15
11
  //# sourceMappingURL=readFileContent.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["readFileContent","file","Promise","resolve","reject","reader","window","FileReader","onload","e","target","result","readAsDataURL"],"sources":["readFileContent.ts"],"sourcesContent":["export const readFileContent = async (file: File) => {\n return new Promise<string>((resolve, reject) => {\n const reader = new window.FileReader();\n reader.onload = function (e) {\n if (e.target) {\n resolve(e.target.result as string);\n } else {\n reject(`Unable to read file contents!`);\n }\n };\n\n reader.readAsDataURL(file);\n });\n};\n"],"mappings":"AAAA,OAAO,MAAMA,eAAe,GAAG,MAAOC,IAAU,IAAK;EACjD,OAAO,IAAIC,OAAO,CAAS,CAACC,OAAO,EAAEC,MAAM,KAAK;IAC5C,MAAMC,MAAM,GAAG,IAAIC,MAAM,CAACC,UAAU,CAAC,CAAC;IACtCF,MAAM,CAACG,MAAM,GAAG,UAAUC,CAAC,EAAE;MACzB,IAAIA,CAAC,CAACC,MAAM,EAAE;QACVP,OAAO,CAACM,CAAC,CAACC,MAAM,CAACC,MAAgB,CAAC;MACtC,CAAC,MAAM;QACHP,MAAM,CAAC,+BAA+B,CAAC;MAC3C;IACJ,CAAC;IAEDC,MAAM,CAACO,aAAa,CAACX,IAAI,CAAC;EAC9B,CAAC,CAAC;AACN,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"react-butterfiles/utils/readFileContent.js","sources":["../../../src/react-butterfiles/utils/readFileContent.ts"],"sourcesContent":["export const readFileContent = async (file: File) => {\n return new Promise<string>((resolve, reject) => {\n const reader = new window.FileReader();\n reader.onload = function (e) {\n if (e.target) {\n resolve(e.target.result as string);\n } else {\n reject(`Unable to read file contents!`);\n }\n };\n\n reader.readAsDataURL(file);\n });\n};\n"],"names":["readFileContent","file","Promise","resolve","reject","reader","window","e"],"mappings":"AAAO,MAAMA,kBAAkB,OAAOC,OAC3B,IAAIC,QAAgB,CAACC,SAASC;QACjC,MAAMC,SAAS,IAAIC,OAAO,UAAU;QACpCD,OAAO,MAAM,GAAG,SAAUE,CAAC;YACvB,IAAIA,EAAE,MAAM,EACRJ,QAAQI,EAAE,MAAM,CAAC,MAAM;iBAEvBH,OAAO;QAEf;QAEAC,OAAO,aAAa,CAACJ;IACzB"}
package/renderApp.js CHANGED
@@ -1,9 +1,10 @@
1
- import ReactDOMClient from "react-dom/client";
2
- export const renderApp = app => {
3
- const container = document.getElementById("root");
4
- const root = ReactDOMClient.createRoot(container);
5
- root.render(app);
6
- return root;
1
+ import client from "react-dom/client";
2
+ const renderApp = (app)=>{
3
+ const container = document.getElementById("root");
4
+ const root = client.createRoot(container);
5
+ root.render(app);
6
+ return root;
7
7
  };
8
+ export { renderApp };
8
9
 
9
10
  //# sourceMappingURL=renderApp.js.map
package/renderApp.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["ReactDOMClient","renderApp","app","container","document","getElementById","root","createRoot","render"],"sources":["renderApp.tsx"],"sourcesContent":["import type { Root } from \"react-dom/client\";\nimport ReactDOMClient from \"react-dom/client\";\n\nexport const renderApp = (app: React.JSX.Element): Root => {\n const container = document.getElementById(\"root\")!;\n\n const root = ReactDOMClient.createRoot(container);\n root.render(app);\n return root;\n};\n"],"mappings":"AACA,OAAOA,cAAc,MAAM,kBAAkB;AAE7C,OAAO,MAAMC,SAAS,GAAIC,GAAsB,IAAW;EACvD,MAAMC,SAAS,GAAGC,QAAQ,CAACC,cAAc,CAAC,MAAM,CAAE;EAElD,MAAMC,IAAI,GAAGN,cAAc,CAACO,UAAU,CAACJ,SAAS,CAAC;EACjDG,IAAI,CAACE,MAAM,CAACN,GAAG,CAAC;EAChB,OAAOI,IAAI;AACf,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"renderApp.js","sources":["../src/renderApp.tsx"],"sourcesContent":["import type { Root } from \"react-dom/client\";\nimport ReactDOMClient from \"react-dom/client\";\n\nexport const renderApp = (app: React.JSX.Element): Root => {\n const container = document.getElementById(\"root\")!;\n\n const root = ReactDOMClient.createRoot(container);\n root.render(app);\n return root;\n};\n"],"names":["renderApp","app","container","document","root","ReactDOMClient"],"mappings":";AAGO,MAAMA,YAAY,CAACC;IACtB,MAAMC,YAAYC,SAAS,cAAc,CAAC;IAE1C,MAAMC,OAAOC,OAAAA,UAAyB,CAACH;IACvCE,KAAK,MAAM,CAACH;IACZ,OAAOG;AACX"}
package/router.js CHANGED
@@ -1,8 +1,5 @@
1
- // Router
2
1
  export { Route } from "./features/router/Route.js";
3
2
  export { useRouter } from "./presentation/router/hooks/useRouter.js";
4
3
  export { useRoute } from "./presentation/router/hooks/useRoute.js";
5
4
  export { RouteLink } from "./presentation/router/components/RouteLink.js";
6
5
  export { SimpleLink } from "./presentation/router/components/SimpleLink.js";
7
-
8
- //# sourceMappingURL=router.js.map
@@ -0,0 +1,14 @@
1
+ var __webpack_require__ = {};
2
+ (()=>{
3
+ __webpack_require__.g = (()=>{
4
+ if ('object' == typeof globalThis) return globalThis;
5
+ try {
6
+ return this || new Function('return this')();
7
+ } catch (e) {
8
+ if ('object' == typeof window) return window;
9
+ }
10
+ })();
11
+ })();
12
+ export { __webpack_require__ };
13
+
14
+ //# sourceMappingURL=rslib-runtime.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rslib-runtime.js","sources":["webpack://webpack/runtime/global"],"sourcesContent":["__webpack_require__.g = (() => {\n\tif (typeof globalThis === 'object') return globalThis;\n\ttry {\n\t\treturn this || new Function('return this')();\n\t} catch (e) {\n\t\tif (typeof window === 'object') return window;\n\t}\n})();"],"names":["__webpack_require__","globalThis","Function","e","window"],"mappings":";;IAAAA,oBAAoB,CAAC,GAAG,AAAC;QACxB,IAAI,AAAsB,YAAtB,OAAOC,YAAyB,OAAOA;QAC3C,IAAI;YACH,OAAO,IAAI,IAAI,IAAIC,SAAS;QAC7B,EAAE,OAAOC,GAAG;YACX,IAAI,AAAkB,YAAlB,OAAOC,QAAqB,OAAOA;QACxC;IACD"}
@@ -1,17 +1,13 @@
1
- import React from "react";
1
+ import react from "react";
2
2
  import { createGenericContext } from "../../utils/createGenericContext.js";
3
3
  const DiContainerContext = createGenericContext("DiContainer");
4
- export const DiContainerProvider = ({
5
- container,
6
- children
7
- }) => {
8
- return /*#__PURE__*/React.createElement(DiContainerContext.Provider, {
9
- container: container
10
- }, children);
11
- };
12
- export const useContainer = () => {
13
- const context = DiContainerContext.useHook();
14
- return context.container;
4
+ const DiContainerProvider = ({ container, children })=>/*#__PURE__*/ react.createElement(DiContainerContext.Provider, {
5
+ container: container
6
+ }, children);
7
+ const useContainer = ()=>{
8
+ const context = DiContainerContext.useHook();
9
+ return context.container;
15
10
  };
11
+ export { DiContainerProvider, useContainer };
16
12
 
17
13
  //# sourceMappingURL=DiContainerProvider.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["React","createGenericContext","DiContainerContext","DiContainerProvider","container","children","createElement","Provider","useContainer","context","useHook"],"sources":["DiContainerProvider.tsx"],"sourcesContent":["import React from \"react\";\nimport { Container } from \"@webiny/di\";\nimport { createGenericContext } from \"~/utils/createGenericContext.js\";\n\ntype DiContainerContext = { container: Container };\n\nconst DiContainerContext = createGenericContext<DiContainerContext>(\"DiContainer\");\n\nexport interface DiContainerProviderProps {\n container: Container;\n children: React.ReactNode;\n}\n\nexport const DiContainerProvider = ({ container, children }: DiContainerProviderProps) => {\n return (\n <DiContainerContext.Provider container={container}>{children}</DiContainerContext.Provider>\n );\n};\n\nexport const useContainer = () => {\n const context = DiContainerContext.useHook();\n\n return context.container;\n};\n"],"mappings":"AAAA,OAAOA,KAAK,MAAM,OAAO;AAEzB,SAASC,oBAAoB;AAI7B,MAAMC,kBAAkB,GAAGD,oBAAoB,CAAqB,aAAa,CAAC;AAOlF,OAAO,MAAME,mBAAmB,GAAGA,CAAC;EAAEC,SAAS;EAAEC;AAAmC,CAAC,KAAK;EACtF,oBACIL,KAAA,CAAAM,aAAA,CAACJ,kBAAkB,CAACK,QAAQ;IAACH,SAAS,EAAEA;EAAU,GAAEC,QAAsC,CAAC;AAEnG,CAAC;AAED,OAAO,MAAMG,YAAY,GAAGA,CAAA,KAAM;EAC9B,MAAMC,OAAO,GAAGP,kBAAkB,CAACQ,OAAO,CAAC,CAAC;EAE5C,OAAOD,OAAO,CAACL,SAAS;AAC5B,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"shared/di/DiContainerProvider.js","sources":["../../../src/shared/di/DiContainerProvider.tsx"],"sourcesContent":["import React from \"react\";\nimport { Container } from \"@webiny/di\";\nimport { createGenericContext } from \"~/utils/createGenericContext.js\";\n\ntype DiContainerContext = { container: Container };\n\nconst DiContainerContext = createGenericContext<DiContainerContext>(\"DiContainer\");\n\nexport interface DiContainerProviderProps {\n container: Container;\n children: React.ReactNode;\n}\n\nexport const DiContainerProvider = ({ container, children }: DiContainerProviderProps) => {\n return (\n <DiContainerContext.Provider container={container}>{children}</DiContainerContext.Provider>\n );\n};\n\nexport const useContainer = () => {\n const context = DiContainerContext.useHook();\n\n return context.container;\n};\n"],"names":["DiContainerContext","createGenericContext","DiContainerProvider","container","children","useContainer","context"],"mappings":";;AAMA,MAAMA,qBAAqBC,qBAAyC;AAO7D,MAAMC,sBAAsB,CAAC,EAAEC,SAAS,EAAEC,QAAQ,EAA4B,GAC1E,WAAP,GACI,oBAACJ,mBAAmB,QAAQ;QAAC,WAAWG;OAAYC;AAIrD,MAAMC,eAAe;IACxB,MAAMC,UAAUN,mBAAmB,OAAO;IAE1C,OAAOM,QAAQ,SAAS;AAC5B"}
@@ -1,11 +1,10 @@
1
- export function createFeature(def) {
2
- return {
3
- name: def.name,
4
- register: def.register,
5
- resolve: container => {
6
- return def.resolve(container);
7
- }
8
- };
1
+ function createFeature(def) {
2
+ return {
3
+ name: def.name,
4
+ register: def.register,
5
+ resolve: (container)=>def.resolve(container)
6
+ };
9
7
  }
8
+ export { createFeature };
10
9
 
11
10
  //# sourceMappingURL=createFeature.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["createFeature","def","name","register","resolve","container"],"sources":["createFeature.ts"],"sourcesContent":["import { Container } from \"@webiny/di\";\n\nexport interface FeatureDefinition<TExports = any, TParams extends any[] = []> {\n name: string;\n register: (container: Container, ...args: TParams) => void;\n resolve: (container: Container) => TExports;\n}\n\nexport function createFeature<\n TExports = any,\n TParams extends any[] = [] // tuple for extra args\n>(def: {\n name: string;\n register: (container: Container, ...args: TParams) => void;\n resolve: (container: Container) => TExports;\n}): FeatureDefinition<TExports, TParams> {\n return {\n name: def.name,\n register: def.register,\n resolve: (container: Container): TExports => {\n return def.resolve(container);\n }\n };\n}\n"],"mappings":"AAQA,OAAO,SAASA,aAAaA,CAG3BC,GAID,EAAwC;EACrC,OAAO;IACHC,IAAI,EAAED,GAAG,CAACC,IAAI;IACdC,QAAQ,EAAEF,GAAG,CAACE,QAAQ;IACtBC,OAAO,EAAGC,SAAoB,IAAe;MACzC,OAAOJ,GAAG,CAACG,OAAO,CAACC,SAAS,CAAC;IACjC;EACJ,CAAC;AACL","ignoreList":[]}
1
+ {"version":3,"file":"shared/di/createFeature.js","sources":["../../../src/shared/di/createFeature.ts"],"sourcesContent":["import { Container } from \"@webiny/di\";\n\nexport interface FeatureDefinition<TExports = any, TParams extends any[] = []> {\n name: string;\n register: (container: Container, ...args: TParams) => void;\n resolve: (container: Container) => TExports;\n}\n\nexport function createFeature<\n TExports = any,\n TParams extends any[] = [] // tuple for extra args\n>(def: {\n name: string;\n register: (container: Container, ...args: TParams) => void;\n resolve: (container: Container) => TExports;\n}): FeatureDefinition<TExports, TParams> {\n return {\n name: def.name,\n register: def.register,\n resolve: (container: Container): TExports => {\n return def.resolve(container);\n }\n };\n}\n"],"names":["createFeature","def","container"],"mappings":"AAQO,SAASA,cAGdC,GAID;IACG,OAAO;QACH,MAAMA,IAAI,IAAI;QACd,UAAUA,IAAI,QAAQ;QACtB,SAAS,CAACC,YACCD,IAAI,OAAO,CAACC;IAE3B;AACJ"}