|
|
|
@ -1,5 +1,5 @@
|
|
|
|
import { useState, useEffect, useRef, useCallback } from "react";
|
|
|
|
import { useState, useEffect, useRef, useCallback } from "react";
|
|
|
|
import { AnchorId } from "@jsplumb/common";
|
|
|
|
import { AnchorId, AnchorLocations } from "@jsplumb/common";
|
|
|
|
import {
|
|
|
|
import {
|
|
|
|
BeforeDropParams,
|
|
|
|
BeforeDropParams,
|
|
|
|
Connection,
|
|
|
|
Connection,
|
|
|
|
@ -28,12 +28,12 @@ import {
|
|
|
|
} from "../utils/options";
|
|
|
|
} from "../utils/options";
|
|
|
|
import eventBus from "../events/eventBus";
|
|
|
|
import eventBus from "../events/eventBus";
|
|
|
|
import { getConnections } from "../utils";
|
|
|
|
import { getConnections } from "../utils";
|
|
|
|
import { IServiceNodeItem } from "../types";
|
|
|
|
import { IServiceNodeItem, IVolumeNodeItem } from "../types";
|
|
|
|
import { Dictionary, isEqual } from "lodash";
|
|
|
|
import { Dictionary, isEqual } from "lodash";
|
|
|
|
import { IAnchor, CallbackFunction } from "../types";
|
|
|
|
import { IAnchor, CallbackFunction } from "../types";
|
|
|
|
|
|
|
|
|
|
|
|
export const useJsPlumb = (
|
|
|
|
export const useJsPlumb = (
|
|
|
|
nodes: Dictionary<IServiceNodeItem>,
|
|
|
|
nodes: Dictionary<IServiceNodeItem | IVolumeNodeItem>,
|
|
|
|
connections: Array<[string, string]>,
|
|
|
|
connections: Array<[string, string]>,
|
|
|
|
onGraphUpdate: CallbackFunction,
|
|
|
|
onGraphUpdate: CallbackFunction,
|
|
|
|
onNodeUpdate: CallbackFunction,
|
|
|
|
onNodeUpdate: CallbackFunction,
|
|
|
|
@ -47,7 +47,7 @@ export const useJsPlumb = (
|
|
|
|
] => {
|
|
|
|
] => {
|
|
|
|
const [instance, setInstance] = useState<BrowserJsPlumbInstance>(null as any);
|
|
|
|
const [instance, setInstance] = useState<BrowserJsPlumbInstance>(null as any);
|
|
|
|
const containerRef = useRef<HTMLDivElement>();
|
|
|
|
const containerRef = useRef<HTMLDivElement>();
|
|
|
|
const stateRef = useRef<Dictionary<IServiceNodeItem>>();
|
|
|
|
const stateRef = useRef<Dictionary<IServiceNodeItem | IVolumeNodeItem>>();
|
|
|
|
const instanceRef = useRef<BrowserJsPlumbInstance>();
|
|
|
|
const instanceRef = useRef<BrowserJsPlumbInstance>();
|
|
|
|
stateRef.current = nodes;
|
|
|
|
stateRef.current = nodes;
|
|
|
|
instanceRef.current = instance;
|
|
|
|
instanceRef.current = instance;
|
|
|
|
@ -65,12 +65,15 @@ export const useJsPlumb = (
|
|
|
|
targetAnchors: IAnchor[],
|
|
|
|
targetAnchors: IAnchor[],
|
|
|
|
maxConnections: number
|
|
|
|
maxConnections: number
|
|
|
|
) => {
|
|
|
|
) => {
|
|
|
|
|
|
|
|
if (sourceAnchors.length === 0 && targetAnchors.length === 0) {
|
|
|
|
|
|
|
|
instance.addEndpoint(el, {
|
|
|
|
|
|
|
|
endpoint: "Blank"
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sourceAnchors.forEach((x) => {
|
|
|
|
sourceAnchors.forEach((x) => {
|
|
|
|
const endpoint = sourceEndpoint;
|
|
|
|
const endpoint = sourceEndpoint;
|
|
|
|
endpoint.maxConnections = maxConnections;
|
|
|
|
endpoint.maxConnections = maxConnections;
|
|
|
|
|
|
|
|
|
|
|
|
// arrow overlay for connector to specify
|
|
|
|
|
|
|
|
// it's dependency on another service
|
|
|
|
|
|
|
|
instance.addEndpoint(el, endpoint, {
|
|
|
|
instance.addEndpoint(el, endpoint, {
|
|
|
|
anchor: [
|
|
|
|
anchor: [
|
|
|
|
[1, 0.6, 1, 0],
|
|
|
|
[1, 0.6, 1, 0],
|
|
|
|
@ -83,8 +86,8 @@ export const useJsPlumb = (
|
|
|
|
{
|
|
|
|
{
|
|
|
|
type: "PlainArrow",
|
|
|
|
type: "PlainArrow",
|
|
|
|
options: {
|
|
|
|
options: {
|
|
|
|
width: 16,
|
|
|
|
width: 12,
|
|
|
|
length: 16,
|
|
|
|
length: 12,
|
|
|
|
location: 1,
|
|
|
|
location: 1,
|
|
|
|
id: "arrow"
|
|
|
|
id: "arrow"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -96,14 +99,8 @@ export const useJsPlumb = (
|
|
|
|
targetAnchors.forEach((x) => {
|
|
|
|
targetAnchors.forEach((x) => {
|
|
|
|
const endpoint = targetEndpoint;
|
|
|
|
const endpoint = targetEndpoint;
|
|
|
|
endpoint.maxConnections = maxConnections;
|
|
|
|
endpoint.maxConnections = maxConnections;
|
|
|
|
|
|
|
|
|
|
|
|
instance.addEndpoint(el, endpoint, {
|
|
|
|
instance.addEndpoint(el, endpoint, {
|
|
|
|
anchor: [
|
|
|
|
anchor: AnchorLocations.AutoDefault,
|
|
|
|
[0, 0.4, -1, 0],
|
|
|
|
|
|
|
|
[0.4, 1, 0, 1],
|
|
|
|
|
|
|
|
[1, 0.4, 1, 0],
|
|
|
|
|
|
|
|
[0.4, 0, 0, -1]
|
|
|
|
|
|
|
|
],
|
|
|
|
|
|
|
|
uuid: x.id
|
|
|
|
uuid: x.id
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|