@likec4/diagram 1.6.0 → 1.7.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/LikeC4Diagram.d.ts +1 -1
- package/dist/LikeC4Diagram.props.d.ts +10 -11
- package/dist/hooks/useUpdateEffect.d.ts +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.mjs +769 -8587
- package/dist/state/DiagramContext.d.ts +746 -181
- package/dist/state/diagram-to-xyflow.d.ts +10 -0
- package/dist/state/diagramStore.d.ts +782 -202
- package/dist/style.css +273 -275
- package/dist/types.d.ts +20 -0
- package/dist/xyflow/EdgeMarkers.d.ts +1 -0
- package/dist/xyflow/FitviewOnDiagramChange.d.ts +1 -1
- package/dist/xyflow/XYFlow.d.ts +1 -4
- package/dist/xyflow/XYFlowEvents.d.ts +41 -12
- package/dist/xyflow/XYFlowInner.d.ts +0 -1
- package/dist/xyflow/edges/RelationshipEdge.d.ts +3 -3
- package/dist/xyflow/hooks/index.d.ts +0 -1
- package/dist/xyflow/hooks/useXYFlow.d.ts +27 -27
- package/dist/xyflow/types.d.ts +11 -19
- package/dist/xyflow/utils.d.ts +1 -0
- package/package.json +11 -11
- package/src/LikeC4Diagram.props.ts +17 -13
- package/src/LikeC4Diagram.tsx +67 -106
- package/src/globals.css.ts +10 -6
- package/src/hooks/useUpdateEffect.ts +16 -1
- package/src/index.ts +3 -0
- package/src/state/DiagramContext.tsx +19 -27
- package/src/{xyflow → state}/diagram-to-xyflow.ts +19 -18
- package/src/state/diagramStore.ts +404 -192
- package/src/types.ts +22 -0
- package/src/ui/BackwardForwardPanel.tsx +24 -7
- package/src/xyflow/EdgeMarkers.tsx +2 -0
- package/src/xyflow/FitviewOnDiagramChange.tsx +42 -75
- package/src/xyflow/SelectEdgesOnNodeFocus.tsx +1 -1
- package/src/xyflow/XYFlow.tsx +57 -35
- package/src/xyflow/XYFlowEvents.tsx +58 -10
- package/src/xyflow/XYFlowInner.tsx +9 -8
- package/src/xyflow/edges/RelationshipEdge.tsx +43 -29
- package/src/xyflow/edges/edges.css.ts +3 -3
- package/src/xyflow/edges/utils.ts +0 -1
- package/src/xyflow/hooks/index.ts +0 -1
- package/src/xyflow/hooks/useLayoutConstraints.ts +42 -65
- package/src/xyflow/nodes/element/ElementNode.tsx +8 -11
- package/src/xyflow/nodes/element/element.css.ts +8 -6
- package/src/xyflow/types.ts +14 -32
- package/src/xyflow/utils.ts +4 -0
- package/dist/xyflow/SyncWithDiagram.d.ts +0 -4
- package/dist/xyflow/diagram-to-xyflow.d.ts +0 -7
- package/src/xyflow/SyncWithDiagram.tsx +0 -85
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import { deepEqual as eq } from 'fast-equals'
|
|
2
|
-
|
|
3
|
-
import { useEffect } from 'react'
|
|
4
|
-
import { omit } from 'remeda'
|
|
5
|
-
import { useDiagramState, useDiagramStoreApi } from '../state/useDiagramStore'
|
|
6
|
-
import { diagramViewToXYFlowData } from './diagram-to-xyflow'
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Syncs the diagram state with the XYFlow instance
|
|
10
|
-
*/
|
|
11
|
-
export function SyncWithDiagram() {
|
|
12
|
-
const xyflowSynced = useDiagramState(s => s.xyflowSynced)
|
|
13
|
-
const diagramStoreApi = useDiagramStoreApi()
|
|
14
|
-
|
|
15
|
-
useEffect(() => {
|
|
16
|
-
if (xyflowSynced) {
|
|
17
|
-
return
|
|
18
|
-
}
|
|
19
|
-
const {
|
|
20
|
-
view,
|
|
21
|
-
nodesDraggable,
|
|
22
|
-
nodesSelectable,
|
|
23
|
-
focusedNodeId,
|
|
24
|
-
xystore
|
|
25
|
-
} = diagramStoreApi.getState()
|
|
26
|
-
const updates = diagramViewToXYFlowData(view, {
|
|
27
|
-
draggable: nodesDraggable,
|
|
28
|
-
selectable: nodesSelectable || focusedNodeId !== null
|
|
29
|
-
})
|
|
30
|
-
|
|
31
|
-
const {
|
|
32
|
-
nodeLookup,
|
|
33
|
-
edgeLookup,
|
|
34
|
-
setNodes,
|
|
35
|
-
setEdges
|
|
36
|
-
} = xystore.getState()
|
|
37
|
-
|
|
38
|
-
setNodes(updates.nodes.map(update => {
|
|
39
|
-
const existing = nodeLookup.get(update.id)?.internals.userNode
|
|
40
|
-
if (existing && existing.type === update.type && eq(existing.parentId, update.parentId)) {
|
|
41
|
-
if (eq(existing.data.element, update.data.element)) {
|
|
42
|
-
return existing
|
|
43
|
-
}
|
|
44
|
-
return {
|
|
45
|
-
...existing,
|
|
46
|
-
...update
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
return update
|
|
50
|
-
}))
|
|
51
|
-
|
|
52
|
-
setEdges(updates.edges.map(update => {
|
|
53
|
-
const existing = edgeLookup.get(update.id)
|
|
54
|
-
if (existing) {
|
|
55
|
-
if (
|
|
56
|
-
eq(existing.data.controlPoints, update.data.controlPoints)
|
|
57
|
-
&& eq(existing.markerStart, update.markerStart)
|
|
58
|
-
&& eq(existing.markerEnd, update.markerEnd)
|
|
59
|
-
&& eq(existing.data.edge, update.data.edge)
|
|
60
|
-
) {
|
|
61
|
-
return existing
|
|
62
|
-
}
|
|
63
|
-
return {
|
|
64
|
-
...omit(existing, ['data', 'markerStart', 'markerEnd']),
|
|
65
|
-
...update,
|
|
66
|
-
data: {
|
|
67
|
-
...existing.data,
|
|
68
|
-
...update.data
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
return update
|
|
73
|
-
}))
|
|
74
|
-
|
|
75
|
-
diagramStoreApi.setState(
|
|
76
|
-
{
|
|
77
|
-
xyflowSynced: true
|
|
78
|
-
},
|
|
79
|
-
false,
|
|
80
|
-
'xyflowSynced'
|
|
81
|
-
)
|
|
82
|
-
}, [xyflowSynced, diagramStoreApi])
|
|
83
|
-
|
|
84
|
-
return null
|
|
85
|
-
}
|