|
|
|
@@ -24,65 +24,73 @@ import type {
|
|
|
|
|
Interface,
|
|
|
|
|
} from './classTypes.js';
|
|
|
|
|
import type { Node, Edge } from '../../rendering-util/types.js';
|
|
|
|
|
import type { DiagramDB } from '../../diagram-api/types.js';
|
|
|
|
|
|
|
|
|
|
const MERMAID_DOM_ID_PREFIX = 'classId-';
|
|
|
|
|
|
|
|
|
|
let relations: ClassRelation[] = [];
|
|
|
|
|
let classes = new Map<string, ClassNode>();
|
|
|
|
|
const styleClasses = new Map<string, StyleClass>();
|
|
|
|
|
let notes: ClassNote[] = [];
|
|
|
|
|
let interfaces: Interface[] = [];
|
|
|
|
|
let classCounter = 0;
|
|
|
|
|
let namespaces = new Map<string, NamespaceNode>();
|
|
|
|
|
let namespaceCounter = 0;
|
|
|
|
|
|
|
|
|
|
let functions: any[] = [];
|
|
|
|
|
export class ClassDB implements DiagramDB {
|
|
|
|
|
private relations: ClassRelation[] = [];
|
|
|
|
|
private classes = new Map<string, ClassNode>();
|
|
|
|
|
private readonly styleClasses = new Map<string, StyleClass>();
|
|
|
|
|
private notes: ClassNote[] = [];
|
|
|
|
|
private interfaces: Interface[] = [];
|
|
|
|
|
// private static classCounter = 0;
|
|
|
|
|
private namespaces = new Map<string, NamespaceNode>();
|
|
|
|
|
private namespaceCounter = 0;
|
|
|
|
|
|
|
|
|
|
const sanitizeText = (txt: string) => common.sanitizeText(txt, getConfig());
|
|
|
|
|
private functions: any[] = [];
|
|
|
|
|
|
|
|
|
|
const splitClassNameAndType = function (_id: string) {
|
|
|
|
|
private readonly sanitizeText = (txt: string) => common.sanitizeText(txt, getConfig());
|
|
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
|
this.functions.push(this.setupToolTips);
|
|
|
|
|
this.clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private readonly splitClassNameAndType = (_id: string) => {
|
|
|
|
|
const id = common.sanitizeText(_id, getConfig());
|
|
|
|
|
let genericType = '';
|
|
|
|
|
let className = id;
|
|
|
|
|
|
|
|
|
|
if (id.indexOf('~') > 0) {
|
|
|
|
|
const split = id.split('~');
|
|
|
|
|
className = sanitizeText(split[0]);
|
|
|
|
|
genericType = sanitizeText(split[1]);
|
|
|
|
|
className = this.sanitizeText(split[0]);
|
|
|
|
|
genericType = this.sanitizeText(split[1]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return { className: className, type: genericType };
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const setClassLabel = function (_id: string, label: string) {
|
|
|
|
|
public setClassLabel = (_id: string, label: string) => {
|
|
|
|
|
const id = common.sanitizeText(_id, getConfig());
|
|
|
|
|
if (label) {
|
|
|
|
|
label = sanitizeText(label);
|
|
|
|
|
label = this.sanitizeText(label);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const { className } = splitClassNameAndType(id);
|
|
|
|
|
classes.get(className)!.label = label;
|
|
|
|
|
classes.get(className)!.text =
|
|
|
|
|
`${label}${classes.get(className)!.type ? `<${classes.get(className)!.type}>` : ''}`;
|
|
|
|
|
};
|
|
|
|
|
const { className } = this.splitClassNameAndType(id);
|
|
|
|
|
this.classes.get(className)!.label = label;
|
|
|
|
|
this.classes.get(className)!.text =
|
|
|
|
|
`${label}${this.classes.get(className)!.type ? `<${this.classes.get(className)!.type}>` : ''}`;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
/**
|
|
|
|
|
* Function called by parser when a node definition has been found.
|
|
|
|
|
*
|
|
|
|
|
* @param id - Id of the class to add
|
|
|
|
|
* @public
|
|
|
|
|
*/
|
|
|
|
|
export const addClass = function (_id: string) {
|
|
|
|
|
public addClass = (_id: string) => {
|
|
|
|
|
const id = common.sanitizeText(_id, getConfig());
|
|
|
|
|
const { className, type } = splitClassNameAndType(id);
|
|
|
|
|
const { className, type } = this.splitClassNameAndType(id);
|
|
|
|
|
// Only add class if not exists
|
|
|
|
|
if (classes.has(className)) {
|
|
|
|
|
if (this.classes.has(className)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// alert('Adding class: ' + className);
|
|
|
|
|
const name = common.sanitizeText(className, getConfig());
|
|
|
|
|
// alert('Adding class after: ' + name);
|
|
|
|
|
classes.set(name, {
|
|
|
|
|
this.classes.set(name, {
|
|
|
|
|
id: name,
|
|
|
|
|
type: type,
|
|
|
|
|
label: name,
|
|
|
|
@@ -97,93 +105,93 @@ export const addClass = function (_id: string) {
|
|
|
|
|
} as ClassNode);
|
|
|
|
|
|
|
|
|
|
classCounter++;
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const addInterface = function (label: string, classId: string) {
|
|
|
|
|
private readonly addInterface = (label: string, classId: string) => {
|
|
|
|
|
const classInterface: Interface = {
|
|
|
|
|
id: `interface${interfaces.length}`,
|
|
|
|
|
id: `interface${this.interfaces.length}`,
|
|
|
|
|
label,
|
|
|
|
|
classId,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
interfaces.push(classInterface);
|
|
|
|
|
};
|
|
|
|
|
this.interfaces.push(classInterface);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
/**
|
|
|
|
|
* Function to lookup domId from id in the graph definition.
|
|
|
|
|
*
|
|
|
|
|
* @param id - class ID to lookup
|
|
|
|
|
* @public
|
|
|
|
|
*/
|
|
|
|
|
export const lookUpDomId = function (_id: string): string {
|
|
|
|
|
public lookUpDomId = (_id: string): string => {
|
|
|
|
|
const id = common.sanitizeText(_id, getConfig());
|
|
|
|
|
if (classes.has(id)) {
|
|
|
|
|
return classes.get(id)!.domId;
|
|
|
|
|
if (this.classes.has(id)) {
|
|
|
|
|
return this.classes.get(id)!.domId;
|
|
|
|
|
}
|
|
|
|
|
throw new Error('Class not found: ' + id);
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const clear = function () {
|
|
|
|
|
relations = [];
|
|
|
|
|
classes = new Map();
|
|
|
|
|
notes = [];
|
|
|
|
|
interfaces = [];
|
|
|
|
|
functions = [];
|
|
|
|
|
functions.push(setupToolTips);
|
|
|
|
|
namespaces = new Map();
|
|
|
|
|
namespaceCounter = 0;
|
|
|
|
|
direction = 'TB';
|
|
|
|
|
public clear = () => {
|
|
|
|
|
this.relations = [];
|
|
|
|
|
this.classes = new Map();
|
|
|
|
|
this.notes = [];
|
|
|
|
|
this.interfaces = [];
|
|
|
|
|
this.functions = [];
|
|
|
|
|
this.functions.push(this.setupToolTips);
|
|
|
|
|
this.namespaces = new Map();
|
|
|
|
|
this.namespaceCounter = 0;
|
|
|
|
|
this.direction = 'TB';
|
|
|
|
|
commonClear();
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const getClass = function (id: string): ClassNode {
|
|
|
|
|
return classes.get(id)!;
|
|
|
|
|
};
|
|
|
|
|
public getClass = (id: string): ClassNode => {
|
|
|
|
|
return this.classes.get(id)!;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const getClasses = function (): ClassMap {
|
|
|
|
|
return classes;
|
|
|
|
|
};
|
|
|
|
|
public getClasses = (): ClassMap => {
|
|
|
|
|
return this.classes;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const getRelations = function (): ClassRelation[] {
|
|
|
|
|
return relations;
|
|
|
|
|
};
|
|
|
|
|
public getRelations = (): ClassRelation[] => {
|
|
|
|
|
return this.relations;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const getNotes = function () {
|
|
|
|
|
return notes;
|
|
|
|
|
};
|
|
|
|
|
public getNotes = () => {
|
|
|
|
|
return this.notes;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const addRelation = function (classRelation: ClassRelation) {
|
|
|
|
|
public addRelation = (classRelation: ClassRelation) => {
|
|
|
|
|
log.debug('Adding relation: ' + JSON.stringify(classRelation));
|
|
|
|
|
// Due to relationType cannot just check if it is equal to 'none' or it complains, can fix this later
|
|
|
|
|
const invalidTypes = [
|
|
|
|
|
relationType.LOLLIPOP,
|
|
|
|
|
relationType.AGGREGATION,
|
|
|
|
|
relationType.COMPOSITION,
|
|
|
|
|
relationType.DEPENDENCY,
|
|
|
|
|
relationType.EXTENSION,
|
|
|
|
|
this.relationType.LOLLIPOP,
|
|
|
|
|
this.relationType.AGGREGATION,
|
|
|
|
|
this.relationType.COMPOSITION,
|
|
|
|
|
this.relationType.DEPENDENCY,
|
|
|
|
|
this.relationType.EXTENSION,
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
classRelation.relation.type1 === relationType.LOLLIPOP &&
|
|
|
|
|
classRelation.relation.type1 === this.relationType.LOLLIPOP &&
|
|
|
|
|
!invalidTypes.includes(classRelation.relation.type2)
|
|
|
|
|
) {
|
|
|
|
|
addClass(classRelation.id2);
|
|
|
|
|
addInterface(classRelation.id1, classRelation.id2);
|
|
|
|
|
classRelation.id1 = `interface${interfaces.length - 1}`;
|
|
|
|
|
this.addClass(classRelation.id2);
|
|
|
|
|
this.addInterface(classRelation.id1, classRelation.id2);
|
|
|
|
|
classRelation.id1 = `interface${this.interfaces.length - 1}`;
|
|
|
|
|
} else if (
|
|
|
|
|
classRelation.relation.type2 === relationType.LOLLIPOP &&
|
|
|
|
|
classRelation.relation.type2 === this.relationType.LOLLIPOP &&
|
|
|
|
|
!invalidTypes.includes(classRelation.relation.type1)
|
|
|
|
|
) {
|
|
|
|
|
addClass(classRelation.id1);
|
|
|
|
|
addInterface(classRelation.id2, classRelation.id1);
|
|
|
|
|
classRelation.id2 = `interface${interfaces.length - 1}`;
|
|
|
|
|
this.addClass(classRelation.id1);
|
|
|
|
|
this.addInterface(classRelation.id2, classRelation.id1);
|
|
|
|
|
classRelation.id2 = `interface${this.interfaces.length - 1}`;
|
|
|
|
|
} else {
|
|
|
|
|
addClass(classRelation.id1);
|
|
|
|
|
addClass(classRelation.id2);
|
|
|
|
|
this.addClass(classRelation.id1);
|
|
|
|
|
this.addClass(classRelation.id2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
classRelation.id1 = splitClassNameAndType(classRelation.id1).className;
|
|
|
|
|
classRelation.id2 = splitClassNameAndType(classRelation.id2).className;
|
|
|
|
|
classRelation.id1 = this.splitClassNameAndType(classRelation.id1).className;
|
|
|
|
|
classRelation.id2 = this.splitClassNameAndType(classRelation.id2).className;
|
|
|
|
|
|
|
|
|
|
classRelation.relationTitle1 = common.sanitizeText(
|
|
|
|
|
classRelation.relationTitle1.trim(),
|
|
|
|
@@ -195,10 +203,10 @@ export const addRelation = function (classRelation: ClassRelation) {
|
|
|
|
|
getConfig()
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
relations.push(classRelation);
|
|
|
|
|
};
|
|
|
|
|
this.relations.push(classRelation);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
/**
|
|
|
|
|
* Adds an annotation to the specified class Annotations mark special properties of the given type
|
|
|
|
|
* (like 'interface' or 'service')
|
|
|
|
|
*
|
|
|
|
@@ -206,12 +214,12 @@ export const addRelation = function (classRelation: ClassRelation) {
|
|
|
|
|
* @param annotation - The name of the annotation without any brackets
|
|
|
|
|
* @public
|
|
|
|
|
*/
|
|
|
|
|
export const addAnnotation = function (className: string, annotation: string) {
|
|
|
|
|
const validatedClassName = splitClassNameAndType(className).className;
|
|
|
|
|
classes.get(validatedClassName)!.annotations.push(annotation);
|
|
|
|
|
};
|
|
|
|
|
public addAnnotation = (className: string, annotation: string) => {
|
|
|
|
|
const validatedClassName = this.splitClassNameAndType(className).className;
|
|
|
|
|
this.classes.get(validatedClassName)!.annotations.push(annotation);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
/**
|
|
|
|
|
* Adds a member to the specified class
|
|
|
|
|
*
|
|
|
|
|
* @param className - The class name
|
|
|
|
@@ -220,11 +228,11 @@ export const addAnnotation = function (className: string, annotation: string) {
|
|
|
|
|
* method Otherwise the member will be treated as a normal property
|
|
|
|
|
* @public
|
|
|
|
|
*/
|
|
|
|
|
export const addMember = function (className: string, member: string) {
|
|
|
|
|
addClass(className);
|
|
|
|
|
public addMember = (className: string, member: string) => {
|
|
|
|
|
this.addClass(className);
|
|
|
|
|
|
|
|
|
|
const validatedClassName = splitClassNameAndType(className).className;
|
|
|
|
|
const theClass = classes.get(validatedClassName)!;
|
|
|
|
|
const validatedClassName = this.splitClassNameAndType(className).className;
|
|
|
|
|
const theClass = this.classes.get(validatedClassName)!;
|
|
|
|
|
|
|
|
|
|
if (typeof member === 'string') {
|
|
|
|
|
// Member can contain white spaces, we trim them out
|
|
|
|
@@ -232,7 +240,9 @@ export const addMember = function (className: string, member: string) {
|
|
|
|
|
|
|
|
|
|
if (memberString.startsWith('<<') && memberString.endsWith('>>')) {
|
|
|
|
|
// its an annotation
|
|
|
|
|
theClass.annotations.push(sanitizeText(memberString.substring(2, memberString.length - 2)));
|
|
|
|
|
theClass.annotations.push(
|
|
|
|
|
this.sanitizeText(memberString.substring(2, memberString.length - 2))
|
|
|
|
|
);
|
|
|
|
|
} else if (memberString.indexOf(')') > 0) {
|
|
|
|
|
//its a method
|
|
|
|
|
theClass.methods.push(new ClassMember(memberString, 'method'));
|
|
|
|
@@ -240,60 +250,60 @@ export const addMember = function (className: string, member: string) {
|
|
|
|
|
theClass.members.push(new ClassMember(memberString, 'attribute'));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const addMembers = function (className: string, members: string[]) {
|
|
|
|
|
public addMembers = (className: string, members: string[]) => {
|
|
|
|
|
if (Array.isArray(members)) {
|
|
|
|
|
members.reverse();
|
|
|
|
|
members.forEach((member) => addMember(className, member));
|
|
|
|
|
members.forEach((member) => this.addMember(className, member));
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const addNote = function (text: string, className: string) {
|
|
|
|
|
public addNote = (text: string, className: string) => {
|
|
|
|
|
const note = {
|
|
|
|
|
id: `note${notes.length}`,
|
|
|
|
|
id: `note${this.notes.length}`,
|
|
|
|
|
class: className,
|
|
|
|
|
text: text,
|
|
|
|
|
};
|
|
|
|
|
notes.push(note);
|
|
|
|
|
};
|
|
|
|
|
this.notes.push(note);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const cleanupLabel = function (label: string) {
|
|
|
|
|
public cleanupLabel = (label: string) => {
|
|
|
|
|
if (label.startsWith(':')) {
|
|
|
|
|
label = label.substring(1);
|
|
|
|
|
}
|
|
|
|
|
return sanitizeText(label.trim());
|
|
|
|
|
};
|
|
|
|
|
return this.sanitizeText(label.trim());
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
/**
|
|
|
|
|
* Called by parser when assigning cssClass to a class
|
|
|
|
|
*
|
|
|
|
|
* @param ids - Comma separated list of ids
|
|
|
|
|
* @param className - Class to add
|
|
|
|
|
*/
|
|
|
|
|
export const setCssClass = function (ids: string, className: string) {
|
|
|
|
|
ids.split(',').forEach(function (_id) {
|
|
|
|
|
public setCssClass = (ids: string, className: string) => {
|
|
|
|
|
ids.split(',').forEach((_id) => {
|
|
|
|
|
let id = _id;
|
|
|
|
|
if (/\d/.exec(_id[0])) {
|
|
|
|
|
id = MERMAID_DOM_ID_PREFIX + id;
|
|
|
|
|
}
|
|
|
|
|
const classNode = classes.get(id);
|
|
|
|
|
const classNode = this.classes.get(id);
|
|
|
|
|
if (classNode) {
|
|
|
|
|
classNode.cssClasses += ' ' + className;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const defineClass = function (ids: string[], style: string[]) {
|
|
|
|
|
public defineClass = (ids: string[], style: string[]) => {
|
|
|
|
|
for (const id of ids) {
|
|
|
|
|
let styleClass = styleClasses.get(id);
|
|
|
|
|
let styleClass = this.styleClasses.get(id);
|
|
|
|
|
if (styleClass === undefined) {
|
|
|
|
|
styleClass = { id, styles: [], textStyles: [] };
|
|
|
|
|
styleClasses.set(id, styleClass);
|
|
|
|
|
this.styleClasses.set(id, styleClass);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (style) {
|
|
|
|
|
style.forEach(function (s) {
|
|
|
|
|
style.forEach((s) => {
|
|
|
|
|
if (/color/.exec(s)) {
|
|
|
|
|
const newStyle = s.replace('fill', 'bgFill'); // .replace('color', 'fill');
|
|
|
|
|
styleClass.textStyles.push(newStyle);
|
|
|
|
@@ -302,81 +312,81 @@ export const defineClass = function (ids: string[], style: string[]) {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
classes.forEach((value) => {
|
|
|
|
|
this.classes.forEach((value) => {
|
|
|
|
|
if (value.cssClasses.includes(id)) {
|
|
|
|
|
value.styles.push(...style.flatMap((s) => s.split(',')));
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
/**
|
|
|
|
|
* Called by parser when a tooltip is found, e.g. a clickable element.
|
|
|
|
|
*
|
|
|
|
|
* @param ids - Comma separated list of ids
|
|
|
|
|
* @param tooltip - Tooltip to add
|
|
|
|
|
*/
|
|
|
|
|
const setTooltip = function (ids: string, tooltip?: string) {
|
|
|
|
|
ids.split(',').forEach(function (id) {
|
|
|
|
|
public setTooltip = (ids: string, tooltip?: string) => {
|
|
|
|
|
ids.split(',').forEach((id) => {
|
|
|
|
|
if (tooltip !== undefined) {
|
|
|
|
|
classes.get(id)!.tooltip = sanitizeText(tooltip);
|
|
|
|
|
this.classes.get(id)!.tooltip = this.sanitizeText(tooltip);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const getTooltip = function (id: string, namespace?: string) {
|
|
|
|
|
if (namespace && namespaces.has(namespace)) {
|
|
|
|
|
return namespaces.get(namespace)!.classes.get(id)!.tooltip;
|
|
|
|
|
public getTooltip = (id: string, namespace?: string) => {
|
|
|
|
|
if (namespace && this.namespaces.has(namespace)) {
|
|
|
|
|
return this.namespaces.get(namespace)!.classes.get(id)!.tooltip;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return classes.get(id)!.tooltip;
|
|
|
|
|
};
|
|
|
|
|
return this.classes.get(id)!.tooltip;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
/**
|
|
|
|
|
* Called by parser when a link is found. Adds the URL to the vertex data.
|
|
|
|
|
*
|
|
|
|
|
* @param ids - Comma separated list of ids
|
|
|
|
|
* @param linkStr - URL to create a link for
|
|
|
|
|
* @param target - Target of the link, _blank by default as originally defined in the svgDraw.js file
|
|
|
|
|
*/
|
|
|
|
|
export const setLink = function (ids: string, linkStr: string, target: string) {
|
|
|
|
|
public setLink = (ids: string, linkStr: string, target: string) => {
|
|
|
|
|
const config = getConfig();
|
|
|
|
|
ids.split(',').forEach(function (_id) {
|
|
|
|
|
ids.split(',').forEach((_id) => {
|
|
|
|
|
let id = _id;
|
|
|
|
|
if (/\d/.exec(_id[0])) {
|
|
|
|
|
id = MERMAID_DOM_ID_PREFIX + id;
|
|
|
|
|
}
|
|
|
|
|
const theClass = classes.get(id);
|
|
|
|
|
const theClass = this.classes.get(id);
|
|
|
|
|
if (theClass) {
|
|
|
|
|
theClass.link = utils.formatUrl(linkStr, config);
|
|
|
|
|
if (config.securityLevel === 'sandbox') {
|
|
|
|
|
theClass.linkTarget = '_top';
|
|
|
|
|
} else if (typeof target === 'string') {
|
|
|
|
|
theClass.linkTarget = sanitizeText(target);
|
|
|
|
|
theClass.linkTarget = this.sanitizeText(target);
|
|
|
|
|
} else {
|
|
|
|
|
theClass.linkTarget = '_blank';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
setCssClass(ids, 'clickable');
|
|
|
|
|
};
|
|
|
|
|
this.setCssClass(ids, 'clickable');
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
/**
|
|
|
|
|
* Called by parser when a click definition is found. Registers an event handler.
|
|
|
|
|
*
|
|
|
|
|
* @param ids - Comma separated list of ids
|
|
|
|
|
* @param functionName - Function to be called on click
|
|
|
|
|
* @param functionArgs - Function args the function should be called with
|
|
|
|
|
*/
|
|
|
|
|
export const setClickEvent = function (ids: string, functionName: string, functionArgs: string) {
|
|
|
|
|
ids.split(',').forEach(function (id) {
|
|
|
|
|
setClickFunc(id, functionName, functionArgs);
|
|
|
|
|
classes.get(id)!.haveCallback = true;
|
|
|
|
|
public setClickEvent = (ids: string, functionName: string, functionArgs: string) => {
|
|
|
|
|
ids.split(',').forEach((id) => {
|
|
|
|
|
this.setClickFunc(id, functionName, functionArgs);
|
|
|
|
|
this.classes.get(id)!.haveCallback = true;
|
|
|
|
|
});
|
|
|
|
|
setCssClass(ids, 'clickable');
|
|
|
|
|
};
|
|
|
|
|
this.setCssClass(ids, 'clickable');
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const setClickFunc = function (_domId: string, functionName: string, functionArgs: string) {
|
|
|
|
|
private readonly setClickFunc = (_domId: string, functionName: string, functionArgs: string) => {
|
|
|
|
|
const domId = common.sanitizeText(_domId, getConfig());
|
|
|
|
|
const config = getConfig();
|
|
|
|
|
if (config.securityLevel !== 'loose') {
|
|
|
|
@@ -387,8 +397,8 @@ const setClickFunc = function (_domId: string, functionName: string, functionArg
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const id = domId;
|
|
|
|
|
if (classes.has(id)) {
|
|
|
|
|
const elemId = lookUpDomId(id);
|
|
|
|
|
if (this.classes.has(id)) {
|
|
|
|
|
const elemId = this.lookUpDomId(id);
|
|
|
|
|
let argList: string[] = [];
|
|
|
|
|
if (typeof functionArgs === 'string') {
|
|
|
|
|
/* Splits functionArgs by ',', ignoring all ',' in double quoted strings */
|
|
|
|
@@ -409,12 +419,12 @@ const setClickFunc = function (_domId: string, functionName: string, functionArg
|
|
|
|
|
argList.push(elemId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
functions.push(function () {
|
|
|
|
|
this.functions.push(() => {
|
|
|
|
|
const elem = document.querySelector(`[id="${elemId}"]`);
|
|
|
|
|
if (elem !== null) {
|
|
|
|
|
elem.addEventListener(
|
|
|
|
|
'click',
|
|
|
|
|
function () {
|
|
|
|
|
() => {
|
|
|
|
|
utils.runFunc(functionName, ...argList);
|
|
|
|
|
},
|
|
|
|
|
false
|
|
|
|
@@ -422,41 +432,44 @@ const setClickFunc = function (_domId: string, functionName: string, functionArg
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const bindFunctions = function (element: Element) {
|
|
|
|
|
functions.forEach(function (fun) {
|
|
|
|
|
public bindFunctions = (element: Element) => {
|
|
|
|
|
this.functions.forEach((fun) => {
|
|
|
|
|
fun(element);
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const lineType = {
|
|
|
|
|
public lineType = {
|
|
|
|
|
LINE: 0,
|
|
|
|
|
DOTTED_LINE: 1,
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const relationType = {
|
|
|
|
|
public relationType = {
|
|
|
|
|
AGGREGATION: 0,
|
|
|
|
|
EXTENSION: 1,
|
|
|
|
|
COMPOSITION: 2,
|
|
|
|
|
DEPENDENCY: 3,
|
|
|
|
|
LOLLIPOP: 4,
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const setupToolTips = function (element: Element) {
|
|
|
|
|
private readonly setupToolTips = (element: Element) => {
|
|
|
|
|
let tooltipElem: Selection<HTMLDivElement, unknown, HTMLElement, unknown> =
|
|
|
|
|
select('.mermaidTooltip');
|
|
|
|
|
// @ts-expect-error - Incorrect types
|
|
|
|
|
if ((tooltipElem._groups || tooltipElem)[0][0] === null) {
|
|
|
|
|
tooltipElem = select('body').append('div').attr('class', 'mermaidTooltip').style('opacity', 0);
|
|
|
|
|
tooltipElem = select('body')
|
|
|
|
|
.append('div')
|
|
|
|
|
.attr('class', 'mermaidTooltip')
|
|
|
|
|
.style('opacity', 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const svg = select(element).select('svg');
|
|
|
|
|
|
|
|
|
|
const nodes = svg.selectAll('g.node');
|
|
|
|
|
nodes
|
|
|
|
|
.on('mouseover', function () {
|
|
|
|
|
const el = select(this);
|
|
|
|
|
.on('mouseover', (event: MouseEvent) => {
|
|
|
|
|
const el = select(event.currentTarget as HTMLElement);
|
|
|
|
|
const title = el.attr('title');
|
|
|
|
|
// Don't try to draw a tooltip if no data is provided
|
|
|
|
|
if (title === null) {
|
|
|
|
@@ -473,69 +486,68 @@ const setupToolTips = function (element: Element) {
|
|
|
|
|
tooltipElem.html(tooltipElem.html().replace(/<br\/>/g, '<br/>'));
|
|
|
|
|
el.classed('hover', true);
|
|
|
|
|
})
|
|
|
|
|
.on('mouseout', function () {
|
|
|
|
|
.on('mouseout', (event: MouseEvent) => {
|
|
|
|
|
tooltipElem.transition().duration(500).style('opacity', 0);
|
|
|
|
|
const el = select(this);
|
|
|
|
|
const el = select(event.currentTarget as HTMLElement);
|
|
|
|
|
el.classed('hover', false);
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
functions.push(setupToolTips);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let direction = 'TB';
|
|
|
|
|
const getDirection = () => direction;
|
|
|
|
|
const setDirection = (dir: string) => {
|
|
|
|
|
direction = dir;
|
|
|
|
|
};
|
|
|
|
|
private direction = 'TB';
|
|
|
|
|
public getDirection = () => this.direction;
|
|
|
|
|
public setDirection = (dir: string) => {
|
|
|
|
|
this.direction = dir;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
/**
|
|
|
|
|
* Function called by parser when a namespace definition has been found.
|
|
|
|
|
*
|
|
|
|
|
* @param id - Id of the namespace to add
|
|
|
|
|
* @public
|
|
|
|
|
*/
|
|
|
|
|
export const addNamespace = function (id: string) {
|
|
|
|
|
if (namespaces.has(id)) {
|
|
|
|
|
public addNamespace = (id: string) => {
|
|
|
|
|
if (this.namespaces.has(id)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
namespaces.set(id, {
|
|
|
|
|
this.namespaces.set(id, {
|
|
|
|
|
id: id,
|
|
|
|
|
classes: new Map(),
|
|
|
|
|
children: {},
|
|
|
|
|
domId: MERMAID_DOM_ID_PREFIX + id + '-' + namespaceCounter,
|
|
|
|
|
domId: MERMAID_DOM_ID_PREFIX + id + '-' + this.namespaceCounter,
|
|
|
|
|
} as NamespaceNode);
|
|
|
|
|
|
|
|
|
|
namespaceCounter++;
|
|
|
|
|
};
|
|
|
|
|
this.namespaceCounter++;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const getNamespace = function (name: string): NamespaceNode {
|
|
|
|
|
return namespaces.get(name)!;
|
|
|
|
|
};
|
|
|
|
|
public getNamespace = (name: string): NamespaceNode => {
|
|
|
|
|
return this.namespaces.get(name)!;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const getNamespaces = function (): NamespaceMap {
|
|
|
|
|
return namespaces;
|
|
|
|
|
};
|
|
|
|
|
public getNamespaces = (): NamespaceMap => {
|
|
|
|
|
return this.namespaces;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
/**
|
|
|
|
|
* Function called by parser when a namespace definition has been found.
|
|
|
|
|
*
|
|
|
|
|
* @param id - Id of the namespace to add
|
|
|
|
|
* @param classNames - Ids of the class to add
|
|
|
|
|
* @public
|
|
|
|
|
*/
|
|
|
|
|
export const addClassesToNamespace = function (id: string, classNames: string[]) {
|
|
|
|
|
if (!namespaces.has(id)) {
|
|
|
|
|
public addClassesToNamespace = (id: string, classNames: string[]) => {
|
|
|
|
|
if (!this.namespaces.has(id)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
for (const name of classNames) {
|
|
|
|
|
const { className } = splitClassNameAndType(name);
|
|
|
|
|
classes.get(className)!.parent = id;
|
|
|
|
|
namespaces.get(id)!.classes.set(className, classes.get(className)!);
|
|
|
|
|
const { className } = this.splitClassNameAndType(name);
|
|
|
|
|
this.classes.get(className)!.parent = id;
|
|
|
|
|
this.namespaces.get(id)!.classes.set(className, this.classes.get(className)!);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const setCssStyle = function (id: string, styles: string[]) {
|
|
|
|
|
const thisClass = classes.get(id);
|
|
|
|
|
public setCssStyle = (id: string, styles: string[]) => {
|
|
|
|
|
const thisClass = this.classes.get(id);
|
|
|
|
|
if (!styles || !thisClass) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
@@ -546,15 +558,15 @@ export const setCssStyle = function (id: string, styles: string[]) {
|
|
|
|
|
thisClass.styles.push(s);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
/**
|
|
|
|
|
* Gets the arrow marker for a type index
|
|
|
|
|
*
|
|
|
|
|
* @param type - The type to look for
|
|
|
|
|
* @returns The arrow marker
|
|
|
|
|
*/
|
|
|
|
|
function getArrowMarker(type: number) {
|
|
|
|
|
private readonly getArrowMarker = (type: number) => {
|
|
|
|
|
let marker;
|
|
|
|
|
switch (type) {
|
|
|
|
|
case 0:
|
|
|
|
@@ -576,15 +588,15 @@ function getArrowMarker(type: number) {
|
|
|
|
|
marker = 'none';
|
|
|
|
|
}
|
|
|
|
|
return marker;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const getData = () => {
|
|
|
|
|
public getData = () => {
|
|
|
|
|
const nodes: Node[] = [];
|
|
|
|
|
const edges: Edge[] = [];
|
|
|
|
|
const config = getConfig();
|
|
|
|
|
|
|
|
|
|
for (const namespaceKey of namespaces.keys()) {
|
|
|
|
|
const namespace = namespaces.get(namespaceKey);
|
|
|
|
|
for (const namespaceKey of this.namespaces.keys()) {
|
|
|
|
|
const namespace = this.namespaces.get(namespaceKey);
|
|
|
|
|
if (namespace) {
|
|
|
|
|
const node: Node = {
|
|
|
|
|
id: namespace.id,
|
|
|
|
@@ -600,8 +612,8 @@ export const getData = () => {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (const classKey of classes.keys()) {
|
|
|
|
|
const classNode = classes.get(classKey);
|
|
|
|
|
for (const classKey of this.classes.keys()) {
|
|
|
|
|
const classNode = this.classes.get(classKey);
|
|
|
|
|
if (classNode) {
|
|
|
|
|
const node = classNode as unknown as Node;
|
|
|
|
|
node.parentId = classNode.parent;
|
|
|
|
@@ -611,7 +623,7 @@ export const getData = () => {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let cnt = 0;
|
|
|
|
|
for (const note of notes) {
|
|
|
|
|
for (const note of this.notes) {
|
|
|
|
|
cnt++;
|
|
|
|
|
const noteNode: Node = {
|
|
|
|
|
id: note.id,
|
|
|
|
@@ -629,7 +641,7 @@ export const getData = () => {
|
|
|
|
|
};
|
|
|
|
|
nodes.push(noteNode);
|
|
|
|
|
|
|
|
|
|
const noteClassId = classes.get(note.class)?.id ?? '';
|
|
|
|
|
const noteClassId = this.classes.get(note.class)?.id ?? '';
|
|
|
|
|
|
|
|
|
|
if (noteClassId) {
|
|
|
|
|
const edge: Edge = {
|
|
|
|
@@ -651,7 +663,7 @@ export const getData = () => {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (const _interface of interfaces) {
|
|
|
|
|
for (const _interface of this.interfaces) {
|
|
|
|
|
const interfaceNode: Node = {
|
|
|
|
|
id: _interface.id,
|
|
|
|
|
label: _interface.label,
|
|
|
|
@@ -664,7 +676,7 @@ export const getData = () => {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cnt = 0;
|
|
|
|
|
for (const classRelation of relations) {
|
|
|
|
|
for (const classRelation of this.relations) {
|
|
|
|
|
cnt++;
|
|
|
|
|
const edge: Edge = {
|
|
|
|
|
id: getEdgeId(classRelation.id1, classRelation.id2, {
|
|
|
|
@@ -678,9 +690,10 @@ export const getData = () => {
|
|
|
|
|
labelpos: 'c',
|
|
|
|
|
thickness: 'normal',
|
|
|
|
|
classes: 'relation',
|
|
|
|
|
arrowTypeStart: getArrowMarker(classRelation.relation.type1),
|
|
|
|
|
arrowTypeEnd: getArrowMarker(classRelation.relation.type2),
|
|
|
|
|
startLabelRight: classRelation.relationTitle1 === 'none' ? '' : classRelation.relationTitle1,
|
|
|
|
|
arrowTypeStart: this.getArrowMarker(classRelation.relation.type1),
|
|
|
|
|
arrowTypeEnd: this.getArrowMarker(classRelation.relation.type2),
|
|
|
|
|
startLabelRight:
|
|
|
|
|
classRelation.relationTitle1 === 'none' ? '' : classRelation.relationTitle1,
|
|
|
|
|
endLabelLeft: classRelation.relationTitle2 === 'none' ? '' : classRelation.relationTitle2,
|
|
|
|
|
arrowheadStyle: '',
|
|
|
|
|
labelStyle: ['display: inline-block'],
|
|
|
|
@@ -691,46 +704,14 @@ export const getData = () => {
|
|
|
|
|
edges.push(edge);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return { nodes, edges, other: {}, config, direction: getDirection() };
|
|
|
|
|
};
|
|
|
|
|
return { nodes, edges, other: {}, config, direction: this.getDirection() };
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
setAccTitle,
|
|
|
|
|
getAccTitle,
|
|
|
|
|
getAccDescription,
|
|
|
|
|
setAccDescription,
|
|
|
|
|
getConfig: () => getConfig().class,
|
|
|
|
|
addClass,
|
|
|
|
|
bindFunctions,
|
|
|
|
|
clear,
|
|
|
|
|
getClass,
|
|
|
|
|
getClasses,
|
|
|
|
|
getNotes,
|
|
|
|
|
addAnnotation,
|
|
|
|
|
addNote,
|
|
|
|
|
getRelations,
|
|
|
|
|
addRelation,
|
|
|
|
|
getDirection,
|
|
|
|
|
setDirection,
|
|
|
|
|
addMember,
|
|
|
|
|
addMembers,
|
|
|
|
|
cleanupLabel,
|
|
|
|
|
lineType,
|
|
|
|
|
relationType,
|
|
|
|
|
setClickEvent,
|
|
|
|
|
setCssClass,
|
|
|
|
|
defineClass,
|
|
|
|
|
setLink,
|
|
|
|
|
getTooltip,
|
|
|
|
|
setTooltip,
|
|
|
|
|
lookUpDomId,
|
|
|
|
|
setDiagramTitle,
|
|
|
|
|
getDiagramTitle,
|
|
|
|
|
setClassLabel,
|
|
|
|
|
addNamespace,
|
|
|
|
|
addClassesToNamespace,
|
|
|
|
|
getNamespace,
|
|
|
|
|
getNamespaces,
|
|
|
|
|
setCssStyle,
|
|
|
|
|
getData,
|
|
|
|
|
};
|
|
|
|
|
public setAccTitle = setAccTitle;
|
|
|
|
|
public getAccTitle = getAccTitle;
|
|
|
|
|
public setAccDescription = setAccDescription;
|
|
|
|
|
public getAccDescription = getAccDescription;
|
|
|
|
|
public setDiagramTitle = setDiagramTitle;
|
|
|
|
|
public getDiagramTitle = getDiagramTitle;
|
|
|
|
|
public getConfig = () => getConfig().class;
|
|
|
|
|
}
|
|
|
|
|