Skip to content

Commit

Permalink
chore: move commonDb into diagrams/common/commonDb
Browse files Browse the repository at this point in the history
  • Loading branch information
Yokozuna59 committed Sep 2, 2023
1 parent 6e51f8f commit a61887f
Show file tree
Hide file tree
Showing 19 changed files with 79 additions and 64 deletions.
47 changes: 0 additions & 47 deletions packages/mermaid/src/commonDb.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/mermaid/src/diagram-api/diagramAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

/*
Expand Down
7 changes: 6 additions & 1 deletion packages/mermaid/src/diagrams/c4/c4Db.js
Original file line number Diff line number Diff line change
@@ -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 = [''];
Expand Down
2 changes: 1 addition & 1 deletion packages/mermaid/src/diagrams/class/classDb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
clear as commonClear,
setDiagramTitle,
getDiagramTitle,
} from '../../commonDb.js';
} from '../common/commonDb.js';
import type {
ClassRelation,
ClassNode,
Expand Down
47 changes: 47 additions & 0 deletions packages/mermaid/src/diagrams/common/commonDb.ts
Original file line number Diff line number Diff line change
@@ -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,
};
12 changes: 12 additions & 0 deletions packages/mermaid/src/diagrams/common/commonTypes.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { DiagramDB } from '../../diagram-api/types.js';

export interface RectData {
x: number;
y: number;
Expand Down Expand Up @@ -56,3 +58,13 @@ export type D3ImageElement = d3.Selection<SVGImageElement, unknown, Element | nu
export type D3TextElement = d3.Selection<SVGTextElement, unknown, Element | null, unknown>;

export type D3TSpanElement = d3.Selection<SVGTSpanElement, unknown, Element | null, unknown>;

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;
}
2 changes: 1 addition & 1 deletion packages/mermaid/src/diagrams/er/erDb.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
clear as commonClear,
setDiagramTitle,
getDiagramTitle,
} from '../../commonDb.js';
} from '../common/commonDb.js';

let entities = {};
let relationships = [];
Expand Down
2 changes: 1 addition & 1 deletion packages/mermaid/src/diagrams/flowchart/flowDb.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion packages/mermaid/src/diagrams/gantt/ganttDb.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
clear as commonClear,
setDiagramTitle,
getDiagramTitle,
} from '../../commonDb.js';
} from '../common/commonDb.js';

dayjs.extend(dayjsIsoWeek);
dayjs.extend(dayjsCustomParseFormat);
Expand Down
2 changes: 1 addition & 1 deletion packages/mermaid/src/diagrams/git/gitGraphAst.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion packages/mermaid/src/diagrams/pie/pieDb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion packages/mermaid/src/diagrams/quadrant-chart/quadrantDb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion packages/mermaid/src/diagrams/requirement/requirementDb.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
getAccDescription,
setAccDescription,
clear as commonClear,
} from '../../commonDb.js';
} from '../common/commonDb.js';

let relations = [];
let latestRequirement = {};
Expand Down
2 changes: 1 addition & 1 deletion packages/mermaid/src/diagrams/sankey/sankeyDB.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = [];
Expand Down
2 changes: 1 addition & 1 deletion packages/mermaid/src/diagrams/sequence/sequenceDb.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
getAccDescription,
setAccDescription,
clear as commonClear,
} from '../../commonDb.js';
} from '../common/commonDb.js';

let prevActor = undefined;
let actors = {};
Expand Down
2 changes: 1 addition & 1 deletion packages/mermaid/src/diagrams/state/stateDb.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
clear as commonClear,
setDiagramTitle,
getDiagramTitle,
} from '../../commonDb.js';
} from '../common/commonDb.js';

import {
DEFAULT_DIAGRAM_DIRECTION,
Expand Down
2 changes: 0 additions & 2 deletions packages/mermaid/src/diagrams/timeline/timeline.spec.js
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -18,7 +17,6 @@ import {
// getConfig,
// sanitizeText,
// setupGraphViewBox,
// _commonDb,
// _parseDirective
// );

Expand Down
2 changes: 1 addition & 1 deletion packages/mermaid/src/diagrams/timeline/timelineDb.js
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
2 changes: 1 addition & 1 deletion packages/mermaid/src/diagrams/user-journey/journeyDb.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
getAccDescription,
setAccDescription,
clear as commonClear,
} from '../../commonDb.js';
} from '../common/commonDb.js';

let currentSection = '';

Expand Down

0 comments on commit a61887f

Please sign in to comment.