UNPKG

react-box-tools

Version:

Box tools react components, utils and hooks

2 lines (1 loc) 982 B
"use strict";const o=require("react/jsx-runtime");require("react");const c=require("./useOutClick-BPW052ac.cjs"),f=n=>{const{elementRef:e}=n;return e.current===null?null:o.jsx(v,{elementRef:e})},v=n=>{const{elementRef:e}=n,t=e.current;let l=0,r=0,u=!1;const m=s=>{s.target.classList.contains("move")&&(l=t.offsetLeft-s.clientX,r=t.offsetTop-s.clientY,u=!0)},i=()=>{u=!1},a=s=>{s.preventDefault(),u&&(t.style.top=`${s.clientY+r}px`,t.style.marginLeft=`${s.clientX+l}px`,t.style.bottom="auto",t.style.position="absolute")};return c.useEventListener("mousedown",m,e),c.useEventListener("mouseup",i,e),c.useEventListener("mousemove",a,e),o.jsx(o.Fragment,{})},E=n=>{const{elementRef:e}=n;return e.current===null?null:o.jsx(d,{...n})},d=n=>{const{elementRef:e,className:t}=n,l=e.current,r=()=>{l.classList.add(t);const u=setTimeout(async()=>{l.classList.remove(t),await clearTimeout(u)},1e3)};return c.useOutClick(e,r),o.jsx(o.Fragment,{})};exports.MoveElement=f;exports.ShakeElement=E;