@flowgram.ai/free-layout-core 0.4.2 → 0.4.4

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) {
@@ -611,6 +621,9 @@ var _WorkflowNodeLinesData = class _WorkflowNodeLinesData extends EntityData2 {
611
621
  get allLines() {
612
622
  return this.data.inputLines.concat(this.data.outputLines);
613
623
  }
624
+ get availableLines() {
625
+ return this.allLines.filter((line) => !line.isDrawing && !line.isHidden);
626
+ }
614
627
  /**
615
628
  * 输入节点
616
629
  */
@@ -752,6 +765,12 @@ var WorkflowLineRenderData = class extends EntityData3 {
752
765
  get lineType() {
753
766
  return this.entity.renderType ?? this.entity.linesManager.lineType;
754
767
  }
768
+ /**
769
+ * 获取 center 位置
770
+ */
771
+ get center() {
772
+ return this.currentLine?.center || { x: 0, y: 0, labelX: 0, labelY: 0 };
773
+ }
755
774
  /**
756
775
  * 更新版本
757
776
  * WARNING: 这个方法,必须在 requestAnimationFrame / useLayoutEffect 中调用,否则会引起浏览器强制重排
@@ -1013,6 +1032,9 @@ var _WorkflowLineEntity = class _WorkflowLineEntity extends Entity2 {
1013
1032
  get bounds() {
1014
1033
  return this.getData(WorkflowLineRenderData).bounds;
1015
1034
  }
1035
+ get center() {
1036
+ return this.getData(WorkflowLineRenderData).center;
1037
+ }
1016
1038
  /**
1017
1039
  * 获取点和线最接近的距离
1018
1040
  */
@@ -2425,9 +2447,18 @@ var WorkflowDocument = class extends FlowDocument {
2425
2447
  this._onReloadEmitter.dispose();
2426
2448
  }
2427
2449
  /**
2428
- * 逐层创建节点和线条
2450
+ * 批量添加节点
2451
+ * @deprecated use 'batchAddFromJSON' instead
2452
+ * @param json
2453
+ * @param options
2429
2454
  */
2430
2455
  renderJSON(json, options) {
2456
+ return this.batchAddFromJSON(json, options);
2457
+ }
2458
+ /**
2459
+ * 批量添加节点
2460
+ */
2461
+ batchAddFromJSON(json, options) {
2431
2462
  const { parent = this.root, isClone = false } = options ?? {};
2432
2463
  const containerID = this.getNodeSubCanvas(parent)?.canvasNode.id ?? parent.id;
2433
2464
  const processedJSON = buildGroupJSON(json);
@@ -3589,81 +3620,6 @@ var WorkflowDocumentContainerModule = new ContainerModule(
3589
3620
  bind(WorkflowDocumentProvider).toDynamicValue((ctx) => () => ctx.container.get(WorkflowDocument)).inSingletonScope();
3590
3621
  }
3591
3622
  );
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
3623
  export {
3668
3624
  EditorCursorState,
3669
3625
  InteractiveType,
@@ -3694,7 +3650,6 @@ export {
3694
3650
  WorkflowPortEntity,
3695
3651
  WorkflowResetLayoutService,
3696
3652
  WorkflowSelectService,
3697
- WorkflowSimpleLineContribution,
3698
3653
  bindConfigEntity,
3699
3654
  buildGroupJSON,
3700
3655
  compose,
@@ -3703,6 +3658,7 @@ export {
3703
3658
  domReactToBounds,
3704
3659
  fitView,
3705
3660
  getAntiOverlapPosition,
3661
+ getLineCenter,
3706
3662
  getPortEntityId,
3707
3663
  nanoid,
3708
3664
  useConfigEntity,