Skip to content

Commit

Permalink
chore: fix JSDoc comments
Browse files Browse the repository at this point in the history
* fix @param types
* fix formatting
  • Loading branch information
philippfromme committed Feb 24, 2023
1 parent 0d111a2 commit e7d1a18
Show file tree
Hide file tree
Showing 133 changed files with 1,383 additions and 482 deletions.
2 changes: 1 addition & 1 deletion lib/core/Canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ function findRoot(element) {
* Creates a HTML container element for a SVG element with
* the given configuration
*
* @param {CanvasConfig} options
* @param {CanvasConfig} options
*
* @return {HTMLElement} the container element
*/
Expand Down
4 changes: 2 additions & 2 deletions lib/core/Canvas.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import Diagram from '../../lib/Diagram';

import CoreModule from '../../lib/core';
import Canvas from '../../lib/core/Canvas';
import ElementFactory from '../../lib/core/ElementFactory';
import Canvas from './Canvas';
import ElementFactory from './ElementFactory';

const diagram = new Diagram({
modules: [
Expand Down
5 changes: 5 additions & 0 deletions lib/draw/DefaultRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ import {
isFrameElement
} from '../util/Elements';

/**
* @typedef {import('../core/EventBus').default} EventBus
* @typedef {import('./Styles').default} Styles
*/

// apply default renderer with lowest possible priority
// so that it only kicks in if noone else could render
var DEFAULT_RENDER_PRIORITY = 1;
Expand Down
10 changes: 5 additions & 5 deletions lib/draw/Styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ export default function Styles() {
/**
* Builds a style definition from a className, a list of traits and an object of additional attributes.
*
* @param {string} className
* @param {Array<string>} traits
* @param {Object} additionalAttrs
* @param {string} className
* @param {Array<string>} traits
* @param {Object} additionalAttrs
*
* @return {Object} the style defintion
*/
Expand All @@ -43,8 +43,8 @@ export default function Styles() {
/**
* Builds a style definition from a list of traits and an object of additional attributes.
*
* @param {Array<string>} traits
* @param {Object} additionalAttrs
* @param {Array<string>} traits
* @param {Object} additionalAttrs
*
* @return {Object} the style defintion
*/
Expand Down
20 changes: 14 additions & 6 deletions lib/features/align-elements/AlignElements.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ import {
sortBy
} from 'min-dash';

/**
* @typedef {import('../modeling/Modeling').default} Modeling
* @typedef {import('../rules/Rules').default} Rules
*/

function last(arr) {
return arr && arr[arr.length - 1];
}
Expand Down Expand Up @@ -37,7 +42,10 @@ var ALIGNMENT_SORTING = {
}
};


/**
* @param {Modeling} modeling
* @param {Rules} rules
*/
export default function AlignElements(modeling, rules) {
this._modeling = modeling;
this._rules = rules;
Expand All @@ -49,7 +57,7 @@ AlignElements.$inject = [ 'modeling', 'rules' ];
/**
* Get the relevant "axis" and "dimension" related to the current type of alignment
*
* @param {string} type left|right|center|top|bottom|middle
* @param {string} type left|right|center|top|bottom|middle
*
* @return {Object} { axis, dimension }
*/
Expand All @@ -76,8 +84,8 @@ AlignElements.prototype._isType = function(type, types) {
/**
* Get a point on the relevant axis where elements should align to
*
* @param {string} type left|right|center|top|bottom|middle
* @param {Array} sortedElements
* @param {string} type left|right|center|top|bottom|middle
* @param {Array} sortedElements
*
* @return {Object}
*/
Expand Down Expand Up @@ -152,8 +160,8 @@ AlignElements.prototype._alignmentPosition = function(type, sortedElements) {
/**
* Executes the alignment of a selection of elements
*
* @param {Array} elements
* @param {string} type left|right|center|top|bottom|middle
* @param {Array} elements
* @param {string} type left|right|center|top|bottom|middle
*/
AlignElements.prototype.trigger = function(elements, type) {
var modeling = this._modeling,
Expand Down
25 changes: 18 additions & 7 deletions lib/features/attach-support/AttachSupport.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ import inherits from 'inherits-browser';

import CommandInterceptor from '../../command/CommandInterceptor';

/**
* @typedef {import('didi').Injector} Injector
*
* @typedef {import('../../model').Base} Base
*
* @typedef {import('../../core/Canvas').default} Canvas
* @typedef {import('../../core/EventBus').default} EventBus
* @typedef {import('../rules/Rules').default} Rules
* @typedef {import('../modeling/Modeling').default} Modeling
*/

var LOW_PRIORITY = 251,
HIGH_PRIORITY = 1401;

Expand All @@ -30,7 +41,7 @@ var MARKER_ATTACH = 'attach-ok';
* Optionally depends on `diagram-js/lib/features/label-support`
* to render attached labels during move preview.
*
* @param {didi.Injector} injector
* @param {Injector} injector
* @param {EventBus} eventBus
* @param {Canvas} canvas
* @param {Rules} rules
Expand Down Expand Up @@ -273,8 +284,8 @@ AttachSupport.$inject = [
/**
* Return attachers of the given shapes
*
* @param {Array<djs.model.Base>} shapes
* @return {Array<djs.model.Base>}
* @param {Array<Base>} shapes
* @return {Array<Base>}
*/
function getAttachers(shapes) {
return flatten(map(shapes, function(s) {
Expand All @@ -286,8 +297,8 @@ function getAttachers(shapes) {
* Return a combined list of elements and
* attachers.
*
* @param {Array<djs.model.Base>} elements
* @return {Array<djs.model.Base>} filtered
* @param {Array<Base>} elements
* @return {Array<Base>} filtered
*/
function addAttached(elements) {
var attachers = getAttachers(elements);
Expand All @@ -300,9 +311,9 @@ function addAttached(elements) {
* contain attached elements with hosts being part
* of the selection.
*
* @param {Array<djs.model.Base>} elements
* @param {Array<Base>} elements
*
* @return {Array<djs.model.Base>} filtered
* @return {Array<Base>} filtered
*/
function removeAttached(elements) {

Expand Down
25 changes: 18 additions & 7 deletions lib/features/auto-place/AutoPlace.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ import {

import { DEFAULT_DISTANCE } from './AutoPlaceUtil';

/**
* @typedef {import('../../model').Shape} Shape
*
* @typedef {import('../../util/Types').Point} Point
*
* @typedef {import('../../core/Canvas').default} Canvas
* @typedef {import('../../core/EventBus').default} EventBus
* @typedef {import('../modeling/Modeling').default} Modeling
*/

var LOW_PRIORITY = 100;


Expand All @@ -14,6 +24,7 @@ var LOW_PRIORITY = 100;
*
* @param {EventBus} eventBus
* @param {Modeling} modeling
* @param {Canvas} canvas
*/
export default function AutoPlace(eventBus, modeling, canvas) {

Expand All @@ -31,10 +42,10 @@ export default function AutoPlace(eventBus, modeling, canvas) {
/**
* Append shape to source at appropriate position.
*
* @param {djs.model.Shape} source
* @param {djs.model.Shape} shape
* @param {Shape} source
* @param {Shape} shape
*
* @return {djs.model.Shape} appended shape
* @return {Shape} appended shape
*/
this.append = function(source, shape, hints) {

Expand Down Expand Up @@ -73,10 +84,10 @@ AutoPlace.$inject = [
* Find the new position for the target element to
* connect to source.
*
* @param {djs.model.Shape} source
* @param {djs.model.Shape} element
* @param {Object} [hints]
* @param {Object} [hints.defaultDistance]
* @param {Shape} source
* @param {Shape} element
* @param {Object} [hints]
* @param {Object} [hints.defaultDistance]
*
* @returns {Point}
*/
Expand Down
5 changes: 5 additions & 0 deletions lib/features/auto-place/AutoPlaceSelectionBehavior.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/**
* @typedef {import('../../core/EventBus').default} EventBus
* @typedef {import('../selection/Selection').default} Selection
*/

/**
* Select element after auto placement.
*
Expand Down
16 changes: 11 additions & 5 deletions lib/features/auto-place/AutoPlaceUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ import {
reduce
} from 'min-dash';

/**
* @typedef {import('../../model').Shape} Shape
*
* @typedef {import('../../util/Types').Point} Point
*/

// padding to detect element placement
var PLACEMENT_DETECTION_PAD = 10;

Expand All @@ -20,8 +26,8 @@ var DEFAULT_MAX_DISTANCE = 250;
/**
* Get free position starting from given position.
*
* @param {djs.model.Shape} source
* @param {djs.model.Shape} element
* @param {Shape} source
* @param {Shape} element
* @param {Point} position
* @param {Function} getNextPosition
*
Expand Down Expand Up @@ -116,7 +122,7 @@ export function getConnectedAtPosition(source, position, element) {
* Compute optimal distance between source and target based on existing connections to and from source.
* Assumes left-to-right and top-to-down modeling.
*
* @param {djs.model.Shape} source
* @param {Shape} source
* @param {Object} [hints]
* @param {number} [hints.defaultDistance]
* @param {string} [hints.direction]
Expand Down Expand Up @@ -255,9 +261,9 @@ export function getConnectedDistance(source, hints) {
* - host connected elements
* - attachers connected elements
*
* @param {djs.model.Shape} source
* @param {Shape} source
*
* @return {Array<djs.model.Shape>}
* @return {Array<Shape>}
*/
function getAutoPlaceClosure(source) {

Expand Down
39 changes: 26 additions & 13 deletions lib/features/auto-resize/AutoResize.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,19 @@ import {

import CommandInterceptor from '../../command/CommandInterceptor';

/**
* @typedef {import('../../model').Base} Base
* @typedef {import('../../model').Shape} Shape
*
* @typedef {import('../../util/Types').Direction} Direction
* @typedef {import('../../util/Types').Rect} Rect
* @typedef {import('../../util/Types').RectTRBL} RectTRBL
*
* @typedef {import('../../core/ElementRegistry').default} ElementRegistry
* @typedef {import('../../core/EventBus').default} EventBus
* @typedef {import('../modeling/Modeling').default} Modeling
* @typedef {import('../rules/Rules').default} Rules
*/

/**
* An auto resize component that takes care of expanding a parent element
Expand Down Expand Up @@ -132,8 +145,8 @@ inherits(AutoResize, CommandInterceptor);
* This method considers the current size, the added elements as well as
* the provided padding for the new bounds.
*
* @param {Array<djs.model.Shape>} elements
* @param {djs.model.Shape} target
* @param {Shape[]} elements
* @param {Shape} target
*/
AutoResize.prototype._getOptimalBounds = function(elements, target) {

Expand Down Expand Up @@ -168,8 +181,8 @@ AutoResize.prototype._getOptimalBounds = function(elements, target) {
/**
* Expand the target shape respecting rules, offset and padding
*
* @param {Array<djs.model.Shape>} elements
* @param {djs.model.Shape|string} target|targetId
* @param {Shape[]} elements
* @param {Shape|string} target The target or its ID.
*/
AutoResize.prototype._expand = function(elements, target) {

Expand Down Expand Up @@ -212,9 +225,9 @@ AutoResize.prototype._expand = function(elements, target) {
/**
* Get the amount to expand the given shape in each direction.
*
* @param {djs.model.Shape} shape
* @param {Shape} shape
*
* @return {TRBL}
* @return {RectTRBL}
*/
AutoResize.prototype.getOffset = function(shape) {
return { top: 60, bottom: 60, left: 100, right: 100 };
Expand All @@ -225,9 +238,9 @@ AutoResize.prototype.getOffset = function(shape) {
* Get the activation threshold for each side for which
* resize triggers.
*
* @param {djs.model.Shape} shape
* @param {Shape} shape
*
* @return {TRBL}
* @return {RectTRBL}
*/
AutoResize.prototype.getPadding = function(shape) {
return { top: 2, bottom: 2, left: 15, right: 15 };
Expand All @@ -237,8 +250,8 @@ AutoResize.prototype.getPadding = function(shape) {
/**
* Perform the actual resize operation.
*
* @param {djs.model.Shape} shape
* @param {Bounds} newBounds
* @param {Shape} shape
* @param {Rect} newBounds
* @param {Object} [hints]
* @param {string} [hints.autoResize]
*/
Expand All @@ -259,10 +272,10 @@ function boundsChanged(newBounds, oldBounds) {
/**
* Get directions of resize as {n|w|s|e} e.g. "nw".
*
* @param {Bounds} oldBounds
* @param {Bounds} newBounds
* @param {Rect} oldBounds
* @param {Rect} newBounds
*
* @returns {string} Resize directions as {n|w|s|e}.
* @returns {Direction} Resize directions as {n|w|s|e}.
*/
function getResizeDirections(oldBounds, newBounds) {
var directions = '';
Expand Down
12 changes: 10 additions & 2 deletions lib/features/auto-resize/AutoResizeProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,16 @@ import RuleProvider from '../rules/RuleProvider';

import inherits from 'inherits-browser';

/**
* @typedef {import('../../model').Shape} Shape
*
* @typedef {import('../../core/EventBus').default} EventBus
*/

/**
* This is a base rule provider for the element.autoResize rule.
*
* @param {EventBus} eventBus
*/
export default function AutoResizeProvider(eventBus) {

Expand All @@ -23,8 +31,8 @@ inherits(AutoResizeProvider, RuleProvider);
/**
* Needs to be implemented by sub classes to allow actual auto resize
*
* @param {Array<djs.model.Shape>} elements
* @param {djs.model.Shape} target
* @param {Shape[]} elements
* @param {Shape} target
*
* @return {boolean}
*/
Expand Down
Loading

0 comments on commit e7d1a18

Please sign in to comment.