source: trip-planner-front/node_modules/@angular/material/fesm2015/tree.js@ 571e0df

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

initial commit

  • Property mode set to 100644
File size: 17.1 KB
RevLine 
[6a3a178]1import { CdkTreeNode, CdkTree, CdkTreeNodeDef, CdkNestedTreeNode, CDK_TREE_NODE_OUTLET_NODE, CdkTreeNodePadding, CdkTreeNodeOutlet, CdkTreeNodeToggle, CdkTreeModule } from '@angular/cdk/tree';
2import { Directive, ElementRef, Attribute, Input, IterableDiffers, ViewContainerRef, Inject, Optional, Component, ViewEncapsulation, ChangeDetectionStrategy, ViewChild, NgModule } from '@angular/core';
3import { mixinTabIndex, mixinDisabled, MatCommonModule } from '@angular/material/core';
4import { coerceBooleanProperty } from '@angular/cdk/coercion';
5import { DataSource } from '@angular/cdk/collections';
6import { BehaviorSubject, merge } from 'rxjs';
7import { take, map } from 'rxjs/operators';
8
9/**
10 * @license
11 * Copyright Google LLC All Rights Reserved.
12 *
13 * Use of this source code is governed by an MIT-style license that can be
14 * found in the LICENSE file at https://angular.io/license
15 */
16const _MatTreeNodeBase = mixinTabIndex(mixinDisabled(CdkTreeNode));
17/**
18 * Wrapper for the CdkTree node with Material design styles.
19 */
20class MatTreeNode extends _MatTreeNodeBase {
21 constructor(elementRef, tree, tabIndex) {
22 super(elementRef, tree);
23 this.tabIndex = Number(tabIndex) || 0;
24 // The classes are directly added here instead of in the host property because classes on
25 // the host property are not inherited with View Engine. It is not set as a @HostBinding because
26 // it is not set by the time it's children nodes try to read the class from it.
27 // TODO: move to host after View Engine deprecation
28 elementRef.nativeElement.classList.add('mat-tree-node');
29 }
30 // This is a workaround for https://github.com/angular/angular/issues/23091
31 // In aot mode, the lifecycle hooks from parent class are not called.
32 ngOnInit() {
33 super.ngOnInit();
34 }
35 ngDoCheck() {
36 super.ngDoCheck();
37 }
38 ngOnDestroy() {
39 super.ngOnDestroy();
40 }
41}
42MatTreeNode.decorators = [
43 { type: Directive, args: [{
44 selector: 'mat-tree-node',
45 exportAs: 'matTreeNode',
46 inputs: ['role', 'disabled', 'tabIndex'],
47 providers: [{ provide: CdkTreeNode, useExisting: MatTreeNode }]
48 },] }
49];
50MatTreeNode.ctorParameters = () => [
51 { type: ElementRef },
52 { type: CdkTree },
53 { type: String, decorators: [{ type: Attribute, args: ['tabindex',] }] }
54];
55/**
56 * Wrapper for the CdkTree node definition with Material design styles.
57 * Captures the node's template and a when predicate that describes when this node should be used.
58 */
59class MatTreeNodeDef extends CdkTreeNodeDef {
60}
61MatTreeNodeDef.decorators = [
62 { type: Directive, args: [{
63 selector: '[matTreeNodeDef]',
64 inputs: [
65 'when: matTreeNodeDefWhen'
66 ],
67 providers: [{ provide: CdkTreeNodeDef, useExisting: MatTreeNodeDef }]
68 },] }
69];
70MatTreeNodeDef.propDecorators = {
71 data: [{ type: Input, args: ['matTreeNode',] }]
72};
73/**
74 * Wrapper for the CdkTree nested node with Material design styles.
75 */
76class MatNestedTreeNode extends CdkNestedTreeNode {
77 constructor(elementRef, tree, differs, tabIndex) {
78 super(elementRef, tree, differs);
79 this._disabled = false;
80 this.tabIndex = Number(tabIndex) || 0;
81 // The classes are directly added here instead of in the host property because classes on
82 // the host property are not inherited with View Engine. It is not set as a @HostBinding because
83 // it is not set by the time it's children nodes try to read the class from it.
84 // TODO: move to host after View Engine deprecation
85 elementRef.nativeElement.classList.add('mat-nested-tree-node');
86 }
87 /** Whether the node is disabled. */
88 get disabled() { return this._disabled; }
89 set disabled(value) { this._disabled = coerceBooleanProperty(value); }
90 /** Tabindex for the node. */
91 get tabIndex() { return this.disabled ? -1 : this._tabIndex; }
92 set tabIndex(value) {
93 // If the specified tabIndex value is null or undefined, fall back to the default value.
94 this._tabIndex = value != null ? value : 0;
95 }
96 // This is a workaround for https://github.com/angular/angular/issues/19145
97 // In aot mode, the lifecycle hooks from parent class are not called.
98 // TODO(tinayuangao): Remove when the angular issue #19145 is fixed
99 ngOnInit() {
100 super.ngOnInit();
101 }
102 ngDoCheck() {
103 super.ngDoCheck();
104 }
105 ngAfterContentInit() {
106 super.ngAfterContentInit();
107 }
108 ngOnDestroy() {
109 super.ngOnDestroy();
110 }
111}
112MatNestedTreeNode.decorators = [
113 { type: Directive, args: [{
114 selector: 'mat-nested-tree-node',
115 exportAs: 'matNestedTreeNode',
116 inputs: ['role', 'disabled', 'tabIndex'],
117 providers: [
118 { provide: CdkNestedTreeNode, useExisting: MatNestedTreeNode },
119 { provide: CdkTreeNode, useExisting: MatNestedTreeNode },
120 { provide: CDK_TREE_NODE_OUTLET_NODE, useExisting: MatNestedTreeNode }
121 ]
122 },] }
123];
124MatNestedTreeNode.ctorParameters = () => [
125 { type: ElementRef },
126 { type: CdkTree },
127 { type: IterableDiffers },
128 { type: String, decorators: [{ type: Attribute, args: ['tabindex',] }] }
129];
130MatNestedTreeNode.propDecorators = {
131 node: [{ type: Input, args: ['matNestedTreeNode',] }],
132 disabled: [{ type: Input }],
133 tabIndex: [{ type: Input }]
134};
135
136/**
137 * @license
138 * Copyright Google LLC All Rights Reserved.
139 *
140 * Use of this source code is governed by an MIT-style license that can be
141 * found in the LICENSE file at https://angular.io/license
142 */
143/**
144 * Wrapper for the CdkTree padding with Material design styles.
145 */
146class MatTreeNodePadding extends CdkTreeNodePadding {
147 /** The level of depth of the tree node. The padding will be `level * indent` pixels. */
148 get level() { return this._level; }
149 set level(value) { this._setLevelInput(value); }
150 /** The indent for each level. Default number 40px from material design menu sub-menu spec. */
151 get indent() { return this._indent; }
152 set indent(indent) { this._setIndentInput(indent); }
153}
154MatTreeNodePadding.decorators = [
155 { type: Directive, args: [{
156 selector: '[matTreeNodePadding]',
157 providers: [{ provide: CdkTreeNodePadding, useExisting: MatTreeNodePadding }]
158 },] }
159];
160MatTreeNodePadding.propDecorators = {
161 level: [{ type: Input, args: ['matTreeNodePadding',] }],
162 indent: [{ type: Input, args: ['matTreeNodePaddingIndent',] }]
163};
164
165/**
166 * @license
167 * Copyright Google LLC All Rights Reserved.
168 *
169 * Use of this source code is governed by an MIT-style license that can be
170 * found in the LICENSE file at https://angular.io/license
171 */
172/**
173 * Outlet for nested CdkNode. Put `[matTreeNodeOutlet]` on a tag to place children dataNodes
174 * inside the outlet.
175 */
176class MatTreeNodeOutlet {
177 constructor(viewContainer, _node) {
178 this.viewContainer = viewContainer;
179 this._node = _node;
180 }
181}
182MatTreeNodeOutlet.decorators = [
183 { type: Directive, args: [{
184 selector: '[matTreeNodeOutlet]',
185 providers: [{
186 provide: CdkTreeNodeOutlet,
187 useExisting: MatTreeNodeOutlet
188 }]
189 },] }
190];
191MatTreeNodeOutlet.ctorParameters = () => [
192 { type: ViewContainerRef },
193 { type: undefined, decorators: [{ type: Inject, args: [CDK_TREE_NODE_OUTLET_NODE,] }, { type: Optional }] }
194];
195
196/**
197 * @license
198 * Copyright Google LLC All Rights Reserved.
199 *
200 * Use of this source code is governed by an MIT-style license that can be
201 * found in the LICENSE file at https://angular.io/license
202 */
203/**
204 * Wrapper for the CdkTable with Material design styles.
205 */
206class MatTree extends CdkTree {
207}
208MatTree.decorators = [
209 { type: Component, args: [{
210 selector: 'mat-tree',
211 exportAs: 'matTree',
212 template: `<ng-container matTreeNodeOutlet></ng-container>`,
213 host: {
214 // The 'cdk-tree' class needs to be included here because classes set in the host in the
215 // parent class are not inherited with View Engine. The 'cdk-tree' class in CdkTreeNode has
216 // to be set in the host because:
217 // if it is set as a @HostBinding it is not set by the time the tree nodes try to read the
218 // class from it.
219 // the ElementRef is not available in the constructor so the class can't be applied directly
220 // without a breaking constructor change.
221 'class': 'mat-tree cdk-tree',
222 'role': 'tree',
223 },
224 encapsulation: ViewEncapsulation.None,
225 // See note on CdkTree for explanation on why this uses the default change detection strategy.
226 // tslint:disable-next-line:validate-decorators
227 changeDetection: ChangeDetectionStrategy.Default,
228 providers: [{ provide: CdkTree, useExisting: MatTree }],
229 styles: [".mat-tree{display:block}.mat-tree-node{display:flex;align-items:center;flex:1;word-wrap:break-word}.mat-nested-tree-node{border-bottom-width:0}\n"]
230 },] }
231];
232MatTree.propDecorators = {
233 _nodeOutlet: [{ type: ViewChild, args: [MatTreeNodeOutlet, { static: true },] }]
234};
235
236/**
237 * @license
238 * Copyright Google LLC All Rights Reserved.
239 *
240 * Use of this source code is governed by an MIT-style license that can be
241 * found in the LICENSE file at https://angular.io/license
242 */
243/**
244 * Wrapper for the CdkTree's toggle with Material design styles.
245 */
246// tslint:disable-next-line: coercion-types
247class MatTreeNodeToggle extends CdkTreeNodeToggle {
248 get recursive() { return this._recursive; }
249 set recursive(value) {
250 // TODO: when we remove support for ViewEngine, change this setter to an input
251 // alias in the decorator metadata.
252 this._recursive = coerceBooleanProperty(value);
253 }
254}
255MatTreeNodeToggle.decorators = [
256 { type: Directive, args: [{
257 selector: '[matTreeNodeToggle]',
258 providers: [{ provide: CdkTreeNodeToggle, useExisting: MatTreeNodeToggle }]
259 },] }
260];
261MatTreeNodeToggle.propDecorators = {
262 recursive: [{ type: Input, args: ['matTreeNodeToggleRecursive',] }]
263};
264
265/**
266 * @license
267 * Copyright Google LLC All Rights Reserved.
268 *
269 * Use of this source code is governed by an MIT-style license that can be
270 * found in the LICENSE file at https://angular.io/license
271 */
272const MAT_TREE_DIRECTIVES = [
273 MatNestedTreeNode,
274 MatTreeNodeDef,
275 MatTreeNodePadding,
276 MatTreeNodeToggle,
277 MatTree,
278 MatTreeNode,
279 MatTreeNodeOutlet
280];
281class MatTreeModule {
282}
283MatTreeModule.decorators = [
284 { type: NgModule, args: [{
285 imports: [CdkTreeModule, MatCommonModule],
286 exports: [MatCommonModule, MAT_TREE_DIRECTIVES],
287 declarations: MAT_TREE_DIRECTIVES,
288 },] }
289];
290
291/**
292 * @license
293 * Copyright Google LLC All Rights Reserved.
294 *
295 * Use of this source code is governed by an MIT-style license that can be
296 * found in the LICENSE file at https://angular.io/license
297 */
298/**
299 * Tree flattener to convert a normal type of node to node with children & level information.
300 * Transform nested nodes of type `T` to flattened nodes of type `F`.
301 *
302 * For example, the input data of type `T` is nested, and contains its children data:
303 * SomeNode: {
304 * key: 'Fruits',
305 * children: [
306 * NodeOne: {
307 * key: 'Apple',
308 * },
309 * NodeTwo: {
310 * key: 'Pear',
311 * }
312 * ]
313 * }
314 * After flattener flatten the tree, the structure will become
315 * SomeNode: {
316 * key: 'Fruits',
317 * expandable: true,
318 * level: 1
319 * },
320 * NodeOne: {
321 * key: 'Apple',
322 * expandable: false,
323 * level: 2
324 * },
325 * NodeTwo: {
326 * key: 'Pear',
327 * expandable: false,
328 * level: 2
329 * }
330 * and the output flattened type is `F` with additional information.
331 */
332class MatTreeFlattener {
333 constructor(transformFunction, getLevel, isExpandable, getChildren) {
334 this.transformFunction = transformFunction;
335 this.getLevel = getLevel;
336 this.isExpandable = isExpandable;
337 this.getChildren = getChildren;
338 }
339 _flattenNode(node, level, resultNodes, parentMap) {
340 const flatNode = this.transformFunction(node, level);
341 resultNodes.push(flatNode);
342 if (this.isExpandable(flatNode)) {
343 const childrenNodes = this.getChildren(node);
344 if (childrenNodes) {
345 if (Array.isArray(childrenNodes)) {
346 this._flattenChildren(childrenNodes, level, resultNodes, parentMap);
347 }
348 else {
349 childrenNodes.pipe(take(1)).subscribe(children => {
350 this._flattenChildren(children, level, resultNodes, parentMap);
351 });
352 }
353 }
354 }
355 return resultNodes;
356 }
357 _flattenChildren(children, level, resultNodes, parentMap) {
358 children.forEach((child, index) => {
359 let childParentMap = parentMap.slice();
360 childParentMap.push(index != children.length - 1);
361 this._flattenNode(child, level + 1, resultNodes, childParentMap);
362 });
363 }
364 /**
365 * Flatten a list of node type T to flattened version of node F.
366 * Please note that type T may be nested, and the length of `structuredData` may be different
367 * from that of returned list `F[]`.
368 */
369 flattenNodes(structuredData) {
370 let resultNodes = [];
371 structuredData.forEach(node => this._flattenNode(node, 0, resultNodes, []));
372 return resultNodes;
373 }
374 /**
375 * Expand flattened node with current expansion status.
376 * The returned list may have different length.
377 */
378 expandFlattenedNodes(nodes, treeControl) {
379 let results = [];
380 let currentExpand = [];
381 currentExpand[0] = true;
382 nodes.forEach(node => {
383 let expand = true;
384 for (let i = 0; i <= this.getLevel(node); i++) {
385 expand = expand && currentExpand[i];
386 }
387 if (expand) {
388 results.push(node);
389 }
390 if (this.isExpandable(node)) {
391 currentExpand[this.getLevel(node) + 1] = treeControl.isExpanded(node);
392 }
393 });
394 return results;
395 }
396}
397/**
398 * Data source for flat tree.
399 * The data source need to handle expansion/collapsion of the tree node and change the data feed
400 * to `MatTree`.
401 * The nested tree nodes of type `T` are flattened through `MatTreeFlattener`, and converted
402 * to type `F` for `MatTree` to consume.
403 */
404class MatTreeFlatDataSource extends DataSource {
405 constructor(_treeControl, _treeFlattener, initialData) {
406 super();
407 this._treeControl = _treeControl;
408 this._treeFlattener = _treeFlattener;
409 this._flattenedData = new BehaviorSubject([]);
410 this._expandedData = new BehaviorSubject([]);
411 this._data = new BehaviorSubject([]);
412 if (initialData) {
413 // Assign the data through the constructor to ensure that all of the logic is executed.
414 this.data = initialData;
415 }
416 }
417 get data() { return this._data.value; }
418 set data(value) {
419 this._data.next(value);
420 this._flattenedData.next(this._treeFlattener.flattenNodes(this.data));
421 this._treeControl.dataNodes = this._flattenedData.value;
422 }
423 connect(collectionViewer) {
424 return merge(collectionViewer.viewChange, this._treeControl.expansionModel.changed, this._flattenedData).pipe(map(() => {
425 this._expandedData.next(this._treeFlattener.expandFlattenedNodes(this._flattenedData.value, this._treeControl));
426 return this._expandedData.value;
427 }));
428 }
429 disconnect() {
430 // no op
431 }
432}
433
434/**
435 * @license
436 * Copyright Google LLC All Rights Reserved.
437 *
438 * Use of this source code is governed by an MIT-style license that can be
439 * found in the LICENSE file at https://angular.io/license
440 */
441/**
442 * Data source for nested tree.
443 *
444 * The data source for nested tree doesn't have to consider node flattener, or the way to expand
445 * or collapse. The expansion/collapsion will be handled by TreeControl and each non-leaf node.
446 */
447class MatTreeNestedDataSource extends DataSource {
448 constructor() {
449 super(...arguments);
450 this._data = new BehaviorSubject([]);
451 }
452 /**
453 * Data for the nested tree
454 */
455 get data() { return this._data.value; }
456 set data(value) { this._data.next(value); }
457 connect(collectionViewer) {
458 return merge(...[collectionViewer.viewChange, this._data])
459 .pipe(map(() => this.data));
460 }
461 disconnect() {
462 // no op
463 }
464}
465
466/**
467 * @license
468 * Copyright Google LLC All Rights Reserved.
469 *
470 * Use of this source code is governed by an MIT-style license that can be
471 * found in the LICENSE file at https://angular.io/license
472 */
473
474/**
475 * Generated bundle index. Do not edit.
476 */
477
478export { MatNestedTreeNode, MatTree, MatTreeFlatDataSource, MatTreeFlattener, MatTreeModule, MatTreeNestedDataSource, MatTreeNode, MatTreeNodeDef, MatTreeNodeOutlet, MatTreeNodePadding, MatTreeNodeToggle };
479//# sourceMappingURL=tree.js.map
Note: See TracBrowser for help on using the repository browser.