@@ -262,70 +262,60 @@ const parseDoc = (
262
262
return nodes ;
263
263
} ;
264
264
265
- function isNodeInCluster ( node : Element | null ) {
266
- if ( ! node ) {
267
- return false ;
268
- }
269
-
270
- let parentNode = node . parentNode as Element ;
271
- while ( parentNode && parentNode ?. tagName !== "svg" ) {
272
- if ( parentNode . getAttribute ( "transform" ) ) {
273
- return true ;
274
- }
275
- parentNode = parentNode . parentNode as Element ;
276
- }
277
- return false ;
278
- }
279
-
280
265
const parseEdges = ( nodes : ParsedDoc [ ] , containerEl : Element ) : any [ ] => {
281
266
let rootEdgeIndex = 0 ;
282
267
283
- function parse ( nodes : ParsedDoc [ ] ) : any [ ] {
268
+ function parse ( nodes : ParsedDoc [ ] , isCluster = false ) : any [ ] {
284
269
return nodes . flatMap ( ( node , index ) => {
285
270
if ( node . stmt === "state" && node ?. doc ) {
286
- return parse ( node . doc ) ;
271
+ const clusters = containerEl
272
+ ?. querySelector ( `[id="${ node . id } "]` )
273
+ ?. closest ( ".root" ) ;
274
+
275
+ return parse ( node . doc , clusters ?. hasAttribute ( "transform" ) ) ;
287
276
} else if ( node . stmt === "relation" ) {
288
277
const startId = node . state1 . id ;
289
278
const endId = node . state2 . id ;
290
279
291
- let nodeStartElement = containerEl . querySelector < SVGPathElement > (
280
+ let nodeStartElement = containerEl . querySelector (
292
281
`[data-id*="${ startId } "]`
293
282
) ! ;
294
283
295
- let nodeEndElement = containerEl . querySelector < SVGPathElement > (
284
+ let nodeEndElement = containerEl . querySelector (
296
285
`[data-id*="${ endId } "]`
297
286
) ! ;
298
287
299
- // It's a cluster node
300
- if (
288
+ const isClusterStartRelation =
301
289
nodeStartElement . id . includes ( `${ startId } _start` ) ||
302
- nodeStartElement . id . includes ( `${ startId } _end` )
303
- ) {
290
+ nodeStartElement . id . includes ( `${ startId } _end` ) ;
291
+ const isClusterEndRelation =
292
+ nodeEndElement . id . includes ( `${ endId } _end` ) ||
293
+ nodeEndElement . id . includes ( `${ endId } _start` ) ;
294
+
295
+ if ( isClusterStartRelation ) {
304
296
nodeStartElement = containerEl . querySelector ( `[id="${ startId } "]` ) ! ;
305
297
}
306
298
307
- // It's a cluster node
308
- if (
309
- nodeEndElement . id . includes ( `${ endId } _end` ) ||
310
- nodeEndElement . id . includes ( `${ endId } _start` )
311
- ) {
299
+ if ( isClusterEndRelation ) {
312
300
nodeEndElement = containerEl . querySelector ( `[id="${ endId } "]` ) ! ;
313
301
}
314
302
315
- const rootContainer = nodeStartElement . parentElement ?. parentElement ;
303
+ const rootContainer = nodeStartElement . closest ( ".root" ) ;
316
304
317
305
if ( ! rootContainer ) {
318
306
throw new Error ( "Root container not found" ) ;
319
307
}
320
308
321
- const edges = rootContainer . querySelector ( ".edgePaths" ) ?. children ;
309
+ const edges = isCluster
310
+ ? rootContainer . querySelector ( ".edgePaths" ) ?. children
311
+ : containerEl . querySelector ( ".edgePaths" ) ?. children ;
322
312
323
313
if ( ! edges ) {
324
314
throw new Error ( "Edges not found" ) ;
325
315
}
326
316
327
317
const edgeStartElement = edges [
328
- isNodeInCluster ( nodeStartElement ) ? index : rootEdgeIndex
318
+ isCluster ? index : rootEdgeIndex
329
319
] as SVGPathElement ;
330
320
331
321
const position = computeElementPosition ( edgeStartElement , containerEl ) ;
0 commit comments