-
Notifications
You must be signed in to change notification settings - Fork 437
feat(react): react devtool #236
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
bb34f5e
feat(react): react devtool
danilowoz de00175
create component
danilowoz 5d8354a
feat(reactdevtools):register
danilowoz 564247e
style
danilowoz 25e61d7
register react dev tools
danilowoz 7248189
docs
danilowoz 9aee55d
fix(react devtool): load only on client
danilowoz 6d1996d
import approach
danilowoz 2cbe974
import approach
danilowoz 672db09
improve docs
danilowoz 6e49c03
fix props
danilowoz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
42 changes: 42 additions & 0 deletions
42
sandpack-react/src/components/ReactDevTools/ReactDevTool.stories.tsx
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| import { SandpackPreview } from ".."; | ||
| import { SandpackProvider, SandpackLayout, SandpackThemeProvider } from "../.."; | ||
|
|
||
| import { SandpackReactDevTools } from "./"; | ||
|
|
||
| export default { | ||
| title: "components/ReactDevTools", | ||
| }; | ||
|
|
||
| export const ReactDevTool: React.FC = () => ( | ||
| <SandpackProvider | ||
| customSetup={{ | ||
| files: { | ||
| "/App.js": ` | ||
| const Container = ({children}) => <div>{children}</div> | ||
| const Button = () => <p>Button</p> | ||
|
|
||
| export default function App() { | ||
| return ( | ||
| <Container> | ||
| <div> | ||
| <Button /> | ||
| <Button /> | ||
| <h1>Hello World</h1> | ||
| <Button /> | ||
| </div> | ||
| </Container> | ||
| ) | ||
| } | ||
| `, | ||
| }, | ||
| }} | ||
| template="react" | ||
| > | ||
| <SandpackThemeProvider> | ||
| <SandpackLayout> | ||
| <SandpackPreview /> | ||
| <SandpackReactDevTools style={{ width: "50%" }} /> | ||
| </SandpackLayout> | ||
| </SandpackThemeProvider> | ||
| </SandpackProvider> | ||
| ); |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| import { useClasser } from "@code-hike/classer"; | ||
| import type { CSSProperties } from "react"; | ||
| import React, { useEffect, useRef, useState } from "react"; | ||
|
|
||
| import { useSandpackTheme } from "../.."; | ||
| import { useSandpack } from "../../hooks/useSandpack"; | ||
| import { isDarkColor } from "../../utils/stringUtils"; | ||
|
|
||
| export const SandpackReactDevTools = ({ | ||
| clientId, | ||
| ...props | ||
| }: { | ||
| clientId?: string; | ||
| style?: CSSProperties; | ||
| }): JSX.Element | null => { | ||
| const { listen, sandpack } = useSandpack(); | ||
| const { theme } = useSandpackTheme(); | ||
| const c = useClasser("sp"); | ||
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| const reactDevtools = useRef<any>(); | ||
|
|
||
| const [ReactDevTools, setDevTools] = useState<React.FunctionComponent<{ | ||
| browserTheme: "dark" | "light"; | ||
| }> | null>(null); | ||
|
|
||
| useEffect(() => { | ||
| import("react-devtools-inline/frontend").then((module) => { | ||
| reactDevtools.current = module; | ||
| }); | ||
| }, []); | ||
|
|
||
| useEffect(() => { | ||
| const unsubscribe = listen((msg) => { | ||
| if (msg.type === "activate-react-devtools") { | ||
| const client = clientId | ||
| ? sandpack.clients[clientId] | ||
| : Object.values(sandpack.clients)[0]; | ||
| const contentWindow = client?.iframe?.contentWindow; | ||
|
|
||
| setDevTools(reactDevtools.current.initialize(contentWindow)); | ||
| } | ||
| }); | ||
|
|
||
| return unsubscribe; | ||
| }, [clientId, listen, sandpack.clients]); | ||
|
|
||
| useEffect(() => { | ||
| sandpack.registerReactDevTools(); | ||
| }, []); | ||
|
|
||
| if (!ReactDevTools) return null; | ||
|
|
||
| const isDarkTheme = isDarkColor(theme.palette.defaultBackground); | ||
|
|
||
| return ( | ||
| <div className={c("devtools")} {...props}> | ||
| <ReactDevTools browserTheme={isDarkTheme ? "dark" : "light"} /> | ||
| </div> | ||
| ); | ||
| }; |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| declare module "react-devtools-inline/frontend"; |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -8649,7 +8649,7 @@ es6-shim@^0.35.5: | |
| resolved "https://registry.yarnpkg.com/es6-shim/-/es6-shim-0.35.6.tgz#d10578301a83af2de58b9eadb7c2c9945f7388a0" | ||
| integrity sha512-EmTr31wppcaIAgblChZiuN/l9Y7DPyw8Xtbg7fIVngn6zMW+IEBJDJngeKC3x6wr0V/vcA2wqeFnaw1bFJbDdA== | ||
|
|
||
| es6-symbol@^3.1.1, es6-symbol@~3.1.3: | ||
| es6-symbol@^3, es6-symbol@^3.1.1, es6-symbol@~3.1.3: | ||
| version "3.1.3" | ||
| resolved "https://registry.yarnpkg.com/es6-symbol/-/es6-symbol-3.1.3.tgz#bad5d3c1bcdac28269f4cb331e431c78ac705d18" | ||
| integrity sha512-NJ6Yn3FuDinBaBRWl/q5X/s4koRHBrgKAu+yGI6JCBeiu3qrcbJhwT2GeR/EXVfylRk8dpQVJoLEFhK+Mu31NA== | ||
|
|
@@ -15769,6 +15769,13 @@ react-dev-utils@^11.0.4: | |
| strip-ansi "6.0.0" | ||
| text-table "0.2.0" | ||
|
|
||
| [email protected]: | ||
| version "4.4.0" | ||
| resolved "https://registry.yarnpkg.com/react-devtools-inline/-/react-devtools-inline-4.4.0.tgz#e032a6eb17a9977b682306f84b46e683adf4bf68" | ||
| integrity sha512-ES0GolSrKO8wsKbsEkVeiR/ZAaHQTY4zDh1UW8DImVmm8oaGLl3ijJDvSGe+qDRKPZdPRnDtWWnSvvrgxXdThQ== | ||
| dependencies: | ||
| es6-symbol "^3" | ||
|
|
||
| react-docgen-typescript@^2.0.0: | ||
| version "2.1.1" | ||
| resolved "https://registry.yarnpkg.com/react-docgen-typescript/-/react-docgen-typescript-2.1.1.tgz#c9f9ccb1fa67e0f4caf3b12f2a07512a201c2dcf" | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like you forgot the "```" ticks for formatting here.