Skip to content

Commit

Permalink
chore: fix util JSDocs
Browse files Browse the repository at this point in the history
  • Loading branch information
philippfromme committed Apr 11, 2023
1 parent 5589cd4 commit 38625df
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 32 deletions.
13 changes: 13 additions & 0 deletions lib/util/CompatibilityUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import {
isFunction
} from 'min-dash';

/**
* @typedef {import('../model/Types').ModdleElement} ModdleElement
*/

// TODO(nikku): remove with future bpmn-js version

/**
Expand All @@ -12,6 +16,10 @@ import {
* 2) If Promise class is implemented in current environment.
*
* @private
*
* @param {Function} api
*
* @return {Function}
*/
export function wrapForCompatibility(api) {

Expand Down Expand Up @@ -60,6 +68,11 @@ export function wrapForCompatibility(api) {

var DI_ERROR_MESSAGE = 'Tried to access di from the businessObject. The di is available through the diagram element only. For more information, see https://github.com/bpmn-io/bpmn-js/issues/1472';

/**
* @private
*
* @param {ModdleElement} businessObject
*/
export function ensureCompatDiRef(businessObject) {

// bpmnElement can have multiple independent DIs
Expand Down
18 changes: 9 additions & 9 deletions lib/util/DiUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import {
} from 'min-dash';

/**
* @typedef {import('../model').DiagramElement} DiagramElement
* @typedef {import('../model').ModdleElement} ModdleElement
* @typedef {import('../model/Types').BpmnElement} BpmnElement
* @typedef {import('../model/Types').ModdleElement} ModdleElement
*/

/**
* @param {DiagramElement} element
* @param {BpmnElement} element
* @param {ModdleElement} di
*
* @return {boolean}
Expand Down Expand Up @@ -43,7 +43,7 @@ export function isExpanded(element, di) {
}

/**
* @param {DiagramElement} element
* @param {BpmnElement} element
*
* @return {boolean}
*/
Expand All @@ -52,7 +52,7 @@ export function isInterrupting(element) {
}

/**
* @param {DiagramElement} element
* @param {BpmnElement} element
*
* @return {boolean}
*/
Expand All @@ -61,7 +61,7 @@ export function isEventSubProcess(element) {
}

/**
* @param {DiagramElement} element
* @param {BpmnElement} element
* @param {string} eventType
*
* @return {boolean}
Expand All @@ -75,7 +75,7 @@ export function hasEventDefinition(element, eventType) {
}

/**
* @param {DiagramElement} element
* @param {BpmnElement} element
*
* @return {boolean}
*/
Expand All @@ -84,7 +84,7 @@ export function hasErrorEventDefinition(element) {
}

/**
* @param {DiagramElement} element
* @param {BpmnElement} element
*
* @return {boolean}
*/
Expand All @@ -93,7 +93,7 @@ export function hasEscalationEventDefinition(element) {
}

/**
* @param {DiagramElement} element
* @param {BpmnElement} element
*
* @return {boolean}
*/
Expand Down
20 changes: 12 additions & 8 deletions lib/util/DrilldownUtil.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import { getDi, is } from './ModelUtil';

/**
* @typedef {import('../model/Types').BpmnElement} BpmnElement
* @typedef {import('../model/Types').ModdleElement} ModdleElement
*/

export var planeSuffix = '_plane';

/**
* Get primary shape ID for a plane.
*
* @param {djs.model.Base|ModdleElement} element
* @param {BpmnElement|ModdleElement} element
*
* @returns {String}
* @return {string}
*/
export function getShapeIdFromPlane(element) {
var id = element.id;
Expand All @@ -19,9 +23,9 @@ export function getShapeIdFromPlane(element) {
/**
* Get plane ID for a primary shape.
*
* @param {djs.model.Base|ModdleElement} element
* @param {BpmnElement|ModdleElement} element
*
* @returns {String}
* @return {string}
*/
export function getPlaneIdFromShape(element) {
var id = element.id;
Expand All @@ -36,9 +40,9 @@ export function getPlaneIdFromShape(element) {
/**
* Get plane ID for primary shape ID.
*
* @param {String} id
* @param {string} id
*
* @returns {String}
* @return {string}
*/
export function toPlaneId(id) {
return addPlaneSuffix(id);
Expand All @@ -47,9 +51,9 @@ export function toPlaneId(id) {
/**
* Check wether element is plane.
*
* @param {djs.model.Base|ModdleElement} element
* @param {BpmnElement|ModdleElement} element
*
* @returns {Boolean}
* @return {boolean}
*/
export function isPlane(element) {
var di = getDi(element);
Expand Down
54 changes: 39 additions & 15 deletions lib/util/LabelUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ import {

import { is } from './ModelUtil';

/**
* @typedef {import('diagram-js/lib/util/Types').Point} Point
* @typedef {import('diagram-js/lib/util/Types').Rect} Rect
*
* @typedef {import('../model/Types').BpmnElement} BpmnElement
* @typedef {import('../model/Types').ModdleElement} ModdleElement
*/

export var DEFAULT_LABEL_SIZE = {
width: 90,
Expand All @@ -14,10 +21,11 @@ export var FLOW_LABEL_INDENT = 15;


/**
* Returns true if the given semantic has an external label
* Return true if the given semantic has an external label.
*
* @param {BpmnElement} semantic
* @return {boolean} true if has label
*
* @return {boolean}
*/
export function isLabelExternal(semantic) {
return is(semantic, 'bpmn:Event') ||
Expand All @@ -32,20 +40,22 @@ export function isLabelExternal(semantic) {
}

/**
* Returns true if the given element has an external label
* Return true if the given element has an external label.
*
* @param {djs.model.shape} element
* @return {boolean} true if has label
* @param {BpmnElement} element
*
* @return {boolean}
*/
export function hasExternalLabel(element) {
return isLabel(element.label);
}

/**
* Get the position for sequence flow labels
* Get the position of a sequence flow label.
*
* @param {Point[]} waypoints
*
* @param {Array<Point>} waypoints
* @return {Point} the label position
* @return {Point}
*/
export function getFlowLabelPosition(waypoints) {

Expand Down Expand Up @@ -75,10 +85,11 @@ export function getFlowLabelPosition(waypoints) {


/**
* Get the middle of a number of waypoints
* Get the middle of a number of waypoints.
*
* @param {Array<Point>} waypoints
* @return {Point} the mid point
* @param {Point[]} waypoints
*
* @return {Point}
*/
export function getWaypointsMid(waypoints) {

Expand All @@ -93,7 +104,13 @@ export function getWaypointsMid(waypoints) {
};
}


/**
* Get the middle of the external label of an element.
*
* @param {BpmnElement} element
*
* @return {Point}
*/
export function getExternalLabelMid(element) {

if (element.waypoints) {
Expand All @@ -113,11 +130,13 @@ export function getExternalLabelMid(element) {


/**
* Returns the bounds of an elements label, parsed from the elements DI or
* Return the bounds of an elements label, parsed from the elements DI or
* generated from its bounds.
*
* @param {BpmndDi} di
* @param {djs.model.Base} element
* @param {ModdleElement} di
* @param {BpmnElement} element
*
* @return {Rect}
*/
export function getExternalLabelBounds(di, element) {

Expand Down Expand Up @@ -151,6 +170,11 @@ export function getExternalLabelBounds(di, element) {
}, size);
}

/**
* @param {BpmnElement} element
*
* @return {boolean}
*/
export function isLabel(element) {
return element && !!element.labelTarget;
}

0 comments on commit 38625df

Please sign in to comment.