@pie-element/multiple-choice 9.20.2 → 9.20.3-next.2

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
  /**
@@ -2541,34 +2541,7 @@ var defaults = {
2541
2541
  keyboardEventsEnabled: false,
2542
2542
  };
2543
2543
 
2544
- var controllerUtils$1 = {};
2545
-
2546
- var controllerUtils = {};
2547
-
2548
- var _typeof = {exports: {}};
2549
-
2550
- (function (module) {
2551
- function _typeof(obj) {
2552
- "@babel/helpers - typeof";
2553
-
2554
- return (module.exports = _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
2555
- return typeof obj;
2556
- } : function (obj) {
2557
- return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
2558
- }, module.exports.__esModule = true, module.exports["default"] = module.exports), _typeof(obj);
2559
- }
2560
-
2561
- module.exports = _typeof, module.exports.__esModule = true, module.exports["default"] = module.exports;
2562
- }(_typeof));
2563
-
2564
- var partialScoring = {};
2565
-
2566
- Object.defineProperty(partialScoring, "__esModule", {
2567
- value: true
2568
- });
2569
- partialScoring.enabled = void 0;
2570
-
2571
- var enabled = function enabled(config, env, defaultValue) {
2544
+ const enabled = (config, env, defaultValue) => {
2572
2545
  // if model.partialScoring = false
2573
2546
  // - if env.partialScoring = false || env.partialScoring = true => use dichotomous scoring
2574
2547
  // else if model.partialScoring = true || undefined
@@ -2588,22 +2561,6 @@ var enabled = function enabled(config, env, defaultValue) {
2588
2561
  return typeof defaultValue === 'boolean' ? defaultValue : true;
2589
2562
  };
2590
2563
 
2591
- partialScoring.enabled = enabled;
2592
-
2593
- var persistence = {};
2594
-
2595
- var interopRequireDefault = {exports: {}};
2596
-
2597
- (function (module) {
2598
- function _interopRequireDefault(obj) {
2599
- return obj && obj.__esModule ? obj : {
2600
- "default": obj
2601
- };
2602
- }
2603
-
2604
- module.exports = _interopRequireDefault, module.exports.__esModule = true, module.exports["default"] = module.exports;
2605
- }(interopRequireDefault));
2606
-
2607
2564
  var baseGetTag = _baseGetTag,
2608
2565
  isObjectLike = isObjectLike_1;
2609
2566
 
@@ -2816,7 +2773,7 @@ function arrayMap$2(array, iteratee) {
2816
2773
 
2817
2774
  var _arrayMap = arrayMap$2;
2818
2775
 
2819
- var Symbol$1 = _Symbol,
2776
+ var Symbol = _Symbol,
2820
2777
  arrayMap$1 = _arrayMap,
2821
2778
  isArray$2 = isArray_1,
2822
2779
  isSymbol$1 = isSymbol_1;
@@ -2825,7 +2782,7 @@ var Symbol$1 = _Symbol,
2825
2782
  var INFINITY$1 = 1 / 0;
2826
2783
 
2827
2784
  /** Used to convert symbols to primitives and strings. */
2828
- var symbolProto = Symbol$1 ? Symbol$1.prototype : undefined,
2785
+ var symbolProto = Symbol ? Symbol.prototype : undefined,
2829
2786
  symbolToString = symbolProto ? symbolProto.toString : undefined;
2830
2787
 
2831
2788
  /**
@@ -3170,86 +3127,54 @@ function shuffle(collection) {
3170
3127
 
3171
3128
  var shuffle_1 = shuffle;
3172
3129
 
3173
- var _interopRequireDefault = interopRequireDefault.exports;
3174
-
3175
- Object.defineProperty(persistence, "__esModule", {
3176
- value: true
3177
- });
3178
- persistence.lockChoices = persistence.getShuffledChoices = persistence.compact = void 0;
3179
-
3180
- var _typeof2 = _interopRequireDefault(_typeof.exports);
3181
-
3182
- var _get = _interopRequireDefault(get_1);
3183
-
3184
- var _shuffle = _interopRequireDefault(shuffle_1);
3185
-
3186
- var _isEmpty = _interopRequireDefault(isEmpty_1);
3187
-
3188
3130
  // eslint-disable-next-line no-console
3189
- var lg = function lg(n) {
3190
- return console[n].bind(console, 'controller-utils:');
3191
- };
3192
-
3193
- var debug = lg('debug');
3194
- var log = lg('log');
3195
- var warn = lg('warn');
3196
- var error = lg('error');
3131
+ const lg = (n) => console[n].bind(console, 'controller-utils:');
3132
+ const debug = lg('debug');
3133
+ const log = lg('log');
3134
+ const warn = lg('warn');
3135
+ const error = lg('error');
3197
3136
 
3198
- var compact = function compact(arr) {
3137
+ const compact = (arr) => {
3199
3138
  if (Array.isArray(arr)) {
3200
- return arr.filter(function (v) {
3201
- return v !== null && v !== undefined;
3202
- });
3139
+ return arr.filter((v) => v !== null && v !== undefined);
3203
3140
  }
3204
-
3205
3141
  return arr;
3206
3142
  };
3207
3143
 
3208
- persistence.compact = compact;
3209
-
3210
- var getShuffledChoices = function getShuffledChoices(choices, session, updateSession, choiceKey) {
3211
- return new Promise(function (resolve) {
3212
- var _session$data;
3213
-
3214
- log('updateSession type: ', (0, _typeof2["default"])(updateSession));
3144
+ const getShuffledChoices = (choices, session, updateSession, choiceKey) =>
3145
+ new Promise((resolve) => {
3146
+ log('updateSession type: ', typeof updateSession);
3215
3147
  log('session: ', session);
3216
- 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) || []);
3148
+
3149
+ const currentShuffled = compact(session?.data?.shuffledValues || session?.shuffledValues || []);
3217
3150
 
3218
3151
  if (!session) {
3219
3152
  // eslint-disable-next-line quotes
3220
3153
  warn("unable to save shuffled choices because there's no session.");
3221
3154
  resolve(undefined);
3222
- } else if (!(0, _isEmpty["default"])(currentShuffled)) {
3223
- var _session$data2;
3224
-
3225
- debug('use shuffledValues to sort the choices...', (_session$data2 = session.data) === null || _session$data2 === void 0 ? void 0 : _session$data2.shuffledValues);
3226
- resolve(compact(currentShuffled.map(function (v) {
3227
- return choices.find(function (c) {
3228
- return c[choiceKey] === v;
3229
- });
3230
- })));
3155
+ } else if (!isEmpty_1(currentShuffled)) {
3156
+ debug('use shuffledValues to sort the choices...', session.data?.shuffledValues);
3157
+ resolve(compact(currentShuffled.map((v) => choices.find((c) => c[choiceKey] === v))));
3231
3158
  } else {
3232
- var shuffledChoices = (0, _shuffle["default"])(choices);
3159
+ const shuffledChoices = shuffle_1(choices);
3233
3160
 
3234
3161
  if (updateSession && typeof updateSession === 'function') {
3235
3162
  try {
3236
3163
  //Note: session.id refers to the id of the element within a session
3237
- var shuffledValues = compact(shuffledChoices.map(function (c) {
3238
- return c[choiceKey];
3239
- }));
3164
+ const shuffledValues = compact(shuffledChoices.map((c) => c[choiceKey]));
3240
3165
  log('try to save shuffledValues to session...', shuffledValues);
3241
3166
  log('call updateSession... ', session.id, session.element);
3242
-
3243
- if ((0, _isEmpty["default"])(shuffledValues)) {
3244
- error("shuffledValues is an empty array? - refusing to call updateSession: shuffledChoices: ".concat(JSON.stringify(shuffledChoices), ", key: ").concat(choiceKey));
3167
+ if (isEmpty_1(shuffledValues)) {
3168
+ error(
3169
+ `shuffledValues is an empty array? - refusing to call updateSession: shuffledChoices: ${JSON.stringify(
3170
+ shuffledChoices,
3171
+ )}, key: ${choiceKey}`,
3172
+ );
3245
3173
  } else {
3246
- updateSession(session.id, session.element, {
3247
- shuffledValues: shuffledValues
3248
- })["catch"](function (e) {
3249
- return (// eslint-disable-next-line no-console
3250
- console.error('update session failed for: ', session.id, e)
3251
- );
3252
- });
3174
+ updateSession(session.id, session.element, { shuffledValues }).catch((e) =>
3175
+ // eslint-disable-next-line no-console
3176
+ console.error('update session failed for: ', session.id, e),
3177
+ );
3253
3178
  }
3254
3179
  } catch (e) {
3255
3180
  warn('unable to save shuffled order for choices');
@@ -3257,13 +3182,12 @@ var getShuffledChoices = function getShuffledChoices(choices, session, updateSes
3257
3182
  }
3258
3183
  } else {
3259
3184
  warn('unable to save shuffled choices, shuffle will happen every time.');
3260
- } //save this shuffle to the session for later retrieval
3261
-
3262
-
3185
+ }
3186
+ //save this shuffle to the session for later retrieval
3263
3187
  resolve(shuffledChoices);
3264
3188
  }
3265
3189
  });
3266
- };
3190
+
3267
3191
  /**
3268
3192
  * If we return:
3269
3193
  * - true - that means that the order of the choices will be ordinal (as is created in the configure item)
@@ -3274,101 +3198,35 @@ var getShuffledChoices = function getShuffledChoices(choices, session, updateSes
3274
3198
  * @param env - env to check if we should lock order
3275
3199
  * @returns {boolean}
3276
3200
  */
3277
-
3278
-
3279
- persistence.getShuffledChoices = getShuffledChoices;
3280
-
3281
- var lockChoices = function lockChoices(model, session, env) {
3201
+ const lockChoices = (model, session, env) => {
3282
3202
  if (model.lockChoiceOrder) {
3283
3203
  return true;
3284
3204
  }
3285
3205
 
3286
- log('lockChoiceOrder: ', (0, _get["default"])(env, ['@pie-element', 'lockChoiceOrder'], false));
3206
+ log('lockChoiceOrder: ', get_1(env, ['@pie-element', 'lockChoiceOrder'], false));
3287
3207
 
3288
- if ((0, _get["default"])(env, ['@pie-element', 'lockChoiceOrder'], false)) {
3208
+ if (get_1(env, ['@pie-element', 'lockChoiceOrder'], false)) {
3289
3209
  return true;
3290
3210
  }
3291
3211
 
3292
- var role = (0, _get["default"])(env, 'role', 'student');
3212
+ const role = get_1(env, 'role', 'student');
3293
3213
 
3294
3214
  if (role === 'instructor') {
3295
3215
  // TODO: .. in the future the instructor can toggle between ordinal and shuffled here, so keeping this code until then
3296
-
3297
3216
  /*const alreadyShuffled = hasShuffledValues(session);
3298
- if (alreadyShuffled) {
3217
+
3218
+ if (alreadyShuffled) {
3299
3219
  return false;
3300
3220
  }
3301
- return true;*/
3302
- return true;
3303
- } // here it's a student, so don't lock and it will shuffle if needs be
3304
3221
 
3222
+ return true;*/
3223
+ return true;
3224
+ }
3305
3225
 
3226
+ // here it's a student, so don't lock and it will shuffle if needs be
3306
3227
  return false;
3307
3228
  };
3308
3229
 
3309
- persistence.lockChoices = lockChoices;
3310
-
3311
- (function (exports) {
3312
-
3313
- var _typeof$1 = _typeof.exports;
3314
-
3315
- Object.defineProperty(exports, "__esModule", {
3316
- value: true
3317
- });
3318
- Object.defineProperty(exports, "getShuffledChoices", {
3319
- enumerable: true,
3320
- get: function get() {
3321
- return _persistence.getShuffledChoices;
3322
- }
3323
- });
3324
- Object.defineProperty(exports, "lockChoices", {
3325
- enumerable: true,
3326
- get: function get() {
3327
- return _persistence.lockChoices;
3328
- }
3329
- });
3330
- exports.partialScoring = void 0;
3331
-
3332
- var partialScoring$1 = _interopRequireWildcard(partialScoring);
3333
-
3334
- exports.partialScoring = partialScoring$1;
3335
-
3336
- var _persistence = persistence;
3337
-
3338
- 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); }
3339
-
3340
- 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; }
3341
-
3342
- }(controllerUtils));
3343
-
3344
- (function (exports) {
3345
-
3346
- Object.defineProperty(exports, "__esModule", {
3347
- value: true
3348
- });
3349
- Object.defineProperty(exports, "getShuffledChoices", {
3350
- enumerable: true,
3351
- get: function get() {
3352
- return _controllerUtils.getShuffledChoices;
3353
- }
3354
- });
3355
- Object.defineProperty(exports, "lockChoices", {
3356
- enumerable: true,
3357
- get: function get() {
3358
- return _controllerUtils.lockChoices;
3359
- }
3360
- });
3361
- Object.defineProperty(exports, "partialScoring", {
3362
- enumerable: true,
3363
- get: function get() {
3364
- return _controllerUtils.partialScoring;
3365
- }
3366
- });
3367
-
3368
- var _controllerUtils = controllerUtils;
3369
-
3370
- }(controllerUtils$1));
3371
-
3372
3230
  /* eslint-disable no-console */
3373
3231
 
3374
3232
  const prepareChoice = (model, env, defaultFeedback) => (choice) => {
@@ -3434,10 +3292,10 @@ async function model(question, session, env, updateSession) {
3434
3292
 
3435
3293
  let choices = (normalizedQuestion.choices || []).map(prepareChoice(normalizedQuestion, env, defaultFeedback));
3436
3294
 
3437
- const lockChoiceOrder = controllerUtils$1.lockChoices(normalizedQuestion, session, env);
3295
+ const lockChoiceOrder = lockChoices(normalizedQuestion, session, env);
3438
3296
 
3439
3297
  if (!lockChoiceOrder) {
3440
- choices = await controllerUtils$1.getShuffledChoices(choices, session, updateSession, 'value');
3298
+ choices = await getShuffledChoices(choices, session, updateSession, 'value');
3441
3299
  }
3442
3300
 
3443
3301
  const out = {
@@ -3521,7 +3379,7 @@ function outcome(model, session, env) {
3521
3379
  if (!session || isEmpty_1(session)) {
3522
3380
  resolve({ score: 0, empty: true });
3523
3381
  } else {
3524
- const partialScoringEnabled = controllerUtils$1.partialScoring.enabled(model, env) && model.choiceMode !== 'radio';
3382
+ const partialScoringEnabled = enabled(model, env) && model.choiceMode !== 'radio';
3525
3383
  const score = getScore(model, session);
3526
3384
 
3527
3385
  resolve({ score: partialScoringEnabled ? score : score === 1 ? 1 : 0, empty: false });