@pie-element/ebsr 12.3.4-next.3 → 13.0.0-beta.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/defaults.js +23 -36
- package/configure/lib/defaults.js.map +1 -1
- package/configure/lib/index.js +114 -202
- package/configure/lib/index.js.map +1 -1
- package/configure/lib/main.js +188 -271
- package/configure/lib/main.js.map +1 -1
- package/configure/node_modules/@pie-element/multiple-choice/CHANGELOG.json +1972 -0
- package/configure/node_modules/@pie-element/multiple-choice/CHANGELOG.md +4213 -0
- package/configure/node_modules/@pie-element/multiple-choice/PRINT.md +35 -0
- package/configure/node_modules/@pie-element/multiple-choice/README.md +56 -0
- package/configure/node_modules/@pie-element/multiple-choice/choice.png +0 -0
- package/configure/node_modules/@pie-element/multiple-choice/configure/CHANGELOG.json +1387 -0
- package/configure/node_modules/@pie-element/multiple-choice/configure/CHANGELOG.md +3351 -0
- package/configure/node_modules/@pie-element/multiple-choice/configure/lib/__tests__/root.test.js +248 -0
- package/configure/node_modules/@pie-element/multiple-choice/configure/lib/defaults.js +200 -0
- package/configure/node_modules/@pie-element/multiple-choice/configure/lib/defaults.js.map +1 -0
- package/configure/node_modules/@pie-element/multiple-choice/configure/lib/index.js +211 -0
- package/configure/node_modules/@pie-element/multiple-choice/configure/lib/index.js.map +1 -0
- package/configure/node_modules/@pie-element/multiple-choice/configure/lib/main.js +477 -0
- package/configure/node_modules/@pie-element/multiple-choice/configure/lib/main.js.map +1 -0
- package/configure/node_modules/@pie-element/multiple-choice/configure/lib/utils.js +18 -0
- package/configure/node_modules/@pie-element/multiple-choice/configure/lib/utils.js.map +1 -0
- package/configure/node_modules/@pie-element/multiple-choice/configure/package.json +22 -0
- package/configure/node_modules/@pie-element/multiple-choice/controller/CHANGELOG.json +527 -0
- package/configure/node_modules/@pie-element/multiple-choice/controller/CHANGELOG.md +2316 -0
- package/configure/node_modules/@pie-element/multiple-choice/controller/lib/__tests__/index.test.js +520 -0
- package/configure/node_modules/@pie-element/multiple-choice/controller/lib/__tests__/utils.test.js +8 -0
- package/configure/node_modules/@pie-element/multiple-choice/controller/lib/defaults.js +33 -0
- package/configure/node_modules/@pie-element/multiple-choice/controller/lib/defaults.js.map +1 -0
- package/configure/node_modules/@pie-element/multiple-choice/controller/lib/index.js +251 -0
- package/configure/node_modules/@pie-element/multiple-choice/controller/lib/index.js.map +1 -0
- package/configure/node_modules/@pie-element/multiple-choice/controller/lib/utils.js +16 -0
- package/configure/node_modules/@pie-element/multiple-choice/controller/lib/utils.js.map +1 -0
- package/configure/node_modules/@pie-element/multiple-choice/controller/package.json +15 -0
- package/configure/node_modules/@pie-element/multiple-choice/docs/config-schema.json +2993 -0
- package/configure/node_modules/@pie-element/multiple-choice/docs/config-schema.json.md +2217 -0
- package/configure/node_modules/@pie-element/multiple-choice/docs/demo/config.js +8 -0
- package/configure/node_modules/@pie-element/multiple-choice/docs/demo/generate.js +61 -0
- package/configure/node_modules/@pie-element/multiple-choice/docs/demo/index.html +1 -0
- package/configure/node_modules/@pie-element/multiple-choice/docs/demo/pie.manifest.json +11 -0
- package/configure/node_modules/@pie-element/multiple-choice/docs/demo/session.js +7 -0
- package/configure/node_modules/@pie-element/multiple-choice/docs/pie-schema.json +1332 -0
- package/configure/node_modules/@pie-element/multiple-choice/docs/pie-schema.json.md +1015 -0
- package/configure/node_modules/@pie-element/multiple-choice/lib/__tests__/choice-input-test.js +117 -0
- package/configure/node_modules/@pie-element/multiple-choice/lib/__tests__/index-test.js +151 -0
- package/configure/node_modules/@pie-element/multiple-choice/lib/__tests__/key-events-test.js +95 -0
- package/configure/node_modules/@pie-element/multiple-choice/lib/__tests__/multiple-choice-test.js +223 -0
- package/configure/node_modules/@pie-element/multiple-choice/lib/__tests__/session-updater-test.js +70 -0
- package/configure/node_modules/@pie-element/multiple-choice/lib/choice-input.js +370 -0
- package/configure/node_modules/@pie-element/multiple-choice/lib/choice-input.js.map +1 -0
- package/configure/node_modules/@pie-element/multiple-choice/lib/choice.js +197 -0
- package/configure/node_modules/@pie-element/multiple-choice/lib/choice.js.map +1 -0
- package/configure/node_modules/@pie-element/multiple-choice/lib/feedback-tick.js +130 -0
- package/configure/node_modules/@pie-element/multiple-choice/lib/feedback-tick.js.map +1 -0
- package/configure/node_modules/@pie-element/multiple-choice/lib/index.js +292 -0
- package/configure/node_modules/@pie-element/multiple-choice/lib/index.js.map +1 -0
- package/configure/node_modules/@pie-element/multiple-choice/lib/main.js +54 -0
- package/configure/node_modules/@pie-element/multiple-choice/lib/main.js.map +1 -0
- package/configure/node_modules/@pie-element/multiple-choice/lib/multiple-choice.js +386 -0
- package/configure/node_modules/@pie-element/multiple-choice/lib/multiple-choice.js.map +1 -0
- package/configure/node_modules/@pie-element/multiple-choice/lib/print.js +92 -0
- package/configure/node_modules/@pie-element/multiple-choice/lib/print.js.map +1 -0
- package/configure/node_modules/@pie-element/multiple-choice/lib/session-updater.js +37 -0
- package/configure/node_modules/@pie-element/multiple-choice/lib/session-updater.js.map +1 -0
- package/configure/node_modules/@pie-element/multiple-choice/package.json +39 -0
- package/configure/package.json +9 -6
- package/configure/src/__tests__/index.test.js +99 -108
- package/configure/src/index.js +13 -6
- package/configure/src/main.jsx +14 -18
- package/controller/lib/defaults.js +20 -32
- package/controller/lib/defaults.js.map +1 -1
- package/controller/lib/index.js +224 -349
- package/controller/lib/index.js.map +1 -1
- package/controller/lib/utils.js +4 -18
- package/controller/lib/utils.js.map +1 -1
- package/controller/package.json +3 -3
- package/lib/index.js +113 -181
- package/lib/index.js.map +1 -1
- package/lib/print.js +120 -204
- package/lib/print.js.map +1 -1
- package/package.json +5 -13
- package/src/__tests__/index.test.js +18 -5
- package/configure/src/__tests__/__snapshots__/index.test.js.snap +0 -83
- package/esm/configure.js +0 -12003
- package/esm/configure.js.map +0 -1
- package/esm/controller.js +0 -3358
- package/esm/controller.js.map +0 -1
- package/esm/element.js +0 -2203
- package/esm/element.js.map +0 -1
- package/esm/package.json +0 -3
- package/esm/print.js +0 -4092
- package/esm/print.js.map +0 -1
- package/module/configure.js +0 -1
- package/module/controller.js +0 -6469
- package/module/demo.js +0 -77
- package/module/element.js +0 -1
- package/module/index.html +0 -21
- package/module/manifest.json +0 -14
- package/module/print-demo.js +0 -115
- package/module/print.html +0 -18
- package/module/print.js +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"print.js","names":["_react","_interopRequireDefault","require","_client","_debounce","_cloneDeep","_main","_mathRendering","_debug","log","debug","preparePrintModel","model","opts","instr","role","prompt","promptEnabled","undefined","teacherInstructions","teacherInstructionsEnabled","showTeacherInstructions","alwaysShowCorrect","mode","disabled","animationsDisabled","lockChoiceOrder","choicesLayout","choices","cloneDeep","map","c","rationale","rationaleEnabled","hideTick","feedback","keyMode","choicePrefix","MultipleChoicePrint","HTMLElement","constructor","_options","_model","_session","_root","_rerender","debounce","printModel","element","React","createElement","Main","session","options","createRoot","render","queueMicrotask","renderMath","leading","trailing","o","s","connectedCallback","disconnectedCallback","unmount","exports","default"],"sources":["../src/print.js"],"sourcesContent":["import React from 'react';\nimport { createRoot } from 'react-dom/client';\nimport debounce from 'lodash/debounce';\nimport cloneDeep from 'lodash/cloneDeep';\nimport Main from './main';\nimport { renderMath } from '@pie-lib/math-rendering';\nimport debug from 'debug';\n\nconst log = debug('pie-element:multiple-choice:print');\n\n/**\n * Live in same package as main element - so we can access some of the shared comps!\n *\n * - update pslb to build print if src/print.js is there\n * - update demo el\n * - get configure/controller building\n */\n\nconst preparePrintModel = (model, opts) => {\n const instr = opts.role === 'instructor';\n\n model.prompt = model.promptEnabled !== false ? model.prompt : undefined;\n model.teacherInstructions =\n instr && model.teacherInstructionsEnabled !== false ? model.teacherInstructions : undefined;\n model.showTeacherInstructions = instr;\n model.alwaysShowCorrect = instr;\n model.mode = instr ? 'evaluate' : model.mode;\n\n model.disabled = true;\n model.animationsDisabled = true;\n model.lockChoiceOrder = true;\n model.choicesLayout = model.choicesLayout || 'vertical';\n\n const choices = cloneDeep(model.choices);\n\n model.choices = choices.map((c) => {\n c.rationale = instr && model.rationaleEnabled !== false ? c.rationale : undefined;\n c.hideTick = instr;\n c.feedback = undefined;\n return c;\n });\n\n model.keyMode = model.choicePrefix || 'letters';\n\n return model;\n};\n\nexport default class MultipleChoicePrint extends HTMLElement {\n constructor() {\n super();\n this._options = null;\n this._model = null;\n this._session = [];\n this._root = null;\n this._rerender = debounce(\n () => {\n if (this._model && this._session) {\n const printModel = preparePrintModel(this._model, this._options);\n\n const element =\n this._options &&\n React.createElement(Main, {\n model: printModel,\n session: {},\n options: this._options,\n });\n\n if (!this._root) {\n this._root = createRoot(this);\n }\n this._root.render(element);\n queueMicrotask(() => {\n log('render complete - render math');\n renderMath(this);\n });\n } else {\n log('skip');\n }\n },\n 50,\n { leading: false, trailing: true },\n );\n }\n set options(o) {\n this._options = o;\n }\n\n set model(s) {\n this._model = s;\n this._rerender();\n }\n\n connectedCallback() {}\n\n disconnectedCallback() {\n if (this._root) {\n this._root.unmount();\n }\n }\n}\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,SAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,UAAA,GAAAJ,sBAAA,CAAAC,OAAA;AACA,IAAAI,KAAA,GAAAL,sBAAA,CAAAC,OAAA;AACA,IAAAK,cAAA,GAAAL,OAAA;AACA,IAAAM,MAAA,GAAAP,sBAAA,CAAAC,OAAA;AAEA,MAAMO,GAAG,GAAG,IAAAC,cAAK,EAAC,mCAAmC,CAAC;;AAEtD;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,MAAMC,iBAAiB,GAAGA,CAACC,KAAK,EAAEC,IAAI,KAAK;EACzC,MAAMC,KAAK,GAAGD,IAAI,CAACE,IAAI,KAAK,YAAY;EAExCH,KAAK,CAACI,MAAM,GAAGJ,KAAK,CAACK,aAAa,KAAK,KAAK,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,OAAA,GAAA5B,mBAAA","ignoreList":[]}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.updateSessionMetadata = updateSessionMetadata;
|
|
7
|
+
exports.updateSessionValue = updateSessionValue;
|
|
8
|
+
function updateSessionValue(session, choiceMode, data) {
|
|
9
|
+
session.value = session.value || [];
|
|
10
|
+
if (choiceMode === 'checkbox') {
|
|
11
|
+
if (data.selected) {
|
|
12
|
+
session.value = Array.from(new Set([...session.value, data.value]));
|
|
13
|
+
} else {
|
|
14
|
+
session.value = session.value.filter(v => v !== data.value);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
if (choiceMode === 'radio') {
|
|
18
|
+
if (data.selected) {
|
|
19
|
+
session.value = [data.value];
|
|
20
|
+
} else {
|
|
21
|
+
session.value = [];
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
//update session value metadata
|
|
26
|
+
session.selector = data.selector; //the input method used to select the choice (e.g. mouse, keyboard)
|
|
27
|
+
}
|
|
28
|
+
function updateSessionMetadata(session, metadata) {
|
|
29
|
+
session.audioStartTime = session.audioStartTime || metadata.audioStartTime; //timestamp when auto-played audio started playing
|
|
30
|
+
session.audioEndTime = session.audioEndTime || metadata.audioEndTime; //timestamp when auto-played audio completed playing
|
|
31
|
+
|
|
32
|
+
if (!session.waitTime && session.audioStartTime && session.audioEndTime) {
|
|
33
|
+
// waitTime is elapsed time the user waited for auto-played audio to finish
|
|
34
|
+
session.waitTime = session.audioEndTime - session.audioStartTime;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6WyJ1cGRhdGVTZXNzaW9uVmFsdWUiLCJzZXNzaW9uIiwiY2hvaWNlTW9kZSIsImRhdGEiL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8sQ0FBQ2MsWUFBWSxFQUFFO0lBQ3RFO0lBQ0FkLE9BQU8sQ0FBQ2UsUUFBUSxHQUFJZixPQUFPLENBQUNjLFlBQVksR0FBR2QsT0FBTyxDQUFDYSxjQUFlO0VBQ3BFO0FBQ0YiLCJpZ25vcmVMaXN0IjpbXX0=
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-updater.js","names":["updateSessionValue","session","choiceMode","data","value","selected","Array","from","Set","filter","v","selector","updateSessionMetadata","metadata","audioStartTime","audioEndTime","waitTime"],"sources":["../src/session-updater.js"],"sourcesContent":["export function updateSessionValue(session, choiceMode, data) {\n session.value = session.value || [];\n if (choiceMode === 'checkbox') {\n if (data.selected) {\n session.value = Array.from(new Set([...session.value, data.value]));\n } else {\n session.value = session.value.filter(v => v !== data.value);\n }\n }\n\n if (choiceMode === 'radio') {\n if (data.selected) {\n session.value = [data.value];\n } else {\n session.value = [];\n }\n }\n \n //update session value metadata\n session.selector = data.selector; //the input method used to select the choice (e.g. mouse, keyboard)\n}\n\nexport function updateSessionMetadata(session, metadata) {\n session.audioStartTime = session.audioStartTime || metadata.audioStartTime; //timestamp when auto-played audio started playing\n session.audioEndTime = session.audioEndTime || metadata.audioEndTime; //timestamp when auto-played audio completed playing\n \n if(!session.waitTime && session.audioStartTime && session.audioEndTime) {\n // waitTime is elapsed time the user waited for auto-played audio to finish\n session.waitTime = (session.audioEndTime - session.audioStartTime);\n }\n}\n"],"mappings":";;;;;;;AAAO,SAASA,kBAAkBA,CAACC,OAAO,EAAEC,UAAU,EAAEC,IAAI,EAAE;EAC5DF,OAAO,CAACG,KAAK,GAAGH,OAAO,CAACG,KAAK,IAAI,EAAE;EACnC,IAAIF,UAAU,KAAK,UAAU,EAAE;IAC7B,IAAIC,IAAI,CAACE,QAAQ,EAAE;MACjBJ,OAAO,CAACG,KAAK,GAAGE,KAAK,CAACC,IAAI,CAAC,IAAIC,GAAG,CAAC,CAAC,GAAGP,OAAO,CAACG,KAAK,EAAED,IAAI,CAACC,KAAK,CAAC,CAAC,CAAC;IACrE,CAAC,MAAM;MACLH,OAAO,CAACG,KAAK,GAAGH,OAAO,CAACG,KAAK,CAACK,MAAM,CAACC,CAAC,IAAIA,CAAC,KAAKP,IAAI,CAACC,KAAK,CAAC;IAC7D;EACF;EAEA,IAAIF,UAAU,KAAK,OAAO,EAAE;IAC1B,IAAIC,IAAI,CAACE,QAAQ,EAAE;MACjBJ,OAAO,CAACG,KAAK,GAAG,CAACD,IAAI,CAACC,KAAK,CAAC;IAC9B,CAAC,MAAM;MACLH,OAAO,CAACG,KAAK,GAAG,EAAE;IACpB;EACF;;EAEA;EACAH,OAAO,CAACU,QAAQ,GAAGR,IAAI,CAACQ,QAAQ,CAAC,CAAC;AACpC;AAEO,SAASC,qBAAqBA,CAACX,OAAO,EAAEY,QAAQ,EAAE;EACvDZ,OAAO,CAACa,cAAc,GAAGb,OAAO,CAACa,cAAc,IAAID,QAAQ,CAACC,cAAc,CAAC,CAAC;EAC5Eb,OAAO,CAACc,YAAY,GAAGd,OAAO,CAACc,YAAY,IAAIF,QAAQ,CAACE,YAAY,CAAC,CAAC;;EAEtE,IAAG,CAACd,OAAO,CAACe,QAAQ,IAAIf,OAAO,CAACa,cAAc,IAAIb,OAAO,CAACc,YAAY,EAAE;IACtE;IACAd,OAAO,CAACe,QAAQ,GAAIf,OAAO,CAACc,YAAY,GAAGd,OAAO,CAACa,cAAe;EACpE;AACF","ignoreList":[]}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pie-element/multiple-choice",
|
|
3
|
+
"repository": "pie-framework/pie-elements",
|
|
4
|
+
"version": "11.2.0-mui-update.4",
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"access": "public"
|
|
7
|
+
},
|
|
8
|
+
"dependencies": {
|
|
9
|
+
"@emotion/react": "^11.14.0",
|
|
10
|
+
"@emotion/style": "^0.8.0",
|
|
11
|
+
"@mui/icons-material": "^7.3.4",
|
|
12
|
+
"@mui/material": "^7.3.4",
|
|
13
|
+
"@pie-framework/pie-player-events": "^0.1.0",
|
|
14
|
+
"@pie-lib/correct-answer-toggle": "2.32.1-mui-update.0",
|
|
15
|
+
"@pie-lib/math-rendering": "3.33.1-mui-update.0",
|
|
16
|
+
"@pie-lib/render-ui": "4.42.1-mui-update.0",
|
|
17
|
+
"@pie-lib/translator": "2.31.1-mui-update.0",
|
|
18
|
+
"classnames": "^2.2.5",
|
|
19
|
+
"debug": "^4.1.1",
|
|
20
|
+
"enzyme-to-json": "^3.3.3",
|
|
21
|
+
"lodash": "^4.17.10",
|
|
22
|
+
"prop-types": "^15.6.1",
|
|
23
|
+
"react": "18.2.0",
|
|
24
|
+
"react-dom": "18.2.0",
|
|
25
|
+
"react-test-renderer": "18.2.0",
|
|
26
|
+
"react-transition-group": "^2.3.1"
|
|
27
|
+
},
|
|
28
|
+
"gitHead": "0e14ff981bcdc8a89a0e58484026496701bfdbc3",
|
|
29
|
+
"scripts": {
|
|
30
|
+
"postpublish": "../../scripts/postpublish"
|
|
31
|
+
},
|
|
32
|
+
"main": "lib/index.js",
|
|
33
|
+
"module": "src/index.js",
|
|
34
|
+
"exports": {
|
|
35
|
+
".": "./src/index.js",
|
|
36
|
+
"./print": "./src/print.js",
|
|
37
|
+
"./configure/lib": "./configure/lib/index.js"
|
|
38
|
+
}
|
|
39
|
+
}
|
package/configure/package.json
CHANGED
|
@@ -1,20 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pie-element/ebsr-configure",
|
|
3
3
|
"private": true,
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "12.0.0-beta.0",
|
|
5
5
|
"description": "",
|
|
6
6
|
"main": "lib/index.js",
|
|
7
7
|
"module": "src/index.js",
|
|
8
8
|
"author": "",
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"@
|
|
11
|
-
"@
|
|
10
|
+
"@emotion/react": "^11.14.0",
|
|
11
|
+
"@emotion/style": "^0.8.0",
|
|
12
|
+
"@mui/icons-material": "^7.3.4",
|
|
13
|
+
"@mui/material": "^7.3.4",
|
|
14
|
+
"@pie-element/multiple-choice": "12.0.0-beta.0",
|
|
12
15
|
"@pie-framework/pie-configure-events": "^1.2.0",
|
|
13
|
-
"@pie-lib/config-ui": "11.30.
|
|
16
|
+
"@pie-lib/config-ui": "11.30.4-next.0",
|
|
14
17
|
"lodash": "^4.17.15",
|
|
15
18
|
"prop-types": "^15.6.2",
|
|
16
|
-
"react": "
|
|
17
|
-
"react-dom": "
|
|
19
|
+
"react": "18.2.0",
|
|
20
|
+
"react-dom": "18.2.0"
|
|
18
21
|
},
|
|
19
22
|
"license": "ISC"
|
|
20
23
|
}
|
|
@@ -1,23 +1,29 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { render } from '@testing-library/react';
|
|
3
|
+
import { ThemeProvider, createTheme } from '@mui/material/styles';
|
|
3
4
|
import { ModelUpdatedEvent } from '@pie-framework/pie-configure-events';
|
|
4
5
|
import { choiceUtils as utils } from '@pie-lib/config-ui';
|
|
5
|
-
import
|
|
6
|
+
import { createRoot } from 'react-dom/client';
|
|
6
7
|
import defaults from '../defaults';
|
|
7
8
|
import { Main } from '../main';
|
|
8
9
|
import EbsrConfigure from '../index';
|
|
9
10
|
|
|
10
|
-
jest.
|
|
11
|
-
|
|
11
|
+
const mockRender = jest.fn();
|
|
12
|
+
const mockUnmount = jest.fn();
|
|
13
|
+
jest.mock('react-dom/client', () => ({
|
|
14
|
+
createRoot: jest.fn(() => ({
|
|
15
|
+
render: mockRender,
|
|
16
|
+
unmount: mockUnmount,
|
|
17
|
+
})),
|
|
12
18
|
}));
|
|
13
19
|
|
|
14
20
|
jest.mock('@pie-framework/pie-configure-events', () => ({
|
|
15
|
-
ModelUpdatedEvent:
|
|
16
|
-
|
|
17
|
-
update
|
|
18
|
-
preventDefault
|
|
19
|
-
stopImmediatePropagation
|
|
20
|
-
}
|
|
21
|
+
ModelUpdatedEvent: class ModelUpdatedEvent {
|
|
22
|
+
constructor(update) {
|
|
23
|
+
this.update = update;
|
|
24
|
+
this.preventDefault = jest.fn();
|
|
25
|
+
this.stopImmediatePropagation = jest.fn();
|
|
26
|
+
}
|
|
21
27
|
},
|
|
22
28
|
}));
|
|
23
29
|
|
|
@@ -26,17 +32,19 @@ jest.mock('@pie-lib/config-ui', () => ({
|
|
|
26
32
|
firstAvailableIndex: jest.fn(),
|
|
27
33
|
},
|
|
28
34
|
settings: {
|
|
29
|
-
Panel: (props) => <div {...props} />,
|
|
35
|
+
Panel: (props) => <div data-testid="settings-panel" {...props} />,
|
|
30
36
|
toggle: jest.fn(),
|
|
31
37
|
radio: jest.fn(),
|
|
32
38
|
dropdown: jest.fn(),
|
|
33
39
|
},
|
|
34
40
|
layout: {
|
|
35
|
-
ConfigLayout: (props) => <div>{props.children}</div>,
|
|
41
|
+
ConfigLayout: (props) => <div data-testid="config-layout">{props.children}</div>,
|
|
36
42
|
},
|
|
37
43
|
}));
|
|
38
44
|
|
|
39
|
-
jest.mock('@pie-element/multiple-choice/configure/lib', () => class MockConfigure {});
|
|
45
|
+
jest.mock('@pie-element/multiple-choice/configure/lib', () => (class MockConfigure {}));
|
|
46
|
+
|
|
47
|
+
const theme = createTheme();
|
|
40
48
|
|
|
41
49
|
const PART_A = 'partA';
|
|
42
50
|
const PART_B = 'partB';
|
|
@@ -110,65 +118,25 @@ describe('index', () => {
|
|
|
110
118
|
let el;
|
|
111
119
|
let onModelChanged = jest.fn();
|
|
112
120
|
let onConfigurationChanged = jest.fn();
|
|
113
|
-
let main;
|
|
114
121
|
|
|
115
122
|
beforeAll(() => {
|
|
116
123
|
Def = require('../index').default;
|
|
124
|
+
|
|
125
|
+
// Register the custom element if not already registered
|
|
126
|
+
if (!customElements.get('ebsr-configure')) {
|
|
127
|
+
customElements.define('ebsr-configure', Def);
|
|
128
|
+
}
|
|
117
129
|
});
|
|
118
130
|
|
|
119
131
|
beforeEach(() => {
|
|
120
|
-
|
|
132
|
+
jest.clearAllMocks();
|
|
133
|
+
el = document.createElement('ebsr-configure');
|
|
121
134
|
el.model = model;
|
|
122
135
|
el.configuration = defaults.configuration;
|
|
123
136
|
el.onModelChanged = onModelChanged;
|
|
124
137
|
el.onConfigurationChanged = onConfigurationChanged;
|
|
125
138
|
el.connectedCallback();
|
|
126
139
|
el.dispatchEvent = el.onModelUpdated;
|
|
127
|
-
|
|
128
|
-
main = mount(
|
|
129
|
-
<Main
|
|
130
|
-
classes={{}}
|
|
131
|
-
model={el._model}
|
|
132
|
-
configuration={defaults.configuration}
|
|
133
|
-
onConfigurationChanged={el.onConfigurationChanged}
|
|
134
|
-
onModelChanged={el.onModelChanged}
|
|
135
|
-
/>,
|
|
136
|
-
);
|
|
137
|
-
|
|
138
|
-
// mock onModelChanged to dispatch a MODEL_UPDATED event (as multiple-choice does)
|
|
139
|
-
main.instance().partA.onModelChanged = (m) => {
|
|
140
|
-
const event = new ModelUpdatedEvent(m, false);
|
|
141
|
-
|
|
142
|
-
el.dispatchEvent({
|
|
143
|
-
...event,
|
|
144
|
-
target: {
|
|
145
|
-
getAttribute: jest.fn().mockReturnValue('A'),
|
|
146
|
-
},
|
|
147
|
-
});
|
|
148
|
-
};
|
|
149
|
-
main.instance().partB.onModelChanged = (m) => {
|
|
150
|
-
const event = new ModelUpdatedEvent(m, false);
|
|
151
|
-
|
|
152
|
-
el.dispatchEvent({
|
|
153
|
-
...event,
|
|
154
|
-
target: {
|
|
155
|
-
getAttribute: jest.fn().mockReturnValue('B'),
|
|
156
|
-
},
|
|
157
|
-
});
|
|
158
|
-
};
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
describe('createDefaultModel', () => {
|
|
162
|
-
it('default-snapshot', () => {
|
|
163
|
-
const m = EbsrConfigure.createDefaultModel({});
|
|
164
|
-
expect(m).toMatchSnapshot();
|
|
165
|
-
});
|
|
166
|
-
it('with-overrides-snapshot', () => {
|
|
167
|
-
const m = EbsrConfigure.createDefaultModel({
|
|
168
|
-
partA: { rationale: 'foo', teacherInstructions: 'ti' },
|
|
169
|
-
});
|
|
170
|
-
expect(m).toMatchSnapshot();
|
|
171
|
-
});
|
|
172
140
|
});
|
|
173
141
|
|
|
174
142
|
describe('set model', () => {
|
|
@@ -176,12 +144,26 @@ describe('index', () => {
|
|
|
176
144
|
el.model = model;
|
|
177
145
|
|
|
178
146
|
expect(el._model).toEqual(model);
|
|
179
|
-
expect(
|
|
147
|
+
expect(createRoot).toHaveBeenCalled();
|
|
148
|
+
expect(mockRender).toHaveBeenCalled();
|
|
180
149
|
});
|
|
181
150
|
|
|
182
151
|
it('should have set the model for partA and partB', () => {
|
|
183
|
-
|
|
184
|
-
|
|
152
|
+
const { container } = render(
|
|
153
|
+
<ThemeProvider theme={theme}>
|
|
154
|
+
<Main
|
|
155
|
+
classes={{}}
|
|
156
|
+
model={el._model}
|
|
157
|
+
configuration={defaults.configuration}
|
|
158
|
+
onConfigurationChanged={el.onConfigurationChanged}
|
|
159
|
+
onModelChanged={el.onModelChanged}
|
|
160
|
+
/>
|
|
161
|
+
</ThemeProvider>
|
|
162
|
+
);
|
|
163
|
+
|
|
164
|
+
expect(container).toBeInTheDocument();
|
|
165
|
+
expect(el._model.partA).toEqual(model.partA);
|
|
166
|
+
expect(el._model.partB).toEqual(model.partB);
|
|
185
167
|
});
|
|
186
168
|
});
|
|
187
169
|
|
|
@@ -189,24 +171,28 @@ describe('index', () => {
|
|
|
189
171
|
it('calls ReactDOM.render', () => {
|
|
190
172
|
el.configuration = defaults.configuration;
|
|
191
173
|
|
|
192
|
-
expect(
|
|
174
|
+
expect(createRoot).toHaveBeenCalled();
|
|
175
|
+
expect(mockRender).toHaveBeenCalled();
|
|
193
176
|
});
|
|
194
177
|
|
|
195
178
|
it('should have set the configuration for partA and partB', () => {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
179
|
+
const { container } = render(
|
|
180
|
+
<ThemeProvider theme={theme}>
|
|
181
|
+
<Main
|
|
182
|
+
classes={{}}
|
|
183
|
+
model={el._model}
|
|
184
|
+
configuration={defaults.configuration}
|
|
185
|
+
onConfigurationChanged={el.onConfigurationChanged}
|
|
186
|
+
onModelChanged={el.onModelChanged}
|
|
187
|
+
/>
|
|
188
|
+
</ThemeProvider>
|
|
189
|
+
);
|
|
190
|
+
|
|
191
|
+
expect(container).toBeInTheDocument();
|
|
206
192
|
});
|
|
207
193
|
});
|
|
208
194
|
|
|
209
|
-
const
|
|
195
|
+
const assertOnModelUpdated = (label, key, updatedPart, expected) => {
|
|
210
196
|
it(label, () => {
|
|
211
197
|
const event = new ModelUpdatedEvent(updatedPart, false);
|
|
212
198
|
|
|
@@ -217,22 +203,23 @@ describe('index', () => {
|
|
|
217
203
|
},
|
|
218
204
|
});
|
|
219
205
|
|
|
220
|
-
expect(
|
|
206
|
+
expect(createRoot).toBeCalled();
|
|
207
|
+
expect(mockRender).toBeCalled();
|
|
221
208
|
expect(el._model[`part${key}`]).toEqual(expected);
|
|
222
209
|
});
|
|
223
210
|
};
|
|
224
211
|
|
|
225
212
|
describe('onModelUpdated', () => {
|
|
226
|
-
|
|
227
|
-
|
|
213
|
+
assertOnModelUpdated('dispatching MODEL_UPDATED updates model.partA', 'A', { updatedA: true }, { updatedA: true });
|
|
214
|
+
assertOnModelUpdated('dispatching MODEL_UPDATED updates model.partB', 'B', { updatedB: true }, { updatedB: true });
|
|
228
215
|
|
|
229
|
-
|
|
216
|
+
assertOnModelUpdated(
|
|
230
217
|
'dispatching MODEL_UPDATED with update undefined does not update model.partA',
|
|
231
218
|
'A',
|
|
232
219
|
undefined,
|
|
233
220
|
createDefaultModel(model).partA,
|
|
234
221
|
);
|
|
235
|
-
|
|
222
|
+
assertOnModelUpdated(
|
|
236
223
|
'dispatching MODEL_UPDATED with update undefined does not update model.partB',
|
|
237
224
|
'B',
|
|
238
225
|
undefined,
|
|
@@ -240,34 +227,43 @@ describe('index', () => {
|
|
|
240
227
|
);
|
|
241
228
|
});
|
|
242
229
|
|
|
243
|
-
const
|
|
230
|
+
const assertPartUpdate = (label, key, updatedModel) => {
|
|
244
231
|
it(`${key} - ${label}`, () => {
|
|
245
|
-
|
|
232
|
+
// Simulate the onModelChanged call for the specific part
|
|
233
|
+
const event = new ModelUpdatedEvent(updatedModel, false);
|
|
234
|
+
|
|
235
|
+
el.dispatchEvent({
|
|
236
|
+
...event,
|
|
237
|
+
target: {
|
|
238
|
+
getAttribute: jest.fn().mockReturnValue(key === 'partA' ? 'A' : 'B'),
|
|
239
|
+
},
|
|
240
|
+
});
|
|
246
241
|
|
|
247
242
|
expect(el._model[key]).toEqual(updatedModel);
|
|
248
|
-
expect(
|
|
243
|
+
expect(createRoot).toBeCalled();
|
|
244
|
+
expect(mockRender).toBeCalled();
|
|
249
245
|
});
|
|
250
246
|
};
|
|
251
247
|
|
|
252
248
|
describe('part update', () => {
|
|
253
|
-
|
|
249
|
+
assertPartUpdate('Dispatching Model Updated Event will update Teacher Instructions', 'partA', {
|
|
254
250
|
...model.partA,
|
|
255
251
|
teacherInstructions: 'Part A Teacher Instructions',
|
|
256
252
|
});
|
|
257
|
-
|
|
253
|
+
assertPartUpdate('Dispatching Model Updated Event will update Teacher Instructions', 'partB', {
|
|
258
254
|
...model.partB,
|
|
259
255
|
teacherInstructions: 'Part B Teacher Instructions',
|
|
260
256
|
});
|
|
261
|
-
|
|
257
|
+
assertPartUpdate('Dispatching Model Updated Event will update Prompt', 'partA', {
|
|
262
258
|
...model.partA,
|
|
263
259
|
prompt: 'Prompt A',
|
|
264
260
|
});
|
|
265
|
-
|
|
261
|
+
assertPartUpdate('Dispatching Model Updated Event will update Prompt', 'partB', {
|
|
266
262
|
...model.partA,
|
|
267
263
|
prompt: 'Prompt B',
|
|
268
264
|
});
|
|
269
265
|
|
|
270
|
-
|
|
266
|
+
assertPartUpdate('Dispatching Model Updated Event will update Choices - ADD CHOICE', 'partA', {
|
|
271
267
|
...model.partA,
|
|
272
268
|
choices: [
|
|
273
269
|
...model.partA.choices,
|
|
@@ -283,7 +279,7 @@ describe('index', () => {
|
|
|
283
279
|
},
|
|
284
280
|
],
|
|
285
281
|
});
|
|
286
|
-
|
|
282
|
+
assertPartUpdate('Dispatching Model Updated Event will update Choices - ADD CHOICE', 'partB', {
|
|
287
283
|
...model.partB,
|
|
288
284
|
choices: [
|
|
289
285
|
...model.partB.choices,
|
|
@@ -299,15 +295,15 @@ describe('index', () => {
|
|
|
299
295
|
},
|
|
300
296
|
],
|
|
301
297
|
});
|
|
302
|
-
|
|
298
|
+
assertPartUpdate('Dispatching Model Updated Event will update Choices - REMOVE CHOICE', 'partA', {
|
|
303
299
|
...model.partA,
|
|
304
300
|
choices: model.partA.choices.splice(0, 2),
|
|
305
301
|
});
|
|
306
|
-
|
|
302
|
+
assertPartUpdate('Dispatching Model Updated Event will update Choices - REMOVE CHOICE', 'partB', {
|
|
307
303
|
...model.partB,
|
|
308
304
|
choices: model.partB.choices.splice(0, 2),
|
|
309
305
|
});
|
|
310
|
-
|
|
306
|
+
assertPartUpdate('Dispatching Model Updated Event will update Choices - CHANGE CHOICE', 'partA', {
|
|
311
307
|
...model.partA,
|
|
312
308
|
choices: model.partA.choices.splice(1, 1, {
|
|
313
309
|
correct: true,
|
|
@@ -319,7 +315,7 @@ describe('index', () => {
|
|
|
319
315
|
},
|
|
320
316
|
}),
|
|
321
317
|
});
|
|
322
|
-
|
|
318
|
+
assertPartUpdate('Dispatching Model Updated Event will update Choices - CHANGE CHOICE', 'partB', {
|
|
323
319
|
...model.partB,
|
|
324
320
|
choices: model.partB.choices.splice(1, 1, {
|
|
325
321
|
correct: true,
|
|
@@ -332,40 +328,35 @@ describe('index', () => {
|
|
|
332
328
|
}),
|
|
333
329
|
});
|
|
334
330
|
|
|
335
|
-
|
|
336
|
-
|
|
331
|
+
assertPartUpdate('Dispatching Model Updated Event will update Choices', 'partA', { ...model.partA, choices: [] });
|
|
332
|
+
assertPartUpdate('Dispatching Model Updated Event will update Choices', 'partB', { ...model.partB, choices: [] });
|
|
337
333
|
});
|
|
338
334
|
});
|
|
339
335
|
|
|
340
336
|
describe('main', () => {
|
|
341
337
|
let Def;
|
|
342
338
|
let el;
|
|
343
|
-
let main;
|
|
344
339
|
|
|
345
340
|
beforeAll(() => {
|
|
346
341
|
Def = require('../index').default;
|
|
342
|
+
|
|
343
|
+
// Register the custom element if not already registered
|
|
344
|
+
if (!customElements.get('ebsr-configure')) {
|
|
345
|
+
customElements.define('ebsr-configure', Def);
|
|
346
|
+
}
|
|
347
347
|
});
|
|
348
348
|
|
|
349
349
|
beforeEach(() => {
|
|
350
|
-
|
|
350
|
+
jest.clearAllMocks();
|
|
351
|
+
el = document.createElement('ebsr-configure');
|
|
351
352
|
el.model = model;
|
|
352
353
|
el.configuration = defaults.configuration;
|
|
353
354
|
el.dispatchEvent = el.onModelUpdated;
|
|
354
|
-
|
|
355
|
-
main = mount(
|
|
356
|
-
<Main
|
|
357
|
-
classes={{}}
|
|
358
|
-
model={el._model}
|
|
359
|
-
configuration={defaults.configuration}
|
|
360
|
-
onConfigurationChanged={el.onConfigurationChanged}
|
|
361
|
-
onModelChanged={el.onModelChanged}
|
|
362
|
-
/>,
|
|
363
|
-
);
|
|
364
355
|
});
|
|
365
356
|
|
|
366
357
|
const assertOnModelChanged = (label, updatedModel, expected) => {
|
|
367
358
|
it(label, () => {
|
|
368
|
-
|
|
359
|
+
el.onModelChanged(updatedModel);
|
|
369
360
|
|
|
370
361
|
expect(el._model).toEqual(createDefaultModel(model, expected));
|
|
371
362
|
});
|
package/configure/src/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import
|
|
2
|
+
import { createRoot } from 'react-dom/client';
|
|
3
3
|
import { ModelUpdatedEvent } from '@pie-framework/pie-configure-events';
|
|
4
4
|
import MultipleChoiceConfigure from '@pie-element/multiple-choice/configure/lib';
|
|
5
5
|
import defaults from 'lodash/defaults';
|
|
@@ -50,6 +50,7 @@ export default class EbsrConfigure extends HTMLElement {
|
|
|
50
50
|
|
|
51
51
|
constructor() {
|
|
52
52
|
super();
|
|
53
|
+
this._root = null;
|
|
53
54
|
|
|
54
55
|
this._model = EbsrConfigure.createDefaultModel();
|
|
55
56
|
|
|
@@ -150,10 +151,6 @@ export default class EbsrConfigure extends HTMLElement {
|
|
|
150
151
|
this._render();
|
|
151
152
|
}
|
|
152
153
|
|
|
153
|
-
disconnectedCallback() {
|
|
154
|
-
this.removeEventListener(MODEL_UPDATED, this.onModelUpdated);
|
|
155
|
-
}
|
|
156
|
-
|
|
157
154
|
_render() {
|
|
158
155
|
let element = React.createElement(Main, {
|
|
159
156
|
model: this._model,
|
|
@@ -162,6 +159,16 @@ export default class EbsrConfigure extends HTMLElement {
|
|
|
162
159
|
onConfigurationChanged: this.onConfigurationChanged,
|
|
163
160
|
});
|
|
164
161
|
|
|
165
|
-
|
|
162
|
+
if (!this._root) {
|
|
163
|
+
this._root = createRoot(this);
|
|
164
|
+
}
|
|
165
|
+
this._root.render(element);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
disconnectedCallback() {
|
|
169
|
+
this.removeEventListener(MODEL_UPDATED, this.onModelUpdated);
|
|
170
|
+
if (this._root) {
|
|
171
|
+
this._root.unmount();
|
|
172
|
+
}
|
|
166
173
|
}
|
|
167
174
|
}
|
package/configure/src/main.jsx
CHANGED
|
@@ -1,23 +1,21 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
3
|
import { settings, layout } from '@pie-lib/config-ui';
|
|
4
|
-
import {
|
|
4
|
+
import { styled } from '@mui/material/styles';
|
|
5
5
|
|
|
6
6
|
const { Panel, toggle, radio, dropdown } = settings;
|
|
7
7
|
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
});
|
|
8
|
+
const PartLabel = styled('div')(({ theme }) => ({
|
|
9
|
+
paddingBottom: theme.spacing(2),
|
|
10
|
+
}));
|
|
11
|
+
|
|
12
|
+
const Divider = styled('div')(({ theme }) => ({
|
|
13
|
+
flex: 1,
|
|
14
|
+
height: theme.spacing(2.5),
|
|
15
|
+
}));
|
|
17
16
|
|
|
18
17
|
export class Main extends React.Component {
|
|
19
18
|
static propTypes = {
|
|
20
|
-
classes: PropTypes.object,
|
|
21
19
|
configuration: PropTypes.object,
|
|
22
20
|
model: PropTypes.object,
|
|
23
21
|
onModelChanged: PropTypes.func,
|
|
@@ -61,7 +59,7 @@ export class Main extends React.Component {
|
|
|
61
59
|
};
|
|
62
60
|
|
|
63
61
|
render() {
|
|
64
|
-
const {
|
|
62
|
+
const { model, configuration, onConfigurationChanged } = this.props;
|
|
65
63
|
const { partLabelType, partA: modelPartA, partB: modelPartB, extraCSSRules } = model;
|
|
66
64
|
const {
|
|
67
65
|
contentDimensions = {},
|
|
@@ -188,7 +186,7 @@ export class Main extends React.Component {
|
|
|
188
186
|
/>
|
|
189
187
|
}
|
|
190
188
|
>
|
|
191
|
-
{model.partLabels && <
|
|
189
|
+
{model.partLabels && <PartLabel>{firstPart}</PartLabel>}
|
|
192
190
|
<ebsr-multiple-choice-configure
|
|
193
191
|
id="A"
|
|
194
192
|
key="partA"
|
|
@@ -208,9 +206,9 @@ export class Main extends React.Component {
|
|
|
208
206
|
}}
|
|
209
207
|
/>
|
|
210
208
|
|
|
211
|
-
<
|
|
209
|
+
<Divider />
|
|
212
210
|
|
|
213
|
-
{model.partLabels && <
|
|
211
|
+
{model.partLabels && <PartLabel>{secondPart}</PartLabel>}
|
|
214
212
|
<ebsr-multiple-choice-configure
|
|
215
213
|
id="B"
|
|
216
214
|
key="partB"
|
|
@@ -234,6 +232,4 @@ export class Main extends React.Component {
|
|
|
234
232
|
}
|
|
235
233
|
}
|
|
236
234
|
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
export default Styled;
|
|
235
|
+
export default Main;
|