react-scroll-ondrag
Advanced tools
Comparing version
@@ -1,31 +0,23 @@ | ||
import { useRef, useCallback, useEffect } from 'react'; | ||
import { useEffect, useRef, useCallback } from 'react'; | ||
import invariant from 'tiny-invariant'; | ||
var maxHorizontalScroll = function maxHorizontalScroll(dom) { | ||
return dom.scrollWidth - dom.clientWidth; | ||
}; | ||
const maxHorizontalScroll = dom => dom.scrollWidth - dom.clientWidth; | ||
var maxVerticalScroll = function maxVerticalScroll(dom) { | ||
return dom.scrollHeight - dom.clientHeight; | ||
}; | ||
const maxVerticalScroll = dom => dom.scrollHeight - dom.clientHeight; | ||
var index = (function (domRef) { | ||
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, | ||
_ref$onDragStart = _ref.onDragStart, | ||
onDragStart = _ref$onDragStart === void 0 ? function () {} : _ref$onDragStart, | ||
_ref$onDragEnd = _ref.onDragEnd, | ||
onDragEnd = _ref$onDragEnd === void 0 ? function () {} : _ref$onDragEnd, | ||
_ref$runScroll = _ref.runScroll, | ||
runScroll = _ref$runScroll === void 0 ? function (_ref2) { | ||
var dx = _ref2.dx, | ||
dy = _ref2.dy; | ||
var offsetX = Math.min(maxHorizontalScroll(domRef.current), domRef.current.scrollLeft + dx); | ||
export default ((domRef, { | ||
onDragStart = () => {}, | ||
onDragEnd = () => {}, | ||
runScroll = ({ | ||
dx, | ||
dy | ||
}) => { | ||
const offsetX = Math.min(maxHorizontalScroll(domRef.current), domRef.current.scrollLeft + dx); | ||
domRef.current.scrollLeft = offsetX; // eslint-disable-line no-param-reassign | ||
// eslint-disable-line no-param-reassign | ||
var offsetY = Math.min(maxVerticalScroll(domRef.current), domRef.current.scrollTop + dy); | ||
const offsetY = Math.min(maxVerticalScroll(domRef.current), domRef.current.scrollTop + dy); | ||
domRef.current.scrollTop = offsetY; // eslint-disable-line no-param-reassign | ||
} : _ref$runScroll; | ||
var internalState = useRef({ | ||
} | ||
} = {}) => { | ||
const internalState = useRef({ | ||
lastMouseX: null, | ||
@@ -36,12 +28,14 @@ lastMouseY: null, | ||
}); | ||
var scroll = useCallback(function (_ref3) { | ||
var dx = _ref3.dx, | ||
dy = _ref3.dy; | ||
!(domRef.current !== null) ? process.env.NODE_ENV !== "production" ? invariant(false, "Trying to scroll to the bottom, but no element was found.\n Did you call this scrollBottom before the component with this hook finished mounting?") : invariant(false) : void 0; | ||
const scroll = useCallback(({ | ||
dx, | ||
dy | ||
}) => { | ||
!(domRef.current !== null) ? process.env.NODE_ENV !== "production" ? invariant(false, `Trying to scroll to the bottom, but no element was found. | ||
Did you call this scrollBottom before the component with this hook finished mounting?`) : invariant(false) : void 0; | ||
runScroll({ | ||
dx: dx, | ||
dy: dy | ||
dx, | ||
dy | ||
}); | ||
}, [runScroll]); | ||
var onMouseDown = useCallback(function (e) { | ||
const onMouseDown = useCallback(e => { | ||
internalState.current.isMouseDown = true; | ||
@@ -52,3 +46,3 @@ internalState.current.lastMouseX = e.clientX; | ||
var onMouseUp = function onMouseUp() { | ||
const onMouseUp = () => { | ||
internalState.current.isMouseDown = false; | ||
@@ -64,3 +58,3 @@ internalState.current.lastMouseX = null; | ||
var onMouseMove = function onMouseMove(e) { | ||
const onMouseMove = e => { | ||
if (!internalState.current.isMouseDown) { | ||
@@ -76,16 +70,16 @@ return; | ||
var dx = -(e.clientX - internalState.current.lastMouseX); | ||
var dy = -(e.clientY - internalState.current.lastMouseY); | ||
const dx = -(e.clientX - internalState.current.lastMouseX); | ||
const dy = -(e.clientY - internalState.current.lastMouseY); | ||
internalState.current.lastMouseX = e.clientX; | ||
internalState.current.lastMouseY = e.clientY; | ||
scroll({ | ||
dx: dx, | ||
dy: dy | ||
dx, | ||
dy | ||
}); | ||
}; | ||
useEffect(function () { | ||
useEffect(() => { | ||
window.addEventListener('mouseup', onMouseUp); | ||
window.addEventListener('mousemove', onMouseMove); | ||
return function () { | ||
return () => { | ||
window.removeEventListener('mouseup', onMouseUp); | ||
@@ -97,7 +91,6 @@ window.removeEventListener('mousemove', onMouseMove); | ||
events: { | ||
onMouseDown: onMouseDown | ||
onMouseDown | ||
} | ||
}; | ||
}); | ||
export { index as default }; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "react-scroll-ondrag", | ||
"version": "2.1.0", | ||
"version": "3.0.0", | ||
"description": "React library for scrolling elements by dragging the mouse", | ||
"main": "dist/index.cjs", | ||
"main": "dist/index.js", | ||
"module": "dist/index.js", | ||
"type": "module", | ||
"engines": { | ||
"node": ">=12.2" | ||
"node": ">=14.0.0" | ||
}, | ||
"exports": { | ||
".": { | ||
"import": "./dist/index.js", | ||
"require": "./dist/index.cjs" | ||
} | ||
".": "./dist/index.js", | ||
"./package.json": "./package.json" | ||
}, | ||
@@ -21,3 +19,3 @@ "scripts": { | ||
"tdd": "karma start karma.conf.cjs", | ||
"build": "rollup -c", | ||
"build": "babel src -s -d dist", | ||
"prepare": "npm run build" | ||
@@ -49,38 +47,40 @@ }, | ||
"devDependencies": { | ||
"@babel/core": "^7.16.0", | ||
"@babel/preset-env": "^7.16.0", | ||
"@babel/preset-react": "^7.16.0", | ||
"@rollup/plugin-babel": "^5.3.0", | ||
"@rollup/plugin-commonjs": "^21.0.1", | ||
"@rollup/plugin-node-resolve": "^13.0.6", | ||
"@rollup/plugin-replace": "^3.0.0", | ||
"@babel/cli": "^7.17.10", | ||
"@babel/core": "^7.18.2", | ||
"@babel/preset-react": "^7.17.12", | ||
"@rollup/plugin-alias": "^3.1.9", | ||
"@rollup/plugin-babel": "^5.3.1", | ||
"@rollup/plugin-commonjs": "^22.0.0", | ||
"@rollup/plugin-node-resolve": "^13.3.0", | ||
"@rollup/plugin-replace": "^4.0.0", | ||
"babel-plugin-dev-expression": "^0.2.3", | ||
"babel-plugin-istanbul": "^6.1.1", | ||
"chai": "^4.3.4", | ||
"chai": "^4.3.6", | ||
"dirty-chai": "^2.0.1", | ||
"eslint": "^7.32.0", | ||
"eslint-config-airbnb": "^18.2.1", | ||
"eslint-plugin-import": "^2.25.2", | ||
"eslint-plugin-jsx-a11y": "^6.4.1", | ||
"eslint-plugin-mocha": "^9.0.0", | ||
"eslint-plugin-react": "^7.26.1", | ||
"eslint-plugin-react-hooks": "^4.2.0", | ||
"karma": "^6.3.7", | ||
"karma-chrome-launcher": "^3.1.0", | ||
"karma-coverage": "^2.0.3", | ||
"eslint": "^8.16.0", | ||
"eslint-config-airbnb": "^19.0.4", | ||
"eslint-plugin-eslint-comments": "^3.2.0", | ||
"eslint-plugin-import": "^2.26.0", | ||
"eslint-plugin-jsx-a11y": "^6.5.1", | ||
"eslint-plugin-mocha": "^10.0.5", | ||
"eslint-plugin-react": "^7.30.0", | ||
"eslint-plugin-react-hooks": "^4.5.0", | ||
"eslint-plugin-unicorn": "^42.0.0", | ||
"karma": "^6.3.20", | ||
"karma-chrome-launcher": "^3.1.1", | ||
"karma-coverage": "^2.2.0", | ||
"karma-coveralls": "^2.1.0", | ||
"karma-firefox-launcher": "^2.1.2", | ||
"karma-mocha": "^2.0.1", | ||
"karma-rollup-preprocessor": "^7.0.7", | ||
"karma-rollup-preprocessor": "^7.0.8", | ||
"karma-sourcemap-loader": "^0.3.8", | ||
"karma-spec-reporter": "0.0.32", | ||
"mocha": "^9.1.3", | ||
"puppeteer": "^11.0.0", | ||
"react": "^17.0.2", | ||
"react-dom": "^17.0.2", | ||
"rollup": "^2.59.0", | ||
"rollup-plugin-terser": "^7.0.2", | ||
"sinon": "^12.0.1", | ||
"karma-spec-reporter": "0.0.34", | ||
"mocha": "^10.0.0", | ||
"puppeteer": "^14.1.1", | ||
"react": "^18.1.0", | ||
"react-dom": "^18.1.0", | ||
"rollup": "^2.75.3", | ||
"sinon": "^14.0.0", | ||
"sinon-chai": "^3.7.0", | ||
"styled-components": "^5.3.3" | ||
"styled-components": "^5.3.5" | ||
}, | ||
@@ -87,0 +87,0 @@ "dependencies": { |
@@ -6,4 +6,2 @@ # react-scroll-ondrag | ||
[![Coverage Status][coveralls-badge]][coveralls] | ||
[![Dependency Status][dependency-status-badge]][dependency-status] | ||
[![devDependency Status][dev-dependency-status-badge]][dev-dependency-status] | ||
@@ -110,7 +108,1 @@ > Scroll your elements by dragging your mouse | ||
[coveralls]: https://coveralls.io/r/dotcore64/react-scroll-ondrag | ||
[dependency-status-badge]: https://david-dm.org/dotcore64/react-scroll-ondrag.svg?style=flat-square | ||
[dependency-status]: https://david-dm.org/dotcore64/react-scroll-ondrag | ||
[dev-dependency-status-badge]: https://david-dm.org/dotcore64/react-scroll-ondrag/dev-status.svg?style=flat-square | ||
[dev-dependency-status]: https://david-dm.org/dotcore64/react-scroll-ondrag#info=devDependencies |
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
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
0
-100%1
-75%14612
-6.38%38
5.56%5
-16.67%79
-57.07%107
-6.96%