@micromag/screen-quiz 0.3.150 → 0.3.154
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/assets/css/styles.css +2 -2
- package/es/index.js +225 -153
- package/lib/index.js +224 -150
- package/package.json +13 -12
package/es/index.js
CHANGED
|
@@ -5,12 +5,13 @@ import classNames from 'classnames';
|
|
|
5
5
|
import PropTypes$1 from 'prop-types';
|
|
6
6
|
import React, { useMemo, useState, useEffect, useCallback, useRef } from 'react';
|
|
7
7
|
import { PropTypes } from '@micromag/core';
|
|
8
|
-
import { useScreenRenderContext, useScreenSize,
|
|
9
|
-
import {
|
|
8
|
+
import { useScreenRenderContext, useScreenSize, useViewerContext, useViewerWebView, usePlaybackContext, usePlaybackMediaRef, useVisitor, useScreenState } from '@micromag/core/contexts';
|
|
9
|
+
import { useDimensionObserver, useTrackScreenEvent } from '@micromag/core/hooks';
|
|
10
10
|
import { useQuizCreate } from '@micromag/data';
|
|
11
11
|
import Background from '@micromag/element-background';
|
|
12
12
|
import CallToAction from '@micromag/element-call-to-action';
|
|
13
13
|
import Container from '@micromag/element-container';
|
|
14
|
+
import Scroll from '@micromag/element-scroll';
|
|
14
15
|
import _objectSpread from '@babel/runtime/helpers/objectSpread2';
|
|
15
16
|
import { ScreenElement, Transitions } from '@micromag/core/components';
|
|
16
17
|
import { isTextFilled, getStyleFromColor } from '@micromag/core/utils';
|
|
@@ -24,7 +25,7 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
|
|
24
25
|
import Button from '@micromag/element-button';
|
|
25
26
|
import { TransitionGroup, CSSTransition } from 'react-transition-group';
|
|
26
27
|
|
|
27
|
-
var styles$4 = {"emptyAnswer":"micromag-screen-quiz-answers-emptyAnswer","button":"micromag-screen-quiz-answers-button","container":"micromag-screen-quiz-answers-container","items":"micromag-screen-quiz-answers-items","item":"micromag-screen-quiz-answers-item","
|
|
28
|
+
var styles$4 = {"emptyAnswer":"micromag-screen-quiz-answers-emptyAnswer","button":"micromag-screen-quiz-answers-button","container":"micromag-screen-quiz-answers-container","items":"micromag-screen-quiz-answers-items","item":"micromag-screen-quiz-answers-item","answerToSlide":"micromag-screen-quiz-answers-answerToSlide","isUserAnswer":"micromag-screen-quiz-answers-isUserAnswer","answered":"micromag-screen-quiz-answers-answered","rightAnswer":"micromag-screen-quiz-answers-rightAnswer","userAnswer":"micromag-screen-quiz-answers-userAnswer","willCollapse":"micromag-screen-quiz-answers-willCollapse","didCollapsed":"micromag-screen-quiz-answers-didCollapsed","withoutGoodAnswer":"micromag-screen-quiz-answers-withoutGoodAnswer","isPlaceholder":"micromag-screen-quiz-answers-isPlaceholder","withGoodAnswer":"micromag-screen-quiz-answers-withGoodAnswer","resultIcon":"micromag-screen-quiz-answers-resultIcon","itemContent":"micromag-screen-quiz-answers-itemContent"};
|
|
28
29
|
|
|
29
30
|
var propTypes$5 = {
|
|
30
31
|
items: PropTypes.quizAnswers.isRequired,
|
|
@@ -73,7 +74,7 @@ var defaultProps$5 = {
|
|
|
73
74
|
};
|
|
74
75
|
|
|
75
76
|
var Answers = function Answers(_ref) {
|
|
76
|
-
var
|
|
77
|
+
var _ref4;
|
|
77
78
|
|
|
78
79
|
var items = _ref.items,
|
|
79
80
|
answeredIndex = _ref.answeredIndex,
|
|
@@ -111,24 +112,24 @@ var Answers = function Answers(_ref) {
|
|
|
111
112
|
// we also get the right answer's Y to animate its position
|
|
112
113
|
|
|
113
114
|
|
|
114
|
-
var
|
|
115
|
-
answerRef =
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
var _ref3 = answerContentRect || {},
|
|
119
|
-
answerHeight = _ref3.height;
|
|
115
|
+
var _useDimensionObserver = useDimensionObserver(),
|
|
116
|
+
answerRef = _useDimensionObserver.ref,
|
|
117
|
+
answerHeight = _useDimensionObserver.height;
|
|
120
118
|
|
|
121
|
-
var
|
|
122
|
-
rightAnswerRef =
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
var _ref4 = rightAnswerContentRect || {},
|
|
126
|
-
rightAnswerHeight = _ref4.height;
|
|
119
|
+
var _useDimensionObserver2 = useDimensionObserver(),
|
|
120
|
+
rightAnswerRef = _useDimensionObserver2.ref,
|
|
121
|
+
rightAnswerHeight = _useDimensionObserver2.height;
|
|
127
122
|
|
|
128
123
|
var rightAnswerTop = useMemo(function () {
|
|
129
124
|
return rightAnswerRef.current !== null ? rightAnswerRef.current.offsetTop : 0;
|
|
130
125
|
}, [rightAnswerHeight]);
|
|
131
|
-
var
|
|
126
|
+
var hasRightAnswer = items !== null && !isPlaceholder ? items.reduce(function (hasGood, _ref3) {
|
|
127
|
+
var _ref3$good = _ref3.good,
|
|
128
|
+
good = _ref3$good === void 0 ? false : _ref3$good;
|
|
129
|
+
return hasGood || good;
|
|
130
|
+
}, false) : false;
|
|
131
|
+
var finalShowUserAnswer = showUserAnswer || !hasRightAnswer;
|
|
132
|
+
var shouldCollapse = !withoutGoodAnswer || finalShowUserAnswer && answeredIndex !== null;
|
|
132
133
|
|
|
133
134
|
var _useState = useState(answeredIndex !== null),
|
|
134
135
|
_useState2 = _slicedToArray(_useState, 2),
|
|
@@ -150,7 +151,7 @@ var Answers = function Answers(_ref) {
|
|
|
150
151
|
if (onCollapse !== null) {
|
|
151
152
|
onCollapse();
|
|
152
153
|
}
|
|
153
|
-
}, hasAnsweredRight ||
|
|
154
|
+
}, hasAnsweredRight || finalShowUserAnswer ? 500 : answersCollapseDelay);
|
|
154
155
|
}
|
|
155
156
|
|
|
156
157
|
return function () {
|
|
@@ -158,7 +159,7 @@ var Answers = function Answers(_ref) {
|
|
|
158
159
|
clearTimeout(timeout);
|
|
159
160
|
}
|
|
160
161
|
};
|
|
161
|
-
}, [answeredIndex, withoutGoodAnswer, setAnswersCollapsed, onCollapse, answersCollapseDelay, hasAnsweredRight,
|
|
162
|
+
}, [answeredIndex, withoutGoodAnswer, setAnswersCollapsed, onCollapse, answersCollapseDelay, hasAnsweredRight, finalShowUserAnswer]);
|
|
162
163
|
var onAnswerTransitionEnd = useCallback(function () {
|
|
163
164
|
if (onTransitionEnd !== null) {
|
|
164
165
|
onTransitionEnd();
|
|
@@ -173,7 +174,7 @@ var Answers = function Answers(_ref) {
|
|
|
173
174
|
}
|
|
174
175
|
}, [shouldCollapse, answersCollapsed, answersDidCollapsed, setAnswersCollapsed, onCollapsed, onTransitionEnd]);
|
|
175
176
|
return /*#__PURE__*/React.createElement("div", {
|
|
176
|
-
className: classNames([styles$4.container, (
|
|
177
|
+
className: classNames([styles$4.container, (_ref4 = {}, _defineProperty(_ref4, styles$4.answered, answered), _defineProperty(_ref4, styles$4.withoutGoodAnswer, withoutGoodAnswer || !hasRightAnswer), _defineProperty(_ref4, styles$4.withGoodAnswer, !withoutGoodAnswer && hasRightAnswer), _defineProperty(_ref4, styles$4.willCollapse, shouldCollapse && answersCollapsed), _defineProperty(_ref4, styles$4.didCollapsed, shouldCollapse && answersDidCollapsed), _defineProperty(_ref4, styles$4.isPlaceholder, isPlaceholder), _defineProperty(_ref4, className, className !== null), _ref4)]),
|
|
177
178
|
ref: answerRef,
|
|
178
179
|
style: answered && !answersDidCollapsed && (isView || isEdit) && shouldCollapse ? {
|
|
179
180
|
height: answersCollapsed ? rightAnswerHeight : answerHeight
|
|
@@ -181,44 +182,40 @@ var Answers = function Answers(_ref) {
|
|
|
181
182
|
}, items !== null || isPlaceholder ? /*#__PURE__*/React.createElement("div", {
|
|
182
183
|
className: styles$4.items
|
|
183
184
|
}, (isPlaceholder || isEdit && items.length === 0 ? _toConsumableArray(new Array(2)) : items).map(function (answer, answerI) {
|
|
184
|
-
var
|
|
185
|
+
var _ref7;
|
|
185
186
|
|
|
186
187
|
var userAnswer = answerI === answeredIndex;
|
|
187
188
|
|
|
188
|
-
var
|
|
189
|
-
|
|
190
|
-
rightAnswer =
|
|
191
|
-
|
|
192
|
-
label =
|
|
193
|
-
|
|
194
|
-
answerButtonStyle =
|
|
189
|
+
var _ref5 = answer || {},
|
|
190
|
+
_ref5$good = _ref5.good,
|
|
191
|
+
rightAnswer = _ref5$good === void 0 ? false : _ref5$good,
|
|
192
|
+
_ref5$label = _ref5.label,
|
|
193
|
+
label = _ref5$label === void 0 ? null : _ref5$label,
|
|
194
|
+
_ref5$buttonStyle = _ref5.buttonStyle,
|
|
195
|
+
answerButtonStyle = _ref5$buttonStyle === void 0 ? null : _ref5$buttonStyle,
|
|
196
|
+
_ref5$textStyle = _ref5.textStyle,
|
|
197
|
+
answerButtonTextStyle = _ref5$textStyle === void 0 ? null : _ref5$textStyle;
|
|
198
|
+
|
|
199
|
+
var _ref6 = label || {},
|
|
195
200
|
_ref6$textStyle = _ref6.textStyle,
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
var _ref7 = label || {},
|
|
199
|
-
_ref7$textStyle = _ref7.textStyle,
|
|
200
|
-
textStyle = _ref7$textStyle === void 0 ? null : _ref7$textStyle;
|
|
201
|
+
textStyle = _ref6$textStyle === void 0 ? null : _ref6$textStyle;
|
|
201
202
|
|
|
202
203
|
var hasAnswer = isTextFilled(label);
|
|
203
|
-
var hasFinalUserAnswer =
|
|
204
|
-
|
|
205
|
-
if (!showUserAnswer && answersDidCollapsed && !rightAnswer) {
|
|
206
|
-
return null;
|
|
207
|
-
} // Only show user answer
|
|
208
|
-
|
|
204
|
+
var hasFinalUserAnswer = finalShowUserAnswer && answeredIndex !== null; // Hide bad answers
|
|
209
205
|
|
|
210
|
-
if (
|
|
206
|
+
if (answersDidCollapsed && !rightAnswer && (hasRightAnswer || !userAnswer)) {
|
|
211
207
|
return null;
|
|
212
208
|
}
|
|
213
209
|
|
|
210
|
+
var answerToShow = rightAnswer && hasRightAnswer || !hasRightAnswer && userAnswer && finalShowUserAnswer;
|
|
214
211
|
return /*#__PURE__*/React.createElement("div", {
|
|
215
212
|
key: "answer-".concat(answerI),
|
|
216
|
-
ref:
|
|
217
|
-
className: classNames([styles$4.item, (
|
|
218
|
-
style: answersCollapsed &&
|
|
213
|
+
ref: answerToShow ? rightAnswerRef : null,
|
|
214
|
+
className: classNames([styles$4.item, (_ref7 = {}, _defineProperty(_ref7, styles$4.rightAnswer, rightAnswer && !withoutGoodAnswer), _defineProperty(_ref7, styles$4.userAnswer, userAnswer && !finalShowUserAnswer), _defineProperty(_ref7, styles$4.isUserAnswer, userAnswer && hasFinalUserAnswer), _defineProperty(_ref7, styles$4.answerToSlide, answerToShow), _ref7)]),
|
|
215
|
+
style: answersCollapsed && answerToShow && !answersDidCollapsed && shouldCollapse ? {
|
|
219
216
|
transform: "translateY(".concat(-rightAnswerTop, "px)")
|
|
220
217
|
} : null,
|
|
221
|
-
onTransitionEnd:
|
|
218
|
+
onTransitionEnd: answerToShow ? onAnswerTransitionEnd : null
|
|
222
219
|
}, /*#__PURE__*/React.createElement("div", {
|
|
223
220
|
className: styles$4.itemContent
|
|
224
221
|
}, /*#__PURE__*/React.createElement(ScreenElement, {
|
|
@@ -290,7 +287,6 @@ var propTypes$4 = {
|
|
|
290
287
|
badAnswerColor: PropTypes.color,
|
|
291
288
|
focusable: PropTypes$1.bool,
|
|
292
289
|
layout: PropTypes$1.string,
|
|
293
|
-
callToActionHeight: PropTypes$1.number,
|
|
294
290
|
showInstantAnswer: PropTypes$1.bool,
|
|
295
291
|
withResult: PropTypes$1.bool,
|
|
296
292
|
withoutGoodAnswer: PropTypes$1.bool,
|
|
@@ -319,7 +315,6 @@ var defaultProps$4 = {
|
|
|
319
315
|
badAnswerColor: null,
|
|
320
316
|
focusable: false,
|
|
321
317
|
layout: null,
|
|
322
|
-
callToActionHeight: null,
|
|
323
318
|
showInstantAnswer: false,
|
|
324
319
|
withResult: false,
|
|
325
320
|
withoutGoodAnswer: false,
|
|
@@ -336,7 +331,7 @@ var defaultProps$4 = {
|
|
|
336
331
|
};
|
|
337
332
|
|
|
338
333
|
var Question = function Question(_ref) {
|
|
339
|
-
var
|
|
334
|
+
var _ref3;
|
|
340
335
|
|
|
341
336
|
var question = _ref.question,
|
|
342
337
|
answers = _ref.answers,
|
|
@@ -356,7 +351,6 @@ var Question = function Question(_ref) {
|
|
|
356
351
|
withoutTrueFalse = _ref.withoutTrueFalse,
|
|
357
352
|
withoutIndex = _ref.withoutIndex,
|
|
358
353
|
layout = _ref.layout,
|
|
359
|
-
callToActionHeight = _ref.callToActionHeight,
|
|
360
354
|
transitions = _ref.transitions,
|
|
361
355
|
transitionPlaying = _ref.transitionPlaying,
|
|
362
356
|
transitionStagger = _ref.transitionStagger,
|
|
@@ -385,22 +379,12 @@ var Question = function Question(_ref) {
|
|
|
385
379
|
setResultVisible = _useState2[1];
|
|
386
380
|
|
|
387
381
|
var answered = answeredIndex !== null;
|
|
388
|
-
|
|
389
|
-
var _useResizeObserver = useResizeObserver(),
|
|
390
|
-
resultRef = _useResizeObserver.ref,
|
|
391
|
-
resultContentRect = _useResizeObserver.entry.contentRect;
|
|
392
|
-
|
|
393
|
-
var _ref3 = resultContentRect || {};
|
|
394
|
-
_ref3.height; // eslint-disable-line
|
|
395
|
-
|
|
396
|
-
|
|
397
382
|
var onAnswersCollapse = useCallback(function () {
|
|
398
383
|
setResultVisible(true);
|
|
399
384
|
}, [setResultVisible]);
|
|
400
385
|
var hasIndex = index !== null && totalCount !== null;
|
|
401
386
|
return /*#__PURE__*/React.createElement(Layout, {
|
|
402
|
-
className: classNames([styles$3.container, (
|
|
403
|
-
fullscreen: true,
|
|
387
|
+
className: classNames([styles$3.container, (_ref3 = {}, _defineProperty(_ref3, styles$3.isPlaceholder, isPlaceholder), _defineProperty(_ref3, styles$3.resultVisible, resultVisible), _defineProperty(_ref3, className, className !== null), _ref3)]),
|
|
404
388
|
verticalAlign: verticalAlign,
|
|
405
389
|
style: style
|
|
406
390
|
}, [!withoutIndex && hasIndex ? /*#__PURE__*/React.createElement(ScreenElement, {
|
|
@@ -456,8 +440,7 @@ var Question = function Question(_ref) {
|
|
|
456
440
|
onTransitionEnd: onAnswerTransitionEnd
|
|
457
441
|
}), withResult ? /*#__PURE__*/React.createElement("div", {
|
|
458
442
|
className: styles$3.result,
|
|
459
|
-
key: "results"
|
|
460
|
-
ref: resultRef
|
|
443
|
+
key: "results"
|
|
461
444
|
}, /*#__PURE__*/React.createElement("div", {
|
|
462
445
|
className: styles$3.resultContent
|
|
463
446
|
}, /*#__PURE__*/React.createElement(ScreenElement, {
|
|
@@ -477,11 +460,7 @@ var Question = function Question(_ref) {
|
|
|
477
460
|
disabled: transitionDisabled
|
|
478
461
|
}, /*#__PURE__*/React.createElement(Text, Object.assign({}, result, {
|
|
479
462
|
className: styles$3.resultText
|
|
480
|
-
}))
|
|
481
|
-
style: {
|
|
482
|
-
height: callToActionHeight
|
|
483
|
-
}
|
|
484
|
-
}) : null) : null))) : null]);
|
|
463
|
+
}))) : null))) : null]);
|
|
485
464
|
};
|
|
486
465
|
|
|
487
466
|
Question.propTypes = propTypes$4;
|
|
@@ -511,8 +490,6 @@ var propTypes$3 = {
|
|
|
511
490
|
transitions: PropTypes.transitions,
|
|
512
491
|
transitionStagger: PropTypes$1.number,
|
|
513
492
|
type: PropTypes$1.string,
|
|
514
|
-
enableInteraction: PropTypes$1.func,
|
|
515
|
-
disableInteraction: PropTypes$1.func,
|
|
516
493
|
className: PropTypes$1.string
|
|
517
494
|
};
|
|
518
495
|
var defaultProps$3 = {
|
|
@@ -534,8 +511,6 @@ var defaultProps$3 = {
|
|
|
534
511
|
transitions: null,
|
|
535
512
|
transitionStagger: 100,
|
|
536
513
|
type: null,
|
|
537
|
-
enableInteraction: null,
|
|
538
|
-
disableInteraction: null,
|
|
539
514
|
className: null
|
|
540
515
|
};
|
|
541
516
|
|
|
@@ -558,8 +533,6 @@ var QuizScreen = function QuizScreen(_ref) {
|
|
|
558
533
|
transitions = _ref.transitions,
|
|
559
534
|
transitionStagger = _ref.transitionStagger,
|
|
560
535
|
type = _ref.type,
|
|
561
|
-
enableInteraction = _ref.enableInteraction,
|
|
562
|
-
disableInteraction = _ref.disableInteraction,
|
|
563
536
|
className = _ref.className;
|
|
564
537
|
var screenId = id || 'screen-id';
|
|
565
538
|
var trackScreenEvent = useTrackScreenEvent(type);
|
|
@@ -567,12 +540,8 @@ var QuizScreen = function QuizScreen(_ref) {
|
|
|
567
540
|
var _useScreenSize = useScreenSize(),
|
|
568
541
|
width = _useScreenSize.width,
|
|
569
542
|
height = _useScreenSize.height,
|
|
570
|
-
menuOverScreen = _useScreenSize.menuOverScreen,
|
|
571
543
|
resolution = _useScreenSize.resolution;
|
|
572
544
|
|
|
573
|
-
var _useViewer = useViewer(),
|
|
574
|
-
menuSize = _useViewer.menuSize;
|
|
575
|
-
|
|
576
545
|
var _useScreenRenderConte = useScreenRenderContext(),
|
|
577
546
|
isView = _useScreenRenderConte.isView,
|
|
578
547
|
isPreview = _useScreenRenderConte.isPreview,
|
|
@@ -581,20 +550,31 @@ var QuizScreen = function QuizScreen(_ref) {
|
|
|
581
550
|
isStatic = _useScreenRenderConte.isStatic,
|
|
582
551
|
isCapture = _useScreenRenderConte.isCapture;
|
|
583
552
|
|
|
553
|
+
var _useViewerContext = useViewerContext(),
|
|
554
|
+
viewerTopHeight = _useViewerContext.topHeight,
|
|
555
|
+
viewerBottomHeight = _useViewerContext.bottomHeight,
|
|
556
|
+
viewerBottomSidesWidth = _useViewerContext.bottomSidesWidth;
|
|
557
|
+
|
|
558
|
+
var _useViewerWebView = useViewerWebView(),
|
|
559
|
+
openWebView = _useViewerWebView.open;
|
|
560
|
+
|
|
561
|
+
var _usePlaybackContext = usePlaybackContext(),
|
|
562
|
+
muted = _usePlaybackContext.muted;
|
|
563
|
+
|
|
564
|
+
var mediaRef = usePlaybackMediaRef(current);
|
|
584
565
|
var transitionPlaying = current;
|
|
585
566
|
var transitionDisabled = isStatic || isCapture || isPlaceholder || isPreview || isEdit;
|
|
586
567
|
var backgroundPlaying = current && (isView || isEdit);
|
|
587
568
|
var mediaShouldLoad = current || active; // Call to Action
|
|
588
569
|
|
|
589
|
-
var
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
callToActionRef = _useResizeObserver.ref,
|
|
593
|
-
callToActionRect = _useResizeObserver.entry.contentRect;
|
|
570
|
+
var _ref2 = callToAction || {},
|
|
571
|
+
_ref2$active = _ref2.active,
|
|
572
|
+
hasCallToAction = _ref2$active === void 0 ? false : _ref2$active;
|
|
594
573
|
|
|
595
|
-
var
|
|
596
|
-
|
|
597
|
-
|
|
574
|
+
var _useDimensionObserver = useDimensionObserver(),
|
|
575
|
+
callToActionRef = _useDimensionObserver.ref,
|
|
576
|
+
_useDimensionObserver2 = _useDimensionObserver.height,
|
|
577
|
+
callToActionHeight = _useDimensionObserver2 === void 0 ? 0 : _useDimensionObserver2;
|
|
598
578
|
|
|
599
579
|
var showInstantAnswer = isStatic || isCapture;
|
|
600
580
|
var goodAnswerIndex = answers !== null ? answers.findIndex(function (answer) {
|
|
@@ -606,8 +586,15 @@ var QuizScreen = function QuizScreen(_ref) {
|
|
|
606
586
|
userAnswerIndex = _useState2[0],
|
|
607
587
|
setUserAnswerIndex = _useState2[1];
|
|
608
588
|
|
|
589
|
+
var visitor = useVisitor();
|
|
590
|
+
|
|
591
|
+
var _ref3 = visitor || {},
|
|
592
|
+
_ref3$id = _ref3.id,
|
|
593
|
+
visitorId = _ref3$id === void 0 ? null : _ref3$id;
|
|
594
|
+
|
|
609
595
|
var _useQuizCreate = useQuizCreate({
|
|
610
|
-
screenId: screenId
|
|
596
|
+
screenId: screenId,
|
|
597
|
+
visitorId: visitorId
|
|
611
598
|
}),
|
|
612
599
|
submitQuiz = _useQuizCreate.create;
|
|
613
600
|
|
|
@@ -629,15 +616,15 @@ var QuizScreen = function QuizScreen(_ref) {
|
|
|
629
616
|
}, [isEdit, current, userAnswerIndex, setUserAnswerIndex]);
|
|
630
617
|
useEffect(function () {
|
|
631
618
|
if (userAnswerIndex !== null) {
|
|
632
|
-
var
|
|
633
|
-
|
|
634
|
-
isGood =
|
|
635
|
-
|
|
636
|
-
label =
|
|
619
|
+
var _ref4 = userAnswerIndex !== null && answers ? answers[userAnswerIndex] : {},
|
|
620
|
+
_ref4$good = _ref4.good,
|
|
621
|
+
isGood = _ref4$good === void 0 ? false : _ref4$good,
|
|
622
|
+
_ref4$label = _ref4.label,
|
|
623
|
+
label = _ref4$label === void 0 ? {} : _ref4$label;
|
|
637
624
|
|
|
638
|
-
var
|
|
639
|
-
|
|
640
|
-
body =
|
|
625
|
+
var _ref5 = label || {},
|
|
626
|
+
_ref5$body = _ref5.body,
|
|
627
|
+
body = _ref5$body === void 0 ? '' : _ref5$body;
|
|
641
628
|
|
|
642
629
|
submitQuiz({
|
|
643
630
|
choice: body || userAnswerIndex,
|
|
@@ -645,6 +632,27 @@ var QuizScreen = function QuizScreen(_ref) {
|
|
|
645
632
|
});
|
|
646
633
|
}
|
|
647
634
|
}, [userAnswerIndex, answers, submitQuiz]);
|
|
635
|
+
var scrollingDisabled = !isEdit && transitionDisabled || !current;
|
|
636
|
+
|
|
637
|
+
var _useState3 = useState(false),
|
|
638
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
639
|
+
scrolledBottom = _useState4[0],
|
|
640
|
+
setScrolledBottom = _useState4[1];
|
|
641
|
+
|
|
642
|
+
var onScrolledBottom = useCallback(function (_ref6) {
|
|
643
|
+
var initial = _ref6.initial;
|
|
644
|
+
|
|
645
|
+
if (initial) {
|
|
646
|
+
trackScreenEvent('scroll', 'Screen');
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
setScrolledBottom(true);
|
|
650
|
+
}, [trackScreenEvent]);
|
|
651
|
+
var onScrolledNotBottom = useCallback(function () {
|
|
652
|
+
setScrolledBottom(false);
|
|
653
|
+
}, [setScrolledBottom]);
|
|
654
|
+
var isSplitted = layout === 'split';
|
|
655
|
+
var verticalAlign = isSplitted ? null : layout;
|
|
648
656
|
return /*#__PURE__*/React.createElement("div", {
|
|
649
657
|
className: classNames([styles$2.container, _defineProperty({}, className, className !== null)]),
|
|
650
658
|
"data-screen-ready": true
|
|
@@ -654,10 +662,17 @@ var QuizScreen = function QuizScreen(_ref) {
|
|
|
654
662
|
height: height,
|
|
655
663
|
resolution: resolution,
|
|
656
664
|
playing: backgroundPlaying,
|
|
657
|
-
|
|
665
|
+
muted: muted,
|
|
666
|
+
shouldLoad: mediaShouldLoad,
|
|
667
|
+
mediaRef: mediaRef
|
|
658
668
|
}) : null, /*#__PURE__*/React.createElement(Container, {
|
|
659
669
|
width: width,
|
|
660
670
|
height: height
|
|
671
|
+
}, /*#__PURE__*/React.createElement(Scroll, {
|
|
672
|
+
verticalAlign: verticalAlign,
|
|
673
|
+
disabled: scrollingDisabled,
|
|
674
|
+
onScrolledBottom: onScrolledBottom,
|
|
675
|
+
onScrolledNotBottom: onScrolledNotBottom
|
|
661
676
|
}, /*#__PURE__*/React.createElement(Question, {
|
|
662
677
|
question: question,
|
|
663
678
|
answers: answers,
|
|
@@ -672,7 +687,6 @@ var QuizScreen = function QuizScreen(_ref) {
|
|
|
672
687
|
showInstantAnswer: showInstantAnswer,
|
|
673
688
|
withResult: true,
|
|
674
689
|
layout: layout,
|
|
675
|
-
callToActionHeight: callToActionHeight,
|
|
676
690
|
transitions: transitions,
|
|
677
691
|
transitionPlaying: transitionPlaying,
|
|
678
692
|
transitionStagger: transitionStagger,
|
|
@@ -681,21 +695,24 @@ var QuizScreen = function QuizScreen(_ref) {
|
|
|
681
695
|
className: styles$2.question,
|
|
682
696
|
style: !isPlaceholder ? {
|
|
683
697
|
padding: spacing,
|
|
684
|
-
paddingTop: (
|
|
698
|
+
paddingTop: (!isPreview ? viewerTopHeight : 0) + spacing,
|
|
699
|
+
paddingBottom: (!isPreview ? viewerBottomHeight : 0) + (callToActionHeight || spacing)
|
|
685
700
|
} : null
|
|
686
|
-
}), !isPlaceholder && hasCallToAction ? /*#__PURE__*/React.createElement(
|
|
701
|
+
})), !isPlaceholder && hasCallToAction ? /*#__PURE__*/React.createElement("div", {
|
|
687
702
|
ref: callToActionRef,
|
|
688
|
-
className: styles$2.callToAction,
|
|
689
|
-
|
|
703
|
+
className: classNames([styles$2.callToAction, _defineProperty({}, styles$2.disabled, !scrolledBottom)]),
|
|
704
|
+
style: {
|
|
705
|
+
transform: !isPreview ? "translate(0, -".concat(viewerBottomHeight, "px)") : null,
|
|
706
|
+
paddingLeft: Math.max(spacing / 2, viewerBottomSidesWidth),
|
|
707
|
+
paddingRight: Math.max(spacing / 2, viewerBottomSidesWidth),
|
|
708
|
+
paddingTop: spacing / 2,
|
|
709
|
+
paddingBottom: spacing / 2
|
|
710
|
+
}
|
|
711
|
+
}, /*#__PURE__*/React.createElement(CallToAction, Object.assign({}, callToAction, {
|
|
690
712
|
animationDisabled: isPreview,
|
|
691
713
|
focusable: current && isView,
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
height: height
|
|
695
|
-
},
|
|
696
|
-
enableInteraction: enableInteraction,
|
|
697
|
-
disableInteraction: disableInteraction
|
|
698
|
-
}) : null));
|
|
714
|
+
openWebView: openWebView
|
|
715
|
+
}))) : null));
|
|
699
716
|
};
|
|
700
717
|
|
|
701
718
|
QuizScreen.propTypes = propTypes$3;
|
|
@@ -996,7 +1013,7 @@ var defaultProps = {
|
|
|
996
1013
|
};
|
|
997
1014
|
|
|
998
1015
|
var QuizMultipleScreen = function QuizMultipleScreen(_ref) {
|
|
999
|
-
var
|
|
1016
|
+
var _ref13;
|
|
1000
1017
|
|
|
1001
1018
|
var id = _ref.id,
|
|
1002
1019
|
layout = _ref.layout,
|
|
@@ -1029,11 +1046,12 @@ var QuizMultipleScreen = function QuizMultipleScreen(_ref) {
|
|
|
1029
1046
|
var _useScreenSize = useScreenSize(),
|
|
1030
1047
|
width = _useScreenSize.width,
|
|
1031
1048
|
height = _useScreenSize.height,
|
|
1032
|
-
menuOverScreen = _useScreenSize.menuOverScreen,
|
|
1033
1049
|
resolution = _useScreenSize.resolution;
|
|
1034
1050
|
|
|
1035
|
-
var
|
|
1036
|
-
|
|
1051
|
+
var _useViewerContext = useViewerContext(),
|
|
1052
|
+
viewerTopHeight = _useViewerContext.topHeight,
|
|
1053
|
+
viewerBottomHeight = _useViewerContext.bottomHeight,
|
|
1054
|
+
viewerBottomSidesWidth = _useViewerContext.bottomSidesWidth;
|
|
1037
1055
|
|
|
1038
1056
|
var _useScreenRenderConte = useScreenRenderContext(),
|
|
1039
1057
|
isView = _useScreenRenderConte.isView,
|
|
@@ -1043,6 +1061,14 @@ var QuizMultipleScreen = function QuizMultipleScreen(_ref) {
|
|
|
1043
1061
|
isStatic = _useScreenRenderConte.isStatic,
|
|
1044
1062
|
isCapture = _useScreenRenderConte.isCapture;
|
|
1045
1063
|
|
|
1064
|
+
var _usePlaybackContext = usePlaybackContext(),
|
|
1065
|
+
muted = _usePlaybackContext.muted;
|
|
1066
|
+
|
|
1067
|
+
var mediaRef = usePlaybackMediaRef(current);
|
|
1068
|
+
|
|
1069
|
+
var _useViewerWebView = useViewerWebView(),
|
|
1070
|
+
openWebView = _useViewerWebView.open;
|
|
1071
|
+
|
|
1046
1072
|
var screenState = useScreenState();
|
|
1047
1073
|
|
|
1048
1074
|
var _ref2 = screenState !== null ? screenState.split('.') : [],
|
|
@@ -1059,13 +1085,10 @@ var QuizMultipleScreen = function QuizMultipleScreen(_ref) {
|
|
|
1059
1085
|
|
|
1060
1086
|
var hasCallToAction = callToAction !== null && callToAction.active === true;
|
|
1061
1087
|
|
|
1062
|
-
var
|
|
1063
|
-
callToActionRef =
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
var _ref4 = callToActionRect || {},
|
|
1067
|
-
_ref4$height = _ref4.height,
|
|
1068
|
-
callToActionHeight = _ref4$height === void 0 ? 0 : _ref4$height;
|
|
1088
|
+
var _useDimensionObserver = useDimensionObserver(),
|
|
1089
|
+
callToActionRef = _useDimensionObserver.ref,
|
|
1090
|
+
_useDimensionObserver2 = _useDimensionObserver.height,
|
|
1091
|
+
callToActionHeight = _useDimensionObserver2 === void 0 ? 0 : _useDimensionObserver2;
|
|
1069
1092
|
|
|
1070
1093
|
var showInstantAnswer = isStatic || isCapture;
|
|
1071
1094
|
var hasIntro = title !== null || description !== null || isEdit || stateId === 'intro';
|
|
@@ -1133,15 +1156,15 @@ var QuizMultipleScreen = function QuizMultipleScreen(_ref) {
|
|
|
1133
1156
|
var currentAnsweredIndex = userAnswers !== null && typeof userAnswers[questionIndex] !== 'undefined' ? userAnswers[questionIndex] : null;
|
|
1134
1157
|
var currentPoints = useMemo(function () {
|
|
1135
1158
|
return userAnswers !== null ? Object.keys(userAnswers).reduce(function (totalPoints, answerQuestionIndex) {
|
|
1136
|
-
var
|
|
1137
|
-
|
|
1138
|
-
questionAnswers =
|
|
1159
|
+
var _ref4 = questions !== null ? questions[answerQuestionIndex] || {} : {},
|
|
1160
|
+
_ref4$answers = _ref4.answers,
|
|
1161
|
+
questionAnswers = _ref4$answers === void 0 ? [] : _ref4$answers;
|
|
1139
1162
|
|
|
1140
1163
|
var answerIndex = userAnswers[answerQuestionIndex];
|
|
1141
1164
|
|
|
1142
|
-
var
|
|
1143
|
-
|
|
1144
|
-
points =
|
|
1165
|
+
var _ref5 = questionAnswers[answerIndex] || {},
|
|
1166
|
+
_ref5$points = _ref5.points,
|
|
1167
|
+
points = _ref5$points === void 0 ? 0 : _ref5$points;
|
|
1145
1168
|
|
|
1146
1169
|
return points + totalPoints;
|
|
1147
1170
|
}, 0) : 0;
|
|
@@ -1158,11 +1181,11 @@ var QuizMultipleScreen = function QuizMultipleScreen(_ref) {
|
|
|
1158
1181
|
return (results || [])[parseInt(stateIndex, 10)] || null;
|
|
1159
1182
|
}
|
|
1160
1183
|
|
|
1161
|
-
return (results || []).sort(function (
|
|
1184
|
+
return (results || []).sort(function (_ref6, _ref7) {
|
|
1185
|
+
var _ref6$points = _ref6.points,
|
|
1186
|
+
pointsA = _ref6$points === void 0 ? 0 : _ref6$points;
|
|
1162
1187
|
var _ref7$points = _ref7.points,
|
|
1163
|
-
|
|
1164
|
-
var _ref8$points = _ref8.points,
|
|
1165
|
-
pointsB = _ref8$points === void 0 ? 0 : _ref8$points;
|
|
1188
|
+
pointsB = _ref7$points === void 0 ? 0 : _ref7$points;
|
|
1166
1189
|
|
|
1167
1190
|
if (pointsA === pointsB) {
|
|
1168
1191
|
return 0;
|
|
@@ -1170,26 +1193,33 @@ var QuizMultipleScreen = function QuizMultipleScreen(_ref) {
|
|
|
1170
1193
|
|
|
1171
1194
|
return pointsA > pointsB ? 1 : -1;
|
|
1172
1195
|
}).reduce(function (lastResult, result) {
|
|
1173
|
-
var
|
|
1174
|
-
|
|
1175
|
-
lastPoints =
|
|
1196
|
+
var _ref8 = lastResult || {},
|
|
1197
|
+
_ref8$points = _ref8.points,
|
|
1198
|
+
lastPoints = _ref8$points === void 0 ? 0 : _ref8$points;
|
|
1176
1199
|
|
|
1177
|
-
var
|
|
1178
|
-
|
|
1179
|
-
points =
|
|
1200
|
+
var _ref9 = result || {},
|
|
1201
|
+
_ref9$points = _ref9.points,
|
|
1202
|
+
points = _ref9$points === void 0 ? 0 : _ref9$points;
|
|
1180
1203
|
|
|
1181
1204
|
return currentPoints >= lastPoints && currentPoints <= points ? result : lastResult;
|
|
1182
1205
|
}, null);
|
|
1183
1206
|
}, [isResults, results, currentPoints, stateId, stateIndex]);
|
|
1184
1207
|
|
|
1185
|
-
var
|
|
1186
|
-
|
|
1187
|
-
resultBackground =
|
|
1188
|
-
|
|
1189
|
-
resultLayout =
|
|
1208
|
+
var _ref10 = currentResult || {},
|
|
1209
|
+
_ref10$background = _ref10.background,
|
|
1210
|
+
resultBackground = _ref10$background === void 0 ? null : _ref10$background,
|
|
1211
|
+
_ref10$layout = _ref10.layout,
|
|
1212
|
+
resultLayout = _ref10$layout === void 0 ? null : _ref10$layout;
|
|
1213
|
+
|
|
1214
|
+
var visitor = useVisitor();
|
|
1215
|
+
|
|
1216
|
+
var _ref11 = visitor || {},
|
|
1217
|
+
_ref11$id = _ref11.id,
|
|
1218
|
+
visitorId = _ref11$id === void 0 ? null : _ref11$id;
|
|
1190
1219
|
|
|
1191
1220
|
var _useQuizCreate = useQuizCreate({
|
|
1192
|
-
screenId: screenId
|
|
1221
|
+
screenId: screenId,
|
|
1222
|
+
visitorId: visitorId
|
|
1193
1223
|
}),
|
|
1194
1224
|
submitQuiz = _useQuizCreate.create;
|
|
1195
1225
|
|
|
@@ -1248,8 +1278,37 @@ var QuizMultipleScreen = function QuizMultipleScreen(_ref) {
|
|
|
1248
1278
|
lastQuestionIndexRef.current = questionIndex;
|
|
1249
1279
|
return 'right';
|
|
1250
1280
|
}, [questionIndex]);
|
|
1281
|
+
var scrollingDisabled = !isEdit && transitionDisabled || !current;
|
|
1282
|
+
|
|
1283
|
+
var _useState5 = useState(false),
|
|
1284
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
1285
|
+
scrolledBottom = _useState6[0],
|
|
1286
|
+
setScrolledBottom = _useState6[1];
|
|
1287
|
+
|
|
1288
|
+
var onScrolledBottom = useCallback(function (_ref12) {
|
|
1289
|
+
var initial = _ref12.initial;
|
|
1290
|
+
|
|
1291
|
+
if (initial) {
|
|
1292
|
+
trackScreenEvent('scroll', 'Screen');
|
|
1293
|
+
}
|
|
1294
|
+
|
|
1295
|
+
setScrolledBottom(true);
|
|
1296
|
+
}, [trackScreenEvent]);
|
|
1297
|
+
var onScrolledNotBottom = useCallback(function () {
|
|
1298
|
+
setScrolledBottom(false);
|
|
1299
|
+
}, [setScrolledBottom]);
|
|
1300
|
+
var verticalAlign = layout;
|
|
1301
|
+
|
|
1302
|
+
if (isIntro && introLayout !== null) {
|
|
1303
|
+
verticalAlign = introLayout;
|
|
1304
|
+
} else if (isQuestion && questionLayout !== null) {
|
|
1305
|
+
verticalAlign = questionLayout;
|
|
1306
|
+
} else if (isResults && resultLayout !== null) {
|
|
1307
|
+
verticalAlign = questionLayout;
|
|
1308
|
+
}
|
|
1309
|
+
|
|
1251
1310
|
return /*#__PURE__*/React.createElement("div", {
|
|
1252
|
-
className: classNames([styles$2.container, (
|
|
1311
|
+
className: classNames([styles$2.container, (_ref13 = {}, _defineProperty(_ref13, styles$2[direction], direction !== null), _defineProperty(_ref13, className, className !== null), _ref13)]),
|
|
1253
1312
|
"data-screen-ready": true
|
|
1254
1313
|
}, !isPlaceholder ? /*#__PURE__*/React.createElement(TransitionGroup, null, /*#__PURE__*/React.createElement(CSSTransition, {
|
|
1255
1314
|
key: backgroundKey,
|
|
@@ -1261,11 +1320,18 @@ var QuizMultipleScreen = function QuizMultipleScreen(_ref) {
|
|
|
1261
1320
|
height: height,
|
|
1262
1321
|
resolution: resolution,
|
|
1263
1322
|
playing: backgroundPlaying,
|
|
1323
|
+
muted: muted,
|
|
1264
1324
|
shouldLoad: backgroundShouldLoad,
|
|
1325
|
+
mediaRef: mediaRef,
|
|
1265
1326
|
className: styles$2.background
|
|
1266
1327
|
}))) : null, /*#__PURE__*/React.createElement(Container, {
|
|
1267
1328
|
width: width,
|
|
1268
1329
|
height: height
|
|
1330
|
+
}, /*#__PURE__*/React.createElement(Scroll, {
|
|
1331
|
+
verticalAlign: verticalAlign,
|
|
1332
|
+
disabled: scrollingDisabled,
|
|
1333
|
+
onScrolledBottom: onScrolledBottom,
|
|
1334
|
+
onScrolledNotBottom: onScrolledNotBottom
|
|
1269
1335
|
}, /*#__PURE__*/React.createElement(TransitionGroup, null, [isIntro ? /*#__PURE__*/React.createElement(CSSTransition, {
|
|
1270
1336
|
key: "intro",
|
|
1271
1337
|
classNames: styles$2,
|
|
@@ -1283,7 +1349,8 @@ var QuizMultipleScreen = function QuizMultipleScreen(_ref) {
|
|
|
1283
1349
|
className: styles$2.intro,
|
|
1284
1350
|
style: !isPlaceholder ? {
|
|
1285
1351
|
padding: spacing,
|
|
1286
|
-
paddingTop: (
|
|
1352
|
+
paddingTop: (!isPreview ? viewerTopHeight : 0) + spacing,
|
|
1353
|
+
paddingBottom: (!isPreview ? viewerBottomHeight : 0) + (callToActionHeight || spacing)
|
|
1287
1354
|
} : null,
|
|
1288
1355
|
onClickButton: onClickIntroButton
|
|
1289
1356
|
})) : null, isQuestion ? /*#__PURE__*/React.createElement(CSSTransition, {
|
|
@@ -1305,7 +1372,6 @@ var QuizMultipleScreen = function QuizMultipleScreen(_ref) {
|
|
|
1305
1372
|
showInstantAnswer: showInstantAnswer,
|
|
1306
1373
|
layout: questionLayout || layout,
|
|
1307
1374
|
withoutGoodAnswer: true,
|
|
1308
|
-
callToActionHeight: callToActionHeight,
|
|
1309
1375
|
transitions: transitions,
|
|
1310
1376
|
transitionPlaying: transitionPlaying,
|
|
1311
1377
|
transitionStagger: transitionStagger,
|
|
@@ -1315,7 +1381,8 @@ var QuizMultipleScreen = function QuizMultipleScreen(_ref) {
|
|
|
1315
1381
|
className: styles$2.question,
|
|
1316
1382
|
style: !isPlaceholder ? {
|
|
1317
1383
|
padding: spacing,
|
|
1318
|
-
paddingTop: (
|
|
1384
|
+
paddingTop: (!isPreview ? viewerTopHeight : 0) + spacing,
|
|
1385
|
+
paddingBottom: (!isPreview ? viewerBottomHeight : 0) + (callToActionHeight || spacing)
|
|
1319
1386
|
} : null
|
|
1320
1387
|
})) : null, isResults ? /*#__PURE__*/React.createElement(CSSTransition, {
|
|
1321
1388
|
key: "results",
|
|
@@ -1332,19 +1399,24 @@ var QuizMultipleScreen = function QuizMultipleScreen(_ref) {
|
|
|
1332
1399
|
className: styles$2.results,
|
|
1333
1400
|
style: !isPlaceholder ? {
|
|
1334
1401
|
padding: spacing,
|
|
1335
|
-
paddingTop: (
|
|
1402
|
+
paddingTop: (!isPreview ? viewerTopHeight : 0) + spacing,
|
|
1403
|
+
paddingBottom: (!isPreview ? viewerBottomHeight : 0) + (callToActionHeight || spacing)
|
|
1336
1404
|
} : null
|
|
1337
|
-
}))) : null]), !isPlaceholder && hasCallToAction ? /*#__PURE__*/React.createElement(
|
|
1405
|
+
}))) : null])), !isPlaceholder && hasCallToAction ? /*#__PURE__*/React.createElement("div", {
|
|
1338
1406
|
ref: callToActionRef,
|
|
1339
|
-
className: styles$2.callToAction,
|
|
1340
|
-
|
|
1407
|
+
className: classNames([styles$2.callToAction, _defineProperty({}, styles$2.disabled, !scrolledBottom)]),
|
|
1408
|
+
style: {
|
|
1409
|
+
transform: !isPreview ? "translate(0, -".concat(viewerBottomHeight, "px)") : null,
|
|
1410
|
+
paddingLeft: Math.max(spacing / 2, viewerBottomSidesWidth),
|
|
1411
|
+
paddingRight: Math.max(spacing / 2, viewerBottomSidesWidth),
|
|
1412
|
+
paddingTop: spacing / 2,
|
|
1413
|
+
paddingBottom: spacing / 2
|
|
1414
|
+
}
|
|
1415
|
+
}, /*#__PURE__*/React.createElement(CallToAction, Object.assign({}, callToAction, {
|
|
1341
1416
|
animationDisabled: isPreview,
|
|
1342
1417
|
focusable: current && isView,
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
height: height
|
|
1346
|
-
}
|
|
1347
|
-
}) : null));
|
|
1418
|
+
openWebView: openWebView
|
|
1419
|
+
}))) : null));
|
|
1348
1420
|
};
|
|
1349
1421
|
|
|
1350
1422
|
QuizMultipleScreen.propTypes = propTypes;
|
|
@@ -1813,4 +1885,4 @@ var definition = [{
|
|
|
1813
1885
|
}]
|
|
1814
1886
|
}];
|
|
1815
1887
|
|
|
1816
|
-
export { QuizScreen, definition as default };
|
|
1888
|
+
export { QuizMultipleScreen, QuizScreen, definition as default };
|