@@ -4,14 +4,16 @@ import {
44 GraphComponent ,
55 GraphInputMode ,
66 GraphItemTypes ,
7- ICommand ,
7+ Command ,
88 IModelItem ,
9- KeyboardInputModeBinding
10- } from 'yfiles'
9+ KeyboardInputModeBinding ,
10+ ExecuteCommandArgs ,
11+ CanExecuteCommandArgs
12+ } from '@yfiles/yfiles'
1113
1214// TODO move to core?
1315
14- type Recognizer = ( eventSource : any , evt : EventArgs ) => boolean
16+ type Recognizer = ( evt : EventArgs , eventSource : any ) => boolean
1517
1618let commandBindings : KeyboardInputModeBinding [ ] = [ ]
1719
@@ -32,13 +34,13 @@ export function disableSingleSelection(graphComponent: GraphComponent) {
3234 }
3335
3436 // re-activate commands
35- mode . availableCommands . add ( ICommand . TOGGLE_ITEM_SELECTION )
36- mode . availableCommands . add ( ICommand . SELECT_ALL )
37+ mode . availableCommands . add ( Command . TOGGLE_ITEM_SELECTION )
38+ mode . availableCommands . add ( Command . SELECT_ALL )
3739
38- mode . navigationInputMode . availableCommands . add ( ICommand . EXTEND_SELECTION_LEFT )
39- mode . navigationInputMode . availableCommands . add ( ICommand . EXTEND_SELECTION_UP )
40- mode . navigationInputMode . availableCommands . add ( ICommand . EXTEND_SELECTION_DOWN )
41- mode . navigationInputMode . availableCommands . add ( ICommand . EXTEND_SELECTION_RIGHT )
40+ mode . navigationInputMode . availableCommands . add ( Command . EXTEND_SELECTION_LEFT )
41+ mode . navigationInputMode . availableCommands . add ( Command . EXTEND_SELECTION_UP )
42+ mode . navigationInputMode . availableCommands . add ( Command . EXTEND_SELECTION_DOWN )
43+ mode . navigationInputMode . availableCommands . add ( Command . EXTEND_SELECTION_RIGHT )
4244
4345 // remove the previously registered command bindings
4446 for ( const binding of commandBindings ) {
@@ -61,26 +63,35 @@ export function enableSingleSelection(graphComponent: GraphComponent) {
6163 mode . multiSelectionRecognizer = EventRecognizers . NEVER
6264
6365 // deactivate commands that can lead to multi selection
64- mode . availableCommands . remove ( ICommand . TOGGLE_ITEM_SELECTION )
65- mode . availableCommands . remove ( ICommand . SELECT_ALL )
66+ mode . availableCommands . remove ( Command . TOGGLE_ITEM_SELECTION )
67+ mode . availableCommands . remove ( Command . SELECT_ALL )
6668
67- mode . navigationInputMode . availableCommands . remove ( ICommand . EXTEND_SELECTION_LEFT )
68- mode . navigationInputMode . availableCommands . remove ( ICommand . EXTEND_SELECTION_UP )
69- mode . navigationInputMode . availableCommands . remove ( ICommand . EXTEND_SELECTION_DOWN )
70- mode . navigationInputMode . availableCommands . remove ( ICommand . EXTEND_SELECTION_RIGHT )
69+ mode . navigationInputMode . availableCommands . remove ( Command . EXTEND_SELECTION_LEFT )
70+ mode . navigationInputMode . availableCommands . remove ( Command . EXTEND_SELECTION_UP )
71+ mode . navigationInputMode . availableCommands . remove ( Command . EXTEND_SELECTION_DOWN )
72+ mode . navigationInputMode . availableCommands . remove ( Command . EXTEND_SELECTION_RIGHT )
7173
7274 // add dummy command bindings that do nothing in order to prevent default behavior
73- commandBindings . push ( mode . keyboardInputMode . addCommandBinding ( ICommand . EXTEND_SELECTION_LEFT ) )
74- commandBindings . push ( mode . keyboardInputMode . addCommandBinding ( ICommand . EXTEND_SELECTION_UP ) )
75- commandBindings . push ( mode . keyboardInputMode . addCommandBinding ( ICommand . EXTEND_SELECTION_DOWN ) )
76- commandBindings . push ( mode . keyboardInputMode . addCommandBinding ( ICommand . EXTEND_SELECTION_RIGHT ) )
75+ const dummyExecutedHandler = ( _ : ExecuteCommandArgs ) => { }
76+ commandBindings . push (
77+ mode . keyboardInputMode . addCommandBinding ( Command . EXTEND_SELECTION_LEFT , dummyExecutedHandler )
78+ )
79+ commandBindings . push (
80+ mode . keyboardInputMode . addCommandBinding ( Command . EXTEND_SELECTION_UP , dummyExecutedHandler )
81+ )
82+ commandBindings . push (
83+ mode . keyboardInputMode . addCommandBinding ( Command . EXTEND_SELECTION_DOWN , dummyExecutedHandler )
84+ )
85+ commandBindings . push (
86+ mode . keyboardInputMode . addCommandBinding ( Command . EXTEND_SELECTION_RIGHT , dummyExecutedHandler )
87+ )
7788
7889 // add custom binding for toggle item selection
7990 commandBindings . push (
8091 mode . keyboardInputMode . addCommandBinding (
81- ICommand . TOGGLE_ITEM_SELECTION ,
82- ( command , parameter ) => toggleItemSelectionExecuted ( graphComponent , parameter ) ,
83- ( command , parameter ) => toggleItemSelectionCanExecute ( graphComponent , parameter )
92+ Command . TOGGLE_ITEM_SELECTION ,
93+ ( evt : ExecuteCommandArgs ) => toggleItemSelectionExecuted ( graphComponent , evt . parameter ) ,
94+ ( evt : CanExecuteCommandArgs ) => toggleItemSelectionCanExecute ( graphComponent , evt . parameter )
8495 )
8596 )
8697 // Also clear the selection - even though the setup works when more than one item is selected, it looks a bit
@@ -105,7 +116,7 @@ function toggleItemSelectionCanExecute(graphComponent: GraphComponent, parameter
105116 * @param graphComponent The given graphComponent
106117 * @param parameter The given parameter
107118 */
108- function toggleItemSelectionExecuted ( graphComponent : GraphComponent , parameter : any ) : boolean {
119+ function toggleItemSelectionExecuted ( graphComponent : GraphComponent , parameter : any ) : void {
109120 // get the item
110121 const modelItem = parameter instanceof IModelItem ? parameter : graphComponent . currentItem
111122 const inputMode = graphComponent . inputMode as GraphInputMode
@@ -117,10 +128,10 @@ function toggleItemSelectionExecuted(graphComponent: GraphComponent, parameter:
117128 ! GraphItemTypes . itemIsOfTypes ( inputMode . selectableItems , modelItem ) ||
118129 ! inputMode . graphSelection
119130 ) {
120- return false
131+ return
121132 }
122133
123- const isSelected = inputMode . graphSelection . isSelected ( modelItem )
134+ const isSelected = inputMode . graphSelection . includes ( modelItem )
124135 if ( isSelected ) {
125136 // the item is selected and needs to be unselected - just clear the selection
126137 inputMode . graphSelection . clear ( )
@@ -129,5 +140,4 @@ function toggleItemSelectionExecuted(graphComponent: GraphComponent, parameter:
129140 inputMode . graphSelection . clear ( )
130141 inputMode . setSelected ( modelItem , true )
131142 }
132- return true
133143}
0 commit comments