mirror of
https://github.com/basketikun/infinite-canvas.git
synced 2026-07-24 06:54:06 +08:00
27 lines
1.3 KiB
TypeScript
27 lines
1.3 KiB
TypeScript
import { createPluginStorage, emitCanvasEvent, onCanvasEvent } from "@/lib/canvas/canvas-event-bus";
|
|
import { getNodePluginId } from "@/lib/canvas/node-registry";
|
|
import type { CanvasTheme } from "@/lib/canvas-theme";
|
|
import type { CanvasNodeData } from "@/types/canvas";
|
|
import type { CanvasNodeContext, CanvasPluginHost } from "@/types/canvas-plugin";
|
|
|
|
// 把宿主能力 + 节点 + 主题/缩放,组装成注入给插件节点的上下文
|
|
export function buildNodeContext(host: CanvasPluginHost, node: CanvasNodeData, theme: CanvasTheme, scale: number): CanvasNodeContext {
|
|
const storage = createPluginStorage(getNodePluginId(node.type));
|
|
return {
|
|
node,
|
|
theme,
|
|
scale,
|
|
updateMetadata: (patch) => host.updateMetadata(node.id, patch),
|
|
updateNode: (patch) => host.updateNode(node.id, patch),
|
|
getNode: (id) => host.getNode(id),
|
|
getNodes: () => host.getNodes(),
|
|
getConnections: () => host.getConnections(),
|
|
getUpstream: () => host.getUpstream(node.id),
|
|
getDownstream: () => host.getDownstream(node.id),
|
|
applyOps: (ops) => host.applyOps(ops),
|
|
emit: (event, payload) => emitCanvasEvent(event, payload),
|
|
on: (event, handler) => onCanvasEvent(event, handler),
|
|
storage,
|
|
};
|
|
}
|