@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,105 @@
|
|
|
1
|
+
var inherits = require('inherits');
|
|
2
|
+
|
|
3
|
+
var EditorActions = require('diagram-js/lib/features/editor-actions/EditorActions').default;
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Registers and executes CMMN specific editor actions.
|
|
8
|
+
*
|
|
9
|
+
* @param {Injector} injector
|
|
10
|
+
*/
|
|
11
|
+
function CmmnEditorActions(injector) {
|
|
12
|
+
injector.invoke(EditorActions, this);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
inherits(CmmnEditorActions, EditorActions);
|
|
16
|
+
|
|
17
|
+
CmmnEditorActions.$inject = [
|
|
18
|
+
'injector'
|
|
19
|
+
];
|
|
20
|
+
|
|
21
|
+
module.exports = CmmnEditorActions;
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Register default actions.
|
|
26
|
+
*
|
|
27
|
+
* @param {Injector} injector
|
|
28
|
+
*/
|
|
29
|
+
CmmnEditorActions.prototype._registerDefaultActions = function(injector) {
|
|
30
|
+
|
|
31
|
+
// (0) invoke super method
|
|
32
|
+
|
|
33
|
+
EditorActions.prototype._registerDefaultActions.call(this, injector);
|
|
34
|
+
|
|
35
|
+
// (1) retrieve optional components to integrate with
|
|
36
|
+
|
|
37
|
+
var canvas = injector.get('canvas', false);
|
|
38
|
+
var elementRegistry = injector.get('elementRegistry', false);
|
|
39
|
+
var selection = injector.get('selection', false);
|
|
40
|
+
var spaceTool = injector.get('spaceTool', false);
|
|
41
|
+
var lassoTool = injector.get('lassoTool', false);
|
|
42
|
+
var handTool = injector.get('handTool', false);
|
|
43
|
+
var globalConnect = injector.get('globalConnect', false);
|
|
44
|
+
var directEditing = injector.get('directEditing', false);
|
|
45
|
+
var searchPad = injector.get('searchPad', false);
|
|
46
|
+
|
|
47
|
+
// (2) check components and register actions
|
|
48
|
+
|
|
49
|
+
if (canvas && elementRegistry && selection) {
|
|
50
|
+
this._registerAction('selectElements', function() {
|
|
51
|
+
// select all elements except for the invisible
|
|
52
|
+
// root element
|
|
53
|
+
var rootElement = canvas.getRootElement();
|
|
54
|
+
|
|
55
|
+
var elements = elementRegistry.filter(function(element) {
|
|
56
|
+
return element !== rootElement;
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
selection.select(elements);
|
|
60
|
+
|
|
61
|
+
return elements;
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (spaceTool) {
|
|
66
|
+
this._registerAction('spaceTool', function() {
|
|
67
|
+
spaceTool.toggle();
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (lassoTool) {
|
|
72
|
+
this._registerAction('lassoTool', function() {
|
|
73
|
+
lassoTool.toggle();
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (handTool) {
|
|
78
|
+
this._registerAction('handTool', function() {
|
|
79
|
+
handTool.toggle();
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (globalConnect) {
|
|
84
|
+
this._registerAction('globalConnectTool', function() {
|
|
85
|
+
globalConnect.toggle();
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (selection && directEditing) {
|
|
90
|
+
this._registerAction('directEditing', function() {
|
|
91
|
+
var currentSelection = selection.get();
|
|
92
|
+
|
|
93
|
+
if (currentSelection.length) {
|
|
94
|
+
directEditing.activate(currentSelection[0]);
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (searchPad) {
|
|
100
|
+
this._registerAction('find', function() {
|
|
101
|
+
searchPad.toggle();
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
var EditorActionsModule = require('diagram-js/lib/features/editor-actions').default;
|
|
2
|
+
|
|
3
|
+
var CmmnEditorActions = require('./CmmnEditorActions');
|
|
4
|
+
|
|
5
|
+
module.exports = {
|
|
6
|
+
__depends__: [
|
|
7
|
+
EditorActionsModule
|
|
8
|
+
],
|
|
9
|
+
editorActions: [ 'type', CmmnEditorActions ]
|
|
10
|
+
};
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
var inherits = require('inherits');
|
|
2
|
+
|
|
3
|
+
var KeyboardBindings = require('diagram-js/lib/features/keyboard/KeyboardBindings').default;
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* CMMN specific keyboard bindings.
|
|
8
|
+
*
|
|
9
|
+
* @param {Injector} injector
|
|
10
|
+
*/
|
|
11
|
+
function CmmnKeyboardBindings(injector) {
|
|
12
|
+
injector.invoke(KeyboardBindings, this);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
inherits(CmmnKeyboardBindings, KeyboardBindings);
|
|
16
|
+
|
|
17
|
+
CmmnKeyboardBindings.$inject = [
|
|
18
|
+
'injector'
|
|
19
|
+
];
|
|
20
|
+
|
|
21
|
+
module.exports = CmmnKeyboardBindings;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Register available keyboard bindings.
|
|
25
|
+
*
|
|
26
|
+
* @param {Keyboard} keyboard
|
|
27
|
+
* @param {EditorActions} editorActions
|
|
28
|
+
*/
|
|
29
|
+
CmmnKeyboardBindings.prototype.registerBindings = function(keyboard, editorActions) {
|
|
30
|
+
|
|
31
|
+
// inherit default bindings
|
|
32
|
+
KeyboardBindings.prototype.registerBindings.call(this, keyboard, editorActions);
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Add keyboard binding if respective editor action
|
|
36
|
+
* is registered.
|
|
37
|
+
*
|
|
38
|
+
* @param {String} action name
|
|
39
|
+
* @param {Function} fn that implements the key binding
|
|
40
|
+
*/
|
|
41
|
+
function addListener(action, fn) {
|
|
42
|
+
|
|
43
|
+
if (editorActions.isRegistered(action)) {
|
|
44
|
+
keyboard.addListener(fn);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// select all elements
|
|
49
|
+
// CTRL + A
|
|
50
|
+
addListener('selectElements', function(context) {
|
|
51
|
+
|
|
52
|
+
var event = context.keyEvent;
|
|
53
|
+
|
|
54
|
+
if (keyboard.isKey(['a', 'A'], event) && keyboard.isCmd(event)) {
|
|
55
|
+
editorActions.trigger('selectElements');
|
|
56
|
+
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
// search labels
|
|
62
|
+
// CTRL + F
|
|
63
|
+
addListener('find', function(context) {
|
|
64
|
+
|
|
65
|
+
var event = context.keyEvent;
|
|
66
|
+
|
|
67
|
+
if (keyboard.isKey(['f', 'F'], event) && keyboard.isCmd(event)) {
|
|
68
|
+
editorActions.trigger('find');
|
|
69
|
+
|
|
70
|
+
return true;
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
// activate space tool
|
|
75
|
+
// S
|
|
76
|
+
addListener('spaceTool', function(context) {
|
|
77
|
+
|
|
78
|
+
var event = context.keyEvent;
|
|
79
|
+
|
|
80
|
+
if (keyboard.hasModifier(event)) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (keyboard.isKey(['s', 'S'], event)) {
|
|
85
|
+
editorActions.trigger('spaceTool');
|
|
86
|
+
|
|
87
|
+
return true;
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
// activate lasso tool
|
|
92
|
+
// L
|
|
93
|
+
addListener('lassoTool', function(context) {
|
|
94
|
+
|
|
95
|
+
var event = context.keyEvent;
|
|
96
|
+
|
|
97
|
+
if (keyboard.hasModifier(event)) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (keyboard.isKey(['l', 'L'], event)) {
|
|
102
|
+
editorActions.trigger('lassoTool');
|
|
103
|
+
|
|
104
|
+
return true;
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
// activate hand tool
|
|
109
|
+
// H
|
|
110
|
+
addListener('handTool', function(context) {
|
|
111
|
+
|
|
112
|
+
var event = context.keyEvent;
|
|
113
|
+
|
|
114
|
+
if (keyboard.hasModifier(event)) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if (keyboard.isKey(['h', 'H'], event)) {
|
|
119
|
+
editorActions.trigger('handTool');
|
|
120
|
+
|
|
121
|
+
return true;
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
// activate global connect tool
|
|
126
|
+
// C
|
|
127
|
+
addListener('globalConnectTool', function(context) {
|
|
128
|
+
|
|
129
|
+
var event = context.keyEvent;
|
|
130
|
+
|
|
131
|
+
if (keyboard.hasModifier(event)) {
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
if (keyboard.isKey(['c', 'C'], event)) {
|
|
136
|
+
editorActions.trigger('globalConnectTool');
|
|
137
|
+
|
|
138
|
+
return true;
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
// activate direct editing
|
|
143
|
+
// E
|
|
144
|
+
addListener('directEditing', function(context) {
|
|
145
|
+
|
|
146
|
+
var event = context.keyEvent;
|
|
147
|
+
|
|
148
|
+
if (keyboard.hasModifier(event)) {
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
if (keyboard.isKey(['e', 'E'], event)) {
|
|
153
|
+
editorActions.trigger('directEditing');
|
|
154
|
+
|
|
155
|
+
return true;
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
};
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var UpdateLabelHandler = require('./cmd/UpdateLabelHandler');
|
|
4
|
+
|
|
5
|
+
var LabelUtil = require('./LabelUtil');
|
|
6
|
+
|
|
7
|
+
var isCasePlanModel = require('../../util/ModelUtil').isCasePlanModel,
|
|
8
|
+
is = require('../../util/ModelUtil').is,
|
|
9
|
+
getDefinition = require('../../util/ModelUtil').getDefinition;
|
|
10
|
+
|
|
11
|
+
var assign = require('min-dash').assign;
|
|
12
|
+
|
|
13
|
+
var LINE_HEIGHT = 14,
|
|
14
|
+
PADDING = 6;
|
|
15
|
+
|
|
16
|
+
function LabelEditingProvider(eventBus, canvas, directEditing, commandStack) {
|
|
17
|
+
|
|
18
|
+
this._canvas = canvas;
|
|
19
|
+
this._commandStack = commandStack;
|
|
20
|
+
|
|
21
|
+
directEditing.registerProvider(this);
|
|
22
|
+
|
|
23
|
+
commandStack.registerHandler('element.updateLabel', UpdateLabelHandler);
|
|
24
|
+
|
|
25
|
+
// listen to dblclick on non-root elements
|
|
26
|
+
eventBus.on('element.dblclick', function(event) {
|
|
27
|
+
directEditing.activate(event.element);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
// complete on followup canvas operation
|
|
31
|
+
eventBus.on([ 'element.mousedown', 'drag.init', 'canvas.viewbox.changed' ], function(event) {
|
|
32
|
+
directEditing.complete();
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
// cancel on command stack changes
|
|
36
|
+
eventBus.on([ 'commandStack.changed' ], function() {
|
|
37
|
+
directEditing.cancel();
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
eventBus.on('create.end', 500, function(event) {
|
|
41
|
+
|
|
42
|
+
var element = event.shape,
|
|
43
|
+
canExecute = event.context.canExecute,
|
|
44
|
+
isTouch = event.isTouch;
|
|
45
|
+
|
|
46
|
+
// TODO(nikku): we need to find a way to support the
|
|
47
|
+
// direct editing on mobile devices; right now this will
|
|
48
|
+
// break for desworkflowediting on mobile devices
|
|
49
|
+
// as it breaks the user interaction workflow
|
|
50
|
+
|
|
51
|
+
// TODO(nre): we should temporarily focus the edited element
|
|
52
|
+
// here and release the focused viewport after the direct edit
|
|
53
|
+
// operation is finished
|
|
54
|
+
if (isTouch) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (!canExecute) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
directEditing.activate(element);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
LabelEditingProvider.$inject = [
|
|
68
|
+
'eventBus',
|
|
69
|
+
'canvas',
|
|
70
|
+
'directEditing',
|
|
71
|
+
'commandStack'
|
|
72
|
+
];
|
|
73
|
+
|
|
74
|
+
module.exports = LabelEditingProvider;
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Activate direct editing.
|
|
79
|
+
*
|
|
80
|
+
* @param {djs.model.Base} element
|
|
81
|
+
*
|
|
82
|
+
* @return {Object} an object with properties bounds (position and size) and text
|
|
83
|
+
*/
|
|
84
|
+
LabelEditingProvider.prototype.activate = function(element) {
|
|
85
|
+
|
|
86
|
+
var text = LabelUtil.getLabel(element);
|
|
87
|
+
|
|
88
|
+
if (text === undefined) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// don't activate for root element
|
|
93
|
+
if (!element.parent) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
var target = element.label || element;
|
|
98
|
+
|
|
99
|
+
var props = this.getEditingBBox(element);
|
|
100
|
+
|
|
101
|
+
var definition = getDefinition(element);
|
|
102
|
+
|
|
103
|
+
var options = {};
|
|
104
|
+
|
|
105
|
+
if (is(definition, 'cmmn:Task') || is(definition, 'cmmn:Milestone')) {
|
|
106
|
+
options.centerVertically = true;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (is(element, 'cmmn:TextAnnotation')) {
|
|
110
|
+
options.autoResize = true;
|
|
111
|
+
options.resizable = true;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// external labels for event listener, case file items and connections
|
|
115
|
+
if (target.labelTarget) {
|
|
116
|
+
options.autoResize = true;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return assign({ text: text, options: options }, props);
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Get the editing bounding box based on the element's size and position
|
|
125
|
+
*
|
|
126
|
+
* @param {djs.model.Base} element
|
|
127
|
+
*
|
|
128
|
+
* @return {Object} an object containing information about position and size (fixed or minimum and/or maximum)
|
|
129
|
+
*/
|
|
130
|
+
LabelEditingProvider.prototype.getEditingBBox = function(element, maxBounds) {
|
|
131
|
+
|
|
132
|
+
var canvas = this._canvas;
|
|
133
|
+
|
|
134
|
+
var definition = getDefinition(element);
|
|
135
|
+
|
|
136
|
+
var target = element.label || element;
|
|
137
|
+
|
|
138
|
+
var bbox = this._canvas.getAbsoluteBBox(target);
|
|
139
|
+
|
|
140
|
+
var mid = {
|
|
141
|
+
x: bbox.x + bbox.width / 2,
|
|
142
|
+
y: bbox.y + bbox.height / 2
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
// default position
|
|
146
|
+
var bounds = { x: bbox.x, y: bbox.y };
|
|
147
|
+
|
|
148
|
+
var style = {};
|
|
149
|
+
|
|
150
|
+
var zoom = canvas.zoom();
|
|
151
|
+
|
|
152
|
+
// internal labels for case plan models
|
|
153
|
+
if (isCasePlanModel(element)) {
|
|
154
|
+
bounds.height = 50;
|
|
155
|
+
bounds.width = 200;
|
|
156
|
+
bounds.y -= 30;
|
|
157
|
+
|
|
158
|
+
style.textAlign = 'left';
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// internal labels for stages and plan fragments (excluding case plan models)
|
|
162
|
+
if (is(definition, 'cmmn:PlanFragment') && !isCasePlanModel(element)) {
|
|
163
|
+
bounds.width = element.width;
|
|
164
|
+
bounds.maxHeight = 3 * LINE_HEIGHT + PADDING; // maximum 3 lines
|
|
165
|
+
bounds.y += 5;
|
|
166
|
+
|
|
167
|
+
style.textAlign = 'left';
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// internal labels for tasks
|
|
171
|
+
if (is(definition, 'cmmn:Task') || is(definition, 'cmmn:Milestone')) {
|
|
172
|
+
|
|
173
|
+
// fixed size for internal labels:
|
|
174
|
+
// on high zoom levels: text box size === bbox size
|
|
175
|
+
// on low zoom levels: text box size === bbox size at 100% zoom
|
|
176
|
+
// This ensures minimum bounds at low zoom levels
|
|
177
|
+
if (zoom > 1) {
|
|
178
|
+
bounds.width = bbox.width;
|
|
179
|
+
bounds.height = bbox.height;
|
|
180
|
+
} else {
|
|
181
|
+
bounds.width = bbox.width / zoom;
|
|
182
|
+
bounds.height = bbox.height / zoom;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// centering overlapping text box size at low zoom levels
|
|
186
|
+
if (zoom < 1) {
|
|
187
|
+
bounds.x = bbox.x - (bounds.width / 2 - bbox.width / 2);
|
|
188
|
+
bounds.y = bbox.y - (bounds.height / 2 - bbox.height / 2);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
if (is(element, 'cmmn:TextAnnotation')) {
|
|
193
|
+
bounds.width = bbox.width;
|
|
194
|
+
bounds.height = bbox.height;
|
|
195
|
+
bounds.minWidth = 30 * zoom;
|
|
196
|
+
bounds.minHeight = 10 * zoom;
|
|
197
|
+
|
|
198
|
+
style.textAlign = 'left';
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// external labels for event listener, case file items and connections
|
|
202
|
+
if (target.labelTarget) {
|
|
203
|
+
|
|
204
|
+
bounds.width = 150;
|
|
205
|
+
bounds.minHeight = LINE_HEIGHT + PADDING; // 1 line
|
|
206
|
+
bounds.x = mid.x - bounds.width / 2;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
return {
|
|
210
|
+
bounds: bounds,
|
|
211
|
+
style: style
|
|
212
|
+
};
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
LabelEditingProvider.prototype.update = function(element, newLabel) {
|
|
217
|
+
this._commandStack.execute('element.updateLabel', {
|
|
218
|
+
element: element,
|
|
219
|
+
newLabel: newLabel
|
|
220
|
+
});
|
|
221
|
+
};
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var is = require('../../util/ModelUtil').is;
|
|
4
|
+
var isAny = require('../modeling/util/ModelingUtil').isAny;
|
|
5
|
+
|
|
6
|
+
var getBusinessObject = require('../../util/ModelUtil').getBusinessObject;
|
|
7
|
+
|
|
8
|
+
function getLabelAttr(element) {
|
|
9
|
+
if (is(element, 'cmmn:TextAnnotation')) {
|
|
10
|
+
return 'text';
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
return 'name';
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function getSemantic(element) {
|
|
17
|
+
var bo = getBusinessObject(element);
|
|
18
|
+
|
|
19
|
+
if (is(bo, 'cmmndi:CMMNEdge') && bo.cmmnElementRef) {
|
|
20
|
+
bo = bo.cmmnElementRef;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return bo;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Check if the given element is of a type which has a reference to a definition.
|
|
28
|
+
* This could be either plan items or discretionary items or case file items.
|
|
29
|
+
*
|
|
30
|
+
* @param {djs.model.Base} element
|
|
31
|
+
*
|
|
32
|
+
* @return {Boolean}
|
|
33
|
+
*/
|
|
34
|
+
var isReferencing = function(element) {
|
|
35
|
+
return isAny(element, [
|
|
36
|
+
'cmmn:PlanItem',
|
|
37
|
+
'cmmn:DiscretionaryItem',
|
|
38
|
+
'cmmn:CaseFileItem'
|
|
39
|
+
]);
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
function hasEditableLabel(element) {
|
|
43
|
+
return !isAny(element, [
|
|
44
|
+
'cmmn:Association',
|
|
45
|
+
'cmmn:Criterion',
|
|
46
|
+
'cmmndi:CMMNEdge'
|
|
47
|
+
]);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
var getLabel = function(element) {
|
|
51
|
+
|
|
52
|
+
var semantic = getSemantic(element),
|
|
53
|
+
attr = getLabelAttr(semantic);
|
|
54
|
+
|
|
55
|
+
if (!hasEditableLabel(semantic)) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Get definition as semantic if
|
|
60
|
+
// * the element has no name property set
|
|
61
|
+
// * the element type has a reference to a definition
|
|
62
|
+
if (!semantic[attr] && isReferencing(element)) {
|
|
63
|
+
semantic = semantic.definitionRef;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return semantic[attr] || '';
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
module.exports.getLabel = getLabel;
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
var setLabel = function(element, text, isExternal, isExclusiveRef) {
|
|
73
|
+
|
|
74
|
+
var semantic = getSemantic(element),
|
|
75
|
+
attr = getLabelAttr(semantic);
|
|
76
|
+
|
|
77
|
+
// Get definition as semantic if
|
|
78
|
+
// * the element has no name property set
|
|
79
|
+
// * the element type has a reference to a definition
|
|
80
|
+
// * the element is the only reference to a defition
|
|
81
|
+
if (!semantic[attr] && isReferencing(element) && isExclusiveRef) {
|
|
82
|
+
semantic = semantic.definitionRef;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
semantic[attr] = text;
|
|
86
|
+
|
|
87
|
+
// show external label if not empty
|
|
88
|
+
if (isExternal) {
|
|
89
|
+
element.hidden = !text;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return element;
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
module.exports.setLabel = setLabel;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var LabelUtil = require('../LabelUtil');
|
|
4
|
+
|
|
5
|
+
var getDefinition = require('../../../util/ModelUtil').getDefinition;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* A handler that updates the text of a CMMN element.
|
|
9
|
+
*/
|
|
10
|
+
function UpdateLabelHandler(itemRegistry) {
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Set the label and return the changed elements.
|
|
14
|
+
*
|
|
15
|
+
* Element parameter can be label itself or connection (i.e. sequence flow).
|
|
16
|
+
*
|
|
17
|
+
* @param {djs.model.Base} element
|
|
18
|
+
* @param {String} text
|
|
19
|
+
*/
|
|
20
|
+
function setText(element, text) {
|
|
21
|
+
|
|
22
|
+
// external label if present
|
|
23
|
+
var label = element.label || element;
|
|
24
|
+
|
|
25
|
+
var labelTarget = element.labelTarget || element;
|
|
26
|
+
|
|
27
|
+
LabelUtil.setLabel(label, text, labelTarget !== label, isExclusiveRef(element));
|
|
28
|
+
|
|
29
|
+
return [ label, labelTarget ];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Return a function which checks if the element is the only reference to a definition
|
|
34
|
+
*
|
|
35
|
+
* @param {djs.model.Base} element
|
|
36
|
+
*
|
|
37
|
+
* @return {Function}
|
|
38
|
+
*/
|
|
39
|
+
function isExclusiveRef(element) {
|
|
40
|
+
var definition = getDefinition(element);
|
|
41
|
+
return definition ? itemRegistry.getReferences(definition).length === 1 : true;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
function execute(ctx) {
|
|
46
|
+
ctx.oldLabel = LabelUtil.getLabel(ctx.element);
|
|
47
|
+
return setText(ctx.element, ctx.newLabel);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function revert(ctx) {
|
|
51
|
+
return setText(ctx.element, ctx.oldLabel);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// API
|
|
55
|
+
|
|
56
|
+
this.execute = execute;
|
|
57
|
+
this.revert = revert;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
UpdateLabelHandler.$inject = [ 'itemRegistry' ];
|
|
62
|
+
|
|
63
|
+
module.exports = UpdateLabelHandler;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
__depends__: [
|
|
3
|
+
require('diagram-js/lib/command').default,
|
|
4
|
+
require('diagram-js/lib/features/change-support').default,
|
|
5
|
+
require('diagram-js-direct-editing').default
|
|
6
|
+
],
|
|
7
|
+
__init__: [ 'labelEditingProvider' ],
|
|
8
|
+
labelEditingProvider: [ 'type', require('./LabelEditingProvider') ]
|
|
9
|
+
};
|