format code

This commit is contained in:
codetypes committed 2024-04-30 15:51:36 +08:00
1 parent d32c457990
commit 8b9e5b963f
6 files changed
+44 -35

No files matched your search

+29 -26
View File
@@ -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;
@@ -148,7 +148,7 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
filterCase: false, filterCase: false,
filterFocus: false, filterFocus: false,
filterType: "", filterType: "",
placeholder: "" placeholder: "",
}); });
const onSearchChange = (option: FilterOption) => { const onSearchChange = (option: FilterOption) => {
@@ -238,10 +238,13 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
let found = false; let found = false;
if (option.filterType === "nodeId") { if (option.filterType === "nodeId") {
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) {
@@ -1091,40 +1094,40 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
}; };
const searchByType = (type: string) => { const searchByType = (type: string) => {
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 "nodeId":
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) return searchIptRef.current?.focus();
setShowingSearch(false) setShowingSearch(false);
setTimeout(() => { setTimeout(() => {
setShowingSearch(true) setShowingSearch(true);
setFilterOption({ ...filterOption, placeholder, filterType }) setFilterOption({ ...filterOption, placeholder, filterType });
searchIptRef.current?.focus() searchIptRef.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("");
} else if ((e.ctrlKey || e.metaKey) && e.code === "KeyG") { } else if ((e.ctrlKey || e.metaKey) && e.code === "KeyG") {
searchByType("nodeId") searchByType("nodeId");
}
} }
};
return ( return (
<div <div
@@ -1249,7 +1252,7 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
filterFocus: false, filterFocus: false,
filterStr: "", filterStr: "",
filterType: "", filterType: "",
placeholder: "" placeholder: "",
}); });
keysRef.current?.focus(); keysRef.current?.focus();
}} }}
+1 -1
View File
@@ -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";
+11 -4
View File
@@ -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 -1
View File
@@ -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";
+1 -2
View File
@@ -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
View File
@@ -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);