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).
This commit is contained in:
parent
6ef78c0c30
commit
00b193506f
44 changed files with 4864 additions and 2 deletions
149
packages/shell/src/panel/Settings.tsx
Normal file
149
packages/shell/src/panel/Settings.tsx
Normal file
|
|
@ -0,0 +1,149 @@
|
|||
// Settings rows every app has: the home page, where links open and session restore (waybetter-host
|
||||
// `settings_get/set`), keyword alerts (`alerts_get/set`) and the media panel's folders and
|
||||
// clipboard history (`media_get/set`). Stored natively; applied live to every tab.
|
||||
import { useEffect, useState } from 'react';
|
||||
import { invoke } from '../frame/bridge.ts';
|
||||
import { useT } from '../frame/hooks.ts';
|
||||
import { CLIP_MAX_LIMIT, clampClipMax, folderLabel, withoutFolder, type MediaSettings } from '../frame/mediaModel.ts';
|
||||
import { site } from '../frame/site.ts';
|
||||
import { ChipList, Button, InputRow, Row, Section, Segmented, Stepper, Toggle } from './controls.tsx';
|
||||
import { panelSite, type Notify } from './site.ts';
|
||||
|
||||
/** The shell's settings (waybetter-host `ShellSettings`). */
|
||||
export type ShellSettings = {
|
||||
homeUrl: string;
|
||||
/** Links to other sites: beside the tab (split), a new tab, or the system browser. */
|
||||
externalLinks: 'pane' | 'tab' | 'browser';
|
||||
/** Site pages clicked in the page: the site's in-place navigation, beside, a new tab, or the system browser. */
|
||||
siteLinks: 'same' | 'pane' | 'tab' | 'browser';
|
||||
restoreTabs: boolean;
|
||||
};
|
||||
|
||||
const getError = (error: unknown) => error instanceof Error ? error.message : String(error);
|
||||
const FOLDER_ICON = <svg width="13" height="13" viewBox="0 0 16 16" aria-hidden="true"><path d="M2 4.5A1.5 1.5 0 0 1 3.5 3h3l1.5 1.5h4.5A1.5 1.5 0 0 1 14 6v5.5a1.5 1.5 0 0 1-1.5 1.5h-9A1.5 1.5 0 0 1 2 11.5z" fill="none" stroke="currentColor" strokeWidth="1.3"/></svg>;
|
||||
|
||||
type Opens = 'same' | 'pane' | 'tab' | 'browser';
|
||||
const OPENS: Record<Opens, string> = { same: 'wb.settings.links.opens.same', pane: 'wb.settings.links.opens.pane', tab: 'wb.settings.links.opens.tab', browser: 'wb.settings.links.opens.browser' };
|
||||
|
||||
/** Home page, where links open, session restore. Stored natively; read by the tab webviews. */
|
||||
export function BrowserSettings({ notify }: { notify: Notify }) {
|
||||
const t = useT();
|
||||
const [settings, setSettings] = useState<ShellSettings | null>(null);
|
||||
const [home, setHome] = useState('');
|
||||
|
||||
useEffect(() => { invoke<ShellSettings>('settings_get').then(value => { setSettings(value); setHome(value.homeUrl); }).catch(err => notify(getError(err), true)); }, []);
|
||||
|
||||
async function save(next: ShellSettings, message: string) {
|
||||
const previous = settings;
|
||||
setSettings(next);
|
||||
try { const saved = await invoke<ShellSettings>('settings_set', { settings: next }); setSettings(saved); setHome(saved.homeUrl); notify(message); }
|
||||
catch (err) { setSettings(previous); notify(getError(err), true); }
|
||||
}
|
||||
|
||||
if (!settings) return null;
|
||||
const siteHome = site().homeUrl;
|
||||
return <Section title={t('wb.settings.links.title')} hint={t('wb.settings.links.hint')}>
|
||||
<Row label={t('wb.settings.home.label')} hint={t('wb.settings.home.hint')} keywords="new tab start url" wide>
|
||||
<div className="bt-inline">
|
||||
<InputRow label={t('wb.settings.home.url')} mono value={home} onChange={setHome} button={t('wb.common.save')} disabled={home === settings.homeUrl}
|
||||
onSubmit={() => void save({ ...settings, homeUrl: home }, t('wb.settings.home.saved'))}/>
|
||||
{settings.homeUrl !== siteHome && <Button tone="ghost" size="sm" onClick={() => void save({ ...settings, homeUrl: siteHome }, t('wb.settings.home.resetDone'))}>{t('wb.settings.home.reset')}</Button>}
|
||||
</div>
|
||||
</Row>
|
||||
<Row label={t('wb.settings.links.external')} hint={t('wb.settings.links.externalHint')} keywords="external open browser pane split side">
|
||||
<Segmented label={t('wb.settings.links.external')} value={settings.externalLinks} onChange={mode => void save({ ...settings, externalLinks: mode }, t('wb.settings.links.externalSaved', { how: t(OPENS[mode as Opens]) }))}
|
||||
options={[{ value: 'pane', label: t('wb.settings.links.beside') }, { value: 'tab', label: t('wb.settings.links.newTab') }, { value: 'browser', label: t('wb.settings.links.browser') }]}/>
|
||||
</Row>
|
||||
<Row label={t('wb.settings.links.site')} hint={t('wb.settings.links.siteHint')} keywords={`${panelSite().settings?.linkKeywords ?? site().name} post profile open pane split side tab`}>
|
||||
<Segmented label={t('wb.settings.links.site')} value={settings.siteLinks} onChange={mode => void save({ ...settings, siteLinks: mode }, t('wb.settings.links.siteSaved', { how: t(OPENS[mode as Opens]) }))}
|
||||
options={[{ value: 'same', label: t('wb.settings.links.sameTab') }, { value: 'pane', label: t('wb.settings.links.beside') }, { value: 'tab', label: t('wb.settings.links.newTab') }, { value: 'browser', label: t('wb.settings.links.browser') }]}/>
|
||||
</Row>
|
||||
<Row label={t('wb.settings.restore.label')} hint={t('wb.settings.restore.hint')} keywords="session">
|
||||
<Toggle label={t('wb.settings.restore.label')} checked={settings.restoreTabs} onChange={next => void save({ ...settings, restoreTabs: next }, next ? t('wb.settings.restore.on') : t('wb.settings.restore.off'))}/>
|
||||
</Row>
|
||||
</Section>;
|
||||
}
|
||||
|
||||
type Alerts = { enabled: boolean; keywords: string[] };
|
||||
export const parseKeywords = (text: string) => text.split(/[,\n]/).map(word => word.trim()).filter(Boolean);
|
||||
const MAX_KEYWORDS = 32;
|
||||
|
||||
/** Keyword alerts: local OS notifications for keywords in items the site already loaded. Native only. */
|
||||
export function AlertSettings({ notify }: { notify: Notify }) {
|
||||
const t = useT();
|
||||
const [alerts, setAlerts] = useState<Alerts | null>(null);
|
||||
const [text, setText] = useState('');
|
||||
|
||||
useEffect(() => { invoke<Alerts>('alerts_get').then(setAlerts).catch(err => notify(getError(err), true)); }, []);
|
||||
|
||||
async function save(next: Alerts, message: string) {
|
||||
const previous = alerts;
|
||||
setAlerts(next);
|
||||
try { setAlerts(await invoke<Alerts>('alerts_set', { settings: next })); notify(message); }
|
||||
catch (err) { setAlerts(previous); notify(getError(err), true); }
|
||||
}
|
||||
function add() {
|
||||
if (!alerts) return;
|
||||
const known = new Set(alerts.keywords.map(word => word.toLowerCase()));
|
||||
const fresh = parseKeywords(text).filter(word => !known.has(word.toLowerCase()));
|
||||
if (!fresh.length) { setText(''); return; }
|
||||
const keywords = [...alerts.keywords, ...fresh].slice(0, MAX_KEYWORDS);
|
||||
setText('');
|
||||
void save({ ...alerts, keywords }, fresh.length === 1 ? t('wb.settings.alerts.watching', { word: fresh[0]! }) : t('wb.settings.alerts.watchingMore', { count: fresh.length }));
|
||||
}
|
||||
|
||||
if (!alerts) return null;
|
||||
return <Section title={t('wb.settings.alerts.title')} hint={t('wb.settings.alerts.hint')}>
|
||||
<Row label={t('wb.settings.alerts.label')} hint={alerts.enabled ? t('wb.settings.alerts.onCount', { count: alerts.keywords.length }) : t('wb.common.off')} keywords="keyword notification notify">
|
||||
<Toggle label={t('wb.settings.alerts.title')} checked={alerts.enabled} onChange={next => void save({ ...alerts, enabled: next }, next ? t('wb.settings.alerts.turnedOn') : t('wb.settings.alerts.turnedOff'))}/>
|
||||
</Row>
|
||||
<Row label={t('wb.settings.alerts.keywords')} hint={t('wb.settings.alerts.keywordsHint', { max: MAX_KEYWORDS })} keywords="alert words watch" wide>
|
||||
<div className="bt-stack">
|
||||
<ChipList items={alerts.keywords} empty={t('wb.settings.alerts.none')} onRemove={word => void save({ ...alerts, keywords: alerts.keywords.filter(item => item !== word) }, t('wb.settings.alerts.stopped', { word }))}/>
|
||||
<InputRow label={t('wb.settings.alerts.add')} placeholder="tauri, waybetter" value={text} onChange={setText} button={t('wb.common.add')} disabled={!parseKeywords(text).length || alerts.keywords.length >= MAX_KEYWORDS} onSubmit={add}/>
|
||||
</div>
|
||||
</Row>
|
||||
</Section>;
|
||||
}
|
||||
|
||||
/** Gallery folders and the opt-in clipboard history for the Media panel (Ctrl+Shift+G). Native only. */
|
||||
export function MediaSettingsRows({ notify }: { notify: Notify }) {
|
||||
const t = useT();
|
||||
const [settings, setSettings] = useState<MediaSettings | null>(null);
|
||||
useEffect(() => { invoke<MediaSettings>('media_get').then(setSettings).catch(err => notify(getError(err), true)); }, []);
|
||||
|
||||
async function save(next: MediaSettings, message?: string) {
|
||||
const previous = settings;
|
||||
setSettings(next);
|
||||
try { setSettings(await invoke<MediaSettings>('media_set', { settings: next })); if (message) notify(message); }
|
||||
catch (err) { setSettings(previous); notify(getError(err), true); }
|
||||
}
|
||||
async function addFolder() {
|
||||
try { setSettings(await invoke<MediaSettings>('gallery_add_folder')); }
|
||||
catch (err) { notify(getError(err), true); }
|
||||
}
|
||||
async function clearHistory() {
|
||||
try { await invoke('clip_remove', { id: null }); notify(t('wb.settings.media.cleared')); }
|
||||
catch (err) { notify(getError(err), true); }
|
||||
}
|
||||
|
||||
if (!settings) return null;
|
||||
return <Section title={t('wb.settings.media.title')} hint={t('wb.settings.media.hint')}>
|
||||
<Row label={t('wb.settings.media.folders')} hint={t('wb.settings.media.foldersHint')} keywords="images pictures screenshots" wide>
|
||||
<div className="bt-stack">
|
||||
<ChipList items={settings.folders} icon={FOLDER_ICON} render={folderLabel} empty={t('wb.settings.media.noFolders')}
|
||||
onRemove={folder => void save(withoutFolder(settings, folder), t('wb.settings.media.folderRemoved'))}/>
|
||||
<div><Button size="sm" onClick={() => void addFolder()} icon={<span aria-hidden="true">+</span>}>{t('wb.settings.media.addFolder')}</Button></div>
|
||||
</div>
|
||||
</Row>
|
||||
<Row label={t('wb.settings.media.clipboard')} hint={t('wb.settings.media.clipboardHint')} keywords="copy paste">
|
||||
<Toggle label={t('wb.settings.media.clipboard')} checked={settings.clipboardEnabled} onChange={next => void save({ ...settings, clipboardEnabled: next }, next ? t('wb.settings.media.clipboardOn') : t('wb.settings.media.clipboardOff'))}/>
|
||||
</Row>
|
||||
{settings.clipboardEnabled && <Row label={t('wb.settings.media.keep')} hint={t('wb.settings.media.keepHint')} keywords="clipboard size">
|
||||
<div className="bt-inline">
|
||||
<Stepper label={t('wb.settings.media.keep')} value={settings.clipboardMax} min={1} max={CLIP_MAX_LIMIT} onChange={value => void save({ ...settings, clipboardMax: clampClipMax(value) })}/>
|
||||
<Button size="sm" tone="ghost" onClick={() => void clearHistory()}>{t('wb.common.clear')}</Button>
|
||||
</div>
|
||||
</Row>}
|
||||
</Section>;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue