项目作者: bpmn-io

项目描述 :
An example how to add custom editor controls to bpmn-js
高级语言: JavaScript
项目地址: git://github.com/bpmn-io/bpmn-js-example-custom-controls.git
创建时间: 2019-03-27T16:19:05Z
项目社区:https://github.com/bpmn-io/bpmn-js-example-custom-controls

开源协议:

下载


This example is part of our :notebook: custom elements guide. Checkout the final result here.

bpmn-js Example: Custom Controls

An example of creating custom editing controls for bpmn-js. Use this blueprint to suite the BPMN modeler to your specific needs.

About

This example adds controls that allow you to create bpmn:ServiceTask elements through the palette and the context pad.

Screencast

Creating Custom Controls

First, let’s add the ability to create bpmn:ServiceTask elements through the palette. We’ll create a new module that will register itself with the palette as a provider for entries. We don’t need to override the existing provider since we want to keep the existing entries. Our provider implements a getPaletteEntries method that returns a single entry:

  1. getPaletteEntries(element) {
  2. const {
  3. create,
  4. elementFactory,
  5. translate
  6. } = this;
  7. function createServiceTask(event) {
  8. const shape = elementFactory.createShape({ type: 'bpmn:ServiceTask' });
  9. create.start(event, shape);
  10. }
  11. return {
  12. 'create.service-task': {
  13. group: 'activity',
  14. className: 'bpmn-icon-service-task',
  15. title: translate('Create ServiceTask'),
  16. action: {
  17. dragstart: createServiceTask,
  18. click: createServiceTask
  19. }
  20. }
  21. }
  22. }

You can use the group property to group multiple entries. In this case, we’re adding our entry to an existing group. Using the className property, you can style your entry through CSS. We’re using a class that is part of bpmn-font, so there will be a service task icon in the palette. Using the action property, we decide what happens when the user clicks or drags the icon.

See the entire palette here.

Now, let’s also add the ability to create bpmn:ServiceTask elements through the context-pad:

  1. 'append.service-task': {
  2. group: 'model',
  3. className: 'bpmn-icon-service-task',
  4. title: translate('Append ServiceTask'),
  5. action: {
  6. click: appendServiceTask,
  7. dragstart: appendServiceTaskStart
  8. }
  9. }

See the entire context pad here.

Next, let’s add our custom controls to bpmn-js.

Adding the Custom Controls to bpmn-js

When creating a new instance of bpmn-js we need to add our custom controls using the additionalModules property:

  1. import BpmnModeler from 'bpmn-js/lib/Modeler';
  2. import customControlsModule from './custom';
  3. const bpmnModeler = new BpmnModeler({
  4. additionalModules: [
  5. customControlsModule
  6. ]
  7. });

Our custom controls will now be added to bpmn-js.

Run the Example

You need a NodeJS development stack with npm installed to build the project.

To install all project dependencies execute

  1. npm install

To start the example execute

  1. npm start

To build the example into the public folder execute

  1. npm run all

License

MIT