Skip to content

Commit 766a51b

Browse files
author
Eugene Musika
committed
Remove dist from ignore for direct gihub link download with npm
1 parent efc7f26 commit 766a51b

File tree

9 files changed

+545
-21
lines changed

9 files changed

+545
-21
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,4 @@ yarn-error.log*
99

1010
# build
1111
node_modules
12-
dist
1312
examples/dist

dist/ScrollLock.js

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
'use strict';
2+
3+
Object.defineProperty(exports, "__esModule", {
4+
value: true
5+
});
6+
7+
var _createClass = function () { 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); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
8+
9+
var _react = require('react');
10+
11+
var _react2 = _interopRequireDefault(_react);
12+
13+
var _exenv = require('exenv');
14+
15+
var _TouchScrollable = require('./TouchScrollable');
16+
17+
var _withLockSheet = require('./withLockSheet');
18+
19+
var _withLockSheet2 = _interopRequireDefault(_withLockSheet);
20+
21+
var _withTouchListeners = require('./withTouchListeners');
22+
23+
var _withTouchListeners2 = _interopRequireDefault(_withTouchListeners);
24+
25+
var _utils = require('./utils');
26+
27+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
28+
29+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
30+
31+
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
32+
33+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
34+
35+
var ScrollLock = function (_PureComponent) {
36+
_inherits(ScrollLock, _PureComponent);
37+
38+
function ScrollLock() {
39+
_classCallCheck(this, ScrollLock);
40+
41+
return _possibleConstructorReturn(this, (ScrollLock.__proto__ || Object.getPrototypeOf(ScrollLock)).apply(this, arguments));
42+
}
43+
44+
_createClass(ScrollLock, [{
45+
key: 'componentDidMount',
46+
value: function componentDidMount() {
47+
if (!_exenv.canUseDOM) return;
48+
this.initialHeight = window.innerHeight;
49+
}
50+
}, {
51+
key: 'componentWillUnmount',
52+
value: function componentWillUnmount() {
53+
var offset = window.innerHeight - this.initialHeight;
54+
55+
// adjust scroll if the window has been resized since the lock was engaged
56+
// e.g. mobile safari dynamic chrome heights
57+
if (offset) {
58+
window.scrollTo(0, window.pageYOffset + offset);
59+
}
60+
61+
// reset the initial height in case this scroll lock is used again
62+
this.initialHeight = window.innerHeight;
63+
}
64+
}, {
65+
key: 'render',
66+
value: function render() {
67+
var children = this.props.children;
68+
69+
70+
return children ? _react2.default.createElement(
71+
_TouchScrollable.TouchScrollable,
72+
null,
73+
children
74+
) : null;
75+
}
76+
}]);
77+
78+
return ScrollLock;
79+
}(_react.PureComponent);
80+
81+
// attach the stylesheet and inject styles on [un]mount
82+
83+
84+
var compose = (0, _utils.pipe)(_withTouchListeners2.default, _withLockSheet2.default);
85+
var SheetLock = compose(ScrollLock);
86+
87+
// toggle the lock based on `isActive` prop
88+
var LockToggle = function LockToggle(props) {
89+
return props.isActive ? _react2.default.createElement(SheetLock, props) : props.children;
90+
};
91+
92+
LockToggle.defaultProps = {
93+
accountForScrollbars: true,
94+
children: null,
95+
isActive: true
96+
};
97+
98+
exports.default = LockToggle;

dist/TouchScrollable.js

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
'use strict';
2+
3+
Object.defineProperty(exports, "__esModule", {
4+
value: true
5+
});
6+
exports.TouchScrollable = undefined;
7+
8+
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
9+
10+
var _createClass = function () { 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); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
11+
12+
var _react = require('react');
13+
14+
var _exenv = require('exenv');
15+
16+
var _utils = require('./utils');
17+
18+
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
19+
20+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
21+
22+
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
23+
24+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
25+
26+
var TouchScrollable = exports.TouchScrollable = function (_PureComponent) {
27+
_inherits(TouchScrollable, _PureComponent);
28+
29+
function TouchScrollable() {
30+
var _ref;
31+
32+
var _temp, _this, _ret;
33+
34+
_classCallCheck(this, TouchScrollable);
35+
36+
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
37+
args[_key] = arguments[_key];
38+
}
39+
40+
return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = TouchScrollable.__proto__ || Object.getPrototypeOf(TouchScrollable)).call.apply(_ref, [this].concat(args))), _this), _this.getScrollableArea = function (ref) {
41+
_this.scrollableArea = ref;
42+
}, _temp), _possibleConstructorReturn(_this, _ret);
43+
}
44+
45+
_createClass(TouchScrollable, [{
46+
key: 'componentDidMount',
47+
value: function componentDidMount() {
48+
if (!_exenv.canUseEventListeners) return;
49+
50+
this.scrollableArea.addEventListener('touchstart', _utils.preventInertiaScroll, _utils.listenerOptions);
51+
this.scrollableArea.addEventListener('touchmove', _utils.allowTouchMove, _utils.listenerOptions);
52+
}
53+
}, {
54+
key: 'componentWillUnmount',
55+
value: function componentWillUnmount() {
56+
if (!_exenv.canUseEventListeners) return;
57+
58+
this.scrollableArea.removeEventListener('touchstart', _utils.preventInertiaScroll, _utils.listenerOptions);
59+
this.scrollableArea.removeEventListener('touchmove', _utils.allowTouchMove, _utils.listenerOptions);
60+
}
61+
}, {
62+
key: 'render',
63+
value: function render() {
64+
var _props = this.props,
65+
children = _props.children,
66+
rest = _objectWithoutProperties(_props, ['children']);
67+
68+
return typeof children === 'function' ? children(this.getScrollableArea) : (0, _react.cloneElement)(children, _extends({ ref: this.getScrollableArea }, rest));
69+
}
70+
}]);
71+
72+
return TouchScrollable;
73+
}(_react.PureComponent);

dist/index.d.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import * as React from 'react';
2+
3+
interface OneChildrenElement {
4+
children?: React.ReactElement;
5+
}
6+
7+
interface ScrollLockProps extends OneChildrenElement {
8+
accountForScrollbars?: boolean;
9+
isActive?: boolean;
10+
}
11+
12+
export default class ScrollLock extends React.Component<ScrollLockProps> {}
13+
14+
export class TouchScrollable extends React.Component<OneChildrenElement> {}

dist/index.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
'use strict';
2+
3+
Object.defineProperty(exports, "__esModule", {
4+
value: true
5+
});
6+
7+
var _ScrollLock = require('./ScrollLock');
8+
9+
Object.defineProperty(exports, 'default', {
10+
enumerable: true,
11+
get: function get() {
12+
return _interopRequireDefault(_ScrollLock).default;
13+
}
14+
});
15+
16+
var _TouchScrollable = require('./TouchScrollable');
17+
18+
Object.defineProperty(exports, 'TouchScrollable', {
19+
enumerable: true,
20+
get: function get() {
21+
return _TouchScrollable.TouchScrollable;
22+
}
23+
});
24+
25+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

dist/utils.js

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
'use strict';
2+
3+
Object.defineProperty(exports, "__esModule", {
4+
value: true
5+
});
6+
exports.pipe = exports.listenerOptions = undefined;
7+
exports.preventTouchMove = preventTouchMove;
8+
exports.allowTouchMove = allowTouchMove;
9+
exports.preventInertiaScroll = preventInertiaScroll;
10+
exports.isTouchDevice = isTouchDevice;
11+
exports.camelToKebab = camelToKebab;
12+
exports.parse = parse;
13+
exports.getPadding = getPadding;
14+
exports.getWindowHeight = getWindowHeight;
15+
exports.getDocumentHeight = getDocumentHeight;
16+
exports.makeStyleTag = makeStyleTag;
17+
exports.injectStyles = injectStyles;
18+
exports.insertStyleTag = insertStyleTag;
19+
20+
var _exenv = require('exenv');
21+
22+
var listenerOptions = exports.listenerOptions = {
23+
capture: false,
24+
passive: false
25+
};
26+
27+
// ==============================
28+
// Touch Helpers
29+
// ==============================
30+
31+
function preventTouchMove(e) {
32+
e.preventDefault();
33+
34+
return false;
35+
}
36+
37+
function allowTouchMove(e) {
38+
var target = e.currentTarget;
39+
40+
if (target.scrollHeight > target.clientHeight || target.scrollWidth > target.clientWidth) {
41+
e.stopPropagation();
42+
return true;
43+
}
44+
45+
e.preventDefault();
46+
return false;
47+
}
48+
49+
function preventInertiaScroll() {
50+
var top = this.scrollTop;
51+
var totalScroll = this.scrollHeight;
52+
var currentScroll = top + this.offsetHeight;
53+
54+
if (top === 0) {
55+
this.scrollTop = 1;
56+
} else if (currentScroll === totalScroll) {
57+
this.scrollTop = top - 1;
58+
}
59+
}
60+
61+
// `ontouchstart` check works on most browsers
62+
// `maxTouchPoints` works on IE10/11 and Surface
63+
function isTouchDevice() {
64+
if (!_exenv.canUseDOM) return false;
65+
return 'ontouchstart' in window || navigator.maxTouchPoints;
66+
}
67+
68+
// ==============================
69+
// Misc.
70+
// ==============================
71+
72+
function camelToKebab(str) {
73+
return str.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
74+
}
75+
76+
function parse(val) {
77+
return isNaN(val) ? val : val + 'px';
78+
}
79+
80+
// Take a list of functions and return a function that applies the list of
81+
// functions from left to right
82+
83+
var pipeFns = function pipeFns(a, b) {
84+
return function () {
85+
return b(a.apply(undefined, arguments));
86+
};
87+
};
88+
var pipe = exports.pipe = function pipe() {
89+
for (var _len = arguments.length, fns = Array(_len), _key = 0; _key < _len; _key++) {
90+
fns[_key] = arguments[_key];
91+
}
92+
93+
return fns.reduce(pipeFns);
94+
};
95+
96+
// ==============================
97+
// Document Helpers
98+
// ==============================
99+
100+
function getPadding() {
101+
if (!_exenv.canUseDOM) return 0;
102+
103+
var paddingRight = parseInt(window.getComputedStyle(document.body).paddingRight, 10);
104+
var scrollbarWidth = window.innerWidth - document.documentElement.clientWidth;
105+
106+
return paddingRight + scrollbarWidth;
107+
}
108+
109+
function getWindowHeight() {
110+
var multiplier = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
111+
112+
if (_exenv.canUseDOM) {
113+
return window.innerHeight * multiplier;
114+
}
115+
}
116+
117+
function getDocumentHeight() {
118+
if (_exenv.canUseDOM) {
119+
return document.body.clientHeight;
120+
}
121+
}
122+
123+
// ==============================
124+
// Style Sheets
125+
// ==============================
126+
127+
function makeStyleTag() {
128+
if (!_exenv.canUseDOM) return;
129+
130+
var tag = document.createElement('style');
131+
tag.type = 'text/css';
132+
tag.setAttribute('data-react-scrolllock', '');
133+
134+
return tag;
135+
}
136+
function injectStyles(tag, css) {
137+
if (!_exenv.canUseDOM) return;
138+
139+
if (tag.styleSheet) {
140+
tag.styleSheet.cssText = css;
141+
} else {
142+
tag.appendChild(document.createTextNode(css));
143+
}
144+
}
145+
function insertStyleTag(tag) {
146+
if (!_exenv.canUseDOM) return;
147+
148+
var head = document.head || document.getElementsByTagName('head')[0];
149+
150+
head.appendChild(tag);
151+
}

0 commit comments

Comments
 (0)