@likec4/core 0.2.1 → 0.4.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/compute-view/EdgeBuilder.js +8 -8
- package/dist/compute-view/compute.element-view.js +3 -1
- package/dist/compute-view/utils/evaluate-expression.js +3 -3
- package/dist/types/computed-view.d.ts +2 -1
- package/dist/types/view.d.ts +5 -1
- package/dist/types/view.js +3 -0
- package/dist/utils/relations.d.ts +6 -1
- package/dist/utils/relations.js +11 -1
- package/package.json +3 -3
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { equals, keys, pluck, reject } from 'rambdax';
|
|
2
|
-
import { commonAncestor, compareFqnHierarchically } from '../utils';
|
|
1
|
+
import { equals, head, keys, pluck, reject } from 'rambdax';
|
|
2
|
+
import { commonAncestor, compareFqnHierarchically } from '../utils/fqn';
|
|
3
|
+
import { compareRelations } from '../utils/relations';
|
|
3
4
|
export class EdgeBuilder {
|
|
4
5
|
_relationsObj = {};
|
|
5
6
|
add(source, target, relation) {
|
|
@@ -11,12 +12,11 @@ export class EdgeBuilder {
|
|
|
11
12
|
return this;
|
|
12
13
|
}
|
|
13
14
|
build() {
|
|
14
|
-
return keys(this._relationsObj).
|
|
15
|
+
return keys(this._relationsObj).flatMap(source => {
|
|
15
16
|
const targets = this._relationsObj[source] ?? {};
|
|
16
|
-
return keys(targets).
|
|
17
|
-
const relations = targets[target] ?? [];
|
|
18
|
-
const
|
|
19
|
-
const label = titles.length === 1 ? titles[0] : null;
|
|
17
|
+
return keys(targets).map(target => {
|
|
18
|
+
const relations = (targets[target] ?? []).sort(compareRelations);
|
|
19
|
+
const label = head(reject(equals(''), pluck('title', relations))) ?? null;
|
|
20
20
|
return {
|
|
21
21
|
id: `${source}:${target}`,
|
|
22
22
|
parent: commonAncestor(source, target),
|
|
@@ -26,6 +26,6 @@ export class EdgeBuilder {
|
|
|
26
26
|
relations: pluck('id', relations)
|
|
27
27
|
};
|
|
28
28
|
});
|
|
29
|
-
});
|
|
29
|
+
}).sort(compareRelations).reverse();
|
|
30
30
|
}
|
|
31
31
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { anyPass, filter } from 'rambdax';
|
|
2
2
|
import { DefaultElementShape, DefaultThemeColor } from '../types';
|
|
3
3
|
import * as Expression from '../types/expression';
|
|
4
|
-
import { isViewRuleExpression, isViewRuleStyle } from '../types/view';
|
|
4
|
+
import { isViewRuleAutoLayout, isViewRuleExpression, isViewRuleStyle } from '../types/view';
|
|
5
5
|
import { Relations, compareByFqnHierarchically, failExpectedNever, isSameHierarchy, parentFqn } from '../utils';
|
|
6
6
|
import { EdgeBuilder } from './EdgeBuilder';
|
|
7
7
|
import { anyPossibleRelations } from './utils/anyPossibleRelations';
|
|
@@ -155,8 +155,10 @@ export function computeElementView(view, index) {
|
|
|
155
155
|
return edge;
|
|
156
156
|
});
|
|
157
157
|
const nodes = applyViewRuleStyles(view.rules.filter(isViewRuleStyle), sortNodes(nodesreg, edges));
|
|
158
|
+
const autoLayoutRule = view.rules.find(isViewRuleAutoLayout);
|
|
158
159
|
return {
|
|
159
160
|
...view,
|
|
161
|
+
autoLayout: autoLayoutRule?.autoLayout ?? 'TB',
|
|
160
162
|
nodes,
|
|
161
163
|
edges
|
|
162
164
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { anyPass, map, pluck, uniq } from 'rambdax';
|
|
2
2
|
import * as Expr from '../../types/expression';
|
|
3
3
|
import { failExpectedNever, isAncestor } from '../../utils';
|
|
4
|
-
import { isBetween, isIncoming, isOutgoing } from '../../utils/relations';
|
|
4
|
+
import { isBetween, isIncoming, isInside, isOutgoing } from '../../utils/relations';
|
|
5
5
|
import { anyPossibleRelations } from './anyPossibleRelations';
|
|
6
6
|
const dropNested = (elements) => {
|
|
7
7
|
return elements.reduce((acc, current) => {
|
|
@@ -65,7 +65,7 @@ const evaluateElementExpression = (index, expr, rootElement = null) => {
|
|
|
65
65
|
])
|
|
66
66
|
];
|
|
67
67
|
relations = index.filterRelations(anyPass([
|
|
68
|
-
|
|
68
|
+
isInside(rootElement),
|
|
69
69
|
isIncoming(rootElement),
|
|
70
70
|
isOutgoing(rootElement),
|
|
71
71
|
]));
|
|
@@ -85,7 +85,7 @@ const evaluateElementExpression = (index, expr, rootElement = null) => {
|
|
|
85
85
|
if (Expr.isElementRef(expr)) {
|
|
86
86
|
elements = expr.isDescedants ? index.children(expr.element) : [index.find(expr.element)];
|
|
87
87
|
if (expr.isDescedants) {
|
|
88
|
-
relations = index.filterRelations(
|
|
88
|
+
relations = index.filterRelations(isInside(expr.element));
|
|
89
89
|
// relations = index.filterRelations(anyPass([
|
|
90
90
|
// isBetween(expr.element),
|
|
91
91
|
// isIncoming(expr.element),
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Opaque } from './opaque';
|
|
2
2
|
import type { ElementShape, Fqn, ThemeColor } from './element';
|
|
3
3
|
import type { RelationID } from './relation';
|
|
4
|
-
import type { ElementView, ViewID } from './view';
|
|
4
|
+
import type { ElementView, ViewID, ViewRuleAutoLayout } from './view';
|
|
5
5
|
export type NodeId = Fqn;
|
|
6
6
|
export type EdgeId = Opaque<string, 'EdgeId'>;
|
|
7
7
|
export interface ComputedNode {
|
|
@@ -24,6 +24,7 @@ export interface ComputedEdge {
|
|
|
24
24
|
relations: RelationID[];
|
|
25
25
|
}
|
|
26
26
|
export interface ComputedView<Node extends ComputedNode = ComputedNode, Edge extends ComputedEdge = ComputedEdge> extends ElementView {
|
|
27
|
+
autoLayout: ViewRuleAutoLayout['autoLayout'];
|
|
27
28
|
nodes: Node[];
|
|
28
29
|
edges: Edge[];
|
|
29
30
|
}
|
package/dist/types/view.d.ts
CHANGED
|
@@ -15,7 +15,11 @@ export interface ViewRuleStyle {
|
|
|
15
15
|
};
|
|
16
16
|
}
|
|
17
17
|
export declare function isViewRuleStyle(rule: ViewRule): rule is ViewRuleStyle;
|
|
18
|
-
export
|
|
18
|
+
export interface ViewRuleAutoLayout {
|
|
19
|
+
autoLayout: 'TB' | 'BT' | 'LR' | 'RL';
|
|
20
|
+
}
|
|
21
|
+
export declare function isViewRuleAutoLayout(rule: ViewRule): rule is ViewRuleAutoLayout;
|
|
22
|
+
export type ViewRule = ViewRuleExpression | ViewRuleStyle | ViewRuleAutoLayout;
|
|
19
23
|
export interface ElementView {
|
|
20
24
|
readonly id: ViewID;
|
|
21
25
|
readonly viewOf?: Fqn;
|
package/dist/types/view.js
CHANGED
|
@@ -3,7 +3,12 @@ type Relation = {
|
|
|
3
3
|
source: Fqn;
|
|
4
4
|
target: Fqn;
|
|
5
5
|
};
|
|
6
|
-
export declare const
|
|
6
|
+
export declare const compareRelations: <T extends {
|
|
7
|
+
source: Fqn;
|
|
8
|
+
target: Fqn;
|
|
9
|
+
}>(a: T, b: T) => number;
|
|
10
|
+
export declare const isInside: (parent: Fqn) => (rel: Relation) => boolean;
|
|
11
|
+
export declare const isBetween: (source: Fqn, target: Fqn) => (rel: Relation) => boolean;
|
|
7
12
|
export declare const isAnyBetween: (source: Fqn, target: Fqn) => import("rambdax").Predicate<Relation>;
|
|
8
13
|
export declare const isIncoming: (target: Fqn) => (rel: Relation) => boolean;
|
|
9
14
|
export declare const isOutgoing: (source: Fqn) => (rel: Relation) => boolean;
|
package/dist/utils/relations.js
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
import { either } from 'rambdax';
|
|
2
|
-
|
|
2
|
+
import { compareFqnHierarchically } from './fqn';
|
|
3
|
+
export const compareRelations = (a, b) => {
|
|
4
|
+
return compareFqnHierarchically(a.source, b.source) || compareFqnHierarchically(a.target, b.target);
|
|
5
|
+
};
|
|
6
|
+
export const isInside = (parent) => {
|
|
7
|
+
const prefix = parent + '.';
|
|
8
|
+
return (rel) => {
|
|
9
|
+
return rel.source.startsWith(prefix) && rel.target.startsWith(prefix);
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
export const isBetween = (source, target) => {
|
|
3
13
|
const sourcePrefix = source + '.';
|
|
4
14
|
const targetPrefix = target + '.';
|
|
5
15
|
return (rel) => {
|
package/package.json
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@likec4/core",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"type": "module",
|
|
3
|
+
"version": "0.4.0",
|
|
5
4
|
"bugs": "https://github.com/likec4/likec4/issues",
|
|
6
5
|
"homepage": "https://like-c4.dev",
|
|
7
6
|
"author": "Denis Davydkov <denis@davydkov.com>",
|
|
@@ -24,6 +23,7 @@
|
|
|
24
23
|
},
|
|
25
24
|
"main": "./dist/index.js",
|
|
26
25
|
"types": "./dist/index.d.ts",
|
|
26
|
+
"type": "module",
|
|
27
27
|
"exports": {
|
|
28
28
|
".": {
|
|
29
29
|
"types": "./dist/index.d.ts",
|
|
@@ -83,6 +83,6 @@
|
|
|
83
83
|
"devDependencies": {
|
|
84
84
|
"typescript": "^5.0.3",
|
|
85
85
|
"vite": "^4.2.1",
|
|
86
|
-
"vitest": "^0.
|
|
86
|
+
"vitest": "^0.30.1"
|
|
87
87
|
}
|
|
88
88
|
}
|