@tacoshell/shell 0.0.0-stage → 0.1.1
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.
- package/LICENSE +28 -0
- package/README.md +6 -2
- package/package.json +40 -4
- package/src/background.ts +41 -0
- package/src/core/bus.ts +210 -0
- package/src/core/cards.ts +33 -0
- package/src/core/contrib.ts +70 -0
- package/src/core/cron.ts +63 -0
- package/src/core/cronfriendly.ts +70 -0
- package/src/core/csv.ts +36 -0
- package/src/core/csvfeature.ts +57 -0
- package/src/core/datasets.ts +367 -0
- package/src/core/domshot.ts +81 -0
- package/src/core/guards.ts +36 -0
- package/src/core/hosts.ts +15 -0
- package/src/core/hotkeys.ts +44 -0
- package/src/core/indicators.ts +62 -0
- package/src/core/jobs.ts +37 -0
- package/src/core/localdata.ts +88 -0
- package/src/core/log.ts +91 -0
- package/src/core/markdown.ts +57 -0
- package/src/core/nav.ts +105 -0
- package/src/core/notifyrules.ts +31 -0
- package/src/core/page.ts +91 -0
- package/src/core/prefs.ts +119 -0
- package/src/core/router.ts +78 -0
- package/src/core/search.ts +65 -0
- package/src/core/services.ts +178 -0
- package/src/core/sessions.ts +93 -0
- package/src/core/startpage.ts +28 -0
- package/src/core/storage.ts +54 -0
- package/src/core/systemtools.ts +85 -0
- package/src/core/tabfit.ts +30 -0
- package/src/core/templates.ts +48 -0
- package/src/core/text.ts +6 -0
- package/src/core/toasts.ts +13 -0
- package/src/core/vault.ts +208 -0
- package/src/env.d.ts +2 -0
- package/src/index.ts +58 -0
- package/src/styles.css +391 -0
- package/src/types.ts +133 -0
- package/src/ui/ActionModal.tsx +22 -0
- package/src/ui/App.tsx +241 -0
- package/src/ui/ClearableInput.tsx +23 -0
- package/src/ui/CsvFeature.tsx +151 -0
- package/src/ui/Icon.tsx +8 -0
- package/src/ui/ItemFeature.tsx +39 -0
- package/src/ui/Markdown.tsx +24 -0
- package/src/ui/Rail.tsx +135 -0
- package/src/ui/RelatedMenu.tsx +57 -0
- package/src/ui/Search.tsx +111 -0
- package/src/ui/Sessions.tsx +76 -0
- package/src/ui/SidePanel.tsx +150 -0
- package/src/ui/TabBar.tsx +56 -0
- package/src/ui/ViewHost.tsx +142 -0
- package/src/ui/hooks.ts +28 -0
- package/src/ui/settings/Datasets.tsx +172 -0
- package/src/ui/settings/ReleaseNotes.tsx +96 -0
- package/src/ui/settings/ScheduleEditor.tsx +57 -0
- package/src/ui/settings/Settings.tsx +339 -0
- package/src/ui/settings/SettingsTabs.tsx +63 -0
- package/src/ui/settings/Templates.tsx +52 -0
- package/src/ui/useContrib.ts +36 -0
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
import type { Context } from '@tacoshell/sdk';
|
|
3
|
+
import { navigate } from '../core/bus.ts';
|
|
4
|
+
import { actionProblem, buttonContext, targetContext, type CollectedButton } from '../core/contrib.ts';
|
|
5
|
+
import * as log from '../core/log.ts';
|
|
6
|
+
import { currentPage } from '../core/page.ts';
|
|
7
|
+
import { toast } from '../core/toasts.ts';
|
|
8
|
+
import type { RegistryView } from '../types.ts';
|
|
9
|
+
import { ActionModal } from './ActionModal.tsx';
|
|
10
|
+
import { useStore } from './hooks.ts';
|
|
11
|
+
import { useContributions } from './useContrib.ts';
|
|
12
|
+
|
|
13
|
+
/** A Related button: the framework's look for `styleType`, overridden by `styleClass`, overridden by `styleInline`. */
|
|
14
|
+
function ContribButton({ b, onClick }: { b: CollectedButton; onClick: () => void }) {
|
|
15
|
+
const cls = ['rel-btn', b.styleType ? `rel-btn-${b.styleType}` : '', b.styleClass ?? ''].filter(Boolean).join(' ');
|
|
16
|
+
return <button type="button" className={cls} style={b.styleInline} data-style-type={b.styleType} onClick={(e) => { e.stopPropagation(); onClick(); }}>{b.label}</button>;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Related ▾: appears (left of Tools) once at least one feature contributes, and keeps filling in. Links carry this page's context as `context.referrer`.
|
|
21
|
+
* An entry may also have one button that launches an ACTION in a modal (its own context first, this page's as `referrer`).
|
|
22
|
+
*/
|
|
23
|
+
export function RelatedMenu() {
|
|
24
|
+
const page = useStore(currentPage);
|
|
25
|
+
const { items, exposed } = useContributions('related', page);
|
|
26
|
+
const [open, setOpen] = useState(false);
|
|
27
|
+
// Fixed when the button is pressed, so what the page exposes later doesn't rebuild the action's page.
|
|
28
|
+
const [action, setAction] = useState<{ view: RegistryView; context: Context } | null>(null);
|
|
29
|
+
const go = (i: (typeof items)[number]) => { setOpen(false); void navigate({ kind: 'view', module: i.view.module, component: `view:${i.view.name}` }, targetContext(i, exposed)); };
|
|
30
|
+
const launch = (b: CollectedButton) => {
|
|
31
|
+
setOpen(false);
|
|
32
|
+
const context = buttonContext(b, exposed);
|
|
33
|
+
const problem = actionProblem(b.action, context);
|
|
34
|
+
if (problem) { log.add('error', `Related button "${b.label}": context for ${b.action.module}/${b.action.name} doesn't match its declaration (${problem})`, context, b.action.module); toast(`Can't open ${b.action.label}: ${problem}`, 'error'); return; }
|
|
35
|
+
setAction({ view: b.action, context });
|
|
36
|
+
};
|
|
37
|
+
return (
|
|
38
|
+
<>
|
|
39
|
+
{items.length > 0 && (
|
|
40
|
+
<div className="filter" data-menu="related">
|
|
41
|
+
<button className={`bar-btn${open ? ' on' : ''}`} onClick={() => setOpen(!open)} aria-expanded={open}><i className="fa-solid fa-link" /> Related ▾</button>
|
|
42
|
+
{open && (
|
|
43
|
+
<div className="filter-menu" onMouseLeave={() => setOpen(false)}>
|
|
44
|
+
{items.map((i) => (
|
|
45
|
+
<div key={i.id} className="related-row">
|
|
46
|
+
<a className="menu-item" href={i.href} onClick={(e) => { e.preventDefault(); go(i); }}>{i.icon?.startsWith('fa-') ? <i className={i.icon} /> : null} {i.label}</a>
|
|
47
|
+
{i.button && <ContribButton b={i.button} onClick={() => launch(i.button!)} />}
|
|
48
|
+
</div>
|
|
49
|
+
))}
|
|
50
|
+
</div>
|
|
51
|
+
)}
|
|
52
|
+
</div>
|
|
53
|
+
)}
|
|
54
|
+
{action && <ActionModal view={action.view} context={action.context} onClose={() => setAction(null)} />}
|
|
55
|
+
</>
|
|
56
|
+
);
|
|
57
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { useEffect, useRef, useState } from 'react';
|
|
2
|
+
import * as services from '../core/services.ts';
|
|
3
|
+
import * as sessions from '../core/sessions.ts';
|
|
4
|
+
import { href } from '../core/router.ts';
|
|
5
|
+
import { serviceKey, type Registry, type RegistryService } from '../types.ts';
|
|
6
|
+
import { toast } from '../core/toasts.ts';
|
|
7
|
+
import { Icon } from './Icon.tsx';
|
|
8
|
+
import { useStore } from './hooks.ts';
|
|
9
|
+
|
|
10
|
+
const RECHECK_MS = 5 * 60_000;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Header Sessions icon for "Current Session" services. Plain while every shown session is active; "Warning" yellow while one is missing.
|
|
14
|
+
* Its menu lists each such service: green = detected and active, yellow = missing. Hidden entirely when no service uses Current Session.
|
|
15
|
+
*/
|
|
16
|
+
export function SessionsMenu({ registry }: { registry: Registry }) {
|
|
17
|
+
useStore(services.states);
|
|
18
|
+
const all = useStore(sessions.statuses);
|
|
19
|
+
const list = sessions.shown(registry);
|
|
20
|
+
const [open, setOpen] = useState(false);
|
|
21
|
+
const [busy, setBusy] = useState(false);
|
|
22
|
+
const box = useRef<HTMLDivElement>(null);
|
|
23
|
+
const key = sessions.sessionServices(registry).map((s) => serviceKey(s) + JSON.stringify(services.stateOf(s).config)).join('|'); // re-check when a service is added, switched or reconfigured
|
|
24
|
+
|
|
25
|
+
const recheck = async () => { setBusy(true); try { await sessions.checkAll(registry); } finally { setBusy(false); } };
|
|
26
|
+
// Check on start, when the services change (a mode switch, turned on / off), every few minutes, and when the user comes back to the app.
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
void recheck();
|
|
29
|
+
const t = setInterval(() => void recheck(), RECHECK_MS);
|
|
30
|
+
const onFocus = () => void recheck();
|
|
31
|
+
addEventListener('focus', onFocus);
|
|
32
|
+
return () => { clearInterval(t); removeEventListener('focus', onFocus); };
|
|
33
|
+
}, [key]);
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
const away = (e: MouseEvent) => { if (box.current && !box.current.contains(e.target as Node)) setOpen(false); };
|
|
36
|
+
addEventListener('mousedown', away);
|
|
37
|
+
return () => removeEventListener('mousedown', away);
|
|
38
|
+
}, []);
|
|
39
|
+
if (!sessions.sessionServices(registry).length) return null;
|
|
40
|
+
|
|
41
|
+
const level = sessions.worst(registry, all);
|
|
42
|
+
return (
|
|
43
|
+
<div className="sessions" ref={box}>
|
|
44
|
+
<button className={`bar-btn icon-only${level ? ` st-${level}` : ''}${open ? ' on' : ''}`} onClick={() => { setOpen(!open); if (!open) void recheck(); }} title="Sessions" aria-label="Sessions" aria-expanded={open}>
|
|
45
|
+
<i className="fa-solid fa-id-badge" />
|
|
46
|
+
</button>
|
|
47
|
+
{open && (
|
|
48
|
+
<div className="sessions-list" role="menu">
|
|
49
|
+
<div className="sessions-head"><strong>Current Sessions</strong>
|
|
50
|
+
<button className="bar-btn icon-only" onClick={() => void recheck()} disabled={busy} title="Check again" aria-label="Check sessions again"><i className={`fa-solid fa-rotate${busy ? ' fa-spin' : ''}`} /></button></div>
|
|
51
|
+
{!list.length && <p className="muted small">Every Current Session service is hidden from this menu (Settings → Services).</p>}
|
|
52
|
+
{list.map((s) => <SessionRow key={serviceKey(s)} s={s} st={all[serviceKey(s)]} onClose={() => setOpen(false)} />)}
|
|
53
|
+
</div>
|
|
54
|
+
)}
|
|
55
|
+
</div>
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function SessionRow({ s, st, onClose }: { s: RegistryService; st?: sessions.SessionStatus; onClose: () => void }) {
|
|
60
|
+
const state = st?.state ?? 'checking';
|
|
61
|
+
const level = sessions.levelOf(s, st);
|
|
62
|
+
const req = sessions.REQUIREMENT_LABEL[s.sessionRequirement ?? 'recommended'];
|
|
63
|
+
const word = state === 'active' ? (st?.who ? `Active · ${st.who}` : 'Active') : state === 'missing' ? 'Missing' : 'Checking…';
|
|
64
|
+
const icon = level === 'bad' ? 'fa-circle-xmark' : level === 'warn' ? 'fa-triangle-exclamation' : 'fa-circle-check';
|
|
65
|
+
return (
|
|
66
|
+
<a className="session-row" href={href.settings('services', s.type, s.name)} onClick={onClose} title={`${req}${state === 'missing' && st?.detail ? `: ${st.detail}` : ''}`}>
|
|
67
|
+
<i className={level ? `fa-solid ${icon} sess-${level}` : 'fa-solid fa-circle-notch fa-spin muted'} />
|
|
68
|
+
<Icon icon={s.icon} />
|
|
69
|
+
<span className="session-name">{s.label} <span className="muted small">{req}</span></span>
|
|
70
|
+
<span className={`${level ? `sess-${level}` : 'muted'} small`}>{word}</span>
|
|
71
|
+
{state === 'missing' && sessions.canReauth(s) && (
|
|
72
|
+
<button type="button" className="session-reauth" onClick={(e) => { e.preventDefault(); e.stopPropagation(); void sessions.reauth(s).then((err) => { if (err) toast(`${s.label}: ${err}`, 'error'); }); }}>Sign in again</button>
|
|
73
|
+
)}
|
|
74
|
+
</a>
|
|
75
|
+
);
|
|
76
|
+
}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { useEffect, useRef, useState } from 'react';
|
|
2
|
+
import type { LogLevel, Tool } from '@tacoshell/sdk';
|
|
3
|
+
import * as log from '../core/log.ts';
|
|
4
|
+
import { currentPage } from '../core/page.ts';
|
|
5
|
+
import { toast } from '../core/toasts.ts';
|
|
6
|
+
import { createStore, favorites, settings, sidePanel, toggleFavorite, togglePanel, updateSettings, pref, setPref } from '../core/prefs.ts';
|
|
7
|
+
import { useStore } from './hooks.ts';
|
|
8
|
+
import { ClearableInput } from './ClearableInput.tsx';
|
|
9
|
+
import { Icon } from './Icon.tsx';
|
|
10
|
+
import { TabBar } from './TabBar.tsx';
|
|
11
|
+
import { Markdown } from './Markdown.tsx';
|
|
12
|
+
import { RelatedMenu } from './RelatedMenu.tsx';
|
|
13
|
+
import type { RegistryIcon } from '../types.ts';
|
|
14
|
+
|
|
15
|
+
const logStore = { get: log.getVersion, subscribe: log.subscribe };
|
|
16
|
+
/** Notification history is a filter on the Activity Log, not a separate UI (ADR-028). */
|
|
17
|
+
const onlyNotifications = createStore<boolean>(pref('log.onlyNotifications', false));
|
|
18
|
+
const setOnlyNotifications = (on: boolean) => { onlyNotifications.set(on); setPref('log.onlyNotifications', on); };
|
|
19
|
+
|
|
20
|
+
/** Text typed in the Activity Log's filter box (not remembered across reloads). */
|
|
21
|
+
const logFilter = createStore<string>('');
|
|
22
|
+
const rowMatches = (e: log.Entry, q: string) => !q || [e.message, e.level, e.source, e.tag].some((v) => v?.toLowerCase().includes(q));
|
|
23
|
+
|
|
24
|
+
// useSyncExternalStore needs a stable snapshot: one shared empty list, not a new [] per call.
|
|
25
|
+
const NO_TOOLS: Tool[] = [];
|
|
26
|
+
const noTools = { get: () => NO_TOOLS, subscribe: () => () => {} };
|
|
27
|
+
|
|
28
|
+
/** Tools ▾ (ADR-051, from v2 FR-TOOLS-1): shown only while the page has tools; cleared when the user navigates away. */
|
|
29
|
+
function ToolsMenu() {
|
|
30
|
+
const page = useStore(currentPage);
|
|
31
|
+
const tools = useStore(page?.tools ?? noTools);
|
|
32
|
+
const [open, setOpen] = useState(false);
|
|
33
|
+
if (!tools.length) return null;
|
|
34
|
+
const run = async (t: (typeof tools)[number]) => {
|
|
35
|
+
setOpen(false);
|
|
36
|
+
try { await t.run(); } catch (e) { log.add('error', `Tool ${t.label} failed: ${(e as Error).message}`); toast(`${t.label} failed: ${(e as Error).message}`, 'error'); }
|
|
37
|
+
};
|
|
38
|
+
return (
|
|
39
|
+
<div className="filter">
|
|
40
|
+
<button className={`bar-btn${open ? ' on' : ''}`} onClick={() => setOpen(!open)} aria-expanded={open}><i className="fa-solid fa-screwdriver-wrench" /> Tools ▾</button>
|
|
41
|
+
{open && <div className="filter-menu" onMouseLeave={() => setOpen(false)}>{tools.map((t) => <button key={t.id} className="menu-item" onClick={() => void run(t)}>{t.icon?.startsWith('fa-') ? <i className={t.icon} /> : t.icon ? `${t.icon} ` : null} {t.label}</button>)}</div>}
|
|
42
|
+
</div>
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* The 3rd-level bar (ADR-039): tabs anchored left (they mirror the Level-2 group; overflow goes to "More"), then, on the right, icon-only buttons:
|
|
48
|
+
* Refresh · Related ▾ (when features contribute) · Tools ▾ (when the page has any) · Favorite · Log · Help. Tooltips carry the names.
|
|
49
|
+
*/
|
|
50
|
+
export function SubBar({ tabs, favoriteKey, hasHelp, favoriteOff, onRefresh }: { tabs?: { label: string; href: string; active: boolean; icon?: RegistryIcon }[]; favoriteKey?: string; hasHelp: boolean; /** The view turned Favorite off. */ favoriteOff?: boolean; /** Undefined = Refresh is unavailable here (not a view, or the view turned it off). */ onRefresh?: () => void }) {
|
|
51
|
+
useStore(logStore);
|
|
52
|
+
const panel = useStore(sidePanel);
|
|
53
|
+
const favs = useStore(favorites);
|
|
54
|
+
const level = log.indicator();
|
|
55
|
+
const isFav = !!favoriteKey && favs.includes(favoriteKey);
|
|
56
|
+
return (
|
|
57
|
+
<div className="subbar">
|
|
58
|
+
{(tabs ?? []).length > 1 ? <TabBar tabs={tabs!} /> : <div className="subbar-tabs" />}
|
|
59
|
+
<div className="subbar-actions">
|
|
60
|
+
<button className="bar-btn icon-only" onClick={onRefresh} disabled={!onRefresh} title={onRefresh ? 'Refresh' : 'Nothing to refresh here'} aria-label="Refresh"><i className="fa-solid fa-rotate" /></button>
|
|
61
|
+
<RelatedMenu />
|
|
62
|
+
<ToolsMenu />
|
|
63
|
+
{/* Favorite is shown on every page, and is active only on pages that can be starred (views that haven't turned it off). */}
|
|
64
|
+
<button className={`bar-btn icon-only${isFav ? ' on fav-on' : ''}`} onClick={() => favoriteKey && toggleFavorite(favoriteKey)} disabled={!favoriteKey} aria-label="Favorite" aria-pressed={isFav} title={favoriteKey ? 'Favorite' : favoriteOff ? 'Favorite is turned off for this page' : 'Only views can be favorites'}>
|
|
65
|
+
<i className={`${isFav ? 'fa-solid' : 'fa-regular'} fa-star`} />
|
|
66
|
+
</button>
|
|
67
|
+
<button className={`bar-btn icon-only${panel === 'log' ? ' on' : ''}${level ? ` sev-${level}` : ''}`} onClick={() => togglePanel('log')} title="Activity Log (⌘.)" aria-label="Activity Log"><i className="fa-regular fa-file-lines" /></button>
|
|
68
|
+
<button className={`bar-btn icon-only${panel === 'help' ? ' on' : ''}`} onClick={() => togglePanel('help')} disabled={!hasHelp} title="Help (⌘?)" aria-label="Help"><i className="fa-solid fa-life-ring" /></button>
|
|
69
|
+
</div>
|
|
70
|
+
</div>
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function LevelFilter() {
|
|
75
|
+
const { visibleLevels } = useStore(settings);
|
|
76
|
+
const [open, setOpen] = useState(false);
|
|
77
|
+
const set = (levels: string[]) => void updateSettings({ visibleLevels: levels });
|
|
78
|
+
const onlyNotes = useStore(onlyNotifications);
|
|
79
|
+
const allOn = log.LEVELS.every((l) => visibleLevels.includes(l));
|
|
80
|
+
return (
|
|
81
|
+
<div className="filter">
|
|
82
|
+
<button className="bar-btn" onClick={() => setOpen(!open)}>Levels ▾</button>
|
|
83
|
+
{open && (
|
|
84
|
+
<div className="filter-menu" onMouseLeave={() => setOpen(false)}>
|
|
85
|
+
<div className="filter-row"><button onClick={() => set(allOn ? [] : [...log.LEVELS])}>{allOn ? 'Deselect all' : 'Select all'}</button></div>
|
|
86
|
+
{log.LEVELS.map((l) => (
|
|
87
|
+
<label key={l}><input type="checkbox" checked={visibleLevels.includes(l)} onChange={(e) => set(e.target.checked ? [...visibleLevels, l] : visibleLevels.filter((x) => x !== l))} /> <span className={`lvl lvl-${l}`}>{l}</span></label>
|
|
88
|
+
))}
|
|
89
|
+
<label className="sep"><input type="checkbox" checked={onlyNotes} onChange={(e) => setOnlyNotifications(e.target.checked)} /> Notifications only</label>
|
|
90
|
+
</div>
|
|
91
|
+
)}
|
|
92
|
+
</div>
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** HH:MM:SS (24 h) for the left column; the full date and time are in the tooltip. */
|
|
97
|
+
const clock = (at: number) => new Date(at).toLocaleTimeString([], { hour12: false });
|
|
98
|
+
|
|
99
|
+
function LogPanel() {
|
|
100
|
+
useStore(logStore);
|
|
101
|
+
const { visibleLevels } = useStore(settings);
|
|
102
|
+
const onlyNotes = useStore(onlyNotifications);
|
|
103
|
+
useEffect(() => { log.setPanelOpen(true); return () => log.setPanelOpen(false); }, []);
|
|
104
|
+
const text = useStore(logFilter);
|
|
105
|
+
const q = text.trim().toLowerCase();
|
|
106
|
+
const rows = log.all();
|
|
107
|
+
return (
|
|
108
|
+
<>
|
|
109
|
+
<div className="panel-head"><ClearableInput wrapperClass="log-filter" placeholder="Filter" aria-label="Filter the Activity Log" value={text} onValue={(v) => logFilter.set(v)} /><LevelFilter /><button className="bar-btn" onClick={log.clear}>Clear</button></div>
|
|
110
|
+
<ol className="log-list">
|
|
111
|
+
{[...rows].reverse().map((e) => (
|
|
112
|
+
// Hidden rather than dropped, so turning a level on later shows earlier lines too (ADR-040).
|
|
113
|
+
<li key={e.id} hidden={!visibleLevels.includes(e.level as LogLevel) || (onlyNotes && e.tag !== 'notification') || !rowMatches(e, q)}>
|
|
114
|
+
<div className="log-head">
|
|
115
|
+
<time dateTime={new Date(e.at).toISOString()} title={new Date(e.at).toLocaleString()}>{clock(e.at)}</time>
|
|
116
|
+
<span className={`lvl lvl-${e.level}`}>{e.level}</span>
|
|
117
|
+
{e.tag === 'notification' && <span className="tag">notification</span>}
|
|
118
|
+
{e.source && <span className="src">{e.source}</span>}
|
|
119
|
+
</div>
|
|
120
|
+
<div className="msg">{e.message}</div>
|
|
121
|
+
{e.data !== undefined && <pre className="data">{JSON.stringify(e.data, null, 1)}</pre>}
|
|
122
|
+
</li>
|
|
123
|
+
))}
|
|
124
|
+
</ol>
|
|
125
|
+
</>
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** Log and Help share one right-hand slot; each remembers its own width, 240–800 px (ADR-039). */
|
|
130
|
+
export function SidePanel({ helpText, helpTitle }: { helpText?: string; helpTitle: string }) {
|
|
131
|
+
const panel = useStore(sidePanel);
|
|
132
|
+
const [width, setWidth] = useState(() => pref(`side.width.${panel}`, 420));
|
|
133
|
+
const dragging = useRef(false);
|
|
134
|
+
useEffect(() => setWidth(pref(`side.width.${panel}`, 420)), [panel]);
|
|
135
|
+
if (!panel) return null;
|
|
136
|
+
const startDrag = (e: React.PointerEvent) => {
|
|
137
|
+
dragging.current = true;
|
|
138
|
+
const startX = e.clientX, startW = width;
|
|
139
|
+
const move = (ev: PointerEvent) => setWidth(Math.min(800, Math.max(240, startW + (startX - ev.clientX))));
|
|
140
|
+
const up = (ev: PointerEvent) => { dragging.current = false; setPref(`side.width.${panel}`, Math.min(800, Math.max(240, startW + (startX - ev.clientX)))); removeEventListener('pointermove', move); removeEventListener('pointerup', up); };
|
|
141
|
+
addEventListener('pointermove', move);
|
|
142
|
+
addEventListener('pointerup', up);
|
|
143
|
+
};
|
|
144
|
+
return (
|
|
145
|
+
<aside className="side" style={{ width }}>
|
|
146
|
+
<div className="side-grip" onPointerDown={startDrag} onDoubleClick={() => { setWidth(420); setPref(`side.width.${panel}`, 420); }} />
|
|
147
|
+
{panel === 'log' ? <LogPanel /> : (<><div className="panel-head"><strong>Help · {helpTitle}</strong></div><div className="help-body"><Markdown text={helpText} /></div></>)}
|
|
148
|
+
</aside>
|
|
149
|
+
);
|
|
150
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { useLayoutEffect, useRef, useState } from 'react';
|
|
2
|
+
import type { RegistryIcon } from '../types.ts';
|
|
3
|
+
import { fit, TAB_GUTTER } from '../core/tabfit.ts';
|
|
4
|
+
import { Icon } from './Icon.tsx';
|
|
5
|
+
|
|
6
|
+
export interface Tab { label: string; href: string; active: boolean; icon?: RegistryIcon }
|
|
7
|
+
|
|
8
|
+
/** The 3rd-level tabs, anchored left. They keep a 64 px gutter before the buttons on the right; whatever would overlap it goes in a "More" menu. */
|
|
9
|
+
export function TabBar({ tabs }: { tabs: Tab[] }) {
|
|
10
|
+
const box = useRef<HTMLDivElement>(null);
|
|
11
|
+
const measure = useRef<HTMLDivElement>(null);
|
|
12
|
+
const [layout, setLayout] = useState<{ shown: number[]; hidden: number[] }>({ shown: tabs.map((_, i) => i), hidden: [] });
|
|
13
|
+
const [open, setOpen] = useState(false);
|
|
14
|
+
const activeAt = tabs.findIndex((t) => t.active);
|
|
15
|
+
// The layout is measured after render, so for one render it can describe the PREVIOUS tab list (13 tabs → 4): ignore indices that no longer exist.
|
|
16
|
+
const shown = layout.shown.filter((i) => i < tabs.length);
|
|
17
|
+
const hidden = layout.hidden.filter((i) => i < tabs.length);
|
|
18
|
+
const sig = tabs.map((t) => `${t.label}|${t.active}`).join('/');
|
|
19
|
+
|
|
20
|
+
useLayoutEffect(() => {
|
|
21
|
+
const run = () => {
|
|
22
|
+
const m = measure.current, b = box.current;
|
|
23
|
+
if (!m || !b) return;
|
|
24
|
+
const kids = [...m.children] as HTMLElement[];
|
|
25
|
+
const widths = kids.slice(0, tabs.length).map((k) => k.offsetWidth);
|
|
26
|
+
const next = fit(widths, kids[tabs.length]?.offsetWidth ?? 70, b.clientWidth, activeAt);
|
|
27
|
+
setLayout((cur) => (cur.shown.join() === next.shown.join() && cur.hidden.join() === next.hidden.join() ? cur : next));
|
|
28
|
+
};
|
|
29
|
+
run();
|
|
30
|
+
const ro = new ResizeObserver(run);
|
|
31
|
+
if (box.current) ro.observe(box.current);
|
|
32
|
+
// The icon font may arrive after the first measure and change every tab's width: watch the measuring strip too, and re-measure when fonts are ready.
|
|
33
|
+
if (measure.current) ro.observe(measure.current);
|
|
34
|
+
void document.fonts?.ready.then(run);
|
|
35
|
+
return () => ro.disconnect();
|
|
36
|
+
}, [sig, activeAt, tabs.length]);
|
|
37
|
+
|
|
38
|
+
useLayoutEffect(() => { setOpen(false); }, [sig]);
|
|
39
|
+
const link = (t: Tab, cls: string) => <a key={t.href} href={t.href} className={`${cls}${t.active ? ' active' : ''}`} onClick={() => setOpen(false)}><Icon icon={t.icon} />{t.label}</a>;
|
|
40
|
+
return (
|
|
41
|
+
<div className="subbar-tabs" ref={box} style={{ marginRight: TAB_GUTTER }}>
|
|
42
|
+
{shown.map((i) => link(tabs[i], 'tab'))}
|
|
43
|
+
{hidden.length > 0 && (
|
|
44
|
+
<div className="tab-more">
|
|
45
|
+
<button className={`tab${hidden.includes(activeAt) ? ' active' : ''}`} onClick={() => setOpen(!open)} aria-expanded={open} aria-haspopup="menu" title={shown.length ? 'More' : tabs[activeAt]?.label}>{shown.length === 0 && activeAt >= 0 ? tabs[activeAt].label : 'More'} <i className="fa-solid fa-chevron-down" /></button>
|
|
46
|
+
{open && <div className="tab-more-menu" role="menu" onMouseLeave={() => setOpen(false)}>{hidden.map((i) => link(tabs[i], 'menu-link'))}</div>}
|
|
47
|
+
</div>
|
|
48
|
+
)}
|
|
49
|
+
{/* Off-screen copy used only to measure every tab (and More) at its natural width. */}
|
|
50
|
+
<div className="tabs-measure" ref={measure} aria-hidden="true">
|
|
51
|
+
{tabs.map((t) => <span key={t.href} className="tab"><Icon icon={t.icon} />{t.label}</span>)}
|
|
52
|
+
<span className="tab">More <i className="fa-solid fa-chevron-down" /></span>
|
|
53
|
+
</div>
|
|
54
|
+
</div>
|
|
55
|
+
);
|
|
56
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { Component, type ComponentType, useEffect, useMemo, useState, type ReactNode } from 'react';
|
|
2
|
+
import { createFramework, setSlotRenderer } from '../core/bus.ts';
|
|
3
|
+
import * as log from '../core/log.ts';
|
|
4
|
+
import { unmet } from '../core/nav.ts';
|
|
5
|
+
import { createPage, currentPage, deliver, type Page } from '../core/page.ts';
|
|
6
|
+
import { systemToolsFor } from '../core/systemtools.ts';
|
|
7
|
+
import * as router from '../core/router.ts';
|
|
8
|
+
import * as services from '../core/services.ts';
|
|
9
|
+
import * as vault from '../core/vault.ts';
|
|
10
|
+
import * as cards from '../core/cards.ts';
|
|
11
|
+
import { pref, setPref } from '../core/prefs.ts';
|
|
12
|
+
import { viewKey, type RegistryCard, type RegistryPanel, type RegistryView } from '../types.ts';
|
|
13
|
+
import type { Framework, ViewProps } from '@tacoshell/sdk';
|
|
14
|
+
import { CsvFeature } from './CsvFeature.tsx';
|
|
15
|
+
import { Icon } from './Icon.tsx';
|
|
16
|
+
import { ItemFeature } from './ItemFeature.tsx';
|
|
17
|
+
import { useShell, useStore, type ShellInput } from './hooks.ts';
|
|
18
|
+
|
|
19
|
+
export class Boundary extends Component<{ name: string; quiet?: boolean; children: ReactNode }, { error?: Error }> {
|
|
20
|
+
state: { error?: Error } = {};
|
|
21
|
+
static getDerivedStateFromError(error: Error) { return { error }; }
|
|
22
|
+
componentDidCatch(error: Error) { log.add('error', `${this.props.name} crashed: ${error.message}`); }
|
|
23
|
+
render() {
|
|
24
|
+
if (!this.state.error) return this.props.children;
|
|
25
|
+
if (this.props.quiet) return <div className="card danger small">{this.props.name} crashed (details in the Activity Log).</div>;
|
|
26
|
+
return <div className="card danger"><strong>This view crashed.</strong><p className="muted">{this.state.error.message}</p><p className="muted">Details are in the Activity Log.</p></div>;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Panels other modules contributed to a slot of the page's view (ADR-053). Each gets its own module-scoped framework on the shared page. */
|
|
31
|
+
function SlotHost({ page, name }: { page: Page; name: string }) {
|
|
32
|
+
const input = useShell();
|
|
33
|
+
useStore(services.states);
|
|
34
|
+
const [module, view] = [page.key.slice(0, page.key.lastIndexOf('/')), page.key.slice(page.key.lastIndexOf('/') + 1)];
|
|
35
|
+
const panels = (input.registry.panels ?? []).filter((p) => p.into.module === module && p.into.view === view && p.into.slot === name);
|
|
36
|
+
return <div className="slot" data-slot={name}>{panels.map((p) => <PanelHost key={`${p.module}/${p.name}`} panel={p} page={page} input={input} slot={name} />)}</div>;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function PanelHost({ panel, page, input, slot }: { panel: RegistryPanel; page: Page; input: ShellInput; slot: string }) {
|
|
40
|
+
const framework = useMemo(() => createFramework(panel.module, page), [panel.module, page]);
|
|
41
|
+
const Panel = input.panels?.[`${panel.module}/${panel.name}`];
|
|
42
|
+
// A panel whose services aren't usable stays out of the page rather than showing a broken box.
|
|
43
|
+
if (!Panel || unmet({ ...panel, requires: panel.requires } as unknown as RegistryView, services.isUsable).length) return null;
|
|
44
|
+
return <Boundary name={`Panel ${panel.label} (${panel.module})`} quiet><Panel framework={framework} slot={slot} /></Boundary>;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** One card: header (icon, label, collapse) and the module's component, given only the page-context entries it is wired to. */
|
|
48
|
+
function CardHost({ card, context, page, input }: { card: RegistryCard; context: Record<string, unknown>; page: Page; input: ShellInput }) {
|
|
49
|
+
const id = `${card.module}/${card.name}`;
|
|
50
|
+
const framework = useMemo(() => createFramework(card.module, page), [card.module, page]);
|
|
51
|
+
const [closed, setClosed] = useState(() => { const saved = pref<Record<string, boolean>>('cards.collapsed', {}); return id in saved ? saved[id] : card.collapsed; });
|
|
52
|
+
const Card = input.cards?.[id];
|
|
53
|
+
if (!Card) return null;
|
|
54
|
+
const toggle = () => { setClosed(!closed); setPref('cards.collapsed', { ...pref<Record<string, boolean>>('cards.collapsed', {}), [id]: !closed }); };
|
|
55
|
+
return (
|
|
56
|
+
<section className={`card-host${closed ? ' closed' : ''}`} data-card={id}>
|
|
57
|
+
<button className="card-head" onClick={toggle} aria-expanded={!closed}>
|
|
58
|
+
<i className={`fa-solid fa-chevron-${closed ? 'right' : 'down'} card-chev`} /><Icon icon={card.icon} /><strong>{card.label}</strong><span className="muted small">{card.module}</span>
|
|
59
|
+
</button>
|
|
60
|
+
{!closed && <div className="card-body"><Boundary name={`Card ${card.label} (${card.module})`} quiet><Card framework={framework} context={context} /></Boundary></div>}
|
|
61
|
+
</section>
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Cards for the current page (ADR-062): every module's card whose wired context entries the page context has, shown under the view.
|
|
67
|
+
* It follows the page context live, so a card appears (or goes) when a component sets the entry with page.set. A view opts out with "cards": false.
|
|
68
|
+
*/
|
|
69
|
+
function CardsRegion({ page, view }: { page: Page; view: RegistryView }) {
|
|
70
|
+
const input = useShell();
|
|
71
|
+
useStore(services.states);
|
|
72
|
+
const ctx = useStore(page.page);
|
|
73
|
+
if (view.cards === false) return null;
|
|
74
|
+
const list = cards.applicable(input.registry.cards ?? [], ctx).filter(({ card }) => !unmet({ ...card } as unknown as RegistryView, services.isUsable).length && input.cards?.[`${card.module}/${card.name}`]);
|
|
75
|
+
if (!list.length) return null;
|
|
76
|
+
return (
|
|
77
|
+
<aside className="cards-region" aria-label="Cards">
|
|
78
|
+
<h2 className="cards-title"><i className="fa-solid fa-layer-group" /> Cards <span className="muted small">{list.length}</span></h2>
|
|
79
|
+
<div className="cards-grid">{list.map(({ card, context }) => <CardHost key={`${card.module}/${card.name}`} card={card} context={context} page={page} input={input} />)}</div>
|
|
80
|
+
</aside>
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Registered once, before any view renders: registering it in an effect left a view's first paint without its panels.
|
|
85
|
+
setSlotRenderer((p, name) => <SlotHost page={p} name={name} />);
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
/** The view itself, or the screen that explains why it can't run yet. Shared by pages and ACTION modals. Standard feature types (CSV, ITEM) are rendered by the framework from the entry's definition. */
|
|
89
|
+
export function ViewBody({ view, page, framework }: { view: RegistryView; page: Page; framework: Framework }) {
|
|
90
|
+
const input = useShell();
|
|
91
|
+
useStore(services.states);
|
|
92
|
+
const key = viewKey(view);
|
|
93
|
+
const vaultState = useStore({ get: vault.status, subscribe: (fn) => vault.subscribe(fn) });
|
|
94
|
+
const missing = unmet(view, services.isUsable);
|
|
95
|
+
if (missing.length) {
|
|
96
|
+
return (
|
|
97
|
+
<div className="card">
|
|
98
|
+
<h2>Set up {missing.length === 1 ? 'a service' : 'services'} first</h2>
|
|
99
|
+
<p className="muted">This view needs:</p>
|
|
100
|
+
<ul>{missing.map((k) => { const [type, name] = k.split('/'); const s = services.find(type, name); return <li key={k}><a href={router.href.settings('services', type, name)}>{s?.label ?? type} ({k})</a>: {s && !services.stateOf(s).enabled ? 'turned off' : 'not set up'}</li>; })}</ul>
|
|
101
|
+
<p className="muted">Set it up, then come back here.</p>
|
|
102
|
+
</div>
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
const needsVault = view.requires.some((r) => { const s = services.find(r.type, r.name); return !!s && services.stateOf(s).mode !== 'session'; });
|
|
106
|
+
if (needsVault && vaultState === 'locked') return <div className="card"><h2>The vault is locked</h2><p className="muted">This view uses saved credentials.</p><button className="primary" onClick={() => void vault.whenUnlocked()}>Unlock</button></div>;
|
|
107
|
+
|
|
108
|
+
const entry = input.views[key];
|
|
109
|
+
if (view.viewType === 'ITEMS') return <div className="card"><h2>{view.label}</h2><p className="muted">The ITEMS feature type is reserved and not implemented yet.</p></div>;
|
|
110
|
+
if (!entry) return <div className="card"><h2>{view.label}</h2><p className="muted">This view has no component (taco.module.json › entry).</p></div>;
|
|
111
|
+
const context = page.viewContext.get();
|
|
112
|
+
const def = typeof entry === 'function' ? undefined : entry;
|
|
113
|
+
if (def && view.viewType === 'CSV' && def.kind === 'csv') return <Boundary name={`View ${key}`}><CsvFeature def={def} framework={framework} view={view} /></Boundary>;
|
|
114
|
+
if (def && view.viewType === 'ITEM' && def.kind === 'item') return <Boundary name={`View ${key}`}><ItemFeature def={def} framework={framework} page={page} context={context} /></Boundary>;
|
|
115
|
+
if (def || view.viewType === 'CSV' || view.viewType === 'ITEM') return <div className="card danger"><strong>{view.label} is a {view.viewType} view</strong><p className="muted">Its entry must export default {view.viewType === 'CSV' ? 'defineCsvFeature({ … })' : 'defineItemFeature({ … })'}.</p></div>;
|
|
116
|
+
const View = entry as ComponentType<ViewProps>;
|
|
117
|
+
return <Boundary name={`View ${key}`}><View framework={framework} context={context} /></Boundary>;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** Mounts a module view with its page and framework instance, or the screen that explains why it can't run yet. */
|
|
121
|
+
export function ViewHost({ view }: { view: RegistryView }) {
|
|
122
|
+
const input = useShell();
|
|
123
|
+
useStore(services.states);
|
|
124
|
+
const key = viewKey(view);
|
|
125
|
+
const vaultState = useStore({ get: vault.status, subscribe: (fn) => vault.subscribe(fn) });
|
|
126
|
+
// The page lives as long as this view is mounted; it starts with the context showView left in the mailbox.
|
|
127
|
+
const page = useMemo(() => createPage(key, router.takeContext(key)), [key]);
|
|
128
|
+
const framework = useMemo(() => createFramework(view.module, page), [view.module, page]);
|
|
129
|
+
|
|
130
|
+
useEffect(() => {
|
|
131
|
+
// The system tools this view lists in its manifest (ADR-054), for as long as it is open.
|
|
132
|
+
const removeSystem = systemToolsFor(view.tools).map((t) => page.tools.add(t));
|
|
133
|
+
currentPage.set(page);
|
|
134
|
+
const initial = page.viewContext.get();
|
|
135
|
+
if (initial) log.add('debug', `Opened ${key} with context: ${Object.keys(initial).join(', ')}`, initial, 'navigation');
|
|
136
|
+
// Later hand-offs while this view is open arrive live, without a re-mount (ADR-036).
|
|
137
|
+
router.setLiveHandler(key, (ctx) => { log.add('debug', `${key} received context: ${Object.keys(ctx).join(', ')}`, ctx, 'navigation'); deliver(page, ctx); });
|
|
138
|
+
return () => { removeSystem.forEach((r) => r()); router.setLiveHandler(key, null); if (currentPage.get() === page) currentPage.set(null); };
|
|
139
|
+
}, [page, key, input, view.tools]);
|
|
140
|
+
|
|
141
|
+
return <><ViewBody view={view} page={page} framework={framework} /><CardsRegion page={page} view={view} /></>;
|
|
142
|
+
}
|
package/src/ui/hooks.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { createContext, useContext, useSyncExternalStore, type ComponentType } from 'react';
|
|
2
|
+
import type { BackgroundJob, CardProps, FeatureDef, PanelProps, Routine, ServiceImpl, SettingsTabProps, ViewProps } from '@tacoshell/sdk';
|
|
3
|
+
import type { Handlers } from '../core/contrib.ts';
|
|
4
|
+
import type { Registry } from '../types.ts';
|
|
5
|
+
|
|
6
|
+
export const useStore = <T,>(s: { get: () => T; subscribe: (fn: () => void) => () => void }) => useSyncExternalStore(s.subscribe, s.get);
|
|
7
|
+
|
|
8
|
+
export interface ShellInput {
|
|
9
|
+
registry: Registry;
|
|
10
|
+
/** View components by `<module>/<view>` (generated entry). */
|
|
11
|
+
views: Record<string, ComponentType<ViewProps> | FeatureDef>;
|
|
12
|
+
/** Each view entry's named exports (`contributeRelated`, `contributeActions`) by `<module>/<view>`. */
|
|
13
|
+
handlers?: Handlers;
|
|
14
|
+
/** Background jobs by `<module>/<view>`. */
|
|
15
|
+
background?: Record<string, BackgroundJob>;
|
|
16
|
+
/** Service implementations by `<type>/<name>`. */
|
|
17
|
+
services: Record<string, ServiceImpl>;
|
|
18
|
+
/** Panel components by `<module>/<panel>` (ADR-053). */
|
|
19
|
+
panels?: Record<string, ComponentType<PanelProps>>;
|
|
20
|
+
/** Card components by `<module>/<card>` (ADR-062). */
|
|
21
|
+
cards?: Record<string, ComponentType<CardProps<any>>>;
|
|
22
|
+
/** Settings tab components by `<module>/<tab>` (ADR-072). */
|
|
23
|
+
settingsTabs?: Record<string, ComponentType<SettingsTabProps>>;
|
|
24
|
+
/** Refreshable datasets' routines by `<module>/<dataset>` (ADR-043). */
|
|
25
|
+
routines?: Record<string, Routine>;
|
|
26
|
+
}
|
|
27
|
+
export const ShellContext = createContext<ShellInput | null>(null);
|
|
28
|
+
export const useShell = () => useContext(ShellContext)!;
|