31 lines
716 B
JavaScript
31 lines
716 B
JavaScript
import { NOOP } from "../../utils/functions.mjs";
|
|
|
|
//#region ../../packages/hooks/use-same-target/index.ts
|
|
const useSameTarget = (handleClick) => {
|
|
if (!handleClick) return {
|
|
onClick: NOOP,
|
|
onMousedown: NOOP,
|
|
onMouseup: NOOP
|
|
};
|
|
let mousedownTarget = false;
|
|
let mouseupTarget = false;
|
|
const onClick = (e) => {
|
|
if (mousedownTarget && mouseupTarget) handleClick(e);
|
|
mousedownTarget = mouseupTarget = false;
|
|
};
|
|
const onMousedown = (e) => {
|
|
mousedownTarget = e.target === e.currentTarget;
|
|
};
|
|
const onMouseup = (e) => {
|
|
mouseupTarget = e.target === e.currentTarget;
|
|
};
|
|
return {
|
|
onClick,
|
|
onMousedown,
|
|
onMouseup
|
|
};
|
|
};
|
|
|
|
//#endregion
|
|
export { useSameTarget };
|
|
//# sourceMappingURL=index.mjs.map
|