@pie-element/inline-dropdown 9.0.0-next.42 → 9.1.0-next.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/configure/lib/index.js +5 -5
- package/configure/lib/index.js.map +1 -1
- package/configure/lib/inline-dropdown-toolbar.js +4 -5
- package/configure/lib/inline-dropdown-toolbar.js.map +1 -1
- package/configure/lib/main.js +13 -18
- package/configure/lib/main.js.map +1 -1
- package/configure/lib/markupUtils.js +2 -3
- package/configure/lib/markupUtils.js.map +1 -1
- package/configure/package.json +8 -8
- package/controller/lib/index.js +7 -9
- package/controller/lib/index.js.map +1 -1
- package/controller/lib/utils.js +2 -3
- package/controller/lib/utils.js.map +1 -1
- package/controller/package.json +3 -3
- package/lib/inline-dropdown.js +2 -2
- package/lib/inline-dropdown.js.map +1 -1
- package/package.json +13 -10
- package/module/configure.js +0 -1
- package/module/controller.js +0 -6261
- package/module/demo.js +0 -101
- package/module/element.js +0 -1
- package/module/index.html +0 -21
- package/module/manifest.json +0 -18
- package/module/print-demo.js +0 -139
- package/module/print.html +0 -18
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
7
6
|
exports.removeUnwantedCharacters = exports.processMarkup = exports.createSlateMarkup = exports.createElementFromHTML = void 0;
|
|
8
|
-
var
|
|
7
|
+
var _lodashEs = require("lodash-es");
|
|
9
8
|
// do not remove \t from \times, \triangle, \tan, \theta or \therefore
|
|
10
9
|
const tSymbols = 'imes|riangle|an|heta|herefore';
|
|
11
10
|
// do not remove \n from \nthroot, \nparallel, \ncong, \napprox, \neq, \ne or \nsim
|
|
@@ -41,7 +40,7 @@ const createSlateMarkup = (markup, choices) => {
|
|
|
41
40
|
label: ''
|
|
42
41
|
};
|
|
43
42
|
}
|
|
44
|
-
return `<span data-type="inline_dropdown" data-index="${index}" data-value="${(0,
|
|
43
|
+
return `<span data-type="inline_dropdown" data-index="${index}" data-value="${(0, _lodashEs.escape)(correctChoice.label)}"></span>`;
|
|
45
44
|
};
|
|
46
45
|
return newMarkup.replace(REGEX, (match, g) => {
|
|
47
46
|
return createSelect(g);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"markupUtils.js","names":["
|
|
1
|
+
{"version":3,"file":"markupUtils.js","names":["_lodashEs","require","tSymbols","nSymbols","matchTabAndNewLine","RegExp","removeUnwantedCharacters","markup","replace","exports","createElementFromHTML","htmlString","div","document","createElement","innerHTML","trim","processMarkup","newMarkup","slateMarkup","querySelectorAll","forEach","s","replaceWith","dataset","index","REGEX","createSlateMarkup","choices","createSelect","correctChoice","find","c","correct","value","id","label","escape","match","g"],"sources":["../src/markupUtils.js"],"sourcesContent":["import { escape } from 'lodash-es';\n\n// do not remove \\t from \\times, \\triangle, \\tan, \\theta or \\therefore\nconst tSymbols = 'imes|riangle|an|heta|herefore';\n// do not remove \\n from \\nthroot, \\nparallel, \\ncong, \\napprox, \\neq, \\ne or \\nsim\nconst nSymbols = 'throot|parallel|cong|approx|eq|e|sim';\n// match all \\t and \\n that are not part of math symbols that starts with \\t or \\n\nconst matchTabAndNewLine = new RegExp(\n `(\\\\t(?!${tSymbols}))|(\\\\n(?!${nSymbols}))|(\\\\\\\\t(?!${tSymbols}))|(\\\\\\\\n(?!${nSymbols}))`,\n 'g',\n);\n\nexport const removeUnwantedCharacters = (markup) =>\n markup.replace(matchTabAndNewLine, '').replace(/\\\\\"/g, '\"').replace(/\\\\\\//g, '/');\n\nexport const createElementFromHTML = (htmlString) => {\n const div = document.createElement('div');\n\n div.innerHTML = htmlString.trim();\n\n return div;\n};\n\nexport const processMarkup = (markup) => {\n const newMarkup = removeUnwantedCharacters(markup);\n const slateMarkup = createElementFromHTML(newMarkup);\n\n slateMarkup.querySelectorAll('[data-type=\"inline_dropdown\"]').forEach((s) => {\n s.replaceWith(`{{${s.dataset.index}}}`);\n });\n\n return slateMarkup.innerHTML;\n};\n\nconst REGEX = /\\{\\{(\\d+)\\}\\}/g;\n\nexport const createSlateMarkup = (markup, choices) => {\n const newMarkup = removeUnwantedCharacters(markup);\n const createSelect = (index) => {\n let correctChoice = choices[index] && choices[index].find((c) => c.correct);\n\n if (!correctChoice || !correctChoice.value) {\n correctChoice = {\n id: '',\n value: '',\n label: '',\n };\n }\n\n return `<span data-type=\"inline_dropdown\" data-index=\"${index}\" data-value=\"${escape(\n correctChoice.label,\n )}\"></span>`;\n };\n\n return newMarkup.replace(REGEX, (match, g) => {\n return createSelect(g);\n });\n};\n"],"mappings":";;;;;;AAAA,IAAAA,SAAA,GAAAC,OAAA;AAEA;AACA,MAAMC,QAAQ,GAAG,+BAA+B;AAChD;AACA,MAAMC,QAAQ,GAAG,sCAAsC;AACvD;AACA,MAAMC,kBAAkB,GAAG,IAAIC,MAAM,CACnC,UAAUH,QAAQ,aAAaC,QAAQ,eAAeD,QAAQ,eAAeC,QAAQ,IAAI,EACzF,GACF,CAAC;AAEM,MAAMG,wBAAwB,GAAIC,MAAM,IAC7CA,MAAM,CAACC,OAAO,CAACJ,kBAAkB,EAAE,EAAE,CAAC,CAACI,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAACA,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC;AAACC,OAAA,CAAAH,wBAAA,GAAAA,wBAAA;AAE7E,MAAMI,qBAAqB,GAAIC,UAAU,IAAK;EACnD,MAAMC,GAAG,GAAGC,QAAQ,CAACC,aAAa,CAAC,KAAK,CAAC;EAEzCF,GAAG,CAACG,SAAS,GAAGJ,UAAU,CAACK,IAAI,CAAC,CAAC;EAEjC,OAAOJ,GAAG;AACZ,CAAC;AAACH,OAAA,CAAAC,qBAAA,GAAAA,qBAAA;AAEK,MAAMO,aAAa,GAAIV,MAAM,IAAK;EACvC,MAAMW,SAAS,GAAGZ,wBAAw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-configure",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.1.0-next.0",
|
|
4
4
|
"private": true,
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "src/index.js",
|
|
@@ -10,15 +10,15 @@
|
|
|
10
10
|
"@mui/icons-material": "^7.3.4",
|
|
11
11
|
"@mui/material": "^7.3.4",
|
|
12
12
|
"@pie-framework/pie-configure-events": "^1.3.0",
|
|
13
|
-
"@pie-lib/config-ui": "12.1.1-next.
|
|
14
|
-
"@pie-lib/editable-html-tip-tap": "1.1.1-next.
|
|
15
|
-
"@pie-lib/math-rendering": "4.1.1-next.
|
|
16
|
-
"@pie-lib/render-ui": "5.1.1-next.
|
|
13
|
+
"@pie-lib/config-ui": "12.1.1-next.3",
|
|
14
|
+
"@pie-lib/editable-html-tip-tap": "1.1.1-next.3",
|
|
15
|
+
"@pie-lib/math-rendering": "4.1.1-next.1",
|
|
16
|
+
"@pie-lib/render-ui": "5.1.1-next.1",
|
|
17
17
|
"classnames": "^2.2.6",
|
|
18
18
|
"debug": "^4.1.1",
|
|
19
|
-
"lodash": "^4.17.23",
|
|
19
|
+
"lodash-es": "^4.17.23",
|
|
20
20
|
"prop-types": "^15.8.1",
|
|
21
|
-
"react": "18.
|
|
22
|
-
"react-dom": "18.
|
|
21
|
+
"react": "18.3.1",
|
|
22
|
+
"react-dom": "18.3.1"
|
|
23
23
|
}
|
|
24
24
|
}
|
package/controller/lib/index.js
CHANGED
|
@@ -9,9 +9,7 @@ exports.model = model;
|
|
|
9
9
|
exports.normalize = void 0;
|
|
10
10
|
exports.outcome = outcome;
|
|
11
11
|
exports.validate = void 0;
|
|
12
|
-
var
|
|
13
|
-
var _reduce = _interopRequireDefault(require("lodash/reduce"));
|
|
14
|
-
var _isEmpty = _interopRequireDefault(require("lodash/isEmpty"));
|
|
12
|
+
var _lodashEs = require("lodash-es");
|
|
15
13
|
var _controllerUtils = require("@pie-lib/controller-utils");
|
|
16
14
|
var _defaults = _interopRequireDefault(require("./defaults"));
|
|
17
15
|
var _utils = require("./utils");
|
|
@@ -39,8 +37,8 @@ async function model(question, session, env, updateSession) {
|
|
|
39
37
|
const {
|
|
40
38
|
value = {}
|
|
41
39
|
} = session || {};
|
|
42
|
-
let choices = (0,
|
|
43
|
-
obj[key] = (0,
|
|
40
|
+
let choices = (0, _lodashEs.reduce)(normalizedQuestion.choices, (obj, area, key) => {
|
|
41
|
+
obj[key] = (0, _lodashEs.map)(area, choice => choice);
|
|
44
42
|
return obj;
|
|
45
43
|
}, {});
|
|
46
44
|
let feedback = {};
|
|
@@ -49,7 +47,7 @@ async function model(question, session, env, updateSession) {
|
|
|
49
47
|
const respAreaLength = Object.keys(allCorrectResponses).length;
|
|
50
48
|
let correctResponses = 0;
|
|
51
49
|
for (let i = 0; i < respAreaLength; i++) {
|
|
52
|
-
const result = (0,
|
|
50
|
+
const result = (0, _lodashEs.reduce)(allCorrectResponses, (obj, choices, key) => {
|
|
53
51
|
const answer = value && value[key] || '';
|
|
54
52
|
const correctChoice = choices[i] || '';
|
|
55
53
|
const isCorrect = answer && correctChoice && correctChoice === answer;
|
|
@@ -92,7 +90,7 @@ async function model(question, session, env, updateSession) {
|
|
|
92
90
|
shuffledValues: Array.isArray(storedValues) ? storedValues : []
|
|
93
91
|
}, us(key), 'value');
|
|
94
92
|
}
|
|
95
|
-
if (!(0,
|
|
93
|
+
if (!(0, _lodashEs.isEmpty)(shuffledValues)) {
|
|
96
94
|
if (session && updateSession && typeof updateSession === 'function') {
|
|
97
95
|
updateSession(session.id, session.element, {
|
|
98
96
|
shuffledValues
|
|
@@ -145,7 +143,7 @@ const getScore = (config, session) => {
|
|
|
145
143
|
const allCorrectResponses = (0, _utils.getAllCorrectResponses)(config);
|
|
146
144
|
let correctCount = 0;
|
|
147
145
|
for (let i = 0; i < maxScore; i++) {
|
|
148
|
-
const result = (0,
|
|
146
|
+
const result = (0, _lodashEs.reduce)(allCorrectResponses, (total, choices, key) => {
|
|
149
147
|
const answer = value && value[key] || '';
|
|
150
148
|
const correctChoice = choices[i] || '';
|
|
151
149
|
if (correctChoice && answer && correctChoice === answer) {
|
|
@@ -179,7 +177,7 @@ const getScore = (config, session) => {
|
|
|
179
177
|
exports.getScore = getScore;
|
|
180
178
|
function outcome(model, session, env = {}) {
|
|
181
179
|
return new Promise(resolve => {
|
|
182
|
-
if (!session || (0,
|
|
180
|
+
if (!session || (0, _lodashEs.isEmpty)(session)) {
|
|
183
181
|
resolve({
|
|
184
182
|
score: 0,
|
|
185
183
|
empty: true
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["_map","_interopRequireDefault","require","_reduce","_isEmpty","_controllerUtils","_defaults","_utils","getFeedback","correct","normalize","question","defaults","exports","model","session","env","updateSession","normalizedQuestion","value","choices","reduce","obj","area","key","map","choice","feedback","mode","allCorrectResponses","getAllCorrectResponses","respAreaLength","Object","keys","length","correctResponses","i","result","answer","correctChoice","isCorrect","lockChoiceOrder","lockChoices","shuffledValues","us","part","id","element","update","Promise","resolve","storedValues","getShuffledChoices","Array","isArray","isEmpty","catch","e","console","error","teacherInstructions","rationale","choicesWillNullRationales","acc","currentValue","role","rationaleEnabled","teacherInstructionsEnabled","choiceRationaleEnabled","out","disabled","prompt","promptEnabled","displayType","markup","responseCorrect","getScore","undefined","language","extraCSSRules","config","maxScore","correctCount","total","str","toFixed","parseFloat","outcome","score","empty","partialScoringEnabled","partialScoring","enabled","Math","floor","createCorrectResponseSession","forEach","correctChoices","filter","c","getInnerText","html","replaceAll","getContent","replace","validate","maxResponseAreas","maxResponseAreaChoices","errors","field","required","nbOfResponseAreas","match","responseAreasError","choiceKey","responseAreaChoicesError"],"sources":["../src/index.js"],"sourcesContent":["import map from 'lodash/map';\nimport reduce from 'lodash/reduce';\nimport isEmpty from 'lodash/isEmpty';\nimport { lockChoices, getShuffledChoices, partialScoring } from '@pie-lib/controller-utils';\nimport defaults from './defaults';\n\nimport { getAllCorrectResponses } from './utils';\n\nconst getFeedback = (correct) => {\n if (correct) {\n return 'correct';\n }\n\n return 'incorrect';\n};\n\nexport const normalize = (question) => ({ ...defaults, ...question });\n\n/**\n *\n * @param {*} question\n * @param {*} session\n * @param {*} env\n * @param {*} updateSession - optional - a function that will set the properties passed into it on the session.\n */\nexport async function model(question, session, env, updateSession) {\n const normalizedQuestion = normalize(question);\n const { value = {} } = session || {};\n let choices = reduce(\n normalizedQuestion.choices,\n (obj, area, key) => {\n obj[key] = map(area, (choice) => choice);\n\n return obj;\n },\n {},\n );\n\n let feedback = {};\n\n if (env.mode === 'evaluate') {\n const allCorrectResponses = getAllCorrectResponses(normalizedQuestion);\n const respAreaLength = Object.keys(allCorrectResponses).length;\n let correctResponses = 0;\n\n for (let i = 0; i < respAreaLength; i++) {\n const result = reduce(\n allCorrectResponses,\n (obj, choices, key) => {\n const answer = (value && value[key]) || '';\n const correctChoice = choices[i] || '';\n const isCorrect = answer && correctChoice && correctChoice === answer;\n\n obj.feedback[key] = getFeedback(isCorrect);\n\n if (isCorrect) {\n obj.correctResponses += 1;\n }\n\n return obj;\n },\n { correctResponses: 0, feedback: {} },\n );\n\n if (result.correctResponses >= correctResponses) {\n correctResponses = result.correctResponses;\n feedback = result.feedback;\n }\n\n if (result.correctResponses === respAreaLength) {\n break;\n }\n }\n }\n\n const lockChoiceOrder = lockChoices(normalizedQuestion, session, env);\n\n if (!lockChoiceOrder) {\n const shuffledValues = {};\n const keys = Object.keys(choices);\n\n const us = (part) => (id, element, update) => {\n return new Promise((resolve) => {\n shuffledValues[part] = update.shuffledValues;\n resolve();\n });\n };\n\n let i;\n\n for (i = 0; i < keys.length; i++) {\n const key = keys[i];\n const storedValues = session?.shuffledValues?.[key];\n\n choices[key] = await getShuffledChoices(\n choices[key],\n // the shuffledValues structure was updated to an object like { choice_key: [] }\n // and we need to override shuffledValues if it's not an array\n { shuffledValues: Array.isArray(storedValues) ? storedValues : [] },\n us(key),\n 'value',\n );\n }\n\n if (!isEmpty(shuffledValues)) {\n if (session && updateSession && typeof updateSession === 'function') {\n updateSession(session.id, session.element, {\n shuffledValues,\n }).catch((e) => {\n // eslint-disable-next-line no-console\n console.error('update session failed', e);\n });\n }\n }\n }\n\n let teacherInstructions = null;\n let rationale = null;\n\n const choicesWillNullRationales = (Object.keys(choices) || []).reduce((acc, currentValue) => {\n acc[currentValue] = (choices[currentValue] || []).map((choice) => ({\n ...choice,\n rationale: null,\n }));\n\n return acc;\n }, {});\n\n if (env.role === 'instructor' && (env.mode === 'view' || env.mode === 'evaluate')) {\n rationale = normalizedQuestion.rationaleEnabled ? normalizedQuestion.rationale : null;\n teacherInstructions = normalizedQuestion.teacherInstructionsEnabled\n ? normalizedQuestion.teacherInstructions\n : null;\n\n choices = normalizedQuestion.choiceRationaleEnabled ? normalizedQuestion.choices : choicesWillNullRationales;\n } else {\n rationale = null;\n teacherInstructions = null;\n choices = choicesWillNullRationales;\n }\n\n const out = {\n disabled: env.mode !== 'gather',\n mode: env.mode,\n prompt: normalizedQuestion.promptEnabled ? normalizedQuestion.prompt : null,\n displayType: normalizedQuestion.displayType,\n markup: normalizedQuestion.markup,\n choices,\n feedback,\n\n responseCorrect: env.mode === 'evaluate' ? getScore(normalizedQuestion, session) === 1 : undefined,\n rationale,\n teacherInstructions,\n language: normalizedQuestion.language,\n extraCSSRules: normalizedQuestion.extraCSSRules,\n };\n\n return out;\n}\n\nexport const getScore = (config, session) => {\n const { value = {} } = session || {};\n const maxScore = config && config.choices ? Object.keys(config.choices).length : 0;\n const allCorrectResponses = getAllCorrectResponses(config);\n let correctCount = 0;\n\n for (let i = 0; i < maxScore; i++) {\n const result = reduce(\n allCorrectResponses,\n (total, choices, key) => {\n const answer = (value && value[key]) || '';\n const correctChoice = choices[i] || '';\n\n if (correctChoice && answer && correctChoice === answer) {\n return total;\n }\n\n return total - 1;\n },\n maxScore,\n );\n\n if (result > correctCount) {\n correctCount = result;\n }\n\n if (result === maxScore) {\n break;\n }\n }\n\n const str = (correctCount / maxScore).toFixed(2);\n\n return parseFloat(str);\n};\n\n/**\n *\n * The score is partial by default for checkbox mode, allOrNothing for radio mode.\n * To disable partial scoring for checkbox mode you either set model.partialScoring = false or env.partialScoring =\n * false. the value in `env` will override the value in `model`.\n * @param {Object} model - the main model\n * @param {boolean} model.partialScoring - is partial scoring enabled (if undefined set to to true)\n * @param {*} session\n * @param {Object} env\n * @param {boolean} env.partialScoring - is partial scoring enabled (if undefined default to true) This overrides\n * `model.partialScoring`.\n */\nexport function outcome(model, session, env = {}) {\n return new Promise((resolve) => {\n if (!session || isEmpty(session)) {\n resolve({ score: 0, empty: true });\n }\n\n const partialScoringEnabled = partialScoring.enabled(model, env);\n const score = getScore(model, session);\n\n resolve({\n score: partialScoringEnabled ? score : Math.floor(score),\n empty: false,\n });\n });\n}\n\nexport const createCorrectResponseSession = (question, env) => {\n return new Promise((resolve) => {\n if (env.mode !== 'evaluate' && env.role === 'instructor') {\n const { choices } = question;\n const value = {};\n\n if (choices) {\n Object.keys(choices).forEach((key, i) => {\n const correctChoices = choices[key] && choices[key].filter((c) => c.correct);\n\n value[i] = correctChoices && correctChoices[0].value;\n });\n }\n\n resolve({\n id: '1',\n value,\n });\n } else {\n resolve(null);\n }\n });\n};\n\n// remove all html tags\nconst getInnerText = (html) => (html || '').replaceAll(/<[^>]*>/g, '');\n\n// remove all html tags except img, iframe and source tag for audio\nconst getContent = (html) => (html || '').replace(/(<(?!img|iframe|source)([^>]+)>)/gi, '');\n\nexport const validate = (model = {}, config = {}) => {\n const { markup, choices } = model;\n const { maxResponseAreas, maxResponseAreaChoices } = config;\n const errors = {};\n\n ['teacherInstructions', 'prompt', 'rationale'].forEach((field) => {\n if (config[field]?.required && !getContent(model[field])) {\n errors[field] = 'This field is required.';\n }\n });\n\n const nbOfResponseAreas = ((markup || '').match(/\\{\\{(\\d+)\\}\\}/g) || []).length;\n\n if (nbOfResponseAreas > maxResponseAreas) {\n errors.responseAreasError = `No more than ${maxResponseAreas} response areas should be defined.`;\n } else if (nbOfResponseAreas < 1) {\n errors.responseAreasError = 'There should be defined at least 1 response area.';\n }\n\n (Object.keys(choices) || []).forEach((choiceKey) => {\n if (choices[choiceKey] && choices[choiceKey].length > maxResponseAreaChoices) {\n errors.responseAreaChoicesError = `No more than ${maxResponseAreaChoices} choices per response area should be defined.`;\n }\n });\n\n return errors;\n};\n"],"mappings":";;;;;;;;;;;AAAA,IAAAA,IAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,OAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,QAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,gBAAA,GAAAH,OAAA;AACA,IAAAI,SAAA,GAAAL,sBAAA,CAAAC,OAAA;AAEA,IAAAK,MAAA,GAAAL,OAAA;AAEA,MAAMM,WAAW,GAAIC,OAAO,IAAK;EAC/B,IAAIA,OAAO,EAAE;IACX,OAAO,SAAS;EAClB;EAEA,OAAO,WAAW;AACpB,CAAC;AAEM,MAAMC,SAAS,GAAIC,QAAQ,KAAM;EAAE,GAAGC,iBAAQ;EAAE,GAAGD;AAAS,CAAC,CAAC;;AAErE;AACA;AACA;AACA;AACA;AACA;AACA;AANAE,OAAA,CAAAH,SAAA,GAAAA,SAAA;AAOO,eAAeI,KAAKA,CAACH,QAAQ,EAAEI,OAAO,EAAEC,GAAG,EAAEC,aAAa,EAAE;EAC/D,MAAMC,kBAAkB,GAAGR,SAAS,CAACC,QAAQ,CAAC;EAC9C,MAAM;IAAEQ,KAAK,GAAG,CAAC;EAAE,CAAC,GAAGJ,OAAO,IAAI,CAAC,CAAC;EACpC,IAAIK,OAAO,GAAG,IAAAC,eAAM,EAClBH,kBAAkB,CAACE,OAAO,EAC1B,CAACE,GAAG,EAAEC,IAAI,EAAEC,GAAG,KAAK;IAClBF,GAAG,CAACE,GAAG,CAAC,GAAG,IAAAC,YAAG,EAACF,IAAI,EAAGG,MAAM,IAAKA,MAAM,CAAC;IAExC,OAAOJ,GAAG;EACZ,CAAC,EACD,CAAC,CAC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IAAI,CAACP,UAAU,CAACzF,KAAK,CAAC+F,KAAK,CAAC,CAAC,EAAE;MACxDD,MAAM,CAACC,KAAK,CAAC,GAAG,yBAAyB;IAC3C;EACF,CAAC,CAAC;EAEF,MAAME,iBAAiB,GAAG,CAAC,CAACrC,MAAM,IAAI,EAAE,EAAEsC,KAAK,CAAC,gBAAgB,CAAC,IAAI,EAAE,EAAE9E,MAAM;EAE/E,IAAI6E,iBAAiB,GAAGL,gBAAgB,EAAE;IACxCE,MAAM,CAACK,kBAAkB,GAAG,gBAAgBP,gBAAgB,oCAAoC;EAClG,CAAC,MAAM,IAAIK,iBAAiB,GAAG,CAAC,EAAE;IAChCH,MAAM,CAACK,kBAAkB,GAAG,mDAAmD;EACjF;EAEA,CAACjF,MAAM,CAACC,IAAI,CAACb,OAAO,CAAC,IAAI,EAAE,EAAE4E,OAAO,CAAEkB,SAAS,IAAK;IAClD,IAAI9F,OAAO,CAAC8F,SAAS,CAAC,IAAI9F,OAAO,CAAC8F,SAAS,CAAC,CAAChF,MAAM,GAAGyE,sBAAsB,EAAE;MAC5EC,MAAM,CAACO,wBAAwB,GAAG,gBAAgBR,sBAAsB,+CAA+C;IACzH;EACF,CAAC,CAAC;EAEF,OAAOC,MAAM;AACf,CAAC;AAAC/F,OAAA,CAAA4F,QAAA,GAAAA,QAAA","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"index.js","names":["_lodashEs","require","_controllerUtils","_defaults","_interopRequireDefault","_utils","getFeedback","correct","normalize","question","defaults","exports","model","session","env","updateSession","normalizedQuestion","value","choices","reduce","obj","area","key","map","choice","feedback","mode","allCorrectResponses","getAllCorrectResponses","respAreaLength","Object","keys","length","correctResponses","i","result","answer","correctChoice","isCorrect","lockChoiceOrder","lockChoices","shuffledValues","us","part","id","element","update","Promise","resolve","storedValues","getShuffledChoices","Array","isArray","isEmpty","catch","e","console","error","teacherInstructions","rationale","choicesWillNullRationales","acc","currentValue","role","rationaleEnabled","teacherInstructionsEnabled","choiceRationaleEnabled","out","disabled","prompt","promptEnabled","displayType","markup","responseCorrect","getScore","undefined","language","extraCSSRules","config","maxScore","correctCount","total","str","toFixed","parseFloat","outcome","score","empty","partialScoringEnabled","partialScoring","enabled","Math","floor","createCorrectResponseSession","forEach","correctChoices","filter","c","getInnerText","html","replaceAll","getContent","replace","validate","maxResponseAreas","maxResponseAreaChoices","errors","field","required","nbOfResponseAreas","match","responseAreasError","choiceKey","responseAreaChoicesError"],"sources":["../src/index.js"],"sourcesContent":["import { isEmpty, map, reduce } from 'lodash-es';\nimport { lockChoices, getShuffledChoices, partialScoring } from '@pie-lib/controller-utils';\nimport defaults from './defaults';\n\nimport { getAllCorrectResponses } from './utils';\n\nconst getFeedback = (correct) => {\n if (correct) {\n return 'correct';\n }\n\n return 'incorrect';\n};\n\nexport const normalize = (question) => ({ ...defaults, ...question });\n\n/**\n *\n * @param {*} question\n * @param {*} session\n * @param {*} env\n * @param {*} updateSession - optional - a function that will set the properties passed into it on the session.\n */\nexport async function model(question, session, env, updateSession) {\n const normalizedQuestion = normalize(question);\n const { value = {} } = session || {};\n let choices = reduce(\n normalizedQuestion.choices,\n (obj, area, key) => {\n obj[key] = map(area, (choice) => choice);\n\n return obj;\n },\n {},\n );\n\n let feedback = {};\n\n if (env.mode === 'evaluate') {\n const allCorrectResponses = getAllCorrectResponses(normalizedQuestion);\n const respAreaLength = Object.keys(allCorrectResponses).length;\n let correctResponses = 0;\n\n for (let i = 0; i < respAreaLength; i++) {\n const result = reduce(\n allCorrectResponses,\n (obj, choices, key) => {\n const answer = (value && value[key]) || '';\n const correctChoice = choices[i] || '';\n const isCorrect = answer && correctChoice && correctChoice === answer;\n\n obj.feedback[key] = getFeedback(isCorrect);\n\n if (isCorrect) {\n obj.correctResponses += 1;\n }\n\n return obj;\n },\n { correctResponses: 0, feedback: {} },\n );\n\n if (result.correctResponses >= correctResponses) {\n correctResponses = result.correctResponses;\n feedback = result.feedback;\n }\n\n if (result.correctResponses === respAreaLength) {\n break;\n }\n }\n }\n\n const lockChoiceOrder = lockChoices(normalizedQuestion, session, env);\n\n if (!lockChoiceOrder) {\n const shuffledValues = {};\n const keys = Object.keys(choices);\n\n const us = (part) => (id, element, update) => {\n return new Promise((resolve) => {\n shuffledValues[part] = update.shuffledValues;\n resolve();\n });\n };\n\n let i;\n\n for (i = 0; i < keys.length; i++) {\n const key = keys[i];\n const storedValues = session?.shuffledValues?.[key];\n\n choices[key] = await getShuffledChoices(\n choices[key],\n // the shuffledValues structure was updated to an object like { choice_key: [] }\n // and we need to override shuffledValues if it's not an array\n { shuffledValues: Array.isArray(storedValues) ? storedValues : [] },\n us(key),\n 'value',\n );\n }\n\n if (!isEmpty(shuffledValues)) {\n if (session && updateSession && typeof updateSession === 'function') {\n updateSession(session.id, session.element, {\n shuffledValues,\n }).catch((e) => {\n // eslint-disable-next-line no-console\n console.error('update session failed', e);\n });\n }\n }\n }\n\n let teacherInstructions = null;\n let rationale = null;\n\n const choicesWillNullRationales = (Object.keys(choices) || []).reduce((acc, currentValue) => {\n acc[currentValue] = (choices[currentValue] || []).map((choice) => ({\n ...choice,\n rationale: null,\n }));\n\n return acc;\n }, {});\n\n if (env.role === 'instructor' && (env.mode === 'view' || env.mode === 'evaluate')) {\n rationale = normalizedQuestion.rationaleEnabled ? normalizedQuestion.rationale : null;\n teacherInstructions = normalizedQuestion.teacherInstructionsEnabled ? normalizedQuestion.teacherInstructions : null;\n\n choices = normalizedQuestion.choiceRationaleEnabled ? normalizedQuestion.choices : choicesWillNullRationales;\n } else {\n rationale = null;\n teacherInstructions = null;\n choices = choicesWillNullRationales;\n }\n\n const out = {\n disabled: env.mode !== 'gather',\n mode: env.mode,\n prompt: normalizedQuestion.promptEnabled ? normalizedQuestion.prompt : null,\n displayType: normalizedQuestion.displayType,\n markup: normalizedQuestion.markup,\n choices,\n feedback,\n\n responseCorrect: env.mode === 'evaluate' ? getScore(normalizedQuestion, session) === 1 : undefined,\n rationale,\n teacherInstructions,\n language: normalizedQuestion.language,\n extraCSSRules: normalizedQuestion.extraCSSRules,\n };\n\n return out;\n}\n\nexport const getScore = (config, session) => {\n const { value = {} } = session || {};\n const maxScore = config && config.choices ? Object.keys(config.choices).length : 0;\n const allCorrectResponses = getAllCorrectResponses(config);\n let correctCount = 0;\n\n for (let i = 0; i < maxScore; i++) {\n const result = reduce(\n allCorrectResponses,\n (total, choices, key) => {\n const answer = (value && value[key]) || '';\n const correctChoice = choices[i] || '';\n\n if (correctChoice && answer && correctChoice === answer) {\n return total;\n }\n\n return total - 1;\n },\n maxScore,\n );\n\n if (result > correctCount) {\n correctCount = result;\n }\n\n if (result === maxScore) {\n break;\n }\n }\n\n const str = (correctCount / maxScore).toFixed(2);\n\n return parseFloat(str);\n};\n\n/**\n *\n * The score is partial by default for checkbox mode, allOrNothing for radio mode.\n * To disable partial scoring for checkbox mode you either set model.partialScoring = false or env.partialScoring =\n * false. the value in `env` will override the value in `model`.\n * @param {Object} model - the main model\n * @param {boolean} model.partialScoring - is partial scoring enabled (if undefined set to to true)\n * @param {*} session\n * @param {Object} env\n * @param {boolean} env.partialScoring - is partial scoring enabled (if undefined default to true) This overrides\n * `model.partialScoring`.\n */\nexport function outcome(model, session, env = {}) {\n return new Promise((resolve) => {\n if (!session || isEmpty(session)) {\n resolve({ score: 0, empty: true });\n }\n\n const partialScoringEnabled = partialScoring.enabled(model, env);\n const score = getScore(model, session);\n\n resolve({\n score: partialScoringEnabled ? score : Math.floor(score),\n empty: false,\n });\n });\n}\n\nexport const createCorrectResponseSession = (question, env) => {\n return new Promise((resolve) => {\n if (env.mode !== 'evaluate' && env.role === 'instructor') {\n const { choices } = question;\n const value = {};\n\n if (choices) {\n Object.keys(choices).forEach((key, i) => {\n const correctChoices = choices[key] && choices[key].filter((c) => c.correct);\n\n value[i] = correctChoices && correctChoices[0].value;\n });\n }\n\n resolve({\n id: '1',\n value,\n });\n } else {\n resolve(null);\n }\n });\n};\n\n// remove all html tags\nconst getInnerText = (html) => (html || '').replaceAll(/<[^>]*>/g, '');\n\n// remove all html tags except img, iframe and source tag for audio\nconst getContent = (html) => (html || '').replace(/(<(?!img|iframe|source)([^>]+)>)/gi, '');\n\nexport const validate = (model = {}, config = {}) => {\n const { markup, choices } = model;\n const { maxResponseAreas, maxResponseAreaChoices } = config;\n const errors = {};\n\n ['teacherInstructions', 'prompt', 'rationale'].forEach((field) => {\n if (config[field]?.required && !getContent(model[field])) {\n errors[field] = 'This field is required.';\n }\n });\n\n const nbOfResponseAreas = ((markup || '').match(/\\{\\{(\\d+)\\}\\}/g) || []).length;\n\n if (nbOfResponseAreas > maxResponseAreas) {\n errors.responseAreasError = `No more than ${maxResponseAreas} response areas should be defined.`;\n } else if (nbOfResponseAreas < 1) {\n errors.responseAreasError = 'There should be defined at least 1 response area.';\n }\n\n (Object.keys(choices) || []).forEach((choiceKey) => {\n if (choices[choiceKey] && choices[choiceKey].length > maxResponseAreaChoices) {\n errors.responseAreaChoicesError = `No more than ${maxResponseAreaChoices} choices per response area should be defined.`;\n }\n });\n\n return errors;\n};\n"],"mappings":";;;;;;;;;;;AAAA,IAAAA,SAAA,GAAAC,OAAA;AACA,IAAAC,gBAAA,GAAAD,OAAA;AACA,IAAAE,SAAA,GAAAC,sBAAA,CAAAH,OAAA;AAEA,IAAAI,MAAA,GAAAJ,OAAA;AAEA,MAAMK,WAAW,GAAIC,OAAO,IAAK;EAC/B,IAAIA,OAAO,EAAE;IACX,OAAO,SAAS;EAClB;EAEA,OAAO,WAAW;AACpB,CAAC;AAEM,MAAMC,SAAS,GAAIC,QAAQ,KAAM;EAAE,GAAGC,iBAAQ;EAAE,GAAGD;AAAS,CAAC,CAAC;;AAErE;AACA;AACA;AACA;AACA;AACA;AACA;AANAE,OAAA,CAAAH,SAAA,GAAAA,SAAA;AAOO,eAAeI,KAAKA,CAACH,QAAQ,EAAEI,OAAO,EAAEC,GAAG,EAAEC,aAAa,EAAE;EACjE,MAAMC,kBAAkB,GAAGR,SAAS,CAACC,QAAQ,CAAC;EAC9C,MA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
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
7
6
|
exports.getAllCorrectResponses = void 0;
|
|
8
|
-
var
|
|
7
|
+
var _lodashEs = require("lodash-es");
|
|
9
8
|
const getAllCorrectResponses = ({
|
|
10
9
|
choices,
|
|
11
10
|
alternateResponse
|
|
12
11
|
}) => {
|
|
13
12
|
alternateResponse = alternateResponse || {};
|
|
14
13
|
const correctAnswers = {};
|
|
15
|
-
(0,
|
|
14
|
+
(0, _lodashEs.forEach)(choices, (respArea, key) => {
|
|
16
15
|
if (!correctAnswers[key]) {
|
|
17
16
|
correctAnswers[key] = [];
|
|
18
17
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","names":["
|
|
1
|
+
{"version":3,"file":"utils.js","names":["_lodashEs","require","getAllCorrectResponses","choices","alternateResponse","correctAnswers","forEach","respArea","key","choice","correct","push","value","exports"],"sources":["../src/utils.js"],"sourcesContent":["import { forEach } from 'lodash-es';\n\nexport const getAllCorrectResponses = ({ choices, alternateResponse }) => {\n alternateResponse = alternateResponse || {};\n const correctAnswers = {};\n\n forEach(choices, (respArea, key) => {\n if (!correctAnswers[key]) {\n correctAnswers[key] = [];\n }\n\n if (respArea) {\n respArea.forEach((choice) => {\n if (choice.correct) {\n correctAnswers[key].push(choice.value);\n\n if (alternateResponse[key]) {\n correctAnswers[key] = [...correctAnswers[key], ...alternateResponse[key]];\n }\n }\n });\n }\n });\n\n return correctAnswers;\n};\n"],"mappings":";;;;;;AAAA,IAAAA,SAAA,GAAAC,OAAA;AAEO,MAAMC,sBAAsB,GAAGA,CAAC;EAAEC,OAAO;EAAEC;AAAkB,CAAC,KAAK;EACxEA,iBAAiB,GAAGA,iBAAiB,IAAI,CAAC,CAAC;EAC3C,MAAMC,cAAc,GAAG,CAAC,CAAC;EAEzB,IAAAC,iBAAO,EAACH,OAAO,EAAE,CAACI,QAAQ,EAAEC,GAAG,KAAK;IAClC,IAAI,CAACH,cAAc,CAACG,GAAG,CAAC,EAAE;MACxBH,cAAc,CAACG,GAAG,CAAC,GAAG,EAAE;IAC1B;IAEA,IAAID,QAAQ,EAAE;MACZA,QAAQ,CAACD,OAAO,CAAEG,MAAM,IAAK;QAC3B,IAAIA,MAAM,CAACC,OAAO,EAAE;UAClBL,cAAc,CAACG,GAAG,CAAC,CAACG,IAAI,CAACF,MAAM,CAACG,KAAK,CAAC;UAEtC,IAAIR,iBAAiB,CAACI,GAAG,CAAC,EAAE;YAC1BH,cAAc,CAACG,GAAG,CAAC,GAAG,CAAC,GAAGH,cAAc,CAACG,GAAG,CAAC,EAAE,GAAGJ,iBAAiB,CAACI,GAAG,CAAC,CAAC;UAC3E;QACF;MACF,CAAC,CAAC;IACJ;EACF,CAAC,CAAC;EAEF,OAAOH,cAAc;AACvB,CAAC;AAACQ,OAAA,CAAAX,sBAAA,GAAAA,sBAAA","ignoreList":[]}
|
package/controller/package.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pie-element/inline-dropdown-controller",
|
|
3
3
|
"private": true,
|
|
4
|
-
"version": "8.
|
|
4
|
+
"version": "8.1.0-next.0",
|
|
5
5
|
"description": "",
|
|
6
6
|
"main": "lib/index.js",
|
|
7
7
|
"module": "src/index.js",
|
|
8
8
|
"author": "",
|
|
9
9
|
"license": "ISC",
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@pie-lib/controller-utils": "1.1.1-next.
|
|
11
|
+
"@pie-lib/controller-utils": "1.1.1-next.1",
|
|
12
12
|
"debug": "^4.1.1",
|
|
13
|
-
"lodash": "^4.17.23",
|
|
13
|
+
"lodash-es": "^4.17.23",
|
|
14
14
|
"type-of": "^2.0.1"
|
|
15
15
|
}
|
|
16
16
|
}
|
package/lib/inline-dropdown.js
CHANGED
|
@@ -10,7 +10,7 @@ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/de
|
|
|
10
10
|
var _react = _interopRequireDefault(require("react"));
|
|
11
11
|
var _reactDom = _interopRequireDefault(require("react-dom"));
|
|
12
12
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
13
|
-
var
|
|
13
|
+
var _lodashEs = require("lodash-es");
|
|
14
14
|
var _correctAnswerToggle = _interopRequireDefault(require("@pie-lib/correct-answer-toggle"));
|
|
15
15
|
var _maskMarkup = require("@pie-lib/mask-markup");
|
|
16
16
|
var _renderUi = require("@pie-lib/render-ui");
|
|
@@ -67,7 +67,7 @@ class InlineDropdown extends _react.default.Component {
|
|
|
67
67
|
});
|
|
68
68
|
}
|
|
69
69
|
UNSAFE_componentWillReceiveProps(nextProps) {
|
|
70
|
-
if ((0,
|
|
70
|
+
if ((0, _lodashEs.isEmpty)(nextProps.feedback)) {
|
|
71
71
|
this.setState({
|
|
72
72
|
showCorrectAnswer: false
|
|
73
73
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inline-dropdown.js","names":["_react","_interopRequireDefault","require","_reactDom","_propTypes","_isEmpty","_correctAnswerToggle","_maskMarkup","_renderUi","_mathRendering","_styles","StyledUiLayout","styled","UiLayout","color","text","backgroundColor","background","StyledCollapsible","Collapsible","theme","marginBottom","spacing","ChoiceRationaleWrapper","ChoiceRationale","display","whiteSpace","ChoiceRationaleLabel","correct","incorrectWithIcon","SrOnly","position","left","top","width","height","overflow","InlineDropdown","React","Component","constructor","args","_defineProperty2","default","showCorrectAnswer","setState","state","UNSAFE_componentWillReceiveProps","nextProps","isEmpty","feedback","componentDidUpdate","domNode","ReactDOM","findDOMNode","renderMath","render","prompt","mode","model","rationale","teacherInstructions","choices","displayType","language","props","extraCSSRules","showCorrectAnswerToggle","choiceRationalesHaveText","showRationale","hasText","hasMedia","showTeacherInstructions","choiceRationales","Object","keys","map","key","reduce","acc","currentValue","push","createElement","style","labels","hidden","visible","PreviewPrompt","show","toggled","onToggle","toggleShowCorrect","_extends2","index","length","choice","label","dangerouslySetInnerHTML","__html","exports","PropTypes","string","disabled","bool","markup","object","isRequired","value","onChange","func","_default"],"sources":["../src/inline-dropdown.jsx"],"sourcesContent":["import React from 'react';\nimport ReactDOM from 'react-dom';\nimport PropTypes from 'prop-types';\nimport isEmpty from 'lodash/isEmpty';\nimport CorrectAnswerToggle from '@pie-lib/correct-answer-toggle';\nimport { InlineDropdown as DropDown } from '@pie-lib/mask-markup';\nimport { color, Collapsible, hasText, hasMedia, PreviewPrompt, UiLayout } from '@pie-lib/render-ui';\nimport { renderMath } from '@pie-lib/math-rendering';\nimport { styled } from '@mui/material/styles';\n\nconst StyledUiLayout = styled(UiLayout)({\n color: color.text(),\n backgroundColor: color.background(),\n});\n\nconst StyledCollapsible = styled(Collapsible)(({ theme }) => ({\n marginBottom: theme.spacing(2),\n}));\n\nconst ChoiceRationaleWrapper = styled('div')(({ theme }) => ({\n '&:not(:last-child)': {\n marginBottom: theme.spacing(2),\n },\n}));\n\nconst ChoiceRationale = styled('div')({\n display: 'flex',\n whiteSpace: 'break-spaces',\n});\n\nconst ChoiceRationaleLabel = styled('div')(({ correct }) => ({\n display: 'flex',\n ...(correct\n ? {\n color: color.correct(),\n }\n : {\n color: color.incorrectWithIcon(),\n }),\n}));\n\nconst SrOnly = styled('h2')({\n position: 'absolute',\n left: '-10000px',\n top: 'auto',\n width: '1px',\n height: '1px',\n overflow: 'hidden',\n});\n\nexport class InlineDropdown extends React.Component {\n static propTypes = {\n prompt: PropTypes.string,\n disabled: PropTypes.bool,\n markup: PropTypes.string,\n mode: PropTypes.string,\n displayType: PropTypes.string,\n rationale: PropTypes.string,\n teacherInstructions: PropTypes.string,\n model: PropTypes.object.isRequired,\n choices: PropTypes.object,\n value: PropTypes.object,\n feedback: PropTypes.object,\n onChange: PropTypes.func,\n language: PropTypes.string,\n };\n\n static defaultProps = {\n value: {},\n };\n\n state = {\n showCorrectAnswer: false,\n };\n\n UNSAFE_componentWillReceiveProps(nextProps) {\n if (isEmpty(nextProps.feedback)) {\n this.setState({ showCorrectAnswer: false });\n }\n }\n\n componentDidUpdate() {\n // eslint-disable-next-line\n const domNode = ReactDOM.findDOMNode(this);\n\n renderMath(domNode);\n }\n\n toggleShowCorrect = () => {\n this.setState({ showCorrectAnswer: !this.state.showCorrectAnswer });\n };\n\n render() {\n const { showCorrectAnswer } = this.state;\n const { prompt, mode, model, rationale, teacherInstructions, choices, displayType, language } = this.props;\n const { extraCSSRules } = model || {};\n const showCorrectAnswerToggle = mode === 'evaluate';\n let choiceRationalesHaveText = false;\n const showRationale = rationale && (hasText(rationale) || hasMedia(rationale));\n const showTeacherInstructions =\n teacherInstructions && (hasText(teacherInstructions) || hasMedia(teacherInstructions));\n\n const choiceRationales = (Object.keys(choices) || []).map((key) =>\n (choices[key] || []).reduce((acc, currentValue) => {\n if (currentValue.rationale && hasText(currentValue.rationale)) {\n choiceRationalesHaveText = true;\n\n acc.push(currentValue);\n }\n\n return acc;\n }, []),\n );\n\n return (\n <StyledUiLayout extraCSSRules={extraCSSRules} style={{ display: `${displayType}` }}>\n {mode === 'gather' && <SrOnly>Inline Dropdown Question</SrOnly>}\n\n {showTeacherInstructions && (\n <StyledCollapsible\n labels={{ hidden: 'Show Teacher Instructions', visible: 'Hide Teacher Instructions' }}\n >\n <PreviewPrompt prompt={teacherInstructions} />\n </StyledCollapsible>\n )}\n\n {prompt && <PreviewPrompt prompt={prompt} />}\n\n <CorrectAnswerToggle\n show={showCorrectAnswerToggle}\n toggled={showCorrectAnswer}\n onToggle={this.toggleShowCorrect}\n language={language}\n />\n\n <DropDown {...this.props} showCorrectAnswer={showCorrectAnswer} />\n\n {choiceRationalesHaveText && (\n <StyledCollapsible\n labels={{ hidden: 'Show Rationale for choices', visible: 'Hide Rationale for choices' }}\n >\n {choiceRationales.map((choices, index) => (\n <ChoiceRationaleWrapper key={index}>\n {choices?.length > 0 &&\n choices.map((choice) => (\n <ChoiceRationale key={choice.label}>\n <ChoiceRationaleLabel\n correct={choice.correct}\n dangerouslySetInnerHTML={{ __html: `${choice.label}: ` }}\n />\n <PreviewPrompt prompt={choice.rationale} />\n </ChoiceRationale>\n ))}\n </ChoiceRationaleWrapper>\n ))}\n </StyledCollapsible>\n )}\n\n {showRationale && (\n <Collapsible labels={{ hidden: 'Show Rationale', visible: 'Hide Rationale' }}>\n <PreviewPrompt prompt={rationale} />\n </Collapsible>\n )}\n </StyledUiLayout>\n );\n }\n}\n\nexport default InlineDropdown;\n"],"mappings":";;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,SAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,UAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,QAAA,GAAAJ,sBAAA,CAAAC,OAAA;AACA,IAAAI,oBAAA,GAAAL,sBAAA,CAAAC,OAAA;AACA,IAAAK,WAAA,GAAAL,OAAA;AACA,IAAAM,SAAA,GAAAN,OAAA;AACA,IAAAO,cAAA,GAAAP,OAAA;AACA,IAAAQ,OAAA,GAAAR,OAAA;AAEA,MAAMS,cAAc,GAAG,IAAAC,cAAM,EAACC,kBAAQ,CAAC,CAAC;EACtCC,KAAK,EAAEA,eAAK,CAACC,IAAI,CAAC,CAAC;EACnBC,eAAe,EAAEF,eAAK,CAACG,UAAU,CAAC;AACpC,CAAC,CAAC;AAEF,MAAMC,iBAAiB,GAAG,IAAAN,cAAM,EAACO,qBAAW,CAAC,CAAC,CAAC;EAAEC;AAAM,CAAC,MAAM;EAC5DC,YAAY,EAAED,KAAK,CAACE,OAAO,CAAC,CAAC;AAC/B,CAAC,CAAC,CAAC;AAEH,MAAMC,sBAAsB,GAAG,IAAAX,cAAM,EAAC,KAAK,CAAC,CAAC,CAAC;EAAEQ;AAAM,CAAC,MAAM;EAC3D,oBAAoB,EAAE;IACpBC,YAAY,EAAED,KAAK,CAACE,OAAO,CAAC,CAAC;EAC/B;AACF,C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xC,mBAAmB,EAAEuC,kBAAS,CAACC,MAAM;EACrC1C,KAAK,EAAEyC,kBAAS,CAACK,MAAM,CAACC,UAAU;EAClC5C,OAAO,EAAEsC,kBAAS,CAACK,MAAM;EACzBE,KAAK,EAAEP,kBAAS,CAACK,MAAM;EACvBvD,QAAQ,EAAEkD,kBAAS,CAACK,MAAM;EAC1BG,QAAQ,EAAER,kBAAS,CAACS,IAAI;EACxB7C,QAAQ,EAAEoC,kBAAS,CAACC;AACtB,CAAC;AAAA,IAAA3D,gBAAA,CAAAC,OAAA,EAfUN,cAAc,kBAiBH;EACpBsE,KAAK,EAAE,CAAC;AACV,CAAC;AAAA,IAAAG,QAAA,GAAAX,OAAA,CAAAxD,OAAA,GAmGYN,cAAc","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"inline-dropdown.js","names":["_react","_interopRequireDefault","require","_reactDom","_propTypes","_lodashEs","_correctAnswerToggle","_maskMarkup","_renderUi","_mathRendering","_styles","StyledUiLayout","styled","UiLayout","color","text","backgroundColor","background","StyledCollapsible","Collapsible","theme","marginBottom","spacing","ChoiceRationaleWrapper","ChoiceRationale","display","whiteSpace","ChoiceRationaleLabel","correct","incorrectWithIcon","SrOnly","position","left","top","width","height","overflow","InlineDropdown","React","Component","constructor","args","_defineProperty2","default","showCorrectAnswer","setState","state","UNSAFE_componentWillReceiveProps","nextProps","isEmpty","feedback","componentDidUpdate","domNode","ReactDOM","findDOMNode","renderMath","render","prompt","mode","model","rationale","teacherInstructions","choices","displayType","language","props","extraCSSRules","showCorrectAnswerToggle","choiceRationalesHaveText","showRationale","hasText","hasMedia","showTeacherInstructions","choiceRationales","Object","keys","map","key","reduce","acc","currentValue","push","createElement","style","labels","hidden","visible","PreviewPrompt","show","toggled","onToggle","toggleShowCorrect","_extends2","index","length","choice","label","dangerouslySetInnerHTML","__html","exports","PropTypes","string","disabled","bool","markup","object","isRequired","value","onChange","func","_default"],"sources":["../src/inline-dropdown.jsx"],"sourcesContent":["import React from 'react';\nimport ReactDOM from 'react-dom';\nimport PropTypes from 'prop-types';\nimport { isEmpty } from 'lodash-es';\nimport CorrectAnswerToggle from '@pie-lib/correct-answer-toggle';\nimport { InlineDropdown as DropDown } from '@pie-lib/mask-markup';\nimport { color, Collapsible, hasText, hasMedia, PreviewPrompt, UiLayout } from '@pie-lib/render-ui';\nimport { renderMath } from '@pie-lib/math-rendering';\nimport { styled } from '@mui/material/styles';\n\nconst StyledUiLayout = styled(UiLayout)({\n color: color.text(),\n backgroundColor: color.background(),\n});\n\nconst StyledCollapsible = styled(Collapsible)(({ theme }) => ({\n marginBottom: theme.spacing(2),\n}));\n\nconst ChoiceRationaleWrapper = styled('div')(({ theme }) => ({\n '&:not(:last-child)': {\n marginBottom: theme.spacing(2),\n },\n}));\n\nconst ChoiceRationale = styled('div')({\n display: 'flex',\n whiteSpace: 'break-spaces',\n});\n\nconst ChoiceRationaleLabel = styled('div')(({ correct }) => ({\n display: 'flex',\n ...(correct\n ? {\n color: color.correct(),\n }\n : {\n color: color.incorrectWithIcon(),\n }),\n}));\n\nconst SrOnly = styled('h2')({\n position: 'absolute',\n left: '-10000px',\n top: 'auto',\n width: '1px',\n height: '1px',\n overflow: 'hidden',\n});\n\nexport class InlineDropdown extends React.Component {\n static propTypes = {\n prompt: PropTypes.string,\n disabled: PropTypes.bool,\n markup: PropTypes.string,\n mode: PropTypes.string,\n displayType: PropTypes.string,\n rationale: PropTypes.string,\n teacherInstructions: PropTypes.string,\n model: PropTypes.object.isRequired,\n choices: PropTypes.object,\n value: PropTypes.object,\n feedback: PropTypes.object,\n onChange: PropTypes.func,\n language: PropTypes.string,\n };\n\n static defaultProps = {\n value: {},\n };\n\n state = {\n showCorrectAnswer: false,\n };\n\n UNSAFE_componentWillReceiveProps(nextProps) {\n if (isEmpty(nextProps.feedback)) {\n this.setState({ showCorrectAnswer: false });\n }\n }\n\n componentDidUpdate() {\n // eslint-disable-next-line\n const domNode = ReactDOM.findDOMNode(this);\n\n renderMath(domNode);\n }\n\n toggleShowCorrect = () => {\n this.setState({ showCorrectAnswer: !this.state.showCorrectAnswer });\n };\n\n render() {\n const { showCorrectAnswer } = this.state;\n const { prompt, mode, model, rationale, teacherInstructions, choices, displayType, language } = this.props;\n const { extraCSSRules } = model || {};\n const showCorrectAnswerToggle = mode === 'evaluate';\n let choiceRationalesHaveText = false;\n const showRationale = rationale && (hasText(rationale) || hasMedia(rationale));\n const showTeacherInstructions =\n teacherInstructions && (hasText(teacherInstructions) || hasMedia(teacherInstructions));\n\n const choiceRationales = (Object.keys(choices) || []).map((key) =>\n (choices[key] || []).reduce((acc, currentValue) => {\n if (currentValue.rationale && hasText(currentValue.rationale)) {\n choiceRationalesHaveText = true;\n\n acc.push(currentValue);\n }\n\n return acc;\n }, []),\n );\n\n return (\n <StyledUiLayout extraCSSRules={extraCSSRules} style={{ display: `${displayType}` }}>\n {mode === 'gather' && <SrOnly>Inline Dropdown Question</SrOnly>}\n\n {showTeacherInstructions && (\n <StyledCollapsible\n labels={{ hidden: 'Show Teacher Instructions', visible: 'Hide Teacher Instructions' }}\n >\n <PreviewPrompt prompt={teacherInstructions} />\n </StyledCollapsible>\n )}\n\n {prompt && <PreviewPrompt prompt={prompt} />}\n\n <CorrectAnswerToggle\n show={showCorrectAnswerToggle}\n toggled={showCorrectAnswer}\n onToggle={this.toggleShowCorrect}\n language={language}\n />\n\n <DropDown {...this.props} showCorrectAnswer={showCorrectAnswer} />\n\n {choiceRationalesHaveText && (\n <StyledCollapsible\n labels={{ hidden: 'Show Rationale for choices', visible: 'Hide Rationale for choices' }}\n >\n {choiceRationales.map((choices, index) => (\n <ChoiceRationaleWrapper key={index}>\n {choices?.length > 0 &&\n choices.map((choice) => (\n <ChoiceRationale key={choice.label}>\n <ChoiceRationaleLabel\n correct={choice.correct}\n dangerouslySetInnerHTML={{ __html: `${choice.label}: ` }}\n />\n <PreviewPrompt prompt={choice.rationale} />\n </ChoiceRationale>\n ))}\n </ChoiceRationaleWrapper>\n ))}\n </StyledCollapsible>\n )}\n\n {showRationale && (\n <Collapsible labels={{ hidden: 'Show Rationale', visible: 'Hide Rationale' }}>\n <PreviewPrompt prompt={rationale} />\n </Collapsible>\n )}\n </StyledUiLayout>\n );\n }\n}\n\nexport default InlineDropdown;\n"],"mappings":";;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,SAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,UAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,SAAA,GAAAH,OAAA;AACA,IAAAI,oBAAA,GAAAL,sBAAA,CAAAC,OAAA;AACA,IAAAK,WAAA,GAAAL,OAAA;AACA,IAAAM,SAAA,GAAAN,OAAA;AACA,IAAAO,cAAA,GAAAP,OAAA;AACA,IAAAQ,OAAA,GAAAR,OAAA;AAEA,MAAMS,cAAc,GAAG,IAAAC,cAAM,EAACC,kBAAQ,CAAC,CAAC;EACtCC,KAAK,EAAEA,eAAK,CAACC,IAAI,CAAC,CAAC;EACnBC,eAAe,EAAEF,eAAK,CAACG,UAAU,CAAC;AACpC,CAAC,CAAC;AAEF,MAAMC,iBAAiB,GAAG,IAAAN,cAAM,EAACO,qBAAW,CAAC,CAAC,CAAC;EAAEC;AAAM,CAAC,MAAM;EAC5DC,YAAY,EAAED,KAAK,CAACE,OAAO,CAAC,CAAC;AAC/B,CAAC,CAAC,CAAC;AAEH,MAAMC,sBAAsB,GAAG,IAAAX,cAAM,EAAC,KAAK,CAAC,CAAC,CAAC;EAAEQ;AAAM,CAAC,MAAM;EAC3D,oBAAoB,EAAE;IACpBC,YAAY,EAAED,KAAK,CAACE,OAAO,CAAC,CAAC;EAC/B;AACF,CAAC,CAAC,CAAC;AAEH,MAAME,eAAe,GAAG,IAAAZ,cAAM,EAAC,KAAK,CAAC,CAAC;EACpCa,OAAO,EAAE,MAAM;EACfC,UAAU,EAAE;AACd,CAAC,CAAC;AAEF,MAAMC,oBAAoB,GAAG,IAAAf,cAA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vBvD,QAAQ,EAAEkD,kBAAS,CAACK,MAAM;EAC1BG,QAAQ,EAAER,kBAAS,CAACS,IAAI;EACxB7C,QAAQ,EAAEoC,kBAAS,CAACC;AACtB,CAAC;AAAA,IAAA3D,gBAAA,CAAAC,OAAA,EAfUN,cAAc,kBAiBH;EACpBsE,KAAK,EAAE,CAAC;AACV,CAAC;AAAA,IAAAG,QAAA,GAAAX,OAAA,CAAAxD,OAAA,GAmGYN,cAAc","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pie-element/inline-dropdown",
|
|
3
|
+
"repository": {
|
|
4
|
+
"type": "git",
|
|
5
|
+
"url": "https://github.com/pie-framework/pie-elements"
|
|
6
|
+
},
|
|
3
7
|
"publishConfig": {
|
|
4
8
|
"access": "public"
|
|
5
9
|
},
|
|
6
|
-
"
|
|
7
|
-
"version": "9.0.0-next.42+bb1f3eb4e",
|
|
10
|
+
"version": "9.1.0-next.0+20d879b",
|
|
8
11
|
"description": "",
|
|
9
12
|
"scripts": {
|
|
10
13
|
"postpublish": "../../scripts/postpublish"
|
|
@@ -15,18 +18,18 @@
|
|
|
15
18
|
"@mui/icons-material": "^7.3.4",
|
|
16
19
|
"@mui/material": "^7.3.4",
|
|
17
20
|
"@pie-framework/pie-player-events": "^0.1.0",
|
|
18
|
-
"@pie-lib/correct-answer-toggle": "3.1.1-next.
|
|
19
|
-
"@pie-lib/mask-markup": "2.1.1-next.
|
|
20
|
-
"@pie-lib/math-rendering": "4.1.1-next.
|
|
21
|
-
"@pie-lib/render-ui": "5.1.1-next.
|
|
22
|
-
"lodash": "^4.17.23",
|
|
21
|
+
"@pie-lib/correct-answer-toggle": "3.1.1-next.1",
|
|
22
|
+
"@pie-lib/mask-markup": "2.1.1-next.3",
|
|
23
|
+
"@pie-lib/math-rendering": "4.1.1-next.1",
|
|
24
|
+
"@pie-lib/render-ui": "5.1.1-next.1",
|
|
25
|
+
"lodash-es": "^4.17.23",
|
|
23
26
|
"prop-types": "^15.8.1",
|
|
24
|
-
"react": "18.
|
|
25
|
-
"react-dom": "18.
|
|
27
|
+
"react": "18.3.1",
|
|
28
|
+
"react-dom": "18.3.1"
|
|
26
29
|
},
|
|
27
30
|
"author": "",
|
|
28
31
|
"license": "ISC",
|
|
29
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "20d879b8b8fa74decf5028d860d54cd09cbdf051",
|
|
30
33
|
"main": "lib/index.js",
|
|
31
34
|
"module": "src/index.js"
|
|
32
35
|
}
|
package/module/configure.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{_dll_react_dom as e,_dll_react as t,_dll_prop_types as o,_dll_mui__material_styles as i,_dll_lodash as n,_dll_pie_lib__render_ui as a,_dll_mui__icons_material as s,_dll_mui__material as l,_dll_debug as r}from"../../../@pie-lib/shared-module@^3.0.5/module/index.js";import{_dll_pie_lib__editable_html_tip_tap as c}from"../../../@pie-lib/editable-html-module@^6.0.5/module/index.js";import{_dll_pie_lib__config_ui as d}from"../../../@pie-lib/config-module@^3.0.0/module/index.js";import{_dll_pie_lib__math_rendering as p}from"../../../@pie-lib/math-rendering-module@^4.0.5/module/index.js";var h={};Object.defineProperty(h,"__esModule",{value:!0});class u extends CustomEvent{constructor(e,t=!1){super(u.TYPE,{bubbles:!0,detail:{update:e,reset:t}}),this.update=e,this.reset=t}}u.TYPE="model.updated";var g=h.ModelUpdatedEvent=u;class m extends CustomEvent{constructor(e,t){super(m.TYPE,{bubbles:!0,detail:{src:e,done:t}}),this.src=e,this.done=t}}m.TYPE="delete.image";var _=h.DeleteImageEvent=m;class C extends CustomEvent{constructor(e){super(C.TYPE,{bubbles:!0,detail:e}),this.handler=e}}C.TYPE="insert.image";var b=h.InsertImageEvent=C;class f extends CustomEvent{constructor(e,t){super(f.TYPE,{bubbles:!0,detail:{src:e,done:t}}),this.src=e,this.done=t}}f.TYPE="delete.sound";var E=h.DeleteSoundEvent=f;class S extends CustomEvent{constructor(e){super(S.TYPE,{bubbles:!0,detail:e}),this.handler=e}}S.TYPE="insert.sound";var v,y=h.InsertSoundEvent=S,x=e;v=x.createRoot,x.hydrateRoot;const A=(e={},t={})=>({...t,...e}),R=t,k=e,I=o,{styled:M}=i,{isEqual:w}=n,{isEmpty:T}=n,{color:P}=a,{Add:D}=s,{Check:q}=s,{Close:O}=s,{Edit:z}=s,{IconButton:H}=l,L=c,{renderMath:$}=p;function B(e){let t,o=e[0],i=1;for(;i<e.length;){const n=e[i],a=e[i+1];if(i+=2,("optionalAccess"===n||"optionalCall"===n)&&null==o)return;"access"===n||"optionalAccess"===n?(t=o,o=a(o)):"call"!==n&&"optionalCall"!==n||(o=a((...e)=>o.call(t,...e)),t=void 0)}return o}const j=M("div")(({theme:e})=>({display:"flex",alignItems:"flex-start",position:"relative",background:e.palette.common.white,borderBottom:`1px solid ${e.palette.grey[400]}`,"&:last-child":{borderRadius:"0 0 4px 4px"}})),W=M("div")(({theme:e})=>({display:"flex",justifyContent:"center",color:e.palette.common.white,fontSize:e.typography.fontSize,fontStyle:"normal",position:"absolute",transform:"translate(0, -50%)",backgroundColor:P.correct(),borderRadius:"50%",top:e.spacing(2),left:e.spacing(1),zIndex:3})),Y=M("div")(({theme:e,correct:t})=>({flex:1,padding:e.spacing(.75),paddingLeft:e.spacing(3.5),...t&&{background:P.correctSecondary()}})),U=M("div")(({theme:e})=>({margin:e.spacing(.5),display:"flex"})),N=M(H)(({theme:e})=>({fontSize:e.typography.fontSize,padding:e.spacing(.5),color:e.palette.common.black}));class F extends R.Component{constructor(...e){super(...e),F.prototype.__init.call(this),F.prototype.__init2.call(this)}static __initStatic(){this.propTypes={correct:I.bool.isRequired,onClick:I.func.isRequired,onRemoveChoice:I.func.isRequired,onEditChoice:I.func.isRequired,value:I.string.isRequired}}__init(){this.onRemoveClick=e=>{const{onRemoveChoice:t}=this.props;e.preventDefault(),e.stopPropagation(),t()}}__init2(){this.onEditClick=e=>{const{onEditChoice:t}=this.props;e.preventDefault(),e.stopPropagation(),t()}}render(){const{correct:e,onClick:t,value:o}=this.props;return R.createElement(j,null,e&&R.createElement(W,{onClick:t},R.createElement(q,{fontSize:"inherit"})),R.createElement(Y,{correct:e,onClick:t,dangerouslySetInnerHTML:{__html:o}}),R.createElement(U,null,R.createElement(N,{onClick:this.onEditClick,size:"small","aria-label":"Edit"},R.createElement(z,{fontSize:"inherit"})),R.createElement(N,{onClick:this.onRemoveClick,size:"small","aria-label":"Remove"},R.createElement(O,{fontSize:"inherit"}))))}}F.__initStatic();const G=F,K=M("div")(({theme:e})=>({boxShadow:e.shadows[2],borderRadius:"4px",width:"400px"})),V=M(L)(({theme:e})=>({borderRadius:"4px",backgroundColor:e.palette.common.white,'& [data-slate-editor="true"]':{minHeight:"initial !important"}})),J=M(H)(({theme:e})=>({fontSize:e.typography.fontSize+2,padding:e.spacing(.5),color:e.palette.common.black,position:"absolute",top:"50%",right:e.spacing(2),transform:"translate(0, -50%)"})),Q=M("div")({display:"flex",flexDirection:"column","& > div:last-child":{border:"none"}}),X=M("div")(({theme:e})=>({padding:e.spacing(.5),position:"relative"}));class Z extends R.Component{constructor(...e){super(...e),Z.prototype.__init3.call(this),Z.prototype.__init4.call(this),Z.prototype.__init5.call(this),Z.prototype.__init6.call(this),Z.prototype.__init7.call(this),Z.prototype.__init8.call(this),Z.prototype.__init9.call(this),Z.prototype.__init10.call(this),Z.prototype.__init11.call(this),Z.prototype.__init12.call(this),Z.prototype.__init13.call(this),Z.prototype.__init14.call(this),Z.prototype.__init15.call(this)}static __initStatic2(){this.propTypes={node:I.object,uploadSoundSupport:I.object,onDone:I.func,choices:I.array,onAddChoice:I.func.isRequired,onCheck:I.func,onRemoveChoice:I.func.isRequired,onSelectChoice:I.func.isRequired,onToolbarDone:I.func.isRequired,editor:I.object,spellCheck:I.bool}}__init3(){this.clickedInside=!1}__init4(){this.preventDone=!1}__init5(){this.state={respAreaMarkup:"",editedChoiceIndex:-1}}componentDidMount(){const{editor:e}=this.props,t=e.view.nodeDOM(e.state.selection.from);if(1===B([t,"optionalAccess",e=>e.nodeType])){const e=t.getBoundingClientRect(),o=t.closest(".tiptap").getBoundingClientRect(),i=e.top-e.height,n=e.left-o.left;this.setState({toolbarStyle:{position:"absolute",top:`${i+e.height+40}px`,left:`${n+25}px`}})}}componentDidUpdate(){const e=k.findDOMNode(this);$(e)}__init6(){this.onRespAreaChange=e=>{this.setState({respAreaMarkup:e})}}__init7(){this.onAddChoice=()=>{const{editor:e}=this.props,{tr:t}=e.state;t.isDone=!0,e.view.dispatch(t)}}__init8(){this.onDone=e=>{const{choices:t,node:o,editor:i,onAddChoice:n,onToolbarDone:a}=this.props,{editedChoiceIndex:s}=this.state,l=(e=>{const t=document.createElement("div");return t.innerHTML=(e||"").trim(),t})(e).textContent.trim();s>=0&&B([t,"optionalAccess",e=>e[s],"optionalAccess",e=>e.correct])&&(i.commands.updateAttributes("inline_dropdown",{value:e}),a(!1)),T(l)||(n(o.attrs.index,e,s),i.commands.refreshResponseArea()),this.setState({editedChoiceIndex:-1})}}__init9(){this.onSelectChoice=(e,t)=>{const{node:o,editor:i,onToolbarDone:n,onSelectChoice:a}=this.props;i.commands.updateAttributes("inline_dropdown",{value:e}),n(!1),a(t),i.commands.refreshResponseArea()}}__init10(){this.onRemoveChoice=(e,t)=>{const{node:o,editor:i,onToolbarDone:n,onRemoveChoice:a}=this.props;console.log("LOGGING",e,o.attrs.value,w(e,o.attrs.value)),w(e,o.attrs.value)&&(i.commands.updateAttributes("explicit_constructed_response",{value:null}),n(!1)),a(t),i.commands.refreshResponseArea()}}__init11(){this.onEditChoice=(e,t)=>{this.onRespAreaChange(e),this.setState({editedChoiceIndex:t})}}__init12(){this.onKeyDown=e=>{if("Enter"===e.key)return this.preventDone=!1,this.onAddChoice(),!1}}__init13(){this.onBlur=()=>{if(this.clickedInside)return void(this.clickedInside=!1);const{node:e,choices:t,onCheck:o,onToolbarDone:i,editor:n}=this.props,a=(t||[]).find(e=>e.correct);this.onAddChoice(),(!t||t&&t.length<2||!a)&&o(()=>{const{tr:e}=n.state;e.deleteSelection(),n.view.dispatch(e),i(!1)})}}__init14(){this.onClickInside=()=>{this.clickedInside=!0}}__init15(){this.focusInput=()=>{const e=this.editorRef&&this.editorRef.rootRef&&this.editorRef.rootRef.slateEditor,t=e&&e.editorRef&&e.editorRef.element;t&&t.focus()}}render(){const{choices:e,spellCheck:t,uploadSoundSupport:o,mathMlOptions:i={},baseInputConfiguration:n={},responseAreaInputConfiguration:a={}}=this.props,{respAreaMarkup:s,toolbarStyle:l}=this.state;return l?R.createElement(K,{style:{...l,backgroundColor:"#E0E1E6"},onMouseDown:this.onClickInside},R.createElement(X,null,R.createElement(V,{ref:e=>{e&&(this.editorRef=e)},autoFocus:!0,autoSave:!0,toolbarOpts:{position:"top",alwaysVisible:!1,showDone:!1,doneOn:"blur"},markup:s,onKeyDown:this.onKeyDown,languageCharactersProps:[{language:"spanish"},{language:"special"}],onChange:e=>{this.preventDone||this.onRespAreaChange(e)},onDone:e=>{this.preventDone||this.onDone(e)},onBlur:e=>{if(!e.relatedTarget)return;const t=!(!e.relatedTarget||!e.relatedTarget.closest(".insert-character-dialog")),o=!(!e.relatedTarget||!e.relatedTarget.closest('[aria-label="Done"]'));this.preventDone=t||o,(t||o)&&(this.clickedInside=!0),this.onBlur(e)},placeholder:"Add Choice",pluginProps:A(B([a,"optionalAccess",e=>e.inputConfiguration]),n),spellCheck:t,uploadSoundSupport:o,mathMlOptions:i}),R.createElement(J,{onMouseDown:()=>this.focusInput(),onClick:()=>this.onAddChoice(),size:"small","aria-label":"Add"},R.createElement(D,{fontSize:"inherit"}))),e&&R.createElement(Q,null,e.map(({label:e,correct:t},o)=>R.createElement(G,{key:o,onClick:()=>this.onSelectChoice(e,o),onRemoveChoice:()=>this.onRemoveChoice(e,o),onEditChoice:()=>this.onEditChoice(e,o),value:e,correct:t})))):null}}Z.__initStatic2();const ee=Z,te=t,oe=e,ie=o,{styled:ne}=i,ae=c,{renderMath:se}=p,le=ne("div")(({theme:e})=>({paddingBottom:e.spacing(2.5)})),re=ne("div")(({theme:e})=>({fontSize:e.typography.fontSize-2,color:e.palette.error.main,paddingTop:e.spacing(1)}));class ce extends te.Component{static __initStatic(){this.propTypes={editableHtmlProps:ie.object.isRequired,responseAreasError:ie.string,responseAreaChoicesError:ie.string}}componentDidMount(){const e=oe.findDOMNode(this);se(e)}render(){const{editableHtmlProps:e,responseAreasError:t,responseAreaChoicesError:o}=this.props;return te.createElement(le,null,te.createElement(ae,{...e}),t&&te.createElement(re,null,t),o&&te.createElement(re,null,o))}}ce.__initStatic();const de=t,pe=e,he=o,{color:ue}=a,{cloneDeep:ge}=n,{isEqual:me}=n,{isUndefined:_e}=n,{isEmpty:Ce}=n,{reduce:be}=n,{max:fe}=n,{styled:Ee}=i,{Tooltip:Se}=l,{Typography:ve}=l,{Accordion:ye}=l,{AccordionSummary:xe}=l,{AccordionDetails:Ae}=l,{ExpandMore:Re}=s,{Info:ke}=s,Ie=c,{ALL_PLUGINS:Me}=c,{AlertDialog:we}=d,{InputContainer:Te}=d,{layout:Pe}=d,{settings:De}=d,{renderMath:qe}=p;function Oe(e){let t,o=e[0],i=1;for(;i<e.length;){const n=e[i],a=e[i+1];if(i+=2,("optionalAccess"===n||"optionalCall"===n)&&null==o)return;"access"===n||"optionalAccess"===n?(t=o,o=a(o)):"call"!==n&&"optionalCall"!==n||(o=a((...e)=>o.call(t,...e)),t=void 0)}return o}const{toggle:ze,Panel:He,dropdown:Le}=De,$e=Ee(Te)(({theme:e})=>({width:"100%",paddingTop:e.spacing(2),marginBottom:e.spacing(2)})),Be=Ee(Te)(({theme:e})=>({width:"100%",paddingTop:e.spacing(.5),marginBottom:e.spacing(2)})),je=Ee(ve)(({theme:e})=>({fontSize:e.typography.fontSize+2,marginRight:e.spacing(1)})),We=Ee("span")(({theme:e})=>({display:"flex",alignItems:"center",whiteSpace:"break-spaces",color:ue.disabled(),padding:0,fontSize:e.typography.fontSize-2,lineHeight:1})),Ye=Ee("div")(({theme:e})=>({marginBottom:e.spacing(2.5)})),Ue=Ee(Ae)({display:"block",paddingTop:0,paddingBottom:0}),Ne=Ee("div")(({theme:e})=>({display:"flex",alignItems:"center",marginBottom:e.spacing(1)})),Fe=Ee(Se)(({theme:e})=>({"& .MuiTooltip-tooltip":{fontSize:e.typography.fontSize-2,whiteSpace:"pre",maxWidth:"500px"}})),Ge=Ee("div")(({theme:e})=>({fontSize:e.typography.fontSize-2,color:e.palette.error.main,paddingTop:e.spacing(1)}));class Ke extends de.Component{constructor(...e){super(...e),Ke.prototype.__init.call(this),Ke.prototype.__init2.call(this),Ke.prototype.__init3.call(this),Ke.prototype.__init4.call(this),Ke.prototype.__init5.call(this),Ke.prototype.__init6.call(this),Ke.prototype.__init7.call(this),Ke.prototype.__init8.call(this),Ke.prototype.__init9.call(this),Ke.prototype.__init10.call(this),Ke.prototype.__init11.call(this),Ke.prototype.__init12.call(this)}static __initStatic(){this.propTypes={configuration:he.object.isRequired,model:he.object.isRequired,disableSidePanel:he.bool,onModelChanged:he.func.isRequired,onConfigurationChanged:he.func.isRequired,imageSupport:he.shape({add:he.func.isRequired,delete:he.func.isRequired}),uploadSoundSupport:he.shape({add:he.func.isRequired,delete:he.func.isRequired})}}__init(){this.state={warning:{open:!1}}}componentDidMount(){const{model:{choices:e}}=this.props;this.setState({respAreaChoices:ge(e)})}UNSAFE_componentWillReceiveProps(e){const t={};me(e.model.choices,this.props.model.choices)&&me(e.model.choices,this.state.respAreaChoices)||(t.respAreaChoices=ge(e.model.choices)),Ce(t)||this.setState(t)}componentDidUpdate(){const e=pe.findDOMNode(this);qe(e)}__init2(){this.onModelChange=e=>{this.props.onModelChanged({...this.props.model,...e})}}__init3(){this.onPromptChanged=e=>{this.onModelChange({prompt:e})}}__init4(){this.onRationaleChanged=e=>{this.onModelChange({rationale:e})}}__init5(){this.onChoiceRationaleChanged=(e,t)=>{const{model:o}=this.props,i=o.choices&&o.choices[e]&&o.choices[e].findIndex(e=>e.label===t.label&&e.value===t.value);o.choices[e]&&o.choices[e].splice(i,1,t),this.onModelChange(o)}}__init6(){this.onTeacherInstructionsChanged=e=>{this.onModelChange({teacherInstructions:e})}}__init7(){this.onMarkupChanged=e=>{this.onModelChange({slateMarkup:e})}}__init8(){this.onCheck=e=>{this.setState({warning:{open:!0,text:"Response areas with under 2 options or with no correct answers will be discarded.",onClose:()=>{this.setState({warning:{open:!1}})},onConfirm:()=>{this.setState({warning:{open:!1}},e)}}})}}__init9(){this.onChange=e=>{const{respAreaChoices:t}=this.state,o=(e=>{const t=document.createElement("div");return t.innerHTML=(e||"").trim(),t})(e),i=o.querySelectorAll('[data-type="inline_dropdown"]'),n={};i.forEach(e=>{n[e.dataset.index]=e.dataset.value||""});const a=be(t,(e,o,i)=>(_e(n[i])||(e[i]=t[i]),e),{}),s={};let l=!1;i.forEach((e,t)=>{const o=a[e.dataset.index]||[];o.length<2||!o.find(e=>e.correct)?(e.remove(),l=!0):(s[t]=a[e.dataset.index]||[],e.dataset.index=t)}),l?this.setState({warning:{open:!0,text:"Response areas with under 2 options or with no correct answers will be discarded.",onClose:()=>{this.setState({warning:{open:!1}})},onConfirm:()=>{this.setState({warning:{open:!1}},()=>this.onModelChange({choices:ge(s),slateMarkup:o.innerHTML}))}}}):this.onModelChange({choices:ge(s),slateMarkup:o.innerHTML})}}__init10(){this.onAddChoice=(e,t,o)=>{const{respAreaChoices:i}=this.state,{maxResponseAreaChoices:n}=this.props.configuration;if(i[e]&&i[e].length>=n)this.setState({warning:{open:!0,text:`There are only ${n} answers allowed per choice.`,onClose:void 0,onConfirm:()=>{this.setState({warning:{open:!1}})}}});else if(i[e]||(i[e]=[]),(i[e]||[]).find((e,i)=>e.label===t&&i!==o))this.setState({warning:{open:!0,text:"Duplicate answers are not allowed.",onClose:void 0,onConfirm:()=>{this.setState({warning:{open:!1}})}}});else{if(o>=0&&Oe([i,"access",t=>t[e],"optionalAccess",e=>e[o]]))i[e][o].label=t;else{const o=i[e]&&fe(i[e].map(e=>parseInt(e.value)).filter(e=>!isNaN(e)))||0;i[e].push({label:t,value:`${o+1}`,correct:!1})}this.onModelChange({choices:ge(i)})}}}__init11(){this.onRemoveChoice=(e,t)=>{const{respAreaChoices:o}=this.state;o[e].splice(t,1),this.onModelChange({choices:ge(o)})}}__init12(){this.onSelectChoice=(e,t)=>{const{respAreaChoices:o}=this.state;o[e]=o[e].map((e,o)=>({...e,correct:o===t})),this.onModelChange({choices:ge(o)})}}render(){const{warning:e}=this.state,{model:t,configuration:o,onConfigurationChanged:i,imageSupport:n,uploadSoundSupport:a}=this.props,{baseInputConfiguration:s={},choiceRationale:l={},contentDimensions:r={},lockChoiceOrder:c={},maxResponseAreas:d,maxImageWidth:p={},maxImageHeight:h={},partialScoring:u={},prompt:g={},rationale:m={},settingsPanelDisabled:_,spellCheck:C={},teacherInstructions:b={},template:f={},withRubric:E={},mathMlOptions:S={},language:v={},languageChoices:y={},responseAreaInputConfiguration:x={}}=o||{},{choiceRationaleEnabled:A,choices:R,errors:k,extraCSSRules:I,promptEnabled:M,rationaleEnabled:w,spellCheckEnabled:T,teacherInstructionsEnabled:P,toolbarEditorPosition:D}=t||{},{prompt:q,rationale:O,responseAreasError:z,responseAreaChoicesError:H,teacherInstructions:L}=k||{},$=p&&p.prompt,B=h&&h.prompt,j={position:"top"===D?"top":"bottom"},W=(e=>{const{maxResponseAreas:t,maxResponseAreaChoices:o}=e;return"Validation requirements:\nThere should be at least 1 "+(t?`and at most ${t} `:"")+"response area"+(t?"s":"")+" defined."+(o?`\nThere should be at most ${o} choices defined per response area.`:"")})(o),Y={partialScoring:u.settings&&ze(u.label),lockChoiceOrder:c.settings&&ze(c.label),"language.enabled":v.settings&&ze(v.label,!0),language:v.settings&&v.enabled&&Le(y.label,y.options)},U={teacherInstructionsEnabled:b.settings&&ze(b.label),rationaleEnabled:m.settings&&ze(m.label),choiceRationaleEnabled:l.settings&&ze(l.label),promptEnabled:g.settings&&ze(g.label),spellCheckEnabled:C.settings&&ze(C.label),rubricEnabled:Oe([E,"optionalAccess",e=>e.settings])&&ze(Oe([E,"optionalAccess",e=>e.label]))},N=(e={})=>({...s,...e});return de.createElement(Pe.ConfigLayout,{extraCSSRules:{names:["red","blue"],rules:"\n .red {\n color: red !important;\n }\n\n .blue {\n color: blue !important;\n }\n "},dimensions:r,hideSettings:_,settings:de.createElement(He,{model:t,configuration:o,onChangeModel:e=>this.onModelChange(e),onChangeConfiguration:e=>i(e,!0),groups:{Settings:Y,Properties:U}})},P&&de.createElement($e,{label:b.label},de.createElement(Ie,{markup:t.teacherInstructions||"",onChange:this.onTeacherInstructionsChanged,imageSupport:n,nonEmpty:!1,error:L,toolbarOpts:j,pluginProps:N(Oe([b,"optionalAccess",e=>e.inputConfiguration])),spellCheck:T,maxImageWidth:p&&p.teacherInstructions||$,maxImageHeight:h&&h.teacherInstructions||B,uploadSoundSupport:a,languageCharactersProps:[{language:"spanish"},{language:"special"}],mathMlOptions:S}),L&&de.createElement(Ge,null,L)),M&&de.createElement($e,{label:g.label},de.createElement(Ie,{markup:t.prompt,onChange:this.onPromptChanged,imageSupport:n,nonEmpty:!1,disableUnderline:!0,error:q,toolbarOpts:j,pluginProps:N(Oe([g,"optionalAccess",e=>e.inputConfiguration])),spellCheck:T,maxImageWidth:$,maxImageHeight:B,uploadSoundSupport:a,languageCharactersProps:[{language:"spanish"},{language:"special"}],mathMlOptions:S}),q&&de.createElement(Ge,null,q)),de.createElement(Ne,null,de.createElement(je,{component:"div"},"Define Template, Choices, and Correct Responses"),de.createElement(Fe,{disableFocusListener:!0,disableTouchListener:!0,placement:"right",title:W},de.createElement(ke,{fontSize:"small",color:"primary"}))),de.createElement(ce,{responseAreasError:z,responseAreaChoicesError:H,editableHtmlProps:{pluginProps:N(Oe([f,"optionalAccess",e=>e.inputConfiguration])),activePlugins:Me,toolbarOpts:{position:"top"},extraCSSRules:{names:["red","blue"],rules:"\n .red {\n color: red !important;\n }\n\n .blue {\n color: blue !important;\n }\n "},responseAreaProps:{type:"inline-dropdown",options:{duplicates:!0},maxResponseAreas:d,respAreaToolbar:(e,t,o)=>{const{respAreaChoices:i}=this.state;return()=>de.createElement(ee,{onAddChoice:this.onAddChoice,onCheck:this.onCheck,onRemoveChoice:t=>this.onRemoveChoice(e.attrs.index,t),onSelectChoice:t=>this.onSelectChoice(e.attrs.index,t),node:e,editor:t,onToolbarDone:o,choices:i[e.attrs.index],spellCheck:T,uploadSoundSupport:a,mathMlOptions:S,baseInputConfiguration:s,responseAreaInputConfiguration:x})}},spellCheck:T,markup:t.slateMarkup||"",onChange:this.onChange,imageSupport:n,disableImageAlignmentButtons:!0,disabled:!1,highlightShape:!1,error:z,uploadSoundSupport:a,languageCharactersProps:[{language:"spanish"},{language:"special"}],mathMlOptions:S}}),A&&(()=>(Object.keys(R)||[]).map((e,t)=>de.createElement(Ye,{key:e},de.createElement(ye,{slotProps:{transition:{timeout:{enter:225,exit:195}}}},de.createElement(xe,{expandIcon:de.createElement(Re,null)},de.createElement(je,{component:"div"},`Rationale for response area #${t+1}`)),de.createElement(Ue,null,(R[e]||[]).map(t=>de.createElement(de.Fragment,{key:t.label},de.createElement(We,{dangerouslySetInnerHTML:{__html:`${m.label} for ${t.label} (${t.correct?"correct":"incorrect"})`}}),de.createElement(Be,null,de.createElement(Ie,{markup:t.rationale||"",spellCheck:T,onChange:o=>this.onChoiceRationaleChanged(e,{...t,rationale:o}),imageSupport:n,maxImageWidth:p&&p.rationale||$,maxImageHeight:h&&h.rationale||B,uploadSoundSupport:a,mathMlOptions:S})))))))))(),w&&de.createElement($e,{label:m.label},de.createElement(Ie,{markup:t.rationale||"",onChange:this.onRationaleChanged,imageSupport:n,error:O,toolbarOpts:j,pluginProps:N(Oe([m,"optionalAccess",e=>e.inputConfiguration])),spellCheck:T,maxImageWidth:p&&p.rationale||$,maxImageHeight:h&&h.rationale||B,uploadSoundSupport:a,languageCharactersProps:[{language:"spanish"},{language:"special"}],mathMlOptions:S}),O&&de.createElement(Ge,null,O)),de.createElement(we,{open:e.open,title:"Warning",text:e.text,onClose:e.onClose,onConfirm:e.onConfirm,disableAutoFocus:!0,disableEnforceFocus:!0,disableRestoreFocus:!0}))}}Ke.__initStatic();var Ve={alternateResponse:{},choiceRationaleEnabled:!0,choices:{},disabled:!1,displayType:"block",markup:"",mode:"gather",prompt:"",promptEnabled:!0,rationale:"",rationaleEnabled:!0,shuffle:!0,studentInstructionsEnabled:!0,teacherInstructions:"",teacherInstructionsEnabled:!0,toolbarEditorPosition:"bottom"},Je={baseInputConfiguration:{audio:{disabled:!1},video:{disabled:!1},image:{disabled:!1},h3:{disabled:!0},blockquote:{disabled:!0},textAlign:{disabled:!0},showParagraphs:{disabled:!1},separateParagraphs:{disabled:!0}},prompt:{settings:!0,label:"Prompt",required:!1,inputConfiguration:{audio:{disabled:!1},video:{disabled:!1},image:{disabled:!1}}},responseAreaInputConfiguration:{inputConfiguration:{audio:{disabled:!0},video:{disabled:!0},image:{disabled:!0},table:{disabled:!0},ul_list:{disabled:!0},ol_list:{disabled:!0}}},settingsPanelDisabled:!1,spellCheck:{label:"Spellcheck",settings:!1,enabled:!0},lockChoiceOrder:{settings:!0,label:"Lock Choice Order"},partialScoring:{settings:!1,label:"Allow Partial Scoring"},rationale:{settings:!0,label:"Rationale",required:!1,inputConfiguration:{audio:{disabled:!1},video:{disabled:!1},image:{disabled:!1}}},teacherInstructions:{settings:!0,label:"Teacher Instructions",required:!1,inputConfiguration:{audio:{disabled:!1},video:{disabled:!1},image:{disabled:!1}}},template:{inputConfiguration:{audio:{disabled:!1},video:{disabled:!1},image:{disabled:!1}}},choiceRationale:{settings:!0,label:"Choice Rationale"},toolbarEditorPosition:{settings:!1,label:"Toolbar Editor Position"},maxResponseAreas:10,maxResponseAreaChoices:10,maxImageWidth:{teacherInstructions:300,prompt:300,rationale:300},maxImageHeight:{teacherInstructions:300,prompt:300,rationale:300},withRubric:{settings:!1,label:"Add Rubric"},mathMlOptions:{mmlOutput:!1,mmlEditing:!1},language:{settings:!1,label:"Specify Language",enabled:!1},languageChoices:{label:"Language Choices",options:[]}};const{escape:Qe}=n,Xe="imes|riangle|an|heta|herefore",Ze="throot|parallel|cong|approx|eq|e|sim",et=new RegExp(`(\\t(?!${Xe}))|(\\n(?!${Ze}))|(\\\\t(?!${Xe}))|(\\\\n(?!${Ze}))`,"g"),tt=e=>e.replace(et,"").replace(/\\"/g,'"').replace(/\\\//g,"/"),ot=/\{\{(\d+)\}\}/g,it=t,nt=r,{defaults:at}=n;function st(e){let t,o=e[0],i=1;for(;i<e.length;){const n=e[i],a=e[i+1];if(i+=2,("optionalAccess"===n||"optionalCall"===n)&&null==o)return;"access"===n||"optionalAccess"===n?(t=o,o=a(o)):"call"!==n&&"optionalCall"!==n||(o=a((...e)=>o.call(t,...e)),t=void 0)}return o}const lt=nt("multiple-choice:configure");class rt extends HTMLElement{static __initStatic(){this.prepareModel=(e={})=>{const t={...Ve,...e},o=e.slateMarkup||((e,t)=>tt(e).replace(ot,(e,o)=>(e=>{let o=t[e]&&t[e].find(e=>e.correct);return o&&o.value||(o={id:"",value:"",label:""}),`<span data-type="inline_dropdown" data-index="${e}" data-value="${Qe(o.label)}"></span>`})(o)))(t.markup,t.choices),i=(e=>{const t=(e=>{const t=document.createElement("div");return t.innerHTML=e.trim(),t})(tt(e));return t.querySelectorAll('[data-type="inline_dropdown"]').forEach(e=>{e.replaceWith(`{{${e.dataset.index}}}`)}),t.innerHTML})(o);return{...t,slateMarkup:o,markup:i}}}constructor(){super(),this._root=null,this._model=rt.prepareModel(),this._configuration=Je,this.onModelChanged=this.onModelChanged.bind(this),this.onConfigurationChanged=this.onConfigurationChanged.bind(this)}set model(e){this._model=rt.prepareModel(e),this._render()}set configuration(e){this._configuration=at(e,Je),st([e,"access",e=>e.language,"optionalAccess",e=>e.enabled])?st([e,"access",e=>e.languageChoices,"optionalAccess",e=>e.options,"optionalAccess",e=>e.length])&&(this._model.language=e.languageChoices.options[0].value):e.language.settings&&this._model.language?(this._configuration.language.enabled=!0,this._configuration.languageChoices.options&&this._configuration.languageChoices.options.length||(this._configuration.languageChoices.options=[]),this._configuration.languageChoices.options.find(e=>e.value===this._model.language)||this._configuration.languageChoices.options.push({value:this._model.language,label:this._model.language})):delete this._model.language,this._render()}set disableSidePanel(e){this._disableSidePanel=e,this._render()}dispatchModelUpdated(e){const t=!!e;this.dispatchEvent(new g(this._model,t))}onModelChanged(e,t){this._model=rt.prepareModel(e),this._render(),this.dispatchModelUpdated(t)}onConfigurationChanged(e){this._configuration=e,this._render()}insertImage(e){this.dispatchEvent(new b(e))}onDeleteImage(e,t){this.dispatchEvent(new _(e,t))}insertSound(e){this.dispatchEvent(new y(e))}onDeleteSound(e,t){this.dispatchEvent(new E(e,t))}_render(){lt("_render");let e=it.createElement(Ke,{model:this._model,configuration:this._configuration,onModelChanged:this.onModelChanged,onConfigurationChanged:this.onConfigurationChanged,disableSidePanel:this._disableSidePanel,imageSupport:{add:this.insertImage.bind(this),delete:this.onDeleteImage.bind(this)},uploadSoundSupport:{add:this.insertSound.bind(this),delete:this.onDeleteSound.bind(this)}});this._root||(this._root=v(this)),this._root.render(e)}disconnectedCallback(){this._root&&this._root.unmount()}}rt.__initStatic();export{rt as default};
|