-
Notifications
You must be signed in to change notification settings - Fork 370
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(devtools): pull up react devtools element inspector from capsule (…
- Loading branch information
Showing
17 changed files
with
203 additions
and
61 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
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 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 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 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
36 changes: 36 additions & 0 deletions
36
packages/devtools/client/src/components/Devtools/Puller.tsx
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 |
---|---|---|
@@ -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 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
23 changes: 9 additions & 14 deletions
23
packages/devtools/client/src/entries/client/routes/react/[tab]/page.tsx
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
13 changes: 13 additions & 0 deletions
13
packages/devtools/client/src/entries/client/routes/react/state.ts
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 |
---|---|---|
@@ -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 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
Oops, something went wrong.