Skip to content

Commit

Permalink
Merge pull request #120 from softflow24/feat/dnd
Browse files Browse the repository at this point in the history
Feat/Drag-and-drop functionality
  • Loading branch information
c0rtexR authored Oct 13, 2024
2 parents 0637b3f + e6b6ac0 commit cf079b2
Show file tree
Hide file tree
Showing 28 changed files with 10,278 additions and 8,011 deletions.
3 changes: 2 additions & 1 deletion packages/editor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
"lint": "eslint --fix 'src/**/*.{js,jsx,ts,tsx}'"
},
"dependencies": {
"@data-river/execution-engine": "workspace:*",
"@data-river/blocks": "workspace:*",
"@data-river/execution-engine": "workspace:*",
"@data-river/shared": "workspace:*",
"@radix-ui/react-dialog": "^1.1.1",
"@radix-ui/react-icons": "^1.3.0",
Expand All @@ -26,6 +26,7 @@
"lucide-react": "^0.441.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-hotkeys-hook": "^4.5.1",
"react-redux": "^9.1.2",
"reactflow": "^11.11.4",
"tailwind-merge": "^2.5.2",
Expand Down
15 changes: 15 additions & 0 deletions packages/editor/src/blocks/endNode.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Node } from "reactflow";
import { NodeData } from "@/types/NodeTypes";

export const endNode: Partial<Node<NodeData>> = {
type: "custom",
data: {
addable: false,
block: "[email protected]",
label: "End",
color: "rgb(239 68 68)",
sourceHandle: false,
targetHandle: true,
icon: "Flag",
},
};
15 changes: 15 additions & 0 deletions packages/editor/src/blocks/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { startNode } from "./startNode";
import { inputNode } from "./inputNode";
import { logicNode } from "./logicNode";
import { outputNode } from "./outputNode";
import { endNode } from "./endNode";

export const blockConfigs = {
start: startNode,
input: inputNode,
logic: logicNode,
output: outputNode,
end: endNode,
};

export type BlockType = keyof typeof blockConfigs;
29 changes: 29 additions & 0 deletions packages/editor/src/blocks/inputNode.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { Node } from "reactflow";
import { NodeData } from "@/types/NodeTypes";

export const inputNode: Partial<Node<NodeData>> = {
type: "custom",
data: {
block: "[email protected]",
label: "Input",
color: "rgb(234 179 8)",
sourceHandle: true,
targetHandle: true,
icon: "TextCursorInput",
inputs: {},
config: {
input: "",
},
outputs: {
output: "",
},
controls: [
{
type: "text",
label: "Value",
name: "input",
placeholder: "Pass to output",
},
],
},
};
29 changes: 29 additions & 0 deletions packages/editor/src/blocks/logicNode.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { Node } from "reactflow";
import { NodeData } from "@/types/NodeTypes";

export const logicNode: Partial<Node<NodeData>> = {
type: "custom",
data: {
block: "[email protected]",
label: "Logic",
color: "rgb(59 130 246)",
sourceHandle: false,
targetHandle: true,
icon: "GitBranch",
inputs: { value: "" },
outputs: {
result: "",
},
config: {
logicOperator: "AND",
conditions: [],
},
controls: [
{
type: "conditions-summary",
label: "Conditions summary",
name: "conditions",
},
],
},
};
22 changes: 22 additions & 0 deletions packages/editor/src/blocks/outputNode.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Node } from "reactflow";
import { NodeData } from "@/types/NodeTypes";

export const outputNode: Partial<Node<NodeData>> = {
type: "custom",
data: {
block: "[email protected]",
label: "Output",
color: "rgb(234 179 8)",
sourceHandle: true,
targetHandle: true,
icon: "Square",
controls: [
{
label: "",
type: "text-area",
name: "output",
placeholder: "Value from input will be displayed here after execution",
},
],
},
};
15 changes: 15 additions & 0 deletions packages/editor/src/blocks/startNode.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { NodeData } from "@/types/NodeTypes";
import { Node } from "reactflow";

export const startNode: Partial<Node<NodeData>> = {
type: "custom",
data: {
addable: false,
block: "[email protected]",
label: "Start",
color: "rgb(34 197 94)",
sourceHandle: true,
targetHandle: false,
icon: "Play",
},
};
4 changes: 2 additions & 2 deletions packages/editor/src/components/CustomNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ import { useExecutionState } from "@/hooks/useExecutionState";
import clsx from "clsx";
import { createBlockValidationErrorFromObject } from "@data-river/blocks/errors/blockValidationError";

const CustomNode: React.FC<NodeProps<NodeData>> = ({ id, data }) => {
const CustomNode: React.FC<NodeProps<NodeData>> = ({ id, data, selected }) => {
const { selectedNodeId, hoveredNodeId } = useReactFlowState();
const executionResult = useExecutionState((x) => x.executionResult);

const isSelected = id === selectedNodeId;
const isSelected = id === selectedNodeId || selected;
const isHovered = hoveredNodeId === id;
const showHandles =
isSelected || selectedNodeId === id || hoveredNodeId === id;
Expand Down
102 changes: 0 additions & 102 deletions packages/editor/src/components/EditNodeSheet.tsx

This file was deleted.

26 changes: 19 additions & 7 deletions packages/editor/src/components/Flow.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
import React from "react";
import React, { useEffect } from "react";

Check warning on line 1 in packages/editor/src/components/Flow.tsx

View workflow job for this annotation

GitHub Actions / build

'useEffect' is defined but never used
import ReactFlow, {
ConnectionMode,
Background,
Panel,
NodeTypes,
EdgeTypes,
SelectionMode,
} from "reactflow";
import "reactflow/dist/style.css";
import { useReactFlowState } from "@hooks/useReactFlowState";
import { useReactFlowHooks } from "@hooks/useReactFlowHooks";
import { useReactFlowEventHandlers } from "@hooks/useReactFlowEventHandlers";
import useEditorState from "@/hooks/useEditorState";

import CustomNode from "./CustomNode";
import CustomNodeInfo from "./CustomNodeInfo";
import CustomEdge from "./CustomEdge";
import Controls from "./controls";
import EditNodeSheet from "./EditNodeSheet";

const nodeTypes: NodeTypes = {
custom: CustomNode,
Expand All @@ -29,10 +30,11 @@ const FlowChart: React.FC = () => {
const { lightTheme, nodes, edges } = useReactFlowState();
const eventHandlers = useReactFlowEventHandlers();
useReactFlowHooks();
const isPanning = useEditorState((state) => state.isPanning);

return (
<div
className="w-full h-full min-h-full"
className="w-full h-full min-h-full cursor-default"
style={{
backgroundColor: lightTheme
? "#f0f0f0"
Expand All @@ -52,7 +54,6 @@ const FlowChart: React.FC = () => {
onNodeMouseEnter={eventHandlers.onNodeMouseEnter}
onNodeMouseLeave={eventHandlers.onNodeMouseLeave}
onNodeClick={eventHandlers.onNodeClick}
onNodeDragStart={eventHandlers.onNodeDragStart}
connectionMode={ConnectionMode.Loose}
nodeTypes={nodeTypes}
defaultEdgeOptions={{
Expand All @@ -62,15 +63,26 @@ const FlowChart: React.FC = () => {
edgeTypes={edgeTypes}
minZoom={0.5}
maxZoom={3}
fitView
selectNodesOnDrag={true}
selectionOnDrag={true}
selectionMode={SelectionMode.Partial}
panOnDrag={[1, 2]}
panOnScroll
>
<Background color={"hsl(var(--foreground))"} style={{ opacity: 0.6 }} />
<Background
className="cursor-default"
color={"hsl(var(--foreground))"}
style={{ opacity: 0.6 }}
/>
<Controls />
<Panel position="bottom-right">
<CustomNodeInfo />
</Panel>
</ReactFlow>

<EditNodeSheet />
<span className="absolute top-20 left-20">
{isPanning ? "true" : "false"}
</span>
</div>
);
};
Expand Down
2 changes: 0 additions & 2 deletions packages/editor/src/components/LeftPanel.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import React from "react";

const LeftPanel = () => {
return <div className="bg-background h-full w-full"></div>;
};
Expand Down
Loading

0 comments on commit cf079b2

Please sign in to comment.