@@ -28,6 +28,9 @@ export class AppComponent {
2828 )
2929 } ) ;
3030
31+ dia . commandHandler . archetypeGroupData = { key : 'Group' , isGroup : true } ;
32+
33+
3134 const makePort = function ( id : string , spot : go . Spot ) {
3235 return $ ( go . Shape , 'Circle' ,
3336 {
@@ -42,6 +45,17 @@ export class AppComponent {
4245 // define the Node template
4346 dia . nodeTemplate =
4447 $ ( go . Node , 'Spot' ,
48+ {
49+ contextMenu :
50+ $ ( 'ContextMenu' ,
51+ $ ( 'ContextMenuButton' ,
52+ $ ( go . TextBlock , 'Group' ) ,
53+ { click : function ( e , obj ) { e . diagram . commandHandler . groupSelection ( ) ; } } ,
54+ new go . Binding ( 'visible' , '' , function ( o ) {
55+ return o . diagram . selection . count > 1 ;
56+ } ) . ofObject ( ) )
57+ )
58+ } ,
4559 $ ( go . Panel , 'Auto' ,
4660 $ ( go . Shape , 'RoundedRectangle' , { stroke : null } ,
4761 new go . Binding ( 'fill' , 'color' )
@@ -74,9 +88,15 @@ export class AppComponent {
7488 ] ;
7589 public diagramDivClassName : string = 'myDiagramDiv' ;
7690 public diagramModelData = { prop : 'value' } ;
91+ public skipsDiagramUpdate = false ;
7792
7893 // When the diagram model changes, update app data to reflect those changes
7994 public diagramModelChange = function ( changes : go . IncrementalData ) {
95+ // when setting state here, be sure to set skipsDiagramUpdate: true since GoJS already has this update
96+ // (since this is a GoJS model changed listener event function)
97+ // this way, we don't log an unneeded transaction in the Diagram's undoManager history
98+ this . skipsDiagramUpdate = true ;
99+
80100 this . diagramNodeData = DataSyncService . syncNodeData ( changes , this . diagramNodeData ) ;
81101 this . diagramLinkData = DataSyncService . syncLinkData ( changes , this . diagramLinkData ) ;
82102 this . diagramModelData = DataSyncService . syncModelData ( changes , this . diagramModelData ) ;
@@ -171,6 +191,8 @@ export class AppComponent {
171191 }
172192
173193 if ( index >= 0 ) {
194+ // here, we set skipsDiagramUpdate to false, since GoJS does not yet have this update
195+ this . skipsDiagramUpdate = false ;
174196 this . diagramNodeData [ index ] = { key : newNodeData . key , color : newNodeData . color } ;
175197 }
176198 }
0 commit comments