@angular/cdk 7.0.3 → 7.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/a11y/typings/focus-monitor/focus-monitor.d.ts +20 -4
- package/a11y/typings/index.metadata.json +1 -1
- package/a11y/typings/key-manager/list-key-manager.d.ts +8 -0
- package/a11y/typings/live-announcer/live-announcer.d.ts +37 -4
- package/bidi/typings/dir.d.ts +4 -1
- package/bidi/typings/index.metadata.json +1 -1
- package/bundles/cdk-a11y.umd.js +503 -210
- package/bundles/cdk-a11y.umd.js.map +1 -1
- package/bundles/cdk-a11y.umd.min.js +1 -1
- package/bundles/cdk-a11y.umd.min.js.map +1 -1
- package/bundles/cdk-accordion.umd.js +16 -9
- package/bundles/cdk-accordion.umd.js.map +1 -1
- package/bundles/cdk-accordion.umd.min.js.map +1 -1
- package/bundles/cdk-bidi.umd.js +16 -7
- package/bundles/cdk-bidi.umd.js.map +1 -1
- package/bundles/cdk-bidi.umd.min.js +1 -1
- package/bundles/cdk-bidi.umd.min.js.map +1 -1
- package/bundles/cdk-coercion.umd.js +5 -5
- package/bundles/cdk-coercion.umd.js.map +1 -1
- package/bundles/cdk-collections.umd.js +28 -5
- package/bundles/cdk-collections.umd.js.map +1 -1
- package/bundles/cdk-collections.umd.min.js.map +1 -1
- package/bundles/cdk-drag-drop.umd.js +2251 -853
- package/bundles/cdk-drag-drop.umd.js.map +1 -1
- package/bundles/cdk-drag-drop.umd.min.js +2 -1
- package/bundles/cdk-drag-drop.umd.min.js.map +1 -1
- package/bundles/cdk-keycodes.umd.js +33 -1
- package/bundles/cdk-keycodes.umd.js.map +1 -1
- package/bundles/cdk-keycodes.umd.min.js +1 -1
- package/bundles/cdk-keycodes.umd.min.js.map +1 -1
- package/bundles/cdk-layout.umd.js +29 -22
- package/bundles/cdk-layout.umd.js.map +1 -1
- package/bundles/cdk-layout.umd.min.js +1 -1
- package/bundles/cdk-layout.umd.min.js.map +1 -1
- package/bundles/cdk-observers.umd.js +25 -6
- package/bundles/cdk-observers.umd.js.map +1 -1
- package/bundles/cdk-observers.umd.min.js.map +1 -1
- package/bundles/cdk-overlay.umd.js +600 -243
- package/bundles/cdk-overlay.umd.js.map +1 -1
- package/bundles/cdk-overlay.umd.min.js +2 -2
- package/bundles/cdk-overlay.umd.min.js.map +1 -1
- package/bundles/cdk-platform.umd.js +50 -28
- package/bundles/cdk-platform.umd.js.map +1 -1
- package/bundles/cdk-platform.umd.min.js.map +1 -1
- package/bundles/cdk-portal.umd.js +14 -7
- package/bundles/cdk-portal.umd.js.map +1 -1
- package/bundles/cdk-portal.umd.min.js.map +1 -1
- package/bundles/cdk-scrolling.umd.js +143 -48
- package/bundles/cdk-scrolling.umd.js.map +1 -1
- package/bundles/cdk-scrolling.umd.min.js +1 -1
- package/bundles/cdk-scrolling.umd.min.js.map +1 -1
- package/bundles/cdk-stepper.umd.js +103 -19
- package/bundles/cdk-stepper.umd.js.map +1 -1
- package/bundles/cdk-stepper.umd.min.js +1 -1
- package/bundles/cdk-stepper.umd.min.js.map +1 -1
- package/bundles/cdk-table.umd.js +182 -48
- package/bundles/cdk-table.umd.js.map +1 -1
- package/bundles/cdk-table.umd.min.js.map +1 -1
- package/bundles/cdk-text-field.umd.js +70 -32
- package/bundles/cdk-text-field.umd.js.map +1 -1
- package/bundles/cdk-text-field.umd.min.js +1 -1
- package/bundles/cdk-text-field.umd.min.js.map +1 -1
- package/bundles/cdk-tree.umd.js +71 -34
- package/bundles/cdk-tree.umd.js.map +1 -1
- package/bundles/cdk-tree.umd.min.js +1 -1
- package/bundles/cdk-tree.umd.min.js.map +1 -1
- package/bundles/cdk.umd.js +5 -4
- package/bundles/cdk.umd.js.map +1 -1
- package/bundles/cdk.umd.min.js +1 -1
- package/bundles/cdk.umd.min.js.map +1 -1
- package/drag-drop/typings/{drag-handle.d.ts → directives/drag-handle.d.ts} +3 -0
- package/drag-drop/typings/{drag-placeholder.d.ts → directives/drag-placeholder.d.ts} +0 -0
- package/drag-drop/typings/{drag-preview.d.ts → directives/drag-preview.d.ts} +0 -0
- package/drag-drop/typings/directives/drag.d.ts +108 -0
- package/drag-drop/typings/directives/drop-list-group.d.ts +22 -0
- package/drag-drop/typings/directives/drop-list.d.ts +135 -0
- package/drag-drop/typings/drag-drop-registry.d.ts +8 -5
- package/drag-drop/typings/drag-events.d.ts +24 -6
- package/{typings/esm5/drag-drop/drag.d.ts → drag-drop/typings/drag-ref.d.ts} +153 -77
- package/drag-drop/typings/drop-list-container.d.ts +21 -3
- package/drag-drop/typings/{drop-list.d.ts → drop-list-ref.d.ts} +133 -77
- package/drag-drop/typings/index.d.ts +1 -0
- package/drag-drop/typings/index.metadata.json +1 -1
- package/drag-drop/typings/public-api.d.ts +13 -5
- package/esm2015/a11y.js +353 -189
- package/esm2015/a11y.js.map +1 -1
- package/esm2015/accordion.js +16 -11
- package/esm2015/accordion.js.map +1 -1
- package/esm2015/bidi.js +18 -9
- package/esm2015/bidi.js.map +1 -1
- package/esm2015/cdk.js +7 -6
- package/esm2015/cdk.js.map +1 -1
- package/esm2015/coercion.js +7 -7
- package/esm2015/coercion.js.map +1 -1
- package/esm2015/collections.js +22 -7
- package/esm2015/collections.js.map +1 -1
- package/esm2015/drag-drop.js +1768 -751
- package/esm2015/drag-drop.js.map +1 -1
- package/esm2015/keycodes.js +31 -4
- package/esm2015/keycodes.js.map +1 -1
- package/esm2015/layout.js +29 -19
- package/esm2015/layout.js.map +1 -1
- package/esm2015/observers.js +13 -8
- package/esm2015/observers.js.map +1 -1
- package/esm2015/overlay.js +384 -219
- package/esm2015/overlay.js.map +1 -1
- package/esm2015/platform.js +53 -31
- package/esm2015/platform.js.map +1 -1
- package/esm2015/portal.js +13 -9
- package/esm2015/portal.js.map +1 -1
- package/esm2015/scrolling.js +106 -49
- package/esm2015/scrolling.js.map +1 -1
- package/esm2015/stepper.js +93 -24
- package/esm2015/stepper.js.map +1 -1
- package/esm2015/table.js +89 -45
- package/esm2015/table.js.map +1 -1
- package/esm2015/text-field.js +51 -34
- package/esm2015/text-field.js.map +1 -1
- package/esm2015/tree.js +55 -36
- package/esm2015/tree.js.map +1 -1
- package/esm5/a11y.es5.js +507 -214
- package/esm5/a11y.es5.js.map +1 -1
- package/esm5/accordion.es5.js +18 -11
- package/esm5/accordion.es5.js.map +1 -1
- package/esm5/bidi.es5.js +18 -9
- package/esm5/bidi.es5.js.map +1 -1
- package/esm5/cdk.es5.js +7 -6
- package/esm5/cdk.es5.js.map +1 -1
- package/esm5/coercion.es5.js +7 -7
- package/esm5/coercion.es5.js.map +1 -1
- package/esm5/collections.es5.js +35 -7
- package/esm5/collections.es5.js.map +1 -1
- package/esm5/drag-drop.es5.js +2125 -729
- package/esm5/drag-drop.es5.js.map +1 -1
- package/esm5/keycodes.es5.js +35 -4
- package/esm5/keycodes.es5.js.map +1 -1
- package/esm5/layout.es5.js +31 -24
- package/esm5/layout.es5.js.map +1 -1
- package/esm5/observers.es5.js +27 -8
- package/esm5/observers.es5.js.map +1 -1
- package/esm5/overlay.es5.js +602 -245
- package/esm5/overlay.es5.js.map +1 -1
- package/esm5/platform.es5.js +52 -30
- package/esm5/platform.es5.js.map +1 -1
- package/esm5/portal.es5.js +16 -9
- package/esm5/portal.es5.js.map +1 -1
- package/esm5/scrolling.es5.js +145 -50
- package/esm5/scrolling.es5.js.map +1 -1
- package/esm5/stepper.es5.js +106 -24
- package/esm5/stepper.es5.js.map +1 -1
- package/esm5/table.es5.js +184 -50
- package/esm5/table.es5.js.map +1 -1
- package/esm5/text-field.es5.js +72 -34
- package/esm5/text-field.es5.js.map +1 -1
- package/esm5/tree.es5.js +74 -37
- package/esm5/tree.es5.js.map +1 -1
- package/keycodes/typings/index.metadata.json +1 -1
- package/keycodes/typings/modifiers.d.ts +14 -0
- package/keycodes/typings/public-api.d.ts +1 -0
- package/overlay/typings/index.metadata.json +1 -1
- package/package.json +4 -4
- package/schematics/ng-generate/drag-drop/files/__path__/__name@dasherize@if-flat__/__name@dasherize__.component.ts +2 -2
- package/schematics/ng-update/upgrade-data.js +2 -1
- package/schematics/ng-update/upgrade-data.js.map +1 -1
- package/schematics/ng-update/upgrade-rules/index.js +3 -2
- package/schematics/ng-update/upgrade-rules/index.js.map +1 -1
- package/schematics/utils/ast/ng-module-imports.d.ts +1 -1
- package/schematics/utils/ast/ng-module-imports.js +25 -13
- package/schematics/utils/ast/ng-module-imports.js.map +1 -1
- package/schematics/utils/get-project.js +2 -1
- package/schematics/utils/get-project.js.map +1 -1
- package/schematics/utils/parse5-element.js +3 -2
- package/schematics/utils/parse5-element.js.map +1 -1
- package/schematics/utils/project-targets.js +2 -1
- package/schematics/utils/project-targets.js.map +1 -1
- package/schematics/utils/version-agnostic-typescript.js +3 -2
- package/schematics/utils/version-agnostic-typescript.js.map +1 -1
- package/scrolling/typings/index.metadata.json +1 -1
- package/stepper/typings/index.metadata.json +1 -1
- package/stepper/typings/public-api.d.ts +1 -0
- package/stepper/typings/step-header.d.ts +15 -0
- package/stepper/typings/stepper.d.ts +11 -1
- package/text-field/typings/autosize.d.ts +6 -0
- package/text-field/typings/index.metadata.json +1 -1
- package/tree/typings/nested-node.d.ts +5 -5
- package/typings/a11y/focus-monitor/focus-monitor.d.ts +20 -4
- package/typings/a11y/index.metadata.json +1 -1
- package/typings/a11y/key-manager/list-key-manager.d.ts +8 -0
- package/typings/a11y/live-announcer/live-announcer.d.ts +37 -4
- package/typings/bidi/dir.d.ts +4 -1
- package/typings/bidi/index.metadata.json +1 -1
- package/typings/{esm5/drag-drop → drag-drop/directives}/drag-handle.d.ts +3 -0
- package/typings/drag-drop/{drag-placeholder.d.ts → directives/drag-placeholder.d.ts} +0 -0
- package/typings/drag-drop/{drag-preview.d.ts → directives/drag-preview.d.ts} +0 -0
- package/typings/drag-drop/directives/drag.d.ts +108 -0
- package/typings/drag-drop/directives/drop-list-group.d.ts +22 -0
- package/typings/drag-drop/directives/drop-list.d.ts +135 -0
- package/typings/drag-drop/drag-drop-registry.d.ts +8 -5
- package/typings/drag-drop/drag-events.d.ts +24 -6
- package/typings/drag-drop/{drag.d.ts → drag-ref.d.ts} +153 -77
- package/typings/drag-drop/drop-list-container.d.ts +21 -3
- package/typings/{esm5/drag-drop/drop-list.d.ts → drag-drop/drop-list-ref.d.ts} +133 -77
- package/typings/drag-drop/index.d.ts +1 -0
- package/typings/drag-drop/index.metadata.json +1 -1
- package/typings/drag-drop/public-api.d.ts +13 -5
- package/typings/esm5/a11y/focus-monitor/focus-monitor.d.ts +20 -4
- package/typings/esm5/a11y/index.metadata.json +1 -1
- package/typings/esm5/a11y/key-manager/list-key-manager.d.ts +8 -0
- package/typings/esm5/a11y/live-announcer/live-announcer.d.ts +37 -4
- package/typings/esm5/bidi/dir.d.ts +4 -1
- package/typings/esm5/bidi/index.metadata.json +1 -1
- package/typings/{drag-drop → esm5/drag-drop/directives}/drag-handle.d.ts +3 -0
- package/typings/esm5/drag-drop/{drag-placeholder.d.ts → directives/drag-placeholder.d.ts} +0 -0
- package/typings/esm5/drag-drop/{drag-preview.d.ts → directives/drag-preview.d.ts} +0 -0
- package/typings/esm5/drag-drop/directives/drag.d.ts +108 -0
- package/typings/esm5/drag-drop/directives/drop-list-group.d.ts +22 -0
- package/typings/esm5/drag-drop/directives/drop-list.d.ts +135 -0
- package/typings/esm5/drag-drop/drag-drop-registry.d.ts +8 -5
- package/typings/esm5/drag-drop/drag-events.d.ts +24 -6
- package/{drag-drop/typings/drag.d.ts → typings/esm5/drag-drop/drag-ref.d.ts} +153 -77
- package/typings/esm5/drag-drop/drop-list-container.d.ts +21 -3
- package/typings/{drag-drop/drop-list.d.ts → esm5/drag-drop/drop-list-ref.d.ts} +133 -77
- package/typings/esm5/drag-drop/index.d.ts +1 -0
- package/typings/esm5/drag-drop/index.metadata.json +1 -1
- package/typings/esm5/drag-drop/public-api.d.ts +13 -5
- package/typings/esm5/index.metadata.json +1 -1
- package/typings/esm5/keycodes/index.metadata.json +1 -1
- package/typings/esm5/keycodes/modifiers.d.ts +14 -0
- package/typings/esm5/keycodes/public-api.d.ts +1 -0
- package/typings/esm5/overlay/index.metadata.json +1 -1
- package/typings/esm5/scrolling/index.metadata.json +1 -1
- package/typings/esm5/stepper/index.metadata.json +1 -1
- package/typings/esm5/stepper/public-api.d.ts +1 -0
- package/typings/esm5/stepper/step-header.d.ts +15 -0
- package/typings/esm5/stepper/stepper.d.ts +11 -1
- package/typings/esm5/text-field/autosize.d.ts +6 -0
- package/typings/esm5/text-field/index.metadata.json +1 -1
- package/typings/esm5/tree/nested-node.d.ts +5 -5
- package/typings/index.metadata.json +1 -1
- package/typings/keycodes/index.metadata.json +1 -1
- package/typings/keycodes/modifiers.d.ts +14 -0
- package/typings/keycodes/public-api.d.ts +1 -0
- package/typings/overlay/index.metadata.json +1 -1
- package/typings/schematics/utils/ast/ng-module-imports.d.ts +1 -1
- package/typings/scrolling/index.metadata.json +1 -1
- package/typings/stepper/index.metadata.json +1 -1
- package/typings/stepper/public-api.d.ts +1 -0
- package/typings/stepper/step-header.d.ts +15 -0
- package/typings/stepper/stepper.d.ts +11 -1
- package/typings/text-field/autosize.d.ts +6 -0
- package/typings/text-field/index.metadata.json +1 -1
- package/typings/tree/nested-node.d.ts +5 -5
package/esm2015/text-field.js
CHANGED
|
@@ -13,11 +13,12 @@ import { auditTime, takeUntil } from 'rxjs/operators';
|
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* @fileoverview added by tsickle
|
|
16
|
-
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
|
|
16
|
+
* @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
17
17
|
*/
|
|
18
|
-
/**
|
|
18
|
+
/**
|
|
19
19
|
* Options to pass to the animationstart listener.
|
|
20
|
-
|
|
20
|
+
* @type {?}
|
|
21
|
+
*/
|
|
21
22
|
const listenerOptions = normalizePassiveListenerOptions({ passive: true });
|
|
22
23
|
/**
|
|
23
24
|
* An injectable service that can be used to monitor the autofill state of an input.
|
|
@@ -54,21 +55,21 @@ class AutofillMonitor {
|
|
|
54
55
|
/** @type {?} */
|
|
55
56
|
const cssClass = 'cdk-text-field-autofilled';
|
|
56
57
|
/** @type {?} */
|
|
57
|
-
const listener = /** @type {?} */ (((event) => {
|
|
58
|
+
const listener = (/** @type {?} */ (((event) => {
|
|
58
59
|
// Animation events fire on initial element render, we check for the presence of the autofill
|
|
59
60
|
// CSS class to make sure this is a real change in state, not just the initial render before
|
|
60
61
|
// we fire off events.
|
|
61
62
|
if (event.animationName === 'cdk-text-field-autofill-start' &&
|
|
62
63
|
!element.classList.contains(cssClass)) {
|
|
63
64
|
element.classList.add(cssClass);
|
|
64
|
-
this._ngZone.run(() => result.next({ target: /** @type {?} */ (event.target), isAutofilled: true }));
|
|
65
|
+
this._ngZone.run(() => result.next({ target: (/** @type {?} */ (event.target)), isAutofilled: true }));
|
|
65
66
|
}
|
|
66
67
|
else if (event.animationName === 'cdk-text-field-autofill-end' &&
|
|
67
68
|
element.classList.contains(cssClass)) {
|
|
68
69
|
element.classList.remove(cssClass);
|
|
69
|
-
this._ngZone.run(() => result.next({ target: /** @type {?} */ (event.target), isAutofilled: false }));
|
|
70
|
+
this._ngZone.run(() => result.next({ target: (/** @type {?} */ (event.target)), isAutofilled: false }));
|
|
70
71
|
}
|
|
71
|
-
}));
|
|
72
|
+
})));
|
|
72
73
|
this._ngZone.runOutsideAngular(() => {
|
|
73
74
|
element.addEventListener('animationstart', listener, listenerOptions);
|
|
74
75
|
element.classList.add('cdk-text-field-autofill-monitored');
|
|
@@ -161,7 +162,7 @@ CdkAutofill.propDecorators = {
|
|
|
161
162
|
|
|
162
163
|
/**
|
|
163
164
|
* @fileoverview added by tsickle
|
|
164
|
-
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
|
|
165
|
+
* @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
165
166
|
*/
|
|
166
167
|
/**
|
|
167
168
|
* Directive to automatically resize a textarea to fit its content.
|
|
@@ -184,7 +185,7 @@ class CdkTextareaAutosize {
|
|
|
184
185
|
* does not have the same problem because it does not affect the textarea's scrollHeight.
|
|
185
186
|
*/
|
|
186
187
|
this._previousMinRows = -1;
|
|
187
|
-
this._textareaElement = /** @type {?} */ (this._elementRef.nativeElement);
|
|
188
|
+
this._textareaElement = (/** @type {?} */ (this._elementRef.nativeElement));
|
|
188
189
|
}
|
|
189
190
|
/**
|
|
190
191
|
* Minimum amount of rows in the textarea.
|
|
@@ -281,14 +282,16 @@ class CdkTextareaAutosize {
|
|
|
281
282
|
* We need to know how large a single "row" of a textarea is in order to apply minRows and
|
|
282
283
|
* maxRows. For the initial version, we will assume that the height of a single line in the
|
|
283
284
|
* textarea does not ever change.
|
|
285
|
+
* @private
|
|
284
286
|
* @return {?}
|
|
285
287
|
*/
|
|
286
288
|
_cacheTextareaLineHeight() {
|
|
287
289
|
if (this._cachedLineHeight) {
|
|
288
290
|
return;
|
|
289
291
|
}
|
|
292
|
+
// Use a clone element because we have to override some styles.
|
|
290
293
|
/** @type {?} */
|
|
291
|
-
let textareaClone = /** @type {?} */ (this._textareaElement.cloneNode(false));
|
|
294
|
+
let textareaClone = (/** @type {?} */ (this._textareaElement.cloneNode(false)));
|
|
292
295
|
textareaClone.rows = 1;
|
|
293
296
|
// Use `position: absolute` so that this doesn't cause a browser layout and use
|
|
294
297
|
// `visibility: hidden` so that nothing is rendered. Clear any other styles that
|
|
@@ -305,10 +308,10 @@ class CdkTextareaAutosize {
|
|
|
305
308
|
// As a workaround that removes the extra space for the scrollbar, we can just set overflow
|
|
306
309
|
// to hidden. This ensures that there is no invalid calculation of the line height.
|
|
307
310
|
// See Firefox bug report: https://bugzilla.mozilla.org/show_bug.cgi?id=33654
|
|
308
|
-
textareaClone.style.overflow = 'hidden';
|
|
309
|
-
((this._textareaElement.parentNode)).appendChild(textareaClone);
|
|
310
|
-
this._cachedLineHeight = textareaClone.clientHeight;
|
|
311
|
-
((this._textareaElement.parentNode)).removeChild(textareaClone);
|
|
311
|
+
textareaClone.style.overflow = 'hidden';
|
|
312
|
+
(/** @type {?} */ (this._textareaElement.parentNode)).appendChild(textareaClone);
|
|
313
|
+
this._cachedLineHeight = textareaClone.clientHeight;
|
|
314
|
+
(/** @type {?} */ (this._textareaElement.parentNode)).removeChild(textareaClone);
|
|
312
315
|
// Min and max heights have to be re-calculated if the cached line height changes
|
|
313
316
|
this._setMinHeight();
|
|
314
317
|
this._setMaxHeight();
|
|
@@ -339,7 +342,7 @@ class CdkTextareaAutosize {
|
|
|
339
342
|
return;
|
|
340
343
|
}
|
|
341
344
|
/** @type {?} */
|
|
342
|
-
const textarea = /** @type {?} */ (this._elementRef.nativeElement);
|
|
345
|
+
const textarea = (/** @type {?} */ (this._elementRef.nativeElement));
|
|
343
346
|
/** @type {?} */
|
|
344
347
|
const value = textarea.value;
|
|
345
348
|
// Only resize if the value or minRows have changed since these calculations can be expensive.
|
|
@@ -355,28 +358,22 @@ class CdkTextareaAutosize {
|
|
|
355
358
|
// need to be removed temporarily.
|
|
356
359
|
textarea.classList.add('cdk-textarea-autosize-measuring');
|
|
357
360
|
textarea.placeholder = '';
|
|
361
|
+
// The cdk-textarea-autosize-measuring class includes a 2px padding to workaround an issue with
|
|
362
|
+
// Chrome, so we account for that extra space here by subtracting 4 (2px top + 2px bottom).
|
|
358
363
|
/** @type {?} */
|
|
359
364
|
const height = textarea.scrollHeight - 4;
|
|
360
365
|
// Use the scrollHeight to know how large the textarea *would* be if fit its entire value.
|
|
361
366
|
textarea.style.height = `${height}px`;
|
|
362
367
|
textarea.classList.remove('cdk-textarea-autosize-measuring');
|
|
363
368
|
textarea.placeholder = placeholderText;
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
// Also note that we have to assert that the textarea is focused before we set the
|
|
373
|
-
// selection range. Setting the selection range on a non-focused textarea will cause
|
|
374
|
-
// it to receive focus on IE and Edge.
|
|
375
|
-
if (!this._destroyed.isStopped && document.activeElement === textarea) {
|
|
376
|
-
textarea.setSelectionRange(selectionStart, selectionEnd);
|
|
377
|
-
}
|
|
378
|
-
}));
|
|
379
|
-
}
|
|
369
|
+
this._ngZone.runOutsideAngular(() => {
|
|
370
|
+
if (typeof requestAnimationFrame !== 'undefined') {
|
|
371
|
+
requestAnimationFrame(() => this._scrollToCaretPosition(textarea));
|
|
372
|
+
}
|
|
373
|
+
else {
|
|
374
|
+
setTimeout(() => this._scrollToCaretPosition(textarea));
|
|
375
|
+
}
|
|
376
|
+
});
|
|
380
377
|
this._previousValue = value;
|
|
381
378
|
this._previousMinRows = this._minRows;
|
|
382
379
|
}
|
|
@@ -398,6 +395,26 @@ class CdkTextareaAutosize {
|
|
|
398
395
|
_noopInputHandler() {
|
|
399
396
|
// no-op handler that ensures we're running change detection on input events.
|
|
400
397
|
}
|
|
398
|
+
/**
|
|
399
|
+
* Scrolls a textarea to the caret position. On Firefox resizing the textarea will
|
|
400
|
+
* prevent it from scrolling to the caret position. We need to re-set the selection
|
|
401
|
+
* in order for it to scroll to the proper position.
|
|
402
|
+
* @private
|
|
403
|
+
* @param {?} textarea
|
|
404
|
+
* @return {?}
|
|
405
|
+
*/
|
|
406
|
+
_scrollToCaretPosition(textarea) {
|
|
407
|
+
const { selectionStart, selectionEnd } = textarea;
|
|
408
|
+
// IE will throw an "Unspecified error" if we try to set the selection range after the
|
|
409
|
+
// element has been removed from the DOM. Assert that the directive hasn't been destroyed
|
|
410
|
+
// between the time we requested the animation frame and when it was executed.
|
|
411
|
+
// Also note that we have to assert that the textarea is focused before we set the
|
|
412
|
+
// selection range. Setting the selection range on a non-focused textarea will cause
|
|
413
|
+
// it to receive focus on IE and Edge.
|
|
414
|
+
if (!this._destroyed.isStopped && document.activeElement === textarea) {
|
|
415
|
+
textarea.setSelectionRange(selectionStart, selectionEnd);
|
|
416
|
+
}
|
|
417
|
+
}
|
|
401
418
|
}
|
|
402
419
|
CdkTextareaAutosize.decorators = [
|
|
403
420
|
{ type: Directive, args: [{
|
|
@@ -426,7 +443,7 @@ CdkTextareaAutosize.propDecorators = {
|
|
|
426
443
|
|
|
427
444
|
/**
|
|
428
445
|
* @fileoverview added by tsickle
|
|
429
|
-
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
|
|
446
|
+
* @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
430
447
|
*/
|
|
431
448
|
class TextFieldModule {
|
|
432
449
|
}
|
|
@@ -440,12 +457,12 @@ TextFieldModule.decorators = [
|
|
|
440
457
|
|
|
441
458
|
/**
|
|
442
459
|
* @fileoverview added by tsickle
|
|
443
|
-
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
|
|
460
|
+
* @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
444
461
|
*/
|
|
445
462
|
|
|
446
463
|
/**
|
|
447
464
|
* @fileoverview added by tsickle
|
|
448
|
-
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
|
|
465
|
+
* @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
449
466
|
*/
|
|
450
467
|
|
|
451
468
|
export { AutofillMonitor, CdkAutofill, CdkTextareaAutosize, TextFieldModule };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"text-field.js","sources":["../../../src/cdk/text-field/text-field-module.ts","../../../src/cdk/text-field/autosize.ts","../../../src/cdk/text-field/autofill.ts"],"sourcesContent":["/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.io/license\n */\n\nimport {PlatformModule} from '@angular/cdk/platform';\nimport {NgModule} from '@angular/core';\nimport {CdkAutofill} from './autofill';\nimport {CdkTextareaAutosize} from './autosize';\n\n\n@NgModule({\n declarations: [CdkAutofill, CdkTextareaAutosize],\n imports: [PlatformModule],\n exports: [CdkAutofill, CdkTextareaAutosize],\n})\nexport class TextFieldModule {}\n","/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.io/license\n */\n\nimport {coerceBooleanProperty} from '@angular/cdk/coercion';\nimport {\n Directive,\n ElementRef,\n Input,\n AfterViewInit,\n DoCheck,\n OnDestroy,\n NgZone,\n} from '@angular/core';\nimport {Platform} from '@angular/cdk/platform';\nimport {auditTime, takeUntil} from 'rxjs/operators';\nimport {fromEvent, Subject} from 'rxjs';\n\n\n/** Directive to automatically resize a textarea to fit its content. */\n@Directive({\n selector: 'textarea[cdkTextareaAutosize]',\n exportAs: 'cdkTextareaAutosize',\n host: {\n 'class': 'cdk-textarea-autosize',\n // Textarea elements that have the directive applied should have a single row by default.\n // Browsers normally show two rows by default and therefore this limits the minRows binding.\n 'rows': '1',\n '(input)': '_noopInputHandler()',\n },\n})\nexport class CdkTextareaAutosize implements AfterViewInit, DoCheck, OnDestroy {\n /** Keep track of the previous textarea value to avoid resizing when the value hasn't changed. */\n private _previousValue?: string;\n private _initialHeight: string | null;\n private readonly _destroyed = new Subject<void>();\n\n private _minRows: number;\n private _maxRows: number;\n private _enabled: boolean = true;\n\n /**\n * Value of minRows as of last resize. If the minRows has decreased, the\n * height of the textarea needs to be recomputed to reflect the new minimum. The maxHeight\n * does not have the same problem because it does not affect the textarea's scrollHeight.\n */\n private _previousMinRows: number = -1;\n\n private _textareaElement: HTMLTextAreaElement;\n\n /** Minimum amount of rows in the textarea. */\n @Input('cdkAutosizeMinRows')\n get minRows(): number { return this._minRows; }\n set minRows(value: number) {\n this._minRows = value;\n this._setMinHeight();\n }\n\n /** Maximum amount of rows in the textarea. */\n @Input('cdkAutosizeMaxRows')\n get maxRows(): number { return this._maxRows; }\n set maxRows(value: number) {\n this._maxRows = value;\n this._setMaxHeight();\n }\n\n /** Whether autosizing is enabled or not */\n @Input('cdkTextareaAutosize')\n get enabled(): boolean { return this._enabled; }\n set enabled(value: boolean) {\n value = coerceBooleanProperty(value);\n\n // Only act if the actual value changed. This specifically helps to not run\n // resizeToFitContent too early (i.e. before ngAfterViewInit)\n if (this._enabled !== value) {\n (this._enabled = value) ? this.resizeToFitContent(true) : this.reset();\n }\n }\n\n /** Cached height of a textarea with a single row. */\n private _cachedLineHeight: number;\n\n constructor(\n private _elementRef: ElementRef<HTMLElement>,\n private _platform: Platform,\n private _ngZone: NgZone) {\n this._textareaElement = this._elementRef.nativeElement as HTMLTextAreaElement;\n }\n\n /** Sets the minimum height of the textarea as determined by minRows. */\n _setMinHeight(): void {\n const minHeight = this.minRows && this._cachedLineHeight ?\n `${this.minRows * this._cachedLineHeight}px` : null;\n\n if (minHeight) {\n this._textareaElement.style.minHeight = minHeight;\n }\n }\n\n /** Sets the maximum height of the textarea as determined by maxRows. */\n _setMaxHeight(): void {\n const maxHeight = this.maxRows && this._cachedLineHeight ?\n `${this.maxRows * this._cachedLineHeight}px` : null;\n\n if (maxHeight) {\n this._textareaElement.style.maxHeight = maxHeight;\n }\n }\n\n ngAfterViewInit() {\n if (this._platform.isBrowser) {\n // Remember the height which we started with in case autosizing is disabled\n this._initialHeight = this._textareaElement.style.height;\n\n this.resizeToFitContent();\n\n this._ngZone.runOutsideAngular(() => {\n fromEvent(window, 'resize')\n .pipe(auditTime(16), takeUntil(this._destroyed))\n .subscribe(() => this.resizeToFitContent(true));\n });\n }\n }\n\n ngOnDestroy() {\n this._destroyed.next();\n this._destroyed.complete();\n }\n\n /**\n * Cache the height of a single-row textarea if it has not already been cached.\n *\n * We need to know how large a single \"row\" of a textarea is in order to apply minRows and\n * maxRows. For the initial version, we will assume that the height of a single line in the\n * textarea does not ever change.\n */\n private _cacheTextareaLineHeight(): void {\n if (this._cachedLineHeight) {\n return;\n }\n\n // Use a clone element because we have to override some styles.\n let textareaClone = this._textareaElement.cloneNode(false) as HTMLTextAreaElement;\n textareaClone.rows = 1;\n\n // Use `position: absolute` so that this doesn't cause a browser layout and use\n // `visibility: hidden` so that nothing is rendered. Clear any other styles that\n // would affect the height.\n textareaClone.style.position = 'absolute';\n textareaClone.style.visibility = 'hidden';\n textareaClone.style.border = 'none';\n textareaClone.style.padding = '0';\n textareaClone.style.height = '';\n textareaClone.style.minHeight = '';\n textareaClone.style.maxHeight = '';\n\n // In Firefox it happens that textarea elements are always bigger than the specified amount\n // of rows. This is because Firefox tries to add extra space for the horizontal scrollbar.\n // As a workaround that removes the extra space for the scrollbar, we can just set overflow\n // to hidden. This ensures that there is no invalid calculation of the line height.\n // See Firefox bug report: https://bugzilla.mozilla.org/show_bug.cgi?id=33654\n textareaClone.style.overflow = 'hidden';\n\n this._textareaElement.parentNode!.appendChild(textareaClone);\n this._cachedLineHeight = textareaClone.clientHeight;\n this._textareaElement.parentNode!.removeChild(textareaClone);\n\n // Min and max heights have to be re-calculated if the cached line height changes\n this._setMinHeight();\n this._setMaxHeight();\n }\n\n ngDoCheck() {\n if (this._platform.isBrowser) {\n this.resizeToFitContent();\n }\n }\n\n /**\n * Resize the textarea to fit its content.\n * @param force Whether to force a height recalculation. By default the height will be\n * recalculated only if the value changed since the last call.\n */\n resizeToFitContent(force: boolean = false) {\n // If autosizing is disabled, just skip everything else\n if (!this._enabled) {\n return;\n }\n\n this._cacheTextareaLineHeight();\n\n // If we haven't determined the line-height yet, we know we're still hidden and there's no point\n // in checking the height of the textarea.\n if (!this._cachedLineHeight) {\n return;\n }\n\n const textarea = this._elementRef.nativeElement as HTMLTextAreaElement;\n const value = textarea.value;\n\n // Only resize if the value or minRows have changed since these calculations can be expensive.\n if (!force && this._minRows === this._previousMinRows && value === this._previousValue) {\n return;\n }\n\n const placeholderText = textarea.placeholder;\n\n // Reset the textarea height to auto in order to shrink back to its default size.\n // Also temporarily force overflow:hidden, so scroll bars do not interfere with calculations.\n // Long placeholders that are wider than the textarea width may lead to a bigger scrollHeight\n // value. To ensure that the scrollHeight is not bigger than the content, the placeholders\n // need to be removed temporarily.\n textarea.classList.add('cdk-textarea-autosize-measuring');\n textarea.placeholder = '';\n\n // The cdk-textarea-autosize-measuring class includes a 2px padding to workaround an issue with\n // Chrome, so we account for that extra space here by subtracting 4 (2px top + 2px bottom).\n const height = textarea.scrollHeight - 4;\n\n // Use the scrollHeight to know how large the textarea *would* be if fit its entire value.\n textarea.style.height = `${height}px`;\n textarea.classList.remove('cdk-textarea-autosize-measuring');\n textarea.placeholder = placeholderText;\n\n // On Firefox resizing the textarea will prevent it from scrolling to the caret position.\n // We need to re-set the selection in order for it to scroll to the proper position.\n if (typeof requestAnimationFrame !== 'undefined') {\n this._ngZone.runOutsideAngular(() => requestAnimationFrame(() => {\n const {selectionStart, selectionEnd} = textarea;\n\n // IE will throw an \"Unspecified error\" if we try to set the selection range after the\n // element has been removed from the DOM. Assert that the directive hasn't been destroyed\n // between the time we requested the animation frame and when it was executed.\n // Also note that we have to assert that the textarea is focused before we set the\n // selection range. Setting the selection range on a non-focused textarea will cause\n // it to receive focus on IE and Edge.\n if (!this._destroyed.isStopped && document.activeElement === textarea) {\n textarea.setSelectionRange(selectionStart, selectionEnd);\n }\n }));\n }\n\n this._previousValue = value;\n this._previousMinRows = this._minRows;\n }\n\n /**\n * Resets the textarea to it's original size\n */\n reset() {\n // Do not try to change the textarea, if the initialHeight has not been determined yet\n // This might potentially remove styles when reset() is called before ngAfterViewInit\n if (this._initialHeight === undefined) {\n return;\n }\n this._textareaElement.style.height = this._initialHeight;\n }\n\n _noopInputHandler() {\n // no-op handler that ensures we're running change detection on input events.\n }\n}\n","/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.io/license\n */\n\nimport {Platform, normalizePassiveListenerOptions} from '@angular/cdk/platform';\nimport {\n Directive,\n ElementRef,\n EventEmitter,\n Injectable,\n NgZone,\n OnDestroy,\n OnInit,\n Output,\n} from '@angular/core';\nimport {EMPTY, Observable, Subject} from 'rxjs';\n\n\n/** An event that is emitted when the autofill state of an input changes. */\nexport type AutofillEvent = {\n /** The element whose autofill state changes. */\n target: Element;\n /** Whether the element is currently autofilled. */\n isAutofilled: boolean;\n};\n\n\n/** Used to track info about currently monitored elements. */\ntype MonitoredElementInfo = {\n subject: Subject<AutofillEvent>;\n unlisten: () => void;\n};\n\n\n/** Options to pass to the animationstart listener. */\nconst listenerOptions = normalizePassiveListenerOptions({passive: true});\n\n\n/**\n * An injectable service that can be used to monitor the autofill state of an input.\n * Based on the following blog post:\n * https://medium.com/@brunn/detecting-autofilled-fields-in-javascript-aed598d25da7\n */\n@Injectable({providedIn: 'root'})\nexport class AutofillMonitor implements OnDestroy {\n private _monitoredElements = new Map<Element, MonitoredElementInfo>();\n\n constructor(private _platform: Platform, private _ngZone: NgZone) {}\n\n /**\n * Monitor for changes in the autofill state of the given input element.\n * @param element The element to monitor.\n * @return A stream of autofill state changes.\n */\n monitor(element: Element): Observable<AutofillEvent>;\n\n /**\n * Monitor for changes in the autofill state of the given input element.\n * @param element The element to monitor.\n * @return A stream of autofill state changes.\n */\n monitor(element: ElementRef<Element>): Observable<AutofillEvent>;\n\n monitor(elementOrRef: Element | ElementRef<Element>): Observable<AutofillEvent> {\n if (!this._platform.isBrowser) {\n return EMPTY;\n }\n\n const element = elementOrRef instanceof ElementRef ? elementOrRef.nativeElement : elementOrRef;\n const info = this._monitoredElements.get(element);\n\n if (info) {\n return info.subject.asObservable();\n }\n\n const result = new Subject<AutofillEvent>();\n const cssClass = 'cdk-text-field-autofilled';\n const listener = ((event: AnimationEvent) => {\n // Animation events fire on initial element render, we check for the presence of the autofill\n // CSS class to make sure this is a real change in state, not just the initial render before\n // we fire off events.\n if (event.animationName === 'cdk-text-field-autofill-start' &&\n !element.classList.contains(cssClass)) {\n element.classList.add(cssClass);\n this._ngZone.run(() => result.next({target: event.target as Element, isAutofilled: true}));\n } else if (event.animationName === 'cdk-text-field-autofill-end' &&\n element.classList.contains(cssClass)) {\n element.classList.remove(cssClass);\n this._ngZone.run(() => result.next({target: event.target as Element, isAutofilled: false}));\n }\n }) as EventListenerOrEventListenerObject;\n\n this._ngZone.runOutsideAngular(() => {\n element.addEventListener('animationstart', listener, listenerOptions);\n element.classList.add('cdk-text-field-autofill-monitored');\n });\n\n this._monitoredElements.set(element, {\n subject: result,\n unlisten: () => {\n element.removeEventListener('animationstart', listener, listenerOptions);\n }\n });\n\n return result.asObservable();\n }\n\n /**\n * Stop monitoring the autofill state of the given input element.\n * @param element The element to stop monitoring.\n */\n stopMonitoring(element: Element): void;\n\n /**\n * Stop monitoring the autofill state of the given input element.\n * @param element The element to stop monitoring.\n */\n stopMonitoring(element: ElementRef<Element>): void;\n\n stopMonitoring(elementOrRef: Element | ElementRef<Element>): void {\n const element = elementOrRef instanceof ElementRef ? elementOrRef.nativeElement : elementOrRef;\n const info = this._monitoredElements.get(element);\n\n if (info) {\n info.unlisten();\n info.subject.complete();\n element.classList.remove('cdk-text-field-autofill-monitored');\n element.classList.remove('cdk-text-field-autofilled');\n this._monitoredElements.delete(element);\n }\n }\n\n ngOnDestroy() {\n this._monitoredElements.forEach((_info, element) => this.stopMonitoring(element));\n }\n}\n\n\n/** A directive that can be used to monitor the autofill state of an input. */\n@Directive({\n selector: '[cdkAutofill]',\n})\nexport class CdkAutofill implements OnDestroy, OnInit {\n /** Emits when the autofill state of the element changes. */\n @Output() cdkAutofill: EventEmitter<AutofillEvent> = new EventEmitter<AutofillEvent>();\n\n constructor(private _elementRef: ElementRef<HTMLElement>,\n private _autofillMonitor: AutofillMonitor) {}\n\n ngOnInit() {\n this._autofillMonitor\n .monitor(this._elementRef)\n .subscribe(event => this.cdkAutofill.emit(event));\n }\n\n ngOnDestroy() {\n this._autofillMonitor.stopMonitoring(this._elementRef);\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AEuCA,MAAM,eAAe,GAAG,+BAA+B,CAAC,EAAC,OAAO,EAAE,IAAI,EAAC,CAAC,CAAC;;;;;;AASzE,AAAA,MAAa,eAAe,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AC,cAAc,CAAC;KAC1D;;;;IAED,iBAAiB,GAAnB;;KAEG;;;IAhPH,EAAA,IAAA,EAAC,SAAS,EAAV,IAAA,EAAA,CAAW;gBACT,QAAQ,EAAE,+BAA+B;gBACzC,QAAQ,EAAE,qBAAqB;gBAC/B,IAAI,EAAE;oBACJ,OAAO,EAAE,uBAAuB;;;oBAGhC,MAAM,EAAE,GAAG;oBACX,SAAS,EAAE,qBAAqB;iBACjC;aACF,EAAD,EAAA;;;;IAvBA,EAAA,IAAA,EAAE,UAAU,EAAZ;IAOA,EAAA,IAAA,EAAQ,QAAQ,EAAhB;IAFA,EAAA,IAAA,EAAE,MAAM,EAAR;;;IAuCA,OAAA,EAAA,CAAA,EAAA,IAAA,EAAG,KAAK,EAAR,IAAA,EAAA,CAAS,oBAAoB,EAA7B,EAAA,CAAA;IAQA,OAAA,EAAA,CAAA,EAAA,IAAA,EAAG,KAAK,EAAR,IAAA,EAAA,CAAS,oBAAoB,EAA7B,EAAA,CAAA;IAQA,OAAA,EAAA,CAAA,EAAA,IAAA,EAAG,KAAK,EAAR,IAAA,EAAA,CAAS,qBAAqB,EAA9B,EAAA,CAAA;;;;;;;ADpDA,MAAa,eAAe,CAA5B;;;IALA,EAAA,IAAA,EAAC,QAAQ,EAAT,IAAA,EAAA,CAAU;gBACR,YAAY,EAAE,CAAC,WAAW,EAAE,mBAAmB,CAAC;gBAChD,OAAO,EAAE,CAAC,cAAc,CAAC;gBACzB,OAAO,EAAE,CAAC,WAAW,EAAE,mBAAmB,CAAC;aAC5C,EAAD,EAAA;;;;;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"text-field.js","sources":["../../../src/cdk/text-field/text-field-module.ts","../../../src/cdk/text-field/autosize.ts","../../../src/cdk/text-field/autofill.ts"],"sourcesContent":["/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.io/license\n */\n\nimport {PlatformModule} from '@angular/cdk/platform';\nimport {NgModule} from '@angular/core';\nimport {CdkAutofill} from './autofill';\nimport {CdkTextareaAutosize} from './autosize';\n\n\n@NgModule({\n declarations: [CdkAutofill, CdkTextareaAutosize],\n imports: [PlatformModule],\n exports: [CdkAutofill, CdkTextareaAutosize],\n})\nexport class TextFieldModule {}\n","/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.io/license\n */\n\nimport {coerceBooleanProperty} from '@angular/cdk/coercion';\nimport {\n Directive,\n ElementRef,\n Input,\n AfterViewInit,\n DoCheck,\n OnDestroy,\n NgZone,\n} from '@angular/core';\nimport {Platform} from '@angular/cdk/platform';\nimport {auditTime, takeUntil} from 'rxjs/operators';\nimport {fromEvent, Subject} from 'rxjs';\n\n\n/** Directive to automatically resize a textarea to fit its content. */\n@Directive({\n selector: 'textarea[cdkTextareaAutosize]',\n exportAs: 'cdkTextareaAutosize',\n host: {\n 'class': 'cdk-textarea-autosize',\n // Textarea elements that have the directive applied should have a single row by default.\n // Browsers normally show two rows by default and therefore this limits the minRows binding.\n 'rows': '1',\n '(input)': '_noopInputHandler()',\n },\n})\nexport class CdkTextareaAutosize implements AfterViewInit, DoCheck, OnDestroy {\n /** Keep track of the previous textarea value to avoid resizing when the value hasn't changed. */\n private _previousValue?: string;\n private _initialHeight: string | null;\n private readonly _destroyed = new Subject<void>();\n\n private _minRows: number;\n private _maxRows: number;\n private _enabled: boolean = true;\n\n /**\n * Value of minRows as of last resize. If the minRows has decreased, the\n * height of the textarea needs to be recomputed to reflect the new minimum. The maxHeight\n * does not have the same problem because it does not affect the textarea's scrollHeight.\n */\n private _previousMinRows: number = -1;\n\n private _textareaElement: HTMLTextAreaElement;\n\n /** Minimum amount of rows in the textarea. */\n @Input('cdkAutosizeMinRows')\n get minRows(): number { return this._minRows; }\n set minRows(value: number) {\n this._minRows = value;\n this._setMinHeight();\n }\n\n /** Maximum amount of rows in the textarea. */\n @Input('cdkAutosizeMaxRows')\n get maxRows(): number { return this._maxRows; }\n set maxRows(value: number) {\n this._maxRows = value;\n this._setMaxHeight();\n }\n\n /** Whether autosizing is enabled or not */\n @Input('cdkTextareaAutosize')\n get enabled(): boolean { return this._enabled; }\n set enabled(value: boolean) {\n value = coerceBooleanProperty(value);\n\n // Only act if the actual value changed. This specifically helps to not run\n // resizeToFitContent too early (i.e. before ngAfterViewInit)\n if (this._enabled !== value) {\n (this._enabled = value) ? this.resizeToFitContent(true) : this.reset();\n }\n }\n\n /** Cached height of a textarea with a single row. */\n private _cachedLineHeight: number;\n\n constructor(\n private _elementRef: ElementRef<HTMLElement>,\n private _platform: Platform,\n private _ngZone: NgZone) {\n this._textareaElement = this._elementRef.nativeElement as HTMLTextAreaElement;\n }\n\n /** Sets the minimum height of the textarea as determined by minRows. */\n _setMinHeight(): void {\n const minHeight = this.minRows && this._cachedLineHeight ?\n `${this.minRows * this._cachedLineHeight}px` : null;\n\n if (minHeight) {\n this._textareaElement.style.minHeight = minHeight;\n }\n }\n\n /** Sets the maximum height of the textarea as determined by maxRows. */\n _setMaxHeight(): void {\n const maxHeight = this.maxRows && this._cachedLineHeight ?\n `${this.maxRows * this._cachedLineHeight}px` : null;\n\n if (maxHeight) {\n this._textareaElement.style.maxHeight = maxHeight;\n }\n }\n\n ngAfterViewInit() {\n if (this._platform.isBrowser) {\n // Remember the height which we started with in case autosizing is disabled\n this._initialHeight = this._textareaElement.style.height;\n\n this.resizeToFitContent();\n\n this._ngZone.runOutsideAngular(() => {\n fromEvent(window, 'resize')\n .pipe(auditTime(16), takeUntil(this._destroyed))\n .subscribe(() => this.resizeToFitContent(true));\n });\n }\n }\n\n ngOnDestroy() {\n this._destroyed.next();\n this._destroyed.complete();\n }\n\n /**\n * Cache the height of a single-row textarea if it has not already been cached.\n *\n * We need to know how large a single \"row\" of a textarea is in order to apply minRows and\n * maxRows. For the initial version, we will assume that the height of a single line in the\n * textarea does not ever change.\n */\n private _cacheTextareaLineHeight(): void {\n if (this._cachedLineHeight) {\n return;\n }\n\n // Use a clone element because we have to override some styles.\n let textareaClone = this._textareaElement.cloneNode(false) as HTMLTextAreaElement;\n textareaClone.rows = 1;\n\n // Use `position: absolute` so that this doesn't cause a browser layout and use\n // `visibility: hidden` so that nothing is rendered. Clear any other styles that\n // would affect the height.\n textareaClone.style.position = 'absolute';\n textareaClone.style.visibility = 'hidden';\n textareaClone.style.border = 'none';\n textareaClone.style.padding = '0';\n textareaClone.style.height = '';\n textareaClone.style.minHeight = '';\n textareaClone.style.maxHeight = '';\n\n // In Firefox it happens that textarea elements are always bigger than the specified amount\n // of rows. This is because Firefox tries to add extra space for the horizontal scrollbar.\n // As a workaround that removes the extra space for the scrollbar, we can just set overflow\n // to hidden. This ensures that there is no invalid calculation of the line height.\n // See Firefox bug report: https://bugzilla.mozilla.org/show_bug.cgi?id=33654\n textareaClone.style.overflow = 'hidden';\n\n this._textareaElement.parentNode!.appendChild(textareaClone);\n this._cachedLineHeight = textareaClone.clientHeight;\n this._textareaElement.parentNode!.removeChild(textareaClone);\n\n // Min and max heights have to be re-calculated if the cached line height changes\n this._setMinHeight();\n this._setMaxHeight();\n }\n\n ngDoCheck() {\n if (this._platform.isBrowser) {\n this.resizeToFitContent();\n }\n }\n\n /**\n * Resize the textarea to fit its content.\n * @param force Whether to force a height recalculation. By default the height will be\n * recalculated only if the value changed since the last call.\n */\n resizeToFitContent(force: boolean = false) {\n // If autosizing is disabled, just skip everything else\n if (!this._enabled) {\n return;\n }\n\n this._cacheTextareaLineHeight();\n\n // If we haven't determined the line-height yet, we know we're still hidden and there's no point\n // in checking the height of the textarea.\n if (!this._cachedLineHeight) {\n return;\n }\n\n const textarea = this._elementRef.nativeElement as HTMLTextAreaElement;\n const value = textarea.value;\n\n // Only resize if the value or minRows have changed since these calculations can be expensive.\n if (!force && this._minRows === this._previousMinRows && value === this._previousValue) {\n return;\n }\n\n const placeholderText = textarea.placeholder;\n\n // Reset the textarea height to auto in order to shrink back to its default size.\n // Also temporarily force overflow:hidden, so scroll bars do not interfere with calculations.\n // Long placeholders that are wider than the textarea width may lead to a bigger scrollHeight\n // value. To ensure that the scrollHeight is not bigger than the content, the placeholders\n // need to be removed temporarily.\n textarea.classList.add('cdk-textarea-autosize-measuring');\n textarea.placeholder = '';\n\n // The cdk-textarea-autosize-measuring class includes a 2px padding to workaround an issue with\n // Chrome, so we account for that extra space here by subtracting 4 (2px top + 2px bottom).\n const height = textarea.scrollHeight - 4;\n\n // Use the scrollHeight to know how large the textarea *would* be if fit its entire value.\n textarea.style.height = `${height}px`;\n textarea.classList.remove('cdk-textarea-autosize-measuring');\n textarea.placeholder = placeholderText;\n\n this._ngZone.runOutsideAngular(() => {\n if (typeof requestAnimationFrame !== 'undefined') {\n requestAnimationFrame(() => this._scrollToCaretPosition(textarea));\n } else {\n setTimeout(() => this._scrollToCaretPosition(textarea));\n }\n });\n\n this._previousValue = value;\n this._previousMinRows = this._minRows;\n }\n\n /**\n * Resets the textarea to it's original size\n */\n reset() {\n // Do not try to change the textarea, if the initialHeight has not been determined yet\n // This might potentially remove styles when reset() is called before ngAfterViewInit\n if (this._initialHeight === undefined) {\n return;\n }\n this._textareaElement.style.height = this._initialHeight;\n }\n\n _noopInputHandler() {\n // no-op handler that ensures we're running change detection on input events.\n }\n\n /**\n * Scrolls a textarea to the caret position. On Firefox resizing the textarea will\n * prevent it from scrolling to the caret position. We need to re-set the selection\n * in order for it to scroll to the proper position.\n */\n private _scrollToCaretPosition(textarea: HTMLTextAreaElement) {\n const {selectionStart, selectionEnd} = textarea;\n\n // IE will throw an \"Unspecified error\" if we try to set the selection range after the\n // element has been removed from the DOM. Assert that the directive hasn't been destroyed\n // between the time we requested the animation frame and when it was executed.\n // Also note that we have to assert that the textarea is focused before we set the\n // selection range. Setting the selection range on a non-focused textarea will cause\n // it to receive focus on IE and Edge.\n if (!this._destroyed.isStopped && document.activeElement === textarea) {\n textarea.setSelectionRange(selectionStart, selectionEnd);\n }\n }\n}\n","/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.io/license\n */\n\nimport {Platform, normalizePassiveListenerOptions} from '@angular/cdk/platform';\nimport {\n Directive,\n ElementRef,\n EventEmitter,\n Injectable,\n NgZone,\n OnDestroy,\n OnInit,\n Output,\n} from '@angular/core';\nimport {EMPTY, Observable, Subject} from 'rxjs';\n\n\n/** An event that is emitted when the autofill state of an input changes. */\nexport type AutofillEvent = {\n /** The element whose autofill state changes. */\n target: Element;\n /** Whether the element is currently autofilled. */\n isAutofilled: boolean;\n};\n\n\n/** Used to track info about currently monitored elements. */\ntype MonitoredElementInfo = {\n subject: Subject<AutofillEvent>;\n unlisten: () => void;\n};\n\n\n/** Options to pass to the animationstart listener. */\nconst listenerOptions = normalizePassiveListenerOptions({passive: true});\n\n\n/**\n * An injectable service that can be used to monitor the autofill state of an input.\n * Based on the following blog post:\n * https://medium.com/@brunn/detecting-autofilled-fields-in-javascript-aed598d25da7\n */\n@Injectable({providedIn: 'root'})\nexport class AutofillMonitor implements OnDestroy {\n private _monitoredElements = new Map<Element, MonitoredElementInfo>();\n\n constructor(private _platform: Platform, private _ngZone: NgZone) {}\n\n /**\n * Monitor for changes in the autofill state of the given input element.\n * @param element The element to monitor.\n * @return A stream of autofill state changes.\n */\n monitor(element: Element): Observable<AutofillEvent>;\n\n /**\n * Monitor for changes in the autofill state of the given input element.\n * @param element The element to monitor.\n * @return A stream of autofill state changes.\n */\n monitor(element: ElementRef<Element>): Observable<AutofillEvent>;\n\n monitor(elementOrRef: Element | ElementRef<Element>): Observable<AutofillEvent> {\n if (!this._platform.isBrowser) {\n return EMPTY;\n }\n\n const element = elementOrRef instanceof ElementRef ? elementOrRef.nativeElement : elementOrRef;\n const info = this._monitoredElements.get(element);\n\n if (info) {\n return info.subject.asObservable();\n }\n\n const result = new Subject<AutofillEvent>();\n const cssClass = 'cdk-text-field-autofilled';\n const listener = ((event: AnimationEvent) => {\n // Animation events fire on initial element render, we check for the presence of the autofill\n // CSS class to make sure this is a real change in state, not just the initial render before\n // we fire off events.\n if (event.animationName === 'cdk-text-field-autofill-start' &&\n !element.classList.contains(cssClass)) {\n element.classList.add(cssClass);\n this._ngZone.run(() => result.next({target: event.target as Element, isAutofilled: true}));\n } else if (event.animationName === 'cdk-text-field-autofill-end' &&\n element.classList.contains(cssClass)) {\n element.classList.remove(cssClass);\n this._ngZone.run(() => result.next({target: event.target as Element, isAutofilled: false}));\n }\n }) as EventListenerOrEventListenerObject;\n\n this._ngZone.runOutsideAngular(() => {\n element.addEventListener('animationstart', listener, listenerOptions);\n element.classList.add('cdk-text-field-autofill-monitored');\n });\n\n this._monitoredElements.set(element, {\n subject: result,\n unlisten: () => {\n element.removeEventListener('animationstart', listener, listenerOptions);\n }\n });\n\n return result.asObservable();\n }\n\n /**\n * Stop monitoring the autofill state of the given input element.\n * @param element The element to stop monitoring.\n */\n stopMonitoring(element: Element): void;\n\n /**\n * Stop monitoring the autofill state of the given input element.\n * @param element The element to stop monitoring.\n */\n stopMonitoring(element: ElementRef<Element>): void;\n\n stopMonitoring(elementOrRef: Element | ElementRef<Element>): void {\n const element = elementOrRef instanceof ElementRef ? elementOrRef.nativeElement : elementOrRef;\n const info = this._monitoredElements.get(element);\n\n if (info) {\n info.unlisten();\n info.subject.complete();\n element.classList.remove('cdk-text-field-autofill-monitored');\n element.classList.remove('cdk-text-field-autofilled');\n this._monitoredElements.delete(element);\n }\n }\n\n ngOnDestroy() {\n this._monitoredElements.forEach((_info, element) => this.stopMonitoring(element));\n }\n}\n\n\n/** A directive that can be used to monitor the autofill state of an input. */\n@Directive({\n selector: '[cdkAutofill]',\n})\nexport class CdkAutofill implements OnDestroy, OnInit {\n /** Emits when the autofill state of the element changes. */\n @Output() cdkAutofill: EventEmitter<AutofillEvent> = new EventEmitter<AutofillEvent>();\n\n constructor(private _elementRef: ElementRef<HTMLElement>,\n private _autofillMonitor: AutofillMonitor) {}\n\n ngOnInit() {\n this._autofillMonitor\n .monitor(this._elementRef)\n .subscribe(event => this.cdkAutofill.emit(event));\n }\n\n ngOnDestroy() {\n this._autofillMonitor.stopMonitoring(this._elementRef);\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AEuCA,MAAM,eAAe,GAAG,+BAA+B,CAAC,EAAC,OAAO,EAAE,IAAI,EAAC,CAAC,CAAxE;;;;;;AASA,AAAA,MAAa,eAAe,CAA5B;;;;;IAGE,WAAF,CAAsB,SAAmB,EAAU,OAAe,EAAlE;QAAsB,IAAtB,CAAA,SAA+B,GAAT,SAAS,CAAU;QAAU,IAAnD,CAAA,OAA0D,GAAP,OAAO,CAAQ;QAFxD,IAAV,CAAA,kBAA4B,GAAG,IAAI,GAAG,EAAiC,CAAC;KAEF;;;;;IAgBpE,OAAO,CAAC,YAA2C,EAArD;QACI,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,SAAS,EAAE;YAC7B,OAAO,KAAK,CAAC;SACd;;QAEL,MAAU,OAAO,GAAG,YAAY,YAAY,UAAU,GAAG,YAAY,CAAC,aAAa,GAAG,YAAY,CAAlG;;QACA,MAAU,IAAI,GAAG,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,OAAO,CAAC,CAArD;QAEI,IAAI,IAAI,EAAE;YACR,OAAO,IAAI,CAAC,OAAO,CAAC,YAAY,EAAE,CAAC;SACpC;;QAEL,MAAU,MAAM,GAAG,IAAI,OAAO,EAAiB,CAA/C;;QACA,MAAU,QAAQ,GAAG,2BAA2B,CAAhD;;QACA,MAAU,QAAQ,uBAAI,CAAC,KAAqB,KAA5C;;;;YAIM,IAAI,KAAK,CAAC,aAAa,KAAK,+BAA+B;gBACvD,CAAC,OAAO,CAAC,SAAS,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE;gBACzC,OAAO,CAAC,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;gBAChC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,MAAM,C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AAA,EAAC,QAAQ,EAAT,IAAA,EAAA,CAAU;gBACR,YAAY,EAAE,CAAC,WAAW,EAAE,mBAAmB,CAAC;gBAChD,OAAO,EAAE,CAAC,cAAc,CAAC;gBACzB,OAAO,EAAE,CAAC,WAAW,EAAE,mBAAmB,CAAC;aAC5C,EAAD,EAAA;;;;;;;;;;;;;;;"}
|
package/esm2015/tree.js
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import { SelectionModel } from '@angular/cdk/collections';
|
|
9
9
|
import { Observable, BehaviorSubject, of, Subject } from 'rxjs';
|
|
10
|
-
import { take, takeUntil } from 'rxjs/operators';
|
|
10
|
+
import { take, filter, takeUntil } from 'rxjs/operators';
|
|
11
11
|
import { Directive, TemplateRef, ViewContainerRef, ChangeDetectionStrategy, ChangeDetectorRef, Component, ContentChildren, ElementRef, Input, IterableDiffers, ViewChild, ViewEncapsulation, Optional, Renderer2, NgModule } from '@angular/core';
|
|
12
12
|
import { Directionality } from '@angular/cdk/bidi';
|
|
13
13
|
import { coerceNumberProperty, coerceBooleanProperty } from '@angular/cdk/coercion';
|
|
@@ -16,7 +16,7 @@ import { CommonModule } from '@angular/common';
|
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* @fileoverview added by tsickle
|
|
19
|
-
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
|
|
19
|
+
* @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
20
20
|
*/
|
|
21
21
|
/**
|
|
22
22
|
* Base tree control. It has basic toggle/expand/collapse operations on a single data node.
|
|
@@ -105,7 +105,7 @@ class BaseTreeControl {
|
|
|
105
105
|
|
|
106
106
|
/**
|
|
107
107
|
* @fileoverview added by tsickle
|
|
108
|
-
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
|
|
108
|
+
* @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
109
109
|
*/
|
|
110
110
|
/**
|
|
111
111
|
* Flat tree control. Able to expand/collapse a subtree recursively for flattened tree.
|
|
@@ -160,7 +160,7 @@ class FlatTreeControl extends BaseTreeControl {
|
|
|
160
160
|
|
|
161
161
|
/**
|
|
162
162
|
* @fileoverview added by tsickle
|
|
163
|
-
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
|
|
163
|
+
* @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
164
164
|
*/
|
|
165
165
|
/**
|
|
166
166
|
* Nested tree control. Able to expand/collapse a subtree recursively for NestedNode type.
|
|
@@ -202,6 +202,7 @@ class NestedTreeControl extends BaseTreeControl {
|
|
|
202
202
|
}
|
|
203
203
|
/**
|
|
204
204
|
* A helper function to get descendants recursively.
|
|
205
|
+
* @protected
|
|
205
206
|
* @param {?} descendants
|
|
206
207
|
* @param {?} dataNode
|
|
207
208
|
* @return {?}
|
|
@@ -214,7 +215,7 @@ class NestedTreeControl extends BaseTreeControl {
|
|
|
214
215
|
childrenNodes.forEach((child) => this._getDescendants(descendants, child));
|
|
215
216
|
}
|
|
216
217
|
else if (childrenNodes instanceof Observable) {
|
|
217
|
-
childrenNodes.pipe(take(1)).subscribe(children => {
|
|
218
|
+
childrenNodes.pipe(take(1), filter(Boolean)).subscribe(children => {
|
|
218
219
|
children.forEach((child) => this._getDescendants(descendants, child));
|
|
219
220
|
});
|
|
220
221
|
}
|
|
@@ -223,7 +224,12 @@ class NestedTreeControl extends BaseTreeControl {
|
|
|
223
224
|
|
|
224
225
|
/**
|
|
225
226
|
* @fileoverview added by tsickle
|
|
226
|
-
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
|
|
227
|
+
* @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
228
|
+
*/
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* @fileoverview added by tsickle
|
|
232
|
+
* @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
227
233
|
*/
|
|
228
234
|
/**
|
|
229
235
|
* Context provided to the tree node component.
|
|
@@ -266,7 +272,7 @@ CdkTreeNodeDef.ctorParameters = () => [
|
|
|
266
272
|
|
|
267
273
|
/**
|
|
268
274
|
* @fileoverview added by tsickle
|
|
269
|
-
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
|
|
275
|
+
* @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
270
276
|
*/
|
|
271
277
|
/**
|
|
272
278
|
* Outlet for nested CdkNode. Put `[cdkTreeNodeOutlet]` on a tag to place children dataNodes
|
|
@@ -292,7 +298,7 @@ CdkTreeNodeOutlet.ctorParameters = () => [
|
|
|
292
298
|
|
|
293
299
|
/**
|
|
294
300
|
* @fileoverview added by tsickle
|
|
295
|
-
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
|
|
301
|
+
* @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
296
302
|
*/
|
|
297
303
|
|
|
298
304
|
/**
|
|
@@ -338,7 +344,7 @@ function getTreeControlFunctionsMissingError() {
|
|
|
338
344
|
|
|
339
345
|
/**
|
|
340
346
|
* @fileoverview added by tsickle
|
|
341
|
-
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
|
|
347
|
+
* @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
342
348
|
*/
|
|
343
349
|
/**
|
|
344
350
|
* CDK tree component that connects with a data source to retrieve data of type `T` and renders
|
|
@@ -361,6 +367,8 @@ class CdkTree {
|
|
|
361
367
|
* Level of nodes
|
|
362
368
|
*/
|
|
363
369
|
this._levels = new Map();
|
|
370
|
+
// TODO(tinayuangao): Setup a listener for scrolling, emit the calculated view to viewChange.
|
|
371
|
+
// Remove the MAX_VALUE in viewChange
|
|
364
372
|
/**
|
|
365
373
|
* Stream containing the latest information on what rows are being displayed on screen.
|
|
366
374
|
* Can be used by the data source to as a heuristic of what data should be provided.
|
|
@@ -399,8 +407,8 @@ class CdkTree {
|
|
|
399
407
|
this._nodeOutlet.viewContainer.clear();
|
|
400
408
|
this._onDestroy.next();
|
|
401
409
|
this._onDestroy.complete();
|
|
402
|
-
if (this._dataSource && typeof (/** @type {?} */ (this._dataSource)).disconnect === 'function') {
|
|
403
|
-
(/** @type {?} */ (this.dataSource)).disconnect(this);
|
|
410
|
+
if (this._dataSource && typeof ((/** @type {?} */ (this._dataSource))).disconnect === 'function') {
|
|
411
|
+
((/** @type {?} */ (this.dataSource))).disconnect(this);
|
|
404
412
|
}
|
|
405
413
|
if (this._dataSubscription) {
|
|
406
414
|
this._dataSubscription.unsubscribe();
|
|
@@ -421,16 +429,19 @@ class CdkTree {
|
|
|
421
429
|
this._observeRenderChanges();
|
|
422
430
|
}
|
|
423
431
|
}
|
|
432
|
+
// TODO(tinayuangao): Work on keyboard traversal and actions, make sure it's working for RTL
|
|
433
|
+
// and nested trees.
|
|
424
434
|
/**
|
|
425
435
|
* Switch to the provided data source by resetting the data and unsubscribing from the current
|
|
426
436
|
* render change subscription if one exists. If the data source is null, interpret this by
|
|
427
437
|
* clearing the node outlet. Otherwise start listening for new data.
|
|
438
|
+
* @private
|
|
428
439
|
* @param {?} dataSource
|
|
429
440
|
* @return {?}
|
|
430
441
|
*/
|
|
431
442
|
_switchDataSource(dataSource) {
|
|
432
|
-
if (this._dataSource && typeof (/** @type {?} */ (this._dataSource)).disconnect === 'function') {
|
|
433
|
-
(/** @type {?} */ (this.dataSource)).disconnect(this);
|
|
443
|
+
if (this._dataSource && typeof ((/** @type {?} */ (this._dataSource))).disconnect === 'function') {
|
|
444
|
+
((/** @type {?} */ (this.dataSource))).disconnect(this);
|
|
434
445
|
}
|
|
435
446
|
if (this._dataSubscription) {
|
|
436
447
|
this._dataSubscription.unsubscribe();
|
|
@@ -447,6 +458,7 @@ class CdkTree {
|
|
|
447
458
|
}
|
|
448
459
|
/**
|
|
449
460
|
* Set up a subscription for the data provided by the data source.
|
|
461
|
+
* @private
|
|
450
462
|
* @return {?}
|
|
451
463
|
*/
|
|
452
464
|
_observeRenderChanges() {
|
|
@@ -454,8 +466,8 @@ class CdkTree {
|
|
|
454
466
|
let dataStream;
|
|
455
467
|
// Cannot use `instanceof DataSource` since the data source could be a literal with
|
|
456
468
|
// `connect` function and may not extends DataSource.
|
|
457
|
-
if (typeof (/** @type {?} */ (this._dataSource)).connect === 'function') {
|
|
458
|
-
dataStream = (/** @type {?} */ (this._dataSource)).connect(this);
|
|
469
|
+
if (typeof ((/** @type {?} */ (this._dataSource))).connect === 'function') {
|
|
470
|
+
dataStream = ((/** @type {?} */ (this._dataSource))).connect(this);
|
|
459
471
|
}
|
|
460
472
|
else if (this._dataSource instanceof Observable) {
|
|
461
473
|
dataStream = this._dataSource;
|
|
@@ -487,16 +499,16 @@ class CdkTree {
|
|
|
487
499
|
}
|
|
488
500
|
changes.forEachOperation((item, adjustedPreviousIndex, currentIndex) => {
|
|
489
501
|
if (item.previousIndex == null) {
|
|
490
|
-
this.insertNode(data[/** @type {?} */ (
|
|
502
|
+
this.insertNode(data[(/** @type {?} */ (currentIndex))], (/** @type {?} */ (currentIndex)), viewContainer, parentData);
|
|
491
503
|
}
|
|
492
504
|
else if (currentIndex == null) {
|
|
493
|
-
viewContainer.remove(/** @type {?} */ (
|
|
505
|
+
viewContainer.remove((/** @type {?} */ (adjustedPreviousIndex)));
|
|
494
506
|
this._levels.delete(item.item);
|
|
495
507
|
}
|
|
496
508
|
else {
|
|
497
509
|
/** @type {?} */
|
|
498
|
-
const view = viewContainer.get(/** @type {?} */ (
|
|
499
|
-
viewContainer.move(/** @type {?} */ (
|
|
510
|
+
const view = viewContainer.get((/** @type {?} */ (adjustedPreviousIndex)));
|
|
511
|
+
viewContainer.move((/** @type {?} */ (view)), currentIndex);
|
|
500
512
|
}
|
|
501
513
|
});
|
|
502
514
|
this._changeDetectorRef.detectChanges();
|
|
@@ -533,6 +545,7 @@ class CdkTree {
|
|
|
533
545
|
insertNode(nodeData, index, viewContainer, parentData) {
|
|
534
546
|
/** @type {?} */
|
|
535
547
|
const node = this._getNodeDef(nodeData, index);
|
|
548
|
+
// Node context that will be provided to created embedded view
|
|
536
549
|
/** @type {?} */
|
|
537
550
|
const context = new CdkTreeNodeOutletContext(nodeData);
|
|
538
551
|
// If the tree is flat tree, then use the `getLevel` function in flat tree control
|
|
@@ -541,12 +554,13 @@ class CdkTree {
|
|
|
541
554
|
context.level = this.treeControl.getLevel(nodeData);
|
|
542
555
|
}
|
|
543
556
|
else if (typeof parentData !== 'undefined' && this._levels.has(parentData)) {
|
|
544
|
-
context.level = /** @type {?} */ (
|
|
557
|
+
context.level = (/** @type {?} */ (this._levels.get(parentData))) + 1;
|
|
545
558
|
}
|
|
546
559
|
else {
|
|
547
560
|
context.level = 0;
|
|
548
561
|
}
|
|
549
562
|
this._levels.set(nodeData, context.level);
|
|
563
|
+
// Use default tree nodeOutlet, or nested node's nodeOutlet
|
|
550
564
|
/** @type {?} */
|
|
551
565
|
const container = viewContainer ? viewContainer : this._nodeOutlet.viewContainer;
|
|
552
566
|
container.createEmbeddedView(node.template, context, index);
|
|
@@ -603,7 +617,7 @@ class CdkTreeNode {
|
|
|
603
617
|
* and 'treeitem' if it's a leaf node.
|
|
604
618
|
*/
|
|
605
619
|
this.role = 'treeitem';
|
|
606
|
-
CdkTreeNode.mostRecentTreeNode = /** @type {?} */ (this);
|
|
620
|
+
CdkTreeNode.mostRecentTreeNode = (/** @type {?} */ (this));
|
|
607
621
|
}
|
|
608
622
|
/**
|
|
609
623
|
* The tree node's data.
|
|
@@ -650,6 +664,7 @@ class CdkTreeNode {
|
|
|
650
664
|
this._elementRef.nativeElement.focus();
|
|
651
665
|
}
|
|
652
666
|
/**
|
|
667
|
+
* @protected
|
|
653
668
|
* @return {?}
|
|
654
669
|
*/
|
|
655
670
|
_setRoleFromData() {
|
|
@@ -663,7 +678,7 @@ class CdkTreeNode {
|
|
|
663
678
|
/** @type {?} */
|
|
664
679
|
const childrenNodes = this._tree.treeControl.getChildren(this._data);
|
|
665
680
|
if (Array.isArray(childrenNodes)) {
|
|
666
|
-
this._setRoleFromChildren(/** @type {?} */ (childrenNodes));
|
|
681
|
+
this._setRoleFromChildren((/** @type {?} */ (childrenNodes)));
|
|
667
682
|
}
|
|
668
683
|
else if (childrenNodes instanceof Observable) {
|
|
669
684
|
childrenNodes.pipe(takeUntil(this._destroyed))
|
|
@@ -672,6 +687,7 @@ class CdkTreeNode {
|
|
|
672
687
|
}
|
|
673
688
|
}
|
|
674
689
|
/**
|
|
690
|
+
* @protected
|
|
675
691
|
* @param {?} children
|
|
676
692
|
* @return {?}
|
|
677
693
|
*/
|
|
@@ -707,7 +723,7 @@ CdkTreeNode.propDecorators = {
|
|
|
707
723
|
|
|
708
724
|
/**
|
|
709
725
|
* @fileoverview added by tsickle
|
|
710
|
-
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
|
|
726
|
+
* @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
711
727
|
*/
|
|
712
728
|
/**
|
|
713
729
|
* Nested node is a child of `<cdk-tree>`. It works with nested tree.
|
|
@@ -715,19 +731,19 @@ CdkTreeNode.propDecorators = {
|
|
|
715
731
|
* be added in the `cdkTreeNodeOutlet` in tree node template.
|
|
716
732
|
* For example:
|
|
717
733
|
* ```html
|
|
718
|
-
* <cdk-
|
|
734
|
+
* <cdk-nested-tree-node>
|
|
719
735
|
* {{node.name}}
|
|
720
736
|
* <ng-template cdkTreeNodeOutlet></ng-template>
|
|
721
|
-
* </cdk-tree-node>
|
|
737
|
+
* </cdk-nested-tree-node>
|
|
722
738
|
* ```
|
|
723
739
|
* The children of node will be automatically added to `cdkTreeNodeOutlet`, the result dom will be
|
|
724
740
|
* like this:
|
|
725
741
|
* ```html
|
|
726
742
|
* <cdk-nested-tree-node>
|
|
727
743
|
* {{node.name}}
|
|
728
|
-
* <cdk-nested-tree-node>{{child1.name}}</cdk-tree-node>
|
|
729
|
-
* <cdk-nested-tree-node>{{child2.name}}</cdk-tree-node>
|
|
730
|
-
* </cdk-tree-node>
|
|
744
|
+
* <cdk-nested-tree-node>{{child1.name}}</cdk-nested-tree-node>
|
|
745
|
+
* <cdk-nested-tree-node>{{child2.name}}</cdk-nested-tree-node>
|
|
746
|
+
* </cdk-nested-tree-node>
|
|
731
747
|
* ```
|
|
732
748
|
* @template T
|
|
733
749
|
*/
|
|
@@ -754,7 +770,7 @@ class CdkNestedTreeNode extends CdkTreeNode {
|
|
|
754
770
|
/** @type {?} */
|
|
755
771
|
const childrenNodes = this._tree.treeControl.getChildren(this.data);
|
|
756
772
|
if (Array.isArray(childrenNodes)) {
|
|
757
|
-
this.updateChildrenNodes(/** @type {?} */ (childrenNodes));
|
|
773
|
+
this.updateChildrenNodes((/** @type {?} */ (childrenNodes)));
|
|
758
774
|
}
|
|
759
775
|
else if (childrenNodes instanceof Observable) {
|
|
760
776
|
childrenNodes.pipe(takeUntil(this._destroyed))
|
|
@@ -772,6 +788,7 @@ class CdkNestedTreeNode extends CdkTreeNode {
|
|
|
772
788
|
}
|
|
773
789
|
/**
|
|
774
790
|
* Add children dataNodes to the NodeOutlet
|
|
791
|
+
* @protected
|
|
775
792
|
* @param {?=} children
|
|
776
793
|
* @return {?}
|
|
777
794
|
*/
|
|
@@ -791,6 +808,7 @@ class CdkNestedTreeNode extends CdkTreeNode {
|
|
|
791
808
|
}
|
|
792
809
|
/**
|
|
793
810
|
* Clear the children dataNodes.
|
|
811
|
+
* @protected
|
|
794
812
|
* @return {?}
|
|
795
813
|
*/
|
|
796
814
|
_clear() {
|
|
@@ -824,11 +842,12 @@ CdkNestedTreeNode.propDecorators = {
|
|
|
824
842
|
|
|
825
843
|
/**
|
|
826
844
|
* @fileoverview added by tsickle
|
|
827
|
-
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
|
|
845
|
+
* @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
828
846
|
*/
|
|
829
|
-
/**
|
|
847
|
+
/**
|
|
830
848
|
* Regex used to split a string on its CSS units.
|
|
831
|
-
|
|
849
|
+
* @type {?}
|
|
850
|
+
*/
|
|
832
851
|
const cssUnitPattern = /([A-Za-z%]+)$/;
|
|
833
852
|
/**
|
|
834
853
|
* Indent for the children tree dataNodes.
|
|
@@ -952,7 +971,7 @@ CdkTreeNodePadding.propDecorators = {
|
|
|
952
971
|
|
|
953
972
|
/**
|
|
954
973
|
* @fileoverview added by tsickle
|
|
955
|
-
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
|
|
974
|
+
* @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
956
975
|
*/
|
|
957
976
|
/**
|
|
958
977
|
* Node toggle to expand/collapse the node.
|
|
@@ -1008,7 +1027,7 @@ CdkTreeNodeToggle.propDecorators = {
|
|
|
1008
1027
|
|
|
1009
1028
|
/**
|
|
1010
1029
|
* @fileoverview added by tsickle
|
|
1011
|
-
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
|
|
1030
|
+
* @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
1012
1031
|
*/
|
|
1013
1032
|
/** @type {?} */
|
|
1014
1033
|
const EXPORTED_DECLARATIONS = [
|
|
@@ -1033,12 +1052,12 @@ CdkTreeModule.decorators = [
|
|
|
1033
1052
|
|
|
1034
1053
|
/**
|
|
1035
1054
|
* @fileoverview added by tsickle
|
|
1036
|
-
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
|
|
1055
|
+
* @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
1037
1056
|
*/
|
|
1038
1057
|
|
|
1039
1058
|
/**
|
|
1040
1059
|
* @fileoverview added by tsickle
|
|
1041
|
-
* @suppress {checkTypes,extraRequire,uselessCode} checked by tsc
|
|
1060
|
+
* @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
|
|
1042
1061
|
*/
|
|
1043
1062
|
|
|
1044
1063
|
export { BaseTreeControl, FlatTreeControl, NestedTreeControl, CdkNestedTreeNode, CdkTreeNodeOutletContext, CdkTreeNodeDef, CdkTreeNodePadding, CdkTreeNodeOutlet, CdkTree, CdkTreeNode, getTreeNoValidDataSourceError, getTreeMultipleDefaultNodeDefsError, getTreeMissingMatchingNodeDefError, getTreeControlMissingError, getTreeControlFunctionsMissingError, CdkTreeModule, CdkTreeNodeToggle };
|