@rxap/tree 16.0.0-dev.19 → 16.0.0-dev.20
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/CHANGELOG.md +6 -0
- package/README.md +1 -1
- package/esm2022/lib/search.form.mjs +44 -0
- package/esm2022/lib/tree.data-source.mjs +247 -72
- package/fesm2022/rxap-tree.mjs +248 -75
- package/fesm2022/rxap-tree.mjs.map +1 -1
- package/lib/search.form.d.ts +20 -0
- package/lib/tree.data-source.d.ts +40 -13
- package/package.json +10 -9
package/fesm2022/rxap-tree.mjs
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
+
import { __decorate, __metadata } from 'tslib';
|
|
1
2
|
import { SelectionModel } from '@angular/cdk/collections';
|
|
3
|
+
import { FlatTreeControl } from '@angular/cdk/tree';
|
|
2
4
|
import * as i0 from '@angular/core';
|
|
3
|
-
import { InjectionToken, isDevMode, Injectable, Inject, TemplateRef, Directive, EventEmitter, signal, ViewContainerRef, ChangeDetectorRef, Component, ChangeDetectionStrategy,
|
|
4
|
-
import { BaseDataSource, RXAP_DATA_SOURCE_METADATA } from '@rxap/data-source';
|
|
5
|
+
import { InjectionToken, isDevMode, Injectable, Inject, Optional, TemplateRef, Directive, EventEmitter, signal, ViewContainerRef, ChangeDetectorRef, Component, ChangeDetectionStrategy, Input, ContentChild, Output, ViewChild, HostListener } from '@angular/core';
|
|
6
|
+
import { BaseDataSource, RXAP_DATA_SOURCE_METADATA, RxapDataSource } from '@rxap/data-source';
|
|
5
7
|
import { Node } from '@rxap/data-structure-tree';
|
|
6
8
|
import { ToggleSubject } from '@rxap/rxjs';
|
|
7
|
-
import { joinPath, DebounceCall } from '@rxap/utilities';
|
|
8
|
-
import { BehaviorSubject, Subject, from, merge } from 'rxjs';
|
|
9
|
-
import { map, tap,
|
|
10
|
-
import { __decorate, __metadata } from 'tslib';
|
|
9
|
+
import { coerceArray, joinPath, Required, DebounceCall } from '@rxap/utilities';
|
|
10
|
+
import { BehaviorSubject, Subject, combineLatest, from, merge } from 'rxjs';
|
|
11
|
+
import { switchMap, map, tap, startWith } from 'rxjs/operators';
|
|
11
12
|
import * as i8 from '@angular/cdk/portal';
|
|
12
13
|
import { TemplatePortal, PortalModule } from '@angular/cdk/portal';
|
|
13
|
-
import { FlatTreeControl } from '@angular/cdk/tree';
|
|
14
14
|
import { NgStyle, NgIf, AsyncPipe, NgClass, NgForOf } from '@angular/common';
|
|
15
15
|
import * as i5 from '@angular/material/button';
|
|
16
16
|
import { MatButtonModule } from '@angular/material/button';
|
|
@@ -30,39 +30,178 @@ import { ContenteditableDirective } from '@rxap/contenteditable';
|
|
|
30
30
|
import { IconDirective } from '@rxap/material-directives/icon';
|
|
31
31
|
|
|
32
32
|
function isSelectionChange(obj) {
|
|
33
|
-
return !!obj &&
|
|
33
|
+
return !!obj && obj['added'] !== undefined && obj['removed'] !== undefined;
|
|
34
34
|
}
|
|
35
35
|
const RXAP_TREE_DATA_SOURCE_ROOT_REMOTE_METHOD = new InjectionToken('rxap/tree/data-source/root-remote-method');
|
|
36
36
|
const RXAP_TREE_DATA_SOURCE_CHILDREN_REMOTE_METHOD = new InjectionToken('rxap/tree/data-source/children-remote-method');
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
const RXAP_TREE_DATA_SOURCE_APPLY_FILTER_METHOD = new InjectionToken('rxap/tree/data-source/apply-filter-method');
|
|
38
|
+
function flatTree(tree, all = false) {
|
|
39
|
+
tree = coerceArray(tree);
|
|
40
|
+
function flat(acc, list) {
|
|
41
|
+
return [...acc, ...list];
|
|
42
|
+
}
|
|
43
|
+
const _flatTree = (node) => {
|
|
44
|
+
if (!Array.isArray(node.children)) {
|
|
45
|
+
if (isDevMode()) {
|
|
46
|
+
console.log(node);
|
|
47
|
+
}
|
|
48
|
+
throw new Error('Node has not defined children');
|
|
49
|
+
}
|
|
50
|
+
if (all || node.expanded) {
|
|
51
|
+
return [
|
|
52
|
+
node,
|
|
53
|
+
...node.children.map((child) => _flatTree(child)).reduce(flat, []),
|
|
54
|
+
];
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
return [node];
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
return tree
|
|
61
|
+
.map((child) => _flatTree(child))
|
|
62
|
+
.reduce((acc, items) => [...acc, ...items], []);
|
|
63
|
+
}
|
|
64
|
+
class DefaultTreeApplyFilterMethod {
|
|
65
|
+
constructor() {
|
|
66
|
+
this.lastFilter = null;
|
|
67
|
+
}
|
|
68
|
+
call({ tree, filter, scopeTypes }) {
|
|
69
|
+
const nodes = flatTree(tree, true);
|
|
70
|
+
if (this.isEqualToLastFilter(filter)) {
|
|
71
|
+
return flatTree(tree, false).filter(node => node.isVisible);
|
|
72
|
+
}
|
|
73
|
+
const hasScopeFilter = (filter.scope &&
|
|
74
|
+
Object.keys(filter.scope) &&
|
|
75
|
+
Object.values(filter.scope).some(list => list.length > 0));
|
|
76
|
+
// if not scope and the search filter is an empty string, collapse all non-root nodes
|
|
77
|
+
if (!filter.search && filter.search !== this.lastFilter?.search) {
|
|
78
|
+
nodes
|
|
79
|
+
.filter(node => node.parent)
|
|
80
|
+
.forEach(node => node.collapse({ quite: true }));
|
|
81
|
+
}
|
|
82
|
+
if (filter.search || hasScopeFilter) {
|
|
83
|
+
nodes.forEach(node => node.hide());
|
|
84
|
+
for (const [type, list] of Object.entries(filter.scope ?? {})) {
|
|
85
|
+
for (const node of nodes) {
|
|
86
|
+
if (node.type === type) {
|
|
87
|
+
if (list.some(item => item.uuid === node.id)) {
|
|
88
|
+
node.show({ forEachChildren: true });
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
if (filter.search) {
|
|
94
|
+
for (const node of nodes) {
|
|
95
|
+
if (hasScopeFilter && node.hidden) {
|
|
96
|
+
// if the filter has a scope filter. Only check the search filter on nodes that are shown by the scope
|
|
97
|
+
// filter
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
const display = node.display?.toLowerCase();
|
|
101
|
+
if (display) {
|
|
102
|
+
if (display.includes(filter.search.toLowerCase())) {
|
|
103
|
+
node.show({ parents: true });
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
node.hide();
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
// if node has no display, it is not shown
|
|
111
|
+
node.hide();
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
// hide each node that has no visible children
|
|
115
|
+
// there exists the edge case that a node has visible children, but the node.hide() function is called
|
|
116
|
+
// after the child.show({ parent:true })
|
|
117
|
+
for (const node of nodes.filter(n => n.hidden && n.hasChildren && n.children.some(child => child.isVisible))) {
|
|
118
|
+
if (node.hidden) {
|
|
119
|
+
console.warn('Edge case detected. Node has visible children but is hidden.');
|
|
120
|
+
node.show();
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
// expand each node that has visible children
|
|
124
|
+
for (const node of nodes.filter(n => n.hasChildren)) {
|
|
125
|
+
if (node.children.some(child => child.isVisible)) {
|
|
126
|
+
// set quite to true to prevent the tree from reloading -> this would result in a infinite loop
|
|
127
|
+
node.expand({ quite: true });
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
nodes.forEach(node => node.show());
|
|
134
|
+
}
|
|
135
|
+
this.lastFilter = filter;
|
|
136
|
+
return flatTree(tree, false).filter(node => node.isVisible);
|
|
137
|
+
}
|
|
138
|
+
isEqualToLastFilter(filter) {
|
|
139
|
+
if (this.lastFilter) {
|
|
140
|
+
if (this.lastFilter.search === filter.search) {
|
|
141
|
+
if (this.lastFilter.scope && filter.scope) {
|
|
142
|
+
if (Object.keys(this.lastFilter.scope).every(key => Object.keys(filter.scope).includes(key))) {
|
|
143
|
+
if (Object.entries(this.lastFilter.scope)
|
|
144
|
+
.every(([key, scope]) => scope.some(item => filter.scope[key].includes(item)))) {
|
|
145
|
+
return true;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
if (filter.scope === this.lastFilter.scope) {
|
|
150
|
+
return true;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return false;
|
|
155
|
+
}
|
|
156
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: DefaultTreeApplyFilterMethod, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
157
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: DefaultTreeApplyFilterMethod }); }
|
|
158
|
+
}
|
|
159
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: DefaultTreeApplyFilterMethod, decorators: [{
|
|
160
|
+
type: Injectable
|
|
161
|
+
}] });
|
|
162
|
+
let TreeDataSource = class TreeDataSource extends BaseDataSource {
|
|
163
|
+
constructor(rootRemoteMethod, childrenRemoteMethod = null, applyFilterMethod = null, metadata = null) {
|
|
39
164
|
super(metadata);
|
|
40
165
|
this.rootRemoteMethod = rootRemoteMethod;
|
|
41
166
|
this.childrenRemoteMethod = childrenRemoteMethod;
|
|
42
167
|
this.tree$ = new BehaviorSubject([]);
|
|
43
|
-
this.loading$ = new ToggleSubject(true);
|
|
44
|
-
// TODO : änlich problem wie bei der redundaten expand SelectionModel.
|
|
45
|
-
this._data$ = new BehaviorSubject([]);
|
|
46
168
|
this._expandedLocalStorageSubscription = null;
|
|
47
169
|
this._selectedLocalStorageSubscription = null;
|
|
170
|
+
// TODO : änlich problem wie bei der redundaten expand SelectionModel.
|
|
171
|
+
this.loading$ = new ToggleSubject(true);
|
|
172
|
+
this.searchForm = null;
|
|
48
173
|
// im localStorage wird nur die id gespeichert.
|
|
49
174
|
this._preSelected = [];
|
|
175
|
+
this._data$ = new BehaviorSubject([]);
|
|
50
176
|
this._refreshMatchFilter = new Subject();
|
|
51
177
|
this._nodeParameters = null;
|
|
52
178
|
this.toDisplay = () => 'to display function not defined';
|
|
53
179
|
this.getIcon = () => null;
|
|
180
|
+
this.getType = () => null;
|
|
54
181
|
this.getStyle = () => ({});
|
|
55
182
|
this.hasDetails = () => true;
|
|
56
183
|
this.matchFilter = () => true;
|
|
57
|
-
this.
|
|
58
|
-
.pipe(map((tree) => tree
|
|
59
|
-
.map((child) => this.flatTree(child))
|
|
60
|
-
.reduce((acc, nodes) => [...acc, ...nodes], [])))
|
|
61
|
-
.subscribe(this._data$);
|
|
184
|
+
this.applyFilterMethod = applyFilterMethod ?? new DefaultTreeApplyFilterMethod();
|
|
62
185
|
// TODO add new SelectModel class that saves the select model to the localStorage
|
|
63
186
|
this.initSelected();
|
|
64
187
|
this.initExpanded();
|
|
65
188
|
}
|
|
189
|
+
ngOnInit() {
|
|
190
|
+
if (this.searchForm) {
|
|
191
|
+
combineLatest([
|
|
192
|
+
this.tree$,
|
|
193
|
+
this.searchForm.rxapFormGroup.value$,
|
|
194
|
+
]).pipe(switchMap(async ([tree, filter]) => await this.applyFilterMethod.call({
|
|
195
|
+
tree,
|
|
196
|
+
filter,
|
|
197
|
+
scopeTypes: this.metadata?.scopeTypes,
|
|
198
|
+
})), map(nodes => coerceArray(nodes)))
|
|
199
|
+
.subscribe(data => this._data$.next(data));
|
|
200
|
+
}
|
|
201
|
+
else {
|
|
202
|
+
this.tree$.pipe(map(tree => flatTree(tree).filter(node => node.isVisible)), tap(nodes => nodes.forEach(node => node.show()))).subscribe(data => this._data$.next(data));
|
|
203
|
+
}
|
|
204
|
+
}
|
|
66
205
|
get nodeParameters() {
|
|
67
206
|
return this._nodeParameters;
|
|
68
207
|
}
|
|
@@ -75,10 +214,10 @@ class TreeDataSource extends BaseDataSource {
|
|
|
75
214
|
const root = await this.getRoot();
|
|
76
215
|
let rootNodes;
|
|
77
216
|
if (Array.isArray(root)) {
|
|
78
|
-
rootNodes = await Promise.all(root.map((node) => this._toNode(node)));
|
|
217
|
+
rootNodes = await Promise.all(root.map((node) => this._toNode(null, node)));
|
|
79
218
|
}
|
|
80
219
|
else {
|
|
81
|
-
rootNodes = [await this._toNode(root)];
|
|
220
|
+
rootNodes = [await this._toNode(null, root)];
|
|
82
221
|
}
|
|
83
222
|
this.tree$.next(rootNodes);
|
|
84
223
|
this.loading$.disable();
|
|
@@ -114,44 +253,60 @@ class TreeDataSource extends BaseDataSource {
|
|
|
114
253
|
return Promise.resolve();
|
|
115
254
|
}
|
|
116
255
|
// - the SelectModel that stores the selection into the local storage?
|
|
117
|
-
async _toNode(item, depth = 0, onExpand = this.expandNode.bind(this), onCollapse = this.collapseNode.bind(this), onSelect = this.selectNode.bind(this), onDeselect = this.deselectNode.bind(this)) {
|
|
118
|
-
const node = await this.toNode(item, depth, onExpand, onCollapse, onSelect, onDeselect);
|
|
256
|
+
async _toNode(parent, item, depth = 0, onExpand = this.expandNode.bind(this), onCollapse = this.collapseNode.bind(this), onSelect = this.selectNode.bind(this), onDeselect = this.deselectNode.bind(this)) {
|
|
257
|
+
const node = await this.toNode(parent, item, depth, onExpand, onCollapse, onSelect, onDeselect);
|
|
119
258
|
if (this.expanded.isSelected(node.id)) {
|
|
120
259
|
node
|
|
121
260
|
.expand()
|
|
122
261
|
.then(() => {
|
|
123
|
-
// TODO : remove redundant this.expanded SelectionModel. Only store expanded nodes in
|
|
124
|
-
// das problem ist das ich beim speicher in localStorage nur die id speicher.
|
|
125
|
-
// Des wegen kann ich beim laden aus dem localStorage this.treeControl.expansionModel
|
|
126
|
-
//
|
|
127
|
-
//
|
|
128
|
-
// - das node object läde die entity mithilfe der id automatisch nach
|
|
262
|
+
// TODO : remove redundant this.expanded SelectionModel. Only store expanded nodes in
|
|
263
|
+
// this.treeControl.expansionModel das problem ist das ich beim speicher in localStorage nur die id speicher.
|
|
264
|
+
// Des wegen kann ich beim laden aus dem localStorage this.treeControl.expansionModel nicht einfach mit den
|
|
265
|
+
// expanend nodes fullen. Da dort das node object benötigt wird möglich lösungen: - das node object läde die
|
|
266
|
+
// entity mithilfe der id automatisch nach
|
|
129
267
|
this.treeControl.expansionModel.select(node);
|
|
130
|
-
console.debug(`Restore expand for node '${node.id}' SUCCESSFULLY`);
|
|
131
|
-
})
|
|
132
|
-
|
|
268
|
+
// console.debug(`Restore expand for node '${node.id}' SUCCESSFULLY`);
|
|
269
|
+
});
|
|
270
|
+
// .catch(() =>
|
|
271
|
+
// console.debug(`Restore expand for node '${node.id}' FAILED`)
|
|
272
|
+
// );
|
|
133
273
|
}
|
|
134
274
|
if (this._preSelected.includes(node.id)) {
|
|
135
275
|
await node
|
|
136
|
-
.select()
|
|
137
|
-
|
|
138
|
-
|
|
276
|
+
.select();
|
|
277
|
+
// .then(() =>
|
|
278
|
+
// console.debug(`Restore select for node '${node.id}' SUCCESSFULLY`)
|
|
279
|
+
// )
|
|
280
|
+
// .catch(() =>
|
|
281
|
+
// console.debug(`Restore select for node '${node.id}' FAILED`)
|
|
282
|
+
// );
|
|
139
283
|
}
|
|
140
284
|
return node;
|
|
141
285
|
}
|
|
142
|
-
async expandNode(node) {
|
|
286
|
+
async expandNode(node, options) {
|
|
287
|
+
if (!options?.onlySelf) {
|
|
288
|
+
// required to sync the expanstion state with the tree control
|
|
289
|
+
// if the collpase is trigged by node.expand this state is not
|
|
290
|
+
// sync with the tree control
|
|
291
|
+
this.treeControl.expansionModel.select(node);
|
|
292
|
+
}
|
|
143
293
|
if (node.item.hasChildren && !node.item.children?.length) {
|
|
144
294
|
node.isLoading$.enable();
|
|
145
295
|
const children = await this.getChildren(node);
|
|
146
296
|
// add the loaded children to the item object
|
|
147
297
|
node.item.children = children;
|
|
148
|
-
node.addChildren(await Promise.all(children.map((child) => this._toNode(child, node.depth + 1, node.onExpand, node.onCollapse))));
|
|
298
|
+
node.addChildren(await Promise.all(children.map((child) => this._toNode(node, child, node.depth + 1, node.onExpand, node.onCollapse))));
|
|
149
299
|
node.isLoading$.disable();
|
|
150
300
|
}
|
|
151
301
|
this.expanded.select(node.id);
|
|
152
|
-
|
|
302
|
+
if (!options?.quite) {
|
|
303
|
+
this.tree$.next(this.tree$.value);
|
|
304
|
+
}
|
|
153
305
|
}
|
|
154
306
|
async getChildren(node) {
|
|
307
|
+
if (!this.childrenRemoteMethod) {
|
|
308
|
+
throw new Error(`The node '${node.id}' has unloaded children but the RXAP_TREE_DATA_SOURCE_CHILDREN_REMOTE_METHOD is not provided.`);
|
|
309
|
+
}
|
|
155
310
|
return this.childrenRemoteMethod.call(node);
|
|
156
311
|
}
|
|
157
312
|
async getRoot() {
|
|
@@ -179,36 +334,30 @@ class TreeDataSource extends BaseDataSource {
|
|
|
179
334
|
.map((node) => getNodeById(node, id))
|
|
180
335
|
.filter(Boolean)[0] || null);
|
|
181
336
|
}
|
|
182
|
-
async toNode(item, depth = 0, onExpand = this.expandNode.bind(this), onCollapse = this.collapseNode.bind(this), onSelect = this.selectNode.bind(this), onDeselect = this.deselectNode.bind(this)) {
|
|
183
|
-
return Node.ToNode(item, depth, onExpand, onCollapse, this.toDisplay, this.getIcon, onSelect, onDeselect, this.hasDetails, this.getStyle, this.nodeParameters);
|
|
337
|
+
async toNode(parent, item, depth = 0, onExpand = this.expandNode.bind(this), onCollapse = this.collapseNode.bind(this), onSelect = this.selectNode.bind(this), onDeselect = this.deselectNode.bind(this)) {
|
|
338
|
+
return Node.ToNode(parent, item, depth, onExpand, onCollapse, this.toDisplay, this.getIcon, this.getType, onSelect, onDeselect, this.hasDetails, this.getStyle, this.nodeParameters);
|
|
184
339
|
}
|
|
185
|
-
collapseNode(node) {
|
|
340
|
+
collapseNode(node, options) {
|
|
341
|
+
if (!options?.onlySelf) {
|
|
342
|
+
// required to sync the expanstion state with the tree control
|
|
343
|
+
// if the collpase is trigged by node.colapse this state is not
|
|
344
|
+
// sync with the tree control
|
|
345
|
+
this.treeControl.expansionModel.deselect(node);
|
|
346
|
+
}
|
|
186
347
|
this.expanded.deselect(node.id);
|
|
187
|
-
|
|
348
|
+
if (!options?.quite) {
|
|
349
|
+
this.tree$.next(this.tree$.value);
|
|
350
|
+
}
|
|
188
351
|
return Promise.resolve();
|
|
189
352
|
}
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
}
|
|
199
|
-
throw new Error('Node has not defined children');
|
|
200
|
-
}
|
|
201
|
-
if (node.expanded || this.expanded.isSelected(node.id)) {
|
|
202
|
-
return [
|
|
203
|
-
node,
|
|
204
|
-
...node.children.map((child) => flatTree(child)).reduce(flat, []),
|
|
205
|
-
];
|
|
206
|
-
}
|
|
207
|
-
else {
|
|
208
|
-
return [node];
|
|
209
|
-
}
|
|
210
|
-
};
|
|
211
|
-
return flatTree(tree);
|
|
353
|
+
/**
|
|
354
|
+
* Converts the tree structure into a list.
|
|
355
|
+
*
|
|
356
|
+
* @param tree
|
|
357
|
+
* @param all true - include nodes children that are not expanded
|
|
358
|
+
*/
|
|
359
|
+
flatTree(tree, all = false) {
|
|
360
|
+
return flatTree(tree, all);
|
|
212
361
|
}
|
|
213
362
|
destroy() {
|
|
214
363
|
super.destroy();
|
|
@@ -255,6 +404,9 @@ class TreeDataSource extends BaseDataSource {
|
|
|
255
404
|
setGetStyle(getStyle = this.getStyle) {
|
|
256
405
|
this.getStyle = getStyle;
|
|
257
406
|
}
|
|
407
|
+
setGetType(getType = this.getType) {
|
|
408
|
+
this.getType = getType;
|
|
409
|
+
}
|
|
258
410
|
/**
|
|
259
411
|
* recall the getStyle, getIcon and toDisplay methods
|
|
260
412
|
* and update the node objects
|
|
@@ -262,25 +414,29 @@ class TreeDataSource extends BaseDataSource {
|
|
|
262
414
|
updateNodes() {
|
|
263
415
|
this._data$.value.forEach(node => {
|
|
264
416
|
node.style = this.getStyle(node.item);
|
|
265
|
-
node.icon = this.getIcon(node.item);
|
|
417
|
+
node.icon = coerceArray(this.getIcon(node.item));
|
|
266
418
|
node.display = this.toDisplay(node.item);
|
|
267
419
|
});
|
|
268
420
|
this._data$.next(this._data$.value);
|
|
269
421
|
}
|
|
270
422
|
_connect(collectionViewer) {
|
|
271
|
-
this.
|
|
423
|
+
this.init();
|
|
424
|
+
this.treeControl.expansionModel.changed.pipe(tap(async (change) => {
|
|
272
425
|
if (isSelectionChange(change)) {
|
|
426
|
+
const promiseList = [];
|
|
273
427
|
if (change.added) {
|
|
274
|
-
change.added.
|
|
428
|
+
promiseList.push(...change.added.map((node) => node.expand({ onlySelf: true, quite: true })));
|
|
275
429
|
}
|
|
276
430
|
if (change.removed) {
|
|
277
|
-
change.removed
|
|
431
|
+
promiseList.push(...change.removed
|
|
278
432
|
.slice()
|
|
279
433
|
.reverse()
|
|
280
|
-
.
|
|
434
|
+
.map((node) => node.collapse({ onlySelf: true, quite: true })));
|
|
281
435
|
}
|
|
436
|
+
await Promise.all(promiseList);
|
|
437
|
+
this.tree$.next(this.tree$.value);
|
|
282
438
|
}
|
|
283
|
-
});
|
|
439
|
+
})).subscribe();
|
|
284
440
|
let loadRoot = Promise.resolve();
|
|
285
441
|
if (this.tree$.value.length === 0) {
|
|
286
442
|
loadRoot = this.getTreeRoot();
|
|
@@ -325,7 +481,7 @@ class TreeDataSource extends BaseDataSource {
|
|
|
325
481
|
this._preSelected = JSON.parse(localStorage.getItem(key));
|
|
326
482
|
}
|
|
327
483
|
catch (e) {
|
|
328
|
-
console.
|
|
484
|
+
console.error('parse expanded tree data source nodes failed');
|
|
329
485
|
}
|
|
330
486
|
}
|
|
331
487
|
}
|
|
@@ -345,7 +501,7 @@ class TreeDataSource extends BaseDataSource {
|
|
|
345
501
|
expanded = JSON.parse(localStorage.getItem(key));
|
|
346
502
|
}
|
|
347
503
|
catch (e) {
|
|
348
|
-
console.
|
|
504
|
+
console.error('parse expanded tree data source nodes failed');
|
|
349
505
|
}
|
|
350
506
|
}
|
|
351
507
|
}
|
|
@@ -356,21 +512,38 @@ class TreeDataSource extends BaseDataSource {
|
|
|
356
512
|
.subscribe();
|
|
357
513
|
}
|
|
358
514
|
}
|
|
359
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: TreeDataSource, deps: [{ token: RXAP_TREE_DATA_SOURCE_ROOT_REMOTE_METHOD }, { token: RXAP_TREE_DATA_SOURCE_CHILDREN_REMOTE_METHOD }, { token: RXAP_DATA_SOURCE_METADATA }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
515
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: TreeDataSource, deps: [{ token: RXAP_TREE_DATA_SOURCE_ROOT_REMOTE_METHOD }, { token: RXAP_TREE_DATA_SOURCE_CHILDREN_REMOTE_METHOD, optional: true }, { token: RXAP_TREE_DATA_SOURCE_APPLY_FILTER_METHOD, optional: true }, { token: RXAP_DATA_SOURCE_METADATA, optional: true }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
360
516
|
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: TreeDataSource }); }
|
|
361
|
-
}
|
|
517
|
+
};
|
|
518
|
+
__decorate([
|
|
519
|
+
Required,
|
|
520
|
+
__metadata("design:type", FlatTreeControl)
|
|
521
|
+
], TreeDataSource.prototype, "treeControl", void 0);
|
|
522
|
+
TreeDataSource = __decorate([
|
|
523
|
+
RxapDataSource('tree'),
|
|
524
|
+
__metadata("design:paramtypes", [Object, Object, Object, Object])
|
|
525
|
+
], TreeDataSource);
|
|
362
526
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.4", ngImport: i0, type: TreeDataSource, decorators: [{
|
|
363
527
|
type: Injectable
|
|
364
528
|
}], ctorParameters: function () { return [{ type: undefined, decorators: [{
|
|
365
529
|
type: Inject,
|
|
366
530
|
args: [RXAP_TREE_DATA_SOURCE_ROOT_REMOTE_METHOD]
|
|
367
531
|
}] }, { type: undefined, decorators: [{
|
|
532
|
+
type: Optional
|
|
533
|
+
}, {
|
|
368
534
|
type: Inject,
|
|
369
535
|
args: [RXAP_TREE_DATA_SOURCE_CHILDREN_REMOTE_METHOD]
|
|
370
536
|
}] }, { type: undefined, decorators: [{
|
|
537
|
+
type: Optional
|
|
538
|
+
}, {
|
|
539
|
+
type: Inject,
|
|
540
|
+
args: [RXAP_TREE_DATA_SOURCE_APPLY_FILTER_METHOD]
|
|
541
|
+
}] }, { type: undefined, decorators: [{
|
|
542
|
+
type: Optional
|
|
543
|
+
}, {
|
|
371
544
|
type: Inject,
|
|
372
545
|
args: [RXAP_DATA_SOURCE_METADATA]
|
|
373
|
-
}] }]; } });
|
|
546
|
+
}] }]; }, propDecorators: { treeControl: [] } });
|
|
374
547
|
|
|
375
548
|
class TreeContentDirective {
|
|
376
549
|
constructor(template) {
|
|
@@ -571,5 +744,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.1.4", ngImpor
|
|
|
571
744
|
* Generated bundle index. Do not edit.
|
|
572
745
|
*/
|
|
573
746
|
|
|
574
|
-
export { RXAP_TREE_CONTENT_EDITABLE_METHOD, RXAP_TREE_DATA_SOURCE_CHILDREN_REMOTE_METHOD, RXAP_TREE_DATA_SOURCE_ROOT_REMOTE_METHOD, TreeComponent, TreeContentDirective, TreeDataSource, isSelectionChange };
|
|
747
|
+
export { DefaultTreeApplyFilterMethod, RXAP_TREE_CONTENT_EDITABLE_METHOD, RXAP_TREE_DATA_SOURCE_APPLY_FILTER_METHOD, RXAP_TREE_DATA_SOURCE_CHILDREN_REMOTE_METHOD, RXAP_TREE_DATA_SOURCE_ROOT_REMOTE_METHOD, TreeComponent, TreeContentDirective, TreeDataSource, flatTree, isSelectionChange };
|
|
575
748
|
//# sourceMappingURL=rxap-tree.mjs.map
|