mirror of
https://gitee.com/ByteDance/flowgram.ai.git
synced 2025-07-07 17:43:29 +08:00
feat(free-layout): add canDropToNode config to editor-props (#423)
This commit is contained in:
parent
dc5e7eb023
commit
8fa571af9e
@ -114,6 +114,20 @@ export function useEditorProps(
|
|||||||
canDeleteNode(ctx, node) {
|
canDeleteNode(ctx, node) {
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
|
canDropToNode: (ctx, params) => {
|
||||||
|
const { dragNodeType, dropNodeType } = params;
|
||||||
|
/**
|
||||||
|
* 开始/结束节点无法拖入 loop or group
|
||||||
|
* The start and end nodes cannot be dragged into loop or group
|
||||||
|
*/
|
||||||
|
if (
|
||||||
|
(dragNodeType === 'start' || dragNodeType === 'end') &&
|
||||||
|
(dropNodeType === 'loop' || dropNodeType === 'group')
|
||||||
|
) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
},
|
||||||
/**
|
/**
|
||||||
* Drag the end of the line to create an add panel (feature optional)
|
* Drag the end of the line to create an add panel (feature optional)
|
||||||
* 拖拽线条结束需要创建一个添加面板 (功能可选)
|
* 拖拽线条结束需要创建一个添加面板 (功能可选)
|
||||||
|
|||||||
@ -297,6 +297,7 @@ export class WorkflowDragService {
|
|||||||
const dropNode = this._dropNode;
|
const dropNode = this._dropNode;
|
||||||
const { allowDrop } = this.canDropToNode({
|
const { allowDrop } = this.canDropToNode({
|
||||||
dragNodeType: type,
|
dragNodeType: type,
|
||||||
|
dropNodeType: dropNode?.flowNodeType,
|
||||||
dropNode,
|
dropNode,
|
||||||
});
|
});
|
||||||
const dragNode = allowDrop ? await this.dropCard(type, e, data, dropNode) : undefined;
|
const dragNode = allowDrop ? await this.dropCard(type, e, data, dropNode) : undefined;
|
||||||
@ -366,12 +367,31 @@ export class WorkflowDragService {
|
|||||||
/**
|
/**
|
||||||
* 判断是否可以放置节点
|
* 判断是否可以放置节点
|
||||||
*/
|
*/
|
||||||
public canDropToNode(params: { dragNodeType?: FlowNodeType; dropNode?: WorkflowNodeEntity }): {
|
|
||||||
|
public canDropToNode(params: {
|
||||||
|
dragNodeType?: FlowNodeType;
|
||||||
|
dragNode?: WorkflowNodeEntity;
|
||||||
|
dropNode?: WorkflowNodeEntity;
|
||||||
|
dropNodeType?: FlowNodeType;
|
||||||
|
}): {
|
||||||
allowDrop: boolean;
|
allowDrop: boolean;
|
||||||
message?: string;
|
message?: string;
|
||||||
dropNode?: WorkflowNodeEntity;
|
dropNode?: WorkflowNodeEntity;
|
||||||
} {
|
} {
|
||||||
|
const { canDropToNode } = this.document.options;
|
||||||
const { dragNodeType, dropNode } = params;
|
const { dragNodeType, dropNode } = params;
|
||||||
|
if (canDropToNode) {
|
||||||
|
const result = canDropToNode(params);
|
||||||
|
if (result) {
|
||||||
|
return {
|
||||||
|
allowDrop: true,
|
||||||
|
dropNode,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
allowDrop: false,
|
||||||
|
};
|
||||||
|
}
|
||||||
if (!dragNodeType) {
|
if (!dragNodeType) {
|
||||||
return {
|
return {
|
||||||
allowDrop: false,
|
allowDrop: false,
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { FlowNodeErrorData } from '@flowgram.ai/form-core';
|
import { FlowNodeErrorData } from '@flowgram.ai/form-core';
|
||||||
import { FlowDocumentOptions, FlowNodeTransformData } from '@flowgram.ai/document';
|
import { FlowDocumentOptions, FlowNodeTransformData, FlowNodeType } from '@flowgram.ai/document';
|
||||||
import { TransformData } from '@flowgram.ai/core';
|
import { TransformData } from '@flowgram.ai/core';
|
||||||
|
|
||||||
import { type WorkflowLinesManager } from './workflow-lines-manager';
|
import { type WorkflowLinesManager } from './workflow-lines-manager';
|
||||||
@ -83,6 +83,17 @@ export interface WorkflowDocumentOptions extends FlowDocumentOptions {
|
|||||||
newToPort: WorkflowPortEntity,
|
newToPort: WorkflowPortEntity,
|
||||||
lines: WorkflowLinesManager
|
lines: WorkflowLinesManager
|
||||||
) => boolean;
|
) => boolean;
|
||||||
|
/**
|
||||||
|
* 是否允许拖入子画布 (loop or group)
|
||||||
|
* Whether to allow dragging into the sub-canvas (loop or group)
|
||||||
|
* @param params
|
||||||
|
*/
|
||||||
|
canDropToNode?: (params: {
|
||||||
|
dragNodeType?: FlowNodeType;
|
||||||
|
dragNode?: WorkflowNodeEntity;
|
||||||
|
dropNode?: WorkflowNodeEntity;
|
||||||
|
dropNodeType?: FlowNodeType;
|
||||||
|
}) => boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const WorkflowDocumentOptionsDefault: WorkflowDocumentOptions = {
|
export const WorkflowDocumentOptionsDefault: WorkflowDocumentOptions = {
|
||||||
|
|||||||
@ -160,6 +160,7 @@ export function createFreeLayoutPreset(
|
|||||||
setLineClassName: opts.setLineClassName?.bind(null, ctx),
|
setLineClassName: opts.setLineClassName?.bind(null, ctx),
|
||||||
canDeleteNode: opts.canDeleteNode?.bind(null, ctx),
|
canDeleteNode: opts.canDeleteNode?.bind(null, ctx),
|
||||||
canResetLine: opts.canResetLine?.bind(null, ctx),
|
canResetLine: opts.canResetLine?.bind(null, ctx),
|
||||||
|
canDropToNode: opts.canDropToNode?.bind(null, ctx),
|
||||||
cursors: opts.cursors ?? WorkflowDocumentOptionsDefault.cursors,
|
cursors: opts.cursors ?? WorkflowDocumentOptionsDefault.cursors,
|
||||||
lineColor: opts.lineColor ?? WorkflowDocumentOptionsDefault.lineColor,
|
lineColor: opts.lineColor ?? WorkflowDocumentOptionsDefault.lineColor,
|
||||||
allNodesDefaultExpanded: opts.allNodesDefaultExpanded,
|
allNodesDefaultExpanded: opts.allNodesDefaultExpanded,
|
||||||
|
|||||||
@ -20,6 +20,7 @@ import {
|
|||||||
EditorProps,
|
EditorProps,
|
||||||
SelectionService,
|
SelectionService,
|
||||||
PluginContext,
|
PluginContext,
|
||||||
|
FlowNodeType,
|
||||||
} from '@flowgram.ai/editor';
|
} from '@flowgram.ai/editor';
|
||||||
|
|
||||||
export const FreeLayoutPluginContext = PluginContext;
|
export const FreeLayoutPluginContext = PluginContext;
|
||||||
@ -190,6 +191,20 @@ export interface FreeLayoutProps extends EditorProps<FreeLayoutPluginContext, Wo
|
|||||||
newToPort: WorkflowPortEntity,
|
newToPort: WorkflowPortEntity,
|
||||||
lines: WorkflowLinesManager
|
lines: WorkflowLinesManager
|
||||||
) => boolean;
|
) => boolean;
|
||||||
|
/**
|
||||||
|
* 是否允许拖入子画布 (loop or group)
|
||||||
|
* Whether to allow dragging into the sub-canvas (loop or group)
|
||||||
|
* @param params
|
||||||
|
*/
|
||||||
|
canDropToNode?: (
|
||||||
|
ctx: FreeLayoutPluginContext,
|
||||||
|
params: {
|
||||||
|
dragNodeType?: FlowNodeType;
|
||||||
|
dragNode?: WorkflowNodeEntity;
|
||||||
|
dropNode?: WorkflowNodeEntity;
|
||||||
|
dropNodeType?: FlowNodeType;
|
||||||
|
}
|
||||||
|
) => boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export namespace FreeLayoutProps {
|
export namespace FreeLayoutProps {
|
||||||
|
|||||||
@ -111,6 +111,8 @@ export class NodeIntoContainerService {
|
|||||||
}
|
}
|
||||||
const canDrop = this.dragService.canDropToNode({
|
const canDrop = this.dragService.canDropToNode({
|
||||||
dragNodeType: node.flowNodeType,
|
dragNodeType: node.flowNodeType,
|
||||||
|
dragNode: node,
|
||||||
|
dropNodeType: containerNode?.flowNodeType,
|
||||||
dropNode: containerNode,
|
dropNode: containerNode,
|
||||||
});
|
});
|
||||||
if (!canDrop.allowDrop) {
|
if (!canDrop.allowDrop) {
|
||||||
@ -358,6 +360,8 @@ export class NodeIntoContainerService {
|
|||||||
}
|
}
|
||||||
const canDrop = this.dragService.canDropToNode({
|
const canDrop = this.dragService.canDropToNode({
|
||||||
dragNodeType: dragNode.flowNodeType,
|
dragNodeType: dragNode.flowNodeType,
|
||||||
|
dropNodeType: dropNode?.flowNodeType,
|
||||||
|
dragNode,
|
||||||
dropNode,
|
dropNode,
|
||||||
});
|
});
|
||||||
if (!canDrop.allowDrop) {
|
if (!canDrop.allowDrop) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user