@@ -6,7 +6,6 @@ import type {
66 Edge ,
77 Node ,
88} from '@/app/components/workflow/types'
9- import ELK from 'elkjs/lib/elk.bundled.js'
109import { cloneDeep } from 'es-toolkit/object'
1110import {
1211 CUSTOM_NODE ,
@@ -19,7 +18,15 @@ import {
1918 BlockEnum ,
2019} from '@/app/components/workflow/types'
2120
22- const elk = new ELK ( )
21+ let elk : import ( 'elkjs/lib/elk-api' ) . ELK | undefined
22+
23+ async function getELK ( ) {
24+ if ( ! elk ) {
25+ const { default : ELK } = await import ( 'elkjs/lib/elk.bundled.js' )
26+ elk = new ELK ( )
27+ }
28+ return elk
29+ }
2330
2431const DEFAULT_NODE_WIDTH = 244
2532const DEFAULT_NODE_HEIGHT = 100
@@ -473,7 +480,7 @@ export const getLayoutByELK = async (originNodes: Node[], originEdges: Edge[]):
473480 edges : elkEdges ,
474481 }
475482
476- const layoutedGraph = await elk . layout ( graph )
483+ const layoutedGraph = await ( await getELK ( ) ) . layout ( graph )
477484 const layout = collectLayout ( layoutedGraph , ( ) => true )
478485 return normaliseBounds ( layout )
479486}
@@ -571,7 +578,7 @@ export const getLayoutForChildNodes = async (
571578 edges : elkEdges ,
572579 }
573580
574- const layoutedGraph = await elk . layout ( graph )
581+ const layoutedGraph = await ( await getELK ( ) ) . layout ( graph )
575582 const layout = collectLayout ( layoutedGraph , ( ) => true )
576583 return normaliseChildLayout ( layout , nodes )
577584}
0 commit comments