"use client"; import {useScopedNodeEditing} from '@/components/canvas/node-editing'; import { Handle, Position, BaseEdge, getBezierPath, type NodeProps, type EdgeProps } from '@xyflow/react'; import { defineComponent, editable, movable } from '@/lib/canvas-core/index'; import type {ReactFlowProjectionNode as ProjectionNode,ReactFlowProjectionEdge as ProjectionEdge} from '@/lib/canvas-bindings/react-flow'; import type { CanvasRuntimeExtension } from '@/lib/canvas-bindings/react-flow'; import { useCanvasBinding,useElement, useCanvasRendererCommands } from '@/lib/canvas-bindings/react-flow'; function rendered(id:string){const host=globalThis as typeof globalThis&{__fixtureRenders?:Record};const counts=host.__fixtureRenders??={};counts[id]=(counts[id]??0)+1;} function Meter({data}:NodeProps){ const commands=useCanvasRendererCommands(),lookup=useElement(data.__headlessRecord!),record=lookup.status==='present'?lookup.element:data.__headlessRecord!;rendered(record.id);const legacy=useScopedNodeEditing(record.id,data.__headlessTarget),unbound=useScopedNodeEditing(record.id),binding=useCanvasBinding();const host=globalThis as typeof globalThis&{__fixtureEngine?:typeof binding.engine;__fixtureLegacy?:Record;__fixtureUnbound?:Record};host.__fixtureEngine=binding.engine;(host.__fixtureLegacy??={})[record.id]=legacy;(host.__fixtureUnbound??={})[record.id]=unbound; return
Metric {String(record.data.metric)}
; } function MeterEdge(props:EdgeProps){rendered(props.id);const [path]=getBezierPath(props);return Metric {String(props.data?.__headlessRecord?.data.metric)};} export const fixtureExtension:CanvasRuntimeExtension={ components:[defineComponent({id:'fixture:meter',dataVersion:1,structure:'node',validate:data=>Number.isSafeInteger(data.metric),features:[editable(),movable()],copy:{references:[],omit:[]}}),defineComponent({id:'fixture:metric-edge',dataVersion:1,structure:'connection',validate:data=>typeof data.metric==='number',features:[],copy:{references:[],omit:[]}})], renderers:[{componentId:'fixture:meter',dataVersion:1,structure:'node',rendererId:'fixture-meter',render:Meter},{componentId:'fixture:metric-edge',dataVersion:1,structure:'connection',rendererId:'fixture-metric-edge',render:MeterEdge}], };