Merge branch 'main' into feat/packages

This commit is contained in:
moklick
2023-05-16 10:44:00 +02:00
33 changed files with 229 additions and 138 deletions
@@ -2,8 +2,9 @@ import { Handle, NodeProps, Position, ReactFlowState, useStore } from 'reactflow
const connectionNodeIdSelector = (state: ReactFlowState) => state.connectionNodeId;
export default function CustomNode({ id, isConnectable }: NodeProps) {
export default function CustomNode({ id }: NodeProps) {
const connectionNodeId = useStore(connectionNodeIdSelector);
const isConnecting = !!connectionNodeId;
const isTarget = connectionNodeId && connectionNodeId !== id;
const targetHandleStyle = { zIndex: isTarget ? 3 : 1 };
@@ -18,19 +19,16 @@ export default function CustomNode({ id, isConnectable }: NodeProps) {
backgroundColor: isTarget ? '#ffcce3' : '#ccd9f6',
}}
>
{!isConnecting && (
<Handle className="customHandle" style={{ zIndex: 2 }} position={Position.Right} type="source" />
)}
<Handle
className="targetHandle"
style={{ zIndex: 2 }}
position={Position.Right}
type="source"
isConnectable={isConnectable}
/>
<Handle
className="targetHandle"
className="customHandle"
style={targetHandleStyle}
position={Position.Left}
type="target"
isConnectable={isConnectable}
isConnectableStart={false}
/>
{label}
</div>
@@ -28,19 +28,7 @@
border: 2px solid #222138;
}
div.sourceHandle {
width: 100%;
height: 100%;
position: absolute;
top: 0;
left: 0;
border-radius: 0;
transform: none;
border: none;
opacity: 0;
}
div.targetHandle {
div.customHandle {
width: 100%;
height: 100%;
background: blue;
@@ -1,5 +1,5 @@
import { FC } from 'react';
import { EdgeProps, getBezierPath } from 'reactflow';
import { BaseEdge, EdgeProps, getBezierPath } from 'reactflow';
const CustomEdge: FC<EdgeProps> = ({
id,
@@ -22,7 +22,7 @@ const CustomEdge: FC<EdgeProps> = ({
return (
<>
<path id={id} className="react-flow__edge-path" d={edgePath} />
<BaseEdge path={edgePath} id={id} />
<text>
<textPath href={`#${id}`} style={{ fontSize: '12px' }} startOffset="50%" textAnchor="middle">
{data.text}
@@ -1,5 +1,5 @@
import { FC } from 'react';
import { EdgeProps, getBezierPath, EdgeText } from 'reactflow';
import { EdgeProps, getBezierPath, EdgeText, BaseEdge } from 'reactflow';
const CustomEdge: FC<EdgeProps> = ({
id,
@@ -22,7 +22,7 @@ const CustomEdge: FC<EdgeProps> = ({
return (
<>
<path id={id} className="react-flow__edge-path" d={edgePath} />
<BaseEdge id={id} path={edgePath} />
<EdgeText
x={labelX}
y={labelY}
@@ -34,7 +34,6 @@ const CustomEdge: FC<EdgeProps> = ({
labelBgBorderRadius={2}
onClick={() => console.log(data)}
/>
;
</>
);
};
@@ -4,7 +4,7 @@ import { Handle, Position, NodeProps, NodeToolbar } from 'reactflow';
const CustomNode: FC<NodeProps> = ({ id, data }) => {
return (
<>
<NodeToolbar isVisible={data.toolbarVisible} position={data.toolbarPosition}>
<NodeToolbar isVisible={data.toolbarVisible} position={data.toolbarPosition} align={data.toolbarAlign}>
<button>delete</button>
<button>copy</button>
<button>expand</button>
@@ -17,49 +17,38 @@ const nodeTypes: NodeTypes = {
custom: CustomNode,
};
const positions = ['top', 'right', 'bottom', 'left'];
const alignments = ['start', 'center', 'end'];
const initialNodes: Node[] = [
{
id: '1',
type: 'custom',
data: { label: 'toolbar top', toolbarPosition: Position.Top },
position: { x: 0, y: 50 },
className: 'react-flow__node-default',
},
{
id: '2',
type: 'custom',
data: { label: 'toolbar right', toolbarPosition: Position.Right },
position: { x: 300, y: 0 },
className: 'react-flow__node-default',
},
{
id: '3',
type: 'custom',
data: { label: 'toolbar bottom', toolbarPosition: Position.Bottom },
position: { x: 400, y: 100 },
className: 'react-flow__node-default',
},
{
id: '4',
type: 'custom',
data: { label: 'toolbar left', toolbarPosition: Position.Left },
position: { x: 400, y: 200 },
className: 'react-flow__node-default',
},
{
id: '5',
type: 'custom',
data: { label: 'toolbar always open', toolbarPosition: Position.Top, toolbarVisible: true },
position: { x: 0, y: 200 },
data: { label: 'toolbar top', toolbarPosition: Position.Top },
position: { x: 0, y: -200 },
className: 'react-flow__node-default',
},
];
const initialEdges: Edge[] = [
{ id: 'e1-2', source: '1', target: '2' },
{ id: 'e1-3', source: '1', target: '3' },
{ id: 'e1-4', source: '1', target: '4' },
];
positions.forEach((position, posIndex) => {
alignments.forEach((align, alignIndex) => {
const id = `node-${align}-${position}`;
initialNodes.push({
id,
type: 'custom',
data: {
label: `toolbar ${position} ${align}`,
toolbarPosition: position as Position,
toolbarAlign: align,
toolbarVisible: true,
},
className: 'react-flow__node-default',
position: { x: posIndex * 300, y: alignIndex * 100 },
});
});
});
const initialEdges: Edge[] = [];
const defaultEdgeOptions = { zIndex: 0 };
const nodeOrigin: NodeOrigin = [0.5, 0.5];