check group
This commit is contained in:
1 parent
f37bf6b48a
commit
deaa12ff4b
9 files changed
+51
-16
No files matched your search
@@ -103,6 +103,7 @@
|
|||||||
"node.editSubtreeDenied": "Unable to edit the subtree node",
|
"node.editSubtreeDenied": "Unable to edit the subtree node",
|
||||||
"node.id": "Node id",
|
"node.id": "Node id",
|
||||||
"node.inputVariable": "Input variables",
|
"node.inputVariable": "Input variables",
|
||||||
|
"node.invalidGroup": "Node group '{{group}}' is not enabled",
|
||||||
"node.invalidValue": "Invalid value",
|
"node.invalidValue": "Invalid value",
|
||||||
"node.invalidVariableName": "Invalid variable name, should start with a letter or underscore",
|
"node.invalidVariableName": "Invalid variable name, should start with a letter or underscore",
|
||||||
"node.name": "Node name",
|
"node.name": "Node name",
|
||||||
|
|||||||
@@ -103,6 +103,7 @@
|
|||||||
"node.editSubtreeDenied": "不能编辑子树节点",
|
"node.editSubtreeDenied": "不能编辑子树节点",
|
||||||
"node.id": "节点标识",
|
"node.id": "节点标识",
|
||||||
"node.inputVariable": "输入变量",
|
"node.inputVariable": "输入变量",
|
||||||
|
"node.invalidGroup": "节点分组 “{{group}}” 未启用",
|
||||||
"node.invalidValue": "无效的值",
|
"node.invalidValue": "无效的值",
|
||||||
"node.invalidVariableName": "变量名必须以字母或下划线开头",
|
"node.invalidVariableName": "变量名必须以字母或下划线开头",
|
||||||
"node.name": "节点名称",
|
"node.name": "节点名称",
|
||||||
|
|||||||
@@ -48,6 +48,13 @@
|
|||||||
"args": {
|
"args": {
|
||||||
"value": "target.x > 0"
|
"value": "target.x > 0"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 7,
|
||||||
|
"name": "MoveToTarget",
|
||||||
|
"input": [
|
||||||
|
"target"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
Submodule src/behavior3 updated: db1e1369ca...ca446528bd.
@@ -495,6 +495,7 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
|
|||||||
editor.desc = editTree.data.desc || "";
|
editor.desc = editTree.data.desc || "";
|
||||||
editor.export = editTree.data.export !== false;
|
editor.export = editTree.data.export !== false;
|
||||||
editor.group = editTree.data.group || [];
|
editor.group = editTree.data.group || [];
|
||||||
|
b3util.updateUsingGroups(editor.group);
|
||||||
if (editor.data.firstid !== editTree.data.firstid) {
|
if (editor.data.firstid !== editTree.data.firstid) {
|
||||||
editor.firstid = editTree.data.firstid ?? 1;
|
editor.firstid = editTree.data.firstid ?? 1;
|
||||||
editor.declare.vars = editTree.data.declare.vars || [];
|
editor.declare.vars = editTree.data.declare.vars || [];
|
||||||
@@ -1205,6 +1206,7 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (workspace.editing === editor) {
|
if (workspace.editing === editor) {
|
||||||
checkSubtree();
|
checkSubtree();
|
||||||
|
b3util.updateUsingGroups(editor.group);
|
||||||
}
|
}
|
||||||
}, [workspace.editing]);
|
}, [workspace.editing]);
|
||||||
|
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ import {
|
|||||||
isValidVariableName,
|
isValidVariableName,
|
||||||
isVariadic,
|
isVariadic,
|
||||||
loadVarDef,
|
loadVarDef,
|
||||||
|
usingGroups,
|
||||||
} from "../misc/b3util";
|
} from "../misc/b3util";
|
||||||
import { Hotkey, isMacos } from "../misc/keys";
|
import { Hotkey, isMacos } from "../misc/keys";
|
||||||
import { mergeClassNames } from "../misc/util";
|
import { mergeClassNames } from "../misc/util";
|
||||||
@@ -746,7 +747,20 @@ const NodeInspector: FC = () => {
|
|||||||
<Form.Item name="id" label={t("node.id")}>
|
<Form.Item name="id" label={t("node.id")}>
|
||||||
<Input disabled={true} />
|
<Input disabled={true} />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item name="type" label={t("node.type")}>
|
<Form.Item
|
||||||
|
name="type"
|
||||||
|
label={t("node.type")}
|
||||||
|
rules={[
|
||||||
|
{
|
||||||
|
validator() {
|
||||||
|
if (def.group && !usingGroups[def.group]) {
|
||||||
|
return Promise.reject(new Error(t("node.invalidGroup", { group: def.group })));
|
||||||
|
}
|
||||||
|
return Promise.resolve();
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
>
|
||||||
<Input disabled={true} />
|
<Input disabled={true} />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item name="children" label={t("node.children")}>
|
<Form.Item name="children" label={t("node.children")}>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import G6 from "@antv/g6";
|
import G6 from "@antv/g6";
|
||||||
import { useWorkspace } from "../contexts/workspace-context";
|
import { useWorkspace } from "../contexts/workspace-context";
|
||||||
import { TreeGraphData, getNodeType } from "../misc/b3type";
|
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 i18n from "../misc/i18n";
|
||||||
import { isMacos } from "../misc/keys";
|
import { isMacos } from "../misc/keys";
|
||||||
|
|
||||||
@@ -142,14 +142,14 @@ G6.registerNode(
|
|||||||
},
|
},
|
||||||
draw(cfg, group) {
|
draw(cfg, group) {
|
||||||
const data = cfg as TreeGraphData;
|
const data = cfg as TreeGraphData;
|
||||||
const nodeDefs = getNodeDefs();
|
|
||||||
const nodeDef = nodeDefs.get(data.name);
|
const nodeDef = nodeDefs.get(data.name);
|
||||||
let classify = getNodeType(nodeDef);
|
let classify = getNodeType(nodeDef);
|
||||||
let color = nodeDef.color || NODE_COLORS[classify] || NODE_COLORS["Other"];
|
let color = nodeDef.color || NODE_COLORS[classify] || NODE_COLORS["Other"];
|
||||||
if (
|
if (
|
||||||
!nodeDefs.has(data.name) ||
|
!nodeDefs.has(data.name) ||
|
||||||
(data.path && !data.children?.length) ||
|
(data.path && !data.children?.length) ||
|
||||||
!checkTreeData(data)
|
!checkTreeData(data) ||
|
||||||
|
(nodeDef.group && !usingGroups[nodeDef.group])
|
||||||
) {
|
) {
|
||||||
classify = "Error";
|
classify = "Error";
|
||||||
color = NODE_COLORS[classify];
|
color = NODE_COLORS[classify];
|
||||||
|
|||||||
@@ -651,7 +651,7 @@ export const useWorkspace = create<WorkspaceStore>((set, get) => ({
|
|||||||
loadNodeDefs: () => {
|
loadNodeDefs: () => {
|
||||||
const workspace = get();
|
const workspace = get();
|
||||||
b3util.initWorkdir(workspace.workdir, message.error.bind(message));
|
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");
|
workspace.editing?.dispatch("refresh");
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
+20
-10
@@ -24,10 +24,14 @@ export class NodeDefs extends Map<string, NodeDef> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export let nodeDefs: NodeDefs = new NodeDefs();
|
||||||
|
export let groupDefs: string[] = [];
|
||||||
|
|
||||||
|
export let usingGroups: Record<string, boolean> = {};
|
||||||
|
export let usingVars: Record<string, boolean> = {};
|
||||||
|
|
||||||
let workdir: string = "";
|
let workdir: string = "";
|
||||||
let alertError: (msg: string, duration?: number) => void = () => {};
|
let alertError: (msg: string, duration?: number) => void = () => {};
|
||||||
let nodeDefs: NodeDefs = new NodeDefs();
|
|
||||||
let groupDefs: string[] = [];
|
|
||||||
|
|
||||||
const unknownNodeDef: NodeDef = {
|
const unknownNodeDef: NodeDef = {
|
||||||
name: "unknown",
|
name: "unknown",
|
||||||
@@ -35,14 +39,6 @@ const unknownNodeDef: NodeDef = {
|
|||||||
type: "Action",
|
type: "Action",
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getNodeDefs = () => {
|
|
||||||
return nodeDefs;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const getGroupDefs = () => {
|
|
||||||
return groupDefs;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const initWorkdir = (path: string, handler: typeof alertError) => {
|
export const initWorkdir = (path: string, handler: typeof alertError) => {
|
||||||
workdir = path;
|
workdir = path;
|
||||||
alertError = handler;
|
alertError = handler;
|
||||||
@@ -61,6 +57,20 @@ export const initWorkdir = (path: string, handler: typeof alertError) => {
|
|||||||
groupDefs = Array.from(groups);
|
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) => {
|
export const isValidVariableName = (name: string) => {
|
||||||
return /^[a-zA-Z_]/.test(name);
|
return /^[a-zA-Z_]/.test(name);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in new issue
Block a user