@@ -24,6 +24,7 @@ import ReactFlow, {
24
24
import "reactflow/dist/style.css" ;
25
25
26
26
import Box from "@mui/material/Box" ;
27
+ import InputBase from "@mui/material/InputBase" ;
27
28
import CircularProgress from "@mui/material/CircularProgress" ;
28
29
import Tooltip from "@mui/material/Tooltip" ;
29
30
import IconButton from "@mui/material/IconButton" ;
@@ -71,6 +72,9 @@ const ScopeNode = memo<Props>(({ data, id, isConnectable }) => {
71
72
const ref = useRef ( null ) ;
72
73
const store = useContext ( RepoContext ) ;
73
74
if ( ! store ) throw new Error ( "Missing BearContext.Provider in the tree" ) ;
75
+ const getPod = useStore ( store , ( state ) => state . getPod ) ;
76
+ const pod = getPod ( id ) ;
77
+ const setPodName = useStore ( store , ( state ) => state . setPodName ) ;
74
78
const updatePod = useStore ( store , ( state ) => state . updatePod ) ;
75
79
const [ target , setTarget ] = React . useState < any > ( ) ;
76
80
const nodesMap = useStore ( store , ( state ) => state . ydoc . getMap < Node > ( "pods" ) ) ;
@@ -130,7 +134,21 @@ const ScopeNode = memo<Props>(({ data, id, isConnectable }) => {
130
134
justifyContent : "center" ,
131
135
} }
132
136
>
133
- Scope
137
+ < InputBase
138
+ defaultValue = { pod . name || "Scope" }
139
+ onBlur = { ( e ) => {
140
+ const name = e . target . value ;
141
+ if ( name === pod . name ) return ;
142
+ setPodName ( { id, name } ) ;
143
+ } }
144
+ inputProps = { {
145
+ style : {
146
+ padding : "0px" ,
147
+ textAlign : "center" ,
148
+ textOverflow : "ellipsis" ,
149
+ } ,
150
+ } }
151
+ > </ InputBase >
134
152
</ Box >
135
153
</ Grid >
136
154
< Grid item xs = { 4 } > </ Grid >
@@ -339,6 +357,7 @@ const CodeNode = memo<Props>(({ data, id, isConnectable }) => {
339
357
const isRightLayout = layout === "right" ;
340
358
const { setNodes } = useReactFlow ( ) ;
341
359
// const selected = useStore(store, (state) => state.selected);
360
+ const setPodName = useStore ( store , ( state ) => state . setPodName ) ;
342
361
const setPodSelected = useStore ( store , ( state ) => state . setPodSelected ) ;
343
362
const setCurrentEditor = useStore ( store , ( state ) => state . setCurrentEditor ) ;
344
363
const getPod = useStore ( store , ( state ) => state . getPod ) ;
@@ -435,6 +454,28 @@ const CodeNode = memo<Props>(({ data, id, isConnectable }) => {
435
454
/>
436
455
{ /* The header of code pods. */ }
437
456
< Box className = "custom-drag-handle" >
457
+ < Box
458
+ sx = { {
459
+ position : "absolute" ,
460
+ top : "-24px" ,
461
+ width : "50%" ,
462
+ } }
463
+ >
464
+ < InputBase
465
+ defaultValue = { pod . name }
466
+ onBlur = { ( e ) => {
467
+ const name = e . target . value ;
468
+ if ( name === pod . name ) return ;
469
+ setPodName ( { id, name } ) ;
470
+ } }
471
+ inputProps = { {
472
+ style : {
473
+ padding : "0px" ,
474
+ textOverflow : "ellipsis" ,
475
+ } ,
476
+ } }
477
+ > </ InputBase >
478
+ </ Box >
438
479
< Box sx = { styles [ "pod-index" ] } > [{ pod . index } ]</ Box >
439
480
< Box
440
481
sx = { {
@@ -581,7 +622,7 @@ export function Canvas() {
581
622
const provider = useStore ( store , ( state ) => state . provider ) ;
582
623
583
624
const getRealNodes = useCallback (
584
- ( id , level ) => {
625
+ ( id : string , level : number ) => {
585
626
let res : any [ ] = [ ] ;
586
627
let children = getId2children ( id ) || [ ] ;
587
628
const pod = getPod ( id ) ;
@@ -683,7 +724,7 @@ export function Canvas() {
683
724
const userColor = useStore ( store , ( state ) => state . user ?. color ) ;
684
725
685
726
const addNode = useCallback (
686
- ( x , y , type ) => {
727
+ ( x : number , y : number , type : string ) => {
687
728
const reactFlowBounds = reactFlowWrapper . current . getBoundingClientRect ( ) ;
688
729
let style ;
689
730
0 commit comments