Skip to content

Commit 406f1aa

Browse files
committed
Add edge and stylize canvas node
1 parent 168ead5 commit 406f1aa

File tree

13 files changed

+435
-258
lines changed

13 files changed

+435
-258
lines changed

web/components/views/canvas/canvas-node-control.tsx

Lines changed: 0 additions & 104 deletions
This file was deleted.

web/components/views/canvas/canvas-node-view-layout.tsx

Lines changed: 0 additions & 98 deletions
This file was deleted.

web/components/views/canvas/canvas-view.tsx

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -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";
1721
import "@xyflow/react/dist/style.css";
1822
import { useCallback, useEffect, useRef, useState } from "react";
1923
import 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

3927
const 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"

web/components/views/canvas/nodes/app-node.tsx renamed to web/components/views/canvas/nodes/app-node/app-node.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import { ViewModeEnum } from "@pulse-editor/shared-utils";
44
import { Node } from "@xyflow/react";
55
import { memo } from "react";
66
import { v4 } from "uuid";
7-
import BaseAppView from "../../base/base-app-view";
8-
import CanvasNodeViewLayout from "../canvas-node-view-layout";
7+
import BaseAppView from "../../../base/base-app-view";
8+
import CanvasNodeViewLayout from "./layout";
99

1010
const AppNode = memo((props: any) => {
1111
const nodeProps = props as Node<{ config: AppViewConfig }>;
@@ -24,6 +24,7 @@ const AppNode = memo((props: any) => {
2424

2525
return (
2626
<CanvasNodeViewLayout
27+
viewId={viewId}
2728
controlActions={{
2829
fullscreen: () => {
2930
openViewInFullScreen();

0 commit comments

Comments
 (0)