GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — opencode/packages/plugin/src/gui/context.ts at dev · yusha/opencode Expand file tree/ Copy pathcontext.tsMore file actions 328 lines (325 loc) · 9.25 KB / Copy pathcontext.tsFile metadata and controls328 lines (325 loc) · 9.25 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 import type { Accessor } from "solid-js" import type { BaseContext, App, Cleanup, Contract, DeclaredIcons, DeclaredStores, Ipc, IpcClient, IpcSpec, Live, Persisted, PluginIconName, StoreDeclaration, Token, TokenValue, } from "./core.js" import type { Appearance, Attention, Commands, Desktop, Dialogs, Embeds, Keybinds, Layout, Links, Locale, Router, Screen, Servers, SessionRef, Sessions, Storage, System, Tabs, Toasts, Ui, Workspaces, } from "./host-apis.js" /** * What every window entry gets. Contracts are provided and read at runtime: `ctx.provide` for your own, `ctx.use` for * other plugins', `ctx.main` for your main process. The APIs the host always provides are properties, each created * on first read. * Setup runs under the plugin's root owner: Solid's `onCleanup` in setup runs when the plugin goes away. * `usePlugin()` returns the same object inside contributions. */ export interface Context extends BaseContext { /** * Provides an in-process contract. Withdrawn with the current owner, else with the plugin. Throws for a contract * whose id is not your plugin's id or under it (`<id>.<name>`), and for an Ipc token: Ipcs are provided by the main * entry. * * @param token - The contract. * @param impl - Its implementation. * @returns Withdraws the contract early. * * @example * ```ts * ctx.provide(Changes, { diffs, open }) * ``` */ provide<C extends Contract<unknown>>(token: C, impl: TokenValue<C>): Cleanup /** * Follows a contract or an Ipc that another plugin provides. Returns a `Live` accessor: pending while its provider * loads, active with its value, inactive while it is turned off or failed. The plugin must keep working while it is * inactive. Branch on it, or follow it with `createKeyed`. The provider is the plugin whose id the token's id names. * * @param token - The contract or Ipc. * @returns The provider as a `Live` accessor; the same accessor for every call with the token. * * @example * ```ts * createKeyed(ctx.use(Changes), (changes) => changes.watch(screen, "files")) * ``` */ use<T extends Token>(token: T): Accessor<Live<TokenValue<T>>> /** * The client of an Ipc your own main entry provides. A call waits while the main entry starts, and rejects when it * cannot answer: on the web, while the plugin's main entry is off or failed, or when main throws. A call waits * indefinitely when the plugin has no main entry. `state` and `on` * follow the main entry across restarts. Throws for an Ipc whose id is not your plugin's id or under it. * * @param token - The Ipc. * @returns Its client; the same client for every call with the token. * * @example * ```ts * const awake = ctx.main(KeepAwake) * ctx.add(Command, { id: "awake", title: ctx.t("awake"), run: () => void awake.set(true) }) * ``` */ main<S extends IpcSpec>(token: Ipc<S>): IpcClient<S> /** * Side panel tabs, scroll offsets, and the settings and project dialogs. * * @example * ```ts * ctx.layout.open(`${ctx.id}:main`, session, { background: true }) * ``` */ readonly layout: Layout /** * The sessions of open shell tabs, and the mounted one. * * @example * ```ts * const session = ctx.sessions.current() * ``` */ readonly sessions: Sessions /** * The mounted session screen and its route-following files, comments and composer. Read it where you act, so an * action targets the session routed at that moment; a `MountedSession` carries no such actions. * * @example * ```ts * const screen = ctx.screen.current() * if (screen) screen.composer.attach({ type: "file", path }) * ``` */ readonly screen: Screen /** * Stores for keys only known at runtime, and window-local memory. Declare `stores` for keys known up front. * * @example * ```ts * const recent = ctx.storage.store(`recent.${server}`, { schema: Recent, initial: { paths: [] } }) * ``` */ readonly storage: Storage /** * The clipboard, saving files, and opening URLs in the system browser. Works on every platform. * * @example * ```ts * await ctx.system.copy(url) * ``` */ readonly system: System /** * Desktop-only abilities; undefined on the web. * * @example * ```ts * if (!ctx.desktop) return * void ctx.desktop.reveal(path) * ``` */ readonly desktop: Desktop | undefined /** * Dialogs that close with the owner that opened them, else when the plugin goes away. * * @example * ```ts * ctx.dialogs.open((dialog) => <ConfirmDialog onDone={dialog.close} />) * ``` */ readonly dialogs: Dialogs /** * Short messages in a corner of the window. A plugin's toasts close when it goes away. * * @example * ```ts * const saving = ctx.toast.show({ title: ctx.t("saving"), variant: "loading", persistent: true }) * await save() * saving.dismiss() * ``` */ readonly toast: Toasts /** * The shell's tab strip: open, show, move and close session tabs. * * @example * ```ts * const first = (key: string) => ctx.tabs.move(key, 0) * ``` */ readonly tabs: Tabs /** * System notifications and sounds that follow the user's notification settings, for when they look elsewhere. * * @example * ```ts * void ctx.attention.notify({ title: ctx.t("tests.done"), session: { server: session.server.id, id: session.id } }) * ``` */ readonly attention: Attention /** * Runs published plugin commands and the app's own, as the command palette does. * * @example * ```ts * if (!ctx.commands.run("terminal.toggle")) ctx.toast.show({ title: ctx.t("terminal.unavailable") }) * ``` */ readonly commands: Commands /** * Routes local links to the plugins that handle them. * * @example * ```ts * ctx.links.open({ href: path, session, exact: true }) * ``` */ readonly links: Links /** * Shows the web pages the main entry created. * * @example * ```ts * <ctx.embeds.View id={embed()} visible={visible()} /> * ``` */ readonly embeds: Embeds /** * The app's own components: icons, buttons, tooltips, menus and menu rows, the loading indicator, the dialog frame, * switches, text fields, selects, keybind chips, Markdown, highlighted code, and settings pages, sections and rows. * * @example * ```tsx * <ctx.ui.Button icon="check" onClick={apply}>{ctx.t("apply")}</ctx.ui.Button> * ``` */ readonly ui: Ui /** * The running app: its version, release channel and platform, as `ctx.app` in server and TUI plugins. * * @example * ```ts * if (ctx.app.channel === "dev") showDebug() * ``` */ readonly app: App /** * The interface language and its writing direction. * * @example * ```ts * new Intl.NumberFormat(ctx.locale.locale()).format(count) * ``` */ readonly locale: Locale /** * The user's appearance settings. * * @example * ```ts * terminal.options.fontFamily = ctx.appearance.font("mono") * ``` */ readonly appearance: Appearance /** * The app's route. * * @example * ```ts * const onSettings = () => ctx.router.path().startsWith("/settings") * ``` */ readonly router: Router /** * The effective keybinds of published commands. * * @example * ```ts * const keys = () => ctx.keybinds.keybind(`${ctx.id}.toggle`) * ``` */ readonly keybinds: Keybinds /** * The servers the app lists: their ids, and each one's live `ServerRef`. * * @example * ```ts * const known = () => new Set(ctx.servers.list()) * const server = (id: string) => ctx.servers.get(id) * ``` */ readonly servers: Servers /** * Workspace lifecycle events. * * @example * ```ts * ctx.workspaces.on("remove", (value) => forget(value.server, value.directory)) * ``` */ readonly workspaces: Workspaces } type Handle<S> = S extends StoreDeclaration<infer Schema, infer Scope> ? Scope extends "global" ? Persisted<Schema["Type"], Schema["Type"]> : (session: SessionRef) => Persisted<Schema["Type"]> : never /** * The context `Plugin.Setup<typeof definition>` receives: the host's members, and the definition's declared stores and * icons. */ export interface SetupContext<D> extends Context { /** * Each declared store, by its name in `stores`. A global store is a `Persisted` that has loaded before setup; a * session store is a function of the session whose `value` is undefined until that session's store loads. * * @example * ```ts * const shown = () => ctx.stores.prefs.value.shown * const open = (session: SessionRef) => ctx.stores.view(session).value?.open ?? [] * ``` */ readonly stores: { readonly [K in keyof DeclaredStores<D>]: Handle<DeclaredStores<D>[K]> } /** * The name of each declared icon, by its name in `icons`, for every SDK icon field and for `ctx.ui.Icon`. A name the * definition does not declare fails to compile. See `PluginIconName`. * * @example * ```tsx * ctx.add(TitlebarItem, () => ({ id: "sync", label: ctx.t("sync"), icon: ctx.icons.logo, run: sync })) * const mark = <ctx.ui.Icon name={ctx.icons.logo} size="small" /> * ``` */ readonly icons: { readonly [K in keyof DeclaredIcons<D>]: PluginIconName } } |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |