zidane-ui/ app/ headless
import { … } from 'zidane-ui/app/headless'ui/src/app/headless/index.ts
Functions#
createResourceStoreFunction#
A new resource store over an invalidation source.
function createResourceStore<Topic extends string = string>(
options?: ResourceStoreOptions<Topic>,
): ResourceStore<Topic>Type parameters
| Name | Type | Default | Description |
|---|---|---|---|
| Topic | extends string | string |
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
| options? | ResourceStoreOptions<Topic> | {} | The event source, the watched topics and the focus signal. |
Returns
ResourceStore<Topic>readableResourceFunction#
One resource of a store as a readable value (get + subscribe, the shape hosts hand to components):
subscribing keeps it live like a mounted reader. Both methods keep their identity.
function readableResource<T, Topic extends string = string>(
store: ResourceStore<Topic>,
spec: ResourceSpec<T, Topic>,
): { get(): ResourceSnapshot<T>; subscribe(listener: () => void): () => void }Type parameters
| Name | Type | Default | Description |
|---|---|---|---|
| T | |||
| Topic | extends string | string |
Parameters
| Name | Type | Description |
|---|---|---|
| store | ResourceStore<Topic> | The store holding it. |
| spec | ResourceSpec<T, Topic> | The resource. |
Returns
{ get(): ResourceSnapshot<T>; subscribe(listener: () => void): () => void }resourceEventMatchesFunction#
Whether event concerns a resource with options: its topic is listed, and absent fields on either side
mean "any"; folders match when one holds the other (a repo root vs a subfolder).
function resourceEventMatches<Topic extends string>(
event: ResourceEvent<Topic>,
options: ResourceOptions<Topic>,
): booleanType parameters
| Name | Type | Description |
|---|---|---|
| Topic | extends string |
Parameters
| Name | Type | Description |
|---|---|---|
| event | ResourceEvent<Topic> | An invalidation event. |
| options | ResourceOptions<Topic> | A resource's options. |
Returns
booleanConstants#
IDLE_RESOURCEConstant#
What a null spec reads.
const IDLE_RESOURCE: ResourceSnapshot<never>Interfaces#
AppHostInterface#
Every area's host an app offers. An area whose host is absent is not shown.
interface AppHostProperties
| Name | Type | Description |
|---|---|---|
| appearance? | AppearanceHost | Where the appearance preferences live, the extra themes, the pre-paint snapshot and the window effects. Absent: the app applies no appearance (the stylesheet's defaults). |
| approvals? | ApprovalsHost | Tool approvals (safe mode): the pending approvals, the decisions and the safelist. Absent: no approval UI. |
| chat? | ChatHost | The chat area: sessions, transcripts, sending and interactions. Absent: no chat. |
| composer? | ComposerHost | The rich composer's host: shared drafts, completions, ghost text and next-prompt suggestions. Absent: those stay off ( |
| extensions? | ExtensionsHost | What the extensions behind the app contribute (slots, screens, renderers, dialogs, settings pages, webviews) and the way back to them. Absent: no extension UI. |
| files? | FilesHost | The Files and Diffs tabs' host: listing, reading, writing and searching files, git status, the working-tree diff and the editor preferences. Absent: no Files or Diffs tab. |
| git? | GitHost | The git area's host: branches and pull requests, worktrees, environment kinds and remote folders. Absent: no branch menu, no remote folder picker. |
| keybindings? | KeybindingsHost | Where the user's keybinding overrides live. Absent: the default bindings. |
| machines? | MachinesHost | Which agent hosts the app talks to and how they are: servers, machines, self-update, tokens, the local daemon. Absent: no host status, banners or server settings. |
| onboarding? | OnboardingHost | The setup wizard's host: detection, settings, sign-in and the commit. Absent: no onboarding. |
| palette? | PaletteHost | The command palette's host: commands, files, extension items, settings and recents. Absent: the palette lists only the app's own sources. |
| session? | SessionHost | The session panels' host: todos, the message queue and artifacts. Absent: no session panels. |
| settings? | SettingsHost | The zidane settings document: read, written through when this connection may. Absent: no settings rows. |
| sidebar? | SidebarHost | The session sidebar's platform members: Finder, standalone windows, environment commands. Absent: those menu rows hide. |
| terminal? | TerminalHost | The terminals: listing, opening and viewing them per scope. Absent: no terminal drawer or tab. |
| workspace? | WorkspaceHost<WorkspaceScope> | Where the side panel's layouts live, and the extension panels. Absent: layouts last as long as the page, no extension panels. |
ResourceEventInterface#
An invalidation event: a topic, and the scope it is about (absent fields: any).
interface ResourceEvent<Topic extends string = string> extends ResourceScopeType parameters
| Name | Type | Default | Description |
|---|---|---|---|
| Topic | extends string | string |
Properties
| Name | Type | Description |
|---|---|---|
cwd?from ResourceScope | string | The folder (an event about a folder that holds it, or that it holds, concerns it). |
hostId?from ResourceScope | string | The host (this computer's or a server's id). |
sessionId?from ResourceScope | string | The session. |
| topic | Topic | What changed. |
ResourceInvalidationInterface#
Where invalidation events come from (an app's IPC, a server's signals).
interface ResourceInvalidation<Topic extends string = string>Type parameters
| Name | Type | Default | Description |
|---|---|---|---|
| Topic | extends string | string |
Properties
| Name | Type | Description |
|---|---|---|
| onInvalidate | (listener: (event: ResourceEvent<Topic>) => void) => () => void | Calls |
| unwatch? | (topic: Topic, cwd: string) => unknown | Stop emitting it. |
| watch? | (topic: Topic, cwd: string) => unknown | Start emitting a watched topic for a folder. |
ResourceOptionsInterface#
How a resource stays current.
interface ResourceOptions<Topic extends string = string>Type parameters
| Name | Type | Default | Description |
|---|---|---|---|
| Topic | extends string | string |
Properties
| Name | Type | Description |
|---|---|---|
| revalidateOnFocus? | boolean | Refetch (when old) as the window regains focus. |
| scope? | ResourceScope | What the data is about. |
| topics? | readonly Topic[] | Topics whose events stale this resource. |
| ttl? | number | A new reader refetches data older than this (ms). |
ResourceScopeInterface#
What a resource's data is about; an event naming another folder, server or session leaves it alone.
interface ResourceScopeProperties
| Name | Type | Description |
|---|---|---|
| cwd? | string | The folder (an event about a folder that holds it, or that it holds, concerns it). |
| hostId? | string | The host (this computer's or a server's id). |
| sessionId? | string | The session. |
ResourceSnapshotInterface#
A resource as read: immutable, replaced only when something changed.
interface ResourceSnapshot<T>Type parameters
| Name | Description |
|---|---|
| T |
Properties
| Name | Type | Description |
|---|---|---|
| data | T | undefined | The last data fetched. |
| error | unknown | The last fetch's error. |
| refresh | () => Promise<void> | Refetch now; keeps its identity for the life of the entry. |
| stale | boolean |
|
| status | ResourceStatus | See |
ResourceSpecInterface#
One kind of data: the same key and fetcher wherever it is read.
interface ResourceSpec<T, Topic extends string = string>Type parameters
| Name | Type | Default | Description |
|---|---|---|---|
| T | |||
| Topic | extends string | string |
Properties
| Name | Type | Description |
|---|---|---|
| fetcher | () => Promise<T> | Reads the data. |
| key | ResourceKey | The resource's identity. |
| options? | ResourceOptions<Topic> | How it stays current; the first read of a key decides. |
ResourceStoreInterface#
A store of resources; see the top of this file.
interface ResourceStore<Topic extends string = string>Type parameters
| Name | Type | Default | Description |
|---|---|---|---|
| Topic | extends string | string |
Properties
| Name | Type | Description |
|---|---|---|
| fetch | <T>(spec: ResourceSpec<T, Topic>) => Promise<T> | The data now: a fresh value is reused and an in-flight fetch joined. Rejects with the fetch's error. |
| keyOf | (key: ResourceKey) => string | The serialized form of a key: what |
| peek | <T>(spec: ResourceSpec<T, Topic>) => ResourceSnapshot<T> | The snapshot |
| peekKey | (id: string) => ResourceSnapshot<unknown> | The snapshot a serialized key holds now ( |
| reset | () => void | Forget every entry and listener, and unhook the event source (tests). |
| subscribe | <T>(spec: ResourceSpec<T, Topic>, onChange: (snapshot: ResourceSnapshot<T>) => void) => () => void | Keep |
| subscribeInvalidation | (options: ResourceOptions<Topic>, listener: (event: ResourceEvent<Topic>) => void) => () => void |
|
| watch | <T>(spec: ResourceSpec<T, Topic>, listener: () => void) => () => void | Keep |
ResourceStoreOptionsInterface#
Options of createResourceStore.
interface ResourceStoreOptions<Topic extends string = string>Type parameters
| Name | Type | Default | Description |
|---|---|---|---|
| Topic | extends string | string |
Properties
| Name | Type | Description |
|---|---|---|
| invalidation? | () => ResourceInvalidation<Topic> | undefined | The event source, read when the store first needs it (and again after |
| onFocus? | (listener: () => void) => () => void | Calls |
| watchedTopics? | readonly Topic[] | Topics only emitted while watched for a folder. |
Types#
ResourceKeyType#
A resource's identity: a string, or values serialized as JSON.
type ResourceKey = string | readonly unknown[]ResourceStatusType#
Where a resource is: idle (nothing asked), loading (the first fetch runs), then the last fetch's outcome.
type ResourceStatus = 'idle' | 'loading' | 'success' | 'error'