UNPKG

react-goodies

Version:

[![Build Status][build-badge]][build] [![Code Coverage][coverage-badge]][coverage] [![downloads][downloads-badge]][npmcharts] [![version][version-badge]][package] [![MIT License][license-badge]][license]

3 lines (2 loc) 8.55 kB
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("react"),require("prop-types")):"function"==typeof define&&define.amd?define(["exports","react","prop-types"],e):e(t.ReactGoodies={},t.React,t.PropTypes)}(this,function(t,e,n){"use strict";var r="default"in e?e.default:e;function o(){}function i(t,e){var n=Array.isArray(t)?t[0]:t;return!n&&e?e:n}n=n&&n.hasOwnProperty("default")?n.default:n;var s=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},u=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t},c=function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)},a=function(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e},p=function(t){function e(){var n,r;s(this,e);for(var o=arguments.length,i=Array(o),u=0;u<o;u++)i[u]=arguments[u];return n=r=a(this,t.call.apply(t,[this].concat(i))),r.isTouch=!1,r.setRef=function(t){r.container=t},r.handle=function(t){if("touchend"===t.type&&(r.isTouch=!0),"click"!==t.type||!r.isTouch){var e=r.props.onClickOutside;r.container.contains(t.target)||e(t)}},a(r,n)}return c(e,t),e.prototype.addListener=function(){document.addEventListener("touchend",this.handle,!0),document.addEventListener("click",this.handle,!0)},e.prototype.removeListener=function(){document.removeEventListener("touchend",this.handle,!0),document.removeEventListener("click",this.handle,!0)},e.prototype.componentDidMount=function(){this.props.disabled||this.addListener()},e.prototype.componentDidUpdate=function(t){var e=this.props.disabled;t.disabled!==e&&(e?this.removeListener():this.addListener())},e.prototype.componentWillUnmount=function(){this.removeListener()},e.prototype.render=function(){return i(this.props.children,o)({setRef:this.setRef})},e}(e.Component),f=function(t){function e(){var n,r;s(this,e);for(var o=arguments.length,i=Array(o),c=0;c<o;c++)i[c]=arguments[c];return n=r=a(this,t.call.apply(t,[this].concat(i))),r.state={},r.setRef=function(t){r.domNode=t},r.onObserve=function(t){var e=r.props.thresholds;r.setState(Object.keys(e).reduce(function(n,r){return u({},n,t.reduce(function(t,n){var o;return u({},t,((o={})[r]=n.isIntersecting&&n.intersectionRatio>=e[r],o))},{}))},{}))},a(r,n)}return c(e,t),e.prototype.componentDidMount=function(){var t=this.props,e=t.thresholds,n=t.options;this.observer=new global.IntersectionObserver(this.onObserve,u({},n,{threshold:Object.keys(e).map(function(t){return e[t]})})),this.observer.observe(this.domNode)},e.prototype.componentWillUnmount=function(){this.observer&&this.observer.disconnect&&this.observer.disconnect()},e.prototype.render=function(){return i(this.props.children,o)(u({setRef:this.setRef},this.state))},e}(e.Component);f.defaultProps={thresholds:{},options:{}};var l,h,d=(function(t,e){Object.defineProperty(e,"__esModule",{value:!0}),e.default=function(t){return t.displayName||t.name||("string"==typeof t&&t.length>0?t:"Unknown")}}(l={exports:{}},l.exports),l.exports);(h=d)&&h.__esModule&&Object.prototype.hasOwnProperty.call(h,"default")&&h.default;var v="function"==typeof global.IntersectionObserver,y=function(t){return t.replace(/[A-Z]/g,function(t){return"-"+t.toLowerCase()}).toLowerCase()},b=function(t){var e="",n=Object.keys(t);return n.forEach(function(r,o){var i=t[r];(function(t){return/[height|width]$/.test(t)})(r=y(r))&&"number"==typeof i&&(i+="px"),e+=!0===i?r:!1===i?"not "+r:"("+r+": "+i+")",o<n.length-1&&(e+=" and ")}),e},m=function(t){var e="";return"string"==typeof t?t:t instanceof Array?(t.forEach(function(n,r){e+=b(n),r<t.length-1&&(e+=", ")}),e):b(t)},g=function(t){var e=function(t){return global.matchMedia(m(t))}(t);return{matches:e.matches,subscribe:function(t){return e.addListener(t),function(){return e.removeListener(t)}}}},O=function(t){function e(n,r){s(this,e);var o=a(this,t.call(this,n,r)),i=n.query;return o.propsMatchers=Object.keys(i).map(function(t){return u({prop:t},g(i[t]))}),o.state=o.propsMatchers.reduce(function(t,e){var n;return u({},t,((n={})[e.prop]=e.matches,n))},{}),o}return c(e,t),e.prototype.componentDidMount=function(){var t=this;this.unsubscribers=this.propsMatchers.map(function(e){return e.subscribe(function(n){var r;t.setState(((r={})[e.prop]=n.matches,r))})})},e.prototype.componentWillUnmount=function(){this.unsubscribers.forEach(function(t){return t()})},e.prototype.render=function(){return i(this.props.children,o)(u({},this.state))},e}(e.Component);O.defaultProps={query:{}};var E="function"==typeof global.matchMedia,L=function(t){function e(n,r){s(this,e);var o=a(this,t.call(this,n,r));o.handleOnline=function(){o.setState({isOnline:!0,isOffline:!1})},o.handleOffline=function(){o.setState({isOnline:!1,isOffline:!0})};var i=global.navigator.onLine;return o.state={isOnline:i,isOffline:!i},o}return c(e,t),e.prototype.componentDidMount=function(){global.addEventListener("online",this.handleOnline,!1),global.addEventListener("offline",this.handleOffline,!1)},e.prototype.componentWillUnmount=function(){global.removeEventListener("online",this.handleOnline),global.removeEventListener("offline",this.handleOffline)},e.prototype.render=function(){return i(this.props.children,o)(u({},this.state))},e}(e.Component),w=global.navigator&&void 0!==global.navigator.onLine,C=function(t){return t},M=function(t){return{isVisible:"visible"===t,isHidden:"hidden"===t,isPrerendered:"prerender"===t,isUnloaded:"unloaded"===t}},j=function(t){function e(n,r){s(this,e);var o=a(this,t.call(this,n,r));return o.onVibisilityChange=function(){o.setState(M(document.visibilityState))},o.state=M(document.visibilityState),o}return c(e,t),e.prototype.componentDidMount=function(){document.addEventListener("visibilitychange",this.onVibisilityChange,!1)},e.prototype.componentWillUnmount=function(){document.removeEventListener("visibilitychange",this.onVibisilityChange)},e.prototype.render=function(){return i(this.props.children,o)(u({},this.state))},e}(e.Component),R=global.document&&void 0!==global.document.visibilityState,P=function(t){return t};t.ClickOutside=p,t.IntersectionObserverComp=f,t.withIntersectionObserver=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=t.thresholds,o=t.options,i=t.refKey,p=void 0===i?"setRef":i;return function(t){return v?function(e){function i(){var t,n;s(this,i);for(var r=arguments.length,o=Array(r),u=0;u<r;u++)o[u]=arguments[u];return t=n=a(this,e.call.apply(e,[this].concat(o))),n.setRef=function(t,e){t(e),"function"==typeof n.props[p]&&n.props[p](e)},a(n,t)}return c(i,e),i.prototype.render=function(){var e=this;return r.createElement(f,{thresholds:n,options:o},function(n){var o,i=n.setRef,s=function(t,e){var n={};for(var r in t)e.indexOf(r)>=0||Object.prototype.hasOwnProperty.call(t,r)&&(n[r]=t[r]);return n}(n,["setRef"]),c=((o={})[p]=e.setRef.bind(e,i),o);return r.createElement(t,u({},e.props,c,s))})},i}(e.Component):t}},t.MatchMedia=O,t.withMatchMedia=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return function(n){return E?function(e){function o(){return s(this,o),a(this,e.apply(this,arguments))}return c(o,e),o.prototype.render=function(){var e=this;return r.createElement(O,{query:t},function(t){return r.createElement(n,u({},e.props,t))})},o}(e.Component):n}},t.OnlineStatus=L,t.withOnlineStatus=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:C;return function(n){return w?function(e){function o(){return s(this,o),a(this,e.apply(this,arguments))}return c(o,e),o.prototype.render=function(){var e=this;return r.createElement(L,null,function(o){return r.createElement(n,u({},e.props,t(o)))})},o}(e.Component):n}},t.PageVisibility=j,t.withPageVisibility=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:P;return function(n){return R?function(e){function o(){return s(this,o),a(this,e.apply(this,arguments))}return c(o,e),o.prototype.render=function(){var e=this;return r.createElement(j,null,function(o){return r.createElement(n,u({},e.props,t(o)))})},o}(e.Component):n}},Object.defineProperty(t,"__esModule",{value:!0})}); //# sourceMappingURL=react-goodies.umd.min.js.map