source: trip-planner-front/node_modules/@angular/material/esm2015/tree/data-source/flat-data-source.js

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

initial commit

  • Property mode set to 100644
File size: 16.7 KB
Line 
1/**
2 * @license
3 * Copyright Google LLC All Rights Reserved.
4 *
5 * Use of this source code is governed by an MIT-style license that can be
6 * found in the LICENSE file at https://angular.io/license
7 */
8import { DataSource } from '@angular/cdk/collections';
9import { BehaviorSubject, merge } from 'rxjs';
10import { map, take } from 'rxjs/operators';
11/**
12 * Tree flattener to convert a normal type of node to node with children & level information.
13 * Transform nested nodes of type `T` to flattened nodes of type `F`.
14 *
15 * For example, the input data of type `T` is nested, and contains its children data:
16 * SomeNode: {
17 * key: 'Fruits',
18 * children: [
19 * NodeOne: {
20 * key: 'Apple',
21 * },
22 * NodeTwo: {
23 * key: 'Pear',
24 * }
25 * ]
26 * }
27 * After flattener flatten the tree, the structure will become
28 * SomeNode: {
29 * key: 'Fruits',
30 * expandable: true,
31 * level: 1
32 * },
33 * NodeOne: {
34 * key: 'Apple',
35 * expandable: false,
36 * level: 2
37 * },
38 * NodeTwo: {
39 * key: 'Pear',
40 * expandable: false,
41 * level: 2
42 * }
43 * and the output flattened type is `F` with additional information.
44 */
45export class MatTreeFlattener {
46 constructor(transformFunction, getLevel, isExpandable, getChildren) {
47 this.transformFunction = transformFunction;
48 this.getLevel = getLevel;
49 this.isExpandable = isExpandable;
50 this.getChildren = getChildren;
51 }
52 _flattenNode(node, level, resultNodes, parentMap) {
53 const flatNode = this.transformFunction(node, level);
54 resultNodes.push(flatNode);
55 if (this.isExpandable(flatNode)) {
56 const childrenNodes = this.getChildren(node);
57 if (childrenNodes) {
58 if (Array.isArray(childrenNodes)) {
59 this._flattenChildren(childrenNodes, level, resultNodes, parentMap);
60 }
61 else {
62 childrenNodes.pipe(take(1)).subscribe(children => {
63 this._flattenChildren(children, level, resultNodes, parentMap);
64 });
65 }
66 }
67 }
68 return resultNodes;
69 }
70 _flattenChildren(children, level, resultNodes, parentMap) {
71 children.forEach((child, index) => {
72 let childParentMap = parentMap.slice();
73 childParentMap.push(index != children.length - 1);
74 this._flattenNode(child, level + 1, resultNodes, childParentMap);
75 });
76 }
77 /**
78 * Flatten a list of node type T to flattened version of node F.
79 * Please note that type T may be nested, and the length of `structuredData` may be different
80 * from that of returned list `F[]`.
81 */
82 flattenNodes(structuredData) {
83 let resultNodes = [];
84 structuredData.forEach(node => this._flattenNode(node, 0, resultNodes, []));
85 return resultNodes;
86 }
87 /**
88 * Expand flattened node with current expansion status.
89 * The returned list may have different length.
90 */
91 expandFlattenedNodes(nodes, treeControl) {
92 let results = [];
93 let currentExpand = [];
94 currentExpand[0] = true;
95 nodes.forEach(node => {
96 let expand = true;
97 for (let i = 0; i <= this.getLevel(node); i++) {
98 expand = expand && currentExpand[i];
99 }
100 if (expand) {
101 results.push(node);
102 }
103 if (this.isExpandable(node)) {
104 currentExpand[this.getLevel(node) + 1] = treeControl.isExpanded(node);
105 }
106 });
107 return results;
108 }
109}
110/**
111 * Data source for flat tree.
112 * The data source need to handle expansion/collapsion of the tree node and change the data feed
113 * to `MatTree`.
114 * The nested tree nodes of type `T` are flattened through `MatTreeFlattener`, and converted
115 * to type `F` for `MatTree` to consume.
116 */
117export class MatTreeFlatDataSource extends DataSource {
118 constructor(_treeControl, _treeFlattener, initialData) {
119 super();
120 this._treeControl = _treeControl;
121 this._treeFlattener = _treeFlattener;
122 this._flattenedData = new BehaviorSubject([]);
123 this._expandedData = new BehaviorSubject([]);
124 this._data = new BehaviorSubject([]);
125 if (initialData) {
126 // Assign the data through the constructor to ensure that all of the logic is executed.
127 this.data = initialData;
128 }
129 }
130 get data() { return this._data.value; }
131 set data(value) {
132 this._data.next(value);
133 this._flattenedData.next(this._treeFlattener.flattenNodes(this.data));
134 this._treeControl.dataNodes = this._flattenedData.value;
135 }
136 connect(collectionViewer) {
137 return merge(collectionViewer.viewChange, this._treeControl.expansionModel.changed, this._flattenedData).pipe(map(() => {
138 this._expandedData.next(this._treeFlattener.expandFlattenedNodes(this._flattenedData.value, this._treeControl));
139 return this._expandedData.value;
140 }));
141 }
142 disconnect() {
143 // no op
144 }
145}
146//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZmxhdC1kYXRhLXNvdXJjZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uLy4uLy4uL3NyYy9tYXRlcmlhbC90cmVlL2RhdGEtc291cmNlL2ZsYXQtZGF0YS1zb3VyY2UudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUE7Ozs7OztHQU1HO0FBRUgsT0FBTyxFQUFtQixVQUFVLEVBQUMsTUFBTSwwQkFBMEIsQ0FBQztBQUV0RSxPQUFPLEVBQUMsZUFBZSxFQUFFLEtBQUssRUFBYSxNQUFNLE1BQU0sQ0FBQztBQUN4RCxPQUFPLEVBQUMsR0FBRyxFQUFFLElBQUksRUFBQyxNQUFNLGdCQUFnQixDQUFDO0FBRXpDOzs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7R0FpQ0c7QUFDSCxNQUFNLE9BQU8sZ0JBQWdCO0lBRTNCLFlBQW1CLGlCQUFnRCxFQUNoRCxRQUE2QixFQUM3QixZQUFrQyxFQUNsQyxXQUNxQztRQUpyQyxzQkFBaUIsR0FBakIsaUJBQWlCLENBQStCO1FBQ2hELGFBQVEsR0FBUixRQUFRLENBQXFCO1FBQzdCLGlCQUFZLEdBQVosWUFBWSxDQUFzQjtRQUNsQyxnQkFBVyxHQUFYLFdBQVcsQ0FDMEI7SUFBRyxDQUFDO0lBRTVELFlBQVksQ0FBQyxJQUFPLEVBQUUsS0FBYSxFQUN0QixXQUFnQixFQUFFLFNBQW9CO1FBQ2pELE1BQU0sUUFBUSxHQUFHLElBQUksQ0FBQyxpQkFBaUIsQ0FBQyxJQUFJLEVBQUUsS0FBSyxDQUFDLENBQ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ICAgICB0aGlzLl9leHBhbmRlZERhdGEubmV4dChcbiAgICAgICAgdGhpcy5fdHJlZUZsYXR0ZW5lci5leHBhbmRGbGF0dGVuZWROb2Rlcyh0aGlzLl9mbGF0dGVuZWREYXRhLnZhbHVlLCB0aGlzLl90cmVlQ29udHJvbCkpO1xuICAgICAgcmV0dXJuIHRoaXMuX2V4cGFuZGVkRGF0YS52YWx1ZTtcbiAgICB9KSk7XG4gIH1cblxuICBkaXNjb25uZWN0KCkge1xuICAgIC8vIG5vIG9wXG4gIH1cbn1cbiJdfQ==
Note: See TracBrowser for help on using the repository browser.