UNPKG

@nethesis/phone-island

Version:
3 lines (2 loc) 2.28 kB
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../node_modules/tslib/tslib.es6.js"),t=require("react"),r=require("../store/index.js");require("../node_modules/react-redux/es/index.js");var o=require("../utils/customHooks/useLocalStorage.js"),s=require("../utils/customHooks/useLongPress.js"),n=require("../utils/genericFunctions/styleTransformValues.js"),i=require("../lib/island/island.js"),a=require("../node_modules/framer-motion/dist/es/gestures/drag/use-drag-controls.mjs.js"),u=require("../node_modules/framer-motion/dist/es/render/components/motion/proxy.mjs.js"),l=require("../node_modules/react-redux/es/hooks/useSelector.js"),d=require("../node_modules/react-redux/es/hooks/useDispatch.js");function c(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var p=c(t),g=function(c){var g=c.children,f=c.islandContainerRef,m=l.useSelector((function(e){return e.island})).startPosition,v=t.useState(!1),x=v[0],j=v[1],y=d.useDispatch(),h=a.useDragControls(),q=o.useLocalStorage("phone-island",null),_=q[0],b=q[1],D=t.useRef(null),P=t.useState(_&&_.position?_.position:null),S=P[0],C=P[1];var L=s.useLongPress((function(){}),(function(e){var t,o;if(e&&e.target){var s=e.target;if(s.closest('[data-stop-propagation="true"]')||s.hasAttribute("data-stop-propagation"))return}!(null===(o=null===(t=null===r.store||void 0===r.store?void 0:r.store.getState())||void 0===t?void 0:t.island)||void 0===o?void 0:o.isOpen)&&y.island.handleToggleIsOpen()}),x,(function(){return j(!1)}),{shouldPreventDefault:!0,delay:250});return p.default.createElement(u.motion.div,e.__assign({drag:!0,onPointerDown:function(e){var t=e.target;t.closest('[data-stop-propagation="true"]')||t.hasAttribute("data-stop-propagation")||h.start(e)},onDragStart:function(){j(!0)},dragTransition:{power:0,timeConstant:300},initial:{x:(null==S?void 0:S.x)||m.x,y:(null==S?void 0:S.y)||m.y},dragControls:h,dragListener:!1,dragConstraints:f,onDragEnd:function(){var e=n.styleTransformValues(D.current),t=e.x,r=e.y;t=i.xPosition(Math.round(t),D.current,f.current),r=i.yPosition(Math.round(r),D.current,f.current),b({position:{x:t,y:r}}),C({x:t,y:r})},ref:D},L,{className:"pi-absolute"}),g&&g)};exports.IslandDrag=g,exports.default=g; //# sourceMappingURL=IslandDrag.js.map