react-magic-zoom
Version:
React component for show zoom in image on mouse hover.
1,345 lines (1,107 loc) • 1.25 MB
JavaScript
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId])
/******/ return installedModules[moduleId].exports;
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ exports: {},
/******/ id: moduleId,
/******/ loaded: false
/******/ };
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/ // Flag the module as loaded
/******/ module.loaded = true;
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/ // Load entry module and return exports
/******/ return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.App = undefined;
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 _reactMagicZoom = __webpack_require__(1);
var _reactMagicZoom2 = _interopRequireDefault(_reactMagicZoom);
var _reactDom = __webpack_require__(159);
var _reactDom2 = _interopRequireDefault(_reactDom);
var _react = __webpack_require__(2);
var _react2 = _interopRequireDefault(_react);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
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; }
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; }
__webpack_require__(163);
var App = exports.App = function (_React$Component) {
_inherits(App, _React$Component);
function App(props) {
_classCallCheck(this, App);
var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(App).call(this, props));
_this.state = {
reflectoinItem: null,
reflectionChanged: null
};
_this.handleRefreshReflection = _this.handleRefreshReflection.bind(_this);
return _this;
}
_createClass(App, [{
key: 'handleRefreshReflection',
value: function handleRefreshReflection(item) {
this.setState({
reflectoinItem: item,
reflectionChanged: new Date()
});
}
}, {
key: 'getReflectoinItem',
value: function getReflectoinItem() {
return this.refs.id && this.refs.id.getReflection();
}
}, {
key: 'render',
value: function render() {
var reflectoinItem1 = this.getReflectoinItem(),
reflectionOpt = {
type: 'donor',
position: {
left: '100%',
top: '10%'
},
size: {
height: 100,
width: 300
}
};
return _react2.default.createElement(
'div',
null,
_react2.default.createElement(
'div',
null,
_react2.default.createElement(
'h2',
null,
'Original use case:'
),
_react2.default.createElement(
_reactMagicZoom2.default,
null,
_react2.default.createElement(
'span',
null,
_react2.default.createElement('img', { src: 'http://lorempixel.com/520/400/sports/1' })
)
)
),
_react2.default.createElement(
'div',
null,
_react2.default.createElement(
_reactMagicZoom2.default,
{
reflection: reflectionOpt,
subscribeOnReflection: this.handleRefreshReflection
},
_react2.default.createElement(
'span',
null,
_react2.default.createElement('img', { src: 'http://lorempixel.com/520/400/sports/2' })
)
),
_react2.default.createElement(
'div',
null,
reflectoinItem1
)
)
);
}
}]);
return App;
}(_react2.default.Component);
_reactDom2.default.render(_react2.default.createElement(App, null), document.getElementById('app'));
/***/ },
/* 1 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
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 _react = __webpack_require__(2);
var _react2 = _interopRequireDefault(_react);
var _reactDom = __webpack_require__(159);
var _reactDom2 = _interopRequireDefault(_reactDom);
var _classnames = __webpack_require__(160);
var _classnames2 = _interopRequireDefault(_classnames);
var _lodash = __webpack_require__(161);
var _lodash2 = _interopRequireDefault(_lodash);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
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; }
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; } /*jshint esnext: true */
var MagicZoom = function (_React$Component) {
_inherits(MagicZoom, _React$Component);
function MagicZoom(props) {
_classCallCheck(this, MagicZoom);
var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(MagicZoom).call(this, props));
_this.$image = undefined;
_this.$cursorFrame = undefined;
_this.$reflection = undefined;
_this.$imageWrapper = undefined;
_this.handleImageLoad = _this.handleImageLoad.bind(_this);
_this.handleMouseMoveOnImage = _this.handleMouseMoveOnImage.bind(_this);
_this.handleMouseLeaveFromImage = _this.handleMouseLeaveFromImage.bind(_this);
_this.handleMouseEnterOnImage = _this.handleMouseEnterOnImage.bind(_this);
_this.handleStopEvent = _this.handleStopEvent.bind(_this);
_this.delayedReflectionHandler = _lodash2.default.debounce(_this.reflectionSubscribersCall, 10);
_this.state = {
elementsState: {
imageWrapper: {
style: {}
},
reflection: {
size: {
height: 0,
width: 0
},
position: {},
background: {
position: {
x: 0,
y: 0
}
},
disabled: true
},
cursorFrame: {
//default
type: 'default',
overflow: false,
size: {
height: 0,
width: 0
},
position: {
x: 0,
y: 0,
offsetX: 0,
offsetY: 0
}
}
}
};
return _this;
}
_createClass(MagicZoom, [{
key: 'componentDidMount',
value: function componentDidMount() {
this.initializeComponentState();
this.setState(this.state);
}
}, {
key: 'componentWillUnmount',
value: function componentWillUnmount() {}
// Initialization methods
}, {
key: 'initializeComponentState',
value: function initializeComponentState() {
// ToDo move changable props to state
// preset default option by component type
var state = this.state;
this.setState(state);
}
}, {
key: 'initializeReflection',
value: function initializeReflection() {
var state = this.state;
state.elementsState.reflection.scale = this.props.reflection.scale || 2;
if (this.props.reflection.type && this.props.reflection.type !== 'auto') {
state.elementsState.reflection.type = this.props.reflection.type;
}
if (this.$image) {
state.elementsState.imageWrapper.style = {
heigth: this.$image.height,
width: this.$image.width
};
}
// auto calculation
if (!this.props.reflection.size && this.$image) {
state.elementsState.reflection.size.height = this.$image.height;
state.elementsState.reflection.size.width = this.$image.width;
} else {
state.elementsState.reflection.size.height = this.props.reflection.size.height;
state.elementsState.reflection.size.width = this.props.reflection.size.width;
}
if (this.props.reflection.position === 'right' || this.props.reflection.position === 'left' || this.props.reflection.position === 'top' || this.props.reflection.position === 'bottom') {
state.elementsState.reflection.position['left'] = '0';
state.elementsState.reflection.position['top'] = '0';
state.elementsState.reflection.position[this.props.reflection.position] = '110%';
} else {
state.elementsState.reflection.position = this.props.reflection.position;
}
this.setState(state);
}
}, {
key: 'initializeCursorFrame',
value: function initializeCursorFrame() {
var state = this.state,
cursorFrameProps = this.props.cursorFrame,
cursorFrameState = state.elementsState.cursorFrame,
scale = this.props.reflection.scale || 2;
if (cursorFrameProps) {
if (cursorFrameProps.type) {
cursorFrameState.type = cursorFrameProps.type;
}
}
if (cursorFrameState.type === 'default' || !this.$image) {
cursorFrameState.position = {
x: 0,
y: 0,
offsetX: -80,
offsetY: -80
};
cursorFrameState.size = {
height: 160,
width: 160
};
} else if (cursorFrameState.type === 'auto') {
cursorFrameState.size = {
height: state.elementsState.reflection.size.height / scale,
width: state.elementsState.reflection.size.width / scale
};
cursorFrameState.position = {
x: 0,
y: 0,
offsetX: cursorFrameState.size.width / 2,
offsetY: cursorFrameState.size.height / 2
};
}
state.elementsState.cursorFrame = cursorFrameState;
this.setState(state);
}
}, {
key: 'preInitializeElement',
value: function preInitializeElement(element, elementName, options) {
var capitalizedName = elementName.charAt(0).toUpperCase() + elementName.slice(1);
if (!element) {
if (options && options.show) {
var state = this.state;
state.elementsState.reflection.disabled = false;
this.setState(state);
}
this['initialize' + capitalizedName]();
return this['get' + capitalizedName]();
} else {
return element;
}
}
// Handler methods
}, {
key: 'handleImageLoad',
value: function handleImageLoad(event) {
if (event.target.tagName.toLowerCase() === 'img') {
var state = this.state;
this.$image = event.target;
this.$reflection = this.preInitializeElement(null, 'reflection');
this.$cursorFrame = this.preInitializeElement(null, 'cursorFrame');
this.setState(state);
}
}
}, {
key: 'handleMouseMoveOnImage',
value: function handleMouseMoveOnImage(event) {
var state = this.state,
nativeEvent = event.nativeEvent,
reflectionElement = this.getDomElement('reflection'),
cursorFrame = this.getDomElement('cursorFrame'),
eventPoint = {};
if (event.type === 'mousemove') {
if (event.target === this.$image) {
eventPoint = {
x: nativeEvent.offsetX,
y: nativeEvent.offsetY
};
} else {
eventPoint = {
x: nativeEvent.target.offsetLeft + nativeEvent.offsetX,
y: nativeEvent.target.offsetTop + nativeEvent.offsetY
};
}
} else if (event.type === 'touchmove') {
eventPoint = {
x: nativeEvent.touches[0].clientX - this.refs.zoomWrapper.offsetLeft,
y: nativeEvent.touches[0].clientY - this.refs.zoomWrapper.offsetTop
};
event.preventDefault();
}
if (event.target === this.$image) {
this.calculateMouseAndCursorPositionByImage(state, eventPoint, reflectionElement, cursorFrame);
} else if (cursorFrame === event.target) {
this.calculateMouseAndCursorPositionByCursorFrame(state, eventPoint, cursorFrame);
}
this.setState(state);
}
}, {
key: 'handleMouseLeaveFromImage',
value: function handleMouseLeaveFromImage(event) {
var state = this.state;
state.elementsState.reflection.disabled = true;
this.setState(state);
}
}, {
key: 'handleMouseEnterOnImage',
value: function handleMouseEnterOnImage(event) {
var state = this.state;
state.elementsState.reflection.disabled = false;
// should update cursor postion
this.setState(state);
}
}, {
key: 'handleStopEvent',
value: function handleStopEvent(event) {
event.stopPropagation();
}
}, {
key: 'reflectionSubscribersCall',
value: function reflectionSubscribersCall(element) {
this.props.subscribeOnReflection && this.props.subscribeOnReflection(element);
}
// Calculators
}, {
key: 'calculateMouseAndCursorPositionByImage',
value: function calculateMouseAndCursorPositionByImage(state, eventPoint, reflectionElement, cursorFrame) {
state.elementsState.reflection.background.position.x = -(eventPoint.x * this.state.elementsState.reflection.scale - reflectionElement.offsetWidth / 2);
state.elementsState.reflection.background.position.y = -(eventPoint.y * this.state.elementsState.reflection.scale - reflectionElement.offsetHeight / 2);
// frame
if (!state.elementsState.cursorFrame.overflow) {
this.calculateCursorPositionByClosestBorder(state, eventPoint, {
width: this.$image ? this.$image.width : 0,
height: this.$image ? this.$image.height : 0
});
} else if (cursorFrame) {
state.elementsState.cursorFrame.position.y = eventPoint.y;
state.elementsState.cursorFrame.position.x = eventPoint.x;
}
}
}, {
key: 'calculateMouseAndCursorPositionByCursorFrame',
value: function calculateMouseAndCursorPositionByCursorFrame(state, eventPoint, cursorFrame) {
var imageSize = {};
imageSize = {
width: this.$image ? this.$image.width : 0,
height: this.$image ? this.$image.height : 0
};
// hide if mouse blur
if (eventPoint.x > imageSize.width || eventPoint.x < 0 || eventPoint.y > imageSize.height || eventPoint.y < 0) {
state.elementsState.reflection.disabled = true;
} else {
if (!state.elementsState.cursorFrame.overflow) {
this.calculateCursorPositionByClosestBorder(state, eventPoint, imageSize);
} else {
if (cursorFrame) {
state.elementsState.cursorFrame.position.x = eventPoint.x;
state.elementsState.cursorFrame.position.y = eventPoint.y;
}
}
state.elementsState.reflection.background.position.x = -(eventPoint.x * this.state.elementsState.reflection.scale - this.state.elementsState.reflection.size.width / 2);
state.elementsState.reflection.background.position.y = -(eventPoint.y * this.state.elementsState.reflection.scale - this.state.elementsState.reflection.size.height / 2);
}
}
}, {
key: 'calculateCursorPositionByClosestBorder',
value: function calculateCursorPositionByClosestBorder(state, eventPoint, imageSize) {
if (eventPoint.x + state.elementsState.cursorFrame.size.width / 2 >= imageSize.width || eventPoint.x - state.elementsState.cursorFrame.size.width / 2 <= 0) {
if (eventPoint.x + state.elementsState.cursorFrame.size.width / 2 >= imageSize.width) {
state.elementsState.cursorFrame.position.x = imageSize.width - state.elementsState.cursorFrame.size.width / 2;
}
if (eventPoint.x - state.elementsState.cursorFrame.size.width / 2 <= 0) {
state.elementsState.cursorFrame.position.x = state.elementsState.cursorFrame.size.width / 2;
}
} else {
state.elementsState.cursorFrame.position.x = eventPoint.x;
}
if (!state.elementsState.cursorFrame.overflow && eventPoint.y + state.elementsState.cursorFrame.size.height / 2 >= imageSize.height || eventPoint.y - state.elementsState.cursorFrame.size.height / 2 <= 0) {
if (eventPoint.y + state.elementsState.cursorFrame.size.height / 2 >= imageSize.height) {
state.elementsState.cursorFrame.position.y = imageSize.height - state.elementsState.cursorFrame.size.height / 2;
}
if (eventPoint.y - state.elementsState.cursorFrame.size.height / 2 <= 0) {
state.elementsState.cursorFrame.position.y = state.elementsState.cursorFrame.size.height / 2;
}
} else {
state.elementsState.cursorFrame.position.y = eventPoint.y;
}
}
}, {
key: 'getDomElement',
value: function getDomElement(refName, existReflection) {
var existElement = _reactDom2.default.findDOMNode(this.refs[refName]);
return existElement || this.preInitializeElement(existReflection, refName, {
show: true
});
}
// Pre-render methods
}, {
key: 'getCursorFrame',
value: function getCursorFrame() {
var cursorFrameSettings = this.state.elementsState.cursorFrame,
classNames = 'magic-zoom__cursor-frame',
style = {},
element;
if (this.state.elementsState.reflection.disabled) {
return null;
}
if (cursorFrameSettings.type === 'default') {
classNames += ' magic-zoom__cursor-frame--default';
} else if (cursorFrameSettings.type === 'auto') {
classNames += ' magic-zoom__cursor-frame--auto';
style = {
width: cursorFrameSettings.size.width + 'px',
height: cursorFrameSettings.size.height + 'px'
};
}
style.top = cursorFrameSettings.position.y - cursorFrameSettings.position.offsetY + 'px';
style.left = cursorFrameSettings.position.x - cursorFrameSettings.position.offsetX + 'px';
element = _react2.default.createElement('div', { ref: 'cursorFrame',
className: classNames,
style: style
});
return element;
}
}, {
key: 'getReflection',
value: function getReflection() {
var state = this.state,
reflectionSettings = this.state.elementsState.reflection,
style = {
height: reflectionSettings.size.height + 'px',
width: reflectionSettings.size.width + 'px'
},
element;
style = _lodash2.default.assign(style, reflectionSettings.position);
if (reflectionSettings.disabled) {
return null;
}
if (this.$image) {
style.backgroundImage = 'url(' + this.$image.src + ')';
style.backgroundSize = state.elementsState.imageWrapper.style.width * reflectionSettings.scale + 'px ' + state.elementsState.imageWrapper.style.heigth * reflectionSettings.scale + 'px';
style.backgroundPosition = reflectionSettings.background.position.x + 'px ' + reflectionSettings.background.position.y + 'px';
}
element = _react2.default.createElement('div', {
ref: 'reflection',
style: style,
className: 'magic-zoom__reflection',
onMouseMove: this.handleMouseLeaveFromImage,
onTouchMove: this.handleMouseLeaveFromImage
});
if (this.props.subscribeOnReflection) {
this.delayedReflectionHandler(element);
}
return element;
}
}, {
key: 'render',
value: function render() {
var cursorFrame = this.getCursorFrame(),
imageReflection = this.getReflection(),
wrapperStyle = this.state.elementsState.imageWrapper.style;
if (this.props.type === 'donor') {
imageReflection = null;
}
return _react2.default.createElement(
'div',
{
ref: 'zoomWrapper',
className: (0, _classnames2.default)('magic-zoom__wrapper', this.props.className),
onLoad: this.handleImageLoad,
onMouseMove: this.handleMouseMoveOnImage,
onMouseEnter: this.handleMouseEnterOnImage,
onMouseLeave: this.handleMouseLeaveFromImage,
onTouchMove: this.handleMouseMoveOnImage,
onTouchStart: this.handleMouseEnterOnImage,
onTouchEnd: this.handleMouseLeaveFromImage,
onTouchCancel: this.handleMouseLeaveFromImage,
style: wrapperStyle
},
this.props.children,
cursorFrame,
imageReflection
);
}
}]);
return MagicZoom;
}(_react2.default.Component);
exports.default = MagicZoom;
MagicZoom.propTypes = {
children: _react2.default.PropTypes.element.isRequired,
type: _react2.default.PropTypes.oneOf(['auto', 'custom', 'invider', 'donor'])
};
MagicZoom.defaultProps = {
// temporary for testing
type: 'auto',
cursorFrame: {
type: 'auto',
// can be {heigth: int, width: int} or auto string
size: 'auto',
// ablility of frame moving out of original image
overflow: true
},
reflection: {
type: 'auto',
// Value: 'left', 'right', 'top', 'bottom' - position of
// reflection
position: 'left',
// Value: @flaot - scale coefficient
scale: 2
}
};
/***/ },
/* 2 */
/***/ function(module, exports, __webpack_require__) {
'use strict';
module.exports = __webpack_require__(3);
/***/ },
/* 3 */
/***/ function(module, exports, __webpack_require__) {
/**
* Copyright 2013-2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule React
*/
'use strict';
var ReactDOM = __webpack_require__(4);
var ReactDOMServer = __webpack_require__(149);
var ReactIsomorphic = __webpack_require__(153);
var assign = __webpack_require__(40);
var deprecated = __webpack_require__(158);
// `version` will be added here by ReactIsomorphic.
var React = {};
assign(React, ReactIsomorphic);
assign(React, {
// ReactDOM
findDOMNode: deprecated('findDOMNode', 'ReactDOM', 'react-dom', ReactDOM, ReactDOM.findDOMNode),
render: deprecated('render', 'ReactDOM', 'react-dom', ReactDOM, ReactDOM.render),
unmountComponentAtNode: deprecated('unmountComponentAtNode', 'ReactDOM', 'react-dom', ReactDOM, ReactDOM.unmountComponentAtNode),
// ReactDOMServer
renderToString: deprecated('renderToString', 'ReactDOMServer', 'react-dom/server', ReactDOMServer, ReactDOMServer.renderToString),
renderToStaticMarkup: deprecated('renderToStaticMarkup', 'ReactDOMServer', 'react-dom/server', ReactDOMServer, ReactDOMServer.renderToStaticMarkup)
});
React.__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED = ReactDOM;
React.__SECRET_DOM_SERVER_DO_NOT_USE_OR_YOU_WILL_BE_FIRED = ReactDOMServer;
module.exports = React;
/***/ },
/* 4 */
/***/ function(module, exports, __webpack_require__) {
/* WEBPACK VAR INJECTION */(function(process) {/**
* Copyright 2013-2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule ReactDOM
*/
/* globals __REACT_DEVTOOLS_GLOBAL_HOOK__*/
'use strict';
var ReactCurrentOwner = __webpack_require__(6);
var ReactDOMTextComponent = __webpack_require__(7);
var ReactDefaultInjection = __webpack_require__(72);
var ReactInstanceHandles = __webpack_require__(46);
var ReactMount = __webpack_require__(29);
var ReactPerf = __webpack_require__(19);
var ReactReconciler = __webpack_require__(51);
var ReactUpdates = __webpack_require__(55);
var ReactVersion = __webpack_require__(147);
var findDOMNode = __webpack_require__(92);
var renderSubtreeIntoContainer = __webpack_require__(148);
var warning = __webpack_require__(26);
ReactDefaultInjection.inject();
var render = ReactPerf.measure('React', 'render', ReactMount.render);
var React = {
findDOMNode: findDOMNode,
render: render,
unmountComponentAtNode: ReactMount.unmountComponentAtNode,
version: ReactVersion,
/* eslint-disable camelcase */
unstable_batchedUpdates: ReactUpdates.batchedUpdates,
unstable_renderSubtreeIntoContainer: renderSubtreeIntoContainer
};
// Inject the runtime into a devtools global hook regardless of browser.
// Allows for debugging when the hook is injected on the page.
/* eslint-enable camelcase */
if (typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.inject === 'function') {
__REACT_DEVTOOLS_GLOBAL_HOOK__.inject({
CurrentOwner: ReactCurrentOwner,
InstanceHandles: ReactInstanceHandles,
Mount: ReactMount,
Reconciler: ReactReconciler,
TextComponent: ReactDOMTextComponent
});
}
if (process.env.NODE_ENV !== 'production') {
var ExecutionEnvironment = __webpack_require__(10);
if (ExecutionEnvironment.canUseDOM && window.top === window.self) {
// First check if devtools is not installed
if (typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ === 'undefined') {
// If we're in Chrome or Firefox, provide a download link if not installed.
if (navigator.userAgent.indexOf('Chrome') > -1 && navigator.userAgent.indexOf('Edge') === -1 || navigator.userAgent.indexOf('Firefox') > -1) {
console.debug('Download the React DevTools for a better development experience: ' + 'https://fb.me/react-devtools');
}
}
// If we're in IE8, check to see if we are in compatibility mode and provide
// information on preventing compatibility mode
var ieCompatibilityMode = document.documentMode && document.documentMode < 8;
process.env.NODE_ENV !== 'production' ? warning(!ieCompatibilityMode, 'Internet Explorer is running in compatibility mode; please add the ' + 'following tag to your HTML to prevent this from happening: ' + '<meta http-equiv="X-UA-Compatible" content="IE=edge" />') : undefined;
var expectedFeatures = [
// shims
Array.isArray, Array.prototype.every, Array.prototype.forEach, Array.prototype.indexOf, Array.prototype.map, Date.now, Function.prototype.bind, Object.keys, String.prototype.split, String.prototype.trim,
// shams
Object.create, Object.freeze];
for (var i = 0; i < expectedFeatures.length; i++) {
if (!expectedFeatures[i]) {
console.error('One or more ES5 shim/shams expected by React are not available: ' + 'https://fb.me/react-warning-polyfills');
break;
}
}
}
}
module.exports = React;
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(5)))
/***/ },
/* 5 */
/***/ function(module, exports) {
// shim for using process in browser
var process = module.exports = {};
var queue = [];
var draining = false;
var currentQueue;
var queueIndex = -1;
function cleanUpNextTick() {
draining = false;
if (currentQueue.length) {
queue = currentQueue.concat(queue);
} else {
queueIndex = -1;
}
if (queue.length) {
drainQueue();
}
}
function drainQueue() {
if (draining) {
return;
}
var timeout = setTimeout(cleanUpNextTick);
draining = true;
var len = queue.length;
while(len) {
currentQueue = queue;
queue = [];
while (++queueIndex < len) {
if (currentQueue) {
currentQueue[queueIndex].run();
}
}
queueIndex = -1;
len = queue.length;
}
currentQueue = null;
draining = false;
clearTimeout(timeout);
}
process.nextTick = function (fun) {
var args = new Array(arguments.length - 1);
if (arguments.length > 1) {
for (var i = 1; i < arguments.length; i++) {
args[i - 1] = arguments[i];
}
}
queue.push(new Item(fun, args));
if (queue.length === 1 && !draining) {
setTimeout(drainQueue, 0);
}
};
// v8 likes predictible objects
function Item(fun, array) {
this.fun = fun;
this.array = array;
}
Item.prototype.run = function () {
this.fun.apply(null, this.array);
};
process.title = 'browser';
process.browser = true;
process.env = {};
process.argv = [];
process.version = ''; // empty string to avoid regexp issues
process.versions = {};
function noop() {}
process.on = noop;
process.addListener = noop;
process.once = noop;
process.off = noop;
process.removeListener = noop;
process.removeAllListeners = noop;
process.emit = noop;
process.binding = function (name) {
throw new Error('process.binding is not supported');
};
process.cwd = function () { return '/' };
process.chdir = function (dir) {
throw new Error('process.chdir is not supported');
};
process.umask = function() { return 0; };
/***/ },
/* 6 */
/***/ function(module, exports) {
/**
* Copyright 2013-2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule ReactCurrentOwner
*/
'use strict';
/**
* Keeps track of the current owner.
*
* The current owner is the component who should own any components that are
* currently being constructed.
*/
var ReactCurrentOwner = {
/**
* @internal
* @type {ReactComponent}
*/
current: null
};
module.exports = ReactCurrentOwner;
/***/ },
/* 7 */
/***/ function(module, exports, __webpack_require__) {
/* WEBPACK VAR INJECTION */(function(process) {/**
* Copyright 2013-2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule ReactDOMTextComponent
* @typechecks static-only
*/
'use strict';
var DOMChildrenOperations = __webpack_require__(8);
var DOMPropertyOperations = __webpack_require__(23);
var ReactComponentBrowserEnvironment = __webpack_require__(27);
var ReactMount = __webpack_require__(29);
var assign = __webpack_require__(40);
var escapeTextContentForBrowser = __webpack_require__(22);
var setTextContent = __webpack_require__(21);
var validateDOMNesting = __webpack_require__(71);
/**
* Text nodes violate a couple assumptions that React makes about components:
*
* - When mounting text into the DOM, adjacent text nodes are merged.
* - Text nodes cannot be assigned a React root ID.
*
* This component is used to wrap strings in elements so that they can undergo
* the same reconciliation that is applied to elements.
*
* TODO: Investigate representing React components in the DOM with text nodes.
*
* @class ReactDOMTextComponent
* @extends ReactComponent
* @internal
*/
var ReactDOMTextComponent = function (props) {
// This constructor and its argument is currently used by mocks.
};
assign(ReactDOMTextComponent.prototype, {
/**
* @param {ReactText} text
* @internal
*/
construct: function (text) {
// TODO: This is really a ReactText (ReactNode), not a ReactElement
this._currentElement = text;
this._stringText = '' + text;
// Properties
this._rootNodeID = null;
this._mountIndex = 0;
},
/**
* Creates the markup for this text node. This node is not intended to have
* any features besides containing text content.
*
* @param {string} rootID DOM ID of the root node.
* @param {ReactReconcileTransaction|ReactServerRenderingTransaction} transaction
* @return {string} Markup for this text node.
* @internal
*/
mountComponent: function (rootID, transaction, context) {
if (process.env.NODE_ENV !== 'production') {
if (context[validateDOMNesting.ancestorInfoContextKey]) {
validateDOMNesting('span', null, context[validateDOMNesting.ancestorInfoContextKey]);
}
}
this._rootNodeID = rootID;
if (transaction.useCreateElement) {
var ownerDocument = context[ReactMount.ownerDocumentContextKey];
var el = ownerDocument.createElement('span');
DOMPropertyOperations.setAttributeForID(el, rootID);
// Populate node cache
ReactMount.getID(el);
setTextContent(el, this._stringText);
return el;
} else {
var escapedText = escapeTextContentForBrowser(this._stringText);
if (transaction.renderToStaticMarkup) {
// Normally we'd wrap this in a `span` for the reasons stated above, but
// since this is a situation where React won't take over (static pages),
// we can simply return the text as it is.
return escapedText;
}
return '<span ' + DOMPropertyOperations.createMarkupForID(rootID) + '>' + escapedText + '</span>';
}
},
/**
* Updates this component by updating the text content.
*
* @param {ReactText} nextText The next text content
* @param {ReactReconcileTransaction} transaction
* @internal
*/
receiveComponent: function (nextText, transaction) {
if (nextText !== this._currentElement) {
this._currentElement = nextText;
var nextStringText = '' + nextText;
if (nextStringText !== this._stringText) {
// TODO: Save this as pending props and use performUpdateIfNecessary
// and/or updateComponent to do the actual update for consistency with
// other component types?
this._stringText = nextStringText;
var node = ReactMount.getNode(this._rootNodeID);
DOMChildrenOperations.updateTextContent(node, nextStringText);
}
}
},
unmountComponent: function () {
ReactComponentBrowserEnvironment.unmountIDFromEnvironment(this._rootNodeID);
}
});
module.exports = ReactDOMTextComponent;
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(5)))
/***/ },
/* 8 */
/***/ function(module, exports, __webpack_require__) {
/* WEBPACK VAR INJECTION */(function(process) {/**
* Copyright 2013-2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule DOMChildrenOperations
* @typechecks static-only
*/
'use strict';
var Danger = __webpack_require__(9);
var ReactMultiChildUpdateTypes = __webpack_require__(17);
var ReactPerf = __webpack_require__(19);
var setInnerHTML = __webpack_require__(20);
var setTextContent = __webpack_require__(21);
var invariant = __webpack_require__(14);
/**
* Inserts `childNode` as a child of `parentNode` at the `index`.
*
* @param {DOMElement} parentNode Parent node in which to insert.
* @param {DOMElement} childNode Child node to insert.
* @param {number} index Index at which to insert the child.
* @internal
*/
function insertChildAt(parentNode, childNode, index) {
// By exploiting arrays returning `undefined` for an undefined index, we can
// rely exclusively on `insertBefore(node, null)` instead of also using
// `appendChild(node)`. However, using `undefined` is not allowed by all
// browsers so we must replace it with `null`.
// fix render order error in safari
// IE8 will throw error when index out of list size.
var beforeChild = index >= parentNode.childNodes.length ? null : parentNode.childNodes.item(index);
parentNode.insertBefore(childNode, beforeChild);
}
/**
* Operations for updating with DOM children.
*/
var DOMChildrenOperations = {
dangerouslyReplaceNodeWithMarkup: Danger.dangerouslyReplaceNodeWithMarkup,
updateTextContent: setTextContent,
/**
* Updates a component's children by processing a series of updates. The
* update configurations are each expected to have a `parentNode` property.
*
* @param {array<object>} updates List of update configurations.
* @param {array<string>} markupList List of markup strings.
* @internal
*/
processUpdates: function (updates, markupList) {
var update;
// Mapping from parent IDs to initial child orderings.
var initialChildren = null;
// List of children that will be moved or removed.
var updatedChildren = null;
for (var i = 0; i < updates.length; i++) {
update = updates[i];
if (update.type === ReactMultiChildUpdateTypes.MOVE_EXISTING || update.type === ReactMultiChildUpdateTypes.REMOVE_NODE) {
var updatedIndex = update.fromIndex;
var updatedChild = update.parentNode.childNodes[updatedIndex];
var parentID = update.parentID;
!updatedChild ? process.env.NODE_ENV !== 'production' ? invariant(false, 'processUpdates(): Unable to find child %s of element. This ' + 'probably means the DOM was unexpectedly mutated (e.g., by the ' + 'browser), usually due to forgetting a <tbody> when using tables, ' + 'nesting tags like <form>, <p>, or <a>, or using non-SVG elements ' + 'in an <svg> parent. Try inspecting the child nodes of the element ' + 'with React ID `%s`.', updatedIndex, parentID) : invariant(false) : undefined;
initialChildren = initialChildren || {};
initialChildren[parentID] = initialChildren[parentID] || [];
initialChildren[parentID][updatedIndex] = updatedChild;
updatedChildren = updatedChildren || [];
updatedChildren.push(updatedChild);
}
}
var renderedMarkup;
// markupList is either a list of markup or just a list of elements
if (markupList.length && typeof markupList[0] === 'string') {
renderedMarkup = Danger.dangerouslyRenderMarkup(markupList);
} else {
renderedMarkup = markupList;
}
// Remove updated children first so that `toIndex` is consistent.
if (updatedChildren) {
for (var j = 0; j < updatedChildren.length; j++) {
updatedChildren[j].parentNode.removeChild(updatedChildren[j]);
}
}
for (var k = 0; k < updates.length; k++) {
update = updates[k];
switch (update.type) {
case ReactMultiChildUpdateTypes.INSERT_MARKUP:
insertChildAt(update.parentNode, renderedMarkup[update.markupIndex], update.toIndex);
break;
case ReactMultiChildUpdateTypes.MOVE_EXISTING:
insertChildAt(update.parentNode, initialChildren[update.parentID][update.fromIndex], update.toIndex);
break;
case ReactMultiChildUpdateTypes.SET_MARKUP:
setInnerHTML(update.parentNode, update.content);
break;
case ReactMultiChildUpdateTypes.TEXT_CONTENT:
setTextContent(update.parentNode, update.content);
break;
case ReactMultiChildUpdateTypes.REMOVE_NODE:
// Already removed by the for-loop above.
break;
}
}
}
};
ReactPerf.measureMethods(DOMChildrenOperations, 'DOMChildrenOperations', {
updateTextContent: 'updateTextContent'
});
module.exports = DOMChildrenOperations;
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(5)))
/***/ },
/* 9 */
/***/ function(module, exports, __webpack_require__) {
/* WEBPACK VAR INJECTION */(function(process) {/**
* Copyright 2013-2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule Danger
* @typechecks static-only
*/
'use strict';
var ExecutionEnvironment = __webpack_require__(10);
var createNodesFromMarkup = __webpack_require__(11);
var emptyFunction = __webpack_require__(16);
var getMarkupWrap = __webpack_require__(15);
var invariant = __webpack_require__(14);
var OPEN_TAG_NAME_EXP = /^(<[^ \/>]+)/;
var RESULT_INDEX_ATTR = 'data-danger-index';
/**
* Extracts the `nodeName` from a string of markup.
*
* NOTE: Extracting the `nodeName` does not require a regular expression match
* because we make assumptions about React-generated markup (i.e. there are no
* spaces surrounding the opening tag and there is at least one attribute).
*
* @param {string} markup String of markup.
* @return {string} Node name of the supplied markup.
* @see http://jsperf.com/extract-nodename
*/
function getNodeName(markup) {
return markup.substring(1, markup.indexOf(' '));
}
var Danger = {
/**
* Renders markup into an array of nodes. The markup is expected to render
* into a list of root nodes. Also, the length of `resultList` and
* `markupList` should be the same.
*
* @param {array<string>} markupList List of markup strings to render.
* @return {array<DOMElement>} List of rendered nodes.
* @internal
*/
dangerouslyRenderMarkup: function (markupList) {
!ExecutionEnvironment.canUseDOM ? process.env.NODE_ENV !== 'production' ? invariant(false, 'dangerouslyRenderMarkup(...): Cannot render markup in a worker ' + 'thread. Make sure `window` and `document` are available globally ' + 'before requiring React when unit testing or use ' + 'ReactDOMServer.renderToString for server rendering.') : invariant(false) : undefined;
var nodeName;
var markupByNodeName = {};
// Group markup by `nodeName` if a wrap is necessary, else by '*'.
for (var i = 0; i < markupList.length; i++) {
!markupList[i] ? process.env.NODE_ENV !== 'production' ? invariant(false, 'dangerouslyRenderMarkup(...): Missing markup.') : invariant(false) : undefined;
nodeName = getNodeName(markupList[i]);
nodeName = getMarkupWrap(nodeName) ? nodeName : '*';
markupByNodeName[nodeName] = markupByNodeName[nodeName] || [];
markupByNodeName[nodeName][i] = markupList[i];
}
var resultList = [];
var resultListAssignmentCount = 0;
for (nodeName in markupByNodeName) {
if (!markupByNodeName.hasOwnProperty(nodeName)) {
continue;
}
var markupListByNodeName = markupByNodeName[nodeName];
// This for-in loop skips the holes of the sparse array. The order of
// iteration should follow the order of assignment, which happens to match
// numerical index order, but we don't rely on that.
var resultIndex;
for (resultIndex in markupListByNodeName) {
if (markupListByNodeName.hasOwnProperty(resultIndex)) {
var markup = markupListByNodeName[resultIndex];
// Push the requested markup with an additional RESULT_INDEX_ATTR
// attribute. If the markup