/** @jsxImportSource orca */ import { atom, Badge, Button, derived, EmptyState, Heading, IconButton, Input, List, ListItem, on, read, Row, set, Stack, Switch, Text, update, type PanelContext } from 'orca' type Todo = { id: number; title: string; done: boolean } // Persisted for the plugin: the list survives closing the panel and restarting Orca. const todos = atom( 'todos', [ { id: 1, title: 'Read the components guide', done: true }, { id: 2, title: 'Build a panel', done: false } ], { persist: 'plugin' } ) const hideDone = atom('hide-done', false, { persist: 'plugin' }) const draft = atom('') const open = derived(() => read(todos).filter((todo) => !todo.done).length) function add(): void { const title = read(draft).trim() if (!title) { return } update(todos, (list) => [ ...list, { id: Math.max(0, ...list.map((t) => t.id)) + 1, title, done: false } ]) set(draft, '') } function toggle(id: number): void { update(todos, (list) => list.map((todo) => (todo.id === id ? { ...todo, done: !todo.done } : todo)) ) } function TodoList({ items }: { items: Todo[] }) { if (items.length === 0) { return } return ( {items.map((todo) => ( toggle(todo.id)} /> ))} ) } const seenThemes = atom(0) /** Optional: runs once before the first render; its subscriptions end when the panel closes. */ export function setup(ctx: PanelContext): void { ctx.subscriptions.push(on('theme', () => update(seenThemes, (n) => n + 1))) } export default function Panel() { const all = read(todos) const items = read(hideDone) ? all.filter((todo) => !todo.done) : all const count = read(open) return ( Tasks 0 ? 'accent' : 'neutral'}>{count} open set(draft, value)} onSubmit={add} /> set(hideDone, value)} /> Runs isolated with no network; Orca draws every control. Theme changes seen:{' '} {read(seenThemes)}. ) }