@likec4/diagram 1.39.5 → 1.41.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/bundle/{chunk-CW_KClZe.js → chunk-FGcODVxo.js} +1059 -1023
- package/bundle/custom.js +61 -60
- package/bundle/index.js +2932 -764
- package/dist/LikeC4Diagram.d.ts +1 -1
- package/dist/LikeC4Diagram.js +7 -4
- package/dist/LikeC4Diagram.props.d.ts +6 -1
- package/dist/base/const.d.ts +9 -0
- package/dist/base/const.js +10 -1
- package/dist/base/index.d.ts +1 -0
- package/dist/base/primitives/MarkdownBlock.js +2 -0
- package/dist/base/primitives/edge/EdgeLabel.js +2 -1
- package/dist/base/primitives/edge/EdgeLabelContainer.js +10 -4
- package/dist/base/primitives/edge/EdgePath.js +17 -8
- package/dist/base/primitives/edge/edge.css.d.ts +0 -1
- package/dist/base/primitives/edge/edge.css.js +6 -14
- package/dist/base/primitives/element/ElementActionButtons.js +1 -3
- package/dist/base/primitives/element/ElementNodeContainer.d.ts +0 -6
- package/dist/base/primitives/element/ElementNodeContainer.js +3 -26
- package/dist/base/primitives/element/ElementTitle.js +2 -2
- package/dist/base/types.d.ts +3 -3
- package/dist/bundle/LikeC4View.js +4 -12
- package/dist/bundle/LikeC4View.props.d.ts +12 -3
- package/dist/bundle/custom.js +1 -1
- package/dist/components/Link.js +28 -20
- package/dist/custom/customNodes.d.ts +6 -0
- package/dist/custom/customNodes.js +2 -1
- package/dist/custom/index.js +1 -1
- package/dist/hooks/useDiagram.d.ts +5 -1
- package/dist/hooks/useDiagram.js +3 -0
- package/dist/hooks/useXYFlow.d.ts +4 -439
- package/dist/likec4diagram/DiagramUI.js +1 -1
- package/dist/likec4diagram/DiagramXYFlow.js +8 -4
- package/dist/likec4diagram/convert-to-xyflow.d.ts +14 -0
- package/dist/likec4diagram/convert-to-xyflow.js +29 -0
- package/dist/likec4diagram/custom/edges/RelationshipEdge.d.ts +4 -4
- package/dist/likec4diagram/custom/edges/RelationshipEdge.js +0 -1
- package/dist/likec4diagram/custom/edges/SequenceStepEdge.d.ts +3 -0
- package/dist/likec4diagram/custom/edges/SequenceStepEdge.js +71 -0
- package/dist/likec4diagram/custom/index.js +7 -2
- package/dist/likec4diagram/custom/nodes/ElementActions.d.ts +2 -1
- package/dist/likec4diagram/custom/nodes/SequenceActorNode.d.ts +4 -0
- package/dist/likec4diagram/custom/nodes/SequenceActorNode.js +157 -0
- package/dist/likec4diagram/custom/nodes/index.d.ts +1 -0
- package/dist/likec4diagram/custom/nodes/nodes.d.ts +1 -2
- package/dist/likec4diagram/relationship-popover/RelationshipPopover.js +31 -27
- package/dist/likec4diagram/types.d.ts +41 -7
- package/dist/likec4diagram/xyflow-diagram/diagram-view.d.ts +11 -0
- package/dist/likec4diagram/{useViewToNodesEdges.js → xyflow-diagram/diagram-view.js} +4 -13
- package/dist/likec4diagram/xyflow-sequence/_types.d.ts +41 -0
- package/dist/likec4diagram/xyflow-sequence/const.d.ts +17 -0
- package/dist/likec4diagram/xyflow-sequence/const.js +16 -0
- package/dist/likec4diagram/xyflow-sequence/layouter.d.ts +46 -0
- package/dist/likec4diagram/xyflow-sequence/layouter.js +408 -0
- package/dist/likec4diagram/xyflow-sequence/sequence-view.d.ts +7 -0
- package/dist/likec4diagram/xyflow-sequence/sequence-view.js +273 -0
- package/dist/likec4diagram/xyflow-sequence/utils.d.ts +14 -0
- package/dist/likec4diagram/xyflow-sequence/utils.js +92 -0
- package/dist/navigationpanel/NavigationPanelControls.js +2 -2
- package/dist/navigationpanel/controls/ViewDetailsCard.js +27 -12
- package/dist/navigationpanel/dropdown/ProjectsMenu.js +53 -44
- package/dist/navigationpanel/walkthrough/ActiveWalkthroughControls.d.ts +1 -2
- package/dist/navigationpanel/walkthrough/ActiveWalkthroughControls.js +10 -41
- package/dist/navigationpanel/walkthrough/DynamicViewControls.d.ts +292 -0
- package/dist/navigationpanel/walkthrough/DynamicViewControls.js +119 -0
- package/dist/navigationpanel/walkthrough/index.d.ts +2 -1
- package/dist/overlays/element-details/ElementDetailsCard.css.js +7 -1
- package/dist/overlays/element-details/ElementDetailsCard.js +17 -19
- package/dist/overlays/relationship-details/RelationshipDetails.js +4 -1
- package/dist/overlays/relationship-details/layout.d.ts +3 -2
- package/dist/overlays/relationship-details/layout.js +1 -2
- package/dist/overlays/relationships-browser/RelationshipsBrowser.js +2 -1
- package/dist/overlays/relationships-browser/layout.js +1 -1
- package/dist/search/components/ElementsColumn.js +1 -1
- package/dist/state/DiagramActorProvider.d.ts +3 -2
- package/dist/state/DiagramActorProvider.js +40 -41
- package/dist/state/assign.js +11 -4
- package/dist/state/diagram-machine.d.ts +224 -194
- package/dist/state/diagram-machine.js +170 -63
- package/dist/state/utils.d.ts +7 -1
- package/dist/state/utils.js +67 -7
- package/dist/styles-min.css +1 -1
- package/dist/styles.css +1 -1
- package/dist/styles.css2.js +1 -1
- package/package.json +8 -7
- package/panda.buildinfo.json +45 -24
- package/src/LikeC4Diagram.props.ts +14 -1
- package/src/LikeC4Diagram.tsx +7 -4
- package/src/base/const.ts +12 -0
- package/src/base/index.ts +2 -0
- package/src/base/primitives/MarkdownBlock.tsx +2 -0
- package/src/base/primitives/edge/EdgeLabel.tsx +23 -19
- package/src/base/primitives/edge/EdgeLabelContainer.tsx +12 -7
- package/src/base/primitives/edge/EdgePath.tsx +25 -14
- package/src/base/primitives/edge/edge.css.ts +5 -14
- package/src/base/primitives/element/ElementActionButtons.tsx +1 -3
- package/src/base/primitives/element/ElementNodeContainer.tsx +3 -30
- package/src/base/primitives/element/ElementTitle.tsx +2 -3
- package/src/base/types.ts +7 -5
- package/src/bundle/LikeC4View.props.ts +14 -3
- package/src/bundle/LikeC4View.tsx +4 -14
- package/src/bundle/ReactLikeC4.tsx +1 -2
- package/src/components/Link.tsx +21 -18
- package/src/custom/customNodes.ts +7 -0
- package/src/hooks/useDiagram.ts +10 -0
- package/src/likec4diagram/DiagramUI.tsx +1 -1
- package/src/likec4diagram/DiagramXYFlow.tsx +10 -5
- package/src/likec4diagram/convert-to-xyflow.ts +45 -0
- package/src/likec4diagram/custom/edges/RelationshipEdge.tsx +0 -1
- package/src/likec4diagram/custom/edges/SequenceStepEdge.tsx +65 -0
- package/src/likec4diagram/custom/index.ts +7 -1
- package/src/likec4diagram/custom/nodes/ElementActions.tsx +4 -2
- package/src/likec4diagram/custom/nodes/SequenceActorNode.tsx +175 -0
- package/src/likec4diagram/custom/nodes/index.ts +1 -0
- package/src/likec4diagram/custom/nodes/nodes.tsx +1 -1
- package/src/likec4diagram/relationship-popover/RelationshipPopover.tsx +36 -30
- package/src/likec4diagram/types.ts +96 -13
- package/src/likec4diagram/{useViewToNodesEdges.ts → xyflow-diagram/diagram-view.ts} +7 -28
- package/src/likec4diagram/xyflow-sequence/_types.ts +45 -0
- package/src/likec4diagram/xyflow-sequence/const.ts +37 -0
- package/src/likec4diagram/xyflow-sequence/layouter.ts +567 -0
- package/src/likec4diagram/xyflow-sequence/sequence-view.ts +337 -0
- package/src/likec4diagram/xyflow-sequence/utils.ts +112 -0
- package/src/navigationpanel/NavigationPanelControls.tsx +2 -2
- package/src/navigationpanel/controls/ViewDetailsCard.tsx +29 -12
- package/src/navigationpanel/dropdown/ProjectsMenu.tsx +5 -1
- package/src/navigationpanel/walkthrough/ActiveWalkthroughControls.tsx +5 -40
- package/src/navigationpanel/walkthrough/DynamicViewControls.tsx +125 -0
- package/src/navigationpanel/walkthrough/index.tsx +2 -1
- package/src/overlays/element-details/ElementDetailsCard.css.ts +7 -1
- package/src/overlays/element-details/ElementDetailsCard.tsx +24 -25
- package/src/overlays/relationship-details/RelationshipDetails.tsx +5 -2
- package/src/overlays/relationship-details/layout.ts +4 -3
- package/src/overlays/relationships-browser/RelationshipsBrowser.tsx +2 -1
- package/src/overlays/relationships-browser/layout.ts +1 -1
- package/src/search/components/ElementsColumn.tsx +1 -1
- package/src/state/DiagramActorProvider.tsx +46 -51
- package/src/state/assign.ts +18 -5
- package/src/state/diagram-machine.ts +207 -75
- package/src/state/utils.ts +81 -7
- package/dist/likec4diagram/useViewToNodesEdges.d.ts +0 -12
|
@@ -20,7 +20,7 @@ import { DeploymentElementActions, ElementActions } from './ElementActions'
|
|
|
20
20
|
import { CompoundDeploymentToolbar, CompoundElementToolbar } from './toolbar/CompoundToolbar'
|
|
21
21
|
import { DeploymentElementToolbar, ElementToolbar } from './toolbar/ElementToolbar'
|
|
22
22
|
|
|
23
|
-
type CustomNodes = Required<CustomNodesType>
|
|
23
|
+
export type CustomNodes = Required<CustomNodesType>
|
|
24
24
|
|
|
25
25
|
export function ElementDetailsButtonWithHandler(
|
|
26
26
|
props: NodeProps<Types.ElementNodeData | Types.DeploymentElementNodeData>,
|
|
@@ -29,7 +29,7 @@ import {
|
|
|
29
29
|
useRef,
|
|
30
30
|
useState,
|
|
31
31
|
} from 'react'
|
|
32
|
-
import { clamp, filter, isTruthy, map, partition, pipe } from 'remeda'
|
|
32
|
+
import { clamp, filter, isEmpty, isTruthy, map, partition, pipe } from 'remeda'
|
|
33
33
|
import { Link } from '../../components/Link'
|
|
34
34
|
import { useDiagramEventHandlers } from '../../context/DiagramEventHandlers'
|
|
35
35
|
import { useEnabledFeatures } from '../../context/DiagramFeatures'
|
|
@@ -61,6 +61,7 @@ function selectDiagramContext(c: DiagramContext) {
|
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
export const RelationshipPopover = memo(() => {
|
|
64
|
+
const likec4model = useLikeC4Model()
|
|
64
65
|
const actorRef = useActorRef(RelationshipPopoverActorLogic)
|
|
65
66
|
const diagram = useDiagram()
|
|
66
67
|
const { viewId, selected } = useDiagramContext(selectDiagramContext)
|
|
@@ -132,13 +133,42 @@ export const RelationshipPopover = memo(() => {
|
|
|
132
133
|
[openedEdgeId],
|
|
133
134
|
)
|
|
134
135
|
|
|
135
|
-
if (!diagramEdge || !sourceNode || !targetNode) {
|
|
136
|
+
if (!diagramEdge || !sourceNode || !targetNode || isEmpty(diagramEdge.relations)) {
|
|
137
|
+
return null
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const [direct, nested] = pipe(
|
|
141
|
+
diagramEdge.relations,
|
|
142
|
+
map(id => {
|
|
143
|
+
try {
|
|
144
|
+
return likec4model.relationship(id)
|
|
145
|
+
} catch (e) {
|
|
146
|
+
// View was cached, but likec4model based on new data
|
|
147
|
+
console.error(
|
|
148
|
+
`View is cached and likec4model missing relationship ${id} from ${sourceNode.id} -> ${targetNode.id}`,
|
|
149
|
+
e,
|
|
150
|
+
)
|
|
151
|
+
return null
|
|
152
|
+
}
|
|
153
|
+
}),
|
|
154
|
+
filter(isTruthy),
|
|
155
|
+
partition(r => r.source.id === sourceNode.id && r.target.id === targetNode.id),
|
|
156
|
+
)
|
|
157
|
+
|
|
158
|
+
if (direct.length === 0 && nested.length === 0) {
|
|
159
|
+
console.warn('No relationships found diagram edge', {
|
|
160
|
+
diagramEdge,
|
|
161
|
+
sourceNode,
|
|
162
|
+
targetNode,
|
|
163
|
+
})
|
|
136
164
|
return null
|
|
137
165
|
}
|
|
138
166
|
|
|
139
167
|
return (
|
|
140
168
|
<RelationshipPopoverInternal
|
|
141
169
|
viewId={viewId}
|
|
170
|
+
direct={direct}
|
|
171
|
+
nested={nested}
|
|
142
172
|
diagramEdge={diagramEdge}
|
|
143
173
|
sourceNode={sourceNode}
|
|
144
174
|
targetNode={targetNode}
|
|
@@ -153,6 +183,8 @@ const getEdgeLabelElement = (edgeId: string, container: HTMLDivElement | undefin
|
|
|
153
183
|
|
|
154
184
|
type RelationshipPopoverInternalProps = {
|
|
155
185
|
viewId: ViewId
|
|
186
|
+
direct: LikeC4Model.AnyRelation[]
|
|
187
|
+
nested: LikeC4Model.AnyRelation[]
|
|
156
188
|
diagramEdge: DiagramEdge
|
|
157
189
|
sourceNode: DiagramNode
|
|
158
190
|
targetNode: DiagramNode
|
|
@@ -163,6 +195,8 @@ const POPOVER_PADDING = 8
|
|
|
163
195
|
const RelationshipPopoverInternal = ({
|
|
164
196
|
viewId,
|
|
165
197
|
diagramEdge,
|
|
198
|
+
direct,
|
|
199
|
+
nested,
|
|
166
200
|
sourceNode,
|
|
167
201
|
targetNode,
|
|
168
202
|
onMouseEnter,
|
|
@@ -240,36 +274,8 @@ const RelationshipPopoverInternal = ({
|
|
|
240
274
|
}
|
|
241
275
|
}, [referenceEl])
|
|
242
276
|
|
|
243
|
-
const likec4model = useLikeC4Model()
|
|
244
277
|
const diagram = useDiagram()
|
|
245
278
|
|
|
246
|
-
const [direct, nested] = pipe(
|
|
247
|
-
diagramEdge.relations,
|
|
248
|
-
map(id => {
|
|
249
|
-
try {
|
|
250
|
-
return likec4model.relationship(id)
|
|
251
|
-
} catch (e) {
|
|
252
|
-
// View was cached, but likec4model based on new data
|
|
253
|
-
console.error(
|
|
254
|
-
`View is cached and likec4model missing relationship ${id} from ${sourceNode.id} -> ${targetNode.id}`,
|
|
255
|
-
e,
|
|
256
|
-
)
|
|
257
|
-
return null
|
|
258
|
-
}
|
|
259
|
-
}),
|
|
260
|
-
filter(isTruthy),
|
|
261
|
-
partition(r => r.source.id === sourceNode.id && r.target.id === targetNode.id),
|
|
262
|
-
)
|
|
263
|
-
|
|
264
|
-
if (direct.length === 0 && nested.length === 0) {
|
|
265
|
-
console.error('No relationships found diagram edge', {
|
|
266
|
-
diagramEdge,
|
|
267
|
-
sourceNode,
|
|
268
|
-
targetNode,
|
|
269
|
-
})
|
|
270
|
-
return null
|
|
271
|
-
}
|
|
272
|
-
|
|
273
279
|
const navigateTo = enableNavigateTo
|
|
274
280
|
? (viewId: ViewId) => {
|
|
275
281
|
diagram.navigateTo(viewId)
|
|
@@ -1,4 +1,14 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {
|
|
2
|
+
BBox,
|
|
3
|
+
DeploymentFqn,
|
|
4
|
+
DiagramEdge,
|
|
5
|
+
DiagramNode,
|
|
6
|
+
ExclusiveUnion,
|
|
7
|
+
Fqn,
|
|
8
|
+
IconUrl,
|
|
9
|
+
RichTextOrEmpty,
|
|
10
|
+
ViewId,
|
|
11
|
+
} from '@likec4/core/types'
|
|
2
12
|
import type { XYPosition } from '@xyflow/system'
|
|
3
13
|
import type { OptionalKeysOf, Simplify } from 'type-fest'
|
|
4
14
|
import type { Base, ReactFlowEdge, ReactFlowNode } from '../base/types'
|
|
@@ -44,14 +54,16 @@ export namespace Types {
|
|
|
44
54
|
/**
|
|
45
55
|
* Represents element from logical model
|
|
46
56
|
*/
|
|
47
|
-
export type ElementNodeData =
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
57
|
+
export type ElementNodeData = Simplify<
|
|
58
|
+
LeafNodeData & {
|
|
59
|
+
modelFqn: Fqn
|
|
60
|
+
deploymentFqn?: never
|
|
61
|
+
/**
|
|
62
|
+
* If set - this node has navigation to another view and diagram has handler for this
|
|
63
|
+
*/
|
|
64
|
+
navigateTo: ViewId | null
|
|
65
|
+
}
|
|
66
|
+
>
|
|
55
67
|
|
|
56
68
|
/**
|
|
57
69
|
* Represents element from deployment model
|
|
@@ -65,6 +77,32 @@ export namespace Types {
|
|
|
65
77
|
modelFqn: Fqn | null
|
|
66
78
|
}
|
|
67
79
|
|
|
80
|
+
export type SequenceActorNodePort = {
|
|
81
|
+
id: string
|
|
82
|
+
cx: number
|
|
83
|
+
cy: number
|
|
84
|
+
height: number
|
|
85
|
+
type: 'target' | 'source'
|
|
86
|
+
position: 'left' | 'right' | 'top' | 'bottom'
|
|
87
|
+
}
|
|
88
|
+
export type SequenceActorNodeData = Simplify<
|
|
89
|
+
& LeafNodeData
|
|
90
|
+
& {
|
|
91
|
+
navigateTo: ViewId | null
|
|
92
|
+
// If set - this node refers to a model element
|
|
93
|
+
modelFqn: Fqn | null
|
|
94
|
+
ports: Array<SequenceActorNodePort>
|
|
95
|
+
viewHeight: number
|
|
96
|
+
}
|
|
97
|
+
>
|
|
98
|
+
|
|
99
|
+
export type SequenceParallelAreaData = Simplify<
|
|
100
|
+
& LeafNodeData
|
|
101
|
+
& {
|
|
102
|
+
parallelPrefix: string
|
|
103
|
+
}
|
|
104
|
+
>
|
|
105
|
+
|
|
68
106
|
export type CompoundNodeData =
|
|
69
107
|
& Base.NodeData
|
|
70
108
|
& NonOptional<
|
|
@@ -117,13 +155,32 @@ export namespace Types {
|
|
|
117
155
|
|
|
118
156
|
export type ElementNode = ReactFlowNode<ElementNodeData, 'element'>
|
|
119
157
|
export type DeploymentElementNode = ReactFlowNode<DeploymentElementNodeData, 'deployment'>
|
|
158
|
+
|
|
159
|
+
export type SequenceActorNode = ReactFlowNode<SequenceActorNodeData, 'seq-actor'>
|
|
160
|
+
export type SequenceParallelArea = ReactFlowNode<SequenceParallelAreaData, 'seq-parallel'>
|
|
161
|
+
|
|
120
162
|
export type CompoundElementNode = ReactFlowNode<CompoundElementNodeData, 'compound-element'>
|
|
121
163
|
export type CompoundDeploymentNode = ReactFlowNode<CompoundDeploymentNodeData, 'compound-deployment'>
|
|
122
164
|
export type ViewGroupNode = ReactFlowNode<ViewGroupNodeData, 'view-group'>
|
|
123
165
|
|
|
124
|
-
export type Node =
|
|
166
|
+
export type Node =
|
|
167
|
+
| ElementNode
|
|
168
|
+
| DeploymentElementNode
|
|
169
|
+
| CompoundElementNode
|
|
170
|
+
| CompoundDeploymentNode
|
|
171
|
+
| ViewGroupNode
|
|
172
|
+
| SequenceActorNode
|
|
173
|
+
| SequenceParallelArea
|
|
125
174
|
|
|
126
|
-
export type NodeData =
|
|
175
|
+
export type NodeData = ExclusiveUnion<{
|
|
176
|
+
ElementNodeData: ElementNodeData
|
|
177
|
+
DeploymentElementNodeData: DeploymentElementNodeData
|
|
178
|
+
CompoundElementNodeData: CompoundElementNodeData
|
|
179
|
+
CompoundDeploymentNodeData: CompoundDeploymentNodeData
|
|
180
|
+
ViewGroupNodeData: ViewGroupNodeData
|
|
181
|
+
SequenceActorNodeData: SequenceActorNodeData
|
|
182
|
+
SequenceParallelAreaData: SequenceParallelAreaData
|
|
183
|
+
}>
|
|
127
184
|
|
|
128
185
|
export type RelationshipEdgeData = Simplify<
|
|
129
186
|
& Base.EdgeData
|
|
@@ -150,8 +207,34 @@ export namespace Types {
|
|
|
150
207
|
}
|
|
151
208
|
>
|
|
152
209
|
|
|
210
|
+
export type SequenceStepEdgeData = Simplify<
|
|
211
|
+
& Base.EdgeData
|
|
212
|
+
& NonOptional<
|
|
213
|
+
Pick<
|
|
214
|
+
DiagramEdge,
|
|
215
|
+
| 'id'
|
|
216
|
+
| 'label'
|
|
217
|
+
| 'technology'
|
|
218
|
+
| 'points'
|
|
219
|
+
| 'dir'
|
|
220
|
+
| 'color'
|
|
221
|
+
| 'line'
|
|
222
|
+
| 'head'
|
|
223
|
+
| 'tail'
|
|
224
|
+
| 'navigateTo'
|
|
225
|
+
>
|
|
226
|
+
>
|
|
227
|
+
& {
|
|
228
|
+
notes: RichTextOrEmpty
|
|
229
|
+
labelXY: XYPosition | null
|
|
230
|
+
labelBBox: BBox
|
|
231
|
+
controlPoints: XYPosition[] | undefined | null
|
|
232
|
+
}
|
|
233
|
+
>
|
|
234
|
+
|
|
153
235
|
export type RelationshipEdge = ReactFlowEdge<RelationshipEdgeData, 'relationship'>
|
|
236
|
+
export type SequenceStepEdge = ReactFlowEdge<SequenceStepEdgeData, 'seq-step'>
|
|
154
237
|
|
|
155
|
-
export type Edge = RelationshipEdge
|
|
156
|
-
export type EdgeData = RelationshipEdgeData
|
|
238
|
+
export type Edge = RelationshipEdge | SequenceStepEdge
|
|
239
|
+
export type EdgeData = RelationshipEdgeData | SequenceStepEdgeData
|
|
157
240
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
+
type BBox,
|
|
2
3
|
type DiagramEdge,
|
|
3
4
|
type DiagramNode,
|
|
4
5
|
type DiagramView,
|
|
@@ -13,18 +14,16 @@ import {
|
|
|
13
14
|
RichText,
|
|
14
15
|
whereOperatorAsPredicate,
|
|
15
16
|
} from '@likec4/core'
|
|
16
|
-
import { useCustomCompareMemo } from '@react-hookz/web'
|
|
17
|
-
import { deepEqual, shallowEqual } from 'fast-equals'
|
|
18
17
|
import { hasAtLeast, pick } from 'remeda'
|
|
19
|
-
import { ZIndexes } from '
|
|
20
|
-
import type { Types } from '
|
|
18
|
+
import { ZIndexes } from '../../base/const'
|
|
19
|
+
import type { Types } from '../types'
|
|
21
20
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
view: Pick<DiagramView, 'id' | 'nodes' | 'edges' | '_type'>
|
|
21
|
+
export function diagramToXY(opts: {
|
|
22
|
+
view: Pick<DiagramView, 'id' | 'nodes' | 'edges' | 'bounds' | '_type'>
|
|
25
23
|
where: WhereOperator | null
|
|
26
24
|
nodesSelectable: boolean
|
|
27
25
|
}): {
|
|
26
|
+
bounds: BBox
|
|
28
27
|
xynodes: Types.Node[]
|
|
29
28
|
xyedges: Types.Edge[]
|
|
30
29
|
} {
|
|
@@ -269,28 +268,8 @@ function viewToNodesEdge(opts: {
|
|
|
269
268
|
}
|
|
270
269
|
|
|
271
270
|
return {
|
|
271
|
+
bounds: view.bounds,
|
|
272
272
|
xynodes,
|
|
273
273
|
xyedges,
|
|
274
274
|
}
|
|
275
275
|
}
|
|
276
|
-
type ViewToNodesEdgeInput = {
|
|
277
|
-
view: DiagramView
|
|
278
|
-
where: WhereOperator | null
|
|
279
|
-
nodesSelectable: boolean
|
|
280
|
-
}
|
|
281
|
-
const viewToNodesEdgeEqual = (a: ViewToNodesEdgeInput, b: ViewToNodesEdgeInput) => (
|
|
282
|
-
a.view.id === b.view.id
|
|
283
|
-
&& a.view._type === b.view._type
|
|
284
|
-
&& a.nodesSelectable === b.nodesSelectable
|
|
285
|
-
&& shallowEqual(a.view.nodes, b.view.nodes)
|
|
286
|
-
&& shallowEqual(a.view.edges, b.view.edges)
|
|
287
|
-
&& deepEqual(a.where, b.where)
|
|
288
|
-
)
|
|
289
|
-
|
|
290
|
-
export function useViewToNodesEdges(params: ViewToNodesEdgeInput) {
|
|
291
|
-
return useCustomCompareMemo(
|
|
292
|
-
() => viewToNodesEdge(params),
|
|
293
|
-
[params],
|
|
294
|
-
([a], [b]) => !!a && !!b && viewToNodesEdgeEqual(a, b),
|
|
295
|
-
)
|
|
296
|
-
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { DiagramEdge, DiagramNode, EdgeId } from '@likec4/core/types'
|
|
2
|
+
|
|
3
|
+
export type Step = {
|
|
4
|
+
id: EdgeId
|
|
5
|
+
from: {
|
|
6
|
+
column: number
|
|
7
|
+
row: number
|
|
8
|
+
}
|
|
9
|
+
to: {
|
|
10
|
+
column: number
|
|
11
|
+
row: number
|
|
12
|
+
}
|
|
13
|
+
source: DiagramNode
|
|
14
|
+
target: DiagramNode
|
|
15
|
+
label: null | {
|
|
16
|
+
height: number
|
|
17
|
+
width: number
|
|
18
|
+
text: string | null
|
|
19
|
+
}
|
|
20
|
+
isSelfLoop: boolean
|
|
21
|
+
isBack: boolean
|
|
22
|
+
parallelPrefix: string | null
|
|
23
|
+
offset: number // offset for continuing edges
|
|
24
|
+
edge: DiagramEdge
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export type Compound = {
|
|
28
|
+
node: DiagramNode
|
|
29
|
+
from: DiagramNode
|
|
30
|
+
to: DiagramNode
|
|
31
|
+
|
|
32
|
+
nested: Compound[]
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export type ParallelRect = {
|
|
36
|
+
parallelPrefix: string
|
|
37
|
+
min: {
|
|
38
|
+
column: number
|
|
39
|
+
row: number
|
|
40
|
+
}
|
|
41
|
+
max: {
|
|
42
|
+
column: number
|
|
43
|
+
row: number
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { ThemeColor } from '@likec4/core/types'
|
|
2
|
+
|
|
3
|
+
// minimum space between actors
|
|
4
|
+
export const ACTOR_GAP = 60
|
|
5
|
+
|
|
6
|
+
// minimum space between columns
|
|
7
|
+
export const COLUMN_GAP = 32
|
|
8
|
+
|
|
9
|
+
// minimum height of a step row
|
|
10
|
+
export const MIN_ROW_HEIGHT = 80
|
|
11
|
+
|
|
12
|
+
// height of ports, edges connected to center of ports
|
|
13
|
+
export const PORT_HEIGHT = 32
|
|
14
|
+
|
|
15
|
+
// margin from step label to step box
|
|
16
|
+
export const STEP_LABEL_MARGIN = 50
|
|
17
|
+
|
|
18
|
+
// offset from actor box
|
|
19
|
+
export const FIRST_STEP_OFFSET = 30
|
|
20
|
+
|
|
21
|
+
// offset for continuing steps
|
|
22
|
+
// A -> B,
|
|
23
|
+
// C -> D (sequential)
|
|
24
|
+
// A -> B -> C (continuous)
|
|
25
|
+
export const CONTINUOUS_OFFSET = 22
|
|
26
|
+
|
|
27
|
+
export const SeqZIndex = {
|
|
28
|
+
compound: 0,
|
|
29
|
+
parallel: 1,
|
|
30
|
+
actor: 10,
|
|
31
|
+
step: 20,
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export const SeqParallelAreaColor = {
|
|
35
|
+
default: 'gray',
|
|
36
|
+
active: 'amber',
|
|
37
|
+
} satisfies Record<string, ThemeColor>
|