@pie-element/hotspot 4.7.18-next.85 → 4.8.1-beta.587

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 (95) hide show
  1. package/CHANGELOG.md +485 -0
  2. package/configure/CHANGELOG.md +425 -0
  3. package/configure/lib/button.js.map +1 -1
  4. package/configure/lib/defaults.js +24 -2
  5. package/configure/lib/defaults.js.map +1 -1
  6. package/configure/lib/hotspot-container.js +44 -23
  7. package/configure/lib/hotspot-container.js.map +1 -1
  8. package/configure/lib/hotspot-drawable.js +11 -5
  9. package/configure/lib/hotspot-drawable.js.map +1 -1
  10. package/configure/lib/hotspot-palette.js +1 -1
  11. package/configure/lib/hotspot-palette.js.map +1 -1
  12. package/configure/lib/hotspot-polygon.js +1 -1
  13. package/configure/lib/hotspot-polygon.js.map +1 -1
  14. package/configure/lib/hotspot-rectangle.js +1 -1
  15. package/configure/lib/hotspot-rectangle.js.map +1 -1
  16. package/configure/lib/index.js +17 -3
  17. package/configure/lib/index.js.map +1 -1
  18. package/configure/lib/root.js +133 -27
  19. package/configure/lib/root.js.map +1 -1
  20. package/configure/lib/upload-control.js.map +1 -1
  21. package/configure/lib/utils.js +18 -4
  22. package/configure/lib/utils.js.map +1 -1
  23. package/configure/package.json +4 -4
  24. package/configure/src/__tests__/__snapshots__/hotspot-container.test.js.snap +2 -1
  25. package/configure/src/__tests__/__snapshots__/root.test.js.snap +56 -4
  26. package/configure/src/__tests__/hotspot-container.test.js +98 -71
  27. package/configure/src/__tests__/hotspot-drawable.test.js +48 -49
  28. package/configure/src/__tests__/index.test.js +28 -51
  29. package/configure/src/__tests__/root.test.js +162 -82
  30. package/configure/src/__tests__/utils.test.js +112 -98
  31. package/configure/src/button.jsx +4 -4
  32. package/configure/src/defaults.js +36 -18
  33. package/configure/src/hotspot-container.jsx +107 -97
  34. package/configure/src/hotspot-drawable.jsx +59 -53
  35. package/configure/src/hotspot-palette.jsx +12 -25
  36. package/configure/src/hotspot-polygon.jsx +20 -22
  37. package/configure/src/hotspot-rectangle.jsx +5 -15
  38. package/configure/src/index.js +32 -18
  39. package/configure/src/root.jsx +120 -51
  40. package/configure/src/upload-control.jsx +9 -20
  41. package/configure/src/utils.js +51 -22
  42. package/controller/CHANGELOG.md +72 -0
  43. package/controller/lib/defaults.js +2 -2
  44. package/controller/lib/defaults.js.map +1 -1
  45. package/controller/lib/index.js +57 -9
  46. package/controller/lib/index.js.map +1 -1
  47. package/controller/lib/utils.js.map +1 -1
  48. package/controller/package.json +2 -2
  49. package/controller/src/__tests__/index.test.js +99 -55
  50. package/controller/src/defaults.js +5 -9
  51. package/controller/src/index.js +58 -34
  52. package/controller/src/utils.js +9 -6
  53. package/docs/config-schema.json +217 -0
  54. package/docs/config-schema.json.md +169 -0
  55. package/docs/demo/config.js +2 -2
  56. package/docs/demo/generate.js +54 -35
  57. package/docs/demo/session.js +2 -2
  58. package/docs/pie-schema.json +59 -0
  59. package/docs/pie-schema.json.md +47 -0
  60. package/lib/hotspot/container.js +44 -7
  61. package/lib/hotspot/container.js.map +1 -1
  62. package/lib/hotspot/icons.js.map +1 -1
  63. package/lib/hotspot/image.js +35 -8
  64. package/lib/hotspot/image.js.map +1 -1
  65. package/lib/hotspot/index.js +72 -18
  66. package/lib/hotspot/index.js.map +1 -1
  67. package/lib/hotspot/polygon.js +51 -32
  68. package/lib/hotspot/polygon.js.map +1 -1
  69. package/lib/hotspot/rectangle.js +51 -32
  70. package/lib/hotspot/rectangle.js.map +1 -1
  71. package/lib/index.js +4 -1
  72. package/lib/index.js.map +1 -1
  73. package/lib/session-updater.js.map +1 -1
  74. package/package.json +7 -4
  75. package/src/__tests__/__snapshots__/{container-test.jsx.snap → container.test.jsx.snap} +8 -0
  76. package/src/__tests__/__snapshots__/image.test.jsx.snap +43 -0
  77. package/src/__tests__/__snapshots__/{polygon-test.jsx.snap → polygon.test.jsx.snap} +11 -0
  78. package/src/__tests__/__snapshots__/{rectangle-test.jsx.snap → rectangle.test.jsx.snap} +11 -0
  79. package/src/__tests__/container.test.jsx +214 -0
  80. package/src/__tests__/{image-test.jsx → image.test.jsx} +10 -2
  81. package/src/__tests__/polygon.test.jsx +235 -0
  82. package/src/__tests__/rectangle.test.jsx +237 -0
  83. package/src/__tests__/{session-updater-test.jsx → session-updater.test.jsx} +22 -31
  84. package/src/hotspot/container.jsx +60 -23
  85. package/src/hotspot/icons.js +4 -2
  86. package/src/hotspot/image.jsx +26 -13
  87. package/src/hotspot/index.jsx +73 -33
  88. package/src/hotspot/polygon.jsx +51 -40
  89. package/src/hotspot/rectangle.jsx +51 -40
  90. package/src/index.js +10 -18
  91. package/src/session-updater.js +1 -1
  92. package/src/__tests__/__snapshots__/image-test.jsx.snap +0 -21
  93. package/src/__tests__/container-test.jsx +0 -143
  94. package/src/__tests__/polygon-test.jsx +0 -76
  95. package/src/__tests__/rectangle-test.jsx +0 -77
@@ -4,36 +4,25 @@ import { withStyles } from '@material-ui/core/styles/index';
4
4
 
5
5
  import Button from './button';
6
6
 
7
- const UploadControl = ({
8
- classNameButton,
9
- classNameSection,
10
- classes,
11
- label,
12
- onInputClick,
13
- onUploadImage,
14
- setRef
15
- }) => (
7
+ const UploadControl = ({ classNameButton, classNameSection, classes, label, onInputClick, onUploadImage, setRef }) => (
16
8
  <div className={classNameSection}>
17
- <Button
18
- className={classNameButton}
19
- label={label}
20
- onClick={onInputClick}
21
- />
9
+ <Button className={classNameButton} label={label} onClick={onInputClick} />
22
10
  <input
23
11
  accept="image/*"
24
12
  className={classes.input}
25
13
  onChange={onUploadImage}
26
- ref={ref => { setRef(ref); }}
14
+ ref={(ref) => {
15
+ setRef(ref);
16
+ }}
27
17
  type="file"
28
18
  />
29
19
  </div>
30
20
  );
31
21
 
32
-
33
22
  const styles = () => ({
34
23
  input: {
35
- display: 'none'
36
- }
24
+ display: 'none',
25
+ },
37
26
  });
38
27
 
39
28
  UploadControl.propTypes = {
@@ -43,12 +32,12 @@ UploadControl.propTypes = {
43
32
  label: PropTypes.string.isRequired,
44
33
  onInputClick: PropTypes.func.isRequired,
45
34
  onUploadImage: PropTypes.func.isRequired,
46
- setRef: PropTypes.func.isRequired
35
+ setRef: PropTypes.func.isRequired,
47
36
  };
48
37
 
49
38
  UploadControl.defaultProps = {
50
39
  classNameButton: '',
51
- classNameSection: ''
40
+ classNameSection: '',
52
41
  };
53
42
 
54
43
  export default withStyles(styles)(UploadControl);
@@ -9,28 +9,29 @@ const updateImageDimensions = (initialDim, nextDim, keepAspectRatio, resizeType)
9
9
  // if we want to change image height => we update the width accordingly
10
10
  return {
11
11
  width: nextDim.height * imageAspectRatio,
12
- height: nextDim.height
13
- }
12
+ height: nextDim.height,
13
+ };
14
14
  }
15
15
 
16
16
  // if we want to change image width => we update the height accordingly
17
17
  return {
18
18
  width: nextDim.width,
19
- height: nextDim.width / imageAspectRatio
20
- }
19
+ height: nextDim.width / imageAspectRatio,
20
+ };
21
21
  }
22
22
 
23
23
  // if we don't want to keep aspect ratio, we just update both values
24
24
  return {
25
25
  width: nextDim.width,
26
- height: nextDim.height
27
- }
26
+ height: nextDim.height,
27
+ };
28
28
  };
29
29
 
30
30
  // referenceInitialValue = the initial value of the Stage
31
31
  // referenceNextValue = the next value of the Stage
32
32
  // currentValue = the value that has to be re-sized influenced by the changes that were made on the Stage
33
- const getDelta = (referenceInitialValue, referenceNextValue, currentValue) => (referenceNextValue / referenceInitialValue) * currentValue;
33
+ const getDelta = (referenceInitialValue, referenceNextValue, currentValue) =>
34
+ (referenceNextValue / referenceInitialValue) * currentValue;
34
35
 
35
36
  const getUpdatedRectangle = (initialDim, nextDim, shape) => ({
36
37
  ...shape,
@@ -42,17 +43,17 @@ const getUpdatedRectangle = (initialDim, nextDim, shape) => ({
42
43
 
43
44
  const getUpdatedPlygon = (initialDim, nextDim, shape) => ({
44
45
  ...shape,
45
- points: shape.points.map(point => ({
46
+ points: shape.points.map((point) => ({
46
47
  x: getDelta(initialDim.width, nextDim.width, point.x),
47
48
  y: getDelta(initialDim.height, nextDim.height, point.y),
48
- }))
49
+ })),
49
50
  });
50
51
 
51
52
  // initialDim = the initial dimensions: { width, height } of the Stage
52
53
  // nextDim = the next dimensions: { width, height } of the Stage
53
54
  // shapes = array of shapes that have to be re-sized and re-positioned
54
55
  const getUpdatedShapes = (initialDim, nextDim, shapes) => {
55
- return shapes.map(shape => {
56
+ return shapes.map((shape) => {
56
57
  if (shape.group === 'rectangles') {
57
58
  return getUpdatedRectangle(initialDim, nextDim, shape);
58
59
  }
@@ -75,16 +76,19 @@ const getAllShapes = (shapesMap) => {
75
76
  const shapesKeys = Object.keys(shapesMap);
76
77
 
77
78
  return shapesKeys.length
78
- ? shapesKeys.reduce((acc, currentShapeKey) =>
79
- acc.concat(
80
- shapesMap[currentShapeKey]
81
- ? shapesMap[currentShapeKey].map((shape, index) => ({
82
- ...shape,
83
- group: currentShapeKey,
84
- index: shape.index || acc.length + index
85
- }))
86
- : []),
87
- shapesArray)
79
+ ? shapesKeys.reduce(
80
+ (acc, currentShapeKey) =>
81
+ acc.concat(
82
+ shapesMap[currentShapeKey]
83
+ ? shapesMap[currentShapeKey].map((shape, index) => ({
84
+ ...shape,
85
+ group: currentShapeKey,
86
+ index: shape.index || acc.length + index,
87
+ }))
88
+ : [],
89
+ ),
90
+ shapesArray,
91
+ )
88
92
  : shapesArray;
89
93
  };
90
94
 
@@ -97,7 +101,7 @@ const groupShapes = (shapesArray) => {
97
101
  shapesArray = shapesArray || [];
98
102
  const shapesMap = {
99
103
  rectangles: [],
100
- polygons: []
104
+ polygons: [],
101
105
  };
102
106
 
103
107
  if (shapesArray.length) {
@@ -110,5 +114,30 @@ const groupShapes = (shapesArray) => {
110
114
  return cloneDeep(shapesMap);
111
115
  };
112
116
 
117
+ const generateValidationMessage = (config) => {
118
+ const { minShapes, maxShapes, maxSelections } = config;
119
+
120
+ const shapesMessage =
121
+ `\nThere should be at least ${minShapes} ` + (maxShapes ? `and at most ${maxShapes} ` : '') + 'shapes defined.';
122
+
123
+ const selectionsMessage =
124
+ `\nThere should be at least 1 ` +
125
+ (maxSelections ? `and at most ${maxSelections} ` : '') +
126
+ 'shape' +
127
+ (maxSelections ? 's' : '') +
128
+ ' selected.';
113
129
 
114
- export { updateImageDimensions, getUpdatedShapes, getAllShapes, groupShapes, getUpdatedRectangle, getUpdatedPlygon };
130
+ const message = 'Validation requirements:' + shapesMessage + selectionsMessage;
131
+
132
+ return message;
133
+ };
134
+
135
+ export {
136
+ updateImageDimensions,
137
+ generateValidationMessage,
138
+ getUpdatedShapes,
139
+ getAllShapes,
140
+ groupShapes,
141
+ getUpdatedRectangle,
142
+ getUpdatedPlygon,
143
+ };
@@ -3,6 +3,78 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [3.5.1](https://github.com/pie-framework/pie-elements/compare/@pie-element/hotspot-controller@3.5.0...@pie-element/hotspot-controller@3.5.1) (2022-12-07)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * update libs ([441f403](https://github.com/pie-framework/pie-elements/commit/441f403870b7bec0d61fab58b8d93dbe0ead4c32))
12
+
13
+
14
+
15
+
16
+
17
+ # [3.5.0](https://github.com/pie-framework/pie-elements/compare/@pie-element/hotspot-controller@3.4.8...@pie-element/hotspot-controller@3.5.0) (2022-05-03)
18
+
19
+
20
+ ### Features
21
+
22
+ * **hotspot:** added configurable validation PD-1702 ([18eb985](https://github.com/pie-framework/pie-elements/commit/18eb98568adf9248dc616a9ae71d9f8394b62fc1))
23
+ * **hotspot:** PD-1703 implement ui/ux for item validation ([a962183](https://github.com/pie-framework/pie-elements/commit/a962183d0941936b69a95b32002135507d769170))
24
+
25
+
26
+
27
+
28
+
29
+ ## [3.4.5](https://github.com/pie-framework/pie-elements/compare/@pie-element/hotspot-controller@3.4.3...@pie-element/hotspot-controller@3.4.5) (2021-11-11)
30
+
31
+ **Note:** Version bump only for package @pie-element/hotspot-controller
32
+
33
+
34
+
35
+
36
+
37
+ ## [3.4.4](https://github.com/pie-framework/pie-elements/compare/@pie-element/hotspot-controller@3.4.3...@pie-element/hotspot-controller@3.4.4) (2021-11-11)
38
+
39
+ **Note:** Version bump only for package @pie-element/hotspot-controller
40
+
41
+
42
+
43
+
44
+
45
+ ## [3.4.3](https://github.com/pie-framework/pie-elements/compare/@pie-element/hotspot-controller@3.4.1...@pie-element/hotspot-controller@3.4.3) (2021-08-05)
46
+
47
+
48
+ ### Bug Fixes
49
+
50
+ * force bump ([5ea7295](https://github.com/pie-framework/pie-elements/commit/5ea7295e4755fbc492a76e7ec69e5fc35b196919))
51
+
52
+
53
+
54
+
55
+
56
+ ## [3.4.1](https://github.com/pie-framework/pie-elements/compare/@pie-element/hotspot-controller@3.4.0...@pie-element/hotspot-controller@3.4.1) (2021-06-29)
57
+
58
+
59
+ ### Bug Fixes
60
+
61
+ * **hotspot:** partial scoring not working correctly PD-816 ([#583](https://github.com/pie-framework/pie-elements/issues/583)) ([8266134](https://github.com/pie-framework/pie-elements/commit/8266134bd0e298a89cbcbeb1f8ad16bb803e60ae))
62
+
63
+
64
+
65
+
66
+
67
+ # [3.4.0](https://github.com/pie-framework/pie-elements/compare/@pie-element/hotspot-controller@3.3.15...@pie-element/hotspot-controller@3.4.0) (2021-04-07)
68
+
69
+
70
+ ### Features
71
+
72
+ * merge pie-ui into pie-elements PD-977 ([01ebfd7](https://github.com/pie-framework/pie-elements/commit/01ebfd7ce98b041dd0573575efd8b6da03f22162))
73
+
74
+
75
+
76
+
77
+
6
78
  ## [3.3.15](https://github.com/pie-framework/pie-elements/compare/@pie-element/hotspot-controller@3.3.12...@pie-element/hotspot-controller@3.3.15) (2021-03-03)
7
79
 
8
80
  **Note:** Version bump only for package @pie-element/hotspot-controller
@@ -17,8 +17,8 @@ var _default = {
17
17
  height: 0,
18
18
  width: 0
19
19
  },
20
- hotspotColor: 'rgba(137, 183, 244, 0.65)',
21
- hotspotList: ['rgba(137, 183, 244, 0.65)'],
20
+ hotspotColor: 'rgba(137, 183, 244, 0.25)',
21
+ hotspotList: ['rgba(137, 183, 244, 0.25)'],
22
22
  outlineColor: 'blue',
23
23
  outlineList: ['blue']
24
24
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/defaults.js"],"names":["prompt","imageUrl","shapes","rectangles","polygons","multipleCorrect","partialScoring","dimensions","height","width","hotspotColor","hotspotList","outlineColor","outlineList"],"mappings":";;;;;;eAAe;AACbA,EAAAA,MAAM,EAAE,6BADK;AAEbC,EAAAA,QAAQ,EAAE,EAFG;AAGbC,EAAAA,MAAM,EAAE;AACNC,IAAAA,UAAU,EAAE,EADN;AAENC,IAAAA,QAAQ,EAAE;AAFJ,GAHK;AAObC,EAAAA,eAAe,EAAE,IAPJ;AAQbC,EAAAA,cAAc,EAAE,KARH;AASbC,EAAAA,UAAU,EAAE;AACVC,IAAAA,MAAM,EAAE,CADE;AAEVC,IAAAA,KAAK,EAAE;AAFG,GATC;AAabC,EAAAA,YAAY,EAAE,2BAbD;AAcbC,EAAAA,WAAW,EAAE,CACX,2BADW,CAdA;AAiBbC,EAAAA,YAAY,EAAE,MAjBD;AAkBbC,EAAAA,WAAW,EAAE,CACX,MADW;AAlBA,C","sourcesContent":["export default {\n prompt: 'This is the question prompt',\n imageUrl: '',\n shapes: {\n rectangles: [],\n polygons: []\n },\n multipleCorrect: true,\n partialScoring: false,\n dimensions: {\n height: 0,\n width: 0\n },\n hotspotColor: 'rgba(137, 183, 244, 0.65)',\n hotspotList: [\n 'rgba(137, 183, 244, 0.65)'\n ],\n outlineColor: 'blue',\n outlineList: [\n 'blue'\n ]\n};\n"],"file":"defaults.js"}
1
+ {"version":3,"sources":["../src/defaults.js"],"names":["prompt","imageUrl","shapes","rectangles","polygons","multipleCorrect","partialScoring","dimensions","height","width","hotspotColor","hotspotList","outlineColor","outlineList"],"mappings":";;;;;;eAAe;AACbA,EAAAA,MAAM,EAAE,6BADK;AAEbC,EAAAA,QAAQ,EAAE,EAFG;AAGbC,EAAAA,MAAM,EAAE;AACNC,IAAAA,UAAU,EAAE,EADN;AAENC,IAAAA,QAAQ,EAAE;AAFJ,GAHK;AAObC,EAAAA,eAAe,EAAE,IAPJ;AAQbC,EAAAA,cAAc,EAAE,KARH;AASbC,EAAAA,UAAU,EAAE;AACVC,IAAAA,MAAM,EAAE,CADE;AAEVC,IAAAA,KAAK,EAAE;AAFG,GATC;AAabC,EAAAA,YAAY,EAAE,2BAbD;AAcbC,EAAAA,WAAW,EAAE,CAAC,2BAAD,CAdA;AAebC,EAAAA,YAAY,EAAE,MAfD;AAgBbC,EAAAA,WAAW,EAAE,CAAC,MAAD;AAhBA,C","sourcesContent":["export default {\n prompt: 'This is the question prompt',\n imageUrl: '',\n shapes: {\n rectangles: [],\n polygons: [],\n },\n multipleCorrect: true,\n partialScoring: false,\n dimensions: {\n height: 0,\n width: 0,\n },\n hotspotColor: 'rgba(137, 183, 244, 0.25)',\n hotspotList: ['rgba(137, 183, 244, 0.25)'],\n outlineColor: 'blue',\n outlineList: ['blue'],\n};\n"],"file":"defaults.js"}
@@ -5,9 +5,11 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
+ exports.createDefaultModel = exports.createCorrectResponseSession = void 0;
8
9
  exports.model = model;
10
+ exports.normalize = void 0;
9
11
  exports.outcome = outcome;
10
- exports.createCorrectResponseSession = exports.createDefaultModel = exports.normalize = void 0;
12
+ exports.validate = void 0;
11
13
 
12
14
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
13
15
 
@@ -25,9 +27,12 @@ var _utils = require("./utils");
25
27
 
26
28
  var _defaults = _interopRequireDefault(require("./defaults"));
27
29
 
28
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
30
+ var _excluded = ["index"],
31
+ _excluded2 = ["index"];
29
32
 
30
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
33
+ 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; }
34
+
35
+ 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; }
31
36
 
32
37
  var log = (0, _debug["default"])('pie-elements:hotspot:controller');
33
38
 
@@ -72,13 +77,13 @@ function model(question, session, env) {
72
77
  // eslint-disable-next-line no-unused-vars
73
78
  rectangles: (rectangles || []).map(function (_ref2) {
74
79
  var index = _ref2.index,
75
- rectProps = (0, _objectWithoutProperties2["default"])(_ref2, ["index"]);
80
+ rectProps = (0, _objectWithoutProperties2["default"])(_ref2, _excluded);
76
81
  return _objectSpread({}, rectProps);
77
82
  }),
78
83
  // eslint-disable-next-line no-unused-vars
79
84
  polygons: (polygons || []).map(function (_ref3) {
80
85
  var index = _ref3.index,
81
- polyProps = (0, _objectWithoutProperties2["default"])(_ref3, ["index"]);
86
+ polyProps = (0, _objectWithoutProperties2["default"])(_ref3, _excluded2);
82
87
  return _objectSpread({}, polyProps);
83
88
  })
84
89
  }),
@@ -133,20 +138,29 @@ var getScore = function getScore(config, session) {
133
138
  }
134
139
 
135
140
  var correctAnswers = 0;
141
+ var selectedChoices = 0;
136
142
  var choices = [].concat((0, _toConsumableArray2["default"])(rectangles), (0, _toConsumableArray2["default"])(polygons));
143
+ var correctChoices = choices.filter(function (choice) {
144
+ return choice.correct;
145
+ });
137
146
  choices.forEach(function (shape) {
138
147
  var selected = answers && answers.filter(function (answer) {
139
148
  return answer.id === shape.id;
140
149
  })[0];
141
150
  var correctlySelected = shape.correct && selected;
142
- var correctlyUnselected = !shape.correct && !selected;
143
151
 
144
- if (correctlySelected || correctlyUnselected) {
152
+ if (selected) {
153
+ selectedChoices += 1;
154
+ }
155
+
156
+ if (correctlySelected) {
145
157
  correctAnswers += 1;
146
158
  }
147
159
  });
148
- var str = (correctAnswers / choices.length).toFixed(2);
149
- return parseFloat(str);
160
+ var extraAnswers = selectedChoices > correctChoices.length ? selectedChoices - correctChoices.length : 0;
161
+ var total = correctChoices.length === 0 ? 1 : correctChoices.length;
162
+ var str = ((correctAnswers - extraAnswers) / total).toFixed(2);
163
+ return str < 0 ? 0 : parseFloat(str);
150
164
  };
151
165
 
152
166
  function outcome(config, session) {
@@ -212,4 +226,38 @@ var createCorrectResponseSession = function createCorrectResponseSession(questio
212
226
  };
213
227
 
214
228
  exports.createCorrectResponseSession = createCorrectResponseSession;
229
+
230
+ var validate = function validate() {
231
+ var model = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
232
+ var config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
233
+ var shapes = model.shapes;
234
+ var _config$minShapes = config.minShapes,
235
+ minShapes = _config$minShapes === void 0 ? 2 : _config$minShapes,
236
+ maxShapes = config.maxShapes,
237
+ maxSelections = config.maxSelections;
238
+ var errors = {};
239
+ var allShapes = Object.values(shapes || {}).reduce(function (acc, shape) {
240
+ return [].concat((0, _toConsumableArray2["default"])(acc), (0, _toConsumableArray2["default"])(shape));
241
+ }, []);
242
+ var nbOfSelections = (allShapes || []).reduce(function (acc, shape) {
243
+ return shape.correct ? acc + 1 : acc;
244
+ }, 0);
245
+ var nbOfShapes = (allShapes || []).length;
246
+
247
+ if (nbOfShapes < minShapes) {
248
+ errors.shapesError = "There should be at least ".concat(minShapes, " shapes defined.");
249
+ } else if (nbOfShapes > maxShapes) {
250
+ errors.shapesError = "No more than ".concat(maxShapes, " shapes should be defined.");
251
+ }
252
+
253
+ if (nbOfSelections < 1) {
254
+ errors.selectionsError = 'There should be at least 1 shape selected.';
255
+ } else if (nbOfSelections > maxSelections) {
256
+ errors.selectionsError = "No more than ".concat(maxSelections, " shapes should be selected.");
257
+ }
258
+
259
+ return errors;
260
+ };
261
+
262
+ exports.validate = validate;
215
263
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.js"],"names":["log","normalize","question","promptEnabled","rationaleEnabled","teacherInstructionsEnabled","studentInstructionsEnabled","strokeWidth","model","session","env","normalizedQuestion","imageUrl","dimensions","hotspotColor","multipleCorrect","outlineColor","partialScoring","prompt","shapes","rectangles","polygons","Promise","resolve","out","disabled","mode","map","index","rectProps","polyProps","responseCorrect","undefined","role","rationale","teacherInstructions","createDefaultModel","defaults","getScore","config","answers","partialScoringEnabled","enabled","correctAnswers","choices","forEach","shape","selected","filter","answer","id","correctlySelected","correct","correctlyUnselected","str","length","toFixed","parseFloat","outcome","score","empty","returnShapesCorrect","i","push","createCorrectResponseSession","rectangleCorrect","polygonsCorrect"],"mappings":";;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AAEA;;AAEA;;;;;;AAEA,IAAMA,GAAG,GAAG,uBAAM,iCAAN,CAAZ;;AAEO,IAAMC,SAAS,GAAG,SAAZA,SAAY,CAAAC,QAAQ;AAAA;AAC/BC,IAAAA,aAAa,EA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MAAM,CAAC0B,OAAP,CAAe,UAAAiB,CAAC,EAAI;AAAA,QACVV,OADU,GACMU,CADN,CACVV,OADU;AAAA,QACDF,EADC,GACMY,CADN,CACDZ,EADC;;AAElB,QAAIE,OAAJ,EAAa;AACXZ,MAAAA,OAAO,CAACuB,IAAR,CAAa;AAAEb,QAAAA,EAAE,EAAFA;AAAF,OAAb;AACD;AACF,GALD;AAMA,SAAOV,OAAP;AACD,CAVD;;AAYO,IAAMwB,4BAA4B,GAAG,SAA/BA,4BAA+B,CAAC9D,QAAD,EAAWQ,GAAX,EAAmB;AAC7D,SAAO,IAAIY,OAAJ,CAAY,UAAAC,OAAO,EAAI;AAC5B,QAAIb,GAAG,CAACgB,IAAJ,KAAa,UAAb,IAA2BhB,GAAG,CAACuB,IAAJ,KAAa,YAA5C,EAA0D;AAAA,6BACI/B,QADJ,CAChDiB,MADgD;AAAA,uDACH,EADG;AAAA,mDACtCC,UADsC;AAAA,UACtCA,UADsC,sCACzB,EADyB;AAAA,mDACrBC,QADqB;AAAA,UACrBA,QADqB,sCACV,EADU;AAGxD,UAAM4C,gBAAgB,GAAGJ,mBAAmB,CAACzC,UAAD,CAA5C;AACA,UAAM8C,eAAe,GAAGL,mBAAmB,CAACxC,QAAD,CAA3C;AAEAE,MAAAA,OAAO,CAAC;AACNiB,QAAAA,OAAO,gDACFyB,gBADE,uCAEFC,eAFE,EADD;AAKNhB,QAAAA,EAAE,EAAE;AALE,OAAD,CAAP;AAOD,KAbD,MAaO;AACL3B,MAAAA,OAAO,CAAC,IAAD,CAAP;AACD;AACF,GAjBM,CAAP;AAkBD,CAnBM","sourcesContent":["import debug from 'debug';\nimport isEmpty from 'lodash/isEmpty';\nimport { partialScoring } from '@pie-lib/controller-utils';\n\nimport { isResponseCorrect } from './utils';\n\nimport defaults from './defaults';\n\nconst log = debug('pie-elements:hotspot:controller');\n\nexport const normalize = question => ({\n promptEnabled: true,\n rationaleEnabled: true,\n teacherInstructionsEnabled: true,\n studentInstructionsEnabled: true,\n strokeWidth: 5,\n ...question,\n});\n\nexport function model(question, session, env) {\n const normalizedQuestion = normalize(question);\n const {\n imageUrl,\n dimensions,\n hotspotColor,\n multipleCorrect,\n outlineColor,\n partialScoring,\n prompt,\n shapes\n } = normalizedQuestion;\n const { rectangles, polygons } = shapes || {};\n\n return new Promise(resolve => {\n const out = {\n disabled: env.mode !== 'gather',\n mode: env.mode,\n dimensions,\n imageUrl,\n outlineColor,\n hotspotColor,\n multipleCorrect,\n partialScoring,\n shapes: {\n ...shapes,\n // eslint-disable-next-line no-unused-vars\n rectangles: (rectangles || []).map(({ index, ...rectProps }) => ({ ...rectProps })),\n // eslint-disable-next-line no-unused-vars\n polygons: (polygons || []).map(({ index, ...polyProps }) => ({ ...polyProps }))\n },\n responseCorrect:\n env.mode === 'evaluate'\n ? isResponseCorrect(normalizedQuestion, session)\n : undefined\n };\n\n if (env.role === 'instructor' && (env.mode === 'view' || env.mode === 'evaluate')) {\n out.rationale = normalizedQuestion.rationaleEnabled ? normalizedQuestion.rationale : null;\n out.teacherInstructions = normalizedQuestion.teacherInstructionsEnabled ? normalizedQuestion.teacherInstructions : null;\n } else {\n out.rationale = null;\n out.teacherInstructions = null;\n }\n\n out.prompt = normalizedQuestion.promptEnabled ? prompt : null;\n out.strokeWidth = normalizedQuestion.strokeWidth;\n\n // console.log(out);\n resolve(out);\n });\n}\n\nexport const createDefaultModel = (model = {}) =>\n new Promise(resolve => {\n resolve({\n ...defaults,\n ...model,\n });\n });\n\nconst getScore = (config, session, env = {}) => {\n const { answers } = session || {};\n\n if (!config.shapes || (!config.shapes.rectangles && !config.shapes.polygons)) {\n return 0;\n }\n\n const { shapes: { rectangles = [], polygons = [] } = {} } = config;\n const partialScoringEnabled = partialScoring.enabled(config, env);\n\n if (!partialScoringEnabled) {\n return isResponseCorrect(config, session) ? 1 : 0;\n }\n\n let correctAnswers = 0;\n\n const choices = [...rectangles, ...polygons];\n\n choices.forEach(shape => {\n const selected = answers && answers.filter(answer => answer.id === shape.id)[0];\n const correctlySelected = shape.correct && selected;\n const correctlyUnselected = !shape.correct && !selected;\n\n if (correctlySelected || correctlyUnselected) {\n correctAnswers += 1;\n }\n });\n\n const str = (correctAnswers / choices.length).toFixed(2);\n return parseFloat(str);\n};\n\nexport function outcome(config, session, env = {}) {\n return new Promise(resolve => {\n log('outcome...');\n\n if (!session || isEmpty(session)) {\n resolve({ score: 0, empty: true });\n }\n\n if (session.answers) {\n const score = getScore(config, session, env);\n resolve({ score });\n } else {\n resolve({score: 0, empty: true})\n }\n });\n}\n\nconst returnShapesCorrect = (shapes) => {\n let answers = [];\n\n shapes.forEach(i => {\n const { correct, id } = i;\n if (correct) {\n answers.push({ id });\n }\n });\n return answers;\n};\n\nexport const createCorrectResponseSession = (question, env) => {\n return new Promise(resolve => {\n if (env.mode !== 'evaluate' && env.role === 'instructor') {\n const { shapes: { rectangles = [], polygons = {} } = {} } = question;\n\n const rectangleCorrect = returnShapesCorrect(rectangles);\n const polygonsCorrect = returnShapesCorrect(polygons);\n\n resolve({\n answers: [\n ...rectangleCorrect,\n ...polygonsCorrect\n ],\n id: '1'\n });\n } else {\n resolve(null);\n }\n });\n};\n"],"file":"index.js"}
1
+ {"version":3,"sources":["../src/index.js"],"names":["log","normalize","question","promptEnabled","rationaleEnabled","teacherInstructionsEnabled","studentInstructionsEnabled","strokeWidth","model","session","env","normalizedQuestion","imageUrl","dimensions","hotspotColor","multipleCorrect","outlineColor","partialScoring","prompt","shapes","rectangles","polygons","Promise","resolve","out","disabled","mode","map","index","rectProps","polyProps","responseCorrect","undefined","role","rationale","teacherInstructions","createDefaultModel","defaults","getScore","config","answers","partialScoringEnabled","enabled","correctAnswers","selectedChoices","choices","correctChoices","filter","choice","correct","forEach","shape","selected","answer","id","correctlySelected","extraAnswers","length","total","str","toFixed","parseFloat","outcome","score","empty","returnShapesCorrect","i","push","createCorrectResponseSession","rectangleCorrect","polygonsCorrect","validate","minShapes","maxShapes","maxSelections","errors","allShapes","Object","values","re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I,EAAd,EAAkBnB,MAArC;;AAEA,MAAIyB,UAAU,GAAGV,SAAjB,EAA4B;AAC1BG,IAAAA,MAAM,CAACQ,WAAP,sCAAiDX,SAAjD;AACD,GAFD,MAEO,IAAIU,UAAU,GAAGT,SAAjB,EAA4B;AACjCE,IAAAA,MAAM,CAACQ,WAAP,0BAAqCV,SAArC;AACD;;AAED,MAAIQ,cAAc,GAAG,CAArB,EAAwB;AACtBN,IAAAA,MAAM,CAACS,eAAP,GAAyB,4CAAzB;AACD,GAFD,MAEO,IAAIH,cAAc,GAAGP,aAArB,EAAoC;AACzCC,IAAAA,MAAM,CAACS,eAAP,0BAAyCV,aAAzC;AACD;;AAED,SAAOC,MAAP;AACD,CAxBM","sourcesContent":["import debug from 'debug';\nimport isEmpty from 'lodash/isEmpty';\nimport { partialScoring } from '@pie-lib/controller-utils';\n\nimport { isResponseCorrect } from './utils';\n\nimport defaults from './defaults';\n\nconst log = debug('pie-elements:hotspot:controller');\n\nexport const normalize = (question) => ({\n promptEnabled: true,\n rationaleEnabled: true,\n teacherInstructionsEnabled: true,\n studentInstructionsEnabled: true,\n strokeWidth: 5,\n ...question,\n});\n\nexport function model(question, session, env) {\n const normalizedQuestion = normalize(question);\n const { imageUrl, dimensions, hotspotColor, multipleCorrect, outlineColor, partialScoring, prompt, shapes } =\n normalizedQuestion;\n const { rectangles, polygons } = shapes || {};\n\n return new Promise((resolve) => {\n const out = {\n disabled: env.mode !== 'gather',\n mode: env.mode,\n dimensions,\n imageUrl,\n outlineColor,\n hotspotColor,\n multipleCorrect,\n partialScoring,\n shapes: {\n ...shapes,\n // eslint-disable-next-line no-unused-vars\n rectangles: (rectangles || []).map(({ index, ...rectProps }) => ({ ...rectProps })),\n // eslint-disable-next-line no-unused-vars\n polygons: (polygons || []).map(({ index, ...polyProps }) => ({ ...polyProps })),\n },\n responseCorrect: env.mode === 'evaluate' ? isResponseCorrect(normalizedQuestion, session) : undefined,\n };\n\n if (env.role === 'instructor' && (env.mode === 'view' || env.mode === 'evaluate')) {\n out.rationale = normalizedQuestion.rationaleEnabled ? normalizedQuestion.rationale : null;\n out.teacherInstructions = normalizedQuestion.teacherInstructionsEnabled\n ? normalizedQuestion.teacherInstructions\n : null;\n } else {\n out.rationale = null;\n out.teacherInstructions = null;\n }\n\n out.prompt = normalizedQuestion.promptEnabled ? prompt : null;\n out.strokeWidth = normalizedQuestion.strokeWidth;\n\n // console.log(out);\n resolve(out);\n });\n}\n\nexport const createDefaultModel = (model = {}) =>\n new Promise((resolve) => {\n resolve({\n ...defaults,\n ...model,\n });\n });\n\nconst getScore = (config, session, env = {}) => {\n const { answers } = session || {};\n\n if (!config.shapes || (!config.shapes.rectangles && !config.shapes.polygons)) {\n return 0;\n }\n\n const { shapes: { rectangles = [], polygons = [] } = {} } = config;\n const partialScoringEnabled = partialScoring.enabled(config, env);\n\n if (!partialScoringEnabled) {\n return isResponseCorrect(config, session) ? 1 : 0;\n }\n\n let correctAnswers = 0;\n let selectedChoices = 0;\n\n const choices = [...rectangles, ...polygons];\n\n const correctChoices = choices.filter((choice) => choice.correct);\n\n choices.forEach((shape) => {\n const selected = answers && answers.filter((answer) => answer.id === shape.id)[0];\n const correctlySelected = shape.correct && selected;\n\n if (selected) {\n selectedChoices += 1;\n }\n\n if (correctlySelected) {\n correctAnswers += 1;\n }\n });\n\n const extraAnswers = selectedChoices > correctChoices.length ? selectedChoices - correctChoices.length : 0;\n\n const total = correctChoices.length === 0 ? 1 : correctChoices.length;\n const str = ((correctAnswers - extraAnswers) / total).toFixed(2);\n\n return str < 0 ? 0 : parseFloat(str);\n};\n\nexport function outcome(config, session, env = {}) {\n return new Promise((resolve) => {\n log('outcome...');\n\n if (!session || isEmpty(session)) {\n resolve({ score: 0, empty: true });\n }\n\n if (session.answers) {\n const score = getScore(config, session, env);\n resolve({ score });\n } else {\n resolve({ score: 0, empty: true });\n }\n });\n}\n\nconst returnShapesCorrect = (shapes) => {\n let answers = [];\n\n shapes.forEach((i) => {\n const { correct, id } = i;\n if (correct) {\n answers.push({ id });\n }\n });\n return answers;\n};\n\nexport const createCorrectResponseSession = (question, env) => {\n return new Promise((resolve) => {\n if (env.mode !== 'evaluate' && env.role === 'instructor') {\n const { shapes: { rectangles = [], polygons = {} } = {} } = question;\n\n const rectangleCorrect = returnShapesCorrect(rectangles);\n const polygonsCorrect = returnShapesCorrect(polygons);\n\n resolve({\n answers: [...rectangleCorrect, ...polygonsCorrect],\n id: '1',\n });\n } else {\n resolve(null);\n }\n });\n};\n\nexport const validate = (model = {}, config = {}) => {\n const { shapes } = model;\n const { minShapes = 2, maxShapes, maxSelections } = config;\n const errors = {};\n\n const allShapes = Object.values(shapes || {}).reduce((acc, shape) => [...acc, ...shape], []);\n\n const nbOfSelections = (allShapes || []).reduce((acc, shape) => (shape.correct ? acc + 1 : acc), 0);\n\n const nbOfShapes = (allShapes || []).length;\n\n if (nbOfShapes < minShapes) {\n errors.shapesError = `There should be at least ${minShapes} shapes defined.`;\n } else if (nbOfShapes > maxShapes) {\n errors.shapesError = `No more than ${maxShapes} shapes should be defined.`;\n }\n\n if (nbOfSelections < 1) {\n errors.selectionsError = 'There should be at least 1 shape selected.';\n } else if (nbOfSelections > maxSelections) {\n errors.selectionsError = `No more than ${maxSelections} shapes should be selected.`;\n }\n\n return errors;\n};\n"],"file":"index.js"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/utils.js"],"names":["getCorrectResponse","choices","filter","c","correct","map","id","sort","isResponseCorrect","question","session","shapes","rectangles","polygons","correctResponseIds","answers","length","answerIds","a"],"mappings":";;;;;;;;;;;AAAA;;AACA;;AAEO,IAAMA,kBAAkB,GAAG,SAArBA,kBAAqB,CAACC,OAAD;AAAA,SAAaA,OAAO,CACnDC,MAD4C,CACrC,UAAAC,CAAC;AAAA,WAAIA,CAAC,CAACC,OAAN;AAAA,GADoC,EAE5CC,GAF4C,CAExC,UAAAF,CAAC;AAAA,WAAIA,CAAC,CAACG,EAAN;AAAA,GAFuC,EAG5CC,IAH4C,EAAb;AAAA,CAA3B;;;;AAKA,IAAMC,iBAAiB,GAAG,SAApBA,iBAAoB,CAACC,QAAD,EAAWC,OAAX,EAAuB;AAAA,yBACTD,QADS,CAC9CE,MAD8C;AAAA,MACpCC,UADoC,oBACpCA,UADoC;AAAA,MACxBC,QADwB,oBACxBA,QADwB;AAEtD,MAAMZ,OAAO,iDAAOW,UAAP,uCAAsBC,QAAtB,EAAb;AACA,MAAIC,kBAAkB,GAAGd,kBAAkB,CAACC,OAAD,CAA3C;;AAEA,MAAI,CAACS,OAAD,IAAY,yBAAQA,OAAR,CAAhB,EAAkC;AAChC,WAAO,KAAP;AACD;;AAED,MAAIA,OAAO,CAACK,OAAR,IAAmBL,OAAO,CAACK,OAAR,CAAgBC,MAAvC,EAA+C;AAC7C,QAAIC,SAAS,GAAG,CAACP,OAAO,CAACK,OAAR,IAAmB,EAApB,EAAwBV,GAAxB,CAA4B,UAAAa,CAAC;AAAA,aAAIA,CAAC,CAACZ,EAAN;AAAA,KAA7B,CAAhB;AAEA,WAAO,yBAAQW,SAAS,CAACV,IAAV,EAAR,EAA0BO,kBAA1B,CAAP;AACD,GAJD,MAIO,IAAI,EAAEA,kBAAkB,IAAIA,kBAAkB,CAACE,MAA3C,CAAJ,EAAwD;AAC7D,WAAO,IAAP;AACD;;AAED,SAAO,KAAP;AACD,CAlBM","sourcesContent":["import isEqual from 'lodash/isEqual';\nimport isEmpty from 'lodash/isEmpty';\n\nexport const getCorrectResponse = (choices) => choices\n .filter(c => c.correct)\n .map(c => c.id)\n .sort();\n\nexport const isResponseCorrect = (question, session) => {\n const { shapes: { rectangles, polygons } } = question;\n const choices = [...rectangles, ...polygons];\n let correctResponseIds = getCorrectResponse(choices);\n\n if (!session || isEmpty(session)) {\n return false;\n }\n\n if (session.answers && session.answers.length) {\n let answerIds = (session.answers || []).map(a => a.id);\n\n return isEqual(answerIds.sort(), correctResponseIds);\n } else if (!(correctResponseIds && correctResponseIds.length)) {\n return true;\n }\n\n return false;\n};\n"],"file":"utils.js"}
1
+ {"version":3,"sources":["../src/utils.js"],"names":["getCorrectResponse","choices","filter","c","correct","map","id","sort","isResponseCorrect","question","session","shapes","rectangles","polygons","correctResponseIds","answers","length","answerIds","a"],"mappings":";;;;;;;;;;;AAAA;;AACA;;AAEO,IAAMA,kBAAkB,GAAG,SAArBA,kBAAqB,CAACC,OAAD;AAAA,SAChCA,OAAO,CACJC,MADH,CACU,UAACC,CAAD;AAAA,WAAOA,CAAC,CAACC,OAAT;AAAA,GADV,EAEGC,GAFH,CAEO,UAACF,CAAD;AAAA,WAAOA,CAAC,CAACG,EAAT;AAAA,GAFP,EAGGC,IAHH,EADgC;AAAA,CAA3B;;;;AAMA,IAAMC,iBAAiB,GAAG,SAApBA,iBAAoB,CAACC,QAAD,EAAWC,OAAX,EAAuB;AACtD,yBAEID,QAFJ,CACEE,MADF;AAAA,MACYC,UADZ,oBACYA,UADZ;AAAA,MACwBC,QADxB,oBACwBA,QADxB;AAGA,MAAMZ,OAAO,iDAAOW,UAAP,uCAAsBC,QAAtB,EAAb;AACA,MAAIC,kBAAkB,GAAGd,kBAAkB,CAACC,OAAD,CAA3C;;AAEA,MAAI,CAACS,OAAD,IAAY,yBAAQA,OAAR,CAAhB,EAAkC;AAChC,WAAO,KAAP;AACD;;AAED,MAAIA,OAAO,CAACK,OAAR,IAAmBL,OAAO,CAACK,OAAR,CAAgBC,MAAvC,EAA+C;AAC7C,QAAIC,SAAS,GAAG,CAACP,OAAO,CAACK,OAAR,IAAmB,EAApB,EAAwBV,GAAxB,CAA4B,UAACa,CAAD;AAAA,aAAOA,CAAC,CAACZ,EAAT;AAAA,KAA5B,CAAhB;AAEA,WAAO,yBAAQW,SAAS,CAACV,IAAV,EAAR,EAA0BO,kBAA1B,CAAP;AACD,GAJD,MAIO,IAAI,EAAEA,kBAAkB,IAAIA,kBAAkB,CAACE,MAA3C,CAAJ,EAAwD;AAC7D,WAAO,IAAP;AACD;;AAED,SAAO,KAAP;AACD,CApBM","sourcesContent":["import isEqual from 'lodash/isEqual';\nimport isEmpty from 'lodash/isEmpty';\n\nexport const getCorrectResponse = (choices) =>\n choices\n .filter((c) => c.correct)\n .map((c) => c.id)\n .sort();\n\nexport const isResponseCorrect = (question, session) => {\n const {\n shapes: { rectangles, polygons },\n } = question;\n const choices = [...rectangles, ...polygons];\n let correctResponseIds = getCorrectResponse(choices);\n\n if (!session || isEmpty(session)) {\n return false;\n }\n\n if (session.answers && session.answers.length) {\n let answerIds = (session.answers || []).map((a) => a.id);\n\n return isEqual(answerIds.sort(), correctResponseIds);\n } else if (!(correctResponseIds && correctResponseIds.length)) {\n return true;\n }\n\n return false;\n};\n"],"file":"utils.js"}
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@pie-element/hotspot-controller",
3
3
  "private": true,
4
- "version": "3.3.15",
4
+ "version": "3.5.1",
5
5
  "description": "",
6
6
  "scripts": {
7
7
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -11,7 +11,7 @@
11
11
  "main": "lib/index.js",
12
12
  "module": "src/index.js",
13
13
  "dependencies": {
14
- "@pie-lib/controller-utils": "^0.2.24",
14
+ "@pie-lib/controller-utils": "^0.2.42",
15
15
  "debug": "^4.1.1",
16
16
  "lodash": "^4.17.15"
17
17
  }