Skip to content

Plugin API (ctx)

Plugin API 1.0.0 (API_VERSION of @taflor/api). A manifest's api is a semver range over it, "^1.0". The typed declarations are the JSDoc of server/taflor_server/static/table/js/api/index.js (PluginContext, PluginUi, PluginTools, PluginToolDef, PluginRegistry, Plugin).

The entry module

export default {
  activate(ctx)    // required; may be async; 5 s
  deactivate()     // optional; ctx.dispose callbacks and the rollback run anyway
}

ctx

ctx is frozen and made per plugin. After the plugin stops, its methods that register or write throw ("the plugin was stopped").

member what
plugin id, version, settings (the lock's, read-only), assetUrl(path) (a file of the plugin, versioned), t(key, vars) (its labels)
me userId, role, isGm; live, read-only
access may(kind, what), mayEdit(object), seesHidden, readOnly, on("change", fn)
host the page's host providers and capabilities, read-only
registry one registry per name: register(shortName, def) → unregister, get, resolve, list, on("change", fn)
frame request(callback(time, dt), {fps?, perfKey?, still?}) → cancel: the shared per-frame scheduler
hooks on, filter, provide (Hooks)
perf enabled(key) (a plugin key or a core switch), reduced, on("change", fn)
prefs get(key), set(key, value) → Promise: the user's preferences the server keeps; in 0.3.0 only the bundled plugins' picks (token frame, ping, cursor, trail, dice skin and effects). Other keys read undefined, and set throws
local get(key), set(key, value): per-device JSON values in localStorage, namespaced (table.plugin.<id>.<key>)
ui notify(message, level) and the mount points: addMenu, contextMenu, hud, settings, looks, inspector, drawer, modal (mount points)
tools register(def) → unregister, activate(id) → boolean, deactivate(id), isActive(id) (tools)
dispose(fn) runs fn when the plugin stops, in reverse order
log warn, error: the console, tagged with the plugin id

Every handler a plugin gives ctx runs through its guard: an error is caught, logged and reported, and past the error budget (20 errors within 60 s) the plugin is switched off for the page load.

Not in 0.3.0

The design (SPEC §7.5) also has objects, table, selection, camera, messages, sound and documents. They come with later versions of the client; a plugin can't write objects, table data or plugin messages yet, nor read the camera or the selection except through hooks (selection.changed, camera.settled, object.*).

@taflor/api

export stability
API_VERSION stable
Emitter stable: a small event emitter, on(event, handler) → off and emit(event, payload)
type definitions (Plugin, PluginContext, EffectDef, PathStyle, ...) stable within 1.x, except those marked experimental
effects, frames, paths, pings, kinds, TableObject experimental: they may change within API 1.x (details)