@pie-element/ebsr 10.7.2 → 10.7.3-next.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/configure/node_modules/@pie-element/multiple-choice/CHANGELOG.json +1972 -0
  2. package/configure/node_modules/@pie-element/multiple-choice/CHANGELOG.md +4144 -0
  3. package/configure/node_modules/@pie-element/multiple-choice/LICENSE.md +5 -0
  4. package/configure/node_modules/@pie-element/multiple-choice/PRINT.md +35 -0
  5. package/configure/node_modules/@pie-element/multiple-choice/README.md +56 -0
  6. package/configure/node_modules/@pie-element/multiple-choice/choice.png +0 -0
  7. package/configure/node_modules/@pie-element/multiple-choice/configure/CHANGELOG.json +1387 -0
  8. package/configure/node_modules/@pie-element/multiple-choice/configure/CHANGELOG.md +3316 -0
  9. package/configure/node_modules/@pie-element/multiple-choice/configure/lib/defaults.js +202 -0
  10. package/configure/node_modules/@pie-element/multiple-choice/configure/lib/defaults.js.map +1 -0
  11. package/configure/node_modules/@pie-element/multiple-choice/configure/lib/index.js +248 -0
  12. package/configure/node_modules/@pie-element/multiple-choice/configure/lib/index.js.map +1 -0
  13. package/configure/node_modules/@pie-element/multiple-choice/configure/lib/main.js +597 -0
  14. package/configure/node_modules/@pie-element/multiple-choice/configure/lib/main.js.map +1 -0
  15. package/configure/node_modules/@pie-element/multiple-choice/configure/lib/utils.js +18 -0
  16. package/configure/node_modules/@pie-element/multiple-choice/configure/lib/utils.js.map +1 -0
  17. package/configure/node_modules/@pie-element/multiple-choice/configure/package.json +18 -0
  18. package/configure/node_modules/@pie-element/multiple-choice/controller/CHANGELOG.json +527 -0
  19. package/configure/node_modules/@pie-element/multiple-choice/controller/CHANGELOG.md +2281 -0
  20. package/configure/node_modules/@pie-element/multiple-choice/controller/lib/defaults.js +34 -0
  21. package/configure/node_modules/@pie-element/multiple-choice/controller/lib/defaults.js.map +1 -0
  22. package/configure/node_modules/@pie-element/multiple-choice/controller/lib/index.js +346 -0
  23. package/configure/node_modules/@pie-element/multiple-choice/controller/lib/index.js.map +1 -0
  24. package/configure/node_modules/@pie-element/multiple-choice/controller/lib/utils.js +28 -0
  25. package/configure/node_modules/@pie-element/multiple-choice/controller/lib/utils.js.map +1 -0
  26. package/configure/node_modules/@pie-element/multiple-choice/controller/package.json +15 -0
  27. package/configure/node_modules/@pie-element/multiple-choice/docs/config-schema.json +2993 -0
  28. package/configure/node_modules/@pie-element/multiple-choice/docs/config-schema.json.md +2217 -0
  29. package/configure/node_modules/@pie-element/multiple-choice/docs/demo/config.js +8 -0
  30. package/configure/node_modules/@pie-element/multiple-choice/docs/demo/generate.js +61 -0
  31. package/configure/node_modules/@pie-element/multiple-choice/docs/demo/index.html +1 -0
  32. package/configure/node_modules/@pie-element/multiple-choice/docs/demo/session.js +7 -0
  33. package/configure/node_modules/@pie-element/multiple-choice/docs/pie-schema.json +1332 -0
  34. package/configure/node_modules/@pie-element/multiple-choice/docs/pie-schema.json.md +1015 -0
  35. package/configure/node_modules/@pie-element/multiple-choice/lib/choice-input.js +427 -0
  36. package/configure/node_modules/@pie-element/multiple-choice/lib/choice-input.js.map +1 -0
  37. package/configure/node_modules/@pie-element/multiple-choice/lib/choice.js +252 -0
  38. package/configure/node_modules/@pie-element/multiple-choice/lib/choice.js.map +1 -0
  39. package/configure/node_modules/@pie-element/multiple-choice/lib/feedback-tick.js +174 -0
  40. package/configure/node_modules/@pie-element/multiple-choice/lib/feedback-tick.js.map +1 -0
  41. package/configure/node_modules/@pie-element/multiple-choice/lib/index.js +388 -0
  42. package/configure/node_modules/@pie-element/multiple-choice/lib/index.js.map +1 -0
  43. package/configure/node_modules/@pie-element/multiple-choice/lib/main.js +108 -0
  44. package/configure/node_modules/@pie-element/multiple-choice/lib/main.js.map +1 -0
  45. package/configure/node_modules/@pie-element/multiple-choice/lib/multiple-choice.js +469 -0
  46. package/configure/node_modules/@pie-element/multiple-choice/lib/multiple-choice.js.map +1 -0
  47. package/configure/node_modules/@pie-element/multiple-choice/lib/print.js +129 -0
  48. package/configure/node_modules/@pie-element/multiple-choice/lib/print.js.map +1 -0
  49. package/configure/node_modules/@pie-element/multiple-choice/lib/session-updater.js +48 -0
  50. package/configure/node_modules/@pie-element/multiple-choice/lib/session-updater.js.map +1 -0
  51. package/configure/node_modules/@pie-element/multiple-choice/module/configure.js +1 -0
  52. package/configure/node_modules/@pie-element/multiple-choice/module/controller.js +3611 -0
  53. package/configure/node_modules/@pie-element/multiple-choice/module/demo.js +86 -0
  54. package/configure/node_modules/@pie-element/multiple-choice/module/element.js +1 -0
  55. package/configure/node_modules/@pie-element/multiple-choice/module/index.html +21 -0
  56. package/configure/node_modules/@pie-element/multiple-choice/module/manifest.json +10 -0
  57. package/configure/node_modules/@pie-element/multiple-choice/module/print-demo.js +124 -0
  58. package/configure/node_modules/@pie-element/multiple-choice/module/print.html +18 -0
  59. package/configure/node_modules/@pie-element/multiple-choice/module/print.js +1 -0
  60. package/configure/node_modules/@pie-element/multiple-choice/package.json +32 -0
  61. package/module/element.js +1 -1
  62. package/module/index.html +1 -1
  63. package/module/manifest.json +5 -1
  64. package/module/print.html +1 -1
  65. package/module/print.js +1 -1
  66. package/package.json +3 -3
@@ -0,0 +1,388 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.isComplete = exports["default"] = void 0;
9
+
10
+ var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
11
+
12
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
13
+
14
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
15
+
16
+ var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
17
+
18
+ var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
19
+
20
+ var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
21
+
22
+ var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
23
+
24
+ var _wrapNativeSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/wrapNativeSuper"));
25
+
26
+ var _main = _interopRequireDefault(require("./main"));
27
+
28
+ var _react = _interopRequireDefault(require("react"));
29
+
30
+ var _reactDom = _interopRequireDefault(require("react-dom"));
31
+
32
+ var _debounce = _interopRequireDefault(require("lodash/debounce"));
33
+
34
+ var _debug = _interopRequireDefault(require("debug"));
35
+
36
+ var _piePlayerEvents = require("@pie-framework/pie-player-events");
37
+
38
+ var _mathRendering = require("@pie-lib/pie-toolbox/math-rendering");
39
+
40
+ var _renderUi = require("@pie-lib/pie-toolbox/render-ui");
41
+
42
+ var _sessionUpdater = require("./session-updater");
43
+
44
+ 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); }; }
45
+
46
+ 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; } }
47
+
48
+ var log = (0, _debug["default"])('pie-ui:multiple-choice');
49
+
50
+ var isComplete = function isComplete(session, model, audioComplete, elementContext) {
51
+ var _ref = model || {},
52
+ autoplayAudioEnabled = _ref.autoplayAudioEnabled,
53
+ completeAudioEnabled = _ref.completeAudioEnabled; // check audio completion if audio settings are enabled and audio actually exists
54
+
55
+
56
+ if (autoplayAudioEnabled && completeAudioEnabled && !audioComplete) {
57
+ if (elementContext) {
58
+ var audio = elementContext.querySelector('audio');
59
+ var isInsidePrompt = audio && audio.closest('#preview-prompt'); // only require audio completion if audio exists and is inside the prompt
60
+
61
+ if (audio && isInsidePrompt) {
62
+ return false;
63
+ }
64
+ }
65
+ }
66
+
67
+ if (!session || !session.value) {
68
+ return false;
69
+ }
70
+
71
+ var _ref2 = model || {},
72
+ choiceMode = _ref2.choiceMode,
73
+ _ref2$minSelections = _ref2.minSelections,
74
+ minSelections = _ref2$minSelections === void 0 ? 1 : _ref2$minSelections,
75
+ maxSelections = _ref2.maxSelections;
76
+
77
+ var selections = session.value.length || 0;
78
+
79
+ if (choiceMode === 'radio') {
80
+ return !!selections;
81
+ }
82
+
83
+ if (selections < minSelections || selections > maxSelections) {
84
+ return false;
85
+ }
86
+
87
+ return true;
88
+ };
89
+
90
+ exports.isComplete = isComplete;
91
+
92
+ var MultipleChoice = /*#__PURE__*/function (_HTMLElement) {
93
+ (0, _inherits2["default"])(MultipleChoice, _HTMLElement);
94
+
95
+ var _super = _createSuper(MultipleChoice);
96
+
97
+ function MultipleChoice() {
98
+ var _this;
99
+
100
+ (0, _classCallCheck2["default"])(this, MultipleChoice);
101
+ _this = _super.call(this);
102
+ _this._model = null;
103
+ _this._session = null;
104
+ _this.audioComplete = false;
105
+ _this._boundHandleKeyDown = _this.handleKeyDown.bind((0, _assertThisInitialized2["default"])(_this));
106
+ _this._keyboardEventsEnabled = false;
107
+ _this._audioInitialized = false;
108
+ _this._rerender = (0, _debounce["default"])(function () {
109
+ if (_this._model && _this._session) {
110
+ var element = /*#__PURE__*/_react["default"].createElement(_main["default"], {
111
+ model: _this._model,
112
+ session: _this._session,
113
+ onChoiceChanged: _this._onChange.bind((0, _assertThisInitialized2["default"])(_this)),
114
+ onShowCorrectToggle: _this.onShowCorrectToggle.bind((0, _assertThisInitialized2["default"])(_this))
115
+ }); //TODO: aria-label is set in the _rerender because we need to change it when the model.choiceMode is updated. Consider revisiting the placement of the aria-label setting in the _rerender
116
+
117
+
118
+ _this.setAttribute('aria-label', _this._model.choiceMode === 'radio' ? 'Multiple Choice Question' : 'Multiple Correct Answer Question');
119
+
120
+ _this.setAttribute('role', 'region');
121
+
122
+ _this.setLangAttribute();
123
+
124
+ _reactDom["default"].render(element, (0, _assertThisInitialized2["default"])(_this), function () {
125
+ log('render complete - render math');
126
+ (0, _mathRendering.renderMath)((0, _assertThisInitialized2["default"])(_this));
127
+ });
128
+
129
+ if (_this._model.keyboardEventsEnabled === true && !_this._keyboardEventsEnabled) {
130
+ _this.enableKeyboardEvents();
131
+ }
132
+ } else {
133
+ log('skip');
134
+ }
135
+ }, 50, {
136
+ leading: false,
137
+ trailing: true
138
+ });
139
+ _this._dispatchResponseChanged = (0, _debounce["default"])(function () {
140
+ _this.dispatchEvent(new _piePlayerEvents.SessionChangedEvent(_this.tagName.toLowerCase(), isComplete(_this._session, _this._model, _this.audioComplete, (0, _assertThisInitialized2["default"])(_this))));
141
+ });
142
+ _this._dispatchModelSet = (0, _debounce["default"])(function () {
143
+ _this.dispatchEvent(new _piePlayerEvents.ModelSetEvent(_this.tagName.toLowerCase(), isComplete(_this._session, _this._model, _this.audioComplete, (0, _assertThisInitialized2["default"])(_this)), _this._model !== undefined));
144
+ }, 50, {
145
+ leading: false,
146
+ trailing: true
147
+ });
148
+ return _this;
149
+ }
150
+
151
+ (0, _createClass2["default"])(MultipleChoice, [{
152
+ key: "onShowCorrectToggle",
153
+ value: function onShowCorrectToggle() {
154
+ (0, _mathRendering.renderMath)(this);
155
+ }
156
+ }, {
157
+ key: "setLangAttribute",
158
+ value: function setLangAttribute() {
159
+ var language = this._model && (0, _typeof2["default"])(this._model.language) ? this._model.language : '';
160
+ var lang = language ? language.slice(0, 2) : 'en';
161
+ this.setAttribute('lang', lang);
162
+ }
163
+ }, {
164
+ key: "model",
165
+ set: function set(s) {
166
+ this._model = s;
167
+
168
+ this._rerender(); // reset the audioInitialized to false since the model changed, and we might need to reinitialize the audio
169
+
170
+
171
+ this._audioInitialized = false;
172
+
173
+ this._dispatchModelSet();
174
+ }
175
+ }, {
176
+ key: "session",
177
+ get: function get() {
178
+ return this._session;
179
+ },
180
+ set: function set(s) {
181
+ this._session = s;
182
+
183
+ this._rerender(); //TODO: remove this session-changed should only be emit on user change
184
+
185
+
186
+ this._dispatchResponseChanged();
187
+ }
188
+ }, {
189
+ key: "_onChange",
190
+ value: function _onChange(data) {
191
+ (0, _sessionUpdater.updateSessionValue)(this._session, this._model.choiceMode, data);
192
+
193
+ this._dispatchResponseChanged();
194
+
195
+ this._rerender();
196
+ }
197
+ }, {
198
+ key: "_createAudioInfoToast",
199
+ value: function _createAudioInfoToast() {
200
+ var info = document.createElement('div');
201
+ info.id = 'play-audio-info';
202
+ Object.assign(info.style, {
203
+ position: 'absolute',
204
+ top: 0,
205
+ width: '100%',
206
+ height: '100%',
207
+ display: 'flex',
208
+ justifyContent: 'center',
209
+ alignItems: 'center',
210
+ background: 'white',
211
+ zIndex: '1000',
212
+ cursor: 'pointer'
213
+ });
214
+ var img = document.createElement('img');
215
+ img.src = _renderUi.EnableAudioAutoplayImage;
216
+ img.alt = 'Click anywhere to enable audio autoplay';
217
+ img.width = 500;
218
+ img.height = 300;
219
+ info.appendChild(img);
220
+ return info;
221
+ }
222
+ }, {
223
+ key: "connectedCallback",
224
+ value: function connectedCallback() {
225
+ var _this2 = this;
226
+
227
+ this._rerender(); // Observation: audio in Chrome will have the autoplay attribute,
228
+ // while other browsers will not have the autoplay attribute and will need a user interaction to play the audio
229
+ // This workaround fixes the issue of audio being cached and played on any user interaction in Safari and Firefox
230
+
231
+
232
+ var observer = new MutationObserver(function (mutationsList, observer) {
233
+ mutationsList.forEach(function (mutation) {
234
+ if (mutation.type === 'childList') {
235
+ if (_this2._audioInitialized) return;
236
+
237
+ var audio = _this2.querySelector('audio');
238
+
239
+ var isInsidePrompt = audio && audio.closest('#preview-prompt');
240
+ if (!_this2._model) return;
241
+ if (!_this2._model.autoplayAudioEnabled) return;
242
+ if (audio && !isInsidePrompt) return;
243
+ if (!audio) return;
244
+
245
+ var info = _this2._createAudioInfoToast();
246
+
247
+ var container = _this2.querySelector('#main-container');
248
+
249
+ var enableAudio = function enableAudio() {
250
+ if (_this2.querySelector('#play-audio-info')) {
251
+ audio.play();
252
+ container.removeChild(info);
253
+ }
254
+
255
+ document.removeEventListener('click', enableAudio);
256
+ }; // if the audio is paused, it means the user has not interacted with the page yet and the audio will not play
257
+ // FIX FOR SAFARI: play with a slight delay to check if autoplay was blocked
258
+
259
+
260
+ setTimeout(function () {
261
+ if (audio.paused && !_this2.querySelector('#play-audio-info')) {
262
+ // add info message as a toast to enable audio playback
263
+ container.appendChild(info);
264
+ document.addEventListener('click', enableAudio);
265
+ } else {
266
+ document.removeEventListener('click', enableAudio);
267
+ }
268
+ }, 500); // we need to listen for the playing event to remove the toast in case the audio plays because of re-rendering
269
+
270
+ var handlePlaying = function handlePlaying() {
271
+ (0, _sessionUpdater.updateSessionMetadata)(_this2._session, {
272
+ audioStartTime: new Date().getTime()
273
+ });
274
+
275
+ var info = _this2.querySelector('#play-audio-info');
276
+
277
+ if (info) {
278
+ container.removeChild(info);
279
+ }
280
+
281
+ audio.removeEventListener('playing', handlePlaying);
282
+ };
283
+
284
+ audio.addEventListener('playing', handlePlaying); // we need to listen for the ended event to update the isComplete state
285
+
286
+ var handleEnded = function handleEnded() {
287
+ (0, _sessionUpdater.updateSessionMetadata)(_this2._session, {
288
+ audioEndTime: new Date().getTime()
289
+ });
290
+ _this2.audioComplete = true;
291
+
292
+ _this2._dispatchResponseChanged();
293
+
294
+ audio.removeEventListener('ended', handleEnded);
295
+ };
296
+
297
+ audio.addEventListener('ended', handleEnded); // store references to remove later
298
+
299
+ _this2._audio = audio;
300
+ _this2._handlePlaying = handlePlaying;
301
+ _this2._handleEnded = handleEnded;
302
+ _this2._enableAudio = enableAudio; // set to true to prevent multiple initializations
303
+
304
+ _this2._audioInitialized = true;
305
+ observer.disconnect();
306
+ }
307
+ });
308
+ });
309
+ observer.observe(this, {
310
+ childList: true,
311
+ subtree: true
312
+ });
313
+ }
314
+ }, {
315
+ key: "enableKeyboardEvents",
316
+ value: function enableKeyboardEvents() {
317
+ if (!this._keyboardEventsEnabled) {
318
+ window.addEventListener('keydown', this._boundHandleKeyDown);
319
+ this._keyboardEventsEnabled = true;
320
+ }
321
+ }
322
+ }, {
323
+ key: "disconnectedCallback",
324
+ value: function disconnectedCallback() {
325
+ if (this._keyboardEventsEnabled) {
326
+ window.removeEventListener('keydown', this._boundHandleKeyDown);
327
+ this._keyboardEventsEnabled = false;
328
+ }
329
+
330
+ document.removeEventListener('click', this._enableAudio);
331
+
332
+ if (this._audio) {
333
+ this._audio.removeEventListener('playing', this._handlePlaying);
334
+
335
+ this._audio.removeEventListener('ended', this._handleEnded);
336
+
337
+ this._audio = null;
338
+ }
339
+ }
340
+ /**
341
+ * Handles global keyboard events for selecting or toggling multiple-choice answers.
342
+ * Maps keys (1-9, 0, a-j, A-J) to choices and updates the session state accordingly.
343
+ * Ensures valid key presses toggle or select the appropriate choice based on the model.
344
+ */
345
+
346
+ }, {
347
+ key: "handleKeyDown",
348
+ value: function handleKeyDown(event) {
349
+ var _this$_model$choices;
350
+
351
+ if (!this._model || !this._session) {
352
+ return;
353
+ }
354
+
355
+ var mode = this._model.mode;
356
+
357
+ if (mode !== 'gather') {
358
+ return;
359
+ }
360
+
361
+ var keyToIndex = function keyToIndex(key) {
362
+ var numOffset = key >= '1' && key <= '9' ? key - '1' : key === '0' ? 9 : -1;
363
+ var letterOffset = /^[a-jA-J]$/.test(key) ? key.toLowerCase().charCodeAt(0) - 'a'.charCodeAt(0) : -1;
364
+ return numOffset >= 0 ? numOffset : letterOffset;
365
+ };
366
+
367
+ var choiceIndex = keyToIndex(event.key);
368
+
369
+ if (choiceIndex === undefined || choiceIndex <= -1 || choiceIndex >= ((_this$_model$choices = this._model.choices) === null || _this$_model$choices === void 0 ? void 0 : _this$_model$choices.length)) {
370
+ return;
371
+ }
372
+
373
+ var currentValue = this._session.value || [];
374
+ var choiceId = this._model.choices[choiceIndex].value;
375
+ var newValue = {
376
+ value: choiceId,
377
+ selected: !currentValue.includes(choiceId),
378
+ selector: 'Keyboard'
379
+ };
380
+
381
+ this._onChange(newValue);
382
+ }
383
+ }]);
384
+ return MultipleChoice;
385
+ }( /*#__PURE__*/(0, _wrapNativeSuper2["default"])(HTMLElement));
386
+
387
+ exports["default"] = MultipleChoice;
388
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.js"],"names":["log","isComplete","session","model","audioComplete","elementContext","autoplayAudioEnabled","completeAudioEnabled","audio","querySelector","isInsidePrompt","closest","value","choiceMode","minSelections","maxSelections","selections","length","MultipleChoice","_model","_session","_boundHandleKeyDown","handleKeyDown","bind","_keyboardEventsEnabled","_audioInitialized","_rerender","element","React","createElement","Main","onChoiceChanged","_onChange","onShowCorrectToggle","setAttribute","setLangAttribute","ReactDOM","render","keyboardEventsEnabled","enableKeyboardEvents","leading","trailing","_dispatchResponseChanged","dispatchEvent","SessionChangedEvent","tagName","toLowerCase","_dispatchModelSet","ModelSetEvent","undefined","language","lang","slice","s","data","info","document","id","Object","assign","style","position","top","width","height","display","justifyContent","alignItems","background","zIndex","cursor","img","src","EnableAudioAutoplayImage","alt","appendChild","observer","MutationObserver","mutationsList","forEach","mutation","type","_createAudioInfoToast","container","enableAudio","play","removeChild","removeEventListener","setTimeout","paused","addEventListener","handlePlaying","audioStartTime","Date","getTime","handleEnded","audioEndTime","_audio","_handlePlaying","_handleEnded","_enableAudio","disconnect","observe","childList","subtree","window","event","mode","keyToIndex","key","numOffset","letterOffset","test","charCodeAt","choiceIndex","choices","currentValue","choiceId","newValue","selected","includes","selector","HTMLElement"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;AAEA,IAAMA,GAAG,GAAG,uBAAM,wBAAN,CAAZ;;AAEO,IAAMC,UAAU,GAAG,SA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AAe,CAAf,CAA3D,GAA+E,CAAC,CAArG;AACA,eAAOH,SAAS,IAAI,CAAb,GAAiBA,SAAjB,GAA6BC,YAApC;AACD,OAJD;;AAMA,UAAMG,WAAW,GAAGN,UAAU,CAACF,KAAK,CAACG,GAAP,CAA9B;;AAEA,UAAIK,WAAW,KAAKjE,SAAhB,IAA6BiE,WAAW,IAAI,CAAC,CAA7C,IAAkDA,WAAW,6BAAI,KAAK/F,MAAL,CAAYgG,OAAhB,yDAAI,qBAAqBlG,MAAzB,CAAjE,EAAkG;AAChG;AACD;;AAED,UAAMmG,YAAY,GAAG,KAAKhG,QAAL,CAAcR,KAAd,IAAuB,EAA5C;AACA,UAAMyG,QAAQ,GAAG,KAAKlG,MAAL,CAAYgG,OAAZ,CAAoBD,WAApB,EAAiCtG,KAAlD;AAEA,UAAM0G,QAAQ,GAAG;AACf1G,QAAAA,KAAK,EAAEyG,QADQ;AAEfE,QAAAA,QAAQ,EAAE,CAACH,YAAY,CAACI,QAAb,CAAsBH,QAAtB,CAFI;AAGfI,QAAAA,QAAQ,EAAE;AAHK,OAAjB;;AAMA,WAAKzF,SAAL,CAAesF,QAAf;AACD;;;kDA/QyCI,W","sourcesContent":["import Main from './main';\nimport React from 'react';\nimport ReactDOM from 'react-dom';\nimport debounce from 'lodash/debounce';\nimport debug from 'debug';\nimport { ModelSetEvent, SessionChangedEvent } from '@pie-framework/pie-player-events';\nimport { renderMath } from '@pie-lib/pie-toolbox/math-rendering';\nimport { EnableAudioAutoplayImage } from '@pie-lib/pie-toolbox/render-ui';\nimport { updateSessionValue, updateSessionMetadata } from './session-updater';\n\nconst log = debug('pie-ui:multiple-choice');\n\nexport const isComplete = (session, model, audioComplete, elementContext) => {\n const { autoplayAudioEnabled, completeAudioEnabled } = model || {};\n\n // check audio completion if audio settings are enabled and audio actually exists\n if (autoplayAudioEnabled && completeAudioEnabled && !audioComplete) {\n if (elementContext) {\n const audio = elementContext.querySelector('audio');\n const isInsidePrompt = audio && audio.closest('#preview-prompt');\n\n // only require audio completion if audio exists and is inside the prompt\n if (audio && isInsidePrompt) {\n return false;\n }\n }\n }\n\n if (!session || !session.value) {\n return false;\n }\n\n const { choiceMode, minSelections = 1, maxSelections } = model || {};\n const selections = session.value.length || 0;\n\n if (choiceMode === 'radio') {\n return !!selections;\n }\n\n if (selections < minSelections || selections > maxSelections) {\n return false;\n }\n\n return true;\n};\n\nexport default class MultipleChoice extends HTMLElement {\n constructor() {\n super();\n this._model = null;\n this._session = null;\n this.audioComplete = false;\n this._boundHandleKeyDown = this.handleKeyDown.bind(this);\n this._keyboardEventsEnabled = false;\n this._audioInitialized = false;\n\n this._rerender = debounce(\n () => {\n if (this._model && this._session) {\n var element = React.createElement(Main, {\n model: this._model,\n session: this._session,\n onChoiceChanged: this._onChange.bind(this),\n onShowCorrectToggle: this.onShowCorrectToggle.bind(this),\n });\n\n //TODO: aria-label is set in the _rerender because we need to change it when the model.choiceMode is updated. Consider revisiting the placement of the aria-label setting in the _rerender\n this.setAttribute(\n 'aria-label',\n this._model.choiceMode === 'radio' ? 'Multiple Choice Question' : 'Multiple Correct Answer Question',\n );\n this.setAttribute('role', 'region');\n this.setLangAttribute();\n\n ReactDOM.render(element, this, () => {\n log('render complete - render math');\n renderMath(this);\n });\n\n if (this._model.keyboardEventsEnabled === true && !this._keyboardEventsEnabled) {\n this.enableKeyboardEvents();\n }\n } else {\n log('skip');\n }\n },\n 50,\n { leading: false, trailing: true },\n );\n\n this._dispatchResponseChanged = debounce(() => {\n this.dispatchEvent(\n new SessionChangedEvent(\n this.tagName.toLowerCase(),\n isComplete(this._session, this._model, this.audioComplete, this),\n ),\n );\n });\n\n this._dispatchModelSet = debounce(\n () => {\n this.dispatchEvent(\n new ModelSetEvent(\n this.tagName.toLowerCase(),\n isComplete(this._session, this._model, this.audioComplete, this),\n this._model !== undefined,\n ),\n );\n },\n 50,\n { leading: false, trailing: true },\n );\n }\n\n onShowCorrectToggle() {\n renderMath(this);\n }\n\n setLangAttribute() {\n const language = this._model && typeof this._model.language ? this._model.language : '';\n const lang = language ? language.slice(0, 2) : 'en';\n this.setAttribute('lang', lang);\n }\n\n set model(s) {\n this._model = s;\n this._rerender();\n // reset the audioInitialized to false since the model changed, and we might need to reinitialize the audio\n this._audioInitialized = false;\n this._dispatchModelSet();\n }\n\n get session() {\n return this._session;\n }\n\n set session(s) {\n this._session = s;\n this._rerender();\n //TODO: remove this session-changed should only be emit on user change\n this._dispatchResponseChanged();\n }\n\n _onChange(data) {\n updateSessionValue(this._session, this._model.choiceMode, data);\n this._dispatchResponseChanged();\n this._rerender();\n }\n\n _createAudioInfoToast() {\n const info = document.createElement('div');\n info.id = 'play-audio-info';\n\n Object.assign(info.style, {\n position: 'absolute',\n top: 0,\n width: '100%',\n height: '100%',\n display: 'flex',\n justifyContent: 'center',\n alignItems: 'center',\n background: 'white',\n zIndex: '1000',\n cursor: 'pointer',\n });\n\n const img = document.createElement('img');\n img.src = EnableAudioAutoplayImage;\n img.alt = 'Click anywhere to enable audio autoplay';\n img.width = 500;\n img.height = 300;\n\n info.appendChild(img);\n return info;\n }\n\n connectedCallback() {\n this._rerender();\n\n // Observation: audio in Chrome will have the autoplay attribute,\n // while other browsers will not have the autoplay attribute and will need a user interaction to play the audio\n // This workaround fixes the issue of audio being cached and played on any user interaction in Safari and Firefox\n const observer = new MutationObserver((mutationsList, observer) => {\n mutationsList.forEach((mutation) => {\n if (mutation.type === 'childList') {\n if (this._audioInitialized) return;\n\n const audio = this.querySelector('audio');\n const isInsidePrompt = audio && audio.closest('#preview-prompt');\n\n if (!this._model) return;\n if (!this._model.autoplayAudioEnabled) return;\n if (audio && !isInsidePrompt) return;\n if (!audio) return;\n\n const info = this._createAudioInfoToast();\n const container = this.querySelector('#main-container');\n const enableAudio = () => {\n if (this.querySelector('#play-audio-info')) {\n audio.play();\n container.removeChild(info);\n }\n\n document.removeEventListener('click', enableAudio);\n };\n\n // if the audio is paused, it means the user has not interacted with the page yet and the audio will not play\n // FIX FOR SAFARI: play with a slight delay to check if autoplay was blocked\n setTimeout(() => {\n if (audio.paused && !this.querySelector('#play-audio-info')) {\n // add info message as a toast to enable audio playback\n container.appendChild(info);\n document.addEventListener('click', enableAudio);\n } else {\n document.removeEventListener('click', enableAudio);\n }\n }, 500);\n\n // we need to listen for the playing event to remove the toast in case the audio plays because of re-rendering\n const handlePlaying = () => {\n updateSessionMetadata(this._session, { audioStartTime: new Date().getTime() });\n\n const info = this.querySelector('#play-audio-info');\n if (info) {\n container.removeChild(info);\n }\n\n audio.removeEventListener('playing', handlePlaying);\n };\n\n audio.addEventListener('playing', handlePlaying);\n\n // we need to listen for the ended event to update the isComplete state\n const handleEnded = () => {\n updateSessionMetadata(this._session, { audioEndTime: new Date().getTime() });\n this.audioComplete = true;\n this._dispatchResponseChanged();\n audio.removeEventListener('ended', handleEnded);\n };\n\n audio.addEventListener('ended', handleEnded);\n\n // store references to remove later\n this._audio = audio;\n this._handlePlaying = handlePlaying;\n this._handleEnded = handleEnded;\n this._enableAudio = enableAudio;\n // set to true to prevent multiple initializations\n this._audioInitialized = true;\n\n observer.disconnect();\n }\n });\n });\n\n observer.observe(this, { childList: true, subtree: true });\n }\n\n enableKeyboardEvents() {\n if (!this._keyboardEventsEnabled) {\n window.addEventListener('keydown', this._boundHandleKeyDown);\n this._keyboardEventsEnabled = true;\n }\n }\n\n disconnectedCallback() {\n if (this._keyboardEventsEnabled) {\n window.removeEventListener('keydown', this._boundHandleKeyDown);\n this._keyboardEventsEnabled = false;\n }\n\n document.removeEventListener('click', this._enableAudio);\n\n if (this._audio) {\n this._audio.removeEventListener('playing', this._handlePlaying);\n this._audio.removeEventListener('ended', this._handleEnded);\n this._audio = null;\n }\n }\n\n /**\n * Handles global keyboard events for selecting or toggling multiple-choice answers.\n * Maps keys (1-9, 0, a-j, A-J) to choices and updates the session state accordingly.\n * Ensures valid key presses toggle or select the appropriate choice based on the model.\n */\n handleKeyDown(event) {\n if (!this._model || !this._session) {\n return;\n }\n\n const { mode } = this._model;\n if (mode !== 'gather') {\n return;\n }\n\n const keyToIndex = (key) => {\n const numOffset = key >= '1' && key <= '9' ? key - '1' : key === '0' ? 9 : -1;\n const letterOffset = /^[a-jA-J]$/.test(key) ? key.toLowerCase().charCodeAt(0) - 'a'.charCodeAt(0) : -1;\n return numOffset >= 0 ? numOffset : letterOffset;\n };\n\n const choiceIndex = keyToIndex(event.key);\n\n if (choiceIndex === undefined || choiceIndex <= -1 || choiceIndex >= this._model.choices?.length) {\n return;\n }\n\n const currentValue = this._session.value || [];\n const choiceId = this._model.choices[choiceIndex].value;\n\n const newValue = {\n value: choiceId,\n selected: !currentValue.includes(choiceId),\n selector: 'Keyboard',\n };\n\n this._onChange(newValue);\n }\n}\n"],"file":"index.js"}
@@ -0,0 +1,108 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports["default"] = void 0;
9
+
10
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
11
+
12
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
13
+
14
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
15
+
16
+ var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
17
+
18
+ var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
19
+
20
+ var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
21
+
22
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
23
+
24
+ var _react = _interopRequireDefault(require("react"));
25
+
26
+ var _propTypes = _interopRequireDefault(require("prop-types"));
27
+
28
+ var _styles = require("@material-ui/core/styles");
29
+
30
+ var _renderUi = require("@pie-lib/pie-toolbox/render-ui");
31
+
32
+ var _multipleChoice = _interopRequireDefault(require("./multiple-choice"));
33
+
34
+ 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
+
36
+ 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
+
38
+ var styles = function styles() {
39
+ return {};
40
+ };
41
+
42
+ var Main = /*#__PURE__*/function (_React$Component) {
43
+ (0, _inherits2["default"])(Main, _React$Component);
44
+
45
+ var _super = _createSuper(Main);
46
+
47
+ function Main(props) {
48
+ (0, _classCallCheck2["default"])(this, Main);
49
+ return _super.call(this, props);
50
+ }
51
+
52
+ (0, _createClass2["default"])(Main, [{
53
+ key: "render",
54
+ value: function render() {
55
+ var _this$props = this.props,
56
+ model = _this$props.model,
57
+ onChoiceChanged = _this$props.onChoiceChanged,
58
+ session = _this$props.session,
59
+ onShowCorrectToggle = _this$props.onShowCorrectToggle;
60
+ var extraCSSRules = model.extraCSSRules,
61
+ fontSizeFactor = model.fontSizeFactor; // model.partLabel is a property used for ebsr
62
+
63
+ return /*#__PURE__*/_react["default"].createElement(_renderUi.PreviewLayout, {
64
+ extraCSSRules: extraCSSRules,
65
+ fontSizeFactor: fontSizeFactor
66
+ }, /*#__PURE__*/_react["default"].createElement(_multipleChoice["default"], (0, _extends2["default"])({}, model, {
67
+ session: session,
68
+ onChoiceChanged: onChoiceChanged,
69
+ onShowCorrectToggle: onShowCorrectToggle
70
+ })));
71
+ }
72
+ }]);
73
+ return Main;
74
+ }(_react["default"].Component);
75
+
76
+ (0, _defineProperty2["default"])(Main, "propTypes", {
77
+ model: _propTypes["default"].object,
78
+ session: _propTypes["default"].object,
79
+ onChoiceChanged: _propTypes["default"].func,
80
+ classes: _propTypes["default"].object.isRequired,
81
+ onShowCorrectToggle: _propTypes["default"].func,
82
+ extraCSSRules: _propTypes["default"].shape({
83
+ names: _propTypes["default"].arrayOf(_propTypes["default"].string),
84
+ rules: _propTypes["default"].string
85
+ })
86
+ });
87
+ (0, _defineProperty2["default"])(Main, "defaultProps", {
88
+ model: {},
89
+ session: {}
90
+ });
91
+ var Styled = (0, _styles.withStyles)(styles, {
92
+ name: 'Main'
93
+ })(Main);
94
+ var theme = (0, _styles.createMuiTheme)({
95
+ typography: {
96
+ useNextVariants: true
97
+ }
98
+ });
99
+
100
+ var Root = function Root(props) {
101
+ return /*#__PURE__*/_react["default"].createElement(_styles.MuiThemeProvider, {
102
+ theme: theme
103
+ }, /*#__PURE__*/_react["default"].createElement(Styled, props));
104
+ };
105
+
106
+ var _default = Root;
107
+ exports["default"] = _default;
108
+ //# sourceMappingURL=main.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/main.jsx"],"names":["styles","Main","props","model","onChoiceChanged","session","onShowCorrectToggle","extraCSSRules","fontSizeFactor","React","Component","PropTypes","object","func","classes","isRequired","shape","names","arrayOf","string","rules","Styled","name","theme","typography","useNextVariants","Root"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AAEA;;AACA;;;;;;AAEA,IAAMA,MAAM,GAAG,SAATA,MAAS;AAAA,SAAO,EAAP;AAAA,CAAf;;IAEMC,I;;;;;AAiBJ,gBAAYC,KAAZ,EAAmB;AAAA;AAAA,6BACXA,KADW;AAElB;;;;WAED,kBAAS;AACP,wBAAiE,KAAKA,KAAtE;AAAA,UAAQC,KAAR,eAAQA,KAAR;AAAA,UAAeC,eAAf,eAAeA,eAAf;AAAA,UAAgCC,OAAhC,eAAgCA,OAAhC;AAAA,UAAyCC,mBAAzC,eAAyCA,mBAAzC;AACA,UAAQC,aAAR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B,KAAZ,CADF,CADW;AAAA,CAAb;;eAMewB,I","sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\nimport { withStyles } from '@material-ui/core/styles';\nimport { createMuiTheme, MuiThemeProvider } from '@material-ui/core/styles';\nimport { PreviewLayout } from '@pie-lib/pie-toolbox/render-ui';\nimport MultipleChoice from './multiple-choice';\n\nconst styles = () => ({});\n\nclass Main extends React.Component {\n static propTypes = {\n model: PropTypes.object,\n session: PropTypes.object,\n onChoiceChanged: PropTypes.func,\n classes: PropTypes.object.isRequired,\n onShowCorrectToggle: PropTypes.func,\n extraCSSRules: PropTypes.shape({\n names: PropTypes.arrayOf(PropTypes.string),\n rules: PropTypes.string,\n }),\n };\n\n static defaultProps = {\n model: {},\n session: {},\n };\n constructor(props) {\n super(props);\n }\n\n render() {\n const { model, onChoiceChanged, session, onShowCorrectToggle } = this.props;\n const { extraCSSRules, fontSizeFactor } = model;\n\n // model.partLabel is a property used for ebsr\n return (\n <PreviewLayout extraCSSRules={extraCSSRules} fontSizeFactor={fontSizeFactor}>\n <MultipleChoice\n {...model}\n session={session}\n onChoiceChanged={onChoiceChanged}\n onShowCorrectToggle={onShowCorrectToggle}\n />\n </PreviewLayout>\n );\n }\n}\n\nconst Styled = withStyles(styles, { name: 'Main' })(Main);\n\nconst theme = createMuiTheme({\n typography: {\n useNextVariants: true,\n },\n});\n\nconst Root = (props) => (\n <MuiThemeProvider theme={theme}>\n <Styled {...props} />\n </MuiThemeProvider>\n);\n\nexport default Root;\n"],"file":"main.js"}