@pie-element/multiple-choice 9.20.2-next.5 → 9.20.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$4 = root$7.Symbol;
97
+ var Symbol$5 = root$7.Symbol;
98
98
 
99
- var _Symbol = Symbol$4;
99
+ var _Symbol = Symbol$5;
100
100
 
101
- var Symbol$3 = _Symbol;
101
+ var Symbol$4 = _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$3 ? Symbol$3.toStringTag : undefined;
117
+ var symToStringTag$1 = Symbol$4 ? Symbol$4.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$2 = _Symbol,
172
+ var Symbol$3 = _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$2 ? Symbol$2.toStringTag : undefined;
181
+ var symToStringTag = Symbol$3 ? Symbol$3.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$1 = getNative$1(root$1, 'WeakMap');
445
+ var WeakMap$2 = getNative$1(root$1, 'WeakMap');
446
446
 
447
- var _WeakMap = WeakMap$1;
447
+ var _WeakMap = WeakMap$2;
448
448
 
449
449
  var DataView = _DataView,
450
450
  Map$2 = _Map,
451
451
  Promise$1 = _Promise,
452
452
  Set = _Set,
453
- WeakMap = _WeakMap,
453
+ WeakMap$1 = _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);
471
+ weakMapCtorString = toSource(WeakMap$1);
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 && getTag$2(new WeakMap) != weakMapTag$1)) {
487
+ (WeakMap$1 && getTag$2(new WeakMap$1) != 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$1 = _Symbol,
1873
+ var Symbol$2 = _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$1 ? Symbol$1.prototype : undefined,
1899
+ var symbolProto$1 = Symbol$2 ? Symbol$2.prototype : undefined,
1900
1900
  symbolValueOf = symbolProto$1 ? symbolProto$1.valueOf : undefined;
1901
1901
 
1902
1902
  /**
@@ -2541,7 +2541,34 @@ var defaults = {
2541
2541
  keyboardEventsEnabled: false,
2542
2542
  };
2543
2543
 
2544
- const enabled = (config, env, defaultValue) => {
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) {
2545
2572
  // if model.partialScoring = false
2546
2573
  // - if env.partialScoring = false || env.partialScoring = true => use dichotomous scoring
2547
2574
  // else if model.partialScoring = true || undefined
@@ -2561,6 +2588,22 @@ const enabled = (config, env, defaultValue) => {
2561
2588
  return typeof defaultValue === 'boolean' ? defaultValue : true;
2562
2589
  };
2563
2590
 
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
+
2564
2607
  var baseGetTag = _baseGetTag,
2565
2608
  isObjectLike = isObjectLike_1;
2566
2609
 
@@ -2773,7 +2816,7 @@ function arrayMap$2(array, iteratee) {
2773
2816
 
2774
2817
  var _arrayMap = arrayMap$2;
2775
2818
 
2776
- var Symbol = _Symbol,
2819
+ var Symbol$1 = _Symbol,
2777
2820
  arrayMap$1 = _arrayMap,
2778
2821
  isArray$2 = isArray_1,
2779
2822
  isSymbol$1 = isSymbol_1;
@@ -2782,7 +2825,7 @@ var Symbol = _Symbol,
2782
2825
  var INFINITY$1 = 1 / 0;
2783
2826
 
2784
2827
  /** Used to convert symbols to primitives and strings. */
2785
- var symbolProto = Symbol ? Symbol.prototype : undefined,
2828
+ var symbolProto = Symbol$1 ? Symbol$1.prototype : undefined,
2786
2829
  symbolToString = symbolProto ? symbolProto.toString : undefined;
2787
2830
 
2788
2831
  /**
@@ -3127,54 +3170,86 @@ function shuffle(collection) {
3127
3170
 
3128
3171
  var shuffle_1 = shuffle;
3129
3172
 
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
+
3130
3188
  // eslint-disable-next-line no-console
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');
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');
3136
3197
 
3137
- const compact = (arr) => {
3198
+ var compact = function compact(arr) {
3138
3199
  if (Array.isArray(arr)) {
3139
- return arr.filter((v) => v !== null && v !== undefined);
3200
+ return arr.filter(function (v) {
3201
+ return v !== null && v !== undefined;
3202
+ });
3140
3203
  }
3204
+
3141
3205
  return arr;
3142
3206
  };
3143
3207
 
3144
- const getShuffledChoices = (choices, session, updateSession, choiceKey) =>
3145
- new Promise((resolve) => {
3146
- log('updateSession type: ', typeof updateSession);
3147
- log('session: ', session);
3208
+ persistence.compact = compact;
3148
3209
 
3149
- const currentShuffled = compact(session?.data?.shuffledValues || session?.shuffledValues || []);
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));
3215
+ 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) || []);
3150
3217
 
3151
3218
  if (!session) {
3152
3219
  // eslint-disable-next-line quotes
3153
3220
  warn("unable to save shuffled choices because there's no session.");
3154
3221
  resolve(undefined);
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))));
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
+ })));
3158
3231
  } else {
3159
- const shuffledChoices = shuffle_1(choices);
3232
+ var shuffledChoices = (0, _shuffle["default"])(choices);
3160
3233
 
3161
3234
  if (updateSession && typeof updateSession === 'function') {
3162
3235
  try {
3163
3236
  //Note: session.id refers to the id of the element within a session
3164
- const shuffledValues = compact(shuffledChoices.map((c) => c[choiceKey]));
3237
+ var shuffledValues = compact(shuffledChoices.map(function (c) {
3238
+ return c[choiceKey];
3239
+ }));
3165
3240
  log('try to save shuffledValues to session...', shuffledValues);
3166
3241
  log('call updateSession... ', session.id, session.element);
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
- );
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));
3173
3245
  } else {
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
- );
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
+ });
3178
3253
  }
3179
3254
  } catch (e) {
3180
3255
  warn('unable to save shuffled order for choices');
@@ -3182,12 +3257,13 @@ const getShuffledChoices = (choices, session, updateSession, choiceKey) =>
3182
3257
  }
3183
3258
  } else {
3184
3259
  warn('unable to save shuffled choices, shuffle will happen every time.');
3185
- }
3186
- //save this shuffle to the session for later retrieval
3260
+ } //save this shuffle to the session for later retrieval
3261
+
3262
+
3187
3263
  resolve(shuffledChoices);
3188
3264
  }
3189
3265
  });
3190
-
3266
+ };
3191
3267
  /**
3192
3268
  * If we return:
3193
3269
  * - true - that means that the order of the choices will be ordinal (as is created in the configure item)
@@ -3198,35 +3274,101 @@ const getShuffledChoices = (choices, session, updateSession, choiceKey) =>
3198
3274
  * @param env - env to check if we should lock order
3199
3275
  * @returns {boolean}
3200
3276
  */
3201
- const lockChoices = (model, session, env) => {
3277
+
3278
+
3279
+ persistence.getShuffledChoices = getShuffledChoices;
3280
+
3281
+ var lockChoices = function lockChoices(model, session, env) {
3202
3282
  if (model.lockChoiceOrder) {
3203
3283
  return true;
3204
3284
  }
3205
3285
 
3206
- log('lockChoiceOrder: ', get_1(env, ['@pie-element', 'lockChoiceOrder'], false));
3286
+ log('lockChoiceOrder: ', (0, _get["default"])(env, ['@pie-element', 'lockChoiceOrder'], false));
3207
3287
 
3208
- if (get_1(env, ['@pie-element', 'lockChoiceOrder'], false)) {
3288
+ if ((0, _get["default"])(env, ['@pie-element', 'lockChoiceOrder'], false)) {
3209
3289
  return true;
3210
3290
  }
3211
3291
 
3212
- const role = get_1(env, 'role', 'student');
3292
+ var role = (0, _get["default"])(env, 'role', 'student');
3213
3293
 
3214
3294
  if (role === 'instructor') {
3215
3295
  // TODO: .. in the future the instructor can toggle between ordinal and shuffled here, so keeping this code until then
3216
- /*const alreadyShuffled = hasShuffledValues(session);
3217
3296
 
3218
- if (alreadyShuffled) {
3297
+ /*const alreadyShuffled = hasShuffledValues(session);
3298
+ if (alreadyShuffled) {
3219
3299
  return false;
3220
3300
  }
3221
-
3222
- return true;*/
3301
+ return true;*/
3223
3302
  return true;
3224
- }
3303
+ } // here it's a student, so don't lock and it will shuffle if needs be
3304
+
3225
3305
 
3226
- // here it's a student, so don't lock and it will shuffle if needs be
3227
3306
  return false;
3228
3307
  };
3229
3308
 
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
+
3230
3372
  /* eslint-disable no-console */
3231
3373
 
3232
3374
  const prepareChoice = (model, env, defaultFeedback) => (choice) => {
@@ -3292,10 +3434,10 @@ async function model(question, session, env, updateSession) {
3292
3434
 
3293
3435
  let choices = (normalizedQuestion.choices || []).map(prepareChoice(normalizedQuestion, env, defaultFeedback));
3294
3436
 
3295
- const lockChoiceOrder = lockChoices(normalizedQuestion, session, env);
3437
+ const lockChoiceOrder = controllerUtils$1.lockChoices(normalizedQuestion, session, env);
3296
3438
 
3297
3439
  if (!lockChoiceOrder) {
3298
- choices = await getShuffledChoices(choices, session, updateSession, 'value');
3440
+ choices = await controllerUtils$1.getShuffledChoices(choices, session, updateSession, 'value');
3299
3441
  }
3300
3442
 
3301
3443
  const out = {
@@ -3379,7 +3521,7 @@ function outcome(model, session, env) {
3379
3521
  if (!session || isEmpty_1(session)) {
3380
3522
  resolve({ score: 0, empty: true });
3381
3523
  } else {
3382
- const partialScoringEnabled = enabled(model, env) && model.choiceMode !== 'radio';
3524
+ const partialScoringEnabled = controllerUtils$1.partialScoring.enabled(model, env) && model.choiceMode !== 'radio';
3383
3525
  const score = getScore(model, session);
3384
3526
 
3385
3527
  resolve({ score: partialScoringEnabled ? score : score === 1 ? 1 : 0, empty: false });