Paged.The open publishing system
The technical handbook
Plugin SDK

Paged Docs / Plugin SDK

The BundleHost

Area-by-area reference for the BundleHost — the single object a plugin receives at activation, carrying contribution registration, document access, selection, viewport, overlays, storage, diagnostics, and capability detection.

Tier: ProProIIIreference

One parameter carries the whole platform. activate(host) receives a BundleHost; this page is its complete surface at API v0.2. Every member returns serializable data or a Disposable; expected failures resolve as results, never throws.

host.manifest · host.log

Your own manifest (read-only) and a namespaced logger (debug/info/warn/error, prefixed [<plugin-id>]). The logger shares its sink with the diagnostics channel.

host.contribute

Every method enforces the namespace rule and tracks the registration for structural teardown. All return Disposable.

MethodRegistersNotes
tool(c)a tool-rail entryToolContribution: id, title, icon, shortcut, flyout group, rail section, cursor, and the gesture() handler factory the host mounts when the tool activates. The host derives the activation command + guarded shortcut from the registry; contributeTool is the recommended door.
panel(c)a panelPanelContribution: id, title, React component, default dock/group, icon. The host derives paged.panel.show/hide.<id> commands; panels compose the host UI kit so they read as native.
command(c)a commandid, title, category, handler(paged, payload?). Reachable from the command palette and keybindings.
keybinding(c)a key binding{ key: "cmd+shift+h", command, when? }. The when predicate receives live editor state (e.g. suppress single-key tool shortcuts while a text caret is active).
overlay(c)a canvas overlayRenders into the shared camera-transformed SVG above the page.
editContext(d)—Reserved. Throws PluginApiNotImplemented.
objectType(d)—Reserved. Throws PluginApiNotImplemented.
The Paged editor with paged.draw’s Path options panel open beside the canvas, its Width profile section set to 1, 6 and 1 points, and a wavy open path on the page outlined with that profile.
A module’s panel in the dock: paged.draw’s Path options, with its width profile applied to an open path. A plugin’s panel registers the same way.Recorded in the Paged editor at eeef38be6, .

host.document

Read broadly; write through one door.

mutate(m: Mutation, options?: MutateOptions): Promise<MutationOutcome>
//  → { applied: true, createdId, pageIds, appliedSeq? } | { applied: false, error }
undo(): Promise<void>            redo(): Promise<void>
collection<T>(name): Promise<readonly T[]>   // swatches, layers, styles, …
meta(): Promise<DocumentMeta>                // pageCount, units, colorMode, …
pathAnchors(id): Promise<PathAnchorsResult | null>   // Bézier anchor table
hitTest(pageId, [x, y], filter?): Promise<HitResult | null>
elementGeometry(ids): Promise<ElementGeometryItem[]>
tree(): Promise<SceneTreeNode[]>
getMetadata(id): Promise<PluginMetadataEnvelope | null>
setMetadata(id, envelope | null): Promise<MutationOutcome>
onDidChange(l): Disposable
//  fires { kind: "mutationApplied" | "gestureCommitted" | "undoApplied" | "redoApplied" | …,
//          pageIds, appliedSeq? }

mutate is the write path. Every change lands on the editor's single undoable Operation channel — plugin and native edits share one history. The typed Mutation union (path topology, properties, swatches, gradients, layers, pathfinder booleans, batches, …) is re-exported by @paged-media/plugin-sdk/api; batches apply atomically and undo as one step.

A follow-up write in the same undo step

A bundle that keeps derived content in step with its sources — artwork rebuilt from a path, a table re-laid from its data — reacts to an edit only after the engine committed it. Written as an ordinary mutate, the rebuild would be an undo step of its own: it would clear the redo stack, and undoing the edit would leave the rebuilt content behind. mutate(m, { amend }) applies the mutation into the undo step amend names, so one undo reverts the edit and the rebuild, and one redo replays both:

if (host.supports('document.mutate.amend@1')) {
  host.document.onDidChange(async (e) => {
    if (e.appliedSeq === undefined) return;      // an undo or a redo
    let step = e.appliedSeq;
    for (const m of rebuildFor(e)) {
      const out = await host.document.mutate(m, { amend: step });
      if (!out.applied) break;                   // notAmendable: the user moved on
      step = out.appliedSeq ?? step;             // the next write amends this number
    }
  });
}
  • DocumentChangeEvent.appliedSeq is the engine's number of the step a change committed. It is present on mutationApplied and gestureCommitted, and on a scriptResult when the run was one step (a script run is one undo step). It is absent on an undo and a redo — so a listener that rebuilds on edits leaves history moves alone; they already restored the derived content with its sources.
  • A refusal is an outcome, not a throw. Once that step is no longer the last in the history, or an undo or a redo ran since, nothing is applied and the outcome is applied: false with { error: { kind: "notAmendable", details } }.
  • Each write answers the step's new number. A rebuild of several writes amends each with the appliedSeq the previous one answered.
  • Bytes too. mutateWithBytes(m, bytes, { amend }) joins the step the same way.
  • Object writes can carry a follow-up. An object model's write may return followUp(step): it runs after the registry committed the write, writes with mutate(…, { amend }), and keeps the whole consequence in the write's undo step (a recipe parameter and the artwork rebuilt from it).
  • Probe first. document.mutate.amend@1 says the host supports the option; document.mutate.amend@2 adds bytes, scripts and object follow-ups. An older host ignores it and would apply the mutation as a step of its own. A write that is not an engine mutation (a container part) is outside every undo step, an amended one included.

paged.draw uses this to rebuild a pattern, repeat, blend, objects-on-path or live-paint group in the step of the edit that changed its sources. Both members are in the SDK on main and ship with the next release.

Coordinate convention for pathAnchors and hitTest: anchor tables are in the element's local frame (apply the result's itemTransform to reach page-local space); hit-test points are page-local pt.

Plugin metadata

getMetadata/setMetadata attach a JSON envelope — { v: number, data: object, engine?: Record<string, string> } — to a leaf page item. It persists in the document as an IDML Properties/Label KeyValuePair, so it round-trips through save/reopen and survives opens in other IDML tooling (InDesign preserves Labels verbatim). The key is derived from your manifest id (x-paged:<id>) — a bundle reads and writes its own namespace only, enforced at the host door and again for raw mutate calls. The engine adds its own gates: a 64 KiB cap per entry and the envelope shape. setMetadata is an ordinary undoable mutation; v is your schema version (migrations are plugin-owned), and engine carries determinism pins where relevant.

To create an element and attach metadata as one undo step, batch the insert with a setPluginMetadata whose element id is the literal "$created" — inside a batch it resolves to the element minted by the most recent creating member, and the whole batch applies atomically:

await host.document.mutate({
  op: "batch",
  args: {
    ops: [
      { op: "insertFrame", args: { pageId, bounds } },
      {
        op: "setPluginMetadata",
        args: {
          elementId: { kind: "rectangle", id: "$created" },
          key: "x-paged:my.plugin",       // must be YOUR derived key
          value: JSON.stringify({ v: 1, data: { … } }),
        },
      },
    ],
  },
});

host.selection

get(): ElementId[]
set(ids, mode?): Promise<ElementId[]>   // mode: "replace" (default) | …
onDidChange(l): Disposable

host.viewport

camera(): { scale, tx, ty }   // snapshot, CSS px
pxToPt(px: number): number    // screen px → document pt at current zoom

pxToPt is the constant-screen-tolerance idiom: a 6 px pick radius should stay 6 px on screen at every zoom level.

host.overlay

setToolPreview(shape | null)
// shape: { pageId, points: [x,y][], close? }  — polyline
//      | { pageId, rect: [t,l,b,r] }          — rubber-band rect

The in-progress gesture preview channel — page-local pt, rendered by the host above the canvas, excluded from export. Cubic previews are flattened to polylines at this surface today.

host.storage

Namespaced key-value persistence (paged.plugin.<id>.*), JSON values:

get<T>(key): T | undefined     set(key, value)
delete(key)                    keys(): string[]

host.diagnostics

The plugin→host problem channel — parse errors, unsupported-feature warnings:

set(key, Diagnostic[])   // { severity, message, source?, line?, column? }
clear(key?)              get(key): Diagnostic[]
onDidChange(l): Disposable

Mirrored to the console in v0; the host's problems UI consumes the same store as it lands.

host.nativeDocument

Capability-gated access to the document's core-owned parts, and the door an importer uses to open its file as the active document:

readModel(): Promise<Uint8Array | null>        // needs capabilities.document.readNative
readComposition(): Promise<Uint8Array | null>
listParts(prefix?): Promise<string[]>
open(bytes: Uint8Array): Promise<void>         // needs capabilities.document.openNative

Always present: a host without a backend answers null and [], rejects open, and supports("document.readNative@1") / supports("document.openNative@1") are false. The editor backs it, and on main (next release) so does the SDK's headless host (createHeadlessHost): by default it backs the door with the engine, so an importer opens its file standalone headless too — the Node command line opens a .docx as a document of its own this way. HarnessOptions.nativeDocument replaces the backend, or with false wires none, to test the host without it.

host.supports(feature)

Runtime capability detection, preferred over version sniffing for graceful degradation:

if (host.supports("document.hitTest@1")) { … }

Feature strings have the form "area.member@major"; the implemented set is exported as HOST_FEATURES from @paged-media/plugin-sdk, so code, tests, and these docs cannot drift apart.

host.editor — the marked escape hatch

The raw editor handle, present at v0 by design (gesture handlers receive it from the host's tool spine anyway). The rule: any use of host.editor not reachable through a facade is an API gap by definition — record it, don't normalize it. This member does not survive the future isolate boundary.

On this page