lazy-react 3.0.2 → 3.2.0
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/README.md +64 -12
- package/demo/index.html +1 -0
- package/demo/index.js +23 -44
- package/dist/index.js +1 -2
- package/package.json +9 -11
- package/src/{index.js → index.tsx} +1 -0
- package/src/lazyLoadBackgroundImage.tsx +30 -0
- package/src/lazyLoadComponent.tsx +22 -0
- package/src/lazyLoadFrame.tsx +21 -0
- package/src/lazyLoadImage.tsx +21 -0
- package/src/useIsInViewport.tsx +118 -0
- package/tsconfig.json +25 -0
- package/webpack.config.demo.js +1 -1
- package/webpack.config.js +15 -48
- package/.babelrc +0 -6
- package/dist/index.js.map +0 -1
- package/src/baseClass.js +0 -107
- package/src/lazyLoadBackgroundImage.js +0 -20
- package/src/lazyLoadComponent.js +0 -24
- package/src/lazyLoadFrame.js +0 -20
- package/src/lazyLoadImage.js +0 -17
package/dist/index.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
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,(
|
|
2
|
-
//# sourceMappingURL=index.js.map
|
|
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,(e=>(()=>{"use strict";var t={787:t=>{t.exports=e}},n={};function r(e){var o=n[e];if(void 0!==o)return o.exports;var l=n[e]={exports:{}};return t[e](l,l.exports,r),l.exports}r.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return r.d(t,{a:t}),t},r.d=(e,t)=>{for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var o={};return(()=>{r.r(o),r.d(o,{LazyBackgroundImage:()=>n,LazyComponent:()=>i,LazyFrame:()=>a,LazyImage:()=>l,default:()=>s});var e=r(787),t=r.n(e);function n(n){let[r,o,l]=s(n);const[a,i]=(0,e.useState)(Object.assign({backgroundImage:`url(${o})`},n.style));return(0,e.useEffect)((()=>{i(Object.assign({backgroundImage:`url(${o})`},n.style))}),[o,l]),t().createElement("div",{className:n.className,style:a,ref:e=>{r(e)}},n.children)}function l(e){const[n,r]=s(e);return t().createElement("div",{ref:e=>{n(e)}},t().createElement("img",{src:r,alt:e.alt,style:e.style,className:e.className}))}function a(e){let[n,r]=s(e);return t().createElement("iframe",Object.assign({height:e.height||"500",scrolling:e.scrolling||"no",src:r,frameBorder:e.frameBorder||"no",allowFullScreen:e.allowFullScreen||!0,style:e.style||{},ref:e=>{n(e)}},e))}function i(e){const[n,r,o]=s(e);return o?t().createElement("div",null,e.children):t().createElement("div",{ref:e=>{n(e)},style:Object.assign({height:"300px",width:"300px"},e.style)})}function s(t){const[n,r]=(0,e.useState)(""),[o,l]=(0,e.useState)(!1);let[a,i]=(0,e.useState)(null);const s=(0,e.useMemo)((()=>({element:a,makeItVisible:d,offset:t.offset||100})),[a,t]),c=(0,e.useCallback)((e=>{null!==e&&i(e)}),[]);function d(){r((()=>t.link)),l((()=>!0))}return(0,e.useEffect)((()=>(null!==a&&u.addElement(s),()=>u.removeElementFromList(s))),[a]),[c,n,o]}let c=[];const u={isInViewPort:({offset:e,top:t,left:n})=>t<window.innerHeight+e&&n<window.innerWidth+e,calculateNewPosition:e=>{var t;const{top:n,left:r}=(null===(t=e.element)||void 0===t?void 0:t.getBoundingClientRect())||{top:0,left:0};return Object.assign(Object.assign({},e),{top:n,left:r})},addElement:function(e){c.push(e),0===u.isListenerAttached&&(u.isListenerAttached=window.requestAnimationFrame(u.eventHandler))},eventHandler:function(){0===c.length?u.removeScrollHandler():(c.forEach(((e,t)=>{u.isInViewPort(u.calculateNewPosition(e))&&(e.makeItVisible(),u.removeElementFromList(e))})),u.isListenerAttached=window.requestAnimationFrame(u.eventHandler))},removeScrollHandler:function(){window.cancelAnimationFrame(u.isListenerAttached),u.isListenerAttached=0},removeElementFromList:function(e){c=c.filter((t=>t!==e))},isListenerAttached:0}})(),o})()));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lazy-react",
|
|
3
|
-
"version": "3.0
|
|
3
|
+
"version": "3.2.0",
|
|
4
4
|
"description": "components to lazy load iframes, images and images as backgrounds",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"build": "npm run build:release && npm run build:demo",
|
|
10
10
|
"lint": "eslint src/*",
|
|
11
11
|
"lint:fix": "eslint --fix src/*",
|
|
12
|
-
"
|
|
12
|
+
"format": "prettier --write --single-quote --no-semi ./src/*.tsx",
|
|
13
13
|
"precommit": "lint-staged",
|
|
14
14
|
"test": "jest"
|
|
15
15
|
},
|
|
@@ -30,20 +30,19 @@
|
|
|
30
30
|
"url": "https://github.com/jonathanobino/react-lazy"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@
|
|
34
|
-
"@
|
|
35
|
-
"@
|
|
36
|
-
"@
|
|
37
|
-
"@types/
|
|
38
|
-
"babel-cli": "^6.26.0",
|
|
39
|
-
"babel-loader": "^8.1.0",
|
|
40
|
-
"babel-plugin-transform-object-rest-spread": "^6.26.0",
|
|
33
|
+
"@testing-library/react": "^12.1.4",
|
|
34
|
+
"@types/jest": "^27.4.1",
|
|
35
|
+
"@types/node": "^17.0.21",
|
|
36
|
+
"@types/react": "^17.0.43",
|
|
37
|
+
"@types/react-dom": "^17.0.14",
|
|
41
38
|
"eslint": "^7.10.0",
|
|
42
39
|
"eslint-plugin-react": "^7.21.3",
|
|
43
40
|
"husky": "^4.3.0",
|
|
44
41
|
"jest": "^27.5.1",
|
|
45
42
|
"lint-staged": "^10.4.0",
|
|
46
43
|
"prettier": "^2.1.2",
|
|
44
|
+
"ts-loader": "^9.2.7",
|
|
45
|
+
"typescript": "^4.6.2",
|
|
47
46
|
"webpack": "^5.66.0",
|
|
48
47
|
"webpack-cli": "^4.9.1"
|
|
49
48
|
},
|
|
@@ -52,7 +51,6 @@
|
|
|
52
51
|
"react-dom": "^17.0.2"
|
|
53
52
|
},
|
|
54
53
|
"peerDependencies": {
|
|
55
|
-
"react": "^17.0.2",
|
|
56
54
|
"react-dom": "^17.0.2"
|
|
57
55
|
}
|
|
58
56
|
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import React, { useState, useEffect } from 'react' // eslint-disable-line no-unused-vars
|
|
2
|
+
import useIsInViewPort from './index'
|
|
3
|
+
|
|
4
|
+
export default function LazyBackgroundImage(props: any) {
|
|
5
|
+
let [setRef, link, isViewable] = useIsInViewPort(props)
|
|
6
|
+
|
|
7
|
+
const [style, setStyle] = useState({
|
|
8
|
+
backgroundImage: `url(${link})`,
|
|
9
|
+
...props.style,
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
setStyle({
|
|
14
|
+
backgroundImage: `url(${link})`,
|
|
15
|
+
...props.style,
|
|
16
|
+
})
|
|
17
|
+
}, [link, isViewable])
|
|
18
|
+
|
|
19
|
+
return (
|
|
20
|
+
<div
|
|
21
|
+
className={props.className}
|
|
22
|
+
style={style}
|
|
23
|
+
ref={(node) => {
|
|
24
|
+
setRef(node)
|
|
25
|
+
}}
|
|
26
|
+
>
|
|
27
|
+
{props.children}
|
|
28
|
+
</div>
|
|
29
|
+
)
|
|
30
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import useIsInViewport from './index'
|
|
3
|
+
|
|
4
|
+
export default function LazyComponent(props: any) {
|
|
5
|
+
const [setRef, link, isVisible] = useIsInViewport(props)
|
|
6
|
+
|
|
7
|
+
if (!isVisible)
|
|
8
|
+
return (
|
|
9
|
+
<div
|
|
10
|
+
ref={(node) => {
|
|
11
|
+
setRef(node)
|
|
12
|
+
}}
|
|
13
|
+
style={{
|
|
14
|
+
height: '300px',
|
|
15
|
+
width: '300px',
|
|
16
|
+
...props.style,
|
|
17
|
+
}}
|
|
18
|
+
></div>
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
return <div>{props.children}</div>
|
|
22
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import React from 'react' // eslint-disable-line no-unused-vars
|
|
2
|
+
import useIsInViewPort from './index'
|
|
3
|
+
|
|
4
|
+
export default function LazyFrame(props: any) {
|
|
5
|
+
let [setRef, link] = useIsInViewPort(props)
|
|
6
|
+
|
|
7
|
+
return (
|
|
8
|
+
<iframe
|
|
9
|
+
height={props.height || '500'}
|
|
10
|
+
scrolling={props.scrolling || 'no'}
|
|
11
|
+
src={link}
|
|
12
|
+
frameBorder={props.frameBorder || 'no'}
|
|
13
|
+
allowFullScreen={props.allowFullScreen || true}
|
|
14
|
+
style={props.style || {}}
|
|
15
|
+
ref={(node) => {
|
|
16
|
+
setRef(node)
|
|
17
|
+
}}
|
|
18
|
+
{...props}
|
|
19
|
+
/>
|
|
20
|
+
)
|
|
21
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import React from 'react' // eslint-disable-line no-unused-vars
|
|
2
|
+
import useIsInViewPort from './index'
|
|
3
|
+
|
|
4
|
+
export default function LazyImage(props: any) {
|
|
5
|
+
const [setRef, link] = useIsInViewPort(props)
|
|
6
|
+
|
|
7
|
+
return (
|
|
8
|
+
<div
|
|
9
|
+
ref={(node) => {
|
|
10
|
+
setRef(node)
|
|
11
|
+
}}
|
|
12
|
+
>
|
|
13
|
+
<img
|
|
14
|
+
src={link}
|
|
15
|
+
alt={props.alt}
|
|
16
|
+
style={props.style}
|
|
17
|
+
className={props.className}
|
|
18
|
+
/>
|
|
19
|
+
</div>
|
|
20
|
+
)
|
|
21
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import React, { useState, useEffect, useMemo, useCallback } from 'react' // eslint-disable-line no-unused-vars
|
|
2
|
+
|
|
3
|
+
interface InstanceElement {
|
|
4
|
+
makeItVisible: () => void
|
|
5
|
+
element: HTMLElement | null
|
|
6
|
+
offset: number
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export default function useRenderIfInViewPort(props: {
|
|
10
|
+
link: string
|
|
11
|
+
offset: number
|
|
12
|
+
}): [Function, string, boolean] {
|
|
13
|
+
const [link, setLink] = useState('')
|
|
14
|
+
const [visible, setVisible] = useState(false)
|
|
15
|
+
|
|
16
|
+
let [ref, setRef] = useState(null)
|
|
17
|
+
|
|
18
|
+
const thisInstance = useMemo(() => {
|
|
19
|
+
return {
|
|
20
|
+
element: ref,
|
|
21
|
+
makeItVisible,
|
|
22
|
+
offset: props.offset || 100,
|
|
23
|
+
}
|
|
24
|
+
}, [ref, props])
|
|
25
|
+
|
|
26
|
+
const getRef = useCallback((node) => {
|
|
27
|
+
if (node !== null) setRef(node)
|
|
28
|
+
}, [])
|
|
29
|
+
|
|
30
|
+
function makeItVisible() {
|
|
31
|
+
setLink(() => props.link)
|
|
32
|
+
setVisible(() => true)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
useEffect(() => {
|
|
36
|
+
if (ref !== null)
|
|
37
|
+
// add the element to the array of elements that are waiting to be lazy loaded
|
|
38
|
+
CheckIfRender.addElement(thisInstance)
|
|
39
|
+
return () =>
|
|
40
|
+
// if the element is unloaded remove the element from the list of elements that needs to be lazy loader
|
|
41
|
+
CheckIfRender.removeElementFromList(thisInstance)
|
|
42
|
+
}, [ref])
|
|
43
|
+
|
|
44
|
+
return [getRef, link, visible]
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// array with all the elements that are waiting to be shown in the viewport
|
|
48
|
+
let elements: InstanceElement[] = []
|
|
49
|
+
|
|
50
|
+
const CheckIfRender = {
|
|
51
|
+
// top: the position of the element in relation with the top of the browser
|
|
52
|
+
// left: the position of the element in relation with the left of the browser
|
|
53
|
+
// offset: the desired offset of the element in relation of the viewport
|
|
54
|
+
isInViewPort: ({
|
|
55
|
+
offset,
|
|
56
|
+
top,
|
|
57
|
+
left,
|
|
58
|
+
}: {
|
|
59
|
+
offset: number
|
|
60
|
+
top: number
|
|
61
|
+
left: number
|
|
62
|
+
}) => top < window.innerHeight + offset && left < window.innerWidth + offset,
|
|
63
|
+
|
|
64
|
+
calculateNewPosition: (elem: InstanceElement) => {
|
|
65
|
+
const { top, left } = elem.element?.getBoundingClientRect() || {
|
|
66
|
+
top: 0,
|
|
67
|
+
left: 0,
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return {
|
|
71
|
+
...elem,
|
|
72
|
+
top,
|
|
73
|
+
left,
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
addElement: function (element: InstanceElement) {
|
|
77
|
+
//the distance from the pixel 0,0 and the top of the element
|
|
78
|
+
elements.push(element)
|
|
79
|
+
//check if has already been started the rAF cycle
|
|
80
|
+
if (CheckIfRender.isListenerAttached === 0) {
|
|
81
|
+
CheckIfRender.isListenerAttached = window.requestAnimationFrame(
|
|
82
|
+
CheckIfRender.eventHandler
|
|
83
|
+
)
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
eventHandler: function () {
|
|
87
|
+
//if there is no more element to lazy load remove the listener/rAF
|
|
88
|
+
if (elements.length === 0) {
|
|
89
|
+
CheckIfRender.removeScrollHandler()
|
|
90
|
+
} else {
|
|
91
|
+
elements.forEach((elem, i) => {
|
|
92
|
+
const haveToShow = CheckIfRender.isInViewPort(
|
|
93
|
+
CheckIfRender.calculateNewPosition(elem)
|
|
94
|
+
)
|
|
95
|
+
if (haveToShow) {
|
|
96
|
+
elem.makeItVisible()
|
|
97
|
+
// remove element from the list of elements to lazy load
|
|
98
|
+
CheckIfRender.removeElementFromList(elem)
|
|
99
|
+
}
|
|
100
|
+
})
|
|
101
|
+
CheckIfRender.isListenerAttached = window.requestAnimationFrame(
|
|
102
|
+
CheckIfRender.eventHandler
|
|
103
|
+
)
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
|
|
107
|
+
removeScrollHandler: function () {
|
|
108
|
+
window.cancelAnimationFrame(CheckIfRender.isListenerAttached)
|
|
109
|
+
CheckIfRender.isListenerAttached = 0
|
|
110
|
+
},
|
|
111
|
+
//When an element is unloaded remove it from the list of elements that are waiting to be lazy-loaded
|
|
112
|
+
removeElementFromList: function (toRemove: InstanceElement) {
|
|
113
|
+
elements = elements.filter((elem) => elem !== toRemove)
|
|
114
|
+
},
|
|
115
|
+
isListenerAttached: 0, // intended as not set
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export { CheckIfRender }
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "es2015",
|
|
4
|
+
"lib": [
|
|
5
|
+
"dom",
|
|
6
|
+
"dom.iterable",
|
|
7
|
+
"esnext"
|
|
8
|
+
],
|
|
9
|
+
"allowJs": true,
|
|
10
|
+
"skipLibCheck": true,
|
|
11
|
+
"esModuleInterop": true,
|
|
12
|
+
"allowSyntheticDefaultImports": true,
|
|
13
|
+
"strict": true,
|
|
14
|
+
"forceConsistentCasingInFileNames": true,
|
|
15
|
+
"noFallthroughCasesInSwitch": true,
|
|
16
|
+
"module": "esnext",
|
|
17
|
+
"moduleResolution": "node",
|
|
18
|
+
"resolveJsonModule": true,
|
|
19
|
+
"isolatedModules": true,
|
|
20
|
+
"jsx": "react"
|
|
21
|
+
},
|
|
22
|
+
"include": [
|
|
23
|
+
"src"
|
|
24
|
+
]
|
|
25
|
+
}
|
package/webpack.config.demo.js
CHANGED
package/webpack.config.js
CHANGED
|
@@ -1,50 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
var webpack = require('webpack')
|
|
1
|
+
const path = require('path');
|
|
3
2
|
|
|
4
3
|
module.exports = {
|
|
5
4
|
mode:'production',
|
|
6
|
-
entry: './src/index.
|
|
7
|
-
|
|
5
|
+
entry: path.join(__dirname,'./src/index.tsx'),
|
|
6
|
+
module: {
|
|
7
|
+
rules: [
|
|
8
|
+
{
|
|
9
|
+
test: /\.tsx?$/,
|
|
10
|
+
use: [{loader:'ts-loader'}],
|
|
11
|
+
exclude: /node_modules/,
|
|
12
|
+
},
|
|
13
|
+
],
|
|
14
|
+
},
|
|
15
|
+
resolve: {
|
|
16
|
+
extensions: ['.tsx', '.ts'],
|
|
17
|
+
},
|
|
8
18
|
output: {
|
|
9
19
|
library: 'LazyReact',
|
|
10
20
|
libraryTarget: 'umd',
|
|
11
21
|
path: path.join(__dirname),
|
|
12
22
|
filename: './dist/index.js'
|
|
13
23
|
},
|
|
14
|
-
// optimization: {
|
|
15
|
-
// minimizer: [
|
|
16
|
-
// new UglifyJsPlugin({
|
|
17
|
-
// sourceMap: true,
|
|
18
|
-
// uglifyOptions: {
|
|
19
|
-
// compress: {
|
|
20
|
-
// inline: false
|
|
21
|
-
// },
|
|
22
|
-
// output: {
|
|
23
|
-
// comments: false
|
|
24
|
-
// }
|
|
25
|
-
// }
|
|
26
|
-
// })
|
|
27
|
-
// ],
|
|
28
|
-
// runtimeChunk: false,
|
|
29
|
-
// splitChunks: {
|
|
30
|
-
// cacheGroups: {
|
|
31
|
-
// default: false,
|
|
32
|
-
// commons: {
|
|
33
|
-
// test: /[\\/]node_modules[\\/]/,
|
|
34
|
-
// name: 'vendor_app',
|
|
35
|
-
// chunks: 'all',
|
|
36
|
-
// minChunks: 2
|
|
37
|
-
// }
|
|
38
|
-
// }
|
|
39
|
-
// }
|
|
40
|
-
// },
|
|
41
|
-
plugins: [
|
|
42
|
-
new webpack.DefinePlugin({
|
|
43
|
-
'process.env': {
|
|
44
|
-
NODE_ENV: '"production"'
|
|
45
|
-
},
|
|
46
|
-
__DEVELOPMENT__: false
|
|
47
|
-
})],
|
|
48
24
|
externals: [
|
|
49
25
|
{
|
|
50
26
|
react: {
|
|
@@ -63,13 +39,4 @@ module.exports = {
|
|
|
63
39
|
}
|
|
64
40
|
}
|
|
65
41
|
],
|
|
66
|
-
|
|
67
|
-
rules: [
|
|
68
|
-
{
|
|
69
|
-
test: /\.js$/,
|
|
70
|
-
use: 'babel-loader',
|
|
71
|
-
exclude: /node_modules/
|
|
72
|
-
}
|
|
73
|
-
]
|
|
74
|
-
}
|
|
75
|
-
}
|
|
42
|
+
};
|
package/.babelrc
DELETED
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"./dist/index.js","mappings":"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","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/src/baseClass.js
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import React, { useState, useEffect } from 'react' // eslint-disable-line no-unused-vars
|
|
2
|
-
|
|
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 }) =>
|
|
39
|
-
window.scrollY + window.innerHeight + offset > top &&
|
|
40
|
-
window.scrollX + window.innerWidth + offset > left
|
|
41
|
-
|
|
42
|
-
CheckIfRender.calculateNewPosition = (elem) => {
|
|
43
|
-
const reference = elem.element
|
|
44
|
-
const { top, left, right } = reference.getBoundingClientRect()
|
|
45
|
-
return {
|
|
46
|
-
...elem,
|
|
47
|
-
top,
|
|
48
|
-
left,
|
|
49
|
-
right,
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
CheckIfRender.addElement = function ({ element, props, makeItVisible }) {
|
|
54
|
-
//the distance from the pixel 0,0 and the top of the element
|
|
55
|
-
const { top, left, right } = element.getBoundingClientRect()
|
|
56
|
-
CheckIfRender.elements.push({
|
|
57
|
-
element,
|
|
58
|
-
top,
|
|
59
|
-
left,
|
|
60
|
-
right,
|
|
61
|
-
offset: props.offset || 100,
|
|
62
|
-
makeItVisible,
|
|
63
|
-
})
|
|
64
|
-
//check if has already been started the rAF cycle
|
|
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
|
-
})
|
|
88
|
-
CheckIfRender.isListenerAttached = window.requestAnimationFrame(
|
|
89
|
-
CheckIfRender.eventHandler
|
|
90
|
-
)
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
CheckIfRender.removeScrollHandler = function () {
|
|
95
|
-
window.cancelAnimationFrame(CheckIfRender.isListenerAttached)
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
//When an element is unloaded remove it from the list of elements that are waiting to be lazy-loaded
|
|
99
|
-
CheckIfRender.removeElementFromList = function (toRemove) {
|
|
100
|
-
CheckIfRender.elements = CheckIfRender.elements.filter(
|
|
101
|
-
(elem) => elem !== toRemove
|
|
102
|
-
)
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
CheckIfRender.isListenerAttached = false
|
|
106
|
-
|
|
107
|
-
export { CheckIfRender }
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import React, { useState, useEffect, useRef } from 'react' // eslint-disable-line no-unused-vars
|
|
2
|
-
import useIsInViewPort from './baseClass'
|
|
3
|
-
|
|
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
|
-
})
|
|
11
|
-
|
|
12
|
-
useEffect(() => {
|
|
13
|
-
setStyle({
|
|
14
|
-
backgroundImage: `url(${isViewable.link})`,
|
|
15
|
-
...props.style,
|
|
16
|
-
})
|
|
17
|
-
}, [isViewable])
|
|
18
|
-
|
|
19
|
-
return <div className={props.className} style={style} ref={ref} />
|
|
20
|
-
}
|
package/src/lazyLoadComponent.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import React, { useRef } from 'react' // eslint-disable-line no-unused-vars
|
|
2
|
-
import useIsInViewPort from './baseClass'
|
|
3
|
-
|
|
4
|
-
export default function LazyComponent(props) {
|
|
5
|
-
const ref = useRef()
|
|
6
|
-
let isViewable = useIsInViewPort(ref, props)
|
|
7
|
-
|
|
8
|
-
const placeHolder = (
|
|
9
|
-
<div
|
|
10
|
-
style={
|
|
11
|
-
props.style
|
|
12
|
-
? props.style
|
|
13
|
-
: {
|
|
14
|
-
heigt: '300px',
|
|
15
|
-
width: '300px',
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
/>
|
|
19
|
-
)
|
|
20
|
-
|
|
21
|
-
return (
|
|
22
|
-
<div ref={ref}>{isViewable.visible ? props.children : placeHolder}</div>
|
|
23
|
-
)
|
|
24
|
-
}
|
package/src/lazyLoadFrame.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import React, { useRef } from 'react' // eslint-disable-line no-unused-vars
|
|
2
|
-
import useIsInViewPort from './baseClass'
|
|
3
|
-
|
|
4
|
-
export default function LazyFrame(props) {
|
|
5
|
-
const ref = useRef()
|
|
6
|
-
let isViewable = useIsInViewPort(ref, props)
|
|
7
|
-
|
|
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
|
-
)
|
|
20
|
-
}
|
package/src/lazyLoadImage.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import React, { useRef } from 'react' // eslint-disable-line no-unused-vars
|
|
2
|
-
import useIsInViewPort from './baseClass'
|
|
3
|
-
|
|
4
|
-
export default function LazyImage(props) {
|
|
5
|
-
const ref = useRef()
|
|
6
|
-
const isViewable = useIsInViewPort(ref, props)
|
|
7
|
-
|
|
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
|
-
)
|
|
17
|
-
}
|