@@ -6,35 +6,23 @@ import {
66 addEdge ,
77 applyEdgeChanges ,
88 applyNodeChanges ,
9+ Background ,
10+ BackgroundVariant ,
11+ Connection ,
912 EdgeChange ,
1013 NodeChange ,
1114 ReactFlow ,
1215 Edge as ReactFlowEdge ,
1316 Node as ReactFlowNode ,
17+ reconnectEdge ,
1418 useReactFlow ,
1519 useViewport ,
1620} from "@xyflow/react" ;
1721import "@xyflow/react/dist/style.css" ;
1822import { useCallback , useEffect , useRef , useState } from "react" ;
1923import Icon from "../../misc/icon" ;
20- import AppNode from "./nodes/app-node" ;
21-
22- // const initialNodes = [
23- // {
24- // id: "n1",
25- // position: { x: 200, y: 0 },
26- // data: {
27- // label: "Node 1",
28- // config: {
29- // viewId: v4(),
30- // app: "https://cdn.pulse-editor.com/extension/spin_wheel/0.0.1/",
31- // },
32- // },
33- // type: "appNode",
34- // },
35- // { id: "n2", position: { x: 0, y: 100 }, data: { label: "Node 2" } },
36- // ];
37- // const initialEdges = [{ id: "n1-n2", source: "n1", target: "n2" }];
24+ import AppNode from "./nodes/app-node/app-node" ;
25+ import "./theme.css" ;
3826
3927const appInfo : AppInfoModalContent = {
4028 name : "Pulse Editor" ,
@@ -71,16 +59,24 @@ export default function CanvasView({ config }: { config?: CanvasViewConfig }) {
7159 setNodes ( ( nodesSnapshot ) => applyNodeChanges ( changes , nodesSnapshot ) ) ;
7260 } , [ ] ) ;
7361 const onEdgesChange = useCallback (
74- ( changes : EdgeChange < { id : string ; source : string ; target : string } > [ ] ) =>
75- setEdges ( ( edgesSnapshot ) => applyEdgeChanges ( changes , edgesSnapshot ) ) ,
62+ ( changes : EdgeChange < { id : string ; source : string ; target : string } > [ ] ) => {
63+ console . log ( "Edge changes:" , changes ) ;
64+ setEdges ( ( edgesSnapshot ) => applyEdgeChanges ( changes , edgesSnapshot ) ) ;
65+ } ,
7666 [ ] ,
7767 ) ;
7868 const onConnect = useCallback (
7969 ( params : any ) =>
8070 setEdges ( ( edgesSnapshot ) => addEdge ( params , edgesSnapshot ) ) ,
8171 [ ] ,
8272 ) ;
73+ const onReconnect = useCallback (
74+ ( oldEdge : ReactFlowEdge , newConnection : Connection ) =>
75+ setEdges ( ( els ) => reconnectEdge ( oldEdge , newConnection , els ) ) ,
76+ [ ] ,
77+ ) ;
8378
79+ /* Node creator functions */
8480 const createAppNode = useCallback ( ( props : any ) => {
8581 return < AppNode { ...props } /> ;
8682 } , [ ] ) ;
@@ -221,7 +217,7 @@ export default function CanvasView({ config }: { config?: CanvasViewConfig }) {
221217 return (
222218 < div
223219 ref = { containerRef }
224- className = "bg-default text-default -foreground relative h-full w-full"
220+ className = "bg-content3 text-content3 -foreground relative h-full w-full"
225221 id = { `canvas-${ config ?. viewId } ` }
226222 >
227223 < ReactFlow
@@ -237,7 +233,18 @@ export default function CanvasView({ config }: { config?: CanvasViewConfig }) {
237233 nodeTypes = { {
238234 appNode : createAppNode ,
239235 } }
240- />
236+ deleteKeyCode = { [ "Delete" , "Backspace" ] }
237+ onReconnect = { onReconnect }
238+ defaultEdgeOptions = { {
239+ markerEnd : {
240+ type : "arrowclosed" ,
241+ width : 20 ,
242+ height : 20 ,
243+ } ,
244+ } }
245+ >
246+ < Background variant = { BackgroundVariant . Dots } />
247+ </ ReactFlow >
241248 < Button
242249 isIconOnly
243250 className = "absolute right-2 bottom-2"
0 commit comments