mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 08:12:24 +00:00
feat(panels): render each panel's state classes from the store
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.
This commit is contained in:
1 parent
dd3a2c87f9
commit
95523e09cd
37 files changed
+404
-135
No files matched your search
@@ -0,0 +1,70 @@
|
||||
import { watch } from 'vue';
|
||||
import { usePanelChromeStore } from '../stores/panelChrome.js';
|
||||
|
||||
/** The classes a panel's state draws on its root. */
|
||||
const CLASSES = Object.freeze({
|
||||
collapsed: (state) => state.collapsed,
|
||||
'dock-pinned': (state) => state.pinned,
|
||||
'dock-pinned-top': (state) => state.pinnedTop,
|
||||
'layout-auto-collapsed': (state) => state.auto === 'layout',
|
||||
'accordion-collapsed': (state) => state.auto === 'accordion',
|
||||
});
|
||||
|
||||
/**
|
||||
* Draw `state` on a panel's root with `classList`, leaving other classes.
|
||||
* @param {Element} el
|
||||
* @param {import('../stores/panelChrome.js').PanelState} state
|
||||
*/
|
||||
export function applyPanelState(el, state) {
|
||||
for (const [name, on] of Object.entries(CLASSES))
|
||||
if (el.classList.contains(name) !== on(state))
|
||||
el.classList.toggle(name, on(state));
|
||||
}
|
||||
|
||||
/**
|
||||
* Keep `el` drawing the state `store` holds for `panelId`, synchronously:
|
||||
* the panel layouts measure a panel in the same task that opens or closes
|
||||
* it. Until the panel is presented its markup's classes stand.
|
||||
* @returns {() => void} Stops following the store.
|
||||
*/
|
||||
export function followPanelState(store, panelId, el) {
|
||||
return watch(
|
||||
() => store.panels[panelId],
|
||||
(state) => state && applyPanelState(el, state),
|
||||
{ flush: 'sync', immediate: true },
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* `v-panel-state="'data-panel'"`: the panel root draws its open, pinned and
|
||||
* layout-collapsed state from the panel chrome store.
|
||||
*/
|
||||
export const vPanelState = {
|
||||
mounted(el, binding) {
|
||||
const store = usePanelChromeStore(binding.instance.$pinia);
|
||||
el._stopPanelState = followPanelState(store, binding.value, el);
|
||||
},
|
||||
beforeUnmount(el) {
|
||||
el._stopPanelState?.();
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
* A panel's state as its classes draw it: the markup's state, before its
|
||||
* owner first presents the panel.
|
||||
* @param {Element} el
|
||||
* @returns {import('../stores/panelChrome.js').PanelState}
|
||||
*/
|
||||
export function readPanelState(el) {
|
||||
const has = (name) => el.classList.contains(name);
|
||||
return {
|
||||
collapsed: has('collapsed'),
|
||||
pinned: has('dock-pinned'),
|
||||
pinnedTop: has('dock-pinned-top'),
|
||||
auto: has('layout-auto-collapsed')
|
||||
? 'layout'
|
||||
: has('accordion-collapsed')
|
||||
? 'accordion'
|
||||
: null,
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user