@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
| Parameter | Type | Description |
|---|---|---|
initialSource | string | Initial Mermaid source. |
Returns
DiagramSession
Properties
store
readonlystore: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
| Parameter | Type | Description |
|---|---|---|
action | DiagramAction | Action 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
getSnapshot()
getSnapshot():
SessionSnapshot
Defined in: core/diagram-session.ts:436
Returns the current session snapshot.
Returns
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
| Parameter | Type | Description |
|---|---|---|
sourceRevision | number | Revision that was parsed. |
valid | boolean | Whether 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
| Parameter | Type | Default value | Description |
|---|---|---|---|
source | string | — | 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
| Parameter | Type |
|---|---|
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