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.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
CRTkafa 2026-09-29 12:47:10 +07:00
parent 37e3d8e5fc
commit 60faed66be
49 changed files with 6442 additions and 6 deletions

View file

@ -0,0 +1,96 @@
import { useEffect, type CSSProperties, type MouseEvent as ReactMouseEvent } from 'react';
import { RESIZE_BORDER } from '../chrome.ts';
import { chipFor } from '../updateModel.ts';
import { AccountSwitcher } from './AccountSwitcher.tsx';
import { invoke } from './bridge.ts';
import { useT, useUpdateStatus } from './hooks.ts';
import { tx } from './i18n.ts';
import { site } from './site.ts';
import { TitlebarExtras } from './TitlebarExtras.tsx';
import { close, minimize, os, startResize, systemMenu, toggleMaximize, type ResizeDirection } from './windowBinding.ts';
const isInteractive = (target: EventTarget | null) =>
target instanceof Element && !!target.closest('button, input, textarea, a, .dv-tab, [role="button"]');
/** Right-click on empty titlebar space: the native system menu (Restore, Move, Size, ...). */
export function titlebarContextMenu(event: ReactMouseEvent | MouseEvent) {
if (isInteractive(event.target)) return;
event.preventDefault();
const scale = window.devicePixelRatio || 1;
systemMenu(Math.round(event.screenX * scale), Math.round(event.screenY * scale));
}
/**
* The 44px titlebar row. It sits under the dockview root: the top groups' tab headers are
* transparent and let clicks through to the drag layer, the logo and the caption buttons.
*/
export function Titlebar({ maximized }: { maximized: boolean }) {
return <header className="bt-titlebar" onContextMenu={titlebarContextMenu}>
<div className="bt-titlebar-drag" data-tauri-drag-region/>
<img className="bt-titlebar-logo" src={site().logo} alt="" draggable={false} data-tauri-drag-region/>
<div className="bt-titlebar-spacer" data-tauri-drag-region/>
<TitlebarExtras/>
<AccountSwitcher/>
<UpdateChip/>
{os !== 'macos' && <WindowControls maximized={maximized}/>}
</header>;
}
/** "Update ready · restart": appears only when a verified update is downloaded (or failed to start). */
function UpdateChip() {
const [status, apply] = useUpdateStatus();
const chip = chipFor(status, site().product, key => tx(key, undefined, '') || undefined);
// Widen the tab strip's right reserve while the chip is shown so tabs never sit under it.
useEffect(() => {
const root = document.documentElement;
if (chip) root.dataset.update = chip.kind; else delete root.dataset.update;
return () => { delete root.dataset.update; };
}, [chip?.kind]);
if (!chip) return null;
if (chip.kind === 'problem') {
return <button className="bt-update-chip bt-update-chip--problem" title={chip.title}
onClick={() => invoke('open_external_url', { url: chip.href }).catch(() => {})}>{chip.label}</button>;
}
return <button className={`bt-update-chip bt-update-chip--${chip.kind}`} title={chip.title} disabled={chip.kind === 'installing'} onClick={apply}>
<span className="bt-update-chip-dot" aria-hidden="true"/>{chip.label}
</button>;
}
function WindowControls({ maximized }: { maximized: boolean }) {
const t = useT();
return <div className="bt-captions">
<button className="bt-caption" aria-label={t('wb.shell.window.minimize')} title={t('wb.shell.window.minimize')} onClick={minimize}>
<svg viewBox="0 0 10 10" aria-hidden="true"><path d="M0 5.5h10"/></svg>
</button>
<button className="bt-caption" aria-label={maximized ? t('wb.shell.window.restore') : t('wb.shell.window.maximize')} title={maximized ? t('wb.shell.window.restore') : t('wb.shell.window.maximize')} onClick={toggleMaximize}>
{maximized
? <svg viewBox="0 0 10 10" aria-hidden="true"><path d="M.5 2.5h7v7h-7z"/><path d="M2.5 2.5v-2h7v7h-2"/></svg>
: <svg viewBox="0 0 10 10" aria-hidden="true"><path d="M.5.5h9v9h-9z"/></svg>}
</button>
<button className="bt-caption bt-caption--close" aria-label={t('wb.common.close')} title={t('wb.common.close')} onClick={close}>
<svg viewBox="0 0 10 10" aria-hidden="true"><path d="M0 0l10 10M10 0L0 10"/></svg>
</button>
</div>;
}
const CORNER = RESIZE_BORDER * 2;
const GRIPS: Array<[ResizeDirection, CSSProperties]> = [
['North', { top: 0, left: CORNER, right: CORNER, height: RESIZE_BORDER, cursor: 'ns-resize' }],
['South', { bottom: 0, left: CORNER, right: CORNER, height: RESIZE_BORDER, cursor: 'ns-resize' }],
['West', { left: 0, top: CORNER, bottom: CORNER, width: RESIZE_BORDER, cursor: 'ew-resize' }],
['East', { right: 0, top: CORNER, bottom: CORNER, width: RESIZE_BORDER, cursor: 'ew-resize' }],
['NorthWest', { top: 0, left: 0, width: CORNER, height: CORNER, cursor: 'nwse-resize' }],
['SouthEast', { bottom: 0, right: 0, width: CORNER, height: CORNER, cursor: 'nwse-resize' }],
['NorthEast', { top: 0, right: 0, width: CORNER, height: CORNER, cursor: 'nesw-resize' }],
['SouthWest', { bottom: 0, left: 0, width: CORNER, height: CORNER, cursor: 'nesw-resize' }],
];
/**
* The shell webview covers the whole frameless window, so the OS never sees its edges:
* these grips start native resize drags. Tab webviews are inset by the same band (Rust clamps too).
*/
export function ResizeGrips() {
return <>{GRIPS.map(([direction, style]) =>
<div key={direction} className="bt-grip" style={style} aria-hidden="true"
onPointerDown={event => { if (event.button === 0) { event.preventDefault(); startResize(direction); } }}/>)}</>;
}