@nosferatu500/react-dnd-scrollzone
Advanced tools
Comparing version 2.0.10 to 3.0.0-alpha.0
@@ -1,2 +0,2 @@ | ||
import hoist from 'hoist-non-react-statics'; | ||
/// <reference types="react" /> | ||
export declare type Point = { | ||
@@ -14,6 +14,4 @@ x: number; | ||
export declare const createVerticalStrength: (_buffer: number) => ({ y, h, x, w }: Size, point: Point) => number; | ||
export declare const defaultHorizontalStrength: ({ x, w, y, h }: Size, point: Point) => number; | ||
export declare const defaultVerticalStrength: ({ y, h, x, w }: Size, point: Point) => number; | ||
export declare const createScrollingComponent: (WrappedComponent: any) => ((props: any) => JSX.Element) & hoist.NonReactStatics<any, {}>; | ||
export declare const createScrollingComponent: (WrappedComponent: any) => (props: any) => JSX.Element; | ||
declare const createScrollingComponentWithConsumer: (WrappedComponent: any) => (props: any) => JSX.Element; | ||
export default createScrollingComponentWithConsumer; |
import React, { createRef, useEffect } from 'react'; | ||
import hoist from 'hoist-non-react-statics'; | ||
import throttle from 'lodash.throttle'; | ||
@@ -78,12 +77,10 @@ import { DndContext } from 'react-dnd'; | ||
}; | ||
const defaultHorizontalStrength = createHorizontalStrength(DEFAULT_BUFFER); | ||
const defaultVerticalStrength = createVerticalStrength(DEFAULT_BUFFER); | ||
const defaultProps = { | ||
onScrollChange: noop, | ||
verticalStrength: defaultVerticalStrength, | ||
horizontalStrength: defaultHorizontalStrength, | ||
verticalStrength: createVerticalStrength(DEFAULT_BUFFER), | ||
horizontalStrength: createHorizontalStrength(DEFAULT_BUFFER), | ||
strengthMultiplier: 30 | ||
}; | ||
const createScrollingComponent = (WrappedComponent) => { | ||
const ScrollingComponent = (props) => { | ||
return (props) => { | ||
props = __spreadValues(__spreadValues({}, defaultProps), props); | ||
@@ -117,2 +114,10 @@ let container; | ||
}, 100, { trailing: false }); | ||
const handleEvent = (evt) => { | ||
if (dragging && !attached) { | ||
attached = true; | ||
window.document.body.addEventListener("dragover", updateScrolling); | ||
window.document.body.addEventListener("touchmove", updateScrolling); | ||
updateScrolling(evt); | ||
} | ||
}; | ||
useEffect(() => { | ||
@@ -124,3 +129,3 @@ container = wrappedInstance.current; | ||
window.document.body.addEventListener("touchmove", handleEvent); | ||
const clearMonitorSubscription = props.dragDropManager.getMonitor().subscribeToStateChange(() => handleMonitorChange()); | ||
const clearMonitorSubscription = props.dragDropManager.getMonitor().subscribeToStateChange(handleMonitorChange); | ||
return () => { | ||
@@ -135,8 +140,2 @@ if (container && typeof container.removeEventListener === "function") { | ||
}, []); | ||
const handleEvent = (evt) => { | ||
if (dragging && !attached) { | ||
attach(); | ||
updateScrolling(evt); | ||
} | ||
}; | ||
const handleMonitorChange = () => { | ||
@@ -151,12 +150,2 @@ const isDragging = props.dragDropManager.getMonitor().isDragging(); | ||
}; | ||
const attach = () => { | ||
attached = true; | ||
window.document.body.addEventListener("dragover", updateScrolling); | ||
window.document.body.addEventListener("touchmove", updateScrolling); | ||
}; | ||
const detach = () => { | ||
attached = false; | ||
window.document.body.removeEventListener("dragover", updateScrolling); | ||
window.document.body.removeEventListener("touchmove", updateScrolling); | ||
}; | ||
const startScrolling = () => { | ||
@@ -188,3 +177,5 @@ let i = 0; | ||
const stopScrolling = () => { | ||
detach(); | ||
attached = false; | ||
window.document.body.removeEventListener("dragover", updateScrolling); | ||
window.document.body.removeEventListener("touchmove", updateScrolling); | ||
scaleX = 0; | ||
@@ -207,3 +198,2 @@ scaleY = 0; | ||
}; | ||
return hoist(ScrollingComponent, WrappedComponent); | ||
}; | ||
@@ -213,3 +203,3 @@ const createScrollingComponentWithConsumer = (WrappedComponent) => { | ||
return (props) => { | ||
return /* @__PURE__ */ React.createElement(DndContext.Consumer, null, ({ dragDropManager }) => dragDropManager === void 0 ? void 0 : /* @__PURE__ */ React.createElement(ScrollingComponent, __spreadProps(__spreadValues({}, props), { | ||
return /* @__PURE__ */ React.createElement(DndContext.Consumer, null, ({ dragDropManager }) => !dragDropManager ? void 0 : /* @__PURE__ */ React.createElement(ScrollingComponent, __spreadProps(__spreadValues({}, props), { | ||
dragDropManager | ||
@@ -220,2 +210,2 @@ }))); | ||
export { createHorizontalStrength, createScrollingComponent, createVerticalStrength, createScrollingComponentWithConsumer as default, defaultHorizontalStrength, defaultVerticalStrength }; | ||
export { createHorizontalStrength, createScrollingComponent, createVerticalStrength, createScrollingComponentWithConsumer as default }; |
@@ -1,2 +0,2 @@ | ||
import hoist from 'hoist-non-react-statics'; | ||
/// <reference types="react" /> | ||
export declare type Point = { | ||
@@ -14,6 +14,4 @@ x: number; | ||
export declare const createVerticalStrength: (_buffer: number) => ({ y, h, x, w }: Size, point: Point) => number; | ||
export declare const defaultHorizontalStrength: ({ x, w, y, h }: Size, point: Point) => number; | ||
export declare const defaultVerticalStrength: ({ y, h, x, w }: Size, point: Point) => number; | ||
export declare const createScrollingComponent: (WrappedComponent: any) => ((props: any) => JSX.Element) & hoist.NonReactStatics<any, {}>; | ||
export declare const createScrollingComponent: (WrappedComponent: any) => (props: any) => JSX.Element; | ||
declare const createScrollingComponentWithConsumer: (WrappedComponent: any) => (props: any) => JSX.Element; | ||
export default createScrollingComponentWithConsumer; |
51
index.js
@@ -7,3 +7,2 @@ 'use strict'; | ||
var react = require('react'); | ||
var hoist = require('hoist-non-react-statics'); | ||
var throttle = require('lodash.throttle'); | ||
@@ -14,3 +13,2 @@ var reactDnd = require('react-dnd'); | ||
var hoist__default = /*#__PURE__*/_interopDefaultLegacy(hoist); | ||
var throttle__default = /*#__PURE__*/_interopDefaultLegacy(throttle); | ||
@@ -81,12 +79,10 @@ | ||
}; | ||
const defaultHorizontalStrength = createHorizontalStrength(DEFAULT_BUFFER); | ||
const defaultVerticalStrength = createVerticalStrength(DEFAULT_BUFFER); | ||
const defaultProps = { | ||
onScrollChange: noop, | ||
verticalStrength: defaultVerticalStrength, | ||
horizontalStrength: defaultHorizontalStrength, | ||
verticalStrength: createVerticalStrength(DEFAULT_BUFFER), | ||
horizontalStrength: createHorizontalStrength(DEFAULT_BUFFER), | ||
strengthMultiplier: 30 | ||
}; | ||
const createScrollingComponent = WrappedComponent => { | ||
const ScrollingComponent = props => { | ||
return props => { | ||
props = { ...defaultProps, | ||
@@ -125,2 +121,12 @@ ...props | ||
}); | ||
const handleEvent = evt => { | ||
if (dragging && !attached) { | ||
attached = true; | ||
window.document.body.addEventListener('dragover', updateScrolling); | ||
window.document.body.addEventListener('touchmove', updateScrolling); | ||
updateScrolling(evt); | ||
} | ||
}; | ||
react.useEffect(() => { | ||
@@ -134,3 +140,3 @@ container = wrappedInstance.current; | ||
window.document.body.addEventListener('touchmove', handleEvent); | ||
const clearMonitorSubscription = props.dragDropManager.getMonitor().subscribeToStateChange(() => handleMonitorChange()); | ||
const clearMonitorSubscription = props.dragDropManager.getMonitor().subscribeToStateChange(handleMonitorChange); | ||
return () => { | ||
@@ -147,9 +153,2 @@ if (container && typeof container.removeEventListener === 'function') { | ||
const handleEvent = evt => { | ||
if (dragging && !attached) { | ||
attach(); | ||
updateScrolling(evt); | ||
} | ||
}; | ||
const handleMonitorChange = () => { | ||
@@ -166,14 +165,2 @@ const isDragging = props.dragDropManager.getMonitor().isDragging(); | ||
const attach = () => { | ||
attached = true; | ||
window.document.body.addEventListener('dragover', updateScrolling); | ||
window.document.body.addEventListener('touchmove', updateScrolling); | ||
}; | ||
const detach = () => { | ||
attached = false; | ||
window.document.body.removeEventListener('dragover', updateScrolling); | ||
window.document.body.removeEventListener('touchmove', updateScrolling); | ||
}; | ||
const startScrolling = () => { | ||
@@ -211,3 +198,5 @@ let i = 0; | ||
const stopScrolling = () => { | ||
detach(); | ||
attached = false; | ||
window.document.body.removeEventListener('dragover', updateScrolling); | ||
window.document.body.removeEventListener('touchmove', updateScrolling); | ||
scaleX = 0; | ||
@@ -234,4 +223,2 @@ scaleY = 0; | ||
}; | ||
return hoist__default["default"](ScrollingComponent, WrappedComponent); | ||
}; | ||
@@ -245,3 +232,3 @@ | ||
dragDropManager | ||
}) => dragDropManager === undefined ? undefined : jsxRuntime.jsx(ScrollingComponent, { ...props, | ||
}) => !dragDropManager ? undefined : jsxRuntime.jsx(ScrollingComponent, { ...props, | ||
dragDropManager: dragDropManager | ||
@@ -257,3 +244,1 @@ }) | ||
exports["default"] = createScrollingComponentWithConsumer; | ||
exports.defaultHorizontalStrength = defaultHorizontalStrength; | ||
exports.defaultVerticalStrength = defaultVerticalStrength; |
{ | ||
"name": "@nosferatu500/react-dnd-scrollzone", | ||
"version": "2.0.10", | ||
"version": "3.0.0-alpha.0", | ||
"description": "A cross browser solution to scrolling during drag and drop.", | ||
@@ -47,3 +47,2 @@ "main": "./index.js", | ||
"dependencies": { | ||
"hoist-non-react-statics": "^3.3.2", | ||
"lodash.throttle": "^4.1.1" | ||
@@ -53,3 +52,3 @@ }, | ||
"react": ">=17.0.2", | ||
"react-dnd": "14.0.4", | ||
"react-dnd": ">=15.1.2", | ||
"react-dom": ">=17.0.2" | ||
@@ -56,0 +55,0 @@ }, |
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
4
29974
631
2
+ Added@react-dnd/asap@5.0.2(transitive)
+ Added@react-dnd/invariant@4.0.2(transitive)
+ Added@react-dnd/shallowequal@4.0.2(transitive)
+ Addeddnd-core@16.0.1(transitive)
+ Addedreact-dnd@16.0.1(transitive)
- Removedhoist-non-react-statics@^3.3.2
- Removed@react-dnd/asap@4.0.1(transitive)
- Removed@react-dnd/invariant@2.0.0(transitive)
- Removed@react-dnd/shallowequal@2.0.0(transitive)
- Removeddnd-core@14.0.1(transitive)
- Removedreact-dnd@14.0.4(transitive)