Merge branch 'dev'
This commit is contained in:
commit
c1c96662fd
6 files changed
+59
-48
No files matched your search
+44
-39
@@ -11,6 +11,7 @@ import { message } from "@/misc/hooks";
|
|||||||
import i18n from "@/misc/i18n";
|
import i18n from "@/misc/i18n";
|
||||||
import { Hotkey, isHotkeyPressed, isMacos, useHotkeys } from "@/misc/keys";
|
import { Hotkey, isHotkeyPressed, isMacos, useHotkeys } from "@/misc/keys";
|
||||||
import Path from "@/misc/path";
|
import Path from "@/misc/path";
|
||||||
|
import { mergeClassNames } from "@/misc/util";
|
||||||
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, TreeGraph } from "@antv/g6";
|
||||||
import { dialog } from "@electron/remote";
|
import { dialog } from "@electron/remote";
|
||||||
@@ -18,7 +19,7 @@ import { useSize } from "ahooks";
|
|||||||
import { Button, Dropdown, Flex, FlexProps, Input, InputRef, MenuProps } from "antd";
|
import { Button, Dropdown, Flex, FlexProps, Input, InputRef, MenuProps } from "antd";
|
||||||
import { clipboard } from "electron";
|
import { clipboard } from "electron";
|
||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import React, { FC, KeyboardEvent, useCallback, useEffect, useMemo, useRef, useState } from "react";
|
import React, { FC, KeyboardEvent, useEffect, useMemo, useRef, useState } from "react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { FiDelete } from "react-icons/fi";
|
import { FiDelete } from "react-icons/fi";
|
||||||
import { IoMdReturnLeft } from "react-icons/io";
|
import { IoMdReturnLeft } from "react-icons/io";
|
||||||
@@ -27,7 +28,6 @@ import { VscCaseSensitive } from "react-icons/vsc";
|
|||||||
import { mergeRefs } from "react-merge-refs";
|
import { mergeRefs } from "react-merge-refs";
|
||||||
import { useDebounceCallback } from "usehooks-ts";
|
import { useDebounceCallback } from "usehooks-ts";
|
||||||
import "./register-node";
|
import "./register-node";
|
||||||
import { mergeClassNames } from "@/misc/util";
|
|
||||||
|
|
||||||
export interface EditorProps extends React.HTMLAttributes<HTMLElement> {
|
export interface EditorProps extends React.HTMLAttributes<HTMLElement> {
|
||||||
data: EditorStore;
|
data: EditorStore;
|
||||||
@@ -40,7 +40,7 @@ interface FilterOption {
|
|||||||
filterStr: string;
|
filterStr: string;
|
||||||
filterCase: boolean;
|
filterCase: boolean;
|
||||||
filterFocus: boolean;
|
filterFocus: boolean;
|
||||||
filterType: string;
|
filterType: "content" | "id";
|
||||||
placeholder: string;
|
placeholder: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -133,7 +133,7 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
|
|||||||
workdir: useWorkspace((state) => state.workdir),
|
workdir: useWorkspace((state) => state.workdir),
|
||||||
};
|
};
|
||||||
|
|
||||||
const searchIptRef = useRef<InputRef>(null);
|
const searchInputRef = useRef<InputRef>(null);
|
||||||
const graphRef = useRef(null);
|
const graphRef = useRef(null);
|
||||||
const sizeRef = useRef(null);
|
const sizeRef = useRef(null);
|
||||||
const editorSize = useSize(sizeRef);
|
const editorSize = useSize(sizeRef);
|
||||||
@@ -147,8 +147,8 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
|
|||||||
filterStr: "",
|
filterStr: "",
|
||||||
filterCase: false,
|
filterCase: false,
|
||||||
filterFocus: false,
|
filterFocus: false,
|
||||||
filterType: "",
|
filterType: "content",
|
||||||
placeholder: ""
|
placeholder: "",
|
||||||
});
|
});
|
||||||
|
|
||||||
const onSearchChange = (option: FilterOption) => {
|
const onSearchChange = (option: FilterOption) => {
|
||||||
@@ -236,12 +236,15 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
|
|||||||
node.highlightGray = option.filterFocus;
|
node.highlightGray = option.filterFocus;
|
||||||
if (option.filterStr) {
|
if (option.filterStr) {
|
||||||
let found = false;
|
let found = false;
|
||||||
if (option.filterType === "nodeId") {
|
if (option.filterType === "id") {
|
||||||
if (option.filterStr === node.id) {
|
if (option.filterStr === node.id) {
|
||||||
found = true
|
found = true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (includeString(node.name, option) || includeString(node.desc || node.def.desc, option)) {
|
if (
|
||||||
|
includeString(node.name, option) ||
|
||||||
|
includeString(node.desc || node.def.desc, option)
|
||||||
|
) {
|
||||||
found = true;
|
found = true;
|
||||||
} else if (node.input) {
|
} else if (node.input) {
|
||||||
for (const str of node.input) {
|
for (const str of node.input) {
|
||||||
@@ -1019,11 +1022,11 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "searchNode": {
|
case "searchNode": {
|
||||||
searchByType("");
|
searchByType("content");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "jumpNode": {
|
case "jumpNode": {
|
||||||
searchByType("nodeId");
|
searchByType("id");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "editSubtree": {
|
case "editSubtree": {
|
||||||
@@ -1090,41 +1093,43 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const searchByType = (type: string) => {
|
const searchByType = (type: FilterOption["filterType"]) => {
|
||||||
let placeholder = ""
|
let placeholder = "";
|
||||||
const filterType = type
|
const filterType = type;
|
||||||
// todo multiple parameter format judgment
|
// todo multiple parameter format judgment
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case "nodeId":
|
case "id":
|
||||||
placeholder = t("jumpNode")
|
placeholder = t("jumpNode");
|
||||||
break
|
break;
|
||||||
default:
|
default:
|
||||||
placeholder = t("searchNode")
|
placeholder = t("searchNode");
|
||||||
break
|
break;
|
||||||
}
|
}
|
||||||
if (!showingSearch) {
|
if (!showingSearch) {
|
||||||
setFilterOption({ ...filterOption, placeholder, filterType })
|
setFilterOption({ ...filterOption, placeholder, filterType });
|
||||||
setShowingSearch(true)
|
setShowingSearch(true);
|
||||||
return
|
return;
|
||||||
}
|
}
|
||||||
if (filterOption.filterType === type) return searchIptRef.current?.focus()
|
if (filterOption.filterType === type) {
|
||||||
setShowingSearch(false)
|
return searchInputRef.current?.focus();
|
||||||
|
}
|
||||||
|
setShowingSearch(false);
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
setShowingSearch(true)
|
setShowingSearch(true);
|
||||||
setFilterOption({ ...filterOption, placeholder, filterType })
|
setFilterOption({ ...filterOption, placeholder, filterType });
|
||||||
searchIptRef.current?.focus()
|
searchInputRef.current?.focus();
|
||||||
}, 50)
|
}, 50);
|
||||||
}
|
};
|
||||||
|
|
||||||
const handleKeyDown = (e: KeyboardEvent) => {
|
const handleKeyDown = (e: KeyboardEvent) => {
|
||||||
if (e.code === Hotkey.Enter) {
|
if (e.code === Hotkey.Enter) {
|
||||||
nextResult()
|
nextResult();
|
||||||
} else if ((e.ctrlKey || e.metaKey) && e.code === "KeyF") {
|
} else if ((e.ctrlKey || e.metaKey) && e.code === "KeyF") {
|
||||||
searchByType("")
|
searchByType("content");
|
||||||
} else if ((e.ctrlKey || e.metaKey) && e.code === "KeyG") {
|
} else if ((e.ctrlKey || e.metaKey) && e.code === "KeyG") {
|
||||||
searchByType("nodeId")
|
searchByType("id");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
@@ -1155,7 +1160,7 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Input
|
<Input
|
||||||
ref={searchIptRef}
|
ref={searchInputRef}
|
||||||
placeholder={filterOption.placeholder}
|
placeholder={filterOption.placeholder}
|
||||||
autoFocus
|
autoFocus
|
||||||
size="small"
|
size="small"
|
||||||
@@ -1175,7 +1180,7 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
|
|||||||
onKeyDown={handleKeyDown}
|
onKeyDown={handleKeyDown}
|
||||||
suffix={
|
suffix={
|
||||||
<Flex gap="2px" style={{ alignItems: "center" }}>
|
<Flex gap="2px" style={{ alignItems: "center" }}>
|
||||||
{filterOption.filterType !== "nodeId" && (
|
{filterOption.filterType !== "id" && (
|
||||||
<Button
|
<Button
|
||||||
type="text"
|
type="text"
|
||||||
size="small"
|
size="small"
|
||||||
@@ -1215,7 +1220,7 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
|
|||||||
? `${filterOption.index + 1}/${filterOption.results.length}`
|
? `${filterOption.index + 1}/${filterOption.results.length}`
|
||||||
: ""}
|
: ""}
|
||||||
</div>
|
</div>
|
||||||
{filterOption.filterType !== "nodeId" && (
|
{filterOption.filterType !== "id" && (
|
||||||
<Button
|
<Button
|
||||||
icon={<ArrowDownOutlined />}
|
icon={<ArrowDownOutlined />}
|
||||||
type="text"
|
type="text"
|
||||||
@@ -1225,7 +1230,7 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
|
|||||||
onClick={nextResult}
|
onClick={nextResult}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{filterOption.filterType !== "nodeId" && (
|
{filterOption.filterType !== "id" && (
|
||||||
<Button
|
<Button
|
||||||
icon={<ArrowUpOutlined />}
|
icon={<ArrowUpOutlined />}
|
||||||
type="text"
|
type="text"
|
||||||
@@ -1248,8 +1253,8 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
|
|||||||
filterCase: false,
|
filterCase: false,
|
||||||
filterFocus: false,
|
filterFocus: false,
|
||||||
filterStr: "",
|
filterStr: "",
|
||||||
filterType: "",
|
filterType: "content",
|
||||||
placeholder: ""
|
placeholder: "",
|
||||||
});
|
});
|
||||||
keysRef.current?.focus();
|
keysRef.current?.focus();
|
||||||
}}
|
}}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { EditNode, EditTree, FileTreeType, useWorkspace } from "@/contexts/workspace-context";
|
import { EditNode, EditTree, useWorkspace } from "@/contexts/workspace-context";
|
||||||
import { NodeArgType, NodeModel, TreeGraphData, TreeModel } from "@/misc/b3type";
|
import { NodeArgType, NodeModel, TreeGraphData, TreeModel } from "@/misc/b3type";
|
||||||
import { Hotkey, isMacos } from "@/misc/keys";
|
import { Hotkey, isMacos } from "@/misc/keys";
|
||||||
import Path from "@/misc/path";
|
import Path from "@/misc/path";
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import { app } from "@electron/remote";
|
|||||||
import { Button, Flex, Layout, Space, Tabs, Tag, Tooltip } from "antd";
|
import { Button, Flex, Layout, Space, Tabs, Tag, Tooltip } from "antd";
|
||||||
import { FC, useEffect, useState } from "react";
|
import { FC, useEffect, useState } from "react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { FaExclamationTriangle, FaRegFolderOpen } from "react-icons/fa";
|
import { FaExclamationTriangle } from "react-icons/fa";
|
||||||
import { PiTreeStructureFill } from "react-icons/pi";
|
import { PiTreeStructureFill } from "react-icons/pi";
|
||||||
import { VscNewFolder, VscRepo } from "react-icons/vsc";
|
import { VscNewFolder, VscRepo } from "react-icons/vsc";
|
||||||
import useForceUpdate from "use-force-update";
|
import useForceUpdate from "use-force-update";
|
||||||
@@ -44,7 +44,14 @@ export const Workspace: FC = () => {
|
|||||||
const { width = 0, height = 0 } = useWindowSize();
|
const { width = 0, height = 0 } = useWindowSize();
|
||||||
|
|
||||||
const keysRef = useHotkeys<HTMLDivElement>(
|
const keysRef = useHotkeys<HTMLDivElement>(
|
||||||
[Hotkey.Save, Hotkey.CloseEditor, Hotkey.SearchTree, Hotkey.Build, Hotkey.SearchNode, Hotkey.JumpNode],
|
[
|
||||||
|
Hotkey.Save,
|
||||||
|
Hotkey.CloseEditor,
|
||||||
|
Hotkey.SearchTree,
|
||||||
|
Hotkey.Build,
|
||||||
|
Hotkey.SearchNode,
|
||||||
|
Hotkey.JumpNode,
|
||||||
|
],
|
||||||
(event) => {
|
(event) => {
|
||||||
if (isHotkeyPressed(Hotkey.Save)) {
|
if (isHotkeyPressed(Hotkey.Save)) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
@@ -68,8 +75,8 @@ export const Workspace: FC = () => {
|
|||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
workspace.editing?.dispatch("searchNode");
|
workspace.editing?.dispatch("searchNode");
|
||||||
} else if (isHotkeyPressed(Hotkey.JumpNode)) {
|
} else if (isHotkeyPressed(Hotkey.JumpNode)) {
|
||||||
event.preventDefault()
|
event.preventDefault();
|
||||||
workspace.editing?.dispatch("jumpNode")
|
workspace.editing?.dispatch("jumpNode");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { readJson, writeJson } from "@/misc/util";
|
import { readJson, writeJson } from "@/misc/util";
|
||||||
import { app } from "@electron/remote";
|
import { app } from "@electron/remote";
|
||||||
import { create } from "zustand";
|
|
||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
|
import { create } from "zustand";
|
||||||
|
|
||||||
const settingPath = app.getPath("userData") + "/settings.json";
|
const settingPath = app.getPath("userData") + "/settings.json";
|
||||||
|
|
||||||
|
|||||||
@@ -389,8 +389,7 @@ export const useWorkspace = create<WorkspaceStore>((set, get) => ( {
|
|||||||
saveFile(workspace.editing);
|
saveFile(workspace.editing);
|
||||||
},
|
},
|
||||||
|
|
||||||
saveAs: () => {
|
saveAs: () => {},
|
||||||
},
|
|
||||||
|
|
||||||
saveAll: () => {
|
saveAll: () => {
|
||||||
const workspace = get();
|
const workspace = get();
|
||||||
|
|||||||
+1
-1
@@ -33,7 +33,7 @@ export function useHotkeys<T extends HTMLElement>(
|
|||||||
keys: Keys,
|
keys: Keys,
|
||||||
callback: HotkeyCallback,
|
callback: HotkeyCallback,
|
||||||
options?: OptionsOrDependencyArray,
|
options?: OptionsOrDependencyArray,
|
||||||
dependencies?: OptionsOrDependencyArray,
|
dependencies?: OptionsOrDependencyArray
|
||||||
): MutableRefObject<RefType<T>> {
|
): MutableRefObject<RefType<T>> {
|
||||||
if (keys instanceof Array) {
|
if (keys instanceof Array) {
|
||||||
keys = keys.filter((v) => !!v);
|
keys = keys.filter((v) => !!v);
|
||||||
|
|||||||
Reference in new issue
Block a user