create-batch-function.ts 1.0 KB

12345678910111213141516171819202122232425262728293031
  1. /**
  2. * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
  3. * SPDX-License-Identifier: MIT
  4. */
  5. import { WorkflowNodeEntity, WorkflowDocument, IPoint } from '@flowgram.ai/free-layout-editor';
  6. import { BatchFunctionIDPrefix } from './relation';
  7. import { createBatchFunctionLines } from './create-batch-function-lines';
  8. import { createBatchFunctionJSON } from './create-batch-function-json';
  9. /** 创建 Batch 循环体节点 */
  10. export const createBatchFunction = (batchNode: WorkflowNodeEntity, batchPosition: IPoint) => {
  11. const document = batchNode.document as WorkflowDocument;
  12. const id = `${BatchFunctionIDPrefix}${batchNode.id}`;
  13. const offset: IPoint = {
  14. x: -112,
  15. y: 230,
  16. };
  17. const position = {
  18. x: batchPosition.x + offset.x,
  19. y: batchPosition.y + offset.y,
  20. };
  21. const batchFunctionJSON = createBatchFunctionJSON(id, position);
  22. const batchFunctionNode = document.createWorkflowNode(batchFunctionJSON);
  23. createBatchFunctionLines({
  24. document,
  25. batchId: batchNode.id,
  26. batchFunctionId: batchFunctionNode.id,
  27. });
  28. };