feat(panels): render collapse, dock and pin buttons from the store

PanelChrome no longer writes the panels' collapse buttons, the command
dock tray toggles' names or the dock pins' pressed state. It presents each
panel's open and pinned state to the new gev-panel-chrome store, and the
buttons, now views, call it there: PanelCollapseButton for the panel
headers, bound toggles and pins in the command dock. Clicks take effect
once the chrome is initialized; a new owner starts from its own states.

bindPanelDisclosure binds only a panel's Escape and refuses the retired
buttons and onChange arguments. UiButton joins the component kit.
This commit is contained in:
Sameh Khamis committed 2026-10-31 23:30:08 -07:00
1 parent ec4c55e78c
commit dd3a2c87f9
25 files changed
+635 -212

No files matched your search

+11 -18
View File
@@ -13,28 +13,21 @@ function listenerScope() {
};
}
/** Bind collapse buttons and bubbling Escape to an existing panel. */
export function bindPanelDisclosure({
panel,
buttons = [],
onChange,
onEscape,
}) {
if (
!panel ||
typeof onChange !== 'function' ||
typeof onEscape !== 'function'
) {
/**
* Bind bubbling Escape to an existing panel. Its collapse buttons are views
* that ask the panel's owner to toggle it (PanelCollapseButton).
*/
export function bindPanelDisclosure({ panel, onEscape, ...retired }) {
if (!panel || typeof onEscape !== 'function') {
throw new TypeError('Panel disclosure requires a panel and onEscape');
}
// Buttons are views now; a caller still passing them would lose its clicks.
if ('buttons' in retired || 'onChange' in retired) {
throw new TypeError(
'Panel disclosure requires a panel, onChange and onEscape',
'Panel disclosure binds Escape only; render the buttons as views',
);
}
const scope = listenerScope();
for (const button of new Set(buttons)) {
scope.listen(button, 'click', () => {
onChange(!panel.classList.contains('collapsed'), { explicit: true });
});
}
scope.listen(panel, 'keydown', onEscape);
return { destroy: () => scope.destroy() };
}