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

3 лет назад
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. 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; };
  6. 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; };
  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. exports.default = DragLayer;
  9. var _react = require('react');
  10. var _react2 = _interopRequireDefault(_react);
  11. var _propTypes = require('prop-types');
  12. var _propTypes2 = _interopRequireDefault(_propTypes);
  13. var _hoistNonReactStatics = require('hoist-non-react-statics');
  14. var _hoistNonReactStatics2 = _interopRequireDefault(_hoistNonReactStatics);
  15. var _isPlainObject = require('lodash/isPlainObject');
  16. var _isPlainObject2 = _interopRequireDefault(_isPlainObject);
  17. var _invariant = require('invariant');
  18. var _invariant2 = _interopRequireDefault(_invariant);
  19. var _shallowEqual = require('./utils/shallowEqual');
  20. var _shallowEqual2 = _interopRequireDefault(_shallowEqual);
  21. var _shallowEqualScalar = require('./utils/shallowEqualScalar');
  22. var _shallowEqualScalar2 = _interopRequireDefault(_shallowEqualScalar);
  23. var _checkDecoratorArguments = require('./utils/checkDecoratorArguments');
  24. var _checkDecoratorArguments2 = _interopRequireDefault(_checkDecoratorArguments);
  25. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  26. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  27. 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; }
  28. 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; }
  29. function DragLayer(collect) {
  30. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  31. _checkDecoratorArguments2.default.apply(undefined, ['DragLayer', 'collect[, options]'].concat(Array.prototype.slice.call(arguments))); // eslint-disable-line prefer-rest-params
  32. (0, _invariant2.default)(typeof collect === 'function', 'Expected "collect" provided as the first argument to DragLayer to be a function that collects props to inject into the component. ', 'Instead, received %s. Read more: http://react-dnd.github.io/react-dnd/docs-drag-layer.html', collect);
  33. (0, _invariant2.default)((0, _isPlainObject2.default)(options), 'Expected "options" provided as the second argument to DragLayer to be a plain object when specified. ' + 'Instead, received %s. Read more: http://react-dnd.github.io/react-dnd/docs-drag-layer.html', options);
  34. return function decorateLayer(DecoratedComponent) {
  35. var _class, _temp;
  36. var _options$arePropsEqua = options.arePropsEqual,
  37. arePropsEqual = _options$arePropsEqua === undefined ? _shallowEqualScalar2.default : _options$arePropsEqua;
  38. var displayName = DecoratedComponent.displayName || DecoratedComponent.name || 'Component';
  39. var DragLayerContainer = (_temp = _class = function (_Component) {
  40. _inherits(DragLayerContainer, _Component);
  41. _createClass(DragLayerContainer, [{
  42. key: 'getDecoratedComponentInstance',
  43. value: function getDecoratedComponentInstance() {
  44. (0, _invariant2.default)(this.child, 'In order to access an instance of the decorated component it can not be a stateless component.');
  45. return this.child;
  46. }
  47. }, {
  48. key: 'shouldComponentUpdate',
  49. value: function shouldComponentUpdate(nextProps, nextState) {
  50. return !arePropsEqual(nextProps, this.props) || !(0, _shallowEqual2.default)(nextState, this.state);
  51. }
  52. }]);
  53. function DragLayerContainer(props, context) {
  54. _classCallCheck(this, DragLayerContainer);
  55. var _this = _possibleConstructorReturn(this, (DragLayerContainer.__proto__ || Object.getPrototypeOf(DragLayerContainer)).call(this, props));
  56. _this.handleChange = _this.handleChange.bind(_this);
  57. _this.manager = context.dragDropManager;
  58. (0, _invariant2.default)(_typeof(_this.manager) === 'object', 'Could not find the drag and drop manager in the context of %s. ' + 'Make sure to wrap the top-level component of your app with DragDropContext. ' + 'Read more: http://react-dnd.github.io/react-dnd/docs-troubleshooting.html#could-not-find-the-drag-and-drop-manager-in-the-context', displayName, displayName);
  59. _this.state = _this.getCurrentState();
  60. return _this;
  61. }
  62. _createClass(DragLayerContainer, [{
  63. key: 'componentDidMount',
  64. value: function componentDidMount() {
  65. this.isCurrentlyMounted = true;
  66. var monitor = this.manager.getMonitor();
  67. this.unsubscribeFromOffsetChange = monitor.subscribeToOffsetChange(this.handleChange);
  68. this.unsubscribeFromStateChange = monitor.subscribeToStateChange(this.handleChange);
  69. this.handleChange();
  70. }
  71. }, {
  72. key: 'componentWillUnmount',
  73. value: function componentWillUnmount() {
  74. this.isCurrentlyMounted = false;
  75. this.unsubscribeFromOffsetChange();
  76. this.unsubscribeFromStateChange();
  77. }
  78. }, {
  79. key: 'handleChange',
  80. value: function handleChange() {
  81. if (!this.isCurrentlyMounted) {
  82. return;
  83. }
  84. var nextState = this.getCurrentState();
  85. if (!(0, _shallowEqual2.default)(nextState, this.state)) {
  86. this.setState(nextState);
  87. }
  88. }
  89. }, {
  90. key: 'getCurrentState',
  91. value: function getCurrentState() {
  92. var monitor = this.manager.getMonitor();
  93. return collect(monitor, this.props);
  94. }
  95. }, {
  96. key: 'render',
  97. value: function render() {
  98. var _this2 = this;
  99. return _react2.default.createElement(DecoratedComponent, _extends({}, this.props, this.state, {
  100. ref: function ref(child) {
  101. _this2.child = child;
  102. }
  103. }));
  104. }
  105. }]);
  106. return DragLayerContainer;
  107. }(_react.Component), _class.DecoratedComponent = DecoratedComponent, _class.displayName = 'DragLayer(' + displayName + ')', _class.contextTypes = {
  108. dragDropManager: _propTypes2.default.object.isRequired
  109. }, _temp);
  110. return (0, _hoistNonReactStatics2.default)(DragLayerContainer, DecoratedComponent);
  111. };
  112. }