@html-graph/html-graph 8.15.0 → 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 +16 -1
- package/dist/html-graph.js +309 -257
- package/dist/html-graph.min.js +664 -614
- package/dist/html-graph.min.umd.cjs +1 -1
- package/dist/html-graph.umd.cjs +309 -257
- 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);
|
|
@@ -4352,7 +4526,16 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
4352
4526
|
this.moveDraggingPort(cursor);
|
|
4353
4527
|
},
|
|
4354
4528
|
onPointerMoveOutside: () => {
|
|
4355
|
-
this.
|
|
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
|
+
});
|
|
4356
4539
|
},
|
|
4357
4540
|
onPointerUp: (cursor) => {
|
|
4358
4541
|
this.tryCreateConnection(cursor);
|
|
@@ -4602,311 +4785,152 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
4602
4785
|
}
|
|
4603
4786
|
}
|
|
4604
4787
|
class UserSelectableNodesConfigurator {
|
|
4605
|
-
constructor(canvas, window2, pointInsideVerifier, params) {
|
|
4788
|
+
constructor(canvas, window2, pointInsideVerifier, eventTagger, params) {
|
|
4789
|
+
__publicField(this, "configurator");
|
|
4606
4790
|
__publicField(this, "onNodeSelected");
|
|
4607
|
-
__publicField(this, "
|
|
4608
|
-
__publicField(this, "mouseUpEventVerifier");
|
|
4609
|
-
__publicField(this, "movementThreshold");
|
|
4610
|
-
__publicField(this, "selectionCandidateNodeId", null);
|
|
4611
|
-
__publicField(this, "movedDistance", 0);
|
|
4612
|
-
__publicField(this, "previousMouse", null);
|
|
4613
|
-
__publicField(this, "previousTouch", null);
|
|
4791
|
+
__publicField(this, "selectionHandledTag", selectionHandled);
|
|
4614
4792
|
__publicField(this, "onAfterNodeAdded", (nodeId) => {
|
|
4615
4793
|
const { element } = this.canvas.graph.getNode(nodeId);
|
|
4616
|
-
|
|
4617
|
-
passive: true
|
|
4618
|
-
});
|
|
4619
|
-
element.addEventListener("touchstart", this.onNodeTouchStart, {
|
|
4620
|
-
passive: true
|
|
4621
|
-
});
|
|
4794
|
+
this.configurator.enable(element);
|
|
4622
4795
|
});
|
|
4623
4796
|
__publicField(this, "onBeforeNodeRemoved", (nodeId) => {
|
|
4624
4797
|
const { element } = this.canvas.graph.getNode(nodeId);
|
|
4625
|
-
|
|
4626
|
-
element.removeEventListener("touchstart", this.onNodeTouchStart);
|
|
4798
|
+
this.configurator.disable(element);
|
|
4627
4799
|
});
|
|
4628
4800
|
__publicField(this, "reset", () => {
|
|
4629
4801
|
this.canvas.graph.getAllNodeIds().forEach((nodeId) => {
|
|
4630
4802
|
const { element } = this.canvas.graph.getNode(nodeId);
|
|
4631
|
-
|
|
4632
|
-
element.removeEventListener("touchstart", this.onNodeTouchStart);
|
|
4633
|
-
});
|
|
4634
|
-
});
|
|
4635
|
-
__publicField(this, "revert", () => {
|
|
4636
|
-
this.reset();
|
|
4637
|
-
this.removeWindowMouseListeners();
|
|
4638
|
-
this.removeWindowTouchListeners();
|
|
4639
|
-
});
|
|
4640
|
-
__publicField(this, "onNodeMouseDown", (event) => {
|
|
4641
|
-
const mouseEvent = event;
|
|
4642
|
-
if (!this.mouseDownEventVerifier(mouseEvent)) {
|
|
4643
|
-
return;
|
|
4644
|
-
}
|
|
4645
|
-
const nodeId = this.canvas.graph.findNodeIdByElement(
|
|
4646
|
-
event.currentTarget
|
|
4647
|
-
);
|
|
4648
|
-
this.selectionCandidateNodeId = nodeId;
|
|
4649
|
-
this.previousMouse = { x: mouseEvent.clientX, y: mouseEvent.clientY };
|
|
4650
|
-
this.movedDistance = 0;
|
|
4651
|
-
this.window.addEventListener("mousemove", this.onWindowMouseMove, {
|
|
4652
|
-
passive: true
|
|
4653
|
-
});
|
|
4654
|
-
this.window.addEventListener("mouseup", this.onWindowMouseUp, {
|
|
4655
|
-
passive: true
|
|
4656
|
-
});
|
|
4657
|
-
});
|
|
4658
|
-
__publicField(this, "onNodeTouchStart", (event) => {
|
|
4659
|
-
const touchEvent = event;
|
|
4660
|
-
if (touchEvent.touches.length !== 1) {
|
|
4661
|
-
return;
|
|
4662
|
-
}
|
|
4663
|
-
const nodeId = this.canvas.graph.findNodeIdByElement(
|
|
4664
|
-
touchEvent.currentTarget
|
|
4665
|
-
);
|
|
4666
|
-
this.selectionCandidateNodeId = nodeId;
|
|
4667
|
-
this.previousTouch = touchEvent.touches[0];
|
|
4668
|
-
this.movedDistance = 0;
|
|
4669
|
-
this.window.addEventListener("touchmove", this.onWindowTouchMove, {
|
|
4670
|
-
passive: true
|
|
4671
|
-
});
|
|
4672
|
-
this.window.addEventListener("touchend", this.onWindowTouchEnd, {
|
|
4673
|
-
passive: true
|
|
4674
|
-
});
|
|
4675
|
-
this.window.addEventListener("touchcancel", this.onWindowTouchCancel, {
|
|
4676
|
-
passive: true
|
|
4803
|
+
this.configurator.disable(element);
|
|
4677
4804
|
});
|
|
4678
4805
|
});
|
|
4679
|
-
__publicField(this, "onWindowMouseMove", (event) => {
|
|
4680
|
-
const mouseEvent = event;
|
|
4681
|
-
const previousMouse = this.previousMouse;
|
|
4682
|
-
const x = mouseEvent.clientX - previousMouse.x;
|
|
4683
|
-
const y = mouseEvent.clientY - previousMouse.y;
|
|
4684
|
-
if (!this.pointInsideVerifier.verify(mouseEvent.clientX, mouseEvent.clientY)) {
|
|
4685
|
-
this.removeWindowMouseListeners();
|
|
4686
|
-
return;
|
|
4687
|
-
}
|
|
4688
|
-
this.processMoveThresholdVerification(x, y, () => {
|
|
4689
|
-
this.removeWindowMouseListeners();
|
|
4690
|
-
});
|
|
4691
|
-
this.previousMouse = { x: mouseEvent.clientX, y: mouseEvent.clientY };
|
|
4692
|
-
});
|
|
4693
|
-
__publicField(this, "onWindowTouchMove", (event) => {
|
|
4694
|
-
const touchEvent = event;
|
|
4695
|
-
if (touchEvent.touches.length !== 1) {
|
|
4696
|
-
this.removeWindowTouchListeners();
|
|
4697
|
-
return;
|
|
4698
|
-
}
|
|
4699
|
-
const touch = touchEvent.touches[0];
|
|
4700
|
-
if (!this.pointInsideVerifier.verify(touch.clientX, touch.clientY)) {
|
|
4701
|
-
this.removeWindowTouchListeners();
|
|
4702
|
-
return;
|
|
4703
|
-
}
|
|
4704
|
-
const previousTouch = this.previousTouch;
|
|
4705
|
-
const x = touch.clientX - previousTouch.clientX;
|
|
4706
|
-
const y = touch.clientY - previousTouch.clientY;
|
|
4707
|
-
this.processMoveThresholdVerification(x, y, () => {
|
|
4708
|
-
this.removeWindowTouchListeners();
|
|
4709
|
-
});
|
|
4710
|
-
this.previousTouch = touch;
|
|
4711
|
-
});
|
|
4712
|
-
__publicField(this, "onWindowMouseUp", (event) => {
|
|
4713
|
-
const mouseEvent = event;
|
|
4714
|
-
if (!this.mouseUpEventVerifier(mouseEvent)) {
|
|
4715
|
-
return;
|
|
4716
|
-
}
|
|
4717
|
-
this.removeWindowMouseListeners();
|
|
4718
|
-
this.trySelectNode(event);
|
|
4719
|
-
});
|
|
4720
|
-
__publicField(this, "onWindowTouchEnd", (event) => {
|
|
4721
|
-
this.removeWindowTouchListeners();
|
|
4722
|
-
this.trySelectNode(event);
|
|
4723
|
-
});
|
|
4724
|
-
__publicField(this, "onWindowTouchCancel", () => {
|
|
4725
|
-
this.removeWindowTouchListeners();
|
|
4726
|
-
});
|
|
4727
4806
|
this.canvas = canvas;
|
|
4728
4807
|
this.window = window2;
|
|
4729
4808
|
this.pointInsideVerifier = pointInsideVerifier;
|
|
4730
|
-
this.
|
|
4731
|
-
this.mouseUpEventVerifier = params.mouseUpEventVerifier;
|
|
4809
|
+
this.eventTagger = eventTagger;
|
|
4732
4810
|
this.onNodeSelected = params.onNodeSelected;
|
|
4733
|
-
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
|
+
);
|
|
4734
4825
|
this.canvas.graph.onAfterNodeAdded.subscribe(this.onAfterNodeAdded);
|
|
4735
4826
|
this.canvas.graph.onBeforeNodeRemoved.subscribe(this.onBeforeNodeRemoved);
|
|
4736
4827
|
this.canvas.graph.onBeforeClear.subscribe(this.reset);
|
|
4737
|
-
this.canvas.onBeforeDestroy.subscribe(this.
|
|
4828
|
+
this.canvas.onBeforeDestroy.subscribe(this.reset);
|
|
4738
4829
|
}
|
|
4739
|
-
static configure(canvas, window2, pointInsideVerifier, params) {
|
|
4830
|
+
static configure(canvas, window2, pointInsideVerifier, eventTagger, params) {
|
|
4740
4831
|
new UserSelectableNodesConfigurator(
|
|
4741
4832
|
canvas,
|
|
4742
4833
|
window2,
|
|
4743
4834
|
pointInsideVerifier,
|
|
4835
|
+
eventTagger,
|
|
4744
4836
|
params
|
|
4745
4837
|
);
|
|
4746
4838
|
}
|
|
4747
|
-
removeWindowMouseListeners() {
|
|
4748
|
-
this.window.removeEventListener("mouseup", this.onWindowMouseUp);
|
|
4749
|
-
this.window.removeEventListener("mousemove", this.onWindowMouseMove);
|
|
4750
|
-
}
|
|
4751
|
-
removeWindowTouchListeners() {
|
|
4752
|
-
this.window.removeEventListener("touchmove", this.onWindowTouchMove);
|
|
4753
|
-
this.window.removeEventListener("touchend", this.onWindowTouchEnd);
|
|
4754
|
-
this.window.removeEventListener("touchcancel", this.onWindowTouchCancel);
|
|
4755
|
-
}
|
|
4756
|
-
trySelectNode(event) {
|
|
4757
|
-
const nodeId = this.selectionCandidateNodeId;
|
|
4758
|
-
if (this.canvas.graph.hasNode(nodeId)) {
|
|
4759
|
-
this.onNodeSelected(nodeId);
|
|
4760
|
-
event.ignoreCanvasSelection = true;
|
|
4761
|
-
}
|
|
4762
|
-
}
|
|
4763
|
-
processMoveThresholdVerification(x, y, thresholdReachedCallback) {
|
|
4764
|
-
const distance = Math.sqrt(x * x + y * y);
|
|
4765
|
-
this.movedDistance += distance;
|
|
4766
|
-
if (this.movedDistance > this.movementThreshold) {
|
|
4767
|
-
thresholdReachedCallback();
|
|
4768
|
-
}
|
|
4769
|
-
}
|
|
4770
4839
|
}
|
|
4771
|
-
class
|
|
4772
|
-
constructor(canvas,
|
|
4773
|
-
__publicField(this, "
|
|
4774
|
-
__publicField(this, "
|
|
4775
|
-
__publicField(this, "
|
|
4776
|
-
__publicField(this, "
|
|
4777
|
-
|
|
4778
|
-
|
|
4779
|
-
__publicField(this, "previousTouch", null);
|
|
4780
|
-
__publicField(this, "onMouseDown", (event) => {
|
|
4781
|
-
const mouseEvent = event;
|
|
4782
|
-
if (!this.mouseDownEventVerifier(mouseEvent)) {
|
|
4783
|
-
return;
|
|
4784
|
-
}
|
|
4785
|
-
this.previousMouseDown = { x: mouseEvent.clientX, y: mouseEvent.clientY };
|
|
4786
|
-
this.movedDistance = 0;
|
|
4787
|
-
this.window.addEventListener("mousemove", this.onWindowMouseMove, {
|
|
4788
|
-
passive: true
|
|
4789
|
-
});
|
|
4790
|
-
this.window.addEventListener("mouseup", this.onWindowMouseUp, {
|
|
4791
|
-
passive: true
|
|
4792
|
-
});
|
|
4793
|
-
});
|
|
4794
|
-
__publicField(this, "onTouchStart", (event) => {
|
|
4795
|
-
const touchEvent = event;
|
|
4796
|
-
if (touchEvent.touches.length !== 1) {
|
|
4797
|
-
return;
|
|
4798
|
-
}
|
|
4799
|
-
const touch = touchEvent.touches[0];
|
|
4800
|
-
this.previousTouch = touch;
|
|
4801
|
-
this.movedDistance = 0;
|
|
4802
|
-
this.window.addEventListener("touchmove", this.onWindowTouchMove, {
|
|
4803
|
-
passive: true
|
|
4804
|
-
});
|
|
4805
|
-
this.window.addEventListener("touchend", this.onWindowTouchEnd, {
|
|
4806
|
-
passive: true
|
|
4807
|
-
});
|
|
4808
|
-
this.window.addEventListener("touchcancel", this.onWindowTouchCancel, {
|
|
4809
|
-
passive: true
|
|
4810
|
-
});
|
|
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);
|
|
4811
4848
|
});
|
|
4812
|
-
__publicField(this, "
|
|
4813
|
-
const
|
|
4814
|
-
|
|
4815
|
-
this.removeWindowMouseListeners();
|
|
4816
|
-
return;
|
|
4817
|
-
}
|
|
4818
|
-
const previous = this.previousMouseDown;
|
|
4819
|
-
const dx = mouseEvent.clientX - previous.x;
|
|
4820
|
-
const dy = mouseEvent.clientY - previous.y;
|
|
4821
|
-
this.processMoveThresholdVerification(dx, dy, () => {
|
|
4822
|
-
this.removeWindowMouseListeners();
|
|
4823
|
-
});
|
|
4824
|
-
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);
|
|
4825
4852
|
});
|
|
4826
|
-
__publicField(this, "
|
|
4827
|
-
|
|
4828
|
-
|
|
4829
|
-
this.
|
|
4830
|
-
return;
|
|
4831
|
-
}
|
|
4832
|
-
const touch = touchEvent.touches[0];
|
|
4833
|
-
if (!this.pointInsideVerifier.verify(touch.clientX, touch.clientY)) {
|
|
4834
|
-
this.removeWindowTouchListeners();
|
|
4835
|
-
return;
|
|
4836
|
-
}
|
|
4837
|
-
const previous = this.previousTouch;
|
|
4838
|
-
const dx = touch.clientX - previous.clientX;
|
|
4839
|
-
const dy = touch.clientY - previous.clientY;
|
|
4840
|
-
this.processMoveThresholdVerification(dx, dy, () => {
|
|
4841
|
-
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);
|
|
4842
4857
|
});
|
|
4843
|
-
this.previousTouch = touch;
|
|
4844
4858
|
});
|
|
4845
|
-
|
|
4846
|
-
|
|
4847
|
-
|
|
4848
|
-
|
|
4849
|
-
|
|
4850
|
-
|
|
4851
|
-
|
|
4852
|
-
|
|
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
|
|
4853
4876
|
}
|
|
4854
|
-
|
|
4855
|
-
|
|
4856
|
-
|
|
4857
|
-
|
|
4858
|
-
|
|
4859
|
-
|
|
4860
|
-
|
|
4861
|
-
|
|
4862
|
-
|
|
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);
|
|
4863
4898
|
__publicField(this, "restore", () => {
|
|
4864
|
-
this.
|
|
4865
|
-
this.element.removeEventListener("touchstart", this.onTouchStart);
|
|
4866
|
-
this.removeWindowMouseListeners();
|
|
4867
|
-
this.removeWindowTouchListeners();
|
|
4899
|
+
this.configurator.disable(this.element);
|
|
4868
4900
|
});
|
|
4869
4901
|
this.canvas = canvas;
|
|
4870
4902
|
this.element = element;
|
|
4871
4903
|
this.window = window2;
|
|
4872
4904
|
this.pointInsideVerifier = pointInsideVerifier;
|
|
4905
|
+
this.eventTagger = eventTagger;
|
|
4873
4906
|
this.onCanvasSelected = params.onCanvasSelected;
|
|
4874
|
-
this.
|
|
4875
|
-
|
|
4876
|
-
|
|
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);
|
|
4877
4922
|
this.canvas.onBeforeDestroy.subscribe(this.restore);
|
|
4878
|
-
this.element.addEventListener("mousedown", this.onMouseDown, {
|
|
4879
|
-
passive: true
|
|
4880
|
-
});
|
|
4881
|
-
this.element.addEventListener("touchstart", this.onTouchStart, {
|
|
4882
|
-
passive: true
|
|
4883
|
-
});
|
|
4884
4923
|
}
|
|
4885
|
-
static configure(canvas, element, window2, pointInsideVerifier, params) {
|
|
4924
|
+
static configure(canvas, element, window2, pointInsideVerifier, eventTagger, params) {
|
|
4886
4925
|
new UserSelectableCanvasConfigurator(
|
|
4887
4926
|
canvas,
|
|
4888
4927
|
element,
|
|
4889
4928
|
window2,
|
|
4890
4929
|
pointInsideVerifier,
|
|
4930
|
+
eventTagger,
|
|
4891
4931
|
params
|
|
4892
4932
|
);
|
|
4893
4933
|
}
|
|
4894
|
-
removeWindowMouseListeners() {
|
|
4895
|
-
this.window.removeEventListener("mousemove", this.onWindowMouseMove);
|
|
4896
|
-
this.window.removeEventListener("mouseup", this.onWindowMouseUp);
|
|
4897
|
-
}
|
|
4898
|
-
removeWindowTouchListeners() {
|
|
4899
|
-
this.window.removeEventListener("touchmove", this.onWindowTouchMove);
|
|
4900
|
-
this.window.removeEventListener("touchend", this.onWindowTouchEnd);
|
|
4901
|
-
this.window.removeEventListener("touchcancel", this.onWindowTouchCancel);
|
|
4902
|
-
}
|
|
4903
|
-
processMoveThresholdVerification(x, y, thresholdReachedCallback) {
|
|
4904
|
-
const distance = Math.sqrt(x * x + y * y);
|
|
4905
|
-
this.movedDistance += distance;
|
|
4906
|
-
if (this.movedDistance > this.movementThreshold) {
|
|
4907
|
-
thresholdReachedCallback();
|
|
4908
|
-
}
|
|
4909
|
-
}
|
|
4910
4934
|
}
|
|
4911
4935
|
const createHost = () => {
|
|
4912
4936
|
const host = document.createElement("div");
|
|
@@ -6720,6 +6744,14 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
6720
6744
|
movementThreshold: config.movementThreshold ?? selectionDefaults.movementThreshold
|
|
6721
6745
|
};
|
|
6722
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
|
+
};
|
|
6723
6755
|
class CanvasBuilder {
|
|
6724
6756
|
constructor(element) {
|
|
6725
6757
|
__publicField(this, "used", false);
|
|
@@ -6733,6 +6765,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
6733
6765
|
__publicField(this, "layoutConfig", {});
|
|
6734
6766
|
__publicField(this, "animatedLayoutConfig", {});
|
|
6735
6767
|
__publicField(this, "userSelectableNodesConfig");
|
|
6768
|
+
__publicField(this, "userSelectableEdgesConfig");
|
|
6736
6769
|
__publicField(this, "userSelectableCanvasConfig");
|
|
6737
6770
|
__publicField(this, "hasDraggableNodes", false);
|
|
6738
6771
|
__publicField(this, "hasTransformableViewport", false);
|
|
@@ -6746,6 +6779,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
6746
6779
|
__publicField(this, "window", window);
|
|
6747
6780
|
__publicField(this, "animationStaticNodes", /* @__PURE__ */ new Set());
|
|
6748
6781
|
__publicField(this, "pointInsideVerifier");
|
|
6782
|
+
__publicField(this, "eventTagger", new EventTagger());
|
|
6749
6783
|
this.element = element;
|
|
6750
6784
|
this.pointInsideVerifier = new PointInsideVerifier(element, this.window);
|
|
6751
6785
|
}
|
|
@@ -6802,6 +6836,10 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
6802
6836
|
this.userSelectableNodesConfig = config;
|
|
6803
6837
|
return this;
|
|
6804
6838
|
}
|
|
6839
|
+
enableUserSelectableEdges(config) {
|
|
6840
|
+
this.userSelectableEdgesConfig = config;
|
|
6841
|
+
return this;
|
|
6842
|
+
}
|
|
6805
6843
|
enableUserSelectableCanvas(config) {
|
|
6806
6844
|
this.userSelectableCanvasConfig = config;
|
|
6807
6845
|
return this;
|
|
@@ -6859,6 +6897,18 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
6859
6897
|
if (this.hasNodeResizeReactiveEdges) {
|
|
6860
6898
|
NodeResizeReactiveEdgesConfigurator.configure(canvas);
|
|
6861
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
|
+
}
|
|
6862
6912
|
if (this.userSelectableNodesConfig !== void 0) {
|
|
6863
6913
|
const params = createUserSelectableNodesParams(
|
|
6864
6914
|
this.userSelectableNodesConfig
|
|
@@ -6867,6 +6917,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
6867
6917
|
canvas,
|
|
6868
6918
|
this.window,
|
|
6869
6919
|
this.pointInsideVerifier,
|
|
6920
|
+
this.eventTagger,
|
|
6870
6921
|
params
|
|
6871
6922
|
);
|
|
6872
6923
|
}
|
|
@@ -6879,6 +6930,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
6879
6930
|
layers.main,
|
|
6880
6931
|
this.window,
|
|
6881
6932
|
this.pointInsideVerifier,
|
|
6933
|
+
this.eventTagger,
|
|
6882
6934
|
params
|
|
6883
6935
|
);
|
|
6884
6936
|
}
|