@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.
- package/dist/LikeC4Diagram.css.d.ts +1 -0
- package/dist/LikeC4Diagram.css.js +3 -1
- package/dist/base/BaseXYFlow.js +15 -14
- package/dist/base/Link.css.d.ts +3 -0
- package/dist/base/Link.css.js +9 -0
- package/dist/base/Link.d.ts +5 -0
- package/dist/base/Link.js +58 -0
- package/dist/base/const.d.ts +1 -0
- package/dist/base/const.js +2 -1
- package/dist/base/example/custom.d.ts +1 -1
- package/dist/base/index.d.ts +1 -0
- package/dist/base/primitives/compound/CompoundActionButton.js +2 -1
- package/dist/base/primitives/compound/CompoundDetailsButton.js +2 -1
- package/dist/base/primitives/compound/CompoundNodeContainer.css.d.ts +0 -1
- package/dist/base/primitives/compound/CompoundNodeContainer.css.js +4 -6
- package/dist/base/primitives/compound/CompoundNodeContainer.js +2 -2
- package/dist/base/primitives/customEdge.d.ts +1 -1
- package/dist/base/primitives/customEdge.js +1 -1
- package/dist/base/primitives/customNode.js +1 -1
- package/dist/base/primitives/edge/EdgeLabel.js +3 -1
- package/dist/base/primitives/edge/EdgePath.d.ts +2 -1
- package/dist/base/primitives/edge/EdgePath.js +2 -0
- package/dist/base/primitives/element/ElementActionButtons.js +2 -1
- package/dist/base/primitives/element/ElementDetailsButton.js +2 -1
- package/dist/base/primitives/element/ElementNodeContainer.css.d.ts +0 -1
- package/dist/base/primitives/element/ElementNodeContainer.css.js +1 -3
- package/dist/base/primitives/element/ElementNodeContainer.js +2 -3
- package/dist/base/primitives/element/ElementShape.js +4 -2
- package/dist/base/primitives/element/ElementTitle.js +2 -1
- package/dist/base/updateEdges.js +3 -3
- package/dist/base/updateNodes.js +2 -2
- package/dist/context/FramerMotionConfig.js +1 -1
- package/dist/hooks/useDiagram.d.ts +313 -90
- package/dist/hooks/useDiagramActor.d.ts +2 -2
- package/dist/hooks/useDiagramContext.d.ts +1 -1
- package/dist/hooks/useXYFlow.d.ts +2 -1
- package/dist/hooks/useXYFlow.js +5 -0
- package/dist/likec4diagram/XYFlow.js +12 -10
- package/dist/likec4diagram/custom/edges/RelationshipEdge.d.ts +1 -1
- package/dist/likec4diagram/custom/edges/RelationshipsDropdownMenu.js +2 -2
- package/dist/likec4diagram/custom/index.d.ts +1 -1
- package/dist/likec4diagram/custom/nodes/nodeTypes.js +2 -2
- package/dist/likec4diagram/state/actorContext.d.ts +1438 -364
- package/dist/likec4diagram/state/assign.js +2 -2
- package/dist/likec4diagram/state/machine.d.ts +321 -93
- package/dist/likec4diagram/state/syncManualLayoutActor.d.ts +1 -1
- package/dist/likec4diagram/types.d.ts +1 -0
- package/dist/likec4diagram/ui/diagram-title/DiagramTitlePanel.js +4 -3
- package/dist/likec4diagram/useLayoutConstraints.d.ts +2 -1
- package/dist/likec4diagram/useLayoutConstraints.js +14 -15
- package/dist/likec4diagram/useViewToNodesEdges.js +3 -1
- package/dist/overlays/element-details/ElementDetailsCard.css.d.ts +0 -1
- package/dist/overlays/element-details/ElementDetailsCard.css.js +1 -3
- package/dist/overlays/element-details/ElementDetailsCard.js +5 -30
- package/dist/overlays/element-details/TabPanelRelationships.js +2 -2
- package/dist/overlays/relationship-details/RelationshipDetails.js +4 -4
- package/dist/overlays/relationship-details/custom/ElementActions.js +1 -3
- package/dist/overlays/relationship-details/custom/edgeTypes.d.ts +1 -1
- package/dist/overlays/relationship-details/hooks.d.ts +2 -2
- package/dist/overlays/relationship-details/hooks.js +7 -7
- package/dist/overlays/relationship-details/useLayoutedDetails.js +7 -10
- package/dist/overlays/relationships-browser/-useRelationshipsView.d.ts +4 -1
- package/dist/overlays/relationships-browser/-useRelationshipsView.js +12 -11
- package/dist/overlays/relationships-browser/RelationshipsBrowser.js +81 -66
- package/dist/overlays/relationships-browser/_types.d.ts +2 -1
- package/dist/overlays/relationships-browser/actor.d.ts +15 -2
- package/dist/overlays/relationships-browser/actor.js +262 -65
- package/dist/overlays/relationships-browser/const.d.ts +1 -0
- package/dist/overlays/relationships-browser/const.js +4 -0
- package/dist/overlays/relationships-browser/custom/ElementActions.js +13 -3
- package/dist/overlays/relationships-browser/custom/edgeTypes.d.ts +3 -2
- package/dist/overlays/relationships-browser/custom/edgeTypes.js +24 -6
- package/dist/overlays/relationships-browser/custom/nodeTypes.js +3 -2
- package/dist/overlays/relationships-browser/hooks.d.ts +6 -3
- package/dist/overlays/relationships-browser/hooks.js +4 -2
- package/dist/overlays/relationships-browser/useViewToNodesEdges.js +7 -2
- package/dist/style.css +1 -1
- package/dist/utils/xyflow.js +9 -1
- package/package.json +10 -10
- package/src/LikeC4Diagram.css.ts +8 -0
- package/src/base/BaseXYFlow.tsx +23 -14
- package/src/base/Link.css.ts +49 -0
- package/src/base/Link.tsx +66 -0
- package/src/base/const.ts +1 -0
- package/src/base/index.ts +2 -0
- package/src/base/primitives/compound/CompoundActionButton.tsx +2 -1
- package/src/base/primitives/compound/CompoundDetailsButton.tsx +2 -1
- package/src/base/primitives/compound/CompoundNodeContainer.css.ts +16 -10
- package/src/base/primitives/compound/CompoundNodeContainer.tsx +1 -1
- package/src/base/primitives/customEdge.ts +2 -0
- package/src/base/primitives/customNode.ts +3 -0
- package/src/base/primitives/edge/EdgeLabel.tsx +3 -1
- package/src/base/primitives/edge/EdgePath.tsx +3 -0
- package/src/base/primitives/element/ElementActionButtons.tsx +2 -1
- package/src/base/primitives/element/ElementDetailsButton.tsx +2 -1
- package/src/base/primitives/element/ElementNodeContainer.css.ts +9 -4
- package/src/base/primitives/element/ElementNodeContainer.tsx +1 -2
- package/src/base/primitives/element/ElementShape.tsx +4 -3
- package/src/base/primitives/element/ElementTitle.tsx +2 -1
- package/src/base/updateEdges.ts +3 -2
- package/src/base/updateNodes.ts +3 -2
- package/src/context/DiagramFeatures.tsx +1 -0
- package/src/context/FramerMotionConfig.tsx +1 -1
- package/src/hooks/useDiagramActor.ts +7 -5
- package/src/hooks/useDiagramContext.ts +4 -1
- package/src/hooks/useXYFlow.ts +6 -1
- package/src/likec4diagram/XYFlow.tsx +20 -9
- package/src/likec4diagram/custom/edges/RelationshipsDropdownMenu.tsx +2 -2
- package/src/likec4diagram/custom/nodes/nodeTypes.tsx +2 -2
- package/src/likec4diagram/types.ts +1 -0
- package/src/likec4diagram/ui/diagram-title/DiagramTitlePanel.tsx +4 -3
- package/src/likec4diagram/useLayoutConstraints.ts +23 -19
- package/src/likec4diagram/useViewToNodesEdges.ts +1 -0
- package/src/overlays/element-details/ElementDetailsCard.css.ts +0 -28
- package/src/overlays/element-details/ElementDetailsCard.tsx +2 -50
- package/src/overlays/element-details/TabPanelRelationships.tsx +2 -2
- package/src/overlays/relationship-details/RelationshipDetails.tsx +4 -4
- package/src/overlays/relationship-details/custom/ElementActions.tsx +1 -2
- package/src/overlays/relationship-details/custom/edgeTypes.tsx +0 -5
- package/src/overlays/relationship-details/hooks.ts +6 -6
- package/src/overlays/relationship-details/useLayoutedDetails.ts +7 -10
- package/src/overlays/relationships-browser/-useRelationshipsView.ts +16 -12
- package/src/overlays/relationships-browser/RelationshipsBrowser.tsx +105 -68
- package/src/overlays/relationships-browser/_types.ts +2 -1
- package/src/overlays/relationships-browser/actor.ts +321 -62
- package/src/overlays/relationships-browser/const.ts +1 -0
- package/src/overlays/relationships-browser/custom/ElementActions.tsx +13 -3
- package/src/overlays/relationships-browser/custom/edgeTypes.tsx +25 -6
- package/src/overlays/relationships-browser/custom/nodeTypes.tsx +3 -2
- package/src/overlays/relationships-browser/hooks.ts +3 -1
- package/src/overlays/relationships-browser/useViewToNodesEdges.ts +8 -2
- package/dist/likec4diagram/ui/diagram-title/Link.js +0 -36
- package/dist/ui/Link.d.ts +0 -4
- 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
|
-
|
|
33
|
-
|
|
34
|
+
initialNodes: Types.Node[]
|
|
35
|
+
initialEdges: Types.Edge[]
|
|
34
36
|
}>(null)
|
|
35
37
|
|
|
36
38
|
if (initialRef.current == null) {
|
|
37
39
|
initialRef.current = {
|
|
38
|
-
|
|
39
|
-
|
|
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
|
-
<
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
71
|
+
isActive,
|
|
68
72
|
nodes,
|
|
69
73
|
edges,
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
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={
|
|
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
|
-
<
|
|
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
|