@progress/kendo-angular-upload 16.3.0-develop.1 → 16.3.0-develop.11

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.
@@ -5,9 +5,9 @@
5
5
  /* eslint-disable @typescript-eslint/no-unused-vars */
6
6
  /* eslint-disable @typescript-eslint/no-explicit-any */
7
7
  import { HttpHeaders } from '@angular/common/http';
8
- import { Component, ContentChild, ElementRef, EventEmitter, forwardRef, HostBinding, Input, NgZone, Output, Renderer2, ViewChild, isDevMode, ChangeDetectorRef, Injector } from '@angular/core';
9
- import { NG_VALUE_ACCESSOR, NgControl } from '@angular/forms';
10
- import { guid, isDocumentAvailable, KendoInput, Keys, isChanged, isControlRequired } from '@progress/kendo-angular-common';
8
+ import { Component, ElementRef, EventEmitter, forwardRef, HostBinding, Input, NgZone, Output, Renderer2, ViewChild, isDevMode, ChangeDetectorRef, Injector } from '@angular/core';
9
+ import { NG_VALUE_ACCESSOR } from '@angular/forms';
10
+ import { isDocumentAvailable, KendoInput, Keys, isChanged } from '@progress/kendo-angular-common';
11
11
  import { L10N_PREFIX, LocalizationService } from '@progress/kendo-angular-l10n';
12
12
  import { fromEvent, merge } from 'rxjs';
13
13
  import { filter } from 'rxjs/operators';
@@ -15,11 +15,10 @@ import { validatePackage } from '@progress/kendo-licensing';
15
15
  import { packageMetadata } from './package-metadata';
16
16
  import { FileState } from './types';
17
17
  import { NavigationService } from './navigation.service';
18
- import { FileTemplateDirective } from './templates/file-template.directive';
19
18
  import { UploadService } from './upload.service';
20
19
  import { hasClasses, IGNORE_TARGET_CLASSES, isFocusable, UPLOAD_CLASSES, validateInitialFileInfo } from './common/util';
21
20
  import { DropZoneService } from './dropzone.service';
22
- import { FileInfoTemplateDirective } from './templates/file-info-template.directive';
21
+ import { UploadFileSelectBase } from './common/base';
23
22
  import * as i0 from "@angular/core";
24
23
  import * as i1 from "./upload.service";
25
24
  import * as i2 from "@progress/kendo-angular-l10n";
@@ -45,8 +44,9 @@ let idx = 0;
45
44
  /**
46
45
  * Represents the [Kendo UI Upload component for Angular]({% slug overview_upload %}).
47
46
  */
48
- export class UploadComponent {
47
+ export class UploadComponent extends UploadFileSelectBase {
49
48
  constructor(uploadService, localization, navigation, dropZoneService, zone, renderer, cdr, wrapper, injector) {
49
+ super(uploadService, navigation, cdr, injector, zone);
50
50
  this.uploadService = uploadService;
51
51
  this.localization = localization;
52
52
  this.navigation = navigation;
@@ -61,41 +61,15 @@ export class UploadComponent {
61
61
  * @default false
62
62
  */
63
63
  this.chunkable = false;
64
- /**
65
- * Enables the selection of multiple files
66
- * ([see example]({% slug fileprocessing_upload %}#toc-upload-of-sinlge-or-multiple-files)).
67
- * If set to `false`, only one file can be selected at a time.
68
- * @default true
69
- */
70
- this.multiple = true;
71
- /**
72
- * Disables the Upload ([see example]({% slug disabledstate_upload %})).
73
- * To learn how to disable the component in reactive forms, refer to the article on [Forms Support](slug:formssupport_upload#toc-managing-the-upload-disabled-state-in-reactive-forms).
74
- * @default false
75
- */
76
- this.disabled = false;
77
64
  /**
78
65
  * Toggles the visibility of the file list.
79
66
  * @default true
80
67
  */
81
68
  this.showFileList = true;
82
- /**
83
- * Specifies the [`tabindex`](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/tabindex) of the component.
84
- * @default 0
85
- */
86
- this.tabindex = 0;
87
- /**
88
- * @hidden
89
- */
90
- this.focusableId = `k-${guid()}`;
91
69
  /**
92
70
  * Specifies the possible layout of the action buttons.
93
71
  */
94
72
  this.actionsLayout = 'end';
95
- /**
96
- * Fires when the user navigates outside the component.
97
- */
98
- this.onBlur = new EventEmitter();
99
73
  /**
100
74
  * Fires when the upload is canceled while in progress.
101
75
  */
@@ -112,26 +86,14 @@ export class UploadComponent {
112
86
  * Fires when an `upload` or `remove` operation has failed.
113
87
  */
114
88
  this.error = new EventEmitter();
115
- /**
116
- * Fires when the component is focused.
117
- */
118
- this.onFocus = new EventEmitter();
119
89
  /**
120
90
  * Fires when the upload of a file has been paused.
121
91
  */
122
92
  this.pause = new EventEmitter();
123
- /**
124
- * Fires when an uploaded file is about to be removed. If prevented, the files will remain in the list.
125
- */
126
- this.remove = new EventEmitter();
127
93
  /**
128
94
  * Fires when the upload of a file has been resumed.
129
95
  */
130
96
  this.resume = new EventEmitter();
131
- /**
132
- * Fires when files are selected. If prevented, the selected files will not be added to the list.
133
- */
134
- this.select = new EventEmitter();
135
97
  /**
136
98
  * Fires when an `upload` or `remove` operation is successfully completed.
137
99
  */
@@ -148,17 +110,6 @@ export class UploadComponent {
148
110
  * Fires when the value of the component has changed as a result of a successful `upload`, `remove` or `clear` operation.
149
111
  */
150
112
  this.valueChange = new EventEmitter();
151
- this.hostDefaultClasses = true;
152
- /**
153
- * @hidden
154
- */
155
- this._restrictions = {
156
- allowedExtensions: [],
157
- maxFileSize: 0,
158
- minFileSize: 0
159
- };
160
- this.onTouchedCallback = (_) => { };
161
- this.onChangeCallback = (_) => { };
162
113
  validatePackage(packageMetadata);
163
114
  this.fileList = this.uploadService.files;
164
115
  this.localizationChangeSubscription = localization.changes.subscribe(({ rtl }) => {
@@ -316,42 +267,14 @@ export class UploadComponent {
316
267
  get tabIndex() {
317
268
  return this.tabindex;
318
269
  }
319
- /**
320
- * Sets the restrictions for selected files ([see example]({% slug api_upload_filerestrictions %})).
321
- */
322
- set restrictions(restrictions) {
323
- const parsedRestrictions = Object.assign({}, this._restrictions, restrictions);
324
- this._restrictions = parsedRestrictions;
325
- }
326
- get restrictions() {
327
- return this._restrictions;
328
- }
329
- get hostRole() {
330
- return 'application';
331
- }
332
- get hostDisabledClass() {
333
- return this.disabled;
334
- }
335
270
  get dir() {
336
271
  return this.direction;
337
272
  }
338
- /**
339
- * @hidden
340
- */
341
- get formControl() {
342
- const ngControl = this.injector.get(NgControl, null);
343
- return ngControl?.control || null;
344
- }
345
- /**
346
- * @hidden
347
- */
348
- get isControlRequired() {
349
- return isControlRequired(this.formControl);
350
- }
351
273
  ngOnInit() {
352
274
  this.verifySettings();
353
- const { buttonId } = this.getIds();
275
+ const { buttonId, fileListId } = this.getIds();
354
276
  this.focusableId = buttonId;
277
+ this.fileListId = fileListId;
355
278
  this.uploadService.setChunkSettings(this.chunkable);
356
279
  if (this.zoneId) {
357
280
  this.dropZoneService.addComponent(this, this.zoneId);
@@ -394,47 +317,7 @@ export class UploadComponent {
394
317
  * @hidden
395
318
  */
396
319
  writeValue(newValue) {
397
- let isValid = true;
398
- if (newValue instanceof Array) {
399
- newValue.forEach((file) => {
400
- if (!validateInitialFileInfo(file)) {
401
- isValid = false;
402
- }
403
- });
404
- if (isValid) {
405
- this.uploadService.addInitialFiles(newValue);
406
- }
407
- }
408
- if (newValue === null) {
409
- this.fileList.clear();
410
- }
411
- this.cdr.markForCheck();
412
- }
413
- /**
414
- * @hidden
415
- */
416
- registerOnChange(fn) {
417
- this.onChangeCallback = fn;
418
- }
419
- /**
420
- * @hidden
421
- */
422
- registerOnTouched(fn) {
423
- this.onTouchedCallback = fn;
424
- }
425
- /**
426
- * @hidden
427
- */
428
- setDisabledState(isDisabled) {
429
- this.disabled = isDisabled;
430
- }
431
- /**
432
- * @hidden
433
- */
434
- onFileSelectButtonFocus() {
435
- if (!this.navigation.focused) {
436
- this.navigation.focusedIndex = -1;
437
- }
320
+ super.writeValue(newValue, validateInitialFileInfo, 'addInitialFiles');
438
321
  }
439
322
  /**
440
323
  * @hidden
@@ -481,42 +364,8 @@ export class UploadComponent {
481
364
  getIds() {
482
365
  const id = ++idx;
483
366
  const buttonId = `k-upload-button-${id}`;
484
- const inputId = `k-upload-input-${id}`;
485
- return { buttonId, inputId };
486
- }
487
- /**
488
- * Focuses the underlying input element.
489
- */
490
- focus() {
491
- setTimeout(() => {
492
- this.fileSelectButton.nativeElement.focus();
493
- this.navigation.focused = true;
494
- this.onFocus.emit();
495
- });
496
- }
497
- /**
498
- * @hidden
499
- * @deprecated
500
- */
501
- focusComponent() {
502
- this.focus();
503
- }
504
- /**
505
- * Blurs the Upload if it was previously focused.
506
- */
507
- blur() {
508
- if (this.navigation.focused) {
509
- this.navigation.focused = false;
510
- document.activeElement.blur();
511
- this.onBlur.emit();
512
- }
513
- }
514
- /**
515
- * @hidden
516
- * @deprecated
517
- */
518
- blurComponent() {
519
- this.blur();
367
+ const fileListId = `k-upload-file-list-${id}`;
368
+ return { buttonId, fileListId };
520
369
  }
521
370
  /**
522
371
  * Pauses the upload process of a file that is currently uploading.
@@ -674,7 +523,7 @@ export class UploadComponent {
674
523
  }
675
524
  }
676
525
  UploadComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.2.10", ngImport: i0, type: UploadComponent, deps: [{ token: i1.UploadService }, { token: i2.LocalizationService }, { token: i3.NavigationService }, { token: i4.DropZoneService }, { token: i0.NgZone }, { token: i0.Renderer2 }, { token: i0.ChangeDetectorRef }, { token: i0.ElementRef }, { token: i0.Injector }], target: i0.ɵɵFactoryTarget.Component });
677
- UploadComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.10", type: UploadComponent, selector: "kendo-upload", inputs: { autoUpload: "autoUpload", batch: "batch", withCredentials: "withCredentials", saveField: "saveField", saveHeaders: "saveHeaders", saveMethod: "saveMethod", saveUrl: "saveUrl", responseType: "responseType", removeField: "removeField", removeHeaders: "removeHeaders", removeMethod: "removeMethod", removeUrl: "removeUrl", chunkable: "chunkable", concurrent: "concurrent", multiple: "multiple", disabled: "disabled", showFileList: "showFileList", tabindex: "tabindex", zoneId: "zoneId", tabIndex: "tabIndex", accept: "accept", restrictions: "restrictions", focusableId: "focusableId", actionsLayout: "actionsLayout" }, outputs: { onBlur: "blur", cancel: "cancel", clear: "clear", complete: "complete", error: "error", onFocus: "focus", pause: "pause", remove: "remove", resume: "resume", select: "select", success: "success", upload: "upload", uploadProgress: "uploadProgress", valueChange: "valueChange" }, host: { properties: { "class.k-upload": "this.hostDefaultClasses", "attr.role": "this.hostRole", "class.k-disabled": "this.hostDisabledClass", "attr.dir": "this.dir" } }, providers: [
526
+ UploadComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "15.2.10", type: UploadComponent, selector: "kendo-upload", inputs: { autoUpload: "autoUpload", batch: "batch", withCredentials: "withCredentials", saveField: "saveField", saveHeaders: "saveHeaders", saveMethod: "saveMethod", saveUrl: "saveUrl", responseType: "responseType", removeField: "removeField", removeHeaders: "removeHeaders", removeMethod: "removeMethod", removeUrl: "removeUrl", chunkable: "chunkable", concurrent: "concurrent", showFileList: "showFileList", tabIndex: "tabIndex", actionsLayout: "actionsLayout" }, outputs: { cancel: "cancel", clear: "clear", complete: "complete", error: "error", pause: "pause", resume: "resume", success: "success", upload: "upload", uploadProgress: "uploadProgress", valueChange: "valueChange" }, host: { properties: { "attr.dir": "this.dir" } }, providers: [
678
527
  LocalizationService,
679
528
  NavigationService,
680
529
  UploadService,
@@ -688,7 +537,7 @@ UploadComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", versio
688
537
  provide: KendoInput,
689
538
  useExisting: forwardRef(() => UploadComponent)
690
539
  }
691
- ], queries: [{ propertyName: "fileTemplate", first: true, predicate: FileTemplateDirective, descendants: true }, { propertyName: "fileInfoTemplate", first: true, predicate: FileInfoTemplateDirective, descendants: true }], viewQueries: [{ propertyName: "fileSelectInput", first: true, predicate: ["fileSelectInput"], descendants: true, static: true }, { propertyName: "fileSelectButton", first: true, predicate: ["fileSelectButton"], descendants: true, read: ElementRef, static: true }], exportAs: ["kendoUpload"], usesOnChanges: true, ngImport: i0, template: `
540
+ ], viewQueries: [{ propertyName: "fileSelectInput", first: true, predicate: ["fileSelectInput"], descendants: true, static: true }], exportAs: ["kendoUpload"], usesInheritance: true, usesOnChanges: true, ngImport: i0, template: `
692
541
  <ng-container kendoUploadLocalizedMessages
693
542
  i18n-cancel="kendo.upload.cancel|The text for the Cancel button"
694
543
  cancel="Cancel"
@@ -762,12 +611,13 @@ UploadComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", versio
762
611
  #fileSelectButton
763
612
  class="k-upload-button"
764
613
  type="button"
765
- role="button"
766
614
  (click)="fileSelectInput.click()"
767
615
  (focus)="onFileSelectButtonFocus()"
768
616
  [id]="focusableId"
769
617
  [attr.aria-label]="textFor('select')"
770
618
  [attr.tabindex]="tabindex"
619
+ [attr.aria-expanded]="hasFileList"
620
+ [attr.aria-controls]="hasFileList ? fileListId : undefined"
771
621
  >
772
622
  {{textFor('select')}}
773
623
  </button>
@@ -785,12 +635,13 @@ UploadComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", versio
785
635
  </kendo-upload-status-total>
786
636
  <div class="k-dropzone-hint">{{textFor('dropFilesHere')}}</div>
787
637
  </div>
788
- <ul kendo-upload-file-list *ngIf="showFileList && fileList.count > 0"
638
+ <ul kendo-upload-file-list *ngIf="hasFileList"
789
639
  class="k-upload-files k-reset"
790
640
  [disabled]="disabled"
791
641
  [fileList]="fileList.files"
792
642
  [fileTemplate]="fileTemplate"
793
- [fileInfoTemplate]="fileInfoTemplate">
643
+ [fileInfoTemplate]="fileInfoTemplate"
644
+ [id]="fileListId">
794
645
  </ul>
795
646
  <kendo-upload-action-buttons
796
647
  *ngIf="showActionButtons"
@@ -892,12 +743,13 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImpo
892
743
  #fileSelectButton
893
744
  class="k-upload-button"
894
745
  type="button"
895
- role="button"
896
746
  (click)="fileSelectInput.click()"
897
747
  (focus)="onFileSelectButtonFocus()"
898
748
  [id]="focusableId"
899
749
  [attr.aria-label]="textFor('select')"
900
750
  [attr.tabindex]="tabindex"
751
+ [attr.aria-expanded]="hasFileList"
752
+ [attr.aria-controls]="hasFileList ? fileListId : undefined"
901
753
  >
902
754
  {{textFor('select')}}
903
755
  </button>
@@ -915,12 +767,13 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImpo
915
767
  </kendo-upload-status-total>
916
768
  <div class="k-dropzone-hint">{{textFor('dropFilesHere')}}</div>
917
769
  </div>
918
- <ul kendo-upload-file-list *ngIf="showFileList && fileList.count > 0"
770
+ <ul kendo-upload-file-list *ngIf="hasFileList"
919
771
  class="k-upload-files k-reset"
920
772
  [disabled]="disabled"
921
773
  [fileList]="fileList.files"
922
774
  [fileTemplate]="fileTemplate"
923
- [fileInfoTemplate]="fileInfoTemplate">
775
+ [fileInfoTemplate]="fileInfoTemplate"
776
+ [id]="fileListId">
924
777
  </ul>
925
778
  <kendo-upload-action-buttons
926
779
  *ngIf="showActionButtons"
@@ -957,42 +810,16 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImpo
957
810
  type: Input
958
811
  }], concurrent: [{
959
812
  type: Input
960
- }], multiple: [{
961
- type: Input
962
- }], disabled: [{
963
- type: Input
964
813
  }], showFileList: [{
965
814
  type: Input
966
- }], tabindex: [{
967
- type: Input
968
- }], zoneId: [{
969
- type: Input
970
815
  }], tabIndex: [{
971
816
  type: Input,
972
817
  args: ['tabIndex']
973
- }], accept: [{
974
- type: Input
975
- }], restrictions: [{
976
- type: Input
977
- }], focusableId: [{
978
- type: Input
979
818
  }], actionsLayout: [{
980
819
  type: Input
981
- }], fileTemplate: [{
982
- type: ContentChild,
983
- args: [FileTemplateDirective]
984
- }], fileInfoTemplate: [{
985
- type: ContentChild,
986
- args: [FileInfoTemplateDirective]
987
820
  }], fileSelectInput: [{
988
821
  type: ViewChild,
989
822
  args: ['fileSelectInput', { static: true }]
990
- }], fileSelectButton: [{
991
- type: ViewChild,
992
- args: ['fileSelectButton', { static: true, read: ElementRef }]
993
- }], onBlur: [{
994
- type: Output,
995
- args: ['blur']
996
823
  }], cancel: [{
997
824
  type: Output
998
825
  }], clear: [{
@@ -1001,17 +828,10 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImpo
1001
828
  type: Output
1002
829
  }], error: [{
1003
830
  type: Output
1004
- }], onFocus: [{
1005
- type: Output,
1006
- args: ['focus']
1007
831
  }], pause: [{
1008
832
  type: Output
1009
- }], remove: [{
1010
- type: Output
1011
833
  }], resume: [{
1012
834
  type: Output
1013
- }], select: [{
1014
- type: Output
1015
835
  }], success: [{
1016
836
  type: Output
1017
837
  }], upload: [{
@@ -1020,15 +840,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.10", ngImpo
1020
840
  type: Output
1021
841
  }], valueChange: [{
1022
842
  type: Output
1023
- }], hostDefaultClasses: [{
1024
- type: HostBinding,
1025
- args: ['class.k-upload']
1026
- }], hostRole: [{
1027
- type: HostBinding,
1028
- args: ['attr.role']
1029
- }], hostDisabledClass: [{
1030
- type: HostBinding,
1031
- args: ['class.k-disabled']
1032
843
  }], dir: [{
1033
844
  type: HostBinding,
1034
845
  args: ['attr.dir']