From 93f58b921b5a7c0d2ad6d23c9250d25ae504fafe Mon Sep 17 00:00:00 2001 From: preysifeiti Date: Sun, 21 Jul 2019 18:37:03 +0000 Subject: [PATCH] hmmm --- dist/ReactOnScreen.js | 2 +- dist/ReactOnScreen.js.map | 2 +- lib/TrackVisibility.js | 4 ++-- src/TrackVisibility.js | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/dist/ReactOnScreen.js b/dist/ReactOnScreen.js index 29e017a..b0265a2 100644 --- a/dist/ReactOnScreen.js +++ b/dist/ReactOnScreen.js @@ -1,2 +1,2 @@ -!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("prop-types"),require("react"),require("lodash.throttle"),require("shallowequal")):"function"==typeof define&&define.amd?define(["prop-types","react","lodash.throttle","shallowequal"],t):"object"==typeof exports?exports.ReactOnScreen=t(require("prop-types"),require("react"),require("lodash.throttle"),require("shallowequal")):e.ReactOnScreen=t(e["prop-types"],e.react,e["lodash.throttle"],e.shallowequal)}(window,function(e,t,o,r){return function(e){var t={};function o(r){if(t[r])return t[r].exports;var n=t[r]={i:r,l:!1,exports:{}};return e[r].call(n.exports,n,n.exports,o),n.l=!0,n.exports}return o.m=e,o.c=t,o.d=function(e,t,r){o.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},o.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},o.t=function(e,t){if(1&t&&(e=o(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(o.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var n in e)o.d(r,n,function(t){return e[t]}.bind(null,n));return r},o.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return o.d(t,"a",t),t},o.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},o.p="",o(o.s=4)}([function(t,o){t.exports=e},function(e,o){e.exports=t},function(e,t){e.exports=o},function(e,t){e.exports=r},function(e,t,o){"use strict";o.r(t);var r=o(1),n=o.n(r),i=o(0),s=o.n(i),l=o(2),p=o.n(l),a=o(3),u=o.n(a);function c(){return(c=Object.assign||function(e){for(var t=1;t=f&&i+p>=h&&s-a<=y&&l-p<=b:n>=f&&i>=h&&s<=y&&l<=b},o.isComponentVisible=function(){setTimeout(function(){if(console.log("IS COMPONENT VISIBLE!?"),o.nodeRef&&o.nodeRef.getBoundingClientRect){var e=document.documentElement,t=o.props.once,r=o.nodeRef.getBoundingClientRect(),n=o.props.body?document.getElementById(o.props.body).innerWidth:window.innerWidth||e.clientWidth,i=o.props.body?document.getElementById(o.props.body).innerHeight:window.innerHeight||e.clientHeight,s=o.isVisible(r,n,i);s&&t&&o.removeListener(),o.setState({isVisible:s})}},0)},o.setNodeRef=function(e){return o.nodeRef=e},o.ownProps=Object.keys(r.propTypes),o.state={isVisible:!1},o.throttleCb=p()(o.isComponentVisible,o.props.throttleInterval),t.nodeRef&&o.setNodeRef(t.nodeRef),o}o=e,(t=r).prototype=Object.create(o.prototype),t.prototype.constructor=t,t.__proto__=o;var i=r.prototype;return i.componentDidMount=function(){this.attachListener(),this.isComponentVisible()},i.componentDidUpdate=function(e){u()(this.getChildProps(this.props),this.getChildProps(e))||this.isComponentVisible()},i.componentWillUnmount=function(){this.removeListener()},i.attachListener=function(){this.props.body?document.getElementById(this.props.body).addEventListener("scroll",this.throttleCb):window.addEventListener("scroll",this.throttleCb),this.props.body?document.getElementById(this.props.body).addEventListener("resize",this.throttleCb):window.addEventListener("resize",this.throttleCb)},i.removeListener=function(){this.props.body?document.getElementById(this.props.body).removeEventListener("scroll",this.throttleCb):window.removeEventListener("scroll",this.throttleCb),this.props.body?document.getElementById(this.props.body).removeEventListener("resize",this.throttleCb):window.removeEventListener("resize",this.throttleCb)},i.getChildProps=function(e){var t=this;void 0===e&&(e=this.props);var o={};return Object.keys(e).forEach(function(r){-1===t.ownProps.indexOf(r)&&(o[r]=e[r])}),o},i.getChildren=function(){var e=this;return"function"==typeof this.props.children?this.props.children(c({},this.getChildProps(),{isVisible:this.state.isVisible})):n.a.Children.map(this.props.children,function(t){return n.a.cloneElement(t,c({},e.getChildProps(),{isVisible:e.state.isVisible}))})},i.render=function(){var e=this.props,t=e.className,o=e.style,r=e.nodeRef,i=e.tag,s=c({},t&&{className:t},{},o&&{style:o});return n.a.createElement(i,c({ref:!r&&this.setNodeRef},s),this.getChildren())},r}(r.PureComponent);d.propTypes={once:s.a.bool,throttleInterval:function(e,t,o){var r=e[t];return!Number.isInteger(r)||r<0?new Error("The "+t+" prop you provided to "+o+" is not a valid integer >= 0."):null},children:s.a.oneOfType([s.a.func,s.a.element,s.a.arrayOf(s.a.element)]),style:s.a.object,className:s.a.string,offset:s.a.number,partialVisibility:s.a.bool,nodeRef:s.a.object,tag:s.a.string,body:s.a.string},d.defaultProps={once:!1,throttleInterval:150,offset:0,partialVisibility:!1,tag:"div"};t.default=d}])}); +!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("prop-types"),require("react"),require("lodash.throttle"),require("shallowequal")):"function"==typeof define&&define.amd?define(["prop-types","react","lodash.throttle","shallowequal"],t):"object"==typeof exports?exports.ReactOnScreen=t(require("prop-types"),require("react"),require("lodash.throttle"),require("shallowequal")):e.ReactOnScreen=t(e["prop-types"],e.react,e["lodash.throttle"],e.shallowequal)}(window,function(e,t,o,r){return function(e){var t={};function o(r){if(t[r])return t[r].exports;var n=t[r]={i:r,l:!1,exports:{}};return e[r].call(n.exports,n,n.exports,o),n.l=!0,n.exports}return o.m=e,o.c=t,o.d=function(e,t,r){o.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},o.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},o.t=function(e,t){if(1&t&&(e=o(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(o.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var n in e)o.d(r,n,function(t){return e[t]}.bind(null,n));return r},o.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return o.d(t,"a",t),t},o.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},o.p="",o(o.s=4)}([function(t,o){t.exports=e},function(e,o){e.exports=t},function(e,t){e.exports=o},function(e,t){e.exports=r},function(e,t,o){"use strict";o.r(t);var r=o(1),n=o.n(r),i=o(0),s=o.n(i),l=o(2),p=o.n(l),a=o(3),u=o.n(a);function c(){return(c=Object.assign||function(e){for(var t=1;t=f&&i+p>=h&&s-a<=y&&l-p<=b:n>=f&&i>=h&&s<=y&&l<=b},o.isComponentVisible=function(){setTimeout(function(){if(console.log("IS COMPONENT VISIBLE!?"),o.nodeRef&&o.nodeRef.getBoundingClientRect){var e=document.documentElement,t=o.props.once,r=o.nodeRef.getBoundingClientRect(),n=window.innerWidth||e.clientWidth,i=window.innerHeight||e.clientHeight,s=o.isVisible(r,n,i);s&&t&&o.removeListener(),o.setState({isVisible:s})}},0)},o.setNodeRef=function(e){return o.nodeRef=e},o.ownProps=Object.keys(r.propTypes),o.state={isVisible:!1},o.throttleCb=p()(o.isComponentVisible,o.props.throttleInterval),t.nodeRef&&o.setNodeRef(t.nodeRef),o}o=e,(t=r).prototype=Object.create(o.prototype),t.prototype.constructor=t,t.__proto__=o;var i=r.prototype;return i.componentDidMount=function(){this.attachListener(),this.isComponentVisible()},i.componentDidUpdate=function(e){u()(this.getChildProps(this.props),this.getChildProps(e))||this.isComponentVisible()},i.componentWillUnmount=function(){this.removeListener()},i.attachListener=function(){this.props.body?document.getElementById(this.props.body).addEventListener("scroll",this.throttleCb):window.addEventListener("scroll",this.throttleCb),this.props.body?document.getElementById(this.props.body).addEventListener("resize",this.throttleCb):window.addEventListener("resize",this.throttleCb)},i.removeListener=function(){this.props.body?document.getElementById(this.props.body).removeEventListener("scroll",this.throttleCb):window.removeEventListener("scroll",this.throttleCb),this.props.body?document.getElementById(this.props.body).removeEventListener("resize",this.throttleCb):window.removeEventListener("resize",this.throttleCb)},i.getChildProps=function(e){var t=this;void 0===e&&(e=this.props);var o={};return Object.keys(e).forEach(function(r){-1===t.ownProps.indexOf(r)&&(o[r]=e[r])}),o},i.getChildren=function(){var e=this;return"function"==typeof this.props.children?this.props.children(c({},this.getChildProps(),{isVisible:this.state.isVisible})):n.a.Children.map(this.props.children,function(t){return n.a.cloneElement(t,c({},e.getChildProps(),{isVisible:e.state.isVisible}))})},i.render=function(){var e=this.props,t=e.className,o=e.style,r=e.nodeRef,i=e.tag,s=c({},t&&{className:t},{},o&&{style:o});return n.a.createElement(i,c({ref:!r&&this.setNodeRef},s),this.getChildren())},r}(r.PureComponent);d.propTypes={once:s.a.bool,throttleInterval:function(e,t,o){var r=e[t];return!Number.isInteger(r)||r<0?new Error("The "+t+" prop you provided to "+o+" is not a valid integer >= 0."):null},children:s.a.oneOfType([s.a.func,s.a.element,s.a.arrayOf(s.a.element)]),style:s.a.object,className:s.a.string,offset:s.a.number,partialVisibility:s.a.bool,nodeRef:s.a.object,tag:s.a.string,body:s.a.string},d.defaultProps={once:!1,throttleInterval:150,offset:0,partialVisibility:!1,tag:"div"};t.default=d}])}); //# sourceMappingURL=ReactOnScreen.js.map \ No newline at end of file diff --git a/dist/ReactOnScreen.js.map b/dist/ReactOnScreen.js.map index 1033788..75cc54e 100644 --- a/dist/ReactOnScreen.js.map +++ b/dist/ReactOnScreen.js.map @@ -1 +1 @@ -{"version":3,"sources":["webpack://ReactOnScreen/webpack/universalModuleDefinition","webpack://ReactOnScreen/webpack/bootstrap","webpack://ReactOnScreen/external \"prop-types\"","webpack://ReactOnScreen/external \"react\"","webpack://ReactOnScreen/external \"lodash.throttle\"","webpack://ReactOnScreen/external \"shallowequal\"","webpack://ReactOnScreen/./src/TrackVisibility.js","webpack://ReactOnScreen/./src/index.js"],"names":["root","factory","exports","module","require","define","amd","window","__WEBPACK_EXTERNAL_MODULE__0__","__WEBPACK_EXTERNAL_MODULE__1__","__WEBPACK_EXTERNAL_MODULE__2__","__WEBPACK_EXTERNAL_MODULE__3__","installedModules","__webpack_require__","moduleId","i","l","modules","call","m","c","d","name","getter","o","Object","defineProperty","enumerable","get","r","Symbol","toStringTag","value","t","mode","__esModule","ns","create","key","bind","n","object","property","prototype","hasOwnProperty","p","s","TrackVisibility","props","_this","_PureComponent","this","isVisible","_ref","windowWidth","windowHeight","top","left","bottom","right","width","height","_this$props","offset","partialVisibility","topThreshold","leftThreshold","widthCheck","heightCheck","isComponentVisible","setTimeout","console","log","nodeRef","getBoundingClientRect","html","document","documentElement","once","boundingClientRect","body","getElementById","innerWidth","clientWidth","innerHeight","clientHeight","removeListener","setState","setNodeRef","ref","ownProps","keys","propTypes","state","throttleCb","throttle","throttleInterval","componentDidMount","attachListener","componentDidUpdate","prevProps","shallowequal","getChildProps","componentWillUnmount","addEventListener","removeEventListener","_this2","childProps","forEach","indexOf","getChildren","_this3","children","_extends","React","Children","map","child","cloneElement","render","_this$props2","className","style","Tag","tag","external_react_default","a","createElement","PureComponent","PropTypes","bool","propName","component","currentProp","Number","isInteger","Error","oneOfType","func","element","arrayOf","string","number","defaultProps"],"mappings":"CAAA,SAAAA,EAAAC,GACA,iBAAAC,SAAA,iBAAAC,OACAA,OAAAD,QAAAD,EAAAG,QAAA,cAAAA,QAAA,SAAAA,QAAA,mBAAAA,QAAA,iBACA,mBAAAC,eAAAC,IACAD,OAAA,wDAAAJ,GACA,iBAAAC,QACAA,QAAA,cAAAD,EAAAG,QAAA,cAAAA,QAAA,SAAAA,QAAA,mBAAAA,QAAA,iBAEAJ,EAAA,cAAAC,EAAAD,EAAA,cAAAA,EAAA,MAAAA,EAAA,mBAAAA,EAAA,cARA,CASCO,OAAA,SAAAC,EAAAC,EAAAC,EAAAC,GACD,mBCTA,IAAAC,EAAA,G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AUY,OAKf7D,KAAMiD,IAAUY,QAhEC9F,EAmEZgG,aAAe,CACpBjE,MAAM,EACNkB,iBAAkB,IAClBjC,OAAQ,EACRC,mBAAmB,EACnB4D,IAAK,OCzEM7E","file":"ReactOnScreen.js","sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory(require(\"prop-types\"), require(\"react\"), require(\"lodash.throttle\"), require(\"shallowequal\"));\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([\"prop-types\", \"react\", \"lodash.throttle\", \"shallowequal\"], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"ReactOnScreen\"] = factory(require(\"prop-types\"), require(\"react\"), require(\"lodash.throttle\"), require(\"shallowequal\"));\n\telse\n\t\troot[\"ReactOnScreen\"] = factory(root[\"prop-types\"], root[\"react\"], root[\"lodash.throttle\"], root[\"shallowequal\"]);\n})(window, function(__WEBPACK_EXTERNAL_MODULE__0__, __WEBPACK_EXTERNAL_MODULE__1__, __WEBPACK_EXTERNAL_MODULE__2__, __WEBPACK_EXTERNAL_MODULE__3__) {\nreturn "," \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 4);\n","module.exports = __WEBPACK_EXTERNAL_MODULE__0__;","module.exports = __WEBPACK_EXTERNAL_MODULE__1__;","module.exports = __WEBPACK_EXTERNAL_MODULE__2__;","module.exports = __WEBPACK_EXTERNAL_MODULE__3__;","/* global window, document */\nimport React, { PureComponent } from 'react';\nimport PropTypes from 'prop-types';\nimport throttle from 'lodash.throttle';\nimport shallowequal from 'shallowequal';\n\nexport default class TrackVisibility extends PureComponent {\n static propTypes = {\n /**\n * Define if the visibility need to be tracked once\n */\n once: PropTypes.bool,\n\n /**\n * Tweak the throttle interval\n * Check https://css-tricks.com/debouncing-throttling-explained-examples/ for more details\n */\n throttleInterval(props, propName, component) {\n const currentProp = props[propName];\n if (!Number.isInteger(currentProp) || currentProp < 0) {\n return new Error(\n `The ${propName} prop you provided to ${component} is not a valid integer >= 0.`\n );\n }\n return null;\n },\n\n /**\n * Pass one or more children to track\n */\n children: PropTypes.oneOfType([\n PropTypes.func,\n PropTypes.element,\n PropTypes.arrayOf(PropTypes.element)\n ]),\n\n /**\n * Additional style to apply\n */\n style: PropTypes.object,\n\n /**\n * Additional className to apply\n */\n className: PropTypes.string,\n\n /**\n * Define an offset. Can be useful for lazy loading\n */\n offset: PropTypes.number,\n\n /**\n * Update the visibility state as soon as a part of the tracked component is visible\n */\n partialVisibility: PropTypes.bool,\n\n /**\n * Exposed for testing but allows node other than internal wrapping
to be tracked\n * for visibility\n */\n nodeRef: PropTypes.object,\n\n /**\n * Define a custom tag\n */\n tag: PropTypes.string,\n\n /**\n * what to attach scroll listeners to\n */\n body: PropTypes.string\n };\n\n static defaultProps = {\n once: false,\n throttleInterval: 150,\n offset: 0,\n partialVisibility: false,\n tag: 'div'\n };\n\n constructor(props) {\n super(props);\n this.ownProps = Object.keys(TrackVisibility.propTypes);\n this.state = {\n isVisible: false\n };\n this.throttleCb = throttle(\n this.isComponentVisible,\n this.props.throttleInterval\n );\n\n props.nodeRef && this.setNodeRef(props.nodeRef);\n }\n\n componentDidMount() {\n this.attachListener();\n this.isComponentVisible();\n }\n\n componentDidUpdate(prevProps) {\n if (\n !shallowequal(\n this.getChildProps(this.props),\n this.getChildProps(prevProps)\n )\n ) {\n this.isComponentVisible();\n }\n }\n\n componentWillUnmount() {\n this.removeListener();\n }\n\n attachListener() {\n this.props.body ? document.getElementById(this.props.body).addEventListener('scroll', this.throttleCb) : window.addEventListener('scroll', this.throttleCb);\n this.props.body ? document.getElementById(this.props.body).addEventListener('resize', this.throttleCb) : window.addEventListener('resize', this.throttleCb)\n }\n\n removeListener() {\n this.props.body ? document.getElementById(this.props.body).removeEventListener('scroll', this.throttleCb) : window.removeEventListener('scroll', this.throttleCb);\n this.props.body ? document.getElementById(this.props.body).removeEventListener('resize', this.throttleCb) : window.removeEventListener('resize', this.throttleCb);\n }\n\n getChildProps(props = this.props) {\n const childProps = {};\n Object.keys(props).forEach(key => {\n if (this.ownProps.indexOf(key) === -1) {\n childProps[key] = props[key];\n }\n });\n return childProps;\n }\n\n isVisible = (\n { top, left, bottom, right, width, height },\n windowWidth,\n windowHeight\n ) => {\n const { offset, partialVisibility } = this.props;\n\n if (top + right + bottom + left === 0) {\n return false;\n }\n\n const topThreshold = 0 - offset;\n const leftThreshold = 0 - offset;\n const widthCheck = windowWidth + offset;\n const heightCheck = windowHeight + offset;\n\n return partialVisibility\n ? top + height >= topThreshold &&\n left + width >= leftThreshold &&\n bottom - height <= heightCheck &&\n right - width <= widthCheck\n : top >= topThreshold &&\n left >= leftThreshold &&\n bottom <= heightCheck &&\n right <= widthCheck;\n };\n\n isComponentVisible = () => {\n setTimeout(() => {\n console.log(\"IS COMPONENT VISIBLE!?\")\n // isComponentVisible might be called from componentDidMount, before component ref is assigned\n if (!this.nodeRef || !this.nodeRef.getBoundingClientRect) return;\n\n const html = document.documentElement;\n const { once } = this.props;\n const boundingClientRect = this.nodeRef.getBoundingClientRect();\n const windowWidth = this.props.body ? document.getElementById(this.props.body).innerWidth : window.innerWidth || html.clientWidth;\n const windowHeight = this.props.body ? document.getElementById(this.props.body).innerHeight : window.innerHeight || html.clientHeight;\n\n const isVisible = this.isVisible(\n boundingClientRect,\n windowWidth,\n windowHeight\n );\n\n if (isVisible && once) {\n this.removeListener();\n }\n\n this.setState({ isVisible });\n }, 0);\n };\n\n setNodeRef = ref => (this.nodeRef = ref);\n\n getChildren() {\n if (typeof this.props.children === 'function') {\n return this.props.children({\n ...this.getChildProps(),\n isVisible: this.state.isVisible\n });\n }\n\n return React.Children.map(this.props.children, child =>\n React.cloneElement(child, {\n ...this.getChildProps(),\n isVisible: this.state.isVisible\n })\n );\n }\n\n render() {\n const { className, style, nodeRef, tag: Tag } = this.props;\n const props = {\n ...(className && { className }),\n ...(style && { style })\n };\n\n return (\n \n {this.getChildren()}\n \n );\n }\n}\n","/*\n* This file seems a bit useless anyway\n* */\nimport TrackVisibility from './TrackVisibility';\n\nexport default TrackVisibility;\n"],"sourceRoot":""} \ No newline at end of file +{"version":3,"sources":["webpack://ReactOnScreen/webpack/universalModuleDefinition","webpack://ReactOnScreen/webpack/bootstrap","webpack://ReactOnScreen/external \"prop-types\"","webpack://ReactOnScreen/external \"react\"","webpack://ReactOnScreen/external \"lodash.throttle\"","webpack://ReactOnScreen/external \"shallowequal\"","webpack://ReactOnScreen/./src/TrackVisibility.js","webpack://ReactOnScreen/./src/index.js"],"names":["root","factory","exports","module","require","define","amd","window","__WEBPACK_EXTERNAL_MODULE__0__","__WEBPACK_EXTERNAL_MODULE__1__","__WEBPACK_EXTERNAL_MODULE__2__","__WEBPACK_EXTERNAL_MODULE__3__","installedModules","__webpack_require__","moduleId","i","l","modules","call","m","c","d","name","getter","o","Object","defineProperty","enumerable","get","r","Symbol","toStringTag","value","t","mode","__esModule","ns","create","key","bind","n","object","property","prototype","hasOwnProperty","p","s","TrackVisibility","props","_this","_PureComponent","this","isVisible","_ref","windowWidth","windowHeight","top","left","bottom","right","width","height","_this$props","offset","partialVisibility","topThreshold","leftThreshold","widthCheck","heightCheck","isComponentVisible","setTimeout","console","log","nodeRef","getBoundingClientRect","html","document","documentElement","once","boundingClientRect","innerWidth","clientWidth","innerHeight","clientHeight","removeListener","setState","setNodeRef","ref","ownProps","keys","propTypes","state","throttleCb","throttle","throttleInterval","componentDidMount","attachListener","componentDidUpdate","prevProps","shallowequal","getChildProps","componentWillUnmount","body","getElementById","addEventListener","removeEventListener","_this2","childProps","forEach","indexOf","getChildren","_this3","children","_extends","React","Children","map","child","cloneElement","render","_this$props2","className","style","Tag","tag","external_react_default","a","createElement","PureComponent","PropTypes","bool","propName","component","currentProp","Number","isInteger","Error","oneOfType","func","element","arrayOf","string","number","defaultProps"],"mappings":"CAAA,SAAAA,EAAAC,GACA,iBAAAC,SAAA,iBAAAC,OACAA,OAAAD,QAAAD,EAAAG,QAAA,cAAAA,QAAA,SAAAA,QAAA,mBAAAA,QAAA,iBACA,mBAAAC,eAAAC,IACAD,OAAA,wDAAAJ,GACA,iBAAAC,QACAA,QAAA,cAAAD,EAAAG,QAAA,cAAAA,QAAA,SAAAA,QAAA,mBAAAA,QAAA,iBAEAJ,EAAA,cAAAC,EAAAD,EAAA,cAAAA,EAAA,MAAAA,EAAA,mBAAAA,EAAA,cARA,CASCO,OAAA,SAAAC,EAAAC,EAAAC,EAAAC,GACD,mBCTA,IAAAC,EAAA,GAGA,SAAAC,EAAAC,GAGA,GAAAF,EAAAE,GACA,OAAAF,EAAAE,GAAAZ,QAGA,IAAAC,EAAAS,EAAAE,GAAA,CACAC,EAAAD,EACAE,GAAA,EACAd,QAAA,IAUA,OANAe,EAAAH,GAAAI,KAAAf,EAAAD,QAAAC,IAAAD,QAAAW,GAGAV,EAAAa,GAAA,EAGAb,EAAAD,QA0DA,OArDAW,EAAAM,EAAAF,EAGAJ,EAAAO,EAAAR,EAGAC,EAAAQ,EAAA,SAAAnB,EAAAoB,EAAAC,GACAV,EAAAW,EAAAtB,EAAAoB,IACAG,OAAAC,eAAAxB,EAAAoB,EAAA,CAA0CK,YAAA,EAAAC,IAAAL,KAK1CV,EAAAgB,EAAA,SAAA3B,GACA,oBAAA4B,eAAAC,aACAN,OAAAC,eAAAxB,EAAA4B,OAAAC,YAAA,CAAwDC,MAAA,WAExDP,OAAAC,eAAAxB,EAAA,cAAiD8B,OAAA,KAQjDnB,EAAAoB,EAAA,SAAA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ACxCG,KAAK2D,mBAjN+BkB,iBAAxBjF,EACZ2C,UAAY,CAIjBZ,KAAMmD,IAAUC,KAMhBpC,iBAViB,SAUA9C,EAAOmF,EAAUC,GAChC,IAAMC,EAAcrF,EAAMmF,GAC1B,OAAKG,OAAOC,UAAUF,IAAgBA,EAAc,EAC3C,IAAIG,MAAJ,OACEL,EADF,yBACmCC,EADnC,iCAIF,MAMTpB,SAAUiB,IAAUQ,UAAU,CAC5BR,IAAUS,KACVT,IAAUU,QACVV,IAAUW,QAAQX,IAAUU,WAM9BjB,MAAOO,IAAUxF,OAKjBgF,UAAWQ,IAAUY,OAKrB9E,OAAQkE,IAAUa,OAKlB9E,kBAAmBiE,IAAUC,KAM7BzD,QAASwD,IAAUxF,OAKnBmF,IAAKK,IAAUY,OAKfvC,KAAM2B,IAAUY,QAhEC9F,EAmEZgG,aAAe,CACpBjE,MAAM,EACNgB,iBAAkB,IAClB/B,OAAQ,EACRC,mBAAmB,EACnB4D,IAAK,OCzEM7E","file":"ReactOnScreen.js","sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory(require(\"prop-types\"), require(\"react\"), require(\"lodash.throttle\"), require(\"shallowequal\"));\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([\"prop-types\", \"react\", \"lodash.throttle\", \"shallowequal\"], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"ReactOnScreen\"] = factory(require(\"prop-types\"), require(\"react\"), require(\"lodash.throttle\"), require(\"shallowequal\"));\n\telse\n\t\troot[\"ReactOnScreen\"] = factory(root[\"prop-types\"], root[\"react\"], root[\"lodash.throttle\"], root[\"shallowequal\"]);\n})(window, function(__WEBPACK_EXTERNAL_MODULE__0__, __WEBPACK_EXTERNAL_MODULE__1__, __WEBPACK_EXTERNAL_MODULE__2__, __WEBPACK_EXTERNAL_MODULE__3__) {\nreturn "," \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 4);\n","module.exports = __WEBPACK_EXTERNAL_MODULE__0__;","module.exports = __WEBPACK_EXTERNAL_MODULE__1__;","module.exports = __WEBPACK_EXTERNAL_MODULE__2__;","module.exports = __WEBPACK_EXTERNAL_MODULE__3__;","/* global window, document */\nimport React, { PureComponent } from 'react';\nimport PropTypes from 'prop-types';\nimport throttle from 'lodash.throttle';\nimport shallowequal from 'shallowequal';\n\nexport default class TrackVisibility extends PureComponent {\n static propTypes = {\n /**\n * Define if the visibility need to be tracked once\n */\n once: PropTypes.bool,\n\n /**\n * Tweak the throttle interval\n * Check https://css-tricks.com/debouncing-throttling-explained-examples/ for more details\n */\n throttleInterval(props, propName, component) {\n const currentProp = props[propName];\n if (!Number.isInteger(currentProp) || currentProp < 0) {\n return new Error(\n `The ${propName} prop you provided to ${component} is not a valid integer >= 0.`\n );\n }\n return null;\n },\n\n /**\n * Pass one or more children to track\n */\n children: PropTypes.oneOfType([\n PropTypes.func,\n PropTypes.element,\n PropTypes.arrayOf(PropTypes.element)\n ]),\n\n /**\n * Additional style to apply\n */\n style: PropTypes.object,\n\n /**\n * Additional className to apply\n */\n className: PropTypes.string,\n\n /**\n * Define an offset. Can be useful for lazy loading\n */\n offset: PropTypes.number,\n\n /**\n * Update the visibility state as soon as a part of the tracked component is visible\n */\n partialVisibility: PropTypes.bool,\n\n /**\n * Exposed for testing but allows node other than internal wrapping
to be tracked\n * for visibility\n */\n nodeRef: PropTypes.object,\n\n /**\n * Define a custom tag\n */\n tag: PropTypes.string,\n\n /**\n * what to attach scroll listeners to\n */\n body: PropTypes.string\n };\n\n static defaultProps = {\n once: false,\n throttleInterval: 150,\n offset: 0,\n partialVisibility: false,\n tag: 'div'\n };\n\n constructor(props) {\n super(props);\n this.ownProps = Object.keys(TrackVisibility.propTypes);\n this.state = {\n isVisible: false\n };\n this.throttleCb = throttle(\n this.isComponentVisible,\n this.props.throttleInterval\n );\n\n props.nodeRef && this.setNodeRef(props.nodeRef);\n }\n\n componentDidMount() {\n this.attachListener();\n this.isComponentVisible();\n }\n\n componentDidUpdate(prevProps) {\n if (\n !shallowequal(\n this.getChildProps(this.props),\n this.getChildProps(prevProps)\n )\n ) {\n this.isComponentVisible();\n }\n }\n\n componentWillUnmount() {\n this.removeListener();\n }\n\n attachListener() {\n this.props.body ? document.getElementById(this.props.body).addEventListener('scroll', this.throttleCb) : window.addEventListener('scroll', this.throttleCb);\n this.props.body ? document.getElementById(this.props.body).addEventListener('resize', this.throttleCb) : window.addEventListener('resize', this.throttleCb)\n }\n\n removeListener() {\n this.props.body ? document.getElementById(this.props.body).removeEventListener('scroll', this.throttleCb) : window.removeEventListener('scroll', this.throttleCb);\n this.props.body ? document.getElementById(this.props.body).removeEventListener('resize', this.throttleCb) : window.removeEventListener('resize', this.throttleCb);\n }\n\n getChildProps(props = this.props) {\n const childProps = {};\n Object.keys(props).forEach(key => {\n if (this.ownProps.indexOf(key) === -1) {\n childProps[key] = props[key];\n }\n });\n return childProps;\n }\n\n isVisible = (\n { top, left, bottom, right, width, height },\n windowWidth,\n windowHeight\n ) => {\n const { offset, partialVisibility } = this.props;\n\n if (top + right + bottom + left === 0) {\n return false;\n }\n\n const topThreshold = 0 - offset;\n const leftThreshold = 0 - offset;\n const widthCheck = windowWidth + offset;\n const heightCheck = windowHeight + offset;\n\n return partialVisibility\n ? top + height >= topThreshold &&\n left + width >= leftThreshold &&\n bottom - height <= heightCheck &&\n right - width <= widthCheck\n : top >= topThreshold &&\n left >= leftThreshold &&\n bottom <= heightCheck &&\n right <= widthCheck;\n };\n\n isComponentVisible = () => {\n setTimeout(() => {\n console.log(\"IS COMPONENT VISIBLE!?\")\n // isComponentVisible might be called from componentDidMount, before component ref is assigned\n if (!this.nodeRef || !this.nodeRef.getBoundingClientRect) return;\n\n const html = document.documentElement;\n const { once } = this.props;\n const boundingClientRect = this.nodeRef.getBoundingClientRect();\n const windowWidth = window.innerWidth || html.clientWidth;\n const windowHeight = window.innerHeight || html.clientHeight;\n\n const isVisible = this.isVisible(\n boundingClientRect,\n windowWidth,\n windowHeight\n );\n\n if (isVisible && once) {\n this.removeListener();\n }\n\n this.setState({ isVisible });\n }, 0);\n };\n\n setNodeRef = ref => (this.nodeRef = ref);\n\n getChildren() {\n if (typeof this.props.children === 'function') {\n return this.props.children({\n ...this.getChildProps(),\n isVisible: this.state.isVisible\n });\n }\n\n return React.Children.map(this.props.children, child =>\n React.cloneElement(child, {\n ...this.getChildProps(),\n isVisible: this.state.isVisible\n })\n );\n }\n\n render() {\n const { className, style, nodeRef, tag: Tag } = this.props;\n const props = {\n ...(className && { className }),\n ...(style && { style })\n };\n\n return (\n \n {this.getChildren()}\n \n );\n }\n}\n","/*\n* This file seems a bit useless anyway\n* */\nimport TrackVisibility from './TrackVisibility';\n\nexport default TrackVisibility;\n"],"sourceRoot":""} \ No newline at end of file diff --git a/lib/TrackVisibility.js b/lib/TrackVisibility.js index 5e0fc38..3877f1d 100644 --- a/lib/TrackVisibility.js +++ b/lib/TrackVisibility.js @@ -61,8 +61,8 @@ function (_PureComponent) { var boundingClientRect = _this.nodeRef.getBoundingClientRect(); - var windowWidth = _this.props.body ? document.getElementById(_this.props.body).innerWidth : window.innerWidth || html.clientWidth; - var windowHeight = _this.props.body ? document.getElementById(_this.props.body).innerHeight : window.innerHeight || html.clientHeight; + var windowWidth = window.innerWidth || html.clientWidth; + var windowHeight = window.innerHeight || html.clientHeight; var isVisible = _this.isVisible(boundingClientRect, windowWidth, windowHeight); diff --git a/src/TrackVisibility.js b/src/TrackVisibility.js index 40903f0..03ca743 100644 --- a/src/TrackVisibility.js +++ b/src/TrackVisibility.js @@ -169,8 +169,8 @@ export default class TrackVisibility extends PureComponent { const html = document.documentElement; const { once } = this.props; const boundingClientRect = this.nodeRef.getBoundingClientRect(); - const windowWidth = this.props.body ? document.getElementById(this.props.body).innerWidth : window.innerWidth || html.clientWidth; - const windowHeight = this.props.body ? document.getElementById(this.props.body).innerHeight : window.innerHeight || html.clientHeight; + const windowWidth = window.innerWidth || html.clientWidth; + const windowHeight = window.innerHeight || html.clientHeight; const isVisible = this.isVisible( boundingClientRect,