mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-02-04 07:13:25 +08:00
Change types
This commit is contained in:
parent
2ec9f0af2e
commit
ca93280b17
@ -5,6 +5,7 @@ export interface ClassNode {
|
|||||||
id: string;
|
id: string;
|
||||||
type: string;
|
type: string;
|
||||||
label: string;
|
label: string;
|
||||||
|
shape: string;
|
||||||
text: string;
|
text: string;
|
||||||
cssClasses: string[];
|
cssClasses: string[];
|
||||||
methods: ClassMember[];
|
methods: ClassMember[];
|
||||||
@ -17,6 +18,7 @@ export interface ClassNode {
|
|||||||
linkTarget?: string;
|
linkTarget?: string;
|
||||||
haveCallback?: boolean;
|
haveCallback?: boolean;
|
||||||
tooltip?: string;
|
tooltip?: string;
|
||||||
|
look?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type Visibility = '#' | '+' | '~' | '-' | '';
|
export type Visibility = '#' | '+' | '~' | '-' | '';
|
||||||
@ -88,7 +90,7 @@ export class ClassMember {
|
|||||||
this.visibility = detectedVisibility as Visibility;
|
this.visibility = detectedVisibility as Visibility;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.id = match[2].trim();
|
this.id = match[2];
|
||||||
this.parameters = match[3] ? match[3].trim() : '';
|
this.parameters = match[3] ? match[3].trim() : '';
|
||||||
potentialClassifier = match[4] ? match[4].trim() : '';
|
potentialClassifier = match[4] ? match[4].trim() : '';
|
||||||
this.returnType = match[5] ? match[5].trim() : '';
|
this.returnType = match[5] ? match[5].trim() : '';
|
||||||
@ -121,8 +123,9 @@ export class ClassMember {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.classifier = potentialClassifier;
|
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 : ''}` : ''}`;
|
const combinedText = `${this.visibility}${this.id}${this.memberType === 'method' ? `(${this.parameters})${this.returnType ? ' : ' + this.returnType : ''}` : ''}`;
|
||||||
|
this.text = combinedText;
|
||||||
if (combinedText.includes('~')) {
|
if (combinedText.includes('~')) {
|
||||||
const numOfTildes = (combinedText.substring(1).match(/~/g) ?? []).length;
|
const numOfTildes = (combinedText.substring(1).match(/~/g) ?? []).length;
|
||||||
let count = numOfTildes;
|
let count = numOfTildes;
|
||||||
@ -138,15 +141,16 @@ export class ClassMember {
|
|||||||
count -= 2; // Each iteration replaces one '>' with '<', so reduce count by 2
|
count -= 2; // Each iteration replaces one '>' with '<', so reduce count by 2
|
||||||
}
|
}
|
||||||
if (odd) {
|
if (odd) {
|
||||||
|
// Replace first occurrence.
|
||||||
if (this.memberType === 'method') {
|
if (this.memberType === 'method') {
|
||||||
replacedRaw = replacedRaw.replace('<', '~');
|
replacedRaw = replacedRaw.replace('<', '~');
|
||||||
} else {
|
} else {
|
||||||
// Replace the middle occurrence of '<' with '~'
|
// Replace middle occurrence.
|
||||||
const ltOccurrences = replacedRaw.match(/</g) ?? [];
|
const ltOccurrences = replacedRaw.match(/</g) ?? [];
|
||||||
if (ltOccurrences.length > 1) {
|
if (ltOccurrences.length > 1) {
|
||||||
let ltCount = 0;
|
let ltCount = 0;
|
||||||
|
|
||||||
replacedRaw = replacedRaw.replace(/</g, (match) => {
|
replacedRaw = replacedRaw.replace('<', (match) => {
|
||||||
ltCount++;
|
ltCount++;
|
||||||
return ltCount === ltOccurrences.length ? '~' : match;
|
return ltCount === ltOccurrences.length ? '~' : match;
|
||||||
});
|
});
|
||||||
@ -154,6 +158,7 @@ export class ClassMember {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.text = this.text.charAt(0) + replacedRaw;
|
this.text = this.text.charAt(0) + replacedRaw;
|
||||||
|
|
||||||
if (this.visibility === '~') {
|
if (this.visibility === '~') {
|
||||||
this.text = this.text.replace('~', '\\~');
|
this.text = this.text.replace('~', '\\~');
|
||||||
}
|
}
|
||||||
@ -161,12 +166,6 @@ export class ClassMember {
|
|||||||
this.text = this.text.replace('~', '\\~');
|
this.text = this.text.replace('~', '\\~');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.classifier === '$') {
|
|
||||||
this.text = `<u>${this.text}</u>`;
|
|
||||||
} else if (this.classifier === '*') {
|
|
||||||
this.text = `<i>${this.text}</i>`;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
parseClassifier() {
|
parseClassifier() {
|
||||||
@ -210,5 +209,11 @@ export interface NamespaceNode {
|
|||||||
children: NamespaceMap;
|
children: NamespaceMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface StyleClass {
|
||||||
|
id: string;
|
||||||
|
styles: string[];
|
||||||
|
textStyles: string[];
|
||||||
|
}
|
||||||
|
|
||||||
export type ClassMap = Map<string, ClassNode>;
|
export type ClassMap = Map<string, ClassNode>;
|
||||||
export type NamespaceMap = Map<string, NamespaceNode>;
|
export type NamespaceMap = Map<string, NamespaceNode>;
|
||||||
|
@ -87,6 +87,9 @@ export interface Edge {
|
|||||||
stroke?: string;
|
stroke?: string;
|
||||||
text?: string;
|
text?: string;
|
||||||
type: string;
|
type: string;
|
||||||
|
// Class Diagram specific properties
|
||||||
|
startLabelRight?: string;
|
||||||
|
endLabelLeft?: string;
|
||||||
// Rendering specific properties
|
// Rendering specific properties
|
||||||
curve?: string;
|
curve?: string;
|
||||||
labelpos?: string;
|
labelpos?: string;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user