UNPKG

postit-js-core

Version:

[![Netlify Status](https://api.netlify.com/api/v1/badges/72130b1d-f56b-473e-8f3b-50a5af916e64/deploy-status)](https://app.netlify.com/sites/postit-js-demo/deploys) ![Build Status](https://github.com/pinussilvestrus/postit-js/workflows/ci/badge.svg)

50 lines (35 loc) 1.14 kB
import inherits from 'inherits'; import { is, getBusinessObject } from '../../../util/ModelUtil'; import CommandInterceptor from 'diagram-js/lib/command/CommandInterceptor'; export default function EmptyTextBoxBehavior(eventBus, modeling, directEditing) { CommandInterceptor.call(this, eventBus); // delete text box if it has no text this.postExecute('element.updateLabel', function(context) { var element = context.element, newLabel = context.newLabel; if (is(element, 'postit:TextBox') && isEmpty(newLabel)) { modeling.removeElements([ element ]); } }, true); eventBus.on('directEditing.cancel', 1001, function(event) { var active = event.active, element = active.element; if (is(element, 'postit:TextBox') && isEmpty(getBusinessObject(element).name)) { directEditing._active = false; modeling.removeElements([ element ]); } }); } inherits(EmptyTextBoxBehavior, CommandInterceptor); EmptyTextBoxBehavior.$inject = [ 'eventBus', 'modeling', 'directEditing' ]; // helpers ////////// function isEmpty(label) { return !label || label === ''; }