@vaadin/upload 23.1.0-alpha3 → 23.1.0-beta2
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vaadin/upload",
|
|
3
|
-
"version": "23.1.0-
|
|
3
|
+
"version": "23.1.0-beta2",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -34,18 +34,18 @@
|
|
|
34
34
|
],
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@polymer/polymer": "^3.0.0",
|
|
37
|
-
"@vaadin/button": "23.1.0-
|
|
38
|
-
"@vaadin/component-base": "23.1.0-
|
|
39
|
-
"@vaadin/progress-bar": "23.1.0-
|
|
40
|
-
"@vaadin/vaadin-lumo-styles": "23.1.0-
|
|
41
|
-
"@vaadin/vaadin-material-styles": "23.1.0-
|
|
42
|
-
"@vaadin/vaadin-themable-mixin": "23.1.0-
|
|
37
|
+
"@vaadin/button": "23.1.0-beta2",
|
|
38
|
+
"@vaadin/component-base": "23.1.0-beta2",
|
|
39
|
+
"@vaadin/progress-bar": "23.1.0-beta2",
|
|
40
|
+
"@vaadin/vaadin-lumo-styles": "23.1.0-beta2",
|
|
41
|
+
"@vaadin/vaadin-material-styles": "23.1.0-beta2",
|
|
42
|
+
"@vaadin/vaadin-themable-mixin": "23.1.0-beta2"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@esm-bundle/chai": "^4.3.4",
|
|
46
|
-
"@vaadin/form-layout": "23.1.0-
|
|
46
|
+
"@vaadin/form-layout": "23.1.0-beta2",
|
|
47
47
|
"@vaadin/testing-helpers": "^0.3.2",
|
|
48
48
|
"sinon": "^13.0.2"
|
|
49
49
|
},
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "f11f9245a0b5e6bf912725a501c27c24b74e7c8d"
|
|
51
51
|
}
|
|
@@ -143,8 +143,8 @@ class UploadFile extends FocusMixin(ThemableMixin(PolymerElement)) {
|
|
|
143
143
|
tabindex: {
|
|
144
144
|
type: Number,
|
|
145
145
|
value: 0,
|
|
146
|
-
reflectToAttribute: true
|
|
147
|
-
}
|
|
146
|
+
reflectToAttribute: true,
|
|
147
|
+
},
|
|
148
148
|
};
|
|
149
149
|
}
|
|
150
150
|
|
|
@@ -154,7 +154,7 @@ class UploadFile extends FocusMixin(ThemableMixin(PolymerElement)) {
|
|
|
154
154
|
'_toggleHostAttribute(file.error, "error")',
|
|
155
155
|
'_toggleHostAttribute(file.indeterminate, "indeterminate")',
|
|
156
156
|
'_toggleHostAttribute(file.uploading, "uploading")',
|
|
157
|
-
'_toggleHostAttribute(file.complete, "complete")'
|
|
157
|
+
'_toggleHostAttribute(file.complete, "complete")',
|
|
158
158
|
];
|
|
159
159
|
}
|
|
160
160
|
|
|
@@ -203,8 +203,8 @@ class UploadFile extends FocusMixin(ThemableMixin(PolymerElement)) {
|
|
|
203
203
|
new CustomEvent('file-remove', {
|
|
204
204
|
detail: { file: this.file },
|
|
205
205
|
bubbles: true,
|
|
206
|
-
composed: true
|
|
207
|
-
})
|
|
206
|
+
composed: true,
|
|
207
|
+
}),
|
|
208
208
|
);
|
|
209
209
|
}
|
|
210
210
|
|
|
@@ -220,8 +220,8 @@ class UploadFile extends FocusMixin(ThemableMixin(PolymerElement)) {
|
|
|
220
220
|
new CustomEvent(e.target.getAttribute('file-event'), {
|
|
221
221
|
detail: { file: this.file },
|
|
222
222
|
bubbles: true,
|
|
223
|
-
composed: true
|
|
224
|
-
})
|
|
223
|
+
composed: true,
|
|
224
|
+
}),
|
|
225
225
|
);
|
|
226
226
|
}
|
|
227
227
|
|
package/src/vaadin-upload.d.ts
CHANGED
|
@@ -59,8 +59,8 @@ export interface UploadI18n {
|
|
|
59
59
|
size: string[];
|
|
60
60
|
sizeBase?: number;
|
|
61
61
|
};
|
|
62
|
-
formatSize
|
|
63
|
-
formatTime
|
|
62
|
+
formatSize?(bytes: number): string;
|
|
63
|
+
formatTime?(seconds: number, units: number[]): string;
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
export type UploadMethod = 'POST' | 'PUT';
|
|
@@ -401,13 +401,13 @@ declare class Upload extends ThemableMixin(ElementMixin(HTMLElement)) {
|
|
|
401
401
|
addEventListener<K extends keyof UploadEventMap>(
|
|
402
402
|
type: K,
|
|
403
403
|
listener: (this: Upload, ev: UploadEventMap[K]) => void,
|
|
404
|
-
options?: boolean | AddEventListenerOptions
|
|
404
|
+
options?: boolean | AddEventListenerOptions,
|
|
405
405
|
): void;
|
|
406
406
|
|
|
407
407
|
removeEventListener<K extends keyof UploadEventMap>(
|
|
408
408
|
type: K,
|
|
409
409
|
listener: (this: Upload, ev: UploadEventMap[K]) => void,
|
|
410
|
-
options?: boolean | EventListenerOptions
|
|
410
|
+
options?: boolean | EventListenerOptions,
|
|
411
411
|
): void;
|
|
412
412
|
}
|
|
413
413
|
|
package/src/vaadin-upload.js
CHANGED
|
@@ -143,7 +143,7 @@ class Upload extends ElementMixin(ThemableMixin(PolymerElement)) {
|
|
|
143
143
|
nodrop: {
|
|
144
144
|
type: Boolean,
|
|
145
145
|
reflectToAttribute: true,
|
|
146
|
-
value: isTouch
|
|
146
|
+
value: isTouch,
|
|
147
147
|
},
|
|
148
148
|
|
|
149
149
|
/**
|
|
@@ -153,7 +153,7 @@ class Upload extends ElementMixin(ThemableMixin(PolymerElement)) {
|
|
|
153
153
|
*/
|
|
154
154
|
target: {
|
|
155
155
|
type: String,
|
|
156
|
-
value: ''
|
|
156
|
+
value: '',
|
|
157
157
|
},
|
|
158
158
|
|
|
159
159
|
/**
|
|
@@ -162,7 +162,7 @@ class Upload extends ElementMixin(ThemableMixin(PolymerElement)) {
|
|
|
162
162
|
*/
|
|
163
163
|
method: {
|
|
164
164
|
type: String,
|
|
165
|
-
value: 'POST'
|
|
165
|
+
value: 'POST',
|
|
166
166
|
},
|
|
167
167
|
|
|
168
168
|
/**
|
|
@@ -175,7 +175,7 @@ class Upload extends ElementMixin(ThemableMixin(PolymerElement)) {
|
|
|
175
175
|
*/
|
|
176
176
|
headers: {
|
|
177
177
|
type: Object,
|
|
178
|
-
value: {}
|
|
178
|
+
value: {},
|
|
179
179
|
},
|
|
180
180
|
|
|
181
181
|
/**
|
|
@@ -185,14 +185,14 @@ class Upload extends ElementMixin(ThemableMixin(PolymerElement)) {
|
|
|
185
185
|
*/
|
|
186
186
|
timeout: {
|
|
187
187
|
type: Number,
|
|
188
|
-
value: 0
|
|
188
|
+
value: 0,
|
|
189
189
|
},
|
|
190
190
|
|
|
191
191
|
/** @private */
|
|
192
192
|
_dragover: {
|
|
193
193
|
type: Boolean,
|
|
194
194
|
value: false,
|
|
195
|
-
observer: '_dragoverChanged'
|
|
195
|
+
observer: '_dragoverChanged',
|
|
196
196
|
},
|
|
197
197
|
|
|
198
198
|
/**
|
|
@@ -221,9 +221,7 @@ class Upload extends ElementMixin(ThemableMixin(PolymerElement)) {
|
|
|
221
221
|
files: {
|
|
222
222
|
type: Array,
|
|
223
223
|
notify: true,
|
|
224
|
-
value:
|
|
225
|
-
return [];
|
|
226
|
-
}
|
|
224
|
+
value: () => [],
|
|
227
225
|
},
|
|
228
226
|
|
|
229
227
|
/**
|
|
@@ -234,7 +232,7 @@ class Upload extends ElementMixin(ThemableMixin(PolymerElement)) {
|
|
|
234
232
|
*/
|
|
235
233
|
maxFiles: {
|
|
236
234
|
type: Number,
|
|
237
|
-
value: Infinity
|
|
235
|
+
value: Infinity,
|
|
238
236
|
},
|
|
239
237
|
|
|
240
238
|
/**
|
|
@@ -248,7 +246,7 @@ class Upload extends ElementMixin(ThemableMixin(PolymerElement)) {
|
|
|
248
246
|
notify: true,
|
|
249
247
|
readOnly: true,
|
|
250
248
|
reflectToAttribute: true,
|
|
251
|
-
computed: '_maxFilesAdded(maxFiles, files.length)'
|
|
249
|
+
computed: '_maxFilesAdded(maxFiles, files.length)',
|
|
252
250
|
},
|
|
253
251
|
|
|
254
252
|
/**
|
|
@@ -262,7 +260,7 @@ class Upload extends ElementMixin(ThemableMixin(PolymerElement)) {
|
|
|
262
260
|
*/
|
|
263
261
|
accept: {
|
|
264
262
|
type: String,
|
|
265
|
-
value: ''
|
|
263
|
+
value: '',
|
|
266
264
|
},
|
|
267
265
|
|
|
268
266
|
/**
|
|
@@ -275,7 +273,7 @@ class Upload extends ElementMixin(ThemableMixin(PolymerElement)) {
|
|
|
275
273
|
*/
|
|
276
274
|
maxFileSize: {
|
|
277
275
|
type: Number,
|
|
278
|
-
value: Infinity
|
|
276
|
+
value: Infinity,
|
|
279
277
|
},
|
|
280
278
|
|
|
281
279
|
/**
|
|
@@ -286,7 +284,7 @@ class Upload extends ElementMixin(ThemableMixin(PolymerElement)) {
|
|
|
286
284
|
_dragoverValid: {
|
|
287
285
|
type: Boolean,
|
|
288
286
|
value: false,
|
|
289
|
-
observer: '_dragoverValidChanged'
|
|
287
|
+
observer: '_dragoverValidChanged',
|
|
290
288
|
},
|
|
291
289
|
|
|
292
290
|
/**
|
|
@@ -296,7 +294,7 @@ class Upload extends ElementMixin(ThemableMixin(PolymerElement)) {
|
|
|
296
294
|
*/
|
|
297
295
|
formDataName: {
|
|
298
296
|
type: String,
|
|
299
|
-
value: 'file'
|
|
297
|
+
value: 'file',
|
|
300
298
|
},
|
|
301
299
|
|
|
302
300
|
/**
|
|
@@ -307,7 +305,7 @@ class Upload extends ElementMixin(ThemableMixin(PolymerElement)) {
|
|
|
307
305
|
*/
|
|
308
306
|
noAuto: {
|
|
309
307
|
type: Boolean,
|
|
310
|
-
value: false
|
|
308
|
+
value: false,
|
|
311
309
|
},
|
|
312
310
|
|
|
313
311
|
/**
|
|
@@ -317,7 +315,7 @@ class Upload extends ElementMixin(ThemableMixin(PolymerElement)) {
|
|
|
317
315
|
*/
|
|
318
316
|
withCredentials: {
|
|
319
317
|
type: Boolean,
|
|
320
|
-
value: false
|
|
318
|
+
value: false,
|
|
321
319
|
},
|
|
322
320
|
|
|
323
321
|
/**
|
|
@@ -388,49 +386,49 @@ class Upload extends ElementMixin(ThemableMixin(PolymerElement)) {
|
|
|
388
386
|
*/
|
|
389
387
|
i18n: {
|
|
390
388
|
type: Object,
|
|
391
|
-
value
|
|
389
|
+
value() {
|
|
392
390
|
return {
|
|
393
391
|
dropFiles: {
|
|
394
392
|
one: 'Drop file here',
|
|
395
|
-
many: 'Drop files here'
|
|
393
|
+
many: 'Drop files here',
|
|
396
394
|
},
|
|
397
395
|
addFiles: {
|
|
398
396
|
one: 'Upload File...',
|
|
399
|
-
many: 'Upload Files...'
|
|
397
|
+
many: 'Upload Files...',
|
|
400
398
|
},
|
|
401
399
|
error: {
|
|
402
400
|
tooManyFiles: 'Too Many Files.',
|
|
403
401
|
fileIsTooBig: 'File is Too Big.',
|
|
404
|
-
incorrectFileType: 'Incorrect File Type.'
|
|
402
|
+
incorrectFileType: 'Incorrect File Type.',
|
|
405
403
|
},
|
|
406
404
|
uploading: {
|
|
407
405
|
status: {
|
|
408
406
|
connecting: 'Connecting...',
|
|
409
407
|
stalled: 'Stalled',
|
|
410
408
|
processing: 'Processing File...',
|
|
411
|
-
held: 'Queued'
|
|
409
|
+
held: 'Queued',
|
|
412
410
|
},
|
|
413
411
|
remainingTime: {
|
|
414
412
|
prefix: 'remaining time: ',
|
|
415
|
-
unknown: 'unknown remaining time'
|
|
413
|
+
unknown: 'unknown remaining time',
|
|
416
414
|
},
|
|
417
415
|
error: {
|
|
418
416
|
serverUnavailable: 'Upload failed, please try again later',
|
|
419
417
|
unexpectedServerError: 'Upload failed due to server error',
|
|
420
|
-
forbidden: 'Upload forbidden'
|
|
421
|
-
}
|
|
418
|
+
forbidden: 'Upload forbidden',
|
|
419
|
+
},
|
|
422
420
|
},
|
|
423
421
|
file: {
|
|
424
422
|
retry: 'Retry',
|
|
425
423
|
start: 'Start',
|
|
426
|
-
remove: 'Remove'
|
|
424
|
+
remove: 'Remove',
|
|
427
425
|
},
|
|
428
426
|
units: {
|
|
429
|
-
size: ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
|
|
430
|
-
}
|
|
427
|
+
size: ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'],
|
|
428
|
+
},
|
|
431
429
|
};
|
|
432
|
-
}
|
|
433
|
-
}
|
|
430
|
+
},
|
|
431
|
+
},
|
|
434
432
|
};
|
|
435
433
|
}
|
|
436
434
|
|
|
@@ -461,7 +459,7 @@ class Upload extends ElementMixin(ThemableMixin(PolymerElement)) {
|
|
|
461
459
|
const unit = ~~(Math.log(bytes) / Math.log(base));
|
|
462
460
|
const dec = Math.max(0, Math.min(3, unit - 1));
|
|
463
461
|
const size = parseFloat((bytes / base ** unit).toFixed(dec));
|
|
464
|
-
return size
|
|
462
|
+
return `${size} ${this.i18n.units.size[unit]}`;
|
|
465
463
|
}
|
|
466
464
|
|
|
467
465
|
/** @private */
|
|
@@ -469,7 +467,7 @@ class Upload extends ElementMixin(ThemableMixin(PolymerElement)) {
|
|
|
469
467
|
const unitSizes = [60, 60, 24, Infinity];
|
|
470
468
|
const timeValues = [0];
|
|
471
469
|
|
|
472
|
-
for (
|
|
470
|
+
for (let i = 0; i < unitSizes.length && time > 0; i++) {
|
|
473
471
|
timeValues[i] = time % unitSizes[i];
|
|
474
472
|
time = Math.floor(time / unitSizes[i]);
|
|
475
473
|
}
|
|
@@ -498,16 +496,12 @@ class Upload extends ElementMixin(ThemableMixin(PolymerElement)) {
|
|
|
498
496
|
|
|
499
497
|
/** @private */
|
|
500
498
|
_formatFileProgress(file) {
|
|
501
|
-
|
|
502
|
-
file.
|
|
503
|
-
': ' +
|
|
504
|
-
file.progress +
|
|
505
|
-
'% (' +
|
|
506
|
-
(file.loaded > 0
|
|
499
|
+
const remainingTime =
|
|
500
|
+
file.loaded > 0
|
|
507
501
|
? this.i18n.uploading.remainingTime.prefix + file.remainingStr
|
|
508
|
-
: this.i18n.uploading.remainingTime.unknown
|
|
509
|
-
|
|
510
|
-
)
|
|
502
|
+
: this.i18n.uploading.remainingTime.unknown;
|
|
503
|
+
|
|
504
|
+
return `${file.totalStr}: ${file.progress}% (${remainingTime})`;
|
|
511
505
|
}
|
|
512
506
|
|
|
513
507
|
/** @private */
|
|
@@ -549,14 +543,14 @@ class Upload extends ElementMixin(ThemableMixin(PolymerElement)) {
|
|
|
549
543
|
|
|
550
544
|
/** @private */
|
|
551
545
|
_configureXhr(xhr) {
|
|
552
|
-
if (typeof this.headers
|
|
546
|
+
if (typeof this.headers === 'string') {
|
|
553
547
|
try {
|
|
554
548
|
this.headers = JSON.parse(this.headers);
|
|
555
549
|
} catch (e) {
|
|
556
550
|
this.headers = undefined;
|
|
557
551
|
}
|
|
558
552
|
}
|
|
559
|
-
for (
|
|
553
|
+
for (const key in this.headers) {
|
|
560
554
|
xhr.setRequestHeader(key, this.headers[key]);
|
|
561
555
|
}
|
|
562
556
|
if (this.timeout) {
|
|
@@ -601,7 +595,7 @@ class Upload extends ElementMixin(ThemableMixin(PolymerElement)) {
|
|
|
601
595
|
const xhr = (file.xhr = this._createXhr());
|
|
602
596
|
|
|
603
597
|
let stalledId, last;
|
|
604
|
-
//
|
|
598
|
+
// Onprogress is called always after onreadystatechange
|
|
605
599
|
xhr.upload.onprogress = (e) => {
|
|
606
600
|
clearTimeout(stalledId);
|
|
607
601
|
|
|
@@ -635,7 +629,7 @@ class Upload extends ElementMixin(ThemableMixin(PolymerElement)) {
|
|
|
635
629
|
|
|
636
630
|
// More reliable than xhr.onload
|
|
637
631
|
xhr.onreadystatechange = () => {
|
|
638
|
-
if (xhr.readyState
|
|
632
|
+
if (xhr.readyState === 4) {
|
|
639
633
|
clearTimeout(stalledId);
|
|
640
634
|
file.indeterminate = file.uploading = false;
|
|
641
635
|
if (file.abort) {
|
|
@@ -648,8 +642,8 @@ class Upload extends ElementMixin(ThemableMixin(PolymerElement)) {
|
|
|
648
642
|
const evt = this.dispatchEvent(
|
|
649
643
|
new CustomEvent('upload-response', {
|
|
650
644
|
detail: { file, xhr },
|
|
651
|
-
cancelable: true
|
|
652
|
-
})
|
|
645
|
+
cancelable: true,
|
|
646
|
+
}),
|
|
653
647
|
);
|
|
654
648
|
|
|
655
649
|
if (!evt) {
|
|
@@ -666,8 +660,8 @@ class Upload extends ElementMixin(ThemableMixin(PolymerElement)) {
|
|
|
666
660
|
file.complete = !file.error;
|
|
667
661
|
this.dispatchEvent(
|
|
668
662
|
new CustomEvent(`upload-${file.error ? 'error' : 'success'}`, {
|
|
669
|
-
detail: { file, xhr }
|
|
670
|
-
})
|
|
663
|
+
detail: { file, xhr },
|
|
664
|
+
}),
|
|
671
665
|
);
|
|
672
666
|
this._notifyFileChanges(file);
|
|
673
667
|
}
|
|
@@ -681,8 +675,8 @@ class Upload extends ElementMixin(ThemableMixin(PolymerElement)) {
|
|
|
681
675
|
const evt = this.dispatchEvent(
|
|
682
676
|
new CustomEvent('upload-before', {
|
|
683
677
|
detail: { file, xhr },
|
|
684
|
-
cancelable: true
|
|
685
|
-
})
|
|
678
|
+
cancelable: true,
|
|
679
|
+
}),
|
|
686
680
|
);
|
|
687
681
|
if (!evt) {
|
|
688
682
|
return;
|
|
@@ -700,8 +694,8 @@ class Upload extends ElementMixin(ThemableMixin(PolymerElement)) {
|
|
|
700
694
|
xhr.upload.onloadstart = () => {
|
|
701
695
|
this.dispatchEvent(
|
|
702
696
|
new CustomEvent('upload-start', {
|
|
703
|
-
detail: { file, xhr }
|
|
704
|
-
})
|
|
697
|
+
detail: { file, xhr },
|
|
698
|
+
}),
|
|
705
699
|
);
|
|
706
700
|
this._notifyFileChanges(file);
|
|
707
701
|
};
|
|
@@ -711,8 +705,8 @@ class Upload extends ElementMixin(ThemableMixin(PolymerElement)) {
|
|
|
711
705
|
const uploadEvt = this.dispatchEvent(
|
|
712
706
|
new CustomEvent('upload-request', {
|
|
713
707
|
detail: { file, xhr, formData },
|
|
714
|
-
cancelable: true
|
|
715
|
-
})
|
|
708
|
+
cancelable: true,
|
|
709
|
+
}),
|
|
716
710
|
);
|
|
717
711
|
if (uploadEvt) {
|
|
718
712
|
xhr.send(formData);
|
|
@@ -724,8 +718,8 @@ class Upload extends ElementMixin(ThemableMixin(PolymerElement)) {
|
|
|
724
718
|
const evt = this.dispatchEvent(
|
|
725
719
|
new CustomEvent('upload-retry', {
|
|
726
720
|
detail: { file, xhr: file.xhr },
|
|
727
|
-
cancelable: true
|
|
728
|
-
})
|
|
721
|
+
cancelable: true,
|
|
722
|
+
}),
|
|
729
723
|
);
|
|
730
724
|
if (evt) {
|
|
731
725
|
this._uploadFile(file);
|
|
@@ -737,8 +731,8 @@ class Upload extends ElementMixin(ThemableMixin(PolymerElement)) {
|
|
|
737
731
|
const evt = this.dispatchEvent(
|
|
738
732
|
new CustomEvent('upload-abort', {
|
|
739
733
|
detail: { file, xhr: file.xhr },
|
|
740
|
-
cancelable: true
|
|
741
|
-
})
|
|
734
|
+
cancelable: true,
|
|
735
|
+
}),
|
|
742
736
|
);
|
|
743
737
|
if (evt) {
|
|
744
738
|
file.abort = true;
|
|
@@ -751,7 +745,7 @@ class Upload extends ElementMixin(ThemableMixin(PolymerElement)) {
|
|
|
751
745
|
|
|
752
746
|
/** @private */
|
|
753
747
|
_notifyFileChanges(file) {
|
|
754
|
-
|
|
748
|
+
const p = `files.${this.files.indexOf(file)}.`;
|
|
755
749
|
for (const i in file) {
|
|
756
750
|
// eslint-disable-next-line no-prototype-builtins
|
|
757
751
|
if (file.hasOwnProperty(i)) {
|
|
@@ -775,26 +769,26 @@ class Upload extends ElementMixin(ThemableMixin(PolymerElement)) {
|
|
|
775
769
|
if (this.maxFilesReached) {
|
|
776
770
|
this.dispatchEvent(
|
|
777
771
|
new CustomEvent('file-reject', {
|
|
778
|
-
detail: { file, error: this.i18n.error.tooManyFiles }
|
|
779
|
-
})
|
|
772
|
+
detail: { file, error: this.i18n.error.tooManyFiles },
|
|
773
|
+
}),
|
|
780
774
|
);
|
|
781
775
|
return;
|
|
782
776
|
}
|
|
783
777
|
if (this.maxFileSize >= 0 && file.size > this.maxFileSize) {
|
|
784
778
|
this.dispatchEvent(
|
|
785
779
|
new CustomEvent('file-reject', {
|
|
786
|
-
detail: { file, error: this.i18n.error.fileIsTooBig }
|
|
787
|
-
})
|
|
780
|
+
detail: { file, error: this.i18n.error.fileIsTooBig },
|
|
781
|
+
}),
|
|
788
782
|
);
|
|
789
783
|
return;
|
|
790
784
|
}
|
|
791
785
|
const fileExt = file.name.match(/\.[^.]*$|$/)[0];
|
|
792
|
-
const re = new RegExp(
|
|
786
|
+
const re = new RegExp(`^(${this.accept.replace(/[, ]+/g, '|').replace(/\/\*/g, '/.*')})$`, 'i');
|
|
793
787
|
if (this.accept && !(re.test(file.type) || re.test(fileExt))) {
|
|
794
788
|
this.dispatchEvent(
|
|
795
789
|
new CustomEvent('file-reject', {
|
|
796
|
-
detail: { file, error: this.i18n.error.incorrectFileType }
|
|
797
|
-
})
|
|
790
|
+
detail: { file, error: this.i18n.error.incorrectFileType },
|
|
791
|
+
}),
|
|
798
792
|
);
|
|
799
793
|
return;
|
|
800
794
|
}
|
|
@@ -884,22 +878,30 @@ class Upload extends ElementMixin(ThemableMixin(PolymerElement)) {
|
|
|
884
878
|
|
|
885
879
|
/** @private */
|
|
886
880
|
_dragoverChanged(dragover) {
|
|
887
|
-
|
|
881
|
+
if (dragover) {
|
|
882
|
+
this.setAttribute('dragover', dragover);
|
|
883
|
+
} else {
|
|
884
|
+
this.removeAttribute('dragover');
|
|
885
|
+
}
|
|
888
886
|
}
|
|
889
887
|
|
|
890
888
|
/** @private */
|
|
891
889
|
_dragoverValidChanged(dragoverValid) {
|
|
892
|
-
|
|
890
|
+
if (dragoverValid) {
|
|
891
|
+
this.setAttribute('dragover-valid', dragoverValid);
|
|
892
|
+
} else {
|
|
893
|
+
this.removeAttribute('dragover-valid');
|
|
894
|
+
}
|
|
893
895
|
}
|
|
894
896
|
|
|
895
897
|
/** @private */
|
|
896
898
|
_i18nPlural(value, plural) {
|
|
897
|
-
return value
|
|
899
|
+
return value === 1 ? plural.one : plural.many;
|
|
898
900
|
}
|
|
899
901
|
|
|
900
902
|
/** @private */
|
|
901
903
|
_isMultiple(maxFiles) {
|
|
902
|
-
return maxFiles
|
|
904
|
+
return maxFiles !== 1;
|
|
903
905
|
}
|
|
904
906
|
|
|
905
907
|
/**
|
|
@@ -93,7 +93,7 @@ registerStyles(
|
|
|
93
93
|
transition-delay: 0s, 0s;
|
|
94
94
|
}
|
|
95
95
|
`,
|
|
96
|
-
{ moduleId: 'material-upload' }
|
|
96
|
+
{ moduleId: 'material-upload' },
|
|
97
97
|
);
|
|
98
98
|
|
|
99
99
|
registerStyles(
|
|
@@ -247,5 +247,5 @@ registerStyles(
|
|
|
247
247
|
display: none;
|
|
248
248
|
}
|
|
249
249
|
`,
|
|
250
|
-
{ moduleId: 'material-upload-file' }
|
|
250
|
+
{ moduleId: 'material-upload-file' },
|
|
251
251
|
);
|