UNPKG

tweak-tools

Version:

Tweak your React projects until awesomeness

22 lines (21 loc) 856 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.useDrag = void 0; const context_1 = require("../context"); const react_1 = require("@use-gesture/react"); function useDrag(handler, config) { const { emitOnEditStart, emitOnEditEnd } = (0, context_1.useInputContext)(); return (0, react_1.useDrag)((state) => { if (state.first) { document.body.classList.add('tweak__panel__dragged'); emitOnEditStart === null || emitOnEditStart === void 0 ? void 0 : emitOnEditStart(); } const result = handler(state); if (state.last) { document.body.classList.remove('tweak__panel__dragged'); emitOnEditEnd === null || emitOnEditEnd === void 0 ? void 0 : emitOnEditEnd(); } return result; }, config); } exports.useDrag = useDrag;