@react-hook/intersection-observer
Advanced tools
Comparing version 3.0.1 to 3.1.0
@@ -1,61 +0,17 @@ | ||
'use strict' | ||
"use strict"; | ||
exports.__esModule = true | ||
exports.default = void 0 | ||
exports.__esModule = true; | ||
exports.default = void 0; | ||
require('intersection-observer') | ||
require("intersection-observer"); | ||
var React = /*#__PURE__*/ _interopRequireWildcard( | ||
/*#__PURE__*/ require('react') | ||
) | ||
var React = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("react")); | ||
var _passiveLayoutEffect = /*#__PURE__*/ _interopRequireDefault( | ||
/*#__PURE__*/ require('@react-hook/passive-layout-effect') | ||
) | ||
var _passiveLayoutEffect = /*#__PURE__*/_interopRequireDefault( /*#__PURE__*/require("@react-hook/passive-layout-effect")); | ||
function _interopRequireDefault(obj) { | ||
return obj && obj.__esModule ? obj : {default: obj} | ||
} | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _getRequireWildcardCache() { | ||
if (typeof WeakMap !== 'function') return null | ||
var cache = new WeakMap() | ||
_getRequireWildcardCache = function () { | ||
return cache | ||
} | ||
return cache | ||
} | ||
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; } | ||
function _interopRequireWildcard(obj) { | ||
if (obj && obj.__esModule) { | ||
return obj | ||
} | ||
if (obj === null || (typeof obj !== 'object' && typeof obj !== 'function')) { | ||
return {default: obj} | ||
} | ||
var cache = _getRequireWildcardCache() | ||
if (cache && cache.has(obj)) { | ||
return cache.get(obj) | ||
} | ||
var newObj = {} | ||
var hasPropertyDescriptor = | ||
Object.defineProperty && Object.getOwnPropertyDescriptor | ||
for (var key in obj) { | ||
if (Object.prototype.hasOwnProperty.call(obj, key)) { | ||
var desc = hasPropertyDescriptor | ||
? Object.getOwnPropertyDescriptor(obj, key) | ||
: null | ||
if (desc && (desc.get || desc.set)) { | ||
Object.defineProperty(newObj, key, desc) | ||
} else { | ||
newObj[key] = obj[key] | ||
} | ||
} | ||
} | ||
newObj.default = obj | ||
if (cache) { | ||
cache.set(obj, newObj) | ||
} | ||
return newObj | ||
} | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
@@ -69,4 +25,4 @@ const useIntersectionObserver = (target, options = {}) => { | ||
threshold = 0, | ||
initialIsIntersecting = false, | ||
} = options | ||
initialIsIntersecting = false | ||
} = options; | ||
const [entry, setEntry] = React.useState(() => ({ | ||
@@ -79,48 +35,43 @@ boundingClientRect: null, | ||
target: null, | ||
time: 0, | ||
})) | ||
time: 0 | ||
})); | ||
function _ref(entries) { | ||
return setEntry(entries[entries.length - 1]) | ||
return setEntry(entries[entries.length - 1]); | ||
} | ||
const createObserver = () => { | ||
if (typeof IntersectionObserver === 'undefined') return null | ||
if (typeof IntersectionObserver === 'undefined') return null; | ||
const observer = new IntersectionObserver(_ref, { | ||
root, | ||
rootMargin, | ||
threshold, | ||
}) // @ts-ignore | ||
threshold | ||
}); // @ts-ignore | ||
observer.POLL_INTERVAL = pollInterval // @ts-ignore | ||
observer.POLL_INTERVAL = pollInterval; // @ts-ignore | ||
observer.USE_MUTATION_OBSERVER = useMutationObserver | ||
return observer | ||
} | ||
observer.USE_MUTATION_OBSERVER = useMutationObserver; | ||
return observer; | ||
}; | ||
const [observer, setObserver] = React.useState(createObserver) | ||
const [observer, setObserver] = React.useState(createObserver); | ||
React.useEffect(() => { | ||
const observer = createObserver() | ||
setObserver(observer) | ||
const observer = createObserver(); | ||
setObserver(observer); | ||
return () => { | ||
observer === null || observer === void 0 ? void 0 : observer.disconnect() | ||
} // eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [ | ||
root, | ||
rootMargin, | ||
pollInterval, | ||
useMutationObserver, // eslint-disable-next-line react-hooks/exhaustive-deps | ||
...(Array.isArray(threshold) === true ? threshold : [threshold]), | ||
]) | ||
;(0, _passiveLayoutEffect.default)(() => { | ||
const targetEl = target && 'current' in target ? target.current : target | ||
targetEl && observer && observer.observe(targetEl) | ||
observer === null || observer === void 0 ? void 0 : observer.disconnect(); | ||
}; // eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [root, rootMargin, pollInterval, useMutationObserver, // eslint-disable-next-line react-hooks/exhaustive-deps | ||
...(Array.isArray(threshold) === true ? threshold : [threshold])]); | ||
(0, _passiveLayoutEffect.default)(() => { | ||
const targetEl = target && 'current' in target ? target.current : target; | ||
targetEl && observer && observer.observe(targetEl); | ||
return () => { | ||
targetEl && observer && observer.unobserve(targetEl) | ||
} | ||
}, [target, observer]) | ||
return entry | ||
} | ||
targetEl && observer && observer.unobserve(targetEl); | ||
}; | ||
}, [target, observer]); | ||
return entry; | ||
}; | ||
var _default = useIntersectionObserver | ||
exports.default = _default | ||
var _default = useIntersectionObserver; | ||
exports.default = _default; |
@@ -1,4 +0,4 @@ | ||
import 'intersection-observer' | ||
import * as React from 'react' | ||
import useLayoutEffect from '@react-hook/passive-layout-effect' | ||
import 'intersection-observer'; | ||
import * as React from 'react'; | ||
import useLayoutEffect from '@react-hook/passive-layout-effect'; | ||
@@ -12,4 +12,4 @@ const useIntersectionObserver = (target, options = {}) => { | ||
threshold = 0, | ||
initialIsIntersecting = false, | ||
} = options | ||
initialIsIntersecting = false | ||
} = options; | ||
const [entry, setEntry] = React.useState(() => ({ | ||
@@ -22,47 +22,42 @@ boundingClientRect: null, | ||
target: null, | ||
time: 0, | ||
})) | ||
time: 0 | ||
})); | ||
function _ref(entries) { | ||
return setEntry(entries[entries.length - 1]) | ||
return setEntry(entries[entries.length - 1]); | ||
} | ||
const createObserver = () => { | ||
if (typeof IntersectionObserver === 'undefined') return null | ||
if (typeof IntersectionObserver === 'undefined') return null; | ||
const observer = new IntersectionObserver(_ref, { | ||
root, | ||
rootMargin, | ||
threshold, | ||
}) // @ts-ignore | ||
threshold | ||
}); // @ts-ignore | ||
observer.POLL_INTERVAL = pollInterval // @ts-ignore | ||
observer.POLL_INTERVAL = pollInterval; // @ts-ignore | ||
observer.USE_MUTATION_OBSERVER = useMutationObserver | ||
return observer | ||
} | ||
observer.USE_MUTATION_OBSERVER = useMutationObserver; | ||
return observer; | ||
}; | ||
const [observer, setObserver] = React.useState(createObserver) | ||
const [observer, setObserver] = React.useState(createObserver); | ||
React.useEffect(() => { | ||
const observer = createObserver() | ||
setObserver(observer) | ||
const observer = createObserver(); | ||
setObserver(observer); | ||
return () => { | ||
observer === null || observer === void 0 ? void 0 : observer.disconnect() | ||
} // eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [ | ||
root, | ||
rootMargin, | ||
pollInterval, | ||
useMutationObserver, // eslint-disable-next-line react-hooks/exhaustive-deps | ||
...(Array.isArray(threshold) === true ? threshold : [threshold]), | ||
]) | ||
observer === null || observer === void 0 ? void 0 : observer.disconnect(); | ||
}; // eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [root, rootMargin, pollInterval, useMutationObserver, // eslint-disable-next-line react-hooks/exhaustive-deps | ||
...(Array.isArray(threshold) === true ? threshold : [threshold])]); | ||
useLayoutEffect(() => { | ||
const targetEl = target && 'current' in target ? target.current : target | ||
targetEl && observer && observer.observe(targetEl) | ||
const targetEl = target && 'current' in target ? target.current : target; | ||
targetEl && observer && observer.observe(targetEl); | ||
return () => { | ||
targetEl && observer && observer.unobserve(targetEl) | ||
} | ||
}, [target, observer]) | ||
return entry | ||
} | ||
targetEl && observer && observer.unobserve(targetEl); | ||
}; | ||
}, [target, observer]); | ||
return entry; | ||
}; | ||
export default useIntersectionObserver | ||
export default useIntersectionObserver; |
106
package.json
{ | ||
"name": "@react-hook/intersection-observer", | ||
"version": "3.0.1", | ||
"version": "3.1.0", | ||
"homepage": "https://github.com/jaredLunde/react-hook/tree/master/packages/intersection-observer#readme", | ||
@@ -23,2 +23,3 @@ "repository": "github:jaredLunde/react-hook", | ||
"module": "dist/module/index.js", | ||
"unpkg": "dist/umd/use-intersection-observer.js", | ||
"source": "src/index.tsx", | ||
@@ -36,2 +37,3 @@ "types": "types/index.d.ts", | ||
"require": "./dist/main/index.js", | ||
"umd": "./dist/umd/use-intersection-observer.js", | ||
"source": "./src/index.tsx", | ||
@@ -46,18 +48,14 @@ "types": "./types/index.d.ts", | ||
"scripts": { | ||
"build": "npm run build-esm && npm run build-main && npm run build-module && npm run build-types", | ||
"build-esm": "npm run compile -- -d dist/esm --env-name esm --out-file-extension .mjs", | ||
"build-main": "npm run compile -- -d dist/main --env-name main", | ||
"build-module": "npm run compile -- -d dist/module --env-name module", | ||
"build-types": "tsc -p tsconfig.json -d --outDir types --emitDeclarationOnly", | ||
"check-types": "tsc --noEmit -p tsconfig.json", | ||
"compile": "babel src -x .ts,.tsx --ignore \"**/*.test.ts\",\"**/*.test.tsx\" --delete-dir-on-start", | ||
"format": "prettier --write \"**/*.{ts,tsx,js,jsx,md,yml,json,eslintrc,prettierrc}\"", | ||
"build": "lundle build --umd-case camel", | ||
"check-types": "lundle check-types", | ||
"dev": "lundle build -f module,cjs -w", | ||
"format": "prettier --write \"{,!(node_modules|dist|coverage)/**/}*.{ts,tsx,js,jsx,md,yml,json}\"", | ||
"lint": "eslint . --ext .ts,.tsx", | ||
"prepublishOnly": "npm run lint && npm run test && npm run build && npm run format", | ||
"test": "jest", | ||
"validate": "npm run check-types && npm run lint && npm run test -- --coverage" | ||
"validate": "lundle check-types && npm run lint && jest --coverage" | ||
}, | ||
"husky": { | ||
"hooks": { | ||
"pre-commit": "npm run build-types && git add types && lint-staged" | ||
"pre-commit": "lundle check-types && lint-staged" | ||
} | ||
@@ -70,34 +68,68 @@ }, | ||
], | ||
"**/*.{md,yml,json,eslintrc,prettierrc}": [ | ||
"**/*.{md,yml,json}": [ | ||
"prettier --write" | ||
] | ||
}, | ||
"eslintConfig": { | ||
"extends": [ | ||
"lunde" | ||
] | ||
}, | ||
"eslintIgnore": [ | ||
"node_modules", | ||
"coverage", | ||
"dist", | ||
"test", | ||
"*.config.js" | ||
], | ||
"jest": { | ||
"moduleDirectories": [ | ||
"node_modules", | ||
"src", | ||
"test" | ||
], | ||
"testMatch": [ | ||
"<rootDir>/src/**/?(*.)test.{ts,tsx}" | ||
], | ||
"collectCoverageFrom": [ | ||
"**/src/**/*.{ts,tsx}" | ||
], | ||
"setupFilesAfterEnv": [ | ||
"./test/setup.js" | ||
], | ||
"snapshotResolver": "./test/resolve-snapshot.js", | ||
"globals": { | ||
"__DEV__": true | ||
} | ||
}, | ||
"prettier": { | ||
"semi": false, | ||
"singleQuote": true, | ||
"jsxSingleQuote": true, | ||
"bracketSpacing": false | ||
}, | ||
"devDependencies": { | ||
"@lunde/babel-preset-es": "latest", | ||
"@testing-library/react": "^9.3.2", | ||
"@testing-library/react-hooks": "^3.2.1", | ||
"@types/jest": "^25.2.3", | ||
"@typescript-eslint/eslint-plugin": "^3.0.1", | ||
"@typescript-eslint/parser": "^3.0.1", | ||
"babel-plugin-annotate-pure-calls": "^0.4.0", | ||
"babel-plugin-optimize-react": "^0.0.4", | ||
"eslint": "^7.1.0", | ||
"eslint-import-resolver-jest": "latest", | ||
"eslint-plugin-jest": "^23.13.2", | ||
"eslint-plugin-react": "^7.20.0", | ||
"eslint-plugin-react-hooks": "^4.0.4", | ||
"husky": "^4.2.5", | ||
"jest": "^26.0.1", | ||
"lint-staged": "^10.2.6", | ||
"prettier": "^2.0.5", | ||
"react": "^16.12.0", | ||
"react-dom": "^16.12.0", | ||
"react-test-renderer": "^16.12.0", | ||
"rimraf": "^2.6.3", | ||
"ts-jest": "^26.0.0", | ||
"typescript": "^3.9.3" | ||
"@testing-library/jest-dom": "latest", | ||
"@testing-library/react": "latest", | ||
"@testing-library/react-hooks": "latest", | ||
"@testing-library/user-event": "latest", | ||
"@types/jest": "latest", | ||
"@types/react": "latest", | ||
"@types/react-dom": "latest", | ||
"babel-jest": "latest", | ||
"eslint": "latest", | ||
"eslint-config-lunde": "latest", | ||
"husky": "latest", | ||
"jest": "latest", | ||
"lint-staged": "latest", | ||
"lundle": "latest", | ||
"prettier": "latest", | ||
"react": "latest", | ||
"react-dom": "latest", | ||
"react-test-renderer": "latest", | ||
"typescript": "latest" | ||
}, | ||
"dependencies": { | ||
"@react-hook/passive-layout-effect": "^1.0.3", | ||
"intersection-observer": "^0.7.0" | ||
"@react-hook/passive-layout-effect": "^1.2.0", | ||
"intersection-observer": "^0.10.0" | ||
}, | ||
@@ -104,0 +136,0 @@ "peerDependencies": { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
86696
19
12
361
1
1
+ Addedintersection-observer@0.10.0(transitive)
- Removedintersection-observer@0.7.0(transitive)