@flowgram.ai/free-layout-core 0.1.0-alpha.13 → 0.1.0-alpha.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,6 +2,7 @@
2
2
  var LineType = /* @__PURE__ */ ((LineType2) => {
3
3
  LineType2[LineType2["BEZIER"] = 0] = "BEZIER";
4
4
  LineType2[LineType2["LINE_CHART"] = 1] = "LINE_CHART";
5
+ LineType2[LineType2["STRAIGHT"] = 2] = "STRAIGHT";
5
6
  return LineType2;
6
7
  })(LineType || {});
7
8
  var LineColors = /* @__PURE__ */ ((LineColors2) => {
@@ -19,4 +20,4 @@ export {
19
20
  LineType,
20
21
  LineColors
21
22
  };
22
- //# sourceMappingURL=chunk-E7ZUQ7LV.js.map
23
+ //# sourceMappingURL=chunk-5BT3ZR4D.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/typings/workflow-line.ts"],"sourcesContent":["/**\n * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates\n * SPDX-License-Identifier: MIT\n */\n\nimport type { Rectangle, IPoint } from '@flowgram.ai/utils';\n\nimport { type WorkflowLineEntity } from '../entities';\n\nexport enum LineType {\n BEZIER, // 贝塞尔曲线\n LINE_CHART, // 折叠线\n STRAIGHT, // 直线\n}\n\nexport type LineRenderType = LineType | string;\n\nexport type LinePointLocation = 'left' | 'top' | 'right' | 'bottom';\n\nexport interface LinePoint {\n x: number;\n y: number;\n location: LinePointLocation;\n}\n\nexport interface LinePosition {\n from: LinePoint;\n to: LinePoint;\n}\n\nexport interface LineColor {\n hidden: string;\n default: string;\n drawing: string;\n hovered: string;\n selected: string;\n error: string;\n flowing: string;\n}\n\nexport enum LineColors {\n HIDDEN = 'var(--g-workflow-line-color-hidden,transparent)', // 隐藏线条\n DEFUALT = 'var(--g-workflow-line-color-default,#4d53e8)',\n DRAWING = 'var(--g-workflow-line-color-drawing, #5DD6E3)', // '#b5bbf8', // '#9197F1',\n HOVER = 'var(--g-workflow-line-color-hover,#37d0ff)',\n SELECTED = 'var(--g-workflow-line-color-selected,#37d0ff)',\n ERROR = 'var(--g-workflow-line-color-error,red)',\n FLOWING = 'var(--g-workflow-line-color-flowing,#4d53e8)', // 流动线条,默认使用主题色\n}\n\nexport interface LineCenterPoint {\n x: number;\n y: number;\n labelX: number; // Relative to where the line begins\n labelY: number; // Relative to where the line begins\n}\n\nexport interface WorkflowLineRenderContribution {\n entity: WorkflowLineEntity;\n path: string;\n center?: LineCenterPoint;\n bounds: Rectangle;\n update: (params: { fromPos: LinePoint; toPos: LinePoint }) => void;\n calcDistance: (pos: IPoint) => number;\n}\n\nexport type WorkflowLineRenderContributionFactory = (new (\n entity: WorkflowLineEntity\n) => WorkflowLineRenderContribution) & {\n type: LineRenderType;\n};\n"],"mappings":";AASO,IAAK,WAAL,kBAAKA,cAAL;AACL,EAAAA,oBAAA;AACA,EAAAA,oBAAA;AACA,EAAAA,oBAAA;AAHU,SAAAA;AAAA,GAAA;AA+BL,IAAK,aAAL,kBAAKC,gBAAL;AACL,EAAAA,YAAA,YAAS;AACT,EAAAA,YAAA,aAAU;AACV,EAAAA,YAAA,aAAU;AACV,EAAAA,YAAA,WAAQ;AACR,EAAAA,YAAA,cAAW;AACX,EAAAA,YAAA,WAAQ;AACR,EAAAA,YAAA,aAAU;AAPA,SAAAA;AAAA,GAAA;","names":["LineType","LineColors"]}
package/dist/esm/index.js CHANGED
@@ -11,7 +11,7 @@ import {
11
11
  import {
12
12
  LineColors,
13
13
  LineType
14
- } from "./chunk-E7ZUQ7LV.js";
14
+ } from "./chunk-5BT3ZR4D.js";
15
15
  import "./chunk-DDJTYHXN.js";
16
16
  import {
17
17
  WorkflowOperationBaseService
@@ -100,6 +100,16 @@ var buildGroupJSON = (json) => {
100
100
  };
101
101
  };
102
102
 
103
+ // src/utils/get-line-center.ts
104
+ function getLineCenter(from, to, bbox, linePadding) {
105
+ return {
106
+ x: bbox.center.x,
107
+ y: bbox.center.y,
108
+ labelX: bbox.center.x - bbox.x + linePadding,
109
+ labelY: bbox.center.y - bbox.y + linePadding
110
+ };
111
+ }
112
+
103
113
  // src/utils/nanoid.ts
104
114
  import { nanoid as nanoidOrigin } from "nanoid";
105
115
  function nanoid(n) {
@@ -445,6 +455,7 @@ var WorkflowNodePortsData = class extends EntityData {
445
455
  ...Array.from(elements).map((element) => ({
446
456
  portID: element.getAttribute("data-port-id"),
447
457
  type: element.getAttribute("data-port-type"),
458
+ location: element.getAttribute("data-port-location"),
448
459
  targetElement: element
449
460
  }))
450
461
  );
@@ -611,6 +622,9 @@ var _WorkflowNodeLinesData = class _WorkflowNodeLinesData extends EntityData2 {
611
622
  get allLines() {
612
623
  return this.data.inputLines.concat(this.data.outputLines);
613
624
  }
625
+ get availableLines() {
626
+ return this.allLines.filter((line) => !line.isDrawing && !line.isHidden);
627
+ }
614
628
  /**
615
629
  * 输入节点
616
630
  */
@@ -752,6 +766,12 @@ var WorkflowLineRenderData = class extends EntityData3 {
752
766
  get lineType() {
753
767
  return this.entity.renderType ?? this.entity.linesManager.lineType;
754
768
  }
769
+ /**
770
+ * 获取 center 位置
771
+ */
772
+ get center() {
773
+ return this.currentLine?.center || { x: 0, y: 0, labelX: 0, labelY: 0 };
774
+ }
755
775
  /**
756
776
  * 更新版本
757
777
  * WARNING: 这个方法,必须在 requestAnimationFrame / useLayoutEffect 中调用,否则会引起浏览器强制重排
@@ -1013,6 +1033,9 @@ var _WorkflowLineEntity = class _WorkflowLineEntity extends Entity2 {
1013
1033
  get bounds() {
1014
1034
  return this.getData(WorkflowLineRenderData).bounds;
1015
1035
  }
1036
+ get center() {
1037
+ return this.getData(WorkflowLineRenderData).center;
1038
+ }
1016
1039
  /**
1017
1040
  * 获取点和线最接近的距离
1018
1041
  */
@@ -1056,7 +1079,9 @@ var _WorkflowLineEntity = class _WorkflowLineEntity extends Entity2 {
1056
1079
  get disabled() {
1057
1080
  return this.linesManager.isDisabledLine(this, this.uiState.disabled);
1058
1081
  }
1059
- /** 是否竖向 */
1082
+ /**
1083
+ * @deprecated
1084
+ */
1060
1085
  get vertical() {
1061
1086
  const fromLocation = this.fromPort.location;
1062
1087
  const toLocation = this.toPort?.location;
@@ -2425,9 +2450,18 @@ var WorkflowDocument = class extends FlowDocument {
2425
2450
  this._onReloadEmitter.dispose();
2426
2451
  }
2427
2452
  /**
2428
- * 逐层创建节点和线条
2453
+ * 批量添加节点
2454
+ * @deprecated use 'batchAddFromJSON' instead
2455
+ * @param json
2456
+ * @param options
2429
2457
  */
2430
2458
  renderJSON(json, options) {
2459
+ return this.batchAddFromJSON(json, options);
2460
+ }
2461
+ /**
2462
+ * 批量添加节点
2463
+ */
2464
+ batchAddFromJSON(json, options) {
2431
2465
  const { parent = this.root, isClone = false } = options ?? {};
2432
2466
  const containerID = this.getNodeSubCanvas(parent)?.canvasNode.id ?? parent.id;
2433
2467
  const processedJSON = buildGroupJSON(json);
@@ -2557,6 +2591,18 @@ function checkDragSuccess(time, e, originLine) {
2557
2591
  }
2558
2592
  return false;
2559
2593
  }
2594
+ function reverseLocation(sourceLocation) {
2595
+ switch (sourceLocation) {
2596
+ case "bottom":
2597
+ return "top";
2598
+ case "left":
2599
+ return "right";
2600
+ case "top":
2601
+ return "bottom";
2602
+ case "right":
2603
+ return "left";
2604
+ }
2605
+ }
2560
2606
  var WorkflowDragService = class {
2561
2607
  constructor() {
2562
2608
  this._onDragLineEventEmitter = new Emitter6();
@@ -3014,7 +3060,7 @@ var WorkflowDragService = class {
3014
3060
  line.drawingTo = {
3015
3061
  x: dragPos.x,
3016
3062
  y: dragPos.y,
3017
- location: line.fromPort.location === "right" ? "left" : "top"
3063
+ location: reverseLocation(line.fromPort.location)
3018
3064
  };
3019
3065
  }
3020
3066
  originLine?.validate();
@@ -3589,81 +3635,6 @@ var WorkflowDocumentContainerModule = new ContainerModule(
3589
3635
  bind(WorkflowDocumentProvider).toDynamicValue((ctx) => () => ctx.container.get(WorkflowDocument)).inSingletonScope();
3590
3636
  }
3591
3637
  );
3592
-
3593
- // src/utils/simple-line.ts
3594
- import { Point, Rectangle as Rectangle9 } from "@flowgram.ai/utils";
3595
- var LINE_PADDING = 12;
3596
- var WorkflowSimpleLineContribution = class {
3597
- constructor(entity) {
3598
- this.entity = entity;
3599
- }
3600
- get path() {
3601
- return this.data?.path ?? "";
3602
- }
3603
- calcDistance(pos) {
3604
- if (!this.data) {
3605
- return Number.MAX_SAFE_INTEGER;
3606
- }
3607
- const [start, end] = this.data.points;
3608
- return Point.getDistance(pos, this.projectPointOnLine(pos, start, end));
3609
- }
3610
- get bounds() {
3611
- if (!this.data) {
3612
- return new Rectangle9();
3613
- }
3614
- return this.data.bbox;
3615
- }
3616
- update(params) {
3617
- const { fromPos, toPos } = params;
3618
- const { vertical } = this.entity;
3619
- const sourceOffset = {
3620
- x: vertical ? 0 : POINT_RADIUS,
3621
- y: vertical ? POINT_RADIUS : 0
3622
- };
3623
- const targetOffset = {
3624
- x: vertical ? 0 : -POINT_RADIUS,
3625
- y: vertical ? -POINT_RADIUS : 0
3626
- };
3627
- const points = [
3628
- {
3629
- x: fromPos.x + sourceOffset.x,
3630
- y: fromPos.y + sourceOffset.y
3631
- },
3632
- {
3633
- x: toPos.x + targetOffset.x,
3634
- y: toPos.y + targetOffset.y
3635
- }
3636
- ];
3637
- const bbox = Rectangle9.createRectangleWithTwoPoints(points[0], points[1]);
3638
- const adjustedPoints = points.map((p) => ({
3639
- x: p.x - bbox.x + LINE_PADDING,
3640
- y: p.y - bbox.y + LINE_PADDING
3641
- }));
3642
- const path = `M ${adjustedPoints[0].x} ${adjustedPoints[0].y} L ${adjustedPoints[1].x} ${adjustedPoints[1].y}`;
3643
- this.data = {
3644
- points,
3645
- path,
3646
- bbox
3647
- };
3648
- }
3649
- projectPointOnLine(point, lineStart, lineEnd) {
3650
- const dx = lineEnd.x - lineStart.x;
3651
- const dy = lineEnd.y - lineStart.y;
3652
- if (dx === 0) {
3653
- return { x: lineStart.x, y: point.y };
3654
- }
3655
- if (dy === 0) {
3656
- return { x: point.x, y: lineStart.y };
3657
- }
3658
- const t = ((point.x - lineStart.x) * dx + (point.y - lineStart.y) * dy) / (dx * dx + dy * dy);
3659
- const clampedT = Math.max(0, Math.min(1, t));
3660
- return {
3661
- x: lineStart.x + clampedT * dx,
3662
- y: lineStart.y + clampedT * dy
3663
- };
3664
- }
3665
- };
3666
- WorkflowSimpleLineContribution.type = "WorkflowSimpleLineContribution";
3667
3638
  export {
3668
3639
  EditorCursorState,
3669
3640
  InteractiveType,
@@ -3694,7 +3665,6 @@ export {
3694
3665
  WorkflowPortEntity,
3695
3666
  WorkflowResetLayoutService,
3696
3667
  WorkflowSelectService,
3697
- WorkflowSimpleLineContribution,
3698
3668
  bindConfigEntity,
3699
3669
  buildGroupJSON,
3700
3670
  compose,
@@ -3703,6 +3673,7 @@ export {
3703
3673
  domReactToBounds,
3704
3674
  fitView,
3705
3675
  getAntiOverlapPosition,
3676
+ getLineCenter,
3706
3677
  getPortEntityId,
3707
3678
  nanoid,
3708
3679
  useConfigEntity,