feat(platform): 插件协议系统 - 支持声明式渠道、工作流与参考媒体映射
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
import type { CanvasNodeData, CanvasNodeType } from "@/types/canvas";
|
||||
import type { CanvasNodeData, CanvasNodeTypeId } from "@/types/canvas";
|
||||
import type { PluginCanvasNodeContribution } from "@/lib/plugins/plugin-types";
|
||||
|
||||
import type { CanvasNodeDefinition } from "./node-definition";
|
||||
import { canvasNodeDefinitionFromPlugin, type CanvasNodeDefinition } from "./node-definition";
|
||||
|
||||
/** 模块级注册表 */
|
||||
const definitions = new Map<CanvasNodeType, CanvasNodeDefinition>();
|
||||
const definitions = new Map<CanvasNodeTypeId, CanvasNodeDefinition>();
|
||||
/** 节点类型 → 归属方。内置节点归属 "builtin",为后续扩展留出隔离位。 */
|
||||
const ownerByType = new Map<CanvasNodeType, string>();
|
||||
const ownerByType = new Map<CanvasNodeTypeId, string>();
|
||||
|
||||
/** 未注册类型的兜底最小尺寸——与非媒体节点的历史下限一致 */
|
||||
const FALLBACK_MIN_SIZE = { width: 220, height: 160 } as const;
|
||||
@@ -18,6 +19,11 @@ export function registerNodeDefinitions(defs: CanvasNodeDefinition[], ownerId =
|
||||
}
|
||||
}
|
||||
|
||||
/** Registers schema-driven canvas nodes from the unified plugin manifest. */
|
||||
export function registerPluginCanvasNodes(pluginId: string, nodes: PluginCanvasNodeContribution[]) {
|
||||
registerNodeDefinitions(nodes.map((node) => canvasNodeDefinitionFromPlugin(pluginId, node)), pluginId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 注销某归属方的全部节点定义。
|
||||
* 只删归属该 ownerId 的条目——内置节点不会被其他归属方的增删波及。
|
||||
@@ -30,11 +36,11 @@ export function unregisterNodeDefinitions(ownerId: string) {
|
||||
}
|
||||
}
|
||||
|
||||
export function getNodeDefinition(type: CanvasNodeType) {
|
||||
export function getNodeDefinition(type: CanvasNodeTypeId) {
|
||||
return definitions.get(type);
|
||||
}
|
||||
|
||||
export function getNodeOwnerId(type: CanvasNodeType) {
|
||||
export function getNodeOwnerId(type: CanvasNodeTypeId) {
|
||||
return ownerByType.get(type) || "builtin";
|
||||
}
|
||||
|
||||
@@ -48,23 +54,23 @@ export function listCreatableNodeDefinitions() {
|
||||
}
|
||||
|
||||
/** UI 短标签 */
|
||||
export function getNodeLabel(type: CanvasNodeType) {
|
||||
export function getNodeLabel(type: CanvasNodeTypeId) {
|
||||
return definitions.get(type)?.label || "未知节点";
|
||||
}
|
||||
|
||||
/** 列表/搜索标签,缺省派生自 label */
|
||||
export function getNodeListLabel(type: CanvasNodeType) {
|
||||
export function getNodeListLabel(type: CanvasNodeTypeId) {
|
||||
const def = definitions.get(type);
|
||||
if (!def) return "未知节点";
|
||||
return def.listLabel || `${def.label}节点`;
|
||||
}
|
||||
|
||||
export function getNodeIcon(type: CanvasNodeType) {
|
||||
export function getNodeIcon(type: CanvasNodeTypeId) {
|
||||
return definitions.get(type)?.icon ?? null;
|
||||
}
|
||||
|
||||
/** 手动拉伸的最小尺寸 */
|
||||
export function getNodeMinSize(type: CanvasNodeType) {
|
||||
export function getNodeMinSize(type: CanvasNodeTypeId) {
|
||||
return definitions.get(type)?.minSize ?? FALLBACK_MIN_SIZE;
|
||||
}
|
||||
|
||||
@@ -87,6 +93,6 @@ export function getNodeGenerationMode(node: CanvasNodeData) {
|
||||
}
|
||||
|
||||
/** 该节点作为上游输入被计数时的类别,不参与计数返回 undefined */
|
||||
export function getNodeInputKind(type: CanvasNodeType) {
|
||||
export function getNodeInputKind(type: CanvasNodeTypeId) {
|
||||
return definitions.get(type)?.inputKind;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user