@pie-lib/drag 2.0.3 → 2.0.4
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 +11 -0
- package/lib/choice.js +25 -3
- package/lib/choice.js.map +1 -1
- package/package.json +2 -2
- package/src/choice.jsx +28 -5
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,17 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [2.0.4](https://github.com/pie-framework/pie-lib/compare/@pie-lib/drag@2.0.3...@pie-lib/drag@2.0.4) (2022-12-19)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* **drag,categorize:** drag an answer choice elsewhere after it has been placed in a category-PD-1995 ([d32015b](https://github.com/pie-framework/pie-lib/commit/d32015b31d50b45851df2f27ad517eeaad8ae511))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
6
17
|
## [2.0.3](https://github.com/pie-framework/pie-lib/compare/@pie-lib/drag@2.0.2...@pie-lib/drag@2.0.3) (2022-12-06)
|
|
7
18
|
|
|
8
19
|
|
package/lib/choice.js
CHANGED
|
@@ -31,6 +31,8 @@ var _grey = _interopRequireDefault(require("@material-ui/core/colors/grey"));
|
|
|
31
31
|
|
|
32
32
|
var _reactDnd = require("react-dnd");
|
|
33
33
|
|
|
34
|
+
var _uidContext = require("./uid-context");
|
|
35
|
+
|
|
34
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); }; }
|
|
35
37
|
|
|
36
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; } }
|
|
@@ -89,17 +91,37 @@ var choiceSource = {
|
|
|
89
91
|
return !props.disabled;
|
|
90
92
|
},
|
|
91
93
|
beginDrag: function beginDrag(props) {
|
|
92
|
-
|
|
94
|
+
var out = {
|
|
95
|
+
choiceId: props.choice.id,
|
|
96
|
+
from: props.category.id,
|
|
97
|
+
alternateResponseIndex: props.alternateResponseIndex,
|
|
98
|
+
choiceIndex: props.choiceIndex
|
|
99
|
+
};
|
|
100
|
+
return out;
|
|
101
|
+
},
|
|
102
|
+
endDrag: function endDrag(props, monitor) {
|
|
103
|
+
if (!monitor.didDrop()) {
|
|
104
|
+
var item = monitor.getItem();
|
|
105
|
+
|
|
106
|
+
if (item.from) {
|
|
107
|
+
props.onRemoveChoice(item);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
93
110
|
}
|
|
94
111
|
};
|
|
95
112
|
var styledChoice = (0, _styles.withStyles)(styles)(Choice);
|
|
96
|
-
|
|
97
|
-
var
|
|
113
|
+
var DraggableChoice = (0, _reactDnd.DragSource)(function (_ref) {
|
|
114
|
+
var uid = _ref.uid;
|
|
115
|
+
return uid;
|
|
116
|
+
}, choiceSource, function (connect, monitor) {
|
|
98
117
|
return {
|
|
99
118
|
connectDragSource: connect.dragSource(),
|
|
119
|
+
connectDragPreview: connect.dragPreview(),
|
|
100
120
|
isDragging: monitor.isDragging()
|
|
101
121
|
};
|
|
102
122
|
})(styledChoice);
|
|
103
123
|
|
|
124
|
+
var _default = (0, _uidContext.withUid)(DraggableChoice);
|
|
125
|
+
|
|
104
126
|
exports["default"] = _default;
|
|
105
127
|
//# sourceMappingURL=choice.js.map
|
package/lib/choice.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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","border","grey","padding","spacing","unit","minHeight","choiceSource","canDrag","disabled","beginDrag","
|
|
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","border","grey","padding","spacing","unit","minHeight","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":";;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AAEA;;AACA;;;;;;AAEO,IAAMA,SAAS,GAAG,QAAlB;;;IAEMC,M;;;;;;;;;;;;WAUX,kBAAS;AACP,wBAA4D,KAAKC,KAAjE;AAAA,UAAQC,OAAR,eAAQA,OAAR;AAAA,UAAiBC,SAAjB,eAAiBA,SAAjB;AAAA,UAA4BC,QAA5B,eAA4BA,QAA5B;AAAA,UAAsCC,iBAAtC,eAAsCA,iBAAtC;AAEA,aAAOA,iBAAiB,eAAC;AAAK,QAAA,SAAS,EAAE,4BAAWH,OAAO,CAACI,MAAnB,EAA2BH,SAA3B;AAAhB,SAAwDC,QAAxD,CAAD,CAAxB;AACD;;;EAdyBG,kBAAMC,S;;;iCAArBR,M,eACQ;AACjBE,EAAAA,OAAO,EAAEO,sBAAUC,MAAV,CAAiBC,UADT;AAEjBR,EAAAA,SAAS,EAAEM,sBAAUG,MAFJ;AAGjBR,EAAAA,QAAQ,EAAEK,sBAAUI,SAAV,CAAoB,CAACJ,sBAAUK,OAAV,CAAkBL,sBAAUM,IAA5B,CAAD,EAAoCN,sBAAUM,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AGA,GAAH;AAAA,SAAaA,GAAb;AAAA,CADsB,EAEtBnB,YAFsB,EAGtB,UAACoB,OAAD,EAAUR,OAAV;AAAA,SAAuB;AACrBjC,IAAAA,iBAAiB,EAAEyC,OAAO,CAACC,UAAR,EADE;AAErBC,IAAAA,kBAAkB,EAAEF,OAAO,CAACG,WAAR,EAFC;AAGrBC,IAAAA,UAAU,EAAEZ,OAAO,CAACY,UAAR;AAHS,GAAvB;AAAA,CAHsB,EAQtBP,YARsB,CAAxB;;eAUe,yBAAQC,eAAR,C","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: 'white',\n border: `solid 1px ${grey[400]}`,\n padding: theme.spacing.unit,\n minHeight: '30px',\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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pie-lib/drag",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.4",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "src/index.js",
|
|
@@ -17,5 +17,5 @@
|
|
|
17
17
|
"scripts": {},
|
|
18
18
|
"author": "",
|
|
19
19
|
"license": "ISC",
|
|
20
|
-
"gitHead": "
|
|
20
|
+
"gitHead": "b26d56c7bb2ddddd23b4c018ac81c418afed443e"
|
|
21
21
|
}
|
package/src/choice.jsx
CHANGED
|
@@ -5,6 +5,7 @@ import classNames from 'classnames';
|
|
|
5
5
|
import grey from '@material-ui/core/colors/grey';
|
|
6
6
|
|
|
7
7
|
import { DragSource } from 'react-dnd';
|
|
8
|
+
import { withUid } from './uid-context';
|
|
8
9
|
|
|
9
10
|
export const DRAG_TYPE = 'CHOICE';
|
|
10
11
|
|
|
@@ -39,13 +40,35 @@ const choiceSource = {
|
|
|
39
40
|
return !props.disabled;
|
|
40
41
|
},
|
|
41
42
|
beginDrag(props) {
|
|
42
|
-
|
|
43
|
+
const out = {
|
|
44
|
+
choiceId: props.choice.id,
|
|
45
|
+
from: props.category.id,
|
|
46
|
+
alternateResponseIndex: props.alternateResponseIndex,
|
|
47
|
+
choiceIndex: props.choiceIndex,
|
|
48
|
+
};
|
|
49
|
+
return out;
|
|
50
|
+
},
|
|
51
|
+
|
|
52
|
+
endDrag: (props, monitor) => {
|
|
53
|
+
if (!monitor.didDrop()) {
|
|
54
|
+
const item = monitor.getItem();
|
|
55
|
+
if (item.from) {
|
|
56
|
+
props.onRemoveChoice(item);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
43
59
|
},
|
|
44
60
|
};
|
|
45
61
|
|
|
46
62
|
const styledChoice = withStyles(styles)(Choice);
|
|
47
63
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
64
|
+
const DraggableChoice = DragSource(
|
|
65
|
+
({ uid }) => uid,
|
|
66
|
+
choiceSource,
|
|
67
|
+
(connect, monitor) => ({
|
|
68
|
+
connectDragSource: connect.dragSource(),
|
|
69
|
+
connectDragPreview: connect.dragPreview(),
|
|
70
|
+
isDragging: monitor.isDragging(),
|
|
71
|
+
}),
|
|
72
|
+
)(styledChoice);
|
|
73
|
+
|
|
74
|
+
export default withUid(DraggableChoice);
|