@pie-element/hotspot 5.14.6-next.8 → 5.15.1-next.6

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/CHANGELOG.md CHANGED
@@ -3,6 +3,25 @@
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
+ # [5.15.0](https://github.com/pie-framework/pie-elements/compare/@pie-element/hotspot@5.14.5...@pie-element/hotspot@5.15.0) (2023-09-04)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * update pie-libs PD-3051 ([1e1a7a3](https://github.com/pie-framework/pie-elements/commit/1e1a7a38732eff5585ad789aea5a08c5e94720ae))
12
+ * update snapshots ([7f7432d](https://github.com/pie-framework/pie-elements/commit/7f7432d4e79747bd8824470ea19ebf7d40617fc5))
13
+ * updated pie-libs PD-2765, PD-3051 ([e6f5b17](https://github.com/pie-framework/pie-elements/commit/e6f5b17c95faf426898f897651863089a54ff3ff))
14
+
15
+
16
+ ### Features
17
+
18
+ * **hotspot:** translations PD-2802 PD-2795 ([15b03fd](https://github.com/pie-framework/pie-elements/commit/15b03fd1d6659364c4d765406c807d30dc5375d1))
19
+ * **select-text, inline-dropdown:** PD-2797-PD-2802 update documentation ([b8ba6c7](https://github.com/pie-framework/pie-elements/commit/b8ba6c7d12eea9d0d729a38e18e87a21ea496a8b))
20
+
21
+
22
+
23
+
24
+
6
25
  ## [5.14.5](https://github.com/pie-framework/pie-elements/compare/@pie-element/hotspot@5.14.4...@pie-element/hotspot@5.14.5) (2023-08-21)
7
26
 
8
27
 
@@ -3,6 +3,24 @@
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
+ # [5.11.0](https://github.com/pie-framework/pie-elements/compare/@pie-element/hotspot-configure@5.10.5...@pie-element/hotspot-configure@5.11.0) (2023-09-04)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * update pie-libs PD-3051 ([1e1a7a3](https://github.com/pie-framework/pie-elements/commit/1e1a7a38732eff5585ad789aea5a08c5e94720ae))
12
+ * update snapshots ([7f7432d](https://github.com/pie-framework/pie-elements/commit/7f7432d4e79747bd8824470ea19ebf7d40617fc5))
13
+ * updated pie-libs PD-2765, PD-3051 ([e6f5b17](https://github.com/pie-framework/pie-elements/commit/e6f5b17c95faf426898f897651863089a54ff3ff))
14
+
15
+
16
+ ### Features
17
+
18
+ * **hotspot:** translations PD-2802 PD-2795 ([15b03fd](https://github.com/pie-framework/pie-elements/commit/15b03fd1d6659364c4d765406c807d30dc5375d1))
19
+
20
+
21
+
22
+
23
+
6
24
  ## [5.10.5](https://github.com/pie-framework/pie-elements/compare/@pie-element/hotspot-configure@5.10.4...@pie-element/hotspot-configure@5.10.5) (2023-08-21)
7
25
 
8
26
 
@@ -79,6 +79,15 @@ var _default = {
79
79
  mathMlOptions: {
80
80
  mmlOutput: false,
81
81
  mmlEditing: false
82
+ },
83
+ language: {
84
+ settings: false,
85
+ label: 'Specify Language',
86
+ enabled: false
87
+ },
88
+ languageChoices: {
89
+ label: 'Language Choices',
90
+ options: []
82
91
  }
83
92
  }
84
93
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/defaults.js"],"names":["model","prompt","toolbarEditorPosition","imageUrl","shapes","rectangles","polygons","multipleCorrect","partialScoring","dimensions","height","width","hotspotColor","hotspotList","outlineColor","outlineList","promptEnabled","rationaleEnabled","teacherInstructionsEnabled","studentInstructionsEnabled","strokeWidth","configuration","settings","label","rationale","settingsPanelDisabled","spellCheck","enabled","teacherInstructions","preserveAspectRatio","minShapes","maxImageWidth","maxImageHeight","withRubric","mathMlOptions","mmlOutput","mmlEditing"],"mappings":";;;;;;eAAe;AACbA,EAAAA,KAAK,EAAE;AACLC,IAAAA,MAAM,EAAE,EADH;AAELC,IAAAA,qBAAqB,EAAE,QAFlB;AAGLC,IAAAA,QAAQ,EAAE,EAHL;AAILC,IAAAA,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C,MAAAA,KAAK,EAAE;AAFY,KAvBR;AA2BbM,IAAAA,mBAAmB,EAAE;AACnBP,MAAAA,QAAQ,EAAE,KADS;AAEnBK,MAAAA,OAAO,EAAE,IAFU;AAGnBJ,MAAAA,KAAK,EAAE;AAHY,KA3BR;AAgCbO,IAAAA,SAAS,EAAE,CAhCE;AAiCbC,IAAAA,aAAa,EAAE;AACbH,MAAAA,mBAAmB,EAAE,GADR;AAEb3B,MAAAA,MAAM,EAAE,GAFK;AAGbuB,MAAAA,SAAS,EAAE;AAHE,KAjCF;AAsCbQ,IAAAA,cAAc,EAAE;AACdJ,MAAAA,mBAAmB,EAAE,GADP;AAEd3B,MAAAA,MAAM,EAAE,GAFM;AAGduB,MAAAA,SAAS,EAAE;AAHG,KAtCH;AA2CbS,IAAAA,UAAU,EAAE;AACVX,MAAAA,QAAQ,EAAE,KADA;AAEVC,MAAAA,KAAK,EAAE;AAFG,KA3CC;AA+CbW,IAAAA,aAAa,EAAE;AACbC,MAAAA,SAAS,EAAE,KADE;AAEbC,MAAAA,UAAU,EAAE;AAFC;AA/CF;AAzBF,C","sourcesContent":["export default {\n model: {\n prompt: '',\n toolbarEditorPosition: 'bottom',\n imageUrl: '',\n shapes: {\n rectangles: [],\n polygons: [],\n },\n multipleCorrect: true,\n partialScoring: false,\n dimensions: {\n height: 0,\n width: 0,\n },\n hotspotColor: 'rgba(137, 183, 244, 0.25)',\n hotspotList: ['rgba(137, 183, 244, 0.25)'],\n outlineColor: 'blue',\n outlineList: ['blue'],\n promptEnabled: true,\n rationaleEnabled: true,\n teacherInstructionsEnabled: true,\n studentInstructionsEnabled: true,\n strokeWidth: 5,\n },\n configuration: {\n multipleCorrect: {\n settings: true,\n label: 'Multiple Correct Responses',\n },\n partialScoring: {\n settings: false,\n label: 'Allow Partial Scoring',\n },\n rationale: {\n settings: true,\n label: 'Rationale',\n },\n prompt: {\n settings: true,\n label: 'Prompt',\n },\n settingsPanelDisabled: false,\n spellCheck: {\n label: 'Spellcheck',\n settings: false,\n enabled: true,\n },\n teacherInstructions: {\n settings: true,\n label: 'Teacher Instructions',\n },\n preserveAspectRatio: {\n settings: false,\n enabled: true,\n label: 'Preserve aspect ratio',\n },\n minShapes: 2,\n maxImageWidth: {\n teacherInstructions: 300,\n prompt: 300,\n rationale: 300,\n },\n maxImageHeight: {\n teacherInstructions: 300,\n prompt: 300,\n rationale: 300,\n },\n withRubric: {\n settings: false,\n label: 'Add Rubric',\n },\n mathMlOptions: {\n mmlOutput: false,\n mmlEditing: false,\n },\n },\n};\n"],"file":"defaults.js"}
1
+ {"version":3,"sources":["../src/defaults.js"],"names":["model","prompt","toolbarEditorPosition","imageUrl","shapes","rectangles","polygons","multipleCorrect","partialScoring","dimensions","height","width","hotspotColor","hotspotList","outlineColor","outlineList","promptEnabled","rationaleEnabled","teacherInstructionsEnabled","studentInstructionsEnabled","strokeWidth","configuration","settings","label","rationale","settingsPanelDisabled","spellCheck","enabled","teacherInstructions","preserveAspectRatio","minShapes","maxImageWidth","maxImageHeight","withRubric","mathMlOptions","mmlOutput","mmlEditing","language","languageChoices","options"],"mappings":";;;;;;eAAe;AACbA,EAAAA,KAAK,EAAE;AACLC,IAAAA,MAAM,EAAE,EADH;AAELC,IAAAA,qBAAqB,EAAE,QAFlB;AAGLC,IAAAA,QAAQ,EAAE,EAHL;AAILC,IAAAA,MAAM,EAAE;AACNC,MAAAA,UAAU,EAAE,EADN;AAENC,MAAAA,QAAQ,EAAE;AAFJ,KAJH;AAQLC,IAAAA,eAAe,EAAE,IARZ;AASLC,IAAAA,cAAc,EAAE,KATX;AAULC,IAAAA,UAAU,EAAE;AACVC,MAAAA,MAAM,EAAE,CADE;AAEVC,MAAAA,KAAK,EAAE;AAFG,KAVP;AAcLC,IAAAA,YAAY,EAAE,2BAdT;AAeLC,IAAAA,WAAW,EAAE,CAAC,2BAAD,CAfR;AAgBLC,IAAAA,YAAY,EAAE,MAhBT;AAiBLC,IAAAA,WAAW,EAAE,CAAC,MAAD,CAjB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AE,GADP;AAEd3B,MAAAA,MAAM,EAAE,GAFM;AAGduB,MAAAA,SAAS,EAAE;AAHG,KAtCH;AA2CbS,IAAAA,UAAU,EAAE;AACVX,MAAAA,QAAQ,EAAE,KADA;AAEVC,MAAAA,KAAK,EAAE;AAFG,KA3CC;AA+CbW,IAAAA,aAAa,EAAE;AACbC,MAAAA,SAAS,EAAE,KADE;AAEbC,MAAAA,UAAU,EAAE;AAFC,KA/CF;AAmDbC,IAAAA,QAAQ,EAAE;AACRf,MAAAA,QAAQ,EAAE,KADF;AAERC,MAAAA,KAAK,EAAE,kBAFC;AAGRI,MAAAA,OAAO,EAAE;AAHD,KAnDG;AAwDbW,IAAAA,eAAe,EAAE;AACff,MAAAA,KAAK,EAAE,kBADQ;AAEfgB,MAAAA,OAAO,EAAE;AAFM;AAxDJ;AAzBF,C","sourcesContent":["export default {\n model: {\n prompt: '',\n toolbarEditorPosition: 'bottom',\n imageUrl: '',\n shapes: {\n rectangles: [],\n polygons: [],\n },\n multipleCorrect: true,\n partialScoring: false,\n dimensions: {\n height: 0,\n width: 0,\n },\n hotspotColor: 'rgba(137, 183, 244, 0.25)',\n hotspotList: ['rgba(137, 183, 244, 0.25)'],\n outlineColor: 'blue',\n outlineList: ['blue'],\n promptEnabled: true,\n rationaleEnabled: true,\n teacherInstructionsEnabled: true,\n studentInstructionsEnabled: true,\n strokeWidth: 5,\n },\n configuration: {\n multipleCorrect: {\n settings: true,\n label: 'Multiple Correct Responses',\n },\n partialScoring: {\n settings: false,\n label: 'Allow Partial Scoring',\n },\n rationale: {\n settings: true,\n label: 'Rationale',\n },\n prompt: {\n settings: true,\n label: 'Prompt',\n },\n settingsPanelDisabled: false,\n spellCheck: {\n label: 'Spellcheck',\n settings: false,\n enabled: true,\n },\n teacherInstructions: {\n settings: true,\n label: 'Teacher Instructions',\n },\n preserveAspectRatio: {\n settings: false,\n enabled: true,\n label: 'Preserve aspect ratio',\n },\n minShapes: 2,\n maxImageWidth: {\n teacherInstructions: 300,\n prompt: 300,\n rationale: 300,\n },\n maxImageHeight: {\n teacherInstructions: 300,\n prompt: 300,\n rationale: 300,\n },\n withRubric: {\n settings: false,\n label: 'Add Rubric',\n },\n mathMlOptions: {\n mmlOutput: false,\n mmlEditing: false,\n },\n language: {\n settings: false,\n label: 'Specify Language',\n enabled: false,\n },\n languageChoices: {\n label: 'Language Choices',\n options: [],\n },\n },\n};\n"],"file":"defaults.js"}
@@ -31,10 +31,16 @@ var _reactKonva = require("react-konva");
31
31
 
32
32
  var _index = require("@material-ui/core/styles/index");
33
33
 
34
+ 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; }
35
+
36
+ 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; }
37
+
34
38
  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); }; }
35
39
 
36
40
  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; } }
37
41
 
42
+ var HOVERED_COLOR = '#00BFFF';
43
+
38
44
  var PolComponent = /*#__PURE__*/function (_React$Component) {
39
45
  (0, _inherits2["default"])(PolComponent, _React$Component);
40
46
 
@@ -50,7 +56,49 @@ var PolComponent = /*#__PURE__*/function (_React$Component) {
50
56
  }
51
57
 
52
58
  _this = _super.call.apply(_super, [this].concat(args));
53
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "state", {});
59
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "getOffset", function (points) {
60
+ var xList = points.map(function (p) {
61
+ return p.x;
62
+ });
63
+ var yList = points.map(function (p) {
64
+ return p.y;
65
+ });
66
+ return {
67
+ x: Math.min.apply(Math, (0, _toConsumableArray2["default"])(xList)),
68
+ y: Math.max.apply(Math, (0, _toConsumableArray2["default"])(yList))
69
+ };
70
+ });
71
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "serialize", function (points) {
72
+ var _this$getOffset = _this.getOffset(points),
73
+ xOffset = _this$getOffset.x,
74
+ yOffset = _this$getOffset.y;
75
+
76
+ return points.reduce(function (acc, point) {
77
+ return [].concat((0, _toConsumableArray2["default"])(acc), [point.x - xOffset, point.y - yOffset]);
78
+ }, []);
79
+ });
80
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "getInitialState", function (points) {
81
+ if (points.length) {
82
+ var _this$getOffset2 = _this.getOffset(points),
83
+ x = _this$getOffset2.x,
84
+ y = _this$getOffset2.y;
85
+
86
+ return {
87
+ x: x,
88
+ y: y,
89
+ points: points
90
+ };
91
+ }
92
+
93
+ return {
94
+ x: 0,
95
+ y: 0,
96
+ points: []
97
+ };
98
+ });
99
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "state", _objectSpread({
100
+ hovered: false
101
+ }, _this.getInitialState(_this.props.points)));
54
102
  (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "handleClick", function (e) {
55
103
  var points = _this.props.points;
56
104
  var xList = points.map(function (p) {
@@ -74,32 +122,69 @@ var PolComponent = /*#__PURE__*/function (_React$Component) {
74
122
  onClick(id);
75
123
  });
76
124
  (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "handleMouseEnter", function () {
125
+ _this.setState({
126
+ hovered: true
127
+ });
128
+
77
129
  document.body.style.cursor = 'pointer';
78
130
  });
79
131
  (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "handleMouseLeave", function () {
132
+ _this.setState({
133
+ hovered: false
134
+ });
135
+
80
136
  document.body.style.cursor = 'default';
81
137
  });
82
138
  (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "handleOnDragEnd", function (e) {
139
+ var updateModel = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
83
140
  var _this$props2 = _this.props,
84
141
  onDragEnd = _this$props2.onDragEnd,
85
142
  id = _this$props2.id;
86
143
 
87
- var points = e.target.points() || _this.state.points;
144
+ var points = e.target.points() || _this.serialize(_this.state.points);
88
145
 
89
146
  var newPoints = points.reduce(function (acc, currentPointCoordinate, index) {
90
147
  if (index % 2 === 0 && index + 1 < points.length) {
91
- acc.push({
148
+ return [].concat((0, _toConsumableArray2["default"])(acc), [{
92
149
  x: currentPointCoordinate + e.target.x(),
93
150
  y: points[index + 1] + e.target.y()
94
- });
95
- return acc;
96
- } else {
97
- return acc;
151
+ }]);
98
152
  }
153
+
154
+ return acc;
99
155
  }, []);
100
- onDragEnd(id, {
156
+
157
+ _this.setState(_objectSpread({
101
158
  points: newPoints
159
+ }, _this.getOffset(newPoints)));
160
+
161
+ if (updateModel) {
162
+ onDragEnd(id, {
163
+ points: newPoints
164
+ });
165
+ }
166
+ });
167
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "handleOnDragVertex", function (e, changedIndex, updateModel) {
168
+ var _this$props3 = _this.props,
169
+ onDragEnd = _this$props3.onDragEnd,
170
+ id = _this$props3.id;
171
+ var points = _this.state.points;
172
+ var newPoints = points.map(function (point, index) {
173
+ return index === changedIndex ? {
174
+ x: e.target.x(),
175
+ y: e.target.y()
176
+ } : point;
102
177
  });
178
+
179
+ _this.setState(_objectSpread({
180
+ points: newPoints
181
+ }, _this.getOffset(newPoints)));
182
+
183
+ if (updateModel) {
184
+ onDragEnd(id, {
185
+ points: newPoints
186
+ });
187
+ }
103
188
  });
104
189
  return _this;
105
190
  }
@@ -107,63 +192,62 @@ var PolComponent = /*#__PURE__*/function (_React$Component) {
107
192
  (0, _createClass2["default"])(PolComponent, [{
108
193
  key: "render",
109
194
  value: function render() {
110
- var _this$props3 = this.props,
111
- classes = _this$props3.classes,
112
- correct = _this$props3.correct,
113
- hotspotColor = _this$props3.hotspotColor,
114
- outlineColor = _this$props3.outlineColor,
115
- _this$props3$strokeWi = _this$props3.strokeWidth,
116
- strokeWidth = _this$props3$strokeWi === void 0 ? 5 : _this$props3$strokeWi;
195
+ var _this2 = this;
196
+
197
+ var _this$props4 = this.props,
198
+ classes = _this$props4.classes,
199
+ correct = _this$props4.correct,
200
+ hotspotColor = _this$props4.hotspotColor,
201
+ outlineColor = _this$props4.outlineColor,
202
+ _this$props4$strokeWi = _this$props4.strokeWidth,
203
+ strokeWidth = _this$props4$strokeWi === void 0 ? 5 : _this$props4$strokeWi;
117
204
  var _this$state = this.state,
118
205
  points = _this$state.points,
119
206
  x = _this$state.x,
120
- y = _this$state.y;
121
- return /*#__PURE__*/_react["default"].createElement(_reactKonva.Group, null, /*#__PURE__*/_react["default"].createElement(_reactKonva.Line, {
207
+ y = _this$state.y,
208
+ hovered = _this$state.hovered;
209
+ var calculatedStrokeWidth = correct ? strokeWidth : hovered ? 1 : 0;
210
+ var calculatedStroke = correct ? outlineColor : hovered ? HOVERED_COLOR : '';
211
+ return /*#__PURE__*/_react["default"].createElement(_reactKonva.Group, {
212
+ classes: classes.group,
213
+ onMouseLeave: this.handleMouseLeave,
214
+ onMouseEnter: this.handleMouseEnter
215
+ }, /*#__PURE__*/_react["default"].createElement(_reactKonva.Line, {
122
216
  classes: classes.base,
123
- points: points,
217
+ points: this.serialize(points),
124
218
  closed: true,
125
219
  fill: hotspotColor,
126
220
  onClick: this.handleClick,
127
221
  onTap: this.handleClick,
128
222
  draggable: true,
129
- stroke: outlineColor,
130
- strokeWidth: correct ? strokeWidth : 0,
131
- onMouseLeave: this.handleMouseLeave,
132
- onMouseEnter: this.handleMouseEnter,
133
- onDragEnd: this.handleOnDragEnd,
223
+ stroke: calculatedStroke,
224
+ strokeWidth: calculatedStrokeWidth,
225
+ onDragMove: this.handleOnDragEnd,
226
+ onDragEnd: function onDragEnd(e) {
227
+ return _this2.handleOnDragEnd(e, true);
228
+ },
134
229
  x: x,
135
230
  y: y
231
+ }), hovered && points.map(function (point, index) {
232
+ return /*#__PURE__*/_react["default"].createElement(_reactKonva.Circle, {
233
+ key: index,
234
+ className: classes.circle,
235
+ x: point.x,
236
+ y: point.y,
237
+ radius: 5,
238
+ fill: 'white',
239
+ stroke: HOVERED_COLOR,
240
+ strokeWidth: 1,
241
+ draggable: true,
242
+ onDragMove: function onDragMove(e) {
243
+ _this2.handleOnDragVertex(e, index);
244
+ },
245
+ onDragEnd: function onDragEnd(e) {
246
+ _this2.handleOnDragVertex(e, index, true);
247
+ }
248
+ });
136
249
  }));
137
250
  }
138
- }], [{
139
- key: "getDerivedStateFromProps",
140
- value: function getDerivedStateFromProps(nextProps) {
141
- var points = nextProps.points;
142
- var xList = points.map(function (p) {
143
- return p.x;
144
- });
145
- var yList = points.map(function (p) {
146
- return p.y;
147
- });
148
- var xOffset = Math.min.apply(Math, (0, _toConsumableArray2["default"])(xList));
149
- var yOffset = Math.max.apply(Math, (0, _toConsumableArray2["default"])(yList));
150
-
151
- if (points.length) {
152
- return {
153
- x: xOffset,
154
- y: yOffset,
155
- points: points.reduce(function (acc, point) {
156
- return acc.concat([point.x - xOffset, point.y - yOffset]);
157
- }, [])
158
- };
159
- }
160
-
161
- return {
162
- x: 0,
163
- y: 0,
164
- points: []
165
- };
166
- }
167
251
  }]);
168
252
  return PolComponent;
169
253
  }(_react["default"].Component);
@@ -173,6 +257,12 @@ var styles = function styles() {
173
257
  base: {
174
258
  cursor: 'pointer',
175
259
  opacity: 0.5
260
+ },
261
+ circle: {
262
+ opacity: 4
263
+ },
264
+ group: {
265
+ padding: '12px'
176
266
  }
177
267
  };
178
268
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/hotspot-polygon.jsx"],"names":["PolComponent","e","points","props","xList","map","p","x","yList","y","width","Math","max","min","height","isDrawing","onClick","id","cancelBubble","document","body","style","cursor","onDragEnd","target","state","newPoints","reduce","acc","currentPointCoordinate","index","length","push","classes","correct","hotspotColor","outlineColor","strokeWidth","base","handleClick","handleMouseLeave","handleMouseEnter","handleOnDragEnd","nextProps","xOffset","yOffset","point","concat","React","Component","styles","opacity","propTypes","PropTypes","object","isRequired","bool","string","func","arrayOf","shape","number","defaultProps"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;;;;;IAEMA,Y;;;;;;;;;;;;;;;8FA0BI,E;oGAEM,UAACC,CAAD,EAAO;AACnB,UAAQC,MAAR,GAAmB,MAAKC,KAAxB,CAAQD,MAAR;AACA,UAAME,KAAK,GAAGF,MAAM,CAACG,GAAP,CAAW,UAACC,CAAD;AAAA,eAAOA,CAAC,CAACC,CAAT;AAAA,OAAX,CAAd;AACA,UAAMC,KAAK,GAAGN,MAAM,CAACG,GAAP,CAAW,UAACC,CAAD;AAAA,eAAOA,CAAC,CAACG,CAAT;AAAA,OAAX,CAAd;AAEA,UAAMC,KAAK,GAAGC,IAAI,CAACC,GAAL,OAAAD,IAAI,sCAAQP,KAAR,EAAJ,GAAqBO,IAAI,CAACE,GAAL,OAAAF,IAAI,sCAAQP,KAAR,EAAvC;AACA,UAAMU,MAAM,GAAGH,IAAI,CAACC,GAAL,OAAAD,IAAI,sCAAQH,KAAR,EAAJ,GAAqBG,IAAI,CAACE,GAAL,OAAAF,IA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SAAS,EAAEsC,sBAAUG,IAAV,CAAeD,UAHH;AAIvBtC,EAAAA,EAAE,EAAEoC,sBAAUI,MAAV,CAAiBF,UAJE;AAKvBpB,EAAAA,YAAY,EAAEkB,sBAAUI,MAAV,CAAiBF,UALR;AAMvBvC,EAAAA,OAAO,EAAEqC,sBAAUK,IAAV,CAAeH,UAND;AAOvBhC,EAAAA,SAAS,EAAE8B,sBAAUK,IAAV,CAAeH,UAPH;AAQvBnB,EAAAA,YAAY,EAAEiB,sBAAUI,MAAV,CAAiBF,UARR;AASvBrD,EAAAA,MAAM,EAAEmD,sBAAUM,OAAV,CACNN,sBAAUO,KAAV,CAAgB;AACdrD,IAAAA,CAAC,EAAE8C,sBAAUQ,MADC;AAEdpD,IAAAA,CAAC,EAAE4C,sBAAUQ;AAFC,GAAhB,CADM,EAKNN,UAdqB;AAevBlB,EAAAA,WAAW,EAAEgB,sBAAUQ;AAfA,CAAzB;AAkBA7D,YAAY,CAAC8D,YAAb,GAA4B;AAC1B5B,EAAAA,OAAO,EAAE;AADiB,CAA5B;;eAIe,uBAAWgB,MAAX,EAAmBlD,YAAnB,C","sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\nimport { Group, Line } from 'react-konva';\nimport { withStyles } from '@material-ui/core/styles/index';\n\nclass PolComponent extends React.Component {\n static getDerivedStateFromProps(nextProps) {\n const { points } = nextProps;\n const xList = points.map((p) => p.x);\n const yList = points.map((p) => p.y);\n\n const xOffset = Math.min(...xList);\n const yOffset = Math.max(...yList);\n\n if (points.length) {\n return {\n x: xOffset,\n y: yOffset,\n points: points.reduce((acc, point) => {\n return acc.concat([point.x - xOffset, point.y - yOffset]);\n }, []),\n };\n }\n\n return {\n x: 0,\n y: 0,\n points: [],\n };\n }\n\n state = {};\n\n handleClick = (e) => {\n const { points } = this.props;\n const xList = points.map((p) => p.x);\n const yList = points.map((p) => p.y);\n\n const width = Math.max(...xList) - Math.min(...xList);\n const height = Math.max(...yList) - Math.min(...yList);\n\n const { isDrawing, onClick, id } = this.props;\n\n if (width < 0 && height < 0 && isDrawing) {\n return;\n }\n\n e.cancelBubble = true;\n onClick(id);\n };\n\n handleMouseEnter = () => {\n document.body.style.cursor = 'pointer';\n };\n\n handleMouseLeave = () => {\n document.body.style.cursor = 'default';\n };\n\n handleOnDragEnd = (e) => {\n const { onDragEnd, id } = this.props;\n const points = e.target.points() || this.state.points;\n\n const newPoints = points.reduce((acc, currentPointCoordinate, index) => {\n if (index % 2 === 0 && index + 1 < points.length) {\n acc.push({\n x: currentPointCoordinate + e.target.x(),\n y: points[index + 1] + e.target.y(),\n });\n\n return acc;\n } else {\n return acc;\n }\n }, []);\n\n onDragEnd(id, {\n points: newPoints,\n });\n };\n\n render() {\n const { classes, correct, hotspotColor, outlineColor, strokeWidth = 5 } = this.props;\n const { points, x, y } = this.state;\n\n return (\n <Group>\n <Line\n classes={classes.base}\n points={points}\n closed={true}\n fill={hotspotColor}\n onClick={this.handleClick}\n onTap={this.handleClick}\n draggable\n stroke={outlineColor}\n strokeWidth={correct ? strokeWidth : 0}\n onMouseLeave={this.handleMouseLeave}\n onMouseEnter={this.handleMouseEnter}\n onDragEnd={this.handleOnDragEnd}\n x={x}\n y={y}\n />\n </Group>\n );\n }\n}\n\nconst styles = () => ({\n base: {\n cursor: 'pointer',\n opacity: 0.5,\n },\n});\n\nPolComponent.propTypes = {\n classes: PropTypes.object.isRequired,\n correct: PropTypes.bool,\n isDrawing: PropTypes.bool.isRequired,\n id: PropTypes.string.isRequired,\n hotspotColor: PropTypes.string.isRequired,\n onClick: PropTypes.func.isRequired,\n onDragEnd: PropTypes.func.isRequired,\n outlineColor: PropTypes.string.isRequired,\n points: PropTypes.arrayOf(\n PropTypes.shape({\n x: PropTypes.number,\n y: PropTypes.number,\n }),\n ).isRequired,\n strokeWidth: PropTypes.number,\n};\n\nPolComponent.defaultProps = {\n correct: false,\n};\n\nexport default withStyles(styles)(PolComponent);\n"],"file":"hotspot-polygon.js"}
1
+ {"version":3,"sources":["../src/hotspot-polygon.jsx"],"names":["HOVERED_COLOR","PolComponent","points","xList","map","p","x","yList","y","Math","min","max","getOffset","xOffset","yOffset","reduce","acc","point","length","hovered","getInitialState","props","e","width","height","isDrawing","onClick","id","cancelBubble","setState","document","body","style","cursor","updateModel","onDragEnd","target","serialize","state","newPoints","currentPointCoordinate","index","changedIndex","classes","correct","hotspotColor","outlineColor","strokeWidth","calculatedStrokeWidth","calculatedStroke","group","handleMouseLeave","handleMouseEnter","base","handleClick","handleOnDragEnd","circle","handleOnDragVertex","React","Component","styles","opacity","padding","propTypes","PropTypes","object","isRequired","bool","string","func","arrayOf","shape","number","defaultProps"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;;;;;;;;;AAEA,IAAMA,aAAa,GAAG,SAAtB;;IAEMC,Y;;;;;;;;;;;;;;;kGACQ,UAACC,MAAD,EAAY;AACtB,UAAMC,KAAK,GAAGD,MAAM,CAACE,GAAP,CAAW,UAACC,CAAD;AAAA,eAAOA,CAAC,CAACC,CAAT;AAAA,OAAX,CAAd;AACA,UAAMC,KAAK,GAAGL,MAAM,CAACE,GAAP,CAAW,UAACC,CAAD;AAAA,eAAOA,CAAC,CAACG,CAAT;AAAA,OAAX,CAAd;AAEA,aAAO;AACLF,QAAAA,CAAC,EAAEG,IAAI,CAACC,GAAL,OAAAD,IAAI,sCAAQN,KAAR,EADF;AAELK,QAAAA,CAAC,EAAEC,IAAI,CAACE,GAAL,OAAAF,IAAI,sCAAQF,KAAR;AAFF,OAAP;AAID,K;kGAEW,UAACL,MAAD,EAAY;AACtB,4BAAmC,MAAKU,SAAL,CAAeV,MAAf,CAAnC;AAAA,UAAWW,OAAX,mBAAQP,CAAR;AAAA,UAAuBQ,OAAvB,mBAAoBN,CAApB;;AAEA,aAAON,MAAM,CAACa,MAAP,CAAc,UAACC,GAAD,EAAMC,KAAN;AAAA,6DAAoBD,GAApB,IAAyBC,KAAK,CAACX,CAAN,GAAUO,OAAn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,sBAAUI,MAAV,CAAiBF,UAJE;AAKvBrB,EAAAA,YAAY,EAAEmB,sBAAUI,MAAV,CAAiBF,UALR;AAMvBxC,EAAAA,OAAO,EAAEsC,sBAAUK,IAAV,CAAeH,UAND;AAOvB/B,EAAAA,SAAS,EAAE6B,sBAAUK,IAAV,CAAeH,UAPH;AAQvBpB,EAAAA,YAAY,EAAEkB,sBAAUI,MAAV,CAAiBF,UARR;AASvBhE,EAAAA,MAAM,EAAE8D,sBAAUM,OAAV,CACNN,sBAAUO,KAAV,CAAgB;AACdjE,IAAAA,CAAC,EAAE0D,sBAAUQ,MADC;AAEdhE,IAAAA,CAAC,EAAEwD,sBAAUQ;AAFC,GAAhB,CADM,EAKNN,UAdqB;AAevBnB,EAAAA,WAAW,EAAEiB,sBAAUQ;AAfA,CAAzB;AAkBAvE,YAAY,CAACwE,YAAb,GAA4B;AAC1B7B,EAAAA,OAAO,EAAE;AADiB,CAA5B;;eAIe,uBAAWgB,MAAX,EAAmB3D,YAAnB,C","sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\nimport { Group, Line, Circle } from 'react-konva';\nimport { withStyles } from '@material-ui/core/styles/index';\n\nconst HOVERED_COLOR = '#00BFFF';\n\nclass PolComponent extends React.Component {\n getOffset = (points) => {\n const xList = points.map((p) => p.x);\n const yList = points.map((p) => p.y);\n\n return {\n x: Math.min(...xList),\n y: Math.max(...yList),\n };\n };\n\n serialize = (points) => {\n const { x: xOffset, y: yOffset } = this.getOffset(points);\n\n return points.reduce((acc, point) => [...acc, point.x - xOffset, point.y - yOffset], []);\n };\n\n getInitialState = (points) => {\n if (points.length) {\n const { x, y } = this.getOffset(points);\n\n return {\n x,\n y,\n points,\n };\n }\n\n return {\n x: 0,\n y: 0,\n points: [],\n };\n };\n\n state = {\n hovered: false,\n ...this.getInitialState(this.props.points),\n };\n\n handleClick = (e) => {\n const { points } = this.props;\n const xList = points.map((p) => p.x);\n const yList = points.map((p) => p.y);\n\n const width = Math.max(...xList) - Math.min(...xList);\n const height = Math.max(...yList) - Math.min(...yList);\n\n const { isDrawing, onClick, id } = this.props;\n\n if (width < 0 && height < 0 && isDrawing) {\n return;\n }\n\n e.cancelBubble = true;\n onClick(id);\n };\n\n handleMouseEnter = () => {\n this.setState({ hovered: true });\n document.body.style.cursor = 'pointer';\n };\n\n handleMouseLeave = () => {\n this.setState({ hovered: false });\n document.body.style.cursor = 'default';\n };\n\n handleOnDragEnd = (e, updateModel = false) => {\n const { onDragEnd, id } = this.props;\n const points = e.target.points() || this.serialize(this.state.points);\n\n const newPoints = points.reduce((acc, currentPointCoordinate, index) => {\n if (index % 2 === 0 && index + 1 < points.length) {\n return [\n ...acc,\n {\n x: currentPointCoordinate + e.target.x(),\n y: points[index + 1] + e.target.y(),\n },\n ];\n }\n\n return acc;\n }, []);\n\n this.setState({ points: newPoints, ...this.getOffset(newPoints) });\n\n if (updateModel) {\n onDragEnd(id, { points: newPoints });\n }\n };\n\n handleOnDragVertex = (e, changedIndex, updateModel) => {\n const { onDragEnd, id } = this.props;\n const { points } = this.state;\n\n const newPoints = points.map((point, index) =>\n index === changedIndex ? { x: e.target.x(), y: e.target.y() } : point,\n );\n\n this.setState({ points: newPoints, ...this.getOffset(newPoints) });\n\n if (updateModel) {\n onDragEnd(id, { points: newPoints });\n }\n };\n\n render() {\n const { classes, correct, hotspotColor, outlineColor, strokeWidth = 5 } = this.props;\n const { points, x, y, hovered } = this.state;\n\n const calculatedStrokeWidth = correct ? strokeWidth : hovered ? 1 : 0;\n const calculatedStroke = correct ? outlineColor : hovered ? HOVERED_COLOR : '';\n\n return (\n <Group classes={classes.group} onMouseLeave={this.handleMouseLeave} onMouseEnter={this.handleMouseEnter}>\n <Line\n classes={classes.base}\n points={this.serialize(points)}\n closed={true}\n fill={hotspotColor}\n onClick={this.handleClick}\n onTap={this.handleClick}\n draggable\n stroke={calculatedStroke}\n strokeWidth={calculatedStrokeWidth}\n onDragMove={this.handleOnDragEnd}\n onDragEnd={(e) => this.handleOnDragEnd(e, true)}\n x={x}\n y={y}\n />\n\n {hovered &&\n points.map((point, index) => (\n <Circle\n key={index}\n className={classes.circle}\n x={point.x}\n y={point.y}\n radius={5}\n fill={'white'}\n stroke={HOVERED_COLOR}\n strokeWidth={1}\n draggable\n onDragMove={(e) => {\n this.handleOnDragVertex(e, index);\n }}\n onDragEnd={(e) => {\n this.handleOnDragVertex(e, index, true);\n }}\n />\n ))}\n </Group>\n );\n }\n}\n\nconst styles = () => ({\n base: {\n cursor: 'pointer',\n opacity: 0.5,\n },\n circle: {\n opacity: 4,\n },\n group: {\n padding: '12px',\n },\n});\n\nPolComponent.propTypes = {\n classes: PropTypes.object.isRequired,\n correct: PropTypes.bool,\n isDrawing: PropTypes.bool.isRequired,\n id: PropTypes.string.isRequired,\n hotspotColor: PropTypes.string.isRequired,\n onClick: PropTypes.func.isRequired,\n onDragEnd: PropTypes.func.isRequired,\n outlineColor: PropTypes.string.isRequired,\n points: PropTypes.arrayOf(\n PropTypes.shape({\n x: PropTypes.number,\n y: PropTypes.number,\n }),\n ).isRequired,\n strokeWidth: PropTypes.number,\n};\n\nPolComponent.defaultProps = {\n correct: false,\n};\n\nexport default withStyles(styles)(PolComponent);\n"],"file":"hotspot-polygon.js"}
@@ -38,16 +38,11 @@ var RectComponent = /*#__PURE__*/function (_React$Component) {
38
38
 
39
39
  var _super = _createSuper(RectComponent);
40
40
 
41
- function RectComponent() {
41
+ function RectComponent(props) {
42
42
  var _this;
43
43
 
44
44
  (0, _classCallCheck2["default"])(this, RectComponent);
45
-
46
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
47
- args[_key] = arguments[_key];
48
- }
49
-
50
- _this = _super.call.apply(_super, [this].concat(args));
45
+ _this = _super.call(this, props);
51
46
  (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "handleClick", function (e) {
52
47
  var _this$props = _this.props,
53
48
  width = _this$props.width,
@@ -65,8 +60,20 @@ var RectComponent = /*#__PURE__*/function (_React$Component) {
65
60
  });
66
61
  (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "handleMouseEnter", function () {
67
62
  document.body.style.cursor = 'pointer';
63
+
64
+ _this.setState({
65
+ hovered: true
66
+ });
67
+
68
+ _this.trRef.current.setNode(_this.shapeRef.current);
69
+
70
+ _this.trRef.current.getLayer().batchDraw();
68
71
  });
69
72
  (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "handleMouseLeave", function () {
73
+ _this.setState({
74
+ hovered: false
75
+ });
76
+
70
77
  document.body.style.cursor = 'default';
71
78
  });
72
79
  (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "handleOnDragEnd", function (e) {
@@ -78,25 +85,57 @@ var RectComponent = /*#__PURE__*/function (_React$Component) {
78
85
  y: e.target.y()
79
86
  });
80
87
  });
88
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "onResizeEnd", function () {
89
+ var _this$props3 = _this.props,
90
+ onDragEnd = _this$props3.onDragEnd,
91
+ id = _this$props3.id; // transformer is changing scale of the node
92
+ // and NOT its width or height
93
+ // but in the store we have only width and height
94
+ // to match the data better we will reset scale on transform end
95
+
96
+ var node = _this.shapeRef.current;
97
+ var scaleX = node.scaleX();
98
+ var scaleY = node.scaleY(); // we will reset it back
99
+
100
+ node.scaleX(1);
101
+ node.scaleY(1);
102
+ onDragEnd(id, {
103
+ x: node.x(),
104
+ y: node.y(),
105
+ // set minimal value
106
+ width: Math.max(5, node.width() * scaleX),
107
+ height: Math.max(node.height() * scaleY)
108
+ });
109
+ });
110
+ _this.state = {
111
+ hovered: false
112
+ };
113
+ _this.shapeRef = /*#__PURE__*/_react["default"].createRef();
114
+ _this.trRef = /*#__PURE__*/_react["default"].createRef();
81
115
  return _this;
82
116
  }
83
117
 
84
118
  (0, _createClass2["default"])(RectComponent, [{
85
119
  key: "render",
86
120
  value: function render() {
87
- var _this$props3 = this.props,
88
- classes = _this$props3.classes,
89
- correct = _this$props3.correct,
90
- height = _this$props3.height,
91
- hotspotColor = _this$props3.hotspotColor,
92
- outlineColor = _this$props3.outlineColor,
93
- width = _this$props3.width,
94
- x = _this$props3.x,
95
- y = _this$props3.y,
96
- _this$props3$strokeWi = _this$props3.strokeWidth,
97
- strokeWidth = _this$props3$strokeWi === void 0 ? 5 : _this$props3$strokeWi;
98
- return /*#__PURE__*/_react["default"].createElement(_reactKonva.Group, null, /*#__PURE__*/_react["default"].createElement(_reactKonva.Rect, {
121
+ var _this$props4 = this.props,
122
+ classes = _this$props4.classes,
123
+ correct = _this$props4.correct,
124
+ height = _this$props4.height,
125
+ hotspotColor = _this$props4.hotspotColor,
126
+ outlineColor = _this$props4.outlineColor,
127
+ width = _this$props4.width,
128
+ x = _this$props4.x,
129
+ y = _this$props4.y,
130
+ _this$props4$strokeWi = _this$props4.strokeWidth,
131
+ strokeWidth = _this$props4$strokeWi === void 0 ? 5 : _this$props4$strokeWi;
132
+ return /*#__PURE__*/_react["default"].createElement(_reactKonva.Group, {
133
+ classes: classes.group,
134
+ onMouseLeave: this.handleMouseLeave,
135
+ onMouseEnter: this.handleMouseEnter
136
+ }, /*#__PURE__*/_react["default"].createElement(_reactKonva.Rect, {
99
137
  classes: classes.base,
138
+ ref: this.shapeRef,
100
139
  width: width,
101
140
  height: height,
102
141
  fill: hotspotColor,
@@ -105,11 +144,21 @@ var RectComponent = /*#__PURE__*/function (_React$Component) {
105
144
  draggable: true,
106
145
  stroke: outlineColor,
107
146
  strokeWidth: correct ? strokeWidth : 0,
108
- onMouseLeave: this.handleMouseLeave,
109
- onMouseEnter: this.handleMouseEnter,
110
147
  onDragEnd: this.handleOnDragEnd,
148
+ onTransformEnd: this.onResizeEnd,
111
149
  x: x,
112
150
  y: y
151
+ }), this.state.hovered && /*#__PURE__*/_react["default"].createElement(_reactKonva.Transformer, {
152
+ ref: this.trRef,
153
+ rotateEnabled: false,
154
+ boundBoxFunc: function boundBoxFunc(oldBox, newBox) {
155
+ // limit resize
156
+ if (newBox.width < 10 || newBox.height < 10) {
157
+ return oldBox;
158
+ }
159
+
160
+ return newBox;
161
+ }
113
162
  }));
114
163
  }
115
164
  }]);
@@ -121,6 +170,9 @@ var styles = function styles() {
121
170
  base: {
122
171
  cursor: 'pointer',
123
172
  opacity: 0.5
173
+ },
174
+ group: {
175
+ padding: '12px'
124
176
  }
125
177
  };
126
178
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/hotspot-rectangle.jsx"],"names":["RectComponent","e","props","width","height","isDrawing","onClick","id","cancelBubble","document","body","style","cursor","onDragEnd","x","target","y","classes","correct","hotspotColor","outlineColor","strokeWidth","base","handleClick","handleMouseLeave","handleMouseEnter","handleOnDragEnd","React","Component","styles","opacity","propTypes","PropTypes","object","isRequired","bool","string","number","func","defaultProps"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;;;;;IAEMA,a;;;;;;;;;;;;;;;oGACU,UAACC,CAAD,EAAO;AACnB,wBAAkD,MAAKC,KAAvD;AAAA,UAAQC,KAAR,eAAQA,KAAR;AAAA,UAAeC,MAAf,eAAeA,MAAf;AAAA,UAAuBC,SAAvB,eAAuBA,SAAvB;AAAA,UAAkCC,OAAlC,eAAkCA,OAAlC;AAAA,UAA2CC,EAA3C,eAA2CA,EAA3C;;AACA,UAAIJ,KAAK,GAAG,CAAR,IAAaC,MAAM,GAAG,CAAtB,IAA2BC,SAA/B,EAA0C;AACxC;AACD;;AACDJ,MAAAA,CAAC,CAACO,YAAF,GAAiB,IAAjB;AACAF,MAAAA,OAAO,CAACC,EAAD,CAAP;AACD,K;yGAEkB,YAAM;AACvBE,MAAAA,QAAQ,CAACC,IAAT,CAAcC,KAAd,CAAoBC,MAApB,GAA6B,SAA7B;AACD,K;yGAEkB,YAAM;AACvBH,MAAAA,QAAQ,CAACC,IAAT,CAAcC,KAAd,CAAoBC,MAApB,GAA6B,SAA7B;AACD,K;wGAEiB,UAACX,CAAD,EAAO;AACvB,yBAA0B,MAAKC,KA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D;;;EAlDyBW,kBAAMC,S;;AAqDlC,IAAMC,MAAM,GAAG,SAATA,MAAS;AAAA,SAAO;AACpBP,IAAAA,IAAI,EAAE;AACJV,MAAAA,MAAM,EAAE,SADJ;AAEJkB,MAAAA,OAAO,EAAE;AAFL;AADc,GAAP;AAAA,CAAf;;AAOA9B,aAAa,CAAC+B,SAAd,GAA0B;AACxBd,EAAAA,OAAO,EAAEe,sBAAUC,MAAV,CAAiBC,UADF;AAExBhB,EAAAA,OAAO,EAAEc,sBAAUG,IAFK;AAGxB9B,EAAAA,SAAS,EAAE2B,sBAAUG,IAAV,CAAeD,UAHF;AAIxB3B,EAAAA,EAAE,EAAEyB,sBAAUI,MAAV,CAAiBF,UAJG;AAKxB9B,EAAAA,MAAM,EAAE4B,sBAAUK,MAAV,CAAiBH,UALD;AAMxBf,EAAAA,YAAY,EAAEa,sBAAUI,MAAV,CAAiBF,UANP;AAOxB5B,EAAAA,OAAO,EAAE0B,sBAAUM,IAAV,CAAeJ,UAPA;AAQxBrB,EAAAA,SAAS,EAAEmB,sBAAUM,IAAV,CAAeJ,UARF;AASxBd,EAAAA,YAAY,EAAEY,sBAAUI,MAAV,CAAiBF,UATP;AAUxB/B,EAAAA,KAAK,EAAE6B,sBAAUK,MAAV,CAAiBH,UAVA;AAWxBpB,EAAAA,CAAC,EAAEkB,sBAAUK,MAAV,CAAiBH,UAXI;AAYxBlB,EAAAA,CAAC,EAAEgB,sBAAUK,MAAV,CAAiBH,UAZI;AAaxBb,EAAAA,WAAW,EAAEW,sBAAUK;AAbC,CAA1B;AAgBArC,aAAa,CAACuC,YAAd,GAA6B;AAC3BrB,EAAAA,OAAO,EAAE;AADkB,CAA7B;;eAIe,uBAAWW,MAAX,EAAmB7B,aAAnB,C","sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\nimport { Rect, Group } from 'react-konva';\nimport { withStyles } from '@material-ui/core/styles/index';\n\nclass RectComponent extends React.Component {\n handleClick = (e) => {\n const { width, height, isDrawing, onClick, id } = this.props;\n if (width < 0 && height < 0 && isDrawing) {\n return;\n }\n e.cancelBubble = true;\n onClick(id);\n };\n\n handleMouseEnter = () => {\n document.body.style.cursor = 'pointer';\n };\n\n handleMouseLeave = () => {\n document.body.style.cursor = 'default';\n };\n\n handleOnDragEnd = (e) => {\n const { onDragEnd, id } = this.props;\n\n onDragEnd(id, {\n x: e.target.x(),\n y: e.target.y(),\n });\n };\n\n render() {\n const { classes, correct, height, hotspotColor, outlineColor, width, x, y, strokeWidth = 5 } = this.props;\n\n return (\n <Group>\n <Rect\n classes={classes.base}\n width={width}\n height={height}\n fill={hotspotColor}\n onClick={this.handleClick}\n onTap={this.handleClick}\n draggable\n stroke={outlineColor}\n strokeWidth={correct ? strokeWidth : 0}\n onMouseLeave={this.handleMouseLeave}\n onMouseEnter={this.handleMouseEnter}\n onDragEnd={this.handleOnDragEnd}\n x={x}\n y={y}\n />\n </Group>\n );\n }\n}\n\nconst styles = () => ({\n base: {\n cursor: 'pointer',\n opacity: 0.5,\n },\n});\n\nRectComponent.propTypes = {\n classes: PropTypes.object.isRequired,\n correct: PropTypes.bool,\n isDrawing: PropTypes.bool.isRequired,\n id: PropTypes.string.isRequired,\n height: PropTypes.number.isRequired,\n hotspotColor: PropTypes.string.isRequired,\n onClick: PropTypes.func.isRequired,\n onDragEnd: PropTypes.func.isRequired,\n outlineColor: PropTypes.string.isRequired,\n width: PropTypes.number.isRequired,\n x: PropTypes.number.isRequired,\n y: PropTypes.number.isRequired,\n strokeWidth: PropTypes.number,\n};\n\nRectComponent.defaultProps = {\n correct: false,\n};\n\nexport default withStyles(styles)(RectComponent);\n"],"file":"hotspot-rectangle.js"}
1
+ {"version":3,"sources":["../src/hotspot-rectangle.jsx"],"names":["RectComponent","props","e","width","height","isDrawing","onClick","id","cancelBubble","document","body","style","cursor","setState","hovered","trRef","current","setNode","shapeRef","getLayer","batchDraw","onDragEnd","x","target","y","node","scaleX","scaleY","Math","max","state","React","createRef","classes","correct","hotspotColor","outlineColor","strokeWidth","group","handleMouseLeave","handleMouseEnter","base","handleClick","handleOnDragEnd","onResizeEnd","oldBox","newBox","Component","styles","opacity","padding","propTypes","PropTypes","object","isRequired","bool","string","number","func","defaultProps"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;;;;;IAEMA,a;;;;;AACJ,yBAAYC,KAAZ,EAAmB;AAAA;;AAAA;AACjB,8BAAMA,KAAN;AADiB,oGASL,UAACC,CAAD,EAAO;AACnB,wBAAkD,MAAKD,KAAvD;AAAA,UAAQE,KAAR,eAAQA,KAAR;AAAA,UAAeC,MAAf,eAAeA,MAAf;AAAA,UAAuBC,SAAvB,eAAuBA,SAAvB;AAAA,UAAkCC,OAAlC,eAAkCA,OAAlC;AAAA,UAA2CC,EAA3C,eAA2CA,EAA3C;;AACA,UAAIJ,KAAK,GAAG,CAAR,IAAaC,MAAM,GAAG,CAAtB,IAA2BC,SAA/B,EAA0C;AACxC;AACD;;AACDH,MAAAA,CAAC,CAACM,YAAF,GAAiB,IAAjB;AACAF,MAAAA,OAAO,CAACC,EAAD,CAAP;AACD,KAhBkB;AAAA,yGAkBA,YAAM;AACvBE,MAAAA,QAAQ,CAACC,IAAT,CAAcC,KAAd,CAAoBC,MAApB,GAA6B,SAA7B;;AACA,YAAKC,QAAL,CAAc;AAAEC,QAAAA,OAAO,EAAE;AAAX,OAAd;;AACA,YAAKC,KAAL,CAAWC,OAAX,CAAmBC,OAAnB,CAA2B,MAAKC,QAAL,CAAcF,OAAzC;;AACA,YAAKD,KAAL,CAAWC,OAAX,CAAmBG,QAAnB,GAA8BC,SAA9B;AACD,KAvBkB;AAAA,yGAyBA,YAAM;AACvB,YAAKP,QAAL,CAAc;AAAEC,QAAAA,OAAO,EAAE;AAAX,OAAd;;AACAL,MAAAA,QAAQ,CAACC,IAAT,CAAcC,KAAd,CAAoBC,MAApB,GAA6B,SAA7B;AACD,KA5BkB;AAAA,wGA8BD,UAACV,CAAD,EAAO;AACv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AaxBjB,EAAAA,WAAW,EAAEe,sBAAUK;AAbC,CAA1B;AAgBAzD,aAAa,CAAC2D,YAAd,GAA6B;AAC3BzB,EAAAA,OAAO,EAAE;AADkB,CAA7B;;eAIe,uBAAWc,MAAX,EAAmBhD,aAAnB,C","sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\nimport { Rect, Group, Transformer } from 'react-konva';\nimport { withStyles } from '@material-ui/core/styles/index';\n\nclass RectComponent extends React.Component {\n constructor(props) {\n super(props);\n this.state = {\n hovered: false,\n };\n this.shapeRef = React.createRef();\n this.trRef = React.createRef();\n }\n\n handleClick = (e) => {\n const { width, height, isDrawing, onClick, id } = this.props;\n if (width < 0 && height < 0 && isDrawing) {\n return;\n }\n e.cancelBubble = true;\n onClick(id);\n };\n\n handleMouseEnter = () => {\n document.body.style.cursor = 'pointer';\n this.setState({ hovered: true });\n this.trRef.current.setNode(this.shapeRef.current);\n this.trRef.current.getLayer().batchDraw();\n };\n\n handleMouseLeave = () => {\n this.setState({ hovered: false });\n document.body.style.cursor = 'default';\n };\n\n handleOnDragEnd = (e) => {\n const { onDragEnd, id } = this.props;\n\n onDragEnd(id, {\n x: e.target.x(),\n y: e.target.y(),\n });\n };\n\n onResizeEnd = () => {\n const { onDragEnd, id } = this.props;\n // transformer is changing scale of the node\n // and NOT its width or height\n // but in the store we have only width and height\n // to match the data better we will reset scale on transform end\n const node = this.shapeRef.current;\n const scaleX = node.scaleX();\n const scaleY = node.scaleY();\n\n // we will reset it back\n node.scaleX(1);\n node.scaleY(1);\n onDragEnd(id, {\n x: node.x(),\n y: node.y(),\n // set minimal value\n width: Math.max(5, node.width() * scaleX),\n height: Math.max(node.height() * scaleY),\n });\n };\n\n render() {\n const { classes, correct, height, hotspotColor, outlineColor, width, x, y, strokeWidth = 5 } = this.props;\n\n return (\n <Group classes={classes.group} onMouseLeave={this.handleMouseLeave} onMouseEnter={this.handleMouseEnter}>\n <Rect\n classes={classes.base}\n ref={this.shapeRef}\n width={width}\n height={height}\n fill={hotspotColor}\n onClick={this.handleClick}\n onTap={this.handleClick}\n draggable\n stroke={outlineColor}\n strokeWidth={correct ? strokeWidth : 0}\n onDragEnd={this.handleOnDragEnd}\n onTransformEnd={this.onResizeEnd}\n x={x}\n y={y}\n />\n {this.state.hovered && (\n <Transformer\n ref={this.trRef}\n rotateEnabled={false}\n boundBoxFunc={(oldBox, newBox) => {\n // limit resize\n if (newBox.width < 10 || newBox.height < 10) {\n return oldBox;\n }\n return newBox;\n }}\n />\n )}\n </Group>\n );\n }\n}\n\nconst styles = () => ({\n base: {\n cursor: 'pointer',\n opacity: 0.5,\n },\n\n group: {\n padding: '12px',\n },\n});\n\nRectComponent.propTypes = {\n classes: PropTypes.object.isRequired,\n correct: PropTypes.bool,\n isDrawing: PropTypes.bool.isRequired,\n id: PropTypes.string.isRequired,\n height: PropTypes.number.isRequired,\n hotspotColor: PropTypes.string.isRequired,\n onClick: PropTypes.func.isRequired,\n onDragEnd: PropTypes.func.isRequired,\n outlineColor: PropTypes.string.isRequired,\n width: PropTypes.number.isRequired,\n x: PropTypes.number.isRequired,\n y: PropTypes.number.isRequired,\n strokeWidth: PropTypes.number,\n};\n\nRectComponent.defaultProps = {\n correct: false,\n};\n\nexport default withStyles(styles)(RectComponent);\n"],"file":"hotspot-rectangle.js"}
@@ -139,7 +139,39 @@ var HotspotConfigure = /*#__PURE__*/function (_HTMLElement) {
139
139
  }, {
140
140
  key: "configuration",
141
141
  set: function set(c) {
142
- this._configuration = c;
142
+ var _this2 = this;
143
+
144
+ this._configuration = c; // if language:enabled is true, then the corresponding default item model should include a language value;
145
+ // if it is false, then the language field should be omitted from the item model.
146
+ // if a default item model includes a language value (e.g., en_US) and the corresponding authoring view settings have language:settings = true,
147
+ // then (a) language:enabled should also be true, and (b) that default language value should be represented in languageChoices[] (as a key).
148
+
149
+ if (c.language.enabled) {
150
+ var _c$languageChoices, _c$languageChoices$op;
151
+
152
+ if ((_c$languageChoices = c.languageChoices) !== null && _c$languageChoices !== void 0 && (_c$languageChoices$op = _c$languageChoices.options) !== null && _c$languageChoices$op !== void 0 && _c$languageChoices$op.length) {
153
+ this._model.language = c.languageChoices.options[0].value;
154
+ }
155
+ } else if (c.language.settings && this._model.language) {
156
+ this._configuration.language.enabled = true;
157
+
158
+ if (!this._configuration.languageChoices.options || !this._configuration.languageChoices.options.length) {
159
+ this._configuration.languageChoices.options = [];
160
+ } // check if the language is already included in the languageChoices.options array
161
+ // and if not, then add it.
162
+
163
+
164
+ if (!this._configuration.languageChoices.options.find(function (option) {
165
+ return option.value === _this2._model.language;
166
+ })) {
167
+ this._configuration.languageChoices.options.push({
168
+ value: this._model.language,
169
+ label: this._model.language
170
+ });
171
+ }
172
+ } else {
173
+ delete this._model.language;
174
+ }
143
175
 
144
176
  this._render();
145
177
  }