@mermaid-editor-sdk/headless


@mermaid-editor-sdk/headless / DiagramSession

Class: DiagramSession

Defined in: core/diagram-session.ts:404

Constructors

Constructor

new DiagramSession(initialSource): DiagramSession

Defined in: core/diagram-session.ts:418

Creates a session initialized with Mermaid source.

Parameters

ParameterTypeDescription
initialSourcestringInitial Mermaid source.

Returns

DiagramSession

Properties

store

readonly store: StoreApi<SessionSnapshot>

Defined in: core/diagram-session.ts:413

Vanilla Zustand store containing the current session snapshot.

Methods

dispatch()

dispatch(action): string | undefined

Defined in: core/diagram-session.ts:469

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

Parameters

ParameterTypeDescription
actionDiagramActionAction to validate and apply to the current diagram.

Returns

string | undefined


getServerSnapshot()

getServerSnapshot(): SessionSnapshot

Defined in: core/diagram-session.ts:438

Returns the initial snapshot for server rendering.

Returns

SessionSnapshot


getSnapshot()

getSnapshot(): SessionSnapshot

Defined in: core/diagram-session.ts:436

Returns the current session snapshot.

Returns

SessionSnapshot


redo()

redo(): string | undefined

Defined in: core/diagram-session.ts:507

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

Returns

string | undefined


setParseResult()

setParseResult(sourceRevision, valid): void

Defined in: core/diagram-session.ts:489

Updates parse state only when the revision still matches the current source.

Parameters

ParameterTypeDescription
sourceRevisionnumberRevision that was parsed.
validbooleanWhether parsing succeeded.

Returns

void


setSource()

setSource(source, origin?): boolean

Defined in: core/diagram-session.ts:446

Replaces source and updates undo history according to the change origin.

Parameters

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

Returns

boolean


subscribe()

subscribe(listener): () => void

Defined in: core/diagram-session.ts:440

Subscribes to snapshot changes and returns an unsubscribe function.

Parameters

ParameterType
listener() => void

Returns

() => void


undo()

undo(): string | undefined

Defined in: core/diagram-session.ts:499

Restores the previous source, if one is available.

Returns

string | undefined