@pie-element/hotspot 11.1.6 → 11.2.0
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 +18 -0
- package/configure/CHANGELOG.md +12 -0
- package/configure/lib/root.js +2 -1
- package/configure/lib/root.js.map +1 -1
- package/configure/package.json +3 -3
- package/configure/src/root.jsx +6 -10
- package/controller/CHANGELOG.md +6 -0
- package/controller/lib/index.js +2 -1
- package/controller/lib/index.js.map +1 -1
- package/controller/package.json +1 -1
- package/controller/src/index.js +26 -24
- package/docs/demo/generate.js +20 -16
- package/lib/hotspot/circle.js +16 -12
- package/lib/hotspot/circle.js.map +1 -1
- package/lib/hotspot/container.js +92 -7
- package/lib/hotspot/container.js.map +1 -1
- package/lib/hotspot/index.js +11 -0
- package/lib/hotspot/index.js.map +1 -1
- package/lib/hotspot/polygon.js +16 -12
- package/lib/hotspot/polygon.js.map +1 -1
- package/lib/hotspot/rectangle.js +19 -16
- package/lib/hotspot/rectangle.js.map +1 -1
- package/package.json +2 -2
- package/src/hotspot/__tests__/circle.test.jsx +42 -42
- package/src/hotspot/__tests__/index.test.jsx +64 -0
- package/src/hotspot/__tests__/rectangle.test.jsx +37 -37
- package/src/hotspot/circle.jsx +16 -14
- package/src/hotspot/container.jsx +80 -0
- package/src/hotspot/index.jsx +14 -0
- package/src/hotspot/polygon.jsx +19 -17
- package/src/hotspot/rectangle.jsx +17 -16
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"polygon.js","names":["_react","_interopRequireDefault","require","_propTypes","_reactKonva","_imageKonvaTooltip","_icons","PolygonComponent","React","Component","constructor","props","_defineProperty2","default","points","x","map","y","minX","Math","min","apply","maxX","max","minY","maxY","parsedPoints","forEach","push","e","onClick","id","selected","disabled","cancelBubble","selector","document","body","style","cursor","setState","hovered","isCorrect","markAsCorrect","outlineColor","showCorrectEnabled","strokeWidth","state","render","hotspotColor","isEvaluateMode","hoverOutlineColor","evaluateText","scale","selectedHotspotColor","outlineColorParsed","getEvaluateOutlineColor","outlineWidth","getOutlineWidth","pointsParsed","parsePointsForKonva","center","getPolygonCenter","iconX","iconY","iconSrc","faCorrect","faWrong","useHoveredStyle","xValues","filter","_","index","yValues","rectX","rectY","rectWidth","rectHeight","createElement","Group","scaleX","scaleY","Rect","width","height","stroke","Line","closed","fill","handleClick","onTap","draggable","onMouseLeave","handleMouseLeave","onMouseEnter","handleMouseEnter","position","src","tooltip","propTypes","PropTypes","string","isRequired","bool","func","array","number","defaultProps","_default","exports"],"sources":["../../src/hotspot/polygon.jsx"],"sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\nimport { Line, Group, Rect } from 'react-konva';\nimport ImageComponent from './image-konva-tooltip';\nimport { faCorrect, faWrong } from './icons';\n\nclass PolygonComponent extends React.Component {\n constructor(props) {\n super(props);\n this.state = {\n hovered: false,\n };\n }\n\n getPolygonCenter = (points) => {\n const x = points.map(({ x }) => x);\n const y = points.map(({ y }) => y);\n const minX = Math.min.apply(null, x);\n const maxX = Math.max.apply(null, x);\n const minY = Math.min.apply(null, y);\n const maxY = Math.max.apply(null, y);\n return [(minX + maxX) / 2, (minY + maxY) / 2];\n };\n\n parsePointsForKonva = (points) => {\n const parsedPoints = [];\n points.forEach(({ x, y }) => {\n parsedPoints.push(x);\n parsedPoints.push(y);\n });\n return parsedPoints;\n };\n\n handleClick = (e) => {\n const { onClick, id, selected, disabled } = this.props;\n\n if (!disabled) {\n e.cancelBubble = true;\n onClick({ id, selected: !selected, selector: 'Mouse' });\n }\n };\n\n handleMouseEnter = () => {\n const { disabled } = this.props;\n\n if (!disabled) {\n document.body.style.cursor = 'pointer';\n }\n this.setState({ hovered: true });\n };\n\n handleMouseLeave = () => {\n document.body.style.cursor = 'default';\n this.setState({ hovered: false });\n };\n\n getEvaluateOutlineColor = (isCorrect, markAsCorrect, outlineColor) =>\n markAsCorrect ? 'green' : isCorrect ? outlineColor : 'red';\n\n getOutlineWidth = (showCorrectEnabled, selected, markAsCorrect, strokeWidth) =>\n markAsCorrect || (!markAsCorrect && !showCorrectEnabled && selected) ? strokeWidth : 0;\n\n render() {\n const {\n hotspotColor,\n isCorrect,\n isEvaluateMode,\n hoverOutlineColor,\n outlineColor,\n selected,\n points,\n evaluateText,\n strokeWidth,\n scale,\n markAsCorrect,\n selectedHotspotColor,\n showCorrectEnabled,\n } = this.props;\n\n const { hovered } = this.state;\n\n const outlineColorParsed = isEvaluateMode\n ? this.getEvaluateOutlineColor(isCorrect, markAsCorrect, outlineColor)\n : outlineColor;\n const outlineWidth = this.getOutlineWidth(showCorrectEnabled, selected, markAsCorrect, strokeWidth);\n\n const pointsParsed = this.parsePointsForKonva(points);\n const center = this.getPolygonCenter(points);\n const iconX = center[0];\n const iconY = center[1];\n\n // \"Show Correct Answer\" Enabled:\n // - Correctly Selected: white checkmark in green circle\n // - Correctly Not Selected: none\n // - Incorrectly Selected: none\n // - Incorrectly Not Selected: white checkmark in green circle\n // \"Show Correct Answer\" Disabled:\n // - Correctly Selected:\n // - white checkmark in green circle\n // - heavy outline, as on “Gather”\n // - Correctly Not Selected: none\n // - Incorrectly Selected:\n // - white \"X\" in red circle\n // - heavy outline around the selection should appear in red\n // - Incorrectly Not Selected: white \"X\" in red circle\n let iconSrc;\n\n if (showCorrectEnabled) {\n if ((selected && isCorrect) || (!selected && !isCorrect)) {\n iconSrc = faCorrect;\n }\n } else {\n if (selected) {\n if (isCorrect) {\n iconSrc = faCorrect;\n } else {\n iconSrc = faWrong;\n }\n } else if (!isCorrect) {\n iconSrc = faWrong;\n }\n }\n const useHoveredStyle = hovered && hoverOutlineColor;\n\n const xValues = pointsParsed.filter((_, index) => index % 2 === 0); // Even indices are x-coordinates\n const yValues = pointsParsed.filter((_, index) => index % 2 !== 0); // Odd indices are y-coordinates\n\n const minX = Math.min(...xValues);\n const maxX = Math.max(...xValues);\n const minY = Math.min(...yValues);\n const maxY = Math.max(...yValues);\n\n const rectX = minX;\n const rectY = minY;\n const rectWidth = maxX - minX;\n const rectHeight = maxY - minY;\n\n return (\n <Group scaleX={scale} scaleY={scale}>\n {useHoveredStyle && (\n <Rect\n x={rectX}\n y={rectY}\n width={rectWidth}\n height={rectHeight}\n stroke={selected ? 'transparent' : hoverOutlineColor}\n strokeWidth={strokeWidth}\n />\n )}\n <Line\n points={pointsParsed}\n closed={true}\n fill={selected && selectedHotspotColor? selectedHotspotColor : hotspotColor}\n onClick={this.handleClick}\n onTap={this.handleClick}\n draggable={false}\n stroke={useHoveredStyle && !selected ? 'transparent' : outlineColorParsed}\n strokeWidth={useHoveredStyle && !selected ? 0 : outlineWidth}\n onMouseLeave={this.handleMouseLeave}\n onMouseEnter={this.handleMouseEnter}\n cursor='pointer'\n position='relative'\n />\n {isEvaluateMode && iconSrc ? <ImageComponent src={iconSrc} x={iconX} y={iconY} tooltip={evaluateText} /> : null}\n </Group>\n );\n }\n}\n\nPolygonComponent.propTypes = {\n hotspotColor: PropTypes.string.isRequired,\n id: PropTypes.string.isRequired,\n isCorrect: PropTypes.bool.isRequired,\n isEvaluateMode: PropTypes.bool.isRequired,\n hoverOutlineColor: PropTypes.string,\n disabled: PropTypes.bool.isRequired,\n onClick: PropTypes.func.isRequired,\n outlineColor: PropTypes.string.isRequired,\n points: PropTypes.array.isRequired,\n selected: PropTypes.bool.isRequired,\n evaluateText: PropTypes.string,\n selectedHotspotColor: PropTypes.string,\n strokeWidth: PropTypes.number,\n scale: PropTypes.number,\n markAsCorrect: PropTypes.bool.isRequired,\n showCorrectEnabled: PropTypes.bool.isRequired,\n};\n\nPolygonComponent.defaultProps = {\n evaluateText: null,\n strokeWidth: 5,\n scale: 1,\n};\n\nexport default PolygonComponent;\n"],"mappings":";;;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,UAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,WAAA,GAAAF,OAAA;AACA,IAAAG,kBAAA,GAAAJ,sBAAA,CAAAC,OA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,CAACK,KAAK,CAACH,UAAU;EAClCtE,QAAQ,EAAEoE,kBAAS,CAACG,IAAI,CAACD,UAAU;EACnClD,YAAY,EAAEgD,kBAAS,CAACC,MAAM;EAC9B/C,oBAAoB,EAAE8C,kBAAS,CAACC,MAAM;EACtCvD,WAAW,EAAEsD,kBAAS,CAACM,MAAM;EAC7BrD,KAAK,EAAE+C,kBAAS,CAACM,MAAM;EACvB/D,aAAa,EAAEyD,kBAAS,CAACG,IAAI,CAACD,UAAU;EACxCzD,kBAAkB,EAAEuD,kBAAS,CAACG,IAAI,CAACD;AACrC,CAAC;AAED/F,gBAAgB,CAACoG,YAAY,GAAG;EAC9BvD,YAAY,EAAE,IAAI;EAClBN,WAAW,EAAE,CAAC;EACdO,KAAK,EAAE;AACT,CAAC;AAAC,IAAAuD,QAAA,GAAAC,OAAA,CAAAhG,OAAA,GAEaN,gBAAgB","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"polygon.js","names":["_react","_interopRequireDefault","require","_propTypes","_reactKonva","_imageKonvaTooltip","_icons","PolygonComponent","React","Component","constructor","props","_defineProperty2","default","points","x","map","y","minX","Math","min","apply","maxX","max","minY","maxY","parsedPoints","forEach","push","e","onClick","id","selected","disabled","cancelBubble","selector","document","body","style","cursor","setState","hovered","isCorrect","markAsCorrect","outlineColor","showCorrectEnabled","strokeWidth","state","render","hotspotColor","isEvaluateMode","hoverOutlineColor","focused","evaluateText","scale","selectedHotspotColor","outlineColorParsed","getEvaluateOutlineColor","outlineWidth","getOutlineWidth","pointsParsed","parsePointsForKonva","center","getPolygonCenter","iconX","iconY","iconSrc","faCorrect","faWrong","useHoveredStyle","xValues","filter","_","index","yValues","rectX","rectY","rectWidth","rectHeight","createElement","Group","scaleX","scaleY","onMouseEnter","handleMouseEnter","onMouseLeave","handleMouseLeave","Line","closed","fill","handleClick","onTap","draggable","stroke","position","Rect","width","height","listening","src","tooltip","propTypes","PropTypes","string","isRequired","bool","func","array","number","defaultProps","_default","exports"],"sources":["../../src/hotspot/polygon.jsx"],"sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\nimport { Line, Group, Rect } from 'react-konva';\nimport ImageComponent from './image-konva-tooltip';\nimport { faCorrect, faWrong } from './icons';\n\nclass PolygonComponent extends React.Component {\n constructor(props) {\n super(props);\n this.state = {\n hovered: false,\n };\n }\n\n getPolygonCenter = (points) => {\n const x = points.map(({ x }) => x);\n const y = points.map(({ y }) => y);\n const minX = Math.min.apply(null, x);\n const maxX = Math.max.apply(null, x);\n const minY = Math.min.apply(null, y);\n const maxY = Math.max.apply(null, y);\n return [(minX + maxX) / 2, (minY + maxY) / 2];\n };\n\n parsePointsForKonva = (points) => {\n const parsedPoints = [];\n points.forEach(({ x, y }) => {\n parsedPoints.push(x);\n parsedPoints.push(y);\n });\n return parsedPoints;\n };\n\n handleClick = (e) => {\n const { onClick, id, selected, disabled } = this.props;\n\n if (!disabled) {\n e.cancelBubble = true;\n onClick({ id, selected: !selected, selector: 'Mouse' });\n }\n };\n\n handleMouseEnter = () => {\n const { disabled } = this.props;\n\n if (!disabled) {\n document.body.style.cursor = 'pointer';\n }\n this.setState({ hovered: true });\n };\n\n handleMouseLeave = () => {\n document.body.style.cursor = 'default';\n this.setState({ hovered: false });\n };\n\n getEvaluateOutlineColor = (isCorrect, markAsCorrect, outlineColor) =>\n markAsCorrect ? 'green' : isCorrect ? outlineColor : 'red';\n\n getOutlineWidth = (showCorrectEnabled, selected, markAsCorrect, strokeWidth) =>\n markAsCorrect || (!markAsCorrect && !showCorrectEnabled && selected) ? strokeWidth : 0;\n\n render() {\n const {\n hotspotColor,\n isCorrect,\n isEvaluateMode,\n hoverOutlineColor,\n outlineColor,\n selected,\n focused,\n points,\n evaluateText,\n strokeWidth,\n scale,\n markAsCorrect,\n selectedHotspotColor,\n showCorrectEnabled,\n } = this.props;\n\n const { hovered } = this.state;\n\n const outlineColorParsed = isEvaluateMode\n ? this.getEvaluateOutlineColor(isCorrect, markAsCorrect, outlineColor)\n : outlineColor;\n const outlineWidth = this.getOutlineWidth(showCorrectEnabled, selected, markAsCorrect, strokeWidth);\n\n const pointsParsed = this.parsePointsForKonva(points);\n const center = this.getPolygonCenter(points);\n const iconX = center[0];\n const iconY = center[1];\n\n // \"Show Correct Answer\" Enabled:\n // - Correctly Selected: white checkmark in green circle\n // - Correctly Not Selected: none\n // - Incorrectly Selected: none\n // - Incorrectly Not Selected: white checkmark in green circle\n // \"Show Correct Answer\" Disabled:\n // - Correctly Selected:\n // - white checkmark in green circle\n // - heavy outline, as on “Gather”\n // - Correctly Not Selected: none\n // - Incorrectly Selected:\n // - white \"X\" in red circle\n // - heavy outline around the selection should appear in red\n // - Incorrectly Not Selected: white \"X\" in red circle\n let iconSrc;\n\n if (showCorrectEnabled) {\n if ((selected && isCorrect) || (!selected && !isCorrect)) {\n iconSrc = faCorrect;\n }\n } else {\n if (selected) {\n if (isCorrect) {\n iconSrc = faCorrect;\n } else {\n iconSrc = faWrong;\n }\n } else if (!isCorrect) {\n iconSrc = faWrong;\n }\n }\n const useHoveredStyle = (hovered || focused) && hoverOutlineColor;\n\n const xValues = pointsParsed.filter((_, index) => index % 2 === 0); // Even indices are x-coordinates\n const yValues = pointsParsed.filter((_, index) => index % 2 !== 0); // Odd indices are y-coordinates\n\n const minX = Math.min(...xValues);\n const maxX = Math.max(...xValues);\n const minY = Math.min(...yValues);\n const maxY = Math.max(...yValues);\n\n const rectX = minX;\n const rectY = minY;\n const rectWidth = maxX - minX;\n const rectHeight = maxY - minY;\n\n return (\n <Group scaleX={scale} scaleY={scale} onMouseEnter={this.handleMouseEnter} onMouseLeave={this.handleMouseLeave}>\n <Line\n points={pointsParsed}\n closed={true}\n fill={selected && selectedHotspotColor ? selectedHotspotColor : hotspotColor}\n onClick={this.handleClick}\n onTap={this.handleClick}\n draggable={false}\n stroke={useHoveredStyle && !selected ? 'transparent' : outlineColorParsed}\n strokeWidth={useHoveredStyle && !selected ? 0 : outlineWidth}\n cursor=\"pointer\"\n position=\"relative\"\n />\n {useHoveredStyle && (\n <Rect\n x={rectX}\n y={rectY}\n width={rectWidth}\n height={rectHeight}\n stroke={hoverOutlineColor}\n strokeWidth={strokeWidth}\n listening={false}\n />\n )}\n {isEvaluateMode && iconSrc ? <ImageComponent src={iconSrc} x={iconX} y={iconY} tooltip={evaluateText} /> : null}\n </Group>\n );\n }\n}\n\nPolygonComponent.propTypes = {\n hotspotColor: PropTypes.string.isRequired,\n id: PropTypes.string.isRequired,\n isCorrect: PropTypes.bool.isRequired,\n isEvaluateMode: PropTypes.bool.isRequired,\n hoverOutlineColor: PropTypes.string,\n disabled: PropTypes.bool.isRequired,\n focused: PropTypes.bool,\n onClick: PropTypes.func.isRequired,\n outlineColor: PropTypes.string.isRequired,\n points: PropTypes.array.isRequired,\n selected: PropTypes.bool.isRequired,\n evaluateText: PropTypes.string,\n selectedHotspotColor: PropTypes.string,\n strokeWidth: PropTypes.number,\n scale: PropTypes.number,\n markAsCorrect: PropTypes.bool.isRequired,\n showCorrectEnabled: PropTypes.bool.isRequired,\n};\n\nPolygonComponent.defaultProps = {\n evaluateText: null,\n focused: false,\n strokeWidth: 5,\n scale: 1,\n};\n\nexport default PolygonComponent;\n"],"mappings":";;;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,UAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,WAAA,GAAAF,OAAA;AACA,IAAAG,kBAAA,GAAAJ,sBAAA,CAAAC,OAAA;AACA,IAAAI,MAAA,GAAAJ,OAAA;AAEA,MAAMK,gBAAgB,SAASC,cAAK,CAACC,SAAS,CAAC;EAC7CC,WAAWA,CAACC,KAAK,EAAE;IACjB,KAAK,CAACA,KAAK,CAAC;IAAC,IAAAC,gBAAA,CAAAC,OAAA,4BAMKC,MAAM,IAAK;MAC7B,MAAMC,CAAC,GAAGD,MAAM,CAACE,GAAG,CAAC,CAAC;QAAED;MAAE,CAAC,KAAKA,CAAC,CAAC;MAClC,MAAME,C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kBAAS,CAACM,MAAM;EACvBjE,aAAa,EAAE2D,kBAAS,CAACG,IAAI,CAACD,UAAU;EACxC3D,kBAAkB,EAAEyD,kBAAS,CAACG,IAAI,CAACD;AACrC,CAAC;AAEDjG,gBAAgB,CAACsG,YAAY,GAAG;EAC9BxD,YAAY,EAAE,IAAI;EAClBD,OAAO,EAAE,KAAK;EACdN,WAAW,EAAE,CAAC;EACdQ,KAAK,EAAE;AACT,CAAC;AAAC,IAAAwD,QAAA,GAAAC,OAAA,CAAAlG,OAAA,GAEaN,gBAAgB","ignoreList":[]}
|
package/lib/hotspot/rectangle.js
CHANGED
|
@@ -63,6 +63,7 @@ class RectComponent extends _react.default.Component {
|
|
|
63
63
|
isEvaluateMode,
|
|
64
64
|
outlineColor,
|
|
65
65
|
selected,
|
|
66
|
+
focused,
|
|
66
67
|
width,
|
|
67
68
|
x,
|
|
68
69
|
y,
|
|
@@ -72,6 +73,9 @@ class RectComponent extends _react.default.Component {
|
|
|
72
73
|
markAsCorrect,
|
|
73
74
|
showCorrectEnabled
|
|
74
75
|
} = this.props;
|
|
76
|
+
const {
|
|
77
|
+
hovered
|
|
78
|
+
} = this.state;
|
|
75
79
|
const outlineColorParsed = isEvaluateMode ? this.getEvaluateOutlineColor(isCorrect, markAsCorrect, outlineColor) : outlineColor;
|
|
76
80
|
const outlineWidth = this.getOutlineWidth(showCorrectEnabled, selected, markAsCorrect, strokeWidth);
|
|
77
81
|
const iconX = x + width / 2 - 10;
|
|
@@ -107,22 +111,13 @@ class RectComponent extends _react.default.Component {
|
|
|
107
111
|
iconSrc = _icons.faWrong;
|
|
108
112
|
}
|
|
109
113
|
}
|
|
110
|
-
const
|
|
111
|
-
hovered
|
|
112
|
-
} = this.state;
|
|
113
|
-
const useHoveredStyle = hovered && hoverOutlineColor;
|
|
114
|
+
const useHoveredStyle = (hovered || focused) && hoverOutlineColor;
|
|
114
115
|
return /*#__PURE__*/_react.default.createElement(_reactKonva.Group, {
|
|
115
116
|
scaleX: scale,
|
|
116
|
-
scaleY: scale
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
width: width,
|
|
121
|
-
height: height,
|
|
122
|
-
stroke: selected ? 'transparent' : hoverOutlineColor,
|
|
123
|
-
strokeWidth: strokeWidth,
|
|
124
|
-
listening: false
|
|
125
|
-
}), /*#__PURE__*/_react.default.createElement(_reactKonva.Rect, {
|
|
117
|
+
scaleY: scale,
|
|
118
|
+
onMouseLeave: this.handleMouseLeave,
|
|
119
|
+
onMouseEnter: this.handleMouseEnter
|
|
120
|
+
}, /*#__PURE__*/_react.default.createElement(_reactKonva.Rect, {
|
|
126
121
|
x: x,
|
|
127
122
|
y: y,
|
|
128
123
|
width: width,
|
|
@@ -133,9 +128,15 @@ class RectComponent extends _react.default.Component {
|
|
|
133
128
|
draggable: false,
|
|
134
129
|
stroke: useHoveredStyle && !selected ? 'transparent' : outlineColorParsed,
|
|
135
130
|
strokeWidth: useHoveredStyle && !selected ? 0 : outlineWidth,
|
|
136
|
-
onMouseLeave: this.handleMouseLeave,
|
|
137
|
-
onMouseEnter: this.handleMouseEnter,
|
|
138
131
|
cursor: "pointer"
|
|
132
|
+
}), useHoveredStyle && /*#__PURE__*/_react.default.createElement(_reactKonva.Rect, {
|
|
133
|
+
x: x,
|
|
134
|
+
y: y,
|
|
135
|
+
width: width,
|
|
136
|
+
height: height,
|
|
137
|
+
stroke: hoverOutlineColor,
|
|
138
|
+
strokeWidth: strokeWidth,
|
|
139
|
+
listening: false
|
|
139
140
|
}), isEvaluateMode && iconSrc ? /*#__PURE__*/_react.default.createElement(_imageKonvaTooltip.default, {
|
|
140
141
|
src: iconSrc,
|
|
141
142
|
x: iconX,
|
|
@@ -152,6 +153,7 @@ RectComponent.propTypes = {
|
|
|
152
153
|
isEvaluateMode: _propTypes.default.bool.isRequired,
|
|
153
154
|
hoverOutlineColor: _propTypes.default.string,
|
|
154
155
|
disabled: _propTypes.default.bool.isRequired,
|
|
156
|
+
focused: _propTypes.default.bool,
|
|
155
157
|
onClick: _propTypes.default.func.isRequired,
|
|
156
158
|
outlineColor: _propTypes.default.string.isRequired,
|
|
157
159
|
selected: _propTypes.default.bool.isRequired,
|
|
@@ -168,6 +170,7 @@ RectComponent.propTypes = {
|
|
|
168
170
|
RectComponent.defaultProps = {
|
|
169
171
|
isCorrect: false,
|
|
170
172
|
evaluateText: null,
|
|
173
|
+
focused: false,
|
|
171
174
|
strokeWidth: 5,
|
|
172
175
|
scale: 1
|
|
173
176
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rectangle.js","names":["_react","_interopRequireDefault","require","_propTypes","_reactKonva","_imageKonvaTooltip","_icons","RectComponent","React","Component","constructor","props","_defineProperty2","default","e","onClick","id","selected","disabled","cancelBubble","selector","document","body","style","cursor","setState","hovered","isCorrect","markAsCorrect","outlineColor","showCorrectEnabled","strokeWidth","state","render","height","hotspotColor","hoverOutlineColor","selectedHotspotColor","isEvaluateMode","width","x","y","evaluateText","scale","outlineColorParsed","getEvaluateOutlineColor","outlineWidth","getOutlineWidth","iconX","iconY","iconSrc","faCorrect","faWrong","useHoveredStyle","createElement","Group","scaleX","scaleY","Rect","stroke","listening","fill","handleClick","onTap","draggable","onMouseLeave","handleMouseLeave","onMouseEnter","handleMouseEnter","src","tooltip","propTypes","PropTypes","number","isRequired","string","oneOfType","bool","func","defaultProps","_default","exports"],"sources":["../../src/hotspot/rectangle.jsx"],"sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\nimport { Rect, Group } from 'react-konva';\nimport ImageComponent from './image-konva-tooltip';\nimport { faCorrect, faWrong } from './icons';\n\nclass RectComponent extends React.Component {\n constructor(props) {\n super(props);\n this.state = {\n hovered: false,\n };\n }\n\n handleClick = (e) => {\n const { onClick, id, selected, disabled } = this.props;\n\n if (!disabled) {\n e.cancelBubble = true;\n onClick({ id, selected: !selected, selector: 'Mouse' });\n }\n };\n\n handleMouseEnter = () => {\n const { disabled } = this.props;\n\n if (!disabled) {\n document.body.style.cursor = 'pointer';\n }\n this.setState({ hovered: true });\n };\n\n handleMouseLeave = () => {\n document.body.style.cursor = 'default';\n this.setState({ hovered: false });\n };\n\n getEvaluateOutlineColor = (isCorrect, markAsCorrect, outlineColor) =>\n markAsCorrect ? 'green' : isCorrect ? outlineColor : 'red';\n\n getOutlineWidth = (showCorrectEnabled, selected, markAsCorrect, strokeWidth) =>\n markAsCorrect || (!markAsCorrect && !showCorrectEnabled && selected) ? strokeWidth : 0;\n\n render() {\n const {\n height,\n hotspotColor,\n hoverOutlineColor,\n selectedHotspotColor,\n isCorrect,\n isEvaluateMode,\n outlineColor,\n selected,\n width,\n x,\n y,\n evaluateText,\n strokeWidth,\n scale,\n markAsCorrect,\n showCorrectEnabled,\n } = this.props;\n\n const outlineColorParsed = isEvaluateMode\n ? this.getEvaluateOutlineColor(isCorrect, markAsCorrect, outlineColor)\n : outlineColor;\n\n const outlineWidth = this.getOutlineWidth(showCorrectEnabled, selected, markAsCorrect, strokeWidth);\n\n const iconX = x + width / 2 - 10;\n const iconY = y + height / 2 - 10;\n\n // \"Show Correct Answer\" Enabled:\n // - Correctly Selected: white checkmark in green circle\n // - Correctly Not Selected: none\n // - Incorrectly Selected: none\n // - Incorrectly Not Selected: white checkmark in green circle\n // \"Show Correct Answer\" Disabled:\n // - Correctly Selected:\n // - white checkmark in green circle\n // - heavy outline, as on “Gather”\n // - Correctly Not Selected: none\n // - Incorrectly Selected:\n // - white \"X\" in red circle\n // - heavy outline around the selection should appear in red\n // - Incorrectly Not Selected: white \"X\" in red circle\n let iconSrc;\n\n if (showCorrectEnabled) {\n if ((selected && isCorrect) || (!selected && !isCorrect)) {\n iconSrc = faCorrect;\n }\n } else {\n if (selected) {\n if (isCorrect) {\n iconSrc = faCorrect;\n } else {\n iconSrc = faWrong;\n }\n } else if (!isCorrect) {\n iconSrc = faWrong;\n }\n }\n\n const { hovered } = this.state;\n const useHoveredStyle = hovered && hoverOutlineColor;\n\n return (\n <Group scaleX={scale} scaleY={scale}>\n {useHoveredStyle && (\n <Rect\n x={x}\n y={y}\n width={width}\n height={height}\n stroke={selected ? 'transparent' : hoverOutlineColor}\n strokeWidth={strokeWidth}\n listening={false}\n />\n )}\n <Rect\n x={x}\n y={y}\n width={width}\n height={height}\n fill={selected && selectedHotspotColor ? selectedHotspotColor : hotspotColor}\n onClick={this.handleClick}\n onTap={this.handleClick}\n draggable={false}\n stroke={useHoveredStyle && !selected ? 'transparent' : outlineColorParsed}\n strokeWidth={useHoveredStyle && !selected ? 0 : outlineWidth}\n onMouseLeave={this.handleMouseLeave}\n onMouseEnter={this.handleMouseEnter}\n cursor=\"pointer\"\n />\n {isEvaluateMode && iconSrc ? <ImageComponent src={iconSrc} x={iconX} y={iconY} tooltip={evaluateText} /> : null}\n </Group>\n );\n }\n}\n\nRectComponent.propTypes = {\n height: PropTypes.number.isRequired,\n hotspotColor: PropTypes.string.isRequired,\n id: PropTypes.string.isRequired,\n isCorrect: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]),\n isEvaluateMode: PropTypes.bool.isRequired,\n hoverOutlineColor: PropTypes.string,\n disabled: PropTypes.bool.isRequired,\n onClick: PropTypes.func.isRequired,\n outlineColor: PropTypes.string.isRequired,\n selected: PropTypes.bool.isRequired,\n width: PropTypes.number.isRequired,\n x: PropTypes.number.isRequired,\n y: PropTypes.number.isRequired,\n evaluateText: PropTypes.string,\n strokeWidth: PropTypes.number,\n scale: PropTypes.number,\n selectedHotspotColor: PropTypes.string,\n markAsCorrect: PropTypes.bool.isRequired,\n showCorrectEnabled: PropTypes.bool.isRequired,\n};\n\nRectComponent.defaultProps = {\n isCorrect: false,\n evaluateText: null,\n strokeWidth: 5,\n scale: 1,\n};\n\nexport default RectComponent;\n"],"mappings":";;;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,UAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,WAAA,GAAAF,OAAA;AACA,IAAAG,kBAAA,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AAU;EACxC5C,kBAAkB,EAAE0C,kBAAS,CAACK,IAAI,CAACH;AACrC,CAAC;AAEDnE,aAAa,CAACwE,YAAY,GAAG;EAC3BpD,SAAS,EAAE,KAAK;EAChBe,YAAY,EAAE,IAAI;EAClBX,WAAW,EAAE,CAAC;EACdY,KAAK,EAAE;AACT,CAAC;AAAC,IAAAqC,QAAA,GAAAC,OAAA,CAAApE,OAAA,GAEaN,aAAa","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"rectangle.js","names":["_react","_interopRequireDefault","require","_propTypes","_reactKonva","_imageKonvaTooltip","_icons","RectComponent","React","Component","constructor","props","_defineProperty2","default","e","onClick","id","selected","disabled","cancelBubble","selector","document","body","style","cursor","setState","hovered","isCorrect","markAsCorrect","outlineColor","showCorrectEnabled","strokeWidth","state","render","height","hotspotColor","hoverOutlineColor","selectedHotspotColor","isEvaluateMode","focused","width","x","y","evaluateText","scale","outlineColorParsed","getEvaluateOutlineColor","outlineWidth","getOutlineWidth","iconX","iconY","iconSrc","faCorrect","faWrong","useHoveredStyle","createElement","Group","scaleX","scaleY","onMouseLeave","handleMouseLeave","onMouseEnter","handleMouseEnter","Rect","fill","handleClick","onTap","draggable","stroke","listening","src","tooltip","propTypes","PropTypes","number","isRequired","string","oneOfType","bool","func","defaultProps","_default","exports"],"sources":["../../src/hotspot/rectangle.jsx"],"sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\nimport { Rect, Group } from 'react-konva';\nimport ImageComponent from './image-konva-tooltip';\nimport { faCorrect, faWrong } from './icons';\n\nclass RectComponent extends React.Component {\n constructor(props) {\n super(props);\n this.state = {\n hovered: false,\n };\n }\n\n handleClick = (e) => {\n const { onClick, id, selected, disabled } = this.props;\n\n if (!disabled) {\n e.cancelBubble = true;\n onClick({ id, selected: !selected, selector: 'Mouse' });\n }\n };\n\n handleMouseEnter = () => {\n const { disabled } = this.props;\n\n if (!disabled) {\n document.body.style.cursor = 'pointer';\n }\n this.setState({ hovered: true });\n };\n\n handleMouseLeave = () => {\n document.body.style.cursor = 'default';\n this.setState({ hovered: false });\n };\n\n getEvaluateOutlineColor = (isCorrect, markAsCorrect, outlineColor) =>\n markAsCorrect ? 'green' : isCorrect ? outlineColor : 'red';\n\n getOutlineWidth = (showCorrectEnabled, selected, markAsCorrect, strokeWidth) =>\n markAsCorrect || (!markAsCorrect && !showCorrectEnabled && selected) ? strokeWidth : 0;\n\n render() {\n const {\n height,\n hotspotColor,\n hoverOutlineColor,\n selectedHotspotColor,\n isCorrect,\n isEvaluateMode,\n outlineColor,\n selected,\n focused,\n width,\n x,\n y,\n evaluateText,\n strokeWidth,\n scale,\n markAsCorrect,\n showCorrectEnabled,\n } = this.props;\n const { hovered } = this.state;\n\n const outlineColorParsed = isEvaluateMode\n ? this.getEvaluateOutlineColor(isCorrect, markAsCorrect, outlineColor)\n : outlineColor;\n\n const outlineWidth = this.getOutlineWidth(showCorrectEnabled, selected, markAsCorrect, strokeWidth);\n\n const iconX = x + width / 2 - 10;\n const iconY = y + height / 2 - 10;\n\n // \"Show Correct Answer\" Enabled:\n // - Correctly Selected: white checkmark in green circle\n // - Correctly Not Selected: none\n // - Incorrectly Selected: none\n // - Incorrectly Not Selected: white checkmark in green circle\n // \"Show Correct Answer\" Disabled:\n // - Correctly Selected:\n // - white checkmark in green circle\n // - heavy outline, as on “Gather”\n // - Correctly Not Selected: none\n // - Incorrectly Selected:\n // - white \"X\" in red circle\n // - heavy outline around the selection should appear in red\n // - Incorrectly Not Selected: white \"X\" in red circle\n let iconSrc;\n\n if (showCorrectEnabled) {\n if ((selected && isCorrect) || (!selected && !isCorrect)) {\n iconSrc = faCorrect;\n }\n } else {\n if (selected) {\n if (isCorrect) {\n iconSrc = faCorrect;\n } else {\n iconSrc = faWrong;\n }\n } else if (!isCorrect) {\n iconSrc = faWrong;\n }\n }\n\n const useHoveredStyle = (hovered || focused) && hoverOutlineColor;\n\n return (\n <Group scaleX={scale} scaleY={scale} onMouseLeave={this.handleMouseLeave} onMouseEnter={this.handleMouseEnter}>\n <Rect\n x={x}\n y={y}\n width={width}\n height={height}\n fill={selected && selectedHotspotColor ? selectedHotspotColor : hotspotColor}\n onClick={this.handleClick}\n onTap={this.handleClick}\n draggable={false}\n stroke={useHoveredStyle && !selected ? 'transparent' : outlineColorParsed}\n strokeWidth={useHoveredStyle && !selected ? 0 : outlineWidth}\n cursor=\"pointer\"\n />\n {useHoveredStyle && (\n <Rect\n x={x}\n y={y}\n width={width}\n height={height}\n stroke={hoverOutlineColor}\n strokeWidth={strokeWidth}\n listening={false}\n />\n )}\n {isEvaluateMode && iconSrc ? <ImageComponent src={iconSrc} x={iconX} y={iconY} tooltip={evaluateText} /> : null}\n </Group>\n );\n }\n}\n\nRectComponent.propTypes = {\n height: PropTypes.number.isRequired,\n hotspotColor: PropTypes.string.isRequired,\n id: PropTypes.string.isRequired,\n isCorrect: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]),\n isEvaluateMode: PropTypes.bool.isRequired,\n hoverOutlineColor: PropTypes.string,\n disabled: PropTypes.bool.isRequired,\n focused: PropTypes.bool,\n onClick: PropTypes.func.isRequired,\n outlineColor: PropTypes.string.isRequired,\n selected: PropTypes.bool.isRequired,\n width: PropTypes.number.isRequired,\n x: PropTypes.number.isRequired,\n y: PropTypes.number.isRequired,\n evaluateText: PropTypes.string,\n strokeWidth: PropTypes.number,\n scale: PropTypes.number,\n selectedHotspotColor: PropTypes.string,\n markAsCorrect: PropTypes.bool.isRequired,\n showCorrectEnabled: PropTypes.bool.isRequired,\n};\n\nRectComponent.defaultProps = {\n isCorrect: false,\n evaluateText: null,\n focused: false,\n strokeWidth: 5,\n scale: 1,\n};\n\nexport default RectComponent;\n"],"mappings":";;;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,UAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,WAAA,GAAAF,OAAA;AACA,IAAAG,kBAAA,GAAAJ,sBAAA,CAAAC,OAA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ACK,IAAI,CAACH,UAAU;EACxC7C,kBAAkB,EAAE2C,kBAAS,CAACK,IAAI,CAACH;AACrC,CAAC;AAEDpE,aAAa,CAACyE,YAAY,GAAG;EAC3BrD,SAAS,EAAE,KAAK;EAChBgB,YAAY,EAAE,IAAI;EAClBJ,OAAO,EAAE,KAAK;EACdR,WAAW,EAAE,CAAC;EACda,KAAK,EAAE;AACT,CAAC;AAAC,IAAAqC,QAAA,GAAAC,OAAA,CAAArE,OAAA,GAEaN,aAAa","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pie-element/hotspot",
|
|
3
3
|
"repository": "pie-framework/pie-elements",
|
|
4
|
-
"version": "11.
|
|
4
|
+
"version": "11.2.0",
|
|
5
5
|
"description": "",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
},
|
|
25
25
|
"author": "pie framework developers",
|
|
26
26
|
"license": "ISC",
|
|
27
|
-
"gitHead": "
|
|
27
|
+
"gitHead": "2b221481f30b228062d17fd0c2d41a402a9ded26",
|
|
28
28
|
"scripts": {
|
|
29
29
|
"postpublish": "../../scripts/postpublish"
|
|
30
30
|
},
|
|
@@ -70,7 +70,7 @@ describe('CircleComponent', () => {
|
|
|
70
70
|
it('should render with correct position and radius', () => {
|
|
71
71
|
const { getByTestId } = render(<CircleComponent {...defaultProps} />);
|
|
72
72
|
const circle = getByTestId('circle');
|
|
73
|
-
|
|
73
|
+
|
|
74
74
|
expect(circle).toHaveAttribute('x', '50');
|
|
75
75
|
expect(circle).toHaveAttribute('y', '50');
|
|
76
76
|
expect(circle).toHaveAttribute('radius', '30');
|
|
@@ -79,21 +79,21 @@ describe('CircleComponent', () => {
|
|
|
79
79
|
it('should render with hotspot color when not selected', () => {
|
|
80
80
|
const { getByTestId } = render(<CircleComponent {...defaultProps} />);
|
|
81
81
|
const circle = getByTestId('circle');
|
|
82
|
-
|
|
82
|
+
|
|
83
83
|
expect(circle).toHaveAttribute('fill', '#FF0000');
|
|
84
84
|
});
|
|
85
85
|
|
|
86
86
|
it('should render with selected color when selected', () => {
|
|
87
87
|
const { getByTestId } = render(<CircleComponent {...defaultProps} selected={true} />);
|
|
88
88
|
const circle = getByTestId('circle');
|
|
89
|
-
|
|
89
|
+
|
|
90
90
|
expect(circle).toHaveAttribute('fill', '#00FF00');
|
|
91
91
|
});
|
|
92
92
|
|
|
93
93
|
it('should apply scale transform', () => {
|
|
94
94
|
const { getByTestId } = render(<CircleComponent {...defaultProps} scale={2.0} />);
|
|
95
95
|
const group = getByTestId('group');
|
|
96
|
-
|
|
96
|
+
|
|
97
97
|
expect(group).toHaveAttribute('scaleX', '2');
|
|
98
98
|
expect(group).toHaveAttribute('scaleY', '2');
|
|
99
99
|
});
|
|
@@ -101,7 +101,7 @@ describe('CircleComponent', () => {
|
|
|
101
101
|
it('should render with default scale of 1', () => {
|
|
102
102
|
const { getByTestId } = render(<CircleComponent {...defaultProps} />);
|
|
103
103
|
const group = getByTestId('group');
|
|
104
|
-
|
|
104
|
+
|
|
105
105
|
expect(group).toHaveAttribute('scaleX', '1');
|
|
106
106
|
expect(group).toHaveAttribute('scaleY', '1');
|
|
107
107
|
});
|
|
@@ -112,9 +112,9 @@ describe('CircleComponent', () => {
|
|
|
112
112
|
const onClick = jest.fn();
|
|
113
113
|
const { getByTestId } = render(<CircleComponent {...defaultProps} onClick={onClick} />);
|
|
114
114
|
const circle = getByTestId('circle');
|
|
115
|
-
|
|
115
|
+
|
|
116
116
|
fireEvent.click(circle);
|
|
117
|
-
|
|
117
|
+
|
|
118
118
|
expect(onClick).toHaveBeenCalledWith({
|
|
119
119
|
id: 'circle1',
|
|
120
120
|
selected: true,
|
|
@@ -126,20 +126,20 @@ describe('CircleComponent', () => {
|
|
|
126
126
|
const onClick = jest.fn();
|
|
127
127
|
const { getByTestId, rerender } = render(<CircleComponent {...defaultProps} onClick={onClick} selected={false} />);
|
|
128
128
|
const circle = getByTestId('circle');
|
|
129
|
-
|
|
129
|
+
|
|
130
130
|
fireEvent.click(circle);
|
|
131
|
-
|
|
131
|
+
|
|
132
132
|
expect(onClick).toHaveBeenCalledWith({
|
|
133
133
|
id: 'circle1',
|
|
134
134
|
selected: true,
|
|
135
135
|
selector: 'Mouse',
|
|
136
136
|
});
|
|
137
|
-
|
|
137
|
+
|
|
138
138
|
rerender(<CircleComponent {...defaultProps} onClick={onClick} selected={true} />);
|
|
139
|
-
|
|
139
|
+
|
|
140
140
|
const circleAfter = getByTestId('circle');
|
|
141
141
|
fireEvent.click(circleAfter);
|
|
142
|
-
|
|
142
|
+
|
|
143
143
|
expect(onClick).toHaveBeenCalledWith({
|
|
144
144
|
id: 'circle1',
|
|
145
145
|
selected: false,
|
|
@@ -151,37 +151,37 @@ describe('CircleComponent', () => {
|
|
|
151
151
|
const onClick = jest.fn();
|
|
152
152
|
const { getByTestId } = render(<CircleComponent {...defaultProps} onClick={onClick} disabled={true} />);
|
|
153
153
|
const circle = getByTestId('circle');
|
|
154
|
-
|
|
154
|
+
|
|
155
155
|
fireEvent.click(circle);
|
|
156
|
-
|
|
156
|
+
|
|
157
157
|
expect(onClick).not.toHaveBeenCalled();
|
|
158
158
|
});
|
|
159
159
|
|
|
160
160
|
it('should change cursor to pointer on mouse enter when not disabled', () => {
|
|
161
161
|
const { getByTestId } = render(<CircleComponent {...defaultProps} />);
|
|
162
162
|
const circle = getByTestId('circle');
|
|
163
|
-
|
|
163
|
+
|
|
164
164
|
fireEvent.mouseEnter(circle);
|
|
165
|
-
|
|
165
|
+
|
|
166
166
|
expect(document.body.style.cursor).toBe('pointer');
|
|
167
167
|
});
|
|
168
168
|
|
|
169
169
|
it('should not change cursor when disabled', () => {
|
|
170
170
|
const { getByTestId } = render(<CircleComponent {...defaultProps} disabled={true} />);
|
|
171
171
|
const circle = getByTestId('circle');
|
|
172
|
-
|
|
172
|
+
|
|
173
173
|
fireEvent.mouseEnter(circle);
|
|
174
|
-
|
|
174
|
+
|
|
175
175
|
expect(document.body.style.cursor).toBe('default');
|
|
176
176
|
});
|
|
177
177
|
|
|
178
178
|
it('should reset cursor to default on mouse leave', () => {
|
|
179
179
|
const { getByTestId } = render(<CircleComponent {...defaultProps} />);
|
|
180
180
|
const circle = getByTestId('circle');
|
|
181
|
-
|
|
181
|
+
|
|
182
182
|
fireEvent.mouseEnter(circle);
|
|
183
183
|
fireEvent.mouseLeave(circle);
|
|
184
|
-
|
|
184
|
+
|
|
185
185
|
expect(document.body.style.cursor).toBe('default');
|
|
186
186
|
});
|
|
187
187
|
});
|
|
@@ -190,9 +190,9 @@ describe('CircleComponent', () => {
|
|
|
190
190
|
it('should show hover rect when hoverOutlineColor is provided', () => {
|
|
191
191
|
const { container, getByTestId } = render(<CircleComponent {...defaultProps} hoverOutlineColor="#FFFF00" />);
|
|
192
192
|
const circle = getByTestId('circle');
|
|
193
|
-
|
|
193
|
+
|
|
194
194
|
fireEvent.mouseEnter(circle);
|
|
195
|
-
|
|
195
|
+
|
|
196
196
|
const rects = container.querySelectorAll('[data-testid="rect"]');
|
|
197
197
|
expect(rects.length).toBeGreaterThan(0);
|
|
198
198
|
});
|
|
@@ -208,9 +208,9 @@ describe('CircleComponent', () => {
|
|
|
208
208
|
/>
|
|
209
209
|
);
|
|
210
210
|
const circle = getByTestId('circle');
|
|
211
|
-
|
|
211
|
+
|
|
212
212
|
fireEvent.mouseEnter(circle);
|
|
213
|
-
|
|
213
|
+
|
|
214
214
|
const rect = container.querySelector('[data-testid="rect"]');
|
|
215
215
|
if (rect) {
|
|
216
216
|
// Rect should be positioned at (x - radius, y - radius) with width/height = radius * 2
|
|
@@ -226,12 +226,12 @@ describe('CircleComponent', () => {
|
|
|
226
226
|
<CircleComponent {...defaultProps} selected={true} hoverOutlineColor="#FFFF00" />
|
|
227
227
|
);
|
|
228
228
|
const circle = getByTestId('circle');
|
|
229
|
-
|
|
229
|
+
|
|
230
230
|
fireEvent.mouseEnter(circle);
|
|
231
|
-
|
|
231
|
+
|
|
232
232
|
const rect = container.querySelector('[data-testid="rect"]');
|
|
233
233
|
if (rect) {
|
|
234
|
-
expect(rect).toHaveAttribute('stroke', '
|
|
234
|
+
expect(rect).toHaveAttribute('stroke', '#FFFF00');
|
|
235
235
|
}
|
|
236
236
|
});
|
|
237
237
|
});
|
|
@@ -247,7 +247,7 @@ describe('CircleComponent', () => {
|
|
|
247
247
|
showCorrectEnabled={false}
|
|
248
248
|
/>
|
|
249
249
|
);
|
|
250
|
-
|
|
250
|
+
|
|
251
251
|
const icon = getByTestId('icon-image');
|
|
252
252
|
expect(icon).toBeInTheDocument();
|
|
253
253
|
});
|
|
@@ -262,7 +262,7 @@ describe('CircleComponent', () => {
|
|
|
262
262
|
showCorrectEnabled={false}
|
|
263
263
|
/>
|
|
264
264
|
);
|
|
265
|
-
|
|
265
|
+
|
|
266
266
|
const icon = getByTestId('icon-image');
|
|
267
267
|
expect(icon).toBeInTheDocument();
|
|
268
268
|
});
|
|
@@ -277,7 +277,7 @@ describe('CircleComponent', () => {
|
|
|
277
277
|
showCorrectEnabled={false}
|
|
278
278
|
/>
|
|
279
279
|
);
|
|
280
|
-
|
|
280
|
+
|
|
281
281
|
const icon = getByTestId('icon-image');
|
|
282
282
|
expect(icon).toBeInTheDocument();
|
|
283
283
|
});
|
|
@@ -292,7 +292,7 @@ describe('CircleComponent', () => {
|
|
|
292
292
|
showCorrectEnabled={false}
|
|
293
293
|
/>
|
|
294
294
|
);
|
|
295
|
-
|
|
295
|
+
|
|
296
296
|
const icon = queryByTestId('icon-image');
|
|
297
297
|
expect(icon).not.toBeInTheDocument();
|
|
298
298
|
});
|
|
@@ -307,7 +307,7 @@ describe('CircleComponent', () => {
|
|
|
307
307
|
showCorrectEnabled={true}
|
|
308
308
|
/>
|
|
309
309
|
);
|
|
310
|
-
|
|
310
|
+
|
|
311
311
|
const icon = getByTestId('icon-image');
|
|
312
312
|
expect(icon).toBeInTheDocument();
|
|
313
313
|
});
|
|
@@ -322,7 +322,7 @@ describe('CircleComponent', () => {
|
|
|
322
322
|
showCorrectEnabled={true}
|
|
323
323
|
/>
|
|
324
324
|
);
|
|
325
|
-
|
|
325
|
+
|
|
326
326
|
const icon = getByTestId('icon-image');
|
|
327
327
|
expect(icon).toBeInTheDocument();
|
|
328
328
|
});
|
|
@@ -337,7 +337,7 @@ describe('CircleComponent', () => {
|
|
|
337
337
|
showCorrectEnabled={true}
|
|
338
338
|
/>
|
|
339
339
|
);
|
|
340
|
-
|
|
340
|
+
|
|
341
341
|
const icon = queryByTestId('icon-image');
|
|
342
342
|
expect(icon).not.toBeInTheDocument();
|
|
343
343
|
});
|
|
@@ -352,7 +352,7 @@ describe('CircleComponent', () => {
|
|
|
352
352
|
showCorrectEnabled={true}
|
|
353
353
|
/>
|
|
354
354
|
);
|
|
355
|
-
|
|
355
|
+
|
|
356
356
|
const icon = queryByTestId('icon-image');
|
|
357
357
|
expect(icon).not.toBeInTheDocument();
|
|
358
358
|
});
|
|
@@ -365,7 +365,7 @@ describe('CircleComponent', () => {
|
|
|
365
365
|
markAsCorrect={true}
|
|
366
366
|
/>
|
|
367
367
|
);
|
|
368
|
-
|
|
368
|
+
|
|
369
369
|
const circle = getByTestId('circle');
|
|
370
370
|
expect(circle).toHaveAttribute('stroke', 'green');
|
|
371
371
|
});
|
|
@@ -379,7 +379,7 @@ describe('CircleComponent', () => {
|
|
|
379
379
|
markAsCorrect={false}
|
|
380
380
|
/>
|
|
381
381
|
);
|
|
382
|
-
|
|
382
|
+
|
|
383
383
|
const circle = getByTestId('circle');
|
|
384
384
|
expect(circle).toHaveAttribute('stroke', 'red');
|
|
385
385
|
});
|
|
@@ -395,7 +395,7 @@ describe('CircleComponent', () => {
|
|
|
395
395
|
showCorrectEnabled={false}
|
|
396
396
|
/>
|
|
397
397
|
);
|
|
398
|
-
|
|
398
|
+
|
|
399
399
|
const icon = getByTestId('icon-image');
|
|
400
400
|
expect(icon).toHaveAttribute('data-tooltip', 'Great job!');
|
|
401
401
|
});
|
|
@@ -415,7 +415,7 @@ describe('CircleComponent', () => {
|
|
|
415
415
|
showCorrectEnabled={false}
|
|
416
416
|
/>
|
|
417
417
|
);
|
|
418
|
-
|
|
418
|
+
|
|
419
419
|
const icon = getByTestId('icon-image');
|
|
420
420
|
// Icon should be at x - 10, y - 10
|
|
421
421
|
expect(icon).toHaveAttribute('data-x', '90');
|
|
@@ -431,7 +431,7 @@ describe('CircleComponent', () => {
|
|
|
431
431
|
radius={5}
|
|
432
432
|
/>
|
|
433
433
|
);
|
|
434
|
-
|
|
434
|
+
|
|
435
435
|
const circle = getByTestId('circle');
|
|
436
436
|
expect(circle).toHaveAttribute('radius', '5');
|
|
437
437
|
});
|
|
@@ -443,7 +443,7 @@ describe('CircleComponent', () => {
|
|
|
443
443
|
radius={200}
|
|
444
444
|
/>
|
|
445
445
|
);
|
|
446
|
-
|
|
446
|
+
|
|
447
447
|
const circle = getByTestId('circle');
|
|
448
448
|
expect(circle).toHaveAttribute('radius', '200');
|
|
449
449
|
});
|
|
@@ -455,7 +455,7 @@ describe('CircleComponent', () => {
|
|
|
455
455
|
scale={0.5}
|
|
456
456
|
/>
|
|
457
457
|
);
|
|
458
|
-
|
|
458
|
+
|
|
459
459
|
const group = getByTestId('group');
|
|
460
460
|
expect(group).toHaveAttribute('scaleX', '0.5');
|
|
461
461
|
expect(group).toHaveAttribute('scaleY', '0.5');
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render } from '@testing-library/react';
|
|
3
|
+
import { renderMath } from '@pie-lib/math-rendering';
|
|
4
|
+
import HotspotComponent from '../index';
|
|
5
|
+
|
|
6
|
+
jest.mock('@pie-lib/math-rendering', () => ({
|
|
7
|
+
renderMath: jest.fn(),
|
|
8
|
+
}));
|
|
9
|
+
|
|
10
|
+
jest.mock('../container', () => (props) => <div data-testid="container" {...props} />);
|
|
11
|
+
|
|
12
|
+
describe('HotspotComponent', () => {
|
|
13
|
+
const defaultModel = {
|
|
14
|
+
disabled: false,
|
|
15
|
+
imageUrl: 'http://example.com/image.png',
|
|
16
|
+
prompt: 'prompt',
|
|
17
|
+
mode: 'gather',
|
|
18
|
+
multipleCorrect: false,
|
|
19
|
+
shapes: { rectangles: [], polygons: [], circles: [] },
|
|
20
|
+
dimensions: { width: 800, height: 600 },
|
|
21
|
+
strokeWidth: 5,
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const getWrapper = (props) =>
|
|
25
|
+
render(
|
|
26
|
+
<HotspotComponent
|
|
27
|
+
onSelectChoice={jest.fn()}
|
|
28
|
+
session={{ answers: [] }}
|
|
29
|
+
model={defaultModel}
|
|
30
|
+
{...props}
|
|
31
|
+
/>,
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
beforeEach(() => {
|
|
35
|
+
renderMath.mockClear();
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
describe('math rendering', () => {
|
|
39
|
+
it('calls renderMath on mount', () => {
|
|
40
|
+
getWrapper();
|
|
41
|
+
expect(renderMath).toHaveBeenCalled();
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('passes the rendered dom node to renderMath on mount', () => {
|
|
45
|
+
getWrapper();
|
|
46
|
+
expect(renderMath).toHaveBeenCalledWith(expect.any(HTMLElement));
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('calls renderMath again on update', () => {
|
|
50
|
+
const { rerender } = getWrapper();
|
|
51
|
+
renderMath.mockClear();
|
|
52
|
+
|
|
53
|
+
rerender(
|
|
54
|
+
<HotspotComponent
|
|
55
|
+
onSelectChoice={jest.fn()}
|
|
56
|
+
session={{ answers: [] }}
|
|
57
|
+
model={{ ...defaultModel, prompt: 'updated prompt' }}
|
|
58
|
+
/>,
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
expect(renderMath).toHaveBeenCalled();
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
});
|