@pie-element/inline-dropdown 8.3.4-next.3 → 9.0.0-beta.1

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 (37) hide show
  1. package/CHANGELOG.md +0 -11
  2. package/configure/CHANGELOG.md +0 -11
  3. package/configure/lib/defaults.js +2 -3
  4. package/configure/lib/defaults.js.map +1 -1
  5. package/configure/lib/index.js +111 -185
  6. package/configure/lib/index.js.map +1 -1
  7. package/configure/lib/inline-dropdown-toolbar.js +371 -496
  8. package/configure/lib/inline-dropdown-toolbar.js.map +1 -1
  9. package/configure/lib/main.js +479 -596
  10. package/configure/lib/main.js.map +1 -1
  11. package/configure/lib/markupUtils.js +20 -39
  12. package/configure/lib/markupUtils.js.map +1 -1
  13. package/configure/lib/response-area.js +34 -85
  14. package/configure/lib/response-area.js.map +1 -1
  15. package/configure/lib/utils.js +11 -22
  16. package/configure/lib/utils.js.map +1 -1
  17. package/configure/package.json +11 -9
  18. package/controller/CHANGELOG.md +0 -11
  19. package/controller/lib/defaults.js +2 -3
  20. package/controller/lib/defaults.js.map +1 -1
  21. package/controller/lib/index.js +156 -290
  22. package/controller/lib/index.js.map +1 -1
  23. package/controller/lib/utils.js +8 -15
  24. package/controller/lib/utils.js.map +1 -1
  25. package/controller/package.json +2 -2
  26. package/lib/index.js +65 -110
  27. package/lib/index.js.map +1 -1
  28. package/lib/inline-dropdown.js +148 -220
  29. package/lib/inline-dropdown.js.map +1 -1
  30. package/package.json +12 -10
  31. package/esm/configure.js +0 -24594
  32. package/esm/configure.js.map +0 -1
  33. package/esm/controller.js +0 -3944
  34. package/esm/controller.js.map +0 -1
  35. package/esm/element.js +0 -9587
  36. package/esm/element.js.map +0 -1
  37. package/esm/package.json +0 -3
@@ -1,573 +1,448 @@
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["default"] = exports.RespAreaToolbar = void 0;
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
- var _editableHtml = _interopRequireDefault(require("@pie-lib/editable-html"));
33
-
13
+ var _editableHtmlTipTap = _interopRequireDefault(require("@pie-lib/editable-html-tip-tap"));
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 _Add = _interopRequireDefault(require("@material-ui/icons/Add"));
47
-
48
- var _Check = _interopRequireDefault(require("@material-ui/icons/Check"));
49
-
50
- var _Close = _interopRequireDefault(require("@material-ui/icons/Close"));
51
-
52
- var _Edit = _interopRequireDefault(require("@material-ui/icons/Edit"));
53
-
54
- var _IconButton = _interopRequireDefault(require("@material-ui/core/IconButton"));
55
-
56
- 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; }
57
-
58
- 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; }
59
-
60
- 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); }; }
61
-
62
- 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; } }
63
-
64
- var MenuItemComp = /*#__PURE__*/function (_React$Component) {
65
- (0, _inherits2["default"])(MenuItemComp, _React$Component);
66
-
67
- var _super = _createSuper(MenuItemComp);
68
-
69
- function MenuItemComp() {
70
- var _this;
71
-
72
- (0, _classCallCheck2["default"])(this, MenuItemComp);
73
-
74
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
75
- args[_key] = arguments[_key];
76
- }
77
-
78
- _this = _super.call.apply(_super, [this].concat(args));
79
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "onRemoveClick", function (e) {
80
- var onRemoveChoice = _this.props.onRemoveChoice;
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["default"])((0, _assertThisInitialized2["default"])(_this), "onEditClick", function (e) {
86
- var onEditChoice = _this.props.onEditChoice;
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
- (0, _createClass2["default"])(MenuItemComp, [{
95
- key: "render",
96
- value: function render() {
97
- var _this$props = this.props,
98
- classes = _this$props.classes,
99
- correct = _this$props.correct,
100
- onClick = _this$props.onClick,
101
- value = _this$props.value;
102
- return /*#__PURE__*/_react["default"].createElement("div", {
103
- className: classes.wrapper
104
- }, correct && /*#__PURE__*/_react["default"].createElement("div", {
105
- className: classes.selectedIcon,
106
- onClick: onClick
107
- }, /*#__PURE__*/_react["default"].createElement(_Check["default"], {
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
- correct: {
158
- background: _renderUi.color.correctSecondary()
159
- },
160
- actionButtons: {
161
- margin: theme.spacing.unit / 2,
162
- display: 'flex'
163
- },
164
- iconButton: {
165
- fontSize: theme.typography.fontSize,
166
- padding: theme.spacing.unit / 2,
167
- color: theme.palette.common.black
168
- },
169
- selectedIcon: {
170
- display: 'flex',
171
- justifyContent: 'center',
172
- color: theme.palette.common.white,
173
- fontSize: theme.typography.fontSize,
174
- fontStyle: 'normal',
175
- position: 'absolute',
176
- transform: 'translate(0, -50%)',
177
- backgroundColor: _renderUi.color.correct(),
178
- borderRadius: '50%',
179
- top: theme.spacing.unit * 2,
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
- var createElementFromHTML = function createElementFromHTML(htmlString) {
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
- var RespAreaToolbar = /*#__PURE__*/function (_React$Component2) {
202
- (0, _inherits2["default"])(RespAreaToolbar, _React$Component2);
203
-
204
- var _super2 = _createSuper(RespAreaToolbar);
205
-
206
- function RespAreaToolbar() {
207
- var _this2;
208
-
209
- (0, _classCallCheck2["default"])(this, RespAreaToolbar);
210
-
211
- for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
212
- args[_key2] = arguments[_key2];
213
- }
214
-
215
- _this2 = _super2.call.apply(_super2, [this].concat(args));
216
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this2), "clickedInside", false);
217
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this2), "preventDone", false);
218
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this2), "state", {
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)(_editableHtmlTipTap.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["default"])((0, _assertThisInitialized2["default"])(_this2), "onRespAreaChange", function (respAreaMarkup) {
223
- _this2.setState({
224
- respAreaMarkup: respAreaMarkup
192
+ (0, _defineProperty2.default)(this, "onRespAreaChange", respAreaMarkup => {
193
+ this.setState({
194
+ respAreaMarkup
225
195
  });
226
196
  });
227
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this2), "onAddChoice", function () {
228
- if (_this2.editorRef) {
229
- _this2.editorRef.finishEditing();
230
- }
197
+ (0, _defineProperty2.default)(this, "onAddChoice", () => {
198
+ const {
199
+ editor
200
+ } = this.props;
201
+ const {
202
+ tr
203
+ } = editor.state;
204
+ tr.isDone = true;
205
+ editor.view.dispatch(tr);
231
206
  });
232
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this2), "onDone", function (val) {
233
- var _choices$editedChoice;
234
-
235
- var _this2$props = _this2.props,
236
- choices = _this2$props.choices,
237
- node = _this2$props.node,
238
- value = _this2$props.value,
239
- onAddChoice = _this2$props.onAddChoice,
240
- onToolbarDone = _this2$props.onToolbarDone;
241
- var editedChoiceIndex = _this2.state.editedChoiceIndex;
242
- var onlyText = createElementFromHTML(val).textContent.trim();
243
-
244
- if (editedChoiceIndex >= 0 && choices !== null && choices !== void 0 && (_choices$editedChoice = choices[editedChoiceIndex]) !== null && _choices$editedChoice !== void 0 && _choices$editedChoice.correct) {
245
- var update = _objectSpread(_objectSpread({}, node.data.toJSON()), {}, {
207
+ (0, _defineProperty2.default)(this, "onDone", val => {
208
+ const {
209
+ choices,
210
+ node,
211
+ editor,
212
+ onAddChoice,
213
+ onToolbarDone
214
+ } = this.props;
215
+ const {
216
+ editedChoiceIndex
217
+ } = this.state;
218
+ const onlyText = createElementFromHTML(val).textContent.trim();
219
+ if (editedChoiceIndex >= 0 && choices?.[editedChoiceIndex]?.correct) {
220
+ editor.commands.updateAttributes('inline_dropdown', {
246
221
  value: val
247
222
  });
248
-
249
- var change = value.change().setNodeByKey(node.key, {
250
- data: update
251
- });
252
- onToolbarDone(change, false);
223
+ onToolbarDone(false);
253
224
  }
254
-
255
- if (!(0, _isEmpty["default"])(onlyText)) {
256
- onAddChoice(node.data.get('index'), val, editedChoiceIndex);
225
+ if (!(0, _isEmpty.default)(onlyText)) {
226
+ onAddChoice(node.attrs.index, val, editedChoiceIndex);
227
+ editor.commands.refreshResponseArea();
257
228
  }
258
-
259
- _this2.setState({
229
+ this.setState({
260
230
  editedChoiceIndex: -1
261
231
  });
262
232
  });
263
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this2), "onSelectChoice", function (newValue, index) {
264
- var _this2$props2 = _this2.props,
265
- node = _this2$props2.node,
266
- value = _this2$props2.value,
267
- onToolbarDone = _this2$props2.onToolbarDone,
268
- onSelectChoice = _this2$props2.onSelectChoice;
269
-
270
- var update = _objectSpread(_objectSpread({}, node.data.toJSON()), {}, {
233
+ (0, _defineProperty2.default)(this, "onSelectChoice", (newValue, index) => {
234
+ const {
235
+ node,
236
+ editor,
237
+ onToolbarDone,
238
+ onSelectChoice
239
+ } = this.props;
240
+ editor.commands.updateAttributes('inline_dropdown', {
271
241
  value: newValue
272
242
  });
273
-
274
- var change = value.change().setNodeByKey(node.key, {
275
- data: update
276
- });
277
- var nextText = value.document.getNextText(node.key);
278
- change.moveFocusTo(nextText.key, 0).moveAnchorTo(nextText.key, 0);
279
- onToolbarDone(change, false);
243
+ onToolbarDone(false);
280
244
  onSelectChoice(index);
245
+ editor.commands.refreshResponseArea();
281
246
  });
282
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this2), "onRemoveChoice", function (val, index) {
283
- var _this2$props3 = _this2.props,
284
- node = _this2$props3.node,
285
- value = _this2$props3.value,
286
- onToolbarDone = _this2$props3.onToolbarDone,
287
- onRemoveChoice = _this2$props3.onRemoveChoice;
288
-
289
- if ((0, _isEqual["default"])(val, node.data.get('value'))) {
290
- var update = _objectSpread(_objectSpread({}, node.data.toJSON()), {}, {
247
+ (0, _defineProperty2.default)(this, "onRemoveChoice", (val, index) => {
248
+ const {
249
+ node,
250
+ editor,
251
+ onToolbarDone,
252
+ onRemoveChoice
253
+ } = this.props;
254
+ console.log('LOGGING', val, node.attrs.value, (0, _isEqual.default)(val, node.attrs.value));
255
+ if ((0, _isEqual.default)(val, node.attrs.value)) {
256
+ editor.commands.updateAttributes('explicit_constructed_response', {
291
257
  value: null
292
258
  });
293
-
294
- var change = value.change().setNodeByKey(node.key, {
295
- data: update
296
- });
297
- onToolbarDone(change, false);
259
+ onToolbarDone(false);
298
260
  }
299
-
300
261
  onRemoveChoice(index);
262
+ editor.commands.refreshResponseArea();
301
263
  });
302
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this2), "onEditChoice", function (val, index) {
303
- _this2.onRespAreaChange(val);
304
-
305
- _this2.setState({
264
+ (0, _defineProperty2.default)(this, "onEditChoice", (val, index) => {
265
+ this.onRespAreaChange(val);
266
+ this.setState({
306
267
  editedChoiceIndex: index
307
268
  });
308
269
  });
309
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this2), "onKeyDown", function (event) {
270
+ (0, _defineProperty2.default)(this, "onKeyDown", event => {
310
271
  if (event.key === 'Enter') {
311
- _this2.preventDone = false;
312
-
313
- _this2.onAddChoice(); // Cancelling event
314
-
315
-
272
+ this.preventDone = false;
273
+ this.onAddChoice();
274
+ // Cancelling event
316
275
  return false;
317
276
  }
318
277
  });
319
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this2), "onBlur", function () {
320
- if (_this2.clickedInside) {
321
- _this2.clickedInside = false;
278
+ (0, _defineProperty2.default)(this, "onBlur", () => {
279
+ if (this.clickedInside) {
280
+ this.clickedInside = false;
322
281
  return;
323
282
  }
324
-
325
- var _this2$props4 = _this2.props,
326
- node = _this2$props4.node,
327
- choices = _this2$props4.choices,
328
- onCheck = _this2$props4.onCheck,
329
- onToolbarDone = _this2$props4.onToolbarDone,
330
- value = _this2$props4.value;
331
- var correctResponse = (choices || []).find(function (choice) {
332
- return choice.correct;
333
- });
334
-
335
- _this2.onAddChoice();
336
-
283
+ const {
284
+ node,
285
+ choices,
286
+ onCheck,
287
+ onToolbarDone,
288
+ editor
289
+ } = this.props;
290
+ const correctResponse = (choices || []).find(choice => choice.correct);
291
+ this.onAddChoice();
337
292
  if (!choices || choices && choices.length < 2 || !correctResponse) {
338
- onCheck(function () {
339
- var change = value.change();
340
- change.removeNodeByKey(node.get('key'));
341
- onToolbarDone(change, false);
293
+ onCheck(() => {
294
+ const {
295
+ tr
296
+ } = editor.state;
297
+ tr.deleteSelection();
298
+ editor.view.dispatch(tr);
299
+ onToolbarDone(false);
342
300
  });
343
301
  }
344
302
  });
345
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this2), "onClickInside", function () {
346
- _this2.clickedInside = true;
303
+ (0, _defineProperty2.default)(this, "onClickInside", () => {
304
+ this.clickedInside = true;
347
305
  });
348
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this2), "focusInput", function () {
306
+ (0, _defineProperty2.default)(this, "focusInput", () => {
349
307
  // we need to focus the input so that math is saved even without pressing the green checkmark
350
- var slateEditorRef = _this2.editorRef && _this2.editorRef.rootRef && _this2.editorRef.rootRef.slateEditor;
351
- var inputRef = slateEditorRef && slateEditorRef.editorRef && slateEditorRef.editorRef.element;
352
-
308
+ const slateEditorRef = this.editorRef && this.editorRef.rootRef && this.editorRef.rootRef.slateEditor;
309
+ const inputRef = slateEditorRef && slateEditorRef.editorRef && slateEditorRef.editorRef.element;
353
310
  if (inputRef) {
354
311
  inputRef.focus();
355
312
  }
356
313
  });
357
- return _this2;
358
314
  }
359
-
360
- (0, _createClass2["default"])(RespAreaToolbar, [{
361
- key: "componentDidMount",
362
- value: function componentDidMount() {
363
- var node = this.props.node;
364
- var domNode = findSlateNode(node.key);
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() {
315
+ componentDidMount() {
316
+ const {
317
+ editor
318
+ } = this.props;
319
+ const domNode = editor.view.nodeDOM(editor.state.selection.from);
320
+ if (domNode?.nodeType === 1) {
385
321
  //eslint-disable-next-line
386
- var domNode = _reactDom["default"].findDOMNode(this);
387
-
388
- (0, _mathRendering.renderMath)(domNode);
322
+ const domNodeRect = domNode.getBoundingClientRect();
323
+ const editorNode = domNode.closest('.tiptap');
324
+ const editorRect = editorNode.getBoundingClientRect();
325
+ const top = domNodeRect.top - domNodeRect.height;
326
+ const left = domNodeRect.left - editorRect.left;
327
+ this.setState({
328
+ toolbarStyle: {
329
+ position: 'absolute',
330
+ top: `${top + domNodeRect.height + 40}px`,
331
+ left: `${left + 25}px`
332
+ }
333
+ });
389
334
  }
390
- }, {
391
- key: "render",
392
- value: function render() {
393
- var _this3 = this;
394
-
395
- var _this$props2 = this.props,
396
- classes = _this$props2.classes,
397
- choices = _this$props2.choices,
398
- spellCheck = _this$props2.spellCheck,
399
- uploadSoundSupport = _this$props2.uploadSoundSupport,
400
- _this$props2$mathMlOp = _this$props2.mathMlOptions,
401
- mathMlOptions = _this$props2$mathMlOp === void 0 ? {} : _this$props2$mathMlOp,
402
- _this$props2$baseInpu = _this$props2.baseInputConfiguration,
403
- baseInputConfiguration = _this$props2$baseInpu === void 0 ? {} : _this$props2$baseInpu,
404
- _this$props2$response = _this$props2.responseAreaInputConfiguration,
405
- responseAreaInputConfiguration = _this$props2$response === void 0 ? {} : _this$props2$response;
406
- var _this$state = this.state,
407
- respAreaMarkup = _this$state.respAreaMarkup,
408
- toolbarStyle = _this$state.toolbarStyle;
409
-
410
- if (!toolbarStyle) {
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
- })));
335
+ }
336
+ componentDidUpdate() {
337
+ //eslint-disable-next-line
338
+ const domNode = _reactDom.default.findDOMNode(this);
339
+ (0, _mathRendering.renderMath)(domNode);
340
+ }
341
+ render() {
342
+ const {
343
+ choices,
344
+ spellCheck,
345
+ uploadSoundSupport,
346
+ mathMlOptions = {},
347
+ baseInputConfiguration = {},
348
+ responseAreaInputConfiguration = {}
349
+ } = this.props;
350
+ const {
351
+ respAreaMarkup,
352
+ toolbarStyle
353
+ } = this.state;
354
+ if (!toolbarStyle) {
355
+ return null;
510
356
  }
511
- }]);
512
- return RespAreaToolbar;
513
- }(_react["default"].Component);
514
-
515
- exports.RespAreaToolbar = RespAreaToolbar;
516
- (0, _defineProperty2["default"])(RespAreaToolbar, "propTypes", {
517
- classes: _propTypes["default"].object,
518
- node: _propTypes["default"].object,
519
- uploadSoundSupport: _propTypes["default"].object,
520
- onDone: _propTypes["default"].func,
521
- choices: _propTypes["default"].array,
522
- onAddChoice: _propTypes["default"].func.isRequired,
523
- onCheck: _propTypes["default"].func,
524
- onRemoveChoice: _propTypes["default"].func.isRequired,
525
- onSelectChoice: _propTypes["default"].func.isRequired,
526
- onToolbarDone: _propTypes["default"].func.isRequired,
527
- value: _propTypes["default"].shape({
528
- change: _propTypes["default"].func.isRequired,
529
- document: _propTypes["default"].shape({
530
- getNextText: _propTypes["default"].func.isRequired
531
- })
532
- }),
533
- spellCheck: _propTypes["default"].bool
357
+ return /*#__PURE__*/_react.default.createElement(ResponseContainer, {
358
+ style: {
359
+ ...toolbarStyle,
360
+ backgroundColor: '#E0E1E6'
361
+ },
362
+ onMouseDown: this.onClickInside
363
+ }, /*#__PURE__*/_react.default.createElement(ItemBuilder, null, /*#__PURE__*/_react.default.createElement(RespArea, {
364
+ ref: ref => {
365
+ if (ref) {
366
+ this.editorRef = ref;
367
+ }
368
+ },
369
+ autoFocus: true,
370
+ autoSave: true,
371
+ toolbarOpts: {
372
+ position: 'top',
373
+ alwaysVisible: false,
374
+ showDone: false,
375
+ doneOn: 'blur'
376
+ },
377
+ markup: respAreaMarkup,
378
+ onKeyDown: this.onKeyDown,
379
+ languageCharactersProps: [{
380
+ language: 'spanish'
381
+ }, {
382
+ language: 'special'
383
+ }],
384
+ onChange: respAreaMarkup => {
385
+ if (this.preventDone) {
386
+ return;
387
+ }
388
+ this.onRespAreaChange(respAreaMarkup);
389
+ },
390
+ onDone: val => {
391
+ if (this.preventDone) {
392
+ return;
393
+ }
394
+ this.onDone(val);
395
+ },
396
+ onBlur: e => {
397
+ if (!e.relatedTarget) {
398
+ return;
399
+ }
400
+ const isInInsertCharacter = !!(e.relatedTarget && e.relatedTarget.closest('.insert-character-dialog'));
401
+ const isInDoneButton = !!(e.relatedTarget && e.relatedTarget.closest('[aria-label="Done"]'));
402
+ this.preventDone = isInInsertCharacter || isInDoneButton;
403
+ if (isInInsertCharacter || isInDoneButton) {
404
+ this.clickedInside = true;
405
+ }
406
+ this.onBlur(e);
407
+ },
408
+ placeholder: "Add Choice",
409
+ pluginProps: (0, _utils.getPluginProps)(responseAreaInputConfiguration?.inputConfiguration, baseInputConfiguration),
410
+ spellCheck: spellCheck,
411
+ uploadSoundSupport: uploadSoundSupport,
412
+ mathMlOptions: mathMlOptions
413
+ }), /*#__PURE__*/_react.default.createElement(AddButton, {
414
+ onMouseDown: () => this.focusInput(),
415
+ onClick: () => this.onAddChoice(),
416
+ size: "small",
417
+ "aria-label": "Add"
418
+ }, /*#__PURE__*/_react.default.createElement(_Add.default, {
419
+ fontSize: "inherit"
420
+ }))), choices && /*#__PURE__*/_react.default.createElement(ChoicesHolder, null, choices.map(({
421
+ label,
422
+ correct
423
+ }, index) => /*#__PURE__*/_react.default.createElement(MenuItem, {
424
+ key: index,
425
+ onClick: () => this.onSelectChoice(label, index),
426
+ onRemoveChoice: () => this.onRemoveChoice(label, index),
427
+ onEditChoice: () => this.onEditChoice(label, index),
428
+ value: label,
429
+ correct: correct
430
+ }))));
431
+ }
432
+ }
433
+ (0, _defineProperty2.default)(RespAreaToolbar, "propTypes", {
434
+ node: _propTypes.default.object,
435
+ uploadSoundSupport: _propTypes.default.object,
436
+ onDone: _propTypes.default.func,
437
+ choices: _propTypes.default.array,
438
+ onAddChoice: _propTypes.default.func.isRequired,
439
+ onCheck: _propTypes.default.func,
440
+ onRemoveChoice: _propTypes.default.func.isRequired,
441
+ onSelectChoice: _propTypes.default.func.isRequired,
442
+ onToolbarDone: _propTypes.default.func.isRequired,
443
+ editor: _propTypes.default.object,
444
+ spellCheck: _propTypes.default.bool
534
445
  });
535
- var StyledRespAreaToolbar = (0, _styles.withStyles)(function (theme) {
536
- return {
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;
446
+ const StyledRespAreaToolbar = RespAreaToolbar;
447
+ var _default = exports.default = StyledRespAreaToolbar;
573
448
  //# sourceMappingURL=inline-dropdown-toolbar.js.map