source: trip-planner-front/node_modules/@angular/cdk/__ivy_ngcc__/fesm2015/text-field.js@ 6a3a178

Last change on this file since 6a3a178 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 22.2 KB
RevLine 
[6a3a178]1import * as i1 from '@angular/cdk/platform';
2import { normalizePassiveListenerOptions, Platform, PlatformModule } from '@angular/cdk/platform';
3import * as i0 from '@angular/core';
4import { Injectable, NgZone, EventEmitter, Directive, ElementRef, Output, Optional, Inject, Input, HostListener, NgModule } from '@angular/core';
5import { coerceElement, coerceNumberProperty, coerceBooleanProperty } from '@angular/cdk/coercion';
6import { EMPTY, Subject, fromEvent } from 'rxjs';
7import { auditTime, takeUntil } from 'rxjs/operators';
8import { DOCUMENT } from '@angular/common';
9
10/**
11 * @license
12 * Copyright Google LLC All Rights Reserved.
13 *
14 * Use of this source code is governed by an MIT-style license that can be
15 * found in the LICENSE file at https://angular.io/license
16 */
17/** Options to pass to the animationstart listener. */
18import * as ɵngcc0 from '@angular/core';
19import * as ɵngcc1 from '@angular/cdk/platform';
20const listenerOptions = normalizePassiveListenerOptions({ passive: true });
21/**
22 * An injectable service that can be used to monitor the autofill state of an input.
23 * Based on the following blog post:
24 * https://medium.com/@brunn/detecting-autofilled-fields-in-javascript-aed598d25da7
25 */
26class AutofillMonitor {
27 constructor(_platform, _ngZone) {
28 this._platform = _platform;
29 this._ngZone = _ngZone;
30 this._monitoredElements = new Map();
31 }
32 monitor(elementOrRef) {
33 if (!this._platform.isBrowser) {
34 return EMPTY;
35 }
36 const element = coerceElement(elementOrRef);
37 const info = this._monitoredElements.get(element);
38 if (info) {
39 return info.subject;
40 }
41 const result = new Subject();
42 const cssClass = 'cdk-text-field-autofilled';
43 const listener = ((event) => {
44 // Animation events fire on initial element render, we check for the presence of the autofill
45 // CSS class to make sure this is a real change in state, not just the initial render before
46 // we fire off events.
47 if (event.animationName === 'cdk-text-field-autofill-start' &&
48 !element.classList.contains(cssClass)) {
49 element.classList.add(cssClass);
50 this._ngZone.run(() => result.next({ target: event.target, isAutofilled: true }));
51 }
52 else if (event.animationName === 'cdk-text-field-autofill-end' &&
53 element.classList.contains(cssClass)) {
54 element.classList.remove(cssClass);
55 this._ngZone.run(() => result.next({ target: event.target, isAutofilled: false }));
56 }
57 });
58 this._ngZone.runOutsideAngular(() => {
59 element.addEventListener('animationstart', listener, listenerOptions);
60 element.classList.add('cdk-text-field-autofill-monitored');
61 });
62 this._monitoredElements.set(element, {
63 subject: result,
64 unlisten: () => {
65 element.removeEventListener('animationstart', listener, listenerOptions);
66 }
67 });
68 return result;
69 }
70 stopMonitoring(elementOrRef) {
71 const element = coerceElement(elementOrRef);
72 const info = this._monitoredElements.get(element);
73 if (info) {
74 info.unlisten();
75 info.subject.complete();
76 element.classList.remove('cdk-text-field-autofill-monitored');
77 element.classList.remove('cdk-text-field-autofilled');
78 this._monitoredElements.delete(element);
79 }
80 }
81 ngOnDestroy() {
82 this._monitoredElements.forEach((_info, element) => this.stopMonitoring(element));
83 }
84}
85AutofillMonitor.ɵfac = function AutofillMonitor_Factory(t) { return new (t || AutofillMonitor)(ɵngcc0.ɵɵinject(ɵngcc1.Platform), ɵngcc0.ɵɵinject(ɵngcc0.NgZone)); };
86AutofillMonitor.ɵprov = i0.ɵɵdefineInjectable({ factory: function AutofillMonitor_Factory() { return new AutofillMonitor(i0.ɵɵinject(i1.Platform), i0.ɵɵinject(i0.NgZone)); }, token: AutofillMonitor, providedIn: "root" });
87AutofillMonitor.ctorParameters = () => [
88 { type: Platform },
89 { type: NgZone }
90];
91(function () { (typeof ngDevMode === "undefined" || ngDevMode) && ɵngcc0.ɵsetClassMetadata(AutofillMonitor, [{
92 type: Injectable,
93 args: [{ providedIn: 'root' }]
94 }], function () { return [{ type: ɵngcc1.Platform }, { type: ɵngcc0.NgZone }]; }, null); })();
95/** A directive that can be used to monitor the autofill state of an input. */
96class CdkAutofill {
97 constructor(_elementRef, _autofillMonitor) {
98 this._elementRef = _elementRef;
99 this._autofillMonitor = _autofillMonitor;
100 /** Emits when the autofill state of the element changes. */
101 this.cdkAutofill = new EventEmitter();
102 }
103 ngOnInit() {
104 this._autofillMonitor
105 .monitor(this._elementRef)
106 .subscribe(event => this.cdkAutofill.emit(event));
107 }
108 ngOnDestroy() {
109 this._autofillMonitor.stopMonitoring(this._elementRef);
110 }
111}
112CdkAutofill.ɵfac = function CdkAutofill_Factory(t) { return new (t || CdkAutofill)(ɵngcc0.ɵɵdirectiveInject(ɵngcc0.ElementRef), ɵngcc0.ɵɵdirectiveInject(AutofillMonitor)); };
113CdkAutofill.ɵdir = /*@__PURE__*/ ɵngcc0.ɵɵdefineDirective({ type: CdkAutofill, selectors: [["", "cdkAutofill", ""]], outputs: { cdkAutofill: "cdkAutofill" } });
114CdkAutofill.ctorParameters = () => [
115 { type: ElementRef },
116 { type: AutofillMonitor }
117];
118CdkAutofill.propDecorators = {
119 cdkAutofill: [{ type: Output }]
120};
121(function () { (typeof ngDevMode === "undefined" || ngDevMode) && ɵngcc0.ɵsetClassMetadata(CdkAutofill, [{
122 type: Directive,
123 args: [{
124 selector: '[cdkAutofill]'
125 }]
126 }], function () { return [{ type: ɵngcc0.ElementRef }, { type: AutofillMonitor }]; }, { cdkAutofill: [{
127 type: Output
128 }] }); })();
129
130/**
131 * @license
132 * Copyright Google LLC All Rights Reserved.
133 *
134 * Use of this source code is governed by an MIT-style license that can be
135 * found in the LICENSE file at https://angular.io/license
136 */
137/** Directive to automatically resize a textarea to fit its content. */
138class CdkTextareaAutosize {
139 constructor(_elementRef, _platform, _ngZone,
140 /** @breaking-change 11.0.0 make document required */
141 document) {
142 this._elementRef = _elementRef;
143 this._platform = _platform;
144 this._ngZone = _ngZone;
145 this._destroyed = new Subject();
146 this._enabled = true;
147 /**
148 * Value of minRows as of last resize. If the minRows has decreased, the
149 * height of the textarea needs to be recomputed to reflect the new minimum. The maxHeight
150 * does not have the same problem because it does not affect the textarea's scrollHeight.
151 */
152 this._previousMinRows = -1;
153 this._isViewInited = false;
154 /** Handles `focus` and `blur` events. */
155 this._handleFocusEvent = (event) => {
156 this._hasFocus = event.type === 'focus';
157 };
158 this._document = document;
159 this._textareaElement = this._elementRef.nativeElement;
160 }
161 /** Minimum amount of rows in the textarea. */
162 get minRows() { return this._minRows; }
163 set minRows(value) {
164 this._minRows = coerceNumberProperty(value);
165 this._setMinHeight();
166 }
167 /** Maximum amount of rows in the textarea. */
168 get maxRows() { return this._maxRows; }
169 set maxRows(value) {
170 this._maxRows = coerceNumberProperty(value);
171 this._setMaxHeight();
172 }
173 /** Whether autosizing is enabled or not */
174 get enabled() { return this._enabled; }
175 set enabled(value) {
176 value = coerceBooleanProperty(value);
177 // Only act if the actual value changed. This specifically helps to not run
178 // resizeToFitContent too early (i.e. before ngAfterViewInit)
179 if (this._enabled !== value) {
180 (this._enabled = value) ? this.resizeToFitContent(true) : this.reset();
181 }
182 }
183 get placeholder() { return this._textareaElement.placeholder; }
184 set placeholder(value) {
185 this._cachedPlaceholderHeight = undefined;
186 this._textareaElement.placeholder = value;
187 this._cacheTextareaPlaceholderHeight();
188 }
189 /** Sets the minimum height of the textarea as determined by minRows. */
190 _setMinHeight() {
191 const minHeight = this.minRows && this._cachedLineHeight ?
192 `${this.minRows * this._cachedLineHeight}px` : null;
193 if (minHeight) {
194 this._textareaElement.style.minHeight = minHeight;
195 }
196 }
197 /** Sets the maximum height of the textarea as determined by maxRows. */
198 _setMaxHeight() {
199 const maxHeight = this.maxRows && this._cachedLineHeight ?
200 `${this.maxRows * this._cachedLineHeight}px` : null;
201 if (maxHeight) {
202 this._textareaElement.style.maxHeight = maxHeight;
203 }
204 }
205 ngAfterViewInit() {
206 if (this._platform.isBrowser) {
207 // Remember the height which we started with in case autosizing is disabled
208 this._initialHeight = this._textareaElement.style.height;
209 this.resizeToFitContent();
210 this._ngZone.runOutsideAngular(() => {
211 const window = this._getWindow();
212 fromEvent(window, 'resize')
213 .pipe(auditTime(16), takeUntil(this._destroyed))
214 .subscribe(() => this.resizeToFitContent(true));
215 this._textareaElement.addEventListener('focus', this._handleFocusEvent);
216 this._textareaElement.addEventListener('blur', this._handleFocusEvent);
217 });
218 this._isViewInited = true;
219 this.resizeToFitContent(true);
220 }
221 }
222 ngOnDestroy() {
223 this._textareaElement.removeEventListener('focus', this._handleFocusEvent);
224 this._textareaElement.removeEventListener('blur', this._handleFocusEvent);
225 this._destroyed.next();
226 this._destroyed.complete();
227 }
228 /**
229 * Cache the height of a single-row textarea if it has not already been cached.
230 *
231 * We need to know how large a single "row" of a textarea is in order to apply minRows and
232 * maxRows. For the initial version, we will assume that the height of a single line in the
233 * textarea does not ever change.
234 */
235 _cacheTextareaLineHeight() {
236 if (this._cachedLineHeight) {
237 return;
238 }
239 // Use a clone element because we have to override some styles.
240 let textareaClone = this._textareaElement.cloneNode(false);
241 textareaClone.rows = 1;
242 // Use `position: absolute` so that this doesn't cause a browser layout and use
243 // `visibility: hidden` so that nothing is rendered. Clear any other styles that
244 // would affect the height.
245 textareaClone.style.position = 'absolute';
246 textareaClone.style.visibility = 'hidden';
247 textareaClone.style.border = 'none';
248 textareaClone.style.padding = '0';
249 textareaClone.style.height = '';
250 textareaClone.style.minHeight = '';
251 textareaClone.style.maxHeight = '';
252 // In Firefox it happens that textarea elements are always bigger than the specified amount
253 // of rows. This is because Firefox tries to add extra space for the horizontal scrollbar.
254 // As a workaround that removes the extra space for the scrollbar, we can just set overflow
255 // to hidden. This ensures that there is no invalid calculation of the line height.
256 // See Firefox bug report: https://bugzilla.mozilla.org/show_bug.cgi?id=33654
257 textareaClone.style.overflow = 'hidden';
258 this._textareaElement.parentNode.appendChild(textareaClone);
259 this._cachedLineHeight = textareaClone.clientHeight;
260 this._textareaElement.parentNode.removeChild(textareaClone);
261 // Min and max heights have to be re-calculated if the cached line height changes
262 this._setMinHeight();
263 this._setMaxHeight();
264 }
265 _measureScrollHeight() {
266 const element = this._textareaElement;
267 const previousMargin = element.style.marginBottom || '';
268 const isFirefox = this._platform.FIREFOX;
269 const needsMarginFiller = isFirefox && this._hasFocus;
270 const measuringClass = isFirefox ?
271 'cdk-textarea-autosize-measuring-firefox' :
272 'cdk-textarea-autosize-measuring';
273 // In some cases the page might move around while we're measuring the `textarea` on Firefox. We
274 // work around it by assigning a temporary margin with the same height as the `textarea` so that
275 // it occupies the same amount of space. See #23233.
276 if (needsMarginFiller) {
277 element.style.marginBottom = `${element.clientHeight}px`;
278 }
279 // Reset the textarea height to auto in order to shrink back to its default size.
280 // Also temporarily force overflow:hidden, so scroll bars do not interfere with calculations.
281 element.classList.add(measuringClass);
282 // The measuring class includes a 2px padding to workaround an issue with Chrome,
283 // so we account for that extra space here by subtracting 4 (2px top + 2px bottom).
284 const scrollHeight = element.scrollHeight - 4;
285 element.classList.remove(measuringClass);
286 if (needsMarginFiller) {
287 element.style.marginBottom = previousMargin;
288 }
289 return scrollHeight;
290 }
291 _cacheTextareaPlaceholderHeight() {
292 if (!this._isViewInited || this._cachedPlaceholderHeight != undefined) {
293 return;
294 }
295 if (!this.placeholder) {
296 this._cachedPlaceholderHeight = 0;
297 return;
298 }
299 const value = this._textareaElement.value;
300 this._textareaElement.value = this._textareaElement.placeholder;
301 this._cachedPlaceholderHeight = this._measureScrollHeight();
302 this._textareaElement.value = value;
303 }
304 ngDoCheck() {
305 if (this._platform.isBrowser) {
306 this.resizeToFitContent();
307 }
308 }
309 /**
310 * Resize the textarea to fit its content.
311 * @param force Whether to force a height recalculation. By default the height will be
312 * recalculated only if the value changed since the last call.
313 */
314 resizeToFitContent(force = false) {
315 // If autosizing is disabled, just skip everything else
316 if (!this._enabled) {
317 return;
318 }
319 this._cacheTextareaLineHeight();
320 this._cacheTextareaPlaceholderHeight();
321 // If we haven't determined the line-height yet, we know we're still hidden and there's no point
322 // in checking the height of the textarea.
323 if (!this._cachedLineHeight) {
324 return;
325 }
326 const textarea = this._elementRef.nativeElement;
327 const value = textarea.value;
328 // Only resize if the value or minRows have changed since these calculations can be expensive.
329 if (!force && this._minRows === this._previousMinRows && value === this._previousValue) {
330 return;
331 }
332 const scrollHeight = this._measureScrollHeight();
333 const height = Math.max(scrollHeight, this._cachedPlaceholderHeight || 0);
334 // Use the scrollHeight to know how large the textarea *would* be if fit its entire value.
335 textarea.style.height = `${height}px`;
336 this._ngZone.runOutsideAngular(() => {
337 if (typeof requestAnimationFrame !== 'undefined') {
338 requestAnimationFrame(() => this._scrollToCaretPosition(textarea));
339 }
340 else {
341 setTimeout(() => this._scrollToCaretPosition(textarea));
342 }
343 });
344 this._previousValue = value;
345 this._previousMinRows = this._minRows;
346 }
347 /**
348 * Resets the textarea to its original size
349 */
350 reset() {
351 // Do not try to change the textarea, if the initialHeight has not been determined yet
352 // This might potentially remove styles when reset() is called before ngAfterViewInit
353 if (this._initialHeight !== undefined) {
354 this._textareaElement.style.height = this._initialHeight;
355 }
356 }
357 // In Ivy the `host` metadata will be merged, whereas in ViewEngine it is overridden. In order
358 // to avoid double event listeners, we need to use `HostListener`. Once Ivy is the default, we
359 // can move this back into `host`.
360 // tslint:disable:no-host-decorator-in-concrete
361 _noopInputHandler() {
362 // no-op handler that ensures we're running change detection on input events.
363 }
364 /** Access injected document if available or fallback to global document reference */
365 _getDocument() {
366 return this._document || document;
367 }
368 /** Use defaultView of injected document if available or fallback to global window reference */
369 _getWindow() {
370 const doc = this._getDocument();
371 return doc.defaultView || window;
372 }
373 /**
374 * Scrolls a textarea to the caret position. On Firefox resizing the textarea will
375 * prevent it from scrolling to the caret position. We need to re-set the selection
376 * in order for it to scroll to the proper position.
377 */
378 _scrollToCaretPosition(textarea) {
379 const { selectionStart, selectionEnd } = textarea;
380 // IE will throw an "Unspecified error" if we try to set the selection range after the
381 // element has been removed from the DOM. Assert that the directive hasn't been destroyed
382 // between the time we requested the animation frame and when it was executed.
383 // Also note that we have to assert that the textarea is focused before we set the
384 // selection range. Setting the selection range on a non-focused textarea will cause
385 // it to receive focus on IE and Edge.
386 if (!this._destroyed.isStopped && this._hasFocus) {
387 textarea.setSelectionRange(selectionStart, selectionEnd);
388 }
389 }
390}
391CdkTextareaAutosize.ɵfac = function CdkTextareaAutosize_Factory(t) { return new (t || CdkTextareaAutosize)(ɵngcc0.ɵɵdirectiveInject(ɵngcc0.ElementRef), ɵngcc0.ɵɵdirectiveInject(ɵngcc1.Platform), ɵngcc0.ɵɵdirectiveInject(ɵngcc0.NgZone), ɵngcc0.ɵɵdirectiveInject(DOCUMENT, 8)); };
392CdkTextareaAutosize.ɵdir = /*@__PURE__*/ ɵngcc0.ɵɵdefineDirective({ type: CdkTextareaAutosize, selectors: [["textarea", "cdkTextareaAutosize", ""]], hostAttrs: ["rows", "1", 1, "cdk-textarea-autosize"], hostBindings: function CdkTextareaAutosize_HostBindings(rf, ctx) { if (rf & 1) {
393 ɵngcc0.ɵɵlistener("input", function CdkTextareaAutosize_input_HostBindingHandler() { return ctx._noopInputHandler(); });
394 } }, inputs: { minRows: ["cdkAutosizeMinRows", "minRows"], maxRows: ["cdkAutosizeMaxRows", "maxRows"], enabled: ["cdkTextareaAutosize", "enabled"], placeholder: "placeholder" }, exportAs: ["cdkTextareaAutosize"] });
395CdkTextareaAutosize.ctorParameters = () => [
396 { type: ElementRef },
397 { type: Platform },
398 { type: NgZone },
399 { type: undefined, decorators: [{ type: Optional }, { type: Inject, args: [DOCUMENT,] }] }
400];
401CdkTextareaAutosize.propDecorators = {
402 minRows: [{ type: Input, args: ['cdkAutosizeMinRows',] }],
403 maxRows: [{ type: Input, args: ['cdkAutosizeMaxRows',] }],
404 enabled: [{ type: Input, args: ['cdkTextareaAutosize',] }],
405 placeholder: [{ type: Input }],
406 _noopInputHandler: [{ type: HostListener, args: ['input',] }]
407};
408(function () { (typeof ngDevMode === "undefined" || ngDevMode) && ɵngcc0.ɵsetClassMetadata(CdkTextareaAutosize, [{
409 type: Directive,
410 args: [{
411 selector: 'textarea[cdkTextareaAutosize]',
412 exportAs: 'cdkTextareaAutosize',
413 host: {
414 'class': 'cdk-textarea-autosize',
415 // Textarea elements that have the directive applied should have a single row by default.
416 // Browsers normally show two rows by default and therefore this limits the minRows binding.
417 'rows': '1'
418 }
419 }]
420 }], function () { return [{ type: ɵngcc0.ElementRef }, { type: ɵngcc1.Platform }, { type: ɵngcc0.NgZone }, { type: undefined, decorators: [{
421 type: Optional
422 }, {
423 type: Inject,
424 args: [DOCUMENT]
425 }] }]; }, { minRows: [{
426 type: Input,
427 args: ['cdkAutosizeMinRows']
428 }], maxRows: [{
429 type: Input,
430 args: ['cdkAutosizeMaxRows']
431 }], enabled: [{
432 type: Input,
433 args: ['cdkTextareaAutosize']
434 }], placeholder: [{
435 type: Input
436 }],
437 // In Ivy the `host` metadata will be merged, whereas in ViewEngine it is overridden. In order
438 // to avoid double event listeners, we need to use `HostListener`. Once Ivy is the default, we
439 // can move this back into `host`.
440 // tslint:disable:no-host-decorator-in-concrete
441 _noopInputHandler: [{
442 type: HostListener,
443 args: ['input']
444 }] }); })();
445
446/**
447 * @license
448 * Copyright Google LLC All Rights Reserved.
449 *
450 * Use of this source code is governed by an MIT-style license that can be
451 * found in the LICENSE file at https://angular.io/license
452 */
453class TextFieldModule {
454}
455TextFieldModule.ɵfac = function TextFieldModule_Factory(t) { return new (t || TextFieldModule)(); };
456TextFieldModule.ɵmod = /*@__PURE__*/ ɵngcc0.ɵɵdefineNgModule({ type: TextFieldModule });
457TextFieldModule.ɵinj = /*@__PURE__*/ ɵngcc0.ɵɵdefineInjector({ imports: [[PlatformModule]] });
458(function () { (typeof ngDevMode === "undefined" || ngDevMode) && ɵngcc0.ɵsetClassMetadata(TextFieldModule, [{
459 type: NgModule,
460 args: [{
461 declarations: [CdkAutofill, CdkTextareaAutosize],
462 imports: [PlatformModule],
463 exports: [CdkAutofill, CdkTextareaAutosize]
464 }]
465 }], null, null); })();
466(function () { (typeof ngJitMode === "undefined" || ngJitMode) && ɵngcc0.ɵɵsetNgModuleScope(TextFieldModule, { declarations: function () { return [CdkAutofill, CdkTextareaAutosize]; }, imports: function () { return [PlatformModule]; }, exports: function () { return [CdkAutofill, CdkTextareaAutosize]; } }); })();
467
468/**
469 * @license
470 * Copyright Google LLC All Rights Reserved.
471 *
472 * Use of this source code is governed by an MIT-style license that can be
473 * found in the LICENSE file at https://angular.io/license
474 */
475
476/**
477 * Generated bundle index. Do not edit.
478 */
479
480export { AutofillMonitor, CdkAutofill, CdkTextareaAutosize, TextFieldModule };
481
482//# sourceMappingURL=text-field.js.map
Note: See TracBrowser for help on using the repository browser.