@mr-scroll/react
Advanced tools
Comparing version 0.1.4 to 0.1.5
@@ -1,2 +0,2 @@ | ||
import { ScrollMode, ScrollPosition, ScrollState } from '@mr-scroll/core'; | ||
import { Scroll, ScrollMode, ScrollPosition, ScrollState } from '@mr-scroll/core'; | ||
import React from 'react'; | ||
@@ -30,2 +30,3 @@ interface Props { | ||
constructor(props: Props); | ||
get scroll(): Scroll; | ||
componentDidMount(): void; | ||
@@ -32,0 +33,0 @@ componentWillUnmount(): void; |
@@ -6,2 +6,18 @@ function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } | ||
function _defineProperties(target, props) { | ||
for (var i = 0; i < props.length; i++) { | ||
var descriptor = props[i]; | ||
descriptor.enumerable = descriptor.enumerable || false; | ||
descriptor.configurable = true; | ||
if ("value" in descriptor) descriptor.writable = true; | ||
Object.defineProperty(target, descriptor.key, descriptor); | ||
} | ||
} | ||
function _createClass(Constructor, protoProps, staticProps) { | ||
if (protoProps) _defineProperties(Constructor.prototype, protoProps); | ||
if (staticProps) _defineProperties(Constructor, staticProps); | ||
return Constructor; | ||
} | ||
function _inheritsLoose(subClass, superClass) { | ||
@@ -85,2 +101,9 @@ subClass.prototype = Object.create(superClass.prototype); | ||
_createClass(ScrollComponent, [{ | ||
key: "scroll", | ||
get: function get() { | ||
return this._scroll; | ||
} | ||
}]); | ||
return ScrollComponent; | ||
@@ -87,0 +110,0 @@ }(React.Component); |
import { Scroll } from '@mr-scroll/core'; | ||
import React from 'react'; | ||
class ScrollComponent extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
this._hostRef = React.createRef(); | ||
this._contentRef = React.createRef(); | ||
function _defineProperties(target, props) { | ||
for (var i = 0; i < props.length; i++) { | ||
var descriptor = props[i]; | ||
descriptor.enumerable = descriptor.enumerable || false; | ||
descriptor.configurable = true; | ||
if ("value" in descriptor) descriptor.writable = true; | ||
Object.defineProperty(target, descriptor.key, descriptor); | ||
} | ||
} | ||
componentDidMount() { | ||
this._scroll = new Scroll(() => this._hostRef.current, () => this._contentRef.current, { | ||
function _createClass(Constructor, protoProps, staticProps) { | ||
if (protoProps) _defineProperties(Constructor.prototype, protoProps); | ||
if (staticProps) _defineProperties(Constructor, staticProps); | ||
return Constructor; | ||
} | ||
function _inheritsLoose(subClass, superClass) { | ||
subClass.prototype = Object.create(superClass.prototype); | ||
subClass.prototype.constructor = subClass; | ||
_setPrototypeOf(subClass, superClass); | ||
} | ||
function _setPrototypeOf(o, p) { | ||
_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { | ||
o.__proto__ = p; | ||
return o; | ||
}; | ||
return _setPrototypeOf(o, p); | ||
} | ||
var ScrollComponent = /*#__PURE__*/function (_React$Component) { | ||
_inheritsLoose(ScrollComponent, _React$Component); | ||
function ScrollComponent(props) { | ||
var _this; | ||
_this = _React$Component.call(this, props) || this; | ||
_this._hostRef = React.createRef(); | ||
_this._contentRef = React.createRef(); | ||
return _this; | ||
} | ||
var _proto = ScrollComponent.prototype; | ||
_proto.componentDidMount = function componentDidMount() { | ||
var _this2 = this; | ||
this._scroll = new Scroll(function () { | ||
return _this2._hostRef.current; | ||
}, function () { | ||
return _this2._contentRef.current; | ||
}, { | ||
mode: this.props.mode, | ||
@@ -20,8 +65,10 @@ topThreshold: this.props.topThreshold, | ||
}); | ||
const delegatedEvents = ['scrolled', 'topReached', 'bottomReached', 'leftReached', 'rightReached', 'positionHChanged', 'positionAbsoluteHChanged', 'stateHChanged', 'positionVChanged', 'positionAbsoluteVChanged', 'stateVChanged']; | ||
var delegatedEvents = ['scrolled', 'topReached', 'bottomReached', 'leftReached', 'rightReached', 'positionHChanged', 'positionAbsoluteHChanged', 'stateHChanged', 'positionVChanged', 'positionAbsoluteVChanged', 'stateVChanged']; | ||
for (const eventName of delegatedEvents) { | ||
this._scroll[eventName].subscribe(x => { | ||
const handler = this.props[eventName]; | ||
var _loop = function _loop() { | ||
var eventName = _delegatedEvents[_i]; | ||
_this2._scroll[eventName].subscribe(function (x) { | ||
var handler = _this2.props[eventName]; | ||
if (handler) { | ||
@@ -31,12 +78,16 @@ handler(x); | ||
}); | ||
}; | ||
for (var _i = 0, _delegatedEvents = delegatedEvents; _i < _delegatedEvents.length; _i++) { | ||
_loop(); | ||
} | ||
this._scroll.initialize(); | ||
} | ||
}; | ||
componentWillUnmount() { | ||
_proto.componentWillUnmount = function componentWillUnmount() { | ||
this._scroll.destroy(); | ||
} | ||
}; | ||
render() { | ||
_proto.render = function render() { | ||
return React.createElement("div", { | ||
@@ -47,7 +98,15 @@ ref: this._hostRef | ||
}, this.props.children)); | ||
} | ||
}; | ||
} | ||
_createClass(ScrollComponent, [{ | ||
key: "scroll", | ||
get: function get() { | ||
return this._scroll; | ||
} | ||
}]); | ||
return ScrollComponent; | ||
}(React.Component); | ||
export default ScrollComponent; | ||
//# sourceMappingURL=index.modern.js.map |
{ | ||
"name": "@mr-scroll/react", | ||
"description": "The best custom scroll for the web. This is the react wrapper.", | ||
"version": "0.1.4", | ||
"version": "0.1.5", | ||
"main": "dist/index.js", | ||
"module": "dist/index.modern.js", | ||
"types": "dist/index.d.ts", | ||
"source": "src/index.tsx", | ||
"engines": { | ||
@@ -13,4 +12,5 @@ "node": ">=10" | ||
"scripts": { | ||
"start": "microbundle-crl watch --no-compress --format modern,cjs", | ||
"build": "microbundle-crl --no-compress --format modern,cjs", | ||
"start": "microbundle-crl watch --no-compress --format modern,cjs" | ||
"prepublishOnly": "npm run build" | ||
}, | ||
@@ -44,3 +44,3 @@ "keywords": [ | ||
"devDependencies": { | ||
"@mr-scroll/core": "^0.1.4", | ||
"@mr-scroll/core": "^0.1.5", | ||
"@testing-library/jest-dom": "^4.2.4", | ||
@@ -68,3 +68,3 @@ "@testing-library/react": "^9.5.0", | ||
"gh-pages": "^2.2.0", | ||
"microbundle-crl": "^0.13.10", | ||
"microbundle-crl": "^0.13.11", | ||
"npm-run-all": "^4.1.5", | ||
@@ -77,3 +77,3 @@ "prettier": "^2.0.4", | ||
}, | ||
"gitHead": "4bcec5f6f4fdf0844dbb4c13b384a1744ae08b09" | ||
"gitHead": "f289f23e3f3acc15e9ef72d9d14fc4aa5f472c42" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
20227
219