@pie-element/hotspot 9.3.4-next.3 → 10.0.0-beta.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.
Files changed (103) hide show
  1. package/configure/lib/DeleteWidget.js +30 -43
  2. package/configure/lib/DeleteWidget.js.map +1 -1
  3. package/configure/lib/button.js +26 -45
  4. package/configure/lib/button.js.map +1 -1
  5. package/configure/lib/buttons/circle.js +20 -27
  6. package/configure/lib/buttons/circle.js.map +1 -1
  7. package/configure/lib/buttons/polygon.js +26 -33
  8. package/configure/lib/buttons/polygon.js.map +1 -1
  9. package/configure/lib/buttons/rectangle.js +26 -33
  10. package/configure/lib/buttons/rectangle.js.map +1 -1
  11. package/configure/lib/defaults.js +2 -3
  12. package/configure/lib/defaults.js.map +1 -1
  13. package/configure/lib/hotspot-circle.js +132 -198
  14. package/configure/lib/hotspot-circle.js.map +1 -1
  15. package/configure/lib/hotspot-container.js +250 -355
  16. package/configure/lib/hotspot-container.js.map +1 -1
  17. package/configure/lib/hotspot-drawable.js +360 -472
  18. package/configure/lib/hotspot-drawable.js.map +1 -1
  19. package/configure/lib/hotspot-palette.js +92 -139
  20. package/configure/lib/hotspot-palette.js.map +1 -1
  21. package/configure/lib/hotspot-polygon.js +212 -317
  22. package/configure/lib/hotspot-polygon.js.map +1 -1
  23. package/configure/lib/hotspot-rectangle.js +128 -192
  24. package/configure/lib/hotspot-rectangle.js.map +1 -1
  25. package/configure/lib/icons.js.map +1 -1
  26. package/configure/lib/image-konva.js +46 -86
  27. package/configure/lib/image-konva.js.map +1 -1
  28. package/configure/lib/index.js +162 -222
  29. package/configure/lib/index.js.map +1 -1
  30. package/configure/lib/root.js +301 -393
  31. package/configure/lib/root.js.map +1 -1
  32. package/configure/lib/shapes/circle.js +69 -101
  33. package/configure/lib/shapes/circle.js.map +1 -1
  34. package/configure/lib/shapes/index.js +4 -12
  35. package/configure/lib/shapes/index.js.map +1 -1
  36. package/configure/lib/shapes/polygon.js +64 -96
  37. package/configure/lib/shapes/polygon.js.map +1 -1
  38. package/configure/lib/shapes/rectagle.js +69 -101
  39. package/configure/lib/shapes/rectagle.js.map +1 -1
  40. package/configure/lib/shapes/utils.js +2 -8
  41. package/configure/lib/shapes/utils.js.map +1 -1
  42. package/configure/lib/upload-control.js +25 -52
  43. package/configure/lib/upload-control.js.map +1 -1
  44. package/configure/lib/utils.js +84 -137
  45. package/configure/lib/utils.js.map +1 -1
  46. package/configure/package.json +11 -10
  47. package/configure/src/__tests__/hotspot-container.test.js +50 -19
  48. package/configure/src/__tests__/hotspot-drawable.test.js +55 -34
  49. package/configure/src/__tests__/index.test.js +167 -5
  50. package/configure/src/__tests__/root.test.js +89 -63
  51. package/configure/src/button.jsx +12 -20
  52. package/configure/src/hotspot-circle.jsx +5 -18
  53. package/configure/src/hotspot-container.jsx +82 -98
  54. package/configure/src/hotspot-drawable.jsx +43 -45
  55. package/configure/src/hotspot-palette.jsx +45 -37
  56. package/configure/src/hotspot-polygon.jsx +4 -20
  57. package/configure/src/hotspot-rectangle.jsx +4 -17
  58. package/configure/src/index.js +12 -2
  59. package/configure/src/root.jsx +85 -79
  60. package/configure/src/upload-control.jsx +6 -16
  61. package/controller/lib/defaults.js +2 -3
  62. package/controller/lib/defaults.js.map +1 -1
  63. package/controller/lib/index.js +151 -205
  64. package/controller/lib/index.js.map +1 -1
  65. package/controller/lib/utils.js +14 -34
  66. package/controller/lib/utils.js.map +1 -1
  67. package/controller/package.json +2 -2
  68. package/lib/hotspot/circle.js +110 -169
  69. package/lib/hotspot/circle.js.map +1 -1
  70. package/lib/hotspot/container.js +174 -260
  71. package/lib/hotspot/container.js.map +1 -1
  72. package/lib/hotspot/icons.js.map +1 -1
  73. package/lib/hotspot/image-konva-tooltip.js +65 -112
  74. package/lib/hotspot/image-konva-tooltip.js.map +1 -1
  75. package/lib/hotspot/index.js +135 -198
  76. package/lib/hotspot/index.js.map +1 -1
  77. package/lib/hotspot/polygon.js +150 -214
  78. package/lib/hotspot/polygon.js.map +1 -1
  79. package/lib/hotspot/rectangle.js +128 -185
  80. package/lib/hotspot/rectangle.js.map +1 -1
  81. package/lib/index.js +187 -256
  82. package/lib/index.js.map +1 -1
  83. package/lib/session-updater.js +12 -18
  84. package/lib/session-updater.js.map +1 -1
  85. package/package.json +14 -11
  86. package/src/__tests__/container.test.jsx +27 -175
  87. package/src/__tests__/index.test.js +70 -30
  88. package/src/hotspot/circle.jsx +2 -13
  89. package/src/hotspot/container.jsx +35 -50
  90. package/src/hotspot/index.jsx +16 -28
  91. package/src/hotspot/polygon.jsx +4 -13
  92. package/src/hotspot/rectangle.jsx +5 -15
  93. package/src/index.js +21 -12
  94. package/configure/src/__tests__/DeleteWidget.test.js +0 -64
  95. package/configure/src/__tests__/__snapshots__/hotspot-container.test.js.snap +0 -192
  96. package/configure/src/__tests__/__snapshots__/hotspot-drawable.test.js.snap +0 -562
  97. package/configure/src/__tests__/__snapshots__/root.test.js.snap +0 -469
  98. package/src/__tests__/__snapshots__/container.test.jsx.snap +0 -264
  99. package/src/__tests__/__snapshots__/index.test.js.snap +0 -81
  100. package/src/__tests__/__snapshots__/polygon.test.jsx.snap +0 -192
  101. package/src/__tests__/__snapshots__/rectangle.test.jsx.snap +0 -127
  102. package/src/__tests__/polygon.test.jsx +0 -230
  103. package/src/__tests__/rectangle.test.jsx +0 -232
@@ -1,400 +1,365 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
- exports["default"] = exports.Drawable = void 0;
9
-
7
+ exports.default = exports.Drawable = void 0;
10
8
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
11
-
12
- var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
13
-
14
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
15
-
16
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
17
-
18
- var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
19
-
20
- var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
21
-
22
- var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
23
-
24
- var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
25
-
26
9
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
27
-
28
10
  var _react = _interopRequireDefault(require("react"));
29
-
30
11
  var _propTypes = _interopRequireDefault(require("prop-types"));
31
-
32
12
  var _reactKonva = require("react-konva");
33
-
34
13
  var _cloneDeep = _interopRequireDefault(require("lodash/cloneDeep"));
35
-
36
- var _index = require("@material-ui/core/styles/index");
37
-
14
+ var _styles = require("@mui/material/styles");
38
15
  var _hotspotRectangle = _interopRequireDefault(require("./hotspot-rectangle"));
39
-
40
16
  var _hotspotPolygon = _interopRequireDefault(require("./hotspot-polygon"));
41
-
42
17
  var _hotspotCircle = _interopRequireDefault(require("./hotspot-circle"));
43
-
44
18
  var _utils = require("./utils");
45
-
46
- var _shapes2 = require("./shapes");
47
-
48
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
49
-
50
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
51
-
52
- 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); }; }
53
-
54
- 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; } }
55
-
56
- var IMAGE_MAX_WIDTH = 800;
57
-
58
- var Drawable = /*#__PURE__*/function (_React$Component) {
59
- (0, _inherits2["default"])(Drawable, _React$Component);
60
-
61
- var _super = _createSuper(Drawable);
62
-
63
- function Drawable(props) {
64
- var _this;
65
-
66
- (0, _classCallCheck2["default"])(this, Drawable);
67
- _this = _super.call(this, props);
68
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "handleOnMouseDown", function (e) {
69
- var _this$props = _this.props,
70
- shapeType = _this$props.shapeType,
71
- onUpdateShapes = _this$props.onUpdateShapes,
72
- shapes = _this$props.shapes;
73
- var newState, newShapeId; // Ensure that the click originated from the expected element
74
-
19
+ var _shapes = require("./shapes");
20
+ const BaseContainer = (0, _styles.styled)('div')({
21
+ position: 'relative'
22
+ });
23
+ const ImageContainer = (0, _styles.styled)('div')({
24
+ position: 'relative',
25
+ width: 'fit-content'
26
+ });
27
+ const Image = (0, _styles.styled)('img')({
28
+ alignItems: 'center',
29
+ display: 'flex',
30
+ justifyContent: 'center'
31
+ });
32
+ const ResizeHandle = (0, _styles.styled)('div')({
33
+ borderBottom: '1px solid #727272',
34
+ borderRight: '1px solid #727272',
35
+ bottom: '-10px',
36
+ cursor: 'se-resize',
37
+ height: '10px',
38
+ position: 'absolute',
39
+ right: '-10px',
40
+ width: '10px'
41
+ });
42
+ const StyledStage = (0, _styles.styled)(_reactKonva.Stage)({
43
+ left: 0,
44
+ top: 0,
45
+ position: 'absolute'
46
+ });
47
+ const IMAGE_MAX_WIDTH = 800;
48
+ class Drawable extends _react.default.Component {
49
+ static getDerivedStateFromProps(nextProps, prevState) {
50
+ // Update the state only if the props have changed
51
+ if (nextProps.shapes !== prevState.shapes) {
52
+ return {
53
+ shapes: nextProps.shapes
54
+ };
55
+ }
56
+ return null;
57
+ }
58
+ constructor(props) {
59
+ super(props);
60
+ (0, _defineProperty2.default)(this, "handleOnMouseDown", e => {
61
+ const {
62
+ shapeType,
63
+ onUpdateShapes,
64
+ shapes
65
+ } = this.props;
66
+ let newState, newShapeId;
67
+
68
+ // Ensure that the click originated from the expected element
75
69
  if (e.target !== e.currentTarget) {
76
70
  return;
77
71
  }
78
-
79
- if (!Object.values(_shapes2.SUPPORTED_SHAPES).includes(shapeType)) {
72
+ if (!Object.values(_shapes.SUPPORTED_SHAPES).includes(shapeType)) {
80
73
  return;
81
74
  }
82
-
83
75
  switch (shapeType) {
84
- case _shapes2.SUPPORTED_SHAPES.RECTANGLE:
85
- newState = _shapes2.RectangleShape.create(shapes, e);
76
+ case _shapes.SUPPORTED_SHAPES.RECTANGLE:
77
+ newState = _shapes.RectangleShape.create(shapes, e);
86
78
  break;
87
-
88
- case _shapes2.SUPPORTED_SHAPES.CIRCLE:
89
- newState = _shapes2.CircleShape.create(shapes, e);
79
+ case _shapes.SUPPORTED_SHAPES.CIRCLE:
80
+ newState = _shapes.CircleShape.create(shapes, e);
90
81
  break;
91
-
92
- case _shapes2.SUPPORTED_SHAPES.POLYGON:
93
- newShapeId = _this.state.isDrawingShapeId;
94
-
82
+ case _shapes.SUPPORTED_SHAPES.POLYGON:
83
+ newShapeId = this.state.isDrawingShapeId;
95
84
  if (newShapeId) {
96
85
  // If a polygon is in progress, add a new point
97
- var _shapes = _this.addPolygonPoint(e);
98
-
86
+ const shapes = this.addPolygonPoint(e);
99
87
  newState = {
100
88
  isDrawing: true,
101
89
  isDrawingShapeId: newShapeId,
102
- shapes: _shapes
90
+ shapes: shapes
103
91
  };
104
92
  } else {
105
93
  // Else start a new one
106
- newState = _shapes2.PolygonShape.create(shapes, e);
94
+ newState = _shapes.PolygonShape.create(shapes, e);
107
95
  }
108
-
109
96
  break;
110
-
111
97
  default:
112
98
  return;
113
99
  }
114
-
115
- _this.setState(_objectSpread({}, newState));
116
-
100
+ this.setState({
101
+ ...newState
102
+ });
117
103
  onUpdateShapes(newState.shapes);
118
104
  });
119
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "handleOnMouseUp", function () {
120
- var _this$props2 = _this.props,
121
- shapeType = _this$props2.shapeType,
122
- onUpdateShapes = _this$props2.onUpdateShapes;
123
- var newState;
124
-
125
- if (shapeType === _shapes2.SUPPORTED_SHAPES.POLYGON) {
105
+ (0, _defineProperty2.default)(this, "handleOnMouseUp", () => {
106
+ const {
107
+ shapeType,
108
+ onUpdateShapes
109
+ } = this.props;
110
+ let newState;
111
+ if (shapeType === _shapes.SUPPORTED_SHAPES.POLYGON) {
126
112
  return;
127
113
  }
128
-
129
114
  switch (shapeType) {
130
- case _shapes2.SUPPORTED_SHAPES.RECTANGLE:
131
- newState = _shapes2.RectangleShape.finalizeCreation(_this.state, _this.props);
115
+ case _shapes.SUPPORTED_SHAPES.RECTANGLE:
116
+ newState = _shapes.RectangleShape.finalizeCreation(this.state, this.props);
132
117
  break;
133
-
134
- case _shapes2.SUPPORTED_SHAPES.CIRCLE:
135
- newState = _shapes2.CircleShape.finalizeCreation(_this.state, _this.props);
118
+ case _shapes.SUPPORTED_SHAPES.CIRCLE:
119
+ newState = _shapes.CircleShape.finalizeCreation(this.state, this.props);
136
120
  break;
137
-
138
121
  default:
139
122
  return;
140
123
  }
141
-
142
- _this.setState(_objectSpread(_objectSpread({}, newState), {}, {
124
+ this.setState({
125
+ ...newState,
143
126
  isDrawing: false
144
- }));
145
-
127
+ });
146
128
  onUpdateShapes(newState.shapes);
147
129
  });
148
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "handleMouseMove", function (e) {
149
- var _this$props3 = _this.props,
150
- shapeType = _this$props3.shapeType,
151
- onUpdateShapes = _this$props3.onUpdateShapes;
152
- var newState;
153
-
154
- if (!_this.state.isDrawing || !Object.values(_shapes2.SUPPORTED_SHAPES).includes(shapeType)) {
130
+ (0, _defineProperty2.default)(this, "handleMouseMove", e => {
131
+ const {
132
+ shapeType,
133
+ onUpdateShapes
134
+ } = this.props;
135
+ let newState;
136
+ if (!this.state.isDrawing || !Object.values(_shapes.SUPPORTED_SHAPES).includes(shapeType)) {
155
137
  return;
156
138
  }
157
-
158
139
  switch (shapeType) {
159
- case _shapes2.SUPPORTED_SHAPES.RECTANGLE:
160
- newState = _shapes2.RectangleShape.handleMouseMove(_this.state, e);
140
+ case _shapes.SUPPORTED_SHAPES.RECTANGLE:
141
+ newState = _shapes.RectangleShape.handleMouseMove(this.state, e);
161
142
  break;
162
-
163
- case _shapes2.SUPPORTED_SHAPES.CIRCLE:
164
- newState = _shapes2.CircleShape.handleMouseMove(_this.state, e);
143
+ case _shapes.SUPPORTED_SHAPES.CIRCLE:
144
+ newState = _shapes.CircleShape.handleMouseMove(this.state, e);
165
145
  break;
166
-
167
- case _shapes2.SUPPORTED_SHAPES.POLYGON:
168
- newState = _shapes2.PolygonShape.handleMouseMove(_this.state, e);
146
+ case _shapes.SUPPORTED_SHAPES.POLYGON:
147
+ newState = _shapes.PolygonShape.handleMouseMove(this.state, e);
169
148
  break;
170
-
171
149
  default:
172
150
  return;
173
151
  }
174
-
175
- _this.setState(newState);
176
-
152
+ this.setState(newState);
177
153
  onUpdateShapes(newState.shapes);
178
154
  });
179
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "handleOnMouseOutOrLeave", function (e) {
180
- if (_this.state.isDrawing) {
181
- _this.handleOnMouseUp(e);
155
+ (0, _defineProperty2.default)(this, "handleOnMouseOutOrLeave", e => {
156
+ if (this.state.isDrawing) {
157
+ this.handleOnMouseUp(e);
182
158
  }
183
159
  });
184
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "handleOnDragEnd", function (id, updatedProps) {
185
- var _this$props4 = _this.props,
186
- shapes = _this$props4.shapes,
187
- onUpdateShapes = _this$props4.onUpdateShapes,
188
- dimensions = _this$props4.dimensions;
189
- var canvasWidth = dimensions.width,
190
- canvasHeight = dimensions.height; // when a shape is moved completely outside the canvas
160
+ (0, _defineProperty2.default)(this, "handleOnDragEnd", (id, updatedProps) => {
161
+ const {
162
+ shapes,
163
+ onUpdateShapes,
164
+ dimensions
165
+ } = this.props;
166
+ const {
167
+ width: canvasWidth,
168
+ height: canvasHeight
169
+ } = dimensions;
170
+
171
+ // when a shape is moved completely outside the canvas
191
172
  // remove that shape
192
-
193
- var newShapes = shapes.map(function (shape) {
173
+ const newShapes = shapes.map(shape => {
194
174
  if (shape.id !== id) {
195
175
  return shape;
196
176
  }
197
-
198
- var newX = updatedProps.x;
199
- var newY = updatedProps.y;
200
-
177
+ let newX = updatedProps.x;
178
+ let newY = updatedProps.y;
201
179
  if (shape.group === 'rectangles') {
202
180
  if (newX + shape.width < 0 || newX > canvasWidth || newY + shape.height < 0 || newY > canvasHeight) {
203
181
  return null;
204
182
  }
205
-
206
- return _objectSpread(_objectSpread({}, shape), updatedProps);
183
+ return {
184
+ ...shape,
185
+ ...updatedProps
186
+ };
207
187
  }
208
-
209
188
  if (shape.group === 'circles') {
210
- var radius = shape.radius;
211
-
189
+ const radius = shape.radius;
212
190
  if (newX + radius < 0 || newX - radius > canvasWidth || newY + radius < 0 || newY - radius > canvasHeight) {
213
191
  return null;
214
192
  }
215
-
216
- return _objectSpread(_objectSpread({}, shape), updatedProps);
193
+ return {
194
+ ...shape,
195
+ ...updatedProps
196
+ };
217
197
  }
218
-
219
198
  if (shape.group === 'polygons') {
220
- var points = shape.points;
221
- var xValues = points.map(function (point) {
222
- return point.x;
223
- });
224
- var yValues = points.map(function (point) {
225
- return point.y;
226
- });
227
- var minX = Math.min.apply(Math, (0, _toConsumableArray2["default"])(xValues));
228
- var minY = Math.min.apply(Math, (0, _toConsumableArray2["default"])(yValues));
229
- var maxX = Math.max.apply(Math, (0, _toConsumableArray2["default"])(xValues));
230
- var maxY = Math.max.apply(Math, (0, _toConsumableArray2["default"])(yValues)); // Calculate deltas based on the first point as a reference
231
-
232
- var deltaX = updatedProps['points'][0].x - points[0].x;
233
- var deltaY = updatedProps['points'][0].y - points[0].y;
199
+ const points = shape.points;
200
+ const xValues = points.map(point => point.x);
201
+ const yValues = points.map(point => point.y);
202
+ let minX = Math.min(...xValues);
203
+ let minY = Math.min(...yValues);
204
+ let maxX = Math.max(...xValues);
205
+ let maxY = Math.max(...yValues);
206
+
207
+ // Calculate deltas based on the first point as a reference
208
+ const deltaX = updatedProps['points'][0].x - points[0].x;
209
+ const deltaY = updatedProps['points'][0].y - points[0].y;
234
210
  minX = minX + deltaX;
235
211
  maxX = maxX + deltaX;
236
212
  minY = minY + deltaY;
237
213
  maxY = maxY + deltaY;
238
-
239
214
  if (maxX < 0 || minX > canvasWidth || maxY < 0 || minY > canvasHeight) {
240
215
  return null;
241
216
  }
242
-
243
- return _objectSpread(_objectSpread({}, shape), updatedProps);
217
+ return {
218
+ ...shape,
219
+ ...updatedProps
220
+ };
244
221
  }
245
-
246
222
  return shape;
247
- }).filter(function (shape) {
248
- return shape !== null;
249
- });
250
- onUpdateShapes((0, _cloneDeep["default"])(newShapes));
223
+ }).filter(shape => shape !== null);
224
+ onUpdateShapes((0, _cloneDeep.default)(newShapes));
251
225
  });
252
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "closeInProgressPolygons", function (id) {
253
- var _this$props5 = _this.props,
254
- shapes = _this$props5.shapes,
255
- onUpdateShapes = _this$props5.onUpdateShapes;
256
- var inProgressPolygon = (shapes || []).find(function (shape) {
257
- return shape.id === 'newPolygon';
258
- });
259
-
260
- if (id === 'newPolygon' || inProgressPolygon && _this.state.isDrawing) {
261
- _shapes2.PolygonShape.finalizeCreation(_this.state, function (newShapes) {
262
- _this.setState({
226
+ (0, _defineProperty2.default)(this, "closeInProgressPolygons", id => {
227
+ const {
228
+ shapes,
229
+ onUpdateShapes
230
+ } = this.props;
231
+ const inProgressPolygon = (shapes || []).find(shape => shape.id === 'newPolygon');
232
+ if (id === 'newPolygon' || inProgressPolygon && this.state.isDrawing) {
233
+ _shapes.PolygonShape.finalizeCreation(this.state, newShapes => {
234
+ this.setState({
263
235
  isDrawing: false,
264
236
  shapes: newShapes,
265
237
  isDrawingShapeId: undefined
266
238
  });
267
-
268
- onUpdateShapes((0, _cloneDeep["default"])(newShapes));
239
+ onUpdateShapes((0, _cloneDeep.default)(newShapes));
269
240
  });
270
241
  }
271
242
  });
272
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "handleOnSetAsCorrect", function (shape) {
273
- var id = shape.id;
274
- var _this$props6 = _this.props,
275
- multipleCorrect = _this$props6.multipleCorrect,
276
- shapes = _this$props6.shapes,
277
- onUpdateShapes = _this$props6.onUpdateShapes;
278
- var newShapes;
279
-
243
+ (0, _defineProperty2.default)(this, "handleOnSetAsCorrect", shape => {
244
+ const {
245
+ id
246
+ } = shape;
247
+ const {
248
+ multipleCorrect,
249
+ shapes,
250
+ onUpdateShapes
251
+ } = this.props;
252
+ let newShapes;
280
253
  if (multipleCorrect) {
281
- newShapes = shapes.map(function (shape) {
254
+ newShapes = shapes.map(shape => {
282
255
  if (shape.id === id) {
283
256
  shape.correct = !shape.correct;
284
257
  }
285
-
286
258
  return shape;
287
259
  });
288
260
  } else {
289
- newShapes = shapes.map(function (shape) {
261
+ newShapes = shapes.map(shape => {
290
262
  shape.correct = shape.id === id;
291
263
  return shape;
292
264
  });
293
265
  }
294
-
295
- onUpdateShapes((0, _cloneDeep["default"])(newShapes));
296
-
297
- _this.closeInProgressPolygons(id);
266
+ onUpdateShapes((0, _cloneDeep.default)(newShapes));
267
+ this.closeInProgressPolygons(id);
298
268
  });
299
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "handleOnImageLoad", function (_ref) {
300
- var target = _ref.target;
301
- var onUpdateImageDimension = _this.props.onUpdateImageDimension;
302
- var resizeHandle = _this.resize;
303
- var elementStyle = getComputedStyle(target);
304
- var newHeight = parseFloat(elementStyle.height);
305
- var newWidth = parseFloat(elementStyle.width);
306
- var aspectWidth = newWidth / IMAGE_MAX_WIDTH;
307
- var dimensions = newWidth > IMAGE_MAX_WIDTH ? {
269
+ /// end of handling HotSpots section
270
+ /// start of handling Image section
271
+ (0, _defineProperty2.default)(this, "handleOnImageLoad", ({
272
+ target
273
+ }) => {
274
+ const {
275
+ onUpdateImageDimension
276
+ } = this.props;
277
+ const resizeHandle = this.resize;
278
+ const elementStyle = getComputedStyle(target);
279
+ const newHeight = parseFloat(elementStyle.height);
280
+ const newWidth = parseFloat(elementStyle.width);
281
+ const aspectWidth = newWidth / IMAGE_MAX_WIDTH;
282
+ const dimensions = newWidth > IMAGE_MAX_WIDTH ? {
308
283
  height: newHeight / aspectWidth,
309
284
  width: IMAGE_MAX_WIDTH
310
285
  } : {
311
286
  height: newHeight,
312
287
  width: newWidth
313
288
  };
314
-
315
- _this.setState({
316
- dimensions: dimensions
317
- }, function () {
318
- return onUpdateImageDimension(dimensions);
319
- });
320
-
321
- resizeHandle.addEventListener('mousedown', _this.initialiseResize, false);
289
+ this.setState({
290
+ dimensions
291
+ }, () => onUpdateImageDimension(dimensions));
292
+ resizeHandle.addEventListener('mousedown', this.initialiseResize, false);
322
293
  });
323
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "initialiseResize", function () {
324
- window.addEventListener('mousemove', _this.startResizing, false);
325
- window.addEventListener('mouseup', _this.stopResizing, false);
294
+ (0, _defineProperty2.default)(this, "initialiseResize", () => {
295
+ window.addEventListener('mousemove', this.startResizing, false);
296
+ window.addEventListener('mouseup', this.stopResizing, false);
326
297
  });
327
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "startResizing", function (e) {
328
- var bounds = e.target.getBoundingClientRect();
329
- var box = _this.image;
330
- var _this$props7 = _this.props,
331
- disableDrag = _this$props7.disableDrag,
332
- preserveAspectRatioEnabled = _this$props7.preserveAspectRatioEnabled,
333
- dimensions = _this$props7.dimensions,
334
- shapes = _this$props7.shapes;
335
-
336
- var _updateImageDimension = (0, _utils.updateImageDimensions)(dimensions, {
298
+ (0, _defineProperty2.default)(this, "startResizing", e => {
299
+ const bounds = e.target.getBoundingClientRect();
300
+ const box = this.image;
301
+ const {
302
+ disableDrag,
303
+ preserveAspectRatioEnabled,
304
+ dimensions,
305
+ shapes
306
+ } = this.props;
307
+ const {
308
+ width,
309
+ height
310
+ } = (0, _utils.updateImageDimensions)(dimensions, {
337
311
  width: e.clientX - bounds.left,
338
312
  height: e.clientY - bounds.top
339
- }, preserveAspectRatioEnabled),
340
- width = _updateImageDimension.width,
341
- height = _updateImageDimension.height;
342
-
343
- var resizeValid = _this.checkIfResizeValid(width, height);
344
-
345
- var hasMinimumWidth = width > 150 && height > 150;
346
-
313
+ }, preserveAspectRatioEnabled);
314
+ const resizeValid = this.checkIfResizeValid(width, height);
315
+ const hasMinimumWidth = width > 150 && height > 150;
347
316
  if (resizeValid && hasMinimumWidth && box) {
348
- box.style.width = "".concat(width, "px");
349
- box.style.height = "".concat(height, "px");
350
-
351
- _this.setState({
317
+ box.style.width = `${width}px`;
318
+ box.style.height = `${height}px`;
319
+ this.setState({
352
320
  resizing: true,
353
321
  dimensions: {
354
322
  height: height,
355
323
  width: width
356
324
  },
357
325
  stateShapes: (0, _utils.getUpdatedShapes)(dimensions, {
358
- width: width,
359
- height: height
326
+ width,
327
+ height
360
328
  }, shapes)
361
329
  });
362
330
  }
363
-
364
331
  disableDrag();
365
332
  });
366
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "stopResizing", function () {
367
- var _this$props8 = _this.props,
368
- enableDrag = _this$props8.enableDrag,
369
- onUpdateImageDimension = _this$props8.onUpdateImageDimension,
370
- onUpdateShapes = _this$props8.onUpdateShapes;
371
- var _this$state = _this.state,
372
- dimensions = _this$state.dimensions,
373
- stateShapes = _this$state.stateShapes;
333
+ (0, _defineProperty2.default)(this, "stopResizing", () => {
334
+ const {
335
+ enableDrag,
336
+ onUpdateImageDimension,
337
+ onUpdateShapes
338
+ } = this.props;
339
+ const {
340
+ dimensions,
341
+ stateShapes
342
+ } = this.state;
374
343
  enableDrag();
375
-
376
344
  if (stateShapes) {
377
- onUpdateShapes((0, _cloneDeep["default"])(stateShapes));
345
+ onUpdateShapes((0, _cloneDeep.default)(stateShapes));
378
346
  }
379
-
380
347
  onUpdateImageDimension(dimensions);
381
- window.removeEventListener('mousemove', _this.startResizing, false);
382
- window.removeEventListener('mouseup', _this.stopResizing, false);
383
-
384
- _this.setState({
348
+ window.removeEventListener('mousemove', this.startResizing, false);
349
+ window.removeEventListener('mouseup', this.stopResizing, false);
350
+ this.setState({
385
351
  resizing: false,
386
352
  stateShapes: false
387
353
  });
388
354
  });
389
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "deleteShape", function (id) {
390
- _this.setState({
355
+ (0, _defineProperty2.default)(this, "deleteShape", id => {
356
+ this.setState({
391
357
  isDrawing: false,
392
358
  isDrawingShapeId: undefined
393
359
  });
394
-
395
- _this.props.onDeleteShape(id);
360
+ this.props.onDeleteShape(id);
396
361
  });
397
- _this.state = {
362
+ this.state = {
398
363
  isDrawing: false,
399
364
  stateShapes: false,
400
365
  resizing: false,
@@ -405,227 +370,150 @@ var Drawable = /*#__PURE__*/function (_React$Component) {
405
370
  width: 0
406
371
  }
407
372
  };
408
- return _this;
409
373
  }
410
-
411
- (0, _createClass2["default"])(Drawable, [{
412
- key: "addPolygonPoint",
413
- value: function addPolygonPoint(e) {
414
- var _this2 = this;
415
-
416
- var _PolygonShape$addPoin = _shapes2.PolygonShape.addPoint(this.state, e, function (newShapes) {
417
- _this2.setState({
418
- isDrawing: false,
419
- shapes: newShapes,
420
- isDrawingShapeId: undefined
421
- });
422
-
423
- _this2.props.onUpdateShapes(newShapes);
424
- }),
425
- shapes = _PolygonShape$addPoin.shapes;
426
-
427
- return shapes;
428
- }
429
- }, {
430
- key: "checkIfResizeValid",
431
- value: function checkIfResizeValid(x, y) {
432
- var shapes = this.state.shapes;
433
- var drawable = true; // Do not allow resizing over the hotspots
434
-
435
- shapes && shapes.forEach(function (shape) {
436
- var right = shape.x + shape.width + 5;
437
- var bottom = shape.y + shape.height + 5;
438
-
439
- if (x <= right || y <= bottom) {
440
- drawable = false;
441
- }
374
+ addPolygonPoint(e) {
375
+ const {
376
+ shapes
377
+ } = _shapes.PolygonShape.addPoint(this.state, e, newShapes => {
378
+ this.setState({
379
+ isDrawing: false,
380
+ shapes: newShapes,
381
+ isDrawingShapeId: undefined
442
382
  });
443
- return drawable;
444
- }
445
- }, {
446
- key: "render",
447
- value: /// end of handling Image section
448
- function render() {
449
- var _this3 = this;
450
-
451
- var _this$props9 = this.props,
452
- classes = _this$props9.classes,
453
- imageUrl = _this$props9.imageUrl,
454
- _this$props9$dimensio = _this$props9.dimensions,
455
- height = _this$props9$dimensio.height,
456
- width = _this$props9$dimensio.width,
457
- hotspotColor = _this$props9.hotspotColor,
458
- outlineColor = _this$props9.outlineColor,
459
- shapes = _this$props9.shapes,
460
- strokeWidth = _this$props9.strokeWidth,
461
- hoverOutlineColor = _this$props9.hoverOutlineColor,
462
- selectedHotspotColor = _this$props9.selectedHotspotColor;
463
- var _this$state2 = this.state,
464
- stateShapes = _this$state2.stateShapes,
465
- isDrawing = _this$state2.isDrawing,
466
- _this$state2$dimensio = _this$state2.dimensions,
467
- heightFromState = _this$state2$dimensio.height,
468
- widthFromState = _this$state2$dimensio.width;
469
- var shapesToUse = stateShapes || shapes;
470
- return /*#__PURE__*/_react["default"].createElement("div", {
471
- className: classes.base
472
- }, imageUrl && /*#__PURE__*/_react["default"].createElement("div", {
473
- className: classes.imageContainer
474
- }, /*#__PURE__*/_react["default"].createElement("img", (0, _extends2["default"])({
475
- className: classes.image,
476
- onLoad: this.handleOnImageLoad,
477
- ref: function ref(_ref2) {
478
- _this3.image = _ref2;
479
- },
480
- src: imageUrl
481
- }, height && width ? {
482
- style: {
483
- height: height,
484
- width: width
485
- }
486
- } : {})), /*#__PURE__*/_react["default"].createElement("div", {
487
- ref: function ref(_ref3) {
488
- _this3.resize = _ref3;
489
- },
490
- className: classes.resize
491
- })), /*#__PURE__*/_react["default"].createElement(_reactKonva.Stage, {
492
- className: classes.stage,
493
- height: heightFromState || height,
494
- width: widthFromState || width,
495
- onMouseDown: this.handleOnMouseDown,
496
- onMouseUp: this.handleOnMouseUp,
497
- onMouseMove: this.handleMouseMove,
498
- onContentMouseOut: this.handleOnMouseOutOrLeave,
499
- onContentMouseLeave: this.handleOnMouseOutOrLeave
500
- }, /*#__PURE__*/_react["default"].createElement(_reactKonva.Layer, null, shapesToUse.map(function (shape, i) {
501
- var Tag;
502
-
503
- switch (shape.group) {
504
- case _shapes2.SHAPE_GROUPS.RECTANGLES:
505
- Tag = _hotspotRectangle["default"];
506
- break;
507
-
508
- case _shapes2.SHAPE_GROUPS.CIRCLES:
509
- Tag = _hotspotCircle["default"];
510
- break;
511
-
512
- case _shapes2.SHAPE_GROUPS.POLYGONS:
513
- Tag = _hotspotPolygon["default"];
514
- break;
515
-
516
- default:
517
- return null;
518
- }
519
-
520
- return /*#__PURE__*/_react["default"].createElement(Tag, (0, _extends2["default"])({}, shape.group === _shapes2.SHAPE_GROUPS.CIRCLES ? {
521
- radius: shape.radius
522
- } : {}, shape.group === _shapes2.SHAPE_GROUPS.RECTANGLES ? {
523
- height: shape.height,
524
- width: shape.width
525
- } : {}, shape.group === _shapes2.SHAPE_GROUPS.POLYGONS ? {
526
- points: shape.points,
527
- addPolygonPoint: function addPolygonPoint(e) {
528
- return _this3.addPolygonPoint(e);
529
- }
530
- } : {}, {
531
- correct: shape.correct,
532
- isDrawing: isDrawing,
533
- hotspotColor: hotspotColor,
534
- hoverOutlineColor: hoverOutlineColor,
535
- selectedHotspotColor: selectedHotspotColor,
536
- id: shape.id,
537
- key: i,
538
- onClick: function onClick() {
539
- return _this3.handleOnSetAsCorrect(shape);
540
- },
541
- onDragEnd: _this3.handleOnDragEnd,
542
- onDeleteShape: _this3.deleteShape,
543
- outlineColor: outlineColor,
544
- width: shape.width,
545
- x: shape.x,
546
- y: shape.y,
547
- strokeWidth: strokeWidth,
548
- imageHeight: heightFromState || height,
549
- imageWidth: widthFromState || width
550
- }, shape.group === 'polygons' ? {
551
- addPolygonPoint: function addPolygonPoint(e) {
552
- return _this3.addPolygonPoint(e);
553
- }
554
- } : {}));
555
- }))));
556
- }
557
- }], [{
558
- key: "getDerivedStateFromProps",
559
- value: function getDerivedStateFromProps(nextProps, prevState) {
560
- // Update the state only if the props have changed
561
- if (nextProps.shapes !== prevState.shapes) {
562
- return {
563
- shapes: nextProps.shapes
564
- };
383
+ this.props.onUpdateShapes(newShapes);
384
+ });
385
+ return shapes;
386
+ }
387
+ checkIfResizeValid(x, y) {
388
+ const {
389
+ shapes
390
+ } = this.state;
391
+ let drawable = true;
392
+
393
+ // Do not allow resizing over the hotspots
394
+ shapes && shapes.forEach(shape => {
395
+ const right = shape.x + shape.width + 5;
396
+ const bottom = shape.y + shape.height + 5;
397
+ if (x <= right || y <= bottom) {
398
+ drawable = false;
565
399
  }
400
+ });
401
+ return drawable;
402
+ }
403
+ /// end of handling Image section
566
404
 
567
- return null;
568
- }
569
- }]);
570
- return Drawable;
571
- }(_react["default"].Component);
572
-
405
+ render() {
406
+ const {
407
+ imageUrl,
408
+ dimensions: {
409
+ height,
410
+ width
411
+ },
412
+ hotspotColor,
413
+ outlineColor,
414
+ shapes,
415
+ strokeWidth,
416
+ hoverOutlineColor,
417
+ selectedHotspotColor
418
+ } = this.props;
419
+ const {
420
+ stateShapes,
421
+ isDrawing,
422
+ dimensions: {
423
+ height: heightFromState,
424
+ width: widthFromState
425
+ }
426
+ } = this.state;
427
+ const shapesToUse = stateShapes || shapes;
428
+ return /*#__PURE__*/_react.default.createElement(BaseContainer, null, imageUrl && /*#__PURE__*/_react.default.createElement(ImageContainer, null, /*#__PURE__*/_react.default.createElement(Image, (0, _extends2.default)({
429
+ onLoad: this.handleOnImageLoad,
430
+ ref: ref => {
431
+ this.image = ref;
432
+ },
433
+ src: imageUrl
434
+ }, height && width ? {
435
+ style: {
436
+ height,
437
+ width
438
+ }
439
+ } : {})), /*#__PURE__*/_react.default.createElement(ResizeHandle, {
440
+ ref: ref => {
441
+ this.resize = ref;
442
+ }
443
+ })), /*#__PURE__*/_react.default.createElement(StyledStage, {
444
+ height: heightFromState || height,
445
+ width: widthFromState || width,
446
+ onMouseDown: this.handleOnMouseDown,
447
+ onMouseUp: this.handleOnMouseUp,
448
+ onMouseMove: this.handleMouseMove,
449
+ onContentMouseOut: this.handleOnMouseOutOrLeave,
450
+ onContentMouseLeave: this.handleOnMouseOutOrLeave
451
+ }, /*#__PURE__*/_react.default.createElement(_reactKonva.Layer, null, shapesToUse.map((shape, i) => {
452
+ let Tag;
453
+ switch (shape.group) {
454
+ case _shapes.SHAPE_GROUPS.RECTANGLES:
455
+ Tag = _hotspotRectangle.default;
456
+ break;
457
+ case _shapes.SHAPE_GROUPS.CIRCLES:
458
+ Tag = _hotspotCircle.default;
459
+ break;
460
+ case _shapes.SHAPE_GROUPS.POLYGONS:
461
+ Tag = _hotspotPolygon.default;
462
+ break;
463
+ default:
464
+ return null;
465
+ }
466
+ return /*#__PURE__*/_react.default.createElement(Tag, (0, _extends2.default)({}, shape.group === _shapes.SHAPE_GROUPS.CIRCLES ? {
467
+ radius: shape.radius
468
+ } : {}, shape.group === _shapes.SHAPE_GROUPS.RECTANGLES ? {
469
+ height: shape.height,
470
+ width: shape.width
471
+ } : {}, shape.group === _shapes.SHAPE_GROUPS.POLYGONS ? {
472
+ points: shape.points,
473
+ addPolygonPoint: e => this.addPolygonPoint(e)
474
+ } : {}, {
475
+ correct: shape.correct,
476
+ isDrawing: isDrawing,
477
+ hotspotColor: hotspotColor,
478
+ hoverOutlineColor: hoverOutlineColor,
479
+ selectedHotspotColor: selectedHotspotColor,
480
+ id: shape.id,
481
+ key: i,
482
+ onClick: () => this.handleOnSetAsCorrect(shape),
483
+ onDragEnd: this.handleOnDragEnd,
484
+ onDeleteShape: this.deleteShape,
485
+ outlineColor: outlineColor,
486
+ width: shape.width,
487
+ x: shape.x,
488
+ y: shape.y,
489
+ strokeWidth: strokeWidth,
490
+ imageHeight: heightFromState || height,
491
+ imageWidth: widthFromState || width
492
+ }, shape.group === 'polygons' ? {
493
+ addPolygonPoint: e => this.addPolygonPoint(e)
494
+ } : {}));
495
+ }))));
496
+ }
497
+ }
573
498
  exports.Drawable = Drawable;
574
-
575
- var styles = function styles() {
576
- return {
577
- base: {
578
- position: 'relative'
579
- },
580
- image: {
581
- alignItems: 'center',
582
- display: 'flex',
583
- justifyContent: 'center'
584
- },
585
- imageContainer: {
586
- position: 'relative',
587
- width: 'fit-content'
588
- },
589
- resize: {
590
- borderBottom: '1px solid #727272',
591
- borderRight: '1px solid #727272',
592
- bottom: '-10px',
593
- cursor: 'se-resize',
594
- height: '10px',
595
- position: 'absolute',
596
- right: '-10px',
597
- width: '10px'
598
- },
599
- stage: {
600
- left: 0,
601
- top: 0,
602
- position: 'absolute'
603
- }
604
- };
605
- };
606
-
607
499
  Drawable.propTypes = {
608
- classes: _propTypes["default"].object.isRequired,
609
- disableDrag: _propTypes["default"].func.isRequired,
610
- dimensions: _propTypes["default"].object.isRequired,
611
- enableDrag: _propTypes["default"].func.isRequired,
612
- shapeType: _propTypes["default"].oneOf(Object.values(_shapes2.SUPPORTED_SHAPES)),
613
- imageUrl: _propTypes["default"].string.isRequired,
614
- handleFinishDrawing: _propTypes["default"].func.isRequired,
615
- hotspotColor: _propTypes["default"].string.isRequired,
616
- selectedHotspotColor: _propTypes["default"].string,
617
- hoverOutlineColor: _propTypes["default"].string,
618
- multipleCorrect: _propTypes["default"].bool.isRequired,
619
- onUpdateImageDimension: _propTypes["default"].func.isRequired,
620
- onUpdateShapes: _propTypes["default"].func.isRequired,
621
- onDeleteShape: _propTypes["default"].func.isRequired,
622
- outlineColor: _propTypes["default"].string.isRequired,
623
- shapes: _propTypes["default"].array.isRequired,
624
- strokeWidth: _propTypes["default"].number,
625
- preserveAspectRatioEnabled: _propTypes["default"].bool
500
+ disableDrag: _propTypes.default.func.isRequired,
501
+ dimensions: _propTypes.default.object.isRequired,
502
+ enableDrag: _propTypes.default.func.isRequired,
503
+ shapeType: _propTypes.default.oneOf(Object.values(_shapes.SUPPORTED_SHAPES)),
504
+ imageUrl: _propTypes.default.string.isRequired,
505
+ handleFinishDrawing: _propTypes.default.func.isRequired,
506
+ hotspotColor: _propTypes.default.string.isRequired,
507
+ selectedHotspotColor: _propTypes.default.string,
508
+ hoverOutlineColor: _propTypes.default.string,
509
+ multipleCorrect: _propTypes.default.bool.isRequired,
510
+ onUpdateImageDimension: _propTypes.default.func.isRequired,
511
+ onUpdateShapes: _propTypes.default.func.isRequired,
512
+ onDeleteShape: _propTypes.default.func.isRequired,
513
+ outlineColor: _propTypes.default.string.isRequired,
514
+ shapes: _propTypes.default.array.isRequired,
515
+ strokeWidth: _propTypes.default.number,
516
+ preserveAspectRatioEnabled: _propTypes.default.bool
626
517
  };
627
-
628
- var _default = (0, _index.withStyles)(styles)(Drawable);
629
-
630
- exports["default"] = _default;
518
+ var _default = exports.default = Drawable;
631
519
  //# sourceMappingURL=hotspot-drawable.js.map