@likec4/diagram 1.20.1 → 1.20.3

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 (134) hide show
  1. package/dist/LikeC4Diagram.css.d.ts +1 -0
  2. package/dist/LikeC4Diagram.css.js +3 -1
  3. package/dist/base/BaseXYFlow.js +15 -14
  4. package/dist/base/Link.css.d.ts +3 -0
  5. package/dist/base/Link.css.js +9 -0
  6. package/dist/base/Link.d.ts +5 -0
  7. package/dist/base/Link.js +58 -0
  8. package/dist/base/const.d.ts +1 -0
  9. package/dist/base/const.js +2 -1
  10. package/dist/base/example/custom.d.ts +1 -1
  11. package/dist/base/index.d.ts +1 -0
  12. package/dist/base/primitives/compound/CompoundActionButton.js +2 -1
  13. package/dist/base/primitives/compound/CompoundDetailsButton.js +2 -1
  14. package/dist/base/primitives/compound/CompoundNodeContainer.css.d.ts +0 -1
  15. package/dist/base/primitives/compound/CompoundNodeContainer.css.js +4 -6
  16. package/dist/base/primitives/compound/CompoundNodeContainer.js +2 -2
  17. package/dist/base/primitives/customEdge.d.ts +1 -1
  18. package/dist/base/primitives/customEdge.js +1 -1
  19. package/dist/base/primitives/customNode.js +1 -1
  20. package/dist/base/primitives/edge/EdgeLabel.js +3 -1
  21. package/dist/base/primitives/edge/EdgePath.d.ts +2 -1
  22. package/dist/base/primitives/edge/EdgePath.js +2 -0
  23. package/dist/base/primitives/element/ElementActionButtons.js +2 -1
  24. package/dist/base/primitives/element/ElementDetailsButton.js +2 -1
  25. package/dist/base/primitives/element/ElementNodeContainer.css.d.ts +0 -1
  26. package/dist/base/primitives/element/ElementNodeContainer.css.js +1 -3
  27. package/dist/base/primitives/element/ElementNodeContainer.js +2 -3
  28. package/dist/base/primitives/element/ElementShape.js +4 -2
  29. package/dist/base/primitives/element/ElementTitle.js +2 -1
  30. package/dist/base/updateEdges.js +3 -3
  31. package/dist/base/updateNodes.js +2 -2
  32. package/dist/context/FramerMotionConfig.js +1 -1
  33. package/dist/hooks/useDiagram.d.ts +313 -90
  34. package/dist/hooks/useDiagramActor.d.ts +2 -2
  35. package/dist/hooks/useDiagramContext.d.ts +1 -1
  36. package/dist/hooks/useXYFlow.d.ts +2 -1
  37. package/dist/hooks/useXYFlow.js +5 -0
  38. package/dist/likec4diagram/XYFlow.js +12 -10
  39. package/dist/likec4diagram/custom/edges/RelationshipEdge.d.ts +1 -1
  40. package/dist/likec4diagram/custom/edges/RelationshipsDropdownMenu.js +2 -2
  41. package/dist/likec4diagram/custom/index.d.ts +1 -1
  42. package/dist/likec4diagram/custom/nodes/nodeTypes.js +2 -2
  43. package/dist/likec4diagram/state/actorContext.d.ts +1438 -364
  44. package/dist/likec4diagram/state/assign.js +2 -2
  45. package/dist/likec4diagram/state/machine.d.ts +321 -93
  46. package/dist/likec4diagram/state/syncManualLayoutActor.d.ts +1 -1
  47. package/dist/likec4diagram/types.d.ts +1 -0
  48. package/dist/likec4diagram/ui/diagram-title/DiagramTitlePanel.js +4 -3
  49. package/dist/likec4diagram/useLayoutConstraints.d.ts +2 -1
  50. package/dist/likec4diagram/useLayoutConstraints.js +14 -15
  51. package/dist/likec4diagram/useViewToNodesEdges.js +3 -1
  52. package/dist/overlays/element-details/ElementDetailsCard.css.d.ts +0 -1
  53. package/dist/overlays/element-details/ElementDetailsCard.css.js +1 -3
  54. package/dist/overlays/element-details/ElementDetailsCard.js +5 -30
  55. package/dist/overlays/element-details/TabPanelRelationships.js +2 -2
  56. package/dist/overlays/relationship-details/RelationshipDetails.js +4 -4
  57. package/dist/overlays/relationship-details/custom/ElementActions.js +1 -3
  58. package/dist/overlays/relationship-details/custom/edgeTypes.d.ts +1 -1
  59. package/dist/overlays/relationship-details/hooks.d.ts +2 -2
  60. package/dist/overlays/relationship-details/hooks.js +7 -7
  61. package/dist/overlays/relationship-details/useLayoutedDetails.js +7 -10
  62. package/dist/overlays/relationships-browser/-useRelationshipsView.d.ts +4 -1
  63. package/dist/overlays/relationships-browser/-useRelationshipsView.js +12 -11
  64. package/dist/overlays/relationships-browser/RelationshipsBrowser.js +81 -66
  65. package/dist/overlays/relationships-browser/_types.d.ts +2 -1
  66. package/dist/overlays/relationships-browser/actor.d.ts +15 -2
  67. package/dist/overlays/relationships-browser/actor.js +262 -65
  68. package/dist/overlays/relationships-browser/const.d.ts +1 -0
  69. package/dist/overlays/relationships-browser/const.js +4 -0
  70. package/dist/overlays/relationships-browser/custom/ElementActions.js +13 -3
  71. package/dist/overlays/relationships-browser/custom/edgeTypes.d.ts +3 -2
  72. package/dist/overlays/relationships-browser/custom/edgeTypes.js +24 -6
  73. package/dist/overlays/relationships-browser/custom/nodeTypes.js +3 -2
  74. package/dist/overlays/relationships-browser/hooks.d.ts +6 -3
  75. package/dist/overlays/relationships-browser/hooks.js +4 -2
  76. package/dist/overlays/relationships-browser/useViewToNodesEdges.js +7 -2
  77. package/dist/style.css +1 -1
  78. package/dist/utils/xyflow.js +9 -1
  79. package/package.json +10 -10
  80. package/src/LikeC4Diagram.css.ts +8 -0
  81. package/src/base/BaseXYFlow.tsx +23 -14
  82. package/src/base/Link.css.ts +49 -0
  83. package/src/base/Link.tsx +66 -0
  84. package/src/base/const.ts +1 -0
  85. package/src/base/index.ts +2 -0
  86. package/src/base/primitives/compound/CompoundActionButton.tsx +2 -1
  87. package/src/base/primitives/compound/CompoundDetailsButton.tsx +2 -1
  88. package/src/base/primitives/compound/CompoundNodeContainer.css.ts +16 -10
  89. package/src/base/primitives/compound/CompoundNodeContainer.tsx +1 -1
  90. package/src/base/primitives/customEdge.ts +2 -0
  91. package/src/base/primitives/customNode.ts +3 -0
  92. package/src/base/primitives/edge/EdgeLabel.tsx +3 -1
  93. package/src/base/primitives/edge/EdgePath.tsx +3 -0
  94. package/src/base/primitives/element/ElementActionButtons.tsx +2 -1
  95. package/src/base/primitives/element/ElementDetailsButton.tsx +2 -1
  96. package/src/base/primitives/element/ElementNodeContainer.css.ts +9 -4
  97. package/src/base/primitives/element/ElementNodeContainer.tsx +1 -2
  98. package/src/base/primitives/element/ElementShape.tsx +4 -3
  99. package/src/base/primitives/element/ElementTitle.tsx +2 -1
  100. package/src/base/updateEdges.ts +3 -2
  101. package/src/base/updateNodes.ts +3 -2
  102. package/src/context/DiagramFeatures.tsx +1 -0
  103. package/src/context/FramerMotionConfig.tsx +1 -1
  104. package/src/hooks/useDiagramActor.ts +7 -5
  105. package/src/hooks/useDiagramContext.ts +4 -1
  106. package/src/hooks/useXYFlow.ts +6 -1
  107. package/src/likec4diagram/XYFlow.tsx +20 -9
  108. package/src/likec4diagram/custom/edges/RelationshipsDropdownMenu.tsx +2 -2
  109. package/src/likec4diagram/custom/nodes/nodeTypes.tsx +2 -2
  110. package/src/likec4diagram/types.ts +1 -0
  111. package/src/likec4diagram/ui/diagram-title/DiagramTitlePanel.tsx +4 -3
  112. package/src/likec4diagram/useLayoutConstraints.ts +23 -19
  113. package/src/likec4diagram/useViewToNodesEdges.ts +1 -0
  114. package/src/overlays/element-details/ElementDetailsCard.css.ts +0 -28
  115. package/src/overlays/element-details/ElementDetailsCard.tsx +2 -50
  116. package/src/overlays/element-details/TabPanelRelationships.tsx +2 -2
  117. package/src/overlays/relationship-details/RelationshipDetails.tsx +4 -4
  118. package/src/overlays/relationship-details/custom/ElementActions.tsx +1 -2
  119. package/src/overlays/relationship-details/custom/edgeTypes.tsx +0 -5
  120. package/src/overlays/relationship-details/hooks.ts +6 -6
  121. package/src/overlays/relationship-details/useLayoutedDetails.ts +7 -10
  122. package/src/overlays/relationships-browser/-useRelationshipsView.ts +16 -12
  123. package/src/overlays/relationships-browser/RelationshipsBrowser.tsx +105 -68
  124. package/src/overlays/relationships-browser/_types.ts +2 -1
  125. package/src/overlays/relationships-browser/actor.ts +321 -62
  126. package/src/overlays/relationships-browser/const.ts +1 -0
  127. package/src/overlays/relationships-browser/custom/ElementActions.tsx +13 -3
  128. package/src/overlays/relationships-browser/custom/edgeTypes.tsx +25 -6
  129. package/src/overlays/relationships-browser/custom/nodeTypes.tsx +3 -2
  130. package/src/overlays/relationships-browser/hooks.ts +3 -1
  131. package/src/overlays/relationships-browser/useViewToNodesEdges.ts +8 -2
  132. package/dist/likec4diagram/ui/diagram-title/Link.js +0 -36
  133. package/dist/ui/Link.d.ts +0 -4
  134. package/src/ui/Link.tsx +0 -40
@@ -2,15 +2,17 @@ import type { Fqn } from '@likec4/core'
2
2
  import { ActionIcon, Box, Group } from '@mantine/core'
3
3
  import { useCallbackRef, useStateHistory } from '@mantine/hooks'
4
4
  import { IconChevronLeft, IconChevronRight, IconX } from '@tabler/icons-react'
5
- import { Panel, ReactFlowProvider } from '@xyflow/react'
5
+ import { Panel, ReactFlowProvider, useStoreApi } from '@xyflow/react'
6
6
  import clsx from 'clsx'
7
+ import { shallowEqual } from 'fast-equals'
7
8
  import { AnimatePresence, LayoutGroup, m } from 'framer-motion'
8
9
  import { memo, useEffect, useRef } from 'react'
9
10
  import type { SnapshotFrom } from 'xstate'
10
11
  import { BaseXYFlow } from '../../base/BaseXYFlow'
11
12
  import { useRelationshipsView } from './-useRelationshipsView'
12
- import type { RelationshipsBrowserTypes as Types } from './_types'
13
+ import type { RelationshipsBrowserTypes, RelationshipsBrowserTypes as Types } from './_types'
13
14
  import type { RelationshipsBrowserActorRef } from './actor'
15
+ import { ViewPadding } from './const'
14
16
  import { edgeTypes } from './custom/edgeTypes'
15
17
  import { nodeTypes } from './custom/nodeTypes'
16
18
  import {
@@ -29,69 +31,56 @@ export function RelationshipsBrowser({ actorRef }: RelationshipsBrowserProps) {
29
31
  // return null
30
32
  // }
31
33
  const initialRef = useRef<{
32
- defaultNodes: Types.Node[]
33
- defaultEdges: Types.Edge[]
34
+ initialNodes: Types.Node[]
35
+ initialEdges: Types.Edge[]
34
36
  }>(null)
35
37
 
36
38
  if (initialRef.current == null) {
37
39
  initialRef.current = {
38
- defaultNodes: [],
39
- defaultEdges: [],
40
+ initialNodes: [],
41
+ initialEdges: [],
40
42
  }
41
43
  }
42
44
 
43
45
  return (
44
46
  <RelationshipsBrowserActorContext.Provider value={actorRef}>
45
47
  <ReactFlowProvider {...initialRef.current}>
46
- <RelationshipsBrowserInner />
48
+ <RelationshipsBrowserXYFlow />
47
49
  </ReactFlowProvider>
48
50
  </RelationshipsBrowserActorContext.Provider>
49
51
  )
50
52
  }
51
53
 
52
54
  const selector = (state: SnapshotFrom<RelationshipsBrowserActorRef>) => ({
53
- subjectId: state.context.subject,
54
55
  initialized: state.context.initialized,
55
- scope: state.context.scope,
56
+ isActive: state.hasTag('active'),
56
57
  nodes: state.context.xynodes,
57
58
  edges: state.context.xyedges,
58
- closeable: state.context.closeable,
59
- enableNavigationMenu: state.context.enableNavigationMenu,
60
59
  })
60
+ const selectorEq = (a: ReturnType<typeof selector>, b: ReturnType<typeof selector>) =>
61
+ a.initialized === b.initialized &&
62
+ a.isActive === b.isActive &&
63
+ shallowEqual(a.nodes, b.nodes) &&
64
+ shallowEqual(a.edges, b.edges)
61
65
 
62
- const RelationshipsBrowserInner = memo(() => {
66
+ const RelationshipsBrowserXYFlow = memo(() => {
67
+ const xystore = useStoreApi<RelationshipsBrowserTypes.Node, RelationshipsBrowserTypes.Edge>()
63
68
  const browser = useRelationshipsBrowser()
64
69
  const {
65
- subjectId,
66
70
  initialized,
67
- scope,
71
+ isActive,
68
72
  nodes,
69
73
  edges,
70
- closeable,
71
- enableNavigationMenu,
72
- } = useRelationshipsBrowserState(selector)
73
-
74
- const layouted = useRelationshipsView(subjectId)
75
- const [historySubjectId, historyOps, { history, current }] = useStateHistory(subjectId)
76
-
77
- useEffect(() => {
78
- if (historySubjectId !== subjectId) {
79
- historyOps.set(subjectId)
80
- }
81
- }, [subjectId])
82
-
83
- useEffect(() => {
84
- if (historySubjectId !== subjectId) {
85
- browser.navigateTo(historySubjectId)
86
- }
87
- }, [historySubjectId])
74
+ } = useRelationshipsBrowserState(
75
+ selector,
76
+ selectorEq,
77
+ )
88
78
 
89
- useEffect(() => {
90
- browser.send({ type: 'update.view', layouted })
91
- }, [layouted])
92
-
93
- const hasStepBack = current > 0
94
- const hasStepForward = current + 1 < history.length
79
+ // useLifecycleLogger('RelationshipsBrowserXYFlow.browser', [browser])
80
+ // useLifecycleLogger('RelationshipsBrowserXYFlow.xystore', [xystore])
81
+ // useLifecycleLogger('RelationshipsBrowserXYFlow.initialized, isActive', [initialized, isActive])
82
+ // useLifecycleLogger('RelationshipsBrowserXYFlow.nodes', [nodes])
83
+ // useLifecycleLogger('RelationshipsBrowserXYFlow.edges', [edges])
95
84
 
96
85
  return (
97
86
  <LayoutGroup>
@@ -99,12 +88,12 @@ const RelationshipsBrowserInner = memo(() => {
99
88
  id="relationships-browser"
100
89
  nodes={nodes}
101
90
  edges={edges}
102
- className={clsx(initialized ? 'initialized' : 'not-initialized')}
91
+ className={clsx(initialized && isActive ? 'initialized' : 'not-initialized')}
103
92
  nodeTypes={nodeTypes}
104
93
  edgeTypes={edgeTypes}
105
- fitViewPadding={0.05}
94
+ fitViewPadding={ViewPadding}
106
95
  onInit={useCallbackRef((instance) => {
107
- browser.send({ type: 'xyflow.init', instance })
96
+ browser.send({ type: 'xyflow.init', instance, store: xystore })
108
97
  })}
109
98
  onNodeClick={useCallbackRef((e, node) => {
110
99
  e.stopPropagation()
@@ -122,9 +111,9 @@ const RelationshipsBrowserInner = memo(() => {
122
111
  e.stopPropagation()
123
112
  browser.send({ type: 'xyflow.paneDblClick' })
124
113
  })}
125
- onViewportResize={() => {
114
+ onViewportResize={useCallbackRef(() => {
126
115
  browser.send({ type: 'xyflow.resized' })
127
- }}
116
+ })}
128
117
  onNodesChange={useCallbackRef((changes) => {
129
118
  browser.send({ type: 'xyflow.applyNodeChages', changes })
130
119
  })}
@@ -136,36 +125,84 @@ const RelationshipsBrowserInner = memo(() => {
136
125
  pannable
137
126
  zoomable
138
127
  >
139
- <TopLeftPanel
140
- enableNavigationMenu={enableNavigationMenu}
141
- subjectId={subjectId}
142
- hasStepBack={hasStepBack}
143
- hasStepForward={hasStepForward}
144
- onStepBack={() => historyOps.back()}
145
- onStepForward={() => historyOps.forward()}
146
- />
147
- {closeable && (
148
- <Panel position="top-right">
149
- <ActionIcon
150
- variant="default"
151
- color="gray"
152
- // color="gray"
153
- // size={'lg'}
154
- // data-autofocus
155
- // autoFocus
156
- onClick={(e) => {
157
- e.stopPropagation()
158
- browser.close()
159
- }}>
160
- <IconX />
161
- </ActionIcon>
162
- </Panel>
163
- )}
128
+ {initialized && <RelationshipsBrowserInner />}
164
129
  </BaseXYFlow>
165
130
  </LayoutGroup>
166
131
  )
167
132
  })
168
133
 
134
+ const selector2 = (state: SnapshotFrom<RelationshipsBrowserActorRef>) => ({
135
+ subjectId: state.context.subject,
136
+ closeable: state.context.closeable,
137
+ enableNavigationMenu: state.context.enableNavigationMenu,
138
+ })
139
+
140
+ const RelationshipsBrowserInner = memo(() => {
141
+ const browser = useRelationshipsBrowser()
142
+ const {
143
+ subjectId,
144
+ closeable,
145
+ enableNavigationMenu,
146
+ } = useRelationshipsBrowserState(selector2)
147
+
148
+ const layouted = useRelationshipsView(subjectId)
149
+ const [historySubjectId, historyOps, { history, current }] = useStateHistory(subjectId)
150
+
151
+ useEffect(() => {
152
+ if (historySubjectId !== subjectId) {
153
+ historyOps.set(subjectId)
154
+ }
155
+ }, [subjectId])
156
+
157
+ useEffect(() => {
158
+ if (historySubjectId !== subjectId) {
159
+ browser.navigateTo(historySubjectId)
160
+ }
161
+ }, [historySubjectId])
162
+
163
+ useEffect(() => {
164
+ browser.send({ type: 'update.view', layouted })
165
+ }, [layouted])
166
+
167
+ const hasStepBack = current > 0
168
+ const hasStepForward = current + 1 < history.length
169
+
170
+ // useLifecycleLogger('RelationshipsBrowserInner.browser', [browser])
171
+ // useLifecycleLogger('RelationshipsBrowserInner.layouted', [layouted])
172
+ // useLifecycleLogger('RelationshipsBrowserInner', [
173
+ // historySubjectId,
174
+ // subjectId,
175
+ // closeable,
176
+ // enableNavigationMenu,
177
+ // ])
178
+
179
+ return (
180
+ <>
181
+ <TopLeftPanel
182
+ enableNavigationMenu={enableNavigationMenu}
183
+ subjectId={subjectId}
184
+ hasStepBack={hasStepBack}
185
+ hasStepForward={hasStepForward}
186
+ onStepBack={() => historyOps.back()}
187
+ onStepForward={() => historyOps.forward()}
188
+ />
189
+ {closeable && (
190
+ <Panel position="top-right">
191
+ <ActionIcon
192
+ variant="default"
193
+ color="gray"
194
+ onClick={(e) => {
195
+ e.stopPropagation()
196
+ browser.close()
197
+ }}>
198
+ <IconX />
199
+ </ActionIcon>
200
+ </Panel>
201
+ )}
202
+ </>
203
+ )
204
+ })
205
+
169
206
  type TopLeftPanelProps = {
170
207
  enableNavigationMenu: boolean
171
208
  subjectId: Fqn
@@ -1,4 +1,4 @@
1
- import type { Color, DiagramNode, Fqn, RelationshipLineType, ViewId } from '@likec4/core'
1
+ import type { Color, DiagramNode, Fqn, NonEmptyArray, RelationId, RelationshipLineType, ViewId } from '@likec4/core'
2
2
  import type { Base, NonOptional, ReactFlowEdge, ReactFlowNode } from '../../base/types'
3
3
 
4
4
  export namespace RelationshipsBrowserTypes {
@@ -79,6 +79,7 @@ export namespace RelationshipsBrowserTypes {
79
79
  // Extend the edge types provided by SharedFlowTypes with RelationshipsOfEdgeData
80
80
 
81
81
  export type EdgeData = Base.EdgeData<{
82
+ relations: NonEmptyArray<RelationId>
82
83
  color: Color | undefined
83
84
  label: string | null
84
85
  navigateTo: ViewId | null