@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
package/src/types.ts ADDED
@@ -0,0 +1,113 @@
1
+ // The registry the CLI generates (`.taco/generated/registry.json`) and the shell reads. Keep in step with packages/cli/src/lib/build.ts.
2
+
3
+ export type AuthMode = 'session' | 'apikey' | 'basic' | 'oauth';
4
+ export type Bucket = 'featured' | 'tools' | 'services';
5
+
6
+ /** Font Awesome classes, or a bundled image (a data: URI embedded by the CLI). */
7
+ export type RegistryIcon = { fa: string } | { img: string };
8
+
9
+ export interface FieldDecl { key: string; label?: string; secret?: boolean; modes?: AuthMode[]; placeholder?: string; required?: boolean }
10
+ export interface TopicDecl { visibility?: 'public' | 'protected'; event?: boolean }
11
+
12
+ export interface RegistryService {
13
+ module: string;
14
+ name: string;
15
+ type: string;
16
+ label: string;
17
+ auth: AuthMode[];
18
+ hosts: string[];
19
+ fields?: FieldDecl[];
20
+ /** `{field}` placeholders are filled from the service's config (e.g. `https://{subdomain}.zendesk.com/oauth/authorizations/new`). */
21
+ oauth?: { authorizeUrl: string; tokenUrl: string; scopes?: string[] };
22
+ apiKey?: { header?: string; prefix?: string };
23
+ topics?: Record<string, TopicDecl>;
24
+ /** Present when the service opts in to header search (its implementation then has `resolve`). */
25
+ resolver?: { label: string; hint?: string };
26
+ icon?: RegistryIcon;
27
+ sessionRequirement?: 'required' | 'recommended' | 'optional';
28
+ howToText?: string;
29
+ }
30
+
31
+ export interface RegistryView {
32
+ module: string;
33
+ name: string;
34
+ label: string;
35
+ viewType: string;
36
+ nav: { section?: 'home' | 'reports'; bucket: Bucket; group?: string; feature?: string };
37
+ helpText?: string;
38
+ /** Services this view needs (from its module's non-optional `uses`, or the view's own `requires`). */
39
+ requires: { type: string; name: string }[];
40
+ /** The context it accepts (ADR-052): `{ "slug": "string", "ticket": "number?" }`. */
41
+ context?: Record<string, string>;
42
+ /** Slots other modules can contribute panels to (ADR-053). */
43
+ slots?: Record<string, { label?: string }>;
44
+ /** System tools for the Tools menu (ADR-054): which ones, and which DIVs Copy Chart may pick (default: every div). */
45
+ tools?: { system?: string[]; selector?: string };
46
+ /** Tiles offered for a resolved search context of a service type; `map` renames context keys (view key → resolved key). */
47
+ quickActions?: QuickActionDecl[];
48
+ icon?: RegistryIcon;
49
+ /** Turn the 3rd-level bar's Favorite / Refresh buttons off for this view (both default to on). */
50
+ favorite?: boolean;
51
+ refresh?: boolean;
52
+ /** false = no cards on this view (default true). */
53
+ cards?: boolean;
54
+ }
55
+
56
+ export interface QuickActionDecl { service: string; label?: string; icon?: string; map?: Record<string, string> }
57
+
58
+ /** A panel one module contributes into another view's slot (ADR-053). */
59
+ export interface RegistryPanel {
60
+ module: string;
61
+ name: string;
62
+ label: string;
63
+ into: { module: string; view: string; slot: string };
64
+ requires: { type: string; name: string }[];
65
+ }
66
+
67
+ /** A card (ADR-062): wired to page-context entries, shown on any view whose page context satisfies them. */
68
+ export interface RegistryCard { module: string; name: string; label: string; context: Record<string, string>; icon?: RegistryIcon; order: number; collapsed: boolean; requires: { type: string; name: string }[] }
69
+
70
+ /** A dataset (ADR-043). `schema` types: string · integer · number · boolean · date · timestamp · list · json. */
71
+ export interface RegistryDataset {
72
+ module: string;
73
+ name: string;
74
+ label: string;
75
+ kind: 'importOnly' | 'refreshable';
76
+ key?: string;
77
+ schema?: Record<string, string>;
78
+ instructionsText?: string;
79
+ /** Who may use the set / delete topics: only the dataset's own module (default), or any module. */
80
+ writes: 'module' | 'public';
81
+ /** The developer's default refresh schedule (refreshable only); the user's choice, saved in the dataset state, wins. */
82
+ schedule?: { cron: string };
83
+ }
84
+
85
+ /** Developer-shipped text the user may reword in Settings → Templates; an edit may only use the declared tokens. */
86
+ export interface RegistryTemplate { module: string; name: string; label: string; description: string; tokens: string[]; value: string }
87
+
88
+ export interface RegistryNotification { module: string; id: string; label: string; description?: string; default: 'enabled' | 'disabled'; delivery: 'toast' | 'system' | 'both' }
89
+
90
+ export interface Registry {
91
+ app: { name: string; displayName: string; version: string; extensionId: string; framework: string };
92
+ modules: { id: string; version: string; origin: string }[];
93
+ services: RegistryService[];
94
+ views: RegistryView[];
95
+ datasets: RegistryDataset[];
96
+ notifications: RegistryNotification[];
97
+ templates?: RegistryTemplate[];
98
+ panels?: RegistryPanel[];
99
+ cards?: RegistryCard[];
100
+ gettingStartedText?: string;
101
+ releaseNotesText?: string;
102
+ sectionIcons?: Partial<Record<'home' | 'reports' | 'settings', RegistryIcon>>;
103
+ settings: {
104
+ /** The developer's default start page ("auto" | "home" | "reports" | "<module>/<view>"); the user can override it (ADR-064). */
105
+ startPage?: string;
106
+ vault: { idleLockMinutes: number; minPassphraseLength: number; kdf: { iterations: number } };
107
+ activityLog: { visibleLevels: string[]; retentionEntries: number };
108
+ notifications: { defaultDelivery: string };
109
+ };
110
+ }
111
+
112
+ export const viewKey = (v: { module: string; name: string }) => `${v.module}/${v.name}`;
113
+ export const serviceKey = (s: { type: string; name: string }) => `${s.type}/${s.name}`;
package/src/ui/App.tsx ADDED
@@ -0,0 +1,229 @@
1
+ import { useEffect, useMemo, useRef, useState } from 'react';
2
+ import { barItems, buildNav, firstFeatured, hasReports, pageTitle, type NavSection } from '../core/nav.ts';
3
+ import { favorites, moveFavorite, settings, togglePanel, toggleFavorite, updateSettings } from '../core/prefs.ts';
4
+ import * as router from '../core/router.ts';
5
+ import { currentPage } from '../core/page.ts';
6
+ import * as services from '../core/services.ts';
7
+ import { dismiss, toast, toasts } from '../core/toasts.ts';
8
+ import * as vault from '../core/vault.ts';
9
+ import { viewKey, type RegistryView } from '../types.ts';
10
+ import { useShell, useStore } from './hooks.ts';
11
+ import { Icon } from './Icon.tsx';
12
+ import { Rail, SettingsRail } from './Rail.tsx';
13
+ import { Configuration, GettingStarted, ServicePage, ServicesList, VaultAndData } from './settings/Settings.tsx';
14
+ import { DatasetsPage } from './settings/Datasets.tsx';
15
+ import { ReleaseNotesPage } from './settings/ReleaseNotes.tsx';
16
+ import { TemplatesPage } from './settings/Templates.tsx';
17
+ import { comboOf, match } from '../core/hotkeys.ts';
18
+ import { appDefaultOf, startHash } from '../core/startpage.ts';
19
+ import { SearchBar } from './Search.tsx';
20
+ import { SessionsMenu } from './Sessions.tsx';
21
+ import { SidePanel, SubBar } from './SidePanel.tsx';
22
+ import { ViewHost } from './ViewHost.tsx';
23
+
24
+ const vaultStore = { get: vault.status, subscribe: (fn: () => void) => vault.subscribe(fn) };
25
+
26
+ function UnlockPrompt({ onClose }: { onClose: () => void }) {
27
+ const [pass, setPass] = useState('');
28
+ const [wrong, setWrong] = useState(false);
29
+ const submit = async () => { if (await vault.unlock(pass)) onClose(); else { setWrong(true); setPass(''); } };
30
+ return (
31
+ <div className="backdrop">
32
+ <div className="modal">
33
+ <button className="close" onClick={onClose} aria-label="Close">×</button>
34
+ <h2>Unlock the vault</h2>
35
+ <p className="muted">Anything waiting for a saved credential continues after you unlock.</p>
36
+ <input autoFocus type="password" value={pass} placeholder="Passphrase" onChange={(e) => { setPass(e.target.value); setWrong(false); }} onKeyDown={(e) => e.key === 'Enter' && void submit()} />
37
+ {wrong && <p className="error">That passphrase isn't right.</p>}
38
+ <div className="actions"><button className="primary" onClick={() => void submit()}>Unlock</button></div>
39
+ </div>
40
+ </div>
41
+ );
42
+ }
43
+
44
+ function Toasts() {
45
+ const list = useStore(toasts);
46
+ return <div className="toasts">{list.map((t) => <div key={t.id} className={`toast ${t.kind}`} onClick={() => dismiss(t.id)}>{t.title && <strong>{t.title}</strong>}<div>{t.text}</div></div>)}</div>;
47
+ }
48
+
49
+ function FavoritesMenu({ views }: { views: RegistryView[] }) {
50
+ const favs = useStore(favorites);
51
+ const [open, setOpen] = useState(false);
52
+ const items = favs.map((k) => views.find((v) => viewKey(v) === k)).filter((v): v is RegistryView => !!v);
53
+ return (
54
+ <div className="favmenu">
55
+ <button className="bar-btn icon-only" onClick={() => setOpen(!open)} title="Favorites" aria-label="Favorites"><i className="fa-solid fa-bars" /></button>
56
+ {open && (
57
+ <div className="favmenu-list" onMouseLeave={() => setOpen(false)}>
58
+ {!items.length && <p className="muted small">Star a page with Favorite in its bar.</p>}
59
+ {items.map((v) => (
60
+ <div key={viewKey(v)} className="favmenu-row" tabIndex={0} onKeyDown={(e) => { if (e.altKey && e.key === 'ArrowUp') moveFavorite(viewKey(v), -1); if (e.altKey && e.key === 'ArrowDown') moveFavorite(viewKey(v), 1); }}>
61
+ <a href={router.href.view(v.module, v.name)} onClick={() => setOpen(false)}><Icon icon={v.icon} />{v.label}</a>
62
+ <button onClick={() => moveFavorite(viewKey(v), -1)} title="Move up (Alt+↑)">↑</button><button onClick={() => moveFavorite(viewKey(v), 1)} title="Move down (Alt+↓)">↓</button>
63
+ </div>
64
+ ))}
65
+ </div>
66
+ )}
67
+ </div>
68
+ );
69
+ }
70
+
71
+ /** "Lock the vault?" before the Vault button locks it (Settings → Configuration → Vault: Confirm before locking; default on). Enter locks, Esc cancels. */
72
+ function LockConfirm({ onClose }: { onClose: () => void }) {
73
+ const lock = () => { onClose(); void vault.lock(); };
74
+ return (
75
+ <div className="backdrop" onMouseDown={(e) => e.target === e.currentTarget && onClose()} onKeyDown={(e) => e.key === 'Escape' && onClose()}>
76
+ <div className="modal" role="alertdialog" aria-labelledby="lock-title">
77
+ <h2 id="lock-title">Lock the vault?</h2>
78
+ <p className="muted">Saved credentials, datasets and templates become unavailable until you enter your passphrase again. Anything waiting for the vault pauses.</p>
79
+ <div className="actions"><button onClick={onClose}>Cancel</button><button className="primary" autoFocus onClick={lock}>Lock</button></div>
80
+ </div>
81
+ </div>
82
+ );
83
+ }
84
+
85
+ /** Vault state at a glance, icon only: green open lock while unlocked (click to lock, after a confirmation), red closed lock while locked (click to unlock). */
86
+ function VaultButton({ state, onUnlock }: { state: ReturnType<typeof vault.status>; onUnlock: () => void }) {
87
+ const confirm = useStore(settings).confirmLock;
88
+ const [asking, setAsking] = useState(false);
89
+ if (state === 'uninitialized') return null;
90
+ const unlocked = state === 'unlocked';
91
+ return (
92
+ <>
93
+ <button className={`bar-btn icon-only ${unlocked ? 'st-ok' : 'st-bad'}`} title="Vault" aria-label="Vault" onClick={() => (unlocked ? (confirm ? setAsking(true) : void vault.lock()) : onUnlock())}>
94
+ <i className={`fa-solid ${unlocked ? 'fa-lock-open' : 'fa-lock'}`} />
95
+ </button>
96
+ {asking && unlocked && <LockConfirm onClose={() => setAsking(false)} />}
97
+ </>
98
+ );
99
+ }
100
+
101
+ /** One click turns notifications on / off (the same switch as Settings → Configuration → Notifications): green bell when on, red crossed-out bell when off or paused by a locked vault. */
102
+ function NotifyBell({ locked }: { locked: boolean }) {
103
+ const prefs = useStore(settings).notifications;
104
+ const on = prefs.enabled && !locked;
105
+ const toggle = () => { void updateSettings({ notifications: { ...prefs, enabled: !prefs.enabled } }); toast(prefs.enabled ? 'Notifications off' : 'Notifications on'); };
106
+ return <button className={`bar-btn icon-only ${on ? 'st-ok' : 'st-bad'}`} onClick={toggle} disabled={locked} title="Notifications" aria-label="Notifications" aria-pressed={on}><i className={`fa-solid ${on ? 'fa-bell' : 'fa-bell-slash'}`} /></button>;
107
+ }
108
+
109
+ function FullscreenButton() {
110
+ const [full, setFull] = useState(() => !!document.fullscreenElement);
111
+ useEffect(() => { const f = () => setFull(!!document.fullscreenElement); document.addEventListener('fullscreenchange', f); return () => document.removeEventListener('fullscreenchange', f); }, []);
112
+ const toggle = () => { if (document.fullscreenElement) void document.exitFullscreen(); else document.documentElement.requestFullscreen().catch(() => toast('Full screen not allowed here', 'error')); };
113
+ return <button className={`bar-btn icon-only${full ? ' st-ok' : ''}`} onClick={toggle} title="Full Screen" aria-label="Full Screen" aria-pressed={full}><i className={`fa-solid ${full ? 'fa-compress' : 'fa-expand'}`} /></button>;
114
+ }
115
+
116
+ function Landing({ title, section, views }: { title: string; section: NavSection; views: RegistryView[] }) {
117
+ const favs = useStore(favorites);
118
+ const tiles = title === 'Home' ? favs.map((k) => views.find((v) => viewKey(v) === k)).filter((v): v is RegistryView => !!v) : [];
119
+ const all = [...section.featured, ...section.tools.flatMap((g) => g.features), ...section.services.flatMap((g) => g.features)];
120
+ return (
121
+ <div className="page">
122
+ <h1>{title}</h1>
123
+ {title === 'Home' && <><h2>Favorites</h2>{tiles.length ? <div className="tiles">{tiles.map((v) => <a key={viewKey(v)} className="tile" href={router.href.view(v.module, v.name)}><strong><Icon icon={v.icon} />{v.label}</strong><span className="muted small">{v.module}</span><button className="unstar" onClick={(e) => { e.preventDefault(); toggleFavorite(viewKey(v)); }}>★</button></a>)}</div> : <p className="muted">Star a page with Favorite in its bar to pin it here.</p>}</>}
124
+ <h2>{title === 'Home' ? 'Everything' : 'Reports'}</h2>
125
+ <div className="tiles">{all.map((f) => <a key={f.key} className="tile" href={router.href.view(f.views[0].module, f.views[0].name)}><strong><Icon icon={f.icon} />{f.label}</strong><span className="muted small">{f.views.length} view{f.views.length === 1 ? '' : 's'}</span></a>)}</div>
126
+ </div>
127
+ );
128
+ }
129
+
130
+ export function App() {
131
+ const { registry } = useShell();
132
+ const hash = useStore(router.current);
133
+ const vaultState = useStore(vaultStore);
134
+ useStore(services.states);
135
+ const [filter, setFilter] = useState('');
136
+ const [prompt, setPrompt] = useState(false);
137
+ // Refresh: pages that listen (usePageRefresh) are asked to reload their data; a page with no listeners is re-mounted, which reloads it from scratch.
138
+ const [remount, setRemount] = useState(0);
139
+ const filterRef = useRef<HTMLInputElement>(null);
140
+ const searchRef = useRef<HTMLInputElement>(null);
141
+ const nav = useMemo(() => buildNav(registry, services.isUsable, filter), [registry, filter, services.states.get(), vaultState]);
142
+
143
+ useEffect(() => vault.setUnlockPrompt(() => setPrompt(true)), []);
144
+ // Always ask for the passphrase when the app starts with a locked vault (an idle lock, a browser restart). Closing the prompt keeps it locked; the Vault button asks again.
145
+ useEffect(() => { if (vault.status() === 'locked') setPrompt(true); }, []);
146
+ // Start page (ADR-047, ADR-064): Getting Started until a vault exists, then the user's choice (Settings → Configuration), else the app's default
147
+ // (taco.json settings.startPage), else the first Featured Action, else Home.
148
+ const userStart = useStore(settings).startPage;
149
+ useEffect(() => {
150
+ if (router.parse(hash)) return;
151
+ router.replace(vaultState === 'uninitialized' ? router.href.settings('getting-started') : startHash(registry, firstFeatured(nav), userStart, appDefaultOf(registry)));
152
+ }, [hash]);
153
+ // HotKeys (ADR-046): the user's mapping from Settings → Configuration, defaults from core/hotkeys.ts.
154
+ useEffect(() => {
155
+ const onKey = (e: KeyboardEvent) => {
156
+ const hk = settings.get().hotkeys;
157
+ if (!hk.enabled || (e.target as HTMLElement)?.classList?.contains('hotkey-rec')) return;
158
+ const def = match(comboOf(e), hk.map);
159
+ if (!def) return;
160
+ e.preventDefault();
161
+ if (def.id === 'navFilter') { filterRef.current?.focus(); filterRef.current?.select(); }
162
+ else if (def.id === 'search') { searchRef.current?.focus(); }
163
+ else if (def.id === 'log') togglePanel('log');
164
+ else if (def.id === 'help') togglePanel('help');
165
+ else if (def.id === 'lock') void vault.lock();
166
+ else if (def.id === 'favorite') { const r = router.parse(location.hash); if (r?.page === 'view' && registry.views.find((v) => v.module === r.module && v.name === r.view)?.favorite !== false) toggleFavorite(`${r.module}/${r.view}`); }
167
+ };
168
+ addEventListener('keydown', onKey);
169
+ return () => removeEventListener('keydown', onKey);
170
+ }, [registry]);
171
+
172
+ const route = router.parse(hash) ?? { page: 'home' as const };
173
+ const section = route.page === 'settings' ? 'settings' : route.page === 'reports' ? 'reports' : route.page === 'view' ? (registry.views.find((v) => v.module === route.module && v.name === route.view)?.nav.section ?? 'home') : 'home';
174
+ const view = route.page === 'view' ? registry.views.find((v) => v.module === route.module && v.name === route.view) : undefined;
175
+ const feature = view ? nav.byView.get(viewKey(view)) : undefined;
176
+
177
+ const refresh = () => {
178
+ const p = currentPage.get();
179
+ if (p && p.refreshListeners() > 0) p.page.refresh('Refresh button');
180
+ else setRemount((n) => n + 1);
181
+ };
182
+
183
+ let body;
184
+ let help: { text?: string; title: string } = { title: 'This page' };
185
+ if (route.page === 'view') {
186
+ body = view ? <ViewHost key={`${viewKey(view)}:${remount}`} view={view} /> : <div className="page"><h1>Not found</h1><p className="muted">No view {route.module}/{route.view} in this app.</p></div>;
187
+ if (view) help = { text: view.helpText, title: view.label };
188
+ } else if (route.page === 'settings') {
189
+ body = route.sub === 'getting-started' ? <GettingStarted /> : route.sub === 'configuration' ? <Configuration /> : route.sub === 'vault' ? <VaultAndData />
190
+ : route.sub === 'datasets' ? <DatasetsPage /> : route.sub === 'templates' ? <TemplatesPage /> : route.sub === 'release-notes' ? <ReleaseNotesPage /> : route.type && route.name ? <ServicePage type={route.type} name={route.name} /> : <ServicesList />;
191
+ if (route.sub === 'services' && route.type && route.name) { const s = services.find(route.type, route.name); help = { text: s?.howToText, title: s?.label ?? 'Service' }; }
192
+ } else {
193
+ body = <Landing title={route.page === 'reports' ? 'Reports' : 'Home'} section={route.page === 'reports' ? nav.reports : nav.home} views={registry.views} />;
194
+ }
195
+
196
+ return (
197
+ <div className="app">
198
+ <header className="top">
199
+ <FavoritesMenu views={registry.views} />
200
+ <strong className="app-name">{registry.app.displayName}</strong>
201
+ <nav className="sections">
202
+ <a className={section === 'home' ? 'on' : ''} href="#/home"><Icon icon={registry.sectionIcons?.home} />Home</a>
203
+ {hasReports(nav) && <a className={section === 'reports' ? 'on' : ''} href="#/reports"><Icon icon={registry.sectionIcons?.reports} />Reports</a>}
204
+ <a className={section === 'settings' ? 'on' : ''} href={router.href.settings('getting-started')}><Icon icon={registry.sectionIcons?.settings} />Settings</a>
205
+ </nav>
206
+ <a className="pill version" href={router.href.settings('release-notes')} title={`${registry.app.displayName} v${registry.app.version}: click for the release notes`}>v{registry.app.version}</a>
207
+ <SearchBar registry={registry} inputRef={searchRef} />
208
+ <div className="top-right">
209
+ <SessionsMenu registry={registry} />
210
+ <NotifyBell locked={vaultState === 'locked'} />
211
+ <VaultButton state={vaultState} onUnlock={() => setPrompt(true)} />
212
+ <FullscreenButton />
213
+ </div>
214
+ </header>
215
+ <div className="layout">
216
+ {section === 'settings' ? <SettingsRail active={route.page === 'settings' ? route.sub : ''} />
217
+ : <Rail section={section === 'reports' ? nav.reports : nav.home} active={view ? viewKey(view) : undefined} filter={filter} setFilter={setFilter} filterRef={filterRef} />}
218
+ <main className="content">
219
+ <SubBar tabs={view ? barItems(registry, view).map((b) => ({ label: b.label, href: router.href.view(b.view.module, b.view.name), active: b.view === view, icon: b.view.icon })) : undefined} favoriteKey={view && view.favorite !== false ? viewKey(view) : undefined} favoriteOff={view?.favorite === false} hasHelp={!!help.text} onRefresh={view && view.refresh !== false ? refresh : undefined} />
220
+ {view && <h1 className="page-title"><Icon icon={view.icon} />{pageTitle(registry, view)}</h1>}
221
+ <div className={view ? 'view-body' : undefined}>{body}</div>
222
+ </main>
223
+ <SidePanel helpText={help.text} helpTitle={help.title} />
224
+ </div>
225
+ {prompt && vaultState === 'locked' && <UnlockPrompt onClose={() => setPrompt(false)} />}
226
+ <Toasts />
227
+ </div>
228
+ );
229
+ }
@@ -0,0 +1,23 @@
1
+ import type { InputHTMLAttributes, RefObject } from 'react';
2
+
3
+ /** The "×" inside a filter box: shown only while there is text; clears it and keeps focus in the box. */
4
+ export function ClearButton({ onClear }: { onClear: () => void }) {
5
+ return <button type="button" className="clear-x" onClick={onClear} onMouseDown={(e) => e.preventDefault()} title="Clear" aria-label="Clear"><i className="fa-solid fa-xmark" /></button>;
6
+ }
7
+
8
+ type Props = Omit<InputHTMLAttributes<HTMLInputElement>, 'value' | 'onChange'> & {
9
+ value: string;
10
+ onValue: (v: string) => void;
11
+ inputRef?: RefObject<HTMLInputElement | null>;
12
+ wrapperClass?: string;
13
+ };
14
+
15
+ /** A text box with a "×" on its right that clears it: used by the Activity Log filter, the left-rail filter and header search. */
16
+ export function ClearableInput({ value, onValue, inputRef, wrapperClass = '', ...rest }: Props) {
17
+ return (
18
+ <div className={`clearable ${wrapperClass}`}>
19
+ <input {...rest} ref={inputRef} value={value} onChange={(e) => onValue(e.target.value)} />
20
+ {value && <ClearButton onClear={() => { onValue(''); inputRef?.current?.focus(); }} />}
21
+ </div>
22
+ );
23
+ }
@@ -0,0 +1,8 @@
1
+ import type { RegistryIcon } from '../types.ts';
2
+
3
+ /** A module-declared icon: Font Awesome classes, or a bundled image. Draws nothing when the feature has none. */
4
+ export function Icon({ icon, className = '' }: { icon?: RegistryIcon; className?: string }) {
5
+ if (!icon) return null;
6
+ if ('fa' in icon) return <i className={`${icon.fa} fa-fw nav-icon ${className}`} aria-hidden="true" />;
7
+ return <img className={`nav-icon nav-img ${className}`} src={icon.img} alt="" aria-hidden="true" />;
8
+ }
@@ -0,0 +1,24 @@
1
+ import { parse, type Inline } from '../core/markdown.ts';
2
+
3
+ const inl = (items: Inline[]) =>
4
+ items.map((x, i) =>
5
+ x.t === 'code' ? <code key={i}>{x.v}</code>
6
+ : x.t === 'bold' ? <strong key={i}>{x.v}</strong>
7
+ : x.t === 'link' ? <a key={i} href={x.href} target="_blank" rel="noopener noreferrer">{x.v}</a>
8
+ : <span key={i}>{x.v}</span>);
9
+
10
+ /** Renders the Markdown subset as React elements: text is never interpreted as HTML (SECURITY.md rule 5). */
11
+ export function Markdown({ text }: { text?: string }) {
12
+ if (!text?.trim()) return <p className="muted">No help has been written for this page yet.</p>;
13
+ return (
14
+ <div className="md">
15
+ {parse(text).map((b, i) => {
16
+ if (b.t === 'h') { const H = (`h${b.level + 1}`) as 'h2' | 'h3' | 'h4'; return <H key={i}>{inl(b.inl)}</H>; }
17
+ if (b.t === 'p') return <p key={i}>{inl(b.inl)}</p>;
18
+ if (b.t === 'code') return <pre key={i}><code>{b.v}</code></pre>;
19
+ const L = b.t;
20
+ return <L key={i}>{b.items.map((it, j) => <li key={j}>{inl(it)}</li>)}</L>;
21
+ })}
22
+ </div>
23
+ );
24
+ }
@@ -0,0 +1,89 @@
1
+ import { useEffect, useState, type KeyboardEvent, type RefObject } from 'react';
2
+ import type { NavFeature, NavGroup, NavSection } from '../core/nav.ts';
3
+ import { pref, setPref } from '../core/prefs.ts';
4
+ import { go, href } from '../core/router.ts';
5
+ import { viewKey } from '../types.ts';
6
+ import { ClearableInput } from './ClearableInput.tsx';
7
+ import { Icon } from './Icon.tsx';
8
+
9
+ const featureHref = (f: NavFeature) => href.view(f.views[0].module, f.views[0].name);
10
+
11
+ function Link({ f, active, picked }: { f: NavFeature; active?: string; picked?: string | null }) {
12
+ const on = f.views.some((v) => viewKey(v) === active);
13
+ return <a data-feature={f.key} className={`rail-link${on ? ' active' : ''}${picked === f.key ? ' kbd-sel' : ''}`} href={featureHref(f)}><Icon icon={f.icon} />{f.label}</a>;
14
+ }
15
+
16
+ function Group({ g, active, forceOpen, picked }: { g: NavGroup; active?: string; forceOpen: boolean; picked?: string | null }) {
17
+ const [open, setOpen] = useState(() => !pref<string[]>('nav.collapsed', []).includes(g.key));
18
+ if (g.flat) return <Link f={g.features[0]} active={active} picked={picked} />;
19
+ const toggle = () => {
20
+ const collapsed = pref<string[]>('nav.collapsed', []);
21
+ setPref('nav.collapsed', open ? [...collapsed, g.key] : collapsed.filter((k) => k !== g.key));
22
+ setOpen(!open);
23
+ };
24
+ const shown = open || forceOpen;
25
+ return (
26
+ <div className="rail-group">
27
+ <button className="rail-group-head" onClick={toggle} aria-expanded={shown}>{shown ? '▾' : '▸'} {g.label}</button>
28
+ {shown && g.features.map((f) => <Link key={f.key} f={f} active={active} picked={picked} />)}
29
+ </div>
30
+ );
31
+ }
32
+
33
+ /** Left rail (ADR-038): Featured (never collapses) → filter → Tools groups → Services groups A–Z. */
34
+ export function Rail({ section, active, filter, setFilter, filterRef }: { section: NavSection; active?: string; filter: string; setFilter: (s: string) => void; filterRef: RefObject<HTMLInputElement | null> }) {
35
+ const [picked, setPicked] = useState<string | null>(null);
36
+ useEffect(() => setPicked(null), [filter]);
37
+ // What is on display, top to bottom: Featured, then each group's features unless the group is collapsed (a filter opens them all).
38
+ const shownFeatures = (): NavFeature[] => {
39
+ const collapsed = pref<string[]>('nav.collapsed', []);
40
+ const open = (g: NavGroup) => g.flat || !!filter || !collapsed.includes(g.key);
41
+ return [...section.featured, ...[...section.tools, ...section.services].filter(open).flatMap((g) => g.features)];
42
+ };
43
+ // ↑ ↓ move the selection through what is shown; Enter opens it (with a filter typed and nothing picked, the first match).
44
+ const onKeyDown = (e: KeyboardEvent<HTMLInputElement>) => {
45
+ const list = shownFeatures();
46
+ if (e.key === 'ArrowDown' || e.key === 'ArrowUp') {
47
+ e.preventDefault();
48
+ if (!list.length) return;
49
+ const i = list.findIndex((f) => f.key === picked);
50
+ const next = list[i < 0 ? (e.key === 'ArrowDown' ? 0 : list.length - 1) : (i + (e.key === 'ArrowDown' ? 1 : list.length - 1)) % list.length];
51
+ setPicked(next.key);
52
+ requestAnimationFrame(() => document.querySelector(`[data-feature="${CSS.escape(next.key)}"]`)?.scrollIntoView({ block: 'nearest' }));
53
+ } else if (e.key === 'Enter') {
54
+ const f = list.find((x) => x.key === picked) ?? (filter.trim() ? list[0] : undefined);
55
+ if (f) { e.preventDefault(); if (go(featureHref(f))) { setPicked(null); e.currentTarget.blur(); } }
56
+ } else if (e.key === 'Escape') { setPicked(null); e.currentTarget.blur(); }
57
+ };
58
+ const empty = !section.featured.length && !section.tools.length && !section.services.length;
59
+ return (
60
+ <nav className="rail">
61
+ {section.featured.length > 0 && <div className="rail-label">Featured</div>}
62
+ {section.featured.map((f) => <Link key={f.key} f={f} active={active} picked={picked} />)}
63
+ <ClearableInput inputRef={filterRef} wrapperClass="rail-filter" placeholder="Filter (⌘/)" aria-label="Filter navigation" value={filter} onValue={setFilter} onKeyDown={onKeyDown} />
64
+ {section.tools.length > 0 && <div className="rail-label">Tools</div>}
65
+ {section.tools.map((g) => <Group key={g.key} g={g} active={active} forceOpen={!!filter} picked={picked} />)}
66
+ {section.services.length > 0 && <div className="rail-label">Services</div>}
67
+ {section.services.map((g) => <Group key={g.key} g={g} active={active} forceOpen={!!filter} picked={picked} />)}
68
+ {empty && <p className="muted small">{filter ? 'Nothing matches the filter.' : 'No views yet. Add one with `taco-cli add component --type=view`.'}</p>}
69
+ </nav>
70
+ );
71
+ }
72
+
73
+ export function SettingsRail({ active }: { active: string }) {
74
+ const items: [string, string, string][] = [
75
+ ['getting-started', 'Getting Started', 'fa-solid fa-flag-checkered'],
76
+ ['services', 'Services', 'fa-solid fa-plug'],
77
+ ['datasets', 'Datasets', 'fa-solid fa-database'],
78
+ ['templates', 'Templates', 'fa-solid fa-file-lines'],
79
+ ['configuration', 'Configuration', 'fa-solid fa-sliders'],
80
+ ['vault', 'Vault & Data', 'fa-solid fa-shield-halved'],
81
+ ['release-notes', 'Release Notes', 'fa-solid fa-clipboard-list'],
82
+ ];
83
+ return (
84
+ <nav className="rail">
85
+ <div className="rail-label">Settings</div>
86
+ {items.map(([id, label, icon]) => <a key={id} className={`rail-link${active === id ? ' active' : ''}`} href={href.settings(id)}><i className={`${icon} rail-icon`} />{label}</a>)}
87
+ </nav>
88
+ );
89
+ }
@@ -0,0 +1,111 @@
1
+ import { useEffect, useRef, useState, type RefObject } from 'react';
2
+ import { navigate } from '../core/bus.ts';
3
+ import * as search from '../core/search.ts';
4
+ import * as services from '../core/services.ts';
5
+ import { toast } from '../core/toasts.ts';
6
+ import type { Registry } from '../types.ts';
7
+ import { ClearButton } from './ClearableInput.tsx';
8
+ import { useStore } from './hooks.ts';
9
+
10
+ type Phase =
11
+ | { kind: 'idle' }
12
+ | { kind: 'busy' }
13
+ | { kind: 'empty'; failed: string[] }
14
+ | { kind: 'pick'; hits: search.Hit[]; failed: string[] }
15
+ | { kind: 'tiles'; hit: search.Hit; tiles: search.Tile[]; back?: search.Hit[] };
16
+
17
+ const icon = (i?: string) => (i?.startsWith('fa-') ? <i className={i} /> : i ? <span>{i}</span> : <i className="fa-solid fa-bolt" />);
18
+
19
+ /**
20
+ * Header search. It shows only when at least one usable connector opted in with a resolver.
21
+ * Enter resolves the term; one result is the context, several are listed (↑ ↓ Enter) and the pick becomes the context;
22
+ * then each view that registered a Quick Action for that connector offers a tile that opens it with the context ready.
23
+ */
24
+ export function SearchBar({ registry, inputRef }: { registry: Registry; inputRef: RefObject<HTMLInputElement | null> }) {
25
+ useStore(services.states);
26
+ const list = search.resolvers(registry);
27
+ const [term, setTerm] = useState('');
28
+ const [phase, setPhase] = useState<Phase>({ kind: 'idle' });
29
+ const [cursor, setCursor] = useState(0);
30
+ const box = useRef<HTMLDivElement>(null);
31
+ const run = useRef(0); // a newer search supersedes a slower, older one
32
+
33
+ useEffect(() => {
34
+ const away = (e: MouseEvent) => { if (box.current && !box.current.contains(e.target as Node)) setPhase({ kind: 'idle' }); };
35
+ addEventListener('mousedown', away);
36
+ return () => removeEventListener('mousedown', away);
37
+ }, []);
38
+ if (!list.length) return null;
39
+
40
+ const choose = (hit: search.Hit, back?: search.Hit[]) => { setPhase({ kind: 'tiles', hit, tiles: search.tilesFor(registry, hit.service), back }); setCursor(0); };
41
+ const submit = async () => {
42
+ const q = term.trim();
43
+ if (!q) return;
44
+ const id = ++run.current;
45
+ setPhase({ kind: 'busy' });
46
+ const out = await search.resolve(q, list);
47
+ if (id !== run.current) return;
48
+ if (!out.hits.length) setPhase({ kind: 'empty', failed: out.failed });
49
+ else if (out.hits.length === 1) choose(out.hits[0]); // one result: the context is inferred
50
+ else { setPhase({ kind: 'pick', hits: out.hits, failed: out.failed }); setCursor(0); }
51
+ };
52
+ const launch = async (t: search.Tile, hit: search.Hit) => {
53
+ const ok = await navigate({ kind: 'view', module: t.view.module, component: `view:${t.view.name}` }, search.contextFor(t, hit.result.context));
54
+ if (ok) { setPhase({ kind: 'idle' }); setTerm(''); inputRef.current?.blur(); }
55
+ else toast(`Couldn't open ${t.label}; the Activity Log says why.`, 'error');
56
+ };
57
+
58
+ const count = phase.kind === 'pick' ? phase.hits.length : phase.kind === 'tiles' ? phase.tiles.length : 0;
59
+ const activate = (i: number) => {
60
+ if (phase.kind === 'pick') choose(phase.hits[i], phase.hits);
61
+ else if (phase.kind === 'tiles' && phase.tiles[i]) void launch(phase.tiles[i], phase.hit);
62
+ };
63
+ const onKey = (e: React.KeyboardEvent) => {
64
+ if (e.key === 'Escape') { setPhase({ kind: 'idle' }); return; }
65
+ if (count && (e.key === 'ArrowDown' || e.key === 'ArrowUp')) { e.preventDefault(); setCursor((c) => (c + (e.key === 'ArrowDown' ? 1 : count - 1)) % count); return; }
66
+ if (e.key === 'Enter') { e.preventDefault(); if (count) activate(cursor); else void submit(); }
67
+ };
68
+
69
+ return (
70
+ <div className="search" ref={box}>
71
+ <i className="fa-solid fa-magnifying-glass search-icon" />
72
+ <input ref={inputRef} className="search-input" value={term} placeholder={search.placeholder(list)} aria-label="Search"
73
+ onChange={(e) => { setTerm(e.target.value); setPhase({ kind: 'idle' }); }} onKeyDown={onKey} onFocus={(e) => e.target.select()} />
74
+ {term && <ClearButton onClear={() => { setTerm(''); setPhase({ kind: 'idle' }); inputRef.current?.focus(); }} />}
75
+ {phase.kind !== 'idle' && (
76
+ <div className="search-panel" role="listbox">
77
+ {phase.kind === 'busy' && <p className="muted small">Searching…</p>}
78
+ {phase.kind === 'empty' && <><p className="muted small">Nothing found for “{term.trim()}”.</p>{phase.failed.map((f) => <p key={f} className="error small">{f}</p>)}</>}
79
+ {phase.kind === 'pick' && (
80
+ <>
81
+ <div className="search-head">{phase.hits.length} matches: pick one</div>
82
+ {phase.hits.map((h, i) => (
83
+ <button key={`${h.service.name}:${h.result.id}`} role="option" aria-selected={i === cursor} className={`search-row${i === cursor ? ' sel' : ''}`} onMouseEnter={() => setCursor(i)} onClick={() => activate(i)}>
84
+ <strong>{h.result.label}</strong>{h.result.detail && <span className="muted small"> {h.result.detail}</span>}<span className="pill">{h.service.resolver!.label}</span>
85
+ </button>
86
+ ))}
87
+ {phase.failed.map((f) => <p key={f} className="error small">{f}</p>)}
88
+ </>
89
+ )}
90
+ {phase.kind === 'tiles' && (
91
+ <>
92
+ <div className="search-head">
93
+ {phase.back && <button className="search-back" onClick={() => { setPhase({ kind: 'pick', hits: phase.back!, failed: [] }); setCursor(0); inputRef.current?.focus(); }} title="Back to the matches" aria-label="Back to the matches"><i className="fa-solid fa-arrow-left" /></button>}
94
+ <strong>{phase.hit.result.label}</strong>{phase.hit.result.detail && <span className="muted small"> {phase.hit.result.detail}</span>}<span className="pill">{phase.hit.service.resolver!.label}</span>
95
+ </div>
96
+ {phase.tiles.length ? (
97
+ <div className="search-tiles">
98
+ {phase.tiles.map((t, i) => (
99
+ <button key={`${t.view.module}/${t.view.name}:${i}`} className={`search-tile${i === cursor ? ' sel' : ''}`} onMouseEnter={() => setCursor(i)} onClick={() => activate(i)}>
100
+ {icon(t.icon)}<strong>{t.label}</strong><span className="muted small">{t.view.label}</span>
101
+ </button>
102
+ ))}
103
+ </div>
104
+ ) : <p className="muted small">No Quick Actions are registered for {phase.hit.service.resolver!.label} yet.</p>}
105
+ </>
106
+ )}
107
+ </div>
108
+ )}
109
+ </div>
110
+ );
111
+ }