react-dnd
Version:
Drag and Drop for React
60 lines • 3.33 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var invariant_1 = __importDefault(require("invariant"));
var isPlainObject_1 = __importDefault(require("lodash/isPlainObject"));
var checkDecoratorArguments_1 = __importDefault(require("./utils/checkDecoratorArguments"));
var decorateHandler_1 = __importDefault(require("./decorateHandler"));
var registerSource_1 = __importDefault(require("./registerSource"));
var createSourceFactory_1 = __importDefault(require("./createSourceFactory"));
var createSourceMonitor_1 = __importDefault(require("./createSourceMonitor"));
var createSourceConnector_1 = __importDefault(require("./createSourceConnector"));
var isValidType_1 = __importDefault(require("./utils/isValidType"));
/**
* Decorates a component as a dragsource
* @param type The dragsource type
* @param spec The drag source specification
* @param collect The props collector function
* @param options DnD optinos
*/
function DragSource(type, spec, collect, options) {
if (options === void 0) { options = {}; }
checkDecoratorArguments_1.default('DragSource', 'type, spec, collect[, options]', type, spec, collect, options);
var getType = type;
if (typeof type !== 'function') {
invariant_1.default(isValidType_1.default(type), 'Expected "type" provided as the first argument to DragSource to be ' +
'a string, or a function that returns a string given the current props. ' +
'Instead, received %s. ' +
'Read more: http://react-dnd.github.io/react-dnd/docs-drag-source.html', type);
getType = function () { return type; };
}
invariant_1.default(isPlainObject_1.default(spec), 'Expected "spec" provided as the second argument to DragSource to be ' +
'a plain object. Instead, received %s. ' +
'Read more: http://react-dnd.github.io/react-dnd/docs-drag-source.html', spec);
var createSource = createSourceFactory_1.default(spec);
invariant_1.default(typeof collect === 'function', 'Expected "collect" provided as the third argument to DragSource to be ' +
'a function that returns a plain object of props to inject. ' +
'Instead, received %s. ' +
'Read more: http://react-dnd.github.io/react-dnd/docs-drag-source.html', collect);
invariant_1.default(isPlainObject_1.default(options), 'Expected "options" provided as the fourth argument to DragSource to be ' +
'a plain object when specified. ' +
'Instead, received %s. ' +
'Read more: http://react-dnd.github.io/react-dnd/docs-drag-source.html', collect);
return function decorateSource(DecoratedComponent) {
return decorateHandler_1.default({
containerDisplayName: 'DragSource',
createHandler: createSource,
registerHandler: registerSource_1.default,
createMonitor: createSourceMonitor_1.default,
createConnector: createSourceConnector_1.default,
DecoratedComponent: DecoratedComponent,
getType: getType,
collect: collect,
options: options,
});
};
}
exports.default = DragSource;
//# sourceMappingURL=DragSource.js.map