Files
RuneStone/packages/plugin-sdk/src/api.ts
T
Knotty Wyvern e66f089176 Make Project Management a native feature
- Move the storage and model of the plugin into src/lib/features/pm/ as pure TypeScript, so the skill can still bundle them.
- Move the DOM interface onto the host menus, the shared tooltip, and the host icons.
- A ribbon button opens Project Management. Board tabs keep the owner runestone.pm and the board-<hex> view IDs through view patterns.
- Read only .runestone/pm/. Offer the plugin migration, with backups, for legacy notes.
- A save, move, or delete reads only that card again. Watcher paths reach the feature.
- Add Settings → Project Management and the projectManagement section. View states move to localStorage.
- Background reads the boards from workspace.json. Remove api.backgrounds and the boards service.
- Add yaml 2.9.1. Use the host markdown-it.
- Move 18 plugin test files to tests/unit/features/pm/ and add native tests.
2026-10-29 20:54:29 -07:00

90 lines
5.2 KiB
TypeScript

import type { CompletionApi } from "./completion.ts";
import type { Contributions } from "./contributions.ts";
import type { ActionIcon } from "./icons.ts";
import type { ActionMenuItem, ActionMenuOptions } from "./menu.ts";
/** Plugin API version 1. A compiled plugin exports `activate(api)`. */
export type Dispose = () => void | Promise<void>;
export interface PluginCommand { id: string; title: string; icon?: ActionIcon | PluginView["icon"]; category?: "open" | "action"; run: () => void | Promise<void> }
export interface PluginView { id: string; title: string; settings?: boolean; launcher?: boolean; launch?: () => void | Promise<void>; placement?: "dialog" | "editor" | "sidebar"; navigation?: boolean; toolbar?: boolean; pinned?: boolean; icon?: "list" | "kanban" | "puzzle" | "globe" | "git"; iconImage?: string | null; tabActions?: (context: { pinned: boolean }) => ActionMenuItem[]; tabDragData?: (context: { pinned: boolean }) => string | undefined; find?: () => void; saveTabState?: () => unknown; restoreTabState?: (state: unknown) => void | Promise<void>; mount: (container: HTMLElement, context?: { surface: "settings" | "view" }) => void | Dispose | Promise<void | Dispose> }
export interface PluginViewOpenOptions { split: "right" | "down"; relativeTo: string }
export interface PluginDocumentContext { id: string; path: string }
export interface PluginDocumentType {
id: string;
title: string;
icon?: "kanban" | "file";
extensions: string[];
content?: "text" | "binary";
identify(path: string, source: string): { id: string } | null;
create?: { label: string; defaultName: string; extension: string; contents(): string };
mount(container: HTMLElement, document: PluginDocumentContext): void | Dispose | Promise<void | Dispose>;
}
export interface FolderGrant { id: string; path: string; name: string }
export interface FolderEntry { name: string; size: number }
/** Folders outside the workspace that the user granted to this plugin. */
export interface FilesApi {
readonly version: 1;
chooseFolder(options?: { title?: string }): Promise<FolderGrant | null>;
pictureFolder(name: string): Promise<FolderGrant>;
grants(): Promise<FolderGrant[]>;
revoke(grant: string): Promise<boolean>;
list(grant: string): Promise<FolderEntry[]>;
readBytes(grant: string, name: string): Promise<Uint8Array>;
readSidecar(grant: string, name: string): Promise<string | null>;
writeSidecar(grant: string, name: string, contents: string, expected: string | null): Promise<void>;
}
export type ServiceMethods = Record<string, (...args: never[]) => unknown>;
/** Data that one plugin offers to other plugins in the same window. */
export interface ServicesApi {
readonly version: 1;
provide(name: string, methods: ServiceMethods): { notify(): void; dispose(): void };
get(plugin: string, name: string): Record<string, (...args: unknown[]) => Promise<unknown>> | null;
subscribe(listener: (plugin: string, name: string) => void): Dispose;
}
/** Files in the active workspace. All paths are relative to the workspace root. */
export interface WorkspaceApi {
list(path?: string): Promise<{ name: string; rel_path: string; kind: string }[]>;
listMarkdown?(): Promise<string[]>;
read(path: string): Promise<string>;
readMany?(paths: string[]): Promise<{ path: string; source?: string; error?: string }[]>;
readBytes?(path: string): Promise<Uint8Array>;
readOptional?(path: string): Promise<string | null>;
create?(path: string, contents: string): Promise<void>;
write(path: string, contents: string, expected: string): Promise<void>;
subscribe?(listener: () => void): Dispose;
}
/** The saved JSON settings of the plugin. */
export interface SettingsApi { read(): Promise<unknown>; write(value: unknown): Promise<void>; subscribe?(listener: () => void): Dispose }
/** The files in the plugin package. */
export interface AssetsApi { read(path: string): Promise<Uint8Array> }
/** Interface parts that the host draws. */
export interface UiApi { showActionMenu(options: ActionMenuOptions): { close(): void } }
export interface PluginApi {
files?: FilesApi;
services?: ServicesApi;
ui?: UiApi;
completion?: CompletionApi;
readonly id: string;
readonly signal: AbortSignal;
contribute<K extends keyof Contributions>(key: K, value: Contributions[K]): void;
registerCommand(command: PluginCommand): void;
registerView(view: PluginView): void;
registerTabDrop?(receive: (data: string) => void | Promise<void>): void;
updateViewTitle?(id: string, title: string): void;
updateViewIcon?(id: string, image: string | null): void;
registerDocumentType(type: PluginDocumentType): void;
openDocument(path: string): Promise<void>;
openFile?(path: string): Promise<void>;
renameDocument?(document: PluginDocumentContext, name: string): Promise<string>;
openView(id: string, options?: PluginViewOpenOptions): void;
closeView?(id: string): void;
replaceView?(currentId: string, nextId: string): void;
replaceDocumentWithView?(document: PluginDocumentContext, nextId: string): void;
onDispose(cleanup: Dispose): void;
workspace: WorkspaceApi;
settings: SettingsApi;
assets: AssetsApi;
}
/** The entry module of a plugin. */
export interface PluginModule { activate(api: PluginApi): void | Dispose | Promise<void | Dispose> }