@angular/cdk 21.0.0-next.9 → 21.0.0-rc.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/_adev_assets/cdk_drag_drop.json +13 -12
- package/_adev_assets/cdk_testing.json +9 -9
- package/_adev_assets/cdk_testing_protractor.json +1 -1
- package/_adev_assets/cdk_testing_selenium_webdriver.json +1 -1
- package/_adev_assets/cdk_testing_testbed.json +1 -1
- package/fesm2022/_a11y-module-chunk.mjs +755 -869
- package/fesm2022/_a11y-module-chunk.mjs.map +1 -1
- package/fesm2022/_activedescendant-key-manager-chunk.mjs +8 -8
- package/fesm2022/_activedescendant-key-manager-chunk.mjs.map +1 -1
- package/fesm2022/_array-chunk.mjs +1 -1
- package/fesm2022/_array-chunk.mjs.map +1 -1
- package/fesm2022/_breakpoints-observer-chunk.mjs +149 -152
- package/fesm2022/_breakpoints-observer-chunk.mjs.map +1 -1
- package/fesm2022/_css-pixel-value-chunk.mjs +4 -5
- package/fesm2022/_css-pixel-value-chunk.mjs.map +1 -1
- package/fesm2022/_data-source-chunk.mjs +2 -8
- package/fesm2022/_data-source-chunk.mjs.map +1 -1
- package/fesm2022/_directionality-chunk.mjs +54 -54
- package/fesm2022/_directionality-chunk.mjs.map +1 -1
- package/fesm2022/_dispose-view-repeater-strategy-chunk.mjs +25 -36
- package/fesm2022/_dispose-view-repeater-strategy-chunk.mjs.map +1 -1
- package/fesm2022/_element-chunk.mjs +6 -17
- package/fesm2022/_element-chunk.mjs.map +1 -1
- package/fesm2022/_fake-event-detection-chunk.mjs +3 -17
- package/fesm2022/_fake-event-detection-chunk.mjs.map +1 -1
- package/fesm2022/_focus-key-manager-chunk.mjs +10 -14
- package/fesm2022/_focus-key-manager-chunk.mjs.map +1 -1
- package/fesm2022/_focus-monitor-chunk.mjs +376 -566
- package/fesm2022/_focus-monitor-chunk.mjs.map +1 -1
- package/fesm2022/_id-generator-chunk.mjs +36 -27
- package/fesm2022/_id-generator-chunk.mjs.map +1 -1
- package/fesm2022/_keycodes-chunk.mjs +9 -9
- package/fesm2022/_keycodes-chunk.mjs.map +1 -1
- package/fesm2022/_list-key-manager-chunk.mjs +248 -336
- package/fesm2022/_list-key-manager-chunk.mjs.map +1 -1
- package/fesm2022/_overlay-module-chunk.mjs +2534 -2948
- package/fesm2022/_overlay-module-chunk.mjs.map +1 -1
- package/fesm2022/_passive-listeners-chunk.mjs +10 -22
- package/fesm2022/_passive-listeners-chunk.mjs.map +1 -1
- package/fesm2022/_platform-chunk.mjs +42 -65
- package/fesm2022/_platform-chunk.mjs.map +1 -1
- package/fesm2022/_recycle-view-repeater-strategy-chunk.mjs +78 -134
- package/fesm2022/_recycle-view-repeater-strategy-chunk.mjs.map +1 -1
- package/fesm2022/_scrolling-chunk.mjs +44 -85
- package/fesm2022/_scrolling-chunk.mjs.map +1 -1
- package/fesm2022/_selection-model-chunk.mjs +138 -209
- package/fesm2022/_selection-model-chunk.mjs.map +1 -1
- package/fesm2022/_shadow-dom-chunk.mjs +21 -35
- package/fesm2022/_shadow-dom-chunk.mjs.map +1 -1
- package/fesm2022/_style-loader-chunk.mjs +50 -37
- package/fesm2022/_style-loader-chunk.mjs.map +1 -1
- package/fesm2022/_test-environment-chunk.mjs +2 -14
- package/fesm2022/_test-environment-chunk.mjs.map +1 -1
- package/fesm2022/_tree-key-manager-chunk.mjs +229 -308
- package/fesm2022/_tree-key-manager-chunk.mjs.map +1 -1
- package/fesm2022/_typeahead-chunk.mjs +52 -74
- package/fesm2022/_typeahead-chunk.mjs.map +1 -1
- package/fesm2022/_unique-selection-dispatcher-chunk.mjs +43 -40
- package/fesm2022/_unique-selection-dispatcher-chunk.mjs.map +1 -1
- package/fesm2022/a11y.mjs +351 -449
- package/fesm2022/a11y.mjs.map +1 -1
- package/fesm2022/accordion.mjs +254 -192
- package/fesm2022/accordion.mjs.map +1 -1
- package/fesm2022/bidi.mjs +121 -64
- package/fesm2022/bidi.mjs.map +1 -1
- package/fesm2022/cdk.mjs +1 -2
- package/fesm2022/cdk.mjs.map +1 -1
- package/fesm2022/clipboard.mjs +208 -186
- package/fesm2022/clipboard.mjs.map +1 -1
- package/fesm2022/coercion-private.mjs +4 -8
- package/fesm2022/coercion-private.mjs.map +1 -1
- package/fesm2022/coercion.mjs +11 -29
- package/fesm2022/coercion.mjs.map +1 -1
- package/fesm2022/dialog.mjs +660 -808
- package/fesm2022/dialog.mjs.map +1 -1
- package/fesm2022/drag-drop.mjs +3347 -4286
- package/fesm2022/drag-drop.mjs.map +1 -1
- package/fesm2022/keycodes.mjs +4 -8
- package/fesm2022/keycodes.mjs.map +1 -1
- package/fesm2022/layout.mjs +44 -26
- package/fesm2022/layout.mjs.map +1 -1
- package/fesm2022/listbox.mjs +841 -895
- package/fesm2022/listbox.mjs.map +1 -1
- package/fesm2022/menu.mjs +1942 -1858
- package/fesm2022/menu.mjs.map +1 -1
- package/fesm2022/observers-private.mjs +88 -106
- package/fesm2022/observers-private.mjs.map +1 -1
- package/fesm2022/observers.mjs +262 -184
- package/fesm2022/observers.mjs.map +1 -1
- package/fesm2022/overlay.mjs +72 -68
- package/fesm2022/overlay.mjs.map +1 -1
- package/fesm2022/platform.mjs +43 -54
- package/fesm2022/platform.mjs.map +1 -1
- package/fesm2022/portal.mjs +402 -560
- package/fesm2022/portal.mjs.map +1 -1
- package/fesm2022/private.mjs +38 -10
- package/fesm2022/private.mjs.map +1 -1
- package/fesm2022/scrolling.mjs +1323 -1400
- package/fesm2022/scrolling.mjs.map +1 -1
- package/fesm2022/stepper.mjs +758 -590
- package/fesm2022/stepper.mjs.map +1 -1
- package/fesm2022/table.mjs +2327 -2319
- package/fesm2022/table.mjs.map +1 -1
- package/fesm2022/testing-selenium-webdriver.mjs +252 -325
- package/fesm2022/testing-selenium-webdriver.mjs.map +1 -1
- package/fesm2022/testing-testbed.mjs +592 -709
- package/fesm2022/testing-testbed.mjs.map +1 -1
- package/fesm2022/testing.mjs +368 -889
- package/fesm2022/testing.mjs.map +1 -1
- package/fesm2022/text-field.mjs +459 -388
- package/fesm2022/text-field.mjs.map +1 -1
- package/fesm2022/tree.mjs +1483 -1731
- package/fesm2022/tree.mjs.map +1 -1
- package/overlay/_index.scss +28 -0
- package/overlay-prebuilt.css +1 -1
- package/package.json +1 -1
- package/schematics/ng-add/index.js +1 -1
- package/types/_overlay-module-chunk.d.ts +59 -7
- package/types/_portal-directives-chunk.d.ts +2 -18
- package/types/accordion.d.ts +3 -1
- package/types/dialog.d.ts +1 -1
- package/types/overlay.d.ts +6 -2
- package/types/portal.d.ts +1 -1
package/fesm2022/observers.mjs
CHANGED
|
@@ -4,207 +4,285 @@ import { Observable, Subject } from 'rxjs';
|
|
|
4
4
|
import { map, filter, debounceTime } from 'rxjs/operators';
|
|
5
5
|
import { coerceNumberProperty, coerceElement } from './_element-chunk.mjs';
|
|
6
6
|
|
|
7
|
-
// Angular may add, remove, or edit comment nodes during change detection. We don't care about
|
|
8
|
-
// these changes because they don't affect the user-preceived content, and worse it can cause
|
|
9
|
-
// infinite change detection cycles where the change detection updates a comment, triggering the
|
|
10
|
-
// MutationObserver, triggering another change detection and kicking the cycle off again.
|
|
11
7
|
function shouldIgnoreRecord(record) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
if (record.type === 'characterData' && record.target instanceof Comment) {
|
|
9
|
+
return true;
|
|
10
|
+
}
|
|
11
|
+
if (record.type === 'childList') {
|
|
12
|
+
for (let i = 0; i < record.addedNodes.length; i++) {
|
|
13
|
+
if (!(record.addedNodes[i] instanceof Comment)) {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
15
16
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
return false;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
for (let i = 0; i < record.removedNodes.length; i++) {
|
|
24
|
-
if (!(record.removedNodes[i] instanceof Comment)) {
|
|
25
|
-
return false;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
return true;
|
|
17
|
+
for (let i = 0; i < record.removedNodes.length; i++) {
|
|
18
|
+
if (!(record.removedNodes[i] instanceof Comment)) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
29
21
|
}
|
|
30
|
-
|
|
31
|
-
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
return false;
|
|
32
25
|
}
|
|
33
|
-
/**
|
|
34
|
-
* Factory that creates a new MutationObserver and allows us to stub it out in unit tests.
|
|
35
|
-
* @docs-private
|
|
36
|
-
*/
|
|
37
26
|
class MutationObserverFactory {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
27
|
+
create(callback) {
|
|
28
|
+
return typeof MutationObserver === 'undefined' ? null : new MutationObserver(callback);
|
|
29
|
+
}
|
|
30
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
31
|
+
minVersion: "12.0.0",
|
|
32
|
+
version: "20.2.0-next.2",
|
|
33
|
+
ngImport: i0,
|
|
34
|
+
type: MutationObserverFactory,
|
|
35
|
+
deps: [],
|
|
36
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
37
|
+
});
|
|
38
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({
|
|
39
|
+
minVersion: "12.0.0",
|
|
40
|
+
version: "20.2.0-next.2",
|
|
41
|
+
ngImport: i0,
|
|
42
|
+
type: MutationObserverFactory,
|
|
43
|
+
providedIn: 'root'
|
|
44
|
+
});
|
|
43
45
|
}
|
|
44
|
-
i0.ɵɵngDeclareClassMetadata({
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
47
|
+
minVersion: "12.0.0",
|
|
48
|
+
version: "20.2.0-next.2",
|
|
49
|
+
ngImport: i0,
|
|
50
|
+
type: MutationObserverFactory,
|
|
51
|
+
decorators: [{
|
|
52
|
+
type: Injectable,
|
|
53
|
+
args: [{
|
|
54
|
+
providedIn: 'root'
|
|
55
|
+
}]
|
|
56
|
+
}]
|
|
57
|
+
});
|
|
49
58
|
class ContentObserver {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
.subscribe(records => {
|
|
65
|
-
this._ngZone.run(() => {
|
|
66
|
-
observer.next(records);
|
|
67
|
-
});
|
|
68
|
-
});
|
|
69
|
-
return () => {
|
|
70
|
-
subscription.unsubscribe();
|
|
71
|
-
this._unobserveElement(element);
|
|
72
|
-
};
|
|
59
|
+
_mutationObserverFactory = inject(MutationObserverFactory);
|
|
60
|
+
_observedElements = new Map();
|
|
61
|
+
_ngZone = inject(NgZone);
|
|
62
|
+
constructor() {}
|
|
63
|
+
ngOnDestroy() {
|
|
64
|
+
this._observedElements.forEach((_, element) => this._cleanupObserver(element));
|
|
65
|
+
}
|
|
66
|
+
observe(elementOrRef) {
|
|
67
|
+
const element = coerceElement(elementOrRef);
|
|
68
|
+
return new Observable(observer => {
|
|
69
|
+
const stream = this._observeElement(element);
|
|
70
|
+
const subscription = stream.pipe(map(records => records.filter(record => !shouldIgnoreRecord(record))), filter(records => !!records.length)).subscribe(records => {
|
|
71
|
+
this._ngZone.run(() => {
|
|
72
|
+
observer.next(records);
|
|
73
73
|
});
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
}
|
|
93
|
-
else {
|
|
94
|
-
this._observedElements.get(element).count++;
|
|
95
|
-
}
|
|
96
|
-
return this._observedElements.get(element).stream;
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* Un-observes the given element and cleans up the underlying MutationObserver if nobody else is
|
|
101
|
-
* observing this element.
|
|
102
|
-
*/
|
|
103
|
-
_unobserveElement(element) {
|
|
104
|
-
if (this._observedElements.has(element)) {
|
|
105
|
-
this._observedElements.get(element).count--;
|
|
106
|
-
if (!this._observedElements.get(element).count) {
|
|
107
|
-
this._cleanupObserver(element);
|
|
108
|
-
}
|
|
74
|
+
});
|
|
75
|
+
return () => {
|
|
76
|
+
subscription.unsubscribe();
|
|
77
|
+
this._unobserveElement(element);
|
|
78
|
+
};
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
_observeElement(element) {
|
|
82
|
+
return this._ngZone.runOutsideAngular(() => {
|
|
83
|
+
if (!this._observedElements.has(element)) {
|
|
84
|
+
const stream = new Subject();
|
|
85
|
+
const observer = this._mutationObserverFactory.create(mutations => stream.next(mutations));
|
|
86
|
+
if (observer) {
|
|
87
|
+
observer.observe(element, {
|
|
88
|
+
characterData: true,
|
|
89
|
+
childList: true,
|
|
90
|
+
subtree: true
|
|
91
|
+
});
|
|
109
92
|
}
|
|
93
|
+
this._observedElements.set(element, {
|
|
94
|
+
observer,
|
|
95
|
+
stream,
|
|
96
|
+
count: 1
|
|
97
|
+
});
|
|
98
|
+
} else {
|
|
99
|
+
this._observedElements.get(element).count++;
|
|
100
|
+
}
|
|
101
|
+
return this._observedElements.get(element).stream;
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
_unobserveElement(element) {
|
|
105
|
+
if (this._observedElements.has(element)) {
|
|
106
|
+
this._observedElements.get(element).count--;
|
|
107
|
+
if (!this._observedElements.get(element).count) {
|
|
108
|
+
this._cleanupObserver(element);
|
|
109
|
+
}
|
|
110
110
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
111
|
+
}
|
|
112
|
+
_cleanupObserver(element) {
|
|
113
|
+
if (this._observedElements.has(element)) {
|
|
114
|
+
const {
|
|
115
|
+
observer,
|
|
116
|
+
stream
|
|
117
|
+
} = this._observedElements.get(element);
|
|
118
|
+
if (observer) {
|
|
119
|
+
observer.disconnect();
|
|
120
|
+
}
|
|
121
|
+
stream.complete();
|
|
122
|
+
this._observedElements.delete(element);
|
|
121
123
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
+
}
|
|
125
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
126
|
+
minVersion: "12.0.0",
|
|
127
|
+
version: "20.2.0-next.2",
|
|
128
|
+
ngImport: i0,
|
|
129
|
+
type: ContentObserver,
|
|
130
|
+
deps: [],
|
|
131
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
132
|
+
});
|
|
133
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({
|
|
134
|
+
minVersion: "12.0.0",
|
|
135
|
+
version: "20.2.0-next.2",
|
|
136
|
+
ngImport: i0,
|
|
137
|
+
type: ContentObserver,
|
|
138
|
+
providedIn: 'root'
|
|
139
|
+
});
|
|
124
140
|
}
|
|
125
|
-
i0.ɵɵngDeclareClassMetadata({
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
141
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
142
|
+
minVersion: "12.0.0",
|
|
143
|
+
version: "20.2.0-next.2",
|
|
144
|
+
ngImport: i0,
|
|
145
|
+
type: ContentObserver,
|
|
146
|
+
decorators: [{
|
|
147
|
+
type: Injectable,
|
|
148
|
+
args: [{
|
|
149
|
+
providedIn: 'root'
|
|
150
|
+
}]
|
|
151
|
+
}],
|
|
152
|
+
ctorParameters: () => []
|
|
153
|
+
});
|
|
133
154
|
class CdkObserveContent {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
_debounce;
|
|
159
|
-
_currentSubscription = null;
|
|
160
|
-
constructor() { }
|
|
161
|
-
ngAfterContentInit() {
|
|
162
|
-
if (!this._currentSubscription && !this.disabled) {
|
|
163
|
-
this._subscribe();
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
ngOnDestroy() {
|
|
167
|
-
this._unsubscribe();
|
|
168
|
-
}
|
|
169
|
-
_subscribe() {
|
|
170
|
-
this._unsubscribe();
|
|
171
|
-
const stream = this._contentObserver.observe(this._elementRef);
|
|
172
|
-
this._currentSubscription = (this.debounce ? stream.pipe(debounceTime(this.debounce)) : stream).subscribe(this.event);
|
|
173
|
-
}
|
|
174
|
-
_unsubscribe() {
|
|
175
|
-
this._currentSubscription?.unsubscribe();
|
|
155
|
+
_contentObserver = inject(ContentObserver);
|
|
156
|
+
_elementRef = inject(ElementRef);
|
|
157
|
+
event = new EventEmitter();
|
|
158
|
+
get disabled() {
|
|
159
|
+
return this._disabled;
|
|
160
|
+
}
|
|
161
|
+
set disabled(value) {
|
|
162
|
+
this._disabled = value;
|
|
163
|
+
this._disabled ? this._unsubscribe() : this._subscribe();
|
|
164
|
+
}
|
|
165
|
+
_disabled = false;
|
|
166
|
+
get debounce() {
|
|
167
|
+
return this._debounce;
|
|
168
|
+
}
|
|
169
|
+
set debounce(value) {
|
|
170
|
+
this._debounce = coerceNumberProperty(value);
|
|
171
|
+
this._subscribe();
|
|
172
|
+
}
|
|
173
|
+
_debounce;
|
|
174
|
+
_currentSubscription = null;
|
|
175
|
+
constructor() {}
|
|
176
|
+
ngAfterContentInit() {
|
|
177
|
+
if (!this._currentSubscription && !this.disabled) {
|
|
178
|
+
this._subscribe();
|
|
176
179
|
}
|
|
177
|
-
|
|
178
|
-
|
|
180
|
+
}
|
|
181
|
+
ngOnDestroy() {
|
|
182
|
+
this._unsubscribe();
|
|
183
|
+
}
|
|
184
|
+
_subscribe() {
|
|
185
|
+
this._unsubscribe();
|
|
186
|
+
const stream = this._contentObserver.observe(this._elementRef);
|
|
187
|
+
this._currentSubscription = (this.debounce ? stream.pipe(debounceTime(this.debounce)) : stream).subscribe(this.event);
|
|
188
|
+
}
|
|
189
|
+
_unsubscribe() {
|
|
190
|
+
this._currentSubscription?.unsubscribe();
|
|
191
|
+
}
|
|
192
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
193
|
+
minVersion: "12.0.0",
|
|
194
|
+
version: "20.2.0-next.2",
|
|
195
|
+
ngImport: i0,
|
|
196
|
+
type: CdkObserveContent,
|
|
197
|
+
deps: [],
|
|
198
|
+
target: i0.ɵɵFactoryTarget.Directive
|
|
199
|
+
});
|
|
200
|
+
static ɵdir = i0.ɵɵngDeclareDirective({
|
|
201
|
+
minVersion: "16.1.0",
|
|
202
|
+
version: "20.2.0-next.2",
|
|
203
|
+
type: CdkObserveContent,
|
|
204
|
+
isStandalone: true,
|
|
205
|
+
selector: "[cdkObserveContent]",
|
|
206
|
+
inputs: {
|
|
207
|
+
disabled: ["cdkObserveContentDisabled", "disabled", booleanAttribute],
|
|
208
|
+
debounce: "debounce"
|
|
209
|
+
},
|
|
210
|
+
outputs: {
|
|
211
|
+
event: "cdkObserveContent"
|
|
212
|
+
},
|
|
213
|
+
exportAs: ["cdkObserveContent"],
|
|
214
|
+
ngImport: i0
|
|
215
|
+
});
|
|
179
216
|
}
|
|
180
|
-
i0.ɵɵngDeclareClassMetadata({
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
217
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
218
|
+
minVersion: "12.0.0",
|
|
219
|
+
version: "20.2.0-next.2",
|
|
220
|
+
ngImport: i0,
|
|
221
|
+
type: CdkObserveContent,
|
|
222
|
+
decorators: [{
|
|
223
|
+
type: Directive,
|
|
224
|
+
args: [{
|
|
225
|
+
selector: '[cdkObserveContent]',
|
|
226
|
+
exportAs: 'cdkObserveContent'
|
|
227
|
+
}]
|
|
228
|
+
}],
|
|
229
|
+
ctorParameters: () => [],
|
|
230
|
+
propDecorators: {
|
|
231
|
+
event: [{
|
|
232
|
+
type: Output,
|
|
233
|
+
args: ['cdkObserveContent']
|
|
234
|
+
}],
|
|
235
|
+
disabled: [{
|
|
236
|
+
type: Input,
|
|
237
|
+
args: [{
|
|
238
|
+
alias: 'cdkObserveContentDisabled',
|
|
239
|
+
transform: booleanAttribute
|
|
240
|
+
}]
|
|
241
|
+
}],
|
|
242
|
+
debounce: [{
|
|
243
|
+
type: Input
|
|
244
|
+
}]
|
|
245
|
+
}
|
|
246
|
+
});
|
|
195
247
|
class ObserversModule {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
248
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
249
|
+
minVersion: "12.0.0",
|
|
250
|
+
version: "20.2.0-next.2",
|
|
251
|
+
ngImport: i0,
|
|
252
|
+
type: ObserversModule,
|
|
253
|
+
deps: [],
|
|
254
|
+
target: i0.ɵɵFactoryTarget.NgModule
|
|
255
|
+
});
|
|
256
|
+
static ɵmod = i0.ɵɵngDeclareNgModule({
|
|
257
|
+
minVersion: "14.0.0",
|
|
258
|
+
version: "20.2.0-next.2",
|
|
259
|
+
ngImport: i0,
|
|
260
|
+
type: ObserversModule,
|
|
261
|
+
imports: [CdkObserveContent],
|
|
262
|
+
exports: [CdkObserveContent]
|
|
263
|
+
});
|
|
264
|
+
static ɵinj = i0.ɵɵngDeclareInjector({
|
|
265
|
+
minVersion: "12.0.0",
|
|
266
|
+
version: "20.2.0-next.2",
|
|
267
|
+
ngImport: i0,
|
|
268
|
+
type: ObserversModule,
|
|
269
|
+
providers: [MutationObserverFactory]
|
|
270
|
+
});
|
|
199
271
|
}
|
|
200
|
-
i0.ɵɵngDeclareClassMetadata({
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
272
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
273
|
+
minVersion: "12.0.0",
|
|
274
|
+
version: "20.2.0-next.2",
|
|
275
|
+
ngImport: i0,
|
|
276
|
+
type: ObserversModule,
|
|
277
|
+
decorators: [{
|
|
278
|
+
type: NgModule,
|
|
279
|
+
args: [{
|
|
280
|
+
imports: [CdkObserveContent],
|
|
281
|
+
exports: [CdkObserveContent],
|
|
282
|
+
providers: [MutationObserverFactory]
|
|
283
|
+
}]
|
|
284
|
+
}]
|
|
285
|
+
});
|
|
208
286
|
|
|
209
287
|
export { CdkObserveContent, ContentObserver, MutationObserverFactory, ObserversModule };
|
|
210
288
|
//# sourceMappingURL=observers.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"observers.mjs","sources":["../../../../../darwin_arm64-fastbuild-ST-199a4f3c4e20/bin/src/cdk/observers/observe-content.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.dev/license\n */\n\nimport {NumberInput, coerceElement, coerceNumberProperty} from '../coercion';\nimport {\n AfterContentInit,\n Directive,\n ElementRef,\n EventEmitter,\n Injectable,\n Input,\n NgModule,\n NgZone,\n OnDestroy,\n Output,\n booleanAttribute,\n inject,\n} from '@angular/core';\nimport {Observable, Observer, Subject, Subscription} from 'rxjs';\nimport {debounceTime, filter, map} from 'rxjs/operators';\n\n// Angular may add, remove, or edit comment nodes during change detection. We don't care about\n// these changes because they don't affect the user-preceived content, and worse it can cause\n// infinite change detection cycles where the change detection updates a comment, triggering the\n// MutationObserver, triggering another change detection and kicking the cycle off again.\nfunction shouldIgnoreRecord(record: MutationRecord) {\n // Ignore changes to comment text.\n if (record.type === 'characterData' && record.target instanceof Comment) {\n return true;\n }\n // Ignore addition / removal of comments.\n if (record.type === 'childList') {\n for (let i = 0; i < record.addedNodes.length; i++) {\n if (!(record.addedNodes[i] instanceof Comment)) {\n return false;\n }\n }\n for (let i = 0; i < record.removedNodes.length; i++) {\n if (!(record.removedNodes[i] instanceof Comment)) {\n return false;\n }\n }\n return true;\n }\n // Observe everything else.\n return false;\n}\n\n/**\n * Factory that creates a new MutationObserver and allows us to stub it out in unit tests.\n * @docs-private\n */\n@Injectable({providedIn: 'root'})\nexport class MutationObserverFactory {\n create(callback: MutationCallback): MutationObserver | null {\n return typeof MutationObserver === 'undefined' ? null : new MutationObserver(callback);\n }\n}\n\n/** An injectable service that allows watching elements for changes to their content. */\n@Injectable({providedIn: 'root'})\nexport class ContentObserver implements OnDestroy {\n private _mutationObserverFactory = inject(MutationObserverFactory);\n\n /** Keeps track of the existing MutationObservers so they can be reused. */\n private _observedElements = new Map<\n Element,\n {\n observer: MutationObserver | null;\n readonly stream: Subject<MutationRecord[]>;\n count: number;\n }\n >();\n\n private _ngZone = inject(NgZone);\n\n constructor(...args: unknown[]);\n constructor() {}\n\n ngOnDestroy() {\n this._observedElements.forEach((_, element) => this._cleanupObserver(element));\n }\n\n /**\n * Observe content changes on an element.\n * @param element The element to observe for content changes.\n */\n observe(element: Element): Observable<MutationRecord[]>;\n\n /**\n * Observe content changes on an element.\n * @param element The element to observe for content changes.\n */\n observe(element: ElementRef<Element>): Observable<MutationRecord[]>;\n\n observe(elementOrRef: Element | ElementRef<Element>): Observable<MutationRecord[]> {\n const element = coerceElement(elementOrRef);\n\n return new Observable((observer: Observer<MutationRecord[]>) => {\n const stream = this._observeElement(element);\n const subscription = stream\n .pipe(\n map(records => records.filter(record => !shouldIgnoreRecord(record))),\n filter(records => !!records.length),\n )\n .subscribe(records => {\n this._ngZone.run(() => {\n observer.next(records);\n });\n });\n\n return () => {\n subscription.unsubscribe();\n this._unobserveElement(element);\n };\n });\n }\n\n /**\n * Observes the given element by using the existing MutationObserver if available, or creating a\n * new one if not.\n */\n private _observeElement(element: Element): Subject<MutationRecord[]> {\n return this._ngZone.runOutsideAngular(() => {\n if (!this._observedElements.has(element)) {\n const stream = new Subject<MutationRecord[]>();\n const observer = this._mutationObserverFactory.create(mutations => stream.next(mutations));\n if (observer) {\n observer.observe(element, {\n characterData: true,\n childList: true,\n subtree: true,\n });\n }\n this._observedElements.set(element, {observer, stream, count: 1});\n } else {\n this._observedElements.get(element)!.count++;\n }\n return this._observedElements.get(element)!.stream;\n });\n }\n\n /**\n * Un-observes the given element and cleans up the underlying MutationObserver if nobody else is\n * observing this element.\n */\n private _unobserveElement(element: Element) {\n if (this._observedElements.has(element)) {\n this._observedElements.get(element)!.count--;\n if (!this._observedElements.get(element)!.count) {\n this._cleanupObserver(element);\n }\n }\n }\n\n /** Clean up the underlying MutationObserver for the specified element. */\n private _cleanupObserver(element: Element) {\n if (this._observedElements.has(element)) {\n const {observer, stream} = this._observedElements.get(element)!;\n if (observer) {\n observer.disconnect();\n }\n stream.complete();\n this._observedElements.delete(element);\n }\n }\n}\n\n/**\n * Directive that triggers a callback whenever the content of\n * its associated element has changed.\n */\n@Directive({\n selector: '[cdkObserveContent]',\n exportAs: 'cdkObserveContent',\n})\nexport class CdkObserveContent implements AfterContentInit, OnDestroy {\n private _contentObserver = inject(ContentObserver);\n private _elementRef = inject<ElementRef<HTMLElement>>(ElementRef);\n\n /** Event emitted for each change in the element's content. */\n @Output('cdkObserveContent') readonly event = new EventEmitter<MutationRecord[]>();\n\n /**\n * Whether observing content is disabled. This option can be used\n * to disconnect the underlying MutationObserver until it is needed.\n */\n @Input({alias: 'cdkObserveContentDisabled', transform: booleanAttribute})\n get disabled(): boolean {\n return this._disabled;\n }\n set disabled(value: boolean) {\n this._disabled = value;\n this._disabled ? this._unsubscribe() : this._subscribe();\n }\n private _disabled = false;\n\n /** Debounce interval for emitting the changes. */\n @Input()\n get debounce(): number {\n return this._debounce;\n }\n set debounce(value: NumberInput) {\n this._debounce = coerceNumberProperty(value);\n this._subscribe();\n }\n private _debounce: number;\n\n private _currentSubscription: Subscription | null = null;\n\n constructor(...args: unknown[]);\n constructor() {}\n\n ngAfterContentInit() {\n if (!this._currentSubscription && !this.disabled) {\n this._subscribe();\n }\n }\n\n ngOnDestroy() {\n this._unsubscribe();\n }\n\n private _subscribe() {\n this._unsubscribe();\n const stream = this._contentObserver.observe(this._elementRef);\n\n this._currentSubscription = (\n this.debounce ? stream.pipe(debounceTime(this.debounce)) : stream\n ).subscribe(this.event);\n }\n\n private _unsubscribe() {\n this._currentSubscription?.unsubscribe();\n }\n}\n\n@NgModule({\n imports: [CdkObserveContent],\n exports: [CdkObserveContent],\n providers: [MutationObserverFactory],\n})\nexport class ObserversModule {}\n"],"names":[],"mappings":";;;;;;AA0BA;AACA;AACA;AACA;AACA,SAAS,kBAAkB,CAAC,MAAsB,EAAA;;AAEhD,IAAA,IAAI,MAAM,CAAC,IAAI,KAAK,eAAe,IAAI,MAAM,CAAC,MAAM,YAAY,OAAO,EAAE;AACvE,QAAA,OAAO,IAAI;;;AAGb,IAAA,IAAI,MAAM,CAAC,IAAI,KAAK,WAAW,EAAE;AAC/B,QAAA,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;AACjD,YAAA,IAAI,EAAE,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,YAAY,OAAO,CAAC,EAAE;AAC9C,gBAAA,OAAO,KAAK;;;AAGhB,QAAA,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,YAAY,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;AACnD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,UAAA,EAAA,CAAA;kBAL3B,QAAQ;AAAC,YAAA,IAAA,EAAA,CAAA;oBACR,OAAO,EAAE,CAAC,iBAAiB,CAAC;oBAC5B,OAAO,EAAE,CAAC,iBAAiB,CAAC;oBAC5B,SAAS,EAAE,CAAC,uBAAuB,CAAC;AACrC,iBAAA;;;;;"}
|
|
1
|
+
{"version":3,"file":"observers.mjs","sources":["../../../../../darwin_arm64-fastbuild-ST-199a4f3c4e20/bin/src/cdk/observers/observe-content.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.dev/license\n */\n\nimport {NumberInput, coerceElement, coerceNumberProperty} from '../coercion';\nimport {\n AfterContentInit,\n Directive,\n ElementRef,\n EventEmitter,\n Injectable,\n Input,\n NgModule,\n NgZone,\n OnDestroy,\n Output,\n booleanAttribute,\n inject,\n} from '@angular/core';\nimport {Observable, Observer, Subject, Subscription} from 'rxjs';\nimport {debounceTime, filter, map} from 'rxjs/operators';\n\n// Angular may add, remove, or edit comment nodes during change detection. We don't care about\n// these changes because they don't affect the user-preceived content, and worse it can cause\n// infinite change detection cycles where the change detection updates a comment, triggering the\n// MutationObserver, triggering another change detection and kicking the cycle off again.\nfunction shouldIgnoreRecord(record: MutationRecord) {\n // Ignore changes to comment text.\n if (record.type === 'characterData' && record.target instanceof Comment) {\n return true;\n }\n // Ignore addition / removal of comments.\n if (record.type === 'childList') {\n for (let i = 0; i < record.addedNodes.length; i++) {\n if (!(record.addedNodes[i] instanceof Comment)) {\n return false;\n }\n }\n for (let i = 0; i < record.removedNodes.length; i++) {\n if (!(record.removedNodes[i] instanceof Comment)) {\n return false;\n }\n }\n return true;\n }\n // Observe everything else.\n return false;\n}\n\n/**\n * Factory that creates a new MutationObserver and allows us to stub it out in unit tests.\n * @docs-private\n */\n@Injectable({providedIn: 'root'})\nexport class MutationObserverFactory {\n create(callback: MutationCallback): MutationObserver | null {\n return typeof MutationObserver === 'undefined' ? null : new MutationObserver(callback);\n }\n}\n\n/** An injectable service that allows watching elements for changes to their content. */\n@Injectable({providedIn: 'root'})\nexport class ContentObserver implements OnDestroy {\n private _mutationObserverFactory = inject(MutationObserverFactory);\n\n /** Keeps track of the existing MutationObservers so they can be reused. */\n private _observedElements = new Map<\n Element,\n {\n observer: MutationObserver | null;\n readonly stream: Subject<MutationRecord[]>;\n count: number;\n }\n >();\n\n private _ngZone = inject(NgZone);\n\n constructor(...args: unknown[]);\n constructor() {}\n\n ngOnDestroy() {\n this._observedElements.forEach((_, element) => this._cleanupObserver(element));\n }\n\n /**\n * Observe content changes on an element.\n * @param element The element to observe for content changes.\n */\n observe(element: Element): Observable<MutationRecord[]>;\n\n /**\n * Observe content changes on an element.\n * @param element The element to observe for content changes.\n */\n observe(element: ElementRef<Element>): Observable<MutationRecord[]>;\n\n observe(elementOrRef: Element | ElementRef<Element>): Observable<MutationRecord[]> {\n const element = coerceElement(elementOrRef);\n\n return new Observable((observer: Observer<MutationRecord[]>) => {\n const stream = this._observeElement(element);\n const subscription = stream\n .pipe(\n map(records => records.filter(record => !shouldIgnoreRecord(record))),\n filter(records => !!records.length),\n )\n .subscribe(records => {\n this._ngZone.run(() => {\n observer.next(records);\n });\n });\n\n return () => {\n subscription.unsubscribe();\n this._unobserveElement(element);\n };\n });\n }\n\n /**\n * Observes the given element by using the existing MutationObserver if available, or creating a\n * new one if not.\n */\n private _observeElement(element: Element): Subject<MutationRecord[]> {\n return this._ngZone.runOutsideAngular(() => {\n if (!this._observedElements.has(element)) {\n const stream = new Subject<MutationRecord[]>();\n const observer = this._mutationObserverFactory.create(mutations => stream.next(mutations));\n if (observer) {\n observer.observe(element, {\n characterData: true,\n childList: true,\n subtree: true,\n });\n }\n this._observedElements.set(element, {observer, stream, count: 1});\n } else {\n this._observedElements.get(element)!.count++;\n }\n return this._observedElements.get(element)!.stream;\n });\n }\n\n /**\n * Un-observes the given element and cleans up the underlying MutationObserver if nobody else is\n * observing this element.\n */\n private _unobserveElement(element: Element) {\n if (this._observedElements.has(element)) {\n this._observedElements.get(element)!.count--;\n if (!this._observedElements.get(element)!.count) {\n this._cleanupObserver(element);\n }\n }\n }\n\n /** Clean up the underlying MutationObserver for the specified element. */\n private _cleanupObserver(element: Element) {\n if (this._observedElements.has(element)) {\n const {observer, stream} = this._observedElements.get(element)!;\n if (observer) {\n observer.disconnect();\n }\n stream.complete();\n this._observedElements.delete(element);\n }\n }\n}\n\n/**\n * Directive that triggers a callback whenever the content of\n * its associated element has changed.\n */\n@Directive({\n selector: '[cdkObserveContent]',\n exportAs: 'cdkObserveContent',\n})\nexport class CdkObserveContent implements AfterContentInit, OnDestroy {\n private _contentObserver = inject(ContentObserver);\n private _elementRef = inject<ElementRef<HTMLElement>>(ElementRef);\n\n /** Event emitted for each change in the element's content. */\n @Output('cdkObserveContent') readonly event = new EventEmitter<MutationRecord[]>();\n\n /**\n * Whether observing content is disabled. This option can be used\n * to disconnect the underlying MutationObserver until it is needed.\n */\n @Input({alias: 'cdkObserveContentDisabled', transform: booleanAttribute})\n get disabled(): boolean {\n return this._disabled;\n }\n set disabled(value: boolean) {\n this._disabled = value;\n this._disabled ? this._unsubscribe() : this._subscribe();\n }\n private _disabled = false;\n\n /** Debounce interval for emitting the changes. */\n @Input()\n get debounce(): number {\n return this._debounce;\n }\n set debounce(value: NumberInput) {\n this._debounce = coerceNumberProperty(value);\n this._subscribe();\n }\n private _debounce: number;\n\n private _currentSubscription: Subscription | null = null;\n\n constructor(...args: unknown[]);\n constructor() {}\n\n ngAfterContentInit() {\n if (!this._currentSubscription && !this.disabled) {\n this._subscribe();\n }\n }\n\n ngOnDestroy() {\n this._unsubscribe();\n }\n\n private _subscribe() {\n this._unsubscribe();\n const stream = this._contentObserver.observe(this._elementRef);\n\n this._currentSubscription = (\n this.debounce ? stream.pipe(debounceTime(this.debounce)) : stream\n ).subscribe(this.event);\n }\n\n private _unsubscribe() {\n this._currentSubscription?.unsubscribe();\n }\n}\n\n@NgModule({\n imports: [CdkObserveContent],\n exports: [CdkObserveContent],\n providers: [MutationObserverFactory],\n})\nexport class ObserversModule {}\n"],"names":["shouldIgnoreRecord","record","type","i","addedNodes","length","Comment","removedNodes","create","callback","MutationObserver","i0","ɵɵngDeclareClassMetadata","minVersion","version","ngImport","MutationObserverFactory","decorators","Map","NgZone","ngOnDestroy","_observedElements","forEach","_","element","_cleanupObserver","observe","elementOrRef","coerceElement","Observable","observer","_observeElement","subscription","stream","pipe","map","records","filter","subscribe","_ngZone","run","next","unsubscribe","_unobserveElement","has","characterData","set","count","get","disconnect","delete","ɵɵngDeclareFactory","ContentObserver","deps","target","ɵɵFactoryTarget","Injectable","ɵɵngDeclareInjectable","providedIn","args","ctorParameters","inject","disabled","_subscribe","transform","booleanAttribute","ObserversModule","NgModule"],"mappings":";;;;;;AA4CQ,SAAAA,kBAAYA,CAAAC,MAAA,EAAA;;AAGhB,IAAA,OAAA,IAAA;;EAGF,IAAAA,MAAA,CAAAC,IAAA,KAAA,WAAA,EAAA;IACF,KAAA,IAAAC,CAAA,GAAA,CAAA,EAAAA,CAAA,GAAAF,MAAA,CAAAG,UAAA,CAAAC,MAAA,EAAAF,CAAA,EAAA,EAAA;AAEA,MAAA,IAAA,EAAAF,MAAA,CAAAG,UAAA,CAAAD,CAAA,CAAA,YAAAG,OAAA,CAAA,EAAA;;;AAGG;IAEH,KAAAH,IAAAA,CAAA,GAAAA,CAAAA,EAAAA,CAAA,GAAAF,MAAA,CAAAM,YAAoC,CAAAF,MAAA,EAAAF,CAAA,EAAA,EAAA;AAClC,MAAA,IAAiC,EAAAF,MAAA,CAAAM,YAAA,CAAAJ,CAAA,aAAAG,OAAA,CAAA,EAAA;AAC/B,QAAA,YAA8B;AAChC;;AAHW,IAAA,OAAA,IAAA;;;;6BAWgE,CAAA;AACnEE,EAAAA,MAAAA,CAAAC,QAAA,EAAA;AASA,IAAA,OAAA,OAAAC,gBAAA,KAAA,WAAA,GAAA,IAAA,GAAA,I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