Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add alignment buttons for multi-element context pad
Related to #1680
- Loading branch information
Showing
13 changed files
with
263 additions
and
41 deletions.
There are no files selected for viewing
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
73 changes: 73 additions & 0 deletions
73
lib/features/align-elements/AlignElementsContextPadProvider.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,73 @@ | ||
import ICONS from './AlignElementsIcons'; | ||
|
||
import { | ||
assign, | ||
forEach | ||
} from 'min-dash'; | ||
|
||
var ALIGNMENT_OPTIONS = [ | ||
'left', | ||
'center', | ||
'right', | ||
'top', | ||
'middle', | ||
'bottom' | ||
]; | ||
|
||
var LOW_PRIORITY = 900; | ||
|
||
/** | ||
* A provider for BPMN 2.0 elements context pad | ||
*/ | ||
export default function AlignElementsContextPadProvider(contextPad, alignElements, translate) { | ||
|
||
contextPad.registerProvider(LOW_PRIORITY, this); | ||
|
||
this._contextPad = contextPad; | ||
|
||
this._alignElements = alignElements; | ||
this._translate = translate; | ||
} | ||
|
||
AlignElementsContextPadProvider.$inject = [ | ||
'contextPad', | ||
'alignElements', | ||
'translate' | ||
]; | ||
|
||
AlignElementsContextPadProvider.prototype.getMultiElementContextPadEntries = function(elements) { | ||
var actions = {}; | ||
|
||
if (this._isAllowed(elements)) { | ||
assign(actions, this._getEntries(elements)); | ||
} | ||
|
||
return actions; | ||
}; | ||
|
||
AlignElementsContextPadProvider.prototype._isAllowed = function(elements) { | ||
return true; | ||
}; | ||
|
||
AlignElementsContextPadProvider.prototype._getEntries = function(elements) { | ||
var alignElements = this._alignElements, | ||
translate = this._translate; | ||
|
||
var entries = {}; | ||
|
||
forEach(ALIGNMENT_OPTIONS, function(alignment) { | ||
entries['align-elements-' + alignment] = { | ||
group: 'align', | ||
className: 'bjs-align', | ||
title: translate('Align elements ' + alignment), | ||
imageUrl: ICONS[alignment], | ||
action: { | ||
click: function(event, elements) { | ||
alignElements.trigger(elements, alignment); | ||
} | ||
} | ||
}; | ||
}); | ||
|
||
return entries; | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import AlignElementsModule from 'diagram-js/lib/features/align-elements'; | ||
import ContextPadModule from 'diagram-js/lib/features/context-pad'; | ||
|
||
import AlignElementsContextPadProvider from './AlignElementsContextPadProvider'; | ||
|
||
export default { | ||
__depends__: [ | ||
AlignElementsModule, | ||
ContextPadModule | ||
], | ||
__init__: [ 'alignElementsContextPadProvider' ], | ||
alignElementsContextPadProvider: [ 'type', AlignElementsContextPadProvider ] | ||
}; |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions
1
lib/features/align-elements/resources/align-horizontal-center-tool.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions
1
lib/features/align-elements/resources/align-vertical-center-tool.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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
Oops, something went wrong.