From ca93280b177bdbecd50f09dc59343a5f00c61e14 Mon Sep 17 00:00:00 2001 From: yari-dewalt Date: Fri, 13 Sep 2024 12:54:40 -0700 Subject: [PATCH] Change types --- .../mermaid/src/diagrams/class/classTypes.ts | 25 +++++++++++-------- packages/mermaid/src/rendering-util/types.ts | 3 +++ 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/packages/mermaid/src/diagrams/class/classTypes.ts b/packages/mermaid/src/diagrams/class/classTypes.ts index adeae2aeb..b28e7c9e5 100644 --- a/packages/mermaid/src/diagrams/class/classTypes.ts +++ b/packages/mermaid/src/diagrams/class/classTypes.ts @@ -5,6 +5,7 @@ export interface ClassNode { id: string; type: string; label: string; + shape: string; text: string; cssClasses: string[]; methods: ClassMember[]; @@ -17,6 +18,7 @@ export interface ClassNode { linkTarget?: string; haveCallback?: boolean; tooltip?: string; + look?: string; } export type Visibility = '#' | '+' | '~' | '-' | ''; @@ -88,7 +90,7 @@ export class ClassMember { this.visibility = detectedVisibility as Visibility; } - this.id = match[2].trim(); + this.id = match[2]; this.parameters = match[3] ? match[3].trim() : ''; potentialClassifier = match[4] ? match[4].trim() : ''; this.returnType = match[5] ? match[5].trim() : ''; @@ -121,8 +123,9 @@ export class ClassMember { } this.classifier = potentialClassifier; - this.text = `${this.visibility}${this.id}${this.memberType === 'method' ? `(${this.parameters})${this.returnType ? ' : ' + this.returnType : ''}` : ''}`; + // TODO: Right now getting rid of spacing in id / name, TODO: Add optional spacing const combinedText = `${this.visibility}${this.id}${this.memberType === 'method' ? `(${this.parameters})${this.returnType ? ' : ' + this.returnType : ''}` : ''}`; + this.text = combinedText; if (combinedText.includes('~')) { const numOfTildes = (combinedText.substring(1).match(/~/g) ?? []).length; let count = numOfTildes; @@ -138,15 +141,16 @@ export class ClassMember { count -= 2; // Each iteration replaces one '>' with '<', so reduce count by 2 } if (odd) { + // Replace first occurrence. if (this.memberType === 'method') { replacedRaw = replacedRaw.replace('<', '~'); } else { - // Replace the middle occurrence of '<' with '~' + // Replace middle occurrence. const ltOccurrences = replacedRaw.match(/</g) ?? []; if (ltOccurrences.length > 1) { let ltCount = 0; - replacedRaw = replacedRaw.replace(/</g, (match) => { + replacedRaw = replacedRaw.replace('<', (match) => { ltCount++; return ltCount === ltOccurrences.length ? '~' : match; }); @@ -154,6 +158,7 @@ export class ClassMember { } } this.text = this.text.charAt(0) + replacedRaw; + if (this.visibility === '~') { this.text = this.text.replace('~', '\\~'); } @@ -161,12 +166,6 @@ export class ClassMember { this.text = this.text.replace('~', '\\~'); } } - - if (this.classifier === '$') { - this.text = `${this.text}`; - } else if (this.classifier === '*') { - this.text = `${this.text}`; - } } parseClassifier() { @@ -210,5 +209,11 @@ export interface NamespaceNode { children: NamespaceMap; } +export interface StyleClass { + id: string; + styles: string[]; + textStyles: string[]; +} + export type ClassMap = Map; export type NamespaceMap = Map; diff --git a/packages/mermaid/src/rendering-util/types.ts b/packages/mermaid/src/rendering-util/types.ts index 8280f9676..b775a22a4 100644 --- a/packages/mermaid/src/rendering-util/types.ts +++ b/packages/mermaid/src/rendering-util/types.ts @@ -87,6 +87,9 @@ export interface Edge { stroke?: string; text?: string; type: string; + // Class Diagram specific properties + startLabelRight?: string; + endLabelLeft?: string; // Rendering specific properties curve?: string; labelpos?: string;