You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

32 lines
780 B

import {Cell} from '@antv/x6';
interface DSL {
cells: Cell.Properties[];
}
const extractObj = (obj: Cell.Properties = {}, keys: string[] = []): Cell.Properties => {
const ret: Cell.Properties = {};
keys.forEach((key) => {
if (obj[key]) {
ret[key] = obj[key];
}
});
return ret;
};
const simplifyDSL = (dsl: DSL): Cell.Properties => {
const { cells = [] } = dsl;
return {
cells: cells.map((cell) => {
if (cell.shape === 'edge') {
return extractObj(cell, ['id', 'shape', 'source', 'target']);
} else {
const newCell = extractObj(cell, ['id', 'shape', 'data']);
newCell.data = extractObj(cell.data, ['trigger', 'configData', 'ports']);
return newCell;
}
}),
};
};
export default simplifyDSL;