Files
ai-video-fullstack/frontend/src/components/workflow/context.ts
T

32 lines
1.0 KiB
TypeScript

"use client";
/**
* 画布内共享上下文。GenericNode / ConditionEdge 由 ReactFlow 渲染,拿不到外层
* 回调,统一通过这些 context 取节点规格与编辑/复制/删除动作。
*/
import { createContext } from "react";
import type { NodeSpecMap } from "./specs";
/** 节点类型 → 运行期规格(来自 /api/node-types) */
export const NodeSpecsContext = createContext<NodeSpecMap>({});
export type ElementActions = {
edit: (id: string) => void;
remove: (id: string) => void;
};
export type NodeActions = ElementActions & {
duplicate: (id: string) => void;
};
const noop: ElementActions = { edit: () => {}, remove: () => {} };
const noopNodeActions: NodeActions = { ...noop, duplicate: () => {} };
export const NodeActionContext = createContext<NodeActions>(noopNodeActions);
export const EdgeActionContext = createContext<ElementActions>(noop);
/** 调试通话中当前激活的节点 id(画布据此高亮),无激活为 null。 */
export const ActiveNodeContext = createContext<string | null>(null);