react-reorder-list 0.10.2 → 0.10.3
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/index.d.mts +1 -1
- package/dist/index.mjs +10 -15
- package/dist/types-CRxTdmXH.d.mts +50 -0
- package/dist/types.d.mts +1 -49
- package/dist/types.mjs +1 -1
- package/package.json +3 -4
package/dist/index.d.mts
CHANGED
package/dist/index.mjs
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import React, { Children, cloneElement, createRef, isValidElement, useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
2
|
-
|
|
3
2
|
//#region src/constants.ts
|
|
4
3
|
const scrollThreshold = {
|
|
5
4
|
x: 10,
|
|
6
5
|
y: 100
|
|
7
6
|
};
|
|
8
|
-
|
|
9
7
|
//#endregion
|
|
10
8
|
//#region src/hooks.ts
|
|
11
9
|
function useDraggable(initValue = false) {
|
|
@@ -33,7 +31,6 @@ function useStateWithHistory(initValue) {
|
|
|
33
31
|
setStateWithHistory
|
|
34
32
|
];
|
|
35
33
|
}
|
|
36
|
-
|
|
37
34
|
//#endregion
|
|
38
35
|
//#region src/icons.tsx
|
|
39
36
|
function PiDotsSixVerticalBold(props) {
|
|
@@ -44,7 +41,6 @@ function PiDotsSixVerticalBold(props) {
|
|
|
44
41
|
height: "1.25rem"
|
|
45
42
|
}, /* @__PURE__ */ React.createElement("path", { d: "M108,60A16,16,0,1,1,92,44,16,16,0,0,1,108,60Zm56,16a16,16,0,1,0-16-16A16,16,0,0,0,164,76ZM92,112a16,16,0,1,0,16,16A16,16,0,0,0,92,112Zm72,0a16,16,0,1,0,16,16A16,16,0,0,0,164,112ZM92,180a16,16,0,1,0,16,16A16,16,0,0,0,92,180Zm72,0a16,16,0,1,0,16,16A16,16,0,0,0,164,180Z" })));
|
|
46
43
|
}
|
|
47
|
-
|
|
48
44
|
//#endregion
|
|
49
45
|
//#region src/lib/react.ts
|
|
50
46
|
function calculateBoundingBoxes(children) {
|
|
@@ -55,7 +51,6 @@ function calculateBoundingBoxes(children) {
|
|
|
55
51
|
});
|
|
56
52
|
return boundingBoxes;
|
|
57
53
|
}
|
|
58
|
-
|
|
59
54
|
//#endregion
|
|
60
55
|
//#region src/lib/utils.ts
|
|
61
56
|
const areOrdersEqual = (a, b) => a.length === b.length && a.every((key, index) => key === b[index]);
|
|
@@ -64,7 +59,6 @@ function swap(array, i, j) {
|
|
|
64
59
|
array[i] = array[j];
|
|
65
60
|
array[j] = temp;
|
|
66
61
|
}
|
|
67
|
-
|
|
68
62
|
//#endregion
|
|
69
63
|
//#region src/components.tsx
|
|
70
64
|
if (typeof window !== "undefined") import("drag-drop-touch");
|
|
@@ -78,7 +72,7 @@ function Animation({ duration, children }) {
|
|
|
78
72
|
if (duration <= 0 || !prevBoundingBox || !Object.keys(prevBoundingBox).length) return;
|
|
79
73
|
children.forEach((child) => {
|
|
80
74
|
const { key } = child;
|
|
81
|
-
if (
|
|
75
|
+
if (key == null) return;
|
|
82
76
|
const domNode = child.props.ref.current;
|
|
83
77
|
if (!domNode) return;
|
|
84
78
|
const { left: prevLeft, top: prevTop } = prevBoundingBox[key] || {};
|
|
@@ -144,8 +138,7 @@ function ReorderList({ useOnlyIconToDrag = false, selectedItemOpacity = .5, anim
|
|
|
144
138
|
Children.forEach(children, (child) => {
|
|
145
139
|
if (!isValidElement(child)) return;
|
|
146
140
|
const { key, props } = child;
|
|
147
|
-
if (
|
|
148
|
-
map.set(key, {
|
|
141
|
+
if (key != null) map.set(key, {
|
|
149
142
|
child,
|
|
150
143
|
disabled: props["data-disable-reorder"]
|
|
151
144
|
});
|
|
@@ -155,8 +148,9 @@ function ReorderList({ useOnlyIconToDrag = false, selectedItemOpacity = .5, anim
|
|
|
155
148
|
const orderedChildren = useMemo(() => {
|
|
156
149
|
if (!order.length) return [];
|
|
157
150
|
return order.flatMap((key, orderIndex) => {
|
|
158
|
-
const
|
|
159
|
-
if (!
|
|
151
|
+
const entry = childMap.get(key);
|
|
152
|
+
if (!entry) return [];
|
|
153
|
+
const { child, disabled } = entry;
|
|
160
154
|
const ref = getRef(key);
|
|
161
155
|
const isSelected = dragState?.currentIndex === orderIndex;
|
|
162
156
|
return /* @__PURE__ */ React.createElement(ReorderItem, {
|
|
@@ -247,13 +241,15 @@ function ReorderList({ useOnlyIconToDrag = false, selectedItemOpacity = .5, anim
|
|
|
247
241
|
useEffect(() => {
|
|
248
242
|
const currentKeys = [];
|
|
249
243
|
Children.forEach(children, (child) => {
|
|
244
|
+
if (!isValidElement(child)) return;
|
|
250
245
|
const { key } = child;
|
|
251
|
-
if (key) currentKeys.push(key);
|
|
246
|
+
if (key != null) currentKeys.push(key);
|
|
252
247
|
});
|
|
253
248
|
let newOrder;
|
|
254
249
|
if (preserveOrder) {
|
|
255
250
|
const currentKeySet = new Set(currentKeys);
|
|
256
|
-
const
|
|
251
|
+
const orderSet = new Set(order);
|
|
252
|
+
const newKeys = currentKeys.filter((key) => !orderSet.has(key));
|
|
257
253
|
newOrder = [...order.filter((key) => currentKeySet.has(key)), ...newKeys];
|
|
258
254
|
} else newOrder = currentKeys;
|
|
259
255
|
if (!areOrdersEqual(order, newOrder)) {
|
|
@@ -279,6 +275,5 @@ function ReorderList({ useOnlyIconToDrag = false, selectedItemOpacity = .5, anim
|
|
|
279
275
|
...props
|
|
280
276
|
}, disabled ? children : /* @__PURE__ */ React.createElement(Animation, { duration: dragState && !scroll ? animationDuration : 0 }, orderedChildren));
|
|
281
277
|
}
|
|
282
|
-
|
|
283
278
|
//#endregion
|
|
284
|
-
export { ReorderIcon, ReorderList as default };
|
|
279
|
+
export { ReorderIcon, ReorderList as default };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { CSSProperties, DetailedHTMLProps, DragEventHandler, HTMLAttributes, Key, MouseEventHandler, ReactElement, ReactNode, RefObject, TouchEventHandler } from "react";
|
|
2
|
+
|
|
3
|
+
//#region src/types.d.ts
|
|
4
|
+
type AnimationProps = {
|
|
5
|
+
duration: number;
|
|
6
|
+
children: Child[];
|
|
7
|
+
};
|
|
8
|
+
type BoundingBox = Record<string, DOMRect>;
|
|
9
|
+
type Child = ReactElement<{
|
|
10
|
+
ref: RefObject<HTMLElement>;
|
|
11
|
+
}>;
|
|
12
|
+
type Order = Key[];
|
|
13
|
+
type DivDragEventHandler = DragEventHandler<HTMLDivElement>;
|
|
14
|
+
type DivMouseEventHandler = MouseEventHandler<HTMLDivElement>;
|
|
15
|
+
type DivProps = DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>;
|
|
16
|
+
type DivRef = RefObject<HTMLDivElement | null>;
|
|
17
|
+
type DivTouchEventHandler = TouchEventHandler<HTMLDivElement>;
|
|
18
|
+
type PositionChangeHandler = (event: {
|
|
19
|
+
start: number;
|
|
20
|
+
end: number;
|
|
21
|
+
oldOrder: Order;
|
|
22
|
+
newOrder: Order;
|
|
23
|
+
revert: RevertHandler;
|
|
24
|
+
}) => void;
|
|
25
|
+
type ReorderItemProps = {
|
|
26
|
+
useOnlyIconToDrag: boolean;
|
|
27
|
+
disable?: boolean;
|
|
28
|
+
ref: DivRef;
|
|
29
|
+
style: CSSProperties;
|
|
30
|
+
onDragStart?: DivDragEventHandler;
|
|
31
|
+
onDragEnter: DivDragEventHandler;
|
|
32
|
+
onDragEnd: DivDragEventHandler;
|
|
33
|
+
onTouchMove: DivTouchEventHandler;
|
|
34
|
+
onTouchEnd: DivTouchEventHandler;
|
|
35
|
+
children: ReactNode;
|
|
36
|
+
};
|
|
37
|
+
type ReorderListProps = {
|
|
38
|
+
useOnlyIconToDrag?: boolean;
|
|
39
|
+
selectedItemOpacity?: number;
|
|
40
|
+
animationDuration?: number;
|
|
41
|
+
preserveOrder?: boolean;
|
|
42
|
+
onPositionChange?: PositionChangeHandler;
|
|
43
|
+
disabled?: boolean;
|
|
44
|
+
props?: DivProps;
|
|
45
|
+
children?: ReactNode;
|
|
46
|
+
};
|
|
47
|
+
type RevertHandler = () => void;
|
|
48
|
+
type IconProps = React.DetailedHTMLProps<React.HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>;
|
|
49
|
+
//#endregion
|
|
50
|
+
export { DivMouseEventHandler as a, DivTouchEventHandler as c, PositionChangeHandler as d, ReorderItemProps as f, DivDragEventHandler as i, IconProps as l, RevertHandler as m, BoundingBox as n, DivProps as o, ReorderListProps as p, Child as r, DivRef as s, AnimationProps as t, Order as u };
|
package/dist/types.d.mts
CHANGED
|
@@ -1,50 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
//#region src/types.d.ts
|
|
4
|
-
type AnimationProps = {
|
|
5
|
-
duration: number;
|
|
6
|
-
children: Child[];
|
|
7
|
-
};
|
|
8
|
-
type BoundingBox = Record<string, DOMRect>;
|
|
9
|
-
type Child = ReactElement<{
|
|
10
|
-
ref: RefObject<HTMLElement>;
|
|
11
|
-
}>;
|
|
12
|
-
type Order = Key[];
|
|
13
|
-
type DivDragEventHandler = DragEventHandler<HTMLDivElement>;
|
|
14
|
-
type DivMouseEventHandler = MouseEventHandler<HTMLDivElement>;
|
|
15
|
-
type DivProps = DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>;
|
|
16
|
-
type DivRef = RefObject<HTMLDivElement | null>;
|
|
17
|
-
type DivTouchEventHandler = TouchEventHandler<HTMLDivElement>;
|
|
18
|
-
type PositionChangeHandler = (event: {
|
|
19
|
-
start: number;
|
|
20
|
-
end: number;
|
|
21
|
-
oldOrder: Order;
|
|
22
|
-
newOrder: Order;
|
|
23
|
-
revert: RevertHandler;
|
|
24
|
-
}) => void;
|
|
25
|
-
type ReorderItemProps = {
|
|
26
|
-
useOnlyIconToDrag: boolean;
|
|
27
|
-
disable?: boolean;
|
|
28
|
-
ref: DivRef;
|
|
29
|
-
style: CSSProperties;
|
|
30
|
-
onDragStart?: DivDragEventHandler;
|
|
31
|
-
onDragEnter: DivDragEventHandler;
|
|
32
|
-
onDragEnd: DivDragEventHandler;
|
|
33
|
-
onTouchMove: DivTouchEventHandler;
|
|
34
|
-
onTouchEnd: DivTouchEventHandler;
|
|
35
|
-
children: ReactNode;
|
|
36
|
-
};
|
|
37
|
-
type ReorderListProps = {
|
|
38
|
-
useOnlyIconToDrag?: boolean;
|
|
39
|
-
selectedItemOpacity?: number;
|
|
40
|
-
animationDuration?: number;
|
|
41
|
-
preserveOrder?: boolean;
|
|
42
|
-
onPositionChange?: PositionChangeHandler;
|
|
43
|
-
disabled?: boolean;
|
|
44
|
-
props?: DivProps;
|
|
45
|
-
children?: ReactNode;
|
|
46
|
-
};
|
|
47
|
-
type RevertHandler = () => void;
|
|
48
|
-
type IconProps = React.DetailedHTMLProps<React.HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>;
|
|
49
|
-
//#endregion
|
|
1
|
+
import { a as DivMouseEventHandler, c as DivTouchEventHandler, d as PositionChangeHandler, f as ReorderItemProps, i as DivDragEventHandler, l as IconProps, m as RevertHandler, n as BoundingBox, o as DivProps, p as ReorderListProps, r as Child, s as DivRef, t as AnimationProps, u as Order } from "./types-CRxTdmXH.mjs";
|
|
50
2
|
export { AnimationProps, BoundingBox, Child, DivDragEventHandler, DivMouseEventHandler, DivProps, DivRef, DivTouchEventHandler, IconProps, Order, PositionChangeHandler, ReorderItemProps, ReorderListProps, RevertHandler };
|
package/dist/types.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-reorder-list",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.3",
|
|
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
|
"license": "MIT",
|
|
6
6
|
"author": "Sahil Aggarwal <aggarwalsahil2004@gmail.com>",
|
|
@@ -18,12 +18,11 @@
|
|
|
18
18
|
".": "./dist/index.mjs",
|
|
19
19
|
"./types": "./dist/types.mjs"
|
|
20
20
|
},
|
|
21
|
-
"main": "dist/index.mjs",
|
|
22
21
|
"files": [
|
|
23
22
|
"dist"
|
|
24
23
|
],
|
|
25
24
|
"sideEffects": true,
|
|
26
|
-
"types": "dist/index.d.ts",
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
27
26
|
"dependencies": {
|
|
28
27
|
"drag-drop-touch": "^1.3.1"
|
|
29
28
|
},
|
|
@@ -35,7 +34,7 @@
|
|
|
35
34
|
"@types/react": "^19.2.14",
|
|
36
35
|
"prettier-package-json": "^2.8.0",
|
|
37
36
|
"release-it": "^19.2.4",
|
|
38
|
-
"tsdown": "^0.
|
|
37
|
+
"tsdown": "^0.21.0",
|
|
39
38
|
"typescript": "^5.9.3"
|
|
40
39
|
},
|
|
41
40
|
"keywords": [
|