@pie-element/multiple-choice 11.1.0 → 11.2.0-mui-update.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js CHANGED
@@ -1,133 +1,89 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
- exports.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
-
7
+ exports.isComplete = exports.default = void 0;
26
8
  var _main = _interopRequireDefault(require("./main"));
27
-
28
9
  var _react = _interopRequireDefault(require("react"));
29
-
30
- var _reactDom = _interopRequireDefault(require("react-dom"));
31
-
10
+ var _client = require("react-dom/client");
32
11
  var _debounce = _interopRequireDefault(require("lodash/debounce"));
33
-
34
12
  var _debug = _interopRequireDefault(require("debug"));
35
-
36
13
  var _piePlayerEvents = require("@pie-framework/pie-player-events");
37
-
38
14
  var _mathRendering = require("@pie-lib/math-rendering");
39
-
40
15
  var _renderUi = require("@pie-lib/render-ui");
41
-
42
16
  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
-
17
+ const log = (0, _debug.default)('pie-ui:multiple-choice');
18
+ const isComplete = (session, model, audioComplete, elementContext) => {
19
+ const {
20
+ autoplayAudioEnabled,
21
+ completeAudioEnabled
22
+ } = model || {};
23
+
24
+ // check audio completion if audio settings are enabled and audio actually exists
56
25
  if (autoplayAudioEnabled && completeAudioEnabled && !audioComplete) {
57
26
  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
27
+ const audio = elementContext.querySelector('audio');
28
+ const isInsidePrompt = audio && audio.closest('#preview-prompt');
60
29
 
30
+ // only require audio completion if audio exists and is inside the prompt
61
31
  if (audio && isInsidePrompt) {
62
32
  return false;
63
33
  }
64
34
  }
65
35
  }
66
-
67
36
  if (!session || !session.value) {
68
37
  return false;
69
38
  }
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
-
39
+ const {
40
+ choiceMode,
41
+ minSelections = 1,
42
+ maxSelections
43
+ } = model || {};
44
+ const selections = session.value.length || 0;
79
45
  if (choiceMode === 'radio') {
80
46
  return !!selections;
81
47
  }
82
-
83
48
  if (selections < minSelections || selections > maxSelections) {
84
49
  return false;
85
50
  }
86
-
87
51
  return true;
88
52
  };
89
-
90
53
  exports.isComplete = isComplete;
54
+ class MultipleChoice extends HTMLElement {
55
+ constructor() {
56
+ super();
57
+ this._model = null;
58
+ this._session = null;
59
+ this.audioComplete = false;
60
+ this._boundHandleKeyDown = this.handleKeyDown.bind(this);
61
+ this._keyboardEventsEnabled = false;
62
+ this._audioInitialized = false;
63
+ this._root = null;
64
+ this._rerender = (0, _debounce.default)(() => {
65
+ if (this._model && this._session) {
66
+ var element = /*#__PURE__*/_react.default.createElement(_main.default, {
67
+ model: this._model,
68
+ session: this._session,
69
+ onChoiceChanged: this._onChange.bind(this),
70
+ onShowCorrectToggle: this.onShowCorrectToggle.bind(this)
71
+ });
91
72
 
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 () {
73
+ //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
74
+ this.setAttribute('aria-label', this._model.choiceMode === 'radio' ? 'Multiple Choice Question' : 'Multiple Correct Answer Question');
75
+ this.setAttribute('role', 'region');
76
+ this.setLangAttribute();
77
+ if (!this._root) {
78
+ this._root = (0, _client.createRoot)(this);
79
+ }
80
+ this._root.render(element);
81
+ queueMicrotask(() => {
125
82
  log('render complete - render math');
126
- (0, _mathRendering.renderMath)((0, _assertThisInitialized2["default"])(_this));
83
+ (0, _mathRendering.renderMath)(this);
127
84
  });
128
-
129
- if (_this._model.keyboardEventsEnabled === true && !_this._keyboardEventsEnabled) {
130
- _this.enableKeyboardEvents();
85
+ if (this._model.keyboardEventsEnabled === true && !this._keyboardEventsEnabled) {
86
+ this.enableKeyboardEvents();
131
87
  }
132
88
  } else {
133
89
  log('skip');
@@ -136,253 +92,201 @@ var MultipleChoice = /*#__PURE__*/function (_HTMLElement) {
136
92
  leading: false,
137
93
  trailing: true
138
94
  });
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))));
95
+ this._dispatchResponseChanged = (0, _debounce.default)(() => {
96
+ this.dispatchEvent(new _piePlayerEvents.SessionChangedEvent(this.tagName.toLowerCase(), isComplete(this._session, this._model, this.audioComplete, this)));
141
97
  });
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));
98
+ this._dispatchModelSet = (0, _debounce.default)(() => {
99
+ this.dispatchEvent(new _piePlayerEvents.ModelSetEvent(this.tagName.toLowerCase(), isComplete(this._session, this._model, this.audioComplete, this), this._model !== undefined));
144
100
  }, 50, {
145
101
  leading: false,
146
102
  trailing: true
147
103
  });
148
- return _this;
149
104
  }
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();
105
+ onShowCorrectToggle() {
106
+ (0, _mathRendering.renderMath)(this);
107
+ }
108
+ setLangAttribute() {
109
+ const language = this._model && typeof this._model.language ? this._model.language : '';
110
+ const lang = language ? language.slice(0, 2) : 'en';
111
+ this.setAttribute('lang', lang);
112
+ }
113
+ set model(s) {
114
+ this._model = s;
115
+ this._rerender();
116
+ // reset the audioInitialized to false since the model changed, and we might need to reinitialize the audio
117
+ this._audioInitialized = false;
118
+ this._dispatchModelSet();
119
+ }
120
+ get session() {
121
+ return this._session;
122
+ }
123
+ set session(s) {
124
+ this._session = s;
125
+ this._rerender();
126
+ //TODO: remove this session-changed should only be emit on user change
127
+ this._dispatchResponseChanged();
128
+ }
129
+ _onChange(data) {
130
+ (0, _sessionUpdater.updateSessionValue)(this._session, this._model.choiceMode, data);
131
+ this._dispatchResponseChanged();
132
+ this._rerender();
133
+ }
134
+ _createAudioInfoToast() {
135
+ const info = document.createElement('div');
136
+ info.id = 'play-audio-info';
137
+ Object.assign(info.style, {
138
+ position: 'absolute',
139
+ top: 0,
140
+ width: '100%',
141
+ height: '100%',
142
+ display: 'flex',
143
+ justifyContent: 'center',
144
+ alignItems: 'center',
145
+ background: 'white',
146
+ zIndex: '1000',
147
+ cursor: 'pointer'
148
+ });
149
+ const img = document.createElement('img');
150
+ img.src = _renderUi.EnableAudioAutoplayImage;
151
+ img.alt = 'Click anywhere to enable audio autoplay';
152
+ img.width = 500;
153
+ img.height = 300;
154
+ info.appendChild(img);
155
+ return info;
156
+ }
157
+ connectedCallback() {
158
+ this._rerender();
159
+
160
+ // Observation: audio in Chrome will have the autoplay attribute,
161
+ // while other browsers will not have the autoplay attribute and will need a user interaction to play the audio
162
+ // This workaround fixes the issue of audio being cached and played on any user interaction in Safari and Firefox
163
+ const observer = new MutationObserver((mutationsList, observer) => {
164
+ mutationsList.forEach(mutation => {
165
+ if (mutation.type === 'childList') {
166
+ if (this._audioInitialized) return;
167
+ const audio = this.querySelector('audio');
168
+ const isInsidePrompt = audio && audio.closest('#preview-prompt');
169
+ if (!this._model) return;
170
+ if (!this._model.autoplayAudioEnabled) return;
171
+ if (audio && !isInsidePrompt) return;
172
+ if (!audio) return;
173
+ const info = this._createAudioInfoToast();
174
+ const container = this.querySelector('#main-container');
175
+ const enableAudio = () => {
176
+ if (this.querySelector('#play-audio-info')) {
177
+ audio.play();
178
+ container.removeChild(info);
179
+ }
180
+ document.removeEventListener('click', enableAudio);
181
+ };
182
+
183
+ // if the audio is paused, it means the user has not interacted with the page yet and the audio will not play
184
+ // FIX FOR SAFARI: play with a slight delay to check if autoplay was blocked
185
+ setTimeout(() => {
186
+ if (audio.paused && !this.querySelector('#play-audio-info')) {
187
+ // add info message as a toast to enable audio playback
188
+ container.appendChild(info);
189
+ document.addEventListener('click', enableAudio);
190
+ } else {
191
+ document.removeEventListener('click', enableAudio);
192
+ }
193
+ }, 500);
194
+
195
+ // we need to listen for the playing event to remove the toast in case the audio plays because of re-rendering
196
+ const handlePlaying = () => {
197
+ (0, _sessionUpdater.updateSessionMetadata)(this._session, {
198
+ audioStartTime: new Date().getTime()
199
+ });
200
+ const info = this.querySelector('#play-audio-info');
201
+ if (info) {
202
+ container.removeChild(info);
203
+ }
204
+ audio.removeEventListener('playing', handlePlaying);
205
+ };
206
+ audio.addEventListener('playing', handlePlaying);
207
+
208
+ // we need to listen for the ended event to update the isComplete state
209
+ const handleEnded = () => {
210
+ (0, _sessionUpdater.updateSessionMetadata)(this._session, {
211
+ audioEndTime: new Date().getTime()
212
+ });
213
+ this.audioComplete = true;
214
+ this._dispatchResponseChanged();
215
+ audio.removeEventListener('ended', handleEnded);
216
+ };
217
+ audio.addEventListener('ended', handleEnded);
218
+
219
+ // store references to remove later
220
+ this._audio = audio;
221
+ this._handlePlaying = handlePlaying;
222
+ this._handleEnded = handleEnded;
223
+ this._enableAudio = enableAudio;
224
+ // set to true to prevent multiple initializations
225
+ this._audioInitialized = true;
226
+ observer.disconnect();
227
+ }
228
+ });
229
+ });
230
+ observer.observe(this, {
231
+ childList: true,
232
+ subtree: true
233
+ });
234
+ }
235
+ enableKeyboardEvents() {
236
+ if (!this._keyboardEventsEnabled) {
237
+ window.addEventListener('keydown', this._boundHandleKeyDown);
238
+ this._keyboardEventsEnabled = true;
174
239
  }
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();
240
+ }
241
+ disconnectedCallback() {
242
+ if (this._keyboardEventsEnabled) {
243
+ window.removeEventListener('keydown', this._boundHandleKeyDown);
244
+ this._keyboardEventsEnabled = false;
187
245
  }
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();
246
+ document.removeEventListener('click', this._enableAudio);
247
+ if (this._audio) {
248
+ this._audio.removeEventListener('playing', this._handlePlaying);
249
+ this._audio.removeEventListener('ended', this._handleEnded);
250
+ this._audio = null;
196
251
  }
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;
252
+ if (this._root) {
253
+ this._root.unmount();
221
254
  }
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
255
+ }
303
256
 
304
- _this2._audioInitialized = true;
305
- observer.disconnect();
306
- }
307
- });
308
- });
309
- observer.observe(this, {
310
- childList: true,
311
- subtree: true
312
- });
257
+ /**
258
+ * Handles global keyboard events for selecting or toggling multiple-choice answers.
259
+ * Maps keys (1-9, 0, a-j, A-J) to choices and updates the session state accordingly.
260
+ * Ensures valid key presses toggle or select the appropriate choice based on the model.
261
+ */
262
+ handleKeyDown(event) {
263
+ if (!this._model || !this._session) {
264
+ return;
313
265
  }
314
- }, {
315
- key: "enableKeyboardEvents",
316
- value: function enableKeyboardEvents() {
317
- if (!this._keyboardEventsEnabled) {
318
- window.addEventListener('keydown', this._boundHandleKeyDown);
319
- this._keyboardEventsEnabled = true;
320
- }
266
+ const {
267
+ mode
268
+ } = this._model;
269
+ if (mode !== 'gather') {
270
+ return;
321
271
  }
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
- }
272
+ const keyToIndex = key => {
273
+ const numOffset = key >= '1' && key <= '9' ? key - '1' : key === '0' ? 9 : -1;
274
+ const letterOffset = /^[a-jA-J]$/.test(key) ? key.toLowerCase().charCodeAt(0) - 'a'.charCodeAt(0) : -1;
275
+ return numOffset >= 0 ? numOffset : letterOffset;
276
+ };
277
+ const choiceIndex = keyToIndex(event.key);
278
+ if (choiceIndex === undefined || choiceIndex <= -1 || choiceIndex >= this._model.choices?.length) {
279
+ return;
339
280
  }
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;
281
+ const currentValue = this._session.value || [];
282
+ const choiceId = this._model.choices[choiceIndex].value;
283
+ const newValue = {
284
+ value: choiceId,
285
+ selected: !currentValue.includes(choiceId),
286
+ selector: 'Keyboard'
287
+ };
288
+ this._onChange(newValue);
289
+ }
290
+ }
291
+ exports.default = MultipleChoice;
388
292
  //# sourceMappingURL=index.js.map