-
Notifications
You must be signed in to change notification settings - Fork 386
feat(devtools): pull up react devtools element inspector from capsule #5300
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
Asuka109
merged 3 commits into
web-infra-dev:main
from
Asuka109:feat/pullup-react-inspector
Jan 24, 2024
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@modern-js/devtools-client': patch | ||
| --- | ||
|
|
||
| feat(devtools): pull up react devtools element inspector from capsule |
23 changes: 23 additions & 0 deletions
23
packages/devtools/client/src/components/Devtools/Button.module.scss
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,23 @@ | ||
| .container { | ||
| width: var(--space-5); | ||
| height: var(--space-5); | ||
| padding: var(--space-1); | ||
| color: var(--gray-12); | ||
| stroke: var(--gray-12); | ||
| display: flex; | ||
| justify-content: center; | ||
| align-items: center; | ||
| transition: opacity 200ms; | ||
|
|
||
| &[data-loading='true'] { | ||
| cursor: wait; | ||
| pointer-events: none; | ||
| } | ||
|
|
||
| &[data-type='default'] { | ||
| opacity: 0.4; | ||
| &:hover { | ||
| opacity: 1; | ||
| } | ||
| } | ||
| } |
30 changes: 30 additions & 0 deletions
30
packages/devtools/client/src/components/Devtools/Button.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,30 @@ | ||
| import React from 'react'; | ||
| import { useAsyncFn } from 'react-use'; | ||
| import { Promisable } from 'type-fest'; | ||
| import { Box } from '@radix-ui/themes'; | ||
| import styles from './Button.module.scss'; | ||
|
|
||
| export interface DevtoolsCapsuleButtonProps extends React.PropsWithChildren { | ||
| type?: 'primary' | 'default'; | ||
| onClick: () => Promisable<void>; | ||
| } | ||
|
|
||
| export const DevtoolsCapsuleButton: React.FC< | ||
| DevtoolsCapsuleButtonProps | ||
| > = props => { | ||
| const [clickState, handleClick] = useAsyncFn( | ||
| () => Promise.resolve(props.onClick()), | ||
| [], | ||
| ); | ||
|
|
||
| return ( | ||
| <Box | ||
| className={styles.container} | ||
| onClick={handleClick} | ||
| data-type={props.type ?? 'default'} | ||
| data-loading={clickState.loading} | ||
| > | ||
| {props.children} | ||
| </Box> | ||
| ); | ||
| }; |
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
36 changes: 36 additions & 0 deletions
36
packages/devtools/client/src/components/Devtools/Puller.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,36 @@ | ||
| import React, { useEffect } from 'react'; | ||
| import { useNavigate } from '@modern-js/runtime/router'; | ||
| import { useThrowable } from '@/utils'; | ||
| import { $mountPoint } from '@/entries/client/routes/state'; | ||
| import { bridge } from '@/entries/client/routes/react/state'; | ||
|
|
||
| let _intendPullUp = false; | ||
|
|
||
| $mountPoint.then(({ hooks }) => { | ||
| hooks.hookOnce('pullUpReactInspector', async () => { | ||
| _intendPullUp = true; | ||
| }); | ||
| }); | ||
|
|
||
| export const DevtoolsPuller: React.FC = () => { | ||
| const navigate = useNavigate(); | ||
| const mountPoint = useThrowable($mountPoint); | ||
| const handlePullUp = async () => { | ||
| navigate('/react'); | ||
| const { store } = await import('@/entries/client/routes/react/state'); | ||
| if (store.backendVersion) { | ||
| bridge.send('startInspectingNative'); | ||
| } else { | ||
| const handleOperations = () => { | ||
| bridge.removeListener('operations', handleOperations); | ||
| bridge.send('startInspectingNative'); | ||
| }; | ||
| bridge.addListener('operations', handleOperations); | ||
| } | ||
| }; | ||
| useEffect(() => { | ||
| _intendPullUp && handlePullUp(); | ||
| mountPoint.hooks.hook('pullUpReactInspector', handlePullUp); | ||
| }, []); | ||
| return null; | ||
| }; |
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
23 changes: 9 additions & 14 deletions
23
packages/devtools/client/src/entries/client/routes/react/[tab]/page.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
13 changes: 13 additions & 0 deletions
13
packages/devtools/client/src/entries/client/routes/react/state.ts
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,13 @@ | ||
| import { createBridge, createStore } from 'react-devtools-inline/frontend'; | ||
| import { $mountPoint } from '../state'; | ||
| import { WallAgent } from '@/utils/react-devtools'; | ||
|
|
||
| export const wallAgent = new WallAgent(); | ||
|
|
||
| $mountPoint.then(mountPoint => { | ||
| wallAgent.bindRemote(mountPoint.remote, 'sendReactDevtoolsData'); | ||
| }); | ||
|
|
||
| export const bridge = createBridge(window.parent, wallAgent); | ||
|
|
||
| export const store = createStore(bridge); |
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.