@pie-element/multiple-choice 0.1.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/dist/author/defaults.d.ts +206 -0
- package/dist/author/defaults.d.ts.map +1 -0
- package/dist/author/defaults.js +151 -0
- package/dist/author/index.d.ts +27 -0
- package/dist/author/index.d.ts.map +1 -0
- package/dist/author/index.js +116 -0
- package/dist/author/main.d.ts +35 -0
- package/dist/author/main.d.ts.map +1 -0
- package/dist/author/main.js +290 -0
- package/dist/author/utils.d.ts +10 -0
- package/dist/author/utils.d.ts.map +1 -0
- package/dist/author/utils.js +7 -0
- package/dist/controller/defaults.d.ts +36 -0
- package/dist/controller/defaults.d.ts.map +1 -0
- package/dist/controller/defaults.js +29 -0
- package/dist/controller/index.d.ts +66 -0
- package/dist/controller/index.d.ts.map +1 -0
- package/dist/controller/index.js +124 -0
- package/dist/controller/utils.d.ts +11 -0
- package/dist/controller/utils.d.ts.map +1 -0
- package/dist/controller/utils.js +8 -0
- package/dist/delivery/choice-input.d.ts +45 -0
- package/dist/delivery/choice-input.d.ts.map +1 -0
- package/dist/delivery/choice-input.js +269 -0
- package/dist/delivery/choice.d.ts +21 -0
- package/dist/delivery/choice.d.ts.map +1 -0
- package/dist/delivery/choice.js +109 -0
- package/dist/delivery/feedback-tick.d.ts +21 -0
- package/dist/delivery/feedback-tick.d.ts.map +1 -0
- package/dist/delivery/feedback-tick.js +104 -0
- package/dist/delivery/index.d.ts +34 -0
- package/dist/delivery/index.d.ts.map +1 -0
- package/dist/delivery/index.js +167 -0
- package/dist/delivery/main.d.ts +30 -0
- package/dist/delivery/main.d.ts.map +1 -0
- package/dist/delivery/main.js +47 -0
- package/dist/delivery/multiple-choice.d.ts +61 -0
- package/dist/delivery/multiple-choice.d.ts.map +1 -0
- package/dist/delivery/multiple-choice.js +241 -0
- package/dist/delivery/session-updater.d.ts +11 -0
- package/dist/delivery/session-updater.d.ts.map +1 -0
- package/dist/delivery/session-updater.js +9 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.iife.d.ts +9 -0
- package/dist/index.iife.d.ts.map +1 -0
- package/dist/index.iife.js +148 -0
- package/dist/index.js +2 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_DataView.js +6 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_Hash.js +16 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_ListCache.js +16 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_Map.js +6 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_MapCache.js +16 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_Promise.js +6 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_Set.js +6 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_SetCache.js +11 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_Stack.js +13 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_Symbol.js +5 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_Uint8Array.js +5 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_WeakMap.js +6 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_apply.js +12 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_arrayEach.js +7 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_arrayFilter.js +10 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_arrayLikeKeys.js +15 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_arrayPush.js +7 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_arraySome.js +7 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_assignMergeValue.js +8 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_assignValue.js +10 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_assocIndexOf.js +8 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_baseAssign.js +8 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_baseAssignIn.js +8 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_baseAssignValue.js +12 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_baseClone.js +57 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_baseCreate.js +14 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_baseFor.js +5 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_baseGetAllKeys.js +9 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_baseGetTag.js +10 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_baseIsArguments.js +9 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_baseIsEqual.js +8 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_baseIsEqualDeep.js +30 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_baseIsMap.js +9 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_baseIsNative.js +11 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_baseIsSet.js +9 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_baseIsTypedArray.js +11 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_baseKeys.js +12 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_baseKeysIn.js +13 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_baseMerge.js +19 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_baseMergeDeep.js +31 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_baseRest.js +9 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_baseSetToString.js +14 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_baseTimes.js +7 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_baseTrim.js +8 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_baseUnary.js +8 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_cacheHas.js +6 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_cloneArrayBuffer.js +8 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_cloneBuffer.js +10 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_cloneDataView.js +8 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_cloneRegExp.js +8 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_cloneSymbol.js +8 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_cloneTypedArray.js +8 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_copyArray.js +8 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_copyObject.js +14 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_copySymbols.js +8 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_copySymbolsIn.js +8 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_coreJsData.js +5 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_createAssigner.js +15 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_createBaseFor.js +12 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_defineProperty.js +10 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_equalArrays.js +35 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_equalByTag.js +35 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_equalObjects.js +32 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_freeGlobal.js +4 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_getAllKeys.js +9 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_getAllKeysIn.js +9 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_getMapData.js +8 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_getNative.js +9 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_getPrototype.js +5 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_getRawTag.js +14 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_getSymbols.js +10 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_getSymbolsIn.js +11 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_getTag.js +23 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_getValue.js +6 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_hashClear.js +7 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_hashDelete.js +7 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_hashGet.js +13 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_hashHas.js +9 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_hashSet.js +9 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_initCloneArray.js +8 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_initCloneByTag.js +33 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_initCloneObject.js +9 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_isIndex.js +8 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_isIterateeCall.js +12 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_isKeyable.js +7 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_isMasked.js +11 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_isPrototype.js +8 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_listCacheClear.js +6 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_listCacheDelete.js +9 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_listCacheGet.js +8 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_listCacheHas.js +7 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_listCacheSet.js +8 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_mapCacheClear.js +13 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_mapCacheDelete.js +8 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_mapCacheGet.js +7 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_mapCacheHas.js +7 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_mapCacheSet.js +8 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_mapToArray.js +9 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_nativeCreate.js +5 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_nativeKeys.js +5 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_nativeKeysIn.js +8 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_nodeUtil.js +9 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_objectToString.js +7 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_overArg.js +8 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_overRest.js +13 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_root.js +5 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_safeGet.js +6 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_setCacheAdd.js +7 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_setCacheHas.js +6 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_setToArray.js +9 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_setToString.js +6 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_shortOut.js +14 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_stackClear.js +7 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_stackDelete.js +7 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_stackGet.js +6 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_stackHas.js +6 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_stackSet.js +16 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_toSource.js +15 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_trimmedEndIndex.js +8 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/cloneDeep.js +8 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/constant.js +8 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/debounce.js +50 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/defaults.js +16 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/eq.js +6 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/identity.js +6 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/isArguments.js +10 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/isArray.js +4 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/isArrayLike.js +8 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/isArrayLikeObject.js +8 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/isBuffer.js +6 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/isEmpty.js +21 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/isEqual.js +7 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/isFunction.js +11 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/isLength.js +7 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/isMap.js +7 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/isObject.js +7 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/isObjectLike.js +6 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/isPlainObject.js +14 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/isSet.js +7 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/isSymbol.js +9 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/isTypedArray.js +7 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/keys.js +9 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/keysIn.js +9 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/merge.js +8 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/now.js +7 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/stubArray.js +6 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/stubFalse.js +6 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/toNumber.js +19 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/toPlainObject.js +8 -0
- package/dist/print/index.d.ts +16 -0
- package/dist/print/index.d.ts.map +1 -0
- package/dist/print/index.js +44 -0
- package/package.json +77 -0
- package/src/author/defaults.ts +168 -0
- package/src/author/index.ts +258 -0
- package/src/author/main.tsx +509 -0
- package/src/author/utils.ts +25 -0
- package/src/controller/defaults.ts +36 -0
- package/src/controller/index.ts +302 -0
- package/src/controller/utils.ts +22 -0
- package/src/delivery/choice-input.tsx +413 -0
- package/src/delivery/choice.tsx +203 -0
- package/src/delivery/feedback-tick.tsx +156 -0
- package/src/delivery/index.ts +411 -0
- package/src/delivery/main.tsx +81 -0
- package/src/delivery/multiple-choice.tsx +466 -0
- package/src/delivery/session-updater.ts +41 -0
- package/src/index.iife.ts +16 -0
- package/src/index.ts +1 -0
- package/src/print/index.tsx +112 -0
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/**
|
|
3
|
+
* @synced-from pie-elements/packages/multiple-choice/controller/src/index.js
|
|
4
|
+
* @auto-generated
|
|
5
|
+
*
|
|
6
|
+
* This file is automatically synced from pie-elements and converted to TypeScript.
|
|
7
|
+
* Manual edits will be overwritten on next sync.
|
|
8
|
+
* To make changes, edit the upstream JavaScript file and run sync again.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/* eslint-disable no-console */
|
|
12
|
+
import { isEmpty } from 'lodash-es';
|
|
13
|
+
import { isResponseCorrect } from './utils.js';
|
|
14
|
+
import defaults from './defaults.js';
|
|
15
|
+
import { lockChoices, partialScoring, getShuffledChoices } from '@pie-element/shared-controller-utils';
|
|
16
|
+
|
|
17
|
+
const prepareChoice = (model, env, defaultFeedback) => (choice) => {
|
|
18
|
+
const { role, mode } = env || {};
|
|
19
|
+
const out = {
|
|
20
|
+
label: choice.label,
|
|
21
|
+
value: choice.value,
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
if (role === 'instructor' && (mode === 'view' || mode === 'evaluate')) {
|
|
25
|
+
out.rationale = model.rationaleEnabled ? choice.rationale : null;
|
|
26
|
+
} else {
|
|
27
|
+
out.rationale = null;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (mode === 'evaluate') {
|
|
31
|
+
out.correct = !!choice.correct;
|
|
32
|
+
|
|
33
|
+
if (model.feedbackEnabled) {
|
|
34
|
+
const feedbackType = (choice.feedback && choice.feedback.type) || 'none';
|
|
35
|
+
|
|
36
|
+
if (feedbackType === 'default') {
|
|
37
|
+
out.feedback = defaultFeedback[choice.correct ? 'correct' : 'incorrect'];
|
|
38
|
+
} else if (feedbackType === 'custom') {
|
|
39
|
+
out.feedback = choice.feedback.value;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return out;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export function createDefaultModel(model = {}) {
|
|
48
|
+
return new Promise((resolve) => resolve({ ...defaults, ...model }));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export const normalize = (question) => {
|
|
52
|
+
const { verticalMode, choicesLayout, ...questionProps } = question || {};
|
|
53
|
+
|
|
54
|
+
return {
|
|
55
|
+
...defaults,
|
|
56
|
+
...questionProps,
|
|
57
|
+
// This is used for offering support for old models which have the property verticalMode
|
|
58
|
+
// Same thing is set in authoring : packages/multiple-choice/configure/src/index.jsx - createDefaultModel
|
|
59
|
+
choicesLayout: choicesLayout || (verticalMode === false && 'horizontal') || defaults.choicesLayout,
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
*
|
|
65
|
+
* @param {*} question
|
|
66
|
+
* @param {*} session
|
|
67
|
+
* @param {*} env
|
|
68
|
+
* @param {*} updateSession - optional - a function that will set the properties passed into it on the session.
|
|
69
|
+
*/
|
|
70
|
+
export async function model(question, session, env, updateSession) {
|
|
71
|
+
const normalizedQuestion = normalize(question);
|
|
72
|
+
|
|
73
|
+
const defaultFeedback = Object.assign(
|
|
74
|
+
{ correct: 'Correct', incorrect: 'Incorrect' },
|
|
75
|
+
normalizedQuestion.defaultFeedback,
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
let choices = (normalizedQuestion.choices || []).map(prepareChoice(normalizedQuestion, env, defaultFeedback));
|
|
79
|
+
|
|
80
|
+
const lockChoiceOrder = lockChoices(normalizedQuestion, session, env);
|
|
81
|
+
|
|
82
|
+
if (!lockChoiceOrder) {
|
|
83
|
+
choices = await getShuffledChoices(choices, session, updateSession, 'value');
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const out = {
|
|
87
|
+
disabled: env.mode !== 'gather',
|
|
88
|
+
mode: env.mode,
|
|
89
|
+
prompt: normalizedQuestion.promptEnabled ? normalizedQuestion.prompt : null,
|
|
90
|
+
choicesLayout: normalizedQuestion.choicesLayout,
|
|
91
|
+
gridColumns: normalizedQuestion.gridColumns,
|
|
92
|
+
choiceMode: normalizedQuestion.choiceMode,
|
|
93
|
+
keyMode: normalizedQuestion.choicePrefix,
|
|
94
|
+
choices,
|
|
95
|
+
responseCorrect: env.mode === 'evaluate' ? isResponseCorrect(normalizedQuestion, session) : undefined,
|
|
96
|
+
language: normalizedQuestion.language,
|
|
97
|
+
extraCSSRules: normalizedQuestion.extraCSSRules,
|
|
98
|
+
fontSizeFactor: normalizedQuestion.fontSizeFactor,
|
|
99
|
+
isSelectionButtonBelow: normalizedQuestion.isSelectionButtonBelow,
|
|
100
|
+
selectedAnswerBackgroundColor: normalizedQuestion.selectedAnswerBackgroundColor || 'initial',
|
|
101
|
+
selectedAnswerStrokeColor: normalizedQuestion.selectedAnswerStrokeColor || 'initial',
|
|
102
|
+
selectedAnswerStrokeWidth: normalizedQuestion.selectedAnswerStrokeWidth || 'initial',
|
|
103
|
+
hoverAnswerBackgroundColor: normalizedQuestion.hoverAnswerBackgroundColor || 'initial',
|
|
104
|
+
hoverAnswerStrokeColor: normalizedQuestion.hoverAnswerStrokeColor || 'initial',
|
|
105
|
+
hoverAnswerStrokeWidth: normalizedQuestion.hoverAnswerStrokeWidth || 'initial',
|
|
106
|
+
minSelections: normalizedQuestion.minSelections,
|
|
107
|
+
maxSelections: normalizedQuestion.maxSelections,
|
|
108
|
+
keyboardEventsEnabled: normalizedQuestion.keyboardEventsEnabled,
|
|
109
|
+
autoplayAudioEnabled: normalizedQuestion.autoplayAudioEnabled,
|
|
110
|
+
completeAudioEnabled: normalizedQuestion.completeAudioEnabled,
|
|
111
|
+
customAudioButton: normalizedQuestion.customAudioButton,
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
const { role, mode } = env || {};
|
|
115
|
+
|
|
116
|
+
if (role === 'instructor' && (mode === 'view' || mode === 'evaluate')) {
|
|
117
|
+
out.teacherInstructions = normalizedQuestion.teacherInstructionsEnabled
|
|
118
|
+
? normalizedQuestion.teacherInstructions
|
|
119
|
+
: null;
|
|
120
|
+
} else {
|
|
121
|
+
out.teacherInstructions = null;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return out;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export const getScore = (config, session) => {
|
|
128
|
+
if (!session || isEmpty(session)) {
|
|
129
|
+
return 0;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const selectedChoices = session.value || [];
|
|
133
|
+
const correctChoices = (config.choices || []).filter((ch) => ch.correct);
|
|
134
|
+
|
|
135
|
+
let score = selectedChoices.reduce(
|
|
136
|
+
(acc, selectedChoice) => acc + (correctChoices.find((ch) => ch.value === selectedChoice) ? 1 : 0),
|
|
137
|
+
0,
|
|
138
|
+
);
|
|
139
|
+
|
|
140
|
+
if (correctChoices.length < selectedChoices.length) {
|
|
141
|
+
score -= selectedChoices.length - correctChoices.length;
|
|
142
|
+
|
|
143
|
+
if (score < 0) {
|
|
144
|
+
score = 0;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const str = correctChoices.length ? score / correctChoices.length : 0;
|
|
149
|
+
|
|
150
|
+
return parseFloat(str.toFixed(2));
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Generates detailed trace log for scoring evaluation
|
|
155
|
+
* @param {Object} model - the question model
|
|
156
|
+
* @param {Object} session - the student session
|
|
157
|
+
* @param {Object} env - the environment
|
|
158
|
+
* @returns {Array} traceLog - array of trace messages
|
|
159
|
+
*/
|
|
160
|
+
export const getLogTrace = (model, session, env) => {
|
|
161
|
+
const traceLog = [];
|
|
162
|
+
const selected = session?.value || [];
|
|
163
|
+
|
|
164
|
+
const questionType = model.choiceMode === 'radio' ? 'multiple-choice (radio)' : 'multiple-select (checkbox)';
|
|
165
|
+
traceLog.push(`Question type: ${questionType}.`);
|
|
166
|
+
|
|
167
|
+
if (selected.length) {
|
|
168
|
+
traceLog.push(`Student selected ${selected.length} answer(s): ${selected.join(', ')}.`);
|
|
169
|
+
} else {
|
|
170
|
+
traceLog.push('Student did not select any answers.');
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
const correctChoices = (model.choices || []).filter((c) => c.correct);
|
|
174
|
+
const correctValues = correctChoices.map((c) => c.value);
|
|
175
|
+
traceLog.push(`${correctChoices.length} correct answer(s) are defined for this question.`);
|
|
176
|
+
|
|
177
|
+
if (selected.length) {
|
|
178
|
+
const correctSelected = selected.filter((v) => correctValues.includes(v));
|
|
179
|
+
const incorrectSelected = selected.filter((v) => !correctValues.includes(v));
|
|
180
|
+
traceLog.push(
|
|
181
|
+
`Student selected ${correctSelected.length} correct and ${incorrectSelected.length} incorrect answer(s).`
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
const partialScoringEnabled = partialScoring.enabled(model, env) && model.choiceMode !== 'radio';
|
|
186
|
+
const scoringMethod = partialScoringEnabled ? 'partial scoring' : 'all-or-nothing scoring';
|
|
187
|
+
traceLog.push(`Score calculated using ${scoringMethod}.`);
|
|
188
|
+
|
|
189
|
+
const score = getScore(model, session);
|
|
190
|
+
traceLog.push(`Final score: ${score}.`);
|
|
191
|
+
|
|
192
|
+
return traceLog;
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
*
|
|
197
|
+
* The score is partial by default for checkbox mode, allOrNothing for radio mode.
|
|
198
|
+
* To disable partial scoring for checkbox mode you either set model.partialScoring = false or env.partialScoring = false. the value in `env` will
|
|
199
|
+
* override the value in `model`.
|
|
200
|
+
* @param {Object} model - the main model
|
|
201
|
+
* @param {*} session
|
|
202
|
+
* @param {Object} env
|
|
203
|
+
*/
|
|
204
|
+
export function outcome(model, session, env) {
|
|
205
|
+
return new Promise((resolve) => {
|
|
206
|
+
if (!session || isEmpty(session)) {
|
|
207
|
+
resolve({ score: 0, empty: true, traceLog: ['Student did not select any answers. Score is 0.'] });
|
|
208
|
+
} else {
|
|
209
|
+
const traceLog = getLogTrace(model, session, env);
|
|
210
|
+
const score = getScore(model, session);
|
|
211
|
+
const partialScoringEnabled = partialScoring.enabled(model, env) && model.choiceMode !== 'radio';
|
|
212
|
+
|
|
213
|
+
resolve({
|
|
214
|
+
score: partialScoringEnabled ? score : score === 1 ? 1 : 0,
|
|
215
|
+
empty: false,
|
|
216
|
+
traceLog
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
export const createCorrectResponseSession = (question, env) => {
|
|
223
|
+
return new Promise((resolve) => {
|
|
224
|
+
if (env.mode !== 'evaluate' && env.role === 'instructor') {
|
|
225
|
+
const { choices } = question || { choices: [] };
|
|
226
|
+
|
|
227
|
+
resolve({
|
|
228
|
+
id: '1',
|
|
229
|
+
value: choices.filter((c) => c.correct).map((c) => c.value),
|
|
230
|
+
});
|
|
231
|
+
} else {
|
|
232
|
+
resolve(null);
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
// remove all html tags
|
|
238
|
+
const getInnerText = (html) => (html || '').replaceAll(/<[^>]*>/g, '');
|
|
239
|
+
|
|
240
|
+
// remove all html tags except img, iframe and source tag for audio
|
|
241
|
+
const getContent = (html) => (html || '').replace(/(<(?!img|iframe|source)([^>]+)>)/gi, '');
|
|
242
|
+
|
|
243
|
+
export const validate = (model = {}, config = {}) => {
|
|
244
|
+
const { choices } = model;
|
|
245
|
+
const { minAnswerChoices = 2, maxAnswerChoices } = config;
|
|
246
|
+
const reversedChoices = [...(choices || [])].reverse();
|
|
247
|
+
const choicesErrors = {};
|
|
248
|
+
const rationaleErrors = {};
|
|
249
|
+
const errors = {};
|
|
250
|
+
|
|
251
|
+
['teacherInstructions', 'prompt'].forEach((field) => {
|
|
252
|
+
if (config[field]?.required && !getContent(model[field])) {
|
|
253
|
+
errors[field] = 'This field is required.';
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
let hasCorrectResponse = false;
|
|
258
|
+
|
|
259
|
+
reversedChoices.forEach((choice, index) => {
|
|
260
|
+
const { correct, value, label, rationale } = choice;
|
|
261
|
+
|
|
262
|
+
if (correct) {
|
|
263
|
+
hasCorrectResponse = true;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
if (!getContent(label)) {
|
|
267
|
+
choicesErrors[value] = 'Content should not be empty.';
|
|
268
|
+
} else {
|
|
269
|
+
const identicalAnswer = reversedChoices.slice(index + 1).some((c) => c.label === label);
|
|
270
|
+
|
|
271
|
+
if (identicalAnswer) {
|
|
272
|
+
choicesErrors[value] = 'Content should be unique.';
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
if (config.rationale?.required && !getContent(rationale)) {
|
|
277
|
+
rationaleErrors[value] = 'This field is required.';
|
|
278
|
+
}
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
const nbOfChoices = (choices || []).length;
|
|
282
|
+
|
|
283
|
+
if (nbOfChoices < minAnswerChoices) {
|
|
284
|
+
errors.answerChoices = `There should be at least ${minAnswerChoices} choices defined.`;
|
|
285
|
+
} else if (nbOfChoices > maxAnswerChoices) {
|
|
286
|
+
errors.answerChoices = `No more than ${maxAnswerChoices} choices should be defined.`;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
if (!hasCorrectResponse) {
|
|
290
|
+
errors.correctResponse = 'No correct response defined.';
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
if (!isEmpty(choicesErrors)) {
|
|
294
|
+
errors.choices = choicesErrors;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
if (!isEmpty(rationaleErrors)) {
|
|
298
|
+
errors.rationale = rationaleErrors;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
return errors;
|
|
302
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/**
|
|
3
|
+
* @synced-from pie-elements/packages/multiple-choice/controller/src/utils.js
|
|
4
|
+
* @auto-generated
|
|
5
|
+
*
|
|
6
|
+
* This file is automatically synced from pie-elements and converted to TypeScript.
|
|
7
|
+
* Manual edits will be overwritten on next sync.
|
|
8
|
+
* To make changes, edit the upstream JavaScript file and run sync again.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { isEqual } from 'lodash-es';
|
|
12
|
+
|
|
13
|
+
export const getCorrectResponse = (choices) =>
|
|
14
|
+
choices
|
|
15
|
+
.filter((c) => c.correct)
|
|
16
|
+
.map((c) => c.value)
|
|
17
|
+
.sort();
|
|
18
|
+
|
|
19
|
+
export const isResponseCorrect = (question, session) => {
|
|
20
|
+
let correctResponse = getCorrectResponse(question.choices);
|
|
21
|
+
return session && isEqual((session.value || []).sort(), correctResponse);
|
|
22
|
+
};
|