@@ -5,13 +5,10 @@ import {
55
66import type { NodeModel } from "@defs/Node" ;
77
8- import { useNodeSystemContext } from "@contexts/nodeSystem" ;
9-
108import { DynamicIcon } from "@components/commons/DynamicIcon" ;
119import { Glass } from "@components/commons/Glass" ;
12- import { Input } from "@components/commons/Input" ;
1310
14- import { Canvas } from "@components/engine/Canvas " ;
11+ import { NodeContext } from "@components/engine/NodeContext " ;
1512
1613import "./style.css" ;
1714
@@ -24,27 +21,13 @@ export function Node({
2421 showCanvas ?: boolean ;
2522 forcedActive ?: boolean ;
2623} ) {
27- const { updateNode } = useNodeSystemContext ( ) ! ;
28-
2924 const [ active , setActive ] = useState ( false ) ;
30- const [ baseType , setBaseType ] = useState < string > ( node . baseType || "text" ) ;
3125
3226 const handleClick : ( ) => void = useCallback ( ( ) => {
3327 if ( node . action ) node . action ( ) ;
3428 else setActive ( prev => ! prev ) ;
3529 } , [ node ] ) ;
3630
37- const switchBaseType = useCallback ( ( type : string ) => {
38- node . baseType = type ;
39- setBaseType ( type ) ;
40- updateNode ( node . id ! , node ) ;
41- } , [ updateNode , node ] ) ;
42-
43- const changeValue = useCallback ( ( value : string ) => {
44- node . value = value ;
45- updateNode ( node . id ! , node ) ;
46- } , [ updateNode , node ] ) ;
47-
4831 return ( < >
4932 < div className = "node-wrapper" >
5033 < Glass
@@ -72,72 +55,10 @@ export function Node({
7255 ) }
7356 </ Glass >
7457
75- { ( node . context ?. length !== 0 ) && node . context && (
76- < Glass
77- className = { [
78- "node-context" ,
79- node . context . length > 20 ? "side" : "" ,
80- ] . join ( " " ) }
81- >
82- {
83- node . context ?. map ( ( contextNode => < Node
84- key = { contextNode . name }
85- node = { contextNode }
86- /> ) )
87- }
88-
89- {
90- ( ! node . isBase && showCanvas ) && ( < >
91- < Glass className = "context-canvas" >
92- < Canvas
93- baseId = { node . id ! }
94- contextCanvas = { true }
95- />
96- </ Glass >
97- </ > )
98- }
99-
100- { node . isBase && ( < >
101- < Node
102- forcedActive = { baseType === "text" }
103- node = { {
104- color : "#000" ,
105- icon : "Type" ,
106- name : "Text Type" ,
107- action : ( ) => switchBaseType ( "text" ) ,
108- } }
109- />
110-
111- < Node
112- forcedActive = { baseType === "numeric" }
113- node = { {
114- color : "#000" ,
115- icon : "Hash" ,
116- name : "Numeric Type" ,
117- action : ( ) => switchBaseType ( "numeric" ) ,
118- } }
119- />
120-
121- < Node
122- forcedActive = { baseType === "boolean" }
123- node = { {
124- color : "#000" ,
125- icon : "ToggleRight" ,
126- name : "Boolean Type" ,
127- action : ( ) => switchBaseType ( "boolean" ) ,
128- } }
129- />
130-
131- < div className = "node-base-input" >
132- < Input
133- placeholder = "Base Node Value"
134- defaultValue = { node . value || "" }
135- onChange = { ( e ) => changeValue ( e . target . value ) }
136- />
137- </ div >
138- </ > ) }
139- </ Glass >
140- ) }
58+ < NodeContext
59+ node = { node }
60+ showCanvas = { showCanvas }
61+ />
14162 </ div >
14263 </ > ) ;
14364}
0 commit comments