2.4.7 • Published 8 months ago

@kseniass/react-flow-editor v2.4.7

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

Flow Editor

npm version

Try in your browser.

Main features

  • DnD to move canvas or nodes
  • Available autoScroll when DnD connection or nodes
  • Multiple Selection with SHIFT + click nodes
  • Multiple Selection with SHIFT and dragging select zone
  • Delete (multiple too) selected nodes with DELETE/BACKSPACE
  • DnD multiple selected nodes with SHIFT
  • Scroll mouse to zoom
  • Connectors could be disconnected from both edges
  • Overview function to place all the nodes to viewPort

API

Editor Configuration

The editor props looks as follow

export type EditorProps = {
  nodes: Node[]
  setNodes: (action: SetStateAction<Node[]>) => void
  transformation: Transformation
  setTransformation: (transformation: Transformation) => void
  onSelectionZoneChanged?: (value: RectZone) => void
  onEditorRectsMounted?: (value: OnEditorRectsMountedProps) => void
  styleConfig?: StyleConfig
}

export type Output = {
  id: string
  position: Point
  nextNodeId: string | null
}

export type NodeBase = {
  id: string
  outputs: Output[]
  position: Point
  rectPosition?: DOMRect
  inputPosition?: Point
  inputNumber: number
  state: NodeState | null
}

export type Node = NodeBase & {
  children: React.FC<NodeProps>
}

export type NodeProps = NodeBase & {
  onSizeChanged: () => void
}

export type Transformation = {
  dx: number
  dy: number
  zoom: number
}

export type RectZone = {
  left: number
  right: number
  top: number
  bottom: number
}

export type OnEditorRectsMountedProps = {
  zoomContainerRef: MutableRefObject<HTMLDivElement>
  editorContainerRef: MutableRefObject<HTMLDivElement>
  overview: () => void
}
PropDescription
nodesArray of nodes to render in editor
setNodesFunction for nodes managing
transformationEditor translate and scale transformation
setTransformationTransformation managing function
onEditorRectsMountedCallback for receiving editor DOMRect and nodes container DOMRect
onSelectionZoneChangedCallback for receiving selection zone coordinates
styleConfigConfig of editor parts styles

Node

PropDescription
idThe unique identifier for the node
positionCoordinates of the node
rectPositionDOMRect for the node
outputsArray of outputs. Each output contains data about point position (relatively to node) and connected node id.
inputPositionPosition of input point for connectors (relatively to node)
inputNumberMax number of inputs
stateNode state

Node states

  • null
  • dragging
  • selected
  • draggingConnector
  • connectorHovered

Rules for node states

  1. node mouseDown = no changes in state
  2. node mouseDown -> mouseUp = selected
  3. node mouseDown -> mouseMove = dragging
  4. node mouseDown -> mouseMove -> mouseUp = null

  5. SHIFT + node mouseDown = no changes in state

  6. SHIFT + (node mouseDown -> mouseUp) = selected
  7. SHIFT + (node mouseDown-> mouseMove) = dragging
  8. SHIFT + (node mouseDown-> mouseMove -> mouseUp) = selected

  9. SHIFT + (node click -> node_2 click) = selected both

  10. SHIFT + (node click -> node_2 click -> (node or node_2) mouseDown -> mouseMove) = dragging both
  11. SHIFT + (node click -> node_2 click -> (node or node_2) mouseDown -> mouseMove -> mouseUp) = selected both

  12. DnD from node_1 point = draggingConnector

  13. DnD from node_1 point over node_2 point = node_1 draggingConnector and node_2 connectorHovered
  14. DnD from node_1 point drop in any place = null for all

  15. click away from nodes = null for all

Transfromation

PropDescription
dxHorizontal editor offset
dyVertical editor offset
zoomEditor zoom

Selection zone

PropDescription
cornerStartCoordinates of the start selection point
cornerEndCoordinates of the end selection point

OnEditorRectsMountedProps

PropDescription
zoomContainerRefReact Ref Object of nodes container
editorContainerRefReact Ref Object of editor
overviewFunction for applying transformation to place all the nodes into viewPort

styleConfig

PropDescription
pointPoint styles
connectorConnector styles

PointStyleConfig

PropDescription
widthPoint width
heightPoint height
colorPoint color

ConnectorStyleConfig

PropDescription
widthConnector width
colorConnector color

Changelog

2.4.5

8 months ago

2.3.5

9 months ago

2.4.7

8 months ago

2.4.6

8 months ago

2.2.5

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

2.0.0

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago

1.1.4

1 year ago

1.1.3

1 year ago

1.1.2

1 year ago

2.1.4

1 year ago

2.1.4-test

1 year ago

2.1.3

1 year ago

2.1.5

1 year ago

2.1.0

1 year ago

0.7.61

2 years ago

0.7.60

2 years ago

0.7.55

2 years ago

0.7.54

2 years ago

0.7.57

2 years ago

0.7.56

2 years ago

0.7.59

2 years ago

0.7.58

2 years ago

0.7.52

2 years ago

0.7.51

2 years ago

0.7.50

2 years ago

0.7.49

2 years ago

0.7.48

2 years ago

0.7.47

2 years ago

0.7.46

2 years ago

0.7.45

2 years ago

0.7.44

2 years ago

0.7.43

2 years ago

0.7.42

2 years ago

0.7.41

2 years ago

0.7.40

2 years ago

0.7.39

2 years ago

0.7.3-8.3

2 years ago

0.7.3-8.2

2 years ago

0.7.3-8.1

2 years ago

0.7.38

2 years ago

0.7.3-7.1

2 years ago

0.7.37

2 years ago

0.7.3-6.7

2 years ago

0.7.3-6.6

2 years ago

0.7.3-6.5

2 years ago

0.7.3-6.4

2 years ago

0.7.3-6.3

2 years ago

0.7.3-6.2

2 years ago

0.7.3-6.1

2 years ago

0.7.36

2 years ago

0.7.35

2 years ago

0.7.34

2 years ago

0.7.33

2 years ago

0.7.32

2 years ago

0.7.31

2 years ago

0.7.30

2 years ago

0.7.29

2 years ago

0.7.28

2 years ago

0.7.27

2 years ago

0.7.26

2 years ago

0.7.25

2 years ago

0.7.24

2 years ago

0.7.23

2 years ago

0.7.22

2 years ago

0.7.21

2 years ago

0.7.20

2 years ago

0.7.19

2 years ago

0.7.18

2 years ago

0.7.17

2 years ago

0.7.16

2 years ago

0.7.15

2 years ago

0.7.14

2 years ago

0.7.13

2 years ago

0.7.12

2 years ago

0.7.11

2 years ago

0.7.10

2 years ago

0.7.2

2 years ago

0.7.1

2 years ago

0.7.0

2 years ago

0.6.11

2 years ago

0.6.10

2 years ago

0.6.9

2 years ago

0.6.8

2 years ago

0.6.7

2 years ago

0.6.6

2 years ago

0.6.5

2 years ago

0.6.4

2 years ago

0.6.3

2 years ago

0.6.2

2 years ago

0.6.1

2 years ago