@@ -1,30 +1,22 @@
|
|||||||
import React from 'react';
|
import React, { memo } from 'react';
|
||||||
|
|
||||||
import { Handle } from 'react-flow-renderer';
|
import { Handle } from 'react-flow-renderer';
|
||||||
|
|
||||||
export default ({ data }) => {
|
export default memo(({ data }) => {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Handle
|
<Handle
|
||||||
type="target"
|
type="target"
|
||||||
position="left"
|
position="left"
|
||||||
style={{ background: '#fff' }}
|
style={{ background: '#fff' }}
|
||||||
onConnect={params => console.log('handle onConnect', params)}
|
onConnect={(params) => console.log('handle onConnect', params)}
|
||||||
/>
|
|
||||||
<div>Custom Color Picker Node: <strong>{data.color}</strong></div>
|
|
||||||
<input className="nodrag" type="color" onChange={data.onChange} defaultValue={data.color}/>
|
|
||||||
<Handle
|
|
||||||
type="source"
|
|
||||||
position="right"
|
|
||||||
id="a"
|
|
||||||
style={{ top: 10, background: '#fff' }}
|
|
||||||
/>
|
|
||||||
<Handle
|
|
||||||
type="source"
|
|
||||||
position="right"
|
|
||||||
id="b"
|
|
||||||
style={{ bottom: 10, top: 'auto', background: '#fff' }}
|
|
||||||
/>
|
/>
|
||||||
|
<div>
|
||||||
|
Custom Color Picker Node: <strong>{data.color}</strong>
|
||||||
|
</div>
|
||||||
|
<input className="nodrag" type="color" onChange={data.onChange} defaultValue={data.color} />
|
||||||
|
<Handle type="source" position="right" id="a" style={{ top: 10, background: '#fff' }} />
|
||||||
|
<Handle type="source" position="right" id="b" style={{ bottom: 10, top: 'auto', background: '#fff' }} />
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
});
|
||||||
|
|||||||
@@ -8,53 +8,43 @@ const initialElements = [
|
|||||||
{ id: '0', type: 'custominput', position: { x: 0, y: 150 } },
|
{ id: '0', type: 'custominput', position: { x: 0, y: 150 } },
|
||||||
{ id: 'A', type: 'customnode', position: { x: 250, y: 0 } },
|
{ id: 'A', type: 'customnode', position: { x: 250, y: 0 } },
|
||||||
{ id: 'B', type: 'customnode', position: { x: 250, y: 150 } },
|
{ id: 'B', type: 'customnode', position: { x: 250, y: 150 } },
|
||||||
{ id: 'C', type: 'customnode', position: { x: 250, y:300 } },
|
{ id: 'C', type: 'customnode', position: { x: 250, y: 300 } },
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const isValidConnection = (connection) => connection.target === 'B';
|
||||||
|
|
||||||
const CustomInput = () => (
|
const CustomInput = () => (
|
||||||
<>
|
<>
|
||||||
<div>Only connectable with B</div>
|
<div>Only connectable with B</div>
|
||||||
<Handle
|
<Handle type="source" position="right" isValidConnection={isValidConnection} />
|
||||||
type="source"
|
|
||||||
position="right"
|
|
||||||
isValidConnection={connection => connection.target === 'B'}
|
|
||||||
/>
|
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|
||||||
const CustomNode = ({ id }) => (
|
const CustomNode = ({ id }) => (
|
||||||
<>
|
<>
|
||||||
<Handle
|
<Handle type="target" position="left" isValidConnection={isValidConnection} />
|
||||||
type="target"
|
|
||||||
position="left"
|
|
||||||
isValidConnection={_ => id === 'B'}
|
|
||||||
/>
|
|
||||||
<div>{id}</div>
|
<div>{id}</div>
|
||||||
<Handle
|
<Handle type="source" position="right" isValidConnection={isValidConnection} />
|
||||||
type="source"
|
|
||||||
position="right"
|
|
||||||
isValidConnection={_ => id === 'B'}
|
|
||||||
/>
|
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|
||||||
const HorizontalFlow = () => {
|
const HorizontalFlow = () => {
|
||||||
const [elements, setElements] = useState(initialElements);
|
const [elements, setElements] = useState(initialElements);
|
||||||
const onConnect = (params) => setElements(els => addEdge(params, els));
|
const onConnect = (params) => setElements((els) => addEdge(params, els));
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ReactFlow
|
<ReactFlow
|
||||||
elements={elements}
|
elements={elements}
|
||||||
onConnect={onConnect}
|
onConnect={onConnect}
|
||||||
selectNodesOnDrag={false}
|
selectNodesOnDrag={false}
|
||||||
onLoad={reactFlowInstance => reactFlowInstance.fitView()}
|
onLoad={(reactFlowInstance) => reactFlowInstance.fitView()}
|
||||||
className="validationflow"
|
className="validationflow"
|
||||||
nodeTypes={{
|
nodeTypes={{
|
||||||
custominput: CustomInput,
|
custominput: CustomInput,
|
||||||
customnode: CustomNode
|
customnode: CustomNode,
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
};
|
||||||
|
|
||||||
export default HorizontalFlow;
|
export default HorizontalFlow;
|
||||||
|
|||||||
@@ -1,15 +1,15 @@
|
|||||||
import React from 'react';
|
import React, { memo } from 'react';
|
||||||
|
|
||||||
import Handle from '../../components/Handle';
|
import Handle from '../../components/Handle';
|
||||||
import { NodeProps, Position } from '../../types';
|
import { NodeProps, Position } from '../../types';
|
||||||
|
|
||||||
const DefaultNode = ({ data, targetPosition = Position.Top, sourcePosition = Position.Bottom }: NodeProps) => (
|
const DefaultNode = memo(({ data, targetPosition = Position.Top, sourcePosition = Position.Bottom }: NodeProps) => (
|
||||||
<>
|
<>
|
||||||
<Handle type="target" position={targetPosition} />
|
<Handle type="target" position={targetPosition} />
|
||||||
{data.label}
|
{data.label}
|
||||||
<Handle type="source" position={sourcePosition} />
|
<Handle type="source" position={sourcePosition} />
|
||||||
</>
|
</>
|
||||||
);
|
));
|
||||||
|
|
||||||
DefaultNode.displayName = 'DefaultNode';
|
DefaultNode.displayName = 'DefaultNode';
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
import React from 'react';
|
import React, { memo } from 'react';
|
||||||
|
|
||||||
import Handle from '../../components/Handle';
|
import Handle from '../../components/Handle';
|
||||||
import { NodeProps, Position } from '../../types';
|
import { NodeProps, Position } from '../../types';
|
||||||
|
|
||||||
const InputNode = ({ data, sourcePosition = Position.Bottom }: NodeProps) => (
|
const InputNode = memo(({ data, sourcePosition = Position.Bottom }: NodeProps) => (
|
||||||
<>
|
<>
|
||||||
{data.label}
|
{data.label}
|
||||||
<Handle type="source" position={sourcePosition} />
|
<Handle type="source" position={sourcePosition} />
|
||||||
</>
|
</>
|
||||||
);
|
));
|
||||||
|
|
||||||
InputNode.displayName = 'InputNode';
|
InputNode.displayName = 'InputNode';
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
import React from 'react';
|
import React, { memo } from 'react';
|
||||||
|
|
||||||
import Handle from '../../components/Handle';
|
import Handle from '../../components/Handle';
|
||||||
import { NodeProps, Position } from '../../types';
|
import { NodeProps, Position } from '../../types';
|
||||||
|
|
||||||
const OutputNode = ({ data, targetPosition = Position.Top }: NodeProps) => (
|
const OutputNode = memo(({ data, targetPosition = Position.Top }: NodeProps) => (
|
||||||
<>
|
<>
|
||||||
<Handle type="target" position={targetPosition} />
|
<Handle type="target" position={targetPosition} />
|
||||||
{data.label}
|
{data.label}
|
||||||
</>
|
</>
|
||||||
);
|
));
|
||||||
|
|
||||||
OutputNode.displayName = 'OutputNode';
|
OutputNode.displayName = 'OutputNode';
|
||||||
|
|
||||||
|
|||||||
+3
-1
@@ -330,7 +330,9 @@ export const storeModel: StoreModel = {
|
|||||||
}),
|
}),
|
||||||
|
|
||||||
updateTransform: action((state, transform) => {
|
updateTransform: action((state, transform) => {
|
||||||
state.transform = [transform.x, transform.y, transform.k];
|
state.transform[0] = transform.x;
|
||||||
|
state.transform[1] = transform.y;
|
||||||
|
state.transform[2] = transform.k;
|
||||||
}),
|
}),
|
||||||
|
|
||||||
updateSize: action((state, size) => {
|
updateSize: action((state, size) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user