toggle-loop-expanded.ts 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /**
  2. * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
  3. * SPDX-License-Identifier: MIT
  4. */
  5. import { WorkflowNodeEntity, WorkflowNodeLinesData } from '@flowgram.ai/free-layout-editor';
  6. export function toggleLoopExpanded(
  7. node: WorkflowNodeEntity,
  8. expanded: boolean = node.transform.collapsed,
  9. heightCollapsed = 54
  10. ) {
  11. const bounds = node.bounds.clone();
  12. const prePosition = {
  13. x: node.transform.position.x,
  14. y: node.transform.position.y,
  15. };
  16. node.transform.collapsed = !expanded;
  17. if (!expanded) {
  18. node.transform.transform.update({
  19. position: {
  20. x: prePosition.x - node.transform.padding.left,
  21. y: prePosition.y - node.transform.padding.top,
  22. },
  23. origin: {
  24. x: 0,
  25. y: 0,
  26. },
  27. });
  28. setTimeout(() => {
  29. // When folded, the width and height no longer change according to the child nodes, and need to be set manually
  30. // 折叠起来,宽高不再根据子节点变化,需要手动设置
  31. node.transform.size = {
  32. width: bounds.width,
  33. height: heightCollapsed,
  34. };
  35. }, 0);
  36. } else {
  37. node.transform.transform.update({
  38. position: {
  39. x: prePosition.x + node.transform.padding.left,
  40. y: prePosition.y + node.transform.padding.top,
  41. },
  42. origin: {
  43. x: 0,
  44. y: 0,
  45. },
  46. });
  47. }
  48. // 隐藏子节点线条
  49. // Hide the child node lines
  50. node.blocks.forEach((block) => {
  51. block.getData(WorkflowNodeLinesData).allLines.forEach((line) => {
  52. line.updateUIState({
  53. style: !expanded ? { display: 'none' } : {},
  54. });
  55. });
  56. });
  57. }