-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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 and distribution menu multi-element context pad
- Loading branch information
1 parent
51aa2cd
commit befe8b8
Showing
28 changed files
with
1,006 additions
and
129 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
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
87 changes: 87 additions & 0 deletions
87
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,87 @@ | ||
import { | ||
assign | ||
} from 'min-dash'; | ||
|
||
import ICONS from './AlignElementsIcons'; | ||
|
||
var LOW_PRIORITY = 900; | ||
|
||
/** | ||
* A provider for align elements context pad button | ||
*/ | ||
export default function AlignElementsContextPadProvider(contextPad, popupMenu, translate, canvas) { | ||
|
||
contextPad.registerProvider(LOW_PRIORITY, this); | ||
|
||
this._contextPad = contextPad; | ||
this._popupMenu = popupMenu; | ||
this._translate = translate; | ||
this._canvas = canvas; | ||
} | ||
|
||
AlignElementsContextPadProvider.$inject = [ | ||
'contextPad', | ||
'popupMenu', | ||
'translate', | ||
'canvas' | ||
]; | ||
|
||
AlignElementsContextPadProvider.prototype.getMultiElementContextPadEntries = function(elements) { | ||
var actions = {}; | ||
|
||
if (this._isAllowed(elements)) { | ||
assign(actions, this._getEntries(elements)); | ||
} | ||
|
||
return actions; | ||
}; | ||
|
||
AlignElementsContextPadProvider.prototype._isAllowed = function(elements) { | ||
return !this._popupMenu.isEmpty(elements, 'align-elements'); | ||
}; | ||
|
||
AlignElementsContextPadProvider.prototype._getEntries = function(elements) { | ||
var self = this; | ||
|
||
return { | ||
'align-elements': { | ||
group: 'align-elements', | ||
title: self._translate('Align elements'), | ||
imageUrl: ICONS['align'], | ||
action: { | ||
click: function(event, elements) { | ||
var position = self._getMenuPosition(elements); | ||
|
||
assign(position, { | ||
cursor: { | ||
x: event.x, | ||
y: event.y | ||
} | ||
}); | ||
|
||
self._popupMenu.open(elements, 'align-elements', position); | ||
} | ||
} | ||
} | ||
}; | ||
}; | ||
|
||
AlignElementsContextPadProvider.prototype._getMenuPosition = function(elements) { | ||
var Y_OFFSET = 5; | ||
|
||
var diagramContainer = this._canvas.getContainer(), | ||
pad = this._contextPad.getPad(elements).html; | ||
|
||
var diagramRect = diagramContainer.getBoundingClientRect(), | ||
padRect = pad.getBoundingClientRect(); | ||
|
||
var top = padRect.top - diagramRect.top; | ||
var left = padRect.left - diagramRect.left; | ||
|
||
var pos = { | ||
x: left, | ||
y: top + padRect.height + Y_OFFSET | ||
}; | ||
|
||
return pos; | ||
}; |
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,72 @@ | ||
import ICONS from './AlignElementsIcons'; | ||
|
||
import { | ||
assign, | ||
forEach, | ||
} from 'min-dash'; | ||
|
||
var ALIGNMENT_OPTIONS = [ | ||
'left', | ||
'center', | ||
'right', | ||
'top', | ||
'middle', | ||
'bottom' | ||
]; | ||
|
||
/** | ||
* A provider for align elements popup menu. | ||
*/ | ||
export default function AlignElementsMenuProvider(popupMenu, alignElements, translate, rules) { | ||
|
||
this._alignElements = alignElements; | ||
this._translate = translate; | ||
this._popupMenu = popupMenu; | ||
this._rules = rules; | ||
|
||
popupMenu.registerProvider('align-elements', this); | ||
} | ||
|
||
AlignElementsMenuProvider.$inject = [ | ||
'popupMenu', | ||
'alignElements', | ||
'translate', | ||
'rules' | ||
]; | ||
|
||
AlignElementsMenuProvider.prototype.getPopupMenuEntries = function(elements) { | ||
var entries = {}; | ||
|
||
if (this._isAllowed(elements)) { | ||
assign(entries, this._getEntries(elements)); | ||
} | ||
|
||
return entries; | ||
}; | ||
|
||
AlignElementsMenuProvider.prototype._isAllowed = function(elements) { | ||
return this._rules.allowed('elements.align', { elements: elements }); | ||
}; | ||
|
||
AlignElementsMenuProvider.prototype._getEntries = function(elements) { | ||
var alignElements = this._alignElements, | ||
translate = this._translate, | ||
popupMenu = this._popupMenu; | ||
|
||
var entries = {}; | ||
|
||
forEach(ALIGNMENT_OPTIONS, function(alignment) { | ||
entries[ 'align-elements-' + alignment ] = { | ||
group: 'align', | ||
title: translate('Align elements ' + alignment), | ||
className: 'bjs-align-elements-menu-entry', | ||
imageUrl: ICONS[alignment], | ||
action: function(event, entry) { | ||
alignElements.trigger(elements, alignment); | ||
popupMenu.close(); | ||
} | ||
}; | ||
}); | ||
|
||
return entries; | ||
}; |
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,39 @@ | ||
import inherits from 'inherits-browser'; | ||
|
||
import RuleProvider from 'diagram-js/lib/features/rules/RuleProvider'; | ||
import { getParents } from 'diagram-js/lib/util/Elements'; | ||
|
||
import { | ||
filter | ||
} from 'min-dash'; | ||
|
||
/** | ||
* Rule provider for alignment of BPMN elements. | ||
*/ | ||
export default function BpmnAlignElements(eventBus) { | ||
RuleProvider.call(this, eventBus); | ||
} | ||
|
||
BpmnAlignElements.$inject = [ 'eventBus' ]; | ||
|
||
inherits(BpmnAlignElements, RuleProvider); | ||
|
||
BpmnAlignElements.prototype.init = function() { | ||
this.addRule('elements.align', function(context) { | ||
var elements = context.elements; | ||
|
||
// filter out elements which cannot be aligned | ||
var filteredElements = filter(elements, function(element) { | ||
return !(element.waypoints || element.host || element.labelTarget); | ||
}); | ||
|
||
// filter out elements which are children of any of the selected elements | ||
filteredElements = getParents(filteredElements); | ||
|
||
if (filteredElements.length < 2) { | ||
return false; | ||
} | ||
|
||
return filteredElements; | ||
}); | ||
}; |
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,23 @@ | ||
import AlignElementsModule from 'diagram-js/lib/features/align-elements'; | ||
import ContextPadModule from 'diagram-js/lib/features/context-pad'; | ||
import PopupMenuModule from 'diagram-js/lib/features/popup-menu'; | ||
|
||
import AlignElementsContextPadProvider from './AlignElementsContextPadProvider'; | ||
import AlignElementsMenuProvider from './AlignElementsMenuProvider'; | ||
import BpmnAlignElements from './BpmnAlignElements'; | ||
|
||
export default { | ||
__depends__: [ | ||
AlignElementsModule, | ||
ContextPadModule, | ||
PopupMenuModule | ||
], | ||
__init__: [ | ||
'alignElementsContextPadProvider', | ||
'alignElementsMenuProvider', | ||
'bpmnAlignElements' | ||
], | ||
alignElementsContextPadProvider: [ 'type', AlignElementsContextPadProvider ], | ||
alignElementsMenuProvider: [ 'type', AlignElementsMenuProvider ], | ||
bpmnAlignElements: [ 'type', BpmnAlignElements] | ||
}; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions
5
lib/features/align-elements/resources/align-horizontal-center-tool.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions
5
lib/features/align-elements/resources/align-vertical-center-tool.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.