@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.
- package/Components/404.d.ts +5 -2
- package/Components/404.js +83 -105
- package/Components/ColorPicker.js.map +1 -1
- package/Components/FileViewer.d.ts +0 -1
- package/Components/FileViewer.js +1 -2
- package/Components/FileViewer.js.map +1 -1
- package/Components/Icon.d.ts +10 -17
- package/Components/Icon.js +104 -161
- package/Components/IconPicker.d.ts +16 -61
- package/Components/IconPicker.js +100 -158
- package/Components/Loader.d.ts +22 -33
- package/Components/Loader.js +276 -102
- package/Components/TabContainer.d.ts +1 -1
- package/Components/TextWithIcon.d.ts +21 -16
- package/Components/TextWithIcon.js +104 -125
- package/Components/UploadImage.d.ts +13 -1
- package/Components/UploadImage.js +499 -292
- package/Dialogs/TextInput.d.ts +2 -86
- package/Dialogs/TextInput.js +37 -130
- package/LegacyConnection.d.ts +3 -3
- package/README.md +6 -3
- package/Theme.d.ts +3 -4
- package/Theme.js +389 -382
- package/i18n.d.ts +38 -55
- package/i18n.js +164 -189
- package/package.json +1 -1
- package/types.d.ts +4 -2
- package/Components/404.js.map +0 -1
- package/Components/Icon.js.map +0 -1
- package/Components/IconPicker.js.map +0 -1
- package/Components/Loader.js.map +0 -1
- package/Components/TextWithIcon.js.map +0 -1
- package/Components/UploadImage.js.map +0 -1
- package/Dialogs/TextInput.js.map +0 -1
- package/Theme.js.map +0 -1
- package/i18n.js.map +0 -1
|
@@ -1,324 +1,531 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
Object.
|
|
5
|
-
|
|
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
|
-
|
|
8
|
-
|
|
9
|
-
var
|
|
10
|
-
var
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
var
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
-
|
|
31
|
-
|
|
32
|
-
|
|
347
|
+
width: '100%',
|
|
348
|
+
height: 100,
|
|
349
|
+
position: 'relative',
|
|
33
350
|
},
|
|
34
351
|
dropZoneEmpty: {},
|
|
35
352
|
image: {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
353
|
+
objectFit: 'contain',
|
|
354
|
+
margin: 'auto',
|
|
355
|
+
display: 'flex',
|
|
356
|
+
width: '100%',
|
|
357
|
+
height: '100%',
|
|
41
358
|
},
|
|
42
359
|
uploadDiv: {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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
|
-
|
|
53
|
-
|
|
369
|
+
opacity: 1,
|
|
370
|
+
background: 'rgba(128,255,128,0.1)',
|
|
54
371
|
},
|
|
55
372
|
uploadCenterDiv: {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
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
|
-
|
|
66
|
-
|
|
67
|
-
|
|
382
|
+
paddingTop: 10,
|
|
383
|
+
width: 48,
|
|
384
|
+
height: 48,
|
|
68
385
|
},
|
|
69
386
|
uploadCenterText: {
|
|
70
|
-
|
|
387
|
+
fontSize: 16,
|
|
71
388
|
},
|
|
72
389
|
uploadCenterTextAndIcon: {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
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
|
-
|
|
86
|
-
|
|
402
|
+
opacity: 0.3,
|
|
403
|
+
cursor: 'default',
|
|
87
404
|
},
|
|
88
405
|
buttonRemoveWrapper: {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
406
|
+
position: 'absolute',
|
|
407
|
+
zIndex: 222,
|
|
408
|
+
right: 0,
|
|
92
409
|
},
|
|
93
410
|
buttonCropWrapper: {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
411
|
+
position: 'absolute',
|
|
412
|
+
zIndex: 222,
|
|
413
|
+
right: 0,
|
|
414
|
+
top: 50,
|
|
98
415
|
},
|
|
99
416
|
error: {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
}
|
|
103
|
-
};
|
|
417
|
+
border: '2px solid red',
|
|
418
|
+
boxSizing: 'border-box',
|
|
419
|
+
},
|
|
104
420
|
};
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
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
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
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
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
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
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
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);
|