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

121 строка
5.7 KiB

  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.unpackBackendForEs5Users = exports.createChildContext = exports.CHILD_CONTEXT_TYPES = undefined;
  6. 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; };
  7. 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; }; }();
  8. var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
  9. exports.default = DragDropContext;
  10. var _react = require('react');
  11. var _react2 = _interopRequireDefault(_react);
  12. var _propTypes = require('prop-types');
  13. var _propTypes2 = _interopRequireDefault(_propTypes);
  14. var _dndCore = require('dnd-core');
  15. var _invariant = require('invariant');
  16. var _invariant2 = _interopRequireDefault(_invariant);
  17. var _hoistNonReactStatics = require('hoist-non-react-statics');
  18. var _hoistNonReactStatics2 = _interopRequireDefault(_hoistNonReactStatics);
  19. var _checkDecoratorArguments = require('./utils/checkDecoratorArguments');
  20. var _checkDecoratorArguments2 = _interopRequireDefault(_checkDecoratorArguments);
  21. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  22. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  23. 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; }
  24. 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; }
  25. var CHILD_CONTEXT_TYPES = exports.CHILD_CONTEXT_TYPES = {
  26. dragDropManager: _propTypes2.default.object.isRequired
  27. };
  28. var createChildContext = exports.createChildContext = function createChildContext(backend, context) {
  29. return {
  30. dragDropManager: new _dndCore.DragDropManager(backend, context)
  31. };
  32. };
  33. var unpackBackendForEs5Users = exports.unpackBackendForEs5Users = function unpackBackendForEs5Users(backendOrModule) {
  34. // Auto-detect ES6 default export for people still using ES5
  35. var backend = backendOrModule;
  36. if ((typeof backend === 'undefined' ? 'undefined' : _typeof(backend)) === 'object' && typeof backend.default === 'function') {
  37. backend = backend.default;
  38. }
  39. (0, _invariant2.default)(typeof backend === 'function', 'Expected the backend to be a function or an ES6 module exporting a default function. ' + 'Read more: http://react-dnd.github.io/react-dnd/docs-drag-drop-context.html');
  40. return backend;
  41. };
  42. function DragDropContext(backendOrModule) {
  43. _checkDecoratorArguments2.default.apply(undefined, ['DragDropContext', 'backend'].concat(Array.prototype.slice.call(arguments))); // eslint-disable-line prefer-rest-params
  44. var backend = unpackBackendForEs5Users(backendOrModule);
  45. var childContext = createChildContext(backend);
  46. return function decorateContext(DecoratedComponent) {
  47. var _class, _temp;
  48. var displayName = DecoratedComponent.displayName || DecoratedComponent.name || 'Component';
  49. var DragDropContextContainer = (_temp = _class = function (_Component) {
  50. _inherits(DragDropContextContainer, _Component);
  51. function DragDropContextContainer() {
  52. _classCallCheck(this, DragDropContextContainer);
  53. return _possibleConstructorReturn(this, (DragDropContextContainer.__proto__ || Object.getPrototypeOf(DragDropContextContainer)).apply(this, arguments));
  54. }
  55. _createClass(DragDropContextContainer, [{
  56. key: 'getDecoratedComponentInstance',
  57. value: function getDecoratedComponentInstance() {
  58. (0, _invariant2.default)(this.child, 'In order to access an instance of the decorated component it can not be a stateless component.');
  59. return this.child;
  60. }
  61. }, {
  62. key: 'getManager',
  63. value: function getManager() {
  64. return childContext.dragDropManager;
  65. }
  66. }, {
  67. key: 'getChildContext',
  68. value: function getChildContext() {
  69. return childContext;
  70. }
  71. }, {
  72. key: 'render',
  73. value: function render() {
  74. var _this2 = this;
  75. return _react2.default.createElement(DecoratedComponent, _extends({}, this.props, {
  76. ref: function ref(child) {
  77. _this2.child = child;
  78. }
  79. }));
  80. }
  81. }]);
  82. return DragDropContextContainer;
  83. }(_react.Component), _class.DecoratedComponent = DecoratedComponent, _class.displayName = 'DragDropContext(' + displayName + ')', _class.childContextTypes = CHILD_CONTEXT_TYPES, _temp);
  84. return (0, _hoistNonReactStatics2.default)(DragDropContextContainer, DecoratedComponent);
  85. };
  86. }