@iobroker/adapter-react-v5 4.9.11 → 4.10.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.
@@ -1,324 +1,531 @@
1
1
  "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
6
17
  });
7
- exports["default"] = void 0;
8
- var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
10
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
11
- var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
12
- var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
13
- var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
14
- var _react = require("react");
15
- var _propTypes = _interopRequireDefault(require("prop-types"));
16
- var _reactDropzone = _interopRequireDefault(require("react-dropzone"));
17
- var _reactCropper = require("react-cropper");
18
- var _styles = require("@mui/styles");
19
- var _material = require("@mui/material");
20
- var _iconsMaterial = require("@mui/icons-material");
21
- var _fa = require("react-icons/fa");
22
- var _Utils = _interopRequireDefault(require("./Utils"));
23
- function _callSuper(t, o, e) { return o = (0, _getPrototypeOf2["default"])(o), (0, _possibleConstructorReturn2["default"])(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], (0, _getPrototypeOf2["default"])(t).constructor) : o.apply(t, e)); }
24
- function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ const react_1 = __importStar(require("react"));
30
+ const react_dropzone_1 = __importDefault(require("react-dropzone"));
31
+ const react_cropper_1 = require("react-cropper");
32
+ const styles_1 = require("@mui/styles");
33
+ const material_1 = require("@mui/material");
34
+ const icons_material_1 = require("@mui/icons-material");
35
+ const fa_1 = require("react-icons/fa");
36
+ const Utils_1 = __importDefault(require("./Utils"));
37
+ const i18n_1 = __importDefault(require("../i18n"));
25
38
  // import 'cropperjs/dist/cropper.css';
26
- var cropperStyles = "\n/*!\n * Cropper.js v1.5.12\n * https://fengyuanchen.github.io/cropperjs\n *\n * Copyright 2015-present Chen Fengyuan\n * Released under the MIT license\n *\n * Date: 2021-06-12T08:00:11.623Z\n */\n\n.cropper-container {\n direction: ltr;\n font-size: 0;\n line-height: 0;\n position: relative;\n -ms-touch-action: none;\n touch-action: none;\n -webkit-user-select: none;\n -moz-user-select: none;\n -ms-user-select: none;\n user-select: none;\n}\n\n.cropper-container img {\n display: block;\n height: 100%;\n image-orientation: 0deg;\n max-height: none !important;\n max-width: none !important;\n min-height: 0 !important;\n min-width: 0 !important;\n width: 100%;\n}\n\n.cropper-wrap-box,\n.cropper-canvas,\n.cropper-drag-box,\n.cropper-crop-box,\n.cropper-modal {\n bottom: 0;\n left: 0;\n position: absolute;\n right: 0;\n top: 0;\n}\n\n.cropper-wrap-box,\n.cropper-canvas {\n overflow: hidden;\n}\n\n.cropper-drag-box {\n background-color: #fff;\n opacity: 0;\n}\n\n.cropper-modal {\n background-color: #000;\n opacity: 0.5;\n}\n\n.cropper-view-box {\n display: block;\n height: 100%;\n outline: 1px solid #39f;\n outline-color: rgba(51, 153, 255, 0.75);\n overflow: hidden;\n width: 100%;\n}\n\n.cropper-dashed {\n border: 0 dashed #eee;\n display: block;\n opacity: 0.5;\n position: absolute;\n}\n\n.cropper-dashed.dashed-h {\n border-bottom-width: 1px;\n border-top-width: 1px;\n height: calc(100% / 3);\n left: 0;\n top: calc(100% / 3);\n width: 100%;\n}\n\n.cropper-dashed.dashed-v {\n border-left-width: 1px;\n border-right-width: 1px;\n height: 100%;\n left: calc(100% / 3);\n top: 0;\n width: calc(100% / 3);\n}\n\n.cropper-center {\n display: block;\n height: 0;\n left: 50%;\n opacity: 0.75;\n position: absolute;\n top: 50%;\n width: 0;\n}\n\n.cropper-center::before,\n.cropper-center::after {\n background-color: #eee;\n content: ' ';\n display: block;\n position: absolute;\n}\n\n.cropper-center::before {\n height: 1px;\n left: -3px;\n top: 0;\n width: 7px;\n}\n\n.cropper-center::after {\n height: 7px;\n left: 0;\n top: -3px;\n width: 1px;\n}\n\n.cropper-face,\n.cropper-line,\n.cropper-point {\n display: block;\n height: 100%;\n opacity: 0.1;\n position: absolute;\n width: 100%;\n}\n\n.cropper-face {\n background-color: #fff;\n left: 0;\n top: 0;\n}\n\n.cropper-line {\n background-color: #39f;\n}\n\n.cropper-line.line-e {\n cursor: ew-resize;\n right: -3px;\n top: 0;\n width: 5px;\n}\n\n.cropper-line.line-n {\n cursor: ns-resize;\n height: 5px;\n left: 0;\n top: -3px;\n}\n\n.cropper-line.line-w {\n cursor: ew-resize;\n left: -3px;\n top: 0;\n width: 5px;\n}\n\n.cropper-line.line-s {\n bottom: -3px;\n cursor: ns-resize;\n height: 5px;\n left: 0;\n}\n\n.cropper-point {\n background-color: #39f;\n height: 5px;\n opacity: 0.75;\n width: 5px;\n}\n\n.cropper-point.point-e {\n cursor: ew-resize;\n margin-top: -3px;\n right: -3px;\n top: 50%;\n}\n\n.cropper-point.point-n {\n cursor: ns-resize;\n left: 50%;\n margin-left: -3px;\n top: -3px;\n}\n\n.cropper-point.point-w {\n cursor: ew-resize;\n left: -3px;\n margin-top: -3px;\n top: 50%;\n}\n\n.cropper-point.point-s {\n bottom: -3px;\n cursor: s-resize;\n left: 50%;\n margin-left: -3px;\n}\n\n.cropper-point.point-ne {\n cursor: nesw-resize;\n right: -3px;\n top: -3px;\n}\n\n.cropper-point.point-nw {\n cursor: nwse-resize;\n left: -3px;\n top: -3px;\n}\n\n.cropper-point.point-sw {\n bottom: -3px;\n cursor: nesw-resize;\n left: -3px;\n}\n\n.cropper-point.point-se {\n bottom: -3px;\n cursor: nwse-resize;\n height: 20px;\n opacity: 1;\n right: -3px;\n width: 20px;\n}\n\n@media (min-width: 768px) {\n .cropper-point.point-se {\n height: 15px;\n width: 15px;\n }\n}\n\n@media (min-width: 992px) {\n .cropper-point.point-se {\n height: 10px;\n width: 10px;\n }\n}\n\n@media (min-width: 1200px) {\n .cropper-point.point-se {\n height: 5px;\n opacity: 0.75;\n width: 5px;\n }\n}\n\n.cropper-point.point-se::before {\n background-color: #39f;\n bottom: -50%;\n content: ' ';\n display: block;\n height: 200%;\n opacity: 0;\n position: absolute;\n right: -50%;\n width: 200%;\n}\n\n.cropper-invisible {\n opacity: 0;\n}\n\n.cropper-bg {\n background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQAQMAAAAlPW0iAAAAA3NCSVQICAjb4U/gAAAABlBMVEXMzMz////TjRV2AAAACXBIWXMAAArrAAAK6wGCiw1aAAAAHHRFWHRTb2Z0d2FyZQBBZG9iZSBGaXJld29ya3MgQ1M26LyyjAAAABFJREFUCJlj+M/AgBVhF/0PAH6/D/HkDxOGAAAAAElFTkSuQmCC');\n}\n\n.cropper-hide {\n display: block;\n height: 0;\n position: absolute;\n width: 0;\n}\n\n.cropper-hidden {\n display: none !important;\n}\n\n.cropper-move {\n cursor: move;\n}\n\n.cropper-crop {\n cursor: crosshair;\n}\n\n.cropper-disabled .cropper-drag-box,\n.cropper-disabled .cropper-face,\n.cropper-disabled .cropper-line,\n.cropper-disabled .cropper-point {\n cursor: not-allowed;\n}\n";
27
- var styles = function styles() {
28
- return {
39
+ const cropperStyles = `
40
+ /*!
41
+ * Cropper.js v1.5.12
42
+ * https://fengyuanchen.github.io/cropperjs
43
+ *
44
+ * Copyright 2015-present Chen Fengyuan
45
+ * Released under the MIT license
46
+ *
47
+ * Date: 2021-06-12T08:00:11.623Z
48
+ */
49
+
50
+ .cropper-container {
51
+ direction: ltr;
52
+ font-size: 0;
53
+ line-height: 0;
54
+ position: relative;
55
+ -ms-touch-action: none;
56
+ touch-action: none;
57
+ -webkit-user-select: none;
58
+ -moz-user-select: none;
59
+ -ms-user-select: none;
60
+ user-select: none;
61
+ }
62
+
63
+ .cropper-container img {
64
+ display: block;
65
+ height: 100%;
66
+ image-orientation: 0deg;
67
+ max-height: none !important;
68
+ max-width: none !important;
69
+ min-height: 0 !important;
70
+ min-width: 0 !important;
71
+ width: 100%;
72
+ }
73
+
74
+ .cropper-wrap-box,
75
+ .cropper-canvas,
76
+ .cropper-drag-box,
77
+ .cropper-crop-box,
78
+ .cropper-modal {
79
+ bottom: 0;
80
+ left: 0;
81
+ position: absolute;
82
+ right: 0;
83
+ top: 0;
84
+ }
85
+
86
+ .cropper-wrap-box,
87
+ .cropper-canvas {
88
+ overflow: hidden;
89
+ }
90
+
91
+ .cropper-drag-box {
92
+ background-color: #fff;
93
+ opacity: 0;
94
+ }
95
+
96
+ .cropper-modal {
97
+ background-color: #000;
98
+ opacity: 0.5;
99
+ }
100
+
101
+ .cropper-view-box {
102
+ display: block;
103
+ height: 100%;
104
+ outline: 1px solid #39f;
105
+ outline-color: rgba(51, 153, 255, 0.75);
106
+ overflow: hidden;
107
+ width: 100%;
108
+ }
109
+
110
+ .cropper-dashed {
111
+ border: 0 dashed #eee;
112
+ display: block;
113
+ opacity: 0.5;
114
+ position: absolute;
115
+ }
116
+
117
+ .cropper-dashed.dashed-h {
118
+ border-bottom-width: 1px;
119
+ border-top-width: 1px;
120
+ height: calc(100% / 3);
121
+ left: 0;
122
+ top: calc(100% / 3);
123
+ width: 100%;
124
+ }
125
+
126
+ .cropper-dashed.dashed-v {
127
+ border-left-width: 1px;
128
+ border-right-width: 1px;
129
+ height: 100%;
130
+ left: calc(100% / 3);
131
+ top: 0;
132
+ width: calc(100% / 3);
133
+ }
134
+
135
+ .cropper-center {
136
+ display: block;
137
+ height: 0;
138
+ left: 50%;
139
+ opacity: 0.75;
140
+ position: absolute;
141
+ top: 50%;
142
+ width: 0;
143
+ }
144
+
145
+ .cropper-center::before,
146
+ .cropper-center::after {
147
+ background-color: #eee;
148
+ content: ' ';
149
+ display: block;
150
+ position: absolute;
151
+ }
152
+
153
+ .cropper-center::before {
154
+ height: 1px;
155
+ left: -3px;
156
+ top: 0;
157
+ width: 7px;
158
+ }
159
+
160
+ .cropper-center::after {
161
+ height: 7px;
162
+ left: 0;
163
+ top: -3px;
164
+ width: 1px;
165
+ }
166
+
167
+ .cropper-face,
168
+ .cropper-line,
169
+ .cropper-point {
170
+ display: block;
171
+ height: 100%;
172
+ opacity: 0.1;
173
+ position: absolute;
174
+ width: 100%;
175
+ }
176
+
177
+ .cropper-face {
178
+ background-color: #fff;
179
+ left: 0;
180
+ top: 0;
181
+ }
182
+
183
+ .cropper-line {
184
+ background-color: #39f;
185
+ }
186
+
187
+ .cropper-line.line-e {
188
+ cursor: ew-resize;
189
+ right: -3px;
190
+ top: 0;
191
+ width: 5px;
192
+ }
193
+
194
+ .cropper-line.line-n {
195
+ cursor: ns-resize;
196
+ height: 5px;
197
+ left: 0;
198
+ top: -3px;
199
+ }
200
+
201
+ .cropper-line.line-w {
202
+ cursor: ew-resize;
203
+ left: -3px;
204
+ top: 0;
205
+ width: 5px;
206
+ }
207
+
208
+ .cropper-line.line-s {
209
+ bottom: -3px;
210
+ cursor: ns-resize;
211
+ height: 5px;
212
+ left: 0;
213
+ }
214
+
215
+ .cropper-point {
216
+ background-color: #39f;
217
+ height: 5px;
218
+ opacity: 0.75;
219
+ width: 5px;
220
+ }
221
+
222
+ .cropper-point.point-e {
223
+ cursor: ew-resize;
224
+ margin-top: -3px;
225
+ right: -3px;
226
+ top: 50%;
227
+ }
228
+
229
+ .cropper-point.point-n {
230
+ cursor: ns-resize;
231
+ left: 50%;
232
+ margin-left: -3px;
233
+ top: -3px;
234
+ }
235
+
236
+ .cropper-point.point-w {
237
+ cursor: ew-resize;
238
+ left: -3px;
239
+ margin-top: -3px;
240
+ top: 50%;
241
+ }
242
+
243
+ .cropper-point.point-s {
244
+ bottom: -3px;
245
+ cursor: s-resize;
246
+ left: 50%;
247
+ margin-left: -3px;
248
+ }
249
+
250
+ .cropper-point.point-ne {
251
+ cursor: nesw-resize;
252
+ right: -3px;
253
+ top: -3px;
254
+ }
255
+
256
+ .cropper-point.point-nw {
257
+ cursor: nwse-resize;
258
+ left: -3px;
259
+ top: -3px;
260
+ }
261
+
262
+ .cropper-point.point-sw {
263
+ bottom: -3px;
264
+ cursor: nesw-resize;
265
+ left: -3px;
266
+ }
267
+
268
+ .cropper-point.point-se {
269
+ bottom: -3px;
270
+ cursor: nwse-resize;
271
+ height: 20px;
272
+ opacity: 1;
273
+ right: -3px;
274
+ width: 20px;
275
+ }
276
+
277
+ @media (min-width: 768px) {
278
+ .cropper-point.point-se {
279
+ height: 15px;
280
+ width: 15px;
281
+ }
282
+ }
283
+
284
+ @media (min-width: 992px) {
285
+ .cropper-point.point-se {
286
+ height: 10px;
287
+ width: 10px;
288
+ }
289
+ }
290
+
291
+ @media (min-width: 1200px) {
292
+ .cropper-point.point-se {
293
+ height: 5px;
294
+ opacity: 0.75;
295
+ width: 5px;
296
+ }
297
+ }
298
+
299
+ .cropper-point.point-se::before {
300
+ background-color: #39f;
301
+ bottom: -50%;
302
+ content: ' ';
303
+ display: block;
304
+ height: 200%;
305
+ opacity: 0;
306
+ position: absolute;
307
+ right: -50%;
308
+ width: 200%;
309
+ }
310
+
311
+ .cropper-invisible {
312
+ opacity: 0;
313
+ }
314
+
315
+ .cropper-bg {
316
+ background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQAQMAAAAlPW0iAAAAA3NCSVQICAjb4U/gAAAABlBMVEXMzMz////TjRV2AAAACXBIWXMAAArrAAAK6wGCiw1aAAAAHHRFWHRTb2Z0d2FyZQBBZG9iZSBGaXJld29ya3MgQ1M26LyyjAAAABFJREFUCJlj+M/AgBVhF/0PAH6/D/HkDxOGAAAAAElFTkSuQmCC');
317
+ }
318
+
319
+ .cropper-hide {
320
+ display: block;
321
+ height: 0;
322
+ position: absolute;
323
+ width: 0;
324
+ }
325
+
326
+ .cropper-hidden {
327
+ display: none !important;
328
+ }
329
+
330
+ .cropper-move {
331
+ cursor: move;
332
+ }
333
+
334
+ .cropper-crop {
335
+ cursor: crosshair;
336
+ }
337
+
338
+ .cropper-disabled .cropper-drag-box,
339
+ .cropper-disabled .cropper-face,
340
+ .cropper-disabled .cropper-line,
341
+ .cropper-disabled .cropper-point {
342
+ cursor: not-allowed;
343
+ }
344
+ `;
345
+ const styles = {
29
346
  dropZone: {
30
- width: '100%',
31
- height: 100,
32
- position: 'relative'
347
+ width: '100%',
348
+ height: 100,
349
+ position: 'relative',
33
350
  },
34
351
  dropZoneEmpty: {},
35
352
  image: {
36
- objectFit: 'contain',
37
- margin: 'auto',
38
- display: 'flex',
39
- width: '100%',
40
- height: '100%'
353
+ objectFit: 'contain',
354
+ margin: 'auto',
355
+ display: 'flex',
356
+ width: '100%',
357
+ height: '100%',
41
358
  },
42
359
  uploadDiv: {
43
- position: 'relative',
44
- width: '100%',
45
- height: 300,
46
- opacity: 0.9,
47
- marginTop: 30,
48
- cursor: 'pointer',
49
- outline: 'none'
360
+ position: 'relative',
361
+ width: '100%',
362
+ height: 300,
363
+ opacity: 0.9,
364
+ marginTop: 30,
365
+ cursor: 'pointer',
366
+ outline: 'none',
50
367
  },
51
368
  uploadDivDragging: {
52
- opacity: 1,
53
- background: 'rgba(128,255,128,0.1)'
369
+ opacity: 1,
370
+ background: 'rgba(128,255,128,0.1)',
54
371
  },
55
372
  uploadCenterDiv: {
56
- margin: 5,
57
- border: '3px dashed grey',
58
- borderRadius: 5,
59
- width: 'calc(100% - 10px)',
60
- height: 'calc(100% - 10px)',
61
- position: 'relative',
62
- display: 'flex'
373
+ margin: 5,
374
+ border: '3px dashed grey',
375
+ borderRadius: 5,
376
+ width: 'calc(100% - 10px)',
377
+ height: 'calc(100% - 10px)',
378
+ position: 'relative',
379
+ display: 'flex',
63
380
  },
64
381
  uploadCenterIcon: {
65
- paddingTop: 10,
66
- width: 48,
67
- height: 48
382
+ paddingTop: 10,
383
+ width: 48,
384
+ height: 48,
68
385
  },
69
386
  uploadCenterText: {
70
- fontSize: 16
387
+ fontSize: 16,
71
388
  },
72
389
  uploadCenterTextAndIcon: {
73
- textAlign: 'center',
74
- position: 'absolute',
75
- top: 0,
76
- bottom: 0,
77
- left: 0,
78
- right: 0,
79
- display: 'flex',
80
- flexDirection: 'column',
81
- alignItems: 'center',
82
- justifyContent: 'center'
390
+ textAlign: 'center',
391
+ position: 'absolute',
392
+ top: 0,
393
+ bottom: 0,
394
+ left: 0,
395
+ right: 0,
396
+ display: 'flex',
397
+ flexDirection: 'column',
398
+ alignItems: 'center',
399
+ justifyContent: 'center',
83
400
  },
84
401
  disabledOpacity: {
85
- opacity: 0.3,
86
- cursor: 'default'
402
+ opacity: 0.3,
403
+ cursor: 'default',
87
404
  },
88
405
  buttonRemoveWrapper: {
89
- position: 'absolute',
90
- zIndex: 222,
91
- right: 0
406
+ position: 'absolute',
407
+ zIndex: 222,
408
+ right: 0,
92
409
  },
93
410
  buttonCropWrapper: {
94
- position: 'absolute',
95
- zIndex: 222,
96
- right: 0,
97
- top: 50
411
+ position: 'absolute',
412
+ zIndex: 222,
413
+ right: 0,
414
+ top: 50,
98
415
  },
99
416
  error: {
100
- border: '2px solid red',
101
- boxSizing: 'border-box'
102
- }
103
- };
417
+ border: '2px solid red',
418
+ boxSizing: 'border-box',
419
+ },
104
420
  };
105
- var UploadImage = /*#__PURE__*/function (_Component) {
106
- (0, _inherits2["default"])(UploadImage, _Component);
107
- function UploadImage(props) {
108
- var _this;
109
- (0, _classCallCheck2["default"])(this, UploadImage);
110
- _this = _callSuper(this, UploadImage, [props]);
111
- _this.state = {
112
- uploadFile: false,
113
- anchorEl: null,
114
- cropHandler: false
115
- };
116
- _this.cropperRef = /*#__PURE__*/(0, _react.createRef)();
117
- if (!window.document.getElementById('cropper-style-json-component')) {
118
- var style = window.document.createElement('style');
119
- style.setAttribute('id', 'cropper-style-json-component');
120
- style.innerHTML = cropperStyles;
121
- window.document.head.appendChild(style);
122
- }
123
- return _this;
124
- }
125
- (0, _createClass2["default"])(UploadImage, [{
126
- key: "onDrop",
127
- value: function onDrop(acceptedFiles) {
128
- var _this$props = this.props,
129
- maxSize = _this$props.maxSize,
130
- t = _this$props.t,
131
- onChange = _this$props.onChange;
132
- var file = acceptedFiles[0];
133
- var reader = new FileReader();
134
- reader.onabort = function () {
135
- return console.log('file reading was aborted');
136
- };
137
- reader.onerror = function () {
138
- return console.log('file reading has failed');
139
- };
140
- reader.onload = function () {
141
- var ext = "image/".concat(file.name.split('.').pop().toLowerCase());
142
- if (ext === 'image/jpg') {
143
- ext = 'image/jpeg';
144
- } else if (ext.includes('svg')) {
145
- ext = 'image/svg+xml';
421
+ class UploadImage extends react_1.Component {
422
+ constructor(props) {
423
+ super(props);
424
+ this.state = {
425
+ uploadFile: false,
426
+ anchorEl: null,
427
+ cropHandler: false,
428
+ };
429
+ this.cropperRef = (0, react_1.createRef)();
430
+ if (!window.document.getElementById('cropper-style-json-component')) {
431
+ const style = window.document.createElement('style');
432
+ style.setAttribute('id', 'cropper-style-json-component');
433
+ style.innerHTML = cropperStyles;
434
+ window.document.head.appendChild(style);
146
435
  }
147
- if (file.size > maxSize) {
148
- window.alert(t('ra_File is too big. Max %sk allowed. Try use SVG.', Math.round(maxSize / 1024)));
149
- } else {
150
- var base64 = "data:".concat(ext, ";base64,").concat(btoa(new Uint8Array(reader.result).reduce(function (data, _byte) {
151
- return data + String.fromCharCode(_byte);
152
- }, '')));
153
- onChange(base64);
154
- }
155
- };
156
- reader.readAsArrayBuffer(file);
157
436
  }
158
- }, {
159
- key: "render",
160
- value: function render() {
161
- var _this2 = this;
162
- var _this$props2 = this.props,
163
- disabled = _this$props2.disabled,
164
- maxSize = _this$props2.maxSize,
165
- classes = _this$props2.classes,
166
- icon = _this$props2.icon,
167
- t = _this$props2.t,
168
- removeIconFunc = _this$props2.removeIconFunc,
169
- accept = _this$props2.accept,
170
- error = _this$props2.error,
171
- crop = _this$props2.crop,
172
- onChange = _this$props2.onChange;
173
- var _this$state = this.state,
174
- uploadFile = _this$state.uploadFile,
175
- anchorEl = _this$state.anchorEl,
176
- cropHandler = _this$state.cropHandler;
177
- return /*#__PURE__*/React.createElement(_reactDropzone["default"], {
178
- disabled: disabled || cropHandler,
179
- key: "dropzone",
180
- multiple: false,
181
- accept: accept,
182
- maxSize: maxSize,
183
- onDragEnter: function onDragEnter() {
184
- return _this2.setState({
185
- uploadFile: 'dragging'
186
- });
187
- },
188
- onDragLeave: function onDragLeave() {
189
- return _this2.setState({
190
- uploadFile: true
191
- });
192
- },
193
- onDrop: function onDrop(acceptedFiles, errors) {
194
- _this2.setState({
195
- uploadFile: false
196
- });
197
- if (!acceptedFiles.length) {
198
- window.alert(errors && errors[0] && errors[0].errors && errors[0].errors[0] && errors[0].errors[0].message || t('ra_Cannot upload'));
199
- } else {
200
- _this2.onDrop(acceptedFiles);
201
- }
202
- }
203
- }, function (_ref) {
204
- var getRootProps = _ref.getRootProps,
205
- getInputProps = _ref.getInputProps;
206
- return /*#__PURE__*/React.createElement("div", (0, _extends2["default"])({
207
- className: _Utils["default"].clsx(classes.uploadDiv, uploadFile === 'dragging' && classes.uploadDivDragging, classes.dropZone, disabled && classes.disabledOpacity, !icon && classes.dropZoneEmpty)
208
- }, getRootProps()), /*#__PURE__*/React.createElement("input", getInputProps()), /*#__PURE__*/React.createElement("div", {
209
- className: _Utils["default"].clsx(classes.uploadCenterDiv, error && classes.error)
210
- }, !icon ? /*#__PURE__*/React.createElement("div", {
211
- className: classes.uploadCenterTextAndIcon
212
- }, /*#__PURE__*/React.createElement(_fa.FaFileUpload, {
213
- className: classes.uploadCenterIcon
214
- }), /*#__PURE__*/React.createElement("div", {
215
- className: classes.uploadCenterText
216
- }, uploadFile === 'dragging' ? t('ra_Drop file here') : t('ra_Place your files here or click here to open the browse dialog'))) : removeIconFunc && !cropHandler && /*#__PURE__*/React.createElement("div", {
217
- className: classes.buttonRemoveWrapper
218
- }, /*#__PURE__*/React.createElement(_material.Tooltip, {
219
- title: t('ra_Clear')
220
- }, /*#__PURE__*/React.createElement(_material.IconButton, {
221
- size: "large",
222
- onClick: function onClick(e) {
223
- removeIconFunc && removeIconFunc();
224
- e.stopPropagation();
225
- }
226
- }, /*#__PURE__*/React.createElement(_iconsMaterial.Close, null)))), icon && crop && /*#__PURE__*/React.createElement("div", {
227
- className: classes.buttonCropWrapper
228
- }, /*#__PURE__*/React.createElement(_material.Tooltip, {
229
- title: t('ra_Crop')
230
- }, /*#__PURE__*/React.createElement(_material.IconButton, {
231
- size: "large",
232
- onClick: function onClick(e) {
233
- if (!cropHandler) {
234
- _this2.setState({
235
- cropHandler: true
236
- });
237
- } else {
238
- _this2.setState({
239
- anchorEl: e.currentTarget
240
- });
437
+ onDrop(acceptedFiles) {
438
+ const onChange = this.props.onChange;
439
+ const maxSize = this.props.maxSize || 10 * 1024;
440
+ const file = acceptedFiles[0];
441
+ const reader = new FileReader();
442
+ reader.onabort = () => console.log('file reading was aborted');
443
+ reader.onerror = () => console.log('file reading has failed');
444
+ reader.onload = () => {
445
+ var _a, _b;
446
+ if (!file || !file.name) {
447
+ return;
241
448
  }
242
- e.stopPropagation();
243
- }
244
- }, /*#__PURE__*/React.createElement(_iconsMaterial.Crop, {
245
- color: cropHandler ? 'primary' : 'inherit'
246
- }))), /*#__PURE__*/React.createElement(_material.Menu, {
247
- anchorEl: anchorEl,
248
- keepMounted: true,
249
- open: Boolean(anchorEl),
250
- onClose: function onClose() {
251
- return _this2.setState({
252
- anchorEl: null
253
- });
254
- }
255
- }, /*#__PURE__*/React.createElement(_material.MenuItem, {
256
- onClick: function onClick() {
257
- return _this2.setState({
258
- anchorEl: null,
259
- cropHandler: false
260
- }, function () {
261
- var _this2$cropperRef;
262
- var imageElement = (_this2$cropperRef = _this2.cropperRef) === null || _this2$cropperRef === void 0 || (_this2$cropperRef = _this2$cropperRef.current) === null || _this2$cropperRef === void 0 ? void 0 : _this2$cropperRef.cropper;
263
- onChange(imageElement.getCroppedCanvas().toDataURL());
264
- });
265
- }
266
- }, t('ra_Save')), /*#__PURE__*/React.createElement(_material.MenuItem, {
267
- onClick: function onClick() {
268
- return _this2.setState({
269
- anchorEl: null,
270
- cropHandler: false
271
- });
272
- }
273
- }, t('ra_Close')))), icon && !cropHandler ? /*#__PURE__*/React.createElement("img", {
274
- src: icon,
275
- className: classes.image,
276
- alt: "icon"
277
- }) : null, icon && crop && cropHandler ? /*#__PURE__*/React.createElement(_reactCropper.Cropper, {
278
- ref: _this2.cropperRef,
279
- className: classes.image,
280
- src: icon,
281
- initialAspectRatio: 1,
282
- viewMode: 1,
283
- guides: false,
284
- minCropBoxHeight: 10,
285
- minCropBoxWidth: 10,
286
- background: false,
287
- checkOrientation: false
288
- }) : null));
289
- });
449
+ const parts = (_a = file.name) === null || _a === void 0 ? void 0 : _a.split('.');
450
+ let ext = (parts === null || parts === void 0 ? void 0 : parts.length) ? `image/${(_b = parts.pop()) === null || _b === void 0 ? void 0 : _b.toLowerCase()}` : 'image/jpeg';
451
+ if (ext === 'image/jpg') {
452
+ ext = 'image/jpeg';
453
+ }
454
+ else if (ext.includes('svg')) {
455
+ ext = 'image/svg+xml';
456
+ }
457
+ if (file.size > maxSize) {
458
+ window.alert(i18n_1.default.t('ra_File is too big. Max %sk allowed. Try use SVG.', Math.round(maxSize / 1024)));
459
+ }
460
+ else {
461
+ const base64 = `data:${ext};base64,${btoa(new Uint8Array(reader.result)
462
+ .reduce((data, byte) => data + String.fromCharCode(byte), ''))}`;
463
+ if (onChange) {
464
+ onChange(base64);
465
+ }
466
+ else {
467
+ console.log(base64);
468
+ }
469
+ }
470
+ };
471
+ reader.readAsArrayBuffer(file);
290
472
  }
291
- }]);
292
- return UploadImage;
293
- }(_react.Component);
294
- UploadImage.defaultProps = {
295
- disabled: false,
296
- maxSize: 10 * 1024,
297
- icon: null,
298
- removeIconFunc: null,
299
- accept: {
300
- 'image/*': []
301
- },
302
- error: false,
303
- onChange: function onChange(base64) {
304
- return console.log(base64);
305
- },
306
- t: function t(el) {
307
- return el;
308
- },
309
- crop: false
310
- };
311
- UploadImage.propTypes = {
312
- classes: _propTypes["default"].object,
313
- maxSize: _propTypes["default"].number,
314
- disabled: _propTypes["default"].bool,
315
- crop: _propTypes["default"].bool,
316
- error: _propTypes["default"].bool,
317
- onChange: _propTypes["default"].func,
318
- icon: _propTypes["default"].string,
319
- removeIconFunc: _propTypes["default"].func,
320
- accept: _propTypes["default"].object,
321
- t: _propTypes["default"].func
322
- };
323
- var _default = exports["default"] = (0, _styles.withStyles)(styles)(UploadImage);
324
- //# sourceMappingURL=UploadImage.js.map
473
+ render() {
474
+ const { disabled, classes, icon, removeIconFunc, error, crop, onChange, } = this.props;
475
+ const maxSize = this.props.maxSize || 10 * 1024;
476
+ const accept = this.props.accept || { 'image/*': [] };
477
+ const { uploadFile, anchorEl, cropHandler } = this.state;
478
+ return react_1.default.createElement(react_dropzone_1.default, { disabled: !!disabled || cropHandler, key: "dropzone", multiple: false, accept: accept, maxSize: maxSize, onDragEnter: () => this.setState({ uploadFile: 'dragging' }), onDragLeave: () => this.setState({ uploadFile: true }), onDrop: (acceptedFiles, errors) => {
479
+ this.setState({ uploadFile: false });
480
+ if (!acceptedFiles.length) {
481
+ window.alert((errors && errors[0] && errors[0].errors && errors[0].errors[0] && errors[0].errors[0].message) || i18n_1.default.t('ra_Cannot upload'));
482
+ }
483
+ else {
484
+ this.onDrop(acceptedFiles);
485
+ }
486
+ } }, ({ getRootProps, getInputProps }) => react_1.default.createElement("div", Object.assign({ className: Utils_1.default.clsx(classes.uploadDiv, uploadFile === 'dragging' && classes.uploadDivDragging, classes.dropZone, disabled && classes.disabledOpacity, !icon && classes.dropZoneEmpty) }, getRootProps()),
487
+ react_1.default.createElement("input", Object.assign({}, getInputProps())),
488
+ react_1.default.createElement("div", { className: Utils_1.default.clsx(classes.uploadCenterDiv, error && classes.error) },
489
+ !icon ? react_1.default.createElement("div", { className: classes.uploadCenterTextAndIcon },
490
+ react_1.default.createElement(fa_1.FaFileUpload, { className: classes.uploadCenterIcon }),
491
+ react_1.default.createElement("div", { className: classes.uploadCenterText }, uploadFile === 'dragging' ? i18n_1.default.t('ra_Drop file here') :
492
+ i18n_1.default.t('ra_Place your files here or click here to open the browse dialog')))
493
+ :
494
+ removeIconFunc && !cropHandler && react_1.default.createElement("div", { className: classes.buttonRemoveWrapper },
495
+ react_1.default.createElement(material_1.Tooltip, { title: i18n_1.default.t('ra_Clear') },
496
+ react_1.default.createElement(material_1.IconButton, { size: "large", onClick: e => {
497
+ removeIconFunc && removeIconFunc();
498
+ e.stopPropagation();
499
+ } },
500
+ react_1.default.createElement(icons_material_1.Close, null)))),
501
+ icon && crop && react_1.default.createElement("div", { className: classes.buttonCropWrapper },
502
+ react_1.default.createElement(material_1.Tooltip, { title: i18n_1.default.t('ra_Crop') },
503
+ react_1.default.createElement(material_1.IconButton, { size: "large", onClick: e => {
504
+ if (!cropHandler) {
505
+ this.setState({ cropHandler: true });
506
+ }
507
+ else {
508
+ this.setState({ anchorEl: e.currentTarget });
509
+ }
510
+ e.stopPropagation();
511
+ } },
512
+ react_1.default.createElement(icons_material_1.Crop, { color: cropHandler ? 'primary' : 'inherit' }))),
513
+ react_1.default.createElement(material_1.Menu, { anchorEl: anchorEl, keepMounted: true, open: Boolean(anchorEl), onClose: () => this.setState({ anchorEl: null }) },
514
+ react_1.default.createElement(material_1.MenuItem, { onClick: () => this.setState({ anchorEl: null, cropHandler: false }, () => {
515
+ var _a, _b;
516
+ const imageElement = (_b = (_a = this.cropperRef) === null || _a === void 0 ? void 0 : _a.current) === null || _b === void 0 ? void 0 : _b.cropper;
517
+ if (imageElement) {
518
+ if (onChange) {
519
+ onChange(imageElement.getCroppedCanvas().toDataURL());
520
+ }
521
+ else {
522
+ console.log(imageElement.getCroppedCanvas().toDataURL());
523
+ }
524
+ }
525
+ }) }, i18n_1.default.t('ra_Save')),
526
+ react_1.default.createElement(material_1.MenuItem, { onClick: () => this.setState({ anchorEl: null, cropHandler: false }) }, i18n_1.default.t('ra_Close')))),
527
+ icon && !cropHandler ? react_1.default.createElement("img", { src: icon, className: classes.image, alt: "icon" }) : null,
528
+ icon && crop && cropHandler ? react_1.default.createElement(react_cropper_1.Cropper, { ref: this.cropperRef, className: classes.image, src: icon, initialAspectRatio: 1, viewMode: 1, guides: false, minCropBoxHeight: 10, minCropBoxWidth: 10, background: false, checkOrientation: false }) : null)));
529
+ }
530
+ }
531
+ exports.default = (0, styles_1.withStyles)(styles)(UploadImage);