@gamelearn/arcade-components 0.22.7 → 0.22.9

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.
@@ -57,6 +57,26 @@ var ImageReview = function ImageReview() {
57
57
  };
58
58
 
59
59
  var ImageClickWrapperComponent = function ImageClickWrapperComponent(props) {
60
+ // Common config
61
+ var soundActions = props.soundActions,
62
+ emitEvent = props.emitEvent,
63
+ disableExit = props.disableExit,
64
+ setResolveAction = props.setResolveAction,
65
+ info = props.info,
66
+ image = props.image,
67
+ areas = props.areas,
68
+ badAreas = props.badAreas,
69
+ hasClickOrder = props.hasClickOrder,
70
+ hasClickOnce = props.hasClickOnce,
71
+ hasHighlights = props.hasHighlights,
72
+ hasImageReview = props.hasImageReview,
73
+ defaultCompleted = props.defaultCompleted,
74
+ className = props.className,
75
+ emitFinish = props.emitFinish,
76
+ emitResolve = props.emitResolve,
77
+ translateFromParent = props.translateFromParent,
78
+ specificFeedbacks = props.specificFeedbacks;
79
+
60
80
  var _useState = (0, _react.useState)([]),
61
81
  _useState2 = _slicedToArray(_useState, 2),
62
82
  clickedZones = _useState2[0],
@@ -72,33 +92,15 @@ var ImageClickWrapperComponent = function ImageClickWrapperComponent(props) {
72
92
  finished = _useState6[0],
73
93
  setFinished = _useState6[1];
74
94
 
75
- var _useState7 = (0, _react.useState)(false),
95
+ var _useState7 = (0, _react.useState)({
96
+ show: false,
97
+ success: false,
98
+ text: '',
99
+ rewards: []
100
+ }),
76
101
  _useState8 = _slicedToArray(_useState7, 2),
77
- showWrongFeedback = _useState8[0],
78
- setShowWrongFeedback = _useState8[1];
79
-
80
- var _useState9 = (0, _react.useState)(false),
81
- _useState10 = _slicedToArray(_useState9, 2),
82
- disableClick = _useState10[0],
83
- setDisableClick = _useState10[1]; // Common config
84
-
85
-
86
- var soundActions = props.soundActions,
87
- emitEvent = props.emitEvent,
88
- disableExit = props.disableExit,
89
- setResolveAction = props.setResolveAction,
90
- info = props.info,
91
- image = props.image,
92
- areas = props.areas,
93
- badAreas = props.badAreas,
94
- hasClickOrder = props.hasClickOrder,
95
- hasHighlights = props.hasHighlights,
96
- hasImageReview = props.hasImageReview,
97
- defaultCompleted = props.defaultCompleted,
98
- className = props.className,
99
- emitFinish = props.emitFinish,
100
- emitResolve = props.emitResolve,
101
- translateFromParent = props.translateFromParent;
102
+ feedbackData = _useState8[0],
103
+ setFeedbackData = _useState8[1];
102
104
 
103
105
  var translate = function translate(id) {
104
106
  if (translateFromParent) return translateFromParent(id); // when there is no emitEvent pass the Translate
@@ -109,11 +111,6 @@ var ImageClickWrapperComponent = function ImageClickWrapperComponent(props) {
109
111
  });
110
112
  };
111
113
 
112
- var _useState11 = (0, _react.useState)(''),
113
- _useState12 = _slicedToArray(_useState11, 2),
114
- resolvedClass = _useState12[0],
115
- setResolveClass = _useState12[1];
116
-
117
114
  var _soundActions = _slicedToArray(soundActions, 1),
118
115
  playSound = _soundActions[0];
119
116
 
@@ -131,18 +128,16 @@ var ImageClickWrapperComponent = function ImageClickWrapperComponent(props) {
131
128
  shape: 'poly'
132
129
  }, area);
133
130
  });
134
- var handleFinish = (0, _react.useCallback)(function () {
135
- var rewards = solution.right.rewards;
136
-
131
+ var handleFinish = (0, _react.useCallback)(function (rewards) {
137
132
  if (emitFinish) {
138
- emitFinish(rewards);
133
+ emitFinish(rewards, feedbackData.success);
139
134
  } else {
140
135
  emitEvent({
141
136
  type: 'addPoints',
142
137
  payload: rewards
143
138
  });
144
139
  }
145
- }, [emitEvent, emitFinish, solution.right]);
140
+ }, [emitEvent, emitFinish, feedbackData.success]);
146
141
  (0, _react.useEffect)(function () {
147
142
  if (completed) {
148
143
  disableExit(true);
@@ -152,16 +147,26 @@ var ImageClickWrapperComponent = function ImageClickWrapperComponent(props) {
152
147
  setCompleted(defaultCompleted);
153
148
  }, [defaultCompleted]);
154
149
  (0, _react.useEffect)(function () {
155
- if (areas.length === clickedZones.length && !completed) {
150
+ if (areas.length === clickedZones.length && !completed || hasClickOnce && clickedZones.length > 0) {
151
+ var _specificFeedbacks$co;
152
+
156
153
  setCompleted(true);
157
- setDisableClick(true);
158
- setResolveClass('success');
154
+
155
+ if (!((_specificFeedbacks$co = specificFeedbacks.correctFeedbacks) !== null && _specificFeedbacks$co !== void 0 && _specificFeedbacks$co.length)) {
156
+ setFeedbackData(function (oldState) {
157
+ return _objectSpread(_objectSpread({}, oldState), {}, {
158
+ show: true,
159
+ success: true,
160
+ text: info.solution.right.desc,
161
+ rewards: info.solution.right.rewards
162
+ });
163
+ });
164
+ }
159
165
  }
160
- }, [clickedZones, areas.length, handleFinish, completed, info.solution.right.desc, emitEvent]);
166
+ }, [clickedZones, areas.length, specificFeedbacks, hasClickOnce, completed, info.solution.right]);
161
167
  (0, _react.useEffect)(function () {
162
168
  setResolveAction(function (resolve) {
163
169
  setCompleted(true);
164
- setDisableClick(true);
165
170
  setFinished(true);
166
171
  setTimeout(function () {
167
172
  emitResolve ? emitResolve(resolve) : resolve();
@@ -174,78 +179,109 @@ var ImageClickWrapperComponent = function ImageClickWrapperComponent(props) {
174
179
  }
175
180
  }, [finished, disableExit]);
176
181
 
177
- var handleClickOutSide = function handleClickOutSide() {
178
- if (!disableClick && !defaultCompleted) {
179
- var wrongRewards = solution.wrong.rewards;
182
+ var handleIncorrectAreaClick = function handleIncorrectAreaClick(area) {
183
+ if (!completed) {
184
+ var _specificFeedbacks$wr;
185
+
186
+ var _solution$wrong = solution.wrong,
187
+ wrongRewards = _solution$wrong.rewards,
188
+ desc = _solution$wrong.desc;
189
+ var feedback = desc;
190
+ var rewards = wrongRewards;
180
191
  emitEvent({
181
192
  type: 'hidePuzzleButtons',
182
193
  payload: true
183
194
  });
195
+ var specific = (_specificFeedbacks$wr = specificFeedbacks.wrongFeedbacks) === null || _specificFeedbacks$wr === void 0 ? void 0 : _specificFeedbacks$wr.find(function (feed) {
196
+ return feed.id === area.id;
197
+ });
198
+
199
+ if (specific) {
200
+ feedback = specific.desc;
201
+ rewards = specific.rewards;
202
+ }
203
+
204
+ if (emitFinish) {
205
+ emitFinish(wrongRewards, false);
206
+ }
184
207
 
185
208
  if (hasClickOrder) {
186
209
  setClickedZones([]);
187
210
  }
188
211
 
189
- setShowWrongFeedback(true);
190
- setResolveClass('wrong');
191
- playSound('fail');
192
- setTimeout(function () {
193
- setShowWrongFeedback(false);
194
- setResolveClass('');
195
- emitEvent({
196
- type: 'addPoints',
197
- payload: wrongRewards,
198
- finish: false
212
+ setFeedbackData(function (oldState) {
213
+ return _objectSpread(_objectSpread({}, oldState), {}, {
214
+ show: true,
215
+ success: false,
216
+ text: feedback,
217
+ rewards: rewards
199
218
  });
200
- }, 2000);
219
+ });
220
+ playSound('fail');
201
221
  }
202
222
  };
203
223
 
204
224
  var handleOnClose = function handleOnClose() {
205
- handleFinish();
225
+ handleFinish(feedbackData.rewards);
206
226
  playSound('click-ui');
207
- setResolveClass('');
208
- setShowWrongFeedback(false);
227
+ setFeedbackData(function (oldState) {
228
+ return _objectSpread(_objectSpread({}, oldState), {}, {
229
+ show: false,
230
+ success: false,
231
+ text: '',
232
+ rewards: []
233
+ });
234
+ });
209
235
  };
210
236
 
211
- var handleAreaClick = function handleAreaClick(area) {
237
+ var handleCorrectAreaClick = function handleCorrectAreaClick(area) {
212
238
  if (!clickedZones.some(function (zone) {
213
239
  return zone.index === area.index;
214
- }) && !defaultCompleted && !showWrongFeedback && !disableClick) {
215
- var updatedClickedZones = [].concat(_toConsumableArray(clickedZones), [area]);
240
+ }) && !feedbackData.show && !completed) {
216
241
  playSound('click-ui');
242
+ var feedback = solution.right.desc;
243
+ var rewards = solution.right.rewards;
217
244
 
218
245
  if (hasClickOrder && area.index === clickedZones.length || !hasClickOrder) {
219
- setClickedZones(updatedClickedZones);
220
- } else {
221
- var _solution$wrong = solution.wrong,
222
- wrongRewards = _solution$wrong.rewards,
223
- feedback = _solution$wrong.desc;
224
- setClickedZones([]);
225
- updatedClickedZones = [];
226
-
227
- if (feedback) {
228
- setShowWrongFeedback(true);
229
- setResolveClass('wrong');
230
- } else {
231
- emitEvent({
232
- type: 'addPoints',
233
- payload: wrongRewards,
234
- finish: false
246
+ var _specificFeedbacks$co2;
247
+
248
+ if ((_specificFeedbacks$co2 = specificFeedbacks.correctFeedbacks) !== null && _specificFeedbacks$co2 !== void 0 && _specificFeedbacks$co2.length) {
249
+ var _specificFeedbacks$co3;
250
+
251
+ var specific = (_specificFeedbacks$co3 = specificFeedbacks.correctFeedbacks) === null || _specificFeedbacks$co3 === void 0 ? void 0 : _specificFeedbacks$co3.find(function (feed) {
252
+ return feed.id === area.id;
253
+ });
254
+
255
+ if (specific) {
256
+ feedback = specific.desc;
257
+ rewards = specific.rewards;
258
+ }
259
+
260
+ setFeedbackData(function (oldState) {
261
+ return _objectSpread(_objectSpread({}, oldState), {}, {
262
+ show: true,
263
+ success: true,
264
+ text: feedback,
265
+ rewards: rewards
266
+ });
235
267
  });
236
268
  }
269
+
270
+ setClickedZones([].concat(_toConsumableArray(clickedZones), [area]));
271
+ } else {
272
+ handleIncorrectAreaClick(area);
237
273
  }
238
274
  }
239
275
  };
240
276
 
241
277
  return /*#__PURE__*/_react.default.createElement("div", {
242
278
  className: className
243
- }, resolvedClass ? /*#__PURE__*/_react.default.createElement(_FeedbackComponent.default, {
279
+ }, feedbackData.show ? /*#__PURE__*/_react.default.createElement(_FeedbackComponent.default, {
244
280
  playSound: playSound,
245
- text: info.solution[resolvedClass === 'success' ? 'right' : 'wrong'].desc,
246
- success: resolvedClass === 'success',
281
+ text: feedbackData.text,
282
+ success: feedbackData.success,
247
283
  translate: translate,
248
- hasTimeout: !info.solution.right.desc,
284
+ hasTimeout: !feedbackData.text,
249
285
  delay: 2000,
250
286
  functionOnClose: handleOnClose
251
287
  }) : null, /*#__PURE__*/_react.default.createElement(_KonvaMapper.default, {
@@ -254,8 +290,8 @@ var ImageClickWrapperComponent = function ImageClickWrapperComponent(props) {
254
290
  areas: areasList,
255
291
  badAreas: badAreasList,
256
292
  clickedZones: clickedZones,
257
- onClick: handleAreaClick,
258
- onClickOutside: handleClickOutSide,
293
+ onClick: handleCorrectAreaClick,
294
+ onClickOutside: handleIncorrectAreaClick,
259
295
  hasHighlights: hasHighlights,
260
296
  emitEvent: emitEvent
261
297
  }), hasImageReview ? /*#__PURE__*/_react.default.createElement(ImageReview, null) : null);
@@ -272,6 +308,7 @@ ImageClickWrapperComponent.defaultProps = {
272
308
  badAreas: [],
273
309
  className: 'puzzle--image__click',
274
310
  hasClickOrder: false,
311
+ hasClickOnce: false,
275
312
  hasHighlights: false,
276
313
  hasImageReview: false,
277
314
  defaultCompleted: false,
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.mockProps4 = exports.mockProps3 = exports.mockProps2 = exports.mockProps = void 0;
6
+ exports.mockPropsOnce = exports.mockProps4 = exports.mockProps3 = exports.mockProps2 = exports.mockProps = void 0;
7
7
 
8
8
  var emitEvent = function emitEvent(_ref) {
9
9
  var type = _ref.type,
@@ -346,4 +346,79 @@ var mockProps4 = {
346
346
  hasClickOrder: false,
347
347
  hasHighlights: false
348
348
  };
349
- exports.mockProps4 = mockProps4;
349
+ exports.mockProps4 = mockProps4;
350
+ var mockPropsOnce = {
351
+ emitEvent: emitEvent,
352
+ soundActions: soundActions,
353
+ disableExit: function disableExit() {},
354
+ setResolveAction: function setResolveAction() {},
355
+ transitionEffects: null,
356
+ audioId: '',
357
+ itemOrder: 1,
358
+ info: {
359
+ hint: {
360
+ active: true,
361
+ desc: 'hint',
362
+ rewards: []
363
+ },
364
+ resolve: {
365
+ rewards: []
366
+ },
367
+ solution: {
368
+ right: {
369
+ desc: 'correctSolution',
370
+ desc_labelId: 'alfalfa01',
371
+ rewards: []
372
+ },
373
+ wrong: {
374
+ desc: 'wrongSolution',
375
+ desc_labelId: 'fabada01',
376
+ rewards: [{
377
+ id: 'grade',
378
+ name: 'grade',
379
+ points: -17,
380
+ type: 'grade'
381
+ }]
382
+ }
383
+ },
384
+ instructions: 'instructions'
385
+ },
386
+ image: {
387
+ imgName: 'gato5.jpg',
388
+ img: {
389
+ url: 'https://min.gamelearn.io/css-resources/gamelearn/resources/image-click.jpg',
390
+ imgName: 'gato5.jpg',
391
+ resourceId: '6007f80eac41ad001120f135'
392
+ },
393
+ width: 1280,
394
+ height: 720
395
+ },
396
+ areas: [{
397
+ id: '1601910616179',
398
+ name: 'a',
399
+ x: 0,
400
+ y: 0,
401
+ draggable: true,
402
+ points: [74.1584158415841, 423.99133663366337, 229.20792079207916, 366.96163366336634, 516.1386138613861, 482.8032178217822, 644.4554455445544, 710.9220297029703, 56.33663366336629, 712.7042079207921],
403
+ strokeWidth: 2,
404
+ stroke: '#44d7ab',
405
+ fill: 'rgba(68, 215, 171, 0.56)',
406
+ closed: true
407
+ }, {
408
+ id: '1601910626254',
409
+ name: 'b',
410
+ x: 0,
411
+ y: 0,
412
+ draggable: true,
413
+ points: [607.0297029702971, 343.79331683168317, 783.4653465346535, 388.3477722772277, 865.4455445544554, 539.8329207920792, 1138.118811881188, 593.2982673267327, 1262.871287128713, 358.0507425742574, 1262.871287128713, 46.16955445544554, 1193.3663366336634, 12.308168316831683, 1018.7128712871288, 19.43688118811881, 746.0396039603961, 213.69430693069307, 555.3465346534654, 268.94183168316835],
414
+ strokeWidth: 2,
415
+ stroke: '#44d7ab',
416
+ fill: 'rgba(68, 215, 171, 0.56)',
417
+ closed: true
418
+ }],
419
+ badAreas: [],
420
+ hasClickOrder: false,
421
+ hasClickOnce: true,
422
+ hasHighlights: true
423
+ };
424
+ exports.mockPropsOnce = mockPropsOnce;
@@ -68,7 +68,7 @@ var Area = function Area(_ref) {
68
68
  var clickArea = function clickArea() {
69
69
  if (!completed) {
70
70
  if (isBad) {
71
- onClickOutside();
71
+ onClickOutside(area);
72
72
  } else {
73
73
  onClick(area);
74
74
  }
@@ -96,7 +96,7 @@ var KonvaMapper = function KonvaMapper(_ref) {
96
96
 
97
97
  var handleStageClick = function handleStageClick(a) {
98
98
  if (incorrectArea && !a.target.attrs.shape) {
99
- onClickOutside();
99
+ onClickOutside(incorrectArea);
100
100
  }
101
101
  };
102
102
 
@@ -107,8 +107,11 @@ var TextClickPuzzleComponent = function TextClickPuzzleComponent(_ref) {
107
107
  });
108
108
  }, [emitEvent]);
109
109
  var parsedText = (0, _react.useRef)(null);
110
+ var isCompleted = (0, _react.useCallback)(function () {
111
+ return correctTextFragmentsPartial.current === list[currentSlide].correctTexts.length || list[currentSlide].hasClickOnce && correctTextFragmentsPartial.current >= 1;
112
+ }, [currentSlide, list]);
110
113
  var goForward = (0, _react.useCallback)(function () {
111
- if (correctTextFragmentsPartial.current === list[currentSlide].correctTexts.length) {
114
+ if (isCompleted()) {
112
115
  setFeedbackData(function (prevState) {
113
116
  return _objectSpread(_objectSpread({}, prevState), {}, {
114
117
  result: false
@@ -140,7 +143,7 @@ var TextClickPuzzleComponent = function TextClickPuzzleComponent(_ref) {
140
143
  }, 1200);
141
144
  }
142
145
  }
143
- }, [list, currentSlide, correctTextFragmentsAccumulated, numberAllCorrectFragments, setShowPoints]);
146
+ }, [isCompleted, correctTextFragmentsAccumulated, numberAllCorrectFragments, setShowPoints, currentSlide]);
144
147
  var handleFeedbackFuncionOnClose = (0, _react.useCallback)(function () {
145
148
  emitEvent({
146
149
  type: 'hidePuzzleButtons',
@@ -174,7 +177,7 @@ var TextClickPuzzleComponent = function TextClickPuzzleComponent(_ref) {
174
177
 
175
178
  if ((_list$currentSlide$in = list[currentSlide].info.solution.right) !== null && _list$currentSlide$in !== void 0 && _list$currentSlide$in.desc) {
176
179
  //solo muestra la caja verde y suma puntos cuando resuelves todos los fragmentos correctos
177
- if (correctTextFragmentsPartial.current === list[currentSlide].correctTexts.length) {
180
+ if (isCompleted()) {
178
181
  accRewards.current = [].concat(_toConsumableArray(accRewards.current), _toConsumableArray(list[currentSlide].info.solution.right.rewards));
179
182
  setFeedbackData(function (prevState) {
180
183
  return _objectSpread(_objectSpread({}, prevState), {}, {
@@ -205,7 +208,7 @@ var TextClickPuzzleComponent = function TextClickPuzzleComponent(_ref) {
205
208
  if (list[currentSlide].specificFeedbacks.specificCorrectFeedbacks) {
206
209
  accRewards.current = [].concat(_toConsumableArray(accRewards.current), _toConsumableArray(specificFeedback === null || specificFeedback === void 0 ? void 0 : specificFeedback.rewards));
207
210
 
208
- if (correctTextFragmentsPartial.current === list[currentSlide].correctTexts.length) {
211
+ if (isCompleted()) {
209
212
  setFeedbackData(function (prevState) {
210
213
  return _objectSpread(_objectSpread({}, prevState), {}, {
211
214
  show: true,
@@ -216,7 +219,7 @@ var TextClickPuzzleComponent = function TextClickPuzzleComponent(_ref) {
216
219
  }
217
220
  } // si tiene puntos generales
218
221
  else {
219
- if (correctTextFragmentsPartial.current === list[currentSlide].correctTexts.length) {
222
+ if (isCompleted()) {
220
223
  accRewards.current = [].concat(_toConsumableArray(accRewards.current), _toConsumableArray(list[currentSlide].info.solution.right.rewards));
221
224
  setFeedbackData(function (prevState) {
222
225
  return _objectSpread(_objectSpread({}, prevState), {}, {
@@ -228,7 +231,7 @@ var TextClickPuzzleComponent = function TextClickPuzzleComponent(_ref) {
228
231
  }
229
232
  }
230
233
  }
231
- }, [correctTextFragmentsAccumulated, emitEvent, playSound, list, currentSlide]);
234
+ }, [correctTextFragmentsAccumulated, emitEvent, playSound, list, currentSlide, isCompleted]);
232
235
  var handleIncorrectClick = (0, _react.useCallback)(function (allDataTextIds, specificFeedback) {
233
236
  allDataTextIds.forEach(function (el) {
234
237
  return el.classList.add('text-click__failed');
@@ -368,18 +371,25 @@ var TextClickPuzzleComponent = function TextClickPuzzleComponent(_ref) {
368
371
  var counter = 0;
369
372
 
370
373
  for (var i = 0; i < list.length; i++) {
371
- for (var j = 0; j < list[i].correctTexts.length; j++) {
374
+ if (list[i].hasClickOnce) {
372
375
  counter++;
373
376
  setNumberAllCorrectFragments(counter);
377
+ } else {
378
+ for (var j = 0; j < list[i].correctTexts.length; j++) {
379
+ counter++;
380
+ setNumberAllCorrectFragments(counter);
381
+ }
374
382
  }
375
383
  }
376
384
  }, [list]);
377
385
  (0, _react.useEffect)(function () {
378
- setInfo(_objectSpread(_objectSpread({}, list[currentSlide].info), {}, {
386
+ var _list$currentSlide3;
387
+
388
+ (list === null || list === void 0 ? void 0 : list[currentSlide]) && setInfo(_objectSpread(_objectSpread({}, list[currentSlide].info), {}, {
379
389
  description: description
380
390
  }));
381
391
 
382
- if (list[currentSlide].text) {
392
+ if ((_list$currentSlide3 = list[currentSlide]) !== null && _list$currentSlide3 !== void 0 && _list$currentSlide3.text) {
383
393
  var jsx = (0, _htmlReactParser.default)(list[currentSlide].text);
384
394
  parsedText.current = recursiveStuff(jsx);
385
395
  getnumberAllCorrectFragments();