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