@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.
Files changed (49) hide show
  1. package/dist/LikeC4Diagram.d.ts +1 -1
  2. package/dist/LikeC4Diagram.props.d.ts +10 -11
  3. package/dist/hooks/useUpdateEffect.d.ts +1 -0
  4. package/dist/index.d.ts +2 -0
  5. package/dist/index.mjs +769 -8587
  6. package/dist/state/DiagramContext.d.ts +746 -181
  7. package/dist/state/diagram-to-xyflow.d.ts +10 -0
  8. package/dist/state/diagramStore.d.ts +782 -202
  9. package/dist/style.css +273 -275
  10. package/dist/types.d.ts +20 -0
  11. package/dist/xyflow/EdgeMarkers.d.ts +1 -0
  12. package/dist/xyflow/FitviewOnDiagramChange.d.ts +1 -1
  13. package/dist/xyflow/XYFlow.d.ts +1 -4
  14. package/dist/xyflow/XYFlowEvents.d.ts +41 -12
  15. package/dist/xyflow/XYFlowInner.d.ts +0 -1
  16. package/dist/xyflow/edges/RelationshipEdge.d.ts +3 -3
  17. package/dist/xyflow/hooks/index.d.ts +0 -1
  18. package/dist/xyflow/hooks/useXYFlow.d.ts +27 -27
  19. package/dist/xyflow/types.d.ts +11 -19
  20. package/dist/xyflow/utils.d.ts +1 -0
  21. package/package.json +11 -11
  22. package/src/LikeC4Diagram.props.ts +17 -13
  23. package/src/LikeC4Diagram.tsx +67 -106
  24. package/src/globals.css.ts +10 -6
  25. package/src/hooks/useUpdateEffect.ts +16 -1
  26. package/src/index.ts +3 -0
  27. package/src/state/DiagramContext.tsx +19 -27
  28. package/src/{xyflow → state}/diagram-to-xyflow.ts +19 -18
  29. package/src/state/diagramStore.ts +404 -192
  30. package/src/types.ts +22 -0
  31. package/src/ui/BackwardForwardPanel.tsx +24 -7
  32. package/src/xyflow/EdgeMarkers.tsx +2 -0
  33. package/src/xyflow/FitviewOnDiagramChange.tsx +42 -75
  34. package/src/xyflow/SelectEdgesOnNodeFocus.tsx +1 -1
  35. package/src/xyflow/XYFlow.tsx +57 -35
  36. package/src/xyflow/XYFlowEvents.tsx +58 -10
  37. package/src/xyflow/XYFlowInner.tsx +9 -8
  38. package/src/xyflow/edges/RelationshipEdge.tsx +43 -29
  39. package/src/xyflow/edges/edges.css.ts +3 -3
  40. package/src/xyflow/edges/utils.ts +0 -1
  41. package/src/xyflow/hooks/index.ts +0 -1
  42. package/src/xyflow/hooks/useLayoutConstraints.ts +42 -65
  43. package/src/xyflow/nodes/element/ElementNode.tsx +8 -11
  44. package/src/xyflow/nodes/element/element.css.ts +8 -6
  45. package/src/xyflow/types.ts +14 -32
  46. package/src/xyflow/utils.ts +4 -0
  47. package/dist/xyflow/SyncWithDiagram.d.ts +0 -4
  48. package/dist/xyflow/diagram-to-xyflow.d.ts +0 -7
  49. 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
- }