@pie-lib/drag 2.18.3-next.12 → 2.19.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.
Files changed (42) hide show
  1. package/CHANGELOG.md +5 -24
  2. package/lib/drag-in-the-blank-dp.js +28 -24
  3. package/lib/drag-in-the-blank-dp.js.map +1 -1
  4. package/lib/drag-provider.js +47 -0
  5. package/lib/drag-provider.js.map +1 -0
  6. package/lib/drag-type.js +2 -3
  7. package/lib/drag-type.js.map +1 -1
  8. package/lib/draggable-choice.js +87 -0
  9. package/lib/draggable-choice.js.map +1 -0
  10. package/lib/droppable-placeholder.js +33 -65
  11. package/lib/droppable-placeholder.js.map +1 -1
  12. package/lib/ica-dp.js +38 -26
  13. package/lib/ica-dp.js.map +1 -1
  14. package/lib/index.js +7 -35
  15. package/lib/index.js.map +1 -1
  16. package/lib/match-list-dp.js +38 -26
  17. package/lib/match-list-dp.js.map +1 -1
  18. package/lib/placeholder.js +77 -102
  19. package/lib/placeholder.js.map +1 -1
  20. package/lib/preview-component.js +67 -107
  21. package/lib/preview-component.js.map +1 -1
  22. package/lib/swap.js +1 -7
  23. package/lib/swap.js.map +1 -1
  24. package/lib/uid-context.js +4 -18
  25. package/lib/uid-context.js.map +1 -1
  26. package/package.json +12 -10
  27. package/src/drag-in-the-blank-dp.jsx +32 -15
  28. package/src/drag-provider.jsx +40 -0
  29. package/src/drag-type.js +1 -1
  30. package/src/draggable-choice.jsx +87 -0
  31. package/src/droppable-placeholder.jsx +38 -28
  32. package/src/ica-dp.jsx +41 -18
  33. package/src/index.js +4 -8
  34. package/src/match-list-dp.jsx +41 -18
  35. package/src/placeholder.jsx +64 -71
  36. package/src/preview-component.jsx +62 -70
  37. package/lib/choice.js +0 -129
  38. package/lib/choice.js.map +0 -1
  39. package/lib/with-drag-context.js +0 -59
  40. package/lib/with-drag-context.js.map +0 -1
  41. package/src/choice.jsx +0 -76
  42. package/src/with-drag-context.js +0 -32
@@ -1,14 +1,66 @@
1
1
  import React from 'react';
2
- import { withStyles } from '@material-ui/core/styles';
2
+ import { styled } from '@mui/material/styles';
3
3
  import classNames from 'classnames';
4
4
  import PropTypes from 'prop-types';
5
- import grey from '@material-ui/core/colors/grey';
6
5
  import { color } from '@pie-lib/render-ui';
6
+ import { grey } from '@mui/material/colors';
7
+
8
+ const StyledPlaceholder = styled('div')(({ theme }) => ({
9
+ WebkitTouchCallout: 'none',
10
+ WebkitUserSelect: 'none',
11
+ KhtmlUserSelect: 'none',
12
+ MozUserSelect: 'none',
13
+ MsUserSelect: 'none',
14
+ userSelect: 'none',
15
+ width: '100%',
16
+ height: '100%',
17
+ background: color.white(),
18
+ transition: 'background-color 200ms linear, border-color 200ms linear',
19
+ boxSizing: 'border-box',
20
+ display: 'grid',
21
+ gridRowGap: `${theme.spacing(1)}px`,
22
+ gridColumnGap: `${theme.spacing(1)}px`,
23
+ padding: theme.spacing(1),
24
+ border: `2px dashed ${color.black()}`,
25
+ '&.disabled': {
26
+ boxShadow: 'none',
27
+ background: theme.palette.background.paper,
28
+ },
29
+ '&.over': {
30
+ border: `1px solid ${grey[500]}`,
31
+ backgroundColor: `${grey[300]}`,
32
+ },
33
+ '&.board': {
34
+ padding: theme.spacing(1),
35
+ display: 'flex',
36
+ flexWrap: 'wrap',
37
+ alignItems: 'center',
38
+ minHeight: '100px',
39
+ justifyContent: 'center',
40
+ overflow: 'hidden',
41
+ touchAction: 'none',
42
+ backgroundColor: color.backgroundDark(),
43
+ },
44
+ '&.categorizeBoard': {
45
+ padding: theme.spacing(0.5),
46
+ display: 'flex',
47
+ flexWrap: 'wrap',
48
+ alignItems: 'center',
49
+ minHeight: '100px',
50
+ justifyContent: 'center',
51
+ overflow: 'hidden',
52
+ touchAction: 'none',
53
+ backgroundColor: color.backgroundDark(),
54
+ },
55
+ '&.verticalPool': {
56
+ display: 'flex',
57
+ flexFlow: 'column wrap',
58
+ },
59
+ }));
7
60
 
8
61
  export const PlaceHolder = (props) => {
9
62
  const {
10
63
  children,
11
- classes,
12
64
  className,
13
65
  isOver,
14
66
  type,
@@ -21,10 +73,10 @@ export const PlaceHolder = (props) => {
21
73
  } = props;
22
74
 
23
75
  const names = classNames(
24
- classes.placeholder,
25
- disabled && classes.disabled,
26
- isOver && classes.over,
27
- classes[type],
76
+ 'placeholder',
77
+ disabled && 'disabled',
78
+ isOver && 'over',
79
+ type,
28
80
  className,
29
81
  );
30
82
 
@@ -49,24 +101,22 @@ export const PlaceHolder = (props) => {
49
101
  style.background = color.backgroundDark();
50
102
  }
51
103
 
52
- const boardStyle = isCategorize ? classes.categorizeBoard : classes.board;
104
+ const boardStyle = isCategorize ? 'categorizeBoard' : 'board';
53
105
 
54
106
  return (
55
- <div
107
+ <StyledPlaceholder
56
108
  style={{ ...style, minHeight: minHeight }}
57
109
  className={classNames(
58
- classes.noSelectStyles,
59
110
  choiceBoard ? boardStyle : names,
60
- isVerticalPool && classes.verticalPool,
111
+ isVerticalPool && 'verticalPool',
61
112
  )}
62
113
  >
63
114
  {children}
64
- </div>
115
+ </StyledPlaceholder>
65
116
  );
66
117
  };
67
118
 
68
119
  PlaceHolder.propTypes = {
69
- classes: PropTypes.object.isRequired,
70
120
  choiceBoard: PropTypes.bool,
71
121
  grid: PropTypes.shape({
72
122
  columns: PropTypes.number,
@@ -85,61 +135,4 @@ PlaceHolder.propTypes = {
85
135
  minHeight: PropTypes.number,
86
136
  };
87
137
 
88
- const styles = (theme) => ({
89
- noSelectStyles: {
90
- WebkitTouchCallout: 'none',
91
- WebkitUserSelect: 'none',
92
- KhtmlUserSelect: 'none',
93
- MozUserSelect: 'none',
94
- MsUserSelect: 'none',
95
- userSelect: 'none',
96
- },
97
- placeholder: {
98
- width: '100%',
99
- height: '100%',
100
- background: color.white(),
101
- transition: 'background-color 200ms linear, border-color 200ms linear',
102
- boxSizing: 'border-box',
103
- display: 'grid',
104
- gridRowGap: `${theme.spacing.unit}px`,
105
- gridColumnGap: `${theme.spacing.unit}px`,
106
- padding: theme.spacing.unit * 1,
107
- border: `2px dashed ${color.black()}`,
108
- },
109
- disabled: {
110
- boxShadow: 'none',
111
- background: theme.palette.background.paper,
112
- },
113
- over: {
114
- border: `1px solid ${grey[500]}`,
115
- backgroundColor: `${grey[300]}`,
116
- },
117
- board: {
118
- padding: theme.spacing.unit,
119
- display: 'flex',
120
- flexWrap: 'wrap',
121
- alignItems: 'center',
122
- minHeight: '100px',
123
- justifyContent: 'center',
124
- overflow: 'hidden',
125
- touchAction: 'none',
126
- backgroundColor: color.backgroundDark(),
127
- },
128
- categorizeBoard: {
129
- padding: theme.spacing.unit / 2,
130
- display: 'flex',
131
- flexWrap: 'wrap',
132
- alignItems: 'center',
133
- minHeight: '100px',
134
- justifyContent: 'center',
135
- overflow: 'hidden',
136
- touchAction: 'none',
137
- backgroundColor: color.backgroundDark(),
138
- },
139
- verticalPool: {
140
- display: 'flex',
141
- flexFlow: 'column wrap',
142
- },
143
- });
144
-
145
- export default withStyles(styles)(PlaceHolder);
138
+ export default PlaceHolder;
@@ -1,5 +1,5 @@
1
- import React, { useEffect, useRef, useState, useCallback } from 'react';
2
- import { usePreview } from 'react-dnd-multi-backend';
1
+ import React, { useEffect, useRef, useState } from 'react';
2
+ import { DragOverlay, useDndContext } from '@dnd-kit/core';
3
3
  import { PreviewPrompt, color } from '@pie-lib/render-ui';
4
4
  import { renderMath } from '@pie-lib/math-rendering';
5
5
 
@@ -54,99 +54,91 @@ const styles = {
54
54
  },
55
55
  };
56
56
 
57
- const getPrompt = (itemType, item) => {
58
- switch (itemType) {
59
- // DRAG-IN-THE-BLANK
57
+ const getPrompt = (dragData) => {
58
+ if (!dragData) return undefined;
59
+
60
+ // Handle different drag data structures based on the component type
61
+ if (dragData.choiceId) {
62
+ // DraggableChoice format
63
+ return dragData.value;
64
+ }
65
+
66
+ // Legacy format support
67
+ switch (dragData.itemType) {
60
68
  case 'MaskBlank':
61
- return item?.choice?.value;
62
- // IMAGE-CLOZE-ASSOCIATION
63
- case 'react-dnd-response':
64
- return item?.value;
65
- // MATCH-LIST
69
+ return dragData.choice?.value;
70
+ case 'dnd-kit-response':
71
+ return dragData.value;
66
72
  case 'Answer':
67
- return item?.value;
68
- // PLACEMENT-ORDERING
73
+ return dragData.value;
69
74
  case 'Tile':
70
- return item?.value;
75
+ return dragData.value;
76
+ case 'categorize':
77
+ return dragData.value;
71
78
  default:
72
- return item?.itemType === 'categorize' ? item?.value : undefined;
79
+ return dragData.value;
73
80
  }
74
81
  };
75
82
 
76
- const getCustomStyle = (itemType, item, touchPosition, style) => {
77
- const transform = `translate(${touchPosition.x}px, ${touchPosition.y}px)`;
78
- const top = style?.top || 0;
79
- const left = style?.left || 0;
80
- const position = style?.position || 'fixed';
83
+ const getCustomStyle = (dragData) => {
84
+ if (!dragData) return {};
81
85
 
82
- return {
83
- position,
84
- top,
85
- left,
86
- transform,
87
- ...(itemType === 'MaskBlank' ? styles.maskBlank : {}),
88
- ...(item?.itemType === 'categorize' ? styles.categorize : {}),
89
- ...(itemType === 'Answer' ? styles.matchList : {}),
90
- ...(itemType === 'Tile' ? styles.placementOrdering : {}),
91
- ...(itemType === 'react-dnd-response' ? styles.ica : {}),
86
+ const baseStyle = {
87
+ cursor: 'grabbing',
88
+ opacity: 0.8,
89
+ transform: 'rotate(5deg)', // Slight rotation for visual feedback
92
90
  };
91
+
92
+ // Apply specific styles based on item type
93
+ if (dragData.itemType === 'MaskBlank') {
94
+ return { ...baseStyle, ...styles.maskBlank };
95
+ }
96
+ if (dragData.itemType === 'categorize') {
97
+ return { ...baseStyle, ...styles.categorize };
98
+ }
99
+ if (dragData.itemType === 'Answer') {
100
+ return { ...baseStyle, ...styles.matchList };
101
+ }
102
+ if (dragData.itemType === 'Tile') {
103
+ return { ...baseStyle, ...styles.placementOrdering };
104
+ }
105
+ if (dragData.itemType === 'dnd-kit-response') {
106
+ return { ...baseStyle, ...styles.ica };
107
+ }
108
+
109
+ // Default style for choice items
110
+ return { ...baseStyle, ...styles.categorize };
93
111
  };
94
112
 
95
113
  const PreviewComponent = () => {
96
- const preview = usePreview();
97
- const { itemType, item, style, display } = preview;
98
- const [touchPosition, setTouchPosition] = useState({ x: 0, y: 0 });
114
+ const { active } = useDndContext();
99
115
  const [zoomLevel, setZoomLevel] = useState(1);
100
-
101
- const handleTouchMove = useCallback(
102
- (event) => {
103
- if (event.touches.length > 0) {
104
- const touch = event.touches[0];
105
- const touchOffset = 1;
106
- setTouchPosition({
107
- x: (touch.clientX + touchOffset) / zoomLevel,
108
- y: (touch.clientY + touchOffset) / zoomLevel,
109
- });
110
- }
111
- },
112
- [zoomLevel],
113
- );
114
-
115
116
  const root = useRef(null);
116
117
 
118
+ const dragData = active?.data?.current;
119
+ const isActive = !!active;
120
+
117
121
  useEffect(() => {
118
- if (display && root.current) {
122
+ if (isActive && root.current) {
119
123
  renderMath(root.current);
120
124
 
121
125
  // Adjusted for precise zoom level calculation in Online Testing, targeting the specific class pattern .asmt-zoomable.asmt-zoom-NR .asmt-question .padding
122
126
  const zoomAffectedElement = document.querySelector('.padding') || document.body;
123
-
124
127
  setZoomLevel(parseFloat(getComputedStyle(zoomAffectedElement).zoom) || 1);
125
128
  }
126
- }, [display, item?.choice?.value, item?.value, itemType, item]);
127
-
128
- useEffect(() => {
129
- const touchMoveListener = (event) => handleTouchMove(event);
130
- if (display) {
131
- window.addEventListener('touchmove', touchMoveListener);
132
- }
133
- return () => {
134
- window.removeEventListener('touchmove', touchMoveListener);
135
- };
136
- }, [display, handleTouchMove]);
137
-
138
- if (!display) {
139
- return null;
140
- }
141
-
142
- const customStyle = getCustomStyle(itemType, item, touchPosition, style);
129
+ }, [isActive, dragData]);
143
130
 
144
- const prompt = getPrompt(itemType, item);
131
+ const customStyle = getCustomStyle(dragData);
132
+ const prompt = getPrompt(dragData);
145
133
 
146
134
  return (
147
- <div ref={root} style={customStyle}>
148
- <PreviewPrompt className="label" prompt={prompt} tagName="span" />
149
- </div>
135
+ <DragOverlay>
136
+ {isActive && prompt && (
137
+ <div ref={root} style={customStyle}>
138
+ <PreviewPrompt className="label" prompt={prompt} tagName="span" />
139
+ </div>
140
+ )}
141
+ </DragOverlay>
150
142
  );
151
143
  };
152
144
 
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"}
@@ -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);
@@ -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
- };