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 = [
|
Modeler.prototype._interactionModules = [
|
||||||
// non-modeling components
|
// 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/movecanvas'),
|
||||||
require('diagram-js/lib/navigation/touch'),
|
require('diagram-js/lib/navigation/touch'),
|
||||||
require('diagram-js/lib/features/auto-scroll')
|
require('diagram-js/lib/navigation/zoomscroll')
|
||||||
];
|
];
|
||||||
|
|
||||||
Modeler.prototype._modelingModules = [
|
Modeler.prototype._modelingModules = [
|
||||||
// modeling components
|
// 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/bendpoints'),
|
||||||
|
require('diagram-js/lib/features/move'),
|
||||||
require('diagram-js/lib/features/resize'),
|
require('diagram-js/lib/features/resize'),
|
||||||
require('diagram-js/lib/features/space-tool'),
|
require('./features/auto-resize'),
|
||||||
require('diagram-js/lib/features/lasso-tool'),
|
require('./features/editor-actions'),
|
||||||
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/context-pad'),
|
require('./features/context-pad'),
|
||||||
|
require('./features/keyboard'),
|
||||||
|
require('./features/label-editing'),
|
||||||
|
require('./features/modeling'),
|
||||||
require('./features/palette'),
|
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';
|
'use strict';
|
||||||
|
|
||||||
var filter = require('lodash/collection/filter');
|
/**
|
||||||
|
* BPMN 2.0 specific key bindings.
|
||||||
var is = require('../../util/ModelUtil').is;
|
*
|
||||||
|
* @param {Keyboard} keyboard
|
||||||
function BpmnKeyBindings(keyboard, spaceTool, lassoTool, handTool, globalConnect, distributeElements, alignElements, directEditing,
|
* @param {EditorActions} editorActions
|
||||||
searchPad, selection, canvas, elementRegistry, editorActions) {
|
*/
|
||||||
|
function BpmnKeyBindings(keyboard, 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);
|
|
||||||
|
|
||||||
keyboard.addListener(function(key, modifiers) {
|
keyboard.addListener(function(key, modifiers) {
|
||||||
|
|
||||||
|
@ -125,18 +67,7 @@ function BpmnKeyBindings(keyboard, spaceTool, lassoTool, handTool, globalConnect
|
||||||
|
|
||||||
BpmnKeyBindings.$inject = [
|
BpmnKeyBindings.$inject = [
|
||||||
'keyboard',
|
'keyboard',
|
||||||
'spaceTool',
|
|
||||||
'lassoTool',
|
|
||||||
'handTool',
|
|
||||||
'globalConnect',
|
|
||||||
'distributeElements',
|
|
||||||
'alignElements',
|
|
||||||
'directEditing',
|
|
||||||
'searchPad',
|
|
||||||
'selection',
|
|
||||||
'canvas',
|
|
||||||
'elementRegistry',
|
|
||||||
'editorActions'
|
'editorActions'
|
||||||
];
|
];
|
||||||
|
|
||||||
module.exports = BpmnKeyBindings;
|
module.exports = BpmnKeyBindings;
|
|
@ -1,9 +1,6 @@
|
||||||
module.exports = {
|
module.exports = {
|
||||||
__depends__: [
|
__depends__: [
|
||||||
require('diagram-js/lib/features/keyboard'),
|
require('diagram-js/lib/features/keyboard')
|
||||||
require('diagram-js/lib/features/align-elements'),
|
|
||||||
require('../distribute-elements'),
|
|
||||||
require('../global-connect')
|
|
||||||
],
|
],
|
||||||
__init__: [ 'bpmnKeyBindings' ],
|
__init__: [ 'bpmnKeyBindings' ],
|
||||||
bpmnKeyBindings: [ 'type', require('./BpmnKeyBindings') ]
|
bpmnKeyBindings: [ 'type', require('./BpmnKeyBindings') ]
|
||||||
|
|
|
@ -3,39 +3,29 @@
|
||||||
var TestContainer = require('mocha-test-container-support');
|
var TestContainer = require('mocha-test-container-support');
|
||||||
|
|
||||||
var coreModule = require('../../../../lib/core'),
|
var coreModule = require('../../../../lib/core'),
|
||||||
modelingModule = require('../../../../lib/features/modeling'),
|
editorActionsModule = require('../../../../lib/features/editor-actions'),
|
||||||
keyboardModule = require('../../../../lib/features/keyboard'),
|
keyboardModule = require('../../../../lib/features/keyboard'),
|
||||||
bpmnSearchModule = require('../../../../lib/features/search'),
|
modelingModule = require('../../../../lib/features/modeling');
|
||||||
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');
|
|
||||||
|
|
||||||
var createKeyEvent = require('diagram-js/test/util/KeyEvents').createKeyEvent;
|
var createKeyEvent = require('diagram-js/test/util/KeyEvents').createKeyEvent;
|
||||||
|
|
||||||
/* global bootstrapViewer, inject, sinon */
|
/* global bootstrapViewer, inject, sinon */
|
||||||
|
|
||||||
|
|
||||||
describe('features - keyboard', function() {
|
describe('features - keyboard', function() {
|
||||||
|
|
||||||
var diagramXML = require('../../../fixtures/bpmn/simple.bpmn');
|
var diagramXML = require('../../../fixtures/bpmn/simple.bpmn');
|
||||||
|
|
||||||
var testModules = [
|
var testModules = [
|
||||||
coreModule,
|
coreModule,
|
||||||
modelingModule,
|
editorActionsModule,
|
||||||
selectionModule,
|
|
||||||
spaceToolModule,
|
|
||||||
bpmnSearchModule,
|
|
||||||
lassoToolModule,
|
|
||||||
handToolModule,
|
|
||||||
keyboardModule,
|
keyboardModule,
|
||||||
zoomScrollModule,
|
modelingModule
|
||||||
editorActionsModule
|
|
||||||
];
|
];
|
||||||
|
|
||||||
beforeEach(bootstrapViewer(diagramXML, { modules: testModules }));
|
beforeEach(bootstrapViewer(diagramXML, { modules: testModules }));
|
||||||
|
|
||||||
|
|
||||||
describe('bpmn key bindings', function() {
|
describe('bpmn key bindings', function() {
|
||||||
|
|
||||||
var container;
|
var container;
|
||||||
|
|
Loading…
Reference in New Issue