Skip to content

Commit e407819

Browse files
committed
🚸 完善搜索节点面板
1 parent 35a219c commit e407819

File tree

6 files changed

+43
-20
lines changed

6 files changed

+43
-20
lines changed

app/src/components/popup.tsx

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@ import { MouseLocation } from "../core/service/controlService/MouseLocation";
44
import { cn } from "../utils/cn";
55
import once from "lodash/once";
66
import Box from "./Box";
7+
import { CircleX } from "lucide-react";
78

89
export namespace Popup {
910
/**
10-
* 弹出一个弹窗
11+
* 弹出一个弹窗,这个弹窗面板不能是 fixed 布局
1112
* @param children
1213
* @returns
1314
*/
14-
export function show(children: React.ReactNode): Promise<void> {
15+
export function show(children: React.ReactNode, closeWhenClickOutside: boolean = true): Promise<void> {
1516
return new Promise((resolve) => {
1617
// 启动一个新的React实例
1718
const container = document.createElement("div");
@@ -21,6 +22,7 @@ export namespace Popup {
2122
<Component
2223
x={MouseLocation.x}
2324
y={MouseLocation.y}
25+
closeWhenClickOutside={closeWhenClickOutside}
2426
onClose={() => {
2527
resolve();
2628
setTimeout(
@@ -52,11 +54,13 @@ export namespace Popup {
5254
y,
5355
onClose,
5456
children,
57+
closeWhenClickOutside,
5558
}: {
5659
x: number;
5760
y: number;
5861
onClose: () => void;
5962
children: React.ReactNode;
63+
closeWhenClickOutside: boolean;
6064
}) {
6165
const [adjustedX, setAdjustedX] = React.useState(0);
6266
const [adjustedY, setAdjustedY] = React.useState(0);
@@ -69,7 +73,6 @@ export namespace Popup {
6973
if (ref.current) {
7074
// 调整弹窗位置,确保不会超出屏幕边界
7175
const { width, height } = ref.current.getBoundingClientRect();
72-
console.log(width, height);
7376
setAdjustedX(x);
7477
setAdjustedY(y);
7578
if (x + width > window.innerWidth) {
@@ -94,8 +97,10 @@ export namespace Popup {
9497
// 监听在外面点击事件
9598
const handleClickOutside = (event: MouseEvent) => {
9699
if (ref.current && !ref.current.contains(event.target as Node)) {
97-
setShow(false);
98-
onClose();
100+
if (closeWhenClickOutside) {
101+
setShow(false);
102+
onClose();
103+
}
99104
}
100105
};
101106
document.addEventListener("mousedown", handleClickOutside);
@@ -112,6 +117,7 @@ export namespace Popup {
112117
className={cn("border-icon-button-border fixed z-[102] opacity-0", {
113118
"opacity-100": show,
114119
"opacity-0 transition-none": adjusting,
120+
// absolute: closeWhenClickOutside,
115121
})}
116122
style={{
117123
left: adjustedX,
@@ -120,6 +126,17 @@ export namespace Popup {
120126
}}
121127
>
122128
{children}
129+
{!closeWhenClickOutside && (
130+
<span
131+
onClick={() => {
132+
setShow(false);
133+
onClose();
134+
}}
135+
className="bg-panel-bg text-panel-text border-panel-details-text absolute -right-4 -top-4 cursor-pointer rounded-full p-1 text-sm hover:scale-105"
136+
>
137+
<CircleX className="cursor-pointer" />
138+
</span>
139+
)}
123140
</Box>
124141
);
125142
}

app/src/main.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ async function registerKeyBinds() {
427427
shift: false,
428428
})
429429
).down(() => {
430-
Popup.show(<ColorPanel />);
430+
Popup.show(<ColorPanel />, true);
431431
});
432432
(
433433
await KeyBinds.create("switchDebugShow", "F3", {
@@ -475,7 +475,7 @@ async function registerKeyBinds() {
475475
shift: false,
476476
})
477477
).down(() => {
478-
Popup.show(<SearchingNodePanel />);
478+
Popup.show(<SearchingNodePanel />, false);
479479
});
480480
(
481481
await KeyBinds.create("openTextNodeByContentExternal", "e", {

app/src/pages/_app_menu.tsx

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
RefreshCcw,
2424
Save,
2525
Scaling,
26+
Search,
2627
Settings as SettingsIcon,
2728
SquareDashedKanbanIcon,
2829
SquareDashedMousePointer,
@@ -53,6 +54,9 @@ import { TextNode } from "../core/stage/stageObject/entity/TextNode";
5354
import { PathString } from "../utils/pathString";
5455
import { HelpService } from "../core/service/helpService/helpService";
5556
import { StageHistoryManager } from "../core/stage/stageManager/StageHistoryManager";
57+
import { SoundService } from "../core/service/feedbackService/SoundService";
58+
import SearchingNodePanel from "./_popup_panel/_searching_node_panel";
59+
import { Popup } from "../components/popup";
5660

5761
export default function AppMenu({ className = "", open = false }: { className?: string; open: boolean }) {
5862
const navigate = useNavigate();
@@ -467,18 +471,14 @@ export default function AppMenu({ className = "", open = false }: { className?:
467471
>
468472
撤销
469473
</Col>
470-
{/* <Col
471-
icon={<Undo />}
474+
<Col
475+
icon={<Search />}
472476
onClick={() => {
473-
const userInput = window.prompt("请输入搜索内容:");
474-
if (!userInput) {
475-
return;
476-
}
477-
Stage.contentSearchEngine.startSearch(userInput);
477+
Popup.show(<SearchingNodePanel />, false);
478478
}}
479479
>
480480
查找
481-
</Col> */}
481+
</Col>
482482
</Row>
483483
<Row icon={<MoreHorizontal />} title={t("more.title")}>
484484
<Col icon={<SettingsIcon />} onClick={() => navigate("/settings/visual")}>
@@ -651,6 +651,12 @@ function Col({
651651
<div
652652
className="hover:bg-appmenu-hover-bg hover:outline-appmenu-hover-bg text-appmenu-item-text flex w-max cursor-pointer items-center gap-1 rounded-lg outline-0 outline-white/0 transition-all hover:outline-8 active:scale-90"
653653
onClick={onClick}
654+
onMouseDown={() => {
655+
SoundService.play.mouseClickButton();
656+
}}
657+
onMouseEnter={() => {
658+
SoundService.play.mouseEnterButton();
659+
}}
654660
>
655661
{icon}
656662
{children}

app/src/pages/_popup_panel/_color_panel.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ export default function ColorPanel() {
114114
></input>
115115
<Button
116116
onClick={() => {
117-
Popup.show(<ColorManagerPanel />);
117+
Popup.show(<ColorManagerPanel />, true);
118118
}}
119119
>
120120
打开颜色管理

app/src/pages/_popup_panel/_searching_node_panel.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export default function SearchingNodePanel() {
4949
// endregion
5050

5151
return (
52-
<Box className="bg-panel-bg border-panel-details-text fixed right-0 m-1 flex transform flex-col p-4">
52+
<Box className="bg-panel-bg border-panel-details-text m-1 flex transform flex-col p-4">
5353
<div className="flex items-center justify-between">
5454
<Input
5555
placeholder="请输入要搜索的内容"

app/src/pages/_toolbar.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export default function Toolbar({ className = "" }: { className?: string }) {
9595
<ToolbarItem
9696
description="通过文本生成节点"
9797
icon={<ClipboardPaste />}
98-
handleFunction={() => Popup.show(<GenerateNodePanel />)}
98+
handleFunction={() => Popup.show(<GenerateNodePanel />, true)}
9999
/>
100100
{isHaveSelectedEdge && (
101101
<ToolbarItem
@@ -111,14 +111,14 @@ export default function Toolbar({ className = "" }: { className?: string }) {
111111
<ToolbarItem
112112
description="设置节点/连线/框的颜色,注意要先选中再点颜色"
113113
icon={<PaintBucket />}
114-
handleFunction={() => Popup.show(<ColorPanel />)}
114+
handleFunction={() => Popup.show(<ColorPanel />, true)}
115115
/>
116116

117117
{isHaveSelectedNode && (
118118
<ToolbarItem
119119
description="节点对齐相关"
120120
icon={<LayoutDashboard />}
121-
handleFunction={() => Popup.show(<AlignNodePanel />)}
121+
handleFunction={() => Popup.show(<AlignNodePanel />, true)}
122122
/>
123123
)}
124124
{isClipboardClearShow && (

0 commit comments

Comments
 (0)