@pie-element/inline-dropdown 8.3.4-next.3 → 9.0.0-beta.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/configure/lib/defaults.js +2 -3
- package/configure/lib/defaults.js.map +1 -1
- package/configure/lib/index.js +111 -185
- package/configure/lib/index.js.map +1 -1
- package/configure/lib/inline-dropdown-toolbar.js +364 -482
- package/configure/lib/inline-dropdown-toolbar.js.map +1 -1
- package/configure/lib/main.js +457 -597
- package/configure/lib/main.js.map +1 -1
- package/configure/lib/markupUtils.js +20 -39
- package/configure/lib/markupUtils.js.map +1 -1
- package/configure/lib/response-area.js +33 -84
- package/configure/lib/response-area.js.map +1 -1
- package/configure/lib/utils.js +11 -22
- package/configure/lib/utils.js.map +1 -1
- package/configure/package.json +11 -9
- package/controller/lib/defaults.js +2 -3
- package/controller/lib/defaults.js.map +1 -1
- package/controller/lib/index.js +156 -290
- package/controller/lib/index.js.map +1 -1
- package/controller/lib/utils.js +8 -15
- package/controller/lib/utils.js.map +1 -1
- package/controller/package.json +2 -2
- package/lib/index.js +65 -110
- package/lib/index.js.map +1 -1
- package/lib/inline-dropdown.js +148 -220
- package/lib/inline-dropdown.js.map +1 -1
- package/package.json +12 -10
- package/esm/configure.js +0 -24594
- package/esm/configure.js.map +0 -1
- package/esm/controller.js +0 -3944
- package/esm/controller.js.map +0 -1
- package/esm/element.js +0 -9587
- package/esm/element.js.map +0 -1
- package/esm/package.json +0 -3
|
@@ -1,573 +1,455 @@
|
|
|
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
|
-
exports
|
|
9
|
-
|
|
10
|
-
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
11
|
-
|
|
12
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
13
|
-
|
|
14
|
-
var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
|
|
15
|
-
|
|
16
|
-
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
17
|
-
|
|
18
|
-
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
19
|
-
|
|
20
|
-
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
21
|
-
|
|
7
|
+
exports.default = void 0;
|
|
22
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
23
|
-
|
|
24
9
|
var _utils = require("./utils");
|
|
25
|
-
|
|
26
10
|
var _react = _interopRequireDefault(require("react"));
|
|
27
|
-
|
|
28
11
|
var _reactDom = _interopRequireDefault(require("react-dom"));
|
|
29
|
-
|
|
30
12
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
31
|
-
|
|
32
13
|
var _editableHtml = _interopRequireDefault(require("@pie-lib/editable-html"));
|
|
33
|
-
|
|
34
14
|
var _mathRendering = require("@pie-lib/math-rendering");
|
|
35
|
-
|
|
36
|
-
var _styles = require("@material-ui/core/styles");
|
|
37
|
-
|
|
15
|
+
var _styles = require("@mui/material/styles");
|
|
38
16
|
var _isEqual = _interopRequireDefault(require("lodash/isEqual"));
|
|
39
|
-
|
|
40
17
|
var _isEmpty = _interopRequireDefault(require("lodash/isEmpty"));
|
|
41
|
-
|
|
42
|
-
var _classnames2 = _interopRequireDefault(require("classnames"));
|
|
43
|
-
|
|
44
18
|
var _renderUi = require("@pie-lib/render-ui");
|
|
45
|
-
|
|
46
|
-
var
|
|
47
|
-
|
|
48
|
-
var
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
19
|
+
var _Add = _interopRequireDefault(require("@mui/icons-material/Add"));
|
|
20
|
+
var _Check = _interopRequireDefault(require("@mui/icons-material/Check"));
|
|
21
|
+
var _Close = _interopRequireDefault(require("@mui/icons-material/Close"));
|
|
22
|
+
var _Edit = _interopRequireDefault(require("@mui/icons-material/Edit"));
|
|
23
|
+
var _IconButton = _interopRequireDefault(require("@mui/material/IconButton"));
|
|
24
|
+
const MenuItemWrapper = (0, _styles.styled)('div')(({
|
|
25
|
+
theme
|
|
26
|
+
}) => ({
|
|
27
|
+
display: 'flex',
|
|
28
|
+
alignItems: 'flex-start',
|
|
29
|
+
position: 'relative',
|
|
30
|
+
background: theme.palette.common.white,
|
|
31
|
+
borderBottom: `1px solid ${theme.palette.grey[400]}`,
|
|
32
|
+
'&:last-child': {
|
|
33
|
+
borderRadius: '0 0 4px 4px'
|
|
34
|
+
}
|
|
35
|
+
}));
|
|
36
|
+
const SelectedIcon = (0, _styles.styled)('div')(({
|
|
37
|
+
theme
|
|
38
|
+
}) => ({
|
|
39
|
+
display: 'flex',
|
|
40
|
+
justifyContent: 'center',
|
|
41
|
+
color: theme.palette.common.white,
|
|
42
|
+
fontSize: theme.typography.fontSize,
|
|
43
|
+
fontStyle: 'normal',
|
|
44
|
+
position: 'absolute',
|
|
45
|
+
transform: 'translate(0, -50%)',
|
|
46
|
+
backgroundColor: _renderUi.color.correct(),
|
|
47
|
+
borderRadius: '50%',
|
|
48
|
+
top: theme.spacing(2),
|
|
49
|
+
left: theme.spacing(1),
|
|
50
|
+
zIndex: 3
|
|
51
|
+
}));
|
|
52
|
+
const ValueHolder = (0, _styles.styled)('div')(({
|
|
53
|
+
theme,
|
|
54
|
+
correct
|
|
55
|
+
}) => ({
|
|
56
|
+
flex: 1,
|
|
57
|
+
padding: theme.spacing(0.75),
|
|
58
|
+
paddingLeft: theme.spacing(3.5),
|
|
59
|
+
...(correct && {
|
|
60
|
+
background: _renderUi.color.correctSecondary()
|
|
61
|
+
})
|
|
62
|
+
}));
|
|
63
|
+
const ActionButtons = (0, _styles.styled)('div')(({
|
|
64
|
+
theme
|
|
65
|
+
}) => ({
|
|
66
|
+
margin: theme.spacing(0.5),
|
|
67
|
+
display: 'flex'
|
|
68
|
+
}));
|
|
69
|
+
const StyledIconButton = (0, _styles.styled)(_IconButton.default)(({
|
|
70
|
+
theme
|
|
71
|
+
}) => ({
|
|
72
|
+
fontSize: theme.typography.fontSize,
|
|
73
|
+
padding: theme.spacing(0.5),
|
|
74
|
+
color: theme.palette.common.black
|
|
75
|
+
}));
|
|
76
|
+
class MenuItemComp extends _react.default.Component {
|
|
77
|
+
constructor(...args) {
|
|
78
|
+
super(...args);
|
|
79
|
+
(0, _defineProperty2.default)(this, "onRemoveClick", e => {
|
|
80
|
+
const {
|
|
81
|
+
onRemoveChoice
|
|
82
|
+
} = this.props;
|
|
81
83
|
e.preventDefault();
|
|
82
84
|
e.stopPropagation();
|
|
83
85
|
onRemoveChoice();
|
|
84
86
|
});
|
|
85
|
-
(0, _defineProperty2
|
|
86
|
-
|
|
87
|
+
(0, _defineProperty2.default)(this, "onEditClick", e => {
|
|
88
|
+
const {
|
|
89
|
+
onEditChoice
|
|
90
|
+
} = this.props;
|
|
87
91
|
e.preventDefault();
|
|
88
92
|
e.stopPropagation();
|
|
89
93
|
onEditChoice();
|
|
90
94
|
});
|
|
91
|
-
return _this;
|
|
92
95
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
fontSize: "inherit"
|
|
109
|
-
})), /*#__PURE__*/_react["default"].createElement("div", {
|
|
110
|
-
className: (0, _classnames2["default"])(classes.valueHolder, (0, _defineProperty2["default"])({}, classes.correct, correct)),
|
|
111
|
-
onClick: onClick,
|
|
112
|
-
dangerouslySetInnerHTML: {
|
|
113
|
-
__html: value
|
|
114
|
-
}
|
|
115
|
-
}), /*#__PURE__*/_react["default"].createElement("div", {
|
|
116
|
-
className: classes.actionButtons
|
|
117
|
-
}, /*#__PURE__*/_react["default"].createElement(_IconButton["default"], {
|
|
118
|
-
className: classes.iconButton,
|
|
119
|
-
onClick: this.onEditClick,
|
|
120
|
-
size: "small",
|
|
121
|
-
"aria-label": "Edit"
|
|
122
|
-
}, /*#__PURE__*/_react["default"].createElement(_Edit["default"], {
|
|
123
|
-
fontSize: "inherit"
|
|
124
|
-
})), /*#__PURE__*/_react["default"].createElement(_IconButton["default"], {
|
|
125
|
-
className: classes.iconButton,
|
|
126
|
-
onClick: this.onRemoveClick,
|
|
127
|
-
size: "small",
|
|
128
|
-
"aria-label": "Remove"
|
|
129
|
-
}, /*#__PURE__*/_react["default"].createElement(_Close["default"], {
|
|
130
|
-
fontSize: "inherit"
|
|
131
|
-
}))));
|
|
132
|
-
}
|
|
133
|
-
}]);
|
|
134
|
-
return MenuItemComp;
|
|
135
|
-
}(_react["default"].Component);
|
|
136
|
-
|
|
137
|
-
(0, _defineProperty2["default"])(MenuItemComp, "propTypes", {
|
|
138
|
-
classes: _propTypes["default"].object.isRequired,
|
|
139
|
-
correct: _propTypes["default"].bool.isRequired,
|
|
140
|
-
onClick: _propTypes["default"].func.isRequired,
|
|
141
|
-
onRemoveChoice: _propTypes["default"].func.isRequired,
|
|
142
|
-
onEditChoice: _propTypes["default"].func.isRequired,
|
|
143
|
-
value: _propTypes["default"].string.isRequired
|
|
144
|
-
});
|
|
145
|
-
var MenuItem = (0, _styles.withStyles)(function (theme) {
|
|
146
|
-
return {
|
|
147
|
-
wrapper: {
|
|
148
|
-
display: 'flex',
|
|
149
|
-
alignItems: 'flex-start',
|
|
150
|
-
position: 'relative',
|
|
151
|
-
background: theme.palette.common.white,
|
|
152
|
-
borderBottom: "1px solid ".concat(theme.palette.grey[400]),
|
|
153
|
-
'&:last-child': {
|
|
154
|
-
borderRadius: '0 0 4px 4px'
|
|
96
|
+
render() {
|
|
97
|
+
const {
|
|
98
|
+
correct,
|
|
99
|
+
onClick,
|
|
100
|
+
value
|
|
101
|
+
} = this.props;
|
|
102
|
+
return /*#__PURE__*/_react.default.createElement(MenuItemWrapper, null, correct && /*#__PURE__*/_react.default.createElement(SelectedIcon, {
|
|
103
|
+
onClick: onClick
|
|
104
|
+
}, /*#__PURE__*/_react.default.createElement(_Check.default, {
|
|
105
|
+
fontSize: "inherit"
|
|
106
|
+
})), /*#__PURE__*/_react.default.createElement(ValueHolder, {
|
|
107
|
+
correct: correct,
|
|
108
|
+
onClick: onClick,
|
|
109
|
+
dangerouslySetInnerHTML: {
|
|
110
|
+
__html: value
|
|
155
111
|
}
|
|
156
|
-
},
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
left: theme.spacing.unit,
|
|
181
|
-
zIndex: 3
|
|
182
|
-
},
|
|
183
|
-
valueHolder: {
|
|
184
|
-
flex: 1,
|
|
185
|
-
padding: theme.spacing.unit * 0.75,
|
|
186
|
-
paddingLeft: theme.spacing.unit * 3.5
|
|
187
|
-
}
|
|
188
|
-
};
|
|
189
|
-
})(MenuItemComp);
|
|
190
|
-
|
|
191
|
-
var findSlateNode = function findSlateNode(key) {
|
|
112
|
+
}), /*#__PURE__*/_react.default.createElement(ActionButtons, null, /*#__PURE__*/_react.default.createElement(StyledIconButton, {
|
|
113
|
+
onClick: this.onEditClick,
|
|
114
|
+
size: "small",
|
|
115
|
+
"aria-label": "Edit"
|
|
116
|
+
}, /*#__PURE__*/_react.default.createElement(_Edit.default, {
|
|
117
|
+
fontSize: "inherit"
|
|
118
|
+
})), /*#__PURE__*/_react.default.createElement(StyledIconButton, {
|
|
119
|
+
onClick: this.onRemoveClick,
|
|
120
|
+
size: "small",
|
|
121
|
+
"aria-label": "Remove"
|
|
122
|
+
}, /*#__PURE__*/_react.default.createElement(_Close.default, {
|
|
123
|
+
fontSize: "inherit"
|
|
124
|
+
}))));
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
(0, _defineProperty2.default)(MenuItemComp, "propTypes", {
|
|
128
|
+
correct: _propTypes.default.bool.isRequired,
|
|
129
|
+
onClick: _propTypes.default.func.isRequired,
|
|
130
|
+
onRemoveChoice: _propTypes.default.func.isRequired,
|
|
131
|
+
onEditChoice: _propTypes.default.func.isRequired,
|
|
132
|
+
value: _propTypes.default.string.isRequired
|
|
133
|
+
});
|
|
134
|
+
const MenuItem = MenuItemComp;
|
|
135
|
+
const findSlateNode = key => {
|
|
192
136
|
return window.document.querySelector('[data-key="' + key + '"]');
|
|
193
137
|
};
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
var div = document.createElement('div');
|
|
138
|
+
const createElementFromHTML = htmlString => {
|
|
139
|
+
const div = document.createElement('div');
|
|
197
140
|
div.innerHTML = (htmlString || '').trim();
|
|
198
141
|
return div;
|
|
199
142
|
};
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
143
|
+
const ResponseContainer = (0, _styles.styled)('div')(({
|
|
144
|
+
theme
|
|
145
|
+
}) => ({
|
|
146
|
+
boxShadow: theme.shadows[2],
|
|
147
|
+
borderRadius: '4px',
|
|
148
|
+
width: '400px'
|
|
149
|
+
}));
|
|
150
|
+
const RespArea = (0, _styles.styled)(_editableHtml.default)(({
|
|
151
|
+
theme
|
|
152
|
+
}) => ({
|
|
153
|
+
borderRadius: '4px',
|
|
154
|
+
backgroundColor: theme.palette.common.white,
|
|
155
|
+
'& [data-slate-editor="true"]': {
|
|
156
|
+
minHeight: 'initial !important'
|
|
157
|
+
}
|
|
158
|
+
}));
|
|
159
|
+
const AddButton = (0, _styles.styled)(_IconButton.default)(({
|
|
160
|
+
theme
|
|
161
|
+
}) => ({
|
|
162
|
+
fontSize: theme.typography.fontSize + 2,
|
|
163
|
+
padding: theme.spacing(0.5),
|
|
164
|
+
color: theme.palette.common.black,
|
|
165
|
+
position: 'absolute',
|
|
166
|
+
top: '50%',
|
|
167
|
+
right: theme.spacing(2),
|
|
168
|
+
transform: 'translate(0, -50%)'
|
|
169
|
+
}));
|
|
170
|
+
const ChoicesHolder = (0, _styles.styled)('div')({
|
|
171
|
+
display: 'flex',
|
|
172
|
+
flexDirection: 'column',
|
|
173
|
+
'& > div:last-child': {
|
|
174
|
+
border: 'none'
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
const ItemBuilder = (0, _styles.styled)('div')(({
|
|
178
|
+
theme
|
|
179
|
+
}) => ({
|
|
180
|
+
padding: theme.spacing(0.5),
|
|
181
|
+
position: 'relative'
|
|
182
|
+
}));
|
|
183
|
+
class RespAreaToolbar extends _react.default.Component {
|
|
184
|
+
constructor(...args) {
|
|
185
|
+
super(...args);
|
|
186
|
+
(0, _defineProperty2.default)(this, "clickedInside", false);
|
|
187
|
+
(0, _defineProperty2.default)(this, "preventDone", false);
|
|
188
|
+
(0, _defineProperty2.default)(this, "state", {
|
|
219
189
|
respAreaMarkup: '',
|
|
220
190
|
editedChoiceIndex: -1
|
|
221
191
|
});
|
|
222
|
-
(0, _defineProperty2
|
|
223
|
-
|
|
224
|
-
respAreaMarkup
|
|
192
|
+
(0, _defineProperty2.default)(this, "onRespAreaChange", respAreaMarkup => {
|
|
193
|
+
this.setState({
|
|
194
|
+
respAreaMarkup
|
|
225
195
|
});
|
|
226
196
|
});
|
|
227
|
-
(0, _defineProperty2
|
|
228
|
-
if (
|
|
229
|
-
|
|
197
|
+
(0, _defineProperty2.default)(this, "onAddChoice", () => {
|
|
198
|
+
if (this.editorRef) {
|
|
199
|
+
this.editorRef.finishEditing();
|
|
230
200
|
}
|
|
231
201
|
});
|
|
232
|
-
(0, _defineProperty2
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
if (editedChoiceIndex >= 0 && choices
|
|
245
|
-
|
|
202
|
+
(0, _defineProperty2.default)(this, "onDone", val => {
|
|
203
|
+
const {
|
|
204
|
+
choices,
|
|
205
|
+
node,
|
|
206
|
+
value,
|
|
207
|
+
onAddChoice,
|
|
208
|
+
onToolbarDone
|
|
209
|
+
} = this.props;
|
|
210
|
+
const {
|
|
211
|
+
editedChoiceIndex
|
|
212
|
+
} = this.state;
|
|
213
|
+
const onlyText = createElementFromHTML(val).textContent.trim();
|
|
214
|
+
if (editedChoiceIndex >= 0 && choices?.[editedChoiceIndex]?.correct) {
|
|
215
|
+
const update = {
|
|
216
|
+
...node.data.toJSON(),
|
|
246
217
|
value: val
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
var change = value.change().setNodeByKey(node.key, {
|
|
218
|
+
};
|
|
219
|
+
const change = value.change().setNodeByKey(node.key, {
|
|
250
220
|
data: update
|
|
251
221
|
});
|
|
252
222
|
onToolbarDone(change, false);
|
|
253
223
|
}
|
|
254
|
-
|
|
255
|
-
if (!(0, _isEmpty["default"])(onlyText)) {
|
|
224
|
+
if (!(0, _isEmpty.default)(onlyText)) {
|
|
256
225
|
onAddChoice(node.data.get('index'), val, editedChoiceIndex);
|
|
257
226
|
}
|
|
258
|
-
|
|
259
|
-
_this2.setState({
|
|
227
|
+
this.setState({
|
|
260
228
|
editedChoiceIndex: -1
|
|
261
229
|
});
|
|
262
230
|
});
|
|
263
|
-
(0, _defineProperty2
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
231
|
+
(0, _defineProperty2.default)(this, "onSelectChoice", (newValue, index) => {
|
|
232
|
+
const {
|
|
233
|
+
node,
|
|
234
|
+
value,
|
|
235
|
+
onToolbarDone,
|
|
236
|
+
onSelectChoice
|
|
237
|
+
} = this.props;
|
|
238
|
+
const update = {
|
|
239
|
+
...node.data.toJSON(),
|
|
271
240
|
value: newValue
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
var change = value.change().setNodeByKey(node.key, {
|
|
241
|
+
};
|
|
242
|
+
const change = value.change().setNodeByKey(node.key, {
|
|
275
243
|
data: update
|
|
276
244
|
});
|
|
277
|
-
|
|
245
|
+
const nextText = value.document.getNextText(node.key);
|
|
278
246
|
change.moveFocusTo(nextText.key, 0).moveAnchorTo(nextText.key, 0);
|
|
279
247
|
onToolbarDone(change, false);
|
|
280
248
|
onSelectChoice(index);
|
|
281
249
|
});
|
|
282
|
-
(0, _defineProperty2
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
if ((0, _isEqual
|
|
290
|
-
|
|
250
|
+
(0, _defineProperty2.default)(this, "onRemoveChoice", (val, index) => {
|
|
251
|
+
const {
|
|
252
|
+
node,
|
|
253
|
+
value,
|
|
254
|
+
onToolbarDone,
|
|
255
|
+
onRemoveChoice
|
|
256
|
+
} = this.props;
|
|
257
|
+
if ((0, _isEqual.default)(val, node.data.get('value'))) {
|
|
258
|
+
const update = {
|
|
259
|
+
...node.data.toJSON(),
|
|
291
260
|
value: null
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
var change = value.change().setNodeByKey(node.key, {
|
|
261
|
+
};
|
|
262
|
+
const change = value.change().setNodeByKey(node.key, {
|
|
295
263
|
data: update
|
|
296
264
|
});
|
|
297
265
|
onToolbarDone(change, false);
|
|
298
266
|
}
|
|
299
|
-
|
|
300
267
|
onRemoveChoice(index);
|
|
301
268
|
});
|
|
302
|
-
(0, _defineProperty2
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
_this2.setState({
|
|
269
|
+
(0, _defineProperty2.default)(this, "onEditChoice", (val, index) => {
|
|
270
|
+
this.onRespAreaChange(val);
|
|
271
|
+
this.setState({
|
|
306
272
|
editedChoiceIndex: index
|
|
307
273
|
});
|
|
308
274
|
});
|
|
309
|
-
(0, _defineProperty2
|
|
275
|
+
(0, _defineProperty2.default)(this, "onKeyDown", event => {
|
|
310
276
|
if (event.key === 'Enter') {
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
277
|
+
this.preventDone = false;
|
|
278
|
+
this.onAddChoice();
|
|
279
|
+
// Cancelling event
|
|
316
280
|
return false;
|
|
317
281
|
}
|
|
318
282
|
});
|
|
319
|
-
(0, _defineProperty2
|
|
320
|
-
if (
|
|
321
|
-
|
|
283
|
+
(0, _defineProperty2.default)(this, "onBlur", () => {
|
|
284
|
+
if (this.clickedInside) {
|
|
285
|
+
this.clickedInside = false;
|
|
322
286
|
return;
|
|
323
287
|
}
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
});
|
|
334
|
-
|
|
335
|
-
_this2.onAddChoice();
|
|
336
|
-
|
|
288
|
+
const {
|
|
289
|
+
node,
|
|
290
|
+
choices,
|
|
291
|
+
onCheck,
|
|
292
|
+
onToolbarDone,
|
|
293
|
+
value
|
|
294
|
+
} = this.props;
|
|
295
|
+
const correctResponse = (choices || []).find(choice => choice.correct);
|
|
296
|
+
this.onAddChoice();
|
|
337
297
|
if (!choices || choices && choices.length < 2 || !correctResponse) {
|
|
338
|
-
onCheck(
|
|
339
|
-
|
|
298
|
+
onCheck(() => {
|
|
299
|
+
const change = value.change();
|
|
340
300
|
change.removeNodeByKey(node.get('key'));
|
|
341
301
|
onToolbarDone(change, false);
|
|
342
302
|
});
|
|
343
303
|
}
|
|
344
304
|
});
|
|
345
|
-
(0, _defineProperty2
|
|
346
|
-
|
|
305
|
+
(0, _defineProperty2.default)(this, "onClickInside", () => {
|
|
306
|
+
this.clickedInside = true;
|
|
347
307
|
});
|
|
348
|
-
(0, _defineProperty2
|
|
308
|
+
(0, _defineProperty2.default)(this, "focusInput", () => {
|
|
349
309
|
// we need to focus the input so that math is saved even without pressing the green checkmark
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
310
|
+
const slateEditorRef = this.editorRef && this.editorRef.rootRef && this.editorRef.rootRef.slateEditor;
|
|
311
|
+
const inputRef = slateEditorRef && slateEditorRef.editorRef && slateEditorRef.editorRef.element;
|
|
353
312
|
if (inputRef) {
|
|
354
313
|
inputRef.focus();
|
|
355
314
|
}
|
|
356
315
|
});
|
|
357
|
-
return _this2;
|
|
358
316
|
}
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
if (domNode) {
|
|
367
|
-
//eslint-disable-next-line
|
|
368
|
-
var domNodeRect = domNode.getBoundingClientRect();
|
|
369
|
-
var editor = domNode.closest('[data-slate-editor]');
|
|
370
|
-
var editorRect = editor.getBoundingClientRect();
|
|
371
|
-
var top = domNodeRect.top - editorRect.top;
|
|
372
|
-
var left = domNodeRect.left - editorRect.left;
|
|
373
|
-
this.setState({
|
|
374
|
-
toolbarStyle: {
|
|
375
|
-
position: 'absolute',
|
|
376
|
-
top: "".concat(top + domNodeRect.height + 60, "px"),
|
|
377
|
-
left: "".concat(left + 25, "px")
|
|
378
|
-
}
|
|
379
|
-
});
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
}, {
|
|
383
|
-
key: "componentDidUpdate",
|
|
384
|
-
value: function componentDidUpdate() {
|
|
317
|
+
componentDidMount() {
|
|
318
|
+
const {
|
|
319
|
+
node
|
|
320
|
+
} = this.props;
|
|
321
|
+
const domNode = findSlateNode(node.key);
|
|
322
|
+
if (domNode) {
|
|
385
323
|
//eslint-disable-next-line
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
324
|
+
const domNodeRect = domNode.getBoundingClientRect();
|
|
325
|
+
const editor = domNode.closest('[data-slate-editor]');
|
|
326
|
+
const editorRect = editor.getBoundingClientRect();
|
|
327
|
+
const top = domNodeRect.top - editorRect.top;
|
|
328
|
+
const left = domNodeRect.left - editorRect.left;
|
|
329
|
+
this.setState({
|
|
330
|
+
toolbarStyle: {
|
|
331
|
+
position: 'absolute',
|
|
332
|
+
top: `${top + domNodeRect.height + 60}px`,
|
|
333
|
+
left: `${left + 25}px`
|
|
334
|
+
}
|
|
335
|
+
});
|
|
389
336
|
}
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
return null;
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
return /*#__PURE__*/_react["default"].createElement("div", {
|
|
415
|
-
className: classes.responseContainer,
|
|
416
|
-
style: _objectSpread(_objectSpread({}, toolbarStyle), {}, {
|
|
417
|
-
backgroundColor: '#E0E1E6'
|
|
418
|
-
}),
|
|
419
|
-
onMouseDown: this.onClickInside
|
|
420
|
-
}, /*#__PURE__*/_react["default"].createElement("div", {
|
|
421
|
-
className: classes.itemBuilder
|
|
422
|
-
}, /*#__PURE__*/_react["default"].createElement(_editableHtml["default"], {
|
|
423
|
-
ref: function ref(_ref) {
|
|
424
|
-
if (_ref) {
|
|
425
|
-
_this3.editorRef = _ref;
|
|
426
|
-
}
|
|
427
|
-
},
|
|
428
|
-
autoFocus: true,
|
|
429
|
-
autoSave: true,
|
|
430
|
-
className: classes.respArea,
|
|
431
|
-
toolbarOpts: {
|
|
432
|
-
position: 'top',
|
|
433
|
-
alwaysVisible: false,
|
|
434
|
-
showDone: false,
|
|
435
|
-
doneOn: 'blur'
|
|
436
|
-
},
|
|
437
|
-
markup: respAreaMarkup,
|
|
438
|
-
onKeyDown: this.onKeyDown,
|
|
439
|
-
languageCharactersProps: [{
|
|
440
|
-
language: 'spanish'
|
|
441
|
-
}, {
|
|
442
|
-
language: 'special'
|
|
443
|
-
}],
|
|
444
|
-
onChange: function onChange(respAreaMarkup) {
|
|
445
|
-
if (_this3.preventDone) {
|
|
446
|
-
return;
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
_this3.onRespAreaChange(respAreaMarkup);
|
|
450
|
-
},
|
|
451
|
-
onDone: function onDone(val) {
|
|
452
|
-
if (_this3.preventDone) {
|
|
453
|
-
return;
|
|
454
|
-
}
|
|
455
|
-
|
|
456
|
-
_this3.onDone(val);
|
|
457
|
-
},
|
|
458
|
-
onBlur: function onBlur(e) {
|
|
459
|
-
if (!e.relatedTarget) {
|
|
460
|
-
return;
|
|
461
|
-
}
|
|
462
|
-
|
|
463
|
-
var isInInsertCharacter = !!(e.relatedTarget && e.relatedTarget.closest('.insert-character-dialog'));
|
|
464
|
-
var isInDoneButton = !!(e.relatedTarget && e.relatedTarget.closest('[aria-label="Done"]'));
|
|
465
|
-
_this3.preventDone = isInInsertCharacter || isInDoneButton;
|
|
466
|
-
|
|
467
|
-
if (isInInsertCharacter || isInDoneButton) {
|
|
468
|
-
_this3.clickedInside = true;
|
|
469
|
-
}
|
|
470
|
-
|
|
471
|
-
_this3.onBlur(e);
|
|
472
|
-
},
|
|
473
|
-
placeholder: "Add Choice",
|
|
474
|
-
pluginProps: (0, _utils.getPluginProps)(responseAreaInputConfiguration === null || responseAreaInputConfiguration === void 0 ? void 0 : responseAreaInputConfiguration.inputConfiguration, baseInputConfiguration),
|
|
475
|
-
spellCheck: spellCheck,
|
|
476
|
-
uploadSoundSupport: uploadSoundSupport,
|
|
477
|
-
mathMlOptions: mathMlOptions
|
|
478
|
-
}), /*#__PURE__*/_react["default"].createElement(_IconButton["default"], {
|
|
479
|
-
className: classes.addButton,
|
|
480
|
-
onMouseDown: function onMouseDown() {
|
|
481
|
-
return _this3.focusInput();
|
|
482
|
-
},
|
|
483
|
-
onClick: function onClick() {
|
|
484
|
-
return _this3.onAddChoice();
|
|
485
|
-
},
|
|
486
|
-
size: "small",
|
|
487
|
-
"aria-label": "Add"
|
|
488
|
-
}, /*#__PURE__*/_react["default"].createElement(_Add["default"], {
|
|
489
|
-
fontSize: "inherit"
|
|
490
|
-
}))), choices && /*#__PURE__*/_react["default"].createElement("div", {
|
|
491
|
-
className: classes.choicesHolder
|
|
492
|
-
}, choices.map(function (_ref2, index) {
|
|
493
|
-
var label = _ref2.label,
|
|
494
|
-
correct = _ref2.correct;
|
|
495
|
-
return /*#__PURE__*/_react["default"].createElement(MenuItem, {
|
|
496
|
-
key: index,
|
|
497
|
-
onClick: function onClick() {
|
|
498
|
-
return _this3.onSelectChoice(label, index);
|
|
499
|
-
},
|
|
500
|
-
onRemoveChoice: function onRemoveChoice() {
|
|
501
|
-
return _this3.onRemoveChoice(label, index);
|
|
502
|
-
},
|
|
503
|
-
onEditChoice: function onEditChoice() {
|
|
504
|
-
return _this3.onEditChoice(label, index);
|
|
505
|
-
},
|
|
506
|
-
value: label,
|
|
507
|
-
correct: correct
|
|
508
|
-
});
|
|
509
|
-
})));
|
|
337
|
+
}
|
|
338
|
+
componentDidUpdate() {
|
|
339
|
+
//eslint-disable-next-line
|
|
340
|
+
const domNode = _reactDom.default.findDOMNode(this);
|
|
341
|
+
(0, _mathRendering.renderMath)(domNode);
|
|
342
|
+
}
|
|
343
|
+
render() {
|
|
344
|
+
const {
|
|
345
|
+
choices,
|
|
346
|
+
spellCheck,
|
|
347
|
+
uploadSoundSupport,
|
|
348
|
+
mathMlOptions = {},
|
|
349
|
+
baseInputConfiguration = {},
|
|
350
|
+
responseAreaInputConfiguration = {}
|
|
351
|
+
} = this.props;
|
|
352
|
+
const {
|
|
353
|
+
respAreaMarkup,
|
|
354
|
+
toolbarStyle
|
|
355
|
+
} = this.state;
|
|
356
|
+
if (!toolbarStyle) {
|
|
357
|
+
return null;
|
|
510
358
|
}
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
359
|
+
return /*#__PURE__*/_react.default.createElement(ResponseContainer, {
|
|
360
|
+
style: {
|
|
361
|
+
...toolbarStyle,
|
|
362
|
+
backgroundColor: '#E0E1E6'
|
|
363
|
+
},
|
|
364
|
+
onMouseDown: this.onClickInside
|
|
365
|
+
}, /*#__PURE__*/_react.default.createElement(ItemBuilder, null, /*#__PURE__*/_react.default.createElement(RespArea, {
|
|
366
|
+
ref: ref => {
|
|
367
|
+
if (ref) {
|
|
368
|
+
this.editorRef = ref;
|
|
369
|
+
}
|
|
370
|
+
},
|
|
371
|
+
autoFocus: true,
|
|
372
|
+
autoSave: true,
|
|
373
|
+
toolbarOpts: {
|
|
374
|
+
position: 'top',
|
|
375
|
+
alwaysVisible: false,
|
|
376
|
+
showDone: false,
|
|
377
|
+
doneOn: 'blur'
|
|
378
|
+
},
|
|
379
|
+
markup: respAreaMarkup,
|
|
380
|
+
onKeyDown: this.onKeyDown,
|
|
381
|
+
languageCharactersProps: [{
|
|
382
|
+
language: 'spanish'
|
|
383
|
+
}, {
|
|
384
|
+
language: 'special'
|
|
385
|
+
}],
|
|
386
|
+
onChange: respAreaMarkup => {
|
|
387
|
+
if (this.preventDone) {
|
|
388
|
+
return;
|
|
389
|
+
}
|
|
390
|
+
this.onRespAreaChange(respAreaMarkup);
|
|
391
|
+
},
|
|
392
|
+
onDone: val => {
|
|
393
|
+
if (this.preventDone) {
|
|
394
|
+
return;
|
|
395
|
+
}
|
|
396
|
+
this.onDone(val);
|
|
397
|
+
},
|
|
398
|
+
onBlur: e => {
|
|
399
|
+
if (!e.relatedTarget) {
|
|
400
|
+
return;
|
|
401
|
+
}
|
|
402
|
+
const isInInsertCharacter = !!(e.relatedTarget && e.relatedTarget.closest('.insert-character-dialog'));
|
|
403
|
+
const isInDoneButton = !!(e.relatedTarget && e.relatedTarget.closest('[aria-label="Done"]'));
|
|
404
|
+
this.preventDone = isInInsertCharacter || isInDoneButton;
|
|
405
|
+
if (isInInsertCharacter || isInDoneButton) {
|
|
406
|
+
this.clickedInside = true;
|
|
407
|
+
}
|
|
408
|
+
this.onBlur(e);
|
|
409
|
+
},
|
|
410
|
+
placeholder: "Add Choice",
|
|
411
|
+
pluginProps: (0, _utils.getPluginProps)(responseAreaInputConfiguration?.inputConfiguration, baseInputConfiguration),
|
|
412
|
+
spellCheck: spellCheck,
|
|
413
|
+
uploadSoundSupport: uploadSoundSupport,
|
|
414
|
+
mathMlOptions: mathMlOptions
|
|
415
|
+
}), /*#__PURE__*/_react.default.createElement(AddButton, {
|
|
416
|
+
onMouseDown: () => this.focusInput(),
|
|
417
|
+
onClick: () => this.onAddChoice(),
|
|
418
|
+
size: "small",
|
|
419
|
+
"aria-label": "Add"
|
|
420
|
+
}, /*#__PURE__*/_react.default.createElement(_Add.default, {
|
|
421
|
+
fontSize: "inherit"
|
|
422
|
+
}))), choices && /*#__PURE__*/_react.default.createElement(ChoicesHolder, null, choices.map(({
|
|
423
|
+
label,
|
|
424
|
+
correct
|
|
425
|
+
}, index) => /*#__PURE__*/_react.default.createElement(MenuItem, {
|
|
426
|
+
key: index,
|
|
427
|
+
onClick: () => this.onSelectChoice(label, index),
|
|
428
|
+
onRemoveChoice: () => this.onRemoveChoice(label, index),
|
|
429
|
+
onEditChoice: () => this.onEditChoice(label, index),
|
|
430
|
+
value: label,
|
|
431
|
+
correct: correct
|
|
432
|
+
}))));
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
(0, _defineProperty2.default)(RespAreaToolbar, "propTypes", {
|
|
436
|
+
node: _propTypes.default.object,
|
|
437
|
+
uploadSoundSupport: _propTypes.default.object,
|
|
438
|
+
onDone: _propTypes.default.func,
|
|
439
|
+
choices: _propTypes.default.array,
|
|
440
|
+
onAddChoice: _propTypes.default.func.isRequired,
|
|
441
|
+
onCheck: _propTypes.default.func,
|
|
442
|
+
onRemoveChoice: _propTypes.default.func.isRequired,
|
|
443
|
+
onSelectChoice: _propTypes.default.func.isRequired,
|
|
444
|
+
onToolbarDone: _propTypes.default.func.isRequired,
|
|
445
|
+
value: _propTypes.default.shape({
|
|
446
|
+
change: _propTypes.default.func.isRequired,
|
|
447
|
+
document: _propTypes.default.shape({
|
|
448
|
+
getNextText: _propTypes.default.func.isRequired
|
|
531
449
|
})
|
|
532
450
|
}),
|
|
533
|
-
spellCheck: _propTypes
|
|
451
|
+
spellCheck: _propTypes.default.bool
|
|
534
452
|
});
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
responseContainer: {
|
|
538
|
-
boxShadow: theme.shadows[2],
|
|
539
|
-
borderRadius: '4px',
|
|
540
|
-
width: '400px'
|
|
541
|
-
},
|
|
542
|
-
respArea: {
|
|
543
|
-
borderRadius: '4px',
|
|
544
|
-
backgroundColor: theme.palette.common.white,
|
|
545
|
-
'& [data-slate-editor="true"]': {
|
|
546
|
-
minHeight: 'initial !important'
|
|
547
|
-
}
|
|
548
|
-
},
|
|
549
|
-
addButton: {
|
|
550
|
-
fontSize: theme.typography.fontSize + 2,
|
|
551
|
-
padding: theme.spacing.unit / 2,
|
|
552
|
-
color: theme.palette.common.black,
|
|
553
|
-
position: 'absolute',
|
|
554
|
-
top: '50%',
|
|
555
|
-
right: theme.spacing.unit * 2,
|
|
556
|
-
transform: 'translate(0, -50%)'
|
|
557
|
-
},
|
|
558
|
-
choicesHolder: {
|
|
559
|
-
display: 'flex',
|
|
560
|
-
flexDirection: 'column',
|
|
561
|
-
'& > div:last-child': {
|
|
562
|
-
border: 'none'
|
|
563
|
-
}
|
|
564
|
-
},
|
|
565
|
-
itemBuilder: {
|
|
566
|
-
padding: theme.spacing.unit / 2,
|
|
567
|
-
position: 'relative'
|
|
568
|
-
}
|
|
569
|
-
};
|
|
570
|
-
})(RespAreaToolbar);
|
|
571
|
-
var _default = StyledRespAreaToolbar;
|
|
572
|
-
exports["default"] = _default;
|
|
453
|
+
const StyledRespAreaToolbar = RespAreaToolbar;
|
|
454
|
+
var _default = exports.default = StyledRespAreaToolbar;
|
|
573
455
|
//# sourceMappingURL=inline-dropdown-toolbar.js.map
|