diff --git a/lib/Modeler.js b/lib/Modeler.js index b59a82da..56ecee91 100644 --- a/lib/Modeler.js +++ b/lib/Modeler.js @@ -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') ]; diff --git a/lib/features/editor-actions/BpmnEditorActions.js b/lib/features/editor-actions/BpmnEditorActions.js new file mode 100644 index 00000000..4f72f090 --- /dev/null +++ b/lib/features/editor-actions/BpmnEditorActions.js @@ -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; \ No newline at end of file diff --git a/lib/features/editor-actions/index.js b/lib/features/editor-actions/index.js new file mode 100644 index 00000000..f37308a4 --- /dev/null +++ b/lib/features/editor-actions/index.js @@ -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') ] +}; \ No newline at end of file diff --git a/lib/features/keyboard/BpmnKeyBindings.js b/lib/features/keyboard/BpmnKeyBindings.js index d7b65acc..d405ff67 100644 --- a/lib/features/keyboard/BpmnKeyBindings.js +++ b/lib/features/keyboard/BpmnKeyBindings.js @@ -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,18 +67,7 @@ function BpmnKeyBindings(keyboard, spaceTool, lassoTool, handTool, globalConnect BpmnKeyBindings.$inject = [ 'keyboard', - 'spaceTool', - 'lassoTool', - 'handTool', - 'globalConnect', - 'distributeElements', - 'alignElements', - 'directEditing', - 'searchPad', - 'selection', - 'canvas', - 'elementRegistry', 'editorActions' ]; -module.exports = BpmnKeyBindings; +module.exports = BpmnKeyBindings; \ No newline at end of file diff --git a/lib/features/keyboard/index.js b/lib/features/keyboard/index.js index 8ca165cd..d2fd69af 100644 --- a/lib/features/keyboard/index.js +++ b/lib/features/keyboard/index.js @@ -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') ] diff --git a/test/spec/features/keyboard/BpmnKeyBindingsSpec.js b/test/spec/features/keyboard/BpmnKeyBindingsSpec.js index 39a8cc9a..e080660d 100644 --- a/test/spec/features/keyboard/BpmnKeyBindingsSpec.js +++ b/test/spec/features/keyboard/BpmnKeyBindingsSpec.js @@ -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;