Custom Rules for shape or element moved

Hi All,
I am trying to add a custom rule that doesn’t allow when an element or shape of type Task is moved from inside the subProcess in canvas.I have tried this =>

  this.addRule("shape.move.executed", 2000, function (context) {
    var target = context.target,
      typeOfElementSelected = context.shape.type;
    if (typeOfElementSelected === 'bpmn:Task' && target.type === 'bpmn:Process') {
      return false;
    } else {
      // not returning anything means other rule
      // providers can still do their work
      //
      // this allows us to reuse the existing BPMN rules
    }
  })

Also have tried to replace the event in this.addRule with - commandStack.shape.move.executed,shape.move.elements.move but it doesn’t apply as a rule.
Another rule as shape.create works fine but not the one that i have described.
Some infos would help me a lot.
Thank you

Please checkout how we implement move rules in BpmnRules. You’d want to hook in using a higher priority elements.move handler and return false to reject the move operation in your special case (or otherwise do nothing to allow default rules to kick in):

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

const HIGH_PRIORITY = 1500;

export default class CustomRuleProvider extends RuleProvider {
  constructor(eventBus) {
    super(eventBus);
  }

  init() {

    // a high priority rule that rejects a certain operation
    // before the default rules kick in
    this.addRule('elements.move', HIGH_PRIORITY, context => {
      if (context.elements.some(el => el.id === 'mike')) {
        return false;
      }
    });
  }
}

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.