@pie-element/hotspot 6.0.2-next.3 → 6.0.2-next.45
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/configure/lib/DeleteWidget.js +2 -2
- package/configure/lib/DeleteWidget.js.map +1 -1
- package/configure/package.json +1 -1
- package/configure/src/DeleteWidget.jsx +2 -2
- package/configure/src/__tests__/DeleteWidget.test.js +64 -0
- package/controller/package.json +1 -1
- package/lib/hotspot/polygon.js +7 -7
- package/lib/hotspot/polygon.js.map +1 -1
- package/lib/hotspot/rectangle.js +7 -7
- package/lib/hotspot/rectangle.js.map +1 -1
- package/package.json +3 -3
- package/src/__tests__/polygon.test.jsx +7 -7
- package/src/__tests__/rectangle.test.jsx +7 -7
- package/src/hotspot/polygon.jsx +2 -3
- package/src/hotspot/rectangle.jsx +2 -3
- package/configure/lib/image.js +0 -133
- package/configure/lib/image.js.map +0 -1
- package/configure/src/image.jsx +0 -76
- package/lib/hotspot/image.js +0 -133
- package/lib/hotspot/image.js.map +0 -1
- package/src/__tests__/__snapshots__/image.test.jsx.snap +0 -43
- package/src/__tests__/image.test.jsx +0 -54
- package/src/hotspot/image.jsx +0 -76
|
@@ -15,7 +15,7 @@ var _reactKonva = require("react-konva");
|
|
|
15
15
|
|
|
16
16
|
var _icons = require("./icons");
|
|
17
17
|
|
|
18
|
-
var
|
|
18
|
+
var _icons2 = require("@pie-lib/pie-toolbox/icons");
|
|
19
19
|
|
|
20
20
|
var _utils = require("./utils");
|
|
21
21
|
|
|
@@ -47,7 +47,7 @@ var DeleteWidget = function DeleteWidget(_ref) {
|
|
|
47
47
|
onClick: function onClick() {
|
|
48
48
|
return handleWidgetClick(id);
|
|
49
49
|
}
|
|
50
|
-
}, /*#__PURE__*/_react["default"].createElement(
|
|
50
|
+
}, /*#__PURE__*/_react["default"].createElement(_icons2.ImageComponent, {
|
|
51
51
|
width: 20,
|
|
52
52
|
height: 20,
|
|
53
53
|
x: positionX,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/DeleteWidget.jsx"],"names":["DeleteWidget","height","id","width","x","y","points","outlineColor","handleWidgetClick","positionX","positionY","faDelete","propTypes","PropTypes","string","isRequired","number","func","arrayOf","shape"],"mappings":";;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAEA,IAAMA,YAAY,GAAG,SAAfA,YAAe,OAA0E;AAAA,MAAvEC,MAAuE,QAAvEA,MAAuE;AAAA,MAA/DC,EAA+D,QAA/DA,EAA+D;AAAA,MAA3DC,KAA2D,QAA3DA,KAA2D;AAAA,MAApDC,CAAoD,QAApDA,CAAoD;AAAA,MAAjDC,CAAiD,QAAjDA,CAAiD;AAAA,MAA9CC,MAA8C,QAA9CA,MAA8C;AAAA,MAAtCC,YAAsC,QAAtCA,YAAsC;AAAA,MAAxBC,iBAAwB,QAAxBA,iBAAwB;AAC7F,MAAIC,SAAJ,EAAeC,SAAf,CAD6F,CAE7F;;AACA,MAAIJ,MAAJ,EAAY;AACV,qBAAiB,sBAAUA,MAAV,CAAjB;AAAA,QAAQF,EAAR,cAAQA,CAAR;AAAA,QAAWC,EAAX,cAAWA,CAAX;;AACAI,IAAAA,SAAS,GAAGL,EAAZ;AACAM,IAAAA,SAAS,GAAGL,EAAZ;AACD,GAJD,MAIO;AACLI,IAAAA,SAAS,GAAGL,CAAC,GAAGD,KAAJ,GAAY,EAAxB,CADK,CACuB;;AAC5BO,IAAAA,SAAS,GAAGL,CAAC,GAAGJ,MAAJ,GAAa,EAAzB,CAFK,CAEwB;AAC9B;;AAED,sBACE,gCAAC,iBAAD;AAAO,IAAA,OAAO,EAAE;AAAA,aAAMO,iBAAiB,CAACN,EAAD,CAAvB;AAAA;AAAhB,kBACE,gCAAC,
|
|
1
|
+
{"version":3,"sources":["../src/DeleteWidget.jsx"],"names":["DeleteWidget","height","id","width","x","y","points","outlineColor","handleWidgetClick","positionX","positionY","faDelete","propTypes","PropTypes","string","isRequired","number","func","array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EvBd,EAAAA,MAAM,EAAEY,sBAAUG,MAFK;AAGvBb,EAAAA,KAAK,EAAEU,sBAAUG,MAHM;AAIvBZ,EAAAA,CAAC,EAAES,sBAAUG,MAAV,CAAiBD,UAJG;AAKvBV,EAAAA,CAAC,EAAEQ,sBAAUG,MAAV,CAAiBD,UALG;AAMvBP,EAAAA,iBAAiB,EAAEK,sBAAUI,IAAV,CAAeF,UANX;AAOvBT,EAAAA,MAAM,EAAEO,sBAAUK,OAAV,CACNL,sBAAUM,KAAV,CAAgB;AACdf,IAAAA,CAAC,EAAES,sBAAUG,MADC;AAEdX,IAAAA,CAAC,EAAEQ,sBAAUG;AAFC,GAAhB,CADM,CAPe;AAavBT,EAAAA,YAAY,EAAEM,sBAAUC,MAAV,CAAiBC;AAbR,CAAzB;eAgBef,Y","sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\nimport { Group } from 'react-konva';\nimport { faDelete } from './icons';\nimport { ImageComponent } from '@pie-lib/pie-toolbox/icons';\nimport { calculate } from './utils';\n\nconst DeleteWidget = ({ height, id, width, x, y, points, outlineColor, handleWidgetClick }) => {\n let positionX, positionY;\n // if points exist we have an irregular form (polygon) and position should be computed\n if (points) {\n const { x, y } = calculate(points);\n positionX = x;\n positionY = y;\n } else {\n positionX = x + width - 20; // 10 pixels to the left\n positionY = y + height - 20; // 10 pixels above\n }\n\n return (\n <Group onClick={() => handleWidgetClick(id)}>\n <ImageComponent width={20} height={20} x={positionX} y={positionY} src={faDelete} />\n </Group>\n );\n};\n\nDeleteWidget.propTypes = {\n id: PropTypes.string.isRequired,\n height: PropTypes.number,\n width: PropTypes.number,\n x: PropTypes.number.isRequired,\n y: PropTypes.number.isRequired,\n handleWidgetClick: PropTypes.func.isRequired,\n points: PropTypes.arrayOf(\n PropTypes.shape({\n x: PropTypes.number,\n y: PropTypes.number,\n }),\n ),\n outlineColor: PropTypes.string.isRequired,\n};\n\nexport default DeleteWidget;\n"],"file":"DeleteWidget.js"}
|
package/configure/package.json
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"@material-ui/core": "^3.9.2",
|
|
11
11
|
"@material-ui/icons": "^3.0.2",
|
|
12
12
|
"@pie-framework/pie-configure-events": "^1.3.0",
|
|
13
|
-
"@pie-lib/pie-toolbox": "1.0
|
|
13
|
+
"@pie-lib/pie-toolbox": "1.1.0",
|
|
14
14
|
"classnames": "^2.2.6",
|
|
15
15
|
"debug": "^3.1.0",
|
|
16
16
|
"konva": "^3.2.4",
|
|
@@ -2,7 +2,7 @@ import React from 'react';
|
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
3
|
import { Group } from 'react-konva';
|
|
4
4
|
import { faDelete } from './icons';
|
|
5
|
-
import
|
|
5
|
+
import { ImageComponent } from '@pie-lib/pie-toolbox/icons';
|
|
6
6
|
import { calculate } from './utils';
|
|
7
7
|
|
|
8
8
|
const DeleteWidget = ({ height, id, width, x, y, points, outlineColor, handleWidgetClick }) => {
|
|
@@ -19,7 +19,7 @@ const DeleteWidget = ({ height, id, width, x, y, points, outlineColor, handleWid
|
|
|
19
19
|
|
|
20
20
|
return (
|
|
21
21
|
<Group onClick={() => handleWidgetClick(id)}>
|
|
22
|
-
<
|
|
22
|
+
<ImageComponent width={20} height={20} x={positionX} y={positionY} src={faDelete} />
|
|
23
23
|
</Group>
|
|
24
24
|
);
|
|
25
25
|
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { shallow } from 'enzyme';
|
|
3
|
+
import DeleteWidget from '../DeleteWidget'; // Adjust the import path as needed
|
|
4
|
+
import { ImageComponent } from '@pie-lib/pie-toolbox/icons';
|
|
5
|
+
|
|
6
|
+
describe('DeleteWidget', () => {
|
|
7
|
+
it('computes positionX and positionY correctly without points', () => {
|
|
8
|
+
const mockHandleWidgetClick = jest.fn();
|
|
9
|
+
|
|
10
|
+
const props = {
|
|
11
|
+
id: 'someId',
|
|
12
|
+
x: 5,
|
|
13
|
+
y: 10,
|
|
14
|
+
width: 30,
|
|
15
|
+
height: 40,
|
|
16
|
+
outlineColor: 'blue',
|
|
17
|
+
handleWidgetClick: mockHandleWidgetClick,
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const wrapper = shallow(<DeleteWidget {...props} />);
|
|
21
|
+
|
|
22
|
+
// Assert that the computed positionX and positionY match the expected values
|
|
23
|
+
expect(wrapper.find(ImageComponent).prop('x')).toEqual(15);
|
|
24
|
+
expect(wrapper.find(ImageComponent).prop('y')).toEqual(30);
|
|
25
|
+
|
|
26
|
+
// Simulate a click event on the Group element
|
|
27
|
+
wrapper.find('Group').simulate('click');
|
|
28
|
+
|
|
29
|
+
// Assert that the handleWidgetClick function is called with the correct arguments
|
|
30
|
+
expect(mockHandleWidgetClick).toHaveBeenCalledWith('someId');
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('computes positionX and positionY correctly with points', () => {
|
|
34
|
+
const props = {
|
|
35
|
+
id: 'someId',
|
|
36
|
+
x: 5,
|
|
37
|
+
y: 10,
|
|
38
|
+
points: [
|
|
39
|
+
{
|
|
40
|
+
"y": 151,
|
|
41
|
+
"x": 141
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
"y": 289,
|
|
45
|
+
"x": 205
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
"x": 269,
|
|
49
|
+
"y": 151
|
|
50
|
+
}
|
|
51
|
+
],
|
|
52
|
+
width: 30,
|
|
53
|
+
height: 40,
|
|
54
|
+
outlineColor: 'blue',
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const wrapper = shallow(<DeleteWidget {...props} />);
|
|
58
|
+
|
|
59
|
+
// Assert that the computed positionX and positionY match the expected values
|
|
60
|
+
expect(wrapper.find(ImageComponent).prop('x')).toEqual(239);
|
|
61
|
+
expect(wrapper.find(ImageComponent).prop('y')).toEqual(194);
|
|
62
|
+
|
|
63
|
+
});
|
|
64
|
+
});
|
package/controller/package.json
CHANGED
package/lib/hotspot/polygon.js
CHANGED
|
@@ -29,9 +29,9 @@ var _reactKonva = require("react-konva");
|
|
|
29
29
|
|
|
30
30
|
var _styles = require("@material-ui/core/styles");
|
|
31
31
|
|
|
32
|
-
var
|
|
32
|
+
var _icons = require("@pie-lib/pie-toolbox/icons");
|
|
33
33
|
|
|
34
|
-
var
|
|
34
|
+
var _icons2 = 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
|
|
|
@@ -146,17 +146,17 @@ var PolygonComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
146
146
|
|
|
147
147
|
if (showCorrectEnabled) {
|
|
148
148
|
if (selected && isCorrect || !selected && !isCorrect) {
|
|
149
|
-
iconSrc =
|
|
149
|
+
iconSrc = _icons2.faCorrect;
|
|
150
150
|
}
|
|
151
151
|
} else {
|
|
152
152
|
if (selected) {
|
|
153
153
|
if (isCorrect) {
|
|
154
|
-
iconSrc =
|
|
154
|
+
iconSrc = _icons2.faCorrect;
|
|
155
155
|
} else {
|
|
156
|
-
iconSrc =
|
|
156
|
+
iconSrc = _icons2.faWrong;
|
|
157
157
|
}
|
|
158
158
|
} else if (!isCorrect) {
|
|
159
|
-
iconSrc =
|
|
159
|
+
iconSrc = _icons2.faWrong;
|
|
160
160
|
}
|
|
161
161
|
}
|
|
162
162
|
|
|
@@ -175,7 +175,7 @@ var PolygonComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
175
175
|
strokeWidth: outlineWidth,
|
|
176
176
|
onMouseLeave: this.handleMouseLeave,
|
|
177
177
|
onMouseEnter: this.handleMouseEnter
|
|
178
|
-
}), isEvaluateMode && iconSrc ? /*#__PURE__*/_react["default"].createElement(
|
|
178
|
+
}), isEvaluateMode && iconSrc ? /*#__PURE__*/_react["default"].createElement(_icons.ImageComponent, {
|
|
179
179
|
src: iconSrc,
|
|
180
180
|
x: iconX,
|
|
181
181
|
y: iconY,
|
|
@@ -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","markAsCorrect","outlineColor","showCorrectEnabled","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,CAAe,IAAf,EAAqBN,CAArB,CAAb;AACA,UAAMO,IAAI,GAAGH,IAAI,CAACI,GAAL,CAASF,KAAT,CAAe,IAAf,EAAqBN,CAArB,CAAb;AACA,UAAMS,IAA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GAAgC;AAC9BjC,EAAAA,YAAY,EAAE,IADgB;AAE9BJ,EAAAA,WAAW,EAAE,CAFiB;AAG9BK,EAAAA,KAAK,EAAE;AAHuB,CAAhC;;eAMe,wBAAWoB,MAAX,EAAmBxD,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, 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 classes,\n hotspotColor,\n isCorrect,\n isEvaluateMode,\n outlineColor,\n selected,\n points,\n evaluateText,\n strokeWidth,\n scale,\n markAsCorrect,\n showCorrectEnabled,\n } = this.props;\n\n const outlineColorParsed = isEvaluateMode\n ? this.getEvaluateOutlineColor(isCorrect, markAsCorrect, outlineColor)\n : outlineColor;\n const outlineWidth = this.getOutlineWidth(showCorrectEnabled, selected, markAsCorrect, strokeWidth);\n\n const pointsParsed = this.parsePointsForKonva(points);\n const center = this.getPolygonCenter(points);\n const iconX = center[0];\n const iconY = center[1];\n\n // \"Show Correct Answer\" Enabled:\n // - Correctly Selected: white checkmark in green circle\n // - Correctly Not Selected: none\n // - Incorrectly Selected: none\n // - Incorrectly Not Selected: white checkmark in green circle\n // \"Show Correct Answer\" Disabled:\n // - Correctly Selected:\n // - white checkmark in green circle\n // - heavy outline, as on “Gather”\n // - Correctly Not Selected: none\n // - Incorrectly Selected:\n // - white \"X\" in red circle\n // - heavy outline around the selection should appear in red\n // - Incorrectly Not Selected: white \"X\" in red circle\n let iconSrc;\n\n if (showCorrectEnabled) {\n if ((selected && isCorrect) || (!selected && !isCorrect)) {\n iconSrc = faCorrect;\n }\n } else {\n if (selected) {\n if (isCorrect) {\n iconSrc = faCorrect;\n } else {\n iconSrc = faWrong;\n }\n } else if (!isCorrect) {\n iconSrc = faWrong;\n }\n }\n\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 ? <Image src={iconSrc} x={iconX} y={iconY} tooltip={evaluateText} /> : 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 markAsCorrect: PropTypes.bool.isRequired,\n showCorrectEnabled: PropTypes.bool.isRequired,\n};\n\nPolygonComponent.defaultProps = {\n evaluateText: null,\n strokeWidth: 5,\n scale: 1,\n};\n\nexport default withStyles(styles)(PolygonComponent);\n"],"file":"polygon.js"}
|
|
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","markAsCorrect","outlineColor","showCorrectEnabled","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;;AACA;;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,CAAe,IAA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AAUI,IAAV,CAAeF,UAdH;AAe3BhC,EAAAA,kBAAkB,EAAE8B,sBAAUI,IAAV,CAAeF;AAfR,CAA7B;AAkBA9D,gBAAgB,CAACoE,YAAjB,GAAgC;AAC9BjC,EAAAA,YAAY,EAAE,IADgB;AAE9BJ,EAAAA,WAAW,EAAE,CAFiB;AAG9BK,EAAAA,KAAK,EAAE;AAHuB,CAAhC;;eAMe,wBAAWoB,MAAX,EAAmBxD,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';\nimport { ImageComponent } from '@pie-lib/pie-toolbox/icons';\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, 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 classes,\n hotspotColor,\n isCorrect,\n isEvaluateMode,\n outlineColor,\n selected,\n points,\n evaluateText,\n strokeWidth,\n scale,\n markAsCorrect,\n showCorrectEnabled,\n } = this.props;\n\n const outlineColorParsed = isEvaluateMode\n ? this.getEvaluateOutlineColor(isCorrect, markAsCorrect, outlineColor)\n : outlineColor;\n const outlineWidth = this.getOutlineWidth(showCorrectEnabled, selected, markAsCorrect, strokeWidth);\n\n const pointsParsed = this.parsePointsForKonva(points);\n const center = this.getPolygonCenter(points);\n const iconX = center[0];\n const iconY = center[1];\n\n // \"Show Correct Answer\" Enabled:\n // - Correctly Selected: white checkmark in green circle\n // - Correctly Not Selected: none\n // - Incorrectly Selected: none\n // - Incorrectly Not Selected: white checkmark in green circle\n // \"Show Correct Answer\" Disabled:\n // - Correctly Selected:\n // - white checkmark in green circle\n // - heavy outline, as on “Gather”\n // - Correctly Not Selected: none\n // - Incorrectly Selected:\n // - white \"X\" in red circle\n // - heavy outline around the selection should appear in red\n // - Incorrectly Not Selected: white \"X\" in red circle\n let iconSrc;\n\n if (showCorrectEnabled) {\n if ((selected && isCorrect) || (!selected && !isCorrect)) {\n iconSrc = faCorrect;\n }\n } else {\n if (selected) {\n if (isCorrect) {\n iconSrc = faCorrect;\n } else {\n iconSrc = faWrong;\n }\n } else if (!isCorrect) {\n iconSrc = faWrong;\n }\n }\n\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 ? <ImageComponent src={iconSrc} x={iconX} y={iconY} tooltip={evaluateText} /> : 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 markAsCorrect: PropTypes.bool.isRequired,\n showCorrectEnabled: PropTypes.bool.isRequired,\n};\n\nPolygonComponent.defaultProps = {\n evaluateText: null,\n strokeWidth: 5,\n scale: 1,\n};\n\nexport default withStyles(styles)(PolygonComponent);\n"],"file":"polygon.js"}
|
package/lib/hotspot/rectangle.js
CHANGED
|
@@ -29,9 +29,9 @@ var _reactKonva = require("react-konva");
|
|
|
29
29
|
|
|
30
30
|
var _styles = require("@material-ui/core/styles");
|
|
31
31
|
|
|
32
|
-
var
|
|
32
|
+
var _icons = require("@pie-lib/pie-toolbox/icons");
|
|
33
33
|
|
|
34
|
-
var
|
|
34
|
+
var _icons2 = 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
|
|
|
@@ -122,17 +122,17 @@ var RectComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
122
122
|
|
|
123
123
|
if (showCorrectEnabled) {
|
|
124
124
|
if (selected && isCorrect || !selected && !isCorrect) {
|
|
125
|
-
iconSrc =
|
|
125
|
+
iconSrc = _icons2.faCorrect;
|
|
126
126
|
}
|
|
127
127
|
} else {
|
|
128
128
|
if (selected) {
|
|
129
129
|
if (isCorrect) {
|
|
130
|
-
iconSrc =
|
|
130
|
+
iconSrc = _icons2.faCorrect;
|
|
131
131
|
} else {
|
|
132
|
-
iconSrc =
|
|
132
|
+
iconSrc = _icons2.faWrong;
|
|
133
133
|
}
|
|
134
134
|
} else if (!isCorrect) {
|
|
135
|
-
iconSrc =
|
|
135
|
+
iconSrc = _icons2.faWrong;
|
|
136
136
|
}
|
|
137
137
|
}
|
|
138
138
|
|
|
@@ -153,7 +153,7 @@ var RectComponent = /*#__PURE__*/function (_React$Component) {
|
|
|
153
153
|
onMouseEnter: this.handleMouseEnter,
|
|
154
154
|
x: x,
|
|
155
155
|
y: y
|
|
156
|
-
}), isEvaluateMode && iconSrc ? /*#__PURE__*/_react["default"].createElement(
|
|
156
|
+
}), isEvaluateMode && iconSrc ? /*#__PURE__*/_react["default"].createElement(_icons.ImageComponent, {
|
|
157
157
|
src: iconSrc,
|
|
158
158
|
x: iconX,
|
|
159
159
|
y: iconY,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/hotspot/rectangle.jsx"],"names":["RectComponent","props","e","onClick","id","selected","disabled","cancelBubble","document","body","style","cursor","isCorrect","markAsCorrect","outlineColor","showCorrectEnabled","strokeWidth","classes","height","hotspotColor","isEvaluateMode","width","x","y","evaluateText","scale","outlineColorParsed","getEvaluateOutlineColor","outlineWidth","getOutlineWidth","iconX","iconY","iconSrc","faCorrect","faWrong","base","handleClick","handleMouseLeave","handleMouseEnter","React","Component","styles","opacity","position","propTypes","PropTypes","object","isRequired","number","string","oneOfType","bool","func","defaultProps"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;
|
|
1
|
+
{"version":3,"sources":["../../src/hotspot/rectangle.jsx"],"names":["RectComponent","props","e","onClick","id","selected","disabled","cancelBubble","document","body","style","cursor","isCorrect","markAsCorrect","outlineColor","showCorrectEnabled","strokeWidth","classes","height","hotspotColor","isEvaluateMode","width","x","y","evaluateText","scale","outlineColorParsed","getEvaluateOutlineColor","outlineWidth","getOutlineWidth","iconX","iconY","iconSrc","faCorrect","faWrong","base","handleClick","handleMouseLeave","handleMouseEnter","React","Component","styles","opacity","position","propTypes","PropTypes","object","isRequired","number","string","oneOfType","bool","func","defaultProps"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;IAEMA,a;;;;;AACJ,yBAAYC,KAAZ,EAAmB;AAAA;;AAAA;AACjB,8BAAMA,KAAN;AADiB,oGAIL,UAACC,CAAD,EAAO;AACnB,wBAA4C,MAAKD,KAAjD;AAAA,UAAQE,OAAR,eAAQA,OAAR;AAAA,UAAiBC,EAAjB,eAAiBA,EAAjB;AAAA,UAAqBC,QAArB,eAAqBA,QAArB;AAAA,UAA+BC,QAA/B,eAA+BA,QAA/B;;AAEA,UAAI,CAACA,QAAL,EAAe;AACbJ,QAAAA,CAAC,CAACK,YAAF,GAAiB,IAAjB;AACAJ,QAAAA,OAAO,CAAC;AAAEC,UAAAA,EAAE,EAAFA,EAAF;AAAMC,UAAAA,QAAQ,EAAE,CAACA;AAAjB,SAAD,CAAP;AACD;AACF,KAXkB;AAAA,yGAaA,YAAM;AACvB,UAAQC,QAAR,GAAqB,MAAKL,KAA1B,CAAQK,QAAR;;AAEA,UAAI,CAACA,QAAL,EAAe;AACbE,QAAAA,QAAQ,CAACC,IAAT,CAAcC,KAAd,CAAoBC,MAApB,GAA6B,SAA7B;AACD;AACF,KAnBkB;AAAA,yGAqBA,YAAM;AACvBH,MAAAA,QAAQ,CAACC,IAAT,CAAcC,KAAd,CAAoBC,MAApB,GAA6B,SAA7B;AACD,KAvBkB;AAAA,gHAyBO,UAACC,SAAD,EAAYC,aAAZ,EAA2BC,YAA3B;AAAA,aACxBD,aAAa,GAAG,OAAH,GAAaD,SAAS,GAAGE,YAAH,GAAkB,KAD7B;AAAA,KAzBP;AAAA,wGA4BD,UAACC,kBAAD,EAAqBV,QAArB,EA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X,CAA1B;AAqBA/C,aAAa,CAACqD,YAAd,GAA6B;AAC3BzC,EAAAA,SAAS,EAAE,KADgB;AAE3BY,EAAAA,YAAY,EAAE,IAFa;AAG3BR,EAAAA,WAAW,EAAE,CAHc;AAI3BS,EAAAA,KAAK,EAAE;AAJoB,CAA7B;;eAOe,wBAAWgB,MAAX,EAAmBzC,aAAnB,C","sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\nimport { Rect, Group } from 'react-konva';\nimport { withStyles } from '@material-ui/core/styles';\nimport { ImageComponent } from '@pie-lib/pie-toolbox/icons';\nimport { faCorrect, faWrong } from './icons';\n\nclass RectComponent extends React.Component {\n constructor(props) {\n super(props);\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, 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 classes,\n height,\n hotspotColor,\n isCorrect,\n isEvaluateMode,\n outlineColor,\n selected,\n width,\n x,\n y,\n evaluateText,\n strokeWidth,\n scale,\n markAsCorrect,\n showCorrectEnabled,\n } = this.props;\n\n const outlineColorParsed = isEvaluateMode\n ? this.getEvaluateOutlineColor(isCorrect, markAsCorrect, outlineColor)\n : outlineColor;\n\n const outlineWidth = this.getOutlineWidth(showCorrectEnabled, selected, markAsCorrect, strokeWidth);\n\n const iconX = x + width / 2 - 10;\n const iconY = y + height / 2 - 10;\n\n // \"Show Correct Answer\" Enabled:\n // - Correctly Selected: white checkmark in green circle\n // - Correctly Not Selected: none\n // - Incorrectly Selected: none\n // - Incorrectly Not Selected: white checkmark in green circle\n // \"Show Correct Answer\" Disabled:\n // - Correctly Selected:\n // - white checkmark in green circle\n // - heavy outline, as on “Gather”\n // - Correctly Not Selected: none\n // - Incorrectly Selected:\n // - white \"X\" in red circle\n // - heavy outline around the selection should appear in red\n // - Incorrectly Not Selected: white \"X\" in red circle\n let iconSrc;\n\n if (showCorrectEnabled) {\n if ((selected && isCorrect) || (!selected && !isCorrect)) {\n iconSrc = faCorrect;\n }\n } else {\n if (selected) {\n if (isCorrect) {\n iconSrc = faCorrect;\n } else {\n iconSrc = faWrong;\n }\n } else if (!isCorrect) {\n iconSrc = faWrong;\n }\n }\n\n return (\n <Group scaleX={scale} scaleY={scale}>\n <Rect\n classes={classes.base}\n width={width}\n height={height}\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 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\nconst styles = () => ({\n base: {\n cursor: 'pointer',\n opacity: 0.5,\n position: 'relative',\n },\n});\n\nRectComponent.propTypes = {\n classes: PropTypes.object.isRequired,\n height: PropTypes.number.isRequired,\n hotspotColor: PropTypes.string.isRequired,\n id: PropTypes.string.isRequired,\n isCorrect: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]),\n isEvaluateMode: PropTypes.bool.isRequired,\n disabled: PropTypes.bool.isRequired,\n onClick: PropTypes.func.isRequired,\n outlineColor: PropTypes.string.isRequired,\n selected: PropTypes.bool.isRequired,\n width: PropTypes.number.isRequired,\n x: PropTypes.number.isRequired,\n y: PropTypes.number.isRequired,\n evaluateText: PropTypes.string,\n strokeWidth: PropTypes.number,\n scale: PropTypes.number,\n markAsCorrect: PropTypes.bool.isRequired,\n showCorrectEnabled: PropTypes.bool.isRequired,\n};\n\nRectComponent.defaultProps = {\n isCorrect: false,\n evaluateText: null,\n strokeWidth: 5,\n scale: 1,\n};\n\nexport default withStyles(styles)(RectComponent);\n"],"file":"rectangle.js"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pie-element/hotspot",
|
|
3
|
-
"version": "6.0.2-next.
|
|
3
|
+
"version": "6.0.2-next.45+89d4b74dd",
|
|
4
4
|
"description": "",
|
|
5
5
|
"repository": "pie-framework/pie-elements",
|
|
6
6
|
"publishConfig": {
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"dependencies": {
|
|
10
10
|
"@material-ui/core": "^3.9.3",
|
|
11
11
|
"@pie-framework/pie-player-events": "^0.1.0",
|
|
12
|
-
"@pie-lib/pie-toolbox": "1.0
|
|
12
|
+
"@pie-lib/pie-toolbox": "1.1.0",
|
|
13
13
|
"konva": "^3.2.5",
|
|
14
14
|
"prop-types": "^15.6.1",
|
|
15
15
|
"react": "^16.8.1",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
},
|
|
19
19
|
"author": "pie framework developers",
|
|
20
20
|
"license": "ISC",
|
|
21
|
-
"gitHead": "
|
|
21
|
+
"gitHead": "89d4b74dd113d9d9213a7023a3857fb78c45bc10",
|
|
22
22
|
"scripts": {
|
|
23
23
|
"postpublish": "../../scripts/postpublish"
|
|
24
24
|
},
|
|
@@ -8,7 +8,7 @@ import { Line } from 'react-konva';
|
|
|
8
8
|
import { shallowChild } from '@pie-lib/pie-toolbox/test-utils';
|
|
9
9
|
|
|
10
10
|
import Polygon from '../hotspot/polygon';
|
|
11
|
-
import
|
|
11
|
+
import { ImageComponent } from '@pie-lib/pie-toolbox/icons';
|
|
12
12
|
import { faCorrect, faWrong } from '../hotspot/icons';
|
|
13
13
|
|
|
14
14
|
Konva.isBrowser = false;
|
|
@@ -134,7 +134,7 @@ describe('Polygon', () => {
|
|
|
134
134
|
});
|
|
135
135
|
|
|
136
136
|
it('should have a green checkmark icon', () => {
|
|
137
|
-
const imgComponent = polygonComponent.find(
|
|
137
|
+
const imgComponent = polygonComponent.find(ImageComponent);
|
|
138
138
|
expect(imgComponent.length).toEqual(1);
|
|
139
139
|
expect(imgComponent.prop('src')).toEqual(faCorrect);
|
|
140
140
|
});
|
|
@@ -151,7 +151,7 @@ describe('Polygon', () => {
|
|
|
151
151
|
});
|
|
152
152
|
|
|
153
153
|
it('should have no icon', () => {
|
|
154
|
-
const imgComponent = polygonComponent.find(
|
|
154
|
+
const imgComponent = polygonComponent.find(ImageComponent);
|
|
155
155
|
expect(imgComponent.length).toEqual(0);
|
|
156
156
|
});
|
|
157
157
|
});
|
|
@@ -168,7 +168,7 @@ describe('Polygon', () => {
|
|
|
168
168
|
});
|
|
169
169
|
|
|
170
170
|
it('should have a red x icon', () => {
|
|
171
|
-
const imgComponent = polygonComponent.find(
|
|
171
|
+
const imgComponent = polygonComponent.find(ImageComponent);
|
|
172
172
|
expect(imgComponent.length).toEqual(1);
|
|
173
173
|
expect(imgComponent.prop('src')).toEqual(faWrong);
|
|
174
174
|
});
|
|
@@ -185,7 +185,7 @@ describe('Polygon', () => {
|
|
|
185
185
|
});
|
|
186
186
|
|
|
187
187
|
it('should have a red x icon', () => {
|
|
188
|
-
const imgComponent = polygonComponent.find(
|
|
188
|
+
const imgComponent = polygonComponent.find(ImageComponent);
|
|
189
189
|
expect(imgComponent.length).toEqual(1);
|
|
190
190
|
expect(imgComponent.prop('src')).toEqual(faWrong);
|
|
191
191
|
});
|
|
@@ -206,7 +206,7 @@ describe('Polygon', () => {
|
|
|
206
206
|
showCorrectEnabled: true,
|
|
207
207
|
markAsCorrect: true,
|
|
208
208
|
});
|
|
209
|
-
const imgComponent = polygonComponent.find(
|
|
209
|
+
const imgComponent = polygonComponent.find(ImageComponent);
|
|
210
210
|
expect(imgComponent.prop('src')).toEqual(faCorrect);
|
|
211
211
|
});
|
|
212
212
|
|
|
@@ -227,7 +227,7 @@ describe('Polygon', () => {
|
|
|
227
227
|
selected: true,
|
|
228
228
|
isCorrect: false,
|
|
229
229
|
});
|
|
230
|
-
const imgComponent = polygonComponent.find(
|
|
230
|
+
const imgComponent = polygonComponent.find(ImageComponent);
|
|
231
231
|
expect(imgComponent.length).toEqual(0);
|
|
232
232
|
});
|
|
233
233
|
});
|
|
@@ -8,7 +8,7 @@ import { Rect } from 'react-konva';
|
|
|
8
8
|
import { shallowChild } from '@pie-lib/pie-toolbox/test-utils';
|
|
9
9
|
|
|
10
10
|
import Rectangle from '../hotspot/rectangle';
|
|
11
|
-
import
|
|
11
|
+
import { ImageComponent } from '@pie-lib/pie-toolbox/icons';
|
|
12
12
|
import { faCorrect, faWrong } from '../hotspot/icons';
|
|
13
13
|
|
|
14
14
|
global.MutationObserver = class {
|
|
@@ -136,7 +136,7 @@ describe('Rectangle', () => {
|
|
|
136
136
|
});
|
|
137
137
|
|
|
138
138
|
it('should have a green checkmark icon', () => {
|
|
139
|
-
const imgComponent = rectangleComponent.find(
|
|
139
|
+
const imgComponent = rectangleComponent.find(ImageComponent);
|
|
140
140
|
expect(imgComponent.length).toEqual(1);
|
|
141
141
|
expect(imgComponent.prop('src')).toEqual(faCorrect);
|
|
142
142
|
});
|
|
@@ -153,7 +153,7 @@ describe('Rectangle', () => {
|
|
|
153
153
|
});
|
|
154
154
|
|
|
155
155
|
it('should have no icon', () => {
|
|
156
|
-
const imgComponent = rectangleComponent.find(
|
|
156
|
+
const imgComponent = rectangleComponent.find(ImageComponent);
|
|
157
157
|
expect(imgComponent.length).toEqual(0);
|
|
158
158
|
});
|
|
159
159
|
});
|
|
@@ -170,7 +170,7 @@ describe('Rectangle', () => {
|
|
|
170
170
|
});
|
|
171
171
|
|
|
172
172
|
it('should have a red x icon', () => {
|
|
173
|
-
const imgComponent = rectangleComponent.find(
|
|
173
|
+
const imgComponent = rectangleComponent.find(ImageComponent);
|
|
174
174
|
expect(imgComponent.length).toEqual(1);
|
|
175
175
|
expect(imgComponent.prop('src')).toEqual(faWrong);
|
|
176
176
|
});
|
|
@@ -187,7 +187,7 @@ describe('Rectangle', () => {
|
|
|
187
187
|
});
|
|
188
188
|
|
|
189
189
|
it('should have a red x icon', () => {
|
|
190
|
-
const imgComponent = rectangleComponent.find(
|
|
190
|
+
const imgComponent = rectangleComponent.find(ImageComponent);
|
|
191
191
|
expect(imgComponent.length).toEqual(1);
|
|
192
192
|
expect(imgComponent.prop('src')).toEqual(faWrong);
|
|
193
193
|
});
|
|
@@ -208,7 +208,7 @@ describe('Rectangle', () => {
|
|
|
208
208
|
showCorrectEnabled: true,
|
|
209
209
|
markAsCorrect: true,
|
|
210
210
|
});
|
|
211
|
-
const imgComponent = rectangleComponent.find(
|
|
211
|
+
const imgComponent = rectangleComponent.find(ImageComponent);
|
|
212
212
|
expect(imgComponent.prop('src')).toEqual(faCorrect);
|
|
213
213
|
});
|
|
214
214
|
|
|
@@ -229,7 +229,7 @@ describe('Rectangle', () => {
|
|
|
229
229
|
selected: true,
|
|
230
230
|
isCorrect: false,
|
|
231
231
|
});
|
|
232
|
-
const imgComponent = rectangleComponent.find(
|
|
232
|
+
const imgComponent = rectangleComponent.find(ImageComponent);
|
|
233
233
|
expect(imgComponent.length).toEqual(0);
|
|
234
234
|
});
|
|
235
235
|
});
|
package/src/hotspot/polygon.jsx
CHANGED
|
@@ -2,8 +2,7 @@ import React from 'react';
|
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
3
|
import { Line, Group } from 'react-konva';
|
|
4
4
|
import { withStyles } from '@material-ui/core/styles';
|
|
5
|
-
|
|
6
|
-
import Image from './image';
|
|
5
|
+
import { ImageComponent } from '@pie-lib/pie-toolbox/icons';
|
|
7
6
|
import { faCorrect, faWrong } from './icons';
|
|
8
7
|
|
|
9
8
|
class PolygonComponent extends React.Component {
|
|
@@ -130,7 +129,7 @@ class PolygonComponent extends React.Component {
|
|
|
130
129
|
onMouseLeave={this.handleMouseLeave}
|
|
131
130
|
onMouseEnter={this.handleMouseEnter}
|
|
132
131
|
/>
|
|
133
|
-
{isEvaluateMode && iconSrc ? <
|
|
132
|
+
{isEvaluateMode && iconSrc ? <ImageComponent src={iconSrc} x={iconX} y={iconY} tooltip={evaluateText} /> : null}
|
|
134
133
|
</Group>
|
|
135
134
|
);
|
|
136
135
|
}
|
|
@@ -2,8 +2,7 @@ import React from 'react';
|
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
3
|
import { Rect, Group } from 'react-konva';
|
|
4
4
|
import { withStyles } from '@material-ui/core/styles';
|
|
5
|
-
|
|
6
|
-
import Image from './image';
|
|
5
|
+
import { ImageComponent } from '@pie-lib/pie-toolbox/icons';
|
|
7
6
|
import { faCorrect, faWrong } from './icons';
|
|
8
7
|
|
|
9
8
|
class RectComponent extends React.Component {
|
|
@@ -115,7 +114,7 @@ class RectComponent extends React.Component {
|
|
|
115
114
|
x={x}
|
|
116
115
|
y={y}
|
|
117
116
|
/>
|
|
118
|
-
{isEvaluateMode && iconSrc ? <
|
|
117
|
+
{isEvaluateMode && iconSrc ? <ImageComponent src={iconSrc} x={iconX} y={iconY} tooltip={evaluateText} /> : null}
|
|
119
118
|
</Group>
|
|
120
119
|
);
|
|
121
120
|
}
|
package/configure/lib/image.js
DELETED
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports["default"] = void 0;
|
|
9
|
-
|
|
10
|
-
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
11
|
-
|
|
12
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
13
|
-
|
|
14
|
-
var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
|
|
15
|
-
|
|
16
|
-
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
17
|
-
|
|
18
|
-
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
19
|
-
|
|
20
|
-
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
21
|
-
|
|
22
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
23
|
-
|
|
24
|
-
var _react = _interopRequireDefault(require("react"));
|
|
25
|
-
|
|
26
|
-
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
27
|
-
|
|
28
|
-
var _reactKonva = require("react-konva");
|
|
29
|
-
|
|
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
|
-
|
|
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
|
-
|
|
34
|
-
var ImageComponent = /*#__PURE__*/function (_React$Component) {
|
|
35
|
-
(0, _inherits2["default"])(ImageComponent, _React$Component);
|
|
36
|
-
|
|
37
|
-
var _super = _createSuper(ImageComponent);
|
|
38
|
-
|
|
39
|
-
function ImageComponent(props) {
|
|
40
|
-
var _this;
|
|
41
|
-
|
|
42
|
-
(0, _classCallCheck2["default"])(this, ImageComponent);
|
|
43
|
-
_this = _super.call(this, props);
|
|
44
|
-
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "handleLoad", function () {
|
|
45
|
-
_this.setState({
|
|
46
|
-
image: _this.image
|
|
47
|
-
});
|
|
48
|
-
});
|
|
49
|
-
_this.state = {
|
|
50
|
-
image: null,
|
|
51
|
-
showTooltip: false
|
|
52
|
-
};
|
|
53
|
-
return _this;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
(0, _createClass2["default"])(ImageComponent, [{
|
|
57
|
-
key: "componentDidMount",
|
|
58
|
-
value: function componentDidMount() {
|
|
59
|
-
this.loadImage();
|
|
60
|
-
}
|
|
61
|
-
}, {
|
|
62
|
-
key: "componentDidUpdate",
|
|
63
|
-
value: function componentDidUpdate(oldProps) {
|
|
64
|
-
if (oldProps.src !== this.props.src) {
|
|
65
|
-
this.loadImage();
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}, {
|
|
69
|
-
key: "componentWillUnmount",
|
|
70
|
-
value: function componentWillUnmount() {
|
|
71
|
-
this.image.removeEventListener('load', this.handleLoad);
|
|
72
|
-
}
|
|
73
|
-
}, {
|
|
74
|
-
key: "loadImage",
|
|
75
|
-
value: function loadImage() {
|
|
76
|
-
var src = this.props.src;
|
|
77
|
-
this.image = new window.Image();
|
|
78
|
-
this.image.src = src;
|
|
79
|
-
this.image.addEventListener('load', this.handleLoad);
|
|
80
|
-
}
|
|
81
|
-
}, {
|
|
82
|
-
key: "render",
|
|
83
|
-
value: function render() {
|
|
84
|
-
var _this2 = this;
|
|
85
|
-
|
|
86
|
-
var _this$props = this.props,
|
|
87
|
-
x = _this$props.x,
|
|
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, {
|
|
94
|
-
width: 20,
|
|
95
|
-
height: 20,
|
|
96
|
-
x: x,
|
|
97
|
-
y: y,
|
|
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
|
-
})));
|
|
120
|
-
}
|
|
121
|
-
}]);
|
|
122
|
-
return ImageComponent;
|
|
123
|
-
}(_react["default"].Component);
|
|
124
|
-
|
|
125
|
-
ImageComponent.propTypes = {
|
|
126
|
-
src: _propTypes["default"].string.isRequired,
|
|
127
|
-
x: _propTypes["default"].number.isRequired,
|
|
128
|
-
y: _propTypes["default"].number.isRequired,
|
|
129
|
-
tooltip: _propTypes["default"].string
|
|
130
|
-
};
|
|
131
|
-
var _default = ImageComponent;
|
|
132
|
-
exports["default"] = _default;
|
|
133
|
-
//# sourceMappingURL=image.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/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;AAAK,QAAA,IAAI,EAAC,OAAV;AAAkB,QAAA,YAAY,EAAE,CAAhC;AAAmC,QAAA,OAAO,EAAE;AAA5C,QADF,eAEE,gCAAC,gBAAD;AAAM,QAAA,IAAI,EAAEC,OAAZ;AAAqB,QAAA,OAAO,EAAE;AAA9B,QAFF,CAZJ,CADF;AAoBD;;;EA7D0BC,kBAAMC,S;;AAgEnClB,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 fill=\"white\" cornerRadius={5} opacity={0.9} />\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/configure/src/image.jsx
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
3
|
-
import { Group, Image, Text, Tag, Label } from 'react-konva';
|
|
4
|
-
|
|
5
|
-
class ImageComponent extends React.Component {
|
|
6
|
-
constructor(props) {
|
|
7
|
-
super(props);
|
|
8
|
-
this.state = {
|
|
9
|
-
image: null,
|
|
10
|
-
showTooltip: false,
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
componentDidMount() {
|
|
15
|
-
this.loadImage();
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
componentDidUpdate(oldProps) {
|
|
19
|
-
if (oldProps.src !== this.props.src) {
|
|
20
|
-
this.loadImage();
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
componentWillUnmount() {
|
|
25
|
-
this.image.removeEventListener('load', this.handleLoad);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
loadImage() {
|
|
29
|
-
const { src } = this.props;
|
|
30
|
-
|
|
31
|
-
this.image = new window.Image();
|
|
32
|
-
this.image.src = src;
|
|
33
|
-
this.image.addEventListener('load', this.handleLoad);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
handleLoad = () => {
|
|
37
|
-
this.setState({
|
|
38
|
-
image: this.image,
|
|
39
|
-
});
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
render() {
|
|
43
|
-
const { x, y, tooltip } = this.props;
|
|
44
|
-
const { image, showTooltip } = this.state;
|
|
45
|
-
|
|
46
|
-
return (
|
|
47
|
-
<Group>
|
|
48
|
-
<Image
|
|
49
|
-
width={20}
|
|
50
|
-
height={20}
|
|
51
|
-
x={x}
|
|
52
|
-
y={y}
|
|
53
|
-
image={image}
|
|
54
|
-
onMouseEnter={() => this.setState({ showTooltip: true })}
|
|
55
|
-
onMouseLeave={() => this.setState({ showTooltip: false })}
|
|
56
|
-
/>
|
|
57
|
-
|
|
58
|
-
{showTooltip && tooltip && (
|
|
59
|
-
<Label x={x - 30} y={y + 25}>
|
|
60
|
-
<Tag fill="white" cornerRadius={5} opacity={0.9} />
|
|
61
|
-
<Text text={tooltip} padding={5} />
|
|
62
|
-
</Label>
|
|
63
|
-
)}
|
|
64
|
-
</Group>
|
|
65
|
-
);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
ImageComponent.propTypes = {
|
|
70
|
-
src: PropTypes.string.isRequired,
|
|
71
|
-
x: PropTypes.number.isRequired,
|
|
72
|
-
y: PropTypes.number.isRequired,
|
|
73
|
-
tooltip: PropTypes.string,
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
export default ImageComponent;
|
package/lib/hotspot/image.js
DELETED
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports["default"] = void 0;
|
|
9
|
-
|
|
10
|
-
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
11
|
-
|
|
12
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
13
|
-
|
|
14
|
-
var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
|
|
15
|
-
|
|
16
|
-
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
17
|
-
|
|
18
|
-
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
19
|
-
|
|
20
|
-
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
21
|
-
|
|
22
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
23
|
-
|
|
24
|
-
var _react = _interopRequireDefault(require("react"));
|
|
25
|
-
|
|
26
|
-
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
27
|
-
|
|
28
|
-
var _reactKonva = require("react-konva");
|
|
29
|
-
|
|
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
|
-
|
|
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
|
-
|
|
34
|
-
var ImageComponent = /*#__PURE__*/function (_React$Component) {
|
|
35
|
-
(0, _inherits2["default"])(ImageComponent, _React$Component);
|
|
36
|
-
|
|
37
|
-
var _super = _createSuper(ImageComponent);
|
|
38
|
-
|
|
39
|
-
function ImageComponent(props) {
|
|
40
|
-
var _this;
|
|
41
|
-
|
|
42
|
-
(0, _classCallCheck2["default"])(this, ImageComponent);
|
|
43
|
-
_this = _super.call(this, props);
|
|
44
|
-
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "handleLoad", function () {
|
|
45
|
-
_this.setState({
|
|
46
|
-
image: _this.image
|
|
47
|
-
});
|
|
48
|
-
});
|
|
49
|
-
_this.state = {
|
|
50
|
-
image: null,
|
|
51
|
-
showTooltip: false
|
|
52
|
-
};
|
|
53
|
-
return _this;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
(0, _createClass2["default"])(ImageComponent, [{
|
|
57
|
-
key: "componentDidMount",
|
|
58
|
-
value: function componentDidMount() {
|
|
59
|
-
this.loadImage();
|
|
60
|
-
}
|
|
61
|
-
}, {
|
|
62
|
-
key: "componentDidUpdate",
|
|
63
|
-
value: function componentDidUpdate(oldProps) {
|
|
64
|
-
if (oldProps.src !== this.props.src) {
|
|
65
|
-
this.loadImage();
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}, {
|
|
69
|
-
key: "componentWillUnmount",
|
|
70
|
-
value: function componentWillUnmount() {
|
|
71
|
-
this.image.removeEventListener('load', this.handleLoad);
|
|
72
|
-
}
|
|
73
|
-
}, {
|
|
74
|
-
key: "loadImage",
|
|
75
|
-
value: function loadImage() {
|
|
76
|
-
var src = this.props.src;
|
|
77
|
-
this.image = new window.Image();
|
|
78
|
-
this.image.src = src;
|
|
79
|
-
this.image.addEventListener('load', this.handleLoad);
|
|
80
|
-
}
|
|
81
|
-
}, {
|
|
82
|
-
key: "render",
|
|
83
|
-
value: function render() {
|
|
84
|
-
var _this2 = this;
|
|
85
|
-
|
|
86
|
-
var _this$props = this.props,
|
|
87
|
-
x = _this$props.x,
|
|
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, {
|
|
94
|
-
width: 20,
|
|
95
|
-
height: 20,
|
|
96
|
-
x: x,
|
|
97
|
-
y: y,
|
|
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
|
-
})));
|
|
120
|
-
}
|
|
121
|
-
}]);
|
|
122
|
-
return ImageComponent;
|
|
123
|
-
}(_react["default"].Component);
|
|
124
|
-
|
|
125
|
-
ImageComponent.propTypes = {
|
|
126
|
-
src: _propTypes["default"].string.isRequired,
|
|
127
|
-
x: _propTypes["default"].number.isRequired,
|
|
128
|
-
y: _propTypes["default"].number.isRequired,
|
|
129
|
-
tooltip: _propTypes["default"].string
|
|
130
|
-
};
|
|
131
|
-
var _default = ImageComponent;
|
|
132
|
-
exports["default"] = _default;
|
|
133
|
-
//# sourceMappingURL=image.js.map
|
package/lib/hotspot/image.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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;;;;;;IAEMA,c;;;;;AACJ,0BAAYC,KAAZ,EAAmB;AAAA;;AAAA;AACjB,8BAAMA,KAAN;AADiB,mGA8BN,YAAM;AACjB,YAAKC,QAAL,CAAc;AACZC,QAAAA,KAAK,EAAE,MAAKA;AADA,OAAd;AAGD,KAlCkB;AAEjB,UAAKC,KAAL,GAAa;AACXD,MAAAA,KAAK,EAAE,IADI;AAEXE,MAAAA,WAAW,EAAE;AAFF,KAAb;AAFiB;AAMlB;;;;WAED,6BAAoB;AAClB,WAAKC,SAAL;AACD;;;WAED,4BAAmBC,QAAnB,EAA6B;AAC3B,UAAIA,QAAQ,CAACC,GAAT,KAAiB,KAAKP,KAAL,CAAWO,GAAhC,EAAqC;AACnC,aAAKF,SAAL;AACD;AACF;;;WAED,gCAAuB;AACrB,WAAKH,KAAL,CAAWM,mBAAX,CAA+B,MAA/B,EAAuC,KAAKC,UAA5C;AACD;;;WAED,qBAAY;AACV,UAAQF,GAAR,GAAgB,KAAKP,KAArB,CAAQO,GAAR;AAEA,WAAKL,KAAL,GAAa,IAAIQ,MAAM,CAACC,KAAX,EAAb;AACA,WAAKT,KAAL,CAAWK,GAAX,GAAiBA,GAAjB;AACA,WAAKL,KAAL,CAAWU,gBAAX,CAA4B,MAA5B,EAAoC,KAAKH,UAAzC;AACD;;;WAQD,kBAAS;AAAA;;AACP,wBAA0B,KAAKT,KAA/B;AAAA,UAAQa,CAAR,eAAQA,CAAR;AAAA,UAAWC,CAAX,eAAWA,CAAX;AAAA,UAAcC,OAAd,eAAcA,OAAd;AACA,wBAA+B,KAAKZ,KAApC;AAAA,UAAQD,KAAR,eAAQA,KAAR;AAAA,UAAeE,WAAf,eAAeA,WAAf;AAEA,0BACE,gCAAC,iBAAD,qBACE,gCAAC,iBAAD;AACE,QAAA,KAAK,EAAE,EADT;AAEE,QAAA,MAAM,EAAE,EAFV;AAGE,QAAA,CAAC,EAAES,CAHL;AAIE,QAAA,CAAC,EAAEC,CAJL;AAKE,QAAA,KAAK,EAAEZ,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;AAAK,QAAA,IAAI,EAAC,OAAV;AAAkB,QAAA,YAAY,EAAE,CAAhC;AAAmC,QAAA,OAAO,EAAE;AAA5C,QADF,eAEE,gCAAC,gBAAD;AAAM,QAAA,IAAI,EAAEC,OAAZ;AAAqB,QAAA,OAAO,EAAE;AAA9B,QAFF,CAZJ,CADF;AAoBD;;;EA7D0BC,kBAAMC,S;;AAgEnClB,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 fill=\"white\" cornerRadius={5} opacity={0.9} />\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"}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
-
|
|
3
|
-
exports[`Image snapshots image renders 1`] = `
|
|
4
|
-
<Group>
|
|
5
|
-
<Image
|
|
6
|
-
height={20}
|
|
7
|
-
image={null}
|
|
8
|
-
onMouseEnter={[Function]}
|
|
9
|
-
onMouseLeave={[Function]}
|
|
10
|
-
width={20}
|
|
11
|
-
x={5}
|
|
12
|
-
y={5}
|
|
13
|
-
/>
|
|
14
|
-
</Group>
|
|
15
|
-
`;
|
|
16
|
-
|
|
17
|
-
exports[`Image snapshots tooltip renders 1`] = `
|
|
18
|
-
<Group>
|
|
19
|
-
<Image
|
|
20
|
-
height={20}
|
|
21
|
-
image={null}
|
|
22
|
-
onMouseEnter={[Function]}
|
|
23
|
-
onMouseLeave={[Function]}
|
|
24
|
-
width={20}
|
|
25
|
-
x={5}
|
|
26
|
-
y={5}
|
|
27
|
-
/>
|
|
28
|
-
</Group>
|
|
29
|
-
`;
|
|
30
|
-
|
|
31
|
-
exports[`Image snapshots x y position renders 1`] = `
|
|
32
|
-
<Group>
|
|
33
|
-
<Image
|
|
34
|
-
height={20}
|
|
35
|
-
image={null}
|
|
36
|
-
onMouseEnter={[Function]}
|
|
37
|
-
onMouseLeave={[Function]}
|
|
38
|
-
width={20}
|
|
39
|
-
x={10}
|
|
40
|
-
y={10}
|
|
41
|
-
/>
|
|
42
|
-
</Group>
|
|
43
|
-
`;
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import _ from 'lodash';
|
|
3
|
-
import { shallow } from 'enzyme';
|
|
4
|
-
import toJson from 'enzyme-to-json';
|
|
5
|
-
import Konva from 'konva';
|
|
6
|
-
|
|
7
|
-
import Image from '../hotspot/image';
|
|
8
|
-
|
|
9
|
-
Konva.isBrowser = false;
|
|
10
|
-
|
|
11
|
-
describe('Image', () => {
|
|
12
|
-
let wrapper;
|
|
13
|
-
|
|
14
|
-
const mkWrapper = (opts = {}) => {
|
|
15
|
-
opts = _.extend(
|
|
16
|
-
{
|
|
17
|
-
x: 5,
|
|
18
|
-
y: 5,
|
|
19
|
-
src: '',
|
|
20
|
-
tooltip: null,
|
|
21
|
-
},
|
|
22
|
-
opts,
|
|
23
|
-
);
|
|
24
|
-
|
|
25
|
-
return shallow(<Image {...opts} />);
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
beforeEach(() => {
|
|
29
|
-
wrapper = mkWrapper();
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
describe('snapshots', () => {
|
|
33
|
-
describe('x y position', () => {
|
|
34
|
-
it('renders', () => {
|
|
35
|
-
const wrapper = mkWrapper({ x: 10, y: 10 });
|
|
36
|
-
expect(toJson(wrapper)).toMatchSnapshot();
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
describe('image', () => {
|
|
41
|
-
it('renders', () => {
|
|
42
|
-
const wrapper = mkWrapper({ src: 'https://picsum.photos/id/102/200/300' });
|
|
43
|
-
expect(toJson(wrapper)).toMatchSnapshot();
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
describe('tooltip', () => {
|
|
48
|
-
it('renders', () => {
|
|
49
|
-
const wrapper = mkWrapper({ tooltip: 'Correctly\nselected' });
|
|
50
|
-
expect(toJson(wrapper)).toMatchSnapshot();
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
});
|
package/src/hotspot/image.jsx
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
3
|
-
import { Group, Image, Text, Tag, Label } from 'react-konva';
|
|
4
|
-
|
|
5
|
-
class ImageComponent extends React.Component {
|
|
6
|
-
constructor(props) {
|
|
7
|
-
super(props);
|
|
8
|
-
this.state = {
|
|
9
|
-
image: null,
|
|
10
|
-
showTooltip: false,
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
componentDidMount() {
|
|
15
|
-
this.loadImage();
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
componentDidUpdate(oldProps) {
|
|
19
|
-
if (oldProps.src !== this.props.src) {
|
|
20
|
-
this.loadImage();
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
componentWillUnmount() {
|
|
25
|
-
this.image.removeEventListener('load', this.handleLoad);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
loadImage() {
|
|
29
|
-
const { src } = this.props;
|
|
30
|
-
|
|
31
|
-
this.image = new window.Image();
|
|
32
|
-
this.image.src = src;
|
|
33
|
-
this.image.addEventListener('load', this.handleLoad);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
handleLoad = () => {
|
|
37
|
-
this.setState({
|
|
38
|
-
image: this.image,
|
|
39
|
-
});
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
render() {
|
|
43
|
-
const { x, y, tooltip } = this.props;
|
|
44
|
-
const { image, showTooltip } = this.state;
|
|
45
|
-
|
|
46
|
-
return (
|
|
47
|
-
<Group>
|
|
48
|
-
<Image
|
|
49
|
-
width={20}
|
|
50
|
-
height={20}
|
|
51
|
-
x={x}
|
|
52
|
-
y={y}
|
|
53
|
-
image={image}
|
|
54
|
-
onMouseEnter={() => this.setState({ showTooltip: true })}
|
|
55
|
-
onMouseLeave={() => this.setState({ showTooltip: false })}
|
|
56
|
-
/>
|
|
57
|
-
|
|
58
|
-
{showTooltip && tooltip && (
|
|
59
|
-
<Label x={x - 30} y={y + 25}>
|
|
60
|
-
<Tag fill="white" cornerRadius={5} opacity={0.9} />
|
|
61
|
-
<Text text={tooltip} padding={5} />
|
|
62
|
-
</Label>
|
|
63
|
-
)}
|
|
64
|
-
</Group>
|
|
65
|
-
);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
ImageComponent.propTypes = {
|
|
70
|
-
src: PropTypes.string.isRequired,
|
|
71
|
-
x: PropTypes.number.isRequired,
|
|
72
|
-
y: PropTypes.number.isRequired,
|
|
73
|
-
tooltip: PropTypes.string,
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
export default ImageComponent;
|