Join two disconnected links to obtain one link

I suggest that you start with the Draggable Link sample, Draggable Link.

Now you may not be interested in dragging links, in which case you don’t need to set DraggingTool.dragsLink to true. But you will see that links do not need to be connected with ports at either or at both ends. Furthermore, because isUnconnectedLinkValid is true on both the LinkingTool and the RelinkingTool, users can draw a new link from a port and not have to connect it with a port, and users can reconnect a selected link to another port or to no port at all.

(Additionally, if you want users to be able to draw a new link with a mouse-down-and-drag in the background, see the DisconnectedLinkingTool at A tool to create a line - #10 by walter)

Being able to reconnect a link to the unconnected end of a link (that presumably is going in the “same” direction) should be quite possible, but I don’t have that code for you.