check expr in arg array
This commit is contained in:
1 parent
4d666d6592
commit
4ac8a01c62
6 files changed
+76
-27
No files matched your search
@@ -15,7 +15,6 @@ module.exports = {
|
|||||||
"react-refresh/only-export-components": "warn",
|
"react-refresh/only-export-components": "warn",
|
||||||
|
|
||||||
// TODO:
|
// TODO:
|
||||||
"@typescript-eslint/no-explicit-any": "off",
|
|
||||||
"@typescript-eslint/no-unused-vars": "off",
|
"@typescript-eslint/no-unused-vars": "off",
|
||||||
"@typescript-eslint/no-unsafe-assignment": "off",
|
"@typescript-eslint/no-unsafe-assignment": "off",
|
||||||
"@typescript-eslint/no-unsafe-argument": "off",
|
"@typescript-eslint/no-unsafe-argument": "off",
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { ArrowDownOutlined, ArrowUpOutlined, CloseOutlined } from "@ant-design/icons";
|
import { ArrowDownOutlined, ArrowUpOutlined, CloseOutlined } from "@ant-design/icons";
|
||||||
import G6, { G6GraphEvent, Item, TreeGraph } from "@antv/g6";
|
import G6, { G6GraphEvent, Item, Matrix, TreeGraph } from "@antv/g6";
|
||||||
import { dialog } from "@electron/remote";
|
import { dialog } from "@electron/remote";
|
||||||
import { useSize } from "ahooks";
|
import { useSize } from "ahooks";
|
||||||
import { Button, Dropdown, Flex, FlexProps, Input, InputRef, MenuProps } from "antd";
|
import { Button, Dropdown, Flex, FlexProps, Input, InputRef, MenuProps } from "antd";
|
||||||
@@ -319,7 +319,7 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
|
|||||||
|
|
||||||
node.def.args?.forEach((arg) => {
|
node.def.args?.forEach((arg) => {
|
||||||
if (isExprType(arg.type)) {
|
if (isExprType(arg.type)) {
|
||||||
const expr: string | string[] = node.args?.[arg.name];
|
const expr = node.args?.[arg.name] as string | string[] | undefined;
|
||||||
if (typeof expr === "string") {
|
if (typeof expr === "string") {
|
||||||
for (const v of b3util.parseExpr(expr)) {
|
for (const v of b3util.parseExpr(expr)) {
|
||||||
if (highlight.includes(v)) {
|
if (highlight.includes(v)) {
|
||||||
@@ -399,10 +399,20 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!found && node.args) {
|
if (!found && node.args) {
|
||||||
for (const str in node.args) {
|
loop: for (const str in node.args) {
|
||||||
if (includeString(str, option) || includeString(node.args[str], option)) {
|
const value = node.args[str];
|
||||||
|
if (typeof value === "string") {
|
||||||
|
if (includeString(value, option)) {
|
||||||
found = true;
|
found = true;
|
||||||
break;
|
break loop;
|
||||||
|
}
|
||||||
|
} else if (value instanceof Array) {
|
||||||
|
for (const v of value) {
|
||||||
|
if (includeString(v, option)) {
|
||||||
|
found = true;
|
||||||
|
break loop;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -900,6 +910,7 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
|
|||||||
const icon = data.collapsed ? G6.Marker.expand : G6.Marker.collapse;
|
const icon = data.collapsed ? G6.Marker.expand : G6.Marker.collapse;
|
||||||
const marker = item
|
const marker = item
|
||||||
.get("group")
|
.get("group")
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
.find((ele: any) => ele.get("name") === "collapse-icon");
|
.find((ele: any) => ele.get("name") === "collapse-icon");
|
||||||
editor.graph.refresh();
|
editor.graph.refresh();
|
||||||
marker.attr("symbol", icon);
|
marker.attr("symbol", icon);
|
||||||
@@ -935,9 +946,9 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
editor.graph.on("viewportchange", (data: any) => {
|
editor.graph.on("viewportchange", (data) => {
|
||||||
if (data.action === "translate" || data.action === "zoom") {
|
if (data.action === "translate" || data.action === "zoom") {
|
||||||
editor.graphMatrix = data.matrix;
|
editor.graphMatrix = data.matrix as Matrix;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -106,6 +106,7 @@ const TreeInspector: FC = () => {
|
|||||||
form.setFieldValue("subtree", data.subtree);
|
form.setFieldValue("subtree", data.subtree);
|
||||||
}, [workspace.editingTree, groupDefs]);
|
}, [workspace.editingTree, groupDefs]);
|
||||||
|
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
const finish = (values: any) => {
|
const finish = (values: any) => {
|
||||||
workspace.editing?.dispatch("updateTree", {
|
workspace.editing?.dispatch("updateTree", {
|
||||||
data: {
|
data: {
|
||||||
@@ -117,10 +118,10 @@ const TreeInspector: FC = () => {
|
|||||||
.map((v) => (v.value ? v.name : undefined))
|
.map((v) => (v.value ? v.name : undefined))
|
||||||
.filter((v) => v)
|
.filter((v) => v)
|
||||||
.sort(),
|
.sort(),
|
||||||
declvar: (values["declvar"] as VarDef[])
|
declvar: (values.declvar as VarDef[])
|
||||||
.filter((v) => v && v.name)
|
.filter((v) => v && v.name)
|
||||||
.sort((a, b) => a.name.localeCompare(b.name)),
|
.sort((a, b) => a.name.localeCompare(b.name)),
|
||||||
import: (values["import"] as ImportDef[])
|
import: (values.import as ImportDef[])
|
||||||
.filter((v) => v && v.path)
|
.filter((v) => v && v.path)
|
||||||
.sort((a, b) => a.path.localeCompare(b.path))
|
.sort((a, b) => a.path.localeCompare(b.path))
|
||||||
.map((v) => ({
|
.map((v) => ({
|
||||||
@@ -633,6 +634,7 @@ const NodeInspector: FC = () => {
|
|||||||
const disabled = !editingNode.editable;
|
const disabled = !editingNode.editable;
|
||||||
|
|
||||||
// update value
|
// update value
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
const finish = (values: any) => {
|
const finish = (values: any) => {
|
||||||
const data = {} as NodeModel;
|
const data = {} as NodeModel;
|
||||||
data.id = editingNode.data.id;
|
data.id = editingNode.data.id;
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import G6 from "@antv/g6";
|
import G6 from "@antv/g6";
|
||||||
|
import { NodeDef } from "../behavior3/src/behavior3";
|
||||||
import { useWorkspace } from "../contexts/workspace-context";
|
import { useWorkspace } from "../contexts/workspace-context";
|
||||||
import { TreeGraphData, getNodeType, isExprType } from "../misc/b3type";
|
import { TreeGraphData, getNodeType, isExprType } from "../misc/b3type";
|
||||||
import { checkTreeData, nodeDefs, parseExpr, usingGroups, usingVars } from "../misc/b3util";
|
import { checkTreeData, nodeDefs, parseExpr, usingGroups, usingVars } from "../misc/b3util";
|
||||||
@@ -71,9 +72,43 @@ const toBreakWord = (str: string, maxWidth: number, fontSize?: string) => {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const foundUndefined = (value?: string[]) => {
|
||||||
|
if (!value || !usingVars) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return value.some((v) => v && usingVars?.[v] === undefined);
|
||||||
|
};
|
||||||
|
|
||||||
|
const foundUndefinedInArgs = (def: NodeDef, data: TreeGraphData) => {
|
||||||
|
if (!def.args || !data.args || !usingVars) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
for (const arg of def.args) {
|
||||||
|
if (!isExprType(arg.type)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const expr = data.args[arg.name] as string | string[] | undefined;
|
||||||
|
if (!expr) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (typeof expr === "string") {
|
||||||
|
if (foundUndefined(parseExpr(expr))) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} else if (Array.isArray(expr)) {
|
||||||
|
for (const str of expr) {
|
||||||
|
if (foundUndefined(parseExpr(str))) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
export const calcTreeDataSize = (data: TreeGraphData) => {
|
export const calcTreeDataSize = (data: TreeGraphData) => {
|
||||||
let height = 50 + 2;
|
let height = 50 + 2;
|
||||||
const updateHeight = (obj: any) => {
|
const updateHeight = (obj: unknown) => {
|
||||||
if ((Array.isArray(obj) && obj.length) || (obj && Object.keys(obj).length > 0)) {
|
if ((Array.isArray(obj) && obj.length) || (obj && Object.keys(obj).length > 0)) {
|
||||||
const { line } = toBreakWord(`${i18n.t("regnode.args")}${JSON.stringify(obj)}`, 200);
|
const { line } = toBreakWord(`${i18n.t("regnode.args")}${JSON.stringify(obj)}`, 200);
|
||||||
height += 20 * line;
|
height += 20 * line;
|
||||||
@@ -88,7 +123,7 @@ export const calcTreeDataSize = (data: TreeGraphData) => {
|
|||||||
return [220, height];
|
return [220, height];
|
||||||
};
|
};
|
||||||
|
|
||||||
const NODE_COLORS: any = {
|
const NODE_COLORS = {
|
||||||
["Composite"]: "#34d800",
|
["Composite"]: "#34d800",
|
||||||
["Decorator"]: "#ff6700",
|
["Decorator"]: "#ff6700",
|
||||||
["Condition"]: "#e4148b",
|
["Condition"]: "#e4148b",
|
||||||
@@ -149,18 +184,11 @@ G6.registerNode(
|
|||||||
if (
|
if (
|
||||||
!nodeDefs.has(data.name) ||
|
!nodeDefs.has(data.name) ||
|
||||||
(data.path && !data.children?.length) ||
|
(data.path && !data.children?.length) ||
|
||||||
!checkTreeData(data) ||
|
|
||||||
(nodeDef.group && !nodeDef.group.some((g) => usingGroups[g])) ||
|
(nodeDef.group && !nodeDef.group.some((g) => usingGroups[g])) ||
|
||||||
(usingVars &&
|
!checkTreeData(data) ||
|
||||||
(data.input?.some((v) => v && usingVars?.[v] === undefined) ||
|
foundUndefined(data.input) ||
|
||||||
data.output?.some((v) => v && usingVars?.[v] === undefined) ||
|
foundUndefined(data.output) ||
|
||||||
nodeDef.args?.some(
|
foundUndefinedInArgs(nodeDef, data)
|
||||||
(v) =>
|
|
||||||
isExprType(v.type) &&
|
|
||||||
parseExpr(data.args?.[v.name] ?? "").some(
|
|
||||||
(vv) => vv && usingVars?.[vv] === undefined
|
|
||||||
)
|
|
||||||
)))
|
|
||||||
) {
|
) {
|
||||||
classify = "Error";
|
classify = "Error";
|
||||||
color = NODE_COLORS[classify];
|
color = NODE_COLORS[classify];
|
||||||
@@ -359,7 +387,7 @@ G6.registerNode(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const args: any = data.args;
|
const args = data.args;
|
||||||
if (nodeDef.args && args && Object.keys(args).length > 0) {
|
if (nodeDef.args && args && Object.keys(args).length > 0) {
|
||||||
const { str, line } = toBreakWord(`${i18n.t("regnode.args")}${JSON.stringify(args)}`, 200);
|
const { str, line } = toBreakWord(`${i18n.t("regnode.args")}${JSON.stringify(args)}`, 200);
|
||||||
if (data.highlightArgs) {
|
if (data.highlightArgs) {
|
||||||
|
|||||||
+2
-2
@@ -24,7 +24,7 @@ export interface NodeModel {
|
|||||||
id: number;
|
id: number;
|
||||||
name: string;
|
name: string;
|
||||||
desc?: string;
|
desc?: string;
|
||||||
args?: { [key: string]: any };
|
args?: { [key: string]: unknown };
|
||||||
input?: string[];
|
input?: string[];
|
||||||
output?: string[];
|
output?: string[];
|
||||||
children?: NodeModel[];
|
children?: NodeModel[];
|
||||||
@@ -74,7 +74,7 @@ export interface TreeModel {
|
|||||||
export interface TreeGraphData extends G6TreeGraphData {
|
export interface TreeGraphData extends G6TreeGraphData {
|
||||||
name: string;
|
name: string;
|
||||||
desc?: string;
|
desc?: string;
|
||||||
args?: { [key: string]: any };
|
args?: { [key: string]: unknown };
|
||||||
input?: string[];
|
input?: string[];
|
||||||
output?: string[];
|
output?: string[];
|
||||||
children?: TreeGraphData[];
|
children?: TreeGraphData[];
|
||||||
|
|||||||
+10
-1
@@ -325,8 +325,17 @@ export const checkNodeData = (data: NodeModel | null | undefined) => {
|
|||||||
|
|
||||||
if (data.args && conf.args) {
|
if (data.args && conf.args) {
|
||||||
for (const arg of conf.args) {
|
for (const arg of conf.args) {
|
||||||
|
const value = data.args?.[arg.name] as string | string[] | undefined;
|
||||||
if (isExprType(arg.type)) {
|
if (isExprType(arg.type)) {
|
||||||
for (const v of parseExpr(data.args[arg.name] ?? "")) {
|
const vars: string[] = [];
|
||||||
|
if (typeof value === "string") {
|
||||||
|
vars.push(...parseExpr(value));
|
||||||
|
} else if (Array.isArray(value)) {
|
||||||
|
for (const v of value) {
|
||||||
|
vars.push(...parseExpr(v));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (const v of vars) {
|
||||||
if (v && !usingVars[v]) {
|
if (v && !usingVars[v]) {
|
||||||
error(data, `expr variable '${arg.name}' is not defined`);
|
error(data, `expr variable '${arg.name}' is not defined`);
|
||||||
hasError = true;
|
hasError = true;
|
||||||
|
|||||||
Reference in new issue
Block a user