Skip to content

Commit f42af4b

Browse files
committed
expand on embedded mode
1 parent 73bba2b commit f42af4b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1643
-187
lines changed

Diff for: package-lock.json

+49-14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

+2
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,11 @@
6868
"docs": "npm run dev -w docs",
6969
"prepublishOnly": "npm run build",
7070
"remix-vite": "npm run dev -w test-apps/remix-vite",
71+
"remix-vite-embedded": "npm run dev -w test-apps/remix-vite-embedded",
7172
"remix-website": "npm run dev -w test-apps/remix-website",
7273
"runner": "npm-run-all -s build -p watch-all",
7374
"dev": "npm run runner remix-vite",
75+
"dev:embedded": "npm run runner remix-vite-embedded",
7476
"dev:website": "npm run runner remix-website ",
7577
"build": "run-s tsup:* -- --clean",
7678
"watch-all": "npm-run-all -p tsup:index:watch tsup:client:watch tsup:server:watch -- --watch",

Diff for: src/client/EmbeddedDevTools.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { useLocation } from "@remix-run/react"
22
import clsx from "clsx"
33
import { useEffect, useState } from "react"
44
import type { RemixDevToolsProps } from "./RemixDevTools.js"
5-
import { RDTContextProvider } from "./context/RDTContext.js"
5+
import { RDTContextProvider, RDTEmbeddedContextProvider as RemixDevToolsEmbeddedMode } from "./context/RDTContext.js"
66
import { useSettingsContext } from "./context/useRDTContext.js"
77
import { useBorderedRoutes } from "./hooks/useBorderedRoutes.js"
88
import { useSetRouteBoundaries } from "./hooks/useSetRouteBoundaries.js"

Diff for: src/client/context/RDTContext.tsx

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { Dispatch } from "react"
22
import type React from "react"
3-
import { createContext, useEffect, useMemo, useReducer } from "react"
3+
import { createContext, useContext, useEffect, useMemo, useReducer } from "react"
44
import { useRemoveBody } from "../hooks/detached/useRemoveBody.js"
55
import { checkIsDetached, checkIsDetachedOwner, checkIsDetachedWindow } from "../utils/detached.js"
66
import { tryParseJson } from "../utils/sanitize.js"
@@ -20,6 +20,16 @@ export const RDTContext = createContext<{
2020
dispatch: Dispatch<RemixDevToolsActions>
2121
}>({ state: initialState, dispatch: () => null })
2222

23+
const RDTEmbeddedContext = createContext<boolean>(false)
24+
25+
export function RDTEmbeddedContextProvider({ children }: React.PropsWithChildren) {
26+
return <RDTEmbeddedContext.Provider value={true}>{children}</RDTEmbeddedContext.Provider>
27+
}
28+
29+
export function useIsEmbeddedRDT() {
30+
return useContext(RDTEmbeddedContext)
31+
}
32+
2333
RDTContext.displayName = "RDTContext"
2434

2535
interface ContextProps {

Diff for: src/client/init/root.tsx

+44-25
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useEffect, useState } from "react"
22
import { createPortal } from "react-dom"
33
import { RemixDevTools, type RemixDevToolsProps } from "../RemixDevTools.js"
4-
import type { RdtClientConfig } from "../context/RDTContext.js"
4+
import { RDTEmbeddedContextProvider, type RdtClientConfig, useIsEmbeddedRDT } from "../context/RDTContext.js"
55
import { hydrationDetector } from "./hydration.js"
66

77
let hydrating = true
@@ -19,34 +19,53 @@ function useHydrated() {
1919

2020
export const defineClientConfig = (config: RdtClientConfig) => config
2121

22-
export const withDevTools = (Component: any, config?: RemixDevToolsProps) => () => {
23-
hydrationDetector()
24-
const hydrated = useHydrated()
25-
if (!hydrated) return <Component />
26-
27-
return (
28-
<>
29-
<Component />
30-
{createPortal(<RemixDevTools {...config} />, document.body)}
31-
</>
32-
)
33-
}
34-
35-
/**
36-
*
37-
* @description Injects the dev tools into the Vite App, ONLY meant to be used by the package plugin, do not use this yourself!
38-
*/
39-
export const withViteDevTools = (Component: any, config?: RemixDevToolsProps) => () => {
40-
hydrationDetector()
41-
function AppWithDevTools(props: any) {
22+
export const withDevTools =
23+
(Component: any, config?: RemixDevToolsProps & { panelMode?: "auto" | "embedded" }) => () => {
24+
hydrationDetector()
4225
const hydrated = useHydrated()
26+
const isEmbedded = useIsEmbeddedRDT()
4327
if (!hydrated) return <Component />
28+
29+
if ((config?.panelMode ?? "auto") === "embedded") {
30+
return (
31+
<RDTEmbeddedContextProvider>
32+
<Component />
33+
</RDTEmbeddedContextProvider>
34+
)
35+
}
36+
4437
return (
4538
<>
46-
<Component {...props} />
47-
{createPortal(<RemixDevTools {...config} />, document.body)}
39+
<Component />
40+
{!isEmbedded && createPortal(<RemixDevTools {...config} />, document.body)}
4841
</>
4942
)
5043
}
51-
return AppWithDevTools
52-
}
44+
45+
/**
46+
*
47+
* @description Injects the dev tools into the Vite App, ONLY meant to be used by the package plugin, do not use this yourself!
48+
*/
49+
export const withViteDevTools =
50+
(Component: any, config?: RemixDevToolsProps & { panelMode?: "auto" | "embedded" }) => () => {
51+
hydrationDetector()
52+
function AppWithDevTools(props: any) {
53+
const hydrated = useHydrated()
54+
if (!hydrated) return <Component />
55+
if ((config?.panelMode ?? "auto") === "embedded") {
56+
return (
57+
<RDTEmbeddedContextProvider>
58+
<Component />
59+
</RDTEmbeddedContextProvider>
60+
)
61+
}
62+
63+
return (
64+
<>
65+
<Component {...props} />
66+
{createPortal(<RemixDevTools {...config} />, document.body)}
67+
</>
68+
)
69+
}
70+
return AppWithDevTools
71+
}

Diff for: src/client/layout/MainPanel.tsx

+17-8
Original file line numberDiff line numberDiff line change
@@ -30,27 +30,36 @@ const MainPanel = ({ children, isOpen, isEmbedded = false, className }: MainPane
3030

3131
return (
3232
<div
33-
style={{
34-
zIndex: 9998,
35-
...(!isEmbedded && { height: detachedWindow ? window.innerHeight : height }),
36-
}}
33+
style={
34+
!isEmbedded
35+
? {
36+
zIndex: 9998,
37+
height: detachedWindow ? window.innerHeight : height,
38+
}
39+
: undefined
40+
}
3741
className={clsx(
38-
"duration-600 box-border flex w-screen flex-col overflow-auto bg-main text-white opacity-0 transition-all",
42+
"duration-600 box-border flex overflow-auto bg-main text-white opacity-0 transition-all",
3943
isOpen ? "opacity-100 drop-shadow-2xl" : "!h-0",
4044
isResizing && "cursor-grabbing ",
41-
!isEmbedded ? `fixed left-0 ${panelLocation === "bottom" ? "bottom-0" : "top-0 border-b-2 border-main"}` : "",
45+
!isEmbedded
46+
? clsx(
47+
"flex-col fixed left-0 w-screen",
48+
panelLocation === "bottom" ? "bottom-0" : "top-0 border-b-2 border-main"
49+
)
50+
: "flex-row",
4251
className
4352
)}
4453
>
45-
{panelLocation === "bottom" && (
54+
{!isEmbedded && panelLocation === "bottom" && (
4655
<div
4756
onMouseDown={enableResize}
4857
onMouseUp={disableResize}
4958
className={clsx("absolute z-50 h-1 w-full", isResizing ? "cursor-grabbing" : "cursor-ns-resize")}
5059
/>
5160
)}
5261
{children}
53-
{panelLocation === "top" && (
62+
{!isEmbedded && panelLocation === "top" && (
5463
<div
5564
onMouseDown={enableResize}
5665
onMouseUp={disableResize}

0 commit comments

Comments
 (0)