@pie-element/math-templated 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 +174 -0
- package/dist/author/defaults.d.ts.map +1 -0
- package/dist/author/defaults.js +123 -0
- package/dist/author/design.d.ts +36 -0
- package/dist/author/design.d.ts.map +1 -0
- package/dist/author/design.js +494 -0
- package/dist/author/index.d.ts +43 -0
- package/dist/author/index.d.ts.map +1 -0
- package/dist/author/index.js +98 -0
- package/dist/author/markupUtils.d.ts +12 -0
- package/dist/author/markupUtils.d.ts.map +1 -0
- package/dist/author/markupUtils.js +10 -0
- package/dist/author/response.d.ts +42 -0
- package/dist/author/response.d.ts.map +1 -0
- package/dist/author/response.js +342 -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 +30 -0
- package/dist/controller/defaults.d.ts.map +1 -0
- package/dist/controller/defaults.js +23 -0
- package/dist/controller/index.d.ts +38 -0
- package/dist/controller/index.d.ts.map +1 -0
- package/dist/controller/index.js +125 -0
- package/dist/delivery/index.d.ts +21 -0
- package/dist/delivery/index.d.ts.map +1 -0
- package/dist/delivery/index.js +51 -0
- package/dist/delivery/main.d.ts +40 -0
- package/dist/delivery/main.d.ts.map +1 -0
- package/dist/delivery/main.js +538 -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 +224 -0
- package/dist/index.js +2 -0
- package/dist/math-templated.css +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/_arrayMap.js +7 -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/_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/_baseFlatten.js +13 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_baseGet.js +10 -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/_baseHasIn.js +6 -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/_basePick.js +10 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_basePickBy.js +13 -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/_baseSet.js +22 -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/_baseToString.js +15 -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/_castPath.js +10 -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/_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/_flatRest.js +9 -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/_hasPath.js +18 -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/_isFlattenable.js +10 -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/_isKey.js +11 -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/_memoizeCapped.js +11 -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/_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/_stringToPath.js +10 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/_toKey.js +10 -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/flatten.js +7 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/hasIn.js +8 -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/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/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/memoize.js +16 -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/pick.js +8 -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/throttle.js +15 -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/toString.js +7 -0
- package/dist/print/index.d.ts +16 -0
- package/dist/print/index.d.ts.map +1 -0
- package/dist/print/index.js +47 -0
- package/package.json +80 -0
- package/src/author/defaults.ts +133 -0
- package/src/author/design.tsx +526 -0
- package/src/author/index.ts +195 -0
- package/src/author/markupUtils.tsx +55 -0
- package/src/author/response.tsx +397 -0
- package/src/author/utils.ts +24 -0
- package/src/controller/defaults.ts +31 -0
- package/src/controller/index.ts +294 -0
- package/src/delivery/index.ts +94 -0
- package/src/delivery/main.tsx +800 -0
- package/src/index.iife.ts +16 -0
- package/src/index.ts +1 -0
- package/src/print/index.tsx +99 -0
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/**
|
|
3
|
+
* @synced-from pie-elements/packages/math-templated/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
|
+
import debug from 'debug';
|
|
12
|
+
import { isEmpty } from 'lodash-es';
|
|
13
|
+
import Translator from '@pie-lib/translator';
|
|
14
|
+
import * as mv from '@pie-framework/math-validation';
|
|
15
|
+
|
|
16
|
+
import defaults from './defaults';
|
|
17
|
+
import { partialScoring } from '@pie-element/shared-controller-utils';
|
|
18
|
+
|
|
19
|
+
const { translator } = Translator;
|
|
20
|
+
const log = debug('@pie-element:math-templated:controller');
|
|
21
|
+
|
|
22
|
+
const getFeedback = (value) => (value ? 'correct' : 'incorrect');
|
|
23
|
+
const getContent = (html) => (html || '').replace(/(<(?!img|iframe|source)([^>]+)>)/gi, '');
|
|
24
|
+
|
|
25
|
+
const getIsAnswerCorrect = (correctResponse, answerItem) => {
|
|
26
|
+
let answerCorrect = false;
|
|
27
|
+
|
|
28
|
+
const opts = {
|
|
29
|
+
mode: correctResponse.validation || defaults.validationDefault,
|
|
30
|
+
...(correctResponse.validation === 'literal' && {
|
|
31
|
+
literal: {
|
|
32
|
+
allowTrailingZeros: correctResponse.allowTrailingZeros || false,
|
|
33
|
+
ignoreOrder: correctResponse.ignoreOrder || false,
|
|
34
|
+
},
|
|
35
|
+
}),
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
if (!answerCorrect) {
|
|
39
|
+
const acceptedValues = [correctResponse.answer, ...Object.values(correctResponse.alternates || {})];
|
|
40
|
+
|
|
41
|
+
try {
|
|
42
|
+
for (const value of acceptedValues) {
|
|
43
|
+
answerCorrect = mv.latexEqual(answerItem.value, value, opts);
|
|
44
|
+
if (answerCorrect) break;
|
|
45
|
+
}
|
|
46
|
+
} catch (e) {
|
|
47
|
+
log('Parse failure when evaluating math', e, correctResponse, answerItem);
|
|
48
|
+
answerCorrect = false;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return answerCorrect;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const getResponseCorrectness = (question, sessionResponse) => {
|
|
56
|
+
const correctResponses = question.responses;
|
|
57
|
+
|
|
58
|
+
if (!sessionResponse) {
|
|
59
|
+
return {
|
|
60
|
+
correctness: 'unanswered',
|
|
61
|
+
score: 0,
|
|
62
|
+
correct: false,
|
|
63
|
+
};
|
|
64
|
+
} else {
|
|
65
|
+
let correctAnswers = 0;
|
|
66
|
+
let score = 0;
|
|
67
|
+
const correctResponsesCount = Object.keys(correctResponses || {}).length;
|
|
68
|
+
|
|
69
|
+
Object.keys(correctResponses).forEach((responseId) => {
|
|
70
|
+
const answerItem = sessionResponse['r' + responseId];
|
|
71
|
+
const correctResponse = correctResponses[responseId] || {};
|
|
72
|
+
|
|
73
|
+
const answerCorrect = getIsAnswerCorrect(correctResponse, answerItem);
|
|
74
|
+
if (answerCorrect) {
|
|
75
|
+
correctAnswers++;
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
const fullyCorrect = correctAnswers === correctResponsesCount;
|
|
80
|
+
|
|
81
|
+
// partial credit scoring: each correct answer is worth 1 / total answers point
|
|
82
|
+
// dichotomous scoring: for credit to be awarded, a correct answer must be entered for every response area
|
|
83
|
+
score = Number((correctAnswers / Object.keys(correctResponses).length).toFixed(2));
|
|
84
|
+
|
|
85
|
+
return {
|
|
86
|
+
correctness: getFeedback(fullyCorrect),
|
|
87
|
+
score: correctAnswers > 0 ? score : 0,
|
|
88
|
+
correct: fullyCorrect,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
export const getCorrectness = (question, env, session) => {
|
|
94
|
+
if (env.mode === 'evaluate') {
|
|
95
|
+
return getResponseCorrectness(question, session && session.answers);
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
export const getPartialScore = (question, session) => {
|
|
100
|
+
if (!session || isEmpty(session)) {
|
|
101
|
+
return 0;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return 1;
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
export const outcome = (question, session, env) =>
|
|
108
|
+
new Promise((resolve) => {
|
|
109
|
+
if (!session || isEmpty(session)) {
|
|
110
|
+
resolve({ score: 0, empty: true });
|
|
111
|
+
}
|
|
112
|
+
const partialScoringEnabled = partialScoring.enabled(question, env);
|
|
113
|
+
session = normalizeSession(session);
|
|
114
|
+
|
|
115
|
+
if (env.mode !== 'evaluate') {
|
|
116
|
+
resolve({ score: undefined, completed: undefined });
|
|
117
|
+
} else {
|
|
118
|
+
const correctness = getCorrectness(question, env, session, true);
|
|
119
|
+
const score = correctness.score;
|
|
120
|
+
|
|
121
|
+
resolve({ score: partialScoringEnabled ? score : score === 1 ? 1 : 0 });
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
export const createDefaultModel = (model = {}) => {
|
|
126
|
+
const { validationDefault, allowTrailingZerosDefault, ignoreOrderDefault, responses = {} } = model;
|
|
127
|
+
|
|
128
|
+
const updatedResponses = Object.keys(responses).reduce((acc, responseId) => {
|
|
129
|
+
const correctResponse = responses[responseId];
|
|
130
|
+
|
|
131
|
+
acc[responseId] = {
|
|
132
|
+
...correctResponse,
|
|
133
|
+
validation: correctResponse.validation || validationDefault,
|
|
134
|
+
allowTrailingZeros: correctResponse.allowTrailingZeros || allowTrailingZerosDefault,
|
|
135
|
+
ignoreOrder: correctResponse.ignoreOrder || ignoreOrderDefault,
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
return acc;
|
|
139
|
+
}, {});
|
|
140
|
+
|
|
141
|
+
return {
|
|
142
|
+
...defaults.model,
|
|
143
|
+
...model,
|
|
144
|
+
responses: updatedResponses,
|
|
145
|
+
};
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
export const normalizeSession = (s) => ({ ...s });
|
|
149
|
+
|
|
150
|
+
const getTextFromHTML = (html) => (html || '').replace(/<\/?[^>]+(>|$)/g, '');
|
|
151
|
+
|
|
152
|
+
export const prepareVal = (html) => getTextFromHTML(html).trim();
|
|
153
|
+
|
|
154
|
+
export const model = (question, session, env) => {
|
|
155
|
+
return new Promise((resolve) => {
|
|
156
|
+
session = session || {};
|
|
157
|
+
const normalizedQuestion = createDefaultModel(question);
|
|
158
|
+
const correctness = getCorrectness(normalizedQuestion, env, session);
|
|
159
|
+
const { responses, language } = normalizedQuestion;
|
|
160
|
+
let { note } = normalizedQuestion;
|
|
161
|
+
let showNote = false;
|
|
162
|
+
|
|
163
|
+
// check if there is at least one alternate response or if the validation for at least one response is not literal
|
|
164
|
+
Object.keys(responses).forEach((responseId) => {
|
|
165
|
+
const correctResponse = responses[responseId] || {};
|
|
166
|
+
if (correctResponse.alternates && Object.keys(correctResponse.alternates).length > 0) {
|
|
167
|
+
showNote = true;
|
|
168
|
+
} else if (correctResponse.validation !== 'literal') {
|
|
169
|
+
showNote = true;
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
if (!note) {
|
|
174
|
+
note = translator.t('mathInline.primaryCorrectWithAlternates', { lng: language });
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
const out = {
|
|
178
|
+
prompt: normalizedQuestion.promptEnabled ? normalizedQuestion.prompt : null,
|
|
179
|
+
markup: normalizedQuestion.markup,
|
|
180
|
+
responses: env.mode === 'gather' ? null : normalizedQuestion.responses,
|
|
181
|
+
language: normalizedQuestion.language,
|
|
182
|
+
equationEditor: normalizedQuestion.equationEditor,
|
|
183
|
+
customKeys: normalizedQuestion.customKeys,
|
|
184
|
+
disabled: env.mode !== 'gather',
|
|
185
|
+
view: env.mode === 'view',
|
|
186
|
+
correctness,
|
|
187
|
+
env,
|
|
188
|
+
extraCSSRules: normalizedQuestion.extraCSSRules,
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
const { answers = {} } = session || {};
|
|
192
|
+
let feedback = {};
|
|
193
|
+
|
|
194
|
+
if (env.mode === 'evaluate') {
|
|
195
|
+
Object.keys(responses).forEach((responseId) => {
|
|
196
|
+
const answerItem = answers['r' + responseId];
|
|
197
|
+
const correctResponse = responses[responseId];
|
|
198
|
+
feedback[responseId] = getIsAnswerCorrect(correctResponse, answerItem);
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
if (env.mode === 'evaluate') {
|
|
203
|
+
out.correctResponse = {};
|
|
204
|
+
out.showNote = showNote;
|
|
205
|
+
out.note = note;
|
|
206
|
+
out.feedback = feedback;
|
|
207
|
+
} else {
|
|
208
|
+
out.responses = {};
|
|
209
|
+
out.showNote = false;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
if (env.role === 'instructor' && (env.mode === 'view' || env.mode === 'evaluate')) {
|
|
213
|
+
out.rationale = normalizedQuestion.rationaleEnabled ? normalizedQuestion.rationale : null;
|
|
214
|
+
out.teacherInstructions = normalizedQuestion.teacherInstructionsEnabled
|
|
215
|
+
? normalizedQuestion.teacherInstructions
|
|
216
|
+
: null;
|
|
217
|
+
} else {
|
|
218
|
+
out.rationale = null;
|
|
219
|
+
out.teacherInstructions = null;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
log('out: ', out);
|
|
223
|
+
resolve(out);
|
|
224
|
+
});
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
export const createCorrectResponseSession = (question, env) =>
|
|
228
|
+
new Promise((resolve) => {
|
|
229
|
+
if (env.mode !== 'evaluate' && env.role === 'instructor') {
|
|
230
|
+
const correctResponse = Object.keys(question.responses).reduce((acc, responseId) => {
|
|
231
|
+
acc['r' + responseId] = { value: question.responses[responseId].answer };
|
|
232
|
+
return acc;
|
|
233
|
+
}, {});
|
|
234
|
+
|
|
235
|
+
resolve({ id: '1', answers: correctResponse });
|
|
236
|
+
} else {
|
|
237
|
+
resolve(null);
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
export const validate = (model = {}, config = {}) => {
|
|
242
|
+
const { responses, markup } = model;
|
|
243
|
+
const { maxResponseAreas } = config;
|
|
244
|
+
const responsesErrors = {};
|
|
245
|
+
const errors = {};
|
|
246
|
+
|
|
247
|
+
['teacherInstructions', 'prompt', 'rationale'].forEach((field) => {
|
|
248
|
+
if (config[field]?.required && !getContent(model[field])) {
|
|
249
|
+
errors[field] = 'This field is required.';
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
Object.entries(responses || {}).forEach(([key, response], index) => {
|
|
254
|
+
const { answer } = response;
|
|
255
|
+
const reversedAlternates = [...Object.entries(response.alternates || {})].reverse();
|
|
256
|
+
const alternatesErrors = {};
|
|
257
|
+
const responseError = {};
|
|
258
|
+
|
|
259
|
+
if (answer === '') {
|
|
260
|
+
responseError.answer = 'Content should not be empty.';
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
reversedAlternates.forEach(([key, value], index) => {
|
|
264
|
+
if (value === '') {
|
|
265
|
+
alternatesErrors[key] = 'Content should not be empty.';
|
|
266
|
+
} else {
|
|
267
|
+
const identicalAnswer =
|
|
268
|
+
answer === value || reversedAlternates.slice(index + 1).some(([, val]) => val === value);
|
|
269
|
+
|
|
270
|
+
if (identicalAnswer) {
|
|
271
|
+
alternatesErrors[key] = 'Content should be unique.';
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
if (!isEmpty(responseError) || !isEmpty(alternatesErrors)) {
|
|
277
|
+
responsesErrors[index] = { ...responseError, ...alternatesErrors };
|
|
278
|
+
}
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
const nbOfResponseAreas = (markup.match(/\{\{(\d+)\}\}/g) || []).length;
|
|
282
|
+
|
|
283
|
+
if (nbOfResponseAreas > maxResponseAreas) {
|
|
284
|
+
errors.responseAreas = `No more than ${maxResponseAreas} response areas should be defined.`;
|
|
285
|
+
} else if (nbOfResponseAreas < 1) {
|
|
286
|
+
errors.responseAreas = 'There should be at least 1 response area defined.';
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
if (!isEmpty(responsesErrors)) {
|
|
290
|
+
errors.responses = responsesErrors;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
return errors;
|
|
294
|
+
};
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/**
|
|
3
|
+
* @synced-from pie-elements/packages/math-templated/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
|
+
import React from 'react';
|
|
12
|
+
import { createRoot } from 'react-dom/client';
|
|
13
|
+
import { SessionChangedEvent, ModelSetEvent } from '@pie-element/shared-player-events';
|
|
14
|
+
import Main from './main';
|
|
15
|
+
import { debounce } from 'lodash-es';
|
|
16
|
+
|
|
17
|
+
export default class MathTemplated extends HTMLElement {
|
|
18
|
+
constructor() {
|
|
19
|
+
super();
|
|
20
|
+
this._root = null;
|
|
21
|
+
this.sessionChangedEventCaller = debounce(() => {
|
|
22
|
+
this.dispatchEvent(new SessionChangedEvent(this.tagName.toLowerCase(), true));
|
|
23
|
+
}, 1000);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
set model(m) {
|
|
27
|
+
this._model = m;
|
|
28
|
+
|
|
29
|
+
this.render();
|
|
30
|
+
this.dispatchEvent(
|
|
31
|
+
new ModelSetEvent(this.tagName.toLowerCase(), this.isSessionComplete(), this._model !== undefined),
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
get model() {
|
|
36
|
+
return this._model;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
set session(s) {
|
|
40
|
+
this._session = s;
|
|
41
|
+
|
|
42
|
+
this.render();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
get session() {
|
|
46
|
+
return this._session;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
isSessionComplete() {
|
|
50
|
+
// a method to check if student answered the question
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
onSessionChange(session) {
|
|
55
|
+
// you can add an extra step here to validate session
|
|
56
|
+
Object.keys(session).map((key) => {
|
|
57
|
+
this._session[key] = session[key];
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
this.sessionChangedEventCaller();
|
|
61
|
+
this.render();
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
connectedCallback() {
|
|
65
|
+
// TODO set accessibility labels
|
|
66
|
+
|
|
67
|
+
this.render();
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
render() {
|
|
71
|
+
if (!this._model || !this._session) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (this._model && this._session) {
|
|
76
|
+
const el = React.createElement(Main, {
|
|
77
|
+
model: this._model,
|
|
78
|
+
session: this._session,
|
|
79
|
+
onSessionChange: this.onSessionChange.bind(this),
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
if (!this._root) {
|
|
83
|
+
this._root = createRoot(this);
|
|
84
|
+
}
|
|
85
|
+
this._root.render(el);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
disconnectedCallback() {
|
|
90
|
+
if (this._root) {
|
|
91
|
+
this._root.unmount();
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|