Skip to content

Commit

Permalink
chore: move model types to dedicated model directory
Browse files Browse the repository at this point in the history
  • Loading branch information
philippfromme committed Apr 5, 2023
1 parent 5d5f601 commit fb3cc83
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 51 deletions.
3 changes: 1 addition & 2 deletions lib/BaseModeler.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ import BaseViewer from './BaseViewer';

/**
* @typedef {import('./BaseViewer').BaseViewerOptions} BaseViewerOptions
* @typedef {import('./BaseViewer').ModdleElement} ModdleElement
* @typedef {import('./BaseViewer').ModdleElementsById} ModdleElementsById
*
* @typedef {any} Moddle
* @typedef {import('./model/Types').ModdleElement} ModdleElement
*/

/**
Expand Down
21 changes: 17 additions & 4 deletions lib/BaseViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ import {
/**
* @typedef {import('didi').ModuleDeclaration} ModuleDeclaration
*
* @typedef {import('./model/Types').Moddle} Moddle
* @typedef {import('./model/Types').ModdleElement} ModdleElement
* @typedef {import('./model/Types').ModdleExtension} ModdleExtension
*
* @typedef { {
* width?: number|string;
* height?: number|string;
Expand All @@ -53,12 +57,8 @@ import {
* additionalModules?: ModuleDeclaration[];
* } } BaseViewerOptions
*
* @typedef {any} ModdleElement
*
* @typedef {Record<string, ModdleElement>} ModdleElementsById
*
* @typedef {Object} ModdleExtension
*
* @typedef { {
* [key: string]: ModdleExtension;
* } } ModdleExtensions
Expand Down Expand Up @@ -135,6 +135,9 @@ export default function BaseViewer(options) {
*/
options = assign({}, DEFAULT_OPTIONS, options);

/**
* @type {Moddle}
*/
this._moddle = this._createModdle(options);

/**
Expand Down Expand Up @@ -734,6 +737,11 @@ BaseViewer.prototype._emit = function(type, event) {
return this.get('eventBus').fire(type, event);
};

/**
* @param {BaseViewerOptions} options
*
* @returns {HTMLElement}
*/
BaseViewer.prototype._createContainer = function(options) {

const container = domify('<div class="bjs-container"></div>');
Expand All @@ -747,6 +755,11 @@ BaseViewer.prototype._createContainer = function(options) {
return container;
};

/**
* @param {BaseViewerOptions} options
*
* @returns {Moddle}
*/
BaseViewer.prototype._createModdle = function(options) {
const moddleOptions = assign({}, this._moddleExtensions, options.moddleExtensions);

Expand Down
4 changes: 2 additions & 2 deletions lib/features/modeling/BpmnFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import {
} from '../../util/ModelUtil';

/**
* @typedef {import('../../BaseModeler').Moddle} Moddle
* @typedef {import('../../BaseViewer').ModdleElement} ModdleElement
* @typedef {import('../../model/Types').Moddle} Moddle
* @typedef {import('../../model/Types').ModdleElement} ModdleElement
*
* @typedef {import('diagram-js/lib/util/Types').Point} Point
*/
Expand Down
10 changes: 6 additions & 4 deletions lib/features/modeling/BpmnLayouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,18 @@ import { is } from '../../util/ModelUtil';
/**
* @typedef {import('diagram-js/lib/util/Types').Point} Point
*
* @typedef {import('./ElementFactory').BpmnConnection} BpmnConnection
* @typedef {import('./ElementFactory').BpmnElement} BpmnElement
* @typedef {import('../../model/Types').BpmnConnection} BpmnConnection
* @typedef {import('../../model/Types').BpmnElement} BpmnElement
*
* @typedef {import('diagram-js/lib/layout/BaseLayouter').LayoutConnectionHints} LayoutConnectionHints
*
* @typedef { {
* source?: BpmnElement;
* target?: BpmnElement;
* waypoints?: Point[];
* connectionStart?: Point;
* connectionEnd?: Point;
* } } LayoutConnectionHints
* } & LayoutConnectionHints } BpmnLayoutConnectionHints
*/

var ATTACH_ORIENTATION_PADDING = -10,
Expand Down Expand Up @@ -66,7 +68,7 @@ inherits(BpmnLayouter, BaseLayouter);
* Returns waypoints of laid out connection.
*
* @param {BpmnConnection} connection
* @param {LayoutConnectionHints} [hints]
* @param {BpmnLayoutConnectionHints} [hints]
*
* @return {Point[]}
*/
Expand Down
11 changes: 5 additions & 6 deletions lib/features/modeling/BpmnUpdater.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,11 @@ import CommandInterceptor from 'diagram-js/lib/command/CommandInterceptor';
* @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
* @typedef {import('../../model/Types').BpmnConnection} BpmnConnection
* @typedef {import('../../model/Types').BpmnElement} BpmnElement
* @typedef {import('../../model/Types').BpmnShape} BpmnShape
* @typedef {import('../../model/Types').BpmnParent} BpmnParent
* @typedef {import('../../model/Types').ModdleElement} ModdleElement
*/

/**
Expand Down
41 changes: 8 additions & 33 deletions lib/features/modeling/ElementFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,45 +33,20 @@ import {
} from '../../util/CompatibilityUtil';

/**
* @typedef {import('diagram-js/lib/model').Element} Element
* @typedef {import('diagram-js/lib/model').Connection} Connection
* @typedef {import('diagram-js/lib/model').Label} Label
* @typedef {import('diagram-js/lib/model').Root} Root
* @typedef {import('diagram-js/lib/model').Shape} Shape
*
* @typedef {import('diagram-js/lib/i18n/translate/translate').default} Translate
*
* @typedef {import('diagram-js/lib/util/Types').Dimensions} Dimensions
*
* @typedef {import('./BpmnFactory').default} BpmnFactory
*
* @typedef {import('../../BaseModeler').Moddle} Moddle
* @typedef {import('../../BaseViewer').ModdleElement} ModdleElement
*/

/**
* @typedef { {
* businessObject: any;
* di: any;
* type: string;
* } & Element } BpmnElement
*
* @typedef { {
* associationDirection: 'None' | 'One' | 'Both';
* cancelActivity: boolean;
* eventDefinitionType: string;
* isExpanded: boolean;
* isForCompensation: boolean;
* isInterrupting: boolean;
* processRef: ModdleElement;
* triggeredByEvent: boolean;
* } } BpmnAttributes
*
* @typedef {Connection & BpmnElement} BpmnConnection
* @typedef {Label & BpmnElement} BpmnLabel
* @typedef {Root & BpmnElement} BpmnRoot
* @typedef {Shape & BpmnElement} BpmnShape
* @typedef {BpmnRoot | BpmnShape} BpmnParent
* @typedef {import('../../model/Types').BpmnAttributes} BpmnAttributes
* @typedef {import('../../model/Types').BpmnConnection} BpmnConnection
* @typedef {import('../../model/Types').BpmnElement} BpmnElement
* @typedef {import('../../model/Types').BpmnLabel} BpmnLabel
* @typedef {import('../../model/Types').BpmnRoot} BpmnRoot
* @typedef {import('../../model/Types').BpmnShape} BpmnShape
* @typedef {import('../../model/Types').Moddle} Moddle
* @typedef {import('../../model/Types').ModdleElement} ModdleElement
*/

/**
Expand Down
39 changes: 39 additions & 0 deletions lib/model/Types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import {
Connection,
Label,
Root,
Shape
} from "diagram-js/lib/model";

export type Moddle = any;

export type ModdleElement = any;

export type ModdleExtension = {};

export type BpmnAttributes = {
associationDirection: 'None' | 'One' | 'Both';
cancelActivity: boolean;
eventDefinitionType: string;
isExpanded: boolean;
isForCompensation: boolean;
isInterrupting: boolean;
processRef: ModdleElement;
triggeredByEvent: boolean;
};

export type BpmnElement = {
businessObject: any;
di: any;
type: string;
};

export type BpmnConnection = Connection & BpmnElement;

export type BpmnLabel = Label & BpmnElement;

export type BpmnRoot = Root & BpmnElement;

export type BpmnShape = Shape & BpmnElement;

export type BpmnParent = BpmnRoot | BpmnShape;

0 comments on commit fb3cc83

Please sign in to comment.