UNPKG

1.13 kBJavaScriptView Raw
1import {
2 assign
3} from 'min-dash';
4
5import {
6 getBpmnJS
7} from 'test/TestHelper';
8
9
10/**
11 * Create an event with global coordinates
12 * computed based on the loaded diagrams canvas position and the
13 * specified canvas local coordinates.
14 *
15 * @param {Point} point of the event local the canvas (closure)
16 * @param {Object} data
17 *
18 * @return {Event} event, scoped to the given canvas
19 */
20export function createCanvasEvent(position, data) {
21
22 return getBpmnJS().invoke(function(canvas) {
23
24 var target = canvas._svg;
25
26 var clientRect = canvas._container.getBoundingClientRect();
27
28 var absolutePosition = {
29 x: position.x + clientRect.left,
30 y: position.y + clientRect.top
31 };
32
33 return createEvent(target, absolutePosition, data);
34 });
35}
36
37
38export function createEvent(target, position, data) {
39
40 return getBpmnJS().invoke(function(eventBus) {
41 data = assign({
42 target: target,
43 x: position.x,
44 y: position.y,
45 clientX: position.x,
46 clientY: position.y,
47 offsetX: position.x,
48 offsetY: position.y
49 }, data || {});
50
51 return eventBus.createEvent(data);
52 });
53}
\No newline at end of file