mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-18 18:41:14 +00:00
feat(editor): Add remove node and connections functionality to canvas v2 (#9602)
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
import type { IConnections, INodeTypeDescription } from 'n8n-workflow';
|
||||
import type { IConnection, IConnections, INodeTypeDescription } from 'n8n-workflow';
|
||||
import type { INodeUi } from '@/Interface';
|
||||
import type { CanvasConnection, CanvasConnectionPortType, CanvasConnectionPort } from '@/types';
|
||||
import type { Connection } from '@vue-flow/core';
|
||||
import { v4 as uuid } from 'uuid';
|
||||
import { isValidNodeConnectionType } from '@/utils/typeGuards';
|
||||
import { NodeConnectionType } from 'n8n-workflow';
|
||||
|
||||
export function mapLegacyConnectionsToCanvasConnections(
|
||||
legacyConnections: IConnections,
|
||||
@@ -49,6 +52,53 @@ export function mapLegacyConnectionsToCanvasConnections(
|
||||
return mappedConnections;
|
||||
}
|
||||
|
||||
export function parseCanvasConnectionHandleString(handle: string | null | undefined) {
|
||||
const [, type, index] = (handle ?? '').split('/');
|
||||
|
||||
const resolvedType = isValidNodeConnectionType(type) ? type : NodeConnectionType.Main;
|
||||
|
||||
let resolvedIndex = parseInt(index, 10);
|
||||
if (isNaN(resolvedIndex)) {
|
||||
resolvedIndex = 0;
|
||||
}
|
||||
|
||||
return {
|
||||
type: resolvedType,
|
||||
index: resolvedIndex,
|
||||
};
|
||||
}
|
||||
|
||||
export function mapCanvasConnectionToLegacyConnection(
|
||||
sourceNode: INodeUi,
|
||||
targetNode: INodeUi,
|
||||
connection: Connection,
|
||||
): [IConnection, IConnection] {
|
||||
// Output
|
||||
const sourceNodeName = sourceNode?.name ?? '';
|
||||
const { type: sourceType, index: sourceIndex } = parseCanvasConnectionHandleString(
|
||||
connection.sourceHandle,
|
||||
);
|
||||
|
||||
// Input
|
||||
const targetNodeName = targetNode?.name ?? '';
|
||||
const { type: targetType, index: targetIndex } = parseCanvasConnectionHandleString(
|
||||
connection.targetHandle,
|
||||
);
|
||||
|
||||
return [
|
||||
{
|
||||
node: sourceNodeName,
|
||||
type: sourceType,
|
||||
index: sourceIndex,
|
||||
},
|
||||
{
|
||||
node: targetNodeName,
|
||||
type: targetType,
|
||||
index: targetIndex,
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
export function mapLegacyEndpointsToCanvasConnectionPort(
|
||||
endpoints: INodeTypeDescription['inputs'],
|
||||
): CanvasConnectionPort[] {
|
||||
|
||||
Reference in New Issue
Block a user