@pie-element/hotspot 5.4.3-next.5 → 5.4.3-next.57

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 (64) hide show
  1. package/configure/lib/button.js.map +1 -1
  2. package/configure/lib/defaults.js.map +1 -1
  3. package/configure/lib/hotspot-container.js.map +1 -1
  4. package/configure/lib/hotspot-drawable.js.map +1 -1
  5. package/configure/lib/hotspot-palette.js.map +1 -1
  6. package/configure/lib/hotspot-polygon.js.map +1 -1
  7. package/configure/lib/hotspot-rectangle.js.map +1 -1
  8. package/configure/lib/index.js.map +1 -1
  9. package/configure/lib/root.js +1 -1
  10. package/configure/lib/root.js.map +1 -1
  11. package/configure/lib/upload-control.js.map +1 -1
  12. package/configure/lib/utils.js.map +1 -1
  13. package/configure/package.json +2 -2
  14. package/configure/src/__tests__/hotspot-container.test.js +98 -71
  15. package/configure/src/__tests__/hotspot-drawable.test.js +48 -49
  16. package/configure/src/__tests__/index.test.js +28 -51
  17. package/configure/src/__tests__/root.test.js +162 -82
  18. package/configure/src/__tests__/utils.test.js +112 -98
  19. package/configure/src/button.jsx +4 -4
  20. package/configure/src/defaults.js +16 -20
  21. package/configure/src/hotspot-container.jsx +72 -89
  22. package/configure/src/hotspot-drawable.jsx +55 -55
  23. package/configure/src/hotspot-palette.jsx +12 -25
  24. package/configure/src/hotspot-polygon.jsx +20 -22
  25. package/configure/src/hotspot-rectangle.jsx +5 -15
  26. package/configure/src/index.js +20 -20
  27. package/configure/src/root.jsx +38 -67
  28. package/configure/src/upload-control.jsx +9 -20
  29. package/configure/src/utils.js +35 -28
  30. package/controller/lib/defaults.js.map +1 -1
  31. package/controller/lib/index.js.map +1 -1
  32. package/controller/lib/utils.js.map +1 -1
  33. package/controller/package.json +1 -1
  34. package/controller/src/__tests__/index.test.js +29 -50
  35. package/controller/src/defaults.js +4 -8
  36. package/controller/src/index.js +22 -34
  37. package/controller/src/utils.js +9 -6
  38. package/docs/config-schema.json.md +1 -1
  39. package/docs/demo/config.js +2 -2
  40. package/docs/demo/generate.js +49 -37
  41. package/docs/demo/session.js +2 -2
  42. package/docs/pie-schema.json.md +1 -1
  43. package/lib/hotspot/container.js.map +1 -1
  44. package/lib/hotspot/icons.js.map +1 -1
  45. package/lib/hotspot/image.js.map +1 -1
  46. package/lib/hotspot/index.js.map +1 -1
  47. package/lib/hotspot/polygon.js.map +1 -1
  48. package/lib/hotspot/rectangle.js.map +1 -1
  49. package/lib/index.js.map +1 -1
  50. package/lib/session-updater.js.map +1 -1
  51. package/package.json +6 -6
  52. package/src/__tests__/container.test.jsx +57 -43
  53. package/src/__tests__/image.test.jsx +2 -2
  54. package/src/__tests__/polygon.test.jsx +31 -20
  55. package/src/__tests__/rectangle.test.jsx +22 -18
  56. package/src/__tests__/session-updater.test.jsx +22 -31
  57. package/src/hotspot/container.jsx +20 -23
  58. package/src/hotspot/icons.js +4 -2
  59. package/src/hotspot/image.jsx +4 -8
  60. package/src/hotspot/index.jsx +27 -47
  61. package/src/hotspot/polygon.jsx +13 -18
  62. package/src/hotspot/rectangle.jsx +11 -16
  63. package/src/index.js +5 -18
  64. package/src/session-updater.js +1 -1
@@ -7,7 +7,7 @@ class ImageComponent extends React.Component {
7
7
  super(props);
8
8
  this.state = {
9
9
  image: null,
10
- showTooltip: false
10
+ showTooltip: false,
11
11
  };
12
12
  }
13
13
 
@@ -35,7 +35,7 @@ class ImageComponent extends React.Component {
35
35
 
36
36
  handleLoad = () => {
37
37
  this.setState({
38
- image: this.image
38
+ image: this.image,
39
39
  });
40
40
  };
41
41
 
@@ -57,11 +57,7 @@ class ImageComponent extends React.Component {
57
57
 
58
58
  {showTooltip && tooltip && (
59
59
  <Label x={x - 30} y={y + 25}>
60
- <Tag
61
- fill="white"
62
- cornerRadius={5}
63
- opacity={0.9}
64
- />
60
+ <Tag fill="white" cornerRadius={5} opacity={0.9} />
65
61
  <Text text={tooltip} padding={5} />
66
62
  </Label>
67
63
  )}
@@ -74,7 +70,7 @@ ImageComponent.propTypes = {
74
70
  src: PropTypes.string.isRequired,
75
71
  x: PropTypes.number.isRequired,
76
72
  y: PropTypes.number.isRequired,
77
- tooltip: PropTypes.string
73
+ tooltip: PropTypes.string,
78
74
  };
79
75
 
80
76
  export default ImageComponent;
@@ -2,7 +2,7 @@ import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
3
  import Typography from '@material-ui/core/Typography';
4
4
  import CorrectAnswerToggle from '@pie-lib/correct-answer-toggle';
5
- import {Collapsible, hasText, PreviewPrompt} from '@pie-lib/render-ui';
5
+ import { Collapsible, hasText, PreviewPrompt } from '@pie-lib/render-ui';
6
6
  import { withStyles } from '@material-ui/core/styles';
7
7
 
8
8
  import Container from './container';
@@ -13,18 +13,15 @@ class HotspotComponent extends React.Component {
13
13
  this.state = {
14
14
  showCorrect: false,
15
15
  observer: null,
16
- scale: 1
16
+ scale: 1,
17
17
  };
18
18
  }
19
19
 
20
20
  componentDidMount() {
21
21
  this.observer = new MutationObserver((mutations) => {
22
22
  mutations.forEach(() => {
23
- const target = document.getElementById('question-container')?.style?.cssText
24
- const zoom = target?.substring(
25
- target.indexOf('--pie-zoom') + 11,
26
- target.lastIndexOf('%')
27
- );
23
+ const target = document.getElementById('question-container')?.style?.cssText;
24
+ const zoom = target?.substring(target.indexOf('--pie-zoom') + 11, target.lastIndexOf('%'));
28
25
 
29
26
  const zoomParsed = zoom?.replace(/\s/g, '');
30
27
  if (zoomParsed) {
@@ -32,7 +29,7 @@ class HotspotComponent extends React.Component {
32
29
  if (newScale !== this.state.scale) {
33
30
  this.setState({
34
31
  scale: parseFloat(zoomParsed) / 100,
35
- })
32
+ });
36
33
  }
37
34
  } else if (!zoomParsed && this.state.scale !== 1) {
38
35
  this.setState({
@@ -44,7 +41,7 @@ class HotspotComponent extends React.Component {
44
41
 
45
42
  const target = document.getElementById('question-container');
46
43
  if (target) {
47
- this.observer.observe(target, { attributes : true, attributeFilter : ['style'] })
44
+ this.observer.observe(target, { attributes: true, attributeFilter: ['style'] });
48
45
  }
49
46
  }
50
47
 
@@ -73,10 +70,10 @@ class HotspotComponent extends React.Component {
73
70
  rationale,
74
71
  teacherInstructions,
75
72
  strokeWidth,
76
- responseCorrect
73
+ responseCorrect,
77
74
  },
78
75
  onSelectChoice,
79
- classes
76
+ classes,
80
77
  } = this.props;
81
78
  const { showCorrect } = this.state;
82
79
  const isEvaluateMode = mode === 'evaluate';
@@ -92,25 +89,17 @@ class HotspotComponent extends React.Component {
92
89
  />
93
90
  )}
94
91
  {showCorrectAnswerToggle && <br />}
95
- {
96
- teacherInstructions && hasText(teacherInstructions) && (
97
- <Collapsible
98
- labels={{ hidden: 'Show Teacher Instructions', visible: 'Hide Teacher Instructions' }}
99
- className={classes.collapsible}
100
- >
101
- <PreviewPrompt
102
- className="prompt"
103
- prompt={teacherInstructions}
104
- />
105
- </Collapsible>
106
- )
107
- }
92
+ {teacherInstructions && hasText(teacherInstructions) && (
93
+ <Collapsible
94
+ labels={{ hidden: 'Show Teacher Instructions', visible: 'Hide Teacher Instructions' }}
95
+ className={classes.collapsible}
96
+ >
97
+ <PreviewPrompt className="prompt" prompt={teacherInstructions} />
98
+ </Collapsible>
99
+ )}
108
100
 
109
101
  <Typography className={classes.prompt}>
110
- <PreviewPrompt
111
- className="prompt"
112
- prompt={prompt}
113
- />
102
+ <PreviewPrompt className="prompt" prompt={prompt} />
114
103
  </Typography>
115
104
 
116
105
  {imageUrl ? (
@@ -131,20 +120,11 @@ class HotspotComponent extends React.Component {
131
120
  />
132
121
  ) : null}
133
122
 
134
- {
135
- rationale && hasText(rationale) && (
136
- <Collapsible
137
- labels={{ hidden: 'Show Rationale', visible: 'Hide Rationale' }}
138
- className={classes.collapsible}
139
- >
140
- <PreviewPrompt
141
- className="prompt"
142
- prompt={rationale}
143
- />
144
- </Collapsible>
145
- )
146
- }
147
-
123
+ {rationale && hasText(rationale) && (
124
+ <Collapsible labels={{ hidden: 'Show Rationale', visible: 'Hide Rationale' }} className={classes.collapsible}>
125
+ <PreviewPrompt className="prompt" prompt={rationale} />
126
+ </Collapsible>
127
+ )}
148
128
  </div>
149
129
  );
150
130
  }
@@ -154,21 +134,21 @@ HotspotComponent.propTypes = {
154
134
  classes: PropTypes.object,
155
135
  model: PropTypes.object.isRequired,
156
136
  onSelectChoice: PropTypes.func.isRequired,
157
- session: PropTypes.object.isRequired
137
+ session: PropTypes.object.isRequired,
158
138
  };
159
139
 
160
140
  HotspotComponent.defaultProps = {
161
- classes: {}
141
+ classes: {},
162
142
  };
163
143
 
164
- const styles = theme => ({
144
+ const styles = (theme) => ({
165
145
  collapsible: {
166
146
  paddingTop: theme.spacing.unit * 2,
167
147
  paddingBottom: theme.spacing.unit * 2,
168
148
  },
169
149
  prompt: {
170
- fontSize: 'inherit'
171
- }
150
+ fontSize: 'inherit',
151
+ },
172
152
  });
173
153
 
174
154
  export default withStyles(styles)(HotspotComponent);
@@ -14,10 +14,10 @@ class PolygonComponent extends React.Component {
14
14
  getPolygonCenter = (points) => {
15
15
  const x = points.map(({ x }) => x);
16
16
  const y = points.map(({ y }) => y);
17
- const minX = Math.min.apply (null, x);
18
- const maxX = Math.max.apply (null, x);
19
- const minY = Math.min.apply (null, y);
20
- const maxY = Math.max.apply (null, y);
17
+ const minX = Math.min.apply(null, x);
18
+ const maxX = Math.max.apply(null, x);
19
+ const minY = Math.min.apply(null, y);
20
+ const maxY = Math.max.apply(null, y);
21
21
  return [(minX + maxX) / 2, (minY + maxY) / 2];
22
22
  };
23
23
 
@@ -51,9 +51,11 @@ class PolygonComponent extends React.Component {
51
51
  document.body.style.cursor = 'default';
52
52
  };
53
53
 
54
- getEvaluateOutlineColor = (isCorrect, markAsCorrect, outlineColor) => markAsCorrect ? 'green' : (isCorrect ? outlineColor : 'red')
54
+ getEvaluateOutlineColor = (isCorrect, markAsCorrect, outlineColor) =>
55
+ markAsCorrect ? 'green' : isCorrect ? outlineColor : 'red';
55
56
 
56
- getOutlineWidth = (showCorrectEnabled, selected, markAsCorrect, strokeWidth) => markAsCorrect || (!markAsCorrect && !showCorrectEnabled && selected) ? strokeWidth : 0;
57
+ getOutlineWidth = (showCorrectEnabled, selected, markAsCorrect, strokeWidth) =>
58
+ markAsCorrect || (!markAsCorrect && !showCorrectEnabled && selected) ? strokeWidth : 0;
57
59
 
58
60
  render() {
59
61
  const {
@@ -68,7 +70,7 @@ class PolygonComponent extends React.Component {
68
70
  strokeWidth,
69
71
  scale,
70
72
  markAsCorrect,
71
- showCorrectEnabled
73
+ showCorrectEnabled,
72
74
  } = this.props;
73
75
 
74
76
  const outlineColorParsed = isEvaluateMode
@@ -128,14 +130,7 @@ class PolygonComponent extends React.Component {
128
130
  onMouseLeave={this.handleMouseLeave}
129
131
  onMouseEnter={this.handleMouseEnter}
130
132
  />
131
- {(isEvaluateMode && iconSrc) ? (
132
- <Image
133
- src={iconSrc}
134
- x={iconX}
135
- y={iconY}
136
- tooltip={evaluateText}
137
- />
138
- ): null}
133
+ {isEvaluateMode && iconSrc ? <Image src={iconSrc} x={iconX} y={iconY} tooltip={evaluateText} /> : null}
139
134
  </Group>
140
135
  );
141
136
  }
@@ -145,7 +140,7 @@ const styles = () => ({
145
140
  base: {
146
141
  cursor: 'pointer',
147
142
  opacity: 0.5,
148
- position: 'relative'
143
+ position: 'relative',
149
144
  },
150
145
  });
151
146
 
@@ -164,13 +159,13 @@ PolygonComponent.propTypes = {
164
159
  strokeWidth: PropTypes.number,
165
160
  scale: PropTypes.number,
166
161
  markAsCorrect: PropTypes.bool.isRequired,
167
- showCorrectEnabled: PropTypes.bool.isRequired
162
+ showCorrectEnabled: PropTypes.bool.isRequired,
168
163
  };
169
164
 
170
165
  PolygonComponent.defaultProps = {
171
166
  evaluateText: null,
172
167
  strokeWidth: 5,
173
- scale: 1
168
+ scale: 1,
174
169
  };
175
170
 
176
171
  export default withStyles(styles)(PolygonComponent);
@@ -32,9 +32,11 @@ class RectComponent extends React.Component {
32
32
  document.body.style.cursor = 'default';
33
33
  };
34
34
 
35
- getEvaluateOutlineColor = (isCorrect, markAsCorrect, outlineColor) => markAsCorrect ? 'green' : (isCorrect ? outlineColor : 'red')
35
+ getEvaluateOutlineColor = (isCorrect, markAsCorrect, outlineColor) =>
36
+ markAsCorrect ? 'green' : isCorrect ? outlineColor : 'red';
36
37
 
37
- getOutlineWidth = (showCorrectEnabled, selected, markAsCorrect, strokeWidth) => markAsCorrect || (!markAsCorrect && !showCorrectEnabled && selected) ? strokeWidth : 0;
38
+ getOutlineWidth = (showCorrectEnabled, selected, markAsCorrect, strokeWidth) =>
39
+ markAsCorrect || (!markAsCorrect && !showCorrectEnabled && selected) ? strokeWidth : 0;
38
40
 
39
41
  render() {
40
42
  const {
@@ -52,7 +54,7 @@ class RectComponent extends React.Component {
52
54
  strokeWidth,
53
55
  scale,
54
56
  markAsCorrect,
55
- showCorrectEnabled
57
+ showCorrectEnabled,
56
58
  } = this.props;
57
59
 
58
60
  const outlineColorParsed = isEvaluateMode
@@ -61,8 +63,8 @@ class RectComponent extends React.Component {
61
63
 
62
64
  const outlineWidth = this.getOutlineWidth(showCorrectEnabled, selected, markAsCorrect, strokeWidth);
63
65
 
64
- const iconX = (x + (width / 2)) - 10;
65
- const iconY = (y + (height / 2)) - 10;
66
+ const iconX = x + width / 2 - 10;
67
+ const iconY = y + height / 2 - 10;
66
68
 
67
69
  // "Show Correct Answer" Enabled:
68
70
  // - Correctly Selected: white checkmark in green circle
@@ -113,14 +115,7 @@ class RectComponent extends React.Component {
113
115
  x={x}
114
116
  y={y}
115
117
  />
116
- {(isEvaluateMode && iconSrc) ? (
117
- <Image
118
- src={iconSrc}
119
- x={iconX}
120
- y={iconY}
121
- tooltip={evaluateText}
122
- />
123
- ): null}
118
+ {isEvaluateMode && iconSrc ? <Image src={iconSrc} x={iconX} y={iconY} tooltip={evaluateText} /> : null}
124
119
  </Group>
125
120
  );
126
121
  }
@@ -130,7 +125,7 @@ const styles = () => ({
130
125
  base: {
131
126
  cursor: 'pointer',
132
127
  opacity: 0.5,
133
- position: 'relative'
128
+ position: 'relative',
134
129
  },
135
130
  });
136
131
 
@@ -152,14 +147,14 @@ RectComponent.propTypes = {
152
147
  strokeWidth: PropTypes.number,
153
148
  scale: PropTypes.number,
154
149
  markAsCorrect: PropTypes.bool.isRequired,
155
- showCorrectEnabled: PropTypes.bool.isRequired
150
+ showCorrectEnabled: PropTypes.bool.isRequired,
156
151
  };
157
152
 
158
153
  RectComponent.defaultProps = {
159
154
  isCorrect: false,
160
155
  evaluateText: null,
161
156
  strokeWidth: 5,
162
- scale: 1
157
+ scale: 1,
163
158
  };
164
159
 
165
160
  export default withStyles(styles)(RectComponent);
package/src/index.js CHANGED
@@ -1,10 +1,7 @@
1
1
  import React from 'react';
2
2
  import ReactDOM from 'react-dom';
3
3
  import { renderMath } from '@pie-lib/math-rendering';
4
- import {
5
- SessionChangedEvent,
6
- ModelSetEvent
7
- } from '@pie-framework/pie-player-events';
4
+ import { SessionChangedEvent, ModelSetEvent } from '@pie-framework/pie-player-events';
8
5
 
9
6
  import HotspotComponent from './hotspot';
10
7
  import { updateSessionValue } from './session-updater';
@@ -13,13 +10,7 @@ export default class Hotspot extends HTMLElement {
13
10
  set model(m) {
14
11
  this._model = m;
15
12
 
16
- this.dispatchEvent(
17
- new ModelSetEvent(
18
- this.tagName.toLowerCase(),
19
- this.isComplete(),
20
- !!this._model
21
- )
22
- );
13
+ this.dispatchEvent(new ModelSetEvent(this.tagName.toLowerCase(), this.isComplete(), !!this._model));
23
14
  this._render();
24
15
  }
25
16
 
@@ -28,9 +19,7 @@ export default class Hotspot extends HTMLElement {
28
19
  return false;
29
20
  }
30
21
 
31
- return (
32
- Array.isArray(this._session.answers) && this._session.answers.length > 0
33
- );
22
+ return Array.isArray(this._session.answers) && this._session.answers.length > 0;
34
23
  }
35
24
 
36
25
  set session(s) {
@@ -49,9 +38,7 @@ export default class Hotspot extends HTMLElement {
49
38
  onSelectChoice(data) {
50
39
  updateSessionValue(this._session, this._model, data);
51
40
 
52
- this.dispatchEvent(
53
- new SessionChangedEvent(this.tagName.toLowerCase(), this.isComplete())
54
- );
41
+ this.dispatchEvent(new SessionChangedEvent(this.tagName.toLowerCase(), this.isComplete()));
55
42
 
56
43
  this._render();
57
44
  }
@@ -65,7 +52,7 @@ export default class Hotspot extends HTMLElement {
65
52
  const el = React.createElement(HotspotComponent, {
66
53
  model: this._model,
67
54
  session: this._session,
68
- onSelectChoice: this.onSelectChoice.bind(this)
55
+ onSelectChoice: this.onSelectChoice.bind(this),
69
56
  });
70
57
 
71
58
  ReactDOM.render(el, this, () => {
@@ -4,7 +4,7 @@ export function updateSessionValue(session, model, data) {
4
4
  session.answers = session.answers || [];
5
5
 
6
6
  if (!selected) {
7
- session.answers = session.answers.filter(answer => answer.id !== id);
7
+ session.answers = session.answers.filter((answer) => answer.id !== id);
8
8
  } else {
9
9
  const item = { id };
10
10
  if (multipleCorrect) {