UNPKG

7.49 kBTypeScriptView Raw
1import { AfterViewInit } from '@angular/core';
2import { BooleanInput } from '@angular/cdk/coercion';
3import { DoCheck } from '@angular/core';
4import { ElementRef } from '@angular/core';
5import { EventEmitter } from '@angular/core';
6import * as i0 from '@angular/core';
7import { NgZone } from '@angular/core';
8import { NumberInput } from '@angular/cdk/coercion';
9import { Observable } from 'rxjs';
10import { OnDestroy } from '@angular/core';
11import { OnInit } from '@angular/core';
12import { Platform } from '@angular/cdk/platform';
13
14/** An event that is emitted when the autofill state of an input changes. */
15export declare type AutofillEvent = {
16 /** The element whose autofill state changes. */
17 target: Element;
18 /** Whether the element is currently autofilled. */
19 isAutofilled: boolean;
20};
21
22/**
23 * An injectable service that can be used to monitor the autofill state of an input.
24 * Based on the following blog post:
25 * https://medium.com/@brunn/detecting-autofilled-fields-in-javascript-aed598d25da7
26 */
27export declare class AutofillMonitor implements OnDestroy {
28 private _platform;
29 private _ngZone;
30 private _monitoredElements;
31 constructor(_platform: Platform, _ngZone: NgZone);
32 /**
33 * Monitor for changes in the autofill state of the given input element.
34 * @param element The element to monitor.
35 * @return A stream of autofill state changes.
36 */
37 monitor(element: Element): Observable<AutofillEvent>;
38 /**
39 * Monitor for changes in the autofill state of the given input element.
40 * @param element The element to monitor.
41 * @return A stream of autofill state changes.
42 */
43 monitor(element: ElementRef<Element>): Observable<AutofillEvent>;
44 /**
45 * Stop monitoring the autofill state of the given input element.
46 * @param element The element to stop monitoring.
47 */
48 stopMonitoring(element: Element): void;
49 /**
50 * Stop monitoring the autofill state of the given input element.
51 * @param element The element to stop monitoring.
52 */
53 stopMonitoring(element: ElementRef<Element>): void;
54 ngOnDestroy(): void;
55 static ɵfac: i0.ɵɵFactoryDeclaration<AutofillMonitor, never>;
56 static ɵprov: i0.ɵɵInjectableDeclaration<AutofillMonitor>;
57}
58
59/** A directive that can be used to monitor the autofill state of an input. */
60export declare class CdkAutofill implements OnDestroy, OnInit {
61 private _elementRef;
62 private _autofillMonitor;
63 /** Emits when the autofill state of the element changes. */
64 readonly cdkAutofill: EventEmitter<AutofillEvent>;
65 constructor(_elementRef: ElementRef<HTMLElement>, _autofillMonitor: AutofillMonitor);
66 ngOnInit(): void;
67 ngOnDestroy(): void;
68 static ɵfac: i0.ɵɵFactoryDeclaration<CdkAutofill, never>;
69 static ɵdir: i0.ɵɵDirectiveDeclaration<CdkAutofill, "[cdkAutofill]", never, {}, { "cdkAutofill": "cdkAutofill"; }, never, never, false, never>;
70}
71
72/** Directive to automatically resize a textarea to fit its content. */
73export declare class CdkTextareaAutosize implements AfterViewInit, DoCheck, OnDestroy {
74 private _elementRef;
75 private _platform;
76 private _ngZone;
77 /** Keep track of the previous textarea value to avoid resizing when the value hasn't changed. */
78 private _previousValue?;
79 private _initialHeight;
80 private readonly _destroyed;
81 private _minRows;
82 private _maxRows;
83 private _enabled;
84 /**
85 * Value of minRows as of last resize. If the minRows has decreased, the
86 * height of the textarea needs to be recomputed to reflect the new minimum. The maxHeight
87 * does not have the same problem because it does not affect the textarea's scrollHeight.
88 */
89 private _previousMinRows;
90 private _textareaElement;
91 /** Minimum amount of rows in the textarea. */
92 get minRows(): number;
93 set minRows(value: NumberInput);
94 /** Maximum amount of rows in the textarea. */
95 get maxRows(): number;
96 set maxRows(value: NumberInput);
97 /** Whether autosizing is enabled or not */
98 get enabled(): boolean;
99 set enabled(value: BooleanInput);
100 get placeholder(): string;
101 set placeholder(value: string);
102 /** Cached height of a textarea with a single row. */
103 private _cachedLineHeight;
104 /** Cached height of a textarea with only the placeholder. */
105 private _cachedPlaceholderHeight?;
106 /** Used to reference correct document/window */
107 protected _document?: Document;
108 private _hasFocus;
109 private _isViewInited;
110 constructor(_elementRef: ElementRef<HTMLElement>, _platform: Platform, _ngZone: NgZone,
111 /** @breaking-change 11.0.0 make document required */
112 document?: any);
113 /** Sets the minimum height of the textarea as determined by minRows. */
114 _setMinHeight(): void;
115 /** Sets the maximum height of the textarea as determined by maxRows. */
116 _setMaxHeight(): void;
117 ngAfterViewInit(): void;
118 ngOnDestroy(): void;
119 /**
120 * Cache the height of a single-row textarea if it has not already been cached.
121 *
122 * We need to know how large a single "row" of a textarea is in order to apply minRows and
123 * maxRows. For the initial version, we will assume that the height of a single line in the
124 * textarea does not ever change.
125 */
126 private _cacheTextareaLineHeight;
127 private _measureScrollHeight;
128 private _cacheTextareaPlaceholderHeight;
129 /** Handles `focus` and `blur` events. */
130 private _handleFocusEvent;
131 ngDoCheck(): void;
132 /**
133 * Resize the textarea to fit its content.
134 * @param force Whether to force a height recalculation. By default the height will be
135 * recalculated only if the value changed since the last call.
136 */
137 resizeToFitContent(force?: boolean): void;
138 /**
139 * Resets the textarea to its original size
140 */
141 reset(): void;
142 _noopInputHandler(): void;
143 /** Access injected document if available or fallback to global document reference */
144 private _getDocument;
145 /** Use defaultView of injected document if available or fallback to global window reference */
146 private _getWindow;
147 /**
148 * Scrolls a textarea to the caret position. On Firefox resizing the textarea will
149 * prevent it from scrolling to the caret position. We need to re-set the selection
150 * in order for it to scroll to the proper position.
151 */
152 private _scrollToCaretPosition;
153 static ɵfac: i0.ɵɵFactoryDeclaration<CdkTextareaAutosize, [null, null, null, { optional: true; }]>;
154 static ɵdir: i0.ɵɵDirectiveDeclaration<CdkTextareaAutosize, "textarea[cdkTextareaAutosize]", ["cdkTextareaAutosize"], { "minRows": { "alias": "cdkAutosizeMinRows"; "required": false; }; "maxRows": { "alias": "cdkAutosizeMaxRows"; "required": false; }; "enabled": { "alias": "cdkTextareaAutosize"; "required": false; }; "placeholder": { "alias": "placeholder"; "required": false; }; }, {}, never, never, false, never>;
155}
156
157declare namespace i1 {
158 export {
159 AutofillEvent,
160 AutofillMonitor,
161 CdkAutofill
162 }
163}
164
165declare namespace i2 {
166 export {
167 CdkTextareaAutosize
168 }
169}
170
171export declare class TextFieldModule {
172 static ɵfac: i0.ɵɵFactoryDeclaration<TextFieldModule, never>;
173 static ɵmod: i0.ɵɵNgModuleDeclaration<TextFieldModule, [typeof i1.CdkAutofill, typeof i2.CdkTextareaAutosize], never, [typeof i1.CdkAutofill, typeof i2.CdkTextareaAutosize]>;
174 static ɵinj: i0.ɵɵInjectorDeclaration<TextFieldModule>;
175}
176
177export { }