Skip to content

Commit

Permalink
feat(modeling): delete empty text boxes
Browse files Browse the repository at this point in the history
Closes #6
  • Loading branch information
Niklas Kiefer committed May 24, 2020
1 parent 6c1a7bd commit 55e68bd
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
38 changes: 38 additions & 0 deletions lib/features/modeling/behavior/EmptyTextBoxBehavior.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import inherits from 'inherits';

import {
is
} from '../../../util/ModelUtil';

import CommandInterceptor from 'diagram-js/lib/command/CommandInterceptor';


export default function EmptyTextBoxBehavior(eventBus, modeling) {

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);
}

inherits(EmptyTextBoxBehavior, CommandInterceptor);

EmptyTextBoxBehavior.$inject = [
'eventBus',
'modeling'
];


// helpers //////////

function isEmpty(label) {
return !label || label === '';
}
7 changes: 5 additions & 2 deletions lib/features/modeling/behavior/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import LabelBehavior from './LabelBehavior';
import ReplaceElementBehaviour from './ReplaceElementBehaviour';
import UnclaimIdBehavior from './UnclaimIdBehavior';
import CreateBoardElementBehavior from './CreateBoardElementBehavior';
import EmptyTextBoxBehavior from './EmptyTextBoxBehavior';

export default {
__init__: [
Expand All @@ -16,7 +17,8 @@ export default {
'labelBehavior',
'replaceElementBehaviour',
'unclaimIdBehavior',
'createBoardElementBehavior'
'createBoardElementBehavior',
'emptyTextBoxBehavior'
],
adaptiveLabelPositioningBehavior: [ 'type', AdaptiveLabelPositioningBehavior ],
appendBehavior: [ 'type', AppendBehavior ],
Expand All @@ -25,5 +27,6 @@ export default {
labelBehavior: [ 'type', LabelBehavior ],
replaceElementBehaviour: [ 'type', ReplaceElementBehaviour ],
unclaimIdBehavior: [ 'type', UnclaimIdBehavior ],
createBoardElementBehavior: [ 'type', CreateBoardElementBehavior ]
createBoardElementBehavior: [ 'type', CreateBoardElementBehavior ],
emptyTextBoxBehavior: [ 'type', EmptyTextBoxBehavior ]
};

0 comments on commit 55e68bd

Please sign in to comment.