react-box-tools
Version:
Box tools react components, utils and hooks
34 lines (33 loc) • 1.21 kB
JavaScript
import { jsx as r, Fragment as m } from "react/jsx-runtime";
import "react";
import { u as c, a as p } from "./useOutClick-DP--F-Sn.js";
const x = (n) => {
const { elementRef: e } = n;
return e.current === null ? null : /* @__PURE__ */ r(d, { elementRef: e });
}, d = (n) => {
const { elementRef: e } = n, t = e.current;
let o = 0, u = 0, l = !1;
const a = (s) => {
s.target.classList.contains("move") && (o = t.offsetLeft - s.clientX, u = t.offsetTop - s.clientY, l = !0);
}, i = () => {
l = !1;
}, f = (s) => {
s.preventDefault(), l && (t.style.top = `${s.clientY + u}px`, t.style.marginLeft = `${s.clientX + o}px`, t.style.bottom = "auto", t.style.position = "absolute");
};
return c("mousedown", a, e), c("mouseup", i, e), c("mousemove", f, e), /* @__PURE__ */ r(m, {});
}, E = (n) => {
const { elementRef: e } = n;
return e.current === null ? null : /* @__PURE__ */ r(v, { ...n });
}, v = (n) => {
const { elementRef: e, className: t } = n, o = e.current;
return p(e, () => {
o.classList.add(t);
const l = setTimeout(async () => {
o.classList.remove(t), await clearTimeout(l);
}, 1e3);
}), /* @__PURE__ */ r(m, {});
};
export {
x as M,
E as S
};