File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import type { Node , Edge } from '@vue-flow/core'
2- import ELK from 'elkjs/lib/elk.bundled.js'
2+ import type ELK from 'elkjs/lib/elk.bundled.js'
33import type { TaskInfo , NodeInfo } from '../types'
44import { sortNodesByGlobalExecutionOrder } from './taskExecutionOrder'
55import {
@@ -48,7 +48,20 @@ const resolveNodeWidth = (label: string): number => {
4848 return Math . max ( NODE_MIN_WIDTH , Math . ceil ( estimateLabelWidth ( label ) + NODE_HORIZONTAL_PADDING ) )
4949}
5050
51- const elk = new ELK ( )
51+ type ElkLayoutEngine = InstanceType < typeof ELK >
52+
53+ let elkPromise : Promise < ElkLayoutEngine > | null = null
54+
55+ const getElk = async ( ) : Promise < ElkLayoutEngine > => {
56+ if ( ! elkPromise ) {
57+ elkPromise = import ( 'elkjs/lib/elk.bundled.js' ) . then ( ( module ) => {
58+ const ElkConstructor = module . default
59+ return new ElkConstructor ( )
60+ } )
61+ }
62+
63+ return elkPromise
64+ }
5265
5366interface ElkLayoutNode {
5467 id : string
@@ -94,6 +107,7 @@ const resolveFlowNodeStatus = (
94107}
95108
96109export async function buildFlowchartData ( task : TaskInfo , options : BuildFlowchartOptions = { } ) : Promise < { nodes : Node [ ] ; edges : Edge [ ] } > {
110+ const elk = await getElk ( )
97111 const orderedNodes = sortNodesByGlobalExecutionOrder ( task . nodes )
98112 const orderedExecutions = orderedNodes . map ( ( node ) => ( {
99113 node,
You can’t perform that action at this time.
0 commit comments