update node layout

This commit is contained in:
codetypes committed 2025-04-16 22:41:13 +08:00
1 parent 3b1091cf87
commit 6894aacfd1
5 files changed
+25 -26

No files matched your search

+3 -3
View File
@@ -19,7 +19,7 @@ import {
useWorkspace, useWorkspace,
} from "../contexts/workspace-context"; } from "../contexts/workspace-context";
import i18n from "../misc/i18n"; import i18n from "../misc/i18n";
import { Hotkey, isMacos, useKeyDown } from "../misc/keys"; import { Hotkey, isMacos, useKeyPress } from "../misc/keys";
import { mergeClassNames } from "../misc/util"; import { mergeClassNames } from "../misc/util";
import { FilterOption, Graph } from "./graph"; import { FilterOption, Graph } from "./graph";
import "./register-node"; import "./register-node";
@@ -129,7 +129,7 @@ export const Editor: FC<EditorProps> = ({ onChange, data: editor, ...props }) =>
); );
const keysRef = useRef<HTMLDivElement>(null); const keysRef = useRef<HTMLDivElement>(null);
useKeyDown( useKeyPress(
[ [
Hotkey.Copy, Hotkey.Copy,
Hotkey.Replace, Hotkey.Replace,
@@ -148,7 +148,7 @@ export const Editor: FC<EditorProps> = ({ onChange, data: editor, ...props }) =>
} }
); );
useKeyDown([Hotkey.Undo, Hotkey.Redo], null, (e, key) => { useKeyPress([Hotkey.Undo, Hotkey.Redo], null, (e, key) => {
if (e.target instanceof HTMLInputElement || e.target instanceof HTMLTextAreaElement) { if (e.target instanceof HTMLInputElement || e.target instanceof HTMLTextAreaElement) {
return; return;
} }
+7 -7
View File
@@ -17,7 +17,7 @@ import { getNodeType } from "../misc/b3type";
import * as b3util from "../misc/b3util"; import * as b3util from "../misc/b3util";
import { modal } from "../misc/hooks"; import { modal } from "../misc/hooks";
import i18n from "../misc/i18n"; import i18n from "../misc/i18n";
import { Hotkey, isMacos, useKeyDown } from "../misc/keys"; import { Hotkey, isMacos, useKeyPress } from "../misc/keys";
import Path from "../misc/path"; import Path from "../misc/path";
const { DirectoryTree } = Tree; const { DirectoryTree } = Tree;
@@ -631,7 +631,7 @@ export const Explorer: FC = () => {
const keysRef = useRef<HTMLDivElement>(null); const keysRef = useRef<HTMLDivElement>(null);
useKeyDown([Hotkey.F2, isMacos ? Hotkey.Enter : ""], keysRef, (event) => { useKeyPress([Hotkey.F2, isMacos ? Hotkey.Enter : ""], keysRef, (event) => {
event.preventDefault(); event.preventDefault();
const node = findFile(selectedKeys[0], workspace.fileTree!); const node = findFile(selectedKeys[0], workspace.fileTree!);
if (node && node !== workspace.fileTree && !node.editing) { if (node && node !== workspace.fileTree && !node.editing) {
@@ -639,7 +639,7 @@ export const Explorer: FC = () => {
} }
}); });
useKeyDown([Hotkey.Delete, isMacos ? Hotkey.MacDelete : ""], keysRef, (event) => { useKeyPress([Hotkey.Delete, isMacos ? Hotkey.MacDelete : ""], keysRef, (event) => {
event.preventDefault(); event.preventDefault();
const node = findFile(selectedKeys[0], workspace.fileTree!); const node = findFile(selectedKeys[0], workspace.fileTree!);
if (node && node !== workspace.fileTree) { if (node && node !== workspace.fileTree) {
@@ -647,7 +647,7 @@ export const Explorer: FC = () => {
} }
}); });
useKeyDown(Hotkey.Escape, keysRef, (event) => { useKeyPress(Hotkey.Escape, keysRef, (event) => {
event.preventDefault(); event.preventDefault();
const node = findFile(selectedKeys[0], workspace.fileTree!); const node = findFile(selectedKeys[0], workspace.fileTree!);
if (node) { if (node) {
@@ -656,7 +656,7 @@ export const Explorer: FC = () => {
} }
}); });
useKeyDown(Hotkey.Duplicate, keysRef, (event) => { useKeyPress(Hotkey.Duplicate, keysRef, (event) => {
event.preventDefault(); event.preventDefault();
const node = findFile(selectedKeys[0], workspace.fileTree!); const node = findFile(selectedKeys[0], workspace.fileTree!);
if (node && node.isLeaf) { if (node && node.isLeaf) {
@@ -664,7 +664,7 @@ export const Explorer: FC = () => {
} }
}); });
useKeyDown(Hotkey.Copy, keysRef, (event) => { useKeyPress(Hotkey.Copy, keysRef, (event) => {
event.preventDefault(); event.preventDefault();
const node = findFile(selectedKeys[0], workspace.fileTree!); const node = findFile(selectedKeys[0], workspace.fileTree!);
if (node && node.isLeaf) { if (node && node.isLeaf) {
@@ -672,7 +672,7 @@ export const Explorer: FC = () => {
} }
}); });
useKeyDown(Hotkey.Paste, keysRef, (event) => { useKeyPress(Hotkey.Paste, keysRef, (event) => {
event.preventDefault(); event.preventDefault();
const node = findFile(selectedKeys[0], workspace.fileTree!); const node = findFile(selectedKeys[0], workspace.fileTree!);
if (node) { if (node) {
+4 -4
View File
@@ -254,15 +254,15 @@ export const TreeNodeStyle: { [s in TreeNodeState]?: { [n in ShapeName]?: NodeSt
}, },
highlightargs: { highlightargs: {
"args-bg": { visibility: "visible" }, "args-bg": { visibility: "visible" },
"args-text": { fill: "white", fontWeight: "bolder" }, "args-text": { fill: "white" },
}, },
highlightinput: { highlightinput: {
"input-bg": { visibility: "visible" }, "input-bg": { visibility: "visible" },
"input-text": { fill: "white", fontWeight: "bolder" }, "input-text": { fill: "white" },
}, },
highlightoutput: { highlightoutput: {
"output-bg": { visibility: "visible" }, "output-bg": { visibility: "visible" },
"output-text": { fill: "white", fontWeight: "bolder" }, "output-text": { fill: "white" },
}, },
highlightgray: { highlightgray: {
"args-text": { fill: "#666" }, "args-text": { fill: "#666" },
@@ -414,7 +414,7 @@ class TreeNode extends Rect {
text: this._data.name, text: this._data.name,
textBaseline: "top", textBaseline: "top",
x: this._nodeLayout === "compact" ? 26 : 46, x: this._nodeLayout === "compact" ? 26 : 46,
y: 5, y: isMacos ? 3 : 2,
}, },
container container
); );
+8 -9
View File
@@ -1,5 +1,4 @@
import { app } from "@electron/remote"; import { app } from "@electron/remote";
import { useKeyPress } from "ahooks";
import { Button, Flex, Layout, Space, Tabs, Tag, Tooltip } from "antd"; import { Button, Flex, Layout, Space, Tabs, Tag, Tooltip } from "antd";
import { FC, useEffect, useRef, useState } from "react"; import { FC, useEffect, useRef, useState } from "react";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
@@ -12,7 +11,7 @@ import { useShallow } from "zustand/react/shallow";
import { useSetting } from "../contexts/setting-context"; import { useSetting } from "../contexts/setting-context";
import { EditorStore, useWorkspace } from "../contexts/workspace-context"; import { EditorStore, useWorkspace } from "../contexts/workspace-context";
import { modal } from "../misc/hooks"; import { modal } from "../misc/hooks";
import { Hotkey, isMacos, setInputFocus, useKeyDown } from "../misc/keys"; import { Hotkey, isMacos, setInputFocus, useKeyPress } from "../misc/keys";
import Path from "../misc/path"; import Path from "../misc/path";
import { Editor } from "./editor"; import { Editor } from "./editor";
import { Explorer } from "./explorer"; import { Explorer } from "./explorer";
@@ -47,21 +46,21 @@ export const Workspace: FC = () => {
const keysRef = useRef<HTMLDivElement>(null); const keysRef = useRef<HTMLDivElement>(null);
useKeyDown(Hotkey.Build, keysRef, (event) => { useKeyPress(Hotkey.Build, keysRef, (event) => {
event.preventDefault(); event.preventDefault();
workspace.buildProject(); workspace.buildProject();
}); });
useKeyDown(Hotkey.Save, keysRef, (event) => { useKeyPress(Hotkey.Save, keysRef, (event) => {
event.preventDefault(); event.preventDefault();
workspace.save(); workspace.save();
}); });
useKeyPress(Hotkey.CloseEditor, (event) => { useKeyPress(Hotkey.CloseEditor, null, (event) => {
event.preventDefault(); event.preventDefault();
}); });
useKeyDown(Hotkey.CloseEditor, null, (event) => { useKeyPress(Hotkey.CloseEditor, null, (event) => {
if (workspace.editing) { if (workspace.editing) {
event.preventDefault(); event.preventDefault();
if (workspace.editing.changed) { if (workspace.editing.changed) {
@@ -73,17 +72,17 @@ export const Workspace: FC = () => {
keysRef.current?.focus(); keysRef.current?.focus();
}); });
useKeyDown(Hotkey.SearchTree, keysRef, (event) => { useKeyPress(Hotkey.SearchTree, keysRef, (event) => {
event.preventDefault(); event.preventDefault();
workspace.onShowingSearch(true); workspace.onShowingSearch(true);
}); });
useKeyDown(Hotkey.SearchNode, keysRef, (event) => { useKeyPress(Hotkey.SearchNode, keysRef, (event) => {
event.preventDefault(); event.preventDefault();
workspace.editing?.dispatch?.("searchNode"); workspace.editing?.dispatch?.("searchNode");
}); });
useKeyDown(Hotkey.JumpNode, keysRef, (event) => { useKeyPress(Hotkey.JumpNode, keysRef, (event) => {
event.preventDefault(); event.preventDefault();
workspace.editing?.dispatch?.("jumpNode"); workspace.editing?.dispatch?.("jumpNode");
}); });
+3 -3
View File
@@ -1,5 +1,5 @@
import { BrowserWindow } from "@electron/remote"; import { BrowserWindow } from "@electron/remote";
import useKeyPress, { KeyFilter, KeyType, Options, Target } from "ahooks/lib/useKeyPress"; import _useKeyPress, { KeyFilter, KeyType, Options, Target } from "ahooks/lib/useKeyPress";
import { Key } from "ts-key-enum"; import { Key } from "ts-key-enum";
export const isMacos = process.platform === "darwin"; export const isMacos = process.platform === "darwin";
@@ -13,7 +13,7 @@ const hotkey = (key: string) => {
return key.toLowerCase(); return key.toLowerCase();
}; };
export const useKeyDown = ( export const useKeyPress = (
keyFilter: KeyFilter, keyFilter: KeyFilter,
target: Target, target: Target,
eventHandler: (event: KeyboardEvent, key: KeyType) => void, eventHandler: (event: KeyboardEvent, key: KeyType) => void,
@@ -22,7 +22,7 @@ export const useKeyDown = (
option = option || {}; option = option || {};
option.target = target; option.target = target;
option.exactMatch = true; option.exactMatch = true;
return useKeyPress(keyFilter, (e, key) => !e.repeat && eventHandler(e, key), option); return _useKeyPress(keyFilter, (e, key) => !e.repeat && eventHandler(e, key), option);
}; };
export const Hotkey = { export const Hotkey = {