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

67 строки
2.0 KiB

  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = wrapConnectorHooks;
  6. var _react = require('react');
  7. var _cloneWithRef = require('./utils/cloneWithRef');
  8. var _cloneWithRef2 = _interopRequireDefault(_cloneWithRef);
  9. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  10. function throwIfCompositeComponentElement(element) {
  11. // Custom components can no longer be wrapped directly in React DnD 2.0
  12. // so that we don't need to depend on findDOMNode() from react-dom.
  13. if (typeof element.type === 'string') {
  14. return;
  15. }
  16. var displayName = element.type.displayName || element.type.name || 'the component';
  17. throw new Error('Only native element nodes can now be passed to React DnD connectors.' + ('You can either wrap ' + displayName + ' into a <div>, or turn it into a ') + 'drag source or a drop target itself.');
  18. }
  19. function wrapHookToRecognizeElement(hook) {
  20. return function () {
  21. var elementOrNode = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
  22. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
  23. // When passed a node, call the hook straight away.
  24. if (!(0, _react.isValidElement)(elementOrNode)) {
  25. var node = elementOrNode;
  26. hook(node, options);
  27. return undefined;
  28. }
  29. // If passed a ReactElement, clone it and attach this function as a ref.
  30. // This helps us achieve a neat API where user doesn't even know that refs
  31. // are being used under the hood.
  32. var element = elementOrNode;
  33. throwIfCompositeComponentElement(element);
  34. // When no options are passed, use the hook directly
  35. var ref = options ? function (node) {
  36. return hook(node, options);
  37. } : hook;
  38. return (0, _cloneWithRef2.default)(element, ref);
  39. };
  40. }
  41. function wrapConnectorHooks(hooks) {
  42. var wrappedHooks = {};
  43. Object.keys(hooks).forEach(function (key) {
  44. var hook = hooks[key];
  45. var wrappedHook = wrapHookToRecognizeElement(hook);
  46. wrappedHooks[key] = function () {
  47. return wrappedHook;
  48. };
  49. });
  50. return wrappedHooks;
  51. }