Skip to content

Commit

Permalink
fix(BpmnUpdater): fix JSDoc
Browse files Browse the repository at this point in the history
  • Loading branch information
philippfromme committed Apr 5, 2023
1 parent 0365dfb commit 5d5f601
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 29 deletions.
120 changes: 91 additions & 29 deletions lib/features/modeling/BpmnUpdater.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,53 @@ import {
import inherits from 'inherits-browser';

import {
remove as collectionRemove,
add as collectionAdd
add as collectionAdd,
remove as collectionRemove
} from 'diagram-js/lib/util/Collections';

import {
Label
} from 'diagram-js/lib/model';

import {
getBusinessObject,
getDi,
is
} from '../../util/ModelUtil';

import {
isAny
} from './util/ModelingUtil';
import { isAny } from './util/ModelingUtil';

import {
delta
} from 'diagram-js/lib/util/PositionUtil';
import { isLabel } from '../../util/LabelUtil';

import { delta } from 'diagram-js/lib/util/PositionUtil';

import CommandInterceptor from 'diagram-js/lib/command/CommandInterceptor';

/**
* A handler responsible for updating the underlying BPMN 2.0 XML + DI
* once changes on the diagram happen
* @typedef {import('diagram-js/lib/core/EventBus').default} EventBus
* @typedef {import('./BpmnFactory').default} BpmnFactory
* @typedef {import('diagram-js/lib/layout/CroppingConnectionDocking').default} CroppingConnectionDocking
* @typedef {import('diagram-js/lib/i18n/translate/translate').default} Translate
*
* @typedef {import('../../BaseViewer').ModdleElement} ModdleElement
*
* @typedef {import('./ElementFactory').BpmnConnection} BpmnConnection
* @typedef {import('./ElementFactory').BpmnElement} BpmnElement
* @typedef {import('./ElementFactory').BpmnShape} BpmnShape
* @typedef {import('./ElementFactory').BpmnParent} BpmnParent
*/

/**
* A handler responsible for updating the underlying BPMN 2.0 XML & DI
* once changes on the diagram happen.
*
* @param {EventBus} eventBus
* @param {BpmnFactory} bpmnFactory
* @param {CroppingConnectionDocking} connectionDocking
* @param {Translate} translate
*/
export default function BpmnUpdater(
eventBus, bpmnFactory, connectionDocking,
translate) {
eventBus,
bpmnFactory,
connectionDocking,
translate
) {

CommandInterceptor.call(this, eventBus);

Expand Down Expand Up @@ -286,6 +302,12 @@ BpmnUpdater.$inject = [

// implementation //////////////////////

/**
* @param { {
* shape: BpmnShape;
* host: BpmnShape;
* } } context
*/
BpmnUpdater.prototype.updateAttachment = function(context) {

var shape = context.shape,
Expand All @@ -295,10 +317,14 @@ BpmnUpdater.prototype.updateAttachment = function(context) {
businessObject.attachedToRef = host && host.businessObject;
};

/**
* @param {BpmnElement} element
* @param {BpmnParent} oldParent
*/
BpmnUpdater.prototype.updateParent = function(element, oldParent) {

// do not update BPMN 2.0 label parent
if (element instanceof Label) {
if (isLabel(element)) {
return;
}

Expand Down Expand Up @@ -345,7 +371,9 @@ BpmnUpdater.prototype.updateParent = function(element, oldParent) {
this.updateDiParent(di, parentDi);
};


/**
* @param {BpmnShape} shape
*/
BpmnUpdater.prototype.updateBounds = function(shape) {

var di = getDi(shape),
Expand All @@ -361,7 +389,7 @@ BpmnUpdater.prototype.updateBounds = function(shape) {
});
}

var target = (shape instanceof Label) ? this._getLabel(di) : di;
var target = isLabel(shape) ? this._getLabel(di) : di;

var bounds = target.bounds;

Expand All @@ -378,6 +406,11 @@ BpmnUpdater.prototype.updateBounds = function(shape) {
});
};

/**
* @param {ModdleElement} businessObject
* @param {ModdleElement} newContainment
* @param {ModdleElement} oldContainment
*/
BpmnUpdater.prototype.updateFlowNodeRefs = function(businessObject, newContainment, oldContainment) {

if (oldContainment === newContainment) {
Expand All @@ -397,8 +430,11 @@ BpmnUpdater.prototype.updateFlowNodeRefs = function(businessObject, newContainme
}
};


// update existing sourceElement and targetElement di information
/**
* @param {BpmnConnection} connection
* @param {BpmnElement} newSource
* @param {BpmnElement} newTarget
*/
BpmnUpdater.prototype.updateDiConnection = function(connection, newSource, newTarget) {
var connectionDi = getDi(connection),
newSourceDi = getDi(newSource),
Expand All @@ -414,7 +450,10 @@ BpmnUpdater.prototype.updateDiConnection = function(connection, newSource, newTa

};


/**
* @param {ModdleElement} di
* @param {ModdleElement} parentDi
*/
BpmnUpdater.prototype.updateDiParent = function(di, parentDi) {

if (parentDi && !is(parentDi, 'bpmndi:BPMNPlane')) {
Expand All @@ -436,6 +475,11 @@ BpmnUpdater.prototype.updateDiParent = function(di, parentDi) {
}
};

/**
* @param {ModdleElement} element
*
* @returns {ModdleElement}
*/
function getDefinitions(element) {
while (element && !is(element, 'bpmn:Definitions')) {
element = element.$parent;
Expand All @@ -444,6 +488,11 @@ function getDefinitions(element) {
return element;
}

/**
* @param {ModdleElement} container
*
* @returns {ModdleElement}
*/
BpmnUpdater.prototype.getLaneSet = function(container) {

var laneSet, laneSets;
Expand Down Expand Up @@ -479,6 +528,11 @@ BpmnUpdater.prototype.getLaneSet = function(container) {
return laneSet;
};

/**
* @param {ModdleElement} businessObject
* @param {ModdleElement} newParent
* @param {ModdleElement} visualParent
*/
BpmnUpdater.prototype.updateSemanticParent = function(businessObject, newParent, visualParent) {

var containment,
Expand Down Expand Up @@ -632,14 +686,22 @@ BpmnUpdater.prototype.updateSemanticParent = function(businessObject, newParent,
}
};


/**
* @param {BpmnConnection} connection
*/
BpmnUpdater.prototype.updateConnectionWaypoints = function(connection) {
var di = getDi(connection);

di.set('waypoint', this._bpmnFactory.createDiWaypoints(connection.waypoints));
};


/**
* @param { {
* connection: BpmnConnection;
* parent: BpmnParent;
* newParent: BpmnParent;
* } } context
*/
BpmnUpdater.prototype.updateConnection = function(context) {
var connection = context.connection,
businessObject = getBusinessObject(connection),
Expand Down Expand Up @@ -715,11 +777,11 @@ BpmnUpdater.prototype._getLabel = function(di) {


/**
* Make sure the event listener is only called
* if the touched element is a BPMN element.
* Call function if shape or connection is BPMN element.
*
* @param {Function} fn
* @return {Function} guarded function
*
* @return {Function}
*/
function ifBpmn(fn) {

Expand All @@ -737,9 +799,9 @@ function ifBpmn(fn) {
/**
* Return dc:Bounds of bpmndi:BPMNLabel if exists.
*
* @param {djs.model.shape} shape
* @param {BpmnShape} shape
*
* @returns {Object|undefined}
* @returns {ModdleElement|undefined}
*/
function getEmbeddedLabelBounds(shape) {
if (!is(shape, 'bpmn:Activity')) {
Expand Down
1 change: 1 addition & 0 deletions lib/features/modeling/ElementFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ import {
* @typedef {Label & BpmnElement} BpmnLabel
* @typedef {Root & BpmnElement} BpmnRoot
* @typedef {Shape & BpmnElement} BpmnShape
* @typedef {BpmnRoot | BpmnShape} BpmnParent
*/

/**
Expand Down

0 comments on commit 5d5f601

Please sign in to comment.