@pie-element/graphing 8.1.0 → 8.2.0-mui-update.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.
@@ -1,601 +1,490 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
- var _typeof = require("@babel/runtime/helpers/typeof");
6
-
7
4
  Object.defineProperty(exports, "__esModule", {
8
5
  value: true
9
6
  });
10
- exports["default"] = exports.Tools = exports.CorrectResponse = void 0;
11
-
12
- var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
13
-
14
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
15
-
16
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
17
-
18
- var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
19
-
20
- var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
21
-
22
- var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
23
-
24
- var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
25
-
7
+ exports.default = exports.Tools = exports.CorrectResponse = void 0;
26
8
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
27
-
28
- var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
29
-
9
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
30
10
  var React = _interopRequireWildcard(require("react"));
31
-
32
11
  var _reactDom = _interopRequireDefault(require("react-dom"));
33
-
34
- var _classnames = _interopRequireDefault(require("classnames"));
35
-
36
12
  var _propTypes = _interopRequireDefault(require("prop-types"));
37
-
38
- var _styles = require("@material-ui/core/styles");
39
-
13
+ var _styles = require("@mui/material/styles");
40
14
  var _graphing = require("@pie-lib/graphing");
41
-
42
15
  var _configUi = require("@pie-lib/config-ui");
43
-
44
16
  var _mathRendering = require("@pie-lib/math-rendering");
45
-
46
- var _Delete = _interopRequireDefault(require("@material-ui/icons/Delete"));
47
-
17
+ var _Delete = _interopRequireDefault(require("@mui/icons-material/Delete"));
48
18
  var _lodash = require("lodash");
49
-
50
- var _core = require("@material-ui/core");
51
-
52
- var _Info = _interopRequireDefault(require("@material-ui/icons/Info"));
53
-
54
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
55
-
56
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
57
-
58
- 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; }
59
-
60
- 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; }
61
-
62
- 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); }; }
63
-
64
- 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; } }
65
-
66
- var styles = function styles(theme) {
67
- return {
68
- column: {
69
- flex: 1
70
- },
71
- graphingTools: {
72
- color: theme.palette.grey['A200']
73
- },
74
- availableTools: {
75
- marginTop: theme.spacing.unit,
76
- display: 'flex',
77
- flexWrap: 'wrap'
78
- },
79
- availableTool: {
80
- cursor: 'pointer',
81
- margin: theme.spacing.unit,
82
- padding: theme.spacing.unit,
83
- border: "2px solid ".concat(theme.palette.common.white),
84
- textTransform: 'capitalize',
85
- '&:hover': {
86
- color: theme.palette.grey[800]
87
- }
88
- },
89
- selectedTool: {
90
- background: theme.palette.grey['A100'],
91
- border: "2px solid ".concat(theme.palette.grey['A200'])
92
- },
93
- container: {
94
- border: "2px solid ".concat(theme.palette.grey['A200']),
95
- borderRadius: '4px',
96
- padding: "0 ".concat(theme.spacing.unit * 4, "px ").concat(theme.spacing.unit * 2, "px"),
97
- background: theme.palette.grey[50]
98
- },
99
- button: {
100
- margin: "".concat(theme.spacing.unit * 2.5, "px 0"),
101
- cursor: 'pointer',
102
- background: theme.palette.grey[200],
103
- padding: theme.spacing.unit * 1.5,
104
- width: 'fit-content',
105
- borderRadius: '4px',
106
- '&:hover': {
107
- background: theme.palette.grey['A100']
108
- }
109
- },
110
- responseTitle: {
111
- display: 'flex',
112
- alignItems: 'center',
113
- marginTop: theme.spacing.unit * 2.5
114
- },
115
- iconButton: {
116
- marginLeft: '6px',
117
- color: theme.palette.grey[600],
118
- '&:hover': {
119
- cursor: 'pointer',
120
- color: theme.palette.common.black
121
- }
122
- },
123
- name: {
124
- marginBottom: theme.spacing.unit / 2
125
- },
126
- tooltip: {
127
- fontSize: theme.typography.fontSize - 2,
128
- whiteSpace: 'pre',
129
- maxWidth: '500px'
130
- },
131
- subtitleText: {
132
- marginTop: theme.spacing.unit * 1.5,
133
- marginBottom: theme.spacing.unit
134
- },
135
- toolsHeader: {
136
- display: 'flex',
137
- alignItems: 'center',
138
- justifyContent: 'space-between'
139
- },
140
- defaultTool: {
141
- display: 'flex',
142
- alignItems: 'center',
143
- width: '300px'
144
- },
145
- defaultToolSelect: {
146
- marginLeft: theme.spacing.unit,
147
- textTransform: 'uppercase',
148
- color: theme.palette.grey[800]
149
- },
150
- menuItem: {
151
- textTransform: 'uppercase'
152
- },
153
- noDefaultTool: {
154
- padding: theme.spacing.unit / 2
155
- },
156
- error: {
157
- color: theme.palette.error.main
158
- },
159
- errorMessage: {
160
- fontSize: theme.typography.fontSize - 2,
161
- color: theme.palette.error.main,
162
- marginTop: theme.spacing.unit
163
- },
164
- graphError: {
165
- border: "2px solid ".concat(theme.palette.error.main)
166
- }
167
- };
168
- };
169
-
170
- var Tools = function Tools(_ref) {
171
- var classes = _ref.classes,
172
- availableTools = _ref.availableTools,
173
- defaultTool = _ref.defaultTool,
174
- hasErrors = _ref.hasErrors,
175
- toolbarTools = _ref.toolbarTools,
176
- toggleToolBarTool = _ref.toggleToolBarTool,
177
- onDefaultToolChange = _ref.onDefaultToolChange;
178
- var allTools = availableTools || [];
179
- var isLabelAvailable = allTools.includes('label');
180
- var toolbarToolsNoLabel = (toolbarTools || []).filter(function (tool) {
181
- return tool !== 'label';
182
- });
183
-
19
+ var _material = require("@mui/material");
20
+ var _Info = _interopRequireDefault(require("@mui/icons-material/Info"));
21
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
22
+ // custom grey values close to old v3 accents
23
+ const GREY_A100 = '#D5D5D5';
24
+ const GREY_A200 = '#AAAAAA';
25
+ const GraphingTools = (0, _styles.styled)('div')(({
26
+ theme
27
+ }) => ({
28
+ color: GREY_A200
29
+ }));
30
+ const Button = (0, _styles.styled)('div')(({
31
+ theme
32
+ }) => ({
33
+ margin: `${theme.spacing(2.5)} 0`,
34
+ cursor: 'pointer',
35
+ background: theme.palette.grey[200],
36
+ padding: theme.spacing(1.5),
37
+ width: 'fit-content',
38
+ borderRadius: '4px',
39
+ '&:hover': {
40
+ background: GREY_A100
41
+ }
42
+ }));
43
+ const AvailableTools = (0, _styles.styled)('div')(({
44
+ theme
45
+ }) => ({
46
+ marginTop: theme.spacing(1),
47
+ display: 'flex',
48
+ flexWrap: 'wrap'
49
+ }));
50
+ const AvailableTool = (0, _styles.styled)('div')(({
51
+ theme
52
+ }) => ({
53
+ cursor: 'pointer',
54
+ margin: theme.spacing(1),
55
+ padding: theme.spacing(1),
56
+ border: `2px solid ${theme.palette.common.white}`,
57
+ textTransform: 'capitalize',
58
+ '&:hover': {
59
+ color: theme.palette.grey[800]
60
+ }
61
+ }));
62
+ const SelectedTool = (0, _styles.styled)(AvailableTool)(({
63
+ theme
64
+ }) => ({
65
+ background: GREY_A100,
66
+ border: `2px solid ${GREY_A200}`
67
+ }));
68
+ const ResponseTitle = (0, _styles.styled)('div')(({
69
+ theme
70
+ }) => ({
71
+ display: 'flex',
72
+ alignItems: 'center',
73
+ marginTop: theme.spacing(2.5)
74
+ }));
75
+ const IconButton = (0, _styles.styled)('div')(({
76
+ theme
77
+ }) => ({
78
+ marginLeft: '6px',
79
+ color: theme.palette.grey[600],
80
+ '&:hover': {
81
+ cursor: 'pointer',
82
+ color: theme.palette.common.black
83
+ }
84
+ }));
85
+ const Name = (0, _styles.styled)('div')(({
86
+ theme
87
+ }) => ({
88
+ marginBottom: theme.spacing(0.5)
89
+ }));
90
+ const StyledTooltip = (0, _styles.styled)(({
91
+ className,
92
+ ...props
93
+ }) => /*#__PURE__*/React.createElement(_material.Tooltip, (0, _extends2.default)({}, props, {
94
+ classes: {
95
+ tooltip: className
96
+ }
97
+ })))(({
98
+ theme
99
+ }) => ({
100
+ '& .MuiTooltip-tooltip': {
101
+ fontSize: theme.typography.fontSize - 2,
102
+ whiteSpace: 'pre',
103
+ maxWidth: '500px'
104
+ }
105
+ }));
106
+ const SubtitleText = (0, _styles.styled)(_material.Typography)(({
107
+ theme
108
+ }) => ({
109
+ marginTop: theme.spacing(1.5),
110
+ marginBottom: theme.spacing(1)
111
+ }));
112
+ const ToolsHeader = (0, _styles.styled)('div')({
113
+ display: 'flex',
114
+ alignItems: 'center',
115
+ justifyContent: 'space-between'
116
+ });
117
+ const DefaultTool = (0, _styles.styled)('div')(({
118
+ theme
119
+ }) => ({
120
+ display: 'flex',
121
+ alignItems: 'center',
122
+ width: '300px'
123
+ }));
124
+ const DefaultToolSelect = (0, _styles.styled)(_material.Select)(({
125
+ theme
126
+ }) => ({
127
+ marginLeft: theme.spacing(1),
128
+ textTransform: 'uppercase',
129
+ color: theme.palette.grey[800]
130
+ }));
131
+ const StyledMenuItem = (0, _styles.styled)(_material.MenuItem)({
132
+ textTransform: 'uppercase'
133
+ });
134
+ const ErrorMessage = (0, _styles.styled)('div')(({
135
+ theme
136
+ }) => ({
137
+ fontSize: theme.typography.fontSize - 2,
138
+ color: theme.palette.error.main,
139
+ marginTop: theme.spacing(1)
140
+ }));
141
+ const Tools = ({
142
+ availableTools,
143
+ defaultTool,
144
+ hasErrors,
145
+ toolbarTools,
146
+ toggleToolBarTool,
147
+ onDefaultToolChange
148
+ }) => {
149
+ let allTools = availableTools || [];
150
+ const isLabelAvailable = allTools.includes('label');
151
+ const toolbarToolsNoLabel = (toolbarTools || []).filter(tool => tool !== 'label');
184
152
  if (isLabelAvailable) {
185
153
  // label has to be placed at the end of the list
186
- var allToolsNoLabel = allTools.filter(function (tool) {
187
- return tool !== 'label';
188
- });
189
- allTools = [].concat((0, _toConsumableArray2["default"])(allToolsNoLabel), ['label']);
154
+ const allToolsNoLabel = allTools.filter(tool => tool !== 'label');
155
+ allTools = [...allToolsNoLabel, 'label'];
190
156
  }
191
-
192
- return /*#__PURE__*/React.createElement("div", {
193
- className: classes.graphingTools
194
- }, /*#__PURE__*/React.createElement("div", {
195
- className: classes.toolsHeader
196
- }, /*#__PURE__*/React.createElement("span", null, "GRAPHING TOOLS"), toolbarToolsNoLabel.length > 0 && /*#__PURE__*/React.createElement("div", {
197
- className: classes.defaultTool
198
- }, /*#__PURE__*/React.createElement("span", null, "Default graphing tool:"), /*#__PURE__*/React.createElement(_core.Select, {
199
- className: classes.defaultToolSelect,
157
+ return /*#__PURE__*/React.createElement(GraphingTools, null, /*#__PURE__*/React.createElement(ToolsHeader, null, /*#__PURE__*/React.createElement("span", null, "GRAPHING TOOLS"), toolbarToolsNoLabel.length > 0 && /*#__PURE__*/React.createElement(DefaultTool, null, /*#__PURE__*/React.createElement("span", null, "Default graphing tool:"), /*#__PURE__*/React.createElement(DefaultToolSelect, {
158
+ variant: "standard",
200
159
  onChange: onDefaultToolChange,
201
160
  value: defaultTool,
202
- disableUnderline: true
203
- }, toolbarToolsNoLabel.map(function (tool, index) {
204
- return /*#__PURE__*/React.createElement(_core.MenuItem, {
205
- key: index,
206
- className: classes.menuItem,
207
- value: tool
208
- }, tool);
209
- })))), /*#__PURE__*/React.createElement("div", {
210
- className: classes.availableTools
211
- }, allTools.map(function (tool) {
212
- var selected = toolbarTools.find(function (t) {
213
- return t === tool;
214
- });
215
- return /*#__PURE__*/React.createElement("div", {
216
- key: tool,
217
- className: (0, _classnames["default"])(classes.availableTool, selected && classes.selectedTool, hasErrors && tool !== 'label' && classes.error),
218
- onClick: function onClick() {
219
- return toggleToolBarTool(tool);
161
+ disableUnderline: true,
162
+ MenuProps: {
163
+ transitionDuration: {
164
+ enter: 225,
165
+ exit: 195
220
166
  }
167
+ }
168
+ }, toolbarToolsNoLabel.map((tool, index) => /*#__PURE__*/React.createElement(StyledMenuItem, {
169
+ key: index,
170
+ value: tool
171
+ }, tool))))), /*#__PURE__*/React.createElement(AvailableTools, null, allTools.map(tool => {
172
+ const selected = toolbarTools.find(t => t === tool);
173
+ const ToolComponent = selected ? SelectedTool : AvailableTool;
174
+ return /*#__PURE__*/React.createElement(ToolComponent, {
175
+ key: tool,
176
+ style: {
177
+ ...(hasErrors && tool !== 'label' && {
178
+ color: 'red'
179
+ })
180
+ },
181
+ onClick: () => toggleToolBarTool(tool)
221
182
  }, tool.toUpperCase());
222
183
  })));
223
184
  };
224
-
225
185
  exports.Tools = Tools;
226
186
  Tools.propTypes = {
227
- classes: _propTypes["default"].object.isRequired,
228
- toolbarTools: _propTypes["default"].arrayOf(_propTypes["default"].string),
229
- toggleToolBarTool: _propTypes["default"].func,
230
- availableTools: _propTypes["default"].array,
231
- defaultTool: _propTypes["default"].string,
232
- hasErrors: _propTypes["default"].number,
233
- onDefaultToolChange: _propTypes["default"].func
187
+ toolbarTools: _propTypes.default.arrayOf(_propTypes.default.string),
188
+ toggleToolBarTool: _propTypes.default.func,
189
+ availableTools: _propTypes.default.array,
190
+ defaultTool: _propTypes.default.string,
191
+ hasErrors: _propTypes.default.number,
192
+ onDefaultToolChange: _propTypes.default.func
234
193
  };
235
-
236
- var CorrectResponse = /*#__PURE__*/function (_React$Component) {
237
- (0, _inherits2["default"])(CorrectResponse, _React$Component);
238
-
239
- var _super = _createSuper(CorrectResponse);
240
-
241
- function CorrectResponse() {
242
- var _this;
243
-
244
- (0, _classCallCheck2["default"])(this, CorrectResponse);
245
-
246
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
247
- args[_key] = arguments[_key];
248
- }
249
-
250
- _this = _super.call.apply(_super, [this].concat(args));
251
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "state", {
194
+ class CorrectResponse extends React.Component {
195
+ constructor(...args) {
196
+ super(...args);
197
+ (0, _defineProperty2.default)(this, "state", {
252
198
  dialog: {
253
199
  open: false
254
200
  }
255
201
  });
256
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "handleAlertDialog", function (open, callback) {
257
- return _this.setState({
258
- dialog: {
259
- open: open
260
- }
261
- }, callback);
262
- });
263
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "changeMarks", function (key, marks) {
264
- var _this$props = _this.props,
265
- model = _this$props.model,
266
- onChange = _this$props.onChange;
267
- (0, _lodash.set)(model, "answers.".concat(key, ".marks"), marks);
202
+ (0, _defineProperty2.default)(this, "handleAlertDialog", (open, callback) => this.setState({
203
+ dialog: {
204
+ open
205
+ }
206
+ }, callback));
207
+ (0, _defineProperty2.default)(this, "changeMarks", (key, marks) => {
208
+ const {
209
+ model,
210
+ onChange
211
+ } = this.props;
212
+ (0, _lodash.set)(model, `answers.${key}.marks`, marks);
268
213
  onChange(model);
269
214
  });
270
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "filterMarks", function (tool) {
271
- var answers = _this.props.model.answers;
272
- return Object.entries(answers || {}).reduce(function (object, _ref2) {
273
- var _ref3 = (0, _slicedToArray2["default"])(_ref2, 2),
274
- key = _ref3[0],
275
- answer = _ref3[1];
276
-
277
- object[key] = _objectSpread(_objectSpread({}, answer), {}, {
278
- marks: (answer.marks || []).filter(function (mark) {
279
- return mark.type !== tool;
280
- })
281
- });
215
+ (0, _defineProperty2.default)(this, "filterMarks", tool => {
216
+ const {
217
+ model: {
218
+ answers
219
+ }
220
+ } = this.props;
221
+ return Object.entries(answers || {}).reduce((object, [key, answer]) => {
222
+ object[key] = {
223
+ ...answer,
224
+ marks: (answer.marks || []).filter(mark => mark.type !== tool)
225
+ };
282
226
  return object;
283
227
  }, {});
284
228
  });
285
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "changeToolbarTools", function (toolbarTools) {
286
- var _this$props2 = _this.props,
287
- model = _this$props2.model,
288
- onChange = _this$props2.onChange;
229
+ (0, _defineProperty2.default)(this, "changeToolbarTools", toolbarTools => {
230
+ const {
231
+ model,
232
+ onChange
233
+ } = this.props;
289
234
  model.toolbarTools = toolbarTools;
290
235
  onChange(model);
291
236
  });
292
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "updateModel", function (props) {
293
- var _this$props3 = _this.props,
294
- model = _this$props3.model,
295
- onChange = _this$props3.onChange;
296
- onChange(_objectSpread(_objectSpread({}, model), props));
297
- });
298
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "toggleToolBarTool", function (tool) {
299
- var _this$props$model = _this.props.model,
300
- defaultTool = _this$props$model.defaultTool,
301
- toolbarTools = _this$props$model.toolbarTools,
302
- _this$props$model$ans = _this$props$model.answers,
303
- answers = _this$props$model$ans === void 0 ? {} : _this$props$model$ans;
304
- var updatedToolbarTools = (0, _toConsumableArray2["default"])(toolbarTools);
305
- var newDefaultTool = defaultTool;
306
- var index = toolbarTools.findIndex(function (t) {
307
- return tool === t;
237
+ (0, _defineProperty2.default)(this, "updateModel", props => {
238
+ const {
239
+ model,
240
+ onChange
241
+ } = this.props;
242
+ onChange({
243
+ ...model,
244
+ ...props
308
245
  });
309
-
246
+ });
247
+ (0, _defineProperty2.default)(this, "toggleToolBarTool", tool => {
248
+ const {
249
+ model: {
250
+ defaultTool,
251
+ toolbarTools,
252
+ answers = {}
253
+ }
254
+ } = this.props;
255
+ const updatedToolbarTools = [...toolbarTools];
256
+ let newDefaultTool = defaultTool;
257
+ const index = toolbarTools.findIndex(t => tool === t);
310
258
  if (index >= 0) {
311
- var updatedAnswers = _this.filterMarks(tool);
312
-
259
+ const updatedAnswers = this.filterMarks(tool);
313
260
  updatedToolbarTools.splice(index, 1);
314
-
315
261
  if (tool === defaultTool) {
316
- var toolbarToolsNoLabel = (updatedToolbarTools || []).filter(function (tool) {
317
- return tool !== 'label';
318
- });
262
+ const toolbarToolsNoLabel = (updatedToolbarTools || []).filter(tool => tool !== 'label');
319
263
  newDefaultTool = toolbarToolsNoLabel.length && toolbarToolsNoLabel[0] || '';
320
264
  }
321
-
322
265
  if (!(0, _lodash.isEqual)(answers, updatedAnswers)) {
323
- _this.setState({
266
+ this.setState({
324
267
  dialog: {
325
268
  open: true,
326
269
  title: 'Warning',
327
- text: "Correct answer includes one or more ".concat(tool, " objects and all of them will be deleted."),
328
- onConfirm: function onConfirm() {
329
- return _this.handleAlertDialog(false, _this.updateModel({
330
- toolbarTools: updatedToolbarTools,
331
- answers: updatedAnswers,
332
- defaultTool: newDefaultTool
333
- }));
334
- },
335
- onClose: function onClose() {
336
- return _this.handleAlertDialog(false);
337
- }
270
+ text: `Correct answer includes one or more ${tool} objects and all of them will be deleted.`,
271
+ onConfirm: () => this.handleAlertDialog(false, this.updateModel({
272
+ toolbarTools: updatedToolbarTools,
273
+ answers: updatedAnswers,
274
+ defaultTool: newDefaultTool
275
+ })),
276
+ onClose: () => this.handleAlertDialog(false)
338
277
  }
339
278
  });
340
-
341
279
  return;
342
280
  }
343
281
  } else {
344
282
  updatedToolbarTools.push(tool);
345
-
346
283
  if (defaultTool === '' && tool !== 'label') {
347
284
  newDefaultTool = tool;
348
285
  }
349
286
  }
350
-
351
- _this.updateModel({
287
+ this.updateModel({
352
288
  toolbarTools: updatedToolbarTools,
353
289
  defaultTool: newDefaultTool
354
290
  });
355
291
  });
356
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "onDefaultToolChange", function (event) {
357
- var value = event.target.value;
358
-
359
- _this.updateModel({
292
+ (0, _defineProperty2.default)(this, "onDefaultToolChange", event => {
293
+ const {
294
+ value
295
+ } = event.target;
296
+ this.updateModel({
360
297
  defaultTool: value
361
298
  });
362
299
  });
363
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "addAlternateResponse", function () {
364
- var _this$props4 = _this.props,
365
- model = _this$props4.model,
366
- onChange = _this$props4.onChange;
367
-
368
- var _ref4 = model || {},
369
- answers = _ref4.answers;
370
-
371
- var answersKeys = Object.keys(answers || {});
372
- (0, _lodash.set)(model, "answers.".concat("alternate".concat(answersKeys.length)), {
373
- name: "Alternate ".concat(answersKeys.length),
300
+ (0, _defineProperty2.default)(this, "addAlternateResponse", () => {
301
+ const {
302
+ model,
303
+ onChange
304
+ } = this.props;
305
+ const {
306
+ answers
307
+ } = model || {};
308
+ const answersKeys = Object.keys(answers || {});
309
+ (0, _lodash.set)(model, `answers.${`alternate${answersKeys.length}`}`, {
310
+ name: `Alternate ${answersKeys.length}`,
374
311
  marks: []
375
312
  });
376
313
  onChange(model);
377
314
  });
378
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "deleteAlternateResponse", function (answerKey, answer) {
379
- var _this$props5 = _this.props,
380
- model = _this$props5.model,
381
- onChange = _this$props5.onChange;
382
-
383
- var _ref5 = model || {},
384
- answers = _ref5.answers;
385
-
386
- var _ref6 = answer || {},
387
- _ref6$marks = _ref6.marks,
388
- marks = _ref6$marks === void 0 ? [] : _ref6$marks,
389
- name = _ref6.name;
390
-
391
- var deleteAnswer = function deleteAnswer() {
392
- delete answers[answerKey]; // rebuild answers based on new alternate positions after deletion
393
-
394
- var newAnswers = Object.entries(answers).reduce(function (acc, currentValue, index) {
395
- var _currentValue = (0, _slicedToArray2["default"])(currentValue, 2),
396
- key = _currentValue[0],
397
- value = _currentValue[1];
398
-
399
- var newAnswer = key === 'correctAnswer' ? _objectSpread(_objectSpread({}, acc), {}, (0, _defineProperty2["default"])({}, key, value)) : _objectSpread(_objectSpread({}, acc), {}, (0, _defineProperty2["default"])({}, 'alternate' + index, _objectSpread(_objectSpread({}, value), {}, {
400
- name: "Alternate ".concat(index)
401
- })));
315
+ (0, _defineProperty2.default)(this, "deleteAlternateResponse", (answerKey, answer) => {
316
+ const {
317
+ model,
318
+ onChange
319
+ } = this.props;
320
+ const {
321
+ answers
322
+ } = model || {};
323
+ const {
324
+ marks = [],
325
+ name
326
+ } = answer || {};
327
+ const deleteAnswer = () => {
328
+ delete answers[answerKey];
329
+ // rebuild answers based on new alternate positions after deletion
330
+ const newAnswers = Object.entries(answers).reduce((acc, currentValue, index) => {
331
+ const [key, value] = currentValue;
332
+ const newAnswer = key === 'correctAnswer' ? {
333
+ ...acc,
334
+ [key]: value
335
+ } : {
336
+ ...acc,
337
+ ['alternate' + index]: {
338
+ ...value,
339
+ name: `Alternate ${index}`
340
+ }
341
+ };
402
342
  return newAnswer;
403
343
  }, {});
404
- onChange(_objectSpread(_objectSpread({}, model), {}, {
344
+ onChange({
345
+ ...model,
405
346
  answers: newAnswers
406
- }));
347
+ });
407
348
  };
408
-
409
349
  if (marks.length) {
410
- _this.setState({
350
+ this.setState({
411
351
  dialog: {
412
352
  open: true,
413
353
  title: 'Warning',
414
- text: "".concat(name, " includes one or more shapes and the entire response will be deleted."),
415
- onConfirm: function onConfirm() {
416
- return _this.handleAlertDialog(false, deleteAnswer);
417
- },
418
- onClose: function onClose() {
419
- return _this.handleAlertDialog(false);
420
- }
354
+ text: `${name} includes one or more shapes and the entire response will be deleted.`,
355
+ onConfirm: () => this.handleAlertDialog(false, deleteAnswer),
356
+ onClose: () => this.handleAlertDialog(false)
421
357
  }
422
358
  });
423
-
424
359
  return;
425
360
  }
426
-
427
361
  deleteAnswer();
428
362
  });
429
- return _this;
430
363
  }
431
-
432
- (0, _createClass2["default"])(CorrectResponse, [{
433
- key: "componentDidMount",
434
- value: function componentDidMount() {
435
- try {
436
- // eslint-disable-next-line react/no-find-dom-node
437
- var domNode = _reactDom["default"].findDOMNode(this);
438
-
439
- (0, _mathRendering.renderMath)(domNode);
440
- } catch (e) {
441
- // Added try-catch block to handle "Unable to find node on an unmounted component" error from tests, thrown because of the usage of shallow
442
- console.error('DOM not mounted');
443
- }
364
+ componentDidMount() {
365
+ try {
366
+ // eslint-disable-next-line react/no-find-dom-node
367
+ const domNode = _reactDom.default.findDOMNode(this);
368
+ (0, _mathRendering.renderMath)(domNode);
369
+ } catch (e) {
370
+ // Added try-catch block to handle "Unable to find node on an unmounted component" error from tests, thrown because of the usage of shallow
371
+ console.error('DOM not mounted');
444
372
  }
445
- }, {
446
- key: "render",
447
- value: function render() {
448
- var _this2 = this;
449
-
450
- var _this$props6 = this.props,
451
- availableTools = _this$props6.availableTools,
452
- classes = _this$props6.classes,
453
- errors = _this$props6.errors,
454
- model = _this$props6.model,
455
- _this$props6$mathMlOp = _this$props6.mathMlOptions,
456
- mathMlOptions = _this$props6$mathMlOp === void 0 ? {} : _this$props6$mathMlOp,
457
- removeIncompleteTool = _this$props6.removeIncompleteTool;
458
- var dialog = this.state.dialog;
459
-
460
- var _ref7 = model || {},
461
- _ref7$answers = _ref7.answers,
462
- answers = _ref7$answers === void 0 ? {} : _ref7$answers,
463
- arrows = _ref7.arrows,
464
- backgroundMarks = _ref7.backgroundMarks,
465
- coordinatesOnHover = _ref7.coordinatesOnHover,
466
- defaultTool = _ref7.defaultTool,
467
- domain = _ref7.domain,
468
- _ref7$graph = _ref7.graph,
469
- graph = _ref7$graph === void 0 ? {} : _ref7$graph,
470
- labels = _ref7.labels,
471
- labelsEnabled = _ref7.labelsEnabled,
472
- range = _ref7.range,
473
- title = _ref7.title,
474
- titleEnabled = _ref7.titleEnabled,
475
- toolbarTools = _ref7.toolbarTools;
476
-
477
- var _ref8 = errors || {},
478
- _ref8$correctAnswerEr = _ref8.correctAnswerErrors,
479
- correctAnswerErrors = _ref8$correctAnswerEr === void 0 ? {} : _ref8$correctAnswerEr,
480
- toolbarToolsError = _ref8.toolbarToolsError;
481
-
482
- return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(_core.Typography, {
483
- component: "div",
484
- variant: "subheading"
485
- }, "Define Tool Set and Correct Response"), /*#__PURE__*/React.createElement(_core.Typography, {
486
- component: "div",
487
- variant: "body1",
488
- className: classes.subtitleText
489
- }, "Use this interface to choose which graphing tools students will be able to use, and to define the correct answer"), /*#__PURE__*/React.createElement(Tools, {
490
- classes: classes,
491
- availableTools: availableTools,
492
- defaultTool: defaultTool,
493
- hasErrors: !!toolbarToolsError,
494
- onDefaultToolChange: this.onDefaultToolChange,
495
- toggleToolBarTool: this.toggleToolBarTool,
496
- toolbarTools: toolbarTools
497
- }), toolbarToolsError && /*#__PURE__*/React.createElement("div", {
498
- className: classes.errorMessage
499
- }, toolbarToolsError), Object.entries(answers || {}).map(function (_ref9) {
500
- var _ref10 = (0, _slicedToArray2["default"])(_ref9, 2),
501
- key = _ref10[0],
502
- answer = _ref10[1];
503
-
504
- var _ref11 = answer || {},
505
- _ref11$marks = _ref11.marks,
506
- marks = _ref11$marks === void 0 ? [] : _ref11$marks,
507
- name = _ref11.name;
508
-
509
- return /*#__PURE__*/React.createElement(React.Fragment, {
510
- key: "correct-response-graph-".concat(name)
511
- }, /*#__PURE__*/React.createElement("div", {
512
- className: classes.responseTitle
513
- }, /*#__PURE__*/React.createElement("div", {
514
- className: classes.name
515
- }, name), key === 'correctAnswer' && /*#__PURE__*/React.createElement(_core.Tooltip, {
516
- classes: {
517
- tooltip: classes.tooltip
518
- },
519
- disableFocusListener: true,
520
- disableTouchListener: true,
521
- placement: 'right',
522
- title: 'At least 1 graph object should be defined.'
523
- }, /*#__PURE__*/React.createElement(_Info["default"], {
524
- fontSize: 'small',
525
- color: 'primary',
526
- style: {
527
- marginLeft: '8px',
528
- marginBottom: 'auto'
529
- }
530
- })), key !== 'correctAnswer' && /*#__PURE__*/React.createElement(_Delete["default"], {
531
- className: classes.iconButton,
532
- onClick: function onClick() {
533
- return _this2.deleteAlternateResponse(key, answer);
534
- }
535
- })), /*#__PURE__*/React.createElement(_graphing.GraphContainer, {
536
- className: correctAnswerErrors[key] && classes.graphError,
537
- axesSettings: {
538
- includeArrows: arrows
539
- },
540
- backgroundMarks: backgroundMarks.filter(function (mark) {
541
- return !mark.building;
542
- }),
543
- coordinatesOnHover: coordinatesOnHover,
544
- disabledLabels: true,
545
- disabledTitle: true,
546
- domain: domain,
547
- draggableTools: key === 'correctAnswer',
548
- labels: labels,
549
- marks: marks,
550
- onChangeMarks: function onChangeMarks(newMarks) {
551
- return _this2.changeMarks(key, newMarks);
552
- },
553
- range: range,
554
- showLabels: labelsEnabled,
555
- showTitle: titleEnabled,
556
- size: {
557
- width: graph.width,
558
- height: graph.height
559
- },
560
- title: title,
561
- toolbarTools: toolbarTools,
562
- onChangeTools: function onChangeTools(toolbarTools) {
563
- return _this2.updateModel({
564
- toolbarTools: toolbarTools
565
- });
566
- },
567
- mathMlOptions: mathMlOptions,
568
- removeIncompleteTool: removeIncompleteTool,
569
- limitLabeling: true
570
- }), correctAnswerErrors[key] && /*#__PURE__*/React.createElement("div", {
571
- className: classes.errorMessage
572
- }, correctAnswerErrors[key]));
573
- }), /*#__PURE__*/React.createElement("div", {
574
- className: classes.button,
575
- onClick: this.addAlternateResponse
576
- }, "ADD ALTERNATE"), /*#__PURE__*/React.createElement(_configUi.AlertDialog, {
577
- open: dialog.open,
578
- title: dialog.title,
579
- text: dialog.text,
580
- onClose: dialog.onClose,
581
- onConfirm: dialog.onConfirm
582
- }));
583
- }
584
- }]);
585
- return CorrectResponse;
586
- }(React.Component);
587
-
373
+ }
374
+ render() {
375
+ const {
376
+ availableTools,
377
+ errors,
378
+ model,
379
+ mathMlOptions = {},
380
+ removeIncompleteTool
381
+ } = this.props;
382
+ const {
383
+ dialog
384
+ } = this.state;
385
+ const {
386
+ answers = {},
387
+ arrows,
388
+ backgroundMarks,
389
+ coordinatesOnHover,
390
+ defaultTool,
391
+ domain,
392
+ graph = {},
393
+ labels,
394
+ labelsEnabled,
395
+ range,
396
+ title,
397
+ titleEnabled,
398
+ toolbarTools
399
+ } = model || {};
400
+ const {
401
+ correctAnswerErrors = {},
402
+ toolbarToolsError
403
+ } = errors || {};
404
+ return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(_material.Typography, {
405
+ component: "div",
406
+ variant: "h6"
407
+ }, "Define Tool Set and Correct Response"), /*#__PURE__*/React.createElement(SubtitleText, {
408
+ component: "div",
409
+ variant: "body1"
410
+ }, "Use this interface to choose which graphing tools students will be able to use, and to define the correct answer"), /*#__PURE__*/React.createElement(Tools, {
411
+ availableTools: availableTools,
412
+ defaultTool: defaultTool,
413
+ hasErrors: !!toolbarToolsError,
414
+ onDefaultToolChange: this.onDefaultToolChange,
415
+ toggleToolBarTool: this.toggleToolBarTool,
416
+ toolbarTools: toolbarTools
417
+ }), toolbarToolsError && /*#__PURE__*/React.createElement(ErrorMessage, null, toolbarToolsError), Object.entries(answers || {}).map(([key, answer]) => {
418
+ const {
419
+ marks = [],
420
+ name
421
+ } = answer || {};
422
+ return /*#__PURE__*/React.createElement(React.Fragment, {
423
+ key: `correct-response-graph-${name}`
424
+ }, /*#__PURE__*/React.createElement(ResponseTitle, null, /*#__PURE__*/React.createElement(Name, null, name), key === 'correctAnswer' && /*#__PURE__*/React.createElement(StyledTooltip, {
425
+ disableFocusListener: true,
426
+ disableTouchListener: true,
427
+ placement: 'right',
428
+ title: 'At least 1 graph object should be defined.'
429
+ }, /*#__PURE__*/React.createElement(_Info.default, {
430
+ fontSize: 'small',
431
+ color: 'primary',
432
+ style: {
433
+ marginLeft: '8px',
434
+ marginBottom: 'auto'
435
+ }
436
+ })), key !== 'correctAnswer' && /*#__PURE__*/React.createElement(IconButton, {
437
+ onClick: () => this.deleteAlternateResponse(key, answer)
438
+ }, /*#__PURE__*/React.createElement(_Delete.default, null))), /*#__PURE__*/React.createElement(_graphing.GraphContainer, {
439
+ style: correctAnswerErrors[key] && {
440
+ border: '2px solid red'
441
+ },
442
+ axesSettings: {
443
+ includeArrows: arrows
444
+ },
445
+ backgroundMarks: backgroundMarks.filter(mark => !mark.building),
446
+ coordinatesOnHover: coordinatesOnHover,
447
+ disabledLabels: true,
448
+ disabledTitle: true,
449
+ domain: domain,
450
+ draggableTools: key === 'correctAnswer',
451
+ labels: labels,
452
+ marks: marks,
453
+ onChangeMarks: newMarks => this.changeMarks(key, newMarks),
454
+ range: range,
455
+ showLabels: labelsEnabled,
456
+ showTitle: titleEnabled,
457
+ size: {
458
+ width: graph.width,
459
+ height: graph.height
460
+ },
461
+ title: title,
462
+ toolbarTools: toolbarTools,
463
+ onChangeTools: toolbarTools => this.updateModel({
464
+ toolbarTools
465
+ }),
466
+ mathMlOptions: mathMlOptions,
467
+ removeIncompleteTool: removeIncompleteTool,
468
+ limitLabeling: true
469
+ }), correctAnswerErrors[key] && /*#__PURE__*/React.createElement(ErrorMessage, null, correctAnswerErrors[key]));
470
+ }), /*#__PURE__*/React.createElement(Button, {
471
+ onClick: this.addAlternateResponse
472
+ }, "ADD ALTERNATE"), /*#__PURE__*/React.createElement(_configUi.AlertDialog, {
473
+ open: dialog.open,
474
+ title: dialog.title,
475
+ text: dialog.text,
476
+ onClose: dialog.onClose,
477
+ onConfirm: dialog.onConfirm
478
+ }));
479
+ }
480
+ }
588
481
  exports.CorrectResponse = CorrectResponse;
589
- (0, _defineProperty2["default"])(CorrectResponse, "propTypes", {
590
- availableTools: _propTypes["default"].array,
591
- classes: _propTypes["default"].object.isRequired,
592
- errors: _propTypes["default"].object,
593
- model: _propTypes["default"].object.isRequired,
594
- onChange: _propTypes["default"].func.isRequired,
595
- toolbarTools: _propTypes["default"].arrayOf(_propTypes["default"].String)
482
+ (0, _defineProperty2.default)(CorrectResponse, "propTypes", {
483
+ availableTools: _propTypes.default.array,
484
+ errors: _propTypes.default.object,
485
+ model: _propTypes.default.object.isRequired,
486
+ onChange: _propTypes.default.func.isRequired,
487
+ toolbarTools: _propTypes.default.arrayOf(_propTypes.default.String)
596
488
  });
597
-
598
- var _default = (0, _styles.withStyles)(styles)(CorrectResponse);
599
-
600
- exports["default"] = _default;
489
+ var _default = exports.default = CorrectResponse;
601
490
  //# sourceMappingURL=correct-response.js.map