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
| Prop | Type | Effective default |
|---|---|---|
label | string | 'Diagram' |
autoFit | boolean | false |
portHitRadius | number | 22 CSS pixels |
connectorStrokeScaling | 'viewport' | 'world' | 'viewport' |
edgeLayer | 'below' | 'above' | 'below' |
initialFrame | DiagramInitialFrame | Normal initial framing when omitted. |
virtualization | DiagramVirtualizationOptions | Visibility resolver defaults. |
The default viewport slot contains additional viewport content. The viewport requires a measurable height.
| Handle | Public members |
|---|---|
DiagramRootHandle | root: HTMLElement | null, getStore(): DiagramStore, getSession(): DiagramSession, followLink(id: string): void |
DiagramViewportHandle | focus(): 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
| Part | Props | Default slot payload |
|---|---|---|
Diagram.NodeDef | nodeType?: string | node, geometry, actions |
Diagram.NodePortsDef | nodeType?: string | Node payload plus ports |
Diagram.Field | name: string, readOnly?: boolean | getInputProps(application?) |
Diagram.Port | portId: string, disabled?: boolean | getPortProps(application?) |
Diagram.CommandButton | commandId: string | getButtonProps(application?) |
Diagram.TooltipTrigger | text: string | getTriggerProps(application?) |
Diagram.ExplorerFocus | None | getFocusProps(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
| Part | Contract |
|---|---|
Diagram.Inspector | Optional commandIds; slot receives selectedIds, nodes, commands, execute, availability, and apply. |
Diagram.UserHandle | Required commandId; optional nodeId and offset, default { x: 0, y: -12 }. Slot receives command, node, position, and execute. |
Diagram.ContextMenu | Optional commandIds, label, and defaultPresentation, default true. Slot receives commands, execute, and close. |
Diagram.Tooltip | defaultPresentation defaults to true. Slot receives text. |
Diagram.WorkspaceHost | Required activeLayerId; emits pageChange and layerChange strings. Provides workspace state to descendants. |
Diagram.PersistenceHost | Required 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:
| Accessor | Key | Readable context |
|---|---|---|
useDiagramContext() | DIAGRAM_KEY | Root text, model, store, session, interaction, scene, geometry version, content availability, measurements, and connection action. |
useDiagramNodeContext() | DIAGRAM_NODE_KEY | Current node and geometry refs, plus node actions. |
useDiagramInspectorContext() | DIAGRAM_INSPECTOR_KEY | Inspector selection, nodes, commands, and actions. |
useDiagramUserHandleContext() | DIAGRAM_USER_HANDLE_KEY | Handle command, node, position, and execute action. |
useDiagramContextMenuContext() | DIAGRAM_CONTEXT_MENU_KEY | Menu commands, execute, and close. |
useDiagramTooltipContext() | DIAGRAM_TOOLTIP_KEY | Tooltip 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.
| API | Contract |
|---|---|
DiagramRenderedExportSource | Opaque 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. |
source | Optional 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. |
colorScheme | Omission follows source CSS; 'light' or 'dark' selects an isolated mode. Detached explicit modes fail with render-source-required. |
theme, styles, geometry, measureText, symbols | Portable 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 field | Meaning |
|---|---|
| Public name and import | Supported spelling from the listed wrapper entry. |
| Type / value namespace | Whether the name is a type, a runtime value, or both. |
| Prop | A value supplied to a Vue component. |
| Named model | A prop with a documented update:<name> emit; root value has no model contract. |
| Emit | A named event separate from readable ref state. |
| Slot | Plain readonly payload values and explicit actions. |
| Context | Readonly refs and bound actions from the nearest provider. |
| Handle | Exposed component methods and current getters available after mount. |
| Default | Required, omitted/implicit undefined, explicit undefined, or the source default. |
| Optional method parameter | May 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.
| Prop | Type | Default or requirement |
|---|---|---|
value | DiagramModel | Exactly one of value or store. New reference reloads the managed store. |
store | DiagramStore | Exactly one source. Supplied store remains caller-owned. |
pageId | string | Required, identifies an existing page. |
text | DiagramTextOverrides | Omitted overrides fall back to English wording. |
contentAvailability | DiagramContentAvailability | null | No content capability override. |
symbols | DiagramSymbolRegistry | null | No registry. |
sceneOptions | Omit<DiagramSceneOptions, 'previews'> | Subsystem defaults; previews belong to the session. |
aidOptions | DiagramAidOptions | Subsystem defaults. |
commands | readonly DiagramCommandDefinition[] | Built-in command registration remains available. |
commandShortcuts | readonly (DiagramKeyInput & { id: string })[] | undefined retains registry shortcuts. [] disables those mappings. |
connectionOptions | DiagramConnectionOptions | Subsystem defaults. |
connectionType | DiagramConnectionPathType | 'polyline'; supports v-model:connection-type. |
editingOptions | DiagramEditingOptions | Subsystem defaults. |
navigationOptions | DiagramNavigationOptions | Subsystem defaults. |
showDefaultDiagnostics | boolean | true. |
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
| Emit | Payload | Meaning |
|---|---|---|
commit | DiagramCommit | A completed persistent change. Reloading value does not emit a commit. |
navigatePage | { pageId: string; nodeId?: string } | Requested page navigation, including an optional focus target. |
sourceError | Error | A rejected source update. |
update:connectionType | DiagramConnectionPathType | Named 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): DiagramStoreImport 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 area | Guide |
|---|---|
| Model records, geometry and immutable snapshots | Model |
| Store writes, proposals, results and commands | Events and commands |
| Root/node injection and template envelopes | Slots and contexts |
| Copied controls and inherited models | UI parts |
| Entry points and dependencies | Imports |
| Resource, notation and exchange boundaries | Supported profiles |
| Ownership and teardown | SSR and lifecycle |
#Related Docs
#Connector paint order
| Public member | Type | Default and behavior |
|---|---|---|
DiagramEdgeLayer | 'below' | 'above' | Shared type, re-exported by @primeui/vue-diagram. |
DiagramViewport.edgeLayer | DiagramEdgeLayer | 'below'. Live viewport preference; omission or binding removal restores the default. |
DiagramExportOptions.edgeLayer? | DiagramEdgeLayer | Inherits 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.