shell: the panel, createPanel(site) (moved from wayBetter for X)
packages/shell/src/panel (waybetter/shell/panel): an app's own tab. An app describes itself (PanelSite: brand and the home page's words, its own sections and their order, its theme store, catalog and the preview component a theme document is drawn in, Make's examples and docs, the install controller, its languages, what its native side serves) and createPanel returns the component for ShellSite.panel. It is in the shell package because it is drawn in the frame and shares its stores, native bridge and language. - Panel.tsx (header, settings search over every settings section, navigation, toasts; Accounts and Updates), nav.ts (which built-in sections an app gets: each shows only when the app serves what it needs; the app's sections in its order), Home.tsx (hero, highlights, About from the app's data), controls.tsx + panel.css. - Appearance.tsx, ThemeBuilder.tsx + builderModel.ts + builder.css, fonts/ (FontBrowser, FontRoles, catalog, the offline Google Fonts list; scripts/google-fonts-catalog.mjs regenerates it): the theme documents are the runtime's, the store, catalog, accents, draft palette, file suffix and preview are the app's (PanelSite.themes). - Plugins.tsx (the plugins list and custom CSS over the host's plugins_*/custom_css_*), StoreSection.tsx, MakePanel.tsx + makeModel.ts + MarkdownDoc.tsx + markdown.ts + make.css (the examples, the theme file and the docs are the app's), Settings.tsx (links and session over settings_get/set with `siteLinks`, keyword alerts, the media panel), FeatureToggles.tsx (useFeatures + FeatureGroups over features_get/set: the app names its flags and groups), PowerSettings.tsx (deck defaults from site.deck: its flags and presets; DeckPreset gets `name` and `hint`), BackupPanel.tsx + backup.css, DeveloperPanel.tsx, LanguageSettings.tsx, compare.ts. - frame: language.ts (createLanguage: follow the site / the system / one language, i18n_set; moved from the app), appI18n.ts (createAppI18n: the app's typed i18n instance, useT, dates and numbers; the app passes React's useSyncExternalStore), formatDate in i18n.ts (ShellI18n.date). - tests/panel.test.ts: every panel key has English and is used, sections per app, the builder model, the font catalog, plugin header rules, the UI kit demos, Markdown, compare. - npm package: exports ./shell/panel, ./shell/panel/*, ./shell/panel/*.css; the build is scripts/build.mjs (the shell is compiled with the runtime sources it imports under one root and its imports are pointed at dist/runtime; stylesheets and the font list are copied). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
7a3f23aa82
commit
ad2a3ad375
44 changed files with 4864 additions and 2 deletions
57
packages/shell/src/panel/StoreSection.tsx
Normal file
57
packages/shell/src/panel/StoreSection.tsx
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
// The wayBetter Store section: the Store view (StoreView.tsx) with the panel's own controls, the
|
||||
// app's built-in and own themes, and removal of installed items. Native code verifies the catalog's
|
||||
// Ed25519 signature, keeps the app's items, then checks each download's sha256. Installing always
|
||||
// goes through the shell's install screen (InstallDialog), never straight from here.
|
||||
import { invoke } from '../frame/bridge.ts';
|
||||
import { useT } from '../frame/hooks.ts';
|
||||
import { relativeTime } from '../frame/i18n.ts';
|
||||
import { site } from '../frame/site.ts';
|
||||
import type { StoreCatalogView, StoreItem } from '../storeModel.ts';
|
||||
import { StoreView, type StoreControls } from '../StoreView.tsx';
|
||||
import '../store.css';
|
||||
import { Badge, Button, EmptyState, SearchField, Segmented, useSettingsQuery } from './controls.tsx';
|
||||
import { panelSite, panelThemes, type Notify } from './site.ts';
|
||||
import { useThemeState } from './themes.ts';
|
||||
import './plugins.css';
|
||||
|
||||
const CONTROLS: Partial<StoreControls> = { Button, SearchField, Segmented, EmptyState, Badge };
|
||||
const RELOAD_ON = ['bt-plugins-changed', 'bt-store-changed'];
|
||||
|
||||
export function StoreSection({ notify }: { notify: Notify }) {
|
||||
const t = useT();
|
||||
const { store, catalog } = panelThemes();
|
||||
const themes = useThemeState();
|
||||
const settingsQuery = useSettingsQuery();
|
||||
if (settingsQuery) return null;
|
||||
const userThemes = themes.choice.themes.map(theme => theme.id);
|
||||
|
||||
async function remove(item: StoreItem, view: StoreCatalogView): Promise<boolean> {
|
||||
if (item.kind === 'plugin' && item.file) {
|
||||
await invoke('plugin_remove', { file: item.file });
|
||||
window.dispatchEvent(new CustomEvent('bt-plugins-changed'));
|
||||
return true;
|
||||
}
|
||||
const record = Object.entries(view.records.items).find(([key, value]) => key.startsWith('theme:') && value.storeId === item.id && userThemes.includes(key.slice(6)));
|
||||
const id = record?.[0].slice(6);
|
||||
if (!id) return false;
|
||||
const choice = themes.choice;
|
||||
await store.setChoice({ ...choice, themes: choice.themes.filter(theme => theme.id !== id), ...(choice.preset === id ? { preset: catalog.defaultChoice.preset, overrides: {}, accent: null } : {}) });
|
||||
await invoke('install_forget', { kind: 'theme', name: id });
|
||||
return true;
|
||||
}
|
||||
|
||||
return <StoreView
|
||||
t={t}
|
||||
site={site().name}
|
||||
load={refresh => invoke<StoreCatalogView>('store_catalog', { refresh })}
|
||||
controller={panelSite().store!.controller}
|
||||
builtinThemes={catalog.builtins.map(theme => theme.id)}
|
||||
userThemes={userThemes}
|
||||
onRemove={remove}
|
||||
onUse={item => store.setChoice({ ...themes.choice, preset: item.id, overrides: {}, accent: null })}
|
||||
notify={notify}
|
||||
relativeTime={relativeTime}
|
||||
reloadOn={RELOAD_ON}
|
||||
controls={CONTROLS}
|
||||
/>;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue