feat(nodes): add group type
This commit is contained in:
@@ -61,10 +61,11 @@ const initialNodes: Node[] = [
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: '5',
|
id: '5',
|
||||||
|
type: 'group',
|
||||||
data: { label: 'Node 5' },
|
data: { label: 'Node 5' },
|
||||||
position: { x: 650, y: 250 },
|
position: { x: 650, y: 250 },
|
||||||
className: 'light',
|
className: 'light',
|
||||||
style: { backgroundColor: 'rgba(20 ,200, 255, 1.5)', width: 400, height: 150 },
|
style: { width: 400, height: 150 },
|
||||||
zIndex: 1000,
|
zIndex: 1000,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -98,7 +99,6 @@ const initialEdges: Edge[] = [
|
|||||||
{ id: 'e4a-4b1', source: '4a', target: '4b1' },
|
{ id: 'e4a-4b1', source: '4a', target: '4b1' },
|
||||||
{ id: 'e4a-4b2', source: '4a', target: '4b2', zIndex: 100 },
|
{ id: 'e4a-4b2', source: '4a', target: '4b2', zIndex: 100 },
|
||||||
{ id: 'e4b1-4b2', source: '4b1', target: '4b2' },
|
{ id: 'e4b1-4b2', source: '4b1', target: '4b2' },
|
||||||
{ id: '3-5', source: '3', target: '5' },
|
|
||||||
];
|
];
|
||||||
|
|
||||||
const nodeTypes = {
|
const nodeTypes = {
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
const GroupNode = () => null;
|
||||||
|
|
||||||
|
GroupNode.displayName = 'GroupNode';
|
||||||
|
|
||||||
|
export default GroupNode;
|
||||||
@@ -3,6 +3,7 @@ import { ComponentType } from 'react';
|
|||||||
import DefaultNode from '../../components/Nodes/DefaultNode';
|
import DefaultNode from '../../components/Nodes/DefaultNode';
|
||||||
import InputNode from '../../components/Nodes/InputNode';
|
import InputNode from '../../components/Nodes/InputNode';
|
||||||
import OutputNode from '../../components/Nodes/OutputNode';
|
import OutputNode from '../../components/Nodes/OutputNode';
|
||||||
|
import GroupNode from '../../components/Nodes/GroupNode';
|
||||||
import wrapNode from '../../components/Nodes/wrapNode';
|
import wrapNode from '../../components/Nodes/wrapNode';
|
||||||
import { NodeTypesType, NodeProps } from '../../types';
|
import { NodeTypesType, NodeProps } from '../../types';
|
||||||
|
|
||||||
@@ -11,11 +12,12 @@ export function createNodeTypes(nodeTypes: NodeTypesType): NodeTypesType {
|
|||||||
input: wrapNode((nodeTypes.input || InputNode) as ComponentType<NodeProps>),
|
input: wrapNode((nodeTypes.input || InputNode) as ComponentType<NodeProps>),
|
||||||
default: wrapNode((nodeTypes.default || DefaultNode) as ComponentType<NodeProps>),
|
default: wrapNode((nodeTypes.default || DefaultNode) as ComponentType<NodeProps>),
|
||||||
output: wrapNode((nodeTypes.output || OutputNode) as ComponentType<NodeProps>),
|
output: wrapNode((nodeTypes.output || OutputNode) as ComponentType<NodeProps>),
|
||||||
|
group: wrapNode((nodeTypes.group || GroupNode) as ComponentType<NodeProps>),
|
||||||
};
|
};
|
||||||
|
|
||||||
const wrappedTypes = {} as NodeTypesType;
|
const wrappedTypes = {} as NodeTypesType;
|
||||||
const specialTypes: NodeTypesType = Object.keys(nodeTypes)
|
const specialTypes: NodeTypesType = Object.keys(nodeTypes)
|
||||||
.filter((k) => !['input', 'default', 'output'].includes(k))
|
.filter((k) => !['input', 'default', 'output', 'group'].includes(k))
|
||||||
.reduce((res, key) => {
|
.reduce((res, key) => {
|
||||||
res[key] = wrapNode((nodeTypes[key] || DefaultNode) as ComponentType<NodeProps>);
|
res[key] = wrapNode((nodeTypes[key] || DefaultNode) as ComponentType<NodeProps>);
|
||||||
|
|
||||||
|
|||||||
+20
-43
@@ -1,8 +1,3 @@
|
|||||||
.react-flow__selection {
|
|
||||||
background: rgba(0, 89, 220, 0.08);
|
|
||||||
border: 1px dotted rgba(0, 89, 220, 0.8);
|
|
||||||
}
|
|
||||||
|
|
||||||
.react-flow__edge {
|
.react-flow__edge {
|
||||||
&.selected {
|
&.selected {
|
||||||
.react-flow__edge-path {
|
.react-flow__edge-path {
|
||||||
@@ -46,7 +41,8 @@
|
|||||||
|
|
||||||
.react-flow__node-default,
|
.react-flow__node-default,
|
||||||
.react-flow__node-input,
|
.react-flow__node-input,
|
||||||
.react-flow__node-output {
|
.react-flow__node-output,
|
||||||
|
.react-flow__node-group {
|
||||||
padding: 10px;
|
padding: 10px;
|
||||||
border-radius: 3px;
|
border-radius: 3px;
|
||||||
width: 150px;
|
width: 150px;
|
||||||
@@ -55,31 +51,6 @@
|
|||||||
text-align: center;
|
text-align: center;
|
||||||
border-width: 1px;
|
border-width: 1px;
|
||||||
border-style: solid;
|
border-style: solid;
|
||||||
}
|
|
||||||
|
|
||||||
.react-flow__node-default.selectable,
|
|
||||||
.react-flow__node-input.selectable,
|
|
||||||
.react-flow__node-output.selectable {
|
|
||||||
&:hover {
|
|
||||||
box-shadow: 0 1px 4px 1px rgba(0, 0, 0, 0.08);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.react-flow__node-input {
|
|
||||||
background: #fff;
|
|
||||||
border-color: #0041d0;
|
|
||||||
|
|
||||||
&.selected,
|
|
||||||
&.selected:hover {
|
|
||||||
box-shadow: 0 0 0 0.5px #0041d0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.react-flow__handle {
|
|
||||||
background: #0041d0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.react-flow__node-default {
|
|
||||||
background: #fff;
|
background: #fff;
|
||||||
border-color: #1a192b;
|
border-color: #1a192b;
|
||||||
|
|
||||||
@@ -93,21 +64,27 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.react-flow__node-output {
|
.react-flow__node-default.selectable,
|
||||||
background: #fff;
|
.react-flow__node-input.selectable,
|
||||||
border-color: #ff0072;
|
.react-flow__node-output.selectable,
|
||||||
|
.react-flow__node-group.selectable {
|
||||||
&.selected,
|
&:hover {
|
||||||
&.selected:hover {
|
box-shadow: 0 1px 4px 1px rgba(0, 0, 0, 0.08);
|
||||||
box-shadow: 0 0 0 0.5px #ff0072;
|
|
||||||
}
|
|
||||||
|
|
||||||
.react-flow__handle {
|
|
||||||
background: #ff0072;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.react-flow__nodesselection-rect {
|
.react-flow__node-group {
|
||||||
|
background: rgba(240, 240, 240, 0.25);
|
||||||
|
border-color: #1a192b;
|
||||||
|
|
||||||
|
&.selected,
|
||||||
|
&.selected:hover {
|
||||||
|
box-shadow: 0 0 0 0.5px #1a192b;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.react-flow__nodesselection-rect,
|
||||||
|
.react-flow__selection {
|
||||||
background: rgba(0, 89, 220, 0.08);
|
background: rgba(0, 89, 220, 0.08);
|
||||||
border: 1px dotted rgba(0, 89, 220, 0.8);
|
border: 1px dotted rgba(0, 89, 220, 0.8);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user