@webiny/app 5.43.3 → 6.0.0-alpha.1

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 (177) hide show
  1. package/App.d.ts +5 -12
  2. package/App.js +70 -84
  3. package/App.js.map +1 -1
  4. package/AppContainer.d.ts +23 -0
  5. package/AppContainer.js +9 -0
  6. package/AppContainer.js.map +1 -0
  7. package/apollo-client/InMemoryCache.d.ts +3 -2
  8. package/apollo-client/InMemoryCache.js +16 -47
  9. package/apollo-client/InMemoryCache.js.map +1 -1
  10. package/apollo-client/IntrospectionFragmentMatcher.d.ts +2 -2
  11. package/apollo-client/IntrospectionFragmentMatcher.js +33 -50
  12. package/apollo-client/IntrospectionFragmentMatcher.js.map +1 -1
  13. package/components/Image.d.ts +1 -1
  14. package/components/Image.js +11 -19
  15. package/components/Image.js.map +1 -1
  16. package/components/Routes.js +13 -23
  17. package/components/Routes.js.map +1 -1
  18. package/components/View.js +14 -26
  19. package/components/View.js.map +1 -1
  20. package/components/index.js +2 -19
  21. package/components/index.js.map +1 -1
  22. package/config/RouterConfig/Route.d.ts +30 -0
  23. package/config/RouterConfig/Route.js +42 -0
  24. package/config/RouterConfig/Route.js.map +1 -0
  25. package/config/RouterConfig.d.ts +32 -0
  26. package/config/RouterConfig.js +18 -0
  27. package/config/RouterConfig.js.map +1 -0
  28. package/config.js +9 -15
  29. package/config.js.map +1 -1
  30. package/contexts/Ui/index.js +28 -52
  31. package/contexts/Ui/index.js.map +1 -1
  32. package/core/DebounceRender.js +13 -24
  33. package/core/DebounceRender.js.map +1 -1
  34. package/core/Plugin.d.ts +1 -1
  35. package/core/Plugin.js +11 -19
  36. package/core/Plugin.js.map +1 -1
  37. package/core/Plugins.js +18 -24
  38. package/core/Plugins.js.map +1 -1
  39. package/core/Provider.d.ts +1 -1
  40. package/core/Provider.js +9 -13
  41. package/core/Provider.js.map +1 -1
  42. package/core/Routes.js +14 -23
  43. package/core/Routes.js.map +1 -1
  44. package/core/createProvider.d.ts +2 -2
  45. package/core/createProvider.js +1 -7
  46. package/core/createProvider.js.map +1 -1
  47. package/core/createProviderPlugin.d.ts +1 -1
  48. package/core/createProviderPlugin.js +4 -10
  49. package/core/createProviderPlugin.js.map +1 -1
  50. package/hooks/useAutocomplete/index.js +1 -12
  51. package/hooks/useAutocomplete/index.js.map +1 -1
  52. package/hooks/useAutocomplete/useAutocomplete.d.ts +1 -1
  53. package/hooks/useAutocomplete/useAutocomplete.js +9 -16
  54. package/hooks/useAutocomplete/useAutocomplete.js.map +1 -1
  55. package/hooks/useDataList/functions/getData.js +2 -11
  56. package/hooks/useDataList/functions/getData.js.map +1 -1
  57. package/hooks/useDataList/functions/getError.js +2 -11
  58. package/hooks/useDataList/functions/getError.js.map +1 -1
  59. package/hooks/useDataList/functions/getMeta.js +2 -11
  60. package/hooks/useDataList/functions/getMeta.js.map +1 -1
  61. package/hooks/useDataList/functions/index.js +3 -27
  62. package/hooks/useDataList/functions/index.js.map +1 -1
  63. package/hooks/useDataList/functions/searchDataByKey.js +4 -10
  64. package/hooks/useDataList/functions/searchDataByKey.js.map +1 -1
  65. package/hooks/useDataList/index.js +1 -12
  66. package/hooks/useDataList/index.js.map +1 -1
  67. package/hooks/useDataList/useDataList.d.ts +2 -2
  68. package/hooks/useDataList/useDataList.js +78 -78
  69. package/hooks/useDataList/useDataList.js.map +1 -1
  70. package/hooks/useDataList/utils/index.js +2 -20
  71. package/hooks/useDataList/utils/index.js.map +1 -1
  72. package/hooks/useDataList/utils/prepareLoadListParams.js +9 -15
  73. package/hooks/useDataList/utils/prepareLoadListParams.js.map +1 -1
  74. package/hooks/useDataList/utils/redirectToRouteWithQueryParams.js +10 -14
  75. package/hooks/useDataList/utils/redirectToRouteWithQueryParams.js.map +1 -1
  76. package/hooks/useDataList/utils/types.js +1 -5
  77. package/hooks/useHandler.js +7 -12
  78. package/hooks/useHandler.js.map +1 -1
  79. package/hooks/useHandlers.js +11 -17
  80. package/hooks/useHandlers.js.map +1 -1
  81. package/hooks/useRegisterLegacyPlugin.js +5 -11
  82. package/hooks/useRegisterLegacyPlugin.js.map +1 -1
  83. package/hooks/useUi.d.ts +1 -1
  84. package/hooks/useUi.js +4 -10
  85. package/hooks/useUi.js.map +1 -1
  86. package/i18n/i18n.js +5 -13
  87. package/i18n/i18n.js.map +1 -1
  88. package/i18n/index.js +1 -13
  89. package/i18n/index.js.map +1 -1
  90. package/index.d.ts +2 -2
  91. package/index.js +17 -177
  92. package/index.js.map +1 -1
  93. package/package.json +10 -9
  94. package/plugins/AddQuerySelectionPlugin.d.ts +1 -1
  95. package/plugins/AddQuerySelectionPlugin.js +61 -107
  96. package/plugins/AddQuerySelectionPlugin.js.map +1 -1
  97. package/plugins/ApolloCacheObjectIdPlugin.js +12 -31
  98. package/plugins/ApolloCacheObjectIdPlugin.js.map +1 -1
  99. package/plugins/ApolloDynamicLink.d.ts +3 -2
  100. package/plugins/ApolloDynamicLink.js +19 -46
  101. package/plugins/ApolloDynamicLink.js.map +1 -1
  102. package/plugins/ApolloLinkPlugin.d.ts +1 -1
  103. package/plugins/ApolloLinkPlugin.js +18 -37
  104. package/plugins/ApolloLinkPlugin.js.map +1 -1
  105. package/plugins/ConsoleLinkPlugin.js +20 -41
  106. package/plugins/ConsoleLinkPlugin.js.map +1 -1
  107. package/plugins/LocaleHeaderLinkPlugin.d.ts +1 -1
  108. package/plugins/LocaleHeaderLinkPlugin.js +23 -40
  109. package/plugins/LocaleHeaderLinkPlugin.js.map +1 -1
  110. package/plugins/NetworkErrorLinkPlugin/ErrorOverlay.js +39 -51
  111. package/plugins/NetworkErrorLinkPlugin/ErrorOverlay.js.map +1 -1
  112. package/plugins/NetworkErrorLinkPlugin/StyledComponents.js +68 -12
  113. package/plugins/NetworkErrorLinkPlugin/StyledComponents.js.map +1 -1
  114. package/plugins/NetworkErrorLinkPlugin/createErrorOverlay.d.ts +1 -1
  115. package/plugins/NetworkErrorLinkPlugin/createErrorOverlay.js +12 -18
  116. package/plugins/NetworkErrorLinkPlugin/createErrorOverlay.js.map +1 -1
  117. package/plugins/NetworkErrorLinkPlugin.js +23 -40
  118. package/plugins/NetworkErrorLinkPlugin.js.map +1 -1
  119. package/plugins/OmitTypenameLinkPlugin.js +11 -30
  120. package/plugins/OmitTypenameLinkPlugin.js.map +1 -1
  121. package/plugins/RoutePlugin.d.ts +1 -1
  122. package/plugins/RoutePlugin.js +12 -31
  123. package/plugins/RoutePlugin.js.map +1 -1
  124. package/plugins/TenantHeaderLinkPlugin.d.ts +1 -1
  125. package/plugins/TenantHeaderLinkPlugin.js +30 -47
  126. package/plugins/TenantHeaderLinkPlugin.js.map +1 -1
  127. package/plugins/ViewPlugin.d.ts +1 -1
  128. package/plugins/ViewPlugin.js +15 -36
  129. package/plugins/ViewPlugin.js.map +1 -1
  130. package/plugins/image.d.ts +1 -1
  131. package/plugins/image.js +46 -53
  132. package/plugins/image.js.map +1 -1
  133. package/plugins/index.d.ts +2 -2
  134. package/plugins/index.js +31 -53
  135. package/plugins/index.js.map +1 -1
  136. package/react-butterfiles/Files.js +208 -235
  137. package/react-butterfiles/Files.js.map +1 -1
  138. package/react-butterfiles/index.js +2 -8
  139. package/react-butterfiles/index.js.map +1 -1
  140. package/react-butterfiles/utils/generateId.js +1 -7
  141. package/react-butterfiles/utils/generateId.js.map +1 -1
  142. package/react-butterfiles/utils/readFileContent.js +4 -10
  143. package/react-butterfiles/utils/readFileContent.js.map +1 -1
  144. package/renderApp.d.ts +1 -1
  145. package/renderApp.js +4 -11
  146. package/renderApp.js.map +1 -1
  147. package/types.d.ts +3 -3
  148. package/types.js +11 -11
  149. package/types.js.map +1 -1
  150. package/utils/createGenericContext.js +13 -22
  151. package/utils/createGenericContext.js.map +1 -1
  152. package/utils/createHashing.js +9 -15
  153. package/utils/createHashing.js.map +1 -1
  154. package/utils/getApiUrl.js +1 -8
  155. package/utils/getApiUrl.js.map +1 -1
  156. package/utils/getGqlApiUrl.js +3 -9
  157. package/utils/getGqlApiUrl.js.map +1 -1
  158. package/utils/getHeadlessCmsGqlApiUrl.js +7 -13
  159. package/utils/getHeadlessCmsGqlApiUrl.js.map +1 -1
  160. package/utils/getLocaleCode.js +6 -16
  161. package/utils/getLocaleCode.js.map +1 -1
  162. package/utils/getPrerenderId.js +1 -7
  163. package/utils/getPrerenderId.js.map +1 -1
  164. package/utils/getTenantId.js +7 -13
  165. package/utils/getTenantId.js.map +1 -1
  166. package/utils/index.js +10 -115
  167. package/utils/index.js.map +1 -1
  168. package/utils/isLocalhost.js +4 -12
  169. package/utils/isLocalhost.js.map +1 -1
  170. package/utils/isPrerendering.js +1 -7
  171. package/utils/isPrerendering.js.map +1 -1
  172. package/utils/legacyPluginToReactComponent.d.ts +1 -1
  173. package/utils/legacyPluginToReactComponent.js +5 -11
  174. package/utils/legacyPluginToReactComponent.js.map +1 -1
  175. package/core/AddRoute.d.ts +0 -21
  176. package/core/AddRoute.js +0 -21
  177. package/core/AddRoute.js.map +0 -1
@@ -1,254 +1,227 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.Files = void 0;
8
- var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
9
- var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
10
- var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
11
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
12
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
13
- var _callSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/callSuper"));
14
- var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
15
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
16
- var _react = _interopRequireDefault(require("react"));
17
- var _bytes = _interopRequireDefault(require("bytes"));
18
- var _minimatch = _interopRequireDefault(require("minimatch"));
19
- var _readFileContent = require("./utils/readFileContent");
20
- var _generateId = require("./utils/generateId");
21
- var _excluded = ["onSuccess", "onError", "onDragOver", "onDrop"];
22
- var Files = exports.Files = /*#__PURE__*/function (_React$Component) {
23
- function Files() {
24
- var _this;
25
- (0, _classCallCheck2.default)(this, Files);
26
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
27
- args[_key] = arguments[_key];
1
+ import React from "react";
2
+ import bytes from "bytes";
3
+ import minimatch from "minimatch";
4
+ import { readFileContent } from "./utils/readFileContent";
5
+ import { generateId } from "./utils/generateId";
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;
28
34
  }
29
- _this = (0, _callSuper2.default)(this, Files, [].concat(args));
30
- (0, _defineProperty2.default)(_this, "input", null);
31
- (0, _defineProperty2.default)(_this, "browseFilesPassedParams", null);
32
- (0, _defineProperty2.default)(_this, "id", (0, _generateId.generateId)());
33
- (0, _defineProperty2.default)(_this, "validateFiles", function (files) {
34
- var _this$props = _this.props,
35
- multiple = _this$props.multiple,
36
- multipleMaxSize = _this$props.multipleMaxSize,
37
- multipleMaxCount = _this$props.multipleMaxCount,
38
- accept = _this$props.accept,
39
- maxSize = _this$props.maxSize;
40
- var errors = [];
41
- var multipleFileSize = 0;
42
- if (!multiple && files.length > 1) {
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))) {
43
38
  errors.push({
44
- id: (0, _generateId.generateId)(),
45
- type: "multipleNotAllowed"
39
+ id: generateId(),
40
+ index,
41
+ file,
42
+ type: "unsupportedFileType"
46
43
  });
47
- return errors;
48
- }
49
- var _loop = function _loop() {
50
- var file = files[index];
51
- if (Array.isArray(accept) && accept.length && !accept.some(function (type) {
52
- return (0, _minimatch.default)(file.type, type);
53
- })) {
44
+ } else if (maxSize) {
45
+ const sizeAsBytes = bytes(maxSize);
46
+ if (sizeAsBytes && file.size > sizeAsBytes) {
54
47
  errors.push({
55
- id: (0, _generateId.generateId)(),
56
- index: index,
57
- file: file,
58
- type: "unsupportedFileType"
48
+ id: generateId(),
49
+ index,
50
+ file,
51
+ type: "maxSizeExceeded"
59
52
  });
60
- } else if (maxSize) {
61
- var sizeAsBytes = (0, _bytes.default)(maxSize);
62
- if (sizeAsBytes && file.size > sizeAsBytes) {
63
- errors.push({
64
- id: (0, _generateId.generateId)(),
65
- index: index,
66
- file: file,
67
- type: "maxSizeExceeded"
68
- });
69
- }
70
53
  }
71
- if (multiple) {
72
- multipleFileSize += file.size;
73
- }
74
- };
75
- for (var index = 0; index < files.length; index++) {
76
- _loop();
77
54
  }
78
55
  if (multiple) {
79
- var maxMultipleMaxSize = (0, _bytes.default)(multipleMaxSize);
80
- if (maxMultipleMaxSize && multipleMaxSize && multipleFileSize > maxMultipleMaxSize) {
81
- errors.push({
82
- id: (0, _generateId.generateId)(),
83
- type: "multipleMaxSizeExceeded",
84
- multipleFileSize: multipleFileSize,
85
- multipleMaxSize: maxMultipleMaxSize
86
- });
87
- }
88
- if (multipleMaxCount && files.length > multipleMaxCount) {
89
- errors.push({
90
- id: (0, _generateId.generateId)(),
91
- type: "multipleMaxCountExceeded",
92
- multipleCount: files.length,
93
- multipleMaxCount: multipleMaxCount
94
- });
95
- }
56
+ multipleFileSize += file.size;
96
57
  }
97
- return errors;
98
- });
99
- (0, _defineProperty2.default)(_this, "processSelectedFiles", async function (eventFiles) {
100
- if (eventFiles.length === 0) {
101
- return;
102
- }
103
- var _this$props2 = _this.props,
104
- convertToBase64 = _this$props2.convertToBase64,
105
- onSuccess = _this$props2.onSuccess,
106
- onError = _this$props2.onError;
107
- var _this2 = _this,
108
- browseFilesPassedParams = _this2.browseFilesPassedParams;
109
- var callbacks = {
110
- onSuccess: onSuccess,
111
- onError: onError
112
- };
113
- if (browseFilesPassedParams && browseFilesPassedParams.onSuccess) {
114
- callbacks.onSuccess = browseFilesPassedParams.onSuccess;
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
+ });
115
68
  }
116
- if (browseFilesPassedParams && browseFilesPassedParams.onError) {
117
- callbacks.onError = browseFilesPassedParams.onError;
69
+ if (multipleMaxCount && files.length > multipleMaxCount) {
70
+ errors.push({
71
+ id: generateId(),
72
+ type: "multipleMaxCountExceeded",
73
+ multipleCount: files.length,
74
+ multipleMaxCount
75
+ });
118
76
  }
119
- var files = (0, _toConsumableArray2.default)(eventFiles).map(function (file) {
120
- return {
121
- id: (0, _generateId.generateId)(),
122
- name: file.name,
123
- type: file.type,
124
- size: file.size,
125
- src: {
126
- file: file,
127
- base64: null
128
- }
129
- };
130
- });
131
- var errors = _this.validateFiles(files);
132
- if (errors.length) {
133
- callbacks.onError && callbacks.onError(errors, files);
134
- } else {
135
- if (convertToBase64) {
136
- for (var i = 0; i < files.length; i++) {
137
- var file = files[i].src.file;
138
- files[i].src.base64 = await (0, _readFileContent.readFileContent)(file);
139
- }
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
140
111
  }
141
- callbacks.onSuccess && callbacks.onSuccess(files);
142
- }
143
-
144
- // Reset the browseFiles arguments.
145
- if (_this.input) {
146
- _this.input.value = "";
147
- }
148
- _this.browseFilesPassedParams = null;
149
- });
150
- /**
151
- * Extracted into a separate method just for testing purposes.
152
- */
153
- (0, _defineProperty2.default)(_this, "onDropFilesHandler", async function (_ref) {
154
- var e = _ref.e,
155
- onSuccess = _ref.onSuccess,
156
- onError = _ref.onError;
157
- _this.browseFilesPassedParams = {
158
- onSuccess: onSuccess,
159
- onError: onError
160
112
  };
161
- e.dataTransfer && e.dataTransfer.files && (await _this.processSelectedFiles(e.dataTransfer.files));
162
113
  });
163
- /**
164
- * Extracted into a separate method just for testing purposes.
165
- */
166
- (0, _defineProperty2.default)(_this, "browseFilesHandler", function (_ref2) {
167
- var onSuccess = _ref2.onSuccess,
168
- onError = _ref2.onError;
169
- _this.browseFilesPassedParams = {
170
- onSuccess: onSuccess,
171
- onError: onError
172
- };
173
- _this.input && _this.input.click();
174
- });
175
- return _this;
176
- }
177
- (0, _inherits2.default)(Files, _React$Component);
178
- return (0, _createClass2.default)(Files, [{
179
- key: "render",
180
- value: function render() {
181
- var _this3 = this;
182
- var _this$props3 = this.props,
183
- multiple = _this$props3.multiple,
184
- accept = _this$props3.accept,
185
- id = _this$props3.id;
186
- return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, this.props.children({
187
- getLabelProps: function getLabelProps(props) {
188
- return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, props), {}, {
189
- htmlFor: id || _this3.id
190
- });
191
- },
192
- validateFiles: this.validateFiles,
193
- browseFiles: function browseFiles() {
194
- var _ref3 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
195
- onSuccess = _ref3.onSuccess,
196
- onError = _ref3.onError;
197
- _this3.browseFilesHandler({
198
- onSuccess: onSuccess,
199
- onError: onError
200
- });
201
- },
202
- getDropZoneProps: function getDropZoneProps() {
203
- var _ref4 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
204
- var onSuccess = _ref4.onSuccess,
205
- onError = _ref4.onError,
206
- _onDragOver = _ref4.onDragOver,
207
- _onDrop = _ref4.onDrop,
208
- rest = (0, _objectWithoutProperties2.default)(_ref4, _excluded);
209
- return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, rest), {}, {
210
- onDragOver: function onDragOver(e) {
211
- e.preventDefault();
212
- typeof _onDragOver === "function" && _onDragOver();
213
- },
214
- onDrop: async function onDrop(e) {
215
- e.preventDefault();
216
- typeof _onDrop === "function" && _onDrop();
217
- _this3.onDropFilesHandler({
218
- e: e,
219
- onSuccess: onSuccess,
220
- onError: onError
221
- });
222
- }
223
- });
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);
224
122
  }
225
- }), /*#__PURE__*/_react.default.createElement("input", {
226
- id: id || this.id,
227
- ref: function ref(_ref5) {
228
- if (_ref5) {
229
- _this3.input = _ref5;
123
+ }
124
+ callbacks.onSuccess && callbacks.onSuccess(files);
125
+ }
126
+
127
+ // Reset the browseFiles arguments.
128
+ if (this.input) {
129
+ this.input.value = "";
130
+ }
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
+ });
230
206
  }
231
- },
232
- accept: accept.join(","),
233
- style: {
234
- display: "none"
235
- },
236
- type: "file",
237
- multiple: multiple,
238
- onChange: function onChange(e) {
239
- return _this3.processSelectedFiles(e.target.files ?? []);
207
+ };
208
+ }
209
+ }), /*#__PURE__*/React.createElement("input", {
210
+ id: id || this.id,
211
+ ref: ref => {
212
+ if (ref) {
213
+ this.input = ref;
240
214
  }
241
- }));
242
- }
243
- }]);
244
- }(_react.default.Component);
245
- (0, _defineProperty2.default)(Files, "defaultProps", {
246
- accept: [],
247
- multiple: false,
248
- maxSize: "2mb",
249
- multipleMaxSize: "10mb",
250
- multipleMaxCount: null,
251
- convertToBase64: false
252
- });
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
+ }
225
+ }
253
226
 
254
227
  //# sourceMappingURL=Files.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_react","_interopRequireDefault","require","_bytes","_minimatch","_readFileContent","_generateId","_excluded","Files","exports","_React$Component","_this","_classCallCheck2","default","_len","arguments","length","args","Array","_key","_callSuper2","concat","_defineProperty2","generateId","files","_this$props","props","multiple","multipleMaxSize","multipleMaxCount","accept","maxSize","errors","multipleFileSize","push","id","type","_loop","file","index","isArray","some","minimatch","sizeAsBytes","bytes","size","maxMultipleMaxSize","multipleCount","eventFiles","_this$props2","convertToBase64","onSuccess","onError","_this2","browseFilesPassedParams","callbacks","_toConsumableArray2","map","name","src","base64","validateFiles","i","readFileContent","input","value","_ref","e","dataTransfer","processSelectedFiles","_ref2","click","_inherits2","_createClass2","key","render","_this3","_this$props3","createElement","Fragment","children","getLabelProps","_objectSpread2","htmlFor","browseFiles","_ref3","undefined","browseFilesHandler","getDropZoneProps","_ref4","onDragOver","onDrop","rest","_objectWithoutProperties2","preventDefault","onDropFilesHandler","ref","join","style","display","onChange","target","React","Component"],"sources":["Files.tsx"],"sourcesContent":["import React from \"react\";\nimport bytes from \"bytes\";\nimport minimatch from \"minimatch\";\nimport { readFileContent } from \"./utils/readFileContent\";\nimport { generateId } from \"./utils/generateId\";\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,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,MAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,UAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,gBAAA,GAAAH,OAAA;AACA,IAAAI,WAAA,GAAAJ,OAAA;AAAgD,IAAAK,SAAA;AAAA,IAyDnCC,KAAK,GAAAC,OAAA,CAAAD,KAAA,0BAA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AOH,OAAM,KAAK,UAAU,IAAIA,OAAM,CAAC,CAAC;cACxCf,MAAI,CAACmB,kBAAkB,CAAC;gBAAE5B,CAAC,EAADA,CAAC;gBAAEhB,SAAS,EAATA,SAAS;gBAAEC,OAAO,EAAPA;cAAQ,CAAC,CAAC;YACtD;UAAC;QAET;MACJ,CAAC,CAAC,eAEFpD,MAAA,CAAAa,OAAA,CAAAiE,aAAA;QACI3C,EAAE,EAAEA,EAAE,IAAI,IAAI,CAACA,EAAG;QAClB6D,GAAG,EAAE,SAALA,GAAGA,CAAEA,KAAG,EAAI;UACR,IAAIA,KAAG,EAAE;YACLpB,MAAI,CAACZ,KAAK,GAAGgC,KAAG;UACpB;QACJ,CAAE;QACFlE,MAAM,EAAEA,MAAM,CAACmE,IAAI,CAAC,GAAG,CAAE;QACzBC,KAAK,EAAE;UAAEC,OAAO,EAAE;QAAO,CAAE;QAC3B/D,IAAI,EAAC,MAAM;QACXT,QAAQ,EAAEA,QAAS;QACnByE,QAAQ,EAAE,SAAVA,QAAQA,CAAEjC,CAAC;UAAA,OACPS,MAAI,CAACP,oBAAoB,CAAEF,CAAC,CAACkC,MAAM,CAAC7E,KAAK,IAA2B,EAAE,CAAC;QAAA;MAC1E,CACJ,CACW,CAAC;IAEzB;EAAC;AAAA,EApNsB8E,cAAK,CAACC,SAAS;AAAA,IAAAjF,gBAAA,CAAAT,OAAA,EAA7BL,KAAK,kBACQ;EAClBsB,MAAM,EAAE,EAAE;EACVH,QAAQ,EAAE,KAAK;EACfI,OAAO,EAAE,KAAK;EACdH,eAAe,EAAE,MAAM;EACvBC,gBAAgB,EAAE,IAAI;EACtBqB,eAAe,EAAE;AACrB,CAAC","ignoreList":[]}
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\";\nimport { generateId } from \"./utils/generateId\";\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.processSelectedFi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;IACzE,CACJ,CACW,CAAC;EAEzB;AACJ","ignoreList":[]}
@@ -1,10 +1,4 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- var _Files = require("./Files");
8
- var _default = exports.default = _Files.Files;
1
+ import { Files } from "./Files";
2
+ export default Files;
9
3
 
10
4
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_Files","require","_default","exports","default","Files"],"sources":["index.ts"],"sourcesContent":["import { Files } from \"./Files\";\n\nexport default Files;\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAAgC,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEjBC,YAAK","ignoreList":[]}
1
+ {"version":3,"names":["Files"],"sources":["index.ts"],"sourcesContent":["import { Files } from \"./Files\";\n\nexport default Files;\n"],"mappings":"AAAA,SAASA,KAAK;AAEd,eAAeA,KAAK","ignoreList":[]}
@@ -1,10 +1,4 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.generateId = void 0;
7
- var generateId = exports.generateId = function generateId() {
1
+ export const generateId = () => {
8
2
  return "_" + Math.random().toString(36).substr(2, 9);
9
3
  };
10
4
 
@@ -1 +1 @@
1
- {"version":3,"names":["generateId","exports","Math","random","toString","substr"],"sources":["generateId.ts"],"sourcesContent":["export const generateId = () => {\n return \"_\" + Math.random().toString(36).substr(2, 9);\n};\n"],"mappings":";;;;;;AAAO,IAAMA,UAAU,GAAAC,OAAA,CAAAD,UAAA,GAAG,SAAbA,UAAUA,CAAA,EAAS;EAC5B,OAAO,GAAG,GAAGE,IAAI,CAACC,MAAM,CAAC,CAAC,CAACC,QAAQ,CAAC,EAAE,CAAC,CAACC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC;AACxD,CAAC","ignoreList":[]}
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,17 +1,11 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.readFileContent = void 0;
7
- var readFileContent = exports.readFileContent = async function readFileContent(file) {
8
- return new Promise(function (resolve, reject) {
9
- var reader = new window.FileReader();
1
+ export const readFileContent = async file => {
2
+ return new Promise((resolve, reject) => {
3
+ const reader = new window.FileReader();
10
4
  reader.onload = function (e) {
11
5
  if (e.target) {
12
6
  resolve(e.target.result);
13
7
  } else {
14
- reject("Unable to read file contents!");
8
+ reject(`Unable to read file contents!`);
15
9
  }
16
10
  };
17
11
  reader.readAsDataURL(file);
@@ -1 +1 @@
1
- {"version":3,"names":["readFileContent","exports","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":";;;;;;AAAO,IAAMA,eAAe,GAAAC,OAAA,CAAAD,eAAA,GAAG,eAAlBA,eAAeA,CAAUE,IAAU,EAAK;EACjD,OAAO,IAAIC,OAAO,CAAS,UAACC,OAAO,EAAEC,MAAM,EAAK;IAC5C,IAAMC,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,gCAAgC,CAAC;MAC3C;IACJ,CAAC;IAEDC,MAAM,CAACO,aAAa,CAACX,IAAI,CAAC;EAC9B,CAAC,CAAC;AACN,CAAC","ignoreList":[]}
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":[]}
package/renderApp.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { Root } from "react-dom/client";
1
+ import type { Root } from "react-dom/client";
2
2
  export declare const renderApp: (app: JSX.Element) => Root;
package/renderApp.js CHANGED
@@ -1,14 +1,7 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.renderApp = void 0;
8
- var _client = _interopRequireDefault(require("react-dom/client"));
9
- var renderApp = exports.renderApp = function renderApp(app) {
10
- var container = document.getElementById("root");
11
- var root = _client.default.createRoot(container);
1
+ import ReactDOMClient from "react-dom/client";
2
+ export const renderApp = app => {
3
+ const container = document.getElementById("root");
4
+ const root = ReactDOMClient.createRoot(container);
12
5
  root.render(app);
13
6
  return root;
14
7
  };
package/renderApp.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["_client","_interopRequireDefault","require","renderApp","exports","app","container","document","getElementById","root","ReactDOMClient","createRoot","render"],"sources":["renderApp.tsx"],"sourcesContent":["import ReactDOMClient, { Root } from \"react-dom/client\";\n\nexport const renderApp = (app: 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":";;;;;;;AAAA,IAAAA,OAAA,GAAAC,sBAAA,CAAAC,OAAA;AAEO,IAAMC,SAAS,GAAAC,OAAA,CAAAD,SAAA,GAAG,SAAZA,SAASA,CAAIE,GAAgB,EAAW;EACjD,IAAMC,SAAS,GAAGC,QAAQ,CAACC,cAAc,CAAC,MAAM,CAAE;EAElD,IAAMC,IAAI,GAAGC,eAAc,CAACC,UAAU,CAACL,SAAS,CAAC;EACjDG,IAAI,CAACG,MAAM,CAACP,GAAG,CAAC;EAChB,OAAOI,IAAI;AACf,CAAC","ignoreList":[]}
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: 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,GAAgB,IAAW;EACjD,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":[]}