Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 

92 строки
4.2 KiB

  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = undefined;
  6. 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; }; }();
  7. var _class, _temp;
  8. var _react = require('react');
  9. var _propTypes = require('prop-types');
  10. var _propTypes2 = _interopRequireDefault(_propTypes);
  11. var _DragDropContext = require('./DragDropContext');
  12. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  13. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  14. 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; }
  15. 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; }
  16. /**
  17. * This class is a React-Component based version of the DragDropContext.
  18. * This is an alternative to decorating an application component with an ES7 decorator.
  19. */
  20. var DragDropContextProvider = (_temp = _class = function (_Component) {
  21. _inherits(DragDropContextProvider, _Component);
  22. function DragDropContextProvider(props, context) {
  23. _classCallCheck(this, DragDropContextProvider);
  24. /**
  25. * This property determines which window global to use for creating the DragDropManager.
  26. * If a window has been injected explicitly via props, that is used first. If it is available
  27. * as a context value, then use that, otherwise use the browser global.
  28. */
  29. var _this = _possibleConstructorReturn(this, (DragDropContextProvider.__proto__ || Object.getPrototypeOf(DragDropContextProvider)).call(this, props, context));
  30. var getWindow = function getWindow() {
  31. if (props && props.window) {
  32. return props.window;
  33. } else if (context && context.window) {
  34. return context.window;
  35. } else if (typeof window !== 'undefined') {
  36. return window;
  37. }
  38. return undefined;
  39. };
  40. _this.backend = (0, _DragDropContext.unpackBackendForEs5Users)(props.backend);
  41. _this.childContext = (0, _DragDropContext.createChildContext)(_this.backend, {
  42. window: getWindow()
  43. });
  44. return _this;
  45. }
  46. _createClass(DragDropContextProvider, [{
  47. key: 'componentWillReceiveProps',
  48. value: function componentWillReceiveProps(nextProps) {
  49. if (nextProps.backend !== this.props.backend || nextProps.window !== this.props.window) {
  50. throw new Error('DragDropContextProvider backend and window props must not change.');
  51. }
  52. }
  53. }, {
  54. key: 'getChildContext',
  55. value: function getChildContext() {
  56. return this.childContext;
  57. }
  58. }, {
  59. key: 'render',
  60. value: function render() {
  61. return _react.Children.only(this.props.children);
  62. }
  63. }]);
  64. return DragDropContextProvider;
  65. }(_react.Component), _class.propTypes = {
  66. backend: _propTypes2.default.oneOfType([_propTypes2.default.func, _propTypes2.default.object]).isRequired,
  67. children: _propTypes2.default.element.isRequired,
  68. window: _propTypes2.default.object // eslint-disable-line react/forbid-prop-types
  69. }, _class.defaultProps = {
  70. window: undefined
  71. }, _class.childContextTypes = _DragDropContext.CHILD_CONTEXT_TYPES, _class.displayName = 'DragDropContextProvider', _class.contextTypes = {
  72. window: _propTypes2.default.object
  73. }, _temp);
  74. exports.default = DragDropContextProvider;