@likec4/core 0.6.3 → 0.18.0
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/dist/colors.d.ts +79 -0
- package/dist/colors.js +94 -0
- package/dist/compute-view/EdgeBuilder.d.ts +1 -0
- package/dist/compute-view/EdgeBuilder.js +1 -1
- package/dist/compute-view/compute-ctx.d.ts +18 -0
- package/dist/compute-view/compute-ctx.js +25 -0
- package/dist/compute-view/{compute.element-view.d.ts → compute-element-view.d.ts} +2 -2
- package/dist/compute-view/compute-element-view.js +416 -0
- package/dist/compute-view/{compute-view.d.ts → compute.d.ts} +2 -2
- package/dist/compute-view/{compute-view.js → compute.js} +1 -1
- package/dist/compute-view/index.d.ts +2 -1
- package/dist/compute-view/index.js +1 -1
- package/dist/compute-view/utils/anyPossibleRelations.d.ts +1 -0
- package/dist/compute-view/utils/sortNodes.d.ts +1 -0
- package/dist/index.d.ts +4 -2
- package/dist/index.js +2 -1
- package/dist/model-index/{model-index.d.ts → ModelIndex.d.ts} +1 -0
- package/dist/model-index/{model-index.js → ModelIndex.js} +3 -3
- package/dist/model-index/index.d.ts +2 -1
- package/dist/model-index/index.js +1 -1
- package/dist/types/computed-view.d.ts +1 -0
- package/dist/types/diagram.d.ts +7 -0
- package/dist/types/element.d.ts +3 -2
- package/dist/types/expression.d.ts +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/model.d.ts +1 -0
- package/dist/types/opaque.d.ts +1 -0
- package/dist/types/relation.d.ts +1 -0
- package/dist/types/view.d.ts +1 -0
- package/dist/utils/compute-node-levels.d.ts +8 -0
- package/dist/utils/compute-node-levels.js +31 -0
- package/dist/utils/fqn.d.ts +3 -0
- package/dist/utils/fqn.js +22 -1
- package/dist/utils/guards.d.ts +1 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.js +1 -0
- package/dist/utils/relations.d.ts +3 -1
- package/dist/utils/relations.js +10 -4
- package/package.json +31 -21
- package/dist/compute-view/compute.element-view.js +0 -168
- package/dist/compute-view/utils/evaluate-expression.d.ts +0 -10
- package/dist/compute-view/utils/evaluate-expression.js +0 -186
|
@@ -1,186 +0,0 @@
|
|
|
1
|
-
import { anyPass, map, pluck, uniq } from 'rambdax';
|
|
2
|
-
import * as Expr from '../../types/expression';
|
|
3
|
-
import { failExpectedNever, isAncestor } from '../../utils';
|
|
4
|
-
import { isBetween, isIncoming, isInside, isOutgoing } from '../../utils/relations';
|
|
5
|
-
import { anyPossibleRelations } from './anyPossibleRelations';
|
|
6
|
-
const dropNested = (elements) => {
|
|
7
|
-
return elements.reduce((acc, current) => {
|
|
8
|
-
if (acc.length === 0)
|
|
9
|
-
return [current];
|
|
10
|
-
// current is a child of some in acc
|
|
11
|
-
if (acc.some(p => p.id === current.id || isAncestor(p, current))) {
|
|
12
|
-
return acc;
|
|
13
|
-
}
|
|
14
|
-
return [
|
|
15
|
-
// drop children of current
|
|
16
|
-
...acc.filter(e => !isAncestor(current, e)),
|
|
17
|
-
current
|
|
18
|
-
];
|
|
19
|
-
}, []);
|
|
20
|
-
};
|
|
21
|
-
export const keepLeafs = (elements) => {
|
|
22
|
-
return elements.reduce((acc, current) => {
|
|
23
|
-
if (acc.length === 0)
|
|
24
|
-
return [current];
|
|
25
|
-
// current is an ancestor of some in acc
|
|
26
|
-
if (acc.some(p => p.id === current.id || isAncestor(current, p))) {
|
|
27
|
-
return acc;
|
|
28
|
-
}
|
|
29
|
-
return [
|
|
30
|
-
// drop ancestors of current
|
|
31
|
-
...acc.filter(e => !isAncestor(e, current)),
|
|
32
|
-
current
|
|
33
|
-
];
|
|
34
|
-
}, []);
|
|
35
|
-
};
|
|
36
|
-
const evaluateElementExpression = (index, expr, rootElement = null) => {
|
|
37
|
-
let elements = [];
|
|
38
|
-
let neighbours = [];
|
|
39
|
-
let relations = [];
|
|
40
|
-
// const inOutRelations = (elements: Element[]) => {
|
|
41
|
-
// if (elements.length == 0) return []
|
|
42
|
-
// const filters = dropNested(elements).map(e => isAnyInOut(e.id))
|
|
43
|
-
// return index.filterRelations(anyPass(filters))
|
|
44
|
-
// }
|
|
45
|
-
const allRelationsBetween = (elements) => {
|
|
46
|
-
if (elements.length <= 1)
|
|
47
|
-
return [];
|
|
48
|
-
const filters = [];
|
|
49
|
-
for (const [source, target] of anyPossibleRelations(elements)) {
|
|
50
|
-
filters.push(isBetween(source.id, target.id));
|
|
51
|
-
}
|
|
52
|
-
return filters.length ? index.filterRelations(anyPass(filters)) : [];
|
|
53
|
-
};
|
|
54
|
-
// WildcardExpression
|
|
55
|
-
if (Expr.isWildcard(expr)) {
|
|
56
|
-
if (rootElement) {
|
|
57
|
-
elements = [index.find(rootElement), ...index.children(rootElement)];
|
|
58
|
-
neighbours = [
|
|
59
|
-
...index.siblings(rootElement),
|
|
60
|
-
...index.ancestors(rootElement).flatMap(a => [...index.siblings(a.id)])
|
|
61
|
-
];
|
|
62
|
-
relations = index.filterRelations(anyPass([isInside(rootElement), isIncoming(rootElement), isOutgoing(rootElement)]));
|
|
63
|
-
}
|
|
64
|
-
else {
|
|
65
|
-
elements = index.rootElements();
|
|
66
|
-
neighbours = elements;
|
|
67
|
-
relations = allRelationsBetween(elements);
|
|
68
|
-
}
|
|
69
|
-
return {
|
|
70
|
-
elements,
|
|
71
|
-
neighbours,
|
|
72
|
-
relations
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
// Identifier
|
|
76
|
-
if (Expr.isElementRef(expr)) {
|
|
77
|
-
elements = expr.isDescedants ? index.children(expr.element) : [index.find(expr.element)];
|
|
78
|
-
if (expr.isDescedants) {
|
|
79
|
-
relations = index.filterRelations(isInside(expr.element));
|
|
80
|
-
// relations = index.filterRelations(anyPass([
|
|
81
|
-
// isBetween(expr.element),
|
|
82
|
-
// isIncoming(expr.element),
|
|
83
|
-
// isOutgoing(expr.element),
|
|
84
|
-
// ]))
|
|
85
|
-
// } else {
|
|
86
|
-
// relations = index.filterRelations(anyPass([
|
|
87
|
-
// isIncoming(expr.element),
|
|
88
|
-
// isOutgoing(expr.element)
|
|
89
|
-
// ]))
|
|
90
|
-
}
|
|
91
|
-
return {
|
|
92
|
-
elements,
|
|
93
|
-
neighbours,
|
|
94
|
-
relations
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
failExpectedNever(expr);
|
|
98
|
-
};
|
|
99
|
-
export function evaluateExpression(index, expr, rootElement) {
|
|
100
|
-
const elements = [];
|
|
101
|
-
let neighbours = [];
|
|
102
|
-
let relations = [];
|
|
103
|
-
if (Expr.isInOut(expr)) {
|
|
104
|
-
const targets = evaluateElementExpression(index, expr.inout).elements;
|
|
105
|
-
for (const target of targets) {
|
|
106
|
-
const incoming = index.filterRelations(isIncoming(target.id));
|
|
107
|
-
const outgoing = index.filterRelations(isOutgoing(target.id));
|
|
108
|
-
if (incoming.length + outgoing.length > 0) {
|
|
109
|
-
elements.push(target);
|
|
110
|
-
neighbours = neighbours.concat(map(index.find, [...pluck('source', incoming), ...pluck('target', outgoing)]));
|
|
111
|
-
relations = relations.concat([...incoming, ...outgoing]);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
return {
|
|
115
|
-
elements: uniq(elements),
|
|
116
|
-
neighbours: dropNested(neighbours),
|
|
117
|
-
relations: uniq(relations)
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
if (Expr.isIncoming(expr)) {
|
|
121
|
-
const targets = evaluateElementExpression(index, expr.incoming).elements;
|
|
122
|
-
for (const target of targets) {
|
|
123
|
-
const incoming = index.filterRelations(isIncoming(target.id));
|
|
124
|
-
if (incoming.length > 0) {
|
|
125
|
-
elements.push(target);
|
|
126
|
-
neighbours = neighbours.concat(map(index.find, pluck('source', incoming)));
|
|
127
|
-
relations = relations.concat(incoming);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
return {
|
|
131
|
-
elements: uniq(elements),
|
|
132
|
-
neighbours: dropNested(neighbours),
|
|
133
|
-
relations: uniq(relations)
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
if (Expr.isOutgoing(expr)) {
|
|
137
|
-
const sources = evaluateElementExpression(index, expr.outgoing).elements;
|
|
138
|
-
for (const source of sources) {
|
|
139
|
-
const outgoing = index.filterRelations(isOutgoing(source.id));
|
|
140
|
-
if (outgoing.length > 0) {
|
|
141
|
-
elements.push(source);
|
|
142
|
-
neighbours = neighbours.concat(map(index.find, pluck('target', outgoing)));
|
|
143
|
-
relations = relations.concat(outgoing);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
return {
|
|
147
|
-
elements: uniq(elements),
|
|
148
|
-
neighbours: dropNested(neighbours),
|
|
149
|
-
relations: uniq(relations)
|
|
150
|
-
};
|
|
151
|
-
}
|
|
152
|
-
if (Expr.isRelation(expr)) {
|
|
153
|
-
const isSourceWildcard = Expr.isWildcard(expr.source);
|
|
154
|
-
const isTargetWildcard = Expr.isWildcard(expr.target);
|
|
155
|
-
if (isSourceWildcard && !isTargetWildcard) {
|
|
156
|
-
return evaluateExpression(index, {
|
|
157
|
-
incoming: expr.target
|
|
158
|
-
}, rootElement);
|
|
159
|
-
}
|
|
160
|
-
if (!isSourceWildcard && isTargetWildcard) {
|
|
161
|
-
return evaluateExpression(index, {
|
|
162
|
-
outgoing: expr.source
|
|
163
|
-
}, rootElement);
|
|
164
|
-
}
|
|
165
|
-
const sources = evaluateElementExpression(index, expr.source).elements;
|
|
166
|
-
const targets = evaluateElementExpression(index, expr.target).elements;
|
|
167
|
-
for (const source of sources) {
|
|
168
|
-
for (const target of targets) {
|
|
169
|
-
if (isAncestor(source.id, target.id) || isAncestor(target.id, source.id)) {
|
|
170
|
-
continue;
|
|
171
|
-
}
|
|
172
|
-
const foundRelations = index.filterRelations(isBetween(source.id, target.id));
|
|
173
|
-
if (foundRelations.length > 0) {
|
|
174
|
-
relations = relations.concat(foundRelations);
|
|
175
|
-
neighbours.push(source, target);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
return {
|
|
180
|
-
elements,
|
|
181
|
-
neighbours: uniq(neighbours),
|
|
182
|
-
relations: uniq(relations)
|
|
183
|
-
};
|
|
184
|
-
}
|
|
185
|
-
return evaluateElementExpression(index, expr, rootElement);
|
|
186
|
-
}
|