This commit is contained in:
Sidharth Vinod
2023-02-14 10:56:16 +05:30
parent e1710fddd9
commit 10e6c92766
6 changed files with 75 additions and 82 deletions

View File

@@ -19,7 +19,7 @@
"brkt", "brkt",
"brolin", "brolin",
"brotli", "brotli",
"Città", "città",
"classdef", "classdef",
"codedoc", "codedoc",
"colour", "colour",
@@ -110,11 +110,7 @@
"yash" "yash"
], ],
"patterns": [ "patterns": [
{ { "name": "Markdown links", "pattern": "\\((.*)\\)", "description": "" },
"name": "Markdown links",
"pattern": "\\((.*)\\)",
"description": ""
},
{ {
"name": "Markdown code blocks", "name": "Markdown code blocks",
"pattern": "/^(\\s*`{3,}).*[\\s\\S]*?^\\1/gmx", "pattern": "/^(\\s*`{3,}).*[\\s\\S]*?^\\1/gmx",
@@ -125,25 +121,14 @@
"pattern": "\\`([^\\`\\r\\n]+?)\\`", "pattern": "\\`([^\\`\\r\\n]+?)\\`",
"description": "https://stackoverflow.com/questions/41274241/how-to-capture-inline-markdown-code-but-not-a-markdown-code-fence-with-regex" "description": "https://stackoverflow.com/questions/41274241/how-to-capture-inline-markdown-code-but-not-a-markdown-code-fence-with-regex"
}, },
{ { "name": "Link contents", "pattern": "\\<a(.*)\\>", "description": "" },
"name": "Link contents", { "name": "Snippet references", "pattern": "-- snippet:(.*)", "description": "" },
"pattern": "\\<a(.*)\\>",
"description": ""
},
{
"name": "Snippet references",
"pattern": "-- snippet:(.*)",
"description": ""
},
{ {
"name": "Snippet references 2", "name": "Snippet references 2",
"pattern": "\\<\\[sample:(.*)", "pattern": "\\<\\[sample:(.*)",
"description": "another kind of snippet reference" "description": "another kind of snippet reference"
}, },
{ { "name": "Multi-line code blocks", "pattern": "/^\\s*```[\\s\\S]*?^\\s*```/gm" },
"name": "Multi-line code blocks",
"pattern": "/^\\s*```[\\s\\S]*?^\\s*```/gm"
},
{ {
"name": "HTML Tags", "name": "HTML Tags",
"pattern": "<[^>]*>", "pattern": "<[^>]*>",

View File

@@ -395,4 +395,4 @@ export interface FontConfig {
export type FontCalculator = () => Partial<FontConfig>; export type FontCalculator = () => Partial<FontConfig>;
export { }; export {};

View File

@@ -342,7 +342,8 @@ export const relationType = {
}; };
const setupToolTips = function (element: Element) { const setupToolTips = function (element: Element) {
let tooltipElem: Selection<HTMLDivElement, unknown, HTMLElement, unknown> = select('.mermaidTooltip'); let tooltipElem: Selection<HTMLDivElement, unknown, HTMLElement, unknown> =
select('.mermaidTooltip');
// @ts-ignore - _groups is a dynamic property // @ts-ignore - _groups is a dynamic property
if ((tooltipElem._groups || tooltipElem)[0][0] === null) { 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);

View File

@@ -1024,7 +1024,6 @@ C1 --> C2
expect(c1.label).toBe('Class 1 with text label'); expect(c1.label).toBe('Class 1 with text label');
expect(c1.cssClasses.length).toBe(1); expect(c1.cssClasses.length).toBe(1);
expect(c1.cssClasses[0]).toBe('styleClass'); expect(c1.cssClasses[0]).toBe('styleClass');
}); });
it('should parse a class with text label and css class', () => { it('should parse a class with text label and css class', () => {
@@ -1040,7 +1039,6 @@ cssClass "C1" styleClass
expect(c1.label).toBe('Class 1 with text label'); expect(c1.label).toBe('Class 1 with text label');
expect(c1.cssClasses.length).toBe(1); expect(c1.cssClasses.length).toBe(1);
expect(c1.cssClasses[0]).toBe('styleClass'); expect(c1.cssClasses[0]).toBe('styleClass');
}); });
it('should parse two classes with text labels and css classes', () => { it('should parse two classes with text labels and css classes', () => {
@@ -1130,7 +1128,7 @@ class C13["With Città foreign language"]
expect(classDb.getClass('C9').label).toBe('With - dash'); expect(classDb.getClass('C9').label).toBe('With - dash');
expect(classDb.getClass('C10').label).toBe('With _ underscore'); expect(classDb.getClass('C10').label).toBe('With _ underscore');
expect(classDb.getClass('C11').label).toBe("With ' single quote"); expect(classDb.getClass('C11').label).toBe("With ' single quote");
expect(classDb.getClass('C12').label).toBe("With ~!@#$%^&*()_+=-/?"); expect(classDb.getClass('C12').label).toBe('With ~!@#$%^&*()_+=-/?');
expect(classDb.getClass('C13').label).toBe('With Città foreign language'); expect(classDb.getClass('C13').label).toBe('With Città foreign language');
}); });
}); });

View File

@@ -16,7 +16,7 @@ let conf = {
dividerMargin: 10, dividerMargin: 10,
padding: 5, padding: 5,
textHeight: 10, textHeight: 10,
curve: undefined curve: undefined,
}; };
/** /**
@@ -27,7 +27,12 @@ let conf = {
* @param _id - id of the graph * @param _id - id of the graph
* @param diagObj - The diagram object * @param diagObj - The diagram object
*/ */
export const addClasses = function (classes: ClassMap, g: graphlib.Graph, _id: string, diagObj: any) { export const addClasses = function (
classes: ClassMap,
g: graphlib.Graph,
_id: string,
diagObj: any
) {
const keys = Object.keys(classes); const keys = Object.keys(classes);
log.info('keys:', keys); log.info('keys:', keys);
log.info(classes); log.info(classes);
@@ -83,7 +88,12 @@ export const addClasses = function (classes: ClassMap, g: graphlib.Graph, _id: s
* @param startEdgeId - starting index for note edge * @param startEdgeId - starting index for note edge
* @param classes - Classes * @param classes - Classes
*/ */
export const addNotes = function (notes: ClassNote[], g: graphlib.Graph, startEdgeId: number, classes: ClassMap) { export const addNotes = function (
notes: ClassNote[],
g: graphlib.Graph,
startEdgeId: number,
classes: ClassMap
) {
log.info(notes); log.info(notes);
// Iterate through each item in the vertex object (containing all the vertices found) in the graph definition // Iterate through each item in the vertex object (containing all the vertices found) in the graph definition
@@ -178,19 +188,17 @@ export const addRelations = function (relations: ClassRelation[], g: graphlib.Gr
arrowTypeEnd: getArrowMarker(edge.relation.type2), arrowTypeEnd: getArrowMarker(edge.relation.type2),
style: 'fill:none', style: 'fill:none',
labelStyle: '', labelStyle: '',
curve: interpolateToCurve(conf?.curve, curveLinear) curve: interpolateToCurve(conf?.curve, curveLinear),
} };
log.info(edgeData, edge); log.info(edgeData, edge);
if (edge.style !== undefined) { if (edge.style !== undefined) {
const styles = getStylesFromArray(edge.style); const styles = getStylesFromArray(edge.style);
edgeData.style = styles.style; edgeData.style = styles.style;
edgeData.labelStyle = styles.labelStyle; edgeData.labelStyle = styles.labelStyle;
} }
edge.text = edge.title; edge.text = edge.title;
if (edge.text === undefined) { if (edge.text === undefined) {
if (edge.style !== undefined) { if (edge.style !== undefined) {
@@ -227,8 +235,9 @@ export const addRelations = function (relations: ClassRelation[], g: graphlib.Gr
*/ */
export const setConf = function (cnf: any) { export const setConf = function (cnf: any) {
conf = { conf = {
...conf, ...cnf ...conf,
} ...cnf,
};
}; };
/** /**
@@ -281,9 +290,9 @@ export const draw = function (text: string, id: string, _version: string, diagOb
} }
const root = const root =
securityLevel === 'sandbox' securityLevel === 'sandbox'
// @ts-ignore Ignore type error for now ? // @ts-ignore Ignore type error for now
? select(sandboxElement.nodes()[0].contentDocument.body) select(sandboxElement.nodes()[0].contentDocument.body)
: select('body'); : select('body');
// @ts-ignore Ignore type error for now // @ts-ignore Ignore type error for now
const svg = root.select(`[id="${id}"]`); const svg = root.select(`[id="${id}"]`);

View File

@@ -1,55 +1,55 @@
export interface ClassNode { export interface ClassNode {
id: string; id: string;
type: string; type: string;
label: string; label: string;
cssClasses: string[]; cssClasses: string[];
methods: string[]; methods: string[];
members: string[]; members: string[];
annotations: string[]; annotations: string[];
domId: string; domId: string;
link?: string; link?: string;
linkTarget?: string; linkTarget?: string;
haveCallback?: boolean; haveCallback?: boolean;
tooltip?: string; tooltip?: string;
} }
export interface ClassNote { export interface ClassNote {
id: string; id: string;
class: string; class: string;
text: string; text: string;
} }
export interface EdgeData { export interface EdgeData {
arrowheadStyle?: string; arrowheadStyle?: string;
labelpos?: string; labelpos?: string;
labelType?: string; labelType?: string;
label?: string; label?: string;
classes: string; classes: string;
pattern: string; pattern: string;
id: string; id: string;
arrowhead: string; arrowhead: string;
startLabelRight: string; startLabelRight: string;
endLabelLeft: string; endLabelLeft: string;
arrowTypeStart: string; arrowTypeStart: string;
arrowTypeEnd: string; arrowTypeEnd: string;
style: string; style: string;
labelStyle: string; labelStyle: string;
curve: any; curve: any;
} }
export type ClassRelation = { export type ClassRelation = {
id1: string, id1: string;
id2: string, id2: string;
relationTitle1: string, relationTitle1: string;
relationTitle2: string, relationTitle2: string;
type: string, type: string;
title: string, title: string;
text: string, text: string;
style: string[], style: string[];
relation: { relation: {
type1: number, type1: number;
type2: number, type2: number;
lineType: number lineType: number;
} };
}; };
export type ClassMap = Record<string, ClassNode> export type ClassMap = Record<string, ClassNode>;