1 | import * as i0 from '@angular/core';
|
2 | import { EventEmitter, Directive, Optional, Host, Input, Output, HostBinding, HostListener, forwardRef, ElementRef, Component, ChangeDetectionStrategy, ViewChild, ContentChild, Injectable, NgModule } from '@angular/core';
|
3 | import * as i2 from '@angular/common';
|
4 | import { CommonModule } from '@angular/common';
|
5 | import * as i1 from '@angular/forms';
|
6 | import { NG_VALUE_ACCESSOR, FormsModule } from '@angular/forms';
|
7 | import * as i5 from '@angular/cdk/portal';
|
8 | import { TemplatePortalDirective, PortalModule } from '@angular/cdk/portal';
|
9 | import * as i3 from '@angular/material/icon';
|
10 | import { MatIconModule } from '@angular/material/icon';
|
11 | import * as i4 from '@angular/material/button';
|
12 | import { MatButtonModule } from '@angular/material/button';
|
13 | import { coerceBooleanProperty } from '@angular/cdk/coercion';
|
14 | import { ENTER } from '@angular/cdk/keycodes';
|
15 | import { Subject, merge, fromEvent } from 'rxjs';
|
16 | import { filter, takeUntil, tap } from 'rxjs/operators';
|
17 | import { mixinControlValueAccessor, mixinDisabled } from '@covalent/core/common';
|
18 | import * as i1$1 from '@angular/common/http';
|
19 | import { HttpRequest, HttpHeaders, HttpParams, HttpEventType } from '@angular/common/http';
|
20 |
|
21 | class TdFileSelectDirective {
|
22 | model;
|
23 | _multiple = false;
|
24 | |
25 |
|
26 |
|
27 |
|
28 |
|
29 | set multiple(multiple) {
|
30 | this._multiple = coerceBooleanProperty(multiple);
|
31 | }
|
32 | |
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 | fileSelect = new EventEmitter();
|
39 | |
40 |
|
41 |
|
42 | get multipleBinding() {
|
43 | return this._multiple ? '' : undefined;
|
44 | }
|
45 | constructor(model) {
|
46 | this.model = model;
|
47 | }
|
48 | |
49 |
|
50 |
|
51 |
|
52 |
|
53 | onChange(event) {
|
54 | if (event.target instanceof HTMLInputElement) {
|
55 | const fileInputEl = event.target;
|
56 | const files = fileInputEl.files || new FileList();
|
57 | if (files.length) {
|
58 | const value = this._multiple
|
59 | ? files.length > 1
|
60 | ? files
|
61 | : files[0]
|
62 | : files[0];
|
63 | this.model
|
64 | ? this.model.update.emit(value)
|
65 | : this.fileSelect.emit(value);
|
66 | }
|
67 | }
|
68 | }
|
69 | static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.1.2", ngImport: i0, type: TdFileSelectDirective, deps: [{ token: i1.NgModel, host: true, optional: true }], target: i0.ɵɵFactoryTarget.Directive });
|
70 | static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "17.1.2", type: TdFileSelectDirective, selector: "[tdFileSelect]", inputs: { multiple: "multiple" }, outputs: { fileSelect: "fileSelect" }, host: { listeners: { "change": "onChange($event)" }, properties: { "attr.multiple": "this.multipleBinding" } }, ngImport: i0 });
|
71 | }
|
72 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.1.2", ngImport: i0, type: TdFileSelectDirective, decorators: [{
|
73 | type: Directive,
|
74 | args: [{
|
75 | selector: '[tdFileSelect]',
|
76 | }]
|
77 | }], ctorParameters: () => [{ type: i1.NgModel, decorators: [{
|
78 | type: Optional
|
79 | }, {
|
80 | type: Host
|
81 | }] }], propDecorators: { multiple: [{
|
82 | type: Input
|
83 | }], fileSelect: [{
|
84 | type: Output
|
85 | }], multipleBinding: [{
|
86 | type: HostBinding,
|
87 | args: ['attr.multiple']
|
88 | }], onChange: [{
|
89 | type: HostListener,
|
90 | args: ['change', ['$event']]
|
91 | }] } });
|
92 |
|
93 | class TdFileDropBase {
|
94 | }
|
95 | class TdFileDropDirective {
|
96 | _renderer;
|
97 | _element;
|
98 | _ngZone;
|
99 | _multiple = false;
|
100 | _dragenterListener;
|
101 | _dragleaveListener;
|
102 | _dragoverListener;
|
103 | |
104 |
|
105 |
|
106 |
|
107 |
|
108 | set multiple(multiple) {
|
109 | this._multiple = coerceBooleanProperty(multiple);
|
110 | }
|
111 | disabled = false;
|
112 | |
113 |
|
114 |
|
115 |
|
116 |
|
117 | fileDrop = new EventEmitter();
|
118 | |
119 |
|
120 |
|
121 | get multipleBinding() {
|
122 | return this._multiple ? '' : undefined;
|
123 | }
|
124 | |
125 |
|
126 |
|
127 | get disabledBinding() {
|
128 | return this.disabled ? '' : undefined;
|
129 | }
|
130 | constructor(_renderer, _element, _ngZone) {
|
131 | this._renderer = _renderer;
|
132 | this._element = _element;
|
133 | this._ngZone = _ngZone;
|
134 | }
|
135 | ngOnInit() {
|
136 | this._ngZone.runOutsideAngular(() => {
|
137 |
|
138 |
|
139 | this._dragenterListener = this._renderer.listen(this._element.nativeElement, 'dragenter', (event) => {
|
140 | if (!this.disabled) {
|
141 | this._renderer.addClass(this._element.nativeElement, 'drop-zone');
|
142 | }
|
143 | this._stopEvent(event);
|
144 | });
|
145 |
|
146 |
|
147 | this._dragleaveListener = this._renderer.listen(this._element.nativeElement, 'dragleave', (event) => {
|
148 | this._renderer.removeClass(this._element.nativeElement, 'drop-zone');
|
149 | this._stopEvent(event);
|
150 | });
|
151 |
|
152 |
|
153 |
|
154 | this._dragoverListener = this._renderer.listen(this._element.nativeElement, 'dragover', (event) => {
|
155 | const transfer = event.dataTransfer || new DataTransfer();
|
156 | transfer.dropEffect = this._typeCheck(transfer.types);
|
157 | if (this.disabled ||
|
158 | (!this._multiple &&
|
159 | ((transfer.items && transfer.items.length > 1) ||
|
160 | transfer.mozItemCount > 1))) {
|
161 | transfer.dropEffect = 'none';
|
162 | }
|
163 | else {
|
164 | transfer.dropEffect = 'copy';
|
165 | }
|
166 | this._stopEvent(event);
|
167 | });
|
168 | });
|
169 | }
|
170 | ngOnDestroy() {
|
171 | this._dragenterListener?.();
|
172 | this._dragleaveListener?.();
|
173 | this._dragoverListener?.();
|
174 | }
|
175 | |
176 |
|
177 |
|
178 |
|
179 |
|
180 | onDrop(event) {
|
181 | if (!this.disabled) {
|
182 | const transfer = event.dataTransfer ?? new DataTransfer();
|
183 | const files = transfer.files;
|
184 | if (files.length) {
|
185 | const value = this._multiple
|
186 | ? files.length > 1
|
187 | ? files
|
188 | : files[0]
|
189 | : files[0];
|
190 | this.fileDrop.emit(value);
|
191 | }
|
192 | }
|
193 | this._renderer.removeClass(this._element.nativeElement, 'drop-zone');
|
194 | this._stopEvent(event);
|
195 | }
|
196 | |
197 |
|
198 |
|
199 | _typeCheck(types) {
|
200 | let dropEffect = 'none';
|
201 | if (types &&
|
202 | ((types.contains && types.contains('Files')) ||
|
203 | (types.indexOf && types.indexOf('Files') !== -1))) {
|
204 | dropEffect = 'copy';
|
205 | }
|
206 | return dropEffect;
|
207 | }
|
208 | _stopEvent(event) {
|
209 | event.preventDefault();
|
210 | event.stopPropagation();
|
211 | }
|
212 | static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.1.2", ngImport: i0, type: TdFileDropDirective, deps: [{ token: i0.Renderer2 }, { token: i0.ElementRef }, { token: i0.NgZone }], target: i0.ɵɵFactoryTarget.Directive });
|
213 | static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "17.1.2", type: TdFileDropDirective, selector: "[tdFileDrop]", inputs: { multiple: "multiple", disabled: "disabled" }, outputs: { fileDrop: "fileDrop" }, host: { listeners: { "drop": "onDrop($event)" }, properties: { "attr.multiple": "this.multipleBinding", "attr.disabled": "this.disabledBinding" } }, ngImport: i0 });
|
214 | }
|
215 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.1.2", ngImport: i0, type: TdFileDropDirective, decorators: [{
|
216 | type: Directive,
|
217 | args: [{ selector: '[tdFileDrop]' }]
|
218 | }], ctorParameters: () => [{ type: i0.Renderer2 }, { type: i0.ElementRef }, { type: i0.NgZone }], propDecorators: { multiple: [{
|
219 | type: Input
|
220 | }], disabled: [{
|
221 | type: Input
|
222 | }], fileDrop: [{
|
223 | type: Output
|
224 | }], multipleBinding: [{
|
225 | type: HostBinding,
|
226 | args: ['attr.multiple']
|
227 | }], disabledBinding: [{
|
228 | type: HostBinding,
|
229 | args: ['attr.disabled']
|
230 | }], onDrop: [{
|
231 | type: HostListener,
|
232 | args: ['drop', ['$event']]
|
233 | }] } });
|
234 |
|
235 | class TdFileInputLabelDirective extends TemplatePortalDirective {
|
236 | constructor(templateRef, viewContainerRef) {
|
237 | super(templateRef, viewContainerRef);
|
238 | }
|
239 | static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.1.2", ngImport: i0, type: TdFileInputLabelDirective, deps: [{ token: i0.TemplateRef }, { token: i0.ViewContainerRef }], target: i0.ɵɵFactoryTarget.Directive });
|
240 | static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "17.1.2", type: TdFileInputLabelDirective, selector: "[tdFileInputLabel]ng-template", usesInheritance: true, ngImport: i0 });
|
241 | }
|
242 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.1.2", ngImport: i0, type: TdFileInputLabelDirective, decorators: [{
|
243 | type: Directive,
|
244 | args: [{
|
245 | selector: '[tdFileInputLabel]ng-template',
|
246 | }]
|
247 | }], ctorParameters: () => [{ type: i0.TemplateRef }, { type: i0.ViewContainerRef }] });
|
248 | class TdFileInputBase {
|
249 | _changeDetectorRef;
|
250 | constructor(_changeDetectorRef) {
|
251 | this._changeDetectorRef = _changeDetectorRef;
|
252 | }
|
253 | }
|
254 | const _TdFileInputMixinBase = mixinControlValueAccessor(mixinDisabled(TdFileInputBase));
|
255 | class TdFileInputComponent extends _TdFileInputMixinBase {
|
256 | _ngZone;
|
257 | _renderer;
|
258 | _multiple = false;
|
259 |
|
260 | _inputButton;
|
261 |
|
262 | _inputElement;
|
263 | get inputElement() {
|
264 | return this._inputElement.nativeElement;
|
265 | }
|
266 | |
267 |
|
268 |
|
269 |
|
270 | color;
|
271 | |
272 |
|
273 |
|
274 |
|
275 | set multiple(multiple) {
|
276 | this._multiple = coerceBooleanProperty(multiple);
|
277 | }
|
278 | get multiple() {
|
279 | return this._multiple;
|
280 | }
|
281 | |
282 |
|
283 |
|
284 |
|
285 |
|
286 | accept;
|
287 | |
288 |
|
289 |
|
290 |
|
291 |
|
292 | selectFile = new EventEmitter();
|
293 | _destroy$ = new Subject();
|
294 | constructor(_ngZone, _renderer, _changeDetectorRef) {
|
295 | super(_changeDetectorRef);
|
296 | this._ngZone = _ngZone;
|
297 | this._renderer = _renderer;
|
298 | }
|
299 | ngOnInit() {
|
300 | this._ngZone.runOutsideAngular(() => {
|
301 | merge(fromEvent(this._inputButton.nativeElement, 'click'), fromEvent(this._inputButton.nativeElement, 'keyup').pipe(filter((event) => event.keyCode === ENTER)))
|
302 | .pipe(takeUntil(this._destroy$))
|
303 | .subscribe(() => this._inputElement.nativeElement.click());
|
304 | });
|
305 | }
|
306 | ngOnDestroy() {
|
307 | this._destroy$.next();
|
308 | }
|
309 | |
310 |
|
311 |
|
312 | handleSelect(files) {
|
313 | this.writeValue(files);
|
314 | this.selectFile.emit(files);
|
315 | }
|
316 | |
317 |
|
318 |
|
319 | clear() {
|
320 | this.writeValue(undefined);
|
321 | this._renderer.setProperty(this.inputElement, 'value', '');
|
322 | }
|
323 |
|
324 | onDisabledChange(v) {
|
325 | if (v) {
|
326 | this.clear();
|
327 | }
|
328 | }
|
329 | |
330 |
|
331 |
|
332 | setDisabledState(isDisabled) {
|
333 | this.disabled = isDisabled;
|
334 | }
|
335 | static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.1.2", ngImport: i0, type: TdFileInputComponent, deps: [{ token: i0.NgZone }, { token: i0.Renderer2 }, { token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Component });
|
336 | static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "17.1.2", type: TdFileInputComponent, selector: "td-file-input", inputs: { disabled: "disabled", value: "value", color: "color", multiple: "multiple", accept: "accept" }, outputs: { selectFile: "selectFile" }, providers: [
|
337 | {
|
338 | provide: NG_VALUE_ACCESSOR,
|
339 | useExisting: forwardRef(() => TdFileInputComponent),
|
340 | multi: true,
|
341 | },
|
342 | ], viewQueries: [{ propertyName: "_inputButton", first: true, predicate: ["fileInputButton"], descendants: true, read: ElementRef, static: true }, { propertyName: "_inputElement", first: true, predicate: ["fileInput"], descendants: true, static: true }], usesInheritance: true, ngImport: i0, template: "<button\n #fileInputButton\n mat-stroked-button\n class=\"td-file-input\"\n type=\"button\"\n [color]=\"color\"\n [multiple]=\"multiple\"\n [disabled]=\"disabled\"\n (fileDrop)=\"handleSelect($event)\"\n tdFileDrop\n>\n <ng-content></ng-content>\n</button>\n<input\n #fileInput\n class=\"td-file-input-hidden\"\n type=\"file\"\n [attr.accept]=\"accept\"\n (fileSelect)=\"handleSelect($event)\"\n [multiple]=\"multiple\"\n [disabled]=\"disabled\"\n tdFileSelect\n/>\n", styles: [":host .td-file-input{padding-left:8px;padding-right:8px}:host input.td-file-input-hidden{display:none}:host ::ng-deep .mdc-button__label{display:flex;align-items:center}:host .drop-zone{border-radius:3px}:host .drop-zone *{pointer-events:none}\n"], dependencies: [{ kind: "component", type: i4.MatButton, selector: " button[mat-button], button[mat-raised-button], button[mat-flat-button], button[mat-stroked-button] ", exportAs: ["matButton"] }, { kind: "directive", type: TdFileSelectDirective, selector: "[tdFileSelect]", inputs: ["multiple"], outputs: ["fileSelect"] }, { kind: "directive", type: TdFileDropDirective, selector: "[tdFileDrop]", inputs: ["multiple", "disabled"], outputs: ["fileDrop"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
|
343 | }
|
344 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.1.2", ngImport: i0, type: TdFileInputComponent, decorators: [{
|
345 | type: Component,
|
346 | args: [{ changeDetection: ChangeDetectionStrategy.OnPush, providers: [
|
347 | {
|
348 | provide: NG_VALUE_ACCESSOR,
|
349 | useExisting: forwardRef(() => TdFileInputComponent),
|
350 | multi: true,
|
351 | },
|
352 | ], selector: 'td-file-input', inputs: ['disabled', 'value'], template: "<button\n #fileInputButton\n mat-stroked-button\n class=\"td-file-input\"\n type=\"button\"\n [color]=\"color\"\n [multiple]=\"multiple\"\n [disabled]=\"disabled\"\n (fileDrop)=\"handleSelect($event)\"\n tdFileDrop\n>\n <ng-content></ng-content>\n</button>\n<input\n #fileInput\n class=\"td-file-input-hidden\"\n type=\"file\"\n [attr.accept]=\"accept\"\n (fileSelect)=\"handleSelect($event)\"\n [multiple]=\"multiple\"\n [disabled]=\"disabled\"\n tdFileSelect\n/>\n", styles: [":host .td-file-input{padding-left:8px;padding-right:8px}:host input.td-file-input-hidden{display:none}:host ::ng-deep .mdc-button__label{display:flex;align-items:center}:host .drop-zone{border-radius:3px}:host .drop-zone *{pointer-events:none}\n"] }]
|
353 | }], ctorParameters: () => [{ type: i0.NgZone }, { type: i0.Renderer2 }, { type: i0.ChangeDetectorRef }], propDecorators: { _inputButton: [{
|
354 | type: ViewChild,
|
355 | args: ['fileInputButton', { static: true, read: ElementRef }]
|
356 | }], _inputElement: [{
|
357 | type: ViewChild,
|
358 | args: ['fileInput', { static: true }]
|
359 | }], color: [{
|
360 | type: Input
|
361 | }], multiple: [{
|
362 | type: Input
|
363 | }], accept: [{
|
364 | type: Input
|
365 | }], selectFile: [{
|
366 | type: Output
|
367 | }] } });
|
368 |
|
369 | class TdFileUploadBase {
|
370 | _changeDetectorRef;
|
371 | constructor(_changeDetectorRef) {
|
372 | this._changeDetectorRef = _changeDetectorRef;
|
373 | }
|
374 | }
|
375 | class TdFileUploadComponent {
|
376 | _changeDetectorRef;
|
377 | _multiple = false;
|
378 | _required = false;
|
379 | _disabled = false;
|
380 | fileInput;
|
381 | inputLabel;
|
382 | |
383 |
|
384 |
|
385 |
|
386 | defaultColor = 'primary';
|
387 | |
388 |
|
389 |
|
390 |
|
391 | activeColor = 'accent';
|
392 | |
393 |
|
394 |
|
395 |
|
396 | cancelColor = 'warn';
|
397 | |
398 |
|
399 |
|
400 |
|
401 | set multiple(multiple) {
|
402 | this._multiple = coerceBooleanProperty(multiple);
|
403 | }
|
404 | get multiple() {
|
405 | return this._multiple;
|
406 | }
|
407 | |
408 |
|
409 |
|
410 |
|
411 |
|
412 | set required(required) {
|
413 | this._required = coerceBooleanProperty(required);
|
414 | }
|
415 | get required() {
|
416 | return this._required;
|
417 | }
|
418 | |
419 |
|
420 |
|
421 |
|
422 |
|
423 | accept;
|
424 | set disabled(disabled) {
|
425 | this._disabled = disabled;
|
426 | this.onDisabledChange(disabled);
|
427 | }
|
428 | get disabled() {
|
429 | return this._disabled;
|
430 | }
|
431 | value;
|
432 | |
433 |
|
434 |
|
435 |
|
436 |
|
437 | selectFile = new EventEmitter();
|
438 | |
439 |
|
440 |
|
441 |
|
442 |
|
443 | upload = new EventEmitter();
|
444 | |
445 |
|
446 |
|
447 |
|
448 | cancel = new EventEmitter();
|
449 | constructor(_changeDetectorRef) {
|
450 | this._changeDetectorRef = _changeDetectorRef;
|
451 | }
|
452 | writeValue(value) {
|
453 | this.value = value;
|
454 | this._changeDetectorRef.markForCheck();
|
455 | }
|
456 | registerOnChange() {
|
457 |
|
458 | }
|
459 | registerOnTouched() {
|
460 |
|
461 | }
|
462 | |
463 |
|
464 |
|
465 | uploadPressed() {
|
466 | if (this.value) {
|
467 | this.upload.emit(this.value);
|
468 | }
|
469 | }
|
470 | |
471 |
|
472 |
|
473 | handleSelect(value) {
|
474 | this.value = value;
|
475 | this.selectFile.emit(value);
|
476 | }
|
477 | |
478 |
|
479 |
|
480 |
|
481 | _cancel() {
|
482 | this.value = undefined;
|
483 | this.cancel.emit();
|
484 |
|
485 | if (this.fileInput) {
|
486 | this.fileInput.clear();
|
487 | }
|
488 | }
|
489 |
|
490 | onDisabledChange(v) {
|
491 | if (v) {
|
492 | this._cancel();
|
493 | }
|
494 | }
|
495 | static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.1.2", ngImport: i0, type: TdFileUploadComponent, deps: [{ token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Component });
|
496 | static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "17.1.2", type: TdFileUploadComponent, selector: "td-file-upload", inputs: { defaultColor: "defaultColor", activeColor: "activeColor", cancelColor: "cancelColor", multiple: "multiple", required: "required", accept: "accept", disabled: "disabled", value: "value" }, outputs: { selectFile: "selectFile", upload: "upload", cancel: "cancel" }, providers: [
|
497 | {
|
498 | provide: NG_VALUE_ACCESSOR,
|
499 | useExisting: forwardRef(() => TdFileUploadComponent),
|
500 | multi: true,
|
501 | },
|
502 | ], queries: [{ propertyName: "inputLabel", first: true, predicate: TdFileInputLabelDirective, descendants: true }], viewQueries: [{ propertyName: "fileInput", first: true, predicate: TdFileInputComponent, descendants: true }], ngImport: i0, template: "<td-file-input\n *ngIf=\"!value\"\n [(ngModel)]=\"value\"\n [multiple]=\"multiple\"\n [disabled]=\"disabled\"\n [accept]=\"accept\"\n [color]=\"defaultColor\"\n (selectFile)=\"(handleSelect)\"\n>\n <ng-template [cdkPortalOutlet]=\"inputLabel\" [ngIf]=\"true\"></ng-template>\n</td-file-input>\n<div *ngIf=\"value\">\n <button\n #fileUpload\n class=\"td-file-upload\"\n mat-raised-button\n type=\"button\"\n [color]=\"activeColor\"\n (keyup.delete)=\"_cancel()\"\n (keyup.backspace)=\"_cancel()\"\n (keyup.escape)=\"_cancel()\"\n (click)=\"uploadPressed()\"\n >\n <ng-content></ng-content>\n </button>\n <button\n mat-icon-button\n type=\"button\"\n class=\"td-file-upload-cancel\"\n [color]=\"cancelColor\"\n (click)=\"_cancel()\"\n >\n <mat-icon>cancel</mat-icon>\n </button>\n</div>\n", styles: [".td-file-upload{padding-left:8px;padding-right:8px}.td-file-upload-cancel{height:24px;width:24px;position:relative;top:24px;left:-12px}::ng-deep [dir=rtl] .td-file-upload-cancel{right:-12px;left:0}.td-file-upload-cancel mat-icon{border-radius:12px;vertical-align:baseline}.drop-zone{border-radius:3px}.drop-zone *{pointer-events:none}\n"], dependencies: [{ kind: "directive", type: i1.NgControlStatus, selector: "[formControlName],[ngModel],[formControl]" }, { kind: "directive", type: i1.NgModel, selector: "[ngModel]:not([formControlName]):not([formControl])", inputs: ["name", "disabled", "ngModel", "ngModelOptions"], outputs: ["ngModelChange"], exportAs: ["ngModel"] }, { kind: "directive", type: i2.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "component", type: i3.MatIcon, selector: "mat-icon", inputs: ["color", "inline", "svgIcon", "fontSet", "fontIcon"], exportAs: ["matIcon"] }, { kind: "component", type: i4.MatButton, selector: " button[mat-button], button[mat-raised-button], button[mat-flat-button], button[mat-stroked-button] ", exportAs: ["matButton"] }, { kind: "component", type: i4.MatIconButton, selector: "button[mat-icon-button]", exportAs: ["matButton"] }, { kind: "directive", type: i5.CdkPortalOutlet, selector: "[cdkPortalOutlet]", inputs: ["cdkPortalOutlet"], outputs: ["attached"], exportAs: ["cdkPortalOutlet"] }, { kind: "component", type: TdFileInputComponent, selector: "td-file-input", inputs: ["disabled", "value", "color", "multiple", "accept"], outputs: ["selectFile"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
|
503 | }
|
504 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.1.2", ngImport: i0, type: TdFileUploadComponent, decorators: [{
|
505 | type: Component,
|
506 | args: [{ changeDetection: ChangeDetectionStrategy.OnPush, providers: [
|
507 | {
|
508 | provide: NG_VALUE_ACCESSOR,
|
509 | useExisting: forwardRef(() => TdFileUploadComponent),
|
510 | multi: true,
|
511 | },
|
512 | ], selector: 'td-file-upload', template: "<td-file-input\n *ngIf=\"!value\"\n [(ngModel)]=\"value\"\n [multiple]=\"multiple\"\n [disabled]=\"disabled\"\n [accept]=\"accept\"\n [color]=\"defaultColor\"\n (selectFile)=\"(handleSelect)\"\n>\n <ng-template [cdkPortalOutlet]=\"inputLabel\" [ngIf]=\"true\"></ng-template>\n</td-file-input>\n<div *ngIf=\"value\">\n <button\n #fileUpload\n class=\"td-file-upload\"\n mat-raised-button\n type=\"button\"\n [color]=\"activeColor\"\n (keyup.delete)=\"_cancel()\"\n (keyup.backspace)=\"_cancel()\"\n (keyup.escape)=\"_cancel()\"\n (click)=\"uploadPressed()\"\n >\n <ng-content></ng-content>\n </button>\n <button\n mat-icon-button\n type=\"button\"\n class=\"td-file-upload-cancel\"\n [color]=\"cancelColor\"\n (click)=\"_cancel()\"\n >\n <mat-icon>cancel</mat-icon>\n </button>\n</div>\n", styles: [".td-file-upload{padding-left:8px;padding-right:8px}.td-file-upload-cancel{height:24px;width:24px;position:relative;top:24px;left:-12px}::ng-deep [dir=rtl] .td-file-upload-cancel{right:-12px;left:0}.td-file-upload-cancel mat-icon{border-radius:12px;vertical-align:baseline}.drop-zone{border-radius:3px}.drop-zone *{pointer-events:none}\n"] }]
|
513 | }], ctorParameters: () => [{ type: i0.ChangeDetectorRef }], propDecorators: { fileInput: [{
|
514 | type: ViewChild,
|
515 | args: [TdFileInputComponent]
|
516 | }], inputLabel: [{
|
517 | type: ContentChild,
|
518 | args: [TdFileInputLabelDirective]
|
519 | }], defaultColor: [{
|
520 | type: Input
|
521 | }], activeColor: [{
|
522 | type: Input
|
523 | }], cancelColor: [{
|
524 | type: Input
|
525 | }], multiple: [{
|
526 | type: Input
|
527 | }], required: [{
|
528 | type: Input
|
529 | }], accept: [{
|
530 | type: Input
|
531 | }], disabled: [{
|
532 | type: Input
|
533 | }], value: [{
|
534 | type: Input
|
535 | }], selectFile: [{
|
536 | type: Output
|
537 | }], upload: [{
|
538 | type: Output
|
539 | }], cancel: [{
|
540 | type: Output
|
541 | }] } });
|
542 |
|
543 | class TdFileService {
|
544 | _http;
|
545 | _progressSubject = new Subject();
|
546 | _progressObservable;
|
547 | |
548 |
|
549 |
|
550 |
|
551 | get progress() {
|
552 | return this._progressObservable;
|
553 | }
|
554 | |
555 |
|
556 |
|
557 |
|
558 |
|
559 | constructor(_http) {
|
560 | this._http = _http;
|
561 | this._progressObservable = this._progressSubject.asObservable();
|
562 | }
|
563 | |
564 |
|
565 |
|
566 | send(url, method, body, { headers, params } = {}) {
|
567 | if (!this._http) {
|
568 | throw new Error('The HttpClient module needs to be imported at root module level');
|
569 | }
|
570 | const req = new HttpRequest(method.toUpperCase(), url, body, {
|
571 | reportProgress: true,
|
572 | headers: new HttpHeaders(headers || {}),
|
573 | params: new HttpParams({ fromObject: params || {} }),
|
574 | });
|
575 | return this._http
|
576 | .request(req)
|
577 | .pipe(tap((event) => this.handleEvent(event)));
|
578 | }
|
579 | handleEvent(event) {
|
580 | switch (event.type) {
|
581 | case HttpEventType.Sent:
|
582 | this._progressSubject.next(0);
|
583 | break;
|
584 | case HttpEventType.UploadProgress:
|
585 | this._progressSubject.next(Math.round((100 * event.loaded) / (event.total ?? 0)));
|
586 | break;
|
587 | case HttpEventType.Response:
|
588 | this._progressSubject.next(100);
|
589 | break;
|
590 | default:
|
591 | break;
|
592 | }
|
593 | }
|
594 | static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.1.2", ngImport: i0, type: TdFileService, deps: [{ token: i1$1.HttpClient, optional: true }], target: i0.ɵɵFactoryTarget.Injectable });
|
595 | static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "17.1.2", ngImport: i0, type: TdFileService });
|
596 | }
|
597 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.1.2", ngImport: i0, type: TdFileService, decorators: [{
|
598 | type: Injectable
|
599 | }], ctorParameters: () => [{ type: i1$1.HttpClient, decorators: [{
|
600 | type: Optional
|
601 | }] }] });
|
602 |
|
603 | const TD_FILE = [
|
604 | TdFileSelectDirective,
|
605 | TdFileDropDirective,
|
606 | TdFileUploadComponent,
|
607 | TdFileInputComponent,
|
608 | TdFileInputLabelDirective,
|
609 | ];
|
610 | class CovalentFileModule {
|
611 | static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.1.2", ngImport: i0, type: CovalentFileModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
612 | static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "17.1.2", ngImport: i0, type: CovalentFileModule, declarations: [TdFileSelectDirective,
|
613 | TdFileDropDirective,
|
614 | TdFileUploadComponent,
|
615 | TdFileInputComponent,
|
616 | TdFileInputLabelDirective], imports: [FormsModule,
|
617 | CommonModule,
|
618 | MatIconModule,
|
619 | MatButtonModule,
|
620 | PortalModule], exports: [TdFileSelectDirective,
|
621 | TdFileDropDirective,
|
622 | TdFileUploadComponent,
|
623 | TdFileInputComponent,
|
624 | TdFileInputLabelDirective] });
|
625 | static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "17.1.2", ngImport: i0, type: CovalentFileModule, providers: [TdFileService], imports: [FormsModule,
|
626 | CommonModule,
|
627 | MatIconModule,
|
628 | MatButtonModule,
|
629 | PortalModule] });
|
630 | }
|
631 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.1.2", ngImport: i0, type: CovalentFileModule, decorators: [{
|
632 | type: NgModule,
|
633 | args: [{
|
634 | imports: [
|
635 | FormsModule,
|
636 | CommonModule,
|
637 | MatIconModule,
|
638 | MatButtonModule,
|
639 | PortalModule,
|
640 | ],
|
641 | declarations: [TD_FILE],
|
642 | exports: [TD_FILE],
|
643 | providers: [TdFileService],
|
644 | }]
|
645 | }] });
|
646 |
|
647 |
|
648 |
|
649 |
|
650 |
|
651 | export { CovalentFileModule, TdFileDropBase, TdFileDropDirective, TdFileInputBase, TdFileInputComponent, TdFileInputLabelDirective, TdFileSelectDirective, TdFileService, TdFileUploadBase, TdFileUploadComponent, _TdFileInputMixinBase };
|
652 |
|