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
Hide 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 {
ACTION_RENDERING_INDICATOR_HIDE
,
ACTION_RENDERING_INDICATOR_SHOW
,
ACTION_DEVTOOL_UPDATE_ROUTE_STATE
,
type
OverlayState
,
type
DispatcherEvent
,
}
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
{
FontStyles
}
from
'./dev-overlay/font/font-styles'
import
type
{
HydrationErrorState
}
from
'./shared/hydration-error'
...
...
@@ -208,14 +216,31 @@ function DevOverlayRoot({
<>
{
/* Fonts can only be loaded outside the Shadow DOM. */
}
<
FontStyles
/>
<
DevOverlay
state=
{
state
}
dispatch=
{
dispatch
}
getSquashedHydrationErrorDetails=
{
getSquashedHydrationErrorDetails
}
/>
<
DevOverlayContext
value=
{
{
dispatch
,
getSquashedHydrationErrorDetails
,
state
,
}
}
>
<
DevOverlay
// we also pass props for legacy UI
dispatch=
{
dispatch
}
state=
{
state
}
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
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
{
OverlayState
}
from
'../../shared'
import
{
DevToolsIndicator
}
from
'./devtools-indicator'
import
{
DevToolsIndicator
New
}
from
'./devtools-indicator'
import
{
INITIAL_OVERLAY_STATE
}
from
'../../shared'
import
{
withShadowPortal
}
from
'../../storybook/with-shadow-portal'
const
meta
:
Meta
<
typeof
DevToolsIndicator
>
=
{
component
:
DevToolsIndicator
,
const
meta
:
Meta
<
typeof
DevToolsIndicator
New
>
=
{
component
:
DevToolsIndicator
New
,
parameters
:
{
layout
:
'centered'
,
},
...
...
@@ -37,7 +37,7 @@ const meta: Meta<typeof DevToolsIndicator> = {
}
export
default
meta
type
Story
=
StoryObj
<
typeof
DevToolsIndicator
>
type
Story
=
StoryObj
<
typeof
DevToolsIndicator
New
>
const
state
:
OverlayState
=
{
...
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
{
OverlayState
,
OverlayDispatch
}
from
'../../shared'
import
{
useState
}
from
'react'
import
{
NextLogo
}
from
'./next-logo'
import
{
NextLogoNew
}
from
'./next-logo'
import
{
Toast
}
from
'../toast'
import
{
MENU_CURVE
,
MENU_DURATION_MS
,
}
from
'../errors/dev-tools-indicator/utils'
import
{
ACTION_DEVTOOLS_PANEL_TOGGLE
,
STORAGE_KEY_POSITION
,
ACTION_DEVTOOLS_POSITION
,
ACTION_DEVTOOLS_PANEL_OPEN
,
ACTION_ERROR_OVERLAY_OPEN
,
}
from
'../../shared'
import
{
STORAGE_KEY_POSITION
,
ACTION_DEVTOOLS_POSITION
}
from
'../../shared'
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
function
DevToolsIndicator
({
state
,
dispatch
,
errorCount
,
isBuildError
,
}:
{
state
:
OverlayState
dispatch
:
OverlayDispatch
errorCount
:
number
isBuildError
:
boolean
})
{
const
[
open
,
setOpen
]
=
useState
(
false
)
export
function
DevToolsIndicatorNew
()
{
const
{
state
,
dispatch
}
=
useDevOverlayContext
()
const
{
triggerRef
,
setPanel
}
=
usePanelRouterContext
()
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
(
// TODO: why is this called a toast
<
Toast
data
-
nextjs
-
toast
style=
{
...
...
@@ -54,16 +30,12 @@ export function DevToolsIndicator({
boxShadow
:
'none'
,
[
vertical
]:
`${INDICATOR_PADDING}px`
,
[
horizontal
]:
`${INDICATOR_PADDING}px`
,
visibility
:
state
.
isDevToolsPanelOpen
||
state
.
isErrorOverlayOpen
?
'hidden'
:
'visible'
,
visibility
:
state
.
isErrorOverlayOpen
?
'hidden'
:
'visible'
,
}
as
CSSProperties
}
>
<
Draggable
padding=
{
INDICATOR_PADDING
}
onDragStart=
{
()
=>
setOpen
(
false
)
}
position=
{
state
.
devToolsPosition
}
setPosition=
{
(
p
)
=>
{
dispatch
({
...
...
@@ -73,21 +45,13 @@ export function DevToolsIndicator({
localStorage
.
setItem
(
STORAGE_KEY_POSITION
,
p
)
}
}
>
{
/* Trigger */
}
<
NextLogo
aria
-
haspopup=
"menu"
aria
-
expanded=
{
open
}
aria
-
controls=
"nextjs-dev-tools-menu"
aria
-
label=
{
`${open ? 'Close' : 'Open'} Next.js Dev Tools`
}
data
-
nextjs
-
dev
-
tools
-
button
disabled=
{
state
.
disableDevIndicator
}
issueCount=
{
errorCount
}
onTriggerClick=
{
toggleDevToolsPanel
}
toggleErrorOverlay=
{
enableErrorOverlayMode
}
isDevBuilding=
{
state
.
buildingIndicator
}
isDevRendering=
{
state
.
renderingIndicator
}
isBuildError=
{
isBuildError
}
scale=
{
state
.
scale
}
<
NextLogoNew
onTriggerClick=
{
()
=>
{
setPanel
((
prev
)
=>
prev
===
'panel-selector'
?
null
:
'panel-selector'
)
}
}
ref=
{
triggerRef
}
/>
</
Draggable
>
</
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
{
NextLogo
}
from
'./next-logo'
import
{
NextLogo
New
}
from
'./next-logo'
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
>
=
{
component
:
NextLogo
,
const
meta
:
Meta
<
typeof
StoryBook
NextLogo
>
=
{
component
:
StoryBook
NextLogo
,
parameters
:
{
layout
:
'centered'
,
},
args
:
{
'aria-label'
:
'Open Next.js DevTools'
,
onClick
:
()
=>
console
.
log
(
'Clicked!'
),
},
decorators
:
[
withShadowPortal
],
}
export
default
meta
type
Story
=
StoryObj
<
typeof
NextLogo
>
type
Story
=
StoryObj
<
typeof
StoryBook
NextLogo
>
export
const
NoIssues
:
Story
=
{
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
{
useUpdateAnimation
}
from
'./hooks/use-update-animation'
import
{
useMeasureWidth
}
from
'./hooks/use-measure-width'
...
...
@@ -7,45 +5,42 @@ import { useMinimumLoadingTimeMultiple } from './hooks/use-minimum-loading-time-
import
{
Cross
}
from
'../../icons/cross'
import
{
Warning
}
from
'../../icons/warning'
import
{
css
}
from
'../../utils/css'
interface
Props
extends
React
.
ComponentProps
<
'button'
>
{
issueCount
:
number
isDevBuilding
:
boolean
isDevRendering
:
boolean
isBuildError
:
boolean
onTriggerClick
:
()
=>
void
toggleErrorOverlay
:
()
=>
void
scale
:
DevToolsScale
}
import
{
useDevOverlayContext
}
from
'../../../dev-overlay.browser'
import
{
useRenderErrorContext
}
from
'../../dev-overlay'
import
{
ACTION_DEVTOOLS_PANEL_OPEN
,
ACTION_ERROR_OVERLAY_OPEN
,
}
from
'../../shared'
import
{
usePanelRouterContext
}
from
'../../menu/context'
const
SHORT_DURATION_MS
=
150
export
function
NextLogo
({
disabled
,
issueCount
,
isDevBuilding
,
isDevRendering
,
isBuildError
,
export
function
NextLogoNew
({
onTriggerClick
,
toggleErrorOverlay
,
scale
=
1
,
...
props
}:
Props
)
{
const
SIZE
=
36
/
scale
const
hasError
=
issueCount
>
0
...
buttonProps
}:
{
onTriggerClick
:
()
=>
void
}
&
React
.
ComponentProps
<
'button'
>
)
{
const
{
state
,
dispatch
}
=
useDevOverlayContext
()
const
{
totalErrorCount
}
=
useRenderErrorContext
()
const
SIZE
=
36
/
state
.
scale
const
{
panel
}
=
usePanelRouterContext
()
const
isMenuOpen
=
panel
===
'panel-selector'
const
hasError
=
totalErrorCount
>
0
const
[
isErrorExpanded
,
setIsErrorExpanded
]
=
useState
(
hasError
)
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
ref
=
useRef
<
HTMLDivElement
|
null
>
(
null
)
const
measuredWidth
=
useMeasureWidth
(
ref
)
const
isLoading
=
useMinimumLoadingTimeMultiple
(
isDevBuilding
||
isDevRendering
state
.
buildingIndicator
||
state
.
renderingIndicator
)
const
isExpanded
=
isErrorExpanded
||
disabled
const
isExpanded
=
isErrorExpanded
||
state
.
disableDevIndicator
const
width
=
measuredWidth
===
0
?
'auto'
:
measuredWidth
useEffect
(()
=>
{
...
...
@@ -61,7 +56,10 @@ export function NextLogo({
'--duration-short'
:
`${SHORT_DURATION_MS}ms`
,
// if the indicator is disabled, hide the badge
// 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
}
>
...
...
@@ -396,15 +394,25 @@ export function NextLogo({
>
<
div
ref=
{
ref
}
>
{
/* Children */
}
{
!
disabled
&&
(
{
!
state
.
disableDevIndicator
&&
(
<
button
id=
"next-logo"
ref=
{
triggerRef
}
data
-
next
-
mark
data
-
next
-
mark
-
loading=
{
isLoading
}
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
>
)
}
{
isExpanded
&&
(
...
...
@@ -412,42 +420,46 @@ export function NextLogo({
<
button
data
-
issues
-
open
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
>
<
Warning
/>
</
div
>
)
}
<
AnimateCount
// Used the key to force a re-render when the count changes.
key=
{
issue
Count
}
key=
{
totalError
Count
}
animate=
{
newErrorDetected
}
data
-
issues
-
count
-
animation
>
{
issue
Count
}
{
totalError
Count
}
</
AnimateCount
>
{
' '
}
<
div
>
Issue
{
issue
Count
>
1
&&
(
{
totalError
Count
>
1
&&
(
<
span
aria
-
hidden
data
-
issues
-
count
-
plural
// This only needs to animate once the count changes from 1 -> 2,
// otherwise it should stay static between re-renders.
data
-
animate=
{
newErrorDetected
&&
issue
Count
===
2
}
data
-
animate=
{
newErrorDetected
&&
totalError
Count
===
2
}
>
s
</
span
>
)
}
</
div
>
</
button
>
{
!
isB
uildError
&&
(
{
!
state
.
b
uildError
&&
(
<
button
data
-
issues
-
collapse
aria
-
label=
"Collapse issues badge"
onClick=
{
()
=>
{
if
(
disabled
)
{
if
(
state
.
disableDevIndicator
)
{
setDismissed
(
true
)
}
else
{
setIsErrorExpanded
(
false
)
...
...
packages/next/src/next-devtools/dev-overlay/components/devtools-panel/resize/resize-handle.css
View file @
30743443
...
...
@@ -20,14 +20,14 @@
/* start really fast because we start super hidden initially behind the panel, otherwise feels like an unintended animation delay */
.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.left
{
top
:
0
;
height
:
100%
;
width
:
2
5
px
;
width
:
2
2
px
;
cursor
:
ew-resize
;
}
...
...
@@ -37,97 +37,97 @@
.resize-container.top
{
left
:
0
;
width
:
100%
;
height
:
2
5
px
;
height
:
2
2
px
;
cursor
:
ns-resize
;
}
.resize-container.top
{
top
:
-
12
px
;
top
:
-
7
px
;
}
.resize-container.bottom
{
bottom
:
-
12
px
;
bottom
:
-
7
px
;
}
.resize-container.left
{
left
:
-
12
px
;
left
:
-
7
px
;
}
.resize-container.right
{
right
:
-
12
px
;
right
:
-
7
px
;
}
.resize-container.top-left
,
.resize-container.top-right
,
.resize-container.bottom-left
,
.resize-container.bottom-right
{
width
:
32
px
;
height
:
32
px
;
width
:
26
px
;
height
:
26
px
;
z-index
:
15
;
}
.resize-container.top-left
{
top
:
-
16
px
;
left
:
-
16
px
;
top
:
-
5
px
;
left
:
-
5
px
;
cursor
:
nwse-resize
;
}
.resize-container.top-right
{
top
:
-
16
px
;
right
:
-
16
px
;
top
:
-
5
px
;
right
:
-
5
px
;
cursor
:
nesw-resize
;
}
.resize-container.bottom-left
{
bottom
:
-
16
px
;
left
:
-
16
px
;
bottom
:
-
5
px
;
left
:
-
5
px
;
cursor
:
nesw-resize
;
}
.resize-container.bottom-right
{
bottom
:
-
16
px
;
right
:
-
16
px
;
bottom
:
-
5
px
;
right
:
-
5
px
;
cursor
:
nwse-resize
;
}
.resize-line.top
,
.resize-line.bottom
{
height
:
2
8px
;
height
:
1
8px
;
width
:
100%
;
background-color
:
var
(
--color-background-
1
00
);
background-color
:
var
(
--color-background-
2
00
);
}
.resize-line.left
,
.resize-line.right
{
width
:
2
8px
;
width
:
1
8px
;
height
:
100%
;
background-color
:
var
(
--color-background-
1
00
);
background-color
:
var
(
--color-background-
2
00
);
}
.resize-line.top
{
top
:
-
12
px
;
top
:
-
7
px
;
left
:
calc
(
-1
*
var
(
--border-left
,
2px
));
width
:
calc
(
100%
+
var
(
--border-horizontal
,
4px
));
border-radius
:
var
(
--rounded-md
)
var
(
--rounded-md
)
0
0
;
transform
:
translateY
(
2
8px
);
transform
:
translateY
(
1
8px
);
}
.resize-line.bottom
{
bottom
:
-
12
px
;
bottom
:
-
7
px
;
left
:
calc
(
-1
*
var
(
--border-left
,
2px
));
width
:
calc
(
100%
+
var
(
--border-horizontal
,
4px
));
border-radius
:
0
0
var
(
--rounded-md
)
var
(
--rounded-md
);
transform
:
translateY
(
-
2
8px
);
transform
:
translateY
(
-
1
8px
);
}
.resize-line.left
{
top
:
calc
(
-1
*
var
(
--border-top
,
2px
));
left
:
-
12
px
;
left
:
-
7
px
;
height
:
calc
(
100%
+
var
(
--border-vertical
,
4px
));
border-radius
:
var
(
--rounded-md
)
0
0
var
(
--rounded-md
);
transform
:
translateX
(
2
8px
);
transform
:
translateX
(
1
8px
);
}
.resize-line.right
{
top
:
calc
(
-1
*
var
(
--border-top
,
2px
));
right
:
-
12
px
;
right
:
-
7
px
;
height
:
calc
(
100%
+
var
(
--border-vertical
,
4px
));
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
,
...
...
@@ -149,14 +149,14 @@
* regardless of hover state
*/
.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
{
transform
:
translateX
(
2
8
px
);
transform
:
translateX
(
2
0
px
);
}
.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
{
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'
import
{
useResize
,
type
ResizeDirection
}
from
'./resize-provider'
import
'./resize-handle.css'
const
STORAGE_KEY_DIMENSIONS
=
'nextjs-devtools-dimensions'
export
const
ResizeHandle
=
({
direction
}:
{
direction
:
ResizeDirection
})
=>
{
export
const
ResizeHandle
=
({
direction
,
position
,
}:
{
direction
:
ResizeDirection
position
:
Corners
})
=>
{
const
{
resizeRef
,
minWidth
,
minHeight
,
devToolsPosition
,
storageKey
,
draggingDirection
,
setDraggingDirection
,
}
=
useResize
()
...
...
@@ -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)
// 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)
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
// sense is the corner fully exposed (the opposing corner)
const
isCorner
=
direction
.
includes
(
'-'
)
if
(
isCorner
)
{
const
opposite
=
getOppositeCorner
(
devToolsP
osition
)
const
opposite
=
getOppositeCorner
(
p
osition
)
return
direction
===
opposite
}
...
...
@@ -123,10 +127,7 @@ export const ResizeHandle = ({ direction }: { direction: ResizeDirection }) => {
// invariant ref exists
const
{
width
,
height
}
=
resizeRef
.
current
!
.
getBoundingClientRect
()
localStorage
.
setItem
(
STORAGE_KEY_DIMENSIONS
,
JSON
.
stringify
({
width
,
height
})
)
localStorage
.
setItem
(
storageKey
,
JSON
.
stringify
({
width
,
height
}))
}
document
.
addEventListener
(
'mousemove'
,
handleMouseMove
)
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 {
resizeRef
:
RefObject
<
HTMLElement
|
null
>
minWidth
:
number
minHeight
:
number
devToolsPosition
:
Corners
draggingDirection
:
ResizeDirection
|
null
setDraggingDirection
:
(
direction
:
ResizeDirection
|
null
)
=>
void
storageKey
:
string
}
const
ResizeContext
=
createContext
<
ResizeContextValue
>
(
null
!
)
...
...
@@ -44,8 +44,8 @@ const constrainDimensions = (params: {
}
}
const
parseResizeLocalStorage
=
()
=>
{
const
savedDimensions
=
localStorage
.
getItem
(
STORAGE_KEY_DIMENSIONS
)
const
parseResizeLocalStorage
=
(
key
:
string
)
=>
{
const
savedDimensions
=
localStorage
.
getItem
(
key
)
if
(
!
savedDimensions
)
return
null
try
{
const
parsed
=
JSON
.
parse
(
savedDimensions
)
...
...
@@ -59,7 +59,7 @@ const parseResizeLocalStorage = () => {
}
return
null
}
catch
(
e
)
{
localStorage
.
removeItem
(
STORAGE_KEY_DIMENSIONS
)
localStorage
.
removeItem
(
key
)
return
null
}
}
...
...
@@ -70,6 +70,7 @@ interface ResizeProviderProps {
minWidth
?:
number
minHeight
?:
number
devToolsPosition
:
Corners
storageKey
?:
string
}
children
:
React
.
ReactNode
}
...
...
@@ -80,6 +81,8 @@ export const ResizeProvider = ({ value, children }: ResizeProviderProps) => {
const
[
draggingDirection
,
setDraggingDirection
]
=
useState
<
ResizeDirection
|
null
>
(
null
)
const
storageKey
=
value
.
storageKey
??
STORAGE_KEY_DIMENSIONS
useLayoutEffect
(()
=>
{
const
applyConstrainedDimensions
=
()
=>
{
if
(
!
value
.
resizeRef
.
current
)
return
...
...
@@ -91,7 +94,7 @@ export const ResizeProvider = ({ value, children }: ResizeProviderProps) => {
// 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
// what we're doing here, just dumber
const
dim
=
parseResizeLocalStorage
()
const
dim
=
parseResizeLocalStorage
(
storageKey
)
if
(
!
dim
)
{
return
}
...
...
@@ -110,7 +113,7 @@ export const ResizeProvider = ({ value, children }: ResizeProviderProps) => {
window
.
addEventListener
(
'resize'
,
applyConstrainedDimensions
)
return
()
=>
window
.
removeEventListener
(
'resize'
,
applyConstrainedDimensions
)
},
[
value
.
resizeRef
,
minWidth
,
minHeight
])
},
[
value
.
resizeRef
,
minWidth
,
minHeight
,
storageKey
])
return
(
<
ResizeContext
.
Provider
...
...
@@ -118,9 +121,9 @@ export const ResizeProvider = ({ value, children }: ResizeProviderProps) => {
resizeRef
:
value
.
resizeRef
,
minWidth
,
minHeight
,
devToolsPosition
:
value
.
devToolsPosition
,
draggingDirection
,
setDraggingDirection
,
storageKey
,
}
}
>
{
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
{
Dev
ToolsIndicator
}
from
'./dev-tools-indicato
r'
import
{
Dev
OverlayStoryWrapper
}
from
'../../../storybook/DevOverlayStoryWrappe
r'
import
{
withShadowPortal
}
from
'../../../storybook/with-shadow-portal'
import
type
{
VersionInfo
}
from
'../../../../../server/dev/parse-version-info'
import
type
{
OverlayState
}
from
'../../../shared'
const
meta
:
Meta
<
typeof
Dev
ToolsIndicato
r
>
=
{
component
:
Dev
ToolsIndicato
r
,
const
meta
:
Meta
<
typeof
Dev
OverlayStoryWrappe
r
>
=
{
component
:
Dev
OverlayStoryWrappe
r
,
parameters
:
{
layout
:
'centered'
,
},
...
...
@@ -36,7 +36,7 @@ const meta: Meta<typeof DevToolsIndicator> = {
}
export
default
meta
type
Story
=
StoryObj
<
typeof
Dev
ToolsIndicato
r
>
type
Story
=
StoryObj
<
typeof
Dev
OverlayStoryWrappe
r
>
// Mock version info for stories
const
mockVersionInfo
:
VersionInfo
=
{
...
...
@@ -68,36 +68,31 @@ const state: OverlayState = {
}
export
const
StaticRoute
:
Story
=
{
args
:
{
errorCount
:
0
,
state
,
dispatch
:
()
=>
{},
},
render
:
()
=>
(
<
DevOverlayStoryWrapper
initialState=
{
state
}
runtimeErrors=
{
[]
}
/>
),
}
export
const
DynamicRoute
:
Story
=
{
args
:
{
errorCount
:
0
,
state
:
{
...
state
,
staticIndicator
:
false
,
},
dispatch
:
()
=>
{},
},
render
:
()
=>
(
<
DevOverlayStoryWrapper
initialState=
{
{
...
state
,
staticIndicator
:
false
}
}
runtimeErrors=
{
[]
}
/>
),
}
export
const
SingleError
:
Story
=
{
args
:
{
errorCount
:
1
,
state
,
dispatch
:
()
=>
{},
},
render
:
()
=>
(
<
DevOverlayStoryWrapper
initialState=
{
state
}
runtimeErrors=
{
[{}
as
any
]
}
/>
),
}
export
const
MultipleErrors
:
Story
=
{
args
:
{
errorCount
:
3
,
state
,
dispatch
:
()
=>
{},
},
render
:
()
=>
(
<
DevOverlayStoryWrapper
initialState=
{
state
}
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({
//////////////////////////////////////////////////////////////////////////////////////
interface
C
{
closeMenu
:
()
=>
void
closeMenu
?
:
()
=>
void
selectedIndex
:
number
setSelectedIndex
:
Dispatch
<
SetStateAction
<
number
>>
}
const
Context
=
createContext
({}
as
C
)
export
const
Menu
Context
=
createContext
({}
as
C
)
const
OVERLAYS
=
{
Root
:
'root'
,
...
...
@@ -397,7 +397,7 @@ function DevToolsPopover({
data
-
rendered=
{
menuRendered
}
style=
{
popover
}
>
<
Context
.
Provider
<
Menu
Context
.
Provider
value=
{
{
closeMenu
,
selectedIndex
,
...
...
@@ -457,7 +457,7 @@ function DevToolsPopover({
/>
)
:
null
}
</
div
>
</
Context
.
Provider
>
</
Menu
Context
.
Provider
>
</
div
>
)
}
</
Toast
>
...
...
@@ -483,7 +483,7 @@ function ChevronRight() {
)
}
function
MenuItem
({
export
function
MenuItem
({
index
,
label
,
value
,
...
...
@@ -500,13 +500,13 @@ function MenuItem({
})
{
const
isInteractive
=
typeof
onClick
===
'function'
||
typeof
href
===
'string'
const
{
closeMenu
,
selectedIndex
,
setSelectedIndex
}
=
useContext
(
Context
)
const
{
closeMenu
,
selectedIndex
,
setSelectedIndex
}
=
useContext
(
Menu
Context
)
const
selected
=
selectedIndex
===
index
function
click
()
{
if
(
isInteractive
)
{
onClick
?.()
closeMenu
()
closeMenu
?.
()
if
(
href
)
{
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
{
MENU_DURATION_MS
,
useClickOutside
,
useFocusTrap
}
from
'../utils'
import
{
useDelayedRender
}
from
'../../../../hooks/use-delayed-render'
import
{
css
}
from
'../../../../utils/css'
export
interface
DevToolsInfoPropsCore
{
isOpen
:
boolean
...
...
@@ -84,7 +85,7 @@ export function DevToolsInfo({
)
}
export
const
DEV_TOOLS_INFO_STYLES
=
`
export
const
DEV_TOOLS_INFO_STYLES
=
css
`
[data-info-popover] {
-webkit-font-smoothing: antialiased;
display: flex;
...
...
@@ -135,7 +136,7 @@ export const DEV_TOOLS_INFO_STYLES = `
.dev-tools-info-close-button {
all: unset;
width: 20px;
height: 20px;
height: 20px;
display: flex;
align-items: center;
justify-content: center;
...
...
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
{
DevToolsInfoPropsCore
}
from
'./dev-tools-info'
import
type
{
ComponentProps
,
HTMLProps
,
RefObject
}
from
'react'
import
{
DevToolsInfo
}
from
'./dev-tools-info'
function
StaticRouteContent
({
routerType
}:
{
routerType
:
'pages'
|
'app'
})
{
function
StaticRouteContent
({
routerType
,
...
props
}:
{
routerType
:
'pages'
|
'app'
}
&
ComponentProps
<
'div'
>
)
{
return
(
<
article
className=
"dev-tools-info-article"
>
<
article
className=
"dev-tools-info-article"
{
...
props
}
>
<
p
className=
"dev-tools-info-paragraph"
>
The path
{
' '
}
<
code
className=
"dev-tools-info-code"
>
{
window
.
location
.
pathname
}
</
code
>
{
' '
}
...
...
@@ -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
(
<
article
className=
"dev-tools-info-article"
>
<
article
className=
"dev-tools-info-article"
{
...
props
}
>
<
p
className=
"dev-tools-info-paragraph"
>
The path
{
' '
}
<
code
className=
"dev-tools-info-code"
>
{
window
.
location
.
pathname
}
</
code
>
{
' '
}
...
...
@@ -110,32 +115,50 @@ const learnMoreLink = {
},
}
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
({
routeType
,
isOpen
,
close
,
routerType
,
routeType
,
triggerRef
,
...
props
}:
{
routeType
:
'Static'
|
'Dynamic'
isOpen
:
boolean
close
:
()
=>
void
routerType
:
'pages'
|
'app'
}
&
DevToolsInfoPropsCore
&
HTMLProps
<
HTMLDivElement
>
)
{
routeType
:
'Static'
|
'Dynamic'
triggerRef
:
RefObject
<
HTMLButtonElement
|
null
>
}
&
HTMLProps
<
HTMLDivElement
>
)
{
const
isStaticRoute
=
routeType
===
'Static'
const
learnMore
=
isStaticRoute
?
learnMoreLink
[
routerType
].
static
:
learnMoreLink
[
routerType
].
dynamic
return
(
<
DevToolsInfo
title=
{
`${routeType} Route`
}
learnMoreLink=
{
learnMore
}
close=
{
close
}
isOpen=
{
isOpen
}
triggerRef=
{
triggerRef
}
{
...
props
}
>
{
isStaticRoute
?
(
<
StaticRouteContent
routerType=
{
routerType
}
/>
)
:
(
<
DynamicRouteContent
routerType=
{
routerType
}
/>
)
}
<
RouteInfoBody
routerType=
{
routerType
}
isStaticRoute=
{
isStaticRoute
}
/>
</
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'
import
{
CopyButton
}
from
'../../../copy-button'
import
type
{
HTMLProps
}
from
'react'
export
function
TurbopackInfo
(
props
:
DevToolsInfoPropsCore
&
HTMLProps
<
HTMLDivElement
>
)
{
export
function
TurbopackInfoBody
(
props
:
React
.
ComponentProps
<
'div'
>
)
{
return
(
<
DevToolsInfo
title=
"Turbopack"
learnMoreLink=
"https://nextjs.org/docs/app/api-reference/turbopack"
{
...
props
}
>
<
article
className=
"dev-tools-info-article"
>
<>
<
article
className=
"dev-tools-info-article"
{
...
props
}
>
<
p
className=
"dev-tools-info-paragraph"
>
Turbopack is an incremental bundler optimized for JavaScript and
TypeScript, written in Rust, and built into Next.js. Turbopack can be
...
...
@@ -96,6 +90,20 @@ export function TurbopackInfo(
</
pre
>
</
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
>
)
}
...
...
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 {
import
{
ShortcutRecorder
}
from
'./shortcut-recorder'
export
function
UserPreferences
({
setPosition
,
position
,
hide
,
scale
,
setScale
,
hideShortcut
,
setHideShortcut
,
setScale
,
scale
,
position
,
setPosition
,
...
props
}:
{
hide
:
()
=>
void
hideShortcut
:
string
|
null
setHideShortcut
:
(
value
:
string
|
null
)
=>
void
setPosition
:
(
position
:
DevToolsIndicatorPosition
)
=>
void
position
:
DevToolsIndicatorPosition
scale
:
DevToolsScale
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
hideShortcut
:
string
|
null
setHideShortcut
:
(
value
:
string
|
null
)
=>
void
}
&
DevToolsInfoPropsCore
&
Omit
<
HTMLProps
<
HTMLDivElement
>
,
'size'
>
)
{
// derive initial theme from system preference
setPosition
:
(
position
:
DevToolsIndicatorPosition
)
=>
void
position
:
DevToolsIndicatorPosition
scale
:
DevToolsScale
setScale
:
(
value
:
DevToolsScale
)
=>
void
})
{
const
[
theme
,
setTheme
]
=
useState
(
getInitialTheme
())
const
handleThemeChange
=
(
e
:
React
.
ChangeEvent
<
HTMLSelectElement
>
)
=>
{
...
...
@@ -90,7 +121,7 @@ export function UserPreferences({
}
return
(
<
DevToolsInfo
title=
"Preferences"
{
...
props
}
>
<>
<
h2
className=
"dev-tools-info-section-title"
>
General
</
h2
>
<
div
className=
"preferences-container"
>
<
div
className=
"preference-section"
>
...
...
@@ -257,7 +288,7 @@ export function UserPreferences({
</
div
>
</
div
>
)
:
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
{
useCallback
,
useLayoutEffect
,
useRef
}
from
'react'
import
{
useDragContext
}
from
'./drag-context'
interface
Point
{
x
:
number
...
...
@@ -19,6 +20,7 @@ export function Draggable({
onDragStart
,
dragHandleSelector
,
disableDrag
=
false
,
avoidZone
,
...
props
}:
{
children
:
React
.
ReactElement
...
...
@@ -28,9 +30,16 @@ export function Draggable({
onDragStart
?:
()
=>
void
dragHandleSelector
?:
string
disableDrag
?:
boolean
style
?:
React
.
CSSProperties
avoidZone
?:
{
square
:
number
corner
:
Corners
padding
:
number
}
})
{
const
{
ref
,
animate
,
...
drag
}
=
useDrag
({
disabled
:
disableDrag
,
handles
:
useDragContext
()?.
handles
,
threshold
:
5
,
onDragStart
,
onDragEnd
,
...
...
@@ -56,7 +65,6 @@ export function Draggable({
}
function
onAnimationEnd
({
corner
}:
Corner
)
{
// Unset drag translation
setTimeout
(()
=>
{
ref
.
current
?.
style
.
removeProperty
(
'translate'
)
setCurrentCorner
(
corner
)
...
...
@@ -74,7 +82,7 @@ export function Draggable({
const
min
=
Math
.
min
(...
distances
.
map
((
d
)
=>
d
.
distance
))
const
nearest
=
distances
.
find
((
d
)
=>
d
.
distance
===
min
)
if
(
!
nearest
)
{
//
Safety fallback
//
this should be guarded by an invariant, shouldn't ever happen
return
{
corner
:
currentCorner
,
translation
:
allCorners
[
currentCorner
]
}
}
return
{
...
...
@@ -94,49 +102,53 @@ export function Draggable({
const
isRight
=
corner
.
includes
(
'right'
)
const
isBottom
=
corner
.
includes
(
'bottom'
)
return
{
x
:
isRight
?
window
.
innerWidth
-
scrollbarWidth
-
offset
-
triggerWidth
:
0
,
y
:
isBottom
?
window
.
innerHeight
-
offset
-
triggerHeight
:
0
,
// Base positions flush against the chosen corner
let
x
=
isRight
?
window
.
innerWidth
-
scrollbarWidth
-
offset
-
triggerWidth
:
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
)
// 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
{
'top-left'
:
{
x
:
0
-
basePosition
.
x
,
y
:
0
-
basePosition
.
y
,
},
'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
,
},
'top-left'
:
rel
(
getAbsolutePosition
(
'top-left'
)),
'top-right'
:
rel
(
getAbsolutePosition
(
'top-right'
)),
'bottom-left'
:
rel
(
getAbsolutePosition
(
'bottom-left'
)),
'bottom-right'
:
rel
(
getAbsolutePosition
(
'bottom-right'
)),
}
}
return
(
<
div
{
...
props
}
ref=
{
ref
}
{
...
drag
}
style=
{
{
touchAction
:
'none'
}
}
>
<
div
{
...
props
}
ref=
{
ref
}
{
...
drag
}
style=
{
{
touchAction
:
'none'
,
...
props
.
style
}
}
>
{
children
}
</
div
>
)
...
...
@@ -150,6 +162,7 @@ interface UseDragOptions {
onAnimationEnd
?:
(
corner
:
Corner
)
=>
void
threshold
:
number
// Minimum movement before drag starts
dragHandleSelector
?:
string
handles
?:
Set
<
HTMLElement
>
}
interface
Velocity
{
...
...
@@ -234,18 +247,23 @@ export function useDrag(options: UseDragOptions) {
}
function
isValidDragHandle
(
target
:
EventTarget
|
null
):
boolean
{
if
(
!
options
.
dragHandleSelector
||
!
ref
.
current
||
!
target
)
{
return
true
// If no selector provided, entire element is draggable
}
if
(
!
target
||
!
ref
.
current
)
return
true
const
element
=
target
as
Element
if
(
!
element
.
matches
)
{
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
}
// Check if the target element directly matches the drag handle selector
// This excludes children elements, only allowing drag from the exact element
return
element
.
matches
(
options
.
dragHandleSelector
)
if
(
options
.
dragHandleSelector
)
{
const
element
=
target
as
Element
return
element
.
closest
(
options
.
dragHandleSelector
)
!==
null
}
return
true
}
function
onPointerDown
(
e
:
React
.
PointerEvent
)
{
...
...
@@ -328,6 +346,13 @@ export function useDrag(options: UseDragOptions) {
options
.
onDragEnd
?.(
translation
.
current
,
velocity
)
}
if
(
options
.
disabled
)
{
return
{
ref
,
animate
,
}
}
return
{
ref
,
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(
return
}
const
cushion
=
10
if
(
!
(
rootRef
.
current
?.
getBoundingClientRect
()
?
event
.
clientX
>=
rootRef
.
current
.
getBoundingClientRect
()
!
.
left
&&
event
.
clientX
<=
rootRef
.
current
.
getBoundingClientRect
()
!
.
right
&&
event
.
clientY
>=
rootRef
.
current
.
getBoundingClientRect
()
!
.
top
&&
event
.
clientY
<=
rootRef
.
current
.
getBoundingClientRect
()
!
.
bottom
?
event
.
clientX
>=
rootRef
.
current
.
getBoundingClientRect
()
!
.
left
-
cushion
&&
event
.
clientX
<=
rootRef
.
current
.
getBoundingClientRect
()
!
.
right
+
cushion
&&
event
.
clientY
>=
rootRef
.
current
.
getBoundingClientRect
()
!
.
top
-
cushion
&&
event
.
clientY
<=
rootRef
.
current
.
getBoundingClientRect
()
!
.
bottom
+
cushion
:
false
)
&&
!
(
triggerRef
.
current
?.
getBoundingClientRect
()
?
event
.
clientX
>=
triggerRef
.
current
.
getBoundingClientRect
()
!
.
left
&&
?
event
.
clientX
>=
triggerRef
.
current
.
getBoundingClientRect
()
!
.
left
-
cushion
&&
event
.
clientX
<=
triggerRef
.
current
.
getBoundingClientRect
()
!
.
right
&&
event
.
clientY
>=
triggerRef
.
current
.
getBoundingClientRect
()
!
.
top
&&
event
.
clientY
<=
triggerRef
.
current
.
getBoundingClientRect
()
!
.
bottom
triggerRef
.
current
.
getBoundingClientRect
()
!
.
right
+
cushion
&&
event
.
clientY
>=
triggerRef
.
current
.
getBoundingClientRect
()
!
.
top
-
cushion
&&
event
.
clientY
<=
triggerRef
.
current
.
getBoundingClientRect
()
!
.
bottom
+
cushion
:
false
)
)
{
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'
export
function
ErrorOverlayOverlay
({
children
,
...
props
}:
OverlayProps
)
{
return
<
Overlay
{
...
props
}
>
{
children
}
</
Overlay
>
}
export
const
OVERLAY_STYLES
=
`
export
const
OVERLAY_STYLES
=
css
`
[data-nextjs-dialog-overlay] {
padding: initial;
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] {
position: fixed;
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> = {
export
default
meta
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
=
{
args
:
{
getSquashedHydrationErrorDetails
:
()
=>
null
,
...
...
packages/next/src/next-devtools/dev-overlay/dev-overlay.stories.tsx
View file @
30743443
...
...
@@ -10,6 +10,8 @@ import {
storybookDefaultOverlayState
,
useStorybookOverlayReducer
,
}
from
'./storybook/use-overlay-reducer'
import
{
DevOverlayContext
}
from
'../dev-overlay.browser'
import
{
getSquashedHydrationErrorDetails
}
from
'../userspace/pages/hydration-error-state'
const
meta
:
Meta
<
typeof
DevOverlay
>
=
{
component
:
DevOverlay
,
...
...
@@ -39,14 +41,20 @@ function getNoSquashedHydrationErrorDetails() {
const
initialState
:
OverlayState
=
{
...
storybookDefaultOverlayState
,
errors
,
errors
:
errors
,
}
export
const
Default
:
Story
=
{
render
:
function
DevOverlayStory
()
{
const
[
state
,
dispatch
]
=
useStorybookOverlayReducer
(
initialState
)
return
(
<>
<
div
style=
{
{
height
:
'100vh'
,
backgroundColor
:
'black'
,
}
}
>
{
/* TODO: get lots of real hard examples so we have better debug */
}
<
img
src=
{
imgApp
}
style=
{
{
...
...
@@ -55,19 +63,26 @@ export const Default: Story = {
objectFit
:
'contain'
,
}
}
/>
<
DevOverlay
state=
{
state
}
dispatch=
{
dispatch
}
getSquashedHydrationErrorDetails=
{
// Testing like App Router where we no longer quash hydration errors
getNoSquashedHydrationErrorDetails
}
/>
</>
<
DevOverlayContext
value=
{
{
dispatch
,
getSquashedHydrationErrorDetails
:
getNoSquashedHydrationErrorDetails
,
state
,
}
}
>
<
DevOverlay
state=
{
state
}
dispatch=
{
dispatch
}
getSquashedHydrationErrorDetails=
{
getSquashedHydrationErrorDetails
}
/>
</
DevOverlayContext
>
</
div
>
)
},
}
// todo: fix story with "Context arg provider" wrapper
export
const
WithPanel
:
Story
=
{
beforeEach
:
()
=>
{
process
.
env
.
__NEXT_DEVTOOL_NEW_PANEL_UI
=
'true'
...
...
@@ -89,14 +104,20 @@ export const WithPanel: Story = {
objectFit
:
'contain'
,
}
}
/>
<
DevOverlay
state=
{
state
}
dispatch=
{
dispatch
}
getSquashedHydrationErrorDetails=
{
// Testing like App Router where we no longer quash hydration errors
getNoSquashedHydrationErrorDetails
}
/>
<
DevOverlayContext
value=
{
{
dispatch
,
getSquashedHydrationErrorDetails
:
getNoSquashedHydrationErrorDetails
,
state
,
}
}
>
<
DevOverlay
dispatch=
{
dispatch
}
getSquashedHydrationErrorDetails=
{
getSquashedHydrationErrorDetails
}
state=
{
state
}
/>
</
DevOverlayContext
>
</>
)
},
...
...
packages/next/src/next-devtools/dev-overlay/dev-overlay.tsx
View file @
30743443
...
...
@@ -5,7 +5,7 @@ import {
type
OverlayState
,
}
from
'./shared'
import
{
useState
}
from
'react'
import
{
createContext
,
useContext
,
useRef
,
useState
}
from
'react'
import
{
ShadowPortal
}
from
'./components/shadow-portal'
import
{
Base
}
from
'./styles/base'
...
...
@@ -18,8 +18,17 @@ import { RenderError } from './container/runtime-error/render-error'
import
{
DarkTheme
}
from
'./styles/dark-theme'
import
{
useDevToolsScale
}
from
'./components/errors/dev-tools-indicator/dev-tools-info/preferences'
import
type
{
HydrationErrorState
}
from
'../shared/hydration-error'
import
{
DevToolsIndicator
as
DevToolsIndicatorNew
}
from
'./components/devtools-indicator/devtools-indicator'
import
{
DevToolsPanel
}
from
'./components/devtools-panel/devtools-panel'
import
type
{
ReadyRuntimeError
}
from
'./utils/get-error-by-type'
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
({
state
,
...
...
@@ -32,6 +41,8 @@ export function DevOverlay({
})
{
const
[
scale
,
setScale
]
=
useDevToolsScale
()
const
[
isPrevBuildError
,
setIsPrevBuildError
]
=
useState
(
false
)
const
[
panel
,
setPanel
]
=
useState
<
null
|
PanelStateKind
>
(
null
)
const
triggerRef
=
useRef
<
HTMLButtonElement
>
(
null
)
const
isBuildError
=
state
.
buildError
!==
null
...
...
@@ -63,50 +74,54 @@ export function DevOverlay({
return
(
<>
{
state
.
showIndicator
&&
(
process
.
env
.
__NEXT_DEVTOOL_NEW_PANEL_UI
?
(
<>
<
DevToolsIndicatorNew
state=
{
state
}
dispatch=
{
dispatch
}
errorCount=
{
totalErrorCount
}
isBuildError=
{
isBuildError
}
/>
{
(
state
.
isDevToolsPanelOpen
||
state
.
isErrorOverlayOpen
)
&&
(
<
DevToolsPanel
process
.
env
.
__NEXT_DEVTOOL_NEW_PANEL_UI
?
(
<>
<
RenderErrorContext
value=
{
{
runtimeErrors
,
totalErrorCount
}
}
>
<
PanelRouterContext
value=
{
{
panel
,
setPanel
,
triggerRef
,
}
}
>
<
ErrorOverlay
state=
{
state
}
dispatch=
{
dispatch
}
issueCount=
{
totalErrorCount
}
runtimeErrors=
{
runtimeErrors
}
getSquashedHydrationErrorDetails=
{
getSquashedHydrationErrorDetails
}
runtimeErrors=
{
runtimeErrors
}
errorCount=
{
totalErrorCount
}
/>
)
}
</>
)
:
(
<>
<
DevToolsIndicator
scale=
{
scale
}
setScale=
{
setScale
}
state=
{
state
}
dispatch=
{
dispatch
}
errorCount=
{
totalErrorCount
}
isBuildError=
{
isBuildError
}
/>
<
PanelRouter
/>
<
DevToolsIndicatorNew
/>
</
PanelRouterContext
>
</
RenderErrorContext
>
</>
)
:
(
<>
<
DevToolsIndicator
scale=
{
scale
}
setScale=
{
setScale
}
state=
{
state
}
dispatch=
{
dispatch
}
errorCount=
{
totalErrorCount
}
isBuildError=
{
isBuildError
}
/>
<
ErrorOverlay
state=
{
state
}
dispatch=
{
dispatch
}
getSquashedHydrationErrorDetails=
{
getSquashedHydrationErrorDetails
}
runtimeErrors=
{
runtimeErrors
}
errorCount=
{
totalErrorCount
}
/>
</>
)
)
}
<
ErrorOverlay
state=
{
state
}
dispatch=
{
dispatch
}
getSquashedHydrationErrorDetails=
{
getSquashedHydrationErrorDetails
}
runtimeErrors=
{
runtimeErrors
}
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 {
isErrorOverlayOpen
:
boolean
isDevToolsPanelOpen
:
boolean
devToolsPosition
:
Corners
devToolsPanelPosition
:
Corners
scale
:
number
page
:
string
}
...
...
@@ -64,6 +65,7 @@ export const ACTION_UNHANDLED_ERROR = 'unhandled-error'
export
const
ACTION_UNHANDLED_REJECTION
=
'unhandled-rejection'
export
const
ACTION_DEBUG_INFO
=
'debug-info'
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_CLOSE
=
'error-overlay-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_POSITION
=
'devtools-position'
export
const
ACTION_DEVTOOLS_PANEL_POSITION
=
'devtools-panel-position'
export
const
ACTION_DEVTOOLS_SCALE
=
'devtools-scale'
export
const
ACTION_RESTART_SERVER_BUTTON
=
'restart-server-button'
export
const
STORAGE_KEY_THEME
=
'__nextjs-dev-tools-theme'
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_ACTIVE_TAB
=
'__nextjs-devtools-active-tab'
...
...
@@ -133,6 +137,11 @@ interface DevIndicatorAction {
devIndicator
:
DevIndicatorServerState
}
interface
DevIndicatorSetAction
{
type
:
typeof
ACTION_DEV_INDICATOR_SET
disabled
:
boolean
}
export
interface
ErrorOverlayOpenAction
{
type
:
typeof
ACTION_ERROR_OVERLAY_OPEN
}
...
...
@@ -172,6 +181,11 @@ export interface DevToolsIndicatorPositionAction {
devToolsPosition
:
Corners
}
export
interface
DevToolsPanelPositionAction
{
type
:
typeof
ACTION_DEVTOOLS_PANEL_POSITION
devToolsPanelPosition
:
Corners
}
export
interface
DevToolsScaleAction
{
type
:
typeof
ACTION_DEVTOOLS_SCALE
scale
:
number
...
...
@@ -209,9 +223,11 @@ export type DispatcherEvent =
|
DevToolsPanelCloseAction
|
DevToolsPanelToggleAction
|
DevToolsIndicatorPositionAction
|
DevToolsPanelPositionAction
|
DevToolsScaleAction
|
DevToolUpdateRouteStateAction
|
RestartServerButtonAction
|
DevIndicatorSetAction
const
REACT_ERROR_STACK_BOTTOM_FRAME_REGEX
=
// 1st group: new frame + v8
...
...
@@ -231,6 +247,42 @@ function getStackIgnoringStrictMode(stack: string | undefined) {
const
shouldDisableDevIndicator
=
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
<
OverlayState
,
'isErrorOverlayOpen'
|
'routerType'
...
...
@@ -254,7 +306,8 @@ export const INITIAL_OVERLAY_STATE: Omit<
debugInfo
:
{
devtoolsFrontendUrl
:
undefined
},
isDevToolsPanelOpen
:
false
,
showRestartServerButton
:
false
,
devToolsPosition
:
'bottom-left'
,
devToolsPosition
:
getStoredPosition
(),
devToolsPanelPosition
:
getStoredPanelPosition
()
??
'bottom-left'
,
scale
:
NEXT_DEV_TOOLS_SCALE
.
Medium
,
page
:
''
,
}
...
...
@@ -390,6 +443,9 @@ export function useErrorOverlayReducer(
case
ACTION_VERSION_INFO
:
{
return
{
...
state
,
versionInfo
:
action
.
versionInfo
}
}
case
ACTION_DEV_INDICATOR_SET
:
{
return
{
...
state
,
disableDevIndicator
:
action
.
disabled
}
}
case
ACTION_DEV_INDICATOR
:
{
return
{
...
state
,
...
...
@@ -431,6 +487,12 @@ export function useErrorOverlayReducer(
case
ACTION_DEVTOOLS_POSITION
:
{
return
{
...
state
,
devToolsPosition
:
action
.
devToolsPosition
}
}
case
ACTION_DEVTOOLS_PANEL_POSITION
:
{
return
{
...
state
,
devToolsPanelPosition
:
action
.
devToolsPanelPosition
,
}
}
case
ACTION_DEVTOOLS_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'
import
{
useReducer
}
from
'react'
import
{
ACTION_DEVTOOLS_POSITION
,
ACTION_DEVTOOLS_PANEL_POSITION
,
ACTION_DEVTOOLS_PANEL_CLOSE
,
ACTION_DEVTOOLS_PANEL_TOGGLE
,
ACTION_ERROR_OVERLAY_CLOSE
,
...
...
@@ -16,7 +17,7 @@ import {
export
const
storybookDefaultOverlayState
:
OverlayState
=
{
...
INITIAL_OVERLAY_STATE
,
routerType
:
'app'
,
isErrorOverlayOpen
:
tru
e
,
isErrorOverlayOpen
:
fals
e
,
showIndicator
:
true
,
versionInfo
:
{
installed
:
'15.4.0'
,
...
...
@@ -49,6 +50,13 @@ export function useStorybookOverlayReducer(initialState?: OverlayState) {
case
ACTION_DEVTOOLS_POSITION
:
{
return
{
...
state
,
devToolsPosition
:
action
.
devToolsPosition
}
}
// todo remove
case
ACTION_DEVTOOLS_PANEL_POSITION
:
{
return
{
...
state
,
devToolsPanelPosition
:
action
.
devToolsPanelPosition
,
}
}
case
ACTION_DEVTOOLS_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