@mermaid-editor-sdk/headless


@mermaid-editor-sdk/headless / EditorController

Class: EditorController

Defined in: core/editor-controller.ts:4

Constructors

Constructor

new EditorController(initialSource, onChange?): EditorController

Defined in: core/editor-controller.ts:15

Creates a controller for Mermaid source and an optional change callback.

Parameters

ParameterTypeDescription
initialSourcestringInitial Mermaid source.
onChange?(value) => voidCalled when a non-host source change is published.

Returns

EditorController

Properties

session

readonly session: DiagramSession

Defined in: core/editor-controller.ts:6

Underlying observable diagram session.

Methods

dispatch()

dispatch(action): string | undefined

Defined in: core/editor-controller.ts:63

Applies a diagram action and returns the new source when it changes.

Parameters

ParameterTypeDescription
actionDiagramActionDiagram action to validate and apply.

Returns

string | undefined


redo()

redo(): string | undefined

Defined in: core/editor-controller.ts:73

Restores the next source in history, if one is available.

Returns

string | undefined


setHostValue()

setHostValue(source): void

Defined in: core/editor-controller.ts:47

Applies a host value without publishing it as an edit.

Parameters

ParameterType
sourcestring

Returns

void


setOnChange()

setOnChange(callback?): void

Defined in: core/editor-controller.ts:24

Replaces the callback used for published source changes.

Parameters

ParameterTypeDescription
callback?(value) => voidCallback invoked when a non-host source change is published.

Returns

void


setSource()

setSource(source, origin?): boolean

Defined in: core/editor-controller.ts:56

Updates source and records its origin.

Parameters

ParameterTypeDefault valueDescription
sourcestring—Mermaid source to apply.
origin?ChangeOrigin'source-editor'Change origin.

Returns

boolean


start()

start(): void

Defined in: core/editor-controller.ts:29

Starts forwarding non-host session changes to the callback.

Returns

void


stop()

stop(): void

Defined in: core/editor-controller.ts:41

Stops forwarding session changes.

Returns

void


undo()

undo(): string | undefined

Defined in: core/editor-controller.ts:68

Restores the previous source, if one is available.

Returns

string | undefined