diff --git a/public/locales/en.json b/public/locales/en.json index fc809e8..ac67896 100644 --- a/public/locales/en.json +++ b/public/locales/en.json @@ -103,6 +103,7 @@ "node.editSubtreeDenied": "Unable to edit the subtree node", "node.id": "Node id", "node.inputVariable": "Input variables", + "node.invalidGroup": "Node group '{{group}}' is not enabled", "node.invalidValue": "Invalid value", "node.invalidVariableName": "Invalid variable name, should start with a letter or underscore", "node.name": "Node name", diff --git a/public/locales/zh.json b/public/locales/zh.json index 18e0bc4..be9c5c5 100644 --- a/public/locales/zh.json +++ b/public/locales/zh.json @@ -103,6 +103,7 @@ "node.editSubtreeDenied": "不能编辑子树节点", "node.id": "节点标识", "node.inputVariable": "输入变量", + "node.invalidGroup": "节点分组 “{{group}}” 未启用", "node.invalidValue": "无效的值", "node.invalidVariableName": "变量名必须以字母或下划线开头", "node.name": "节点名称", diff --git a/sample/vars/test-vars.json b/sample/vars/test-vars.json index 9e4587b..81ef870 100644 --- a/sample/vars/test-vars.json +++ b/sample/vars/test-vars.json @@ -48,6 +48,13 @@ "args": { "value": "target.x > 0" } + }, + { + "id": 7, + "name": "MoveToTarget", + "input": [ + "target" + ] } ] } diff --git a/src/behavior3 b/src/behavior3 index db1e136..ca44652 160000 --- a/src/behavior3 +++ b/src/behavior3 @@ -1 +1 @@ -Subproject commit db1e1369ca48d572210ed2b3a912e62b7cf77737 +Subproject commit ca446528bd715eb250a6f32d94bcf8af0d4d5c12 diff --git a/src/components/editor.tsx b/src/components/editor.tsx index 1b2000f..672f438 100644 --- a/src/components/editor.tsx +++ b/src/components/editor.tsx @@ -495,6 +495,7 @@ export const Editor: FC = ({ onUpdate: updateState, data: editor, . editor.desc = editTree.data.desc || ""; editor.export = editTree.data.export !== false; editor.group = editTree.data.group || []; + b3util.updateUsingGroups(editor.group); if (editor.data.firstid !== editTree.data.firstid) { editor.firstid = editTree.data.firstid ?? 1; editor.declare.vars = editTree.data.declare.vars || []; @@ -1205,6 +1206,7 @@ export const Editor: FC = ({ onUpdate: updateState, data: editor, . useEffect(() => { if (workspace.editing === editor) { checkSubtree(); + b3util.updateUsingGroups(editor.group); } }, [workspace.editing]); diff --git a/src/components/inspector.tsx b/src/components/inspector.tsx index 5bfa45f..a8adc8c 100644 --- a/src/components/inspector.tsx +++ b/src/components/inspector.tsx @@ -43,6 +43,7 @@ import { isValidVariableName, isVariadic, loadVarDef, + usingGroups, } from "../misc/b3util"; import { Hotkey, isMacos } from "../misc/keys"; import { mergeClassNames } from "../misc/util"; @@ -746,7 +747,20 @@ const NodeInspector: FC = () => { - + diff --git a/src/components/register-node.ts b/src/components/register-node.ts index 486747d..0a59ecd 100644 --- a/src/components/register-node.ts +++ b/src/components/register-node.ts @@ -1,7 +1,7 @@ import G6 from "@antv/g6"; import { useWorkspace } from "../contexts/workspace-context"; import { TreeGraphData, getNodeType } from "../misc/b3type"; -import { checkTreeData, getNodeDefs } from "../misc/b3util"; +import { checkTreeData, nodeDefs, usingGroups } from "../misc/b3util"; import i18n from "../misc/i18n"; import { isMacos } from "../misc/keys"; @@ -142,14 +142,14 @@ G6.registerNode( }, draw(cfg, group) { const data = cfg as TreeGraphData; - const nodeDefs = getNodeDefs(); const nodeDef = nodeDefs.get(data.name); let classify = getNodeType(nodeDef); let color = nodeDef.color || NODE_COLORS[classify] || NODE_COLORS["Other"]; if ( !nodeDefs.has(data.name) || (data.path && !data.children?.length) || - !checkTreeData(data) + !checkTreeData(data) || + (nodeDef.group && !usingGroups[nodeDef.group]) ) { classify = "Error"; color = NODE_COLORS[classify]; diff --git a/src/contexts/workspace-context.ts b/src/contexts/workspace-context.ts index faea9f9..5cbe345 100644 --- a/src/contexts/workspace-context.ts +++ b/src/contexts/workspace-context.ts @@ -651,7 +651,7 @@ export const useWorkspace = create((set, get) => ({ loadNodeDefs: () => { const workspace = get(); b3util.initWorkdir(workspace.workdir, message.error.bind(message)); - set({ nodeDefs: b3util.getNodeDefs(), groupDefs: b3util.getGroupDefs() }); + set({ nodeDefs: b3util.nodeDefs, groupDefs: b3util.groupDefs }); workspace.editing?.dispatch("refresh"); }, diff --git a/src/misc/b3util.ts b/src/misc/b3util.ts index 7980b97..ab51ce4 100644 --- a/src/misc/b3util.ts +++ b/src/misc/b3util.ts @@ -24,10 +24,14 @@ export class NodeDefs extends Map { } } +export let nodeDefs: NodeDefs = new NodeDefs(); +export let groupDefs: string[] = []; + +export let usingGroups: Record = {}; +export let usingVars: Record = {}; + let workdir: string = ""; let alertError: (msg: string, duration?: number) => void = () => {}; -let nodeDefs: NodeDefs = new NodeDefs(); -let groupDefs: string[] = []; const unknownNodeDef: NodeDef = { name: "unknown", @@ -35,14 +39,6 @@ const unknownNodeDef: NodeDef = { type: "Action", }; -export const getNodeDefs = () => { - return nodeDefs; -}; - -export const getGroupDefs = () => { - return groupDefs; -}; - export const initWorkdir = (path: string, handler: typeof alertError) => { workdir = path; alertError = handler; @@ -61,6 +57,20 @@ export const initWorkdir = (path: string, handler: typeof alertError) => { groupDefs = Array.from(groups); }; +export const updateUsingGroups = (group: string[]) => { + usingGroups = {}; + for (const g of group) { + usingGroups[g] = true; + } +}; + +export const updateUsingVars = (vars: VarDef[]) => { + usingVars = {}; + for (const v of vars) { + usingVars[v.name] = true; + } +}; + export const isValidVariableName = (name: string) => { return /^[a-zA-Z_]/.test(name); };