// The team canvas (M5): vaults on the left, people on the right, ribbons for who can sync what. // Grant = drag a vault onto a person; revoke = pull a ribbon's dot until it snaps (Undo for 8 s). Every gesture // also has a button in the details panel (X3). import { useEffect, useMemo, useRef, useState } from 'react'; import { MacSection } from './MacApp'; import { api, type CanvasData, type Comparison, type Health, type LogEntry, type Member, type Person, type Role, type Status, type Vault } from './api'; import { HANDLE_T, W, boardHeight, circle, easeBack, lerp, personColor, positions, ribbon, roundRect, vaultColor, type Layout, type Pt, } from './geometry'; const UNDO_SECONDS = 8; const ROLES: Role[] = ['read', 'edit', 'manage']; const roleName = (r: Role) => r.charAt(0).toUpperCase() + r.slice(1); const plural = (n: number, word: string, many = word + 's') => `${n} ${n === 1 ? word : many}`; const keyOf = (m: { vault: string; person: string }) => `${m.vault}|${m.person}`; /** Status colors are reserved for status (X6): green current, amber behind or needs a decision, grey offline, * red only for a possible secret held back. */ const STATUS: Record = { current: '#2E8B5F', behind: '#E09A2B', offline: '#A9A5B6' }; const STATUS_WORDS: Record = { current: 'Current', behind: 'Behind', offline: 'Offline' }; const PILL: Record = { current: ['#E3F2EA', '#1F6B47'], behind: ['#FBEBD3', '#7A4500'], offline: ['#EEECF2', '#5C5770'] }; const SECRET_RED = '#C8323B'; /** A person's freshness is their worst device. */ function worst(p: Person): Status { if (!p.devices.length) return 'offline'; if (p.devices.some((d) => d.health.status === 'behind')) return 'behind'; if (p.devices.some((d) => d.health.status === 'offline')) return 'offline'; return 'current'; } function ago(unix: number | null): string { if (!unix) return 'never'; const s = Math.max(0, Date.now() / 1000 - unix); if (s < 90) return 'just now'; if (s < 3600) return `${Math.round(s / 60)} min ago`; if (s < 86400) return `${Math.round(s / 3600)} h ago`; return plural(Math.round(s / 86400), 'day') + ' ago'; } function healthLine(h: Health): string { const waiting = h.waiting > 0 ? `${plural(h.waiting, 'change')} not shared` : ''; if (h.status === 'offline') return `Offline · last seen ${ago(h.last_seen)}${waiting ? ' · ' + waiting : ''}`; if (h.status === 'behind') return [waiting, h.last_synced ? `last synced ${ago(h.last_synced)}` : ''].filter(Boolean).join(' · ') || 'Something is held on this device'; return `Synced ${ago(h.last_synced)}`; } type Sel = | { kind: 'overview'; back?: Sel } | { kind: 'vault'; id: string; back?: Sel } | { kind: 'person'; id: string; back?: Sel }; type Drag = | { kind: 'grant'; v: string; start: Pt; p: Pt; moved: boolean } | { kind: 'retract'; v: string; p: Pt } | { kind: 'detach'; key: string; p: Pt } | { kind: 'snap'; key: string; p: Pt }; type Toast = { text: string; undo?: () => void }; type Sheet = | 'invite' | 'vault' | { kind: 'compare'; vault: Vault; copy: string } | { kind: 'team'; p: Person } | { kind: 'delete'; v: Vault } | { kind: 'restored'; p: Person; link: string }; function store(key: string, value?: string): string | null { try { if (value !== undefined) localStorage.setItem(key, value); return localStorage.getItem(key); } catch { return null; } } const reducedMotion = () => window.matchMedia?.('(prefers-reduced-motion: reduce)').matches ?? false; export function Canvas({ data, reload, onSignOut }: { data: CanvasData; reload: () => Promise; onSignOut: () => void }) { const [layout, setLayoutState] = useState(store('lune.layout') === 'dock' ? 'dock' : 'float'); const [blend, setBlend] = useState<{ from: Layout; to: Layout; t: number } | null>(null); const [sel, setSel] = useState(null); const [hover, setHover] = useState<{ kind: 'vault' | 'person'; id: string } | null>(null); const [drag, setDrag] = useState(null); const [pinched, setPinched] = useState<{ key: string; p: Pt; t: number } | null>(null); const [toast, setToast] = useState(null); const [sheet, setSheet] = useState(null); const [onboarded, setOnboarded] = useState(store('lune.onboarded') === '1'); const [hidden, setHidden] = useState>(new Set()); const [extra, setExtra] = useState([]); const [log, setLog] = useState([]); const svgRef = useRef(null); const rafs = useRef>({}); const toastTimer = useRef(); const hoverTimer = useRef(); const lastFocus = useRef<{ kind: 'vault' | 'person'; id: string } | null>(null); // Optimistic additions last until fresh data arrives; the hub stays the source of truth. useEffect(() => setExtra([]), [data]); useEffect(() => { const t = window.setInterval(() => reload(), 10000); return () => window.clearInterval(t); }, [reload]); useEffect(() => () => Object.values(rafs.current).forEach(cancelAnimationFrame), []); // Float: every node bobs on one shared clock (X8). useEffect(() => { try { document.getAnimations?.().forEach((a) => { if ((a as CSSAnimation).animationName === 'bob' && a.startTime !== 0) a.startTime = 0; }); } catch { /* older browsers: unsynced bobbing is fine */ } }); useEffect(() => { if (sel?.kind === 'overview' && data.me.owner) api.log(8).then(setLog).catch(() => setLog([])); }, [sel, data]); const vaults = data.vaults; const people = data.people; const vault = (id: string) => vaults.find((v) => v.id === id)!; const person = (id: string) => people.find((p) => p.id === id)!; const pendingKeys = useMemo(() => new Set(data.pending.map(keyOf)), [data]); const members = useMemo( () => [...data.members, ...extra.filter((e) => !data.members.some((m) => keyOf(m) === keyOf(e)))].filter( (m) => !hidden.has(keyOf(m)) && !pendingKeys.has(keyOf(m)), ), [data, extra, hidden, pendingKeys], ); const H = boardHeight(vaults.length, people.length); const at = useMemo( () => ({ float: positions(vaults.map((v) => v.id), people.map((p) => p.id), 'float', H), dock: positions(vaults.map((v) => v.id), people.map((p) => p.id), 'dock', H), }), [vaults, people, H], ); const pos = (id: string): Pt => { if (!blend) return at[layout][id]; const a = at[blend.from][id], c = at[blend.to][id], t = easeBack(blend.t); return { x: lerp(a.x, c.x, t), y: lerp(a.y, c.y, t) }; }; const ends = (m: { vault: string; person: string }) => { const a = pos(m.vault), b = pos(m.person); return { ax: a.x, ay: a.y, bx: b.x, by: b.y }; }; function anim(key: string, ms: number, step: (t: number) => void, done?: () => void) { const t0 = performance.now(); cancelAnimationFrame(rafs.current[key]); const tick = (now: number) => { const t = Math.min(1, (now - t0) / ms); step(t); if (t < 1) rafs.current[key] = requestAnimationFrame(tick); else done?.(); }; rafs.current[key] = requestAnimationFrame(tick); } function say(text: string, undo?: () => void) { setToast({ text, undo }); window.clearTimeout(toastTimer.current); toastTimer.current = window.setTimeout(() => setToast(null), undo ? UNDO_SECONDS * 1000 : 4200); } async function run(action: () => Promise, ok?: string) { try { await action(); if (ok) say(ok); } catch (e) { say((e as Error).message); } finally { await reload(); } } // ---- What the gestures and buttons do ---- function grant(vId: string, pId: string) { const v = vault(vId), p = person(pId); if (members.some((m) => m.vault === vId && m.person === pId)) return say(`${p.name} already has ${v.name}.`); setExtra((x) => [...x, { vault: vId, person: pId, role: 'edit' }]); run( () => (p.invited ? api.inviteGrant(p.name, v.name, 'edit') : api.grant(p.name, v.name, 'edit')), p.invited ? `${v.name} is added to ${p.name}'s invite.` : `${p.name} can now sync ${v.name}. It arrives on their devices within a minute.`, ); } async function revoke(key: string) { const [vId, pId] = key.split('|'); const v = vault(vId), p = person(pId); setHidden((h) => new Set(h).add(key)); const unhide = () => setHidden((h) => { const n = new Set(h); n.delete(key); return n; }); if (p.invited) { await run(() => api.inviteGrant(p.name, v.name, null, true), `${v.name} is off ${p.name}'s invite.`); unhide(); return; } try { const res = await api.remove(p.name, v.name, UNDO_SECONDS); const copies = v.delete_from_devices ? 'then deleted from their devices' : 'then their copy stops updating'; say(`${p.name} removed from ${v.name}. Unshared work comes to you for review, ${copies}.`, async () => { setToast(null); await run(() => api.undoRemove(res.pending!), `${p.name} has ${v.name} again. Nothing changed on their devices.`); unhide(); }); window.setTimeout(() => reload().then(unhide), (UNDO_SECONDS + 1.5) * 1000); } catch (e) { unhide(); say((e as Error).message); } } function cycleRole(m: Member) { const v = vault(m.vault), p = person(m.person); const next = ROLES[(ROLES.indexOf(m.role) + 1) % ROLES.length]; run(() => (p.invited ? api.inviteGrant(p.name, v.name, next) : api.grant(p.name, v.name, next)), `${p.name} now has ${roleName(next)} on ${v.name}.`); } function setLayout(l: Layout) { if (blend || l === layout) return; store('lune.layout', l); if (reducedMotion()) return setLayoutState(l); const from = layout; setBlend({ from, to: l, t: 0 }); anim('layout', 720, (t) => setBlend({ from, to: l, t }), () => { setLayoutState(l); setBlend(null); }); } // ---- Pointer handling ---- const toSvg = (e: React.PointerEvent): Pt => { const svg = svgRef.current; if (!svg) return { x: 0, y: 0 }; const pt = svg.createSVGPoint(); pt.x = e.clientX; pt.y = e.clientY; const q = pt.matrixTransform(svg.getScreenCTM()!.inverse()); return { x: q.x, y: q.y }; }; const capture = (e: React.PointerEvent) => { try { svgRef.current?.setPointerCapture(e.pointerId); } catch { /* fine */ } }; const target = (p: Pt) => { let best: string | null = null, bd = 1e9; for (const pr of people) { if (pr.removed) continue; const q = pos(pr.id), d = Math.hypot(p.x - q.x, p.y - q.y); if (d < bd) { bd = d; best = pr.id; } } return best && bd < 130 ? { id: best, dist: bd } : null; }; function startGrant(vId: string, e: React.PointerEvent) { if (sheet || drag || pinched) return; e.preventDefault(); const p = toSvg(e); capture(e); setDrag({ kind: 'grant', v: vId, start: p, p, moved: false }); } function startDetach(key: string, e: React.PointerEvent) { if (sheet || drag || pinched) return; e.preventDefault(); capture(e); setDrag({ kind: 'detach', key, p: toSvg(e) }); } function onMove(e: React.PointerEvent) { if (!drag || (drag.kind !== 'grant' && drag.kind !== 'detach')) return; const p = toSvg(e); if (drag.kind === 'grant') setDrag({ ...drag, p, moved: drag.moved || Math.hypot(p.x - drag.start.x, p.y - drag.start.y) > 6 }); else setDrag({ ...drag, p }); } function onUp() { const d = drag; if (!d) return; if (d.kind === 'grant') { if (!d.moved) { setDrag(null); setSel({ kind: 'vault', id: d.v }); return; } const t = target(d.p); if (t && t.dist < 75) { setDrag(null); grant(d.v, t.id); return; } const a = pos(d.v), p0 = d.p; setDrag({ kind: 'retract', v: d.v, p: p0 }); anim('drag', 260, (t) => { const k = 1 - Math.pow(1 - t, 3); setDrag({ kind: 'retract', v: d.v, p: { x: lerp(p0.x, a.x, k), y: lerp(p0.y, a.y, k) } }); }, () => setDrag(null)); } else if (d.kind === 'detach') { const [vId, pId] = d.key.split('|'); const e = ends({ vault: vId, person: pId }); const h0 = { x: lerp(e.ax, e.bx, HANDLE_T), y: lerp(e.ay, e.by, HANDLE_T) }; if (Math.hypot(d.p.x - h0.x, d.p.y - h0.y) > 110) { const key = d.key, P = d.p; setDrag(null); setPinched({ key, p: P, t: 0 }); anim('pinch', reducedMotion() ? 1 : 300, (t) => setPinched({ key, p: P, t }), () => { setPinched(null); revoke(key); }); } else { const q0 = d.p; setDrag({ kind: 'snap', key: d.key, p: q0 }); anim('drag', 240, (t) => { const k = 1 - Math.pow(1 - t, 3); setDrag({ kind: 'snap', key: d.key, p: { x: lerp(q0.x, h0.x, k), y: lerp(q0.y, h0.y, k) } }); }, () => setDrag(null)); } } } // ---- Drawing ---- const bob = !blend && layout === 'float' && !reducedMotion() ? 'bob' : ''; const grantDrag = drag && drag.kind === 'grant' && drag.moved ? drag : null; const tgt = grantDrag ? target(grantDrag.p) : null; const hot = tgt && tgt.dist < 75 ? tgt.id : null; const focus = !drag && hover ? hover : sel && (sel.kind === 'vault' || sel.kind === 'person') ? { kind: sel.kind, id: sel.id } : null; if (focus) lastFocus.current = focus; const relV = (vId: string) => !focus || (focus.kind === 'vault' ? focus.id === vId : members.some((m) => m.vault === vId && m.person === focus.id)); const relP = (pId: string) => !focus || (focus.kind === 'person' ? focus.id === pId : members.some((m) => m.person === pId && m.vault === focus.id)); const pct = (x: number, y: number): React.CSSProperties => ({ position: 'absolute', left: `${(x / W) * 100}%`, top: `${(y / H) * 100}%` }); const leave = () => { window.clearTimeout(hoverTimer.current); hoverTimer.current = window.setTimeout(() => setHover(null), 90); }; const enter = (kind: 'vault' | 'person', id: string) => { window.clearTimeout(hoverTimer.current); if (!drag) setHover({ kind, id }); }; const blobs: { d: string; fill: string; delay: string; op: number }[] = []; const labels: { text: string; style: React.CSSProperties; inner: React.CSSProperties }[] = []; const ribbons: { d: string; fill: string; op?: number; dim?: number }[] = []; const handles: { key: string; x: number; y: number; dim: boolean }[] = []; const grips: { x: number; y: number; r: number }[] = []; const grads: { id: string; x1: number; y1: number; x2: number; y2: number; c1: string; c2: string }[] = []; vaults.forEach((v, i) => { const p = pos(v.id), delay = (i * 0.7).toFixed(1), vo = relV(v.id) ? 1 : 0.35; // Amber means a decision is waiting (X6): notes to tidy, handovers to review. const review = v.handovers.filter((h) => h.state === 'received').length, tidy = v.tidy.length; const decide = review + tidy; if (decide > 0) { labels.push({ text: tidy && !review ? `${tidy} to tidy` : review && !tidy ? plural(review, 'handover') : `${decide} to decide`, style: { ...pct(p.x + 34, p.y - 40), transform: 'translate(-50%,-50%)', opacity: vo }, inner: { display: 'inline-block', whiteSpace: 'nowrap', fontWeight: 700, fontSize: 'max(1.05cqw, 9px)', color: '#7A4500', background: '#FBEBD3', border: '1px solid #E09A2B', borderRadius: 999, padding: '0.15em 0.7em', animationDelay: `${delay}s` }, }); } blobs.push({ d: roundRect(p.x, p.y, 138, 70, 26), fill: vaultColor(v.id).fill, delay, op: focus && relV(v.id) ? 1 : 0 }); labels.push({ text: v.name, style: { ...pct(p.x - 20, p.y), transform: 'translateY(-50%)', opacity: vo, transition: 'opacity .2s' }, inner: { display: 'inline-block', whiteSpace: 'nowrap', fontWeight: 700, fontSize: 'max(1.4cqw, 10px)', animationDelay: `${delay}s`, maxWidth: '8.2cqw', overflow: 'hidden', textOverflow: 'ellipsis' }, }); }); people.forEach((pr, i) => { const p = pos(pr.id), delay = (0.35 + i * 0.6).toFixed(1), po = pr.removed ? 0.45 : relP(pr.id) ? 1 : 0.35; if (!pr.invited && !pr.removed) blobs.push({ d: circle(p.x, p.y, 38), fill: personColor(pr.id).fill, delay, op: focus && relP(pr.id) ? 1 : 0 }); labels.push({ text: pr.name.charAt(0).toUpperCase(), style: { ...pct(p.x, p.y), transform: 'translate(-50%,-50%)', opacity: po }, inner: { display: 'inline-block', fontWeight: 700, fontSize: 'max(2cqw, 12px)', animationDelay: `${delay}s` } }); labels.push({ text: pr.invited ? `${pr.name} · invited` : pr.removed ? `${pr.name} · removed` : pr.name, style: { ...pct(p.x, p.y + 48), transform: 'translate(-50%,-50%)', opacity: po }, inner: { display: 'inline-block', whiteSpace: 'nowrap', fontSize: 'max(1.3cqw, 10px)', animationDelay: `${delay}s` }, }); }); for (const m of members) { const key = keyOf(m), e = ends(m), gid = `g-${key.replace(/[^a-zA-Z0-9]/g, '-')}`, fill = `url(#${gid})`; grads.push({ id: gid, x1: e.ax, y1: e.ay, x2: e.bx, y2: e.by, c1: vaultColor(m.vault).fill, c2: personColor(m.person).fill }); const dim = !!(focus && ((focus.kind === 'vault' && focus.id !== m.vault) || (focus.kind === 'person' && focus.id !== m.person))); const h0 = { x: lerp(e.ax, e.bx, HANDLE_T), y: lerp(e.ay, e.by, HANDLE_T) }; if (pinched?.key === key) { const P = pinched.p, shrink = 1 - pinched.t; ribbons.push({ d: ribbon(e.ax, e.ay, lerp(e.ax, P.x, 0.45 * shrink), lerp(e.ay, P.y, 0.45 * shrink), 14, 3, 0.6), fill }); ribbons.push({ d: ribbon(e.bx, e.by, lerp(e.bx, P.x, 0.3 * shrink), lerp(e.by, P.y, 0.3 * shrink), 11, 4, 0.6), fill }); continue; } const active = drag && (drag.kind === 'detach' || drag.kind === 'snap') && drag.key === key ? drag.p : null; if (active) { const P = active, dist = Math.hypot(P.x - h0.x, P.y - h0.y), neck = dist < 110 ? 4 + 4 * (1 - dist / 110) : 0; if (neck > 0.5) { ribbons.push({ d: ribbon(e.ax, e.ay, P.x, P.y, 16, Math.max(4, neck * 0.8), neck), fill }); ribbons.push({ d: ribbon(P.x, P.y, e.bx, e.by, neck, Math.max(4, neck * 0.8), 11), fill }); grips.push({ x: P.x, y: P.y, r: 7 }); } else { ribbons.push({ d: ribbon(e.ax, e.ay, lerp(e.ax, P.x, 0.45), lerp(e.ay, P.y, 0.45), 14, 3, 0.6), fill }); ribbons.push({ d: ribbon(e.bx, e.by, lerp(e.bx, P.x, 0.3), lerp(e.by, P.y, 0.3), 9, 3, 0.6), fill }); grips.push({ x: P.x, y: P.y, r: 5 }); } } else { ribbons.push({ d: ribbon(e.ax, e.ay, e.bx, e.by, 16, 4.5, 11), fill, dim: focus && !dim ? 1 : 0 }); const pr = person(m.person); // You can't pull your own ribbon, nor the team owner's (they always keep access). if (vault(m.vault).can_manage && !pr.owner && pr.id !== data.me.id) handles.push({ key, x: h0.x, y: h0.y, dim }); } } let ghost: { d: string; cx: number; cy: number; c2: string } | null = null; if (drag && ((drag.kind === 'grant' && drag.moved) || drag.kind === 'retract')) { const a = pos(drag.v); let E = drag.p; if (tgt) { const q = pos(tgt.id), k = Math.max(0, Math.min(1, 1 - tgt.dist / 130)) * 0.55; E = { x: lerp(E.x, q.x, k), y: lerp(E.y, q.y, k) }; } const c2 = tgt ? personColor(tgt.id).fill : vaultColor(drag.v).fill; grads.push({ id: 'g-ghost', x1: a.x, y1: a.y, x2: E.x, y2: E.y, c1: vaultColor(drag.v).fill, c2 }); ghost = { d: ribbon(a.x, a.y, E.x, E.y, 16, 4.5, 9), cx: E.x, cy: E.y, c2 }; } let hint = '', hintHot = false; if (grantDrag) { hint = hot ? `Release to give ${person(hot).name} access to ${vault(grantDrag.v).name}.` : 'Drop on a person to give access.'; hintHot = !!hot; } if (drag?.kind === 'detach') { const [vId, pId] = drag.key.split('|'), e = ends({ vault: vId, person: pId }); const far = Math.hypot(drag.p.x - lerp(e.ax, e.bx, HANDLE_T), drag.p.y - lerp(e.ay, e.by, HANDLE_T)) > 110; hint = far ? `Release to remove ${person(pId).name} from ${vault(vId).name}.` : 'Pull further to remove access.'; hintHot = far; } const manages = vaults.some((v) => v.can_manage); const back = sel?.back; const backLabel = !back ? '' : back.kind === 'overview' ? 'Vaults & people' : back.kind === 'vault' ? vault(back.id)?.name : person(back.id)?.name; const open = (s: Sel) => setSel({ ...s, back: sel ?? undefined }); const boardStyle: React.CSSProperties = { width: `min(100%, calc((100dvh - 160px) * ${W / H}))`, aspectRatio: `${W} / ${H}` }; return (
Team canvas {plural(vaults.length, 'vault')} · {plural(people.filter((p) => !p.invited).length, 'person', 'people')}
{manages && }
{ if (e.target === e.currentTarget && !drag) setSel(null); }}> {vaults.length === 0 ? (

No vaults yet

{data.me.owner ? 'Create one here, or move an existing vault onto the hub with `lunesync vault upload`.' : 'When someone gives you a vault, it shows up here.'}

{data.me.owner && }
) : (
{grads.map((g) => ( ))} { if (!drag) setSel(null); }} /> VAULTS PEOPLE {/* Ribbons and node halos melt together (X4); a focused node's set is redrawn bright on top (X7). */} {ribbons.map((r, i) => )} {blobs.map((b, i) => )} {ghost && <>} {ribbons.filter((r) => r.dim !== undefined).map((r, i) => )} {blobs.map((b, i) => )} {ghost && } {grips.map((g, i) => )} {vaults.map((v, i) => { const p = pos(v.id), c = vaultColor(v.id), on = sel?.kind === 'vault' && sel.id === v.id, veil = relV(v.id) ? 0 : 0.65; return ( (v.can_manage ? startGrant(v.id, e) : undefined)} onClick={() => { if (!v.can_manage) setSel({ kind: 'vault', id: v.id }); }} onPointerEnter={() => enter('vault', v.id)} onPointerLeave={leave} style={{ cursor: v.can_manage ? 'grab' : 'pointer' }} > ); })} {people.map((pr, i) => { const p = pos(pr.id), c = personColor(pr.id), on = sel?.kind === 'person' && sel.id === pr.id; const veil = relP(pr.id) ? 0 : 0.65, n = pr.devices.length; const angles = n === 1 ? [18] : n === 2 ? [-30, 30] : pr.devices.map((_, j) => -40 + (j * 80) / Math.max(1, n - 1)); return ( {pr.devices.map((d, j) => { const a = (angles[j] * Math.PI) / 180, cx = Math.cos(a) * 52, cy = Math.sin(a) * 52; return ( 0 ? SECRET_RED : STATUS[d.health.status]} stroke="#FFFFFF" strokeWidth="2" /> ); })} { if (!drag) setSel({ kind: 'person', id: pr.id }); }} onPointerEnter={() => enter('person', pr.id)} onPointerLeave={leave} style={{ cursor: 'pointer' }}> ); })} {handles.map((h) => ( startDetach(h.key, e)} style={{ cursor: 'grab' }}> ))}
)}
{hint && {hint}} {(Object.keys(STATUS) as Status[]).map((s) => {STATUS_WORDS[s]})} Possible secret held
{!onboarded && manages && vaults.length > 0 && (
Two moves to know
1Drag a vault onto a person to give them access.
2Pull the dot on a ribbon until it snaps to take access back. You can undo.
Click any vault or person for details and buttons.
)} {sel && ( )} {sheet === 'invite' && v.can_manage)} owner={data.me.owner} close={() => { setSheet(null); reload(); }} />} {typeof sheet === 'object' && sheet?.kind === 'compare' && ( m.vault === sheet.vault.id && m.person === data.me.id)?.role ?? '')} close={() => setSheet(null)} resolve={(keep) => { const s = sheet; setSheet(null); run(async () => say((await api.resolve(s.vault.name, s.copy, keep)).message)); }} /> )} {typeof sheet === 'object' && sheet?.kind === 'team' && ( setSheet(null)} confirm={() => { const p = sheet.p; setSheet(null); setSel({ kind: 'person', id: p.id }); run(() => api.teamRemove(p.name), `${p.name} was removed from the team. Their devices send unshared work, then delete every vault copy.`); }} /> )} {typeof sheet === 'object' && sheet?.kind === 'delete' && ( setSheet(null)} confirm={() => { const v = sheet.v; setSheet(null); setSel(null); run(() => api.deleteVault(v.name), `${v.name} was deleted. Every device sends unshared work, then removes its copy.`); }} /> )} {typeof sheet === 'object' && sheet?.kind === 'restored' && (
{ if (e.target === e.currentTarget) setSheet(null); }}>

{sheet.p.name} is back on the team

They start with no vaults — give them some by dragging. Send them this one-time sign-in link (7 days):

lunesync join {sheet.link} --name "<their device>"
)} {sheet === 'vault' && setSheet(null)} create={(name) => { setSheet(null); run(() => api.createVault(name), `${name} is ready. Drag it onto people to share it.`); }} />}
{toast && (
{toast.text} {toast.undo && }
)}
); } function Avatar({ p }: { p: Person }) { const c = personColor(p.id); const ring = p.invited ? c.ring : p.removed ? STATUS.offline : STATUS[worst(p)]; return {p.name.charAt(0).toUpperCase()}; } function Swatch({ v }: { v: Vault }) { const c = vaultColor(v.id); return ( ); } function CloseButton({ close }: { close: () => void }) { return ; } function Overview({ data, members, log, open, close, newVault, signOut }: { data: CanvasData; members: Member[]; log: LogEntry[]; open: (s: Sel) => void; close: () => void; newVault: () => void; signOut: () => void; }) { return ( <>

Vaults & people

Vaults

{data.vaults.length}
{data.vaults.map((v) => ( ))} {data.me.owner && }

People

{data.people.length}
{data.people.map((p) => ( ))}
{data.me.owner && log.length > 0 && (

Recent activity

    {log.map((e, i) => (
  1. {e.actor} · {e.action}: {e.detail}{new Date(e.at * 1000).toLocaleString()}
  2. ))}
)}
Signed in as {data.me.person}
); } function VaultPanel({ v, data, members, open, close, cycleRole, remove, grant, toggleDelete, run, compare, deleteVault }: { v: Vault; data: CanvasData; members: Member[]; open: (s: Sel) => void; close: () => void; deleteVault?: (v: Vault) => void; cycleRole: (m: Member) => void; remove: (m: Member) => void; grant: (v: string, p: string) => void; toggleDelete: (v: Vault) => void; run: (action: () => Promise, ok?: string) => Promise; compare: (copy: string) => void; }) { const inVault = members.filter((m) => m.vault === v.id); const outside = data.people.filter((p) => !p.removed && !inVault.some((m) => m.person === p.id)); const mine = inVault.find((m) => m.person === data.me.id); return ( <>
Vault · {plural(inVault.length, 'person', 'people')}

{v.name}

{!v.can_manage && mine &&
You have {roleName(mine.role)} access. People with Manage decide who else can sync it.
} {v.tidy.length > 0 && (
{plural(v.tidy.length, 'note')} to tidy Changed in two places at once. Both versions are kept, so nothing is lost. {v.tidy.map((t) => (
{t.note}
))}
)} {v.handovers.map((h) => )}

People with access

{inVault.map((m) => { const p = data.people.find((x) => x.id === m.person)!; // Your own row and the team owner's can't be changed here (no locking yourself out by accident). const fixed = p.owner || p.id === data.me.id; return (
{v.can_manage && !fixed ? ( ) : ( {roleName(m.role)} )} {v.can_manage && !fixed && ( )}
); })}
{v.can_manage && outside.length > 0 && (

Give access

{outside.map((p) => )}
)} {v.can_manage && (

When someone is removed

Removing someone only affects this vault. Copies made elsewhere can't be recalled.

)} {deleteVault && (
)} ); } /** Deleting a vault asks first: it ends everyone's access at once (team owner only). */ function DeleteVaultDialog({ v, members, close, confirm }: { v: Vault; members: Member[]; close: () => void; confirm: () => void }) { const people = members.filter((m) => m.vault === v.id).length; return (
{ if (e.target === e.currentTarget) close(); }}>

Delete {v.name}?

{plural(people, 'person', 'people')} lose access. Their devices first send anything not yet shared, then remove their copy{v.delete_from_devices ? '' : ' (or keep it read-only, as this vault is set)'}.

The vault's history stays archived on the hub, so nothing is lost; the name {v.name} is free for a new vault. Copies made elsewhere can't be recalled.

); } function PersonPanel({ p, data, members, open, close, run, removeFromTeam, restore }: { p: Person; data: CanvasData; members: Member[]; open: (s: Sel) => void; close: () => void; run: (action: () => Promise, ok?: string) => Promise; removeFromTeam: (p: Person) => void; restore: (p: Person) => void; }) { const [renaming, setRenaming] = useState<{ id: string; value: string } | null>(null); const theirs = members.filter((m) => m.person === p.id); const canEditDevices = p.id === data.me.id || data.me.owner; const eyebrow = p.invited ? 'Invited' : p.removed ? 'Removed from team' : p.owner ? 'Team owner' : 'Team member'; const leaving = data.vaults.flatMap((v) => v.handovers.filter((h) => h.person === p.name && h.state === 'waiting').map((h) => ({ ...h, vault: v }))); return ( <>
{eyebrow}

{p.name}

{p.invited &&
{p.name} hasn't joined yet. Vaults you give them now arrive once they join with their invite link.
} {p.removed && (

This account is disabled. Past changes keep this name in history.

{data.me.owner && }
)} {leaving.length > 0 && (
Leaving {leaving.map((h) => (
{h.device} hasn't reported in since losing {h.vault.name}. Its unshared work comes back when it's next online.
))}
)} {!p.invited && !p.removed && (

Devices

{p.devices.length === 0 &&

{canEditDevices ? 'No devices yet.' : "Only their vault managers see someone's devices."}

} {p.devices.map((d) => (
{renaming?.id === d.id ? (
{ e.preventDefault(); const label = renaming.value.trim(); setRenaming(null); if (label && label !== d.label) run(() => api.renameDevice(d.id, label), `Renamed to ${label}. New history entries carry this name.`); }}> setRenaming({ id: d.id, value: e.target.value })} autoFocus maxLength={40} />
) : ( <>
{d.label} {STATUS_WORDS[d.health.status]}
{healthLine(d.health)} {d.health.held_secrets > 0 && ( {plural(d.health.held_secrets, 'note')} held back: possible secret, not shared. Its owner decides with lunesync held. )} {d.health.holding && A big change is held here, waiting for its owner to share or undo it.} )} {canEditDevices && renaming?.id !== d.id && (
{d.health.waiting > 0 && ( )}
)}
))}
)}

Vaults

{theirs.length === 0 &&

None yet. Drag a vault onto {p.name} to share it.

} {theirs.map((m) => { const v = data.vaults.find((x) => x.id === m.vault)!; return ( ); })}
{data.me.owner && !p.owner && !p.removed && !p.invited && (

Ends every vault and device for this person. The account is disabled and can be restored.

)} ); } /** A handover waiting for a manager: received work to review, or a device that hasn't reported in. */ function HandoverCard({ h, vault, run }: { h: Vault['handovers'][number]; vault: Vault; run: (action: () => Promise, ok?: string) => Promise }) { const [files, setFiles] = useState(null); if (h.state === 'waiting') { return (
{h.person} is leaving {vault.name} {h.device} hasn't reported in yet. Its unshared work comes to you when it's next online.
); } return (
{h.person}'s last changes from {h.device} These arrived in a final sync after the removal. Review before they join the vault. {files === null ? ( ) : (
    {files.map((f) =>
  • {f}
  • )}
)}
); } /** Both versions of a note side by side (J3); lines only in one version are highlighted. */ function CompareDialog({ vault, copy, canEdit, close, resolve }: { vault: Vault; copy: string; canEdit: boolean; close: () => void; resolve: (keep: 'note' | 'copy' | 'both') => void; }) { const [c, setC] = useState(null); const [error, setError] = useState(''); useEffect(() => { api.compare(vault.name, copy).then(setC).catch((e) => setError(e.message)); }, [vault, copy]); const column = (title: string, text: string | null, other: string | null, tint: string) => { const others = new Set((other ?? '').split('\n')); return (
{title}
{text === null ? Not shown (not a text note, or very large). : text.split('\n').map((line, i) =>
{line || '\u00a0'}
)}
); }; return (
{ if (e.target === e.currentTarget) close(); }}>
{vault.name} · {c?.note ?? ''}

Two versions of the same lines

{error &&

{error}

} {c && (
{column(c.note_exists ? 'In the vault' : 'In the vault (removed since)', c.note_text, c.copy_text, '#FBEBD3')} {column(`${c.label}'s version · kept beside it`, c.copy_text, c.note_text, '#E8E1FB')}
)} {c && !canEdit &&

You have read access, so you can look but not choose.

}
{c && canEdit && ( <> {c.note_exists && } )}
); } /** The only gesture on the canvas that asks first (X2, A8). */ function TeamDialog({ p, data, members, close, confirm }: { p: Person; data: CanvasData; members: Member[]; close: () => void; confirm: () => void }) { const theirs = members.filter((m) => m.person === p.id).map((m) => data.vaults.find((v) => v.id === m.vault)?.name ?? ''); const waiting = p.devices.reduce((n, d) => n + d.health.waiting, 0); return (
{ if (e.target === e.currentTarget) close(); }}>

Remove {p.name} from the team?

{p.name} is in {plural(theirs.length, 'vault')}{theirs.length ? ` (${theirs.join(', ')})` : ''} on {plural(p.devices.length, 'device')}. All access ends and every vault copy is deleted from those devices.

{waiting > 0 &&

{plural(waiting, 'change')} haven't been shared yet. They'll be sent to the team for review before anything is deleted.

}

The account is disabled, not deleted, and can be restored. Past changes keep {p.name}'s name in history. Copies made elsewhere can't be recalled.

); } function InviteDialog({ vaults, owner, close }: { vaults: Vault[]; owner: boolean; close: () => void }) { const [name, setName] = useState(''); const [picked, setPicked] = useState>(new Set()); const [link, setLink] = useState(''); const [error, setError] = useState(''); const [copied, setCopied] = useState(false); const create = async (e: React.FormEvent) => { e.preventDefault(); try { const grants = vaults.filter((v) => picked.has(v.id)).map((v) => ({ vault: v.name, role: 'edit' as Role })); setLink((await api.invite(name.trim(), grants)).link); setError(''); } catch (err) { setError((err as Error).message); } }; const command = `lunesync join ${link} --name ""`; return (
{ if (e.target === e.currentTarget) close(); }}>

Invite a person

{!link ? (
setName(e.target.value)} placeholder="Sari" autoFocus /> {vaults.length > 0 && (
Vaults they get (Edit){owner ? ' — optional' : ''} {vaults.map((v) => ( ))}
)}

You'll get a one-time link to send them. They join with the sync app and appear here; give them more vaults by dragging.

{error &&

{error}

}
) : ( <>

Send this to {name.trim()} over a channel you trust. It works once, for 7 days. They run:

{command}
)}
); } function NewVaultDialog({ close, create }: { close: () => void; create: (name: string) => void }) { const [name, setName] = useState(''); return (
{ if (e.target === e.currentTarget) close(); }}>
{ e.preventDefault(); if (name.trim()) create(name.trim()); }}>

New vault

setName(e.target.value)} placeholder="DevOps" autoFocus />

It starts empty and arrives on your devices within a minute. To move an existing vault here, use lunesync vault upload.

); }