@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,800 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/**
|
|
3
|
+
* @synced-from pie-elements/packages/math-templated/src/main.jsx
|
|
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 PropTypes from 'prop-types';
|
|
13
|
+
import { isEmpty, isEqual } from 'lodash-es';
|
|
14
|
+
import { styled } from '@mui/material/styles';
|
|
15
|
+
import Tooltip from '@mui/material/Tooltip';
|
|
16
|
+
import { mq, HorizontalKeypad, updateSpans } from '@pie-lib/math-input';
|
|
17
|
+
import { color, Collapsible, Readable, hasText, hasMedia, PreviewPrompt, UiLayout } from '@pie-lib/render-ui';
|
|
18
|
+
import { renderMath } from '@pie-element/shared-math-rendering-mathjax';
|
|
19
|
+
import { Customizable } from '@pie-lib/mask-markup';
|
|
20
|
+
import CorrectAnswerToggle from '@pie-lib/correct-answer-toggle';
|
|
21
|
+
import ReactDOM from 'react-dom';
|
|
22
|
+
import MathQuill from '@pie-framework/mathquill';
|
|
23
|
+
|
|
24
|
+
const StyledUiLayout: any = styled(UiLayout)({
|
|
25
|
+
color: color.text(),
|
|
26
|
+
backgroundColor: color.background(),
|
|
27
|
+
display: 'inline-block',
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
const MainContainer: any = styled('div')({
|
|
31
|
+
width: '100%',
|
|
32
|
+
position: 'relative',
|
|
33
|
+
backgroundColor: color.background(),
|
|
34
|
+
color: color.text(),
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
const PromptContainer: any = styled('div')(({ theme }) => ({
|
|
38
|
+
marginBottom: theme.spacing(2),
|
|
39
|
+
}));
|
|
40
|
+
|
|
41
|
+
const CollapsibleContainer: any = styled('div')(({ theme }) => ({
|
|
42
|
+
marginBottom: theme.spacing(2),
|
|
43
|
+
}));
|
|
44
|
+
|
|
45
|
+
const InputAndKeypadContainer: any = styled('div')({
|
|
46
|
+
position: 'relative',
|
|
47
|
+
'& > div > div': {
|
|
48
|
+
display: 'flex',
|
|
49
|
+
alignItems: 'baseline',
|
|
50
|
+
flexWrap: 'wrap',
|
|
51
|
+
},
|
|
52
|
+
'& .mq-overarrow-inner': {
|
|
53
|
+
border: 'none !important',
|
|
54
|
+
padding: '0 !important',
|
|
55
|
+
},
|
|
56
|
+
'& .mq-overarrow-inner-right': {
|
|
57
|
+
display: 'none !important',
|
|
58
|
+
},
|
|
59
|
+
'& .mq-overarrow-inner-left': {
|
|
60
|
+
display: 'none !important',
|
|
61
|
+
},
|
|
62
|
+
'& .mq-overarrow.mq-arrow-both': {
|
|
63
|
+
minWidth: '1.23em',
|
|
64
|
+
'& *': {
|
|
65
|
+
lineHeight: '1 !important',
|
|
66
|
+
},
|
|
67
|
+
'&:before': {
|
|
68
|
+
top: '-0.4em',
|
|
69
|
+
left: '-1px',
|
|
70
|
+
},
|
|
71
|
+
'&:after': {
|
|
72
|
+
top: '-2.4em',
|
|
73
|
+
right: '-1px',
|
|
74
|
+
},
|
|
75
|
+
'&.mq-empty:after': {
|
|
76
|
+
top: '-0.45em',
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
'& .mq-overarrow.mq-arrow-right': {
|
|
80
|
+
'&:before': {
|
|
81
|
+
top: '-0.4em',
|
|
82
|
+
right: '-1px',
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
'& .mq-longdiv-inner': {
|
|
86
|
+
borderTop: '1px solid !important',
|
|
87
|
+
paddingTop: '1.5px !important',
|
|
88
|
+
},
|
|
89
|
+
'& .mq-parallelogram': {
|
|
90
|
+
lineHeight: 0.85,
|
|
91
|
+
},
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
const Expression: any = styled('div')(({ theme, $incorrect, $correct, $showCorrectness, $correctAnswerShown }) => ({
|
|
95
|
+
maxWidth: 'fit-content',
|
|
96
|
+
...($incorrect && {
|
|
97
|
+
borderColor: `${color.incorrect()} !important`,
|
|
98
|
+
}),
|
|
99
|
+
...($correct && {
|
|
100
|
+
borderColor: `${color.correct()} !important`,
|
|
101
|
+
}),
|
|
102
|
+
...($showCorrectness && {
|
|
103
|
+
border: '2px solid',
|
|
104
|
+
}),
|
|
105
|
+
...($correctAnswerShown && {
|
|
106
|
+
padding: theme.spacing(1),
|
|
107
|
+
letterSpacing: '0.5px',
|
|
108
|
+
}),
|
|
109
|
+
'& > .mq-math-mode': {
|
|
110
|
+
'& > .mq-root-block': {
|
|
111
|
+
'& > .mq-editable-field': {
|
|
112
|
+
minWidth: '10px',
|
|
113
|
+
padding: theme.spacing(0.25),
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
'& sup': {
|
|
117
|
+
top: 0,
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
}));
|
|
121
|
+
|
|
122
|
+
const StyledStatic: any = styled(mq.Static)({
|
|
123
|
+
'& > .mq-root-block': {
|
|
124
|
+
'& > .mq-editable-field': {
|
|
125
|
+
borderColor: color.text(),
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
// Tooltip styling is handled via slotProps, no need for styled component
|
|
131
|
+
|
|
132
|
+
const ResponseContainer: any = styled('div')(({ theme }) => ({
|
|
133
|
+
zIndex: 10,
|
|
134
|
+
minWidth: '400px',
|
|
135
|
+
marginTop: theme.spacing(2),
|
|
136
|
+
}));
|
|
137
|
+
|
|
138
|
+
const PrintContainer: any = styled('div')(({ theme }) => ({
|
|
139
|
+
marginBottom: theme.spacing(1),
|
|
140
|
+
pointerEvents: 'none',
|
|
141
|
+
}));
|
|
142
|
+
|
|
143
|
+
const SrOnly: any = styled('h2')({
|
|
144
|
+
position: 'absolute',
|
|
145
|
+
left: '-10000px',
|
|
146
|
+
top: 'auto',
|
|
147
|
+
width: '1px',
|
|
148
|
+
height: '1px',
|
|
149
|
+
overflow: 'hidden',
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
const Note: any = styled('div')(({ theme }) => ({
|
|
153
|
+
marginBottom: theme.spacing(2),
|
|
154
|
+
}));
|
|
155
|
+
|
|
156
|
+
const StyledToggle: any = styled(CorrectAnswerToggle)(({ theme }) => ({
|
|
157
|
+
color: color.text(),
|
|
158
|
+
marginBottom: theme.spacing(2),
|
|
159
|
+
}));
|
|
160
|
+
|
|
161
|
+
// CSS for classes used in HTML strings and classList operations
|
|
162
|
+
if (typeof document !== 'undefined') {
|
|
163
|
+
const styleId = 'math-templated-main-styles';
|
|
164
|
+
if (!document.getElementById(styleId)) {
|
|
165
|
+
const style = document.createElement('style');
|
|
166
|
+
style.id = styleId;
|
|
167
|
+
style.textContent = `
|
|
168
|
+
.block-container {
|
|
169
|
+
margin: 8px !important;
|
|
170
|
+
display: inline-flex;
|
|
171
|
+
border: 2px solid grey !important;
|
|
172
|
+
}
|
|
173
|
+
.block-response {
|
|
174
|
+
flex: 2;
|
|
175
|
+
color: grey;
|
|
176
|
+
background: rgba(0, 0, 0, 0.04);
|
|
177
|
+
font-size: 0.8rem !important;
|
|
178
|
+
padding: 4px !important;
|
|
179
|
+
display: flex;
|
|
180
|
+
align-items: center;
|
|
181
|
+
justify-content: center;
|
|
182
|
+
border-right: 2px solid #bdbdbd !important;
|
|
183
|
+
}
|
|
184
|
+
.block-math {
|
|
185
|
+
color: ${color.text()};
|
|
186
|
+
background-color: ${color.background()};
|
|
187
|
+
padding: 4px !important;
|
|
188
|
+
display: flex;
|
|
189
|
+
align-items: center;
|
|
190
|
+
justify-content: center;
|
|
191
|
+
flex: 8;
|
|
192
|
+
}
|
|
193
|
+
.block-math > .mq-math-mode > .mq-hasCursor > .mq-cursor {
|
|
194
|
+
display: none;
|
|
195
|
+
}
|
|
196
|
+
.correct {
|
|
197
|
+
border-color: ${color.correct()} !important;
|
|
198
|
+
}
|
|
199
|
+
.incorrect {
|
|
200
|
+
border-color: ${color.incorrect()} !important;
|
|
201
|
+
}
|
|
202
|
+
`;
|
|
203
|
+
document.head.appendChild(style);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// Define a regex pattern to match {{number}}
|
|
208
|
+
const REGEX = /(\{\{\d+\}\})/gm;
|
|
209
|
+
const DEFAULT_KEYPAD_VARIANT = 6;
|
|
210
|
+
let registered = false;
|
|
211
|
+
|
|
212
|
+
// !!! If you're using Chrome but have selected the "iPad" device in Chrome Developer Tools, the navigator.userAgent string may still report as
|
|
213
|
+
// Safari because Chrome on iOS actually uses the Safari rendering engine under the hood due to Apple's restrictions on third-party browser engines.
|
|
214
|
+
// When you select the "iPad" device in Chrome Developer Tools, you're essentially emulating the behavior of Safari on an iPad, including the user agent string.
|
|
215
|
+
// Therefore, even though you're using Chrome, the user agent string will resemble that of Safari on an iPad.
|
|
216
|
+
// Since the regular expression /^((?!chrome|android).)*safari/i checks for the presence of "safari" in the user agent string while excluding "chrome" and "android",
|
|
217
|
+
// it will return true in this case because "safari" is present in the user agent string emulated by Chrome when in iPad mode.
|
|
218
|
+
const IS_SAFARI = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
|
|
219
|
+
|
|
220
|
+
function generateAdditionalKeys(keyData = []) {
|
|
221
|
+
const normalizeKeyLatex = (value = '') => value.replace(/\$\$/g, '').replace(/^\$|\$$/g, '').trim();
|
|
222
|
+
return keyData.map((key) => ({
|
|
223
|
+
name: key,
|
|
224
|
+
latex: normalizeKeyLatex(key),
|
|
225
|
+
write: normalizeKeyLatex(key),
|
|
226
|
+
label: normalizeKeyLatex(key),
|
|
227
|
+
}));
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
function getKeyPadWidth(additionalKeys = [], equationEditor) {
|
|
231
|
+
return Math.floor(additionalKeys.length / 5) * 30 + (equationEditor === 'miscellaneous' ? 600 : 500);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
function splitByParts(text) {
|
|
235
|
+
// Use the regex pattern to split the text
|
|
236
|
+
const parts = text.split(REGEX);
|
|
237
|
+
// Filter out empty strings that might result from splitting
|
|
238
|
+
return parts.filter((part) => part);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
function prepareForStatic(model, state) {
|
|
242
|
+
const { responses, disabled, markup, printMode, alwaysShowCorrect } = model || {};
|
|
243
|
+
|
|
244
|
+
if (markup) {
|
|
245
|
+
if (state.showCorrect) {
|
|
246
|
+
return Object.keys(responses || {}).reduce((acc, responseKey) => {
|
|
247
|
+
acc[responseKey] = responses?.[responseKey]?.answer;
|
|
248
|
+
|
|
249
|
+
return acc;
|
|
250
|
+
}, {});
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
const splitted = splitByParts(markup);
|
|
254
|
+
|
|
255
|
+
return splitted.reduce((acc, split) => {
|
|
256
|
+
if (split.match(REGEX)) {
|
|
257
|
+
const responseKey = Main.getResponseKey(split);
|
|
258
|
+
const answer = state.session.answers[`r${responseKey}`];
|
|
259
|
+
|
|
260
|
+
if (printMode && !alwaysShowCorrect) {
|
|
261
|
+
const blankSpace = '\\ \\ '.repeat(30) + '\\embed{newLine}[] ';
|
|
262
|
+
|
|
263
|
+
return {
|
|
264
|
+
...acc,
|
|
265
|
+
[responseKey]: `\\MathQuillMathField[r${responseKey}]{${blankSpace.repeat(3)}}`,
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
if (disabled) {
|
|
270
|
+
return {
|
|
271
|
+
...acc,
|
|
272
|
+
[responseKey]: `\\embed{answerBlock}[r${responseKey}]`,
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
return {
|
|
277
|
+
...acc,
|
|
278
|
+
[responseKey]: `\\MathQuillMathField[r${responseKey}]{${(answer && answer.value) || ''}}`,
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
return acc;
|
|
283
|
+
}, {});
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
export class Main extends React.Component {
|
|
288
|
+
// removes {{ and }} and returns only key response. Eg: {{0}} => 0
|
|
289
|
+
static getResponseKey = (response) => (response || '').replaceAll('{{', '').replaceAll('}}', '');
|
|
290
|
+
|
|
291
|
+
static propTypes = {
|
|
292
|
+
session: PropTypes.object.isRequired,
|
|
293
|
+
onSessionChange: PropTypes.func,
|
|
294
|
+
model: PropTypes.object.isRequired,
|
|
295
|
+
};
|
|
296
|
+
|
|
297
|
+
constructor(props) {
|
|
298
|
+
super(props);
|
|
299
|
+
|
|
300
|
+
const answers = {};
|
|
301
|
+
const { model, session } = props || {};
|
|
302
|
+
const { markup, alwaysShowCorrect } = model || {};
|
|
303
|
+
const { answers: sessionAnswers } = session || {};
|
|
304
|
+
|
|
305
|
+
if (markup) {
|
|
306
|
+
// build out local state model using responses declared in markup
|
|
307
|
+
(markup || '').replace(REGEX, (response) => {
|
|
308
|
+
const responseKey = Main.getResponseKey(response);
|
|
309
|
+
const sessionAnswerForResponse = sessionAnswers && sessionAnswers[`r${responseKey}`];
|
|
310
|
+
|
|
311
|
+
answers[`r${responseKey}`] = { value: sessionAnswerForResponse?.value || '' };
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
this.state = {
|
|
316
|
+
session: { ...props.session, answers },
|
|
317
|
+
activeAnswerBlock: '',
|
|
318
|
+
showCorrect: alwaysShowCorrect || false,
|
|
319
|
+
tooltipContainerRef: React.createRef(),
|
|
320
|
+
};
|
|
321
|
+
|
|
322
|
+
if (typeof window !== 'undefined' && !registered) {
|
|
323
|
+
const MQ = MathQuill.getInterface(2);
|
|
324
|
+
MQ.registerEmbed('answerBlock', (data) => ({
|
|
325
|
+
htmlString: `<div class="block-container">
|
|
326
|
+
<div class="block-response" id="${data}Index">R</div>
|
|
327
|
+
<div class="block-math">
|
|
328
|
+
<span id="${data}"></span>
|
|
329
|
+
</div>
|
|
330
|
+
</div>`,
|
|
331
|
+
text: () => 'text',
|
|
332
|
+
latex: () => `\\embed{answerBlock}[${data}]`,
|
|
333
|
+
}));
|
|
334
|
+
registered = true;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
handleAnswerBlockDomUpdate: any = () => {
|
|
339
|
+
const { model } = this.props;
|
|
340
|
+
const { session, showCorrect } = this.state;
|
|
341
|
+
const answers = session.answers;
|
|
342
|
+
|
|
343
|
+
if (this.root && model.disabled && !showCorrect) {
|
|
344
|
+
Object.keys(answers).forEach((answerId) => {
|
|
345
|
+
const el = this.root.querySelector(`#${answerId}`);
|
|
346
|
+
const indexEl = this.root.querySelector(`#${answerId}Index`);
|
|
347
|
+
|
|
348
|
+
if (el) {
|
|
349
|
+
let MQ = MathQuill.getInterface(2);
|
|
350
|
+
const answer = answers[answerId];
|
|
351
|
+
|
|
352
|
+
el.textContent = (answer && answer.value) || '';
|
|
353
|
+
|
|
354
|
+
if (model.view) {
|
|
355
|
+
el.parentElement.parentElement.classList.remove('correct');
|
|
356
|
+
el.parentElement.parentElement.classList.remove('incorrect');
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
MQ.StaticMath(el);
|
|
360
|
+
indexEl.textContent = 'R';
|
|
361
|
+
}
|
|
362
|
+
});
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
if (this.root) {
|
|
366
|
+
renderMath(this.root);
|
|
367
|
+
}
|
|
368
|
+
};
|
|
369
|
+
|
|
370
|
+
UNSAFE_componentWillReceiveProps(nextProps) {
|
|
371
|
+
const { model } = this.props;
|
|
372
|
+
const { model: nextModel = {} } = nextProps || {};
|
|
373
|
+
const { markup = '', env = {} } = model || {};
|
|
374
|
+
const { markup: nextMarkup = '', env: nextEnv = {}, alwaysShowCorrect: nextAlwaysShowCorrect = false } = nextModel;
|
|
375
|
+
|
|
376
|
+
const isEvaluateMode = (env) => env && env.mode === 'evaluate';
|
|
377
|
+
|
|
378
|
+
if (!isEvaluateMode(env) || !isEvaluateMode(nextEnv)) {
|
|
379
|
+
this.setState((prevState) => ({ ...prevState.session, showCorrect: false }));
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
if (nextAlwaysShowCorrect) {
|
|
383
|
+
this.setState({ showCorrect: true });
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
const matches = markup.match(REGEX);
|
|
387
|
+
const nextMatches = nextMarkup.match(REGEX);
|
|
388
|
+
|
|
389
|
+
// If markup changed, and we no longer have the same response area, the session needs to be updated
|
|
390
|
+
if (!isEqual(matches, nextMatches)) {
|
|
391
|
+
const newAnswers = {};
|
|
392
|
+
const answers = this.state.session.answers;
|
|
393
|
+
|
|
394
|
+
(nextMatches || []).forEach((nextMatch) => {
|
|
395
|
+
const responseKey = Main.getResponseKey(nextMatch);
|
|
396
|
+
const sessionAnswerForResponse = answers && answers[`r${responseKey}`];
|
|
397
|
+
|
|
398
|
+
// build out local state model using responses declared in markup
|
|
399
|
+
newAnswers[`r${responseKey}`] = { value: sessionAnswerForResponse?.value || '' };
|
|
400
|
+
});
|
|
401
|
+
|
|
402
|
+
this.setState(
|
|
403
|
+
(state) => ({
|
|
404
|
+
session: {
|
|
405
|
+
...state.session,
|
|
406
|
+
answers: newAnswers,
|
|
407
|
+
},
|
|
408
|
+
}),
|
|
409
|
+
() => {
|
|
410
|
+
this.props.onSessionChange(this.state.session);
|
|
411
|
+
this.handleAnswerBlockDomUpdate();
|
|
412
|
+
},
|
|
413
|
+
);
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
shouldComponentUpdate(nextProps, nextState) {
|
|
418
|
+
const sameModel = isEqual(this.props.model, nextProps.model);
|
|
419
|
+
const sameState = isEqual(this.state, nextState);
|
|
420
|
+
|
|
421
|
+
return !sameModel || !sameState;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
componentDidMount() {
|
|
425
|
+
this.handleAnswerBlockDomUpdate();
|
|
426
|
+
setTimeout(() => renderMath(this.root), 100);
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
componentDidUpdate() {
|
|
430
|
+
this.handleAnswerBlockDomUpdate();
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
onSubFieldFocus: any = (id) => {
|
|
434
|
+
this.setState({ activeAnswerBlock: id });
|
|
435
|
+
};
|
|
436
|
+
|
|
437
|
+
toNodeData: any = (data) => {
|
|
438
|
+
if (!data) {
|
|
439
|
+
return;
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
const { type, value } = data;
|
|
443
|
+
|
|
444
|
+
if (type === 'command' || type === 'cursor') return data;
|
|
445
|
+
|
|
446
|
+
if (type === 'answer') return { type: 'answer', ...data };
|
|
447
|
+
|
|
448
|
+
if (value === 'clear') return { type: 'clear' };
|
|
449
|
+
|
|
450
|
+
return { type: 'write', value };
|
|
451
|
+
};
|
|
452
|
+
|
|
453
|
+
setInput: any = (input) => {
|
|
454
|
+
this.input = input;
|
|
455
|
+
};
|
|
456
|
+
|
|
457
|
+
onClick: any = (data) => {
|
|
458
|
+
const c = this.toNodeData(data);
|
|
459
|
+
|
|
460
|
+
if (c.type === 'clear') {
|
|
461
|
+
this.input.clear();
|
|
462
|
+
} else if (c.type === 'command') {
|
|
463
|
+
if (Array.isArray(c.value)) {
|
|
464
|
+
c.value.forEach((vv) => {
|
|
465
|
+
this.input.cmd(vv);
|
|
466
|
+
});
|
|
467
|
+
} else {
|
|
468
|
+
this.input.cmd(c.value);
|
|
469
|
+
}
|
|
470
|
+
} else if (c.type === 'cursor') {
|
|
471
|
+
this.input.keystroke(c.value);
|
|
472
|
+
} else {
|
|
473
|
+
this.input.write(c.value);
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
this.input.focus();
|
|
477
|
+
};
|
|
478
|
+
|
|
479
|
+
callOnSessionChange: any = () => {
|
|
480
|
+
const { onSessionChange } = this.props;
|
|
481
|
+
|
|
482
|
+
if (onSessionChange) {
|
|
483
|
+
onSessionChange(this.state.session);
|
|
484
|
+
}
|
|
485
|
+
};
|
|
486
|
+
|
|
487
|
+
toggleShowCorrect: any = (show) => {
|
|
488
|
+
this.setState({ showCorrect: show }, this.handleAnswerBlockDomUpdate);
|
|
489
|
+
};
|
|
490
|
+
|
|
491
|
+
subFieldChanged: any = (name, subfieldValue) => {
|
|
492
|
+
updateSpans();
|
|
493
|
+
|
|
494
|
+
if (name) {
|
|
495
|
+
this.setState(
|
|
496
|
+
(state) => ({
|
|
497
|
+
session: {
|
|
498
|
+
...state.session,
|
|
499
|
+
answers: {
|
|
500
|
+
...state.session.answers,
|
|
501
|
+
[name]: { value: subfieldValue },
|
|
502
|
+
},
|
|
503
|
+
},
|
|
504
|
+
}),
|
|
505
|
+
this.callOnSessionChange,
|
|
506
|
+
);
|
|
507
|
+
}
|
|
508
|
+
};
|
|
509
|
+
|
|
510
|
+
getFieldName: any = (changeField, fields) => {
|
|
511
|
+
const { answers } = this.state.session;
|
|
512
|
+
|
|
513
|
+
if (Object.keys(answers || {}).length) {
|
|
514
|
+
const keys = Object.keys(answers);
|
|
515
|
+
|
|
516
|
+
return keys.find((k) => {
|
|
517
|
+
const tf = fields[k];
|
|
518
|
+
|
|
519
|
+
return tf && tf.id == changeField.id;
|
|
520
|
+
});
|
|
521
|
+
}
|
|
522
|
+
};
|
|
523
|
+
|
|
524
|
+
onBlur: any = (e) => {
|
|
525
|
+
const { relatedTarget, currentTarget } = e || {};
|
|
526
|
+
|
|
527
|
+
function getParentWithRoleTooltip(element, depth = 0) {
|
|
528
|
+
// only run this max 16 times
|
|
529
|
+
if (!element || depth >= 16) return null;
|
|
530
|
+
|
|
531
|
+
const parent = element.offsetParent;
|
|
532
|
+
|
|
533
|
+
if (!parent) return null;
|
|
534
|
+
|
|
535
|
+
if (parent.getAttribute('role') === 'tooltip') {
|
|
536
|
+
return parent;
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
return getParentWithRoleTooltip(parent, depth + 1);
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
function getDeepChildDataKeypad(element, depth = 0) {
|
|
543
|
+
// only run this max 4 times
|
|
544
|
+
if (!element || depth >= 4) return null;
|
|
545
|
+
|
|
546
|
+
const child = element?.children?.[0];
|
|
547
|
+
|
|
548
|
+
if (!child) return null;
|
|
549
|
+
|
|
550
|
+
if (child.attributes && child.attributes['data-keypad']) {
|
|
551
|
+
return child;
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
return getDeepChildDataKeypad(child, depth + 1);
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
const parentWithTooltipRole = getParentWithRoleTooltip(relatedTarget);
|
|
558
|
+
const childWithDataKeypad = parentWithTooltipRole ? getDeepChildDataKeypad(parentWithTooltipRole) : null;
|
|
559
|
+
|
|
560
|
+
if (!relatedTarget || !currentTarget || !childWithDataKeypad?.attributes['data-keypad']) {
|
|
561
|
+
this.setState({ activeAnswerBlock: '' });
|
|
562
|
+
}
|
|
563
|
+
};
|
|
564
|
+
|
|
565
|
+
// function for tooltip
|
|
566
|
+
setTooltipRef(ref) {
|
|
567
|
+
// Safari Hack: https://stackoverflow.com/a/42764495/5757635
|
|
568
|
+
setTimeout(() => {
|
|
569
|
+
if (ref && IS_SAFARI) {
|
|
570
|
+
const div = document.querySelector("[role='tooltip']");
|
|
571
|
+
|
|
572
|
+
if (div) {
|
|
573
|
+
const el = div.firstChild;
|
|
574
|
+
el.setAttribute('tabindex', '-1');
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
}, 1);
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
renderTeacherInstructions: any = () => {
|
|
581
|
+
const { model } = this.props;
|
|
582
|
+
const { teacherInstructions, animationsDisabled } = model || {};
|
|
583
|
+
const showTeacherInstructions =
|
|
584
|
+
teacherInstructions && (hasText(teacherInstructions) || hasMedia(teacherInstructions));
|
|
585
|
+
|
|
586
|
+
const teacherInstructionsDiv = (
|
|
587
|
+
<PreviewPrompt defaultClassName="teacher-instructions" prompt={teacherInstructions} />
|
|
588
|
+
);
|
|
589
|
+
|
|
590
|
+
return (
|
|
591
|
+
showTeacherInstructions && (
|
|
592
|
+
<CollapsibleContainer>
|
|
593
|
+
{!animationsDisabled ? (
|
|
594
|
+
<Collapsible labels={{ hidden: 'Show Teacher Instructions', visible: 'Hide Teacher Instructions' }}>
|
|
595
|
+
{teacherInstructionsDiv}
|
|
596
|
+
</Collapsible>
|
|
597
|
+
) : (
|
|
598
|
+
teacherInstructionsDiv
|
|
599
|
+
)}
|
|
600
|
+
</CollapsibleContainer>
|
|
601
|
+
)
|
|
602
|
+
);
|
|
603
|
+
};
|
|
604
|
+
|
|
605
|
+
renderRationale: any = () => {
|
|
606
|
+
const { model } = this.props;
|
|
607
|
+
const { rationale, animationsDisabled } = model || {};
|
|
608
|
+
const rationaleDiv = <PreviewPrompt prompt={rationale} />;
|
|
609
|
+
const showRationale = rationale && (hasText(rationale) || hasMedia(rationale));
|
|
610
|
+
|
|
611
|
+
return (
|
|
612
|
+
showRationale && (
|
|
613
|
+
<CollapsibleContainer>
|
|
614
|
+
{!animationsDisabled ? (
|
|
615
|
+
<Collapsible labels={{ hidden: 'Show Rationale', visible: 'Hide Rationale' }}>{rationaleDiv}</Collapsible>
|
|
616
|
+
) : (
|
|
617
|
+
rationaleDiv
|
|
618
|
+
)}
|
|
619
|
+
</CollapsibleContainer>
|
|
620
|
+
)
|
|
621
|
+
);
|
|
622
|
+
};
|
|
623
|
+
|
|
624
|
+
renderPlayerContent: any = () => {
|
|
625
|
+
const { model } = this.props;
|
|
626
|
+
const { activeAnswerBlock, showCorrect, session, tooltipContainerRef } = this.state;
|
|
627
|
+
const {
|
|
628
|
+
correctness,
|
|
629
|
+
disabled,
|
|
630
|
+
view,
|
|
631
|
+
responses,
|
|
632
|
+
equationEditor,
|
|
633
|
+
customKeys,
|
|
634
|
+
feedback,
|
|
635
|
+
env: { mode } = {},
|
|
636
|
+
printMode,
|
|
637
|
+
alwaysShowCorrect,
|
|
638
|
+
} = model || {};
|
|
639
|
+
|
|
640
|
+
const emptyResponse = isEmpty(responses);
|
|
641
|
+
const additionalKeys = generateAdditionalKeys(customKeys);
|
|
642
|
+
const statics = prepareForStatic(model, this.state) || '';
|
|
643
|
+
const studentPrintMode = printMode && !alwaysShowCorrect;
|
|
644
|
+
|
|
645
|
+
return (
|
|
646
|
+
<InputAndKeypadContainer>
|
|
647
|
+
<Customizable
|
|
648
|
+
disabled={disabled}
|
|
649
|
+
markup={model.markup}
|
|
650
|
+
// TODO remove the need of value?
|
|
651
|
+
value={{}}
|
|
652
|
+
customMarkMarkupComponent={(id) => {
|
|
653
|
+
const responseIsCorrect = mode === 'evaluate' && feedback && feedback[id];
|
|
654
|
+
|
|
655
|
+
const MQStatic = (
|
|
656
|
+
<StyledStatic
|
|
657
|
+
ref={(mqStatic) => {
|
|
658
|
+
this.mqStatic = mqStatic || this.mqStatic;
|
|
659
|
+
}}
|
|
660
|
+
latex={statics[id]}
|
|
661
|
+
onSubFieldChange={this.subFieldChanged}
|
|
662
|
+
getFieldName={this.getFieldName}
|
|
663
|
+
setInput={this.setInput}
|
|
664
|
+
onSubFieldFocus={this.onSubFieldFocus}
|
|
665
|
+
onBlur={this.onBlur}
|
|
666
|
+
/>
|
|
667
|
+
);
|
|
668
|
+
|
|
669
|
+
return (
|
|
670
|
+
<Expression
|
|
671
|
+
ref={tooltipContainerRef}
|
|
672
|
+
$incorrect={!emptyResponse && !responseIsCorrect && !showCorrect}
|
|
673
|
+
$correct={!emptyResponse && (responseIsCorrect || showCorrect)}
|
|
674
|
+
$showCorrectness={!emptyResponse && disabled && correctness && !view}
|
|
675
|
+
$correctAnswerShown={showCorrect}
|
|
676
|
+
>
|
|
677
|
+
<Tooltip
|
|
678
|
+
ref={(ref) => this.setTooltipRef(ref)}
|
|
679
|
+
enterTouchDelay={0}
|
|
680
|
+
interactive
|
|
681
|
+
open={activeAnswerBlock === `r${id}`}
|
|
682
|
+
slotProps={{
|
|
683
|
+
popper: {
|
|
684
|
+
container: tooltipContainerRef?.current || undefined,
|
|
685
|
+
placement: 'bottom-end',
|
|
686
|
+
sx: {
|
|
687
|
+
backgroundColor: 'transparent',
|
|
688
|
+
width: '650px',
|
|
689
|
+
opacity: 1,
|
|
690
|
+
'& .MuiTooltip-arrow': {
|
|
691
|
+
display: 'none',
|
|
692
|
+
},
|
|
693
|
+
},
|
|
694
|
+
modifiers: {
|
|
695
|
+
preventOverflow: {
|
|
696
|
+
enabled: true,
|
|
697
|
+
boundariesElement: 'body',
|
|
698
|
+
},
|
|
699
|
+
flip: {
|
|
700
|
+
enabled: false,
|
|
701
|
+
},
|
|
702
|
+
},
|
|
703
|
+
},
|
|
704
|
+
tooltip: {
|
|
705
|
+
sx: {
|
|
706
|
+
fontSize: 'initial',
|
|
707
|
+
backgroundColor: 'transparent',
|
|
708
|
+
width: '600px',
|
|
709
|
+
marginTop: 0,
|
|
710
|
+
paddingTop: 0,
|
|
711
|
+
boxShadow: 'none',
|
|
712
|
+
},
|
|
713
|
+
},
|
|
714
|
+
}}
|
|
715
|
+
title={Object.keys(session.answers).map(
|
|
716
|
+
(answerId) =>
|
|
717
|
+
(answerId === activeAnswerBlock && !(showCorrect || disabled) && (
|
|
718
|
+
<ResponseContainer
|
|
719
|
+
data-keypad={true}
|
|
720
|
+
key={answerId}
|
|
721
|
+
style={{ width: getKeyPadWidth(additionalKeys, equationEditor) }}
|
|
722
|
+
>
|
|
723
|
+
<HorizontalKeypad
|
|
724
|
+
additionalKeys={additionalKeys}
|
|
725
|
+
mode={equationEditor || DEFAULT_KEYPAD_VARIANT}
|
|
726
|
+
onClick={this.onClick}
|
|
727
|
+
onRequestClose={() => this.setState({ activeAnswerBlock: '' })}
|
|
728
|
+
/>
|
|
729
|
+
</ResponseContainer>
|
|
730
|
+
)) ||
|
|
731
|
+
null,
|
|
732
|
+
)}
|
|
733
|
+
>
|
|
734
|
+
{studentPrintMode ? <PrintContainer>{MQStatic}</PrintContainer> : <div>{MQStatic}</div>}
|
|
735
|
+
</Tooltip>
|
|
736
|
+
</Expression>
|
|
737
|
+
);
|
|
738
|
+
}}
|
|
739
|
+
/>
|
|
740
|
+
</InputAndKeypadContainer>
|
|
741
|
+
);
|
|
742
|
+
};
|
|
743
|
+
|
|
744
|
+
render() {
|
|
745
|
+
const { model } = this.props;
|
|
746
|
+
const { showCorrect } = this.state;
|
|
747
|
+
const {
|
|
748
|
+
prompt,
|
|
749
|
+
env: { mode, role } = {},
|
|
750
|
+
extraCSSRules,
|
|
751
|
+
correctness,
|
|
752
|
+
responses,
|
|
753
|
+
language,
|
|
754
|
+
showNote,
|
|
755
|
+
note,
|
|
756
|
+
} = model || {};
|
|
757
|
+
const emptyResponse = isEmpty(responses);
|
|
758
|
+
const showCorrectAnswerToggle = !emptyResponse && correctness && correctness.correctness !== 'correct';
|
|
759
|
+
const displayNote = (showCorrect || (mode === 'view' && role === 'instructor')) && showNote && note;
|
|
760
|
+
|
|
761
|
+
return (
|
|
762
|
+
<StyledUiLayout
|
|
763
|
+
extraCSSRules={extraCSSRules}
|
|
764
|
+
ref={(r) => {
|
|
765
|
+
// eslint-disable-next-line react/no-find-dom-node
|
|
766
|
+
const domNode = ReactDOM.findDOMNode(r);
|
|
767
|
+
|
|
768
|
+
this.root = domNode || this.root;
|
|
769
|
+
}}
|
|
770
|
+
>
|
|
771
|
+
<MainContainer>
|
|
772
|
+
{/* what is srOnly ? */}
|
|
773
|
+
{mode === 'gather' && <SrOnly>Math Equation Response Question</SrOnly>}
|
|
774
|
+
|
|
775
|
+
<MainContainer>
|
|
776
|
+
{showCorrectAnswerToggle && (
|
|
777
|
+
<StyledToggle language={language} show toggled={showCorrect} onToggle={this.toggleShowCorrect} />
|
|
778
|
+
)}
|
|
779
|
+
</MainContainer>
|
|
780
|
+
|
|
781
|
+
{this.renderTeacherInstructions()}
|
|
782
|
+
|
|
783
|
+
{prompt && (
|
|
784
|
+
<PromptContainer>
|
|
785
|
+
<PreviewPrompt prompt={prompt} />
|
|
786
|
+
</PromptContainer>
|
|
787
|
+
)}
|
|
788
|
+
|
|
789
|
+
<Readable false>{this.renderPlayerContent()}</Readable>
|
|
790
|
+
|
|
791
|
+
{displayNote && <Note className="note" dangerouslySetInnerHTML={{ __html: note }} />}
|
|
792
|
+
|
|
793
|
+
{this.renderRationale()}
|
|
794
|
+
</MainContainer>
|
|
795
|
+
</StyledUiLayout>
|
|
796
|
+
);
|
|
797
|
+
}
|
|
798
|
+
}
|
|
799
|
+
|
|
800
|
+
export default Main;
|