@@ -15,25 +15,35 @@ import "./style.css";
1515
1616export function Node ( {
1717 node,
18+ forcedActive = false ,
1819} : {
1920 node : NodeModel ;
21+ forcedActive ?: boolean ;
2022} ) {
2123 const {
2224 setUnsavedChanges,
2325 } = useUnsavedChangesContext ( ) ! ;
26+
2427 const [ active , setActive ] = useState ( false ) ;
28+ const [ baseType , setBaseType ] = useState < string > ( node . baseType || "text" ) ;
2529
2630 const handleClick : ( ) => void = useCallback ( ( ) => {
2731 if ( node . action ) node . action ( ) ;
2832 else setActive ( prev => ! prev ) ;
2933 } , [ node ] ) ;
3034
35+ const switchBaseType = useCallback ( ( type : string ) => {
36+ node . baseType = type ;
37+ setBaseType ( type ) ;
38+ setUnsavedChanges ( true ) ;
39+ } , [ setUnsavedChanges , node ] ) ;
40+
3141 return ( < >
3242 < div className = "node-wrapper" >
3343 < Glass
3444 className = { [
3545 "node" ,
36- active ? "active" : "" ,
46+ ( active || forcedActive ) ? "active" : "" ,
3747 ] . join ( " " ) }
3848 style = { { color : node . color } }
3949 onClick = { handleClick }
@@ -69,7 +79,37 @@ export function Node({
6979 /> ) )
7080 }
7181
72- { node . isBase && (
82+ { node . isBase && ( < >
83+ < Node
84+ forcedActive = { baseType === "text" }
85+ node = { {
86+ color : "#000" ,
87+ icon : "Type" ,
88+ name : "Text Type" ,
89+ action : ( ) => switchBaseType ( "text" ) ,
90+ } }
91+ />
92+
93+ < Node
94+ forcedActive = { baseType === "numeric" }
95+ node = { {
96+ color : "#000" ,
97+ icon : "Hash" ,
98+ name : "Numeric Type" ,
99+ action : ( ) => switchBaseType ( "numeric" ) ,
100+ } }
101+ />
102+
103+ < Node
104+ forcedActive = { baseType === "boolean" }
105+ node = { {
106+ color : "#000" ,
107+ icon : "ToggleRight" ,
108+ name : "Boolean Type" ,
109+ action : ( ) => switchBaseType ( "boolean" ) ,
110+ } }
111+ />
112+
73113 < div className = "node-base-input" >
74114 < Input
75115 placeholder = "Base Node Value"
@@ -80,7 +120,7 @@ export function Node({
80120 } }
81121 />
82122 </ div >
83- ) }
123+ </ > ) }
84124 </ Glass >
85125 ) }
86126 </ div >
0 commit comments