Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add activatorEvent to resize events #58

Merged
merged 1 commit into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions packages/dnd-timeline/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@
"url": "https://github.com/samuelarbibe/dnd-timeline"
},
"homepage": "https://samuel-arbibe.gitbook.io/dnd-timeline/",
"files": [
"dist",
"src"
],
"files": ["dist", "src"],
"scripts": {
"build": "tsup src/index.tsx --format esm,cjs --dts --external react",
"clean": "rm -rf dist",
Expand Down
9 changes: 6 additions & 3 deletions packages/dnd-timeline/src/hooks/useItem.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useDraggable } from "@dnd-kit/core";
import { CSS } from "@dnd-kit/utilities";
import type { CSSProperties, PointerEventHandler } from "react";
import type { CSSProperties, PointerEvent, PointerEventHandler } from "react";
import { useCallback, useLayoutEffect, useRef, useState } from "react";

import type {
Expand Down Expand Up @@ -112,7 +112,7 @@ export default function useItem(props: UseItemProps) {
useLayoutEffect(() => {
if (!dragDirection) return;

const pointermoveHandler = (event: PointerEvent) => {
const pointermoveHandler = (event: globalThis.PointerEvent) => {
if (!dragStartX.current || !draggableProps.node.current) return;

const dragDeltaX =
Expand All @@ -131,6 +131,7 @@ export default function useItem(props: UseItemProps) {
}

onResizeMoveCallback({
activatorEvent: event,
delta: {
x: dragDeltaX,
},
Expand Down Expand Up @@ -161,7 +162,7 @@ export default function useItem(props: UseItemProps) {
useLayoutEffect(() => {
if (!dragDirection) return;

const pointerupHandler = () => {
const pointerupHandler = (event: globalThis.PointerEvent) => {
if (!dragStartX.current || !draggableProps.node.current) return;

let dragDeltaX = 0;
Expand All @@ -179,6 +180,7 @@ export default function useItem(props: UseItemProps) {
}

onResizeEndCallback({
activatorEvent: event,
delta: {
x: dragDeltaX,
},
Expand Down Expand Up @@ -246,6 +248,7 @@ export default function useItem(props: UseItemProps) {
dragStartX.current = event.clientX;

onResizeStartCallback({
activatorEvent: event as unknown as Event,
active: {
id: props.id,
data: dataRef,
Expand Down
2 changes: 2 additions & 0 deletions packages/dnd-timeline/src/types/resize.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { DragDirection, ResizeActiveItem } from ".";

export interface ResizeMoveEvent {
activatorEvent: Event;
active: ResizeActiveItem;
delta: {
x: number;
Expand All @@ -11,6 +12,7 @@ export interface ResizeMoveEvent {
export type ResizeEndEvent = ResizeMoveEvent;

export interface ResizeStartEvent {
activatorEvent: Event;
samuelarbibe marked this conversation as resolved.
Show resolved Hide resolved
active: ResizeActiveItem;
direction: DragDirection;
}
Loading