@pie-element/ebsr 7.0.24-next.2 → 7.0.26

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.
Files changed (137) hide show
  1. package/CHANGELOG.md +48 -0
  2. package/{configure/node_modules/@pie-element/multiple-choice/LICENSE.md → LICENSE.md} +0 -0
  3. package/configure/CHANGELOG.md +48 -0
  4. package/configure/package.json +3 -3
  5. package/controller/CHANGELOG.md +8 -0
  6. package/controller/package.json +1 -1
  7. package/package.json +3 -3
  8. package/configure/node_modules/@pie-element/multiple-choice/CHANGELOG.json +0 -1972
  9. package/configure/node_modules/@pie-element/multiple-choice/CHANGELOG.md +0 -1793
  10. package/configure/node_modules/@pie-element/multiple-choice/PRINT.md +0 -35
  11. package/configure/node_modules/@pie-element/multiple-choice/README.md +0 -56
  12. package/configure/node_modules/@pie-element/multiple-choice/choice.png +0 -0
  13. package/configure/node_modules/@pie-element/multiple-choice/configure/CHANGELOG.json +0 -1387
  14. package/configure/node_modules/@pie-element/multiple-choice/configure/CHANGELOG.md +0 -1334
  15. package/configure/node_modules/@pie-element/multiple-choice/configure/lib/defaults.js +0 -104
  16. package/configure/node_modules/@pie-element/multiple-choice/configure/lib/defaults.js.map +0 -1
  17. package/configure/node_modules/@pie-element/multiple-choice/configure/lib/index.js +0 -198
  18. package/configure/node_modules/@pie-element/multiple-choice/configure/lib/index.js.map +0 -1
  19. package/configure/node_modules/@pie-element/multiple-choice/configure/lib/main.js +0 -599
  20. package/configure/node_modules/@pie-element/multiple-choice/configure/lib/main.js.map +0 -1
  21. package/configure/node_modules/@pie-element/multiple-choice/configure/lib/utils.js +0 -18
  22. package/configure/node_modules/@pie-element/multiple-choice/configure/lib/utils.js.map +0 -1
  23. package/configure/node_modules/@pie-element/multiple-choice/configure/package.json +0 -20
  24. package/configure/node_modules/@pie-element/multiple-choice/controller/CHANGELOG.json +0 -527
  25. package/configure/node_modules/@pie-element/multiple-choice/controller/CHANGELOG.md +0 -768
  26. package/configure/node_modules/@pie-element/multiple-choice/controller/lib/defaults.js +0 -18
  27. package/configure/node_modules/@pie-element/multiple-choice/controller/lib/defaults.js.map +0 -1
  28. package/configure/node_modules/@pie-element/multiple-choice/controller/lib/index.js +0 -305
  29. package/configure/node_modules/@pie-element/multiple-choice/controller/lib/index.js.map +0 -1
  30. package/configure/node_modules/@pie-element/multiple-choice/controller/lib/utils.js +0 -36
  31. package/configure/node_modules/@pie-element/multiple-choice/controller/lib/utils.js.map +0 -1
  32. package/configure/node_modules/@pie-element/multiple-choice/controller/package.json +0 -15
  33. package/configure/node_modules/@pie-element/multiple-choice/docs/config-schema.json +0 -353
  34. package/configure/node_modules/@pie-element/multiple-choice/docs/config-schema.json.md +0 -277
  35. package/configure/node_modules/@pie-element/multiple-choice/docs/demo/config.js +0 -8
  36. package/configure/node_modules/@pie-element/multiple-choice/docs/demo/generate.js +0 -52
  37. package/configure/node_modules/@pie-element/multiple-choice/docs/demo/index.html +0 -1
  38. package/configure/node_modules/@pie-element/multiple-choice/docs/demo/session.js +0 -7
  39. package/configure/node_modules/@pie-element/multiple-choice/docs/pie-schema.json +0 -338
  40. package/configure/node_modules/@pie-element/multiple-choice/docs/pie-schema.json.md +0 -274
  41. package/configure/node_modules/@pie-element/multiple-choice/lib/choice-input.js +0 -298
  42. package/configure/node_modules/@pie-element/multiple-choice/lib/choice-input.js.map +0 -1
  43. package/configure/node_modules/@pie-element/multiple-choice/lib/choice.js +0 -157
  44. package/configure/node_modules/@pie-element/multiple-choice/lib/choice.js.map +0 -1
  45. package/configure/node_modules/@pie-element/multiple-choice/lib/feedback-tick.js +0 -174
  46. package/configure/node_modules/@pie-element/multiple-choice/lib/feedback-tick.js.map +0 -1
  47. package/configure/node_modules/@pie-element/multiple-choice/lib/index.js +0 -151
  48. package/configure/node_modules/@pie-element/multiple-choice/lib/index.js.map +0 -1
  49. package/configure/node_modules/@pie-element/multiple-choice/lib/main.js +0 -97
  50. package/configure/node_modules/@pie-element/multiple-choice/lib/main.js.map +0 -1
  51. package/configure/node_modules/@pie-element/multiple-choice/lib/multiple-choice.js +0 -254
  52. package/configure/node_modules/@pie-element/multiple-choice/lib/multiple-choice.js.map +0 -1
  53. package/configure/node_modules/@pie-element/multiple-choice/lib/print.js +0 -129
  54. package/configure/node_modules/@pie-element/multiple-choice/lib/print.js.map +0 -1
  55. package/configure/node_modules/@pie-element/multiple-choice/lib/session-updater.js +0 -35
  56. package/configure/node_modules/@pie-element/multiple-choice/lib/session-updater.js.map +0 -1
  57. package/configure/node_modules/@pie-element/multiple-choice/module/configure.js +0 -843
  58. package/configure/node_modules/@pie-element/multiple-choice/module/controller.js +0 -20686
  59. package/configure/node_modules/@pie-element/multiple-choice/module/demo.js +0 -77
  60. package/configure/node_modules/@pie-element/multiple-choice/module/element.js +0 -2019
  61. package/configure/node_modules/@pie-element/multiple-choice/module/index.html +0 -21
  62. package/configure/node_modules/@pie-element/multiple-choice/module/manifest.json +0 -14
  63. package/configure/node_modules/@pie-element/multiple-choice/module/print-demo.js +0 -115
  64. package/configure/node_modules/@pie-element/multiple-choice/module/print.html +0 -18
  65. package/configure/node_modules/@pie-element/multiple-choice/module/print.js +0 -1983
  66. package/configure/node_modules/@pie-element/multiple-choice/package.json +0 -34
  67. package/configure/node_modules/@pie-lib/math-rendering/CHANGELOG.json +0 -672
  68. package/configure/node_modules/@pie-lib/math-rendering/CHANGELOG.md +0 -427
  69. package/configure/node_modules/@pie-lib/math-rendering/LICENSE.md +0 -5
  70. package/configure/node_modules/@pie-lib/math-rendering/lib/index.js +0 -30
  71. package/configure/node_modules/@pie-lib/math-rendering/lib/index.js.map +0 -1
  72. package/configure/node_modules/@pie-lib/math-rendering/lib/mstack/chtml.js +0 -316
  73. package/configure/node_modules/@pie-lib/math-rendering/lib/mstack/chtml.js.map +0 -1
  74. package/configure/node_modules/@pie-lib/math-rendering/lib/mstack/index.js +0 -23
  75. package/configure/node_modules/@pie-lib/math-rendering/lib/mstack/index.js.map +0 -1
  76. package/configure/node_modules/@pie-lib/math-rendering/lib/mstack/mml.js +0 -123
  77. package/configure/node_modules/@pie-lib/math-rendering/lib/mstack/mml.js.map +0 -1
  78. package/configure/node_modules/@pie-lib/math-rendering/lib/normalization.js +0 -103
  79. package/configure/node_modules/@pie-lib/math-rendering/lib/normalization.js.map +0 -1
  80. package/configure/node_modules/@pie-lib/math-rendering/lib/render-math.js +0 -275
  81. package/configure/node_modules/@pie-lib/math-rendering/lib/render-math.js.map +0 -1
  82. package/configure/node_modules/@pie-lib/math-rendering/package.json +0 -19
  83. package/configure/node_modules/@pie-lib/math-rendering/playground/demo.html +0 -872
  84. package/configure/node_modules/@pie-lib/math-rendering/playground/demo.js +0 -108
  85. package/configure/node_modules/@pie-lib/math-rendering/playground/main.html +0 -156
  86. package/configure/node_modules/@pie-lib/math-rendering/playground/main.js +0 -16
  87. package/configure/node_modules/@pie-lib/math-rendering/playground/webpack.config.js +0 -29
  88. package/configure/node_modules/@pie-lib/math-rendering/src/index.js +0 -4
  89. package/configure/node_modules/@pie-lib/math-rendering/src/mstack/chtml.js +0 -215
  90. package/configure/node_modules/@pie-lib/math-rendering/src/mstack/index.js +0 -13
  91. package/configure/node_modules/@pie-lib/math-rendering/src/mstack/mml.js +0 -24
  92. package/configure/node_modules/@pie-lib/math-rendering/src/normalization.js +0 -69
  93. package/configure/node_modules/@pie-lib/math-rendering/src/render-math.js +0 -234
  94. package/configure/node_modules/@pie-lib/render-ui/CHANGELOG.json +0 -937
  95. package/configure/node_modules/@pie-lib/render-ui/CHANGELOG.md +0 -602
  96. package/configure/node_modules/@pie-lib/render-ui/LICENSE.md +0 -5
  97. package/configure/node_modules/@pie-lib/render-ui/README.md +0 -33
  98. package/configure/node_modules/@pie-lib/render-ui/lib/collapsible/index.js +0 -146
  99. package/configure/node_modules/@pie-lib/render-ui/lib/collapsible/index.js.map +0 -1
  100. package/configure/node_modules/@pie-lib/render-ui/lib/color.js +0 -134
  101. package/configure/node_modules/@pie-lib/render-ui/lib/color.js.map +0 -1
  102. package/configure/node_modules/@pie-lib/render-ui/lib/feedback.js +0 -160
  103. package/configure/node_modules/@pie-lib/render-ui/lib/feedback.js.map +0 -1
  104. package/configure/node_modules/@pie-lib/render-ui/lib/has-text.js +0 -24
  105. package/configure/node_modules/@pie-lib/render-ui/lib/has-text.js.map +0 -1
  106. package/configure/node_modules/@pie-lib/render-ui/lib/html-and-math.js +0 -102
  107. package/configure/node_modules/@pie-lib/render-ui/lib/html-and-math.js.map +0 -1
  108. package/configure/node_modules/@pie-lib/render-ui/lib/index.js +0 -104
  109. package/configure/node_modules/@pie-lib/render-ui/lib/index.js.map +0 -1
  110. package/configure/node_modules/@pie-lib/render-ui/lib/input-container.js +0 -60
  111. package/configure/node_modules/@pie-lib/render-ui/lib/input-container.js.map +0 -1
  112. package/configure/node_modules/@pie-lib/render-ui/lib/preview-layout.js +0 -133
  113. package/configure/node_modules/@pie-lib/render-ui/lib/preview-layout.js.map +0 -1
  114. package/configure/node_modules/@pie-lib/render-ui/lib/preview-prompt.js +0 -162
  115. package/configure/node_modules/@pie-lib/render-ui/lib/preview-prompt.js.map +0 -1
  116. package/configure/node_modules/@pie-lib/render-ui/lib/purpose.js +0 -28
  117. package/configure/node_modules/@pie-lib/render-ui/lib/purpose.js.map +0 -1
  118. package/configure/node_modules/@pie-lib/render-ui/lib/readable.js +0 -28
  119. package/configure/node_modules/@pie-lib/render-ui/lib/readable.js.map +0 -1
  120. package/configure/node_modules/@pie-lib/render-ui/lib/response-indicators.js +0 -160
  121. package/configure/node_modules/@pie-lib/render-ui/lib/response-indicators.js.map +0 -1
  122. package/configure/node_modules/@pie-lib/render-ui/lib/withUndoReset.js +0 -206
  123. package/configure/node_modules/@pie-lib/render-ui/lib/withUndoReset.js.map +0 -1
  124. package/configure/node_modules/@pie-lib/render-ui/package.json +0 -30
  125. package/configure/node_modules/@pie-lib/render-ui/src/collapsible/index.jsx +0 -68
  126. package/configure/node_modules/@pie-lib/render-ui/src/color.js +0 -48
  127. package/configure/node_modules/@pie-lib/render-ui/src/feedback.jsx +0 -100
  128. package/configure/node_modules/@pie-lib/render-ui/src/has-text.js +0 -14
  129. package/configure/node_modules/@pie-lib/render-ui/src/html-and-math.js +0 -40
  130. package/configure/node_modules/@pie-lib/render-ui/src/index.js +0 -27
  131. package/configure/node_modules/@pie-lib/render-ui/src/input-container.jsx +0 -41
  132. package/configure/node_modules/@pie-lib/render-ui/src/preview-layout.jsx +0 -77
  133. package/configure/node_modules/@pie-lib/render-ui/src/preview-prompt.jsx +0 -90
  134. package/configure/node_modules/@pie-lib/render-ui/src/purpose.jsx +0 -19
  135. package/configure/node_modules/@pie-lib/render-ui/src/readable.jsx +0 -19
  136. package/configure/node_modules/@pie-lib/render-ui/src/response-indicators.jsx +0 -89
  137. package/configure/node_modules/@pie-lib/render-ui/src/withUndoReset.jsx +0 -118
@@ -1,18 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports["default"] = void 0;
7
- var _default = {
8
- promptEnabled: true,
9
- rationaleEnabled: true,
10
- accessibilityLabelsEnabled: false,
11
- teacherInstructionsEnabled: true,
12
- studentInstructionsEnabled: true,
13
- choicePrefix: 'letters',
14
- choicesLayout: 'vertical',
15
- gridColumns: '2'
16
- };
17
- exports["default"] = _default;
18
- //# sourceMappingURL=defaults.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/defaults.js"],"names":["promptEnabled","rationaleEnabled","accessibilityLabelsEnabled","teacherInstructionsEnabled","studentInstructionsEnabled","choicePrefix","choicesLayout","gridColumns"],"mappings":";;;;;;eAAe;AACbA,EAAAA,aAAa,EAAE,IADF;AAEbC,EAAAA,gBAAgB,EAAE,IAFL;AAGbC,EAAAA,0BAA0B,EAAE,KAHf;AAIbC,EAAAA,0BAA0B,EAAE,IAJf;AAKbC,EAAAA,0BAA0B,EAAE,IALf;AAMbC,EAAAA,YAAY,EAAE,SAND;AAObC,EAAAA,aAAa,EAAE,UAPF;AAQbC,EAAAA,WAAW,EAAE;AARA,C","sourcesContent":["export default {\n promptEnabled: true,\n rationaleEnabled: true,\n accessibilityLabelsEnabled: false,\n teacherInstructionsEnabled: true,\n studentInstructionsEnabled: true,\n choicePrefix: 'letters',\n choicesLayout: 'vertical',\n gridColumns: '2'\n};\n"],"file":"defaults.js"}
@@ -1,305 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.createCorrectResponseSession = void 0;
9
- exports.createDefaultModel = createDefaultModel;
10
- exports.getScore = void 0;
11
- exports.model = model;
12
- exports.normalize = void 0;
13
- exports.outcome = outcome;
14
- exports.validate = void 0;
15
-
16
- var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
17
-
18
- var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
19
-
20
- var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
21
-
22
- var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
23
-
24
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
25
-
26
- var _isEmpty = _interopRequireDefault(require("lodash/isEmpty"));
27
-
28
- var _utils = require("./utils");
29
-
30
- var _defaults = _interopRequireDefault(require("./defaults"));
31
-
32
- var _controllerUtils = require("@pie-lib/controller-utils");
33
-
34
- var _excluded = ["verticalMode", "choicesLayout"];
35
-
36
- 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; }
37
-
38
- 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; }
39
-
40
- var prepareChoice = function prepareChoice(model, env, defaultFeedback) {
41
- return function (choice) {
42
- var _ref = env || {},
43
- role = _ref.role,
44
- mode = _ref.mode;
45
-
46
- var out = {
47
- label: choice.label,
48
- value: choice.value
49
- };
50
-
51
- if (model.accessibilityLabelsEnabled) {
52
- out.accessibility = (0, _utils.parseHTML)(choice.accessibility).textContent || choice.value;
53
- }
54
-
55
- if (role === 'instructor' && (mode === 'view' || mode === 'evaluate')) {
56
- out.rationale = model.rationaleEnabled ? choice.rationale : null;
57
- } else {
58
- out.rationale = null;
59
- }
60
-
61
- if (mode === 'evaluate') {
62
- out.correct = !!choice.correct;
63
-
64
- if (model.feedbackEnabled) {
65
- var feedbackType = choice.feedback && choice.feedback.type || 'none';
66
-
67
- if (feedbackType === 'default') {
68
- out.feedback = defaultFeedback[choice.correct ? 'correct' : 'incorrect'];
69
- } else if (feedbackType === 'custom') {
70
- out.feedback = choice.feedback.value;
71
- }
72
- }
73
- }
74
-
75
- return out;
76
- };
77
- };
78
-
79
- function createDefaultModel() {
80
- var model = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
81
- return new Promise(function (resolve) {
82
- return resolve(_objectSpread(_objectSpread({}, _defaults["default"]), model));
83
- });
84
- }
85
-
86
- var normalize = function normalize(question) {
87
- var _ref2 = question || {},
88
- verticalMode = _ref2.verticalMode,
89
- choicesLayout = _ref2.choicesLayout,
90
- questionProps = (0, _objectWithoutProperties2["default"])(_ref2, _excluded);
91
-
92
- return _objectSpread(_objectSpread(_objectSpread({}, _defaults["default"]), questionProps), {}, {
93
- // This is used for offering support for old models which have the property verticalMode
94
- // Same thing is set in authoring : packages/multiple-choice/configure/src/index.jsx - createDefaultModel
95
- choicesLayout: choicesLayout || verticalMode === false && 'horizontal' || _defaults["default"].choicesLayout
96
- });
97
- };
98
- /**
99
- *
100
- * @param {*} question
101
- * @param {*} session
102
- * @param {*} env
103
- * @param {*} updateSession - optional - a function that will set the properties passed into it on the session.
104
- */
105
-
106
-
107
- exports.normalize = normalize;
108
-
109
- function model(_x, _x2, _x3, _x4) {
110
- return _model.apply(this, arguments);
111
- }
112
-
113
- function _model() {
114
- _model = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(question, session, env, updateSession) {
115
- var normalizedQuestion, defaultFeedback, choices, lockChoiceOrder, out, _ref4, role, mode;
116
-
117
- return _regenerator["default"].wrap(function _callee$(_context) {
118
- while (1) {
119
- switch (_context.prev = _context.next) {
120
- case 0:
121
- normalizedQuestion = normalize(question);
122
- defaultFeedback = Object.assign({
123
- correct: 'Correct',
124
- incorrect: 'Incorrect'
125
- }, normalizedQuestion.defaultFeedback);
126
- choices = normalizedQuestion.choices.map(prepareChoice(normalizedQuestion, env, defaultFeedback));
127
- lockChoiceOrder = (0, _controllerUtils.lockChoices)(normalizedQuestion, session, env);
128
-
129
- if (lockChoiceOrder) {
130
- _context.next = 8;
131
- break;
132
- }
133
-
134
- _context.next = 7;
135
- return (0, _controllerUtils.getShuffledChoices)(choices, session, updateSession, 'value');
136
-
137
- case 7:
138
- choices = _context.sent;
139
-
140
- case 8:
141
- out = {
142
- disabled: env.mode !== 'gather',
143
- mode: env.mode,
144
- prompt: normalizedQuestion.promptEnabled ? normalizedQuestion.prompt : null,
145
- choicesLayout: normalizedQuestion.choicesLayout,
146
- gridColumns: normalizedQuestion.gridColumns,
147
- choiceMode: normalizedQuestion.choiceMode,
148
- keyMode: normalizedQuestion.choicePrefix,
149
- choices: choices,
150
- responseCorrect: env.mode === 'evaluate' ? (0, _utils.isResponseCorrect)(normalizedQuestion, session) : undefined
151
- };
152
- _ref4 = env || {}, role = _ref4.role, mode = _ref4.mode;
153
-
154
- if (role === 'instructor' && (mode === 'view' || mode === 'evaluate')) {
155
- out.teacherInstructions = normalizedQuestion.teacherInstructionsEnabled ? normalizedQuestion.teacherInstructions : null;
156
- } else {
157
- out.teacherInstructions = null;
158
- }
159
-
160
- return _context.abrupt("return", out);
161
-
162
- case 12:
163
- case "end":
164
- return _context.stop();
165
- }
166
- }
167
- }, _callee);
168
- }));
169
- return _model.apply(this, arguments);
170
- }
171
-
172
- var getScore = function getScore(config, session) {
173
- if (!session || (0, _isEmpty["default"])(session)) {
174
- return 0;
175
- }
176
-
177
- var selectedChoices = session.value || [];
178
- var correctChoices = (config.choices || []).filter(function (ch) {
179
- return ch.correct;
180
- });
181
- var score = selectedChoices.reduce(function (acc, selectedChoice) {
182
- return acc + (correctChoices.find(function (ch) {
183
- return ch.value === selectedChoice;
184
- }) ? 1 : 0);
185
- }, 0);
186
-
187
- if (correctChoices.length < selectedChoices.length) {
188
- score -= selectedChoices.length - correctChoices.length;
189
-
190
- if (score < 0) {
191
- score = 0;
192
- }
193
- }
194
-
195
- var str = correctChoices.length ? score / correctChoices.length : 0;
196
- return parseFloat(str.toFixed(2));
197
- };
198
- /**
199
- *
200
- * The score is partial by default for checkbox mode, allOrNothing for radio mode.
201
- * To disable partial scoring for checkbox mode you either set model.partialScoring = false or env.partialScoring = false. the value in `env` will
202
- * override the value in `model`.
203
- * @param {Object} model - the main model
204
- * @param {*} session
205
- * @param {Object} env
206
- */
207
-
208
-
209
- exports.getScore = getScore;
210
-
211
- function outcome(model, session, env) {
212
- return new Promise(function (resolve) {
213
- if (!session || (0, _isEmpty["default"])(session)) {
214
- resolve({
215
- score: 0,
216
- empty: true
217
- });
218
- } else {
219
- var partialScoringEnabled = _controllerUtils.partialScoring.enabled(model, env) && model.choiceMode !== 'radio';
220
- var score = getScore(model, session);
221
- resolve({
222
- score: partialScoringEnabled ? score : score === 1 ? 1 : 0,
223
- empty: false
224
- });
225
- }
226
- });
227
- }
228
-
229
- var createCorrectResponseSession = function createCorrectResponseSession(question, env) {
230
- return new Promise(function (resolve) {
231
- if (env.mode !== 'evaluate' && env.role === 'instructor') {
232
- var _ref3 = question || {
233
- choices: []
234
- },
235
- choices = _ref3.choices;
236
-
237
- resolve({
238
- id: '1',
239
- value: choices.filter(function (c) {
240
- return c.correct;
241
- }).map(function (c) {
242
- return c.value;
243
- })
244
- });
245
- } else {
246
- resolve(null);
247
- }
248
- });
249
- };
250
-
251
- exports.createCorrectResponseSession = createCorrectResponseSession;
252
-
253
- var validate = function validate() {
254
- var model = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
255
- var config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
256
- var choices = model.choices;
257
- var _config$minAnswerChoi = config.minAnswerChoices,
258
- minAnswerChoices = _config$minAnswerChoi === void 0 ? 2 : _config$minAnswerChoi,
259
- maxAnswerChoices = config.maxAnswerChoices;
260
- var reversedChoices = (0, _toConsumableArray2["default"])(choices || []).reverse();
261
- var choicesErrors = {};
262
- var hasCorrectResponse = false;
263
- reversedChoices.forEach(function (choice, index) {
264
- var correct = choice.correct,
265
- value = choice.value,
266
- label = choice.label;
267
-
268
- if (correct) {
269
- hasCorrectResponse = true;
270
- }
271
-
272
- if (label === '' || label === '<div></div>') {
273
- choicesErrors[value] = 'Content should not be empty.';
274
- } else {
275
- var identicalAnswer = reversedChoices.slice(index + 1).some(function (c) {
276
- return c.label === label;
277
- });
278
-
279
- if (identicalAnswer) {
280
- choicesErrors[value] = 'Content should be unique.';
281
- }
282
- }
283
- });
284
- var errors = {};
285
- var nbOfChoices = (choices || []).length;
286
-
287
- if (nbOfChoices < minAnswerChoices) {
288
- errors.answerChoicesError = "There should be at least ".concat(minAnswerChoices, " choices defined.");
289
- } else if (nbOfChoices > maxAnswerChoices) {
290
- errors.answerChoicesError = "No more than ".concat(maxAnswerChoices, " choices should be defined.");
291
- }
292
-
293
- if (!hasCorrectResponse) {
294
- errors.correctResponseError = 'No correct response defined.';
295
- }
296
-
297
- if (!(0, _isEmpty["default"])(choicesErrors)) {
298
- errors.choicesErrors = choicesErrors;
299
- }
300
-
301
- return errors;
302
- };
303
-
304
- exports.validate = validate;
305
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/index.js"],"names":["prepareChoice","model","env","defaultFeedback","choice","role","mode","out","label","value","accessibilityLabelsEnabled","accessibility","textContent","rationale","rationaleEnabled","correct","feedbackEnabled","feedbackType","feedback","type","createDefaultModel","Promise","resolve","defaults","normalize","question","verticalMode","choicesLayout","questionProps","session","updateSession","normalizedQuestion","Object","assign","incorrect","choices","map","lockChoiceOrder","disabled","prompt","promptEnabled","gridColumns","choiceMode","keyMode","choicePrefix","responseCorrect","undefined","teacherInstructions","teacherInstructionsEnabled","getScore","config","selectedChoices","correctChoices","filter","ch","score","reduce","acc","selectedChoice","find","length","str","parseFloat","toFixed","outcome","empty","partialScoringEnabled","partialScoring","enabled","createCorrectResponseSession","id","c","validate","minAnswerChoices","maxAnswerChoices","reversedChoices","reverse","choicesErrors","hasCorrectResponse","forEach","index","identicalAnswer","slice","some","errors","nbOfChoices","answerChoicesError","correctResponseError"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AACA;;AACA;;AACA;;AACA;;;;;;;;AAEA,IAAMA,aAAa,GAAG,SAAhBA,aAAgB,CAACC,KAAD,EAAQC,GAAR,EAAaC,eAAb;AAAA,SAAiC,UAAAC,MAAM,EAAI;AAC/D,eAAuBF,GAAG,IAAI,EAA9B;AAAA,QAAQG,IAAR,QAAQA,IAAR;AAAA,QAAcC,IAAd,QAAcA,IAAd;;AACA,QAAMC,GAAG,GAAG;AACVC,MAAAA,KAAK,EAAEJ,MAAM,CAACI,KADJ;AAEVC,MAAAA,KAAK,EAAEL,MAAM,CAACK;AAFJ,KAAZ;;AAKA,QAAIR,KAAK,CAACS,0BAAV,EAAsC;AACpCH,MAAAA,GAAG,CAACI,aAAJ,GAAoB,sBAAUP,MAAM,CAACO,aAAjB,E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AAP,GAAuBA,aAAvB;AACD;;AAED,SAAOO,MAAP;AACD,CA3CM","sourcesContent":["/* eslint-disable no-console */\nimport isEmpty from 'lodash/isEmpty';\nimport { isResponseCorrect, parseHTML } from './utils';\nimport defaults from './defaults';\nimport { lockChoices, partialScoring, getShuffledChoices } from '@pie-lib/controller-utils';\n\nconst prepareChoice = (model, env, defaultFeedback) => choice => {\n const { role, mode } = env || {};\n const out = {\n label: choice.label,\n value: choice.value,\n };\n\n if (model.accessibilityLabelsEnabled) {\n out.accessibility = parseHTML(choice.accessibility).textContent || choice.value;\n }\n\n if (role === 'instructor' && (mode === 'view' || mode === 'evaluate')) {\n out.rationale = model.rationaleEnabled ? choice.rationale : null;\n } else {\n out.rationale = null;\n }\n\n if (mode === 'evaluate') {\n out.correct = !!choice.correct;\n\n if (model.feedbackEnabled) {\n const feedbackType = (choice.feedback && choice.feedback.type) || 'none';\n\n if (feedbackType === 'default') {\n out.feedback = defaultFeedback[choice.correct ? 'correct' : 'incorrect'];\n } else if (feedbackType === 'custom') {\n out.feedback = choice.feedback.value;\n }\n }\n }\n\n return out;\n};\n\nexport function createDefaultModel(model = {}) {\n return new Promise(resolve => resolve({ ...defaults, ...model }));\n}\n\nexport const normalize = question => {\n const { verticalMode, choicesLayout, ...questionProps } = question || {};\n\n return {\n ...defaults,\n ...questionProps,\n // This is used for offering support for old models which have the property verticalMode\n // Same thing is set in authoring : packages/multiple-choice/configure/src/index.jsx - createDefaultModel\n choicesLayout: choicesLayout || (verticalMode === false && 'horizontal') || defaults.choicesLayout\n };\n};\n\n/**\n *\n * @param {*} question\n * @param {*} session\n * @param {*} env\n * @param {*} updateSession - optional - a function that will set the properties passed into it on the session.\n */\nexport async function model(question, session, env, updateSession) {\n const normalizedQuestion = normalize(question);\n\n const defaultFeedback = Object.assign(\n { correct: 'Correct', incorrect: 'Incorrect' },\n normalizedQuestion.defaultFeedback\n );\n\n let choices = normalizedQuestion.choices.map(\n prepareChoice(normalizedQuestion, env, defaultFeedback)\n );\n\n const lockChoiceOrder = lockChoices(normalizedQuestion, session, env);\n\n if (!lockChoiceOrder) {\n choices = await getShuffledChoices(\n choices,\n session,\n updateSession,\n 'value'\n );\n }\n\n const out = {\n disabled: env.mode !== 'gather',\n mode: env.mode,\n prompt: normalizedQuestion.promptEnabled ? normalizedQuestion.prompt : null,\n choicesLayout: normalizedQuestion.choicesLayout,\n gridColumns: normalizedQuestion.gridColumns,\n choiceMode: normalizedQuestion.choiceMode,\n keyMode: normalizedQuestion.choicePrefix,\n choices,\n responseCorrect:\n env.mode === 'evaluate' ? isResponseCorrect(normalizedQuestion, session) : undefined\n };\n\n const { role, mode } = env || {};\n\n if (role === 'instructor' && (mode === 'view' || mode === 'evaluate')) {\n out.teacherInstructions = normalizedQuestion.teacherInstructionsEnabled\n ? normalizedQuestion.teacherInstructions\n : null;\n } else {\n out.teacherInstructions = null;\n }\n\n return out;\n}\n\n\nexport const getScore = (config, session) => {\n if (!session || isEmpty(session)) {\n return 0;\n }\n\n const selectedChoices = session.value || [];\n const correctChoices = (config.choices || []).filter(ch => ch.correct);\n\n let score = selectedChoices.reduce((acc, selectedChoice) =>\n acc + (correctChoices.find(ch => ch.value === selectedChoice) ? 1 : 0), 0);\n\n if (correctChoices.length < selectedChoices.length) {\n score -= selectedChoices.length - correctChoices.length;\n\n if (score < 0) {\n score = 0;\n }\n }\n\n const str = correctChoices.length ? score / correctChoices.length : 0;\n\n return parseFloat(str.toFixed(2));\n};\n\n/**\n *\n * The score is partial by default for checkbox mode, allOrNothing for radio mode.\n * To disable partial scoring for checkbox mode you either set model.partialScoring = false or env.partialScoring = false. the value in `env` will\n * override the value in `model`.\n * @param {Object} model - the main model\n * @param {*} session\n * @param {Object} env\n */\nexport function outcome(model, session, env) {\n return new Promise(resolve => {\n if (!session || isEmpty(session)) {\n resolve({ score: 0, empty: true });\n } else {\n const partialScoringEnabled =\n partialScoring.enabled(model, env) && model.choiceMode !== 'radio';\n const score = getScore(model, session);\n\n resolve({ score: partialScoringEnabled ? score : score === 1 ? 1 : 0, empty: false });\n }\n });\n}\n\nexport const createCorrectResponseSession = (question, env) => {\n return new Promise(resolve => {\n if (env.mode !== 'evaluate' && env.role === 'instructor') {\n const { choices } = question || { choices: [] };\n\n resolve({\n id: '1',\n value: choices.filter(c => c.correct).map(c => c.value)\n });\n } else {\n resolve(null);\n }\n });\n};\n\nexport const validate = (model = {}, config = {}) => {\n const { choices } = model;\n const { minAnswerChoices = 2, maxAnswerChoices } = config;\n const reversedChoices = [...choices || []].reverse();\n const choicesErrors = {};\n let hasCorrectResponse = false;\n\n reversedChoices.forEach((choice, index) => {\n const { correct, value, label } = choice;\n\n if (correct) {\n hasCorrectResponse = true;\n }\n\n if (label === '' || label === '<div></div>') {\n choicesErrors[value] = '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[value] = 'Content should be unique.';\n }\n }\n });\n\n const errors = {};\n const nbOfChoices = (choices || []).length;\n\n if (nbOfChoices < minAnswerChoices) {\n errors.answerChoicesError = `There should be at least ${minAnswerChoices} choices defined.`;\n } else if (nbOfChoices > maxAnswerChoices) {\n errors.answerChoicesError = `No more than ${maxAnswerChoices} choices should be defined.`;\n }\n\n if (!hasCorrectResponse) {\n errors.correctResponseError = 'No correct response defined.';\n }\n\n if (!isEmpty(choicesErrors)) {\n errors.choicesErrors = choicesErrors;\n }\n\n return errors;\n};\n"],"file":"index.js"}
@@ -1,36 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.parseHTML = exports.isResponseCorrect = exports.getCorrectResponse = void 0;
9
-
10
- var _isEqual = _interopRequireDefault(require("lodash/isEqual"));
11
-
12
- var getCorrectResponse = function getCorrectResponse(choices) {
13
- return choices.filter(function (c) {
14
- return c.correct;
15
- }).map(function (c) {
16
- return c.value;
17
- }).sort();
18
- };
19
-
20
- exports.getCorrectResponse = getCorrectResponse;
21
-
22
- var isResponseCorrect = function isResponseCorrect(question, session) {
23
- var correctResponse = getCorrectResponse(question.choices);
24
- return session && (0, _isEqual["default"])((session.value || []).sort(), correctResponse);
25
- };
26
-
27
- exports.isResponseCorrect = isResponseCorrect;
28
-
29
- var parseHTML = function parseHTML(html) {
30
- var template = document.createElement('template');
31
- template.innerHTML = html;
32
- return template.content;
33
- };
34
-
35
- exports.parseHTML = parseHTML;
36
- //# sourceMappingURL=utils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/utils.js"],"names":["getCorrectResponse","choices","filter","c","correct","map","value","sort","isResponseCorrect","question","session","correctResponse","parseHTML","html","template","document","createElement","innerHTML","content"],"mappings":";;;;;;;;;AAAA;;AAEO,IAAMA,kBAAkB,GAAG,SAArBA,kBAAqB,CAACC,OAAD;AAAA,SAAaA,OAAO,CACnDC,MAD4C,CACrC,UAAAC,CAAC;AAAA,WAAIA,CAAC,CAACC,OAAN;AAAA,GADoC,EAE5CC,GAF4C,CAExC,UAAAF,CAAC;AAAA,WAAIA,CAAC,CAACG,KAAN;AAAA,GAFuC,EAG5CC,IAH4C,EAAb;AAAA,CAA3B;;;;AAKA,IAAMC,iBAAiB,GAAG,SAApBA,iBAAoB,CAACC,QAAD,EAAWC,OAAX,EAAuB;AACtD,MAAIC,eAAe,GAAGX,kBAAkB,CAACS,QAAQ,CAACR,OAAV,CAAxC;AACA,SAAOS,OAAO,IAAI,yBAAQ,CAACA,OAAO,CAACJ,KAAR,IAAiB,EAAlB,EAAsBC,IAAtB,EAAR,EAAsCI,eAAtC,CAAlB;AACD,CAHM;;;;AAKA,IAAMC,SAAS,GAAG,SAAZA,SAAY,CAACC,IAAD,EAAU;AACjC,MAAMC,QAAQ,GAAGC,QAAQ,CAACC,aAAT,CAAuB,UAAvB,CAAjB;AACAF,EAAAA,QAAQ,CAACG,SAAT,GAAqBJ,IAArB;AACA,SAAOC,QAAQ,CAACI,OAAhB;AACD,CAJM","sourcesContent":["import isEqual from 'lodash/isEqual';\n\nexport const getCorrectResponse = (choices) => choices\n .filter(c => c.correct)\n .map(c => c.value)\n .sort();\n\nexport const isResponseCorrect = (question, session) => {\n let correctResponse = getCorrectResponse(question.choices);\n return session && isEqual((session.value || []).sort(), correctResponse);\n};\n\nexport const parseHTML = (html) => {\n const template = document.createElement('template');\n template.innerHTML = html;\n return template.content;\n};\n"],"file":"utils.js"}
@@ -1,15 +0,0 @@
1
- {
2
- "name": "@pie-element/multiple-choice-controller",
3
- "private": true,
4
- "version": "3.6.0",
5
- "description": "",
6
- "main": "lib/index.js",
7
- "module": "src/index.js",
8
- "author": "",
9
- "license": "ISC",
10
- "dependencies": {
11
- "@pie-lib/controller-utils": "^0.2.26",
12
- "debug": "^3.1.0",
13
- "lodash": "^4.17.15"
14
- }
15
- }