@pie-lib/mask-markup 1.31.0 → 1.33.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.
- package/CHANGELOG.md +14 -2
- package/lib/choices/choice.js +74 -203
- package/lib/choices/choice.js.map +1 -1
- package/lib/choices/index.js +19 -52
- 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 +292 -357
- 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 +203 -248
- 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 +117 -96
- 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 +40 -112
- 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 +26 -55
- package/lib/with-mask.js.map +1 -1
- package/package.json +12 -10
- package/src/choices/choice.jsx +58 -154
- package/src/choices/index.jsx +8 -2
- package/src/components/blank.jsx +272 -262
- package/src/components/correct-input.jsx +33 -39
- package/src/components/dropdown.jsx +165 -156
- package/src/constructed-response.jsx +22 -18
- package/src/drag-in-the-blank.jsx +97 -39
- package/src/mask.jsx +18 -27
package/lib/with-mask.js
CHANGED
|
@@ -1,85 +1,60 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.withMask = exports.buildLayoutFromMarkup = void 0;
|
|
9
|
-
|
|
10
8
|
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
11
|
-
|
|
12
9
|
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
13
|
-
|
|
14
|
-
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
15
|
-
|
|
16
10
|
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
17
|
-
|
|
18
11
|
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
19
|
-
|
|
12
|
+
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
20
13
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
21
|
-
|
|
22
14
|
var _react = _interopRequireDefault(require("react"));
|
|
23
|
-
|
|
24
15
|
var _reactDom = _interopRequireDefault(require("react-dom"));
|
|
25
|
-
|
|
26
16
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
27
|
-
|
|
28
17
|
var _mask = _interopRequireDefault(require("./mask"));
|
|
29
|
-
|
|
30
18
|
var _componentize2 = _interopRequireDefault(require("./componentize"));
|
|
31
|
-
|
|
32
19
|
var _serialization = require("./serialization");
|
|
33
|
-
|
|
34
|
-
function
|
|
35
|
-
|
|
36
|
-
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; } }
|
|
37
|
-
|
|
38
|
-
var buildLayoutFromMarkup = function buildLayoutFromMarkup(markup, type) {
|
|
20
|
+
function _callSuper(t, o, e) { return o = (0, _getPrototypeOf2["default"])(o), (0, _possibleConstructorReturn2["default"])(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], (0, _getPrototypeOf2["default"])(t).constructor) : o.apply(t, e)); }
|
|
21
|
+
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
22
|
+
var buildLayoutFromMarkup = exports.buildLayoutFromMarkup = function buildLayoutFromMarkup(markup, type) {
|
|
39
23
|
var _componentize = (0, _componentize2["default"])(markup, type),
|
|
40
|
-
|
|
41
|
-
|
|
24
|
+
processed = _componentize.markup;
|
|
42
25
|
var value = (0, _serialization.deserialize)(processed);
|
|
43
26
|
return value.document;
|
|
44
27
|
};
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
var withMask = function withMask(type, renderChildren) {
|
|
49
|
-
var _class;
|
|
50
|
-
|
|
51
|
-
return _class = /*#__PURE__*/function (_React$Component) {
|
|
52
|
-
(0, _inherits2["default"])(WithMask, _React$Component);
|
|
53
|
-
|
|
54
|
-
var _super = _createSuper(WithMask);
|
|
55
|
-
|
|
28
|
+
var withMask = exports.withMask = function withMask(type, renderChildren) {
|
|
29
|
+
var _WithMask;
|
|
30
|
+
return _WithMask = /*#__PURE__*/function (_React$Component) {
|
|
56
31
|
function WithMask() {
|
|
57
32
|
(0, _classCallCheck2["default"])(this, WithMask);
|
|
58
|
-
return
|
|
33
|
+
return _callSuper(this, WithMask, arguments);
|
|
59
34
|
}
|
|
60
|
-
|
|
61
|
-
(0, _createClass2["default"])(WithMask, [{
|
|
35
|
+
(0, _inherits2["default"])(WithMask, _React$Component);
|
|
36
|
+
return (0, _createClass2["default"])(WithMask, [{
|
|
62
37
|
key: "componentDidUpdate",
|
|
63
38
|
value: function componentDidUpdate(prevProps) {
|
|
64
39
|
if (this.props.markup !== prevProps.markup) {
|
|
65
40
|
// eslint-disable-next-line
|
|
66
|
-
var domNode = _reactDom["default"].findDOMNode(this);
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
var mathElements = domNode && domNode.querySelectorAll('[data-latex][data-math-handled="true"]'); // Clean up for fresh MathJax processing
|
|
41
|
+
var domNode = _reactDom["default"].findDOMNode(this);
|
|
42
|
+
// Query all elements that may contain outdated MathJax renderings
|
|
43
|
+
var mathElements = domNode && domNode.querySelectorAll('[data-latex][data-math-handled="true"]');
|
|
70
44
|
|
|
45
|
+
// Clean up for fresh MathJax processing
|
|
71
46
|
(mathElements || []).forEach(function (el) {
|
|
72
47
|
// Remove the MathJax container to allow for clean updates
|
|
73
48
|
var mjxContainer = el.querySelector('mjx-container');
|
|
74
|
-
|
|
75
49
|
if (mjxContainer) {
|
|
76
50
|
el.removeChild(mjxContainer);
|
|
77
|
-
}
|
|
78
|
-
|
|
51
|
+
}
|
|
79
52
|
|
|
53
|
+
// Update the innerHTML to match the raw LaTeX data, ensuring it is reprocessed correctly
|
|
80
54
|
var latexCode = el.getAttribute('data-raw');
|
|
81
|
-
el.innerHTML = latexCode;
|
|
55
|
+
el.innerHTML = latexCode;
|
|
82
56
|
|
|
57
|
+
// Remove the attribute to signal that MathJax should reprocess this element
|
|
83
58
|
el.removeAttribute('data-math-handled');
|
|
84
59
|
});
|
|
85
60
|
}
|
|
@@ -88,11 +63,11 @@ var withMask = function withMask(type, renderChildren) {
|
|
|
88
63
|
key: "render",
|
|
89
64
|
value: function render() {
|
|
90
65
|
var _this$props = this.props,
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
66
|
+
markup = _this$props.markup,
|
|
67
|
+
layout = _this$props.layout,
|
|
68
|
+
value = _this$props.value,
|
|
69
|
+
onChange = _this$props.onChange,
|
|
70
|
+
elementType = _this$props.elementType;
|
|
96
71
|
var maskLayout = layout ? layout : buildLayoutFromMarkup(markup, type);
|
|
97
72
|
return /*#__PURE__*/_react["default"].createElement(_mask["default"], {
|
|
98
73
|
elementType: elementType,
|
|
@@ -103,13 +78,11 @@ var withMask = function withMask(type, renderChildren) {
|
|
|
103
78
|
});
|
|
104
79
|
}
|
|
105
80
|
}]);
|
|
106
|
-
|
|
107
|
-
}(_react["default"].Component), (0, _defineProperty2["default"])(_class, "propTypes", {
|
|
81
|
+
}(_react["default"].Component), (0, _defineProperty2["default"])(_WithMask, "propTypes", {
|
|
108
82
|
/**
|
|
109
83
|
* At the start we'll probably work with markup
|
|
110
84
|
*/
|
|
111
85
|
markup: _propTypes["default"].string,
|
|
112
|
-
|
|
113
86
|
/**
|
|
114
87
|
* Once we start authoring, it may make sense for use to us layout, which will be a simple js object that maps to `slate.Value`.
|
|
115
88
|
*/
|
|
@@ -118,8 +91,6 @@ var withMask = function withMask(type, renderChildren) {
|
|
|
118
91
|
onChange: _propTypes["default"].func,
|
|
119
92
|
customMarkMarkupComponent: _propTypes["default"].func,
|
|
120
93
|
elementType: _propTypes["default"].string
|
|
121
|
-
}),
|
|
94
|
+
}), _WithMask;
|
|
122
95
|
};
|
|
123
|
-
|
|
124
|
-
exports.withMask = withMask;
|
|
125
96
|
//# sourceMappingURL=with-mask.js.map
|
package/lib/with-mask.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"with-mask.js","names":["_react","_interopRequireDefault","require","_reactDom","_propTypes","_mask","_componentize2","_serialization","_callSuper","t","o","e","_getPrototypeOf2","_possibleConstructorReturn2","_isNativeReflectConstruct","Reflect","construct","constructor","apply","Boolean","prototype","valueOf","call","buildLayoutFromMarkup","exports","markup","type","_componentize","componentize","processed","value","deserialize","document","withMask","renderChildren","_WithMask","_React$Component","WithMask","_classCallCheck2","arguments","_inherits2","_createClass2","key","componentDidUpdate","prevProps","props","domNode","ReactDOM","findDOMNode","mathElements","querySelectorAll","forEach","el","mjxContainer","querySelector","removeChild","latexCode","getAttribute","innerHTML","removeAttribute","render","_this$props","layout","onChange","elementType","maskLayout","createElement","React","Component","_defineProperty2","PropTypes","string","object","func","customMarkMarkupComponent"],"sources":["../src/with-mask.jsx"],"sourcesContent":["import React from 'react';\nimport ReactDOM from 'react-dom';\nimport PropTypes from 'prop-types';\nimport Mask from './mask';\nimport componentize from './componentize';\nimport { deserialize } from './serialization';\n\nexport const buildLayoutFromMarkup = (markup, type) => {\n const { markup: processed } = componentize(markup, type);\n const value = deserialize(processed);\n return value.document;\n};\n\nexport const withMask = (type, renderChildren) => {\n return class WithMask extends React.Component {\n static propTypes = {\n /**\n * At the start we'll probably work with markup\n */\n markup: PropTypes.string,\n /**\n * Once we start authoring, it may make sense for use to us layout, which will be a simple js object that maps to `slate.Value`.\n */\n layout: PropTypes.object,\n value: PropTypes.object,\n onChange: PropTypes.func,\n customMarkMarkupComponent: PropTypes.func,\n elementType: PropTypes.string,\n };\n\n componentDidUpdate(prevProps) {\n if (this.props.markup !== prevProps.markup) {\n // eslint-disable-next-line\n const domNode = ReactDOM.findDOMNode(this);\n // Query all elements that may contain outdated MathJax renderings\n const mathElements = domNode && domNode.querySelectorAll('[data-latex][data-math-handled=\"true\"]');\n\n // Clean up for fresh MathJax processing\n (mathElements || []).forEach((el) => {\n // Remove the MathJax container to allow for clean updates\n const mjxContainer = el.querySelector('mjx-container');\n\n if (mjxContainer) {\n el.removeChild(mjxContainer);\n }\n\n // Update the innerHTML to match the raw LaTeX data, ensuring it is reprocessed correctly\n const latexCode = el.getAttribute('data-raw');\n el.innerHTML = latexCode;\n\n // Remove the attribute to signal that MathJax should reprocess this element\n el.removeAttribute('data-math-handled');\n });\n }\n }\n\n render() {\n const { markup, layout, value, onChange, elementType } = this.props;\n\n const maskLayout = layout ? layout : buildLayoutFromMarkup(markup, type);\n return (\n <Mask\n elementType={elementType}\n layout={maskLayout}\n value={value}\n onChange={onChange}\n renderChildren={renderChildren(this.props)}\n />\n );\n }\n };\n};\n"],"mappings":";;;;;;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,SAAA,GAAA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,oBACE1B,MAAA,YAAAkE,aAAA,CAAC7D,KAAA,WAAI;UACH2D,WAAW,EAAEA,WAAY;UACzBF,MAAM,EAAEG,UAAW;UACnBnC,KAAK,EAAEA,KAAM;UACbiC,QAAQ,EAAEA,QAAS;UACnB7B,cAAc,EAAEA,cAAc,CAAC,IAAI,CAACW,KAAK;QAAE,CAC5C,CAAC;MAEN;IAAC;EAAA,EAvD2BsB,iBAAK,CAACC,SAAS,OAAAC,gBAAA,aAAAlC,SAAA,eACxB;IACjB;AACN;AACA;IACMV,MAAM,EAAE6C,qBAAS,CAACC,MAAM;IACxB;AACN;AACA;IACMT,MAAM,EAAEQ,qBAAS,CAACE,MAAM;IACxB1C,KAAK,EAAEwC,qBAAS,CAACE,MAAM;IACvBT,QAAQ,EAAEO,qBAAS,CAACG,IAAI;IACxBC,yBAAyB,EAAEJ,qBAAS,CAACG,IAAI;IACzCT,WAAW,EAAEM,qBAAS,CAACC;EACzB,CAAC,GAAApC,SAAA;AA2CL,CAAC","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pie-lib/mask-markup",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.33.0-mui-update.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "src/index.js",
|
|
@@ -8,20 +8,22 @@
|
|
|
8
8
|
"access": "public"
|
|
9
9
|
},
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@
|
|
12
|
-
"@
|
|
13
|
-
"@
|
|
14
|
-
"@
|
|
15
|
-
"@pie-lib/
|
|
16
|
-
"@pie-lib/
|
|
11
|
+
"@emotion/react": "^11.14.0",
|
|
12
|
+
"@emotion/style": "^0.8.0",
|
|
13
|
+
"@mui/icons-material": "^7.3.4",
|
|
14
|
+
"@mui/material": "^7.3.4",
|
|
15
|
+
"@pie-lib/drag": "^2.22.0-mui-update.0",
|
|
16
|
+
"@pie-lib/editable-html": "^11.21.0-mui-update.0",
|
|
17
|
+
"@pie-lib/math-rendering": "^3.26.0-mui-update.0",
|
|
18
|
+
"@pie-lib/render-ui": "^4.35.0-mui-update.0",
|
|
17
19
|
"classnames": "^2.2.6",
|
|
18
20
|
"debug": "^4.1.1",
|
|
19
21
|
"immutable": "^4.0.0-rc.12",
|
|
20
22
|
"lodash": "^4.17.11",
|
|
21
23
|
"prop-types": "^15.7.2",
|
|
22
|
-
"react": "^
|
|
24
|
+
"react": "^18.2.0",
|
|
23
25
|
"react-dnd-html5-backend": "^14.0.2",
|
|
24
|
-
"react-dom": "^
|
|
26
|
+
"react-dom": "^18.2.0",
|
|
25
27
|
"slate": "^0.36.2",
|
|
26
28
|
"slate-html-serializer": "^0.6.12",
|
|
27
29
|
"slate-prop-types": "^0.4.38",
|
|
@@ -31,5 +33,5 @@
|
|
|
31
33
|
"keywords": [],
|
|
32
34
|
"author": "",
|
|
33
35
|
"license": "ISC",
|
|
34
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "622d5627dc85e393cdf13e3362970299cc485cc5"
|
|
35
37
|
}
|
package/src/choices/choice.jsx
CHANGED
|
@@ -1,164 +1,68 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
1
|
+
// choices/Choice.js
|
|
2
|
+
import React, { useEffect, useRef } from 'react';
|
|
3
3
|
import PropTypes from 'prop-types';
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
4
|
+
import { useDraggable } from '@dnd-kit/core';
|
|
5
|
+
import { styled } from '@mui/material/styles';
|
|
6
|
+
import Chip from '@mui/material/Chip';
|
|
6
7
|
import classnames from 'classnames';
|
|
7
|
-
|
|
8
8
|
import { renderMath } from '@pie-lib/math-rendering';
|
|
9
9
|
import { color } from '@pie-lib/render-ui';
|
|
10
|
-
import { DragSource } from '@pie-lib/drag';
|
|
11
10
|
|
|
12
11
|
export const DRAG_TYPE = 'MaskBlank';
|
|
13
12
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
render() {
|
|
66
|
-
const { connectDragSource, choice, classes, disabled } = this.props;
|
|
67
|
-
|
|
68
|
-
// 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.
|
|
69
|
-
|
|
70
|
-
return connectDragSource(
|
|
71
|
-
<span
|
|
72
|
-
className={classnames(classes.choice, disabled && classes.disabled)}
|
|
73
|
-
ref={(ref) => {
|
|
74
|
-
//eslint-disable-next-line
|
|
75
|
-
this.dragContainerRef = ReactDOM.findDOMNode(ref);
|
|
76
|
-
}}
|
|
77
|
-
>
|
|
78
|
-
<Chip
|
|
79
|
-
clickable={false}
|
|
80
|
-
disabled={true}
|
|
81
|
-
ref={(ref) => {
|
|
82
|
-
//eslint-disable-next-line
|
|
83
|
-
this.rootRef = ReactDOM.findDOMNode(ref);
|
|
84
|
-
}}
|
|
85
|
-
className={classes.chip}
|
|
86
|
-
label={
|
|
87
|
-
<span
|
|
88
|
-
className={classes.chipLabel}
|
|
89
|
-
ref={(ref) => {
|
|
90
|
-
if (ref) {
|
|
91
|
-
ref.innerHTML = choice.value || ' ';
|
|
92
|
-
}
|
|
93
|
-
}}
|
|
94
|
-
>
|
|
95
|
-
{' '}
|
|
96
|
-
</span>
|
|
97
|
-
}
|
|
98
|
-
variant={disabled ? 'outlined' : undefined}
|
|
99
|
-
/>
|
|
100
|
-
</span>,
|
|
101
|
-
{},
|
|
102
|
-
);
|
|
103
|
-
}
|
|
13
|
+
const StyledChoice = styled('span')(({ theme }) => ({
|
|
14
|
+
border: `solid 0px ${theme.palette.primary.main}`,
|
|
15
|
+
borderRadius: theme.spacing(2),
|
|
16
|
+
margin: theme.spacing(0.5),
|
|
17
|
+
transform: 'translate(0, 0)',
|
|
18
|
+
display: 'inline-flex',
|
|
19
|
+
'&.disabled': { opacity: 0.6 },
|
|
20
|
+
}));
|
|
21
|
+
|
|
22
|
+
const StyledChip = styled(Chip)(() => ({
|
|
23
|
+
backgroundColor: color.white(),
|
|
24
|
+
border: `1px solid ${color.text()}`,
|
|
25
|
+
color: color.text(),
|
|
26
|
+
alignItems: 'center',
|
|
27
|
+
display: 'inline-flex',
|
|
28
|
+
height: 'initial',
|
|
29
|
+
minHeight: '32px',
|
|
30
|
+
fontSize: 'inherit',
|
|
31
|
+
whiteSpace: 'pre-wrap',
|
|
32
|
+
maxWidth: '374px',
|
|
33
|
+
pointerEvents: 'none',
|
|
34
|
+
borderRadius: '3px',
|
|
35
|
+
paddingTop: '12px',
|
|
36
|
+
paddingBottom: '12px',
|
|
37
|
+
}));
|
|
38
|
+
|
|
39
|
+
export default function Choice({ choice, disabled, instanceId }) {
|
|
40
|
+
const rootRef = useRef(null);
|
|
41
|
+
|
|
42
|
+
const { attributes, listeners, setNodeRef } = useDraggable({
|
|
43
|
+
id: `choice-${choice.id}`,
|
|
44
|
+
data: { choice, instanceId, fromChoice: true, type: DRAG_TYPE },
|
|
45
|
+
disabled,
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
if (rootRef.current) renderMath(rootRef.current);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
return (
|
|
53
|
+
<StyledChoice ref={setNodeRef} className={classnames({ disabled })} {...listeners} {...attributes}>
|
|
54
|
+
<StyledChip
|
|
55
|
+
clickable={false}
|
|
56
|
+
disabled
|
|
57
|
+
ref={rootRef}
|
|
58
|
+
label={choice.value}
|
|
59
|
+
/>
|
|
60
|
+
</StyledChoice>
|
|
61
|
+
);
|
|
104
62
|
}
|
|
105
63
|
|
|
106
|
-
|
|
107
|
-
choice:
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
margin: theme.spacing.unit / 2,
|
|
111
|
-
transform: 'translate(0, 0)',
|
|
112
|
-
},
|
|
113
|
-
chip: {
|
|
114
|
-
backgroundColor: color.white(),
|
|
115
|
-
border: `1px solid ${color.text()}`,
|
|
116
|
-
color: color.text(),
|
|
117
|
-
alignItems: 'center',
|
|
118
|
-
display: 'inline-flex',
|
|
119
|
-
height: 'initial',
|
|
120
|
-
minHeight: '32px',
|
|
121
|
-
fontSize: 'inherit',
|
|
122
|
-
whiteSpace: 'pre-wrap',
|
|
123
|
-
maxWidth: '374px',
|
|
124
|
-
// Added for touch devices, for image content.
|
|
125
|
-
// This will prevent the context menu from appearing and not allowing other interactions with the image.
|
|
126
|
-
// If interactions with the image in the token will be requested we should handle only the context Menu.
|
|
127
|
-
pointerEvents: 'none',
|
|
128
|
-
borderRadius: '3px',
|
|
129
|
-
paddingTop: '12px',
|
|
130
|
-
paddingBottom: '12px',
|
|
131
|
-
},
|
|
132
|
-
chipLabel: {
|
|
133
|
-
whiteSpace: 'normal',
|
|
134
|
-
'& img': {
|
|
135
|
-
display: 'block',
|
|
136
|
-
padding: '2px 0',
|
|
137
|
-
},
|
|
138
|
-
'& mjx-frac': {
|
|
139
|
-
fontSize: '120% !important',
|
|
140
|
-
},
|
|
141
|
-
},
|
|
142
|
-
disabled: {
|
|
143
|
-
opacity: 0.6,
|
|
144
|
-
},
|
|
145
|
-
}))(BlankContentComp);
|
|
146
|
-
|
|
147
|
-
const tileSource = {
|
|
148
|
-
canDrag(props) {
|
|
149
|
-
return !props.disabled;
|
|
150
|
-
},
|
|
151
|
-
beginDrag(props) {
|
|
152
|
-
return {
|
|
153
|
-
choice: props.choice,
|
|
154
|
-
instanceId: props.instanceId,
|
|
155
|
-
};
|
|
156
|
-
},
|
|
64
|
+
Choice.propTypes = {
|
|
65
|
+
choice: PropTypes.object.isRequired,
|
|
66
|
+
disabled: PropTypes.bool,
|
|
67
|
+
instanceId: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
157
68
|
};
|
|
158
|
-
|
|
159
|
-
const DragDropTile = DragSource(DRAG_TYPE, tileSource, (connect, monitor) => ({
|
|
160
|
-
connectDragSource: connect.dragSource(),
|
|
161
|
-
isDragging: monitor.isDragging(),
|
|
162
|
-
}))(BlankContent);
|
|
163
|
-
|
|
164
|
-
export default DragDropTile;
|
package/src/choices/index.jsx
CHANGED
|
@@ -11,6 +11,7 @@ export default class Choices extends React.Component {
|
|
|
11
11
|
choices: PropTypes.arrayOf(PropTypes.shape({ label: PropTypes.string, value: PropTypes.string })),
|
|
12
12
|
value: PropTypes.object,
|
|
13
13
|
choicePosition: PropTypes.string.isRequired,
|
|
14
|
+
instanceId: PropTypes.string, // Added for drag isolation
|
|
14
15
|
};
|
|
15
16
|
|
|
16
17
|
getStyleForWrapper = () => {
|
|
@@ -40,7 +41,7 @@ export default class Choices extends React.Component {
|
|
|
40
41
|
};
|
|
41
42
|
|
|
42
43
|
render() {
|
|
43
|
-
const { disabled, duplicates, choices, value } = this.props;
|
|
44
|
+
const { disabled, duplicates, choices, value, instanceId } = this.props;
|
|
44
45
|
const filteredChoices = choices.filter((c) => {
|
|
45
46
|
if (duplicates === true) {
|
|
46
47
|
return true;
|
|
@@ -54,7 +55,12 @@ export default class Choices extends React.Component {
|
|
|
54
55
|
<div style={elementStyle}>
|
|
55
56
|
<DragDroppablePlaceholder disabled={disabled}>
|
|
56
57
|
{filteredChoices.map((c, index) => (
|
|
57
|
-
<Choice
|
|
58
|
+
<Choice
|
|
59
|
+
key={`${c.value}-${index}`}
|
|
60
|
+
disabled={disabled}
|
|
61
|
+
choice={c}
|
|
62
|
+
instanceId={instanceId}
|
|
63
|
+
/>
|
|
58
64
|
))}
|
|
59
65
|
</DragDroppablePlaceholder>
|
|
60
66
|
</div>
|