@pie-element/placement-ordering 7.7.9 → 7.8.1-beta.1443
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 +374 -0
- package/README.md +1 -1
- package/configure/CHANGELOG.md +356 -0
- package/configure/lib/choice-editor.js +73 -65
- package/configure/lib/choice-editor.js.map +1 -1
- package/configure/lib/choice-tile.js +44 -48
- package/configure/lib/choice-tile.js.map +1 -1
- package/configure/lib/defaults.js +23 -0
- package/configure/lib/defaults.js.map +1 -1
- package/configure/lib/design.js +204 -94
- package/configure/lib/design.js.map +1 -1
- package/configure/lib/help.js.map +1 -1
- package/configure/lib/index.js +16 -2
- package/configure/lib/index.js.map +1 -1
- package/configure/lib/utils.js +14 -0
- package/configure/lib/utils.js.map +1 -0
- package/configure/package.json +6 -6
- package/controller/CHANGELOG.md +57 -0
- package/controller/lib/defaults.js.map +1 -1
- package/controller/lib/index.js +67 -16
- package/controller/lib/index.js.map +1 -1
- package/controller/lib/scoring.js +3 -3
- package/controller/lib/scoring.js.map +1 -1
- package/controller/package.json +3 -3
- package/docs/config-schema.json +145 -0
- package/docs/config-schema.json.md +113 -1
- package/docs/demo/config.js +2 -2
- package/docs/demo/generate.js +9 -10
- package/docs/demo/index.html +1 -2
- package/docs/demo/session.js +1 -1
- package/docs/pie-schema.json +48 -0
- package/docs/pie-schema.json.md +36 -0
- package/lib/index.js +4 -1
- package/lib/index.js.map +1 -1
- package/lib/main.js.map +1 -1
- package/lib/ordering.js +2 -1
- package/lib/ordering.js.map +1 -1
- package/lib/placement-ordering.js +73 -30
- package/lib/placement-ordering.js.map +1 -1
- package/lib/tile.js.map +1 -1
- package/lib/tiler.js +2 -2
- package/lib/tiler.js.map +1 -1
- package/package.json +7 -7
package/configure/package.json
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pie-element/placement-ordering-configure",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.5.0",
|
|
4
4
|
"private": true,
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "src/index.js",
|
|
7
7
|
"dependencies": {
|
|
8
8
|
"@material-ui/core": "^3.9.2",
|
|
9
9
|
"@material-ui/icons": "^3.0.1",
|
|
10
|
-
"@pie-framework/pie-configure-events": "^1.
|
|
11
|
-
"@pie-lib/config-ui": "
|
|
12
|
-
"@pie-lib/editable-html": "
|
|
13
|
-
"@pie-lib/scoring-config": "^3.
|
|
10
|
+
"@pie-framework/pie-configure-events": "^1.3.0",
|
|
11
|
+
"@pie-lib/config-ui": "12.0.0-beta.2",
|
|
12
|
+
"@pie-lib/editable-html": "10.0.0-beta.2",
|
|
13
|
+
"@pie-lib/scoring-config": "^3.6.12",
|
|
14
14
|
"debug": "^3.1.0",
|
|
15
15
|
"lodash": "^4.17.15",
|
|
16
16
|
"nested-property": "^0.0.7",
|
|
17
17
|
"pluralize": "^8.0.0",
|
|
18
18
|
"prop-types": "^15.6.2",
|
|
19
19
|
"react": "^16.8.1",
|
|
20
|
-
"react-dnd": "^
|
|
20
|
+
"react-dnd": "^14.0.5",
|
|
21
21
|
"react-dom": "^16.8.1"
|
|
22
22
|
}
|
|
23
23
|
}
|
package/controller/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,63 @@
|
|
|
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
|
+
## [6.5.2](https://github.com/pie-framework/pie-elements/compare/@pie-element/placement-ordering-controller@6.5.1...@pie-element/placement-ordering-controller@6.5.2) (2022-12-07)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* revert Patricia's latest changes related to PD-2155, revert Carla's changes related to PD-1559, and updated the approach of setting a default session value PD-2155 ([890f3a3](https://github.com/pie-framework/pie-elements/commit/890f3a3fb9077d7f2e53062ad9d4cd43c7d30365))
|
|
12
|
+
* update libs ([441f403](https://github.com/pie-framework/pie-elements/commit/441f403870b7bec0d61fab58b8d93dbe0ead4c32))
|
|
13
|
+
* **placement-ordering:** disable feedbackEnabled if feedback object is not present in model PD-2182 ([98aa82a](https://github.com/pie-framework/pie-elements/commit/98aa82a7f153471217e53c3ff8e942d9a9b31975))
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
## [6.5.1](https://github.com/pie-framework/pie-elements/compare/@pie-element/placement-ordering-controller@6.5.0...@pie-element/placement-ordering-controller@6.5.1) (2022-11-15)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
### Bug Fixes
|
|
23
|
+
|
|
24
|
+
* **placement-ordering:** fix feedback behavior PD-2156 ([561c36f](https://github.com/pie-framework/pie-elements/commit/561c36fdd2467fcc38907cdbbb91d990ef5c8ee3))
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
# [6.5.0](https://github.com/pie-framework/pie-elements/compare/@pie-element/placement-ordering-controller@6.4.7...@pie-element/placement-ordering-controller@6.5.0) (2022-10-31)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
### Bug Fixes
|
|
34
|
+
|
|
35
|
+
* add choices validation in controller method, remove from autoring PD-2152 ([8c49a7f](https://github.com/pie-framework/pie-elements/commit/8c49a7f6500bf541e03d86276292189aeadb465a))
|
|
36
|
+
* **placement-ordering:** add sanity check for alternateResponses to prevent console.error if it's undefined PD-2135 ([5290755](https://github.com/pie-framework/pie-elements/commit/5290755b2b4a339f81835a6c8dfd0dacee540630))
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
### Features
|
|
40
|
+
|
|
41
|
+
* **placement-ordering:** added validation PD-1743 ([a2f2611](https://github.com/pie-framework/pie-elements/commit/a2f2611da08ab41f2944b9dd5adaca1fc4821d8a))
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
## [6.4.7](https://github.com/pie-framework/pie-elements/compare/@pie-element/placement-ordering-controller@6.4.6...@pie-element/placement-ordering-controller@6.4.7) (2022-05-16)
|
|
48
|
+
|
|
49
|
+
**Note:** Version bump only for package @pie-element/placement-ordering-controller
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
## [6.4.6](https://github.com/pie-framework/pie-elements/compare/@pie-element/placement-ordering-controller@6.4.5...@pie-element/placement-ordering-controller@6.4.6) (2022-03-08)
|
|
56
|
+
|
|
57
|
+
**Note:** Version bump only for package @pie-element/placement-ordering-controller
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
6
63
|
## [6.4.2](https://github.com/pie-framework/pie-elements/compare/@pie-element/placement-ordering-controller@6.4.1...@pie-element/placement-ordering-controller@6.4.2) (2021-12-01)
|
|
7
64
|
|
|
8
65
|
**Note:** Version bump only for package @pie-element/placement-ordering-controller
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/defaults.js"],"names":["choiceLabel","choices","correctResponse","enableImages","prompt","numberedGuides","orientation","partialScoring","placementArea","choiceLabelEnabled","removeTilesAfterPlacing","scoringType","targetLabel","note","rationaleEnabled","feedbackEnabled","promptEnabled","teacherInstructionsEnabled","studentInstructionsEnabled"],"mappings":";;;;;;eAAe;AACbA,EAAAA,WAAW,EAAE,EADA;AAEbC,EAAAA,OAAO,EAAE,EAFI;AAGbC,EAAAA,eAAe,EAAE,EAHJ;AAIbC,EAAAA,YAAY,EAAE,KAJD;AAKbC,EAAAA,MAAM,EAAE,qBALK;AAMbC,EAAAA,cAAc,EAAE,KANH;AAObC,EAAAA,WAAW,EAAE,UAPA;AAQbC,EAAAA,cAAc,EAAE,IARH;AASbC,EAAAA,aAAa,EAAE,KATF;AAUbC,EAAAA,kBAAkB,EAAE,IAVP;AAWbC,EAAAA,uBAAuB,EAAE,IAXZ;AAYbC,EAAAA,WAAW,EAAE,MAZA;AAabC,EAAAA,WAAW,EAAE,EAbA;AAcbC,EAAAA,IAAI,EAAE,0KAdO;AAebC,EAAAA,gBAAgB,EAAE,IAfL;AAgBbC,EAAAA,eAAe,EAAE,IAhBJ;AAiBbC,EAAAA,aAAa,EAAE,IAjBF;AAkBbC,EAAAA,0BAA0B,EAAE,IAlBf;AAmBbC,EAAAA,0BAA0B,EAAE;AAnBf,C","sourcesContent":["export default {\n choiceLabel: '',\n choices: [],\n correctResponse: [],\n enableImages: false,\n prompt: 'Item Stem goes here',\n numberedGuides: false,\n orientation: 'vertical',\n partialScoring: true,\n placementArea: false,\n choiceLabelEnabled: true,\n removeTilesAfterPlacing: true,\n scoringType: 'auto',\n targetLabel: '',\n note: 'The answer shown above is the most common correct answer for this item. One or more additional correct answers are also defined, and will also be recognized as correct.',\n rationaleEnabled: true,\n feedbackEnabled: true,\n promptEnabled: true,\n teacherInstructionsEnabled: true,\n studentInstructionsEnabled: true
|
|
1
|
+
{"version":3,"sources":["../src/defaults.js"],"names":["choiceLabel","choices","correctResponse","enableImages","prompt","numberedGuides","orientation","partialScoring","placementArea","choiceLabelEnabled","removeTilesAfterPlacing","scoringType","targetLabel","note","rationaleEnabled","feedbackEnabled","promptEnabled","teacherInstructionsEnabled","studentInstructionsEnabled"],"mappings":";;;;;;eAAe;AACbA,EAAAA,WAAW,EAAE,EADA;AAEbC,EAAAA,OAAO,EAAE,EAFI;AAGbC,EAAAA,eAAe,EAAE,EAHJ;AAIbC,EAAAA,YAAY,EAAE,KAJD;AAKbC,EAAAA,MAAM,EAAE,qBALK;AAMbC,EAAAA,cAAc,EAAE,KANH;AAObC,EAAAA,WAAW,EAAE,UAPA;AAQbC,EAAAA,cAAc,EAAE,IARH;AASbC,EAAAA,aAAa,EAAE,KATF;AAUbC,EAAAA,kBAAkB,EAAE,IAVP;AAWbC,EAAAA,uBAAuB,EAAE,IAXZ;AAYbC,EAAAA,WAAW,EAAE,MAZA;AAabC,EAAAA,WAAW,EAAE,EAbA;AAcbC,EAAAA,IAAI,EAAE,0KAdO;AAebC,EAAAA,gBAAgB,EAAE,IAfL;AAgBbC,EAAAA,eAAe,EAAE,IAhBJ;AAiBbC,EAAAA,aAAa,EAAE,IAjBF;AAkBbC,EAAAA,0BAA0B,EAAE,IAlBf;AAmBbC,EAAAA,0BAA0B,EAAE;AAnBf,C","sourcesContent":["export default {\n choiceLabel: '',\n choices: [],\n correctResponse: [],\n enableImages: false,\n prompt: 'Item Stem goes here',\n numberedGuides: false,\n orientation: 'vertical',\n partialScoring: true,\n placementArea: false,\n choiceLabelEnabled: true,\n removeTilesAfterPlacing: true,\n scoringType: 'auto',\n targetLabel: '',\n note: 'The answer shown above is the most common correct answer for this item. One or more additional correct answers are also defined, and will also be recognized as correct.',\n rationaleEnabled: true,\n feedbackEnabled: true,\n promptEnabled: true,\n teacherInstructionsEnabled: true,\n studentInstructionsEnabled: true,\n};\n"],"file":"defaults.js"}
|
package/controller/lib/index.js
CHANGED
|
@@ -5,13 +5,17 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
-
exports.
|
|
8
|
+
exports.createCorrectResponseSession = void 0;
|
|
9
9
|
exports.createDefaultModel = createDefaultModel;
|
|
10
10
|
exports.model = model;
|
|
11
|
-
exports.
|
|
11
|
+
exports.normalize = void 0;
|
|
12
|
+
exports.outcome = outcome;
|
|
13
|
+
exports.validate = exports.questionError = void 0;
|
|
12
14
|
|
|
13
15
|
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
14
16
|
|
|
17
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
18
|
+
|
|
15
19
|
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
16
20
|
|
|
17
21
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
@@ -28,9 +32,13 @@ var _debug = _interopRequireDefault(require("debug"));
|
|
|
28
32
|
|
|
29
33
|
var _defaults = _interopRequireDefault(require("./defaults"));
|
|
30
34
|
|
|
31
|
-
|
|
35
|
+
var _isEqual = _interopRequireDefault(require("lodash/isEqual"));
|
|
36
|
+
|
|
37
|
+
var _isEmpty = _interopRequireDefault(require("lodash/isEmpty"));
|
|
32
38
|
|
|
33
|
-
function
|
|
39
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
40
|
+
|
|
41
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
34
42
|
|
|
35
43
|
var log = (0, _debug["default"])('@pie-element:placement-ordering:controller');
|
|
36
44
|
|
|
@@ -94,7 +102,7 @@ exports.normalize = normalize;
|
|
|
94
102
|
function model(question, session, env) {
|
|
95
103
|
return new Promise( /*#__PURE__*/function () {
|
|
96
104
|
var _ref = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(resolve) {
|
|
97
|
-
var normalizedQuestion, base, value, allCorrectResponses, bestSetOfResponses, allCorrect;
|
|
105
|
+
var normalizedQuestion, base, value, allCorrectResponses, bestSetOfResponses, allCorrect, fb;
|
|
98
106
|
return _regenerator["default"].wrap(function _callee$(_context) {
|
|
99
107
|
while (1) {
|
|
100
108
|
switch (_context.prev = _context.next) {
|
|
@@ -102,7 +110,7 @@ function model(question, session, env) {
|
|
|
102
110
|
normalizedQuestion = normalize(question);
|
|
103
111
|
base = {};
|
|
104
112
|
|
|
105
|
-
if (_lodash["default"].every(question.alternateResponses, _lodash["default"].isArray)) {
|
|
113
|
+
if (question.alternateResponses && _lodash["default"].every(question.alternateResponses, _lodash["default"].isArray)) {
|
|
106
114
|
log('Deprecated structure of alternateResponses is in use');
|
|
107
115
|
console.error('Deprecated structure of alternateResponses is in use');
|
|
108
116
|
}
|
|
@@ -115,13 +123,6 @@ function model(question, session, env) {
|
|
|
115
123
|
});
|
|
116
124
|
base.note = normalizedQuestion.note;
|
|
117
125
|
base.showNote = normalizedQuestion.alternateResponses && normalizedQuestion.alternateResponses.length > 0;
|
|
118
|
-
|
|
119
|
-
if (env.mode === 'gather' && !normalizedQuestion.placementArea) {
|
|
120
|
-
session.value = base.choices.map(function (m) {
|
|
121
|
-
return m.id;
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
|
|
125
126
|
log('[model] removing tileSize for the moment.');
|
|
126
127
|
base.prompt = normalizedQuestion.promptEnabled ? normalizedQuestion.prompt : null;
|
|
127
128
|
base.config = {
|
|
@@ -143,7 +144,7 @@ function model(question, session, env) {
|
|
|
143
144
|
base.teacherInstructions = null;
|
|
144
145
|
}
|
|
145
146
|
|
|
146
|
-
if (env.mode === 'evaluate'
|
|
147
|
+
if (env.mode === 'evaluate') {
|
|
147
148
|
value = session && session.value || [];
|
|
148
149
|
allCorrectResponses = (0, _scoring.getAllCorrectResponses)(normalizedQuestion);
|
|
149
150
|
bestSetOfResponses = allCorrectResponses.reduce(function (info, cr) {
|
|
@@ -180,9 +181,15 @@ function model(question, session, env) {
|
|
|
180
181
|
|
|
181
182
|
if (!allCorrect) {
|
|
182
183
|
base.correctResponse = (0, _scoring.flattenCorrect)(normalizedQuestion);
|
|
184
|
+
} // requirement made in PD-2182
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
if (!normalizedQuestion.feedback) {
|
|
188
|
+
normalizedQuestion.feedbackEnabled = false;
|
|
183
189
|
}
|
|
184
190
|
|
|
185
|
-
(0, _feedback.getFeedbackForCorrectness)(base.correctness, normalizedQuestion.feedback).
|
|
191
|
+
fb = normalizedQuestion.feedbackEnabled ? (0, _feedback.getFeedbackForCorrectness)(base.correctness, normalizedQuestion.feedback) : Promise.resolve(undefined);
|
|
192
|
+
fb.then(function (feedback) {
|
|
186
193
|
base.feedback = feedback;
|
|
187
194
|
resolve(base);
|
|
188
195
|
});
|
|
@@ -190,7 +197,7 @@ function model(question, session, env) {
|
|
|
190
197
|
resolve(base);
|
|
191
198
|
}
|
|
192
199
|
|
|
193
|
-
case
|
|
200
|
+
case 15:
|
|
194
201
|
case "end":
|
|
195
202
|
return _context.stop();
|
|
196
203
|
}
|
|
@@ -218,4 +225,48 @@ var createCorrectResponseSession = function createCorrectResponseSession(questio
|
|
|
218
225
|
};
|
|
219
226
|
|
|
220
227
|
exports.createCorrectResponseSession = createCorrectResponseSession;
|
|
228
|
+
|
|
229
|
+
var validate = function validate() {
|
|
230
|
+
var model = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
231
|
+
var config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
232
|
+
var choices = model.choices,
|
|
233
|
+
correctResponse = model.correctResponse;
|
|
234
|
+
var errors = {};
|
|
235
|
+
var reversedChoices = (0, _toConsumableArray2["default"])(choices || []).reverse();
|
|
236
|
+
var choicesErrors = {};
|
|
237
|
+
reversedChoices.forEach(function (choice, index) {
|
|
238
|
+
var id = choice.id,
|
|
239
|
+
label = choice.label;
|
|
240
|
+
|
|
241
|
+
if (label === '' || label === '<div></div>') {
|
|
242
|
+
choicesErrors[id] = 'Content should not be empty.';
|
|
243
|
+
} else {
|
|
244
|
+
var identicalAnswer = reversedChoices.slice(index + 1).some(function (c) {
|
|
245
|
+
return c.label === label;
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
if (identicalAnswer) {
|
|
249
|
+
choicesErrors[id] = 'Content should be unique.';
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
var choicesIds = (choices || []).map(function (choice) {
|
|
254
|
+
return choice.id;
|
|
255
|
+
});
|
|
256
|
+
var correctResponseIds = (correctResponse || []).map(function (response) {
|
|
257
|
+
return response.id || response;
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
if ((0, _isEqual["default"])(choicesIds, correctResponseIds)) {
|
|
261
|
+
errors.orderError = 'The correct ordering should not be identical to the initial ordering.';
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
if (!(0, _isEmpty["default"])(choicesErrors)) {
|
|
265
|
+
errors.choicesErrors = choicesErrors;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
return errors;
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
exports.validate = validate;
|
|
221
272
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.js"],"names":["log","questionError","Error","outcome","question","session","env","Promise","resolve","reject","_","isEmpty","score","empty","correctResponse","s","finalScore","partialScoring","enabled","e","createDefaultModel","model","defaults","normalize","rationaleEnabled","feedbackEnabled","promptEnabled","teacherInstructionsEnabled","studentInstructionsEnabled","normalizedQuestion","base","every","alternateResponses","isArray","console","error","outcomes","completeLength","length","choices","filter","choice","label","note","showNote","mode","placementArea","value","map","m","id","prompt","config","orientation","includeTargets","choiceLabelEnabled","targetLabel","choiceLabel","showOrdering","numberedGuides","allowSameChoiceInTargets","removeTilesAfterPlacing","disabled","role","rationale","teacherInstructions","allCorrectResponses","bestSetOfResponses","reduce","info","cr","currentScore","acc","c","idx","arr","allCorrect","correct","isEqual","correctness","feedback","then","createCorrectResponseSession"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;;AAEA;;AACA;;AACA;;AACA;;AAEA;;;;;;AAEA,IAAMA,GAAG,GAAG,uBAA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,6BAAe3C,QAAf;AAFD,OAAD,CAAP;AAID,KALD,MAKO;AACLI,MAAAA,OAAO,CAAC,IAAD,CAAP;AACD;AACF,GATM,CAAP;AAUD,CAXM","sourcesContent":["import { flattenCorrect, getAllCorrectResponses, score } from './scoring';\n\nimport _ from 'lodash';\nimport { getFeedbackForCorrectness } from '@pie-lib/feedback';\nimport { partialScoring } from '@pie-lib/controller-utils';\nimport debug from 'debug';\n\nimport defaults from './defaults';\n\nconst log = debug('@pie-element:placement-ordering:controller');\n\nexport const questionError = () =>\n new Error('Question is missing required array: correctResponse');\n\nexport function outcome(question, session, env) {\n return new Promise((resolve, reject) => {\n if (!session || _.isEmpty(session)) {\n resolve({ score: 0, empty: true });\n }\n\n if (\n !question ||\n !question.correctResponse ||\n _.isEmpty(question.correctResponse)\n ) {\n reject(questionError());\n } else {\n try {\n const s = score(question, session);\n const finalScore = partialScoring.enabled(question, env || {})\n ? s\n : s === 1\n ? 1\n : 0;\n resolve({\n score: finalScore\n });\n } catch (e) {\n reject(e);\n }\n }\n });\n}\n\nexport function createDefaultModel(model = {}) {\n return new Promise(resolve => {\n resolve({\n ...defaults,\n ...model\n });\n });\n}\n\nexport const normalize = question => ({\n ...defaults,\n rationaleEnabled: true,\n feedbackEnabled: true,\n promptEnabled: true,\n teacherInstructionsEnabled: true,\n studentInstructionsEnabled: true,\n ...question\n});\n\n/**\n *\n * @param {*} question\n * @param {*} session\n * @param {*} env\n */\nexport function model(question, session, env) {\n return new Promise(async resolve => {\n const normalizedQuestion = normalize(question);\n const base = {};\n\n if (_.every(question.alternateResponses, _.isArray)) {\n log('Deprecated structure of alternateResponses is in use');\n console.error('Deprecated structure of alternateResponses is in use');\n }\n\n base.env = env;\n base.outcomes = [];\n base.completeLength = (normalizedQuestion.correctResponse || []).length;\n base.choices = (normalizedQuestion.choices || []).filter(choice => choice.label);\n base.note = normalizedQuestion.note;\n base.showNote = normalizedQuestion.alternateResponses && normalizedQuestion.alternateResponses.length > 0;\n\n if (env.mode === 'gather' && !normalizedQuestion.placementArea) {\n session.value = base.choices.map(m => m.id);\n }\n\n log('[model] removing tileSize for the moment.');\n\n base.prompt = normalizedQuestion.promptEnabled\n ? normalizedQuestion.prompt\n : null;\n base.config = {\n orientation: normalizedQuestion.orientation || 'vertical',\n includeTargets: normalizedQuestion.placementArea,\n choiceLabelEnabled: normalizedQuestion.choiceLabelEnabled,\n targetLabel: normalizedQuestion.targetLabel,\n choiceLabel: normalizedQuestion.choiceLabel,\n showOrdering: normalizedQuestion.numberedGuides,\n allowSameChoiceInTargets: !normalizedQuestion.removeTilesAfterPlacing\n };\n\n base.disabled = env.mode !== 'gather';\n\n if (\n env.role === 'instructor' &&\n (env.mode === 'view' || env.mode === 'evaluate')\n ) {\n base.rationale = normalizedQuestion.rationaleEnabled\n ? normalizedQuestion.rationale\n : null;\n base.teacherInstructions = normalizedQuestion.teacherInstructionsEnabled\n ? normalizedQuestion.teacherInstructions\n : null;\n } else {\n base.rationale = null;\n base.teacherInstructions = null;\n }\n\n if (env.mode === 'evaluate' && normalizedQuestion.feedbackEnabled) {\n const value = (session && session.value) || [];\n const allCorrectResponses = getAllCorrectResponses(normalizedQuestion);\n\n const bestSetOfResponses = allCorrectResponses.reduce(\n (info, cr) => {\n const currentScore = _.reduce(\n value,\n (acc, c, idx) => acc + (cr[idx] === c ? 1 : 0),\n 0\n );\n\n if (currentScore > info.score) {\n return {\n arr: cr,\n score: currentScore\n };\n }\n\n return info;\n },\n { arr: [], score: 0 }\n );\n\n base.outcomes = _.map(value, function(c, idx) {\n return {\n id: c,\n outcome: bestSetOfResponses.arr[idx] === c ? 'correct' : 'incorrect'\n };\n });\n\n const allCorrect = allCorrectResponses.reduce((correct, cr) => {\n if (_.isEqual(cr, value)) {\n return true;\n }\n\n return correct;\n }, false);\n\n base.correctness = allCorrect ? 'correct' : 'incorrect';\n\n if (!allCorrect) {\n base.correctResponse = flattenCorrect(normalizedQuestion);\n }\n\n getFeedbackForCorrectness(\n base.correctness,\n normalizedQuestion.feedback\n ).then(feedback => {\n base.feedback = feedback;\n resolve(base);\n });\n } else {\n resolve(base);\n }\n });\n}\n\nexport const createCorrectResponseSession = (question, env) => {\n return new Promise(resolve => {\n if (env.mode !== 'evaluate' && env.role === 'instructor') {\n resolve({\n id: '1',\n value: flattenCorrect(question)\n });\n } else {\n resolve(null);\n }\n });\n};\n"],"file":"index.js"}
|
|
1
|
+
{"version":3,"sources":["../src/index.js"],"names":["log","questionError","Error","outcome","question","session","env","Promise","resolve","reject","_","isEmpty","score","empty","correctResponse","s","finalScore","partialScoring","enabled","e","createDefaultModel","model","defaults","normalize","rationaleEnabled","feedbackEnabled","promptEnabled","teacherInstructionsEnabled","studentInstructionsEnabled","normalizedQuestion","base","alternateResponses","every","isArray","console","error","outcomes","completeLength","length","choices","filter","choice","label","note","showNote","prompt","config","orientation","includeTargets","placementArea","choiceLabelEnabled","targetLabel","choiceLabel","showOrdering","numberedGuides","allowSameChoiceInTargets","removeTilesAfterPlacing","disabled","mode","role","rationale","teacherInstructions","value","allCorrectResponses","bestSetOfResponses","reduce","info","cr","currentScore","acc","c","idx","arr","map","id","allCorrect","correct","isEqual","correctness","feedback","fb","undefined","then","createCorrectResponseSession","validate","errors","reversedChoices","reverse","choicesErrors","forEach","index","identicalAnswer","slice","some","choicesIds","correctResponseIds","response","orderError"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA;;AAEA;;AACA;;AACA;;AACA;;AAEA;;AACA;;AACA;;;;;;AAEA,IAAMA,GAAG,GAAG,uBAAM,4CAAN,CAAZ;;AAEO,IAAMC,aAAa,GAAG,SAAhBA,aAAgB;AAAA,SAC3B,IAAIC,KAAJ,CAAU,qDAAV,CAD2B;AAAA,CAAtB;;;;AAGA,SAASC,OAAT,CAAiBC,QAAjB,EAA2BC,OAA3B,EAAoCC,GAApC,EAAyC;AAC9C,SAAO,IAAIC,OAAJ,CAAY,UAACC,OAAD,EAAUC,MAAV,EAAqB;AACtC,QAAI,CAACJ,OAAD,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BAAQT,aAAR,CAAL,EAA6B;AAC3BH,IAAAA,MAAM,CAACG,aAAP,GAAuBA,aAAvB;AACD;;AAED,SAAOH,MAAP;AACD,CAjCM","sourcesContent":["import { flattenCorrect, getAllCorrectResponses, score } from './scoring';\n\nimport _ from 'lodash';\nimport { getFeedbackForCorrectness } from '@pie-lib/feedback';\nimport { partialScoring } from '@pie-lib/controller-utils';\nimport debug from 'debug';\n\nimport defaults from './defaults';\nimport isEqual from 'lodash/isEqual';\nimport isEmpty from 'lodash/isEmpty';\n\nconst log = debug('@pie-element:placement-ordering:controller');\n\nexport const questionError = () =>\n new Error('Question is missing required array: correctResponse');\n\nexport function outcome(question, session, env) {\n return new Promise((resolve, reject) => {\n if (!session || _.isEmpty(session)) {\n resolve({ score: 0, empty: true });\n }\n\n if (\n !question ||\n !question.correctResponse ||\n _.isEmpty(question.correctResponse)\n ) {\n reject(questionError());\n } else {\n try {\n const s = score(question, session);\n const finalScore = partialScoring.enabled(question, env || {})\n ? s\n : s === 1\n ? 1\n : 0;\n resolve({\n score: finalScore\n });\n } catch (e) {\n reject(e);\n }\n }\n });\n}\n\nexport function createDefaultModel(model = {}) {\n return new Promise(resolve => {\n resolve({\n ...defaults,\n ...model\n });\n });\n}\n\nexport const normalize = question => ({\n ...defaults,\n rationaleEnabled: true,\n feedbackEnabled: true,\n promptEnabled: true,\n teacherInstructionsEnabled: true,\n studentInstructionsEnabled: true,\n ...question\n});\n\n/**\n *\n * @param {*} question\n * @param {*} session\n * @param {*} env\n */\nexport function model(question, session, env) {\n return new Promise(async resolve => {\n const normalizedQuestion = normalize(question);\n const base = {};\n\n if (question.alternateResponses && _.every(question.alternateResponses, _.isArray)) {\n log('Deprecated structure of alternateResponses is in use');\n console.error('Deprecated structure of alternateResponses is in use');\n }\n\n base.env = env;\n base.outcomes = [];\n base.completeLength = (normalizedQuestion.correctResponse || []).length;\n base.choices = (normalizedQuestion.choices || []).filter(choice => choice.label);\n base.note = normalizedQuestion.note;\n base.showNote = normalizedQuestion.alternateResponses && normalizedQuestion.alternateResponses.length > 0;\n\n log('[model] removing tileSize for the moment.');\n\n base.prompt = normalizedQuestion.promptEnabled\n ? normalizedQuestion.prompt\n : null;\n base.config = {\n orientation: normalizedQuestion.orientation || 'vertical',\n includeTargets: normalizedQuestion.placementArea,\n choiceLabelEnabled: normalizedQuestion.choiceLabelEnabled,\n targetLabel: normalizedQuestion.targetLabel,\n choiceLabel: normalizedQuestion.choiceLabel,\n showOrdering: normalizedQuestion.numberedGuides,\n allowSameChoiceInTargets: !normalizedQuestion.removeTilesAfterPlacing\n };\n\n base.disabled = env.mode !== 'gather';\n\n if (\n env.role === 'instructor' &&\n (env.mode === 'view' || env.mode === 'evaluate')\n ) {\n base.rationale = normalizedQuestion.rationaleEnabled\n ? normalizedQuestion.rationale\n : null;\n base.teacherInstructions = normalizedQuestion.teacherInstructionsEnabled\n ? normalizedQuestion.teacherInstructions\n : null;\n } else {\n base.rationale = null;\n base.teacherInstructions = null;\n }\n\n if (env.mode === 'evaluate') {\n const value = (session && session.value) || [];\n const allCorrectResponses = getAllCorrectResponses(normalizedQuestion);\n\n const bestSetOfResponses = allCorrectResponses.reduce(\n (info, cr) => {\n const currentScore = _.reduce(\n value,\n (acc, c, idx) => acc + (cr[idx] === c ? 1 : 0),\n 0\n );\n\n if (currentScore > info.score) {\n return {\n arr: cr,\n score: currentScore\n };\n }\n\n return info;\n },\n { arr: [], score: 0 }\n );\n\n base.outcomes = _.map(value, function(c, idx) {\n return {\n id: c,\n outcome: bestSetOfResponses.arr[idx] === c ? 'correct' : 'incorrect'\n };\n });\n\n const allCorrect = allCorrectResponses.reduce((correct, cr) => {\n if (_.isEqual(cr, value)) {\n return true;\n }\n\n return correct;\n }, false);\n\n base.correctness = allCorrect ? 'correct' : 'incorrect';\n\n if (!allCorrect) {\n base.correctResponse = flattenCorrect(normalizedQuestion);\n }\n\n // requirement made in PD-2182\n if (!normalizedQuestion.feedback) {\n normalizedQuestion.feedbackEnabled = false;\n }\n\n const fb = normalizedQuestion.feedbackEnabled\n ? getFeedbackForCorrectness(base.correctness, normalizedQuestion.feedback)\n : Promise.resolve(undefined);\n\n fb.then((feedback) => {\n base.feedback = feedback;\n resolve(base);\n });\n } else {\n resolve(base);\n }\n });\n}\n\nexport const createCorrectResponseSession = (question, env) => {\n return new Promise(resolve => {\n if (env.mode !== 'evaluate' && env.role === 'instructor') {\n resolve({\n id: '1',\n value: flattenCorrect(question)\n });\n } else {\n resolve(null);\n }\n });\n};\n\nexport const validate = (model = {}, config = {}) => {\n const { choices, correctResponse } = model;\n const errors = {};\n\n const reversedChoices = [...choices || []].reverse();\n const choicesErrors = {};\n\n reversedChoices.forEach((choice, index) => {\n const { id, label } = choice;\n\n if (label === '' || label === '<div></div>') {\n choicesErrors[id] = 'Content should not be empty.';\n } else {\n const identicalAnswer = reversedChoices.slice(index + 1).some(c => c.label === label);\n\n if (identicalAnswer) {\n choicesErrors[id] = 'Content should be unique.';\n }\n }\n });\n\n const choicesIds = (choices || []).map(choice => choice.id);\n const correctResponseIds = (correctResponse || []).map(response => response.id || response);\n\n if (isEqual(choicesIds, correctResponseIds)) {\n errors.orderError = 'The correct ordering should not be identical to the initial ordering.';\n }\n\n if (!isEmpty(choicesErrors)) {\n errors.choicesErrors = choicesErrors;\n }\n\n return errors;\n};\n"],"file":"index.js"}
|
|
@@ -5,7 +5,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
-
exports.score = exports.
|
|
8
|
+
exports.score = exports.pairwiseCombinationScore = exports.illegalArgumentError = exports.getAllCorrectResponses = exports.flattenCorrect = void 0;
|
|
9
9
|
|
|
10
10
|
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
11
11
|
|
|
@@ -17,9 +17,9 @@ var _jsCombinatorics = require("js-combinatorics");
|
|
|
17
17
|
|
|
18
18
|
var _debug = _interopRequireDefault(require("debug"));
|
|
19
19
|
|
|
20
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object);
|
|
20
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
21
21
|
|
|
22
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]
|
|
22
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
23
23
|
|
|
24
24
|
var log = (0, _debug["default"])('pie-elements:placement-ordering:controller');
|
|
25
25
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/scoring.js"],"names":["log","illegalArgumentError","answer","Error","pairwiseCombinationScore","correct","opts","allowDuplicates","orderMustBeComplete","_","isEqual","uniq","length","Array","isArray","correctCombo","toArray","answerCombo","diff","differenceWith","comboLengthDiff","total","actual","n","toFixed","parseFloat","flattenCorrect","question","correctResponse","map","r","id","getAllCorrectResponses","alternates","alternateResponses","alternate","response","score","session","value","allCorrectResponse","configure","removeTilesAfterPlacing","bestScore","forEach","cr","currentScore"],"mappings":";;;;;;;;;;;;;AAAA;;AACA;;AACA;;;;;;AAEA,IAAMA,GAAG,GAAG,uBAAM,4CAAN,CAAZ;;AAEO,IAAMC,oBAAoB,GAAG,SAAvBA,oBAAuB,
|
|
1
|
+
{"version":3,"sources":["../src/scoring.js"],"names":["log","illegalArgumentError","answer","Error","pairwiseCombinationScore","correct","opts","allowDuplicates","orderMustBeComplete","_","isEqual","uniq","length","Array","isArray","correctCombo","toArray","answerCombo","diff","differenceWith","comboLengthDiff","total","actual","n","toFixed","parseFloat","flattenCorrect","question","correctResponse","map","r","id","getAllCorrectResponses","alternates","alternateResponses","alternate","response","score","session","value","allCorrectResponse","configure","removeTilesAfterPlacing","bestScore","forEach","cr","currentScore"],"mappings":";;;;;;;;;;;;;AAAA;;AACA;;AACA;;;;;;AAEA,IAAMA,GAAG,GAAG,uBAAM,4CAAN,CAAZ;;AAEO,IAAMC,oBAAoB,GAAG,SAAvBA,oBAAuB,CAACC,MAAD;AAAA,SAClC,IAAIC,KAAJ,8BAAgCD,MAAhC,qDADkC;AAAA,CAA7B;;;;AAEA,IAAME,wBAAwB,GAAG,SAA3BA,wBAA2B,CAACC,OAAD,EAAUH,MAAV,EAAkBI,IAAlB,EAA2B;AACjEA,EAAAA,IAAI;AAAKC,IAAAA,eAAe,EAAE,KAAtB;AAA6BC,IAAAA,mBAAmB,EAAE;AAAlD,KAA4DF,IAA5D,CAAJ;;AAEA,MAAI,CAACA,IAAI,CAACC,eAAN,IAAyB,CAACE,mBAAEC,OAAF,CAAUD,mBAAEE,IAAF,CAAON,OAAP,CAAV,EAA2BA,OAA3B,CAA9B,EAAmE;AACjE,UAAMJ,oBAAoB,CAACC,MAAD,CAA1B;AACD;;AAED,MAAII,IAAI,CAACC,eAAL,KAAyB,KAAzB,IAAkCL,MAAM,CAACU,MAAP,KAAkBH,mBAAEE,IAAF,CAAOT,MAAP,EAAeU,MAAvE,EAA+E;AAC7E,WAAO,CAAP;AACD;;AAEDV,EAAAA,MAAM,GAAGI,IAAI,CAACC,eAAL,KAAyB,KAAzB,GAAiCL,MAAjC,GAA0CO,mBAAEE,IAAF,CAAOT,MAAP,CAAnD;AAEAF,EAAAA,GAAG,CAAC,SAAD,EA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AG1C,wBAAwB,CAACyC,EAAD,EAAKN,KAAL,EAAY;AACvDhC,MAAAA,eAAe,EAAfA;AADuD,KAAZ,CAA7C;;AAIA,QAAIuC,YAAY,IAAIH,SAApB,EAA+B;AAC7BA,MAAAA,SAAS,GAAGG,YAAZ;AACD;AACF,GARD;AAUA,SAAOH,SAAP;AACD,CA5BM","sourcesContent":["import _ from 'lodash';\nimport { combination } from 'js-combinatorics';\nimport debug from 'debug';\n\nconst log = debug('pie-elements:placement-ordering:controller');\n\nexport const illegalArgumentError = (answer) =>\n new Error(`Cant score answer: ${answer} it has duplicates and allowDuplicates is false`);\nexport const pairwiseCombinationScore = (correct, answer, opts) => {\n opts = { allowDuplicates: false, orderMustBeComplete: false, ...opts };\n\n if (!opts.allowDuplicates && !_.isEqual(_.uniq(correct), correct)) {\n throw illegalArgumentError(answer);\n }\n\n if (opts.allowDuplicates === false && answer.length !== _.uniq(answer).length) {\n return 0;\n }\n\n answer = opts.allowDuplicates !== false ? answer : _.uniq(answer);\n\n log('answer:', answer);\n if (!Array.isArray(correct) || correct.length === 0) {\n throw new Error('correct must be non empty an array');\n }\n\n if (correct.length === 1) {\n return _.isEqual(correct, answer) ? 1 : 0;\n }\n\n if (!Array.isArray(answer) || answer.length < 2) {\n return 0;\n }\n\n if (answer.length > correct.length) {\n return 0;\n }\n\n if (correct.length !== answer.length && opts.orderMustBeComplete) {\n return 0;\n }\n\n const correctCombo = combination(correct, 2).toArray();\n const answerCombo = combination(answer, 2).toArray();\n\n const diff = _.differenceWith(answerCombo, correctCombo, _.isEqual);\n\n const comboLengthDiff = correctCombo.length - answerCombo.length;\n\n const total = correctCombo.length;\n const actual = total - diff.length - comboLengthDiff;\n\n const n = (actual / total).toFixed(2);\n\n return parseFloat(n);\n};\n\n/**\n * Flattens the correctResponse into an array of ordered identifiers representing the\n * correct response.\n */\nexport const flattenCorrect = (question) =>\n question.correctResponse ? question.correctResponse.map((r) => (r && r.id ? r.id : r)) : [];\n\n/**\n * Returns all correct responses for this question\n * @param question - array\n */\nexport const getAllCorrectResponses = (question) => {\n const alternates = (question.alternateResponses || []).map((alternate) => {\n if (Array.isArray(alternate)) {\n return alternate;\n }\n\n return alternate.response;\n });\n\n return [flattenCorrect(question), ...alternates];\n};\n\n/**\n * Returns the score for a session. If weighted scoring is present in the correctResponse\n * field for the question, this will be used. If partial scoring is present in the question\n * model, this will be used. Otherwise the default scoring mechanism (0 for any incorrect, 1\n * for all correct) will be used.\n */\n\nexport const score = (question, session) => {\n const { value } = session || {};\n\n if (!value) {\n return 0;\n }\n\n const allCorrectResponse = getAllCorrectResponses(question);\n const allowDuplicates = (question.configure && question.configure.removeTilesAfterPlacing) !== false;\n\n /**\n * We require this to be the case - locking\n */\n //const orderMustBeComplete = true;\n\n let bestScore = 0;\n\n allCorrectResponse.forEach((cr) => {\n const currentScore = pairwiseCombinationScore(cr, value, {\n allowDuplicates,\n });\n\n if (currentScore >= bestScore) {\n bestScore = currentScore;\n }\n });\n\n return bestScore;\n};\n"],"file":"scoring.js"}
|
package/controller/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pie-element/placement-ordering-controller",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.5.2",
|
|
4
4
|
"private": true,
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "src/index.js",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@pie-lib/controller-utils": "^0.2.
|
|
9
|
-
"@pie-lib/feedback": "^0.4.
|
|
8
|
+
"@pie-lib/controller-utils": "^0.2.42",
|
|
9
|
+
"@pie-lib/feedback": "^0.4.42",
|
|
10
10
|
"debug": "^3.1.0",
|
|
11
11
|
"js-combinatorics": "^0.5.4",
|
|
12
12
|
"lodash": "^4.17.19"
|
package/docs/config-schema.json
CHANGED
|
@@ -179,6 +179,22 @@
|
|
|
179
179
|
}
|
|
180
180
|
}
|
|
181
181
|
},
|
|
182
|
+
"spellCheck": {
|
|
183
|
+
"title": "ConfigureProp",
|
|
184
|
+
"type": "object",
|
|
185
|
+
"properties": {
|
|
186
|
+
"settings": {
|
|
187
|
+
"description": "Indicates if the item has to be displayed in the Settings Panel",
|
|
188
|
+
"type": "boolean",
|
|
189
|
+
"title": "settings"
|
|
190
|
+
},
|
|
191
|
+
"label": {
|
|
192
|
+
"description": "Indicates the label for the item that has to be displayed in the Settings Panel",
|
|
193
|
+
"type": "string",
|
|
194
|
+
"title": "label"
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
},
|
|
182
198
|
"removeTilesAfterPlacing": {
|
|
183
199
|
"title": "ConfigureProp",
|
|
184
200
|
"type": "object",
|
|
@@ -195,6 +211,11 @@
|
|
|
195
211
|
}
|
|
196
212
|
}
|
|
197
213
|
},
|
|
214
|
+
"settingsPanelDisabled": {
|
|
215
|
+
"description": "Indicates if the settings panel is not available",
|
|
216
|
+
"type": "boolean",
|
|
217
|
+
"title": "settingsPanelDisabled"
|
|
218
|
+
},
|
|
198
219
|
"scoringType": {
|
|
199
220
|
"title": "ConfigureProp",
|
|
200
221
|
"type": "object",
|
|
@@ -259,6 +280,94 @@
|
|
|
259
280
|
}
|
|
260
281
|
}
|
|
261
282
|
},
|
|
283
|
+
"maxImageWidth": {
|
|
284
|
+
"title": "ConfigureMaxImageDimensionsProp",
|
|
285
|
+
"type": "object",
|
|
286
|
+
"properties": {
|
|
287
|
+
"teacherInstructions": {
|
|
288
|
+
"description": "Indicates the max dimension for images in teacher instructions",
|
|
289
|
+
"type": "number",
|
|
290
|
+
"title": "teacherInstructions"
|
|
291
|
+
},
|
|
292
|
+
"prompt": {
|
|
293
|
+
"description": "Indicates the max dimension for images in prompt - this is also the default dimension for all other input fields if it's not specified",
|
|
294
|
+
"type": "number",
|
|
295
|
+
"title": "prompt"
|
|
296
|
+
},
|
|
297
|
+
"rationale": {
|
|
298
|
+
"description": "Indicates the max dimension for images in rationale",
|
|
299
|
+
"type": "number",
|
|
300
|
+
"title": "rationale"
|
|
301
|
+
},
|
|
302
|
+
"choicesWithPlacementArea": {
|
|
303
|
+
"description": "Only available for the width prop: indicates the max width for images in choices and choices labels when placement area is enabled",
|
|
304
|
+
"type": "number",
|
|
305
|
+
"title": "choicesWithPlacementArea"
|
|
306
|
+
},
|
|
307
|
+
"choicesWithoutPlacementArea": {
|
|
308
|
+
"description": "Only available for the width prop: indicates the max width for images in choices and choices labels when placement area is disabled",
|
|
309
|
+
"type": "number",
|
|
310
|
+
"title": "choicesWithoutPlacementArea"
|
|
311
|
+
},
|
|
312
|
+
"choices": {
|
|
313
|
+
"description": "Only available for the height prop: indicates the max height for images in choices and choices labels",
|
|
314
|
+
"type": "number",
|
|
315
|
+
"title": "choices"
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
},
|
|
319
|
+
"maxImageHeight": {
|
|
320
|
+
"title": "ConfigureMaxImageDimensionsProp",
|
|
321
|
+
"type": "object",
|
|
322
|
+
"properties": {
|
|
323
|
+
"teacherInstructions": {
|
|
324
|
+
"description": "Indicates the max dimension for images in teacher instructions",
|
|
325
|
+
"type": "number",
|
|
326
|
+
"title": "teacherInstructions"
|
|
327
|
+
},
|
|
328
|
+
"prompt": {
|
|
329
|
+
"description": "Indicates the max dimension for images in prompt - this is also the default dimension for all other input fields if it's not specified",
|
|
330
|
+
"type": "number",
|
|
331
|
+
"title": "prompt"
|
|
332
|
+
},
|
|
333
|
+
"rationale": {
|
|
334
|
+
"description": "Indicates the max dimension for images in rationale",
|
|
335
|
+
"type": "number",
|
|
336
|
+
"title": "rationale"
|
|
337
|
+
},
|
|
338
|
+
"choicesWithPlacementArea": {
|
|
339
|
+
"description": "Only available for the width prop: indicates the max width for images in choices and choices labels when placement area is enabled",
|
|
340
|
+
"type": "number",
|
|
341
|
+
"title": "choicesWithPlacementArea"
|
|
342
|
+
},
|
|
343
|
+
"choicesWithoutPlacementArea": {
|
|
344
|
+
"description": "Only available for the width prop: indicates the max width for images in choices and choices labels when placement area is disabled",
|
|
345
|
+
"type": "number",
|
|
346
|
+
"title": "choicesWithoutPlacementArea"
|
|
347
|
+
},
|
|
348
|
+
"choices": {
|
|
349
|
+
"description": "Only available for the height prop: indicates the max height for images in choices and choices labels",
|
|
350
|
+
"type": "number",
|
|
351
|
+
"title": "choices"
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
},
|
|
355
|
+
"withRubric": {
|
|
356
|
+
"title": "ConfigureProp",
|
|
357
|
+
"type": "object",
|
|
358
|
+
"properties": {
|
|
359
|
+
"settings": {
|
|
360
|
+
"description": "Indicates if the item has to be displayed in the Settings Panel",
|
|
361
|
+
"type": "boolean",
|
|
362
|
+
"title": "settings"
|
|
363
|
+
},
|
|
364
|
+
"label": {
|
|
365
|
+
"description": "Indicates the label for the item that has to be displayed in the Settings Panel",
|
|
366
|
+
"type": "string",
|
|
367
|
+
"title": "label"
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
},
|
|
262
371
|
"showPrompt": {
|
|
263
372
|
"description": "Determines whether prompt field will be displayed or not",
|
|
264
373
|
"default": true,
|
|
@@ -294,6 +403,42 @@
|
|
|
294
403
|
"title": "label"
|
|
295
404
|
}
|
|
296
405
|
}
|
|
406
|
+
},
|
|
407
|
+
"ConfigureMaxImageDimensionsProp": {
|
|
408
|
+
"title": "ConfigureMaxImageDimensionsProp",
|
|
409
|
+
"type": "object",
|
|
410
|
+
"properties": {
|
|
411
|
+
"teacherInstructions": {
|
|
412
|
+
"description": "Indicates the max dimension for images in teacher instructions",
|
|
413
|
+
"type": "number",
|
|
414
|
+
"title": "teacherInstructions"
|
|
415
|
+
},
|
|
416
|
+
"prompt": {
|
|
417
|
+
"description": "Indicates the max dimension for images in prompt - this is also the default dimension for all other input fields if it's not specified",
|
|
418
|
+
"type": "number",
|
|
419
|
+
"title": "prompt"
|
|
420
|
+
},
|
|
421
|
+
"rationale": {
|
|
422
|
+
"description": "Indicates the max dimension for images in rationale",
|
|
423
|
+
"type": "number",
|
|
424
|
+
"title": "rationale"
|
|
425
|
+
},
|
|
426
|
+
"choicesWithPlacementArea": {
|
|
427
|
+
"description": "Only available for the width prop: indicates the max width for images in choices and choices labels when placement area is enabled",
|
|
428
|
+
"type": "number",
|
|
429
|
+
"title": "choicesWithPlacementArea"
|
|
430
|
+
},
|
|
431
|
+
"choicesWithoutPlacementArea": {
|
|
432
|
+
"description": "Only available for the width prop: indicates the max width for images in choices and choices labels when placement area is disabled",
|
|
433
|
+
"type": "number",
|
|
434
|
+
"title": "choicesWithoutPlacementArea"
|
|
435
|
+
},
|
|
436
|
+
"choices": {
|
|
437
|
+
"description": "Only available for the height prop: indicates the max height for images in choices and choices labels",
|
|
438
|
+
"type": "number",
|
|
439
|
+
"title": "choices"
|
|
440
|
+
}
|
|
441
|
+
}
|
|
297
442
|
}
|
|
298
443
|
},
|
|
299
444
|
"$schema": "http://json-schema.org/draft-07/schema#"
|