Skip to content

Commit

Permalink
Update main.ts MouseDragComponent
Browse files Browse the repository at this point in the history
  • Loading branch information
gastonmorixe authored Oct 22, 2024
1 parent e89cddc commit acf25b1
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -639,9 +639,9 @@ class ChartSystem extends System {
class DOMMouseDragHandler {
initializeDragListeners(entity: Entity) {
const domComponent = entity.getComponent(DOMComponent);
const mouseDrag = entity.getComponent(MouseDragForceComponent);
const mouseDrag = entity.getComponent(MouseDragComponent);
const position = entity.getComponent(PositionComponent);

if (!domComponent || !mouseDrag || !position) return;

const domElement = domComponent.domElement;
Expand Down Expand Up @@ -671,7 +671,7 @@ class DOMMouseDragHandler {

onMouseDown(
event: MouseEvent,
mouseDragComponent: MouseDragForceComponent,
mouseDragComponent: MouseDragComponent,
position: PositionComponent,
element: HTMLElement,
) {
Expand All @@ -688,7 +688,7 @@ class DOMMouseDragHandler {
); // Set initial target
}

onMouseMove(event: MouseEvent, mouseDragComponent: MouseDragForceComponent) {
onMouseMove(event: MouseEvent, mouseDragComponent: MouseDragComponent) {
if (mouseDragComponent.isDragging) {
// Update the target, accounting for the initial offset
mouseDragComponent.setTarget(
Expand All @@ -698,15 +698,15 @@ class DOMMouseDragHandler {
}
}

onMouseUp(mouseDragComponent: MouseDragForceComponent, element: HTMLElement) {
onMouseUp(mouseDragComponent: MouseDragComponent, element: HTMLElement) {
element.classList.remove("dragging");
mouseDragComponent.stopDrag();
}

// Touch event equivalents
onTouchStart(
event: TouchEvent,
mouseDragComponent: MouseDragForceComponent,
mouseDragComponent: MouseDragComponent,
position: PositionComponent,
element: HTMLElement,
) {
Expand All @@ -726,7 +726,7 @@ class DOMMouseDragHandler {
); // Set initial target
}

onTouchMove(event: TouchEvent, mouseDragComponent: MouseDragForceComponent) {
onTouchMove(event: TouchEvent, mouseDragComponent: MouseDragComponent) {
if (mouseDragComponent.isDragging) {
event.preventDefault(); // Prevent scrolling
const touch = event.touches[0]; // Get the first touch point
Expand All @@ -739,7 +739,7 @@ class DOMMouseDragHandler {
}
}

onTouchEnd(mouseDragComponent: MouseDragForceComponent, element: HTMLElement) {
onTouchEnd(mouseDragComponent: MouseDragComponent, element: HTMLElement) {
element.classList.remove("dragging");
mouseDragComponent.stopDrag();
}
Expand Down

0 comments on commit acf25b1

Please sign in to comment.