11import { ReactScanInternals } from '../../index' ;
2- import { createElement } from './utils' ;
2+ import { createElement , throttle } from './utils' ;
33import { MONO_FONT } from './outline' ;
44import { INSPECT_TOGGLE_ID } from './inspect-element/inspect-state-machine' ;
55import {
@@ -8,6 +8,21 @@ import {
88} from './inspect-element/utils' ;
99
1010let isDragging = false ;
11+ let isResizing = false ;
12+ let initialWidth = 0 ;
13+ let initialMouseX = 0 ;
14+
15+ export const persistSizeToLocalStorage = throttle ( ( width : number ) => {
16+ localStorage . setItem ( 'react-scan-toolbar-width' , String ( width ) ) ;
17+ } , 100 ) ;
18+
19+
20+ export const restoreSizeFromLocalStorage = ( el : HTMLDivElement ) => {
21+ const width = localStorage . getItem ( 'react-scan-toolbar-width' ) ;
22+ el . style . width = `${ width ?? 360 } px` ;
23+
24+ } ;
25+
1126export const createToolbar = ( ) => {
1227 if ( typeof window === 'undefined' ) {
1328 return ;
@@ -52,6 +67,7 @@ export const createToolbar = () => {
5267 overflow: hidden;
5368 width: fit-content;
5469 min-width: min-content;
70+ position: relative;
5571 ">
5672 <div style="display: flex; align-items: center; height: 36px; width: 100%;">
5773 <button id="${ INSPECT_TOGGLE_ID } " style="
@@ -136,13 +152,23 @@ export const createToolbar = () => {
136152 pointer-events: auto;
137153 background: #000;
138154 border-top: 1px solid rgba(255, 255, 255, 0.1);
155+ min-width: 100%;
139156 width: 360px;
140157 overflow: auto;
141158 max-height: 0;
142159 transition: max-height 500ms cubic-bezier(0, 0.95, 0.1, 1);
143160 ">
144161 <!-- Props content will be injected here -->
145162 </div>
163+ <div id="react-scan-resize-handle" style="
164+ position: absolute;
165+ left: 0;
166+ top: 0;
167+ bottom: 0;
168+ width: 4px;
169+ cursor: ew-resize;
170+ dis
171+ "></div>
146172 </div>
147173 </div>
148174` ) as HTMLDivElement ;
@@ -153,10 +179,12 @@ export const createToolbar = () => {
153179 font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
154180 }
155181
182+
156183 .react-scan-inspector {
157184 font-size: 13px;
158185 width: 360px;
159186 color: #fff;
187+ width: 100%;
160188 }
161189
162190 .react-scan-header {
@@ -388,6 +416,11 @@ export const createToolbar = () => {
388416 const toolbarContent = toolbar . querySelector < HTMLElement > (
389417 '#react-scan-toolbar-content' ,
390418 ) ! ;
419+ const resizeHandle = toolbar . querySelector < HTMLElement > (
420+ '#react-scan-resize-handle' ,
421+ ) ! ;
422+
423+
391424
392425 let isActive = ! ReactScanInternals . isPaused ;
393426
@@ -408,7 +441,8 @@ export const createToolbar = () => {
408441 if (
409442 event . target === inspectBtn ||
410443 event . target === powerBtn ||
411- event . target === parentFocusBtn
444+ event . target === parentFocusBtn ||
445+ event . target === resizeHandle
412446 )
413447 return ;
414448
@@ -424,21 +458,38 @@ export const createToolbar = () => {
424458 event . preventDefault ( ) ;
425459 } ) ;
426460
461+ resizeHandle . addEventListener ( 'mousedown' , ( e ) => {
462+ isResizing = true ;
463+ initialWidth = propContainer . offsetWidth ;
464+ initialMouseX = e . clientX ;
465+ e . preventDefault ( ) ;
466+ } ) ;
467+
427468 document . addEventListener ( 'mousemove' , ( e ) => {
428- if ( ! isDragging ) return ;
469+ if ( isDragging ) {
470+ const x = e . clientX - initialX ;
471+ const y = e . clientY - initialY ;
429472
430- const x = e . clientX - initialX ;
431- const y = e . clientY - initialY ;
473+ currentX = x ;
474+ currentY = y ;
475+ updateToolbarPosition ( x , y ) ;
476+ }
432477
433- currentX = x ;
434- currentY = y ;
435- updateToolbarPosition ( x , y ) ;
478+ if ( isResizing ) {
479+ const width = initialWidth - ( e . clientX - initialMouseX ) ;
480+ propContainer . style . width = `${ Math . max ( 360 , width ) } px` ;
481+ persistSizeToLocalStorage ( width ) ;
482+ }
436483 } ) ;
437484
438485 document . addEventListener ( 'mouseup' , ( ) => {
439- if ( ! isDragging ) return ;
440- isDragging = false ;
441- toolbar . style . transition = '' ;
486+ if ( isDragging ) {
487+ isDragging = false ;
488+ toolbar . style . transition = '' ;
489+ }
490+ if ( isResizing ) {
491+ isResizing = false ;
492+ }
442493 } ) ;
443494
444495 const updateNavigationButtons = ( ) => {
@@ -486,6 +537,9 @@ export const createToolbar = () => {
486537 propContainer . style . maxHeight = '0' ;
487538 propContainer . style . width = 'fit-content' ;
488539 propContainer . innerHTML = '' ;
540+ resizeHandle . style . display = 'none' ;
541+ } else if ( focusActive ) {
542+ resizeHandle . style . display = 'block' ;
489543 }
490544
491545 updateNavigationButtons ( ) ;
0 commit comments