@html-graph/html-graph 8.15.1 → 8.16.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.
- package/dist/html-graph.d.ts +13 -0
- package/dist/html-graph.js +299 -256
- package/dist/html-graph.min.js +654 -613
- package/dist/html-graph.min.umd.cjs +1 -1
- package/dist/html-graph.umd.cjs +299 -256
- package/package.json +1 -1
package/dist/html-graph.umd.cjs
CHANGED
|
@@ -623,6 +623,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
623
623
|
removeNonexistentPort: (portId) => `Failed to remove port with ID ${JSON.stringify(portId)} because it does not exist`,
|
|
624
624
|
accessNonexistentEdge: (edgeId) => `Failed to access edge with ID ${JSON.stringify(edgeId)} because it does not exist`,
|
|
625
625
|
addEdgeWithExistingId: (edgeId) => `Failed to add edge with ID ${JSON.stringify(edgeId)} because an edge with this ID already exists`,
|
|
626
|
+
addEdgeWithElementInUse: (edgeId, useEdgeId) => `Failed to add edge with ID ${JSON.stringify(edgeId)} because its SVG element is already attached to edge with ID ${JSON.stringify(useEdgeId)}`,
|
|
626
627
|
addEdgeFromNonexistentPort: (edgeId, portId) => `Failed to add edge with ID ${JSON.stringify(edgeId)} from port with ID ${JSON.stringify(portId)} because the port does not exist`,
|
|
627
628
|
addEdgeToNonexistentPort: (edgeId, portId) => `Failed to add edge with ID ${JSON.stringify(edgeId)} to port with ID ${JSON.stringify(portId)} because the port does not exist`,
|
|
628
629
|
updateNonexistentEdge: (edgeId) => `Failed to update edge with ID ${JSON.stringify(edgeId)} because it does not exist`,
|
|
@@ -641,6 +642,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
641
642
|
__publicField(this, "portOutgoingEdges", /* @__PURE__ */ new Map());
|
|
642
643
|
__publicField(this, "portCycleEdges", /* @__PURE__ */ new Map());
|
|
643
644
|
__publicField(this, "elementPorts", new OneToManyCollection());
|
|
645
|
+
__publicField(this, "edgesElementsMap", /* @__PURE__ */ new Map());
|
|
644
646
|
__publicField(this, "afterNodeAddedEmitter");
|
|
645
647
|
__publicField(this, "onAfterNodeAdded");
|
|
646
648
|
__publicField(this, "afterNodeUpdatedEmitter");
|
|
@@ -821,6 +823,9 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
821
823
|
}
|
|
822
824
|
return edge;
|
|
823
825
|
}
|
|
826
|
+
findEdgeIdByElement(element) {
|
|
827
|
+
return this.edgesElementsMap.get(element);
|
|
828
|
+
}
|
|
824
829
|
addEdge(request) {
|
|
825
830
|
if (this.hasEdge(request.id)) {
|
|
826
831
|
throw new CanvasError(canvasErrorText.addEdgeWithExistingId(request.id));
|
|
@@ -835,6 +840,12 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
835
840
|
canvasErrorText.addEdgeToNonexistentPort(request.id, request.to)
|
|
836
841
|
);
|
|
837
842
|
}
|
|
843
|
+
const useEdgeId = this.findEdgeIdByElement(request.shape.svg);
|
|
844
|
+
if (useEdgeId !== void 0) {
|
|
845
|
+
throw new CanvasError(
|
|
846
|
+
canvasErrorText.addEdgeWithElementInUse(request.id, useEdgeId)
|
|
847
|
+
);
|
|
848
|
+
}
|
|
838
849
|
this.addEdgeInternal(request);
|
|
839
850
|
this.afterEdgeAddedEmitter.emit(request.id);
|
|
840
851
|
}
|
|
@@ -892,6 +903,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
892
903
|
this.portCycleEdges.clear();
|
|
893
904
|
this.elementPorts.clear();
|
|
894
905
|
this.nodesElementsMap.clear();
|
|
906
|
+
this.edgesElementsMap.clear();
|
|
895
907
|
this.edges.clear();
|
|
896
908
|
this.ports.clear();
|
|
897
909
|
this.nodes.clear();
|
|
@@ -1000,6 +1012,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1000
1012
|
priority: request.priority
|
|
1001
1013
|
}
|
|
1002
1014
|
});
|
|
1015
|
+
this.edgesElementsMap.set(request.shape.svg, request.id);
|
|
1003
1016
|
if (request.from !== request.to) {
|
|
1004
1017
|
this.portOutgoingEdges.get(request.from).add(request.id);
|
|
1005
1018
|
this.portIncomingEdges.get(request.to).add(request.id);
|
|
@@ -1008,7 +1021,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1008
1021
|
}
|
|
1009
1022
|
}
|
|
1010
1023
|
removeEdgeInternal(edgeId) {
|
|
1011
|
-
const { from, to } = this.getEdge(edgeId);
|
|
1024
|
+
const { from, to, payload } = this.getEdge(edgeId);
|
|
1012
1025
|
this.portCycleEdges.get(from).delete(edgeId);
|
|
1013
1026
|
this.portCycleEdges.get(to).delete(edgeId);
|
|
1014
1027
|
this.portIncomingEdges.get(from).delete(edgeId);
|
|
@@ -1016,6 +1029,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1016
1029
|
this.portOutgoingEdges.get(from).delete(edgeId);
|
|
1017
1030
|
this.portOutgoingEdges.get(to).delete(edgeId);
|
|
1018
1031
|
this.edges.delete(edgeId);
|
|
1032
|
+
this.edgesElementsMap.delete(payload.shape.svg);
|
|
1019
1033
|
}
|
|
1020
1034
|
}
|
|
1021
1035
|
const calculateReverseMatrix = (matrix) => {
|
|
@@ -2833,6 +2847,9 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
2833
2847
|
shape: payload.shape
|
|
2834
2848
|
};
|
|
2835
2849
|
}
|
|
2850
|
+
findEdgeIdByElement(element) {
|
|
2851
|
+
return this.graphStore.findEdgeIdByElement(element);
|
|
2852
|
+
}
|
|
2836
2853
|
getPortIncomingEdgeIds(portId) {
|
|
2837
2854
|
return this.graphStore.getPortIncomingEdgeIds(portId);
|
|
2838
2855
|
}
|
|
@@ -3460,6 +3477,163 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
3460
3477
|
this.params.onAfterApplied();
|
|
3461
3478
|
}
|
|
3462
3479
|
}
|
|
3480
|
+
class EventTagger {
|
|
3481
|
+
constructor() {
|
|
3482
|
+
__publicField(this, "field", "_htmlGraphTags");
|
|
3483
|
+
}
|
|
3484
|
+
has(event, tag) {
|
|
3485
|
+
const e = event;
|
|
3486
|
+
const tags = e[this.field];
|
|
3487
|
+
return tags !== void 0 && tags.has(tag);
|
|
3488
|
+
}
|
|
3489
|
+
tag(event, tag) {
|
|
3490
|
+
const e = event;
|
|
3491
|
+
const tags = e[this.field];
|
|
3492
|
+
if (tags === void 0) {
|
|
3493
|
+
e[this.field] = /* @__PURE__ */ new Set([tag]);
|
|
3494
|
+
} else {
|
|
3495
|
+
tags.add(tag);
|
|
3496
|
+
}
|
|
3497
|
+
}
|
|
3498
|
+
}
|
|
3499
|
+
const selectionHandled = Symbol();
|
|
3500
|
+
class UserSelectableElementsConfigurator {
|
|
3501
|
+
constructor(window2, pointInsideVerifier, params) {
|
|
3502
|
+
__publicField(this, "onSelected");
|
|
3503
|
+
__publicField(this, "mouseDownEventVerifier");
|
|
3504
|
+
__publicField(this, "mouseUpEventVerifier");
|
|
3505
|
+
__publicField(this, "movementThreshold");
|
|
3506
|
+
__publicField(this, "selectionCandidate", null);
|
|
3507
|
+
__publicField(this, "previousMouse", null);
|
|
3508
|
+
__publicField(this, "previousTouch", null);
|
|
3509
|
+
__publicField(this, "movedDistance", 0);
|
|
3510
|
+
__publicField(this, "onElementMouseDown", (event) => {
|
|
3511
|
+
const mouseEvent = event;
|
|
3512
|
+
if (!this.mouseDownEventVerifier(mouseEvent)) {
|
|
3513
|
+
return;
|
|
3514
|
+
}
|
|
3515
|
+
this.selectionCandidate = mouseEvent.currentTarget;
|
|
3516
|
+
this.previousMouse = { x: mouseEvent.clientX, y: mouseEvent.clientY };
|
|
3517
|
+
this.movedDistance = 0;
|
|
3518
|
+
this.window.addEventListener("mousemove", this.onWindowMouseMove, {
|
|
3519
|
+
passive: true
|
|
3520
|
+
});
|
|
3521
|
+
this.window.addEventListener("mouseup", this.onWindowMouseUp, {
|
|
3522
|
+
passive: true
|
|
3523
|
+
});
|
|
3524
|
+
});
|
|
3525
|
+
__publicField(this, "onElementTouchStart", (event) => {
|
|
3526
|
+
const touchEvent = event;
|
|
3527
|
+
const touches = touchEvent.touches;
|
|
3528
|
+
if (touches.length !== 1) {
|
|
3529
|
+
return;
|
|
3530
|
+
}
|
|
3531
|
+
this.selectionCandidate = touchEvent.currentTarget;
|
|
3532
|
+
this.previousTouch = touches[0];
|
|
3533
|
+
this.movedDistance = 0;
|
|
3534
|
+
this.window.addEventListener("touchmove", this.onWindowTouchMove, {
|
|
3535
|
+
passive: true
|
|
3536
|
+
});
|
|
3537
|
+
this.window.addEventListener("touchend", this.onWindowTouchEnd, {
|
|
3538
|
+
passive: true
|
|
3539
|
+
});
|
|
3540
|
+
this.window.addEventListener("touchcancel", this.onWindowTouchCancel, {
|
|
3541
|
+
passive: true
|
|
3542
|
+
});
|
|
3543
|
+
});
|
|
3544
|
+
__publicField(this, "onWindowMouseMove", (event) => {
|
|
3545
|
+
const mouseEvent = event;
|
|
3546
|
+
const inside = this.pointInsideVerifier.verify(
|
|
3547
|
+
mouseEvent.clientX,
|
|
3548
|
+
mouseEvent.clientY
|
|
3549
|
+
);
|
|
3550
|
+
if (!inside) {
|
|
3551
|
+
this.removeWindowMouseListeners();
|
|
3552
|
+
return;
|
|
3553
|
+
}
|
|
3554
|
+
const previousMouse = this.previousMouse;
|
|
3555
|
+
const x = mouseEvent.clientX - previousMouse.x;
|
|
3556
|
+
const y = mouseEvent.clientY - previousMouse.y;
|
|
3557
|
+
this.previousMouse = { x: mouseEvent.clientX, y: mouseEvent.clientY };
|
|
3558
|
+
this.processMoveThresholdVerification(x, y, () => {
|
|
3559
|
+
this.removeWindowMouseListeners();
|
|
3560
|
+
});
|
|
3561
|
+
});
|
|
3562
|
+
__publicField(this, "onWindowMouseUp", (event) => {
|
|
3563
|
+
const mouseEvent = event;
|
|
3564
|
+
if (!this.mouseUpEventVerifier(mouseEvent)) {
|
|
3565
|
+
return;
|
|
3566
|
+
}
|
|
3567
|
+
this.removeWindowMouseListeners();
|
|
3568
|
+
this.onSelected(this.selectionCandidate, event);
|
|
3569
|
+
});
|
|
3570
|
+
__publicField(this, "onWindowTouchMove", (event) => {
|
|
3571
|
+
const touchEvent = event;
|
|
3572
|
+
const touches = touchEvent.touches;
|
|
3573
|
+
if (touches.length !== 1) {
|
|
3574
|
+
this.removeWindowTouchListeners();
|
|
3575
|
+
return;
|
|
3576
|
+
}
|
|
3577
|
+
const touch = touches[0];
|
|
3578
|
+
const inside = this.pointInsideVerifier.verify(
|
|
3579
|
+
touch.clientX,
|
|
3580
|
+
touch.clientY
|
|
3581
|
+
);
|
|
3582
|
+
if (!inside) {
|
|
3583
|
+
this.removeWindowTouchListeners();
|
|
3584
|
+
return;
|
|
3585
|
+
}
|
|
3586
|
+
const previousTouch = this.previousTouch;
|
|
3587
|
+
const x = touch.clientX - previousTouch.clientX;
|
|
3588
|
+
const y = touch.clientY - previousTouch.clientY;
|
|
3589
|
+
this.previousTouch = touch;
|
|
3590
|
+
this.processMoveThresholdVerification(x, y, () => {
|
|
3591
|
+
this.removeWindowTouchListeners();
|
|
3592
|
+
});
|
|
3593
|
+
});
|
|
3594
|
+
__publicField(this, "onWindowTouchEnd", (event) => {
|
|
3595
|
+
this.removeWindowTouchListeners();
|
|
3596
|
+
this.onSelected(this.selectionCandidate, event);
|
|
3597
|
+
});
|
|
3598
|
+
__publicField(this, "onWindowTouchCancel", () => {
|
|
3599
|
+
this.removeWindowTouchListeners();
|
|
3600
|
+
});
|
|
3601
|
+
this.window = window2;
|
|
3602
|
+
this.pointInsideVerifier = pointInsideVerifier;
|
|
3603
|
+
this.mouseDownEventVerifier = params.mouseDownEventVerifier;
|
|
3604
|
+
this.mouseUpEventVerifier = params.mouseUpEventVerifier;
|
|
3605
|
+
this.onSelected = params.onSelected;
|
|
3606
|
+
this.movementThreshold = params.movementThreshold;
|
|
3607
|
+
}
|
|
3608
|
+
enable(element) {
|
|
3609
|
+
element.addEventListener("mousedown", this.onElementMouseDown);
|
|
3610
|
+
element.addEventListener("touchstart", this.onElementTouchStart);
|
|
3611
|
+
}
|
|
3612
|
+
disable(element) {
|
|
3613
|
+
element.removeEventListener("mousedown", this.onElementMouseDown);
|
|
3614
|
+
element.removeEventListener("touchstart", this.onElementTouchStart);
|
|
3615
|
+
if (element === this.selectionCandidate) {
|
|
3616
|
+
this.removeWindowMouseListeners();
|
|
3617
|
+
this.removeWindowTouchListeners();
|
|
3618
|
+
}
|
|
3619
|
+
}
|
|
3620
|
+
removeWindowMouseListeners() {
|
|
3621
|
+
this.window.removeEventListener("mousemove", this.onWindowMouseMove);
|
|
3622
|
+
this.window.removeEventListener("mouseup", this.onWindowMouseUp);
|
|
3623
|
+
}
|
|
3624
|
+
removeWindowTouchListeners() {
|
|
3625
|
+
this.window.removeEventListener("touchmove", this.onWindowTouchMove);
|
|
3626
|
+
this.window.removeEventListener("touchend", this.onWindowTouchEnd);
|
|
3627
|
+
this.window.removeEventListener("touchcancel", this.onWindowTouchCancel);
|
|
3628
|
+
}
|
|
3629
|
+
processMoveThresholdVerification(x, y, thresholdReachedCallback) {
|
|
3630
|
+
const distance = Math.sqrt(x * x + y * y);
|
|
3631
|
+
this.movedDistance += distance;
|
|
3632
|
+
if (this.movedDistance > this.movementThreshold) {
|
|
3633
|
+
thresholdReachedCallback();
|
|
3634
|
+
}
|
|
3635
|
+
}
|
|
3636
|
+
}
|
|
3463
3637
|
class UserDraggableNodesConfigurator {
|
|
3464
3638
|
constructor(canvas, element, window2, pointInsideVerifier, params) {
|
|
3465
3639
|
__publicField(this, "grabbedNode", null);
|
|
@@ -4611,311 +4785,152 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
4611
4785
|
}
|
|
4612
4786
|
}
|
|
4613
4787
|
class UserSelectableNodesConfigurator {
|
|
4614
|
-
constructor(canvas, window2, pointInsideVerifier, params) {
|
|
4788
|
+
constructor(canvas, window2, pointInsideVerifier, eventTagger, params) {
|
|
4789
|
+
__publicField(this, "configurator");
|
|
4615
4790
|
__publicField(this, "onNodeSelected");
|
|
4616
|
-
__publicField(this, "
|
|
4617
|
-
__publicField(this, "mouseUpEventVerifier");
|
|
4618
|
-
__publicField(this, "movementThreshold");
|
|
4619
|
-
__publicField(this, "selectionCandidateNodeId", null);
|
|
4620
|
-
__publicField(this, "movedDistance", 0);
|
|
4621
|
-
__publicField(this, "previousMouse", null);
|
|
4622
|
-
__publicField(this, "previousTouch", null);
|
|
4791
|
+
__publicField(this, "selectionHandledTag", selectionHandled);
|
|
4623
4792
|
__publicField(this, "onAfterNodeAdded", (nodeId) => {
|
|
4624
4793
|
const { element } = this.canvas.graph.getNode(nodeId);
|
|
4625
|
-
|
|
4626
|
-
passive: true
|
|
4627
|
-
});
|
|
4628
|
-
element.addEventListener("touchstart", this.onNodeTouchStart, {
|
|
4629
|
-
passive: true
|
|
4630
|
-
});
|
|
4794
|
+
this.configurator.enable(element);
|
|
4631
4795
|
});
|
|
4632
4796
|
__publicField(this, "onBeforeNodeRemoved", (nodeId) => {
|
|
4633
4797
|
const { element } = this.canvas.graph.getNode(nodeId);
|
|
4634
|
-
|
|
4635
|
-
element.removeEventListener("touchstart", this.onNodeTouchStart);
|
|
4798
|
+
this.configurator.disable(element);
|
|
4636
4799
|
});
|
|
4637
4800
|
__publicField(this, "reset", () => {
|
|
4638
4801
|
this.canvas.graph.getAllNodeIds().forEach((nodeId) => {
|
|
4639
4802
|
const { element } = this.canvas.graph.getNode(nodeId);
|
|
4640
|
-
|
|
4641
|
-
element.removeEventListener("touchstart", this.onNodeTouchStart);
|
|
4642
|
-
});
|
|
4643
|
-
});
|
|
4644
|
-
__publicField(this, "revert", () => {
|
|
4645
|
-
this.reset();
|
|
4646
|
-
this.removeWindowMouseListeners();
|
|
4647
|
-
this.removeWindowTouchListeners();
|
|
4648
|
-
});
|
|
4649
|
-
__publicField(this, "onNodeMouseDown", (event) => {
|
|
4650
|
-
const mouseEvent = event;
|
|
4651
|
-
if (!this.mouseDownEventVerifier(mouseEvent)) {
|
|
4652
|
-
return;
|
|
4653
|
-
}
|
|
4654
|
-
const nodeId = this.canvas.graph.findNodeIdByElement(
|
|
4655
|
-
event.currentTarget
|
|
4656
|
-
);
|
|
4657
|
-
this.selectionCandidateNodeId = nodeId;
|
|
4658
|
-
this.previousMouse = { x: mouseEvent.clientX, y: mouseEvent.clientY };
|
|
4659
|
-
this.movedDistance = 0;
|
|
4660
|
-
this.window.addEventListener("mousemove", this.onWindowMouseMove, {
|
|
4661
|
-
passive: true
|
|
4662
|
-
});
|
|
4663
|
-
this.window.addEventListener("mouseup", this.onWindowMouseUp, {
|
|
4664
|
-
passive: true
|
|
4665
|
-
});
|
|
4666
|
-
});
|
|
4667
|
-
__publicField(this, "onNodeTouchStart", (event) => {
|
|
4668
|
-
const touchEvent = event;
|
|
4669
|
-
if (touchEvent.touches.length !== 1) {
|
|
4670
|
-
return;
|
|
4671
|
-
}
|
|
4672
|
-
const nodeId = this.canvas.graph.findNodeIdByElement(
|
|
4673
|
-
touchEvent.currentTarget
|
|
4674
|
-
);
|
|
4675
|
-
this.selectionCandidateNodeId = nodeId;
|
|
4676
|
-
this.previousTouch = touchEvent.touches[0];
|
|
4677
|
-
this.movedDistance = 0;
|
|
4678
|
-
this.window.addEventListener("touchmove", this.onWindowTouchMove, {
|
|
4679
|
-
passive: true
|
|
4680
|
-
});
|
|
4681
|
-
this.window.addEventListener("touchend", this.onWindowTouchEnd, {
|
|
4682
|
-
passive: true
|
|
4683
|
-
});
|
|
4684
|
-
this.window.addEventListener("touchcancel", this.onWindowTouchCancel, {
|
|
4685
|
-
passive: true
|
|
4803
|
+
this.configurator.disable(element);
|
|
4686
4804
|
});
|
|
4687
4805
|
});
|
|
4688
|
-
__publicField(this, "onWindowMouseMove", (event) => {
|
|
4689
|
-
const mouseEvent = event;
|
|
4690
|
-
const previousMouse = this.previousMouse;
|
|
4691
|
-
const x = mouseEvent.clientX - previousMouse.x;
|
|
4692
|
-
const y = mouseEvent.clientY - previousMouse.y;
|
|
4693
|
-
if (!this.pointInsideVerifier.verify(mouseEvent.clientX, mouseEvent.clientY)) {
|
|
4694
|
-
this.removeWindowMouseListeners();
|
|
4695
|
-
return;
|
|
4696
|
-
}
|
|
4697
|
-
this.processMoveThresholdVerification(x, y, () => {
|
|
4698
|
-
this.removeWindowMouseListeners();
|
|
4699
|
-
});
|
|
4700
|
-
this.previousMouse = { x: mouseEvent.clientX, y: mouseEvent.clientY };
|
|
4701
|
-
});
|
|
4702
|
-
__publicField(this, "onWindowTouchMove", (event) => {
|
|
4703
|
-
const touchEvent = event;
|
|
4704
|
-
if (touchEvent.touches.length !== 1) {
|
|
4705
|
-
this.removeWindowTouchListeners();
|
|
4706
|
-
return;
|
|
4707
|
-
}
|
|
4708
|
-
const touch = touchEvent.touches[0];
|
|
4709
|
-
if (!this.pointInsideVerifier.verify(touch.clientX, touch.clientY)) {
|
|
4710
|
-
this.removeWindowTouchListeners();
|
|
4711
|
-
return;
|
|
4712
|
-
}
|
|
4713
|
-
const previousTouch = this.previousTouch;
|
|
4714
|
-
const x = touch.clientX - previousTouch.clientX;
|
|
4715
|
-
const y = touch.clientY - previousTouch.clientY;
|
|
4716
|
-
this.processMoveThresholdVerification(x, y, () => {
|
|
4717
|
-
this.removeWindowTouchListeners();
|
|
4718
|
-
});
|
|
4719
|
-
this.previousTouch = touch;
|
|
4720
|
-
});
|
|
4721
|
-
__publicField(this, "onWindowMouseUp", (event) => {
|
|
4722
|
-
const mouseEvent = event;
|
|
4723
|
-
if (!this.mouseUpEventVerifier(mouseEvent)) {
|
|
4724
|
-
return;
|
|
4725
|
-
}
|
|
4726
|
-
this.removeWindowMouseListeners();
|
|
4727
|
-
this.trySelectNode(event);
|
|
4728
|
-
});
|
|
4729
|
-
__publicField(this, "onWindowTouchEnd", (event) => {
|
|
4730
|
-
this.removeWindowTouchListeners();
|
|
4731
|
-
this.trySelectNode(event);
|
|
4732
|
-
});
|
|
4733
|
-
__publicField(this, "onWindowTouchCancel", () => {
|
|
4734
|
-
this.removeWindowTouchListeners();
|
|
4735
|
-
});
|
|
4736
4806
|
this.canvas = canvas;
|
|
4737
4807
|
this.window = window2;
|
|
4738
4808
|
this.pointInsideVerifier = pointInsideVerifier;
|
|
4739
|
-
this.
|
|
4740
|
-
this.mouseUpEventVerifier = params.mouseUpEventVerifier;
|
|
4809
|
+
this.eventTagger = eventTagger;
|
|
4741
4810
|
this.onNodeSelected = params.onNodeSelected;
|
|
4742
|
-
this.
|
|
4811
|
+
this.configurator = new UserSelectableElementsConfigurator(
|
|
4812
|
+
this.window,
|
|
4813
|
+
this.pointInsideVerifier,
|
|
4814
|
+
{
|
|
4815
|
+
onSelected: (element, event) => {
|
|
4816
|
+
const nodeId = this.canvas.graph.findNodeIdByElement(element);
|
|
4817
|
+
this.eventTagger.tag(event, this.selectionHandledTag);
|
|
4818
|
+
this.onNodeSelected(nodeId);
|
|
4819
|
+
},
|
|
4820
|
+
movementThreshold: params.movementThreshold,
|
|
4821
|
+
mouseDownEventVerifier: params.mouseDownEventVerifier,
|
|
4822
|
+
mouseUpEventVerifier: params.mouseUpEventVerifier
|
|
4823
|
+
}
|
|
4824
|
+
);
|
|
4743
4825
|
this.canvas.graph.onAfterNodeAdded.subscribe(this.onAfterNodeAdded);
|
|
4744
4826
|
this.canvas.graph.onBeforeNodeRemoved.subscribe(this.onBeforeNodeRemoved);
|
|
4745
4827
|
this.canvas.graph.onBeforeClear.subscribe(this.reset);
|
|
4746
|
-
this.canvas.onBeforeDestroy.subscribe(this.
|
|
4828
|
+
this.canvas.onBeforeDestroy.subscribe(this.reset);
|
|
4747
4829
|
}
|
|
4748
|
-
static configure(canvas, window2, pointInsideVerifier, params) {
|
|
4830
|
+
static configure(canvas, window2, pointInsideVerifier, eventTagger, params) {
|
|
4749
4831
|
new UserSelectableNodesConfigurator(
|
|
4750
4832
|
canvas,
|
|
4751
4833
|
window2,
|
|
4752
4834
|
pointInsideVerifier,
|
|
4835
|
+
eventTagger,
|
|
4753
4836
|
params
|
|
4754
4837
|
);
|
|
4755
4838
|
}
|
|
4756
|
-
removeWindowMouseListeners() {
|
|
4757
|
-
this.window.removeEventListener("mouseup", this.onWindowMouseUp);
|
|
4758
|
-
this.window.removeEventListener("mousemove", this.onWindowMouseMove);
|
|
4759
|
-
}
|
|
4760
|
-
removeWindowTouchListeners() {
|
|
4761
|
-
this.window.removeEventListener("touchmove", this.onWindowTouchMove);
|
|
4762
|
-
this.window.removeEventListener("touchend", this.onWindowTouchEnd);
|
|
4763
|
-
this.window.removeEventListener("touchcancel", this.onWindowTouchCancel);
|
|
4764
|
-
}
|
|
4765
|
-
trySelectNode(event) {
|
|
4766
|
-
const nodeId = this.selectionCandidateNodeId;
|
|
4767
|
-
if (this.canvas.graph.hasNode(nodeId)) {
|
|
4768
|
-
this.onNodeSelected(nodeId);
|
|
4769
|
-
event.ignoreCanvasSelection = true;
|
|
4770
|
-
}
|
|
4771
|
-
}
|
|
4772
|
-
processMoveThresholdVerification(x, y, thresholdReachedCallback) {
|
|
4773
|
-
const distance = Math.sqrt(x * x + y * y);
|
|
4774
|
-
this.movedDistance += distance;
|
|
4775
|
-
if (this.movedDistance > this.movementThreshold) {
|
|
4776
|
-
thresholdReachedCallback();
|
|
4777
|
-
}
|
|
4778
|
-
}
|
|
4779
4839
|
}
|
|
4780
|
-
class
|
|
4781
|
-
constructor(canvas,
|
|
4782
|
-
__publicField(this, "
|
|
4783
|
-
__publicField(this, "
|
|
4784
|
-
__publicField(this, "
|
|
4785
|
-
__publicField(this, "
|
|
4786
|
-
|
|
4787
|
-
|
|
4788
|
-
__publicField(this, "previousTouch", null);
|
|
4789
|
-
__publicField(this, "onMouseDown", (event) => {
|
|
4790
|
-
const mouseEvent = event;
|
|
4791
|
-
if (!this.mouseDownEventVerifier(mouseEvent)) {
|
|
4792
|
-
return;
|
|
4793
|
-
}
|
|
4794
|
-
this.previousMouseDown = { x: mouseEvent.clientX, y: mouseEvent.clientY };
|
|
4795
|
-
this.movedDistance = 0;
|
|
4796
|
-
this.window.addEventListener("mousemove", this.onWindowMouseMove, {
|
|
4797
|
-
passive: true
|
|
4798
|
-
});
|
|
4799
|
-
this.window.addEventListener("mouseup", this.onWindowMouseUp, {
|
|
4800
|
-
passive: true
|
|
4801
|
-
});
|
|
4802
|
-
});
|
|
4803
|
-
__publicField(this, "onTouchStart", (event) => {
|
|
4804
|
-
const touchEvent = event;
|
|
4805
|
-
if (touchEvent.touches.length !== 1) {
|
|
4806
|
-
return;
|
|
4807
|
-
}
|
|
4808
|
-
const touch = touchEvent.touches[0];
|
|
4809
|
-
this.previousTouch = touch;
|
|
4810
|
-
this.movedDistance = 0;
|
|
4811
|
-
this.window.addEventListener("touchmove", this.onWindowTouchMove, {
|
|
4812
|
-
passive: true
|
|
4813
|
-
});
|
|
4814
|
-
this.window.addEventListener("touchend", this.onWindowTouchEnd, {
|
|
4815
|
-
passive: true
|
|
4816
|
-
});
|
|
4817
|
-
this.window.addEventListener("touchcancel", this.onWindowTouchCancel, {
|
|
4818
|
-
passive: true
|
|
4819
|
-
});
|
|
4840
|
+
class UserSelectableEdgesConfigurator {
|
|
4841
|
+
constructor(canvas, window2, pointInsideVerifier, eventTagger, params) {
|
|
4842
|
+
__publicField(this, "configurator");
|
|
4843
|
+
__publicField(this, "selectionHandledTag", selectionHandled);
|
|
4844
|
+
__publicField(this, "onEdgeSelected");
|
|
4845
|
+
__publicField(this, "onAfterEdgeAdded", (edgeId) => {
|
|
4846
|
+
const { shape } = this.canvas.graph.getEdge(edgeId);
|
|
4847
|
+
this.configurator.enable(shape.svg);
|
|
4820
4848
|
});
|
|
4821
|
-
__publicField(this, "
|
|
4822
|
-
const
|
|
4823
|
-
|
|
4824
|
-
this.removeWindowMouseListeners();
|
|
4825
|
-
return;
|
|
4826
|
-
}
|
|
4827
|
-
const previous = this.previousMouseDown;
|
|
4828
|
-
const dx = mouseEvent.clientX - previous.x;
|
|
4829
|
-
const dy = mouseEvent.clientY - previous.y;
|
|
4830
|
-
this.processMoveThresholdVerification(dx, dy, () => {
|
|
4831
|
-
this.removeWindowMouseListeners();
|
|
4832
|
-
});
|
|
4833
|
-
this.previousMouseDown = { x: mouseEvent.clientX, y: mouseEvent.clientY };
|
|
4849
|
+
__publicField(this, "onBeforeEdgeRemoved", (edgeId) => {
|
|
4850
|
+
const { shape } = this.canvas.graph.getEdge(edgeId);
|
|
4851
|
+
this.configurator.disable(shape.svg);
|
|
4834
4852
|
});
|
|
4835
|
-
__publicField(this, "
|
|
4836
|
-
|
|
4837
|
-
|
|
4838
|
-
this.
|
|
4839
|
-
return;
|
|
4840
|
-
}
|
|
4841
|
-
const touch = touchEvent.touches[0];
|
|
4842
|
-
if (!this.pointInsideVerifier.verify(touch.clientX, touch.clientY)) {
|
|
4843
|
-
this.removeWindowTouchListeners();
|
|
4844
|
-
return;
|
|
4845
|
-
}
|
|
4846
|
-
const previous = this.previousTouch;
|
|
4847
|
-
const dx = touch.clientX - previous.clientX;
|
|
4848
|
-
const dy = touch.clientY - previous.clientY;
|
|
4849
|
-
this.processMoveThresholdVerification(dx, dy, () => {
|
|
4850
|
-
this.removeWindowTouchListeners();
|
|
4853
|
+
__publicField(this, "reset", () => {
|
|
4854
|
+
this.canvas.graph.getAllEdgeIds().forEach((edgeId) => {
|
|
4855
|
+
const { shape } = this.canvas.graph.getEdge(edgeId);
|
|
4856
|
+
this.configurator.disable(shape.svg);
|
|
4851
4857
|
});
|
|
4852
|
-
this.previousTouch = touch;
|
|
4853
4858
|
});
|
|
4854
|
-
|
|
4855
|
-
|
|
4856
|
-
|
|
4857
|
-
|
|
4858
|
-
|
|
4859
|
-
|
|
4860
|
-
|
|
4861
|
-
|
|
4859
|
+
this.canvas = canvas;
|
|
4860
|
+
this.window = window2;
|
|
4861
|
+
this.pointInsideVerifier = pointInsideVerifier;
|
|
4862
|
+
this.eventTagger = eventTagger;
|
|
4863
|
+
this.onEdgeSelected = params.onEdgeSelected;
|
|
4864
|
+
this.configurator = new UserSelectableElementsConfigurator(
|
|
4865
|
+
this.window,
|
|
4866
|
+
this.pointInsideVerifier,
|
|
4867
|
+
{
|
|
4868
|
+
onSelected: (element, event) => {
|
|
4869
|
+
const edgeId = this.canvas.graph.findEdgeIdByElement(element);
|
|
4870
|
+
this.eventTagger.tag(event, this.selectionHandledTag);
|
|
4871
|
+
this.onEdgeSelected(edgeId);
|
|
4872
|
+
},
|
|
4873
|
+
movementThreshold: params.movementThreshold,
|
|
4874
|
+
mouseDownEventVerifier: params.mouseDownEventVerifier,
|
|
4875
|
+
mouseUpEventVerifier: params.mouseUpEventVerifier
|
|
4862
4876
|
}
|
|
4863
|
-
|
|
4864
|
-
|
|
4865
|
-
|
|
4866
|
-
|
|
4867
|
-
|
|
4868
|
-
|
|
4869
|
-
|
|
4870
|
-
|
|
4871
|
-
|
|
4877
|
+
);
|
|
4878
|
+
this.canvas.graph.onAfterEdgeAdded.subscribe(this.onAfterEdgeAdded);
|
|
4879
|
+
this.canvas.graph.onBeforeEdgeRemoved.subscribe(this.onBeforeEdgeRemoved);
|
|
4880
|
+
this.canvas.graph.onBeforeClear.subscribe(this.reset);
|
|
4881
|
+
this.canvas.onBeforeDestroy.subscribe(this.reset);
|
|
4882
|
+
}
|
|
4883
|
+
static configure(canvas, window2, pointInsideVerifier, eventTagger, params) {
|
|
4884
|
+
new UserSelectableEdgesConfigurator(
|
|
4885
|
+
canvas,
|
|
4886
|
+
window2,
|
|
4887
|
+
pointInsideVerifier,
|
|
4888
|
+
eventTagger,
|
|
4889
|
+
params
|
|
4890
|
+
);
|
|
4891
|
+
}
|
|
4892
|
+
}
|
|
4893
|
+
class UserSelectableCanvasConfigurator {
|
|
4894
|
+
constructor(canvas, element, window2, pointInsideVerifier, eventTagger, params) {
|
|
4895
|
+
__publicField(this, "configurator");
|
|
4896
|
+
__publicField(this, "onCanvasSelected");
|
|
4897
|
+
__publicField(this, "selectionHandledTag", selectionHandled);
|
|
4872
4898
|
__publicField(this, "restore", () => {
|
|
4873
|
-
this.
|
|
4874
|
-
this.element.removeEventListener("touchstart", this.onTouchStart);
|
|
4875
|
-
this.removeWindowMouseListeners();
|
|
4876
|
-
this.removeWindowTouchListeners();
|
|
4899
|
+
this.configurator.disable(this.element);
|
|
4877
4900
|
});
|
|
4878
4901
|
this.canvas = canvas;
|
|
4879
4902
|
this.element = element;
|
|
4880
4903
|
this.window = window2;
|
|
4881
4904
|
this.pointInsideVerifier = pointInsideVerifier;
|
|
4905
|
+
this.eventTagger = eventTagger;
|
|
4882
4906
|
this.onCanvasSelected = params.onCanvasSelected;
|
|
4883
|
-
this.
|
|
4884
|
-
|
|
4885
|
-
|
|
4907
|
+
this.configurator = new UserSelectableElementsConfigurator(
|
|
4908
|
+
this.window,
|
|
4909
|
+
this.pointInsideVerifier,
|
|
4910
|
+
{
|
|
4911
|
+
onSelected: (_element, event) => {
|
|
4912
|
+
if (!this.eventTagger.has(event, this.selectionHandledTag)) {
|
|
4913
|
+
this.onCanvasSelected();
|
|
4914
|
+
}
|
|
4915
|
+
},
|
|
4916
|
+
movementThreshold: params.movementThreshold,
|
|
4917
|
+
mouseDownEventVerifier: params.mouseDownEventVerifier,
|
|
4918
|
+
mouseUpEventVerifier: params.mouseUpEventVerifier
|
|
4919
|
+
}
|
|
4920
|
+
);
|
|
4921
|
+
this.configurator.enable(this.element);
|
|
4886
4922
|
this.canvas.onBeforeDestroy.subscribe(this.restore);
|
|
4887
|
-
this.element.addEventListener("mousedown", this.onMouseDown, {
|
|
4888
|
-
passive: true
|
|
4889
|
-
});
|
|
4890
|
-
this.element.addEventListener("touchstart", this.onTouchStart, {
|
|
4891
|
-
passive: true
|
|
4892
|
-
});
|
|
4893
4923
|
}
|
|
4894
|
-
static configure(canvas, element, window2, pointInsideVerifier, params) {
|
|
4924
|
+
static configure(canvas, element, window2, pointInsideVerifier, eventTagger, params) {
|
|
4895
4925
|
new UserSelectableCanvasConfigurator(
|
|
4896
4926
|
canvas,
|
|
4897
4927
|
element,
|
|
4898
4928
|
window2,
|
|
4899
4929
|
pointInsideVerifier,
|
|
4930
|
+
eventTagger,
|
|
4900
4931
|
params
|
|
4901
4932
|
);
|
|
4902
4933
|
}
|
|
4903
|
-
removeWindowMouseListeners() {
|
|
4904
|
-
this.window.removeEventListener("mousemove", this.onWindowMouseMove);
|
|
4905
|
-
this.window.removeEventListener("mouseup", this.onWindowMouseUp);
|
|
4906
|
-
}
|
|
4907
|
-
removeWindowTouchListeners() {
|
|
4908
|
-
this.window.removeEventListener("touchmove", this.onWindowTouchMove);
|
|
4909
|
-
this.window.removeEventListener("touchend", this.onWindowTouchEnd);
|
|
4910
|
-
this.window.removeEventListener("touchcancel", this.onWindowTouchCancel);
|
|
4911
|
-
}
|
|
4912
|
-
processMoveThresholdVerification(x, y, thresholdReachedCallback) {
|
|
4913
|
-
const distance = Math.sqrt(x * x + y * y);
|
|
4914
|
-
this.movedDistance += distance;
|
|
4915
|
-
if (this.movedDistance > this.movementThreshold) {
|
|
4916
|
-
thresholdReachedCallback();
|
|
4917
|
-
}
|
|
4918
|
-
}
|
|
4919
4934
|
}
|
|
4920
4935
|
const createHost = () => {
|
|
4921
4936
|
const host = document.createElement("div");
|
|
@@ -6729,6 +6744,14 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
6729
6744
|
movementThreshold: config.movementThreshold ?? selectionDefaults.movementThreshold
|
|
6730
6745
|
};
|
|
6731
6746
|
};
|
|
6747
|
+
const createUserSelectableEdgesParams = (config) => {
|
|
6748
|
+
return {
|
|
6749
|
+
onEdgeSelected: config.onEdgeSelected,
|
|
6750
|
+
mouseDownEventVerifier: config.mouseDownEventVerifier ?? selectionDefaults.mouseDownEventVerifier,
|
|
6751
|
+
mouseUpEventVerifier: config.mouseUpEventVerifier ?? selectionDefaults.mouseUpEventVerifier,
|
|
6752
|
+
movementThreshold: config.movementThreshold ?? selectionDefaults.movementThreshold
|
|
6753
|
+
};
|
|
6754
|
+
};
|
|
6732
6755
|
class CanvasBuilder {
|
|
6733
6756
|
constructor(element) {
|
|
6734
6757
|
__publicField(this, "used", false);
|
|
@@ -6742,6 +6765,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
6742
6765
|
__publicField(this, "layoutConfig", {});
|
|
6743
6766
|
__publicField(this, "animatedLayoutConfig", {});
|
|
6744
6767
|
__publicField(this, "userSelectableNodesConfig");
|
|
6768
|
+
__publicField(this, "userSelectableEdgesConfig");
|
|
6745
6769
|
__publicField(this, "userSelectableCanvasConfig");
|
|
6746
6770
|
__publicField(this, "hasDraggableNodes", false);
|
|
6747
6771
|
__publicField(this, "hasTransformableViewport", false);
|
|
@@ -6755,6 +6779,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
6755
6779
|
__publicField(this, "window", window);
|
|
6756
6780
|
__publicField(this, "animationStaticNodes", /* @__PURE__ */ new Set());
|
|
6757
6781
|
__publicField(this, "pointInsideVerifier");
|
|
6782
|
+
__publicField(this, "eventTagger", new EventTagger());
|
|
6758
6783
|
this.element = element;
|
|
6759
6784
|
this.pointInsideVerifier = new PointInsideVerifier(element, this.window);
|
|
6760
6785
|
}
|
|
@@ -6811,6 +6836,10 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
6811
6836
|
this.userSelectableNodesConfig = config;
|
|
6812
6837
|
return this;
|
|
6813
6838
|
}
|
|
6839
|
+
enableUserSelectableEdges(config) {
|
|
6840
|
+
this.userSelectableEdgesConfig = config;
|
|
6841
|
+
return this;
|
|
6842
|
+
}
|
|
6814
6843
|
enableUserSelectableCanvas(config) {
|
|
6815
6844
|
this.userSelectableCanvasConfig = config;
|
|
6816
6845
|
return this;
|
|
@@ -6868,6 +6897,18 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
6868
6897
|
if (this.hasNodeResizeReactiveEdges) {
|
|
6869
6898
|
NodeResizeReactiveEdgesConfigurator.configure(canvas);
|
|
6870
6899
|
}
|
|
6900
|
+
if (this.userSelectableEdgesConfig !== void 0) {
|
|
6901
|
+
const params = createUserSelectableEdgesParams(
|
|
6902
|
+
this.userSelectableEdgesConfig
|
|
6903
|
+
);
|
|
6904
|
+
UserSelectableEdgesConfigurator.configure(
|
|
6905
|
+
canvas,
|
|
6906
|
+
this.window,
|
|
6907
|
+
this.pointInsideVerifier,
|
|
6908
|
+
this.eventTagger,
|
|
6909
|
+
params
|
|
6910
|
+
);
|
|
6911
|
+
}
|
|
6871
6912
|
if (this.userSelectableNodesConfig !== void 0) {
|
|
6872
6913
|
const params = createUserSelectableNodesParams(
|
|
6873
6914
|
this.userSelectableNodesConfig
|
|
@@ -6876,6 +6917,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
6876
6917
|
canvas,
|
|
6877
6918
|
this.window,
|
|
6878
6919
|
this.pointInsideVerifier,
|
|
6920
|
+
this.eventTagger,
|
|
6879
6921
|
params
|
|
6880
6922
|
);
|
|
6881
6923
|
}
|
|
@@ -6888,6 +6930,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
6888
6930
|
layers.main,
|
|
6889
6931
|
this.window,
|
|
6890
6932
|
this.pointInsideVerifier,
|
|
6933
|
+
this.eventTagger,
|
|
6891
6934
|
params
|
|
6892
6935
|
);
|
|
6893
6936
|
}
|