@pie-element/hotspot 4.8.1 → 4.8.4-next.1014
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 +162 -0
- package/configure/CHANGELOG.md +146 -0
- package/configure/lib/defaults.js +17 -0
- package/configure/lib/defaults.js.map +1 -1
- package/configure/lib/hotspot-container.js +18 -6
- package/configure/lib/hotspot-container.js.map +1 -1
- package/configure/lib/hotspot-drawable.js +11 -5
- package/configure/lib/hotspot-drawable.js.map +1 -1
- package/configure/lib/hotspot-palette.js +1 -1
- package/configure/lib/hotspot-palette.js.map +1 -1
- package/configure/lib/hotspot-polygon.js +1 -1
- package/configure/lib/hotspot-polygon.js.map +1 -1
- package/configure/lib/hotspot-rectangle.js +1 -1
- package/configure/lib/hotspot-rectangle.js.map +1 -1
- package/configure/lib/index.js +3 -3
- package/configure/lib/index.js.map +1 -1
- package/configure/lib/root.js +96 -13
- package/configure/lib/root.js.map +1 -1
- package/configure/lib/utils.js +18 -4
- package/configure/lib/utils.js.map +1 -1
- package/configure/package.json +3 -3
- package/configure/src/__tests__/__snapshots__/hotspot-container.test.js.snap +1 -0
- package/configure/src/__tests__/__snapshots__/root.test.js.snap +48 -4
- package/configure/src/defaults.js +17 -0
- package/configure/src/hotspot-container.jsx +10 -1
- package/configure/src/hotspot-drawable.jsx +8 -2
- package/configure/src/root.jsx +80 -9
- package/configure/src/utils.js +23 -1
- package/controller/CHANGELOG.md +27 -0
- package/controller/lib/index.js +44 -5
- package/controller/lib/index.js.map +1 -1
- package/controller/lib/utils.js.map +1 -1
- package/controller/package.json +1 -1
- package/controller/src/index.js +26 -0
- package/docs/config-schema.json +196 -0
- package/docs/config-schema.json.md +153 -0
- package/docs/demo/generate.js +1 -0
- package/docs/pie-schema.json +53 -0
- package/docs/pie-schema.json.md +43 -0
- package/lib/hotspot/container.js +33 -4
- package/lib/hotspot/container.js.map +1 -1
- package/lib/hotspot/image.js +35 -8
- package/lib/hotspot/image.js.map +1 -1
- package/lib/hotspot/index.js +61 -17
- package/lib/hotspot/index.js.map +1 -1
- package/lib/hotspot/polygon.js +16 -17
- package/lib/hotspot/polygon.js.map +1 -1
- package/lib/hotspot/rectangle.js +16 -17
- package/lib/hotspot/rectangle.js.map +1 -1
- package/lib/index.js +4 -1
- package/lib/index.js.map +1 -1
- package/lib/session-updater.js.map +1 -1
- package/package.json +4 -4
- package/src/__tests__/image-test.jsx +9 -1
- package/src/__tests__/polygon-test.jsx +2 -1
- package/src/__tests__/rectangle-test.jsx +2 -1
- package/src/hotspot/container.jsx +34 -2
- package/src/hotspot/image.jsx +29 -12
- package/src/hotspot/index.jsx +54 -6
- package/src/hotspot/polygon.jsx +11 -15
- package/src/hotspot/rectangle.jsx +11 -15
- package/src/index.js +5 -0
package/docs/pie-schema.json.md
CHANGED
|
@@ -138,6 +138,10 @@ Indicates if Rationale are enabled
|
|
|
138
138
|
|
|
139
139
|
Indicates if Student Instructions are enabled
|
|
140
140
|
|
|
141
|
+
# `spellCheckEnabled` (boolean, required)
|
|
142
|
+
|
|
143
|
+
Indicates if spellcheck is enabled for the author. Default value is true
|
|
144
|
+
|
|
141
145
|
# `strokeWidth` (number, required)
|
|
142
146
|
|
|
143
147
|
Indicates the width of the outline for a selection
|
|
@@ -146,6 +150,17 @@ Indicates the width of the outline for a selection
|
|
|
146
150
|
|
|
147
151
|
Indicates if Teacher Instructions are enabled
|
|
148
152
|
|
|
153
|
+
# `toolbarEditorPosition` (string, enum)
|
|
154
|
+
|
|
155
|
+
Indicates the editor's toolbar position which can be 'bottom' or 'top'
|
|
156
|
+
|
|
157
|
+
This element must be one of the following enum values:
|
|
158
|
+
|
|
159
|
+
* `bottom`
|
|
160
|
+
* `top`
|
|
161
|
+
|
|
162
|
+
Default: `": 'bottom'"`
|
|
163
|
+
|
|
149
164
|
# `id` (string, required)
|
|
150
165
|
|
|
151
166
|
Identifier to identify the Pie Element in html markup, Must be unique within a pie item config.
|
|
@@ -160,6 +175,34 @@ The html Element tag name
|
|
|
160
175
|
|
|
161
176
|
The schema defines the following additional types:
|
|
162
177
|
|
|
178
|
+
## `ConfigureProp` (object)
|
|
179
|
+
|
|
180
|
+
Properties of the `ConfigureProp` object:
|
|
181
|
+
|
|
182
|
+
### `settings` (boolean)
|
|
183
|
+
|
|
184
|
+
Indicates if the item has to be displayed in the Settings Panel
|
|
185
|
+
|
|
186
|
+
### `label` (string)
|
|
187
|
+
|
|
188
|
+
Indicates the label for the item that has to be displayed in the Settings Panel
|
|
189
|
+
|
|
190
|
+
## `ConfigureMaxImageDimensionsProp` (object)
|
|
191
|
+
|
|
192
|
+
Properties of the `ConfigureMaxImageDimensionsProp` object:
|
|
193
|
+
|
|
194
|
+
### `teacherInstructions` (number)
|
|
195
|
+
|
|
196
|
+
Indicates the max dimension for images in teacher instructions
|
|
197
|
+
|
|
198
|
+
### `prompt` (number)
|
|
199
|
+
|
|
200
|
+
Indicates the max dimension for images in prompt - this is also the default dimension for all other input fields if it's not specified
|
|
201
|
+
|
|
202
|
+
### `rationale` (number)
|
|
203
|
+
|
|
204
|
+
Indicates the max dimension for images in rationale
|
|
205
|
+
|
|
163
206
|
## `Shape` (object)
|
|
164
207
|
|
|
165
208
|
Properties of the `Shape` object:
|
package/lib/hotspot/container.js
CHANGED
|
@@ -37,7 +37,7 @@ var _polygon = _interopRequireDefault(require("./polygon"));
|
|
|
37
37
|
|
|
38
38
|
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; }
|
|
39
39
|
|
|
40
|
-
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try {
|
|
40
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
41
41
|
|
|
42
42
|
var Container = /*#__PURE__*/function (_React$Component) {
|
|
43
43
|
(0, _inherits2["default"])(Container, _React$Component);
|
|
@@ -57,6 +57,21 @@ var Container = /*#__PURE__*/function (_React$Component) {
|
|
|
57
57
|
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "correctness", function (isCorrect, isChecked) {
|
|
58
58
|
return isCorrect ? isChecked : !isChecked;
|
|
59
59
|
});
|
|
60
|
+
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "getEvaluateText", function (isCorrect, selected) {
|
|
61
|
+
if (selected && isCorrect) {
|
|
62
|
+
return 'Correctly\nselected';
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (selected && !isCorrect) {
|
|
66
|
+
return 'Should not have\nbeen selected';
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (!selected && isCorrect) {
|
|
70
|
+
return 'Should have\nbeen selected';
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return null;
|
|
74
|
+
});
|
|
60
75
|
return _this;
|
|
61
76
|
}
|
|
62
77
|
|
|
@@ -76,8 +91,8 @@ var Container = /*#__PURE__*/function (_React$Component) {
|
|
|
76
91
|
var _this$props = this.props,
|
|
77
92
|
classes = _this$props.classes,
|
|
78
93
|
_this$props$dimension = _this$props.dimensions,
|
|
79
|
-
|
|
80
|
-
|
|
94
|
+
withProp = _this$props$dimension.width,
|
|
95
|
+
heightProp = _this$props$dimension.height,
|
|
81
96
|
disabled = _this$props.disabled,
|
|
82
97
|
hotspotColor = _this$props.hotspotColor,
|
|
83
98
|
imageUrl = _this$props.imageUrl,
|
|
@@ -87,7 +102,10 @@ var Container = /*#__PURE__*/function (_React$Component) {
|
|
|
87
102
|
_this$props$shapes = _this$props.shapes,
|
|
88
103
|
rectangles = _this$props$shapes.rectangles,
|
|
89
104
|
polygons = _this$props$shapes.polygons,
|
|
105
|
+
SCALE = _this$props.scale,
|
|
90
106
|
strokeWidth = _this$props.strokeWidth;
|
|
107
|
+
var width = withProp * SCALE;
|
|
108
|
+
var height = heightProp * SCALE;
|
|
91
109
|
return /*#__PURE__*/_react["default"].createElement("div", {
|
|
92
110
|
className: classes.base,
|
|
93
111
|
style: {
|
|
@@ -96,6 +114,7 @@ var Container = /*#__PURE__*/function (_React$Component) {
|
|
|
96
114
|
}, imageUrl ? /*#__PURE__*/_react["default"].createElement("div", {
|
|
97
115
|
className: classes.imageContainer
|
|
98
116
|
}, /*#__PURE__*/_react["default"].createElement("img", {
|
|
117
|
+
alt: "hotspot-image",
|
|
99
118
|
className: classes.image,
|
|
100
119
|
height: "auto",
|
|
101
120
|
src: imageUrl,
|
|
@@ -115,9 +134,12 @@ var Container = /*#__PURE__*/function (_React$Component) {
|
|
|
115
134
|
var selected = _this2.isSelected(shape);
|
|
116
135
|
|
|
117
136
|
var isCorrect = isEvaluateMode ? _this2.correctness(shape.correct, selected) : undefined;
|
|
137
|
+
var evaluateText = isEvaluateMode ? _this2.getEvaluateText(shape.correct, selected) : null;
|
|
118
138
|
return /*#__PURE__*/_react["default"].createElement(_rectangle["default"], {
|
|
139
|
+
scale: SCALE,
|
|
119
140
|
isEvaluateMode: isEvaluateMode,
|
|
120
141
|
isCorrect: isCorrect,
|
|
142
|
+
evaluateText: evaluateText,
|
|
121
143
|
disabled: disabled,
|
|
122
144
|
selected: selected,
|
|
123
145
|
height: shape.height,
|
|
@@ -135,9 +157,12 @@ var Container = /*#__PURE__*/function (_React$Component) {
|
|
|
135
157
|
var selected = _this2.isSelected(polygon);
|
|
136
158
|
|
|
137
159
|
var isCorrect = isEvaluateMode ? _this2.correctness(polygon.correct, selected) : undefined;
|
|
160
|
+
var evaluateText = isEvaluateMode ? _this2.getEvaluateText(polygon.correct, selected) : null;
|
|
138
161
|
return /*#__PURE__*/_react["default"].createElement(_polygon["default"], {
|
|
162
|
+
scale: SCALE,
|
|
139
163
|
isEvaluateMode: isEvaluateMode,
|
|
140
164
|
isCorrect: !!isCorrect,
|
|
165
|
+
evaluateText: evaluateText,
|
|
141
166
|
disabled: disabled,
|
|
142
167
|
selected: selected,
|
|
143
168
|
hotspotColor: hotspotColor,
|
|
@@ -200,7 +225,11 @@ Container.propTypes = {
|
|
|
200
225
|
outlineColor: _propTypes["default"].string.isRequired,
|
|
201
226
|
session: _propTypes["default"].object.isRequired,
|
|
202
227
|
shapes: _propTypes["default"].object.isRequired,
|
|
203
|
-
strokeWidth: _propTypes["default"].number
|
|
228
|
+
strokeWidth: _propTypes["default"].number,
|
|
229
|
+
scale: _propTypes["default"].number
|
|
230
|
+
};
|
|
231
|
+
Container.defaultProps = {
|
|
232
|
+
scale: 1
|
|
204
233
|
};
|
|
205
234
|
|
|
206
235
|
var _default = (0, _styles.withStyles)(styles)(Container);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/hotspot/container.jsx"],"names":["Container","isCorrect","isChecked","shape","selectedShape","props","session","answers","filter","answer","id","classes","dimensions","width","height","disabled","hotspotColor","imageUrl","isEvaluateMode","outlineColor","onSelectChoice","shapes","rectangles","polygons","strokeWidth","base","padding","imageContainer","image","maxWidth","maxHeight","stage","map","selected","isSelected","correctness","correct","undefined","x","y","polygon","points","React","Component","styles","theme","marginTop","spacing","unit","position","alignItems","display","justifyContent","left","top","resize","borderBottom","color","borderRight","bottom","cursor","right","propTypes","PropTypes","object","isRequired","bool","string","func","number"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AAEA;;AACA;;;;;;IAEaA,S;;;;;;;;;;;;;;;oGAMG,UAACC,SAAD,EAAYC,SAAZ;AAAA,aAA0BD,SAAS,GAAGC,SAAH,GAAe,CAACA,SAAnD;A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Y,sBAAeC,gBAAM1C,QAAN,EAAf,CADN;AAEN2C,MAAAA,WAAW,sBAAeD,gBAAM1C,QAAN,EAAf,CAFL;AAGN4C,MAAAA,MAAM,EAAE,OAHF;AAINC,MAAAA,MAAM,EAAE,WAJF;AAKN9C,MAAAA,MAAM,EAAE,MALF;AAMNmC,MAAAA,QAAQ,EAAE,UANJ;AAONY,MAAAA,KAAK,EAAE,OAPD;AAQNhD,MAAAA,KAAK,EAAE;AARD;AAnBe,GAAL;AAAA,CAApB;;AA+BAb,SAAS,CAAC8D,SAAV,GAAsB;AACpBnD,EAAAA,OAAO,EAAEoD,sBAAUC,MAAV,CAAiBC,UADN;AAEpBrD,EAAAA,UAAU,EAAEmD,sBAAUC,MAAV,CAAiBC,UAFT;AAGpBlD,EAAAA,QAAQ,EAAEgD,sBAAUG,IAAV,CAAeD,UAHL;AAIpBjD,EAAAA,YAAY,EAAC+C,sBAAUI,MAAV,CAAiBF,UAJV;AAKpBhD,EAAAA,QAAQ,EAAC8C,sBAAUI,MAAV,CAAiBF,UALN;AAMpB/C,EAAAA,cAAc,EAAC6C,sBAAUG,IAAV,CAAeD,UANV;AAOpB7C,EAAAA,cAAc,EAAC2C,sBAAUK,IAAV,CAAeH,UAPV;AAQpB9C,EAAAA,YAAY,EAAC4C,sBAAUI,MAAV,CAAiBF,UARV;AASpB3D,EAAAA,OAAO,EAACyD,sBAAUC,MAAV,CAAiBC,UATL;AAUpB5C,EAAAA,MAAM,EAAC0C,sBAAUC,MAAV,CAAiBC,UAVJ;AAWpBzC,EAAAA,WAAW,EAAEuC,sBAAUM;AAXH,CAAtB;;eAce,wBAAWzB,MAAX,EAAmB5C,SAAnB,C","sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\nimport { Layer, Stage } from 'react-konva';\nimport { withStyles } from '@material-ui/core/styles';\nimport { color } from '@pie-lib/render-ui';\n\nimport Rectangle from './rectangle';\nimport Polygon from './polygon';\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 render() {\n const {\n classes,\n dimensions: { width, height },\n disabled,\n hotspotColor,\n imageUrl,\n isEvaluateMode,\n outlineColor,\n onSelectChoice,\n shapes: { rectangles, polygons },\n strokeWidth\n } = this.props;\n\n return (\n <div\n className={classes.base}\n style={{ padding: strokeWidth / 2 }}\n >\n {imageUrl ? (\n <div className={classes.imageContainer}>\n <img\n className={classes.image}\n height=\"auto\"\n src={imageUrl}\n style={{ width, height, maxWidth: width, maxHeight: height }}\n />\n </div>\n ) : null}\n\n <Stage\n className={classes.stage}\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\n return (\n <Rectangle\n isEvaluateMode={isEvaluateMode}\n isCorrect={isCorrect}\n disabled={disabled}\n selected={selected}\n height={shape.height}\n hotspotColor={hotspotColor}\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 />\n )\n })}\n {polygons.map((polygon) => {\n const selected = this.isSelected(polygon);\n const isCorrect = isEvaluateMode ? this.correctness(polygon.correct, selected) : undefined;\n\n return (\n <Polygon\n isEvaluateMode={isEvaluateMode}\n isCorrect={!!isCorrect}\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 />\n )\n })}\n </Layer>\n </Stage>\n </div>\n );\n }\n}\n\nconst styles = theme => ({\n base: {\n marginTop: theme.spacing.unit * 3,\n position: 'relative'\n },\n image: {\n alignItems: 'center',\n display: 'flex',\n justifyContent: 'center',\n },\n imageContainer: {\n position: 'relative',\n width: 'fit-content'\n },\n stage: {\n left: 0,\n top: 0,\n position: 'absolute'\n },\n resize: {\n borderBottom: `1px solid ${color.disabled()}`,\n borderRight: `1px solid ${color.disabled()}`,\n bottom: '-10px',\n cursor: 'se-resize',\n height: '10px',\n position: 'absolute',\n right: '-10px',\n width: '10px',\n }\n});\n\nContainer.propTypes = {\n classes: PropTypes.object.isRequired,\n dimensions: PropTypes.object.isRequired,\n disabled: PropTypes.bool.isRequired,\n hotspotColor:PropTypes.string.isRequired,\n imageUrl:PropTypes.string.isRequired,\n isEvaluateMode:PropTypes.bool.isRequired,\n onSelectChoice:PropTypes.func.isRequired,\n outlineColor:PropTypes.string.isRequired,\n session:PropTypes.object.isRequired,\n shapes:PropTypes.object.isRequired,\n strokeWidth: PropTypes.number\n};\n\nexport default withStyles(styles)(Container);\n"],"file":"container.js"}
|
|
1
|
+
{"version":3,"sources":["../../src/hotspot/container.jsx"],"names":["Container","isCorrect","isChecked","selected","shape","selectedShape","props","session","answers","filter","answer","id","classes","dimensions","withProp","width","heightProp","height","disabled","hotspotColor","imageUrl","isEvaluateMode","outlineColor","onSelectChoice","shapes","rectangles","polygons","SCALE","scale","strokeWidth","base","padding","imageContainer","image","maxWidth","maxHeight","stage","map","isSelected","correctness","correct","undefined","evaluateText","getEvaluateText","x","y","polygon","points","React","Component","styles","theme","marginTop","spacing","unit","position","alignItems","display","justifyContent","left","top","resize","borderBottom","color","borderRight","bottom","cursor","right","propTypes","PropTypes","object","isRequired","bool","string","func","number","defaultProps"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AAEA;;AACA;;;;;;IAEaA,S;;;;;;;;;;;;;;;oGAMG,UAACC,SAAD,EAAYC,SAAZ;AAAA,aAA0BD,SAAS,GAAGC,SAAH,GAAe,CAACA,SAAnD;AAAA,K;wGAEI,UAACD,SAAD,EAAYE,QAAZ,EAAyB;AACz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;AAGpBrD,EAAAA,QAAQ,EAAEmD,sBAAUG,IAAV,CAAeD,UAHL;AAIpBpD,EAAAA,YAAY,EAACkD,sBAAUI,MAAV,CAAiBF,UAJV;AAKpBnD,EAAAA,QAAQ,EAACiD,sBAAUI,MAAV,CAAiBF,UALN;AAMpBlD,EAAAA,cAAc,EAACgD,sBAAUG,IAAV,CAAeD,UANV;AAOpBhD,EAAAA,cAAc,EAAC8C,sBAAUK,IAAV,CAAeH,UAPV;AAQpBjD,EAAAA,YAAY,EAAC+C,sBAAUI,MAAV,CAAiBF,UARV;AASpBhE,EAAAA,OAAO,EAAC8D,sBAAUC,MAAV,CAAiBC,UATL;AAUpB/C,EAAAA,MAAM,EAAC6C,sBAAUC,MAAV,CAAiBC,UAVJ;AAWpB1C,EAAAA,WAAW,EAAEwC,sBAAUM,MAXH;AAYpB/C,EAAAA,KAAK,EAAEyC,sBAAUM;AAZG,CAAtB;AAeA3E,SAAS,CAAC4E,YAAV,GAAyB;AACvBhD,EAAAA,KAAK,EAAE;AADgB,CAAzB;;eAIe,wBAAWsB,MAAX,EAAmBlD,SAAnB,C","sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\nimport { Layer, Stage } from 'react-konva';\nimport { withStyles } from '@material-ui/core/styles';\nimport { color } from '@pie-lib/render-ui';\n\nimport Rectangle from './rectangle';\nimport Polygon from './polygon';\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 classes,\n dimensions: { width: withProp, height: heightProp },\n disabled,\n hotspotColor,\n imageUrl,\n isEvaluateMode,\n outlineColor,\n onSelectChoice,\n shapes: { rectangles, polygons },\n scale: SCALE,\n strokeWidth\n } = this.props;\n\n const width = withProp * SCALE;\n const height = heightProp * SCALE;\n\n return (\n <div\n className={classes.base}\n style={{ padding: strokeWidth / 2 }}\n >\n {imageUrl ? (\n <div className={classes.imageContainer}>\n <img\n alt=\"hotspot-image\"\n className={classes.image}\n height=\"auto\"\n src={imageUrl}\n style={{ width, height, maxWidth: width, maxHeight: height }}\n />\n </div>\n ) : null}\n\n <Stage\n className={classes.stage}\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\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 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 />\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\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 />\n )\n })}\n </Layer>\n </Stage>\n </div>\n );\n }\n}\n\nconst styles = theme => ({\n base: {\n marginTop: theme.spacing.unit * 3,\n position: 'relative'\n },\n image: {\n alignItems: 'center',\n display: 'flex',\n justifyContent: 'center',\n },\n imageContainer: {\n position: 'relative',\n width: 'fit-content'\n },\n stage: {\n left: 0,\n top: 0,\n position: 'absolute'\n },\n resize: {\n borderBottom: `1px solid ${color.disabled()}`,\n borderRight: `1px solid ${color.disabled()}`,\n bottom: '-10px',\n cursor: 'se-resize',\n height: '10px',\n position: 'absolute',\n right: '-10px',\n width: '10px',\n }\n});\n\nContainer.propTypes = {\n classes: PropTypes.object.isRequired,\n dimensions: PropTypes.object.isRequired,\n disabled: PropTypes.bool.isRequired,\n hotspotColor:PropTypes.string.isRequired,\n imageUrl:PropTypes.string.isRequired,\n isEvaluateMode:PropTypes.bool.isRequired,\n onSelectChoice:PropTypes.func.isRequired,\n outlineColor:PropTypes.string.isRequired,\n session:PropTypes.object.isRequired,\n shapes:PropTypes.object.isRequired,\n strokeWidth: PropTypes.number,\n scale: PropTypes.number\n};\n\nContainer.defaultProps = {\n scale: 1\n};\n\nexport default withStyles(styles)(Container);\n"],"file":"container.js"}
|
package/lib/hotspot/image.js
CHANGED
|
@@ -29,7 +29,7 @@ var _reactKonva = require("react-konva");
|
|
|
29
29
|
|
|
30
30
|
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; }
|
|
31
31
|
|
|
32
|
-
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try {
|
|
32
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
33
33
|
|
|
34
34
|
var ImageComponent = /*#__PURE__*/function (_React$Component) {
|
|
35
35
|
(0, _inherits2["default"])(ImageComponent, _React$Component);
|
|
@@ -47,7 +47,8 @@ var ImageComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
47
47
|
});
|
|
48
48
|
});
|
|
49
49
|
_this.state = {
|
|
50
|
-
image: null
|
|
50
|
+
image: null,
|
|
51
|
+
showTooltip: false
|
|
51
52
|
};
|
|
52
53
|
return _this;
|
|
53
54
|
}
|
|
@@ -80,17 +81,42 @@ var ImageComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
80
81
|
}, {
|
|
81
82
|
key: "render",
|
|
82
83
|
value: function render() {
|
|
84
|
+
var _this2 = this;
|
|
85
|
+
|
|
83
86
|
var _this$props = this.props,
|
|
84
87
|
x = _this$props.x,
|
|
85
|
-
y = _this$props.y
|
|
86
|
-
|
|
87
|
-
|
|
88
|
+
y = _this$props.y,
|
|
89
|
+
tooltip = _this$props.tooltip;
|
|
90
|
+
var _this$state = this.state,
|
|
91
|
+
image = _this$state.image,
|
|
92
|
+
showTooltip = _this$state.showTooltip;
|
|
93
|
+
return /*#__PURE__*/_react["default"].createElement(_reactKonva.Group, null, /*#__PURE__*/_react["default"].createElement(_reactKonva.Image, {
|
|
88
94
|
width: 20,
|
|
89
95
|
height: 20,
|
|
90
96
|
x: x,
|
|
91
97
|
y: y,
|
|
92
|
-
image: image
|
|
93
|
-
|
|
98
|
+
image: image,
|
|
99
|
+
onMouseEnter: function onMouseEnter() {
|
|
100
|
+
return _this2.setState({
|
|
101
|
+
showTooltip: true
|
|
102
|
+
});
|
|
103
|
+
},
|
|
104
|
+
onMouseLeave: function onMouseLeave() {
|
|
105
|
+
return _this2.setState({
|
|
106
|
+
showTooltip: false
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
}), showTooltip && tooltip && /*#__PURE__*/_react["default"].createElement(_reactKonva.Label, {
|
|
110
|
+
x: x - 30,
|
|
111
|
+
y: y + 25
|
|
112
|
+
}, /*#__PURE__*/_react["default"].createElement(_reactKonva.Tag, {
|
|
113
|
+
fill: "white",
|
|
114
|
+
cornerRadius: 5,
|
|
115
|
+
opacity: 0.9
|
|
116
|
+
}), /*#__PURE__*/_react["default"].createElement(_reactKonva.Text, {
|
|
117
|
+
text: tooltip,
|
|
118
|
+
padding: 5
|
|
119
|
+
})));
|
|
94
120
|
}
|
|
95
121
|
}]);
|
|
96
122
|
return ImageComponent;
|
|
@@ -99,7 +125,8 @@ var ImageComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
99
125
|
ImageComponent.propTypes = {
|
|
100
126
|
src: _propTypes["default"].string.isRequired,
|
|
101
127
|
x: _propTypes["default"].number.isRequired,
|
|
102
|
-
y: _propTypes["default"].number.isRequired
|
|
128
|
+
y: _propTypes["default"].number.isRequired,
|
|
129
|
+
tooltip: _propTypes["default"].string
|
|
103
130
|
};
|
|
104
131
|
var _default = ImageComponent;
|
|
105
132
|
exports["default"] = _default;
|
package/lib/hotspot/image.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/hotspot/image.jsx"],"names":["ImageComponent","props","setState","image","state","loadImage","oldProps","src","removeEventListener","handleLoad","window","Image","addEventListener","x","y","React","Component","propTypes","PropTypes","string","isRequired","number"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;;;;;IAEMA,c;;;;;AACJ,0BAAYC,KAAZ,EAAmB;AAAA;;AAAA;AACjB,8BAAMA,KAAN;AADiB,
|
|
1
|
+
{"version":3,"sources":["../../src/hotspot/image.jsx"],"names":["ImageComponent","props","setState","image","state","showTooltip","loadImage","oldProps","src","removeEventListener","handleLoad","window","Image","addEventListener","x","y","tooltip","React","Component","propTypes","PropTypes","string","isRequired","number"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;;;;;I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,KALT;AAME,QAAA,YAAY,EAAE;AAAA,iBAAM,MAAI,CAACD,QAAL,CAAc;AAAEG,YAAAA,WAAW,EAAE;AAAf,WAAd,CAAN;AAAA,SANhB;AAOE,QAAA,YAAY,EAAE;AAAA,iBAAM,MAAI,CAACH,QAAL,CAAc;AAAEG,YAAAA,WAAW,EAAE;AAAf,WAAd,CAAN;AAAA;AAPhB,QADF,EAWGA,WAAW,IAAIW,OAAf,iBACC,gCAAC,iBAAD;AAAO,QAAA,CAAC,EAAEF,CAAC,GAAG,EAAd;AAAkB,QAAA,CAAC,EAAEC,CAAC,GAAG;AAAzB,sBACE,gCAAC,eAAD;AACE,QAAA,IAAI,EAAC,OADP;AAEE,QAAA,YAAY,EAAE,CAFhB;AAGE,QAAA,OAAO,EAAE;AAHX,QADF,eAME,gCAAC,gBAAD;AAAM,QAAA,IAAI,EAAEC,OAAZ;AAAqB,QAAA,OAAO,EAAE;AAA9B,QANF,CAZJ,CADF;AAwBD;;;EAjE0BC,kBAAMC,S;;AAoEnClB,cAAc,CAACmB,SAAf,GAA2B;AACzBX,EAAAA,GAAG,EAAEY,sBAAUC,MAAV,CAAiBC,UADG;AAEzBR,EAAAA,CAAC,EAAEM,sBAAUG,MAAV,CAAiBD,UAFK;AAGzBP,EAAAA,CAAC,EAAEK,sBAAUG,MAAV,CAAiBD,UAHK;AAIzBN,EAAAA,OAAO,EAAEI,sBAAUC;AAJM,CAA3B;eAOerB,c","sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\nimport { Group, Image, Text, Tag, Label } from 'react-konva';\n\nclass ImageComponent extends React.Component {\n constructor(props) {\n super(props);\n this.state = {\n image: null,\n showTooltip: false\n };\n }\n\n componentDidMount() {\n this.loadImage();\n }\n\n componentDidUpdate(oldProps) {\n if (oldProps.src !== this.props.src) {\n this.loadImage();\n }\n }\n\n componentWillUnmount() {\n this.image.removeEventListener('load', this.handleLoad);\n }\n\n loadImage() {\n const { src } = this.props;\n\n this.image = new window.Image();\n this.image.src = src;\n this.image.addEventListener('load', this.handleLoad);\n }\n\n handleLoad = () => {\n this.setState({\n image: this.image\n });\n };\n\n render() {\n const { x, y, tooltip } = this.props;\n const { image, showTooltip } = this.state;\n\n return (\n <Group>\n <Image\n width={20}\n height={20}\n x={x}\n y={y}\n image={image}\n onMouseEnter={() => this.setState({ showTooltip: true })}\n onMouseLeave={() => this.setState({ showTooltip: false })}\n />\n\n {showTooltip && tooltip && (\n <Label x={x - 30} y={y + 25}>\n <Tag\n fill=\"white\"\n cornerRadius={5}\n opacity={0.9}\n />\n <Text text={tooltip} padding={5} />\n </Label>\n )}\n </Group>\n );\n }\n}\n\nImageComponent.propTypes = {\n src: PropTypes.string.isRequired,\n x: PropTypes.number.isRequired,\n y: PropTypes.number.isRequired,\n tooltip: PropTypes.string\n};\n\nexport default ImageComponent;\n"],"file":"image.js"}
|
package/lib/hotspot/index.js
CHANGED
|
@@ -29,13 +29,13 @@ var _Typography = _interopRequireDefault(require("@material-ui/core/Typography")
|
|
|
29
29
|
|
|
30
30
|
var _renderUi = require("@pie-lib/render-ui");
|
|
31
31
|
|
|
32
|
-
var _container = _interopRequireDefault(require("./container"));
|
|
33
|
-
|
|
34
32
|
var _styles = require("@material-ui/core/styles");
|
|
35
33
|
|
|
34
|
+
var _container = _interopRequireDefault(require("./container"));
|
|
35
|
+
|
|
36
36
|
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; }
|
|
37
37
|
|
|
38
|
-
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try {
|
|
38
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
39
39
|
|
|
40
40
|
var HotspotComponent = /*#__PURE__*/function (_React$Component) {
|
|
41
41
|
(0, _inherits2["default"])(HotspotComponent, _React$Component);
|
|
@@ -55,12 +55,58 @@ var HotspotComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
55
55
|
});
|
|
56
56
|
});
|
|
57
57
|
_this.state = {
|
|
58
|
-
showCorrect: false
|
|
58
|
+
showCorrect: false,
|
|
59
|
+
observer: null,
|
|
60
|
+
scale: 1
|
|
59
61
|
};
|
|
60
62
|
return _this;
|
|
61
63
|
}
|
|
62
64
|
|
|
63
65
|
(0, _createClass2["default"])(HotspotComponent, [{
|
|
66
|
+
key: "componentDidMount",
|
|
67
|
+
value: function componentDidMount() {
|
|
68
|
+
var _this2 = this;
|
|
69
|
+
|
|
70
|
+
this.observer = new MutationObserver(function (mutations) {
|
|
71
|
+
mutations.forEach(function () {
|
|
72
|
+
var _document$getElementB, _document$getElementB2;
|
|
73
|
+
|
|
74
|
+
var target = (_document$getElementB = document.getElementById('question-container')) === null || _document$getElementB === void 0 ? void 0 : (_document$getElementB2 = _document$getElementB.style) === null || _document$getElementB2 === void 0 ? void 0 : _document$getElementB2.cssText;
|
|
75
|
+
var zoom = target === null || target === void 0 ? void 0 : target.substring(target.indexOf('--pie-zoom') + 11, target.lastIndexOf('%'));
|
|
76
|
+
var zoomParsed = zoom === null || zoom === void 0 ? void 0 : zoom.replace(/\s/g, '');
|
|
77
|
+
|
|
78
|
+
if (zoomParsed) {
|
|
79
|
+
var newScale = parseFloat(zoomParsed) / 100;
|
|
80
|
+
|
|
81
|
+
if (newScale !== _this2.state.scale) {
|
|
82
|
+
_this2.setState({
|
|
83
|
+
scale: parseFloat(zoomParsed) / 100
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
} else if (!zoomParsed && _this2.state.scale !== 1) {
|
|
87
|
+
_this2.setState({
|
|
88
|
+
scale: 1
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
var target = document.getElementById('question-container');
|
|
94
|
+
|
|
95
|
+
if (target) {
|
|
96
|
+
this.observer.observe(target, {
|
|
97
|
+
attributes: true,
|
|
98
|
+
attributeFilter: ['style']
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}, {
|
|
103
|
+
key: "componentWillUnmount",
|
|
104
|
+
value: function componentWillUnmount() {
|
|
105
|
+
var _this$observer;
|
|
106
|
+
|
|
107
|
+
(_this$observer = this.observer) === null || _this$observer === void 0 ? void 0 : _this$observer.disconnect();
|
|
108
|
+
}
|
|
109
|
+
}, {
|
|
64
110
|
key: "render",
|
|
65
111
|
value: function render() {
|
|
66
112
|
var _this$props = this.props,
|
|
@@ -87,16 +133,14 @@ var HotspotComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
87
133
|
visible: 'Hide Teacher Instructions'
|
|
88
134
|
},
|
|
89
135
|
className: classes.collapsible
|
|
90
|
-
}, /*#__PURE__*/_react["default"].createElement(
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
}
|
|
136
|
+
}, /*#__PURE__*/_react["default"].createElement(_renderUi.PreviewPrompt, {
|
|
137
|
+
className: "prompt",
|
|
138
|
+
prompt: teacherInstructions
|
|
94
139
|
})), /*#__PURE__*/_react["default"].createElement(_Typography["default"], {
|
|
95
140
|
className: classes.prompt
|
|
96
|
-
}, /*#__PURE__*/_react["default"].createElement(
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
}
|
|
141
|
+
}, /*#__PURE__*/_react["default"].createElement(_renderUi.PreviewPrompt, {
|
|
142
|
+
className: "prompt",
|
|
143
|
+
prompt: prompt
|
|
100
144
|
})), imageUrl ? /*#__PURE__*/_react["default"].createElement(_container["default"], {
|
|
101
145
|
isEvaluateMode: isEvaluateMode,
|
|
102
146
|
session: session,
|
|
@@ -108,17 +152,17 @@ var HotspotComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
108
152
|
onSelectChoice: onSelectChoice,
|
|
109
153
|
shapes: shapes,
|
|
110
154
|
disabled: disabled,
|
|
111
|
-
strokeWidth: strokeWidth
|
|
155
|
+
strokeWidth: strokeWidth,
|
|
156
|
+
scale: this.state.scale
|
|
112
157
|
}) : null, rationale && (0, _renderUi.hasText)(rationale) && /*#__PURE__*/_react["default"].createElement(_renderUi.Collapsible, {
|
|
113
158
|
labels: {
|
|
114
159
|
hidden: 'Show Rationale',
|
|
115
160
|
visible: 'Hide Rationale'
|
|
116
161
|
},
|
|
117
162
|
className: classes.collapsible
|
|
118
|
-
}, /*#__PURE__*/_react["default"].createElement(
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
}
|
|
163
|
+
}, /*#__PURE__*/_react["default"].createElement(_renderUi.PreviewPrompt, {
|
|
164
|
+
className: "prompt",
|
|
165
|
+
prompt: rationale
|
|
122
166
|
})));
|
|
123
167
|
}
|
|
124
168
|
}]);
|
package/lib/hotspot/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/hotspot/index.jsx"],"names":["HotspotComponent","props","showCorrect","state","setState","session","model","disabled","imageUrl","prompt","mode","multipleCorrect","shapes","outlineColor","hotspotColor","dimensions","rationale","teacherInstructions","strokeWidth","onSelectChoice","classes","isEvaluateMode","hidden","visible","collapsible","
|
|
1
|
+
{"version":3,"sources":["../../src/hotspot/index.jsx"],"names":["HotspotComponent","props","showCorrect","state","setState","observer","scale","MutationObserver","mutations","forEach","target","document","getElementById","style","cssText","zoom","substring","indexOf","lastIndexOf","zoomParsed","replace","newScale","parseFloat","observe","attributes","attributeFilter","disconnect","session","model","disabled","imageUrl","prompt","mode","multipleCorrect","shapes","outlineColor","hotspotColor","dimensions","rationale","teacherInstructions","strokeWidth","onSelectChoice","classes","isEvaluateMode","hidden","visible","collapsible","React","Component","propTypes","PropTypes","object","isRequired","func","defaultProps","styles","theme","paddingTop","spacing","unit","paddingBottom","fontSize"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AAEA;;;;;;IAEMA,gB;;;;;AACJ,4BAAYC,KAAZ,EAAmB;AAAA;;AAAA;AACjB,8BAAMA,KAAN;AADiB,iGA4CR,YAAM;AACf,UAAQC,WAAR,GAAwB,MAAKC,KAA7B,CAAQD,WAAR;;AACA,YAAKE,QAAL,CAAc;AAAEF,QAAAA,WAAW,EAAE,CAACA;AAAhB,OAAd;AACD,KA/CkB;AAEjB,UAAKC,KAAL,GAAa;AACXD,MAAAA,WAAW,EAAE,KADF;AAEXG,MAAAA,QAAQ,EAAE,IAFC;AAGXC,MAAAA,KAAK,EAAE;AAHI,KAAb;AAFiB;AAOlB;;;;WAED,6BAAoB;AAAA;;AAClB,WAAKD,QAAL,GAAgB,IAAIE,gBAAJ,CAAqB,UAACC,SAAD,EAAe;AAClDA,QAAAA,SAAS,CAACC,OAAV,CAAkB,YAAM;AAAA;;AACtB,cAAMC,MAAM,4BAAGC,QAAQ,CAACC,cAAT,CAAwB,oBAAxB,CAAH,oFAAG,sBAA+CC,KAAlD,2DAAG,uBAAsDC,OAArE;AACA,cAAMC,IAAI,GAAGL,MAAH,aAAGA,MAAH,uBAAGA,MAAM,CAAEM,SAAR,CACXN,MAAM,CAACO,OAAP,CAAe,YAAf,IAA+B,EADpB,EAEXP,MAAM,CAACQ,WAAP,CAAmB,GAAnB,CAFW,CAAb;AAKA,cAAMC,UAAU,GAAGJ,IAAH,aAAGA,IAAH,uBAAGA,IAAI,CAAEK,OAAN,CAAc,KAAd,EAAqB,EAArB,CAAnB;;AACA,cAAID,UAAJ,EAAgB;AACd,gBAAME,QAAQ,GAAGC,UAAU,CAACH,UAAD,CAAV,GAAyB,GAA1C;;AACA,gBAAIE,QAAQ,KAAK,MAAI,CAAClB,KAAL,CAAWG,KAA5B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MAAM,EAAER;AAFV,QAJF,CAzCN,CADF;AAwDD;;;EAjI4BS,kBAAMC,S;;AAoIrChD,gBAAgB,CAACiD,SAAjB,GAA6B;AAC3BP,EAAAA,OAAO,EAAEQ,sBAAUC,MADQ;AAE3BvB,EAAAA,KAAK,EAAEsB,sBAAUC,MAAV,CAAiBC,UAFG;AAG3BX,EAAAA,cAAc,EAAES,sBAAUG,IAAV,CAAeD,UAHJ;AAI3BzB,EAAAA,OAAO,EAAEuB,sBAAUC,MAAV,CAAiBC;AAJC,CAA7B;AAOApD,gBAAgB,CAACsD,YAAjB,GAAgC;AAC9BZ,EAAAA,OAAO,EAAE;AADqB,CAAhC;;AAIA,IAAMa,MAAM,GAAG,SAATA,MAAS,CAAAC,KAAK;AAAA,SAAK;AACvBV,IAAAA,WAAW,EAAE;AACXW,MAAAA,UAAU,EAAED,KAAK,CAACE,OAAN,CAAcC,IAAd,GAAqB,CADtB;AAEXC,MAAAA,aAAa,EAAEJ,KAAK,CAACE,OAAN,CAAcC,IAAd,GAAqB;AAFzB,KADU;AAKvB5B,IAAAA,MAAM,EAAE;AACN8B,MAAAA,QAAQ,EAAE;AADJ;AALe,GAAL;AAAA,CAApB;;eAUe,wBAAWN,MAAX,EAAmBvD,gBAAnB,C","sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\nimport Typography from '@material-ui/core/Typography';\nimport {Collapsible, hasText, PreviewPrompt} from '@pie-lib/render-ui';\nimport { withStyles } from '@material-ui/core/styles';\n\nimport Container from './container';\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(\n target.indexOf('--pie-zoom') + 11,\n target.lastIndexOf('%')\n );\n\n const zoomParsed = zoom?.replace(/\\s/g, '');\n if (zoomParsed) {\n const newScale = parseFloat(zoomParsed) / 100;\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 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 imageUrl,\n prompt,\n mode,\n multipleCorrect,\n shapes,\n outlineColor,\n hotspotColor,\n dimensions,\n rationale,\n teacherInstructions,\n strokeWidth\n },\n onSelectChoice,\n classes\n } = this.props;\n\n const isEvaluateMode = mode === 'evaluate';\n\n return (\n <div>\n {\n teacherInstructions && hasText(teacherInstructions) && (\n <Collapsible\n labels={{ hidden: 'Show Teacher Instructions', visible: 'Hide Teacher Instructions' }}\n className={classes.collapsible}\n >\n <PreviewPrompt\n className=\"prompt\"\n prompt={teacherInstructions}\n />\n </Collapsible>\n )\n }\n\n <Typography className={classes.prompt}>\n <PreviewPrompt\n className=\"prompt\"\n prompt={prompt}\n />\n </Typography>\n\n {imageUrl ? (\n <Container\n isEvaluateMode={isEvaluateMode}\n session={session}\n dimensions={dimensions}\n imageUrl={imageUrl}\n hotspotColor={hotspotColor}\n multipleCorrect={multipleCorrect}\n outlineColor={outlineColor}\n onSelectChoice={onSelectChoice}\n shapes={shapes}\n disabled={disabled}\n strokeWidth={strokeWidth}\n scale={this.state.scale}\n />\n ) : null}\n\n {\n rationale && hasText(rationale) && (\n <Collapsible\n labels={{ hidden: 'Show Rationale', visible: 'Hide Rationale' }}\n className={classes.collapsible}\n >\n <PreviewPrompt\n className=\"prompt\"\n prompt={rationale}\n />\n </Collapsible>\n )\n }\n\n </div>\n );\n }\n}\n\nHotspotComponent.propTypes = {\n classes: PropTypes.object,\n model: PropTypes.object.isRequired,\n onSelectChoice: PropTypes.func.isRequired,\n session: PropTypes.object.isRequired\n};\n\nHotspotComponent.defaultProps = {\n classes: {}\n};\n\nconst styles = theme => ({\n collapsible: {\n paddingTop: theme.spacing.unit * 2,\n paddingBottom: theme.spacing.unit * 2,\n },\n prompt: {\n fontSize: 'inherit'\n }\n});\n\nexport default withStyles(styles)(HotspotComponent);\n"],"file":"index.js"}
|
package/lib/hotspot/polygon.js
CHANGED
|
@@ -35,7 +35,7 @@ var _icons = require("./icons");
|
|
|
35
35
|
|
|
36
36
|
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; }
|
|
37
37
|
|
|
38
|
-
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try {
|
|
38
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
39
39
|
|
|
40
40
|
var PolygonComponent = /*#__PURE__*/function (_React$Component) {
|
|
41
41
|
(0, _inherits2["default"])(PolygonComponent, _React$Component);
|
|
@@ -103,17 +103,6 @@ var PolygonComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
103
103
|
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "getOutlineWidth", function (selected, strokeWidth) {
|
|
104
104
|
return selected ? strokeWidth : 0;
|
|
105
105
|
});
|
|
106
|
-
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "getEvaluateText", function (isCorrect, selected) {
|
|
107
|
-
if (selected && isCorrect) {
|
|
108
|
-
return 'Correctly\nselected';
|
|
109
|
-
} else if (selected && !isCorrect) {
|
|
110
|
-
return 'Incorrectly\nselected';
|
|
111
|
-
} else if (!selected && isCorrect) {
|
|
112
|
-
return 'Correctly\nunselected';
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
return 'Incorrectly\nunselected';
|
|
116
|
-
});
|
|
117
106
|
return _this;
|
|
118
107
|
}
|
|
119
108
|
|
|
@@ -128,7 +117,9 @@ var PolygonComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
128
117
|
outlineColor = _this$props2.outlineColor,
|
|
129
118
|
selected = _this$props2.selected,
|
|
130
119
|
points = _this$props2.points,
|
|
131
|
-
|
|
120
|
+
evaluateText = _this$props2.evaluateText,
|
|
121
|
+
strokeWidth = _this$props2.strokeWidth,
|
|
122
|
+
scale = _this$props2.scale;
|
|
132
123
|
var outlineColorParsed = isEvaluateMode ? this.getEvaluateOutlineColor(isCorrect, outlineColor) : outlineColor;
|
|
133
124
|
var outlineWidth = this.getOutlineWidth(selected, strokeWidth);
|
|
134
125
|
var pointsParsed = this.parsePointsForKonva(points);
|
|
@@ -151,7 +142,10 @@ var PolygonComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
151
142
|
iconSrc = _icons.faWrong;
|
|
152
143
|
}
|
|
153
144
|
|
|
154
|
-
return /*#__PURE__*/_react["default"].createElement(_reactKonva.Group,
|
|
145
|
+
return /*#__PURE__*/_react["default"].createElement(_reactKonva.Group, {
|
|
146
|
+
scaleX: scale,
|
|
147
|
+
scaleY: scale
|
|
148
|
+
}, /*#__PURE__*/_react["default"].createElement(_reactKonva.Line, {
|
|
155
149
|
points: pointsParsed,
|
|
156
150
|
closed: true,
|
|
157
151
|
classes: classes.base,
|
|
@@ -166,7 +160,8 @@ var PolygonComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
166
160
|
}), isEvaluateMode && iconSrc ? /*#__PURE__*/_react["default"].createElement(_image["default"], {
|
|
167
161
|
src: iconSrc,
|
|
168
162
|
x: iconX,
|
|
169
|
-
y: iconY
|
|
163
|
+
y: iconY,
|
|
164
|
+
tooltip: evaluateText
|
|
170
165
|
}) : null);
|
|
171
166
|
}
|
|
172
167
|
}]);
|
|
@@ -194,10 +189,14 @@ PolygonComponent.propTypes = {
|
|
|
194
189
|
outlineColor: _propTypes["default"].string.isRequired,
|
|
195
190
|
points: _propTypes["default"].array.isRequired,
|
|
196
191
|
selected: _propTypes["default"].bool.isRequired,
|
|
197
|
-
|
|
192
|
+
evaluateText: _propTypes["default"].string,
|
|
193
|
+
strokeWidth: _propTypes["default"].number,
|
|
194
|
+
scale: _propTypes["default"].number
|
|
198
195
|
};
|
|
199
196
|
PolygonComponent.defaultProps = {
|
|
200
|
-
|
|
197
|
+
evaluateText: null,
|
|
198
|
+
strokeWidth: 5,
|
|
199
|
+
scale: 1
|
|
201
200
|
};
|
|
202
201
|
|
|
203
202
|
var _default = (0, _styles.withStyles)(styles)(PolygonComponent);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/hotspot/polygon.jsx"],"names":["PolygonComponent","props","points","x","map","y","minX","Math","min","apply","maxX","max","minY","maxY","parsedPoints","forEach","push","e","onClick","id","selected","disabled","cancelBubble","document","body","style","cursor","isCorrect","outlineColor","strokeWidth","classes","hotspotColor","isEvaluateMode","outlineColorParsed","getEvaluateOutlineColor","outlineWidth","getOutlineWidth","pointsParsed","parsePointsForKonva","center","getPolygonCenter","iconX","iconY","iconSrc","faCorrect","faWrong","base","handleClick","handleMouseLeave","handleMouseEnter","React","Component","styles","opacity","position","propTypes","PropTypes","object","isRequired","string","bool","func","array","number","defaultProps"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AAEA;;AACA;;;;;;IAEMA,gB;;;;;AACJ,4BAAYC,KAAZ,EAAmB;AAAA;;AAAA;AACjB,8BAAMA,KAAN;AADiB,yGAIA,UAACC,MAAD,EAAY;AAC7B,UAAMC,CAAC,GAAGD,MAAM,CAACE,GAAP,CAAW;AAAA,YAAGD,CAAH,QAAGA,CAAH;AAAA,eAAWA,CAAX;AAAA,OAAX,CAAV;AACA,UAAME,CAAC,GAAGH,MAAM,CAACE,GAAP,CAAW;AAAA,YAAGC,CAAH,SAAGA,CAAH;AAAA,eAAWA,CAAX;AAAA,OAAX,CAAV;AACA,UAAMC,IAAI,GAAGC,IAAI,CAACC,GAAL,CAASC,KAAT,CAAgB,IAAhB,EAAsBN,CAAtB,CAAb;AACA,UAAMO,IAAI,GAAGH,IAAI,CAACI,GAAL,CAASF,KAAT,CAAgB,IAAhB,EAAsBN,CAAtB,CAAb;AACA,UAAMS,IAAI,GAAGL,IAAI,CAACC,GAAL,CAASC,KAAT,CAAgB,IAAhB,EAAsBJ,CAAtB,CAAb;AACA,UAAMQ,IAAI,GAAGN,IAAI,CAACI,GAAL,CAASF,KAAT,CAAgB,IAAhB,EAAsBJ,CAAtB,CAAb;AACA,aAAO,CAAC,CAACC,IAAI,GAAGI,IAAR,IAAgB,CAAjB,EAAoB,CAACE,IAAI,GAAGC,IAAR,IAAgB,CAApC,CAAP;AACD,KAZkB;AAAA,4GAcG,UAACX,MAAD,EAAY;AAChC,UAAMY,YAAY,GAAG,EAArB;AACAZ,MAAAA,MAAM,CAACa,OAAP,CAAe,iBAAc;AAAA,YAAXZ,CAAW,SAAXA,CAAW;AAAA,YAARE,CAAQ,SAARA,CAAQ;AAC3BS,QAAAA,YAAY,CAACE,IAAb,CAAkBb,CAAlB;AACAW,QAAAA,YAAY,CAACE,IAAb,CAAkBX,CAAlB;AACD,OAHD;AAIA,aAAOS,YAAP;AACD,KArBkB;AAAA,oGAuBL,UAACG,CAAD,EAAO;
|
|
1
|
+
{"version":3,"sources":["../../src/hotspot/polygon.jsx"],"names":["PolygonComponent","props","points","x","map","y","minX","Math","min","apply","maxX","max","minY","maxY","parsedPoints","forEach","push","e","onClick","id","selected","disabled","cancelBubble","document","body","style","cursor","isCorrect","outlineColor","strokeWidth","classes","hotspotColor","isEvaluateMode","evaluateText","scale","outlineColorParsed","getEvaluateOutlineColor","outlineWidth","getOutlineWidth","pointsParsed","parsePointsForKonva","center","getPolygonCenter","iconX","iconY","iconSrc","faCorrect","faWrong","base","handleClick","handleMouseLeave","handleMouseEnter","React","Component","styles","opacity","position","propTypes","PropTypes","object","isRequired","string","bool","func","array","number","defaultProps"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AAEA;;AACA;;;;;;IAEMA,gB;;;;;AACJ,4BAAYC,KAAZ,EAAmB;AAAA;;AAAA;AACjB,8BAAMA,KAAN;AADiB,yGAIA,UAACC,MAAD,EAAY;AAC7B,UAAMC,CAAC,GAAGD,MAAM,CAACE,GAAP,CAAW;AAAA,YAAGD,CAAH,QAAGA,CAAH;AAAA,eAAWA,CAAX;AAAA,OAAX,CAAV;AACA,UAAME,CAAC,GAAGH,MAAM,CAACE,GAAP,CAAW;AAAA,YAAGC,CAAH,SAAGA,CAAH;AAAA,eAAWA,CAAX;AAAA,OAAX,CAAV;AACA,UAAMC,IAAI,GAAGC,IAAI,CAACC,GAAL,CAASC,KAAT,CAAgB,IAAhB,EAAsBN,CAAtB,CAAb;AACA,UAAMO,IAAI,GAAGH,IAAI,CAACI,GAAL,CAASF,KAAT,CAAgB,IAAhB,EAAsBN,CAAtB,CAAb;AACA,UAAMS,IAAI,GAAGL,IAAI,CAACC,GAAL,CAASC,KAAT,CAAgB,IAAhB,EAAsBJ,CAAtB,CAAb;AACA,UAAMQ,IAAI,GAAGN,IAAI,CAACI,GAAL,CAASF,KAAT,CAAgB,IAAhB,EAAsBJ,CAAtB,CAAb;AACA,aAAO,CAAC,CAACC,IAAI,GAAGI,IAAR,IAAgB,CAAjB,EAAoB,CAACE,IAAI,GAAGC,IAAR,IAAgB,CAApC,CAAP;AACD,KAZkB;AAAA,4GAcG,UAACX,MAAD,EAAY;AAChC,UAAMY,YAAY,GAAG,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,EAAAA,MAAM,EAAEwD,sBAAUM,KAAV,CAAgBJ,UATG;AAU3BxC,EAAAA,QAAQ,EAAEsC,sBAAUI,IAAV,CAAeF,UAVE;AAW3B3B,EAAAA,YAAY,EAAEyB,sBAAUG,MAXG;AAY3BhC,EAAAA,WAAW,EAAE6B,sBAAUO,MAZI;AAa3B/B,EAAAA,KAAK,EAAEwB,sBAAUO;AAbU,CAA7B;AAgBAjE,gBAAgB,CAACkE,YAAjB,GAAgC;AAC9BjC,EAAAA,YAAY,EAAE,IADgB;AAE9BJ,EAAAA,WAAW,EAAE,CAFiB;AAG9BK,EAAAA,KAAK,EAAE;AAHuB,CAAhC;;eAMe,wBAAWoB,MAAX,EAAmBtD,gBAAnB,C","sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\nimport { Line, Group } from 'react-konva';\nimport { withStyles } from '@material-ui/core/styles';\n\nimport Image from './image';\nimport { faCorrect, faWrong } from './icons';\n\nclass PolygonComponent extends React.Component {\n constructor(props) {\n super(props);\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 });\n }\n };\n\n handleMouseEnter = () => {\n const { disabled } = this.props;\n\n if (!disabled) {\n document.body.style.cursor = 'pointer';\n }\n };\n\n handleMouseLeave = () => {\n document.body.style.cursor = 'default';\n };\n\n getEvaluateOutlineColor = (isCorrect, outlineColor) => isCorrect ? outlineColor : 'red';\n\n getOutlineWidth = (selected, strokeWidth) => selected ? strokeWidth : 0;\n\n render() {\n const {\n classes,\n hotspotColor,\n isCorrect,\n isEvaluateMode,\n outlineColor,\n selected,\n points,\n evaluateText,\n strokeWidth,\n scale\n } = this.props;\n\n const outlineColorParsed = isEvaluateMode\n ? this.getEvaluateOutlineColor(isCorrect, outlineColor)\n : outlineColor;\n const outlineWidth = this.getOutlineWidth(selected, 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 // Correctly selected hotspot: white checkmark in green circle (plus the selected hotspot will have a heavy outline, as on “Gather”)\n // Correctly not selected hotspot: none\n // Incorrectly selected hostpot: white “X” in red circle, plus the heavy outline around the selection should appear in red\n // Incorrectly not selected hotspot: white “X” in red circle\n let iconSrc;\n\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 return (\n <Group scaleX={scale} scaleY={scale}>\n <Line\n points={pointsParsed}\n closed={true}\n classes={classes.base}\n fill={hotspotColor}\n onClick={this.handleClick}\n onTap={this.handleClick}\n draggable={false}\n stroke={outlineColorParsed}\n strokeWidth={outlineWidth}\n onMouseLeave={this.handleMouseLeave}\n onMouseEnter={this.handleMouseEnter}\n />\n {(isEvaluateMode && iconSrc) ? (\n <Image\n src={iconSrc}\n x={iconX}\n y={iconY}\n tooltip={evaluateText}\n />\n ): null}\n </Group>\n );\n }\n}\n\nconst styles = () => ({\n base: {\n cursor: 'pointer',\n opacity: 0.5,\n position: 'relative'\n },\n});\n\nPolygonComponent.propTypes = {\n classes: PropTypes.object.isRequired,\n hotspotColor: PropTypes.string.isRequired,\n id: PropTypes.string.isRequired,\n isCorrect: PropTypes.bool.isRequired,\n isEvaluateMode: PropTypes.bool.isRequired,\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 strokeWidth: PropTypes.number,\n scale: PropTypes.number\n};\n\nPolygonComponent.defaultProps = {\n evaluateText: null,\n strokeWidth: 5,\n scale: 1\n};\n\nexport default withStyles(styles)(PolygonComponent);\n"],"file":"polygon.js"}
|