@html-graph/html-graph 8.16.0 → 8.18.0

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.
@@ -2691,6 +2691,11 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
2691
2691
  __publicField(this, "line");
2692
2692
  __publicField(this, "sourceArrow");
2693
2693
  __publicField(this, "targetArrow");
2694
+ // TODO: make private
2695
+ /**
2696
+ * @deprecated
2697
+ * do use shape.svg instead
2698
+ */
2694
2699
  __publicField(this, "handle", createEdgeGroup());
2695
2700
  __publicField(this, "onAfterRender");
2696
2701
  __publicField(this, "interactiveLine");
@@ -3304,11 +3309,11 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
3304
3309
  }
3305
3310
  const target = event.currentTarget;
3306
3311
  const portId = this.canvas.graph.findPortIdsByElement(target)[0];
3307
- const accepted = this.params.onPortPointerDown(portId, {
3312
+ const dragAllowed = this.params.onPointerDownVerifier(portId, {
3308
3313
  x: mouseEvent.clientX,
3309
3314
  y: mouseEvent.clientY
3310
3315
  });
3311
- if (!accepted) {
3316
+ if (!dragAllowed) {
3312
3317
  return;
3313
3318
  }
3314
3319
  event.stopPropagation();
@@ -3325,8 +3330,8 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
3325
3330
  event.clientY
3326
3331
  );
3327
3332
  if (!isInside) {
3328
- this.params.onPointerMoveOutside();
3329
- this.stopMouseDrag();
3333
+ this.removeWindowMouseListeners();
3334
+ this.params.onPointerOutside();
3330
3335
  return;
3331
3336
  }
3332
3337
  this.params.onPointerMove({ x: event.clientX, y: event.clientY });
@@ -3335,8 +3340,8 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
3335
3340
  if (!this.params.mouseUpEventVerifier(event)) {
3336
3341
  return;
3337
3342
  }
3343
+ this.removeWindowMouseListeners();
3338
3344
  this.params.onPointerUp({ x: event.clientX, y: event.clientY });
3339
- this.stopMouseDrag();
3340
3345
  });
3341
3346
  __publicField(this, "onPortTouchStart", (event) => {
3342
3347
  const touchEvent = event;
@@ -3346,11 +3351,11 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
3346
3351
  const touch = touchEvent.touches[0];
3347
3352
  const target = event.currentTarget;
3348
3353
  const portId = this.canvas.graph.findPortIdsByElement(target)[0];
3349
- const accepted = this.params.onPortPointerDown(portId, {
3354
+ const dragAllowed = this.params.onPointerDownVerifier(portId, {
3350
3355
  x: touch.clientX,
3351
3356
  y: touch.clientY
3352
3357
  });
3353
- if (!accepted) {
3358
+ if (!dragAllowed) {
3354
3359
  return;
3355
3360
  }
3356
3361
  event.stopPropagation();
@@ -3371,16 +3376,16 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
3371
3376
  touch.clientY
3372
3377
  );
3373
3378
  if (!isInside) {
3374
- this.params.onPointerMoveOutside();
3375
- this.stopTouchDrag();
3379
+ this.removeWindowTouchListeners();
3380
+ this.params.onPointerOutside();
3376
3381
  return;
3377
3382
  }
3378
3383
  this.params.onPointerMove({ x: touch.clientX, y: touch.clientY });
3379
3384
  });
3380
3385
  __publicField(this, "onWindowTouchFinish", (event) => {
3386
+ this.removeWindowTouchListeners();
3381
3387
  const touch = event.changedTouches[0];
3382
3388
  this.params.onPointerUp({ x: touch.clientX, y: touch.clientY });
3383
- this.stopTouchDrag();
3384
3389
  });
3385
3390
  __publicField(this, "reset", () => {
3386
3391
  this.canvas.graph.getAllPortIds().forEach((portId) => {
@@ -3389,10 +3394,9 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
3389
3394
  });
3390
3395
  });
3391
3396
  __publicField(this, "revert", () => {
3392
- this.params.onStopDrag();
3393
- this.reset();
3394
3397
  this.removeWindowMouseListeners();
3395
3398
  this.removeWindowTouchListeners();
3399
+ this.reset();
3396
3400
  });
3397
3401
  this.canvas = canvas;
3398
3402
  this.window = window2;
@@ -3418,14 +3422,6 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
3418
3422
  element.removeEventListener("mousedown", this.onPortMouseDown);
3419
3423
  element.removeEventListener("touchstart", this.onPortTouchStart);
3420
3424
  }
3421
- stopMouseDrag() {
3422
- this.params.onStopDrag();
3423
- this.removeWindowMouseListeners();
3424
- }
3425
- stopTouchDrag() {
3426
- this.params.onStopDrag();
3427
- this.removeWindowTouchListeners();
3428
- }
3429
3425
  removeWindowMouseListeners() {
3430
3426
  this.window.removeEventListener("mousemove", this.onWindowMouseMove);
3431
3427
  this.window.removeEventListener("mouseup", this.onWindowMouseUp);
@@ -3436,47 +3432,6 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
3436
3432
  this.window.removeEventListener("touchcancel", this.onWindowTouchFinish);
3437
3433
  }
3438
3434
  }
3439
- class LayoutApplier {
3440
- constructor(canvas, layoutAlgorithm, params) {
3441
- this.canvas = canvas;
3442
- this.layoutAlgorithm = layoutAlgorithm;
3443
- this.params = params;
3444
- }
3445
- apply() {
3446
- const coords = this.layoutAlgorithm.calculateCoordinates({
3447
- graph: this.canvas.graph,
3448
- viewport: this.canvas.viewport
3449
- });
3450
- this.params.onBeforeApplied();
3451
- coords.forEach((point, nodeId) => {
3452
- if (!this.params.staticNodeResolver(nodeId)) {
3453
- this.canvas.updateNode(nodeId, point);
3454
- }
3455
- });
3456
- this.params.onAfterApplied();
3457
- }
3458
- }
3459
- class AnimatedLayoutApplier {
3460
- constructor(canvas, layoutAlgorithm, params) {
3461
- this.canvas = canvas;
3462
- this.layoutAlgorithm = layoutAlgorithm;
3463
- this.params = params;
3464
- }
3465
- apply(dt) {
3466
- const coords = this.layoutAlgorithm.calculateNextCoordinates({
3467
- graph: this.canvas.graph,
3468
- viewport: this.canvas.viewport,
3469
- dt
3470
- });
3471
- this.params.onBeforeApplied();
3472
- coords.forEach((point, nodeId) => {
3473
- if (!this.params.staticNodeResolver(nodeId)) {
3474
- this.canvas.updateNode(nodeId, point);
3475
- }
3476
- });
3477
- this.params.onAfterApplied();
3478
- }
3479
- }
3480
3435
  class EventTagger {
3481
3436
  constructor() {
3482
3437
  __publicField(this, "field", "_htmlGraphTags");
@@ -3634,6 +3589,52 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
3634
3589
  }
3635
3590
  }
3636
3591
  }
3592
+ const resolveCreateEdgeRequest = (params, targetPortId) => {
3593
+ return {
3594
+ from: params.isDirect ? params.staticPortId : targetPortId,
3595
+ to: params.isDirect ? targetPortId : params.staticPortId
3596
+ };
3597
+ };
3598
+ class ClosestConnectablePortDraggingPortDirectionResolver {
3599
+ constructor(graph, connectionAllowedVerifier) {
3600
+ this.graph = graph;
3601
+ this.connectionAllowedVerifier = connectionAllowedVerifier;
3602
+ }
3603
+ resolve(params) {
3604
+ let closestDirection = void 0;
3605
+ let closestDistance = Infinity;
3606
+ const { cursor } = params;
3607
+ this.graph.getAllPortIds().forEach((portId) => {
3608
+ const { element, direction, nodeId } = this.graph.getPort(portId);
3609
+ const { x, y } = this.graph.getNode(nodeId);
3610
+ if (x === null || y === null) {
3611
+ return;
3612
+ }
3613
+ const request = resolveCreateEdgeRequest(params, portId);
3614
+ if (!this.connectionAllowedVerifier(request)) {
3615
+ return;
3616
+ }
3617
+ const { top, left, width, height } = element.getBoundingClientRect();
3618
+ const center = { x: left + width / 2, y: top + height / 2 };
3619
+ const dx = cursor.x - center.x;
3620
+ const dy = cursor.y - center.y;
3621
+ const distance = Math.sqrt(dx * dx + dy * dy);
3622
+ if (distance < closestDistance) {
3623
+ closestDistance = distance;
3624
+ closestDirection = direction;
3625
+ }
3626
+ });
3627
+ return closestDirection;
3628
+ }
3629
+ }
3630
+ class ConstantDraggingPortDirectionResolver {
3631
+ constructor(direction) {
3632
+ this.direction = direction;
3633
+ }
3634
+ resolve() {
3635
+ return this.direction;
3636
+ }
3637
+ }
3637
3638
  class UserDraggableNodesConfigurator {
3638
3639
  constructor(canvas, element, window2, pointInsideVerifier, params) {
3639
3640
  __publicField(this, "grabbedNode", null);
@@ -4355,8 +4356,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
4355
4356
  class UserConnectablePortsConfigurator {
4356
4357
  constructor(canvas, overlayLayer, viewportStore, window2, pointInsideVerifier, params) {
4357
4358
  __publicField(this, "overlayCanvas");
4358
- __publicField(this, "staticPortId", null);
4359
- __publicField(this, "isTargetDragging", true);
4359
+ __publicField(this, "edgeInProgress", null);
4360
4360
  __publicField(this, "onEdgeCreated", (edgeId) => {
4361
4361
  this.params.onAfterEdgeCreated(edgeId);
4362
4362
  });
@@ -4371,34 +4371,35 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
4371
4371
  this.viewportStore,
4372
4372
  this.window
4373
4373
  );
4374
+ const draggablePortsParams = {
4375
+ mouseDownEventVerifier: this.params.mouseDownEventVerifier,
4376
+ mouseUpEventVerifier: this.params.mouseUpEventVerifier,
4377
+ onPointerDownVerifier: (portId, cursor) => {
4378
+ const connectionType = this.params.connectionTypeResolver(portId);
4379
+ if (connectionType === null) {
4380
+ return false;
4381
+ }
4382
+ this.grabPort(portId, cursor, connectionType);
4383
+ return true;
4384
+ },
4385
+ onPointerMove: (cursor) => {
4386
+ this.moveDraggingPort(cursor);
4387
+ },
4388
+ onPointerUp: (cursor) => {
4389
+ this.tryCreateConnection(cursor);
4390
+ this.resetDragState();
4391
+ },
4392
+ onPointerOutside: () => {
4393
+ const params2 = this.edgeInProgress;
4394
+ this.resetDragState();
4395
+ this.params.onEdgeCreationInterrupted(params2);
4396
+ }
4397
+ };
4374
4398
  DraggablePortsConfigurator.configure(
4375
4399
  this.canvas,
4376
4400
  this.window,
4377
4401
  this.pointInsideVerifier,
4378
- {
4379
- mouseDownEventVerifier: this.params.mouseDownEventVerifier,
4380
- mouseUpEventVerifier: this.params.mouseUpEventVerifier,
4381
- onStopDrag: () => {
4382
- this.resetDragState();
4383
- },
4384
- onPortPointerDown: (portId, cursor) => {
4385
- const connectionType = this.params.connectionTypeResolver(portId);
4386
- if (connectionType === null) {
4387
- return false;
4388
- }
4389
- this.grabPort(portId, cursor, connectionType);
4390
- return true;
4391
- },
4392
- onPointerMove: (cursor) => {
4393
- this.moveDraggingPort(cursor);
4394
- },
4395
- onPointerMoveOutside: () => {
4396
- this.handleEdgeCreationInterrupted();
4397
- },
4398
- onPointerUp: (cursor) => {
4399
- this.tryCreateConnection(cursor);
4400
- }
4401
- }
4402
+ draggablePortsParams
4402
4403
  );
4403
4404
  }
4404
4405
  static configure(canvas, overlayLayer, viewportStore, win, pointInsideVerifier, params) {
@@ -4411,9 +4412,8 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
4411
4412
  params
4412
4413
  );
4413
4414
  }
4414
- grabPort(portId, cursor, connectionType) {
4415
- const port = this.canvas.graph.getPort(portId);
4416
- this.staticPortId = portId;
4415
+ grabPort(staticPortId, cursor, connectionType) {
4416
+ const port = this.canvas.graph.getPort(staticPortId);
4417
4417
  const portRect = port.element.getBoundingClientRect();
4418
4418
  const portX = portRect.x + portRect.width / 2;
4419
4419
  const portY = portRect.y + portRect.height / 2;
@@ -4431,13 +4431,20 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
4431
4431
  portCoords: portPoint,
4432
4432
  portDirection: port.direction
4433
4433
  };
4434
+ const isDirect = connectionType === "direct";
4435
+ this.edgeInProgress = {
4436
+ staticPortId,
4437
+ isDirect
4438
+ };
4434
4439
  const draggingParams = {
4435
4440
  overlayNodeId: OverlayId.DraggingNodeId,
4436
4441
  portCoords: cursorPoint,
4437
- portDirection: this.params.dragPortDirection
4442
+ portDirection: this.params.draggingPortDirectionResolver.resolve({
4443
+ cursor,
4444
+ ...this.edgeInProgress
4445
+ }) ?? port.direction
4438
4446
  };
4439
- this.isTargetDragging = connectionType === "direct";
4440
- const [sourceParams, targetParams] = this.isTargetDragging ? [staticParams, draggingParams] : [draggingParams, staticParams];
4447
+ const [sourceParams, targetParams] = isDirect ? [staticParams, draggingParams] : [draggingParams, staticParams];
4441
4448
  this.overlayCanvas.addNode(createAddNodeOverlayRequest(sourceParams));
4442
4449
  this.overlayCanvas.addNode(createAddNodeOverlayRequest(targetParams));
4443
4450
  this.overlayCanvas.addEdge({
@@ -4447,22 +4454,25 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
4447
4454
  });
4448
4455
  }
4449
4456
  resetDragState() {
4450
- this.staticPortId = null;
4451
- this.isTargetDragging = true;
4457
+ this.edgeInProgress = null;
4452
4458
  this.overlayCanvas.clear();
4453
4459
  }
4454
4460
  tryCreateConnection(cursor) {
4455
- const draggingPortId = findPortAtPoint(this.canvas.graph, cursor);
4456
- if (draggingPortId === null) {
4457
- this.handleEdgeCreationInterrupted();
4461
+ const targetPortId = findPortAtPoint(this.canvas.graph, cursor);
4462
+ if (targetPortId === null) {
4463
+ this.params.onEdgeCreationInterrupted(this.edgeInProgress);
4458
4464
  return;
4459
4465
  }
4460
- const staticPortId = this.staticPortId;
4461
- const sourceId = this.isTargetDragging ? staticPortId : draggingPortId;
4462
- const targetId = this.isTargetDragging ? draggingPortId : staticPortId;
4463
- const request = { from: sourceId, to: targetId };
4464
- const processedRequest = this.params.connectionPreprocessor(request);
4465
- if (processedRequest !== null) {
4466
+ const request = resolveCreateEdgeRequest(
4467
+ this.edgeInProgress,
4468
+ targetPortId
4469
+ );
4470
+ const connectionAllowed = this.params.connectionAllowedVerifier(request);
4471
+ const processedRequest = this.params.connectionPreprocessor({
4472
+ from: request.from,
4473
+ to: request.to
4474
+ });
4475
+ if (connectionAllowed && processedRequest !== null) {
4466
4476
  this.canvas.graph.onAfterEdgeAdded.subscribe(this.onEdgeCreated);
4467
4477
  this.canvas.addEdge(processedRequest);
4468
4478
  this.canvas.graph.onAfterEdgeAdded.unsubscribe(this.onEdgeCreated);
@@ -4470,30 +4480,26 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
4470
4480
  this.params.onEdgeCreationPrevented(request);
4471
4481
  }
4472
4482
  }
4473
- moveDraggingPort(dragPoint) {
4483
+ moveDraggingPort(cursor) {
4474
4484
  const canvasRect = this.overlayLayer.getBoundingClientRect();
4475
4485
  const nodeContentCoords = this.canvas.viewport.createContentCoords({
4476
- x: dragPoint.x - canvasRect.x,
4477
- y: dragPoint.y - canvasRect.y
4486
+ x: cursor.x - canvasRect.x,
4487
+ y: cursor.y - canvasRect.y
4488
+ });
4489
+ const direction = this.params.draggingPortDirectionResolver.resolve({
4490
+ cursor,
4491
+ ...this.edgeInProgress
4478
4492
  });
4479
4493
  this.overlayCanvas.updateNode(OverlayId.DraggingNodeId, {
4480
4494
  x: nodeContentCoords.x,
4481
4495
  y: nodeContentCoords.y
4482
- });
4483
- }
4484
- handleEdgeCreationInterrupted() {
4485
- const staticPortId = this.staticPortId;
4486
- this.params.onEdgeCreationInterrupted({
4487
- staticPortId,
4488
- isDirect: this.isTargetDragging
4489
- });
4496
+ }).updatePort(OverlayId.DraggingNodeId, { direction });
4490
4497
  }
4491
4498
  }
4492
4499
  class UserDraggableEdgesConfigurator {
4493
4500
  constructor(canvas, overlayLayer, viewportStore, window2, pointInsideVerifier, params) {
4494
4501
  __publicField(this, "overlayCanvas");
4495
- __publicField(this, "staticPortId", null);
4496
- __publicField(this, "isTargetDragging", true);
4502
+ __publicField(this, "edgeInProgress", null);
4497
4503
  __publicField(this, "draggingEdgePayload", null);
4498
4504
  __publicField(this, "onEdgeReattached", (edgeId) => {
4499
4505
  this.params.onAfterEdgeReattached(edgeId);
@@ -4509,38 +4515,36 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
4509
4515
  this.viewportStore,
4510
4516
  this.window
4511
4517
  );
4518
+ const draggablePortsParams = {
4519
+ mouseDownEventVerifier: this.params.mouseDownEventVerifier,
4520
+ mouseUpEventVerifier: this.params.mouseUpEventVerifier,
4521
+ onPointerDownVerifier: (portId, cursor) => {
4522
+ return this.tryStartEdgeDragging(portId, cursor);
4523
+ },
4524
+ onPointerMove: (cursor) => {
4525
+ this.moveDraggingPort(cursor);
4526
+ },
4527
+ onPointerUp: (cursor) => {
4528
+ this.tryCreateConnection(cursor);
4529
+ this.resetDragState();
4530
+ },
4531
+ onPointerOutside: () => {
4532
+ const edge = this.draggingEdgePayload;
4533
+ this.resetDragState();
4534
+ this.params.onEdgeReattachInterrupted({
4535
+ id: edge.id,
4536
+ from: edge.from,
4537
+ to: edge.to,
4538
+ shape: edge.shape,
4539
+ priority: edge.priority
4540
+ });
4541
+ }
4542
+ };
4512
4543
  DraggablePortsConfigurator.configure(
4513
4544
  this.canvas,
4514
4545
  this.window,
4515
4546
  this.pointInsideVerifier,
4516
- {
4517
- mouseDownEventVerifier: this.params.mouseDownEventVerifier,
4518
- mouseUpEventVerifier: this.params.mouseUpEventVerifier,
4519
- onStopDrag: () => {
4520
- this.resetDragState();
4521
- },
4522
- onPortPointerDown: (portId, cursor) => {
4523
- return this.tryStartEdgeDragging(portId, cursor);
4524
- },
4525
- onPointerMove: (cursor) => {
4526
- this.moveDraggingPort(cursor);
4527
- },
4528
- onPointerMoveOutside: () => {
4529
- const edge = this.draggingEdgePayload;
4530
- queueMicrotask(() => {
4531
- this.params.onEdgeReattachInterrupted({
4532
- id: edge.id,
4533
- from: edge.from,
4534
- to: edge.to,
4535
- shape: edge.shape,
4536
- priority: edge.priority
4537
- });
4538
- });
4539
- },
4540
- onPointerUp: (cursor) => {
4541
- this.tryCreateConnection(cursor);
4542
- }
4543
- }
4547
+ draggablePortsParams
4544
4548
  );
4545
4549
  }
4546
4550
  static configure(canvas, overlayLayer, viewportStore, win, pointInsideVerifier, params) {
@@ -4555,15 +4559,14 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
4555
4559
  }
4556
4560
  tryStartEdgeDragging(portId, cursor) {
4557
4561
  const edgeId = this.params.draggingEdgeResolver(portId);
4558
- if (edgeId === null || !this.canvas.graph.hasEdge(edgeId)) {
4562
+ if (edgeId === null) {
4559
4563
  return false;
4560
4564
  }
4561
4565
  const edge = this.canvas.graph.getEdge(edgeId);
4562
4566
  const isSourceDragging = portId === edge.from;
4563
- const isTargetDragging = portId === edge.to;
4567
+ const isDirect = portId === edge.to;
4564
4568
  const staticPortId = isSourceDragging ? edge.to : edge.from;
4565
- this.staticPortId = staticPortId;
4566
- this.isTargetDragging = isTargetDragging;
4569
+ this.edgeInProgress = { staticPortId, isDirect };
4567
4570
  const draggingPort = this.canvas.graph.getPort(portId);
4568
4571
  const staticPort = this.canvas.graph.getPort(staticPortId);
4569
4572
  const staticRect = staticPort.element.getBoundingClientRect();
@@ -4593,12 +4596,16 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
4593
4596
  portCoords: staticPoint,
4594
4597
  portDirection: staticPort.direction
4595
4598
  };
4599
+ const direction = this.params.draggingPortDirectionResolver.resolve({
4600
+ cursor,
4601
+ ...this.edgeInProgress
4602
+ });
4596
4603
  const draggingParams = {
4597
4604
  overlayNodeId: OverlayId.DraggingNodeId,
4598
4605
  portCoords: draggingPoint,
4599
- portDirection: draggingPort.direction
4606
+ portDirection: direction ?? draggingPort.direction
4600
4607
  };
4601
- const [sourceParams, targetParams] = this.isTargetDragging ? [staticParams, draggingParams] : [draggingParams, staticParams];
4608
+ const [sourceParams, targetParams] = isDirect ? [staticParams, draggingParams] : [draggingParams, staticParams];
4602
4609
  this.overlayCanvas.addNode(createAddNodeOverlayRequest(sourceParams));
4603
4610
  this.overlayCanvas.addNode(createAddNodeOverlayRequest(targetParams));
4604
4611
  const overlayEdgeShape = this.params.draggingEdgeShapeFactory !== null ? this.params.draggingEdgeShapeFactory(OverlayId.EdgeId) : edge.shape;
@@ -4612,30 +4619,43 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
4612
4619
  }
4613
4620
  resetDragState() {
4614
4621
  this.draggingEdgePayload = null;
4615
- this.staticPortId = null;
4616
- this.isTargetDragging = true;
4622
+ this.edgeInProgress = null;
4617
4623
  this.overlayCanvas.clear();
4618
4624
  }
4619
- moveDraggingPort(dragPoint) {
4625
+ moveDraggingPort(cursor) {
4620
4626
  const canvasRect = this.overlayLayer.getBoundingClientRect();
4621
4627
  const nodeViewCoords = {
4622
- x: dragPoint.x - canvasRect.x,
4623
- y: dragPoint.y - canvasRect.y
4628
+ x: cursor.x - canvasRect.x,
4629
+ y: cursor.y - canvasRect.y
4624
4630
  };
4625
4631
  const nodeContentCoords = this.canvas.viewport.createContentCoords(nodeViewCoords);
4632
+ const direction = this.params.draggingPortDirectionResolver.resolve({
4633
+ cursor,
4634
+ ...this.edgeInProgress
4635
+ });
4626
4636
  this.overlayCanvas.updateNode(OverlayId.DraggingNodeId, {
4627
4637
  x: nodeContentCoords.x,
4628
4638
  y: nodeContentCoords.y
4629
- });
4639
+ }).updatePort(OverlayId.DraggingNodeId, { direction });
4630
4640
  }
4631
4641
  tryCreateConnection(cursor) {
4632
4642
  const draggingPortId = findPortAtPoint(this.canvas.graph, cursor);
4633
4643
  this.overlayCanvas.removeEdge(OverlayId.EdgeId);
4634
4644
  if (draggingPortId === null) {
4635
- this.handleEdgeReattachInterrupted();
4645
+ const edge2 = this.draggingEdgePayload;
4646
+ this.params.onEdgeReattachInterrupted({
4647
+ id: edge2.id,
4648
+ from: edge2.from,
4649
+ to: edge2.to,
4650
+ shape: edge2.shape,
4651
+ priority: edge2.priority
4652
+ });
4636
4653
  return;
4637
4654
  }
4638
- const [from, to] = this.isTargetDragging ? [this.staticPortId, draggingPortId] : [draggingPortId, this.staticPortId];
4655
+ const { from, to } = resolveCreateEdgeRequest(
4656
+ this.edgeInProgress,
4657
+ draggingPortId
4658
+ );
4639
4659
  const edge = this.draggingEdgePayload;
4640
4660
  const request = {
4641
4661
  id: edge.id,
@@ -4644,8 +4664,12 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
4644
4664
  shape: edge.shape,
4645
4665
  priority: edge.priority
4646
4666
  };
4667
+ const connectionAllowed = this.params.connectionAllowedVerifier({
4668
+ from,
4669
+ to
4670
+ });
4647
4671
  const processedRequest = this.params.connectionPreprocessor(request);
4648
- if (processedRequest !== null) {
4672
+ if (connectionAllowed && processedRequest !== null) {
4649
4673
  this.canvas.graph.onAfterEdgeAdded.subscribe(this.onEdgeReattached);
4650
4674
  this.canvas.addEdge(processedRequest);
4651
4675
  this.canvas.graph.onAfterEdgeAdded.unsubscribe(this.onEdgeReattached);
@@ -4660,16 +4684,6 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
4660
4684
  });
4661
4685
  }
4662
4686
  }
4663
- handleEdgeReattachInterrupted() {
4664
- const edge = this.draggingEdgePayload;
4665
- this.params.onEdgeReattachInterrupted({
4666
- id: edge.id,
4667
- from: edge.from,
4668
- to: edge.to,
4669
- shape: edge.shape,
4670
- priority: edge.priority
4671
- });
4672
- }
4673
4687
  }
4674
4688
  class ManualLayoutApplicationStrategyConfigurator {
4675
4689
  constructor(applier, trigger) {
@@ -4721,6 +4735,26 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
4721
4735
  this.defererFn(this.apply);
4722
4736
  }
4723
4737
  }
4738
+ class LayoutApplier {
4739
+ constructor(canvas, layoutAlgorithm, params) {
4740
+ this.canvas = canvas;
4741
+ this.layoutAlgorithm = layoutAlgorithm;
4742
+ this.params = params;
4743
+ }
4744
+ apply() {
4745
+ const coords = this.layoutAlgorithm.calculateCoordinates({
4746
+ graph: this.canvas.graph,
4747
+ viewport: this.canvas.viewport
4748
+ });
4749
+ this.params.onBeforeApplied();
4750
+ coords.forEach((point, nodeId) => {
4751
+ if (!this.params.staticNodeResolver(nodeId)) {
4752
+ this.canvas.updateNode(nodeId, point);
4753
+ }
4754
+ });
4755
+ this.params.onAfterApplied();
4756
+ }
4757
+ }
4724
4758
  class LayoutConfigurator {
4725
4759
  static configure(canvas, params) {
4726
4760
  const strategy = params.applyOn;
@@ -4766,6 +4800,27 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
4766
4800
  this.win.requestAnimationFrame(this.step);
4767
4801
  }
4768
4802
  }
4803
+ class AnimatedLayoutApplier {
4804
+ constructor(canvas, layoutAlgorithm, params) {
4805
+ this.canvas = canvas;
4806
+ this.layoutAlgorithm = layoutAlgorithm;
4807
+ this.params = params;
4808
+ }
4809
+ apply(dt) {
4810
+ const coords = this.layoutAlgorithm.calculateNextCoordinates({
4811
+ graph: this.canvas.graph,
4812
+ viewport: this.canvas.viewport,
4813
+ dt
4814
+ });
4815
+ this.params.onBeforeApplied();
4816
+ coords.forEach((point, nodeId) => {
4817
+ if (!this.params.staticNodeResolver(nodeId)) {
4818
+ this.canvas.updateNode(nodeId, point);
4819
+ }
4820
+ });
4821
+ this.params.onAfterApplied();
4822
+ }
4823
+ }
4769
4824
  class AnimatedLayoutConfigurator {
4770
4825
  constructor(canvas, params, win) {
4771
4826
  __publicField(this, "applier");
@@ -4895,9 +4950,6 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
4895
4950
  __publicField(this, "configurator");
4896
4951
  __publicField(this, "onCanvasSelected");
4897
4952
  __publicField(this, "selectionHandledTag", selectionHandled);
4898
- __publicField(this, "restore", () => {
4899
- this.configurator.disable(this.element);
4900
- });
4901
4953
  this.canvas = canvas;
4902
4954
  this.element = element;
4903
4955
  this.window = window2;
@@ -4919,7 +4971,9 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
4919
4971
  }
4920
4972
  );
4921
4973
  this.configurator.enable(this.element);
4922
- this.canvas.onBeforeDestroy.subscribe(this.restore);
4974
+ this.canvas.onBeforeDestroy.subscribe(() => {
4975
+ this.configurator.disable(this.element);
4976
+ });
4923
4977
  }
4924
4978
  static configure(canvas, element, window2, pointInsideVerifier, eventTagger, params) {
4925
4979
  new UserSelectableCanvasConfigurator(
@@ -4972,22 +5026,119 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
4972
5026
  this.element.removeChild(this.host);
4973
5027
  }
4974
5028
  }
5029
+ const forceDirectedDefaults = Object.freeze({
5030
+ seed: "HTMLGraph is awesome",
5031
+ maxTimeDeltaSec: 0.01,
5032
+ nodeCharge: 1e5,
5033
+ nodeMass: 1,
5034
+ edgeEquilibriumLength: 300,
5035
+ edgeStiffness: 1e3,
5036
+ dtSec: 0.01,
5037
+ maxIterations: 1e3,
5038
+ convergenceVelocity: 10,
5039
+ maxForce: 1e7,
5040
+ nodeForceCoefficient: 1,
5041
+ barnesHutAreaRadiusThreshold: 0.01,
5042
+ barnesHutTheta: 1
5043
+ });
5044
+ const selectionDefaults = Object.freeze({
5045
+ mouseDownEventVerifier: (event) => event.button === 0,
5046
+ mouseUpEventVerifier: (event) => event.button === 0,
5047
+ movementThreshold: 10
5048
+ });
5049
+ const noopFn = () => {
5050
+ };
5051
+ const resolveDraggingPortDirectionResolver = (config, graph, connectionAllowedVerifier) => {
5052
+ if (config === "closest-connectable-port") {
5053
+ return new ClosestConnectablePortDraggingPortDirectionResolver(
5054
+ graph,
5055
+ connectionAllowedVerifier
5056
+ );
5057
+ }
5058
+ return new ConstantDraggingPortDirectionResolver(config);
5059
+ };
5060
+ const resolveEdgeShapeFactory = (config) => {
5061
+ if (typeof config === "function") {
5062
+ return config;
5063
+ }
5064
+ switch (config.type) {
5065
+ case "straight":
5066
+ return () => new StraightEdgeShape({
5067
+ color: config.color,
5068
+ width: config.width,
5069
+ arrowLength: config.arrowLength,
5070
+ arrowOffset: config.arrowOffset,
5071
+ arrowRenderer: config.arrowRenderer,
5072
+ hasSourceArrow: config.hasSourceArrow,
5073
+ hasTargetArrow: config.hasTargetArrow,
5074
+ cycleSquareSide: config.cycleSquareSide,
5075
+ roundness: config.roundness,
5076
+ detourDistance: config.detourDistance,
5077
+ detourDirection: config.detourDirection
5078
+ });
5079
+ case "horizontal":
5080
+ return () => new HorizontalEdgeShape({
5081
+ color: config.color,
5082
+ width: config.width,
5083
+ arrowLength: config.arrowLength,
5084
+ arrowOffset: config.arrowOffset,
5085
+ arrowRenderer: config.arrowRenderer,
5086
+ hasSourceArrow: config.hasSourceArrow,
5087
+ hasTargetArrow: config.hasTargetArrow,
5088
+ cycleSquareSide: config.cycleSquareSide,
5089
+ roundness: config.roundness,
5090
+ detourDistance: config.detourDistance
5091
+ });
5092
+ case "vertical":
5093
+ return () => new VerticalEdgeShape({
5094
+ color: config.color,
5095
+ width: config.width,
5096
+ arrowLength: config.arrowLength,
5097
+ arrowOffset: config.arrowOffset,
5098
+ arrowRenderer: config.arrowRenderer,
5099
+ hasSourceArrow: config.hasSourceArrow,
5100
+ hasTargetArrow: config.hasTargetArrow,
5101
+ cycleSquareSide: config.cycleSquareSide,
5102
+ roundness: config.roundness,
5103
+ detourDistance: config.detourDistance
5104
+ });
5105
+ case "direct":
5106
+ return () => new DirectEdgeShape({
5107
+ color: config.color,
5108
+ width: config.width,
5109
+ arrowLength: config.arrowLength,
5110
+ arrowRenderer: config.arrowRenderer,
5111
+ hasSourceArrow: config.hasSourceArrow,
5112
+ hasTargetArrow: config.hasTargetArrow,
5113
+ sourceOffset: config.sourceOffset,
5114
+ targetOffset: config.targetOffset
5115
+ });
5116
+ default:
5117
+ return () => new BezierEdgeShape({
5118
+ color: config.color,
5119
+ width: config.width,
5120
+ arrowLength: config.arrowLength,
5121
+ arrowRenderer: config.arrowRenderer,
5122
+ hasSourceArrow: config.hasSourceArrow,
5123
+ hasTargetArrow: config.hasTargetArrow,
5124
+ cycleRadius: config.cycleRadius,
5125
+ smallCycleRadius: config.smallCycleRadius,
5126
+ curvature: config.curvature,
5127
+ detourDistance: config.detourDistance,
5128
+ detourDirection: config.detourDirection
5129
+ });
5130
+ }
5131
+ };
4975
5132
  const createDraggableNodesParams = (config) => {
4976
5133
  var _a, _b, _c, _d, _e, _f;
4977
- const onNodeDragStarted = ((_a = config.events) == null ? void 0 : _a.onNodeDragStarted) ?? (() => {
4978
- });
4979
- const onNodeDrag = ((_b = config.events) == null ? void 0 : _b.onNodeDrag) ?? (() => {
4980
- });
4981
5134
  const nodeDragVerifier = config.nodeDragVerifier ?? (() => true);
4982
- const onNodeDragFinished = ((_c = config.events) == null ? void 0 : _c.onNodeDragFinished) ?? (() => {
4983
- });
4984
5135
  const moveOnTop = config.moveOnTop !== false;
4985
5136
  const moveEdgesOnTop = config.moveEdgesOnTop !== false && moveOnTop;
4986
- const cursor = (_d = config.mouse) == null ? void 0 : _d.dragCursor;
5137
+ const cursor = (_a = config.mouse) == null ? void 0 : _a.dragCursor;
4987
5138
  const dragCursor = cursor !== void 0 ? cursor : "grab";
4988
- const defaultMouseDownEventVerifier = (_e = config.mouse) == null ? void 0 : _e.mouseDownEventVerifier;
5139
+ const defaultMouseDownEventVerifier = (_b = config.mouse) == null ? void 0 : _b.mouseDownEventVerifier;
4989
5140
  const mouseDownEventVerifier = defaultMouseDownEventVerifier !== void 0 ? defaultMouseDownEventVerifier : (event) => event.button === 0;
4990
- const defaultMouseUpEventVerifier = (_f = config.mouse) == null ? void 0 : _f.mouseUpEventVerifier;
5141
+ const defaultMouseUpEventVerifier = (_c = config.mouse) == null ? void 0 : _c.mouseUpEventVerifier;
4991
5142
  const mouseUpEventVerifier = defaultMouseUpEventVerifier !== void 0 ? defaultMouseUpEventVerifier : (event) => event.button === 0;
4992
5143
  return {
4993
5144
  moveOnTop,
@@ -4996,10 +5147,10 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
4996
5147
  gridSize: config.gridSize ?? null,
4997
5148
  mouseDownEventVerifier,
4998
5149
  mouseUpEventVerifier,
4999
- onNodeDragStarted,
5000
- onNodeDrag,
5150
+ onNodeDragStarted: ((_d = config.events) == null ? void 0 : _d.onNodeDragStarted) ?? noopFn,
5151
+ onNodeDrag: ((_e = config.events) == null ? void 0 : _e.onNodeDrag) ?? noopFn,
5001
5152
  nodeDragVerifier,
5002
- onNodeDragFinished
5153
+ onNodeDragFinished: ((_f = config.events) == null ? void 0 : _f.onNodeDragFinished) ?? noopFn
5003
5154
  };
5004
5155
  };
5005
5156
  const createShiftLimitTransformPreprocessor = (preprocessorParams) => {
@@ -5117,34 +5268,26 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
5117
5268
  };
5118
5269
  }
5119
5270
  const shiftCursor = ((_b = transformConfig == null ? void 0 : transformConfig.shift) == null ? void 0 : _b.cursor) !== void 0 ? transformConfig.shift.cursor : "grab";
5120
- const onBeforeTransformStarted = ((_c = transformConfig == null ? void 0 : transformConfig.events) == null ? void 0 : _c.onBeforeTransformChange) ?? (() => {
5121
- });
5122
- const onTransformFinished = ((_d = transformConfig == null ? void 0 : transformConfig.events) == null ? void 0 : _d.onTransformChange) ?? (() => {
5123
- });
5124
- const defaultMouseDownEventVerifier = (_e = transformConfig == null ? void 0 : transformConfig.shift) == null ? void 0 : _e.mouseDownEventVerifier;
5271
+ const defaultMouseDownEventVerifier = (_c = transformConfig == null ? void 0 : transformConfig.shift) == null ? void 0 : _c.mouseDownEventVerifier;
5125
5272
  const mouseDownEventVerifier = defaultMouseDownEventVerifier !== void 0 ? defaultMouseDownEventVerifier : (event) => event.button === 0;
5126
- const defaultMouseUpEventVerifier = (_f = transformConfig == null ? void 0 : transformConfig.shift) == null ? void 0 : _f.mouseUpEventVerifier;
5273
+ const defaultMouseUpEventVerifier = (_d = transformConfig == null ? void 0 : transformConfig.shift) == null ? void 0 : _d.mouseUpEventVerifier;
5127
5274
  const mouseUpEventVerifier = defaultMouseUpEventVerifier !== void 0 ? defaultMouseUpEventVerifier : (event) => event.button === 0;
5128
- const defaultMouseWheelEventVerifier = (_g = transformConfig == null ? void 0 : transformConfig.scale) == null ? void 0 : _g.mouseWheelEventVerifier;
5275
+ const defaultMouseWheelEventVerifier = (_e = transformConfig == null ? void 0 : transformConfig.scale) == null ? void 0 : _e.mouseWheelEventVerifier;
5129
5276
  const mouseWheelEventVerifier = defaultMouseWheelEventVerifier !== void 0 ? defaultMouseWheelEventVerifier : () => true;
5130
5277
  return {
5131
5278
  wheelSensitivity,
5132
- onTransformStarted: ((_h = transformConfig == null ? void 0 : transformConfig.events) == null ? void 0 : _h.onTransformStarted) ?? (() => {
5133
- }),
5134
- onTransformFinished: ((_i = transformConfig == null ? void 0 : transformConfig.events) == null ? void 0 : _i.onTransformFinished) ?? (() => {
5135
- }),
5136
- onBeforeTransformChange: onBeforeTransformStarted,
5137
- onTransformChange: onTransformFinished,
5279
+ onTransformStarted: ((_f = transformConfig == null ? void 0 : transformConfig.events) == null ? void 0 : _f.onTransformStarted) ?? noopFn,
5280
+ onTransformFinished: ((_g = transformConfig == null ? void 0 : transformConfig.events) == null ? void 0 : _g.onTransformFinished) ?? noopFn,
5281
+ onBeforeTransformChange: ((_h = transformConfig == null ? void 0 : transformConfig.events) == null ? void 0 : _h.onBeforeTransformChange) ?? noopFn,
5282
+ onTransformChange: ((_i = transformConfig == null ? void 0 : transformConfig.events) == null ? void 0 : _i.onTransformChange) ?? noopFn,
5138
5283
  transformPreprocessor,
5139
5284
  shiftCursor,
5140
5285
  mouseDownEventVerifier,
5141
5286
  mouseUpEventVerifier,
5142
5287
  mouseWheelEventVerifier,
5143
5288
  scaleWheelFinishTimeout: ((_j = transformConfig == null ? void 0 : transformConfig.scale) == null ? void 0 : _j.wheelFinishTimeout) ?? 500,
5144
- onResizeTransformStarted: ((_k = transformConfig == null ? void 0 : transformConfig.events) == null ? void 0 : _k.onResizeTransformStarted) ?? (() => {
5145
- }),
5146
- onResizeTransformFinished: ((_l = transformConfig == null ? void 0 : transformConfig.events) == null ? void 0 : _l.onResizeTransformFinished) ?? (() => {
5147
- })
5289
+ onResizeTransformStarted: ((_k = transformConfig == null ? void 0 : transformConfig.events) == null ? void 0 : _k.onResizeTransformStarted) ?? noopFn,
5290
+ onResizeTransformFinished: ((_l = transformConfig == null ? void 0 : transformConfig.events) == null ? void 0 : _l.onResizeTransformFinished) ?? noopFn
5148
5291
  };
5149
5292
  };
5150
5293
  const createContent = (radius, color) => {
@@ -5180,106 +5323,41 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
5180
5323
  maxViewportScale: backgroundConfig.maxViewportScale ?? 10
5181
5324
  };
5182
5325
  };
5183
- const resolveEdgeShapeFactory = (config) => {
5184
- if (typeof config === "function") {
5185
- return config;
5186
- }
5187
- switch (config.type) {
5188
- case "straight":
5189
- return () => new StraightEdgeShape({
5190
- color: config.color,
5191
- width: config.width,
5192
- arrowLength: config.arrowLength,
5193
- arrowOffset: config.arrowOffset,
5194
- arrowRenderer: config.arrowRenderer,
5195
- hasSourceArrow: config.hasSourceArrow,
5196
- hasTargetArrow: config.hasTargetArrow,
5197
- cycleSquareSide: config.cycleSquareSide,
5198
- roundness: config.roundness,
5199
- detourDistance: config.detourDistance,
5200
- detourDirection: config.detourDirection
5201
- });
5202
- case "horizontal":
5203
- return () => new HorizontalEdgeShape({
5204
- color: config.color,
5205
- width: config.width,
5206
- arrowLength: config.arrowLength,
5207
- arrowOffset: config.arrowOffset,
5208
- arrowRenderer: config.arrowRenderer,
5209
- hasSourceArrow: config.hasSourceArrow,
5210
- hasTargetArrow: config.hasTargetArrow,
5211
- cycleSquareSide: config.cycleSquareSide,
5212
- roundness: config.roundness,
5213
- detourDistance: config.detourDistance
5214
- });
5215
- case "vertical":
5216
- return () => new VerticalEdgeShape({
5217
- color: config.color,
5218
- width: config.width,
5219
- arrowLength: config.arrowLength,
5220
- arrowOffset: config.arrowOffset,
5221
- arrowRenderer: config.arrowRenderer,
5222
- hasSourceArrow: config.hasSourceArrow,
5223
- hasTargetArrow: config.hasTargetArrow,
5224
- cycleSquareSide: config.cycleSquareSide,
5225
- roundness: config.roundness,
5226
- detourDistance: config.detourDistance
5227
- });
5228
- case "direct":
5229
- return () => new DirectEdgeShape({
5230
- color: config.color,
5231
- width: config.width,
5232
- arrowLength: config.arrowLength,
5233
- arrowRenderer: config.arrowRenderer,
5234
- hasSourceArrow: config.hasSourceArrow,
5235
- hasTargetArrow: config.hasTargetArrow,
5236
- sourceOffset: config.sourceOffset,
5237
- targetOffset: config.targetOffset
5238
- });
5239
- default:
5240
- return () => new BezierEdgeShape({
5241
- color: config.color,
5242
- width: config.width,
5243
- arrowLength: config.arrowLength,
5244
- arrowRenderer: config.arrowRenderer,
5245
- hasSourceArrow: config.hasSourceArrow,
5246
- hasTargetArrow: config.hasTargetArrow,
5247
- cycleRadius: config.cycleRadius,
5248
- smallCycleRadius: config.smallCycleRadius,
5249
- curvature: config.curvature,
5250
- detourDistance: config.detourDistance,
5251
- detourDirection: config.detourDirection
5252
- });
5253
- }
5254
- };
5255
- const createConnectablePortsParams = (config, defaultEdgeShapeFactory, defaultDragPortDirection) => {
5326
+ const defaults$3 = Object.freeze({
5327
+ connectionTypeResolver: () => "direct",
5328
+ connectionPreprocessor: (request) => request,
5329
+ connectionAllowedVerifier: () => true,
5330
+ mouseEventVerifier: (event) => event.button === 0
5331
+ });
5332
+ const createConnectablePortsParams = (config, defaultEdgeShapeFactory, graph) => {
5256
5333
  var _a, _b, _c;
5257
- const defaultConnectionTypeResolver = () => "direct";
5258
- const defaultConnectionPreprocessor = (request) => request;
5259
- const defaultMouseEventVerifier = (event) => event.button === 0;
5260
- const defaultOnAfterEdgeCreated = () => {
5261
- };
5262
- const defaultOnAfterEdgeConnectionPrevented = () => {
5263
- };
5264
- const defaultOnAfterEdgeConnectionInterrupted = () => {
5265
- };
5334
+ const connectionAllowedVerifier = config.connectionAllowedVerifier ?? defaults$3.connectionAllowedVerifier;
5266
5335
  return {
5267
- connectionTypeResolver: config.connectionTypeResolver ?? defaultConnectionTypeResolver,
5268
- connectionPreprocessor: config.connectionPreprocessor ?? defaultConnectionPreprocessor,
5269
- mouseDownEventVerifier: config.mouseDownEventVerifier ?? defaultMouseEventVerifier,
5270
- mouseUpEventVerifier: config.mouseUpEventVerifier ?? defaultMouseEventVerifier,
5271
- onAfterEdgeCreated: ((_a = config.events) == null ? void 0 : _a.onAfterEdgeCreated) ?? defaultOnAfterEdgeCreated,
5272
- onEdgeCreationInterrupted: ((_b = config.events) == null ? void 0 : _b.onEdgeCreationInterrupted) ?? defaultOnAfterEdgeConnectionInterrupted,
5273
- onEdgeCreationPrevented: ((_c = config.events) == null ? void 0 : _c.onEdgeCreationPrevented) ?? defaultOnAfterEdgeConnectionPrevented,
5274
- dragPortDirection: config.dragPortDirection ?? defaultDragPortDirection,
5275
- edgeShapeFactory: config.edgeShape !== void 0 ? resolveEdgeShapeFactory(config.edgeShape) : defaultEdgeShapeFactory
5336
+ connectionTypeResolver: config.connectionTypeResolver ?? defaults$3.connectionTypeResolver,
5337
+ connectionAllowedVerifier,
5338
+ draggingPortDirectionResolver: resolveDraggingPortDirectionResolver(
5339
+ config.dragPortDirection,
5340
+ graph,
5341
+ connectionAllowedVerifier
5342
+ ),
5343
+ edgeShapeFactory: config.edgeShape !== void 0 ? resolveEdgeShapeFactory(config.edgeShape) : defaultEdgeShapeFactory,
5344
+ connectionPreprocessor: config.connectionPreprocessor ?? defaults$3.connectionPreprocessor,
5345
+ mouseDownEventVerifier: config.mouseDownEventVerifier ?? defaults$3.mouseEventVerifier,
5346
+ mouseUpEventVerifier: config.mouseUpEventVerifier ?? defaults$3.mouseEventVerifier,
5347
+ onAfterEdgeCreated: ((_a = config.events) == null ? void 0 : _a.onAfterEdgeCreated) ?? noopFn,
5348
+ onEdgeCreationInterrupted: ((_b = config.events) == null ? void 0 : _b.onEdgeCreationInterrupted) ?? noopFn,
5349
+ onEdgeCreationPrevented: ((_c = config.events) == null ? void 0 : _c.onEdgeCreationPrevented) ?? noopFn
5276
5350
  };
5277
5351
  };
5352
+ const defaults$2 = Object.freeze({
5353
+ connectionAllowedVerifier: () => true,
5354
+ connectionPreprocessor: (request) => request,
5355
+ // TODO: remove ctrl key
5356
+ mouseDownEventVerifier: (event) => event.button === 0 && event.ctrlKey,
5357
+ mouseUpEventVerifier: (event) => event.button === 0
5358
+ });
5278
5359
  const createDraggableEdgeParams = (config, graph) => {
5279
5360
  var _a, _b, _c;
5280
- const defaultConnectionPreprocessor = (request) => request;
5281
- const defaultMouseDownEventVerifier = (event) => event.button === 0 && event.ctrlKey;
5282
- const defaultMouseUpEventVerifier = (event) => event.button === 0;
5283
5361
  const defaultDraggingEdgeResolver = (portId) => {
5284
5362
  const edgeIds = graph.getPortAdjacentEdgeIds(portId);
5285
5363
  if (edgeIds.length > 0) {
@@ -5288,21 +5366,22 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
5288
5366
  return null;
5289
5367
  }
5290
5368
  };
5291
- const defaultOnAfterEdgeReattached = () => {
5292
- };
5293
- const defaultOnAfterEdgeReattachPrevented = () => {
5294
- };
5295
- const defaultOnAfterEdgeReattachInterrupted = () => {
5296
- };
5369
+ const connectionAllowedVerifier = config.connectionAllowedVerifier ?? defaults$2.connectionAllowedVerifier;
5297
5370
  return {
5298
- connectionPreprocessor: config.connectionPreprocessor ?? defaultConnectionPreprocessor,
5299
- mouseDownEventVerifier: config.mouseDownEventVerifier ?? defaultMouseDownEventVerifier,
5300
- mouseUpEventVerifier: config.mouseUpEventVerifier ?? defaultMouseUpEventVerifier,
5371
+ connectionPreprocessor: config.connectionPreprocessor ?? defaults$2.connectionPreprocessor,
5372
+ connectionAllowedVerifier,
5373
+ mouseDownEventVerifier: config.mouseDownEventVerifier ?? defaults$2.mouseDownEventVerifier,
5374
+ mouseUpEventVerifier: config.mouseUpEventVerifier ?? defaults$2.mouseUpEventVerifier,
5301
5375
  draggingEdgeResolver: config.draggingEdgeResolver ?? defaultDraggingEdgeResolver,
5302
5376
  draggingEdgeShapeFactory: config.draggingEdgeShape !== void 0 ? resolveEdgeShapeFactory(config.draggingEdgeShape) : null,
5303
- onAfterEdgeReattached: ((_a = config.events) == null ? void 0 : _a.onAfterEdgeReattached) ?? defaultOnAfterEdgeReattached,
5304
- onEdgeReattachInterrupted: ((_b = config.events) == null ? void 0 : _b.onEdgeReattachInterrupted) ?? defaultOnAfterEdgeReattachInterrupted,
5305
- onEdgeReattachPrevented: ((_c = config.events) == null ? void 0 : _c.onEdgeReattachPrevented) ?? defaultOnAfterEdgeReattachPrevented
5377
+ onAfterEdgeReattached: ((_a = config.events) == null ? void 0 : _a.onAfterEdgeReattached) ?? noopFn,
5378
+ onEdgeReattachInterrupted: ((_b = config.events) == null ? void 0 : _b.onEdgeReattachInterrupted) ?? noopFn,
5379
+ onEdgeReattachPrevented: ((_c = config.events) == null ? void 0 : _c.onEdgeReattachPrevented) ?? noopFn,
5380
+ draggingPortDirectionResolver: resolveDraggingPortDirectionResolver(
5381
+ config.dragPortDirection,
5382
+ graph,
5383
+ connectionAllowedVerifier
5384
+ )
5306
5385
  };
5307
5386
  };
5308
5387
  const createVirtualScrollParams = (config) => {
@@ -5314,10 +5393,8 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
5314
5393
  const createVirtualScrollHtmlViewParams = (config) => {
5315
5394
  var _a, _b;
5316
5395
  return {
5317
- onAfterNodeDetached: ((_a = config == null ? void 0 : config.events) == null ? void 0 : _a.onAfterNodeDetached) ?? (() => {
5318
- }),
5319
- onBeforeNodeAttached: ((_b = config == null ? void 0 : config.events) == null ? void 0 : _b.onBeforeNodeAttached) ?? (() => {
5320
- })
5396
+ onAfterNodeDetached: ((_a = config == null ? void 0 : config.events) == null ? void 0 : _a.onAfterNodeDetached) ?? noopFn,
5397
+ onBeforeNodeAttached: ((_b = config == null ? void 0 : config.events) == null ? void 0 : _b.onBeforeNodeAttached) ?? noopFn
5321
5398
  };
5322
5399
  };
5323
5400
  class CanvasBuilderError extends Error {
@@ -6328,26 +6405,6 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
6328
6405
  return (t >>> 0) / 4294967296;
6329
6406
  };
6330
6407
  };
6331
- const forceDirectedDefaults = Object.freeze({
6332
- seed: "HTMLGraph is awesome",
6333
- maxTimeDeltaSec: 0.01,
6334
- nodeCharge: 1e5,
6335
- nodeMass: 1,
6336
- edgeEquilibriumLength: 300,
6337
- edgeStiffness: 1e3,
6338
- dtSec: 0.01,
6339
- maxIterations: 1e3,
6340
- convergenceVelocity: 10,
6341
- maxForce: 1e7,
6342
- nodeForceCoefficient: 1,
6343
- barnesHutAreaRadiusThreshold: 0.01,
6344
- barnesHutTheta: 1
6345
- });
6346
- const selectionDefaults = Object.freeze({
6347
- mouseDownEventVerifier: (event) => event.button === 0,
6348
- mouseUpEventVerifier: (event) => event.button === 0,
6349
- movementThreshold: 10
6350
- });
6351
6408
  const resolveAnimatedLayoutAlgorithm = (config) => {
6352
6409
  var _a, _b;
6353
6410
  switch (config == null ? void 0 : config.type) {
@@ -6374,11 +6431,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
6374
6431
  }
6375
6432
  };
6376
6433
  const defaults$1 = {
6377
- staticNodeResolver: () => false,
6378
- onBeforeApplied: () => {
6379
- },
6380
- onAfterApplied: () => {
6381
- }
6434
+ staticNodeResolver: () => false
6382
6435
  };
6383
6436
  const createAnimatedLayoutParams = (config) => {
6384
6437
  var _a, _b;
@@ -6386,8 +6439,8 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
6386
6439
  return {
6387
6440
  algorithm,
6388
6441
  staticNodeResolver: (config == null ? void 0 : config.staticNodeResolver) ?? defaults$1.staticNodeResolver,
6389
- onBeforeApplied: ((_a = config == null ? void 0 : config.events) == null ? void 0 : _a.onBeforeApplied) ?? defaults$1.onBeforeApplied,
6390
- onAfterApplied: ((_b = config == null ? void 0 : config.events) == null ? void 0 : _b.onAfterApplied) ?? defaults$1.onAfterApplied
6442
+ onBeforeApplied: ((_a = config == null ? void 0 : config.events) == null ? void 0 : _a.onBeforeApplied) ?? noopFn,
6443
+ onAfterApplied: ((_b = config == null ? void 0 : config.events) == null ? void 0 : _b.onAfterApplied) ?? noopFn
6391
6444
  };
6392
6445
  };
6393
6446
  const resolveLayoutApplyOn = (applyOn) => {
@@ -6410,10 +6463,6 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
6410
6463
  };
6411
6464
  const defaults = Object.freeze({
6412
6465
  staticNodeResolver: () => false,
6413
- onBeforeApplied: () => {
6414
- },
6415
- onAfterApplied: () => {
6416
- },
6417
6466
  hierarchicalLayout: {
6418
6467
  layerWidth: 300,
6419
6468
  layerSpace: 300
@@ -6620,8 +6669,8 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
6620
6669
  algorithm: resolveLayoutAlgorithm(config.algorithm),
6621
6670
  applyOn: resolveLayoutApplyOn(config.applyOn),
6622
6671
  staticNodeResolver: config.staticNodeResolver ?? defaults.staticNodeResolver,
6623
- onBeforeApplied: ((_a = config.events) == null ? void 0 : _a.onBeforeApplied) ?? defaults.onBeforeApplied,
6624
- onAfterApplied: ((_b = config.events) == null ? void 0 : _b.onAfterApplied) ?? defaults.onAfterApplied
6672
+ onBeforeApplied: ((_a = config.events) == null ? void 0 : _a.onBeforeApplied) ?? noopFn,
6673
+ onAfterApplied: ((_b = config.events) == null ? void 0 : _b.onAfterApplied) ?? noopFn
6625
6674
  };
6626
6675
  };
6627
6676
  const patchAnimatedLayoutDraggableNodesParams = (params, staticNodes) => {
@@ -6954,7 +7003,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
6954
7003
  const params = createConnectablePortsParams(
6955
7004
  this.connectablePortsConfig,
6956
7005
  graphControllerParams.edges.shapeFactory,
6957
- graphControllerParams.ports.direction
7006
+ canvas.graph
6958
7007
  );
6959
7008
  UserConnectablePortsConfigurator.configure(
6960
7009
  canvas,
@@ -7002,9 +7051,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
7002
7051
  LayoutConfigurator.configure(canvas, layoutParams);
7003
7052
  }
7004
7053
  if (this.hasAnimatedLayout) {
7005
- let config = createAnimatedLayoutParams(
7006
- this.animatedLayoutConfig
7007
- );
7054
+ let config = createAnimatedLayoutParams(this.animatedLayoutConfig);
7008
7055
  if (this.hasDraggableNodes) {
7009
7056
  subscribeAnimatedLayoutStaticNodesUpdate(
7010
7057
  canvas,
@@ -7017,11 +7064,9 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
7017
7064
  }
7018
7065
  AnimatedLayoutConfigurator.configure(canvas, config, this.window);
7019
7066
  }
7020
- const onBeforeDestroy = () => {
7067
+ canvas.onBeforeDestroy.subscribe(() => {
7021
7068
  layers.destroy();
7022
- canvas.onBeforeDestroy.unsubscribe(onBeforeDestroy);
7023
- };
7024
- canvas.onBeforeDestroy.subscribe(onBeforeDestroy);
7069
+ });
7025
7070
  return canvas;
7026
7071
  }
7027
7072
  createHtmlView(host, graphStore, viewportStore) {