@dnd-kit/react 0.0.10-beta-20250216045856 → 0.0.10-beta-20250217020220
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/index.cjs +29 -0
- package/index.d.ts +25 -8
- package/index.js +29 -1
- package/package.json +4 -4
package/index.cjs
CHANGED
|
@@ -352,6 +352,34 @@ function useDroppable(input) {
|
|
|
352
352
|
)
|
|
353
353
|
};
|
|
354
354
|
}
|
|
355
|
+
function useDragDropMonitor(handlers) {
|
|
356
|
+
const manager = useDragDropManager();
|
|
357
|
+
react.useEffect(() => {
|
|
358
|
+
if (!manager) {
|
|
359
|
+
if (process.env.NODE_ENV !== "production") {
|
|
360
|
+
console.warn(
|
|
361
|
+
"useDndMonitor hook was called outside of a DragDropProvider. Make sure your app is wrapped in a DragDropProvider component."
|
|
362
|
+
);
|
|
363
|
+
}
|
|
364
|
+
return;
|
|
365
|
+
}
|
|
366
|
+
const cleanupFns = Object.entries(handlers).reduce(
|
|
367
|
+
(acc, [handlerName, handler]) => {
|
|
368
|
+
if (handler) {
|
|
369
|
+
const eventName = handlerName.replace(/^on/, "").toLowerCase();
|
|
370
|
+
const unsubscribe = manager.monitor.addEventListener(
|
|
371
|
+
eventName,
|
|
372
|
+
handler
|
|
373
|
+
);
|
|
374
|
+
acc.push(unsubscribe);
|
|
375
|
+
}
|
|
376
|
+
return acc;
|
|
377
|
+
},
|
|
378
|
+
[]
|
|
379
|
+
);
|
|
380
|
+
return () => cleanupFns.forEach((cleanup) => cleanup == null ? void 0 : cleanup());
|
|
381
|
+
}, [manager, handlers]);
|
|
382
|
+
}
|
|
355
383
|
function useDragOperation() {
|
|
356
384
|
const manager = useDragDropManager();
|
|
357
385
|
const source = hooks.useComputed(() => manager == null ? void 0 : manager.dragOperation.source, [manager]);
|
|
@@ -369,6 +397,7 @@ function useDragOperation() {
|
|
|
369
397
|
exports.DragDropProvider = DragDropProvider;
|
|
370
398
|
exports.DragOverlay = DragOverlay;
|
|
371
399
|
exports.useDragDropManager = useDragDropManager;
|
|
400
|
+
exports.useDragDropMonitor = useDragDropMonitor;
|
|
372
401
|
exports.useDragOperation = useDragOperation;
|
|
373
402
|
exports.useDraggable = useDraggable;
|
|
374
403
|
exports.useDroppable = useDroppable;
|
package/index.d.ts
CHANGED
|
@@ -7,15 +7,15 @@ import { DragDropManagerInput, DragDropManager, Draggable, Droppable, DraggableI
|
|
|
7
7
|
import { RefOrValue } from '@dnd-kit/react/utilities';
|
|
8
8
|
import { CleanupFunction } from '@dnd-kit/state';
|
|
9
9
|
|
|
10
|
-
type Events = DragDropEvents<Draggable, Droppable, DragDropManager>;
|
|
10
|
+
type Events$1 = DragDropEvents<Draggable, Droppable, DragDropManager>;
|
|
11
11
|
interface Props$1 extends DragDropManagerInput, PropsWithChildren {
|
|
12
12
|
manager?: DragDropManager;
|
|
13
|
-
onBeforeDragStart?: Events['beforedragstart'];
|
|
14
|
-
onCollision?: Events['collision'];
|
|
15
|
-
onDragStart?: Events['dragstart'];
|
|
16
|
-
onDragMove?: Events['dragmove'];
|
|
17
|
-
onDragOver?: Events['dragover'];
|
|
18
|
-
onDragEnd?: Events['dragend'];
|
|
13
|
+
onBeforeDragStart?: Events$1['beforedragstart'];
|
|
14
|
+
onCollision?: Events$1['collision'];
|
|
15
|
+
onDragStart?: Events$1['dragstart'];
|
|
16
|
+
onDragMove?: Events$1['dragmove'];
|
|
17
|
+
onDragOver?: Events$1['dragover'];
|
|
18
|
+
onDragEnd?: Events$1['dragend'];
|
|
19
19
|
}
|
|
20
20
|
declare function DragDropProvider({ children, onCollision, onBeforeDragStart, onDragStart, onDragMove, onDragOver, onDragEnd, ...input }: Props$1): react_jsx_runtime.JSX.Element;
|
|
21
21
|
|
|
@@ -51,6 +51,23 @@ declare function useDroppable<T extends Data = Data>(input: UseDroppableInput<T>
|
|
|
51
51
|
|
|
52
52
|
declare function useDragDropManager(): _dnd_kit_dom.DragDropManager<_dnd_kit_dom.Draggable<_dnd_kit_abstract.Data>, _dnd_kit_dom.Droppable<_dnd_kit_abstract.Data>> | null;
|
|
53
53
|
|
|
54
|
+
/**
|
|
55
|
+
* Type helper to convert event names to handler names (e.g. 'dragstart' -> 'onDragStart')
|
|
56
|
+
*/
|
|
57
|
+
type EventHandlerName<T extends string> = `on${Capitalize<T>}`;
|
|
58
|
+
/**
|
|
59
|
+
* Type for all possible event handlers
|
|
60
|
+
*/
|
|
61
|
+
type Events<T extends Data> = DragDropEvents<Draggable<T>, Droppable<T>, DragDropManager<Draggable<T>, Droppable<T>>>;
|
|
62
|
+
type DndMonitorEventHandlers<T extends Data> = {
|
|
63
|
+
[K in keyof Events<T> as EventHandlerName<K>]?: Events<T>[K];
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* Hook to monitor drag and drop events within a DragDropProvider
|
|
67
|
+
* @param handlers Object containing event handlers for drag and drop events
|
|
68
|
+
*/
|
|
69
|
+
declare function useDragDropMonitor<T extends Data = Data>(handlers: DndMonitorEventHandlers<T>): void;
|
|
70
|
+
|
|
54
71
|
declare function useDragOperation(): {
|
|
55
72
|
readonly source: _dnd_kit_dom.Draggable<_dnd_kit_abstract.Data> | null | undefined;
|
|
56
73
|
readonly target: _dnd_kit_dom.Droppable<_dnd_kit_abstract.Data> | null | undefined;
|
|
@@ -62,4 +79,4 @@ interface Instance<T extends DragDropManager$1<any, any> = DragDropManager$1<any
|
|
|
62
79
|
}
|
|
63
80
|
declare function useInstance<T extends Instance>(initializer: (manager: DragDropManager$1<any, any> | undefined) => T): T;
|
|
64
81
|
|
|
65
|
-
export { DragDropProvider, DragOverlay, type UseDraggableInput, type UseDroppableInput, useDragDropManager, useDragOperation, useDraggable, useDroppable, useInstance };
|
|
82
|
+
export { DragDropProvider, DragOverlay, type UseDraggableInput, type UseDroppableInput, useDragDropManager, useDragDropMonitor, useDragOperation, useDraggable, useDroppable, useInstance };
|
package/index.js
CHANGED
|
@@ -350,6 +350,34 @@ function useDroppable(input) {
|
|
|
350
350
|
)
|
|
351
351
|
};
|
|
352
352
|
}
|
|
353
|
+
function useDragDropMonitor(handlers) {
|
|
354
|
+
const manager = useDragDropManager();
|
|
355
|
+
useEffect(() => {
|
|
356
|
+
if (!manager) {
|
|
357
|
+
if (process.env.NODE_ENV !== "production") {
|
|
358
|
+
console.warn(
|
|
359
|
+
"useDndMonitor hook was called outside of a DragDropProvider. Make sure your app is wrapped in a DragDropProvider component."
|
|
360
|
+
);
|
|
361
|
+
}
|
|
362
|
+
return;
|
|
363
|
+
}
|
|
364
|
+
const cleanupFns = Object.entries(handlers).reduce(
|
|
365
|
+
(acc, [handlerName, handler]) => {
|
|
366
|
+
if (handler) {
|
|
367
|
+
const eventName = handlerName.replace(/^on/, "").toLowerCase();
|
|
368
|
+
const unsubscribe = manager.monitor.addEventListener(
|
|
369
|
+
eventName,
|
|
370
|
+
handler
|
|
371
|
+
);
|
|
372
|
+
acc.push(unsubscribe);
|
|
373
|
+
}
|
|
374
|
+
return acc;
|
|
375
|
+
},
|
|
376
|
+
[]
|
|
377
|
+
);
|
|
378
|
+
return () => cleanupFns.forEach((cleanup) => cleanup == null ? void 0 : cleanup());
|
|
379
|
+
}, [manager, handlers]);
|
|
380
|
+
}
|
|
353
381
|
function useDragOperation() {
|
|
354
382
|
const manager = useDragDropManager();
|
|
355
383
|
const source = useComputed(() => manager == null ? void 0 : manager.dragOperation.source, [manager]);
|
|
@@ -364,6 +392,6 @@ function useDragOperation() {
|
|
|
364
392
|
};
|
|
365
393
|
}
|
|
366
394
|
|
|
367
|
-
export { DragDropProvider, DragOverlay, useDragDropManager, useDragOperation, useDraggable, useDroppable, useInstance };
|
|
395
|
+
export { DragDropProvider, DragOverlay, useDragDropManager, useDragDropMonitor, useDragOperation, useDraggable, useDroppable, useInstance };
|
|
368
396
|
//# sourceMappingURL=index.js.map
|
|
369
397
|
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dnd-kit/react",
|
|
3
|
-
"version": "0.0.10-beta-
|
|
3
|
+
"version": "0.0.10-beta-20250217020220",
|
|
4
4
|
"main": "./index.cjs",
|
|
5
5
|
"module": "./index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -56,9 +56,9 @@
|
|
|
56
56
|
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist"
|
|
57
57
|
},
|
|
58
58
|
"dependencies": {
|
|
59
|
-
"@dnd-kit/abstract": "0.0.10-beta-
|
|
60
|
-
"@dnd-kit/dom": "0.0.10-beta-
|
|
61
|
-
"@dnd-kit/state": "0.0.10-beta-
|
|
59
|
+
"@dnd-kit/abstract": "0.0.10-beta-20250217020220",
|
|
60
|
+
"@dnd-kit/dom": "0.0.10-beta-20250217020220",
|
|
61
|
+
"@dnd-kit/state": "0.0.10-beta-20250217020220",
|
|
62
62
|
"tslib": "^2.6.2"
|
|
63
63
|
},
|
|
64
64
|
"peerDependencies": {
|