@likec4/core 0.31.0 → 0.33.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/README.md +13 -2
- package/dist/colors.d.ts +82 -15
- package/dist/colors.js +116 -87
- package/dist/colors.mjs +112 -0
- package/dist/compute-view/EdgeBuilder.d.ts +0 -1
- package/dist/compute-view/EdgeBuilder.js +37 -34
- package/dist/compute-view/EdgeBuilder.mjs +31 -0
- package/dist/compute-view/compute-ctx.d.ts +0 -1
- package/dist/compute-view/compute-ctx.js +33 -24
- package/dist/compute-view/compute-ctx.mjs +42 -0
- package/dist/compute-view/compute-element-view.d.ts +2 -3
- package/dist/compute-view/compute-element-view.js +137 -469
- package/dist/compute-view/compute-element-view.mjs +145 -0
- package/dist/compute-view/compute-predicates.d.ts +16 -0
- package/dist/compute-view/compute-predicates.js +358 -0
- package/dist/compute-view/compute-predicates.mjs +324 -0
- package/dist/compute-view/compute.d.ts +8 -9
- package/dist/compute-view/compute.js +49 -39
- package/dist/compute-view/compute.mjs +39 -0
- package/dist/compute-view/index.d.ts +1 -1
- package/dist/compute-view/index.js +24 -2
- package/dist/compute-view/index.mjs +1 -0
- package/dist/compute-view/utils/anyPossibleRelations.d.ts +0 -1
- package/dist/compute-view/utils/anyPossibleRelations.js +17 -12
- package/dist/compute-view/utils/anyPossibleRelations.mjs +12 -0
- package/dist/compute-view/utils/applyViewRuleStyles.d.ts +3 -0
- package/dist/compute-view/utils/applyViewRuleStyles.js +59 -0
- package/dist/compute-view/utils/applyViewRuleStyles.mjs +50 -0
- package/dist/compute-view/utils/sortNodes.d.ts +0 -1
- package/dist/compute-view/utils/sortNodes.js +47 -40
- package/dist/compute-view/utils/sortNodes.mjs +40 -0
- package/dist/errors/_base.d.ts +0 -1
- package/dist/errors/_base.js +14 -11
- package/dist/errors/_base.mjs +4 -0
- package/dist/errors/index.d.ts +2 -1
- package/dist/errors/index.js +60 -4
- package/dist/errors/index.mjs +5 -0
- package/dist/errors/invariant.d.ts +0 -1
- package/dist/errors/invariant.js +16 -16
- package/dist/errors/invariant.mjs +8 -0
- package/dist/errors/model-index.d.ts +0 -1
- package/dist/errors/model-index.js +16 -14
- package/dist/errors/model-index.mjs +8 -0
- package/dist/errors/non-nullable.d.ts +2 -0
- package/dist/errors/non-nullable.js +16 -0
- package/dist/errors/non-nullable.mjs +8 -0
- package/dist/errors/nonexhaustive.d.ts +2 -0
- package/dist/errors/nonexhaustive.js +13 -0
- package/dist/errors/nonexhaustive.mjs +5 -0
- package/dist/index.d.ts +6 -3
- package/dist/index.js +71 -7
- package/dist/index.mjs +6 -0
- package/dist/model-index/ModelIndex.d.ts +0 -1
- package/dist/model-index/ModelIndex.js +125 -124
- package/dist/model-index/ModelIndex.mjs +128 -0
- package/dist/model-index/index.d.ts +0 -1
- package/dist/model-index/index.js +13 -2
- package/dist/model-index/index.mjs +1 -0
- package/dist/types/_common.d.ts +2 -1
- package/dist/types/_common.js +1 -2
- package/dist/types/_common.mjs +0 -0
- package/dist/types/computed-view.d.ts +9 -7
- package/dist/types/computed-view.js +1 -2
- package/dist/types/computed-view.mjs +0 -0
- package/dist/types/diagram.d.ts +5 -2
- package/dist/types/diagram.js +1 -2
- package/dist/types/diagram.mjs +0 -0
- package/dist/types/element.d.ts +5 -8
- package/dist/types/element.js +13 -5
- package/dist/types/element.mjs +5 -0
- package/dist/types/expression.d.ts +0 -1
- package/dist/types/expression.js +45 -31
- package/dist/types/expression.mjs +30 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.js +48 -4
- package/dist/types/index.mjs +3 -0
- package/dist/types/model.d.ts +0 -1
- package/dist/types/model.js +1 -2
- package/dist/types/model.mjs +0 -0
- package/dist/types/opaque.d.ts +0 -1
- package/dist/types/opaque.js +1 -2
- package/dist/types/opaque.mjs +0 -0
- package/dist/types/relation.d.ts +0 -1
- package/dist/types/relation.js +1 -2
- package/dist/types/relation.mjs +0 -0
- package/dist/types/theme.d.ts +22 -0
- package/dist/types/theme.js +1 -0
- package/dist/types/theme.mjs +0 -0
- package/dist/types/view.d.ts +4 -3
- package/dist/types/view.js +15 -8
- package/dist/types/view.mjs +9 -0
- package/dist/utils/compute-node-levels.d.ts +0 -1
- package/dist/utils/compute-node-levels.js +45 -29
- package/dist/utils/compute-node-levels.mjs +31 -0
- package/dist/utils/fqn.d.ts +12 -7
- package/dist/utils/fqn.js +73 -76
- package/dist/utils/fqn.mjs +66 -0
- package/dist/utils/guards.d.ts +2 -3
- package/dist/utils/guards.js +19 -11
- package/dist/utils/guards.mjs +13 -0
- package/dist/utils/index.d.ts +0 -1
- package/dist/utils/index.js +49 -5
- package/dist/utils/index.mjs +4 -0
- package/dist/utils/relations.d.ts +11 -7
- package/dist/utils/relations.js +56 -43
- package/dist/utils/relations.mjs +42 -0
- package/package.json +25 -49
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { difference } from "rambdax";
|
|
2
|
+
export class ComputeCtx {
|
|
3
|
+
constructor(index, root, elements = /* @__PURE__ */ new Set(), relations = /* @__PURE__ */ new Set(), implicits = /* @__PURE__ */ new Set()) {
|
|
4
|
+
this.index = index;
|
|
5
|
+
this.root = root;
|
|
6
|
+
this.elements = elements;
|
|
7
|
+
this.relations = relations;
|
|
8
|
+
this.implicits = implicits;
|
|
9
|
+
}
|
|
10
|
+
include({
|
|
11
|
+
elements,
|
|
12
|
+
relations,
|
|
13
|
+
implicits
|
|
14
|
+
}) {
|
|
15
|
+
return new ComputeCtx(
|
|
16
|
+
this.index,
|
|
17
|
+
this.root,
|
|
18
|
+
elements ? /* @__PURE__ */ new Set([...this.elements, ...elements]) : this.elements,
|
|
19
|
+
relations ? /* @__PURE__ */ new Set([...this.relations, ...relations]) : this.relations,
|
|
20
|
+
implicits ? /* @__PURE__ */ new Set([...this.implicits, ...implicits]) : this.implicits
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
exclude({
|
|
24
|
+
elements,
|
|
25
|
+
relations,
|
|
26
|
+
implicits
|
|
27
|
+
}) {
|
|
28
|
+
let newImplicits = implicits ? new Set(difference([...this.implicits], implicits)) : this.implicits;
|
|
29
|
+
if (elements) {
|
|
30
|
+
newImplicits = new Set(
|
|
31
|
+
difference([...newImplicits], elements)
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
return new ComputeCtx(
|
|
35
|
+
this.index,
|
|
36
|
+
this.root,
|
|
37
|
+
elements ? new Set(difference([...this.elements], elements)) : this.elements,
|
|
38
|
+
relations ? new Set(difference([...this.relations], relations)) : this.relations,
|
|
39
|
+
newImplicits
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
import type { ModelIndex } from '../model-index';
|
|
2
|
-
import { type ElementView, type
|
|
3
|
-
export declare function computeElementView
|
|
4
|
-
//# sourceMappingURL=compute-element-view.d.ts.map
|
|
2
|
+
import { type ElementView, type ComputedView } from '../types';
|
|
3
|
+
export declare function computeElementView(view: ElementView, index: ModelIndex): ComputedView;
|
|
@@ -1,471 +1,139 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
for (const target of rule.targets) {
|
|
48
|
-
if (Expr.isWildcard(target)) {
|
|
49
|
-
predicates.push(() => true);
|
|
50
|
-
break;
|
|
51
|
-
}
|
|
52
|
-
if (Expr.isElementKindExpr(target)) {
|
|
53
|
-
predicates.push(target.isEqual ? n => n.kind === target.elementKind : n => n.kind !== target.elementKind);
|
|
54
|
-
continue;
|
|
55
|
-
}
|
|
56
|
-
if (Expr.isElementTagExpr(target)) {
|
|
57
|
-
predicates.push(target.isEqual
|
|
58
|
-
? ({ tags }) => !!tags && tags.includes(target.elementTag)
|
|
59
|
-
: ({ tags }) => isNil(tags) || !tags.includes(target.elementTag));
|
|
60
|
-
continue;
|
|
61
|
-
}
|
|
62
|
-
if (Expr.isElementRef(target)) {
|
|
63
|
-
const { element, isDescedants } = target;
|
|
64
|
-
predicates.push(isDescedants ? n => n.id.startsWith(element + '.') : n => n.id === element);
|
|
65
|
-
continue;
|
|
66
|
-
}
|
|
67
|
-
failExpectedNever(target);
|
|
68
|
-
}
|
|
69
|
-
filter(anyPass(predicates), nodes).forEach(n => {
|
|
70
|
-
n.shape = rule.style.shape ?? n.shape;
|
|
71
|
-
n.color = rule.style.color ?? n.color;
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
return nodes;
|
|
75
|
-
}
|
|
76
|
-
const includeElementRef = (ctx, expr) => {
|
|
77
|
-
const elements = expr.isDescedants
|
|
78
|
-
? ctx.index.children(expr.element)
|
|
79
|
-
: [ctx.index.find(expr.element)];
|
|
80
|
-
const filters = [];
|
|
81
|
-
if (expr.isDescedants) {
|
|
82
|
-
filters.push(Relations.isInside(expr.element));
|
|
83
|
-
}
|
|
84
|
-
const ctxElements = uniq([...ctx.elements, ...ctx.implicits]);
|
|
85
|
-
const excludeImplicits = [];
|
|
86
|
-
for (const el of elements) {
|
|
87
|
-
if (ctx.root && ctx.root !== el.id && !isAncestor(el.id, ctx.root)) {
|
|
88
|
-
excludeImplicits.push(...[...ctx.implicits].filter(impl => isAncestor(el.id, impl.id)));
|
|
89
|
-
}
|
|
90
|
-
for (const ctxEl of ctxElements) {
|
|
91
|
-
if (!isSameHierarchy(el, ctxEl)) {
|
|
92
|
-
filters.push(Relations.isAnyBetween(el.id, ctxEl.id));
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
const relations = filters.length ? ctx.index.filterRelations(anyPass(filters)) : [];
|
|
97
|
-
if (excludeImplicits.length == 0) {
|
|
98
|
-
return ctx.include({ elements, relations });
|
|
99
|
-
}
|
|
100
|
-
return ctx.include({ elements, relations }).exclude({ implicits: excludeImplicits });
|
|
101
|
-
};
|
|
102
|
-
const excludeElementRef = (ctx, expr) => {
|
|
103
|
-
const elements = expr.isDescedants
|
|
104
|
-
? ctx.index.children(expr.element)
|
|
105
|
-
: [ctx.index.find(expr.element)];
|
|
106
|
-
const elementsIds = elements.map(e => e.id);
|
|
107
|
-
const relations = [...ctx.relations].filter(r => elementsIds.includes(r.source) || elementsIds.includes(r.target));
|
|
108
|
-
return ctx.exclude({ elements, relations });
|
|
109
|
-
};
|
|
110
|
-
const asElementPredicate = (expr) => {
|
|
111
|
-
if (expr.isEqual) {
|
|
112
|
-
if (Expr.isElementKindExpr(expr)) {
|
|
113
|
-
return e => e.kind === expr.elementKind;
|
|
114
|
-
}
|
|
115
|
-
else {
|
|
116
|
-
return ({ tags }) => !!tags && tags.includes(expr.elementTag);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
else {
|
|
120
|
-
if (Expr.isElementKindExpr(expr)) {
|
|
121
|
-
return e => e.kind !== expr.elementKind;
|
|
122
|
-
}
|
|
123
|
-
else {
|
|
124
|
-
return ({ tags }) => isNil(tags) || tags.length === 0 || !tags.includes(expr.elementTag);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
};
|
|
128
|
-
const includeElementKindOrTag = (ctx, expr) => {
|
|
129
|
-
const elements = ctx.index.elements.filter(asElementPredicate(expr));
|
|
130
|
-
return elements.reduce((accCtx, el) => includeElementRef(accCtx, {
|
|
131
|
-
element: el.id,
|
|
132
|
-
isDescedants: false
|
|
133
|
-
}), ctx);
|
|
134
|
-
};
|
|
135
|
-
const excludeElementKindOrTag = (ctx, expr) => {
|
|
136
|
-
const predicate = asElementPredicate(expr);
|
|
137
|
-
const elements = [...ctx.elements].filter(predicate);
|
|
138
|
-
const implicits = [...ctx.implicits].filter(predicate);
|
|
139
|
-
return ctx.exclude({ elements, implicits });
|
|
140
|
-
};
|
|
141
|
-
const includeWildcardRef = (ctx, _expr) => {
|
|
142
|
-
const { root } = ctx;
|
|
143
|
-
if (root) {
|
|
144
|
-
const elements = [ctx.index.find(root), ...ctx.index.children(root)];
|
|
145
|
-
// All neighbors that may have relations with root or its children
|
|
146
|
-
const allImplicits = [
|
|
147
|
-
...ctx.index.siblings(root),
|
|
148
|
-
...ctx.index.ancestors(root).flatMap(a => [...ctx.index.siblings(a.id)])
|
|
149
|
-
];
|
|
150
|
-
const allInOut = ctx.index.filterRelations(isAnyInOut(root));
|
|
151
|
-
// Neighbors that have relations with root or its children
|
|
152
|
-
const implicits = [];
|
|
153
|
-
const relations = [];
|
|
154
|
-
for (const implicit of allImplicits) {
|
|
155
|
-
const relationsWithImplicit = allInOut.filter(isAnyInOut(implicit.id));
|
|
156
|
-
if (relationsWithImplicit.length) {
|
|
157
|
-
implicits.push(implicit);
|
|
158
|
-
relations.push(...relationsWithImplicit);
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
return ctx.include({
|
|
162
|
-
elements,
|
|
163
|
-
relations: [...ctx.index.filterRelations(isInside(root)), ...relations],
|
|
164
|
-
implicits: implicits
|
|
165
|
-
});
|
|
166
|
-
}
|
|
167
|
-
else {
|
|
168
|
-
const elements = ctx.index.rootElements();
|
|
169
|
-
if (elements.length <= 1) {
|
|
170
|
-
return new ComputeCtx(ctx.index, ctx.root, new Set(elements));
|
|
171
|
-
}
|
|
172
|
-
const predicates = [];
|
|
173
|
-
for (const [source, target] of anyPossibleRelations(elements)) {
|
|
174
|
-
predicates.push(Relations.isAnyBetween(source.id, target.id));
|
|
175
|
-
}
|
|
176
|
-
const relations = predicates.length ? ctx.index.filterRelations(anyPass(predicates)) : [];
|
|
177
|
-
return new ComputeCtx(ctx.index, ctx.root, new Set(elements), new Set(relations));
|
|
178
|
-
}
|
|
179
|
-
};
|
|
180
|
-
const excludeWildcardRef = (ctx, _expr) => {
|
|
181
|
-
const { root } = ctx;
|
|
182
|
-
if (root) {
|
|
183
|
-
const relations = [...ctx.relations].filter(anyPass([isInside(root), isIncoming(root), isOutgoing(root)]));
|
|
184
|
-
return ctx.exclude({
|
|
185
|
-
elements: [...ctx.elements].filter(e => isAncestor(root, e.id)),
|
|
186
|
-
relations,
|
|
187
|
-
implicits: [...ctx.implicits].filter(anyPass(relations.map(r => hasRelation(r))))
|
|
188
|
-
});
|
|
189
|
-
}
|
|
190
|
-
else {
|
|
191
|
-
return new ComputeCtx(ctx.index, ctx.root);
|
|
192
|
-
}
|
|
193
|
-
};
|
|
194
|
-
const resolveElements = (ctx, expr) => {
|
|
195
|
-
if (Expr.isWildcard(expr)) {
|
|
196
|
-
if (ctx.root) {
|
|
197
|
-
return [ctx.index.find(ctx.root)];
|
|
198
|
-
}
|
|
199
|
-
else {
|
|
200
|
-
return ctx.index.rootElements();
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
if (Expr.isElementKindExpr(expr)) {
|
|
204
|
-
return ctx.index.elements.filter(el => {
|
|
205
|
-
if (expr.isEqual) {
|
|
206
|
-
return el.kind === expr.elementKind;
|
|
207
|
-
}
|
|
208
|
-
return el.kind !== expr.elementKind;
|
|
209
|
-
});
|
|
210
|
-
}
|
|
211
|
-
if (Expr.isElementTagExpr(expr)) {
|
|
212
|
-
return ctx.index.elements.filter(el => {
|
|
213
|
-
const tags = el.tags;
|
|
214
|
-
if (expr.isEqual) {
|
|
215
|
-
return !!tags && tags.includes(expr.elementTag);
|
|
216
|
-
}
|
|
217
|
-
return isNil(tags) || tags.length === 0 || !tags.includes(expr.elementTag);
|
|
218
|
-
});
|
|
219
|
-
}
|
|
220
|
-
if (expr.isDescedants) {
|
|
221
|
-
return ctx.index.children(expr.element);
|
|
222
|
-
}
|
|
223
|
-
else {
|
|
224
|
-
return [ctx.index.find(expr.element)];
|
|
225
|
-
}
|
|
226
|
-
};
|
|
227
|
-
const includeIncomingExpr = (ctx, expr) => {
|
|
228
|
-
if (Expr.isWildcard(expr.incoming) && !ctx.root) {
|
|
229
|
-
return ctx;
|
|
230
|
-
}
|
|
231
|
-
const elements = resolveElements(ctx, expr.incoming);
|
|
232
|
-
if (elements.length === 0) {
|
|
233
|
-
return ctx;
|
|
234
|
-
}
|
|
235
|
-
const implicits = [];
|
|
236
|
-
const relations = [];
|
|
237
|
-
for (const el of elements) {
|
|
238
|
-
const elRelations = ctx.index.filterRelations(isIncoming(el.id));
|
|
239
|
-
if (elRelations.length > 0) {
|
|
240
|
-
relations.push(...elRelations);
|
|
241
|
-
implicits.push(el);
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
return ctx.include({
|
|
245
|
-
relations,
|
|
246
|
-
implicits
|
|
247
|
-
});
|
|
248
|
-
};
|
|
249
|
-
const excludeIncomingExpr = (ctx, expr) => {
|
|
250
|
-
if (Expr.isWildcard(expr.incoming) && !ctx.root) {
|
|
251
|
-
return ctx;
|
|
252
|
-
}
|
|
253
|
-
const elements = resolveElements(ctx, expr.incoming);
|
|
254
|
-
if (elements.length === 0) {
|
|
255
|
-
return ctx;
|
|
256
|
-
}
|
|
257
|
-
const isIncomings = anyPass(elements.map(el => isIncoming(el.id)));
|
|
258
|
-
const excluded = [...ctx.relations].filter(isIncomings);
|
|
259
|
-
if (excluded.length > 0) {
|
|
260
|
-
return ctx.exclude({
|
|
261
|
-
relations: excluded
|
|
262
|
-
});
|
|
263
|
-
}
|
|
264
|
-
return ctx;
|
|
265
|
-
};
|
|
266
|
-
const includeOutgoingExpr = (ctx, expr) => {
|
|
267
|
-
if (Expr.isWildcard(expr.outgoing) && !ctx.root) {
|
|
268
|
-
return ctx;
|
|
269
|
-
}
|
|
270
|
-
const elements = resolveElements(ctx, expr.outgoing);
|
|
271
|
-
if (elements.length === 0) {
|
|
272
|
-
return ctx;
|
|
273
|
-
}
|
|
274
|
-
const implicits = [];
|
|
275
|
-
const relations = [];
|
|
276
|
-
for (const el of elements) {
|
|
277
|
-
const elRelations = ctx.index.filterRelations(isOutgoing(el.id));
|
|
278
|
-
if (elRelations.length > 0) {
|
|
279
|
-
relations.push(...elRelations);
|
|
280
|
-
implicits.push(el);
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
return ctx.include({
|
|
284
|
-
relations,
|
|
285
|
-
implicits
|
|
286
|
-
});
|
|
287
|
-
};
|
|
288
|
-
const excludeOutgoingExpr = (ctx, expr) => {
|
|
289
|
-
if (Expr.isWildcard(expr.outgoing) && !ctx.root) {
|
|
290
|
-
return ctx;
|
|
291
|
-
}
|
|
292
|
-
const elements = resolveElements(ctx, expr.outgoing);
|
|
293
|
-
if (elements.length === 0) {
|
|
294
|
-
return ctx;
|
|
295
|
-
}
|
|
296
|
-
const isOutgoings = anyPass(elements.map(el => isOutgoing(el.id)));
|
|
297
|
-
const excluded = [...ctx.relations].filter(isOutgoings);
|
|
298
|
-
if (excluded.length > 0) {
|
|
299
|
-
return ctx.exclude({
|
|
300
|
-
relations: excluded
|
|
301
|
-
});
|
|
302
|
-
}
|
|
303
|
-
return ctx;
|
|
304
|
-
};
|
|
305
|
-
const includeInOutExpr = (ctx, expr) => {
|
|
306
|
-
if (Expr.isWildcard(expr.inout) && !ctx.root) {
|
|
307
|
-
return ctx;
|
|
308
|
-
}
|
|
309
|
-
const targets = resolveElements(ctx, expr.inout);
|
|
310
|
-
if (targets.length === 0) {
|
|
311
|
-
return ctx;
|
|
312
|
-
}
|
|
313
|
-
const implicits = [];
|
|
314
|
-
const relations = [];
|
|
315
|
-
for (const target of targets) {
|
|
316
|
-
const foundRelations = ctx.index.filterRelations(isAnyInOut(target.id));
|
|
317
|
-
if (foundRelations.length > 0) {
|
|
318
|
-
relations.push(...foundRelations);
|
|
319
|
-
implicits.push(target);
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
return ctx.include({
|
|
323
|
-
relations,
|
|
324
|
-
implicits
|
|
325
|
-
});
|
|
326
|
-
};
|
|
327
|
-
const excludeInOutExpr = (ctx, expr) => {
|
|
328
|
-
if (Expr.isWildcard(expr.inout) && !ctx.root) {
|
|
329
|
-
return ctx;
|
|
330
|
-
}
|
|
331
|
-
const targets = resolveElements(ctx, expr.inout);
|
|
332
|
-
if (targets.length === 0) {
|
|
333
|
-
return ctx;
|
|
334
|
-
}
|
|
335
|
-
const excluded = [...ctx.relations].filter(anyPass(targets.map(t => isAnyInOut(t.id))));
|
|
336
|
-
if (excluded.length > 0) {
|
|
337
|
-
return ctx.exclude({
|
|
338
|
-
relations: excluded
|
|
339
|
-
});
|
|
340
|
-
}
|
|
341
|
-
return ctx;
|
|
342
|
-
};
|
|
343
|
-
const includeRelationExpr = (ctx, expr) => {
|
|
344
|
-
const sources = resolveElements(ctx, expr.source);
|
|
345
|
-
const targets = resolveElements(ctx, expr.target);
|
|
346
|
-
if (sources.length === 0 || targets.length === 0) {
|
|
347
|
-
return ctx;
|
|
348
|
-
}
|
|
349
|
-
const implicits = [];
|
|
350
|
-
const relations = [];
|
|
351
|
-
for (const source of sources) {
|
|
352
|
-
for (const target of targets) {
|
|
353
|
-
if (isSameHierarchy(source, target)) {
|
|
354
|
-
continue;
|
|
355
|
-
}
|
|
356
|
-
const foundRelations = ctx.index.filterRelations(isBetween(source.id, target.id));
|
|
357
|
-
if (foundRelations.length > 0) {
|
|
358
|
-
relations.push(...foundRelations);
|
|
359
|
-
implicits.push(source, target);
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
return ctx.include({
|
|
364
|
-
relations,
|
|
365
|
-
implicits
|
|
366
|
-
});
|
|
367
|
-
};
|
|
368
|
-
const excludeRelationExpr = (ctx, expr) => {
|
|
369
|
-
const sources = resolveElements(ctx, expr.source);
|
|
370
|
-
const targets = resolveElements(ctx, expr.target);
|
|
371
|
-
const filters = [];
|
|
372
|
-
for (const source of sources) {
|
|
373
|
-
for (const target of targets) {
|
|
374
|
-
if (isSameHierarchy(source, target)) {
|
|
375
|
-
continue;
|
|
376
|
-
}
|
|
377
|
-
filters.push(isBetween(source.id, target.id));
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
if (filters.length == 0) {
|
|
381
|
-
return ctx;
|
|
382
|
-
}
|
|
383
|
-
const excluded = [...ctx.relations].filter(anyPass(filters));
|
|
384
|
-
if (excluded.length == 0) {
|
|
385
|
-
return ctx;
|
|
386
|
-
}
|
|
387
|
-
return ctx.exclude({
|
|
388
|
-
relations: excluded
|
|
389
|
-
});
|
|
390
|
-
};
|
|
391
|
-
export function computeElementView(view, index) {
|
|
392
|
-
const rootElement = view.viewOf ?? null;
|
|
393
|
-
let ctx = new ComputeCtx(index, rootElement);
|
|
394
|
-
const rulesInclude = view.rules.filter(isViewRuleExpression);
|
|
395
|
-
if (rootElement && rulesInclude.length == 0) {
|
|
396
|
-
ctx = ctx.include({
|
|
397
|
-
elements: [index.find(rootElement)]
|
|
398
|
-
});
|
|
399
|
-
}
|
|
400
|
-
for (const { isInclude, exprs } of rulesInclude) {
|
|
401
|
-
for (const expr of exprs) {
|
|
402
|
-
if (Expr.isElementKindExpr(expr) || Expr.isElementTagExpr(expr)) {
|
|
403
|
-
ctx = isInclude ? includeElementKindOrTag(ctx, expr) : excludeElementKindOrTag(ctx, expr);
|
|
404
|
-
continue;
|
|
405
|
-
}
|
|
406
|
-
if (Expr.isElementRef(expr)) {
|
|
407
|
-
ctx = isInclude ? includeElementRef(ctx, expr) : excludeElementRef(ctx, expr);
|
|
408
|
-
continue;
|
|
409
|
-
}
|
|
410
|
-
if (Expr.isWildcard(expr)) {
|
|
411
|
-
ctx = isInclude ? includeWildcardRef(ctx, expr) : excludeWildcardRef(ctx, expr);
|
|
412
|
-
continue;
|
|
413
|
-
}
|
|
414
|
-
if (Expr.isIncoming(expr)) {
|
|
415
|
-
ctx = isInclude ? includeIncomingExpr(ctx, expr) : excludeIncomingExpr(ctx, expr);
|
|
416
|
-
continue;
|
|
417
|
-
}
|
|
418
|
-
if (Expr.isOutgoing(expr)) {
|
|
419
|
-
ctx = isInclude ? includeOutgoingExpr(ctx, expr) : excludeOutgoingExpr(ctx, expr);
|
|
420
|
-
continue;
|
|
421
|
-
}
|
|
422
|
-
if (Expr.isInOut(expr)) {
|
|
423
|
-
ctx = isInclude ? includeInOutExpr(ctx, expr) : excludeInOutExpr(ctx, expr);
|
|
424
|
-
continue;
|
|
425
|
-
}
|
|
426
|
-
if (Expr.isRelation(expr)) {
|
|
427
|
-
ctx = isInclude ? includeRelationExpr(ctx, expr) : excludeRelationExpr(ctx, expr);
|
|
428
|
-
continue;
|
|
429
|
-
}
|
|
430
|
-
ignoreNeverInRuntime(expr);
|
|
431
|
-
}
|
|
432
|
-
}
|
|
433
|
-
const elements = new Set([...ctx.elements]);
|
|
434
|
-
const edgeBuilder = new EdgeBuilder();
|
|
435
|
-
const resolvedRelations = [...ctx.relations];
|
|
436
|
-
for (const [source, target] of anyPossibleRelations([...elements, ...ctx.implicits])) {
|
|
437
|
-
if (!elements.has(source) && !elements.has(target)) {
|
|
438
|
-
continue;
|
|
439
|
-
}
|
|
440
|
-
const findPredicate = Relations.isBetween(source.id, target.id);
|
|
441
|
-
let idx = resolvedRelations.findIndex(findPredicate);
|
|
442
|
-
while (idx >= 0) {
|
|
443
|
-
const [rel] = resolvedRelations.splice(idx, 1);
|
|
444
|
-
if (rel) {
|
|
445
|
-
elements.add(source);
|
|
446
|
-
elements.add(target);
|
|
447
|
-
edgeBuilder.add(source.id, target.id, rel);
|
|
448
|
-
}
|
|
449
|
-
idx = resolvedRelations.findIndex(findPredicate);
|
|
450
|
-
}
|
|
451
|
-
}
|
|
452
|
-
const nodesreg = transformToNodes(elements);
|
|
453
|
-
const edges = edgeBuilder.build().map(edge => {
|
|
454
|
-
while (edge.parent) {
|
|
455
|
-
if (nodesreg.has(edge.parent)) {
|
|
456
|
-
break;
|
|
457
|
-
}
|
|
458
|
-
edge.parent = parentFqn(edge.parent);
|
|
459
|
-
}
|
|
460
|
-
return edge;
|
|
461
|
-
});
|
|
462
|
-
const nodes = applyViewRuleStyles(view.rules.filter(isViewRuleStyle), sortNodes(nodesreg, edges));
|
|
463
|
-
const autoLayoutRule = view.rules.find(isViewRuleAutoLayout);
|
|
464
|
-
return {
|
|
465
|
-
...view,
|
|
466
|
-
autoLayout: autoLayoutRule?.autoLayout ?? 'TB',
|
|
467
|
-
nodes,
|
|
468
|
-
edges
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.computeElementView = computeElementView;
|
|
7
|
+
var _remeda = require("remeda");
|
|
8
|
+
var _errors = require("../errors");
|
|
9
|
+
var _types = require("../types");
|
|
10
|
+
var Expr = _interopRequireWildcard(require("../types/expression"));
|
|
11
|
+
var _view = require("../types/view");
|
|
12
|
+
var _utils = require("../utils");
|
|
13
|
+
var _EdgeBuilder = require("./EdgeBuilder");
|
|
14
|
+
var _computeCtx = require("./compute-ctx");
|
|
15
|
+
var _computePredicates = require("./compute-predicates");
|
|
16
|
+
var _applyViewRuleStyles = require("./utils/applyViewRuleStyles");
|
|
17
|
+
var _sortNodes = require("./utils/sortNodes");
|
|
18
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
19
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
20
|
+
function reduceToMap(elementsIterator) {
|
|
21
|
+
return Array.from(elementsIterator).sort(_utils.compareByFqnHierarchically).reduce((map, {
|
|
22
|
+
id,
|
|
23
|
+
color,
|
|
24
|
+
shape,
|
|
25
|
+
...el
|
|
26
|
+
}) => {
|
|
27
|
+
let parent = (0, _utils.parentFqn)(id);
|
|
28
|
+
while (parent) {
|
|
29
|
+
if (map.has(parent)) {
|
|
30
|
+
break;
|
|
31
|
+
}
|
|
32
|
+
parent = (0, _utils.parentFqn)(parent);
|
|
33
|
+
}
|
|
34
|
+
if (parent) {
|
|
35
|
+
const parentNd = (0, _errors.nonNullable)(map.get(parent));
|
|
36
|
+
parentNd.children.push(id);
|
|
37
|
+
}
|
|
38
|
+
const node = {
|
|
39
|
+
...el,
|
|
40
|
+
id,
|
|
41
|
+
parent,
|
|
42
|
+
color: color ?? _types.DefaultThemeColor,
|
|
43
|
+
shape: shape ?? _types.DefaultElementShape,
|
|
44
|
+
children: [],
|
|
45
|
+
inEdges: [],
|
|
46
|
+
outEdges: []
|
|
469
47
|
};
|
|
48
|
+
map.set(id, node);
|
|
49
|
+
return map;
|
|
50
|
+
}, /* @__PURE__ */new Map());
|
|
470
51
|
}
|
|
471
|
-
|
|
52
|
+
function computeElementView(view, index) {
|
|
53
|
+
const rootElement = view.viewOf ?? null;
|
|
54
|
+
let ctx = new _computeCtx.ComputeCtx(index, rootElement);
|
|
55
|
+
const rulesInclude = view.rules.filter(_view.isViewRuleExpression);
|
|
56
|
+
if (rootElement && rulesInclude.length == 0) {
|
|
57
|
+
ctx = ctx.include({
|
|
58
|
+
elements: [index.find(rootElement)]
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
for (const {
|
|
62
|
+
isInclude,
|
|
63
|
+
exprs
|
|
64
|
+
} of rulesInclude) {
|
|
65
|
+
for (const expr of exprs) {
|
|
66
|
+
if (Expr.isElementKindExpr(expr) || Expr.isElementTagExpr(expr)) {
|
|
67
|
+
ctx = isInclude ? (0, _computePredicates.includeElementKindOrTag)(ctx, expr) : (0, _computePredicates.excludeElementKindOrTag)(ctx, expr);
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
if (Expr.isElementRef(expr)) {
|
|
71
|
+
ctx = isInclude ? (0, _computePredicates.includeElementRef)(ctx, expr) : (0, _computePredicates.excludeElementRef)(ctx, expr);
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
if (Expr.isWildcard(expr)) {
|
|
75
|
+
ctx = isInclude ? (0, _computePredicates.includeWildcardRef)(ctx, expr) : (0, _computePredicates.excludeWildcardRef)(ctx, expr);
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
if (Expr.isIncoming(expr)) {
|
|
79
|
+
ctx = isInclude ? (0, _computePredicates.includeIncomingExpr)(ctx, expr) : (0, _computePredicates.excludeIncomingExpr)(ctx, expr);
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
if (Expr.isOutgoing(expr)) {
|
|
83
|
+
ctx = isInclude ? (0, _computePredicates.includeOutgoingExpr)(ctx, expr) : (0, _computePredicates.excludeOutgoingExpr)(ctx, expr);
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
if (Expr.isInOut(expr)) {
|
|
87
|
+
ctx = isInclude ? (0, _computePredicates.includeInOutExpr)(ctx, expr) : (0, _computePredicates.excludeInOutExpr)(ctx, expr);
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
if (Expr.isRelation(expr)) {
|
|
91
|
+
ctx = isInclude ? (0, _computePredicates.includeRelationExpr)(ctx, expr) : (0, _computePredicates.excludeRelationExpr)(ctx, expr);
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
(0, _errors.nonexhaustive)(expr);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
const allElements = [...ctx.elements, ...ctx.implicits].sort(_utils.compareByFqnHierarchically).reverse();
|
|
98
|
+
const elementsWithRelations = /* @__PURE__ */new Set();
|
|
99
|
+
const edgeBuilder = new _EdgeBuilder.EdgeBuilder();
|
|
100
|
+
const anscestorOf = id => e => e.id === id || (0, _utils.isAncestor)(e.id, id);
|
|
101
|
+
const sortedRelations = [...ctx.relations];
|
|
102
|
+
for (const rel of sortedRelations) {
|
|
103
|
+
const source = (0, _remeda.find)(allElements, anscestorOf(rel.source));
|
|
104
|
+
if (!source) {
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
const target = (0, _remeda.find)(allElements, (0, _remeda.allPass)([anscestorOf(rel.target), e => !(0, _utils.isSameHierarchy)(e, source)]));
|
|
108
|
+
if (!target) {
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
elementsWithRelations.add(source);
|
|
112
|
+
elementsWithRelations.add(target);
|
|
113
|
+
edgeBuilder.add(source.id, target.id, rel);
|
|
114
|
+
}
|
|
115
|
+
const elements = /* @__PURE__ */new Set([...ctx.elements, ...elementsWithRelations]);
|
|
116
|
+
const nodesMap = reduceToMap(elements);
|
|
117
|
+
const edges = edgeBuilder.build().map(edge => {
|
|
118
|
+
while (edge.parent) {
|
|
119
|
+
if (nodesMap.has(edge.parent)) {
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
edge.parent = (0, _utils.parentFqn)(edge.parent);
|
|
123
|
+
}
|
|
124
|
+
(0, _errors.nonNullable)(nodesMap.get(edge.source)).outEdges.push(edge.id);
|
|
125
|
+
(0, _errors.nonNullable)(nodesMap.get(edge.target)).inEdges.push(edge.id);
|
|
126
|
+
return edge;
|
|
127
|
+
});
|
|
128
|
+
const nodes = (0, _applyViewRuleStyles.applyViewRuleStyles)(view.rules.filter(_view.isViewRuleStyle), (0, _sortNodes.sortNodes)(nodesMap, edges)
|
|
129
|
+
// map(e => nodesMap.get(e.id)!, Array.from(elements))
|
|
130
|
+
);
|
|
131
|
+
|
|
132
|
+
const autoLayoutRule = view.rules.find(_view.isViewRuleAutoLayout);
|
|
133
|
+
return {
|
|
134
|
+
...view,
|
|
135
|
+
autoLayout: autoLayoutRule?.autoLayout ?? "TB",
|
|
136
|
+
nodes,
|
|
137
|
+
edges
|
|
138
|
+
};
|
|
139
|
+
}
|