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