forked from bpmn-io/bpmn-js-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MagicPropertiesProvider.js
72 lines (56 loc) · 1.68 KB
/
MagicPropertiesProvider.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Import your custom property entries.
// The entry is a text input field with logic attached to create,
// update and delete the "spell" property.
import spellProps from './parts/SpellProps';
import { is } from 'bpmn-js/lib/util/ModelUtil';
const LOW_PRIORITY = 500;
/**
* A provider with a `#getGroups(element)` method
* that exposes groups for a diagram element.
*
* @param {PropertiesPanel} propertiesPanel
* @param {Function} translate
*/
export default function MagicPropertiesProvider(propertiesPanel, translate) {
// API ////////
/**
* Return the groups provided for the given element.
*
* @param {DiagramElement} element
*
* @return {(Object[]) => (Object[])} groups middleware
*/
this.getGroups = function(element) {
/**
* We return a middleware that modifies
* the existing groups.
*
* @param {Object[]} groups
*
* @return {Object[]} modified groups
*/
return function(groups) {
// Add the "magic" group
if(is(element, 'bpmn:StartEvent')) {
groups.push(createMagicGroup(element, translate));
}
return groups;
}
};
// registration ////////
// Register our custom magic properties provider.
// Use a lower priority to ensure it is loaded after
// the basic BPMN properties.
propertiesPanel.registerProvider(LOW_PRIORITY, this);
}
MagicPropertiesProvider.$inject = [ 'propertiesPanel', 'translate' ];
// Create the custom magic group
function createMagicGroup(element, translate) {
// create a group called "Magic properties".
const magicGroup = {
id: 'magic',
label: translate('Magic properties'),
entries: spellProps(element)
};
return magicGroup
}