@n8tb1t/use-scroll-position
Advanced tools
Comparing version 1.0.46 to 1.0.47
@@ -0,1 +1,7 @@ | ||
#### 1.0.47 (2020-09-15) | ||
##### Bug Fixes | ||
* **build:** fix build ([28f8743a](https://github.com/n8tb1t/use-scroll-position/commit/28f8743a444176c32e56459d955c945978cf298e)) | ||
#### 1.0.46 (2020-09-13) | ||
@@ -2,0 +8,0 @@ |
@@ -1,1 +0,4 @@ | ||
export { useScrollPosition } from './useScrollPosition'; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var useScrollPosition_1 = require("./useScrollPosition"); | ||
Object.defineProperty(exports, "useScrollPosition", { enumerable: true, get: function () { return useScrollPosition_1.useScrollPosition; } }); |
@@ -1,2 +0,5 @@ | ||
import { useLayoutEffect, useEffect } from 'react'; | ||
export var useIsomorphicLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.useIsomorphicLayoutEffect = void 0; | ||
const react_1 = require("react"); | ||
exports.useIsomorphicLayoutEffect = typeof window !== 'undefined' ? react_1.useLayoutEffect : react_1.useEffect; |
@@ -1,8 +0,10 @@ | ||
import { useRef } from 'react'; | ||
import { useIsomorphicLayoutEffect } from './useIsomorphicLayoutEffect'; | ||
var isBrowser = typeof window !== "undefined"; | ||
var zeroPosition = { x: 0, y: 0 }; | ||
var getClientRect = function (element) { return element === null || element === void 0 ? void 0 : element.getBoundingClientRect(); }; | ||
var getScrollPosition = function (_a) { | ||
var element = _a.element, useWindow = _a.useWindow, boundingElement = _a.boundingElement; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.useScrollPosition = void 0; | ||
const react_1 = require("react"); | ||
const useIsomorphicLayoutEffect_1 = require("./useIsomorphicLayoutEffect"); | ||
const isBrowser = typeof window !== `undefined`; | ||
const zeroPosition = { x: 0, y: 0 }; | ||
const getClientRect = (element) => element === null || element === void 0 ? void 0 : element.getBoundingClientRect(); | ||
const getScrollPosition = ({ element, useWindow, boundingElement, }) => { | ||
if (!isBrowser) { | ||
@@ -14,4 +16,4 @@ return zeroPosition; | ||
} | ||
var targetPosition = getClientRect((element === null || element === void 0 ? void 0 : element.current) || document.body); | ||
var containerPosition = getClientRect(boundingElement === null || boundingElement === void 0 ? void 0 : boundingElement.current); | ||
const targetPosition = getClientRect((element === null || element === void 0 ? void 0 : element.current) || document.body); | ||
const containerPosition = getClientRect(boundingElement === null || boundingElement === void 0 ? void 0 : boundingElement.current); | ||
if (!targetPosition) { | ||
@@ -27,12 +29,12 @@ return zeroPosition; | ||
}; | ||
export var useScrollPosition = function (effect, deps, element, useWindow, wait, boundingElement) { | ||
var position = useRef(getScrollPosition({ useWindow: useWindow, boundingElement: boundingElement })); | ||
var throttleTimeout = null; | ||
var callBack = function () { | ||
var currPos = getScrollPosition({ element: element, useWindow: useWindow, boundingElement: boundingElement }); | ||
effect({ prevPos: position.current, currPos: currPos }); | ||
exports.useScrollPosition = (effect, deps, element, useWindow, wait, boundingElement) => { | ||
const position = react_1.useRef(getScrollPosition({ useWindow, boundingElement })); | ||
let throttleTimeout = null; | ||
const callBack = () => { | ||
const currPos = getScrollPosition({ element, useWindow, boundingElement }); | ||
effect({ prevPos: position.current, currPos }); | ||
position.current = currPos; | ||
throttleTimeout = null; | ||
}; | ||
useIsomorphicLayoutEffect(function () { | ||
useIsomorphicLayoutEffect_1.useIsomorphicLayoutEffect(() => { | ||
var _a; | ||
@@ -42,3 +44,3 @@ if (!isBrowser) { | ||
} | ||
var handleScroll = function () { | ||
const handleScroll = () => { | ||
if (wait) { | ||
@@ -59,3 +61,3 @@ if (throttleTimeout === null) { | ||
} | ||
return function () { | ||
return () => { | ||
var _a; | ||
@@ -74,3 +76,3 @@ if (boundingElement) { | ||
}; | ||
useScrollPosition.defaultProps = { | ||
exports.useScrollPosition.defaultProps = { | ||
deps: [], | ||
@@ -77,0 +79,0 @@ element: false, |
{ | ||
"name": "@n8tb1t/use-scroll-position", | ||
"version": "1.0.46", | ||
"version": "1.0.47", | ||
"author": "n8tb1t <n8tb1t@gmail.com>", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
{ | ||
"compilerOptions": { | ||
"target": "es5", | ||
"module": "esnext", | ||
"target": "ES2015", | ||
"module": "commonjs", | ||
"moduleResolution": "node", | ||
@@ -6,0 +6,0 @@ "declaration": true, |
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
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
285107
6761