chore(editor-actions): factor out into own component
Related to bpmn-io/diagram-js#177
This commit is contained in:
parent
224fa6da61
commit
e99214bb6a
|
@ -173,33 +173,26 @@ Modeler.prototype._collectIds = function(definitions, context) {
|
|||
|
||||
Modeler.prototype._interactionModules = [
|
||||
// non-modeling components
|
||||
require('./features/label-editing'),
|
||||
require('./features/auto-resize'),
|
||||
require('./features/search'),
|
||||
require('diagram-js/lib/navigation/zoomscroll'),
|
||||
require('diagram-js/lib/navigation/movecanvas'),
|
||||
require('diagram-js/lib/navigation/touch'),
|
||||
require('diagram-js/lib/features/auto-scroll')
|
||||
require('diagram-js/lib/navigation/zoomscroll')
|
||||
];
|
||||
|
||||
Modeler.prototype._modelingModules = [
|
||||
// modeling components
|
||||
require('diagram-js/lib/features/move'),
|
||||
require('diagram-js/lib/features/auto-scroll'),
|
||||
require('diagram-js/lib/features/bendpoints'),
|
||||
require('diagram-js/lib/features/move'),
|
||||
require('diagram-js/lib/features/resize'),
|
||||
require('diagram-js/lib/features/space-tool'),
|
||||
require('diagram-js/lib/features/lasso-tool'),
|
||||
require('diagram-js/lib/features/hand-tool'),
|
||||
require('diagram-js/lib/features/align-elements'),
|
||||
require('./features/global-connect'),
|
||||
require('./features/distribute-elements'),
|
||||
require('./features/keyboard'),
|
||||
require('./features/copy-paste'),
|
||||
require('./features/snapping'),
|
||||
require('./features/modeling'),
|
||||
require('./features/auto-resize'),
|
||||
require('./features/editor-actions'),
|
||||
require('./features/context-pad'),
|
||||
require('./features/keyboard'),
|
||||
require('./features/label-editing'),
|
||||
require('./features/modeling'),
|
||||
require('./features/palette'),
|
||||
require('./features/replace-preview')
|
||||
require('./features/replace-preview'),
|
||||
require('./features/snapping')
|
||||
];
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,99 @@
|
|||
'use strict';
|
||||
|
||||
var inherits = require('inherits');
|
||||
|
||||
var EditorActions = require('diagram-js/lib/features/editor-actions/EditorActions');
|
||||
|
||||
var filter = require('lodash/collection/filter');
|
||||
|
||||
var is = require('../../util/ModelUtil').is;
|
||||
|
||||
|
||||
function BpmnEditorActions(
|
||||
injector,
|
||||
canvas, elementRegistry, selection,
|
||||
spaceTool,
|
||||
lassoTool,
|
||||
handTool,
|
||||
globalConnect,
|
||||
distributeElements,
|
||||
alignElements,
|
||||
directEditing,
|
||||
searchPad) {
|
||||
|
||||
injector.invoke(EditorActions, this);
|
||||
|
||||
this.register({
|
||||
selectElements: function() {
|
||||
// select all elements except for the invisible
|
||||
// root element
|
||||
var rootElement = canvas.getRootElement();
|
||||
|
||||
var elements = elementRegistry.filter(function(element) {
|
||||
return element != rootElement;
|
||||
});
|
||||
|
||||
selection.select(elements);
|
||||
},
|
||||
spaceTool: function() {
|
||||
spaceTool.toggle();
|
||||
},
|
||||
lassoTool: function() {
|
||||
lassoTool.toggle();
|
||||
},
|
||||
handTool: function() {
|
||||
handTool.toggle();
|
||||
},
|
||||
globalConnectTool: function() {
|
||||
globalConnect.toggle();
|
||||
},
|
||||
distributeElements: function(opts) {
|
||||
var currentSelection = selection.get(),
|
||||
type = opts.type;
|
||||
|
||||
if (currentSelection.length) {
|
||||
distributeElements.trigger(currentSelection, type);
|
||||
}
|
||||
},
|
||||
alignElements: function(opts) {
|
||||
var currentSelection = selection.get(),
|
||||
aligneableElements = [],
|
||||
type = opts.type;
|
||||
|
||||
if (currentSelection.length) {
|
||||
aligneableElements = filter(currentSelection, function(element) {
|
||||
return !is(element, 'bpmn:Lane');
|
||||
});
|
||||
|
||||
alignElements.trigger(aligneableElements, type);
|
||||
}
|
||||
},
|
||||
directEditing: function() {
|
||||
var currentSelection = selection.get();
|
||||
|
||||
if (currentSelection.length) {
|
||||
directEditing.activate(currentSelection[0]);
|
||||
}
|
||||
},
|
||||
find: function() {
|
||||
searchPad.toggle();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
inherits(BpmnEditorActions, EditorActions);
|
||||
|
||||
BpmnEditorActions.$inject = [
|
||||
'injector',
|
||||
'canvas', 'elementRegistry', 'selection',
|
||||
'spaceTool',
|
||||
'lassoTool',
|
||||
'handTool',
|
||||
'globalConnect',
|
||||
'distributeElements',
|
||||
'alignElements',
|
||||
'directEditing',
|
||||
'searchPad'
|
||||
];
|
||||
|
||||
module.exports = BpmnEditorActions;
|
|
@ -0,0 +1,15 @@
|
|||
module.exports = {
|
||||
__depends__: [
|
||||
require('diagram-js/lib/features/align-elements'),
|
||||
require('diagram-js/lib/features/editor-actions'),
|
||||
require('diagram-js/lib/features/hand-tool'),
|
||||
require('diagram-js/lib/features/lasso-tool'),
|
||||
require('diagram-js/lib/features/space-tool'),
|
||||
require('../global-connect'),
|
||||
require('../copy-paste'),
|
||||
require('../distribute-elements'),
|
||||
require('../global-connect'),
|
||||
require('../search')
|
||||
],
|
||||
editorActions: [ 'type', require('./BpmnEditorActions') ]
|
||||
};
|
|
@ -1,70 +1,12 @@
|
|||
'use strict';
|
||||
|
||||
var filter = require('lodash/collection/filter');
|
||||
|
||||
var is = require('../../util/ModelUtil').is;
|
||||
|
||||
function BpmnKeyBindings(keyboard, spaceTool, lassoTool, handTool, globalConnect, distributeElements, alignElements, directEditing,
|
||||
searchPad, selection, canvas, elementRegistry, editorActions) {
|
||||
|
||||
var actions = {
|
||||
selectElements: function() {
|
||||
// select all elements except for the invisible
|
||||
// root element
|
||||
var rootElement = canvas.getRootElement();
|
||||
|
||||
var elements = elementRegistry.filter(function(element) {
|
||||
return element != rootElement;
|
||||
});
|
||||
|
||||
selection.select(elements);
|
||||
},
|
||||
spaceTool: function() {
|
||||
spaceTool.toggle();
|
||||
},
|
||||
lassoTool: function() {
|
||||
lassoTool.toggle();
|
||||
},
|
||||
handTool: function() {
|
||||
handTool.toggle();
|
||||
},
|
||||
globalConnectTool: function() {
|
||||
globalConnect.toggle();
|
||||
},
|
||||
distributeElements: function(opts) {
|
||||
var currentSelection = selection.get(),
|
||||
type = opts.type;
|
||||
|
||||
if (currentSelection.length) {
|
||||
distributeElements.trigger(currentSelection, type);
|
||||
}
|
||||
},
|
||||
alignElements: function(opts) {
|
||||
var currentSelection = selection.get(),
|
||||
aligneableElements = [],
|
||||
type = opts.type;
|
||||
|
||||
if (currentSelection.length) {
|
||||
aligneableElements = filter(currentSelection, function(element) {
|
||||
return !is(element, 'bpmn:Lane');
|
||||
});
|
||||
|
||||
alignElements.trigger(aligneableElements, type);
|
||||
}
|
||||
},
|
||||
directEditing: function() {
|
||||
var currentSelection = selection.get();
|
||||
|
||||
if (currentSelection.length) {
|
||||
directEditing.activate(currentSelection[0]);
|
||||
}
|
||||
},
|
||||
find: function() {
|
||||
searchPad.toggle();
|
||||
}
|
||||
};
|
||||
|
||||
editorActions.register(actions);
|
||||
/**
|
||||
* BPMN 2.0 specific key bindings.
|
||||
*
|
||||
* @param {Keyboard} keyboard
|
||||
* @param {EditorActions} editorActions
|
||||
*/
|
||||
function BpmnKeyBindings(keyboard, editorActions) {
|
||||
|
||||
keyboard.addListener(function(key, modifiers) {
|
||||
|
||||
|
@ -125,17 +67,6 @@ function BpmnKeyBindings(keyboard, spaceTool, lassoTool, handTool, globalConnect
|
|||
|
||||
BpmnKeyBindings.$inject = [
|
||||
'keyboard',
|
||||
'spaceTool',
|
||||
'lassoTool',
|
||||
'handTool',
|
||||
'globalConnect',
|
||||
'distributeElements',
|
||||
'alignElements',
|
||||
'directEditing',
|
||||
'searchPad',
|
||||
'selection',
|
||||
'canvas',
|
||||
'elementRegistry',
|
||||
'editorActions'
|
||||
];
|
||||
|
||||
|
|
|
@ -1,9 +1,6 @@
|
|||
module.exports = {
|
||||
__depends__: [
|
||||
require('diagram-js/lib/features/keyboard'),
|
||||
require('diagram-js/lib/features/align-elements'),
|
||||
require('../distribute-elements'),
|
||||
require('../global-connect')
|
||||
require('diagram-js/lib/features/keyboard')
|
||||
],
|
||||
__init__: [ 'bpmnKeyBindings' ],
|
||||
bpmnKeyBindings: [ 'type', require('./BpmnKeyBindings') ]
|
||||
|
|
|
@ -3,39 +3,29 @@
|
|||
var TestContainer = require('mocha-test-container-support');
|
||||
|
||||
var coreModule = require('../../../../lib/core'),
|
||||
modelingModule = require('../../../../lib/features/modeling'),
|
||||
editorActionsModule = require('../../../../lib/features/editor-actions'),
|
||||
keyboardModule = require('../../../../lib/features/keyboard'),
|
||||
bpmnSearchModule = require('../../../../lib/features/search'),
|
||||
selectionModule = require('diagram-js/lib/features/selection'),
|
||||
spaceToolModule = require('diagram-js/lib/features/space-tool'),
|
||||
lassoToolModule = require('diagram-js/lib/features/lasso-tool'),
|
||||
handToolModule = require('diagram-js/lib/features/hand-tool'),
|
||||
zoomScrollModule = require('diagram-js/lib/navigation/zoomscroll'),
|
||||
editorActionsModule = require('diagram-js/lib/features/editor-actions');
|
||||
modelingModule = require('../../../../lib/features/modeling');
|
||||
|
||||
var createKeyEvent = require('diagram-js/test/util/KeyEvents').createKeyEvent;
|
||||
|
||||
/* global bootstrapViewer, inject, sinon */
|
||||
|
||||
|
||||
describe('features - keyboard', function() {
|
||||
|
||||
var diagramXML = require('../../../fixtures/bpmn/simple.bpmn');
|
||||
|
||||
var testModules = [
|
||||
coreModule,
|
||||
modelingModule,
|
||||
selectionModule,
|
||||
spaceToolModule,
|
||||
bpmnSearchModule,
|
||||
lassoToolModule,
|
||||
handToolModule,
|
||||
editorActionsModule,
|
||||
keyboardModule,
|
||||
zoomScrollModule,
|
||||
editorActionsModule
|
||||
modelingModule
|
||||
];
|
||||
|
||||
beforeEach(bootstrapViewer(diagramXML, { modules: testModules }));
|
||||
|
||||
|
||||
describe('bpmn key bindings', function() {
|
||||
|
||||
var container;
|
||||
|
|
Loading…
Reference in New Issue