@pie-element/hotspot 5.4.3-next.5 → 5.4.3-next.57
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/button.js.map +1 -1
- package/configure/lib/defaults.js.map +1 -1
- package/configure/lib/hotspot-container.js.map +1 -1
- package/configure/lib/hotspot-drawable.js.map +1 -1
- package/configure/lib/hotspot-palette.js.map +1 -1
- package/configure/lib/hotspot-polygon.js.map +1 -1
- package/configure/lib/hotspot-rectangle.js.map +1 -1
- package/configure/lib/index.js.map +1 -1
- package/configure/lib/root.js +1 -1
- package/configure/lib/root.js.map +1 -1
- package/configure/lib/upload-control.js.map +1 -1
- package/configure/lib/utils.js.map +1 -1
- package/configure/package.json +2 -2
- package/configure/src/__tests__/hotspot-container.test.js +98 -71
- package/configure/src/__tests__/hotspot-drawable.test.js +48 -49
- package/configure/src/__tests__/index.test.js +28 -51
- package/configure/src/__tests__/root.test.js +162 -82
- package/configure/src/__tests__/utils.test.js +112 -98
- package/configure/src/button.jsx +4 -4
- package/configure/src/defaults.js +16 -20
- package/configure/src/hotspot-container.jsx +72 -89
- package/configure/src/hotspot-drawable.jsx +55 -55
- package/configure/src/hotspot-palette.jsx +12 -25
- package/configure/src/hotspot-polygon.jsx +20 -22
- package/configure/src/hotspot-rectangle.jsx +5 -15
- package/configure/src/index.js +20 -20
- package/configure/src/root.jsx +38 -67
- package/configure/src/upload-control.jsx +9 -20
- package/configure/src/utils.js +35 -28
- package/controller/lib/defaults.js.map +1 -1
- package/controller/lib/index.js.map +1 -1
- package/controller/lib/utils.js.map +1 -1
- package/controller/package.json +1 -1
- package/controller/src/__tests__/index.test.js +29 -50
- package/controller/src/defaults.js +4 -8
- package/controller/src/index.js +22 -34
- package/controller/src/utils.js +9 -6
- package/docs/config-schema.json.md +1 -1
- package/docs/demo/config.js +2 -2
- package/docs/demo/generate.js +49 -37
- package/docs/demo/session.js +2 -2
- package/docs/pie-schema.json.md +1 -1
- package/lib/hotspot/container.js.map +1 -1
- package/lib/hotspot/icons.js.map +1 -1
- package/lib/hotspot/image.js.map +1 -1
- package/lib/hotspot/index.js.map +1 -1
- package/lib/hotspot/polygon.js.map +1 -1
- package/lib/hotspot/rectangle.js.map +1 -1
- package/lib/index.js.map +1 -1
- package/lib/session-updater.js.map +1 -1
- package/package.json +6 -6
- package/src/__tests__/container.test.jsx +57 -43
- package/src/__tests__/image.test.jsx +2 -2
- package/src/__tests__/polygon.test.jsx +31 -20
- package/src/__tests__/rectangle.test.jsx +22 -18
- package/src/__tests__/session-updater.test.jsx +22 -31
- package/src/hotspot/container.jsx +20 -23
- package/src/hotspot/icons.js +4 -2
- package/src/hotspot/image.jsx +4 -8
- package/src/hotspot/index.jsx +27 -47
- package/src/hotspot/polygon.jsx +13 -18
- package/src/hotspot/rectangle.jsx +11 -16
- package/src/index.js +5 -18
- package/src/session-updater.js +1 -1
|
@@ -19,7 +19,7 @@ export class Container extends Component {
|
|
|
19
19
|
return {
|
|
20
20
|
...prevState,
|
|
21
21
|
shapes: getAllShapes(nextProps.shapes),
|
|
22
|
-
}
|
|
22
|
+
};
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
constructor(props) {
|
|
@@ -28,8 +28,8 @@ export class Container extends Component {
|
|
|
28
28
|
this.state = {
|
|
29
29
|
dragEnabled: true,
|
|
30
30
|
// always transform shapes map into shapes array at this level
|
|
31
|
-
shapes: getAllShapes(props.shapes)
|
|
32
|
-
}
|
|
31
|
+
shapes: getAllShapes(props.shapes),
|
|
32
|
+
};
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
handleFileRead = (file) => {
|
|
@@ -38,7 +38,7 @@ export class Container extends Component {
|
|
|
38
38
|
const reader = new FileReader();
|
|
39
39
|
|
|
40
40
|
reader.onloadend = () => onImageUpload(reader.result);
|
|
41
|
-
reader.readAsDataURL(file)
|
|
41
|
+
reader.readAsDataURL(file);
|
|
42
42
|
}
|
|
43
43
|
};
|
|
44
44
|
|
|
@@ -92,13 +92,13 @@ export class Container extends Component {
|
|
|
92
92
|
this.disableDropzone();
|
|
93
93
|
};
|
|
94
94
|
|
|
95
|
-
onUpdateShapes = newShapes => {
|
|
95
|
+
onUpdateShapes = (newShapes) => {
|
|
96
96
|
const { onUpdateShapes } = this.props;
|
|
97
97
|
|
|
98
98
|
this.setState(
|
|
99
99
|
{ shapes: newShapes },
|
|
100
100
|
// always transform shapes array back into shapes map when saving changes
|
|
101
|
-
() => onUpdateShapes(groupShapes(newShapes))
|
|
101
|
+
() => onUpdateShapes(groupShapes(newShapes)),
|
|
102
102
|
);
|
|
103
103
|
};
|
|
104
104
|
|
|
@@ -107,7 +107,7 @@ export class Container extends Component {
|
|
|
107
107
|
|
|
108
108
|
if (shapes && shapes.length) {
|
|
109
109
|
// sort by index value
|
|
110
|
-
let newShapes = shapes.sort((a, b) =>
|
|
110
|
+
let newShapes = shapes.sort((a, b) => parseInt(a.index) - parseInt(b.index));
|
|
111
111
|
|
|
112
112
|
newShapes = newShapes ? newShapes.slice(0, newShapes.length - 1) : [];
|
|
113
113
|
|
|
@@ -133,25 +133,24 @@ export class Container extends Component {
|
|
|
133
133
|
onUpdateImageDimension,
|
|
134
134
|
outlineColor,
|
|
135
135
|
strokeWidth,
|
|
136
|
-
preserveAspectRatioEnabled
|
|
136
|
+
preserveAspectRatioEnabled,
|
|
137
137
|
} = this.props;
|
|
138
|
-
const {
|
|
139
|
-
dropzoneActive,
|
|
140
|
-
dragEnabled,
|
|
141
|
-
showTooltip
|
|
142
|
-
} = this.state;
|
|
138
|
+
const { dropzoneActive, dragEnabled, showTooltip } = this.state;
|
|
143
139
|
const { shapes } = this.state;
|
|
144
140
|
|
|
145
141
|
return (
|
|
146
142
|
<div className={classes.base}>
|
|
147
|
-
<div
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
143
|
+
<div
|
|
144
|
+
className={`${classes.box} ${dropzoneActive ? classes.boxActive : ''}`}
|
|
145
|
+
{...(dragEnabled
|
|
146
|
+
? {
|
|
147
|
+
onDragExit: this.handleOnDragExit,
|
|
148
|
+
onDragLeave: this.handleOnDragExit,
|
|
149
|
+
onDragOver: this.handleOnDragOver,
|
|
150
|
+
onDrop: this.handleOnDrop,
|
|
151
|
+
onPaste: this.handleOnPaste,
|
|
152
|
+
}
|
|
153
|
+
: {})}
|
|
155
154
|
>
|
|
156
155
|
<div className={classes.toolbar}>
|
|
157
156
|
{imageUrl && (
|
|
@@ -166,54 +165,45 @@ export class Container extends Component {
|
|
|
166
165
|
}}
|
|
167
166
|
/>
|
|
168
167
|
)}
|
|
169
|
-
<Button
|
|
170
|
-
|
|
171
|
-
onClick={this.handleUndo}
|
|
172
|
-
label="Undo"
|
|
173
|
-
/>
|
|
174
|
-
<Button
|
|
175
|
-
disabled={!(shapes && shapes.length)}
|
|
176
|
-
onClick={this.handleClearAll}
|
|
177
|
-
label="Clear all"
|
|
178
|
-
/>
|
|
168
|
+
<Button disabled={!(shapes && shapes.length)} onClick={this.handleUndo} label="Undo" />
|
|
169
|
+
<Button disabled={!(shapes && shapes.length)} onClick={this.handleClearAll} label="Clear all" />
|
|
179
170
|
</div>
|
|
180
171
|
|
|
181
172
|
<div
|
|
182
|
-
ref={ref => {
|
|
173
|
+
ref={(ref) => {
|
|
183
174
|
this.imageSection = ref;
|
|
184
175
|
}}
|
|
185
|
-
className={classes.drawableHeight}
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
176
|
+
className={classes.drawableHeight}
|
|
177
|
+
>
|
|
178
|
+
{imageUrl ? (
|
|
179
|
+
<Drawable
|
|
180
|
+
dimensions={dimensions}
|
|
181
|
+
disableDrag={this.handleDisableDrag}
|
|
182
|
+
enableDrag={this.handleEnableDrag}
|
|
183
|
+
imageUrl={imageUrl}
|
|
184
|
+
hotspotColor={hotspotColor}
|
|
185
|
+
multipleCorrect={multipleCorrect}
|
|
186
|
+
onUpdateImageDimension={onUpdateImageDimension}
|
|
187
|
+
onUpdateShapes={this.onUpdateShapes}
|
|
188
|
+
outlineColor={outlineColor}
|
|
189
|
+
shapes={shapes}
|
|
190
|
+
strokeWidth={strokeWidth}
|
|
191
|
+
preserveAspectRatioEnabled={preserveAspectRatioEnabled}
|
|
192
|
+
/>
|
|
193
|
+
) : (
|
|
194
|
+
<div className={`${classes.drawableHeight} ${classes.centered}`}>
|
|
195
|
+
<label>Drag and drop or upload image from computer</label>
|
|
196
|
+
<br />
|
|
197
|
+
<UploadControl
|
|
198
|
+
label="Upload Image"
|
|
199
|
+
onInputClick={this.handleInputClick}
|
|
200
|
+
onUploadImage={this.handleUploadImage}
|
|
201
|
+
setRef={(ref) => {
|
|
202
|
+
this.input = ref;
|
|
203
|
+
}}
|
|
201
204
|
/>
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
<div className={`${classes.drawableHeight} ${classes.centered}`}>
|
|
205
|
-
<label>Drag and drop or upload image from computer</label>
|
|
206
|
-
<br/>
|
|
207
|
-
<UploadControl
|
|
208
|
-
label="Upload Image"
|
|
209
|
-
onInputClick={this.handleInputClick}
|
|
210
|
-
onUploadImage={this.handleUploadImage}
|
|
211
|
-
setRef={(ref) => {
|
|
212
|
-
this.input = ref;
|
|
213
|
-
}}
|
|
214
|
-
/>
|
|
215
|
-
</div>
|
|
216
|
-
)}
|
|
205
|
+
</div>
|
|
206
|
+
)}
|
|
217
207
|
</div>
|
|
218
208
|
|
|
219
209
|
{imageUrl && (
|
|
@@ -221,42 +211,36 @@ export class Container extends Component {
|
|
|
221
211
|
{showTooltip && (
|
|
222
212
|
<div className={classes.tooltipContent}>
|
|
223
213
|
<label>
|
|
224
|
-
Click and drag to create a hotspot. Click the hotspot to mark correct. Click
|
|
225
|
-
again to unmark.
|
|
214
|
+
Click and drag to create a hotspot. Click the hotspot to mark correct. Click again to unmark.
|
|
226
215
|
</label>
|
|
227
|
-
<div className={classes.tooltipArrow}/>
|
|
216
|
+
<div className={classes.tooltipArrow} />
|
|
228
217
|
</div>
|
|
229
218
|
)}
|
|
230
|
-
<Help
|
|
231
|
-
className={classes.icon}
|
|
232
|
-
onMouseOut={this.toggleTooltip}
|
|
233
|
-
onMouseOver={this.toggleTooltip}
|
|
234
|
-
/>
|
|
219
|
+
<Help className={classes.icon} onMouseOut={this.toggleTooltip} onMouseOver={this.toggleTooltip} />
|
|
235
220
|
</div>
|
|
236
221
|
)}
|
|
237
222
|
</div>
|
|
238
223
|
</div>
|
|
239
|
-
|
|
240
224
|
);
|
|
241
225
|
}
|
|
242
226
|
}
|
|
243
227
|
|
|
244
|
-
const styles = theme => ({
|
|
228
|
+
const styles = (theme) => ({
|
|
245
229
|
base: {
|
|
246
|
-
marginTop: theme.spacing.unit * 2
|
|
230
|
+
marginTop: theme.spacing.unit * 2,
|
|
247
231
|
},
|
|
248
232
|
box: {
|
|
249
233
|
border: '1px solid #E0E1E6',
|
|
250
|
-
borderRadius: '5px'
|
|
234
|
+
borderRadius: '5px',
|
|
251
235
|
},
|
|
252
236
|
boxActive: {
|
|
253
|
-
border: '1px solid #0032C2'
|
|
237
|
+
border: '1px solid #0032C2',
|
|
254
238
|
},
|
|
255
239
|
centered: {
|
|
256
240
|
alignItems: 'center',
|
|
257
241
|
display: 'flex',
|
|
258
242
|
flexDirection: 'column',
|
|
259
|
-
justifyContent: 'center'
|
|
243
|
+
justifyContent: 'center',
|
|
260
244
|
},
|
|
261
245
|
drawableHeight: {
|
|
262
246
|
minHeight: 350,
|
|
@@ -266,15 +250,15 @@ const styles = theme => ({
|
|
|
266
250
|
icon: {
|
|
267
251
|
'&:hover': {
|
|
268
252
|
color: '#333131',
|
|
269
|
-
cursor: 'help'
|
|
253
|
+
cursor: 'help',
|
|
270
254
|
},
|
|
271
|
-
color: '#C1C1C1'
|
|
255
|
+
color: '#C1C1C1',
|
|
272
256
|
},
|
|
273
257
|
replaceButton: {
|
|
274
258
|
marginLeft: 0,
|
|
275
259
|
},
|
|
276
260
|
replaceSection: {
|
|
277
|
-
marginRight: 'auto'
|
|
261
|
+
marginRight: 'auto',
|
|
278
262
|
},
|
|
279
263
|
toolbar: {
|
|
280
264
|
backgroundColor: '#ECEDF1',
|
|
@@ -283,12 +267,12 @@ const styles = theme => ({
|
|
|
283
267
|
borderTopRightRadius: '5px',
|
|
284
268
|
display: 'flex',
|
|
285
269
|
justifyContent: 'flex-end',
|
|
286
|
-
padding: '12px 8px'
|
|
270
|
+
padding: '12px 8px',
|
|
287
271
|
},
|
|
288
272
|
tooltip: {
|
|
289
273
|
position: 'relative',
|
|
290
274
|
textAlign: 'right',
|
|
291
|
-
padding: '5px 9px'
|
|
275
|
+
padding: '5px 9px',
|
|
292
276
|
},
|
|
293
277
|
tooltipContent: {
|
|
294
278
|
background: '#333131',
|
|
@@ -301,7 +285,7 @@ const styles = theme => ({
|
|
|
301
285
|
position: 'absolute',
|
|
302
286
|
right: '5px',
|
|
303
287
|
textAlign: 'left',
|
|
304
|
-
width: '300px'
|
|
288
|
+
width: '300px',
|
|
305
289
|
},
|
|
306
290
|
tooltipArrow: {
|
|
307
291
|
width: 0,
|
|
@@ -312,8 +296,8 @@ const styles = theme => ({
|
|
|
312
296
|
marginBottom: -10,
|
|
313
297
|
marginTop: '2px',
|
|
314
298
|
position: 'absolute',
|
|
315
|
-
right: '5px'
|
|
316
|
-
}
|
|
299
|
+
right: '5px',
|
|
300
|
+
},
|
|
317
301
|
});
|
|
318
302
|
|
|
319
303
|
Container.propTypes = {
|
|
@@ -328,14 +312,13 @@ Container.propTypes = {
|
|
|
328
312
|
outlineColor: PropTypes.string.isRequired,
|
|
329
313
|
shapes: PropTypes.shape({
|
|
330
314
|
rectangles: PropTypes.array,
|
|
331
|
-
polygons: PropTypes.array
|
|
315
|
+
polygons: PropTypes.array,
|
|
332
316
|
}).isRequired,
|
|
333
317
|
strokeWidth: PropTypes.number,
|
|
334
|
-
preserveAspectRatioEnabled: PropTypes.bool
|
|
318
|
+
preserveAspectRatioEnabled: PropTypes.bool,
|
|
335
319
|
};
|
|
336
320
|
Container.defaultProps = {
|
|
337
|
-
strokeWidth: 5
|
|
321
|
+
strokeWidth: 5,
|
|
338
322
|
};
|
|
339
323
|
|
|
340
|
-
|
|
341
324
|
export default withStyles(styles)(Container);
|
|
@@ -22,7 +22,7 @@ export class Drawable extends React.Component {
|
|
|
22
22
|
return {
|
|
23
23
|
...prevState,
|
|
24
24
|
dimensions: dimensions,
|
|
25
|
-
}
|
|
25
|
+
};
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
constructor(props) {
|
|
@@ -36,7 +36,7 @@ export class Drawable extends React.Component {
|
|
|
36
36
|
height: 0,
|
|
37
37
|
width: 0,
|
|
38
38
|
},
|
|
39
|
-
}
|
|
39
|
+
};
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
/// start of handling HotSpots section
|
|
@@ -45,7 +45,7 @@ export class Drawable extends React.Component {
|
|
|
45
45
|
const { onUpdateShapes, shapes } = this.props;
|
|
46
46
|
// Add a new rectangle at the mouse position with 0 width and height
|
|
47
47
|
const newShapes = shapes.slice();
|
|
48
|
-
const value = max(newShapes.map(c => parseInt(c.id)).filter(id => !isNaN(id))) || 0;
|
|
48
|
+
const value = max(newShapes.map((c) => parseInt(c.id)).filter((id) => !isNaN(id))) || 0;
|
|
49
49
|
|
|
50
50
|
newShapes.push({
|
|
51
51
|
id: `${value + 1}`,
|
|
@@ -54,7 +54,7 @@ export class Drawable extends React.Component {
|
|
|
54
54
|
x: e.evt.layerX,
|
|
55
55
|
y: e.evt.layerY,
|
|
56
56
|
group: 'rectangles',
|
|
57
|
-
index: shapes.length
|
|
57
|
+
index: shapes.length,
|
|
58
58
|
});
|
|
59
59
|
|
|
60
60
|
this.setState({ isDrawing: true, isDrawingShapeId: `${value + 1}` });
|
|
@@ -86,7 +86,7 @@ export class Drawable extends React.Component {
|
|
|
86
86
|
const mouseX = e.evt.layerX;
|
|
87
87
|
const mouseY = e.evt.layerY;
|
|
88
88
|
|
|
89
|
-
const currShapeIndex = shapes.findIndex(shape => shape.id === isDrawingShapeId);
|
|
89
|
+
const currShapeIndex = shapes.findIndex((shape) => shape.id === isDrawingShapeId);
|
|
90
90
|
const currShape = shapes[currShapeIndex];
|
|
91
91
|
|
|
92
92
|
if (currShape) {
|
|
@@ -100,7 +100,7 @@ export class Drawable extends React.Component {
|
|
|
100
100
|
height: newHeight,
|
|
101
101
|
width: newWidth,
|
|
102
102
|
x: currShape.x,
|
|
103
|
-
y: currShape.y
|
|
103
|
+
y: currShape.y,
|
|
104
104
|
};
|
|
105
105
|
|
|
106
106
|
// On mouse move don't trigger any event. Put the shapes on this state instead.
|
|
@@ -111,12 +111,12 @@ export class Drawable extends React.Component {
|
|
|
111
111
|
|
|
112
112
|
handleOnDragEnd = (id, updatedProps) => {
|
|
113
113
|
const { shapes, onUpdateShapes } = this.props;
|
|
114
|
-
const newShapes = shapes.map(shape => {
|
|
114
|
+
const newShapes = shapes.map((shape) => {
|
|
115
115
|
if (shape.id === id) {
|
|
116
116
|
return {
|
|
117
117
|
...shape,
|
|
118
|
-
...updatedProps
|
|
119
|
-
}
|
|
118
|
+
...updatedProps,
|
|
119
|
+
};
|
|
120
120
|
}
|
|
121
121
|
return shape;
|
|
122
122
|
});
|
|
@@ -131,17 +131,17 @@ export class Drawable extends React.Component {
|
|
|
131
131
|
let newShapes = [];
|
|
132
132
|
|
|
133
133
|
if (multipleCorrect) {
|
|
134
|
-
newShapes = shapes.map(shape => {
|
|
134
|
+
newShapes = shapes.map((shape) => {
|
|
135
135
|
if (shape.id === id) {
|
|
136
136
|
shape.correct = !shape.correct;
|
|
137
137
|
}
|
|
138
138
|
return shape;
|
|
139
|
-
})
|
|
139
|
+
});
|
|
140
140
|
} else {
|
|
141
|
-
newShapes = shapes.map(shape => {
|
|
141
|
+
newShapes = shapes.map((shape) => {
|
|
142
142
|
shape.correct = shape.id === id;
|
|
143
143
|
return shape;
|
|
144
|
-
})
|
|
144
|
+
});
|
|
145
145
|
}
|
|
146
146
|
|
|
147
147
|
onUpdateShapes(cloneDeep(newShapes));
|
|
@@ -157,17 +157,18 @@ export class Drawable extends React.Component {
|
|
|
157
157
|
const newWidth = parseFloat(elementStyle.width);
|
|
158
158
|
const aspectWidth = newWidth / IMAGE_MAX_WIDTH;
|
|
159
159
|
|
|
160
|
-
const dimensions =
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
160
|
+
const dimensions =
|
|
161
|
+
newWidth > IMAGE_MAX_WIDTH
|
|
162
|
+
? {
|
|
163
|
+
height: newHeight / aspectWidth,
|
|
164
|
+
width: IMAGE_MAX_WIDTH,
|
|
165
|
+
}
|
|
166
|
+
: {
|
|
167
|
+
height: newHeight,
|
|
168
|
+
width: newWidth,
|
|
169
|
+
};
|
|
167
170
|
|
|
168
|
-
this.setState(
|
|
169
|
-
{ dimensions },
|
|
170
|
-
() => onUpdateImageDimension(dimensions));
|
|
171
|
+
this.setState({ dimensions }, () => onUpdateImageDimension(dimensions));
|
|
171
172
|
|
|
172
173
|
resizeHandle.addEventListener('mousedown', this.initialiseResize, false);
|
|
173
174
|
};
|
|
@@ -182,34 +183,30 @@ export class Drawable extends React.Component {
|
|
|
182
183
|
let drawable = true;
|
|
183
184
|
|
|
184
185
|
// Do not allow resizing over the hotspots
|
|
185
|
-
shapes &&
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
186
|
+
shapes &&
|
|
187
|
+
shapes.forEach((shape) => {
|
|
188
|
+
const right = shape.x + shape.width + 5;
|
|
189
|
+
const bottom = shape.y + shape.height + 5;
|
|
190
|
+
if (x <= right || y <= bottom) {
|
|
191
|
+
drawable = false;
|
|
192
|
+
}
|
|
193
|
+
});
|
|
192
194
|
return drawable;
|
|
193
195
|
}
|
|
194
196
|
|
|
195
197
|
startResizing = (e) => {
|
|
196
198
|
const bounds = e.target.getBoundingClientRect();
|
|
197
199
|
const box = this.image;
|
|
198
|
-
const {
|
|
199
|
-
disableDrag,
|
|
200
|
-
preserveAspectRatioEnabled,
|
|
201
|
-
dimensions,
|
|
202
|
-
shapes
|
|
203
|
-
} = this.props;
|
|
200
|
+
const { disableDrag, preserveAspectRatioEnabled, dimensions, shapes } = this.props;
|
|
204
201
|
|
|
205
202
|
// todo previously we had state.dimensions, is it needed?
|
|
206
203
|
const { width, height } = updateImageDimensions(
|
|
207
204
|
dimensions,
|
|
208
205
|
{
|
|
209
206
|
width: e.clientX - bounds.left,
|
|
210
|
-
height: e.clientY - bounds.top
|
|
207
|
+
height: e.clientY - bounds.top,
|
|
211
208
|
},
|
|
212
|
-
preserveAspectRatioEnabled
|
|
209
|
+
preserveAspectRatioEnabled,
|
|
213
210
|
);
|
|
214
211
|
|
|
215
212
|
const resizeValid = this.checkIfResizeValid(width, height);
|
|
@@ -222,7 +219,7 @@ export class Drawable extends React.Component {
|
|
|
222
219
|
this.setState({
|
|
223
220
|
resizing: true,
|
|
224
221
|
dimensions: { height: height, width: width },
|
|
225
|
-
stateShapes: getUpdatedShapes(dimensions, { width, height }, shapes)
|
|
222
|
+
stateShapes: getUpdatedShapes(dimensions, { width, height }, shapes),
|
|
226
223
|
});
|
|
227
224
|
}
|
|
228
225
|
|
|
@@ -256,12 +253,12 @@ export class Drawable extends React.Component {
|
|
|
256
253
|
hotspotColor,
|
|
257
254
|
outlineColor,
|
|
258
255
|
shapes,
|
|
259
|
-
strokeWidth
|
|
256
|
+
strokeWidth,
|
|
260
257
|
} = this.props;
|
|
261
258
|
const {
|
|
262
259
|
stateShapes,
|
|
263
260
|
isDrawing,
|
|
264
|
-
dimensions: { height: heightFromState, width: widthFromState }
|
|
261
|
+
dimensions: { height: heightFromState, width: widthFromState },
|
|
265
262
|
} = this.state;
|
|
266
263
|
const shapesToUse = stateShapes || shapes;
|
|
267
264
|
|
|
@@ -272,15 +269,18 @@ export class Drawable extends React.Component {
|
|
|
272
269
|
<img
|
|
273
270
|
className={classes.image}
|
|
274
271
|
onLoad={this.handleOnImageLoad}
|
|
275
|
-
ref={ref => {
|
|
272
|
+
ref={(ref) => {
|
|
276
273
|
this.image = ref;
|
|
277
274
|
}}
|
|
278
275
|
src={imageUrl}
|
|
279
|
-
{...height && width ? { style: { height, width } } : {}}
|
|
276
|
+
{...(height && width ? { style: { height, width } } : {})}
|
|
277
|
+
/>
|
|
278
|
+
<div
|
|
279
|
+
ref={(ref) => {
|
|
280
|
+
this.resize = ref;
|
|
281
|
+
}}
|
|
282
|
+
className={classes.resize}
|
|
280
283
|
/>
|
|
281
|
-
<div ref={ref => {
|
|
282
|
-
this.resize = ref;
|
|
283
|
-
}} className={classes.resize}/>
|
|
284
284
|
</div>
|
|
285
285
|
)}
|
|
286
286
|
|
|
@@ -288,9 +288,9 @@ export class Drawable extends React.Component {
|
|
|
288
288
|
className={classes.stage}
|
|
289
289
|
height={heightFromState || height}
|
|
290
290
|
width={widthFromState || width}
|
|
291
|
-
onMouseDown={this.handleOnMouseDown
|
|
292
|
-
onMouseUp={this.handleOnMouseUp
|
|
293
|
-
onMouseMove={this.handleMouseMove
|
|
291
|
+
onMouseDown={this.handleOnMouseDown}
|
|
292
|
+
onMouseUp={this.handleOnMouseUp}
|
|
293
|
+
onMouseMove={this.handleMouseMove}
|
|
294
294
|
>
|
|
295
295
|
<Layer>
|
|
296
296
|
{shapesToUse.map((shape, index) => {
|
|
@@ -324,7 +324,7 @@ export class Drawable extends React.Component {
|
|
|
324
324
|
|
|
325
325
|
const styles = () => ({
|
|
326
326
|
base: {
|
|
327
|
-
position: 'relative'
|
|
327
|
+
position: 'relative',
|
|
328
328
|
},
|
|
329
329
|
image: {
|
|
330
330
|
alignItems: 'center',
|
|
@@ -333,7 +333,7 @@ const styles = () => ({
|
|
|
333
333
|
},
|
|
334
334
|
imageContainer: {
|
|
335
335
|
position: 'relative',
|
|
336
|
-
width: 'fit-content'
|
|
336
|
+
width: 'fit-content',
|
|
337
337
|
},
|
|
338
338
|
resize: {
|
|
339
339
|
borderBottom: '1px solid #727272',
|
|
@@ -343,13 +343,13 @@ const styles = () => ({
|
|
|
343
343
|
height: '10px',
|
|
344
344
|
position: 'absolute',
|
|
345
345
|
right: '-10px',
|
|
346
|
-
width: '10px'
|
|
346
|
+
width: '10px',
|
|
347
347
|
},
|
|
348
348
|
stage: {
|
|
349
349
|
left: 0,
|
|
350
350
|
top: 0,
|
|
351
|
-
position: 'absolute'
|
|
352
|
-
}
|
|
351
|
+
position: 'absolute',
|
|
352
|
+
},
|
|
353
353
|
});
|
|
354
354
|
|
|
355
355
|
Drawable.propTypes = {
|
|
@@ -365,7 +365,7 @@ Drawable.propTypes = {
|
|
|
365
365
|
outlineColor: PropTypes.string.isRequired,
|
|
366
366
|
shapes: PropTypes.array.isRequired,
|
|
367
367
|
strokeWidth: PropTypes.number,
|
|
368
|
-
preserveAspectRatioEnabled: PropTypes.bool
|
|
368
|
+
preserveAspectRatioEnabled: PropTypes.bool,
|
|
369
369
|
};
|
|
370
370
|
|
|
371
371
|
export default withStyles(styles)(Drawable);
|
|
@@ -6,14 +6,14 @@ import MenuItem from '@material-ui/core/MenuItem';
|
|
|
6
6
|
import { withStyles } from '@material-ui/core/styles';
|
|
7
7
|
|
|
8
8
|
class Palette extends React.Component {
|
|
9
|
-
onChange = (name) => event => {
|
|
9
|
+
onChange = (name) => (event) => {
|
|
10
10
|
const { value } = event.target;
|
|
11
11
|
const { onHotspotColorChange, onOutlineColorChange } = this.props;
|
|
12
12
|
|
|
13
13
|
if (name === 'hotspot') {
|
|
14
14
|
onHotspotColorChange(value);
|
|
15
15
|
} else {
|
|
16
|
-
onOutlineColorChange(value)
|
|
16
|
+
onOutlineColorChange(value);
|
|
17
17
|
}
|
|
18
18
|
};
|
|
19
19
|
|
|
@@ -23,18 +23,9 @@ class Palette extends React.Component {
|
|
|
23
23
|
return (
|
|
24
24
|
<div className={classes.base}>
|
|
25
25
|
<InputContainer label="Hot Spot" className={classes.input}>
|
|
26
|
-
<Select
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
value={hotspotColor}
|
|
30
|
-
>
|
|
31
|
-
{hotspotList.map(hotspot => (
|
|
32
|
-
<MenuItem
|
|
33
|
-
key={hotspot}
|
|
34
|
-
value={hotspot}
|
|
35
|
-
className={classes.item}
|
|
36
|
-
style={{ backgroundColor: hotspot }}
|
|
37
|
-
>
|
|
26
|
+
<Select className={classes.select} onChange={this.onChange('hotspot')} value={hotspotColor}>
|
|
27
|
+
{hotspotList.map((hotspot) => (
|
|
28
|
+
<MenuItem key={hotspot} value={hotspot} className={classes.item} style={{ backgroundColor: hotspot }}>
|
|
38
29
|
{hotspot}
|
|
39
30
|
</MenuItem>
|
|
40
31
|
))}
|
|
@@ -42,12 +33,8 @@ class Palette extends React.Component {
|
|
|
42
33
|
</InputContainer>
|
|
43
34
|
|
|
44
35
|
<InputContainer label="Response Outline" className={classes.input}>
|
|
45
|
-
<Select
|
|
46
|
-
|
|
47
|
-
onChange={this.onChange('outline')}
|
|
48
|
-
value={outlineColor}
|
|
49
|
-
>
|
|
50
|
-
{outlineList.map(outline => (
|
|
36
|
+
<Select className={classes.select} onChange={this.onChange('outline')} value={outlineColor}>
|
|
37
|
+
{outlineList.map((outline) => (
|
|
51
38
|
<MenuItem
|
|
52
39
|
key={outline}
|
|
53
40
|
value={outline}
|
|
@@ -64,21 +51,21 @@ class Palette extends React.Component {
|
|
|
64
51
|
}
|
|
65
52
|
}
|
|
66
53
|
|
|
67
|
-
const styles = theme => ({
|
|
54
|
+
const styles = (theme) => ({
|
|
68
55
|
base: {
|
|
69
56
|
marginTop: theme.spacing.unit * 2,
|
|
70
|
-
display: 'flex'
|
|
57
|
+
display: 'flex',
|
|
71
58
|
},
|
|
72
59
|
input: {
|
|
73
60
|
flex: 1,
|
|
74
|
-
width: '90%'
|
|
61
|
+
width: '90%',
|
|
75
62
|
},
|
|
76
63
|
item: {
|
|
77
64
|
borderRadius: '2px',
|
|
78
65
|
height: '22px',
|
|
79
66
|
marginLeft: theme.spacing.unit * 2,
|
|
80
67
|
marginRight: theme.spacing.unit * 2,
|
|
81
|
-
marginTop: theme.spacing.unit * 2
|
|
68
|
+
marginTop: theme.spacing.unit * 2,
|
|
82
69
|
},
|
|
83
70
|
});
|
|
84
71
|
|
|
@@ -89,7 +76,7 @@ Palette.propTypes = {
|
|
|
89
76
|
onHotspotColorChange: PropTypes.func.isRequired,
|
|
90
77
|
onOutlineColorChange: PropTypes.func.isRequired,
|
|
91
78
|
outlineColor: PropTypes.string.isRequired,
|
|
92
|
-
outlineList: PropTypes.array.isRequired
|
|
79
|
+
outlineList: PropTypes.array.isRequired,
|
|
93
80
|
};
|
|
94
81
|
|
|
95
82
|
export default withStyles(styles)(Palette);
|