@pie-element/hotspot 4.10.16 → 4.11.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.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,43 @@
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
+ ## [4.11.1](https://github.com/pie-framework/pie-elements/compare/@pie-element/hotspot@4.11.0...@pie-element/hotspot@4.11.1) (2022-05-09)
7
+
8
+ **Note:** Version bump only for package @pie-element/hotspot
9
+
10
+
11
+
12
+
13
+
14
+ # [4.11.0](https://github.com/pie-framework/pie-elements/compare/@pie-element/hotspot@4.10.17...@pie-element/hotspot@4.11.0) (2022-05-03)
15
+
16
+
17
+ ### Bug Fixes
18
+
19
+ * added getters for the session PD-1668 ([de8a754](https://github.com/pie-framework/pie-elements/commit/de8a754f4580370b127257c435e43db405b4bdc4))
20
+ * **hotspot:** add support for --pie-zoom css property PD-360 ([f2dc70d](https://github.com/pie-framework/pie-elements/commit/f2dc70dc4b27bdab76c68cd938dc1b734b50a80f))
21
+ * **hotspot:** add support for --pie-zoom css property PD-360 (review) ([cf34390](https://github.com/pie-framework/pie-elements/commit/cf34390d29c9291bd82b75c649d5b4d1b6c78fdf))
22
+ * **hotspot:** add support for removing --pie-zoom css property PD-360 ([3e7a293](https://github.com/pie-framework/pie-elements/commit/3e7a29385d84264b167ad5f2e9a75ef38e9c14f3))
23
+ * **hotspot:** use "prompt" class on PreviewPrompt PD-1553 ([9650b64](https://github.com/pie-framework/pie-elements/commit/9650b646414ecb9ee6d9a362f4cc1a129d92d357))
24
+
25
+
26
+ ### Features
27
+
28
+ * **hotspot:** added configurable validation PD-1702 ([18eb985](https://github.com/pie-framework/pie-elements/commit/18eb98568adf9248dc616a9ae71d9f8394b62fc1))
29
+ * **hotspot:** PD-1703 implement ui/ux for item validation ([a962183](https://github.com/pie-framework/pie-elements/commit/a962183d0941936b69a95b32002135507d769170))
30
+
31
+
32
+
33
+
34
+
35
+ ## [4.10.17](https://github.com/pie-framework/pie-elements/compare/@pie-element/hotspot@4.10.16...@pie-element/hotspot@4.10.17) (2022-04-12)
36
+
37
+ **Note:** Version bump only for package @pie-element/hotspot
38
+
39
+
40
+
41
+
42
+
6
43
  ## [4.10.16](https://github.com/pie-framework/pie-elements/compare/@pie-element/hotspot@4.10.15...@pie-element/hotspot@4.10.16) (2022-03-28)
7
44
 
8
45
  **Note:** Version bump only for package @pie-element/hotspot
@@ -3,6 +3,33 @@
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
+ ## [4.7.1](https://github.com/pie-framework/pie-elements/compare/@pie-element/hotspot-configure@4.7.0...@pie-element/hotspot-configure@4.7.1) (2022-05-09)
7
+
8
+ **Note:** Version bump only for package @pie-element/hotspot-configure
9
+
10
+
11
+
12
+
13
+
14
+ # [4.7.0](https://github.com/pie-framework/pie-elements/compare/@pie-element/hotspot-configure@4.6.16...@pie-element/hotspot-configure@4.7.0) (2022-05-03)
15
+
16
+
17
+ ### Features
18
+
19
+ * **hotspot:** PD-1703 implement ui/ux for item validation ([a962183](https://github.com/pie-framework/pie-elements/commit/a962183d0941936b69a95b32002135507d769170))
20
+
21
+
22
+
23
+
24
+
25
+ ## [4.6.16](https://github.com/pie-framework/pie-elements/compare/@pie-element/hotspot-configure@4.6.15...@pie-element/hotspot-configure@4.6.16) (2022-04-12)
26
+
27
+ **Note:** Version bump only for package @pie-element/hotspot-configure
28
+
29
+
30
+
31
+
32
+
6
33
  ## [4.6.15](https://github.com/pie-framework/pie-elements/compare/@pie-element/hotspot-configure@4.6.14...@pie-element/hotspot-configure@4.6.15) (2022-03-28)
7
34
 
8
35
  **Note:** Version bump only for package @pie-element/hotspot-configure
@@ -59,7 +59,8 @@ var _default = {
59
59
  settings: false,
60
60
  enabled: true,
61
61
  label: 'Preserve aspect ratio'
62
- }
62
+ },
63
+ minShapes: 2
63
64
  }
64
65
  };
65
66
  exports["default"] = _default;
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/defaults.js"],"names":["model","prompt","toolbarEditorPosition","promptEnabled","imageUrl","shapes","rectangles","polygons","multipleCorrect","partialScoring","dimensions","height","width","hotspotColor","hotspotList","outlineColor","outlineList","rationaleEnabled","teacherInstructionsEnabled","studentInstructionsEnabled","strokeWidth","configuration","settings","label","rationale","spellCheck","enabled","teacherInstructions","preserveAspectRatio"],"mappings":";;;;;;eAAe;AACbA,EAAAA,KAAK,EAAE;AACLC,IAAAA,MAAM,EAAE,6BADH;AAELC,IAAAA,qBAAqB,EAAE,QAFlB;AAGLC,IAAAA,aAAa,EAAE,IAHV;AAILC,IAAAA,QAAQ,EAAE,EAJL;AAKLC,IAAAA,MAAM,EAAE;AACNC,MAAAA,UAAU,EAAE,EADN;AAENC,MAAAA,QAAQ,EAAE;AAFJ,KALH;AASLC,IAAAA,eAAe,EAAE,IATZ;AAULC,IAAAA,cAAc,EAAE,KAVX;AAWLC,IAAAA,UAAU,EAAE;AACVC,MAAAA,MAAM,EAAE,CADE;AAEVC,MAAAA,KAAK,EAAE;AAFG,KAXP;AAeLC,IAAAA,YAAY,EAAE,2BAfT;AAgBLC,IAAAA,WAAW,EAAE,CACX,2BADW,CAhBR;AAmBLC,IAAAA,YAAY,EAAE,MAnBT;AAoBLC,IAAAA,WAAW,EAAE,CACX,MADW,CApBR;AAuBLC,IAAAA,gBAAgB,EAAE,IAvBb;AAwBLC,IAAAA,0BAA0B,EAAE,IAxBvB;AAyBLC,IAAAA,0BAA0B,EAAE,IAzBvB;AA0BLC,IAAAA,WAAW,EAAE;AA1BR,GADM;AA6BbC,EAAAA,aAAa,EAAE;AACbb,IAAAA,eAAe,EAAE;AACfc,MAAAA,QAAQ,EAAE,IADK;AAEfC,MAAAA,KAAK,EAAE;AAFQ,KADJ;AAKbd,IAAAA,cAAc,EAAE;AACda,MAAAA,QAAQ,EAAE,KADI;AAEdC,MAAAA,KAAK,EAAE;AAFO,KALH;AASbC,IAAAA,SAAS,EAAE;AACTF,MAAAA,QAAQ,EAAE,IADD;AAETC,MAAAA,KAAK,EAAE;AAFE,KATE;AAabtB,IAAAA,MAAM,EAAE;AACNqB,MAAAA,QAAQ,EAAE,IADJ;AAENC,MAAAA,KAAK,EAAE;AAFD,KAbK;AAiBbE,IAAAA,UAAU,EAAE;AACVF,MAAAA,KAAK,EAAE,YADG;AAEVD,MAAAA,QAAQ,EAAC,KAFC;AAGVI,MAAAA,OAAO,EAAC;AAHE,KAjBC;AAsBbC,IAAAA,mBAAmB,EAAE;AACnBL,MAAAA,QAAQ,EAAE,IADS;AAEnBC,MAAAA,KAAK,EAAE;AAFY,KAtBR;AA0BbK,IAAAA,mBAAmB,EAAE;AACnBN,MAAAA,QAAQ,EAAE,KADS;AAEnBI,MAAAA,OAAO,EAAE,IAFU;AAGnBH,MAAAA,KAAK,EAAE;AAHY;AA1BR;AA7BF,C","sourcesContent":["export default {\n model: {\n prompt: 'This is the question prompt',\n toolbarEditorPosition: 'bottom',\n promptEnabled: true,\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 rationaleEnabled: true,\n teacherInstructionsEnabled: true,\n studentInstructionsEnabled: true,\n strokeWidth: 5\n },\n configuration: {\n multipleCorrect: {\n settings: true,\n label: 'Multiple Correct Responses'\n },\n partialScoring: {\n settings: false,\n label: 'Allow Partial Scoring'\n },\n rationale: {\n settings: true,\n label: 'Rationale'\n },\n prompt: {\n settings: true,\n label: 'Prompt'\n },\n spellCheck: {\n label: 'Spellcheck',\n settings:false,\n enabled:true\n },\n teacherInstructions: {\n settings: true,\n label: 'Teacher Instructions'\n },\n preserveAspectRatio: {\n settings: false,\n enabled: true,\n label: 'Preserve aspect ratio'\n }\n }\n};\n"],"file":"defaults.js"}
1
+ {"version":3,"sources":["../src/defaults.js"],"names":["model","prompt","toolbarEditorPosition","promptEnabled","imageUrl","shapes","rectangles","polygons","multipleCorrect","partialScoring","dimensions","height","width","hotspotColor","hotspotList","outlineColor","outlineList","rationaleEnabled","teacherInstructionsEnabled","studentInstructionsEnabled","strokeWidth","configuration","settings","label","rationale","spellCheck","enabled","teacherInstructions","preserveAspectRatio","minShapes"],"mappings":";;;;;;eAAe;AACbA,EAAAA,KAAK,EAAE;AACLC,IAAAA,MAAM,EAAE,6BADH;AAELC,IAAAA,qBAAqB,EAAE,QAFlB;AAGLC,IAAAA,aAAa,EAAE,IAHV;AAILC,IAAAA,QAAQ,EAAE,EAJL;AAKLC,IAAAA,MAAM,EAAE;AACNC,MAAAA,UAAU,EAAE,EADN;AAENC,MAAAA,QAAQ,EAAE;AAFJ,KALH;AASLC,IAAAA,eAAe,EAAE,IATZ;AAULC,IAAAA,cAAc,EAAE,KAVX;AAWLC,IAAAA,UAAU,EAAE;AACVC,MAAAA,MAAM,EAAE,CADE;AAEVC,MAAAA,KAAK,EAAE;AAFG,KAXP;AAeLC,IAAAA,YAAY,EAAE,2BAfT;AAgBLC,IAAAA,WAAW,EAAE,CACX,2BADW,CAhBR;AAmBLC,IAAAA,YAAY,EAAE,MAnBT;AAoBLC,IAAAA,WAAW,EAAE,CACX,MADW,CApBR;AAuBLC,IAAAA,gBAAgB,EAAE,IAvBb;AAwBLC,IAAAA,0BAA0B,EAAE,IAxBvB;AAyBLC,IAAAA,0BAA0B,EAAE,IAzBvB;AA0BLC,IAAAA,WAAW,EAAE;AA1BR,GADM;AA6BbC,EAAAA,aAAa,EAAE;AACbb,IAAAA,eAAe,EAAE;AACfc,MAAAA,QAAQ,EAAE,IADK;AAEfC,MAAAA,KAAK,EAAE;AAFQ,KADJ;AAKbd,IAAAA,cAAc,EAAE;AACda,MAAAA,QAAQ,EAAE,KADI;AAEdC,MAAAA,KAAK,EAAE;AAFO,KALH;AASbC,IAAAA,SAAS,EAAE;AACTF,MAAAA,QAAQ,EAAE,IADD;AAETC,MAAAA,KAAK,EAAE;AAFE,KATE;AAabtB,IAAAA,MAAM,EAAE;AACNqB,MAAAA,QAAQ,EAAE,IADJ;AAENC,MAAAA,KAAK,EAAE;AAFD,KAbK;AAiBbE,IAAAA,UAAU,EAAE;AACVF,MAAAA,KAAK,EAAE,YADG;AAEVD,MAAAA,QAAQ,EAAC,KAFC;AAGVI,MAAAA,OAAO,EAAC;AAHE,KAjBC;AAsBbC,IAAAA,mBAAmB,EAAE;AACnBL,MAAAA,QAAQ,EAAE,IADS;AAEnBC,MAAAA,KAAK,EAAE;AAFY,KAtBR;AA0BbK,IAAAA,mBAAmB,EAAE;AACnBN,MAAAA,QAAQ,EAAE,KADS;AAEnBI,MAAAA,OAAO,EAAE,IAFU;AAGnBH,MAAAA,KAAK,EAAE;AAHY,KA1BR;AA+BbM,IAAAA,SAAS,EAAE;AA/BE;AA7BF,C","sourcesContent":["export default {\n model: {\n prompt: 'This is the question prompt',\n toolbarEditorPosition: 'bottom',\n promptEnabled: true,\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 rationaleEnabled: true,\n teacherInstructionsEnabled: true,\n studentInstructionsEnabled: true,\n strokeWidth: 5\n },\n configuration: {\n multipleCorrect: {\n settings: true,\n label: 'Multiple Correct Responses'\n },\n partialScoring: {\n settings: false,\n label: 'Allow Partial Scoring'\n },\n rationale: {\n settings: true,\n label: 'Rationale'\n },\n prompt: {\n settings: true,\n label: 'Prompt'\n },\n spellCheck: {\n label: 'Spellcheck',\n settings:false,\n enabled:true\n },\n teacherInstructions: {\n settings: true,\n label: 'Teacher Instructions'\n },\n preserveAspectRatio: {\n settings: false,\n enabled: true,\n label: 'Preserve aspect ratio'\n },\n minShapes: 2\n }\n};\n"],"file":"defaults.js"}
@@ -228,7 +228,7 @@ var Drawable = /*#__PURE__*/function (_React$Component) {
228
228
 
229
229
  var hasMinimumWidth = width > 150 && height > 150;
230
230
 
231
- if (resizeValid && hasMinimumWidth) {
231
+ if (resizeValid && hasMinimumWidth && box) {
232
232
  box.style.width = "".concat(width, "px");
233
233
  box.style.height = "".concat(height, "px");
234
234
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/hotspot-drawable.jsx"],"names":["IMAGE_MAX_WIDTH","Drawable","props","e","target","currentTarget","onUpdateShapes","shapes","newShapes","slice","value","map","c","parseInt","id","filter","isNaN","push","height","width","x","evt","layerX","y","layerY","group","index","length","setState","isDrawing","isDrawingShapeId","state","stateShapes","undefined","mouseX","mouseY","currShapeIndex","findIndex","shape","currShape","newWidth","newHeight","newShapesList","updatedProps","multipleCorrect","correct","onUpdateImageDimension","resizeHandle","resize","elementStyle","getComputedStyle","parseFloat","aspectWidth","dimensions","addEventListener","initialiseResize","window","startResizing","stopResizing","bounds","getBoundingClientRect","box","image","disableDrag","preserveAspectRatioEnabled","clientX","left","clientY","top","resizeValid","checkIfResizeValid","hasMinimumWidth","style","resizing","enableDrag","removeEventListener","drawable","forEach","right","bottom","classes","imageUrl","hotspotColor","outlineColor","strokeWidth","heightFromState","widthFromState","shapesToUse","base","imageContainer","handleOnImageLoad","ref","stage","handleOnMouseDown","handleOnMouseUp","handleMouseMove","Tag","Polygon","Rectangle","handleOnSetAsCorrect","handleOnDragEnd","points","nextProps","prevState","React","Component","styles","position","alignItems","display","justifyContent","borderBottom","borderRight","cursor","propTypes","PropTypes","object","isRequired","func","string","bool","array","number"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAEA;;AACA;;AACA;;;;;;;;;;AAE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APD;AAQN3D,MAAAA,KAAK,EAAE;AARD,KAbY;AAuBpByE,IAAAA,KAAK,EAAE;AACL1B,MAAAA,IAAI,EAAE,CADD;AAELE,MAAAA,GAAG,EAAE,CAFA;AAGLuC,MAAAA,QAAQ,EAAE;AAHL;AAvBa,GAAP;AAAA,CAAf;;AA8BA1G,QAAQ,CAACiH,SAAT,GAAqB;AACnBlC,EAAAA,OAAO,EAAEmC,sBAAUC,MAAV,CAAiBC,UADP;AAEnBtD,EAAAA,WAAW,EAAEoD,sBAAUG,IAAV,CAAeD,UAFT;AAGnBhE,EAAAA,UAAU,EAAE8D,sBAAUC,MAAV,CAAiBC,UAHV;AAInB3C,EAAAA,UAAU,EAAEyC,sBAAUG,IAAV,CAAeD,UAJR;AAKnBpC,EAAAA,QAAQ,EAAEkC,sBAAUI,MAAV,CAAiBF,UALR;AAMnBnC,EAAAA,YAAY,EAAEiC,sBAAUI,MAAV,CAAiBF,UANZ;AAOnBzE,EAAAA,eAAe,EAAEuE,sBAAUK,IAAV,CAAeH,UAPb;AAQnBvE,EAAAA,sBAAsB,EAAEqE,sBAAUG,IAAV,CAAeD,UARpB;AASnB/G,EAAAA,cAAc,EAAE6G,sBAAUG,IAAV,CAAeD,UATZ;AAUnBlC,EAAAA,YAAY,EAAEgC,sBAAUI,MAAV,CAAiBF,UAVZ;AAWnB9G,EAAAA,MAAM,EAAE4G,sBAAUM,KAAV,CAAgBJ,UAXL;AAYnBjC,EAAAA,WAAW,EAAE+B,sBAAUO,MAZJ;AAanB1D,EAAAA,0BAA0B,EAAEmD,sBAAUK;AAbnB,CAArB;;eAgBe,uBAAWd,MAAX,EAAmBzG,QAAnB,C","sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\nimport { Layer, Stage } from 'react-konva';\nimport max from 'lodash/max';\nimport cloneDeep from 'lodash/cloneDeep';\nimport { withStyles } from '@material-ui/core/styles/index';\n\nimport Rectangle from './hotspot-rectangle';\nimport Polygon from './hotspot-polygon';\nimport { updateImageDimensions, getUpdatedShapes } from './utils';\n\nconst IMAGE_MAX_WIDTH = 800;\n\nexport class Drawable extends React.Component {\n static getDerivedStateFromProps(nextProps, prevState) {\n let dimensions = nextProps.dimensions;\n\n if (prevState && prevState.resizing) {\n dimensions = prevState.dimensions;\n }\n\n return {\n ...prevState,\n dimensions: dimensions,\n }\n }\n\n constructor(props) {\n super(props);\n\n this.state = {\n isDrawing: false,\n stateShapes: false,\n resizing: false,\n dimensions: {\n height: 0,\n width: 0,\n },\n }\n }\n\n /// start of handling HotSpots section\n handleOnMouseDown = (e) => {\n if (e.target === e.currentTarget) {\n const { onUpdateShapes, shapes } = this.props;\n // Add a new rectangle at the mouse position with 0 width and height\n const newShapes = shapes.slice();\n const value = max(newShapes.map(c => parseInt(c.id)).filter(id => !isNaN(id))) || 0;\n\n newShapes.push({\n id: `${value + 1}`,\n height: 0,\n width: 0,\n x: e.evt.layerX,\n y: e.evt.layerY,\n group: 'rectangles',\n index: shapes.length\n });\n\n this.setState({ isDrawing: true, isDrawingShapeId: `${value + 1}` });\n onUpdateShapes(newShapes);\n }\n };\n\n handleOnMouseUp = () => {\n // !IMPORTANT: currently, only 'rectangles' are drawable\n const { isDrawing, stateShapes } = this.state;\n const { onUpdateShapes } = this.props;\n\n // If we're drawing a shape, a click finishes the drawing and sends the new shapes to HOC\n if (isDrawing) {\n this.setState({ isDrawing: !isDrawing, stateShapes: false, isDrawingShapeId: undefined });\n\n if (stateShapes) {\n onUpdateShapes(stateShapes);\n }\n }\n };\n\n handleMouseMove = (e) => {\n // !IMPORTANT: currently, only 'rectangles' are drawable\n const { isDrawing, isDrawingShapeId } = this.state;\n const { shapes } = this.props;\n\n if (isDrawing && isDrawingShapeId) {\n const mouseX = e.evt.layerX;\n const mouseY = e.evt.layerY;\n\n const currShapeIndex = shapes.findIndex(shape => shape.id === isDrawingShapeId);\n const currShape = shapes[currShapeIndex];\n\n if (currShape) {\n const newWidth = mouseX - currShape.x;\n const newHeight = mouseY - currShape.y;\n\n const newShapesList = shapes.slice();\n\n newShapesList[currShapeIndex] = {\n ...newShapesList[currShapeIndex],\n height: newHeight,\n width: newWidth,\n x: currShape.x,\n y: currShape.y\n };\n\n // On mouse move don't trigger any event. Put the shapes on this state instead.\n this.setState({ stateShapes: newShapesList });\n }\n }\n };\n\n handleOnDragEnd = (id, updatedProps) => {\n const { shapes, onUpdateShapes } = this.props;\n const newShapes = shapes.map(shape => {\n if (shape.id === id) {\n return {\n ...shape,\n ...updatedProps\n }\n }\n return shape;\n });\n\n onUpdateShapes(cloneDeep(newShapes));\n };\n\n handleOnSetAsCorrect = (shape) => {\n const { id } = shape;\n const { multipleCorrect, shapes, onUpdateShapes } = this.props;\n\n let newShapes = [];\n\n if (multipleCorrect) {\n newShapes = shapes.map(shape => {\n if (shape.id === id) {\n shape.correct = !shape.correct;\n }\n return shape;\n })\n } else {\n newShapes = shapes.map(shape => {\n shape.correct = shape.id === id;\n return shape;\n })\n }\n\n onUpdateShapes(cloneDeep(newShapes));\n };\n /// end of handling HotSpots section\n\n /// start of handling Image section\n handleOnImageLoad = ({ target }) => {\n const { onUpdateImageDimension } = this.props;\n const resizeHandle = this.resize;\n const elementStyle = getComputedStyle(target);\n const newHeight = parseFloat(elementStyle.height);\n const newWidth = parseFloat(elementStyle.width);\n const aspectWidth = newWidth / IMAGE_MAX_WIDTH;\n\n const dimensions = newWidth > IMAGE_MAX_WIDTH ? {\n height: newHeight / aspectWidth,\n width: IMAGE_MAX_WIDTH\n } : {\n height: newHeight,\n width: newWidth\n };\n\n this.setState(\n { dimensions },\n () => onUpdateImageDimension(dimensions));\n\n resizeHandle.addEventListener('mousedown', this.initialiseResize, false);\n };\n\n initialiseResize = () => {\n window.addEventListener('mousemove', this.startResizing, false);\n window.addEventListener('mouseup', this.stopResizing, false);\n };\n\n checkIfResizeValid(x, y) {\n const { shapes } = this.state;\n let drawable = true;\n\n // Do not allow resizing over the hotspots\n shapes && shapes.forEach(shape => {\n const right = shape.x + shape.width + 5;\n const bottom = shape.y + shape.height + 5;\n if (x <= right || y <= bottom) {\n drawable = false\n }\n });\n return drawable;\n }\n\n startResizing = (e) => {\n const bounds = e.target.getBoundingClientRect();\n const box = this.image;\n const {\n disableDrag,\n preserveAspectRatioEnabled,\n dimensions,\n shapes\n } = this.props;\n\n // todo previously we had state.dimensions, is it needed?\n const { width, height } = updateImageDimensions(\n dimensions,\n {\n width: e.clientX - bounds.left,\n height: e.clientY - bounds.top\n },\n preserveAspectRatioEnabled\n );\n\n const resizeValid = this.checkIfResizeValid(width, height);\n const hasMinimumWidth = width > 150 && height > 150;\n\n if (resizeValid && hasMinimumWidth) {\n box.style.width = `${width}px`;\n box.style.height = `${height}px`;\n\n this.setState({\n resizing: true,\n dimensions: { height: height, width: width },\n stateShapes: getUpdatedShapes(dimensions, { width, height }, shapes)\n });\n }\n\n disableDrag();\n };\n\n stopResizing = () => {\n const { enableDrag, onUpdateImageDimension, onUpdateShapes } = this.props;\n const { dimensions, stateShapes } = this.state;\n\n enableDrag();\n\n if (stateShapes) {\n onUpdateShapes(cloneDeep(stateShapes));\n }\n\n onUpdateImageDimension(dimensions);\n\n window.removeEventListener('mousemove', this.startResizing, false);\n window.removeEventListener('mouseup', this.stopResizing, false);\n\n this.setState({ resizing: false, stateShapes: false });\n };\n /// end of handling Image section\n\n render() {\n const {\n classes,\n imageUrl,\n dimensions: { height, width },\n hotspotColor,\n outlineColor,\n shapes,\n strokeWidth\n } = this.props;\n const {\n stateShapes,\n isDrawing,\n dimensions: { height: heightFromState, width: widthFromState }\n } = this.state;\n const shapesToUse = stateShapes || shapes;\n\n return (\n <div className={classes.base}>\n {imageUrl && (\n <div className={classes.imageContainer}>\n <img\n className={classes.image}\n onLoad={this.handleOnImageLoad}\n ref={ref => {\n this.image = ref;\n }}\n src={imageUrl}\n {...height && width ? { style: { height, width } } : {}}\n />\n <div ref={ref => {\n this.resize = ref;\n }} className={classes.resize}/>\n </div>\n )}\n\n <Stage\n className={classes.stage}\n height={heightFromState || height}\n width={widthFromState || width}\n onMouseDown={this.handleOnMouseDown }\n onMouseUp={this.handleOnMouseUp }\n onMouseMove={this.handleMouseMove }\n >\n <Layer>\n {shapesToUse.map((shape, index) => {\n const Tag = shape.group === 'polygons' ? Polygon : Rectangle;\n\n return (\n <Tag\n correct={shape.correct}\n isDrawing={isDrawing}\n height={shape.height}\n hotspotColor={hotspotColor}\n id={shape.id}\n key={index}\n onClick={() => this.handleOnSetAsCorrect(shape)}\n onDragEnd={this.handleOnDragEnd}\n outlineColor={outlineColor}\n width={shape.width}\n x={shape.x}\n y={shape.y}\n points={shape.points}\n strokeWidth={strokeWidth}\n />\n );\n })}\n </Layer>\n </Stage>\n </div>\n );\n }\n}\n\nconst styles = () => ({\n base: {\n position: 'relative'\n },\n image: {\n alignItems: 'center',\n display: 'flex',\n justifyContent: 'center',\n },\n imageContainer: {\n position: 'relative',\n width: 'fit-content'\n },\n resize: {\n borderBottom: '1px solid #727272',\n borderRight: '1px solid #727272',\n bottom: '-10px',\n cursor: 'se-resize',\n height: '10px',\n position: 'absolute',\n right: '-10px',\n width: '10px'\n },\n stage: {\n left: 0,\n top: 0,\n position: 'absolute'\n }\n});\n\nDrawable.propTypes = {\n classes: PropTypes.object.isRequired,\n disableDrag: PropTypes.func.isRequired,\n dimensions: PropTypes.object.isRequired,\n enableDrag: PropTypes.func.isRequired,\n imageUrl: PropTypes.string.isRequired,\n hotspotColor: PropTypes.string.isRequired,\n multipleCorrect: PropTypes.bool.isRequired,\n onUpdateImageDimension: PropTypes.func.isRequired,\n onUpdateShapes: PropTypes.func.isRequired,\n outlineColor: PropTypes.string.isRequired,\n shapes: PropTypes.array.isRequired,\n strokeWidth: PropTypes.number,\n preserveAspectRatioEnabled: PropTypes.bool\n};\n\nexport default withStyles(styles)(Drawable);\n"],"file":"hotspot-drawable.js"}
1
+ {"version":3,"sources":["../src/hotspot-drawable.jsx"],"names":["IMAGE_MAX_WIDTH","Drawable","props","e","target","currentTarget","onUpdateShapes","shapes","newShapes","slice","value","map","c","parseInt","id","filter","isNaN","push","height","width","x","evt","layerX","y","layerY","group","index","length","setState","isDrawing","isDrawingShapeId","state","stateShapes","undefined","mouseX","mouseY","currShapeIndex","findIndex","shape","currShape","newWidth","newHeight","newShapesList","updatedProps","multipleCorrect","correct","onUpdateImageDimension","resizeHandle","resize","elementStyle","getComputedStyle","parseFloat","aspectWidth","dimensions","addEventListener","initialiseResize","window","startResizing","stopResizing","bounds","getBoundingClientRect","box","image","disableDrag","preserveAspectRatioEnabled","clientX","left","clientY","top","resizeValid","checkIfResizeValid","hasMinimumWidth","style","resizing","enableDrag","removeEventListener","drawable","forEach","right","bottom","classes","imageUrl","hotspotColor","outlineColor","strokeWidth","heightFromState","widthFromState","shapesToUse","base","imageContainer","handleOnImageLoad","ref","stage","handleOnMouseDown","handleOnMouseUp","handleMouseMove","Tag","Polygon","Rectangle","handleOnSetAsCorrect","handleOnDragEnd","points","nextProps","prevState","React","Component","styles","position","alignItems","display","justifyContent","borderBottom","borderRight","cursor","propTypes","PropTypes","object","isRequired","func","string","bool","array","number"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAEA;;AACA;;AACA;;;;;;;;;;AAEA,IAAMA,eAAe,GAAG,GAAxB;;IAEaC,Q;;;;;AAcX,oBAAYC,KAAZ,EAAmB;AAAA;;AAAA;AACjB,8BAAMA,KAAN;AADiB,0GAeC,UAACC,CAAD,EAAO;AACzB,UAAIA,CAAC,CAACC,MAAF,KAAaD,CAAC,CAACE,aAAnB,EAAkC;AAChC,0BAAmC,MAAKH,KAAxC;AAAA,YAAQI,cAAR,eAAQA,cAAR;AAAA,YAAwBC,MAAxB,eAAwBA,MAAxB,CADgC,CAEhC;;AACA,YAAMC,SAAS,GAAGD,MAAM,CAACE,KAAP,EAAlB;AACA,YAAMC,KAAK,GAAG,qBAAIF,SAAS,CAACG,GAAV,CAAc,UAAAC,CAAC;AAAA,iBAAIC,QAAQ,CAAC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IAAV,CAAeD,UAJR;AAKnBpC,EAAAA,QAAQ,EAAEkC,sBAAUI,MAAV,CAAiBF,UALR;AAMnBnC,EAAAA,YAAY,EAAEiC,sBAAUI,MAAV,CAAiBF,UANZ;AAOnBzE,EAAAA,eAAe,EAAEuE,sBAAUK,IAAV,CAAeH,UAPb;AAQnBvE,EAAAA,sBAAsB,EAAEqE,sBAAUG,IAAV,CAAeD,UARpB;AASnB/G,EAAAA,cAAc,EAAE6G,sBAAUG,IAAV,CAAeD,UATZ;AAUnBlC,EAAAA,YAAY,EAAEgC,sBAAUI,MAAV,CAAiBF,UAVZ;AAWnB9G,EAAAA,MAAM,EAAE4G,sBAAUM,KAAV,CAAgBJ,UAXL;AAYnBjC,EAAAA,WAAW,EAAE+B,sBAAUO,MAZJ;AAanB1D,EAAAA,0BAA0B,EAAEmD,sBAAUK;AAbnB,CAArB;;eAgBe,uBAAWd,MAAX,EAAmBzG,QAAnB,C","sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\nimport { Layer, Stage } from 'react-konva';\nimport max from 'lodash/max';\nimport cloneDeep from 'lodash/cloneDeep';\nimport { withStyles } from '@material-ui/core/styles/index';\n\nimport Rectangle from './hotspot-rectangle';\nimport Polygon from './hotspot-polygon';\nimport { updateImageDimensions, getUpdatedShapes } from './utils';\n\nconst IMAGE_MAX_WIDTH = 800;\n\nexport class Drawable extends React.Component {\n static getDerivedStateFromProps(nextProps, prevState) {\n let dimensions = nextProps.dimensions;\n\n if (prevState && prevState.resizing) {\n dimensions = prevState.dimensions;\n }\n\n return {\n ...prevState,\n dimensions: dimensions,\n }\n }\n\n constructor(props) {\n super(props);\n\n this.state = {\n isDrawing: false,\n stateShapes: false,\n resizing: false,\n dimensions: {\n height: 0,\n width: 0,\n },\n }\n }\n\n /// start of handling HotSpots section\n handleOnMouseDown = (e) => {\n if (e.target === e.currentTarget) {\n const { onUpdateShapes, shapes } = this.props;\n // Add a new rectangle at the mouse position with 0 width and height\n const newShapes = shapes.slice();\n const value = max(newShapes.map(c => parseInt(c.id)).filter(id => !isNaN(id))) || 0;\n\n newShapes.push({\n id: `${value + 1}`,\n height: 0,\n width: 0,\n x: e.evt.layerX,\n y: e.evt.layerY,\n group: 'rectangles',\n index: shapes.length\n });\n\n this.setState({ isDrawing: true, isDrawingShapeId: `${value + 1}` });\n onUpdateShapes(newShapes);\n }\n };\n\n handleOnMouseUp = () => {\n // !IMPORTANT: currently, only 'rectangles' are drawable\n const { isDrawing, stateShapes } = this.state;\n const { onUpdateShapes } = this.props;\n\n // If we're drawing a shape, a click finishes the drawing and sends the new shapes to HOC\n if (isDrawing) {\n this.setState({ isDrawing: !isDrawing, stateShapes: false, isDrawingShapeId: undefined });\n\n if (stateShapes) {\n onUpdateShapes(stateShapes);\n }\n }\n };\n\n handleMouseMove = (e) => {\n // !IMPORTANT: currently, only 'rectangles' are drawable\n const { isDrawing, isDrawingShapeId } = this.state;\n const { shapes } = this.props;\n\n if (isDrawing && isDrawingShapeId) {\n const mouseX = e.evt.layerX;\n const mouseY = e.evt.layerY;\n\n const currShapeIndex = shapes.findIndex(shape => shape.id === isDrawingShapeId);\n const currShape = shapes[currShapeIndex];\n\n if (currShape) {\n const newWidth = mouseX - currShape.x;\n const newHeight = mouseY - currShape.y;\n\n const newShapesList = shapes.slice();\n\n newShapesList[currShapeIndex] = {\n ...newShapesList[currShapeIndex],\n height: newHeight,\n width: newWidth,\n x: currShape.x,\n y: currShape.y\n };\n\n // On mouse move don't trigger any event. Put the shapes on this state instead.\n this.setState({ stateShapes: newShapesList });\n }\n }\n };\n\n handleOnDragEnd = (id, updatedProps) => {\n const { shapes, onUpdateShapes } = this.props;\n const newShapes = shapes.map(shape => {\n if (shape.id === id) {\n return {\n ...shape,\n ...updatedProps\n }\n }\n return shape;\n });\n\n onUpdateShapes(cloneDeep(newShapes));\n };\n\n handleOnSetAsCorrect = (shape) => {\n const { id } = shape;\n const { multipleCorrect, shapes, onUpdateShapes } = this.props;\n\n let newShapes = [];\n\n if (multipleCorrect) {\n newShapes = shapes.map(shape => {\n if (shape.id === id) {\n shape.correct = !shape.correct;\n }\n return shape;\n })\n } else {\n newShapes = shapes.map(shape => {\n shape.correct = shape.id === id;\n return shape;\n })\n }\n\n onUpdateShapes(cloneDeep(newShapes));\n };\n /// end of handling HotSpots section\n\n /// start of handling Image section\n handleOnImageLoad = ({ target }) => {\n const { onUpdateImageDimension } = this.props;\n const resizeHandle = this.resize;\n const elementStyle = getComputedStyle(target);\n const newHeight = parseFloat(elementStyle.height);\n const newWidth = parseFloat(elementStyle.width);\n const aspectWidth = newWidth / IMAGE_MAX_WIDTH;\n\n const dimensions = newWidth > IMAGE_MAX_WIDTH ? {\n height: newHeight / aspectWidth,\n width: IMAGE_MAX_WIDTH\n } : {\n height: newHeight,\n width: newWidth\n };\n\n this.setState(\n { dimensions },\n () => onUpdateImageDimension(dimensions));\n\n resizeHandle.addEventListener('mousedown', this.initialiseResize, false);\n };\n\n initialiseResize = () => {\n window.addEventListener('mousemove', this.startResizing, false);\n window.addEventListener('mouseup', this.stopResizing, false);\n };\n\n checkIfResizeValid(x, y) {\n const { shapes } = this.state;\n let drawable = true;\n\n // Do not allow resizing over the hotspots\n shapes && shapes.forEach(shape => {\n const right = shape.x + shape.width + 5;\n const bottom = shape.y + shape.height + 5;\n if (x <= right || y <= bottom) {\n drawable = false\n }\n });\n return drawable;\n }\n\n startResizing = (e) => {\n const bounds = e.target.getBoundingClientRect();\n const box = this.image;\n const {\n disableDrag,\n preserveAspectRatioEnabled,\n dimensions,\n shapes\n } = this.props;\n\n // todo previously we had state.dimensions, is it needed?\n const { width, height } = updateImageDimensions(\n dimensions,\n {\n width: e.clientX - bounds.left,\n height: e.clientY - bounds.top\n },\n preserveAspectRatioEnabled\n );\n\n const resizeValid = this.checkIfResizeValid(width, height);\n const hasMinimumWidth = width > 150 && height > 150;\n\n if (resizeValid && hasMinimumWidth && box) {\n box.style.width = `${width}px`;\n box.style.height = `${height}px`;\n\n this.setState({\n resizing: true,\n dimensions: { height: height, width: width },\n stateShapes: getUpdatedShapes(dimensions, { width, height }, shapes)\n });\n }\n\n disableDrag();\n };\n\n stopResizing = () => {\n const { enableDrag, onUpdateImageDimension, onUpdateShapes } = this.props;\n const { dimensions, stateShapes } = this.state;\n\n enableDrag();\n\n if (stateShapes) {\n onUpdateShapes(cloneDeep(stateShapes));\n }\n\n onUpdateImageDimension(dimensions);\n\n window.removeEventListener('mousemove', this.startResizing, false);\n window.removeEventListener('mouseup', this.stopResizing, false);\n\n this.setState({ resizing: false, stateShapes: false });\n };\n /// end of handling Image section\n\n render() {\n const {\n classes,\n imageUrl,\n dimensions: { height, width },\n hotspotColor,\n outlineColor,\n shapes,\n strokeWidth\n } = this.props;\n const {\n stateShapes,\n isDrawing,\n dimensions: { height: heightFromState, width: widthFromState }\n } = this.state;\n const shapesToUse = stateShapes || shapes;\n\n return (\n <div className={classes.base}>\n {imageUrl && (\n <div className={classes.imageContainer}>\n <img\n className={classes.image}\n onLoad={this.handleOnImageLoad}\n ref={ref => {\n this.image = ref;\n }}\n src={imageUrl}\n {...height && width ? { style: { height, width } } : {}}\n />\n <div ref={ref => {\n this.resize = ref;\n }} className={classes.resize}/>\n </div>\n )}\n\n <Stage\n className={classes.stage}\n height={heightFromState || height}\n width={widthFromState || width}\n onMouseDown={this.handleOnMouseDown }\n onMouseUp={this.handleOnMouseUp }\n onMouseMove={this.handleMouseMove }\n >\n <Layer>\n {shapesToUse.map((shape, index) => {\n const Tag = shape.group === 'polygons' ? Polygon : Rectangle;\n\n return (\n <Tag\n correct={shape.correct}\n isDrawing={isDrawing}\n height={shape.height}\n hotspotColor={hotspotColor}\n id={shape.id}\n key={index}\n onClick={() => this.handleOnSetAsCorrect(shape)}\n onDragEnd={this.handleOnDragEnd}\n outlineColor={outlineColor}\n width={shape.width}\n x={shape.x}\n y={shape.y}\n points={shape.points}\n strokeWidth={strokeWidth}\n />\n );\n })}\n </Layer>\n </Stage>\n </div>\n );\n }\n}\n\nconst styles = () => ({\n base: {\n position: 'relative'\n },\n image: {\n alignItems: 'center',\n display: 'flex',\n justifyContent: 'center',\n },\n imageContainer: {\n position: 'relative',\n width: 'fit-content'\n },\n resize: {\n borderBottom: '1px solid #727272',\n borderRight: '1px solid #727272',\n bottom: '-10px',\n cursor: 'se-resize',\n height: '10px',\n position: 'absolute',\n right: '-10px',\n width: '10px'\n },\n stage: {\n left: 0,\n top: 0,\n position: 'absolute'\n }\n});\n\nDrawable.propTypes = {\n classes: PropTypes.object.isRequired,\n disableDrag: PropTypes.func.isRequired,\n dimensions: PropTypes.object.isRequired,\n enableDrag: PropTypes.func.isRequired,\n imageUrl: PropTypes.string.isRequired,\n hotspotColor: PropTypes.string.isRequired,\n multipleCorrect: PropTypes.bool.isRequired,\n onUpdateImageDimension: PropTypes.func.isRequired,\n onUpdateShapes: PropTypes.func.isRequired,\n outlineColor: PropTypes.string.isRequired,\n shapes: PropTypes.array.isRequired,\n strokeWidth: PropTypes.number,\n preserveAspectRatioEnabled: PropTypes.bool\n};\n\nexport default withStyles(styles)(Drawable);\n"],"file":"hotspot-drawable.js"}
@@ -29,14 +29,20 @@ var _propTypes = _interopRequireDefault(require("prop-types"));
29
29
 
30
30
  var _editableHtml = _interopRequireDefault(require("@pie-lib/editable-html"));
31
31
 
32
+ var _styles = require("@material-ui/core/styles");
33
+
32
34
  var _Typography = _interopRequireDefault(require("@material-ui/core/Typography"));
33
35
 
34
- var _styles = require("@material-ui/core/styles");
36
+ var _Info = _interopRequireDefault(require("@material-ui/icons/Info"));
37
+
38
+ var _Tooltip = _interopRequireDefault(require("@material-ui/core/Tooltip"));
35
39
 
36
40
  var _hotspotPalette = _interopRequireDefault(require("./hotspot-palette"));
37
41
 
38
42
  var _hotspotContainer = _interopRequireDefault(require("./hotspot-container"));
39
43
 
44
+ var _classnames = _interopRequireDefault(require("classnames"));
45
+
40
46
  var _utils = require("./utils");
41
47
 
42
48
  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; }
@@ -134,9 +140,15 @@ var Root = /*#__PURE__*/function (_React$Component) {
134
140
  teacherInstructionsEnabled = _ref2.teacherInstructionsEnabled,
135
141
  promptEnabled = _ref2.promptEnabled,
136
142
  rationaleEnabled = _ref2.rationaleEnabled,
137
- spellCheckEnabled = _ref2.spellCheckEnabled;
143
+ spellCheckEnabled = _ref2.spellCheckEnabled,
144
+ errors = _ref2.errors;
145
+
146
+ var _ref3 = errors || {},
147
+ shapesError = _ref3.shapesError,
148
+ selectionsError = _ref3.selectionsError;
138
149
 
139
150
  var toolbarOpts = {};
151
+ var validationMessage = (0, _utils.generateValidationMessage)(configuration);
140
152
 
141
153
  switch (model.toolbarEditorPosition) {
142
154
  case 'top':
@@ -200,10 +212,30 @@ var Root = /*#__PURE__*/function (_React$Component) {
200
212
  imageSupport: imageSupport,
201
213
  toolbarOpts: toolbarOpts,
202
214
  spellCheck: spellCheckEnabled
203
- })), /*#__PURE__*/_react["default"].createElement(_Typography["default"], {
204
- className: classes.label,
215
+ })), /*#__PURE__*/_react["default"].createElement("div", {
216
+ className: (0, _classnames["default"])(classes.label, classes.flexContainer)
217
+ }, /*#__PURE__*/_react["default"].createElement(_Typography["default"], {
218
+ className: classes.subheading,
205
219
  variant: "subheading"
206
- }, "Define Hotspot"), /*#__PURE__*/_react["default"].createElement(_hotspotPalette["default"], {
220
+ }, "Define Hotspot"), /*#__PURE__*/_react["default"].createElement(_Tooltip["default"], {
221
+ classes: {
222
+ tooltip: classes.tooltip
223
+ },
224
+ disableFocusListener: true,
225
+ disableTouchListener: true,
226
+ placement: 'left',
227
+ title: validationMessage
228
+ }, /*#__PURE__*/_react["default"].createElement(_Info["default"], {
229
+ fontSize: 'small',
230
+ color: 'primary',
231
+ style: {
232
+ "float": 'right'
233
+ }
234
+ }))), shapesError && /*#__PURE__*/_react["default"].createElement("div", {
235
+ className: classes.errorText
236
+ }, shapesError), selectionsError && /*#__PURE__*/_react["default"].createElement("div", {
237
+ className: classes.errorText
238
+ }, selectionsError), /*#__PURE__*/_react["default"].createElement(_hotspotPalette["default"], {
207
239
  hotspotColor: model.hotspotColor,
208
240
  hotspotList: model.hotspotList,
209
241
  outlineColor: model.outlineColor,
@@ -282,12 +314,29 @@ var styles = function styles(theme) {
282
314
  paddingTop: theme.spacing.unit * 2,
283
315
  width: '100%'
284
316
  },
317
+ subheading: {
318
+ marginRight: '5px'
319
+ },
285
320
  regular: {
286
321
  marginBottom: theme.spacing.unit * 3
287
322
  },
288
323
  switchElement: {
289
324
  justifyContent: 'space-between',
290
325
  margin: 0
326
+ },
327
+ flexContainer: {
328
+ display: 'flex',
329
+ alignItems: 'center'
330
+ },
331
+ tooltip: {
332
+ fontSize: '12px',
333
+ whiteSpace: 'pre',
334
+ maxWidth: '500px'
335
+ },
336
+ errorText: {
337
+ fontSize: '12px',
338
+ color: 'red',
339
+ padding: '5px 0'
291
340
  }
292
341
  };
293
342
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/root.jsx"],"names":["Panel","settings","toggle","Root","fieldType","color","onColorChanged","props","cType","value","resizeType","model","dimensions","shapes","configuration","preserveAspectRatio","onUpdateImageDimension","onUpdateShapes","nextImageDimensions","updatedDimensions","enabled","shapesArray","updatedShapes","classes","imageSupport","onConfigurationChanged","onImageUpload","onModelChangedByConfig","onPromptChanged","onRationaleChanged","onTeacherInstructionsChanged","multipleCorrect","partialScoring","prompt","teacherInstructions","rationale","spellCheck","teacherInstructionsEnabled","promptEnabled","rationaleEnabled","spellCheckEnabled","toolbarOpts","toolbarEditorPosition","position","base","label","Properties","regular","hotspotColor","hotspotList","outlineColor","outlineList","handleColorChange","imageUrl","strokeWidth","width","e","handleOnUpdateImageDimensions","field","height","React","Component","styles","theme","marginTop","spacing","unit","container","display","flex","paddingTop","marginBottom","switchElement","justifyCont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YAAY,EAAER,KAAK,CAACE,OAAN,CAAcC,IAAd,GAAqB;AAD5B,KAtBc;AAyBvBM,IAAAA,aAAa,EAAE;AACbC,MAAAA,cAAc,EAAE,eADH;AAEbC,MAAAA,MAAM,EAAE;AAFK;AAzBQ,GAAL;AAAA,CAApB;;AA+BAvE,IAAI,CAACwE,SAAL,GAAiB;AACfpD,EAAAA,OAAO,EAAEqD,sBAAUC,MAAV,CAAiBC,UADX;AAEfhE,EAAAA,aAAa,EAAE8D,sBAAUC,MAFV;AAGflE,EAAAA,KAAK,EAAEiE,sBAAUC,MAAV,CAAiBC,UAHT;AAIftD,EAAAA,YAAY,EAAEoD,sBAAUG,KAAV,CAAgB;AAC5BC,IAAAA,GAAG,EAAEJ,sBAAUK,IADa;AAE5B,cAAQL,sBAAUK;AAFU,GAAhB,CAJC;AAQfvD,EAAAA,aAAa,EAAEkD,sBAAUK,IAAV,CAAeH,UARf;AASfxE,EAAAA,cAAc,EAAEsE,sBAAUK,IAAV,CAAeH,UAThB;AAUflD,EAAAA,eAAe,EAAEgD,sBAAUK,IAAV,CAAeH,UAVjB;AAWf9D,EAAAA,sBAAsB,EAAE4D,sBAAUK,IAAV,CAAeH,UAXxB;AAYf7D,EAAAA,cAAc,EAAE2D,sBAAUK,IAAV,CAAeH,UAZhB;AAafnD,EAAAA,sBAAsB,EAAEiD,sBAAUK,IAAV,CAAeH,UAbxB;AAcfjD,EAAAA,kBAAkB,EAAE+C,sBAAUK,IAAV,CAAeH,UAdpB;AAefrD,EAAAA,sBAAsB,EAAEmD,sBAAUK,IAAV,CAAeH,UAfxB;AAgBfhD,EAAAA,4BAA4B,EAAE8C,sBAAUK,IAAV,CAAeH;AAhB9B,CAAjB;;eAmBe,wBAAWhB,MAAX,EAAmB3D,IAAnB,C","sourcesContent":["import React from 'react';\nimport {\n settings,\n layout,\n InputContainer,\n NumberTextField\n} from '@pie-lib/config-ui';\nimport PropTypes from 'prop-types';\nimport EditableHtml from '@pie-lib/editable-html';\nimport Typography from '@material-ui/core/Typography';\nimport { withStyles } from '@material-ui/core/styles';\n\nimport HotspotPalette from './hotspot-palette';\nimport HotspotContainer from './hotspot-container';\nimport { updateImageDimensions, getUpdatedShapes, getAllShapes, groupShapes } from './utils';\n\nconst { Panel, toggle } = settings;\n\nexport class Root extends React.Component {\n handleColorChange = (fieldType, color) => {\n const { onColorChanged } = this.props;\n const cType = `${fieldType}Color`;\n\n onColorChanged(cType, color);\n };\n\n handleOnUpdateImageDimensions = (value, resizeType) => {\n const {\n model: { dimensions, shapes },\n configuration: { preserveAspectRatio = {} },\n onUpdateImageDimension,\n onUpdateShapes,\n } = this.props;\n\n const nextImageDimensions = { ...dimensions, [resizeType]: value };\n\n // if preserveAspectRatio.enabled, updateImageDimensions function makes sure aspect ratio is kept\n const updatedDimensions = updateImageDimensions(\n dimensions,\n nextImageDimensions,\n preserveAspectRatio.enabled,\n resizeType\n );\n // transform shapes map into shapes array\n const shapesArray = getAllShapes(shapes);\n // transform all the shapes to fit the re-sized image\n const updatedShapes = getUpdatedShapes(dimensions, updatedDimensions, shapesArray);\n // transform shapes array back into shapes map\n\n onUpdateShapes(groupShapes(updatedShapes));\n onUpdateImageDimension(updatedDimensions);\n };\n\n render() {\n const {\n classes,\n configuration,\n model,\n imageSupport,\n onConfigurationChanged,\n onImageUpload,\n onModelChangedByConfig,\n onPromptChanged,\n onRationaleChanged,\n onUpdateImageDimension,\n onTeacherInstructionsChanged,\n onUpdateShapes\n } = this.props;\n const {\n multipleCorrect = {},\n partialScoring = {},\n prompt = {},\n teacherInstructions = {},\n rationale = {},\n spellCheck = {},\n preserveAspectRatio = {}\n } = configuration || {};\n const { teacherInstructionsEnabled, promptEnabled, rationaleEnabled, spellCheckEnabled } = model || {};\n const toolbarOpts = {};\n\n switch (model.toolbarEditorPosition) {\n case 'top':\n toolbarOpts.position = 'top';\n break;\n default:\n toolbarOpts.position = 'bottom';\n break;\n }\n\n return (\n <div className={classes.base}>\n <layout.ConfigLayout\n settings={\n <Panel\n model={model}\n onChangeModel={onModelChangedByConfig}\n configuration={configuration}\n onChangeConfiguration={onConfigurationChanged}\n groups={{\n 'Settings': {\n multipleCorrect:\n multipleCorrect.settings && toggle(multipleCorrect.label),\n partialScoring:\n partialScoring.settings && toggle(partialScoring.label),\n promptEnabled:\n prompt.settings && toggle(prompt.label),\n },\n Properties: {\n teacherInstructionsEnabled:\n teacherInstructions.settings && toggle(teacherInstructions.label),\n rationaleEnabled: rationale.settings && toggle(rationale.label),\n spellCheckEnabled:\n spellCheck.settings && toggle(spellCheck.label),\n }\n }}\n />\n }\n >\n <div className={classes.regular}>\n {teacherInstructionsEnabled && (\n <InputContainer label={teacherInstructions.label} className={classes.prompt}>\n <EditableHtml\n markup={model.teacherInstructions || ''}\n onChange={onTeacherInstructionsChanged}\n imageSupport={imageSupport}\n nonEmpty={false}\n toolbarOpts={toolbarOpts}\n spellCheck={spellCheckEnabled}\n />\n </InputContainer>\n )}\n {promptEnabled && (\n <InputContainer label={prompt.label} className={classes.prompt}>\n <EditableHtml\n markup={model.prompt || ''}\n onChange={onPromptChanged}\n imageSupport={imageSupport}\n nonEmpty={false}\n toolbarOpts={toolbarOpts}\n spellCheck={spellCheckEnabled}\n />\n </InputContainer>\n )}\n\n {rationaleEnabled && (\n <InputContainer\n label={rationale.label}\n className={classes.prompt}\n >\n <EditableHtml\n markup={model.rationale || ''}\n onChange={onRationaleChanged}\n imageSupport={imageSupport}\n toolbarOpts={toolbarOpts}\n spellCheck={spellCheckEnabled}\n />\n </InputContainer>\n )}\n\n <Typography className={classes.label} variant=\"subheading\">\n Define Hotspot\n </Typography>\n\n <HotspotPalette\n hotspotColor={model.hotspotColor}\n hotspotList={model.hotspotList}\n outlineColor={model.outlineColor}\n outlineList={model.outlineList}\n onHotspotColorChange={color =>\n this.handleColorChange('hotspot', color)\n }\n onOutlineColorChange={color =>\n this.handleColorChange('outline', color)\n }\n />\n\n <HotspotContainer\n dimensions={model.dimensions}\n imageUrl={model.imageUrl}\n multipleCorrect={model.multipleCorrect}\n hotspotColor={model.hotspotColor}\n outlineColor={model.outlineColor}\n onUpdateImageDimension={onUpdateImageDimension}\n onUpdateShapes={onUpdateShapes}\n onImageUpload={onImageUpload}\n shapes={model.shapes}\n strokeWidth={model.strokeWidth}\n preserveAspectRatioEnabled={preserveAspectRatio.enabled}\n />\n\n {model.imageUrl && (\n <div>\n <Typography className={classes.label} variant=\"subheading\">\n Image Dimensions\n </Typography>\n\n <div className={classes.dimensions}>\n <NumberTextField\n key=\"hotspot-manual-width\"\n label=\"Width\"\n value={model.dimensions.width}\n min={0}\n onChange={(e, value) => this.handleOnUpdateImageDimensions(value, 'width')}\n showErrorWhenOutsideRange\n className={classes.field}\n />\n <NumberTextField\n key=\"hotspot-manual-height\"\n label=\"Height\"\n value={model.dimensions.height}\n min={0}\n onChange={(e, value) => this.handleOnUpdateImageDimensions(value, 'height')}\n showErrorWhenOutsideRange\n className={classes.field}\n />\n </div>\n </div>\n )}\n </div>\n </layout.ConfigLayout>\n </div>\n );\n }\n}\n\nconst styles = theme => ({\n base: {\n marginTop: theme.spacing.unit * 3\n },\n container: {\n display: 'flex',\n marginTop: theme.spacing.unit\n },\n dimensions: {\n display: 'flex'\n },\n field: {\n flex: 1,\n width: '90%'\n },\n label: {\n marginTop: theme.spacing.unit * 4\n },\n prompt: {\n paddingTop: theme.spacing.unit * 2,\n width: '100%'\n },\n regular: {\n marginBottom: theme.spacing.unit * 3\n },\n switchElement: {\n justifyContent: 'space-between',\n margin: 0\n }\n});\n\nRoot.propTypes = {\n classes: PropTypes.object.isRequired,\n configuration: PropTypes.object,\n model: PropTypes.object.isRequired,\n imageSupport: PropTypes.shape({\n add: PropTypes.func,\n delete: PropTypes.func\n }),\n onImageUpload: PropTypes.func.isRequired,\n onColorChanged: PropTypes.func.isRequired,\n onPromptChanged: PropTypes.func.isRequired,\n onUpdateImageDimension: PropTypes.func.isRequired,\n onUpdateShapes: PropTypes.func.isRequired,\n onModelChangedByConfig: PropTypes.func.isRequired,\n onRationaleChanged: PropTypes.func.isRequired,\n onConfigurationChanged: PropTypes.func.isRequired,\n onTeacherInstructionsChanged: PropTypes.func.isRequired,\n};\n\nexport default withStyles(styles)(Root);\n"],"file":"root.js"}
1
+ {"version":3,"sources":["../src/root.jsx"],"names":["Panel","settings","toggle","Root","fieldType","color","onColorChanged","props","cType","value","resizeType","model","dimensions","shapes","configuration","preserveAspectRatio","onUpdateImageDimension","onUpdateShapes","nextImageDimensions","updatedDimensions","enabled","shapesArray","updatedShapes","classes","imageSupport","onConfigurationChanged","onImageUpload","onModelChangedByConfig","onPromptChanged","onRationaleChanged","onTeacherInstructionsChanged","multipleCorrect","partialScoring","prompt","teacherInstructions","rationale","spellCheck","teacherInstructionsEnabled","promptEnabled","rationaleEnabled","spellCheckEnabled","errors","shapesError","selectionsError","toolbarOpts","validationMessage","toolbarEditorPosition","position","base","label","Properties","regular","flexContainer","subheading","tooltip","errorText","hotspotColor","hotspotList","outlineColor","outlineList","handleColorChange","imageUrl","strokeWidth","width","e","handleOnUpdateImageDimensions","field","height","React","Component","styles","theme","marginTop","spacing","unit","container","display","flex","paddingTop","marginRight","marginBottom","switchElement","justifyContent","margin","alignItems","fontSize","whiteSpace","maxWidth","padding","propTypes","PropTypes","object","isRequired","shape","add","func"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AAMA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;;;;;AAQA,IAAQA,KAAR,GAA0BC,kBAA1B,CAAQD,KAAR;AAAA,IAAeE,MAAf,GAA0BD,kBAA1B,CAAeC,MAAf;;IAEaC,I;;;;;;;;;;;;;;;0GACS,UAACC,SAAD,EAAYC,KAAZ,EAAsB;AACxC,UAAQC,cAAR,GAA2B,MAAKC,KAAhC,CAAQD,cAAR;AACA,UAAME,KAAK,aAAMJ,SAAN,UAAX;AAEAE,MAAAA,cAAc,CAACE,KAAD,EAAQH,KAAR,CAAd;AACD,K;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;AAIfpE,EAAAA,YAAY,EAAEkE,sBAAUG,KAAV,CAAgB;AAC5BC,IAAAA,GAAG,EAAEJ,sBAAUK,IADa;AAE5B,cAAQL,sBAAUK;AAFU,GAAhB,CAJC;AAQfrE,EAAAA,aAAa,EAAEgE,sBAAUK,IAAV,CAAeH,UARf;AASftF,EAAAA,cAAc,EAAEoF,sBAAUK,IAAV,CAAeH,UAThB;AAUfhE,EAAAA,eAAe,EAAE8D,sBAAUK,IAAV,CAAeH,UAVjB;AAWf5E,EAAAA,sBAAsB,EAAE0E,sBAAUK,IAAV,CAAeH,UAXxB;AAYf3E,EAAAA,cAAc,EAAEyE,sBAAUK,IAAV,CAAeH,UAZhB;AAafjE,EAAAA,sBAAsB,EAAE+D,sBAAUK,IAAV,CAAeH,UAbxB;AAcf/D,EAAAA,kBAAkB,EAAE6D,sBAAUK,IAAV,CAAeH,UAdpB;AAefnE,EAAAA,sBAAsB,EAAEiE,sBAAUK,IAAV,CAAeH,UAfxB;AAgBf9D,EAAAA,4BAA4B,EAAE4D,sBAAUK,IAAV,CAAeH;AAhB9B,CAAjB;;eAmBe,wBAAWtB,MAAX,EAAmBnE,IAAnB,C","sourcesContent":["import React from 'react';\nimport {\n settings,\n layout,\n InputContainer,\n NumberTextField\n} from '@pie-lib/config-ui';\nimport PropTypes from 'prop-types';\nimport EditableHtml from '@pie-lib/editable-html';\nimport { withStyles } from '@material-ui/core/styles';\nimport Typography from '@material-ui/core/Typography';\nimport Info from '@material-ui/icons/Info';\nimport Tooltip from '@material-ui/core/Tooltip';\nimport HotspotPalette from './hotspot-palette';\nimport HotspotContainer from './hotspot-container';\nimport classNames from 'classnames';\nimport {\n updateImageDimensions,\n generateValidationMessage,\n getUpdatedShapes,\n getAllShapes,\n groupShapes\n} from './utils';\n\nconst { Panel, toggle } = settings;\n\nexport class Root extends React.Component {\n handleColorChange = (fieldType, color) => {\n const { onColorChanged } = this.props;\n const cType = `${fieldType}Color`;\n\n onColorChanged(cType, color);\n };\n\n handleOnUpdateImageDimensions = (value, resizeType) => {\n const {\n model: { dimensions, shapes },\n configuration: { preserveAspectRatio = {} },\n onUpdateImageDimension,\n onUpdateShapes,\n } = this.props;\n\n const nextImageDimensions = { ...dimensions, [resizeType]: value };\n\n // if preserveAspectRatio.enabled, updateImageDimensions function makes sure aspect ratio is kept\n const updatedDimensions = updateImageDimensions(\n dimensions,\n nextImageDimensions,\n preserveAspectRatio.enabled,\n resizeType\n );\n // transform shapes map into shapes array\n const shapesArray = getAllShapes(shapes);\n // transform all the shapes to fit the re-sized image\n const updatedShapes = getUpdatedShapes(dimensions, updatedDimensions, shapesArray);\n // transform shapes array back into shapes map\n\n onUpdateShapes(groupShapes(updatedShapes));\n onUpdateImageDimension(updatedDimensions);\n };\n\n render() {\n const {\n classes,\n configuration,\n model,\n imageSupport,\n onConfigurationChanged,\n onImageUpload,\n onModelChangedByConfig,\n onPromptChanged,\n onRationaleChanged,\n onUpdateImageDimension,\n onTeacherInstructionsChanged,\n onUpdateShapes\n } = this.props;\n const {\n multipleCorrect = {},\n partialScoring = {},\n prompt = {},\n teacherInstructions = {},\n rationale = {},\n spellCheck = {},\n preserveAspectRatio = {}\n } = configuration || {};\n const { teacherInstructionsEnabled, promptEnabled, rationaleEnabled, spellCheckEnabled, errors } = model || {};\n const { shapesError, selectionsError } = errors || {};\n const toolbarOpts = {};\n\n const validationMessage = generateValidationMessage(configuration);\n\n switch (model.toolbarEditorPosition) {\n case 'top':\n toolbarOpts.position = 'top';\n break;\n default:\n toolbarOpts.position = 'bottom';\n break;\n }\n\n return (\n <div className={classes.base}>\n <layout.ConfigLayout\n settings={\n <Panel\n model={model}\n onChangeModel={onModelChangedByConfig}\n configuration={configuration}\n onChangeConfiguration={onConfigurationChanged}\n groups={{\n 'Settings': {\n multipleCorrect:\n multipleCorrect.settings && toggle(multipleCorrect.label),\n partialScoring:\n partialScoring.settings && toggle(partialScoring.label),\n promptEnabled:\n prompt.settings && toggle(prompt.label),\n },\n Properties: {\n teacherInstructionsEnabled:\n teacherInstructions.settings && toggle(teacherInstructions.label),\n rationaleEnabled: rationale.settings && toggle(rationale.label),\n spellCheckEnabled:\n spellCheck.settings && toggle(spellCheck.label),\n }\n }}\n />\n }\n >\n <div className={classes.regular}>\n {teacherInstructionsEnabled && (\n <InputContainer label={teacherInstructions.label} className={classes.prompt}>\n <EditableHtml\n markup={model.teacherInstructions || ''}\n onChange={onTeacherInstructionsChanged}\n imageSupport={imageSupport}\n nonEmpty={false}\n toolbarOpts={toolbarOpts}\n spellCheck={spellCheckEnabled}\n />\n </InputContainer>\n )}\n {promptEnabled && (\n <InputContainer label={prompt.label} className={classes.prompt}>\n <EditableHtml\n markup={model.prompt || ''}\n onChange={onPromptChanged}\n imageSupport={imageSupport}\n nonEmpty={false}\n toolbarOpts={toolbarOpts}\n spellCheck={spellCheckEnabled}\n />\n </InputContainer>\n )}\n\n {rationaleEnabled && (\n <InputContainer\n label={rationale.label}\n className={classes.prompt}\n >\n <EditableHtml\n markup={model.rationale || ''}\n onChange={onRationaleChanged}\n imageSupport={imageSupport}\n toolbarOpts={toolbarOpts}\n spellCheck={spellCheckEnabled}\n />\n </InputContainer>\n )}\n\n <div className={classNames(classes.label, classes.flexContainer)}>\n <Typography className={classes.subheading} variant=\"subheading\">\n Define Hotspot\n </Typography>\n <Tooltip\n classes={{ tooltip: classes.tooltip }}\n disableFocusListener\n disableTouchListener\n placement={'left'}\n title={validationMessage}\n >\n <Info fontSize={'small'} color={'primary'} style={{ float: 'right' }}/>\n </Tooltip>\n </div>\n {shapesError && <div className={classes.errorText}>{shapesError}</div>}\n {selectionsError && <div className={classes.errorText}>{selectionsError}</div>}\n\n <HotspotPalette\n hotspotColor={model.hotspotColor}\n hotspotList={model.hotspotList}\n outlineColor={model.outlineColor}\n outlineList={model.outlineList}\n onHotspotColorChange={color =>\n this.handleColorChange('hotspot', color)\n }\n onOutlineColorChange={color =>\n this.handleColorChange('outline', color)\n }\n />\n\n <HotspotContainer\n dimensions={model.dimensions}\n imageUrl={model.imageUrl}\n multipleCorrect={model.multipleCorrect}\n hotspotColor={model.hotspotColor}\n outlineColor={model.outlineColor}\n onUpdateImageDimension={onUpdateImageDimension}\n onUpdateShapes={onUpdateShapes}\n onImageUpload={onImageUpload}\n shapes={model.shapes}\n strokeWidth={model.strokeWidth}\n preserveAspectRatioEnabled={preserveAspectRatio.enabled}\n />\n\n {model.imageUrl && (\n <div>\n <Typography className={classes.label} variant=\"subheading\">\n Image Dimensions\n </Typography>\n\n <div className={classes.dimensions}>\n <NumberTextField\n key=\"hotspot-manual-width\"\n label=\"Width\"\n value={model.dimensions.width}\n min={0}\n onChange={(e, value) => this.handleOnUpdateImageDimensions(value, 'width')}\n showErrorWhenOutsideRange\n className={classes.field}\n />\n <NumberTextField\n key=\"hotspot-manual-height\"\n label=\"Height\"\n value={model.dimensions.height}\n min={0}\n onChange={(e, value) => this.handleOnUpdateImageDimensions(value, 'height')}\n showErrorWhenOutsideRange\n className={classes.field}\n />\n </div>\n </div>\n )}\n </div>\n </layout.ConfigLayout>\n </div>\n );\n }\n}\n\nconst styles = theme => ({\n base: {\n marginTop: theme.spacing.unit * 3\n },\n container: {\n display: 'flex',\n marginTop: theme.spacing.unit\n },\n dimensions: {\n display: 'flex'\n },\n field: {\n flex: 1,\n width: '90%'\n },\n label: {\n marginTop: theme.spacing.unit * 4\n },\n prompt: {\n paddingTop: theme.spacing.unit * 2,\n width: '100%'\n },\n subheading: {\n marginRight: '5px'\n },\n regular: {\n marginBottom: theme.spacing.unit * 3\n },\n switchElement: {\n justifyContent: 'space-between',\n margin: 0\n },\n flexContainer: {\n display: 'flex',\n alignItems: 'center'\n },\n tooltip: {\n fontSize: '12px',\n whiteSpace: 'pre',\n maxWidth: '500px',\n },\n errorText: {\n fontSize: '12px',\n color: 'red',\n padding: '5px 0'\n }\n});\n\nRoot.propTypes = {\n classes: PropTypes.object.isRequired,\n configuration: PropTypes.object,\n model: PropTypes.object.isRequired,\n imageSupport: PropTypes.shape({\n add: PropTypes.func,\n delete: PropTypes.func\n }),\n onImageUpload: PropTypes.func.isRequired,\n onColorChanged: PropTypes.func.isRequired,\n onPromptChanged: PropTypes.func.isRequired,\n onUpdateImageDimension: PropTypes.func.isRequired,\n onUpdateShapes: PropTypes.func.isRequired,\n onModelChangedByConfig: PropTypes.func.isRequired,\n onRationaleChanged: PropTypes.func.isRequired,\n onConfigurationChanged: PropTypes.func.isRequired,\n onTeacherInstructionsChanged: PropTypes.func.isRequired,\n};\n\nexport default withStyles(styles)(Root);\n"],"file":"root.js"}
@@ -5,7 +5,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
- exports.updateImageDimensions = exports.groupShapes = exports.getUpdatedShapes = exports.getUpdatedRectangle = exports.getUpdatedPlygon = exports.getAllShapes = void 0;
8
+ exports.updateImageDimensions = exports.groupShapes = exports.getUpdatedShapes = exports.getUpdatedRectangle = exports.getUpdatedPlygon = exports.getAllShapes = exports.generateValidationMessage = void 0;
9
9
 
10
10
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
11
11
 
@@ -145,4 +145,16 @@ var groupShapes = function groupShapes(shapesArray) {
145
145
  };
146
146
 
147
147
  exports.groupShapes = groupShapes;
148
+
149
+ var generateValidationMessage = function generateValidationMessage(config) {
150
+ var minShapes = config.minShapes,
151
+ maxShapes = config.maxShapes,
152
+ maxSelections = config.maxSelections;
153
+ var shapesMessage = "\nThere should be at least ".concat(minShapes, " ") + (maxShapes ? "and at most ".concat(maxShapes, " ") : '') + 'shapes defined.';
154
+ var selectionsMessage = "\nThere should be at least 1 " + (maxSelections ? "and at most ".concat(maxSelections, " ") : '') + 'shape' + (maxSelections ? 's' : '') + ' selected.';
155
+ var message = 'Validation requirements:' + shapesMessage + selectionsMessage;
156
+ return message;
157
+ };
158
+
159
+ exports.generateValidationMessage = generateValidationMessage;
148
160
  //# sourceMappingURL=utils.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/utils.js"],"names":["updateImageDimensions","initialDim","nextDim","keepAspectRatio","resizeType","imageAspectRatio","width","height","getDelta","referenceInitialValue","referenceNextValue","currentValue","getUpdatedRectangle","shape","x","y","getUpdatedPlygon","points","map","point","getUpdatedShapes","shapes","group","getAllShapes","shapesMap","shapesArray","shapesKeys","Object","keys","length","reduce","acc","currentShapeKey","concat","index","groupShapes","rectangles","polygons","shapeProps"],"mappings":";;;;;;;;;;;;;;;AAAA;;;;;;;;AAEA,IAAMA,qBAAqB,GAAG,SAAxBA,qBAAwB,CAACC,UAAD,EAAaC,OAAb,EAAsBC,eAAtB,EAAuCC,UAAvC,EAAsD;AAClF;AACA,MAAID,eAAJ,EAAqB;AACnB,QAAME,gBAAgB,GAAGJ,UAAU,CAACK,KAAX,GAAmBL,UAAU,CAACM,MAAvD;;AAEA,QAAIH,UAAU,KAAK,QAAnB,EAA6B;AAC3B;AACA,aAAO;AACLE,QAAAA,KAAK,EAAEJ,OAAO,CAACK,MAAR,GAAiBF,gBADnB;AAELE,QAAAA,MAAM,EAAEL,OAAO,CAACK;AAFX,OAAP;AAID,KATkB,CAWnB;;;AACA,WAAO;AACLD,MAAAA,KAAK,EAAEJ,OAAO,CAACI,KADV;AAELC,MAAAA,MAAM,EAAEL,OAAO,CAACI,KAAR,GAAgBD;AAFnB,KAAP;AAID,GAlBiF,CAoBlF;;;AACA,SAAO;AACLC,IAAAA,KAAK,EAAEJ,OAAO,CAACI,KADV;AAELC,IAAAA,MAAM,EAAEL,OAAO,CAACK;AAFX,GAAP;AAID,CAzBD,C,CA2BA;AACA;AACA;;;;;AACA,IAAMC,QAAQ,GAAG,SAAXA,QAAW,CAACC,qBAAD,EAAwBC,kBAAxB,EAA4CC,YAA5C;AAAA,SAA8DD,kBAAkB,GAAGD,qBAAtB,GAA+CE,YAA5G;AAAA,CAAjB;;AAEA,IAAMC,mBAAmB,GAAG,SAAtBA,mBAAsB,CAACX,U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AAW,CAACI,MAAhB,EAAwB;AACtB,WAAOJ,WAAW,CAACK,MAAZ,CAAmB,UAACC,GAAD,QAAmC;AAAA,UAA3BT,KAA2B,QAA3BA,KAA2B;AAAA,UAAjBgB,UAAiB;AAC3DP,MAAAA,GAAG,CAACT,KAAD,CAAH,iDAAkBS,GAAG,CAACT,KAAD,CAAH,IAAc,EAAhC,IAAqCgB,UAArC;AACA,aAAOP,GAAP;AACD,KAHM,EAGJP,SAHI,CAAP;AAID;;AAED,SAAO,2BAAUA,SAAV,CAAP;AACD,CAfD","sourcesContent":["import cloneDeep from 'lodash/cloneDeep';\n\nconst updateImageDimensions = (initialDim, nextDim, keepAspectRatio, resizeType) => {\n // if we want to keep image aspect ratio\n if (keepAspectRatio) {\n const imageAspectRatio = initialDim.width / initialDim.height;\n\n if (resizeType === 'height') {\n // if we want to change image height => we update the width accordingly\n return {\n width: nextDim.height * imageAspectRatio,\n height: nextDim.height\n }\n }\n\n // if we want to change image width => we update the height accordingly\n return {\n width: nextDim.width,\n height: nextDim.width / imageAspectRatio\n }\n }\n\n // if we don't want to keep aspect ratio, we just update both values\n return {\n width: nextDim.width,\n height: nextDim.height\n }\n};\n\n// referenceInitialValue = the initial value of the Stage\n// referenceNextValue = the next value of the Stage\n// currentValue = the value that has to be re-sized influenced by the changes that were made on the Stage\nconst getDelta = (referenceInitialValue, referenceNextValue, currentValue) => (referenceNextValue / referenceInitialValue) * currentValue;\n\nconst getUpdatedRectangle = (initialDim, nextDim, shape) => ({\n ...shape,\n width: getDelta(initialDim.width, nextDim.width, shape.width),\n height: getDelta(initialDim.height, nextDim.height, shape.height),\n x: getDelta(initialDim.width, nextDim.width, shape.x),\n y: getDelta(initialDim.height, nextDim.height, shape.y),\n});\n\nconst getUpdatedPlygon = (initialDim, nextDim, shape) => ({\n ...shape,\n points: shape.points.map(point => ({\n x: getDelta(initialDim.width, nextDim.width, point.x),\n y: getDelta(initialDim.height, nextDim.height, point.y),\n }))\n});\n\n// initialDim = the initial dimensions: { width, height } of the Stage\n// nextDim = the next dimensions: { width, height } of the Stage\n// shapes = array of shapes that have to be re-sized and re-positioned\nconst getUpdatedShapes = (initialDim, nextDim, shapes) => {\n return shapes.map(shape => {\n if (shape.group === 'rectangles') {\n return getUpdatedRectangle(initialDim, nextDim, shape);\n }\n\n if (shape.group === 'polygons') {\n return getUpdatedPlygon(initialDim, nextDim, shape);\n }\n });\n};\n\n// converts shapes map to shapes array\n// example:\n// from: { rectangles: [r1], polygons: [p1, p2]}\n// to: [{ ...r1, group: 'rectangles' }, { ...p1, group: 'polygons' }, { ...p2, group: 'polygons' }]\n// if a shape has index defined, keep it, otherwise initialize it\n// index is used for the UNDO function\nconst getAllShapes = (shapesMap) => {\n shapesMap = shapesMap || {};\n const shapesArray = [];\n const shapesKeys = Object.keys(shapesMap);\n\n return shapesKeys.length\n ? shapesKeys.reduce((acc, currentShapeKey) =>\n acc.concat(\n shapesMap[currentShapeKey]\n ? shapesMap[currentShapeKey].map((shape, index) => ({\n ...shape,\n group: currentShapeKey,\n index: shape.index || acc.length + index\n }))\n : []),\n shapesArray)\n : shapesArray;\n};\n\n// converts shapes array to shapes map\n// is the reverse of getAllShapes function\n// example:\n// from: [{ ...r1, group: 'rectangles' }, { ...p1, group: 'polygons' }, { ...p2, group: 'polygons' }]\n// to: { rectangles: [r1], polygons: [p1, p2]}\nconst groupShapes = (shapesArray) => {\n shapesArray = shapesArray || [];\n const shapesMap = {\n rectangles: [],\n polygons: []\n };\n\n if (shapesArray.length) {\n return shapesArray.reduce((acc, { group, ...shapeProps }) => {\n acc[group] = [...(acc[group] || []), shapeProps];\n return acc;\n }, shapesMap);\n }\n\n return cloneDeep(shapesMap);\n};\n\n\nexport { updateImageDimensions, getUpdatedShapes, getAllShapes, groupShapes, getUpdatedRectangle, getUpdatedPlygon };\n"],"file":"utils.js"}
1
+ {"version":3,"sources":["../src/utils.js"],"names":["updateImageDimensions","initialDim","nextDim","keepAspectRatio","resizeType","imageAspectRatio","width","height","getDelta","referenceInitialValue","referenceNextValue","currentValue","getUpdatedRectangle","shape","x","y","getUpdatedPlygon","points","map","point","getUpdatedShapes","shapes","group","getAllShapes","shapesMap","shapesArray","shapesKeys","Object","keys","length","reduce","acc","currentShapeKey","concat","index","groupShapes","rectangles","polygons","shapeProps","generateValidationMessage","config","minShapes","maxShapes","maxSelections","shapesMessage","selectionsMessage","message"],"mappings":";;;;;;;;;;;;;;;AAAA;;;;;;;;AAEA,IAAMA,qBAAqB,GAAG,SAAxBA,qBAAwB,CAACC,UAAD,EAAaC,OAAb,EAAsBC,eAAtB,EAAuCC,UAAvC,EAAsD;AAClF;AACA,MAAID,eAAJ,EAAqB;AACnB,QAAME,gBAAgB,GAAGJ,UAAU,CAACK,KAAX,GAAmBL,UAAU,CAACM,MAAvD;;AAEA,QAAIH,UAAU,KAAK,QAAnB,EAA6B;AAC3B;AACA,aAAO;AACLE,QAAAA,KAAK,EAAEJ,OAAO,CAACK,MAAR,GAAiBF,gBADnB;AAELE,QAAAA,MAAM,EAAEL,OAAO,CAACK;AAFX,OAAP;AAID,KATkB,CAWnB;;;AACA,WAAO;AACLD,MAAAA,KAAK,EAAEJ,OAAO,CAACI,KADV;AAELC,MAAAA,MAAM,EAAEL,OAAO,CAACI,KAAR,GAAgBD;AAFnB,KAAP;AAID,GAlBiF,CAoBlF;;;AACA,SAAO;AACLC,IAAAA,KAAK,EAAEJ,OAAO,CAACI,KADV;AAELC,IAAAA,MAAM,EAAEL,OAAO,CAACK;AAFX,GAAP;AAID,CAzBD,C,CA2BA;AACA;AACA;;;;;AACA,IAAMC,QAAQ,GAAG,SAAXA,QAAW,CAACC,qBAAD,EAAwBC,kBAAxB,EAA4CC,YAA5C;AAAA,SAA8DD,kBAAkB,GAAGD,qBAAtB,GAA+CE,YAA5G;AAAA,CAAjB;;AAEA,IAAMC,mBAAmB,GAAG,SAAtBA,mBAAsB,CAACX,UAAD,EAAaC,OAAb,EAAsBW,KAAtB;AAAA,yCACvBA,KADuB;AAE1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CAAmB,UAACC,GAAD,QAAmC;AAAA,UAA3BT,KAA2B,QAA3BA,KAA2B;AAAA,UAAjBgB,UAAiB;AAC3DP,MAAAA,GAAG,CAACT,KAAD,CAAH,iDAAkBS,GAAG,CAACT,KAAD,CAAH,IAAc,EAAhC,IAAqCgB,UAArC;AACA,aAAOP,GAAP;AACD,KAHM,EAGJP,SAHI,CAAP;AAID;;AAED,SAAO,2BAAUA,SAAV,CAAP;AACD,CAfD;;;;AAiBA,IAAMe,yBAAyB,GAAG,SAA5BA,yBAA4B,CAAAC,MAAM,EAAI;AAC1C,MAAQC,SAAR,GAAgDD,MAAhD,CAAQC,SAAR;AAAA,MAAmBC,SAAnB,GAAgDF,MAAhD,CAAmBE,SAAnB;AAAA,MAA8BC,aAA9B,GAAgDH,MAAhD,CAA8BG,aAA9B;AAEA,MAAMC,aAAa,GAAG,qCAA8BH,SAA9B,UACnBC,SAAS,yBAAkBA,SAAlB,SAAiC,EADvB,IAC6B,iBADnD;AAGA,MAAMG,iBAAiB,GAAG,mCACvBF,aAAa,yBAAkBA,aAAlB,SAAqC,EAD3B,IACiC,OADjC,IAEvBA,aAAa,GAAG,GAAH,GAAS,EAFC,IAEM,YAFhC;AAIA,MAAMG,OAAO,GAAG,6BAA6BF,aAA7B,GAA6CC,iBAA7D;AAEA,SAAOC,OAAP;AACD,CAbD","sourcesContent":["import cloneDeep from 'lodash/cloneDeep';\n\nconst updateImageDimensions = (initialDim, nextDim, keepAspectRatio, resizeType) => {\n // if we want to keep image aspect ratio\n if (keepAspectRatio) {\n const imageAspectRatio = initialDim.width / initialDim.height;\n\n if (resizeType === 'height') {\n // if we want to change image height => we update the width accordingly\n return {\n width: nextDim.height * imageAspectRatio,\n height: nextDim.height\n }\n }\n\n // if we want to change image width => we update the height accordingly\n return {\n width: nextDim.width,\n height: nextDim.width / imageAspectRatio\n }\n }\n\n // if we don't want to keep aspect ratio, we just update both values\n return {\n width: nextDim.width,\n height: nextDim.height\n }\n};\n\n// referenceInitialValue = the initial value of the Stage\n// referenceNextValue = the next value of the Stage\n// currentValue = the value that has to be re-sized influenced by the changes that were made on the Stage\nconst getDelta = (referenceInitialValue, referenceNextValue, currentValue) => (referenceNextValue / referenceInitialValue) * currentValue;\n\nconst getUpdatedRectangle = (initialDim, nextDim, shape) => ({\n ...shape,\n width: getDelta(initialDim.width, nextDim.width, shape.width),\n height: getDelta(initialDim.height, nextDim.height, shape.height),\n x: getDelta(initialDim.width, nextDim.width, shape.x),\n y: getDelta(initialDim.height, nextDim.height, shape.y),\n});\n\nconst getUpdatedPlygon = (initialDim, nextDim, shape) => ({\n ...shape,\n points: shape.points.map(point => ({\n x: getDelta(initialDim.width, nextDim.width, point.x),\n y: getDelta(initialDim.height, nextDim.height, point.y),\n }))\n});\n\n// initialDim = the initial dimensions: { width, height } of the Stage\n// nextDim = the next dimensions: { width, height } of the Stage\n// shapes = array of shapes that have to be re-sized and re-positioned\nconst getUpdatedShapes = (initialDim, nextDim, shapes) => {\n return shapes.map(shape => {\n if (shape.group === 'rectangles') {\n return getUpdatedRectangle(initialDim, nextDim, shape);\n }\n\n if (shape.group === 'polygons') {\n return getUpdatedPlygon(initialDim, nextDim, shape);\n }\n });\n};\n\n// converts shapes map to shapes array\n// example:\n// from: { rectangles: [r1], polygons: [p1, p2]}\n// to: [{ ...r1, group: 'rectangles' }, { ...p1, group: 'polygons' }, { ...p2, group: 'polygons' }]\n// if a shape has index defined, keep it, otherwise initialize it\n// index is used for the UNDO function\nconst getAllShapes = (shapesMap) => {\n shapesMap = shapesMap || {};\n const shapesArray = [];\n const shapesKeys = Object.keys(shapesMap);\n\n return shapesKeys.length\n ? shapesKeys.reduce((acc, currentShapeKey) =>\n acc.concat(\n shapesMap[currentShapeKey]\n ? shapesMap[currentShapeKey].map((shape, index) => ({\n ...shape,\n group: currentShapeKey,\n index: shape.index || acc.length + index\n }))\n : []),\n shapesArray)\n : shapesArray;\n};\n\n// converts shapes array to shapes map\n// is the reverse of getAllShapes function\n// example:\n// from: [{ ...r1, group: 'rectangles' }, { ...p1, group: 'polygons' }, { ...p2, group: 'polygons' }]\n// to: { rectangles: [r1], polygons: [p1, p2]}\nconst groupShapes = (shapesArray) => {\n shapesArray = shapesArray || [];\n const shapesMap = {\n rectangles: [],\n polygons: []\n };\n\n if (shapesArray.length) {\n return shapesArray.reduce((acc, { group, ...shapeProps }) => {\n acc[group] = [...(acc[group] || []), shapeProps];\n return acc;\n }, shapesMap);\n }\n\n return cloneDeep(shapesMap);\n};\n\nconst generateValidationMessage = config => {\n const { minShapes, maxShapes, maxSelections } = config;\n\n const shapesMessage = `\\nThere should be at least ${minShapes} ` +\n (maxShapes ? `and at most ${maxShapes} ` : '') + 'shapes defined.';\n\n const selectionsMessage = `\\nThere should be at least 1 ` +\n (maxSelections ? `and at most ${maxSelections} ` : '') + 'shape' +\n (maxSelections ? 's' : '') + ' selected.';\n\n const message = 'Validation requirements:' + shapesMessage + selectionsMessage;\n\n return message;\n};\n\nexport {\n updateImageDimensions,\n generateValidationMessage,\n getUpdatedShapes,\n getAllShapes,\n groupShapes,\n getUpdatedRectangle,\n getUpdatedPlygon\n};\n"],"file":"utils.js"}
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@pie-element/hotspot-configure",
3
3
  "private": true,
4
- "version": "4.6.15",
4
+ "version": "4.7.1",
5
5
  "description": "",
6
6
  "main": "lib/index.js",
7
7
  "module": "src/index.js",
@@ -10,8 +10,8 @@
10
10
  "@material-ui/core": "^3.9.2",
11
11
  "@material-ui/icons": "^3.0.2",
12
12
  "@pie-framework/pie-configure-events": "^1.2.0",
13
- "@pie-lib/config-ui": "^10.10.24",
14
- "@pie-lib/editable-html": "^7.19.3",
13
+ "@pie-lib/config-ui": "^10.12.2",
14
+ "@pie-lib/editable-html": "^7.22.2",
15
15
  "classnames": "^2.2.6",
16
16
  "debug": "^3.1.0",
17
17
  "konva": "^3.2.4",
@@ -7,6 +7,7 @@ exports[`Root render renders 1`] = `
7
7
  <Panel
8
8
  configuration={
9
9
  Object {
10
+ "minShapes": 2,
10
11
  "multipleCorrect": Object {
11
12
  "label": "Multiple Correct Responses",
12
13
  "settings": true,
@@ -176,11 +177,38 @@ exports[`Root render renders 1`] = `
176
177
  }
177
178
  >
178
179
  <div>
179
- <WithStyles(Typography)
180
- variant="subheading"
180
+ <div
181
+ className=""
181
182
  >
182
- Define Hotspot
183
- </WithStyles(Typography)>
183
+ <WithStyles(Typography)
184
+ variant="subheading"
185
+ >
186
+ Define Hotspot
187
+ </WithStyles(Typography)>
188
+ <WithStyles(Tooltip)
189
+ classes={
190
+ Object {
191
+ "tooltip": undefined,
192
+ }
193
+ }
194
+ disableFocusListener={true}
195
+ disableTouchListener={true}
196
+ placement="left"
197
+ title="Validation requirements:
198
+ There should be at least 2 shapes defined.
199
+ There should be at least 1 shape selected."
200
+ >
201
+ <pure(InfoIcon)
202
+ color="primary"
203
+ fontSize="small"
204
+ style={
205
+ Object {
206
+ "float": "right",
207
+ }
208
+ }
209
+ />
210
+ </WithStyles(Tooltip)>
211
+ </div>
184
212
  <WithStyles(Palette)
185
213
  hotspotColor="rgba(137, 183, 244, 0.65)"
186
214
  hotspotList={
@@ -57,6 +57,7 @@ export default {
57
57
  settings: false,
58
58
  enabled: true,
59
59
  label: 'Preserve aspect ratio'
60
- }
60
+ },
61
+ minShapes: 2
61
62
  }
62
63
  };
@@ -215,7 +215,7 @@ export class Drawable extends React.Component {
215
215
  const resizeValid = this.checkIfResizeValid(width, height);
216
216
  const hasMinimumWidth = width > 150 && height > 150;
217
217
 
218
- if (resizeValid && hasMinimumWidth) {
218
+ if (resizeValid && hasMinimumWidth && box) {
219
219
  box.style.width = `${width}px`;
220
220
  box.style.height = `${height}px`;
221
221
 
@@ -7,12 +7,20 @@ import {
7
7
  } from '@pie-lib/config-ui';
8
8
  import PropTypes from 'prop-types';
9
9
  import EditableHtml from '@pie-lib/editable-html';
10
- import Typography from '@material-ui/core/Typography';
11
10
  import { withStyles } from '@material-ui/core/styles';
12
-
11
+ import Typography from '@material-ui/core/Typography';
12
+ import Info from '@material-ui/icons/Info';
13
+ import Tooltip from '@material-ui/core/Tooltip';
13
14
  import HotspotPalette from './hotspot-palette';
14
15
  import HotspotContainer from './hotspot-container';
15
- import { updateImageDimensions, getUpdatedShapes, getAllShapes, groupShapes } from './utils';
16
+ import classNames from 'classnames';
17
+ import {
18
+ updateImageDimensions,
19
+ generateValidationMessage,
20
+ getUpdatedShapes,
21
+ getAllShapes,
22
+ groupShapes
23
+ } from './utils';
16
24
 
17
25
  const { Panel, toggle } = settings;
18
26
 
@@ -75,9 +83,12 @@ export class Root extends React.Component {
75
83
  spellCheck = {},
76
84
  preserveAspectRatio = {}
77
85
  } = configuration || {};
78
- const { teacherInstructionsEnabled, promptEnabled, rationaleEnabled, spellCheckEnabled } = model || {};
86
+ const { teacherInstructionsEnabled, promptEnabled, rationaleEnabled, spellCheckEnabled, errors } = model || {};
87
+ const { shapesError, selectionsError } = errors || {};
79
88
  const toolbarOpts = {};
80
89
 
90
+ const validationMessage = generateValidationMessage(configuration);
91
+
81
92
  switch (model.toolbarEditorPosition) {
82
93
  case 'top':
83
94
  toolbarOpts.position = 'top';
@@ -157,9 +168,22 @@ export class Root extends React.Component {
157
168
  </InputContainer>
158
169
  )}
159
170
 
160
- <Typography className={classes.label} variant="subheading">
161
- Define Hotspot
162
- </Typography>
171
+ <div className={classNames(classes.label, classes.flexContainer)}>
172
+ <Typography className={classes.subheading} variant="subheading">
173
+ Define Hotspot
174
+ </Typography>
175
+ <Tooltip
176
+ classes={{ tooltip: classes.tooltip }}
177
+ disableFocusListener
178
+ disableTouchListener
179
+ placement={'left'}
180
+ title={validationMessage}
181
+ >
182
+ <Info fontSize={'small'} color={'primary'} style={{ float: 'right' }}/>
183
+ </Tooltip>
184
+ </div>
185
+ {shapesError && <div className={classes.errorText}>{shapesError}</div>}
186
+ {selectionsError && <div className={classes.errorText}>{selectionsError}</div>}
163
187
 
164
188
  <HotspotPalette
165
189
  hotspotColor={model.hotspotColor}
@@ -245,12 +269,29 @@ const styles = theme => ({
245
269
  paddingTop: theme.spacing.unit * 2,
246
270
  width: '100%'
247
271
  },
272
+ subheading: {
273
+ marginRight: '5px'
274
+ },
248
275
  regular: {
249
276
  marginBottom: theme.spacing.unit * 3
250
277
  },
251
278
  switchElement: {
252
279
  justifyContent: 'space-between',
253
280
  margin: 0
281
+ },
282
+ flexContainer: {
283
+ display: 'flex',
284
+ alignItems: 'center'
285
+ },
286
+ tooltip: {
287
+ fontSize: '12px',
288
+ whiteSpace: 'pre',
289
+ maxWidth: '500px',
290
+ },
291
+ errorText: {
292
+ fontSize: '12px',
293
+ color: 'red',
294
+ padding: '5px 0'
254
295
  }
255
296
  });
256
297
 
@@ -110,5 +110,27 @@ const groupShapes = (shapesArray) => {
110
110
  return cloneDeep(shapesMap);
111
111
  };
112
112
 
113
+ const generateValidationMessage = config => {
114
+ const { minShapes, maxShapes, maxSelections } = config;
113
115
 
114
- export { updateImageDimensions, getUpdatedShapes, getAllShapes, groupShapes, getUpdatedRectangle, getUpdatedPlygon };
116
+ const shapesMessage = `\nThere should be at least ${minShapes} ` +
117
+ (maxShapes ? `and at most ${maxShapes} ` : '') + 'shapes defined.';
118
+
119
+ const selectionsMessage = `\nThere should be at least 1 ` +
120
+ (maxSelections ? `and at most ${maxSelections} ` : '') + 'shape' +
121
+ (maxSelections ? 's' : '') + ' selected.';
122
+
123
+ const message = 'Validation requirements:' + shapesMessage + selectionsMessage;
124
+
125
+ return message;
126
+ };
127
+
128
+ export {
129
+ updateImageDimensions,
130
+ generateValidationMessage,
131
+ getUpdatedShapes,
132
+ getAllShapes,
133
+ groupShapes,
134
+ getUpdatedRectangle,
135
+ getUpdatedPlygon
136
+ };
@@ -3,6 +3,18 @@
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.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)
7
+
8
+
9
+ ### Features
10
+
11
+ * **hotspot:** added configurable validation PD-1702 ([18eb985](https://github.com/pie-framework/pie-elements/commit/18eb98568adf9248dc616a9ae71d9f8394b62fc1))
12
+ * **hotspot:** PD-1703 implement ui/ux for item validation ([a962183](https://github.com/pie-framework/pie-elements/commit/a962183d0941936b69a95b32002135507d769170))
13
+
14
+
15
+
16
+
17
+
6
18
  ## [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)
7
19
 
8
20
  **Note:** Version bump only for package @pie-element/hotspot-controller
@@ -9,6 +9,7 @@ exports.createDefaultModel = exports.createCorrectResponseSession = void 0;
9
9
  exports.model = model;
10
10
  exports.normalize = void 0;
11
11
  exports.outcome = outcome;
12
+ exports.validate = void 0;
12
13
 
13
14
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
14
15
 
@@ -225,4 +226,38 @@ var createCorrectResponseSession = function createCorrectResponseSession(questio
225
226
  };
226
227
 
227
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;
228
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","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"],"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,EAAE,IADgB;AAE/BC,IAAAA,gBAAgB,EAAE,IAFa;AAG/BC,IAAAA,0BAA0B,EAAE,IAHG;AAI/BC,IAAAA,0BAA0B,EAAE,IAJG;AAK/BC,IAAAA,WAAW,EAAE;AALkB,KAM5BL,QAN4B;AAAA,CAA1B;;;;AASA,SAASM,KAAT,CAAeN,Q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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 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: [\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","reduce","acc","nbOfSelections","nbOfShapes","shapesError","selectionsError"],"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,EAAE,IADgB;AAE/BC,IAAAA,gBAAgB,EAAE,IAFa;AAG/BC,IAAAA,0BAA0B,EAAE,IAHG;AAI/BC,IAAAA,0BAA0B,EAAE,IAJG;AAK/BC,IAAAA,WAAW,EAAE;AALkB,KAM5BL,QAN4B;AAAA,CAA1B;;;;AASA,SAASM,KAAT,CAAeN,QAAf,EAAyBO,OAAzB,EAAkCC,GAAlC,EAAuC;AAC5C,MAAMC,kBAAkB,GAAGV,SAAS,CAACC,QAAD,CAApC;AACA,MACEU,QADF,GASID,kBATJ,CACEC,QADF;AAAA,MAEEC,UAFF,GASIF,kBATJ,CAEEE,UAFF;AAAA,MAGEC,YAHF,GASIH,kBATJ,CAGEG,YAHF;AAAA,MAIEC,eAJF,GASIJ,kBATJ,CAIEI,eAJF;AAAA,MAKEC,YALF,GASIL,kBATJ,CAKEK,YALF;AAAA,MAMEC,cANF,GASIN,kBATJ,CAMEM,cANF;AAAA,MAOEC,MAPF,GASIP,kBATJ,CAOEO,MAPF;AAAA,MAQEC,MARF,GASIR,kBATJ,CAQEQ,MARF;;AAUA,aAAiCA,MAAM,IAAI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,EAAuE,EAAvE,CAAlB;AAEA,MAAM8B,cAAc,GAAG,CAACL,SAAS,IAAI,EAAd,EAAkBG,MAAlB,CAAyB,UAACC,GAAD,EAAM7B,KAAN;AAAA,WAAgBA,KAAK,CAACF,OAAN,GAAgB+B,GAAG,GAAG,CAAtB,GAA0BA,GAA1C;AAAA,GAAzB,EAAwE,CAAxE,CAAvB;AAEA,MAAME,UAAU,GAAG,CAACN,SAAS,IAAI,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 {\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 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: [\n ...rectangleCorrect,\n ...polygonsCorrect\n ],\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,7 +1,7 @@
1
1
  {
2
2
  "name": "@pie-element/hotspot-controller",
3
3
  "private": true,
4
- "version": "3.4.8",
4
+ "version": "3.5.0",
5
5
  "description": "",
6
6
  "scripts": {
7
7
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -169,3 +169,29 @@ export const createCorrectResponseSession = (question, env) => {
169
169
  }
170
170
  });
171
171
  };
172
+
173
+ export const validate = (model = {}, config = {}) => {
174
+ const { shapes } = model;
175
+ const { minShapes = 2, maxShapes, maxSelections } = config;
176
+ const errors = {};
177
+
178
+ const allShapes = Object.values(shapes || {}).reduce((acc, shape) => [...acc, ...shape], []);
179
+
180
+ const nbOfSelections = (allShapes || []).reduce((acc, shape) => shape.correct ? acc + 1 : acc, 0);
181
+
182
+ const nbOfShapes = (allShapes || []).length;
183
+
184
+ if (nbOfShapes < minShapes) {
185
+ errors.shapesError = `There should be at least ${minShapes} shapes defined.`;
186
+ } else if (nbOfShapes > maxShapes) {
187
+ errors.shapesError = `No more than ${maxShapes} shapes should be defined.`;
188
+ }
189
+
190
+ if (nbOfSelections < 1) {
191
+ errors.selectionsError = 'There should be at least 1 shape selected.';
192
+ } else if (nbOfSelections > maxSelections) {
193
+ errors.selectionsError = `No more than ${maxSelections} shapes should be selected.`;
194
+ }
195
+
196
+ return errors;
197
+ };
package/lib/index.js CHANGED
@@ -64,6 +64,9 @@ var Hotspot = /*#__PURE__*/function (_HTMLElement) {
64
64
  }
65
65
  }, {
66
66
  key: "session",
67
+ get: function get() {
68
+ return this._session;
69
+ },
67
70
  set: function set(s) {
68
71
  if (s && !s.answers) {
69
72
  s.answers = [];
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.js"],"names":["Hotspot","m","_model","dispatchEvent","ModelSetEvent","tagName","toLowerCase","isComplete","_render","_session","Array","isArray","answers","length","s","data","SessionChangedEvent","el","React","createElement","HotspotComponent","model","session","onSelectChoice","bind","ReactDOM","render","HTMLElement"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AAKA;;AACA;;;;;;IAEqBA,O;;;;;;;;;;;;SACnB,aAAUC,CAAV,EAAa;AACX,WAAKC,MAA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;AAC9B,yCAAW,KAAX;AACD,SAFD;AAGD;AACF;;;kDA1DkCU,W","sourcesContent":["import React from 'react';\nimport ReactDOM from 'react-dom';\nimport { renderMath } from '@pie-lib/math-rendering';\nimport {\n SessionChangedEvent,\n ModelSetEvent\n} from '@pie-framework/pie-player-events';\n\nimport HotspotComponent from './hotspot';\nimport { updateSessionValue } from './session-updater';\n\nexport default class Hotspot extends HTMLElement {\n set model(m) {\n this._model = m;\n\n this.dispatchEvent(\n new ModelSetEvent(\n this.tagName.toLowerCase(),\n this.isComplete(),\n !!this._model\n )\n );\n this._render();\n }\n\n isComplete() {\n if (!this._session) {\n return false;\n }\n\n return (\n Array.isArray(this._session.answers) && this._session.answers.length > 0\n );\n }\n\n set session(s) {\n if (s && !s.answers) {\n s.answers = [];\n }\n\n this._session = s;\n this._render();\n }\n\n onSelectChoice(data) {\n updateSessionValue(this._session, this._model, data);\n\n this.dispatchEvent(\n new SessionChangedEvent(this.tagName.toLowerCase(), this.isComplete())\n );\n\n this._render();\n }\n\n connectedCallback() {\n this._render();\n }\n\n _render() {\n if (this._model && this._session) {\n const el = React.createElement(HotspotComponent, {\n model: this._model,\n session: this._session,\n onSelectChoice: this.onSelectChoice.bind(this)\n });\n ReactDOM.render(el, this, () => {\n renderMath(this);\n });\n }\n }\n}\n"],"file":"index.js"}
1
+ {"version":3,"sources":["../src/index.js"],"names":["Hotspot","m","_model","dispatchEvent","ModelSetEvent","tagName","toLowerCase","isComplete","_render","_session","Array","isArray","answers","length","s","data","SessionChangedEvent","el","React","createElement","HotspotComponent","model","session","onSelectChoice","bind","ReactDOM","render","HTMLElement"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AAKA;;AACA;;;;;;IAEqBA,O;;;;;;;;;;;;SACnB,aAAUC,CAAV,EAAa;AACX,WAAKC,MAAL,GAAcD,CAAd;AAEA,WAAKE,aAAL,CACE,IAAIC,8BAAJ,CACE,KAAKC,OAAL,CAAaC,WAAb,EAD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ACF;;;kDA/DkCU,W","sourcesContent":["import React from 'react';\nimport ReactDOM from 'react-dom';\nimport { renderMath } from '@pie-lib/math-rendering';\nimport {\n SessionChangedEvent,\n ModelSetEvent\n} from '@pie-framework/pie-player-events';\n\nimport HotspotComponent from './hotspot';\nimport { updateSessionValue } from './session-updater';\n\nexport default class Hotspot extends HTMLElement {\n set model(m) {\n this._model = m;\n\n this.dispatchEvent(\n new ModelSetEvent(\n this.tagName.toLowerCase(),\n this.isComplete(),\n !!this._model\n )\n );\n this._render();\n }\n\n isComplete() {\n if (!this._session) {\n return false;\n }\n\n return (\n Array.isArray(this._session.answers) && this._session.answers.length > 0\n );\n }\n\n set session(s) {\n if (s && !s.answers) {\n s.answers = [];\n }\n\n this._session = s;\n this._render();\n }\n\n get session() {\n return this._session;\n }\n\n onSelectChoice(data) {\n updateSessionValue(this._session, this._model, data);\n\n this.dispatchEvent(\n new SessionChangedEvent(this.tagName.toLowerCase(), this.isComplete())\n );\n\n this._render();\n }\n\n connectedCallback() {\n this._render();\n }\n\n _render() {\n if (this._model && this._session) {\n const el = React.createElement(HotspotComponent, {\n model: this._model,\n session: this._session,\n onSelectChoice: this.onSelectChoice.bind(this)\n });\n\n ReactDOM.render(el, this, () => {\n renderMath(this);\n });\n }\n }\n}\n"],"file":"index.js"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pie-element/hotspot",
3
- "version": "4.10.16",
3
+ "version": "4.11.1",
4
4
  "description": "",
5
5
  "repository": "pie-framework/pie-elements",
6
6
  "publishConfig": {
@@ -9,8 +9,8 @@
9
9
  "dependencies": {
10
10
  "@material-ui/core": "^3.9.3",
11
11
  "@pie-framework/pie-player-events": "^0.1.0",
12
- "@pie-lib/math-rendering": "^2.3.13",
13
- "@pie-lib/render-ui": "^4.12.5",
12
+ "@pie-lib/math-rendering": "^2.4.0",
13
+ "@pie-lib/render-ui": "^4.12.6",
14
14
  "konva": "^3.2.5",
15
15
  "prop-types": "^15.6.1",
16
16
  "react": "^16.8.1",
@@ -19,7 +19,7 @@
19
19
  },
20
20
  "author": "pie framework developers",
21
21
  "license": "ISC",
22
- "gitHead": "92cd24e6736b2eed8f82ac44ba775ad4f2080ade",
22
+ "gitHead": "43f534de577f1eb49e63c8dc43d5519754d4df93",
23
23
  "scripts": {
24
24
  "postpublish": "../../scripts/postpublish"
25
25
  },
package/src/index.js CHANGED
@@ -42,6 +42,10 @@ export default class Hotspot extends HTMLElement {
42
42
  this._render();
43
43
  }
44
44
 
45
+ get session() {
46
+ return this._session;
47
+ }
48
+
45
49
  onSelectChoice(data) {
46
50
  updateSessionValue(this._session, this._model, data);
47
51
 
@@ -63,6 +67,7 @@ export default class Hotspot extends HTMLElement {
63
67
  session: this._session,
64
68
  onSelectChoice: this.onSelectChoice.bind(this)
65
69
  });
70
+
66
71
  ReactDOM.render(el, this, () => {
67
72
  renderMath(this);
68
73
  });