react-reorder-list 0.6.2 → 0.6.4

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/hooks.d.ts CHANGED
@@ -1,6 +1,10 @@
1
- import { DetailedHTMLProps, HTMLAttributes } from "react";
2
- export type Props = DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>;
3
- export default function useDraggable(initValue?: boolean): {
1
+ import { MouseEvent, TouchEvent } from "react";
2
+ export declare function useDraggable(initValue?: boolean): {
4
3
  draggable: boolean;
5
- draggableProps: Props;
4
+ draggableProps: {
5
+ onMouseEnter: (event: MouseEvent | TouchEvent) => void;
6
+ onMouseLeave: (event: MouseEvent | TouchEvent) => void;
7
+ onTouchStart: (event: MouseEvent | TouchEvent) => void;
8
+ onTouchEnd: (event: MouseEvent | TouchEvent) => void;
9
+ };
6
10
  };
package/dist/hooks.js CHANGED
@@ -1,8 +1,14 @@
1
1
  import { useState } from "react";
2
- export default function useDraggable(initValue = false) {
2
+ export function useDraggable(initValue = false) {
3
3
  const [draggable, setDraggable] = useState(initValue);
4
- const enableDragging = () => setDraggable(true);
5
- const disableDragging = () => setDraggable(false);
4
+ const enableDragging = (event) => {
5
+ event.stopPropagation();
6
+ setDraggable(true);
7
+ };
8
+ const disableDragging = (event) => {
9
+ event.stopPropagation();
10
+ setDraggable(false);
11
+ };
6
12
  const draggableProps = { onMouseEnter: enableDragging, onMouseLeave: disableDragging, onTouchStart: enableDragging, onTouchEnd: disableDragging };
7
13
  return { draggable, draggableProps };
8
14
  }
package/dist/index.d.ts CHANGED
@@ -1,6 +1,5 @@
1
- import React, { ReactNode } from "react";
2
- import { Props } from "./hooks.js";
3
- export type { Props } from "./hooks.js";
1
+ import React, { DetailedHTMLProps, HTMLAttributes, ReactNode } from "react";
2
+ export type Props = DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>;
4
3
  export type PositionChangeHandler = (params?: {
5
4
  start?: number;
6
5
  end?: number;
package/dist/index.js CHANGED
@@ -12,7 +12,7 @@ var __rest = (this && this.__rest) || function (s, e) {
12
12
  import React, { Children, cloneElement, createRef, forwardRef, isValidElement, useEffect, useMemo, useRef, useState } from "react";
13
13
  import { PiDotsSixVerticalBold } from "./icons.js";
14
14
  import Animation from "./animation.js";
15
- import useDraggable from "./hooks.js";
15
+ import { useDraggable } from "./hooks.js";
16
16
  if (typeof window !== "undefined")
17
17
  import("drag-drop-touch");
18
18
  const scrollThreshold = { x: 10, y: 100 };
@@ -90,6 +90,9 @@ export default function ReorderList({ useOnlyIconToDrag = false, selectedItemOpa
90
90
  setIsAnimating(true);
91
91
  setTimeout(() => setIsAnimating(false), animationDuration);
92
92
  }, onDragEnd: handleDragEnd, onTouchMove: (event) => {
93
+ event.stopPropagation();
94
+ if (start === -1)
95
+ return;
93
96
  const { clientX, screenX, clientY, screenY } = event.touches[0];
94
97
  let left = 0, top = 0;
95
98
  if (clientX < scrollThreshold.x)
@@ -107,6 +110,8 @@ export default function ReorderList({ useOnlyIconToDrag = false, selectedItemOpa
107
110
  function ReorderItem(_a, ref) {
108
111
  var { useOnlyIconToDrag, onTouchEnd: propOnTouchEnd, children } = _a, props = __rest(_a, ["useOnlyIconToDrag", "onTouchEnd", "children"]);
109
112
  const _b = useDraggable(), { draggable } = _b, _c = _b.draggableProps, { onTouchEnd: draggableOnTouchEnd } = _c, draggableProps = __rest(_c, ["onTouchEnd"]);
113
+ if (!draggable)
114
+ props.onDragStart = undefined;
110
115
  const recursiveClone = (children) => Children.map(children, (child) => {
111
116
  if (!isValidElement(child))
112
117
  return child;
@@ -114,6 +119,7 @@ function ReorderItem(_a, ref) {
114
119
  });
115
120
  const recursiveChildren = useMemo(() => (useOnlyIconToDrag ? recursiveClone(children) : children), [useOnlyIconToDrag, children]);
116
121
  return (React.createElement("div", Object.assign({ ref: ref, draggable: draggable }, props, (!useOnlyIconToDrag && draggableProps), { onTouchEnd: (event) => {
122
+ event.stopPropagation();
117
123
  draggableOnTouchEnd(event);
118
124
  propOnTouchEnd(event);
119
125
  } }), recursiveChildren));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-reorder-list",
3
- "version": "0.6.2",
3
+ "version": "0.6.4",
4
4
  "description": "A simple react component that facilitates the reordering of JSX/HTML elements through drag-and-drop functionality, allowing for easy position changes.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -26,11 +26,10 @@
26
26
  },
27
27
  "homepage": "https://github.com/SahilAggarwal2004/react-reorder-list#readme",
28
28
  "peerDependencies": {
29
- "react": ">=16.0.0",
30
- "react-dom": ">=16.0.0"
29
+ "react": ">=16.0.0"
31
30
  },
32
31
  "devDependencies": {
33
- "@types/react": "^18.2.48"
32
+ "@types/react": "^18.2.54"
34
33
  },
35
34
  "dependencies": {
36
35
  "drag-drop-touch": "^1.3.1"