refactor: Fix types and imports
This commit is contained in:
parent
e1a23f10df
commit
9651d0c2da
|
@ -127,5 +127,10 @@
|
||||||
},
|
},
|
||||||
"nyc": {
|
"nyc": {
|
||||||
"report-dir": "coverage/cypress"
|
"report-dir": "coverage/cypress"
|
||||||
|
},
|
||||||
|
"pnpm": {
|
||||||
|
"patchedDependencies": {
|
||||||
|
"cytoscape@3.28.1": "patches/cytoscape@3.28.1.patch"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,15 +39,10 @@
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@braintree/sanitize-url": "^6.0.1",
|
"@braintree/sanitize-url": "^6.0.1",
|
||||||
"cytoscape": "^3.23.0",
|
|
||||||
"cytoscape-cose-bilkent": "^4.1.0",
|
|
||||||
"cytoscape-fcose": "^2.1.0",
|
|
||||||
"d3": "^7.0.0",
|
"d3": "^7.0.0",
|
||||||
"khroma": "^2.0.0",
|
"khroma": "^2.0.0"
|
||||||
"non-layered-tidy-tree-layout": "^2.0.2"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/cytoscape": "^3.19.9",
|
|
||||||
"concurrently": "^8.0.0",
|
"concurrently": "^8.0.0",
|
||||||
"rimraf": "^5.0.0",
|
"rimraf": "^5.0.0",
|
||||||
"mermaid": "workspace:*"
|
"mermaid": "workspace:*"
|
||||||
|
|
|
@ -62,9 +62,8 @@
|
||||||
"@braintree/sanitize-url": "^6.0.1",
|
"@braintree/sanitize-url": "^6.0.1",
|
||||||
"@types/d3-scale": "^4.0.3",
|
"@types/d3-scale": "^4.0.3",
|
||||||
"@types/d3-scale-chromatic": "^3.0.0",
|
"@types/d3-scale-chromatic": "^3.0.0",
|
||||||
"cytoscape": "^3.23.0",
|
"cytoscape": "^3.28.1",
|
||||||
"cytoscape-cose-bilkent": "^4.1.0",
|
"cytoscape-cose-bilkent": "^4.1.0",
|
||||||
"cytoscape-fcose": "^2.1.0",
|
|
||||||
"d3": "^7.4.0",
|
"d3": "^7.4.0",
|
||||||
"d3-sankey": "^0.12.3",
|
"d3-sankey": "^0.12.3",
|
||||||
"dagre-d3-es": "7.0.10",
|
"dagre-d3-es": "7.0.10",
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
// @ts-ignore: JISON doesn't support types
|
// @ts-ignore: JISON doesn't support types
|
||||||
import mindmapParser from './parser/mindmap.jison';
|
import parser from './parser/mindmap.jison';
|
||||||
import * as mindmapDb from './mindmapDb.js';
|
import db from './mindmapDb.js';
|
||||||
import mindmapRenderer from './mindmapRenderer.js';
|
import renderer from './mindmapRenderer.js';
|
||||||
import mindmapStyles from './styles.js';
|
import styles from './styles.js';
|
||||||
import type { DiagramDefinition } from '../../diagram-api/types.js';
|
import type { DiagramDefinition } from '../../diagram-api/types.js';
|
||||||
|
|
||||||
export const diagram: DiagramDefinition = {
|
export const diagram: DiagramDefinition = {
|
||||||
db: mindmapDb,
|
db,
|
||||||
renderer: mindmapRenderer,
|
renderer,
|
||||||
parser: mindmapParser,
|
parser,
|
||||||
styles: mindmapStyles,
|
styles,
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// @ts-expect-error No types available for JISON
|
// @ts-expect-error No types available for JISON
|
||||||
import { parser as mindmap } from './parser/mindmap.jison';
|
import { parser as mindmap } from './parser/mindmap.jison';
|
||||||
import * as mindmapDB from './mindmapDb.js';
|
import mindmapDB from './mindmapDb.js';
|
||||||
// Todo fix utils functions for tests
|
// Todo fix utils functions for tests
|
||||||
import { setLogLevel } from '../../diagram-api/diagramAPI.js';
|
import { setLogLevel } from '../../diagram-api/diagramAPI.js';
|
||||||
|
|
||||||
|
|
|
@ -2,23 +2,7 @@ import { getConfig } from '../../diagram-api/diagramAPI.js';
|
||||||
import { sanitizeText } from '../../diagrams/common/common.js';
|
import { sanitizeText } from '../../diagrams/common/common.js';
|
||||||
import { log } from '../../logger.js';
|
import { log } from '../../logger.js';
|
||||||
import type { D3Element } from '../../mermaidAPI.js';
|
import type { D3Element } from '../../mermaidAPI.js';
|
||||||
|
import type { MindMapNode } from './mindmapTypes.js';
|
||||||
export interface MindMapNode {
|
|
||||||
id: number;
|
|
||||||
nodeId: string;
|
|
||||||
level: number;
|
|
||||||
descr: string;
|
|
||||||
type: number;
|
|
||||||
children: MindMapNode[];
|
|
||||||
width: number;
|
|
||||||
padding: number;
|
|
||||||
section?: number;
|
|
||||||
height?: number;
|
|
||||||
class?: string;
|
|
||||||
icon?: string;
|
|
||||||
x?: number;
|
|
||||||
y?: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
let nodes: MindMapNode[] = [];
|
let nodes: MindMapNode[] = [];
|
||||||
let cnt = 0;
|
let cnt = 0;
|
||||||
|
@ -158,3 +142,17 @@ export const type2Str = (type: number) => {
|
||||||
// Expose logger to grammar
|
// Expose logger to grammar
|
||||||
export const getLogger = () => log;
|
export const getLogger = () => log;
|
||||||
export const getElementById = (id: string) => elements[id];
|
export const getElementById = (id: string) => elements[id];
|
||||||
|
|
||||||
|
const db = {
|
||||||
|
clear,
|
||||||
|
addNode,
|
||||||
|
getMindmap,
|
||||||
|
nodeType,
|
||||||
|
setElementForId,
|
||||||
|
decorateNode,
|
||||||
|
type2Str,
|
||||||
|
getLogger,
|
||||||
|
getElementById,
|
||||||
|
} as const;
|
||||||
|
|
||||||
|
export default db;
|
||||||
|
|
|
@ -6,17 +6,16 @@ import svgDraw from './svgDraw.js';
|
||||||
import cytoscape from 'cytoscape';
|
import cytoscape from 'cytoscape';
|
||||||
// @ts-expect-error No types available
|
// @ts-expect-error No types available
|
||||||
import coseBilkent from 'cytoscape-cose-bilkent';
|
import coseBilkent from 'cytoscape-cose-bilkent';
|
||||||
import * as db from './mindmapDb.js';
|
import type { MindMapNode, MindmapDB } from './mindmapTypes.js';
|
||||||
import type { MermaidConfig } from '../../config.type.js';
|
import type { MermaidConfig } from '../../config.type.js';
|
||||||
import type { Diagram } from '../../Diagram.js';
|
import type { Diagram } from '../../Diagram.js';
|
||||||
import type { MindmapDB } from './mindmapTypes.js';
|
|
||||||
import type { D3Element } from '../../mermaidAPI.js';
|
import type { D3Element } from '../../mermaidAPI.js';
|
||||||
import type { MermaidConfigWithDefaults } from '../../config.js';
|
import type { MermaidConfigWithDefaults } from '../../config.js';
|
||||||
|
|
||||||
// Inject the layout algorithm into cytoscape
|
// Inject the layout algorithm into cytoscape
|
||||||
cytoscape.use(coseBilkent);
|
cytoscape.use(coseBilkent);
|
||||||
|
|
||||||
function drawNodes(svg: D3Element, mindmap: db.MindMapNode, section: number, conf: MermaidConfig) {
|
function drawNodes(svg: D3Element, mindmap: MindMapNode, section: number, conf: MermaidConfig) {
|
||||||
svgDraw.drawNode(svg, mindmap, section, conf);
|
svgDraw.drawNode(svg, mindmap, section, conf);
|
||||||
if (mindmap.children) {
|
if (mindmap.children) {
|
||||||
mindmap.children.forEach((child, index) => {
|
mindmap.children.forEach((child, index) => {
|
||||||
|
@ -58,7 +57,7 @@ function drawEdges(edgesEl: D3Element, cy: cytoscape.Core) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function addNodes(mindmap: db.MindMapNode, cy: cytoscape.Core, conf: MermaidConfig, level: number) {
|
function addNodes(mindmap: MindMapNode, cy: cytoscape.Core, conf: MermaidConfig, level: number) {
|
||||||
cy.add({
|
cy.add({
|
||||||
group: 'nodes',
|
group: 'nodes',
|
||||||
data: {
|
data: {
|
||||||
|
@ -94,7 +93,7 @@ function addNodes(mindmap: db.MindMapNode, cy: cytoscape.Core, conf: MermaidConf
|
||||||
}
|
}
|
||||||
|
|
||||||
function layoutMindmap(
|
function layoutMindmap(
|
||||||
node: db.MindMapNode,
|
node: MindMapNode,
|
||||||
conf: MermaidConfigWithDefaults
|
conf: MermaidConfigWithDefaults
|
||||||
): Promise<cytoscape.Core> {
|
): Promise<cytoscape.Core> {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
|
@ -137,7 +136,7 @@ function layoutMindmap(
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function positionNodes(cy: cytoscape.Core) {
|
function positionNodes(db: MindmapDB, cy: cytoscape.Core) {
|
||||||
cy.nodes().map((node, id) => {
|
cy.nodes().map((node, id) => {
|
||||||
const data = node.data();
|
const data = node.data();
|
||||||
data.x = node.position().x;
|
data.x = node.position().x;
|
||||||
|
@ -155,7 +154,7 @@ function positionNodes(cy: cytoscape.Core) {
|
||||||
|
|
||||||
export const draw = async (text: string, id: string, version: string, diagObj: Diagram) => {
|
export const draw = async (text: string, id: string, version: string, diagObj: Diagram) => {
|
||||||
const conf = getConfig();
|
const conf = getConfig();
|
||||||
|
const db = diagObj.db as MindmapDB;
|
||||||
conf.htmlLabels = false;
|
conf.htmlLabels = false;
|
||||||
|
|
||||||
log.debug('Rendering mindmap diagram\n' + text, diagObj.parser);
|
log.debug('Rendering mindmap diagram\n' + text, diagObj.parser);
|
||||||
|
@ -176,7 +175,7 @@ export const draw = async (text: string, id: string, version: string, diagObj: D
|
||||||
const svg = root.select('#' + id);
|
const svg = root.select('#' + id);
|
||||||
|
|
||||||
svg.append('g');
|
svg.append('g');
|
||||||
const mm = (diagObj.db as MindmapDB).getMindmap();
|
const mm = db.getMindmap();
|
||||||
if (!mm) {
|
if (!mm) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -196,7 +195,7 @@ export const draw = async (text: string, id: string, version: string, diagObj: D
|
||||||
|
|
||||||
// After this we can draw, first the edges and the then nodes with the correct position
|
// After this we can draw, first the edges and the then nodes with the correct position
|
||||||
drawEdges(edgesElem, cy);
|
drawEdges(edgesElem, cy);
|
||||||
positionNodes(cy);
|
positionNodes(db, cy);
|
||||||
|
|
||||||
// Setup the view box and size of the svg element
|
// Setup the view box and size of the svg element
|
||||||
setupGraphViewbox(undefined, svg, conf.mindmap.padding, conf.mindmap.useMaxWidth);
|
setupGraphViewbox(undefined, svg, conf.mindmap.padding, conf.mindmap.useMaxWidth);
|
||||||
|
|
|
@ -1,3 +1,20 @@
|
||||||
import type * as mindmapDb from './mindmapDb.js';
|
import type mindmapDb from './mindmapDb.js';
|
||||||
|
|
||||||
|
export interface MindMapNode {
|
||||||
|
id: number;
|
||||||
|
nodeId: string;
|
||||||
|
level: number;
|
||||||
|
descr: string;
|
||||||
|
type: number;
|
||||||
|
children: MindMapNode[];
|
||||||
|
width: number;
|
||||||
|
padding: number;
|
||||||
|
section?: number;
|
||||||
|
height?: number;
|
||||||
|
class?: string;
|
||||||
|
icon?: string;
|
||||||
|
x?: number;
|
||||||
|
y?: number;
|
||||||
|
}
|
||||||
|
|
||||||
export type MindmapDB = typeof mindmapDb;
|
export type MindmapDB = typeof mindmapDb;
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
diff --git a/package.json b/package.json
|
||||||
|
index f2f77fa79c99382b079f4051ed51eafe8d2379c8..0bfddf55394e86f3a386eb7ab681369d410bae07 100644
|
||||||
|
--- a/package.json
|
||||||
|
+++ b/package.json
|
||||||
|
@@ -30,7 +30,15 @@
|
||||||
|
"engines": {
|
||||||
|
"node": ">=0.10"
|
||||||
|
},
|
||||||
|
+ "exports": {
|
||||||
|
+ ".": {
|
||||||
|
+ "import": "./dist/cytoscape.umd.js",
|
||||||
|
+ "default": "./dist/cytoscape.cjs.js"
|
||||||
|
+ },
|
||||||
|
+ "./*": "./*"
|
||||||
|
+ },
|
||||||
|
"main": "dist/cytoscape.cjs.js",
|
||||||
|
+ "module": "dist/cytoscape.umd.js",
|
||||||
|
"unpkg": "dist/cytoscape.min.js",
|
||||||
|
"jsdelivr": "dist/cytoscape.min.js",
|
||||||
|
"scripts": {
|
|
@ -4,6 +4,11 @@ settings:
|
||||||
autoInstallPeers: true
|
autoInstallPeers: true
|
||||||
excludeLinksFromLockfile: false
|
excludeLinksFromLockfile: false
|
||||||
|
|
||||||
|
patchedDependencies:
|
||||||
|
cytoscape@3.28.1:
|
||||||
|
hash: claipxynndhyqyu2csninuoh5e
|
||||||
|
path: patches/cytoscape@3.28.1.patch
|
||||||
|
|
||||||
importers:
|
importers:
|
||||||
|
|
||||||
.:
|
.:
|
||||||
|
@ -201,14 +206,11 @@ importers:
|
||||||
specifier: ^3.0.0
|
specifier: ^3.0.0
|
||||||
version: 3.0.0
|
version: 3.0.0
|
||||||
cytoscape:
|
cytoscape:
|
||||||
specifier: ^3.23.0
|
specifier: ^3.28.1
|
||||||
version: 3.23.0
|
version: 3.28.1(patch_hash=claipxynndhyqyu2csninuoh5e)
|
||||||
cytoscape-cose-bilkent:
|
cytoscape-cose-bilkent:
|
||||||
specifier: ^4.1.0
|
specifier: ^4.1.0
|
||||||
version: 4.1.0(cytoscape@3.23.0)
|
version: 4.1.0(cytoscape@3.28.1)
|
||||||
cytoscape-fcose:
|
|
||||||
specifier: ^2.1.0
|
|
||||||
version: 2.1.0(cytoscape@3.23.0)
|
|
||||||
d3:
|
d3:
|
||||||
specifier: ^7.4.0
|
specifier: ^7.4.0
|
||||||
version: 7.4.0
|
version: 7.4.0
|
||||||
|
@ -384,28 +386,13 @@ importers:
|
||||||
'@braintree/sanitize-url':
|
'@braintree/sanitize-url':
|
||||||
specifier: ^6.0.1
|
specifier: ^6.0.1
|
||||||
version: 6.0.2
|
version: 6.0.2
|
||||||
cytoscape:
|
|
||||||
specifier: ^3.23.0
|
|
||||||
version: 3.23.0
|
|
||||||
cytoscape-cose-bilkent:
|
|
||||||
specifier: ^4.1.0
|
|
||||||
version: 4.1.0(cytoscape@3.23.0)
|
|
||||||
cytoscape-fcose:
|
|
||||||
specifier: ^2.1.0
|
|
||||||
version: 2.1.0(cytoscape@3.23.0)
|
|
||||||
d3:
|
d3:
|
||||||
specifier: ^7.0.0
|
specifier: ^7.0.0
|
||||||
version: 7.0.0
|
version: 7.0.0
|
||||||
khroma:
|
khroma:
|
||||||
specifier: ^2.0.0
|
specifier: ^2.0.0
|
||||||
version: 2.0.0
|
version: 2.0.0
|
||||||
non-layered-tidy-tree-layout:
|
|
||||||
specifier: ^2.0.2
|
|
||||||
version: 2.0.2
|
|
||||||
devDependencies:
|
devDependencies:
|
||||||
'@types/cytoscape':
|
|
||||||
specifier: ^3.19.9
|
|
||||||
version: 3.19.9
|
|
||||||
concurrently:
|
concurrently:
|
||||||
specifier: ^8.0.0
|
specifier: ^8.0.0
|
||||||
version: 8.0.0
|
version: 8.0.0
|
||||||
|
@ -7739,12 +7726,6 @@ packages:
|
||||||
layout-base: 1.0.2
|
layout-base: 1.0.2
|
||||||
dev: false
|
dev: false
|
||||||
|
|
||||||
/cose-base@2.2.0:
|
|
||||||
resolution: {integrity: sha512-AzlgcsCbUMymkADOJtQm3wO9S3ltPfYOFD5033keQn9NJzIbtnZj+UdBJe7DYml/8TdbtHJW3j58SOnKhWY/5g==}
|
|
||||||
dependencies:
|
|
||||||
layout-base: 2.0.1
|
|
||||||
dev: false
|
|
||||||
|
|
||||||
/cosmiconfig-typescript-loader@4.4.0(@types/node@20.4.7)(cosmiconfig@8.2.0)(ts-node@10.9.1)(typescript@5.1.6):
|
/cosmiconfig-typescript-loader@4.4.0(@types/node@20.4.7)(cosmiconfig@8.2.0)(ts-node@10.9.1)(typescript@5.1.6):
|
||||||
resolution: {integrity: sha512-BabizFdC3wBHhbI4kJh0VkQP9GkBfoHPydD0COMce1nJ1kJAB3F2TmJ/I7diULBKtmEWSwEbuN/KDtgnmUUVmw==}
|
resolution: {integrity: sha512-BabizFdC3wBHhbI4kJh0VkQP9GkBfoHPydD0COMce1nJ1kJAB3F2TmJ/I7diULBKtmEWSwEbuN/KDtgnmUUVmw==}
|
||||||
engines: {node: '>=v14.21.3'}
|
engines: {node: '>=v14.21.3'}
|
||||||
|
@ -8135,31 +8116,23 @@ packages:
|
||||||
yauzl: 2.10.0
|
yauzl: 2.10.0
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
/cytoscape-cose-bilkent@4.1.0(cytoscape@3.23.0):
|
/cytoscape-cose-bilkent@4.1.0(cytoscape@3.28.1):
|
||||||
resolution: {integrity: sha512-wgQlVIUJF13Quxiv5e1gstZ08rnZj2XaLHGoFMYXz7SkNfCDOOteKBE6SYRfA9WxxI/iBc3ajfDoc6hb/MRAHQ==}
|
resolution: {integrity: sha512-wgQlVIUJF13Quxiv5e1gstZ08rnZj2XaLHGoFMYXz7SkNfCDOOteKBE6SYRfA9WxxI/iBc3ajfDoc6hb/MRAHQ==}
|
||||||
peerDependencies:
|
peerDependencies:
|
||||||
cytoscape: ^3.2.0
|
cytoscape: ^3.2.0
|
||||||
dependencies:
|
dependencies:
|
||||||
cose-base: 1.0.3
|
cose-base: 1.0.3
|
||||||
cytoscape: 3.23.0
|
cytoscape: 3.28.1(patch_hash=claipxynndhyqyu2csninuoh5e)
|
||||||
dev: false
|
dev: false
|
||||||
|
|
||||||
/cytoscape-fcose@2.1.0(cytoscape@3.23.0):
|
/cytoscape@3.28.1(patch_hash=claipxynndhyqyu2csninuoh5e):
|
||||||
resolution: {integrity: sha512-Q3apPl66jf8/2sMsrCjNP247nbDkyIPjA9g5iPMMWNLZgP3/mn9aryF7EFY/oRPEpv7bKJ4jYmCoU5r5/qAc1Q==}
|
resolution: {integrity: sha512-xyItz4O/4zp9/239wCcH8ZcFuuZooEeF8KHRmzjDfGdXsj3OG9MFSMA0pJE0uX3uCN/ygof6hHf4L7lst+JaDg==}
|
||||||
peerDependencies:
|
|
||||||
cytoscape: ^3.2.0
|
|
||||||
dependencies:
|
|
||||||
cose-base: 2.2.0
|
|
||||||
cytoscape: 3.23.0
|
|
||||||
dev: false
|
|
||||||
|
|
||||||
/cytoscape@3.23.0:
|
|
||||||
resolution: {integrity: sha512-gRZqJj/1kiAVPkrVFvz/GccxsXhF3Qwpptl32gKKypO4IlqnKBjTOu+HbXtEggSGzC5KCaHp3/F7GgENrtsFkA==}
|
|
||||||
engines: {node: '>=0.10'}
|
engines: {node: '>=0.10'}
|
||||||
dependencies:
|
dependencies:
|
||||||
heap: 0.2.7
|
heap: 0.2.7
|
||||||
lodash: 4.17.21
|
lodash: 4.17.21
|
||||||
dev: false
|
dev: false
|
||||||
|
patched: true
|
||||||
|
|
||||||
/d3-array@2.12.1:
|
/d3-array@2.12.1:
|
||||||
resolution: {integrity: sha512-B0ErZK/66mHtEsR1TkPEEkwdy+WDesimkM5gpZr5Dsg54BiTA5RXtYW5qTLIAcekaS9xfZrzBLF/OAkB3Qn1YQ==}
|
resolution: {integrity: sha512-B0ErZK/66mHtEsR1TkPEEkwdy+WDesimkM5gpZr5Dsg54BiTA5RXtYW5qTLIAcekaS9xfZrzBLF/OAkB3Qn1YQ==}
|
||||||
|
@ -12000,10 +11973,6 @@ packages:
|
||||||
resolution: {integrity: sha512-8h2oVEZNktL4BH2JCOI90iD1yXwL6iNW7KcCKT2QZgQJR2vbqDsldCTPRU9NifTCqHZci57XvQQ15YTu+sTYPg==}
|
resolution: {integrity: sha512-8h2oVEZNktL4BH2JCOI90iD1yXwL6iNW7KcCKT2QZgQJR2vbqDsldCTPRU9NifTCqHZci57XvQQ15YTu+sTYPg==}
|
||||||
dev: false
|
dev: false
|
||||||
|
|
||||||
/layout-base@2.0.1:
|
|
||||||
resolution: {integrity: sha512-dp3s92+uNI1hWIpPGH3jK2kxE2lMjdXdr+DH8ynZHpd6PUlH6x6cbuXnoMmiNumznqaNO31xu9e79F0uuZ0JFg==}
|
|
||||||
dev: false
|
|
||||||
|
|
||||||
/lazy-ass@1.6.0:
|
/lazy-ass@1.6.0:
|
||||||
resolution: {integrity: sha512-cc8oEVoctTvsFZ/Oje/kGnHbpWHYBe8IAJe4C0QNc3t8uM/0Y8+erSz/7Y1ALuXTEZTMvxXwO6YbX1ey3ujiZw==}
|
resolution: {integrity: sha512-cc8oEVoctTvsFZ/Oje/kGnHbpWHYBe8IAJe4C0QNc3t8uM/0Y8+erSz/7Y1ALuXTEZTMvxXwO6YbX1ey3ujiZw==}
|
||||||
engines: {node: '> 0.8'}
|
engines: {node: '> 0.8'}
|
||||||
|
|
Loading…
Reference in New Issue