2018-04-02 19:01:53 +00:00
|
|
|
import {
|
|
|
|
assign
|
|
|
|
} from 'min-dash';
|
2015-08-24 13:31:47 +00:00
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
import {
|
|
|
|
getBpmnJS
|
|
|
|
} from 'test/TestHelper';
|
2015-08-24 13:31:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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]
|
2015-08-24 13:31:47 +00:00
|
|
|
*
|
|
|
|
* @return {Event} event, scoped to the given canvas
|
|
|
|
*/
|
2018-04-02 19:01:53 +00:00
|
|
|
export function createCanvasEvent(position, data) {
|
2015-08-24 13:31:47 +00:00
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
return getBpmnJS().invoke(function(canvas) {
|
2015-08-24 13:31:47 +00:00
|
|
|
|
|
|
|
var target = canvas._svg;
|
|
|
|
|
|
|
|
var clientRect = canvas._container.getBoundingClientRect();
|
|
|
|
|
2015-10-20 08:50:48 +00:00
|
|
|
var absolutePosition = {
|
|
|
|
x: position.x + clientRect.left,
|
|
|
|
y: position.y + clientRect.top
|
|
|
|
};
|
|
|
|
|
|
|
|
return createEvent(target, absolutePosition, data);
|
2015-08-24 13:31:47 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
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}
|
|
|
|
*/
|
2018-04-02 19:01:53 +00:00
|
|
|
export function createEvent(target, position, data) {
|
2015-08-24 13:31:47 +00:00
|
|
|
|
2018-04-02 19:01:53 +00:00
|
|
|
return getBpmnJS().invoke(function(eventBus) {
|
2018-04-02 09:13:39 +00:00
|
|
|
data = assign({
|
|
|
|
target: target,
|
|
|
|
x: position.x,
|
|
|
|
y: position.y,
|
|
|
|
clientX: position.x,
|
|
|
|
clientY: position.y,
|
|
|
|
offsetX: position.x,
|
2020-12-16 15:39:23 +00:00
|
|
|
offsetY: position.y,
|
|
|
|
button: 0
|
2018-04-02 09:13:39 +00:00
|
|
|
}, data || {});
|
|
|
|
|
|
|
|
return eventBus.createEvent(data);
|
|
|
|
});
|
2018-04-02 19:01:53 +00:00
|
|
|
}
|