generated from LankyMoose/pnpm-monorepo-package-template
-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
devtools improvements - is now injected in kaioken module instead of …
…user code, handles SSR better
- Loading branch information
1 parent
370e47d
commit fd8dfdb
Showing
9 changed files
with
103 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,46 @@ | ||
import { mount as __devtoolsMount } from "kaioken" | ||
import __DevtoolsApp from "./App" | ||
import { type AnchorCorner, __useDevtoolsStore } from "./store" | ||
import App from "./App" | ||
import { type AnchorCorner, useDevtoolsStore } from "./store" | ||
;(() => { | ||
if ("window" in globalThis) { | ||
//@ts-ignore | ||
if (window.__kaiokenDevtools) return | ||
|
||
function __devtoolsGetCornerStyle(corner: AnchorCorner) { | ||
switch (corner) { | ||
case "br": | ||
return "bottom:0;right:0;" | ||
case "bl": | ||
return "bottom:0;left:0;" | ||
case "tl": | ||
return "top:0;left:0;" | ||
case "tr": | ||
return "top:0;right:0;" | ||
} | ||
} | ||
|
||
if ("window" in globalThis) { | ||
const __devtoolsRoot = Object.assign(document.createElement("div"), { | ||
id: "devtools-root", | ||
}) | ||
const style = __devtoolsGetCornerStyle(__useDevtoolsStore.getState().corner) | ||
__devtoolsRoot.setAttribute("style", "position:fixed;" + style) | ||
document.body.appendChild(__devtoolsRoot) | ||
|
||
__useDevtoolsStore.subscribe((state) => { | ||
const style = __devtoolsGetCornerStyle(state.corner) | ||
__devtoolsRoot.setAttribute("style", "position:fixed;" + style) | ||
}) | ||
|
||
__devtoolsMount(__DevtoolsApp, { | ||
root: __devtoolsRoot, | ||
name: "kaioken.devtools", | ||
}) | ||
window.__kaioken?.on("mount", () => { | ||
//@ts-ignore | ||
if (window.__kaiokenDevtools) return | ||
const root = Object.assign(document.createElement("div"), { | ||
id: "devtools-root", | ||
}) | ||
const style = getCornerStyle(useDevtoolsStore.getState().corner) | ||
root.setAttribute("style", "position:fixed;" + style) | ||
document.body.appendChild(root) | ||
|
||
window.onbeforeunload = () => { | ||
const { popupWindow } = __useDevtoolsStore.getState() | ||
popupWindow?.close() | ||
useDevtoolsStore.subscribe((state) => { | ||
const style = getCornerStyle(state.corner) | ||
root.setAttribute("style", "position:fixed;" + style) | ||
}) | ||
//@ts-ignore | ||
window.__kaiokenDevtools = __devtoolsMount(App, { | ||
root, | ||
name: "kaioken.devtools", | ||
}) | ||
window.addEventListener("beforeunload", () => { | ||
const { popupWindow } = useDevtoolsStore.getState() | ||
popupWindow?.close() | ||
}) | ||
}) | ||
function getCornerStyle(corner: AnchorCorner) { | ||
switch (corner) { | ||
case "br": | ||
return "bottom:0;right:0;" | ||
case "bl": | ||
return "bottom:0;left:0;" | ||
case "tl": | ||
return "top:0;left:0;" | ||
case "tr": | ||
return "top:0;right:0;" | ||
} | ||
} | ||
} | ||
} | ||
})() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters