wix-style-react
Version:
85 lines (68 loc) • 3.19 kB
JavaScript
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import _inherits from "@babel/runtime/helpers/inherits";
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
import React from 'react';
import PropTypes from 'prop-types';
import TouchBackend from './TouchBackend';
import { DndProvider, createDndContext } from 'react-dnd';
var defaultManager;
function getDefaultManager(backend) {
if (!defaultManager) {
defaultManager = createDndContext(backend, {}, {
enableMouseEvents: true
}).dragDropManager;
}
return defaultManager;
} // https://github.com/react-dnd/react-dnd/issues/186#issuecomment-110333064
var DragDropContextProvider = /*#__PURE__*/function (_React$Component) {
_inherits(DragDropContextProvider, _React$Component);
var _super = _createSuper(DragDropContextProvider);
function DragDropContextProvider() {
_classCallCheck(this, DragDropContextProvider);
return _super.apply(this, arguments);
}
_createClass(DragDropContextProvider, [{
key: "getManager",
value: // we add `manager` to instance to allow to manipulate d&d in tests
function getManager() {
return this.context.dragDropManager || getDefaultManager(this.props.backend);
}
}, {
key: "getChildContext",
value: function getChildContext() {
return {
dragDropManager: this.getManager()
};
}
}, {
key: "render",
value: function render() {
var _this$props = this.props,
backend = _this$props.backend,
children = _this$props.children;
return /*#__PURE__*/React.createElement(DndProvider, {
manager: this.getManager(backend)
}, children);
}
}]);
return DragDropContextProvider;
}(React.Component);
_defineProperty(DragDropContextProvider, "propTypes", {
children: PropTypes.node,
backend: PropTypes.func
});
_defineProperty(DragDropContextProvider, "defaultProps", {
backend: TouchBackend
});
_defineProperty(DragDropContextProvider, "contextTypes", {
dragDropManager: PropTypes.object
});
_defineProperty(DragDropContextProvider, "childContextTypes", {
dragDropManager: PropTypes.object
});
export default DragDropContextProvider;