1- import { css , type ComponentContext } from "dreamland/core" ;
1+ import { createDelegate , css , type ComponentContext } from "dreamland/core" ;
22import { browser } from "../Browser" ;
33import { forceScreenshot , popTab , pushTab } from "../Browser" ;
44import { takeScreenshotGDM } from "../screenshot" ;
55
6+ let locks : Symbol [ ] = [ ] ;
7+ let setUnfocus = createDelegate < boolean > ( ) ;
8+ export function requestUnfocusFrames ( ) : [ ( ) => void , ( ) => void ] {
9+ let lock = Symbol ( ) ;
10+ return [
11+ ( ) => {
12+ setUnfocus ( true ) ;
13+ locks . push ( lock ) ;
14+ } ,
15+ ( ) => {
16+ locks = locks . filter ( ( l ) => l !== lock ) ;
17+ if ( locks . length === 0 ) {
18+ setUnfocus ( false ) ;
19+ }
20+ } ,
21+ ] ;
22+ }
23+
624export function Shell ( _ , cx : ComponentContext ) {
725 pushTab . listen ( ( tab ) => {
826 // paint the iframes
@@ -12,6 +30,9 @@ export function Shell(_, cx: ComponentContext) {
1230 let mouseMoveListen = ( e : MouseEvent ) => {
1331 tab . devtoolsWidth = window . innerWidth - e . clientX ;
1432 } ;
33+
34+ const [ lock , unlock ] = requestUnfocusFrames ( ) ;
35+
1536 cx . root . appendChild (
1637 < div
1738 class = "container"
@@ -20,10 +41,7 @@ export function Shell(_, cx: ComponentContext) {
2041 class :active = { use ( browser . activetab ) . map ( ( t ) => t === tab ) }
2142 class :showframe = { use ( tab . internalpage ) . map ( ( t ) => ! t ) }
2243 >
23- < div
24- class = "mainframecontainer"
25- class :unfocus = { use ( browser . unfocusframes ) }
26- >
44+ < div class = "mainframecontainer" >
2745 { use ( tab . internalpage ) }
2846 { tab . frame . frame }
2947 </ div >
@@ -34,21 +52,18 @@ export function Shell(_, cx: ComponentContext) {
3452 >
3553 < div
3654 on :mousedown = { ( e : MouseEvent ) => {
37- browser . unfocusframes = true ;
55+ lock ( ) ;
3856 document . body . style . cursor = "ew-resize" ;
3957 window . addEventListener ( "mousemove" , mouseMoveListen ) ;
4058 window . addEventListener ( "mouseup" , ( ) => {
41- browser . unfocusframes = false ;
59+ unlock ( ) ;
4260 window . removeEventListener ( "mousemove" , mouseMoveListen ) ;
4361 document . body . style . cursor = "" ;
4462 } ) ;
4563 } }
4664 class = "divider"
4765 > </ div >
48- < div
49- class = "devtoolsframecontainer"
50- class :unfocus = { use ( browser . unfocusframes ) }
51- >
66+ < div class = "devtoolsframecontainer" >
5267 { /*{tab.devtoolsFrame.frame}*/ }
5368 </ div >
5469 </ div >
@@ -73,6 +88,23 @@ export function Shell(_, cx: ComponentContext) {
7388 // tab.screenshot = await takeScreenshotSvg(container);
7489 }
7590 } ) ;
91+ setUnfocus . listen ( ( unfocus ) => {
92+ if ( unfocus ) {
93+ cx . root
94+ . querySelectorAll ( ".mainframecontainer, .devtoolsframecontainer" )
95+ . forEach ( ( el ) => {
96+ if ( ! ( el instanceof HTMLElement ) ) return ;
97+ el . style . pointerEvents = "none" ;
98+ } ) ;
99+ } else {
100+ cx . root
101+ . querySelectorAll ( ".mainframecontainer, .devtoolsframecontainer" )
102+ . forEach ( ( el ) => {
103+ if ( ! ( el instanceof HTMLElement ) ) return ;
104+ el . style . pointerEvents = "" ;
105+ } ) ;
106+ }
107+ } ) ;
76108
77109 return < div > </ div > ;
78110}
@@ -84,9 +116,6 @@ Shell.style = css`
84116 width : 100% ;
85117 position : relative;
86118 }
87- .unfocus {
88- pointer-events : none;
89- }
90119 .container {
91120 position : absolute;
92121 width : 100% ;
0 commit comments