lazy-react 2.1.0 → 3.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/demo/demo.js +39 -56
- package/demo/index.js +218 -29
- package/demo/index.js.LICENSE.txt +32 -0
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +21 -18
- package/src/baseClass.js +71 -74
- package/src/lazyLoadBackgroundImage.js +16 -31
- package/src/lazyLoadComponent.js +20 -28
- package/src/lazyLoadFrame.js +17 -33
- package/src/lazyLoadImage.js +14 -31
- package/webpack.config.demo.js +1 -2
- package/webpack.config.js +28 -29
- package/src/indexSingleFile.js +0 -75
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/*
|
|
2
|
+
object-assign
|
|
3
|
+
(c) Sindre Sorhus
|
|
4
|
+
@license MIT
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/** @license React v0.20.2
|
|
8
|
+
* scheduler.production.min.js
|
|
9
|
+
*
|
|
10
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
11
|
+
*
|
|
12
|
+
* This source code is licensed under the MIT license found in the
|
|
13
|
+
* LICENSE file in the root directory of this source tree.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/** @license React v17.0.2
|
|
17
|
+
* react-dom.production.min.js
|
|
18
|
+
*
|
|
19
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
20
|
+
*
|
|
21
|
+
* This source code is licensed under the MIT license found in the
|
|
22
|
+
* LICENSE file in the root directory of this source tree.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
/** @license React v17.0.2
|
|
26
|
+
* react.production.min.js
|
|
27
|
+
*
|
|
28
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
29
|
+
*
|
|
30
|
+
* This source code is licensed under the MIT license found in the
|
|
31
|
+
* LICENSE file in the root directory of this source tree.
|
|
32
|
+
*/
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("react")):"function"==typeof define&&define.amd?define(["react"],t):"object"==typeof exports?exports.LazyReact=t(require("react")):e.LazyReact=t(e.React)}(window,function(n){return function(n){var r={};function o(e){if(r[e])return r[e].exports;var t=r[e]={i:e,l:!1,exports:{}};return n[e].call(t.exports,t,t.exports,o),t.l=!0,t.exports}return o.m=n,o.c=r,o.d=function(e,t,n){o.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},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(t,e){if(1&e&&(t=o(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(o.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var r in t)o.d(n,r,function(e){return t[e]}.bind(null,r));return n},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=3)}([function(e,t){e.exports=n},function(e,n,f){"use strict";(function(e){var t=f(0);function r(e){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function o(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function i(e){return(i=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function u(e,t){return(u=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function c(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}var l=function(e){var t=e.offset,n=e.top,r=e.left;return window.scrollY+window.innerHeight+t>n&&window.scrollX+window.innerWidth+t>r},s=function(e){function n(e){var t;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,n),(t=function(e,t){return!t||"object"!==r(t)&&"function"!=typeof t?c(e):t}(this,i(n).call(this,e))).state={link:"",visible:!1},t.makeItVisible=t.makeItVisible.bind(c(c(t))),t}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&u(e,t)}(n,t["Component"]),function(e,t,n){t&&o(e.prototype,t),n&&o(e,n)}(n,[{key:"makeItVisible",value:function(){this.setState({link:this.props.link,visible:!0})}},{key:"componentDidMount",value:function(){n.addElement(this)}},{key:"componentWillUnmount",value:function(){n.removeElementFromList(this)}}]),n}();s.elements=[],s.eventHandler=function(){if(0===s.elements.length)s.removeScrollHandler();else{for(var n=[],e=0;e<s.elements.length;e++)l(s.elements[e])&&(n.push(e),s.elements[e].element.makeItVisible());0<n.length&&(s.elements=s.elements.filter(function(e,t){return!n.includes(t)})),s.elements=s.elements.map(function(e){return function(e){var t=e.element.domNode.getBoundingClientRect(),n=t.top,r=t.left,o=t.right;return Object.assign({},e,{top:n,left:r,right:o})}(e)}),s.isListenerAttached=window.requestAnimationFrame(s.eventHandler)}},s.addElement=function(e){var t=e.domNode.getBoundingClientRect(),n=t.top,r=t.left,o=t.right;s.elements.push({element:e,top:n,left:r,right:o,offset:e.props.offset||100}),"function"!=typeof s.isListenerAttached&&(s.isListenerAttached=window.requestAnimationFrame(s.eventHandler))},s.removeScrollHandler=function(){window.cancelAnimationFrame(s.isListenerAttached)},s.removeElementFromList=function(t){s.elements=s.elements.filter(function(e){return e.element!==t})},s.isListenerAttached=!1,"production"===!e.NODE_ENV&&(s.propTypes={link:t.PropTypes.string.isRequired}),n.a=s}).call(this,f(2))},function(e,t){var n,r,o=e.exports={};function i(){throw new Error("setTimeout has not been defined")}function u(){throw new Error("clearTimeout has not been defined")}function c(t){if(n===setTimeout)return setTimeout(t,0);if((n===i||!n)&&setTimeout)return n=setTimeout,setTimeout(t,0);try{return n(t,0)}catch(e){try{return n.call(null,t,0)}catch(e){return n.call(this,t,0)}}}!function(){try{n="function"==typeof setTimeout?setTimeout:i}catch(e){n=i}try{r="function"==typeof clearTimeout?clearTimeout:u}catch(e){r=u}}();var l,s=[],f=!1,a=-1;function p(){f&&l&&(f=!1,l.length?s=l.concat(s):a=-1,s.length&&y())}function y(){if(!f){var e=c(p);f=!0;for(var t=s.length;t;){for(l=s,s=[];++a<t;)l&&l[a].run();a=-1,t=s.length}l=null,f=!1,function(t){if(r===clearTimeout)return clearTimeout(t);if((r===u||!r)&&clearTimeout)return r=clearTimeout,clearTimeout(t);try{r(t)}catch(e){try{return r.call(null,t)}catch(e){return r.call(this,t)}}}(e)}}function m(e,t){this.fun=e,this.array=t}function h(){}o.nextTick=function(e){var t=new Array(arguments.length-1);if(1<arguments.length)for(var n=1;n<arguments.length;n++)t[n-1]=arguments[n];s.push(new m(e,t)),1!==s.length||f||c(y)},m.prototype.run=function(){this.fun.apply(null,this.array)},o.title="browser",o.browser=!0,o.env={},o.argv=[],o.version="",o.versions={},o.on=h,o.addListener=h,o.once=h,o.off=h,o.removeListener=h,o.removeAllListeners=h,o.emit=h,o.prependListener=h,o.prependOnceListener=h,o.listeners=function(e){return[]},o.binding=function(e){throw new Error("process.binding is not supported")},o.cwd=function(){return"/"},o.chdir=function(e){throw new Error("process.chdir is not supported")},o.umask=function(){return 0}},function(e,t,n){"use strict";n.r(t);var r=n(0),o=n.n(r),i=n(1);function u(e){return(u="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function c(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function l(e,t){return!t||"object"!==u(t)&&"function"!=typeof t?function(e){if(void 0!==e)return e;throw new ReferenceError("this hasn't been initialised - super() hasn't been called")}(e):t}function s(e){return(s=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function f(e,t){return(f=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}var a=function(e){function t(e){return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),l(this,s(t).call(this,e))}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&f(e,t)}(t,i["a"]),function(e,t,n){t&&c(e.prototype,t),n&&c(e,n)}(t,[{key:"render",value:function(){var t=this;return o.a.createElement("div",{className:this.props.className,style:this.style,ref:function(e){return t.domNode=e}})}},{key:"componentWillMount",value:function(){this.style=Object.assign({backgroundImage:"url(".concat(this.state.link,")")},this.props.style)}},{key:"componentWillUpdate",value:function(e,t){this.style=Object.assign({},this.style,{backgroundImage:"url(".concat(t.link,")")})}}]),t}();function p(e){return(p="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function y(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function m(e,t){return!t||"object"!==p(t)&&"function"!=typeof t?function(e){if(void 0!==e)return e;throw new ReferenceError("this hasn't been initialised - super() hasn't been called")}(e):t}function h(e){return(h=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function b(e,t){return(b=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}a.defaultProps={className:"",style:{}};var d=function(e){function t(e){return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),m(this,h(t).call(this,e))}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&b(e,t)}(t,i["a"]),function(e,t,n){t&&y(e.prototype,t),n&&y(e,n)}(t,[{key:"render",value:function(){var t=this;return o.a.createElement("img",{src:this.state.link,alt:this.props.alt,style:this.style,className:this.props.className,ref:function(e){return t.domNode=e}})}},{key:"componentWillMount",value:function(){""===this.props.className&&!1===this.props.preserveAspect&&(this.style=Object.assign({minHeight:"300px",minWidth:"300px"},this.props.style))}}]),t}();function v(e){return(v="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function g(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function w(e,t){return!t||"object"!==v(t)&&"function"!=typeof t?function(e){if(void 0!==e)return e;throw new ReferenceError("this hasn't been initialised - super() hasn't been called")}(e):t}function O(e){return(O=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function j(e,t){return(j=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}d.defaultProps={style:{},className:"",preserveAspect:!0};var _=function(e){function t(e){return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),w(this,O(t).call(this,e))}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&j(e,t)}(t,i["a"]),function(e,t,n){t&&g(e.prototype,t),n&&g(e,n)}(t,[{key:"render",value:function(){var t=this;return o.a.createElement("iframe",{height:this.props.height,scrolling:this.props.scrolling,src:this.state.link,frameBorder:this.props.frameBorder,allowTransparency:this.props.allowTransparency,allowFullScreen:this.props.allowFullScreen,style:this.style,ref:function(e){return t.domNode=e}})}},{key:"componentWillMount",value:function(){this.style=Object.assign({minWidth:"100%"},this.props.style)}}]),t}();function S(e){return(S="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function k(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function P(e,t){return!t||"object"!==S(t)&&"function"!=typeof t?function(e){if(void 0!==e)return e;throw new ReferenceError("this hasn't been initialised - super() hasn't been called")}(e):t}function T(e){return(T=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function E(e,t){return(E=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}_.defaultProps={height:"500",scrolling:"no",frameBorder:"no",allowTransparency:"true",allowFullScreen:"true"};var x=function(e){function t(e){return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),P(this,T(t).call(this,e))}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&E(e,t)}(t,i["a"]),function(e,t,n){t&&k(e.prototype,t),n&&k(e,n)}(t,[{key:"render",value:function(){var t=this,e=this.state.visible?this.props.children:o.a.createElement("div",null);return o.a.createElement("div",{style:this.style,className:this.props.className,ref:function(e){return t.domNode=e}},e)}},{key:"componentWillMount",value:function(){this.style=Object.assign({},this.props.style),this.state.link||this.props.className||this.style.height||(this.style.height="300px")}}]),t}();x.defaultProps={style:{},className:""},n.d(t,"LazyBackgroundImage",function(){return a}),n.d(t,"LazyImage",function(){return d}),n.d(t,"LazyFrame",function(){return _}),n.d(t,"LazyComponent",function(){return x})}])});
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("react")):"function"==typeof define&&define.amd?define(["react"],t):"object"==typeof exports?exports.LazyReact=t(require("react")):e.LazyReact=t(e.React)}(self,(function(e){return(()=>{"use strict";var t={787:t=>{t.exports=e}},r={};function n(e){var o=r[e];if(void 0!==o)return o.exports;var l=r[e]={exports:{}};return t[e](l,l.exports,n),l.exports}n.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return n.d(t,{a:t}),t},n.d=(e,t)=>{for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var o={};return(()=>{n.r(o),n.d(o,{LazyBackgroundImage:()=>u,LazyComponent:()=>f,LazyFrame:()=>s,LazyImage:()=>c});var e=n(787),t=n.n(e);function r(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function l(t,n){var o,l,a=(o=(0,e.useState)({link:"",visible:!1}),l=2,function(e){if(Array.isArray(e))return e}(o)||function(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,o,l=[],i=!0,a=!1;try{for(r=r.call(e);!(i=(n=r.next()).done)&&(l.push(n.value),!t||l.length!==t);i=!0);}catch(e){a=!0,o=e}finally{try{i||null==r.return||r.return()}finally{if(a)throw o}}return l}}(o,l)||function(e,t){if(e){if("string"==typeof e)return r(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?r(e,t):void 0}}(o,l)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()),u=a[0],c=a[1];function s(){c({visible:!0,link:n.link})}return(0,e.useEffect)((function(){return void 0!==t.current&&i.addElement({element:t.current,props:n,makeItVisible:s}),function(){return i.removeElementFromList({element:t.current,props:n,makeItVisible:s})}}),[]),u}var i={elements:[]};function a(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function u(r){var n,o,i=(0,e.useRef)(),u=l(i,r),c=(n=(0,e.useState)(Object.assign({backgroundImage:"url(".concat(u.link,")")},r.style)),o=2,function(e){if(Array.isArray(e))return e}(n)||function(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,o,l=[],i=!0,a=!1;try{for(r=r.call(e);!(i=(n=r.next()).done)&&(l.push(n.value),!t||l.length!==t);i=!0);}catch(e){a=!0,o=e}finally{try{i||null==r.return||r.return()}finally{if(a)throw o}}return l}}(n,o)||function(e,t){if(e){if("string"==typeof e)return a(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?a(e,t):void 0}}(n,o)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()),s=c[0],f=c[1];return(0,e.useEffect)((function(){f(Object.assign({backgroundImage:"url(".concat(u.link,")")},r.style))}),[u]),t().createElement("div",{className:r.className,style:s,ref:i})}function c(r){var n=(0,e.useRef)(),o=l(n,r);return t().createElement("img",{src:o.link,alt:r.alt,style:r.style,className:r.className,ref:n})}function s(r){var n=(0,e.useRef)(),o=l(n,r);return t().createElement("iframe",{height:r.height||"500",scrolling:r.scrolling||"no",src:o.link,frameBorder:r.frameBorder||"no",allowtransparency:r.allowTransparency||"true",allowFullScreen:r.allowFullScreen||!0,style:r.style||{},ref:n})}function f(r){var n=(0,e.useRef)(),o=l(n,r),i=t().createElement("div",{style:r.style?r.style:{heigt:"300px",width:"300px"}});return t().createElement("div",{ref:n},o.visible?r.children:i)}i.isInViewPort=function(e){var t=e.offset,r=e.top,n=e.left;return window.scrollY+window.innerHeight+t>r&&window.scrollX+window.innerWidth+t>n},i.calculateNewPosition=function(e){var t=e.element.getBoundingClientRect(),r=t.top,n=t.left,o=t.right;return Object.assign({},e,{top:r,left:n,right:o})},i.addElement=function(e){var t=e.element,r=e.props,n=e.makeItVisible,o=t.getBoundingClientRect(),l=o.top,a=o.left,u=o.right;i.elements.push({element:t,top:l,left:a,right:u,offset:r.offset||100,makeItVisible:n}),"boolean"==typeof i.isListenerAttached&&(i.isListenerAttached=window.requestAnimationFrame(i.eventHandler))},i.eventHandler=function(){0===i.elements.length?i.removeScrollHandler():(i.elements.forEach((function(e,t){i.isInViewPort(e)?(e.makeItVisible(),i.removeElementFromList(e)):i.elements[t]=i.calculateNewPosition(e)})),i.isListenerAttached=window.requestAnimationFrame(i.eventHandler))},i.removeScrollHandler=function(){window.cancelAnimationFrame(i.isListenerAttached)},i.removeElementFromList=function(e){i.elements=i.elements.filter((function(t){return t!==e}))},i.isListenerAttached=!1})(),o})()}));
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["webpack://LazyReact/webpack/universalModuleDefinition","webpack://LazyReact/webpack/bootstrap","webpack://LazyReact/external {\"root\":\"React\",\"commonjs2\":\"react\",\"commonjs\":\"react\",\"amd\":\"react\"}","webpack://LazyReact/./src/baseClass.js","webpack://LazyReact/./node_modules/process/browser.js","webpack://LazyReact/./src/lazyLoadBackgroundImage.js","webpack://LazyReact/./src/lazyLoadImage.js","webpack://LazyReact/./src/lazyLoadFrame.js","webpack://LazyReact/./src/lazyLoadComponent.js","webpack://LazyReact/./src/index.js"],"names":["root","factory","exports","module","require","define","amd","window","__WEBPACK_EXTERNAL_MODULE__0__","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","isInViewPort","_ref","offset","top","left","scrollY","innerHeight","scrollX","innerWidth","CheckIfRender","props","_this","_classCallCheck","this","_possibleConstructorReturn","_getPrototypeOf","state","link","visible","makeItVisible","_assertThisInitialized","Component","setState","addElement","removeElementFromList","elements","eventHandler","length","removeScrollHandler","savedIndexs","push","element","filter","elem","index","includes","map","_reference$getBoundin","domNode","getBoundingClientRect","right","assign","calculateNewPosition","isListenerAttached","requestAnimationFrame","_element$domNode$getB","cancelAnimationFrame","toRemove","process","NODE_ENV","propTypes","PropTypes","string","isRequired","cachedSetTimeout","cachedClearTimeout","defaultSetTimout","Error","defaultClearTimeout","runTimeout","fun","setTimeout","e","clearTimeout","currentQueue","queue","draining","queueIndex","cleanUpNextTick","concat","drainQueue","timeout","len","run","marker","runClearTimeout","Item","array","noop","nextTick","args","Array","arguments","apply","title","browser","env","argv","version","versions","on","addListener","once","off","removeListener","removeAllListeners","emit","prependListener","prependOnceListener","listeners","binding","cwd","chdir","dir","umask","LazyBackgroundImage","external_root_React_commonjs2_react_commonjs_react_amd_react_default","a","createElement","className","style","ref","node","backgroundImage","nextProps","nextState","defaultProps","LazyImage","lazyLoadImage_classCallCheck","lazyLoadImage_possibleConstructorReturn","lazyLoadImage_getPrototypeOf","src","alt","preserveAspect","minHeight","minWidth","LazyFrame","lazyLoadFrame_classCallCheck","lazyLoadFrame_possibleConstructorReturn","lazyLoadFrame_getPrototypeOf","height","scrolling","frameBorder","allowTransparency","allowFullScreen","LazyComponent","lazyLoadComponent_classCallCheck","lazyLoadComponent_possibleConstructorReturn","lazyLoadComponent_getPrototypeOf","toRender","children","__webpack_exports__","lazyLoadBackgroundImage_LazyBackgroundImage","lazyLoadImage_LazyImage","lazyLoadFrame_LazyFrame","lazyLoadComponent_LazyComponent"],"mappings":"CAAA,SAAAA,EAAAC,GACA,iBAAAC,SAAA,iBAAAC,OACAA,OAAAD,QAAAD,EAAAG,QAAA,UACA,mBAAAC,eAAAC,IACAD,OAAA,UAAAJ,GACA,iBAAAC,QACAA,QAAA,UAAAD,EAAAG,QAAA,UAEAJ,EAAA,UAAAC,EAAAD,EAAA,OARA,CASCO,OAAA,SAAAC,GACD,mBCTA,IAAAC,EAAA,GAGA,SAAAC,EAAAC,GAGA,GAAAF,EAAAE,GACA,OAAAF,EAAAE,GAAAT,QAGA,IAAAC,EAAAM,EAAAE,GAAA,CACAC,EAAAD,EACAE,GAAA,EACAX,QAAA,IAUA,OANAY,EAAAH,GAAAI,KAAAZ,EAAAD,QAAAC,IAAAD,QAAAQ,GAGAP,EAAAU,GAAA,EAGAV,EAAAD,QA0DA,OArDAQ,EAAAM,EAAAF,EAGAJ,EAAAO,EAAAR,EAGAC,EAAAQ,EAAA,SAAAhB,EAAAiB,EAAAC,GACAV,EAAAW,EAAAnB,EAAAiB,IACAG,OAAAC,eAAArB,EAAAiB,EAAA,CAA0CK,YAAA,EAAAC,IAAAL,KAK1CV,EAAAgB,EAAA,SAAAxB,GACA,oBAAAyB,eAAAC,aACAN,OAAAC,eAAArB,EAAAyB,OAAAC,YAAA,CAAwDC,MAAA,WAExDP,OAAAC,eAAArB,EAAA,cAAiD2B,OAAA,KAQjDnB,EAAAoB,EAAA,SAAAD,EAAAE,GAEA,GADA,EAAAA,IAAAF,EAAAnB,EAAAmB,IACA,EAAAE,EAAA,OAAAF,EACA,KAAAE,GAAA,iBAAAF,QAAAG,WAAA,OAAAH,EACA,IAAAI,EAAAX,OAAAY,OAAA,MAGA,GAFAxB,EAAAgB,EAAA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M4H,gBAC5BxB,MAAOjG,KAAKiG,MACZC,IAAK,SAAAC,GAAI,OAAKrG,EAAK2B,QAAU0E,kDAKjCnG,KAAKiG,MAALpI,OAAA+D,OAAA,CACEoF,SAAU,QACPhH,KAAKH,MAAMoG,uzBAKpBgB,EAAUV,aAAe,CACvBc,OAAQ,MACRC,UAAW,KACXC,YAAa,KACbC,kBAAmB,OACnBC,gBAAiB,YC/BEC,cACnB,SAAAA,EAAY7H,GAAO,mGAAA8H,CAAA3H,KAAA0H,GAAAE,EAAA5H,KAAA6H,EAAAH,GAAApK,KAAA0C,KACXH,gPAFiCD,yFAIhC,IAAAE,EAAAE,KACH8H,EAAW9H,KAAKG,MAAME,QAAUL,KAAKH,MAAMkI,SAAWlC,EAAAC,EAAAC,cAAA,YAE1D,OACEF,EAAAC,EAAAC,cAAA,OACEE,MAAOjG,KAAKiG,MACZD,UAAWhG,KAAKH,MAAMmG,UACtBE,IAAK,SAAAC,GAAI,OAAKrG,EAAK2B,QAAU0E,IAE5B2B,gDAML9H,KAAKiG,MAAQpI,OAAO+D,OAAO,GAAI5B,KAAKH,MAAMoG,OACrCjG,KAAKG,MAAMC,MAASJ,KAAKH,MAAMmG,WAAchG,KAAKiG,MAAMoB,SAC3DrH,KAAKiG,MAAMoB,OAAS,kBAI1BK,EAAcnB,aAAe,CAC3BN,MAAO,GACPD,UAAW,IC9Bb/I,EAAAQ,EAAAuK,EAAA,wCAAAC,IAAAhL,EAAAQ,EAAAuK,EAAA,8BAAAE,IAAAjL,EAAAQ,EAAAuK,EAAA,8BAAAG,IAAAlL,EAAAQ,EAAAuK,EAAA,kCAAAI","file":"./dist/index.js","sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory(require(\"react\"));\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([\"react\"], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"LazyReact\"] = factory(require(\"react\"));\n\telse\n\t\troot[\"LazyReact\"] = factory(root[\"React\"]);\n})(window, function(__WEBPACK_EXTERNAL_MODULE__0__) {\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 = 3);\n","module.exports = __WEBPACK_EXTERNAL_MODULE__0__;","import React, { Component, PropTypes } from 'react' // eslint-disable-line no-unused-vars\n\nconst isInViewPort = ({ offset, top, left }) =>\n window.scrollY + window.innerHeight + offset > top &&\n window.scrollX + window.innerWidth + offset > left\n\nconst calculateNewPosition = elem => {\n const reference = elem.element.domNode\n const { top, left, right } = reference.getBoundingClientRect()\n return {\n ...elem,\n top,\n left,\n right\n }\n}\n\nclass CheckIfRender extends Component {\n constructor(props) {\n super(props)\n //initialize to an empty link to prevent loading the resource\n this.state = {\n link: '',\n visible: false\n }\n this.makeItVisible = this.makeItVisible.bind(this)\n }\n makeItVisible() {\n this.setState({\n link: this.props.link,\n visible: true\n })\n }\n componentDidMount() {\n CheckIfRender.addElement(this)\n }\n componentWillUnmount() {\n CheckIfRender.removeElementFromList(this)\n }\n}\n\nCheckIfRender.elements = []\n\nCheckIfRender.eventHandler = function() {\n //if there is no more element to lazy load just remove the listeners/rAF\n if (CheckIfRender.elements.length === 0) {\n CheckIfRender.removeScrollHandler()\n } else {\n //save every index of elements that has been loaded\n let savedIndexs = []\n for (let i = 0; i < CheckIfRender.elements.length; i++) {\n if (isInViewPort(CheckIfRender.elements[i])) {\n savedIndexs.push(i)\n //make the element visible\n CheckIfRender.elements[i].element.makeItVisible()\n }\n }\n //remove elements that has already been loaded from the list of the elements\n if (savedIndexs.length > 0)\n CheckIfRender.elements = CheckIfRender.elements.filter(\n (elem, index) => !savedIndexs.includes(index)\n )\n //update the coordinates of the elements\n CheckIfRender.elements = CheckIfRender.elements.map(elem =>\n calculateNewPosition(elem)\n )\n CheckIfRender.isListenerAttached = window.requestAnimationFrame(\n CheckIfRender.eventHandler\n )\n }\n}\n\nCheckIfRender.addElement = function(element) {\n //the distance from the pixel 0,0 and the top of the element\n const { top, left, right } = element.domNode.getBoundingClientRect()\n CheckIfRender.elements.push({\n element,\n top,\n left,\n right,\n offset: element.props.offset || 100\n })\n //check if has already been started the rAF cycle\n if (typeof CheckIfRender.isListenerAttached !== 'function') {\n CheckIfRender.isListenerAttached = window.requestAnimationFrame(\n CheckIfRender.eventHandler\n )\n }\n}\n\nCheckIfRender.removeScrollHandler = function() {\n window.cancelAnimationFrame(CheckIfRender.isListenerAttached)\n}\n\n//When an element is unloaded remove it from the list of elements that are waiting to be lazy-loaded\nCheckIfRender.removeElementFromList = function(toRemove) {\n CheckIfRender.elements = CheckIfRender.elements.filter(\n elem => elem.element !== toRemove\n )\n}\n\nCheckIfRender.isListenerAttached = false\n\nif (!process.NODE_ENV === 'production') {\n CheckIfRender.propTypes = {\n link: PropTypes.string.isRequired\n }\n}\n\nexport default CheckIfRender\n","// shim for using process in browser\nvar process = module.exports = {};\n\n// cached from whatever global is present so that test runners that stub it\n// don't break things. But we need to wrap it in a try catch in case it is\n// wrapped in strict mode code which doesn't define any globals. It's inside a\n// function because try/catches deoptimize in certain engines.\n\nvar cachedSetTimeout;\nvar cachedClearTimeout;\n\nfunction defaultSetTimout() {\n throw new Error('setTimeout has not been defined');\n}\nfunction defaultClearTimeout () {\n throw new Error('clearTimeout has not been defined');\n}\n(function () {\n try {\n if (typeof setTimeout === 'function') {\n cachedSetTimeout = setTimeout;\n } else {\n cachedSetTimeout = defaultSetTimout;\n }\n } catch (e) {\n cachedSetTimeout = defaultSetTimout;\n }\n try {\n if (typeof clearTimeout === 'function') {\n cachedClearTimeout = clearTimeout;\n } else {\n cachedClearTimeout = defaultClearTimeout;\n }\n } catch (e) {\n cachedClearTimeout = defaultClearTimeout;\n }\n} ())\nfunction runTimeout(fun) {\n if (cachedSetTimeout === setTimeout) {\n //normal enviroments in sane situations\n return setTimeout(fun, 0);\n }\n // if setTimeout wasn't available but was latter defined\n if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {\n cachedSetTimeout = setTimeout;\n return setTimeout(fun, 0);\n }\n try {\n // when when somebody has screwed with setTimeout but no I.E. maddness\n return cachedSetTimeout(fun, 0);\n } catch(e){\n try {\n // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally\n return cachedSetTimeout.call(null, fun, 0);\n } catch(e){\n // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error\n return cachedSetTimeout.call(this, fun, 0);\n }\n }\n\n\n}\nfunction runClearTimeout(marker) {\n if (cachedClearTimeout === clearTimeout) {\n //normal enviroments in sane situations\n return clearTimeout(marker);\n }\n // if clearTimeout wasn't available but was latter defined\n if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {\n cachedClearTimeout = clearTimeout;\n return clearTimeout(marker);\n }\n try {\n // when when somebody has screwed with setTimeout but no I.E. maddness\n return cachedClearTimeout(marker);\n } catch (e){\n try {\n // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally\n return cachedClearTimeout.call(null, marker);\n } catch (e){\n // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error.\n // Some versions of I.E. have different rules for clearTimeout vs setTimeout\n return cachedClearTimeout.call(this, marker);\n }\n }\n\n\n\n}\nvar queue = [];\nvar draining = false;\nvar currentQueue;\nvar queueIndex = -1;\n\nfunction cleanUpNextTick() {\n if (!draining || !currentQueue) {\n return;\n }\n draining = false;\n if (currentQueue.length) {\n queue = currentQueue.concat(queue);\n } else {\n queueIndex = -1;\n }\n if (queue.length) {\n drainQueue();\n }\n}\n\nfunction drainQueue() {\n if (draining) {\n return;\n }\n var timeout = runTimeout(cleanUpNextTick);\n draining = true;\n\n var len = queue.length;\n while(len) {\n currentQueue = queue;\n queue = [];\n while (++queueIndex < len) {\n if (currentQueue) {\n currentQueue[queueIndex].run();\n }\n }\n queueIndex = -1;\n len = queue.length;\n }\n currentQueue = null;\n draining = false;\n runClearTimeout(timeout);\n}\n\nprocess.nextTick = function (fun) {\n var args = new Array(arguments.length - 1);\n if (arguments.length > 1) {\n for (var i = 1; i < arguments.length; i++) {\n args[i - 1] = arguments[i];\n }\n }\n queue.push(new Item(fun, args));\n if (queue.length === 1 && !draining) {\n runTimeout(drainQueue);\n }\n};\n\n// v8 likes predictible objects\nfunction Item(fun, array) {\n this.fun = fun;\n this.array = array;\n}\nItem.prototype.run = function () {\n this.fun.apply(null, this.array);\n};\nprocess.title = 'browser';\nprocess.browser = true;\nprocess.env = {};\nprocess.argv = [];\nprocess.version = ''; // empty string to avoid regexp issues\nprocess.versions = {};\n\nfunction noop() {}\n\nprocess.on = noop;\nprocess.addListener = noop;\nprocess.once = noop;\nprocess.off = noop;\nprocess.removeListener = noop;\nprocess.removeAllListeners = noop;\nprocess.emit = noop;\nprocess.prependListener = noop;\nprocess.prependOnceListener = noop;\n\nprocess.listeners = function (name) { return [] }\n\nprocess.binding = function (name) {\n throw new Error('process.binding is not supported');\n};\n\nprocess.cwd = function () { return '/' };\nprocess.chdir = function (dir) {\n throw new Error('process.chdir is not supported');\n};\nprocess.umask = function() { return 0; };\n","import React from 'react' // eslint-disable-line no-unused-vars\nimport CheckIfRender from './baseClass'\n\nexport default class LazyBackgroundImage extends CheckIfRender {\n constructor(props) {\n super(props)\n }\n render() {\n return (\n <div\n className={this.props.className}\n style={this.style}\n ref={node => (this.domNode = node)}\n />\n )\n }\n componentWillMount() {\n this.style = {\n backgroundImage: `url(${this.state.link})`,\n ...this.props.style\n }\n }\n\n componentWillUpdate(nextProps, nextState) {\n this.style = {\n ...this.style,\n backgroundImage: `url(${nextState.link})`\n }\n }\n}\n\nLazyBackgroundImage.defaultProps = {\n className: '',\n style: {}\n}\n","import React from 'react' // eslint-disable-line no-unused-vars\nimport CheckIfRender from './baseClass'\n\nexport default class LazyImage extends CheckIfRender {\n constructor(props) {\n super(props)\n }\n render() {\n return (\n <img\n src={this.state.link}\n alt={this.props.alt}\n style={this.style}\n className={this.props.className}\n ref={node => (this.domNode = node)}\n />\n )\n }\n componentWillMount() {\n if (this.props.className === '' && this.props.preserveAspect === false) {\n this.style = {\n minHeight: '300px',\n minWidth: '300px',\n ...this.props.style\n }\n }\n }\n}\n\nLazyImage.defaultProps = {\n style: {},\n className: '',\n preserveAspect: true\n}\n","import React from 'react' // eslint-disable-line no-unused-vars\nimport CheckIfRender from './baseClass'\n\nexport default class LazyFrame extends CheckIfRender {\n constructor(props) {\n super(props)\n }\n render() {\n return (\n <iframe\n height={this.props.height}\n scrolling={this.props.scrolling}\n src={this.state.link}\n frameBorder={this.props.frameBorder}\n allowTransparency={this.props.allowTransparency}\n allowFullScreen={this.props.allowFullScreen}\n style={this.style}\n ref={node => (this.domNode = node)}\n />\n )\n }\n componentWillMount() {\n this.style = {\n minWidth: '100%',\n ...this.props.style\n }\n }\n}\n\nLazyFrame.defaultProps = {\n height: '500',\n scrolling: 'no',\n frameBorder: 'no',\n allowTransparency: 'true',\n allowFullScreen: 'true'\n}\n","import React from 'react' // eslint-disable-line no-unused-vars\nimport CheckIfRender from './baseClass'\n\nexport default class LazyComponent extends CheckIfRender {\n constructor(props) {\n super(props)\n }\n render() {\n let toRender = this.state.visible ? this.props.children : <div />\n\n return (\n <div\n style={this.style}\n className={this.props.className}\n ref={node => (this.domNode = node)}\n >\n {toRender}\n </div>\n )\n }\n\n componentWillMount() {\n this.style = Object.assign({}, this.props.style)\n if (!this.state.link && !this.props.className && !this.style.height)\n this.style.height = '300px'\n }\n}\n\nLazyComponent.defaultProps = {\n style: {},\n className: ''\n}\n","import LazyBackgroundImage from './lazyLoadBackgroundImage'\nimport LazyImage from './lazyLoadImage'\nimport LazyFrame from './lazyLoadFrame'\nimport LazyComponent from './lazyLoadComponent'\n\nexport { LazyBackgroundImage, LazyImage, LazyFrame, LazyComponent }\n"],"sourceRoot":""}
|
|
1
|
+
{"version":3,"file":"./dist/index.js","mappings":"CAAA,SAA2CA,EAAMC,GAC1B,iBAAZC,SAA0C,iBAAXC,OACxCA,OAAOD,QAAUD,EAAQG,QAAQ,UACR,mBAAXC,QAAyBA,OAAOC,IAC9CD,OAAO,CAAC,SAAUJ,GACQ,iBAAZC,QACdA,QAAmB,UAAID,EAAQG,QAAQ,UAEvCJ,EAAgB,UAAIC,EAAQD,EAAY,OAR1C,CASGO,MAAM,SAASC,GAClB,M,kCCVAL,EAAOD,QAAUM,ICCbC,EAA2B,GAG/B,SAASC,EAAoBC,GAE5B,IAAIC,EAAeH,EAAyBE,GAC5C,QAAqBE,IAAjBD,EACH,OAAOA,EAAaV,QAGrB,IAAIC,EAASM,EAAyBE,GAAY,CAGjDT,QAAS,IAOV,OAHAY,EAAoBH,GAAUR,EAAQA,EAAOD,QAASQ,GAG/CP,EAAOD,QCpBfQ,EAAoBK,EAAKZ,IACxB,IAAIa,EAASb,GAAUA,EAAOc,WAC7B,IAAOd,EAAiB,QACxB,IAAM,EAEP,OADAO,EAAoBQ,EAAEF,EAAQ,CAAEG,EAAGH,IAC5BA,GCLRN,EAAoBQ,EAAI,CAAChB,EAASkB,KACjC,IAAI,IAAIC,KAAOD,EACXV,EAAoBY,EAAEF,EAAYC,KAASX,EAAoBY,EAAEpB,EAASmB,IAC5EE,OAAOC,eAAetB,EAASmB,EAAK,CAAEI,YAAY,EAAMC,IAAKN,EAAWC,MCJ3EX,EAAoBY,EAAI,CAACK,EAAKC,IAAUL,OAAOM,UAAUC,eAAeC,KAAKJ,EAAKC,GCClFlB,EAAoBsB,EAAK9B,IACH,oBAAX+B,QAA0BA,OAAOC,a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,IAG8C,kBAArCG,EAAc0C,qBACvB1C,EAAc0C,mBAAqBV,OAAOW,sBACxC3C,EAAc4C,gBAKpB5C,EAAc4C,aAAe,WAEW,IAAlC5C,EAAcG,SAAS0C,OACzB7C,EAAc8C,uBAEd9C,EAAcG,SAAS4C,SAAQ,SAACT,EAAMU,GAEhChD,EAAc4B,aAAaU,IAC7BA,EAAKzC,gBAELG,EAAcE,sBAAsBoC,IAGpCtC,EAAcG,SAAS6C,GAAKhD,EAAcqC,qBAAqBC,MAGnEtC,EAAc0C,mBAAqBV,OAAOW,sBACxC3C,EAAc4C,gBAKpB5C,EAAc8C,oBAAsB,WAClCd,OAAOiB,qBAAqBjD,EAAc0C,qBAI5C1C,EAAcE,sBAAwB,SAAUgD,GAC9ClD,EAAcG,SAAWH,EAAcG,SAASgD,QAC9C,SAACb,GAAD,OAAUA,IAASY,MAIvBlD,EAAc0C,oBAAqB,G","sources":["webpack://LazyReact/webpack/universalModuleDefinition","webpack://LazyReact/external umd {\"root\":\"React\",\"commonjs2\":\"react\",\"commonjs\":\"react\",\"amd\":\"react\"}","webpack://LazyReact/webpack/bootstrap","webpack://LazyReact/webpack/runtime/compat get default export","webpack://LazyReact/webpack/runtime/define property getters","webpack://LazyReact/webpack/runtime/hasOwnProperty shorthand","webpack://LazyReact/webpack/runtime/make namespace object","webpack://LazyReact/./src/baseClass.js","webpack://LazyReact/./src/lazyLoadBackgroundImage.js","webpack://LazyReact/./src/lazyLoadImage.js","webpack://LazyReact/./src/lazyLoadFrame.js","webpack://LazyReact/./src/lazyLoadComponent.js"],"sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory(require(\"react\"));\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([\"react\"], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"LazyReact\"] = factory(require(\"react\"));\n\telse\n\t\troot[\"LazyReact\"] = factory(root[\"React\"]);\n})(self, function(__WEBPACK_EXTERNAL_MODULE__787__) {\nreturn ","module.exports = __WEBPACK_EXTERNAL_MODULE__787__;","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","// getDefaultExport function for compatibility with non-harmony modules\n__webpack_require__.n = (module) => {\n\tvar getter = module && module.__esModule ?\n\t\t() => (module['default']) :\n\t\t() => (module);\n\t__webpack_require__.d(getter, { a: getter });\n\treturn getter;\n};","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","import React, { useState, useEffect } from 'react' // eslint-disable-line no-unused-vars\n\nexport default function useRenderIfInViewPort(element, props) {\n const [state, setState] = useState({\n link: '',\n visible: false,\n })\n\n function makeItVisible() {\n setState({\n visible: true,\n link: props.link,\n })\n }\n\n useEffect(() => {\n if (element.current !== undefined)\n CheckIfRender.addElement({\n element: element.current,\n props,\n makeItVisible,\n })\n return () =>\n CheckIfRender.removeElementFromList({\n element: element.current,\n props,\n makeItVisible,\n })\n }, [])\n\n return state\n}\n\nconst CheckIfRender = {\n elements: [],\n}\n\nCheckIfRender.isInViewPort = ({ offset, top, left }) =>\n window.scrollY + window.innerHeight + offset > top &&\n window.scrollX + window.innerWidth + offset > left\n\nCheckIfRender.calculateNewPosition = (elem) => {\n const reference = elem.element\n const { top, left, right } = reference.getBoundingClientRect()\n return {\n ...elem,\n top,\n left,\n right,\n }\n}\n\nCheckIfRender.addElement = function ({ element, props, makeItVisible }) {\n //the distance from the pixel 0,0 and the top of the element\n const { top, left, right } = element.getBoundingClientRect()\n CheckIfRender.elements.push({\n element,\n top,\n left,\n right,\n offset: props.offset || 100,\n makeItVisible,\n })\n //check if has already been started the rAF cycle\n if (typeof CheckIfRender.isListenerAttached === 'boolean') {\n CheckIfRender.isListenerAttached = window.requestAnimationFrame(\n CheckIfRender.eventHandler\n )\n }\n}\n\nCheckIfRender.eventHandler = function () {\n //if there is no more element to lazy load remove the listener/rAF\n if (CheckIfRender.elements.length === 0) {\n CheckIfRender.removeScrollHandler()\n } else {\n CheckIfRender.elements.forEach((elem, i) => {\n // if element is in viewPort make it visible\n if (CheckIfRender.isInViewPort(elem)) {\n elem.makeItVisible()\n // remove element from the list of elements to lazy load\n CheckIfRender.removeElementFromList(elem)\n } else {\n // if the element is not shown update his position\n CheckIfRender.elements[i] = CheckIfRender.calculateNewPosition(elem)\n }\n })\n CheckIfRender.isListenerAttached = window.requestAnimationFrame(\n CheckIfRender.eventHandler\n )\n }\n}\n\nCheckIfRender.removeScrollHandler = function () {\n window.cancelAnimationFrame(CheckIfRender.isListenerAttached)\n}\n\n//When an element is unloaded remove it from the list of elements that are waiting to be lazy-loaded\nCheckIfRender.removeElementFromList = function (toRemove) {\n CheckIfRender.elements = CheckIfRender.elements.filter(\n (elem) => elem !== toRemove\n )\n}\n\nCheckIfRender.isListenerAttached = false\n\nexport { CheckIfRender }\n","import React, { useState, useEffect, useRef } from 'react' // eslint-disable-line no-unused-vars\nimport useIsInViewPort from './baseClass'\n\nexport default function LazyBackgroundImage(props) {\n const ref = useRef()\n let isViewable = useIsInViewPort(ref, props)\n const [style, setStyle] = useState({\n backgroundImage: `url(${isViewable.link})`,\n ...props.style,\n })\n\n useEffect(() => {\n setStyle({\n backgroundImage: `url(${isViewable.link})`,\n ...props.style,\n })\n }, [isViewable])\n\n return <div className={props.className} style={style} ref={ref} />\n}\n","import React, { useRef } from 'react' // eslint-disable-line no-unused-vars\nimport useIsInViewPort from './baseClass'\n\nexport default function LazyImage(props) {\n const ref = useRef()\n const isViewable = useIsInViewPort(ref, props)\n\n return (\n <img\n src={isViewable.link}\n alt={props.alt}\n style={props.style}\n className={props.className}\n ref={ref}\n />\n )\n}\n","import React, { useRef } from 'react' // eslint-disable-line no-unused-vars\nimport useIsInViewPort from './baseClass'\n\nexport default function LazyFrame(props) {\n const ref = useRef()\n let isViewable = useIsInViewPort(ref, props)\n\n return (\n <iframe\n height={props.height || '500'}\n scrolling={props.scrolling || 'no'}\n src={isViewable.link}\n frameBorder={props.frameBorder || 'no'}\n allowtransparency={props.allowTransparency || 'true'}\n allowFullScreen={props.allowFullScreen || true}\n style={props.style || {}}\n ref={ref}\n />\n )\n}\n","import React, { useRef } from 'react' // eslint-disable-line no-unused-vars\nimport useIsInViewPort from './baseClass'\n\nexport default function LazyComponent(props) {\n const ref = useRef()\n let isViewable = useIsInViewPort(ref, props)\n\n const placeHolder = (\n <div\n style={\n props.style\n ? props.style\n : {\n heigt: '300px',\n width: '300px',\n }\n }\n />\n )\n\n return (\n <div ref={ref}>{isViewable.visible ? props.children : placeHolder}</div>\n )\n}\n"],"names":["root","factory","exports","module","require","define","amd","self","__WEBPACK_EXTERNAL_MODULE__787__","__webpack_module_cache__","__webpack_require__","moduleId","cachedModule","undefined","__webpack_modules__","n","getter","__esModule","d","a","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","r","Symbol","toStringTag","value","useRenderIfInViewPort","element","props","useState","link","visible","state","setState","makeItVisible","useEffect","current","CheckIfRender","addElement","removeElementFromList","elements","LazyBackgroundImage","ref","useRef","isViewable","useIsInViewPort","backgroundImage","style","setStyle","className","LazyImage","src","alt","LazyFrame","height","scrolling","frameBorder","allowtransparency","allowTransparency","allowFullScreen","LazyComponent","placeHolder","heigt","width","children","isInViewPort","offset","top","left","window","scrollY","innerHeight","scrollX","innerWidth","calculateNewPosition","elem","getBoundingClientRect","right","push","isListenerAttached","requestAnimationFrame","eventHandler","length","removeScrollHandler","forEach","i","cancelAnimationFrame","toRemove","filter"],"sourceRoot":""}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lazy-react",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.2",
|
|
4
4
|
"description": "components to lazy load iframes, images and images as backgrounds",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
"lint": "eslint src/*",
|
|
11
11
|
"lint:fix": "eslint --fix src/*",
|
|
12
12
|
"prettify": "prettier --write --single-quote --no-semi ./src/*.js",
|
|
13
|
-
"precommit": "lint-staged"
|
|
13
|
+
"precommit": "lint-staged",
|
|
14
|
+
"test": "jest"
|
|
14
15
|
},
|
|
15
16
|
"lint-staged": {
|
|
16
17
|
"src/*.js": [
|
|
@@ -29,27 +30,29 @@
|
|
|
29
30
|
"url": "https://github.com/jonathanobino/react-lazy"
|
|
30
31
|
},
|
|
31
32
|
"devDependencies": {
|
|
32
|
-
"@babel/core": "^7.
|
|
33
|
-
"@babel/plugin-proposal-object-rest-spread": "^7.
|
|
34
|
-
"@babel/preset-env": "^7.
|
|
35
|
-
"@babel/preset-react": "^7.
|
|
33
|
+
"@babel/core": "^7.11.6",
|
|
34
|
+
"@babel/plugin-proposal-object-rest-spread": "^7.11.0",
|
|
35
|
+
"@babel/preset-env": "^7.11.5",
|
|
36
|
+
"@babel/preset-react": "^7.10.4",
|
|
37
|
+
"@types/jest": "^27.4.0",
|
|
36
38
|
"babel-cli": "^6.26.0",
|
|
37
|
-
"babel-loader": "^8.0
|
|
39
|
+
"babel-loader": "^8.1.0",
|
|
38
40
|
"babel-plugin-transform-object-rest-spread": "^6.26.0",
|
|
39
|
-
"eslint": "^
|
|
40
|
-
"eslint-plugin-react": "^7.
|
|
41
|
-
"husky": "^
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"webpack
|
|
41
|
+
"eslint": "^7.10.0",
|
|
42
|
+
"eslint-plugin-react": "^7.21.3",
|
|
43
|
+
"husky": "^4.3.0",
|
|
44
|
+
"jest": "^27.5.1",
|
|
45
|
+
"lint-staged": "^10.4.0",
|
|
46
|
+
"prettier": "^2.1.2",
|
|
47
|
+
"webpack": "^5.66.0",
|
|
48
|
+
"webpack-cli": "^4.9.1"
|
|
46
49
|
},
|
|
47
50
|
"dependencies": {
|
|
48
|
-
"react": "^
|
|
49
|
-
"react-dom": "^
|
|
51
|
+
"react": "^17.0.2",
|
|
52
|
+
"react-dom": "^17.0.2"
|
|
50
53
|
},
|
|
51
54
|
"peerDependencies": {
|
|
52
|
-
"react": "^
|
|
53
|
-
"react-dom": "^
|
|
55
|
+
"react": "^17.0.2",
|
|
56
|
+
"react-dom": "^17.0.2"
|
|
54
57
|
}
|
|
55
58
|
}
|
package/src/baseClass.js
CHANGED
|
@@ -1,110 +1,107 @@
|
|
|
1
|
-
import React, {
|
|
1
|
+
import React, { useState, useEffect } from 'react' // eslint-disable-line no-unused-vars
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
export default function useRenderIfInViewPort(element, props) {
|
|
4
|
+
const [state, setState] = useState({
|
|
5
|
+
link: '',
|
|
6
|
+
visible: false,
|
|
7
|
+
})
|
|
8
|
+
|
|
9
|
+
function makeItVisible() {
|
|
10
|
+
setState({
|
|
11
|
+
visible: true,
|
|
12
|
+
link: props.link,
|
|
13
|
+
})
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
if (element.current !== undefined)
|
|
18
|
+
CheckIfRender.addElement({
|
|
19
|
+
element: element.current,
|
|
20
|
+
props,
|
|
21
|
+
makeItVisible,
|
|
22
|
+
})
|
|
23
|
+
return () =>
|
|
24
|
+
CheckIfRender.removeElementFromList({
|
|
25
|
+
element: element.current,
|
|
26
|
+
props,
|
|
27
|
+
makeItVisible,
|
|
28
|
+
})
|
|
29
|
+
}, [])
|
|
30
|
+
|
|
31
|
+
return state
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const CheckIfRender = {
|
|
35
|
+
elements: [],
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
CheckIfRender.isInViewPort = ({ offset, top, left }) =>
|
|
4
39
|
window.scrollY + window.innerHeight + offset > top &&
|
|
5
40
|
window.scrollX + window.innerWidth + offset > left
|
|
6
41
|
|
|
7
|
-
|
|
8
|
-
const reference = elem.element
|
|
42
|
+
CheckIfRender.calculateNewPosition = (elem) => {
|
|
43
|
+
const reference = elem.element
|
|
9
44
|
const { top, left, right } = reference.getBoundingClientRect()
|
|
10
45
|
return {
|
|
11
46
|
...elem,
|
|
12
47
|
top,
|
|
13
48
|
left,
|
|
14
|
-
right
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
class CheckIfRender extends Component {
|
|
19
|
-
constructor(props) {
|
|
20
|
-
super(props)
|
|
21
|
-
//initialize to an empty link to prevent loading the resource
|
|
22
|
-
this.state = {
|
|
23
|
-
link: '',
|
|
24
|
-
visible: false
|
|
25
|
-
}
|
|
26
|
-
this.makeItVisible = this.makeItVisible.bind(this)
|
|
27
|
-
}
|
|
28
|
-
makeItVisible() {
|
|
29
|
-
this.setState({
|
|
30
|
-
link: this.props.link,
|
|
31
|
-
visible: true
|
|
32
|
-
})
|
|
33
|
-
}
|
|
34
|
-
componentDidMount() {
|
|
35
|
-
CheckIfRender.addElement(this)
|
|
36
|
-
}
|
|
37
|
-
componentWillUnmount() {
|
|
38
|
-
CheckIfRender.removeElementFromList(this)
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
CheckIfRender.elements = []
|
|
43
|
-
|
|
44
|
-
CheckIfRender.eventHandler = function() {
|
|
45
|
-
//if there is no more element to lazy load just remove the listeners/rAF
|
|
46
|
-
if (CheckIfRender.elements.length === 0) {
|
|
47
|
-
CheckIfRender.removeScrollHandler()
|
|
48
|
-
} else {
|
|
49
|
-
//save every index of elements that has been loaded
|
|
50
|
-
let savedIndexs = []
|
|
51
|
-
for (let i = 0; i < CheckIfRender.elements.length; i++) {
|
|
52
|
-
if (isInViewPort(CheckIfRender.elements[i])) {
|
|
53
|
-
savedIndexs.push(i)
|
|
54
|
-
//make the element visible
|
|
55
|
-
CheckIfRender.elements[i].element.makeItVisible()
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
//remove elements that has already been loaded from the list of the elements
|
|
59
|
-
if (savedIndexs.length > 0)
|
|
60
|
-
CheckIfRender.elements = CheckIfRender.elements.filter(
|
|
61
|
-
(elem, index) => !savedIndexs.includes(index)
|
|
62
|
-
)
|
|
63
|
-
//update the coordinates of the elements
|
|
64
|
-
CheckIfRender.elements = CheckIfRender.elements.map(elem =>
|
|
65
|
-
calculateNewPosition(elem)
|
|
66
|
-
)
|
|
67
|
-
CheckIfRender.isListenerAttached = window.requestAnimationFrame(
|
|
68
|
-
CheckIfRender.eventHandler
|
|
69
|
-
)
|
|
49
|
+
right,
|
|
70
50
|
}
|
|
71
51
|
}
|
|
72
52
|
|
|
73
|
-
CheckIfRender.addElement = function(element) {
|
|
53
|
+
CheckIfRender.addElement = function ({ element, props, makeItVisible }) {
|
|
74
54
|
//the distance from the pixel 0,0 and the top of the element
|
|
75
|
-
const { top, left, right } = element.
|
|
55
|
+
const { top, left, right } = element.getBoundingClientRect()
|
|
76
56
|
CheckIfRender.elements.push({
|
|
77
57
|
element,
|
|
78
58
|
top,
|
|
79
59
|
left,
|
|
80
60
|
right,
|
|
81
|
-
offset:
|
|
61
|
+
offset: props.offset || 100,
|
|
62
|
+
makeItVisible,
|
|
82
63
|
})
|
|
83
64
|
//check if has already been started the rAF cycle
|
|
84
|
-
if (typeof CheckIfRender.isListenerAttached
|
|
65
|
+
if (typeof CheckIfRender.isListenerAttached === 'boolean') {
|
|
66
|
+
CheckIfRender.isListenerAttached = window.requestAnimationFrame(
|
|
67
|
+
CheckIfRender.eventHandler
|
|
68
|
+
)
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
CheckIfRender.eventHandler = function () {
|
|
73
|
+
//if there is no more element to lazy load remove the listener/rAF
|
|
74
|
+
if (CheckIfRender.elements.length === 0) {
|
|
75
|
+
CheckIfRender.removeScrollHandler()
|
|
76
|
+
} else {
|
|
77
|
+
CheckIfRender.elements.forEach((elem, i) => {
|
|
78
|
+
// if element is in viewPort make it visible
|
|
79
|
+
if (CheckIfRender.isInViewPort(elem)) {
|
|
80
|
+
elem.makeItVisible()
|
|
81
|
+
// remove element from the list of elements to lazy load
|
|
82
|
+
CheckIfRender.removeElementFromList(elem)
|
|
83
|
+
} else {
|
|
84
|
+
// if the element is not shown update his position
|
|
85
|
+
CheckIfRender.elements[i] = CheckIfRender.calculateNewPosition(elem)
|
|
86
|
+
}
|
|
87
|
+
})
|
|
85
88
|
CheckIfRender.isListenerAttached = window.requestAnimationFrame(
|
|
86
89
|
CheckIfRender.eventHandler
|
|
87
90
|
)
|
|
88
91
|
}
|
|
89
92
|
}
|
|
90
93
|
|
|
91
|
-
CheckIfRender.removeScrollHandler = function() {
|
|
94
|
+
CheckIfRender.removeScrollHandler = function () {
|
|
92
95
|
window.cancelAnimationFrame(CheckIfRender.isListenerAttached)
|
|
93
96
|
}
|
|
94
97
|
|
|
95
98
|
//When an element is unloaded remove it from the list of elements that are waiting to be lazy-loaded
|
|
96
|
-
CheckIfRender.removeElementFromList = function(toRemove) {
|
|
99
|
+
CheckIfRender.removeElementFromList = function (toRemove) {
|
|
97
100
|
CheckIfRender.elements = CheckIfRender.elements.filter(
|
|
98
|
-
elem => elem
|
|
101
|
+
(elem) => elem !== toRemove
|
|
99
102
|
)
|
|
100
103
|
}
|
|
101
104
|
|
|
102
105
|
CheckIfRender.isListenerAttached = false
|
|
103
106
|
|
|
104
|
-
|
|
105
|
-
CheckIfRender.propTypes = {
|
|
106
|
-
link: PropTypes.string.isRequired
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
export default CheckIfRender
|
|
107
|
+
export { CheckIfRender }
|
|
@@ -1,35 +1,20 @@
|
|
|
1
|
-
import React from 'react' // eslint-disable-line no-unused-vars
|
|
2
|
-
import
|
|
1
|
+
import React, { useState, useEffect, useRef } from 'react' // eslint-disable-line no-unused-vars
|
|
2
|
+
import useIsInViewPort from './baseClass'
|
|
3
3
|
|
|
4
|
-
export default
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
className={this.props.className}
|
|
12
|
-
style={this.style}
|
|
13
|
-
ref={node => (this.domNode = node)}
|
|
14
|
-
/>
|
|
15
|
-
)
|
|
16
|
-
}
|
|
17
|
-
componentWillMount() {
|
|
18
|
-
this.style = {
|
|
19
|
-
backgroundImage: `url(${this.state.link})`,
|
|
20
|
-
...this.props.style
|
|
21
|
-
}
|
|
22
|
-
}
|
|
4
|
+
export default function LazyBackgroundImage(props) {
|
|
5
|
+
const ref = useRef()
|
|
6
|
+
let isViewable = useIsInViewPort(ref, props)
|
|
7
|
+
const [style, setStyle] = useState({
|
|
8
|
+
backgroundImage: `url(${isViewable.link})`,
|
|
9
|
+
...props.style,
|
|
10
|
+
})
|
|
23
11
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
setStyle({
|
|
14
|
+
backgroundImage: `url(${isViewable.link})`,
|
|
15
|
+
...props.style,
|
|
16
|
+
})
|
|
17
|
+
}, [isViewable])
|
|
31
18
|
|
|
32
|
-
|
|
33
|
-
className: '',
|
|
34
|
-
style: {}
|
|
19
|
+
return <div className={props.className} style={style} ref={ref} />
|
|
35
20
|
}
|
package/src/lazyLoadComponent.js
CHANGED
|
@@ -1,32 +1,24 @@
|
|
|
1
|
-
import React from 'react' // eslint-disable-line no-unused-vars
|
|
2
|
-
import
|
|
1
|
+
import React, { useRef } from 'react' // eslint-disable-line no-unused-vars
|
|
2
|
+
import useIsInViewPort from './baseClass'
|
|
3
3
|
|
|
4
|
-
export default
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
render() {
|
|
9
|
-
let toRender = this.state.visible ? this.props.children : <div />
|
|
4
|
+
export default function LazyComponent(props) {
|
|
5
|
+
const ref = useRef()
|
|
6
|
+
let isViewable = useIsInViewPort(ref, props)
|
|
10
7
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
8
|
+
const placeHolder = (
|
|
9
|
+
<div
|
|
10
|
+
style={
|
|
11
|
+
props.style
|
|
12
|
+
? props.style
|
|
13
|
+
: {
|
|
14
|
+
heigt: '300px',
|
|
15
|
+
width: '300px',
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
/>
|
|
19
|
+
)
|
|
21
20
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
this.style.height = '300px'
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
LazyComponent.defaultProps = {
|
|
30
|
-
style: {},
|
|
31
|
-
className: ''
|
|
21
|
+
return (
|
|
22
|
+
<div ref={ref}>{isViewable.visible ? props.children : placeHolder}</div>
|
|
23
|
+
)
|
|
32
24
|
}
|
package/src/lazyLoadFrame.js
CHANGED
|
@@ -1,36 +1,20 @@
|
|
|
1
|
-
import React from 'react' // eslint-disable-line no-unused-vars
|
|
2
|
-
import
|
|
1
|
+
import React, { useRef } from 'react' // eslint-disable-line no-unused-vars
|
|
2
|
+
import useIsInViewPort from './baseClass'
|
|
3
3
|
|
|
4
|
-
export default
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
render() {
|
|
9
|
-
return (
|
|
10
|
-
<iframe
|
|
11
|
-
height={this.props.height}
|
|
12
|
-
scrolling={this.props.scrolling}
|
|
13
|
-
src={this.state.link}
|
|
14
|
-
frameBorder={this.props.frameBorder}
|
|
15
|
-
allowTransparency={this.props.allowTransparency}
|
|
16
|
-
allowFullScreen={this.props.allowFullScreen}
|
|
17
|
-
style={this.style}
|
|
18
|
-
ref={node => (this.domNode = node)}
|
|
19
|
-
/>
|
|
20
|
-
)
|
|
21
|
-
}
|
|
22
|
-
componentWillMount() {
|
|
23
|
-
this.style = {
|
|
24
|
-
minWidth: '100%',
|
|
25
|
-
...this.props.style
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
}
|
|
4
|
+
export default function LazyFrame(props) {
|
|
5
|
+
const ref = useRef()
|
|
6
|
+
let isViewable = useIsInViewPort(ref, props)
|
|
29
7
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
8
|
+
return (
|
|
9
|
+
<iframe
|
|
10
|
+
height={props.height || '500'}
|
|
11
|
+
scrolling={props.scrolling || 'no'}
|
|
12
|
+
src={isViewable.link}
|
|
13
|
+
frameBorder={props.frameBorder || 'no'}
|
|
14
|
+
allowtransparency={props.allowTransparency || 'true'}
|
|
15
|
+
allowFullScreen={props.allowFullScreen || true}
|
|
16
|
+
style={props.style || {}}
|
|
17
|
+
ref={ref}
|
|
18
|
+
/>
|
|
19
|
+
)
|
|
36
20
|
}
|
package/src/lazyLoadImage.js
CHANGED
|
@@ -1,34 +1,17 @@
|
|
|
1
|
-
import React from 'react' // eslint-disable-line no-unused-vars
|
|
2
|
-
import
|
|
1
|
+
import React, { useRef } from 'react' // eslint-disable-line no-unused-vars
|
|
2
|
+
import useIsInViewPort from './baseClass'
|
|
3
3
|
|
|
4
|
-
export default
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
render() {
|
|
9
|
-
return (
|
|
10
|
-
<img
|
|
11
|
-
src={this.state.link}
|
|
12
|
-
alt={this.props.alt}
|
|
13
|
-
style={this.style}
|
|
14
|
-
className={this.props.className}
|
|
15
|
-
ref={node => (this.domNode = node)}
|
|
16
|
-
/>
|
|
17
|
-
)
|
|
18
|
-
}
|
|
19
|
-
componentWillMount() {
|
|
20
|
-
if (this.props.className === '' && this.props.preserveAspect === false) {
|
|
21
|
-
this.style = {
|
|
22
|
-
minHeight: '300px',
|
|
23
|
-
minWidth: '300px',
|
|
24
|
-
...this.props.style
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
}
|
|
4
|
+
export default function LazyImage(props) {
|
|
5
|
+
const ref = useRef()
|
|
6
|
+
const isViewable = useIsInViewPort(ref, props)
|
|
29
7
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
8
|
+
return (
|
|
9
|
+
<img
|
|
10
|
+
src={isViewable.link}
|
|
11
|
+
alt={props.alt}
|
|
12
|
+
style={props.style}
|
|
13
|
+
className={props.className}
|
|
14
|
+
ref={ref}
|
|
15
|
+
/>
|
|
16
|
+
)
|
|
34
17
|
}
|