bpmn-js/test/util/MockEvents.js

62 lines
1.3 KiB
JavaScript
Raw Permalink Normal View History

import {
assign
} from 'min-dash';
import {
getBpmnJS
} from 'test/TestHelper';
/**
* Create an event with global coordinates
* computed based on the loaded diagrams canvas position and the
* specified canvas local coordinates.
*
* @param {Point} point of the event local the canvas (closure)
2021-10-20 07:58:07 +00:00
* @param {Object} [data]
*
* @return {Event} event, scoped to the given canvas
*/
export function createCanvasEvent(position, data) {
return getBpmnJS().invoke(function(canvas) {
var target = canvas._svg;
var clientRect = canvas._container.getBoundingClientRect();
var absolutePosition = {
x: position.x + clientRect.left,
y: position.y + clientRect.top
};
return createEvent(target, absolutePosition, data);
});
}
2021-10-20 07:58:07 +00:00
/**
* Create an Event
*
* @param {Element} target
* @param { { x: number, y: number } } position
* @param {any} [data]
*
* @return {Event}
*/
export function createEvent(target, position, data) {
return getBpmnJS().invoke(function(eventBus) {
data = assign({
target: target,
x: position.x,
y: position.y,
clientX: position.x,
clientY: position.y,
offsetX: position.x,
offsetY: position.y,
button: 0
}, data || {});
return eventBus.createEvent(data);
});
}