182 lines
No EOL
5.9 KiB
JavaScript
182 lines
No EOL
5.9 KiB
JavaScript
'use strict';
|
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
exports.PopperPlacements = exports.keyCodes = exports.TransitionStatuses = exports.TransitionPropTypeKeys = exports.TransitionTimeouts = undefined;
|
|
exports.getScrollbarWidth = getScrollbarWidth;
|
|
exports.setScrollbarWidth = setScrollbarWidth;
|
|
exports.isBodyOverflowing = isBodyOverflowing;
|
|
exports.getOriginalBodyPadding = getOriginalBodyPadding;
|
|
exports.conditionallyUpdateScrollbar = conditionallyUpdateScrollbar;
|
|
exports.mapToCssModules = mapToCssModules;
|
|
exports.omit = omit;
|
|
exports.pick = pick;
|
|
exports.warnOnce = warnOnce;
|
|
exports.deprecated = deprecated;
|
|
exports.DOMElement = DOMElement;
|
|
exports.getTarget = getTarget;
|
|
|
|
var _lodash = require('lodash.isfunction');
|
|
|
|
var _lodash2 = _interopRequireDefault(_lodash);
|
|
|
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
|
|
// https://github.com/twbs/bootstrap/blob/v4.0.0-alpha.4/js/src/modal.js#L436-L443
|
|
function getScrollbarWidth() {
|
|
var scrollDiv = document.createElement('div');
|
|
// .modal-scrollbar-measure styles // https://github.com/twbs/bootstrap/blob/v4.0.0-alpha.4/scss/_modal.scss#L106-L113
|
|
scrollDiv.style.position = 'absolute';
|
|
scrollDiv.style.top = '-9999px';
|
|
scrollDiv.style.width = '50px';
|
|
scrollDiv.style.height = '50px';
|
|
scrollDiv.style.overflow = 'scroll';
|
|
document.body.appendChild(scrollDiv);
|
|
var scrollbarWidth = scrollDiv.offsetWidth - scrollDiv.clientWidth;
|
|
document.body.removeChild(scrollDiv);
|
|
return scrollbarWidth;
|
|
}
|
|
|
|
function setScrollbarWidth(padding) {
|
|
document.body.style.paddingRight = padding > 0 ? padding + 'px' : null;
|
|
}
|
|
|
|
function isBodyOverflowing() {
|
|
return document.body.clientWidth < window.innerWidth;
|
|
}
|
|
|
|
function getOriginalBodyPadding() {
|
|
return parseInt(window.getComputedStyle(document.body, null).getPropertyValue('padding-right') || 0, 10);
|
|
}
|
|
|
|
function conditionallyUpdateScrollbar() {
|
|
var scrollbarWidth = getScrollbarWidth();
|
|
// https://github.com/twbs/bootstrap/blob/v4.0.0-alpha.6/js/src/modal.js#L433
|
|
var fixedContent = document.querySelectorAll('.fixed-top, .fixed-bottom, .is-fixed, .sticky-top')[0];
|
|
var bodyPadding = fixedContent ? parseInt(fixedContent.style.paddingRight || 0, 10) : 0;
|
|
|
|
if (isBodyOverflowing()) {
|
|
setScrollbarWidth(bodyPadding + scrollbarWidth);
|
|
}
|
|
}
|
|
|
|
function mapToCssModules(className, cssModule) {
|
|
if (!cssModule) return className;
|
|
return className.split(' ').map(function (c) {
|
|
return cssModule[c] || c;
|
|
}).join(' ');
|
|
}
|
|
|
|
/**
|
|
* Returns a new object with the key/value pairs from `obj` that are not in the array `omitKeys`.
|
|
*/
|
|
function omit(obj, omitKeys) {
|
|
var result = {};
|
|
Object.keys(obj).forEach(function (key) {
|
|
if (omitKeys.indexOf(key) === -1) {
|
|
result[key] = obj[key];
|
|
}
|
|
});
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Returns a filtered copy of an object with only the specified keys.
|
|
*/
|
|
function pick(obj, keys) {
|
|
var pickKeys = Array.isArray(keys) ? keys : [keys];
|
|
var length = pickKeys.length;
|
|
var key = void 0;
|
|
var result = {};
|
|
|
|
while (length > 0) {
|
|
length -= 1;
|
|
key = pickKeys[length];
|
|
result[key] = obj[key];
|
|
}
|
|
return result;
|
|
}
|
|
|
|
var warned = {};
|
|
|
|
function warnOnce(message) {
|
|
if (!warned[message]) {
|
|
/* istanbul ignore else */
|
|
if (typeof console !== 'undefined') {
|
|
console.error(message); // eslint-disable-line no-console
|
|
}
|
|
warned[message] = true;
|
|
}
|
|
}
|
|
|
|
function deprecated(propType, explanation) {
|
|
return function validate(props, propName, componentName) {
|
|
if (props[propName] !== null && typeof props[propName] !== 'undefined') {
|
|
warnOnce('"' + propName + '" property of "' + componentName + '" has been deprecated.\n' + explanation);
|
|
}
|
|
|
|
for (var _len = arguments.length, rest = Array(_len > 3 ? _len - 3 : 0), _key = 3; _key < _len; _key++) {
|
|
rest[_key - 3] = arguments[_key];
|
|
}
|
|
|
|
return propType.apply(undefined, [props, propName, componentName].concat(rest));
|
|
};
|
|
}
|
|
|
|
function DOMElement(props, propName, componentName) {
|
|
if (!(props[propName] instanceof Element)) {
|
|
return new Error('Invalid prop `' + propName + '` supplied to `' + componentName + '`. Expected prop to be an instance of Element. Validation failed.');
|
|
}
|
|
}
|
|
|
|
function getTarget(target) {
|
|
if ((0, _lodash2.default)(target)) {
|
|
return target();
|
|
}
|
|
|
|
if (typeof target === 'string' && document) {
|
|
var selection = document.querySelector(target);
|
|
if (selection === null) {
|
|
selection = document.querySelector('#' + target);
|
|
}
|
|
if (selection === null) {
|
|
throw new Error('The target \'' + target + '\' could not be identified in the dom, tip: check spelling');
|
|
}
|
|
return selection;
|
|
}
|
|
|
|
return target;
|
|
}
|
|
|
|
/* eslint key-spacing: ["error", { afterColon: true, align: "value" }] */
|
|
// These are all setup to match what is in the bootstrap _variables.scss
|
|
// https://github.com/twbs/bootstrap/blob/v4-dev/scss/_variables.scss
|
|
var TransitionTimeouts = exports.TransitionTimeouts = {
|
|
Fade: 150, // $transition-fade
|
|
Collapse: 350, // $transition-collapse
|
|
Modal: 300, // $modal-transition
|
|
Carousel: 600 // $carousel-transition
|
|
};
|
|
|
|
// Duplicated Transition.propType keys to ensure that Reactstrap builds
|
|
// for distribution properly exclude these keys for nested child HTML attributes
|
|
// since `react-transition-group` removes propTypes in production builds.
|
|
var TransitionPropTypeKeys = exports.TransitionPropTypeKeys = ['in', 'mountOnEnter', 'unmountOnExit', 'appear', 'enter', 'exit', 'timeout', 'onEnter', 'onEntering', 'onEntered', 'onExit', 'onExiting', 'onExited'];
|
|
|
|
var TransitionStatuses = exports.TransitionStatuses = {
|
|
ENTERING: 'entering',
|
|
ENTERED: 'entered',
|
|
EXITING: 'exiting',
|
|
EXITED: 'exited'
|
|
};
|
|
|
|
var keyCodes = exports.keyCodes = {
|
|
esc: 27,
|
|
space: 32,
|
|
tab: 9,
|
|
up: 38,
|
|
down: 40
|
|
};
|
|
|
|
var PopperPlacements = exports.PopperPlacements = ['auto-start', 'auto', 'auto-end', 'top-start', 'top', 'top-end', 'right-start', 'right', 'right-end', 'bottom-end', 'bottom', 'bottom-start', 'left-end', 'left', 'left-start']; |