CustomRule not work


I’m trying implement a custom Rule, but this not work very well.

I created a file with custom provider and add the rule:

this.addRule('shape.create', function(context) {

I debugged the code and this method is called when instance of bpmnj is created.

After of create instance, I inspected the eventBus and see the listner ‘commandStack.shape.create.canExecute’, but the rule not is called.

I’m develop with Angular 6.

CustomRuleProvider File:

import inherits from 'inherits';

import RuleProvider from 'diagram-js/lib/features/rules/RuleProvider';

export default function CustomRules(eventBus) {
    debugger;, eventBus);

inherits(CustomRules, RuleProvider);

CustomRules.$inject = [ 'eventBus' ];

CustomRules.prototype.init = function() {
  // there exist a number of modeling actions
  // that are identified by a unique ID. We
  // can hook into each one of them and make sure
  // they are only allowed if we say so
  this.addRule('shape.create', function(context) {
    return false;
    var shape = context.shape,
        target =;

    // we check for a custom vendor:allowDrop attribute
    // to be present on the BPMN 2.0 xml of the target
    // node
    // we could practically check for other things too,
    // such as incoming / outgoing connections, element
    // types, ...
    var shapeBo = shape.businessObject,
        targetBo = target.businessObject;

    var allowDrop = targetBo.get('vendor:allowDrop');

    if (!allowDrop || !shapeBo.$instanceOf(allowDrop)) {
      return false;

    // not returning anything means other rule
    // providers can still do their work
    // this allows us to reuse the existing BPMN rules

  this.addRule('shape.remove', 1, function(context) {
    return false;

Custom Rule File:

import CustomRules from './customRulesProvider.js';

export default {
  __init__: [ 'customRules' ],
  customRules: [ 'type', CustomRules ]
 this.viewer = new BpmnJS({
        width: '1000px',
        height: '1000px',
        keyboard: { bindTo: document },
        additionalModules: [   
          { [InjectionNames.paletteProvider]: ['type', PaletteProvider] }        
        linting: {
          bpmnlint: linterConfig

Hey, you can try giving your custom rule a high priority so it will be called before the default rule:

this.addRule('shape.create', 2000, function(context) { ... });

That might fix the issue.

@philippfromme Thanks for your reply, but it still doesn’t work :frowning:

For further assistance, please share a CodeSandbox that reproduces your issue in a way that we can inspect it.

@nikku thanks for you help!