@pie-element/placement-ordering 12.3.4-next.3 → 13.0.0-beta.1
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/CHANGELOG.md +0 -11
- package/configure/CHANGELOG.md +0 -11
- package/configure/lib/choice-editor.js +189 -414
- package/configure/lib/choice-editor.js.map +1 -1
- package/configure/lib/choice-tile.js +172 -263
- package/configure/lib/choice-tile.js.map +1 -1
- package/configure/lib/defaults.js +2 -4
- package/configure/lib/defaults.js.map +1 -1
- package/configure/lib/design.js +389 -455
- package/configure/lib/design.js.map +1 -1
- package/configure/lib/help.js +5 -13
- package/configure/lib/help.js.map +1 -1
- package/configure/lib/index.js +118 -193
- package/configure/lib/index.js.map +1 -1
- package/configure/lib/utils.js +99 -4
- package/configure/lib/utils.js.map +1 -1
- package/configure/package.json +12 -10
- package/controller/CHANGELOG.md +0 -11
- package/controller/lib/defaults.js +2 -3
- package/controller/lib/defaults.js.map +1 -1
- package/controller/lib/index.js +133 -218
- package/controller/lib/index.js.map +1 -1
- package/controller/lib/scoring.js +35 -78
- package/controller/lib/scoring.js.map +1 -1
- package/controller/package.json +4 -4
- package/lib/index.js +63 -127
- package/lib/index.js.map +1 -1
- package/lib/main.js +20 -57
- package/lib/main.js.map +1 -1
- package/lib/ordering.js +52 -98
- package/lib/ordering.js.map +1 -1
- package/lib/placement-ordering.js +331 -381
- package/lib/placement-ordering.js.map +1 -1
- package/lib/tile.js +193 -267
- package/lib/tile.js.map +1 -1
- package/lib/tiler.js +126 -204
- package/lib/tiler.js.map +1 -1
- package/lib/utils.js +6 -18
- package/lib/utils.js.map +1 -1
- package/package.json +14 -11
- package/esm/configure.js +0 -25814
- package/esm/configure.js.map +0 -1
- package/esm/controller.js +0 -21221
- package/esm/controller.js.map +0 -1
- package/esm/element.js +0 -17874
- package/esm/element.js.map +0 -1
- package/esm/package.json +0 -3
package/configure/lib/utils.js
CHANGED
|
@@ -1,14 +1,109 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
3
4
|
Object.defineProperty(exports, "__esModule", {
|
|
4
5
|
value: true
|
|
5
6
|
});
|
|
7
|
+
exports.buildTiles = buildTiles;
|
|
6
8
|
exports.generateValidationMessage = void 0;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
exports.normalizeIndex = normalizeIndex;
|
|
10
|
+
exports.updateResponseOrChoices = updateResponseOrChoices;
|
|
11
|
+
var _cloneDeep = _interopRequireDefault(require("lodash/cloneDeep"));
|
|
12
|
+
const generateValidationMessage = () => {
|
|
13
|
+
const answersMessage = '\nThere should be at least 3 tokens.' + '\nThe tokens should not be empty and should be unique.' + '\nThe correct ordering should not be identical to the initial ordering.';
|
|
10
14
|
return 'Validation requirements:' + answersMessage;
|
|
11
15
|
};
|
|
12
|
-
|
|
13
16
|
exports.generateValidationMessage = generateValidationMessage;
|
|
17
|
+
function normalizeIndex(tile, ordering) {
|
|
18
|
+
if (tile.type === 'target') {
|
|
19
|
+
return ordering.response.findIndex(r => r.id === tile.id);
|
|
20
|
+
}
|
|
21
|
+
if (tile.type === 'choice') {
|
|
22
|
+
return ordering.choices.findIndex(c => c.id === tile.id);
|
|
23
|
+
}
|
|
24
|
+
return -1;
|
|
25
|
+
}
|
|
26
|
+
function updateResponseOrChoices(response, choices, from, to) {
|
|
27
|
+
const {
|
|
28
|
+
type: fromType,
|
|
29
|
+
index: fromIndex
|
|
30
|
+
} = from;
|
|
31
|
+
const {
|
|
32
|
+
type: toType,
|
|
33
|
+
index: placeAtIndex
|
|
34
|
+
} = to;
|
|
35
|
+
if (fromType === 'target' && toType === 'target') {
|
|
36
|
+
const updatedResponse = (0, _cloneDeep.default)(response) || [];
|
|
37
|
+
const {
|
|
38
|
+
movedItem,
|
|
39
|
+
remainingItems
|
|
40
|
+
} = updatedResponse.reduce((acc, item, index) => {
|
|
41
|
+
if (index === fromIndex) {
|
|
42
|
+
acc.movedItem = item;
|
|
43
|
+
} else {
|
|
44
|
+
acc.remainingItems.push(item);
|
|
45
|
+
}
|
|
46
|
+
return acc;
|
|
47
|
+
}, {
|
|
48
|
+
movedItem: null,
|
|
49
|
+
remainingItems: []
|
|
50
|
+
});
|
|
51
|
+
return {
|
|
52
|
+
response: [...remainingItems.slice(0, placeAtIndex), movedItem, ...remainingItems.slice(placeAtIndex)],
|
|
53
|
+
choices
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
if (fromType === 'choice' && toType === 'choice') {
|
|
57
|
+
const updatedChoices = (0, _cloneDeep.default)(choices) || [];
|
|
58
|
+
const {
|
|
59
|
+
movedItem,
|
|
60
|
+
remainingItems,
|
|
61
|
+
toIndex
|
|
62
|
+
} = updatedChoices.reduce((acc, item, index) => {
|
|
63
|
+
if (item.id === from.id) {
|
|
64
|
+
acc.movedItem = item;
|
|
65
|
+
} else {
|
|
66
|
+
acc.remainingItems.push(item);
|
|
67
|
+
}
|
|
68
|
+
if (item.id === to.id) {
|
|
69
|
+
acc.toIndex = index;
|
|
70
|
+
}
|
|
71
|
+
return acc;
|
|
72
|
+
}, {
|
|
73
|
+
movedItem: null,
|
|
74
|
+
remainingItems: [],
|
|
75
|
+
toIndex: null
|
|
76
|
+
});
|
|
77
|
+
return {
|
|
78
|
+
response,
|
|
79
|
+
choices: [...remainingItems.slice(0, toIndex), movedItem, ...remainingItems.slice(toIndex)]
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
return {
|
|
83
|
+
response,
|
|
84
|
+
choices
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
function buildTiles(choices, response) {
|
|
88
|
+
const targets = response.map((r, index) => {
|
|
89
|
+
const respId = r && r.id;
|
|
90
|
+
const choice = choices.find(c => respId !== undefined && respId !== null && c.id === respId);
|
|
91
|
+
return {
|
|
92
|
+
type: 'target',
|
|
93
|
+
...choice,
|
|
94
|
+
draggable: true,
|
|
95
|
+
index,
|
|
96
|
+
editable: false
|
|
97
|
+
};
|
|
98
|
+
});
|
|
99
|
+
const processedChoices = choices.map(m => {
|
|
100
|
+
return Object.assign({}, m, {
|
|
101
|
+
type: 'choice',
|
|
102
|
+
droppable: false,
|
|
103
|
+
draggable: true,
|
|
104
|
+
editable: true
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
return processedChoices.concat(targets);
|
|
108
|
+
}
|
|
14
109
|
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"utils.js","names":["_cloneDeep","_interopRequireDefault","require","generateValidationMessage","answersMessage","exports","normalizeIndex","tile","ordering","type","response","findIndex","r","id","choices","c","updateResponseOrChoices","from","to","fromType","index","fromIndex","toType","placeAtIndex","updatedResponse","cloneDeep","movedItem","remainingItems","reduce","acc","item","push","slice","updatedChoices","toIndex","buildTiles","targets","map","respId","choice","find","undefined","draggable","editable","processedChoices","m","Object","assign","droppable","concat"],"sources":["../src/utils.js"],"sourcesContent":["import cloneDeep from 'lodash/cloneDeep';\n\nexport const generateValidationMessage = () => {\n const answersMessage =\n '\\nThere should be at least 3 tokens.' +\n '\\nThe tokens should not be empty and should be unique.' +\n '\\nThe correct ordering should not be identical to the initial ordering.';\n\n return 'Validation requirements:' + answersMessage;\n};\n\nexport function normalizeIndex(tile, ordering) {\n if (tile.type === 'target') {\n return ordering.response.findIndex(r => r.id === tile.id);\n }\n\n if (tile.type === 'choice') {\n return ordering.choices.findIndex(c => c.id === tile.id);\n }\n\n return -1;\n}\n\nexport function updateResponseOrChoices(response, choices, from, to) {\n const { type: fromType, index: fromIndex } = from;\n const { type: toType, index: placeAtIndex } = to;\n\n if (fromType === 'target' && toType === 'target') {\n const updatedResponse = cloneDeep(response) || [];\n\n const { movedItem, remainingItems } = updatedResponse.reduce(\n (acc, item, index) => {\n if (index === fromIndex) {\n acc.movedItem = item;\n } else {\n acc.remainingItems.push(item);\n }\n\n return acc;\n },\n { movedItem: null, remainingItems: [] },\n );\n\n return {\n response: [...remainingItems.slice(0, placeAtIndex), movedItem, ...remainingItems.slice(placeAtIndex)],\n choices,\n };\n }\n\n if (fromType === 'choice' && toType === 'choice') {\n const updatedChoices = cloneDeep(choices) || [];\n\n const { movedItem, remainingItems, toIndex } = updatedChoices.reduce(\n (acc, item, index) => {\n if (item.id === from.id) {\n acc.movedItem = item;\n } else {\n acc.remainingItems.push(item);\n }\n\n if (item.id === to.id) {\n acc.toIndex = index;\n }\n\n return acc;\n },\n { movedItem: null, remainingItems: [], toIndex: null },\n );\n\n return {\n response,\n choices: [...remainingItems.slice(0, toIndex), movedItem, ...remainingItems.slice(toIndex)],\n };\n }\n\n return { response, choices };\n}\n\nexport function buildTiles(choices, response) {\n const targets = response.map((r, index) => {\n const respId = r && r.id;\n const choice = choices.find((c) => respId !== undefined && respId !== null && c.id === respId);\n\n return {\n type: 'target',\n ...choice,\n draggable: true,\n index,\n editable: false,\n };\n });\n\n const processedChoices = choices.map((m) => {\n return Object.assign({}, m, {\n type: 'choice',\n droppable: false,\n draggable: true,\n editable: true,\n });\n });\n\n return processedChoices.concat(targets);\n}"],"mappings":";;;;;;;;;;AAAA,IAAAA,UAAA,GAAAC,sBAAA,CAAAC,OAAA;AAEO,MAAMC,yBAAyB,GAAGA,CAAA,KAAM;EAC7C,MAAMC,cAAc,GAClB,sCAAsC,GACtC,wDAAwD,GACxD,yEAAyE;EAE3E,OAAO,0BAA0B,GAAGA,cAAc;AACpD,CAAC;AAACC,OAAA,CAAAF,yBAAA,GAAAA,yBAAA;AAEK,SAASG,cAAcA,CAACC,IAAI,EAAEC,QAAQ,EAAE;EAC7C,IAAID,IAAI,CAACE,IAAI,KAAK,QAAQ,EAAE;IAC1B,OAAOD,QAAQ,CAACE,QAAQ,CAACC,SAAS,CAACC,CAAC,IAAIA,CAAC,CAACC,EAAE,KAAKN,IAAI,CAACM,EAAE,CAAC;EAC3D;EAEA,IAAIN,IAAI,CAACE,IAAI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d,GAAG8B,MAAM;MACTG,SAAS,EAAE,IAAI;MACftB,KAAK;MACLuB,QAAQ,EAAE;IACZ,CAAC;EACH,CAAC,CAAC;EAEF,MAAMC,gBAAgB,GAAG9B,OAAO,CAACuB,GAAG,CAAEQ,CAAC,IAAK;IAC1C,OAAOC,MAAM,CAACC,MAAM,CAAC,CAAC,CAAC,EAAEF,CAAC,EAAE;MAC1BpC,IAAI,EAAE,QAAQ;MACduC,SAAS,EAAE,KAAK;MAChBN,SAAS,EAAE,IAAI;MACfC,QAAQ,EAAE;IACZ,CAAC,CAAC;EACJ,CAAC,CAAC;EAEF,OAAOC,gBAAgB,CAACK,MAAM,CAACb,OAAO,CAAC;AACzC","ignoreList":[]}
|
package/configure/package.json
CHANGED
|
@@ -1,24 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pie-element/placement-ordering-configure",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "10.0.0-beta.1",
|
|
4
4
|
"private": true,
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "src/index.js",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@
|
|
9
|
-
"@
|
|
8
|
+
"@dnd-kit/core": "^6.3.1",
|
|
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",
|
|
10
13
|
"@pie-framework/pie-configure-events": "^1.3.0",
|
|
11
|
-
"@pie-lib/config-ui": "
|
|
12
|
-
"@pie-lib/drag": "
|
|
13
|
-
"@pie-lib/editable-html": "
|
|
14
|
-
"@pie-lib/render-ui": "
|
|
14
|
+
"@pie-lib/config-ui": "12.1.0-next.5",
|
|
15
|
+
"@pie-lib/drag": "3.1.0-next.5",
|
|
16
|
+
"@pie-lib/editable-html-tip-tap": "1.1.0-next.5",
|
|
17
|
+
"@pie-lib/render-ui": "5.1.0-next.5",
|
|
15
18
|
"debug": "^3.1.0",
|
|
16
19
|
"lodash": "^4.17.15",
|
|
17
20
|
"nested-property": "^0.0.7",
|
|
18
21
|
"pluralize": "^8.0.0",
|
|
19
22
|
"prop-types": "^15.6.2",
|
|
20
|
-
"react": "
|
|
21
|
-
"react-
|
|
22
|
-
"react-dom": "^16.8.1"
|
|
23
|
+
"react": "18.2.0",
|
|
24
|
+
"react-dom": "18.2.0"
|
|
23
25
|
}
|
|
24
26
|
}
|
package/controller/CHANGELOG.md
CHANGED
|
@@ -3,17 +3,6 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
-
## [9.3.3](https://github.com/pie-framework/pie-elements/compare/@pie-element/placement-ordering-controller@9.3.2...@pie-element/placement-ordering-controller@9.3.3) (2025-11-27)
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
### Bug Fixes
|
|
10
|
-
|
|
11
|
-
* bump libs PD-5274, PD-5211, PD-5248 ([7610b25](https://github.com/pie-framework/pie-elements/commit/7610b25423956b6492f33322513b3430051fca77))
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
6
|
## [9.3.2](https://github.com/pie-framework/pie-elements/compare/@pie-element/placement-ordering-controller@9.3.1...@pie-element/placement-ordering-controller@9.3.2) (2025-10-22)
|
|
18
7
|
|
|
19
8
|
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports
|
|
7
|
-
var _default = {
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _default = exports.default = {
|
|
8
8
|
choiceLabel: '',
|
|
9
9
|
choiceLabelEnabled: true,
|
|
10
10
|
choices: [],
|
|
@@ -26,5 +26,4 @@ var _default = {
|
|
|
26
26
|
teacherInstructionsEnabled: true,
|
|
27
27
|
toolbarEditorPosition: 'bottom'
|
|
28
28
|
};
|
|
29
|
-
exports["default"] = _default;
|
|
30
29
|
//# sourceMappingURL=defaults.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"defaults.js","names":["choiceLabel","choiceLabelEnabled","choices","correctResponse","feedbackEnabled","numberedGuides","orientation","partialScoring","placementArea","prompt","promptEnabled","rationale","rationaleEnabled","removeTilesAfterPlacing","scoringType","studentInstructionsEnabled","targetLabel","teacherInstructions","teacherInstructionsEnabled","toolbarEditorPosition"],"sources":["../src/defaults.js"],"sourcesContent":["export default {\n choiceLabel: '',\n choiceLabelEnabled: true,\n choices: [],\n correctResponse: [],\n feedbackEnabled: false,\n numberedGuides: false,\n orientation: 'vertical',\n partialScoring: true,\n placementArea: false,\n prompt: '',\n promptEnabled: true,\n rationale: '',\n rationaleEnabled: true,\n removeTilesAfterPlacing: true,\n scoringType: 'auto',\n studentInstructionsEnabled: true,\n targetLabel: '',\n teacherInstructions: '',\n teacherInstructionsEnabled: true,\n toolbarEditorPosition: 'bottom',\n};\n"],"mappings":";;;;;;iCAAe;EACbA,WAAW,EAAE,EAAE;EACfC,kBAAkB,EAAE,IAAI;EACxBC,OAAO,EAAE,EAAE;EACXC,eAAe,EAAE,EAAE;EACnBC,eAAe,EAAE,KAAK;EACtBC,cAAc,EAAE,KAAK;EACrBC,WAAW,EAAE,UAAU;EACvBC,cAAc,EAAE,IAAI;EACpBC,aAAa,EAAE,KAAK;EACpBC,MAAM,EAAE,EAAE;EACVC,aAAa,EAAE,IAAI;EACnBC,SAAS,EAAE,EAAE;EACbC,gBAAgB,EAAE,IAAI;EACtBC,uBAAuB,EAAE,IAAI;EAC7BC,WAAW,EAAE,MAAM;EACnBC,0BAA0B,EAAE,IAAI;EAChCC,WAAW,EAAE,EAAE;EACfC,mBAAmB,EAAE,EAAE;EACvBC,0BAA0B,EAAE,IAAI;EAChCC,qBAAqB,EAAE;AACzB,CAAC","ignoreList":[]}
|
package/controller/lib/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
@@ -11,61 +10,35 @@ exports.model = model;
|
|
|
11
10
|
exports.normalize = void 0;
|
|
12
11
|
exports.outcome = outcome;
|
|
13
12
|
exports.validate = exports.questionError = void 0;
|
|
14
|
-
|
|
15
|
-
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
16
|
-
|
|
17
|
-
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
18
|
-
|
|
19
|
-
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
20
|
-
|
|
21
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
22
|
-
|
|
23
13
|
var _scoring = require("./scoring");
|
|
24
|
-
|
|
25
14
|
var _lodash = _interopRequireDefault(require("lodash"));
|
|
26
|
-
|
|
27
15
|
var _feedback = require("@pie-lib/feedback");
|
|
28
|
-
|
|
29
16
|
var _controllerUtils = require("@pie-lib/controller-utils");
|
|
30
|
-
|
|
31
17
|
var _debug = _interopRequireDefault(require("debug"));
|
|
32
|
-
|
|
33
18
|
var _defaults = _interopRequireDefault(require("./defaults"));
|
|
34
|
-
|
|
35
19
|
var _isEqual = _interopRequireDefault(require("lodash/isEqual"));
|
|
36
|
-
|
|
37
20
|
var _isEmpty = _interopRequireDefault(require("lodash/isEmpty"));
|
|
38
|
-
|
|
39
21
|
var _translator = _interopRequireDefault(require("@pie-lib/translator"));
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
var log = (0, _debug["default"])('@pie-element:placement-ordering:controller');
|
|
46
|
-
var translator = _translator["default"].translator;
|
|
47
|
-
|
|
48
|
-
var questionError = function questionError() {
|
|
49
|
-
return new Error('Question is missing required array: correctResponse');
|
|
50
|
-
};
|
|
51
|
-
|
|
22
|
+
const log = (0, _debug.default)('@pie-element:placement-ordering:controller');
|
|
23
|
+
const {
|
|
24
|
+
translator
|
|
25
|
+
} = _translator.default;
|
|
26
|
+
const questionError = () => new Error('Question is missing required array: correctResponse');
|
|
52
27
|
exports.questionError = questionError;
|
|
53
|
-
|
|
54
28
|
function outcome(question, session, env) {
|
|
55
|
-
return new Promise(
|
|
56
|
-
if (!session || _lodash
|
|
29
|
+
return new Promise((resolve, reject) => {
|
|
30
|
+
if (!session || _lodash.default.isEmpty(session)) {
|
|
57
31
|
resolve({
|
|
58
32
|
score: 0,
|
|
59
33
|
empty: true
|
|
60
34
|
});
|
|
61
35
|
}
|
|
62
|
-
|
|
63
|
-
if (!question || !question.correctResponse || _lodash["default"].isEmpty(question.correctResponse)) {
|
|
36
|
+
if (!question || !question.correctResponse || _lodash.default.isEmpty(question.correctResponse)) {
|
|
64
37
|
reject(questionError());
|
|
65
38
|
} else {
|
|
66
39
|
try {
|
|
67
|
-
|
|
68
|
-
|
|
40
|
+
const s = (0, _scoring.score)(question, session);
|
|
41
|
+
const finalScore = _controllerUtils.partialScoring.enabled(question, env || {}) ? s : s === 1 ? 1 : 0;
|
|
69
42
|
resolve({
|
|
70
43
|
score: finalScore
|
|
71
44
|
});
|
|
@@ -75,155 +48,115 @@ function outcome(question, session, env) {
|
|
|
75
48
|
}
|
|
76
49
|
});
|
|
77
50
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
51
|
+
function createDefaultModel(model = {}) {
|
|
52
|
+
return new Promise(resolve => {
|
|
53
|
+
resolve({
|
|
54
|
+
..._defaults.default,
|
|
55
|
+
...model
|
|
56
|
+
});
|
|
83
57
|
});
|
|
84
58
|
}
|
|
59
|
+
const normalize = question => ({
|
|
60
|
+
..._defaults.default,
|
|
61
|
+
rationaleEnabled: true,
|
|
62
|
+
feedbackEnabled: false,
|
|
63
|
+
promptEnabled: true,
|
|
64
|
+
teacherInstructionsEnabled: true,
|
|
65
|
+
studentInstructionsEnabled: true,
|
|
66
|
+
...question
|
|
67
|
+
});
|
|
85
68
|
|
|
86
|
-
var normalize = function normalize(question) {
|
|
87
|
-
return _objectSpread(_objectSpread({}, _defaults["default"]), {}, {
|
|
88
|
-
rationaleEnabled: true,
|
|
89
|
-
feedbackEnabled: false,
|
|
90
|
-
promptEnabled: true,
|
|
91
|
-
teacherInstructionsEnabled: true,
|
|
92
|
-
studentInstructionsEnabled: true
|
|
93
|
-
}, question);
|
|
94
|
-
};
|
|
95
69
|
/**
|
|
96
70
|
*
|
|
97
71
|
* @param {*} question
|
|
98
72
|
* @param {*} session
|
|
99
73
|
* @param {*} env
|
|
100
74
|
*/
|
|
101
|
-
|
|
102
|
-
|
|
103
75
|
exports.normalize = normalize;
|
|
76
|
+
async function model(question, session, env) {
|
|
77
|
+
const normalizedQuestion = normalize(question);
|
|
78
|
+
const base = {};
|
|
79
|
+
if (question.alternateResponses && _lodash.default.every(question.alternateResponses, _lodash.default.isArray)) {
|
|
80
|
+
log('Deprecated structure of alternateResponses is in use');
|
|
81
|
+
// eslint-disable-next-line no-console
|
|
82
|
+
console.error('Deprecated structure of alternateResponses is in use');
|
|
83
|
+
}
|
|
84
|
+
base.env = env;
|
|
85
|
+
base.extraCSSRules = normalizedQuestion.extraCSSRules;
|
|
86
|
+
base.outcomes = [];
|
|
87
|
+
base.completeLength = (normalizedQuestion.correctResponse || []).length;
|
|
88
|
+
base.choices = (normalizedQuestion.choices || []).filter(choice => choice.label);
|
|
89
|
+
base.note = normalizedQuestion.note;
|
|
90
|
+
base.showNote = normalizedQuestion.alternateResponses && normalizedQuestion.alternateResponses.length > 0;
|
|
91
|
+
base.language = normalizedQuestion.language;
|
|
92
|
+
log('[model] removing tileSize for the moment.');
|
|
93
|
+
base.prompt = normalizedQuestion.promptEnabled ? normalizedQuestion.prompt : null;
|
|
94
|
+
base.config = {
|
|
95
|
+
orientation: normalizedQuestion.orientation || 'vertical',
|
|
96
|
+
includeTargets: normalizedQuestion.placementArea,
|
|
97
|
+
choiceLabelEnabled: normalizedQuestion.choiceLabelEnabled,
|
|
98
|
+
targetLabel: normalizedQuestion.targetLabel,
|
|
99
|
+
choiceLabel: normalizedQuestion.choiceLabel,
|
|
100
|
+
showOrdering: normalizedQuestion.numberedGuides,
|
|
101
|
+
allowSameChoiceInTargets: !normalizedQuestion.removeTilesAfterPlacing
|
|
102
|
+
};
|
|
103
|
+
base.disabled = env.mode !== 'gather';
|
|
104
|
+
if (!base.note) {
|
|
105
|
+
base.note = translator.t('common:commonCorrectAnswerWithAlternates', {
|
|
106
|
+
lng: normalizedQuestion.language
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
if (env.role === 'instructor' && (env.mode === 'view' || env.mode === 'evaluate')) {
|
|
110
|
+
base.rationale = normalizedQuestion.rationaleEnabled ? normalizedQuestion.rationale : null;
|
|
111
|
+
base.teacherInstructions = normalizedQuestion.teacherInstructionsEnabled ? normalizedQuestion.teacherInstructions : null;
|
|
112
|
+
} else {
|
|
113
|
+
base.rationale = null;
|
|
114
|
+
base.teacherInstructions = null;
|
|
115
|
+
}
|
|
116
|
+
if (env.mode === 'evaluate') {
|
|
117
|
+
const value = session && session.value || [];
|
|
118
|
+
const allCorrectResponses = (0, _scoring.getAllCorrectResponses)(normalizedQuestion);
|
|
119
|
+
const bestSetOfResponses = allCorrectResponses.reduce((info, cr) => {
|
|
120
|
+
const currentScore = _lodash.default.reduce(value, (acc, c, idx) => acc + (Array.isArray(cr) && cr[idx] === c ? 1 : 0), 0);
|
|
121
|
+
if (currentScore > info.score) {
|
|
122
|
+
return {
|
|
123
|
+
arr: cr,
|
|
124
|
+
score: currentScore
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
return info;
|
|
128
|
+
}, {
|
|
129
|
+
arr: [],
|
|
130
|
+
score: 0
|
|
131
|
+
});
|
|
132
|
+
base.outcomes = _lodash.default.map(value, (c, idx) => {
|
|
133
|
+
return {
|
|
134
|
+
id: c,
|
|
135
|
+
outcome: bestSetOfResponses.arr[idx] === c ? 'correct' : 'incorrect'
|
|
136
|
+
};
|
|
137
|
+
});
|
|
138
|
+
const isResponseCorrect = allCorrectResponses.some(response => _lodash.default.isEqual(response, value));
|
|
139
|
+
const responseScore = (0, _scoring.score)(question, session);
|
|
140
|
+
const isCorrect = responseScore === 1;
|
|
141
|
+
const isPartialCorrect = !isCorrect && _controllerUtils.partialScoring.enabled(normalizedQuestion, env || {}) && responseScore !== 0;
|
|
142
|
+
base.correctness = isCorrect ? 'correct' : isPartialCorrect ? 'partial' : 'incorrect';
|
|
143
|
+
if (!isResponseCorrect) {
|
|
144
|
+
base.correctResponse = (0, _scoring.flattenCorrect)(normalizedQuestion);
|
|
145
|
+
}
|
|
104
146
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
if (question.alternateResponses && _lodash["default"].every(question.alternateResponses, _lodash["default"].isArray)) {
|
|
117
|
-
log('Deprecated structure of alternateResponses is in use'); // eslint-disable-next-line no-console
|
|
118
|
-
|
|
119
|
-
console.error('Deprecated structure of alternateResponses is in use');
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
base.env = env;
|
|
123
|
-
base.extraCSSRules = normalizedQuestion.extraCSSRules;
|
|
124
|
-
base.outcomes = [];
|
|
125
|
-
base.completeLength = (normalizedQuestion.correctResponse || []).length;
|
|
126
|
-
base.choices = (normalizedQuestion.choices || []).filter(function (choice) {
|
|
127
|
-
return choice.label;
|
|
128
|
-
});
|
|
129
|
-
base.note = normalizedQuestion.note;
|
|
130
|
-
base.showNote = normalizedQuestion.alternateResponses && normalizedQuestion.alternateResponses.length > 0;
|
|
131
|
-
base.language = normalizedQuestion.language;
|
|
132
|
-
log('[model] removing tileSize for the moment.');
|
|
133
|
-
base.prompt = normalizedQuestion.promptEnabled ? normalizedQuestion.prompt : null;
|
|
134
|
-
base.config = {
|
|
135
|
-
orientation: normalizedQuestion.orientation || 'vertical',
|
|
136
|
-
includeTargets: normalizedQuestion.placementArea,
|
|
137
|
-
choiceLabelEnabled: normalizedQuestion.choiceLabelEnabled,
|
|
138
|
-
targetLabel: normalizedQuestion.targetLabel,
|
|
139
|
-
choiceLabel: normalizedQuestion.choiceLabel,
|
|
140
|
-
showOrdering: normalizedQuestion.numberedGuides,
|
|
141
|
-
allowSameChoiceInTargets: !normalizedQuestion.removeTilesAfterPlacing
|
|
142
|
-
};
|
|
143
|
-
base.disabled = env.mode !== 'gather';
|
|
144
|
-
|
|
145
|
-
if (!base.note) {
|
|
146
|
-
base.note = translator.t('common:commonCorrectAnswerWithAlternates', {
|
|
147
|
-
lng: normalizedQuestion.language
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
if (env.role === 'instructor' && (env.mode === 'view' || env.mode === 'evaluate')) {
|
|
152
|
-
base.rationale = normalizedQuestion.rationaleEnabled ? normalizedQuestion.rationale : null;
|
|
153
|
-
base.teacherInstructions = normalizedQuestion.teacherInstructionsEnabled ? normalizedQuestion.teacherInstructions : null;
|
|
154
|
-
} else {
|
|
155
|
-
base.rationale = null;
|
|
156
|
-
base.teacherInstructions = null;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
if (env.mode === 'evaluate') {
|
|
160
|
-
value = session && session.value || [];
|
|
161
|
-
allCorrectResponses = (0, _scoring.getAllCorrectResponses)(normalizedQuestion);
|
|
162
|
-
bestSetOfResponses = allCorrectResponses.reduce(function (info, cr) {
|
|
163
|
-
var currentScore = _lodash["default"].reduce(value, function (acc, c, idx) {
|
|
164
|
-
return acc + (Array.isArray(cr) && cr[idx] === c ? 1 : 0);
|
|
165
|
-
}, 0);
|
|
166
|
-
|
|
167
|
-
if (currentScore > info.score) {
|
|
168
|
-
return {
|
|
169
|
-
arr: cr,
|
|
170
|
-
score: currentScore
|
|
171
|
-
};
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
return info;
|
|
175
|
-
}, {
|
|
176
|
-
arr: [],
|
|
177
|
-
score: 0
|
|
178
|
-
});
|
|
179
|
-
base.outcomes = _lodash["default"].map(value, function (c, idx) {
|
|
180
|
-
return {
|
|
181
|
-
id: c,
|
|
182
|
-
outcome: bestSetOfResponses.arr[idx] === c ? 'correct' : 'incorrect'
|
|
183
|
-
};
|
|
184
|
-
});
|
|
185
|
-
isResponseCorrect = allCorrectResponses.some(function (response) {
|
|
186
|
-
return _lodash["default"].isEqual(response, value);
|
|
187
|
-
});
|
|
188
|
-
responseScore = (0, _scoring.score)(question, session);
|
|
189
|
-
isCorrect = responseScore === 1;
|
|
190
|
-
isPartialCorrect = !isCorrect && _controllerUtils.partialScoring.enabled(normalizedQuestion, env || {}) && responseScore !== 0;
|
|
191
|
-
base.correctness = isCorrect ? 'correct' : isPartialCorrect ? 'partial' : 'incorrect';
|
|
192
|
-
|
|
193
|
-
if (!isResponseCorrect) {
|
|
194
|
-
base.correctResponse = (0, _scoring.flattenCorrect)(normalizedQuestion);
|
|
195
|
-
} // requirement made in PD-2182
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
if (!normalizedQuestion.feedback) {
|
|
199
|
-
normalizedQuestion.feedbackEnabled = false;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
fb = normalizedQuestion.feedbackEnabled ? (0, _feedback.getFeedbackForCorrectness)(base.correctness, normalizedQuestion.feedback) : Promise.resolve(undefined);
|
|
203
|
-
fb.then(function (feedback) {
|
|
204
|
-
base.feedback = feedback;
|
|
205
|
-
resolve(base);
|
|
206
|
-
});
|
|
207
|
-
} else {
|
|
208
|
-
resolve(base);
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
case 18:
|
|
212
|
-
case "end":
|
|
213
|
-
return _context.stop();
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
}, _callee);
|
|
217
|
-
}));
|
|
218
|
-
|
|
219
|
-
return function (_x) {
|
|
220
|
-
return _ref.apply(this, arguments);
|
|
221
|
-
};
|
|
222
|
-
}());
|
|
147
|
+
// requirement made in PD-2182
|
|
148
|
+
if (!normalizedQuestion.feedback) {
|
|
149
|
+
normalizedQuestion.feedbackEnabled = false;
|
|
150
|
+
}
|
|
151
|
+
const feedback = normalizedQuestion.feedbackEnabled ? await (0, _feedback.getFeedbackForCorrectness)(base.correctness, normalizedQuestion.feedback) : undefined;
|
|
152
|
+
base.feedback = feedback;
|
|
153
|
+
return base;
|
|
154
|
+
} else {
|
|
155
|
+
return base;
|
|
156
|
+
}
|
|
223
157
|
}
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
return new Promise(function (resolve) {
|
|
158
|
+
const createCorrectResponseSession = (question, env) => {
|
|
159
|
+
return new Promise(resolve => {
|
|
227
160
|
if (env.mode !== 'evaluate' && env.role === 'instructor') {
|
|
228
161
|
resolve({
|
|
229
162
|
id: '1',
|
|
@@ -233,68 +166,50 @@ var createCorrectResponseSession = function createCorrectResponseSession(questio
|
|
|
233
166
|
resolve(null);
|
|
234
167
|
}
|
|
235
168
|
});
|
|
236
|
-
}; // remove all html tags
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
exports.createCorrectResponseSession = createCorrectResponseSession;
|
|
240
|
-
|
|
241
|
-
var getInnerText = function getInnerText(html) {
|
|
242
|
-
return (html || '').replaceAll(/<[^>]*>/g, '');
|
|
243
|
-
}; // remove all html tags except img, iframe and source tag for audio
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
var getContent = function getContent(html) {
|
|
247
|
-
return (html || '').replace(/(<(?!img|iframe|source)([^>]+)>)/gi, '');
|
|
248
169
|
};
|
|
249
170
|
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
171
|
+
// remove all html tags
|
|
172
|
+
exports.createCorrectResponseSession = createCorrectResponseSession;
|
|
173
|
+
const getInnerText = html => (html || '').replaceAll(/<[^>]*>/g, '');
|
|
174
|
+
|
|
175
|
+
// remove all html tags except img, iframe and source tag for audio
|
|
176
|
+
const getContent = html => (html || '').replace(/(<(?!img|iframe|source)([^>]+)>)/gi, '');
|
|
177
|
+
const validate = (model = {}, config = {}) => {
|
|
178
|
+
const {
|
|
179
|
+
choices,
|
|
180
|
+
correctResponse
|
|
181
|
+
} = model;
|
|
182
|
+
const errors = {};
|
|
183
|
+
['teacherInstructions', 'prompt', 'rationale'].forEach(field => {
|
|
184
|
+
if (config[field]?.required && !getContent(model[field])) {
|
|
260
185
|
errors[field] = 'This field is required.';
|
|
261
186
|
}
|
|
262
187
|
});
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
reversedChoices.forEach(
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
188
|
+
const reversedChoices = [...(choices || [])].reverse();
|
|
189
|
+
const choicesErrors = {};
|
|
190
|
+
reversedChoices.forEach((choice, index) => {
|
|
191
|
+
const {
|
|
192
|
+
id,
|
|
193
|
+
label
|
|
194
|
+
} = choice;
|
|
269
195
|
if (!getContent(label)) {
|
|
270
196
|
choicesErrors[id] = 'Content should not be empty.';
|
|
271
197
|
} else {
|
|
272
|
-
|
|
273
|
-
return c.label === label;
|
|
274
|
-
});
|
|
275
|
-
|
|
198
|
+
const identicalAnswer = reversedChoices.slice(index + 1).some(c => c.label === label);
|
|
276
199
|
if (identicalAnswer) {
|
|
277
200
|
choicesErrors[id] = 'Content should be unique.';
|
|
278
201
|
}
|
|
279
202
|
}
|
|
280
203
|
});
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
var correctResponseIds = (correctResponse || []).map(function (response) {
|
|
285
|
-
return response.id || response;
|
|
286
|
-
});
|
|
287
|
-
|
|
288
|
-
if ((0, _isEqual["default"])(choicesIds, correctResponseIds)) {
|
|
204
|
+
const choicesIds = (choices || []).map(choice => choice.id);
|
|
205
|
+
const correctResponseIds = (correctResponse || []).map(response => response.id || response);
|
|
206
|
+
if ((0, _isEqual.default)(choicesIds, correctResponseIds)) {
|
|
289
207
|
errors.orderError = 'The correct ordering should not be identical to the initial ordering.';
|
|
290
208
|
}
|
|
291
|
-
|
|
292
|
-
if (!(0, _isEmpty["default"])(choicesErrors)) {
|
|
209
|
+
if (!(0, _isEmpty.default)(choicesErrors)) {
|
|
293
210
|
errors.choicesErrors = choicesErrors;
|
|
294
211
|
}
|
|
295
|
-
|
|
296
212
|
return errors;
|
|
297
213
|
};
|
|
298
|
-
|
|
299
214
|
exports.validate = validate;
|
|
300
215
|
//# sourceMappingURL=index.js.map
|