|
|
|
|
@@ -1,28 +1,28 @@
|
|
|
|
|
import { getConfig } from '../../diagram-api/diagramAPI.js';
|
|
|
|
|
import { log } from '../../logger.js';
|
|
|
|
|
import { generateId } from '../../utils.js';
|
|
|
|
|
import common from '../common/common.js';
|
|
|
|
|
import { getConfig } from '../../diagram-api/diagramAPI.js';
|
|
|
|
|
import {
|
|
|
|
|
clear as commonClear,
|
|
|
|
|
getAccDescription,
|
|
|
|
|
getAccTitle,
|
|
|
|
|
getDiagramTitle,
|
|
|
|
|
setAccDescription,
|
|
|
|
|
setAccTitle,
|
|
|
|
|
getAccTitle,
|
|
|
|
|
getAccDescription,
|
|
|
|
|
setAccDescription,
|
|
|
|
|
clear as commonClear,
|
|
|
|
|
setDiagramTitle,
|
|
|
|
|
getDiagramTitle,
|
|
|
|
|
} from '../common/commonDb.js';
|
|
|
|
|
import { dataFetcher, reset as resetDataFetching } from './dataFetcher.js';
|
|
|
|
|
import { getDir } from './stateRenderer-v3-unified.js';
|
|
|
|
|
|
|
|
|
|
import {
|
|
|
|
|
DEFAULT_DIAGRAM_DIRECTION,
|
|
|
|
|
STMT_STATE,
|
|
|
|
|
STMT_RELATION,
|
|
|
|
|
STMT_CLASSDEF,
|
|
|
|
|
STMT_STYLEDEF,
|
|
|
|
|
STMT_APPLYCLASS,
|
|
|
|
|
DEFAULT_STATE_TYPE,
|
|
|
|
|
DIVIDER_TYPE,
|
|
|
|
|
STMT_APPLYCLASS,
|
|
|
|
|
STMT_CLASSDEF,
|
|
|
|
|
STMT_RELATION,
|
|
|
|
|
STMT_STATE,
|
|
|
|
|
STMT_STYLEDEF,
|
|
|
|
|
} from './stateCommon.js';
|
|
|
|
|
|
|
|
|
|
const START_NODE = '[*]';
|
|
|
|
|
@@ -46,6 +46,15 @@ function newClassesList() {
|
|
|
|
|
return new Map();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let nodes = [];
|
|
|
|
|
let edges = [];
|
|
|
|
|
|
|
|
|
|
let direction = DEFAULT_DIAGRAM_DIRECTION;
|
|
|
|
|
let rootDoc = [];
|
|
|
|
|
let classes = newClassesList(); // style classes defined by a classDef
|
|
|
|
|
|
|
|
|
|
// --------------------------------------
|
|
|
|
|
|
|
|
|
|
const newDoc = () => {
|
|
|
|
|
return {
|
|
|
|
|
/** @type {{ id1: string, id2: string, relationTitle: string }[]} */
|
|
|
|
|
@@ -54,98 +63,40 @@ const newDoc = () => {
|
|
|
|
|
documents: {},
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const clone = (o) => JSON.parse(JSON.stringify(o));
|
|
|
|
|
|
|
|
|
|
export class StateDB {
|
|
|
|
|
constructor() {
|
|
|
|
|
this.clear();
|
|
|
|
|
|
|
|
|
|
// Needed for JISON since it only supports direct properties
|
|
|
|
|
this.setRootDoc = this.setRootDoc.bind(this);
|
|
|
|
|
this.getDividerId = this.getDividerId.bind(this);
|
|
|
|
|
this.setDirection = this.setDirection.bind(this);
|
|
|
|
|
this.trimColon = this.trimColon.bind(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @private
|
|
|
|
|
* @type {Array}
|
|
|
|
|
*/
|
|
|
|
|
nodes = [];
|
|
|
|
|
/**
|
|
|
|
|
* @private
|
|
|
|
|
* @type {Array}
|
|
|
|
|
*/
|
|
|
|
|
edges = [];
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @private
|
|
|
|
|
* @type {string}
|
|
|
|
|
*/
|
|
|
|
|
direction = DEFAULT_DIAGRAM_DIRECTION;
|
|
|
|
|
/**
|
|
|
|
|
* @private
|
|
|
|
|
* @type {Array}
|
|
|
|
|
*/
|
|
|
|
|
rootDoc = [];
|
|
|
|
|
/**
|
|
|
|
|
* @private
|
|
|
|
|
* @type {Map<string, any>}
|
|
|
|
|
*/
|
|
|
|
|
classes = newClassesList(); // style classes defined by a classDef
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @private
|
|
|
|
|
* @type {Object}
|
|
|
|
|
*/
|
|
|
|
|
documents = {
|
|
|
|
|
let documents = {
|
|
|
|
|
root: newDoc(),
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @private
|
|
|
|
|
* @type {Object}
|
|
|
|
|
*/
|
|
|
|
|
currentDocument = this.documents.root;
|
|
|
|
|
/**
|
|
|
|
|
* @private
|
|
|
|
|
* @type {number}
|
|
|
|
|
*/
|
|
|
|
|
startEndCount = 0;
|
|
|
|
|
/**
|
|
|
|
|
* @private
|
|
|
|
|
* @type {number}
|
|
|
|
|
*/
|
|
|
|
|
dividerCnt = 0;
|
|
|
|
|
let currentDocument = documents.root;
|
|
|
|
|
let startEndCount = 0;
|
|
|
|
|
let dividerCnt = 0;
|
|
|
|
|
|
|
|
|
|
static relationType = {
|
|
|
|
|
export const lineType = {
|
|
|
|
|
LINE: 0,
|
|
|
|
|
DOTTED_LINE: 1,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const relationType = {
|
|
|
|
|
AGGREGATION: 0,
|
|
|
|
|
EXTENSION: 1,
|
|
|
|
|
COMPOSITION: 2,
|
|
|
|
|
DEPENDENCY: 3,
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
setRootDoc(o) {
|
|
|
|
|
const clone = (o) => JSON.parse(JSON.stringify(o));
|
|
|
|
|
|
|
|
|
|
const setRootDoc = (o) => {
|
|
|
|
|
log.info('Setting root doc', o);
|
|
|
|
|
// rootDoc = { id: 'root', doc: o };
|
|
|
|
|
this.rootDoc = o;
|
|
|
|
|
}
|
|
|
|
|
rootDoc = o;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
getRootDoc() {
|
|
|
|
|
return this.rootDoc;
|
|
|
|
|
}
|
|
|
|
|
const getRootDoc = () => rootDoc;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @private
|
|
|
|
|
* @param {Object} parent
|
|
|
|
|
* @param {Object} node
|
|
|
|
|
* @param {boolean} first
|
|
|
|
|
*/
|
|
|
|
|
docTranslator(parent, node, first) {
|
|
|
|
|
const docTranslator = (parent, node, first) => {
|
|
|
|
|
if (node.stmt === STMT_RELATION) {
|
|
|
|
|
this.docTranslator(parent, node.state1, true);
|
|
|
|
|
this.docTranslator(parent, node.state2, false);
|
|
|
|
|
docTranslator(parent, node.state1, true);
|
|
|
|
|
docTranslator(parent, node.state2, false);
|
|
|
|
|
} else {
|
|
|
|
|
if (node.stmt === STMT_STATE) {
|
|
|
|
|
if (node.id === '[*]') {
|
|
|
|
|
@@ -164,6 +115,7 @@ export class StateDB {
|
|
|
|
|
let i;
|
|
|
|
|
for (i = 0; i < node.doc.length; i++) {
|
|
|
|
|
if (node.doc[i].type === DIVIDER_TYPE) {
|
|
|
|
|
// debugger;
|
|
|
|
|
const newNode = clone(node.doc[i]);
|
|
|
|
|
newNode.doc = clone(currentDoc);
|
|
|
|
|
doc.push(newNode);
|
|
|
|
|
@@ -185,17 +137,17 @@ export class StateDB {
|
|
|
|
|
node.doc = doc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
node.doc.forEach((docNode) => this.docTranslator(node, docNode, true));
|
|
|
|
|
node.doc.forEach((docNode) => docTranslator(node, docNode, true));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
getRootDocV2() {
|
|
|
|
|
this.docTranslator({ id: 'root' }, { id: 'root', doc: this.rootDoc }, true);
|
|
|
|
|
return { id: 'root', doc: this.rootDoc };
|
|
|
|
|
};
|
|
|
|
|
const getRootDocV2 = () => {
|
|
|
|
|
docTranslator({ id: 'root' }, { id: 'root', doc: rootDoc }, true);
|
|
|
|
|
return { id: 'root', doc: rootDoc };
|
|
|
|
|
// Here
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
/**
|
|
|
|
|
* Convert all of the statements (stmts) that were parsed into states and relationships.
|
|
|
|
|
* This is done because a state diagram may have nested sections,
|
|
|
|
|
* where each section is a 'document' and has its own set of statements.
|
|
|
|
|
@@ -206,7 +158,7 @@ export class StateDB {
|
|
|
|
|
*
|
|
|
|
|
* @param _doc
|
|
|
|
|
*/
|
|
|
|
|
extract(_doc) {
|
|
|
|
|
const extract = (_doc) => {
|
|
|
|
|
// const res = { states: [], relations: [] };
|
|
|
|
|
let doc;
|
|
|
|
|
if (_doc.doc) {
|
|
|
|
|
@@ -219,7 +171,7 @@ export class StateDB {
|
|
|
|
|
// doc = root;
|
|
|
|
|
// }
|
|
|
|
|
log.info(doc);
|
|
|
|
|
this.clear(true);
|
|
|
|
|
clear(true);
|
|
|
|
|
|
|
|
|
|
log.info('Extract initial document:', doc);
|
|
|
|
|
|
|
|
|
|
@@ -227,7 +179,7 @@ export class StateDB {
|
|
|
|
|
log.warn('Statement', item.stmt);
|
|
|
|
|
switch (item.stmt) {
|
|
|
|
|
case STMT_STATE:
|
|
|
|
|
this.addState(
|
|
|
|
|
addState(
|
|
|
|
|
item.id.trim(),
|
|
|
|
|
item.type,
|
|
|
|
|
item.doc,
|
|
|
|
|
@@ -239,48 +191,38 @@ export class StateDB {
|
|
|
|
|
);
|
|
|
|
|
break;
|
|
|
|
|
case STMT_RELATION:
|
|
|
|
|
this.addRelation(item.state1, item.state2, item.description);
|
|
|
|
|
addRelation(item.state1, item.state2, item.description);
|
|
|
|
|
break;
|
|
|
|
|
case STMT_CLASSDEF:
|
|
|
|
|
this.addStyleClass(item.id.trim(), item.classes);
|
|
|
|
|
addStyleClass(item.id.trim(), item.classes);
|
|
|
|
|
break;
|
|
|
|
|
case STMT_STYLEDEF:
|
|
|
|
|
{
|
|
|
|
|
const ids = item.id.trim().split(',');
|
|
|
|
|
const styles = item.styleClass.split(',');
|
|
|
|
|
ids.forEach((id) => {
|
|
|
|
|
let foundState = this.getState(id);
|
|
|
|
|
let foundState = getState(id);
|
|
|
|
|
if (foundState === undefined) {
|
|
|
|
|
const trimmedId = id.trim();
|
|
|
|
|
this.addState(trimmedId);
|
|
|
|
|
foundState = this.getState(trimmedId);
|
|
|
|
|
addState(trimmedId);
|
|
|
|
|
foundState = getState(trimmedId);
|
|
|
|
|
}
|
|
|
|
|
foundState.styles = styles.map((s) => s.replace(/;/g, '')?.trim());
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case STMT_APPLYCLASS:
|
|
|
|
|
this.setCssClass(item.id.trim(), item.styleClass);
|
|
|
|
|
setCssClass(item.id.trim(), item.styleClass);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const diagramStates = this.getStates();
|
|
|
|
|
const diagramStates = getStates();
|
|
|
|
|
const config = getConfig();
|
|
|
|
|
const look = config.look;
|
|
|
|
|
|
|
|
|
|
resetDataFetching();
|
|
|
|
|
dataFetcher(
|
|
|
|
|
undefined,
|
|
|
|
|
this.getRootDocV2(),
|
|
|
|
|
diagramStates,
|
|
|
|
|
this.nodes,
|
|
|
|
|
this.edges,
|
|
|
|
|
true,
|
|
|
|
|
look,
|
|
|
|
|
this.classes
|
|
|
|
|
);
|
|
|
|
|
this.nodes.forEach((node) => {
|
|
|
|
|
dataFetcher(undefined, getRootDocV2(), diagramStates, nodes, edges, true, look, classes);
|
|
|
|
|
nodes.forEach((node) => {
|
|
|
|
|
if (Array.isArray(node.label)) {
|
|
|
|
|
// add the rest as description
|
|
|
|
|
node.description = node.label.slice(1);
|
|
|
|
|
@@ -295,9 +237,9 @@ export class StateDB {
|
|
|
|
|
node.label = node.label[0];
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
/**
|
|
|
|
|
* Function called by parser when a node definition has been found.
|
|
|
|
|
*
|
|
|
|
|
* @param {null | string} id
|
|
|
|
|
@@ -309,7 +251,7 @@ export class StateDB {
|
|
|
|
|
* @param {null | string | string[]} styles - styles to apply to this state. Can be a string (1 style) or an array of styles. If it's just 1 style, convert it to an array of that 1 style.
|
|
|
|
|
* @param {null | string | string[]} textStyles - text styles to apply to this state. Can be a string (1 text test) or an array of text styles. If it's just 1 text style, convert it to an array of that 1 text style.
|
|
|
|
|
*/
|
|
|
|
|
addState(
|
|
|
|
|
export const addState = function (
|
|
|
|
|
id,
|
|
|
|
|
type = DEFAULT_STATE_TYPE,
|
|
|
|
|
doc = null,
|
|
|
|
|
@@ -318,12 +260,12 @@ export class StateDB {
|
|
|
|
|
classes = null,
|
|
|
|
|
styles = null,
|
|
|
|
|
textStyles = null
|
|
|
|
|
) {
|
|
|
|
|
) {
|
|
|
|
|
const trimmedId = id?.trim();
|
|
|
|
|
// add the state if needed
|
|
|
|
|
if (!this.currentDocument.states.has(trimmedId)) {
|
|
|
|
|
if (!currentDocument.states.has(trimmedId)) {
|
|
|
|
|
log.info('Adding state ', trimmedId, descr);
|
|
|
|
|
this.currentDocument.states.set(trimmedId, {
|
|
|
|
|
currentDocument.states.set(trimmedId, {
|
|
|
|
|
id: trimmedId,
|
|
|
|
|
descriptions: [],
|
|
|
|
|
type,
|
|
|
|
|
@@ -334,27 +276,27 @@ export class StateDB {
|
|
|
|
|
textStyles: [],
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
if (!this.currentDocument.states.get(trimmedId).doc) {
|
|
|
|
|
this.currentDocument.states.get(trimmedId).doc = doc;
|
|
|
|
|
if (!currentDocument.states.get(trimmedId).doc) {
|
|
|
|
|
currentDocument.states.get(trimmedId).doc = doc;
|
|
|
|
|
}
|
|
|
|
|
if (!this.currentDocument.states.get(trimmedId).type) {
|
|
|
|
|
this.currentDocument.states.get(trimmedId).type = type;
|
|
|
|
|
if (!currentDocument.states.get(trimmedId).type) {
|
|
|
|
|
currentDocument.states.get(trimmedId).type = type;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (descr) {
|
|
|
|
|
log.info('Setting state description', trimmedId, descr);
|
|
|
|
|
if (typeof descr === 'string') {
|
|
|
|
|
this.addDescription(trimmedId, descr.trim());
|
|
|
|
|
addDescription(trimmedId, descr.trim());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (typeof descr === 'object') {
|
|
|
|
|
descr.forEach((des) => this.addDescription(trimmedId, des.trim()));
|
|
|
|
|
descr.forEach((des) => addDescription(trimmedId, des.trim()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (note) {
|
|
|
|
|
const doc2 = this.currentDocument.states.get(trimmedId);
|
|
|
|
|
const doc2 = currentDocument.states.get(trimmedId);
|
|
|
|
|
doc2.note = note;
|
|
|
|
|
doc2.note.text = common.sanitizeText(doc2.note.text, getConfig());
|
|
|
|
|
}
|
|
|
|
|
@@ -362,126 +304,123 @@ export class StateDB {
|
|
|
|
|
if (classes) {
|
|
|
|
|
log.info('Setting state classes', trimmedId, classes);
|
|
|
|
|
const classesList = typeof classes === 'string' ? [classes] : classes;
|
|
|
|
|
classesList.forEach((cssClass) => this.setCssClass(trimmedId, cssClass.trim()));
|
|
|
|
|
classesList.forEach((cssClass) => setCssClass(trimmedId, cssClass.trim()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (styles) {
|
|
|
|
|
log.info('Setting state styles', trimmedId, styles);
|
|
|
|
|
const stylesList = typeof styles === 'string' ? [styles] : styles;
|
|
|
|
|
stylesList.forEach((style) => this.setStyle(trimmedId, style.trim()));
|
|
|
|
|
stylesList.forEach((style) => setStyle(trimmedId, style.trim()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (textStyles) {
|
|
|
|
|
log.info('Setting state styles', trimmedId, styles);
|
|
|
|
|
const textStylesList = typeof textStyles === 'string' ? [textStyles] : textStyles;
|
|
|
|
|
textStylesList.forEach((textStyle) => this.setTextStyle(trimmedId, textStyle.trim()));
|
|
|
|
|
}
|
|
|
|
|
textStylesList.forEach((textStyle) => setTextStyle(trimmedId, textStyle.trim()));
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
clear(saveCommon) {
|
|
|
|
|
this.nodes = [];
|
|
|
|
|
this.edges = [];
|
|
|
|
|
this.documents = {
|
|
|
|
|
export const clear = function (saveCommon) {
|
|
|
|
|
nodes = [];
|
|
|
|
|
edges = [];
|
|
|
|
|
documents = {
|
|
|
|
|
root: newDoc(),
|
|
|
|
|
};
|
|
|
|
|
this.currentDocument = this.documents.root;
|
|
|
|
|
currentDocument = documents.root;
|
|
|
|
|
|
|
|
|
|
// number of start and end nodes; used to construct ids
|
|
|
|
|
this.startEndCount = 0;
|
|
|
|
|
this.classes = newClassesList();
|
|
|
|
|
startEndCount = 0;
|
|
|
|
|
classes = newClassesList();
|
|
|
|
|
if (!saveCommon) {
|
|
|
|
|
commonClear();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
getState(id) {
|
|
|
|
|
return this.currentDocument.states.get(id);
|
|
|
|
|
}
|
|
|
|
|
getStates() {
|
|
|
|
|
return this.currentDocument.states;
|
|
|
|
|
}
|
|
|
|
|
logDocuments() {
|
|
|
|
|
log.info('Documents = ', this.documents);
|
|
|
|
|
}
|
|
|
|
|
getRelations() {
|
|
|
|
|
return this.currentDocument.relations;
|
|
|
|
|
}
|
|
|
|
|
export const getState = function (id) {
|
|
|
|
|
return currentDocument.states.get(id);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
export const getStates = function () {
|
|
|
|
|
return currentDocument.states;
|
|
|
|
|
};
|
|
|
|
|
export const logDocuments = function () {
|
|
|
|
|
log.info('Documents = ', documents);
|
|
|
|
|
};
|
|
|
|
|
export const getRelations = function () {
|
|
|
|
|
return currentDocument.relations;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* If the id is a start node ( [*] ), then return a new id constructed from
|
|
|
|
|
* the start node name and the current start node count.
|
|
|
|
|
* else return the given id
|
|
|
|
|
*
|
|
|
|
|
* @param {string} id
|
|
|
|
|
* @returns {string} - the id (original or constructed)
|
|
|
|
|
* @private
|
|
|
|
|
*/
|
|
|
|
|
startIdIfNeeded(id = '') {
|
|
|
|
|
function startIdIfNeeded(id = '') {
|
|
|
|
|
let fixedId = id;
|
|
|
|
|
if (id === START_NODE) {
|
|
|
|
|
this.startEndCount++;
|
|
|
|
|
fixedId = `${START_TYPE}${this.startEndCount}`;
|
|
|
|
|
startEndCount++;
|
|
|
|
|
fixedId = `${START_TYPE}${startEndCount}`;
|
|
|
|
|
}
|
|
|
|
|
return fixedId;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
/**
|
|
|
|
|
* If the id is a start node ( [*] ), then return the start type ('start')
|
|
|
|
|
* else return the given type
|
|
|
|
|
*
|
|
|
|
|
* @param {string} id
|
|
|
|
|
* @param {string} type
|
|
|
|
|
* @returns {string} - the type that should be used
|
|
|
|
|
* @private
|
|
|
|
|
*/
|
|
|
|
|
startTypeIfNeeded(id = '', type = DEFAULT_STATE_TYPE) {
|
|
|
|
|
function startTypeIfNeeded(id = '', type = DEFAULT_STATE_TYPE) {
|
|
|
|
|
return id === START_NODE ? START_TYPE : type;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
/**
|
|
|
|
|
* If the id is an end node ( [*] ), then return a new id constructed from
|
|
|
|
|
* the end node name and the current start_end node count.
|
|
|
|
|
* else return the given id
|
|
|
|
|
*
|
|
|
|
|
* @param {string} id
|
|
|
|
|
* @returns {string} - the id (original or constructed)
|
|
|
|
|
* @private
|
|
|
|
|
*/
|
|
|
|
|
endIdIfNeeded(id = '') {
|
|
|
|
|
function endIdIfNeeded(id = '') {
|
|
|
|
|
let fixedId = id;
|
|
|
|
|
if (id === END_NODE) {
|
|
|
|
|
this.startEndCount++;
|
|
|
|
|
fixedId = `${END_TYPE}${this.startEndCount}`;
|
|
|
|
|
startEndCount++;
|
|
|
|
|
fixedId = `${END_TYPE}${startEndCount}`;
|
|
|
|
|
}
|
|
|
|
|
return fixedId;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
/**
|
|
|
|
|
* If the id is an end node ( [*] ), then return the end type
|
|
|
|
|
* else return the given type
|
|
|
|
|
*
|
|
|
|
|
* @param {string} id
|
|
|
|
|
* @param {string} type
|
|
|
|
|
* @returns {string} - the type that should be used
|
|
|
|
|
* @private
|
|
|
|
|
*/
|
|
|
|
|
endTypeIfNeeded(id = '', type = DEFAULT_STATE_TYPE) {
|
|
|
|
|
function endTypeIfNeeded(id = '', type = DEFAULT_STATE_TYPE) {
|
|
|
|
|
return id === END_NODE ? END_TYPE : type;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @param item1
|
|
|
|
|
* @param item2
|
|
|
|
|
* @param relationTitle
|
|
|
|
|
*/
|
|
|
|
|
addRelationObjs(item1, item2, relationTitle) {
|
|
|
|
|
let id1 = this.startIdIfNeeded(item1.id.trim());
|
|
|
|
|
let type1 = this.startTypeIfNeeded(item1.id.trim(), item1.type);
|
|
|
|
|
let id2 = this.startIdIfNeeded(item2.id.trim());
|
|
|
|
|
let type2 = this.startTypeIfNeeded(item2.id.trim(), item2.type);
|
|
|
|
|
export function addRelationObjs(item1, item2, relationTitle) {
|
|
|
|
|
let id1 = startIdIfNeeded(item1.id.trim());
|
|
|
|
|
let type1 = startTypeIfNeeded(item1.id.trim(), item1.type);
|
|
|
|
|
let id2 = startIdIfNeeded(item2.id.trim());
|
|
|
|
|
let type2 = startTypeIfNeeded(item2.id.trim(), item2.type);
|
|
|
|
|
|
|
|
|
|
this.addState(
|
|
|
|
|
addState(
|
|
|
|
|
id1,
|
|
|
|
|
type1,
|
|
|
|
|
item1.doc,
|
|
|
|
|
@@ -491,7 +430,7 @@ export class StateDB {
|
|
|
|
|
item1.styles,
|
|
|
|
|
item1.textStyles
|
|
|
|
|
);
|
|
|
|
|
this.addState(
|
|
|
|
|
addState(
|
|
|
|
|
id2,
|
|
|
|
|
type2,
|
|
|
|
|
item2.doc,
|
|
|
|
|
@@ -502,71 +441,71 @@ export class StateDB {
|
|
|
|
|
item2.textStyles
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
this.currentDocument.relations.push({
|
|
|
|
|
currentDocument.relations.push({
|
|
|
|
|
id1,
|
|
|
|
|
id2,
|
|
|
|
|
relationTitle: common.sanitizeText(relationTitle, getConfig()),
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
/**
|
|
|
|
|
* Add a relation between two items. The items may be full objects or just the string id of a state.
|
|
|
|
|
*
|
|
|
|
|
* @param {string | object} item1
|
|
|
|
|
* @param {string | object} item2
|
|
|
|
|
* @param {string} title
|
|
|
|
|
*/
|
|
|
|
|
addRelation(item1, item2, title) {
|
|
|
|
|
export const addRelation = function (item1, item2, title) {
|
|
|
|
|
if (typeof item1 === 'object') {
|
|
|
|
|
this.addRelationObjs(item1, item2, title);
|
|
|
|
|
addRelationObjs(item1, item2, title);
|
|
|
|
|
} else {
|
|
|
|
|
const id1 = this.startIdIfNeeded(item1.trim());
|
|
|
|
|
const type1 = this.startTypeIfNeeded(item1);
|
|
|
|
|
const id2 = this.endIdIfNeeded(item2.trim());
|
|
|
|
|
const type2 = this.endTypeIfNeeded(item2);
|
|
|
|
|
const id1 = startIdIfNeeded(item1.trim());
|
|
|
|
|
const type1 = startTypeIfNeeded(item1);
|
|
|
|
|
const id2 = endIdIfNeeded(item2.trim());
|
|
|
|
|
const type2 = endTypeIfNeeded(item2);
|
|
|
|
|
|
|
|
|
|
this.addState(id1, type1);
|
|
|
|
|
this.addState(id2, type2);
|
|
|
|
|
this.currentDocument.relations.push({
|
|
|
|
|
addState(id1, type1);
|
|
|
|
|
addState(id2, type2);
|
|
|
|
|
currentDocument.relations.push({
|
|
|
|
|
id1,
|
|
|
|
|
id2,
|
|
|
|
|
title: common.sanitizeText(title, getConfig()),
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
addDescription(id, descr) {
|
|
|
|
|
const theState = this.currentDocument.states.get(id);
|
|
|
|
|
export const addDescription = function (id, descr) {
|
|
|
|
|
const theState = currentDocument.states.get(id);
|
|
|
|
|
const _descr = descr.startsWith(':') ? descr.replace(':', '').trim() : descr;
|
|
|
|
|
theState.descriptions.push(common.sanitizeText(_descr, getConfig()));
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
cleanupLabel(label) {
|
|
|
|
|
export const cleanupLabel = function (label) {
|
|
|
|
|
if (label.substring(0, 1) === ':') {
|
|
|
|
|
return label.substr(2).trim();
|
|
|
|
|
} else {
|
|
|
|
|
return label.trim();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
getDividerId() {
|
|
|
|
|
this.dividerCnt++;
|
|
|
|
|
return 'divider-id-' + this.dividerCnt;
|
|
|
|
|
}
|
|
|
|
|
const getDividerId = () => {
|
|
|
|
|
dividerCnt++;
|
|
|
|
|
return 'divider-id-' + dividerCnt;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
/**
|
|
|
|
|
* Called when the parser comes across a (style) class definition
|
|
|
|
|
* @example classDef my-style fill:#f96;
|
|
|
|
|
*
|
|
|
|
|
* @param {string} id - the id of this (style) class
|
|
|
|
|
* @param {string | null} styleAttributes - the string with 1 or more style attributes (each separated by a comma)
|
|
|
|
|
*/
|
|
|
|
|
addStyleClass(id, styleAttributes = '') {
|
|
|
|
|
export const addStyleClass = function (id, styleAttributes = '') {
|
|
|
|
|
// create a new style class object with this id
|
|
|
|
|
if (!this.classes.has(id)) {
|
|
|
|
|
this.classes.set(id, { id: id, styles: [], textStyles: [] }); // This is a classDef
|
|
|
|
|
if (!classes.has(id)) {
|
|
|
|
|
classes.set(id, { id: id, styles: [], textStyles: [] }); // This is a classDef
|
|
|
|
|
}
|
|
|
|
|
const foundClass = this.classes.get(id);
|
|
|
|
|
const foundClass = classes.get(id);
|
|
|
|
|
if (styleAttributes !== undefined && styleAttributes !== null) {
|
|
|
|
|
styleAttributes.split(STYLECLASS_SEP).forEach((attrib) => {
|
|
|
|
|
// remove any trailing ;
|
|
|
|
|
@@ -581,17 +520,17 @@ export class StateDB {
|
|
|
|
|
foundClass.styles.push(fixedAttrib);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
/**
|
|
|
|
|
* Return all of the style classes
|
|
|
|
|
* @returns {{} | any | classes}
|
|
|
|
|
*/
|
|
|
|
|
getClasses() {
|
|
|
|
|
return this.classes;
|
|
|
|
|
}
|
|
|
|
|
export const getClasses = function () {
|
|
|
|
|
return classes;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
/**
|
|
|
|
|
* Add a (style) class or css class to a state with the given id.
|
|
|
|
|
* If the state isn't already in the list of known states, add it.
|
|
|
|
|
* Might be called by parser when a style class or CSS class should be applied to a state
|
|
|
|
|
@@ -599,19 +538,19 @@ export class StateDB {
|
|
|
|
|
* @param {string | string[]} itemIds The id or a list of ids of the item(s) to apply the css class to
|
|
|
|
|
* @param {string} cssClassName CSS class name
|
|
|
|
|
*/
|
|
|
|
|
setCssClass(itemIds, cssClassName) {
|
|
|
|
|
itemIds.split(',').forEach((id) => {
|
|
|
|
|
let foundState = this.getState(id);
|
|
|
|
|
export const setCssClass = function (itemIds, cssClassName) {
|
|
|
|
|
itemIds.split(',').forEach(function (id) {
|
|
|
|
|
let foundState = getState(id);
|
|
|
|
|
if (foundState === undefined) {
|
|
|
|
|
const trimmedId = id.trim();
|
|
|
|
|
this.addState(trimmedId);
|
|
|
|
|
foundState = this.getState(trimmedId);
|
|
|
|
|
addState(trimmedId);
|
|
|
|
|
foundState = getState(trimmedId);
|
|
|
|
|
}
|
|
|
|
|
foundState.classes.push(cssClassName);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
/**
|
|
|
|
|
* Add a style to a state with the given id.
|
|
|
|
|
* @example style stateId fill:#f9f,stroke:#333,stroke-width:4px
|
|
|
|
|
* where 'style' is the keyword
|
|
|
|
|
@@ -621,55 +560,67 @@ export class StateDB {
|
|
|
|
|
* @param itemId The id of item to apply the style to
|
|
|
|
|
* @param styleText - the text of the attributes for the style
|
|
|
|
|
*/
|
|
|
|
|
setStyle(itemId, styleText) {
|
|
|
|
|
const item = this.getState(itemId);
|
|
|
|
|
export const setStyle = function (itemId, styleText) {
|
|
|
|
|
const item = getState(itemId);
|
|
|
|
|
if (item !== undefined) {
|
|
|
|
|
item.styles.push(styleText);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
/**
|
|
|
|
|
* Add a text style to a state with the given id
|
|
|
|
|
*
|
|
|
|
|
* @param itemId The id of item to apply the css class to
|
|
|
|
|
* @param cssClassName CSS class name
|
|
|
|
|
*/
|
|
|
|
|
setTextStyle(itemId, cssClassName) {
|
|
|
|
|
const item = this.getState(itemId);
|
|
|
|
|
export const setTextStyle = function (itemId, cssClassName) {
|
|
|
|
|
const item = getState(itemId);
|
|
|
|
|
if (item !== undefined) {
|
|
|
|
|
item.textStyles.push(cssClassName);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
getDirection() {
|
|
|
|
|
return this.direction;
|
|
|
|
|
}
|
|
|
|
|
setDirection(dir) {
|
|
|
|
|
this.direction = dir;
|
|
|
|
|
}
|
|
|
|
|
const getDirection = () => direction;
|
|
|
|
|
const setDirection = (dir) => {
|
|
|
|
|
direction = dir;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
trimColon(str) {
|
|
|
|
|
return str && str[0] === ':' ? str.substr(1).trim() : str.trim();
|
|
|
|
|
}
|
|
|
|
|
const trimColon = (str) => (str && str[0] === ':' ? str.substr(1).trim() : str.trim());
|
|
|
|
|
|
|
|
|
|
getData() {
|
|
|
|
|
export const getData = () => {
|
|
|
|
|
const config = getConfig();
|
|
|
|
|
return {
|
|
|
|
|
nodes: this.nodes,
|
|
|
|
|
edges: this.edges,
|
|
|
|
|
other: {},
|
|
|
|
|
config,
|
|
|
|
|
direction: getDir(this.getRootDocV2()),
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
return { nodes, edges, other: {}, config, direction: getDir(getRootDocV2()) };
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
getConfig() {
|
|
|
|
|
return getConfig().state;
|
|
|
|
|
}
|
|
|
|
|
getAccTitle = getAccTitle;
|
|
|
|
|
setAccTitle = setAccTitle;
|
|
|
|
|
getAccDescription = getAccDescription;
|
|
|
|
|
setAccDescription = setAccDescription;
|
|
|
|
|
setDiagramTitle = setDiagramTitle;
|
|
|
|
|
getDiagramTitle = getDiagramTitle;
|
|
|
|
|
}
|
|
|
|
|
export default {
|
|
|
|
|
getConfig: () => getConfig().state,
|
|
|
|
|
getData,
|
|
|
|
|
addState,
|
|
|
|
|
clear,
|
|
|
|
|
getState,
|
|
|
|
|
getStates,
|
|
|
|
|
getRelations,
|
|
|
|
|
getClasses,
|
|
|
|
|
getDirection,
|
|
|
|
|
addRelation,
|
|
|
|
|
getDividerId,
|
|
|
|
|
setDirection,
|
|
|
|
|
cleanupLabel,
|
|
|
|
|
lineType,
|
|
|
|
|
relationType,
|
|
|
|
|
logDocuments,
|
|
|
|
|
getRootDoc,
|
|
|
|
|
setRootDoc,
|
|
|
|
|
getRootDocV2,
|
|
|
|
|
extract,
|
|
|
|
|
trimColon,
|
|
|
|
|
getAccTitle,
|
|
|
|
|
setAccTitle,
|
|
|
|
|
getAccDescription,
|
|
|
|
|
setAccDescription,
|
|
|
|
|
addStyleClass,
|
|
|
|
|
setCssClass,
|
|
|
|
|
addDescription,
|
|
|
|
|
setDiagramTitle,
|
|
|
|
|
getDiagramTitle,
|
|
|
|
|
};
|
|
|
|
|
|