style: format Cockpit components and pure policies

This commit is contained in:
Sameh Khamis committed 2026-09-13 02:37:44 -07:00
1 parent 8075c70e6e
commit e04aefe863
18 files changed
+2227 -1407

No files matched your search

+40 -15
View File
@@ -11,7 +11,9 @@ export class CockpitDisplayPortal {
this.frames = new Set();
this.listeners = new AbortController();
this.records = groups.flatMap(([name, group]) => {
const slot = cockpitPanel?.querySelector(`[data-cockpit-display-slot="${name}"]`);
const slot = cockpitPanel?.querySelector(
`[data-cockpit-display-slot="${name}"]`,
);
if (!group || !slot || !group.parentNode) return [];
const anchor = document.createComment(`cockpit-display-home:${name}`);
group.before(anchor);
@@ -20,15 +22,27 @@ export class CockpitDisplayPortal {
this.standardScrollTop = standardPanel?.scrollTop || 0;
this.cockpitScrollTop = cockpitPanel?.scrollTop || 0;
const options = { passive: true, signal: this.listeners.signal };
standardPanel?.addEventListener('scroll', () => {
if (!this.active) this.standardScrollTop = standardPanel.scrollTop;
}, options);
cockpitPanel?.addEventListener('scroll', () => {
if (this.active) this.cockpitScrollTop = cockpitPanel.scrollTop;
}, options);
window.addEventListener('gev:cockpit-mode-changed', event => {
this.setActive(event?.detail?.active === true);
}, { signal: this.listeners.signal });
standardPanel?.addEventListener(
'scroll',
() => {
if (!this.active) this.standardScrollTop = standardPanel.scrollTop;
},
options,
);
cockpitPanel?.addEventListener(
'scroll',
() => {
if (this.active) this.cockpitScrollTop = cockpitPanel.scrollTop;
},
options,
);
window.addEventListener(
'gev:cockpit-mode-changed',
(event) => {
this.setActive(event?.detail?.active === true);
},
{ signal: this.listeners.signal },
);
this.setActive(document.body.classList.contains('cockpit-mode'));
}
@@ -52,7 +66,9 @@ export class CockpitDisplayPortal {
if (this.active === nextActive) return;
this._cancelFrames();
const generation = this.generation;
const focusedRecord = this.records.find(record => record.group.contains(document.activeElement));
const focusedRecord = this.records.find((record) =>
record.group.contains(document.activeElement),
);
const focusedElement = focusedRecord ? document.activeElement : null;
this.restoreOwner = nextActive ? 'cockpit' : 'standard';
this.active = nextActive;
@@ -60,12 +76,21 @@ export class CockpitDisplayPortal {
if (nextActive) record.slot.append(record.group);
else if (record.anchor.parentNode) record.anchor.after(record.group);
}
this.cockpitPanel?.classList.toggle('uses-shared-display-controls', nextActive);
this.cockpitPanel?.classList.toggle(
'uses-shared-display-controls',
nextActive,
);
const restoreScroll = () => {
if (nextActive && this.cockpitPanel) this.cockpitPanel.scrollTop = this.cockpitScrollTop;
if (!nextActive && this.standardPanel) this.standardPanel.scrollTop = this.standardScrollTop;
if (nextActive && this.cockpitPanel)
this.cockpitPanel.scrollTop = this.cockpitScrollTop;
if (!nextActive && this.standardPanel)
this.standardPanel.scrollTop = this.standardScrollTop;
};
if (!settle) { restoreScroll(); this.restoreOwner = null; return; }
if (!settle) {
restoreScroll();
this.restoreOwner = null;
return;
}
this._frame(generation, () => {
restoreScroll();
focusedElement?.focus?.({ preventScroll: true });