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 05:47:10 +00:00
parent 995b1c016f
commit a078202bd7
49 changed files with 6442 additions and 6 deletions

View file

@ -0,0 +1,71 @@
// Which theme each site tab gets. The global theme applies everywhere unless an account profile
// has a theme of its own, and any pane can override both (the pane's “…” menu, the app's theme
// settings). A pane or account theme is the theme document as it is (the global theme's
// customizations and accent belong to the global theme). Native code keeps the same rules and
// delivers each tab its theme; the shell uses them for pane chrome. Pure (tests, shell, panel).
export type ThemeScopes = {
/** wayBetter's window (tabs, address bar, titlebar, panel) follows the theme, or keeps its own style. */
chrome: 'theme' | 'own';
/** Account profile id -> theme id. */
profiles: Record<string, string>;
/** Pane (tab) id -> theme id. */
panes: Record<string, string>;
};
export const MAX_PROFILE_THEMES = 32;
export const MAX_PANE_THEMES = 64;
export const SCOPES_DEFAULT: ThemeScopes = { chrome: 'theme', profiles: {}, panes: {} };
const THEME_ID = /^[a-z0-9-]{1,40}$/;
const PROFILE_ID = /^(default|p[a-z0-9]{1,32})$/;
const TAB_ID = /^[A-Za-z0-9-]{1,40}$/;
function entries(value: unknown, key: RegExp, max: number): Record<string, string> {
if (!value || typeof value !== 'object' || Array.isArray(value)) return {};
const out: Record<string, string> = {};
for (const [id, theme] of Object.entries(value)) {
if (Object.keys(out).length >= max) break;
if (key.test(id) && typeof theme === 'string' && THEME_ID.test(theme)) out[id] = theme;
}
return out;
}
/** Any JSON to valid scopes (bounded; unknown values dropped). */
export function normalizeScopes(input: unknown): ThemeScopes {
const source = input && typeof input === 'object' ? input as Record<string, unknown> : {};
return {
chrome: source.chrome === 'own' ? 'own' : 'theme',
profiles: entries(source.profiles, PROFILE_ID, MAX_PROFILE_THEMES),
panes: entries(source.panes, TAB_ID, MAX_PANE_THEMES),
};
}
export type ScopeSource = 'pane' | 'account' | 'global';
/**
* The theme id a tab shows and where it comes from: the pane's own, else its account's, else the
* global one. An id that no longer exists (a removed imported theme) falls through.
*/
export function themeIdFor(scopes: ThemeScopes, tab: { id?: string; profile?: string }, globalPreset: string, known: (id: string) => boolean): { id: string; source: ScopeSource } {
const pane = tab.id ? scopes.panes[tab.id] : undefined;
if (pane && known(pane)) return { id: pane, source: 'pane' };
const account = tab.profile ? scopes.profiles[tab.profile] : undefined;
if (account && known(account)) return { id: account, source: 'account' };
return { id: globalPreset, source: 'global' };
}
/** Drops pane entries whose pane is gone (the shell calls this with its open tab ids). */
export function prunePanes(scopes: ThemeScopes, open: Iterable<string>): ThemeScopes {
const keep = new Set(open);
const panes = Object.fromEntries(Object.entries(scopes.panes).filter(([id]) => keep.has(id)));
return Object.keys(panes).length === Object.keys(scopes.panes).length ? scopes : { ...scopes, panes };
}
/** Sets (or with null clears) one pane's or account's theme. */
export function assign(scopes: ThemeScopes, kind: 'panes' | 'profiles', id: string, theme: string | null): ThemeScopes {
const next = { ...scopes[kind] };
if (theme) next[id] = theme; else delete next[id];
return normalizeScopes({ ...scopes, [kind]: next });
}