@pie-element/categorize 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 +224 -0
- package/dist/author/defaults.d.ts.map +1 -0
- package/dist/author/defaults.js +170 -0
- package/dist/author/design/builder.d.ts +11 -0
- package/dist/author/design/builder.d.ts.map +1 -0
- package/dist/author/design/builder.js +24 -0
- package/dist/author/design/buttons.d.ts +29 -0
- package/dist/author/design/buttons.d.ts.map +1 -0
- package/dist/author/design/buttons.js +36 -0
- package/dist/author/design/categories/RowLabel.d.ts +24 -0
- package/dist/author/design/categories/RowLabel.d.ts.map +1 -0
- package/dist/author/design/categories/RowLabel.js +46 -0
- package/dist/author/design/categories/alternateResponses.d.ts +32 -0
- package/dist/author/design/categories/alternateResponses.d.ts.map +1 -0
- package/dist/author/design/categories/alternateResponses.js +62 -0
- package/dist/author/design/categories/category.d.ts +45 -0
- package/dist/author/design/categories/category.d.ts.map +1 -0
- package/dist/author/design/categories/category.js +102 -0
- package/dist/author/design/categories/choice-preview.d.ts +26 -0
- package/dist/author/design/categories/choice-preview.d.ts.map +1 -0
- package/dist/author/design/categories/choice-preview.js +60 -0
- package/dist/author/design/categories/droppable-placeholder.d.ts +11 -0
- package/dist/author/design/categories/droppable-placeholder.d.ts.map +1 -0
- package/dist/author/design/categories/droppable-placeholder.js +70 -0
- package/dist/author/design/categories/index.d.ts +42 -0
- package/dist/author/design/categories/index.d.ts.map +1 -0
- package/dist/author/design/categories/index.js +146 -0
- package/dist/author/design/choices/choice.d.ts +11 -0
- package/dist/author/design/choices/choice.d.ts.map +1 -0
- package/dist/author/design/choices/choice.js +129 -0
- package/dist/author/design/choices/config.d.ts +22 -0
- package/dist/author/design/choices/config.d.ts.map +1 -0
- package/dist/author/design/choices/config.js +33 -0
- package/dist/author/design/choices/index.d.ts +42 -0
- package/dist/author/design/choices/index.d.ts.map +1 -0
- package/dist/author/design/choices/index.js +110 -0
- package/dist/author/design/header.d.ts +25 -0
- package/dist/author/design/header.d.ts.map +1 -0
- package/dist/author/design/header.js +49 -0
- package/dist/author/design/index.d.ts +53 -0
- package/dist/author/design/index.d.ts.map +1 -0
- package/dist/author/design/index.js +410 -0
- package/dist/author/design/input-header.d.ts +40 -0
- package/dist/author/design/input-header.d.ts.map +1 -0
- package/dist/author/design/input-header.js +69 -0
- package/dist/author/design/utils.d.ts +10 -0
- package/dist/author/design/utils.d.ts.map +1 -0
- package/dist/author/design/utils.js +7 -0
- package/dist/author/index.d.ts +52 -0
- package/dist/author/index.d.ts.map +1 -0
- package/dist/author/index.js +87 -0
- package/dist/author/main.d.ts +24 -0
- package/dist/author/main.d.ts.map +1 -0
- package/dist/author/main.js +30 -0
- package/dist/author/utils.d.ts +17 -0
- package/dist/author/utils.d.ts.map +1 -0
- package/dist/author/utils.js +17 -0
- package/dist/controller/defaults.d.ts +35 -0
- package/dist/controller/defaults.d.ts.map +1 -0
- package/dist/controller/defaults.js +29 -0
- package/dist/controller/index.d.ts +62 -0
- package/dist/controller/index.d.ts.map +1 -0
- package/dist/controller/index.js +155 -0
- package/dist/controller/utils.d.ts +21 -0
- package/dist/controller/utils.d.ts.map +1 -0
- package/dist/controller/utils.js +35 -0
- package/dist/delivery/categorize/categories.d.ts +35 -0
- package/dist/delivery/categorize/categories.d.ts.map +1 -0
- package/dist/delivery/categorize/categories.js +66 -0
- package/dist/delivery/categorize/category.d.ts +29 -0
- package/dist/delivery/categorize/category.d.ts.map +1 -0
- package/dist/delivery/categorize/category.js +48 -0
- package/dist/delivery/categorize/choice.d.ts +28 -0
- package/dist/delivery/categorize/choice.d.ts.map +1 -0
- package/dist/delivery/categorize/choice.js +94 -0
- package/dist/delivery/categorize/choices.d.ts +40 -0
- package/dist/delivery/categorize/choices.d.ts.map +1 -0
- package/dist/delivery/categorize/choices.js +51 -0
- package/dist/delivery/categorize/droppable-placeholder.d.ts +33 -0
- package/dist/delivery/categorize/droppable-placeholder.d.ts.map +1 -0
- package/dist/delivery/categorize/droppable-placeholder.js +64 -0
- package/dist/delivery/categorize/grid-content.d.ts +26 -0
- package/dist/delivery/categorize/grid-content.d.ts.map +1 -0
- package/dist/delivery/categorize/grid-content.js +39 -0
- package/dist/delivery/categorize/index.d.ts +58 -0
- package/dist/delivery/categorize/index.d.ts.map +1 -0
- package/dist/delivery/categorize/index.js +260 -0
- package/dist/delivery/index.d.ts +28 -0
- package/dist/delivery/index.d.ts.map +1 -0
- package/dist/delivery/index.js +152 -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 +152 -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/_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/_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/_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/_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/_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/_baseTimes.js +7 -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/_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/_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/_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/_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/_root.js +5 -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/cloneDeep.js +8 -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/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/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/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/stubArray.js +6 -0
- package/dist/node_modules/.bun/lodash-es@4.17.23/node_modules/lodash-es/stubFalse.js +6 -0
- package/package.json +74 -0
- package/src/author/defaults.ts +182 -0
- package/src/author/design/builder.ts +63 -0
- package/src/author/design/buttons.tsx +60 -0
- package/src/author/design/categories/RowLabel.tsx +91 -0
- package/src/author/design/categories/alternateResponses.tsx +127 -0
- package/src/author/design/categories/category.tsx +161 -0
- package/src/author/design/categories/choice-preview.tsx +112 -0
- package/src/author/design/categories/droppable-placeholder.tsx +114 -0
- package/src/author/design/categories/index.tsx +254 -0
- package/src/author/design/choices/choice.tsx +200 -0
- package/src/author/design/choices/config.tsx +58 -0
- package/src/author/design/choices/index.tsx +185 -0
- package/src/author/design/header.tsx +74 -0
- package/src/author/design/index.tsx +764 -0
- package/src/author/design/input-header.tsx +109 -0
- package/src/author/design/utils.ts +14 -0
- package/src/author/index.ts +171 -0
- package/src/author/main.tsx +45 -0
- package/src/author/utils.ts +46 -0
- package/src/controller/defaults.ts +37 -0
- package/src/controller/index.ts +469 -0
- package/src/controller/utils.ts +79 -0
- package/src/delivery/categorize/categories.tsx +139 -0
- package/src/delivery/categorize/category.tsx +78 -0
- package/src/delivery/categorize/choice.tsx +117 -0
- package/src/delivery/categorize/choices.tsx +95 -0
- package/src/delivery/categorize/droppable-placeholder.tsx +95 -0
- package/src/delivery/categorize/grid-content.tsx +53 -0
- package/src/delivery/categorize/index.tsx +515 -0
- package/src/delivery/index.ts +390 -0
- package/src/index.iife.ts +16 -0
- package/src/index.ts +1 -0
|
@@ -0,0 +1,515 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/**
|
|
3
|
+
* @synced-from pie-elements/packages/categorize/src/categorize/index.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 debug from 'debug';
|
|
14
|
+
import { styled } from '@mui/material/styles';
|
|
15
|
+
import { DragOverlay } from '@dnd-kit/core';
|
|
16
|
+
import CorrectAnswerToggle from '@pie-lib/correct-answer-toggle';
|
|
17
|
+
import { buildState, removeChoiceFromCategory, moveChoiceToCategory } from '@pie-lib/categorize';
|
|
18
|
+
import { DragProvider, uid } from '@pie-lib/drag';
|
|
19
|
+
import { color, Feedback as FeedbackImport, Collapsible as CollapsibleImport, hasText, hasMedia, PreviewPrompt as PreviewPromptImport, UiLayout as UiLayoutImport } from '@pie-lib/render-ui';
|
|
20
|
+
|
|
21
|
+
function isRenderableReactInteropType(value: any) {
|
|
22
|
+
return (
|
|
23
|
+
typeof value === 'function' ||
|
|
24
|
+
(typeof value === 'object' && value !== null && typeof value.$$typeof === 'symbol')
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function unwrapReactInteropSymbol(maybeSymbol: any, namedExport?: string) {
|
|
29
|
+
if (!maybeSymbol) return maybeSymbol;
|
|
30
|
+
if (isRenderableReactInteropType(maybeSymbol)) return maybeSymbol;
|
|
31
|
+
if (isRenderableReactInteropType(maybeSymbol.default)) return maybeSymbol.default;
|
|
32
|
+
if (namedExport && isRenderableReactInteropType(maybeSymbol[namedExport])) {
|
|
33
|
+
return maybeSymbol[namedExport];
|
|
34
|
+
}
|
|
35
|
+
if (namedExport && isRenderableReactInteropType(maybeSymbol[namedExport]?.default)) {
|
|
36
|
+
return maybeSymbol[namedExport].default;
|
|
37
|
+
}
|
|
38
|
+
return maybeSymbol;
|
|
39
|
+
}
|
|
40
|
+
const UiLayout = unwrapReactInteropSymbol(UiLayoutImport, 'UiLayout') || unwrapReactInteropSymbol(renderUi.UiLayout, 'UiLayout');
|
|
41
|
+
const PreviewPrompt = unwrapReactInteropSymbol(PreviewPromptImport, 'PreviewPrompt') || unwrapReactInteropSymbol(renderUi.PreviewPrompt, 'PreviewPrompt');
|
|
42
|
+
const Collapsible = unwrapReactInteropSymbol(CollapsibleImport, 'Collapsible') || unwrapReactInteropSymbol(renderUi.Collapsible, 'Collapsible');
|
|
43
|
+
const Feedback = unwrapReactInteropSymbol(FeedbackImport, 'Feedback') || unwrapReactInteropSymbol(renderUi.Feedback, 'Feedback');
|
|
44
|
+
import * as RenderUiNamespace from '@pie-lib/render-ui';
|
|
45
|
+
const renderUiNamespaceAny = RenderUiNamespace as any;
|
|
46
|
+
const renderUiDefaultMaybe = renderUiNamespaceAny['default'];
|
|
47
|
+
const renderUi =
|
|
48
|
+
renderUiDefaultMaybe && typeof renderUiDefaultMaybe === 'object'
|
|
49
|
+
? renderUiDefaultMaybe
|
|
50
|
+
: renderUiNamespaceAny;
|
|
51
|
+
import { renderMath } from '@pie-element/shared-math-rendering-mathjax';
|
|
52
|
+
import Translator from '@pie-lib/translator';
|
|
53
|
+
import { AlertDialog } from '@pie-lib/config-ui';
|
|
54
|
+
import Choices from './choices.js';
|
|
55
|
+
import Choice from './choice.js';
|
|
56
|
+
import Categories from './categories.js';
|
|
57
|
+
|
|
58
|
+
const { translator } = Translator;
|
|
59
|
+
const log = debug('@pie-ui:categorize');
|
|
60
|
+
|
|
61
|
+
class DragPreviewWrapper extends React.Component {
|
|
62
|
+
static propTypes = {
|
|
63
|
+
children: PropTypes.node,
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
containerRef = React.createRef();
|
|
67
|
+
|
|
68
|
+
componentDidMount() {
|
|
69
|
+
if (this.containerRef.current) {
|
|
70
|
+
renderMath(this.containerRef.current);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
render() {
|
|
75
|
+
return <div ref={this.containerRef}>{this.props.children}</div>;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export class Categorize extends React.Component {
|
|
80
|
+
static propTypes = {
|
|
81
|
+
model: PropTypes.object,
|
|
82
|
+
session: PropTypes.shape({
|
|
83
|
+
answers: PropTypes.arrayOf(
|
|
84
|
+
PropTypes.shape({
|
|
85
|
+
choice: PropTypes.string,
|
|
86
|
+
category: PropTypes.string,
|
|
87
|
+
}),
|
|
88
|
+
),
|
|
89
|
+
}),
|
|
90
|
+
onAnswersChange: PropTypes.func.isRequired,
|
|
91
|
+
onShowCorrectToggle: PropTypes.func.isRequired,
|
|
92
|
+
pauseMathObserver: PropTypes.func,
|
|
93
|
+
resumeMathObserver: PropTypes.func,
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
static defaultProps = {
|
|
97
|
+
disabled: false,
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
constructor(props) {
|
|
101
|
+
super(props);
|
|
102
|
+
|
|
103
|
+
this.state = {
|
|
104
|
+
showCorrect: false,
|
|
105
|
+
showMaxChoiceAlert: false,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
removeChoice: any = (c) => {
|
|
110
|
+
log('[removeChoice]: ', c);
|
|
111
|
+
const { onAnswersChange, session } = this.props;
|
|
112
|
+
const answers = removeChoiceFromCategory(c.id, c.categoryId, c.choiceIndex, session.answers);
|
|
113
|
+
onAnswersChange(answers);
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
dropChoice: any = (categoryId, draggedChoice) => {
|
|
117
|
+
const { session, onAnswersChange, model } = this.props;
|
|
118
|
+
const { maxChoicesPerCategory = 0 } = model || {};
|
|
119
|
+
const { answers = [] } = session || {};
|
|
120
|
+
let newAnswers;
|
|
121
|
+
if (draggedChoice) {
|
|
122
|
+
log('[dropChoice] category: ', draggedChoice.categoryId, 'choice: ', draggedChoice);
|
|
123
|
+
} else {
|
|
124
|
+
log('[dropChoice] category: ', undefined, 'choice: ', undefined);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const answer = answers.find((answer) => answer.category === categoryId);
|
|
128
|
+
|
|
129
|
+
// treat special case to replace the existing choice with the new one when maxChoicesPerCategory = 1
|
|
130
|
+
if (draggedChoice && maxChoicesPerCategory === 1 && answer && answer.choices && answer.choices.length === 1) {
|
|
131
|
+
// First, move the dragged choice to the target category (this will also remove it from source if allowMultiplePlacements is disabled)
|
|
132
|
+
newAnswers = moveChoiceToCategory(
|
|
133
|
+
draggedChoice.id,
|
|
134
|
+
draggedChoice.categoryId,
|
|
135
|
+
categoryId,
|
|
136
|
+
draggedChoice.choiceIndex,
|
|
137
|
+
answers,
|
|
138
|
+
);
|
|
139
|
+
// Then, remove the existing choice from the target category (use newAnswers, not answers)
|
|
140
|
+
newAnswers = removeChoiceFromCategory(answer.choices[0], categoryId, 0, newAnswers);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// treat special case when there are as many choices as maxChoicesPerCategory is
|
|
144
|
+
else if (
|
|
145
|
+
draggedChoice &&
|
|
146
|
+
maxChoicesPerCategory > 1 &&
|
|
147
|
+
answer &&
|
|
148
|
+
answer.choices &&
|
|
149
|
+
answer.choices.length === maxChoicesPerCategory
|
|
150
|
+
) {
|
|
151
|
+
newAnswers = draggedChoice.categoryId
|
|
152
|
+
? moveChoiceToCategory(
|
|
153
|
+
draggedChoice.id,
|
|
154
|
+
draggedChoice.categoryId,
|
|
155
|
+
draggedChoice.categoryId,
|
|
156
|
+
draggedChoice.choiceIndex,
|
|
157
|
+
answers,
|
|
158
|
+
)
|
|
159
|
+
: removeChoiceFromCategory(draggedChoice.id, draggedChoice.categoryId, draggedChoice.choiceIndex, answers);
|
|
160
|
+
this.setState({ showMaxChoiceAlert: true });
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// treat special case when there are more choices that maxChoicesPerCategory is (testing purpose in pits)
|
|
164
|
+
else if (maxChoicesPerCategory !== 0 && answer && answer.choices && answer.choices.length > maxChoicesPerCategory) {
|
|
165
|
+
newAnswers = answers;
|
|
166
|
+
this.setState({ showMaxChoiceAlert: true });
|
|
167
|
+
} else {
|
|
168
|
+
newAnswers = draggedChoice
|
|
169
|
+
? moveChoiceToCategory(
|
|
170
|
+
draggedChoice.id,
|
|
171
|
+
draggedChoice.categoryId,
|
|
172
|
+
categoryId,
|
|
173
|
+
draggedChoice.choiceIndex,
|
|
174
|
+
answers,
|
|
175
|
+
)
|
|
176
|
+
: this.removeChoice(categoryId);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
if (draggedChoice) {
|
|
180
|
+
onAnswersChange(newAnswers);
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
UNSAFE_componentWillReceiveProps(nextProps) {
|
|
185
|
+
const { model } = this.props;
|
|
186
|
+
const { model: nextModel } = nextProps;
|
|
187
|
+
|
|
188
|
+
// check if the note is the default one for prev language and change to the default one for new language
|
|
189
|
+
// this check is necessary in order to diferanciate between default and authour defined note
|
|
190
|
+
// and only change between languages for default ones
|
|
191
|
+
if (
|
|
192
|
+
model.note &&
|
|
193
|
+
model.language &&
|
|
194
|
+
model.language !== nextModel.language &&
|
|
195
|
+
model.note === translator.t('common:commonCorrectAnswerWithAlternates', { lng: model.language })
|
|
196
|
+
) {
|
|
197
|
+
model.note = translator.t('common:commonCorrectAnswerWithAlternates', { lng: nextModel.language });
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
this.setState({ showCorrect: false });
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
toggleShowCorrect = () =>
|
|
204
|
+
this.setState({ showCorrect: !this.state.showCorrect }, () => {
|
|
205
|
+
this.props.onShowCorrectToggle();
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
getPositionDirection: any = (choicePosition) => {
|
|
209
|
+
let flexDirection;
|
|
210
|
+
|
|
211
|
+
switch (choicePosition) {
|
|
212
|
+
case 'left':
|
|
213
|
+
flexDirection = 'row-reverse';
|
|
214
|
+
break;
|
|
215
|
+
case 'right':
|
|
216
|
+
flexDirection = 'row';
|
|
217
|
+
break;
|
|
218
|
+
case 'below':
|
|
219
|
+
flexDirection = 'column';
|
|
220
|
+
break;
|
|
221
|
+
default:
|
|
222
|
+
// above
|
|
223
|
+
flexDirection = 'column-reverse';
|
|
224
|
+
break;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
return flexDirection;
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
existAlternateResponse = (correctResponse) =>
|
|
231
|
+
correctResponse?.some((correctRes) => correctRes.alternateResponses?.length > 0);
|
|
232
|
+
|
|
233
|
+
render() {
|
|
234
|
+
const { model, session } = this.props;
|
|
235
|
+
const { showCorrect, showMaxChoiceAlert } = this.state;
|
|
236
|
+
const {
|
|
237
|
+
choicesPosition,
|
|
238
|
+
extraCSSRules,
|
|
239
|
+
note,
|
|
240
|
+
showNote,
|
|
241
|
+
env,
|
|
242
|
+
language,
|
|
243
|
+
maxChoicesPerCategory,
|
|
244
|
+
autoplayAudioEnabled,
|
|
245
|
+
customAudioButton,
|
|
246
|
+
} = model;
|
|
247
|
+
const { mode, role } = env || {};
|
|
248
|
+
const choicePosition = choicesPosition || 'above';
|
|
249
|
+
|
|
250
|
+
const style = {
|
|
251
|
+
flexDirection: this.getPositionDirection(choicePosition),
|
|
252
|
+
gap: '8px',
|
|
253
|
+
};
|
|
254
|
+
|
|
255
|
+
const { categories, choices, correct } = buildState(
|
|
256
|
+
model.categories,
|
|
257
|
+
model.choices,
|
|
258
|
+
showCorrect ? model.correctResponse : session.answers,
|
|
259
|
+
model.correctResponse,
|
|
260
|
+
);
|
|
261
|
+
|
|
262
|
+
log('[render] disabled: ', model.disabled);
|
|
263
|
+
|
|
264
|
+
const { rowLabels, categoriesPerRow, correctResponse, fontSizeFactor } = model;
|
|
265
|
+
const nbOfRows = (categories && Math.ceil(categories.length / categoriesPerRow)) || 0;
|
|
266
|
+
const existAlternate = this.existAlternateResponse(correctResponse) || false;
|
|
267
|
+
const displayNote =
|
|
268
|
+
(showCorrect || (mode === 'view' && role === 'instructor')) && showNote && note && existAlternate;
|
|
269
|
+
const alertMessage = translator.t('translation:categorize:limitMaxChoicesPerCategory', {
|
|
270
|
+
lng: model.language,
|
|
271
|
+
maxChoicesPerCategory,
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
const alertTitle = translator.t('common:warning', {
|
|
275
|
+
lng: model.language,
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
const onCloseText = translator.t('common:cancel', {
|
|
279
|
+
lng: model.language,
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
const showRationale = model.rationale && (hasText(model.rationale) || hasMedia(model.rationale));
|
|
283
|
+
const showTeacherInstructions =
|
|
284
|
+
model.teacherInstructions && (hasText(model.teacherInstructions) || hasMedia(model.teacherInstructions));
|
|
285
|
+
|
|
286
|
+
return (
|
|
287
|
+
<StyledUiLayout extraCSSRules={extraCSSRules} id={'main-container'} fontSizeFactor={fontSizeFactor}>
|
|
288
|
+
{showTeacherInstructions && (
|
|
289
|
+
<React.Fragment>
|
|
290
|
+
<StyledCollapsible
|
|
291
|
+
labels={{
|
|
292
|
+
hidden: 'Show Teacher Instructions',
|
|
293
|
+
visible: 'Hide Teacher Instructions',
|
|
294
|
+
}}
|
|
295
|
+
>
|
|
296
|
+
<PreviewPrompt prompt={model.teacherInstructions} />
|
|
297
|
+
</StyledCollapsible>
|
|
298
|
+
</React.Fragment>
|
|
299
|
+
)}
|
|
300
|
+
|
|
301
|
+
{model.prompt && (
|
|
302
|
+
<PreviewPrompt
|
|
303
|
+
prompt={model.prompt}
|
|
304
|
+
autoplayAudioEnabled={autoplayAudioEnabled}
|
|
305
|
+
customAudioButton={customAudioButton}
|
|
306
|
+
/>
|
|
307
|
+
)}
|
|
308
|
+
|
|
309
|
+
<CorrectAnswerToggle
|
|
310
|
+
show={showCorrect || correct === false}
|
|
311
|
+
toggled={showCorrect}
|
|
312
|
+
onToggle={this.toggleShowCorrect}
|
|
313
|
+
language={language}
|
|
314
|
+
/>
|
|
315
|
+
|
|
316
|
+
<StyledCategorize style={style}>
|
|
317
|
+
<div style={{ display: 'flex', flex: 1 }}>
|
|
318
|
+
<Categories
|
|
319
|
+
model={model}
|
|
320
|
+
disabled={model.disabled}
|
|
321
|
+
categories={categories}
|
|
322
|
+
onDropChoice={this.dropChoice}
|
|
323
|
+
onRemoveChoice={this.removeChoice}
|
|
324
|
+
rowLabels={(rowLabels || []).slice(0, nbOfRows)}
|
|
325
|
+
/>
|
|
326
|
+
</div>
|
|
327
|
+
<Choices
|
|
328
|
+
disabled={model.disabled}
|
|
329
|
+
model={model}
|
|
330
|
+
choices={choices}
|
|
331
|
+
choicePosition={choicePosition}
|
|
332
|
+
onDropChoice={this.dropChoice}
|
|
333
|
+
onRemoveChoice={this.removeChoice}
|
|
334
|
+
correct={correct}
|
|
335
|
+
/>
|
|
336
|
+
</StyledCategorize>
|
|
337
|
+
{displayNote && (
|
|
338
|
+
<StyledNote
|
|
339
|
+
dangerouslySetInnerHTML={{
|
|
340
|
+
__html: note,
|
|
341
|
+
}}
|
|
342
|
+
/>
|
|
343
|
+
)}
|
|
344
|
+
|
|
345
|
+
{showRationale && (
|
|
346
|
+
<StyledCollapsible labels={{ hidden: 'Show Rationale', visible: 'Hide Rationale' }}>
|
|
347
|
+
<PreviewPrompt prompt={model.rationale} />
|
|
348
|
+
</StyledCollapsible>
|
|
349
|
+
)}
|
|
350
|
+
|
|
351
|
+
{model.correctness && model.feedback && !showCorrect && (
|
|
352
|
+
<Feedback correctness={model.correctness} feedback={model.feedback} />
|
|
353
|
+
)}
|
|
354
|
+
<AlertDialog
|
|
355
|
+
title={alertTitle}
|
|
356
|
+
text={alertMessage}
|
|
357
|
+
open={showMaxChoiceAlert}
|
|
358
|
+
onCloseText={onCloseText}
|
|
359
|
+
onClose={() => this.setState({ showMaxChoiceAlert: false })}
|
|
360
|
+
></AlertDialog>
|
|
361
|
+
</StyledUiLayout>
|
|
362
|
+
);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
class CategorizeProvider extends React.Component {
|
|
367
|
+
static propTypes = {
|
|
368
|
+
model: PropTypes.object,
|
|
369
|
+
session: PropTypes.shape({
|
|
370
|
+
answers: PropTypes.arrayOf(
|
|
371
|
+
PropTypes.shape({
|
|
372
|
+
choice: PropTypes.string,
|
|
373
|
+
category: PropTypes.string,
|
|
374
|
+
}),
|
|
375
|
+
),
|
|
376
|
+
}),
|
|
377
|
+
onAnswersChange: PropTypes.func.isRequired,
|
|
378
|
+
onShowCorrectToggle: PropTypes.func.isRequired,
|
|
379
|
+
pauseMathObserver: PropTypes.func,
|
|
380
|
+
resumeMathObserver: PropTypes.func,
|
|
381
|
+
};
|
|
382
|
+
|
|
383
|
+
constructor(props) {
|
|
384
|
+
super(props);
|
|
385
|
+
this.uid = uid.generateId();
|
|
386
|
+
this.state = {
|
|
387
|
+
activeDragItem: null,
|
|
388
|
+
isValidDrop: false,
|
|
389
|
+
};
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
onDragStart: any = (event) => {
|
|
393
|
+
const { active } = event;
|
|
394
|
+
const { pauseMathObserver } = this.props;
|
|
395
|
+
|
|
396
|
+
if (pauseMathObserver) {
|
|
397
|
+
pauseMathObserver();
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
if (active?.data?.current) {
|
|
401
|
+
this.setState({
|
|
402
|
+
activeDragItem: active.data.current,
|
|
403
|
+
isValidDrop: false,
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
};
|
|
407
|
+
|
|
408
|
+
onDragEnd: any = (event) => {
|
|
409
|
+
const { active, over } = event;
|
|
410
|
+
const { resumeMathObserver } = this.props;
|
|
411
|
+
|
|
412
|
+
// Check if drop is valid
|
|
413
|
+
const draggedItem = active?.data?.current;
|
|
414
|
+
const overData = over?.data?.current;
|
|
415
|
+
const isValidDrop =
|
|
416
|
+
over && active && draggedItem && draggedItem.type === 'choice' && overData && overData.itemType === 'categorize';
|
|
417
|
+
|
|
418
|
+
this.setState({
|
|
419
|
+
activeDragItem: null,
|
|
420
|
+
isValidDrop: isValidDrop,
|
|
421
|
+
});
|
|
422
|
+
|
|
423
|
+
if (resumeMathObserver) {
|
|
424
|
+
resumeMathObserver();
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
if (!active || !draggedItem || draggedItem.type !== 'choice') {
|
|
428
|
+
return;
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
const choiceData = {
|
|
432
|
+
id: draggedItem.id,
|
|
433
|
+
categoryId: draggedItem.categoryId,
|
|
434
|
+
choiceIndex: draggedItem.choiceIndex,
|
|
435
|
+
value: draggedItem.value,
|
|
436
|
+
itemType: draggedItem.itemType,
|
|
437
|
+
};
|
|
438
|
+
|
|
439
|
+
// Dropped outside a valid/known target: remove from source category,
|
|
440
|
+
// which returns the choice to the choices pool.
|
|
441
|
+
if (!over) {
|
|
442
|
+
if (this.categorizeRef && this.categorizeRef.removeChoice && draggedItem.categoryId) {
|
|
443
|
+
this.categorizeRef.removeChoice(choiceData);
|
|
444
|
+
}
|
|
445
|
+
return;
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
if (over.id === 'choices-board') {
|
|
449
|
+
if (this.categorizeRef && this.categorizeRef.removeChoice && draggedItem.categoryId) {
|
|
450
|
+
this.categorizeRef.removeChoice(choiceData);
|
|
451
|
+
}
|
|
452
|
+
return;
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
if (this.categorizeRef && this.categorizeRef.dropChoice) {
|
|
456
|
+
this.categorizeRef.dropChoice(over.id, choiceData);
|
|
457
|
+
}
|
|
458
|
+
};
|
|
459
|
+
|
|
460
|
+
renderDragOverlay: any = () => {
|
|
461
|
+
const { activeDragItem } = this.state;
|
|
462
|
+
const { model } = this.props;
|
|
463
|
+
|
|
464
|
+
if (!activeDragItem) return null;
|
|
465
|
+
|
|
466
|
+
if (activeDragItem.type === 'choice') {
|
|
467
|
+
const choice = model.choices?.find((c) => c.id === activeDragItem.id);
|
|
468
|
+
if (choice) {
|
|
469
|
+
return <Choice key={choice.id} id={choice.id} {...choice} />;
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
return null;
|
|
474
|
+
};
|
|
475
|
+
|
|
476
|
+
render() {
|
|
477
|
+
const { isValidDrop } = this.state;
|
|
478
|
+
// Disable drop animation for valid drops to prevent visual snap-back
|
|
479
|
+
// Keep default animation for invalid drops to show visual feedback
|
|
480
|
+
const dropAnimation = isValidDrop ? null : undefined;
|
|
481
|
+
|
|
482
|
+
return (
|
|
483
|
+
<DragProvider onDragStart={this.onDragStart} onDragEnd={this.onDragEnd}>
|
|
484
|
+
<uid.Provider value={this.uid}>
|
|
485
|
+
<Categorize ref={(ref) => (this.categorizeRef = ref)} {...this.props} />
|
|
486
|
+
<DragOverlay dropAnimation={dropAnimation}>
|
|
487
|
+
<DragPreviewWrapper>{this.renderDragOverlay()}</DragPreviewWrapper>
|
|
488
|
+
</DragOverlay>
|
|
489
|
+
</uid.Provider>
|
|
490
|
+
</DragProvider>
|
|
491
|
+
);
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
const StyledUiLayout: any = styled(UiLayout)({
|
|
496
|
+
color: color.text(),
|
|
497
|
+
backgroundColor: color.background(),
|
|
498
|
+
position: 'relative',
|
|
499
|
+
});
|
|
500
|
+
|
|
501
|
+
const StyledNote: any = styled('div')(({ theme }) => ({
|
|
502
|
+
marginBottom: theme.spacing(2),
|
|
503
|
+
}));
|
|
504
|
+
|
|
505
|
+
const StyledCategorize: any = styled('div')(({ theme }) => ({
|
|
506
|
+
marginBottom: theme.spacing(1),
|
|
507
|
+
display: 'flex',
|
|
508
|
+
flexDirection: 'column',
|
|
509
|
+
}));
|
|
510
|
+
|
|
511
|
+
const StyledCollapsible: any = styled(Collapsible)(({ theme }) => ({
|
|
512
|
+
paddingBottom: theme.spacing(2),
|
|
513
|
+
}));
|
|
514
|
+
|
|
515
|
+
export default CategorizeProvider;
|