From 5f6852a69bbd61793c3687b0fc45dd7d820f7a25 Mon Sep 17 00:00:00 2001 From: Robby6Strings Date: Tue, 9 Apr 2024 09:29:34 +1200 Subject: [PATCH] devtools host btn anchoring --- packages/devtools-host/package.json | 1 + packages/devtools-host/src/App.tsx | 71 +++++++++++++++++++++----- packages/devtools-host/src/index.ts | 5 +- packages/devtools-host/src/options.ts | 2 +- sandbox/csr/src/components/Counter.tsx | 19 ++++--- 5 files changed, 71 insertions(+), 27 deletions(-) diff --git a/packages/devtools-host/package.json b/packages/devtools-host/package.json index 499529a1..433b9cf2 100644 --- a/packages/devtools-host/package.json +++ b/packages/devtools-host/package.json @@ -20,6 +20,7 @@ "tsx": "^4.7.0" }, "dependencies": { + "@kaioken-core/hooks": "0.0.1-56", "kaioken": "workspace:^" } } diff --git a/packages/devtools-host/src/App.tsx b/packages/devtools-host/src/App.tsx index 5793de3b..35e6b081 100644 --- a/packages/devtools-host/src/App.tsx +++ b/packages/devtools-host/src/App.tsx @@ -1,6 +1,35 @@ +import { useMemo, useState } from "kaioken" import { __useDevtoolsStore } from "./store" +//@ts-ignore +import { useTween, useWindowSize } from "@kaioken-core/hooks" + +const size = 30 +const padding = 15 export default function __DevtoolsApp() { + const [corner, setCorner] = useState<"br" | "bl" | "tl" | "tr">("br") + const { width, height } = useWindowSize() + + const _width = Math.min(width, document.body.clientWidth) // handle scrollbars + + const topLeftOffset = () => ({ + x: padding, + y: padding, + }) + const topRightOffset = () => ({ x: _width - size - padding, y: padding }) + const bottomRightOffset = () => ({ + x: _width - size - padding, + y: height - size - padding, + }) + const bottomLeftOffset = () => ({ x: padding, y: height - size - padding }) + + const coords = useMemo(() => { + if (corner === "br") return bottomRightOffset() + if (corner === "bl") return bottomLeftOffset() + if (corner === "tl") return topLeftOffset() + else return topRightOffset() + }, [corner, width, height]) + const { value: { popupWindow }, setPopupWindow, @@ -21,20 +50,34 @@ export default function __DevtoolsApp() { } } return ( - + + + ) } diff --git a/packages/devtools-host/src/index.ts b/packages/devtools-host/src/index.ts index b8016eaf..83c8df2e 100644 --- a/packages/devtools-host/src/index.ts +++ b/packages/devtools-host/src/index.ts @@ -4,10 +4,7 @@ import __DevtoolsApp from "./App" const __devtoolsRoot = Object.assign(document.createElement("div"), { id: "devtools-root", }) -__devtoolsRoot.setAttribute( - "style", - "position:fixed;bottom:0;right:0;z-index:999999;color:#fff;" -) +__devtoolsRoot.setAttribute("style", "display:contents;") document.body.appendChild(__devtoolsRoot) __devtoolsMount(__DevtoolsApp, { diff --git a/packages/devtools-host/src/options.ts b/packages/devtools-host/src/options.ts index a6c8acae..d70bf13c 100644 --- a/packages/devtools-host/src/options.ts +++ b/packages/devtools-host/src/options.ts @@ -30,7 +30,7 @@ export function writeFile(content: string) { fs.mkdirSync("dist") fs.writeFileSync( "dist/index.js", - `export default \`import * as devtoolsKaioken from 'kaioken';\n${content}\``, + `export default \`import * as devtoolsKaioken from 'kaioken';\n${content.replace(/[`\\$]/g, "\\$&")}\``, { encoding: "utf-8", } diff --git a/sandbox/csr/src/components/Counter.tsx b/sandbox/csr/src/components/Counter.tsx index 969ccab8..9ef75d5d 100644 --- a/sandbox/csr/src/components/Counter.tsx +++ b/sandbox/csr/src/components/Counter.tsx @@ -8,21 +8,24 @@ export function Counter() { const data = useAsync( () => - fetch("https://dummyjson.com/products/1").then((res) => { + fetch(`https://dummyjson.com/products/${count + 1}`).then((res) => { console.log("resolving req") return res.json() }), - [] + [count] ) console.log("Counter", data) return ( - - - count: {count} - {count % 2 === 0 ? Test : Testw} - - +
+ {data?.title} + + + count: {count} + {count % 2 === 0 ? Test : Testw} + + +
) }