提交 | 用户 | 时间
|
820397
|
1 |
'use strict' |
H |
2 |
|
|
3 |
import { some } from 'min-dash' |
|
4 |
|
|
5 |
// const some = some |
|
6 |
// const some = require('min-dash').some |
|
7 |
|
|
8 |
const ALLOWED_TYPES = { |
|
9 |
FailedJobRetryTimeCycle: [ |
|
10 |
'bpmn:StartEvent', |
|
11 |
'bpmn:BoundaryEvent', |
|
12 |
'bpmn:IntermediateCatchEvent', |
|
13 |
'bpmn:Activity' |
|
14 |
], |
|
15 |
Connector: ['bpmn:EndEvent', 'bpmn:IntermediateThrowEvent'], |
|
16 |
Field: ['bpmn:EndEvent', 'bpmn:IntermediateThrowEvent'] |
|
17 |
} |
|
18 |
|
|
19 |
function is(element, type) { |
|
20 |
return element && typeof element.$instanceOf === 'function' && element.$instanceOf(type) |
|
21 |
} |
|
22 |
|
|
23 |
function exists(element) { |
|
24 |
return element && element.length |
|
25 |
} |
|
26 |
|
|
27 |
function includesType(collection, type) { |
|
28 |
return ( |
|
29 |
exists(collection) && |
|
30 |
some(collection, function (element) { |
|
31 |
return is(element, type) |
|
32 |
}) |
|
33 |
) |
|
34 |
} |
|
35 |
|
|
36 |
function anyType(element, types) { |
|
37 |
return some(types, function (type) { |
|
38 |
return is(element, type) |
|
39 |
}) |
|
40 |
} |
|
41 |
|
|
42 |
function isAllowed(propName, propDescriptor, newElement) { |
|
43 |
const name = propDescriptor.name, |
|
44 |
types = ALLOWED_TYPES[name.replace(/flowable:/, '')] |
|
45 |
|
|
46 |
return name === propName && anyType(newElement, types) |
|
47 |
} |
|
48 |
|
|
49 |
function FlowableModdleExtension(eventBus) { |
|
50 |
eventBus.on( |
|
51 |
'property.clone', |
|
52 |
function (context) { |
|
53 |
const newElement = context.newElement, |
|
54 |
propDescriptor = context.propertyDescriptor |
|
55 |
|
|
56 |
this.canCloneProperty(newElement, propDescriptor) |
|
57 |
}, |
|
58 |
this |
|
59 |
) |
|
60 |
} |
|
61 |
|
|
62 |
FlowableModdleExtension.$inject = ['eventBus'] |
|
63 |
|
|
64 |
FlowableModdleExtension.prototype.canCloneProperty = function (newElement, propDescriptor) { |
|
65 |
if (isAllowed('flowable:FailedJobRetryTimeCycle', propDescriptor, newElement)) { |
|
66 |
return ( |
|
67 |
includesType(newElement.eventDefinitions, 'bpmn:TimerEventDefinition') || |
|
68 |
includesType(newElement.eventDefinitions, 'bpmn:SignalEventDefinition') || |
|
69 |
is(newElement.loopCharacteristics, 'bpmn:MultiInstanceLoopCharacteristics') |
|
70 |
) |
|
71 |
} |
|
72 |
|
|
73 |
if (isAllowed('flowable:Connector', propDescriptor, newElement)) { |
|
74 |
return includesType(newElement.eventDefinitions, 'bpmn:MessageEventDefinition') |
|
75 |
} |
|
76 |
|
|
77 |
if (isAllowed('flowable:Field', propDescriptor, newElement)) { |
|
78 |
return includesType(newElement.eventDefinitions, 'bpmn:MessageEventDefinition') |
|
79 |
} |
|
80 |
} |
|
81 |
|
|
82 |
// module.exports = FlowableModdleExtension; |
|
83 |
export default FlowableModdleExtension |