Small cleanup

This commit is contained in:
Nikolay Rozhkov 2023-07-07 14:12:18 +03:00
parent 791e67641e
commit fee2b244a1
4 changed files with 27 additions and 29 deletions

View File

@ -1,6 +1,7 @@
// TODO: This was auto generated from defaultConfig. Needs to be verified. // TODO: This was auto generated from defaultConfig. Needs to be verified.
import DOMPurify from 'dompurify'; import DOMPurify from 'dompurify';
import { BlockConfig } from './diagrams/block/blockTypes.js';
export interface MermaidConfig { export interface MermaidConfig {
theme?: string; theme?: string;
@ -33,7 +34,7 @@ export interface MermaidConfig {
gitGraph?: GitGraphDiagramConfig; gitGraph?: GitGraphDiagramConfig;
c4?: C4DiagramConfig; c4?: C4DiagramConfig;
sankey?: SankeyDiagramConfig; sankey?: SankeyDiagramConfig;
block?: BlockDiagramConfig; block?: BlockConfig;
dompurifyConfig?: DOMPurify.Config; dompurifyConfig?: DOMPurify.Config;
wrap?: boolean; wrap?: boolean;
fontSize?: number; fontSize?: number;
@ -422,9 +423,6 @@ export interface SankeyDiagramConfig extends BaseDiagramConfig {
linkColor?: SankeyLinkColor | string; linkColor?: SankeyLinkColor | string;
nodeAlignment?: SankeyNodeAlignment; nodeAlignment?: SankeyNodeAlignment;
} }
export interface BlockDiagramConfig extends BaseDiagramConfig {
padding?: number;
}
export interface FontConfig { export interface FontConfig {
fontSize?: string | number; fontSize?: string | number;

View File

@ -1,12 +1,14 @@
import type { BlockDB } from './blockTypes.js';
import * as configApi from '../../config.js'; import * as configApi from '../../config.js';
import common from '../common/common.js'; // import common from '../common/common.js';
import { import {
setAccTitle, // setAccTitle,
getAccTitle, // getAccTitle,
getAccDescription, // getAccDescription,
setAccDescription, // setAccDescription,
setDiagramTitle, // setDiagramTitle,
getDiagramTitle, // getDiagramTitle,
clear as commonClear, clear as commonClear,
} from '../../commonDb.js'; } from '../../commonDb.js';
@ -14,7 +16,6 @@ type Block = {
ID: string; ID: string;
}; };
// Array of nodes guarantees their order
let blocks: Block[] = []; let blocks: Block[] = [];
const clear = (): void => { const clear = (): void => {
@ -22,14 +23,16 @@ const clear = (): void => {
commonClear(); commonClear();
}; };
export default { const db: BlockDB = {
getConfig: () => configApi.getConfig().block, getConfig: () => configApi.getConfig().block,
getAccTitle, // getAccTitle,
setAccTitle, // setAccTitle,
getAccDescription, // getAccDescription,
setAccDescription, // setAccDescription,
getDiagramTitle, // getDiagramTitle,
setDiagramTitle, // setDiagramTitle,
clear, clear,
}; };
export default db;

View File

@ -9,18 +9,14 @@ import {
import { configureSvgSize } from '../../setupGraphViewbox.js'; import { configureSvgSize } from '../../setupGraphViewbox.js';
import { Uid } from '../../rendering-util/uid.js'; import { Uid } from '../../rendering-util/uid.js';
import type { SankeyLinkColor, SankeyNodeAlignment } from '../../config.type.js';
export const draw = function (text: string, id: string, _version: string, diagObj: Diagram): void { export const draw = function (text: string, id: string, _version: string, diagObj: Diagram): void {
// Get the config
const { securityLevel, sankey: conf } = configApi.getConfig();
const defaultSankeyConfig = configApi!.defaultConfig!.blockDiagram!;
// TODO: // TODO:
// This code repeats for every diagram // This code repeats for every diagram
// Figure out what is happening there, probably it should be separated // Figure out what is happening there, probably it should be separated
// The main thing is svg object that is a d3 wrapper for svg operations // The main thing is svg object that is a d3 wrapper for svg operations
// //
const { securityLevel } = configApi.getConfig();
let sandboxElement: any; let sandboxElement: any;
if (securityLevel === 'sandbox') { if (securityLevel === 'sandbox') {
sandboxElement = d3select('#i' + id); sandboxElement = d3select('#i' + id);
@ -44,11 +40,6 @@ export const draw = function (text: string, id: string, _version: string, diagOb
// Prepare data for construction based on diagObj.db // Prepare data for construction based on diagObj.db
// This must be a mutable object with `nodes` and `links` properties: // This must be a mutable object with `nodes` and `links` properties:
// //
// {
// "nodes": [ { "id": "Alice" }, { "id": "Bob" }, { "id": "Carol" } ],
// "links": [ { "source": "Alice", "target": "Bob", "value": 23 }, { "source": "Bob", "target": "Carol", "value": 43 } ]
// }
//
// @ts-ignore TODO: db type // @ts-ignore TODO: db type
const graph = diagObj.db.getGraph(); const graph = diagObj.db.getGraph();

View File

@ -1,5 +1,11 @@
import type { DiagramDB } from '../../diagram-api/types.js'; import type { DiagramDB } from '../../diagram-api/types.js';
import type { BaseDiagramConfig } from '../../config.type.js';
export interface BlockConfig extends BaseDiagramConfig {
padding?: number;
}
export interface BlockDB extends DiagramDB { export interface BlockDB extends DiagramDB {
clear: () => void; clear: () => void;
getConfig: () => BlockConfig | undefined;
} }