react-drag-and-drop-kit 0.0.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/README.md +359 -0
- package/dist/index.d.ts +23 -0
- package/dist/react-drag-and-drop-kit.es.js +279 -0
- package/dist/react-drag-and-drop-kit.umd.js +6 -0
- package/package.json +67 -0
package/README.md
ADDED
|
@@ -0,0 +1,359 @@
|
|
|
1
|
+
# Drag and Drop
|
|
2
|
+
|
|
3
|
+
A lightweight, easy to use React.js library for implementing react-drag-and-drop-kit functionality. This library provides simple components that wrap the native HTML5 Drag and Drop API, making it straightforward to add react-drag-and-drop-kit features to your React applications.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/react-drag-and-drop-kit)
|
|
6
|
+
[](https://www.npmjs.com/package/react-drag-and-drop-kit)
|
|
7
|
+
[](LICENSE)
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
✨ **Simple and Lightweight** - Minimal API with zero dependencies (besides React)
|
|
12
|
+
🎯 **Type-Safe** - Full TypeScript support
|
|
13
|
+
🎨 **Flexible** - Use with any React component
|
|
14
|
+
📦 **Reusable** - Export your own custom data during drag operations
|
|
15
|
+
⚡ **Performance** - Efficient implementation using native browser APIs
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install react-drag-and-drop-kit
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Or using yarn:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
yarn add react-drag-and-drop-kit
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Or using pnpm:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
pnpm add react-drag-and-drop-kit
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Quick Start
|
|
36
|
+
|
|
37
|
+
Import the `Draggable` and `DropZone` components from the library:
|
|
38
|
+
|
|
39
|
+
```tsx
|
|
40
|
+
import { Draggable, DropZone } from "react-drag-and-drop-kit";
|
|
41
|
+
import { useState } from "react";
|
|
42
|
+
|
|
43
|
+
function App() {
|
|
44
|
+
const [droppedData, setDroppedData] = useState(null);
|
|
45
|
+
|
|
46
|
+
const handleDragStart = (event) => {
|
|
47
|
+
console.log("Drag started");
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const handleDropItem = (event, dataTransfer) => {
|
|
51
|
+
console.log("Item dropped:", dataTransfer);
|
|
52
|
+
setDroppedData(dataTransfer);
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
return (
|
|
56
|
+
<div style={{ display: "flex", height: "100vh" }}>
|
|
57
|
+
<div style={{ width: "50%" }}>
|
|
58
|
+
<Draggable
|
|
59
|
+
handleDragStart={handleDragStart}
|
|
60
|
+
dataTransfer={{ id: "item-1", name: "My Item" }}
|
|
61
|
+
>
|
|
62
|
+
<div style={{ padding: "20px", backgroundColor: "#3498db", color: "#fff" }}>Drag me!</div>
|
|
63
|
+
</Draggable>
|
|
64
|
+
</div>
|
|
65
|
+
|
|
66
|
+
<DropZone handleDropItem={handleDropItem}>
|
|
67
|
+
<div style={{ padding: "20px", backgroundColor: "#2ecc71", minHeight: "100%" }}>
|
|
68
|
+
{droppedData ? `Dropped: ${JSON.stringify(droppedData)}` : "Drop here!"}
|
|
69
|
+
</div>
|
|
70
|
+
</DropZone>
|
|
71
|
+
</div>
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export default App;
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## API Reference
|
|
79
|
+
|
|
80
|
+
### `Draggable` Component
|
|
81
|
+
|
|
82
|
+
Wraps any React component to make it draggable.
|
|
83
|
+
|
|
84
|
+
#### Props
|
|
85
|
+
|
|
86
|
+
| Prop | Type | Description |
|
|
87
|
+
| ----------------- | -------------------------------------------------- | -------------------------------------------------------------- |
|
|
88
|
+
| `children` | `ReactNode` | The content to be dragged |
|
|
89
|
+
| `handleDragStart` | `(event: React.DragEvent<HTMLDivElement>) => void` | Callback fired when drag starts |
|
|
90
|
+
| `dataTransfer` | `DataTransferInterface` | Custom data object to be transferred during the drag operation |
|
|
91
|
+
|
|
92
|
+
#### Example
|
|
93
|
+
|
|
94
|
+
```tsx
|
|
95
|
+
<Draggable
|
|
96
|
+
handleDragStart={(event) => console.log("Dragging...")}
|
|
97
|
+
dataTransfer={{ itemId: 123, type: "product" }}
|
|
98
|
+
>
|
|
99
|
+
<div>Draggable Item</div>
|
|
100
|
+
</Draggable>
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### `DropZone` Component
|
|
104
|
+
|
|
105
|
+
Creates a drop target that accepts dragged items.
|
|
106
|
+
|
|
107
|
+
#### Props
|
|
108
|
+
|
|
109
|
+
| Prop | Type | Description |
|
|
110
|
+
| ---------------- | ----------------------------------------------------------------------------------- | -------------------------------------- |
|
|
111
|
+
| `children` | `ReactNode` | The content of the drop zone |
|
|
112
|
+
| `handleDropItem` | `(e: React.DragEvent<HTMLDivElement>, dataTransfer: DataTransferInterface) => void` | Callback fired when an item is dropped |
|
|
113
|
+
|
|
114
|
+
#### Example
|
|
115
|
+
|
|
116
|
+
```tsx
|
|
117
|
+
<DropZone
|
|
118
|
+
handleDropItem={(event, dataTransfer) => {
|
|
119
|
+
console.log("Dropped data:", dataTransfer);
|
|
120
|
+
}}
|
|
121
|
+
>
|
|
122
|
+
<div>Drop Target</div>
|
|
123
|
+
</DropZone>
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### Types
|
|
127
|
+
|
|
128
|
+
#### `DataTransferInterface`
|
|
129
|
+
|
|
130
|
+
A simple object interface for passing custom data during drag operations:
|
|
131
|
+
|
|
132
|
+
```typescript
|
|
133
|
+
interface DataTransferInterface {
|
|
134
|
+
[key: string]: string;
|
|
135
|
+
}
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
## Real-World Example
|
|
139
|
+
|
|
140
|
+
### Shopping Cart Demo
|
|
141
|
+
|
|
142
|
+
```tsx
|
|
143
|
+
import { useState } from "react";
|
|
144
|
+
import { Draggable, DropZone, type DataTransferInterface } from "react-drag-and-drop-kit";
|
|
145
|
+
import "./App.css";
|
|
146
|
+
|
|
147
|
+
function App() {
|
|
148
|
+
const products = [
|
|
149
|
+
{ id: 1, name: "Product A", price: "$10" },
|
|
150
|
+
{ id: 2, name: "Product B", price: "$20" },
|
|
151
|
+
{ id: 3, name: "Product C", price: "$30" },
|
|
152
|
+
];
|
|
153
|
+
|
|
154
|
+
const [cart, setCart] = useState<DataTransferInterface[]>([]);
|
|
155
|
+
|
|
156
|
+
const handleAddToCart = (event, dataTransfer) => {
|
|
157
|
+
setCart([...cart, dataTransfer]);
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
return (
|
|
161
|
+
<div style={{ display: "flex", gap: "20px", padding: "20px" }}>
|
|
162
|
+
<div style={{ flex: 1 }}>
|
|
163
|
+
<h2>Products</h2>
|
|
164
|
+
{products.map((product) => (
|
|
165
|
+
<Draggable
|
|
166
|
+
key={product.id}
|
|
167
|
+
dataTransfer={{ id: String(product.id), name: product.name }}
|
|
168
|
+
handleDragStart={() => console.log(`Dragging ${product.name}`)}
|
|
169
|
+
>
|
|
170
|
+
<div
|
|
171
|
+
style={{
|
|
172
|
+
padding: "10px",
|
|
173
|
+
margin: "10px 0",
|
|
174
|
+
backgroundColor: "#3498db",
|
|
175
|
+
color: "#fff",
|
|
176
|
+
cursor: "grab",
|
|
177
|
+
}}
|
|
178
|
+
>
|
|
179
|
+
{product.name} - {product.price}
|
|
180
|
+
</div>
|
|
181
|
+
</Draggable>
|
|
182
|
+
))}
|
|
183
|
+
</div>
|
|
184
|
+
|
|
185
|
+
<DropZone handleDropItem={handleAddToCart}>
|
|
186
|
+
<div
|
|
187
|
+
style={{
|
|
188
|
+
flex: 1,
|
|
189
|
+
backgroundColor: "#ecf0f1",
|
|
190
|
+
padding: "20px",
|
|
191
|
+
minHeight: "500px",
|
|
192
|
+
}}
|
|
193
|
+
>
|
|
194
|
+
<h2>Shopping Cart</h2>
|
|
195
|
+
{cart.length === 0 ? (
|
|
196
|
+
<p>Drag items here to add to cart</p>
|
|
197
|
+
) : (
|
|
198
|
+
<ul>
|
|
199
|
+
{cart.map((item, idx) => (
|
|
200
|
+
<li key={idx}>{item.name}</li>
|
|
201
|
+
))}
|
|
202
|
+
</ul>
|
|
203
|
+
)}
|
|
204
|
+
</div>
|
|
205
|
+
</DropZone>
|
|
206
|
+
</div>
|
|
207
|
+
);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
export default App;
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
## Advanced Usage
|
|
214
|
+
|
|
215
|
+
### Multiple Drop Zones
|
|
216
|
+
|
|
217
|
+
You can have multiple drop zones and draggable items on the same page:
|
|
218
|
+
|
|
219
|
+
```tsx
|
|
220
|
+
<div>
|
|
221
|
+
<Draggable dataTransfer={{ id: "1" }} handleDragStart={() => {}}>
|
|
222
|
+
<div>Item 1</div>
|
|
223
|
+
</Draggable>
|
|
224
|
+
|
|
225
|
+
<DropZone handleDropItem={(e, data) => console.log("Zone 1:", data)}>
|
|
226
|
+
<div>Drop Zone 1</div>
|
|
227
|
+
</DropZone>
|
|
228
|
+
|
|
229
|
+
<DropZone handleDropItem={(e, data) => console.log("Zone 2:", data)}>
|
|
230
|
+
<div>Drop Zone 2</div>
|
|
231
|
+
</DropZone>
|
|
232
|
+
</div>
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
### Styled Drag and Drop
|
|
236
|
+
|
|
237
|
+
Enhance your react-drag-and-drop-kit with custom CSS:
|
|
238
|
+
|
|
239
|
+
```tsx
|
|
240
|
+
<style>{`
|
|
241
|
+
.draggable {
|
|
242
|
+
padding: 15px;
|
|
243
|
+
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
244
|
+
color: white;
|
|
245
|
+
cursor: grab;
|
|
246
|
+
border-radius: 8px;
|
|
247
|
+
transition: transform 0.2s;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
.draggable:active {
|
|
251
|
+
cursor: grabbing;
|
|
252
|
+
transform: scale(1.05);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
.drop-zone {
|
|
256
|
+
border: 2px dashed #667eea;
|
|
257
|
+
border-radius: 8px;
|
|
258
|
+
padding: 20px;
|
|
259
|
+
min-height: 300px;
|
|
260
|
+
background: rgba(102, 126, 234, 0.1);
|
|
261
|
+
}
|
|
262
|
+
`}</style>
|
|
263
|
+
|
|
264
|
+
<Draggable
|
|
265
|
+
dataTransfer={{ id: '1' }}
|
|
266
|
+
handleDragStart={() => {}}
|
|
267
|
+
className="draggable"
|
|
268
|
+
>
|
|
269
|
+
<div>Drag me with style!</div>
|
|
270
|
+
</Draggable>
|
|
271
|
+
|
|
272
|
+
<DropZone handleDropItem={() => {}} className="drop-zone">
|
|
273
|
+
<div>Styled Drop Zone</div>
|
|
274
|
+
</DropZone>
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
## TypeScript Support
|
|
278
|
+
|
|
279
|
+
The library is built with TypeScript and exports all necessary types:
|
|
280
|
+
|
|
281
|
+
```tsx
|
|
282
|
+
import {
|
|
283
|
+
Draggable,
|
|
284
|
+
DropZone,
|
|
285
|
+
type DraggableProps,
|
|
286
|
+
type DropZoneProps,
|
|
287
|
+
type DataTransferInterface,
|
|
288
|
+
} from "react-drag-and-drop-kit";
|
|
289
|
+
|
|
290
|
+
const handleDrop: DropZoneProps["handleDropItem"] = (event, dataTransfer) => {
|
|
291
|
+
console.log("Dropped:", dataTransfer);
|
|
292
|
+
};
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
## Browser Support
|
|
296
|
+
|
|
297
|
+
This library uses the HTML5 Drag and Drop API, which is supported in all modern browsers:
|
|
298
|
+
|
|
299
|
+
- Chrome/Edge 4+
|
|
300
|
+
- Firefox 3.6+
|
|
301
|
+
- Safari 3.1+
|
|
302
|
+
- Opera 12+
|
|
303
|
+
- IE 10+
|
|
304
|
+
|
|
305
|
+
## Performance Considerations
|
|
306
|
+
|
|
307
|
+
- The library uses React's native event system for optimal performance
|
|
308
|
+
- Drag operations are handled efficiently with minimal re-renders
|
|
309
|
+
- Data transfer is serialized to JSON, so ensure your data is serializable
|
|
310
|
+
|
|
311
|
+
## Contributing
|
|
312
|
+
|
|
313
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
314
|
+
|
|
315
|
+
1. Fork the repository
|
|
316
|
+
2. Create your feature branch (`git checkout -b feature/AmazingFeature`)
|
|
317
|
+
3. Commit your changes (`git commit -m 'Add some AmazingFeature'`)
|
|
318
|
+
4. Push to the branch (`git push origin feature/AmazingFeature`)
|
|
319
|
+
5. Open a Pull Request
|
|
320
|
+
|
|
321
|
+
## License
|
|
322
|
+
|
|
323
|
+
This project is licensed under the MIT License - see the LICENSE file for details.
|
|
324
|
+
|
|
325
|
+
## Author
|
|
326
|
+
|
|
327
|
+
**Sanket Kakad**
|
|
328
|
+
|
|
329
|
+
- GitHub: [@sanketskakad](https://github.com/sanketskakad)
|
|
330
|
+
- Repository: [react-drag-and-drop-kit](https://github.com/sanketskakad/react-drag-and-drop-kit)
|
|
331
|
+
|
|
332
|
+
## Changelog
|
|
333
|
+
|
|
334
|
+
### Version 0.0.0
|
|
335
|
+
|
|
336
|
+
Initial release with:
|
|
337
|
+
|
|
338
|
+
- `Draggable` component
|
|
339
|
+
- `DropZone` component
|
|
340
|
+
- Full TypeScript support
|
|
341
|
+
- React 18+ compatibility
|
|
342
|
+
|
|
343
|
+
## FAQ
|
|
344
|
+
|
|
345
|
+
**Q: Can I drag multiple items at once?**
|
|
346
|
+
A: The current version handles single-item dragging. For multi-item selection, you can manage state in your parent component and transfer a reference to multiple items in the `dataTransfer` object.
|
|
347
|
+
|
|
348
|
+
**Q: Can I customize the drag ghost image?**
|
|
349
|
+
A: Yes, you can use the `setDragImage` method in the `handleDragStart` callback on the drag event.
|
|
350
|
+
|
|
351
|
+
**Q: Is there any CSS required?**
|
|
352
|
+
A: No, the library requires no CSS. However, you may want to add cursor styles and visual feedback for better UX.
|
|
353
|
+
|
|
354
|
+
**Q: What data types can I transfer?**
|
|
355
|
+
A: The `dataTransfer` object should contain string values. Convert complex types to JSON strings if needed.
|
|
356
|
+
|
|
357
|
+
## Support
|
|
358
|
+
|
|
359
|
+
If you have any questions or issues, please open an issue on the [GitHub repository](https://github.com/sanketskakad/react-drag-and-drop-kit/issues).
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { JSX } from 'react/jsx-runtime';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
|
|
4
|
+
export declare interface DataTransferInterface {
|
|
5
|
+
[key: string]: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export declare function Draggable({ children, handleDragStart, dataTransfer }: DraggableProps): JSX.Element;
|
|
9
|
+
|
|
10
|
+
export declare type DraggableProps = {
|
|
11
|
+
children: ReactNode;
|
|
12
|
+
handleDragStart: (event: React.DragEvent<HTMLDivElement>) => void;
|
|
13
|
+
dataTransfer: DataTransferInterface;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export declare function DropZone({ children, handleDropItem }: DropZoneProps): JSX.Element;
|
|
17
|
+
|
|
18
|
+
export declare type DropZoneProps = {
|
|
19
|
+
children: ReactNode;
|
|
20
|
+
handleDropItem: (e: React.DragEvent<HTMLDivElement>, dataTransfer: DataTransferInterface) => void;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export { }
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
import ee from "react";
|
|
2
|
+
var p = { exports: {} }, E = {};
|
|
3
|
+
var Y;
|
|
4
|
+
function re() {
|
|
5
|
+
if (Y) return E;
|
|
6
|
+
Y = 1;
|
|
7
|
+
var l = /* @__PURE__ */ Symbol.for("react.transitional.element"), i = /* @__PURE__ */ Symbol.for("react.fragment");
|
|
8
|
+
function c(s, o, u) {
|
|
9
|
+
var d = null;
|
|
10
|
+
if (u !== void 0 && (d = "" + u), o.key !== void 0 && (d = "" + o.key), "key" in o) {
|
|
11
|
+
u = {};
|
|
12
|
+
for (var m in o)
|
|
13
|
+
m !== "key" && (u[m] = o[m]);
|
|
14
|
+
} else u = o;
|
|
15
|
+
return o = u.ref, {
|
|
16
|
+
$$typeof: l,
|
|
17
|
+
type: s,
|
|
18
|
+
key: d,
|
|
19
|
+
ref: o !== void 0 ? o : null,
|
|
20
|
+
props: u
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
return E.Fragment = i, E.jsx = c, E.jsxs = c, E;
|
|
24
|
+
}
|
|
25
|
+
var _ = {};
|
|
26
|
+
var $;
|
|
27
|
+
function te() {
|
|
28
|
+
return $ || ($ = 1, process.env.NODE_ENV !== "production" && (function() {
|
|
29
|
+
function l(e) {
|
|
30
|
+
if (e == null) return null;
|
|
31
|
+
if (typeof e == "function")
|
|
32
|
+
return e.$$typeof === H ? null : e.displayName || e.name || null;
|
|
33
|
+
if (typeof e == "string") return e;
|
|
34
|
+
switch (e) {
|
|
35
|
+
case b:
|
|
36
|
+
return "Fragment";
|
|
37
|
+
case U:
|
|
38
|
+
return "Profiler";
|
|
39
|
+
case J:
|
|
40
|
+
return "StrictMode";
|
|
41
|
+
case G:
|
|
42
|
+
return "Suspense";
|
|
43
|
+
case X:
|
|
44
|
+
return "SuspenseList";
|
|
45
|
+
case B:
|
|
46
|
+
return "Activity";
|
|
47
|
+
}
|
|
48
|
+
if (typeof e == "object")
|
|
49
|
+
switch (typeof e.tag == "number" && console.error(
|
|
50
|
+
"Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."
|
|
51
|
+
), e.$$typeof) {
|
|
52
|
+
case W:
|
|
53
|
+
return "Portal";
|
|
54
|
+
case V:
|
|
55
|
+
return e.displayName || "Context";
|
|
56
|
+
case q:
|
|
57
|
+
return (e._context.displayName || "Context") + ".Consumer";
|
|
58
|
+
case z:
|
|
59
|
+
var r = e.render;
|
|
60
|
+
return e = e.displayName, e || (e = r.displayName || r.name || "", e = e !== "" ? "ForwardRef(" + e + ")" : "ForwardRef"), e;
|
|
61
|
+
case Z:
|
|
62
|
+
return r = e.displayName || null, r !== null ? r : l(e.type) || "Memo";
|
|
63
|
+
case T:
|
|
64
|
+
r = e._payload, e = e._init;
|
|
65
|
+
try {
|
|
66
|
+
return l(e(r));
|
|
67
|
+
} catch {
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
function i(e) {
|
|
73
|
+
return "" + e;
|
|
74
|
+
}
|
|
75
|
+
function c(e) {
|
|
76
|
+
try {
|
|
77
|
+
i(e);
|
|
78
|
+
var r = !1;
|
|
79
|
+
} catch {
|
|
80
|
+
r = !0;
|
|
81
|
+
}
|
|
82
|
+
if (r) {
|
|
83
|
+
r = console;
|
|
84
|
+
var t = r.error, a = typeof Symbol == "function" && Symbol.toStringTag && e[Symbol.toStringTag] || e.constructor.name || "Object";
|
|
85
|
+
return t.call(
|
|
86
|
+
r,
|
|
87
|
+
"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
|
|
88
|
+
a
|
|
89
|
+
), i(e);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
function s(e) {
|
|
93
|
+
if (e === b) return "<>";
|
|
94
|
+
if (typeof e == "object" && e !== null && e.$$typeof === T)
|
|
95
|
+
return "<...>";
|
|
96
|
+
try {
|
|
97
|
+
var r = l(e);
|
|
98
|
+
return r ? "<" + r + ">" : "<...>";
|
|
99
|
+
} catch {
|
|
100
|
+
return "<...>";
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
function o() {
|
|
104
|
+
var e = k.A;
|
|
105
|
+
return e === null ? null : e.getOwner();
|
|
106
|
+
}
|
|
107
|
+
function u() {
|
|
108
|
+
return Error("react-stack-top-frame");
|
|
109
|
+
}
|
|
110
|
+
function d(e) {
|
|
111
|
+
if (j.call(e, "key")) {
|
|
112
|
+
var r = Object.getOwnPropertyDescriptor(e, "key").get;
|
|
113
|
+
if (r && r.isReactWarning) return !1;
|
|
114
|
+
}
|
|
115
|
+
return e.key !== void 0;
|
|
116
|
+
}
|
|
117
|
+
function m(e, r) {
|
|
118
|
+
function t() {
|
|
119
|
+
w || (w = !0, console.error(
|
|
120
|
+
"%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",
|
|
121
|
+
r
|
|
122
|
+
));
|
|
123
|
+
}
|
|
124
|
+
t.isReactWarning = !0, Object.defineProperty(e, "key", {
|
|
125
|
+
get: t,
|
|
126
|
+
configurable: !0
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
function L() {
|
|
130
|
+
var e = l(this.type);
|
|
131
|
+
return h[e] || (h[e] = !0, console.error(
|
|
132
|
+
"Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release."
|
|
133
|
+
)), e = this.props.ref, e !== void 0 ? e : null;
|
|
134
|
+
}
|
|
135
|
+
function M(e, r, t, a, R, S) {
|
|
136
|
+
var n = t.ref;
|
|
137
|
+
return e = {
|
|
138
|
+
$$typeof: y,
|
|
139
|
+
type: e,
|
|
140
|
+
key: r,
|
|
141
|
+
props: t,
|
|
142
|
+
_owner: a
|
|
143
|
+
}, (n !== void 0 ? n : null) !== null ? Object.defineProperty(e, "ref", {
|
|
144
|
+
enumerable: !1,
|
|
145
|
+
get: L
|
|
146
|
+
}) : Object.defineProperty(e, "ref", { enumerable: !1, value: null }), e._store = {}, Object.defineProperty(e._store, "validated", {
|
|
147
|
+
configurable: !1,
|
|
148
|
+
enumerable: !1,
|
|
149
|
+
writable: !0,
|
|
150
|
+
value: 0
|
|
151
|
+
}), Object.defineProperty(e, "_debugInfo", {
|
|
152
|
+
configurable: !1,
|
|
153
|
+
enumerable: !1,
|
|
154
|
+
writable: !0,
|
|
155
|
+
value: null
|
|
156
|
+
}), Object.defineProperty(e, "_debugStack", {
|
|
157
|
+
configurable: !1,
|
|
158
|
+
enumerable: !1,
|
|
159
|
+
writable: !0,
|
|
160
|
+
value: R
|
|
161
|
+
}), Object.defineProperty(e, "_debugTask", {
|
|
162
|
+
configurable: !1,
|
|
163
|
+
enumerable: !1,
|
|
164
|
+
writable: !0,
|
|
165
|
+
value: S
|
|
166
|
+
}), Object.freeze && (Object.freeze(e.props), Object.freeze(e)), e;
|
|
167
|
+
}
|
|
168
|
+
function A(e, r, t, a, R, S) {
|
|
169
|
+
var n = r.children;
|
|
170
|
+
if (n !== void 0)
|
|
171
|
+
if (a)
|
|
172
|
+
if (Q(n)) {
|
|
173
|
+
for (a = 0; a < n.length; a++)
|
|
174
|
+
P(n[a]);
|
|
175
|
+
Object.freeze && Object.freeze(n);
|
|
176
|
+
} else
|
|
177
|
+
console.error(
|
|
178
|
+
"React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."
|
|
179
|
+
);
|
|
180
|
+
else P(n);
|
|
181
|
+
if (j.call(r, "key")) {
|
|
182
|
+
n = l(e);
|
|
183
|
+
var f = Object.keys(r).filter(function(K) {
|
|
184
|
+
return K !== "key";
|
|
185
|
+
});
|
|
186
|
+
a = 0 < f.length ? "{key: someKey, " + f.join(": ..., ") + ": ...}" : "{key: someKey}", C[n + a] || (f = 0 < f.length ? "{" + f.join(": ..., ") + ": ...}" : "{}", console.error(
|
|
187
|
+
`A props object containing a "key" prop is being spread into JSX:
|
|
188
|
+
let props = %s;
|
|
189
|
+
<%s {...props} />
|
|
190
|
+
React keys must be passed directly to JSX without using spread:
|
|
191
|
+
let props = %s;
|
|
192
|
+
<%s key={someKey} {...props} />`,
|
|
193
|
+
a,
|
|
194
|
+
n,
|
|
195
|
+
f,
|
|
196
|
+
n
|
|
197
|
+
), C[n + a] = !0);
|
|
198
|
+
}
|
|
199
|
+
if (n = null, t !== void 0 && (c(t), n = "" + t), d(r) && (c(r.key), n = "" + r.key), "key" in r) {
|
|
200
|
+
t = {};
|
|
201
|
+
for (var g in r)
|
|
202
|
+
g !== "key" && (t[g] = r[g]);
|
|
203
|
+
} else t = r;
|
|
204
|
+
return n && m(
|
|
205
|
+
t,
|
|
206
|
+
typeof e == "function" ? e.displayName || e.name || "Unknown" : e
|
|
207
|
+
), M(
|
|
208
|
+
e,
|
|
209
|
+
n,
|
|
210
|
+
t,
|
|
211
|
+
o(),
|
|
212
|
+
R,
|
|
213
|
+
S
|
|
214
|
+
);
|
|
215
|
+
}
|
|
216
|
+
function P(e) {
|
|
217
|
+
x(e) ? e._store && (e._store.validated = 1) : typeof e == "object" && e !== null && e.$$typeof === T && (e._payload.status === "fulfilled" ? x(e._payload.value) && e._payload.value._store && (e._payload.value._store.validated = 1) : e._store && (e._store.validated = 1));
|
|
218
|
+
}
|
|
219
|
+
function x(e) {
|
|
220
|
+
return typeof e == "object" && e !== null && e.$$typeof === y;
|
|
221
|
+
}
|
|
222
|
+
var v = ee, y = /* @__PURE__ */ Symbol.for("react.transitional.element"), W = /* @__PURE__ */ Symbol.for("react.portal"), b = /* @__PURE__ */ Symbol.for("react.fragment"), J = /* @__PURE__ */ Symbol.for("react.strict_mode"), U = /* @__PURE__ */ Symbol.for("react.profiler"), q = /* @__PURE__ */ Symbol.for("react.consumer"), V = /* @__PURE__ */ Symbol.for("react.context"), z = /* @__PURE__ */ Symbol.for("react.forward_ref"), G = /* @__PURE__ */ Symbol.for("react.suspense"), X = /* @__PURE__ */ Symbol.for("react.suspense_list"), Z = /* @__PURE__ */ Symbol.for("react.memo"), T = /* @__PURE__ */ Symbol.for("react.lazy"), B = /* @__PURE__ */ Symbol.for("react.activity"), H = /* @__PURE__ */ Symbol.for("react.client.reference"), k = v.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, j = Object.prototype.hasOwnProperty, Q = Array.isArray, O = console.createTask ? console.createTask : function() {
|
|
223
|
+
return null;
|
|
224
|
+
};
|
|
225
|
+
v = {
|
|
226
|
+
react_stack_bottom_frame: function(e) {
|
|
227
|
+
return e();
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
var w, h = {}, N = v.react_stack_bottom_frame.bind(
|
|
231
|
+
v,
|
|
232
|
+
u
|
|
233
|
+
)(), D = O(s(u)), C = {};
|
|
234
|
+
_.Fragment = b, _.jsx = function(e, r, t) {
|
|
235
|
+
var a = 1e4 > k.recentlyCreatedOwnerStacks++;
|
|
236
|
+
return A(
|
|
237
|
+
e,
|
|
238
|
+
r,
|
|
239
|
+
t,
|
|
240
|
+
!1,
|
|
241
|
+
a ? Error("react-stack-top-frame") : N,
|
|
242
|
+
a ? O(s(e)) : D
|
|
243
|
+
);
|
|
244
|
+
}, _.jsxs = function(e, r, t) {
|
|
245
|
+
var a = 1e4 > k.recentlyCreatedOwnerStacks++;
|
|
246
|
+
return A(
|
|
247
|
+
e,
|
|
248
|
+
r,
|
|
249
|
+
t,
|
|
250
|
+
!0,
|
|
251
|
+
a ? Error("react-stack-top-frame") : N,
|
|
252
|
+
a ? O(s(e)) : D
|
|
253
|
+
);
|
|
254
|
+
};
|
|
255
|
+
})()), _;
|
|
256
|
+
}
|
|
257
|
+
var I;
|
|
258
|
+
function ae() {
|
|
259
|
+
return I || (I = 1, process.env.NODE_ENV === "production" ? p.exports = re() : p.exports = te()), p.exports;
|
|
260
|
+
}
|
|
261
|
+
var F = ae();
|
|
262
|
+
function oe({ children: l, handleDragStart: i, dataTransfer: c }) {
|
|
263
|
+
const s = (o) => {
|
|
264
|
+
o.dataTransfer.setData("dataTransfer", JSON.stringify(c)), i(o);
|
|
265
|
+
};
|
|
266
|
+
return /* @__PURE__ */ F.jsx("div", { draggable: "true", onDragStart: s, children: l });
|
|
267
|
+
}
|
|
268
|
+
function se({ children: l, handleDropItem: i }) {
|
|
269
|
+
const c = (s) => {
|
|
270
|
+
s.preventDefault();
|
|
271
|
+
const o = s.dataTransfer.getData("dataTransfer"), u = JSON.parse(o);
|
|
272
|
+
i(s, u);
|
|
273
|
+
};
|
|
274
|
+
return /* @__PURE__ */ F.jsx("div", { onDragOver: (s) => s.preventDefault(), onDrop: c, children: l });
|
|
275
|
+
}
|
|
276
|
+
export {
|
|
277
|
+
oe as Draggable,
|
|
278
|
+
se as DropZone
|
|
279
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
(function(i,m){typeof exports=="object"&&typeof module<"u"?m(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],m):(i=typeof globalThis<"u"?globalThis:i||self,m(i.DragAndDropKit={},i.React))})(this,(function(i,m){"use strict";var v={exports:{}},E={};var P;function W(){if(P)return E;P=1;var l=Symbol.for("react.transitional.element"),f=Symbol.for("react.fragment");function c(s,o,u){var p=null;if(u!==void 0&&(p=""+u),o.key!==void 0&&(p=""+o.key),"key"in o){u={};for(var b in o)b!=="key"&&(u[b]=o[b])}else u=o;return o=u.ref,{$$typeof:l,type:s,key:p,ref:o!==void 0?o:null,props:u}}return E.Fragment=f,E.jsx=c,E.jsxs=c,E}var _={};var j;function J(){return j||(j=1,process.env.NODE_ENV!=="production"&&(function(){function l(e){if(e==null)return null;if(typeof e=="function")return e.$$typeof===ae?null:e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case g:return"Fragment";case B:return"Profiler";case Z:return"StrictMode";case ee:return"Suspense";case re:return"SuspenseList";case ne:return"Activity"}if(typeof e=="object")switch(typeof e.tag=="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),e.$$typeof){case X:return"Portal";case Q:return e.displayName||"Context";case H:return(e._context.displayName||"Context")+".Consumer";case K:var r=e.render;return e=e.displayName,e||(e=r.displayName||r.name||"",e=e!==""?"ForwardRef("+e+")":"ForwardRef"),e;case te:return r=e.displayName||null,r!==null?r:l(e.type)||"Memo";case k:r=e._payload,e=e._init;try{return l(e(r))}catch{}}return null}function f(e){return""+e}function c(e){try{f(e);var r=!1}catch{r=!0}if(r){r=console;var t=r.error,n=typeof Symbol=="function"&&Symbol.toStringTag&&e[Symbol.toStringTag]||e.constructor.name||"Object";return t.call(r,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",n),f(e)}}function s(e){if(e===g)return"<>";if(typeof e=="object"&&e!==null&&e.$$typeof===k)return"<...>";try{var r=l(e);return r?"<"+r+">":"<...>"}catch{return"<...>"}}function o(){var e=O.A;return e===null?null:e.getOwner()}function u(){return Error("react-stack-top-frame")}function p(e){if(Y.call(e,"key")){var r=Object.getOwnPropertyDescriptor(e,"key").get;if(r&&r.isReactWarning)return!1}return e.key!==void 0}function b(e,r){function t(){I||(I=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",r))}t.isReactWarning=!0,Object.defineProperty(e,"key",{get:t,configurable:!0})}function z(){var e=l(this.type);return $[e]||($[e]=!0,console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")),e=this.props.ref,e!==void 0?e:null}function G(e,r,t,n,T,y){var a=t.ref;return e={$$typeof:C,type:e,key:r,props:t,_owner:n},(a!==void 0?a:null)!==null?Object.defineProperty(e,"ref",{enumerable:!1,get:z}):Object.defineProperty(e,"ref",{enumerable:!1,value:null}),e._store={},Object.defineProperty(e._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(e,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(e,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:T}),Object.defineProperty(e,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:y}),Object.freeze&&(Object.freeze(e.props),Object.freeze(e)),e}function w(e,r,t,n,T,y){var a=r.children;if(a!==void 0)if(n)if(oe(a)){for(n=0;n<a.length;n++)N(a[n]);Object.freeze&&Object.freeze(a)}else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else N(a);if(Y.call(r,"key")){a=l(e);var d=Object.keys(r).filter(function(se){return se!=="key"});n=0<d.length?"{key: someKey, "+d.join(": ..., ")+": ...}":"{key: someKey}",L[a+n]||(d=0<d.length?"{"+d.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
|
|
2
|
+
let props = %s;
|
|
3
|
+
<%s {...props} />
|
|
4
|
+
React keys must be passed directly to JSX without using spread:
|
|
5
|
+
let props = %s;
|
|
6
|
+
<%s key={someKey} {...props} />`,n,a,d,a),L[a+n]=!0)}if(a=null,t!==void 0&&(c(t),a=""+t),p(r)&&(c(r.key),a=""+r.key),"key"in r){t={};for(var A in r)A!=="key"&&(t[A]=r[A])}else t=r;return a&&b(t,typeof e=="function"?e.displayName||e.name||"Unknown":e),G(e,a,t,o(),T,y)}function N(e){D(e)?e._store&&(e._store.validated=1):typeof e=="object"&&e!==null&&e.$$typeof===k&&(e._payload.status==="fulfilled"?D(e._payload.value)&&e._payload.value._store&&(e._payload.value._store.validated=1):e._store&&(e._store.validated=1))}function D(e){return typeof e=="object"&&e!==null&&e.$$typeof===C}var R=m,C=Symbol.for("react.transitional.element"),X=Symbol.for("react.portal"),g=Symbol.for("react.fragment"),Z=Symbol.for("react.strict_mode"),B=Symbol.for("react.profiler"),H=Symbol.for("react.consumer"),Q=Symbol.for("react.context"),K=Symbol.for("react.forward_ref"),ee=Symbol.for("react.suspense"),re=Symbol.for("react.suspense_list"),te=Symbol.for("react.memo"),k=Symbol.for("react.lazy"),ne=Symbol.for("react.activity"),ae=Symbol.for("react.client.reference"),O=R.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,Y=Object.prototype.hasOwnProperty,oe=Array.isArray,S=console.createTask?console.createTask:function(){return null};R={react_stack_bottom_frame:function(e){return e()}};var I,$={},F=R.react_stack_bottom_frame.bind(R,u)(),M=S(s(u)),L={};_.Fragment=g,_.jsx=function(e,r,t){var n=1e4>O.recentlyCreatedOwnerStacks++;return w(e,r,t,!1,n?Error("react-stack-top-frame"):F,n?S(s(e)):M)},_.jsxs=function(e,r,t){var n=1e4>O.recentlyCreatedOwnerStacks++;return w(e,r,t,!0,n?Error("react-stack-top-frame"):F,n?S(s(e)):M)}})()),_}var h;function U(){return h||(h=1,process.env.NODE_ENV==="production"?v.exports=W():v.exports=J()),v.exports}var x=U();function q({children:l,handleDragStart:f,dataTransfer:c}){const s=o=>{o.dataTransfer.setData("dataTransfer",JSON.stringify(c)),f(o)};return x.jsx("div",{draggable:"true",onDragStart:s,children:l})}function V({children:l,handleDropItem:f}){const c=s=>{s.preventDefault();const o=s.dataTransfer.getData("dataTransfer"),u=JSON.parse(o);f(s,u)};return x.jsx("div",{onDragOver:s=>s.preventDefault(),onDrop:c,children:l})}i.Draggable=q,i.DropZone=V,Object.defineProperty(i,Symbol.toStringTag,{value:"Module"})}));
|
package/package.json
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "react-drag-and-drop-kit",
|
|
3
|
+
"author": {
|
|
4
|
+
"name": "Sanket Kakad"
|
|
5
|
+
},
|
|
6
|
+
"repository": {
|
|
7
|
+
"url": "https://github.com/sanketskakad/react-drag-and-drop"
|
|
8
|
+
},
|
|
9
|
+
"private": false,
|
|
10
|
+
"version": "0.0.0",
|
|
11
|
+
"description": "An open source, lightweight React.js library for implementing simple and flexible react-drag-and-drop functionality.",
|
|
12
|
+
"keywords": [
|
|
13
|
+
"react",
|
|
14
|
+
"react-drag-and-drop-kit",
|
|
15
|
+
"drag-and-drop",
|
|
16
|
+
"dnd",
|
|
17
|
+
"draggable",
|
|
18
|
+
"sortable",
|
|
19
|
+
"ui-components",
|
|
20
|
+
"drag",
|
|
21
|
+
"drop",
|
|
22
|
+
"javascript",
|
|
23
|
+
"typescript"
|
|
24
|
+
],
|
|
25
|
+
"type": "module",
|
|
26
|
+
"main": "./dist/react-drag-and-drop-kit.umd.js",
|
|
27
|
+
"module": "./dist/react-drag-and-drop-kit.es.js",
|
|
28
|
+
"types": "./dist/index.d.ts",
|
|
29
|
+
"files": [
|
|
30
|
+
"dist"
|
|
31
|
+
],
|
|
32
|
+
"exports": {
|
|
33
|
+
".": {
|
|
34
|
+
"import": {
|
|
35
|
+
"types": "./dist/index.d.ts",
|
|
36
|
+
"default": "./dist/react-drag-and-drop-kit.es.js"
|
|
37
|
+
},
|
|
38
|
+
"require": {
|
|
39
|
+
"types": "./dist/index.d.ts",
|
|
40
|
+
"default": "./dist/react-drag-and-drop-kit.umd.js"
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
"scripts": {
|
|
45
|
+
"build": "vite build",
|
|
46
|
+
"lint": "eslint ."
|
|
47
|
+
},
|
|
48
|
+
"peerDependencies": {
|
|
49
|
+
"react": ">=18",
|
|
50
|
+
"react-dom": ">=18"
|
|
51
|
+
},
|
|
52
|
+
"devDependencies": {
|
|
53
|
+
"@eslint/js": "^9.39.1",
|
|
54
|
+
"@types/node": "^24.10.1",
|
|
55
|
+
"@types/react": "^19.2.5",
|
|
56
|
+
"@types/react-dom": "^19.2.3",
|
|
57
|
+
"@vitejs/plugin-react": "^5.1.1",
|
|
58
|
+
"eslint": "^9.39.1",
|
|
59
|
+
"eslint-plugin-react-hooks": "^7.0.1",
|
|
60
|
+
"eslint-plugin-react-refresh": "^0.4.24",
|
|
61
|
+
"globals": "^16.5.0",
|
|
62
|
+
"typescript": "~5.9.3",
|
|
63
|
+
"typescript-eslint": "^8.46.4",
|
|
64
|
+
"vite": "^7.2.4",
|
|
65
|
+
"vite-plugin-dts": "^4.5.4"
|
|
66
|
+
}
|
|
67
|
+
}
|