react-scroll-into-view-if-needed
Advanced tools
Comparing version 1.0.0 to 1.0.1
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react')) : | ||
typeof define === 'function' && define.amd ? define(['exports', 'react'], factory) : | ||
(factory((global['react-scroll-into-view-if-needed'] = {}),global.React)); | ||
}(this, (function (exports,react) { 'use strict'; | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react'), require('prop-types')) : | ||
typeof define === 'function' && define.amd ? define(['exports', 'react', 'prop-types'], factory) : | ||
(factory((global['react-scroll-into-view-if-needed'] = {}),global.React,null)); | ||
}(this, (function (exports,react,PropTypes) { 'use strict'; | ||
function createCommonjsModule(fn, module) { | ||
return module = { exports: {} }, fn(module, module.exports), module.exports; | ||
} | ||
PropTypes = PropTypes && PropTypes.hasOwnProperty('default') ? PropTypes['default'] : PropTypes; | ||
/** | ||
* Copyright (c) 2013-present, Facebook, Inc. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* | ||
*/ | ||
/** | ||
* https://github.com/gre/bezier-easing | ||
* BezierEasing - use bezier curve for transition easing function | ||
* by Gaëtan Renaudeau 2014 - 2015 – MIT License | ||
*/ | ||
function makeEmptyFunction(arg) { | ||
return function () { | ||
return arg; | ||
}; | ||
} | ||
// These values are established by empiricism with tests (tradeoff: performance VS precision) | ||
var NEWTON_ITERATIONS = 4; | ||
var NEWTON_MIN_SLOPE = 0.001; | ||
var SUBDIVISION_PRECISION = 0.0000001; | ||
var SUBDIVISION_MAX_ITERATIONS = 10; | ||
/** | ||
* This function accepts and discards inputs; it has no side effects. This is | ||
* primarily useful idiomatically for overridable function endpoints which | ||
* always need to be callable, since JS lacks a null-call idiom ala Cocoa. | ||
*/ | ||
var emptyFunction = function emptyFunction() {}; | ||
var kSplineTableSize = 11; | ||
var kSampleStepSize = 1.0 / (kSplineTableSize - 1.0); | ||
emptyFunction.thatReturns = makeEmptyFunction; | ||
emptyFunction.thatReturnsFalse = makeEmptyFunction(false); | ||
emptyFunction.thatReturnsTrue = makeEmptyFunction(true); | ||
emptyFunction.thatReturnsNull = makeEmptyFunction(null); | ||
emptyFunction.thatReturnsThis = function () { | ||
return this; | ||
}; | ||
emptyFunction.thatReturnsArgument = function (arg) { | ||
return arg; | ||
}; | ||
var float32ArraySupported = typeof Float32Array === 'function'; | ||
var emptyFunction_1 = emptyFunction; | ||
function A (aA1, aA2) { return 1.0 - 3.0 * aA2 + 3.0 * aA1; } | ||
function B (aA1, aA2) { return 3.0 * aA2 - 6.0 * aA1; } | ||
function C (aA1) { return 3.0 * aA1; } | ||
var emptyFunction$1 = /*#__PURE__*/Object.freeze({ | ||
default: emptyFunction_1, | ||
__moduleExports: emptyFunction_1 | ||
}); | ||
// Returns x(t) given t, x1, and x2, or y(t) given t, y1, and y2. | ||
function calcBezier (aT, aA1, aA2) { return ((A(aA1, aA2) * aT + B(aA1, aA2)) * aT + C(aA1)) * aT; } | ||
/** | ||
* Copyright (c) 2013-present, Facebook, Inc. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
*/ | ||
// Returns dx/dt given t, x1, and x2, or dy/dt given t, y1, and y2. | ||
function getSlope (aT, aA1, aA2) { return 3.0 * A(aA1, aA2) * aT * aT + 2.0 * B(aA1, aA2) * aT + C(aA1); } | ||
/** | ||
* Use invariant() to assert state which your program assumes to be true. | ||
* | ||
* Provide sprintf-style format (only %s is supported) and arguments | ||
* to provide information about what broke and what you were | ||
* expecting. | ||
* | ||
* The invariant message will be stripped in production, but the invariant | ||
* will remain to ensure logic does not differ in production. | ||
*/ | ||
function binarySubdivide (aX, aA, aB, mX1, mX2) { | ||
var currentX, currentT, i = 0; | ||
do { | ||
currentT = aA + (aB - aA) / 2.0; | ||
currentX = calcBezier(currentT, mX1, mX2) - aX; | ||
if (currentX > 0.0) { | ||
aB = currentT; | ||
} else { | ||
aA = currentT; | ||
} | ||
} while (Math.abs(currentX) > SUBDIVISION_PRECISION && ++i < SUBDIVISION_MAX_ITERATIONS); | ||
return currentT; | ||
} | ||
var validateFormat = function validateFormat(format) {}; | ||
function newtonRaphsonIterate (aX, aGuessT, mX1, mX2) { | ||
for (var i = 0; i < NEWTON_ITERATIONS; ++i) { | ||
var currentSlope = getSlope(aGuessT, mX1, mX2); | ||
if (currentSlope === 0.0) { | ||
return aGuessT; | ||
} | ||
var currentX = calcBezier(aGuessT, mX1, mX2) - aX; | ||
aGuessT -= currentX / currentSlope; | ||
} | ||
return aGuessT; | ||
} | ||
if (process.env.NODE_ENV !== 'production') { | ||
validateFormat = function validateFormat(format) { | ||
if (format === undefined) { | ||
throw new Error('invariant requires an error message argument'); | ||
} | ||
}; | ||
} | ||
var src = function bezier (mX1, mY1, mX2, mY2) { | ||
if (!(0 <= mX1 && mX1 <= 1 && 0 <= mX2 && mX2 <= 1)) { | ||
throw new Error('bezier x values must be in [0, 1] range'); | ||
} | ||
function invariant(condition, format, a, b, c, d, e, f) { | ||
validateFormat(format); | ||
// Precompute samples table | ||
var sampleValues = float32ArraySupported ? new Float32Array(kSplineTableSize) : new Array(kSplineTableSize); | ||
if (mX1 !== mY1 || mX2 !== mY2) { | ||
for (var i = 0; i < kSplineTableSize; ++i) { | ||
sampleValues[i] = calcBezier(i * kSampleStepSize, mX1, mX2); | ||
} | ||
} | ||
if (!condition) { | ||
var error; | ||
if (format === undefined) { | ||
error = new Error('Minified exception occurred; use the non-minified dev environment ' + 'for the full error message and additional helpful warnings.'); | ||
} else { | ||
var args = [a, b, c, d, e, f]; | ||
var argIndex = 0; | ||
error = new Error(format.replace(/%s/g, function () { | ||
return args[argIndex++]; | ||
})); | ||
error.name = 'Invariant Violation'; | ||
} | ||
function getTForX (aX) { | ||
var intervalStart = 0.0; | ||
var currentSample = 1; | ||
var lastSample = kSplineTableSize - 1; | ||
error.framesToPop = 1; // we don't care about invariant's own frame | ||
throw error; | ||
} | ||
} | ||
for (; currentSample !== lastSample && sampleValues[currentSample] <= aX; ++currentSample) { | ||
intervalStart += kSampleStepSize; | ||
} | ||
--currentSample; | ||
var invariant_1 = invariant; | ||
// Interpolate to provide an initial guess for t | ||
var dist = (aX - sampleValues[currentSample]) / (sampleValues[currentSample + 1] - sampleValues[currentSample]); | ||
var guessForT = intervalStart + dist * kSampleStepSize; | ||
var invariant$1 = /*#__PURE__*/Object.freeze({ | ||
default: invariant_1, | ||
__moduleExports: invariant_1 | ||
}); | ||
var initialSlope = getSlope(guessForT, mX1, mX2); | ||
if (initialSlope >= NEWTON_MIN_SLOPE) { | ||
return newtonRaphsonIterate(aX, guessForT, mX1, mX2); | ||
} else if (initialSlope === 0.0) { | ||
return guessForT; | ||
} else { | ||
return binarySubdivide(aX, intervalStart, intervalStart + kSampleStepSize, mX1, mX2); | ||
} | ||
} | ||
var emptyFunction$2 = ( emptyFunction$1 && emptyFunction_1 ) || emptyFunction$1; | ||
return function BezierEasing (x) { | ||
if (mX1 === mY1 && mX2 === mY2) { | ||
return x; // linear | ||
} | ||
// Because JavaScript number are imprecise, we should guarantee the extremes are right. | ||
if (x === 0) { | ||
return 0; | ||
} | ||
if (x === 1) { | ||
return 1; | ||
} | ||
return calcBezier(getTForX(x), mY1, mY2); | ||
}; | ||
}; | ||
/** | ||
* Similar to invariant but only logs a warning if the condition is not met. | ||
* This can be used to log issues in development environments in critical | ||
* paths. Removing the logging code for production environments will keep the | ||
* same logic and follow the same code paths. | ||
*/ | ||
var src$1 = /*#__PURE__*/Object.freeze({ | ||
default: src, | ||
__moduleExports: src | ||
}); | ||
var warning = emptyFunction$2; | ||
var BezierEasing = ( src$1 && src ) || src$1; | ||
if (process.env.NODE_ENV !== 'production') { | ||
var printWarning = function printWarning(format) { | ||
for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
args[_key - 1] = arguments[_key]; | ||
} | ||
// Predefined set of animations. Similar to CSS easing functions | ||
var animations = { | ||
ease: BezierEasing(0.25, 0.1, 0.25, 1), | ||
easeIn: BezierEasing(0.42, 0, 1, 1), | ||
easeOut: BezierEasing(0, 0, 0.58, 1), | ||
easeInOut: BezierEasing(0.42, 0, 0.58, 1), | ||
linear: BezierEasing(0, 0, 1, 1) | ||
}; | ||
var argIndex = 0; | ||
var message = 'Warning: ' + format.replace(/%s/g, function () { | ||
return args[argIndex++]; | ||
}); | ||
if (typeof console !== 'undefined') { | ||
console.error(message); | ||
} | ||
try { | ||
// --- Welcome to debugging React --- | ||
// This error was thrown as a convenience so that you can use this stack | ||
// to find the callsite that caused this warning to fire. | ||
throw new Error(message); | ||
} catch (x) {} | ||
}; | ||
warning = function warning(condition, format) { | ||
if (format === undefined) { | ||
throw new Error('`warning(condition, format, ...args)` requires a warning ' + 'message argument'); | ||
} | ||
var amator = animate; | ||
if (format.indexOf('Failed Composite propType: ') === 0) { | ||
return; // Ignore CompositeComponent proptype check. | ||
} | ||
function animate(source, target, options) { | ||
var start= Object.create(null); | ||
var diff = Object.create(null); | ||
options = options || {}; | ||
// We let clients specify their own easing function | ||
var easing = (typeof options.easing === 'function') ? options.easing : animations[options.easing]; | ||
if (!condition) { | ||
for (var _len2 = arguments.length, args = Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) { | ||
args[_key2 - 2] = arguments[_key2]; | ||
} | ||
// if nothing is specified, default to ease (similar to CSS animations) | ||
if (!easing) { | ||
if (options.easing) { | ||
console.warn('Unknown easing function in amator: ' + options.easing); | ||
} | ||
easing = animations.ease; | ||
} | ||
printWarning.apply(undefined, [format].concat(args)); | ||
} | ||
}; | ||
} | ||
var step = typeof options.step === 'function' ? options.step : noop; | ||
var done = typeof options.done === 'function' ? options.done : noop; | ||
var warning_1 = warning; | ||
var scheduler = getScheduler(options.scheduler); | ||
var warning$1 = /*#__PURE__*/Object.freeze({ | ||
default: warning_1, | ||
__moduleExports: warning_1 | ||
}); | ||
var keys = Object.keys(target); | ||
keys.forEach(function(key) { | ||
start[key] = source[key]; | ||
diff[key] = target[key] - source[key]; | ||
}); | ||
/* | ||
object-assign | ||
(c) Sindre Sorhus | ||
@license MIT | ||
*/ | ||
/* eslint-disable no-unused-vars */ | ||
var getOwnPropertySymbols = Object.getOwnPropertySymbols; | ||
var hasOwnProperty = Object.prototype.hasOwnProperty; | ||
var propIsEnumerable = Object.prototype.propertyIsEnumerable; | ||
var durationInMs = options.duration || 400; | ||
var durationInFrames = Math.max(1, durationInMs * 0.06); // 0.06 because 60 frames pers 1,000 ms | ||
var previousAnimationId; | ||
var frame = 0; | ||
function toObject(val) { | ||
if (val === null || val === undefined) { | ||
throw new TypeError('Object.assign cannot be called with null or undefined'); | ||
} | ||
previousAnimationId = scheduler.next(loop); | ||
return Object(val); | ||
} | ||
return { | ||
cancel: cancel | ||
} | ||
function shouldUseNative() { | ||
try { | ||
if (!Object.assign) { | ||
return false; | ||
} | ||
function cancel() { | ||
scheduler.cancel(previousAnimationId); | ||
previousAnimationId = 0; | ||
} | ||
// Detect buggy property enumeration order in older V8 versions. | ||
function loop() { | ||
var t = easing(frame/durationInFrames); | ||
frame += 1; | ||
setValues(t); | ||
if (frame <= durationInFrames) { | ||
previousAnimationId = scheduler.next(loop); | ||
step(source); | ||
} else { | ||
previousAnimationId = 0; | ||
setTimeout(function() { done(source); }, 0); | ||
} | ||
} | ||
// https://bugs.chromium.org/p/v8/issues/detail?id=4118 | ||
var test1 = new String('abc'); // eslint-disable-line no-new-wrappers | ||
test1[5] = 'de'; | ||
if (Object.getOwnPropertyNames(test1)[0] === '5') { | ||
return false; | ||
} | ||
function setValues(t) { | ||
keys.forEach(function(key) { | ||
source[key] = diff[key] * t + start[key]; | ||
}); | ||
} | ||
} | ||
// https://bugs.chromium.org/p/v8/issues/detail?id=3056 | ||
var test2 = {}; | ||
for (var i = 0; i < 10; i++) { | ||
test2['_' + String.fromCharCode(i)] = i; | ||
} | ||
var order2 = Object.getOwnPropertyNames(test2).map(function (n) { | ||
return test2[n]; | ||
}); | ||
if (order2.join('') !== '0123456789') { | ||
return false; | ||
} | ||
function noop() { } | ||
// https://bugs.chromium.org/p/v8/issues/detail?id=3056 | ||
var test3 = {}; | ||
'abcdefghijklmnopqrst'.split('').forEach(function (letter) { | ||
test3[letter] = letter; | ||
}); | ||
if (Object.keys(Object.assign({}, test3)).join('') !== | ||
'abcdefghijklmnopqrst') { | ||
return false; | ||
} | ||
function getScheduler(scheduler) { | ||
if (!scheduler) { | ||
var canRaf = typeof window !== 'undefined' && window.requestAnimationFrame; | ||
return canRaf ? rafScheduler() : timeoutScheduler() | ||
} | ||
if (typeof scheduler.next !== 'function') throw new Error('Scheduler is supposed to have next(cb) function') | ||
if (typeof scheduler.cancel !== 'function') throw new Error('Scheduler is supposed to have cancel(handle) function') | ||
return true; | ||
} catch (err) { | ||
// We don't expect any of the above to throw, but better to be safe. | ||
return false; | ||
} | ||
} | ||
return scheduler | ||
} | ||
var objectAssign = shouldUseNative() ? Object.assign : function (target, source) { | ||
var from; | ||
var to = toObject(target); | ||
var symbols; | ||
function rafScheduler() { | ||
return { | ||
next: window.requestAnimationFrame.bind(window), | ||
cancel: window.cancelAnimationFrame.bind(window) | ||
} | ||
} | ||
for (var s = 1; s < arguments.length; s++) { | ||
from = Object(arguments[s]); | ||
function timeoutScheduler() { | ||
return { | ||
next: function(cb) { | ||
return setTimeout(cb, 1000/60) | ||
}, | ||
cancel: function (id) { | ||
return clearTimeout(id) | ||
} | ||
} | ||
} | ||
for (var key in from) { | ||
if (hasOwnProperty.call(from, key)) { | ||
to[key] = from[key]; | ||
} | ||
} | ||
var __assign = (undefined && undefined.__assign) || Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
var handleScroll = function (parent, _a) { | ||
var scrollLeft = _a.scrollLeft, scrollTop = _a.scrollTop; | ||
parent.scrollLeft = scrollLeft; | ||
parent.scrollTop = scrollTop; | ||
}; | ||
function calculate(target, options) { | ||
if (!target || !(target instanceof HTMLElement)) | ||
throw new Error('Element is required in scrollIntoViewIfNeeded'); | ||
var config = __assign({ handleScroll: handleScroll }, options); | ||
var defaultOffset = { top: 0, right: 0, bottom: 0, left: 0 }; | ||
config.offset = config.offset | ||
? __assign({}, defaultOffset, config.offset) : defaultOffset; | ||
function withinBounds(value, min, max, extent) { | ||
if (config.centerIfNeeded === false || | ||
(max <= value + extent && value <= min + extent)) { | ||
return Math.min(max, Math.max(min, value)); | ||
} | ||
else { | ||
return (min + max) / 2; | ||
} | ||
} | ||
var offset = config.offset; | ||
var offsetTop = offset.top; | ||
var offsetLeft = offset.left; | ||
var offsetBottom = offset.bottom; | ||
var offsetRight = offset.right; | ||
function makeArea(left, top, width, height) { | ||
return { | ||
left: left + offsetLeft, | ||
top: top + offsetTop, | ||
width: width, | ||
height: height, | ||
right: left + offsetLeft + width + offsetRight, | ||
bottom: top + offsetTop + height + offsetBottom, | ||
translate: function (x, y) { | ||
return makeArea(x + left + offsetLeft, y + top + offsetTop, width, height); | ||
}, | ||
relativeFromTo: function (lhs, rhs) { | ||
var newLeft = left + offsetLeft, newTop = top + offsetTop; | ||
lhs = lhs.offsetParent; | ||
rhs = rhs.offsetParent; | ||
if (lhs === rhs) { | ||
return area; | ||
} | ||
for (; lhs; lhs = lhs.offsetParent) { | ||
newLeft += lhs.offsetLeft + lhs.clientLeft; | ||
newTop += lhs.offsetTop + lhs.clientTop; | ||
} | ||
for (; rhs; rhs = rhs.offsetParent) { | ||
newLeft -= rhs.offsetLeft + rhs.clientLeft; | ||
newTop -= rhs.offsetTop + rhs.clientTop; | ||
} | ||
return makeArea(newLeft, newTop, width, height); | ||
}, | ||
}; | ||
} | ||
var parent, area = makeArea(target.offsetLeft, target.offsetTop, target.offsetWidth, target.offsetHeight); | ||
while ((parent = target.parentNode) instanceof HTMLElement && | ||
target !== config.boundary) { | ||
var clientLeft = parent.offsetLeft + parent.clientLeft; | ||
var clientTop = parent.offsetTop + parent.clientTop; | ||
// Make area relative to parent's client area. | ||
area = area | ||
.relativeFromTo(target, parent) | ||
.translate(-clientLeft, -clientTop); | ||
var scrollLeft = withinBounds(parent.scrollLeft, area.right - parent.clientWidth, area.left, parent.clientWidth); | ||
var scrollTop = withinBounds(parent.scrollTop, area.bottom - parent.clientHeight, area.top, parent.clientHeight); | ||
// Pass the new coordinates to the handleScroll callback | ||
config.handleScroll(parent, { scrollLeft: scrollLeft, scrollTop: scrollTop }, config); | ||
// Determine actual scroll amount by reading back scroll properties. | ||
area = area.translate(clientLeft - parent.scrollLeft, clientTop - parent.scrollTop); | ||
target = parent; | ||
} | ||
} | ||
if (getOwnPropertySymbols) { | ||
symbols = getOwnPropertySymbols(from); | ||
for (var i = 0; i < symbols.length; i++) { | ||
if (propIsEnumerable.call(from, symbols[i])) { | ||
to[symbols[i]] = from[symbols[i]]; | ||
} | ||
} | ||
} | ||
} | ||
var __assign$1 = (undefined && undefined.__assign) || Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
var handleScroll$1 = function (parent, _a, config) { | ||
var scrollLeft = _a.scrollLeft, scrollTop = _a.scrollTop; | ||
if (config.duration) { | ||
amator(parent, { | ||
scrollLeft: scrollLeft, | ||
scrollTop: scrollTop, | ||
}, { duration: config.duration, easing: config.easing }); | ||
} | ||
else { | ||
parent.scrollLeft = scrollLeft; | ||
parent.scrollTop = scrollTop; | ||
} | ||
}; | ||
function isBoolean(options) { | ||
return typeof options === 'boolean'; | ||
} | ||
function scrollIntoViewIfNeeded(target, options, animateOptions, finalElement, offsetOptions) { | ||
if (offsetOptions === void 0) { offsetOptions = {}; } | ||
if (!target || !(target instanceof HTMLElement)) | ||
throw new Error('Element is required in scrollIntoViewIfNeeded'); | ||
var config = { centerIfNeeded: false, handleScroll: handleScroll$1 }; | ||
if (isBoolean(options)) { | ||
config.centerIfNeeded = options; | ||
} | ||
else { | ||
config = __assign$1({}, config, options); | ||
} | ||
var defaultOffset = { top: 0, right: 0, bottom: 0, left: 0 }; | ||
config.offset = config.offset | ||
? __assign$1({}, defaultOffset, config.offset) : defaultOffset; | ||
if (animateOptions) { | ||
config.duration = animateOptions.duration; | ||
config.easing = animateOptions.easing; | ||
} | ||
if (finalElement) { | ||
config.boundary = finalElement; | ||
} | ||
if (offsetOptions.offsetTop) { | ||
config.offset.top = offsetOptions.offsetTop; | ||
} | ||
if (offsetOptions.offsetRight) { | ||
config.offset.right = offsetOptions.offsetRight; | ||
} | ||
if (offsetOptions.offsetBottom) { | ||
config.offset.bottom = offsetOptions.offsetBottom; | ||
} | ||
if (offsetOptions.offsetLeft) { | ||
config.offset.left = offsetOptions.offsetLeft; | ||
} | ||
return calculate(target, config); | ||
} | ||
return to; | ||
}; | ||
var classCallCheck = function (instance, Constructor) { | ||
if (!(instance instanceof Constructor)) { | ||
throw new TypeError("Cannot call a class as a function"); | ||
} | ||
}; | ||
var objectAssign$1 = /*#__PURE__*/Object.freeze({ | ||
default: objectAssign, | ||
__moduleExports: objectAssign | ||
}); | ||
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); | ||
} | ||
} | ||
/** | ||
* Copyright (c) 2013-present, Facebook, Inc. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
return function (Constructor, protoProps, staticProps) { | ||
if (protoProps) defineProperties(Constructor.prototype, protoProps); | ||
if (staticProps) defineProperties(Constructor, staticProps); | ||
return Constructor; | ||
}; | ||
}(); | ||
var ReactPropTypesSecret = 'SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED'; | ||
var _extends = Object.assign || function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i]; | ||
var ReactPropTypesSecret_1 = ReactPropTypesSecret; | ||
for (var key in source) { | ||
if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
target[key] = source[key]; | ||
} | ||
} | ||
} | ||
var ReactPropTypesSecret$1 = /*#__PURE__*/Object.freeze({ | ||
default: ReactPropTypesSecret_1, | ||
__moduleExports: ReactPropTypesSecret_1 | ||
}); | ||
return target; | ||
}; | ||
var require$$0 = ( invariant$1 && invariant_1 ) || invariant$1; | ||
var inherits = function (subClass, superClass) { | ||
if (typeof superClass !== "function" && superClass !== null) { | ||
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); | ||
} | ||
var require$$1 = ( warning$1 && warning_1 ) || warning$1; | ||
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; | ||
}; | ||
var require$$2 = ( ReactPropTypesSecret$1 && ReactPropTypesSecret_1 ) || ReactPropTypesSecret$1; | ||
var objectWithoutProperties = function (obj, keys) { | ||
var target = {}; | ||
if (process.env.NODE_ENV !== 'production') { | ||
var invariant$2 = require$$0; | ||
var warning$2 = require$$1; | ||
var ReactPropTypesSecret$2 = require$$2; | ||
var loggedTypeFailures = {}; | ||
} | ||
for (var i in obj) { | ||
if (keys.indexOf(i) >= 0) continue; | ||
if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; | ||
target[i] = obj[i]; | ||
} | ||
/** | ||
* Assert that the values match with the type specs. | ||
* Error messages are memorized and will only be shown once. | ||
* | ||
* @param {object} typeSpecs Map of name to a ReactPropType | ||
* @param {object} values Runtime values that need to be type-checked | ||
* @param {string} location e.g. "prop", "context", "child context" | ||
* @param {string} componentName Name of the component for error messages. | ||
* @param {?Function} getStack Returns the component stack. | ||
* @private | ||
*/ | ||
function checkPropTypes(typeSpecs, values, location, componentName, getStack) { | ||
if (process.env.NODE_ENV !== 'production') { | ||
for (var typeSpecName in typeSpecs) { | ||
if (typeSpecs.hasOwnProperty(typeSpecName)) { | ||
var error; | ||
// Prop type validation may throw. In case they do, we don't want to | ||
// fail the render phase where it didn't fail before. So we log it. | ||
// After these have been cleaned up, we'll let them throw. | ||
try { | ||
// This is intentionally an invariant that gets caught. It's the same | ||
// behavior as without this statement except with a better message. | ||
invariant$2(typeof typeSpecs[typeSpecName] === 'function', '%s: %s type `%s` is invalid; it must be a function, usually from ' + 'the `prop-types` package, but received `%s`.', componentName || 'React class', location, typeSpecName, typeof typeSpecs[typeSpecName]); | ||
error = typeSpecs[typeSpecName](values, typeSpecName, componentName, location, null, ReactPropTypesSecret$2); | ||
} catch (ex) { | ||
error = ex; | ||
} | ||
warning$2(!error || error instanceof Error, '%s: type specification of %s `%s` is invalid; the type checker ' + 'function must return `null` or an `Error` but returned a %s. ' + 'You may have forgotten to pass an argument to the type checker ' + 'creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and ' + 'shape all require an argument).', componentName || 'React class', location, typeSpecName, typeof error); | ||
if (error instanceof Error && !(error.message in loggedTypeFailures)) { | ||
// Only monitor this failure once because there tends to be a lot of the | ||
// same error. | ||
loggedTypeFailures[error.message] = true; | ||
return target; | ||
}; | ||
var stack = getStack ? getStack() : ''; | ||
var possibleConstructorReturn = function (self, call) { | ||
if (!self) { | ||
throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); | ||
} | ||
warning$2(false, 'Failed %s type: %s%s', location, error.message, stack != null ? stack : ''); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
return call && (typeof call === "object" || typeof call === "function") ? call : self; | ||
}; | ||
var checkPropTypes_1 = checkPropTypes; | ||
var ScrollIntoViewIfNeeded = function (_PureComponent) { | ||
inherits(ScrollIntoViewIfNeeded, _PureComponent); | ||
var checkPropTypes$1 = /*#__PURE__*/Object.freeze({ | ||
default: checkPropTypes_1, | ||
__moduleExports: checkPropTypes_1 | ||
}); | ||
function ScrollIntoViewIfNeeded() { | ||
classCallCheck(this, ScrollIntoViewIfNeeded); | ||
var assign = ( objectAssign$1 && objectAssign ) || objectAssign$1; | ||
var _this = possibleConstructorReturn(this, (ScrollIntoViewIfNeeded.__proto__ || Object.getPrototypeOf(ScrollIntoViewIfNeeded)).call(this)); | ||
var checkPropTypes$2 = ( checkPropTypes$1 && checkPropTypes_1 ) || checkPropTypes$1; | ||
_this.handleScrollIntoViewIfNeeded = function () { | ||
var options = _this.props.options; | ||
var node = _this.node.current; | ||
var factoryWithTypeCheckers = function(isValidElement, throwOnDirectAccess) { | ||
/* global Symbol */ | ||
var ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator; | ||
var FAUX_ITERATOR_SYMBOL = '@@iterator'; // Before Symbol spec. | ||
scrollIntoViewIfNeeded(node, options); | ||
}; | ||
/** | ||
* Returns the iterator method function contained on the iterable object. | ||
* | ||
* Be sure to invoke the function with the iterable as context: | ||
* | ||
* var iteratorFn = getIteratorFn(myIterable); | ||
* if (iteratorFn) { | ||
* var iterator = iteratorFn.call(myIterable); | ||
* ... | ||
* } | ||
* | ||
* @param {?object} maybeIterable | ||
* @return {?function} | ||
*/ | ||
function getIteratorFn(maybeIterable) { | ||
var iteratorFn = maybeIterable && (ITERATOR_SYMBOL && maybeIterable[ITERATOR_SYMBOL] || maybeIterable[FAUX_ITERATOR_SYMBOL]); | ||
if (typeof iteratorFn === 'function') { | ||
return iteratorFn; | ||
} | ||
} | ||
_this.node = react.createRef(); | ||
return _this; | ||
} | ||
/** | ||
* Collection of methods that allow declaration and validation of props that are | ||
* supplied to React components. Example usage: | ||
* | ||
* var Props = require('ReactPropTypes'); | ||
* var MyArticle = React.createClass({ | ||
* propTypes: { | ||
* // An optional string prop named "description". | ||
* description: Props.string, | ||
* | ||
* // A required enum prop named "category". | ||
* category: Props.oneOf(['News','Photos']).isRequired, | ||
* | ||
* // A prop named "dialog" that requires an instance of Dialog. | ||
* dialog: Props.instanceOf(Dialog).isRequired | ||
* }, | ||
* render: function() { ... } | ||
* }); | ||
* | ||
* A more formal specification of how these methods are used: | ||
* | ||
* type := array|bool|func|object|number|string|oneOf([...])|instanceOf(...) | ||
* decl := ReactPropTypes.{type}(.isRequired)? | ||
* | ||
* Each and every declaration produces a function with the same signature. This | ||
* allows the creation of custom validation functions. For example: | ||
* | ||
* var MyLink = React.createClass({ | ||
* propTypes: { | ||
* // An optional string or URI prop named "href". | ||
* href: function(props, propName, componentName) { | ||
* var propValue = props[propName]; | ||
* if (propValue != null && typeof propValue !== 'string' && | ||
* !(propValue instanceof URI)) { | ||
* return new Error( | ||
* 'Expected a string or an URI for ' + propName + ' in ' + | ||
* componentName | ||
* ); | ||
* } | ||
* } | ||
* }, | ||
* render: function() {...} | ||
* }); | ||
* | ||
* @internal | ||
*/ | ||
createClass(ScrollIntoViewIfNeeded, [{ | ||
key: 'componentDidMount', | ||
value: function componentDidMount() { | ||
var active = this.props.active; | ||
var ANONYMOUS = '<<anonymous>>'; | ||
if (active) { | ||
this.handleScrollIntoViewIfNeeded(); | ||
} | ||
} | ||
}, { | ||
key: 'componentDidUpdate', | ||
value: function componentDidUpdate(_ref) { | ||
var active = _ref.active; | ||
var isNowActive = this.props.active; | ||
// Important! | ||
// Keep this list in sync with production version in `./factoryWithThrowingShims.js`. | ||
var ReactPropTypes = { | ||
array: createPrimitiveTypeChecker('array'), | ||
bool: createPrimitiveTypeChecker('boolean'), | ||
func: createPrimitiveTypeChecker('function'), | ||
number: createPrimitiveTypeChecker('number'), | ||
object: createPrimitiveTypeChecker('object'), | ||
string: createPrimitiveTypeChecker('string'), | ||
symbol: createPrimitiveTypeChecker('symbol'), | ||
if (!active && isNowActive) { | ||
this.handleScrollIntoViewIfNeeded(); | ||
} | ||
} | ||
}, { | ||
key: 'render', | ||
value: function render() { | ||
var _props = this.props, | ||
active = _props.active, | ||
elementType = _props.elementType, | ||
children = _props.children, | ||
options = _props.options, | ||
wrapperProps = objectWithoutProperties(_props, ['active', 'elementType', 'children', 'options']); | ||
any: createAnyTypeChecker(), | ||
arrayOf: createArrayOfTypeChecker, | ||
element: createElementTypeChecker(), | ||
instanceOf: createInstanceTypeChecker, | ||
node: createNodeChecker(), | ||
objectOf: createObjectOfTypeChecker, | ||
oneOf: createEnumTypeChecker, | ||
oneOfType: createUnionTypeChecker, | ||
shape: createShapeTypeChecker, | ||
exact: createStrictShapeTypeChecker, | ||
}; | ||
return react.createElement(elementType, _extends({ ref: this.node }, wrapperProps), children); | ||
} | ||
}]); | ||
return ScrollIntoViewIfNeeded; | ||
}(react.PureComponent); | ||
/** | ||
* inlined Object.is polyfill to avoid requiring consumers ship their own | ||
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is | ||
*/ | ||
/*eslint-disable no-self-compare*/ | ||
function is(x, y) { | ||
// SameValue algorithm | ||
if (x === y) { | ||
// Steps 1-5, 7-10 | ||
// Steps 6.b-6.e: +0 != -0 | ||
return x !== 0 || 1 / x === 1 / y; | ||
} else { | ||
// Step 6.a: NaN == NaN | ||
return x !== x && y !== y; | ||
} | ||
} | ||
/*eslint-enable no-self-compare*/ | ||
ScrollIntoViewIfNeeded.propTypes = { | ||
active: PropTypes.bool, | ||
children: PropTypes.node.isRequired, | ||
elementType: PropTypes.string, | ||
// this shape should mirror the scroll-into-view-if-needed options | ||
options: PropTypes.shape({ | ||
boundary: PropTypes.node, | ||
centerIfNeeded: PropTypes.bool, | ||
duration: PropTypes.number, | ||
easing: PropTypes.oneOf(['ease', 'easeIn', 'easeOut', 'easeInOut', 'linear']), | ||
offset: PropTypes.shape({ | ||
top: PropTypes.number, | ||
right: PropTypes.number, | ||
bottom: PropTypes.number, | ||
left: PropTypes.number | ||
}) | ||
}) | ||
}; | ||
ScrollIntoViewIfNeeded.defaultProps = { | ||
active: true, | ||
elementType: 'div', | ||
options: { | ||
duration: 250, | ||
easing: 'easeOut' | ||
} | ||
}; | ||
/** | ||
* We use an Error-like object for backward compatibility as people may call | ||
* PropTypes directly and inspect their output. However, we don't use real | ||
* Errors anymore. We don't inspect their stack anyway, and creating them | ||
* is prohibitively expensive if they are created too often, such as what | ||
* happens in oneOfType() for any type before the one that matched. | ||
*/ | ||
function PropTypeError(message) { | ||
this.message = message; | ||
this.stack = ''; | ||
} | ||
// Make `instanceof Error` still work for returned errors. | ||
PropTypeError.prototype = Error.prototype; | ||
exports.default = ScrollIntoViewIfNeeded; | ||
function createChainableTypeChecker(validate) { | ||
if (process.env.NODE_ENV !== 'production') { | ||
var manualPropTypeCallCache = {}; | ||
var manualPropTypeWarningCount = 0; | ||
} | ||
function checkType(isRequired, props, propName, componentName, location, propFullName, secret) { | ||
componentName = componentName || ANONYMOUS; | ||
propFullName = propFullName || propName; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
if (secret !== require$$2) { | ||
if (throwOnDirectAccess) { | ||
// New behavior only for users of `prop-types` package | ||
require$$0( | ||
false, | ||
'Calling PropTypes validators directly is not supported by the `prop-types` package. ' + | ||
'Use `PropTypes.checkPropTypes()` to call them. ' + | ||
'Read more at http://fb.me/use-check-prop-types' | ||
); | ||
} else if (process.env.NODE_ENV !== 'production' && typeof console !== 'undefined') { | ||
// Old behavior for people using React.PropTypes | ||
var cacheKey = componentName + ':' + propName; | ||
if ( | ||
!manualPropTypeCallCache[cacheKey] && | ||
// Avoid spamming the console because they are often not actionable except for lib authors | ||
manualPropTypeWarningCount < 3 | ||
) { | ||
require$$1( | ||
false, | ||
'You are manually calling a React.PropTypes validation ' + | ||
'function for the `%s` prop on `%s`. This is deprecated ' + | ||
'and will throw in the standalone `prop-types` package. ' + | ||
'You may be seeing this warning due to a third-party PropTypes ' + | ||
'library. See https://fb.me/react-warning-dont-call-proptypes ' + 'for details.', | ||
propFullName, | ||
componentName | ||
); | ||
manualPropTypeCallCache[cacheKey] = true; | ||
manualPropTypeWarningCount++; | ||
} | ||
} | ||
} | ||
if (props[propName] == null) { | ||
if (isRequired) { | ||
if (props[propName] === null) { | ||
return new PropTypeError('The ' + location + ' `' + propFullName + '` is marked as required ' + ('in `' + componentName + '`, but its value is `null`.')); | ||
} | ||
return new PropTypeError('The ' + location + ' `' + propFullName + '` is marked as required in ' + ('`' + componentName + '`, but its value is `undefined`.')); | ||
} | ||
return null; | ||
} else { | ||
return validate(props, propName, componentName, location, propFullName); | ||
} | ||
} | ||
var chainedCheckType = checkType.bind(null, false); | ||
chainedCheckType.isRequired = checkType.bind(null, true); | ||
return chainedCheckType; | ||
} | ||
function createPrimitiveTypeChecker(expectedType) { | ||
function validate(props, propName, componentName, location, propFullName, secret) { | ||
var propValue = props[propName]; | ||
var propType = getPropType(propValue); | ||
if (propType !== expectedType) { | ||
// `propValue` being instance of, say, date/regexp, pass the 'object' | ||
// check, but we can offer a more precise error message here rather than | ||
// 'of type `object`'. | ||
var preciseType = getPreciseType(propValue); | ||
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + preciseType + '` supplied to `' + componentName + '`, expected ') + ('`' + expectedType + '`.')); | ||
} | ||
return null; | ||
} | ||
return createChainableTypeChecker(validate); | ||
} | ||
function createAnyTypeChecker() { | ||
return createChainableTypeChecker(emptyFunction$2.thatReturnsNull); | ||
} | ||
function createArrayOfTypeChecker(typeChecker) { | ||
function validate(props, propName, componentName, location, propFullName) { | ||
if (typeof typeChecker !== 'function') { | ||
return new PropTypeError('Property `' + propFullName + '` of component `' + componentName + '` has invalid PropType notation inside arrayOf.'); | ||
} | ||
var propValue = props[propName]; | ||
if (!Array.isArray(propValue)) { | ||
var propType = getPropType(propValue); | ||
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected an array.')); | ||
} | ||
for (var i = 0; i < propValue.length; i++) { | ||
var error = typeChecker(propValue, i, componentName, location, propFullName + '[' + i + ']', require$$2); | ||
if (error instanceof Error) { | ||
return error; | ||
} | ||
} | ||
return null; | ||
} | ||
return createChainableTypeChecker(validate); | ||
} | ||
function createElementTypeChecker() { | ||
function validate(props, propName, componentName, location, propFullName) { | ||
var propValue = props[propName]; | ||
if (!isValidElement(propValue)) { | ||
var propType = getPropType(propValue); | ||
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected a single ReactElement.')); | ||
} | ||
return null; | ||
} | ||
return createChainableTypeChecker(validate); | ||
} | ||
function createInstanceTypeChecker(expectedClass) { | ||
function validate(props, propName, componentName, location, propFullName) { | ||
if (!(props[propName] instanceof expectedClass)) { | ||
var expectedClassName = expectedClass.name || ANONYMOUS; | ||
var actualClassName = getClassName(props[propName]); | ||
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + actualClassName + '` supplied to `' + componentName + '`, expected ') + ('instance of `' + expectedClassName + '`.')); | ||
} | ||
return null; | ||
} | ||
return createChainableTypeChecker(validate); | ||
} | ||
function createEnumTypeChecker(expectedValues) { | ||
if (!Array.isArray(expectedValues)) { | ||
process.env.NODE_ENV !== 'production' ? require$$1(false, 'Invalid argument supplied to oneOf, expected an instance of array.') : void 0; | ||
return emptyFunction$2.thatReturnsNull; | ||
} | ||
function validate(props, propName, componentName, location, propFullName) { | ||
var propValue = props[propName]; | ||
for (var i = 0; i < expectedValues.length; i++) { | ||
if (is(propValue, expectedValues[i])) { | ||
return null; | ||
} | ||
} | ||
var valuesString = JSON.stringify(expectedValues); | ||
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of value `' + propValue + '` ' + ('supplied to `' + componentName + '`, expected one of ' + valuesString + '.')); | ||
} | ||
return createChainableTypeChecker(validate); | ||
} | ||
function createObjectOfTypeChecker(typeChecker) { | ||
function validate(props, propName, componentName, location, propFullName) { | ||
if (typeof typeChecker !== 'function') { | ||
return new PropTypeError('Property `' + propFullName + '` of component `' + componentName + '` has invalid PropType notation inside objectOf.'); | ||
} | ||
var propValue = props[propName]; | ||
var propType = getPropType(propValue); | ||
if (propType !== 'object') { | ||
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected an object.')); | ||
} | ||
for (var key in propValue) { | ||
if (propValue.hasOwnProperty(key)) { | ||
var error = typeChecker(propValue, key, componentName, location, propFullName + '.' + key, require$$2); | ||
if (error instanceof Error) { | ||
return error; | ||
} | ||
} | ||
} | ||
return null; | ||
} | ||
return createChainableTypeChecker(validate); | ||
} | ||
function createUnionTypeChecker(arrayOfTypeCheckers) { | ||
if (!Array.isArray(arrayOfTypeCheckers)) { | ||
process.env.NODE_ENV !== 'production' ? require$$1(false, 'Invalid argument supplied to oneOfType, expected an instance of array.') : void 0; | ||
return emptyFunction$2.thatReturnsNull; | ||
} | ||
for (var i = 0; i < arrayOfTypeCheckers.length; i++) { | ||
var checker = arrayOfTypeCheckers[i]; | ||
if (typeof checker !== 'function') { | ||
require$$1( | ||
false, | ||
'Invalid argument supplied to oneOfType. Expected an array of check functions, but ' + | ||
'received %s at index %s.', | ||
getPostfixForTypeWarning(checker), | ||
i | ||
); | ||
return emptyFunction$2.thatReturnsNull; | ||
} | ||
} | ||
function validate(props, propName, componentName, location, propFullName) { | ||
for (var i = 0; i < arrayOfTypeCheckers.length; i++) { | ||
var checker = arrayOfTypeCheckers[i]; | ||
if (checker(props, propName, componentName, location, propFullName, require$$2) == null) { | ||
return null; | ||
} | ||
} | ||
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` supplied to ' + ('`' + componentName + '`.')); | ||
} | ||
return createChainableTypeChecker(validate); | ||
} | ||
function createNodeChecker() { | ||
function validate(props, propName, componentName, location, propFullName) { | ||
if (!isNode(props[propName])) { | ||
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` supplied to ' + ('`' + componentName + '`, expected a ReactNode.')); | ||
} | ||
return null; | ||
} | ||
return createChainableTypeChecker(validate); | ||
} | ||
function createShapeTypeChecker(shapeTypes) { | ||
function validate(props, propName, componentName, location, propFullName) { | ||
var propValue = props[propName]; | ||
var propType = getPropType(propValue); | ||
if (propType !== 'object') { | ||
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type `' + propType + '` ' + ('supplied to `' + componentName + '`, expected `object`.')); | ||
} | ||
for (var key in shapeTypes) { | ||
var checker = shapeTypes[key]; | ||
if (!checker) { | ||
continue; | ||
} | ||
var error = checker(propValue, key, componentName, location, propFullName + '.' + key, require$$2); | ||
if (error) { | ||
return error; | ||
} | ||
} | ||
return null; | ||
} | ||
return createChainableTypeChecker(validate); | ||
} | ||
function createStrictShapeTypeChecker(shapeTypes) { | ||
function validate(props, propName, componentName, location, propFullName) { | ||
var propValue = props[propName]; | ||
var propType = getPropType(propValue); | ||
if (propType !== 'object') { | ||
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type `' + propType + '` ' + ('supplied to `' + componentName + '`, expected `object`.')); | ||
} | ||
// We need to check all keys in case some are required but missing from | ||
// props. | ||
var allKeys = assign({}, props[propName], shapeTypes); | ||
for (var key in allKeys) { | ||
var checker = shapeTypes[key]; | ||
if (!checker) { | ||
return new PropTypeError( | ||
'Invalid ' + location + ' `' + propFullName + '` key `' + key + '` supplied to `' + componentName + '`.' + | ||
'\nBad object: ' + JSON.stringify(props[propName], null, ' ') + | ||
'\nValid keys: ' + JSON.stringify(Object.keys(shapeTypes), null, ' ') | ||
); | ||
} | ||
var error = checker(propValue, key, componentName, location, propFullName + '.' + key, require$$2); | ||
if (error) { | ||
return error; | ||
} | ||
} | ||
return null; | ||
} | ||
return createChainableTypeChecker(validate); | ||
} | ||
function isNode(propValue) { | ||
switch (typeof propValue) { | ||
case 'number': | ||
case 'string': | ||
case 'undefined': | ||
return true; | ||
case 'boolean': | ||
return !propValue; | ||
case 'object': | ||
if (Array.isArray(propValue)) { | ||
return propValue.every(isNode); | ||
} | ||
if (propValue === null || isValidElement(propValue)) { | ||
return true; | ||
} | ||
var iteratorFn = getIteratorFn(propValue); | ||
if (iteratorFn) { | ||
var iterator = iteratorFn.call(propValue); | ||
var step; | ||
if (iteratorFn !== propValue.entries) { | ||
while (!(step = iterator.next()).done) { | ||
if (!isNode(step.value)) { | ||
return false; | ||
} | ||
} | ||
} else { | ||
// Iterator will provide entry [k,v] tuples rather than values. | ||
while (!(step = iterator.next()).done) { | ||
var entry = step.value; | ||
if (entry) { | ||
if (!isNode(entry[1])) { | ||
return false; | ||
} | ||
} | ||
} | ||
} | ||
} else { | ||
return false; | ||
} | ||
return true; | ||
default: | ||
return false; | ||
} | ||
} | ||
function isSymbol(propType, propValue) { | ||
// Native Symbol. | ||
if (propType === 'symbol') { | ||
return true; | ||
} | ||
// 19.4.3.5 Symbol.prototype[@@toStringTag] === 'Symbol' | ||
if (propValue['@@toStringTag'] === 'Symbol') { | ||
return true; | ||
} | ||
// Fallback for non-spec compliant Symbols which are polyfilled. | ||
if (typeof Symbol === 'function' && propValue instanceof Symbol) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
// Equivalent of `typeof` but with special handling for array and regexp. | ||
function getPropType(propValue) { | ||
var propType = typeof propValue; | ||
if (Array.isArray(propValue)) { | ||
return 'array'; | ||
} | ||
if (propValue instanceof RegExp) { | ||
// Old webkits (at least until Android 4.0) return 'function' rather than | ||
// 'object' for typeof a RegExp. We'll normalize this here so that /bla/ | ||
// passes PropTypes.object. | ||
return 'object'; | ||
} | ||
if (isSymbol(propType, propValue)) { | ||
return 'symbol'; | ||
} | ||
return propType; | ||
} | ||
// This handles more types than `getPropType`. Only used for error messages. | ||
// See `createPrimitiveTypeChecker`. | ||
function getPreciseType(propValue) { | ||
if (typeof propValue === 'undefined' || propValue === null) { | ||
return '' + propValue; | ||
} | ||
var propType = getPropType(propValue); | ||
if (propType === 'object') { | ||
if (propValue instanceof Date) { | ||
return 'date'; | ||
} else if (propValue instanceof RegExp) { | ||
return 'regexp'; | ||
} | ||
} | ||
return propType; | ||
} | ||
// Returns a string that is postfixed to a warning about an invalid type. | ||
// For example, "undefined" or "of type array" | ||
function getPostfixForTypeWarning(value) { | ||
var type = getPreciseType(value); | ||
switch (type) { | ||
case 'array': | ||
case 'object': | ||
return 'an ' + type; | ||
case 'boolean': | ||
case 'date': | ||
case 'regexp': | ||
return 'a ' + type; | ||
default: | ||
return type; | ||
} | ||
} | ||
// Returns class name of the object, if any. | ||
function getClassName(propValue) { | ||
if (!propValue.constructor || !propValue.constructor.name) { | ||
return ANONYMOUS; | ||
} | ||
return propValue.constructor.name; | ||
} | ||
ReactPropTypes.checkPropTypes = checkPropTypes$2; | ||
ReactPropTypes.PropTypes = ReactPropTypes; | ||
return ReactPropTypes; | ||
}; | ||
var factoryWithTypeCheckers$1 = /*#__PURE__*/Object.freeze({ | ||
default: factoryWithTypeCheckers, | ||
__moduleExports: factoryWithTypeCheckers | ||
}); | ||
var factoryWithThrowingShims = function() { | ||
function shim(props, propName, componentName, location, propFullName, secret) { | ||
if (secret === require$$2) { | ||
// It is still safe when called from React. | ||
return; | ||
} | ||
require$$0( | ||
false, | ||
'Calling PropTypes validators directly is not supported by the `prop-types` package. ' + | ||
'Use PropTypes.checkPropTypes() to call them. ' + | ||
'Read more at http://fb.me/use-check-prop-types' | ||
); | ||
} shim.isRequired = shim; | ||
function getShim() { | ||
return shim; | ||
} // Important! | ||
// Keep this list in sync with production version in `./factoryWithTypeCheckers.js`. | ||
var ReactPropTypes = { | ||
array: shim, | ||
bool: shim, | ||
func: shim, | ||
number: shim, | ||
object: shim, | ||
string: shim, | ||
symbol: shim, | ||
any: shim, | ||
arrayOf: getShim, | ||
element: shim, | ||
instanceOf: getShim, | ||
node: shim, | ||
objectOf: getShim, | ||
oneOf: getShim, | ||
oneOfType: getShim, | ||
shape: getShim, | ||
exact: getShim | ||
}; | ||
ReactPropTypes.checkPropTypes = emptyFunction$2; | ||
ReactPropTypes.PropTypes = ReactPropTypes; | ||
return ReactPropTypes; | ||
}; | ||
var factoryWithThrowingShims$1 = /*#__PURE__*/Object.freeze({ | ||
default: factoryWithThrowingShims, | ||
__moduleExports: factoryWithThrowingShims | ||
}); | ||
var require$$0$1 = ( factoryWithTypeCheckers$1 && factoryWithTypeCheckers ) || factoryWithTypeCheckers$1; | ||
var require$$1$1 = ( factoryWithThrowingShims$1 && factoryWithThrowingShims ) || factoryWithThrowingShims$1; | ||
var propTypes = createCommonjsModule(function (module) { | ||
/** | ||
* Copyright (c) 2013-present, Facebook, Inc. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
if (process.env.NODE_ENV !== 'production') { | ||
var REACT_ELEMENT_TYPE = (typeof Symbol === 'function' && | ||
Symbol.for && | ||
Symbol.for('react.element')) || | ||
0xeac7; | ||
var isValidElement = function(object) { | ||
return typeof object === 'object' && | ||
object !== null && | ||
object.$$typeof === REACT_ELEMENT_TYPE; | ||
}; | ||
// By explicitly using `prop-types` you are opting into new development behavior. | ||
// http://fb.me/prop-types-in-prod | ||
var throwOnDirectAccess = true; | ||
module.exports = require$$0$1(isValidElement, throwOnDirectAccess); | ||
} else { | ||
// By explicitly using `prop-types` you are opting into new production behavior. | ||
// http://fb.me/prop-types-in-prod | ||
module.exports = require$$1$1(); | ||
} | ||
}); | ||
/** | ||
* https://github.com/gre/bezier-easing | ||
* BezierEasing - use bezier curve for transition easing function | ||
* by Gaëtan Renaudeau 2014 - 2015 – MIT License | ||
*/ | ||
// These values are established by empiricism with tests (tradeoff: performance VS precision) | ||
var NEWTON_ITERATIONS = 4; | ||
var NEWTON_MIN_SLOPE = 0.001; | ||
var SUBDIVISION_PRECISION = 0.0000001; | ||
var SUBDIVISION_MAX_ITERATIONS = 10; | ||
var kSplineTableSize = 11; | ||
var kSampleStepSize = 1.0 / (kSplineTableSize - 1.0); | ||
var float32ArraySupported = typeof Float32Array === 'function'; | ||
function A (aA1, aA2) { return 1.0 - 3.0 * aA2 + 3.0 * aA1; } | ||
function B (aA1, aA2) { return 3.0 * aA2 - 6.0 * aA1; } | ||
function C (aA1) { return 3.0 * aA1; } | ||
// Returns x(t) given t, x1, and x2, or y(t) given t, y1, and y2. | ||
function calcBezier (aT, aA1, aA2) { return ((A(aA1, aA2) * aT + B(aA1, aA2)) * aT + C(aA1)) * aT; } | ||
// Returns dx/dt given t, x1, and x2, or dy/dt given t, y1, and y2. | ||
function getSlope (aT, aA1, aA2) { return 3.0 * A(aA1, aA2) * aT * aT + 2.0 * B(aA1, aA2) * aT + C(aA1); } | ||
function binarySubdivide (aX, aA, aB, mX1, mX2) { | ||
var currentX, currentT, i = 0; | ||
do { | ||
currentT = aA + (aB - aA) / 2.0; | ||
currentX = calcBezier(currentT, mX1, mX2) - aX; | ||
if (currentX > 0.0) { | ||
aB = currentT; | ||
} else { | ||
aA = currentT; | ||
} | ||
} while (Math.abs(currentX) > SUBDIVISION_PRECISION && ++i < SUBDIVISION_MAX_ITERATIONS); | ||
return currentT; | ||
} | ||
function newtonRaphsonIterate (aX, aGuessT, mX1, mX2) { | ||
for (var i = 0; i < NEWTON_ITERATIONS; ++i) { | ||
var currentSlope = getSlope(aGuessT, mX1, mX2); | ||
if (currentSlope === 0.0) { | ||
return aGuessT; | ||
} | ||
var currentX = calcBezier(aGuessT, mX1, mX2) - aX; | ||
aGuessT -= currentX / currentSlope; | ||
} | ||
return aGuessT; | ||
} | ||
var src = function bezier (mX1, mY1, mX2, mY2) { | ||
if (!(0 <= mX1 && mX1 <= 1 && 0 <= mX2 && mX2 <= 1)) { | ||
throw new Error('bezier x values must be in [0, 1] range'); | ||
} | ||
// Precompute samples table | ||
var sampleValues = float32ArraySupported ? new Float32Array(kSplineTableSize) : new Array(kSplineTableSize); | ||
if (mX1 !== mY1 || mX2 !== mY2) { | ||
for (var i = 0; i < kSplineTableSize; ++i) { | ||
sampleValues[i] = calcBezier(i * kSampleStepSize, mX1, mX2); | ||
} | ||
} | ||
function getTForX (aX) { | ||
var intervalStart = 0.0; | ||
var currentSample = 1; | ||
var lastSample = kSplineTableSize - 1; | ||
for (; currentSample !== lastSample && sampleValues[currentSample] <= aX; ++currentSample) { | ||
intervalStart += kSampleStepSize; | ||
} | ||
--currentSample; | ||
// Interpolate to provide an initial guess for t | ||
var dist = (aX - sampleValues[currentSample]) / (sampleValues[currentSample + 1] - sampleValues[currentSample]); | ||
var guessForT = intervalStart + dist * kSampleStepSize; | ||
var initialSlope = getSlope(guessForT, mX1, mX2); | ||
if (initialSlope >= NEWTON_MIN_SLOPE) { | ||
return newtonRaphsonIterate(aX, guessForT, mX1, mX2); | ||
} else if (initialSlope === 0.0) { | ||
return guessForT; | ||
} else { | ||
return binarySubdivide(aX, intervalStart, intervalStart + kSampleStepSize, mX1, mX2); | ||
} | ||
} | ||
return function BezierEasing (x) { | ||
if (mX1 === mY1 && mX2 === mY2) { | ||
return x; // linear | ||
} | ||
// Because JavaScript number are imprecise, we should guarantee the extremes are right. | ||
if (x === 0) { | ||
return 0; | ||
} | ||
if (x === 1) { | ||
return 1; | ||
} | ||
return calcBezier(getTForX(x), mY1, mY2); | ||
}; | ||
}; | ||
var src$1 = /*#__PURE__*/Object.freeze({ | ||
default: src, | ||
__moduleExports: src | ||
}); | ||
var BezierEasing = ( src$1 && src ) || src$1; | ||
// Predefined set of animations. Similar to CSS easing functions | ||
var animations = { | ||
ease: BezierEasing(0.25, 0.1, 0.25, 1), | ||
easeIn: BezierEasing(0.42, 0, 1, 1), | ||
easeOut: BezierEasing(0, 0, 0.58, 1), | ||
easeInOut: BezierEasing(0.42, 0, 0.58, 1), | ||
linear: BezierEasing(0, 0, 1, 1) | ||
}; | ||
var amator = animate; | ||
function animate(source, target, options) { | ||
var start= Object.create(null); | ||
var diff = Object.create(null); | ||
options = options || {}; | ||
// We let clients specify their own easing function | ||
var easing = (typeof options.easing === 'function') ? options.easing : animations[options.easing]; | ||
// if nothing is specified, default to ease (similar to CSS animations) | ||
if (!easing) { | ||
if (options.easing) { | ||
console.warn('Unknown easing function in amator: ' + options.easing); | ||
} | ||
easing = animations.ease; | ||
} | ||
var step = typeof options.step === 'function' ? options.step : noop; | ||
var done = typeof options.done === 'function' ? options.done : noop; | ||
var scheduler = getScheduler(options.scheduler); | ||
var keys = Object.keys(target); | ||
keys.forEach(function(key) { | ||
start[key] = source[key]; | ||
diff[key] = target[key] - source[key]; | ||
}); | ||
var durationInMs = options.duration || 400; | ||
var durationInFrames = Math.max(1, durationInMs * 0.06); // 0.06 because 60 frames pers 1,000 ms | ||
var previousAnimationId; | ||
var frame = 0; | ||
previousAnimationId = scheduler.next(loop); | ||
return { | ||
cancel: cancel | ||
} | ||
function cancel() { | ||
scheduler.cancel(previousAnimationId); | ||
previousAnimationId = 0; | ||
} | ||
function loop() { | ||
var t = easing(frame/durationInFrames); | ||
frame += 1; | ||
setValues(t); | ||
if (frame <= durationInFrames) { | ||
previousAnimationId = scheduler.next(loop); | ||
step(source); | ||
} else { | ||
previousAnimationId = 0; | ||
setTimeout(function() { done(source); }, 0); | ||
} | ||
} | ||
function setValues(t) { | ||
keys.forEach(function(key) { | ||
source[key] = diff[key] * t + start[key]; | ||
}); | ||
} | ||
} | ||
function noop() { } | ||
function getScheduler(scheduler) { | ||
if (!scheduler) { | ||
var canRaf = typeof window !== 'undefined' && window.requestAnimationFrame; | ||
return canRaf ? rafScheduler() : timeoutScheduler() | ||
} | ||
if (typeof scheduler.next !== 'function') throw new Error('Scheduler is supposed to have next(cb) function') | ||
if (typeof scheduler.cancel !== 'function') throw new Error('Scheduler is supposed to have cancel(handle) function') | ||
return scheduler | ||
} | ||
function rafScheduler() { | ||
return { | ||
next: window.requestAnimationFrame.bind(window), | ||
cancel: window.cancelAnimationFrame.bind(window) | ||
} | ||
} | ||
function timeoutScheduler() { | ||
return { | ||
next: function(cb) { | ||
return setTimeout(cb, 1000/60) | ||
}, | ||
cancel: function (id) { | ||
return clearTimeout(id) | ||
} | ||
} | ||
} | ||
var __assign = (undefined && undefined.__assign) || Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
var handleScroll = function (parent, _a) { | ||
var scrollLeft = _a.scrollLeft, scrollTop = _a.scrollTop; | ||
parent.scrollLeft = scrollLeft; | ||
parent.scrollTop = scrollTop; | ||
}; | ||
function calculate(target, options) { | ||
if (!target || !(target instanceof HTMLElement)) | ||
throw new Error('Element is required in scrollIntoViewIfNeeded'); | ||
var config = __assign({ handleScroll: handleScroll }, options); | ||
var defaultOffset = { top: 0, right: 0, bottom: 0, left: 0 }; | ||
config.offset = config.offset | ||
? __assign({}, defaultOffset, config.offset) : defaultOffset; | ||
function withinBounds(value, min, max, extent) { | ||
if (config.centerIfNeeded === false || | ||
(max <= value + extent && value <= min + extent)) { | ||
return Math.min(max, Math.max(min, value)); | ||
} | ||
else { | ||
return (min + max) / 2; | ||
} | ||
} | ||
var offset = config.offset; | ||
var offsetTop = offset.top; | ||
var offsetLeft = offset.left; | ||
var offsetBottom = offset.bottom; | ||
var offsetRight = offset.right; | ||
function makeArea(left, top, width, height) { | ||
return { | ||
left: left + offsetLeft, | ||
top: top + offsetTop, | ||
width: width, | ||
height: height, | ||
right: left + offsetLeft + width + offsetRight, | ||
bottom: top + offsetTop + height + offsetBottom, | ||
translate: function (x, y) { | ||
return makeArea(x + left + offsetLeft, y + top + offsetTop, width, height); | ||
}, | ||
relativeFromTo: function (lhs, rhs) { | ||
var newLeft = left + offsetLeft, newTop = top + offsetTop; | ||
lhs = lhs.offsetParent; | ||
rhs = rhs.offsetParent; | ||
if (lhs === rhs) { | ||
return area; | ||
} | ||
for (; lhs; lhs = lhs.offsetParent) { | ||
newLeft += lhs.offsetLeft + lhs.clientLeft; | ||
newTop += lhs.offsetTop + lhs.clientTop; | ||
} | ||
for (; rhs; rhs = rhs.offsetParent) { | ||
newLeft -= rhs.offsetLeft + rhs.clientLeft; | ||
newTop -= rhs.offsetTop + rhs.clientTop; | ||
} | ||
return makeArea(newLeft, newTop, width, height); | ||
}, | ||
}; | ||
} | ||
var parent, area = makeArea(target.offsetLeft, target.offsetTop, target.offsetWidth, target.offsetHeight); | ||
while ((parent = target.parentNode) instanceof HTMLElement && | ||
target !== config.boundary) { | ||
var clientLeft = parent.offsetLeft + parent.clientLeft; | ||
var clientTop = parent.offsetTop + parent.clientTop; | ||
// Make area relative to parent's client area. | ||
area = area | ||
.relativeFromTo(target, parent) | ||
.translate(-clientLeft, -clientTop); | ||
var scrollLeft = withinBounds(parent.scrollLeft, area.right - parent.clientWidth, area.left, parent.clientWidth); | ||
var scrollTop = withinBounds(parent.scrollTop, area.bottom - parent.clientHeight, area.top, parent.clientHeight); | ||
// Pass the new coordinates to the handleScroll callback | ||
config.handleScroll(parent, { scrollLeft: scrollLeft, scrollTop: scrollTop }, config); | ||
// Determine actual scroll amount by reading back scroll properties. | ||
area = area.translate(clientLeft - parent.scrollLeft, clientTop - parent.scrollTop); | ||
target = parent; | ||
} | ||
} | ||
var __assign$1 = (undefined && undefined.__assign) || Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
var handleScroll$1 = function (parent, _a, config) { | ||
var scrollLeft = _a.scrollLeft, scrollTop = _a.scrollTop; | ||
if (config.duration) { | ||
amator(parent, { | ||
scrollLeft: scrollLeft, | ||
scrollTop: scrollTop, | ||
}, { duration: config.duration, easing: config.easing }); | ||
} | ||
else { | ||
parent.scrollLeft = scrollLeft; | ||
parent.scrollTop = scrollTop; | ||
} | ||
}; | ||
function isBoolean(options) { | ||
return typeof options === 'boolean'; | ||
} | ||
function scrollIntoViewIfNeeded(target, options, animateOptions, finalElement, offsetOptions) { | ||
if (offsetOptions === void 0) { offsetOptions = {}; } | ||
if (!target || !(target instanceof HTMLElement)) | ||
throw new Error('Element is required in scrollIntoViewIfNeeded'); | ||
var config = { centerIfNeeded: false, handleScroll: handleScroll$1 }; | ||
if (isBoolean(options)) { | ||
config.centerIfNeeded = options; | ||
} | ||
else { | ||
config = __assign$1({}, config, options); | ||
} | ||
var defaultOffset = { top: 0, right: 0, bottom: 0, left: 0 }; | ||
config.offset = config.offset | ||
? __assign$1({}, defaultOffset, config.offset) : defaultOffset; | ||
if (animateOptions) { | ||
config.duration = animateOptions.duration; | ||
config.easing = animateOptions.easing; | ||
} | ||
if (finalElement) { | ||
config.boundary = finalElement; | ||
} | ||
if (offsetOptions.offsetTop) { | ||
config.offset.top = offsetOptions.offsetTop; | ||
} | ||
if (offsetOptions.offsetRight) { | ||
config.offset.right = offsetOptions.offsetRight; | ||
} | ||
if (offsetOptions.offsetBottom) { | ||
config.offset.bottom = offsetOptions.offsetBottom; | ||
} | ||
if (offsetOptions.offsetLeft) { | ||
config.offset.left = offsetOptions.offsetLeft; | ||
} | ||
return calculate(target, config); | ||
} | ||
var classCallCheck = function (instance, Constructor) { | ||
if (!(instance instanceof Constructor)) { | ||
throw new TypeError("Cannot call a class as a function"); | ||
} | ||
}; | ||
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; | ||
}; | ||
}(); | ||
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; | ||
}; | ||
var inherits = function (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; | ||
}; | ||
var possibleConstructorReturn = function (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; | ||
}; | ||
var ScrollIntoViewIfNeeded = function (_PureComponent) { | ||
inherits(ScrollIntoViewIfNeeded, _PureComponent); | ||
function ScrollIntoViewIfNeeded(props) { | ||
classCallCheck(this, ScrollIntoViewIfNeeded); | ||
var _this = possibleConstructorReturn(this, (ScrollIntoViewIfNeeded.__proto__ || Object.getPrototypeOf(ScrollIntoViewIfNeeded)).call(this, props)); | ||
_this.handleScrollIntoViewIfNeeded = function () { | ||
var options = _this.props.options; | ||
var node = _this.node.current; | ||
scrollIntoViewIfNeeded(node, options); | ||
}; | ||
_this.node = react.createRef(); | ||
return _this; | ||
} | ||
createClass(ScrollIntoViewIfNeeded, [{ | ||
key: 'componentDidMount', | ||
value: function componentDidMount() { | ||
var active = this.props.active; | ||
if (active) { | ||
this.handleScrollIntoViewIfNeeded(); | ||
} | ||
} | ||
}, { | ||
key: 'componentDidUpdate', | ||
value: function componentDidUpdate(_ref) { | ||
var active = _ref.active; | ||
var isNowActive = this.props.active; | ||
if (!active && isNowActive) { | ||
this.handleScrollIntoViewIfNeeded(); | ||
} | ||
} | ||
}, { | ||
key: 'render', | ||
value: function render() { | ||
var _props = this.props, | ||
elementType = _props.elementType, | ||
children = _props.children; | ||
return react.createElement(elementType, _extends({ ref: this.node }, this.props), children); | ||
} | ||
}]); | ||
return ScrollIntoViewIfNeeded; | ||
}(react.PureComponent); | ||
ScrollIntoViewIfNeeded.propTypes = { | ||
active: propTypes.bool, | ||
children: propTypes.node.isRequired, | ||
elementType: propTypes.string, | ||
options: propTypes.shape({ | ||
boundary: propTypes.node, | ||
centerIfNeeded: propTypes.bool, | ||
duration: propTypes.number, | ||
easing: propTypes.oneOf(['ease', 'easeIn', 'easeOut', 'easeInOut', 'linear']), | ||
offset: propTypes.shape(), | ||
top: propTypes.number, | ||
right: propTypes.number, | ||
bottom: propTypes.number, | ||
left: propTypes.number | ||
}) | ||
}; | ||
ScrollIntoViewIfNeeded.defaultProps = { | ||
active: true, | ||
elementType: 'div', | ||
options: { | ||
duration: 250, | ||
easing: 'easeOut' | ||
} | ||
}; | ||
exports.default = ScrollIntoViewIfNeeded; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
}))); | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "react-scroll-into-view-if-needed", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "A thin component wrapper around scroll-into-view-if-needed", | ||
@@ -11,3 +11,4 @@ "main": "dist/umd/index.js", | ||
"peerDependencies": { | ||
"react": "^16.3.0" | ||
"prop-types": "^15.6.1", | ||
"react": "^16.0.0" | ||
}, | ||
@@ -21,8 +22,20 @@ "dependencies": { | ||
"babel-eslint": "^8.2.3", | ||
"babel-jest": "^22.4.3", | ||
"babel-plugin-external-helpers": "^6.22.0", | ||
"babel-preset-env": "^1.6.1", | ||
"babel-preset-react": "^6.24.1", | ||
"babel-preset-stage-2": "^6.24.1", | ||
"coveralls": "^3.0.0", | ||
"enzyme": "^3.3.0", | ||
"enzyme-adapter-react-16": "^1.1.1", | ||
"eslint": "^4.19.1", | ||
"eslint-config-airbnb": "^16.1.0", | ||
"eslint-plugin-import": "^2.11.0", | ||
"eslint-plugin-jsx-a11y": "^6.0.3", | ||
"eslint-plugin-react": "^7.7.0", | ||
"jest": "^22.4.3", | ||
"prop-types": "^15.6.1", | ||
"react": "^16.3.2", | ||
"rollup": "^0.58.0", | ||
"react-dom": "^16.3.2", | ||
"rollup": "^0.58.1", | ||
"rollup-plugin-babel": "^3.0.3", | ||
@@ -33,5 +46,8 @@ "rollup-plugin-commonjs": "^9.1.0", | ||
"scripts": { | ||
"build": "rollup -c", | ||
"lint": "eslint ./src/**", | ||
"prepublishOnly": "yarn build", | ||
"build": "rollup -c" | ||
"test": "jest", | ||
"travis": "yarn run lint && jest && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js" | ||
} | ||
} |
@@ -1,8 +0,8 @@ | ||
<h3 align="center"> | ||
React Scroll Into View If Needed | ||
</h3> | ||
[![Build Status](https://travis-ci.org/icd2k3/react-scroll-into-view-if-needed.svg?branch=master)](https://travis-ci.org/icd2k3/react-scroll-into-view-if-needed) | ||
[![Coverage Status](https://coveralls.io/repos/github/icd2k3/react-scroll-into-view-if-needed/badge.svg)](https://coveralls.io/github/icd2k3/react-scroll-into-view-if-needed) | ||
[![dependencies Status](https://david-dm.org/icd2k3/react-scroll-into-view-if-needed/status.svg)](https://david-dm.org/icd2k3/react-scroll-into-view-if-needed) | ||
## Description | ||
Just a thin component wrapper around the fantastic [scroll-into-view-if-needed](https://www.npmjs.com/package/scroll-into-view-if-needed) polyfill. | ||
A thin react component wrapper bundled with the fantastic [scroll-into-view-if-needed](https://www.npmjs.com/package/scroll-into-view-if-needed) polyfill. | ||
@@ -17,3 +17,3 @@ ## Install | ||
## Example | ||
## Usage | ||
@@ -32,17 +32,20 @@ ```js | ||
## Props | ||
## Optional Props | ||
#### active | ||
> Type: `boolean` | ||
> Default: `true` | ||
The `active` prop allows controll of _when_ to scroll to the component. By default, it will attempt to scroll as soon as it is mounted, but you can set this prop to manually control when to trigger the scroll behavior. | ||
The `active` prop allows controll of _when_ to scroll to the component. By default, it will attempt to scroll as soon as it is mounted, but you can set this prop to manually control when to trigger the scroll behavior from the parent component. | ||
#### elementType | ||
> Type: `string` | ||
> Default: `'div'` | ||
Set the wrapper component type. See the React [createElement](https://reactjs.org/docs/react-api.html#createelement) api | ||
Set the wrapper component type. For example, this could also be `'footer'`, `'button'`, etc... See the React [createElement](https://reactjs.org/docs/react-api.html#createelement) api. | ||
#### options | ||
> Type: `object` | ||
> Default: `{ duration: 250, easing: 'easeOut' }` | ||
The `options` prop simply passes options to `scroll-into-view-if-needed`. See all the possible options in their [API documentation](https://www.npmjs.com/package/scroll-into-view-if-needed#api) | ||
The `options` prop simply passes options to `scroll-into-view-if-needed`. See all the possible options in their [API documentation](https://www.npmjs.com/package/scroll-into-view-if-needed#api). |
@@ -10,2 +10,3 @@ import { createElement, createRef, PureComponent } from 'react'; | ||
elementType: PropTypes.string, | ||
// this shape should mirror the scroll-into-view-if-needed options | ||
options: PropTypes.shape({ | ||
@@ -22,7 +23,8 @@ boundary: PropTypes.node, | ||
]), | ||
offset: PropTypes.shape(), | ||
top: PropTypes.number, | ||
right: PropTypes.number, | ||
bottom: PropTypes.number, | ||
left: PropTypes.number, | ||
offset: PropTypes.shape({ | ||
top: PropTypes.number, | ||
right: PropTypes.number, | ||
bottom: PropTypes.number, | ||
left: PropTypes.number, | ||
}), | ||
}), | ||
@@ -40,4 +42,4 @@ }; | ||
constructor(props) { | ||
super(props); | ||
constructor() { | ||
super(); | ||
this.node = createRef(); | ||
@@ -67,5 +69,11 @@ } | ||
render() { | ||
const { elementType, children } = this.props; | ||
return createElement(elementType, { ref: this.node, ...this.props }, children); | ||
const { | ||
active, | ||
elementType, | ||
children, | ||
options, | ||
...wrapperProps | ||
} = this.props; | ||
return createElement(elementType, { ref: this.node, ...wrapperProps }, children); | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
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
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
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
237503
15
50
1
3
24
658
1