ApollonEditor API¶
The ApollonEditor class is the primary entry point exported by
@besser/wme. Instantiate it with a DOM container and a set of options, then
use the provided methods and subscriptions to tailor the editor to your
application.
Initialisation¶
import { ApollonEditor, UMLDiagramType, ApollonMode, Locale } from '@besser/wme';
const editor = new ApollonEditor(containerElement, {
type: UMLDiagramType.ClassDiagram,
mode: ApollonMode.Modelling,
readonly: false,
enablePopups: true,
locale: Locale.en,
});
await editor.nextRender;
Call await editor.nextRender before accessing the internal Redux store or
subscribing to events; it resolves after the first React render cycle finishes.
Constructor options¶
type(UMLDiagramType)Initial diagram palette to display. Required when the model does not define a
type.mode(ApollonMode)Determines toolbar behaviour.
Modellingunlocks editing,Exportingexposes export views,Assessmentlimits interactions to assessment tools.readonly(boolean)Disables palette actions, movement, and editing when set to
true. The sidebar remains visible but locked.enablePopups(boolean, defaulttrue)Controls whether double-click popups (attribute editors, relationship menus) appear.
copyPasteToClipboard(boolean)Enables the legacy browser clipboard integration.
colorEnabled(boolean)Activates colour-aware palette entries and the optional colour legend.
locale(Localeenum)Localises UI strings using
src/main/i18nresources. Defaults to English.theme(partialStyles)Overrides the default theming tokens. Accepts the
Stylesstructure fromcomponents/theme/styles.scale(number)Sets the initial zoom value. Equivalent to the Zoom slider in the UI.
model(UMLModel)Pre-loads an existing diagram. When not provided, the editor initialises an empty diagram of the requested type.
Model management¶
editor.model(getter)Returns the current
UMLModelrepresentation.editor.model = umlModel(setter)Replaces the diagram with the provided model and resets interaction state.
editor.type = UMLDiagramType(setter)Switches the active palette to another diagram type and clears the canvas.
editor.locale = Locale(setter)Re-renders the UI with the requested translations.
editor.select(selection)(method)Programmatically select/deselect elements by ID using the
Selectiontype.
Subscriptions¶
All subscription methods return a numeric ID; pass the same ID to the matching
unsubscribe call.
subscribeToModelChange/unsubscribeFromModelChangeFires after debouncing when the model changes. Use it to autosave diagrams.
subscribeToModelDiscreteChangeNotified only at the end of an interaction (mouse up, delete). Helpful when you care about completed user actions rather than intermediate drag events.
subscribeToModelChangePatches/subscribeToAllModelChangePatches/subscribeToModelContinuousChangePatchesEmit JSON Patch objects describing changes.
Alldelivers both continuous and discrete patches;Continuoussurfaces high frequency updates during a drag;ModelChangelimits to discrete updates. UseunsubscribeFromModelChangePatchesto remove any of them.subscribeToSelectionChange/unsubscribeFromSelectionChangeTrack element and relationship selection.
subscribeToAssessmentChange/unsubscribeFromAssessmentChangeObserve the set of assessment annotations in the model.
subscribeToApollonErrors/unsubscribeToApollonErrorsListen for unexpected runtime errors. The editor attempts to recover to the latest known state, but the callback lets you escalate the failure.
Collaboration helpers¶
importPatch(patch)Applies a JSON Patch (as emitted by
subscribeTo…Patches) to the current model.remoteSelect(name, color, selectIds, deselectIds?)Mirrors remote selections inside the canvas using coloured cursors.
pruneRemoteSelectors(allowedSelectors)Remove remote cursors that are no longer active.
Exports¶
exportAsSVG(options?)Renders the in-memory model to an SVG string and associated bounding box.
ApollonEditor.exportModelAsSvg(model, options?, theme?)Static helper to export a
UMLModelwithout instantiating the editor UI.getScaleFactor()Returns the current zoom factor applied to the canvas.
Lifecycle¶
destroy()Unmounts React components and releases resources tied to the container. Always call
destroywhen discarding the editor instance.nextRender(promise)Resolves after the editor finishes its current render pass. Await it before calling any subscription APIs from freshly created instances.