mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
A panel's collapsed, dock-pinned, dock-pinned-top, layout-auto-collapsed
and accordion-collapsed classes are drawn by its root's v-panel-state from
the gev-panel-chrome store. PanelChrome, its restore, the layout
controller, both rails and the side accordion present each panel's state
there instead of writing its classes; the rails call onCollapse(panel,
{collapsed, auto}). The directive applies a change in a synchronous
watcher, since the rails measure a panel in the task that opens or closes
it.
Destroying the chrome inside Cockpit now puts back the panels Cockpit's
entry closed while it can still present them. Without a shell, the voice
tools' set_panel_open reports that there is no panel to open. QA scripts
present the states they set instead of writing the classes.
41 lines
1.5 KiB
JavaScript
41 lines
1.5 KiB
JavaScript
/**
|
|
* Keep one side panel open on desktop, and on phones put back the collapse
|
|
* this applied, since a sheet shows several panels at once. The owner is the
|
|
* most recently opened panel, then the one holding keyboard focus, then the
|
|
* first. `accordion-collapsed` marks the collapse as presentation only, so
|
|
* saved and shared preferences still report the panel as the user left it.
|
|
* @param {object} options
|
|
* @param {HTMLElement[]} options.panels The side's laid-out panels.
|
|
* @param {boolean} options.enabled Whether the one-panel rule applies.
|
|
* @param {string} [options.preferredPanelId] Most recently opened panel.
|
|
* @param {Document} [options.documentRef] Document supplying keyboard focus.
|
|
* @param {Function} options.onCollapse Present a panel's collapse:
|
|
* `(panel, {collapsed, auto})`.
|
|
*/
|
|
export function settleSideAccordion({
|
|
panels,
|
|
enabled,
|
|
preferredPanelId,
|
|
documentRef,
|
|
onCollapse,
|
|
}) {
|
|
if (!enabled) {
|
|
for (const panel of panels) {
|
|
if (!panel.classList.contains('accordion-collapsed')) continue;
|
|
onCollapse(panel, { collapsed: false, auto: null });
|
|
}
|
|
return;
|
|
}
|
|
const expanded = panels.filter(
|
|
(panel) => !panel.classList.contains('collapsed'),
|
|
);
|
|
const owner =
|
|
expanded.find((panel) => panel.id === preferredPanelId) ||
|
|
expanded.find((panel) => panel.contains(documentRef?.activeElement)) ||
|
|
expanded[0];
|
|
for (const panel of expanded) {
|
|
if (panel === owner) continue;
|
|
onCollapse(panel, { collapsed: true, auto: 'accordion' });
|
|
}
|
|
}
|