diff --git a/src/main/frontend/app/routes/studio/canvas/nodetypes/exit-node.tsx b/src/main/frontend/app/routes/studio/canvas/nodetypes/exit-node.tsx index 330c76a7..a29de2e2 100644 --- a/src/main/frontend/app/routes/studio/canvas/nodetypes/exit-node.tsx +++ b/src/main/frontend/app/routes/studio/canvas/nodetypes/exit-node.tsx @@ -1,7 +1,8 @@ -import { Handle, type Node, type NodeProps, NodeResizeControl, Position } from '@xyflow/react' +import { Handle, type Node, type NodeProps, NodeResizeControl, Position, useStore } from '@xyflow/react' import { ResizeIcon } from '~/routes/studio/canvas/nodetypes/frank-node' import { FlowConfig } from '~/routes/studio/canvas/flow.config' import { useSettingsStore } from '~/stores/settings-store' +import ZoomedOutNode from './zoomed-out-node' export type ExitNode = Node<{ subtype: string @@ -14,6 +15,20 @@ export default function ExitNodeComponent(properties: NodeProps) { const minNodeWidth = FlowConfig.EXIT_DEFAULT_WIDTH const minNodeHeight = FlowConfig.EXIT_DEFAULT_HEIGHT const gradientEnabled = useSettingsStore((state) => state.studio.gradient) + const zoom = useStore((state) => state.transform[2]) + const isCompact = zoom < 0.4 + + if (isCompact) { + return ( + + ) + } return ( <> diff --git a/src/main/frontend/app/routes/studio/canvas/nodetypes/frank-node.tsx b/src/main/frontend/app/routes/studio/canvas/nodetypes/frank-node.tsx index 7cdc76c9..9faece23 100644 --- a/src/main/frontend/app/routes/studio/canvas/nodetypes/frank-node.tsx +++ b/src/main/frontend/app/routes/studio/canvas/nodetypes/frank-node.tsx @@ -36,6 +36,7 @@ import { parseXsd, } from '~/utils/xsd-utils' import MissingRequirements from './components/missing-requirements' +import ZoomedOutNode from './zoomed-out-node' export type FrankNodeType = Node<{ subtype: string @@ -117,17 +118,6 @@ export default function FrankNode(properties: NodeProps) { return (dimensions.height - (properties.data.sourceHandles.length - 1) * handleSpacing) / 2 }, [dimensions.height, properties.data.sourceHandles.length]) - const COMPACT_INITIALS_BOX_SIZE = 160 - const COMPACT_PADDING_TOP = 8 - const COMPACT_HANDLE_SIZE = 15 - const COMPACT_HANDLE_GAP = 4 - - const compactXOffsetPx = - (FlowConfig.NODE_DEFAULT_WIDTH - COMPACT_INITIALS_BOX_SIZE) / 2 - COMPACT_HANDLE_SIZE - COMPACT_HANDLE_GAP - - const compactHandleTop = - COMPACT_PADDING_TOP + COMPACT_INITIALS_BOX_SIZE / 2 - COMPACT_HANDLE_SIZE / 2 + COMPACT_HANDLE_SIZE - const allForwardTypesUsed = useMemo(() => { if (availableHandleTypes.length === 0) return true @@ -406,107 +396,16 @@ export default function FrankNode(properties: NodeProps) { }, [draggedName, canAcceptChild, frankElement]) if (isCompact) { - const abbr = - properties.data.subtype.replaceAll(/[a-z]/g, '').slice(0, 4) || properties.data.subtype.slice(0, 2).toUpperCase() - return ( - <> -
-
- - {abbr} - -
- - - {properties.data.subtype} - - - {properties.data.name && ( - {properties.data.name} - )} - {properties.data.attributes && - Object.entries(properties.data.attributes).map(([key, value]) => ( - - {value || key} - - ))} -
- - {properties.data.subtype !== 'Receiver' && ( - <> -
- - - )} - - {properties.data.sourceHandles.length > 0 && ( -
- )} - - {properties.data.sourceHandles.map((handle) => ( - - ))} - + ) } diff --git a/src/main/frontend/app/routes/studio/canvas/nodetypes/zoomed-out-node.tsx b/src/main/frontend/app/routes/studio/canvas/nodetypes/zoomed-out-node.tsx new file mode 100644 index 00000000..f8091642 --- /dev/null +++ b/src/main/frontend/app/routes/studio/canvas/nodetypes/zoomed-out-node.tsx @@ -0,0 +1,140 @@ +import { Handle, Position } from '@xyflow/react' +import { FlowConfig } from '~/routes/studio/canvas/flow.config' + +const COMPACT_INITIALS_BOX_SIZE = 160 +const COMPACT_PADDING_TOP = 8 +const COMPACT_HANDLE_SIZE = 15 +const COMPACT_HANDLE_GAP = 4 + +export interface ZoomedOutNodeProps { + subtype: string + name?: string + attributes?: Record + colorVariable: string + selected?: boolean + showTargetHandle?: boolean + sourceHandles?: { type: string; index: number }[] + width?: number +} + +function getAbbreviation(subtype: string): string { + return subtype.replaceAll(/[a-z]/g, '').slice(0, 4) || subtype.slice(0, 2).toUpperCase() +} + +/** + * Compact representation of a node shown when the canvas is zoomed out far enough that the full + * node would be unreadable. Renders an initials box with the subtype, name attributes and the + * handles aligned under it. + */ +export default function ZoomedOutNode({ + subtype, + name, + attributes, + colorVariable, + selected, + showTargetHandle = true, + sourceHandles = [], + width = FlowConfig.NODE_DEFAULT_WIDTH, +}: Readonly) { + const abbr = getAbbreviation(subtype) + + const compactXOffsetPx = (width - COMPACT_INITIALS_BOX_SIZE) / 2 - COMPACT_HANDLE_SIZE - COMPACT_HANDLE_GAP + const compactHandleTop = + COMPACT_PADDING_TOP + COMPACT_INITIALS_BOX_SIZE / 2 - COMPACT_HANDLE_SIZE / 2 + COMPACT_HANDLE_SIZE + + return ( + <> +
+
+ + {abbr} + +
+ + {subtype} + + {name && {name}} + {attributes && + Object.entries(attributes).map(([key, value]) => ( + + {value || key} + + ))} +
+ + {showTargetHandle && ( + <> +
+ + + )} + + {sourceHandles.length > 0 && ( +
+ )} + + {sourceHandles.map((handle) => ( + + ))} + + ) +}