UNPKG

react-composite-events

Version:

A collection of higher-order components (HOCs) to easily create composite events in React components

3 lines (2 loc) 5.55 kB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],t):t(e.RCE={},e.React)}(this,function(e,t){"use strict";var n="default"in t?t.default:t,o=function(e){return"string"==typeof e?e:e.displayName||e.name||"WrapperComponent"},r=function(e,t){var n=babelHelpers.extends({},e);return delete n[t],n},i=function(e,t){return(e||[]).reduce(function(e,n){return babelHelpers.extends({},e,babelHelpers.defineProperty({},n,t.bind(null,n)))},{})},a=function(e){return e>0},u=function(e){var u=e.eventPropName,l=e.triggerEvent,c=e.defaultDuration,s=void 0===c?0:c,v=e.cancelEvent,p=e.shouldResetTimerOnRetrigger,m=void 0===p||p,d=e.beforeHandle,f=void 0===d?function(){return!0}:d,h=Array.isArray(l)?l:[l],g=void 0;return v&&(g=Array.isArray(v)?v:[v]),function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,l=s,c="";a(s)&&a(e)&&(l=e,c="-"+e);var v=""+u+c;return function(e){var s,p,d=o(e);return p=s=function(t){function o(){var e,t,n,r;babelHelpers.classCallCheck(this,o);for(var i=arguments.length,u=Array(i),c=0;c<i;c++)u[c]=arguments[c];return t=n=babelHelpers.possibleConstructorReturn(this,(e=o.__proto__||Object.getPrototypeOf(o)).call.apply(e,[this].concat(u))),n._delayTimeout=null,n._callSpecificHandler=function(e,t){var o=n.props[e];o&&o(t)},n._clearTimeout=function(){n._delayTimeout=clearTimeout(n._delayTimeout)},n._callCompositeEvent=function(e){var t=n.props[v];f(t,e)&&t(e)},n._handleTriggerEvent=function(e,t){var o=n.props[v];n._callSpecificHandler(e,t),o&&(a(l)?(!1!==m&&n._clearTimeout(),n._delayTimeout||(n._delayTimeout=setTimeout(function(){return n._callCompositeEvent(t)},l))):n._callCompositeEvent(t))},n._handleCancelEvent=function(e,t){n._callSpecificHandler(e,t),n._clearTimeout()},r=t,babelHelpers.possibleConstructorReturn(n,r)}return babelHelpers.inherits(o,t),babelHelpers.createClass(o,[{key:"render",value:function(){var t=r(this.props,v),o=i(h,this._handleTriggerEvent),a=i(g,this._handleCancelEvent);return n.createElement(e,babelHelpers.extends({},t,o,a))}}]),o}(t.Component),s.displayName=d+"-"+u+c,p}}},l=u({eventPropName:"onLongPress",triggerEvent:["onMouseDown","onPressIn"],defaultDuration:1250,cancelEvent:["onMouseUp","onMouseOut","onPressOut"]}),c=u({eventPropName:"onRemainReleased",triggerEvent:["onMouseUp","onPressOut"],defaultDuration:500,cancelEvent:["onMouseDown","onPressIn"]}),s=u({eventPropName:"onRemainFocused",triggerEvent:"onFocus",defaultDuration:500,cancelEvent:"onBlur"}),v=u({eventPropName:"onRemainBlurred",triggerEvent:"onBlur",defaultDuration:500,cancelEvent:"onFocus"}),p=function(e){var t=e.eventPropName,n=e.direction,o=e.location;return u({eventPropName:t,triggerEvent:"enter"===n?"onMouseEnter":"onMouseLeave",beforeHandle:function(e,t){if(!t)return!1;var n=t,r=n.screenX,i=n.screenY,a=n.currentTarget;if(!(a instanceof HTMLElement))return!1;var u=a.getBoundingClientRect(),l=u.top,c=u.left,s=u.bottom,v=u.right;return"left"===o&&r<=c||"right"===o&&r>=v||"top"===o&&i<=l||"bottom"===o&&i>=s}})},m=function(e){var t=e.eventPropName,n=e.mouseEvent,o=e.alt,r=void 0!==o&&o,i=e.ctrl,a=void 0!==i&&i,l=e.meta,c=void 0!==l&&l,s=e.shift,v=void 0!==s&&s;return u({eventPropName:t,triggerEvent:n,beforeHandle:function(e,t){var n=t;return n&&n.altKey===r&&n.ctrlKey===a&&n.metaKey===c&&n.shiftKey===v}})},d=u({eventPropName:"onMouseRest",triggerEvent:["onMouseOver","onMouseMove"],defaultDuration:500,cancelEvent:["onMouseOut","onMouseDown"]}),f=u({eventPropName:"onMouseRemainOver",triggerEvent:["onMouseOver","onMouseMove"],defaultDuration:500,cancelEvent:["onMouseOut","onMouseDown"],shouldResetTimerOnRetrigger:!1}),h=u({eventPropName:"onMouseRemainOut",triggerEvent:"onMouseOut",defaultDuration:500,cancelEvent:"onMouseOver"}),g=p({eventPropName:"onMouseEnterLeft",direction:"enter",location:"left"}),E=p({eventPropName:"onMouseEnterRight",direction:"enter",location:"right"}),M=p({eventPropName:"onMouseEnterTop",direction:"enter",location:"top"}),y=p({eventPropName:"onMouseEnterBottom",direction:"enter",location:"bottom"}),P=p({eventPropName:"onMouseLeaveLeft",direction:"leave",location:"left"}),b=p({eventPropName:"onMouseLeaveRight",direction:"leave",location:"right"}),C=p({eventPropName:"onMouseLeaveTop",direction:"leave",location:"top"}),R=p({eventPropName:"onMouseLeaveBottom",direction:"leave",location:"bottom"}),w=m({eventPropName:"onOnlyClick",mouseEvent:"onClick"}),N=m({eventPropName:"onAltClick",mouseEvent:"onClick",alt:!0}),_=m({eventPropName:"onCtrlClick",mouseEvent:"onClick",ctrl:!0}),O=m({eventPropName:"onMetaClick",mouseEvent:"onClick",meta:!0}),T=m({eventPropName:"onShiftClick",mouseEvent:"onClick",shift:!0}),D=u({eventPropName:"onKeyRemainDown",triggerEvent:"onKeyDown",defaultDuration:500,cancelEvent:"onKeyUp"}),k=u({eventPropName:"onKeyRemainUp",triggerEvent:"onKeyUp",defaultDuration:500,cancelEvent:"onKeyDown"});e.compose=u,e.withLongPress=l,e.withRemainReleased=c,e.withRemainFocused=s,e.withRemainBlurred=v,e.composeMouseModifierKey=m,e.withMouseRest=d,e.withMouseRemainOver=f,e.withMouseRemainOut=h,e.withMouseEnterLeft=g,e.withMouseEnterRight=E,e.withMouseEnterTop=M,e.withMouseEnterBottom=y,e.withMouseLeaveLeft=P,e.withMouseLeaveRight=b,e.withMouseLeaveTop=C,e.withMouseLeaveBottom=R,e.withOnlyClick=w,e.withAltClick=N,e.withCtrlClick=_,e.withMetaClick=O,e.withShiftClick=T,e.withKeyRemainDown=D,e.withKeyRemainUp=k,Object.defineProperty(e,"__esModule",{value:!0})}); //# sourceMappingURL=react-composite-events.min.js.map