diff --git a/.changeset/weak-trees-perform.md b/.changeset/weak-trees-perform.md index 1750103fb..17175301d 100644 --- a/.changeset/weak-trees-perform.md +++ b/.changeset/weak-trees-perform.md @@ -2,4 +2,4 @@ 'mermaid': patch --- -In State Diagram refactored getDirection to retrieve the direction from rootDoc, defaulting to DEFAULT_DIAGRAM_DIRECTION and Updated setDirection to modify the existing direction if found or prepend a new entry if not. +fix: `getDirection` and `setDirection` in `stateDb` refactored to return and set actual direction diff --git a/packages/mermaid/src/diagrams/state/stateDb.js b/packages/mermaid/src/diagrams/state/stateDb.js index 1080451c2..029db9c6f 100644 --- a/packages/mermaid/src/diagrams/state/stateDb.js +++ b/packages/mermaid/src/diagrams/state/stateDb.js @@ -657,13 +657,21 @@ export class StateDB { } } - getDirection() { - const doc = this.rootDoc.find((doc) => doc.stmt === STMT_DIRECTION); - const direction = doc ? doc.value : DEFAULT_DIAGRAM_DIRECTION; - return direction; + /** + * Finds the direction statement in the root document. + * @private + * @returns {{ value: string } | undefined} - the direction statement if present + */ + getDirectionStatement() { + return this.rootDoc.find((doc) => doc.stmt === STMT_DIRECTION); } + + getDirection() { + return this.getDirectionStatement()?.value ?? DEFAULT_DIAGRAM_DIRECTION; + } + setDirection(dir) { - const doc = this.rootDoc.find((doc) => doc.stmt === STMT_DIRECTION); + const doc = this.getDirectionStatement(); if (doc) { doc.value = dir; } else {