1
+ import type { SystemStyleObject } from '@invoke-ai/ui-library' ;
2
+ import { Flex } from '@invoke-ai/ui-library' ;
1
3
import { useAppSelector } from 'app/store/storeHooks' ;
2
4
import { selectCanvasWorkflowNodesSlice } from 'features/controlLayers/store/canvasWorkflowNodesSlice' ;
5
+ import {
6
+ ContainerContextProvider ,
7
+ DepthContextProvider ,
8
+ useContainerContext ,
9
+ useDepthContext ,
10
+ } from 'features/nodes/components/sidePanel/builder/contexts' ;
3
11
import { DividerElement } from 'features/nodes/components/sidePanel/builder/DividerElement' ;
4
12
import { HeadingElement } from 'features/nodes/components/sidePanel/builder/HeadingElement' ;
5
13
import { NodeFieldElementViewMode } from 'features/nodes/components/sidePanel/builder/NodeFieldElementViewMode' ;
6
14
import { TextElement } from 'features/nodes/components/sidePanel/builder/TextElement' ;
15
+ import { CONTAINER_CLASS_NAME } from 'features/nodes/types/workflow' ;
7
16
import {
8
17
isContainerElement ,
9
18
isDividerElement ,
@@ -15,9 +24,70 @@ import { memo } from 'react';
15
24
import type { Equals } from 'tsafe' ;
16
25
import { assert } from 'tsafe' ;
17
26
18
- import { CanvasWorkflowContainerElement } from './CanvasWorkflowContainerElement' ;
19
27
import { CanvasWorkflowInvocationNodeContextProvider } from './CanvasWorkflowInvocationContext' ;
20
28
29
+ const containerViewModeSx : SystemStyleObject = {
30
+ gap : 2 ,
31
+ '&[data-self-layout="column"]' : {
32
+ flexDir : 'column' ,
33
+ alignItems : 'stretch' ,
34
+ } ,
35
+ '&[data-self-layout="row"]' : {
36
+ flexDir : 'row' ,
37
+ alignItems : 'flex-start' ,
38
+ overflowX : 'auto' ,
39
+ overflowY : 'visible' ,
40
+ h : 'min-content' ,
41
+ flexShrink : 0 ,
42
+ } ,
43
+ '&[data-parent-layout="column"]' : {
44
+ w : 'full' ,
45
+ h : 'min-content' ,
46
+ } ,
47
+ '&[data-parent-layout="row"]' : {
48
+ flex : '1 1 0' ,
49
+ minW : 32 ,
50
+ } ,
51
+ } ;
52
+
53
+ /**
54
+ * Container element for canvas workflow fields.
55
+ * This reads from the canvas workflow nodes slice.
56
+ */
57
+ const CanvasWorkflowContainerElement = memo ( ( { id } : { id : string } ) => {
58
+ const nodesState = useAppSelector ( selectCanvasWorkflowNodesSlice ) ;
59
+ const el = nodesState . form . elements [ id ] ;
60
+ const depth = useDepthContext ( ) ;
61
+ const containerCtx = useContainerContext ( ) ;
62
+
63
+ if ( ! el || ! isContainerElement ( el ) ) {
64
+ return null ;
65
+ }
66
+
67
+ const { data } = el ;
68
+ const { children, layout } = data ;
69
+
70
+ return (
71
+ < DepthContextProvider depth = { depth + 1 } >
72
+ < ContainerContextProvider id = { id } layout = { layout } >
73
+ < Flex
74
+ id = { id }
75
+ className = { CONTAINER_CLASS_NAME }
76
+ sx = { containerViewModeSx }
77
+ data-self-layout = { layout }
78
+ data-depth = { depth }
79
+ data-parent-layout = { containerCtx . layout }
80
+ >
81
+ { children . map ( ( childId ) => (
82
+ < CanvasWorkflowFormElementComponent key = { childId } id = { childId } />
83
+ ) ) }
84
+ </ Flex >
85
+ </ ContainerContextProvider >
86
+ </ DepthContextProvider >
87
+ ) ;
88
+ } ) ;
89
+ CanvasWorkflowContainerElement . displayName = 'CanvasWorkflowContainerElement' ;
90
+
21
91
/**
22
92
* Renders a form element from canvas workflow nodes.
23
93
* Recursively handles all element types.
0 commit comments