react-reorder-list 0.7.2 → 0.8.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/CHANGELOG.md ADDED
@@ -0,0 +1,56 @@
1
+ # 0.8.0 (06-12-2024)
2
+
3
+ - **breaking:** Dropped support for React.js v18 in favor of React.js v19.
4
+
5
+ ## 0.7.2 (16-04-2024)
6
+
7
+ - **change:** Switched from [pnpm](https://pnpm.io/) to [bun](https://bun.sh).
8
+
9
+ ## 0.7.0 (24-03-2024)
10
+
11
+ - **feat:** Added `data-disable-reorder` prop for children of the `<ReorderList>` component. See [usage with data-disable-reorder](https://www.npmjs.com/package/react-reorder-list#disable-reordering-for-individual-children).
12
+
13
+ ## 0.6.7 (21-03-2024)
14
+
15
+ - **remove:** Support for invalid React elements.
16
+
17
+ ## 0.6.3 (05-02-2024)
18
+
19
+ - **fix:** Minor scrolling bug occurring on touch devices.
20
+
21
+ ## 0.6.1 (03-02-2024)
22
+
23
+ - **fix:** Minor bugs.
24
+
25
+ ## 0.6.0 (27-01-2024)
26
+
27
+ - **feat:** Added support for touch devices.
28
+
29
+ ## 0.5.0 (26-01-2024)
30
+
31
+ - **feat:** Added `preserveOrder` prop in the `<ReorderList>` component. See [ReorderList Component API Reference](https://www.npmjs.com/package/react-reorder-list#reorderlist-component-api-reference).
32
+ - **fix:** A bug where the library would not work in production if `useOnlyIconToDrag` was set to `true`.
33
+
34
+ ## 0.4.0 (26-01-2024)
35
+
36
+ - **feat:** Added `revert` handler/function in the params of the `onPositionChange` handler. See type [PositionChangeHandler](https://www.npmjs.com/package/react-reorder-list#positionchangehandler).
37
+
38
+ ## 0.3.1 (25-01-2024)
39
+
40
+ - **change:** Renamed `disable` prop to `disabled`. See [ReorderList Component API Reference](https://www.npmjs.com/package/react-reorder-list#reorderlist-component-api-reference).
41
+ - **fixed:** Minor bugs.
42
+
43
+ ## 0.3.0 (24-01-2024)
44
+
45
+ - **feat:** Added `watchChildrenUpdates` prop in `<ReorderList>`. See [ReorderList Component API Reference](https://www.npmjs.com/package/react-reorder-list#reorderlist-component-api-reference).
46
+ - **improve:** Overall stability.
47
+
48
+ ## 0.2.0 (23-01-2024)
49
+
50
+ - **feat:** Added `animationDuration` prop in `<ReorderList>` component. See [ReorderList Component API Reference](https://www.npmjs.com/package/react-reorder-list#reorderlist-component-api-reference).
51
+ - **change:** Default value of the `useOnlyIconToDrag` prop to `false`. See [ReorderList Component API Reference](https://www.npmjs.com/package/react-reorder-list#reorderlist-component-api-reference).
52
+ - **improve:** Overall stability.
53
+
54
+ ## 0.1.2 (21-01-2024)
55
+
56
+ - **docs:** Added more details on [usage with ReorderIcon](https://www.npmjs.com/package/react-reorder-list#usage-with-reordericon).
package/dist/animation.js CHANGED
@@ -6,7 +6,7 @@ function calculateBoundingBoxes(children) {
6
6
  Children.forEach(children, (child) => {
7
7
  const key = getKey(child);
8
8
  if (key)
9
- boundingBoxes[key] = child.ref.current.getBoundingClientRect();
9
+ boundingBoxes[key] = child.props.ref.current.getBoundingClientRect();
10
10
  });
11
11
  return boundingBoxes;
12
12
  }
@@ -22,11 +22,10 @@ export default function Animation({ duration, children }) {
22
22
  useLayoutEffect(() => {
23
23
  if (duration > 0 && prevBoundingBox && Object.keys(prevBoundingBox).length)
24
24
  Children.forEach(children, (child) => {
25
- var _a;
26
- const domNode = (_a = child === null || child === void 0 ? void 0 : child.ref) === null || _a === void 0 ? void 0 : _a.current;
27
25
  const key = getKey(child);
28
26
  if (!key)
29
27
  return;
28
+ const domNode = child.props.ref.current;
30
29
  const { left: prevLeft, top: prevTop } = prevBoundingBox[key] || {};
31
30
  const { left, top } = boundingBox[key];
32
31
  const changeInX = prevLeft - left, changeInY = prevTop - top;
@@ -0,0 +1,4 @@
1
+ export declare const scrollThreshold: {
2
+ x: number;
3
+ y: number;
4
+ };
@@ -0,0 +1 @@
1
+ export const scrollThreshold = { x: 10, y: 100 };
package/dist/hooks.d.ts CHANGED
@@ -4,4 +4,4 @@ export declare function useDraggable(initValue?: boolean): readonly [boolean, {
4
4
  onTouchStart: () => void;
5
5
  onTouchEnd: () => void;
6
6
  }];
7
- export declare function usePrevious<T>(value: T): T | undefined;
7
+ export declare function usePrevious<T>(value: T): T | null;
package/dist/hooks.js CHANGED
@@ -7,7 +7,7 @@ export function useDraggable(initValue = false) {
7
7
  return [draggable, draggableProps];
8
8
  }
9
9
  export function usePrevious(value) {
10
- const prevChildrenRef = useRef();
10
+ const prevChildrenRef = useRef(null);
11
11
  useEffect(() => {
12
12
  prevChildrenRef.current = value;
13
13
  }, [value]);
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import React, { CSSProperties, DetailedHTMLProps, DragEventHandler, HTMLAttributes, ReactNode, TouchEventHandler } from "react";
1
+ import { CSSProperties, DetailedHTMLProps, DragEventHandler, HTMLAttributes, JSX, ReactNode, RefObject, TouchEventHandler } from "react";
2
2
  export type Props = DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>;
3
3
  export type PositionChangeHandler = (params?: {
4
4
  start?: number;
@@ -23,6 +23,7 @@ export type DivTouchEventHandler = TouchEventHandler<HTMLDivElement>;
23
23
  export type ReorderItemProps = {
24
24
  useOnlyIconToDrag: boolean;
25
25
  disable: boolean;
26
+ ref: RefObject<HTMLDivElement | null>;
26
27
  style: CSSProperties;
27
28
  onDragStart?: DivDragEventHandler;
28
29
  onDragEnter: DivDragEventHandler;
@@ -32,5 +33,5 @@ export type ReorderItemProps = {
32
33
  children: ReactNode;
33
34
  };
34
35
  export type { IconProps } from "./icons.js";
35
- export default function ReorderList({ useOnlyIconToDrag, selectedItemOpacity, animationDuration, watchChildrenUpdates, preserveOrder, onPositionChange, disabled, props, children }: ReorderListProps): React.JSX.Element;
36
- export declare function ReorderIcon({ children, style, ...props }: Props): React.JSX.Element;
36
+ export declare function ReorderIcon({ children, style, ...props }: Props): JSX.Element;
37
+ export default function ReorderList({ useOnlyIconToDrag, selectedItemOpacity, animationDuration, watchChildrenUpdates, preserveOrder, onPositionChange, disabled, props, children }: ReorderListProps): JSX.Element;
package/dist/index.js CHANGED
@@ -9,15 +9,34 @@ var __rest = (this && this.__rest) || function (s, e) {
9
9
  }
10
10
  return t;
11
11
  };
12
- import React, { Children, cloneElement, createRef, forwardRef, isValidElement, useEffect, useMemo, useRef, useState } from "react";
12
+ import React, { Children, cloneElement, createRef, isValidElement, useEffect, useMemo, useRef, useState } from "react";
13
13
  import Animation from "./animation.js";
14
- import { PiDotsSixVerticalBold } from "./icons.js";
14
+ import { scrollThreshold } from "./constants.js";
15
15
  import { useDraggable } from "./hooks.js";
16
+ import { PiDotsSixVerticalBold } from "./icons.js";
16
17
  import { swap } from "./utils.js";
17
18
  if (typeof window !== "undefined")
18
19
  import("drag-drop-touch");
19
- const scrollThreshold = { x: 10, y: 100 };
20
- const ReorderItemRef = forwardRef(ReorderItem);
20
+ export function ReorderIcon(_a) {
21
+ var { children = React.createElement(PiDotsSixVerticalBold, null), style } = _a, props = __rest(_a, ["children", "style"]);
22
+ return (React.createElement("span", Object.assign({ style: Object.assign({ cursor: "grab" }, style) }, props), children));
23
+ }
24
+ function ReorderItem(_a) {
25
+ var { useOnlyIconToDrag, disable, ref, style, children, onTouchEnd: propOnTouchEnd } = _a, events = __rest(_a, ["useOnlyIconToDrag", "disable", "ref", "style", "children", "onTouchEnd"]);
26
+ const [draggable, _b] = useDraggable(), { onTouchEnd: draggableOnTouchEnd } = _b, draggableProps = __rest(_b, ["onTouchEnd"]);
27
+ if (!draggable)
28
+ events.onDragStart = undefined;
29
+ const recursiveClone = (children) => Children.map(children, (child) => {
30
+ if (!isValidElement(child))
31
+ return child;
32
+ return cloneElement(child, child.type === ReorderIcon ? draggableProps : {}, recursiveClone(child.props.children));
33
+ });
34
+ const recursiveChildren = useMemo(() => (useOnlyIconToDrag ? recursiveClone(children) : children), [useOnlyIconToDrag, children]);
35
+ return (React.createElement("div", Object.assign({ ref: ref, draggable: !disable && draggable, style: style }, (!disable && Object.assign(Object.assign(Object.assign({}, events), (!useOnlyIconToDrag && draggableProps)), { onTouchEnd: (event) => {
36
+ draggableOnTouchEnd();
37
+ propOnTouchEnd(event);
38
+ } }))), recursiveChildren));
39
+ }
21
40
  export default function ReorderList({ useOnlyIconToDrag = false, selectedItemOpacity = 0.5, animationDuration = 400, watchChildrenUpdates = false, preserveOrder = false, onPositionChange, disabled = false, props, children }) {
22
41
  const ref = useRef(null);
23
42
  const [start, setStart] = useState(-1);
@@ -72,11 +91,12 @@ export default function ReorderList({ useOnlyIconToDrag = false, selectedItemOpa
72
91
  return (React.createElement("div", Object.assign({ ref: ref }, props), disabled ? (children) : (React.createElement(Animation, { duration: +(start !== -1 && !scroll) && animationDuration }, items.map((child, i) => {
73
92
  if (!isValidElement(child))
74
93
  return child;
75
- return (React.createElement(ReorderItemRef, { key: child.key, ref: refs[i], useOnlyIconToDrag: useOnlyIconToDrag, disable: disableArr[i], style: { opacity: selected === i ? selectedItemOpacity : 1, touchAction: "pan-y" }, onDragStart: (event) => {
94
+ return (React.createElement(ReorderItem, { key: child.key, ref: refs[i], useOnlyIconToDrag: useOnlyIconToDrag, disable: disableArr[i], style: { opacity: selected === i ? selectedItemOpacity : 1, touchAction: "pan-y" }, onDragStart: (event) => {
95
+ var _a, _b;
76
96
  event.stopPropagation();
77
97
  setStart(i);
78
98
  setSelected(i);
79
- setTemp({ items, rect: ref.current.children[i].getBoundingClientRect() });
99
+ setTemp({ items, rect: ((_b = (_a = ref.current.childNodes[i]).getBoundingClientRect) === null || _b === void 0 ? void 0 : _b.call(_a)) || {} });
80
100
  }, onDragEnter: (event) => {
81
101
  event.stopPropagation();
82
102
  if (start === -1 || selected === i || isAnimating)
@@ -118,23 +138,3 @@ export default function ReorderList({ useOnlyIconToDrag = false, selectedItemOpa
118
138
  }, onTouchEnd: () => setScroll(undefined) }, child));
119
139
  })))));
120
140
  }
121
- function ReorderItem(_a, ref) {
122
- var { useOnlyIconToDrag, disable, style, children, onTouchEnd: propOnTouchEnd } = _a, events = __rest(_a, ["useOnlyIconToDrag", "disable", "style", "children", "onTouchEnd"]);
123
- const [draggable, _b] = useDraggable(), { onTouchEnd: draggableOnTouchEnd } = _b, draggableProps = __rest(_b, ["onTouchEnd"]);
124
- if (!draggable)
125
- events.onDragStart = undefined;
126
- const recursiveClone = (children) => Children.map(children, (child) => {
127
- if (!isValidElement(child))
128
- return child;
129
- return cloneElement(child, child.type === ReorderIcon ? draggableProps : {}, recursiveClone(child.props.children));
130
- });
131
- const recursiveChildren = useMemo(() => (useOnlyIconToDrag ? recursiveClone(children) : children), [useOnlyIconToDrag, children]);
132
- return (React.createElement("div", Object.assign({ ref: ref, draggable: !disable && draggable, style: style }, (!disable && Object.assign(Object.assign(Object.assign({}, events), (!useOnlyIconToDrag && draggableProps)), { onTouchEnd: (event) => {
133
- draggableOnTouchEnd();
134
- propOnTouchEnd(event);
135
- } }))), recursiveChildren));
136
- }
137
- export function ReorderIcon(_a) {
138
- var { children = React.createElement(PiDotsSixVerticalBold, null), style } = _a, props = __rest(_a, ["children", "style"]);
139
- return (React.createElement("span", Object.assign({ style: Object.assign({ cursor: "grab" }, style) }, props), children));
140
- }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-reorder-list",
3
- "version": "0.7.2",
3
+ "version": "0.8.0",
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",
@@ -32,9 +32,9 @@
32
32
  "react": ">=17.0.0"
33
33
  },
34
34
  "devDependencies": {
35
- "@types/react": "^18.2.79"
35
+ "@types/react": "^19.0.0"
36
36
  },
37
37
  "dependencies": {
38
38
  "drag-drop-touch": "^1.3.1"
39
39
  }
40
- }
40
+ }