mirror of
				https://github.com/mermaid-js/mermaid.git
				synced 2025-11-04 04:44:08 +01:00 
			
		
		
		
	fix: update ClassDB and ClassTypes for improved type safety and consistency
This commit is contained in:
		@@ -17,6 +17,7 @@ import type {
 | 
				
			|||||||
  ClassRelation,
 | 
					  ClassRelation,
 | 
				
			||||||
  ClassNode,
 | 
					  ClassNode,
 | 
				
			||||||
  ClassNote,
 | 
					  ClassNote,
 | 
				
			||||||
 | 
					  ClassNoteMap,
 | 
				
			||||||
  ClassMap,
 | 
					  ClassMap,
 | 
				
			||||||
  NamespaceMap,
 | 
					  NamespaceMap,
 | 
				
			||||||
  NamespaceNode,
 | 
					  NamespaceNode,
 | 
				
			||||||
@@ -33,9 +34,9 @@ const sanitizeText = (txt: string) => common.sanitizeText(txt, getConfig());
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
export class ClassDB implements DiagramDB {
 | 
					export class ClassDB implements DiagramDB {
 | 
				
			||||||
  private relations: ClassRelation[] = [];
 | 
					  private relations: ClassRelation[] = [];
 | 
				
			||||||
  private classes = new Map<string, ClassNode>();
 | 
					  private classes: ClassMap = new Map<string, ClassNode>();
 | 
				
			||||||
  private readonly styleClasses = new Map<string, StyleClass>();
 | 
					  private readonly styleClasses = new Map<string, StyleClass>();
 | 
				
			||||||
  private notes = new Map<string, ClassNote>();
 | 
					  private notes: ClassNoteMap = new Map<string, ClassNote>();
 | 
				
			||||||
  private interfaces: Interface[] = [];
 | 
					  private interfaces: Interface[] = [];
 | 
				
			||||||
  // private static classCounter = 0;
 | 
					  // private static classCounter = 0;
 | 
				
			||||||
  private namespaces = new Map<string, NamespaceNode>();
 | 
					  private namespaces = new Map<string, NamespaceNode>();
 | 
				
			||||||
@@ -125,7 +126,7 @@ export class ClassDB implements DiagramDB {
 | 
				
			|||||||
      annotations: [],
 | 
					      annotations: [],
 | 
				
			||||||
      styles: [],
 | 
					      styles: [],
 | 
				
			||||||
      domId: MERMAID_DOM_ID_PREFIX + name + '-' + classCounter,
 | 
					      domId: MERMAID_DOM_ID_PREFIX + name + '-' + classCounter,
 | 
				
			||||||
    } as ClassNode);
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    classCounter++;
 | 
					    classCounter++;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
@@ -184,7 +185,7 @@ export class ClassDB implements DiagramDB {
 | 
				
			|||||||
    return this.notes.get(key)!;
 | 
					    return this.notes.get(key)!;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  public getNotes() {
 | 
					  public getNotes(): ClassNoteMap {
 | 
				
			||||||
    return this.notes;
 | 
					    return this.notes;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -297,7 +298,7 @@ export class ClassDB implements DiagramDB {
 | 
				
			|||||||
    return note.id;
 | 
					    return note.id;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  public cleanupLabel(label: string) {
 | 
					  public cleanupLabel(label: string): string {
 | 
				
			||||||
    if (label.startsWith(':')) {
 | 
					    if (label.startsWith(':')) {
 | 
				
			||||||
      label = label.substring(1);
 | 
					      label = label.substring(1);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@@ -363,7 +364,7 @@ export class ClassDB implements DiagramDB {
 | 
				
			|||||||
    });
 | 
					    });
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  public getTooltip(id: string, namespace?: string) {
 | 
					  public getTooltip(id: string, namespace?: string): string | undefined {
 | 
				
			||||||
    if (namespace && this.namespaces.has(namespace)) {
 | 
					    if (namespace && this.namespaces.has(namespace)) {
 | 
				
			||||||
      return this.namespaces.get(namespace)!.classes.get(id)!.tooltip;
 | 
					      return this.namespaces.get(namespace)!.classes.get(id)!.tooltip;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@@ -543,10 +544,11 @@ export class ClassDB implements DiagramDB {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    this.namespaces.set(id, {
 | 
					    this.namespaces.set(id, {
 | 
				
			||||||
      id: id,
 | 
					      id: id,
 | 
				
			||||||
      classes: new Map(),
 | 
					      classes: new Map<string, ClassNode>(),
 | 
				
			||||||
      children: {},
 | 
					      notes: new Map<string, ClassNote>(),
 | 
				
			||||||
 | 
					      children: new Map<string, NamespaceNode>(),
 | 
				
			||||||
      domId: MERMAID_DOM_ID_PREFIX + id + '-' + this.namespaceCounter,
 | 
					      domId: MERMAID_DOM_ID_PREFIX + id + '-' + this.namespaceCounter,
 | 
				
			||||||
    } as NamespaceNode);
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    this.namespaceCounter++;
 | 
					    this.namespaceCounter++;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
@@ -648,9 +650,13 @@ export class ClassDB implements DiagramDB {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for (const classNode of this.classes.values()) {
 | 
					    for (const classNode of this.classes.values()) {
 | 
				
			||||||
      const node = classNode as unknown as Node;
 | 
					      const node: Node = {
 | 
				
			||||||
      node.parentId = classNode.parent;
 | 
					        ...classNode,
 | 
				
			||||||
      node.look = config.look;
 | 
					        type: undefined,
 | 
				
			||||||
 | 
					        isGroup: false,
 | 
				
			||||||
 | 
					        parentId: classNode.parent,
 | 
				
			||||||
 | 
					        look: classNode.look,
 | 
				
			||||||
 | 
					      };
 | 
				
			||||||
      nodes.push(node);
 | 
					      nodes.push(node);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -5,7 +5,7 @@ export interface ClassNode {
 | 
				
			|||||||
  id: string;
 | 
					  id: string;
 | 
				
			||||||
  type: string;
 | 
					  type: string;
 | 
				
			||||||
  label: string;
 | 
					  label: string;
 | 
				
			||||||
  shape: string;
 | 
					  shape: 'classBox';
 | 
				
			||||||
  text: string;
 | 
					  text: string;
 | 
				
			||||||
  cssClasses: string;
 | 
					  cssClasses: string;
 | 
				
			||||||
  methods: ClassMember[];
 | 
					  methods: ClassMember[];
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user