1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | Object.defineProperty(exports, "__esModule", { value: true });
|
18 | exports.TreeSourceNode = exports.CompositeTreeElementNode = exports.TreeElementNode = exports.SourceTree = void 0;
|
19 | const tslib_1 = require("tslib");
|
20 |
|
21 | const inversify_1 = require("inversify");
|
22 | const tree_1 = require("../tree");
|
23 | const tree_source_1 = require("./tree-source");
|
24 | let SourceTree = class SourceTree extends tree_1.TreeImpl {
|
25 | async resolveChildren(parent) {
|
26 | const elements = await this.resolveElements(parent);
|
27 | const nodes = [];
|
28 | let index = 0;
|
29 | for (const element of elements) {
|
30 | if (element.visible !== false) {
|
31 | nodes.push(this.toNode(element, index++, parent));
|
32 | }
|
33 | }
|
34 | return nodes;
|
35 | }
|
36 | resolveElements(parent) {
|
37 | if (TreeSourceNode.is(parent)) {
|
38 | return parent.source.getElements();
|
39 | }
|
40 | return parent.element.getElements();
|
41 | }
|
42 | toNode(element, index, parent) {
|
43 | const id = element.id ? String(element.id) : (parent.id + ':' + index);
|
44 | const name = id;
|
45 | const existing = this.getNode(id);
|
46 | const updated = existing && Object.assign(existing, { element, parent });
|
47 | if (tree_source_1.CompositeTreeElement.hasElements(element)) {
|
48 | if (updated) {
|
49 | if (!tree_1.ExpandableTreeNode.is(updated)) {
|
50 | Object.assign(updated, { expanded: false });
|
51 | }
|
52 | if (!tree_1.CompositeTreeNode.is(updated)) {
|
53 | Object.assign(updated, { children: [] });
|
54 | }
|
55 | return updated;
|
56 | }
|
57 | return {
|
58 | element,
|
59 | parent,
|
60 | id,
|
61 | name,
|
62 | selected: false,
|
63 | expanded: false,
|
64 | children: []
|
65 | };
|
66 | }
|
67 | if (CompositeTreeElementNode.is(updated)) {
|
68 | delete updated.expanded;
|
69 | delete updated.children;
|
70 | }
|
71 | if (updated) {
|
72 | if (tree_1.ExpandableTreeNode.is(updated)) {
|
73 | delete updated.expanded;
|
74 | }
|
75 | if (tree_1.CompositeTreeNode.is(updated)) {
|
76 | delete updated.children;
|
77 | }
|
78 | return updated;
|
79 | }
|
80 | return {
|
81 | element,
|
82 | parent,
|
83 | id,
|
84 | name,
|
85 | selected: false
|
86 | };
|
87 | }
|
88 | };
|
89 | SourceTree = (0, tslib_1.__decorate)([
|
90 | (0, inversify_1.injectable)()
|
91 | ], SourceTree);
|
92 | exports.SourceTree = SourceTree;
|
93 | var TreeElementNode;
|
94 | (function (TreeElementNode) {
|
95 | function is(node) {
|
96 | return tree_1.SelectableTreeNode.is(node) && 'element' in node;
|
97 | }
|
98 | TreeElementNode.is = is;
|
99 | })(TreeElementNode = exports.TreeElementNode || (exports.TreeElementNode = {}));
|
100 | var CompositeTreeElementNode;
|
101 | (function (CompositeTreeElementNode) {
|
102 | function is(node) {
|
103 | return TreeElementNode.is(node) && tree_1.CompositeTreeNode.is(node) && tree_1.ExpandableTreeNode.is(node) && !!node.visible;
|
104 | }
|
105 | CompositeTreeElementNode.is = is;
|
106 | })(CompositeTreeElementNode = exports.CompositeTreeElementNode || (exports.CompositeTreeElementNode = {}));
|
107 | var TreeSourceNode;
|
108 | (function (TreeSourceNode) {
|
109 | function is(node) {
|
110 | return tree_1.CompositeTreeNode.is(node) && !node.visible && 'source' in node;
|
111 | }
|
112 | TreeSourceNode.is = is;
|
113 | function to(source) {
|
114 | if (!source) {
|
115 | return source;
|
116 | }
|
117 | const id = source.id || '__source__';
|
118 | return {
|
119 | id,
|
120 | name: id,
|
121 | visible: false,
|
122 | children: [],
|
123 | source,
|
124 | parent: undefined,
|
125 | selected: false
|
126 | };
|
127 | }
|
128 | TreeSourceNode.to = to;
|
129 | })(TreeSourceNode = exports.TreeSourceNode || (exports.TreeSourceNode = {}));
|
130 |
|
\ | No newline at end of file |