@pie-lib/mask-markup 1.33.3-next.0 → 1.33.3-next.155
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 +6 -76
- package/esm/package.json +3 -0
- package/lib/choices/choice.js +98 -203
- package/lib/choices/choice.js.map +1 -1
- package/lib/choices/index.js +21 -53
- package/lib/choices/index.js.map +1 -1
- package/lib/componentize.js +1 -5
- package/lib/componentize.js.map +1 -1
- package/lib/components/blank.js +303 -361
- package/lib/components/blank.js.map +1 -1
- package/lib/components/correct-input.js +41 -65
- package/lib/components/correct-input.js.map +1 -1
- package/lib/components/dropdown.js +218 -257
- package/lib/components/dropdown.js.map +1 -1
- package/lib/components/input.js +10 -17
- package/lib/components/input.js.map +1 -1
- package/lib/constructed-response.js +38 -52
- package/lib/constructed-response.js.map +1 -1
- package/lib/customizable.js +5 -9
- package/lib/customizable.js.map +1 -1
- package/lib/drag-in-the-blank.js +140 -105
- package/lib/drag-in-the-blank.js.map +1 -1
- package/lib/index.js +0 -7
- package/lib/index.js.map +1 -1
- package/lib/inline-dropdown.js +4 -12
- package/lib/inline-dropdown.js.map +1 -1
- package/lib/mask.js +60 -118
- package/lib/mask.js.map +1 -1
- package/lib/serialization.js +8 -48
- package/lib/serialization.js.map +1 -1
- package/lib/with-mask.js +30 -58
- package/lib/with-mask.js.map +1 -1
- package/package.json +20 -12
- package/src/__tests__/drag-in-the-blank.test.js +66 -26
- package/src/__tests__/mask.test.js +147 -112
- package/src/__tests__/with-mask.test.js +44 -19
- package/src/choices/__tests__/index.test.js +38 -25
- package/src/choices/choice.jsx +86 -153
- package/src/choices/index.jsx +9 -3
- package/src/components/__tests__/blank.test.js +92 -156
- package/src/components/__tests__/correct-input.test.js +60 -19
- package/src/components/__tests__/dropdown.test.js +61 -19
- package/src/components/__tests__/input.test.js +72 -20
- package/src/components/blank.jsx +273 -272
- package/src/components/correct-input.jsx +33 -39
- package/src/components/dropdown.jsx +173 -161
- package/src/constructed-response.jsx +22 -18
- package/src/drag-in-the-blank.jsx +131 -42
- package/src/mask.jsx +38 -29
- package/src/with-mask.jsx +7 -4
- package/src/__tests__/__snapshots__/drag-in-the-blank.test.js.snap +0 -316
- package/src/__tests__/__snapshots__/mask.test.js.snap +0 -55
- package/src/__tests__/__snapshots__/with-mask.test.js.snap +0 -62
- package/src/choices/__tests__/__snapshots__/index.test.js.snap +0 -209
- package/src/components/__tests__/__snapshots__/blank.test.js.snap +0 -111
- package/src/components/__tests__/__snapshots__/correct-input.test.js.snap +0 -64
- package/src/components/__tests__/__snapshots__/dropdown.test.js.snap +0 -136
- package/src/components/__tests__/__snapshots__/input.test.js.snap +0 -34
package/lib/components/blank.js
CHANGED
|
@@ -1,331 +1,254 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
4
|
+
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
-
exports["default"] =
|
|
9
|
-
|
|
10
|
-
var
|
|
11
|
-
|
|
12
|
-
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
13
|
-
|
|
14
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
15
|
-
|
|
16
|
-
var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
|
|
17
|
-
|
|
18
|
-
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
19
|
-
|
|
20
|
-
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
21
|
-
|
|
22
|
-
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
23
|
-
|
|
8
|
+
exports["default"] = void 0;
|
|
9
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
10
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
24
11
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
25
|
-
|
|
26
|
-
var _grey = _interopRequireDefault(require("@material-ui/core/colors/grey"));
|
|
27
|
-
|
|
28
|
-
var _react = _interopRequireDefault(require("react"));
|
|
29
|
-
|
|
30
|
-
var _reactDom = _interopRequireDefault(require("react-dom"));
|
|
31
|
-
|
|
12
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
32
13
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
33
|
-
|
|
34
14
|
var _mathRendering = require("@pie-lib/math-rendering");
|
|
35
|
-
|
|
36
15
|
var _debug = _interopRequireDefault(require("debug"));
|
|
37
|
-
|
|
38
|
-
var
|
|
39
|
-
|
|
40
|
-
var
|
|
41
|
-
|
|
42
|
-
var _Chip = _interopRequireDefault(require("@material-ui/core/Chip"));
|
|
43
|
-
|
|
44
|
-
var _classnames3 = _interopRequireDefault(require("classnames"));
|
|
45
|
-
|
|
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"));
|
|
46
21
|
var _renderUi = require("@pie-lib/render-ui");
|
|
47
|
-
|
|
48
|
-
var
|
|
49
|
-
|
|
50
|
-
function
|
|
51
|
-
|
|
52
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
53
|
-
|
|
54
|
-
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); }; }
|
|
55
|
-
|
|
56
|
-
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; } }
|
|
57
|
-
|
|
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; }
|
|
58
26
|
var log = (0, _debug["default"])('pie-lib:mask-markup:blank');
|
|
59
|
-
var
|
|
60
|
-
|
|
61
|
-
|
|
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 () {
|
|
62
45
|
return {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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',
|
|
55
|
+
overflow: 'hidden'
|
|
70
56
|
},
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
color: _renderUi.color.text(),
|
|
75
|
-
fontSize: 'inherit',
|
|
76
|
-
maxWidth: '374px',
|
|
77
|
-
position: 'relative',
|
|
78
|
-
borderRadius: '3px'
|
|
57
|
+
'&.parentOver': {
|
|
58
|
+
border: "1px solid ".concat(_colors.grey[500]),
|
|
59
|
+
backgroundColor: "".concat(_colors.grey[300])
|
|
79
60
|
},
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
// Added for touch devices, for image content.
|
|
83
|
-
// This will prevent the context menu from appearing and not allowing other interactions with the image.
|
|
84
|
-
// If interactions with the image in the token will be requested we should handle only the context Menu.
|
|
85
|
-
pointerEvents: 'none',
|
|
86
|
-
'& img': {
|
|
87
|
-
display: 'block',
|
|
88
|
-
padding: '2px 0'
|
|
89
|
-
},
|
|
90
|
-
// Remove default <p> margins to ensure consistent spacing across all wrapped content (p, span, div, math)
|
|
91
|
-
// Padding for top and bottom will instead be controlled by the container for consistent layout
|
|
92
|
-
// Ensures consistent behavior with pie-api-browser, where marginTop is already removed by a Bootstrap stylesheet
|
|
93
|
-
'& p': {
|
|
94
|
-
marginTop: '0',
|
|
95
|
-
marginBottom: '0'
|
|
96
|
-
},
|
|
97
|
-
'& mjx-frac': {
|
|
98
|
-
fontSize: '120% !important'
|
|
99
|
-
}
|
|
61
|
+
'&.correct': {
|
|
62
|
+
border: "solid 1px ".concat(_renderUi.color.correct())
|
|
100
63
|
},
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
opacity: 0
|
|
64
|
+
'&.incorrect': {
|
|
65
|
+
border: "solid 1px ".concat(_renderUi.color.incorrect())
|
|
104
66
|
},
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
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'
|
|
109
82
|
},
|
|
110
|
-
|
|
111
|
-
|
|
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'
|
|
112
89
|
},
|
|
113
|
-
|
|
114
|
-
|
|
90
|
+
'& mjx-frac': {
|
|
91
|
+
fontSize: '120% !important'
|
|
115
92
|
},
|
|
116
|
-
over: {
|
|
93
|
+
'&.over': {
|
|
117
94
|
whiteSpace: 'nowrap',
|
|
118
95
|
overflow: 'hidden'
|
|
119
96
|
},
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
97
|
+
'&.hidden': {
|
|
98
|
+
color: 'transparent',
|
|
99
|
+
opacity: 0
|
|
100
|
+
},
|
|
101
|
+
'&.dragged': {
|
|
102
|
+
position: 'absolute',
|
|
103
|
+
left: 16,
|
|
104
|
+
maxWidth: '60px'
|
|
123
105
|
}
|
|
124
106
|
};
|
|
125
107
|
});
|
|
126
|
-
|
|
127
|
-
var
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "handleTouchStart", function (e) {
|
|
141
|
-
e.preventDefault();
|
|
142
|
-
_this.touchStartTimer = setTimeout(function () {
|
|
143
|
-
_this.startDrag();
|
|
144
|
-
}, 300); // Start drag after 300ms (touch and hold duration)
|
|
145
|
-
});
|
|
146
|
-
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "startDrag", function () {
|
|
147
|
-
var _this$props = _this.props,
|
|
148
|
-
connectDragSource = _this$props.connectDragSource,
|
|
149
|
-
disabled = _this$props.disabled;
|
|
150
|
-
|
|
151
|
-
if (!disabled) {
|
|
152
|
-
connectDragSource(_this.rootRef);
|
|
153
|
-
}
|
|
154
|
-
});
|
|
155
|
-
_this.state = {
|
|
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)({
|
|
156
122
|
height: 0,
|
|
157
123
|
width: 0
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
(
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
_this2.updateDimensions();
|
|
175
|
-
}, 300);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
}, {
|
|
179
|
-
key: "componentDidMount",
|
|
180
|
-
value: function componentDidMount() {
|
|
181
|
-
this.handleElements();
|
|
182
|
-
|
|
183
|
-
if (this.rootRef) {
|
|
184
|
-
this.rootRef.addEventListener('touchstart', this.handleTouchStart, {
|
|
185
|
-
passive: false
|
|
186
|
-
});
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
}, {
|
|
190
|
-
key: "componentDidUpdate",
|
|
191
|
-
value: function componentDidUpdate(prevProps) {
|
|
192
|
-
(0, _mathRendering.renderMath)(this.rootRef);
|
|
193
|
-
var currentChoice = this.props.choice;
|
|
194
|
-
var prevChoice = prevProps.choice;
|
|
195
|
-
|
|
196
|
-
if (JSON.stringify(currentChoice) !== JSON.stringify(prevChoice)) {
|
|
197
|
-
if (!currentChoice) {
|
|
198
|
-
this.setState({
|
|
199
|
-
height: 0,
|
|
200
|
-
width: 0
|
|
201
|
-
});
|
|
202
|
-
return;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
this.handleElements();
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
}, {
|
|
209
|
-
key: "componentWillUnmount",
|
|
210
|
-
value: function componentWillUnmount() {
|
|
211
|
-
if (this.rootRef) {
|
|
212
|
-
this.rootRef.removeEventListener('touchstart', this.handleTouchStart);
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
}, {
|
|
216
|
-
key: "updateDimensions",
|
|
217
|
-
value: function updateDimensions() {
|
|
218
|
-
if (this.spanRef && this.rootRef) {
|
|
219
|
-
// Temporarily set rootRef width to 'auto' for natural measurement
|
|
220
|
-
this.rootRef.style.width = 'auto'; // Get the natural dimensions of the content
|
|
221
|
-
|
|
222
|
-
var width = this.spanRef.offsetWidth || 0;
|
|
223
|
-
var height = this.spanRef.offsetHeight || 0;
|
|
224
|
-
var widthWithPadding = width + 24; // 12px padding on each side
|
|
225
|
-
|
|
226
|
-
var heightWithPadding = height + 24; // 12px padding on top and bottom
|
|
227
|
-
|
|
228
|
-
var responseAreaWidth = parseFloat(this.props.emptyResponseAreaWidth) || 0;
|
|
229
|
-
var responseAreaHeight = parseFloat(this.props.emptyResponseAreaHeight) || 0;
|
|
230
|
-
var adjustedWidth = widthWithPadding <= responseAreaWidth ? responseAreaWidth : widthWithPadding;
|
|
231
|
-
var adjustedHeight = heightWithPadding <= responseAreaHeight ? responseAreaHeight : heightWithPadding;
|
|
232
|
-
this.setState(function (prevState) {
|
|
233
|
-
return {
|
|
234
|
-
width: adjustedWidth > responseAreaWidth ? adjustedWidth : prevState.width,
|
|
235
|
-
height: adjustedHeight > responseAreaHeight ? adjustedHeight : prevState.height
|
|
236
|
-
};
|
|
237
|
-
});
|
|
238
|
-
this.rootRef.style.width = "".concat(adjustedWidth, "px");
|
|
239
|
-
this.rootRef.style.height = "".concat(adjustedHeight, "px");
|
|
240
|
-
}
|
|
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);
|
|
241
140
|
}
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
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
|
+
};
|
|
249
162
|
});
|
|
163
|
+
rootRef.current.style.width = "".concat(adjustedWidth, "px");
|
|
164
|
+
rootRef.current.style.height = "".concat(adjustedHeight, "px");
|
|
250
165
|
}
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
}; // add minWidth, minHeight if width and height are not defined
|
|
261
|
-
// minWidth, minHeight will be also in model in the future
|
|
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
|
|
174
|
+
};
|
|
262
175
|
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
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);
|
|
191
|
+
}
|
|
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
|
|
267
198
|
});
|
|
199
|
+
return;
|
|
268
200
|
}
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
choice = _this$props2.choice,
|
|
278
|
-
classes = _this$props2.classes,
|
|
279
|
-
isOver = _this$props2.isOver,
|
|
280
|
-
dragItem = _this$props2.dragItem,
|
|
281
|
-
correct = _this$props2.correct;
|
|
282
|
-
var draggedLabel = dragItem && isOver && dragItem.choice.value;
|
|
283
|
-
var label = choice && choice.value;
|
|
284
|
-
return (
|
|
285
|
-
/*#__PURE__*/
|
|
286
|
-
// 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.
|
|
287
|
-
_react["default"].createElement(_Chip["default"], {
|
|
288
|
-
clickable: false,
|
|
289
|
-
disabled: true,
|
|
290
|
-
ref: function ref(_ref3) {
|
|
291
|
-
//eslint-disable-next-line
|
|
292
|
-
_this3.rootRef = _reactDom["default"].findDOMNode(_ref3);
|
|
293
|
-
},
|
|
294
|
-
component: "span",
|
|
295
|
-
label: /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement("span", {
|
|
296
|
-
className: (0, _classnames3["default"])(classes.chipLabel, isOver && classes.over, (0, _defineProperty2["default"])({}, classes.hidden, draggedLabel)),
|
|
297
|
-
ref: function ref(_ref) {
|
|
298
|
-
if (_ref) {
|
|
299
|
-
//eslint-disable-next-line
|
|
300
|
-
_this3.spanRef = _reactDom["default"].findDOMNode(_ref);
|
|
301
|
-
_ref.innerHTML = label || '';
|
|
302
|
-
|
|
303
|
-
_this3.addDraggableFalseAttributes(_ref);
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
}, ' '), draggedLabel && /*#__PURE__*/_react["default"].createElement("span", {
|
|
307
|
-
className: (0, _classnames3["default"])(classes.chipLabel, isOver && classes.over, classes.dragged),
|
|
308
|
-
ref: function ref(_ref2) {
|
|
309
|
-
if (_ref2) {
|
|
310
|
-
//eslint-disable-next-line
|
|
311
|
-
_this3.spanRef = _reactDom["default"].findDOMNode(_ref2);
|
|
312
|
-
_ref2.innerHTML = draggedLabel || '';
|
|
313
|
-
|
|
314
|
-
_this3.addDraggableFalseAttributes(_ref2);
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
}, ' ')),
|
|
318
|
-
className: (0, _classnames3["default"])(classes.chip, isOver && classes.over, isOver && classes.parentOver, (_classnames2 = {}, (0, _defineProperty2["default"])(_classnames2, classes.correct, correct !== undefined && correct), (0, _defineProperty2["default"])(_classnames2, classes.incorrect, correct !== undefined && !correct), _classnames2)),
|
|
319
|
-
variant: disabled ? 'outlined' : undefined,
|
|
320
|
-
style: _objectSpread({}, this.getRootDimensions())
|
|
321
|
-
})
|
|
322
|
-
);
|
|
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
|
+
};
|
|
323
209
|
}
|
|
324
|
-
}]);
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
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
|
+
}
|
|
329
252
|
BlankContent.defaultProps = {
|
|
330
253
|
emptyResponseAreaWidth: 0,
|
|
331
254
|
emptyResponseAreaHeight: 0
|
|
@@ -335,81 +258,100 @@ BlankContent.propTypes = {
|
|
|
335
258
|
disabled: _propTypes["default"].bool,
|
|
336
259
|
duplicates: _propTypes["default"].bool,
|
|
337
260
|
choice: _propTypes["default"].object,
|
|
338
|
-
classes: _propTypes["default"].object,
|
|
339
261
|
isOver: _propTypes["default"].bool,
|
|
340
262
|
dragItem: _propTypes["default"].object,
|
|
341
263
|
correct: _propTypes["default"].bool,
|
|
342
264
|
onChange: _propTypes["default"].func,
|
|
343
265
|
emptyResponseAreaWidth: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].number]),
|
|
344
|
-
emptyResponseAreaHeight: _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
|
|
345
268
|
};
|
|
346
|
-
var StyledBlankContent = useStyles(BlankContent);
|
|
347
|
-
var connectedBlankContent = useStyles(function (_ref4) {
|
|
348
|
-
var connectDragSource = _ref4.connectDragSource,
|
|
349
|
-
connectDropTarget = _ref4.connectDropTarget,
|
|
350
|
-
props = (0, _objectWithoutProperties2["default"])(_ref4, _excluded);
|
|
351
|
-
var classes = props.classes,
|
|
352
|
-
isOver = props.isOver;
|
|
353
|
-
return connectDropTarget(connectDragSource( /*#__PURE__*/_react["default"].createElement("span", {
|
|
354
|
-
className: (0, _classnames3["default"])(classes.content, isOver && classes.over)
|
|
355
|
-
}, /*#__PURE__*/_react["default"].createElement(StyledBlankContent, props))));
|
|
356
|
-
});
|
|
357
|
-
var tileTarget = {
|
|
358
|
-
drop: function drop(props, monitor) {
|
|
359
|
-
var draggedItem = monitor.getItem();
|
|
360
|
-
log('props.instanceId', props.instanceId, 'draggedItem.instanceId:', draggedItem.instanceId);
|
|
361
269
|
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
var
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
},
|
|
386
|
-
beginDrag: function beginDrag(props) {
|
|
387
|
-
return {
|
|
388
|
-
id: props.id,
|
|
389
|
-
choice: props.choice,
|
|
390
|
-
instanceId: props.instanceId,
|
|
391
|
-
fromChoice: true
|
|
392
|
-
};
|
|
393
|
-
},
|
|
394
|
-
endDrag: function endDrag(props, monitor) {
|
|
395
|
-
// this will be null if it did not drop
|
|
396
|
-
var dropResult = monitor.getDropResult();
|
|
397
|
-
|
|
398
|
-
if (!dropResult || dropResult.dropped) {
|
|
399
|
-
var draggedItem = monitor.getItem();
|
|
400
|
-
|
|
401
|
-
if (draggedItem.fromChoice) {
|
|
402
|
-
props.onChange(props.id, undefined);
|
|
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'
|
|
403
293
|
}
|
|
404
|
-
}
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
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);
|
|
411
318
|
};
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
319
|
+
var style = {
|
|
320
|
+
transform: _utilities.CSS.Translate.toString(transform)
|
|
321
|
+
};
|
|
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;
|
|
415
357
|
//# sourceMappingURL=blank.js.map
|