Skip to content

Commit

Permalink
feat: add distribution buttons to multi-element context pad
Browse files Browse the repository at this point in the history
Closes #1680
  • Loading branch information
barmac committed Jun 10, 2022
1 parent 05a461c commit bc6e360
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 2 deletions.
@@ -0,0 +1,68 @@
import ICONS from './DistributeElementsIcons';

import { assign } from 'min-dash';

var LOW_PRIORITY = 900;

/**
* A provider for distribute elements context pad
*/
export default function DistributeElementsContextPadProvider(contextPad, distributeElements, translate) {

contextPad.registerProvider(LOW_PRIORITY, this);

this._contextPad = contextPad;

this._distributeElements = distributeElements;
this._translate = translate;
}

DistributeElementsContextPadProvider.$inject = [
'contextPad',
'distributeElements',
'translate'
];

DistributeElementsContextPadProvider.prototype.getMultiElementContextPadEntries = function(elements) {
var actions = {};

if (this._isAllowed(elements)) {
assign(actions, this._getEntries(elements));
}

return actions;
};

DistributeElementsContextPadProvider.prototype._isAllowed = function(elements) {
return true;
};

DistributeElementsContextPadProvider.prototype._getEntries = function(elements) {
var distributeElements = this._distributeElements,
translate = this._translate;

var entries = {
'distribute-elements-horizontally': {
group: 'distribute',
title: translate('Distribute elements horizontally'),
imageUrl: ICONS['horizontal'],
action: {
click: function(event, elements) {
distributeElements.trigger(elements, 'horizontal');
}
}
},
'distribute-elements-vertically': {
group: 'distribute',
title: translate('Distribute elements vertically'),
imageUrl: ICONS['vertical'],
action: {
click: function(event, elements) {
distributeElements.trigger(elements, 'vertical');
}
}
},
};

return entries;
};
10 changes: 10 additions & 0 deletions lib/features/distribute-elements/DistributeElementsIcons.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 9 additions & 2 deletions lib/features/distribute-elements/index.js
@@ -1,12 +1,19 @@
import DistributeElementsModule from 'diagram-js/lib/features/distribute-elements';
import ContextPadModule from 'diagram-js/lib/features/context-pad';

import BpmnDistributeElements from './BpmnDistributeElements';
import DistributeElementsContextPadProvider from './DistributeElementsContextPadProvider';


export default {
__depends__: [
ContextPadModule,
DistributeElementsModule
],
__init__: [ 'bpmnDistributeElements' ],
bpmnDistributeElements: [ 'type', BpmnDistributeElements ]
__init__: [
'bpmnDistributeElements',
'distributeElementsContextPadProvider'
],
bpmnDistributeElements: [ 'type', BpmnDistributeElements ],
distributeElementsContextPadProvider: [ 'type', DistributeElementsContextPadProvider ]
};

0 comments on commit bc6e360

Please sign in to comment.