|
- 'use strict';
-
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- exports.default = 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 _class, _temp;
-
- var _react = require('react');
-
- var _propTypes = require('prop-types');
-
- var _propTypes2 = _interopRequireDefault(_propTypes);
-
- var _DragDropContext = require('./DragDropContext');
-
- 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; }
-
- /**
- * This class is a React-Component based version of the DragDropContext.
- * This is an alternative to decorating an application component with an ES7 decorator.
- */
- var DragDropContextProvider = (_temp = _class = function (_Component) {
- _inherits(DragDropContextProvider, _Component);
-
- function DragDropContextProvider(props, context) {
- _classCallCheck(this, DragDropContextProvider);
-
- /**
- * This property determines which window global to use for creating the DragDropManager.
- * If a window has been injected explicitly via props, that is used first. If it is available
- * as a context value, then use that, otherwise use the browser global.
- */
- var _this = _possibleConstructorReturn(this, (DragDropContextProvider.__proto__ || Object.getPrototypeOf(DragDropContextProvider)).call(this, props, context));
-
- var getWindow = function getWindow() {
- if (props && props.window) {
- return props.window;
- } else if (context && context.window) {
- return context.window;
- } else if (typeof window !== 'undefined') {
- return window;
- }
- return undefined;
- };
-
- _this.backend = (0, _DragDropContext.unpackBackendForEs5Users)(props.backend);
- _this.childContext = (0, _DragDropContext.createChildContext)(_this.backend, {
- window: getWindow()
- });
- return _this;
- }
-
- _createClass(DragDropContextProvider, [{
- key: 'componentWillReceiveProps',
- value: function componentWillReceiveProps(nextProps) {
- if (nextProps.backend !== this.props.backend || nextProps.window !== this.props.window) {
- throw new Error('DragDropContextProvider backend and window props must not change.');
- }
- }
- }, {
- key: 'getChildContext',
- value: function getChildContext() {
- return this.childContext;
- }
- }, {
- key: 'render',
- value: function render() {
- return _react.Children.only(this.props.children);
- }
- }]);
-
- return DragDropContextProvider;
- }(_react.Component), _class.propTypes = {
- backend: _propTypes2.default.oneOfType([_propTypes2.default.func, _propTypes2.default.object]).isRequired,
- children: _propTypes2.default.element.isRequired,
- window: _propTypes2.default.object // eslint-disable-line react/forbid-prop-types
- }, _class.defaultProps = {
- window: undefined
- }, _class.childContextTypes = _DragDropContext.CHILD_CONTEXT_TYPES, _class.displayName = 'DragDropContextProvider', _class.contextTypes = {
- window: _propTypes2.default.object
- }, _temp);
- exports.default = DragDropContextProvider;
|