@vaadin/upload 23.1.0-alpha1 → 23.1.0-alpha4

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-alpha1",
3
+ "version": "23.1.0-alpha4",
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-alpha1",
38
- "@vaadin/component-base": "23.1.0-alpha1",
39
- "@vaadin/progress-bar": "23.1.0-alpha1",
40
- "@vaadin/vaadin-lumo-styles": "23.1.0-alpha1",
41
- "@vaadin/vaadin-material-styles": "23.1.0-alpha1",
42
- "@vaadin/vaadin-themable-mixin": "23.1.0-alpha1"
37
+ "@vaadin/button": "23.1.0-alpha4",
38
+ "@vaadin/component-base": "23.1.0-alpha4",
39
+ "@vaadin/progress-bar": "23.1.0-alpha4",
40
+ "@vaadin/vaadin-lumo-styles": "23.1.0-alpha4",
41
+ "@vaadin/vaadin-material-styles": "23.1.0-alpha4",
42
+ "@vaadin/vaadin-themable-mixin": "23.1.0-alpha4"
43
43
  },
44
44
  "devDependencies": {
45
45
  "@esm-bundle/chai": "^4.3.4",
46
- "@vaadin/form-layout": "23.1.0-alpha1",
46
+ "@vaadin/form-layout": "23.1.0-alpha4",
47
47
  "@vaadin/testing-helpers": "^0.3.2",
48
- "sinon": "^9.2.0"
48
+ "sinon": "^13.0.2"
49
49
  },
50
- "gitHead": "5d0cdee069f866037c507265fafb4d0476795333"
50
+ "gitHead": "aacdb7fe09811894751f0378ff7fb66071892c71"
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
 
@@ -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
 
@@ -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
  /**
@@ -223,7 +223,7 @@ class Upload extends ElementMixin(ThemableMixin(PolymerElement)) {
223
223
  notify: true,
224
224
  value: function () {
225
225
  return [];
226
- }
226
+ },
227
227
  },
228
228
 
229
229
  /**
@@ -234,7 +234,7 @@ class Upload extends ElementMixin(ThemableMixin(PolymerElement)) {
234
234
  */
235
235
  maxFiles: {
236
236
  type: Number,
237
- value: Infinity
237
+ value: Infinity,
238
238
  },
239
239
 
240
240
  /**
@@ -248,7 +248,7 @@ class Upload extends ElementMixin(ThemableMixin(PolymerElement)) {
248
248
  notify: true,
249
249
  readOnly: true,
250
250
  reflectToAttribute: true,
251
- computed: '_maxFilesAdded(maxFiles, files.length)'
251
+ computed: '_maxFilesAdded(maxFiles, files.length)',
252
252
  },
253
253
 
254
254
  /**
@@ -262,7 +262,7 @@ class Upload extends ElementMixin(ThemableMixin(PolymerElement)) {
262
262
  */
263
263
  accept: {
264
264
  type: String,
265
- value: ''
265
+ value: '',
266
266
  },
267
267
 
268
268
  /**
@@ -275,7 +275,7 @@ class Upload extends ElementMixin(ThemableMixin(PolymerElement)) {
275
275
  */
276
276
  maxFileSize: {
277
277
  type: Number,
278
- value: Infinity
278
+ value: Infinity,
279
279
  },
280
280
 
281
281
  /**
@@ -286,7 +286,7 @@ class Upload extends ElementMixin(ThemableMixin(PolymerElement)) {
286
286
  _dragoverValid: {
287
287
  type: Boolean,
288
288
  value: false,
289
- observer: '_dragoverValidChanged'
289
+ observer: '_dragoverValidChanged',
290
290
  },
291
291
 
292
292
  /**
@@ -296,7 +296,7 @@ class Upload extends ElementMixin(ThemableMixin(PolymerElement)) {
296
296
  */
297
297
  formDataName: {
298
298
  type: String,
299
- value: 'file'
299
+ value: 'file',
300
300
  },
301
301
 
302
302
  /**
@@ -307,7 +307,7 @@ class Upload extends ElementMixin(ThemableMixin(PolymerElement)) {
307
307
  */
308
308
  noAuto: {
309
309
  type: Boolean,
310
- value: false
310
+ value: false,
311
311
  },
312
312
 
313
313
  /**
@@ -317,7 +317,7 @@ class Upload extends ElementMixin(ThemableMixin(PolymerElement)) {
317
317
  */
318
318
  withCredentials: {
319
319
  type: Boolean,
320
- value: false
320
+ value: false,
321
321
  },
322
322
 
323
323
  /**
@@ -392,45 +392,45 @@ class Upload extends ElementMixin(ThemableMixin(PolymerElement)) {
392
392
  return {
393
393
  dropFiles: {
394
394
  one: 'Drop file here',
395
- many: 'Drop files here'
395
+ many: 'Drop files here',
396
396
  },
397
397
  addFiles: {
398
398
  one: 'Upload File...',
399
- many: 'Upload Files...'
399
+ many: 'Upload Files...',
400
400
  },
401
401
  error: {
402
402
  tooManyFiles: 'Too Many Files.',
403
403
  fileIsTooBig: 'File is Too Big.',
404
- incorrectFileType: 'Incorrect File Type.'
404
+ incorrectFileType: 'Incorrect File Type.',
405
405
  },
406
406
  uploading: {
407
407
  status: {
408
408
  connecting: 'Connecting...',
409
409
  stalled: 'Stalled',
410
410
  processing: 'Processing File...',
411
- held: 'Queued'
411
+ held: 'Queued',
412
412
  },
413
413
  remainingTime: {
414
414
  prefix: 'remaining time: ',
415
- unknown: 'unknown remaining time'
415
+ unknown: 'unknown remaining time',
416
416
  },
417
417
  error: {
418
418
  serverUnavailable: 'Upload failed, please try again later',
419
419
  unexpectedServerError: 'Upload failed due to server error',
420
- forbidden: 'Upload forbidden'
421
- }
420
+ forbidden: 'Upload forbidden',
421
+ },
422
422
  },
423
423
  file: {
424
424
  retry: 'Retry',
425
425
  start: 'Start',
426
- remove: 'Remove'
426
+ remove: 'Remove',
427
427
  },
428
428
  units: {
429
- size: ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
430
- }
429
+ size: ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'],
430
+ },
431
431
  };
432
- }
433
- }
432
+ },
433
+ },
434
434
  };
435
435
  }
436
436
 
@@ -461,7 +461,7 @@ class Upload extends ElementMixin(ThemableMixin(PolymerElement)) {
461
461
  const unit = ~~(Math.log(bytes) / Math.log(base));
462
462
  const dec = Math.max(0, Math.min(3, unit - 1));
463
463
  const size = parseFloat((bytes / base ** unit).toFixed(dec));
464
- return size + ' ' + this.i18n.units.size[unit];
464
+ return `${size} ${this.i18n.units.size[unit]}`;
465
465
  }
466
466
 
467
467
  /** @private */
@@ -498,16 +498,12 @@ class Upload extends ElementMixin(ThemableMixin(PolymerElement)) {
498
498
 
499
499
  /** @private */
500
500
  _formatFileProgress(file) {
501
- return (
502
- file.totalStr +
503
- ': ' +
504
- file.progress +
505
- '% (' +
506
- (file.loaded > 0
501
+ const remainingTime =
502
+ file.loaded > 0
507
503
  ? this.i18n.uploading.remainingTime.prefix + file.remainingStr
508
- : this.i18n.uploading.remainingTime.unknown) +
509
- ')'
510
- );
504
+ : this.i18n.uploading.remainingTime.unknown;
505
+
506
+ return `${file.totalStr}: ${file.progress}% (${remainingTime})`;
511
507
  }
512
508
 
513
509
  /** @private */
@@ -549,7 +545,7 @@ class Upload extends ElementMixin(ThemableMixin(PolymerElement)) {
549
545
 
550
546
  /** @private */
551
547
  _configureXhr(xhr) {
552
- if (typeof this.headers == 'string') {
548
+ if (typeof this.headers === 'string') {
553
549
  try {
554
550
  this.headers = JSON.parse(this.headers);
555
551
  } catch (e) {
@@ -635,7 +631,7 @@ class Upload extends ElementMixin(ThemableMixin(PolymerElement)) {
635
631
 
636
632
  // More reliable than xhr.onload
637
633
  xhr.onreadystatechange = () => {
638
- if (xhr.readyState == 4) {
634
+ if (xhr.readyState === 4) {
639
635
  clearTimeout(stalledId);
640
636
  file.indeterminate = file.uploading = false;
641
637
  if (file.abort) {
@@ -648,8 +644,8 @@ class Upload extends ElementMixin(ThemableMixin(PolymerElement)) {
648
644
  const evt = this.dispatchEvent(
649
645
  new CustomEvent('upload-response', {
650
646
  detail: { file, xhr },
651
- cancelable: true
652
- })
647
+ cancelable: true,
648
+ }),
653
649
  );
654
650
 
655
651
  if (!evt) {
@@ -666,8 +662,8 @@ class Upload extends ElementMixin(ThemableMixin(PolymerElement)) {
666
662
  file.complete = !file.error;
667
663
  this.dispatchEvent(
668
664
  new CustomEvent(`upload-${file.error ? 'error' : 'success'}`, {
669
- detail: { file, xhr }
670
- })
665
+ detail: { file, xhr },
666
+ }),
671
667
  );
672
668
  this._notifyFileChanges(file);
673
669
  }
@@ -681,8 +677,8 @@ class Upload extends ElementMixin(ThemableMixin(PolymerElement)) {
681
677
  const evt = this.dispatchEvent(
682
678
  new CustomEvent('upload-before', {
683
679
  detail: { file, xhr },
684
- cancelable: true
685
- })
680
+ cancelable: true,
681
+ }),
686
682
  );
687
683
  if (!evt) {
688
684
  return;
@@ -700,8 +696,8 @@ class Upload extends ElementMixin(ThemableMixin(PolymerElement)) {
700
696
  xhr.upload.onloadstart = () => {
701
697
  this.dispatchEvent(
702
698
  new CustomEvent('upload-start', {
703
- detail: { file, xhr }
704
- })
699
+ detail: { file, xhr },
700
+ }),
705
701
  );
706
702
  this._notifyFileChanges(file);
707
703
  };
@@ -711,8 +707,8 @@ class Upload extends ElementMixin(ThemableMixin(PolymerElement)) {
711
707
  const uploadEvt = this.dispatchEvent(
712
708
  new CustomEvent('upload-request', {
713
709
  detail: { file, xhr, formData },
714
- cancelable: true
715
- })
710
+ cancelable: true,
711
+ }),
716
712
  );
717
713
  if (uploadEvt) {
718
714
  xhr.send(formData);
@@ -724,8 +720,8 @@ class Upload extends ElementMixin(ThemableMixin(PolymerElement)) {
724
720
  const evt = this.dispatchEvent(
725
721
  new CustomEvent('upload-retry', {
726
722
  detail: { file, xhr: file.xhr },
727
- cancelable: true
728
- })
723
+ cancelable: true,
724
+ }),
729
725
  );
730
726
  if (evt) {
731
727
  this._uploadFile(file);
@@ -737,8 +733,8 @@ class Upload extends ElementMixin(ThemableMixin(PolymerElement)) {
737
733
  const evt = this.dispatchEvent(
738
734
  new CustomEvent('upload-abort', {
739
735
  detail: { file, xhr: file.xhr },
740
- cancelable: true
741
- })
736
+ cancelable: true,
737
+ }),
742
738
  );
743
739
  if (evt) {
744
740
  file.abort = true;
@@ -751,7 +747,7 @@ class Upload extends ElementMixin(ThemableMixin(PolymerElement)) {
751
747
 
752
748
  /** @private */
753
749
  _notifyFileChanges(file) {
754
- var p = 'files.' + this.files.indexOf(file) + '.';
750
+ var p = `files.${this.files.indexOf(file)}.`;
755
751
  for (const i in file) {
756
752
  // eslint-disable-next-line no-prototype-builtins
757
753
  if (file.hasOwnProperty(i)) {
@@ -775,26 +771,26 @@ class Upload extends ElementMixin(ThemableMixin(PolymerElement)) {
775
771
  if (this.maxFilesReached) {
776
772
  this.dispatchEvent(
777
773
  new CustomEvent('file-reject', {
778
- detail: { file, error: this.i18n.error.tooManyFiles }
779
- })
774
+ detail: { file, error: this.i18n.error.tooManyFiles },
775
+ }),
780
776
  );
781
777
  return;
782
778
  }
783
779
  if (this.maxFileSize >= 0 && file.size > this.maxFileSize) {
784
780
  this.dispatchEvent(
785
781
  new CustomEvent('file-reject', {
786
- detail: { file, error: this.i18n.error.fileIsTooBig }
787
- })
782
+ detail: { file, error: this.i18n.error.fileIsTooBig },
783
+ }),
788
784
  );
789
785
  return;
790
786
  }
791
787
  const fileExt = file.name.match(/\.[^.]*$|$/)[0];
792
- const re = new RegExp('^(' + this.accept.replace(/[, ]+/g, '|').replace(/\/\*/g, '/.*') + ')$', 'i');
788
+ const re = new RegExp(`^(${this.accept.replace(/[, ]+/g, '|').replace(/\/\*/g, '/.*')})$`, 'i');
793
789
  if (this.accept && !(re.test(file.type) || re.test(fileExt))) {
794
790
  this.dispatchEvent(
795
791
  new CustomEvent('file-reject', {
796
- detail: { file, error: this.i18n.error.incorrectFileType }
797
- })
792
+ detail: { file, error: this.i18n.error.incorrectFileType },
793
+ }),
798
794
  );
799
795
  return;
800
796
  }
@@ -884,22 +880,30 @@ class Upload extends ElementMixin(ThemableMixin(PolymerElement)) {
884
880
 
885
881
  /** @private */
886
882
  _dragoverChanged(dragover) {
887
- dragover ? this.setAttribute('dragover', dragover) : this.removeAttribute('dragover');
883
+ if (dragover) {
884
+ this.setAttribute('dragover', dragover);
885
+ } else {
886
+ this.removeAttribute('dragover');
887
+ }
888
888
  }
889
889
 
890
890
  /** @private */
891
891
  _dragoverValidChanged(dragoverValid) {
892
- dragoverValid ? this.setAttribute('dragover-valid', dragoverValid) : this.removeAttribute('dragover-valid');
892
+ if (dragoverValid) {
893
+ this.setAttribute('dragover-valid', dragoverValid);
894
+ } else {
895
+ this.removeAttribute('dragover-valid');
896
+ }
893
897
  }
894
898
 
895
899
  /** @private */
896
900
  _i18nPlural(value, plural) {
897
- return value == 1 ? plural.one : plural.many;
901
+ return value === 1 ? plural.one : plural.many;
898
902
  }
899
903
 
900
904
  /** @private */
901
905
  _isMultiple(maxFiles) {
902
- return maxFiles != 1;
906
+ return maxFiles !== 1;
903
907
  }
904
908
 
905
909
  /**
@@ -67,7 +67,7 @@ registerStyles(
67
67
  border-top: 1px solid var(--lumo-contrast-10pct);
68
68
  }
69
69
  `,
70
- { moduleId: 'lumo-upload' }
70
+ { moduleId: 'lumo-upload' },
71
71
  );
72
72
 
73
73
  const uploadFile = css`
@@ -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
  );