1 | import * as i0 from '@angular/core';
|
2 | import { InjectionToken, Directive, Input, EventEmitter, Optional, Inject, SkipSelf, Output, NgModule } from '@angular/core';
|
3 | import * as i1 from '@angular/cdk/collections';
|
4 | import { coerceBooleanProperty } from '@angular/cdk/coercion';
|
5 | import { Subject, Subscription } from 'rxjs';
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 | let nextId$1 = 0;
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 | const CDK_ACCORDION = new InjectionToken('CdkAccordion');
|
22 |
|
23 |
|
24 |
|
25 | class CdkAccordion {
|
26 | constructor() {
|
27 |
|
28 | this._stateChanges = new Subject();
|
29 |
|
30 | this._openCloseAllActions = new Subject();
|
31 |
|
32 | this.id = `cdk-accordion-${nextId$1++}`;
|
33 | this._multi = false;
|
34 | }
|
35 |
|
36 | get multi() {
|
37 | return this._multi;
|
38 | }
|
39 | set multi(multi) {
|
40 | this._multi = coerceBooleanProperty(multi);
|
41 | }
|
42 |
|
43 | openAll() {
|
44 | if (this._multi) {
|
45 | this._openCloseAllActions.next(true);
|
46 | }
|
47 | }
|
48 |
|
49 | closeAll() {
|
50 | this._openCloseAllActions.next(false);
|
51 | }
|
52 | ngOnChanges(changes) {
|
53 | this._stateChanges.next(changes);
|
54 | }
|
55 | ngOnDestroy() {
|
56 | this._stateChanges.complete();
|
57 | this._openCloseAllActions.complete();
|
58 | }
|
59 | }
|
60 | CdkAccordion.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.1", ngImport: i0, type: CdkAccordion, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
61 | CdkAccordion.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "14.0.1", type: CdkAccordion, selector: "cdk-accordion, [cdkAccordion]", inputs: { multi: "multi" }, providers: [{ provide: CDK_ACCORDION, useExisting: CdkAccordion }], exportAs: ["cdkAccordion"], usesOnChanges: true, ngImport: i0 });
|
62 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.1", ngImport: i0, type: CdkAccordion, decorators: [{
|
63 | type: Directive,
|
64 | args: [{
|
65 | selector: 'cdk-accordion, [cdkAccordion]',
|
66 | exportAs: 'cdkAccordion',
|
67 | providers: [{ provide: CDK_ACCORDION, useExisting: CdkAccordion }],
|
68 | }]
|
69 | }], propDecorators: { multi: [{
|
70 | type: Input
|
71 | }] } });
|
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 | let nextId = 0;
|
82 |
|
83 |
|
84 |
|
85 |
|
86 | class CdkAccordionItem {
|
87 | constructor(accordion, _changeDetectorRef, _expansionDispatcher) {
|
88 | this.accordion = accordion;
|
89 | this._changeDetectorRef = _changeDetectorRef;
|
90 | this._expansionDispatcher = _expansionDispatcher;
|
91 |
|
92 | this._openCloseAllSubscription = Subscription.EMPTY;
|
93 |
|
94 | this.closed = new EventEmitter();
|
95 |
|
96 | this.opened = new EventEmitter();
|
97 |
|
98 | this.destroyed = new EventEmitter();
|
99 | |
100 |
|
101 |
|
102 |
|
103 |
|
104 | this.expandedChange = new EventEmitter();
|
105 |
|
106 | this.id = `cdk-accordion-child-${nextId++}`;
|
107 | this._expanded = false;
|
108 | this._disabled = false;
|
109 |
|
110 | this._removeUniqueSelectionListener = () => { };
|
111 | this._removeUniqueSelectionListener = _expansionDispatcher.listen((id, accordionId) => {
|
112 | if (this.accordion &&
|
113 | !this.accordion.multi &&
|
114 | this.accordion.id === accordionId &&
|
115 | this.id !== id) {
|
116 | this.expanded = false;
|
117 | }
|
118 | });
|
119 |
|
120 | if (this.accordion) {
|
121 | this._openCloseAllSubscription = this._subscribeToOpenCloseAllActions();
|
122 | }
|
123 | }
|
124 |
|
125 | get expanded() {
|
126 | return this._expanded;
|
127 | }
|
128 | set expanded(expanded) {
|
129 | expanded = coerceBooleanProperty(expanded);
|
130 |
|
131 | if (this._expanded !== expanded) {
|
132 | this._expanded = expanded;
|
133 | this.expandedChange.emit(expanded);
|
134 | if (expanded) {
|
135 | this.opened.emit();
|
136 | |
137 |
|
138 |
|
139 |
|
140 | const accordionId = this.accordion ? this.accordion.id : this.id;
|
141 | this._expansionDispatcher.notify(this.id, accordionId);
|
142 | }
|
143 | else {
|
144 | this.closed.emit();
|
145 | }
|
146 |
|
147 |
|
148 | this._changeDetectorRef.markForCheck();
|
149 | }
|
150 | }
|
151 |
|
152 | get disabled() {
|
153 | return this._disabled;
|
154 | }
|
155 | set disabled(disabled) {
|
156 | this._disabled = coerceBooleanProperty(disabled);
|
157 | }
|
158 |
|
159 | ngOnDestroy() {
|
160 | this.opened.complete();
|
161 | this.closed.complete();
|
162 | this.destroyed.emit();
|
163 | this.destroyed.complete();
|
164 | this._removeUniqueSelectionListener();
|
165 | this._openCloseAllSubscription.unsubscribe();
|
166 | }
|
167 |
|
168 | toggle() {
|
169 | if (!this.disabled) {
|
170 | this.expanded = !this.expanded;
|
171 | }
|
172 | }
|
173 |
|
174 | close() {
|
175 | if (!this.disabled) {
|
176 | this.expanded = false;
|
177 | }
|
178 | }
|
179 |
|
180 | open() {
|
181 | if (!this.disabled) {
|
182 | this.expanded = true;
|
183 | }
|
184 | }
|
185 | _subscribeToOpenCloseAllActions() {
|
186 | return this.accordion._openCloseAllActions.subscribe(expanded => {
|
187 |
|
188 | if (!this.disabled) {
|
189 | this.expanded = expanded;
|
190 | }
|
191 | });
|
192 | }
|
193 | }
|
194 | CdkAccordionItem.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.1", ngImport: i0, type: CdkAccordionItem, deps: [{ token: CDK_ACCORDION, optional: true, skipSelf: true }, { token: i0.ChangeDetectorRef }, { token: i1.UniqueSelectionDispatcher }], target: i0.ɵɵFactoryTarget.Directive });
|
195 | CdkAccordionItem.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "14.0.1", type: CdkAccordionItem, selector: "cdk-accordion-item, [cdkAccordionItem]", inputs: { expanded: "expanded", disabled: "disabled" }, outputs: { closed: "closed", opened: "opened", destroyed: "destroyed", expandedChange: "expandedChange" }, providers: [
|
196 |
|
197 |
|
198 | { provide: CDK_ACCORDION, useValue: undefined },
|
199 | ], exportAs: ["cdkAccordionItem"], ngImport: i0 });
|
200 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.1", ngImport: i0, type: CdkAccordionItem, decorators: [{
|
201 | type: Directive,
|
202 | args: [{
|
203 | selector: 'cdk-accordion-item, [cdkAccordionItem]',
|
204 | exportAs: 'cdkAccordionItem',
|
205 | providers: [
|
206 |
|
207 |
|
208 | { provide: CDK_ACCORDION, useValue: undefined },
|
209 | ],
|
210 | }]
|
211 | }], ctorParameters: function () { return [{ type: CdkAccordion, decorators: [{
|
212 | type: Optional
|
213 | }, {
|
214 | type: Inject,
|
215 | args: [CDK_ACCORDION]
|
216 | }, {
|
217 | type: SkipSelf
|
218 | }] }, { type: i0.ChangeDetectorRef }, { type: i1.UniqueSelectionDispatcher }]; }, propDecorators: { closed: [{
|
219 | type: Output
|
220 | }], opened: [{
|
221 | type: Output
|
222 | }], destroyed: [{
|
223 | type: Output
|
224 | }], expandedChange: [{
|
225 | type: Output
|
226 | }], expanded: [{
|
227 | type: Input
|
228 | }], disabled: [{
|
229 | type: Input
|
230 | }] } });
|
231 |
|
232 |
|
233 |
|
234 |
|
235 |
|
236 |
|
237 |
|
238 |
|
239 | class CdkAccordionModule {
|
240 | }
|
241 | CdkAccordionModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.0.1", ngImport: i0, type: CdkAccordionModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
242 | CdkAccordionModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "14.0.1", ngImport: i0, type: CdkAccordionModule, declarations: [CdkAccordion, CdkAccordionItem], exports: [CdkAccordion, CdkAccordionItem] });
|
243 | CdkAccordionModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "14.0.1", ngImport: i0, type: CdkAccordionModule });
|
244 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.0.1", ngImport: i0, type: CdkAccordionModule, decorators: [{
|
245 | type: NgModule,
|
246 | args: [{
|
247 | exports: [CdkAccordion, CdkAccordionItem],
|
248 | declarations: [CdkAccordion, CdkAccordionItem],
|
249 | }]
|
250 | }] });
|
251 |
|
252 |
|
253 |
|
254 |
|
255 |
|
256 |
|
257 |
|
258 |
|
259 |
|
260 |
|
261 |
|
262 |
|
263 |
|
264 |
|
265 |
|
266 |
|
267 |
|
268 |
|
269 |
|
270 |
|
271 |
|
272 | export { CdkAccordion, CdkAccordionItem, CdkAccordionModule };
|
273 |
|