diff --git a/ui/src/components/nodes/Code.tsx b/ui/src/components/nodes/Code.tsx index 860b18fa..870cc925 100644 --- a/ui/src/components/nodes/Code.tsx +++ b/ui/src/components/nodes/Code.tsx @@ -54,7 +54,7 @@ import { RepoContext } from "../../lib/store"; import { MyMonaco } from "../MyMonaco"; import { useApolloClient } from "@apollo/client"; -import { NodeResizeControl, NodeResizer } from "@reactflow/node-resizer"; +import { NodeResizeControl, NodeResizer } from "reactflow"; import "@reactflow/node-resizer/dist/style.css"; import { ResizeIcon } from "./utils"; @@ -440,191 +440,210 @@ export const CodeNode = memo(function ({ isGuest ? ( <>{child} ) : ( - - {child} - - ); - - return Wrap( - { - setShowToolbar(true); - }} - onMouseLeave={() => { - setShowToolbar(false); - }} - > - {/* FIXME this does not support x-axis only resizing. */} - {/* - - */} - - - - - - - {/* The header of code pods. */} - - {devMode && ( + - {id} at ({Math.round(xPos)}, {Math.round(yPos)}, w: {pod.width}, h:{" "} - {pod.height}) + {child} - )} - - { - const name = e.target.value; - if (name === data.name) return; - const node = nodesMap.get(id); - if (node) { - nodesMap.set(id, { ...node, data: { ...node.data, name } }); - } - }} - inputProps={{ - style: { - padding: "0px", - textOverflow: "ellipsis", - }, - }} - > - - - [{index}] - - - - + + ); + + return ( + <> { + setShowToolbar(true); + }} + onMouseLeave={() => { + setShowToolbar(false); }} > - - {showResult && ( + {Wrap( { - // e.stopPropagation(); - // }} + id={"reactflow_node_code_" + id} sx={{ - border: "solid 1px #d6dee6", + border: "1px #d6dee6", + borderWidth: pod.ispublic ? "4px" : "2px", borderRadius: "4px", - position: "absolute", - top: isRightLayout ? 0 : "100%", - left: isRightLayout ? "100%" : 0, - maxHeight: "160px", - maxWidth: isRightLayout ? "300px" : "100%", - minWidth: isRightLayout ? "150px" : "100%", - boxSizing: "border-box", - backgroundColor: "white", - zIndex: 100, - padding: "0 10px", + borderStyle: isCutting ? "dashed" : "solid", + width: "100%", + height: "100%", + backgroundColor: "rgb(244, 246, 248)", + borderColor: isCutting + ? "red" + : pod.ispublic + ? "green" + : selected + ? "#003c8f" + : !isPodFocused + ? "#d6dee6" + : "#5e92f3", }} > - + + + + + + + + {/* The header of code pods. */} + + {devMode && ( + + {id} at ({Math.round(xPos)}, {Math.round(yPos)}, w:{" "} + {pod.width}, h: {pod.height}) + + )} + + { + const name = e.target.value; + if (name === data.name) return; + const node = nodesMap.get(id); + if (node) { + nodesMap.set(id, { + ...node, + data: { ...node.data, name }, + }); + } + }} + inputProps={{ + style: { + padding: "0px", + textOverflow: "ellipsis", + }, + }} + > + + + [{index}] + + + + + + + + {showResult && ( + { + // e.stopPropagation(); + // }} + sx={{ + border: "solid 1px #d6dee6", + borderRadius: "4px", + position: "absolute", + top: isRightLayout ? 0 : "100%", + left: isRightLayout ? "100%" : 0, + maxHeight: "160px", + maxWidth: isRightLayout ? "300px" : "100%", + minWidth: isRightLayout ? "150px" : "100%", + boxSizing: "border-box", + backgroundColor: "white", + zIndex: 100, + padding: "0 10px", + }} + > + + + )} + )} - + ); }); diff --git a/ui/src/components/nodes/Rich.tsx b/ui/src/components/nodes/Rich.tsx index b45ff88b..5a4ad6e8 100644 --- a/ui/src/components/nodes/Rich.tsx +++ b/ui/src/components/nodes/Rich.tsx @@ -266,6 +266,30 @@ const MyEditor = ({ ); }; +function MyFloatingToolbar({ id }: { id: string }) { + const store = useContext(RepoContext); + if (!store) throw new Error("Missing BearContext.Provider in the tree"); + const reactFlowInstance = useReactFlow(); + // const selected = useStore(store, (state) => state.pods[id]?.selected); + const isGuest = useStore(store, (state) => state.role === "GUEST"); + return ( + <> + {!isGuest && ( + + { + reactFlowInstance.deleteElements({ nodes: [{ id }] }); + }} + > + + + + )} + + ); +} + /** * The React Flow node. */ @@ -304,6 +328,8 @@ export const RichNode = memo(function ({ const updateView = useStore(store, (state) => state.updateView); const reactFlowInstance = useReactFlow(); + const [showToolbar, setShowToolbar] = useState(false); + const onResize = useCallback( (e, data) => { const { size } = data; @@ -343,141 +369,170 @@ export const RichNode = memo(function ({ isGuest ? ( <>{child} ) : ( - - {child} - - ); - - return Wrap( - - - - - - - {devMode && ( + - {id} at ({Math.round(xPos)}, {Math.round(yPos)}, w: {pod.width}, h:{" "} - {pod.height}) + {child} - )} - - + + ); - top: "-24px", - width: "50%", - }} - > - { - const name = e.target.value; - if (name === data.name) return; - const node = nodesMap.get(id); - if (node) { - nodesMap.set(id, { ...node, data: { ...node.data, name } }); - } - }} - inputProps={{ - style: { - padding: "0px", - textOverflow: "ellipsis", - }, + return ( + <> + { + setShowToolbar(true); + }} + onMouseLeave={() => { + setShowToolbar(false); + }} + > + {" "} + {Wrap( + - - - {!isGuest && ( - - { - reactFlowInstance.deleteElements({ nodes: [{ id }] }); + > + + + + + + + + {devMode && ( + + {id} at ({Math.round(xPos)}, {Math.round(yPos)}, w:{" "} + {pod.width}, h: {pod.height}) + + )} + + - - - - )} - - - - + { + const name = e.target.value; + if (name === data.name) return; + const node = nodesMap.get(id); + if (node) { + nodesMap.set(id, { + ...node, + data: { ...node.data, name }, + }); + } + }} + inputProps={{ + style: { + padding: "0px", + textOverflow: "ellipsis", + }, + }} + > + + + + + + + + + + )} - + ); }); diff --git a/ui/src/components/nodes/Scope.tsx b/ui/src/components/nodes/Scope.tsx index 0f657492..6e2e5a92 100644 --- a/ui/src/components/nodes/Scope.tsx +++ b/ui/src/components/nodes/Scope.tsx @@ -42,7 +42,7 @@ import { useStore } from "zustand"; import { RepoContext } from "../../lib/store"; -import { NodeResizer, NodeResizeControl } from "@reactflow/node-resizer"; +import { NodeResizer, NodeResizeControl } from "reactflow"; import "@reactflow/node-resizer/dist/style.css"; import { ResizableBox } from "react-resizable"; import { ResizeIcon } from "./utils"; @@ -221,16 +221,19 @@ export const ScopeNode = memo(function ScopeNode({ }} > {/* */} - - - + + + + + +