Diagram - API

Public Vue Diagram exports, bindings, methods and portable contracts.

#Import

import { Diagram, type DiagramRootHandle, type DiagramModel } from '@primeui/vue-diagram';

The namespace and flat prefixed components share the same context and registration identity. Optional capabilities use the entries in Imports.

#API

Viewport props and expose

PropTypeEffective default
labelstring'Diagram'
autoFitbooleanfalse
portHitRadiusnumber22 CSS pixels
connectorStrokeScaling'viewport' | 'world''viewport'
edgeLayer'below' | 'above''below'
initialFrameDiagramInitialFrameNormal initial framing when omitted.
virtualizationDiagramVirtualizationOptionsVisibility resolver defaults.

The default viewport slot contains additional viewport content. The viewport requires a measurable height.

HandlePublic members
DiagramRootHandleroot: HTMLElement | null, getStore(): DiagramStore, getSession(): DiagramSession, followLink(id: string): void
DiagramViewportHandlefocus(): void, frame(id: string, options?: DiagramDetailFrameOptions): boolean, exportSource(): DiagramRenderedExportSource

Handles are available through typed template refs after mount. Root getters resolve the current owners after a reload. exportSource() returns an opaque mounted viewport handle. It expires on viewport unmount. It has no public DOM fields or constructor.

Definition and host-prop parts

PartPropsDefault slot payload
Diagram.NodeDefnodeType?: stringnode, geometry, actions
Diagram.NodePortsDefnodeType?: stringNode payload plus ports
Diagram.Fieldname: string, readOnly?: booleangetInputProps(application?)
Diagram.PortportId: string, disabled?: booleangetPortProps(application?)
Diagram.CommandButtoncommandId: stringgetButtonProps(application?)
Diagram.TooltipTriggertext: stringgetTriggerProps(application?)
Diagram.ExplorerFocusNonegetFocusProps(application?)

Definitions resolve exact types before fallback, independently for bodies and ports; the last match wins. Host-prop getters merge application refs and events. Application handlers run first. Calling event.preventDefault() skips Diagram handling. Required accessibility attributes remain Diagram-owned.

Overlay and service hosts

PartContract
Diagram.InspectorOptional commandIds; slot receives selectedIds, nodes, commands, execute, availability, and apply.
Diagram.UserHandleRequired commandId; optional nodeId and offset, default { x: 0, y: -12 }. Slot receives command, node, position, and execute.
Diagram.ContextMenuOptional commandIds, label, and defaultPresentation, default true. Slot receives commands, execute, and close.
Diagram.TooltipdefaultPresentation defaults to true. Slot receives text.
Diagram.WorkspaceHostRequired activeLayerId; emits pageChange and layerChange strings. Provides workspace state to descendants.
Diagram.PersistenceHostRequired store, controller, loader, and saver; optional readOnly and persistedDirty. Provides persistence presentation; controller stays caller-owned.

Composables and keys

Main and /composables export these six typed keys and their throwing accessors:

AccessorKeyReadable context
useDiagramContext()DIAGRAM_KEYRoot text, model, store, session, interaction, scene, geometry version, content availability, measurements, and connection action.
useDiagramNodeContext()DIAGRAM_NODE_KEYCurrent node and geometry refs, plus node actions.
useDiagramInspectorContext()DIAGRAM_INSPECTOR_KEYInspector selection, nodes, commands, and actions.
useDiagramUserHandleContext()DIAGRAM_USER_HANDLE_KEYHandle command, node, position, and execute action.
useDiagramContextMenuContext()DIAGRAM_CONTEXT_MENU_KEYMenu commands, execute, and close.
useDiagramTooltipContext()DIAGRAM_TOOLTIP_KEYTooltip text.

useDiagramStore(initialModel): DiagramStore requires setup or an active effect scope. It samples the model once, returns the store directly, and owns its disposal. Validation failure throws before a consumer receives a store.

Service accessors useDiagramToolbar(), useDiagramSelectionInspector(), and useDiagramExplorer() require a root descendant. useDiagramWorkspace() requires a workspace host. useDiagramPersistence() requires a persistence host. They expose readonly snapshots and bound actions. Setup reads refs through .value; templates unwrap top-level refs. Changes use flat actions such as setConnectionType(...), not assignment to snapshot refs.

Optional accessors stay in their capability entry. In particular, useDiagramPalette(): DiagramPaletteControls comes only from /palette. The portable DiagramPaletteModel retains its separate portable contract. useDiagramOutput() comes from /export. Notation inspector accessors come from the corresponding notation entry.

Store, session, and output contracts

createDiagramStore(model, options?) returns a discriminated result. Narrow on ok before reading value; failures contain diagnostics. Snapshots and records are readonly. Controlled stores use transaction proposals and explicit acknowledgements, described in Events and commands.

DiagramPersistenceSaver is exported from main for application persistence providers. The BPMN XML import handle exposes readonly canAccept; preview, accept, cancel, resolve, and text/file actions remain on that handle.

exportDiagramSvg and output controls come from /export. Detached output uses portable content. Mounted source output captures eligible in-tree Vue content. Offscreen framework content is rejected with diagnostics; automatic offscreen component staging is unsupported. See Supported profiles and Export.

#Rendered export contracts

Import rendered export controls, options, results and source types from @primeui/vue-diagram/export.

APIContract
DiagramRenderedExportSourceOpaque viewport instance handle; no public fields, constructor, DOM access or serialization.
DiagramViewportHandle.exportSource()Returns the viewport's stable source handle without starting capture. A mounted source is required; destruction expires the handle.
sourceOptional on SVG, raster, print and output controls. Explicit source wins over unique directly owned viewport discovery.
exportDiagramSvg(model, options, source?)Uses the supplied source for rendered capture; calls without a source remain detached.
colorSchemeOmission follows source CSS; 'light' or 'dark' selects an isolated mode. Detached explicit modes fail with render-source-required.
theme, styles, geometry, measureText, symbolsPortable detached options; unsupported rendered-source overrides fail with diagnostics.

Mounted content is cloned with its captured state. Required offscreen Vue content is rejected rather than staged into another Vue tree. Keep the source mounted and stable until output settles. Source/options changes cancel preparation and invalidate prepared print output. See Export rendered templates.

#Read a contract

Props show the accepted binding value and its default. Emits show event payloads. Scoped slots supply plain readonly values and actions; context accessors expose readonly refs. Handles expose mounted component operations.

Contract fieldMeaning
Public name and importSupported spelling from the listed wrapper entry.
Type / value namespaceWhether the name is a type, a runtime value, or both.
PropA value supplied to a Vue component.
Named modelA prop with a documented update:<name> emit; root value has no model contract.
EmitA named event separate from readable ref state.
SlotPlain readonly payload values and explicit actions.
ContextReadonly refs and bound actions from the nearest provider.
HandleExposed component methods and current getters available after mount.
DefaultRequired, omitted/implicit undefined, explicit undefined, or the source default.
Optional method parameterMay be omitted; an initializer shows the source default.

Readonly snapshots do not authorize direct model mutation. Use the documented actions, commands and transactions.

#Component names and record names

The primary entry uses DiagramNode, DiagramConnector and DiagramLabel for Vue rendering components. Import their portable interfaces as DiagramNodeRecord, DiagramConnectorRecord and DiagramLabelRecord.

import { DiagramNode, type DiagramNodeRecord } from '@primeui/vue-diagram';

const node: DiagramNodeRecord = {
    id: 'task',
    pageId: 'page',
    layerId: 'layer',
    type: 'rectangle',
    bounds: { x: 40, y: 40, width: 160, height: 80 },
    rotation: 0,
    ports: [],
    labels: []
};

The component import renders a part. The node value belongs in a model or store command. A portable port can be expressed as DiagramNodeRecord['ports'][number].

#Root bindings and readable state

Root props

Diagram.Root accepts DiagramRootProps, an exclusive value or store source intersected with DiagramRootOptions.

PropTypeDefault or requirement
valueDiagramModelExactly one of value or store. New reference reloads the managed store.
storeDiagramStoreExactly one source. Supplied store remains caller-owned.
pageIdstringRequired, identifies an existing page.
textDiagramTextOverridesOmitted overrides fall back to English wording.
contentAvailabilityDiagramContentAvailability | nullNo content capability override.
symbolsDiagramSymbolRegistry | nullNo registry.
sceneOptionsOmit<DiagramSceneOptions, 'previews'>Subsystem defaults; previews belong to the session.
aidOptionsDiagramAidOptionsSubsystem defaults.
commandsreadonly DiagramCommandDefinition[]Built-in command registration remains available.
commandShortcutsreadonly (DiagramKeyInput & { id: string })[]undefined retains registry shortcuts. [] disables those mappings.
connectionOptionsDiagramConnectionOptionsSubsystem defaults.
connectionTypeDiagramConnectionPathType'polyline'; supports v-model:connection-type.
editingOptionsDiagramEditingOptionsSubsystem defaults.
navigationOptionsDiagramNavigationOptionsSubsystem defaults.
showDefaultDiagnosticsbooleantrue.

Optional configuration props without a declared Vue default are undefined at the binding boundary. Their effective behavior is resolved by the relevant subsystem. Root value is a one-way input, with no update:value or root model contract.

A new value reference resets history and the save baseline even when its content equals the previous model. A page-only change preserves the store. Invalid initial sources throw. Invalid later source updates emit sourceError and preserve the valid lifetime; without a handler, development reports the error through console.error.

Root emits and slots

EmitPayloadMeaning
commitDiagramCommitA completed persistent change. Reloading value does not emit a commit.
navigatePage{ pageId: string; nodeId?: string }Requested page navigation, including an optional focus target.
sourceErrorErrorA rejected source update.
update:connectionTypeDiagramConnectionPathTypeNamed model update for connection path choice.

The default slot contains definitions, viewports, and controls. The diagnostics slot receives { diagnostics } inside a root-owned alert. A custom slot can remain visible with :show-default-diagnostics="false"; license notices are independent.

#Initial-model helper

useDiagramStore(initialModel: DiagramModel): DiagramStore

Import useDiagramStore from the main entry or /composables. Call it in an active synchronous Vue setup/effect scope. It samples the plain model once, creates one store with factory defaults and disposes it with the owner after consumers detach. Invalid models throw with diagnostics. Keep a shared owner alive until all borrowing roots and controllers detach.

Use createDiagramStore(model, options) for controlled transactions, notation modules, custom limits or explicit validation handling; check its result and own successful-store disposal.

#Find the owning workflow

API areaGuide
Model records, geometry and immutable snapshotsModel
Store writes, proposals, results and commandsEvents and commands
Root/node injection and template envelopesSlots and contexts
Copied controls and inherited modelsUI parts
Entry points and dependenciesImports
Resource, notation and exchange boundariesSupported profiles
Ownership and teardownSSR and lifecycle

#Connector paint order

Public memberTypeDefault and behavior
DiagramEdgeLayer'below' | 'above'Shared type, re-exported by @primeui/vue-diagram.
DiagramViewport.edgeLayerDiagramEdgeLayer'below'. Live viewport preference; omission or binding removal restores the default.
DiagramExportOptions.edgeLayer?DiagramEdgeLayerInherits a rendered source; explicit matching values are accepted and conflicts fail with render-invalid-options. Detached output defaults to 'below' and accepts either value.

'below' is endpoint-relative owner order. 'above' paints strokes and attached decorations above bodies within each model layer, in connector model order. Rich parts, aggregate rendering and ordinary canvas picking agree. Ports, handles and default/layer captions retain their higher priority; owner captions stay with their owner. Overlay header labels retain overlay order, while body-contained fallback headers remain part of the body.

Different viewports may choose different values for one model. Changing the policy does not change the model, routes, selection or history. Output uses committed order, and policy changes invalidate pending capture and prepared print. See export.