@@ -72,6 +72,7 @@ const ScopeNode = memo<Props>(({ data, id, isConnectable }) => {
72
72
const ref = useRef ( null ) ;
73
73
const store = useContext ( RepoContext ) ;
74
74
if ( ! store ) throw new Error ( "Missing BearContext.Provider in the tree" ) ;
75
+ const flow = useReactFlow ( ) ;
75
76
const getPod = useStore ( store , ( state ) => state . getPod ) ;
76
77
const pod = getPod ( id ) ;
77
78
const setPodName = useStore ( store , ( state ) => state . setPodName ) ;
@@ -84,6 +85,19 @@ const ScopeNode = memo<Props>(({ data, id, isConnectable }) => {
84
85
const selected = useStore ( store , ( state ) => state . pods [ id ] ?. selected ) ;
85
86
const role = useStore ( store , ( state ) => state . role ) ;
86
87
88
+ const deleteNodeById = useCallback (
89
+ ( id : string ) => {
90
+ flow . deleteElements ( {
91
+ nodes : [
92
+ {
93
+ id,
94
+ } ,
95
+ ] ,
96
+ } ) ;
97
+ } ,
98
+ [ flow ]
99
+ ) ;
100
+
87
101
const onResize = useCallback ( ( { width, height, offx, offy } ) => {
88
102
const node = nodesMap . get ( id ) ;
89
103
if ( node ) {
@@ -97,6 +111,7 @@ const ScopeNode = memo<Props>(({ data, id, isConnectable }) => {
97
111
React . useEffect ( ( ) => {
98
112
setTarget ( ref . current ) ;
99
113
} , [ ] ) ;
114
+
100
115
return (
101
116
< Box
102
117
ref = { ref }
@@ -108,6 +123,35 @@ const ScopeNode = memo<Props>(({ data, id, isConnectable }) => {
108
123
} }
109
124
className = "custom-drag-handle"
110
125
>
126
+ < Box
127
+ sx = { {
128
+ display : "flex" ,
129
+ marginLeft : "10px" ,
130
+ borderRadius : "4px" ,
131
+ position : "absolute" ,
132
+ border : "solid 1px #d6dee6" ,
133
+ right : "25px" ,
134
+ top : "-15px" ,
135
+ background : "white" ,
136
+ zIndex : 250 ,
137
+ justifyContent : "center" ,
138
+ } }
139
+ >
140
+ { role !== RoleType . GUEST && (
141
+ < Tooltip title = "Delete" >
142
+ < IconButton
143
+ size = "small"
144
+ onClick = { ( e : any ) => {
145
+ e . stopPropagation ( ) ;
146
+ e . preventDefault ( ) ;
147
+ deleteNodeById ( id ) ;
148
+ } }
149
+ >
150
+ < DeleteIcon fontSize = "inherit" />
151
+ </ IconButton >
152
+ </ Tooltip >
153
+ ) }
154
+ </ Box >
111
155
< Handle
112
156
type = "source"
113
157
position = { Position . Top }
@@ -181,7 +225,7 @@ const ScopeNode = memo<Props>(({ data, id, isConnectable }) => {
181
225
renderDirections = { [ "e" , "s" , "se" ] }
182
226
edge = { false }
183
227
zoom = { 1 }
184
- origin = { true }
228
+ origin = { false }
185
229
padding = { { left : 0 , top : 0 , right : 0 , bottom : 0 } }
186
230
onResizeStart = { ( e ) => {
187
231
e . setOrigin ( [ "%" , "%" ] ) ;
@@ -580,11 +624,11 @@ const CodeNode = memo<Props>(({ data, id, isConnectable }) => {
580
624
const nodeTypes = { scope : ScopeNode , code : CodeNode } ;
581
625
582
626
const level2color = {
583
- 0 : "rgba(255, 0, 0 , 0.2 )" ,
584
- 1 : "rgba(255, 0, 255 , 0.2 )" ,
585
- 2 : "rgba(0, 255, 255 , 0.2 )" ,
586
- 3 : "rgba(0, 255, 0 , 0.2 )" ,
587
- 4 : "rgba(255, 255, 0 , 0.2 )" ,
627
+ 0 : "rgba(187, 222, 251 , 0.5 )" ,
628
+ 1 : "rgba(144, 202, 249 , 0.5 )" ,
629
+ 2 : "rgba(100, 181, 246 , 0.5 )" ,
630
+ 3 : "rgba(66, 165, 245 , 0.5 )" ,
631
+ 4 : "rgba(33, 150, 243 , 0.5 )" ,
588
632
// default: "rgba(255, 255, 255, 0.2)",
589
633
default : "rgba(240,240,240,0.25)" ,
590
634
} ;
@@ -993,16 +1037,16 @@ export function Canvas() {
993
1037
< Box >
994
1038
< MiniMap
995
1039
nodeStrokeColor = { ( n ) => {
996
- if ( n . style ?. background ) return n . style . background as string ;
997
- if ( n . type === "code" ) return "#0041d0 " ;
998
- if ( n . type === "scope" ) return "#ff0072 " ;
1040
+ if ( n . style ?. borderColor ) return n . style . borderColor ;
1041
+ if ( n . type === "code" ) return "#d6dee6 " ;
1042
+ if ( n . type === "scope" ) return "#f4f6f8 " ;
999
1043
1000
- return "#1a192b " ;
1044
+ return "#d6dee6 " ;
1001
1045
} }
1002
1046
nodeColor = { ( n ) => {
1003
1047
if ( n . style ?. backgroundColor ) return n . style . backgroundColor ;
1004
1048
1005
- return "#1a192b " ;
1049
+ return "#f4f6f8 " ;
1006
1050
} }
1007
1051
nodeBorderRadius = { 2 }
1008
1052
/>
0 commit comments