Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function matches(definition, filter) {
return every(filter, function(val, key) {
// we want a == conversion here, to be able to catch
// undefined == false and friends
/* jshint -W116 */
return definition[key] == val;
});
}
function canMove(elements, target) {
if (!isArray(elements)) {
elements = [ elements ];
}
// allow default move check to start move operation
if (!target) {
return true;
}
if (every(elements, function(element) {
return isAny(element, [
'dmn:BusinessKnowledgeModel',
'dmn:Decision',
'dmn:InputData',
'dmn:KnowledgeSource',
'dmn:TextAnnotation',
'dmn:InformationRequirement',
'dmn:AuthorityRequirement',
'dmn:KnowledgeRequirement',
'dmn:Association'
]);
}) && is(target, 'dmn:Definitions')) {
return true;
}
return false;
this.addRule('paste', ({ elements, target }) => {
if (!isArray(elements)) {
elements = [ elements ];
}
if (target instanceof Row) {
return every(elements, element => element instanceof Row);
} else if (target instanceof Col) {
return every(elements, element => element instanceof Col);
}
return false;
});
}
return every(root, descriptor => {
if (descriptor.type !== 'row') {
return false;
}
if (descriptor.cells.length !== cols.length) {
return false;
}
return every(descriptor.cells, (cellDescriptor, index) => {
if (isInput(cols[index])) {
return cellDescriptor.businessObject.$type === 'dmn:UnaryTests';
} else {
return cellDescriptor.businessObject.$type === 'dmn:LiteralExpression';
}
});
});
}
export function pointsAlignedVertically(a, b) {
var points;
if (isArray(a)) {
points = a;
} else {
points = [ a, b ];
}
var firstPoint = points.slice().shift();
return every(points, function(point) {
return Math.abs(firstPoint.x - point.x) <= ALIGNED_THRESHOLD;
});
}
canPasteCols(root, targetCol) {
const { rows } = this._sheet.getRoot();
return every(root, descriptor => {
if (descriptor.type !== 'col') {
return false;
}
if (descriptor.cells.length !== rows.length) {
return false;
}
if (isInput(targetCol)) {
return descriptor.businessObject.$type === 'dmn:InputClause';
} else {
return descriptor.businessObject.$type === 'dmn:OutputClause';
}
});
}
}
canPasteRows(root) {
const { cols } = this._sheet.getRoot();
return every(root, descriptor => {
if (descriptor.type !== 'row') {
return false;
}
if (descriptor.cells.length !== cols.length) {
return false;
}
return every(descriptor.cells, (cellDescriptor, index) => {
if (isInput(cols[index])) {
return cellDescriptor.businessObject.$type === 'dmn:UnaryTests';
} else {
return cellDescriptor.businessObject.$type === 'dmn:LiteralExpression';
}
});
this.addRule('elements.create', function(context) {
var elements = context.elements,
position = context.position,
target = context.target;
return every(elements, function(element) {
if (isConnection(element)) {
return canConnect(element.source, element.target, element);
}
if (element.host) {
return canAttach(element, element.host, null, position);
}
return canCreate(element, target, null, position);
});
});