@likec4/diagram 1.29.1 → 1.31.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/README.md +324 -5
- package/bundle/chunk-BBzMXzCg.js +21383 -0
- package/bundle/custom.js +62 -0
- package/bundle/index.js +17459 -38163
- package/dist/LikeC4CustomColors.js +2 -2
- package/dist/LikeC4Diagram.d.ts +1 -1
- package/dist/LikeC4Diagram.js +4 -2
- package/dist/LikeC4Diagram.props.d.ts +6 -1
- package/dist/LikeC4ModelProvider.d.ts +3 -3
- package/dist/LikeC4ModelProvider.js +0 -1
- package/dist/StaticLikeC4Diagram.d.ts +1 -1
- package/dist/base/BaseXYFlow.js +3 -3
- package/dist/base/primitives/compound/CompoundActionButton.d.ts +3 -2
- package/dist/base/primitives/compound/CompoundDetailsButton.d.ts +3 -2
- package/dist/base/primitives/compound/CompoundNodeContainer.d.ts +7 -3
- package/dist/base/primitives/compound/CompoundNodeContainer.js +3 -2
- package/dist/base/primitives/customEdge.d.ts +2 -35
- package/dist/base/primitives/customEdge.js +2 -2
- package/dist/base/primitives/customNode.d.ts +2 -2
- package/dist/base/primitives/customNode.js +9 -2
- package/dist/base/primitives/edge/EdgeContainer.js +0 -1
- package/dist/base/primitives/edge/EdgeLabel.js +0 -1
- package/dist/base/primitives/edge/EdgeLabelContainer.js +0 -2
- package/dist/base/primitives/edge/EdgePath.js +2 -2
- package/dist/base/primitives/element/ElementNodeContainer.d.ts +24 -22
- package/dist/base/primitives/element/ElementNodeContainer.js +66 -68
- package/dist/base/primitives/element/ElementShape.d.ts +8 -4
- package/dist/base/primitives/element/ElementShape.js +4 -3
- package/dist/base/primitives/element/ElementTitle.css.d.ts +1 -1
- package/dist/base/primitives/element/ElementTitle.js +0 -1
- package/dist/base/types.d.ts +5 -5
- package/dist/bundle/LikeC4View.js +6 -3
- package/dist/bundle/LikeC4View.props.d.ts +5 -1
- package/dist/bundle/ReactLikeC4.js +1 -2
- package/dist/bundle/ShadowRoot.js +3 -3
- package/dist/bundle/custom.d.ts +1 -0
- package/dist/bundle/index.d.ts +3 -1
- package/dist/bundle/index.js +9 -0
- package/dist/bundle/styles.css.js +5 -5
- package/dist/components/SearchControl.js +2 -2
- package/dist/context/ControlsCustomLayout.js +0 -1
- package/dist/context/DiagramEventHandlers.js +5 -5
- package/dist/context/DiagramFeatures.d.ts +2 -4
- package/dist/context/DiagramFeatures.js +15 -16
- package/dist/context/EnsureMantine.js +9 -4
- package/dist/context/FramerMotionConfig.js +0 -1
- package/dist/context/IconRenderer.js +7 -7
- package/dist/context/ReduceGraphics.js +6 -6
- package/dist/context/RootContainer.js +5 -5
- package/dist/context/index.d.ts +1 -1
- package/dist/custom/components.d.ts +5 -0
- package/dist/custom/customNodes.d.ts +218 -0
- package/dist/custom/hooks.d.ts +10 -0
- package/dist/custom/index.d.ts +4 -0
- package/dist/hooks/safeContext.js +3 -3
- package/dist/hooks/useCurrentViewId.d.ts +5 -1
- package/dist/hooks/useCurrentViewId.js +1 -2
- package/dist/hooks/useDiagram.d.ts +14 -12544
- package/dist/hooks/useDiagram.js +3 -5
- package/dist/hooks/useMantinePortalProps.js +2 -2
- package/dist/hooks/useSetState.js +3 -3
- package/dist/hooks/useUpdateEffect.js +0 -1
- package/dist/hooks/useXYFlow.d.ts +64 -64
- package/dist/hooks/useXYFlow.js +2 -2
- package/dist/index.d.ts +2 -4
- package/dist/index.js +8 -3
- package/dist/likec4diagram/DiagramUI.js +2 -2
- package/dist/likec4diagram/DiagramXYFlow.d.ts +1 -1
- package/dist/likec4diagram/DiagramXYFlow.js +25 -7
- package/dist/likec4diagram/custom/edges/NotePopover.js +2 -2
- package/dist/likec4diagram/custom/edges/RelationshipEdge.d.ts +9 -13
- package/dist/likec4diagram/custom/edges/RelationshipEdge.js +8 -8
- package/dist/likec4diagram/custom/edges/RelationshipsDropdownMenu.js +14 -12
- package/dist/likec4diagram/custom/index.d.ts +15 -19
- package/dist/likec4diagram/custom/index.js +3 -3
- package/dist/likec4diagram/custom/nodes/CompoundActions.js +2 -2
- package/dist/likec4diagram/custom/nodes/ElementActions.d.ts +27 -4
- package/dist/likec4diagram/custom/nodes/ElementActions.js +67 -53
- package/dist/likec4diagram/custom/nodes/index.d.ts +8 -0
- package/dist/likec4diagram/custom/nodes/nodes.d.ts +10 -0
- package/dist/likec4diagram/custom/nodes/{nodeTypes.js → nodes.js} +39 -39
- package/dist/likec4diagram/custom/nodes/toolbar/ColorButton.js +2 -2
- package/dist/likec4diagram/custom/nodes/toolbar/CompoundToolbar.js +6 -7
- package/dist/likec4diagram/custom/nodes/toolbar/ElementToolbar.js +3 -3
- package/dist/likec4diagram/custom/nodes/toolbar/Toolbar.d.ts +3 -2
- package/dist/likec4diagram/custom/nodes/toolbar/Toolbar.js +2 -2
- package/dist/likec4diagram/custom/nodes/toolbar/_shared.d.ts +2 -2
- package/dist/likec4diagram/custom/nodes/toolbar/_shared.js +2 -2
- package/dist/likec4diagram/types.d.ts +15 -7
- package/dist/likec4diagram/ui/controls/ChangeAutoLayoutButton.js +4 -4
- package/dist/likec4diagram/ui/controls/Controls.js +2 -2
- package/dist/likec4diagram/ui/diagram-title/DiagramTitlePanel.js +2 -2
- package/dist/likec4diagram/ui/notation/NotationPanel.js +6 -8
- package/dist/likec4diagram/ui/search/ElementsColumn.js +6 -7
- package/dist/likec4diagram/ui/search/LikeC4Search.js +3 -3
- package/dist/likec4diagram/ui/search/SearchInput.js +0 -1
- package/dist/likec4diagram/ui/search/_shared.css.d.ts +1 -1
- package/dist/likec4diagram/ui/search/state.js +3 -4
- package/dist/likec4diagram/ui/walkthrough/DynamicViewWalkthrough.js +4 -4
- package/dist/likec4diagram/useLayoutConstraints.js +3 -4
- package/dist/likec4diagram/useViewToNodesEdges.js +2 -0
- package/dist/likec4model/LikeC4ModelContext.d.ts +2 -2
- package/dist/likec4model/LikeC4ModelContext.js +2 -2
- package/dist/likec4model/useLikeC4ElementsTree.d.ts +1 -1
- package/dist/likec4model/useLikeC4ElementsTree.js +3 -3
- package/dist/likec4model/useLikeC4Model.d.ts +1 -1
- package/dist/likec4model/useLikeC4Model.js +2 -2
- package/dist/overlays/Overlays.d.ts +2 -3
- package/dist/overlays/Overlays.js +5 -6
- package/dist/overlays/element-details/ElementDetailsCard.css.js +13 -9
- package/dist/overlays/element-details/ElementDetailsCard.js +98 -105
- package/dist/overlays/element-details/TabPanelDeployments.js +4 -4
- package/dist/overlays/element-details/TabPanelRelationships.js +2 -2
- package/dist/overlays/element-details/TabPanelStructure.js +3 -3
- package/dist/overlays/element-details/actor.d.ts +6905 -19690
- package/dist/overlays/element-details/actor.js +0 -2
- package/dist/overlays/element-details/actorContext.js +3 -3
- package/dist/overlays/overlay/Overlay.d.ts +11 -1
- package/dist/overlays/overlay/Overlay.js +8 -8
- package/dist/overlays/overlaysActor.d.ts +4 -2
- package/dist/overlays/overlaysActor.js +2 -1
- package/dist/overlays/relationship-details/RelationshipDetails.d.ts +4 -8
- package/dist/overlays/relationship-details/RelationshipDetails.js +12 -12
- package/dist/overlays/relationship-details/SelectEdge.js +2 -3
- package/dist/overlays/relationship-details/_types.d.ts +6 -5
- package/dist/overlays/relationship-details/actor.d.ts +3 -3
- package/dist/overlays/relationship-details/compute.js +3 -3
- package/dist/overlays/relationship-details/custom/edgeTypes.d.ts +4 -8
- package/dist/overlays/relationship-details/custom/edgeTypes.js +2 -2
- package/dist/overlays/relationship-details/custom/nodeTypes.d.ts +3 -31
- package/dist/overlays/relationship-details/hooks.d.ts +27 -27
- package/dist/overlays/relationship-details/hooks.js +4 -4
- package/dist/overlays/relationship-details/layout.js +2 -3
- package/dist/overlays/relationships-browser/RelationshipsBrowser.d.ts +4 -8
- package/dist/overlays/relationships-browser/RelationshipsBrowser.js +8 -8
- package/dist/overlays/relationships-browser/SelectElement.js +5 -5
- package/dist/overlays/relationships-browser/_types.d.ts +6 -5
- package/dist/overlays/relationships-browser/actor.d.ts +63 -428
- package/dist/overlays/relationships-browser/custom/edgeTypes.d.ts +4 -8
- package/dist/overlays/relationships-browser/custom/edgeTypes.js +2 -2
- package/dist/overlays/relationships-browser/custom/nodeTypes.d.ts +10 -14
- package/dist/overlays/relationships-browser/custom/nodeTypes.js +1 -2
- package/dist/overlays/relationships-browser/hooks.d.ts +4 -61
- package/dist/overlays/relationships-browser/hooks.js +4 -4
- package/dist/overlays/relationships-browser/layout.js +3 -4
- package/dist/state/DiagramActorProvider.js +3 -3
- package/dist/state/diagram-machine.d.ts +186 -10369
- package/dist/state/diagram-machine.js +2 -1
- package/dist/state/hotkeyActor.d.ts +4 -2
- package/dist/state/syncManualLayoutActor.d.ts +14 -3
- package/dist/state/syncManualLayoutActor.js +2 -1
- package/dist/state/types.d.ts +5 -4
- package/dist/state/utils.d.ts +1 -1
- package/dist/styles-font.css +1 -0
- package/dist/styles-min.css +1 -0
- package/dist/styles-xyflow.css +1 -0
- package/dist/styles.css +1 -0
- package/dist/styles.css2.js +3 -0
- package/package.json +46 -21
- package/panda.buildinfo.json +979 -0
- package/src/LikeC4Diagram.props.ts +7 -1
- package/src/LikeC4Diagram.tsx +2 -0
- package/src/LikeC4ModelProvider.tsx +3 -3
- package/src/StaticLikeC4Diagram.tsx +1 -0
- package/src/base/Background.tsx +0 -4
- package/src/base/primitives/compound/CompoundActionButton.tsx +7 -4
- package/src/base/primitives/compound/CompoundDetailsButton.tsx +7 -4
- package/src/base/primitives/compound/CompoundNodeContainer.tsx +8 -7
- package/src/base/primitives/customEdge.ts +1 -1
- package/src/base/primitives/{customNode.ts → customNode.tsx} +11 -3
- package/src/base/primitives/element/ElementNodeContainer.tsx +87 -80
- package/src/base/primitives/element/ElementShape.tsx +11 -10
- package/src/base/types.ts +28 -33
- package/src/bundle/LikeC4View.props.ts +6 -1
- package/src/bundle/LikeC4View.tsx +3 -0
- package/src/bundle/ReactLikeC4.tsx +1 -1
- package/src/bundle/custom.ts +1 -0
- package/src/bundle/index.ts +20 -1
- package/src/bundle/styles.css.ts +1 -1
- package/src/components/SearchControl.tsx +1 -1
- package/src/context/DiagramFeatures.tsx +12 -8
- package/src/context/EnsureMantine.tsx +13 -3
- package/src/context/IconRenderer.tsx +4 -2
- package/src/context/ReduceGraphics.tsx +6 -6
- package/src/context/index.ts +0 -1
- package/src/custom/components.ts +47 -0
- package/src/custom/customNodes.tsx +244 -0
- package/src/custom/hooks.ts +35 -0
- package/src/custom/index.ts +5 -0
- package/src/hooks/useCurrentViewId.ts +9 -1
- package/src/hooks/useDiagram.ts +30 -9
- package/src/index.ts +4 -8
- package/src/likec4diagram/DiagramXYFlow.tsx +28 -5
- package/src/likec4diagram/custom/edges/RelationshipEdge.tsx +1 -1
- package/src/likec4diagram/custom/edges/RelationshipsDropdownMenu.tsx +9 -7
- package/src/likec4diagram/custom/{index.tsx → index.ts} +2 -2
- package/src/likec4diagram/custom/nodes/CompoundActions.tsx +2 -2
- package/src/likec4diagram/custom/nodes/ElementActions.tsx +100 -57
- package/src/likec4diagram/custom/nodes/index.ts +17 -0
- package/src/likec4diagram/custom/nodes/{nodeTypes.tsx → nodes.tsx} +52 -36
- package/src/likec4diagram/custom/nodes/toolbar/CompoundToolbar.tsx +3 -4
- package/src/likec4diagram/custom/nodes/toolbar/ElementToolbar.tsx +3 -3
- package/src/likec4diagram/custom/nodes/toolbar/Toolbar.tsx +5 -4
- package/src/likec4diagram/types.ts +19 -9
- package/src/likec4diagram/ui/diagram-title/DiagramTitlePanel.tsx +1 -1
- package/src/likec4diagram/ui/notation/NotationPanel.tsx +1 -2
- package/src/likec4diagram/ui/search/ElementsColumn.tsx +2 -4
- package/src/likec4diagram/ui/walkthrough/DynamicViewWalkthrough.tsx +1 -1
- package/src/likec4diagram/useViewToNodesEdges.ts +2 -0
- package/src/likec4model/LikeC4ModelContext.ts +2 -2
- package/src/likec4model/useLikeC4ElementsTree.ts +3 -1
- package/src/likec4model/useLikeC4Model.ts +1 -1
- package/src/overlays/Overlays.tsx +2 -3
- package/src/overlays/element-details/ElementDetailsCard.css.ts +14 -22
- package/src/overlays/element-details/ElementDetailsCard.tsx +18 -16
- package/src/overlays/overlay/Overlay.tsx +3 -4
- package/src/overlays/overlaysActor.ts +4 -3
- package/src/overlays/relationship-details/RelationshipDetails.tsx +1 -1
- package/src/overlays/relationship-details/SelectEdge.tsx +0 -2
- package/src/overlays/relationship-details/_types.ts +16 -13
- package/src/overlays/relationship-details/custom/edgeTypes.tsx +2 -2
- package/src/overlays/relationships-browser/_types.ts +18 -15
- package/src/overlays/relationships-browser/actor.ts +2 -2
- package/src/overlays/relationships-browser/custom/edgeTypes.tsx +2 -2
- package/src/overlays/relationships-browser/custom/nodeTypes.tsx +1 -2
- package/src/state/DiagramActorProvider.tsx +2 -2
- package/src/state/diagram-machine.ts +13 -8
- package/src/state/hotkeyActor.ts +4 -2
- package/src/state/syncManualLayoutActor.ts +9 -3
- package/src/state/types.ts +9 -3
- package/src/state/utils.ts +3 -3
- package/src/styles-min.css +2 -0
- package/src/styles-xyflow.css +1 -0
- package/dist/_virtual/_commonjsHelpers.js +0 -5
- package/dist/_virtual/default-map.js +0 -7
- package/dist/_virtual/index.js +0 -5
- package/dist/_virtual/index2.js +0 -3
- package/dist/_virtual/react.production.js +0 -3
- package/dist/_virtual/set.js +0 -5
- package/dist/_virtual/set2.js +0 -3
- package/dist/base/xyflowMachine.d.ts +0 -212
- package/dist/likec4diagram/custom/nodes/nodeTypes.d.ts +0 -8
- package/dist/node_modules/.pnpm/mnemonist@0.40.3_patch_hash_5c12abb43fcff6fd81e53021b89075d53249640d165a2556cc1e58d71201a13a/node_modules/mnemonist/default-map.js +0 -172
- package/dist/node_modules/.pnpm/mnemonist@0.40.3_patch_hash_5c12abb43fcff6fd81e53021b89075d53249640d165a2556cc1e58d71201a13a/node_modules/mnemonist/set.js +0 -369
- package/dist/node_modules/.pnpm/react@19.1.0/node_modules/react/cjs/react.production.js +0 -556
- package/dist/node_modules/.pnpm/react@19.1.0/node_modules/react/index.js +0 -15
- package/dist/packages/core/src/compute-view/relationships-view/compute.js +0 -123
- package/dist/packages/core/src/compute-view/relationships-view/utils.js +0 -68
- package/dist/packages/core/src/errors/index.js +0 -15
- package/dist/packages/core/src/model/connection/model/ConnectionModel.js +0 -121
- package/dist/packages/core/src/model/connection/model/find.js +0 -39
- package/dist/packages/core/src/model/connection/ops.js +0 -7
- package/dist/packages/core/src/utils/const.js +0 -3
- package/dist/packages/core/src/utils/fqn.js +0 -51
- package/dist/packages/core/src/utils/guards.js +0 -7
- package/dist/packages/core/src/utils/iterable/filter.js +0 -21
- package/dist/packages/core/src/utils/iterable/find.js +0 -21
- package/dist/packages/core/src/utils/iterable/map.js +0 -18
- package/dist/packages/core/src/utils/iterable/some.js +0 -21
- package/dist/packages/core/src/utils/iterable/to.js +0 -14
- package/dist/packages/core/src/utils/set.js +0 -48
- package/dist/packages/core/src/utils/string-hash.js +0 -13
- package/dist/styles.css.js +0 -3
- package/src/base/xyflowMachine.ts +0 -75
- /package/dist/{bundle/font.css.js → styles-font.css2.js} +0 -0
- /package/src/{bundle/font.css → styles-font.css} +0 -0
|
@@ -123,12 +123,6 @@ DiagramFeatures.Overlays = ({ children }: PropsWithChildren) => {
|
|
|
123
123
|
)
|
|
124
124
|
}
|
|
125
125
|
|
|
126
|
-
export function useEnabledFeature<F extends NonEmptyArray<FeatureName>>(
|
|
127
|
-
...names: F
|
|
128
|
-
): { [P in `enable${F[number]}`]: boolean } {
|
|
129
|
-
return pick(useContext(DiagramFeaturesContext), map(names, (name) => `enable${name}` as const))
|
|
130
|
-
}
|
|
131
|
-
|
|
132
126
|
export function useEnabledFeatures(): EnabledFeatures {
|
|
133
127
|
return useContext(DiagramFeaturesContext)
|
|
134
128
|
}
|
|
@@ -138,7 +132,7 @@ export function IfEnabled({
|
|
|
138
132
|
children,
|
|
139
133
|
and = true,
|
|
140
134
|
}: PropsWithChildren<{ feature: FeatureName; and?: boolean }>) {
|
|
141
|
-
const enabled =
|
|
135
|
+
const enabled = useEnabledFeatures()[`enable${feature}`] === true
|
|
142
136
|
return enabled && and ? <>{children}</> : null
|
|
143
137
|
}
|
|
144
138
|
|
|
@@ -146,6 +140,16 @@ export function IfNotEnabled({
|
|
|
146
140
|
feature,
|
|
147
141
|
children,
|
|
148
142
|
}: PropsWithChildren<{ feature: FeatureName }>) {
|
|
149
|
-
const notEnabled =
|
|
143
|
+
const notEnabled = useEnabledFeatures()[`enable${feature}`] !== true
|
|
150
144
|
return notEnabled ? <>{children}</> : null
|
|
151
145
|
}
|
|
146
|
+
|
|
147
|
+
export function IfNotReadOnly({
|
|
148
|
+
children,
|
|
149
|
+
}: PropsWithChildren) {
|
|
150
|
+
const isReadOnly = useEnabledFeatures()[`enableReadOnly`] === true
|
|
151
|
+
if (isReadOnly) {
|
|
152
|
+
return null
|
|
153
|
+
}
|
|
154
|
+
return <>{children}</>
|
|
155
|
+
}
|
|
@@ -1,13 +1,23 @@
|
|
|
1
|
-
import { MantineContext } from '@mantine/core'
|
|
2
|
-
import { type PropsWithChildren, useContext } from 'react'
|
|
1
|
+
import { MantineContext, MantineProvider } from '@mantine/core'
|
|
2
|
+
import { type PropsWithChildren, useContext, useEffect } from 'react'
|
|
3
3
|
|
|
4
4
|
type EnsureMantineProps = PropsWithChildren<{}>
|
|
5
5
|
|
|
6
6
|
export function EnsureMantine({ children }: EnsureMantineProps) {
|
|
7
7
|
const mantineCtx = useContext(MantineContext)
|
|
8
8
|
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
if (!mantineCtx) {
|
|
11
|
+
console.warn('LikeC4Diagram must be a child of MantineProvider')
|
|
12
|
+
}
|
|
13
|
+
}, [])
|
|
14
|
+
|
|
9
15
|
if (!mantineCtx) {
|
|
10
|
-
|
|
16
|
+
return (
|
|
17
|
+
<MantineProvider>
|
|
18
|
+
{children}
|
|
19
|
+
</MantineProvider>
|
|
20
|
+
)
|
|
11
21
|
}
|
|
12
22
|
|
|
13
23
|
return <>{children}</>
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ElementShape } from '@likec4/core'
|
|
2
|
+
import { cx as clsx } from '@likec4/styles/css'
|
|
2
3
|
import {
|
|
3
4
|
type Icon,
|
|
4
5
|
type IconProps,
|
|
@@ -9,7 +10,6 @@ import {
|
|
|
9
10
|
IconReorder,
|
|
10
11
|
IconUser,
|
|
11
12
|
} from '@tabler/icons-react'
|
|
12
|
-
import clsx from 'clsx'
|
|
13
13
|
import {
|
|
14
14
|
type ForwardRefExoticComponent,
|
|
15
15
|
type PropsWithChildren,
|
|
@@ -53,7 +53,9 @@ export function IconRenderer({
|
|
|
53
53
|
return null
|
|
54
54
|
}
|
|
55
55
|
let icon: ReactNode
|
|
56
|
-
if (
|
|
56
|
+
if (
|
|
57
|
+
element.icon.startsWith('http://') || element.icon.startsWith('https://')
|
|
58
|
+
) {
|
|
57
59
|
icon = <img src={element.icon} alt={element.title} />
|
|
58
60
|
} else if (RenderIcon) {
|
|
59
61
|
icon = <RenderIcon node={element} />
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createSafeContext } from '@mantine/core'
|
|
2
2
|
import { useStore } from '@nanostores/react'
|
|
3
3
|
import { type WritableAtom, atom } from 'nanostores'
|
|
4
|
-
import { type PropsWithChildren, useRef } from 'react'
|
|
4
|
+
import { type PropsWithChildren, createContext, useContext, useRef } from 'react'
|
|
5
5
|
|
|
6
|
-
const
|
|
6
|
+
const ReduceGraphicsModeCtx = createContext<boolean | null>(null)
|
|
7
7
|
/**
|
|
8
8
|
* Hook to determine if reduced graphics mode is enabled.
|
|
9
9
|
*/
|
|
10
10
|
export function useIsReducedGraphics() {
|
|
11
|
-
const isReduced =
|
|
11
|
+
const isReduced = useContext(ReduceGraphicsModeCtx)
|
|
12
12
|
if (isReduced === null) {
|
|
13
13
|
console.warn('ReduceGraphicsMode is not provided')
|
|
14
14
|
}
|
|
@@ -30,9 +30,9 @@ export function ReduceGraphicsContext({ reduceGraphics, children }: PropsWithChi
|
|
|
30
30
|
}
|
|
31
31
|
return (
|
|
32
32
|
<PanningAtomSafeCtx value={$isPanningRef.current}>
|
|
33
|
-
<ReduceGraphicsModeCtx value={reduceGraphics}>
|
|
33
|
+
<ReduceGraphicsModeCtx.Provider value={reduceGraphics}>
|
|
34
34
|
{children}
|
|
35
|
-
</ReduceGraphicsModeCtx>
|
|
35
|
+
</ReduceGraphicsModeCtx.Provider>
|
|
36
36
|
</PanningAtomSafeCtx>
|
|
37
37
|
)
|
|
38
38
|
}
|
package/src/context/index.ts
CHANGED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
export {
|
|
2
|
+
CompoundActionButton,
|
|
3
|
+
CompoundDetailsButton,
|
|
4
|
+
CompoundNodeContainer,
|
|
5
|
+
CompoundTitle,
|
|
6
|
+
DefaultHandles,
|
|
7
|
+
ElementActionButtons,
|
|
8
|
+
ElementDetailsButton,
|
|
9
|
+
ElementNodeContainer,
|
|
10
|
+
ElementShape,
|
|
11
|
+
ElementTitle,
|
|
12
|
+
} from '../base/primitives'
|
|
13
|
+
|
|
14
|
+
export {
|
|
15
|
+
IconOrShapeRenderer,
|
|
16
|
+
IconRenderer,
|
|
17
|
+
IconRendererProvider,
|
|
18
|
+
} from '../context/IconRenderer'
|
|
19
|
+
|
|
20
|
+
export {
|
|
21
|
+
CompoundActions,
|
|
22
|
+
CompoundDeploymentNode,
|
|
23
|
+
CompoundDeploymentToolbar,
|
|
24
|
+
CompoundDetailsButtonWithHandler,
|
|
25
|
+
CompoundElementNode,
|
|
26
|
+
CompoundElementToolbar,
|
|
27
|
+
DeploymentElementActions,
|
|
28
|
+
DeploymentElementToolbar,
|
|
29
|
+
DeploymentNode,
|
|
30
|
+
ElementActions,
|
|
31
|
+
ElementDetailsButtonWithHandler,
|
|
32
|
+
ElementNode,
|
|
33
|
+
ElementToolbar,
|
|
34
|
+
Toolbar,
|
|
35
|
+
ViewGroupNode,
|
|
36
|
+
} from '../likec4diagram/custom/nodes'
|
|
37
|
+
|
|
38
|
+
export {
|
|
39
|
+
IfEnabled,
|
|
40
|
+
IfNotEnabled,
|
|
41
|
+
IfNotReadOnly,
|
|
42
|
+
} from '../context/DiagramFeatures'
|
|
43
|
+
|
|
44
|
+
export {
|
|
45
|
+
Overlay,
|
|
46
|
+
type OverlayProps,
|
|
47
|
+
} from '../overlays/overlay/Overlay'
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import type { AnyAux, DeployedInstanceModel, DeploymentNodeModel, NodeModel } from '@likec4/core/model'
|
|
2
|
+
import type { DiagramView } from '@likec4/core/types'
|
|
3
|
+
import type { ReactNode } from 'react'
|
|
4
|
+
import { customNode } from '../base/primitives'
|
|
5
|
+
import type { NodeProps } from '../base/types'
|
|
6
|
+
import type { Types } from '../likec4diagram/types'
|
|
7
|
+
import { useLikeC4Model } from '../likec4model/useLikeC4Model'
|
|
8
|
+
|
|
9
|
+
function customDiagramNode<
|
|
10
|
+
P extends {
|
|
11
|
+
nodeProps: NodeProps<Types.NodeData>
|
|
12
|
+
nodeModel: NodeModel<AnyAux>
|
|
13
|
+
},
|
|
14
|
+
>(
|
|
15
|
+
Node: (props: P) => ReactNode,
|
|
16
|
+
): (props: P['nodeProps']) => ReactNode {
|
|
17
|
+
return customNode((props) => {
|
|
18
|
+
const viewModel = useLikeC4Model(true).view(props.data.viewId)
|
|
19
|
+
const model = viewModel.node(props.id)
|
|
20
|
+
// @ts-ignore
|
|
21
|
+
return <Node nodeProps={props} nodeModel={model} />
|
|
22
|
+
}) as (props: P['nodeProps']) => ReactNode
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export type CustomElementNodeProps<M extends AnyAux = AnyAux> = {
|
|
26
|
+
nodeProps: NodeProps<Types.ElementNodeData, 'element'>
|
|
27
|
+
nodeModel: NodeModel.WithElement<M, DiagramView>
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Node that will be used to render the element from the model.
|
|
31
|
+
* It is a leaf node, i.e. it does not have children.
|
|
32
|
+
*
|
|
33
|
+
* Custom node renderer receives these props:
|
|
34
|
+
* - `nodeProps`: props from XYFlow
|
|
35
|
+
* - `nodeModel`: LikeC4 {@link NodeModel.WithElement}
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```tsx
|
|
39
|
+
* import {
|
|
40
|
+
* elementNode,
|
|
41
|
+
* ElementNodeContainer,
|
|
42
|
+
* ElementShape,
|
|
43
|
+
* ElementTitle,
|
|
44
|
+
* ElementActions,
|
|
45
|
+
* ElementDetailsButtonWithHandler,
|
|
46
|
+
* IfNotReadOnly,
|
|
47
|
+
* ElementToolbar,
|
|
48
|
+
* DefaultHandles,
|
|
49
|
+
* } from '@likec4/diagram/custom'
|
|
50
|
+
*
|
|
51
|
+
* const CustomElementNode = elementNode(({ nodeProps, nodeModel }) => (
|
|
52
|
+
* <ElementNodeContainer nodeProps={nodeProps}>
|
|
53
|
+
* <ElementShape {...nodeProps} />
|
|
54
|
+
* <ElementTitle {...nodeProps} />
|
|
55
|
+
* <ElementActions
|
|
56
|
+
* {...nodeProps}
|
|
57
|
+
* extraButtons={[
|
|
58
|
+
* {
|
|
59
|
+
* key: 'plus',
|
|
60
|
+
* icon: <IconPlus />,
|
|
61
|
+
* onClick: () => console.log('extra'),
|
|
62
|
+
* },
|
|
63
|
+
* ]}
|
|
64
|
+
* />
|
|
65
|
+
* <ElementDetailsButtonWithHandler {...nodeProps} />
|
|
66
|
+
* {nodeModel.element.getMetadata('your-attr') === 'value' && <YourComponent />}
|
|
67
|
+
* <IfNotReadOnly>
|
|
68
|
+
* <ElementToolbar {...nodeProps} />
|
|
69
|
+
* </IfNotReadOnly>
|
|
70
|
+
* <DefaultHandles />
|
|
71
|
+
* </ElementNodeContainer>
|
|
72
|
+
* ))
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
export const elementNode = customDiagramNode<CustomElementNodeProps>
|
|
76
|
+
|
|
77
|
+
export type CustomDeploymentNodeProps<M extends AnyAux = AnyAux> = {
|
|
78
|
+
nodeProps: NodeProps<Types.DeploymentElementNodeData, 'deployment'>
|
|
79
|
+
nodeModel: NodeModel.WithDeploymentElement<M, DiagramView>
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Node that will be used to render the element from deployment model.
|
|
83
|
+
* It is a leaf node, i.e. it does not have children.
|
|
84
|
+
* Can be {@link DeploymentNodeModel} or {@link DeployedInstanceModel}.
|
|
85
|
+
*
|
|
86
|
+
* Custom node renderer receives these props:
|
|
87
|
+
* - `nodeProps`: props from XYFlow
|
|
88
|
+
* - `nodeModel`: {@link NodeModel.WithDeploymentElement}
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* ```tsx
|
|
92
|
+
* import {
|
|
93
|
+
* deploymentNode,
|
|
94
|
+
* ElementNodeContainer,
|
|
95
|
+
* ElementShape,
|
|
96
|
+
* ElementTitle,
|
|
97
|
+
* DeploymentElementActions,
|
|
98
|
+
* ElementDetailsButtonWithHandler,
|
|
99
|
+
* IfNotReadOnly,
|
|
100
|
+
* DeploymentElementToolbar,
|
|
101
|
+
* DefaultHandles,
|
|
102
|
+
* } from '@likec4/diagram/custom'
|
|
103
|
+
*
|
|
104
|
+
* const CustomDeploymentNode = deploymentNode(({ nodeProps, nodeModel }) => (
|
|
105
|
+
* <ElementNodeContainer nodeProps={nodeProps}>
|
|
106
|
+
* <ElementShape {...nodeProps} />
|
|
107
|
+
* <ElementTitle {...nodeProps} />
|
|
108
|
+
* <DeploymentElementActions
|
|
109
|
+
* {...nodeProps}
|
|
110
|
+
* extraButtons={[
|
|
111
|
+
* {
|
|
112
|
+
* key: 'plus',
|
|
113
|
+
* icon: <IconPlus />,
|
|
114
|
+
* onClick: () => console.log('extra'),
|
|
115
|
+
* },
|
|
116
|
+
* ]}
|
|
117
|
+
* />
|
|
118
|
+
* <ElementDetailsButtonWithHandler {...nodeProps} />
|
|
119
|
+
* <IfNotReadOnly>
|
|
120
|
+
* <DeploymentElementToolbar {...nodeProps} />
|
|
121
|
+
* </IfNotReadOnly>
|
|
122
|
+
* <DefaultHandles />
|
|
123
|
+
* </ElementNodeContainer>
|
|
124
|
+
* ))
|
|
125
|
+
* ```
|
|
126
|
+
*/
|
|
127
|
+
export const deploymentNode = customDiagramNode<CustomDeploymentNodeProps>
|
|
128
|
+
|
|
129
|
+
export type CustomCompoundElementNodeProps<M extends AnyAux = AnyAux> = {
|
|
130
|
+
nodeProps: NodeProps<Types.CompoundElementNodeData, 'compound-element'>
|
|
131
|
+
nodeModel: NodeModel.WithElement<M, DiagramView>
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Node that will be used to render the compound element from the model.
|
|
135
|
+
* It is a container node, i.e. it has children.
|
|
136
|
+
*
|
|
137
|
+
* Custom node renderer receives these props:
|
|
138
|
+
* - `nodeProps`: props from XYFlow
|
|
139
|
+
* - `nodeModel`: LikeC4 {@link NodeModel.WithElement}
|
|
140
|
+
*
|
|
141
|
+
* @example
|
|
142
|
+
* ```tsx
|
|
143
|
+
* import {
|
|
144
|
+
* compoundElementNode,
|
|
145
|
+
* CompoundNodeContainer,
|
|
146
|
+
* CompoundTitle,
|
|
147
|
+
* CompoundActions,
|
|
148
|
+
* CompoundDetailsButtonWithHandler,
|
|
149
|
+
* IfEnabled,
|
|
150
|
+
* CompoundElementToolbar,
|
|
151
|
+
* DefaultHandles,
|
|
152
|
+
* } from '@likec4/diagram/custom'
|
|
153
|
+
*
|
|
154
|
+
* const CustomCompoundElementNode = compoundElementNode(({ nodeProps, nodeModel }) => (
|
|
155
|
+
* <CompoundNodeContainer nodeProps={props}>
|
|
156
|
+
* <CompoundTitle {...props} />
|
|
157
|
+
* <CompoundActions {...props} />
|
|
158
|
+
* <IfEnabled feature="ElementDetails">
|
|
159
|
+
* <CompoundDetailsButtonWithHandler {...props} />
|
|
160
|
+
* </IfEnabled>
|
|
161
|
+
* <IfNotReadOnly>
|
|
162
|
+
* <CompoundElementToolbar {...props} />
|
|
163
|
+
* </IfNotReadOnly>
|
|
164
|
+
* <DefaultHandles />
|
|
165
|
+
* </CompoundNodeContainer>
|
|
166
|
+
* ))
|
|
167
|
+
* ```
|
|
168
|
+
*/
|
|
169
|
+
export const compoundElementNode = customDiagramNode<CustomCompoundElementNodeProps>
|
|
170
|
+
|
|
171
|
+
export type CustomCompoundDeploymentNodeProps<M extends AnyAux = AnyAux> = {
|
|
172
|
+
nodeProps: NodeProps<Types.CompoundDeploymentNodeData, 'compound-deployment'>
|
|
173
|
+
nodeModel: NodeModel.WithDeploymentElement<M, DiagramView>
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Node that will be used to render the compound from the deployment model.
|
|
177
|
+
* It is a container node, i.e. it has children.
|
|
178
|
+
*
|
|
179
|
+
* Custom node renderer receives these props:
|
|
180
|
+
* - `nodeProps`: props from XYFlow
|
|
181
|
+
* - `nodeModel`: LikeC4 {@link NodeModel.WithDeploymentElement}
|
|
182
|
+
*
|
|
183
|
+
* @example
|
|
184
|
+
* ```tsx
|
|
185
|
+
* import {
|
|
186
|
+
* compoundDeploymentNode,
|
|
187
|
+
* CompoundNodeContainer,
|
|
188
|
+
* CompoundTitle,
|
|
189
|
+
* CompoundActions,
|
|
190
|
+
* CompoundDeploymentToolbar,
|
|
191
|
+
* DefaultHandles,
|
|
192
|
+
* } from '@likec4/diagram/custom'
|
|
193
|
+
*
|
|
194
|
+
* const CustomCompoundDeploymentNode = compoundDeploymentNode(({ nodeProps, nodeModel }) => (
|
|
195
|
+
* <CompoundNodeContainer nodeProps={nodeProps}>
|
|
196
|
+
* <CompoundTitle {...nodeProps} />
|
|
197
|
+
* <CompoundActions {...nodeProps} />
|
|
198
|
+
* <IfNotReadOnly>
|
|
199
|
+
* <CompoundDeploymentToolbar {...nodeProps} />
|
|
200
|
+
* </IfNotReadOnly>
|
|
201
|
+
* <DefaultHandles />
|
|
202
|
+
* </CompoundNodeContainer>
|
|
203
|
+
* ```
|
|
204
|
+
*/
|
|
205
|
+
export const compoundDeploymentNode = customDiagramNode<CustomCompoundDeploymentNodeProps>
|
|
206
|
+
|
|
207
|
+
export type CustomViewGroupNodeProps<M extends AnyAux = AnyAux> = {
|
|
208
|
+
nodeProps: NodeProps<Types.ViewGroupNodeData, 'view-group'>
|
|
209
|
+
nodeModel: NodeModel.IsGroup<M, DiagramView>
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Node that will be used to render the view group from the model.
|
|
213
|
+
*
|
|
214
|
+
* Custom node renderer receives these props:
|
|
215
|
+
* - `nodeProps`: props from XYFlow
|
|
216
|
+
* - `nodeModel`: LikeC4 {@link NodeModel.IsGroup}
|
|
217
|
+
*
|
|
218
|
+
* @example
|
|
219
|
+
* ```tsx
|
|
220
|
+
* import {
|
|
221
|
+
* viewGroupNode,
|
|
222
|
+
* CompoundNodeContainer,
|
|
223
|
+
* CompoundTitle,
|
|
224
|
+
* DefaultHandles,
|
|
225
|
+
* } from '@likec4/diagram/custom'
|
|
226
|
+
*
|
|
227
|
+
* const CustomViewGroupNode = viewGroupNode(({ nodeProps, nodeModel }) => (
|
|
228
|
+
* <CompoundNodeContainer nodeProps={nodeProps}>
|
|
229
|
+
* <CompoundTitle {...nodeProps} />
|
|
230
|
+
* <DefaultHandles />
|
|
231
|
+
* </CompoundNodeContainer>
|
|
232
|
+
* ```
|
|
233
|
+
*/
|
|
234
|
+
export const viewGroupNode = customDiagramNode<CustomViewGroupNodeProps>
|
|
235
|
+
|
|
236
|
+
export interface CustomNodes {
|
|
237
|
+
element?: undefined | ((props: NodeProps<Types.ElementNodeData, 'element'>) => ReactNode)
|
|
238
|
+
deployment?: undefined | ((props: NodeProps<Types.DeploymentElementNodeData, 'deployment'>) => ReactNode)
|
|
239
|
+
compoundElement?: undefined | ((props: NodeProps<Types.CompoundElementNodeData, 'compound-element'>) => ReactNode)
|
|
240
|
+
compoundDeployment?:
|
|
241
|
+
| undefined
|
|
242
|
+
| ((props: NodeProps<Types.CompoundDeploymentNodeData, 'compound-deployment'>) => ReactNode)
|
|
243
|
+
viewGroup?: undefined | ((props: NodeProps<Types.ViewGroupNodeData, 'view-group'>) => ReactNode)
|
|
244
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export type {
|
|
2
|
+
DiagramActorEvent,
|
|
3
|
+
DiagramActorRef,
|
|
4
|
+
DiagramContext,
|
|
5
|
+
} from '../state/types'
|
|
6
|
+
|
|
7
|
+
export {
|
|
8
|
+
useDiagramEventHandlers,
|
|
9
|
+
} from '../context/DiagramEventHandlers'
|
|
10
|
+
|
|
11
|
+
export {
|
|
12
|
+
type EnabledFeatures,
|
|
13
|
+
useEnabledFeatures,
|
|
14
|
+
} from '../context/DiagramFeatures'
|
|
15
|
+
export {
|
|
16
|
+
useCurrentViewId,
|
|
17
|
+
} from '../hooks/useCurrentViewId'
|
|
18
|
+
export {
|
|
19
|
+
useDiagram,
|
|
20
|
+
useDiagramContext,
|
|
21
|
+
} from '../hooks/useDiagram'
|
|
22
|
+
export {
|
|
23
|
+
useXYFlow,
|
|
24
|
+
useXYInternalNode,
|
|
25
|
+
useXYStore,
|
|
26
|
+
useXYStoreApi,
|
|
27
|
+
} from '../hooks/useXYFlow'
|
|
28
|
+
|
|
29
|
+
export {
|
|
30
|
+
useLikeC4Model,
|
|
31
|
+
} from '../likec4model/useLikeC4Model'
|
|
32
|
+
|
|
33
|
+
export { useMantinePortalProps } from '../hooks/useMantinePortalProps'
|
|
34
|
+
export { useSetState } from '../hooks/useSetState'
|
|
35
|
+
export { useUpdateEffect } from '../hooks/useUpdateEffect'
|
|
@@ -1,9 +1,17 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { invariant } from '@likec4/core'
|
|
2
|
+
import type { AnyAux, LikeC4ViewModel } from '@likec4/core/model'
|
|
3
|
+
import type { DiagramView, ViewId } from '@likec4/core/types'
|
|
2
4
|
import { useSelector } from '@xstate/react'
|
|
5
|
+
import { useLikeC4Model } from '../likec4model/useLikeC4Model'
|
|
3
6
|
import type { DiagramActorSnapshot } from '../state/types'
|
|
4
7
|
import { useDiagramActorRef } from './useDiagram'
|
|
5
8
|
|
|
6
9
|
const selectViewId = (s: DiagramActorSnapshot) => s.context.view.id
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Returns current view id
|
|
13
|
+
* Should be used only inside LikeC4Diagram
|
|
14
|
+
*/
|
|
7
15
|
export function useCurrentViewId(): ViewId {
|
|
8
16
|
const actorRef = useDiagramActorRef()
|
|
9
17
|
return useSelector(actorRef, selectViewId)
|
package/src/hooks/useDiagram.ts
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
type DiagramEdge,
|
|
3
|
+
type DiagramNode,
|
|
4
|
+
type DiagramView,
|
|
5
|
+
type EdgeId,
|
|
6
|
+
type ElementNotation,
|
|
7
|
+
type Fqn,
|
|
8
|
+
type NodeId,
|
|
9
|
+
type ViewId,
|
|
10
|
+
} from '@likec4/core'
|
|
2
11
|
import { useCallbackRef } from '@mantine/hooks'
|
|
3
12
|
import { useSelector as useXstateSelector } from '@xstate/react'
|
|
4
13
|
import { shallowEqual } from 'fast-equals'
|
|
@@ -8,17 +17,27 @@ import type { FeatureName } from '../context/DiagramFeatures'
|
|
|
8
17
|
import type { OpenSourceParams } from '../LikeC4Diagram.props'
|
|
9
18
|
import type { Types } from '../likec4diagram/types'
|
|
10
19
|
import type { AlignmentMode } from '../state/aligners'
|
|
11
|
-
import type {
|
|
20
|
+
import type {
|
|
21
|
+
DiagramActorEvent,
|
|
22
|
+
DiagramActorSnapshot,
|
|
23
|
+
DiagramContext,
|
|
24
|
+
SyncLayoutActorRef,
|
|
25
|
+
SyncLayoutActorSnapshot,
|
|
26
|
+
} from '../state/types'
|
|
12
27
|
import { findDiagramEdge, findDiagramNode } from '../state/utils'
|
|
13
28
|
import { useDiagramActorRef } from './safeContext'
|
|
14
29
|
|
|
15
30
|
export { useDiagramActorRef }
|
|
16
31
|
|
|
32
|
+
/**
|
|
33
|
+
* Diagram API
|
|
34
|
+
* Mostly for internal use
|
|
35
|
+
*/
|
|
17
36
|
export function useDiagram() {
|
|
18
37
|
const actor = useDiagramActorRef()
|
|
19
38
|
return useMemo(() => ({
|
|
20
39
|
actor,
|
|
21
|
-
send: actor.send,
|
|
40
|
+
send: (event: DiagramActorEvent) => actor.send(event),
|
|
22
41
|
navigateTo: (viewId: ViewId, fromNode?: NodeId) => {
|
|
23
42
|
actor.send({
|
|
24
43
|
type: 'navigate.to',
|
|
@@ -52,11 +71,10 @@ export function useDiagram() {
|
|
|
52
71
|
updateNodeData: (nodeId: NodeId, data: PartialDeep<Types.NodeData>) => {
|
|
53
72
|
actor.send({ type: 'update.nodeData', nodeId, data })
|
|
54
73
|
},
|
|
55
|
-
updateEdgeData: (edgeId: EdgeId, data: PartialDeep<Types.
|
|
74
|
+
updateEdgeData: (edgeId: EdgeId, data: PartialDeep<Types.EdgeData>) => {
|
|
56
75
|
actor.send({
|
|
57
76
|
type: 'update.edgeData',
|
|
58
77
|
edgeId,
|
|
59
|
-
// @ts-expect-error TODO: fix this
|
|
60
78
|
data,
|
|
61
79
|
})
|
|
62
80
|
},
|
|
@@ -93,21 +111,21 @@ export function useDiagram() {
|
|
|
93
111
|
/**
|
|
94
112
|
* @warning Do not use in render phase
|
|
95
113
|
*/
|
|
96
|
-
getSnapshot: () => actor.getSnapshot(),
|
|
114
|
+
getSnapshot: (): DiagramActorSnapshot => actor.getSnapshot(),
|
|
97
115
|
/**
|
|
98
116
|
* @warning Do not use in render phase
|
|
99
117
|
*/
|
|
100
|
-
getContext: () => actor.getSnapshot().context,
|
|
118
|
+
getContext: (): DiagramContext => actor.getSnapshot().context,
|
|
101
119
|
/**
|
|
102
120
|
* @warning Do not use in render phase
|
|
103
121
|
*/
|
|
104
|
-
findDiagramNode: (xynodeId: string) => {
|
|
122
|
+
findDiagramNode: (xynodeId: string): DiagramNode | null => {
|
|
105
123
|
return findDiagramNode(actor.getSnapshot().context, xynodeId)
|
|
106
124
|
},
|
|
107
125
|
/**
|
|
108
126
|
* @warning Do not use in render phase
|
|
109
127
|
*/
|
|
110
|
-
findDiagramEdge: (xyedgeId: string) => {
|
|
128
|
+
findDiagramEdge: (xyedgeId: string): DiagramEdge | null => {
|
|
111
129
|
return findDiagramEdge(actor.getSnapshot().context, xyedgeId)
|
|
112
130
|
},
|
|
113
131
|
|
|
@@ -152,6 +170,9 @@ export function useDiagramSyncLayoutState<T = unknown>(
|
|
|
152
170
|
return useXstateSelector(syncLayoutActorRef, useCallbackRef(selector), compare)
|
|
153
171
|
}
|
|
154
172
|
|
|
173
|
+
/**
|
|
174
|
+
* Read diagram context
|
|
175
|
+
*/
|
|
155
176
|
export function useDiagramContext<T = unknown>(
|
|
156
177
|
selector: (context: DiagramContext) => T,
|
|
157
178
|
compare: (a: NoInfer<T>, b: NoInfer<T>) => boolean = shallowEqual,
|
package/src/index.ts
CHANGED
|
@@ -5,19 +5,13 @@ export { LikeC4Diagram } from './LikeC4Diagram'
|
|
|
5
5
|
export type { LikeC4DiagramProps } from './LikeC4Diagram'
|
|
6
6
|
export { Overlay } from './overlays/overlay/Overlay'
|
|
7
7
|
|
|
8
|
-
export {
|
|
9
|
-
useLikeC4ElementsTree,
|
|
10
|
-
useLikeC4Model,
|
|
11
|
-
} from './likec4model'
|
|
12
|
-
|
|
13
8
|
export { LikeC4ModelProvider } from './LikeC4ModelProvider'
|
|
14
9
|
|
|
15
|
-
export
|
|
16
|
-
export { useUpdateEffect } from './hooks/useUpdateEffect'
|
|
17
|
-
// export { vars, xyvars } from './theme-vars'
|
|
10
|
+
export * from './custom/hooks'
|
|
18
11
|
|
|
19
12
|
export type {
|
|
20
13
|
ChangeEvent,
|
|
14
|
+
CustomNodes,
|
|
21
15
|
DiagramNodeWithNavigate,
|
|
22
16
|
ElementIconRenderer,
|
|
23
17
|
LikeC4ColorScheme,
|
|
@@ -29,6 +23,8 @@ export type {
|
|
|
29
23
|
OnNavigateTo,
|
|
30
24
|
OnNodeClick,
|
|
31
25
|
OpenSourceParams,
|
|
26
|
+
PaddingUnit,
|
|
27
|
+
PaddingWithUnit,
|
|
32
28
|
WhereOperator,
|
|
33
29
|
} from './LikeC4Diagram.props'
|
|
34
30
|
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import { type EdgeId, type NodeId, nonNullable } from '@likec4/core'
|
|
2
2
|
import { cx } from '@likec4/styles/css'
|
|
3
3
|
import { useCallbackRef, useDebouncedCallback, useTimeout } from '@mantine/hooks'
|
|
4
|
+
import { useCustomCompareMemo } from '@react-hookz/web'
|
|
4
5
|
import type { OnMove, OnMoveEnd } from '@xyflow/system'
|
|
5
6
|
import { deepEqual, shallowEqual } from 'fast-equals'
|
|
6
7
|
import { type PropsWithChildren, memo } from 'react'
|
|
7
8
|
import { BaseXYFlow } from '../base/BaseXYFlow'
|
|
8
9
|
import { useDiagramEventHandlers } from '../context'
|
|
9
10
|
import { useIsReducedGraphics, usePanningAtom } from '../context/ReduceGraphics'
|
|
11
|
+
import { useUpdateEffect } from '../hooks'
|
|
10
12
|
import { useDiagram, useDiagramContext } from '../hooks/useDiagram'
|
|
11
13
|
import type { LikeC4DiagramProperties } from '../LikeC4Diagram.props'
|
|
12
14
|
import type { DiagramContext } from '../state/types'
|
|
13
|
-
import {
|
|
15
|
+
import { BuiltinNodes as defaultNodeTypes, edgeTypes } from './custom'
|
|
14
16
|
import { DiagramUI } from './DiagramUI'
|
|
15
17
|
import type { Types } from './types'
|
|
16
18
|
import { useLayoutConstraints } from './useLayoutConstraints'
|
|
@@ -50,14 +52,17 @@ export type LikeC4DiagramXYFlowProps = PropsWithChildren<
|
|
|
50
52
|
| 'nodesDraggable'
|
|
51
53
|
| 'nodesSelectable'
|
|
52
54
|
| 'reactFlowProps'
|
|
55
|
+
| 'renderNodes'
|
|
53
56
|
>
|
|
54
57
|
>
|
|
55
58
|
|
|
56
59
|
const compareProps = <T extends LikeC4DiagramXYFlowProps>(a: T, b: T): boolean =>
|
|
57
|
-
a.nodesDraggable
|
|
58
|
-
a.nodesSelectable
|
|
60
|
+
a.nodesDraggable == b.nodesDraggable &&
|
|
61
|
+
a.nodesSelectable == b.nodesSelectable &&
|
|
62
|
+
a.children == b.children &&
|
|
59
63
|
deepEqual(a.background, b.background) &&
|
|
60
|
-
deepEqual(a.reactFlowProps ?? {}, b.reactFlowProps ?? {})
|
|
64
|
+
deepEqual(a.reactFlowProps ?? {}, b.reactFlowProps ?? {}) &&
|
|
65
|
+
shallowEqual(a.renderNodes ?? {}, b.renderNodes ?? {})
|
|
61
66
|
|
|
62
67
|
export const LikeC4DiagramXYFlow = memo<LikeC4DiagramXYFlowProps>(({
|
|
63
68
|
background = 'dots',
|
|
@@ -65,6 +70,7 @@ export const LikeC4DiagramXYFlow = memo<LikeC4DiagramXYFlowProps>(({
|
|
|
65
70
|
nodesSelectable = false,
|
|
66
71
|
reactFlowProps = {},
|
|
67
72
|
children,
|
|
73
|
+
renderNodes,
|
|
68
74
|
}) => {
|
|
69
75
|
const diagram = useDiagram()
|
|
70
76
|
const {
|
|
@@ -116,7 +122,24 @@ export const LikeC4DiagramXYFlow = memo<LikeC4DiagramXYFlowProps>(({
|
|
|
116
122
|
}),
|
|
117
123
|
onViewportResize = useCallbackRef(() => {
|
|
118
124
|
diagram.send({ type: 'xyflow.resized' })
|
|
119
|
-
})
|
|
125
|
+
}),
|
|
126
|
+
nodeTypes = useCustomCompareMemo(
|
|
127
|
+
() => {
|
|
128
|
+
return {
|
|
129
|
+
element: renderNodes?.element ?? defaultNodeTypes.element,
|
|
130
|
+
deployment: renderNodes?.deployment ?? defaultNodeTypes.deployment,
|
|
131
|
+
'compound-element': renderNodes?.compoundElement ?? defaultNodeTypes['compound-element'],
|
|
132
|
+
'compound-deployment': renderNodes?.compoundDeployment ?? defaultNodeTypes['compound-deployment'],
|
|
133
|
+
'view-group': renderNodes?.viewGroup ?? defaultNodeTypes['view-group'],
|
|
134
|
+
} satisfies { [key in Types.Node['type']]: any }
|
|
135
|
+
},
|
|
136
|
+
[renderNodes],
|
|
137
|
+
shallowEqual,
|
|
138
|
+
)
|
|
139
|
+
|
|
140
|
+
useUpdateEffect(() => {
|
|
141
|
+
console.warn('renderNodes changed - this might degrade performance')
|
|
142
|
+
}, [renderNodes])
|
|
120
143
|
|
|
121
144
|
return (
|
|
122
145
|
<BaseXYFlow<Types.Node, Types.Edge>
|