diff --git a/frontend/src/components/FloatingPanel.svelte b/frontend/src/components/FloatingPanel.svelte index 74bb0d9..7b78ad8 100644 --- a/frontend/src/components/FloatingPanel.svelte +++ b/frontend/src/components/FloatingPanel.svelte @@ -11,7 +11,8 @@ } from "carbon-components-svelte" import { - Close + Close, FolderMoveTo + } from 'carbon-icons-svelte' export let title: string = "Untitled" @@ -41,7 +42,7 @@ node.style.cursor = 'auto' } function move(e: MouseEvent) { - if (!dragging) return + if (!dragging || resizing) return let dx = e.clientX - x let dy = e.clientY - y x = e.clientX @@ -49,12 +50,87 @@ node.style.left = parseInt(node.style.left) + dx + 'px' node.style.top = parseInt(node.style.top) + dy + 'px' } + } + + let resizing: boolean = false + function resizeDrag(node, direction: 'tl' | 'tr' | 'bl' | 'br' | 't' | 'r' | 'b' | 'l') { + let dragging: boolean = false + let x: number = 0 + let y: number = 0 + let dx: number = 0 + let dy: number = 0 + let left: number = 0 + let top: number = 0 + let width: number = 0 + let height: number = 0 + node.addEventListener('mousedown', start) + window.addEventListener('mouseup', stop) + window.addEventListener('mouseleave', stop) + window.addEventListener('mousemove', move) + + function start(e: MouseEvent) { + resizing = true + dragging = true + x = e.clientX + y = e.clientY + dx = 0 + dy = 0 + let rect = dialog.getBoundingClientRect() + width = rect.width + height = rect.height + top = rect.top + left = rect.left + } + function stop(e: MouseEvent) { + resizing = false + dragging = false + node.style.cursor = 'auto' + } + function move(e: MouseEvent) { + if (!dragging) return + e.preventDefault() + e.stopPropagation() + e.stopImmediatePropagation() + dx += e.clientX - x + dy += e.clientY - y + x = e.clientX + y = e.clientY + + if (direction === 't') { + dialog.style.height = height - dy + 'px' + dialog.style.top = top + dy + 'px' + } else if (direction === 'r') { + dialog.style.width = width + dx + 'px' + dialog.style.left = left + dx + 'px' + } else if (direction === 'b') { + dialog.style.height = height + dy + 'px' + } else if (direction === 'l') { + dialog.style.width = width - dx + 'px' + dialog.style.left = left + dx + 'px' + } else if (direction === 'tl') { + dialog.style.width = width - dx + 'px' + dialog.style.height = height - dy + 'px' + dialog.style.left = left + dx + 'px' + dialog.style.top = top + dy + 'px' + } else if (direction === 'tr') { + dialog.style.width = width + dx + 'px' + dialog.style.height = height - dy + 'px' + dialog.style.top = top + dy + 'px' + } else if (direction === 'bl') { + dialog.style.width = width - dx + 'px' + dialog.style.height = height + dy + 'px' + dialog.style.left = left + dx + 'px' + } else if (direction === 'br') { + dialog.style.width = width + dx + 'px' + dialog.style.height = height + dy + 'px' + } + } } - + let dialog: HTMLDialogElement - +

{label}

\ No newline at end of file