mirror of
https://github.com/hanzoai/ui.git
synced 2026-11-21 13:51:19 +00:00
The workspace declared pkg/* and pkgs/* both, so one repo had two names for one concept and a package's home was a coin toss. The shared build tooling already lived in pkg/ui/scripts and pkgs reached back into it two levels up; now it is a sibling. hanzo.yml gates on pkg/ui, so the published library stays where CI already looks and the rest joins it. The publish glob follows: one root, one pattern, nothing invisible to it. Co-authored-by: Hanzo Dev <[email protected]>
73 lines
2.0 KiB
TypeScript
73 lines
2.0 KiB
TypeScript
"use client"
|
|
|
|
/**
|
|
* The React Flow node type that renders a `ServiceNode` card. Per-render config
|
|
* (icon override, palette, reduced-motion, `now`) rides a context so the
|
|
* `nodeTypes` map stays a stable module-level identity — React Flow re-creates
|
|
* the graph if `nodeTypes` changes, so it must never be built inline. Handles are
|
|
* invisible and non-interactive: the graph is derived, never drawn by the user.
|
|
*/
|
|
import { createContext, memo, useContext } from "react"
|
|
import type { CSSProperties, ReactNode } from "react"
|
|
import { Handle, Position, type NodeProps } from "@xyflow/react"
|
|
|
|
import { ServiceNode } from "./ServiceNode"
|
|
import type { ServiceNodeData, ServiceStatus, StatusPalette } from "./types"
|
|
|
|
export interface CanvasNodeConfig {
|
|
renderIcon?: (d: ServiceNodeData) => ReactNode
|
|
statusPalette?: Partial<Record<ServiceStatus, StatusPalette>>
|
|
reducedMotion?: boolean
|
|
now?: number
|
|
nodeWidth?: number
|
|
}
|
|
|
|
const Ctx = createContext<CanvasNodeConfig>({})
|
|
export const CanvasNodeConfigProvider = Ctx.Provider
|
|
|
|
const HANDLE: CSSProperties = {
|
|
opacity: 0,
|
|
width: 1,
|
|
height: 1,
|
|
minWidth: 1,
|
|
border: "none",
|
|
background: "transparent",
|
|
pointerEvents: "none",
|
|
}
|
|
|
|
const ServiceFlowNode = memo(function ServiceFlowNode({
|
|
data,
|
|
selected,
|
|
}: NodeProps) {
|
|
const cfg = useContext(Ctx)
|
|
const d = data as unknown as ServiceNodeData
|
|
return (
|
|
<>
|
|
<Handle
|
|
type="target"
|
|
position={Position.Left}
|
|
style={HANDLE}
|
|
isConnectable={false}
|
|
/>
|
|
<ServiceNode
|
|
data={d}
|
|
selected={selected}
|
|
reducedMotion={cfg.reducedMotion}
|
|
statusPalette={cfg.statusPalette}
|
|
renderIcon={cfg.renderIcon}
|
|
now={cfg.now}
|
|
width={cfg.nodeWidth}
|
|
/>
|
|
<Handle
|
|
type="source"
|
|
position={Position.Right}
|
|
style={HANDLE}
|
|
isConnectable={false}
|
|
/>
|
|
</>
|
|
)
|
|
})
|
|
|
|
/** Stable module-level node-type map — one card renders every service. */
|
|
export const CANVAS_NODE_TYPES = { service: ServiceFlowNode } as const
|