UNPKG

@progress/kendo-react-common

Version:

React Common package delivers common utilities that can be used with the KendoReact UI components. KendoReact Common Utilities package

60 lines (59 loc) 1.81 kB
/** * @license *------------------------------------------------------------------------------------------- * Copyright © 2025 Progress Software Corporation. All rights reserved. * Licensed under commercial license. See LICENSE.md in the package root for more information *------------------------------------------------------------------------------------------- */ "use client"; import * as n from "react"; import { noop as o } from "../noop.mjs"; import { useInheritedState as x } from "./useInheritedState.mjs"; import { DragAndDropContext as L } from "../drag-n-drop/context/index.mjs"; import { useIsomorphicLayoutEffect as O } from "./use-isomorphic-layout-effect.mjs"; function H(t, m = { onDragEnter: o, onDragOver: o, onDragLeave: o, onDrop: o }, C = {}) { const { onDragEnter: s = o, onDragOver: u = o, onDragLeave: D = o, onDrop: g = o } = m, { context: i = L } = C, { setDrop: b, registerDrop: a, deregisterDrop: c } = n.useContext(i), [, r] = x([null, b]), d = n.useCallback( () => t.current && t.current.element ? t.current.element : t.current, [t] ), l = n.useRef(null); n.useImperativeHandle(l, () => ({ element: d(), onDragEnter: h, onDragOver: k, onDragLeave: v, onDrop: E, data: t.current })); const h = n.useCallback( (e) => { r(l, { target: t.current, event: e }), s(e); }, [r, t, s] ), k = n.useCallback( (e) => { u(e); }, [u] ), v = n.useCallback( (e) => { r(null, { target: t.current, event: e }), D(e); }, [r, t, D] ), E = n.useCallback( (e) => { r(null, { target: t.current, event: e }), g(e); }, [r, t, g] ), p = n.useCallback(() => (a == null || a(l), () => { c == null || c(l); }), [c, a]); O(p, [p]); } export { H as useDroppable };