From 8444fdbf09a09a0f3b82c4ef28d745d0d63c133c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=5FMr=E4=B8=B6s=20=E3=82=9B=F0=9F=98=81=C2=AE?= <31917567+ma123456mai@users.noreply.github.com> Date: Fri, 25 Sep 2026 19:51:46 +0800 Subject: [PATCH] feat(dialog): resizable DDL dialog with maximize on double-click --- .../src/components/objects/DdlViewDialog.vue | 187 ++++++++++++++---- 1 file changed, 151 insertions(+), 36 deletions(-) diff --git a/apps/desktop/src/components/objects/DdlViewDialog.vue b/apps/desktop/src/components/objects/DdlViewDialog.vue index abcbefd2f3..0a7843ed6c 100644 --- a/apps/desktop/src/components/objects/DdlViewDialog.vue +++ b/apps/desktop/src/components/objects/DdlViewDialog.vue @@ -3,7 +3,7 @@ import { applyDdlStoragePreference } from "@/lib/sql/ddlStorage"; import DdlStorageToggle from "@/components/objects/DdlStorageToggle.vue"; import { computed, nextTick, onUnmounted, ref, shallowRef, watch } from "vue"; import { useI18n } from "vue-i18n"; -import { Clipboard, ExternalLink, Loader2, RefreshCw } from "@lucide/vue"; +import { Clipboard, ExternalLink, Loader2, Maximize2, Minimize2, RefreshCw } from "@lucide/vue"; import { useToast } from "@/composables/useToast"; import { useTheme } from "@/composables/useTheme"; import { useSettingsStore } from "@/stores/settingsStore"; @@ -68,26 +68,42 @@ let ddlEditorResizeObserver: ResizeObserver | null = null; const dragOffset = ref({ x: 0, y: 0 }); const isDragging = ref(false); const dragStartPosition = ref({ x: 0, y: 0 }); -const dragStartOffset = ref({ x: 0, y: 0 }); const activePointerId = ref(null); +const lastHeaderPointerDown = ref<{ time: number; x: number; y: number } | null>(null); +const DIALOG_DRAG_THRESHOLD_PX = 5; +const HEADER_DOUBLE_CLICK_INTERVAL_MS = 600; +const HEADER_DOUBLE_CLICK_DISTANCE_PX = 8; const dialogSize = ref({ width: 980, height: 720 }); const isResizing = ref(false); +const isMaximized = ref(false); +const sizeBeforeMaximize = ref({ width: 980, height: 720 }); +const offsetBeforeMaximize = ref({ x: 0, y: 0 }); +type ResizeDirection = "n" | "s" | "e" | "w" | "ne" | "nw" | "se" | "sw"; +const resizeHandles = [ + { direction: "n", className: "left-4 right-4 top-0 h-2 cursor-ns-resize" }, + { direction: "s", className: "bottom-0 left-4 right-4 h-2 cursor-ns-resize" }, + { direction: "e", className: "right-0 top-4 bottom-4 w-2 cursor-ew-resize" }, + { direction: "w", className: "left-0 top-4 bottom-4 w-2 cursor-ew-resize" }, + { direction: "nw", className: "left-0 top-0 size-4 cursor-nwse-resize" }, + { direction: "ne", className: "right-0 top-0 size-4 cursor-nesw-resize" }, + { direction: "sw", className: "bottom-0 left-0 size-4 cursor-nesw-resize" }, + { direction: "se", className: "bottom-0 right-0 size-4 cursor-nwse-resize" }, +] as const; const resizeStartPosition = ref({ x: 0, y: 0 }); -const resizeStartSize = ref({ width: 980, height: 720 }); -const resizeStartOffset = ref({ x: 0, y: 0 }); -const resizeStartRect = ref({ left: 0, top: 0 }); +const dialogStartRect = ref({ left: 0, top: 0, width: 980, height: 720 }); const activeResizePointerId = ref(null); +const activeResizeDirection = ref(null); const dialogContentStyle = computed(() => { const moved = isDragging.value || dragOffset.value.x !== 0 || dragOffset.value.y !== 0; return { - width: `min(${dialogSize.value.width}px, calc(100vw - 32px))`, - height: `min(${dialogSize.value.height}px, calc(100vh - 32px))`, + width: isMaximized.value ? "calc(100vw - 32px)" : `min(${dialogSize.value.width}px, calc(100vw - 32px))`, + height: isMaximized.value ? "calc(100vh - 32px)" : `min(${dialogSize.value.height}px, calc(100vh - 32px))`, maxWidth: "calc(100vw - 32px)", maxHeight: "calc(100vh - 32px)", minWidth: "min(560px, calc(100vw - 32px))", minHeight: "min(420px, calc(100vh - 32px))", - transform: moved ? `translate(${dragOffset.value.x}px, ${dragOffset.value.y}px)` : undefined, - transition: isDragging.value || isResizing.value ? "none" : "transform 0.15s ease-out", + transform: isMaximized.value ? "translate(0px, 0px)" : moved ? `translate(${dragOffset.value.x}px, ${dragOffset.value.y}px)` : undefined, + transition: isDragging.value || isResizing.value ? "none" : "transform 0.15s ease-out, width 0.15s ease-out, height 0.15s ease-out", }; }); @@ -99,30 +115,66 @@ function resetDialogDragOffset() { dragOffset.value = { x: 0, y: 0 }; isDragging.value = false; activePointerId.value = null; + lastHeaderPointerDown.value = null; dialogSize.value = { width: 980, height: 720 }; isResizing.value = false; activeResizePointerId.value = null; + activeResizeDirection.value = null; + isMaximized.value = false; +} + +function onDialogHeaderPointerDown(event: PointerEvent) { + const target = event.target; + if ((event.button !== undefined && event.button !== 0) || (target instanceof Element && target.closest("button"))) { + lastHeaderPointerDown.value = null; + return; + } + + const previous = lastHeaderPointerDown.value; + const elapsed = previous ? event.timeStamp - previous.time : Infinity; + const distance = previous ? Math.hypot(event.clientX - previous.x, event.clientY - previous.y) : Infinity; + if (event.pointerType === "mouse" && elapsed <= HEADER_DOUBLE_CLICK_INTERVAL_MS && distance <= HEADER_DOUBLE_CLICK_DISTANCE_PX) { + lastHeaderPointerDown.value = null; + event.preventDefault(); + toggleDialogMaximized(); + return; + } + + lastHeaderPointerDown.value = event.pointerType === "mouse" ? { time: event.timeStamp, x: event.clientX, y: event.clientY } : null; + startDialogDrag(event); } function startDialogDrag(event: PointerEvent) { - if (event.button !== undefined && event.button !== 0) return; - isDragging.value = true; + if (isMaximized.value || (event.button !== undefined && event.button !== 0)) return; + isDragging.value = false; activePointerId.value = event.pointerId; dragStartPosition.value = { x: event.clientX, y: event.clientY }; - dragStartOffset.value = { ...dragOffset.value }; + const dialogRect = (event.currentTarget as HTMLElement).closest("[data-slot='dialog-content']")?.getBoundingClientRect(); + if (dialogRect) dialogStartRect.value = { left: dialogRect.left, top: dialogRect.top, width: dialogRect.width, height: dialogRect.height }; (event.currentTarget as HTMLElement).setPointerCapture(event.pointerId); } function moveDialogDrag(event: PointerEvent) { - if (!isDragging.value || event.pointerId !== activePointerId.value) return; + if (event.pointerId !== activePointerId.value) return; + const deltaX = event.clientX - dragStartPosition.value.x; + const deltaY = event.clientY - dragStartPosition.value.y; + if (!isDragging.value) { + if (Math.hypot(deltaX, deltaY) < DIALOG_DRAG_THRESHOLD_PX) return; + isDragging.value = true; + lastHeaderPointerDown.value = null; + } + const width = dialogStartRect.value.width; + const height = dialogStartRect.value.height; + const left = Math.max(16, Math.min(window.innerWidth - width - 16, dialogStartRect.value.left + deltaX)); + const top = Math.max(16, Math.min(window.innerHeight - height - 16, dialogStartRect.value.top + deltaY)); dragOffset.value = { - x: dragStartOffset.value.x + event.clientX - dragStartPosition.value.x, - y: dragStartOffset.value.y + event.clientY - dragStartPosition.value.y, + x: left - (window.innerWidth - width) / 2, + y: top - (window.innerHeight - height) / 2, }; } function endDialogDrag(event: PointerEvent) { - if (!isDragging.value || event.pointerId !== activePointerId.value) return; + if (event.pointerId !== activePointerId.value) return; isDragging.value = false; activePointerId.value = null; try { @@ -132,32 +184,61 @@ function endDialogDrag(event: PointerEvent) { } } -function startDialogResize(event: PointerEvent) { - if (event.button !== undefined && event.button !== 0) return; +function startDialogResize(event: PointerEvent, direction: ResizeDirection) { + if (isMaximized.value || (event.button !== undefined && event.button !== 0)) return; event.preventDefault(); event.stopPropagation(); isResizing.value = true; + activeResizeDirection.value = direction; activeResizePointerId.value = event.pointerId; resizeStartPosition.value = { x: event.clientX, y: event.clientY }; const dialogRect = (event.currentTarget as HTMLElement).closest("[data-slot='dialog-content']")?.getBoundingClientRect(); - resizeStartSize.value = dialogRect ? { width: dialogRect.width, height: dialogRect.height } : { ...dialogSize.value }; - resizeStartRect.value = dialogRect ? { left: dialogRect.left, top: dialogRect.top } : { left: 0, top: 0 }; - resizeStartOffset.value = { ...dragOffset.value }; + dialogStartRect.value = dialogRect ? { left: dialogRect.left, top: dialogRect.top, width: dialogRect.width, height: dialogRect.height } : { left: (window.innerWidth - dialogSize.value.width) / 2, top: (window.innerHeight - dialogSize.value.height) / 2, ...dialogSize.value }; (event.currentTarget as HTMLElement).setPointerCapture(event.pointerId); } function moveDialogResize(event: PointerEvent) { - if (!isResizing.value || event.pointerId !== activeResizePointerId.value) return; - const maxWidth = Math.max(1, Math.min(window.innerWidth - 32, window.innerWidth - 16 - resizeStartRect.value.left)); - const maxHeight = Math.max(1, Math.min(window.innerHeight - 32, window.innerHeight - 16 - resizeStartRect.value.top)); - const minWidth = Math.min(560, maxWidth); - const minHeight = Math.min(420, maxHeight); - const width = Math.min(maxWidth, Math.max(minWidth, resizeStartSize.value.width + event.clientX - resizeStartPosition.value.x)); - const height = Math.min(maxHeight, Math.max(minHeight, resizeStartSize.value.height + event.clientY - resizeStartPosition.value.y)); + const direction = activeResizeDirection.value; + if (!isResizing.value || event.pointerId !== activeResizePointerId.value || !direction) return; + const margin = 16; + const minWidth = Math.min(560, window.innerWidth - margin * 2); + const minHeight = Math.min(420, window.innerHeight - margin * 2); + const start = dialogStartRect.value; + const dx = event.clientX - resizeStartPosition.value.x; + const dy = event.clientY - resizeStartPosition.value.y; + let left = start.left; + let right = start.left + start.width; + let top = start.top; + let bottom = start.top + start.height; + + if (direction.includes("w")) { + right = Math.max(margin + minWidth, Math.min(window.innerWidth - margin, right)); + left = Math.max(margin, Math.min(right - minWidth, start.left + dx)); + } else if (direction.includes("e")) { + left = Math.max(margin, Math.min(window.innerWidth - margin - minWidth, left)); + right = Math.max(left + minWidth, Math.min(window.innerWidth - margin, right + dx)); + } else { + left = Math.max(margin, Math.min(window.innerWidth - margin - start.width, left)); + right = left + start.width; + } + + if (direction.includes("n")) { + bottom = Math.max(margin + minHeight, Math.min(window.innerHeight - margin, bottom)); + top = Math.max(margin, Math.min(bottom - minHeight, start.top + dy)); + } else if (direction.includes("s")) { + top = Math.max(margin, Math.min(window.innerHeight - margin - minHeight, top)); + bottom = Math.max(top + minHeight, Math.min(window.innerHeight - margin, bottom + dy)); + } else { + top = Math.max(margin, Math.min(window.innerHeight - margin - start.height, top)); + bottom = top + start.height; + } + + const width = right - left; + const height = bottom - top; dialogSize.value = { width, height }; dragOffset.value = { - x: resizeStartOffset.value.x + (width - resizeStartSize.value.width) / 2, - y: resizeStartOffset.value.y + (height - resizeStartSize.value.height) / 2, + x: (left + right) / 2 - window.innerWidth / 2, + y: (top + bottom) / 2 - window.innerHeight / 2, }; } @@ -165,6 +246,7 @@ function endDialogResize(event: PointerEvent) { if (!isResizing.value || event.pointerId !== activeResizePointerId.value) return; isResizing.value = false; activeResizePointerId.value = null; + activeResizeDirection.value = null; try { (event.currentTarget as HTMLElement).releasePointerCapture(event.pointerId); } catch { @@ -172,6 +254,32 @@ function endDialogResize(event: PointerEvent) { } } +function toggleDialogMaximized() { + if (isMaximized.value) { + const width = Math.min(sizeBeforeMaximize.value.width, window.innerWidth - 32); + const height = Math.min(sizeBeforeMaximize.value.height, window.innerHeight - 32); + const maxOffsetX = Math.max(0, (window.innerWidth - width) / 2 - 16); + const maxOffsetY = Math.max(0, (window.innerHeight - height) / 2 - 16); + dialogSize.value = { width, height }; + dragOffset.value = { + x: Math.max(-maxOffsetX, Math.min(maxOffsetX, offsetBeforeMaximize.value.x)), + y: Math.max(-maxOffsetY, Math.min(maxOffsetY, offsetBeforeMaximize.value.y)), + }; + isMaximized.value = false; + return; + } + + sizeBeforeMaximize.value = { ...dialogSize.value }; + offsetBeforeMaximize.value = { ...dragOffset.value }; + isDragging.value = false; + isResizing.value = false; + activePointerId.value = null; + activeResizePointerId.value = null; + activeResizeDirection.value = null; + dragOffset.value = { x: 0, y: 0 }; + isMaximized.value = true; +} + async function loadDdl(force = false) { ddlError.value = ""; ddlLoading.value = true; @@ -424,9 +532,14 @@ function onClose() {