@@ -20,33 +20,6 @@ interface SectionRegion {
20
20
}
21
21
type Region = PanelRegion | SectionRegion ;
22
22
23
- /** @TODO : remove this when I'm done with the PR */
24
- const enableLog = true ;
25
- let batchLog : any [ ] = [ ] ;
26
- const prepareBatchLog = ( ) => {
27
- batchLog = [ ] ;
28
- } ;
29
- const bLog = ( key : string , value ?: any ) => {
30
- batchLog . push ( { key, value} ) ;
31
- } ;
32
- const outputBatchLog = ( label : string ) => {
33
- if ( ! enableLog ) {
34
- return ;
35
- }
36
- console . log ( 'rfs' , label , batchLog . reduce ( ( acc , { key, value} , i ) => {
37
- acc [ `${ i } . ${ key } ` ] = value ;
38
- return acc ;
39
- } , { } as Record < string , any > ) ) ;
40
- batchLog = [ ] ;
41
- } ;
42
- const log = ( ...args : any [ ] ) => {
43
- if ( ! enableLog ) {
44
- return ;
45
- }
46
- console . log ( 'rfs' , ...args ) ;
47
- } ;
48
-
49
-
50
23
/**
51
24
* RegionFocusSwitcher enables keyboard navigation between app panels and doc widgets.
52
25
*
@@ -102,7 +75,6 @@ export class RegionFocusSwitcher extends Disposable {
102
75
103
76
public focusRegion ( region : Region | undefined , options : { initiator ?: MouseEvent } = { } ) {
104
77
if ( region ?. type === 'panel' && ! getPanelElement ( region . id ) ) {
105
- console . log ( 'RegionFocusSwitcher: skipping update (panel element not found)' ) ;
106
78
return ;
107
79
}
108
80
@@ -119,7 +91,6 @@ export class RegionFocusSwitcher extends Disposable {
119
91
}
120
92
121
93
public reset ( ) {
122
- log ( 'reset' ) ;
123
94
this . focusRegion ( undefined ) ;
124
95
}
125
96
@@ -185,7 +156,6 @@ export class RegionFocusSwitcher extends Disposable {
185
156
const currentlyInSection = current ?. type === 'section' ;
186
157
187
158
if ( targetsMain && ! currentlyInSection ) {
188
- log ( 'onClick: enable active section' ) ;
189
159
this . focusRegion ( { type : 'section' , id : gristDoc . viewModel . activeSectionId ( ) } , { initiator : event } ) ;
190
160
return ;
191
161
}
@@ -201,17 +171,14 @@ export class RegionFocusSwitcher extends Disposable {
201
171
|| ( isFocusableElement ( event . target ) || getPanelElement ( targetRegionId as Panel ) === event . target )
202
172
)
203
173
) {
204
- log ( 'onClick: disable active section' ) ;
205
174
this . focusRegion ( { type : 'panel' , id : targetRegionId as Panel } , { initiator : event } ) ;
206
175
return ;
207
176
}
208
177
}
209
178
210
179
private _onEscapeKeypress ( ) {
211
- log ( 'Esc: pressed' ) ;
212
180
const current = this . current . get ( ) ;
213
181
if ( current ?. type !== 'panel' ) {
214
- log ( 'Esc: not a panel, exiting' , current ) ;
215
182
return ;
216
183
}
217
184
const panelElement = getPanelElement ( current . id ) ;
@@ -222,13 +189,11 @@ export class RegionFocusSwitcher extends Disposable {
222
189
// If user presses escape again, we also want to focus the panel.
223
190
|| ( document . activeElement === document . body && panelElement )
224
191
) {
225
- log ( 'Esc: focus panel' , panelElement ?. className ) ;
226
192
panelElement ?. focus ( ) ;
227
193
return ;
228
194
}
229
195
// …Reset region focus switch if already on the panel itself
230
196
if ( document . activeElement === panelElement ) {
231
- log ( 'Esc: reset' ) ;
232
197
this . reset ( ) ;
233
198
}
234
199
}
@@ -245,20 +210,16 @@ export class RegionFocusSwitcher extends Disposable {
245
210
const isChildOfPanel = prevPanelElement ?. contains ( document . activeElement )
246
211
&& document . activeElement !== prevPanelElement ;
247
212
if ( ! isChildOfPanel ) {
248
- log ( 'save prevFocusedElement: skip' ) ;
249
213
return ;
250
214
}
251
- log ( 'save prevFocusedElement' , prev . id , document . activeElement ?. className ) ;
252
215
this . _prevFocusedElements [ prev . id ] = document . activeElement ;
253
216
}
254
217
255
218
private _onCurrentUpdate ( current : Region | undefined , prev : Region | undefined ) {
256
219
if ( isEqual ( current , prev ) ) {
257
- console . log ( 'RegionFocusSwitcher: skipping update (no change)' ) ;
258
220
return ;
259
221
}
260
222
261
- prepareBatchLog ( ) ;
262
223
const gristDoc = this . _getGristDoc ( ) ;
263
224
const mouseEvent = this . _currentUpdateInitiator instanceof MouseEvent ? this . _currentUpdateInitiator : undefined ;
264
225
@@ -293,16 +254,13 @@ export class RegionFocusSwitcher extends Disposable {
293
254
294
255
// if we reset the focus switch, clean all necessary state
295
256
if ( current === undefined ) {
296
- bLog ( 'reset, clear prevFocusedElements' ) ;
297
257
this . _prevFocusedElements = {
298
258
left : null ,
299
259
top : null ,
300
260
right : null ,
301
261
main : null ,
302
262
} ;
303
263
}
304
- bLog ( 'activeElement' , document . activeElement ) ;
305
- outputBatchLog ( 'currentUpdate' ) ;
306
264
}
307
265
308
266
private _toggleCreatorPanel ( ) {
@@ -351,7 +309,6 @@ const focusPanel = (panel: PanelRegion, child: HTMLElement | null, gristDoc: Gri
351
309
}
352
310
// No child to focus found: just focus the panel
353
311
if ( ! child || child === panelElement || ! child . isConnected ) {
354
- bLog ( 'focusPanel' , panelElement . className ) ;
355
312
panelElement . focus ( ) ;
356
313
}
357
314
@@ -363,7 +320,6 @@ const focusPanel = (panel: PanelRegion, child: HTMLElement | null, gristDoc: Gri
363
320
child . addEventListener ( 'blur' , ( ) => {
364
321
child . removeAttribute ( ATTRS . focusedElement ) ;
365
322
} , { once : true } ) ;
366
- bLog ( 'focusPanel child' , child . className ) ;
367
323
child . focus ?.( ) ;
368
324
}
369
325
@@ -376,7 +332,6 @@ const focusPanel = (panel: PanelRegion, child: HTMLElement | null, gristDoc: Gri
376
332
const focusViewLayout = ( gristDoc : GristDoc ) => {
377
333
triggerFocusGrab ( ) ;
378
334
gristDoc . viewModel . focusedRegionState ( 'in' ) ;
379
- bLog ( 'focusViewLayout focusedRegionState' , 'in' ) ;
380
335
} ;
381
336
382
337
// When going out of the view layout, default view state is 'out' to remove active session
@@ -385,7 +340,6 @@ const focusViewLayout = (gristDoc: GristDoc) => {
385
340
// the active session borders, so that user understands what session the current panel is related to.
386
341
const escapeViewLayout = ( gristDoc : GristDoc , isRelated = false ) => {
387
342
gristDoc . viewModel . focusedRegionState ( isRelated ? 'related' : 'out' ) ;
388
- bLog ( 'escapeViewLayout focusedRegionState' , isRelated ? 'related' : 'out' ) ;
389
343
} ;
390
344
391
345
/**
@@ -394,7 +348,6 @@ const escapeViewLayout = (gristDoc: GristDoc, isRelated = false) => {
394
348
const focusSection = ( section : SectionRegion , gristDoc : GristDoc ) => {
395
349
focusViewLayout ( gristDoc ) ;
396
350
gristDoc . viewModel . activeSectionId ( section . id ) ;
397
- bLog ( 'focusSection activeSectionId' , section . id ) ;
398
351
} ;
399
352
400
353
/**
@@ -449,13 +402,11 @@ const getSibling = (
449
402
// If we still don't find anything, it means we never set the current region before on a non-doc page,
450
403
// or we didn't find any current doc section. Return the first region as default.
451
404
if ( currentIndexInCycle === - 1 ) {
452
- bLog ( 'sibling' , regions [ 0 ] ) ;
453
405
return regions [ 0 ] ;
454
406
}
455
407
456
408
// Normal case: just return the next or previous region in the cycle, wrapping around
457
409
const sibling = regions [ mod ( currentIndexInCycle + ( direction === 'next' ? 1 : - 1 ) , regions . length ) ] ;
458
- bLog ( 'sibling' , sibling ) ;
459
410
return sibling ;
460
411
} ;
461
412
@@ -465,10 +416,6 @@ const getSibling = (
465
416
const blurPanelChild = ( panel : PanelRegion ) => {
466
417
const panelElement = getPanelElement ( panel . id ) ;
467
418
if ( panelElement ?. contains ( document . activeElement ) && document . activeElement !== panelElement ) {
468
- bLog ( 'isPanel clear focus' , {
469
- activeElement : document . activeElement ?. className ,
470
- panelElement : panelElement . className ,
471
- } ) ;
472
419
( document . activeElement as HTMLElement ) . blur ( ) ;
473
420
}
474
421
} ;
@@ -499,7 +446,6 @@ const isFocusableElement = (el: EventTarget | null): boolean => {
499
446
*/
500
447
const removeFocusRings = ( ) => {
501
448
document . querySelectorAll ( `[${ ATTRS . focusedElement } ]` ) . forEach ( el => {
502
- bLog ( `remove ${ ATTRS . focusedElement } ` , el ) ;
503
449
el . removeAttribute ( ATTRS . focusedElement ) ;
504
450
} ) ;
505
451
} ;
0 commit comments