@pie-lib/drag 2.19.6-esmbeta.0 → 2.20.0-mui-update.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +37 -0
- package/lib/drag-in-the-blank-dp.js +28 -24
- package/lib/drag-in-the-blank-dp.js.map +1 -1
- package/lib/drag-provider.js +47 -0
- package/lib/drag-provider.js.map +1 -0
- package/lib/drag-type.js +2 -3
- package/lib/drag-type.js.map +1 -1
- package/lib/draggable-choice.js +87 -0
- package/lib/draggable-choice.js.map +1 -0
- package/lib/droppable-placeholder.js +33 -65
- package/lib/droppable-placeholder.js.map +1 -1
- package/lib/ica-dp.js +38 -26
- package/lib/ica-dp.js.map +1 -1
- package/lib/index.js +7 -35
- package/lib/index.js.map +1 -1
- package/lib/match-list-dp.js +38 -26
- package/lib/match-list-dp.js.map +1 -1
- package/lib/placeholder.js +77 -102
- package/lib/placeholder.js.map +1 -1
- package/lib/preview-component.js +67 -107
- package/lib/preview-component.js.map +1 -1
- package/lib/swap.js +1 -7
- package/lib/swap.js.map +1 -1
- package/lib/uid-context.js +4 -18
- package/lib/uid-context.js.map +1 -1
- package/package.json +12 -17
- package/src/drag-in-the-blank-dp.jsx +32 -15
- package/src/drag-provider.jsx +40 -0
- package/src/drag-type.js +1 -1
- package/src/draggable-choice.jsx +87 -0
- package/src/droppable-placeholder.jsx +38 -28
- package/src/ica-dp.jsx +41 -18
- package/src/index.js +4 -8
- package/src/match-list-dp.jsx +41 -18
- package/src/placeholder.jsx +64 -71
- package/src/preview-component.jsx +62 -70
- package/esm/index.js +0 -47146
- package/esm/index.js.map +0 -1
- package/esm/package.json +0 -1
- package/lib/choice.js +0 -129
- package/lib/choice.js.map +0 -1
- package/lib/with-drag-context.js +0 -59
- package/lib/with-drag-context.js.map +0 -1
- package/src/choice.jsx +0 -76
- package/src/with-drag-context.js +0 -32
package/esm/package.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"type":"module"}
|
package/lib/choice.js
DELETED
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports["default"] = exports.DRAG_TYPE = exports.Choice = void 0;
|
|
9
|
-
|
|
10
|
-
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
11
|
-
|
|
12
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
13
|
-
|
|
14
|
-
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
15
|
-
|
|
16
|
-
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
17
|
-
|
|
18
|
-
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
19
|
-
|
|
20
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
21
|
-
|
|
22
|
-
var _react = _interopRequireDefault(require("react"));
|
|
23
|
-
|
|
24
|
-
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
25
|
-
|
|
26
|
-
var _styles = require("@material-ui/core/styles");
|
|
27
|
-
|
|
28
|
-
var _classnames = _interopRequireDefault(require("classnames"));
|
|
29
|
-
|
|
30
|
-
var _grey = _interopRequireDefault(require("@material-ui/core/colors/grey"));
|
|
31
|
-
|
|
32
|
-
var _reactDnd = require("react-dnd");
|
|
33
|
-
|
|
34
|
-
var _uidContext = require("./uid-context");
|
|
35
|
-
|
|
36
|
-
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; }
|
|
37
|
-
|
|
38
|
-
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; } }
|
|
39
|
-
|
|
40
|
-
var DRAG_TYPE = 'CHOICE';
|
|
41
|
-
exports.DRAG_TYPE = DRAG_TYPE;
|
|
42
|
-
|
|
43
|
-
var Choice = /*#__PURE__*/function (_React$Component) {
|
|
44
|
-
(0, _inherits2["default"])(Choice, _React$Component);
|
|
45
|
-
|
|
46
|
-
var _super = _createSuper(Choice);
|
|
47
|
-
|
|
48
|
-
function Choice() {
|
|
49
|
-
(0, _classCallCheck2["default"])(this, Choice);
|
|
50
|
-
return _super.apply(this, arguments);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
(0, _createClass2["default"])(Choice, [{
|
|
54
|
-
key: "render",
|
|
55
|
-
value: function render() {
|
|
56
|
-
var _this$props = this.props,
|
|
57
|
-
classes = _this$props.classes,
|
|
58
|
-
className = _this$props.className,
|
|
59
|
-
children = _this$props.children,
|
|
60
|
-
connectDragSource = _this$props.connectDragSource;
|
|
61
|
-
return connectDragSource( /*#__PURE__*/_react["default"].createElement("div", {
|
|
62
|
-
className: (0, _classnames["default"])(classes.choice, className)
|
|
63
|
-
}, children));
|
|
64
|
-
}
|
|
65
|
-
}]);
|
|
66
|
-
return Choice;
|
|
67
|
-
}(_react["default"].Component);
|
|
68
|
-
|
|
69
|
-
exports.Choice = Choice;
|
|
70
|
-
(0, _defineProperty2["default"])(Choice, "propTypes", {
|
|
71
|
-
classes: _propTypes["default"].object.isRequired,
|
|
72
|
-
className: _propTypes["default"].string,
|
|
73
|
-
children: _propTypes["default"].oneOfType([_propTypes["default"].arrayOf(_propTypes["default"].node), _propTypes["default"].node]),
|
|
74
|
-
connectDragSource: _propTypes["default"].func.isRequired
|
|
75
|
-
});
|
|
76
|
-
(0, _defineProperty2["default"])(Choice, "defaultProps", {});
|
|
77
|
-
|
|
78
|
-
var styles = function styles(theme) {
|
|
79
|
-
return {
|
|
80
|
-
choice: {
|
|
81
|
-
backgroundColor: theme.palette.background.paper,
|
|
82
|
-
border: "solid 1px ".concat(_grey["default"][400]),
|
|
83
|
-
padding: theme.spacing.unit,
|
|
84
|
-
minHeight: '30px',
|
|
85
|
-
minWidth: theme.spacing.unit * 20,
|
|
86
|
-
maxWidth: theme.spacing.unit * 75
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
var choiceSource = {
|
|
92
|
-
canDrag: function canDrag(props) {
|
|
93
|
-
return !props.disabled;
|
|
94
|
-
},
|
|
95
|
-
beginDrag: function beginDrag(props) {
|
|
96
|
-
var out = {
|
|
97
|
-
choiceId: props.choice.id,
|
|
98
|
-
from: props.category.id,
|
|
99
|
-
alternateResponseIndex: props.alternateResponseIndex,
|
|
100
|
-
choiceIndex: props.choiceIndex
|
|
101
|
-
};
|
|
102
|
-
return out;
|
|
103
|
-
},
|
|
104
|
-
endDrag: function endDrag(props, monitor) {
|
|
105
|
-
if (!monitor.didDrop()) {
|
|
106
|
-
var item = monitor.getItem();
|
|
107
|
-
|
|
108
|
-
if (item.from) {
|
|
109
|
-
props.onRemoveChoice(item);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
};
|
|
114
|
-
var styledChoice = (0, _styles.withStyles)(styles)(Choice);
|
|
115
|
-
var DraggableChoice = (0, _reactDnd.DragSource)(function (_ref) {
|
|
116
|
-
var uid = _ref.uid;
|
|
117
|
-
return uid;
|
|
118
|
-
}, choiceSource, function (connect, monitor) {
|
|
119
|
-
return {
|
|
120
|
-
connectDragSource: connect.dragSource(),
|
|
121
|
-
connectDragPreview: connect.dragPreview(),
|
|
122
|
-
isDragging: monitor.isDragging()
|
|
123
|
-
};
|
|
124
|
-
})(styledChoice);
|
|
125
|
-
|
|
126
|
-
var _default = (0, _uidContext.withUid)(DraggableChoice);
|
|
127
|
-
|
|
128
|
-
exports["default"] = _default;
|
|
129
|
-
//# sourceMappingURL=choice.js.map
|
package/lib/choice.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/choice.jsx"],"names":["DRAG_TYPE","Choice","props","classes","className","children","connectDragSource","choice","React","Component","PropTypes","object","isRequired","string","oneOfType","arrayOf","node","func","styles","theme","backgroundColor","palette","background","paper","border","grey","padding","spacing","unit","minHeight","minWidth","maxWidth","choiceSource","canDrag","disabled","beginDrag","out","choiceId","id","from","category","alternateResponseIndex","choiceIndex","endDrag","monitor","didDrop","item","getItem","onRemoveChoice","styledChoice","DraggableChoice","uid","connect","dragSource","connectDragPreview","dragPreview","isDragging"],"mappings":"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","sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\nimport { withStyles } from '@material-ui/core/styles';\nimport classNames from 'classnames';\nimport grey from '@material-ui/core/colors/grey';\n\nimport { DragSource } from 'react-dnd';\nimport { withUid } from './uid-context';\n\nexport const DRAG_TYPE = 'CHOICE';\n\nexport class Choice extends React.Component {\n static propTypes = {\n classes: PropTypes.object.isRequired,\n className: PropTypes.string,\n children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]),\n connectDragSource: PropTypes.func.isRequired,\n };\n\n static defaultProps = {};\n\n render() {\n const { classes, className, children, connectDragSource } = this.props;\n\n return connectDragSource(<div className={classNames(classes.choice, className)}>{children}</div>);\n }\n}\n\nconst styles = (theme) => ({\n choice: {\n backgroundColor: theme.palette.background.paper,\n border: `solid 1px ${grey[400]}`,\n padding: theme.spacing.unit,\n minHeight: '30px',\n minWidth: theme.spacing.unit * 20,\n maxWidth: theme.spacing.unit * 75,\n },\n});\n\nconst choiceSource = {\n canDrag(props) {\n return !props.disabled;\n },\n beginDrag(props) {\n const out = {\n choiceId: props.choice.id,\n from: props.category.id,\n alternateResponseIndex: props.alternateResponseIndex,\n choiceIndex: props.choiceIndex,\n };\n return out;\n },\n\n endDrag: (props, monitor) => {\n if (!monitor.didDrop()) {\n const item = monitor.getItem();\n if (item.from) {\n props.onRemoveChoice(item);\n }\n }\n },\n};\n\nconst styledChoice = withStyles(styles)(Choice);\n\nconst DraggableChoice = DragSource(\n ({ uid }) => uid,\n choiceSource,\n (connect, monitor) => ({\n connectDragSource: connect.dragSource(),\n connectDragPreview: connect.dragPreview(),\n isDragging: monitor.isDragging(),\n }),\n)(styledChoice);\n\nexport default withUid(DraggableChoice);\n"],"file":"choice.js"}
|
package/lib/with-drag-context.js
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
6
|
-
|
|
7
|
-
Object.defineProperty(exports, "__esModule", {
|
|
8
|
-
value: true
|
|
9
|
-
});
|
|
10
|
-
exports["default"] = void 0;
|
|
11
|
-
|
|
12
|
-
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
13
|
-
|
|
14
|
-
var _react = _interopRequireDefault(require("react"));
|
|
15
|
-
|
|
16
|
-
var _reactDndMultiBackend = _interopRequireWildcard(require("react-dnd-multi-backend"));
|
|
17
|
-
|
|
18
|
-
var _reactDnd = require("react-dnd");
|
|
19
|
-
|
|
20
|
-
var _reactDndTouchBackend = require("react-dnd-touch-backend");
|
|
21
|
-
|
|
22
|
-
var _reactDndHtml5Backend = require("react-dnd-html5-backend");
|
|
23
|
-
|
|
24
|
-
var _previewComponent = _interopRequireDefault(require("./preview-component"));
|
|
25
|
-
|
|
26
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
27
|
-
|
|
28
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
29
|
-
|
|
30
|
-
var backends = [{
|
|
31
|
-
backend: _reactDndHtml5Backend.HTML5Backend,
|
|
32
|
-
transition: _reactDndMultiBackend.MouseTransition
|
|
33
|
-
}, {
|
|
34
|
-
backend: _reactDndTouchBackend.TouchBackend,
|
|
35
|
-
options: {
|
|
36
|
-
enableMouseEvents: true,
|
|
37
|
-
enableTouchEvents: true
|
|
38
|
-
},
|
|
39
|
-
preview: true,
|
|
40
|
-
transition: _reactDndMultiBackend.TouchTransition,
|
|
41
|
-
skipDispatchOnTransition: true
|
|
42
|
-
}];
|
|
43
|
-
|
|
44
|
-
var _default = function _default(Component) {
|
|
45
|
-
return function (props) {
|
|
46
|
-
var isClient = typeof window !== 'undefined';
|
|
47
|
-
return /*#__PURE__*/_react["default"].createElement(_reactDnd.DndProvider, (0, _extends2["default"])({
|
|
48
|
-
backend: _reactDndMultiBackend["default"],
|
|
49
|
-
options: {
|
|
50
|
-
backends: backends
|
|
51
|
-
}
|
|
52
|
-
}, isClient && {
|
|
53
|
-
context: window
|
|
54
|
-
}), /*#__PURE__*/_react["default"].createElement(Component, props), /*#__PURE__*/_react["default"].createElement(_previewComponent["default"], null));
|
|
55
|
-
};
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
exports["default"] = _default;
|
|
59
|
-
//# sourceMappingURL=with-drag-context.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/with-drag-context.js"],"names":["backends","backend","HTML5Backend","transition","MouseTransition","TouchBackend","options","enableMouseEvents","enableTouchEvents","preview","TouchTransition","skipDispatchOnTransition","Component","props","isClient","window","MultiBackend","context"],"mappings":";;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AAEA;;;;;;AAEA,IAAMA,QAAQ,GAAG,CACf;AACEC,EAAAA,OAAO,EAAEC,kCADX;AAEEC,EAAAA,UAAU,EAAEC;AAFd,CADe,EAKf;AACEH,EAAAA,OAAO,EAAEI,kCADX;AAEEC,EAAAA,OAAO,EAAE;AAAEC,IAAAA,iBAAiB,EAAE,IAArB;AAA2BC,IAAAA,iBAAiB,EAAE;AAA9C,GAFX;AAGEC,EAAAA,OAAO,EAAE,IAHX;AAIEN,EAAAA,UAAU,EAAEO,qCAJd;AAKEC,EAAAA,wBAAwB,EAAE;AAL5B,CALe,CAAjB;;eAce,kBAACC,SAAD;AAAA,SAAe,UAACC,KAAD,EAAW;AACvC,QAAMC,QAAQ,GAAG,OAAOC,MAAP,KAAkB,WAAnC;AAEA,wBACE,gCAAC,qBAAD;AAAa,MAAA,OAAO,EAAEC,gCAAtB;AAAoC,MAAA,OAAO,EAAE;AAAEhB,QAAAA,QAAQ,EAARA;AAAF;AAA7C,OAAgEc,QAAQ,IAAI;AAAEG,MAAAA,OAAO,EAAEF;AAAX,KAA5E,gBACE,gCAAC,SAAD,EAAeF,KAAf,CADF,eAEE,gCAAC,4BAAD,OAFF,CADF;AAMD,GATc;AAAA,C","sourcesContent":["import React from 'react';\nimport MultiBackend, { TouchTransition, MouseTransition } from 'react-dnd-multi-backend';\nimport { DndProvider } from 'react-dnd';\nimport { TouchBackend } from 'react-dnd-touch-backend';\nimport { HTML5Backend } from 'react-dnd-html5-backend';\n\nimport PreviewComponent from './preview-component';\n\nconst backends = [\n {\n backend: HTML5Backend,\n transition: MouseTransition,\n },\n {\n backend: TouchBackend,\n options: { enableMouseEvents: true, enableTouchEvents: true },\n preview: true,\n transition: TouchTransition,\n skipDispatchOnTransition: true,\n },\n];\n\nexport default (Component) => (props) => {\n const isClient = typeof window !== 'undefined';\n\n return (\n <DndProvider backend={MultiBackend} options={{ backends }} {...(isClient && { context: window })}>\n <Component {...props} />\n <PreviewComponent />\n </DndProvider>\n );\n};\n"],"file":"with-drag-context.js"}
|
package/src/choice.jsx
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
3
|
-
import { withStyles } from '@material-ui/core/styles';
|
|
4
|
-
import classNames from 'classnames';
|
|
5
|
-
import grey from '@material-ui/core/colors/grey';
|
|
6
|
-
|
|
7
|
-
import { DragSource } from 'react-dnd';
|
|
8
|
-
import { withUid } from './uid-context';
|
|
9
|
-
|
|
10
|
-
export const DRAG_TYPE = 'CHOICE';
|
|
11
|
-
|
|
12
|
-
export class Choice extends React.Component {
|
|
13
|
-
static propTypes = {
|
|
14
|
-
classes: PropTypes.object.isRequired,
|
|
15
|
-
className: PropTypes.string,
|
|
16
|
-
children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]),
|
|
17
|
-
connectDragSource: PropTypes.func.isRequired,
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
static defaultProps = {};
|
|
21
|
-
|
|
22
|
-
render() {
|
|
23
|
-
const { classes, className, children, connectDragSource } = this.props;
|
|
24
|
-
|
|
25
|
-
return connectDragSource(<div className={classNames(classes.choice, className)}>{children}</div>);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const styles = (theme) => ({
|
|
30
|
-
choice: {
|
|
31
|
-
backgroundColor: theme.palette.background.paper,
|
|
32
|
-
border: `solid 1px ${grey[400]}`,
|
|
33
|
-
padding: theme.spacing.unit,
|
|
34
|
-
minHeight: '30px',
|
|
35
|
-
minWidth: theme.spacing.unit * 20,
|
|
36
|
-
maxWidth: theme.spacing.unit * 75,
|
|
37
|
-
},
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
const choiceSource = {
|
|
41
|
-
canDrag(props) {
|
|
42
|
-
return !props.disabled;
|
|
43
|
-
},
|
|
44
|
-
beginDrag(props) {
|
|
45
|
-
const out = {
|
|
46
|
-
choiceId: props.choice.id,
|
|
47
|
-
from: props.category.id,
|
|
48
|
-
alternateResponseIndex: props.alternateResponseIndex,
|
|
49
|
-
choiceIndex: props.choiceIndex,
|
|
50
|
-
};
|
|
51
|
-
return out;
|
|
52
|
-
},
|
|
53
|
-
|
|
54
|
-
endDrag: (props, monitor) => {
|
|
55
|
-
if (!monitor.didDrop()) {
|
|
56
|
-
const item = monitor.getItem();
|
|
57
|
-
if (item.from) {
|
|
58
|
-
props.onRemoveChoice(item);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
},
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
const styledChoice = withStyles(styles)(Choice);
|
|
65
|
-
|
|
66
|
-
const DraggableChoice = DragSource(
|
|
67
|
-
({ uid }) => uid,
|
|
68
|
-
choiceSource,
|
|
69
|
-
(connect, monitor) => ({
|
|
70
|
-
connectDragSource: connect.dragSource(),
|
|
71
|
-
connectDragPreview: connect.dragPreview(),
|
|
72
|
-
isDragging: monitor.isDragging(),
|
|
73
|
-
}),
|
|
74
|
-
)(styledChoice);
|
|
75
|
-
|
|
76
|
-
export default withUid(DraggableChoice);
|
package/src/with-drag-context.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import MultiBackend, { TouchTransition, MouseTransition } from 'react-dnd-multi-backend';
|
|
3
|
-
import { DndProvider } from 'react-dnd';
|
|
4
|
-
import { TouchBackend } from 'react-dnd-touch-backend';
|
|
5
|
-
import { HTML5Backend } from 'react-dnd-html5-backend';
|
|
6
|
-
|
|
7
|
-
import PreviewComponent from './preview-component';
|
|
8
|
-
|
|
9
|
-
const backends = [
|
|
10
|
-
{
|
|
11
|
-
backend: HTML5Backend,
|
|
12
|
-
transition: MouseTransition,
|
|
13
|
-
},
|
|
14
|
-
{
|
|
15
|
-
backend: TouchBackend,
|
|
16
|
-
options: { enableMouseEvents: true, enableTouchEvents: true },
|
|
17
|
-
preview: true,
|
|
18
|
-
transition: TouchTransition,
|
|
19
|
-
skipDispatchOnTransition: true,
|
|
20
|
-
},
|
|
21
|
-
];
|
|
22
|
-
|
|
23
|
-
export default (Component) => (props) => {
|
|
24
|
-
const isClient = typeof window !== 'undefined';
|
|
25
|
-
|
|
26
|
-
return (
|
|
27
|
-
<DndProvider backend={MultiBackend} options={{ backends }} {...(isClient && { context: window })}>
|
|
28
|
-
<Component {...props} />
|
|
29
|
-
<PreviewComponent />
|
|
30
|
-
</DndProvider>
|
|
31
|
-
);
|
|
32
|
-
};
|