@@ -22,7 +22,6 @@ import { useConnection } from 'features/nodes/hooks/useConnection';
2222import { useIsValidConnection } from 'features/nodes/hooks/useIsValidConnection' ;
2323import { useIsWorkflowEditorLocked } from 'features/nodes/hooks/useIsWorkflowEditorLocked' ;
2424import { useNodeCopyPaste } from 'features/nodes/hooks/useNodeCopyPaste' ;
25- import { useSyncExecutionState } from 'features/nodes/hooks/useNodeExecutionState' ;
2625import {
2726 $addNodeCmdk ,
2827 $cursorPos ,
@@ -83,23 +82,16 @@ export const Flow = memo(() => {
8382 const nodes = useAppSelector ( selectNodes ) ;
8483 const edges = useAppSelector ( selectEdges ) ;
8584 const viewport = useStore ( $viewport ) ;
86- const needsFit = useStore ( $needsFit ) ;
87- const mayUndo = useAppSelector ( selectMayUndo ) ;
88- const mayRedo = useAppSelector ( selectMayRedo ) ;
8985 const shouldSnapToGrid = useAppSelector ( selectShouldSnapToGrid ) ;
9086 const selectionMode = useAppSelector ( selectSelectionMode ) ;
9187 const { onConnectStart, onConnect, onConnectEnd } = useConnection ( ) ;
9288 const flowWrapper = useRef < HTMLDivElement > ( null ) ;
9389 const isValidConnection = useIsValidConnection ( ) ;
94- const cancelConnection = useReactFlowStore ( selectCancelConnection ) ;
9590 const updateNodeInternals = useUpdateNodeInternals ( ) ;
96- const store = useAppStore ( ) ;
97- const isWorkflowsFocused = useIsRegionFocused ( 'workflows' ) ;
9891 const isLocked = useIsWorkflowEditorLocked ( ) ;
9992
10093 useFocusRegion ( 'workflows' , flowWrapper ) ;
10194
102- useSyncExecutionState ( ) ;
10395 const [ borderRadius ] = useToken ( 'radii' , [ 'base' ] ) ;
10496 const flowStyles = useMemo < CSSProperties > ( ( ) => ( { borderRadius } ) , [ borderRadius ] ) ;
10597
@@ -110,12 +102,12 @@ export const Flow = memo(() => {
110102 if ( ! flow ) {
111103 return ;
112104 }
113- if ( needsFit ) {
105+ if ( $ needsFit. get ( ) ) {
114106 $needsFit . set ( false ) ;
115107 flow . fitView ( ) ;
116108 }
117109 } ,
118- [ dispatch , needsFit ]
110+ [ dispatch ]
119111 ) ;
120112
121113 const onEdgesChange : OnEdgesChange < AnyEdge > = useCallback (
@@ -214,6 +206,83 @@ export const Flow = memo(() => {
214206
215207 // #endregion
216208
209+ const onNodeClick = useCallback < NodeMouseHandler < AnyNode > > ( ( e , node ) => {
210+ if ( ! $isSelectingOutputNode . get ( ) ) {
211+ return ;
212+ }
213+ if ( ! isInvocationNode ( node ) ) {
214+ return ;
215+ }
216+ const { id } = node . data ;
217+ $outputNodeId . set ( id ) ;
218+ $isSelectingOutputNode . set ( false ) ;
219+ } , [ ] ) ;
220+
221+ return (
222+ < >
223+ < ReactFlow < AnyNode , AnyEdge >
224+ id = "workflow-editor"
225+ ref = { flowWrapper }
226+ defaultViewport = { viewport }
227+ nodeTypes = { nodeTypes }
228+ edgeTypes = { edgeTypes }
229+ nodes = { nodes }
230+ edges = { edges }
231+ onInit = { onInit }
232+ onNodeClick = { onNodeClick }
233+ onMouseMove = { onMouseMove }
234+ onNodesChange = { onNodesChange }
235+ onEdgesChange = { onEdgesChange }
236+ onReconnect = { onReconnect }
237+ onReconnectStart = { onReconnectStart }
238+ onReconnectEnd = { onReconnectEnd }
239+ onConnectStart = { onConnectStart }
240+ onConnect = { onConnect }
241+ onConnectEnd = { onConnectEnd }
242+ onMoveEnd = { handleMoveEnd }
243+ connectionLineComponent = { CustomConnectionLine }
244+ isValidConnection = { isValidConnection }
245+ edgesFocusable = { ! isLocked }
246+ edgesReconnectable = { ! isLocked }
247+ nodesDraggable = { ! isLocked }
248+ nodesConnectable = { ! isLocked }
249+ nodesFocusable = { ! isLocked }
250+ elementsSelectable = { ! isLocked }
251+ minZoom = { 0.1 }
252+ snapToGrid = { shouldSnapToGrid }
253+ snapGrid = { snapGrid }
254+ connectionRadius = { 30 }
255+ proOptions = { proOptions }
256+ style = { flowStyles }
257+ onPaneClick = { handlePaneClick }
258+ deleteKeyCode = { null }
259+ selectionMode = { selectionMode }
260+ elevateEdgesOnSelect
261+ nodeDragThreshold = { 1 }
262+ noDragClassName = { NO_DRAG_CLASS }
263+ noWheelClassName = { NO_WHEEL_CLASS }
264+ noPanClassName = { NO_PAN_CLASS }
265+ >
266+ < Background />
267+ </ ReactFlow >
268+ < HotkeyIsolator />
269+ </ >
270+ ) ;
271+ } ) ;
272+
273+ Flow . displayName = 'Flow' ;
274+
275+ const HotkeyIsolator = memo ( ( ) => {
276+ const isLocked = useIsWorkflowEditorLocked ( ) ;
277+
278+ const mayUndo = useAppSelector ( selectMayUndo ) ;
279+ const mayRedo = useAppSelector ( selectMayRedo ) ;
280+
281+ const cancelConnection = useReactFlowStore ( selectCancelConnection ) ;
282+
283+ const store = useAppStore ( ) ;
284+ const isWorkflowsFocused = useIsRegionFocused ( 'workflows' ) ;
285+
217286 const { copySelection, pasteSelection, pasteSelectionWithEdges } = useNodeCopyPaste ( ) ;
218287
219288 useRegisteredHotkeys ( {
@@ -239,12 +308,12 @@ export const Flow = memo(() => {
239308 }
240309 } ) ;
241310 if ( nodeChanges . length > 0 ) {
242- dispatch ( nodesChanged ( nodeChanges ) ) ;
311+ store . dispatch ( nodesChanged ( nodeChanges ) ) ;
243312 }
244313 if ( edgeChanges . length > 0 ) {
245- dispatch ( edgesChanged ( edgeChanges ) ) ;
314+ store . dispatch ( edgesChanged ( edgeChanges ) ) ;
246315 }
247- } , [ dispatch , store ] ) ;
316+ } , [ store ] ) ;
248317 useRegisteredHotkeys ( {
249318 id : 'selectAll' ,
250319 category : 'workflows' ,
@@ -273,20 +342,20 @@ export const Flow = memo(() => {
273342 id : 'undo' ,
274343 category : 'workflows' ,
275344 callback : ( ) => {
276- dispatch ( undo ( ) ) ;
345+ store . dispatch ( undo ( ) ) ;
277346 } ,
278347 options : { enabled : isWorkflowsFocused && ! isLocked && mayUndo , preventDefault : true } ,
279- dependencies : [ mayUndo , isLocked , isWorkflowsFocused ] ,
348+ dependencies : [ store , mayUndo , isLocked , isWorkflowsFocused ] ,
280349 } ) ;
281350
282351 useRegisteredHotkeys ( {
283352 id : 'redo' ,
284353 category : 'workflows' ,
285354 callback : ( ) => {
286- dispatch ( redo ( ) ) ;
355+ store . dispatch ( redo ( ) ) ;
287356 } ,
288357 options : { enabled : isWorkflowsFocused && ! isLocked && mayRedo , preventDefault : true } ,
289- dependencies : [ mayRedo , isLocked , isWorkflowsFocused ] ,
358+ dependencies : [ store , mayRedo , isLocked , isWorkflowsFocused ] ,
290359 } ) ;
291360
292361 const onEscapeHotkey = useCallback ( ( ) => {
@@ -313,12 +382,12 @@ export const Flow = memo(() => {
313382 edgeChanges . push ( { type : 'remove' , id } ) ;
314383 } ) ;
315384 if ( nodeChanges . length > 0 ) {
316- dispatch ( nodesChanged ( nodeChanges ) ) ;
385+ store . dispatch ( nodesChanged ( nodeChanges ) ) ;
317386 }
318387 if ( edgeChanges . length > 0 ) {
319- dispatch ( edgesChanged ( edgeChanges ) ) ;
388+ store . dispatch ( edgesChanged ( edgeChanges ) ) ;
320389 }
321- } , [ dispatch , store ] ) ;
390+ } , [ store ] ) ;
322391 useRegisteredHotkeys ( {
323392 id : 'deleteSelection' ,
324393 category : 'workflows' ,
@@ -327,65 +396,6 @@ export const Flow = memo(() => {
327396 dependencies : [ deleteSelection , isWorkflowsFocused , isLocked ] ,
328397 } ) ;
329398
330- const onNodeClick = useCallback < NodeMouseHandler < AnyNode > > ( ( e , node ) => {
331- if ( ! $isSelectingOutputNode . get ( ) ) {
332- return ;
333- }
334- if ( ! isInvocationNode ( node ) ) {
335- return ;
336- }
337- const { id } = node . data ;
338- $outputNodeId . set ( id ) ;
339- $isSelectingOutputNode . set ( false ) ;
340- } , [ ] ) ;
341-
342- return (
343- < ReactFlow < AnyNode , AnyEdge >
344- id = "workflow-editor"
345- ref = { flowWrapper }
346- defaultViewport = { viewport }
347- nodeTypes = { nodeTypes }
348- edgeTypes = { edgeTypes }
349- nodes = { nodes }
350- edges = { edges }
351- onInit = { onInit }
352- onNodeClick = { onNodeClick }
353- onMouseMove = { onMouseMove }
354- onNodesChange = { onNodesChange }
355- onEdgesChange = { onEdgesChange }
356- onReconnect = { onReconnect }
357- onReconnectStart = { onReconnectStart }
358- onReconnectEnd = { onReconnectEnd }
359- onConnectStart = { onConnectStart }
360- onConnect = { onConnect }
361- onConnectEnd = { onConnectEnd }
362- onMoveEnd = { handleMoveEnd }
363- connectionLineComponent = { CustomConnectionLine }
364- isValidConnection = { isValidConnection }
365- edgesFocusable = { ! isLocked }
366- edgesReconnectable = { ! isLocked }
367- nodesDraggable = { ! isLocked }
368- nodesConnectable = { ! isLocked }
369- nodesFocusable = { ! isLocked }
370- elementsSelectable = { ! isLocked }
371- minZoom = { 0.1 }
372- snapToGrid = { shouldSnapToGrid }
373- snapGrid = { snapGrid }
374- connectionRadius = { 30 }
375- proOptions = { proOptions }
376- style = { flowStyles }
377- onPaneClick = { handlePaneClick }
378- deleteKeyCode = { null }
379- selectionMode = { selectionMode }
380- elevateEdgesOnSelect
381- nodeDragThreshold = { 1 }
382- noDragClassName = { NO_DRAG_CLASS }
383- noWheelClassName = { NO_WHEEL_CLASS }
384- noPanClassName = { NO_PAN_CLASS }
385- >
386- < Background />
387- </ ReactFlow >
388- ) ;
399+ return null ;
389400} ) ;
390-
391- Flow . displayName = 'Flow' ;
401+ HotkeyIsolator . displayName = 'HotkeyIsolator' ;
0 commit comments