UNPKG

@mnmtanish/react-split-pane

Version:
1,488 lines (1,246 loc) 1.78 MB
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ 'use strict'; var _react = require('react'); var _react2 = _interopRequireDefault(_react); var _reactDom = require('react-dom'); var _reactDom2 = _interopRequireDefault(_reactDom); var _SplitPane = require('../lib/SplitPane'); var _SplitPane2 = _interopRequireDefault(_SplitPane); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } var HSplit = _react2.default.createClass({ displayName: 'HSplit', render: function render() { var style = { cursor: 'row-resize', background: '#EEEEEE', borderBottom: 'solid #E0E0E0 1px', borderTop: 'solid #E0E0E0 1px', width: '100%' }; var headerStyle = { color: '#888', float: 'left', fontFamily: 'sans-serif', fontSize: '11px', letterSpacing: '1px', lineHeight: 1, margin: 0, padding: '8px 10px 8px 10px', textTransform: 'uppercase' }; var buttonStyle = { background: 'transparent', border: 'none', color: '#888', float: 'right', fontFamily: 'sans-serif', fontSize: '11px', lineHeight: 1, outline: 'none', padding: '8px 15px 8px 10px' }; var clearFix = { clear: 'both' }; return _react2.default.createElement( 'div', { style: style }, _react2.default.createElement( 'h3', { style: headerStyle }, this.props.header ), _react2.default.createElement( 'button', { style: buttonStyle, onClick: this.props.onClose }, '✕' ), _react2.default.createElement('div', { style: clearFix }) ); } }); HSplit.propTypes = { onClose: _react.PropTypes.func.isRequired, header: _react.PropTypes.string.isRequired }; var Example = _react2.default.createClass({ displayName: 'Example', render: function render() { var close = function close() { return alert('close button clicked'); }; var hsplit = _react2.default.createElement(HSplit, { header: 'Split Pane Header', onClose: close }); return _react2.default.createElement( _SplitPane2.default, { split: 'vertical', minSize: 50, maxSize: 300, defaultSize: 250, className: 'primary' }, _react2.default.createElement('div', null), _react2.default.createElement( _SplitPane2.default, { split: 'horizontal', primary: 'second', defaultSize: 250, resizerChildren: hsplit }, _react2.default.createElement('div', null), _react2.default.createElement('div', null) ) ); } }); _reactDom2.default.render(_react2.default.createElement(Example, null), document.getElementById("container")); },{"../lib/SplitPane":5,"react":165,"react-dom":35}],2:[function(require,module,exports){ 'use strict'; var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; }; 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 = require('react'); 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 === "undefined" ? "undefined" : _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 === "undefined" ? "undefined" : _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 HSplit = function (_Component) { _inherits(HSplit, _Component); function HSplit() { var _Object$getPrototypeO; _classCallCheck(this, HSplit); for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } var _this = _possibleConstructorReturn(this, (_Object$getPrototypeO = Object.getPrototypeOf(HSplit)).call.apply(_Object$getPrototypeO, [this].concat(args))); _this.state = {}; return _this; } _createClass(HSplit, [{ key: 'render', value: function render() { var style = { cursor: 'row-resize', background: '#EEEEEE', borderBottom: 'solid #E0E0E0 1px', borderTop: 'solid #E0E0E0 1px', height: '3px', width: '100%' }; return _react2.default.createElement('div', { style: style }); } }]); return HSplit; }(_react.Component); exports.default = HSplit; module.exports = exports['default']; },{"react":165}],3:[function(require,module,exports){ 'use strict'; var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; }; 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 = require('react'); var _react2 = _interopRequireDefault(_react); var _reactVendorPrefix = require('react-vendor-prefix'); var _reactVendorPrefix2 = _interopRequireDefault(_reactVendorPrefix); 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 === "undefined" ? "undefined" : _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 === "undefined" ? "undefined" : _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 Pane = function (_Component) { _inherits(Pane, _Component); function Pane() { var _Object$getPrototypeO; _classCallCheck(this, Pane); for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } var _this = _possibleConstructorReturn(this, (_Object$getPrototypeO = Object.getPrototypeOf(Pane)).call.apply(_Object$getPrototypeO, [this].concat(args))); _this.state = {}; return _this; } _createClass(Pane, [{ key: 'render', value: function render() { var split = this.props.split; var classes = ['Pane', split, this.props.className]; var style = { flex: 1, position: 'relative', outline: 'none' }; if (this.state.size !== undefined) { if (split === 'vertical') { style.width = this.state.size; } else { style.height = this.state.size; style.display = 'flex'; } style.flex = 'none'; } var prefixed = _reactVendorPrefix2.default.prefix({ styles: style }); return _react2.default.createElement('div', { className: classes.join(' '), style: prefixed.styles }, this.props.children); } }]); return Pane; }(_react.Component); Pane.propTypes = { split: _react.PropTypes.oneOf(['vertical', 'horizontal']), className: _react.PropTypes.string.isRequired, children: _react.PropTypes.object.isRequired }; exports.default = Pane; module.exports = exports['default']; },{"react":165,"react-vendor-prefix":36}],4:[function(require,module,exports){ 'use strict'; var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; }; Object.defineProperty(exports, "__esModule", { value: true }); 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 _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 = require('react'); 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 === "undefined" ? "undefined" : _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 === "undefined" ? "undefined" : _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 Resizer = function (_Component) { _inherits(Resizer, _Component); function Resizer() { var _Object$getPrototypeO; _classCallCheck(this, Resizer); for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } var _this = _possibleConstructorReturn(this, (_Object$getPrototypeO = Object.getPrototypeOf(Resizer)).call.apply(_Object$getPrototypeO, [this].concat(args))); _this.onMouseDown = _this.onMouseDown.bind(_this); return _this; } _createClass(Resizer, [{ key: 'onMouseDown', value: function onMouseDown(event) { this.props.onMouseDown(event); } }, { key: 'render', value: function render() { var _props = this.props; var split = _props.split; var className = _props.className; var children = _props.children; var classes = ['Resizer', split, className]; var style = {}; if (split === 'vertical') { _extends(style, { height: '100%' }); } else { _extends(style, { width: '100%' }); } return _react2.default.createElement('div', { style: style, className: classes.join(' '), onMouseDown: this.onMouseDown }, children); } }]); return Resizer; }(_react.Component); Resizer.propTypes = { onMouseDown: _react.PropTypes.func.isRequired, split: _react.PropTypes.oneOf(['vertical', 'horizontal']), className: _react.PropTypes.string.isRequired, children: _react.PropTypes.node.isRequired }; exports.default = Resizer; module.exports = exports['default']; },{"react":165}],5:[function(require,module,exports){ 'use strict'; var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; }; Object.defineProperty(exports, "__esModule", { value: true }); 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 _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 = require('react'); var _react2 = _interopRequireDefault(_react); var _reactDom = require('react-dom'); var _reactDom2 = _interopRequireDefault(_reactDom); var _Pane = require('./Pane'); var _Pane2 = _interopRequireDefault(_Pane); var _VSplit = require('./VSplit'); var _VSplit2 = _interopRequireDefault(_VSplit); var _HSplit = require('./HSplit'); var _HSplit2 = _interopRequireDefault(_HSplit); var _Resizer = require('./Resizer'); var _Resizer2 = _interopRequireDefault(_Resizer); var _reactVendorPrefix = require('react-vendor-prefix'); var _reactVendorPrefix2 = _interopRequireDefault(_reactVendorPrefix); 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 === "undefined" ? "undefined" : _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 === "undefined" ? "undefined" : _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 SplitPane = function (_Component) { _inherits(SplitPane, _Component); function SplitPane() { var _Object$getPrototypeO; _classCallCheck(this, SplitPane); for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } var _this = _possibleConstructorReturn(this, (_Object$getPrototypeO = Object.getPrototypeOf(SplitPane)).call.apply(_Object$getPrototypeO, [this].concat(args))); _this.onMouseDown = _this.onMouseDown.bind(_this); _this.onMouseMove = _this.onMouseMove.bind(_this); _this.onMouseUp = _this.onMouseUp.bind(_this); _this.state = { active: false, resized: false }; return _this; } _createClass(SplitPane, [{ key: 'componentDidMount', value: function componentDidMount() { this.setSize(this.props, this.state); document.addEventListener('mouseup', this.onMouseUp); document.addEventListener('mousemove', this.onMouseMove); } }, { key: 'componentWillReceiveProps', value: function componentWillReceiveProps(props) { this.setSize(props, this.state); } }, { key: 'componentWillUnmount', value: function componentWillUnmount() { document.removeEventListener('mouseup', this.onMouseUp); document.removeEventListener('mousemove', this.onMouseMove); } }, { key: 'onMouseDown', value: function onMouseDown(event) { if (this.props.allowResize && !this.props.size) { this.unFocus(); var position = this.props.split === 'vertical' ? event.clientX : event.clientY; if (typeof this.props.onDragStarted === 'function') { this.props.onDragStarted(); } this.setState({ active: true, position: position }); } } }, { key: 'onMouseMove', value: function onMouseMove(event) { if (this.props.allowResize && !this.props.size) { if (this.state.active) { this.unFocus(); var isPrimaryFirst = this.props.primary === 'first'; var ref = isPrimaryFirst ? this.refs.pane1 : this.refs.pane2; if (ref) { var node = _reactDom2.default.findDOMNode(ref); if (node.getBoundingClientRect) { var width = node.getBoundingClientRect().width; var height = node.getBoundingClientRect().height; var current = this.props.split === 'vertical' ? event.clientX : event.clientY; var size = this.props.split === 'vertical' ? width : height; var position = this.state.position; var newPosition = isPrimaryFirst ? position - current : current - position; var newSize = size - newPosition; if (newSize < this.props.minSize) { newSize = this.props.minSize; } else if (newSize > this.props.maxSize) { newSize = this.props.maxSize; } else { this.setState({ position: current, resized: true }); } if (this.props.onChange) { this.props.onChange(newSize); } this.setState({ draggedSize: newSize }); ref.setState({ size: newSize }); } } } } } }, { key: 'onMouseUp', value: function onMouseUp() { if (this.props.allowResize && !this.props.size) { if (this.state.active) { if (typeof this.props.onDragFinished === 'function') { this.props.onDragFinished(); } this.setState({ active: false }); } } } }, { key: 'setSize', value: function setSize(props, state) { var ref = this.props.primary === 'first' ? this.refs.pane1 : this.refs.pane2; var newSize = void 0; if (ref) { newSize = props.size || state && state.draggedSize || props.defaultSize || props.minSize; ref.setState({ size: newSize }); } } }, { key: 'unFocus', value: function unFocus() { if (document.selection) { document.selection.empty(); } else { window.getSelection().removeAllRanges(); } } }, { key: 'render', value: function render() { var _props = this.props; var split = _props.split; var allowResize = _props.allowResize; var disabledClass = allowResize ? '' : 'disabled'; var style = { display: 'flex', flex: 1, position: 'relative', outline: 'none', overflow: 'hidden', MozUserSelect: 'text', WebkitUserSelect: 'text', msUserSelect: 'text', userSelect: 'text' }; if (split === 'vertical') { _extends(style, { flexDirection: 'row', height: '100%', position: 'absolute', left: 0, right: 0 }); } else { _extends(style, { flexDirection: 'column', height: '100%', minHeight: '100%', position: 'absolute', top: 0, bottom: 0, width: '100%' }); } var resizerChildren = null; if (this.props.resizerChildren) { resizerChildren = this.props.resizerChildren; } else if (split === 'vertical') { resizerChildren = _react2.default.createElement(_VSplit2.default, null); } else { resizerChildren = _react2.default.createElement(_HSplit2.default, null); } var children = this.props.children; var classes = ['SplitPane', this.props.className, split, disabledClass]; var prefixed = _reactVendorPrefix2.default.prefix({ styles: style }); return _react2.default.createElement('div', { className: classes.join(' '), style: prefixed.styles, ref: 'splitPane' }, _react2.default.createElement(_Pane2.default, { ref: 'pane1', key: 'pane1', className: 'Pane1', split: split }, children[0]), _react2.default.createElement(_Resizer2.default, { ref: 'resizer', key: 'resizer', className: disabledClass, onMouseDown: this.onMouseDown, children: resizerChildren, split: split }), _react2.default.createElement(_Pane2.default, { ref: 'pane2', key: 'pane2', className: 'Pane2', split: split }, children[1])); } }]); return SplitPane; }(_react.Component); SplitPane.propTypes = { primary: _react.PropTypes.oneOf(['first', 'second']), minSize: _react.PropTypes.number, maxSize: _react.PropTypes.number, defaultSize: _react.PropTypes.number, size: _react.PropTypes.number, allowResize: _react.PropTypes.bool, split: _react.PropTypes.oneOf(['vertical', 'horizontal']), onDragStarted: _react.PropTypes.func, onDragFinished: _react.PropTypes.func, onChange: _react.PropTypes.func, className: _react.PropTypes.string, children: _react.PropTypes.arrayOf(_react.PropTypes.node).isRequired, resizerChildren: _react.PropTypes.node }; SplitPane.defaultProps = { split: 'vertical', minSize: 50, allowResize: true, primary: 'first' }; exports.default = SplitPane; module.exports = exports['default']; },{"./HSplit":2,"./Pane":3,"./Resizer":4,"./VSplit":6,"react":165,"react-dom":35,"react-vendor-prefix":36}],6:[function(require,module,exports){ 'use strict'; var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; }; 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 = require('react'); 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 === "undefined" ? "undefined" : _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 === "undefined" ? "undefined" : _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 VSplit = function (_Component) { _inherits(VSplit, _Component); function VSplit() { var _Object$getPrototypeO; _classCallCheck(this, VSplit); for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } var _this = _possibleConstructorReturn(this, (_Object$getPrototypeO = Object.getPrototypeOf(VSplit)).call.apply(_Object$getPrototypeO, [this].concat(args))); _this.state = {}; return _this; } _createClass(VSplit, [{ key: 'render', value: function render() { var style = { cursor: 'col-resize', background: '#EEEEEE', borderLeft: 'solid #E0E0E0 1px', borderRight: 'solid #E0E0E0 1px', height: '100%', width: '3px' }; return _react2.default.createElement('div', { style: style }); } }]); return VSplit; }(_react.Component); exports.default = VSplit; module.exports = exports['default']; },{"react":165}],7:[function(require,module,exports){ (function (process){ /** * Copyright 2013-2015, Facebook, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * @providesModule EventListener * @typechecks */ 'use strict'; var emptyFunction = require('./emptyFunction'); /** * Upstream version of event listener. Does not take into account specific * nature of platform. */ var EventListener = { /** * Listen to DOM events during the bubble phase. * * @param {DOMEventTarget} target DOM element to register listener on. * @param {string} eventType Event type, e.g. 'click' or 'mouseover'. * @param {function} callback Callback function. * @return {object} Object with a `remove` method. */ listen: function (target, eventType, callback) { if (target.addEventListener) { target.addEventListener(eventType, callback, false); return { remove: function () { target.removeEventListener(eventType, callback, false); } }; } else if (target.attachEvent) { target.attachEvent('on' + eventType, callback); return { remove: function () { target.detachEvent('on' + eventType, callback); } }; } }, /** * Listen to DOM events during the capture phase. * * @param {DOMEventTarget} target DOM element to register listener on. * @param {string} eventType Event type, e.g. 'click' or 'mouseover'. * @param {function} callback Callback function. * @return {object} Object with a `remove` method. */ capture: function (target, eventType, callback) { if (target.addEventListener) { target.addEventListener(eventType, callback, true); return { remove: function () { target.removeEventListener(eventType, callback, true); } }; } else { if (process.env.NODE_ENV !== 'production') { console.error('Attempted to listen to events during the capture phase on a ' + 'browser that does not support the capture phase. Your application ' + 'will not receive some events.'); } return { remove: emptyFunction }; } }, registerDefault: function () {} }; module.exports = EventListener; }).call(this,require('_process')) },{"./emptyFunction":14,"_process":34}],8:[function(require,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 ExecutionEnvironment */ 'use strict'; var canUseDOM = !!(typeof window !== 'undefined' && window.document && window.document.createElement); /** * Simple, lightweight module assisting with the detection and context of * Worker. Helps avoid circular dependencies and allows code to reason about * whether or not they are in a Worker, even if they never include the main * `ReactWorker` dependency. */ var ExecutionEnvironment = { canUseDOM: canUseDOM, canUseWorkers: typeof Worker !== 'undefined', canUseEventListeners: canUseDOM && !!(window.addEventListener || window.attachEvent), canUseViewport: canUseDOM && !!window.screen, isInWorker: !canUseDOM // For now, this is true - might change in the future. }; module.exports = ExecutionEnvironment; },{}],9:[function(require,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 camelize * @typechecks */ "use strict"; var _hyphenPattern = /-(.)/g; /** * Camelcases a hyphenated string, for example: * * > camelize('background-color') * < "backgroundColor" * * @param {string} string * @return {string} */ function camelize(string) { return string.replace(_hyphenPattern, function (_, character) { return character.toUpperCase(); }); } module.exports = camelize; },{}],10:[function(require,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 camelizeStyleName * @typechecks */ 'use strict'; var camelize = require('./camelize'); var msPattern = /^-ms-/; /** * Camelcases a hyphenated CSS property name, for example: * * > camelizeStyleName('background-color') * < "backgroundColor" * > camelizeStyleName('-moz-transition') * < "MozTransition" * > camelizeStyleName('-ms-transition') * < "msTransition" * * As Andi Smith suggests * (http://www.andismith.com/blog/2012/02/modernizr-prefixed/), an `-ms` prefix * is converted to lowercase `ms`. * * @param {string} string * @return {string} */ function camelizeStyleName(string) { return camelize(string.replace(msPattern, 'ms-')); } module.exports = camelizeStyleName; },{"./camelize":9}],11:[function(require,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 containsNode * @typechecks */ 'use strict'; var isTextNode = require('./isTextNode'); /*eslint-disable no-bitwise */ /** * Checks if a given DOM node contains or is another DOM node. * * @param {?DOMNode} outerNode Outer DOM node. * @param {?DOMNode} innerNode Inner DOM node. * @return {boolean} True if `outerNode` contains or is `innerNode`. */ function containsNode(_x, _x2) { var _again = true; _function: while (_again) { var outerNode = _x, innerNode = _x2; _again = false; if (!outerNode || !innerNode) { return false; } else if (outerNode === innerNode) { return true; } else if (isTextNode(outerNode)) { return false; } else if (isTextNode(innerNode)) { _x = outerNode; _x2 = innerNode.parentNode; _again = true; continue _function; } else if (outerNode.contains) { return outerNode.contains(innerNode); } else if (outerNode.compareDocumentPosition) { return !!(outerNode.compareDocumentPosition(innerNode) & 16); } else { return false; } } } module.exports = containsNode; },{"./isTextNode":24}],12:[function(require,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 createArrayFromMixed * @typechecks */ 'use strict'; var toArray = require('./toArray'); /** * Perform a heuristic test to determine if an object is "array-like". * * A monk asked Joshu, a Zen master, "Has a dog Buddha nature?" * Joshu replied: "Mu." * * This function determines if its argument has "array nature": it returns * true if the argument is an actual array, an `arguments' object, or an * HTMLCollection (e.g. node.childNodes or node.getElementsByTagName()). * * It will return false for other array-like objects like Filelist. * * @param {*} obj * @return {boolean} */ function hasArrayNature(obj) { return( // not null/false !!obj && ( // arrays are objects, NodeLists are functions in Safari typeof obj == 'object' || typeof obj == 'function') && // quacks like an array 'length' in obj && // not window !('setInterval' in obj) && // no DOM node should be considered an array-like // a 'select' element has 'length' and 'item' properties on IE8 typeof obj.nodeType != 'number' && ( // a real array Array.isArray(obj) || // arguments 'callee' in obj || // HTMLCollection/NodeList 'item' in obj) ); } /** * Ensure that the argument is an array by wrapping it in an array if it is not. * Creates a copy of the argument if it is already an array. * * This is mostly useful idiomatically: * * var createArrayFromMixed = require('createArrayFromMixed'); * * function takesOneOrMoreThings(things) { * things = createArrayFromMixed(things); * ... * } * * This allows you to treat `things' as an array, but accept scalars in the API. * * If you need to convert an array-like object, like `arguments`, into an array * use toArray instead. * * @param {*} obj * @return {array} */ function createArrayFromMixed(obj) { if (!hasArrayNature(obj)) { return [obj]; } else if (Array.isArray(obj)) { return obj.slice(); } else { return toArray(obj); } } module.exports = createArrayFromMixed; },{"./toArray":32}],13:[function(require,module,exports){ (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 createNodesFromMarkup * @typechecks */ /*eslint-disable fb-www/unsafe-html*/ 'use strict'; var ExecutionEnvironment = require('./ExecutionEnvironment'); var createArrayFromMixed = require('./createArrayFromMixed'); var getMarkupWrap = require('./getMarkupWrap'); var invariant = require('./invariant'); /** * Dummy container used to render all markup. */ var dummyNode = ExecutionEnvironment.canUseDOM ? document.createElement('div') : null; /** * Pattern used by `getNodeName`. */ var nodeNamePattern = /^\s*<(\w+)/; /** * Extracts the `nodeName` of the first element in a string of markup. * * @param {string} markup String of markup. * @return {?string} Node name of the supplied markup. */ function getNodeName(markup) { var nodeNameMatch = markup.match(nodeNamePattern); return nodeNameMatch && nodeNameMatch[1].toLowerCase(); } /** * Creates an array containing the nodes rendered from the supplied markup. The * optionally supplied `handleScript` function will be invoked once for each * <script> element that is rendered. If no `handleScript` function is supplied, * an exception is thrown if any <script> elements are rendered. * * @param {string} markup A string of valid HTML markup. * @param {?function} handleScript Invoked once for each rendered <script>. * @return {array<DOMElement|DOMTextNode>} An array of rendered nodes. */ function createNodesFromMarkup(markup, handleScript) { var node = dummyNode; !!!dummyNode ? process.env.NODE_ENV !== 'production' ? invariant(false, 'createNodesFromMarkup dummy not initialized') : invariant(false) : undefined; var nodeName = getNodeName(markup); var wrap = nodeName && getMarkupWrap(nodeName); if (wrap) { node.innerHTML = wrap[1] + markup + wrap[2]; var wrapDepth = wrap[0]; while (wrapDepth--) { node = node.lastChild; } } else { node.innerHTML = markup; } var scripts = node.getElementsByTagName('script'); if (scripts.length) { !handleScript ? process.env.NODE_ENV !== 'production' ? invariant(false, 'createNodesFromMarkup(...): Unexpected <script> element rendered.') : invariant(false) : undefined; createArrayFromMixed(scripts).forEach(handleScript); } var nodes = createArrayFromMixed(node.childNodes); while (node.lastChild) { node.removeChild(node.lastChild); } return nodes; } module.exports = createNodesFromMarkup; }).call(this,require('_process')) },{"./ExecutionEnvironment":8,"./createArrayFromMixed":12,"./getMarkupWrap":18,"./invariant":22,"_process":34}],14:[function(require,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 emptyFunction */ "use strict"; function makeEmptyFunction(arg) { return function () { return arg; }; } /** * 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. */ function emptyFunction() {} 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; }; module.exports = emptyFunction; },{}],15:[function(require,module,exports){ (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 emptyObject */ 'use strict'; var emptyObject = {}; if (process.env.NODE_ENV !== 'production') { Object.freeze(emptyObject); } module.exports = emptyObject; }).call(this,require('_process')) },{"_process":34}],16:[function(require,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 focusNode */ 'use strict'; /** * @param {DOMElement} node input/textarea to focus */ function focusNode(node) { // IE8 can throw "Can't move focus to the control because it is invisible, // not enabled, or of a type that does not accept the focus." for all kinds of // reasons that are too expensive and fragile to test. try { node.focus(); } catch (e) {} } module.exports = focusNode; },{}],17:[function(require,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 getActiveElement * @typechecks */ /* eslint-disable fb-www/typeof-undefined */ /** * Same as document.activeElement but wraps in a try-catch block. In IE it is * not safe to call document.activeElement if there is nothing focused. * * The activeElement will be null only if the document or document body is not * yet defined. */ 'use strict'; function getActiveElement() /*?DOMElement*/{ if (typeof document === 'undefined') { return null; } try { return document.activeElement || document.body; } catch (e) { return document.body; } } module.exports = getActiveElement; },{}],18:[function(require,module,exports){ (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 getMarkupWrap */ /*eslint-disable fb-www/unsafe-html */ 'use strict'; var ExecutionEnvironment = require('./ExecutionEnvironment'); var invariant = require('./invariant'); /** * Dummy container used to detect which wraps are necessary. */ var dummyNode = ExecutionEnvironment.canUseDOM ? document.createElement('div') : null; /** * Some browsers cannot use `innerHTML` to render certain elements standalone, * so we wrap them, render the wrapped nodes, then extract the desired node. * * In IE8, certain elements cannot render alone, so wrap all elements ('*'). */ var shouldWrap = {}; var selectWrap = [1, '<select multiple="true">', '</select>']; var tableWrap = [1, '<table>', '</table>']; var trWrap = [3, '<table><tbody><tr>', '</tr></tbody></table>']; var svgWrap = [1, '<svg xmlns="http://www.w3.org/2000/svg">', '</svg>']; var markupWrap = { '*': [1, '?<div>', '</div>'], 'area': [1, '<map>', '</map>'], 'col': [2, '<table><tbody></tbody><colgroup>', '</colgroup></table>'], 'legend': [1, '<fieldset>', '</fieldset>'], 'param': [1, '<object>', '</object>'], 'tr': [2, '<table><tbody>', '</tbody></table>'], 'optgroup': selectWrap, 'option': selectWrap, 'caption': tableWrap, 'colgroup': tableWrap, 'tbody': tableWrap, 'tfoot': tableWrap, 'thead': tableWrap, 'td': trWrap, 'th': trWrap }; // Initialize the SVG elements since we know they'll always need to be wrapped // consistently. If they are created inside a <div> they will be initialized in // the wrong namespace (and will not display). var svgElements = ['circle', 'clipPath', 'defs', 'ellipse', 'g', 'image', 'line', 'linearGradient', 'mask', 'path', 'pattern', 'polygon', 'polyline', 'radialGradient', 'rect', 'stop', 'text', 'tspan']; svgElements.forEach(function (nodeName) { markupWrap[nodeName] = svgWrap; shouldWrap[nodeName] = true; }); /** * Gets the markup wrap configuration for the supplied `nodeName`. * * NOTE: This lazily detects which wraps are necessary for the current browser. * * @param {string} nodeName Lowercase `nodeName`. * @return {?array} Markup wrap configuration, if applicable. */ function getMarkupWrap(nodeName) { !!!dummyNode ? process.env.NODE_ENV !== 'production' ? invariant(false, 'Markup wrapping node not initialized') : invariant(false) : undefined; if (!markupWrap.hasOwnProperty(nodeName)) { nodeName = '*'; } if (!shouldWrap.hasOwnProperty(nodeName)) { if (nodeName === '*') { dummyNode.innerHTML = '<link />'; } else { dummyNode.innerHTML = '<' + nodeName + '></' + nodeName + '>'; } shouldWrap[nodeName] = !dummyNode.firstChild; } return shouldWrap[nodeName] ? markupWrap[nodeName] : null; } module.exports = getMarkupWrap; }).call(this,require('_process')) },{"./ExecutionEnvironment":8,"./invariant":22,"_process":34}],19:[function(require,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 getUnboundedScrollPosition * @typechecks */ 'use strict'; /** * Gets the scroll position of the supplied element or window. * * The return values are unbounded, unlike `getScrollPosition`. This means they * may be negative or exceed the element boundaries (which is possible using * inertial scrolling). * * @param {DOMWindow|DOMElement} scrollable * @return {object} Map with `x` and `y` keys. */ function getUnboundedScrollPosition(scrollable) { if (scrollable === window) { return { x: window.pageXOffset || document.doc