Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
30743443
Commit
30743443
authored
Jul 11, 2025
by
RobPruzan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: detachable panel UI
parent
ed14cd2f
Show whitespace changes
Inline
Side-by-side
Showing
31 changed files
with
1486 additions
and
341 deletions
+1486
-341
dev-overlay.browser.tsx
packages/next/src/next-devtools/dev-overlay.browser.tsx
+31
-6
devtools-indicator.stories.tsx
...ponents/devtools-indicator/devtools-indicator.stories.tsx
+4
-4
devtools-indicator.tsx
...rlay/components/devtools-indicator/devtools-indicator.tsx
+16
-52
next-logo.stories.tsx
...erlay/components/devtools-indicator/next-logo.stories.tsx
+15
-5
next-logo.tsx
...s/dev-overlay/components/devtools-indicator/next-logo.tsx
+52
-40
resize-handle.css
...verlay/components/devtools-panel/resize/resize-handle.css
+33
-33
resize-handle.tsx
...verlay/components/devtools-panel/resize/resize-handle.tsx
+11
-10
resize-provider.tsx
...rlay/components/devtools-panel/resize/resize-provider.tsx
+10
-7
dev-tools-indicator.stories.tsx
...rrors/dev-tools-indicator/dev-tools-indicator.stories.tsx
+22
-27
dev-tools-indicator.tsx
...onents/errors/dev-tools-indicator/dev-tools-indicator.tsx
+7
-7
dev-tools-header.tsx
...s/dev-tools-indicator/dev-tools-info/dev-tools-header.tsx
+46
-0
dev-tools-info.tsx
...ors/dev-tools-indicator/dev-tools-info/dev-tools-info.tsx
+3
-2
route-info.tsx
.../errors/dev-tools-indicator/dev-tools-info/route-info.tsx
+39
-16
turbopack-info.tsx
...ors/dev-tools-indicator/dev-tools-info/turbopack-info.tsx
+17
-9
user-preferences.tsx
...s/dev-tools-indicator/dev-tools-info/user-preferences.tsx
+40
-9
drag-context.tsx
...ay/components/errors/dev-tools-indicator/drag-context.tsx
+86
-0
draggable.tsx
...erlay/components/errors/dev-tools-indicator/draggable.tsx
+68
-43
utils.ts
...ev-overlay/components/errors/dev-tools-indicator/utils.ts
+17
-8
overlay.tsx
...evtools/dev-overlay/components/errors/overlay/overlay.tsx
+2
-1
styles.tsx
...c/next-devtools/dev-overlay/components/overlay/styles.tsx
+3
-1
errors.stories.tsx
...rc/next-devtools/dev-overlay/container/errors.stories.tsx
+1
-0
dev-overlay.stories.tsx
...ext/src/next-devtools/dev-overlay/dev-overlay.stories.tsx
+40
-19
dev-overlay.tsx
packages/next/src/next-devtools/dev-overlay/dev-overlay.tsx
+55
-40
context.tsx
packages/next/src/next-devtools/dev-overlay/menu/context.tsx
+21
-0
dev-overlay-menu.tsx
...t/src/next-devtools/dev-overlay/menu/dev-overlay-menu.tsx
+162
-0
panel-router.tsx
.../next/src/next-devtools/dev-overlay/menu/panel-router.tsx
+319
-0
panel.tsx
packages/next/src/next-devtools/dev-overlay/panel/panel.tsx
+246
-0
shared.ts
packages/next/src/next-devtools/dev-overlay/shared.ts
+63
-1
DevOverlayStoryWrapper.tsx
...devtools/dev-overlay/storybook/DevOverlayStoryWrapper.tsx
+34
-0
use-overlay-reducer.ts
...ext-devtools/dev-overlay/storybook/use-overlay-reducer.ts
+9
-1
indicator-metrics.ts
.../src/next-devtools/dev-overlay/utils/indicator-metrics.ts
+14
-0
No files found.
packages/next/src/next-devtools/dev-overlay.browser.tsx
View file @
30743443
...
@@ -18,9 +18,17 @@ import {
...
@@ -18,9 +18,17 @@ import {
ACTION_RENDERING_INDICATOR_HIDE
,
ACTION_RENDERING_INDICATOR_HIDE
,
ACTION_RENDERING_INDICATOR_SHOW
,
ACTION_RENDERING_INDICATOR_SHOW
,
ACTION_DEVTOOL_UPDATE_ROUTE_STATE
,
ACTION_DEVTOOL_UPDATE_ROUTE_STATE
,
type
OverlayState
,
type
DispatcherEvent
,
}
from
'./dev-overlay/shared'
}
from
'./dev-overlay/shared'
import
{
startTransition
,
useInsertionEffect
}
from
'react'
import
{
createContext
,
startTransition
,
useContext
,
useInsertionEffect
,
type
ActionDispatch
,
}
from
'react'
import
{
createRoot
}
from
'react-dom/client'
import
{
createRoot
}
from
'react-dom/client'
import
{
FontStyles
}
from
'./dev-overlay/font/font-styles'
import
{
FontStyles
}
from
'./dev-overlay/font/font-styles'
import
type
{
HydrationErrorState
}
from
'./shared/hydration-error'
import
type
{
HydrationErrorState
}
from
'./shared/hydration-error'
...
@@ -208,14 +216,31 @@ function DevOverlayRoot({
...
@@ -208,14 +216,31 @@ function DevOverlayRoot({
<>
<>
{
/* Fonts can only be loaded outside the Shadow DOM. */
}
{
/* Fonts can only be loaded outside the Shadow DOM. */
}
<
FontStyles
/>
<
FontStyles
/>
<
DevOverlayContext
value=
{
{
dispatch
,
getSquashedHydrationErrorDetails
,
state
,
}
}
>
<
DevOverlay
<
DevOverlay
state=
{
state
}
// we also pass props for legacy UI
dispatch=
{
dispatch
}
dispatch=
{
dispatch
}
state=
{
state
}
getSquashedHydrationErrorDetails=
{
getSquashedHydrationErrorDetails
}
getSquashedHydrationErrorDetails=
{
getSquashedHydrationErrorDetails
}
/>
/>
</
DevOverlayContext
>
</>
</>
)
)
}
}
export
const
DevOverlayContext
=
createContext
<
{
state
:
OverlayState
&
{
routerType
:
'pages'
|
'app'
}
dispatch
:
ActionDispatch
<
[
action
:
DispatcherEvent
]
>
getSquashedHydrationErrorDetails
:
(
error
:
Error
)
=>
HydrationErrorState
|
null
}
>
(
null
!
)
export
const
useDevOverlayContext
=
()
=>
useContext
(
DevOverlayContext
)
let
isPagesMounted
=
false
let
isPagesMounted
=
false
let
isAppMounted
=
false
let
isAppMounted
=
false
...
...
packages/next/src/next-devtools/dev-overlay/components/devtools-indicator/devtools-indicator.stories.tsx
View file @
30743443
import
type
{
Meta
,
StoryObj
}
from
'@storybook/react'
import
type
{
Meta
,
StoryObj
}
from
'@storybook/react'
import
type
{
OverlayState
}
from
'../../shared'
import
type
{
OverlayState
}
from
'../../shared'
import
{
DevToolsIndicator
}
from
'./devtools-indicator'
import
{
DevToolsIndicator
New
}
from
'./devtools-indicator'
import
{
INITIAL_OVERLAY_STATE
}
from
'../../shared'
import
{
INITIAL_OVERLAY_STATE
}
from
'../../shared'
import
{
withShadowPortal
}
from
'../../storybook/with-shadow-portal'
import
{
withShadowPortal
}
from
'../../storybook/with-shadow-portal'
const
meta
:
Meta
<
typeof
DevToolsIndicator
>
=
{
const
meta
:
Meta
<
typeof
DevToolsIndicator
New
>
=
{
component
:
DevToolsIndicator
,
component
:
DevToolsIndicator
New
,
parameters
:
{
parameters
:
{
layout
:
'centered'
,
layout
:
'centered'
,
},
},
...
@@ -37,7 +37,7 @@ const meta: Meta<typeof DevToolsIndicator> = {
...
@@ -37,7 +37,7 @@ const meta: Meta<typeof DevToolsIndicator> = {
}
}
export
default
meta
export
default
meta
type
Story
=
StoryObj
<
typeof
DevToolsIndicator
>
type
Story
=
StoryObj
<
typeof
DevToolsIndicator
New
>
const
state
:
OverlayState
=
{
const
state
:
OverlayState
=
{
...
INITIAL_OVERLAY_STATE
,
...
INITIAL_OVERLAY_STATE
,
...
...
packages/next/src/next-devtools/dev-overlay/components/devtools-indicator/devtools-indicator.tsx
View file @
30743443
import
type
{
CSSProperties
}
from
'react'
import
type
{
CSSProperties
}
from
'react'
import
type
{
OverlayState
,
OverlayDispatch
}
from
'../../shared'
import
{
useState
}
from
'react'
import
{
NextLogoNew
}
from
'./next-logo'
import
{
NextLogo
}
from
'./next-logo'
import
{
Toast
}
from
'../toast'
import
{
Toast
}
from
'../toast'
import
{
import
{
MENU_CURVE
,
MENU_CURVE
,
MENU_DURATION_MS
,
MENU_DURATION_MS
,
}
from
'../errors/dev-tools-indicator/utils'
}
from
'../errors/dev-tools-indicator/utils'
import
{
import
{
STORAGE_KEY_POSITION
,
ACTION_DEVTOOLS_POSITION
}
from
'../../shared'
ACTION_DEVTOOLS_PANEL_TOGGLE
,
STORAGE_KEY_POSITION
,
ACTION_DEVTOOLS_POSITION
,
ACTION_DEVTOOLS_PANEL_OPEN
,
ACTION_ERROR_OVERLAY_OPEN
,
}
from
'../../shared'
import
{
Draggable
}
from
'../errors/dev-tools-indicator/draggable'
import
{
Draggable
}
from
'../errors/dev-tools-indicator/draggable'
import
{
useDevOverlayContext
}
from
'../../../dev-overlay.browser'
import
{
usePanelRouterContext
}
from
'../../menu/context'
export
const
INDICATOR_PADDING
=
20
export
const
INDICATOR_PADDING
=
20
export
function
DevToolsIndicator
({
export
function
DevToolsIndicatorNew
()
{
state
,
const
{
state
,
dispatch
}
=
useDevOverlayContext
()
dispatch
,
const
{
triggerRef
,
setPanel
}
=
usePanelRouterContext
()
errorCount
,
isBuildError
,
}:
{
state
:
OverlayState
dispatch
:
OverlayDispatch
errorCount
:
number
isBuildError
:
boolean
})
{
const
[
open
,
setOpen
]
=
useState
(
false
)
const
[
vertical
,
horizontal
]
=
state
.
devToolsPosition
.
split
(
'-'
,
2
)
const
[
vertical
,
horizontal
]
=
state
.
devToolsPosition
.
split
(
'-'
,
2
)
const
enableErrorOverlayMode
=
()
=>
{
dispatch
({
type
:
ACTION_ERROR_OVERLAY_OPEN
})
// Open the DevTools panel to view as error overlay mode.
dispatch
({
type
:
ACTION_DEVTOOLS_PANEL_OPEN
})
}
const
toggleDevToolsPanel
=
()
=>
{
dispatch
({
type
:
ACTION_DEVTOOLS_PANEL_TOGGLE
})
}
return
(
return
(
// TODO: why is this called a toast
<
Toast
<
Toast
data
-
nextjs
-
toast
data
-
nextjs
-
toast
style=
{
style=
{
...
@@ -54,16 +30,12 @@ export function DevToolsIndicator({
...
@@ -54,16 +30,12 @@ export function DevToolsIndicator({
boxShadow
:
'none'
,
boxShadow
:
'none'
,
[
vertical
]:
`${INDICATOR_PADDING}px`
,
[
vertical
]:
`${INDICATOR_PADDING}px`
,
[
horizontal
]:
`${INDICATOR_PADDING}px`
,
[
horizontal
]:
`${INDICATOR_PADDING}px`
,
visibility
:
visibility
:
state
.
isErrorOverlayOpen
?
'hidden'
:
'visible'
,
state
.
isDevToolsPanelOpen
||
state
.
isErrorOverlayOpen
?
'hidden'
:
'visible'
,
}
as
CSSProperties
}
as
CSSProperties
}
}
>
>
<
Draggable
<
Draggable
padding=
{
INDICATOR_PADDING
}
padding=
{
INDICATOR_PADDING
}
onDragStart=
{
()
=>
setOpen
(
false
)
}
position=
{
state
.
devToolsPosition
}
position=
{
state
.
devToolsPosition
}
setPosition=
{
(
p
)
=>
{
setPosition=
{
(
p
)
=>
{
dispatch
({
dispatch
({
...
@@ -73,21 +45,13 @@ export function DevToolsIndicator({
...
@@ -73,21 +45,13 @@ export function DevToolsIndicator({
localStorage
.
setItem
(
STORAGE_KEY_POSITION
,
p
)
localStorage
.
setItem
(
STORAGE_KEY_POSITION
,
p
)
}
}
}
}
>
>
{
/* Trigger */
}
<
NextLogoNew
<
NextLogo
onTriggerClick=
{
()
=>
{
aria
-
haspopup=
"menu"
setPanel
((
prev
)
=>
aria
-
expanded=
{
open
}
prev
===
'panel-selector'
?
null
:
'panel-selector'
aria
-
controls=
"nextjs-dev-tools-menu"
)
aria
-
label=
{
`${open ? 'Close' : 'Open'} Next.js Dev Tools`
}
}
}
data
-
nextjs
-
dev
-
tools
-
button
ref=
{
triggerRef
}
disabled=
{
state
.
disableDevIndicator
}
issueCount=
{
errorCount
}
onTriggerClick=
{
toggleDevToolsPanel
}
toggleErrorOverlay=
{
enableErrorOverlayMode
}
isDevBuilding=
{
state
.
buildingIndicator
}
isDevRendering=
{
state
.
renderingIndicator
}
isBuildError=
{
isBuildError
}
scale=
{
state
.
scale
}
/>
/>
</
Draggable
>
</
Draggable
>
</
Toast
>
</
Toast
>
...
...
packages/next/src/next-devtools/dev-overlay/components/devtools-indicator/next-logo.stories.tsx
View file @
30743443
import
type
{
Meta
,
StoryObj
}
from
'@storybook/react'
import
type
{
Meta
,
StoryObj
}
from
'@storybook/react'
import
{
NextLogo
}
from
'./next-logo'
import
{
NextLogo
New
}
from
'./next-logo'
import
{
withShadowPortal
}
from
'../../storybook/with-shadow-portal'
import
{
withShadowPortal
}
from
'../../storybook/with-shadow-portal'
// TODO(rob): this storybook's configurability is broken intentionally
// it will be restored when we wrap it in the storybook context addon https://storybook.js.org/addons/storybook-react-context
const
StoryBookNextLogo
=
(
_
:
{
issueCount
:
number
isDevBuilding
:
boolean
isDevRendering
:
boolean
}
&
Record
<
string
,
unknown
>
)
=>
{
return
<
NextLogoNew
onTriggerClick=
{
()
=>
{}
}
/>
}
const
meta
:
Meta
<
typeof
NextLogo
>
=
{
const
meta
:
Meta
<
typeof
StoryBook
NextLogo
>
=
{
component
:
NextLogo
,
component
:
StoryBook
NextLogo
,
parameters
:
{
parameters
:
{
layout
:
'centered'
,
layout
:
'centered'
,
},
},
args
:
{
args
:
{
'aria-label'
:
'Open Next.js DevTools'
,
'aria-label'
:
'Open Next.js DevTools'
,
onClick
:
()
=>
console
.
log
(
'Clicked!'
),
},
},
decorators
:
[
withShadowPortal
],
decorators
:
[
withShadowPortal
],
}
}
export
default
meta
export
default
meta
type
Story
=
StoryObj
<
typeof
NextLogo
>
type
Story
=
StoryObj
<
typeof
StoryBook
NextLogo
>
export
const
NoIssues
:
Story
=
{
export
const
NoIssues
:
Story
=
{
args
:
{
args
:
{
...
...
packages/next/src/next-devtools/dev-overlay/components/devtools-indicator/next-logo.tsx
View file @
30743443
import
type
{
DevToolsScale
}
from
'../errors/dev-tools-indicator/dev-tools-info/preferences'
import
{
useEffect
,
useRef
,
useState
}
from
'react'
import
{
useEffect
,
useRef
,
useState
}
from
'react'
import
{
useUpdateAnimation
}
from
'./hooks/use-update-animation'
import
{
useUpdateAnimation
}
from
'./hooks/use-update-animation'
import
{
useMeasureWidth
}
from
'./hooks/use-measure-width'
import
{
useMeasureWidth
}
from
'./hooks/use-measure-width'
...
@@ -7,45 +5,42 @@ import { useMinimumLoadingTimeMultiple } from './hooks/use-minimum-loading-time-
...
@@ -7,45 +5,42 @@ import { useMinimumLoadingTimeMultiple } from './hooks/use-minimum-loading-time-
import
{
Cross
}
from
'../../icons/cross'
import
{
Cross
}
from
'../../icons/cross'
import
{
Warning
}
from
'../../icons/warning'
import
{
Warning
}
from
'../../icons/warning'
import
{
css
}
from
'../../utils/css'
import
{
css
}
from
'../../utils/css'
import
{
useDevOverlayContext
}
from
'../../../dev-overlay.browser'
interface
Props
extends
React
.
ComponentProps
<
'button'
>
{
import
{
useRenderErrorContext
}
from
'../../dev-overlay'
issueCount
:
number
import
{
isDevBuilding
:
boolean
ACTION_DEVTOOLS_PANEL_OPEN
,
isDevRendering
:
boolean
ACTION_ERROR_OVERLAY_OPEN
,
isBuildError
:
boolean
}
from
'../../shared'
onTriggerClick
:
()
=>
void
import
{
usePanelRouterContext
}
from
'../../menu/context'
toggleErrorOverlay
:
()
=>
void
scale
:
DevToolsScale
}
const
SHORT_DURATION_MS
=
150
const
SHORT_DURATION_MS
=
150
export
function
NextLogo
({
export
function
NextLogoNew
({
disabled
,
issueCount
,
isDevBuilding
,
isDevRendering
,
isBuildError
,
onTriggerClick
,
onTriggerClick
,
toggleErrorOverlay
,
...
buttonProps
scale
=
1
,
}:
{
onTriggerClick
:
()
=>
void
}
&
React
.
ComponentProps
<
'button'
>
)
{
...
props
const
{
state
,
dispatch
}
=
useDevOverlayContext
()
}:
Props
)
{
const
{
totalErrorCount
}
=
useRenderErrorContext
()
const
SIZE
=
36
/
scale
const
SIZE
=
36
/
state
.
scale
const
{
panel
}
=
usePanelRouterContext
()
const
hasError
=
issueCount
>
0
const
isMenuOpen
=
panel
===
'panel-selector'
const
hasError
=
totalErrorCount
>
0
const
[
isErrorExpanded
,
setIsErrorExpanded
]
=
useState
(
hasError
)
const
[
isErrorExpanded
,
setIsErrorExpanded
]
=
useState
(
hasError
)
const
[
dismissed
,
setDismissed
]
=
useState
(
false
)
const
[
dismissed
,
setDismissed
]
=
useState
(
false
)
const
newErrorDetected
=
useUpdateAnimation
(
issueCount
,
SHORT_DURATION_MS
)
const
newErrorDetected
=
useUpdateAnimation
(
totalErrorCount
,
SHORT_DURATION_MS
)
const
triggerRef
=
useRef
<
HTMLButtonElement
|
null
>
(
null
)
const
triggerRef
=
useRef
<
HTMLButtonElement
|
null
>
(
null
)
const
ref
=
useRef
<
HTMLDivElement
|
null
>
(
null
)
const
ref
=
useRef
<
HTMLDivElement
|
null
>
(
null
)
const
measuredWidth
=
useMeasureWidth
(
ref
)
const
measuredWidth
=
useMeasureWidth
(
ref
)
const
isLoading
=
useMinimumLoadingTimeMultiple
(
const
isLoading
=
useMinimumLoadingTimeMultiple
(
isDevBuilding
||
isDevRendering
state
.
buildingIndicator
||
state
.
renderingIndicator
)
)
const
isExpanded
=
isErrorExpanded
||
disabled
const
isExpanded
=
isErrorExpanded
||
state
.
disableDevIndicator
const
width
=
measuredWidth
===
0
?
'auto'
:
measuredWidth
const
width
=
measuredWidth
===
0
?
'auto'
:
measuredWidth
useEffect
(()
=>
{
useEffect
(()
=>
{
...
@@ -61,7 +56,10 @@ export function NextLogo({
...
@@ -61,7 +56,10 @@ export function NextLogo({
'--duration-short'
:
`${SHORT_DURATION_MS}ms`
,
'--duration-short'
:
`${SHORT_DURATION_MS}ms`
,
// if the indicator is disabled, hide the badge
// if the indicator is disabled, hide the badge
// also allow the "disabled" state be dismissed, as long as there are no build errors
// also allow the "disabled" state be dismissed, as long as there are no build errors
display
:
disabled
&&
(
!
hasError
||
dismissed
)
?
'none'
:
'block'
,
display
:
state
.
disableDevIndicator
&&
(
!
hasError
||
dismissed
)
?
'none'
:
'block'
,
}
as
React
.
CSSProperties
}
as
React
.
CSSProperties
}
}
>
>
...
@@ -396,15 +394,25 @@ export function NextLogo({
...
@@ -396,15 +394,25 @@ export function NextLogo({
>
>
<
div
ref=
{
ref
}
>
<
div
ref=
{
ref
}
>
{
/* Children */
}
{
/* Children */
}
{
!
disabled
&&
(
{
!
state
.
disableDevIndicator
&&
(
<
button
<
button
id=
"next-logo"
ref=
{
triggerRef
}
ref=
{
triggerRef
}
data
-
next
-
mark
data
-
next
-
mark
data
-
next
-
mark
-
loading=
{
isLoading
}
data
-
next
-
mark
-
loading=
{
isLoading
}
onClick=
{
onTriggerClick
}
onClick=
{
onTriggerClick
}
{
...
props
}
disabled=
{
state
.
disableDevIndicator
}
aria
-
haspopup=
"menu"
aria
-
expanded=
{
isMenuOpen
}
aria
-
controls=
"nextjs-dev-tools-menu"
aria
-
label=
{
`${isMenuOpen ? 'Close' : 'Open'} Next.js Dev Tools`
}
data
-
nextjs
-
dev
-
tools
-
button
{
...
buttonProps
}
>
>
<
NextMark
isLoading=
{
isLoading
}
isDevBuilding=
{
isDevBuilding
}
/>
<
NextMark
isLoading=
{
isLoading
}
isDevBuilding=
{
state
.
buildingIndicator
}
/>
</
button
>
</
button
>
)
}
)
}
{
isExpanded
&&
(
{
isExpanded
&&
(
...
@@ -412,42 +420,46 @@ export function NextLogo({
...
@@ -412,42 +420,46 @@ export function NextLogo({
<
button
<
button
data
-
issues
-
open
data
-
issues
-
open
aria
-
label=
"Open issues overlay"
aria
-
label=
"Open issues overlay"
onClick=
{
toggleErrorOverlay
}
onClick=
{
()
=>
{
dispatch
({
type
:
ACTION_ERROR_OVERLAY_OPEN
})
// Open the DevTools panel to view as error overlay mode.
dispatch
({
type
:
ACTION_DEVTOOLS_PANEL_OPEN
})
}
}
>
>
{
disabled
&&
(
{
state
.
disableDevIndicator
&&
(
<
div
data
-
disabled
-
icon
>
<
div
data
-
disabled
-
icon
>
<
Warning
/>
<
Warning
/>
</
div
>
</
div
>
)
}
)
}
<
AnimateCount
<
AnimateCount
// Used the key to force a re-render when the count changes.
// Used the key to force a re-render when the count changes.
key=
{
issue
Count
}
key=
{
totalError
Count
}
animate=
{
newErrorDetected
}
animate=
{
newErrorDetected
}
data
-
issues
-
count
-
animation
data
-
issues
-
count
-
animation
>
>
{
issue
Count
}
{
totalError
Count
}
</
AnimateCount
>
{
' '
}
</
AnimateCount
>
{
' '
}
<
div
>
<
div
>
Issue
Issue
{
issue
Count
>
1
&&
(
{
totalError
Count
>
1
&&
(
<
span
<
span
aria
-
hidden
aria
-
hidden
data
-
issues
-
count
-
plural
data
-
issues
-
count
-
plural
// This only needs to animate once the count changes from 1 -> 2,
// This only needs to animate once the count changes from 1 -> 2,
// otherwise it should stay static between re-renders.
// otherwise it should stay static between re-renders.
data
-
animate=
{
newErrorDetected
&&
issue
Count
===
2
}
data
-
animate=
{
newErrorDetected
&&
totalError
Count
===
2
}
>
>
s
s
</
span
>
</
span
>
)
}
)
}
</
div
>
</
div
>
</
button
>
</
button
>
{
!
isB
uildError
&&
(
{
!
state
.
b
uildError
&&
(
<
button
<
button
data
-
issues
-
collapse
data
-
issues
-
collapse
aria
-
label=
"Collapse issues badge"
aria
-
label=
"Collapse issues badge"
onClick=
{
()
=>
{
onClick=
{
()
=>
{
if
(
disabled
)
{
if
(
state
.
disableDevIndicator
)
{
setDismissed
(
true
)
setDismissed
(
true
)
}
else
{
}
else
{
setIsErrorExpanded
(
false
)
setIsErrorExpanded
(
false
)
...
...
packages/next/src/next-devtools/dev-overlay/components/devtools-panel/resize/resize-handle.css
View file @
30743443
...
@@ -20,14 +20,14 @@
...
@@ -20,14 +20,14 @@
/* start really fast because we start super hidden initially behind the panel, otherwise feels like an unintended animation delay */
/* start really fast because we start super hidden initially behind the panel, otherwise feels like an unintended animation delay */
.resize-container
:hover
~
.resize-line
{
.resize-container
:hover
~
.resize-line
{
transition
:
transform
0.2
s
cubic-bezier
(
0.05
,
0.9
,
0.2
,
1
);
/* Fast start for animate in */
transition
:
transform
0.2
5s
cubic-bezier
(
0.23
,
1
,
0.32
,
1
);
}
}
.resize-container.right
,
.resize-container.right
,
.resize-container.left
{
.resize-container.left
{
top
:
0
;
top
:
0
;
height
:
100%
;
height
:
100%
;
width
:
2
5
px
;
width
:
2
2
px
;
cursor
:
ew-resize
;
cursor
:
ew-resize
;
}
}
...
@@ -37,97 +37,97 @@
...
@@ -37,97 +37,97 @@
.resize-container.top
{
.resize-container.top
{
left
:
0
;
left
:
0
;
width
:
100%
;
width
:
100%
;
height
:
2
5
px
;
height
:
2
2
px
;
cursor
:
ns-resize
;
cursor
:
ns-resize
;
}
}
.resize-container.top
{
.resize-container.top
{
top
:
-
12
px
;
top
:
-
7
px
;
}
}
.resize-container.bottom
{
.resize-container.bottom
{
bottom
:
-
12
px
;
bottom
:
-
7
px
;
}
}
.resize-container.left
{
.resize-container.left
{
left
:
-
12
px
;
left
:
-
7
px
;
}
}
.resize-container.right
{
.resize-container.right
{
right
:
-
12
px
;
right
:
-
7
px
;
}
}
.resize-container.top-left
,
.resize-container.top-left
,
.resize-container.top-right
,
.resize-container.top-right
,
.resize-container.bottom-left
,
.resize-container.bottom-left
,
.resize-container.bottom-right
{
.resize-container.bottom-right
{
width
:
32
px
;
width
:
26
px
;
height
:
32
px
;
height
:
26
px
;
z-index
:
15
;
z-index
:
15
;
}
}
.resize-container.top-left
{
.resize-container.top-left
{
top
:
-
16
px
;
top
:
-
5
px
;
left
:
-
16
px
;
left
:
-
5
px
;
cursor
:
nwse-resize
;
cursor
:
nwse-resize
;
}
}
.resize-container.top-right
{
.resize-container.top-right
{
top
:
-
16
px
;
top
:
-
5
px
;
right
:
-
16
px
;
right
:
-
5
px
;
cursor
:
nesw-resize
;
cursor
:
nesw-resize
;
}
}
.resize-container.bottom-left
{
.resize-container.bottom-left
{
bottom
:
-
16
px
;
bottom
:
-
5
px
;
left
:
-
16
px
;
left
:
-
5
px
;
cursor
:
nesw-resize
;
cursor
:
nesw-resize
;
}
}
.resize-container.bottom-right
{
.resize-container.bottom-right
{
bottom
:
-
16
px
;
bottom
:
-
5
px
;
right
:
-
16
px
;
right
:
-
5
px
;
cursor
:
nwse-resize
;
cursor
:
nwse-resize
;
}
}
.resize-line.top
,
.resize-line.top
,
.resize-line.bottom
{
.resize-line.bottom
{
height
:
2
8px
;
height
:
1
8px
;
width
:
100%
;
width
:
100%
;
background-color
:
var
(
--color-background-
1
00
);
background-color
:
var
(
--color-background-
2
00
);
}
}
.resize-line.left
,
.resize-line.left
,
.resize-line.right
{
.resize-line.right
{
width
:
2
8px
;
width
:
1
8px
;
height
:
100%
;
height
:
100%
;
background-color
:
var
(
--color-background-
1
00
);
background-color
:
var
(
--color-background-
2
00
);
}
}
.resize-line.top
{
.resize-line.top
{
top
:
-
12
px
;
top
:
-
7
px
;
left
:
calc
(
-1
*
var
(
--border-left
,
2px
));
left
:
calc
(
-1
*
var
(
--border-left
,
2px
));
width
:
calc
(
100%
+
var
(
--border-horizontal
,
4px
));
width
:
calc
(
100%
+
var
(
--border-horizontal
,
4px
));
border-radius
:
var
(
--rounded-md
)
var
(
--rounded-md
)
0
0
;
border-radius
:
var
(
--rounded-md
)
var
(
--rounded-md
)
0
0
;
transform
:
translateY
(
2
8px
);
transform
:
translateY
(
1
8px
);
}
}
.resize-line.bottom
{
.resize-line.bottom
{
bottom
:
-
12
px
;
bottom
:
-
7
px
;
left
:
calc
(
-1
*
var
(
--border-left
,
2px
));
left
:
calc
(
-1
*
var
(
--border-left
,
2px
));
width
:
calc
(
100%
+
var
(
--border-horizontal
,
4px
));
width
:
calc
(
100%
+
var
(
--border-horizontal
,
4px
));
border-radius
:
0
0
var
(
--rounded-md
)
var
(
--rounded-md
);
border-radius
:
0
0
var
(
--rounded-md
)
var
(
--rounded-md
);
transform
:
translateY
(
-
2
8px
);
transform
:
translateY
(
-
1
8px
);
}
}
.resize-line.left
{
.resize-line.left
{
top
:
calc
(
-1
*
var
(
--border-top
,
2px
));
top
:
calc
(
-1
*
var
(
--border-top
,
2px
));
left
:
-
12
px
;
left
:
-
7
px
;
height
:
calc
(
100%
+
var
(
--border-vertical
,
4px
));
height
:
calc
(
100%
+
var
(
--border-vertical
,
4px
));
border-radius
:
var
(
--rounded-md
)
0
0
var
(
--rounded-md
);
border-radius
:
var
(
--rounded-md
)
0
0
var
(
--rounded-md
);
transform
:
translateX
(
2
8px
);
transform
:
translateX
(
1
8px
);
}
}
.resize-line.right
{
.resize-line.right
{
top
:
calc
(
-1
*
var
(
--border-top
,
2px
));
top
:
calc
(
-1
*
var
(
--border-top
,
2px
));
right
:
-
12
px
;
right
:
-
7
px
;
height
:
calc
(
100%
+
var
(
--border-vertical
,
4px
));
height
:
calc
(
100%
+
var
(
--border-vertical
,
4px
));
border-radius
:
0
var
(
--rounded-md
)
var
(
--rounded-md
)
0
;
border-radius
:
0
var
(
--rounded-md
)
var
(
--rounded-md
)
0
;
transform
:
translateX
(
-
2
8px
);
transform
:
translateX
(
-
1
8px
);
}
}
.resize-container.right
:hover
~
.resize-line.right
,
.resize-container.right
:hover
~
.resize-line.right
,
...
@@ -149,14 +149,14 @@
...
@@ -149,14 +149,14 @@
* regardless of hover state
* regardless of hover state
*/
*/
.resize-container.no-hover.right
:hover
~
.resize-line.right
{
.resize-container.no-hover.right
:hover
~
.resize-line.right
{
transform
:
translateX
(
-2
8
px
);
transform
:
translateX
(
-2
0
px
);
}
}
.resize-container.no-hover.left
:hover
~
.resize-line.left
{
.resize-container.no-hover.left
:hover
~
.resize-line.left
{
transform
:
translateX
(
2
8
px
);
transform
:
translateX
(
2
0
px
);
}
}
.resize-container.no-hover.bottom
:hover
~
.resize-line.bottom
{
.resize-container.no-hover.bottom
:hover
~
.resize-line.bottom
{
transform
:
translateY
(
-2
8
px
);
transform
:
translateY
(
-2
0
px
);
}
}
.resize-container.no-hover.top
:hover
~
.resize-line.top
{
.resize-container.no-hover.top
:hover
~
.resize-line.top
{
transform
:
translateY
(
2
8
px
);
transform
:
translateY
(
2
0
px
);
}
}
packages/next/src/next-devtools/dev-overlay/components/devtools-panel/resize/resize-handle.tsx
View file @
30743443
...
@@ -3,14 +3,18 @@ import type { Corners } from '../../../shared'
...
@@ -3,14 +3,18 @@ import type { Corners } from '../../../shared'
import
{
useResize
,
type
ResizeDirection
}
from
'./resize-provider'
import
{
useResize
,
type
ResizeDirection
}
from
'./resize-provider'
import
'./resize-handle.css'
import
'./resize-handle.css'
const
STORAGE_KEY_DIMENSIONS
=
'nextjs-devtools-dimensions'
export
const
ResizeHandle
=
({
direction
,
export
const
ResizeHandle
=
({
direction
}:
{
direction
:
ResizeDirection
})
=>
{
position
,
}:
{
direction
:
ResizeDirection
position
:
Corners
})
=>
{
const
{
const
{
resizeRef
,
resizeRef
,
minWidth
,
minWidth
,
minHeight
,
minHeight
,
devToolsPosition
,
storageKey
,
draggingDirection
,
draggingDirection
,
setDraggingDirection
,
setDraggingDirection
,
}
=
useResize
()
}
=
useResize
()
...
@@ -44,13 +48,13 @@ export const ResizeHandle = ({ direction }: { direction: ResizeDirection }) => {
...
@@ -44,13 +48,13 @@ export const ResizeHandle = ({ direction }: { direction: ResizeDirection }) => {
// we block the sides of the corner its in (bottom-left has bottom and left sides blocked from resizing)
// we block the sides of the corner its in (bottom-left has bottom and left sides blocked from resizing)
// because there shouldn't be anywhere to resize, and if the user decides to resize from that point it
// because there shouldn't be anywhere to resize, and if the user decides to resize from that point it
// would be unhandled/slightly janky (the component would have to re-magnetic-snap after the resize)
// would be unhandled/slightly janky (the component would have to re-magnetic-snap after the resize)
if
(
devToolsP
osition
.
split
(
'-'
).
includes
(
direction
))
return
false
if
(
p
osition
.
split
(
'-'
).
includes
(
direction
))
return
false
// same logic as above, but the only corner resize that makes
// same logic as above, but the only corner resize that makes
// sense is the corner fully exposed (the opposing corner)
// sense is the corner fully exposed (the opposing corner)
const
isCorner
=
direction
.
includes
(
'-'
)
const
isCorner
=
direction
.
includes
(
'-'
)
if
(
isCorner
)
{
if
(
isCorner
)
{
const
opposite
=
getOppositeCorner
(
devToolsP
osition
)
const
opposite
=
getOppositeCorner
(
p
osition
)
return
direction
===
opposite
return
direction
===
opposite
}
}
...
@@ -123,10 +127,7 @@ export const ResizeHandle = ({ direction }: { direction: ResizeDirection }) => {
...
@@ -123,10 +127,7 @@ export const ResizeHandle = ({ direction }: { direction: ResizeDirection }) => {
// invariant ref exists
// invariant ref exists
const
{
width
,
height
}
=
resizeRef
.
current
!
.
getBoundingClientRect
()
const
{
width
,
height
}
=
resizeRef
.
current
!
.
getBoundingClientRect
()
localStorage
.
setItem
(
localStorage
.
setItem
(
storageKey
,
JSON
.
stringify
({
width
,
height
}))
STORAGE_KEY_DIMENSIONS
,
JSON
.
stringify
({
width
,
height
})
)
}
}
document
.
addEventListener
(
'mousemove'
,
handleMouseMove
)
document
.
addEventListener
(
'mousemove'
,
handleMouseMove
)
document
.
addEventListener
(
'mouseup'
,
handleMouseUp
)
document
.
addEventListener
(
'mouseup'
,
handleMouseUp
)
...
...
packages/next/src/next-devtools/dev-overlay/components/devtools-panel/resize/resize-provider.tsx
View file @
30743443
...
@@ -22,9 +22,9 @@ interface ResizeContextValue {
...
@@ -22,9 +22,9 @@ interface ResizeContextValue {
resizeRef
:
RefObject
<
HTMLElement
|
null
>
resizeRef
:
RefObject
<
HTMLElement
|
null
>
minWidth
:
number
minWidth
:
number
minHeight
:
number
minHeight
:
number
devToolsPosition
:
Corners
draggingDirection
:
ResizeDirection
|
null
draggingDirection
:
ResizeDirection
|
null
setDraggingDirection
:
(
direction
:
ResizeDirection
|
null
)
=>
void
setDraggingDirection
:
(
direction
:
ResizeDirection
|
null
)
=>
void
storageKey
:
string
}
}
const
ResizeContext
=
createContext
<
ResizeContextValue
>
(
null
!
)
const
ResizeContext
=
createContext
<
ResizeContextValue
>
(
null
!
)
...
@@ -44,8 +44,8 @@ const constrainDimensions = (params: {
...
@@ -44,8 +44,8 @@ const constrainDimensions = (params: {
}
}
}
}
const
parseResizeLocalStorage
=
()
=>
{
const
parseResizeLocalStorage
=
(
key
:
string
)
=>
{
const
savedDimensions
=
localStorage
.
getItem
(
STORAGE_KEY_DIMENSIONS
)
const
savedDimensions
=
localStorage
.
getItem
(
key
)
if
(
!
savedDimensions
)
return
null
if
(
!
savedDimensions
)
return
null
try
{
try
{
const
parsed
=
JSON
.
parse
(
savedDimensions
)
const
parsed
=
JSON
.
parse
(
savedDimensions
)
...
@@ -59,7 +59,7 @@ const parseResizeLocalStorage = () => {
...
@@ -59,7 +59,7 @@ const parseResizeLocalStorage = () => {
}
}
return
null
return
null
}
catch
(
e
)
{
}
catch
(
e
)
{
localStorage
.
removeItem
(
STORAGE_KEY_DIMENSIONS
)
localStorage
.
removeItem
(
key
)
return
null
return
null
}
}
}
}
...
@@ -70,6 +70,7 @@ interface ResizeProviderProps {
...
@@ -70,6 +70,7 @@ interface ResizeProviderProps {
minWidth
?:
number
minWidth
?:
number
minHeight
?:
number
minHeight
?:
number
devToolsPosition
:
Corners
devToolsPosition
:
Corners
storageKey
?:
string
}
}
children
:
React
.
ReactNode
children
:
React
.
ReactNode
}
}
...
@@ -80,6 +81,8 @@ export const ResizeProvider = ({ value, children }: ResizeProviderProps) => {
...
@@ -80,6 +81,8 @@ export const ResizeProvider = ({ value, children }: ResizeProviderProps) => {
const
[
draggingDirection
,
setDraggingDirection
]
=
const
[
draggingDirection
,
setDraggingDirection
]
=
useState
<
ResizeDirection
|
null
>
(
null
)
useState
<
ResizeDirection
|
null
>
(
null
)
const
storageKey
=
value
.
storageKey
??
STORAGE_KEY_DIMENSIONS
useLayoutEffect
(()
=>
{
useLayoutEffect
(()
=>
{
const
applyConstrainedDimensions
=
()
=>
{
const
applyConstrainedDimensions
=
()
=>
{
if
(
!
value
.
resizeRef
.
current
)
return
if
(
!
value
.
resizeRef
.
current
)
return
...
@@ -91,7 +94,7 @@ export const ResizeProvider = ({ value, children }: ResizeProviderProps) => {
...
@@ -91,7 +94,7 @@ export const ResizeProvider = ({ value, children }: ResizeProviderProps) => {
// an optimization if this is too expensive is to maintain the current
// an optimization if this is too expensive is to maintain the current
// container size in a ref and update it on resize, which is essentially
// container size in a ref and update it on resize, which is essentially
// what we're doing here, just dumber
// what we're doing here, just dumber
const
dim
=
parseResizeLocalStorage
()
const
dim
=
parseResizeLocalStorage
(
storageKey
)
if
(
!
dim
)
{
if
(
!
dim
)
{
return
return
}
}
...
@@ -110,7 +113,7 @@ export const ResizeProvider = ({ value, children }: ResizeProviderProps) => {
...
@@ -110,7 +113,7 @@ export const ResizeProvider = ({ value, children }: ResizeProviderProps) => {
window
.
addEventListener
(
'resize'
,
applyConstrainedDimensions
)
window
.
addEventListener
(
'resize'
,
applyConstrainedDimensions
)
return
()
=>
return
()
=>
window
.
removeEventListener
(
'resize'
,
applyConstrainedDimensions
)
window
.
removeEventListener
(
'resize'
,
applyConstrainedDimensions
)
},
[
value
.
resizeRef
,
minWidth
,
minHeight
])
},
[
value
.
resizeRef
,
minWidth
,
minHeight
,
storageKey
])
return
(
return
(
<
ResizeContext
.
Provider
<
ResizeContext
.
Provider
...
@@ -118,9 +121,9 @@ export const ResizeProvider = ({ value, children }: ResizeProviderProps) => {
...
@@ -118,9 +121,9 @@ export const ResizeProvider = ({ value, children }: ResizeProviderProps) => {
resizeRef
:
value
.
resizeRef
,
resizeRef
:
value
.
resizeRef
,
minWidth
,
minWidth
,
minHeight
,
minHeight
,
devToolsPosition
:
value
.
devToolsPosition
,
draggingDirection
,
draggingDirection
,
setDraggingDirection
,
setDraggingDirection
,
storageKey
,
}
}
}
}
>
>
{
children
}
{
children
}
...
...
packages/next/src/next-devtools/dev-overlay/components/errors/dev-tools-indicator/dev-tools-indicator.stories.tsx
View file @
30743443
import
type
{
Meta
,
StoryObj
}
from
'@storybook/react'
import
type
{
Meta
,
StoryObj
}
from
'@storybook/react'
import
{
Dev
ToolsIndicator
}
from
'./dev-tools-indicato
r'
import
{
Dev
OverlayStoryWrapper
}
from
'../../../storybook/DevOverlayStoryWrappe
r'
import
{
withShadowPortal
}
from
'../../../storybook/with-shadow-portal'
import
{
withShadowPortal
}
from
'../../../storybook/with-shadow-portal'
import
type
{
VersionInfo
}
from
'../../../../../server/dev/parse-version-info'
import
type
{
VersionInfo
}
from
'../../../../../server/dev/parse-version-info'
import
type
{
OverlayState
}
from
'../../../shared'
import
type
{
OverlayState
}
from
'../../../shared'
const
meta
:
Meta
<
typeof
Dev
ToolsIndicato
r
>
=
{
const
meta
:
Meta
<
typeof
Dev
OverlayStoryWrappe
r
>
=
{
component
:
Dev
ToolsIndicato
r
,
component
:
Dev
OverlayStoryWrappe
r
,
parameters
:
{
parameters
:
{
layout
:
'centered'
,
layout
:
'centered'
,
},
},
...
@@ -36,7 +36,7 @@ const meta: Meta<typeof DevToolsIndicator> = {
...
@@ -36,7 +36,7 @@ const meta: Meta<typeof DevToolsIndicator> = {
}
}
export
default
meta
export
default
meta
type
Story
=
StoryObj
<
typeof
Dev
ToolsIndicato
r
>
type
Story
=
StoryObj
<
typeof
Dev
OverlayStoryWrappe
r
>
// Mock version info for stories
// Mock version info for stories
const
mockVersionInfo
:
VersionInfo
=
{
const
mockVersionInfo
:
VersionInfo
=
{
...
@@ -68,36 +68,31 @@ const state: OverlayState = {
...
@@ -68,36 +68,31 @@ const state: OverlayState = {
}
}
export
const
StaticRoute
:
Story
=
{
export
const
StaticRoute
:
Story
=
{
args
:
{
render
:
()
=>
(
errorCount
:
0
,
<
DevOverlayStoryWrapper
initialState=
{
state
}
runtimeErrors=
{
[]
}
/>
state
,
),
dispatch
:
()
=>
{},
},
}
}
export
const
DynamicRoute
:
Story
=
{
export
const
DynamicRoute
:
Story
=
{
args
:
{
render
:
()
=>
(
errorCount
:
0
,
<
DevOverlayStoryWrapper
state
:
{
initialState=
{
{
...
state
,
staticIndicator
:
false
}
}
...
state
,
runtimeErrors=
{
[]
}
staticIndicator
:
false
,
/>
},
),
dispatch
:
()
=>
{},
},
}
}
export
const
SingleError
:
Story
=
{
export
const
SingleError
:
Story
=
{
args
:
{
render
:
()
=>
(
errorCount
:
1
,
<
DevOverlayStoryWrapper
initialState=
{
state
}
runtimeErrors=
{
[{}
as
any
]
}
/>
state
,
),
dispatch
:
()
=>
{},
},
}
}
export
const
MultipleErrors
:
Story
=
{
export
const
MultipleErrors
:
Story
=
{
args
:
{
render
:
()
=>
(
errorCount
:
3
,
<
DevOverlayStoryWrapper
state
,
initialState=
{
state
}
dispatch
:
()
=>
{},
runtimeErrors=
{
[{},
{},
{}]
as
any
}
},
/>
),
}
}
packages/next/src/next-devtools/dev-overlay/components/errors/dev-tools-indicator/dev-tools-indicator.tsx
View file @
30743443
...
@@ -77,12 +77,12 @@ export function DevToolsIndicator({
...
@@ -77,12 +77,12 @@ export function DevToolsIndicator({
//////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////
interface
C
{
interface
C
{
closeMenu
:
()
=>
void
closeMenu
?
:
()
=>
void
selectedIndex
:
number
selectedIndex
:
number
setSelectedIndex
:
Dispatch
<
SetStateAction
<
number
>>
setSelectedIndex
:
Dispatch
<
SetStateAction
<
number
>>
}
}
const
Context
=
createContext
({}
as
C
)
export
const
Menu
Context
=
createContext
({}
as
C
)
const
OVERLAYS
=
{
const
OVERLAYS
=
{
Root
:
'root'
,
Root
:
'root'
,
...
@@ -397,7 +397,7 @@ function DevToolsPopover({
...
@@ -397,7 +397,7 @@ function DevToolsPopover({
data
-
rendered=
{
menuRendered
}
data
-
rendered=
{
menuRendered
}
style=
{
popover
}
style=
{
popover
}
>
>
<
Context
.
Provider
<
Menu
Context
.
Provider
value=
{
{
value=
{
{
closeMenu
,
closeMenu
,
selectedIndex
,
selectedIndex
,
...
@@ -457,7 +457,7 @@ function DevToolsPopover({
...
@@ -457,7 +457,7 @@ function DevToolsPopover({
/>
/>
)
:
null
}
)
:
null
}
</
div
>
</
div
>
</
Context
.
Provider
>
</
Menu
Context
.
Provider
>
</
div
>
</
div
>
)
}
)
}
</
Toast
>
</
Toast
>
...
@@ -483,7 +483,7 @@ function ChevronRight() {
...
@@ -483,7 +483,7 @@ function ChevronRight() {
)
)
}
}
function
MenuItem
({
export
function
MenuItem
({
index
,
index
,
label
,
label
,
value
,
value
,
...
@@ -500,13 +500,13 @@ function MenuItem({
...
@@ -500,13 +500,13 @@ function MenuItem({
})
{
})
{
const
isInteractive
=
const
isInteractive
=
typeof
onClick
===
'function'
||
typeof
href
===
'string'
typeof
onClick
===
'function'
||
typeof
href
===
'string'
const
{
closeMenu
,
selectedIndex
,
setSelectedIndex
}
=
useContext
(
Context
)
const
{
closeMenu
,
selectedIndex
,
setSelectedIndex
}
=
useContext
(
Menu
Context
)
const
selected
=
selectedIndex
===
index
const
selected
=
selectedIndex
===
index
function
click
()
{
function
click
()
{
if
(
isInteractive
)
{
if
(
isInteractive
)
{
onClick
?.()
onClick
?.()
closeMenu
()
closeMenu
?.
()
if
(
href
)
{
if
(
href
)
{
window
.
open
(
href
,
'_blank'
,
'noopener, noreferrer'
)
window
.
open
(
href
,
'_blank'
,
'noopener, noreferrer'
)
}
}
...
...
packages/next/src/next-devtools/dev-overlay/components/errors/dev-tools-indicator/dev-tools-info/dev-tools-header.tsx
0 → 100644
View file @
30743443
import
React
from
'react'
interface
DevToolsHeaderProps
{
title
:
React
.
ReactNode
onBack
:
()
=>
void
children
?:
React
.
ReactNode
}
export
function
DevToolsHeader
({
title
,
onBack
,
children
,
ref
,
}:
DevToolsHeaderProps
&
{
ref
?:
React
.
Ref
<
HTMLDivElement
>
})
{
return
(
<
div
className=
"dev-tools-info-header"
ref=
{
ref
}
>
<
button
className=
"dev-tools-info-close-button"
onClick=
{
onBack
}
aria
-
label=
"Go back"
>
<
IconChevronLeft
/>
</
button
>
<
h3
className=
"dev-tools-info-title"
style=
{
{
margin
:
0
}
}
>
{
title
}
</
h3
>
{
children
}
</
div
>
)
}
function
IconChevronLeft
()
{
return
(
<
svg
width=
"16"
height=
"16"
viewBox=
"0 0 16 16"
fill=
"none"
xmlns=
"http://www.w3.org/2000/svg"
>
<
path
d=
"M5.14645 8.70703C4.75595 8.31651 4.75595 7.68349 5.14645 7.29297L10.5 1.93945L11.5605 3L6.56051 8L11.5605 13L10.5 14.0605L5.14645 8.70703Z"
fill=
"currentColor"
/>
</
svg
>
)
}
packages/next/src/next-devtools/dev-overlay/components/errors/dev-tools-indicator/dev-tools-info/dev-tools-info.tsx
View file @
30743443
import
{
useRef
}
from
'react'
import
{
useRef
}
from
'react'
import
{
MENU_DURATION_MS
,
useClickOutside
,
useFocusTrap
}
from
'../utils'
import
{
MENU_DURATION_MS
,
useClickOutside
,
useFocusTrap
}
from
'../utils'
import
{
useDelayedRender
}
from
'../../../../hooks/use-delayed-render'
import
{
useDelayedRender
}
from
'../../../../hooks/use-delayed-render'
import
{
css
}
from
'../../../../utils/css'
export
interface
DevToolsInfoPropsCore
{
export
interface
DevToolsInfoPropsCore
{
isOpen
:
boolean
isOpen
:
boolean
...
@@ -84,7 +85,7 @@ export function DevToolsInfo({
...
@@ -84,7 +85,7 @@ export function DevToolsInfo({
)
)
}
}
export
const
DEV_TOOLS_INFO_STYLES
=
`
export
const
DEV_TOOLS_INFO_STYLES
=
css
`
[data-info-popover] {
[data-info-popover] {
-webkit-font-smoothing: antialiased;
-webkit-font-smoothing: antialiased;
display: flex;
display: flex;
...
...
packages/next/src/next-devtools/dev-overlay/components/errors/dev-tools-indicator/dev-tools-info/route-info.tsx
View file @
30743443
import
type
{
HTMLProps
}
from
'react'
import
type
{
ComponentProps
,
HTMLProps
,
RefObject
}
from
'react'
import
type
{
DevToolsInfoPropsCore
}
from
'./dev-tools-info'
import
{
DevToolsInfo
}
from
'./dev-tools-info'
import
{
DevToolsInfo
}
from
'./dev-tools-info'
function
StaticRouteContent
({
routerType
}:
{
routerType
:
'pages'
|
'app'
})
{
function
StaticRouteContent
({
routerType
,
...
props
}:
{
routerType
:
'pages'
|
'app'
}
&
ComponentProps
<
'div'
>
)
{
return
(
return
(
<
article
className=
"dev-tools-info-article"
>
<
article
className=
"dev-tools-info-article"
{
...
props
}
>
<
p
className=
"dev-tools-info-paragraph"
>
<
p
className=
"dev-tools-info-paragraph"
>
The path
{
' '
}
The path
{
' '
}
<
code
className=
"dev-tools-info-code"
>
{
window
.
location
.
pathname
}
</
code
>
{
' '
}
<
code
className=
"dev-tools-info-code"
>
{
window
.
location
.
pathname
}
</
code
>
{
' '
}
...
@@ -37,9 +39,12 @@ function StaticRouteContent({ routerType }: { routerType: 'pages' | 'app' }) {
...
@@ -37,9 +39,12 @@ function StaticRouteContent({ routerType }: { routerType: 'pages' | 'app' }) {
)
)
}
}
function
DynamicRouteContent
({
routerType
}:
{
routerType
:
'pages'
|
'app'
})
{
function
DynamicRouteContent
({
routerType
,
...
props
}:
{
routerType
:
'pages'
|
'app'
}
&
ComponentProps
<
'div'
>
)
{
return
(
return
(
<
article
className=
"dev-tools-info-article"
>
<
article
className=
"dev-tools-info-article"
{
...
props
}
>
<
p
className=
"dev-tools-info-paragraph"
>
<
p
className=
"dev-tools-info-paragraph"
>
The path
{
' '
}
The path
{
' '
}
<
code
className=
"dev-tools-info-code"
>
{
window
.
location
.
pathname
}
</
code
>
{
' '
}
<
code
className=
"dev-tools-info-code"
>
{
window
.
location
.
pathname
}
</
code
>
{
' '
}
...
@@ -110,32 +115,50 @@ const learnMoreLink = {
...
@@ -110,32 +115,50 @@ const learnMoreLink = {
},
},
}
as
const
}
as
const
export
function
RouteInfoBody
({
routerType
,
isStaticRoute
,
...
props
}:
{
routerType
:
'pages'
|
'app'
isStaticRoute
:
boolean
}
&
ComponentProps
<
'div'
>
)
{
return
isStaticRoute
?
(
<
StaticRouteContent
routerType=
{
routerType
}
{
...
props
}
/>
)
:
(
<
DynamicRouteContent
routerType=
{
routerType
}
{
...
props
}
/>
)
}
export
function
RouteInfo
({
export
function
RouteInfo
({
routeType
,
isOpen
,
close
,
routerType
,
routerType
,
routeType
,
triggerRef
,
...
props
...
props
}:
{
}:
{
routeType
:
'Static'
|
'Dynamic'
isOpen
:
boolean
close
:
()
=>
void
routerType
:
'pages'
|
'app'
routerType
:
'pages'
|
'app'
}
&
DevToolsInfoPropsCore
&
routeType
:
'Static'
|
'Dynamic'
HTMLProps
<
HTMLDivElement
>
)
{
triggerRef
:
RefObject
<
HTMLButtonElement
|
null
>
}
&
HTMLProps
<
HTMLDivElement
>
)
{
const
isStaticRoute
=
routeType
===
'Static'
const
isStaticRoute
=
routeType
===
'Static'
const
learnMore
=
isStaticRoute
const
learnMore
=
isStaticRoute
?
learnMoreLink
[
routerType
].
static
?
learnMoreLink
[
routerType
].
static
:
learnMoreLink
[
routerType
].
dynamic
:
learnMoreLink
[
routerType
].
dynamic
return
(
return
(
<
DevToolsInfo
<
DevToolsInfo
title=
{
`${routeType} Route`
}
title=
{
`${routeType} Route`
}
learnMoreLink=
{
learnMore
}
learnMoreLink=
{
learnMore
}
close=
{
close
}
isOpen=
{
isOpen
}
triggerRef=
{
triggerRef
}
{
...
props
}
{
...
props
}
>
>
{
isStaticRoute
?
(
<
RouteInfoBody
routerType=
{
routerType
}
isStaticRoute=
{
isStaticRoute
}
/>
<
StaticRouteContent
routerType=
{
routerType
}
/>
)
:
(
<
DynamicRouteContent
routerType=
{
routerType
}
/>
)
}
</
DevToolsInfo
>
</
DevToolsInfo
>
)
)
}
}
...
...
packages/next/src/next-devtools/dev-overlay/components/errors/dev-tools-indicator/dev-tools-info/turbopack-info.tsx
View file @
30743443
...
@@ -2,16 +2,10 @@ import { DevToolsInfo, type DevToolsInfoPropsCore } from './dev-tools-info'
...
@@ -2,16 +2,10 @@ import { DevToolsInfo, type DevToolsInfoPropsCore } from './dev-tools-info'
import
{
CopyButton
}
from
'../../../copy-button'
import
{
CopyButton
}
from
'../../../copy-button'
import
type
{
HTMLProps
}
from
'react'
import
type
{
HTMLProps
}
from
'react'
export
function
TurbopackInfo
(
export
function
TurbopackInfoBody
(
props
:
React
.
ComponentProps
<
'div'
>
)
{
props
:
DevToolsInfoPropsCore
&
HTMLProps
<
HTMLDivElement
>
)
{
return
(
return
(
<
DevToolsInfo
<>
title=
"Turbopack"
<
article
className=
"dev-tools-info-article"
{
...
props
}
>
learnMoreLink=
"https://nextjs.org/docs/app/api-reference/turbopack"
{
...
props
}
>
<
article
className=
"dev-tools-info-article"
>
<
p
className=
"dev-tools-info-paragraph"
>
<
p
className=
"dev-tools-info-paragraph"
>
Turbopack is an incremental bundler optimized for JavaScript and
Turbopack is an incremental bundler optimized for JavaScript and
TypeScript, written in Rust, and built into Next.js. Turbopack can be
TypeScript, written in Rust, and built into Next.js. Turbopack can be
...
@@ -96,6 +90,20 @@ export function TurbopackInfo(
...
@@ -96,6 +90,20 @@ export function TurbopackInfo(
</
pre
>
</
pre
>
</
div
>
</
div
>
</
div
>
</
div
>
</>
)
}
export
function
TurbopackInfo
(
props
:
DevToolsInfoPropsCore
&
HTMLProps
<
HTMLDivElement
>
)
{
return
(
<
DevToolsInfo
title=
"Turbopack"
learnMoreLink=
"https://nextjs.org/docs/app/api-reference/turbopack"
{
...
props
}
>
<
TurbopackInfoBody
/>
</
DevToolsInfo
>
</
DevToolsInfo
>
)
)
}
}
...
...
packages/next/src/next-devtools/dev-overlay/components/errors/dev-tools-indicator/dev-tools-info/user-preferences.tsx
View file @
30743443
...
@@ -19,25 +19,56 @@ import {
...
@@ -19,25 +19,56 @@ import {
import
{
ShortcutRecorder
}
from
'./shortcut-recorder'
import
{
ShortcutRecorder
}
from
'./shortcut-recorder'
export
function
UserPreferences
({
export
function
UserPreferences
({
setPosition
,
position
,
hide
,
hide
,
scale
,
setScale
,
hideShortcut
,
hideShortcut
,
setHideShortcut
,
setHideShortcut
,
setScale
,
scale
,
position
,
setPosition
,
...
props
...
props
}:
{
}:
{
hide
:
()
=>
void
hideShortcut
:
string
|
null
setHideShortcut
:
(
value
:
string
|
null
)
=>
void
setPosition
:
(
position
:
DevToolsIndicatorPosition
)
=>
void
setPosition
:
(
position
:
DevToolsIndicatorPosition
)
=>
void
position
:
DevToolsIndicatorPosition
position
:
DevToolsIndicatorPosition
scale
:
DevToolsScale
scale
:
DevToolsScale
setScale
:
(
value
:
DevToolsScale
)
=>
void
setScale
:
(
value
:
DevToolsScale
)
=>
void
}
&
DevToolsInfoPropsCore
&
Omit
<
HTMLProps
<
HTMLDivElement
>
,
'size'
>
)
{
return
(
<
DevToolsInfo
title=
"Preferences"
{
...
props
}
>
<
UserPreferencesBody
scale=
{
scale
}
position=
{
position
}
setPosition=
{
setPosition
}
setScale=
{
setScale
}
hide=
{
hide
}
hideShortcut=
{
hideShortcut
}
setHideShortcut=
{
setHideShortcut
}
/>
</
DevToolsInfo
>
)
}
export
function
UserPreferencesBody
({
hide
,
hideShortcut
,
setHideShortcut
,
scale
,
setPosition
,
setScale
,
position
,
}:
{
hide
:
()
=>
void
hide
:
()
=>
void
hideShortcut
:
string
|
null
hideShortcut
:
string
|
null
setHideShortcut
:
(
value
:
string
|
null
)
=>
void
setHideShortcut
:
(
value
:
string
|
null
)
=>
void
}
&
DevToolsInfoPropsCore
&
setPosition
:
(
position
:
DevToolsIndicatorPosition
)
=>
void
Omit
<
HTMLProps
<
HTMLDivElement
>
,
'size'
>
)
{
position
:
DevToolsIndicatorPosition
// derive initial theme from system preference
scale
:
DevToolsScale
setScale
:
(
value
:
DevToolsScale
)
=>
void
})
{
const
[
theme
,
setTheme
]
=
useState
(
getInitialTheme
())
const
[
theme
,
setTheme
]
=
useState
(
getInitialTheme
())
const
handleThemeChange
=
(
e
:
React
.
ChangeEvent
<
HTMLSelectElement
>
)
=>
{
const
handleThemeChange
=
(
e
:
React
.
ChangeEvent
<
HTMLSelectElement
>
)
=>
{
...
@@ -90,7 +121,7 @@ export function UserPreferences({
...
@@ -90,7 +121,7 @@ export function UserPreferences({
}
}
return
(
return
(
<
DevToolsInfo
title=
"Preferences"
{
...
props
}
>
<>
<
h2
className=
"dev-tools-info-section-title"
>
General
</
h2
>
<
h2
className=
"dev-tools-info-section-title"
>
General
</
h2
>
<
div
className=
"preferences-container"
>
<
div
className=
"preferences-container"
>
<
div
className=
"preference-section"
>
<
div
className=
"preference-section"
>
...
@@ -257,7 +288,7 @@ export function UserPreferences({
...
@@ -257,7 +288,7 @@ export function UserPreferences({
</
div
>
</
div
>
</
div
>
</
div
>
)
:
null
}
)
:
null
}
</
DevToolsInfo
>
</>
)
)
}
}
...
...
packages/next/src/next-devtools/dev-overlay/components/errors/dev-tools-indicator/drag-context.tsx
0 → 100644
View file @
30743443
import
React
,
{
createContext
,
useCallback
,
useContext
,
useMemo
,
useRef
,
}
from
'react'
interface
DragContextValue
{
register
:
(
el
:
HTMLElement
)
=>
void
unregister
:
(
el
:
HTMLElement
)
=>
void
handles
:
Set
<
HTMLElement
>
disabled
:
boolean
}
const
DragContext
=
createContext
<
DragContextValue
|
null
>
(
null
)
export
function
DragProvider
({
children
,
disabled
=
false
,
}:
{
children
:
React
.
ReactNode
disabled
?:
boolean
})
{
const
handlesRef
=
useRef
<
Set
<
HTMLElement
>>
(
new
Set
())
const
register
=
useCallback
((
el
:
HTMLElement
)
=>
{
handlesRef
.
current
.
add
(
el
)
},
[])
const
unregister
=
useCallback
((
el
:
HTMLElement
)
=>
{
handlesRef
.
current
.
delete
(
el
)
},
[])
const
value
=
useMemo
<
DragContextValue
>
(
()
=>
({
register
,
unregister
,
handles
:
handlesRef
.
current
,
disabled
}),
[
register
,
unregister
,
disabled
]
)
return
<
DragContext
.
Provider
value=
{
value
}
>
{
children
}
</
DragContext
.
Provider
>
}
export
function
useDragContext
()
{
return
useContext
(
DragContext
)
}
export
function
DragHandle
({
children
,
ref
,
...
props
}:
React
.
HTMLAttributes
<
HTMLDivElement
>
&
{
ref
?:
React
.
Ref
<
HTMLDivElement
>
})
{
const
internalRef
=
useRef
<
HTMLDivElement
>
(
null
)
const
ctx
=
useDragContext
()
const
setRef
=
useCallback
(
(
node
:
HTMLDivElement
|
null
)
=>
{
internalRef
.
current
=
node
??
null
if
(
typeof
ref
===
'function'
)
{
ref
(
node
)
}
else
if
(
ref
&&
typeof
ref
===
'object'
)
{
;(
ref
as
React
.
MutableRefObject
<
HTMLDivElement
|
null
>
).
current
=
node
}
},
[
ref
]
)
React
.
useEffect
(()
=>
{
if
(
!
ctx
||
!
internalRef
.
current
||
ctx
.
disabled
)
return
const
el
=
internalRef
.
current
ctx
.
register
(
el
)
return
()
=>
ctx
.
unregister
(
el
)
},
[
ctx
])
return
(
<
div
ref=
{
setRef
}
{
...
props
}
style=
{
{
cursor
:
ctx
?.
disabled
?
'default'
:
'grab'
,
...(
props
.
style
||
{}),
}
}
>
{
children
}
</
div
>
)
}
packages/next/src/next-devtools/dev-overlay/components/errors/dev-tools-indicator/draggable.tsx
View file @
30743443
import
type
{
Corners
}
from
'../../../shared'
import
type
{
Corners
}
from
'../../../shared'
import
{
useCallback
,
useLayoutEffect
,
useRef
}
from
'react'
import
{
useCallback
,
useLayoutEffect
,
useRef
}
from
'react'
import
{
useDragContext
}
from
'./drag-context'
interface
Point
{
interface
Point
{
x
:
number
x
:
number
...
@@ -19,6 +20,7 @@ export function Draggable({
...
@@ -19,6 +20,7 @@ export function Draggable({
onDragStart
,
onDragStart
,
dragHandleSelector
,
dragHandleSelector
,
disableDrag
=
false
,
disableDrag
=
false
,
avoidZone
,
...
props
...
props
}:
{
}:
{
children
:
React
.
ReactElement
children
:
React
.
ReactElement
...
@@ -28,9 +30,16 @@ export function Draggable({
...
@@ -28,9 +30,16 @@ export function Draggable({
onDragStart
?:
()
=>
void
onDragStart
?:
()
=>
void
dragHandleSelector
?:
string
dragHandleSelector
?:
string
disableDrag
?:
boolean
disableDrag
?:
boolean
style
?:
React
.
CSSProperties
avoidZone
?:
{
square
:
number
corner
:
Corners
padding
:
number
}
})
{
})
{
const
{
ref
,
animate
,
...
drag
}
=
useDrag
({
const
{
ref
,
animate
,
...
drag
}
=
useDrag
({
disabled
:
disableDrag
,
disabled
:
disableDrag
,
handles
:
useDragContext
()?.
handles
,
threshold
:
5
,
threshold
:
5
,
onDragStart
,
onDragStart
,
onDragEnd
,
onDragEnd
,
...
@@ -56,7 +65,6 @@ export function Draggable({
...
@@ -56,7 +65,6 @@ export function Draggable({
}
}
function
onAnimationEnd
({
corner
}:
Corner
)
{
function
onAnimationEnd
({
corner
}:
Corner
)
{
// Unset drag translation
setTimeout
(()
=>
{
setTimeout
(()
=>
{
ref
.
current
?.
style
.
removeProperty
(
'translate'
)
ref
.
current
?.
style
.
removeProperty
(
'translate'
)
setCurrentCorner
(
corner
)
setCurrentCorner
(
corner
)
...
@@ -74,7 +82,7 @@ export function Draggable({
...
@@ -74,7 +82,7 @@ export function Draggable({
const
min
=
Math
.
min
(...
distances
.
map
((
d
)
=>
d
.
distance
))
const
min
=
Math
.
min
(...
distances
.
map
((
d
)
=>
d
.
distance
))
const
nearest
=
distances
.
find
((
d
)
=>
d
.
distance
===
min
)
const
nearest
=
distances
.
find
((
d
)
=>
d
.
distance
===
min
)
if
(
!
nearest
)
{
if
(
!
nearest
)
{
//
Safety fallback
//
this should be guarded by an invariant, shouldn't ever happen
return
{
corner
:
currentCorner
,
translation
:
allCorners
[
currentCorner
]
}
return
{
corner
:
currentCorner
,
translation
:
allCorners
[
currentCorner
]
}
}
}
return
{
return
{
...
@@ -94,49 +102,53 @@ export function Draggable({
...
@@ -94,49 +102,53 @@ export function Draggable({
const
isRight
=
corner
.
includes
(
'right'
)
const
isRight
=
corner
.
includes
(
'right'
)
const
isBottom
=
corner
.
includes
(
'bottom'
)
const
isBottom
=
corner
.
includes
(
'bottom'
)
return
{
// Base positions flush against the chosen corner
x
:
isRight
let
x
=
isRight
?
window
.
innerWidth
-
scrollbarWidth
-
offset
-
triggerWidth
?
window
.
innerWidth
-
scrollbarWidth
-
offset
-
triggerWidth
:
0
,
:
0
y
:
isBottom
?
window
.
innerHeight
-
offset
-
triggerHeight
:
0
,
let
y
=
isBottom
?
window
.
innerHeight
-
offset
-
triggerHeight
:
0
// Apply avoidZone offset if this corner is occupied. We only move along
// the vertical axis to keep the panel within the viewport. For bottom
// corners we move the panel up, for top corners we move it down.
if
(
avoidZone
&&
avoidZone
.
corner
===
corner
)
{
const
delta
=
avoidZone
.
square
+
avoidZone
.
padding
if
(
isBottom
)
{
// move up
y
-=
delta
}
else
{
// move down
y
+=
delta
}
}
}
}
return
{
x
,
y
}
}
const
basePosition
=
getAbsolutePosition
(
currentCorner
)
const
basePosition
=
getAbsolutePosition
(
currentCorner
)
// Calculate all corner positions relative to the current corner
function
rel
(
pos
:
Point
):
Point
{
return
{
x
:
pos
.
x
-
basePosition
.
x
,
y
:
pos
.
y
-
basePosition
.
y
,
}
}
return
{
return
{
'top-left'
:
{
'top-left'
:
rel
(
getAbsolutePosition
(
'top-left'
)),
x
:
0
-
basePosition
.
x
,
'top-right'
:
rel
(
getAbsolutePosition
(
'top-right'
)),
y
:
0
-
basePosition
.
y
,
'bottom-left'
:
rel
(
getAbsolutePosition
(
'bottom-left'
)),
},
'bottom-right'
:
rel
(
getAbsolutePosition
(
'bottom-right'
)),
'top-right'
:
{
x
:
window
.
innerWidth
-
scrollbarWidth
-
offset
-
triggerWidth
-
basePosition
.
x
,
y
:
0
-
basePosition
.
y
,
},
'bottom-left'
:
{
x
:
0
-
basePosition
.
x
,
y
:
window
.
innerHeight
-
offset
-
triggerHeight
-
basePosition
.
y
,
},
'bottom-right'
:
{
x
:
window
.
innerWidth
-
scrollbarWidth
-
offset
-
triggerWidth
-
basePosition
.
x
,
y
:
window
.
innerHeight
-
offset
-
triggerHeight
-
basePosition
.
y
,
},
}
}
}
}
return
(
return
(
<
div
{
...
props
}
ref=
{
ref
}
{
...
drag
}
style=
{
{
touchAction
:
'none'
}
}
>
<
div
{
...
props
}
ref=
{
ref
}
{
...
drag
}
style=
{
{
touchAction
:
'none'
,
...
props
.
style
}
}
>
{
children
}
{
children
}
</
div
>
</
div
>
)
)
...
@@ -150,6 +162,7 @@ interface UseDragOptions {
...
@@ -150,6 +162,7 @@ interface UseDragOptions {
onAnimationEnd
?:
(
corner
:
Corner
)
=>
void
onAnimationEnd
?:
(
corner
:
Corner
)
=>
void
threshold
:
number
// Minimum movement before drag starts
threshold
:
number
// Minimum movement before drag starts
dragHandleSelector
?:
string
dragHandleSelector
?:
string
handles
?:
Set
<
HTMLElement
>
}
}
interface
Velocity
{
interface
Velocity
{
...
@@ -234,18 +247,23 @@ export function useDrag(options: UseDragOptions) {
...
@@ -234,18 +247,23 @@ export function useDrag(options: UseDragOptions) {
}
}
function
isValidDragHandle
(
target
:
EventTarget
|
null
):
boolean
{
function
isValidDragHandle
(
target
:
EventTarget
|
null
):
boolean
{
if
(
!
options
.
dragHandleSelector
||
!
ref
.
current
||
!
target
)
{
if
(
!
target
||
!
ref
.
current
)
return
true
return
true
// If no selector provided, entire element is draggable
if
(
options
.
handles
&&
options
.
handles
.
size
>
0
)
{
let
node
:
HTMLElement
|
null
=
target
as
HTMLElement
while
(
node
&&
node
!==
ref
.
current
)
{
if
(
options
.
handles
.
has
(
node
))
return
true
node
=
node
.
parentElement
}
return
false
}
}
if
(
options
.
dragHandleSelector
)
{
const
element
=
target
as
Element
const
element
=
target
as
Element
if
(
!
element
.
matches
)
{
return
element
.
closest
(
options
.
dragHandleSelector
)
!==
null
return
false
}
}
// Check if the target element directly matches the drag handle selector
return
true
// This excludes children elements, only allowing drag from the exact element
return
element
.
matches
(
options
.
dragHandleSelector
)
}
}
function
onPointerDown
(
e
:
React
.
PointerEvent
)
{
function
onPointerDown
(
e
:
React
.
PointerEvent
)
{
...
@@ -328,6 +346,13 @@ export function useDrag(options: UseDragOptions) {
...
@@ -328,6 +346,13 @@ export function useDrag(options: UseDragOptions) {
options
.
onDragEnd
?.(
translation
.
current
,
velocity
)
options
.
onDragEnd
?.(
translation
.
current
,
velocity
)
}
}
if
(
options
.
disabled
)
{
return
{
ref
,
animate
,
}
}
return
{
return
{
ref
,
ref
,
onPointerDown
,
onPointerDown
,
...
...
packages/next/src/next-devtools/dev-overlay/components/errors/dev-tools-indicator/utils.ts
View file @
30743443
...
@@ -99,19 +99,28 @@ export function useClickOutside(
...
@@ -99,19 +99,28 @@ export function useClickOutside(
return
return
}
}
const
cushion
=
10
if
(
if
(
!
(
rootRef
.
current
?.
getBoundingClientRect
()
!
(
rootRef
.
current
?.
getBoundingClientRect
()
?
event
.
clientX
>=
rootRef
.
current
.
getBoundingClientRect
()
!
.
left
&&
?
event
.
clientX
>=
event
.
clientX
<=
rootRef
.
current
.
getBoundingClientRect
()
!
.
right
&&
rootRef
.
current
.
getBoundingClientRect
()
!
.
left
-
cushion
&&
event
.
clientY
>=
rootRef
.
current
.
getBoundingClientRect
()
!
.
top
&&
event
.
clientX
<=
event
.
clientY
<=
rootRef
.
current
.
getBoundingClientRect
()
!
.
bottom
rootRef
.
current
.
getBoundingClientRect
()
!
.
right
+
cushion
&&
event
.
clientY
>=
rootRef
.
current
.
getBoundingClientRect
()
!
.
top
-
cushion
&&
event
.
clientY
<=
rootRef
.
current
.
getBoundingClientRect
()
!
.
bottom
+
cushion
:
false
)
&&
:
false
)
&&
!
(
triggerRef
.
current
?.
getBoundingClientRect
()
!
(
triggerRef
.
current
?.
getBoundingClientRect
()
?
event
.
clientX
>=
triggerRef
.
current
.
getBoundingClientRect
()
!
.
left
&&
?
event
.
clientX
>=
triggerRef
.
current
.
getBoundingClientRect
()
!
.
left
-
cushion
&&
event
.
clientX
<=
event
.
clientX
<=
triggerRef
.
current
.
getBoundingClientRect
()
!
.
right
&&
triggerRef
.
current
.
getBoundingClientRect
()
!
.
right
+
cushion
&&
event
.
clientY
>=
triggerRef
.
current
.
getBoundingClientRect
()
!
.
top
&&
event
.
clientY
>=
event
.
clientY
<=
triggerRef
.
current
.
getBoundingClientRect
()
!
.
bottom
triggerRef
.
current
.
getBoundingClientRect
()
!
.
top
-
cushion
&&
event
.
clientY
<=
triggerRef
.
current
.
getBoundingClientRect
()
!
.
bottom
+
cushion
:
false
)
:
false
)
)
{
)
{
close
()
close
()
...
...
packages/next/src/next-devtools/dev-overlay/components/errors/overlay/overlay.tsx
View file @
30743443
import
{
css
}
from
'../../../utils/css'
import
{
Overlay
,
type
OverlayProps
}
from
'../../overlay/overlay'
import
{
Overlay
,
type
OverlayProps
}
from
'../../overlay/overlay'
export
function
ErrorOverlayOverlay
({
children
,
...
props
}:
OverlayProps
)
{
export
function
ErrorOverlayOverlay
({
children
,
...
props
}:
OverlayProps
)
{
return
<
Overlay
{
...
props
}
>
{
children
}
</
Overlay
>
return
<
Overlay
{
...
props
}
>
{
children
}
</
Overlay
>
}
}
export
const
OVERLAY_STYLES
=
`
export
const
OVERLAY_STYLES
=
css
`
[data-nextjs-dialog-overlay] {
[data-nextjs-dialog-overlay] {
padding: initial;
padding: initial;
top: 10vh;
top: 10vh;
...
...
packages/next/src/next-devtools/dev-overlay/components/overlay/styles.tsx
View file @
30743443
const
styles
=
`
import
{
css
}
from
'../../utils/css'
const
styles
=
css
`
[data-nextjs-dialog-overlay] {
[data-nextjs-dialog-overlay] {
position: fixed;
position: fixed;
top: 0;
top: 0;
...
...
packages/next/src/next-devtools/dev-overlay/container/errors.stories.tsx
View file @
30743443
...
@@ -16,6 +16,7 @@ const meta: Meta<typeof Errors> = {
...
@@ -16,6 +16,7 @@ const meta: Meta<typeof Errors> = {
export
default
meta
export
default
meta
type
Story
=
StoryObj
<
typeof
Errors
>
type
Story
=
StoryObj
<
typeof
Errors
>
// todo: update the stories to be wrapped in context providers necessary, instead of passing props directly, before they expected props
export
const
Default
:
Story
=
{
export
const
Default
:
Story
=
{
args
:
{
args
:
{
getSquashedHydrationErrorDetails
:
()
=>
null
,
getSquashedHydrationErrorDetails
:
()
=>
null
,
...
...
packages/next/src/next-devtools/dev-overlay/dev-overlay.stories.tsx
View file @
30743443
...
@@ -10,6 +10,8 @@ import {
...
@@ -10,6 +10,8 @@ import {
storybookDefaultOverlayState
,
storybookDefaultOverlayState
,
useStorybookOverlayReducer
,
useStorybookOverlayReducer
,
}
from
'./storybook/use-overlay-reducer'
}
from
'./storybook/use-overlay-reducer'
import
{
DevOverlayContext
}
from
'../dev-overlay.browser'
import
{
getSquashedHydrationErrorDetails
}
from
'../userspace/pages/hydration-error-state'
const
meta
:
Meta
<
typeof
DevOverlay
>
=
{
const
meta
:
Meta
<
typeof
DevOverlay
>
=
{
component
:
DevOverlay
,
component
:
DevOverlay
,
...
@@ -39,14 +41,20 @@ function getNoSquashedHydrationErrorDetails() {
...
@@ -39,14 +41,20 @@ function getNoSquashedHydrationErrorDetails() {
const
initialState
:
OverlayState
=
{
const
initialState
:
OverlayState
=
{
...
storybookDefaultOverlayState
,
...
storybookDefaultOverlayState
,
errors
,
errors
:
errors
,
}
}
export
const
Default
:
Story
=
{
export
const
Default
:
Story
=
{
render
:
function
DevOverlayStory
()
{
render
:
function
DevOverlayStory
()
{
const
[
state
,
dispatch
]
=
useStorybookOverlayReducer
(
initialState
)
const
[
state
,
dispatch
]
=
useStorybookOverlayReducer
(
initialState
)
return
(
return
(
<>
<
div
style=
{
{
height
:
'100vh'
,
backgroundColor
:
'black'
,
}
}
>
{
/* TODO: get lots of real hard examples so we have better debug */
}
<
img
<
img
src=
{
imgApp
}
src=
{
imgApp
}
style=
{
{
style=
{
{
...
@@ -55,19 +63,26 @@ export const Default: Story = {
...
@@ -55,19 +63,26 @@ export const Default: Story = {
objectFit
:
'contain'
,
objectFit
:
'contain'
,
}
}
}
}
/>
/>
<
DevOverlayContext
value=
{
{
dispatch
,
getSquashedHydrationErrorDetails
:
getNoSquashedHydrationErrorDetails
,
state
,
}
}
>
<
DevOverlay
<
DevOverlay
state=
{
state
}
state=
{
state
}
dispatch=
{
dispatch
}
dispatch=
{
dispatch
}
getSquashedHydrationErrorDetails=
{
getSquashedHydrationErrorDetails=
{
getSquashedHydrationErrorDetails
}
// Testing like App Router where we no longer quash hydration errors
getNoSquashedHydrationErrorDetails
}
/>
/>
</>
</
DevOverlayContext
>
</
div
>
)
)
},
},
}
}
// todo: fix story with "Context arg provider" wrapper
export
const
WithPanel
:
Story
=
{
export
const
WithPanel
:
Story
=
{
beforeEach
:
()
=>
{
beforeEach
:
()
=>
{
process
.
env
.
__NEXT_DEVTOOL_NEW_PANEL_UI
=
'true'
process
.
env
.
__NEXT_DEVTOOL_NEW_PANEL_UI
=
'true'
...
@@ -89,14 +104,20 @@ export const WithPanel: Story = {
...
@@ -89,14 +104,20 @@ export const WithPanel: Story = {
objectFit
:
'contain'
,
objectFit
:
'contain'
,
}
}
}
}
/>
/>
<
DevOverlayContext
value=
{
{
dispatch
,
getSquashedHydrationErrorDetails
:
getNoSquashedHydrationErrorDetails
,
state
,
}
}
>
<
DevOverlay
<
DevOverlay
state=
{
state
}
dispatch=
{
dispatch
}
dispatch=
{
dispatch
}
getSquashedHydrationErrorDetails=
{
getSquashedHydrationErrorDetails=
{
getSquashedHydrationErrorDetails
}
// Testing like App Router where we no longer quash hydration errors
state=
{
state
}
getNoSquashedHydrationErrorDetails
}
/>
/>
</
DevOverlayContext
>
</>
</>
)
)
},
},
...
...
packages/next/src/next-devtools/dev-overlay/dev-overlay.tsx
View file @
30743443
...
@@ -5,7 +5,7 @@ import {
...
@@ -5,7 +5,7 @@ import {
type
OverlayState
,
type
OverlayState
,
}
from
'./shared'
}
from
'./shared'
import
{
useState
}
from
'react'
import
{
createContext
,
useContext
,
useRef
,
useState
}
from
'react'
import
{
ShadowPortal
}
from
'./components/shadow-portal'
import
{
ShadowPortal
}
from
'./components/shadow-portal'
import
{
Base
}
from
'./styles/base'
import
{
Base
}
from
'./styles/base'
...
@@ -18,8 +18,17 @@ import { RenderError } from './container/runtime-error/render-error'
...
@@ -18,8 +18,17 @@ import { RenderError } from './container/runtime-error/render-error'
import
{
DarkTheme
}
from
'./styles/dark-theme'
import
{
DarkTheme
}
from
'./styles/dark-theme'
import
{
useDevToolsScale
}
from
'./components/errors/dev-tools-indicator/dev-tools-info/preferences'
import
{
useDevToolsScale
}
from
'./components/errors/dev-tools-indicator/dev-tools-info/preferences'
import
type
{
HydrationErrorState
}
from
'../shared/hydration-error'
import
type
{
HydrationErrorState
}
from
'../shared/hydration-error'
import
{
DevToolsIndicator
as
DevToolsIndicatorNew
}
from
'./components/devtools-indicator/devtools-indicator'
import
type
{
ReadyRuntimeError
}
from
'./utils/get-error-by-type'
import
{
DevToolsPanel
}
from
'./components/devtools-panel/devtools-panel'
import
{
DevToolsIndicatorNew
}
from
'./components/devtools-indicator/devtools-indicator'
import
{
PanelRouter
}
from
'./menu/panel-router'
import
{
PanelRouterContext
,
type
PanelStateKind
}
from
'./menu/context'
export
const
RenderErrorContext
=
createContext
<
{
runtimeErrors
:
ReadyRuntimeError
[]
totalErrorCount
:
number
}
>
(
null
!
)
export
const
useRenderErrorContext
=
()
=>
useContext
(
RenderErrorContext
)
export
function
DevOverlay
({
export
function
DevOverlay
({
state
,
state
,
...
@@ -32,6 +41,8 @@ export function DevOverlay({
...
@@ -32,6 +41,8 @@ export function DevOverlay({
})
{
})
{
const
[
scale
,
setScale
]
=
useDevToolsScale
()
const
[
scale
,
setScale
]
=
useDevToolsScale
()
const
[
isPrevBuildError
,
setIsPrevBuildError
]
=
useState
(
false
)
const
[
isPrevBuildError
,
setIsPrevBuildError
]
=
useState
(
false
)
const
[
panel
,
setPanel
]
=
useState
<
null
|
PanelStateKind
>
(
null
)
const
triggerRef
=
useRef
<
HTMLButtonElement
>
(
null
)
const
isBuildError
=
state
.
buildError
!==
null
const
isBuildError
=
state
.
buildError
!==
null
...
@@ -63,27 +74,31 @@ export function DevOverlay({
...
@@ -63,27 +74,31 @@ export function DevOverlay({
return
(
return
(
<>
<>
{
state
.
showIndicator
&&
{
state
.
showIndicator
&&
(
process
.
env
.
__NEXT_DEVTOOL_NEW_PANEL_UI
?
(
process
.
env
.
__NEXT_DEVTOOL_NEW_PANEL_UI
?
(
<>
<>
<
DevToolsIndicatorNew
<
RenderErrorContext
state=
{
state
}
value=
{
{
runtimeErrors
,
totalErrorCount
}
}
dispatch=
{
dispatch
}
>
errorCount=
{
totalErrorCount
}
<
PanelRouterContext
isBuildError=
{
isBuildError
}
value=
{
{
/>
panel
,
setPanel
,
{
(
state
.
isDevToolsPanelOpen
||
triggerRef
,
state
.
isErrorOverlayOpen
)
&&
(
}
}
<
DevToolsPanel
>
<
ErrorOverlay
state=
{
state
}
state=
{
state
}
dispatch=
{
dispatch
}
dispatch=
{
dispatch
}
issueCount=
{
totalErrorCount
}
runtimeErrors=
{
runtimeErrors
}
getSquashedHydrationErrorDetails=
{
getSquashedHydrationErrorDetails=
{
getSquashedHydrationErrorDetails
getSquashedHydrationErrorDetails
}
}
runtimeErrors=
{
runtimeErrors
}
errorCount=
{
totalErrorCount
}
/>
/>
)
}
<
PanelRouter
/>
<
DevToolsIndicatorNew
/>
</
PanelRouterContext
>
</
RenderErrorContext
>
</>
</>
)
:
(
)
:
(
<>
<>
...
@@ -106,7 +121,7 @@ export function DevOverlay({
...
@@ -106,7 +121,7 @@ export function DevOverlay({
errorCount=
{
totalErrorCount
}
errorCount=
{
totalErrorCount
}
/>
/>
</>
</>
)
)
}
)
}
</>
</>
)
)
}
}
}
}
...
...
packages/next/src/next-devtools/dev-overlay/menu/context.tsx
0 → 100644
View file @
30743443
import
{
createContext
,
useContext
,
type
Dispatch
,
type
SetStateAction
,
}
from
'react'
export
type
PanelStateKind
=
|
'preferences'
|
'route-info'
|
'segment-explorer'
|
'panel-selector'
|
'turbo-info'
export
const
PanelRouterContext
=
createContext
<
{
panel
:
PanelStateKind
|
null
setPanel
:
Dispatch
<
SetStateAction
<
PanelStateKind
|
null
>>
triggerRef
:
React
.
RefObject
<
HTMLButtonElement
|
null
>
}
>
(
null
!
)
export
const
usePanelRouterContext
=
()
=>
useContext
(
PanelRouterContext
)
packages/next/src/next-devtools/dev-overlay/menu/dev-overlay-menu.tsx
0 → 100644
View file @
30743443
import
{
useDevOverlayContext
}
from
'../../dev-overlay.browser'
import
{
useClickOutside
}
from
'../components/errors/dev-tools-indicator/utils'
import
{
useRef
,
useState
,
type
CSSProperties
}
from
'react'
import
{
getIndicatorOffset
}
from
'../utils/indicator-metrics'
import
{
INDICATOR_PADDING
}
from
'../components/devtools-indicator/devtools-indicator'
import
{
MenuContext
,
MenuItem
,
}
from
'../components/errors/dev-tools-indicator/dev-tools-indicator'
import
{
usePanelRouterContext
}
from
'./context'
export
const
DevtoolMenu
=
({
closeOnClickOutside
=
true
,
items
,
}:
{
closeOnClickOutside
?:
boolean
items
:
Array
<
|
false
|
{
onClick
?:
()
=>
void
title
?:
string
label
:
string
value
:
React
.
ReactNode
attributes
?:
Record
<
string
,
string
|
boolean
>
footer
?:
boolean
}
>
})
=>
{
const
{
state
}
=
useDevOverlayContext
()
const
{
setPanel
,
triggerRef
}
=
usePanelRouterContext
()
const
[
vertical
,
horizontal
]
=
state
.
devToolsPosition
.
split
(
'-'
,
2
)
const
menuRef
=
useRef
<
HTMLDivElement
>
(
null
)
useClickOutside
(
menuRef
,
triggerRef
,
closeOnClickOutside
,
()
=>
{
setPanel
(
'panel-selector'
)
})
const
[
selectedIndex
,
setSelectedIndex
]
=
useState
(
-
1
)
const
indicatorOffset
=
getIndicatorOffset
(
state
)
const
[
indicatorVertical
,
indicatorHorizontal
]
=
state
.
devToolsPosition
.
split
(
'-'
,
2
)
const
verticalOffset
=
vertical
===
indicatorVertical
&&
horizontal
===
indicatorHorizontal
?
indicatorOffset
:
INDICATOR_PADDING
const
positionStyle
=
{
[
vertical
]:
`
${
verticalOffset
}
px`
,
[
horizontal
]:
`
${
INDICATOR_PADDING
}
px`
,
[
vertical
===
'top'
?
'bottom'
:
'top'
]:
'auto'
,
[
horizontal
===
'left'
?
'right'
:
'left'
]:
'auto'
,
}
as
CSSProperties
const
definedItems
=
items
.
filter
((
item
)
=>
!!
item
)
const
itemsAboveFooter
=
definedItems
.
filter
((
item
)
=>
!
item
.
footer
)
const
itemsBelowFooter
=
definedItems
.
filter
((
item
)
=>
item
.
footer
)
return
(
<
div
ref=
{
menuRef
}
id=
"nextjs-dev-tools-menu"
role=
"menu"
dir=
"ltr"
aria
-
orientation=
"vertical"
aria
-
label=
"Next.js Dev Tools Items"
tabIndex=
{
-
1
}
style=
{
{
WebkitFontSmoothing
:
'antialiased'
,
display
:
'flex'
,
flexDirection
:
'column'
,
alignItems
:
'flex-start'
,
background
:
'var(--color-background-100)'
,
backgroundClip
:
'padding-box'
,
boxShadow
:
'var(--shadow-menu)'
,
borderRadius
:
'var(--rounded-xl)'
,
position
:
'fixed'
,
fontFamily
:
'var(--font-stack-sans)'
,
zIndex
:
3
,
overflow
:
'hidden'
,
opacity
:
1
,
minWidth
:
'248px'
,
transition
:
'opacity var(--animate-out-duration-ms) var(--animate-out-timing-function)'
,
border
:
'1px solid var(--color-gray-200)'
,
...
positionStyle
,
}
}
// TODO: bring over keydown logic from old impl
// onKeyDown={onMenuKeydown}
>
<
MenuContext
value=
{
{
selectedIndex
,
setSelectedIndex
,
}
}
>
<
div
style=
{
{
padding
:
'6px'
,
width
:
'100%'
}
}
>
{
itemsAboveFooter
.
map
((
item
,
index
)
=>
(
<
MenuItem
key=
{
item
.
label
}
title=
{
item
.
title
}
label=
{
item
.
label
}
value=
{
item
.
value
}
onClick=
{
item
.
onClick
}
index=
{
index
}
{
...
item
.
attributes
}
/>
))
}
</
div
>
<
div
className=
"dev-tools-indicator-footer"
>
{
itemsBelowFooter
.
map
((
item
,
index
)
=>
(
<
MenuItem
key=
{
item
.
label
}
title=
{
item
.
title
}
label=
{
item
.
label
}
value=
{
item
.
value
}
onClick=
{
item
.
onClick
}
{
...
item
.
attributes
}
index=
{
itemsAboveFooter
.
length
+
index
}
/>
))
}
</
div
>
</
MenuContext
>
</
div
>
)
}
export
function
IssueCount
({
children
}:
{
children
:
number
})
{
return
(
<
span
className=
"dev-tools-indicator-issue-count"
data
-
has
-
issues=
{
children
>
0
}
>
<
span
className=
"dev-tools-indicator-issue-count-indicator"
/>
{
children
}
</
span
>
)
}
export
function
ChevronRight
()
{
return
(
<
svg
xmlns=
"http://www.w3.org/2000/svg"
width=
"16"
height=
"16"
viewBox=
"0 0 16 16"
fill=
"none"
>
<
path
fill=
"#666"
fillRule=
"evenodd"
clipRule=
"evenodd"
d=
"M5.50011 1.93945L6.03044 2.46978L10.8537 7.293C11.2442 7.68353 11.2442 8.31669 10.8537 8.70722L6.03044 13.5304L5.50011 14.0608L4.43945 13.0001L4.96978 12.4698L9.43945 8.00011L4.96978 3.53044L4.43945 3.00011L5.50011 1.93945Z"
/>
</
svg
>
)
}
packages/next/src/next-devtools/dev-overlay/menu/panel-router.tsx
0 → 100644
View file @
30743443
import
{
usePanelRouterContext
,
type
PanelStateKind
as
PanelNameKind
,
}
from
'./context'
import
{
ChevronRight
,
DevtoolMenu
,
IssueCount
}
from
'./dev-overlay-menu'
import
{
DynamicPanel
}
from
'../panel/panel'
import
{
RouteInfoBody
}
from
'../components/errors/dev-tools-indicator/dev-tools-info/route-info'
import
{
PageSegmentTree
}
from
'../components/overview/segment-explorer'
import
{
TurbopackInfoBody
}
from
'../components/errors/dev-tools-indicator/dev-tools-info/turbopack-info'
import
{
DevToolsHeader
}
from
'../components/errors/dev-tools-indicator/dev-tools-info/dev-tools-header'
import
{
useDelayedRender
}
from
'../hooks/use-delayed-render'
import
{
MENU_CURVE
,
MENU_DURATION_MS
,
}
from
'../components/errors/dev-tools-indicator/utils'
import
{
useDevOverlayContext
}
from
'../../dev-overlay.browser'
import
{
createContext
,
useContext
,
useRef
}
from
'react'
import
{
useRenderErrorContext
}
from
'../dev-overlay'
import
{
ACTION_DEV_INDICATOR_SET
,
ACTION_DEVTOOLS_POSITION
,
ACTION_DEVTOOLS_SCALE
,
ACTION_ERROR_OVERLAY_OPEN
,
}
from
'../shared'
import
GearIcon
from
'../icons/gear-icon'
import
{
UserPreferencesBody
}
from
'../components/errors/dev-tools-indicator/dev-tools-info/user-preferences'
import
{
useHideShortcutStorage
}
from
'../components/errors/dev-tools-indicator/dev-tools-info/preferences'
import
{
useShortcuts
}
from
'../hooks/use-shortcuts'
const
MenuPanel
=
()
=>
{
const
{
setPanel
}
=
usePanelRouterContext
()
const
{
state
,
dispatch
}
=
useDevOverlayContext
()
const
{
totalErrorCount
}
=
useRenderErrorContext
()
return
(
<
DevtoolMenu
closeOnClickOutside
items=
{
[
totalErrorCount
>
0
&&
{
title
:
`${totalErrorCount} ${totalErrorCount === 1 ? 'issue' : 'issues'} found. Click to view details in the dev overlay.`
,
label
:
'Issues'
,
value
:
<
IssueCount
>
{
totalErrorCount
}
</
IssueCount
>,
onClick
:
()
=>
{
setPanel
(
null
)
if
(
totalErrorCount
>
0
)
{
dispatch
({
type
:
ACTION_ERROR_OVERLAY_OPEN
,
})
}
},
},
{
title
:
`Current route is ${state.staticIndicator ? 'static' : 'dynamic'}.`
,
label
:
'Route'
,
value
:
state
.
staticIndicator
?
'Static'
:
'Dynamic'
,
onClick
:
()
=>
setPanel
(
'route-info'
),
attributes
:
{
'data-nextjs-route-type'
:
state
.
staticIndicator
?
'static'
:
'dynamic'
,
},
},
!!
process
.
env
.
TURBOPACK
?
{
title
:
'Turbopack is enabled.'
,
label
:
'Turbopack'
,
value
:
'Enabled'
,
}
:
{
title
:
'Learn about Turbopack and how to enable it in your application.'
,
label
:
'Try Turbopack'
,
value
:
<
ChevronRight
/>,
onClick
:
()
=>
setPanel
(
'turbo-info'
),
},
{
label
:
'Route Info'
,
value
:
<
ChevronRight
/>,
onClick
:
()
=>
setPanel
(
'segment-explorer'
),
attributes
:
{
'data-segment-explorer'
:
true
,
},
},
{
label
:
'Preferences'
,
value
:
<
GearIcon
/>,
onClick
:
()
=>
setPanel
(
'preferences'
),
footer
:
true
,
attributes
:
{
'data-preferences'
:
true
,
},
},
]
}
/>
)
}
export
const
PanelRouter
=
()
=>
{
const
{
setPanel
}
=
usePanelRouterContext
()
const
{
state
}
=
useDevOverlayContext
()
return
(
// TODO: determine for each panel if it: resizes, drags, closes on click outside
<>
<
PanelRoute
name=
"panel-selector"
>
<
MenuPanel
/>
</
PanelRoute
>
<
PanelRoute
name=
"preferences"
>
<
DynamicPanel
sizeConfig=
{
{
kind
:
'fixed'
,
// maybe to dynamic sizing automatically? little tricky
height
:
656
,
width
:
480
+
32
,
}
}
closeOnClickOutside
header=
{
<
DevToolsHeader
title=
"Preferences"
onBack=
{
()
=>
setPanel
(
'panel-selector'
)
}
/>
}
>
{
/* todo: we broke recording key binds and hiding the devtools */
}
<
UserPreferencesWrapper
/>
</
DynamicPanel
>
</
PanelRoute
>
<
PanelRoute
name=
"route-info"
>
<
DynamicPanel
sizeConfig=
{
{
kind
:
'resizable'
,
// todo till refactor for strings
maxHeight
:
1500
,
maxWidth
:
1500
,
minHeight
:
200
,
minWidth
:
200
,
}
}
closeOnClickOutside
header=
{
<
DevToolsHeader
title=
{
`${state.staticIndicator ? 'Static' : 'Dynamic'} Route`
}
onBack=
{
()
=>
setPanel
(
'panel-selector'
)
}
/>
}
>
<
RouteInfoBody
routerType=
{
state
.
routerType
}
isStaticRoute=
{
state
.
staticIndicator
}
style=
{
{
padding
:
'20px'
,
}
}
/>
</
DynamicPanel
>
</
PanelRoute
>
<
PanelRoute
name=
"segment-explorer"
>
<
DynamicPanel
sizeConfig=
{
{
kind
:
'resizable'
,
// todo till refactor for strings
maxHeight
:
1500
,
maxWidth
:
1500
,
minHeight
:
200
,
minWidth
:
200
,
}
}
header=
{
<
DevToolsHeader
title=
"Segment Explorer"
onBack=
{
()
=>
setPanel
(
'panel-selector'
)
}
/>
}
>
<
PageSegmentTree
isAppRouter=
{
state
.
routerType
===
'app'
}
page=
{
state
.
page
}
/>
</
DynamicPanel
>
</
PanelRoute
>
<
PanelRoute
name=
"turbo-info"
>
{
/* todo dedupe all these names */
}
<
DynamicPanel
sizeConfig=
{
{
kind
:
'resizable'
,
// todo till refactor for strings
maxHeight
:
1500
,
maxWidth
:
1500
,
minHeight
:
200
,
minWidth
:
200
,
}
}
// todo: fix scroll on header so its fixed and body scrolls
closeOnClickOutside
header=
{
<
DevToolsHeader
title=
"Turbopack Info"
onBack=
{
()
=>
setPanel
(
'panel-selector'
)
}
/>
}
>
<
TurbopackInfoBody
style=
{
{
padding
:
'20px'
,
}
}
/>
</
DynamicPanel
>
</
PanelRoute
>
</>
)
}
const
UserPreferencesWrapper
=
()
=>
{
const
[
hideShortcut
,
setHideShortcut
]
=
useHideShortcutStorage
()
const
{
dispatch
,
state
}
=
useDevOverlayContext
()
const
{
triggerRef
}
=
usePanelRouterContext
()
const
rootRef
=
useRef
<
HTMLDivElement
>
(
null
)
// todo, need:
/**
* shortcut listener (i broke it because i was playing around with hide toolbar state should be easy fix)
* focus trap
* the select index stuff
* maybe?
* all defined in devtools popover in dev-tools-indicator.tsx
*/
function
hideDevTools
()
{
dispatch
({
type
:
ACTION_DEV_INDICATOR_SET
,
disabled
:
true
,
})
const
root
=
rootRef
.
current
// Toggle custom hidden attribute, no need
// to close the menu in case you want to quickly get it
// out the way to see an element behind it.
if
(
root
)
{
root
.
dataset
.
hidden
=
root
.
dataset
.
hidden
===
'true'
?
'false'
:
'true'
}
}
useShortcuts
(
hideShortcut
?
{
[
hideShortcut
]:
hideDevTools
}
:
{},
triggerRef
)
return
(
<
div
ref=
{
rootRef
}
style=
{
{
padding
:
'16px'
,
// paddingTop: '0px'
background
:
'var(--color-background-100)'
,
}
}
>
<
UserPreferencesBody
position=
{
state
.
devToolsPosition
}
scale=
{
state
.
scale
}
setScale=
{
(
scale
)
=>
{
dispatch
({
type
:
ACTION_DEVTOOLS_SCALE
,
scale
,
})
}
}
setPosition=
{
(
devToolsPosition
)
=>
{
dispatch
({
type
:
ACTION_DEVTOOLS_POSITION
,
devToolsPosition
,
})
}
}
hideShortcut=
{
hideShortcut
}
setHideShortcut=
{
setHideShortcut
}
hide=
{
()
=>
{
dispatch
({
type
:
ACTION_DEV_INDICATOR_SET
,
disabled
:
true
,
})
fetch
(
'/__nextjs_disable_dev_indicator'
,
{
method
:
'POST'
,
})
}
}
/>
</
div
>
)
}
export
const
usePanelContext
=
()
=>
useContext
(
PanelContext
)
export
const
PanelContext
=
createContext
<
{
name
:
string
}
>
(
null
!
)
function
PanelRoute
({
children
,
name
,
}:
{
children
:
React
.
ReactNode
name
:
PanelNameKind
})
{
const
{
panel
}
=
usePanelRouterContext
()
const
{
mounted
,
rendered
}
=
useDelayedRender
(
name
===
panel
,
{
enterDelay
:
0
,
exitDelay
:
MENU_DURATION_MS
,
})
if
(
!
mounted
)
return
null
return
(
<
PanelContext
value=
{
{
name
,
}
}
>
<
div
style=
{
{
opacity
:
rendered
?
1
:
0
,
transition
:
`opacity ${MENU_DURATION_MS}ms ${MENU_CURVE}`
,
}
}
>
{
children
}
</
div
>
</
PanelContext
>
)
}
packages/next/src/next-devtools/dev-overlay/panel/panel.tsx
0 → 100644
View file @
30743443
import
{
useMemo
,
useRef
,
type
CSSProperties
}
from
'react'
import
{
useDevOverlayContext
}
from
'../../dev-overlay.browser'
import
{
ResizeProvider
}
from
'../components/devtools-panel/resize/resize-provider'
import
{
usePanelRouterContext
}
from
'../menu/context'
import
{
INDICATOR_PADDING
}
from
'../components/devtools-indicator/devtools-indicator'
import
{
getIndicatorOffset
}
from
'../utils/indicator-metrics'
import
{
Draggable
}
from
'../components/errors/dev-tools-indicator/draggable'
import
{
ACTION_DEVTOOLS_PANEL_POSITION
,
STORAGE_KEY_PANEL_POSITION
,
type
Corners
,
}
from
'../shared'
import
{
ResizeHandle
}
from
'../components/devtools-panel/resize/resize-handle'
import
{
DragHandle
,
DragProvider
,
}
from
'../components/errors/dev-tools-indicator/drag-context'
import
{
useClickOutside
}
from
'../components/errors/dev-tools-indicator/utils'
import
{
usePanelContext
}
from
'../menu/panel-router'
export
function
DynamicPanel
({
header
,
children
,
draggable
=
true
,
sizeConfig
=
{
kind
:
'resizable'
,
minWidth
:
400
,
minHeight
:
350
,
maxWidth
:
1000
,
maxHeight
:
1000
,
},
closeOnClickOutside
=
false
,
...
containerProps
}:
{
header
:
React
.
ReactNode
children
:
React
.
ReactNode
draggable
?:
boolean
// todo: allow strings w/ css units
sizeConfig
?:
|
{
kind
:
'resizable'
minWidth
:
number
minHeight
:
number
maxWidth
:
number
maxHeight
:
number
}
|
{
kind
:
'fixed'
height
:
number
width
:
number
}
closeOnClickOutside
?:
boolean
}
&
React
.
HTMLProps
<
HTMLDivElement
>
)
{
const
{
setPanel
}
=
usePanelRouterContext
()
const
{
name
}
=
usePanelContext
()
const
{
dispatch
,
state
}
=
useDevOverlayContext
()
const
storagePositionKey
=
`
${
STORAGE_KEY_PANEL_POSITION
}
-
${
name
}
`
const
panelPosition
:
string
=
useMemo
(()
=>
{
if
(
typeof
window
!==
'undefined'
)
{
return
(
localStorage
.
getItem
(
storagePositionKey
)
||
state
.
devToolsPanelPosition
||
state
.
devToolsPosition
)
}
return
state
.
devToolsPosition
},
[
storagePositionKey
,
state
.
devToolsPanelPosition
,
state
.
devToolsPosition
])
const
[
vertical
,
horizontal
]
=
panelPosition
.
split
(
'-'
,
2
)
const
resizeRef
=
useRef
<
HTMLDivElement
>
(
null
)
const
{
triggerRef
}
=
usePanelRouterContext
()
useClickOutside
(
resizeRef
,
triggerRef
,
closeOnClickOutside
,
()
=>
{
setPanel
(
'panel-selector'
)
})
const
indicatorOffset
=
getIndicatorOffset
(
state
)
const
[
indicatorVertical
,
indicatorHorizontal
]
=
state
.
devToolsPosition
.
split
(
'-'
,
2
)
const
verticalOffset
=
vertical
===
indicatorVertical
&&
horizontal
===
indicatorHorizontal
?
indicatorOffset
:
INDICATOR_PADDING
const
positionStyle
=
{
[
vertical
]:
`
${
verticalOffset
}
px`
,
[
horizontal
]:
`
${
INDICATOR_PADDING
}
px`
,
[
vertical
===
'top'
?
'bottom'
:
'top'
]:
'auto'
,
[
horizontal
===
'left'
?
'right'
:
'left'
]:
'auto'
,
}
as
CSSProperties
const
isResizable
=
sizeConfig
.
kind
===
'resizable'
const
minWidth
=
isResizable
?
sizeConfig
.
minWidth
:
undefined
const
minHeight
=
isResizable
?
sizeConfig
.
minHeight
:
undefined
const
maxWidth
=
isResizable
?
sizeConfig
.
maxWidth
:
undefined
const
maxHeight
=
isResizable
?
sizeConfig
.
maxHeight
:
undefined
const
fixedWidth
=
!
isResizable
?
sizeConfig
.
width
:
undefined
const
fixedHeight
=
!
isResizable
?
sizeConfig
.
height
:
undefined
const
resizeStorageKey
=
`
${
name
}
-panel-resize`
const
{
storedWidth
,
storedHeight
}
=
useMemo
(()
=>
{
if
(
typeof
window
===
'undefined'
)
return
{
storedWidth
:
undefined
,
storedHeight
:
undefined
}
try
{
const
stored
=
JSON
.
parse
(
window
.
localStorage
.
getItem
(
resizeStorageKey
)
||
'null'
)
as
{
width
?:
number
;
height
?:
number
}
|
null
return
{
storedWidth
:
stored
?.
width
,
storedHeight
:
stored
?.
height
,
}
}
catch
{
return
{
storedWidth
:
undefined
,
storedHeight
:
undefined
}
}
},
[
resizeStorageKey
])
return
(
<
ResizeProvider
value=
{
{
resizeRef
,
minWidth
,
minHeight
,
devToolsPosition
:
state
.
devToolsPosition
,
storageKey
:
resizeStorageKey
,
}
}
>
<
div
ref=
{
resizeRef
}
style=
{
{
position
:
'fixed'
,
zIndex
:
2147483646
,
...
positionStyle
,
...(
isResizable
?
{
minWidth
,
minHeight
,
maxWidth
,
maxHeight
,
width
:
storedWidth
?
`${storedWidth}px`
:
undefined
,
height
:
storedHeight
?
`${storedHeight}px`
:
undefined
,
}
:
{
height
:
storedHeight
?
`${storedHeight}px`
:
fixedHeight
,
width
:
storedWidth
?
`${storedWidth}px`
:
fixedWidth
!==
undefined
?
fixedWidth
:
'100%'
,
}),
}
}
>
<
DragProvider
disabled=
{
!
draggable
}
>
<
Draggable
dragHandleSelector=
".resize-container"
avoidZone=
{
{
corner
:
state
.
devToolsPosition
,
square
:
25
/
state
.
scale
,
padding
:
INDICATOR_PADDING
,
}
}
padding=
{
INDICATOR_PADDING
}
onDragStart=
{
()
=>
{}
}
position=
{
panelPosition
as
Corners
}
setPosition=
{
(
p
)
=>
{
localStorage
.
setItem
(
storagePositionKey
,
p
)
dispatch
({
type
:
ACTION_DEVTOOLS_PANEL_POSITION
,
devToolsPanelPosition
:
p
,
})
}
}
style=
{
{
overflow
:
'auto'
,
width
:
'100%'
,
height
:
'100%'
,
}
}
disableDrag=
{
!
draggable
}
>
<>
<
div
{
...
containerProps
}
style=
{
{
position
:
'relative'
,
width
:
'100%'
,
height
:
'100%'
,
border
:
'1px solid var(--color-gray-200)'
,
borderRadius
:
'var(--rounded-xl)'
,
background
:
'var(--color-background-100)'
,
overflow
:
'auto'
,
...
containerProps
.
style
,
}
}
>
<
DragHandle
>
{
header
}
</
DragHandle
>
{
children
}
</
div
>
{
isResizable
&&
(
<>
<
ResizeHandle
position=
{
state
.
devToolsPanelPosition
}
direction=
"top"
/>
<
ResizeHandle
position=
{
state
.
devToolsPanelPosition
}
direction=
"right"
/>
<
ResizeHandle
position=
{
state
.
devToolsPanelPosition
}
direction=
"bottom"
/>
<
ResizeHandle
position=
{
state
.
devToolsPanelPosition
}
direction=
"left"
/>
<
ResizeHandle
position=
{
state
.
devToolsPanelPosition
}
direction=
"top-left"
/>
<
ResizeHandle
position=
{
state
.
devToolsPanelPosition
}
direction=
"top-right"
/>
<
ResizeHandle
position=
{
state
.
devToolsPanelPosition
}
direction=
"bottom-left"
/>
<
ResizeHandle
position=
{
state
.
devToolsPanelPosition
}
direction=
"bottom-right"
/>
</>
)
}
</>
</
Draggable
>
</
DragProvider
>
</
div
>
</
ResizeProvider
>
)
}
packages/next/src/next-devtools/dev-overlay/shared.ts
View file @
30743443
...
@@ -49,6 +49,7 @@ export interface OverlayState {
...
@@ -49,6 +49,7 @@ export interface OverlayState {
isErrorOverlayOpen
:
boolean
isErrorOverlayOpen
:
boolean
isDevToolsPanelOpen
:
boolean
isDevToolsPanelOpen
:
boolean
devToolsPosition
:
Corners
devToolsPosition
:
Corners
devToolsPanelPosition
:
Corners
scale
:
number
scale
:
number
page
:
string
page
:
string
}
}
...
@@ -64,6 +65,7 @@ export const ACTION_UNHANDLED_ERROR = 'unhandled-error'
...
@@ -64,6 +65,7 @@ export const ACTION_UNHANDLED_ERROR = 'unhandled-error'
export
const
ACTION_UNHANDLED_REJECTION
=
'unhandled-rejection'
export
const
ACTION_UNHANDLED_REJECTION
=
'unhandled-rejection'
export
const
ACTION_DEBUG_INFO
=
'debug-info'
export
const
ACTION_DEBUG_INFO
=
'debug-info'
export
const
ACTION_DEV_INDICATOR
=
'dev-indicator'
export
const
ACTION_DEV_INDICATOR
=
'dev-indicator'
export
const
ACTION_DEV_INDICATOR_SET
=
'dev-indicator-disable'
export
const
ACTION_ERROR_OVERLAY_OPEN
=
'error-overlay-open'
export
const
ACTION_ERROR_OVERLAY_OPEN
=
'error-overlay-open'
export
const
ACTION_ERROR_OVERLAY_CLOSE
=
'error-overlay-close'
export
const
ACTION_ERROR_OVERLAY_CLOSE
=
'error-overlay-close'
...
@@ -79,11 +81,13 @@ export const ACTION_DEVTOOLS_PANEL_CLOSE = 'devtools-panel-close'
...
@@ -79,11 +81,13 @@ export const ACTION_DEVTOOLS_PANEL_CLOSE = 'devtools-panel-close'
export
const
ACTION_DEVTOOLS_PANEL_TOGGLE
=
'devtools-panel-toggle'
export
const
ACTION_DEVTOOLS_PANEL_TOGGLE
=
'devtools-panel-toggle'
export
const
ACTION_DEVTOOLS_POSITION
=
'devtools-position'
export
const
ACTION_DEVTOOLS_POSITION
=
'devtools-position'
export
const
ACTION_DEVTOOLS_PANEL_POSITION
=
'devtools-panel-position'
export
const
ACTION_DEVTOOLS_SCALE
=
'devtools-scale'
export
const
ACTION_DEVTOOLS_SCALE
=
'devtools-scale'
export
const
ACTION_RESTART_SERVER_BUTTON
=
'restart-server-button'
export
const
ACTION_RESTART_SERVER_BUTTON
=
'restart-server-button'
export
const
STORAGE_KEY_THEME
=
'__nextjs-dev-tools-theme'
export
const
STORAGE_KEY_THEME
=
'__nextjs-dev-tools-theme'
export
const
STORAGE_KEY_POSITION
=
'__nextjs-dev-tools-position'
export
const
STORAGE_KEY_POSITION
=
'__nextjs-dev-tools-position'
export
const
STORAGE_KEY_PANEL_POSITION
=
'__nextjs-dev-tools-panel-position'
export
const
STORAGE_KEY_SCALE
=
'__nextjs-dev-tools-scale'
export
const
STORAGE_KEY_SCALE
=
'__nextjs-dev-tools-scale'
export
const
STORAGE_KEY_ACTIVE_TAB
=
'__nextjs-devtools-active-tab'
export
const
STORAGE_KEY_ACTIVE_TAB
=
'__nextjs-devtools-active-tab'
...
@@ -133,6 +137,11 @@ interface DevIndicatorAction {
...
@@ -133,6 +137,11 @@ interface DevIndicatorAction {
devIndicator
:
DevIndicatorServerState
devIndicator
:
DevIndicatorServerState
}
}
interface
DevIndicatorSetAction
{
type
:
typeof
ACTION_DEV_INDICATOR_SET
disabled
:
boolean
}
export
interface
ErrorOverlayOpenAction
{
export
interface
ErrorOverlayOpenAction
{
type
:
typeof
ACTION_ERROR_OVERLAY_OPEN
type
:
typeof
ACTION_ERROR_OVERLAY_OPEN
}
}
...
@@ -172,6 +181,11 @@ export interface DevToolsIndicatorPositionAction {
...
@@ -172,6 +181,11 @@ export interface DevToolsIndicatorPositionAction {
devToolsPosition
:
Corners
devToolsPosition
:
Corners
}
}
export
interface
DevToolsPanelPositionAction
{
type
:
typeof
ACTION_DEVTOOLS_PANEL_POSITION
devToolsPanelPosition
:
Corners
}
export
interface
DevToolsScaleAction
{
export
interface
DevToolsScaleAction
{
type
:
typeof
ACTION_DEVTOOLS_SCALE
type
:
typeof
ACTION_DEVTOOLS_SCALE
scale
:
number
scale
:
number
...
@@ -209,9 +223,11 @@ export type DispatcherEvent =
...
@@ -209,9 +223,11 @@ export type DispatcherEvent =
|
DevToolsPanelCloseAction
|
DevToolsPanelCloseAction
|
DevToolsPanelToggleAction
|
DevToolsPanelToggleAction
|
DevToolsIndicatorPositionAction
|
DevToolsIndicatorPositionAction
|
DevToolsPanelPositionAction
|
DevToolsScaleAction
|
DevToolsScaleAction
|
DevToolUpdateRouteStateAction
|
DevToolUpdateRouteStateAction
|
RestartServerButtonAction
|
RestartServerButtonAction
|
DevIndicatorSetAction
const
REACT_ERROR_STACK_BOTTOM_FRAME_REGEX
=
const
REACT_ERROR_STACK_BOTTOM_FRAME_REGEX
=
// 1st group: new frame + v8
// 1st group: new frame + v8
...
@@ -231,6 +247,42 @@ function getStackIgnoringStrictMode(stack: string | undefined) {
...
@@ -231,6 +247,42 @@ function getStackIgnoringStrictMode(stack: string | undefined) {
const
shouldDisableDevIndicator
=
const
shouldDisableDevIndicator
=
process
.
env
.
__NEXT_DEV_INDICATOR
?.
toString
()
===
'false'
process
.
env
.
__NEXT_DEV_INDICATOR
?.
toString
()
===
'false'
// TODO: change local storage impl
function
getStoredPosition
():
Corners
{
if
(
typeof
localStorage
!==
'undefined'
)
{
const
stored
=
localStorage
.
getItem
(
STORAGE_KEY_POSITION
)
if
(
stored
&&
[
'top-left'
,
'top-right'
,
'bottom-left'
,
'bottom-right'
].
includes
(
stored
)
)
{
return
stored
as
Corners
}
}
const
envPosition
=
process
.
env
.
__NEXT_DEV_INDICATOR_POSITION
if
(
envPosition
&&
[
'top-left'
,
'top-right'
,
'bottom-left'
,
'bottom-right'
].
includes
(
envPosition
)
)
{
return
envPosition
as
Corners
}
return
'bottom-left'
}
function
getStoredPanelPosition
():
Corners
|
null
{
if
(
typeof
localStorage
!==
'undefined'
)
{
const
stored
=
localStorage
.
getItem
(
STORAGE_KEY_PANEL_POSITION
)
if
(
stored
&&
[
'top-left'
,
'top-right'
,
'bottom-left'
,
'bottom-right'
].
includes
(
stored
)
)
{
return
stored
as
Corners
}
}
return
null
}
export
const
INITIAL_OVERLAY_STATE
:
Omit
<
export
const
INITIAL_OVERLAY_STATE
:
Omit
<
OverlayState
,
OverlayState
,
'isErrorOverlayOpen'
|
'routerType'
'isErrorOverlayOpen'
|
'routerType'
...
@@ -254,7 +306,8 @@ export const INITIAL_OVERLAY_STATE: Omit<
...
@@ -254,7 +306,8 @@ export const INITIAL_OVERLAY_STATE: Omit<
debugInfo
:
{
devtoolsFrontendUrl
:
undefined
},
debugInfo
:
{
devtoolsFrontendUrl
:
undefined
},
isDevToolsPanelOpen
:
false
,
isDevToolsPanelOpen
:
false
,
showRestartServerButton
:
false
,
showRestartServerButton
:
false
,
devToolsPosition
:
'bottom-left'
,
devToolsPosition
:
getStoredPosition
(),
devToolsPanelPosition
:
getStoredPanelPosition
()
??
'bottom-left'
,
scale
:
NEXT_DEV_TOOLS_SCALE
.
Medium
,
scale
:
NEXT_DEV_TOOLS_SCALE
.
Medium
,
page
:
''
,
page
:
''
,
}
}
...
@@ -390,6 +443,9 @@ export function useErrorOverlayReducer(
...
@@ -390,6 +443,9 @@ export function useErrorOverlayReducer(
case
ACTION_VERSION_INFO
:
{
case
ACTION_VERSION_INFO
:
{
return
{
...
state
,
versionInfo
:
action
.
versionInfo
}
return
{
...
state
,
versionInfo
:
action
.
versionInfo
}
}
}
case
ACTION_DEV_INDICATOR_SET
:
{
return
{
...
state
,
disableDevIndicator
:
action
.
disabled
}
}
case
ACTION_DEV_INDICATOR
:
{
case
ACTION_DEV_INDICATOR
:
{
return
{
return
{
...
state
,
...
state
,
...
@@ -431,6 +487,12 @@ export function useErrorOverlayReducer(
...
@@ -431,6 +487,12 @@ export function useErrorOverlayReducer(
case
ACTION_DEVTOOLS_POSITION
:
{
case
ACTION_DEVTOOLS_POSITION
:
{
return
{
...
state
,
devToolsPosition
:
action
.
devToolsPosition
}
return
{
...
state
,
devToolsPosition
:
action
.
devToolsPosition
}
}
}
case
ACTION_DEVTOOLS_PANEL_POSITION
:
{
return
{
...
state
,
devToolsPanelPosition
:
action
.
devToolsPanelPosition
,
}
}
case
ACTION_DEVTOOLS_SCALE
:
{
case
ACTION_DEVTOOLS_SCALE
:
{
return
{
...
state
,
scale
:
action
.
scale
}
return
{
...
state
,
scale
:
action
.
scale
}
}
}
...
...
packages/next/src/next-devtools/dev-overlay/storybook/DevOverlayStoryWrapper.tsx
0 → 100644
View file @
30743443
import
{
DevOverlay
}
from
'../dev-overlay'
import
{
DevOverlayContext
}
from
'../../dev-overlay.browser'
import
{
useStorybookOverlayReducer
,
storybookDefaultOverlayState
,
}
from
'./use-overlay-reducer'
import
type
{
OverlayState
}
from
'../shared'
import
type
{
ReadyRuntimeError
}
from
'../utils/get-error-by-type'
type
WrapperProps
=
{
initialState
?:
Partial
<
OverlayState
>
runtimeErrors
?:
ReadyRuntimeError
[]
children
?:
never
}
// todo: wrap stories in this so props are configurable
export
function
DevOverlayStoryWrapper
({
initialState
}:
WrapperProps
)
{
const
mergedState
:
OverlayState
=
{
...
storybookDefaultOverlayState
,
...
initialState
,
}
as
OverlayState
const
[
state
,
dispatch
]
=
useStorybookOverlayReducer
(
mergedState
)
return
(
<
DevOverlayContext
value=
{
{
state
,
dispatch
,
getSquashedHydrationErrorDetails
:
()
=>
null
}
}
>
<
DevOverlay
state=
{
state
}
dispatch=
{
dispatch
}
getSquashedHydrationErrorDetails=
{
()
=>
null
}
/>
</
DevOverlayContext
>
)
}
packages/next/src/next-devtools/dev-overlay/storybook/use-overlay-reducer.ts
View file @
30743443
...
@@ -3,6 +3,7 @@ import type { DispatcherEvent, OverlayState } from '../shared'
...
@@ -3,6 +3,7 @@ import type { DispatcherEvent, OverlayState } from '../shared'
import
{
useReducer
}
from
'react'
import
{
useReducer
}
from
'react'
import
{
import
{
ACTION_DEVTOOLS_POSITION
,
ACTION_DEVTOOLS_POSITION
,
ACTION_DEVTOOLS_PANEL_POSITION
,
ACTION_DEVTOOLS_PANEL_CLOSE
,
ACTION_DEVTOOLS_PANEL_CLOSE
,
ACTION_DEVTOOLS_PANEL_TOGGLE
,
ACTION_DEVTOOLS_PANEL_TOGGLE
,
ACTION_ERROR_OVERLAY_CLOSE
,
ACTION_ERROR_OVERLAY_CLOSE
,
...
@@ -16,7 +17,7 @@ import {
...
@@ -16,7 +17,7 @@ import {
export
const
storybookDefaultOverlayState
:
OverlayState
=
{
export
const
storybookDefaultOverlayState
:
OverlayState
=
{
...
INITIAL_OVERLAY_STATE
,
...
INITIAL_OVERLAY_STATE
,
routerType
:
'app'
,
routerType
:
'app'
,
isErrorOverlayOpen
:
tru
e
,
isErrorOverlayOpen
:
fals
e
,
showIndicator
:
true
,
showIndicator
:
true
,
versionInfo
:
{
versionInfo
:
{
installed
:
'15.4.0'
,
installed
:
'15.4.0'
,
...
@@ -49,6 +50,13 @@ export function useStorybookOverlayReducer(initialState?: OverlayState) {
...
@@ -49,6 +50,13 @@ export function useStorybookOverlayReducer(initialState?: OverlayState) {
case
ACTION_DEVTOOLS_POSITION
:
{
case
ACTION_DEVTOOLS_POSITION
:
{
return
{
...
state
,
devToolsPosition
:
action
.
devToolsPosition
}
return
{
...
state
,
devToolsPosition
:
action
.
devToolsPosition
}
}
}
// todo remove
case
ACTION_DEVTOOLS_PANEL_POSITION
:
{
return
{
...
state
,
devToolsPanelPosition
:
action
.
devToolsPanelPosition
,
}
}
case
ACTION_DEVTOOLS_SCALE
:
{
case
ACTION_DEVTOOLS_SCALE
:
{
return
{
...
state
,
scale
:
action
.
scale
}
return
{
...
state
,
scale
:
action
.
scale
}
}
}
...
...
packages/next/src/next-devtools/dev-overlay/utils/indicator-metrics.ts
0 → 100644
View file @
30743443
import
{
INDICATOR_PADDING
}
from
'../components/devtools-indicator/devtools-indicator'
import
type
{
OverlayState
}
from
'../shared'
// TODO(rob): these numbers are very wrong but right because de-sync
const
BASE_LOGO_SIZE
=
36
const
INDICATOR_GAP
=
9
export
function
getIndicatorSquare
(
state
:
OverlayState
):
number
{
return
BASE_LOGO_SIZE
/
state
.
scale
}
export
function
getIndicatorOffset
(
state
:
OverlayState
):
number
{
return
INDICATOR_PADDING
+
getIndicatorSquare
(
state
)
+
INDICATOR_GAP
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment