Skip to content

Commit adeefb8

Browse files
committed
(kb) remove logs
1 parent 3eda7a8 commit adeefb8

File tree

1 file changed

+0
-54
lines changed

1 file changed

+0
-54
lines changed

app/client/components/RegionFocusSwitcher.ts

-54
Original file line numberDiff line numberDiff line change
@@ -20,33 +20,6 @@ interface SectionRegion {
2020
}
2121
type Region = PanelRegion | SectionRegion;
2222

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-
5023
/**
5124
* RegionFocusSwitcher enables keyboard navigation between app panels and doc widgets.
5225
*
@@ -102,7 +75,6 @@ export class RegionFocusSwitcher extends Disposable {
10275

10376
public focusRegion(region: Region | undefined, options: {initiator?: MouseEvent} = {}) {
10477
if (region?.type === 'panel' && !getPanelElement(region.id)) {
105-
console.log('RegionFocusSwitcher: skipping update (panel element not found)');
10678
return;
10779
}
10880

@@ -119,7 +91,6 @@ export class RegionFocusSwitcher extends Disposable {
11991
}
12092

12193
public reset() {
122-
log('reset');
12394
this.focusRegion(undefined);
12495
}
12596

@@ -185,7 +156,6 @@ export class RegionFocusSwitcher extends Disposable {
185156
const currentlyInSection = current?.type === 'section';
186157

187158
if (targetsMain && !currentlyInSection) {
188-
log('onClick: enable active section');
189159
this.focusRegion({ type: 'section', id: gristDoc.viewModel.activeSectionId() }, { initiator: event });
190160
return;
191161
}
@@ -201,17 +171,14 @@ export class RegionFocusSwitcher extends Disposable {
201171
|| (isFocusableElement(event.target) || getPanelElement(targetRegionId as Panel) === event.target)
202172
)
203173
) {
204-
log('onClick: disable active section');
205174
this.focusRegion({ type: 'panel', id: targetRegionId as Panel }, { initiator: event });
206175
return;
207176
}
208177
}
209178

210179
private _onEscapeKeypress() {
211-
log('Esc: pressed');
212180
const current = this.current.get();
213181
if (current?.type !== 'panel') {
214-
log('Esc: not a panel, exiting', current);
215182
return;
216183
}
217184
const panelElement = getPanelElement(current.id);
@@ -222,13 +189,11 @@ export class RegionFocusSwitcher extends Disposable {
222189
// If user presses escape again, we also want to focus the panel.
223190
|| (document.activeElement === document.body && panelElement)
224191
) {
225-
log('Esc: focus panel', panelElement?.className);
226192
panelElement?.focus();
227193
return;
228194
}
229195
// …Reset region focus switch if already on the panel itself
230196
if (document.activeElement === panelElement) {
231-
log('Esc: reset');
232197
this.reset();
233198
}
234199
}
@@ -245,20 +210,16 @@ export class RegionFocusSwitcher extends Disposable {
245210
const isChildOfPanel = prevPanelElement?.contains(document.activeElement)
246211
&& document.activeElement !== prevPanelElement;
247212
if (!isChildOfPanel) {
248-
log('save prevFocusedElement: skip');
249213
return;
250214
}
251-
log('save prevFocusedElement', prev.id, document.activeElement?.className);
252215
this._prevFocusedElements[prev.id] = document.activeElement;
253216
}
254217

255218
private _onCurrentUpdate(current: Region | undefined, prev: Region | undefined) {
256219
if (isEqual(current, prev)) {
257-
console.log('RegionFocusSwitcher: skipping update (no change)');
258220
return;
259221
}
260222

261-
prepareBatchLog();
262223
const gristDoc = this._getGristDoc();
263224
const mouseEvent = this._currentUpdateInitiator instanceof MouseEvent ? this._currentUpdateInitiator : undefined;
264225

@@ -293,16 +254,13 @@ export class RegionFocusSwitcher extends Disposable {
293254

294255
// if we reset the focus switch, clean all necessary state
295256
if (current === undefined) {
296-
bLog('reset, clear prevFocusedElements');
297257
this._prevFocusedElements = {
298258
left: null,
299259
top: null,
300260
right: null,
301261
main: null,
302262
};
303263
}
304-
bLog('activeElement', document.activeElement);
305-
outputBatchLog('currentUpdate');
306264
}
307265

308266
private _toggleCreatorPanel() {
@@ -351,7 +309,6 @@ const focusPanel = (panel: PanelRegion, child: HTMLElement | null, gristDoc: Gri
351309
}
352310
// No child to focus found: just focus the panel
353311
if (!child || child === panelElement || !child.isConnected) {
354-
bLog('focusPanel', panelElement.className);
355312
panelElement.focus();
356313
}
357314

@@ -363,7 +320,6 @@ const focusPanel = (panel: PanelRegion, child: HTMLElement | null, gristDoc: Gri
363320
child.addEventListener('blur', () => {
364321
child.removeAttribute(ATTRS.focusedElement);
365322
}, {once: true});
366-
bLog('focusPanel child', child.className);
367323
child.focus?.();
368324
}
369325

@@ -376,7 +332,6 @@ const focusPanel = (panel: PanelRegion, child: HTMLElement | null, gristDoc: Gri
376332
const focusViewLayout = (gristDoc: GristDoc) => {
377333
triggerFocusGrab();
378334
gristDoc.viewModel.focusedRegionState('in');
379-
bLog('focusViewLayout focusedRegionState', 'in');
380335
};
381336

382337
// When going out of the view layout, default view state is 'out' to remove active session
@@ -385,7 +340,6 @@ const focusViewLayout = (gristDoc: GristDoc) => {
385340
// the active session borders, so that user understands what session the current panel is related to.
386341
const escapeViewLayout = (gristDoc: GristDoc, isRelated = false) => {
387342
gristDoc.viewModel.focusedRegionState(isRelated ? 'related' : 'out');
388-
bLog('escapeViewLayout focusedRegionState', isRelated ? 'related' : 'out');
389343
};
390344

391345
/**
@@ -394,7 +348,6 @@ const escapeViewLayout = (gristDoc: GristDoc, isRelated = false) => {
394348
const focusSection = (section: SectionRegion, gristDoc: GristDoc) => {
395349
focusViewLayout(gristDoc);
396350
gristDoc.viewModel.activeSectionId(section.id);
397-
bLog('focusSection activeSectionId', section.id);
398351
};
399352

400353
/**
@@ -449,13 +402,11 @@ const getSibling = (
449402
// If we still don't find anything, it means we never set the current region before on a non-doc page,
450403
// or we didn't find any current doc section. Return the first region as default.
451404
if (currentIndexInCycle === -1) {
452-
bLog('sibling', regions[0]);
453405
return regions[0];
454406
}
455407

456408
// Normal case: just return the next or previous region in the cycle, wrapping around
457409
const sibling = regions[mod(currentIndexInCycle + (direction === 'next' ? 1 : -1), regions.length)];
458-
bLog('sibling', sibling);
459410
return sibling;
460411
};
461412

@@ -465,10 +416,6 @@ const getSibling = (
465416
const blurPanelChild = (panel: PanelRegion) => {
466417
const panelElement = getPanelElement(panel.id);
467418
if (panelElement?.contains(document.activeElement) && document.activeElement !== panelElement) {
468-
bLog('isPanel clear focus', {
469-
activeElement: document.activeElement?.className,
470-
panelElement: panelElement.className,
471-
});
472419
(document.activeElement as HTMLElement).blur();
473420
}
474421
};
@@ -499,7 +446,6 @@ const isFocusableElement = (el: EventTarget | null): boolean => {
499446
*/
500447
const removeFocusRings = () => {
501448
document.querySelectorAll(`[${ATTRS.focusedElement}]`).forEach(el => {
502-
bLog(`remove ${ATTRS.focusedElement}`, el);
503449
el.removeAttribute(ATTRS.focusedElement);
504450
});
505451
};

0 commit comments

Comments
 (0)