Skip to content

AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.

feat(settings): make the system info dialog draggable

tianma-ife69462d8d905
diff --git a/apps/web/src/components/SystemInfoDialog.test.mjs b/apps/web/src/components/SystemInfoDialog.test.mjs
new file mode 100644
index 00000000..a66913be
--- /dev/null
+++ b/apps/web/src/components/SystemInfoDialog.test.mjs
@@ -0,0 +1,15 @@
+import { describe, expect, test } from "bun:test";
+import { readFileSync } from "node:fs";
+
+const source = readFileSync(new URL("./SystemInfoDialog.tsx", import.meta.url), "utf8");
+
+describe("system information dialog dragging", () => {
+ test("moves from the title bar and keeps the body scrollable", () => {
+ expect(source).toContain("handleContentPointerDown");
+ expect(source).toContain("data-dialog-drag-handle");
+ expect(source).toContain("clampDialogPixelPosition");
+ expect(source).toContain("cursor-grab");
+ expect(source).toContain("grid-rows-[auto_minmax(0,1fr)_auto]");
+ expect(source).toContain("min-h-0 overflow-y-auto");
+ });
+});
diff --git a/apps/web/src/components/SystemInfoDialog.tsx b/apps/web/src/components/SystemInfoDialog.tsx
index 4b571abe..9a98ddc1 100644
--- a/apps/web/src/components/SystemInfoDialog.tsx
+++ b/apps/web/src/components/SystemInfoDialog.tsx
@@ -1,7 +1,9 @@
-import { useEffect } from "react";
+import { useEffect, useRef, useState, type PointerEvent as ReactPointerEvent } from "react";
import { useTranslation } from "react-i18next";
import { Button } from "@/components/ui/button";
import { useDeployedUpdateNotice } from "@/hooks/useDeployedUpdateNotice";
+import { clampDialogPixelPosition } from "@/lib/dialog-drag";
+import { cn } from "@/lib/utils";
import {
Dialog,
DialogContent,
@@ -10,22 +12,126 @@ import {
} from "@/components/ui/dialog";
import { SystemInfoPanel } from "./settings/SystemInfoPanel";
+type DialogDragSession = {
+ pointerId: number;
+ startX: number;
+ startY: number;
+ startPointerX: number;
+ startPointerY: number;
+};
+
export const SystemInfoDialog = ({ open, onOpenChange }: { open: boolean; onOpenChange: (open: boolean) => void }) => {
const { t } = useTranslation();
const { markSeen } = useDeployedUpdateNotice();
+ const contentRef = useRef<HTMLDivElement>(null);
+ const dragRef = useRef<DialogDragSession | null>(null);
+ const positionRef = useRef<{ x: number; y: number } | null>(null);
+ const [position, setPosition] = useState<{ x: number; y: number } | null>(null);
+ const [dragging, setDragging] = useState(false);
useEffect(() => {
if (open) markSeen();
}, [markSeen, open]);
+ useEffect(() => {
+ if (open) return;
+ dragRef.current = null;
+ positionRef.current = null;
+ setPosition(null);
+ setDragging(false);
+ }, [open]);
+
+ const setContentNode = (node: HTMLDivElement | null) => {
+ contentRef.current = node;
+ if (!node || positionRef.current) return;
+ const rect = node.getBoundingClientRect();
+ const next = { x: rect.left, y: rect.top };
+ positionRef.current = next;
+ setPosition(next);
+ };
+
+ const updatePosition = (next: { x: number; y: number }) => {
+ positionRef.current = next;
+ setPosition(next);
+ };
+
+ const handleDragMove = (event: ReactPointerEvent<HTMLDivElement>) => {
+ const drag = dragRef.current;
+ const content = contentRef.current;
+ if (!drag || !content || event.pointerId !== drag.pointerId) return;
+ updatePosition(clampDialogPixelPosition({
+ x: drag.startX + (event.clientX - drag.startPointerX),
+ y: drag.startY + (event.clientY - drag.startPointerY),
+ width: content.offsetWidth,
+ height: content.offsetHeight,
+ viewportWidth: window.innerWidth,
+ viewportHeight: window.innerHeight,
+ }));
+ };
+
+ const stopDragging = (event: ReactPointerEvent<HTMLDivElement>) => {
+ const drag = dragRef.current;
+ if (!drag || event.pointerId !== drag.pointerId) return;
+ dragRef.current = null;
+ setDragging(false);
+ if (event.currentTarget.hasPointerCapture(event.pointerId)) {
+ event.currentTarget.releasePointerCapture(event.pointerId);
+ }
+ };
+
+ const handleContentPointerDown = (event: ReactPointerEvent<HTMLDivElement>) => {
+ if (event.button !== 0) return;
+ const target = event.target as Element | null;
+ if (!target?.closest("[data-dialog-drag-handle]")) return;
+ if (target.closest("button, a, input, textarea, [role='button']")) return;
+ const content = contentRef.current;
+ const current = positionRef.current;
+ if (!content || !current) return;
+ event.preventDefault();
+ event.currentTarget.setPointerCapture(event.pointerId);
+ dragRef.current = {
+ pointerId: event.pointerId,
+ startX: current.x,
+ startY: current.y,
+ startPointerX: event.clientX,
+ startPointerY: event.clientY,
+ };
+ setDragging(true);
+ };
+
return (
<Dialog open={open} onOpenChange={onOpenChange}>
- <DialogContent className="max-h-[min(720px,calc(100dvh-2rem))] max-w-2xl overflow-y-auto p-4 sm:p-6">
- <DialogHeader className="pr-8">
+ <DialogContent
+ ref={setContentNode}
+ unstyledPosition
+ className={cn(
+ "grid max-h-[min(720px,calc(100dvh-2rem))] max-w-2xl grid-rows-[auto_minmax(0,1fr)_auto] gap-4 overflow-hidden p-0",
+ dragging && "cursor-grabbing",
+ )}
+ data-offset-x={position?.x ?? ""}
+ data-offset-y={position?.y ?? ""}
+ onLostPointerCapture={stopDragging}
+ onPointerCancel={stopDragging}
+ onPointerDown={handleContentPointerDown}
+ onPointerMove={handleDragMove}
+ onPointerUp={stopDragging}
+ style={position
+ ? { left: position.x, top: position.y, transform: "none" }
+ : { left: "50%", top: "50%", transform: "translate(-50%, -50%)" }}
+ >
+ <DialogHeader
+ className={cn(
+ "touch-none select-none px-4 pr-12 pt-4 text-left sm:px-6 sm:pt-6",
+ dragging ? "cursor-grabbing" : "cursor-grab",
+ )}
+ data-dialog-drag-handle="true"
+ >
<DialogTitle>{t("systemInfo.title")}</DialogTitle>
</DialogHeader>
- <SystemInfoPanel />
- <div className="flex justify-end">
+ <div className="min-h-0 overflow-y-auto px-4 sm:px-6">
+ <SystemInfoPanel />
+ </div>
+ <div className="flex justify-end px-4 pb-4 sm:px-6 sm:pb-6">
<Button type="button" variant="outline" onClick={() => onOpenChange(false)}>
{t("common.close")}
</Button>
diff --git a/apps/web/src/components/ui/dialog.tsx b/apps/web/src/components/ui/dialog.tsx
index cbdcaa9d..1c07dbb8 100644
--- a/apps/web/src/components/ui/dialog.tsx
+++ b/apps/web/src/components/ui/dialog.tsx
@@ -25,14 +25,18 @@ DialogOverlay.displayName = DialogPrimitive.Overlay.displayName;
const DialogContent = React.forwardRef<
React.ElementRef<typeof DialogPrimitive.Content>,
- React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content> & { showCloseButton?: boolean }
->(({ className, children, showCloseButton = true, ...props }, ref) => (
+ React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content> & {
+ showCloseButton?: boolean;
+ unstyledPosition?: boolean;
+ }
+>(({ className, children, showCloseButton = true, unstyledPosition = false, ...props }, ref) => (
<DialogPortal>
<DialogOverlay />
<DialogPrimitive.Content
ref={ref}
className={cn(
- "fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border border-slate-200 bg-card p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-1/2 data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-1/2 rounded-lg",
+ "fixed z-50 grid w-full max-w-lg gap-4 rounded-lg border border-slate-200 bg-card p-6 shadow-lg",
+ !unstyledPosition && "left-[50%] top-[50%] translate-x-[-50%] translate-y-[-50%] duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-1/2 data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-1/2",
className
)}
{...props}
diff --git a/apps/web/src/lib/dialog-drag.test.mjs b/apps/web/src/lib/dialog-drag.test.mjs
new file mode 100644
index 00000000..6f8b0a98
--- /dev/null
+++ b/apps/web/src/lib/dialog-drag.test.mjs
@@ -0,0 +1,20 @@
+import { describe, expect, test } from "bun:test";
+import { clampDialogPixelPosition } from "./dialog-drag.ts";
+
+describe("clampDialogPixelPosition", () => {
+ const base = {
+ width: 400,
+ height: 300,
+ viewportWidth: 1000,
+ viewportHeight: 800,
+ };
+
+ test("keeps unconstrained movement", () => {
+ expect(clampDialogPixelPosition({ ...base, x: 240, y: 80 })).toEqual({ x: 240, y: 80 });
+ });
+
+ test("keeps a slice of the dialog inside the viewport", () => {
+ expect(clampDialogPixelPosition({ ...base, x: 2000, y: 2000 })).toEqual({ x: 952, y: 752 });
+ expect(clampDialogPixelPosition({ ...base, x: -2000, y: -2000 })).toEqual({ x: -352, y: 0 });
+ });
+});
diff --git a/apps/web/src/lib/dialog-drag.ts b/apps/web/src/lib/dialog-drag.ts
new file mode 100644
index 00000000..7d6795d7
--- /dev/null
+++ b/apps/web/src/lib/dialog-drag.ts
@@ -0,0 +1,28 @@
+export const DIALOG_DRAG_MIN_VISIBLE = 48;
+
+export const clampDialogPixelPosition = ({
+ x,
+ y,
+ width,
+ height,
+ viewportWidth,
+ viewportHeight,
+ minVisible = DIALOG_DRAG_MIN_VISIBLE,
+}: {
+ x: number;
+ y: number;
+ width: number;
+ height: number;
+ viewportWidth: number;
+ viewportHeight: number;
+ minVisible?: number;
+}) => {
+ const minX = minVisible - width;
+ const maxX = viewportWidth - minVisible;
+ const minY = 0;
+ const maxY = viewportHeight - minVisible;
+ return {
+ x: Math.min(Math.max(x, minX), Math.max(minX, maxX)),
+ y: Math.min(Math.max(y, minY), Math.max(minY, maxY)),
+ };
+};