Merging dev into main #49
@@ -1,4 +1,4 @@
|
|||||||
import { useDraggable } from '@neodrag/react';
|
import {useDraggable} from '@neodrag/react';
|
||||||
import {
|
import {
|
||||||
useReactFlow,
|
useReactFlow,
|
||||||
type XYPosition
|
type XYPosition
|
||||||
@@ -11,7 +11,6 @@ import {
|
|||||||
} from 'react';
|
} from 'react';
|
||||||
|
|
||||||
|
|
||||||
// improve later to create better automatic IDs
|
|
||||||
let id = 0;
|
let id = 0;
|
||||||
const getId = () => `dndnode_${id++}`;
|
const getId = () => `dndnode_${id++}`;
|
||||||
|
|
||||||
@@ -23,23 +22,23 @@ interface DraggableNodeProps {
|
|||||||
onDrop: (nodeType: string, position: XYPosition) => void;
|
onDrop: (nodeType: string, position: XYPosition) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
function DraggableNode({ className, children, nodeType, onDrop }: DraggableNodeProps) {
|
function DraggableNode({className, children, nodeType, onDrop}: DraggableNodeProps) {
|
||||||
const draggableRef = useRef<HTMLDivElement>(null);
|
const draggableRef = useRef<HTMLDivElement>(null);
|
||||||
const [position, setPosition] = useState<XYPosition>({ x: 0, y: 0 });
|
const [position, setPosition] = useState<XYPosition>({x: 0, y: 0});
|
||||||
|
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
useDraggable(draggableRef, {
|
useDraggable(draggableRef, {
|
||||||
position: position,
|
position: position,
|
||||||
onDrag: ({ offsetX, offsetY }) => {
|
onDrag: ({offsetX, offsetY}) => {
|
||||||
// Calculate position relative to the viewport
|
// Calculate position relative to the viewport
|
||||||
setPosition({
|
setPosition({
|
||||||
x: offsetX,
|
x: offsetX,
|
||||||
y: offsetY,
|
y: offsetY,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
onDragEnd: ({ event }) => {
|
onDragEnd: ({event}) => {
|
||||||
setPosition({ x: 0, y: 0 });
|
setPosition({x: 0, y: 0});
|
||||||
onDrop(nodeType, {
|
onDrop(nodeType, {
|
||||||
x: event.clientX,
|
x: event.clientX,
|
||||||
y: event.clientY,
|
y: event.clientY,
|
||||||
@@ -48,14 +47,15 @@ function DraggableNode({ className, children, nodeType, onDrop }: DraggableNodeP
|
|||||||
});
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={className === "default" ? "draggable-node" : "draggable-node" + "__" + className} ref={draggableRef}>
|
<div className={className === "default" ? "draggable-node" : "draggable-node" + "__" + className}
|
||||||
|
ref={draggableRef}>
|
||||||
{children}
|
{children}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function Sidebar() {
|
export function Sidebar() {
|
||||||
const { setNodes, screenToFlowPosition } = useReactFlow();
|
const {setNodes, screenToFlowPosition} = useReactFlow();
|
||||||
|
|
||||||
const handleNodeDrop = useCallback(
|
const handleNodeDrop = useCallback(
|
||||||
(nodeType: string, screenPosition: XYPosition) => {
|
(nodeType: string, screenPosition: XYPosition) => {
|
||||||
@@ -120,11 +120,26 @@ export function Sidebar() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<aside style={{padding: '10px 10px',outline: '2.5pt solid black',borderRadius: '0pt 0pt 5pt 5pt', borderColor:'dimgrey', backgroundColor:'canvas', display:'flex', flexDirection: 'column', gap: '1rem'}}>
|
<aside style={{
|
||||||
|
padding: '10px 10px',
|
||||||
|
outline: '2.5pt solid black',
|
||||||
|
borderRadius: '0pt 0pt 5pt 5pt',
|
||||||
|
borderColor: 'dimgrey',
|
||||||
|
backgroundColor: 'canvas',
|
||||||
|
display: 'flex',
|
||||||
|
flexDirection: 'column',
|
||||||
|
gap: '1rem'
|
||||||
|
}}>
|
||||||
<div className="description">
|
<div className="description">
|
||||||
You can drag these nodes to the pane to create new nodes.
|
You can drag these nodes to the pane to create new nodes.
|
||||||
</div>
|
</div>
|
||||||
<div className="DraggableNodeContainer" style={{backgroundColor:'canvas', display: 'flex', flexDirection: 'row', gap: '1rem', justifyContent: 'center'}}>
|
<div className="DraggableNodeContainer" style={{
|
||||||
|
backgroundColor: 'canvas',
|
||||||
|
display: 'flex',
|
||||||
|
flexDirection: 'row',
|
||||||
|
gap: '1rem',
|
||||||
|
justifyContent: 'center'
|
||||||
|
}}>
|
||||||
<DraggableNode className="phase" nodeType="phase" onDrop={handleNodeDrop}>
|
<DraggableNode className="phase" nodeType="phase" onDrop={handleNodeDrop}>
|
||||||
phase Node
|
phase Node
|
||||||
</DraggableNode>
|
</DraggableNode>
|
||||||
|
|||||||
Reference in New Issue
Block a user