projectstorm / react-diagrams

a super simple, no-nonsense diagramming library written in react that just works
https://projectstorm.cloud/react-diagrams
MIT License
8.71k stars 1.18k forks source link

Request for custom addPointToLink function on the DefaultLinkWidget #1036

Open JarneVanAerde opened 3 months ago

JarneVanAerde commented 3 months ago

Hi,

Thanks for making this library!

There is a piece of functionality that we were using to customize the way points are added to the lines that connect the widgets. We only want this to trigger when the user does a mouse click in combination with pressing the CTRL-key.

The way we did this is by overriding the addPointToLink function:

import { DefaultLinkWidget, PointModel } from '@projectstorm/react-diagrams'

class BaseLinkWidget extends DefaultLinkWidget {
  addPointToLink = (event: any, index: number) => {
    if (
      event.ctrlKey &&
      !this.props.link.isLocked() &&
      this.props.link.getPoints().length - 1 <= this.props.diagramEngine.getMaxNumberPointsPerLink()
    ) {
      const point = new PointModel({
        link: this.props.link,
        position: this.props.diagramEngine.getRelativeMousePoint(event)
      })
      this.props.link.addPoint(point, index)
      event.persist()
      event.stopPropagation()
      this.forceUpdate(() => {
        this.props.diagramEngine.getActionEventBus().fireAction({
          event,
          model: point
        })
      })
    }
  }
}

export default BaseLinkWidget

This is no longer possible since the following commit: https://github.com/projectstorm/react-diagrams/commit/20766f539e81279344d5e1a7646cf7c2815e1835

Can this functionality be added back or be provided in another way?

Thanks in advance!