[59329aa] | 1 | import * as i0 from '@angular/core';
|
---|
| 2 | import { EventEmitter, Directive, Optional, Input, Output, HostListener, NgModule } from '@angular/core';
|
---|
| 3 | import { CommonModule } from '@angular/common';
|
---|
| 4 | import * as i1 from '@angular/forms';
|
---|
| 5 |
|
---|
| 6 | class InputTextarea {
|
---|
| 7 | constructor(el, ngModel, control, cd) {
|
---|
| 8 | this.el = el;
|
---|
| 9 | this.ngModel = ngModel;
|
---|
| 10 | this.control = control;
|
---|
| 11 | this.cd = cd;
|
---|
| 12 | this.onResize = new EventEmitter();
|
---|
| 13 | }
|
---|
| 14 | ngOnInit() {
|
---|
| 15 | if (this.ngModel) {
|
---|
| 16 | this.ngModelSubscription = this.ngModel.valueChanges.subscribe(() => {
|
---|
| 17 | this.updateState();
|
---|
| 18 | });
|
---|
| 19 | }
|
---|
| 20 | if (this.control) {
|
---|
| 21 | this.ngControlSubscription = this.control.valueChanges.subscribe(() => {
|
---|
| 22 | this.updateState();
|
---|
| 23 | });
|
---|
| 24 | }
|
---|
| 25 | }
|
---|
| 26 | ngAfterViewInit() {
|
---|
| 27 | if (this.autoResize)
|
---|
| 28 | this.resize();
|
---|
| 29 | this.updateFilledState();
|
---|
| 30 | this.cd.detectChanges();
|
---|
| 31 | }
|
---|
| 32 | onInput(e) {
|
---|
| 33 | this.updateState();
|
---|
| 34 | }
|
---|
| 35 | updateFilledState() {
|
---|
| 36 | this.filled = this.el.nativeElement.value && this.el.nativeElement.value.length;
|
---|
| 37 | }
|
---|
| 38 | onFocus(e) {
|
---|
| 39 | if (this.autoResize) {
|
---|
| 40 | this.resize(e);
|
---|
| 41 | }
|
---|
| 42 | }
|
---|
| 43 | onBlur(e) {
|
---|
| 44 | if (this.autoResize) {
|
---|
| 45 | this.resize(e);
|
---|
| 46 | }
|
---|
| 47 | }
|
---|
| 48 | resize(event) {
|
---|
| 49 | this.el.nativeElement.style.height = 'auto';
|
---|
| 50 | this.el.nativeElement.style.height = this.el.nativeElement.scrollHeight + 'px';
|
---|
| 51 | if (parseFloat(this.el.nativeElement.style.height) >= parseFloat(this.el.nativeElement.style.maxHeight)) {
|
---|
| 52 | this.el.nativeElement.style.overflowY = "scroll";
|
---|
| 53 | this.el.nativeElement.style.height = this.el.nativeElement.style.maxHeight;
|
---|
| 54 | }
|
---|
| 55 | else {
|
---|
| 56 | this.el.nativeElement.style.overflow = "hidden";
|
---|
| 57 | }
|
---|
| 58 | this.onResize.emit(event || {});
|
---|
| 59 | }
|
---|
| 60 | updateState() {
|
---|
| 61 | this.updateFilledState();
|
---|
| 62 | if (this.autoResize) {
|
---|
| 63 | this.resize();
|
---|
| 64 | }
|
---|
| 65 | }
|
---|
| 66 | ngOnDestroy() {
|
---|
| 67 | if (this.ngModelSubscription) {
|
---|
| 68 | this.ngModelSubscription.unsubscribe();
|
---|
| 69 | }
|
---|
| 70 | if (this.ngControlSubscription) {
|
---|
| 71 | this.ngControlSubscription.unsubscribe();
|
---|
| 72 | }
|
---|
| 73 | }
|
---|
| 74 | }
|
---|
| 75 | InputTextarea.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: InputTextarea, deps: [{ token: i0.ElementRef }, { token: i1.NgModel, optional: true }, { token: i1.NgControl, optional: true }, { token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Directive });
|
---|
| 76 | InputTextarea.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.0.0", type: InputTextarea, selector: "[pInputTextarea]", inputs: { autoResize: "autoResize" }, outputs: { onResize: "onResize" }, host: { listeners: { "input": "onInput($event)", "focus": "onFocus($event)", "blur": "onBlur($event)" }, properties: { "class.p-filled": "filled", "class.p-inputtextarea-resizable": "autoResize" }, classAttribute: "p-inputtextarea p-inputtext p-component p-element" }, ngImport: i0 });
|
---|
| 77 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: InputTextarea, decorators: [{
|
---|
| 78 | type: Directive,
|
---|
| 79 | args: [{
|
---|
| 80 | selector: '[pInputTextarea]',
|
---|
| 81 | host: {
|
---|
| 82 | 'class': 'p-inputtextarea p-inputtext p-component p-element',
|
---|
| 83 | '[class.p-filled]': 'filled',
|
---|
| 84 | '[class.p-inputtextarea-resizable]': 'autoResize'
|
---|
| 85 | }
|
---|
| 86 | }]
|
---|
| 87 | }], ctorParameters: function () {
|
---|
| 88 | return [{ type: i0.ElementRef }, { type: i1.NgModel, decorators: [{
|
---|
| 89 | type: Optional
|
---|
| 90 | }] }, { type: i1.NgControl, decorators: [{
|
---|
| 91 | type: Optional
|
---|
| 92 | }] }, { type: i0.ChangeDetectorRef }];
|
---|
| 93 | }, propDecorators: { autoResize: [{
|
---|
| 94 | type: Input
|
---|
| 95 | }], onResize: [{
|
---|
| 96 | type: Output
|
---|
| 97 | }], onInput: [{
|
---|
| 98 | type: HostListener,
|
---|
| 99 | args: ['input', ['$event']]
|
---|
| 100 | }], onFocus: [{
|
---|
| 101 | type: HostListener,
|
---|
| 102 | args: ['focus', ['$event']]
|
---|
| 103 | }], onBlur: [{
|
---|
| 104 | type: HostListener,
|
---|
| 105 | args: ['blur', ['$event']]
|
---|
| 106 | }] } });
|
---|
| 107 | class InputTextareaModule {
|
---|
| 108 | }
|
---|
| 109 | InputTextareaModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: InputTextareaModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
---|
| 110 | InputTextareaModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: InputTextareaModule, declarations: [InputTextarea], imports: [CommonModule], exports: [InputTextarea] });
|
---|
| 111 | InputTextareaModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: InputTextareaModule, imports: [[CommonModule]] });
|
---|
| 112 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: InputTextareaModule, decorators: [{
|
---|
| 113 | type: NgModule,
|
---|
| 114 | args: [{
|
---|
| 115 | imports: [CommonModule],
|
---|
| 116 | exports: [InputTextarea],
|
---|
| 117 | declarations: [InputTextarea]
|
---|
| 118 | }]
|
---|
| 119 | }] });
|
---|
| 120 |
|
---|
| 121 | /**
|
---|
| 122 | * Generated bundle index. Do not edit.
|
---|
| 123 | */
|
---|
| 124 |
|
---|
| 125 | export { InputTextarea, InputTextareaModule };
|
---|