@vaadin/upload 24.8.0-alpha8 → 25.0.0-alpha1
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/README.md +0 -23
- package/package.json +11 -14
- package/src/vaadin-upload-file-list.js +22 -17
- package/src/vaadin-upload-file.d.ts +1 -2
- package/src/vaadin-upload-file.js +30 -28
- package/src/vaadin-upload-icon.js +15 -12
- package/src/vaadin-upload-mixin.d.ts +34 -29
- package/src/vaadin-upload-mixin.js +150 -135
- package/src/vaadin-upload.d.ts +1 -2
- package/src/vaadin-upload.js +33 -30
- package/web-types.json +10 -10
- package/web-types.lit.json +8 -8
- package/src/vaadin-lit-upload-file-list.js +0 -56
- package/src/vaadin-lit-upload-file.js +0 -87
- package/src/vaadin-lit-upload-icon.js +0 -41
- package/src/vaadin-lit-upload.d.ts +0 -6
- package/src/vaadin-lit-upload.js +0 -77
- package/theme/lumo/vaadin-lit-upload.d.ts +0 -2
- package/theme/lumo/vaadin-lit-upload.js +0 -2
- package/theme/material/vaadin-lit-upload.d.ts +0 -2
- package/theme/material/vaadin-lit-upload.js +0 -2
- package/theme/material/vaadin-upload-styles.d.ts +0 -5
- package/theme/material/vaadin-upload-styles.js +0 -253
- package/theme/material/vaadin-upload.d.ts +0 -2
- package/theme/material/vaadin-upload.js +0 -2
- package/vaadin-lit-upload.d.ts +0 -1
- package/vaadin-lit-upload.js +0 -2
|
@@ -5,8 +5,50 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { announce } from '@vaadin/a11y-base/src/announce.js';
|
|
7
7
|
import { isTouch } from '@vaadin/component-base/src/browser-utils.js';
|
|
8
|
+
import { I18nMixin } from '@vaadin/component-base/src/i18n-mixin.js';
|
|
8
9
|
import { SlotController } from '@vaadin/component-base/src/slot-controller.js';
|
|
9
10
|
|
|
11
|
+
const DEFAULT_I18N = {
|
|
12
|
+
dropFiles: {
|
|
13
|
+
one: 'Drop file here',
|
|
14
|
+
many: 'Drop files here',
|
|
15
|
+
},
|
|
16
|
+
addFiles: {
|
|
17
|
+
one: 'Upload File...',
|
|
18
|
+
many: 'Upload Files...',
|
|
19
|
+
},
|
|
20
|
+
error: {
|
|
21
|
+
tooManyFiles: 'Too Many Files.',
|
|
22
|
+
fileIsTooBig: 'File is Too Big.',
|
|
23
|
+
incorrectFileType: 'Incorrect File Type.',
|
|
24
|
+
},
|
|
25
|
+
uploading: {
|
|
26
|
+
status: {
|
|
27
|
+
connecting: 'Connecting...',
|
|
28
|
+
stalled: 'Stalled',
|
|
29
|
+
processing: 'Processing File...',
|
|
30
|
+
held: 'Queued',
|
|
31
|
+
},
|
|
32
|
+
remainingTime: {
|
|
33
|
+
prefix: 'remaining time: ',
|
|
34
|
+
unknown: 'unknown remaining time',
|
|
35
|
+
},
|
|
36
|
+
error: {
|
|
37
|
+
serverUnavailable: 'Upload failed, please try again later',
|
|
38
|
+
unexpectedServerError: 'Upload failed due to server error',
|
|
39
|
+
forbidden: 'Upload forbidden',
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
file: {
|
|
43
|
+
retry: 'Retry',
|
|
44
|
+
start: 'Start',
|
|
45
|
+
remove: 'Remove',
|
|
46
|
+
},
|
|
47
|
+
units: {
|
|
48
|
+
size: ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'],
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
|
|
10
52
|
class AddButtonController extends SlotController {
|
|
11
53
|
constructor(host) {
|
|
12
54
|
super(host, 'add-button', 'vaadin-button');
|
|
@@ -64,7 +106,7 @@ class DropLabelController extends SlotController {
|
|
|
64
106
|
* @polymerMixin
|
|
65
107
|
*/
|
|
66
108
|
export const UploadMixin = (superClass) =>
|
|
67
|
-
class UploadMixin extends superClass {
|
|
109
|
+
class UploadMixin extends I18nMixin(DEFAULT_I18N, superClass) {
|
|
68
110
|
static get properties() {
|
|
69
111
|
return {
|
|
70
112
|
/**
|
|
@@ -272,112 +314,6 @@ export const UploadMixin = (superClass) =>
|
|
|
272
314
|
*/
|
|
273
315
|
capture: String,
|
|
274
316
|
|
|
275
|
-
/**
|
|
276
|
-
* The object used to localize this component.
|
|
277
|
-
* For changing the default localization, change the entire
|
|
278
|
-
* _i18n_ object or just the property you want to modify.
|
|
279
|
-
*
|
|
280
|
-
* The object has the following JSON structure and default values:
|
|
281
|
-
*
|
|
282
|
-
* ```
|
|
283
|
-
* {
|
|
284
|
-
* dropFiles: {
|
|
285
|
-
* one: 'Drop file here',
|
|
286
|
-
* many: 'Drop files here'
|
|
287
|
-
* },
|
|
288
|
-
* addFiles: {
|
|
289
|
-
* one: 'Upload File...',
|
|
290
|
-
* many: 'Upload Files...'
|
|
291
|
-
* },
|
|
292
|
-
* error: {
|
|
293
|
-
* tooManyFiles: 'Too Many Files.',
|
|
294
|
-
* fileIsTooBig: 'File is Too Big.',
|
|
295
|
-
* incorrectFileType: 'Incorrect File Type.'
|
|
296
|
-
* },
|
|
297
|
-
* uploading: {
|
|
298
|
-
* status: {
|
|
299
|
-
* connecting: 'Connecting...',
|
|
300
|
-
* stalled: 'Stalled',
|
|
301
|
-
* processing: 'Processing File...',
|
|
302
|
-
* held: 'Queued'
|
|
303
|
-
* },
|
|
304
|
-
* remainingTime: {
|
|
305
|
-
* prefix: 'remaining time: ',
|
|
306
|
-
* unknown: 'unknown remaining time'
|
|
307
|
-
* },
|
|
308
|
-
* error: {
|
|
309
|
-
* serverUnavailable: 'Upload failed, please try again later',
|
|
310
|
-
* unexpectedServerError: 'Upload failed due to server error',
|
|
311
|
-
* forbidden: 'Upload forbidden'
|
|
312
|
-
* }
|
|
313
|
-
* },
|
|
314
|
-
* file: {
|
|
315
|
-
* retry: 'Retry',
|
|
316
|
-
* start: 'Start',
|
|
317
|
-
* remove: 'Remove'
|
|
318
|
-
* },
|
|
319
|
-
* units: {
|
|
320
|
-
* size: ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'],
|
|
321
|
-
* sizeBase: 1000
|
|
322
|
-
* },
|
|
323
|
-
* formatSize: function(bytes) {
|
|
324
|
-
* // returns the size followed by the best suitable unit
|
|
325
|
-
* },
|
|
326
|
-
* formatTime: function(seconds, [secs, mins, hours]) {
|
|
327
|
-
* // returns a 'HH:MM:SS' string
|
|
328
|
-
* }
|
|
329
|
-
* }
|
|
330
|
-
* ```
|
|
331
|
-
*
|
|
332
|
-
* @type {!UploadI18n}
|
|
333
|
-
* @default {English}
|
|
334
|
-
*/
|
|
335
|
-
i18n: {
|
|
336
|
-
type: Object,
|
|
337
|
-
value() {
|
|
338
|
-
return {
|
|
339
|
-
dropFiles: {
|
|
340
|
-
one: 'Drop file here',
|
|
341
|
-
many: 'Drop files here',
|
|
342
|
-
},
|
|
343
|
-
addFiles: {
|
|
344
|
-
one: 'Upload File...',
|
|
345
|
-
many: 'Upload Files...',
|
|
346
|
-
},
|
|
347
|
-
error: {
|
|
348
|
-
tooManyFiles: 'Too Many Files.',
|
|
349
|
-
fileIsTooBig: 'File is Too Big.',
|
|
350
|
-
incorrectFileType: 'Incorrect File Type.',
|
|
351
|
-
},
|
|
352
|
-
uploading: {
|
|
353
|
-
status: {
|
|
354
|
-
connecting: 'Connecting...',
|
|
355
|
-
stalled: 'Stalled',
|
|
356
|
-
processing: 'Processing File...',
|
|
357
|
-
held: 'Queued',
|
|
358
|
-
},
|
|
359
|
-
remainingTime: {
|
|
360
|
-
prefix: 'remaining time: ',
|
|
361
|
-
unknown: 'unknown remaining time',
|
|
362
|
-
},
|
|
363
|
-
error: {
|
|
364
|
-
serverUnavailable: 'Upload failed, please try again later',
|
|
365
|
-
unexpectedServerError: 'Upload failed due to server error',
|
|
366
|
-
forbidden: 'Upload forbidden',
|
|
367
|
-
},
|
|
368
|
-
},
|
|
369
|
-
file: {
|
|
370
|
-
retry: 'Retry',
|
|
371
|
-
start: 'Start',
|
|
372
|
-
remove: 'Remove',
|
|
373
|
-
},
|
|
374
|
-
units: {
|
|
375
|
-
size: ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'],
|
|
376
|
-
},
|
|
377
|
-
};
|
|
378
|
-
},
|
|
379
|
-
},
|
|
380
|
-
|
|
381
317
|
/** @private */
|
|
382
318
|
_addButton: {
|
|
383
319
|
type: Object,
|
|
@@ -402,13 +338,79 @@ export const UploadMixin = (superClass) =>
|
|
|
402
338
|
|
|
403
339
|
static get observers() {
|
|
404
340
|
return [
|
|
405
|
-
'__updateAddButton(_addButton, maxFiles,
|
|
406
|
-
'__updateDropLabel(_dropLabel, maxFiles,
|
|
407
|
-
'__updateFileList(_fileList, files,
|
|
341
|
+
'__updateAddButton(_addButton, maxFiles, __effectiveI18n, maxFilesReached, disabled)',
|
|
342
|
+
'__updateDropLabel(_dropLabel, maxFiles, __effectiveI18n)',
|
|
343
|
+
'__updateFileList(_fileList, files, __effectiveI18n, disabled)',
|
|
408
344
|
'__updateMaxFilesReached(maxFiles, files)',
|
|
409
345
|
];
|
|
410
346
|
}
|
|
411
347
|
|
|
348
|
+
/**
|
|
349
|
+
* The object used to localize this component. To change the default
|
|
350
|
+
* localization, replace this with an object that provides all properties, or
|
|
351
|
+
* just the individual properties you want to change.
|
|
352
|
+
*
|
|
353
|
+
* The object has the following JSON structure and default values:
|
|
354
|
+
*
|
|
355
|
+
* ```
|
|
356
|
+
* {
|
|
357
|
+
* dropFiles: {
|
|
358
|
+
* one: 'Drop file here',
|
|
359
|
+
* many: 'Drop files here'
|
|
360
|
+
* },
|
|
361
|
+
* addFiles: {
|
|
362
|
+
* one: 'Upload File...',
|
|
363
|
+
* many: 'Upload Files...'
|
|
364
|
+
* },
|
|
365
|
+
* error: {
|
|
366
|
+
* tooManyFiles: 'Too Many Files.',
|
|
367
|
+
* fileIsTooBig: 'File is Too Big.',
|
|
368
|
+
* incorrectFileType: 'Incorrect File Type.'
|
|
369
|
+
* },
|
|
370
|
+
* uploading: {
|
|
371
|
+
* status: {
|
|
372
|
+
* connecting: 'Connecting...',
|
|
373
|
+
* stalled: 'Stalled',
|
|
374
|
+
* processing: 'Processing File...',
|
|
375
|
+
* held: 'Queued'
|
|
376
|
+
* },
|
|
377
|
+
* remainingTime: {
|
|
378
|
+
* prefix: 'remaining time: ',
|
|
379
|
+
* unknown: 'unknown remaining time'
|
|
380
|
+
* },
|
|
381
|
+
* error: {
|
|
382
|
+
* serverUnavailable: 'Upload failed, please try again later',
|
|
383
|
+
* unexpectedServerError: 'Upload failed due to server error',
|
|
384
|
+
* forbidden: 'Upload forbidden'
|
|
385
|
+
* }
|
|
386
|
+
* },
|
|
387
|
+
* file: {
|
|
388
|
+
* retry: 'Retry',
|
|
389
|
+
* start: 'Start',
|
|
390
|
+
* remove: 'Remove'
|
|
391
|
+
* },
|
|
392
|
+
* units: {
|
|
393
|
+
* size: ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'],
|
|
394
|
+
* sizeBase: 1000
|
|
395
|
+
* },
|
|
396
|
+
* formatSize: function(bytes) {
|
|
397
|
+
* // returns the size followed by the best suitable unit
|
|
398
|
+
* },
|
|
399
|
+
* formatTime: function(seconds, [secs, mins, hours]) {
|
|
400
|
+
* // returns a 'HH:MM:SS' string
|
|
401
|
+
* }
|
|
402
|
+
* }
|
|
403
|
+
* ```
|
|
404
|
+
* @return {!UploadI18n}
|
|
405
|
+
*/
|
|
406
|
+
get i18n() {
|
|
407
|
+
return super.i18n;
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
set i18n(value) {
|
|
411
|
+
super.i18n = value;
|
|
412
|
+
}
|
|
413
|
+
|
|
412
414
|
/** @private */
|
|
413
415
|
get __acceptRegexp() {
|
|
414
416
|
if (!this.accept) {
|
|
@@ -462,16 +464,16 @@ export const UploadMixin = (superClass) =>
|
|
|
462
464
|
|
|
463
465
|
/** @private */
|
|
464
466
|
_formatSize(bytes) {
|
|
465
|
-
if (typeof this.
|
|
466
|
-
return this.
|
|
467
|
+
if (typeof this.__effectiveI18n.formatSize === 'function') {
|
|
468
|
+
return this.__effectiveI18n.formatSize(bytes);
|
|
467
469
|
}
|
|
468
470
|
|
|
469
471
|
// https://wiki.ubuntu.com/UnitsPolicy
|
|
470
|
-
const base = this.
|
|
472
|
+
const base = this.__effectiveI18n.units.sizeBase || 1000;
|
|
471
473
|
const unit = ~~(Math.log(bytes) / Math.log(base));
|
|
472
474
|
const dec = Math.max(0, Math.min(3, unit - 1));
|
|
473
475
|
const size = parseFloat((bytes / base ** unit).toFixed(dec));
|
|
474
|
-
return `${size} ${this.
|
|
476
|
+
return `${size} ${this.__effectiveI18n.units.size[unit]}`;
|
|
475
477
|
}
|
|
476
478
|
|
|
477
479
|
/** @private */
|
|
@@ -489,8 +491,8 @@ export const UploadMixin = (superClass) =>
|
|
|
489
491
|
|
|
490
492
|
/** @private */
|
|
491
493
|
_formatTime(seconds, split) {
|
|
492
|
-
if (typeof this.
|
|
493
|
-
return this.
|
|
494
|
+
if (typeof this.__effectiveI18n.formatTime === 'function') {
|
|
495
|
+
return this.__effectiveI18n.formatTime(seconds, split);
|
|
494
496
|
}
|
|
495
497
|
|
|
496
498
|
// Fill HH:MM:SS with leading zeros
|
|
@@ -510,8 +512,8 @@ export const UploadMixin = (superClass) =>
|
|
|
510
512
|
_formatFileProgress(file) {
|
|
511
513
|
const remainingTime =
|
|
512
514
|
file.loaded > 0
|
|
513
|
-
? this.
|
|
514
|
-
: this.
|
|
515
|
+
? this.__effectiveI18n.uploading.remainingTime.prefix + file.remainingStr
|
|
516
|
+
: this.__effectiveI18n.uploading.remainingTime.unknown;
|
|
515
517
|
|
|
516
518
|
return `${file.totalStr}: ${file.progress}% (${remainingTime})`;
|
|
517
519
|
}
|
|
@@ -522,30 +524,30 @@ export const UploadMixin = (superClass) =>
|
|
|
522
524
|
}
|
|
523
525
|
|
|
524
526
|
/** @private */
|
|
525
|
-
__updateAddButton(addButton, maxFiles,
|
|
527
|
+
__updateAddButton(addButton, maxFiles, effectiveI18n, maxFilesReached, disabled) {
|
|
526
528
|
if (addButton) {
|
|
527
529
|
addButton.disabled = disabled || maxFilesReached;
|
|
528
530
|
|
|
529
531
|
// Only update text content for the default button element
|
|
530
532
|
if (addButton === this._addButtonController.defaultNode) {
|
|
531
|
-
addButton.textContent = this._i18nPlural(maxFiles,
|
|
533
|
+
addButton.textContent = this._i18nPlural(maxFiles, effectiveI18n.addFiles);
|
|
532
534
|
}
|
|
533
535
|
}
|
|
534
536
|
}
|
|
535
537
|
|
|
536
538
|
/** @private */
|
|
537
|
-
__updateDropLabel(dropLabel, maxFiles,
|
|
539
|
+
__updateDropLabel(dropLabel, maxFiles, effectiveI18n) {
|
|
538
540
|
// Only update text content for the default label element
|
|
539
541
|
if (dropLabel && dropLabel === this._dropLabelController.defaultNode) {
|
|
540
|
-
dropLabel.textContent = this._i18nPlural(maxFiles,
|
|
542
|
+
dropLabel.textContent = this._i18nPlural(maxFiles, effectiveI18n.dropFiles);
|
|
541
543
|
}
|
|
542
544
|
}
|
|
543
545
|
|
|
544
546
|
/** @private */
|
|
545
|
-
__updateFileList(list, files,
|
|
547
|
+
__updateFileList(list, files, effectiveI18n, disabled) {
|
|
546
548
|
if (list) {
|
|
547
549
|
list.items = [...files];
|
|
548
|
-
list.i18n =
|
|
550
|
+
list.i18n = effectiveI18n;
|
|
549
551
|
list.disabled = disabled;
|
|
550
552
|
}
|
|
551
553
|
}
|
|
@@ -606,6 +608,19 @@ export const UploadMixin = (superClass) =>
|
|
|
606
608
|
}
|
|
607
609
|
}
|
|
608
610
|
|
|
611
|
+
// In some cases (like dragging attachments from Outlook on Windows), "webkitGetAsEntry"
|
|
612
|
+
// can return null for "dataTransfer" items. Also, there is no reason to check for
|
|
613
|
+
// "webkitGetAsEntry" when there are no folders. Therefore, "dataTransfer.files" is used
|
|
614
|
+
// to handle such cases.
|
|
615
|
+
const containsFolders = Array.from(dropEvent.dataTransfer.items)
|
|
616
|
+
.filter((item) => !!item)
|
|
617
|
+
.filter((item) => typeof item.webkitGetAsEntry === 'function')
|
|
618
|
+
.map((item) => item.webkitGetAsEntry())
|
|
619
|
+
.some((entry) => !!entry && entry.isDirectory);
|
|
620
|
+
if (!containsFolders) {
|
|
621
|
+
return Promise.resolve(dropEvent.dataTransfer.files ? Array.from(dropEvent.dataTransfer.files) : []);
|
|
622
|
+
}
|
|
623
|
+
|
|
609
624
|
const filePromises = Array.from(dropEvent.dataTransfer.items)
|
|
610
625
|
.map((item) => item.webkitGetAsEntry())
|
|
611
626
|
.filter((entry) => !!entry)
|
|
@@ -691,12 +706,12 @@ export const UploadMixin = (superClass) =>
|
|
|
691
706
|
if (progress < 100) {
|
|
692
707
|
this._setStatus(file, total, loaded, elapsed);
|
|
693
708
|
stalledId = setTimeout(() => {
|
|
694
|
-
file.status = this.
|
|
709
|
+
file.status = this.__effectiveI18n.uploading.status.stalled;
|
|
695
710
|
this._renderFileList();
|
|
696
711
|
}, 2000);
|
|
697
712
|
} else {
|
|
698
713
|
file.loadedStr = file.totalStr;
|
|
699
|
-
file.status = this.
|
|
714
|
+
file.status = this.__effectiveI18n.uploading.status.processing;
|
|
700
715
|
}
|
|
701
716
|
}
|
|
702
717
|
|
|
@@ -726,11 +741,11 @@ export const UploadMixin = (superClass) =>
|
|
|
726
741
|
return;
|
|
727
742
|
}
|
|
728
743
|
if (xhr.status === 0) {
|
|
729
|
-
file.error = this.
|
|
744
|
+
file.error = this.__effectiveI18n.uploading.error.serverUnavailable;
|
|
730
745
|
} else if (xhr.status >= 500) {
|
|
731
|
-
file.error = this.
|
|
746
|
+
file.error = this.__effectiveI18n.uploading.error.unexpectedServerError;
|
|
732
747
|
} else if (xhr.status >= 400) {
|
|
733
|
-
file.error = this.
|
|
748
|
+
file.error = this.__effectiveI18n.uploading.error.forbidden;
|
|
734
749
|
}
|
|
735
750
|
|
|
736
751
|
file.complete = !file.error;
|
|
@@ -765,7 +780,7 @@ export const UploadMixin = (superClass) =>
|
|
|
765
780
|
xhr.open(this.method, file.uploadTarget, true);
|
|
766
781
|
this._configureXhr(xhr);
|
|
767
782
|
|
|
768
|
-
file.status = this.
|
|
783
|
+
file.status = this.__effectiveI18n.uploading.status.connecting;
|
|
769
784
|
file.uploading = file.indeterminate = true;
|
|
770
785
|
file.complete = file.abort = file.error = file.held = false;
|
|
771
786
|
|
|
@@ -824,7 +839,7 @@ export const UploadMixin = (superClass) =>
|
|
|
824
839
|
|
|
825
840
|
/** @private */
|
|
826
841
|
_renderFileList() {
|
|
827
|
-
if (this._fileList) {
|
|
842
|
+
if (this._fileList && typeof this._fileList.requestContentUpdate === 'function') {
|
|
828
843
|
this._fileList.requestContentUpdate();
|
|
829
844
|
}
|
|
830
845
|
}
|
|
@@ -844,7 +859,7 @@ export const UploadMixin = (superClass) =>
|
|
|
844
859
|
if (this.maxFilesReached) {
|
|
845
860
|
this.dispatchEvent(
|
|
846
861
|
new CustomEvent('file-reject', {
|
|
847
|
-
detail: { file, error: this.
|
|
862
|
+
detail: { file, error: this.__effectiveI18n.error.tooManyFiles },
|
|
848
863
|
}),
|
|
849
864
|
);
|
|
850
865
|
return;
|
|
@@ -852,7 +867,7 @@ export const UploadMixin = (superClass) =>
|
|
|
852
867
|
if (this.maxFileSize >= 0 && file.size > this.maxFileSize) {
|
|
853
868
|
this.dispatchEvent(
|
|
854
869
|
new CustomEvent('file-reject', {
|
|
855
|
-
detail: { file, error: this.
|
|
870
|
+
detail: { file, error: this.__effectiveI18n.error.fileIsTooBig },
|
|
856
871
|
}),
|
|
857
872
|
);
|
|
858
873
|
return;
|
|
@@ -861,14 +876,14 @@ export const UploadMixin = (superClass) =>
|
|
|
861
876
|
if (re && !(re.test(file.type) || re.test(file.name))) {
|
|
862
877
|
this.dispatchEvent(
|
|
863
878
|
new CustomEvent('file-reject', {
|
|
864
|
-
detail: { file, error: this.
|
|
879
|
+
detail: { file, error: this.__effectiveI18n.error.incorrectFileType },
|
|
865
880
|
}),
|
|
866
881
|
);
|
|
867
882
|
return;
|
|
868
883
|
}
|
|
869
884
|
file.loaded = 0;
|
|
870
885
|
file.held = true;
|
|
871
|
-
file.status = this.
|
|
886
|
+
file.status = this.__effectiveI18n.uploading.status.held;
|
|
872
887
|
this.files = [file, ...this.files];
|
|
873
888
|
|
|
874
889
|
if (!this.noAuto) {
|
package/src/vaadin-upload.d.ts
CHANGED
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
* Copyright (c) 2016 - 2025 Vaadin Ltd.
|
|
4
4
|
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
5
|
*/
|
|
6
|
-
import { ControllerMixin } from '@vaadin/component-base/src/controller-mixin.js';
|
|
7
6
|
import { ElementMixin } from '@vaadin/component-base/src/element-mixin.js';
|
|
8
7
|
import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
|
|
9
8
|
import { type UploadFile, UploadMixin } from './vaadin-upload-mixin.js';
|
|
@@ -157,7 +156,7 @@ export interface UploadEventMap extends HTMLElementEventMap, UploadCustomEventMa
|
|
|
157
156
|
* @fires {CustomEvent} upload-retry - Fired when retry upload is requested.
|
|
158
157
|
* @fires {CustomEvent} upload-abort - Fired when upload abort is requested.
|
|
159
158
|
*/
|
|
160
|
-
declare class Upload extends UploadMixin(ThemableMixin(ElementMixin(
|
|
159
|
+
declare class Upload extends UploadMixin(ThemableMixin(ElementMixin(HTMLElement))) {
|
|
161
160
|
addEventListener<K extends keyof UploadEventMap>(
|
|
162
161
|
type: K,
|
|
163
162
|
listener: (this: Upload, ev: UploadEventMap[K]) => void,
|
package/src/vaadin-upload.js
CHANGED
|
@@ -7,10 +7,11 @@ import '@vaadin/button/src/vaadin-button.js';
|
|
|
7
7
|
import './vaadin-upload-icon.js';
|
|
8
8
|
import './vaadin-upload-icons.js';
|
|
9
9
|
import './vaadin-upload-file-list.js';
|
|
10
|
-
import { html,
|
|
11
|
-
import {
|
|
10
|
+
import { css, html, LitElement } from 'lit';
|
|
11
|
+
import { ifDefined } from 'lit/directives/if-defined.js';
|
|
12
12
|
import { defineCustomElement } from '@vaadin/component-base/src/define.js';
|
|
13
13
|
import { ElementMixin } from '@vaadin/component-base/src/element-mixin.js';
|
|
14
|
+
import { PolylitMixin } from '@vaadin/component-base/src/polylit-mixin.js';
|
|
14
15
|
import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
|
|
15
16
|
import { UploadMixin } from './vaadin-upload-mixin.js';
|
|
16
17
|
|
|
@@ -59,33 +60,39 @@ import { UploadMixin } from './vaadin-upload-mixin.js';
|
|
|
59
60
|
*
|
|
60
61
|
* @customElement
|
|
61
62
|
* @extends HTMLElement
|
|
62
|
-
* @mixes ControllerMixin
|
|
63
63
|
* @mixes ThemableMixin
|
|
64
64
|
* @mixes ElementMixin
|
|
65
65
|
* @mixes UploadMixin
|
|
66
66
|
*/
|
|
67
|
-
class Upload extends UploadMixin(ElementMixin(ThemableMixin(
|
|
68
|
-
static get
|
|
69
|
-
return
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
:
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
67
|
+
class Upload extends UploadMixin(ElementMixin(ThemableMixin(PolylitMixin(LitElement)))) {
|
|
68
|
+
static get is() {
|
|
69
|
+
return 'vaadin-upload';
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
static get styles() {
|
|
73
|
+
return css`
|
|
74
|
+
:host {
|
|
75
|
+
display: block;
|
|
76
|
+
position: relative;
|
|
77
|
+
box-sizing: border-box;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
:host([hidden]) {
|
|
81
|
+
display: none !important;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
[hidden] {
|
|
85
|
+
display: none !important;
|
|
86
|
+
}
|
|
87
|
+
`;
|
|
88
|
+
}
|
|
85
89
|
|
|
90
|
+
/** @protected */
|
|
91
|
+
render() {
|
|
92
|
+
return html`
|
|
86
93
|
<div part="primary-buttons">
|
|
87
94
|
<slot name="add-button"></slot>
|
|
88
|
-
<div part="drop-label" hidden
|
|
95
|
+
<div part="drop-label" ?hidden="${this.nodrop}" id="dropLabelContainer" aria-hidden="true">
|
|
89
96
|
<slot name="drop-label-icon"></slot>
|
|
90
97
|
<slot name="drop-label"></slot>
|
|
91
98
|
</div>
|
|
@@ -96,18 +103,14 @@ class Upload extends UploadMixin(ElementMixin(ThemableMixin(ControllerMixin(Poly
|
|
|
96
103
|
type="file"
|
|
97
104
|
id="fileInput"
|
|
98
105
|
hidden
|
|
99
|
-
|
|
100
|
-
accept
|
|
101
|
-
multiple
|
|
102
|
-
capture
|
|
106
|
+
@change="${this._onFileInputChange}"
|
|
107
|
+
accept="${this.accept}"
|
|
108
|
+
?multiple="${this._isMultiple(this.maxFiles)}"
|
|
109
|
+
capture="${ifDefined(this.capture)}"
|
|
103
110
|
/>
|
|
104
111
|
`;
|
|
105
112
|
}
|
|
106
113
|
|
|
107
|
-
static get is() {
|
|
108
|
-
return 'vaadin-upload';
|
|
109
|
-
}
|
|
110
|
-
|
|
111
114
|
/**
|
|
112
115
|
* Fired when a file cannot be added to the queue due to a constrain:
|
|
113
116
|
* file-size, file-type or maxFiles
|
package/web-types.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/web-types",
|
|
3
3
|
"name": "@vaadin/upload",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "25.0.0-alpha1",
|
|
5
5
|
"description-markup": "markdown",
|
|
6
6
|
"contributions": {
|
|
7
7
|
"html": {
|
|
@@ -389,6 +389,15 @@
|
|
|
389
389
|
],
|
|
390
390
|
"js": {
|
|
391
391
|
"properties": [
|
|
392
|
+
{
|
|
393
|
+
"name": "i18n",
|
|
394
|
+
"description": "The object used to localize this component. To change the default\nlocalization, replace this with an object that provides all properties, or\njust the individual properties you want to change.\n\nThe object has the following JSON structure and default values:\n\n```\n{\n dropFiles: {\n one: 'Drop file here',\n many: 'Drop files here'\n },\n addFiles: {\n one: 'Upload File...',\n many: 'Upload Files...'\n },\n error: {\n tooManyFiles: 'Too Many Files.',\n fileIsTooBig: 'File is Too Big.',\n incorrectFileType: 'Incorrect File Type.'\n },\n uploading: {\n status: {\n connecting: 'Connecting...',\n stalled: 'Stalled',\n processing: 'Processing File...',\n held: 'Queued'\n },\n remainingTime: {\n prefix: 'remaining time: ',\n unknown: 'unknown remaining time'\n },\n error: {\n serverUnavailable: 'Upload failed, please try again later',\n unexpectedServerError: 'Upload failed due to server error',\n forbidden: 'Upload forbidden'\n }\n },\n file: {\n retry: 'Retry',\n start: 'Start',\n remove: 'Remove'\n },\n units: {\n size: ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'],\n sizeBase: 1000\n },\n formatSize: function(bytes) {\n // returns the size followed by the best suitable unit\n },\n formatTime: function(seconds, [secs, mins, hours]) {\n // returns a 'HH:MM:SS' string\n }\n}\n```",
|
|
395
|
+
"value": {
|
|
396
|
+
"type": [
|
|
397
|
+
"UploadI18n"
|
|
398
|
+
]
|
|
399
|
+
}
|
|
400
|
+
},
|
|
392
401
|
{
|
|
393
402
|
"name": "disabled",
|
|
394
403
|
"description": "If true, the user cannot interact with this element.",
|
|
@@ -517,15 +526,6 @@
|
|
|
517
526
|
"undefined"
|
|
518
527
|
]
|
|
519
528
|
}
|
|
520
|
-
},
|
|
521
|
-
{
|
|
522
|
-
"name": "i18n",
|
|
523
|
-
"description": "The object used to localize this component.\nFor changing the default localization, change the entire\n_i18n_ object or just the property you want to modify.\n\nThe object has the following JSON structure and default values:\n\n```\n{\n dropFiles: {\n one: 'Drop file here',\n many: 'Drop files here'\n },\n addFiles: {\n one: 'Upload File...',\n many: 'Upload Files...'\n },\n error: {\n tooManyFiles: 'Too Many Files.',\n fileIsTooBig: 'File is Too Big.',\n incorrectFileType: 'Incorrect File Type.'\n },\n uploading: {\n status: {\n connecting: 'Connecting...',\n stalled: 'Stalled',\n processing: 'Processing File...',\n held: 'Queued'\n },\n remainingTime: {\n prefix: 'remaining time: ',\n unknown: 'unknown remaining time'\n },\n error: {\n serverUnavailable: 'Upload failed, please try again later',\n unexpectedServerError: 'Upload failed due to server error',\n forbidden: 'Upload forbidden'\n }\n },\n file: {\n retry: 'Retry',\n start: 'Start',\n remove: 'Remove'\n },\n units: {\n size: ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'],\n sizeBase: 1000\n },\n formatSize: function(bytes) {\n // returns the size followed by the best suitable unit\n },\n formatTime: function(seconds, [secs, mins, hours]) {\n // returns a 'HH:MM:SS' string\n }\n}\n```",
|
|
524
|
-
"value": {
|
|
525
|
-
"type": [
|
|
526
|
-
"UploadI18n"
|
|
527
|
-
]
|
|
528
|
-
}
|
|
529
529
|
}
|
|
530
530
|
],
|
|
531
531
|
"events": [
|
package/web-types.lit.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/web-types",
|
|
3
3
|
"name": "@vaadin/upload",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "25.0.0-alpha1",
|
|
5
5
|
"description-markup": "markdown",
|
|
6
6
|
"framework": "lit",
|
|
7
7
|
"framework-config": {
|
|
@@ -152,6 +152,13 @@
|
|
|
152
152
|
"kind": "expression"
|
|
153
153
|
}
|
|
154
154
|
},
|
|
155
|
+
{
|
|
156
|
+
"name": ".i18n",
|
|
157
|
+
"description": "The object used to localize this component. To change the default\nlocalization, replace this with an object that provides all properties, or\njust the individual properties you want to change.\n\nThe object has the following JSON structure and default values:\n\n```\n{\n dropFiles: {\n one: 'Drop file here',\n many: 'Drop files here'\n },\n addFiles: {\n one: 'Upload File...',\n many: 'Upload Files...'\n },\n error: {\n tooManyFiles: 'Too Many Files.',\n fileIsTooBig: 'File is Too Big.',\n incorrectFileType: 'Incorrect File Type.'\n },\n uploading: {\n status: {\n connecting: 'Connecting...',\n stalled: 'Stalled',\n processing: 'Processing File...',\n held: 'Queued'\n },\n remainingTime: {\n prefix: 'remaining time: ',\n unknown: 'unknown remaining time'\n },\n error: {\n serverUnavailable: 'Upload failed, please try again later',\n unexpectedServerError: 'Upload failed due to server error',\n forbidden: 'Upload forbidden'\n }\n },\n file: {\n retry: 'Retry',\n start: 'Start',\n remove: 'Remove'\n },\n units: {\n size: ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'],\n sizeBase: 1000\n },\n formatSize: function(bytes) {\n // returns the size followed by the best suitable unit\n },\n formatTime: function(seconds, [secs, mins, hours]) {\n // returns a 'HH:MM:SS' string\n }\n}\n```",
|
|
158
|
+
"value": {
|
|
159
|
+
"kind": "expression"
|
|
160
|
+
}
|
|
161
|
+
},
|
|
155
162
|
{
|
|
156
163
|
"name": ".target",
|
|
157
164
|
"description": "The server URL. The default value is an empty string, which means that\n_window.location_ will be used.",
|
|
@@ -222,13 +229,6 @@
|
|
|
222
229
|
"kind": "expression"
|
|
223
230
|
}
|
|
224
231
|
},
|
|
225
|
-
{
|
|
226
|
-
"name": ".i18n",
|
|
227
|
-
"description": "The object used to localize this component.\nFor changing the default localization, change the entire\n_i18n_ object or just the property you want to modify.\n\nThe object has the following JSON structure and default values:\n\n```\n{\n dropFiles: {\n one: 'Drop file here',\n many: 'Drop files here'\n },\n addFiles: {\n one: 'Upload File...',\n many: 'Upload Files...'\n },\n error: {\n tooManyFiles: 'Too Many Files.',\n fileIsTooBig: 'File is Too Big.',\n incorrectFileType: 'Incorrect File Type.'\n },\n uploading: {\n status: {\n connecting: 'Connecting...',\n stalled: 'Stalled',\n processing: 'Processing File...',\n held: 'Queued'\n },\n remainingTime: {\n prefix: 'remaining time: ',\n unknown: 'unknown remaining time'\n },\n error: {\n serverUnavailable: 'Upload failed, please try again later',\n unexpectedServerError: 'Upload failed due to server error',\n forbidden: 'Upload forbidden'\n }\n },\n file: {\n retry: 'Retry',\n start: 'Start',\n remove: 'Remove'\n },\n units: {\n size: ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'],\n sizeBase: 1000\n },\n formatSize: function(bytes) {\n // returns the size followed by the best suitable unit\n },\n formatTime: function(seconds, [secs, mins, hours]) {\n // returns a 'HH:MM:SS' string\n }\n}\n```",
|
|
228
|
-
"value": {
|
|
229
|
-
"kind": "expression"
|
|
230
|
-
}
|
|
231
|
-
},
|
|
232
232
|
{
|
|
233
233
|
"name": "@file-reject",
|
|
234
234
|
"description": "Fired when a file cannot be added to the queue due to a constrain:\n file-size, file-type or maxFiles",
|