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
Closes #1680
- Loading branch information
Showing
21 changed files
with
583 additions
and
7 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) { | ||
|
||
this._alignElements = alignElements; | ||
this._translate = translate; | ||
this._popupMenu = popupMenu; | ||
|
||
popupMenu.registerProvider('align-elements', this); | ||
} | ||
|
||
AlignElementsMenuProvider.$inject = [ | ||
'popupMenu', | ||
'alignElements', | ||
'translate' | ||
]; | ||
|
||
AlignElementsMenuProvider.prototype.getPopupMenuEntries = function(elements) { | ||
var entries = {}; | ||
|
||
if (this._isAllowed(elements)) { | ||
assign(entries, this._getEntries(elements)); | ||
} | ||
|
||
return entries; | ||
}; | ||
|
||
AlignElementsMenuProvider.prototype._isAllowed = function(elements) { | ||
|
||
// TODO(barmac): implement | ||
return true; | ||
}; | ||
|
||
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,20 @@ | ||
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'; | ||
|
||
export default { | ||
__depends__: [ | ||
AlignElementsModule, | ||
ContextPadModule, | ||
PopupMenuModule | ||
], | ||
__init__: [ | ||
'alignElementsContextPadProvider', | ||
'alignElementsMenuProvider' | ||
], | ||
alignElementsContextPadProvider: [ 'type', AlignElementsContextPadProvider ], | ||
alignElementsMenuProvider: [ 'type', AlignElementsMenuProvider ] | ||
}; |
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.
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.
Oops, something went wrong.