@@ -220,13 +220,12 @@ export default class TableBuilding extends React.Component<ComProps, any> {
220
220
221
221
let _addLinks = ( links : any ) => {
222
222
let newLinkOpts = links . map ( ( item : any ) => {
223
- let _oldSource = _ . get ( item , 'sourceEndpoint.id' , '' ) ;
224
- let _oldTarget = _ . get ( item , 'targetEndpoint.id' , '' ) ;
225
- let _newSource = _oldSource . indexOf ( '-right' ) !== - 1 ? _oldSource : _oldSource + '-right' ;
226
- let _newTarget = _oldTarget . indexOf ( '-left' ) !== - 1 ? _oldTarget : _oldTarget + '-left' ;
227
-
223
+ let _oldSource = _ . get ( item , 'sourceEndpoint.id' , '' ) . replace ( '-right' , '' ) ;
224
+ let _oldTarget = _ . get ( item , 'targetEndpoint.id' , '' ) . replace ( '-left' , '' ) ;
225
+ let _newSource = _oldSource + '-right' ;
226
+ let _newTarget = _oldTarget + '-left' ;
228
227
return {
229
- id : item . options . id ,
228
+ id : item . options . id || ` ${ item . options . sourceNode } - ${ _oldSource } - ${ item . options . targetNode } - ${ _oldTarget } ` ,
230
229
sourceNode : item . options . sourceNode ,
231
230
targetNode : item . options . targetNode ,
232
231
arrowShapeType : item . arrowShapeType ,
@@ -247,17 +246,19 @@ export default class TableBuilding extends React.Component<ComProps, any> {
247
246
target : _ . get ( item , 'targetEndpoint.options.originId' ) ,
248
247
} ) ) ;
249
248
} ) ;
249
+
250
+ return newEdge ;
250
251
}
251
252
252
253
this . canvas . on ( 'system.link.connect' , ( data : any ) => {
253
- _addLinks ( data . links || [ ] ) ;
254
- this . onConnectEdges ( data . links ) ;
254
+ let newEdges = _addLinks ( data . links || [ ] ) ;
255
+ this . onConnectEdges ( newEdges ) ;
255
256
this . forceUpdate ( ) ;
256
257
} ) ;
257
258
258
259
this . canvas . on ( 'system.link.reconnect' , ( data : any ) => {
259
- _addLinks ( data . addLinks || [ ] ) ;
260
- this . onReConnectEdges ( data . addLinks , data . delLinks ) ;
260
+ let _addEdges = _addLinks ( data . addLinks || [ ] ) ;
261
+ this . onReConnectEdges ( _addEdges , data . delLinks ) ;
261
262
262
263
this . forceUpdate ( ) ;
263
264
} ) ;
@@ -322,6 +323,13 @@ export default class TableBuilding extends React.Component<ComProps, any> {
322
323
this . onDeleteNodes ( [ data . node ] ) ;
323
324
} ) ;
324
325
326
+ this . canvas . on ( 'custom.item.focus' , ( data : any ) => {
327
+ this . _unfocus ( ) ;
328
+ this . _focusNodes = this . _focusNodes . concat ( data . nodes || [ ] ) ;
329
+ this . _focusLinks = this . _focusLinks . concat ( data . edges || [ ] ) ;
330
+
331
+ } ) ;
332
+
325
333
this . canvas . on ( 'table.canvas.expand' , ( ) => {
326
334
this . forceUpdate ( ) ;
327
335
} ) ;
@@ -407,9 +415,23 @@ export default class TableBuilding extends React.Component<ComProps, any> {
407
415
408
416
onConnectEdges ( links ) {
409
417
let linksInfo = links . map ( ( item ) => {
410
- return item . options ;
418
+ return _ . assign ( item . options , {
419
+ source : _ . get ( item , 'options.source' , '' ) . replace ( '-right' , '' ) ,
420
+ target : _ . get ( item , 'options.target' , '' ) . replace ( '-left' , '' )
421
+ } ) ;
411
422
} ) ;
412
423
424
+ let newEdges = _ . differenceWith ( linksInfo , this . canvasData . edges , ( a : any , b : any ) => {
425
+ return (
426
+ a . sourceNode === b . sourceNode &&
427
+ a . targetNode === b . targetNode &&
428
+ a . source === b . source &&
429
+ a . target === b . target
430
+ ) ;
431
+ } ) ;
432
+
433
+ this . canvasData . edges = this . canvasData . edges . concat ( newEdges ) ;
434
+
413
435
this . props . onChange && this . props . onChange ( {
414
436
type : 'system.link.connect' ,
415
437
links : linksInfo
@@ -418,10 +440,16 @@ export default class TableBuilding extends React.Component<ComProps, any> {
418
440
419
441
onReConnectEdges ( addLinks , rmLinks ) {
420
442
let addLinksInfo = addLinks . map ( ( item ) => {
421
- return item . options ;
443
+ return _ . assign ( item . options , {
444
+ source : _ . get ( item , 'options.source' , '' ) . replace ( '-right' , '' ) ,
445
+ target : _ . get ( item , 'options.target' , '' ) . replace ( '-left' , '' )
446
+ } ) ;
422
447
} ) ;
423
448
let rmLinksInfo = rmLinks . map ( ( item ) => {
424
- return item . options ;
449
+ return _ . assign ( item . options , {
450
+ source : _ . get ( item , 'options.source' , '' ) . replace ( '-right' , '' ) ,
451
+ target : _ . get ( item , 'options.target' , '' ) . replace ( '-left' , '' )
452
+ } ) ;
425
453
} ) ;
426
454
this . props . onChange && this . props . onChange ( {
427
455
type : 'system.link.reconnect' ,
0 commit comments