source: trip-planner-front/node_modules/@angular/cdk/bundles/cdk-text-field.umd.js@ 6fe77af

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

initial commit

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