@pie-element/hotspot 11.2.0-beta.0 → 11.2.0-next.18
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/author.js +2 -0
- package/configure.js +2 -0
- package/controller.js +1 -0
- package/dist/author/DeleteWidget.d.ts +38 -0
- package/dist/author/DeleteWidget.js +46 -0
- package/dist/author/button.d.ts +31 -0
- package/dist/author/button.js +27 -0
- package/dist/author/buttons/circle.d.ts +18 -0
- package/dist/author/buttons/circle.js +25 -0
- package/dist/author/buttons/polygon.d.ts +18 -0
- package/dist/author/buttons/polygon.js +36 -0
- package/dist/author/buttons/rectangle.d.ts +18 -0
- package/dist/author/buttons/rectangle.js +36 -0
- package/dist/author/defaults.d.ts +157 -0
- package/dist/author/defaults.js +119 -0
- package/dist/author/hotspot-circle.d.ts +21 -0
- package/dist/author/hotspot-circle.js +124 -0
- package/dist/author/hotspot-container.d.ts +29 -0
- package/dist/author/hotspot-container.js +210 -0
- package/dist/author/hotspot-drawable.d.ts +31 -0
- package/dist/author/hotspot-drawable.js +312 -0
- package/dist/author/hotspot-palette.d.ts +14 -0
- package/dist/author/hotspot-palette.js +72 -0
- package/dist/author/hotspot-polygon.d.ts +38 -0
- package/dist/author/hotspot-polygon.js +200 -0
- package/dist/author/hotspot-rectangle.d.ts +20 -0
- package/dist/author/hotspot-rectangle.js +119 -0
- package/dist/author/icons.d.ts +9 -0
- package/dist/author/icons.js +4 -0
- package/dist/author/image-konva.d.ts +19 -0
- package/dist/author/image-konva.js +49 -0
- package/dist/author/index.d.ts +53 -0
- package/dist/author/index.js +146 -0
- package/dist/author/root.d.ts +15 -0
- package/dist/author/root.js +215 -0
- package/dist/author/shapes/circle.d.ts +18 -0
- package/dist/author/shapes/circle.js +47 -0
- package/dist/author/shapes/index.d.ts +12 -0
- package/dist/author/shapes/polygon.d.ts +19 -0
- package/dist/author/shapes/polygon.js +51 -0
- package/dist/author/shapes/rectagle.d.ts +18 -0
- package/dist/author/shapes/rectagle.js +57 -0
- package/dist/author/shapes/utils.d.ts +19 -0
- package/dist/author/shapes/utils.js +16 -0
- package/dist/author/upload-control.d.ts +29 -0
- package/dist/author/upload-control.js +28 -0
- package/dist/author/utils.d.ts +24 -0
- package/dist/author/utils.js +83 -0
- package/dist/browser/ReactKonva-e9jPRlPL.js +19304 -0
- package/dist/browser/ReactKonva-e9jPRlPL.js.map +1 -0
- package/dist/browser/assets/Symbola-4c507403.woff2 +0 -0
- package/dist/browser/author/index.js +37002 -0
- package/dist/browser/author/index.js.map +1 -0
- package/dist/browser/browser-D4gLESxz.js +226 -0
- package/dist/browser/browser-D4gLESxz.js.map +1 -0
- package/dist/browser/controller/index.js +198 -0
- package/dist/browser/controller/index.js.map +1 -0
- package/dist/browser/delivery/index.js +2673 -0
- package/dist/browser/delivery/index.js.map +1 -0
- package/dist/browser/dist-CJeYAWp3.js +100 -0
- package/dist/browser/dist-CJeYAWp3.js.map +1 -0
- package/dist/controller/defaults.d.ts +35 -0
- package/dist/controller/defaults.js +29 -0
- package/dist/controller/index.d.ts +22 -0
- package/dist/controller/index.js +154 -0
- package/dist/controller/utils.d.ts +10 -0
- package/dist/controller/utils.js +12 -0
- package/dist/delivery/hotspot/circle.d.ts +22 -0
- package/dist/delivery/hotspot/circle.js +113 -0
- package/dist/delivery/hotspot/container.d.ts +21 -0
- package/dist/delivery/hotspot/container.js +217 -0
- package/dist/delivery/hotspot/icons.d.ts +10 -0
- package/dist/delivery/hotspot/icons.js +4 -0
- package/dist/delivery/hotspot/image-konva-tooltip.d.ts +19 -0
- package/dist/delivery/hotspot/image-konva-tooltip.js +66 -0
- package/dist/delivery/hotspot/index.d.ts +18 -0
- package/dist/delivery/hotspot/index.js +119 -0
- package/dist/delivery/hotspot/polygon.d.ts +24 -0
- package/dist/delivery/hotspot/polygon.js +121 -0
- package/dist/delivery/hotspot/rectangle.d.ts +22 -0
- package/dist/delivery/hotspot/rectangle.js +116 -0
- package/dist/delivery/index.d.ts +20 -0
- package/dist/delivery/index.js +109 -0
- package/dist/delivery/session-updater.d.ts +10 -0
- package/dist/delivery/session-updater.js +14 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.iife.d.ts +8 -0
- package/dist/index.iife.js +169 -0
- package/dist/index.js +2 -0
- package/dist/runtime-support.d.ts +12 -0
- package/dist/runtime-support.js +12 -0
- package/package.json +84 -19
- package/CHANGELOG.json +0 -997
- package/CHANGELOG.md +0 -2230
- package/LICENSE.md +0 -5
- package/README.md +0 -1
- package/configure/CHANGELOG.json +0 -682
- package/configure/CHANGELOG.md +0 -1964
- package/configure/lib/DeleteWidget.js +0 -64
- package/configure/lib/DeleteWidget.js.map +0 -1
- package/configure/lib/button.js +0 -42
- package/configure/lib/button.js.map +0 -1
- package/configure/lib/buttons/circle.js +0 -33
- package/configure/lib/buttons/circle.js.map +0 -1
- package/configure/lib/buttons/polygon.js +0 -39
- package/configure/lib/buttons/polygon.js.map +0 -1
- package/configure/lib/buttons/rectangle.js +0 -39
- package/configure/lib/buttons/rectangle.js.map +0 -1
- package/configure/lib/defaults.js +0 -155
- package/configure/lib/defaults.js.map +0 -1
- package/configure/lib/hotspot-circle.js +0 -192
- package/configure/lib/hotspot-circle.js.map +0 -1
- package/configure/lib/hotspot-container.js +0 -320
- package/configure/lib/hotspot-container.js.map +0 -1
- package/configure/lib/hotspot-drawable.js +0 -519
- package/configure/lib/hotspot-drawable.js.map +0 -1
- package/configure/lib/hotspot-palette.js +0 -107
- package/configure/lib/hotspot-palette.js.map +0 -1
- package/configure/lib/hotspot-polygon.js +0 -293
- package/configure/lib/hotspot-polygon.js.map +0 -1
- package/configure/lib/hotspot-rectangle.js +0 -190
- package/configure/lib/hotspot-rectangle.js.map +0 -1
- package/configure/lib/icons.js +0 -7
- package/configure/lib/icons.js.map +0 -1
- package/configure/lib/image-konva.js +0 -66
- package/configure/lib/image-konva.js.map +0 -1
- package/configure/lib/index.js +0 -198
- package/configure/lib/index.js.map +0 -1
- package/configure/lib/root.js +0 -331
- package/configure/lib/root.js.map +0 -1
- package/configure/lib/shapes/circle.js +0 -84
- package/configure/lib/shapes/circle.js.map +0 -1
- package/configure/lib/shapes/index.js +0 -50
- package/configure/lib/shapes/index.js.map +0 -1
- package/configure/lib/shapes/polygon.js +0 -82
- package/configure/lib/shapes/polygon.js.map +0 -1
- package/configure/lib/shapes/rectagle.js +0 -84
- package/configure/lib/shapes/rectagle.js.map +0 -1
- package/configure/lib/shapes/utils.js +0 -21
- package/configure/lib/shapes/utils.js.map +0 -1
- package/configure/lib/upload-control.js +0 -41
- package/configure/lib/upload-control.js.map +0 -1
- package/configure/lib/utils.js +0 -185
- package/configure/lib/utils.js.map +0 -1
- package/configure/package.json +0 -26
- package/configure/src/DeleteWidget.jsx +0 -51
- package/configure/src/__tests__/DeleteWidget.test.jsx +0 -366
- package/configure/src/__tests__/button.test.jsx +0 -198
- package/configure/src/__tests__/hotspot-circle.test.jsx +0 -259
- package/configure/src/__tests__/hotspot-container.test.js +0 -366
- package/configure/src/__tests__/hotspot-drawable.test.js +0 -271
- package/configure/src/__tests__/hotspot-palette.test.jsx +0 -71
- package/configure/src/__tests__/image-konva.test.jsx +0 -226
- package/configure/src/__tests__/index.test.js +0 -329
- package/configure/src/__tests__/root.test.js +0 -400
- package/configure/src/__tests__/utils.test.js +0 -241
- package/configure/src/button.jsx +0 -35
- package/configure/src/buttons/circle.jsx +0 -18
- package/configure/src/buttons/polygon.jsx +0 -29
- package/configure/src/buttons/rectangle.jsx +0 -29
- package/configure/src/defaults.js +0 -109
- package/configure/src/hotspot-circle.jsx +0 -183
- package/configure/src/hotspot-container.jsx +0 -330
- package/configure/src/hotspot-drawable.jsx +0 -527
- package/configure/src/hotspot-palette.jsx +0 -90
- package/configure/src/hotspot-polygon.jsx +0 -294
- package/configure/src/hotspot-rectangle.jsx +0 -169
- package/configure/src/icons.js +0 -5
- package/configure/src/image-konva.jsx +0 -63
- package/configure/src/index.js +0 -213
- package/configure/src/root.jsx +0 -342
- package/configure/src/shapes/circle.js +0 -81
- package/configure/src/shapes/index.js +0 -4
- package/configure/src/shapes/polygon.js +0 -81
- package/configure/src/shapes/rectagle.js +0 -82
- package/configure/src/shapes/utils.js +0 -16
- package/configure/src/upload-control.jsx +0 -33
- package/configure/src/utils.js +0 -210
- package/controller/CHANGELOG.json +0 -362
- package/controller/CHANGELOG.md +0 -1310
- package/controller/lib/defaults.js +0 -33
- package/controller/lib/defaults.js.map +0 -1
- package/controller/lib/index.js +0 -342
- package/controller/lib/index.js.map +0 -1
- package/controller/lib/utils.js +0 -32
- package/controller/lib/utils.js.map +0 -1
- package/controller/package.json +0 -18
- package/controller/src/__tests__/index.test.js +0 -419
- package/controller/src/__tests__/utils.test.js +0 -5
- package/controller/src/defaults.js +0 -19
- package/controller/src/index.js +0 -330
- package/controller/src/utils.js +0 -29
- package/docs/config-schema.json +0 -2023
- package/docs/config-schema.json.md +0 -1495
- package/docs/demo/config.js +0 -8
- package/docs/demo/generate.js +0 -122
- package/docs/demo/index.html +0 -1
- package/docs/demo/session.js +0 -11
- package/docs/pie-schema.json +0 -1204
- package/docs/pie-schema.json.md +0 -851
- package/lib/hotspot/circle.js +0 -160
- package/lib/hotspot/circle.js.map +0 -1
- package/lib/hotspot/container.js +0 -291
- package/lib/hotspot/container.js.map +0 -1
- package/lib/hotspot/icons.js +0 -8
- package/lib/hotspot/icons.js.map +0 -1
- package/lib/hotspot/image-konva-tooltip.js +0 -86
- package/lib/hotspot/image-konva-tooltip.js.map +0 -1
- package/lib/hotspot/index.js +0 -174
- package/lib/hotspot/index.js.map +0 -1
- package/lib/hotspot/polygon.js +0 -207
- package/lib/hotspot/polygon.js.map +0 -1
- package/lib/hotspot/rectangle.js +0 -178
- package/lib/hotspot/rectangle.js.map +0 -1
- package/lib/index.js +0 -214
- package/lib/index.js.map +0 -1
- package/lib/session-updater.js +0 -42
- package/lib/session-updater.js.map +0 -1
- package/src/__tests__/container.test.jsx +0 -58
- package/src/__tests__/index.test.js +0 -123
- package/src/__tests__/session-updater.test.jsx +0 -69
- package/src/hotspot/__tests__/circle.test.jsx +0 -464
- package/src/hotspot/__tests__/container.test.jsx +0 -546
- package/src/hotspot/__tests__/image-konva-tooltip.test.jsx +0 -510
- package/src/hotspot/__tests__/index.test.jsx +0 -64
- package/src/hotspot/__tests__/polygon.test.jsx +0 -502
- package/src/hotspot/__tests__/rectangle.test.jsx +0 -418
- package/src/hotspot/circle.jsx +0 -154
- package/src/hotspot/container.jsx +0 -297
- package/src/hotspot/icons.js +0 -7
- package/src/hotspot/image-konva-tooltip.jsx +0 -76
- package/src/hotspot/index.jsx +0 -179
- package/src/hotspot/polygon.jsx +0 -197
- package/src/hotspot/rectangle.jsx +0 -172
- package/src/index.js +0 -227
- package/src/session-updater.js +0 -29
package/src/hotspot/index.jsx
DELETED
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import ReactDOM from 'react-dom';
|
|
3
|
-
import PropTypes from 'prop-types';
|
|
4
|
-
import CorrectAnswerToggle from '@pie-lib/correct-answer-toggle';
|
|
5
|
-
import { color, Collapsible, hasText, PreviewPrompt, UiLayout, hasMedia } from '@pie-lib/render-ui';
|
|
6
|
-
import { renderMath } from '@pie-lib/math-rendering';
|
|
7
|
-
import { styled } from '@mui/material/styles';
|
|
8
|
-
|
|
9
|
-
import Container from './container';
|
|
10
|
-
|
|
11
|
-
const StyledUiLayout = styled(UiLayout)({
|
|
12
|
-
color: color.text(),
|
|
13
|
-
backgroundColor: color.background(),
|
|
14
|
-
position: 'relative',
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
const StyledCollapsible = styled(Collapsible)(({ theme }) => ({
|
|
18
|
-
marginBottom: theme.spacing(2),
|
|
19
|
-
}));
|
|
20
|
-
|
|
21
|
-
class HotspotComponent extends React.Component {
|
|
22
|
-
constructor(props) {
|
|
23
|
-
super(props);
|
|
24
|
-
this.state = {
|
|
25
|
-
showCorrect: false,
|
|
26
|
-
observer: null,
|
|
27
|
-
scale: 1,
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
componentDidMount() {
|
|
32
|
-
this.observer = new MutationObserver((mutations) => {
|
|
33
|
-
mutations.forEach(() => {
|
|
34
|
-
const target = document.getElementById('question-container')?.style?.cssText;
|
|
35
|
-
const zoom = target?.substring(target.indexOf('--pie-zoom') + 11, target.lastIndexOf('%'));
|
|
36
|
-
const zoomParsed = zoom?.replace(/\s/g, '');
|
|
37
|
-
|
|
38
|
-
if (zoomParsed) {
|
|
39
|
-
const newScale = parseFloat(zoomParsed) / 100;
|
|
40
|
-
|
|
41
|
-
if (newScale !== this.state.scale) {
|
|
42
|
-
this.setState({
|
|
43
|
-
scale: parseFloat(zoomParsed) / 100,
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
} else if (!zoomParsed && this.state.scale !== 1) {
|
|
47
|
-
this.setState({
|
|
48
|
-
scale: 1,
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
const target = document.getElementById('question-container');
|
|
55
|
-
|
|
56
|
-
if (target) {
|
|
57
|
-
this.observer.observe(target, { attributes: true, attributeFilter: ['style'] });
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
// eslint-disable-next-line react/no-find-dom-node
|
|
61
|
-
const domNode = ReactDOM.findDOMNode(this);
|
|
62
|
-
|
|
63
|
-
renderMath(domNode);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
componentDidUpdate() {
|
|
67
|
-
// eslint-disable-next-line react/no-find-dom-node
|
|
68
|
-
const domNode = ReactDOM.findDOMNode(this);
|
|
69
|
-
|
|
70
|
-
renderMath(domNode);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
componentWillUnmount() {
|
|
74
|
-
this.observer?.disconnect();
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
onToggle = () => {
|
|
78
|
-
const { showCorrect } = this.state;
|
|
79
|
-
this.setState({ showCorrect: !showCorrect });
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
render() {
|
|
83
|
-
const {
|
|
84
|
-
session,
|
|
85
|
-
model: {
|
|
86
|
-
disabled,
|
|
87
|
-
extraCSSRules,
|
|
88
|
-
imageUrl,
|
|
89
|
-
prompt,
|
|
90
|
-
mode,
|
|
91
|
-
multipleCorrect,
|
|
92
|
-
shapes,
|
|
93
|
-
outlineColor,
|
|
94
|
-
hotspotColor,
|
|
95
|
-
hoverOutlineColor,
|
|
96
|
-
selectedHotspotColor,
|
|
97
|
-
dimensions,
|
|
98
|
-
rationale,
|
|
99
|
-
teacherInstructions,
|
|
100
|
-
strokeWidth,
|
|
101
|
-
responseCorrect,
|
|
102
|
-
language,
|
|
103
|
-
fontSizeFactor,
|
|
104
|
-
autoplayAudioEnabled,
|
|
105
|
-
customAudioButton,
|
|
106
|
-
},
|
|
107
|
-
onSelectChoice,
|
|
108
|
-
} = this.props;
|
|
109
|
-
const { showCorrect } = this.state;
|
|
110
|
-
const isEvaluateMode = mode === 'evaluate';
|
|
111
|
-
const isGatherMode = mode === 'gather';
|
|
112
|
-
const showCorrectAnswerToggle = isEvaluateMode && !responseCorrect;
|
|
113
|
-
const showRationale = rationale && (hasText(rationale) || hasMedia(rationale));
|
|
114
|
-
const showTeacherInstructions =
|
|
115
|
-
teacherInstructions && (hasText(teacherInstructions) || hasMedia(teacherInstructions));
|
|
116
|
-
|
|
117
|
-
return (
|
|
118
|
-
<StyledUiLayout extraCSSRules={extraCSSRules} id={'main-container'} fontSizeFactor={fontSizeFactor}>
|
|
119
|
-
{showTeacherInstructions && (
|
|
120
|
-
<StyledCollapsible labels={{ hidden: 'Show Teacher Instructions', visible: 'Hide Teacher Instructions' }}>
|
|
121
|
-
<PreviewPrompt className="prompt" prompt={teacherInstructions} />
|
|
122
|
-
</StyledCollapsible>
|
|
123
|
-
)}
|
|
124
|
-
|
|
125
|
-
{prompt && (
|
|
126
|
-
<PreviewPrompt
|
|
127
|
-
className="prompt"
|
|
128
|
-
prompt={prompt}
|
|
129
|
-
autoplayAudioEnabled={autoplayAudioEnabled}
|
|
130
|
-
customAudioButton={customAudioButton}
|
|
131
|
-
/>
|
|
132
|
-
)}
|
|
133
|
-
|
|
134
|
-
{showCorrectAnswerToggle && (
|
|
135
|
-
<CorrectAnswerToggle
|
|
136
|
-
show={showCorrectAnswerToggle}
|
|
137
|
-
toggled={showCorrect}
|
|
138
|
-
onToggle={this.onToggle.bind(this)}
|
|
139
|
-
language={language}
|
|
140
|
-
/>
|
|
141
|
-
)}
|
|
142
|
-
|
|
143
|
-
{imageUrl ? (
|
|
144
|
-
<Container
|
|
145
|
-
isEvaluateMode={isEvaluateMode}
|
|
146
|
-
session={session}
|
|
147
|
-
dimensions={dimensions}
|
|
148
|
-
imageUrl={imageUrl}
|
|
149
|
-
hotspotColor={hotspotColor}
|
|
150
|
-
hoverOutlineColor={isGatherMode ? hoverOutlineColor : undefined}
|
|
151
|
-
selectedHotspotColor={selectedHotspotColor}
|
|
152
|
-
multipleCorrect={multipleCorrect}
|
|
153
|
-
outlineColor={outlineColor}
|
|
154
|
-
onSelectChoice={onSelectChoice}
|
|
155
|
-
shapes={shapes}
|
|
156
|
-
disabled={disabled}
|
|
157
|
-
strokeWidth={strokeWidth}
|
|
158
|
-
scale={this.state.scale}
|
|
159
|
-
showCorrect={showCorrect}
|
|
160
|
-
/>
|
|
161
|
-
) : null}
|
|
162
|
-
|
|
163
|
-
{showRationale && (
|
|
164
|
-
<Collapsible labels={{ hidden: 'Show Rationale', visible: 'Hide Rationale' }}>
|
|
165
|
-
<PreviewPrompt className="prompt" prompt={rationale} />
|
|
166
|
-
</Collapsible>
|
|
167
|
-
)}
|
|
168
|
-
</StyledUiLayout>
|
|
169
|
-
);
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
HotspotComponent.propTypes = {
|
|
174
|
-
model: PropTypes.object.isRequired,
|
|
175
|
-
onSelectChoice: PropTypes.func.isRequired,
|
|
176
|
-
session: PropTypes.object.isRequired,
|
|
177
|
-
};
|
|
178
|
-
|
|
179
|
-
export default HotspotComponent;
|
package/src/hotspot/polygon.jsx
DELETED
|
@@ -1,197 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
3
|
-
import { Line, Group, Rect } from 'react-konva';
|
|
4
|
-
import ImageComponent from './image-konva-tooltip';
|
|
5
|
-
import { faCorrect, faWrong } from './icons';
|
|
6
|
-
|
|
7
|
-
class PolygonComponent extends React.Component {
|
|
8
|
-
constructor(props) {
|
|
9
|
-
super(props);
|
|
10
|
-
this.state = {
|
|
11
|
-
hovered: false,
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
getPolygonCenter = (points) => {
|
|
16
|
-
const x = points.map(({ x }) => x);
|
|
17
|
-
const y = points.map(({ y }) => y);
|
|
18
|
-
const minX = Math.min.apply(null, x);
|
|
19
|
-
const maxX = Math.max.apply(null, x);
|
|
20
|
-
const minY = Math.min.apply(null, y);
|
|
21
|
-
const maxY = Math.max.apply(null, y);
|
|
22
|
-
return [(minX + maxX) / 2, (minY + maxY) / 2];
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
parsePointsForKonva = (points) => {
|
|
26
|
-
const parsedPoints = [];
|
|
27
|
-
points.forEach(({ x, y }) => {
|
|
28
|
-
parsedPoints.push(x);
|
|
29
|
-
parsedPoints.push(y);
|
|
30
|
-
});
|
|
31
|
-
return parsedPoints;
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
handleClick = (e) => {
|
|
35
|
-
const { onClick, id, selected, disabled } = this.props;
|
|
36
|
-
|
|
37
|
-
if (!disabled) {
|
|
38
|
-
e.cancelBubble = true;
|
|
39
|
-
onClick({ id, selected: !selected, selector: 'Mouse' });
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
handleMouseEnter = () => {
|
|
44
|
-
const { disabled } = this.props;
|
|
45
|
-
|
|
46
|
-
if (!disabled) {
|
|
47
|
-
document.body.style.cursor = 'pointer';
|
|
48
|
-
}
|
|
49
|
-
this.setState({ hovered: true });
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
handleMouseLeave = () => {
|
|
53
|
-
document.body.style.cursor = 'default';
|
|
54
|
-
this.setState({ hovered: false });
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
getEvaluateOutlineColor = (isCorrect, markAsCorrect, outlineColor) =>
|
|
58
|
-
markAsCorrect ? 'green' : isCorrect ? outlineColor : 'red';
|
|
59
|
-
|
|
60
|
-
getOutlineWidth = (showCorrectEnabled, selected, markAsCorrect, strokeWidth) =>
|
|
61
|
-
markAsCorrect || (!markAsCorrect && !showCorrectEnabled && selected) ? strokeWidth : 0;
|
|
62
|
-
|
|
63
|
-
render() {
|
|
64
|
-
const {
|
|
65
|
-
hotspotColor,
|
|
66
|
-
isCorrect,
|
|
67
|
-
isEvaluateMode,
|
|
68
|
-
hoverOutlineColor,
|
|
69
|
-
outlineColor,
|
|
70
|
-
selected,
|
|
71
|
-
focused,
|
|
72
|
-
points,
|
|
73
|
-
evaluateText,
|
|
74
|
-
strokeWidth,
|
|
75
|
-
scale,
|
|
76
|
-
markAsCorrect,
|
|
77
|
-
selectedHotspotColor,
|
|
78
|
-
showCorrectEnabled,
|
|
79
|
-
} = this.props;
|
|
80
|
-
|
|
81
|
-
const { hovered } = this.state;
|
|
82
|
-
|
|
83
|
-
const outlineColorParsed = isEvaluateMode
|
|
84
|
-
? this.getEvaluateOutlineColor(isCorrect, markAsCorrect, outlineColor)
|
|
85
|
-
: outlineColor;
|
|
86
|
-
const outlineWidth = this.getOutlineWidth(showCorrectEnabled, selected, markAsCorrect, strokeWidth);
|
|
87
|
-
|
|
88
|
-
const pointsParsed = this.parsePointsForKonva(points);
|
|
89
|
-
const center = this.getPolygonCenter(points);
|
|
90
|
-
const iconX = center[0];
|
|
91
|
-
const iconY = center[1];
|
|
92
|
-
|
|
93
|
-
// "Show Correct Answer" Enabled:
|
|
94
|
-
// - Correctly Selected: white checkmark in green circle
|
|
95
|
-
// - Correctly Not Selected: none
|
|
96
|
-
// - Incorrectly Selected: none
|
|
97
|
-
// - Incorrectly Not Selected: white checkmark in green circle
|
|
98
|
-
// "Show Correct Answer" Disabled:
|
|
99
|
-
// - Correctly Selected:
|
|
100
|
-
// - white checkmark in green circle
|
|
101
|
-
// - heavy outline, as on “Gather”
|
|
102
|
-
// - Correctly Not Selected: none
|
|
103
|
-
// - Incorrectly Selected:
|
|
104
|
-
// - white "X" in red circle
|
|
105
|
-
// - heavy outline around the selection should appear in red
|
|
106
|
-
// - Incorrectly Not Selected: white "X" in red circle
|
|
107
|
-
let iconSrc;
|
|
108
|
-
|
|
109
|
-
if (showCorrectEnabled) {
|
|
110
|
-
if ((selected && isCorrect) || (!selected && !isCorrect)) {
|
|
111
|
-
iconSrc = faCorrect;
|
|
112
|
-
}
|
|
113
|
-
} else {
|
|
114
|
-
if (selected) {
|
|
115
|
-
if (isCorrect) {
|
|
116
|
-
iconSrc = faCorrect;
|
|
117
|
-
} else {
|
|
118
|
-
iconSrc = faWrong;
|
|
119
|
-
}
|
|
120
|
-
} else if (!isCorrect) {
|
|
121
|
-
iconSrc = faWrong;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
const useHoveredStyle = (hovered || focused) && hoverOutlineColor;
|
|
125
|
-
|
|
126
|
-
const xValues = pointsParsed.filter((_, index) => index % 2 === 0); // Even indices are x-coordinates
|
|
127
|
-
const yValues = pointsParsed.filter((_, index) => index % 2 !== 0); // Odd indices are y-coordinates
|
|
128
|
-
|
|
129
|
-
const minX = Math.min(...xValues);
|
|
130
|
-
const maxX = Math.max(...xValues);
|
|
131
|
-
const minY = Math.min(...yValues);
|
|
132
|
-
const maxY = Math.max(...yValues);
|
|
133
|
-
|
|
134
|
-
const rectX = minX;
|
|
135
|
-
const rectY = minY;
|
|
136
|
-
const rectWidth = maxX - minX;
|
|
137
|
-
const rectHeight = maxY - minY;
|
|
138
|
-
|
|
139
|
-
return (
|
|
140
|
-
<Group scaleX={scale} scaleY={scale} onMouseEnter={this.handleMouseEnter} onMouseLeave={this.handleMouseLeave}>
|
|
141
|
-
<Line
|
|
142
|
-
points={pointsParsed}
|
|
143
|
-
closed={true}
|
|
144
|
-
fill={selected && selectedHotspotColor ? selectedHotspotColor : hotspotColor}
|
|
145
|
-
onClick={this.handleClick}
|
|
146
|
-
onTap={this.handleClick}
|
|
147
|
-
draggable={false}
|
|
148
|
-
stroke={useHoveredStyle && !selected ? 'transparent' : outlineColorParsed}
|
|
149
|
-
strokeWidth={useHoveredStyle && !selected ? 0 : outlineWidth}
|
|
150
|
-
cursor="pointer"
|
|
151
|
-
position="relative"
|
|
152
|
-
/>
|
|
153
|
-
{useHoveredStyle && (
|
|
154
|
-
<Rect
|
|
155
|
-
x={rectX}
|
|
156
|
-
y={rectY}
|
|
157
|
-
width={rectWidth}
|
|
158
|
-
height={rectHeight}
|
|
159
|
-
stroke={hoverOutlineColor}
|
|
160
|
-
strokeWidth={strokeWidth}
|
|
161
|
-
listening={false}
|
|
162
|
-
/>
|
|
163
|
-
)}
|
|
164
|
-
{isEvaluateMode && iconSrc ? <ImageComponent src={iconSrc} x={iconX} y={iconY} tooltip={evaluateText} /> : null}
|
|
165
|
-
</Group>
|
|
166
|
-
);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
PolygonComponent.propTypes = {
|
|
171
|
-
hotspotColor: PropTypes.string.isRequired,
|
|
172
|
-
id: PropTypes.string.isRequired,
|
|
173
|
-
isCorrect: PropTypes.bool.isRequired,
|
|
174
|
-
isEvaluateMode: PropTypes.bool.isRequired,
|
|
175
|
-
hoverOutlineColor: PropTypes.string,
|
|
176
|
-
disabled: PropTypes.bool.isRequired,
|
|
177
|
-
focused: PropTypes.bool,
|
|
178
|
-
onClick: PropTypes.func.isRequired,
|
|
179
|
-
outlineColor: PropTypes.string.isRequired,
|
|
180
|
-
points: PropTypes.array.isRequired,
|
|
181
|
-
selected: PropTypes.bool.isRequired,
|
|
182
|
-
evaluateText: PropTypes.string,
|
|
183
|
-
selectedHotspotColor: PropTypes.string,
|
|
184
|
-
strokeWidth: PropTypes.number,
|
|
185
|
-
scale: PropTypes.number,
|
|
186
|
-
markAsCorrect: PropTypes.bool.isRequired,
|
|
187
|
-
showCorrectEnabled: PropTypes.bool.isRequired,
|
|
188
|
-
};
|
|
189
|
-
|
|
190
|
-
PolygonComponent.defaultProps = {
|
|
191
|
-
evaluateText: null,
|
|
192
|
-
focused: false,
|
|
193
|
-
strokeWidth: 5,
|
|
194
|
-
scale: 1,
|
|
195
|
-
};
|
|
196
|
-
|
|
197
|
-
export default PolygonComponent;
|
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
3
|
-
import { Rect, Group } from 'react-konva';
|
|
4
|
-
import ImageComponent from './image-konva-tooltip';
|
|
5
|
-
import { faCorrect, faWrong } from './icons';
|
|
6
|
-
|
|
7
|
-
class RectComponent extends React.Component {
|
|
8
|
-
constructor(props) {
|
|
9
|
-
super(props);
|
|
10
|
-
this.state = {
|
|
11
|
-
hovered: false,
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
handleClick = (e) => {
|
|
16
|
-
const { onClick, id, selected, disabled } = this.props;
|
|
17
|
-
|
|
18
|
-
if (!disabled) {
|
|
19
|
-
e.cancelBubble = true;
|
|
20
|
-
onClick({ id, selected: !selected, selector: 'Mouse' });
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
handleMouseEnter = () => {
|
|
25
|
-
const { disabled } = this.props;
|
|
26
|
-
|
|
27
|
-
if (!disabled) {
|
|
28
|
-
document.body.style.cursor = 'pointer';
|
|
29
|
-
}
|
|
30
|
-
this.setState({ hovered: true });
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
handleMouseLeave = () => {
|
|
34
|
-
document.body.style.cursor = 'default';
|
|
35
|
-
this.setState({ hovered: false });
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
getEvaluateOutlineColor = (isCorrect, markAsCorrect, outlineColor) =>
|
|
39
|
-
markAsCorrect ? 'green' : isCorrect ? outlineColor : 'red';
|
|
40
|
-
|
|
41
|
-
getOutlineWidth = (showCorrectEnabled, selected, markAsCorrect, strokeWidth) =>
|
|
42
|
-
markAsCorrect || (!markAsCorrect && !showCorrectEnabled && selected) ? strokeWidth : 0;
|
|
43
|
-
|
|
44
|
-
render() {
|
|
45
|
-
const {
|
|
46
|
-
height,
|
|
47
|
-
hotspotColor,
|
|
48
|
-
hoverOutlineColor,
|
|
49
|
-
selectedHotspotColor,
|
|
50
|
-
isCorrect,
|
|
51
|
-
isEvaluateMode,
|
|
52
|
-
outlineColor,
|
|
53
|
-
selected,
|
|
54
|
-
focused,
|
|
55
|
-
width,
|
|
56
|
-
x,
|
|
57
|
-
y,
|
|
58
|
-
evaluateText,
|
|
59
|
-
strokeWidth,
|
|
60
|
-
scale,
|
|
61
|
-
markAsCorrect,
|
|
62
|
-
showCorrectEnabled,
|
|
63
|
-
} = this.props;
|
|
64
|
-
const { hovered } = this.state;
|
|
65
|
-
|
|
66
|
-
const outlineColorParsed = isEvaluateMode
|
|
67
|
-
? this.getEvaluateOutlineColor(isCorrect, markAsCorrect, outlineColor)
|
|
68
|
-
: outlineColor;
|
|
69
|
-
|
|
70
|
-
const outlineWidth = this.getOutlineWidth(showCorrectEnabled, selected, markAsCorrect, strokeWidth);
|
|
71
|
-
|
|
72
|
-
const iconX = x + width / 2 - 10;
|
|
73
|
-
const iconY = y + height / 2 - 10;
|
|
74
|
-
|
|
75
|
-
// "Show Correct Answer" Enabled:
|
|
76
|
-
// - Correctly Selected: white checkmark in green circle
|
|
77
|
-
// - Correctly Not Selected: none
|
|
78
|
-
// - Incorrectly Selected: none
|
|
79
|
-
// - Incorrectly Not Selected: white checkmark in green circle
|
|
80
|
-
// "Show Correct Answer" Disabled:
|
|
81
|
-
// - Correctly Selected:
|
|
82
|
-
// - white checkmark in green circle
|
|
83
|
-
// - heavy outline, as on “Gather”
|
|
84
|
-
// - Correctly Not Selected: none
|
|
85
|
-
// - Incorrectly Selected:
|
|
86
|
-
// - white "X" in red circle
|
|
87
|
-
// - heavy outline around the selection should appear in red
|
|
88
|
-
// - Incorrectly Not Selected: white "X" in red circle
|
|
89
|
-
let iconSrc;
|
|
90
|
-
|
|
91
|
-
if (showCorrectEnabled) {
|
|
92
|
-
if ((selected && isCorrect) || (!selected && !isCorrect)) {
|
|
93
|
-
iconSrc = faCorrect;
|
|
94
|
-
}
|
|
95
|
-
} else {
|
|
96
|
-
if (selected) {
|
|
97
|
-
if (isCorrect) {
|
|
98
|
-
iconSrc = faCorrect;
|
|
99
|
-
} else {
|
|
100
|
-
iconSrc = faWrong;
|
|
101
|
-
}
|
|
102
|
-
} else if (!isCorrect) {
|
|
103
|
-
iconSrc = faWrong;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
const useHoveredStyle = (hovered || focused) && hoverOutlineColor;
|
|
108
|
-
|
|
109
|
-
return (
|
|
110
|
-
<Group scaleX={scale} scaleY={scale} onMouseLeave={this.handleMouseLeave} onMouseEnter={this.handleMouseEnter}>
|
|
111
|
-
<Rect
|
|
112
|
-
x={x}
|
|
113
|
-
y={y}
|
|
114
|
-
width={width}
|
|
115
|
-
height={height}
|
|
116
|
-
fill={selected && selectedHotspotColor ? selectedHotspotColor : hotspotColor}
|
|
117
|
-
onClick={this.handleClick}
|
|
118
|
-
onTap={this.handleClick}
|
|
119
|
-
draggable={false}
|
|
120
|
-
stroke={useHoveredStyle && !selected ? 'transparent' : outlineColorParsed}
|
|
121
|
-
strokeWidth={useHoveredStyle && !selected ? 0 : outlineWidth}
|
|
122
|
-
cursor="pointer"
|
|
123
|
-
/>
|
|
124
|
-
{useHoveredStyle && (
|
|
125
|
-
<Rect
|
|
126
|
-
x={x}
|
|
127
|
-
y={y}
|
|
128
|
-
width={width}
|
|
129
|
-
height={height}
|
|
130
|
-
stroke={hoverOutlineColor}
|
|
131
|
-
strokeWidth={strokeWidth}
|
|
132
|
-
listening={false}
|
|
133
|
-
/>
|
|
134
|
-
)}
|
|
135
|
-
{isEvaluateMode && iconSrc ? <ImageComponent src={iconSrc} x={iconX} y={iconY} tooltip={evaluateText} /> : null}
|
|
136
|
-
</Group>
|
|
137
|
-
);
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
RectComponent.propTypes = {
|
|
142
|
-
height: PropTypes.number.isRequired,
|
|
143
|
-
hotspotColor: PropTypes.string.isRequired,
|
|
144
|
-
id: PropTypes.string.isRequired,
|
|
145
|
-
isCorrect: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]),
|
|
146
|
-
isEvaluateMode: PropTypes.bool.isRequired,
|
|
147
|
-
hoverOutlineColor: PropTypes.string,
|
|
148
|
-
disabled: PropTypes.bool.isRequired,
|
|
149
|
-
focused: PropTypes.bool,
|
|
150
|
-
onClick: PropTypes.func.isRequired,
|
|
151
|
-
outlineColor: PropTypes.string.isRequired,
|
|
152
|
-
selected: PropTypes.bool.isRequired,
|
|
153
|
-
width: PropTypes.number.isRequired,
|
|
154
|
-
x: PropTypes.number.isRequired,
|
|
155
|
-
y: PropTypes.number.isRequired,
|
|
156
|
-
evaluateText: PropTypes.string,
|
|
157
|
-
strokeWidth: PropTypes.number,
|
|
158
|
-
scale: PropTypes.number,
|
|
159
|
-
selectedHotspotColor: PropTypes.string,
|
|
160
|
-
markAsCorrect: PropTypes.bool.isRequired,
|
|
161
|
-
showCorrectEnabled: PropTypes.bool.isRequired,
|
|
162
|
-
};
|
|
163
|
-
|
|
164
|
-
RectComponent.defaultProps = {
|
|
165
|
-
isCorrect: false,
|
|
166
|
-
evaluateText: null,
|
|
167
|
-
focused: false,
|
|
168
|
-
strokeWidth: 5,
|
|
169
|
-
scale: 1,
|
|
170
|
-
};
|
|
171
|
-
|
|
172
|
-
export default RectComponent;
|