@pie-lib/mask-markup 2.0.0-beta.2 → 2.0.0-next.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.json +1 -871
- package/CHANGELOG.md +296 -2
- package/LICENSE.md +5 -0
- package/NEXT.CHANGELOG.json +1 -0
- package/lib/choices/choice.js +99 -118
- package/lib/choices/choice.js.map +1 -1
- package/lib/choices/index.js +23 -19
- package/lib/choices/index.js.map +1 -1
- package/lib/componentize.js +1 -2
- package/lib/componentize.js.map +1 -1
- package/lib/components/blank.js +315 -221
- package/lib/components/blank.js.map +1 -1
- package/lib/components/correct-input.js +39 -42
- package/lib/components/correct-input.js.map +1 -1
- package/lib/components/dropdown.js +393 -124
- package/lib/components/dropdown.js.map +1 -1
- package/lib/components/input.js +1 -2
- package/lib/components/input.js.map +1 -1
- package/lib/constructed-response.js +82 -26
- package/lib/constructed-response.js.map +1 -1
- package/lib/customizable.js +44 -0
- package/lib/customizable.js.map +1 -0
- package/lib/drag-in-the-blank.js +154 -61
- package/lib/drag-in-the-blank.js.map +1 -1
- package/lib/index.js +7 -0
- package/lib/index.js.map +1 -1
- package/lib/inline-dropdown.js +4 -3
- package/lib/inline-dropdown.js.map +1 -1
- package/lib/mask.js +89 -56
- package/lib/mask.js.map +1 -1
- package/lib/serialization.js +30 -42
- package/lib/serialization.js.map +1 -1
- package/lib/with-mask.js +48 -20
- package/lib/with-mask.js.map +1 -1
- package/package.json +26 -15
- package/src/__tests__/drag-in-the-blank.test.js +111 -0
- package/src/__tests__/index.test.js +39 -0
- package/src/__tests__/mask.test.js +187 -0
- package/src/__tests__/serialization.test.js +54 -0
- package/src/__tests__/utils.js +1 -0
- package/src/__tests__/with-mask.test.js +76 -0
- package/src/choices/__tests__/index.test.js +75 -0
- package/src/choices/choice.jsx +83 -96
- package/src/choices/index.jsx +11 -5
- package/src/components/__tests__/blank.test.js +138 -0
- package/src/components/__tests__/correct-input.test.js +90 -0
- package/src/components/__tests__/dropdown.test.js +93 -0
- package/src/components/__tests__/input.test.js +102 -0
- package/src/components/blank.jsx +316 -204
- package/src/components/correct-input.jsx +37 -38
- package/src/components/dropdown.jsx +371 -125
- package/src/constructed-response.jsx +80 -18
- package/src/customizable.jsx +35 -0
- package/src/drag-in-the-blank.jsx +152 -40
- package/src/index.js +10 -1
- package/src/inline-dropdown.jsx +2 -0
- package/src/mask.jsx +71 -25
- package/src/serialization.js +22 -34
- package/src/with-mask.jsx +43 -3
- package/README.md +0 -14
- package/lib/new-serialization.js +0 -267
- package/lib/new-serialization.js.map +0 -1
- package/lib/parse-html.js +0 -17
- package/lib/parse-html.js.map +0 -1
- package/lib/test-serializer.js +0 -164
- package/lib/test-serializer.js.map +0 -1
- package/src/new-serialization.jsx +0 -291
- package/src/parse-html.js +0 -8
- package/src/test-serializer.js +0 -163
package/lib/components/blank.js
CHANGED
|
@@ -1,263 +1,357 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
4
5
|
Object.defineProperty(exports, "__esModule", {
|
|
5
6
|
value: true
|
|
6
7
|
});
|
|
7
|
-
exports["default"] =
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
11
|
-
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
12
|
-
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
13
|
-
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
8
|
+
exports["default"] = void 0;
|
|
9
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
10
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
14
11
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
15
|
-
var _react =
|
|
16
|
-
var _reactDom = _interopRequireDefault(require("react-dom"));
|
|
12
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
17
13
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
18
14
|
var _mathRendering = require("@pie-lib/math-rendering");
|
|
19
15
|
var _debug = _interopRequireDefault(require("debug"));
|
|
20
|
-
var
|
|
21
|
-
var
|
|
22
|
-
var
|
|
23
|
-
var
|
|
16
|
+
var _core = require("@dnd-kit/core");
|
|
17
|
+
var _utilities = require("@dnd-kit/utilities");
|
|
18
|
+
var _styles = require("@mui/material/styles");
|
|
19
|
+
var _Chip = _interopRequireDefault(require("@mui/material/Chip"));
|
|
20
|
+
var _classnames = _interopRequireDefault(require("classnames"));
|
|
24
21
|
var _renderUi = require("@pie-lib/render-ui");
|
|
25
|
-
var
|
|
26
|
-
function
|
|
27
|
-
function
|
|
28
|
-
function
|
|
29
|
-
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; } }
|
|
22
|
+
var _colors = require("@mui/material/colors");
|
|
23
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
|
|
24
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
25
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2["default"])(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
30
26
|
var log = (0, _debug["default"])('pie-lib:mask-markup:blank');
|
|
31
|
-
var
|
|
32
|
-
|
|
33
|
-
|
|
27
|
+
var StyledContent = (0, _styles.styled)('span')(function (_ref) {
|
|
28
|
+
var dragged = _ref.dragged,
|
|
29
|
+
over = _ref.over;
|
|
30
|
+
return _objectSpread(_objectSpread({
|
|
31
|
+
border: "solid 0px ".concat(_renderUi.color.primary()),
|
|
32
|
+
minWidth: '200px',
|
|
33
|
+
touchAction: 'none',
|
|
34
|
+
overflow: 'hidden',
|
|
35
|
+
whiteSpace: 'nowrap',
|
|
36
|
+
opacity: 1
|
|
37
|
+
}, over && {
|
|
38
|
+
whiteSpace: 'nowrap',
|
|
39
|
+
overflow: 'hidden'
|
|
40
|
+
}), dragged && {
|
|
41
|
+
opacity: 0.5
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
var StyledChip = (0, _styles.styled)(_Chip["default"])(function () {
|
|
34
45
|
return {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
46
|
+
backgroundColor: _renderUi.color.background(),
|
|
47
|
+
border: "2px dashed ".concat(_renderUi.color.text()),
|
|
48
|
+
color: _renderUi.color.text(),
|
|
49
|
+
fontSize: 'inherit',
|
|
50
|
+
maxWidth: '374px',
|
|
51
|
+
position: 'relative',
|
|
52
|
+
borderRadius: '3px',
|
|
53
|
+
'&.over': {
|
|
54
|
+
whiteSpace: 'nowrap',
|
|
39
55
|
overflow: 'hidden'
|
|
40
56
|
},
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
color: _renderUi.color.text(),
|
|
45
|
-
minWidth: '90px',
|
|
46
|
-
fontSize: 'inherit',
|
|
47
|
-
minHeight: '32px',
|
|
48
|
-
height: 'auto',
|
|
49
|
-
maxWidth: '374px',
|
|
50
|
-
position: 'relative'
|
|
57
|
+
'&.parentOver': {
|
|
58
|
+
border: "1px solid ".concat(_colors.grey[500]),
|
|
59
|
+
backgroundColor: "".concat(_colors.grey[300])
|
|
51
60
|
},
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
// Added for touch devices, for image content.
|
|
55
|
-
// This will prevent the context menu from appearing and not allowing other interactions with the image.
|
|
56
|
-
// If interactions with the image in the token will be requested we should handle only the context Menu.
|
|
57
|
-
pointerEvents: 'none',
|
|
58
|
-
'& img': {
|
|
59
|
-
display: 'block',
|
|
60
|
-
padding: '2px 0'
|
|
61
|
-
}
|
|
61
|
+
'&.correct': {
|
|
62
|
+
border: "solid 1px ".concat(_renderUi.color.correct())
|
|
62
63
|
},
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
opacity: 0
|
|
64
|
+
'&.incorrect': {
|
|
65
|
+
border: "solid 1px ".concat(_renderUi.color.incorrect())
|
|
66
66
|
},
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
67
|
+
'&.Mui-disabled': {
|
|
68
|
+
opacity: 1
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
});
|
|
72
|
+
var StyledChipLabel = (0, _styles.styled)('span')(function () {
|
|
73
|
+
return {
|
|
74
|
+
whiteSpace: 'normal',
|
|
75
|
+
// Added for touch devices, for image content.
|
|
76
|
+
// This will prevent the context menu from appearing and not allowing other interactions with the image.
|
|
77
|
+
// If interactions with the image in the token will be requested we should handle only the context Menu.
|
|
78
|
+
pointerEvents: 'none',
|
|
79
|
+
'& img': {
|
|
80
|
+
display: 'block',
|
|
81
|
+
padding: '2px 0'
|
|
71
82
|
},
|
|
72
|
-
|
|
73
|
-
|
|
83
|
+
// Remove default <p> margins to ensure consistent spacing across all wrapped content (p, span, div, math)
|
|
84
|
+
// Padding for top and bottom will instead be controlled by the container for consistent layout
|
|
85
|
+
// Ensures consistent behavior with pie-api-browser, where marginTop is already removed by a Bootstrap stylesheet
|
|
86
|
+
'& p': {
|
|
87
|
+
marginTop: '0',
|
|
88
|
+
marginBottom: '0'
|
|
74
89
|
},
|
|
75
|
-
|
|
76
|
-
|
|
90
|
+
'& mjx-frac': {
|
|
91
|
+
fontSize: '120% !important'
|
|
77
92
|
},
|
|
78
|
-
over: {
|
|
93
|
+
'&.over': {
|
|
79
94
|
whiteSpace: 'nowrap',
|
|
80
95
|
overflow: 'hidden'
|
|
96
|
+
},
|
|
97
|
+
'&.hidden': {
|
|
98
|
+
color: 'transparent',
|
|
99
|
+
opacity: 0
|
|
100
|
+
},
|
|
101
|
+
'&.dragged': {
|
|
102
|
+
position: 'absolute',
|
|
103
|
+
left: 16,
|
|
104
|
+
maxWidth: '60px'
|
|
81
105
|
}
|
|
82
106
|
};
|
|
83
107
|
});
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
var
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
108
|
+
function BlankContent(_ref2) {
|
|
109
|
+
var _dragItem$choice, _frozenRef$current, _frozenRef$current2;
|
|
110
|
+
var disabled = _ref2.disabled,
|
|
111
|
+
choice = _ref2.choice,
|
|
112
|
+
isOver = _ref2.isOver,
|
|
113
|
+
isDragging = _ref2.isDragging,
|
|
114
|
+
dragItem = _ref2.dragItem,
|
|
115
|
+
correct = _ref2.correct,
|
|
116
|
+
emptyResponseAreaWidth = _ref2.emptyResponseAreaWidth,
|
|
117
|
+
emptyResponseAreaHeight = _ref2.emptyResponseAreaHeight;
|
|
118
|
+
var rootRef = (0, _react.useRef)(null);
|
|
119
|
+
var spanRef = (0, _react.useRef)(null);
|
|
120
|
+
var frozenRef = (0, _react.useRef)(null); // to use during dragging to prevent flickering
|
|
121
|
+
var _useState = (0, _react.useState)({
|
|
122
|
+
height: 0,
|
|
123
|
+
width: 0
|
|
124
|
+
}),
|
|
125
|
+
_useState2 = (0, _slicedToArray2["default"])(_useState, 2),
|
|
126
|
+
dimensions = _useState2[0],
|
|
127
|
+
setDimensions = _useState2[1];
|
|
128
|
+
var handleImageLoad = function handleImageLoad() {
|
|
129
|
+
updateDimensions();
|
|
130
|
+
};
|
|
131
|
+
var handleElements = function handleElements() {
|
|
132
|
+
var _spanRef$current;
|
|
133
|
+
var imageElement = (_spanRef$current = spanRef.current) === null || _spanRef$current === void 0 ? void 0 : _spanRef$current.querySelector('img');
|
|
134
|
+
if (imageElement) {
|
|
135
|
+
imageElement.onload = handleImageLoad;
|
|
136
|
+
} else {
|
|
137
|
+
setTimeout(function () {
|
|
138
|
+
updateDimensions();
|
|
139
|
+
}, 300);
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
var updateDimensions = function updateDimensions() {
|
|
143
|
+
if (spanRef.current && rootRef.current) {
|
|
144
|
+
// Temporarily set rootRef width to 'auto' for natural measurement
|
|
145
|
+
rootRef.current.style.width = 'auto';
|
|
146
|
+
|
|
147
|
+
// Get the natural dimensions of the content
|
|
148
|
+
var width = spanRef.current.offsetWidth || 0;
|
|
149
|
+
var height = spanRef.current.offsetHeight || 0;
|
|
150
|
+
var widthWithPadding = width + 24; // 12px padding on each side
|
|
151
|
+
var heightWithPadding = height + 24; // 12px padding on top and bottom
|
|
152
|
+
|
|
153
|
+
var responseAreaWidth = parseFloat(emptyResponseAreaWidth) || 0;
|
|
154
|
+
var responseAreaHeight = parseFloat(emptyResponseAreaHeight) || 0;
|
|
155
|
+
var adjustedWidth = widthWithPadding <= responseAreaWidth ? responseAreaWidth : widthWithPadding;
|
|
156
|
+
var adjustedHeight = heightWithPadding <= responseAreaHeight ? responseAreaHeight : heightWithPadding;
|
|
157
|
+
setDimensions(function (prevState) {
|
|
158
|
+
return {
|
|
159
|
+
width: adjustedWidth > responseAreaWidth ? adjustedWidth : prevState.width,
|
|
160
|
+
height: adjustedHeight > responseAreaHeight ? adjustedHeight : prevState.height
|
|
161
|
+
};
|
|
162
|
+
});
|
|
163
|
+
rootRef.current.style.width = "".concat(adjustedWidth, "px");
|
|
164
|
+
rootRef.current.style.height = "".concat(adjustedHeight, "px");
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
var getRootDimensions = function getRootDimensions() {
|
|
168
|
+
// Handle potential non-numeric values
|
|
169
|
+
var responseAreaWidth = !isNaN(parseFloat(emptyResponseAreaWidth)) ? parseFloat(emptyResponseAreaWidth) : 0;
|
|
170
|
+
var responseAreaHeight = !isNaN(parseFloat(emptyResponseAreaHeight)) ? parseFloat(emptyResponseAreaHeight) : 0;
|
|
171
|
+
var rootStyle = {
|
|
172
|
+
height: dimensions.height || responseAreaHeight,
|
|
173
|
+
width: dimensions.width || responseAreaWidth
|
|
93
174
|
};
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
setTimeout(function () {
|
|
111
|
-
_this2.setState({
|
|
112
|
-
height: _this2.spanRef.offsetHeight
|
|
113
|
-
});
|
|
114
|
-
}, 300);
|
|
115
|
-
}
|
|
175
|
+
|
|
176
|
+
// add minWidth, minHeight if width and height are not defined
|
|
177
|
+
return _objectSpread(_objectSpread(_objectSpread({}, rootStyle), responseAreaWidth ? {} : {
|
|
178
|
+
minWidth: 90
|
|
179
|
+
}), responseAreaHeight ? {} : {
|
|
180
|
+
minHeight: 32
|
|
181
|
+
});
|
|
182
|
+
};
|
|
183
|
+
(0, _react.useEffect)(function () {
|
|
184
|
+
handleElements();
|
|
185
|
+
}, []);
|
|
186
|
+
|
|
187
|
+
// Render math for the placeholder/preview when dragging over
|
|
188
|
+
(0, _react.useEffect)(function () {
|
|
189
|
+
if (rootRef.current) {
|
|
190
|
+
(0, _mathRendering.renderMath)(rootRef.current);
|
|
116
191
|
}
|
|
117
|
-
},
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
}
|
|
192
|
+
}, [isOver, dragItem === null || dragItem === void 0 || (_dragItem$choice = dragItem.choice) === null || _dragItem$choice === void 0 ? void 0 : _dragItem$choice.value]);
|
|
193
|
+
(0, _react.useEffect)(function () {
|
|
194
|
+
if (!choice) {
|
|
195
|
+
setDimensions({
|
|
196
|
+
height: 0,
|
|
197
|
+
width: 0
|
|
124
198
|
});
|
|
199
|
+
return;
|
|
125
200
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
classes = _this$props.classes,
|
|
135
|
-
isOver = _this$props.isOver,
|
|
136
|
-
dragItem = _this$props.dragItem,
|
|
137
|
-
correct = _this$props.correct;
|
|
138
|
-
var draggedLabel = dragItem && isOver && dragItem.choice.value;
|
|
139
|
-
var label = choice && choice.value;
|
|
140
|
-
return (
|
|
141
|
-
/*#__PURE__*/
|
|
142
|
-
// TODO the Chip element is causing drag problems on touch devices. Avoid using Chip and consider refactoring the code. Keep in mind that Chip is a span with a button role, which interferes with seamless touch device dragging.
|
|
143
|
-
_react["default"].createElement(_Chip["default"], {
|
|
144
|
-
clickable: false,
|
|
145
|
-
disabled: true,
|
|
146
|
-
ref: function ref(_ref3) {
|
|
147
|
-
//eslint-disable-next-line
|
|
148
|
-
_this3.rootRef = _reactDom["default"].findDOMNode(_ref3);
|
|
149
|
-
},
|
|
150
|
-
component: "span",
|
|
151
|
-
label: /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement("span", {
|
|
152
|
-
className: (0, _classnames3["default"])(classes.chipLabel, isOver && classes.over, (0, _defineProperty2["default"])({}, classes.hidden, draggedLabel)),
|
|
153
|
-
ref: function ref(_ref) {
|
|
154
|
-
if (_ref) {
|
|
155
|
-
//eslint-disable-next-line
|
|
156
|
-
_this3.spanRef = _reactDom["default"].findDOMNode(_ref);
|
|
157
|
-
_ref.innerHTML = label || '';
|
|
158
|
-
_this3.addDraggableFalseAttributes(_ref);
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
}, ' '), draggedLabel && /*#__PURE__*/_react["default"].createElement("span", {
|
|
162
|
-
className: (0, _classnames3["default"])(classes.chipLabel, isOver && classes.over, classes.dragged),
|
|
163
|
-
ref: function ref(_ref2) {
|
|
164
|
-
if (_ref2) {
|
|
165
|
-
//eslint-disable-next-line
|
|
166
|
-
_this3.spanRef = _reactDom["default"].findDOMNode(_ref2);
|
|
167
|
-
_ref2.innerHTML = draggedLabel || '';
|
|
168
|
-
_this3.addDraggableFalseAttributes(_ref2);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
}, ' ')),
|
|
172
|
-
className: (0, _classnames3["default"])(classes.chip, isOver && classes.over, (_classnames2 = {}, (0, _defineProperty2["default"])(_classnames2, classes.correct, correct !== undefined && correct), (0, _defineProperty2["default"])(_classnames2, classes.incorrect, correct !== undefined && !correct), _classnames2)),
|
|
173
|
-
variant: disabled ? 'outlined' : undefined,
|
|
174
|
-
style: _objectSpread({}, this.state.height ? {
|
|
175
|
-
height: this.state.height
|
|
176
|
-
} : {}),
|
|
177
|
-
classes: {
|
|
178
|
-
label: isOver && classes.over
|
|
179
|
-
}
|
|
180
|
-
})
|
|
181
|
-
);
|
|
201
|
+
handleElements();
|
|
202
|
+
}, [choice]);
|
|
203
|
+
(0, _react.useEffect)(function () {
|
|
204
|
+
if (!isOver && !isDragging) {
|
|
205
|
+
frozenRef.current = {
|
|
206
|
+
width: rootRef.current.offsetWidth,
|
|
207
|
+
height: rootRef.current.offsetHeight
|
|
208
|
+
};
|
|
182
209
|
}
|
|
183
|
-
}]);
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
(
|
|
210
|
+
}, [choice, isOver, isDragging]);
|
|
211
|
+
var draggedLabel = dragItem && isOver && dragItem.choice && dragItem.choice.value;
|
|
212
|
+
var label = choice && choice.value;
|
|
213
|
+
var style = isOver || isDragging ? {
|
|
214
|
+
width: (_frozenRef$current = frozenRef.current) === null || _frozenRef$current === void 0 ? void 0 : _frozenRef$current.width,
|
|
215
|
+
height: (_frozenRef$current2 = frozenRef.current) === null || _frozenRef$current2 === void 0 ? void 0 : _frozenRef$current2.height
|
|
216
|
+
} : getRootDimensions();
|
|
217
|
+
return /*#__PURE__*/_react["default"].createElement(StyledChip, {
|
|
218
|
+
clickable: false,
|
|
219
|
+
disabled: disabled,
|
|
220
|
+
ref: rootRef,
|
|
221
|
+
component: "span",
|
|
222
|
+
label: /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(StyledChipLabel, {
|
|
223
|
+
ref: spanRef,
|
|
224
|
+
draggable: true,
|
|
225
|
+
className: (0, _classnames["default"])({
|
|
226
|
+
over: isOver,
|
|
227
|
+
hidden: draggedLabel
|
|
228
|
+
}),
|
|
229
|
+
dangerouslySetInnerHTML: {
|
|
230
|
+
__html: label || ''
|
|
231
|
+
}
|
|
232
|
+
}), draggedLabel && /*#__PURE__*/_react["default"].createElement(StyledChipLabel, {
|
|
233
|
+
draggable: true,
|
|
234
|
+
className: (0, _classnames["default"])({
|
|
235
|
+
over: isOver,
|
|
236
|
+
dragged: true
|
|
237
|
+
}),
|
|
238
|
+
dangerouslySetInnerHTML: {
|
|
239
|
+
__html: draggedLabel || ''
|
|
240
|
+
}
|
|
241
|
+
})),
|
|
242
|
+
className: (0, _classnames["default"])({
|
|
243
|
+
over: isOver,
|
|
244
|
+
parentOver: isOver,
|
|
245
|
+
correct: correct !== undefined && correct,
|
|
246
|
+
incorrect: correct !== undefined && !correct
|
|
247
|
+
}),
|
|
248
|
+
variant: disabled ? 'outlined' : undefined,
|
|
249
|
+
style: style
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
BlankContent.defaultProps = {
|
|
253
|
+
emptyResponseAreaWidth: 0,
|
|
254
|
+
emptyResponseAreaHeight: 0
|
|
255
|
+
};
|
|
256
|
+
BlankContent.propTypes = {
|
|
188
257
|
id: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].number]),
|
|
189
258
|
disabled: _propTypes["default"].bool,
|
|
190
259
|
duplicates: _propTypes["default"].bool,
|
|
191
260
|
choice: _propTypes["default"].object,
|
|
192
|
-
classes: _propTypes["default"].object,
|
|
193
261
|
isOver: _propTypes["default"].bool,
|
|
194
262
|
dragItem: _propTypes["default"].object,
|
|
195
263
|
correct: _propTypes["default"].bool,
|
|
196
|
-
onChange: _propTypes["default"].func
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
var connectDragSource = _ref4.connectDragSource,
|
|
201
|
-
connectDropTarget = _ref4.connectDropTarget,
|
|
202
|
-
props = (0, _objectWithoutProperties2["default"])(_ref4, _excluded);
|
|
203
|
-
var classes = props.classes,
|
|
204
|
-
isOver = props.isOver;
|
|
205
|
-
return connectDropTarget(connectDragSource( /*#__PURE__*/_react["default"].createElement("span", {
|
|
206
|
-
className: (0, _classnames3["default"])(classes.content, isOver && classes.over)
|
|
207
|
-
}, /*#__PURE__*/_react["default"].createElement(StyledBlankContent, props))));
|
|
208
|
-
});
|
|
209
|
-
var tileTarget = {
|
|
210
|
-
drop: function drop(props, monitor) {
|
|
211
|
-
var draggedItem = monitor.getItem();
|
|
212
|
-
log('props.instanceId', props.instanceId, 'draggedItem.instanceId:', draggedItem.instanceId);
|
|
213
|
-
if (draggedItem.id !== props.id) {
|
|
214
|
-
props.onChange(props.id, draggedItem.choice.id);
|
|
215
|
-
}
|
|
216
|
-
return {
|
|
217
|
-
dropped: draggedItem.id !== props.id
|
|
218
|
-
};
|
|
219
|
-
},
|
|
220
|
-
canDrop: function canDrop(props, monitor) {
|
|
221
|
-
var draggedItem = monitor.getItem();
|
|
222
|
-
return draggedItem.instanceId === props.instanceId;
|
|
223
|
-
}
|
|
264
|
+
onChange: _propTypes["default"].func,
|
|
265
|
+
emptyResponseAreaWidth: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].number]),
|
|
266
|
+
emptyResponseAreaHeight: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].number]),
|
|
267
|
+
instanceId: _propTypes["default"].string
|
|
224
268
|
};
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
if (draggedItem.fromChoice) {
|
|
250
|
-
props.onChange(props.id, undefined);
|
|
269
|
+
|
|
270
|
+
// New functional component using @dnd-kit hooks
|
|
271
|
+
function DragDropBlank(_ref3) {
|
|
272
|
+
var _dragItem$data;
|
|
273
|
+
var id = _ref3.id,
|
|
274
|
+
disabled = _ref3.disabled,
|
|
275
|
+
duplicates = _ref3.duplicates,
|
|
276
|
+
choice = _ref3.choice,
|
|
277
|
+
correct = _ref3.correct,
|
|
278
|
+
onChange = _ref3.onChange,
|
|
279
|
+
emptyResponseAreaWidth = _ref3.emptyResponseAreaWidth,
|
|
280
|
+
emptyResponseAreaHeight = _ref3.emptyResponseAreaHeight,
|
|
281
|
+
instanceId = _ref3.instanceId;
|
|
282
|
+
// Setup draggable functionality
|
|
283
|
+
var _useDraggable = (0, _core.useDraggable)({
|
|
284
|
+
id: "mask-blank-drag-".concat(id),
|
|
285
|
+
disabled: disabled || !choice,
|
|
286
|
+
data: {
|
|
287
|
+
id: id,
|
|
288
|
+
choice: choice,
|
|
289
|
+
instanceId: instanceId,
|
|
290
|
+
fromChoice: false,
|
|
291
|
+
// This is from a blank, not from choices
|
|
292
|
+
type: 'MaskBlank'
|
|
251
293
|
}
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
294
|
+
}),
|
|
295
|
+
dragAttributes = _useDraggable.attributes,
|
|
296
|
+
dragListeners = _useDraggable.listeners,
|
|
297
|
+
setDragNodeRef = _useDraggable.setNodeRef,
|
|
298
|
+
transform = _useDraggable.transform,
|
|
299
|
+
isDragging = _useDraggable.isDragging;
|
|
300
|
+
|
|
301
|
+
// Setup droppable functionality
|
|
302
|
+
var _useDroppable = (0, _core.useDroppable)({
|
|
303
|
+
id: "mask-blank-drop-".concat(id),
|
|
304
|
+
data: {
|
|
305
|
+
id: id,
|
|
306
|
+
accepts: ['MaskBlank'],
|
|
307
|
+
instanceId: instanceId
|
|
308
|
+
}
|
|
309
|
+
}),
|
|
310
|
+
setDropNodeRef = _useDroppable.setNodeRef,
|
|
311
|
+
isOver = _useDroppable.isOver,
|
|
312
|
+
dragItem = _useDroppable.active;
|
|
313
|
+
|
|
314
|
+
// Combine refs for both drag and drop
|
|
315
|
+
var setNodeRef = function setNodeRef(node) {
|
|
316
|
+
setDragNodeRef(node);
|
|
317
|
+
setDropNodeRef(node);
|
|
318
|
+
};
|
|
319
|
+
var style = {
|
|
320
|
+
transform: _utilities.CSS.Translate.toString(transform)
|
|
259
321
|
};
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
322
|
+
return /*#__PURE__*/_react["default"].createElement(StyledContent, (0, _extends2["default"])({
|
|
323
|
+
ref: setNodeRef,
|
|
324
|
+
style: style,
|
|
325
|
+
dragged: isDragging,
|
|
326
|
+
over: isOver
|
|
327
|
+
}, dragAttributes, dragListeners), /*#__PURE__*/_react["default"].createElement(BlankContent, {
|
|
328
|
+
id: id,
|
|
329
|
+
disabled: disabled,
|
|
330
|
+
duplicates: duplicates,
|
|
331
|
+
choice: choice,
|
|
332
|
+
isOver: isOver,
|
|
333
|
+
dragItem: dragItem === null || dragItem === void 0 || (_dragItem$data = dragItem.data) === null || _dragItem$data === void 0 ? void 0 : _dragItem$data.current,
|
|
334
|
+
correct: correct,
|
|
335
|
+
onChange: onChange,
|
|
336
|
+
emptyResponseAreaWidth: emptyResponseAreaWidth,
|
|
337
|
+
emptyResponseAreaHeight: emptyResponseAreaHeight,
|
|
338
|
+
instanceId: instanceId
|
|
339
|
+
}));
|
|
340
|
+
}
|
|
341
|
+
DragDropBlank.defaultProps = {
|
|
342
|
+
emptyResponseAreaWidth: 0,
|
|
343
|
+
emptyResponseAreaHeight: 0
|
|
344
|
+
};
|
|
345
|
+
DragDropBlank.propTypes = {
|
|
346
|
+
id: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].number]),
|
|
347
|
+
disabled: _propTypes["default"].bool,
|
|
348
|
+
duplicates: _propTypes["default"].bool,
|
|
349
|
+
choice: _propTypes["default"].object,
|
|
350
|
+
correct: _propTypes["default"].bool,
|
|
351
|
+
onChange: _propTypes["default"].func,
|
|
352
|
+
emptyResponseAreaWidth: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].number]),
|
|
353
|
+
emptyResponseAreaHeight: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].number]),
|
|
354
|
+
instanceId: _propTypes["default"].string
|
|
355
|
+
};
|
|
356
|
+
var _default = exports["default"] = DragDropBlank;
|
|
263
357
|
//# sourceMappingURL=blank.js.map
|