[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 () { return [{ type: i0.ElementRef }, { type: i1.NgModel, decorators: [{
|
---|
| 88 | type: Optional
|
---|
| 89 | }] }, { type: i1.NgControl, decorators: [{
|
---|
| 90 | type: Optional
|
---|
| 91 | }] }, { type: i0.ChangeDetectorRef }]; }, propDecorators: { autoResize: [{
|
---|
| 92 | type: Input
|
---|
| 93 | }], onResize: [{
|
---|
| 94 | type: Output
|
---|
| 95 | }], onInput: [{
|
---|
| 96 | type: HostListener,
|
---|
| 97 | args: ['input', ['$event']]
|
---|
| 98 | }], onFocus: [{
|
---|
| 99 | type: HostListener,
|
---|
| 100 | args: ['focus', ['$event']]
|
---|
| 101 | }], onBlur: [{
|
---|
| 102 | type: HostListener,
|
---|
| 103 | args: ['blur', ['$event']]
|
---|
| 104 | }] } });
|
---|
| 105 | class InputTextareaModule {
|
---|
| 106 | }
|
---|
| 107 | InputTextareaModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: InputTextareaModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
---|
| 108 | InputTextareaModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: InputTextareaModule, declarations: [InputTextarea], imports: [CommonModule], exports: [InputTextarea] });
|
---|
| 109 | InputTextareaModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: InputTextareaModule, imports: [[CommonModule]] });
|
---|
| 110 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: InputTextareaModule, decorators: [{
|
---|
| 111 | type: NgModule,
|
---|
| 112 | args: [{
|
---|
| 113 | imports: [CommonModule],
|
---|
| 114 | exports: [InputTextarea],
|
---|
| 115 | declarations: [InputTextarea]
|
---|
| 116 | }]
|
---|
| 117 | }] });
|
---|
| 118 |
|
---|
| 119 | /**
|
---|
| 120 | * Generated bundle index. Do not edit.
|
---|
| 121 | */
|
---|
| 122 |
|
---|
| 123 | export { InputTextarea, InputTextareaModule };
|
---|