forked from PlanQK/workflow-modeler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEditorEventHandler.js
50 lines (46 loc) · 1.77 KB
/
EditorEventHandler.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/**
* Event handler used to trigger custom HTML events if the workflow of the modeler changes.
*/
// ref to the current quantum workflow modeler
let modelerComponent;
/**
* Initialize the event handler by defining the modeler component.
*
* @param newModelerComponent The quantum workflow modeler component.
*/
export function initEditorEventHandler(newModelerComponent) {
modelerComponent = newModelerComponent;
}
/**
* Trigger new workflow event as custom HTML event, dispatched via the quantum workflow modeler component.
*
* @param type The type of the event, one of the workflowEventTypes
* @param workflowXml The workflow diagram as xml string the current event is triggered for.
* @param workflowName The name of the workflow diagram the current event is triggered for.
* @returns {*} Boolean, true if either event's cancelable attribute value is false or its preventDefault() method was
* not invoked, and false otherwise.
*/
export function dispatchWorkflowEvent(type, workflowXml, workflowName) {
const newEvent = new CustomEvent(type, {
detail: {
workflowName: workflowName,
workflow: workflowXml,
},
cancelable: true,
});
return modelerComponent?.dispatchEvent?.(newEvent) ?? true;
}
/**
* Add event listener for the custom HTML event of the given type. The listener is added to the current quantum workflow
* modeler component and calls the given callback function when the event is fired.
*
* @param type The type of the event, one of the workflowEventTypes
* @param callBckFunction The function defining the action executed when the event occurs
*/
export function addWorkflowEventListener(type, callBckFunction) {
modelerComponent.addEventListener(
type,
(event) => callBckFunction(event),
false
);
}