@pie-element/hotspot 6.24.1-next.9 → 6.25.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,6 +2,7 @@ import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
3
  import { Group, Line, Circle } from 'react-konva';
4
4
  import { withStyles } from '@material-ui/core/styles/index';
5
+ import { Rect } from 'react-konva/lib/ReactKonvaCore';
5
6
  import DeleteWidget from './DeleteWidget';
6
7
 
7
8
  const HOVERED_COLOR = '#00BFFF';
@@ -166,21 +167,66 @@ class PolComponent extends React.Component {
166
167
  onDeleteShape(id);
167
168
  };
168
169
 
170
+ // serialize(points) {
171
+ // return points.reduce((acc, point) => [...acc, point.x, point.y], []);
172
+ // }
173
+
174
+ getBoundingBox(points) {
175
+ const xValues = points.map((point) => point.x);
176
+ const yValues = points.map((point) => point.y);
177
+ const minX = Math.min(...xValues);
178
+ const maxX = Math.max(...xValues);
179
+ const minY = Math.min(...yValues);
180
+ const maxY = Math.max(...yValues);
181
+ return {
182
+ x: minX,
183
+ y: minY,
184
+ width: maxX - minX,
185
+ height: maxY - minY,
186
+ };
187
+ }
188
+
169
189
  render() {
170
- const { classes, correct, id, hotspotColor, outlineColor, strokeWidth = 5 } = this.props;
190
+ const {
191
+ classes,
192
+ correct,
193
+ id,
194
+ hotspotColor,
195
+ outlineColor,
196
+ selectedHotspotColor,
197
+ hoverOutlineColor,
198
+ strokeWidth = 5,
199
+ } = this.props;
200
+
171
201
  const { points, x, y, hovered } = this.state;
172
202
  const showPoints = hovered || id === 'newPolygon';
173
203
 
204
+ const hoverColor = hoverOutlineColor || HOVERED_COLOR;
205
+
174
206
  const calculatedStrokeWidth = correct ? strokeWidth : hovered ? 1 : 0;
175
207
  const calculatedStroke = correct ? outlineColor : hovered ? HOVERED_COLOR : '';
208
+ // const calculatedStroke = correct ? outlineColor : hovered ? hoverColor : '';
209
+ const boundingBox = this.getBoundingBox(points);
176
210
 
177
211
  return (
178
212
  <Group classes={classes.group} onMouseLeave={this.handleMouseLeave} onMouseEnter={this.handleMouseEnter}>
213
+ {hoverOutlineColor && hovered && (
214
+ <Rect
215
+ x={boundingBox.x}
216
+ y={boundingBox.y}
217
+ width={boundingBox.width}
218
+ height={boundingBox.height}
219
+ stroke={hoverOutlineColor}
220
+ strokeWidth={2}
221
+ listening={false}
222
+ />
223
+ )}
224
+
179
225
  <Line
180
226
  classes={classes.base}
181
227
  points={this.serialize(points)}
182
228
  closed={true}
183
- fill={hotspotColor}
229
+ fill={correct ? selectedHotspotColor : hotspotColor}
184
230
  onClick={this.handleClick}
185
231
  onTap={this.handleClick}
186
232
  draggable
@@ -244,6 +290,8 @@ PolComponent.propTypes = {
244
290
  imageHeight: PropTypes.number,
245
291
  imageWidth: PropTypes.number,
246
292
  hotspotColor: PropTypes.string.isRequired,
293
+ selectedHotspotColor: PropTypes.string,
294
+ hoverOutlineColor: PropTypes.string,
247
295
  onClick: PropTypes.func.isRequired,
248
296
  addPolygonPoint: PropTypes.func.isRequired,
249
297
  onDeleteShape: PropTypes.func.isRequired,
@@ -74,20 +74,48 @@ class RectComponent extends React.Component {
74
74
  };
75
75
 
76
76
  render() {
77
- const { classes, correct, height, hotspotColor, id, outlineColor, width, x, y, strokeWidth = 5 } = this.props;
77
+ const {
78
+ classes,
79
+ correct,
80
+ height,
81
+ hotspotColor,
82
+ id,
83
+ outlineColor,
84
+ width,
85
+ x,
86
+ y,
87
+ strokeWidth = 5,
88
+ selectedHotspotColor,
89
+ hoverOutlineColor,
90
+ } = this.props;
91
+
92
+ const { hovered } = this.state;
93
+
78
94
  return (
79
95
  <Group classes={classes.group} onMouseLeave={this.handleMouseLeave} onMouseEnter={this.handleMouseEnter}>
96
+ {hoverOutlineColor && hovered && (
97
+ <Rect
98
+ x={x}
99
+ y={y}
100
+ width={width}
101
+ height={height}
102
+ stroke={hoverOutlineColor}
103
+ strokeWidth={2}
104
+ listening={false}
105
+ />
106
+ )}
107
+
80
108
  <Rect
81
109
  classes={classes.base}
82
110
  ref={this.shapeRef}
83
111
  width={width}
84
112
  height={height}
85
- fill={hotspotColor}
113
+ fill={correct ? selectedHotspotColor : hotspotColor}
86
114
  onClick={this.handleClick}
87
115
  onTap={this.handleClick}
88
116
  draggable
89
- stroke={outlineColor}
90
- strokeWidth={correct ? strokeWidth : 0}
117
+ stroke={hovered ? 'transparent' : outlineColor}
118
+ strokeWidth={correct && !hovered ? strokeWidth : 0}
91
119
  onDragStart={() => this.setState({ isDragging: true })}
92
120
  onDragEnd={this.handleOnDragEnd}
93
121
  onTransformStart={() => this.setState({ isDragging: true })}
@@ -134,6 +162,8 @@ RectComponent.propTypes = {
134
162
  id: PropTypes.string.isRequired,
135
163
  height: PropTypes.number.isRequired,
136
164
  hotspotColor: PropTypes.string.isRequired,
165
+ selectedHotspotColor: PropTypes.string,
166
+ hoverOutlineColor: PropTypes.string,
137
167
  onClick: PropTypes.func.isRequired,
138
168
  onDeleteShape: PropTypes.func.isRequired,
139
169
  onDragEnd: PropTypes.func.isRequired,
@@ -214,6 +214,8 @@ export class Root extends React.Component {
214
214
  hasErrors={!!shapesError || !!selectionsError}
215
215
  hotspotColor={model.hotspotColor}
216
216
  outlineColor={model.outlineColor}
217
+ selectedHotspotColor={model.selectedHotspotColor}
218
+ hoverOutlineColor={model.hoverOutlineColor}
217
219
  onUpdateImageDimension={onUpdateImageDimension}
218
220
  onUpdateShapes={onUpdateShapes}
219
221
  onImageUpload={onImageUpload}
@@ -3,6 +3,17 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [4.19.0](https://github.com/pie-framework/pie-elements/compare/@pie-element/hotspot-controller@4.18.0...@pie-element/hotspot-controller@4.19.0) (2024-08-06)
7
+
8
+
9
+ ### Features
10
+
11
+ * update pie-lib PD-3996, PD-3792, Pd-3791, PD-3841, PD-3956, PD-3569, PD-3855 ([6343d1b](https://github.com/pie-framework/pie-elements/commit/6343d1b00c5a4a3d88de70ed13a8aa5c1a43002d))
12
+
13
+
14
+
15
+
16
+
6
17
  # [4.18.0](https://github.com/pie-framework/pie-elements/compare/@pie-element/hotspot-controller@4.17.6...@pie-element/hotspot-controller@4.18.0) (2024-07-26)
7
18
 
8
19
 
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@pie-element/hotspot-controller",
3
3
  "private": true,
4
- "version": "4.18.0",
4
+ "version": "4.19.0",
5
5
  "description": "",
6
6
  "scripts": {
7
7
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -11,7 +11,7 @@
11
11
  "main": "lib/index.js",
12
12
  "module": "src/index.js",
13
13
  "dependencies": {
14
- "@pie-lib/pie-toolbox": "1.28.0",
14
+ "@pie-lib/pie-toolbox": "1.29.0",
15
15
  "debug": "^4.1.1",
16
16
  "lodash": "^4.17.15"
17
17
  }
@@ -164,6 +164,16 @@
164
164
  "type": "string",
165
165
  "title": "hotspotColor"
166
166
  },
167
+ "selectedHotspotColor": {
168
+ "description": "The color that fills the hotspot",
169
+ "type": "string",
170
+ "title": "selectedHotspotColor"
171
+ },
172
+ "hoverOutlineColor": {
173
+ "description": "The color of the rectangular outline",
174
+ "type": "string",
175
+ "title": "hoverOutlineColor"
176
+ },
167
177
  "hotspotList": {
168
178
  "description": "The filling hotspot color options",
169
179
  "type": "array",
@@ -110,6 +110,14 @@ the width of the section
110
110
 
111
111
  The color that fills the hotspot
112
112
 
113
+ # `selectedHotspotColor` (string)
114
+
115
+ The color that fills the hotspot
116
+
117
+ # `hoverOutlineColor` (string)
118
+
119
+ The color of the rectangular outline
120
+
113
121
  # `hotspotList` (array)
114
122
 
115
123
  The filling hotspot color options
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pie-element/hotspot",
3
- "version": "6.24.1-next.9+da7be3c80",
3
+ "version": "6.25.0",
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.28.0",
12
+ "@pie-lib/pie-toolbox": "1.29.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": "da7be3c80a08c5521006ee1298256e645f20ea02",
21
+ "gitHead": "74eb9b1f92c86492f3e09c7cb919a9757365fbc5",
22
22
  "scripts": {
23
23
  "postpublish": "../../scripts/postpublish"
24
24
  },