@tacoshell/shell 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/LICENSE +28 -0
  2. package/README.md +6 -2
  3. package/package.json +40 -4
  4. package/src/background.ts +41 -0
  5. package/src/core/bus.ts +186 -0
  6. package/src/core/cards.ts +33 -0
  7. package/src/core/cron.ts +63 -0
  8. package/src/core/cronfriendly.ts +70 -0
  9. package/src/core/csv.ts +36 -0
  10. package/src/core/datasets.ts +276 -0
  11. package/src/core/domshot.ts +81 -0
  12. package/src/core/guards.ts +36 -0
  13. package/src/core/hosts.ts +15 -0
  14. package/src/core/hotkeys.ts +44 -0
  15. package/src/core/localdata.ts +88 -0
  16. package/src/core/log.ts +91 -0
  17. package/src/core/markdown.ts +57 -0
  18. package/src/core/nav.ts +102 -0
  19. package/src/core/notifyrules.ts +31 -0
  20. package/src/core/page.ts +81 -0
  21. package/src/core/prefs.ts +114 -0
  22. package/src/core/router.ts +78 -0
  23. package/src/core/search.ts +65 -0
  24. package/src/core/services.ts +161 -0
  25. package/src/core/sessions.ts +72 -0
  26. package/src/core/startpage.ts +28 -0
  27. package/src/core/storage.ts +54 -0
  28. package/src/core/systemtools.ts +85 -0
  29. package/src/core/tabfit.ts +30 -0
  30. package/src/core/templates.ts +48 -0
  31. package/src/core/toasts.ts +13 -0
  32. package/src/core/vault.ts +208 -0
  33. package/src/env.d.ts +2 -0
  34. package/src/index.ts +56 -0
  35. package/src/styles.css +288 -0
  36. package/src/types.ts +113 -0
  37. package/src/ui/App.tsx +229 -0
  38. package/src/ui/ClearableInput.tsx +23 -0
  39. package/src/ui/Icon.tsx +8 -0
  40. package/src/ui/Markdown.tsx +24 -0
  41. package/src/ui/Rail.tsx +89 -0
  42. package/src/ui/Search.tsx +111 -0
  43. package/src/ui/Sessions.tsx +72 -0
  44. package/src/ui/SidePanel.tsx +148 -0
  45. package/src/ui/TabBar.tsx +56 -0
  46. package/src/ui/ViewHost.tsx +122 -0
  47. package/src/ui/hooks.ts +21 -0
  48. package/src/ui/settings/Datasets.tsx +162 -0
  49. package/src/ui/settings/ReleaseNotes.tsx +19 -0
  50. package/src/ui/settings/ScheduleEditor.tsx +57 -0
  51. package/src/ui/settings/Settings.tsx +328 -0
  52. package/src/ui/settings/Templates.tsx +52 -0
@@ -0,0 +1,57 @@
1
+ import { useMemo, useState } from 'react';
2
+ import { cronNext, parseCron } from '../../core/cron.ts';
3
+ import { DAYS, HOUR_STEPS, MINUTE_STEPS, MODES, describeCron, fromForm, toForm, type Form, type Mode } from '../../core/cronfriendly.ts';
4
+
5
+ const fmt = (t: number) => new Date(t).toLocaleString(undefined, { weekday: 'short', day: 'numeric', month: 'short', hour: 'numeric', minute: '2-digit' });
6
+
7
+ /** Plain-English schedule form (How often · time · days). What is saved is the crontab, shown read-only under the form; "Custom" lets an expert type one. */
8
+ export function ScheduleEditor({ title, description, current, defaultCron, onSave, onClose }: { title: string; description?: string; current: string | null; defaultCron?: string | null; onSave: (cron: string | null) => Promise<void>; onClose: () => void }) {
9
+ const [s, setS] = useState<Form>(() => toForm(current));
10
+ const [saving, setSaving] = useState(false);
11
+ const set = (patch: Partial<Form>) => setS((x) => ({ ...x, ...patch }));
12
+ const expr = fromForm(s);
13
+ const problem = useMemo(() => {
14
+ if (s.mode === 'weekly' && !s.days.length) return 'Pick at least one day.';
15
+ if (s.mode === 'custom') { if (!expr) return 'Type a crontab (5 fields).'; try { parseCron(expr); } catch (e) { return (e as Error).message; } }
16
+ return null;
17
+ }, [s, expr]);
18
+ const runs = useMemo(() => {
19
+ const out: number[] = [];
20
+ if (expr && !problem) for (let t = Date.now(), i = 0; i < 3; i++) { const n = cronNext(expr, t); if (n == null) break; out.push(n); t = n; }
21
+ return out;
22
+ }, [expr, problem]);
23
+ const save = async () => { setSaving(true); try { await onSave(expr); onClose(); } finally { setSaving(false); } };
24
+ const steps = s.mode === 'minutes' ? MINUTE_STEPS : HOUR_STEPS;
25
+ const unit = (n: number) => (s.mode === 'minutes' ? (n === 1 ? 'minute' : `${n} minutes`) : n === 1 ? 'hour' : `${n} hours`);
26
+ return (
27
+ <div className="backdrop" onMouseDown={(e) => e.target === e.currentTarget && onClose()}>
28
+ <div className="modal schedule">
29
+ <button className="close" onClick={onClose} aria-label="Close">×</button>
30
+ <h2>Schedule — {title}</h2>
31
+ {description && <p className="muted small">{description}</p>}
32
+ <div className="form-row"><label>Refresh</label>
33
+ <select aria-label="How often" value={s.mode} onChange={(e) => { const mode = e.target.value as Mode; set(mode === 'custom' ? { mode, cron: fromForm({ ...s, mode: 'daily' }) ?? s.cron } : { mode }); }}>
34
+ {MODES.map(([v, l]) => <option key={v} value={v}>{l}</option>)}
35
+ </select></div>
36
+ {(s.mode === 'minutes' || s.mode === 'hours') && <div className="form-row"><label>Every</label>
37
+ <select value={s.every} onChange={(e) => set({ every: Number(e.target.value) })}>{steps.map((n) => <option key={n} value={n}>{unit(n)}</option>)}</select></div>}
38
+ {s.mode === 'hours' && <div className="form-row"><label>At</label>
39
+ <select value={s.minute} onChange={(e) => set({ minute: Number(e.target.value) })}>{[...new Set([0, 5, 10, 15, 20, 30, 45, s.minute])].sort((a, b) => a - b).map((n) => <option key={n} value={n}>:{String(n).padStart(2, '0')} past the hour</option>)}</select></div>}
40
+ {['daily', 'weekdays', 'weekly', 'monthly'].includes(s.mode) && <div className="form-row"><label>At</label><input type="time" value={s.time} onChange={(e) => set({ time: e.target.value || '02:00' })} /></div>}
41
+ {s.mode === 'weekly' && <div className="form-row"><label>On</label><div className="days">{DAYS.map((d, i) => (
42
+ <label key={d} className="inline"><input type="checkbox" checked={s.days.includes(i)} onChange={(e) => set({ days: DAYS.map((_, k) => k).filter((k) => (k === i ? e.target.checked : s.days.includes(k))) })} /> {d}</label>))}</div></div>}
43
+ {s.mode === 'monthly' && <div className="form-row"><label>Day of the month</label><input type="number" min={1} max={28} value={s.day} style={{ width: 80 }} onChange={(e) => set({ day: Number(e.target.value) || 1 })} /> <span className="muted small">(1–28)</span></div>}
44
+ {s.mode === 'custom' && <div className="form-row"><label>Crontab</label><input value={s.cron} placeholder="*/30 * * * *" spellCheck={false} style={{ fontFamily: 'var(--taco-font-mono)' }} onChange={(e) => set({ cron: e.target.value })} /></div>}
45
+ <p><strong>{problem ? `⚠ ${problem}` : describeCron(expr)}</strong></p>
46
+ <p className="muted small">{runs.length ? `Next runs: ${runs.map(fmt).join(' · ')}` : s.mode === 'manual' ? 'No schedule: refresh it yourself whenever you need to.' : ''}</p>
47
+ <p className="muted small mono">Saved as crontab: {expr || '(none: manual)'}</p>
48
+ <p className="muted small">Runs only while this app is open and the vault is unlocked; a run missed while locked starts as soon as you unlock. Times are local.</p>
49
+ <div className="actions">
50
+ {defaultCron !== undefined && <button onClick={() => setS(toForm(defaultCron))} title="Go back to the schedule the developer shipped">Use the default</button>}
51
+ <button onClick={onClose}>Cancel</button>
52
+ <button className="primary" disabled={!!problem || saving} onClick={() => void save()}>Save schedule</button>
53
+ </div>
54
+ </div>
55
+ </div>
56
+ );
57
+ }
@@ -0,0 +1,328 @@
1
+ import { useRef, useState } from 'react';
2
+ import { clash, comboOf, effective, formatCombo, FRAMEWORK_HOTKEYS, type HotkeyDef } from '../../core/hotkeys.ts';
3
+ import { clearAll, collections, download, exportSetup, importSetup } from '../../core/localdata.ts';
4
+ import * as log from '../../core/log.ts';
5
+ import { settings, updateSettings } from '../../core/prefs.ts';
6
+ import { href } from '../../core/router.ts';
7
+ import * as services from '../../core/services.ts';
8
+ import { toast } from '../../core/toasts.ts';
9
+ import * as vault from '../../core/vault.ts';
10
+ import { appDefaultOf, START_AUTO, startHash } from '../../core/startpage.ts';
11
+ import { firstFeatured, buildNav, pageTitle, hasReports } from '../../core/nav.ts';
12
+ import { serviceKey, viewKey, type AuthMode, type RegistryService, type RegistryView } from '../../types.ts';
13
+ import { useShell, useStore } from '../hooks.ts';
14
+ import { Markdown } from '../Markdown.tsx';
15
+
16
+ const MODE_LABEL: Record<AuthMode, string> = { session: 'Browser session', apikey: 'API key', basic: 'HTTP Basic', oauth: 'OAuth (PKCE)' };
17
+ const vaultStore = { get: vault.status, subscribe: (fn: () => void) => vault.subscribe(fn) };
18
+
19
+ export function GettingStarted() {
20
+ const { registry } = useShell();
21
+ const status = useStore(vaultStore);
22
+ const [pass, setPass] = useState('');
23
+ const [again, setAgain] = useState('');
24
+ const [busy, setBusy] = useState(false);
25
+ const min = registry.settings.vault.minPassphraseLength;
26
+ const create = async () => {
27
+ if (pass !== again) return toast("The passphrases don't match.", 'error');
28
+ setBusy(true);
29
+ try { await vault.create(pass, { minLength: min, iterations: registry.settings.vault.kdf.iterations }); log.add('info', 'Vault created', undefined, 'Settings'); toast('Vault created.'); }
30
+ catch (e) { toast((e as Error).message, 'error'); }
31
+ finally { setBusy(false); }
32
+ };
33
+ return (
34
+ <div className="page">
35
+ <h1>Getting Started</h1>
36
+ <div className="card">
37
+ <h2>1 · Create the vault</h2>
38
+ {status === 'uninitialized' ? (
39
+ <>
40
+ <p className="muted">The vault encrypts every token and password on this computer. There is no recovery if you forget the passphrase.</p>
41
+ <div className="form-row"><input type="password" placeholder={`Passphrase (at least ${min} characters)`} value={pass} onChange={(e) => setPass(e.target.value)} /></div>
42
+ <div className="form-row"><input type="password" placeholder="Repeat passphrase" value={again} onChange={(e) => setAgain(e.target.value)} onKeyDown={(e) => e.key === 'Enter' && void create()} /></div>
43
+ <button className="primary" disabled={busy || !pass} onClick={() => void create()}>{busy ? 'Creating…' : 'Create vault'}</button>
44
+ </>
45
+ ) : <p>✓ The vault exists ({status}).</p>}
46
+ </div>
47
+ <div className="card">
48
+ <h2>2 · Set up services</h2>
49
+ <p className="muted">Open <a href={href.settings('services')}>Settings → Services</a> and fill in each service you use.</p>
50
+ </div>
51
+ {registry.gettingStartedText && <div className="card"><Markdown text={registry.gettingStartedText} /></div>}
52
+ </div>
53
+ );
54
+ }
55
+
56
+ function statusOf(s: RegistryService) {
57
+ const st = services.stateOf(s);
58
+ if (!st.enabled) return { cls: 'off', text: 'Off' };
59
+ if (!services.isConfigured(s)) return { cls: 'warn', text: 'Not set up' };
60
+ if (st.lastTest && !st.lastTest.ok) return { cls: 'bad', text: 'Test failed' };
61
+ return { cls: 'ok', text: st.lastTest?.ok ? 'Connected' : 'Set up' };
62
+ }
63
+
64
+ /** Settings → Services: uniform tiles; each opens the service's own page (ADR-032). */
65
+ export function ServicesList() {
66
+ const { registry } = useShell();
67
+ useStore(services.states);
68
+ useStore(vaultStore);
69
+ return (
70
+ <div className="page">
71
+ <h1>Services</h1>
72
+ {!registry.services.length && <p className="muted">This app has no services yet. Add one with <code>taco-cli add component --type=service</code>.</p>}
73
+ <div className="tiles">
74
+ {registry.services.map((s) => { const st = statusOf(s); return (
75
+ <a key={serviceKey(s)} className="tile" href={href.settings('services', s.type, s.name)}>
76
+ <strong>{s.label}</strong><span className="muted small">{serviceKey(s)} · {s.module}</span><span className={`pill ${st.cls}`}>{st.text}</span>
77
+ </a>
78
+ ); })}
79
+ </div>
80
+ </div>
81
+ );
82
+ }
83
+
84
+ function SecretInput({ s, field, label }: { s: RegistryService; field: string; label: string }) {
85
+ const [value, setValue] = useState('');
86
+ const set = services.isConfigured(s) || vault.has(services.secretId(s, field));
87
+ const save = async () => { await vault.put(services.secretId(s, field), value); setValue(''); toast(`${label} saved in the vault.`); await services.update(s, {}); };
88
+ return (
89
+ <div className="form-row">
90
+ <label>{label}</label>
91
+ <input type="password" placeholder={vault.has(services.secretId(s, field)) ? '•••• saved (type to replace)' : 'Not set'} value={value} onChange={(e) => setValue(e.target.value)} />
92
+ <button disabled={!value} onClick={() => void save()}>Save</button>
93
+ {set && <span className="muted small">stored encrypted</span>}
94
+ </div>
95
+ );
96
+ }
97
+
98
+ /** Level 3: Settings → Services → <service>, generated from the declaration (ADR-032). */
99
+ export function ServicePage({ type, name }: { type: string; name: string }) {
100
+ const { registry } = useShell();
101
+ useStore(services.states);
102
+ useStore(vaultStore);
103
+ const s = services.find(type, name);
104
+ const [busy, setBusy] = useState(false);
105
+ if (!s) return <div className="page"><h1>Not found</h1><p className="muted">No service {type}/{name} in this app.</p></div>;
106
+ const st = services.stateOf(s);
107
+ const status = statusOf(s);
108
+ const run = async (what: () => Promise<unknown>) => { setBusy(true); try { await what(); } catch (e) { toast((e as Error).message, 'error'); } finally { setBusy(false); } };
109
+ return (
110
+ <div className="page">
111
+ <p className="crumbs"><a href={href.settings('services')}>Services</a> › {s.label}</p>
112
+ <h1>{s.label} <span className={`pill ${status.cls}`}>{status.text}</span></h1>
113
+ <p className="muted">{serviceKey(s)} · from {s.module} · hosts: {s.hosts.join(', ') || 'none'}</p>
114
+ <div className="card">
115
+ <div className="form-row"><label>Enabled</label><input type="checkbox" checked={st.enabled} onChange={(e) => void services.update(s, { enabled: e.target.checked })} /></div>
116
+ {s.auth.length > 1 && (
117
+ <div className="form-row"><label>Sign-in</label>
118
+ <div className="segmented">{s.auth.map((m) => <button key={m} className={st.mode === m ? 'on' : ''} onClick={() => void services.update(s, { mode: m })}>{MODE_LABEL[m]}</button>)}</div>
119
+ </div>
120
+ )}
121
+ {services.fieldsFor(s, st.mode).map((f) => f.secret
122
+ ? <SecretInput key={f.key} s={s} field={f.key} label={f.label ?? f.key} />
123
+ : (
124
+ <div className="form-row" key={f.key}>
125
+ <label>{f.label ?? f.key}</label>
126
+ <input defaultValue={st.config[f.key] ?? ''} placeholder={f.placeholder} onBlur={(e) => void services.update(s, { config: { ...services.stateOf(s).config, [f.key]: e.target.value.trim() } })} />
127
+ </div>
128
+ ))}
129
+ {st.mode === 'session' && (
130
+ <>
131
+ <p className="muted small">Uses your signed-in browser session for {s.hosts.join(', ')}. Sign in there first.</p>
132
+ <div className="form-row"><label>Show in Sessions</label><input type="checkbox" checked={!st.hideFromSessions} onChange={(e) => void services.update(s, { hideFromSessions: !e.target.checked })} />
133
+ <span className="muted small">The header's Sessions menu lists this service and warns when its session is missing. Hide it once it is connected and you don't need the reminder.</span></div>
134
+ </>
135
+ )}
136
+ {st.mode === 'oauth' && (
137
+ <div className="oauth">
138
+ <div className="form-row"><label>Redirect URL</label><code className="copy">{services.redirectUrl(s, registry.app.extensionId)}</code></div>
139
+ <p className="muted small">Register this exact URL with the provider as a <strong>public</strong> client (no secret), then Connect.</p>
140
+ <button disabled={busy} onClick={() => void run(() => services.connectOAuth(s))}>{vault.has(services.secretId(s, 'accessToken')) ? 'Reconnect' : 'Connect'}</button>
141
+ </div>
142
+ )}
143
+ <div className="actions"><button className="primary" disabled={busy || !st.enabled} onClick={() => void run(async () => { const r = await services.test(s); toast(r.detail, r.ok ? 'info' : 'error'); })}>Test</button>
144
+ {st.lastTest && <span className="muted small">Last test {new Date(st.lastTest.at).toLocaleString()}: {st.lastTest.detail}</span>}</div>
145
+ </div>
146
+ <div className="card"><h2>How to set it up</h2><Markdown text={s.howToText} /></div>
147
+ </div>
148
+ );
149
+ }
150
+
151
+ const Section = ({ title, children, intro }: { title: string; intro?: string; children: React.ReactNode }) => (
152
+ <div className="card"><h2>{title}</h2>{intro && <p className="muted small">{intro}</p>}{children}</div>
153
+ );
154
+
155
+ function HotkeyRow({ def }: { def: HotkeyDef }) {
156
+ const cfg = useStore(settings);
157
+ const [recording, setRecording] = useState(false);
158
+ const combo = effective(def, cfg.hotkeys.map);
159
+ const save = (next: string) => void updateSettings({ hotkeys: { ...cfg.hotkeys, map: { ...cfg.hotkeys.map, [def.id]: next } } });
160
+ const record = (e: React.KeyboardEvent) => {
161
+ e.preventDefault();
162
+ if (e.key === 'Escape') return setRecording(false);
163
+ const c = comboOf(e.nativeEvent);
164
+ if (!c) return;
165
+ const other = clash(def.id, c, cfg.hotkeys.map);
166
+ if (other) { toast(`${formatCombo(c)} is already "${other.label}".`, 'error'); return; }
167
+ save(c);
168
+ setRecording(false);
169
+ };
170
+ return (
171
+ <tr>
172
+ <td>{def.label}</td>
173
+ <td>{recording ? <input autoFocus className="hotkey-rec" placeholder="Press keys… (Esc cancels)" onKeyDown={record} onBlur={() => setRecording(false)} readOnly /> : <kbd>{formatCombo(combo)}</kbd>}</td>
174
+ <td><button onClick={() => setRecording(true)}>Change</button> <button onClick={() => save('')}>None</button> {def.id in cfg.hotkeys.map && <button onClick={() => { const { [def.id]: _, ...rest } = cfg.hotkeys.map; void updateSettings({ hotkeys: { ...cfg.hotkeys, map: rest } }); }}>Default ({formatCombo(def.default)})</button>}</td>
175
+ </tr>
176
+ );
177
+ }
178
+
179
+ /** Settings → Configuration: the user's platform preferences (from v2 Settings › User Configuration). */
180
+ /** What a start-page value is called in Settings: "Auto", "Home", "Reports" or a view's page title. */
181
+ function startLabel(reg: ReturnType<typeof useShell>['registry'], value: string): string {
182
+ if (value === START_AUTO) return 'Auto (the first Featured action)';
183
+ if (value === 'home') return 'Home';
184
+ if (value === 'reports') return 'Reports';
185
+ const v = reg.views.find((x) => viewKey(x) === value);
186
+ return v ? pageTitle(reg, v) : `${value} (no longer in this app)`;
187
+ }
188
+
189
+ /** Settings → Configuration → Start page (ADR-064): the developer's default is in taco.json; the user may pick another page or go back to the app's default. */
190
+ function StartPage() {
191
+ const { registry } = useShell();
192
+ const cfg = useStore(settings);
193
+ const appDefault = appDefaultOf(registry);
194
+ const nav = buildNav(registry, () => true);
195
+ const byBucket = (label: string, views: RegistryView[]) => views.length ? <optgroup key={label} label={label}>{views.map((v) => <option key={viewKey(v)} value={viewKey(v)}>{pageTitle(registry, v)}</option>)}</optgroup> : null;
196
+ const home = registry.views.filter((v) => (v.nav.section ?? 'home') === 'home');
197
+ const opens = startHash(registry, firstFeatured(nav), cfg.startPage, appDefault);
198
+ const where = (() => { const r = opens.match(/^#\/v\/([^/]+)\/([^/]+)$/); const v = r && registry.views.find((x) => x.module === decodeURIComponent(r[1]) && x.name === decodeURIComponent(r[2])); return v ? pageTitle(registry, v) : opens === '#/reports' ? 'Reports' : 'Home'; })();
199
+ return (
200
+ <Section title="Start page" intro="The page the app opens on (after the vault is unlocked). The app ships a default; choose another here, or go back to the app's default.">
201
+ <div className="form-row"><label>Open on</label>
202
+ <select value={cfg.startPage ?? ''} onChange={(e) => void updateSettings({ startPage: e.target.value || null })}>
203
+ <option value="">App default: {startLabel(registry, appDefault)}</option>
204
+ <option value={START_AUTO}>{startLabel(registry, START_AUTO)}</option>
205
+ <option value="home">Home</option>
206
+ {hasReports(nav) && <option value="reports">Reports</option>}
207
+ {byBucket('Featured actions', home.filter((v) => v.nav.bucket === 'featured'))}
208
+ {byBucket('Tools', home.filter((v) => v.nav.bucket === 'tools'))}
209
+ {byBucket('Services', home.filter((v) => v.nav.bucket === 'services'))}
210
+ {byBucket('Reports', registry.views.filter((v) => (v.nav.section ?? 'home') === 'reports'))}
211
+ </select>
212
+ {cfg.startPage !== null && <button onClick={() => void updateSettings({ startPage: null })}>Use the app default</button>}
213
+ </div>
214
+ <p className="muted small">Opens on: <strong>{where}</strong>{cfg.startPage === null ? ' (the app default)' : ' (your choice)'}. Until you create a vault, the app always opens on Getting Started.</p>
215
+ </Section>
216
+ );
217
+ }
218
+
219
+ export function Configuration() {
220
+ const { registry } = useShell();
221
+ const cfg = useStore(settings);
222
+ const n = cfg.notifications;
223
+ const setN = (patch: Partial<typeof n>) => void updateSettings({ notifications: { ...n, ...patch } });
224
+ const setItem = (key: string, on: boolean) => setN({ items: { ...n.items, [key]: on } });
225
+ const test = () => {
226
+ if (typeof chrome !== 'undefined' && chrome.notifications?.create) chrome.notifications.create(`taco:test:${Date.now()}`, { type: 'basic', iconUrl: 'icons/icon-128.png', title: registry.app.displayName, message: 'This is how notifications look.', requireInteraction: n.sticky });
227
+ toast('This is how notifications look.', 'info', 'Test notification');
228
+ };
229
+ return (
230
+ <div className="page">
231
+ <h1>Configuration</h1>
232
+ <Section title="Appearance">
233
+ <div className="form-row"><label>Color theme</label>
234
+ <div className="segmented">{(['dark', 'light', 'system'] as const).map((t) => <button key={t} className={cfg.theme === t ? 'on' : ''} onClick={() => void updateSettings({ theme: t })}>{t === 'dark' ? <><i className="fa-solid fa-moon" /> Dark</> : t === 'light' ? <><i className="fa-solid fa-sun" /> Light</> : <><i className="fa-solid fa-circle-half-stroke" /> System</>}</button>)}</div>
235
+ </div>
236
+ <p className="muted small">Applies immediately. An app theme's colors apply on top of either mode.</p>
237
+ </Section>
238
+ <StartPage />
239
+ <Section title="Vault">
240
+ <div className="form-row"><label>Confirm before locking</label><input type="checkbox" checked={cfg.confirmLock} onChange={(e) => void updateSettings({ confirmLock: e.target.checked })} /><span className="muted small">Ask "Lock the vault?" when you press the Vault button in the header.</span></div>
241
+ </Section>
242
+ <Section title="Notifications" intro="Every notification is also listed in the Activity Log (Levels ▾ → Notifications only). Nothing notifies while the vault is locked.">
243
+ <div className="form-row"><label>All notifications</label><input type="checkbox" checked={n.enabled} onChange={(e) => setN({ enabled: e.target.checked })} /></div>
244
+ <div className="form-row"><label>Only when I'm away</label><input type="checkbox" checked={n.onlyWhenAway} onChange={(e) => setN({ onlyWhenAway: e.target.checked })} /><span className="muted small">Chrome notifications only while this app isn't the window in front (the in-app message always shows).</span></div>
245
+ <div className="form-row"><label>Quiet hours</label><input type="time" value={n.quietFrom} onChange={(e) => setN({ quietFrom: e.target.value })} /> to <input type="time" value={n.quietTo} onChange={(e) => setN({ quietTo: e.target.value })} />{(n.quietFrom || n.quietTo) && <button onClick={() => setN({ quietFrom: '', quietTo: '' })}>Clear</button>}</div>
246
+ <div className="form-row"><label>Keep on screen</label><input type="checkbox" checked={n.sticky} onChange={(e) => setN({ sticky: e.target.checked })} /><span className="muted small">Until dismissed (on macOS, Chrome's notification style must be "Alerts").</span></div>
247
+ <div className="form-row"><label>Toolbar badge</label><input type="checkbox" checked={n.badge} onChange={(e) => setN({ badge: e.target.checked })} /><span className="muted small">Count unseen notifications on the toolbar icon.</span></div>
248
+ <div className="actions"><button onClick={test}><i className="fa-regular fa-bell" /> Send a test notification</button></div>
249
+ <h3>Per notification</h3>
250
+ {!registry.notifications.length && <p className="muted small">No module declares notifications.</p>}
251
+ {registry.notifications.map((d) => { const key = `${d.module}/${d.id}`; return (
252
+ <div className="form-row" key={key}><label>{d.label}</label>
253
+ <input type="checkbox" disabled={!n.enabled} checked={n.items[key] ?? d.default === 'enabled'} onChange={(e) => setItem(key, e.target.checked)} />
254
+ <span className="muted small">{d.description ?? ''} ({d.module}, {d.delivery})</span></div>
255
+ ); })}
256
+ </Section>
257
+ <Section title="HotKeys" intro="⌘ is Ctrl outside macOS. Click Change, then press the new combination.">
258
+ <div className="form-row"><label>HotKeys on</label><input type="checkbox" checked={cfg.hotkeys.enabled} onChange={(e) => void updateSettings({ hotkeys: { ...cfg.hotkeys, enabled: e.target.checked } })} /></div>
259
+ <table className="keys"><tbody>{FRAMEWORK_HOTKEYS.map((d) => <HotkeyRow key={d.id} def={d} />)}</tbody></table>
260
+ </Section>
261
+ <Section title="Activity Log">
262
+ <p className="muted small">Levels shown by default are chosen in the log itself (Levels ▾); the choice is remembered here: {cfg.visibleLevels.join(', ') || 'none'}.</p>
263
+ </Section>
264
+ </div>
265
+ );
266
+ }
267
+
268
+ /** Settings → Vault & Data (from v2's Vault Configuration, Share setup, Manage Local Data, Clear All Local Data). */
269
+ export function VaultAndData() {
270
+ const { registry } = useShell();
271
+ const status = useStore(vaultStore);
272
+ const cfg = useStore(settings);
273
+ const [cur, setCur] = useState(''); const [next, setNext] = useState(''); const [again, setAgain] = useState('');
274
+ const [confirming, setConfirming] = useState<string | null>(null);
275
+ const [changing, setChanging] = useState(false);
276
+ const inv = vault.inventory();
277
+ const change = async () => {
278
+ if (next !== again) return toast("The new passphrases don't match.", 'error');
279
+ setChanging(true);
280
+ try { if (await vault.changePassphrase(cur, next, { minLength: registry.settings.vault.minPassphraseLength })) { toast('Passphrase changed.'); log.add('info', 'Vault passphrase changed', undefined, 'Settings'); setCur(''); setNext(''); setAgain(''); } else toast("The current passphrase isn't right.", 'error'); }
281
+ catch (e) { toast((e as Error).message, 'error'); }
282
+ finally { setChanging(false); }
283
+ };
284
+ const fileInput = useRef<HTMLInputElement>(null);
285
+ const importFile = async (f: File | undefined) => {
286
+ if (!f) return;
287
+ try { const applied = await importSetup(registry, JSON.parse(await f.text())); toast(`Imported: ${applied.join(', ') || 'nothing matched this app'}.`); }
288
+ catch (e) { toast(`Import failed: ${(e as Error).message}`, 'error'); }
289
+ if (fileInput.current) fileInput.current.value = '';
290
+ };
291
+ const danger = async (what: string, run: () => Promise<void>) => { if (confirming !== what) return setConfirming(what); setConfirming(null); await run(); };
292
+ return (
293
+ <div className="page">
294
+ <h1>Vault &amp; Data</h1>
295
+ <Section title="Vault" intro="AES-GCM 256 with a key derived from your passphrase (PBKDF2, 600,000 rounds). The passphrase is never stored; if you forget it, reset the vault and re-enter your secrets.">
296
+ <p>Status: <strong>{status}</strong> · {inv.secrets.length} secret(s) · {inv.moduleData.length} module data item(s)</p>
297
+ {inv.secrets.length > 0 && <p className="muted small">{inv.secrets.join(', ')}</p>}
298
+ <div className="form-row"><label>Lock after no activity</label>
299
+ <select value={cfg.idleLockMinutes} onChange={(e) => void updateSettings({ idleLockMinutes: Number(e.target.value) })}>{[5, 10, 15, 30, 60, 0].map((m) => <option key={m} value={m}>{m ? `${m} minutes` : 'Never'}</option>)}</select>
300
+ {status === 'unlocked' && <button disabled={changing} onClick={() => void vault.lock()}><i className="fa-solid fa-lock" /> Lock now</button>}
301
+ </div>
302
+ {status !== 'uninitialized' && (<>
303
+ <h3>Change passphrase</h3>
304
+ <div className="form-row"><input type="password" placeholder="Current passphrase" value={cur} onChange={(e) => setCur(e.target.value)} /></div>
305
+ <div className="form-row"><input type="password" placeholder="New passphrase" value={next} onChange={(e) => setNext(e.target.value)} /></div>
306
+ <div className="form-row"><input type="password" placeholder="Repeat new passphrase" value={again} onChange={(e) => setAgain(e.target.value)} /><button disabled={!cur || !next || changing} onClick={() => void change()}>{changing ? 'Changing…' : 'Change passphrase'}</button></div>
307
+ <div className="actions"><button className="danger" onClick={() => void danger('vault', async () => { await vault.destroy(); log.add('warn', 'Vault reset', undefined, 'Settings'); toast('Vault reset.'); })}>{confirming === 'vault' ? 'Click again to delete every secret and module data' : 'Reset vault…'}</button></div>
308
+ </>)}
309
+ </Section>
310
+ <Section title="Share setup" intro="Export your service settings (sign-in modes, site names, which services are on) and configuration for a teammate. Secrets are never exported.">
311
+ <div className="actions">
312
+ <button onClick={() => download(`${registry.app.name}-setup.json`, exportSetup(registry))}><i className="fa-solid fa-file-export" /> Export setup</button>
313
+ <button onClick={() => fileInput.current?.click()}><i className="fa-solid fa-file-import" /> Import setup</button>
314
+ <input ref={fileInput} type="file" accept="application/json" hidden onChange={(e) => void importFile(e.target.files?.[0])} />
315
+ </div>
316
+ </Section>
317
+ <Section title="Manage local data" intro="What this app keeps in this browser besides the vault. Clearing one collection leaves the others alone.">
318
+ <table className="keys"><tbody>{collections.map((c) => (
319
+ <tr key={c.id}><td><strong>{c.label}</strong><div className="muted small">{c.description}</div></td>
320
+ <td><button className={c.caution ? 'danger' : ''} onClick={() => void danger(c.id, async () => { await c.clear(); toast(`${c.label} cleared.`); log.add('info', `Local data cleared: ${c.label}`, undefined, 'Settings'); })}>{confirming === c.id ? 'Click again to clear' : 'Clear'}</button></td></tr>
321
+ ))}</tbody></table>
322
+ </Section>
323
+ <Section title="Clear all local data" intro="Removes everything this app stored in this browser: the vault (secrets and module data), service settings, configuration, favorites and the Activity Log. The app starts over at Getting Started.">
324
+ <button className="danger" onClick={() => void danger('all', async () => { await clearAll(); location.hash = '#/settings/getting-started'; location.reload(); })}>{confirming === 'all' ? 'Click again to clear everything' : 'Clear all local data…'}</button>
325
+ </Section>
326
+ </div>
327
+ );
328
+ }
@@ -0,0 +1,52 @@
1
+ import { useEffect, useState } from 'react';
2
+ import { href } from '../../core/router.ts';
3
+ import * as templates from '../../core/templates.ts';
4
+ import { toast } from '../../core/toasts.ts';
5
+ import * as vault from '../../core/vault.ts';
6
+ import type { RegistryTemplate } from '../../types.ts';
7
+ import { useShell, useStore } from '../hooks.ts';
8
+
9
+ const vaultStore = { get: vault.status, subscribe: (fn: () => void) => vault.subscribe(fn) };
10
+
11
+ function TemplateCard({ t }: { t: RegistryTemplate }) {
12
+ const [cur, setCur] = useState<templates.Resolved | null>(null);
13
+ const [text, setText] = useState('');
14
+ const [busy, setBusy] = useState(false);
15
+ useEffect(() => { void templates.get(t).then((r) => { setCur(r); setText(r.value); }); }, [t]);
16
+ if (!cur) return <details className="card"><summary><strong>{t.label}</strong></summary></details>;
17
+ const err = templates.validateEdit(t, text);
18
+ const run = async (what: () => Promise<void>) => { setBusy(true); try { await what(); } catch (e) { toast((e as Error).message, 'error'); } finally { setBusy(false); } };
19
+ const save = () => run(async () => { await templates.save(t, text); setCur(await templates.get(t)); toast(`${t.label} saved`); });
20
+ const reset = () => run(async () => { await templates.reset(t); setCur({ value: t.value, edited: false }); setText(t.value); toast(`${t.label} reset to the default`); });
21
+ return (
22
+ <details className="card template">
23
+ <summary><strong>{t.label}</strong> <span className="muted small">{t.module}/{t.name}</span> <span className={`pill ${cur.edited ? 'warn' : ''}`}>{cur.edited ? 'Edited' : 'Default'}</span></summary>
24
+ {t.description && <p className="muted small">{t.description}</p>}
25
+ <p className="small"><span className="muted">Tokens:</span> {t.tokens.length ? t.tokens.map((k) => <code key={k} className="token">{'${' + k + '}'}</code>) : <span className="muted">none</span>}</p>
26
+ <textarea value={text} rows={Math.min(14, Math.max(3, text.split('\n').length + 1))} spellCheck onChange={(e) => setText(e.target.value)} />
27
+ {err && <p className="error small">{err}</p>}
28
+ <div className="actions">
29
+ <button className="primary" disabled={busy || !!err || text === cur.value} onClick={() => void save()}>Save</button>
30
+ {cur.edited && <button disabled={busy} onClick={() => void reset()}>Reset to default</button>}
31
+ {cur.edited && cur.updatedAt && <span className="muted small">edited {new Date(cur.updatedAt).toLocaleString()}</span>}
32
+ </div>
33
+ </details>
34
+ );
35
+ }
36
+
37
+ /** Settings → Templates (v2 FR-TPL-1): reword the developer-shipped texts. Edits are stored encrypted in the vault; nothing can be added or deleted. */
38
+ export function TemplatesPage() {
39
+ const { registry } = useShell();
40
+ const status = useStore(vaultStore);
41
+ const list = registry.templates ?? [];
42
+ return (
43
+ <div className="page">
44
+ <h1>Templates</h1>
45
+ <p className="muted">Templates are shipped with the app; change the wording here. Use only the <code>{'${tokens}'}</code> each one lists: you can re-use or leave them out, but not invent new ones.</p>
46
+ {!list.length && <p className="muted">No module in this app declares a template. Add one with <code>taco-cli add component --type=template</code>.</p>}
47
+ {status === 'uninitialized' && list.length > 0 && <div className="card">Create the vault first: <a href={href.settings('getting-started')}>Getting Started</a>.</div>}
48
+ {status === 'locked' && list.length > 0 && <div className="card">Unlock the vault to edit templates: your edits are stored encrypted inside it. <button className="primary" onClick={() => void vault.whenUnlocked()}><i className="fa-solid fa-lock-open" /> Unlock</button></div>}
49
+ {status === 'unlocked' && list.map((t) => <TemplateCard key={templates.idOf(t)} t={t} />)}
50
+ </div>
51
+ );
52
+ }