@flowgram.ai/free-lines-plugin 0.4.8 → 0.4.10

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.
package/dist/index.js CHANGED
@@ -299,17 +299,17 @@ var LINE_OFFSET = 6;
299
299
  var LINE_PADDING = 12;
300
300
 
301
301
  // src/create-free-lines-plugin.ts
302
- var import_free_layout_core8 = require("@flowgram.ai/free-layout-core");
302
+ var import_free_layout_core7 = require("@flowgram.ai/free-layout-core");
303
303
  var import_core3 = require("@flowgram.ai/core");
304
304
 
305
305
  // src/layer/workflow-lines-layer.tsx
306
306
  var import_react_dom2 = __toESM(require("react-dom"));
307
307
  var import_react6 = __toESM(require("react"));
308
308
  var import_inversify = require("inversify");
309
- var import_utils = require("@flowgram.ai/utils");
309
+ var import_utils2 = require("@flowgram.ai/utils");
310
310
  var import_renderer = require("@flowgram.ai/renderer");
311
311
  var import_free_stack_plugin = require("@flowgram.ai/free-stack-plugin");
312
- var import_free_layout_core4 = require("@flowgram.ai/free-layout-core");
312
+ var import_free_layout_core3 = require("@flowgram.ai/free-layout-core");
313
313
  var import_core2 = require("@flowgram.ai/core");
314
314
 
315
315
  // src/components/workflow-line-render/index.tsx
@@ -319,7 +319,33 @@ var import_react5 = require("react");
319
319
  var import_react4 = __toESM(require("react"));
320
320
  var import_clsx2 = __toESM(require("clsx"));
321
321
  var import_free_layout_core2 = require("@flowgram.ai/free-layout-core");
322
- var import_free_layout_core3 = require("@flowgram.ai/free-layout-core");
322
+
323
+ // src/contributions/utils.ts
324
+ function toRelative(p, bbox) {
325
+ return {
326
+ x: p.x - bbox.x + LINE_PADDING,
327
+ y: p.y - bbox.y + LINE_PADDING
328
+ };
329
+ }
330
+ function getShrinkOffset(location, shrink) {
331
+ switch (location) {
332
+ case "left":
333
+ return { x: -shrink, y: 0 };
334
+ case "right":
335
+ return { x: shrink, y: 0 };
336
+ case "bottom":
337
+ return { x: 0, y: shrink };
338
+ case "top":
339
+ return { x: 0, y: -shrink };
340
+ }
341
+ }
342
+ function posWithShrink(pos, location, shrink) {
343
+ const offset = getShrinkOffset(location, shrink);
344
+ return {
345
+ x: pos.x + offset.x,
346
+ y: pos.y + offset.y
347
+ };
348
+ }
323
349
 
324
350
  // src/components/workflow-line-render/index.style.ts
325
351
  var import_styled_components2 = __toESM(require("styled-components"));
@@ -343,18 +369,23 @@ var LineStyle = import_styled_components2.default.div`
343
369
 
344
370
  // src/components/workflow-line-render/arrow.tsx
345
371
  var import_react3 = __toESM(require("react"));
346
- function ArrowRenderer({
347
- id,
348
- pos,
349
- reverseArrow,
350
- strokeWidth,
351
- vertical,
352
- hide
353
- }) {
372
+ function getArrowPath(pos, location) {
373
+ switch (location) {
374
+ case "left":
375
+ return `M ${pos.x - LINE_OFFSET},${pos.y - LINE_OFFSET} L ${pos.x},${pos.y} L ${pos.x - LINE_OFFSET},${pos.y + LINE_OFFSET}`;
376
+ case "right":
377
+ return `M ${pos.x + LINE_OFFSET},${pos.y + LINE_OFFSET} L ${pos.x},${pos.y} L ${pos.x + LINE_OFFSET},${pos.y - LINE_OFFSET}`;
378
+ case "bottom":
379
+ return `M ${pos.x - LINE_OFFSET},${pos.y + LINE_OFFSET} L ${pos.x},${pos.y} L ${pos.x + LINE_OFFSET},${pos.y + LINE_OFFSET}`;
380
+ case "top":
381
+ return `M ${pos.x - LINE_OFFSET},${pos.y - LINE_OFFSET} L ${pos.x},${pos.y} L ${pos.x + LINE_OFFSET},${pos.y - LINE_OFFSET}`;
382
+ }
383
+ }
384
+ function ArrowRenderer({ id, pos, strokeWidth, location, hide }) {
354
385
  if (hide) {
355
386
  return null;
356
387
  }
357
- const arrowPath = vertical ? reverseArrow ? `M ${pos.x - LINE_OFFSET},${pos.y} L ${pos.x},${pos.y - LINE_OFFSET} L ${pos.x + LINE_OFFSET},${pos.y}` : `M ${pos.x - LINE_OFFSET},${pos.y - LINE_OFFSET} L ${pos.x},${pos.y} L ${pos.x + LINE_OFFSET},${pos.y - LINE_OFFSET}` : reverseArrow ? `M ${pos.x},${pos.y + LINE_OFFSET} L ${pos.x - LINE_OFFSET},${pos.y} L ${pos.x},${pos.y - LINE_OFFSET}` : `M ${pos.x - LINE_OFFSET},${pos.y - LINE_OFFSET} L ${pos.x},${pos.y} L ${pos.x - LINE_OFFSET},${pos.y + LINE_OFFSET}`;
388
+ const arrowPath = getArrowPath(pos, location);
358
389
  return /* @__PURE__ */ import_react3.default.createElement(
359
390
  "path",
360
391
  {
@@ -372,7 +403,7 @@ var PADDING = 12;
372
403
  var LineSVG = (props) => {
373
404
  const { line, color, selected, children, strokePrefix, rendererRegistry } = props;
374
405
  const { position, reverse, hideArrow, vertical } = line;
375
- const renderData = line.getData(import_free_layout_core3.WorkflowLineRenderData);
406
+ const renderData = line.getData(import_free_layout_core2.WorkflowLineRenderData);
376
407
  const { bounds, path: bezierPath } = renderData;
377
408
  const toRelative2 = (p) => ({
378
409
  x: p.x - bounds.x + PADDING,
@@ -380,8 +411,8 @@ var LineSVG = (props) => {
380
411
  });
381
412
  const fromPos = toRelative2(position.from);
382
413
  const toPos = toRelative2(position.to);
383
- const arrowToPos = position.to.location === "top" ? { x: toPos.x, y: toPos.y - import_free_layout_core2.POINT_RADIUS } : { x: toPos.x - import_free_layout_core2.POINT_RADIUS, y: toPos.y };
384
- const arrowFromPos = position.from.location === "bottom" ? { x: fromPos.x, y: fromPos.y + import_free_layout_core2.POINT_RADIUS + LINE_OFFSET } : { x: fromPos.x + import_free_layout_core2.POINT_RADIUS + LINE_OFFSET, y: fromPos.y };
414
+ const arrowToPos = posWithShrink(toPos, position.to.location, line.uiState.shrink);
415
+ const arrowFromPos = posWithShrink(fromPos, position.from.location, line.uiState.shrink);
385
416
  const strokeWidth = selected ? line.uiState.strokeWidthSelected ?? STROKE_WIDTH_SLECTED : line.uiState.strokeWidth ?? STROKE_WIDTH;
386
417
  const strokeID = strokePrefix ? `${strokePrefix}-${line.id}` : line.id;
387
418
  const CustomArrowRenderer = rendererRegistry?.tryToGetRendererComponent("arrow-renderer")?.renderer;
@@ -424,10 +455,9 @@ var LineSVG = (props) => {
424
455
  ArrowComponent,
425
456
  {
426
457
  id: strokeID,
427
- reverseArrow: reverse,
428
458
  pos: reverse ? arrowFromPos : arrowToPos,
429
459
  strokeWidth,
430
- vertical,
460
+ location: reverse ? position.from.location : position.to.location,
431
461
  hide: hideArrow,
432
462
  line
433
463
  }
@@ -445,13 +475,13 @@ var WorkflowLineRender = (0, import_react5.memo)(
445
475
  var WorkflowLinesLayer = class extends import_core2.Layer {
446
476
  constructor() {
447
477
  super(...arguments);
448
- this.layerID = (0, import_free_layout_core4.nanoid)();
478
+ this.layerID = (0, import_free_layout_core3.nanoid)();
449
479
  this.mountedLines = /* @__PURE__ */ new Map();
450
480
  this._version = 0;
451
481
  /**
452
482
  * 节点线条
453
483
  */
454
- this.node = import_utils.domUtils.createDivWithClass("gedit-playground-layer gedit-flow-lines-layer");
484
+ this.node = import_utils2.domUtils.createDivWithClass("gedit-playground-layer gedit-flow-lines-layer");
455
485
  }
456
486
  onZoom(scale) {
457
487
  this.node.style.transform = `scale(${scale})`;
@@ -477,7 +507,7 @@ var WorkflowLinesLayer = class extends import_core2.Layer {
477
507
  const updateLines = () => {
478
508
  let needsUpdate = false;
479
509
  this.lines.forEach((line) => {
480
- const renderData = line.getData(import_free_layout_core4.WorkflowLineRenderData);
510
+ const renderData = line.getData(import_free_layout_core3.WorkflowLineRenderData);
481
511
  const oldVersion = renderData.renderVersion;
482
512
  renderData.update();
483
513
  if (renderData.renderVersion !== oldVersion) {
@@ -519,7 +549,7 @@ var WorkflowLinesLayer = class extends import_core2.Layer {
519
549
  };
520
550
  }
521
551
  lineVersion(line) {
522
- const renderData = line.getData(import_free_layout_core4.WorkflowLineRenderData);
552
+ const renderData = line.getData(import_free_layout_core3.WorkflowLineRenderData);
523
553
  const { renderVersion } = renderData;
524
554
  const selected = this.selectService.isSelected(line.id);
525
555
  const hovered = this.hoverService.isHovered(line.id);
@@ -556,10 +586,10 @@ var WorkflowLinesLayer = class extends import_core2.Layer {
556
586
  };
557
587
  WorkflowLinesLayer.type = "WorkflowLinesLayer";
558
588
  __decorateClass([
559
- (0, import_inversify.inject)(import_free_layout_core4.WorkflowHoverService)
589
+ (0, import_inversify.inject)(import_free_layout_core3.WorkflowHoverService)
560
590
  ], WorkflowLinesLayer.prototype, "hoverService", 2);
561
591
  __decorateClass([
562
- (0, import_inversify.inject)(import_free_layout_core4.WorkflowSelectService)
592
+ (0, import_inversify.inject)(import_free_layout_core3.WorkflowSelectService)
563
593
  ], WorkflowLinesLayer.prototype, "selectService", 2);
564
594
  __decorateClass([
565
595
  (0, import_inversify.inject)(import_free_stack_plugin.StackingContextManager)
@@ -568,16 +598,16 @@ __decorateClass([
568
598
  (0, import_inversify.inject)(import_renderer.FlowRendererRegistry)
569
599
  ], WorkflowLinesLayer.prototype, "rendererRegistry", 2);
570
600
  __decorateClass([
571
- (0, import_core2.observeEntities)(import_free_layout_core4.WorkflowLineEntity)
601
+ (0, import_core2.observeEntities)(import_free_layout_core3.WorkflowLineEntity)
572
602
  ], WorkflowLinesLayer.prototype, "lines", 2);
573
603
  __decorateClass([
574
- (0, import_core2.observeEntities)(import_free_layout_core4.WorkflowPortEntity)
604
+ (0, import_core2.observeEntities)(import_free_layout_core3.WorkflowPortEntity)
575
605
  ], WorkflowLinesLayer.prototype, "ports", 2);
576
606
  __decorateClass([
577
- (0, import_core2.observeEntityDatas)(import_free_layout_core4.WorkflowNodeEntity, import_core2.TransformData)
607
+ (0, import_core2.observeEntityDatas)(import_free_layout_core3.WorkflowNodeEntity, import_core2.TransformData)
578
608
  ], WorkflowLinesLayer.prototype, "trans", 2);
579
609
  __decorateClass([
580
- (0, import_inversify.inject)(import_free_layout_core4.WorkflowDocument)
610
+ (0, import_inversify.inject)(import_free_layout_core3.WorkflowDocument)
581
611
  ], WorkflowLinesLayer.prototype, "workflowDocument", 2);
582
612
  WorkflowLinesLayer = __decorateClass([
583
613
  (0, import_inversify.injectable)()
@@ -585,16 +615,8 @@ WorkflowLinesLayer = __decorateClass([
585
615
 
586
616
  // src/contributions/bezier/index.ts
587
617
  var import_bezier_js = require("bezier-js");
588
- var import_utils2 = require("@flowgram.ai/utils");
589
- var import_free_layout_core5 = require("@flowgram.ai/free-layout-core");
590
-
591
- // src/contributions/utils.ts
592
- function toRelative(p, bbox) {
593
- return {
594
- x: p.x - bbox.x + LINE_PADDING,
595
- y: p.y - bbox.y + LINE_PADDING
596
- };
597
- }
618
+ var import_utils3 = require("@flowgram.ai/utils");
619
+ var import_free_layout_core4 = require("@flowgram.ai/free-layout-core");
598
620
 
599
621
  // src/contributions/bezier/bezier-controls.ts
600
622
  function getBezierEdgeCenter(fromPos, toPos, fromControl, toControl) {
@@ -678,11 +700,11 @@ var WorkflowBezierLineContribution = class {
678
700
  if (!this.data) {
679
701
  return Number.MAX_SAFE_INTEGER;
680
702
  }
681
- return import_utils2.Point.getDistance(pos, this.data.bezier.project(pos));
703
+ return import_utils3.Point.getDistance(pos, this.data.bezier.project(pos));
682
704
  }
683
705
  get bounds() {
684
706
  if (!this.data) {
685
- return import_utils2.Rectangle.EMPTY;
707
+ return import_utils3.Rectangle.EMPTY;
686
708
  }
687
709
  return this.data.bbox;
688
710
  }
@@ -700,7 +722,7 @@ var WorkflowBezierLineContribution = class {
700
722
  );
701
723
  const bezier = new import_bezier_js.Bezier([fromPos, ...controls, toPos]);
702
724
  const bbox = bezier.bbox();
703
- const bboxBounds = new import_utils2.Rectangle(
725
+ const bboxBounds = new import_utils3.Rectangle(
704
726
  bbox.x.min,
705
727
  bbox.y.min,
706
728
  bbox.x.max - bbox.x.min,
@@ -729,20 +751,20 @@ var WorkflowBezierLineContribution = class {
729
751
  const toPos = toRelative(params.toPos, bbox);
730
752
  const controls = params.controls.map((c) => toRelative(c, bbox));
731
753
  const shrink = this.entity.uiState.shrink;
732
- const renderFromPos = params.fromPos.location === "bottom" ? { x: fromPos.x, y: fromPos.y + shrink } : { x: fromPos.x + shrink, y: fromPos.y };
733
- const renderToPos = params.toPos.location === "top" ? { x: toPos.x, y: toPos.y - shrink } : { x: toPos.x - shrink, y: toPos.y };
754
+ const renderFromPos = posWithShrink(fromPos, params.fromPos.location, shrink);
755
+ const renderToPos = posWithShrink(toPos, params.toPos.location, shrink);
734
756
  const controlPoints = controls.map((s) => `${s.x} ${s.y}`).join(",");
735
757
  return `M${renderFromPos.x} ${renderFromPos.y} C ${controlPoints}, ${renderToPos.x} ${renderToPos.y}`;
736
758
  }
737
759
  };
738
- WorkflowBezierLineContribution.type = import_free_layout_core5.LineType.BEZIER;
760
+ WorkflowBezierLineContribution.type = import_free_layout_core4.LineType.BEZIER;
739
761
 
740
762
  // src/contributions/fold/index.ts
741
- var import_utils5 = require("@flowgram.ai/utils");
742
- var import_free_layout_core6 = require("@flowgram.ai/free-layout-core");
763
+ var import_utils6 = require("@flowgram.ai/utils");
764
+ var import_free_layout_core5 = require("@flowgram.ai/free-layout-core");
743
765
 
744
766
  // src/contributions/fold/fold-line.ts
745
- var import_utils4 = require("@flowgram.ai/utils");
767
+ var import_utils5 = require("@flowgram.ai/utils");
746
768
  var getPointToSegmentDistance = (point, segStart, segEnd) => {
747
769
  const { x: px, y: py } = point;
748
770
  const { x: x1, y: y1 } = segStart;
@@ -886,8 +908,8 @@ var FoldLine;
886
908
  FoldLine2.getPoints = getPoints;
887
909
  function getBend(a, b, c) {
888
910
  const bendSize = Math.min(
889
- import_utils4.Point.getDistance(a, b) / 2,
890
- import_utils4.Point.getDistance(b, c) / 2,
911
+ import_utils5.Point.getDistance(a, b) / 2,
912
+ import_utils5.Point.getDistance(b, c) / 2,
891
913
  EDGE_RADIUS
892
914
  );
893
915
  const { x, y } = b;
@@ -924,7 +946,7 @@ var FoldLine;
924
946
  const right = Math.max(...xList);
925
947
  const top = Math.min(...yList);
926
948
  const bottom = Math.max(...yList);
927
- return import_utils4.Rectangle.createRectangleWithTwoPoints(
949
+ return import_utils5.Rectangle.createRectangleWithTwoPoints(
928
950
  {
929
951
  x: left,
930
952
  y: top
@@ -941,7 +963,7 @@ var FoldLine;
941
963
  return Infinity;
942
964
  }
943
965
  if (points.length === 1) {
944
- return import_utils4.Point.getDistance(points[0], pos);
966
+ return import_utils5.Point.getDistance(points[0], pos);
945
967
  }
946
968
  const lines = [];
947
969
  for (let i = 0; i < points.length - 1; i++) {
@@ -971,7 +993,7 @@ var WorkflowFoldLineContribution = class {
971
993
  }
972
994
  get bounds() {
973
995
  if (!this.data) {
974
- return new import_utils5.Rectangle();
996
+ return new import_utils6.Rectangle();
975
997
  }
976
998
  return this.data.bbox;
977
999
  }
@@ -981,23 +1003,15 @@ var WorkflowFoldLineContribution = class {
981
1003
  update(params) {
982
1004
  const { fromPos, toPos } = params;
983
1005
  const shrink = this.entity.uiState.shrink;
984
- const sourceOffset = {
985
- x: fromPos.location === "bottom" ? 0 : shrink,
986
- y: fromPos.location === "bottom" ? shrink : 0
987
- };
988
- const targetOffset = {
989
- x: toPos.location === "top" ? 0 : -shrink,
990
- y: toPos.location === "top" ? -shrink : 0
991
- };
1006
+ const source = posWithShrink(fromPos, fromPos.location, shrink);
1007
+ const target = posWithShrink(toPos, toPos.location, shrink);
992
1008
  const { points, center } = FoldLine.getPoints({
993
1009
  source: {
994
- x: fromPos.x + sourceOffset.x,
995
- y: fromPos.y + sourceOffset.y,
1010
+ ...source,
996
1011
  location: fromPos.location
997
1012
  },
998
1013
  target: {
999
- x: toPos.x + targetOffset.x,
1000
- y: toPos.y + targetOffset.y,
1014
+ ...target,
1001
1015
  location: toPos.location
1002
1016
  }
1003
1017
  });
@@ -1018,11 +1032,11 @@ var WorkflowFoldLineContribution = class {
1018
1032
  };
1019
1033
  }
1020
1034
  };
1021
- WorkflowFoldLineContribution.type = import_free_layout_core6.LineType.LINE_CHART;
1035
+ WorkflowFoldLineContribution.type = import_free_layout_core5.LineType.LINE_CHART;
1022
1036
 
1023
1037
  // src/contributions/straight/index.ts
1024
- var import_utils7 = require("@flowgram.ai/utils");
1025
- var import_free_layout_core7 = require("@flowgram.ai/free-layout-core");
1038
+ var import_utils8 = require("@flowgram.ai/utils");
1039
+ var import_free_layout_core6 = require("@flowgram.ai/free-layout-core");
1026
1040
 
1027
1041
  // src/contributions/straight/point-on-line.ts
1028
1042
  function projectPointOnLine(point, lineStart, lineEnd) {
@@ -1055,11 +1069,11 @@ var WorkflowStraightLineContribution = class {
1055
1069
  return Number.MAX_SAFE_INTEGER;
1056
1070
  }
1057
1071
  const [start, end] = this.data.points;
1058
- return import_utils7.Point.getDistance(pos, projectPointOnLine(pos, start, end));
1072
+ return import_utils8.Point.getDistance(pos, projectPointOnLine(pos, start, end));
1059
1073
  }
1060
1074
  get bounds() {
1061
1075
  if (!this.data) {
1062
- return new import_utils7.Rectangle();
1076
+ return new import_utils8.Rectangle();
1063
1077
  }
1064
1078
  return this.data.bbox;
1065
1079
  }
@@ -1069,25 +1083,10 @@ var WorkflowStraightLineContribution = class {
1069
1083
  update(params) {
1070
1084
  const { fromPos, toPos } = params;
1071
1085
  const shrink = this.entity.uiState.shrink;
1072
- const sourceOffset = {
1073
- x: fromPos.location === "bottom" ? 0 : shrink,
1074
- y: fromPos.location === "bottom" ? shrink : 0
1075
- };
1076
- const targetOffset = {
1077
- x: toPos.location === "top" ? 0 : -shrink,
1078
- y: toPos.location === "top" ? -shrink : 0
1079
- };
1080
- const points = [
1081
- {
1082
- x: fromPos.x + sourceOffset.x,
1083
- y: fromPos.y + sourceOffset.y
1084
- },
1085
- {
1086
- x: toPos.x + targetOffset.x,
1087
- y: toPos.y + targetOffset.y
1088
- }
1089
- ];
1090
- const bbox = import_utils7.Rectangle.createRectangleWithTwoPoints(points[0], points[1]);
1086
+ const source = posWithShrink(fromPos, fromPos.location, shrink);
1087
+ const target = posWithShrink(toPos, toPos.location, shrink);
1088
+ const points = [source, target];
1089
+ const bbox = import_utils8.Rectangle.createRectangleWithTwoPoints(points[0], points[1]);
1091
1090
  const adjustedPoints = points.map((p) => ({
1092
1091
  x: p.x - bbox.x + LINE_PADDING,
1093
1092
  y: p.y - bbox.y + LINE_PADDING
@@ -1097,11 +1096,11 @@ var WorkflowStraightLineContribution = class {
1097
1096
  points,
1098
1097
  path,
1099
1098
  bbox,
1100
- center: (0, import_free_layout_core7.getLineCenter)(fromPos, toPos, bbox, LINE_PADDING)
1099
+ center: (0, import_free_layout_core6.getLineCenter)(fromPos, toPos, bbox, LINE_PADDING)
1101
1100
  };
1102
1101
  }
1103
1102
  };
1104
- WorkflowStraightLineContribution.type = import_free_layout_core7.LineType.STRAIGHT;
1103
+ WorkflowStraightLineContribution.type = import_free_layout_core6.LineType.STRAIGHT;
1105
1104
 
1106
1105
  // src/create-free-lines-plugin.ts
1107
1106
  var createFreeLinesPlugin = (0, import_core3.definePluginCreator)({
@@ -1112,7 +1111,7 @@ var createFreeLinesPlugin = (0, import_core3.definePluginCreator)({
1112
1111
  });
1113
1112
  },
1114
1113
  onReady: (ctx, opts) => {
1115
- const linesManager = ctx.container.get(import_free_layout_core8.WorkflowLinesManager);
1114
+ const linesManager = ctx.container.get(import_free_layout_core7.WorkflowLinesManager);
1116
1115
  linesManager.registerContribution(WorkflowBezierLineContribution).registerContribution(WorkflowFoldLineContribution).registerContribution(WorkflowStraightLineContribution);
1117
1116
  if (opts.contributions) {
1118
1117
  opts.contributions.forEach((contribution) => {