fix variadic input and ouput
This commit is contained in:
1 parent
61431893bf
commit
46d13cac7b
8 files changed
+95
-496
No files matched your search
+1
-1
Submodule src/behavior3 updated: 752008fbc3...db1e1369ca.
@@ -686,10 +686,14 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
|
||||
const root = b3util.createFileData(editor.data);
|
||||
const treeModel = {
|
||||
name: Path.basenameWithoutExt(path),
|
||||
root,
|
||||
desc: editor.desc,
|
||||
firstid: editor.firstid ?? 1,
|
||||
export: editor.export,
|
||||
desc: editor.desc,
|
||||
declare: {
|
||||
imports: editor.declare.imports.map((v) => v.path).sort(),
|
||||
vars: editor.declare.vars.sort((a, b) => a.name.localeCompare(b.name)),
|
||||
},
|
||||
root,
|
||||
} as TreeModel;
|
||||
editor.modifiedTime = Date.now();
|
||||
fs.writeFileSync(path, JSON.stringify(treeModel, null, 2));
|
||||
|
||||
@@ -36,6 +36,7 @@ import {
|
||||
isNodeArgArray,
|
||||
isNodeArgOptional,
|
||||
isValidVariableName,
|
||||
isVariadic,
|
||||
} from "../misc/b3util";
|
||||
import { Hotkey, isMacos } from "../misc/keys";
|
||||
import { mergeClassNames } from "../misc/util";
|
||||
@@ -119,10 +120,6 @@ const NodeInspector: FC = () => {
|
||||
const { t } = useTranslation();
|
||||
const [form] = Form.useForm();
|
||||
|
||||
const isVariadic = (arr: string[], i: number) => {
|
||||
return arr[i].endsWith("...") && i === arr.length - 1;
|
||||
};
|
||||
|
||||
const validateFieldsLater = useDebounceCallback(
|
||||
() => form.validateFields({ recursive: true }),
|
||||
100
|
||||
@@ -203,7 +200,7 @@ const NodeInspector: FC = () => {
|
||||
node.input?.forEach((v, i) => {
|
||||
let desc: string;
|
||||
const inputDef = node.def.input;
|
||||
if (inputDef && i >= inputDef.length && isVariadic(inputDef, inputDef.length - 1)) {
|
||||
if (inputDef && i >= inputDef.length && isVariadic(inputDef, -1)) {
|
||||
desc = inputDef[inputDef.length - 1];
|
||||
} else {
|
||||
desc = inputDef?.[i] ?? "<unknown>";
|
||||
@@ -215,7 +212,7 @@ const NodeInspector: FC = () => {
|
||||
node.output?.forEach((v, i) => {
|
||||
let desc: string;
|
||||
const outputDef = node.def.output;
|
||||
if (outputDef && i >= outputDef.length && isVariadic(outputDef, outputDef.length - 1)) {
|
||||
if (outputDef && i >= outputDef.length && isVariadic(outputDef, -1)) {
|
||||
desc = outputDef[outputDef.length - 1];
|
||||
} else {
|
||||
desc = outputDef?.[i] ?? "<unknown>";
|
||||
|
||||
@@ -5,7 +5,7 @@ import * as fs from "fs";
|
||||
import React from "react";
|
||||
import { create } from "zustand";
|
||||
import { NodeDef } from "../behavior3/src/behavior3";
|
||||
import { NodeModel, TreeGraphData, TreeModel } from "../misc/b3type";
|
||||
import { NodeModel, TreeGraphData, TreeModel, VarDef } from "../misc/b3type";
|
||||
import * as b3util from "../misc/b3util";
|
||||
import { message } from "../misc/hooks";
|
||||
import i18n from "../misc/i18n";
|
||||
@@ -49,6 +49,14 @@ export class EditorStore {
|
||||
name: string;
|
||||
firstid: number;
|
||||
|
||||
declare: {
|
||||
imports: {
|
||||
path: string;
|
||||
vars: VarDef[];
|
||||
}[];
|
||||
vars: VarDef[];
|
||||
};
|
||||
|
||||
autoId: number = 1;
|
||||
dragSrcId?: string;
|
||||
dragDstId?: string;
|
||||
@@ -78,6 +86,14 @@ export class EditorStore {
|
||||
this.export = file.export !== false;
|
||||
this.name = file.name || path.slice(0, -5);
|
||||
this.firstid = file.firstid ?? 1;
|
||||
this.declare = {
|
||||
vars: file.declare?.vars ?? [],
|
||||
imports:
|
||||
file.declare?.imports?.map((v) => ({
|
||||
path: v,
|
||||
vars: [],
|
||||
})) ?? [],
|
||||
};
|
||||
this.autoId = b3util.refreshTreeDataId(this.data, this.firstid);
|
||||
this.historyStack.push(b3util.createNode(this.data));
|
||||
this.historyIndex = 0;
|
||||
|
||||
@@ -25,12 +25,21 @@ export interface NodeModel {
|
||||
path?: string;
|
||||
}
|
||||
|
||||
export interface VarDef {
|
||||
name: string;
|
||||
desc: string;
|
||||
}
|
||||
|
||||
export interface TreeModel {
|
||||
name: string;
|
||||
desc?: string;
|
||||
export?: boolean;
|
||||
firstid?: number;
|
||||
root: NodeModel;
|
||||
declare?: {
|
||||
imports?: string[];
|
||||
vars?: VarDef[];
|
||||
};
|
||||
}
|
||||
|
||||
export interface TreeGraphData extends G6TreeGraphData {
|
||||
|
||||
+13
-12
@@ -71,7 +71,8 @@ export const isNodeEqual = (node1: NodeModel, node2: NodeModel) => {
|
||||
}
|
||||
|
||||
if (def.input?.length) {
|
||||
for (let i = 0; i < def.input.length; i++) {
|
||||
const len = Math.max(node1.input?.length ?? 0, node2.input?.length ?? 0);
|
||||
for (let i = 0; i < len; i++) {
|
||||
if (node1.input?.[i] !== node2.input?.[i]) {
|
||||
return false;
|
||||
}
|
||||
@@ -79,7 +80,8 @@ export const isNodeEqual = (node1: NodeModel, node2: NodeModel) => {
|
||||
}
|
||||
|
||||
if (def.output?.length) {
|
||||
for (let i = 0; i < def.output.length; i++) {
|
||||
const len = Math.max(node1.output?.length ?? 0, node2.output?.length ?? 0);
|
||||
for (let i = 0; i < len; i++) {
|
||||
if (node1.output?.[i] !== node2.output?.[i]) {
|
||||
return false;
|
||||
}
|
||||
@@ -510,16 +512,15 @@ export const checkChildrenLimit = (data: TreeGraphData) => {
|
||||
return true;
|
||||
};
|
||||
|
||||
const isValidInputOrOutput = (
|
||||
inputDef: string[],
|
||||
inputData: string[] | undefined,
|
||||
index: number
|
||||
) => {
|
||||
return (
|
||||
inputDef[index].includes("?") ||
|
||||
inputData?.[index] ||
|
||||
(index === inputDef.length - 1 && inputDef[index].endsWith("..."))
|
||||
);
|
||||
export const isVariadic = (def: string[], i: number) => {
|
||||
if (i === -1) {
|
||||
i = def.length - 1;
|
||||
}
|
||||
return def[i].endsWith("...") && i === def.length - 1;
|
||||
};
|
||||
|
||||
const isValidInputOrOutput = (def: string[], data: string[] | undefined, index: number) => {
|
||||
return def[index].includes("?") || data?.[index] || (isVariadic(def, index) && data?.[index]);
|
||||
};
|
||||
|
||||
export const checkTreeData = (data: TreeGraphData) => {
|
||||
|
||||
Reference in new issue
Block a user