Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add distribution buttons to multi-element context pad
Closes #1680
- Loading branch information
Showing
3 changed files
with
87 additions
and
2 deletions.
There are no files selected for viewing
68 changes: 68 additions & 0 deletions
68
lib/features/distribute-elements/DistributeElementsContextPadProvider.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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
10
lib/features/distribute-elements/DistributeElementsIcons.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ] | ||
}; |