refactor uuids

This commit is contained in:
Mutasem 2021-11-11 16:15:49 +01:00
parent 2b872ebf42
commit 07f6848065
3 changed files with 17 additions and 15 deletions

View file

@ -60,9 +60,6 @@ const anchorPositions: {
}, },
}; };
const INPUT_UUID_KEY = '-input';
const OUTPUT_UUID_KEY = '-output';
const getInputEndpointStyle = (nodeTypeData: INodeTypeDescription, color: string) => ({ const getInputEndpointStyle = (nodeTypeData: INodeTypeDescription, color: string) => ({
width: 8, width: 8,
height: nodeTypeData && nodeTypeData.outputs.length > 2 ? 18 : 20, height: nodeTypeData && nodeTypeData.outputs.length > 2 ? 18 : 20,
@ -148,7 +145,7 @@ export const nodeBase = mixins(
const anchorPosition = anchorPositions.input[nodeTypeData.inputs.length][index]; const anchorPosition = anchorPositions.input[nodeTypeData.inputs.length][index];
const newEndpointData: IEndpointOptions = { const newEndpointData: IEndpointOptions = {
uuid: `${this.nodeIndex}` + INPUT_UUID_KEY + index, uuid: CanvasHelpers.getInputEndpointUUID(this.nodeIndex, index),
anchor: anchorPosition, anchor: anchorPosition,
maxConnections: -1, maxConnections: -1,
endpoint: 'Rectangle', endpoint: 'Rectangle',
@ -213,7 +210,7 @@ export const nodeBase = mixins(
const anchorPosition = anchorPositions.output[nodeTypeData.outputs.length][index]; const anchorPosition = anchorPositions.output[nodeTypeData.outputs.length][index];
const newEndpointData: IEndpointOptions = { const newEndpointData: IEndpointOptions = {
uuid: `${this.nodeIndex}` + OUTPUT_UUID_KEY + index, uuid: CanvasHelpers.getInputEndpointUUID(this.nodeIndex, index),
anchor: anchorPosition, anchor: anchorPosition,
maxConnections: -1, maxConnections: -1,
endpoint: 'Dot', endpoint: 'Dot',

View file

@ -1644,17 +1644,14 @@ export default mixins(
} }
}); });
}, },
getOutputEndpointUUID(nodeName: string, index: number) {
return `${this.getNodeIndex(nodeName)}-output${index}`;
},
getInputEndpointUUID(nodeName: string, index: number) {
return `${this.getNodeIndex(nodeName)}-input${index}`;
},
__addConnection (connection: [IConnection, IConnection], addVisualConnection = false) { __addConnection (connection: [IConnection, IConnection], addVisualConnection = false) {
if (addVisualConnection === true) { if (addVisualConnection === true) {
const sourceIndex = this.getNodeIndex(connection[0].node);
const targetIndex = this.getNodeIndex(connection[1].node);
const uuid: [string, string] = [ const uuid: [string, string] = [
this.getOutputEndpointUUID(connection[0].node, connection[0].index), CanvasHelpers.getOutputEndpointUUID(sourceIndex, connection[0].index),
this.getInputEndpointUUID(connection[1].node, connection[1].index), CanvasHelpers.getInputEndpointUUID(targetIndex, connection[1].index),
]; ];
// Create connections in DOM // Create connections in DOM
@ -1762,8 +1759,8 @@ export default mixins(
const targetIndex = this.getNodeIndex(targetNodeName); const targetIndex = this.getNodeIndex(targetNodeName);
const targetId = `${NODE_NAME_PREFIX}${targetIndex}`; const targetId = `${NODE_NAME_PREFIX}${targetIndex}`;
const sourceEndpoint = `${sourceIndex}-output${sourceOutputIndex}`; const sourceEndpoint = CanvasHelpers.getOutputEndpointUUID(sourceIndex, sourceOutputIndex);
const targetEndpoint = `${targetIndex}-input${targetInputIndex}`; const targetEndpoint = CanvasHelpers.getInputEndpointUUID(targetIndex, targetInputIndex);
// @ts-ignore // @ts-ignore
const connections = this.instance.getConnections({ const connections = this.instance.getConnections({

View file

@ -637,3 +637,11 @@ export const addConnectionActionsOverlay = (connection: Connection, onDelete: Fu
]); ]);
}; };
export const getOutputEndpointUUID = (nodeIndex: string, outputIndex: number): string => {
return `${nodeIndex}-output${outputIndex}`;
};
export const getInputEndpointUUID = (nodeIndex: string, inputIndex: number): string => {
return `${nodeIndex}-input${inputIndex}`;
};