selection-utils.ts 716 B

1234567891011121314151617181920
  1. import { Rectangle } from '@flowgram.ai/utils';
  2. import { WorkflowNodeEntity } from '@flowgram.ai/free-layout-core';
  3. import { FlowNodeTransformData } from '@flowgram.ai/document';
  4. import { type Entity } from '@flowgram.ai/core';
  5. const BOUNDS_PADDING = 2;
  6. export function getSelectionBounds(
  7. selection: Entity[],
  8. ignoreOneSelect: boolean = true // 忽略单选
  9. ): Rectangle {
  10. const selectedNodes = selection.filter((node) => node instanceof WorkflowNodeEntity);
  11. // 选中单个的时候不显示
  12. return selectedNodes.length > (ignoreOneSelect ? 1 : 0)
  13. ? Rectangle.enlarge(selectedNodes.map((n) => n.getData(FlowNodeTransformData)!.bounds)).pad(
  14. BOUNDS_PADDING
  15. )
  16. : Rectangle.EMPTY;
  17. }