diff --git a/public/locales/en.json b/public/locales/en.json index f187f52..fc809e8 100644 --- a/public/locales/en.json +++ b/public/locales/en.json @@ -79,7 +79,7 @@ "tree.desc": "Tree desc", "tree.export": "Export", "tree.firstid": "First id", - "tree.group": "Available groups", + "tree.group": "Enable Node Grouping", "tree.vars": "Define Variables", "tree.vars.name": "name", "tree.vars.invalidName": "Invalid variable name", diff --git a/public/locales/zh.json b/public/locales/zh.json index 9294f43..18e0bc4 100644 --- a/public/locales/zh.json +++ b/public/locales/zh.json @@ -79,7 +79,7 @@ "tree.desc": "说明", "tree.export": "导出", "tree.firstid": "起始标识", - "tree.group": "可用分组", + "tree.group": "启用节点分组", "tree.vars": "定义变量", "tree.vars.name": "变量名", "tree.vars.invalidName": "变量名不合法", diff --git a/src/components/editor.tsx b/src/components/editor.tsx index f128142..1b2000f 100644 --- a/src/components/editor.tsx +++ b/src/components/editor.tsx @@ -239,10 +239,6 @@ export const Editor: FC = ({ onUpdate: updateState, data: editor, . } }; - const parseExpr = (expr: string) => { - return expr.split(/[^a-zA-Z0-9_]/); - }; - const findHightlight = (node: TreeGraphData, highlight: string[], changed?: TreeGraphData[]) => { changed ||= []; if (node.highlightInput || node.highlightOutput || node.highlightArgs) { @@ -276,7 +272,7 @@ export const Editor: FC = ({ onUpdate: updateState, data: editor, . if (isExprType(arg.type)) { const expr: string | string[] = node.args?.[arg.name]; if (typeof expr === "string") { - for (const v of parseExpr(expr)) { + for (const v of b3util.parseExpr(expr)) { if (highlight.includes(v)) { node.highlightArgs = true; changed.push(node); @@ -285,7 +281,7 @@ export const Editor: FC = ({ onUpdate: updateState, data: editor, . } } else if (expr instanceof Array) { loop: for (const str of expr) { - for (const v of parseExpr(str)) { + for (const v of b3util.parseExpr(str)) { if (highlight.includes(v)) { node.highlightArgs = true; changed.push(node); diff --git a/src/components/inspector.tsx b/src/components/inspector.tsx index df1241c..5bfa45f 100644 --- a/src/components/inspector.tsx +++ b/src/components/inspector.tsx @@ -172,6 +172,7 @@ const TreeInspector: FC = () => { flexDirection: "row", gap: 8, rowGap: 0, + marginLeft: 16, flexWrap: "wrap", }} > diff --git a/src/misc/b3type.ts b/src/misc/b3type.ts index 04c14d8..b3bcce8 100644 --- a/src/misc/b3type.ts +++ b/src/misc/b3type.ts @@ -1,5 +1,11 @@ import type { TreeGraphData as G6TreeGraphData } from "@antv/g6"; -import type { NodeDef } from "../behavior3/src/behavior3"; +import { NodeDef } from "../behavior3/src/behavior3"; + +declare module "../behavior3/src/behavior3" { + interface NodeDef { + group?: string; + } +} export type NodeType = NodeDef["type"] | "Other" | "Error"; export type NodeArg = Exclude[number]; diff --git a/src/misc/b3util.ts b/src/misc/b3util.ts index 80226f5..7980b97 100644 --- a/src/misc/b3util.ts +++ b/src/misc/b3util.ts @@ -1,5 +1,5 @@ import * as fs from "fs"; -import { type NodeDef } from "../behavior3/src/behavior3"; +import { NodeDef } from "../behavior3/src/behavior3"; import { ImportDef, isBoolType, @@ -54,6 +54,7 @@ export const initWorkdir = (path: string, handler: typeof alertError) => { const group = v.type.match(/\((\w+)\)/)?.[1]; if (group) { + v.group = group; groups.add(group); } } @@ -534,7 +535,7 @@ export const isVariadic = (def: string[], i: number) => { }; const isValidInputOrOutput = (def: string[], data: string[] | undefined, index: number) => { - return def[index].includes("?") || data?.[index] || (isVariadic(def, index) && data?.[index]); + return def[index].includes("?") || data?.[index] || isVariadic(def, index); }; export const checkTreeData = (data: TreeGraphData) => { @@ -759,3 +760,8 @@ export const loadSubtreeVarDef = (data: TreeGraphData) => { }); return result; }; + +export const parseExpr = (expr: string) => { + const result = expr.split(/[^a-zA-Z0-9_.]/); + return result.map((v) => v.split(".")[0]).filter((v) => v); +};