UNPKG

1.3 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/**
38 * Create an Event
39 *
40 * @param {Element} target
41 * @param { { x: number, y: number } } position
42 * @param {any} [data]
43 *
44 * @return {Event}
45 */
46export function createEvent(target, position, data) {
47
48 return getBpmnJS().invoke(function(eventBus) {
49 data = assign({
50 target: target,
51 x: position.x,
52 y: position.y,
53 clientX: position.x,
54 clientY: position.y,
55 offsetX: position.x,
56 offsetY: position.y,
57 button: 0
58 }, data || {});
59
60 return eventBus.createEvent(data);
61 });
62}
\No newline at end of file