From 746a300ac10db5302953873756e91a79b26ca93d Mon Sep 17 00:00:00 2001 From: Robby6Strings Date: Fri, 12 Apr 2024 01:51:22 +1200 Subject: [PATCH] improve devtools-host btn --- packages/devtools-host/src/App.tsx | 65 ++++++++++++++++++++++++++--- packages/devtools-host/src/index.ts | 23 +++++++++- packages/devtools-host/src/store.ts | 22 +++++++++- 3 files changed, 101 insertions(+), 9 deletions(-) diff --git a/packages/devtools-host/src/App.tsx b/packages/devtools-host/src/App.tsx index 109705fc..fb9edeb0 100644 --- a/packages/devtools-host/src/App.tsx +++ b/packages/devtools-host/src/App.tsx @@ -1,11 +1,29 @@ +import { useEffect as __devtoolsUseEffect } from "kaioken" import { __useDevtoolsStore } from "./store" +function __devtoolsHandleDragOver(e: DragEvent) { + const dragging = __useDevtoolsStore.getState().dragging + if (!dragging) return + e.preventDefault() + e.stopPropagation() + e.dataTransfer && (e.dataTransfer.dropEffect = "move") +} + export default function __DevtoolsApp() { const { - value: { popupWindow }, + value: { popupWindow, dragging }, setPopupWindow, + setCorner, + setDragging, } = __useDevtoolsStore() + __devtoolsUseEffect(() => { + document.body.addEventListener("dragover", __devtoolsHandleDragOver) + return () => { + document.body.removeEventListener("dragover", __devtoolsHandleDragOver) + } + }, []) + function handleOpen() { if (popupWindow) return popupWindow.focus() const features = `popup,width=${Math.floor(window.screen.width / 2)},height=${Math.floor(window.screen.height / 2)};` @@ -22,16 +40,53 @@ export default function __DevtoolsApp() { } } + function handleDragStart() { + __useDevtoolsStore.setState((prev) => ({ + ...prev, + dragging: true, + })) + } + + function handleDrag(e: DragEvent) { + e.preventDefault() + e.stopPropagation() + + let isLeft = true, + isTop = true + if (e.pageX > window.innerWidth / 2) isLeft = false + if (e.pageY > window.innerHeight / 2) isTop = false + + const corner = isTop ? (isLeft ? "tl" : "tr") : isLeft ? "bl" : "br" + setCorner(corner) + } + + function handleDragEnd(e: DragEvent) { + e.preventDefault() + e.stopPropagation() + setDragging(false) + } + return ( <> -