@@ -17,6 +17,10 @@ var _reactDom = require('react-dom');
17
17
18
18
var _reactDom2 = _interopRequireDefault ( _reactDom ) ;
19
19
20
+ var _Dom = require ( './util/Dom' ) ;
21
+
22
+ var _DomRoute = require ( './util/DomRoute' ) ;
23
+
20
24
var _DropdownMenu = require ( './components/DropdownMenu.js' ) ;
21
25
22
26
var _Svg = require ( './components/Svg.js' ) ;
@@ -59,17 +63,22 @@ require('./styles/menu.css');
59
63
var TOOLBAR_HEIGHT = 82 ,
60
64
PURPLE = '#5943aa' ,
61
65
ORANGE = '#ff7c35' ,
62
- GREEN = '#2ead6d' ,
63
66
RED = '#e31d65' ,
64
67
YELLOW = '#ffcc00' ,
65
- COLORS = [ PURPLE , ORANGE , GREEN , RED , YELLOW ] ;
68
+ COLORS = [ PURPLE , ORANGE , RED , YELLOW ] ;
69
+
70
+ var canvasElement ;
71
+
72
+ //<editor-fold desc="Helper functions">
73
+ function isCanvasElement ( route ) {
74
+ return route . contains ( canvasElement ) ;
75
+ }
66
76
67
- function extractPosition ( e ) {
68
- return {
69
- x : e . clientX ,
70
- y : e . clientY
71
- } ;
77
+ function isCircle ( target ) {
78
+ console . log ( 'target' , target ) ;
79
+ return isCanvasElement && target . id . startsWith ( 'circle' ) ;
72
80
}
81
+ //</editor-fold>
73
82
74
83
var App = exports . App = function ( _Component ) {
75
84
_inherits ( App , _Component ) ;
@@ -80,7 +89,7 @@ var App = exports.App = function (_Component) {
80
89
var _this = _possibleConstructorReturn ( this , Object . getPrototypeOf ( App ) . call ( this , props ) ) ;
81
90
82
91
_this . state = {
83
- showMenu : false ,
92
+ contextMenuVisible : false ,
84
93
openOnMouseOver : false ,
85
94
circles : [ {
86
95
x : 200 , y : 200 , r : 100 , color : PURPLE
@@ -90,75 +99,101 @@ var App = exports.App = function (_Component) {
90
99
current : - 1
91
100
} ;
92
101
93
- _this . onAppContextMenu = _this . onAppContextMenu . bind ( _this ) ;
94
- _this . onAppTouchStart = _this . onAppTouchStart . bind ( _this ) ;
95
- _this . onCircleContextMenu = _this . onCircleContextMenu . bind ( _this ) ;
96
- _this . onCircleTouchStart = _this . onCircleTouchStart . bind ( _this ) ;
97
102
_this . onMenuClose = _this . onMenuClose . bind ( _this ) ;
103
+ _this . onClickOutside = _this . onClickOutside . bind ( _this ) ;
104
+ _this . onContextMenu = _this . onContextMenu . bind ( _this ) ;
98
105
_this . executeCommand = _this . executeCommand . bind ( _this ) ;
99
- _this . onAnywhereClickOrContextMenu = _this . onAnywhereClickOrContextMenu . bind ( _this ) ;
100
106
107
+ // subscribing to menu event dispatcher
101
108
_MenuEventDispatcher2 . default . getInstance ( ) . connect ( {
102
- onAnywhereClick : _this . onAnywhereClickOrContextMenu ,
103
- onAnywhereContextMenu : _this . onAnywhereClickOrContextMenu
109
+ onClickOutside : _this . onClickOutside ,
110
+ onContextMenu : _this . onContextMenu
104
111
} ) ;
105
112
return _this ;
106
113
}
107
114
115
+ //<editor-fold desc="Handlers">
116
+ /**
117
+ * Fires when clicked outside of the current menu
118
+ */
119
+
120
+
108
121
_createClass ( App , [ {
109
- key : 'onAnywhereClickOrContextMenu ' ,
110
- value : function onAnywhereClickOrContextMenu ( e ) {
122
+ key : 'onClickOutside ' ,
123
+ value : function onClickOutside ( ) {
111
124
this . setState ( {
112
125
openOnMouseOver : false
113
126
} ) ;
114
127
}
115
128
116
- //<editor-fold desc="Show/hide menu">
129
+ /**
130
+ * Fires on contextmenu or tap-and-hold
131
+ * @param e
132
+ * @param position
133
+ * @param route DomRoute
134
+ */
117
135
118
136
} , {
119
- key : 'showMenu' ,
120
- value : function showMenu ( e , position , items ) {
121
- this . menuPosition = position ;
122
- e . preventDefault ( ) ;
123
- e . stopPropagation ( ) ;
137
+ key : 'onContextMenu' ,
138
+ value : function onContextMenu ( e , position , route ) {
139
+ console . log ( 'route' , route . getPath ( ) ) ;
140
+ //var target = route.getTarget();
141
+ var target = e . target ;
142
+
124
143
this . setState ( {
125
- showMenu : true ,
126
- items : items
144
+ openOnMouseOver : false
127
145
} ) ;
146
+
147
+ if ( ! isCanvasElement ( route ) ) {
148
+ return ; // we're interested only in canvas clicks
149
+ }
150
+ if ( isCircle ( target ) ) {
151
+ // circle clicked
152
+ this . selectCircle ( target ) ;
153
+ this . showContextMenu ( e , position , this . circleMenuItems ) ;
154
+ } else {
155
+ // background clicked
156
+ this . setState ( {
157
+ current : - 1
158
+ } ) ;
159
+ this . showContextMenu ( e , position , this . appMenuItems ) ;
160
+ }
128
161
}
129
- } , {
130
- key : 'onAppContextMenu' ,
131
- value : function onAppContextMenu ( e ) {
132
- this . showMenu ( e , extractPosition ( e ) , this . appMenuItems ) ;
133
- }
134
- } , {
135
- key : 'onAppTouchStart' ,
136
- value : function onAppTouchStart ( e ) {
137
- this . showMenu ( e , extractPosition ( e . nativeEvent . targetTouches [ 0 ] ) , this . appMenuItems ) ;
138
- }
139
- } , {
140
- key : 'onCircleContextMenu' ,
141
- value : function onCircleContextMenu ( source , e ) {
142
- this . state . current = source ;
143
- this . showMenu ( e , extractPosition ( e ) , this . circleMenuItems ) ;
144
- }
145
- } , {
146
- key : 'onCircleTouchStart' ,
147
- value : function onCircleTouchStart ( source , e ) {
148
- this . state . current = source ;
149
- this . showMenu ( e , extractPosition ( e . nativeEvent . targetTouches [ 0 ] ) , this . circleMenuItems ) ;
150
- }
162
+
163
+ /**
164
+ * Fires on menu close
165
+ * We would accomplish the same effect by subscribing to dispatched directly, instead of the Menu
166
+ */
167
+
151
168
} , {
152
169
key : 'onMenuClose' ,
153
170
value : function onMenuClose ( ) {
154
171
this . setState ( {
155
- showMenu : false ,
172
+ contextMenuVisible : false ,
156
173
current : - 1
157
174
} ) ;
158
175
}
159
176
//</editor-fold>
160
177
161
- //<editor-fold desc="Commands">
178
+ //<editor-fold desc="Show/hide menu">
179
+
180
+ } , {
181
+ key : 'showContextMenu' ,
182
+ value : function showContextMenu ( e , position , items ) {
183
+ var self = this ;
184
+
185
+ e . preventDefault ( ) ;
186
+ e . stopPropagation ( ) ;
187
+
188
+ self . setState ( {
189
+ contextMenuVisible : true ,
190
+ menuPosition : position ,
191
+ items : items
192
+ } ) ;
193
+ }
194
+ //</editor-fold>
195
+
196
+ //<editor-fold desc="Circles & commands">
162
197
163
198
} , {
164
199
key : 'executeCommand' ,
@@ -218,6 +253,13 @@ var App = exports.App = function (_Component) {
218
253
219
254
this . setState ( { circles : circles } ) ;
220
255
}
256
+ } , {
257
+ key : 'selectCircle' ,
258
+ value : function selectCircle ( circleElement ) {
259
+ var circleIndex = parseInt ( circleElement . id . split ( '-' ) [ 1 ] ) ;
260
+
261
+ this . state . current = circleIndex ;
262
+ }
221
263
} , {
222
264
key : 'bringToTop' ,
223
265
value : function bringToTop ( circles , circle , current ) {
@@ -233,7 +275,7 @@ var App = exports.App = function (_Component) {
233
275
} , {
234
276
key : 'newCircle' ,
235
277
value : function newCircle ( circles ) {
236
- var pos = this . menuPosition ,
278
+ var pos = this . state . menuPosition ,
237
279
r = Math . floor ( Math . random ( ) * 150 ) + 50 ,
238
280
color = COLORS [ Math . floor ( Math . random ( ) * COLORS . length ) ] ,
239
281
circle = {
@@ -254,43 +296,20 @@ var App = exports.App = function (_Component) {
254
296
}
255
297
//</editor-fold>
256
298
257
- } , {
258
- key : 'componentDidMount' ,
259
- value : function componentDidMount ( ) {
260
- var self = this ;
261
-
262
- function binder ( ) {
263
- var _self$executeCommand ;
264
-
265
- return ( _self$executeCommand = self . executeCommand ) . bind . apply ( _self$executeCommand , [ self ] . concat ( Array . prototype . slice . call ( arguments ) ) ) ;
266
- }
267
- this . circleMenuItems = new _CircleMenuItems . CircleMenuItems ( binder ) ;
268
- this . appMenuItems = new _AppMenuItems . AppMenuItems ( binder ) ;
269
- }
270
- } , {
271
- key : 'cancelEvent' ,
272
- value : function cancelEvent ( e ) {
273
- var e = event || window . event ;
274
- e . preventDefault && e . preventDefault ( ) ;
275
- e . stopPropagation && e . stopPropagation ( ) ;
276
- e . cancelBubble = true ;
277
- e . returnValue = false ;
278
- return false ;
279
- }
280
299
} , {
281
300
key : 'render' ,
282
301
value : function render ( ) {
283
302
var self = this ,
284
303
index = 0 ,
285
- menu = this . state . showMenu ? _react2 . default . createElement ( _Menu . Menu , { items : this . state . items , position : this . menuPosition , onClose : this . onMenuClose } ) : null ,
304
+ menu = this . state . contextMenuVisible ? _react2 . default . createElement ( _Menu . Menu , { items : this . state . items ,
305
+ position : this . state . menuPosition ,
306
+ onClose : this . onMenuClose } ) : null ,
286
307
circles = this . state . circles . map ( function ( circle ) {
287
- var circleIndex = index ++ ;
308
+ var circle = _react2 . default . createElement ( _Circle . Circle , _extends ( { } , circle , { id : 'circle-' + index , key : 'circle-' + index , strokeColor : 'white' ,
309
+ selected : self . state . current === index } ) ) ;
288
310
289
- return _react2 . default . createElement ( _Circle . Circle , _extends ( { } , circle , { key : 'circle-' + index , strokeColor : 'white' ,
290
- selected : self . state . current === index ,
291
- onContextMenu : self . onCircleContextMenu . bind ( this , circleIndex ) ,
292
- onTouchStart : self . onCircleTouchStart . bind ( this , circleIndex ) ,
293
- onMenuClose : self . onMenuClose } ) ) ;
311
+ index ++ ;
312
+ return circle ;
294
313
} ) ,
295
314
renderers = {
296
315
'link' : _LinkRenderer . LinkRenderer
@@ -307,20 +326,18 @@ var App = exports.App = function (_Component) {
307
326
308
327
return _react2 . default . createElement (
309
328
'div' ,
310
- { onContextMenu : this . onAppContextMenu ,
311
- onTouchStart : this . onAppTouchStart ,
312
- onTouchEnd : this . cancelEvent ,
313
- onTouchCancel : this . cancelEvent ,
314
- onTouchMove : this . cancelEvent } ,
329
+ null ,
315
330
_react2 . default . createElement (
316
331
'div' ,
317
332
{ className : 'toolbar' } ,
318
333
_react2 . default . createElement ( _DropdownMenu . DropdownMenu , _extends ( { buttonText : 'React Data Menu' , items : _items . items1 } , common ) ) ,
319
- _react2 . default . createElement ( _DropdownMenu . DropdownMenu , _extends ( { buttonText : 'Example' , items : _items2 . items2 } , common ) )
334
+ _react2 . default . createElement ( _DropdownMenu . DropdownMenu , _extends ( { buttonText : 'Menu 1' , items : _items2 . items2 } , common ) ) ,
335
+ _react2 . default . createElement ( _DropdownMenu . DropdownMenu , _extends ( { buttonText : 'Menu 2' , items : _items2 . items2 } , common ) ) ,
336
+ _react2 . default . createElement ( _DropdownMenu . DropdownMenu , _extends ( { buttonText : 'Menu 3' , items : _items2 . items2 } , common ) )
320
337
) ,
321
338
_react2 . default . createElement (
322
339
'div' ,
323
- { className : 'container' } ,
340
+ { ref : 'canvas' , className : 'container' } ,
324
341
_react2 . default . createElement (
325
342
_Svg . Svg ,
326
343
{ width : '100%' , height : '100%' } ,
@@ -334,19 +351,22 @@ var App = exports.App = function (_Component) {
334
351
{ className : 'toolbar toolbar-bottom' } ,
335
352
_react2 . default . createElement (
336
353
_DropdownMenu . DropdownMenu ,
337
- _extends ( { items : _items . items1 } , common ) ,
354
+ _extends ( { items : _items . items1 } , common , { toggleMode : false } ) ,
338
355
_react2 . default . createElement (
339
356
'button' ,
340
- { ref : 'button' , className : 'menu-button' } ,
341
- 'Nice menu? '
357
+ { className : 'menu-button' } ,
358
+ 'Menu 4 '
342
359
)
343
360
) ,
361
+ _react2 . default . createElement ( _DropdownMenu . DropdownMenu , _extends ( { buttonText : 'Menu 5' , items : _items2 . items2 } , common , { toggleMode : false } ) ) ,
362
+ _react2 . default . createElement ( _DropdownMenu . DropdownMenu , _extends ( { buttonText : 'Menu 6' , items : _items2 . items2 } , common , { toggleMode : false } ) ) ,
344
363
_react2 . default . createElement (
345
364
_DropdownMenu . DropdownMenu ,
346
365
{
347
366
items : _helpItems . helpItems ,
348
367
className : 'about' ,
349
368
classPrefix : 'help-' ,
369
+ toggleMode : false ,
350
370
openOnMouseOver : true ,
351
371
closeOnMouseOut : false ,
352
372
mouseEnterDelay : 500 ,
@@ -359,13 +379,28 @@ var App = exports.App = function (_Component) {
359
379
} } ,
360
380
_react2 . default . createElement (
361
381
'button' ,
362
- { ref : 'button' , className : 'menu-button' } ,
382
+ { className : 'menu-button' } ,
363
383
'?'
364
384
)
365
385
)
366
386
)
367
387
) ;
368
388
}
389
+ } , {
390
+ key : 'componentDidMount' ,
391
+ value : function componentDidMount ( ) {
392
+ var self = this ;
393
+
394
+ function binder ( ) {
395
+ var _self$executeCommand ;
396
+
397
+ return ( _self$executeCommand = self . executeCommand ) . bind . apply ( _self$executeCommand , [ self ] . concat ( Array . prototype . slice . call ( arguments ) ) ) ;
398
+ }
399
+ this . circleMenuItems = new _CircleMenuItems . CircleMenuItems ( binder ) ;
400
+ this . appMenuItems = new _AppMenuItems . AppMenuItems ( binder ) ;
401
+
402
+ canvasElement = _reactDom2 . default . findDOMNode ( this . refs . canvas ) ;
403
+ }
369
404
} ] ) ;
370
405
371
406
return App ;
0 commit comments