Files
marco/app/utils/sheet-parent.js
raucao c56917e122 WIP: Stack parent sheets behind the mobile bottom drawer
Derive the sheet stack from the URL instead of mutating it: the route
template keeps rendering the top sheet, and application.gjs renders the
service-driven parent (search results, lists index, app menu) behind it on
mobile, inert, so closing the top sheet reveals the parent at its
remembered size.

- bottom-sheet modifier: `background` arg — background instances settle
  immediately, inject no handle, take no gestures, never own the inset slot,
  and never write the remembered detent (restore-only).
- z-index: demote background sheets below the top sheet, including the app
  menu whose desktop z-index was inverted.
- outside tap on mobile pops to the parent without hideSidebar(), keeping
  the session and detent alive; desktop keeps today's close-all.
- tracked matchMedia-backed viewport service for the mobile breakpoint.
- lists index extracted into a component so it can render top or background.
- scope .sidebar-content lookups and test selectors to .sheet-top.

Known v1 limitation: popping hard-cuts to the parent route (no exit
animation). The full derived stack with independent detents for 3-level
chains is deferred.
2026-11-30 15:17:20 +04:00

66 lines
2.3 KiB
JavaScript

// Which sheet sits behind the current route's sheet on mobile.
//
// The URL stays authoritative: the stack is derived from the current route plus
// the map-ui session flags, never pushed or popped imperatively. This module is
// the single source of truth for both the background renderer
// (components/background-sheets.gjs) and the mobile outside-tap behaviour
// (templates/application.gjs).
//
// v1 only renders service-driven parents: the search results (map-ui), the
// lists index (storage) and the app menu (self-contained). A place opened from
// a list / contributions / activity timeline is deliberately parentless: those
// parents are controller-driven, so revealing them needs a data hand-off that
// is out of scope here. The pop still navigates to them; it just hard-cuts
// instead of revealing a background sheet.
// Routes whose parent sheet is the app menu.
const MENU_CHILD_ROUTES = new Set(['lists.index', 'contributions', 'activity']);
// The parent sheet to render behind `routeName`, or null when there is none.
// Returns { type: 'search' | 'lists-index' | 'menu' }.
export function parentSheetFor(routeName, mapUi) {
if (routeName === 'place') {
if (mapUi.returnToSearch && mapUi.currentSearch) {
return { type: 'search' };
}
return null;
}
if (routeName === 'lists.list') {
return { type: 'lists-index' };
}
if (MENU_CHILD_ROUTES.has(routeName)) {
return { type: 'menu' };
}
return null;
}
// The route an outside tap should pop to on mobile, or null when the current
// route has no parent (the sheet should close instead). This is broader than
// parentSheetFor: it also covers controller-driven parents that are not
// rendered as background sheets, so the session still survives the pop.
// Returns a transition descriptor: { name, model? } or { name, queryParams }.
export function parentTransitionFor(routeName, mapUi) {
if (routeName === 'place') {
if (mapUi.returnToSearch && mapUi.currentSearch) {
return { name: 'search', queryParams: mapUi.currentSearch };
}
if (mapUi.returnToRoute) {
return { ...mapUi.returnToRoute };
}
return null;
}
if (routeName === 'lists.list') {
return { name: 'lists.index' };
}
if (MENU_CHILD_ROUTES.has(routeName)) {
return { name: 'menu' };
}
return null;
}