GithubHelp home page GithubHelp logo

bpmn-io / bpmn-js-example-custom-controls Goto Github PK

View Code? Open in Web Editor NEW
12.0 10.0 13.0 89 KB

An example how to add custom editor controls to bpmn-js

JavaScript 87.87% CSS 3.10% HTML 9.03%
bpmn-js

bpmn-js-example-custom-controls's Introduction

This example is part of our ๐Ÿ““ 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:

getPaletteEntries(element) {
    const {
      create,
      elementFactory,
      translate
    } = this;

    function createServiceTask(event) {
      const shape = elementFactory.createShape({ type: 'bpmn:ServiceTask' });

      create.start(event, shape);
    }

    return {
      'create.service-task': {
        group: 'activity',
        className: 'bpmn-icon-service-task',
        title: translate('Create ServiceTask'),
        action: {
          dragstart: createServiceTask,
          click: createServiceTask
        }
      }
    }
  }

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:

'append.service-task': {
  group: 'model',
  className: 'bpmn-icon-service-task',
  title: translate('Append ServiceTask'),
  action: {
    click: appendServiceTask,
    dragstart: appendServiceTaskStart
  }
}

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:

import BpmnModeler from 'bpmn-js/lib/Modeler';

import customControlsModule from './custom';

const bpmnModeler = new BpmnModeler({
  additionalModules: [
    customControlsModule
  ]
});

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

npm install

To start the example execute

npm start

To build the example into the public folder execute

npm run all

License

MIT

bpmn-js-example-custom-controls's People

Contributors

nikku avatar philippfromme avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.