shell: the shell frame, createShell(site) (moved from wayBetter for X)

packages/shell/src/frame (waybetter/shell/frame): the whole shell of an app. An app describes its
site (ShellSite: names and pages, account rules, search, address chips and completions, its panel
tab, the new-tab page, palette items, deck column kinds and flags and an optional compose dock, the
media panel's composer rule, a theme store, overlays, the native features it serves) and passes
its Tauri API and i18n instance; createShell returns the root component.

- Shell.tsx: dockview host (tabs in the titlebar row, splits, drag-link drops, shortcuts, context
  menu, deck back-and-forth, session restore, workspace on start, overlay raise); state.ts (pane
  placeholders, tabs_sync one-in-flight via syncGate, shell_raise layer, profiles, layout).
- WebPanel (address bar), NewTabPage, CommandPalette + paletteModel (frame groups; site items),
  DeckView + AddColumnDialog + deckStore (site column kinds), PaneTheme + themeStore
  (createThemeStore over the app's ThemeAdapter) + chromeTheme (ChromeTheme input) + themeScopes,
  Titlebar + TitlebarExtras + icons + brand (wB mark data URI), AccountSwitcher + accountModel,
  workspaces + workspaceModel, backupModel, syncHost, devHost + devModel, pluginCommandStore,
  MediaPanel + mediaModel, searchInput, hooks, bridge (installPreviewMocks), i18n, boot.ts
  (bootScript: the first-frame boot.js), CSS themed with --wb-* tokens.
- paneModel: paneVisibility, raiseSupported, cssRgb; deckModel: isSourcePage.
- Includes the live-QA titlebar fix (dock ResizeObserver + rAF titlebar marks, dock sized by its
  insets).
- tests/frame.test.ts: every frame key has English and is used, palette order with a site,
  address fallback, layout gate, boot script, chrome variables, switcher rules, workspaces,
  deck settings with site flags.
- npm package 0.4.0: exports ./shell/frame, ./shell/frame/*, ./shell/frame/*.css (copied by the
  build); dockview and acorn optional peers; root devDependencies dockview, acorn.
This commit is contained in:
CRTkafa 2026-09-29 12:47:10 +07:00
parent 60b3e57a0a
commit 322f854753
49 changed files with 6442 additions and 6 deletions

View file

@ -0,0 +1,82 @@
// "Theme for this pane": a menu (tab context menu, the address bar's ⋯ menu) that gives one pane its
// own theme or lets it follow its account's / the global theme again. Pane themes are stored with
// the other scopes (themeStore.ts → native `theme_scopes_set`), which re-themes that tab natively.
// Only with themes (`site.themes`).
import { useEffect, useRef, useState, type KeyboardEvent as ReactKeyboardEvent } from 'react';
import { createPortal } from 'react-dom';
import { useT, useThemeState } from './hooks.ts';
import { Icon } from './icons.tsx';
import { site } from './site.ts';
import { setOverlay, shell } from './state.ts';
import { assign, themeIdFor } from './themeScopes.ts';
import type { ThemeDoc, ThemeStore } from './themeStore.ts';
import './paneTheme.css';
type Request = { id: string; profile: string; x: number; y: number };
let open: (request: Request | null) => void = () => {};
export const openPaneTheme = (request: Request) => open(request);
/** Three dots of a theme's page, text and accent. */
export function ThemeDots<Spec extends ThemeDoc>({ theme, store }: { theme: Spec; store?: ThemeStore<unknown, Spec> }) {
const themes = (store ?? site().themes) as ThemeStore<unknown, Spec> | undefined;
if (!themes) return null;
const c = themes.adapter.dots(theme);
return <span className="wb-dots" aria-hidden="true" style={{ background: c.page }}>
<i style={{ background: c.bg, boxShadow: `inset 0 0 0 1px ${c.border}` }}/><i style={{ background: c.text }}/><i style={{ background: c.accent }}/>
</span>;
}
export function PaneThemeHost() {
const [request, setRequest] = useState<Request | null>(null);
open = setRequest;
const themes = site().themes;
return request && themes ? <PaneThemeMenu request={request} store={themes} onClose={() => setRequest(null)}/> : null;
}
function PaneThemeMenu({ request, store, onClose }: { request: Request; store: ThemeStore<unknown, ThemeDoc>; onClose(): void }) {
const { scopes, choice } = useThemeState(store);
const list = useRef<HTMLDivElement>(null);
useEffect(() => {
setOverlay(1);
const onBlur = () => onClose();
window.addEventListener('blur', onBlur);
requestAnimationFrame(() => list.current?.querySelector<HTMLButtonElement>('[aria-checked=true]')?.focus());
return () => { setOverlay(-1); window.removeEventListener('blur', onBlur); };
}, []);
const own = scopes.panes[request.id];
const inherited = themeIdFor({ ...scopes, panes: {} }, { profile: request.profile }, store.adapter.preset(choice), id => store.knownTheme(id));
const pick = (theme: string | null) => {
onClose();
void store.setScopes(assign(store.themeState().scopes, 'panes', request.id, theme)).catch(() => {});
};
const onKey = (event: ReactKeyboardEvent) => {
const items = [...(list.current?.querySelectorAll<HTMLButtonElement>('button') ?? [])];
const index = items.indexOf(document.activeElement as HTMLButtonElement);
if (event.key === 'Escape') { event.preventDefault(); onClose(); }
else if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
event.preventDefault();
items[(index + (event.key === 'ArrowDown' ? 1 : -1) + items.length) % items.length]?.focus();
} else if (event.key === 'Home' || event.key === 'End') { event.preventDefault(); items[event.key === 'Home' ? 0 : items.length - 1]?.focus(); }
};
const t = useT();
const left = Math.max(8, Math.min(request.x, window.innerWidth - 280));
const top = Math.max(8, Math.min(request.y, window.innerHeight - 440));
return createPortal(<div className="bt-menu-backdrop" onMouseDown={onClose} onContextMenu={event => { event.preventDefault(); onClose(); }}>
<div className="bt-menu bt-pop wb-pane-menu" role="menu" aria-label={t('wb.pane.theme')} style={{ left, top }} onMouseDown={event => event.stopPropagation()} onKeyDown={onKey} ref={list}>
<div className="wb-pane-menu-head"><Icon name="palette"/><span>{t('wb.pane.theme')}</span></div>
<button role="menuitemradio" aria-checked={!own} onClick={() => pick(null)}>
<span className="bt-menu-label">{inherited.source === 'account' ? t('wb.pane.followAccount') : t('wb.pane.followApp')} <small>· {store.themeName(inherited.id)}</small></span>
{!own && <Icon name="check"/>}
</button>
<hr/>
<div className="wb-pane-menu-list">
{store.allThemes(choice).map(theme => <button key={theme.id} role="menuitemradio" aria-checked={own === theme.id} onClick={() => pick(theme.id)}>
<ThemeDots theme={theme} store={store}/><span className="bt-menu-label">{theme.name}</span>{own === theme.id && <Icon name="check"/>}
</button>)}
</div>
<hr/>
<button role="menuitem" onClick={() => { onClose(); shell.openPanelSection('themes'); }}><Icon name="settings"/><span className="bt-menu-label">{t('wb.pane.themesLink')}</span></button>
</div>
</div>, document.body);
}