feat: ant path rendering on cahnges

This commit is contained in:
2026-03-11 22:08:08 +01:00
parent ea6bdeb05f
commit 1232d148e6
11 changed files with 322 additions and 34 deletions

View File

@@ -79,6 +79,8 @@ function CompactNodeView({ id, type, selected, width, height }: NodeProps) {
/**
* Wraps a node component so that when the viewport zoom is at or below
* CONTEXTUAL_ZOOM_THRESHOLD, the node renders as a compact icon-only view.
* Inner is always mounted (hidden when compact) so switching zoom does not
* remount and re-trigger effects (e.g. RenderingNode fetch).
*/
export function createContextualNode<P extends NodeProps>(
Inner: React.ComponentType<P>
@@ -86,22 +88,35 @@ export function createContextualNode<P extends NodeProps>(
function ContextualZoomNode(props: P) {
const { zoom } = useViewport()
const showCompact = zoom <= CONTEXTUAL_ZOOM_THRESHOLD
const p = props as NodeProps
const type = p.type
const defaultStyle = type ? getDefaultStyle(type) : { width: 320, height: 320 }
const w = p.width ?? defaultStyle.width
const h = p.height ?? defaultStyle.height
if (showCompact) {
const p = props as NodeProps
return (
<CompactNodeView
id={p.id}
type={p.type}
data={p.data}
selected={p.selected}
width={p.width}
height={p.height}
/>
)
}
return <Inner {...props} />
return (
<div
style={
showCompact
? { width: w, height: h, minWidth: w, minHeight: h, position: 'relative' }
: { display: 'contents' }
}
>
{showCompact && (
<CompactNodeView
id={p.id}
type={type}
data={p.data}
selected={p.selected}
width={p.width}
height={p.height}
/>
)}
<div style={{ display: showCompact ? 'none' : undefined }} aria-hidden={showCompact}>
<Inner {...props} />
</div>
</div>
)
}
ContextualZoomNode.displayName = `ContextualZoom(${Inner.displayName ?? Inner.name ?? 'Node'})`