UNPKG

qtsd-fork

Version:

Do not use this please

94 lines (75 loc) 3.43 kB
'use strict'; 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; }; }(); exports.default = createTargetFactory; var _invariant = require('invariant'); var _invariant2 = _interopRequireDefault(_invariant); var _isPlainObject = require('lodash/isPlainObject'); var _isPlainObject2 = _interopRequireDefault(_isPlainObject); 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"); } } var ALLOWED_SPEC_METHODS = ['canDrop', 'hover', 'drop']; function createTargetFactory(spec) { Object.keys(spec).forEach(function (key) { (0, _invariant2.default)(ALLOWED_SPEC_METHODS.indexOf(key) > -1, 'Expected the drop target specification to only have ' + 'some of the following keys: %s. ' + 'Instead received a specification with an unexpected "%s" key. ' + 'Read more: http://react-dnd.github.io/react-dnd/docs-drop-target.html', ALLOWED_SPEC_METHODS.join(', '), key); (0, _invariant2.default)(typeof spec[key] === 'function', 'Expected %s in the drop target specification to be a function. ' + 'Instead received a specification with %s: %s. ' + 'Read more: http://react-dnd.github.io/react-dnd/docs-drop-target.html', key, key, spec[key]); }); var Target = function () { function Target(monitor) { _classCallCheck(this, Target); this.monitor = monitor; this.props = null; this.component = null; } _createClass(Target, [{ key: 'receiveProps', value: function receiveProps(props) { this.props = props; } }, { key: 'receiveMonitor', value: function receiveMonitor(monitor) { this.monitor = monitor; } }, { key: 'receiveComponent', value: function receiveComponent(component) { this.component = component; } }, { key: 'canDrop', value: function canDrop() { if (!spec.canDrop) { return true; } return spec.canDrop(this.props, this.monitor); } }, { key: 'hover', value: function hover() { if (!spec.hover) { return; } spec.hover(this.props, this.monitor, this.component); } }, { key: 'drop', value: function drop() { if (!spec.drop) { return undefined; } var dropResult = spec.drop(this.props, this.monitor, this.component); if (process.env.NODE_ENV !== 'production') { (0, _invariant2.default)(typeof dropResult === 'undefined' || (0, _isPlainObject2.default)(dropResult), 'drop() must either return undefined, or an object that represents the drop result. ' + 'Instead received %s. ' + 'Read more: http://react-dnd.github.io/react-dnd/docs-drop-target.html', dropResult); } return dropResult; } }]); return Target; }(); return function createTarget(monitor) { return new Target(monitor); }; }