@pie-element/multiple-choice 9.19.2-next.5 → 9.19.2-next.74

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.
@@ -94,11 +94,11 @@ var _root = root$8;
94
94
  var root$7 = _root;
95
95
 
96
96
  /** Built-in value references. */
97
- var Symbol$5 = root$7.Symbol;
97
+ var Symbol$4 = root$7.Symbol;
98
98
 
99
- var _Symbol = Symbol$5;
99
+ var _Symbol = Symbol$4;
100
100
 
101
- var Symbol$4 = _Symbol;
101
+ var Symbol$3 = _Symbol;
102
102
 
103
103
  /** Used for built-in method references. */
104
104
  var objectProto$a = Object.prototype;
@@ -114,7 +114,7 @@ var hasOwnProperty$8 = objectProto$a.hasOwnProperty;
114
114
  var nativeObjectToString$1 = objectProto$a.toString;
115
115
 
116
116
  /** Built-in value references. */
117
- var symToStringTag$1 = Symbol$4 ? Symbol$4.toStringTag : undefined;
117
+ var symToStringTag$1 = Symbol$3 ? Symbol$3.toStringTag : undefined;
118
118
 
119
119
  /**
120
120
  * A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values.
@@ -169,7 +169,7 @@ function objectToString$1(value) {
169
169
 
170
170
  var _objectToString = objectToString$1;
171
171
 
172
- var Symbol$3 = _Symbol,
172
+ var Symbol$2 = _Symbol,
173
173
  getRawTag = _getRawTag,
174
174
  objectToString = _objectToString;
175
175
 
@@ -178,7 +178,7 @@ var nullTag = '[object Null]',
178
178
  undefinedTag = '[object Undefined]';
179
179
 
180
180
  /** Built-in value references. */
181
- var symToStringTag = Symbol$3 ? Symbol$3.toStringTag : undefined;
181
+ var symToStringTag = Symbol$2 ? Symbol$2.toStringTag : undefined;
182
182
 
183
183
  /**
184
184
  * The base implementation of `getTag` without fallbacks for buggy environments.
@@ -442,15 +442,15 @@ var getNative$1 = _getNative,
442
442
  root$1 = _root;
443
443
 
444
444
  /* Built-in method references that are verified to be native. */
445
- var WeakMap$2 = getNative$1(root$1, 'WeakMap');
445
+ var WeakMap$1 = getNative$1(root$1, 'WeakMap');
446
446
 
447
- var _WeakMap = WeakMap$2;
447
+ var _WeakMap = WeakMap$1;
448
448
 
449
449
  var DataView = _DataView,
450
450
  Map$2 = _Map,
451
451
  Promise$1 = _Promise,
452
452
  Set = _Set,
453
- WeakMap$1 = _WeakMap,
453
+ WeakMap = _WeakMap,
454
454
  baseGetTag$3 = _baseGetTag,
455
455
  toSource = _toSource;
456
456
 
@@ -468,7 +468,7 @@ var dataViewCtorString = toSource(DataView),
468
468
  mapCtorString = toSource(Map$2),
469
469
  promiseCtorString = toSource(Promise$1),
470
470
  setCtorString = toSource(Set),
471
- weakMapCtorString = toSource(WeakMap$1);
471
+ weakMapCtorString = toSource(WeakMap);
472
472
 
473
473
  /**
474
474
  * Gets the `toStringTag` of `value`.
@@ -484,7 +484,7 @@ if ((DataView && getTag$2(new DataView(new ArrayBuffer(1))) != dataViewTag$2) ||
484
484
  (Map$2 && getTag$2(new Map$2) != mapTag$3) ||
485
485
  (Promise$1 && getTag$2(Promise$1.resolve()) != promiseTag) ||
486
486
  (Set && getTag$2(new Set) != setTag$3) ||
487
- (WeakMap$1 && getTag$2(new WeakMap$1) != weakMapTag$1)) {
487
+ (WeakMap && getTag$2(new WeakMap) != weakMapTag$1)) {
488
488
  getTag$2 = function(value) {
489
489
  var result = baseGetTag$3(value),
490
490
  Ctor = result == objectTag$2 ? value.constructor : undefined,
@@ -1870,7 +1870,7 @@ function setToArray$1(set) {
1870
1870
 
1871
1871
  var _setToArray = setToArray$1;
1872
1872
 
1873
- var Symbol$2 = _Symbol,
1873
+ var Symbol$1 = _Symbol,
1874
1874
  Uint8Array = _Uint8Array,
1875
1875
  eq = eq_1,
1876
1876
  equalArrays$1 = _equalArrays,
@@ -1896,7 +1896,7 @@ var arrayBufferTag = '[object ArrayBuffer]',
1896
1896
  dataViewTag = '[object DataView]';
1897
1897
 
1898
1898
  /** Used to convert symbols to primitives and strings. */
1899
- var symbolProto$1 = Symbol$2 ? Symbol$2.prototype : undefined,
1899
+ var symbolProto$1 = Symbol$1 ? Symbol$1.prototype : undefined,
1900
1900
  symbolValueOf = symbolProto$1 ? symbolProto$1.valueOf : undefined;
1901
1901
 
1902
1902
  /**
@@ -2536,34 +2536,7 @@ var defaults = {
2536
2536
  keyboardEventsEnabled: false,
2537
2537
  };
2538
2538
 
2539
- var controllerUtils$1 = {};
2540
-
2541
- var controllerUtils = {};
2542
-
2543
- var _typeof = {exports: {}};
2544
-
2545
- (function (module) {
2546
- function _typeof(obj) {
2547
- "@babel/helpers - typeof";
2548
-
2549
- return (module.exports = _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
2550
- return typeof obj;
2551
- } : function (obj) {
2552
- return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
2553
- }, module.exports.__esModule = true, module.exports["default"] = module.exports), _typeof(obj);
2554
- }
2555
-
2556
- module.exports = _typeof, module.exports.__esModule = true, module.exports["default"] = module.exports;
2557
- }(_typeof));
2558
-
2559
- var partialScoring = {};
2560
-
2561
- Object.defineProperty(partialScoring, "__esModule", {
2562
- value: true
2563
- });
2564
- partialScoring.enabled = void 0;
2565
-
2566
- var enabled = function enabled(config, env, defaultValue) {
2539
+ const enabled = (config, env, defaultValue) => {
2567
2540
  // if model.partialScoring = false
2568
2541
  // - if env.partialScoring = false || env.partialScoring = true => use dichotomous scoring
2569
2542
  // else if model.partialScoring = true || undefined
@@ -2583,22 +2556,6 @@ var enabled = function enabled(config, env, defaultValue) {
2583
2556
  return typeof defaultValue === 'boolean' ? defaultValue : true;
2584
2557
  };
2585
2558
 
2586
- partialScoring.enabled = enabled;
2587
-
2588
- var persistence = {};
2589
-
2590
- var interopRequireDefault = {exports: {}};
2591
-
2592
- (function (module) {
2593
- function _interopRequireDefault(obj) {
2594
- return obj && obj.__esModule ? obj : {
2595
- "default": obj
2596
- };
2597
- }
2598
-
2599
- module.exports = _interopRequireDefault, module.exports.__esModule = true, module.exports["default"] = module.exports;
2600
- }(interopRequireDefault));
2601
-
2602
2559
  var baseGetTag = _baseGetTag,
2603
2560
  isObjectLike = isObjectLike_1;
2604
2561
 
@@ -2811,7 +2768,7 @@ function arrayMap$2(array, iteratee) {
2811
2768
 
2812
2769
  var _arrayMap = arrayMap$2;
2813
2770
 
2814
- var Symbol$1 = _Symbol,
2771
+ var Symbol = _Symbol,
2815
2772
  arrayMap$1 = _arrayMap,
2816
2773
  isArray$2 = isArray_1,
2817
2774
  isSymbol$1 = isSymbol_1;
@@ -2820,7 +2777,7 @@ var Symbol$1 = _Symbol,
2820
2777
  var INFINITY$1 = 1 / 0;
2821
2778
 
2822
2779
  /** Used to convert symbols to primitives and strings. */
2823
- var symbolProto = Symbol$1 ? Symbol$1.prototype : undefined,
2780
+ var symbolProto = Symbol ? Symbol.prototype : undefined,
2824
2781
  symbolToString = symbolProto ? symbolProto.toString : undefined;
2825
2782
 
2826
2783
  /**
@@ -3165,86 +3122,54 @@ function shuffle(collection) {
3165
3122
 
3166
3123
  var shuffle_1 = shuffle;
3167
3124
 
3168
- var _interopRequireDefault = interopRequireDefault.exports;
3169
-
3170
- Object.defineProperty(persistence, "__esModule", {
3171
- value: true
3172
- });
3173
- persistence.lockChoices = persistence.getShuffledChoices = persistence.compact = void 0;
3174
-
3175
- var _typeof2 = _interopRequireDefault(_typeof.exports);
3176
-
3177
- var _get = _interopRequireDefault(get_1);
3178
-
3179
- var _shuffle = _interopRequireDefault(shuffle_1);
3180
-
3181
- var _isEmpty = _interopRequireDefault(isEmpty_1);
3182
-
3183
3125
  // eslint-disable-next-line no-console
3184
- var lg = function lg(n) {
3185
- return console[n].bind(console, 'controller-utils:');
3186
- };
3187
-
3188
- var debug = lg('debug');
3189
- var log = lg('log');
3190
- var warn = lg('warn');
3191
- var error = lg('error');
3126
+ const lg = (n) => console[n].bind(console, 'controller-utils:');
3127
+ const debug = lg('debug');
3128
+ const log = lg('log');
3129
+ const warn = lg('warn');
3130
+ const error = lg('error');
3192
3131
 
3193
- var compact = function compact(arr) {
3132
+ const compact = (arr) => {
3194
3133
  if (Array.isArray(arr)) {
3195
- return arr.filter(function (v) {
3196
- return v !== null && v !== undefined;
3197
- });
3134
+ return arr.filter((v) => v !== null && v !== undefined);
3198
3135
  }
3199
-
3200
3136
  return arr;
3201
3137
  };
3202
3138
 
3203
- persistence.compact = compact;
3204
-
3205
- var getShuffledChoices = function getShuffledChoices(choices, session, updateSession, choiceKey) {
3206
- return new Promise(function (resolve) {
3207
- var _session$data;
3208
-
3209
- log('updateSession type: ', (0, _typeof2["default"])(updateSession));
3139
+ const getShuffledChoices = (choices, session, updateSession, choiceKey) =>
3140
+ new Promise((resolve) => {
3141
+ log('updateSession type: ', typeof updateSession);
3210
3142
  log('session: ', session);
3211
- var currentShuffled = compact((session === null || session === void 0 ? void 0 : (_session$data = session.data) === null || _session$data === void 0 ? void 0 : _session$data.shuffledValues) || (session === null || session === void 0 ? void 0 : session.shuffledValues) || []);
3143
+
3144
+ const currentShuffled = compact(session?.data?.shuffledValues || session?.shuffledValues || []);
3212
3145
 
3213
3146
  if (!session) {
3214
3147
  // eslint-disable-next-line quotes
3215
3148
  warn("unable to save shuffled choices because there's no session.");
3216
3149
  resolve(undefined);
3217
- } else if (!(0, _isEmpty["default"])(currentShuffled)) {
3218
- var _session$data2;
3219
-
3220
- debug('use shuffledValues to sort the choices...', (_session$data2 = session.data) === null || _session$data2 === void 0 ? void 0 : _session$data2.shuffledValues);
3221
- resolve(compact(currentShuffled.map(function (v) {
3222
- return choices.find(function (c) {
3223
- return c[choiceKey] === v;
3224
- });
3225
- })));
3150
+ } else if (!isEmpty_1(currentShuffled)) {
3151
+ debug('use shuffledValues to sort the choices...', session.data?.shuffledValues);
3152
+ resolve(compact(currentShuffled.map((v) => choices.find((c) => c[choiceKey] === v))));
3226
3153
  } else {
3227
- var shuffledChoices = (0, _shuffle["default"])(choices);
3154
+ const shuffledChoices = shuffle_1(choices);
3228
3155
 
3229
3156
  if (updateSession && typeof updateSession === 'function') {
3230
3157
  try {
3231
3158
  //Note: session.id refers to the id of the element within a session
3232
- var shuffledValues = compact(shuffledChoices.map(function (c) {
3233
- return c[choiceKey];
3234
- }));
3159
+ const shuffledValues = compact(shuffledChoices.map((c) => c[choiceKey]));
3235
3160
  log('try to save shuffledValues to session...', shuffledValues);
3236
3161
  log('call updateSession... ', session.id, session.element);
3237
-
3238
- if ((0, _isEmpty["default"])(shuffledValues)) {
3239
- error("shuffledValues is an empty array? - refusing to call updateSession: shuffledChoices: ".concat(JSON.stringify(shuffledChoices), ", key: ").concat(choiceKey));
3162
+ if (isEmpty_1(shuffledValues)) {
3163
+ error(
3164
+ `shuffledValues is an empty array? - refusing to call updateSession: shuffledChoices: ${JSON.stringify(
3165
+ shuffledChoices,
3166
+ )}, key: ${choiceKey}`,
3167
+ );
3240
3168
  } else {
3241
- updateSession(session.id, session.element, {
3242
- shuffledValues: shuffledValues
3243
- })["catch"](function (e) {
3244
- return (// eslint-disable-next-line no-console
3245
- console.error('update session failed for: ', session.id, e)
3246
- );
3247
- });
3169
+ updateSession(session.id, session.element, { shuffledValues }).catch((e) =>
3170
+ // eslint-disable-next-line no-console
3171
+ console.error('update session failed for: ', session.id, e),
3172
+ );
3248
3173
  }
3249
3174
  } catch (e) {
3250
3175
  warn('unable to save shuffled order for choices');
@@ -3252,13 +3177,12 @@ var getShuffledChoices = function getShuffledChoices(choices, session, updateSes
3252
3177
  }
3253
3178
  } else {
3254
3179
  warn('unable to save shuffled choices, shuffle will happen every time.');
3255
- } //save this shuffle to the session for later retrieval
3256
-
3257
-
3180
+ }
3181
+ //save this shuffle to the session for later retrieval
3258
3182
  resolve(shuffledChoices);
3259
3183
  }
3260
3184
  });
3261
- };
3185
+
3262
3186
  /**
3263
3187
  * If we return:
3264
3188
  * - true - that means that the order of the choices will be ordinal (as is created in the configure item)
@@ -3269,101 +3193,35 @@ var getShuffledChoices = function getShuffledChoices(choices, session, updateSes
3269
3193
  * @param env - env to check if we should lock order
3270
3194
  * @returns {boolean}
3271
3195
  */
3272
-
3273
-
3274
- persistence.getShuffledChoices = getShuffledChoices;
3275
-
3276
- var lockChoices = function lockChoices(model, session, env) {
3196
+ const lockChoices = (model, session, env) => {
3277
3197
  if (model.lockChoiceOrder) {
3278
3198
  return true;
3279
3199
  }
3280
3200
 
3281
- log('lockChoiceOrder: ', (0, _get["default"])(env, ['@pie-element', 'lockChoiceOrder'], false));
3201
+ log('lockChoiceOrder: ', get_1(env, ['@pie-element', 'lockChoiceOrder'], false));
3282
3202
 
3283
- if ((0, _get["default"])(env, ['@pie-element', 'lockChoiceOrder'], false)) {
3203
+ if (get_1(env, ['@pie-element', 'lockChoiceOrder'], false)) {
3284
3204
  return true;
3285
3205
  }
3286
3206
 
3287
- var role = (0, _get["default"])(env, 'role', 'student');
3207
+ const role = get_1(env, 'role', 'student');
3288
3208
 
3289
3209
  if (role === 'instructor') {
3290
3210
  // TODO: .. in the future the instructor can toggle between ordinal and shuffled here, so keeping this code until then
3291
-
3292
3211
  /*const alreadyShuffled = hasShuffledValues(session);
3293
- if (alreadyShuffled) {
3212
+
3213
+ if (alreadyShuffled) {
3294
3214
  return false;
3295
3215
  }
3296
- return true;*/
3297
- return true;
3298
- } // here it's a student, so don't lock and it will shuffle if needs be
3299
3216
 
3217
+ return true;*/
3218
+ return true;
3219
+ }
3300
3220
 
3221
+ // here it's a student, so don't lock and it will shuffle if needs be
3301
3222
  return false;
3302
3223
  };
3303
3224
 
3304
- persistence.lockChoices = lockChoices;
3305
-
3306
- (function (exports) {
3307
-
3308
- var _typeof$1 = _typeof.exports;
3309
-
3310
- Object.defineProperty(exports, "__esModule", {
3311
- value: true
3312
- });
3313
- Object.defineProperty(exports, "getShuffledChoices", {
3314
- enumerable: true,
3315
- get: function get() {
3316
- return _persistence.getShuffledChoices;
3317
- }
3318
- });
3319
- Object.defineProperty(exports, "lockChoices", {
3320
- enumerable: true,
3321
- get: function get() {
3322
- return _persistence.lockChoices;
3323
- }
3324
- });
3325
- exports.partialScoring = void 0;
3326
-
3327
- var partialScoring$1 = _interopRequireWildcard(partialScoring);
3328
-
3329
- exports.partialScoring = partialScoring$1;
3330
-
3331
- var _persistence = persistence;
3332
-
3333
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
3334
-
3335
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof$1(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
3336
-
3337
- }(controllerUtils));
3338
-
3339
- (function (exports) {
3340
-
3341
- Object.defineProperty(exports, "__esModule", {
3342
- value: true
3343
- });
3344
- Object.defineProperty(exports, "getShuffledChoices", {
3345
- enumerable: true,
3346
- get: function get() {
3347
- return _controllerUtils.getShuffledChoices;
3348
- }
3349
- });
3350
- Object.defineProperty(exports, "lockChoices", {
3351
- enumerable: true,
3352
- get: function get() {
3353
- return _controllerUtils.lockChoices;
3354
- }
3355
- });
3356
- Object.defineProperty(exports, "partialScoring", {
3357
- enumerable: true,
3358
- get: function get() {
3359
- return _controllerUtils.partialScoring;
3360
- }
3361
- });
3362
-
3363
- var _controllerUtils = controllerUtils;
3364
-
3365
- }(controllerUtils$1));
3366
-
3367
3225
  /* eslint-disable no-console */
3368
3226
 
3369
3227
  const prepareChoice = (model, env, defaultFeedback) => (choice) => {
@@ -3429,10 +3287,10 @@ async function model(question, session, env, updateSession) {
3429
3287
 
3430
3288
  let choices = (normalizedQuestion.choices || []).map(prepareChoice(normalizedQuestion, env, defaultFeedback));
3431
3289
 
3432
- const lockChoiceOrder = controllerUtils$1.lockChoices(normalizedQuestion, session, env);
3290
+ const lockChoiceOrder = lockChoices(normalizedQuestion, session, env);
3433
3291
 
3434
3292
  if (!lockChoiceOrder) {
3435
- choices = await controllerUtils$1.getShuffledChoices(choices, session, updateSession, 'value');
3293
+ choices = await getShuffledChoices(choices, session, updateSession, 'value');
3436
3294
  }
3437
3295
 
3438
3296
  const out = {
@@ -3511,7 +3369,7 @@ function outcome(model, session, env) {
3511
3369
  if (!session || isEmpty_1(session)) {
3512
3370
  resolve({ score: 0, empty: true });
3513
3371
  } else {
3514
- const partialScoringEnabled = controllerUtils$1.partialScoring.enabled(model, env) && model.choiceMode !== 'radio';
3372
+ const partialScoringEnabled = enabled(model, env) && model.choiceMode !== 'radio';
3515
3373
  const score = getScore(model, session);
3516
3374
 
3517
3375
  resolve({ score: partialScoringEnabled ? score : score === 1 ? 1 : 0, empty: false });