@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
package/docs/demo/generate.js
CHANGED
|
@@ -13,6 +13,7 @@ exports.model = (id, element) => ({
|
|
|
13
13
|
'rgba(254, 241, 96, 0.25)',
|
|
14
14
|
'rgba(0, 0, 0, 0.1)',
|
|
15
15
|
],
|
|
16
|
+
// hoverOutlineColor: 'black',
|
|
16
17
|
outlineColor: 'blue',
|
|
17
18
|
outlineList: ['blue', 'red', 'yellow'],
|
|
18
19
|
multipleCorrect: true,
|
|
@@ -25,7 +26,8 @@ exports.model = (id, element) => ({
|
|
|
25
26
|
x: 261,
|
|
26
27
|
y: 44,
|
|
27
28
|
index: 2,
|
|
28
|
-
correct: true
|
|
29
|
+
correct: true,
|
|
30
|
+
// ariaLabel: 'First rectangle',
|
|
29
31
|
},
|
|
30
32
|
{
|
|
31
33
|
id: '4',
|
|
@@ -34,8 +36,8 @@ exports.model = (id, element) => ({
|
|
|
34
36
|
x: 270,
|
|
35
37
|
y: 215.4886474609375,
|
|
36
38
|
index: 3,
|
|
37
|
-
correct: false
|
|
38
|
-
}
|
|
39
|
+
correct: false,
|
|
40
|
+
},
|
|
39
41
|
],
|
|
40
42
|
polygons: [
|
|
41
43
|
{
|
|
@@ -53,10 +55,11 @@ exports.model = (id, element) => ({
|
|
|
53
55
|
{ x: 109, y: 294 },
|
|
54
56
|
{ x: 106, y: 280 },
|
|
55
57
|
{ x: 56, y: 193 },
|
|
56
|
-
{ x: 68, y: 139 }
|
|
58
|
+
{ x: 68, y: 139 },
|
|
57
59
|
],
|
|
58
60
|
index: 1,
|
|
59
|
-
correct: false
|
|
61
|
+
correct: false,
|
|
62
|
+
// ariaLabel: 'First polygon',
|
|
60
63
|
},
|
|
61
64
|
{
|
|
62
65
|
id: '5',
|
|
@@ -71,10 +74,10 @@ exports.model = (id, element) => ({
|
|
|
71
74
|
{ x: 564, y: 465 },
|
|
72
75
|
{ x: 575, y: 461 },
|
|
73
76
|
{ x: 575, y: 438 },
|
|
74
|
-
{ x: 544, y: 367 }
|
|
77
|
+
{ x: 544, y: 367 },
|
|
75
78
|
],
|
|
76
79
|
index: 4,
|
|
77
|
-
correct: false
|
|
80
|
+
correct: false,
|
|
78
81
|
},
|
|
79
82
|
{
|
|
80
83
|
id: '7',
|
|
@@ -84,11 +87,11 @@ exports.model = (id, element) => ({
|
|
|
84
87
|
{ x: 556, y: 287 },
|
|
85
88
|
{ x: 575, y: 302 },
|
|
86
89
|
{ x: 601, y: 280 },
|
|
87
|
-
{ x: 598, y: 246 }
|
|
90
|
+
{ x: 598, y: 246 },
|
|
88
91
|
],
|
|
89
92
|
index: 6,
|
|
90
|
-
correct: true
|
|
91
|
-
}
|
|
93
|
+
correct: true,
|
|
94
|
+
},
|
|
92
95
|
],
|
|
93
96
|
circles: [
|
|
94
97
|
{
|
|
@@ -97,7 +100,8 @@ exports.model = (id, element) => ({
|
|
|
97
100
|
x: 71,
|
|
98
101
|
y: 420,
|
|
99
102
|
index: 1,
|
|
100
|
-
correct: false
|
|
103
|
+
correct: false,
|
|
104
|
+
// ariaLabel: 'First circle',
|
|
101
105
|
},
|
|
102
106
|
{
|
|
103
107
|
id: '6',
|
|
@@ -105,14 +109,14 @@ exports.model = (id, element) => ({
|
|
|
105
109
|
x: 479,
|
|
106
110
|
y: 140,
|
|
107
111
|
index: 5,
|
|
108
|
-
correct: false
|
|
109
|
-
|
|
110
|
-
|
|
112
|
+
correct: false,
|
|
113
|
+
// ariaLabel: 'Second circle',
|
|
114
|
+
},
|
|
115
|
+
],
|
|
111
116
|
},
|
|
112
117
|
rationale: null,
|
|
113
118
|
teacherInstructions: null,
|
|
114
119
|
toolbarEditorPosition: 'bottom',
|
|
115
|
-
prompt:
|
|
116
|
-
'<div>Which state(s) have names beginning in "North"?</div>',
|
|
120
|
+
prompt: '<div>Which state(s) have names beginning in "North"?</div>',
|
|
117
121
|
rubricEnabled: false,
|
|
118
122
|
});
|
package/lib/hotspot/circle.js
CHANGED
|
@@ -62,6 +62,7 @@ class CircleComponent extends _react.default.Component {
|
|
|
62
62
|
hoverOutlineColor,
|
|
63
63
|
outlineColor,
|
|
64
64
|
selected,
|
|
65
|
+
focused,
|
|
65
66
|
x,
|
|
66
67
|
y,
|
|
67
68
|
evaluateText,
|
|
@@ -95,18 +96,13 @@ class CircleComponent extends _react.default.Component {
|
|
|
95
96
|
iconSrc = _icons.faWrong;
|
|
96
97
|
}
|
|
97
98
|
}
|
|
98
|
-
const useHoveredStyle = hovered && hoverOutlineColor;
|
|
99
|
+
const useHoveredStyle = (hovered || focused) && hoverOutlineColor;
|
|
99
100
|
return /*#__PURE__*/_react.default.createElement(_reactKonva.Group, {
|
|
100
101
|
scaleX: scale,
|
|
101
|
-
scaleY: scale
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
width: radius * 2,
|
|
106
|
-
height: radius * 2,
|
|
107
|
-
stroke: selected ? 'transparent' : hoverOutlineColor,
|
|
108
|
-
strokeWidth: strokeWidth
|
|
109
|
-
}), /*#__PURE__*/_react.default.createElement(_reactKonva.Circle, {
|
|
102
|
+
scaleY: scale,
|
|
103
|
+
onMouseLeave: this.handleMouseLeave,
|
|
104
|
+
onMouseEnter: this.handleMouseEnter
|
|
105
|
+
}, /*#__PURE__*/_react.default.createElement(_reactKonva.Circle, {
|
|
110
106
|
radius: radius,
|
|
111
107
|
fill: selected && selectedHotspotColor ? selectedHotspotColor : hotspotColor,
|
|
112
108
|
onClick: this.handleClick,
|
|
@@ -114,10 +110,16 @@ class CircleComponent extends _react.default.Component {
|
|
|
114
110
|
draggable: false,
|
|
115
111
|
stroke: useHoveredStyle && !selected ? 'transparent' : outlineColorParsed,
|
|
116
112
|
strokeWidth: useHoveredStyle && !selected ? 0 : outlineWidth,
|
|
117
|
-
onMouseLeave: this.handleMouseLeave,
|
|
118
|
-
onMouseEnter: this.handleMouseEnter,
|
|
119
113
|
x: x,
|
|
120
114
|
y: y
|
|
115
|
+
}), useHoveredStyle && /*#__PURE__*/_react.default.createElement(_reactKonva.Rect, {
|
|
116
|
+
x: x - radius,
|
|
117
|
+
y: y - radius,
|
|
118
|
+
width: radius * 2,
|
|
119
|
+
height: radius * 2,
|
|
120
|
+
stroke: hoverOutlineColor,
|
|
121
|
+
strokeWidth: strokeWidth,
|
|
122
|
+
listening: false
|
|
121
123
|
}), isEvaluateMode && iconSrc ? /*#__PURE__*/_react.default.createElement(_imageKonvaTooltip.default, {
|
|
122
124
|
src: iconSrc,
|
|
123
125
|
x: iconX,
|
|
@@ -133,6 +135,7 @@ CircleComponent.propTypes = {
|
|
|
133
135
|
isCorrect: _propTypes.default.oneOfType([_propTypes.default.bool, _propTypes.default.string]),
|
|
134
136
|
isEvaluateMode: _propTypes.default.bool.isRequired,
|
|
135
137
|
disabled: _propTypes.default.bool.isRequired,
|
|
138
|
+
focused: _propTypes.default.bool,
|
|
136
139
|
hoverOutlineColor: _propTypes.default.string,
|
|
137
140
|
onClick: _propTypes.default.func.isRequired,
|
|
138
141
|
outlineColor: _propTypes.default.string.isRequired,
|
|
@@ -149,6 +152,7 @@ CircleComponent.propTypes = {
|
|
|
149
152
|
CircleComponent.defaultProps = {
|
|
150
153
|
isCorrect: false,
|
|
151
154
|
evaluateText: null,
|
|
155
|
+
focused: false,
|
|
152
156
|
strokeWidth: 5,
|
|
153
157
|
scale: 1
|
|
154
158
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"circle.js","names":["_react","_interopRequireDefault","require","_propTypes","_reactKonva","_imageKonvaTooltip","_icons","CircleComponent","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","radius","hotspotColor","isEvaluateMode","hoverOutlineColor","x","y","evaluateText","scale","selectedHotspotColor","outlineColorParsed","getEvaluateOutlineColor","outlineWidth","getOutlineWidth","iconX","iconY","iconSrc","faCorrect","faWrong","useHoveredStyle","createElement","Group","scaleX","scaleY","Rect","width","height","stroke","Circle","fill","handleClick","onTap","draggable","onMouseLeave","handleMouseLeave","onMouseEnter","handleMouseEnter","src","tooltip","propTypes","PropTypes","number","isRequired","string","oneOfType","bool","func","defaultProps","_default","exports"],"sources":["../../src/hotspot/circle.jsx"],"sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\nimport { Circle, Group, Rect } from 'react-konva';\nimport ImageComponent from './image-konva-tooltip';\nimport { faCorrect, faWrong } from './icons';\n\nclass CircleComponent 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 radius,\n hotspotColor,\n isCorrect,\n isEvaluateMode,\n hoverOutlineColor,\n outlineColor,\n selected,\n x,\n y,\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\n const outlineWidth = this.getOutlineWidth(showCorrectEnabled, selected, markAsCorrect, strokeWidth);\n\n const iconX = x - 10;\n const iconY = y - 10; // Adjust position for the icon\n\n let iconSrc;\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 && hoverOutlineColor;\n\n return (\n <Group scaleX={scale} scaleY={scale}>\n {useHoveredStyle && (\n <Rect\n x={x - radius}\n y={y - radius}\n width={radius * 2}\n height={radius * 2}\n stroke={selected ? 'transparent' : hoverOutlineColor}\n strokeWidth={strokeWidth}\n />\n )}\n <Circle\n radius={radius}\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 x={x}\n y={y}\n />\n {isEvaluateMode && iconSrc ? <ImageComponent src={iconSrc} x={iconX} y={iconY} tooltip={evaluateText} /> : null}\n </Group>\n );\n }\n}\n\nCircleComponent.propTypes = {\n radius: 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 disabled: PropTypes.bool.isRequired,\n hoverOutlineColor: PropTypes.string,\n onClick: PropTypes.func.isRequired,\n outlineColor: PropTypes.string.isRequired,\n selected: PropTypes.bool.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\nCircleComponent.defaultProps = {\n isCorrect: false,\n evaluateText: null,\n strokeWidth: 5,\n scale: 1,\n};\n\nexport default CircleComponent;\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,eAAe,SAASC,cAAK,CAACC,SAAS,CAAC;EAC5CC,WAAWA,CAACC,KAAK,EAAE;IACjB,KAAK,CAACA,KAAK,CAAC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EsC,kBAAS,CAACG,MAAM,CAACD,UAAU;EACzC3D,EAAE,EAAEyD,kBAAS,CAACG,MAAM,CAACD,UAAU;EAC/BhD,SAAS,EAAE8C,kBAAS,CAACI,SAAS,CAAC,CAACJ,kBAAS,CAACK,IAAI,EAAEL,kBAAS,CAACG,MAAM,CAAC,CAAC;EAClExC,cAAc,EAAEqC,kBAAS,CAACK,IAAI,CAACH,UAAU;EACzCzD,QAAQ,EAAEuD,kBAAS,CAACK,IAAI,CAACH,UAAU;EACnCtC,iBAAiB,EAAEoC,kBAAS,CAACG,MAAM;EACnC7D,OAAO,EAAE0D,kBAAS,CAACM,IAAI,CAACJ,UAAU;EAClC9C,YAAY,EAAE4C,kBAAS,CAACG,MAAM,CAACD,UAAU;EACzC1D,QAAQ,EAAEwD,kBAAS,CAACK,IAAI,CAACH,UAAU;EACnCrC,CAAC,EAAEmC,kBAAS,CAACC,MAAM,CAACC,UAAU;EAC9BpC,CAAC,EAAEkC,kBAAS,CAACC,MAAM,CAACC,UAAU;EAC9BnC,YAAY,EAAEiC,kBAAS,CAACG,MAAM;EAC9B7C,WAAW,EAAE0C,kBAAS,CAACC,MAAM;EAC7BjC,KAAK,EAAEgC,kBAAS,CAACC,MAAM;EACvBhC,oBAAoB,EAAE+B,kBAAS,CAACG,MAAM;EACtChD,aAAa,EAAE6C,kBAAS,CAACK,IAAI,CAACH,UAAU;EACxC7C,kBAAkB,EAAE2C,kBAAS,CAACK,IAAI,CAACH;AACrC,CAAC;AAEDpE,eAAe,CAACyE,YAAY,GAAG;EAC7BrD,SAAS,EAAE,KAAK;EAChBa,YAAY,EAAE,IAAI;EAClBT,WAAW,EAAE,CAAC;EACdU,KAAK,EAAE;AACT,CAAC;AAAC,IAAAwC,QAAA,GAAAC,OAAA,CAAArE,OAAA,GAEaN,eAAe","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"circle.js","names":["_react","_interopRequireDefault","require","_propTypes","_reactKonva","_imageKonvaTooltip","_icons","CircleComponent","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","radius","hotspotColor","isEvaluateMode","hoverOutlineColor","focused","x","y","evaluateText","scale","selectedHotspotColor","outlineColorParsed","getEvaluateOutlineColor","outlineWidth","getOutlineWidth","iconX","iconY","iconSrc","faCorrect","faWrong","useHoveredStyle","createElement","Group","scaleX","scaleY","onMouseLeave","handleMouseLeave","onMouseEnter","handleMouseEnter","Circle","fill","handleClick","onTap","draggable","stroke","Rect","width","height","listening","src","tooltip","propTypes","PropTypes","number","isRequired","string","oneOfType","bool","func","defaultProps","_default","exports"],"sources":["../../src/hotspot/circle.jsx"],"sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\nimport { Circle, Group, Rect } from 'react-konva';\nimport ImageComponent from './image-konva-tooltip';\nimport { faCorrect, faWrong } from './icons';\n\nclass CircleComponent 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 radius,\n hotspotColor,\n isCorrect,\n isEvaluateMode,\n hoverOutlineColor,\n outlineColor,\n selected,\n focused,\n x,\n y,\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\n const outlineWidth = this.getOutlineWidth(showCorrectEnabled, selected, markAsCorrect, strokeWidth);\n\n const iconX = x - 10;\n const iconY = y - 10; // Adjust position for the icon\n\n let iconSrc;\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 <Circle\n radius={radius}\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 x={x}\n y={y}\n />\n {useHoveredStyle && (\n <Rect\n x={x - radius}\n y={y - radius}\n width={radius * 2}\n height={radius * 2}\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\nCircleComponent.propTypes = {\n radius: 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 disabled: PropTypes.bool.isRequired,\n focused: PropTypes.bool,\n hoverOutlineColor: PropTypes.string,\n onClick: PropTypes.func.isRequired,\n outlineColor: PropTypes.string.isRequired,\n selected: PropTypes.bool.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\nCircleComponent.defaultProps = {\n isCorrect: false,\n evaluateText: null,\n focused: false,\n strokeWidth: 5,\n scale: 1,\n};\n\nexport default CircleComponent;\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,eAAe,SAASC,cAAK,CAACC,SAAS,CAAC;EAC5CC,WAAWA,CAACC,KAAK,EAAE;IACjB,KAAK,CAACA,KAAK,CAAC;IAAC,IAAAC,gBAAA,CAAAC,OAAA,uBAMAC,CAAC,IAAK;MACnB,MAAM;QAAEC,OAAO;QAAEC,EAAE;QAAEC,QAAQ;QAAEC;MAAS,CAAC,GAAG,IAAI,CAACP,KAAK;MAEtD,IAAI,CAACO,QAAQ,EAAE;QACbJ,CAAC,CAACK,YAAY,GAAG,IAAI;QACrBJ,OAAO,CAAC;UAAEC,EAAE;UAAEC,QAAQ,EAAE,CAACA,QAAQ;UAAEG,QAAQ,EAAE;QAAQ,CAAC,CAAC;MACzD;IACF,CAAC;IAAA,IAAAR,gBAAA,CAAAC,OAAA,4BAEkB,MAAM;MACvB,MAAM;QAAEK;MAAS,CAAC,GAAG,IAAI,CAACP,KAAK;MAE/B,IAAI,CAACO,QAAQ,EAAE;QACbG,QAAQ,CAACC,IAAI,CAACC,KAAK,CAACC,MAAM,GAAG,SAA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;EACzC5D,QAAQ,EAAE0D,kBAAS,CAACK,IAAI,CAACH,UAAU;EACnCtC,CAAC,EAAEoC,kBAAS,CAACC,MAAM,CAACC,UAAU;EAC9BrC,CAAC,EAAEmC,kBAAS,CAACC,MAAM,CAACC,UAAU;EAC9BpC,YAAY,EAAEkC,kBAAS,CAACG,MAAM;EAC9B/C,WAAW,EAAE4C,kBAAS,CAACC,MAAM;EAC7BlC,KAAK,EAAEiC,kBAAS,CAACC,MAAM;EACvBjC,oBAAoB,EAAEgC,kBAAS,CAACG,MAAM;EACtClD,aAAa,EAAE+C,kBAAS,CAACK,IAAI,CAACH,UAAU;EACxC/C,kBAAkB,EAAE6C,kBAAS,CAACK,IAAI,CAACH;AACrC,CAAC;AAEDtE,eAAe,CAAC2E,YAAY,GAAG;EAC7BvD,SAAS,EAAE,KAAK;EAChBc,YAAY,EAAE,IAAI;EAClBH,OAAO,EAAE,KAAK;EACdP,WAAW,EAAE,CAAC;EACdW,KAAK,EAAE;AACT,CAAC;AAAC,IAAAyC,QAAA,GAAAC,OAAA,CAAAvE,OAAA,GAEaN,eAAe","ignoreList":[]}
|
package/lib/hotspot/container.js
CHANGED
|
@@ -21,8 +21,18 @@ const BaseContainer = (0, _styles.styled)('div')(({
|
|
|
21
21
|
position: 'relative',
|
|
22
22
|
background: theme.palette.common.white,
|
|
23
23
|
border: `${theme.spacing(1)} solid ${theme.palette.common.white}`,
|
|
24
|
-
width: 'fit-content'
|
|
24
|
+
width: 'fit-content',
|
|
25
|
+
maxWidth: '100%',
|
|
26
|
+
overflowX: 'auto'
|
|
25
27
|
}));
|
|
28
|
+
const HiddenFocusable = (0, _styles.styled)('span')({
|
|
29
|
+
position: 'absolute',
|
|
30
|
+
width: 1,
|
|
31
|
+
height: 1,
|
|
32
|
+
overflow: 'hidden',
|
|
33
|
+
clip: 'rect(0, 0, 0, 0)',
|
|
34
|
+
whiteSpace: 'nowrap'
|
|
35
|
+
});
|
|
26
36
|
const ImageContainer = (0, _styles.styled)('div')({
|
|
27
37
|
position: 'relative',
|
|
28
38
|
width: 'fit-content'
|
|
@@ -38,8 +48,8 @@ const StyledStage = (0, _styles.styled)(_reactKonva.Stage)({
|
|
|
38
48
|
position: 'absolute'
|
|
39
49
|
});
|
|
40
50
|
class Container extends _react.default.Component {
|
|
41
|
-
constructor(
|
|
42
|
-
super(
|
|
51
|
+
constructor(props) {
|
|
52
|
+
super(props);
|
|
43
53
|
(0, _defineProperty2.default)(this, "correctness", (isCorrect, isChecked) => isCorrect ? isChecked : !isChecked);
|
|
44
54
|
(0, _defineProperty2.default)(this, "getEvaluateText", (isCorrect, selected) => {
|
|
45
55
|
if (selected && isCorrect) {
|
|
@@ -53,6 +63,62 @@ class Container extends _react.default.Component {
|
|
|
53
63
|
}
|
|
54
64
|
return null;
|
|
55
65
|
});
|
|
66
|
+
(0, _defineProperty2.default)(this, "getAllShapesSorted", () => {
|
|
67
|
+
const {
|
|
68
|
+
shapes: {
|
|
69
|
+
rectangles = [],
|
|
70
|
+
polygons = [],
|
|
71
|
+
circles = []
|
|
72
|
+
}
|
|
73
|
+
} = this.props;
|
|
74
|
+
const allShapes = [...rectangles.map(s => ({
|
|
75
|
+
...s,
|
|
76
|
+
type: 'rectangle'
|
|
77
|
+
})), ...polygons.map(s => ({
|
|
78
|
+
...s,
|
|
79
|
+
type: 'polygon'
|
|
80
|
+
})), ...circles.map(s => ({
|
|
81
|
+
...s,
|
|
82
|
+
type: 'circle'
|
|
83
|
+
}))];
|
|
84
|
+
allShapes.sort((a, b) => String(a.id).localeCompare(String(b.id), undefined, {
|
|
85
|
+
numeric: true
|
|
86
|
+
}));
|
|
87
|
+
return allShapes;
|
|
88
|
+
});
|
|
89
|
+
(0, _defineProperty2.default)(this, "handleShapeFocus", shapeId => {
|
|
90
|
+
this.setState({
|
|
91
|
+
focusedShapeId: shapeId
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
(0, _defineProperty2.default)(this, "handleShapeBlur", () => {
|
|
95
|
+
this.setState({
|
|
96
|
+
focusedShapeId: null
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
(0, _defineProperty2.default)(this, "handleShapeKeyDown", (e, shapeId) => {
|
|
100
|
+
if (e.key === 'Enter' || e.key === ' ') {
|
|
101
|
+
e.preventDefault();
|
|
102
|
+
const {
|
|
103
|
+
onSelectChoice,
|
|
104
|
+
disabled
|
|
105
|
+
} = this.props;
|
|
106
|
+
if (!disabled) {
|
|
107
|
+
const shape = this.getAllShapesSorted().find(s => s.id === shapeId);
|
|
108
|
+
if (shape) {
|
|
109
|
+
const selected = this.isSelected(shape);
|
|
110
|
+
onSelectChoice({
|
|
111
|
+
id: shapeId,
|
|
112
|
+
selected: !selected,
|
|
113
|
+
selector: 'Keyboard'
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
this.state = {
|
|
120
|
+
focusedShapeId: null
|
|
121
|
+
};
|
|
56
122
|
}
|
|
57
123
|
isSelected(shape) {
|
|
58
124
|
const selectedShape = this.props.session.answers.filter(answer => answer.id === shape.id)[0];
|
|
@@ -81,8 +147,12 @@ class Container extends _react.default.Component {
|
|
|
81
147
|
strokeWidth,
|
|
82
148
|
showCorrect
|
|
83
149
|
} = this.props;
|
|
150
|
+
const {
|
|
151
|
+
focusedShapeId
|
|
152
|
+
} = this.state;
|
|
84
153
|
const width = withProp * SCALE;
|
|
85
154
|
const height = heightProp * SCALE;
|
|
155
|
+
const sortedShapes = this.getAllShapesSorted();
|
|
86
156
|
return /*#__PURE__*/_react.default.createElement(BaseContainer, {
|
|
87
157
|
style: {
|
|
88
158
|
padding: strokeWidth / 2
|
|
@@ -127,7 +197,8 @@ class Container extends _react.default.Component {
|
|
|
127
197
|
y: shape.y,
|
|
128
198
|
strokeWidth: strokeWidth,
|
|
129
199
|
markAsCorrect: markAsCorrect,
|
|
130
|
-
showCorrectEnabled: showCorrect
|
|
200
|
+
showCorrectEnabled: showCorrect,
|
|
201
|
+
focused: focusedShapeId === shape.id
|
|
131
202
|
});
|
|
132
203
|
}), polygons.map(polygon => {
|
|
133
204
|
const selected = this.isSelected(polygon);
|
|
@@ -151,7 +222,8 @@ class Container extends _react.default.Component {
|
|
|
151
222
|
markAsCorrect: markAsCorrect,
|
|
152
223
|
selectedHotspotColor: selectedHotspotColor,
|
|
153
224
|
hoverOutlineColor: hoverOutlineColor,
|
|
154
|
-
showCorrectEnabled: showCorrect
|
|
225
|
+
showCorrectEnabled: showCorrect,
|
|
226
|
+
focused: focusedShapeId === polygon.id
|
|
155
227
|
});
|
|
156
228
|
}), circles.map(shape => {
|
|
157
229
|
const selected = this.isSelected(shape);
|
|
@@ -177,9 +249,22 @@ class Container extends _react.default.Component {
|
|
|
177
249
|
markAsCorrect: markAsCorrect,
|
|
178
250
|
selectedHotspotColor: selectedHotspotColor,
|
|
179
251
|
hoverOutlineColor: hoverOutlineColor,
|
|
180
|
-
showCorrectEnabled: showCorrect
|
|
252
|
+
showCorrectEnabled: showCorrect,
|
|
253
|
+
focused: focusedShapeId === shape.id
|
|
254
|
+
});
|
|
255
|
+
}))), sortedShapes.map(shape => {
|
|
256
|
+
const selected = this.isSelected(shape);
|
|
257
|
+
return /*#__PURE__*/_react.default.createElement(HiddenFocusable, {
|
|
258
|
+
key: `focus-${shape.id}`,
|
|
259
|
+
tabIndex: disabled ? -1 : 0,
|
|
260
|
+
role: "button",
|
|
261
|
+
"aria-label": shape.ariaLabel || '',
|
|
262
|
+
"aria-pressed": selected,
|
|
263
|
+
onFocus: () => this.handleShapeFocus(shape.id),
|
|
264
|
+
onBlur: this.handleShapeBlur,
|
|
265
|
+
onKeyDown: e => this.handleShapeKeyDown(e, shape.id)
|
|
181
266
|
});
|
|
182
|
-
}))
|
|
267
|
+
}));
|
|
183
268
|
}
|
|
184
269
|
}
|
|
185
270
|
exports.Container = Container;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"container.js","names":["_react","_interopRequireDefault","require","_propTypes","_reactKonva","_styles","_rectangle","_polygon","_circle","BaseContainer","styled","theme","marginTop","spacing","marginBottom","position","background","palette","common","white","border","width","ImageContainer","Image","alignItems","display","justifyContent","StyledStage","Stage","left","top","Container","React","Component","constructor","args","_defineProperty2","default","isCorrect","isChecked","selected","isSelected","shape","selectedShape","props","session","answers","filter","answer","id","render","dimensions","withProp","height","heightProp","disabled","hotspotColor","hoverOutlineColor","selectedHotspotColor","imageUrl","isEvaluateMode","outlineColor","onSelectChoice","shapes","rectangles","polygons","circles","scale","SCALE","strokeWidth","showCorrect","createElement","style","padding","alt","src","maxWidth","maxHeight","x","y","Layer","map","correctness","correct","undefined","evaluateText","getEvaluateText","markAsCorrect","key","onClick","showCorrectEnabled","polygon","points","radius","exports","propTypes","PropTypes","object","isRequired","bool","string","func","number","defaultProps","_default"],"sources":["../../src/hotspot/container.jsx"],"sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\nimport { Layer, Stage } from 'react-konva';\nimport { styled } from '@mui/material/styles';\n\nimport Rectangle from './rectangle';\nimport Polygon from './polygon';\nimport Circle from './circle';\n\nconst BaseContainer = styled('div')(({ theme }) => ({\n marginTop: theme.spacing(2),\n marginBottom: theme.spacing(2),\n position: 'relative',\n background: theme.palette.common.white,\n border: `${theme.spacing(1)} solid ${theme.palette.common.white}`,\n width: 'fit-content',\n}));\n\nconst ImageContainer = styled('div')({\n position: 'relative',\n width: 'fit-content',\n});\n\nconst Image = styled('img')({\n alignItems: 'center',\n display: 'flex',\n justifyContent: 'center',\n});\n\nconst StyledStage = styled(Stage)({\n left: 0,\n top: 0,\n position: 'absolute',\n});\n\nexport class Container extends React.Component {\n isSelected(shape) {\n const selectedShape = this.props.session.answers.filter((answer) => answer.id === shape.id)[0];\n return !!selectedShape;\n }\n\n correctness = (isCorrect, isChecked) => (isCorrect ? isChecked : !isChecked);\n\n getEvaluateText = (isCorrect, selected) => {\n if (selected && isCorrect) {\n return 'Correctly\\nselected';\n }\n\n if (selected && !isCorrect) {\n return 'Should not have\\nbeen selected';\n }\n\n if (!selected && isCorrect) {\n return 'Should have\\nbeen selected';\n }\n\n return null;\n };\n\n render() {\n const {\n dimensions: { width: withProp, height: heightProp },\n disabled,\n hotspotColor,\n hoverOutlineColor,\n selectedHotspotColor,\n imageUrl,\n isEvaluateMode,\n outlineColor,\n onSelectChoice,\n shapes: { rectangles = [], polygons = [], circles = [] },\n scale: SCALE,\n strokeWidth,\n showCorrect,\n } = this.props;\n\n const width = withProp * SCALE;\n const height = heightProp * SCALE;\n\n return (\n <BaseContainer style={{ padding: strokeWidth / 2 }}>\n {imageUrl ? (\n <ImageContainer>\n <Image\n alt=\"hotspot-image\"\n height=\"auto\"\n src={imageUrl}\n style={{ width, height, maxWidth: width, maxHeight: height }}\n />\n </ImageContainer>\n ) : null}\n\n <StyledStage\n height={height + strokeWidth}\n width={width + strokeWidth}\n x={strokeWidth / 2}\n y={strokeWidth / 2}\n >\n <Layer>\n {rectangles.map((shape) => {\n const selected = this.isSelected(shape);\n const isCorrect = isEvaluateMode ? this.correctness(shape.correct, selected) : undefined;\n const evaluateText = isEvaluateMode ? this.getEvaluateText(shape.correct, selected) : null;\n const markAsCorrect = !!(isEvaluateMode && showCorrect && shape.correct);\n\n return (\n <Rectangle\n scale={SCALE}\n isEvaluateMode={isEvaluateMode}\n isCorrect={isCorrect}\n evaluateText={evaluateText}\n disabled={disabled}\n selected={selected}\n height={shape.height}\n hotspotColor={hotspotColor}\n hoverOutlineColor={hoverOutlineColor}\n selectedHotspotColor={selectedHotspotColor}\n id={shape.id}\n key={shape.id}\n onClick={onSelectChoice}\n outlineColor={outlineColor}\n width={shape.width}\n x={shape.x}\n y={shape.y}\n strokeWidth={strokeWidth}\n markAsCorrect={markAsCorrect}\n showCorrectEnabled={showCorrect}\n />\n );\n })}\n {polygons.map((polygon) => {\n const selected = this.isSelected(polygon);\n const isCorrect = isEvaluateMode ? this.correctness(polygon.correct, selected) : undefined;\n const evaluateText = isEvaluateMode ? this.getEvaluateText(polygon.correct, selected) : null;\n const markAsCorrect = !!(isEvaluateMode && showCorrect && polygon.correct);\n\n return (\n <Polygon\n scale={SCALE}\n isEvaluateMode={isEvaluateMode}\n isCorrect={!!isCorrect}\n evaluateText={evaluateText}\n disabled={disabled}\n selected={selected}\n hotspotColor={hotspotColor}\n id={polygon.id}\n key={polygon.id}\n onClick={onSelectChoice}\n outlineColor={outlineColor}\n points={polygon.points}\n strokeWidth={strokeWidth}\n markAsCorrect={markAsCorrect}\n selectedHotspotColor={selectedHotspotColor}\n hoverOutlineColor={hoverOutlineColor}\n showCorrectEnabled={showCorrect}\n />\n );\n })}\n {circles.map((shape) => {\n const selected = this.isSelected(shape);\n const isCorrect = isEvaluateMode ? this.correctness(shape.correct, selected) : undefined;\n const evaluateText = isEvaluateMode ? this.getEvaluateText(shape.correct, selected) : null;\n const markAsCorrect = !!(isEvaluateMode && showCorrect && shape.correct);\n\n return (\n <Circle\n scale={SCALE}\n isEvaluateMode={isEvaluateMode}\n isCorrect={isCorrect}\n evaluateText={evaluateText}\n disabled={disabled}\n selected={selected}\n radius={shape.radius}\n hotspotColor={hotspotColor}\n id={shape.id}\n key={shape.id}\n onClick={onSelectChoice}\n outlineColor={outlineColor}\n x={shape.x}\n y={shape.y}\n strokeWidth={strokeWidth}\n markAsCorrect={markAsCorrect}\n selectedHotspotColor={selectedHotspotColor}\n hoverOutlineColor={hoverOutlineColor}\n showCorrectEnabled={showCorrect}\n />\n );\n })}\n </Layer>\n </StyledStage>\n </BaseContainer>\n );\n }\n}\n\nContainer.propTypes = {\n dimensions: PropTypes.object.isRequired,\n disabled: PropTypes.bool.isRequired,\n hotspotColor: PropTypes.string.isRequired,\n hoverOutlineColor: PropTypes.string,\n imageUrl: PropTypes.string.isRequired,\n isEvaluateMode: PropTypes.bool.isRequired,\n onSelectChoice: PropTypes.func.isRequired,\n outlineColor: PropTypes.string.isRequired,\n selectedHotspotColor: PropTypes.string,\n session: PropTypes.object.isRequired,\n shapes: PropTypes.object.isRequired,\n strokeWidth: PropTypes.number,\n scale: PropTypes.number,\n showCorrect: PropTypes.bool,\n};\n\nContainer.defaultProps = {\n scale: 1,\n};\n\nexport default Container;\n"],"mappings":";;;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,UAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,WAAA,GAAAF,OAAA;AACA,IAAAG,OAAA,GAAAH,OAAA;AAEA,IAAAI,UAAA,GAAAL,sBAAA,CAAAC,OAAA;AACA,IAAAK,QAAA,GAAAN,sBAAA,CAAAC,OAAA;AACA,IAAAM,OAAA,GAAAP,sBAAA,CAAAC,OAAA;AAEA,MAAMO,aAAa,GAAG,IAAAC,cAAM,EAAC,KAAK,CAAC,CAAC,CAAC;EAAEC;AAAM,CAAC,MAAM;EAClDC,SAAS,EAAED,KAAK,CAACE,OAAO,CAAC,CAAC,CAAC;EAC3BC,YAAY,EAAEH,KAAK,CAACE,OAAO,CAAC,CAAC,CAAC;EAC9BE,QAAQ,EAAE,UAAU;EACpBC,UAAU,EAAEL,KAAK,CAACM,OAAO,CAACC,MAAM,CAACC,KAAK;EACtCC,MAAM,EAAE,GAAGT,KAAK,CAACE,OAAO,CAAC,CAAC,CAAC,UAAUF,KAAK,CAACM,OAAO,CAACC,MAAM,CAACC,KAAK,EAAE;EACjEE,KAAK,EAAE;AACT,CAAC,CAAC,CAAC;AAEH,MAAMC,cAAc,GAAG,IAAAZ,cAAM,EAAC,KAAK,CAAC,CAAC;EACnCK,QAAQ,EAAE,UAAU;EACpBM,KAAK,EAAE;AACT,CAAC,CAAC;AAEF,MAAME,KAAK,GAAG,IAAAb,cAAM,EAAC,KAAK,CAAC,CAAC;EAC1Bc,UAAU,EAAE,QAAQ;EACpBC,OAAO,EAAE,MAAM;EACfC,cAAc,EAAE;AAClB,CAAC,CAAC;AAEF,MAAMC,WAAW,GAAG,IAAAjB,cAAM,EAACkB,iBAAK,CAAC,CAAC;EA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S,CAACC,MAAM,CAACC,UAAU;EACpCnC,MAAM,EAAEiC,kBAAS,CAACC,MAAM,CAACC,UAAU;EACnC7B,WAAW,EAAE2B,kBAAS,CAACM,MAAM;EAC7BnC,KAAK,EAAE6B,kBAAS,CAACM,MAAM;EACvBhC,WAAW,EAAE0B,kBAAS,CAACG;AACzB,CAAC;AAEDpE,SAAS,CAACwE,YAAY,GAAG;EACvBpC,KAAK,EAAE;AACT,CAAC;AAAC,IAAAqC,QAAA,GAAAV,OAAA,CAAAzD,OAAA,GAEaN,SAAS","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"container.js","names":["_react","_interopRequireDefault","require","_propTypes","_reactKonva","_styles","_rectangle","_polygon","_circle","BaseContainer","styled","theme","marginTop","spacing","marginBottom","position","background","palette","common","white","border","width","maxWidth","overflowX","HiddenFocusable","height","overflow","clip","whiteSpace","ImageContainer","Image","alignItems","display","justifyContent","StyledStage","Stage","left","top","Container","React","Component","constructor","props","_defineProperty2","default","isCorrect","isChecked","selected","shapes","rectangles","polygons","circles","allShapes","map","s","type","sort","a","b","String","id","localeCompare","undefined","numeric","shapeId","setState","focusedShapeId","e","key","preventDefault","onSelectChoice","disabled","shape","getAllShapesSorted","find","isSelected","selector","state","selectedShape","session","answers","filter","answer","render","dimensions","withProp","heightProp","hotspotColor","hoverOutlineColor","selectedHotspotColor","imageUrl","isEvaluateMode","outlineColor","scale","SCALE","strokeWidth","showCorrect","sortedShapes","createElement","style","padding","alt","src","maxHeight","x","y","Layer","correctness","correct","evaluateText","getEvaluateText","markAsCorrect","onClick","showCorrectEnabled","focused","polygon","points","radius","tabIndex","role","ariaLabel","onFocus","handleShapeFocus","onBlur","handleShapeBlur","onKeyDown","handleShapeKeyDown","exports","propTypes","PropTypes","object","isRequired","bool","string","func","number","defaultProps","_default"],"sources":["../../src/hotspot/container.jsx"],"sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\nimport { Layer, Stage } from 'react-konva';\nimport { styled } from '@mui/material/styles';\n\nimport Rectangle from './rectangle';\nimport Polygon from './polygon';\nimport Circle from './circle';\n\nconst BaseContainer = styled('div')(({ theme }) => ({\n marginTop: theme.spacing(2),\n marginBottom: theme.spacing(2),\n position: 'relative',\n background: theme.palette.common.white,\n border: `${theme.spacing(1)} solid ${theme.palette.common.white}`,\n width: 'fit-content',\n maxWidth: '100%',\n overflowX: 'auto',\n}));\n\nconst HiddenFocusable = styled('span')({\n position: 'absolute',\n width: 1,\n height: 1,\n overflow: 'hidden',\n clip: 'rect(0, 0, 0, 0)',\n whiteSpace: 'nowrap',\n});\n\nconst ImageContainer = styled('div')({\n position: 'relative',\n width: 'fit-content',\n});\n\nconst Image = styled('img')({\n alignItems: 'center',\n display: 'flex',\n justifyContent: 'center',\n});\n\nconst StyledStage = styled(Stage)({\n left: 0,\n top: 0,\n position: 'absolute',\n});\n\nexport class Container extends React.Component {\n constructor(props) {\n super(props);\n this.state = {\n focusedShapeId: null,\n };\n }\n\n isSelected(shape) {\n const selectedShape = this.props.session.answers.filter((answer) => answer.id === shape.id)[0];\n return !!selectedShape;\n }\n\n correctness = (isCorrect, isChecked) => (isCorrect ? isChecked : !isChecked);\n\n getEvaluateText = (isCorrect, selected) => {\n if (selected && isCorrect) {\n return 'Correctly\\nselected';\n }\n\n if (selected && !isCorrect) {\n return 'Should not have\\nbeen selected';\n }\n\n if (!selected && isCorrect) {\n return 'Should have\\nbeen selected';\n }\n\n return null;\n };\n\n getAllShapesSorted = () => {\n const { shapes: { rectangles = [], polygons = [], circles = [] } } = this.props;\n const allShapes = [\n ...rectangles.map((s) => ({ ...s, type: 'rectangle' })),\n ...polygons.map((s) => ({ ...s, type: 'polygon' })),\n ...circles.map((s) => ({ ...s, type: 'circle' })),\n ];\n allShapes.sort((a, b) => String(a.id).localeCompare(String(b.id), undefined, { numeric: true }));\n\n return allShapes;\n };\n\n handleShapeFocus = (shapeId) => {\n this.setState({ focusedShapeId: shapeId });\n };\n\n handleShapeBlur = () => {\n this.setState({ focusedShapeId: null });\n };\n\n handleShapeKeyDown = (e, shapeId) => {\n if (e.key === 'Enter' || e.key === ' ') {\n e.preventDefault();\n\n const { onSelectChoice, disabled } = this.props;\n\n if (!disabled) {\n const shape = this.getAllShapesSorted().find((s) => s.id === shapeId);\n\n if (shape) {\n const selected = this.isSelected(shape);\n\n onSelectChoice({ id: shapeId, selected: !selected, selector: 'Keyboard' });\n }\n }\n }\n };\n\n render() {\n const {\n dimensions: { width: withProp, height: heightProp },\n disabled,\n hotspotColor,\n hoverOutlineColor,\n selectedHotspotColor,\n imageUrl,\n isEvaluateMode,\n outlineColor,\n onSelectChoice,\n shapes: { rectangles = [], polygons = [], circles = [] },\n scale: SCALE,\n strokeWidth,\n showCorrect,\n } = this.props;\n\n const { focusedShapeId } = this.state;\n\n const width = withProp * SCALE;\n const height = heightProp * SCALE;\n\n const sortedShapes = this.getAllShapesSorted();\n\n return (\n <BaseContainer style={{ padding: strokeWidth / 2 }}>\n {imageUrl ? (\n <ImageContainer>\n <Image\n alt=\"hotspot-image\"\n height=\"auto\"\n src={imageUrl}\n style={{ width, height, maxWidth: width, maxHeight: height }}\n />\n </ImageContainer>\n ) : null}\n\n <StyledStage\n height={height + strokeWidth}\n width={width + strokeWidth}\n x={strokeWidth / 2}\n y={strokeWidth / 2}\n >\n <Layer>\n {rectangles.map((shape) => {\n const selected = this.isSelected(shape);\n const isCorrect = isEvaluateMode ? this.correctness(shape.correct, selected) : undefined;\n const evaluateText = isEvaluateMode ? this.getEvaluateText(shape.correct, selected) : null;\n const markAsCorrect = !!(isEvaluateMode && showCorrect && shape.correct);\n\n return (\n <Rectangle\n scale={SCALE}\n isEvaluateMode={isEvaluateMode}\n isCorrect={isCorrect}\n evaluateText={evaluateText}\n disabled={disabled}\n selected={selected}\n height={shape.height}\n hotspotColor={hotspotColor}\n hoverOutlineColor={hoverOutlineColor}\n selectedHotspotColor={selectedHotspotColor}\n id={shape.id}\n key={shape.id}\n onClick={onSelectChoice}\n outlineColor={outlineColor}\n width={shape.width}\n x={shape.x}\n y={shape.y}\n strokeWidth={strokeWidth}\n markAsCorrect={markAsCorrect}\n showCorrectEnabled={showCorrect}\n focused={focusedShapeId === shape.id}\n />\n );\n })}\n {polygons.map((polygon) => {\n const selected = this.isSelected(polygon);\n const isCorrect = isEvaluateMode ? this.correctness(polygon.correct, selected) : undefined;\n const evaluateText = isEvaluateMode ? this.getEvaluateText(polygon.correct, selected) : null;\n const markAsCorrect = !!(isEvaluateMode && showCorrect && polygon.correct);\n\n return (\n <Polygon\n scale={SCALE}\n isEvaluateMode={isEvaluateMode}\n isCorrect={!!isCorrect}\n evaluateText={evaluateText}\n disabled={disabled}\n selected={selected}\n hotspotColor={hotspotColor}\n id={polygon.id}\n key={polygon.id}\n onClick={onSelectChoice}\n outlineColor={outlineColor}\n points={polygon.points}\n strokeWidth={strokeWidth}\n markAsCorrect={markAsCorrect}\n selectedHotspotColor={selectedHotspotColor}\n hoverOutlineColor={hoverOutlineColor}\n showCorrectEnabled={showCorrect}\n focused={focusedShapeId === polygon.id}\n />\n );\n })}\n {circles.map((shape) => {\n const selected = this.isSelected(shape);\n const isCorrect = isEvaluateMode ? this.correctness(shape.correct, selected) : undefined;\n const evaluateText = isEvaluateMode ? this.getEvaluateText(shape.correct, selected) : null;\n const markAsCorrect = !!(isEvaluateMode && showCorrect && shape.correct);\n\n return (\n <Circle\n scale={SCALE}\n isEvaluateMode={isEvaluateMode}\n isCorrect={isCorrect}\n evaluateText={evaluateText}\n disabled={disabled}\n selected={selected}\n radius={shape.radius}\n hotspotColor={hotspotColor}\n id={shape.id}\n key={shape.id}\n onClick={onSelectChoice}\n outlineColor={outlineColor}\n x={shape.x}\n y={shape.y}\n strokeWidth={strokeWidth}\n markAsCorrect={markAsCorrect}\n selectedHotspotColor={selectedHotspotColor}\n hoverOutlineColor={hoverOutlineColor}\n showCorrectEnabled={showCorrect}\n focused={focusedShapeId === shape.id}\n />\n );\n })}\n </Layer>\n </StyledStage>\n\n {sortedShapes.map((shape) => {\n const selected = this.isSelected(shape);\n\n return (\n <HiddenFocusable\n key={`focus-${shape.id}`}\n tabIndex={disabled ? -1 : 0}\n role=\"button\"\n aria-label={shape.ariaLabel || ''}\n aria-pressed={selected}\n onFocus={() => this.handleShapeFocus(shape.id)}\n onBlur={this.handleShapeBlur}\n onKeyDown={(e) => this.handleShapeKeyDown(e, shape.id)}\n />\n );\n })}\n </BaseContainer>\n );\n }\n}\n\nContainer.propTypes = {\n dimensions: PropTypes.object.isRequired,\n disabled: PropTypes.bool.isRequired,\n hotspotColor: PropTypes.string.isRequired,\n hoverOutlineColor: PropTypes.string,\n imageUrl: PropTypes.string.isRequired,\n isEvaluateMode: PropTypes.bool.isRequired,\n onSelectChoice: PropTypes.func.isRequired,\n outlineColor: PropTypes.string.isRequired,\n selectedHotspotColor: PropTypes.string,\n session: PropTypes.object.isRequired,\n shapes: PropTypes.object.isRequired,\n strokeWidth: PropTypes.number,\n scale: PropTypes.number,\n showCorrect: PropTypes.bool,\n};\n\nContainer.defaultProps = {\n scale: 1,\n};\n\nexport default Container;\n"],"mappings":";;;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,UAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,WAAA,GAAAF,OAAA;AACA,IAAAG,OAAA,GAAAH,OAAA;AAEA,IAAAI,UAAA,GAAAL,sBAAA,CAAAC,OAAA;AACA,IAAAK,QAAA,GAAAN,sBAAA,CAAAC,OAAA;AACA,IAAAM,OAAA,GAAAP,sBAAA,CAAAC,OAAA;AAEA,MAAMO,aAAa,GAAG,IAAAC,cAAM,EAAC,KAAK,CAAC,CAAC,CAAC;EAAEC;AAAM,CAAC,MAAM;EAClDC,SAAS,EAAED,KAAK,CAACE,OAAO,CAAC,CAAC,CAAC;EAC3BC,YAAY,EAAEH,KAAK,CAACE,OAAO,CAAC,CAAC,CAAC;EAC9BE,QAAQ,EAAE,UAAU;EACpBC,UAAU,EAAEL,KAAK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M,CAACC,UAAU;EACnCpC,WAAW,EAAEkC,kBAAS,CAACM,MAAM;EAC7B1C,KAAK,EAAEoC,kBAAS,CAACM,MAAM;EACvBvC,WAAW,EAAEiC,kBAAS,CAACG;AACzB,CAAC;AAED9F,SAAS,CAACkG,YAAY,GAAG;EACvB3C,KAAK,EAAE;AACT,CAAC;AAAC,IAAA4C,QAAA,GAAAV,OAAA,CAAAnF,OAAA,GAEaN,SAAS","ignoreList":[]}
|
package/lib/hotspot/index.js
CHANGED
|
@@ -7,9 +7,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
exports.default = void 0;
|
|
8
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
9
|
var _react = _interopRequireDefault(require("react"));
|
|
10
|
+
var _reactDom = _interopRequireDefault(require("react-dom"));
|
|
10
11
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
12
|
var _correctAnswerToggle = _interopRequireDefault(require("@pie-lib/correct-answer-toggle"));
|
|
12
13
|
var _renderUi = require("@pie-lib/render-ui");
|
|
14
|
+
var _mathRendering = require("@pie-lib/math-rendering");
|
|
13
15
|
var _styles = require("@mui/material/styles");
|
|
14
16
|
var _container = _interopRequireDefault(require("./container"));
|
|
15
17
|
const StyledUiLayout = (0, _styles.styled)(_renderUi.UiLayout)({
|
|
@@ -66,6 +68,15 @@ class HotspotComponent extends _react.default.Component {
|
|
|
66
68
|
attributeFilter: ['style']
|
|
67
69
|
});
|
|
68
70
|
}
|
|
71
|
+
|
|
72
|
+
// eslint-disable-next-line react/no-find-dom-node
|
|
73
|
+
const domNode = _reactDom.default.findDOMNode(this);
|
|
74
|
+
(0, _mathRendering.renderMath)(domNode);
|
|
75
|
+
}
|
|
76
|
+
componentDidUpdate() {
|
|
77
|
+
// eslint-disable-next-line react/no-find-dom-node
|
|
78
|
+
const domNode = _reactDom.default.findDOMNode(this);
|
|
79
|
+
(0, _mathRendering.renderMath)(domNode);
|
|
69
80
|
}
|
|
70
81
|
componentWillUnmount() {
|
|
71
82
|
this.observer?.disconnect();
|
package/lib/hotspot/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["_react","_interopRequireDefault","require","_propTypes","_correctAnswerToggle","_renderUi","_styles","_container","StyledUiLayout","styled","UiLayout","color","text","backgroundColor","background","position","StyledCollapsible","Collapsible","theme","marginBottom","spacing","HotspotComponent","React","Component","constructor","props","_defineProperty2","default","showCorrect","state","setState","observer","scale","componentDidMount","MutationObserver","mutations","forEach","target","document","getElementById","style","cssText","zoom","substring","indexOf","lastIndexOf","zoomParsed","replace","newScale","parseFloat","observe","attributes","attributeFilter","componentWillUnmount","disconnect","render","session","model","disabled","extraCSSRules","imageUrl","prompt","mode","multipleCorrect","shapes","outlineColor","hotspotColor","hoverOutlineColor","selectedHotspotColor","dimensions","rationale","teacherInstructions","strokeWidth","responseCorrect","language","fontSizeFactor","autoplayAudioEnabled","customAudioButton","onSelectChoice","isEvaluateMode","isGatherMode","showCorrectAnswerToggle","showRationale","hasText","hasMedia","showTeacherInstructions","createElement","id","labels","hidden","visible","PreviewPrompt","className","show","toggled","onToggle","bind","undefined","propTypes","PropTypes","object","isRequired","func","_default","exports"],"sources":["../../src/hotspot/index.jsx"],"sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\nimport CorrectAnswerToggle from '@pie-lib/correct-answer-toggle';\nimport { color, Collapsible, hasText, PreviewPrompt, UiLayout, hasMedia } from '@pie-lib/render-ui';\nimport { styled } from '@mui/material/styles';\n\nimport Container from './container';\n\nconst StyledUiLayout = styled(UiLayout)({\n color: color.text(),\n backgroundColor: color.background(),\n position: 'relative',\n});\n\nconst StyledCollapsible = styled(Collapsible)(({ theme }) => ({\n marginBottom: theme.spacing(2),\n}));\n\nclass HotspotComponent extends React.Component {\n constructor(props) {\n super(props);\n this.state = {\n showCorrect: false,\n observer: null,\n scale: 1,\n };\n }\n\n componentDidMount() {\n this.observer = new MutationObserver((mutations) => {\n mutations.forEach(() => {\n const target = document.getElementById('question-container')?.style?.cssText;\n const zoom = target?.substring(target.indexOf('--pie-zoom') + 11, target.lastIndexOf('%'));\n const zoomParsed = zoom?.replace(/\\s/g, '');\n\n if (zoomParsed) {\n const newScale = parseFloat(zoomParsed) / 100;\n\n if (newScale !== this.state.scale) {\n this.setState({\n scale: parseFloat(zoomParsed) / 100,\n });\n }\n } else if (!zoomParsed && this.state.scale !== 1) {\n this.setState({\n scale: 1,\n });\n }\n });\n });\n\n const target = document.getElementById('question-container');\n\n if (target) {\n this.observer.observe(target, { attributes: true, attributeFilter: ['style'] });\n }\n }\n\n componentWillUnmount() {\n this.observer?.disconnect();\n }\n\n onToggle = () => {\n const { showCorrect } = this.state;\n this.setState({ showCorrect: !showCorrect });\n };\n\n render() {\n const {\n session,\n model: {\n disabled,\n extraCSSRules,\n imageUrl,\n prompt,\n mode,\n multipleCorrect,\n shapes,\n outlineColor,\n hotspotColor,\n hoverOutlineColor,\n selectedHotspotColor,\n dimensions,\n rationale,\n teacherInstructions,\n strokeWidth,\n responseCorrect,\n language,\n fontSizeFactor,\n autoplayAudioEnabled,\n customAudioButton,\n },\n onSelectChoice,\n } = this.props;\n const { showCorrect } = this.state;\n const isEvaluateMode = mode === 'evaluate';\n const isGatherMode = mode === 'gather';\n const showCorrectAnswerToggle = isEvaluateMode && !responseCorrect;\n const showRationale = rationale && (hasText(rationale) || hasMedia(rationale));\n const showTeacherInstructions =\n teacherInstructions && (hasText(teacherInstructions) || hasMedia(teacherInstructions));\n\n return (\n <StyledUiLayout extraCSSRules={extraCSSRules} id={'main-container'} fontSizeFactor={fontSizeFactor}>\n {showTeacherInstructions && (\n <StyledCollapsible labels={{ hidden: 'Show Teacher Instructions', visible: 'Hide Teacher Instructions' }}>\n <PreviewPrompt className=\"prompt\" prompt={teacherInstructions} />\n </StyledCollapsible>\n )}\n\n {prompt && (\n <PreviewPrompt\n className=\"prompt\"\n prompt={prompt}\n autoplayAudioEnabled={autoplayAudioEnabled}\n customAudioButton={customAudioButton}\n />\n )}\n\n {showCorrectAnswerToggle && (\n <CorrectAnswerToggle\n show={showCorrectAnswerToggle}\n toggled={showCorrect}\n onToggle={this.onToggle.bind(this)}\n language={language}\n />\n )}\n\n {imageUrl ? (\n <Container\n isEvaluateMode={isEvaluateMode}\n session={session}\n dimensions={dimensions}\n imageUrl={imageUrl}\n hotspotColor={hotspotColor}\n hoverOutlineColor={isGatherMode ? hoverOutlineColor : undefined}\n selectedHotspotColor={selectedHotspotColor}\n multipleCorrect={multipleCorrect}\n outlineColor={outlineColor}\n onSelectChoice={onSelectChoice}\n shapes={shapes}\n disabled={disabled}\n strokeWidth={strokeWidth}\n scale={this.state.scale}\n showCorrect={showCorrect}\n />\n ) : null}\n\n {showRationale && (\n <Collapsible labels={{ hidden: 'Show Rationale', visible: 'Hide Rationale' }}>\n <PreviewPrompt className=\"prompt\" prompt={rationale} />\n </Collapsible>\n )}\n </StyledUiLayout>\n );\n }\n}\n\nHotspotComponent.propTypes = {\n model: PropTypes.object.isRequired,\n onSelectChoice: PropTypes.func.isRequired,\n session: PropTypes.object.isRequired,\n};\n\nexport default HotspotComponent;\n"],"mappings":";;;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,UAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,oBAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,SAAA,GAAAH,OAAA;AACA,IAAAI,OAAA,GAAAJ,OAAA;AAEA,IAAAK,UAAA,GAAAN,sBAAA,CAAAC,OAAA;AAEA,MAAMM,cAAc,GAAG,IAAAC,cAAM,EAACC,kBAAQ,CAAC,CAAC;EACtCC,KAAK,EAAEA,eAAK,CAACC,IAAI,CAAC,CAAC;EACnBC,eAAe,EAAEF,eAAK,CAACG,UAAU,CAAC,CAAC;EACnCC,QAAQ,EAAE;AACZ,CAAC,CAAC;AAEF,MAAMC,iBAAiB,GAAG,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AAU,EAAEA,UAAW;MACvBT,QAAQ,EAAEA,QAAS;MACnBM,YAAY,EAAEA,YAAa;MAC3BC,iBAAiB,EAAEa,YAAY,GAAGb,iBAAiB,GAAG8B,SAAU;MAChE7B,oBAAoB,EAAEA,oBAAqB;MAC3CL,eAAe,EAAEA,eAAgB;MACjCE,YAAY,EAAEA,YAAa;MAC3Ba,cAAc,EAAEA,cAAe;MAC/Bd,MAAM,EAAEA,MAAO;MACfN,QAAQ,EAAEA,QAAS;MACnBc,WAAW,EAAEA,WAAY;MACzBxC,KAAK,EAAE,IAAI,CAACH,KAAK,CAACG,KAAM;MACxBJ,WAAW,EAAEA;IAAY,CAC1B,CAAC,GACA,IAAI,EAEPsD,aAAa,iBACZlF,MAAA,CAAA2B,OAAA,CAAA2D,aAAA,CAACjF,SAAA,CAAAY,WAAW;MAACuE,MAAM,EAAE;QAAEC,MAAM,EAAE,gBAAgB;QAAEC,OAAO,EAAE;MAAiB;IAAE,gBAC3E1F,MAAA,CAAA2B,OAAA,CAAA2D,aAAA,CAACjF,SAAA,CAAAsF,aAAa;MAACC,SAAS,EAAC,QAAQ;MAAC/B,MAAM,EAAES;IAAU,CAAE,CAC3C,CAED,CAAC;EAErB;AACF;AAEAjD,gBAAgB,CAAC6E,SAAS,GAAG;EAC3BzC,KAAK,EAAE0C,kBAAS,CAACC,MAAM,CAACC,UAAU;EAClCvB,cAAc,EAAEqB,kBAAS,CAACG,IAAI,CAACD,UAAU;EACzC7C,OAAO,EAAE2C,kBAAS,CAACC,MAAM,CAACC;AAC5B,CAAC;AAAC,IAAAE,QAAA,GAAAC,OAAA,CAAA7E,OAAA,GAEaN,gBAAgB","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"index.js","names":["_react","_interopRequireDefault","require","_reactDom","_propTypes","_correctAnswerToggle","_renderUi","_mathRendering","_styles","_container","StyledUiLayout","styled","UiLayout","color","text","backgroundColor","background","position","StyledCollapsible","Collapsible","theme","marginBottom","spacing","HotspotComponent","React","Component","constructor","props","_defineProperty2","default","showCorrect","state","setState","observer","scale","componentDidMount","MutationObserver","mutations","forEach","target","document","getElementById","style","cssText","zoom","substring","indexOf","lastIndexOf","zoomParsed","replace","newScale","parseFloat","observe","attributes","attributeFilter","domNode","ReactDOM","findDOMNode","renderMath","componentDidUpdate","componentWillUnmount","disconnect","render","session","model","disabled","extraCSSRules","imageUrl","prompt","mode","multipleCorrect","shapes","outlineColor","hotspotColor","hoverOutlineColor","selectedHotspotColor","dimensions","rationale","teacherInstructions","strokeWidth","responseCorrect","language","fontSizeFactor","autoplayAudioEnabled","customAudioButton","onSelectChoice","isEvaluateMode","isGatherMode","showCorrectAnswerToggle","showRationale","hasText","hasMedia","showTeacherInstructions","createElement","id","labels","hidden","visible","PreviewPrompt","className","show","toggled","onToggle","bind","undefined","propTypes","PropTypes","object","isRequired","func","_default","exports"],"sources":["../../src/hotspot/index.jsx"],"sourcesContent":["import React from 'react';\nimport ReactDOM from 'react-dom';\nimport PropTypes from 'prop-types';\nimport CorrectAnswerToggle from '@pie-lib/correct-answer-toggle';\nimport { color, Collapsible, hasText, PreviewPrompt, UiLayout, hasMedia } from '@pie-lib/render-ui';\nimport { renderMath } from '@pie-lib/math-rendering';\nimport { styled } from '@mui/material/styles';\n\nimport Container from './container';\n\nconst StyledUiLayout = styled(UiLayout)({\n color: color.text(),\n backgroundColor: color.background(),\n position: 'relative',\n});\n\nconst StyledCollapsible = styled(Collapsible)(({ theme }) => ({\n marginBottom: theme.spacing(2),\n}));\n\nclass HotspotComponent extends React.Component {\n constructor(props) {\n super(props);\n this.state = {\n showCorrect: false,\n observer: null,\n scale: 1,\n };\n }\n\n componentDidMount() {\n this.observer = new MutationObserver((mutations) => {\n mutations.forEach(() => {\n const target = document.getElementById('question-container')?.style?.cssText;\n const zoom = target?.substring(target.indexOf('--pie-zoom') + 11, target.lastIndexOf('%'));\n const zoomParsed = zoom?.replace(/\\s/g, '');\n\n if (zoomParsed) {\n const newScale = parseFloat(zoomParsed) / 100;\n\n if (newScale !== this.state.scale) {\n this.setState({\n scale: parseFloat(zoomParsed) / 100,\n });\n }\n } else if (!zoomParsed && this.state.scale !== 1) {\n this.setState({\n scale: 1,\n });\n }\n });\n });\n\n const target = document.getElementById('question-container');\n\n if (target) {\n this.observer.observe(target, { attributes: true, attributeFilter: ['style'] });\n }\n\n // eslint-disable-next-line react/no-find-dom-node\n const domNode = ReactDOM.findDOMNode(this);\n\n renderMath(domNode);\n }\n\n componentDidUpdate() {\n // eslint-disable-next-line react/no-find-dom-node\n const domNode = ReactDOM.findDOMNode(this);\n\n renderMath(domNode);\n }\n\n componentWillUnmount() {\n this.observer?.disconnect();\n }\n\n onToggle = () => {\n const { showCorrect } = this.state;\n this.setState({ showCorrect: !showCorrect });\n };\n\n render() {\n const {\n session,\n model: {\n disabled,\n extraCSSRules,\n imageUrl,\n prompt,\n mode,\n multipleCorrect,\n shapes,\n outlineColor,\n hotspotColor,\n hoverOutlineColor,\n selectedHotspotColor,\n dimensions,\n rationale,\n teacherInstructions,\n strokeWidth,\n responseCorrect,\n language,\n fontSizeFactor,\n autoplayAudioEnabled,\n customAudioButton,\n },\n onSelectChoice,\n } = this.props;\n const { showCorrect } = this.state;\n const isEvaluateMode = mode === 'evaluate';\n const isGatherMode = mode === 'gather';\n const showCorrectAnswerToggle = isEvaluateMode && !responseCorrect;\n const showRationale = rationale && (hasText(rationale) || hasMedia(rationale));\n const showTeacherInstructions =\n teacherInstructions && (hasText(teacherInstructions) || hasMedia(teacherInstructions));\n\n return (\n <StyledUiLayout extraCSSRules={extraCSSRules} id={'main-container'} fontSizeFactor={fontSizeFactor}>\n {showTeacherInstructions && (\n <StyledCollapsible labels={{ hidden: 'Show Teacher Instructions', visible: 'Hide Teacher Instructions' }}>\n <PreviewPrompt className=\"prompt\" prompt={teacherInstructions} />\n </StyledCollapsible>\n )}\n\n {prompt && (\n <PreviewPrompt\n className=\"prompt\"\n prompt={prompt}\n autoplayAudioEnabled={autoplayAudioEnabled}\n customAudioButton={customAudioButton}\n />\n )}\n\n {showCorrectAnswerToggle && (\n <CorrectAnswerToggle\n show={showCorrectAnswerToggle}\n toggled={showCorrect}\n onToggle={this.onToggle.bind(this)}\n language={language}\n />\n )}\n\n {imageUrl ? (\n <Container\n isEvaluateMode={isEvaluateMode}\n session={session}\n dimensions={dimensions}\n imageUrl={imageUrl}\n hotspotColor={hotspotColor}\n hoverOutlineColor={isGatherMode ? hoverOutlineColor : undefined}\n selectedHotspotColor={selectedHotspotColor}\n multipleCorrect={multipleCorrect}\n outlineColor={outlineColor}\n onSelectChoice={onSelectChoice}\n shapes={shapes}\n disabled={disabled}\n strokeWidth={strokeWidth}\n scale={this.state.scale}\n showCorrect={showCorrect}\n />\n ) : null}\n\n {showRationale && (\n <Collapsible labels={{ hidden: 'Show Rationale', visible: 'Hide Rationale' }}>\n <PreviewPrompt className=\"prompt\" prompt={rationale} />\n </Collapsible>\n )}\n </StyledUiLayout>\n );\n }\n}\n\nHotspotComponent.propTypes = {\n model: PropTypes.object.isRequired,\n onSelectChoice: PropTypes.func.isRequired,\n session: PropTypes.object.isRequired,\n};\n\nexport default HotspotComponent;\n"],"mappings":";;;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,SAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,UAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,oBAAA,GAAAJ,sBAAA,CAAAC,OAAA;AACA,IAAAI,SAAA,GAAAJ,OAAA;AACA,IAAAK,cAAA,GAAAL,OAAA;AACA,IAAAM,OAAA,GAAAN,OAAA;AAEA,IAAAO,UAAA,GAAAR,sBAAA,CAAAC,OAAA;AAEA,MAAMQ,cAAc,GAAG,IAAAC,cAAM,EAACC,kBAAQ,CAAC,CAAC;EACtCC,KAAK,EAAEA,eAAK,CAACC,IAAI,CAAC,CAAC;EACnBC,eAAe,EAAEF,eAAK,CAACG,UAAU,CAAC,CAAC;EACnCC,QAAQ,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AAE2C,kBAAS,CAACC,MAAM,CAACC;AAC5B,CAAC;AAAC,IAAAE,QAAA,GAAAC,OAAA,CAAAlF,OAAA,GAEaN,gBAAgB","ignoreList":[]}
|
package/lib/hotspot/polygon.js
CHANGED
|
@@ -85,6 +85,7 @@ class PolygonComponent extends _react.default.Component {
|
|
|
85
85
|
hoverOutlineColor,
|
|
86
86
|
outlineColor,
|
|
87
87
|
selected,
|
|
88
|
+
focused,
|
|
88
89
|
points,
|
|
89
90
|
evaluateText,
|
|
90
91
|
strokeWidth,
|
|
@@ -133,7 +134,7 @@ class PolygonComponent extends _react.default.Component {
|
|
|
133
134
|
iconSrc = _icons.faWrong;
|
|
134
135
|
}
|
|
135
136
|
}
|
|
136
|
-
const useHoveredStyle = hovered && hoverOutlineColor;
|
|
137
|
+
const useHoveredStyle = (hovered || focused) && hoverOutlineColor;
|
|
137
138
|
const xValues = pointsParsed.filter((_, index) => index % 2 === 0); // Even indices are x-coordinates
|
|
138
139
|
const yValues = pointsParsed.filter((_, index) => index % 2 !== 0); // Odd indices are y-coordinates
|
|
139
140
|
|
|
@@ -147,15 +148,10 @@ class PolygonComponent extends _react.default.Component {
|
|
|
147
148
|
const rectHeight = maxY - minY;
|
|
148
149
|
return /*#__PURE__*/_react.default.createElement(_reactKonva.Group, {
|
|
149
150
|
scaleX: scale,
|
|
150
|
-
scaleY: scale
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
width: rectWidth,
|
|
155
|
-
height: rectHeight,
|
|
156
|
-
stroke: selected ? 'transparent' : hoverOutlineColor,
|
|
157
|
-
strokeWidth: strokeWidth
|
|
158
|
-
}), /*#__PURE__*/_react.default.createElement(_reactKonva.Line, {
|
|
151
|
+
scaleY: scale,
|
|
152
|
+
onMouseEnter: this.handleMouseEnter,
|
|
153
|
+
onMouseLeave: this.handleMouseLeave
|
|
154
|
+
}, /*#__PURE__*/_react.default.createElement(_reactKonva.Line, {
|
|
159
155
|
points: pointsParsed,
|
|
160
156
|
closed: true,
|
|
161
157
|
fill: selected && selectedHotspotColor ? selectedHotspotColor : hotspotColor,
|
|
@@ -164,10 +160,16 @@ class PolygonComponent extends _react.default.Component {
|
|
|
164
160
|
draggable: false,
|
|
165
161
|
stroke: useHoveredStyle && !selected ? 'transparent' : outlineColorParsed,
|
|
166
162
|
strokeWidth: useHoveredStyle && !selected ? 0 : outlineWidth,
|
|
167
|
-
onMouseLeave: this.handleMouseLeave,
|
|
168
|
-
onMouseEnter: this.handleMouseEnter,
|
|
169
163
|
cursor: "pointer",
|
|
170
164
|
position: "relative"
|
|
165
|
+
}), useHoveredStyle && /*#__PURE__*/_react.default.createElement(_reactKonva.Rect, {
|
|
166
|
+
x: rectX,
|
|
167
|
+
y: rectY,
|
|
168
|
+
width: rectWidth,
|
|
169
|
+
height: rectHeight,
|
|
170
|
+
stroke: hoverOutlineColor,
|
|
171
|
+
strokeWidth: strokeWidth,
|
|
172
|
+
listening: false
|
|
171
173
|
}), isEvaluateMode && iconSrc ? /*#__PURE__*/_react.default.createElement(_imageKonvaTooltip.default, {
|
|
172
174
|
src: iconSrc,
|
|
173
175
|
x: iconX,
|
|
@@ -183,6 +185,7 @@ PolygonComponent.propTypes = {
|
|
|
183
185
|
isEvaluateMode: _propTypes.default.bool.isRequired,
|
|
184
186
|
hoverOutlineColor: _propTypes.default.string,
|
|
185
187
|
disabled: _propTypes.default.bool.isRequired,
|
|
188
|
+
focused: _propTypes.default.bool,
|
|
186
189
|
onClick: _propTypes.default.func.isRequired,
|
|
187
190
|
outlineColor: _propTypes.default.string.isRequired,
|
|
188
191
|
points: _propTypes.default.array.isRequired,
|
|
@@ -196,6 +199,7 @@ PolygonComponent.propTypes = {
|
|
|
196
199
|
};
|
|
197
200
|
PolygonComponent.defaultProps = {
|
|
198
201
|
evaluateText: null,
|
|
202
|
+
focused: false,
|
|
199
203
|
strokeWidth: 5,
|
|
200
204
|
scale: 1
|
|
201
205
|
};
|