@webiny/app 6.3.0 → 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.
- package/App.js +70 -77
- package/App.js.map +1 -1
- package/AppContainer.js +3 -6
- package/AppContainer.js.map +1 -1
- package/apollo-client/InMemoryCache.js +11 -13
- package/apollo-client/InMemoryCache.js.map +1 -1
- package/apollo-client/IntrospectionFragmentMatcher.js +26 -38
- package/apollo-client/IntrospectionFragmentMatcher.js.map +1 -1
- package/components/Image.js +11 -17
- package/components/Image.js.map +1 -1
- package/components/index.js +0 -2
- package/config/RouterConfig/Route.js +23 -28
- package/config/RouterConfig/Route.js.map +1 -1
- package/config/RouterConfig.js +11 -10
- package/config/RouterConfig.js.map +1 -1
- package/config.js +19 -20
- package/config.js.map +1 -1
- package/contexts/Ui/index.js +26 -28
- package/contexts/Ui/index.js.map +1 -1
- package/core/Plugin.js +7 -9
- package/core/Plugin.js.map +1 -1
- package/core/Plugins.js +15 -34
- package/core/Plugins.js.map +1 -1
- package/core/Provider.js +5 -13
- package/core/Provider.js.map +1 -1
- package/core/createProvider.js +3 -6
- package/core/createProvider.js.map +1 -1
- package/core/createProviderPlugin.js +8 -13
- package/core/createProviderPlugin.js.map +1 -1
- package/errors/AuthenticationErrorEvent.js +8 -5
- package/errors/AuthenticationErrorEvent.js.map +1 -1
- package/errors/NetworkErrorEvent.js +8 -5
- package/errors/NetworkErrorEvent.js.map +1 -1
- package/errors/abstractions.js +3 -2
- package/errors/abstractions.js.map +1 -1
- package/errors/index.js +1 -4
- package/exports/admin/env-config.js +0 -2
- package/exports/admin/graphql-client.js +0 -2
- package/exports/admin/local-storage.js +0 -2
- package/exports/admin/router.js +0 -2
- package/exports/admin/security.js +0 -2
- package/exports/admin.js +0 -2
- package/features/envConfig/EnvConfig.js +12 -13
- package/features/envConfig/EnvConfig.js.map +1 -1
- package/features/envConfig/abstractions.js +2 -1
- package/features/envConfig/abstractions.js.map +1 -1
- package/features/envConfig/feature.js +9 -8
- package/features/envConfig/feature.js.map +1 -1
- package/features/envConfig/index.js +0 -2
- package/features/eventPublisher/EventPublisher.js +13 -21
- package/features/eventPublisher/EventPublisher.js.map +1 -1
- package/features/eventPublisher/abstractions.js +7 -9
- package/features/eventPublisher/abstractions.js.map +1 -1
- package/features/eventPublisher/feature.js +13 -12
- package/features/eventPublisher/feature.js.map +1 -1
- package/features/eventPublisher/index.js +1 -3
- package/features/graphqlClient/AuthenticationErrorPublishing.js +26 -26
- package/features/graphqlClient/AuthenticationErrorPublishing.js.map +1 -1
- package/features/graphqlClient/BatchingGraphQLClient.js +104 -149
- package/features/graphqlClient/BatchingGraphQLClient.js.map +1 -1
- package/features/graphqlClient/FetchGraphQLClient.js +41 -48
- package/features/graphqlClient/FetchGraphQLClient.js.map +1 -1
- package/features/graphqlClient/NetworkErrorPublishing.js +35 -42
- package/features/graphqlClient/NetworkErrorPublishing.js.map +1 -1
- package/features/graphqlClient/RequestValue.js +42 -41
- package/features/graphqlClient/RequestValue.js.map +1 -1
- package/features/graphqlClient/RetryGraphQLClient.js +36 -45
- package/features/graphqlClient/RetryGraphQLClient.js.map +1 -1
- package/features/graphqlClient/__tests__/GraphQLClient.test.js +383 -356
- package/features/graphqlClient/__tests__/GraphQLClient.test.js.map +1 -1
- package/features/graphqlClient/abstractions.js +2 -1
- package/features/graphqlClient/abstractions.js.map +1 -1
- package/features/graphqlClient/feature.js +14 -20
- package/features/graphqlClient/feature.js.map +1 -1
- package/features/graphqlClient/index.js +0 -2
- package/features/graphqlClient/types.js +0 -3
- package/features/localStorage/BrowserLocalStorageGateway.js +56 -63
- package/features/localStorage/BrowserLocalStorageGateway.js.map +1 -1
- package/features/localStorage/LocalStorage.js +27 -24
- package/features/localStorage/LocalStorage.js.map +1 -1
- package/features/localStorage/LocalStorageRepository.js +75 -88
- package/features/localStorage/LocalStorageRepository.js.map +1 -1
- package/features/localStorage/abstractions.js +5 -16
- package/features/localStorage/abstractions.js.map +1 -1
- package/features/localStorage/feature.js +17 -28
- package/features/localStorage/feature.js.map +1 -1
- package/features/localStorage/index.js +1 -3
- package/features/mainGraphQLClient/MainGraphQLClient.js +18 -14
- package/features/mainGraphQLClient/MainGraphQLClient.js.map +1 -1
- package/features/mainGraphQLClient/abstractions.js +2 -1
- package/features/mainGraphQLClient/abstractions.js.map +1 -1
- package/features/mainGraphQLClient/feature.js +11 -10
- package/features/mainGraphQLClient/feature.js.map +1 -1
- package/features/mainGraphQLClient/index.js +0 -2
- package/features/router/HistoryRouterGateway.js +75 -105
- package/features/router/HistoryRouterGateway.js.map +1 -1
- package/features/router/HistoryRouterGateway.test.js +184 -193
- package/features/router/HistoryRouterGateway.test.js.map +1 -1
- package/features/router/Route.js +38 -54
- package/features/router/Route.js.map +1 -1
- package/features/router/RouteUrl.js +84 -217
- package/features/router/RouteUrl.js.map +1 -1
- package/features/router/Router.js +67 -124
- package/features/router/Router.js.map +1 -1
- package/features/router/RouterPresenter.js +44 -49
- package/features/router/RouterPresenter.js.map +1 -1
- package/features/router/RouterRepository.js +103 -111
- package/features/router/RouterRepository.js.map +1 -1
- package/features/router/RouterRepository.test.js +119 -150
- package/features/router/RouterRepository.test.js.map +1 -1
- package/features/router/abstractions.js +4 -14
- package/features/router/abstractions.js.map +1 -1
- package/features/router/feature.js +13 -12
- package/features/router/feature.js.map +1 -1
- package/features/router/index.js +1 -3
- package/helpers/InterfaceGenerator/date.js +0 -3
- package/helpers/InterfaceGenerator/id.js +0 -3
- package/helpers/InterfaceGenerator/identity.js +0 -3
- package/helpers/InterfaceGenerator/index.js +0 -3
- package/helpers/InterfaceGenerator/numeric.js +0 -3
- package/helpers/InterfaceGenerator/truthful.js +0 -3
- package/hooks/useAutocomplete/index.js +0 -2
- package/hooks/useAutocomplete/useAutocomplete.js +12 -15
- package/hooks/useAutocomplete/useAutocomplete.js.map +1 -1
- package/hooks/useDataList/functions/getData.js +2 -1
- package/hooks/useDataList/functions/getData.js.map +1 -1
- package/hooks/useDataList/functions/getError.js +2 -1
- package/hooks/useDataList/functions/getError.js.map +1 -1
- package/hooks/useDataList/functions/getMeta.js +2 -1
- package/hooks/useDataList/functions/getMeta.js.map +1 -1
- package/hooks/useDataList/functions/index.js +0 -2
- package/hooks/useDataList/functions/searchDataByKey.js +9 -14
- package/hooks/useDataList/functions/searchDataByKey.js.map +1 -1
- package/hooks/useDataList/index.js +0 -2
- package/hooks/useDataList/useDataList.js +131 -152
- package/hooks/useDataList/useDataList.js.map +1 -1
- package/hooks/useDataList/utils/index.js +0 -2
- package/hooks/useDataList/utils/prepareLoadListParams.js +25 -34
- package/hooks/useDataList/utils/prepareLoadListParams.js.map +1 -1
- package/hooks/useHandler.js +12 -16
- package/hooks/useHandler.js.map +1 -1
- package/hooks/useHandlers.js +18 -20
- package/hooks/useHandlers.js.map +1 -1
- package/hooks/useRegisterLegacyPlugin.js +7 -6
- package/hooks/useRegisterLegacyPlugin.js.map +1 -1
- package/hooks/useUi.js +2 -3
- package/hooks/useUi.js.map +1 -1
- package/i18n/i18n.js +8 -4
- package/i18n/i18n.js.map +1 -1
- package/i18n/index.js +0 -2
- package/index.js +6 -11
- package/package.json +13 -13
- package/plugins/AddQuerySelectionPlugin.js +36 -61
- package/plugins/AddQuerySelectionPlugin.js.map +1 -1
- package/plugins/ApolloCacheObjectIdPlugin.js +12 -11
- package/plugins/ApolloCacheObjectIdPlugin.js.map +1 -1
- package/plugins/ApolloDynamicLink.js +20 -22
- package/plugins/ApolloDynamicLink.js.map +1 -1
- package/plugins/ApolloLinkPlugin.js +16 -15
- package/plugins/ApolloLinkPlugin.js.map +1 -1
- package/plugins/ConsoleLinkPlugin.js +19 -21
- package/plugins/ConsoleLinkPlugin.js.map +1 -1
- package/plugins/NetworkErrorLinkPlugin/ErrorOverlay.js +39 -45
- package/plugins/NetworkErrorLinkPlugin/ErrorOverlay.js.map +1 -1
- package/plugins/NetworkErrorLinkPlugin/GqlErrorOverlay.js +18 -22
- package/plugins/NetworkErrorLinkPlugin/GqlErrorOverlay.js.map +1 -1
- package/plugins/NetworkErrorLinkPlugin/LocalAwsLambdaTimeoutMessage.js +21 -29
- package/plugins/NetworkErrorLinkPlugin/LocalAwsLambdaTimeoutMessage.js.map +1 -1
- package/plugins/NetworkErrorLinkPlugin/StyledComponents.js +6 -15
- package/plugins/NetworkErrorLinkPlugin/StyledComponents.js.map +1 -1
- package/plugins/NetworkErrorLinkPlugin/Typography.js +9 -14
- package/plugins/NetworkErrorLinkPlugin/Typography.js.map +1 -1
- package/plugins/NetworkErrorLinkPlugin/assets/close_24px.js +19 -0
- package/plugins/NetworkErrorLinkPlugin/assets/close_24px.js.map +1 -0
- package/plugins/NetworkErrorLinkPlugin/createErrorOverlay.js +11 -18
- package/plugins/NetworkErrorLinkPlugin/createErrorOverlay.js.map +1 -1
- package/plugins/NetworkErrorLinkPlugin.js +41 -58
- package/plugins/NetworkErrorLinkPlugin.js.map +1 -1
- package/plugins/OmitTypenameLinkPlugin.js +9 -14
- package/plugins/OmitTypenameLinkPlugin.js.map +1 -1
- package/plugins/TenantHeaderLinkPlugin.js +23 -32
- package/plugins/TenantHeaderLinkPlugin.js.map +1 -1
- package/plugins/components/Image.js +8 -15
- package/plugins/components/Image.js.map +1 -1
- package/plugins/image.js +94 -133
- package/plugins/image.js.map +1 -1
- package/plugins/index.js +35 -59
- package/plugins/index.js.map +1 -1
- package/presentation/envConfig/useEnvConfig.js +4 -8
- package/presentation/envConfig/useEnvConfig.js.map +1 -1
- package/presentation/localStorage/index.js +0 -2
- package/presentation/localStorage/useLocalStorage.js +10 -16
- package/presentation/localStorage/useLocalStorage.js.map +1 -1
- package/presentation/localStorage/useLocalStorageValue.js +15 -13
- package/presentation/localStorage/useLocalStorageValue.js.map +1 -1
- package/presentation/localStorage/useLocalStorageValues.js +23 -30
- package/presentation/localStorage/useLocalStorageValues.js.map +1 -1
- package/presentation/router/RouteElementRegistry.js +22 -25
- package/presentation/router/RouteElementRegistry.js.map +1 -1
- package/presentation/router/abstractions.js +2 -1
- package/presentation/router/abstractions.js.map +1 -1
- package/presentation/router/components/Redirect.js +8 -10
- package/presentation/router/components/Redirect.js.map +1 -1
- package/presentation/router/components/RouteContent.js +14 -17
- package/presentation/router/components/RouteContent.js.map +1 -1
- package/presentation/router/components/RouteLink.js +11 -16
- package/presentation/router/components/RouteLink.js.map +1 -1
- package/presentation/router/components/SimpleLink.js +18 -24
- package/presentation/router/components/SimpleLink.js.map +1 -1
- package/presentation/router/hooks/useRoute.js +15 -23
- package/presentation/router/hooks/useRoute.js.map +1 -1
- package/presentation/router/hooks/useRouter.js +22 -23
- package/presentation/router/hooks/useRouter.js.map +1 -1
- package/presentation/router/index.js +0 -2
- package/presentation/router/types.js +0 -3
- package/react-butterfiles/Files.js +148 -217
- package/react-butterfiles/Files.js.map +1 -1
- package/react-butterfiles/index.js +2 -1
- package/react-butterfiles/index.js.map +1 -1
- package/react-butterfiles/utils/generateId.js +2 -3
- package/react-butterfiles/utils/generateId.js.map +1 -1
- package/react-butterfiles/utils/readFileContent.js +9 -13
- package/react-butterfiles/utils/readFileContent.js.map +1 -1
- package/renderApp.js +7 -6
- package/renderApp.js.map +1 -1
- package/router.js +0 -3
- package/rslib-runtime.js +14 -0
- package/rslib-runtime.js.map +1 -0
- package/shared/di/DiContainerProvider.js +8 -12
- package/shared/di/DiContainerProvider.js.map +1 -1
- package/shared/di/createFeature.js +7 -8
- package/shared/di/createFeature.js.map +1 -1
- package/shared/di/useFeature.js +7 -3
- package/shared/di/useFeature.js.map +1 -1
- package/static/svg/close_24px.33adaadc.svg +1 -0
- package/types.js +0 -3
- package/utils/createGenericContext.js +17 -21
- package/utils/createGenericContext.js.map +1 -1
- package/utils/createHashing.js +13 -16
- package/utils/createHashing.js.map +1 -1
- package/utils/index.js +0 -2
- package/utils/legacyPluginToReactComponent.js +11 -10
- package/utils/legacyPluginToReactComponent.js.map +1 -1
- package/components/index.js.map +0 -1
- package/errors/index.js.map +0 -1
- package/exports/admin/env-config.js.map +0 -1
- package/exports/admin/graphql-client.js.map +0 -1
- package/exports/admin/local-storage.js.map +0 -1
- package/exports/admin/router.js.map +0 -1
- package/exports/admin/security.js.map +0 -1
- package/exports/admin.js.map +0 -1
- package/features/envConfig/index.js.map +0 -1
- package/features/eventPublisher/index.js.map +0 -1
- package/features/graphqlClient/index.js.map +0 -1
- package/features/graphqlClient/types.js.map +0 -1
- package/features/localStorage/index.js.map +0 -1
- package/features/mainGraphQLClient/index.js.map +0 -1
- package/features/router/index.js.map +0 -1
- package/helpers/InterfaceGenerator/date.js.map +0 -1
- package/helpers/InterfaceGenerator/id.js.map +0 -1
- package/helpers/InterfaceGenerator/identity.js.map +0 -1
- package/helpers/InterfaceGenerator/index.js.map +0 -1
- package/helpers/InterfaceGenerator/numeric.js.map +0 -1
- package/helpers/InterfaceGenerator/truthful.js.map +0 -1
- package/hooks/useAutocomplete/index.js.map +0 -1
- package/hooks/useDataList/functions/index.js.map +0 -1
- package/hooks/useDataList/index.js.map +0 -1
- package/hooks/useDataList/utils/index.js.map +0 -1
- package/i18n/index.js.map +0 -1
- package/index.js.map +0 -1
- package/presentation/localStorage/index.js.map +0 -1
- package/presentation/router/index.js.map +0 -1
- package/presentation/router/types.js.map +0 -1
- package/router.js.map +0 -1
- package/types.js.map +0 -1
- package/utils/index.js.map +0 -1
|
@@ -1,227 +1,158 @@
|
|
|
1
|
-
import
|
|
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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
-
|
|
128
|
-
|
|
129
|
-
|
|
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
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
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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AC;YACxC,IAAI,CAACd,kBAAkB,CAAC;cAAEC,CAAC;cAAEV,SAAS;cAAEC;YAAQ,CAAC,CAAC;UACtD;QACJ,CAAC;MACL;IACJ,CAAC,CAAC,eAEFrC,KAAA,CAAAmD,aAAA;MACInC,EAAE,EAAEA,EAAE,IAAI,IAAI,CAACA,EAAG;MAClB8C,GAAG,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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"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 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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,"
|
|
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
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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,"
|
|
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
|
package/rslib-runtime.js
ADDED
|
@@ -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
|
|
1
|
+
import react from "react";
|
|
2
2
|
import { createGenericContext } from "../../utils/createGenericContext.js";
|
|
3
3
|
const DiContainerContext = createGenericContext("DiContainer");
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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,"
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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,"
|
|
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"}
|