Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wip: Add type declarations to Modeling.js #1881

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions lib/BaseViewer.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ declare namespace Events {
* A `import.parse.start` event.
*/
export type ImportParseStart = {

/**
* The XML that is to be parsed.
*/
Expand All @@ -93,7 +93,7 @@ declare namespace Events {
* A `import.parse.complete` event.
*/
export type ImportParseComplete = {

/**
* An error thrown when parsing the XML.
*/
Expand Down Expand Up @@ -151,7 +151,7 @@ declare namespace Events {
* A `saveXML.done` event.
*/
export type SaveXMLDone = SaveXMLResult & Event;

/**
* A `saveSVG.done` event.
*/
Expand Down Expand Up @@ -268,11 +268,11 @@ export default class BaseViewer extends Diagram {
*
* @throws An error thrown during export.
*
* @param options The options.
* @param [options] The options.
*
* @return A promise resolving with the XML.
*/
saveXML(options: SaveXMLOptions): Promise<SaveXMLResult>;
saveXML(options?: SaveXMLOptions): Promise<SaveXMLResult>;

/**
* Export the currently displayed BPMN 2.0 diagram as
Expand Down Expand Up @@ -363,4 +363,4 @@ export default class BaseViewer extends Diagram {
* Detach the viewer.
*/
detach(): void;
}
}
60 changes: 60 additions & 0 deletions lib/features/modeling/Modeling.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import BaseModeling, { ModelingHints } from 'diagram-js/lib/features/modeling/Modeling';
import EventBus from 'diagram-js/lib/core/EventBus';
import ElementFactory from 'diagram-js/lib/core/ElementFactory';
import CommandStack, { CommandHandlerConstructor } from 'diagram-js/lib/command/CommandStack';
import { Base, ModelAttrsConnection, Root, Shape } from 'diagram-js/lib/model';
import { DirectionTRBL, Rect } from 'diagram-js/lib/util/Types';
import { ModdleElement } from '../../BaseViewer';

export type ModelingUpdateLabelHints = {
removeShape?: boolean
} & ModelingHints

export type ModelingColorsHints = {
fill?: string
stroke?: string
} & ModelingHints

/**
* BPMN 2.0 modeling features activator
*
* @param {EventBus} eventBus
* @param {ElementFactory} elementFactory
* @param {CommandStack} commandStack
* @param {BpmnRules} bpmnRules
*/
export default class Modeling extends BaseModeling {
constructor(eventBus: EventBus, elementFactory: ElementFactory, commandStack: CommandStack, bpmnRules: Object);

getHandlers(): Map<string, CommandHandlerConstructor>;

updateLabel(element: Base, newLabel: string, newBounds?: Rect, hints?: ModelingUpdateLabelHints): void;

connect(source: Base, target: Base, attrs?: ModelAttrsConnection, hints?: ModelingHints): typeof BaseModeling.prototype.createConnection;

updateModdleProperties(source: Base, target: ModdleElement, properties: Record<string, unknown>): void;

updateProperties(source: Base, properties: Record<string, unknown>): void;

resizeLane(laneShape: Base, newBounds: Rect, balanced?: boolean): void;

addLane(targetLaneShape: Shape, location?: DirectionTRBL): Shape;

splitLane(targetLane: Shape, count: number): void;

makeCollaboration(): Root;

updateLaneRefs(flowNodeShapes: Shape[], laneShapes: Shape[]): void;

/**
* Transform the current diagram into a process.
*/
makeProcess(): void;

claimId(id: string, moddleElement: ModdleElement): void;

unclaimId(id: string, moddleElement: ModdleElement): void;

setColor(elements: Base, colors?: ModelingColorsHints): void;
setColor(elements: Base[], colors?: ModelingColorsHints): void;
}
14 changes: 6 additions & 8 deletions lib/features/modeling/Modeling.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ Modeling.prototype.updateLabel = function(element, newLabel, newBounds, hints) {

Modeling.prototype.connect = function(source, target, attrs, hints) {

var bpmnRules = this._bpmnRules;
const bpmnRules = this._bpmnRules;

if (!attrs) {
attrs = bpmnRules.canConnect(source, target);
Expand Down Expand Up @@ -110,7 +110,7 @@ Modeling.prototype.resizeLane = function(laneShape, newBounds, balanced) {
};

Modeling.prototype.addLane = function(targetLaneShape, location) {
var context = {
const context = {
shape: targetLaneShape,
location: location
};
Expand All @@ -134,11 +134,11 @@ Modeling.prototype.splitLane = function(targetLane, count) {
*/
Modeling.prototype.makeCollaboration = function() {

var collaborationElement = this._create('root', {
const collaborationElement = this._create('root', {
type: 'bpmn:Collaboration'
});

var context = {
const context = {
newRoot: collaborationElement
};

Expand All @@ -157,16 +157,14 @@ Modeling.prototype.updateLaneRefs = function(flowNodeShapes, laneShapes) {

/**
* Transform the current diagram into a process.
*
* @return {djs.model.Root} the new root element
*/
Modeling.prototype.makeProcess = function() {

var processElement = this._create('root', {
const processElement = this._create('root', {
type: 'bpmn:Process'
});

var context = {
const context = {
newRoot: processElement
};

Expand Down