From e52de6c27982fd8b1cedb8e2c00fb137e0081ed9 Mon Sep 17 00:00:00 2001 From: Knut Sveidqvist Date: Fri, 1 Sep 2023 15:40:49 +0200 Subject: [PATCH] Some cleanup --- .../mermaid/src/diagrams/block/blockDB.ts | 58 ------------------- 1 file changed, 58 deletions(-) diff --git a/packages/mermaid/src/diagrams/block/blockDB.ts b/packages/mermaid/src/diagrams/block/blockDB.ts index 9717bc348..b0a7c20c1 100644 --- a/packages/mermaid/src/diagrams/block/blockDB.ts +++ b/packages/mermaid/src/diagrams/block/blockDB.ts @@ -15,8 +15,6 @@ import { } from '../../commonDb.js'; import { log } from '../../logger.js'; -// export type TBlockColumnsDefaultValue = 'H'; // Do we support something else, like 'auto' | 0? - // Initialize the node database for simple lookups let blockDatabase: Record = {}; @@ -38,14 +36,6 @@ const populateBlockDatabase = (blockList: Block[], parent: Block): void => { } }; -// Function to get a node by its id -type IGetNodeById = (id: string) => Block | undefined; -export const getBlockById = (id: string): Block | undefined => { - return blockDatabase[id]; -}; - -// TODO: Convert to generic TreeNode type? Convert to class? - let blocks: Block[] = []; const links: Link[] = []; let rootBlock = { id: 'root', type: 'composite', children: [], columns: -1 } as Block; @@ -78,28 +68,6 @@ export const generateId = () => { return 'id-' + Math.random().toString(36).substr(2, 12) + '-' + cnt; }; -type IAddBlock = (_id: string, label: string, type: BlockType) => Block; -// Function to add a node to the database -export const addBlock = (_id: string, _label?: string, type?: BlockType) => { - let id = _id; - if (!_id) { - id = generateId(); - } - const label = _label || id; - const node: Block = { - id: id, - label, - type: type || 'square', - children: [], - }; - blockDatabase[node.id] = node; - // currentBlock.children ??= []; - // currentBlock.children.push(node); - // log.info('currentBlock', currentBlock.children, nodeDatabase); - log.info('addNode called:', id, label, type, node); - return node; -}; - type ISetHierarchy = (block: Block[]) => void; const setHierarchy = (block: Block[]): void => { populateBlockDatabase(block, rootBlock); @@ -113,25 +81,6 @@ const addLink: IAddLink = (link: Link): Link => { return link; }; -type ISetColumns = (columnsStr: string) => void; -const setColumns = (columnsStr: string): void => { - const columns = columnsStr === 'auto' ? -1 : parseInt(columnsStr); -}; - -const getBlock = (id: string, blocks: Block[]): Block | undefined => { - for (const block of blocks) { - if (block.id === id) { - return block; - } - if (block.children) { - const foundBlock = getBlock(id, block.children); - if (foundBlock) { - return foundBlock; - } - } - } -}; - type IGetColumns = (blockid: string) => number; const getColumns = (blockid: string): number => { const block = blockDatabase[blockid]; @@ -149,7 +98,6 @@ const getColumns = (blockid: string): number => { type IGetBlocks = () => Block[]; const getBlocks: IGetBlocks = () => { - // log.info('Block in test', rootBlock.children || []); log.info('Block in test', blocks, blocks[0].id); return blocks || []; }; @@ -163,36 +111,30 @@ const getLogger: IGetLogger = () => console; export interface BlockDB extends DiagramDB { clear: () => void; getConfig: () => BlockConfig | undefined; - addBlock: IAddBlock; addLink: IAddLink; getLogger: IGetLogger; getBlocks: IGetBlocks; getLinks: IGetLinks; - setColumns: ISetColumns; getColumns: IGetColumns; typeStr2Type: ITypeStr2Type; setHierarchy: ISetHierarchy; - getBlockById: IGetNodeById; generateId: IGenerateId; } const db: BlockDB = { getConfig: () => configApi.getConfig().block, - addBlock: addBlock, addLink: addLink, typeStr2Type: typeStr2Type, getLogger, // TODO: remove getBlocks, getLinks, setHierarchy, - getBlockById, // getAccTitle, // setAccTitle, // getAccDescription, // setAccDescription, // getDiagramTitle, // setDiagramTitle, - setColumns, getColumns, clear, generateId,