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