create-fixed-drag-plugin.ts 999 B

1234567891011121314151617181920212223242526
  1. import { FlowDragLayer } from '@flowgram.ai/renderer';
  2. import { FlowNodeEntity } from '@flowgram.ai/document';
  3. import { definePluginCreator, PluginContext } from '@flowgram.ai/core';
  4. // import { SelectorBounds } from './selector-bounds';
  5. export interface FixDragPluginOptions<CTX extends PluginContext = PluginContext> {
  6. enable?: boolean;
  7. onDrop?: (ctx: CTX, dropData: { dragNodes: FlowNodeEntity[]; dropNode: FlowNodeEntity }) => void;
  8. canDrop?: (
  9. ctx: CTX,
  10. dropData: { dragNodes: FlowNodeEntity[]; dropNode: FlowNodeEntity; isBranch?: boolean },
  11. ) => boolean;
  12. }
  13. export const createFixedDragPlugin = definePluginCreator<FixDragPluginOptions<any>>({
  14. onInit(ctx, opts): void {
  15. // 默认可用,所以强制判断 false
  16. if (opts.enable !== false) {
  17. ctx.playground.registerLayer(FlowDragLayer, {
  18. onDrop: opts.onDrop ? opts.onDrop.bind(null, ctx) : undefined,
  19. canDrop: opts.canDrop ? opts.canDrop.bind(null, ctx) : undefined,
  20. });
  21. }
  22. },
  23. });