verben-workflow-ui 0.7.8 → 0.7.9

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.
Files changed (54) hide show
  1. package/esm2022/src/lib/components/actors/actors.component.mjs +4 -3
  2. package/esm2022/src/lib/components/designer/services/connection.service.mjs +259 -29
  3. package/esm2022/src/lib/components/designer/services/wf-mapper.service.mjs +13 -2
  4. package/esm2022/src/lib/components/flowable-status/flowable-status.component.mjs +4 -3
  5. package/esm2022/src/lib/components/form-response/form-response.component.mjs +4 -3
  6. package/esm2022/src/lib/components/form-response/form-response.module.mjs +7 -3
  7. package/esm2022/src/lib/components/form-values/form-values.component.mjs +4 -3
  8. package/esm2022/src/lib/components/forms/forms.component.mjs +4 -3
  9. package/esm2022/src/lib/components/my-queue/my-queue.columns.mjs +6 -1
  10. package/esm2022/src/lib/components/my-queue/my-queue.component.mjs +4 -3
  11. package/esm2022/src/lib/components/task-notification/task-notification.component.mjs +3 -3
  12. package/esm2022/src/lib/components/tasks/tasks.columns.mjs +6 -1
  13. package/esm2022/src/lib/components/tasks/tasks.component.mjs +4 -3
  14. package/esm2022/src/lib/components/workflow-designer/designer-canvas/designer-canvas.component.mjs +397 -23
  15. package/esm2022/src/lib/components/workflow-designer/workflow-designer.component.mjs +91 -31
  16. package/esm2022/src/lib/pipes/company-date.pipe.mjs +34 -0
  17. package/esm2022/src/lib/pipes/public-api.mjs +2 -1
  18. package/esm2022/src/lib/services/util.service.mjs +7 -1
  19. package/esm2022/src/lib/shared/shared.module.mjs +7 -5
  20. package/fesm2022/verben-workflow-ui-src-lib-components-actors.mjs +3 -2
  21. package/fesm2022/verben-workflow-ui-src-lib-components-actors.mjs.map +1 -1
  22. package/fesm2022/verben-workflow-ui-src-lib-components-designer.mjs +270 -29
  23. package/fesm2022/verben-workflow-ui-src-lib-components-designer.mjs.map +1 -1
  24. package/fesm2022/verben-workflow-ui-src-lib-components-flowable-status.mjs +3 -2
  25. package/fesm2022/verben-workflow-ui-src-lib-components-flowable-status.mjs.map +1 -1
  26. package/fesm2022/verben-workflow-ui-src-lib-components-form-response.mjs +9 -4
  27. package/fesm2022/verben-workflow-ui-src-lib-components-form-response.mjs.map +1 -1
  28. package/fesm2022/verben-workflow-ui-src-lib-components-form-values.mjs +3 -2
  29. package/fesm2022/verben-workflow-ui-src-lib-components-form-values.mjs.map +1 -1
  30. package/fesm2022/verben-workflow-ui-src-lib-components-forms.mjs +3 -2
  31. package/fesm2022/verben-workflow-ui-src-lib-components-forms.mjs.map +1 -1
  32. package/fesm2022/verben-workflow-ui-src-lib-components-my-queue.mjs +8 -2
  33. package/fesm2022/verben-workflow-ui-src-lib-components-my-queue.mjs.map +1 -1
  34. package/fesm2022/verben-workflow-ui-src-lib-components-task-notification.mjs +2 -2
  35. package/fesm2022/verben-workflow-ui-src-lib-components-task-notification.mjs.map +1 -1
  36. package/fesm2022/verben-workflow-ui-src-lib-components-tasks.mjs +8 -2
  37. package/fesm2022/verben-workflow-ui-src-lib-components-tasks.mjs.map +1 -1
  38. package/fesm2022/verben-workflow-ui-src-lib-components-workflow-designer.mjs +486 -52
  39. package/fesm2022/verben-workflow-ui-src-lib-components-workflow-designer.mjs.map +1 -1
  40. package/fesm2022/verben-workflow-ui-src-lib-pipes.mjs +32 -1
  41. package/fesm2022/verben-workflow-ui-src-lib-pipes.mjs.map +1 -1
  42. package/fesm2022/verben-workflow-ui-src-lib-services.mjs +6 -0
  43. package/fesm2022/verben-workflow-ui-src-lib-services.mjs.map +1 -1
  44. package/fesm2022/verben-workflow-ui-src-lib-shared.mjs +6 -4
  45. package/fesm2022/verben-workflow-ui-src-lib-shared.mjs.map +1 -1
  46. package/package.json +43 -43
  47. package/src/lib/components/designer/services/connection.service.d.ts +15 -0
  48. package/src/lib/components/form-response/form-response.module.d.ts +2 -1
  49. package/src/lib/components/workflow-designer/designer-canvas/designer-canvas.component.d.ts +5 -0
  50. package/src/lib/components/workflow-designer/workflow-designer.component.d.ts +1 -0
  51. package/src/lib/pipes/company-date.pipe.d.ts +11 -0
  52. package/src/lib/pipes/public-api.d.ts +1 -0
  53. package/src/lib/services/util.service.d.ts +4 -0
  54. package/src/lib/shared/shared.module.d.ts +1 -1
@@ -3760,44 +3760,38 @@ class DesignerCanvasComponent {
3760
3760
  if (!sourcePoint) {
3761
3761
  return '';
3762
3762
  }
3763
- return this.getOrthogonalPath(startX, startY, endX, endY, sourcePoint.type);
3763
+ const layout = this.getConnectionLayout(connection);
3764
+ return this.pointsToSvgPath(layout.points);
3764
3765
  }
3765
3766
  catch (error) {
3766
3767
  return '';
3767
3768
  }
3768
3769
  }
3770
+ pointsToSvgPath(points) {
3771
+ if (!points || points.length < 2)
3772
+ return '';
3773
+ return points
3774
+ .map((p, i) => `${i === 0 ? 'M' : 'L'} ${p.x} ${p.y}`)
3775
+ .join(' ');
3776
+ }
3769
3777
  getOrthogonalPath(startX, startY, endX, endY, pointType) {
3770
- // Determine initial direction based on connection point type
3771
- let path = '';
3772
- // For side points (left/right), start with horizontal line
3773
- if (pointType === 'left' || pointType === 'right') {
3774
- // Calculate horizontal distance
3778
+ const startHorizontal = pointType === 'left' || pointType === 'right';
3779
+ if (startHorizontal) {
3775
3780
  const horizontalDist = endX - startX;
3776
- // If the end point is very close horizontally, use a simple 3-segment path
3777
3781
  if (Math.abs(horizontalDist) < 30) {
3778
3782
  const midY = (startY + endY) / 2;
3779
- path = `M ${startX} ${startY} H ${endX} V ${midY} V ${endY}`;
3780
- }
3781
- // Otherwise, create a path with horizontal segment first, then vertical, then horizontal
3782
- else {
3783
- path = `M ${startX} ${startY} H ${startX + horizontalDist / 2} V ${endY} H ${endX}`;
3783
+ return `M ${startX} ${startY} H ${endX} V ${midY} V ${endY}`;
3784
3784
  }
3785
+ return `M ${startX} ${startY} H ${startX + horizontalDist / 2} V ${endY} H ${endX}`;
3785
3786
  }
3786
- // For top/bottom points, start with vertical line
3787
- else if (pointType === 'top' || pointType === 'bottom') {
3788
- // Calculate vertical distance
3787
+ else {
3789
3788
  const verticalDist = endY - startY;
3790
- // If the end point is very close vertically, use a simple 3-segment path
3791
3789
  if (Math.abs(verticalDist) < 30) {
3792
3790
  const midX = (startX + endX) / 2;
3793
- path = `M ${startX} ${startY} V ${endY} H ${midX} H ${endX}`;
3794
- }
3795
- // Otherwise, create a path with vertical segment first, then horizontal, then vertical
3796
- else {
3797
- path = `M ${startX} ${startY} V ${startY + verticalDist / 2} H ${endX} V ${endY}`;
3791
+ return `M ${startX} ${startY} V ${endY} H ${midX} H ${endX}`;
3798
3792
  }
3793
+ return `M ${startX} ${startY} V ${startY + verticalDist / 2} H ${endX} V ${endY}`;
3799
3794
  }
3800
- return path;
3801
3795
  }
3802
3796
  selectFormForStage(form, node) {
3803
3797
  // If form is null, we're clearing the selection
@@ -4030,7 +4024,371 @@ class DesignerCanvasComponent {
4030
4024
  this.canvasHeight = requiredHeight;
4031
4025
  }
4032
4026
  }
4027
+ connectionLayoutCache = new Map();
4028
+ lastLabelLayoutSignature = '';
4033
4029
  getLabelPosition(connection) {
4030
+ return this.getConnectionLayout(connection).labelPos;
4031
+ }
4032
+ getConnectionLayout(connection) {
4033
+ const validConnections = this.state.connections.filter((c) => c.sourceNodeId && c.targetNodeId);
4034
+ const stageBoxes = [];
4035
+ this.state.swimlanes.forEach((lane, laneIdx) => {
4036
+ (lane.nodes || []).forEach((n) => {
4037
+ const gy = n.y + laneIdx * 263;
4038
+ stageBoxes.push({
4039
+ id: n.id,
4040
+ left: n.x,
4041
+ right: n.x + n.width,
4042
+ top: gy,
4043
+ bottom: gy + n.height,
4044
+ });
4045
+ });
4046
+ });
4047
+ const items = validConnections.map((c) => {
4048
+ const pathData = this.state.getConnectionData(c);
4049
+ const sourceNode = this.state.findNodeById(c.sourceNodeId)?.node;
4050
+ const targetNode = this.state.findNodeById(c.targetNodeId)?.node;
4051
+ const sourcePoint = sourceNode?.connectionPoints?.find((p) => p.id === c.sourcePointId);
4052
+ const targetPoint = targetNode?.connectionPoints?.find((p) => p.id === c.targetPointId);
4053
+ return { conn: c, pathData, sourcePoint, targetPoint };
4054
+ });
4055
+ const stageSig = stageBoxes
4056
+ .map((b) => `${b.id}:${Math.round(b.left)}:${Math.round(b.top)}`)
4057
+ .join(',');
4058
+ const connSig = items
4059
+ .map(({ conn, pathData }) => `${conn.id}:${conn.label || ''}:${Math.round(pathData?.startX || 0)}:${Math.round(pathData?.startY || 0)}:${Math.round(pathData?.endX || 0)}:${Math.round(pathData?.endY || 0)}`)
4060
+ .join('|');
4061
+ const signature = `${stageSig}||${connSig}`;
4062
+ if (signature !== this.lastLabelLayoutSignature) {
4063
+ this.lastLabelLayoutSignature = signature;
4064
+ this.connectionLayoutCache.clear();
4065
+ const STAGE_MARGIN = 12;
4066
+ const segHitsStage = (x1, y1, x2, y2, excludeIds) => {
4067
+ const minX = Math.min(x1, x2);
4068
+ const maxX = Math.max(x1, x2);
4069
+ const minY = Math.min(y1, y2);
4070
+ const maxY = Math.max(y1, y2);
4071
+ return stageBoxes.some((b) => {
4072
+ const margin = excludeIds.has(b.id) ? -2 : STAGE_MARGIN;
4073
+ return (maxX > b.left - margin &&
4074
+ minX < b.right + margin &&
4075
+ maxY > b.top - margin &&
4076
+ minY < b.bottom + margin);
4077
+ });
4078
+ };
4079
+ const pointHitsAnyStage = (cx, cy, halfW, halfH) => stageBoxes.some((b) => cx + halfW > b.left &&
4080
+ cx - halfW < b.right &&
4081
+ cy + halfH > b.top &&
4082
+ cy - halfH < b.bottom);
4083
+ const buildPolyline = (startX, startY, endX, endY, sType, tType) => {
4084
+ const OUT = 28;
4085
+ const startH = sType === 'left' || sType === 'right';
4086
+ const endH = tType === 'left' || tType === 'right';
4087
+ const outX = startX + (sType === 'right' ? OUT : sType === 'left' ? -OUT : 0);
4088
+ const outY = startY + (sType === 'bottom' ? OUT : sType === 'top' ? -OUT : 0);
4089
+ const inX = endX + (tType === 'right' ? OUT : tType === 'left' ? -OUT : 0);
4090
+ const inY = endY + (tType === 'bottom' ? OUT : tType === 'top' ? -OUT : 0);
4091
+ if (startH && endH) {
4092
+ const forward = (sType === 'right' && tType === 'left' && endX >= startX) ||
4093
+ (sType === 'left' && tType === 'right' && startX >= endX);
4094
+ if (forward) {
4095
+ const midX = (startX + endX) / 2;
4096
+ const pts = [
4097
+ { x: startX, y: startY },
4098
+ { x: midX, y: startY },
4099
+ { x: midX, y: endY },
4100
+ { x: endX, y: endY },
4101
+ ];
4102
+ return { pts, segIndex: 1 };
4103
+ }
4104
+ const midY = (startY + endY) / 2;
4105
+ const pts = [
4106
+ { x: startX, y: startY },
4107
+ { x: outX, y: startY },
4108
+ { x: outX, y: midY },
4109
+ { x: inX, y: midY },
4110
+ { x: inX, y: endY },
4111
+ { x: endX, y: endY },
4112
+ ];
4113
+ return { pts, segIndex: 2 };
4114
+ }
4115
+ if (!startH && !endH) {
4116
+ const forward = (sType === 'bottom' && tType === 'top' && endY >= startY + 20) ||
4117
+ (sType === 'top' && tType === 'bottom' && startY >= endY + 20);
4118
+ if (forward) {
4119
+ const midY = (startY + endY) / 2;
4120
+ const pts = [
4121
+ { x: startX, y: startY },
4122
+ { x: startX, y: midY },
4123
+ { x: endX, y: midY },
4124
+ { x: endX, y: endY },
4125
+ ];
4126
+ return { pts, segIndex: 1 };
4127
+ }
4128
+ const midY = sType === 'bottom'
4129
+ ? Math.max(outY, inY) + 12
4130
+ : Math.min(outY, inY) - 12;
4131
+ const pts = [
4132
+ { x: startX, y: startY },
4133
+ { x: startX, y: midY },
4134
+ { x: endX, y: midY },
4135
+ { x: endX, y: endY },
4136
+ ];
4137
+ return { pts, segIndex: 1 };
4138
+ }
4139
+ // Perpendicular: startH !== endH
4140
+ if (startH) {
4141
+ const clearX = sType === 'right' ? endX >= startX + 10 : endX <= startX - 10;
4142
+ const clearY = tType === 'bottom' ? startY >= endY + 10 : startY <= endY - 10;
4143
+ if (clearX && clearY) {
4144
+ // Keep a movable middle horizontal segment by stepping to endX via outX or direct L
4145
+ const pts = [
4146
+ { x: startX, y: startY },
4147
+ { x: endX, y: startY },
4148
+ { x: endX, y: endY },
4149
+ ];
4150
+ const hLen = Math.abs(endX - startX);
4151
+ const vLen = Math.abs(endY - startY);
4152
+ return { pts, segIndex: hLen >= vLen ? 0 : 1 };
4153
+ }
4154
+ const pts = [
4155
+ { x: startX, y: startY },
4156
+ { x: outX, y: startY },
4157
+ { x: outX, y: inY },
4158
+ { x: endX, y: inY },
4159
+ { x: endX, y: endY },
4160
+ ];
4161
+ const seg2Len = Math.abs(inY - startY);
4162
+ const seg3Len = Math.abs(endX - outX);
4163
+ return { pts, segIndex: seg3Len >= seg2Len ? 2 : 1 };
4164
+ }
4165
+ else {
4166
+ const clearY = sType === 'bottom' ? endY >= startY + 10 : endY <= startY - 10;
4167
+ const clearX = tType === 'right' ? startX >= endX + 10 : startX <= endX - 10;
4168
+ if (clearY && clearX) {
4169
+ const pts = [
4170
+ { x: startX, y: startY },
4171
+ { x: startX, y: endY },
4172
+ { x: endX, y: endY },
4173
+ ];
4174
+ const vLen = Math.abs(endY - startY);
4175
+ const hLen = Math.abs(endX - startX);
4176
+ return { pts, segIndex: hLen >= vLen ? 1 : 0 };
4177
+ }
4178
+ const pts = [
4179
+ { x: startX, y: startY },
4180
+ { x: startX, y: outY },
4181
+ { x: inX, y: outY },
4182
+ { x: inX, y: endY },
4183
+ { x: endX, y: endY },
4184
+ ];
4185
+ const seg2Len = Math.abs(inX - startX);
4186
+ const seg3Len = Math.abs(endY - outY);
4187
+ return { pts, segIndex: seg2Len >= seg3Len ? 1 : 2 };
4188
+ }
4189
+ };
4190
+ const prepared = items.map(({ conn, pathData, sourcePoint, targetPoint }) => {
4191
+ if (!pathData || !sourcePoint || !targetPoint) {
4192
+ return {
4193
+ conn,
4194
+ pts: [],
4195
+ segIndex: 0,
4196
+ baseLabel: { x: 0, y: 0 },
4197
+ };
4198
+ }
4199
+ const { pts, segIndex } = buildPolyline(pathData.startX, pathData.startY, pathData.endX, pathData.endY, sourcePoint.type, targetPoint.type);
4200
+ const pA = pts[segIndex];
4201
+ const pB = pts[segIndex + 1];
4202
+ return {
4203
+ conn,
4204
+ pts,
4205
+ segIndex,
4206
+ baseLabel: { x: (pA.x + pB.x) / 2, y: (pA.y + pB.y) / 2 },
4207
+ };
4208
+ });
4209
+ prepared.sort((a, b) => a.baseLabel.y - b.baseLabel.y ||
4210
+ a.baseLabel.x - b.baseLabel.x ||
4211
+ a.conn.id.localeCompare(b.conn.id));
4212
+ const placed = [];
4213
+ const STEP_Y = 42;
4214
+ const STEP_X = 80;
4215
+ const overlapsAny = (cx, cy, halfW, halfH) => placed.some((b) => Math.abs(cx - b.cx) < halfW + b.halfW &&
4216
+ Math.abs(cy - b.cy) < halfH + b.halfH);
4217
+ for (const item of prepared) {
4218
+ const { conn, pts, segIndex } = item;
4219
+ if (pts.length < 2) {
4220
+ this.connectionLayoutCache.set(conn.id, {
4221
+ points: pts,
4222
+ labelPos: { x: 0, y: 0 },
4223
+ });
4224
+ continue;
4225
+ }
4226
+ const excludeIds = new Set([conn.sourceNodeId, conn.targetNodeId]);
4227
+ const text = conn.label || 'New Action';
4228
+ const width = Math.max(120, text.length * 7.5 + 56);
4229
+ const height = 38;
4230
+ const halfW = width / 2;
4231
+ const halfH = height / 2;
4232
+ // If the chosen segment is an endpoint segment (segIndex === 0 or last) and needs shifting,
4233
+ // promote it to a 4-point segment so endpoints stay pinned to the stage connection points.
4234
+ const ensureMovableSegment = () => {
4235
+ if (segIndex > 0 && segIndex < pts.length - 2) {
4236
+ return segIndex;
4237
+ }
4238
+ const a = pts[segIndex];
4239
+ const b = pts[segIndex + 1];
4240
+ const isHoriz = Math.abs(a.y - b.y) < 1;
4241
+ if (isHoriz) {
4242
+ const mx = (a.x + b.x) / 2;
4243
+ const sy = a.y;
4244
+ pts.splice(segIndex + 1, 0, { x: a.x + (mx - a.x) * 0.4, y: sy }, { x: a.x + (mx - a.x) * 0.4, y: sy }, { x: b.x - (b.x - mx) * 0.4, y: sy }, { x: b.x - (b.x - mx) * 0.4, y: sy });
4245
+ return segIndex + 2;
4246
+ }
4247
+ else {
4248
+ const my = (a.y + b.y) / 2;
4249
+ const sx = a.x;
4250
+ pts.splice(segIndex + 1, 0, { x: sx, y: a.y + (my - a.y) * 0.4 }, { x: sx, y: a.y + (my - a.y) * 0.4 }, { x: sx, y: b.y - (b.y - my) * 0.4 }, { x: sx, y: b.y - (b.y - my) * 0.4 });
4251
+ return segIndex + 2;
4252
+ }
4253
+ };
4254
+ let activeSeg = segIndex;
4255
+ let pA = pts[activeSeg];
4256
+ let pB = pts[activeSeg + 1];
4257
+ const isHoriz = Math.abs(pA.y - pB.y) < 1;
4258
+ const baseCx = (pA.x + pB.x) / 2;
4259
+ const baseCy = (pA.y + pB.y) / 2;
4260
+ const segBlocked = segHitsStage(pA.x, pA.y, pB.x, pB.y, excludeIds);
4261
+ const labelBlocked = overlapsAny(baseCx, baseCy, halfW, halfH) ||
4262
+ pointHitsAnyStage(baseCx, baseCy, halfW, halfH);
4263
+ let chosenLabelX = baseCx;
4264
+ let chosenLabelY = baseCy;
4265
+ if (segBlocked || labelBlocked) {
4266
+ let resolved = false;
4267
+ // 1. If the segment itself doesn't hit any stage, try sliding the label along the segment first
4268
+ if (!segBlocked) {
4269
+ if (!isHoriz) {
4270
+ const minY = Math.min(pA.y, pB.y) + 20;
4271
+ const maxY = Math.max(pA.y, pB.y) - 20;
4272
+ for (let ring = 1; ring <= 10 && !resolved; ring++) {
4273
+ for (const dy of [ring * STEP_Y, -ring * STEP_Y]) {
4274
+ const ny = baseCy + dy;
4275
+ if (ny >= minY &&
4276
+ ny <= maxY &&
4277
+ !overlapsAny(baseCx, ny, halfW, halfH) &&
4278
+ !pointHitsAnyStage(baseCx, ny, halfW, halfH)) {
4279
+ chosenLabelY = ny;
4280
+ resolved = true;
4281
+ break;
4282
+ }
4283
+ }
4284
+ }
4285
+ }
4286
+ else {
4287
+ const minX = Math.min(pA.x, pB.x) + 30;
4288
+ const maxX = Math.max(pA.x, pB.x) - 30;
4289
+ for (let ring = 1; ring <= 10 && !resolved; ring++) {
4290
+ for (const dx of [ring * STEP_X, -ring * STEP_X]) {
4291
+ const nx = baseCx + dx;
4292
+ if (nx >= minX &&
4293
+ nx <= maxX &&
4294
+ !overlapsAny(nx, baseCy, halfW, halfH) &&
4295
+ !pointHitsAnyStage(nx, baseCy, halfW, halfH)) {
4296
+ chosenLabelX = nx;
4297
+ resolved = true;
4298
+ break;
4299
+ }
4300
+ }
4301
+ }
4302
+ }
4303
+ }
4304
+ // 2. Otherwise promote to a movable segment and shift the segment itself into a stage-free, label-free lane
4305
+ if (!resolved) {
4306
+ activeSeg = ensureMovableSegment();
4307
+ pA = pts[activeSeg];
4308
+ pB = pts[activeSeg + 1];
4309
+ if (isHoriz) {
4310
+ for (let ring = 1; ring <= 12 && !resolved; ring++) {
4311
+ for (const dy of [ring * STEP_Y, -ring * STEP_Y]) {
4312
+ const ny = baseCy + dy;
4313
+ if (!overlapsAny(baseCx, ny, halfW, halfH) &&
4314
+ !segHitsStage(pA.x, ny, pB.x, ny, excludeIds) &&
4315
+ !pointHitsAnyStage(baseCx, ny, halfW, halfH)) {
4316
+ pA.y = ny;
4317
+ pB.y = ny;
4318
+ chosenLabelY = ny;
4319
+ resolved = true;
4320
+ break;
4321
+ }
4322
+ }
4323
+ }
4324
+ }
4325
+ else {
4326
+ const startEndMinX = Math.min(pts[0].x, pts[pts.length - 1].x);
4327
+ const startEndMaxX = Math.max(pts[0].x, pts[pts.length - 1].x);
4328
+ const keepWithinCorridor = startEndMaxX - startEndMinX >= 60 &&
4329
+ baseCx >= startEndMinX &&
4330
+ baseCx <= startEndMaxX;
4331
+ for (let ring = 1; ring <= 10 && !resolved; ring++) {
4332
+ for (const dx of [ring * STEP_X, -ring * STEP_X]) {
4333
+ const nx = baseCx + dx;
4334
+ if (keepWithinCorridor &&
4335
+ (nx < startEndMinX + 8 || nx > startEndMaxX - 8)) {
4336
+ continue;
4337
+ }
4338
+ if (!overlapsAny(nx, baseCy, halfW, halfH) &&
4339
+ !segHitsStage(nx, pA.y, nx, pB.y, excludeIds) &&
4340
+ !pointHitsAnyStage(nx, baseCy, halfW, halfH)) {
4341
+ pA.x = nx;
4342
+ pB.x = nx;
4343
+ chosenLabelX = nx;
4344
+ resolved = true;
4345
+ break;
4346
+ }
4347
+ }
4348
+ }
4349
+ }
4350
+ }
4351
+ // 3. Final fallback: slide label vertically without bending the arrow through stages
4352
+ if (!resolved) {
4353
+ for (let ring = 1; ring <= 12 && !resolved; ring++) {
4354
+ for (const d of [ring * STEP_Y, -ring * STEP_Y]) {
4355
+ if (isHoriz) {
4356
+ const ny = baseCy + d;
4357
+ if (!overlapsAny(baseCx, ny, halfW, halfH) &&
4358
+ !segHitsStage(pA.x, ny, pB.x, ny, excludeIds)) {
4359
+ pA.y = ny;
4360
+ pB.y = ny;
4361
+ chosenLabelY = ny;
4362
+ resolved = true;
4363
+ break;
4364
+ }
4365
+ }
4366
+ else {
4367
+ const ny = baseCy + d;
4368
+ if (!overlapsAny(baseCx, ny, halfW, halfH)) {
4369
+ chosenLabelY = ny;
4370
+ resolved = true;
4371
+ break;
4372
+ }
4373
+ }
4374
+ }
4375
+ }
4376
+ }
4377
+ }
4378
+ const labelPos = {
4379
+ x: chosenLabelX,
4380
+ y: chosenLabelY,
4381
+ };
4382
+ placed.push({ cx: labelPos.x, cy: labelPos.y, halfW, halfH });
4383
+ this.connectionLayoutCache.set(conn.id, { points: pts, labelPos });
4384
+ }
4385
+ }
4386
+ return (this.connectionLayoutCache.get(connection.id) || {
4387
+ points: [],
4388
+ labelPos: this.getBaseLabelPosition(connection),
4389
+ });
4390
+ }
4391
+ getBaseLabelPosition(connection) {
4034
4392
  try {
4035
4393
  const pathData = this.state.getConnectionData(connection);
4036
4394
  if (!pathData) {
@@ -4046,6 +4404,22 @@ class DesignerCanvasComponent {
4046
4404
  if (!sourcePoint) {
4047
4405
  return { x: 0, y: 0 };
4048
4406
  }
4407
+ const targetNode = this.state.findNodeById(connection.targetNodeId)?.node;
4408
+ const targetPoint = targetNode?.connectionPoints?.find((p) => p.id === connection.targetPointId);
4409
+ const startHorizontal = sourcePoint.type === 'left' || sourcePoint.type === 'right';
4410
+ const endHorizontal = targetPoint?.type === 'left' || targetPoint?.type === 'right';
4411
+ if (targetPoint && startHorizontal !== endHorizontal) {
4412
+ if (Math.abs(endX - startX) >= Math.abs(endY - startY)) {
4413
+ return {
4414
+ x: (startX + endX) / 2,
4415
+ y: startHorizontal ? startY : endY,
4416
+ };
4417
+ }
4418
+ return {
4419
+ x: startHorizontal ? endX : startX,
4420
+ y: (startY + endY) / 2,
4421
+ };
4422
+ }
4049
4423
  // Calculate midpoint based on the connection point type
4050
4424
  if (sourcePoint.type === 'left' || sourcePoint.type === 'right') {
4051
4425
  const horizontalDist = endX - startX;
@@ -4553,6 +4927,30 @@ class WorkflowDesignerComponent {
4553
4927
  }
4554
4928
  // Process connections/actions
4555
4929
  if (workflow.Actions && workflow.Actions.length) {
4930
+ const usedAsSource = new Set();
4931
+ const usedAsTarget = new Set();
4932
+ const pickConnectionPoint = (nodeInfo, otherInfo, preferredTypes, oppositeUsed) => {
4933
+ const { node, swimlaneIndex } = nodeInfo;
4934
+ const candidates = (node.connectionPoints || []).filter((p) => preferredTypes.includes(p.type));
4935
+ if (candidates.length === 0)
4936
+ return undefined;
4937
+ const nonOpposite = candidates.filter((p) => !oppositeUsed.has(p.id));
4938
+ const pool = nonOpposite.length > 0 ? nonOpposite : candidates;
4939
+ const nodeGlobalY = node.y + swimlaneIndex * 263;
4940
+ const otherCenterX = otherInfo.node.x + otherInfo.node.width / 2;
4941
+ const otherCenterY = otherInfo.node.y +
4942
+ otherInfo.swimlaneIndex * 263 +
4943
+ otherInfo.node.height / 2;
4944
+ return pool.reduce((best, p) => {
4945
+ const distP = p.type === 'top' || p.type === 'bottom'
4946
+ ? Math.abs(node.x + p.x - otherCenterX)
4947
+ : Math.abs(nodeGlobalY + p.y - otherCenterY);
4948
+ const distBest = best.type === 'top' || best.type === 'bottom'
4949
+ ? Math.abs(node.x + best.x - otherCenterX)
4950
+ : Math.abs(nodeGlobalY + best.y - otherCenterY);
4951
+ return distP < distBest ? p : best;
4952
+ }, pool[0]);
4953
+ };
4556
4954
  workflow.Actions.forEach((action) => {
4557
4955
  // Store original action in record
4558
4956
  this.state.actionRecord[action.Code] = action;
@@ -4560,39 +4958,37 @@ class WorkflowDesignerComponent {
4560
4958
  const sourceNodeInfo = this.state.findNodeById(action.FromStage);
4561
4959
  const targetNodeInfo = this.state.findNodeById(action.ToStage);
4562
4960
  if (sourceNodeInfo && targetNodeInfo) {
4563
- // Find suitable connection points
4564
- // const sourceNode = sourceNodeInfo.node;
4565
- // const targetNode = targetNodeInfo.node;
4566
- // const sourcePoint = sourceNode.connectionPoints?.find(
4567
- // (p) => p.type === 'right' || p.type === 'bottom'
4568
- // );
4569
- // const targetPoint = targetNode.connectionPoints?.find(
4570
- // (p) => p.type === 'left' || p.type === 'top'
4571
- // );
4572
- const sourceNode = sourceNodeInfo.node;
4573
- const targetNode = targetNodeInfo.node;
4574
- let sourcePointId, targetPointId;
4575
- if (action.SourcePointType) {
4576
- // Find a point with matching type
4577
- const sourcePoint = sourceNode.connectionPoints?.find((p) => p.type === action.SourcePointType?.toLowerCase());
4578
- sourcePointId = sourcePoint?.id;
4579
- }
4580
- else {
4581
- // Fallback to finding a suitable point
4582
- const sourcePoint = sourceNode.connectionPoints?.find((p) => p.type === 'right' || p.type === 'bottom');
4583
- sourcePointId = sourcePoint?.id;
4961
+ const sNode = sourceNodeInfo.node;
4962
+ const tNode = targetNodeInfo.node;
4963
+ const sTop = sNode.y + sourceNodeInfo.swimlaneIndex * 263;
4964
+ const sBottom = sTop + sNode.height;
4965
+ const tTop = tNode.y + targetNodeInfo.swimlaneIndex * 263;
4966
+ const tBottom = tTop + tNode.height;
4967
+ const rawSourceType = action.SourcePointType?.toLowerCase();
4968
+ let rawTargetType = action.TargetPointType?.toLowerCase();
4969
+ // Override target side when the stored side faces away from an approach above/below
4970
+ if (rawTargetType === 'bottom' &&
4971
+ (sBottom <= tTop || (rawSourceType === 'top' && tTop >= sTop - 40))) {
4972
+ rawTargetType = 'top';
4584
4973
  }
4585
- if (action.TargetPointType) {
4586
- // Find a point with matching type
4587
- const targetPoint = targetNode.connectionPoints?.find((p) => p.type === action.TargetPointType?.toLowerCase());
4588
- targetPointId = targetPoint?.id;
4589
- }
4590
- else {
4591
- // Fallback to finding a suitable point
4592
- const targetPoint = targetNode.connectionPoints?.find((p) => p.type === 'left' || p.type === 'top');
4593
- targetPointId = targetPoint?.id;
4974
+ else if (rawTargetType === 'top' &&
4975
+ (sTop >= tBottom ||
4976
+ (rawSourceType === 'bottom' && tBottom <= sBottom + 40))) {
4977
+ rawTargetType = 'bottom';
4594
4978
  }
4979
+ const sourceTypes = rawSourceType
4980
+ ? [rawSourceType]
4981
+ : ['right', 'bottom'];
4982
+ const targetTypes = rawTargetType
4983
+ ? [rawTargetType]
4984
+ : ['left', 'top'];
4985
+ const sourcePoint = pickConnectionPoint(sourceNodeInfo, targetNodeInfo, sourceTypes, usedAsTarget);
4986
+ const targetPoint = pickConnectionPoint(targetNodeInfo, sourceNodeInfo, targetTypes, usedAsSource);
4987
+ const sourcePointId = sourcePoint?.id;
4988
+ const targetPointId = targetPoint?.id;
4595
4989
  if (sourcePointId && targetPointId) {
4990
+ usedAsSource.add(sourcePointId);
4991
+ usedAsTarget.add(targetPointId);
4596
4992
  const connection = {
4597
4993
  id: action.Code, // Use original ID
4598
4994
  sourceNodeId: action.FromStage,
@@ -4615,6 +5011,44 @@ class WorkflowDesignerComponent {
4615
5011
  }
4616
5012
  }
4617
5013
  });
5014
+ this.ensureHorizontalArrowClearance();
5015
+ }
5016
+ }
5017
+ ensureHorizontalArrowClearance() {
5018
+ const MIN_GAP = 120;
5019
+ const allNodes = this.state.swimlanes.flatMap((lane) => lane.nodes || []);
5020
+ for (let pass = 0; pass < 3; pass++) {
5021
+ let shifted = false;
5022
+ const sortedConns = [...this.state.connections].sort((a, b) => {
5023
+ const ax = this.state.findNodeById(a.sourceNodeId)?.node.x ?? 0;
5024
+ const bx = this.state.findNodeById(b.sourceNodeId)?.node.x ?? 0;
5025
+ return ax - bx;
5026
+ });
5027
+ for (const conn of sortedConns) {
5028
+ const src = this.state.findNodeById(conn.sourceNodeId)?.node;
5029
+ const tgt = this.state.findNodeById(conn.targetNodeId)?.node;
5030
+ if (!src || !tgt || src.id === tgt.id)
5031
+ continue;
5032
+ const srcPt = src.connectionPoints?.find((p) => p.id === conn.sourcePointId);
5033
+ const tgtPt = tgt.connectionPoints?.find((p) => p.id === conn.targetPointId);
5034
+ if (srcPt?.type !== 'right' || tgtPt?.type !== 'left')
5035
+ continue;
5036
+ if (tgt.x < src.x)
5037
+ continue;
5038
+ const gap = tgt.x - (src.x + src.width);
5039
+ if (gap < MIN_GAP) {
5040
+ const delta = MIN_GAP - gap;
5041
+ const thresholdX = tgt.x;
5042
+ allNodes.forEach((n) => {
5043
+ if (n.x >= thresholdX) {
5044
+ n.x += delta;
5045
+ }
5046
+ });
5047
+ shifted = true;
5048
+ }
5049
+ }
5050
+ if (!shifted)
5051
+ break;
4618
5052
  }
4619
5053
  }
4620
5054
  // Helper method to find swimlane index by Lane ID