optimize import path
This commit is contained in:
1 parent
8bce01dd66
commit
cd84575197
15 files changed
+186
-229
No files matched your search
+14
-14
@@ -1,17 +1,3 @@
|
||||
import {
|
||||
EditEvent,
|
||||
EditNode,
|
||||
EditTree,
|
||||
EditorStore,
|
||||
useWorkspace,
|
||||
} from "@/contexts/workspace-context";
|
||||
import { NodeModel, TreeGraphData, TreeModel } from "@/misc/b3type";
|
||||
import * as b3util from "@/misc/b3util";
|
||||
import { message } from "@/misc/hooks";
|
||||
import i18n from "@/misc/i18n";
|
||||
import { Hotkey, isMacos, useKeyDown } from "@/misc/keys";
|
||||
import Path from "@/misc/path";
|
||||
import { mergeClassNames, readJson } from "@/misc/util";
|
||||
import { ArrowDownOutlined, ArrowUpOutlined, CloseOutlined } from "@ant-design/icons";
|
||||
import G6, { G6GraphEvent, Item, TreeGraph } from "@antv/g6";
|
||||
import { dialog } from "@electron/remote";
|
||||
@@ -27,6 +13,20 @@ import { RiFocus3Line } from "react-icons/ri";
|
||||
import { VscCaseSensitive } from "react-icons/vsc";
|
||||
import { mergeRefs } from "react-merge-refs";
|
||||
import { useDebounceCallback } from "usehooks-ts";
|
||||
import {
|
||||
EditEvent,
|
||||
EditNode,
|
||||
EditTree,
|
||||
EditorStore,
|
||||
useWorkspace,
|
||||
} from "../contexts/workspace-context";
|
||||
import { NodeModel, TreeGraphData, TreeModel } from "../misc/b3type";
|
||||
import * as b3util from "../misc/b3util";
|
||||
import { message } from "../misc/hooks";
|
||||
import i18n from "../misc/i18n";
|
||||
import { Hotkey, isMacos, useKeyDown } from "../misc/keys";
|
||||
import Path from "../misc/path";
|
||||
import { mergeClassNames, readJson } from "../misc/util";
|
||||
import "./register-node";
|
||||
import { calcTreeDataSize } from "./register-node";
|
||||
|
||||
|
||||
@@ -1,10 +1,3 @@
|
||||
import { FileTreeType, useWorkspace } from "@/contexts/workspace-context";
|
||||
import { NodeDef, getNodeType } from "@/misc/b3type";
|
||||
import * as b3util from "@/misc/b3util";
|
||||
import { modal } from "@/misc/hooks";
|
||||
import i18n from "@/misc/i18n";
|
||||
import { Hotkey, isMacos, useKeyDown } from "@/misc/keys";
|
||||
import Path from "@/misc/path";
|
||||
import { DownOutlined } from "@ant-design/icons";
|
||||
import { Button, Dropdown, Flex, FlexProps, Input, MenuProps, Space, Tree } from "antd";
|
||||
import { ItemType } from "antd/es/menu/interface";
|
||||
@@ -17,6 +10,13 @@ import { FaExclamationTriangle, FaSwatchbook } from "react-icons/fa";
|
||||
import { FiCommand, FiDelete } from "react-icons/fi";
|
||||
import { IoMdReturnLeft } from "react-icons/io";
|
||||
import { PiTreeStructureFill } from "react-icons/pi";
|
||||
import { FileTreeType, useWorkspace } from "../contexts/workspace-context";
|
||||
import { NodeDef, getNodeType } from "../misc/b3type";
|
||||
import * as b3util from "../misc/b3util";
|
||||
import { modal } from "../misc/hooks";
|
||||
import i18n from "../misc/i18n";
|
||||
import { Hotkey, isMacos, useKeyDown } from "../misc/keys";
|
||||
import Path from "../misc/path";
|
||||
|
||||
const { DirectoryTree } = Tree;
|
||||
|
||||
|
||||
@@ -1,25 +1,3 @@
|
||||
import { EditNode, EditTree, useWorkspace } from "@/contexts/workspace-context";
|
||||
import {
|
||||
isBoolType,
|
||||
isEnumType,
|
||||
isExprType,
|
||||
isFloatType,
|
||||
isIntType,
|
||||
isJsonType,
|
||||
isStringType,
|
||||
NodeModel,
|
||||
TreeGraphData,
|
||||
} from "@/misc/b3type";
|
||||
import {
|
||||
checkNodeArgValue,
|
||||
checkOneof,
|
||||
getNodeArgRawType,
|
||||
isNodeArgArray,
|
||||
isNodeArgOptional,
|
||||
isValidVariableName,
|
||||
} from "@/misc/b3util";
|
||||
import { Hotkey, isMacos } from "@/misc/keys";
|
||||
import { mergeClassNames } from "@/misc/util";
|
||||
import { EditOutlined, MinusCircleOutlined, PlusOutlined } from "@ant-design/icons";
|
||||
import {
|
||||
AutoComplete,
|
||||
@@ -38,6 +16,29 @@ import { FC, useEffect, useMemo } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import Markdown from "react-markdown";
|
||||
import { useDebounceCallback } from "usehooks-ts";
|
||||
import { EditNode, EditTree, useWorkspace } from "../contexts/workspace-context";
|
||||
import {
|
||||
isBoolType,
|
||||
isEnumType,
|
||||
isExprType,
|
||||
isFloatType,
|
||||
isIntType,
|
||||
isJsonType,
|
||||
isStringType,
|
||||
NodeModel,
|
||||
TreeGraphData,
|
||||
} from "../misc/b3type";
|
||||
import {
|
||||
checkNodeArgValue,
|
||||
checkOneof,
|
||||
getNodeArgRawType,
|
||||
isNodeArgArray,
|
||||
isNodeArgOptional,
|
||||
isValidVariableName,
|
||||
nodeDefs,
|
||||
} from "../misc/b3util";
|
||||
import { Hotkey, isMacos } from "../misc/keys";
|
||||
import { mergeClassNames } from "../misc/util";
|
||||
|
||||
interface OptionType extends DefaultOptionType {
|
||||
value: string;
|
||||
@@ -99,7 +100,6 @@ const NodeInspector: FC = () => {
|
||||
const workspace = {
|
||||
editing: useWorkspace((state) => state.editing),
|
||||
editingNode: useWorkspace((state) => state.editingNode)!,
|
||||
getNodeDef: useWorkspace((state) => state.getNodeDef),
|
||||
nodeDefs: useWorkspace((state) => state.nodeDefs),
|
||||
onEditingNode: useWorkspace((state) => state.onEditingNode),
|
||||
allFiles: useWorkspace((state) => state.allFiles),
|
||||
@@ -121,7 +121,7 @@ const NodeInspector: FC = () => {
|
||||
// set form values
|
||||
useEffect(() => {
|
||||
const data = workspace.editingNode.data;
|
||||
const def = workspace.getNodeDef(workspace.editingNode.data.name);
|
||||
const def = nodeDefs.get(workspace.editingNode.data.name);
|
||||
form.resetFields();
|
||||
form.setFieldValue("id", data.id);
|
||||
form.setFieldValue("name", data.name);
|
||||
@@ -237,7 +237,7 @@ const NodeInspector: FC = () => {
|
||||
}, [workspace.allFiles, workspace.fileTree]);
|
||||
|
||||
const editingNode = workspace.editingNode;
|
||||
const def = workspace.getNodeDef(editingNode.data.name);
|
||||
const def = nodeDefs.get(editingNode.data.name);
|
||||
const disabled = !editingNode.editable;
|
||||
|
||||
// update value
|
||||
|
||||
+6
-53
@@ -1,18 +1,5 @@
|
||||
import { useSetting } from "@/contexts/setting-context";
|
||||
import { useWorkspace } from "@/contexts/workspace-context";
|
||||
import * as b3util from "@/misc/b3util";
|
||||
import i18n from "@/misc/i18n";
|
||||
import { Hotkey, isMacos, sendInputEvent } from "@/misc/keys";
|
||||
import Path from "@/misc/path";
|
||||
import { CheckOutlined } from "@ant-design/icons";
|
||||
import {
|
||||
Menu as AppMenu,
|
||||
BrowserWindow,
|
||||
app,
|
||||
dialog,
|
||||
getCurrentWindow,
|
||||
getGlobal,
|
||||
} from "@electron/remote";
|
||||
import { Menu as AppMenu, BrowserWindow, app, dialog } from "@electron/remote";
|
||||
import { Button, DropDownProps, Dropdown, Flex, FlexProps, LayoutProps, Space } from "antd";
|
||||
import { ItemType } from "antd/es/menu/interface";
|
||||
import { ipcRenderer } from "electron";
|
||||
@@ -21,6 +8,11 @@ import * as fs from "fs";
|
||||
import { FC, useMemo, useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { PiTreeStructureFill } from "react-icons/pi";
|
||||
import { useSetting } from "../contexts/setting-context";
|
||||
import { useWorkspace } from "../contexts/workspace-context";
|
||||
import * as b3util from "../misc/b3util";
|
||||
import i18n from "../misc/i18n";
|
||||
import { Hotkey, isMacos, sendInputEvent } from "../misc/keys";
|
||||
|
||||
const MenuItemLabel: FC<FlexProps> = (itemProps) => {
|
||||
return (
|
||||
@@ -45,45 +37,6 @@ ipcRenderer.on("refresh-app-men", () => {
|
||||
useSetting.getState().load();
|
||||
});
|
||||
|
||||
ipcRenderer.on("build-project", (_, project, buildDir) => {
|
||||
const mainConsole = getGlobal("console") as Console;
|
||||
try {
|
||||
let hasError = false;
|
||||
project = Path.posixPath(project);
|
||||
buildDir = Path.posixPath(buildDir);
|
||||
if (!project.endsWith(".b3-workspace")) {
|
||||
throw new Error(`'${project}' is not a workspace`);
|
||||
}
|
||||
const workspace = useWorkspace.getState();
|
||||
workspace.workdir = Path.dirname(project);
|
||||
workspace.loadNodeDefs();
|
||||
for (const path of Path.ls(Path.dirname(project), true)) {
|
||||
if (path.endsWith(".json")) {
|
||||
const buildpath = buildDir + "/" + path.substring(workspace.workdir.length + 1);
|
||||
const treeModel = b3util.createBuildData(path);
|
||||
if (treeModel && treeModel.export === false) {
|
||||
mainConsole.log("skip:", buildpath);
|
||||
continue;
|
||||
}
|
||||
mainConsole.log("build:", buildpath);
|
||||
if (!b3util.checkNodeData(treeModel?.root)) {
|
||||
hasError = true;
|
||||
}
|
||||
fs.mkdirSync(Path.dirname(buildpath), { recursive: true });
|
||||
fs.writeFileSync(buildpath, JSON.stringify(treeModel, null, 2));
|
||||
}
|
||||
}
|
||||
if (hasError) {
|
||||
mainConsole.error(i18n.t("buildFailed"));
|
||||
} else {
|
||||
mainConsole.log(i18n.t("buildCompleted"));
|
||||
}
|
||||
} catch (error) {
|
||||
mainConsole.error(i18n.t("buildFailed"));
|
||||
}
|
||||
getCurrentWindow().close();
|
||||
});
|
||||
|
||||
export const Menu: FC<LayoutProps> = () => {
|
||||
const { t } = useTranslation();
|
||||
const [trigger, setTrigger] = useState<DropDownProps["trigger"]>(["click"]);
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import { useWorkspace } from "@/contexts/workspace-context";
|
||||
import { TreeGraphData, getNodeType } from "@/misc/b3type";
|
||||
import { checkTreeData } from "@/misc/b3util";
|
||||
|
||||
import i18n from "@/misc/i18n";
|
||||
import { isMacos } from "@/misc/keys";
|
||||
import G6 from "@antv/g6";
|
||||
import { TreeGraphData, getNodeType } from "../misc/b3type";
|
||||
import { checkTreeData, nodeDefs, workdir } from "../misc/b3util";
|
||||
import i18n from "../misc/i18n";
|
||||
import { isMacos } from "../misc/keys";
|
||||
|
||||
let ctx: CanvasRenderingContext2D | null = null;
|
||||
let defaultFontSize = "";
|
||||
@@ -142,12 +140,11 @@ G6.registerNode(
|
||||
},
|
||||
},
|
||||
draw(cfg, group) {
|
||||
const workspace = useWorkspace.getState();
|
||||
const nodeDef = workspace.getNodeDef(cfg.name as string);
|
||||
const nodeDef = nodeDefs.get(cfg.name as string);
|
||||
let classify = getNodeType(nodeDef);
|
||||
let color = nodeDef.color || NODE_COLORS[classify] || NODE_COLORS["Other"];
|
||||
if (
|
||||
!workspace.hasNodeDef(cfg.name as string) ||
|
||||
!nodeDefs.has(cfg.name as string) ||
|
||||
(cfg.path && (!cfg.children || (cfg.children as []).length === 0)) ||
|
||||
!checkTreeData(cfg as TreeGraphData)
|
||||
) {
|
||||
@@ -259,9 +256,7 @@ G6.registerNode(
|
||||
});
|
||||
|
||||
// icon
|
||||
const img = nodeDef.icon
|
||||
? `file:///${workspace.workdir}/${nodeDef.icon}`
|
||||
: `./icons/${classify}.svg`;
|
||||
const img = nodeDef.icon ? `file:///${workdir}/${nodeDef.icon}` : `./icons/${classify}.svg`;
|
||||
addShape("image", {
|
||||
attrs: {
|
||||
x: 5,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { useSetting } from "@/contexts/setting-context";
|
||||
import { message, setGlobalHooks } from "@/misc/hooks";
|
||||
import { FC } from "react";
|
||||
import { useSetting } from "../contexts/setting-context";
|
||||
import { message, setGlobalHooks } from "../misc/hooks";
|
||||
|
||||
export const Setup: FC = () => {
|
||||
if (!message) {
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { useWorkspace } from "@/contexts/workspace-context";
|
||||
import { NodeDef } from "@/misc/b3type";
|
||||
import { Hotkey, isMacos } from "@/misc/keys";
|
||||
import Path from "@/misc/path";
|
||||
import { SearchOutlined } from "@ant-design/icons";
|
||||
import { Button, Flex, LayoutProps, Select } from "antd";
|
||||
import React, { FC, useMemo } from "react";
|
||||
import { useWorkspace } from "../contexts/workspace-context";
|
||||
import { NodeDef } from "../misc/b3type";
|
||||
import { Hotkey, isMacos } from "../misc/keys";
|
||||
import Path from "../misc/path";
|
||||
import { Menu } from "./menu";
|
||||
|
||||
interface OptionType {
|
||||
|
||||
@@ -1,8 +1,3 @@
|
||||
import { useSetting } from "@/contexts/setting-context";
|
||||
import { EditorStore, useWorkspace } from "@/contexts/workspace-context";
|
||||
import { modal } from "@/misc/hooks";
|
||||
import { Hotkey, isMacos, setInputFocus, useKeyDown } from "@/misc/keys";
|
||||
import Path from "@/misc/path";
|
||||
import { app } from "@electron/remote";
|
||||
import { useKeyPress } from "ahooks";
|
||||
import { Button, Flex, Layout, Space, Tabs, Tag, Tooltip } from "antd";
|
||||
@@ -13,6 +8,11 @@ import { PiTreeStructureFill } from "react-icons/pi";
|
||||
import { VscNewFolder, VscRepo } from "react-icons/vsc";
|
||||
import useForceUpdate from "use-force-update";
|
||||
import { useWindowSize } from "usehooks-ts";
|
||||
import { useSetting } from "../contexts/setting-context";
|
||||
import { EditorStore, useWorkspace } from "../contexts/workspace-context";
|
||||
import { modal } from "../misc/hooks";
|
||||
import { Hotkey, isMacos, setInputFocus, useKeyDown } from "../misc/keys";
|
||||
import Path from "../misc/path";
|
||||
import { Editor } from "./editor";
|
||||
import { Explorer } from "./explorer";
|
||||
import { Inspector } from "./inspector";
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { readJson, writeJson } from "@/misc/util";
|
||||
import { app } from "@electron/remote";
|
||||
import * as fs from "fs";
|
||||
import { create } from "zustand";
|
||||
import { readJson, writeJson } from "../misc/util";
|
||||
|
||||
const settingPath = app.getPath("userData") + "/settings.json";
|
||||
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
import { NodeDef, NodeModel, TreeGraphData, TreeModel, unknownNodeDef } from "@/misc/b3type";
|
||||
import * as b3util from "@/misc/b3util";
|
||||
import { message } from "@/misc/hooks";
|
||||
import i18n from "@/misc/i18n";
|
||||
import Path from "@/misc/path";
|
||||
import { readJson, writeJson } from "@/misc/util";
|
||||
import { Matrix, TreeGraph } from "@antv/g6";
|
||||
import { BrowserWindow, dialog } from "@electron/remote";
|
||||
import { ipcRenderer } from "electron";
|
||||
import * as fs from "fs";
|
||||
import React from "react";
|
||||
import { create } from "zustand";
|
||||
import { NodeDef, NodeModel, TreeGraphData, TreeModel } from "../misc/b3type";
|
||||
import * as b3util from "../misc/b3util";
|
||||
import { message } from "../misc/hooks";
|
||||
import i18n from "../misc/i18n";
|
||||
import Path from "../misc/path";
|
||||
import { zhNodeDef } from "../misc/template";
|
||||
import { readJson, writeJson } from "../misc/util";
|
||||
import { useSetting } from "./setting-context";
|
||||
|
||||
let buildDir: string | undefined;
|
||||
@@ -151,7 +152,9 @@ export type WorkspaceStore = {
|
||||
|
||||
watch(): void;
|
||||
loadTrees: () => void;
|
||||
|
||||
loadNodeDefs: () => void;
|
||||
nodeDefs: Map<string, NodeDef>;
|
||||
|
||||
// edit node
|
||||
editingNode?: EditNode | null;
|
||||
@@ -164,11 +167,6 @@ export type WorkspaceStore = {
|
||||
// edit tree
|
||||
editingTree?: EditTree | null;
|
||||
onEditingTree: (editor: EditorStore) => void;
|
||||
|
||||
// node setting
|
||||
nodeDefs: Map<string, NodeDef>;
|
||||
getNodeDef: (name: string) => NodeDef;
|
||||
hasNodeDef: (name: string) => boolean;
|
||||
};
|
||||
|
||||
const loadFileTree = (workdir: string, filename: string) => {
|
||||
@@ -249,7 +247,48 @@ export const useWorkspace = create<WorkspaceStore>((set, get) => ({
|
||||
});
|
||||
if (path) {
|
||||
const workspace = get();
|
||||
b3util.createProject(path);
|
||||
fs.writeFileSync(Path.dirname(path) + "/node-config.b3-setting", zhNodeDef());
|
||||
fs.writeFileSync(
|
||||
Path.dirname(path) + "/example.json",
|
||||
JSON.stringify(
|
||||
{
|
||||
name: "example",
|
||||
root: {
|
||||
id: 1,
|
||||
name: "Sequence",
|
||||
children: [
|
||||
{
|
||||
id: 2,
|
||||
name: "Log",
|
||||
args: {
|
||||
str: "hello",
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
name: "Wait",
|
||||
args: {
|
||||
time: 1,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
null,
|
||||
2
|
||||
)
|
||||
);
|
||||
fs.writeFileSync(
|
||||
path,
|
||||
JSON.stringify(
|
||||
{
|
||||
nodeConf: "node-config.b3-setting",
|
||||
metadata: [],
|
||||
},
|
||||
null,
|
||||
2
|
||||
)
|
||||
);
|
||||
workspace.init(path);
|
||||
}
|
||||
},
|
||||
@@ -569,14 +608,11 @@ export const useWorkspace = create<WorkspaceStore>((set, get) => ({
|
||||
}
|
||||
},
|
||||
|
||||
nodeDefs: new Map(),
|
||||
loadNodeDefs: () => {
|
||||
const workspace = get();
|
||||
const nodeDefData = readJson(`${workspace.workdir}/node-config.b3-setting`) as NodeDef[];
|
||||
const nodeDefs: Map<string, NodeDef> = new Map();
|
||||
for (const v of nodeDefData) {
|
||||
nodeDefs.set(v.name, v);
|
||||
}
|
||||
set({ nodeDefs });
|
||||
b3util.initWorkdir(workspace.workdir, message.error.bind(message));
|
||||
set({ nodeDefs: b3util.nodeDefs });
|
||||
workspace.editing?.dispatch("refresh");
|
||||
},
|
||||
|
||||
@@ -616,16 +652,4 @@ export const useWorkspace = create<WorkspaceStore>((set, get) => ({
|
||||
editingNode: null,
|
||||
});
|
||||
},
|
||||
|
||||
// node def
|
||||
nodeDefs: new Map(),
|
||||
getNodeDef: (name) => {
|
||||
const workspace = get();
|
||||
unknownNodeDef.desc = i18n.t("node.unknown.desc");
|
||||
return workspace.nodeDefs.get(name) || unknownNodeDef;
|
||||
},
|
||||
hasNodeDef: (name) => {
|
||||
const workspace = get();
|
||||
return workspace.nodeDefs.has(name);
|
||||
},
|
||||
}));
|
||||
@@ -122,12 +122,6 @@ export interface TreeGraphData extends G6TreeGraphData {
|
||||
status?: number;
|
||||
}
|
||||
|
||||
export const unknownNodeDef: NodeDef = {
|
||||
name: "unknown",
|
||||
desc: "新建节点",
|
||||
type: "Action",
|
||||
};
|
||||
|
||||
export const getNodeType = (def: NodeDef): NodeType => {
|
||||
const type = def.type.toLocaleLowerCase().toString();
|
||||
if (type.startsWith("action")) {
|
||||
|
||||
+34
-59
@@ -1,4 +1,4 @@
|
||||
import { useWorkspace } from "@/contexts/workspace-context";
|
||||
import * as fs from "fs";
|
||||
import {
|
||||
isBoolType,
|
||||
isEnumType,
|
||||
@@ -12,12 +12,33 @@ import {
|
||||
NodeModel,
|
||||
TreeGraphData,
|
||||
TreeModel,
|
||||
unknownNodeDef,
|
||||
} from "@/misc/b3type";
|
||||
import * as fs from "fs";
|
||||
import { message } from "./hooks";
|
||||
} from "./b3type";
|
||||
import Path from "./path";
|
||||
import { zhNodeDef } from "./template";
|
||||
import { readJson } from "./util";
|
||||
|
||||
export let workdir: string = "";
|
||||
let alertError: (msg: string, duration?: number) => void = () => {};
|
||||
|
||||
const unknownNodeDef: NodeDef = {
|
||||
name: "unknown",
|
||||
desc: "",
|
||||
type: "Action",
|
||||
};
|
||||
|
||||
export const nodeDefs = new (class extends Map<string, NodeDef> {
|
||||
get(key: string): NodeDef {
|
||||
return super.get(key) ?? unknownNodeDef;
|
||||
}
|
||||
})();
|
||||
|
||||
export const initWorkdir = (path: string, handler: typeof alertError) => {
|
||||
workdir = path;
|
||||
alertError = handler;
|
||||
const nodeDefData = readJson(`${workdir}/node-config.b3-setting`) as NodeDef[];
|
||||
for (const v of nodeDefData) {
|
||||
nodeDefs.set(v.name, v);
|
||||
}
|
||||
};
|
||||
|
||||
export const isValidVariableName = (name: string) => {
|
||||
return /^[a-zA-Z_]/.test(name);
|
||||
@@ -35,7 +56,7 @@ export const isNodeEqual = (node1: NodeModel, node2: NodeModel) => {
|
||||
node1.debug === node2.debug &&
|
||||
node1.disabled === node2.disabled
|
||||
) {
|
||||
const def = useWorkspace.getState().getNodeDef(node1.name);
|
||||
const def = nodeDefs.get(node1.name);
|
||||
|
||||
for (const arg of def.args ?? []) {
|
||||
if (node1.args?.[arg.name] !== node2.args?.[arg.name]) {
|
||||
@@ -208,7 +229,7 @@ export const checkNodeData = (data: NodeModel | null | undefined) => {
|
||||
if (!data) {
|
||||
return false;
|
||||
}
|
||||
const conf = useWorkspace.getState().getNodeDef(data.name);
|
||||
const conf = nodeDefs.get(data.name);
|
||||
if (conf.name === unknownNodeDef.name) {
|
||||
error(data, `undefined node: ${data.name}`);
|
||||
return false;
|
||||
@@ -530,7 +551,6 @@ export const createTreeData = (
|
||||
parent?: string,
|
||||
calcSize?: (d: TreeGraphData) => number[]
|
||||
) => {
|
||||
const workspace = useWorkspace.getState();
|
||||
let treeData: TreeGraphData = {
|
||||
id: node.id.toFixed(),
|
||||
name: node.name,
|
||||
@@ -540,7 +560,7 @@ export const createTreeData = (
|
||||
output: node.output,
|
||||
debug: node.debug,
|
||||
disabled: node.disabled,
|
||||
def: workspace.getNodeDef(node.name),
|
||||
def: nodeDefs.get(node.name),
|
||||
parent: parent,
|
||||
};
|
||||
|
||||
@@ -570,12 +590,12 @@ export const createTreeData = (
|
||||
if (calcSize) {
|
||||
treeData.size = calcSize(treeData);
|
||||
}
|
||||
message.error(`循环引用节点:${node.path}`, 4);
|
||||
alertError(`循环引用节点:${node.path}`, 4);
|
||||
return treeData;
|
||||
}
|
||||
parsingStack.push(node.path);
|
||||
try {
|
||||
const subtreePath = workspace.workdir + "/" + node.path;
|
||||
const subtreePath = workdir + "/" + node.path;
|
||||
const str = fs.readFileSync(subtreePath, "utf8");
|
||||
treeData = createTreeData(JSON.parse(str).root, treeData.id, calcSize);
|
||||
treeData.lastModified = fs.statSync(subtreePath).mtimeMs;
|
||||
@@ -588,7 +608,7 @@ export const createTreeData = (
|
||||
treeData.size = calcSize(treeData);
|
||||
}
|
||||
} catch (e) {
|
||||
message.error(`解析子树失败:${node.path}`);
|
||||
alertError(`解析子树失败:${node.path}`);
|
||||
console.log("parse subtree:", e);
|
||||
}
|
||||
parsingStack.pop();
|
||||
@@ -623,7 +643,7 @@ export const createFileData = (data: TreeGraphData, includeSubtree?: boolean) =>
|
||||
disabled: data.disabled || undefined,
|
||||
path: data.path || undefined,
|
||||
};
|
||||
const conf = useWorkspace.getState().getNodeDef(data.name);
|
||||
const conf = nodeDefs.get(data.name);
|
||||
if (!conf.input?.length) {
|
||||
nodeData.input = undefined;
|
||||
}
|
||||
@@ -657,48 +677,3 @@ export const createNewTree = (path: string) => {
|
||||
export const isTreeFile = (path: string) => {
|
||||
return path.toLocaleLowerCase().endsWith(".json");
|
||||
};
|
||||
|
||||
export const createProject = (path: string) => {
|
||||
fs.writeFileSync(Path.dirname(path) + "/node-config.b3-setting", zhNodeDef());
|
||||
fs.writeFileSync(
|
||||
Path.dirname(path) + "/example.json",
|
||||
JSON.stringify(
|
||||
{
|
||||
name: "example",
|
||||
root: {
|
||||
id: 1,
|
||||
name: "Sequence",
|
||||
children: [
|
||||
{
|
||||
id: 2,
|
||||
name: "Log",
|
||||
args: {
|
||||
str: "hello",
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
name: "Wait",
|
||||
args: {
|
||||
time: 1,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
null,
|
||||
2
|
||||
)
|
||||
);
|
||||
fs.writeFileSync(
|
||||
path,
|
||||
JSON.stringify(
|
||||
{
|
||||
nodeConf: "node-config.b3-setting",
|
||||
metadata: [],
|
||||
},
|
||||
null,
|
||||
2
|
||||
)
|
||||
);
|
||||
};
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Context, Node, NodeDef } from "@/behavior3/src/behavior3";
|
||||
import { DeepReadonly } from "../behavior3/src/behavior3/context";
|
||||
import { Node, NodeDef } from "../behavior3/src/behavior3";
|
||||
import { Context, DeepReadonly } from "../behavior3/src/behavior3/context";
|
||||
|
||||
export const zhNodeDef = () => {
|
||||
const context = new (class extends Context {
|
||||
|
||||
Reference in new issue
Block a user