diff --git a/packages/mermaid/src/commonDb.ts b/packages/mermaid/src/commonDb.ts deleted file mode 100644 index 4e1e5141a6..0000000000 --- a/packages/mermaid/src/commonDb.ts +++ /dev/null @@ -1,47 +0,0 @@ -import { sanitizeText as _sanitizeText } from './diagrams/common/common.js'; -import { getConfig } from './config.js'; -let title = ''; -let diagramTitle = ''; -let description = ''; - -const sanitizeText = (txt: string): string => _sanitizeText(txt, getConfig()); - -export const clear = function (): void { - title = ''; - description = ''; - diagramTitle = ''; -}; - -export const setAccTitle = function (txt: string): void { - title = sanitizeText(txt).replace(/^\s+/g, ''); -}; - -export const getAccTitle = function (): string { - return title || diagramTitle; -}; - -export const setAccDescription = function (txt: string): void { - description = sanitizeText(txt).replace(/\n\s+/g, '\n'); -}; - -export const getAccDescription = function (): string { - return description; -}; - -export const setDiagramTitle = function (txt: string): void { - diagramTitle = sanitizeText(txt); -}; - -export const getDiagramTitle = function (): string { - return diagramTitle; -}; - -export default { - getAccTitle, - setAccTitle, - getDiagramTitle, - setDiagramTitle, - getAccDescription, - setAccDescription, - clear, -}; diff --git a/packages/mermaid/src/diagram-api/diagramAPI.ts b/packages/mermaid/src/diagram-api/diagramAPI.ts index 00da66ffe4..6f1421527a 100644 --- a/packages/mermaid/src/diagram-api/diagramAPI.ts +++ b/packages/mermaid/src/diagram-api/diagramAPI.ts @@ -5,7 +5,7 @@ import { sanitizeText as _sanitizeText } from '../diagrams/common/common.js'; import { setupGraphViewbox as _setupGraphViewbox } from '../setupGraphViewbox.js'; import { addStylesForDiagram } from '../styles.js'; import type { DiagramDefinition, DiagramDetector } from './types.js'; -import * as _commonDb from '../commonDb.js'; +import * as _commonDb from '../diagrams/common/commonDb.js'; import { parseDirective as _parseDirective } from '../directiveUtils.js'; /* diff --git a/packages/mermaid/src/diagrams/c4/c4Db.js b/packages/mermaid/src/diagrams/c4/c4Db.js index 09dcc13cda..7c450940f6 100644 --- a/packages/mermaid/src/diagrams/c4/c4Db.js +++ b/packages/mermaid/src/diagrams/c4/c4Db.js @@ -1,7 +1,12 @@ import mermaidAPI from '../../mermaidAPI.js'; import * as configApi from '../../config.js'; import { sanitizeText } from '../common/common.js'; -import { setAccTitle, getAccTitle, getAccDescription, setAccDescription } from '../../commonDb.js'; +import { + setAccTitle, + getAccTitle, + getAccDescription, + setAccDescription, +} from '../common/commonDb.js'; let c4ShapeArray = []; let boundaryParseStack = ['']; diff --git a/packages/mermaid/src/diagrams/class/classDb.ts b/packages/mermaid/src/diagrams/class/classDb.ts index b14b1d07a1..786a3e2b26 100644 --- a/packages/mermaid/src/diagrams/class/classDb.ts +++ b/packages/mermaid/src/diagrams/class/classDb.ts @@ -14,7 +14,7 @@ import { clear as commonClear, setDiagramTitle, getDiagramTitle, -} from '../../commonDb.js'; +} from '../common/commonDb.js'; import type { ClassRelation, ClassNode, diff --git a/packages/mermaid/src/diagrams/common/commonDb.ts b/packages/mermaid/src/diagrams/common/commonDb.ts new file mode 100644 index 0000000000..49198e683a --- /dev/null +++ b/packages/mermaid/src/diagrams/common/commonDb.ts @@ -0,0 +1,47 @@ +import { sanitizeText as _sanitizeText } from './common.js'; +import { getConfig } from '../../config.js'; +import type { CommonDb } from './commonTypes.js'; + +let accTitle = ''; +let diagramTitle = ''; +let accDescription = ''; + +const sanitizeText = (txt: string): string => _sanitizeText(txt, getConfig()); + +export const clear = (): void => { + accTitle = ''; + accDescription = ''; + diagramTitle = ''; +}; + +export const setAccTitle = (txt: string): void => { + accTitle = sanitizeText(txt).replace(/^\s+/g, ''); +}; + +export const getAccTitle = (): string => { + return accTitle; +}; + +export const setAccDescription = (txt: string): void => { + accDescription = sanitizeText(txt).replace(/\n\s+/g, '\n'); +}; + +export const getAccDescription = (): string => { + return accDescription; +}; + +export const setDiagramTitle = (txt: string): void => { + diagramTitle = sanitizeText(txt); +}; + +export const getDiagramTitle = (): string => diagramTitle; + +export const db: CommonDb = { + getAccTitle, + setAccTitle, + getDiagramTitle, + setDiagramTitle, + getAccDescription, + setAccDescription, + clear, +}; diff --git a/packages/mermaid/src/diagrams/common/commonTypes.ts b/packages/mermaid/src/diagrams/common/commonTypes.ts index 84c26db6e1..b856bc362a 100644 --- a/packages/mermaid/src/diagrams/common/commonTypes.ts +++ b/packages/mermaid/src/diagrams/common/commonTypes.ts @@ -1,3 +1,5 @@ +import type { DiagramDB } from '../../diagram-api/types.js'; + export interface RectData { x: number; y: number; @@ -56,3 +58,13 @@ export type D3ImageElement = d3.Selection; export type D3TSpanElement = d3.Selection; + +export interface CommonDb extends DiagramDB { + clear: () => void; + setDiagramTitle: (title: string) => void; + getDiagramTitle: () => string; + setAccTitle: (title: string) => void; + getAccTitle: () => string; + setAccDescription: (describetion: string) => void; + getAccDescription: () => string; +} diff --git a/packages/mermaid/src/diagrams/er/erDb.js b/packages/mermaid/src/diagrams/er/erDb.js index 2f412f7dd8..01bbb585cd 100644 --- a/packages/mermaid/src/diagrams/er/erDb.js +++ b/packages/mermaid/src/diagrams/er/erDb.js @@ -10,7 +10,7 @@ import { clear as commonClear, setDiagramTitle, getDiagramTitle, -} from '../../commonDb.js'; +} from '../common/commonDb.js'; let entities = {}; let relationships = []; diff --git a/packages/mermaid/src/diagrams/flowchart/flowDb.js b/packages/mermaid/src/diagrams/flowchart/flowDb.js index ea8fa71d2b..2bb50abee1 100644 --- a/packages/mermaid/src/diagrams/flowchart/flowDb.js +++ b/packages/mermaid/src/diagrams/flowchart/flowDb.js @@ -12,7 +12,7 @@ import { clear as commonClear, setDiagramTitle, getDiagramTitle, -} from '../../commonDb.js'; +} from '../common/commonDb.js'; const MERMAID_DOM_ID_PREFIX = 'flowchart-'; let vertexCounter = 0; diff --git a/packages/mermaid/src/diagrams/gantt/ganttDb.js b/packages/mermaid/src/diagrams/gantt/ganttDb.js index da838f8392..3ff7955f85 100644 --- a/packages/mermaid/src/diagrams/gantt/ganttDb.js +++ b/packages/mermaid/src/diagrams/gantt/ganttDb.js @@ -16,7 +16,7 @@ import { clear as commonClear, setDiagramTitle, getDiagramTitle, -} from '../../commonDb.js'; +} from '../common/commonDb.js'; dayjs.extend(dayjsIsoWeek); dayjs.extend(dayjsCustomParseFormat); diff --git a/packages/mermaid/src/diagrams/git/gitGraphAst.js b/packages/mermaid/src/diagrams/git/gitGraphAst.js index 416479d151..dc9c32da9b 100644 --- a/packages/mermaid/src/diagrams/git/gitGraphAst.js +++ b/packages/mermaid/src/diagrams/git/gitGraphAst.js @@ -12,7 +12,7 @@ import { clear as commonClear, setDiagramTitle, getDiagramTitle, -} from '../../commonDb.js'; +} from '../common/commonDb.js'; let mainBranchName = getConfig().gitGraph.mainBranchName; let mainBranchOrder = getConfig().gitGraph.mainBranchOrder; diff --git a/packages/mermaid/src/diagrams/pie/pieDb.ts b/packages/mermaid/src/diagrams/pie/pieDb.ts index dbe50f08a0..7f209de460 100644 --- a/packages/mermaid/src/diagrams/pie/pieDb.ts +++ b/packages/mermaid/src/diagrams/pie/pieDb.ts @@ -10,7 +10,7 @@ import { getAccDescription, setAccDescription, clear as commonClear, -} from '../../commonDb.js'; +} from '../common/commonDb.js'; import type { ParseDirectiveDefinition } from '../../diagram-api/types.js'; import type { PieFields, PieDB, Sections } from './pieTypes.js'; import type { RequiredDeep } from 'type-fest'; diff --git a/packages/mermaid/src/diagrams/quadrant-chart/quadrantDb.ts b/packages/mermaid/src/diagrams/quadrant-chart/quadrantDb.ts index c0c0f4c8ac..0dc87a2d48 100644 --- a/packages/mermaid/src/diagrams/quadrant-chart/quadrantDb.ts +++ b/packages/mermaid/src/diagrams/quadrant-chart/quadrantDb.ts @@ -10,7 +10,7 @@ import { getAccDescription, setAccDescription, clear as commonClear, -} from '../../commonDb.js'; +} from '../common/commonDb.js'; import { QuadrantBuilder } from './quadrantBuilder.js'; const config = configApi.getConfig(); diff --git a/packages/mermaid/src/diagrams/requirement/requirementDb.js b/packages/mermaid/src/diagrams/requirement/requirementDb.js index 1d0a3e2e12..c56c4ca162 100644 --- a/packages/mermaid/src/diagrams/requirement/requirementDb.js +++ b/packages/mermaid/src/diagrams/requirement/requirementDb.js @@ -8,7 +8,7 @@ import { getAccDescription, setAccDescription, clear as commonClear, -} from '../../commonDb.js'; +} from '../common/commonDb.js'; let relations = []; let latestRequirement = {}; diff --git a/packages/mermaid/src/diagrams/sankey/sankeyDB.ts b/packages/mermaid/src/diagrams/sankey/sankeyDB.ts index f6db1886d6..8b3a22c5a0 100644 --- a/packages/mermaid/src/diagrams/sankey/sankeyDB.ts +++ b/packages/mermaid/src/diagrams/sankey/sankeyDB.ts @@ -8,7 +8,7 @@ import { setDiagramTitle, getDiagramTitle, clear as commonClear, -} from '../../commonDb.js'; +} from '../common/commonDb.js'; // Sankey diagram represented by nodes and links between those nodes let links: SankeyLink[] = []; diff --git a/packages/mermaid/src/diagrams/sequence/sequenceDb.js b/packages/mermaid/src/diagrams/sequence/sequenceDb.js index b5d68fb9f5..475b0314d8 100644 --- a/packages/mermaid/src/diagrams/sequence/sequenceDb.js +++ b/packages/mermaid/src/diagrams/sequence/sequenceDb.js @@ -10,7 +10,7 @@ import { getAccDescription, setAccDescription, clear as commonClear, -} from '../../commonDb.js'; +} from '../common/commonDb.js'; let prevActor = undefined; let actors = {}; diff --git a/packages/mermaid/src/diagrams/state/stateDb.js b/packages/mermaid/src/diagrams/state/stateDb.js index d9c789a99b..f71290ec3a 100644 --- a/packages/mermaid/src/diagrams/state/stateDb.js +++ b/packages/mermaid/src/diagrams/state/stateDb.js @@ -11,7 +11,7 @@ import { clear as commonClear, setDiagramTitle, getDiagramTitle, -} from '../../commonDb.js'; +} from '../common/commonDb.js'; import { DEFAULT_DIAGRAM_DIRECTION, diff --git a/packages/mermaid/src/diagrams/timeline/timeline.spec.js b/packages/mermaid/src/diagrams/timeline/timeline.spec.js index 1f6a960244..a6a94fd0c7 100644 --- a/packages/mermaid/src/diagrams/timeline/timeline.spec.js +++ b/packages/mermaid/src/diagrams/timeline/timeline.spec.js @@ -1,7 +1,6 @@ import { parser as timeline } from './parser/timeline.jison'; import * as timelineDB from './timelineDb.js'; // import { injectUtils } from './mermaidUtils.js'; -import * as _commonDb from '../../commonDb.js'; import { parseDirective as _parseDirective } from '../../directiveUtils.js'; import { @@ -18,7 +17,6 @@ import { // getConfig, // sanitizeText, // setupGraphViewBox, -// _commonDb, // _parseDirective // ); diff --git a/packages/mermaid/src/diagrams/timeline/timelineDb.js b/packages/mermaid/src/diagrams/timeline/timelineDb.js index 337cfe4416..e5e22147d1 100644 --- a/packages/mermaid/src/diagrams/timeline/timelineDb.js +++ b/packages/mermaid/src/diagrams/timeline/timelineDb.js @@ -1,5 +1,5 @@ import { parseDirective as _parseDirective } from '../../directiveUtils.js'; -import * as commonDb from '../../commonDb.js'; +import * as commonDb from '../common/commonDb.js'; let currentSection = ''; let currentTaskId = 0; diff --git a/packages/mermaid/src/diagrams/user-journey/journeyDb.js b/packages/mermaid/src/diagrams/user-journey/journeyDb.js index d4f34e9422..509c5dc148 100644 --- a/packages/mermaid/src/diagrams/user-journey/journeyDb.js +++ b/packages/mermaid/src/diagrams/user-journey/journeyDb.js @@ -8,7 +8,7 @@ import { getAccDescription, setAccDescription, clear as commonClear, -} from '../../commonDb.js'; +} from '../common/commonDb.js'; let currentSection = '';