2014-06-11 13:08:45 +00:00
|
|
|
'use strict';
|
|
|
|
|
2017-06-27 07:37:58 +00:00
|
|
|
var assign = require('lodash/object/assign');
|
|
|
|
|
2015-04-27 14:50:09 +00:00
|
|
|
var LabelUtil = require('./LabelUtil');
|
|
|
|
|
|
|
|
var is = require('../../util/ModelUtil').is,
|
2017-12-09 20:30:10 +00:00
|
|
|
isAny = require('../modeling/util/ModelingUtil').isAny,
|
2016-05-18 05:54:58 +00:00
|
|
|
isExpanded = require('../../util/DiUtil').isExpanded;
|
2014-06-17 09:53:07 +00:00
|
|
|
|
2017-06-27 07:37:58 +00:00
|
|
|
var SMALL_FONT_SIZE = 11,
|
|
|
|
SMALL_LINE_HEIGHT = 13,
|
|
|
|
MEDIUM_FONT_SIZE = 12,
|
|
|
|
MEDIUM_LINE_HEIGHT = 14;
|
2014-06-11 13:08:45 +00:00
|
|
|
|
2018-01-24 19:25:28 +00:00
|
|
|
|
|
|
|
function LabelEditingProvider(
|
|
|
|
eventBus, canvas, directEditing,
|
|
|
|
modeling, resizeHandles) {
|
2014-06-11 13:08:45 +00:00
|
|
|
|
2016-09-05 12:27:34 +00:00
|
|
|
this._canvas = canvas;
|
2018-01-24 19:25:28 +00:00
|
|
|
this._modeling = modeling;
|
2016-09-05 12:27:34 +00:00
|
|
|
|
2014-06-11 13:08:45 +00:00
|
|
|
directEditing.registerProvider(this);
|
2016-09-05 12:27:34 +00:00
|
|
|
|
2014-12-17 20:54:25 +00:00
|
|
|
// listen to dblclick on non-root elements
|
|
|
|
eventBus.on('element.dblclick', function(event) {
|
2017-12-09 20:30:10 +00:00
|
|
|
activateDirectEdit(event.element, true);
|
2014-06-24 13:34:57 +00:00
|
|
|
});
|
2014-06-17 09:53:07 +00:00
|
|
|
|
2014-12-23 15:49:28 +00:00
|
|
|
// complete on followup canvas operation
|
2018-01-24 19:25:28 +00:00
|
|
|
eventBus.on([
|
|
|
|
'element.mousedown',
|
|
|
|
'drag.init',
|
2018-02-15 22:04:02 +00:00
|
|
|
'canvas.viewbox.changing',
|
|
|
|
'autoPlace'
|
2018-01-24 19:25:28 +00:00
|
|
|
], function(event) {
|
2014-06-11 13:08:45 +00:00
|
|
|
directEditing.complete();
|
|
|
|
});
|
|
|
|
|
2014-12-23 15:49:28 +00:00
|
|
|
// cancel on command stack changes
|
2017-06-27 07:37:58 +00:00
|
|
|
eventBus.on([ 'commandStack.changed' ], function(e) {
|
2014-12-23 15:49:28 +00:00
|
|
|
directEditing.cancel();
|
2014-06-17 09:53:07 +00:00
|
|
|
});
|
|
|
|
|
2017-12-08 18:32:13 +00:00
|
|
|
|
|
|
|
eventBus.on('directEditing.activate', function(event) {
|
|
|
|
resizeHandles.removeResizers();
|
|
|
|
});
|
|
|
|
|
|
|
|
eventBus.on('create.end', 500, function(event) {
|
|
|
|
|
|
|
|
var element = event.shape,
|
|
|
|
canExecute = event.context.canExecute,
|
2017-12-09 22:56:31 +00:00
|
|
|
isTouch = event.isTouch;
|
2017-12-08 18:32:13 +00:00
|
|
|
|
2018-01-24 19:25:28 +00:00
|
|
|
// TODO(nikku): we need to find a way to support the
|
|
|
|
// direct editing on mobile devices; right now this will
|
|
|
|
// break for desworkflowediting on mobile devices
|
2014-12-23 15:49:28 +00:00
|
|
|
// as it breaks the user interaction workflow
|
2014-09-15 12:42:43 +00:00
|
|
|
|
2018-01-24 19:25:28 +00:00
|
|
|
// TODO(nre): we should temporarily focus the edited element
|
|
|
|
// here and release the focused viewport after the direct edit
|
|
|
|
// operation is finished
|
2017-12-08 18:32:13 +00:00
|
|
|
if (isTouch) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!canExecute) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-12-09 20:30:10 +00:00
|
|
|
activateDirectEdit(element);
|
|
|
|
});
|
|
|
|
|
2017-12-08 20:06:08 +00:00
|
|
|
eventBus.on('autoPlace.end', 500, function(event) {
|
|
|
|
activateDirectEdit(event.shape);
|
|
|
|
});
|
|
|
|
|
2017-12-09 20:30:10 +00:00
|
|
|
|
|
|
|
function activateDirectEdit(element, force) {
|
|
|
|
if (force ||
|
|
|
|
isAny(element, [ 'bpmn:Task', 'bpmn:TextAnnotation' ]) ||
|
|
|
|
isCollapsedSubProcess(element)) {
|
|
|
|
|
2017-12-08 18:32:13 +00:00
|
|
|
directEditing.activate(element);
|
|
|
|
}
|
2017-12-09 20:30:10 +00:00
|
|
|
}
|
2017-12-08 18:32:13 +00:00
|
|
|
|
2014-06-11 13:08:45 +00:00
|
|
|
}
|
|
|
|
|
2018-01-24 19:25:28 +00:00
|
|
|
LabelEditingProvider.$inject = [
|
|
|
|
'eventBus',
|
|
|
|
'canvas',
|
|
|
|
'directEditing',
|
|
|
|
'modeling',
|
|
|
|
'resizeHandles'
|
|
|
|
];
|
2014-09-15 12:42:43 +00:00
|
|
|
|
|
|
|
module.exports = LabelEditingProvider;
|
|
|
|
|
2014-06-11 13:08:45 +00:00
|
|
|
|
2016-08-19 14:16:37 +00:00
|
|
|
/**
|
|
|
|
* Activate direct editing for activities and text annotations.
|
|
|
|
*
|
|
|
|
* @param {djs.model.Base} element
|
|
|
|
*
|
2017-06-27 07:37:58 +00:00
|
|
|
* @return {Object} an object with properties bounds (position and size), text and options
|
2016-08-19 14:16:37 +00:00
|
|
|
*/
|
2014-06-11 13:08:45 +00:00
|
|
|
LabelEditingProvider.prototype.activate = function(element) {
|
|
|
|
|
2017-06-27 07:37:58 +00:00
|
|
|
// text
|
2014-09-08 17:03:39 +00:00
|
|
|
var text = LabelUtil.getLabel(element);
|
2014-06-11 13:08:45 +00:00
|
|
|
|
2014-06-17 09:53:07 +00:00
|
|
|
if (text === undefined) {
|
|
|
|
return;
|
2014-06-11 13:08:45 +00:00
|
|
|
}
|
|
|
|
|
2017-06-27 07:37:58 +00:00
|
|
|
var context = {
|
|
|
|
text: text
|
|
|
|
};
|
|
|
|
|
|
|
|
// bounds
|
|
|
|
var bounds = this.getEditingBBox(element);
|
|
|
|
|
|
|
|
assign(context, bounds);
|
|
|
|
|
|
|
|
// options
|
|
|
|
var target = element.label || element;
|
|
|
|
|
|
|
|
var options = {};
|
2016-05-18 05:54:58 +00:00
|
|
|
|
2017-06-27 07:37:58 +00:00
|
|
|
// tasks
|
2018-01-24 19:25:28 +00:00
|
|
|
if (
|
|
|
|
isAny(element, [
|
|
|
|
'bpmn:Task',
|
|
|
|
'bpmn:Participant',
|
|
|
|
'bpmn:Lane',
|
|
|
|
'bpmn:CallActivity'
|
|
|
|
]) ||
|
|
|
|
isCollapsedSubProcess(element)
|
|
|
|
) {
|
2017-06-27 07:37:58 +00:00
|
|
|
assign(options, {
|
|
|
|
centerVertically: true
|
|
|
|
});
|
|
|
|
}
|
2014-06-17 09:53:07 +00:00
|
|
|
|
2017-06-27 07:37:58 +00:00
|
|
|
// external labels
|
|
|
|
if (target.labelTarget) {
|
|
|
|
assign(options, {
|
|
|
|
autoResize: true
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// text annotations
|
|
|
|
if (is(element, 'bpmn:TextAnnotation')) {
|
|
|
|
assign(options, {
|
|
|
|
resizable: true,
|
|
|
|
autoResize: true
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
assign(context, {
|
|
|
|
options: options
|
|
|
|
});
|
|
|
|
|
|
|
|
return context;
|
2016-08-19 14:16:37 +00:00
|
|
|
};
|
2014-06-11 13:08:45 +00:00
|
|
|
|
|
|
|
|
2016-08-19 14:16:37 +00:00
|
|
|
/**
|
|
|
|
* Get the editing bounding box based on the element's size and position
|
|
|
|
*
|
|
|
|
* @param {djs.model.Base} element
|
|
|
|
*
|
2018-01-24 19:25:28 +00:00
|
|
|
* @return {Object} an object containing information about position
|
|
|
|
* and size (fixed or minimum and/or maximum)
|
2016-08-19 14:16:37 +00:00
|
|
|
*/
|
|
|
|
LabelEditingProvider.prototype.getEditingBBox = function(element) {
|
2016-09-05 12:27:34 +00:00
|
|
|
var canvas = this._canvas;
|
2016-03-07 16:06:24 +00:00
|
|
|
|
2016-08-19 14:16:37 +00:00
|
|
|
var target = element.label || element;
|
2016-03-07 16:06:24 +00:00
|
|
|
|
2016-09-05 12:27:34 +00:00
|
|
|
var bbox = canvas.getAbsoluteBBox(target);
|
2016-08-19 14:16:37 +00:00
|
|
|
|
|
|
|
var mid = {
|
|
|
|
x: bbox.x + bbox.width / 2,
|
|
|
|
y: bbox.y + bbox.height / 2
|
|
|
|
};
|
2016-03-07 16:06:24 +00:00
|
|
|
|
2016-08-19 14:16:37 +00:00
|
|
|
// default position
|
|
|
|
var bounds = { x: bbox.x, y: bbox.y };
|
2014-06-17 09:53:07 +00:00
|
|
|
|
2017-06-27 07:37:58 +00:00
|
|
|
var zoom = canvas.zoom();
|
|
|
|
|
|
|
|
// take zoom into account
|
|
|
|
var smallFontSize = SMALL_FONT_SIZE * zoom,
|
|
|
|
smallLineHeight = SMALL_LINE_HEIGHT * zoom,
|
|
|
|
mediumFontSize = MEDIUM_FONT_SIZE * zoom,
|
|
|
|
mediumLineHeight = MEDIUM_LINE_HEIGHT * zoom;
|
|
|
|
|
|
|
|
var style = {};
|
2014-06-11 13:08:45 +00:00
|
|
|
|
2016-08-19 14:16:37 +00:00
|
|
|
// adjust for expanded pools AND lanes
|
2017-12-09 20:30:10 +00:00
|
|
|
if (is(element, 'bpmn:Lane') || isExpandedPool(element)) {
|
2017-06-27 07:37:58 +00:00
|
|
|
|
|
|
|
assign(bounds, {
|
|
|
|
width: bbox.height,
|
|
|
|
height: 30 * zoom,
|
|
|
|
x: bbox.x - bbox.height / 2 + (15 * zoom),
|
|
|
|
y: mid.y - (30 * zoom) / 2
|
|
|
|
});
|
2016-08-19 14:16:37 +00:00
|
|
|
|
2017-06-27 07:37:58 +00:00
|
|
|
assign(style, {
|
|
|
|
fontSize: mediumFontSize + 'px',
|
|
|
|
lineHeight: mediumLineHeight + 'px',
|
|
|
|
paddingTop: (7 * zoom) + 'px',
|
|
|
|
paddingBottom: (7 * zoom) + 'px',
|
|
|
|
paddingLeft: (5 * zoom) + 'px',
|
|
|
|
paddingRight: (5 * zoom) + 'px',
|
|
|
|
transform: 'rotate(-90deg)'
|
|
|
|
});
|
2014-06-11 13:08:45 +00:00
|
|
|
}
|
2014-06-17 09:53:07 +00:00
|
|
|
|
2014-06-11 13:08:45 +00:00
|
|
|
|
2018-01-24 19:25:28 +00:00
|
|
|
// internal labels for tasks and collapsed call activities,
|
|
|
|
// sub processes and participants
|
2017-12-09 20:30:10 +00:00
|
|
|
if (isAny(element, [ 'bpmn:Task', 'bpmn:CallActivity']) ||
|
|
|
|
isCollapsedPool(element) ||
|
|
|
|
isCollapsedSubProcess(element)) {
|
|
|
|
|
2017-06-27 07:37:58 +00:00
|
|
|
assign(bounds, {
|
|
|
|
width: bbox.width,
|
|
|
|
height: bbox.height
|
|
|
|
});
|
2014-06-11 13:08:45 +00:00
|
|
|
|
2017-06-27 07:37:58 +00:00
|
|
|
assign(style, {
|
|
|
|
fontSize: mediumFontSize + 'px',
|
|
|
|
lineHeight: mediumLineHeight + 'px',
|
|
|
|
paddingTop: (7 * zoom) + 'px',
|
|
|
|
paddingBottom: (7 * zoom) + 'px',
|
|
|
|
paddingLeft: (5 * zoom) + 'px',
|
|
|
|
paddingRight: (5 * zoom) + 'px'
|
|
|
|
});
|
2016-08-19 14:16:37 +00:00
|
|
|
}
|
2014-06-11 13:08:45 +00:00
|
|
|
|
2016-05-18 05:54:58 +00:00
|
|
|
|
2016-08-19 14:16:37 +00:00
|
|
|
// internal labels for expanded sub processes
|
2017-12-09 20:30:10 +00:00
|
|
|
if (isExpandedSubProcess(element)) {
|
2017-06-27 07:37:58 +00:00
|
|
|
assign(bounds, {
|
|
|
|
width: bbox.width,
|
|
|
|
x: bbox.x
|
|
|
|
});
|
2014-06-11 13:08:45 +00:00
|
|
|
|
2017-06-27 07:37:58 +00:00
|
|
|
assign(style, {
|
|
|
|
fontSize: mediumFontSize + 'px',
|
|
|
|
lineHeight: mediumLineHeight + 'px',
|
|
|
|
paddingTop: (7 * zoom) + 'px',
|
|
|
|
paddingBottom: (7 * zoom) + 'px',
|
|
|
|
paddingLeft: (5 * zoom) + 'px',
|
|
|
|
paddingRight: (5 * zoom) + 'px'
|
|
|
|
});
|
2016-08-19 14:16:37 +00:00
|
|
|
}
|
2014-06-11 13:08:45 +00:00
|
|
|
|
2016-08-19 14:16:37 +00:00
|
|
|
|
|
|
|
// external labels for events, data elements, gateways and connections
|
2014-09-09 13:21:21 +00:00
|
|
|
if (target.labelTarget) {
|
2017-06-27 07:37:58 +00:00
|
|
|
var width = 90 * zoom,
|
|
|
|
paddingTop = 7 * zoom,
|
|
|
|
paddingBottom = 4 * zoom;
|
|
|
|
|
|
|
|
assign(bounds, {
|
|
|
|
width: width,
|
|
|
|
height: bbox.height + paddingTop + paddingBottom,
|
|
|
|
x: mid.x - width / 2,
|
|
|
|
y: bbox.y - paddingTop
|
|
|
|
});
|
2014-06-11 13:08:45 +00:00
|
|
|
|
2017-06-27 07:37:58 +00:00
|
|
|
assign(style, {
|
|
|
|
fontSize: smallFontSize + 'px',
|
|
|
|
lineHeight: smallLineHeight + 'px',
|
|
|
|
paddingTop: paddingTop + 'px',
|
|
|
|
paddingBottom: paddingBottom + 'px'
|
|
|
|
});
|
2014-09-09 13:21:21 +00:00
|
|
|
}
|
2014-06-11 13:08:45 +00:00
|
|
|
|
2014-06-17 09:53:07 +00:00
|
|
|
|
2016-08-19 14:16:37 +00:00
|
|
|
// text annotations
|
|
|
|
if (is(element, 'bpmn:TextAnnotation')) {
|
2017-06-27 07:37:58 +00:00
|
|
|
assign(bounds, {
|
|
|
|
width: bbox.width,
|
|
|
|
height: bbox.height,
|
|
|
|
minWidth: 30 * zoom,
|
|
|
|
minHeight: 10 * zoom
|
|
|
|
});
|
2016-08-19 14:16:37 +00:00
|
|
|
|
2017-06-27 07:37:58 +00:00
|
|
|
assign(style, {
|
|
|
|
textAlign: 'left',
|
|
|
|
paddingTop: (7 * zoom) + 'px',
|
|
|
|
paddingBottom: (7 * zoom) + 'px',
|
|
|
|
paddingLeft: (5 * zoom) + 'px',
|
|
|
|
paddingRight: (5 * zoom) + 'px',
|
|
|
|
fontSize: mediumFontSize + 'px',
|
|
|
|
lineHeight: mediumLineHeight + 'px'
|
|
|
|
});
|
2016-08-19 14:16:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return { bounds: bounds, style: style };
|
2014-06-11 13:08:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2018-01-24 19:25:28 +00:00
|
|
|
LabelEditingProvider.prototype.update = function(
|
|
|
|
element, newLabel,
|
|
|
|
activeContextText, bounds) {
|
|
|
|
|
|
|
|
var newBounds,
|
|
|
|
bbox;
|
|
|
|
|
|
|
|
if (is(element, 'bpmn:TextAnnotation')) {
|
|
|
|
|
|
|
|
bbox = this._canvas.getAbsoluteBBox(element);
|
2017-06-27 07:37:58 +00:00
|
|
|
|
2018-01-24 19:25:28 +00:00
|
|
|
newBounds = {
|
2017-06-27 07:37:58 +00:00
|
|
|
x: element.x,
|
|
|
|
y: element.y,
|
2018-01-24 19:25:28 +00:00
|
|
|
width: element.width / bbox.width * bounds.width,
|
|
|
|
height: element.height / bbox.height * bounds.height
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
this._modeling.updateLabel(element, newLabel, newBounds);
|
2016-03-07 16:06:24 +00:00
|
|
|
};
|
2017-12-09 20:30:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2018-02-27 08:57:22 +00:00
|
|
|
// helpers //////////////////////
|
2017-12-09 20:30:10 +00:00
|
|
|
|
|
|
|
function isCollapsedSubProcess(element) {
|
|
|
|
return is(element, 'bpmn:SubProcess') && !isExpanded(element);
|
|
|
|
}
|
|
|
|
|
|
|
|
function isExpandedSubProcess(element) {
|
|
|
|
return is(element, 'bpmn:SubProcess') && isExpanded(element);
|
|
|
|
}
|
|
|
|
|
|
|
|
function isCollapsedPool(element) {
|
|
|
|
return is(element, 'bpmn:Participant') && !isExpanded(element);
|
|
|
|
}
|
|
|
|
|
|
|
|
function isExpandedPool(element) {
|
|
|
|
return is(element, 'bpmn:Participant') && isExpanded(element);
|
|
|
|
}
|