Skip to main content

API

ApollonEditor is the only class you construct. It mounts its own React tree into the DOM node you hand it and exposes an imperative API — your host code never touches React.

import { ApollonEditor, UMLDiagramType } from "@tumaet/apollon"
import "@tumaet/apollon/style.css"

const editor = new ApollonEditor(container, {
type: UMLDiagramType.ClassDiagram,
})

For internals (node/edge components, etc.), read dist/index.d.ts.

React hosts do not construct ApollonEditor directly — they render the <Apollon> component instead. The imperative class documented below remains the API for non-React hosts and for advanced control.

<Apollon> React component

For React hosts, <Apollon> wraps ApollonEditor and owns its lifecycle: it constructs the editor on mount and destroys it on unmount. Import it from the @tumaet/apollon/react subpath — see React for the full integration story (hooks, provider, ref, controlled-model overlay).

import { Apollon } from "@tumaet/apollon/react"
import "@tumaet/apollon/style.css"
;<Apollon style={{ height: 600 }} />

ApollonProps

Container, lifecycle, and two layers of editor options.

Container. className, style (needs an explicit non-zero height), and children rendered alongside the canvas inside the editor's context provider.

Initial-only options — snapshotted at mount, ignored if they change afterwards. Re-key the component to apply them to a new editor.

PropTypeEffect
defaultModelUMLModelInitial diagram.
defaultTypeUMLDiagramTypeInitial diagram type when no defaultModel is supplied.
defaultModeApollonModeInitial mode — Modelling, Assessment, or Exporting.
defaultViewApollonViewInitial view.
availableViewsApollonView[]Views the user may switch between at runtime.
enablePopupsbooleanEnable inline edit/property popovers.
collaborationEnabledbooleanOpt into Yjs real-time sync; wire the transport from onMount.
debugbooleanDebug overlays/logging.

Reactive options — applied via the matching setter when the prop changes; no rebuild. Passing undefined for any reactive prop leaves the live value untouched (no reset). Re-key the component to fully reset.

PropTypeMaps to
readonlybooleaneditor.setReadonly(value)
viewApollonVieweditor.view = value
modeApollonModeeditor.setMode(value)
scrollLockbooleaneditor.setScrollLock(value)
previewModebooleaneditor.setPreviewMode(value)
modelUMLModeleditor.model = value — controlled overlay

Lifecycle.

PropTypePurpose
onMount(editor) => void | (() => void)Fires once after mount. The optional returned function runs as cleanup before destroy.
refRef<ApollonEditor | null>Receives the editor after mount; nulled on unmount.

Hooks

HookReturnsPurpose
useApollonEditor()ApollonEditor | nullThe editor for the nearest <Apollon> / <ApollonProvider>.
useApollonEditorOrThrow()ApollonEditorSame, but throws if no editor is mounted.
useApollonSubscription<T>(subscribe, getSnapshot)T | undefinedSubscribe to any editor.subscribeTo* channel with one call.
<ApollonProvider editor={...}>Supply an externally-owned editor to descendants via context.

Constructor

new ApollonEditor(element: HTMLElement, options?: ApollonOptions)

element must be an HTMLElement — the constructor throws Error("Element is required to initialize Apollon") otherwise. The element must have an explicit height; see Quickstart and Troubleshooting.

ApollonOptions

Every field is optional.

OptionTypeDefaultEffect
typeUMLDiagramTypemodel.type or ClassDiagramDiagram type for a fresh canvas. Ignored when model is supplied and carries its own type.
modeApollonModeModellingModelling, Exporting, or Assessment. Drives which UI affordances render.
viewApollonViewModellingModelling, Exporting, or Highlight. Initial view.
availableViewsApollonView[][Modelling]Views the user may switch between. If supplied, the editor merges Modelling, the array, and the configured view. If omitted and view is Highlight, defaults to [Modelling, Highlight].
readonlybooleanfalseLocks the canvas. Can also be toggled at runtime with setReadonly.
enablePopupsbooleantrueEnables the inline edit/property popovers.
modelUMLModelempty diagramInitial diagram. Use importDiagram first if the JSON may be a v2/v3 model.
localeLocaleenAccepted for forward compatibility; the editor currently renders in English regardless.
debugbooleanfalseEnables debug overlays/logging.
collaborationEnabledbooleanfalseOpt into Yjs real-time sync. See Collaboration. Disables the local undo manager.
scrollLockbooleanfalsePrevents the canvas from capturing page scroll.

Lifecycle

MemberReturnsPurpose
new ApollonEditor(element, options?)Mount the editor's React tree into element.
destroy()voidUnmount, drop all subscriptions, stop sync, and destroy the Yjs doc. Always call before re-mounting on the same container.

State

Model

MemberTypePurpose
model (getter)UMLModelSnapshot of the current diagram as plain JSON.
model (setter)UMLModelReplace the entire diagram. Pass importDiagram(json) if the JSON may be v2/v3.
getDiagramMetadata(){ diagramTitle, diagramType }Title and type without serializing the whole model.
updateDiagramTitle(name)voidRename the diagram.
diagramType (setter)UMLDiagramTypeSwitch diagram type. Clears all nodes, edges, and assessments.

View and read-only state

MemberTypePurpose
view (getter / setter)ApollonViewRead or set the active view.
setReadonly(readonly)(boolean) => voidToggle read-only at runtime. Clears selection and any open popover when locking.
setPreviewMode(active)(boolean) => voidOverlay a snapshot on the canvas without writing to the Yjs doc. Used for version-history previews.
toggleInteractiveElementsMode(forceEnabled?)(boolean?) => voidToggle (or force) the Highlight view for marking interactive elements.
setMode(mode)(ApollonMode) => voidSwitch between Modelling, Assessment, and Exporting at runtime.
setScrollLock(locked)(boolean) => voidToggle whether the canvas captures page scroll.
fitView(options?)({ padding?, duration? }) => voidZoom/pan so the whole diagram is visible (capped at maxZoom: 1.0). padding defaults to 0.15, duration to 200 ms. Retries up to 10 rAF ticks.

Canvas geometry

MemberReturnsPurpose
getNodes()Node[]Live React Flow nodes ([] before init).
getEdges()Edge[]Live React Flow edges ([] before init).
getViewport(){ x, y, zoom } | nullCurrent viewport, or null before init.
screenToFlowPosition(position)XYPosition | nullConvert screen coordinates to canvas coordinates.
flowToScreenPosition(position)XYPosition | nullConvert canvas coordinates to screen coordinates.
getSelectedElements()string[]IDs of the currently selected elements.

Assessment

MemberTypePurpose
addOrUpdateAssessment(assessment)(Assessment) => voidAttach or update a score/feedback assessment on an element.
getInteractiveForSerialization()InteractiveElements | undefinedInteractive-element flags for inclusion in a saved model.

Subscriptions

Every subscribeTo… method returns a numeric subscription id. Pass it to unsubscribe(id) to detach. destroy() drops all subscriptions automatically.

Unless noted otherwise, subscribeTo* channels are coarse: they re-fire on any state-store change and the callback receives the current value of the named field. subscribeToSelectionChange is the only channel with a built-in prev/next equality check.

MethodCallback signature
subscribeToModelChange(cb)(model: UMLModel) => void
subscribeToDiagramNameChange(cb)(title: string) => void
subscribeToSelectionChange(cb)(selectedElementIds: string[]) => void
subscribeToAssessmentSelection(cb)(selectedElementIds: string[]) => void
subscribeToAwarenessChanges(cb)(states: Map<number, CollaborationState>) => void
subscribeToCollaboratorChanges(cb)(collaborators: CollaboratorInfo[]) => void
unsubscribe(subscriptionId)(number) => void
const id = editor.subscribeToModelChange((model) => persist(model))
// later
editor.unsubscribe(id)

Collaboration

These members are only meaningful with collaborationEnabled: true. See Collaboration for the full wiring.

MemberTypePurpose
sendBroadcastMessage(sendFn)((base64: string) => void) => voidRegister the callback the editor uses to emit Yjs frames.
receiveBroadcastedMessage(base64Data)(string) => voidFeed a received Yjs frame back into the editor.
broadcastFullState()() => voidPush the entire local Yjs doc to peers — call on every (re)connect.
setLocalAwarenessUser(user)(CollaborationUser) => voidSet the local user's identity for awareness.
setLocalAwarenessCursor(cursor)(CollaborationCursor | null) => voidPublish the local cursor position.
setLocalAwarenessSelectedElement(id)(string | null) => voidPublish the local selection.
setLocalAwarenessState(state)(Partial<CollaborationState>) => voidSet arbitrary local awareness state.
getLocalAwarenessClientId()() => numberThe local Yjs awareness client id.
getCollaborators()() => CollaboratorInfo[]The current collaborator roster.
ApollonEditor.generateInitialSyncMessage()() => string (static)Base64 handshake frame to request an initial sync.
ApollonEditor.generateInitialAwarenessSyncMessage()() => string (static)Base64 handshake frame to request an awareness sync.

Export

MemberReturnsPurpose
exportAsSVG(options?)Promise<SVG>Render the current model to SVG.
ApollonEditor.exportModelAsSvg(model, options?)Promise<SVG>Static. Render an arbitrary model to SVG with no mounted editor.

SVG is { svg: string, clip: { x, y, width, height } }. See Export for ExportOptions and the PNG/PDF pipeline.

Diagram types

Enum literals (the strings on the wire and in UMLModel.type) on the left; human-facing labels used elsewhere on the right.

Enum literalLabel
"ClassDiagram"Class
"ObjectDiagram"Object
"ActivityDiagram"Activity
"UseCaseDiagram"Use Case
"CommunicationDiagram"Communication
"ComponentDiagram"Component
"DeploymentDiagram"Deployment
"PetriNet"Petri Net
"ReachabilityGraph"Reachability Graph
"SyntaxTree"Syntax Tree
"Flowchart"Flowchart
"BPMN"BPMN
"Sfc"SFC

Enums

EnumMembers
ApollonModeModelling, Exporting, Assessment
ApollonViewModelling, Exporting, Highlight
Localeen, de

See Collaboration for the Yjs hooks and Export for SVG/PNG/PDF/JSON details.