@jylups/cmmn-js 0.0.0-stage → 0.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.babelrc +3 -0
- package/CHANGELOG.md +119 -0
- package/LICENSE +23 -0
- package/README.md +107 -2
- package/dist/assets/cmmn-font/css/cmmn-codes.css +41 -0
- package/dist/assets/cmmn-font/css/cmmn-embedded.css +94 -0
- package/dist/assets/cmmn-font/css/cmmn.css +97 -0
- package/dist/assets/cmmn-font/font/cmmn.eot +0 -0
- package/dist/assets/cmmn-font/font/cmmn.svg +90 -0
- package/dist/assets/cmmn-font/font/cmmn.ttf +0 -0
- package/dist/assets/cmmn-font/font/cmmn.woff +0 -0
- package/dist/assets/cmmn-font/font/cmmn.woff2 +0 -0
- package/dist/assets/diagram-js.css +713 -0
- package/dist/cmmn-modeler.development.js +44817 -0
- package/dist/cmmn-modeler.production.min.js +2 -0
- package/dist/cmmn-navigated-viewer.development.js +18131 -0
- package/dist/cmmn-navigated-viewer.production.min.js +2 -0
- package/dist/cmmn-viewer.development.js +17599 -0
- package/dist/cmmn-viewer.production.min.js +2 -0
- package/index.js +1 -0
- package/lib/Modeler.js +222 -0
- package/lib/NavigatedViewer.js +28 -0
- package/lib/Viewer.js +489 -0
- package/lib/core/ItemRegistry.js +316 -0
- package/lib/core/index.js +7 -0
- package/lib/draw/CmmnRenderer.js +1235 -0
- package/lib/draw/PathMap.js +335 -0
- package/lib/draw/index.js +5 -0
- package/lib/features/auto-resize/CmmnAutoResizeProvider.js +57 -0
- package/lib/features/auto-resize/index.js +7 -0
- package/lib/features/context-pad/ContextPadProvider.js +240 -0
- package/lib/features/context-pad/index.js +11 -0
- package/lib/features/editor-actions/CmmnEditorActions.js +105 -0
- package/lib/features/editor-actions/index.js +10 -0
- package/lib/features/keyboard/CmmnKeyboardBindings.js +159 -0
- package/lib/features/keyboard/index.js +7 -0
- package/lib/features/label-editing/LabelEditingProvider.js +221 -0
- package/lib/features/label-editing/LabelUtil.js +95 -0
- package/lib/features/label-editing/cmd/UpdateLabelHandler.js +63 -0
- package/lib/features/label-editing/index.js +9 -0
- package/lib/features/modeling/CmmnFactory.js +166 -0
- package/lib/features/modeling/CmmnLayouter.js +49 -0
- package/lib/features/modeling/CmmnUpdater.js +511 -0
- package/lib/features/modeling/ElementFactory.js +215 -0
- package/lib/features/modeling/Modeling.js +185 -0
- package/lib/features/modeling/behavior/AttachCriterionBehavior.js +58 -0
- package/lib/features/modeling/behavior/CaseFileItemUpdater.js +324 -0
- package/lib/features/modeling/behavior/LabelBehavior.js +139 -0
- package/lib/features/modeling/behavior/PlanItemDefinitionUpdater.js +449 -0
- package/lib/features/modeling/behavior/PlanningTableUpdater.js +620 -0
- package/lib/features/modeling/behavior/ReplaceConnectionBehavior.js +320 -0
- package/lib/features/modeling/behavior/ReplaceElementBehavior.js +395 -0
- package/lib/features/modeling/behavior/ResizeCasePlanModelBehavior.js +108 -0
- package/lib/features/modeling/behavior/SentryUpdater.js +678 -0
- package/lib/features/modeling/behavior/UnclaimIdBehavior.js +28 -0
- package/lib/features/modeling/behavior/index.js +24 -0
- package/lib/features/modeling/cmd/AppendShapeHandler.js +52 -0
- package/lib/features/modeling/cmd/IdClaimHandler.js +38 -0
- package/lib/features/modeling/cmd/ReconnectConnectionHandler.js +57 -0
- package/lib/features/modeling/cmd/ReplaceShapeHandler.js +46 -0
- package/lib/features/modeling/cmd/UpdateControlsHandler.js +221 -0
- package/lib/features/modeling/cmd/UpdatePropertiesHandler.js +240 -0
- package/lib/features/modeling/cmd/UpdateSemanticParentHandler.js +94 -0
- package/lib/features/modeling/index.js +20 -0
- package/lib/features/modeling/util/ModelingUtil.js +138 -0
- package/lib/features/modeling/util/PlanItemDefinitionUtil.js +183 -0
- package/lib/features/ordering/CmmnOrderingProvider.js +146 -0
- package/lib/features/ordering/index.js +4 -0
- package/lib/features/outline/Outline.js +47 -0
- package/lib/features/outline/index.js +6 -0
- package/lib/features/palette/PaletteProvider.js +171 -0
- package/lib/features/palette/index.js +12 -0
- package/lib/features/popup-menu/ReplaceMenuProvider.js +448 -0
- package/lib/features/popup-menu/index.js +4 -0
- package/lib/features/replace/CmmnReplace.js +355 -0
- package/lib/features/replace/ReplaceOptions.js +241 -0
- package/lib/features/replace/index.js +8 -0
- package/lib/features/replace-preview/CmmnReplacePreview.js +247 -0
- package/lib/features/replace-preview/index.js +7 -0
- package/lib/features/rules/CmmnRules.js +1040 -0
- package/lib/features/rules/index.js +7 -0
- package/lib/features/search/CmmnSearchProvider.js +129 -0
- package/lib/features/search/index.js +7 -0
- package/lib/features/snapping/CmmnConnectSnapping.js +110 -0
- package/lib/features/snapping/CmmnCreateMoveSnapping.js +148 -0
- package/lib/features/snapping/CmmnResizeSnapping.js +42 -0
- package/lib/features/snapping/CmmnSnappingUtil.js +76 -0
- package/lib/features/snapping/index.js +17 -0
- package/lib/import/CmmnImporter.js +251 -0
- package/lib/import/CmmnTreeWalker.js +410 -0
- package/lib/import/Importer.js +73 -0
- package/lib/import/Util.js +9 -0
- package/lib/import/index.js +3 -0
- package/lib/util/DiUtil.js +39 -0
- package/lib/util/LabelUtil.js +124 -0
- package/lib/util/ModelUtil.js +257 -0
- package/lib/util/PoweredByUtil.js +91 -0
- package/package.json +88 -4
- package/test/helper/index.js +231 -0
- package/test/util/KeyEvents.js +23 -0
- package/test/util/MockEvents.js +55 -0
- package/test/util/custom-rules/CustomRules.js +19 -0
- package/test/util/custom-rules/index.js +4 -0
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var map = require('min-dash').map,
|
|
4
|
+
filter = require('min-dash').filter,
|
|
5
|
+
sortBy = require('min-dash').sortBy;
|
|
6
|
+
|
|
7
|
+
var labelUtil = require('../label-editing/LabelUtil');
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Provides ability to search through CMMN elements
|
|
12
|
+
*/
|
|
13
|
+
function CmmnSearchProvider(elementRegistry, searchPad, canvas) {
|
|
14
|
+
|
|
15
|
+
this._elementRegistry = elementRegistry;
|
|
16
|
+
this._canvas = canvas;
|
|
17
|
+
|
|
18
|
+
searchPad.registerProvider(this);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
module.exports = CmmnSearchProvider;
|
|
22
|
+
|
|
23
|
+
CmmnSearchProvider.$inject = [
|
|
24
|
+
'elementRegistry',
|
|
25
|
+
'searchPad',
|
|
26
|
+
'canvas'
|
|
27
|
+
];
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Finds all elements that match given pattern
|
|
32
|
+
*
|
|
33
|
+
* <Result> :
|
|
34
|
+
* {
|
|
35
|
+
* primaryTokens: <Array<Token>>,
|
|
36
|
+
* secondaryTokens: <Array<Token>>,
|
|
37
|
+
* element: <Element>
|
|
38
|
+
* }
|
|
39
|
+
*
|
|
40
|
+
* <Token> :
|
|
41
|
+
* {
|
|
42
|
+
* normal|matched: <String>
|
|
43
|
+
* }
|
|
44
|
+
*
|
|
45
|
+
* @param {String} pattern
|
|
46
|
+
* @return {Array<Result>}
|
|
47
|
+
*/
|
|
48
|
+
CmmnSearchProvider.prototype.find = function(pattern) {
|
|
49
|
+
var rootElement = this._canvas.getRootElement();
|
|
50
|
+
|
|
51
|
+
var elements = this._elementRegistry.filter(function(element) {
|
|
52
|
+
if (element.labelTarget) {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
return true;
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
// do not include root element
|
|
59
|
+
elements = filter(elements, function(element) {
|
|
60
|
+
return element !== rootElement;
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
elements = map(elements, function(element) {
|
|
64
|
+
return {
|
|
65
|
+
primaryTokens: matchAndSplit(labelUtil.getLabel(element), pattern),
|
|
66
|
+
secondaryTokens: matchAndSplit(element.id, pattern),
|
|
67
|
+
element: element
|
|
68
|
+
};
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
// exclude non-matched elements
|
|
72
|
+
elements = filter(elements, function(element) {
|
|
73
|
+
return hasMatched(element.primaryTokens) || hasMatched(element.secondaryTokens);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
elements = sortBy(elements, function(element) {
|
|
77
|
+
return labelUtil.getLabel(element.element) + element.element.id;
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
return elements;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
function hasMatched(tokens) {
|
|
85
|
+
var matched = filter(tokens, function(t) {
|
|
86
|
+
return !!t.matched;
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
return matched.length > 0;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
function matchAndSplit(text, pattern) {
|
|
94
|
+
var tokens = [],
|
|
95
|
+
originalText = text;
|
|
96
|
+
|
|
97
|
+
if (!text) {
|
|
98
|
+
return tokens;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
text = text.toLowerCase();
|
|
102
|
+
pattern = pattern.toLowerCase();
|
|
103
|
+
|
|
104
|
+
var i = text.indexOf(pattern);
|
|
105
|
+
|
|
106
|
+
if (i > -1) {
|
|
107
|
+
if (i !== 0) {
|
|
108
|
+
tokens.push({
|
|
109
|
+
normal: originalText.substr(0, i)
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
tokens.push({
|
|
114
|
+
matched: originalText.substr(i, pattern.length)
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
if (pattern.length + i < text.length) {
|
|
118
|
+
tokens.push({
|
|
119
|
+
normal: originalText.substr(pattern.length + i, text.length)
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
} else {
|
|
123
|
+
tokens.push({
|
|
124
|
+
normal: originalText
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return tokens;
|
|
129
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
var SnapUtil = require('diagram-js/lib/features/snapping/SnapUtil'),
|
|
2
|
+
mid =SnapUtil.mid,
|
|
3
|
+
setSnapped = SnapUtil.setSnapped;
|
|
4
|
+
|
|
5
|
+
var isCmd = require('diagram-js/lib/features/keyboard/KeyboardUtil').isCmd;
|
|
6
|
+
|
|
7
|
+
var ModelUtil = require('../../util/ModelUtil'),
|
|
8
|
+
is = ModelUtil.is,
|
|
9
|
+
getDefinition = ModelUtil.getDefinition,
|
|
10
|
+
getBusinessObject = ModelUtil.getBusinessObject;
|
|
11
|
+
|
|
12
|
+
var HIGHER_PRIORITY = 1250;
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Snap during connect.
|
|
17
|
+
*
|
|
18
|
+
* @param {EventBus} eventBus
|
|
19
|
+
* @param {Rules} rules
|
|
20
|
+
*/
|
|
21
|
+
function CmmnConnectSnapping(eventBus, rules) {
|
|
22
|
+
eventBus.on([
|
|
23
|
+
'connect.hover',
|
|
24
|
+
'connect.move',
|
|
25
|
+
'connect.end',
|
|
26
|
+
], HIGHER_PRIORITY, function(event) {
|
|
27
|
+
var context = event.context,
|
|
28
|
+
source = context.source,
|
|
29
|
+
target = context.target,
|
|
30
|
+
canExecute = context.canExecute;
|
|
31
|
+
|
|
32
|
+
if (!canExecute) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (event.originalEvent && isCmd(event.originalEvent)) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (!context.initialSourcePosition) {
|
|
41
|
+
context.initialSourcePosition = context.sourcePosition;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
var connectionAttrs = rules.allowed('connection.create', {
|
|
45
|
+
source: source,
|
|
46
|
+
target: target
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
if (connectionAttrs && isCenterSnapTarget(source)) {
|
|
50
|
+
// snap source
|
|
51
|
+
context.sourcePosition = mid(source);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (connectionAttrs && isCenterSnapTarget(target)) {
|
|
55
|
+
|
|
56
|
+
// snap target
|
|
57
|
+
snapToPosition(event, mid(target));
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
CmmnConnectSnapping.$inject = [
|
|
63
|
+
'eventBus',
|
|
64
|
+
'rules'
|
|
65
|
+
];
|
|
66
|
+
|
|
67
|
+
module.exports = CmmnConnectSnapping;
|
|
68
|
+
|
|
69
|
+
// helpers //////////
|
|
70
|
+
|
|
71
|
+
function snapToPosition(event, position) {
|
|
72
|
+
setSnapped(event, 'x', position.x);
|
|
73
|
+
setSnapped(event, 'y', position.y);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Returns true if element should be center snapped when
|
|
78
|
+
* creating a connection.
|
|
79
|
+
*
|
|
80
|
+
* This applies to all collapsed and non container elements.
|
|
81
|
+
*
|
|
82
|
+
* @param {djs.model.Base} element
|
|
83
|
+
*
|
|
84
|
+
* @return {Boolean}
|
|
85
|
+
*/
|
|
86
|
+
function isCenterSnapTarget(element) {
|
|
87
|
+
|
|
88
|
+
if (!element) {
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (is(element, 'cmmn:Stage')) {
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
var bo = getBusinessObject(element);
|
|
97
|
+
var definition = getDefinition(element) || element;
|
|
98
|
+
|
|
99
|
+
if (!is(definition, 'cmmn:PlanFragment')) {
|
|
100
|
+
return true;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
var di = bo.di;
|
|
104
|
+
|
|
105
|
+
if (di && di.isCollapsed === true) {
|
|
106
|
+
return true;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return false;
|
|
110
|
+
}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var inherits = require('inherits');
|
|
4
|
+
|
|
5
|
+
var SnapUtil = require('diagram-js/lib/features/snapping/SnapUtil');
|
|
6
|
+
|
|
7
|
+
var CreateMoveSnapping = require('diagram-js/lib/features/snapping/CreateMoveSnapping').default;
|
|
8
|
+
|
|
9
|
+
var isSnapped = SnapUtil.isSnapped,
|
|
10
|
+
setSnapped = SnapUtil.setSnapped;
|
|
11
|
+
|
|
12
|
+
var asTRBL = require('diagram-js/lib/layout/LayoutUtil').asTRBL,
|
|
13
|
+
getMid = require('diagram-js/lib/layout/LayoutUtil').getMid;
|
|
14
|
+
|
|
15
|
+
var getCriterionAttachment = require('./CmmnSnappingUtil').getCriterionAttachment;
|
|
16
|
+
|
|
17
|
+
var forEach = require('min-dash').forEach;
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Cmmn specific create move snapping functionality
|
|
22
|
+
*
|
|
23
|
+
* @param {EventBus} eventBus
|
|
24
|
+
* @param {CmmnRules} cmmnRules
|
|
25
|
+
*/
|
|
26
|
+
function CmmnCreateMoveSnapping(eventBus, cmmnRules, injector) {
|
|
27
|
+
|
|
28
|
+
injector.invoke(CreateMoveSnapping, this);
|
|
29
|
+
|
|
30
|
+
function canAttach(shape, target, position) {
|
|
31
|
+
return cmmnRules.canAttach([ shape ], target, null, position) === 'attach';
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
eventBus.on([
|
|
35
|
+
'create.move',
|
|
36
|
+
'create.end',
|
|
37
|
+
'shape.move.move',
|
|
38
|
+
'shape.move.end'
|
|
39
|
+
], 1500, function(event) {
|
|
40
|
+
|
|
41
|
+
var context = event.context,
|
|
42
|
+
target = context.target,
|
|
43
|
+
shape = context.shape;
|
|
44
|
+
|
|
45
|
+
if (target && !isSnapped(event) && canAttach(shape, target, event)) {
|
|
46
|
+
snapCriterion(event, shape, target);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
function snapCriterion(event, shape, target) {
|
|
52
|
+
var targetTRBL = asTRBL(target);
|
|
53
|
+
|
|
54
|
+
var direction = getCriterionAttachment(event, target);
|
|
55
|
+
|
|
56
|
+
if (/top/.test(direction)) {
|
|
57
|
+
setSnapped(event, 'y', targetTRBL.top);
|
|
58
|
+
} else
|
|
59
|
+
if (/bottom/.test(direction)) {
|
|
60
|
+
setSnapped(event, 'y', targetTRBL.bottom);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (/left/.test(direction)) {
|
|
64
|
+
setSnapped(event, 'x', targetTRBL.left);
|
|
65
|
+
} else
|
|
66
|
+
if (/right/.test(direction)) {
|
|
67
|
+
setSnapped(event, 'x', targetTRBL.right);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
inherits(CmmnCreateMoveSnapping, CreateMoveSnapping);
|
|
73
|
+
|
|
74
|
+
CmmnCreateMoveSnapping.$inject = [ 'eventBus', 'cmmnRules', 'injector' ];
|
|
75
|
+
|
|
76
|
+
module.exports = CmmnCreateMoveSnapping;
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
CmmnCreateMoveSnapping.prototype.initSnap = function(event) {
|
|
80
|
+
var snapContext = CreateMoveSnapping.prototype.initSnap.call(this, event);
|
|
81
|
+
|
|
82
|
+
var shape = event.shape;
|
|
83
|
+
|
|
84
|
+
// snap to docking points
|
|
85
|
+
forEach(shape.outgoing, function(connection) {
|
|
86
|
+
var docking = connection.waypoints[0];
|
|
87
|
+
|
|
88
|
+
docking = docking.original || docking;
|
|
89
|
+
|
|
90
|
+
snapContext.setSnapOrigin(connection.id + '-docking', {
|
|
91
|
+
x: docking.x - event.x,
|
|
92
|
+
y: docking.y - event.y
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
forEach(shape.incoming, function(connection) {
|
|
97
|
+
var docking = connection.waypoints[connection.waypoints.length - 1];
|
|
98
|
+
|
|
99
|
+
docking = docking.original || docking;
|
|
100
|
+
|
|
101
|
+
snapContext.setSnapOrigin(connection.id + '-docking', {
|
|
102
|
+
x: docking.x - event.x,
|
|
103
|
+
y: docking.y - event.y
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
return snapContext;
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
CmmnCreateMoveSnapping.prototype.addSnapTargetPoints = function(snapPoints, shape, target) {
|
|
112
|
+
CreateMoveSnapping.prototype.addSnapTargetPoints.call(this, snapPoints, shape, target);
|
|
113
|
+
|
|
114
|
+
var snapTargets = this.getSnapTargets(shape, target);
|
|
115
|
+
|
|
116
|
+
// snap to docking points
|
|
117
|
+
forEach(shape.incoming, function(connection) {
|
|
118
|
+
|
|
119
|
+
if (!includes(snapTargets, connection.source)) {
|
|
120
|
+
snapPoints.add('mid', getMid(connection.source));
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
var docking = connection.waypoints[0];
|
|
124
|
+
|
|
125
|
+
snapPoints.add(connection.id + '-docking', docking.original || docking);
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
forEach(shape.outgoing, function(connection) {
|
|
130
|
+
|
|
131
|
+
if (!includes(snapTargets, connection.target)) {
|
|
132
|
+
snapPoints.add('mid', getMid(connection.target));
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
var docking = connection.waypoints[ connection.waypoints.length - 1 ];
|
|
136
|
+
|
|
137
|
+
snapPoints.add(connection.id + '-docking', docking.original || docking);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
return snapPoints;
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
// helpers ////////////////////
|
|
145
|
+
|
|
146
|
+
function includes(array, value) {
|
|
147
|
+
return array.indexOf(value) !== -1;
|
|
148
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var is = require('../../util/ModelUtil').is,
|
|
4
|
+
getDefinition = require('../../util/ModelUtil').getDefinition,
|
|
5
|
+
isCollapsed = require('../../util/DiUtil').isCollapsed;
|
|
6
|
+
|
|
7
|
+
var SLIGHTLY_HIGHER_PRIORITY = 1001;
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Cmmn specific resize snapping functionality
|
|
12
|
+
*
|
|
13
|
+
* @param {EventBus} eventBus
|
|
14
|
+
* @param {CmmnRules} cmmnRules
|
|
15
|
+
*/
|
|
16
|
+
function CmmnResizeSnapping(eventBus) {
|
|
17
|
+
|
|
18
|
+
eventBus.on('resize.start', SLIGHTLY_HIGHER_PRIORITY + 500, function(event) {
|
|
19
|
+
var context = event.context,
|
|
20
|
+
shape = context.shape;
|
|
21
|
+
|
|
22
|
+
if (isStage(shape) && !isCollapsed(shape)) {
|
|
23
|
+
context.minDimensions = { width: 140, height: 120 };
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (is(shape, 'cmmn:TextAnnotation')) {
|
|
27
|
+
context.minDimensions = { width: 50, height: 30 };
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
CmmnResizeSnapping.$inject = [ 'eventBus', 'cmmnRules', 'injector' ];
|
|
35
|
+
|
|
36
|
+
module.exports = CmmnResizeSnapping;
|
|
37
|
+
|
|
38
|
+
// helpers //////////
|
|
39
|
+
|
|
40
|
+
function isStage(element) {
|
|
41
|
+
return is(getDefinition(element), 'cmmn:PlanFragment');
|
|
42
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var getOrientation = require('diagram-js/lib/layout/LayoutUtil').getOrientation;
|
|
4
|
+
|
|
5
|
+
var is = require('../../util/ModelUtil').is,
|
|
6
|
+
getDefinition = require('../../util/ModelUtil').getDefinition;
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Get orientation of the given position rectangle in relation to the
|
|
11
|
+
* given target rectangle. When the position is near a corner (respecting
|
|
12
|
+
* the given offet) the string 'corner' is returned.
|
|
13
|
+
*
|
|
14
|
+
* A padding (positive or negative) may be passed to influence
|
|
15
|
+
* horizontal / vertical orientation and intersection.
|
|
16
|
+
*
|
|
17
|
+
* @param {Bounds} position
|
|
18
|
+
* @param {Bounds} target
|
|
19
|
+
* @param {Point|Number} padding
|
|
20
|
+
* @param {Number} offset
|
|
21
|
+
*/
|
|
22
|
+
function getCornerlessOrientation(position, target, padding, offset) {
|
|
23
|
+
|
|
24
|
+
// don't snap to top left corner
|
|
25
|
+
if (position.x - offset < target.x &&
|
|
26
|
+
position.y - offset < target.y) {
|
|
27
|
+
return 'corner';
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// don't snap to top right corner
|
|
31
|
+
if (position.x + offset > target.x + target.width &&
|
|
32
|
+
position.y - offset < target.y) {
|
|
33
|
+
return 'corner';
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// don't snap to bottom left corner
|
|
37
|
+
if (position.x - offset < target.x &&
|
|
38
|
+
position.y + offset > target.y + target.height) {
|
|
39
|
+
return 'corner';
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// don't snap to bottom right corner
|
|
43
|
+
if (position.x + offset > target.x + target.width &&
|
|
44
|
+
position.y + offset > target.y + target.height) {
|
|
45
|
+
return 'corner';
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return getOrientation(position, target, padding);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
function getCriterionAttachment(position, target) {
|
|
53
|
+
|
|
54
|
+
var orientation;
|
|
55
|
+
|
|
56
|
+
var definition = getDefinition(target);
|
|
57
|
+
|
|
58
|
+
if (is(target, 'cmmn:PlanItem') && is(definition, 'cmmn:Stage')) {
|
|
59
|
+
orientation = getCornerlessOrientation(position, target, -15, 20);
|
|
60
|
+
|
|
61
|
+
} else
|
|
62
|
+
if (is(definition, 'cmmn:Milestone')) {
|
|
63
|
+
orientation = getCornerlessOrientation(position, target, -3, 7);
|
|
64
|
+
|
|
65
|
+
} else {
|
|
66
|
+
orientation = getOrientation(position, target, -15);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (orientation !== 'intersect') {
|
|
70
|
+
return orientation;
|
|
71
|
+
} else {
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
module.exports.getCriterionAttachment = getCriterionAttachment;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
var CmmnConnectSnapping = require('./CmmnConnectSnapping');
|
|
2
|
+
var CmmnCreateMoveSnapping = require('./CmmnCreateMoveSnapping');
|
|
3
|
+
var CmmnResizeSnapping = require('./CmmnResizeSnapping');
|
|
4
|
+
var SnappingModule = require('diagram-js/lib/features/snapping').default;
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
module.exports = {
|
|
8
|
+
__depends__: [ SnappingModule ],
|
|
9
|
+
__init__: [
|
|
10
|
+
'connectSnapping',
|
|
11
|
+
'createMoveSnapping',
|
|
12
|
+
'resizeSnapping'
|
|
13
|
+
],
|
|
14
|
+
connectSnapping: [ 'type', CmmnConnectSnapping ],
|
|
15
|
+
createMoveSnapping: [ 'type', CmmnCreateMoveSnapping],
|
|
16
|
+
resizeSnapping: [ 'type', CmmnResizeSnapping ]
|
|
17
|
+
};
|