@pie-element/select-text 6.5.3-next.135 → 6.5.3-next.1357

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.
@@ -3,6 +3,162 @@
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
+ ## [4.2.2](https://github.com/pie-framework/pie-elements/compare/@pie-element/select-text-controller@4.2.1...@pie-element/select-text-controller@4.2.2) (2022-06-13)
7
+
8
+ **Note:** Version bump only for package @pie-element/select-text-controller
9
+
10
+
11
+
12
+
13
+
14
+ ## [4.2.1](https://github.com/pie-framework/pie-elements/compare/@pie-element/select-text-controller@4.2.0...@pie-element/select-text-controller@4.2.1) (2022-05-30)
15
+
16
+ **Note:** Version bump only for package @pie-element/select-text-controller
17
+
18
+
19
+
20
+
21
+
22
+ # [4.2.0](https://github.com/pie-framework/pie-elements/compare/@pie-element/select-text-controller@4.1.31...@pie-element/select-text-controller@4.2.0) (2022-05-03)
23
+
24
+
25
+ ### Bug Fixes
26
+
27
+ * in controller we don't have access to the model (text & tokens) parser functions, so I have added 2 props (oldStart and oldEnd) to compare the start & and of the selected tokens (which are parsed) with the correct tokens (which are not parsed). Also, for the createCorrectSession to work, we need to make sure that when session is set, we have the correct start & end for the tokens (that come unparsed from controller). ([d6670b5](https://github.com/pie-framework/pie-elements/commit/d6670b53185acedd3be2dfc37b8f3616c9ce27f3))
28
+
29
+
30
+ ### Features
31
+
32
+ * **select-text:** added configurable validation ([fcea834](https://github.com/pie-framework/pie-elements/commit/fcea834fc7d9d19dbd3bc65d10ef3ecbf2618097))
33
+ * **select-text:** added configurable validation PD-1700 ([467f4a6](https://github.com/pie-framework/pie-elements/commit/467f4a640e560e26c932ce067b1b09ffe444b290))
34
+ * **select-text:** ui/ux validation PD-1701 ([3ae2723](https://github.com/pie-framework/pie-elements/commit/3ae27238a70124dcf2b544f0f1c8ae93ddeb0f6e))
35
+
36
+
37
+
38
+
39
+
40
+ ## [4.1.31](https://github.com/pie-framework/pie-elements/compare/@pie-element/select-text-controller@4.1.30...@pie-element/select-text-controller@4.1.31) (2022-03-22)
41
+
42
+ **Note:** Version bump only for package @pie-element/select-text-controller
43
+
44
+
45
+
46
+
47
+
48
+ ## [4.1.30](https://github.com/pie-framework/pie-elements/compare/@pie-element/select-text-controller@4.1.29...@pie-element/select-text-controller@4.1.30) (2022-02-21)
49
+
50
+ **Note:** Version bump only for package @pie-element/select-text-controller
51
+
52
+
53
+
54
+
55
+
56
+ ## [4.1.29](https://github.com/pie-framework/pie-elements/compare/@pie-element/select-text-controller@4.1.28...@pie-element/select-text-controller@4.1.29) (2022-02-17)
57
+
58
+ **Note:** Version bump only for package @pie-element/select-text-controller
59
+
60
+
61
+
62
+
63
+
64
+ ## [4.1.28](https://github.com/pie-framework/pie-elements/compare/@pie-element/select-text-controller@4.1.27...@pie-element/select-text-controller@4.1.28) (2022-02-04)
65
+
66
+ **Note:** Version bump only for package @pie-element/select-text-controller
67
+
68
+
69
+
70
+
71
+
72
+ ## [4.1.26](https://github.com/pie-framework/pie-elements/compare/@pie-element/select-text-controller@4.1.25...@pie-element/select-text-controller@4.1.26) (2021-12-13)
73
+
74
+ **Note:** Version bump only for package @pie-element/select-text-controller
75
+
76
+
77
+
78
+
79
+
80
+ ## [4.1.23](https://github.com/pie-framework/pie-elements/compare/@pie-element/select-text-controller@4.1.22...@pie-element/select-text-controller@4.1.23) (2021-11-29)
81
+
82
+ **Note:** Version bump only for package @pie-element/select-text-controller
83
+
84
+
85
+
86
+
87
+
88
+ ## [4.1.22](https://github.com/pie-framework/pie-elements/compare/@pie-element/select-text-controller@4.1.21...@pie-element/select-text-controller@4.1.22) (2021-10-04)
89
+
90
+ **Note:** Version bump only for package @pie-element/select-text-controller
91
+
92
+
93
+
94
+
95
+
96
+ ## [4.1.21](https://github.com/pie-framework/pie-elements/compare/@pie-element/select-text-controller@4.1.20...@pie-element/select-text-controller@4.1.21) (2021-10-01)
97
+
98
+
99
+ ### Bug Fixes
100
+
101
+ * Remove breaking import. ([a89168d](https://github.com/pie-framework/pie-elements/commit/a89168ddc8d6986eadf74589994f4b4012040721))
102
+
103
+
104
+
105
+
106
+
107
+ ## [4.1.20](https://github.com/pie-framework/pie-elements/compare/@pie-element/select-text-controller@4.1.19...@pie-element/select-text-controller@4.1.20) (2021-09-20)
108
+
109
+
110
+ ### Bug Fixes
111
+
112
+ * move dom logic from controller to player ([2425be1](https://github.com/pie-framework/pie-elements/commit/2425be1e506b153d946b7643f4b024d2e0edfbbb))
113
+ * Updated pie-lib versions ([1c23830](https://github.com/pie-framework/pie-elements/commit/1c23830fc75d1de5f7bb3bb16de3c665ae5fa350))
114
+ * **select-text:** move prepareText function to pie-lib ([26eb7bd](https://github.com/pie-framework/pie-elements/commit/26eb7bd7e9d2804286886a0f92f9993d67f6cf77))
115
+
116
+
117
+
118
+
119
+
120
+ ## [4.1.19](https://github.com/pie-framework/pie-elements/compare/@pie-element/select-text-controller@4.1.18...@pie-element/select-text-controller@4.1.19) (2021-09-01)
121
+
122
+ **Note:** Version bump only for package @pie-element/select-text-controller
123
+
124
+
125
+
126
+
127
+
128
+ ## [4.1.18](https://github.com/pie-framework/pie-elements/compare/@pie-element/select-text-controller@4.1.17...@pie-element/select-text-controller@4.1.18) (2021-08-09)
129
+
130
+
131
+ ### Bug Fixes
132
+
133
+ * tokens in player ([e9a8ad7](https://github.com/pie-framework/pie-elements/commit/e9a8ad7205212640e349982cd84fe4d606efbc79))
134
+ * tokens in player ([fc96766](https://github.com/pie-framework/pie-elements/commit/fc96766884b14fed7ad6e476431edde27dffcd52))
135
+
136
+
137
+
138
+
139
+
140
+ ## [4.1.17](https://github.com/pie-framework/pie-elements/compare/@pie-element/select-text-controller@4.1.15...@pie-element/select-text-controller@4.1.17) (2021-08-05)
141
+
142
+
143
+ ### Bug Fixes
144
+
145
+ * force bump ([5ea7295](https://github.com/pie-framework/pie-elements/commit/5ea7295e4755fbc492a76e7ec69e5fc35b196919))
146
+
147
+
148
+
149
+
150
+
151
+ ## [4.1.15](https://github.com/pie-framework/pie-elements/compare/@pie-element/select-text-controller@4.1.14...@pie-element/select-text-controller@4.1.15) (2021-06-29)
152
+
153
+
154
+ ### Bug Fixes
155
+
156
+ * **select-text:** partial scoring not working correctly PD-407 ([#584](https://github.com/pie-framework/pie-elements/issues/584)) ([d78e194](https://github.com/pie-framework/pie-elements/commit/d78e19447aeb7953f7eeefb75ce1b71c3d683dea))
157
+
158
+
159
+
160
+
161
+
6
162
  ## [4.1.14](https://github.com/pie-framework/pie-elements/compare/@pie-element/select-text-controller@4.1.11...@pie-element/select-text-controller@4.1.14) (2021-03-03)
7
163
 
8
164
  **Note:** Version bump only for package @pie-element/select-text-controller
@@ -5,8 +5,9 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
+ exports.createCorrectResponseSession = void 0;
8
9
  exports.createDefaultModel = createDefaultModel;
9
- exports.createCorrectResponseSession = exports.model = exports.normalize = exports.normalizeSession = exports.outcome = exports.getPartialScore = exports.getCorrectness = void 0;
10
+ exports.validate = exports.outcome = exports.normalizeSession = exports.normalize = exports.model = exports.getPartialScore = exports.getCorrectness = void 0;
10
11
 
11
12
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
12
13
 
@@ -20,9 +21,9 @@ var _controllerUtils = require("@pie-lib/controller-utils");
20
21
 
21
22
  var _defaults = _interopRequireDefault(require("./defaults"));
22
23
 
23
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
24
+ 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; }
24
25
 
25
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
26
+ 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; }
26
27
 
27
28
  var log = (0, _debug["default"])('@pie-element:select-text:controller');
28
29
 
@@ -68,7 +69,8 @@ exports.getCorrectness = getCorrectness;
68
69
  var getCorrectSelected = function getCorrectSelected(tokens, selected) {
69
70
  return (selected || []).filter(function (s) {
70
71
  var index = tokens.findIndex(function (c) {
71
- return c.correct && c.start === s.start && c.end === s.end;
72
+ return c.correct && (c.start === s.start && c.end === s.end || // this case is used for the cases when the token's start & end were recalculated
73
+ c.start === s.oldStart && c.end === s.oldEnd);
72
74
  });
73
75
  return index !== -1;
74
76
  });
@@ -214,4 +216,35 @@ var createCorrectResponseSession = function createCorrectResponseSession(questio
214
216
  };
215
217
 
216
218
  exports.createCorrectResponseSession = createCorrectResponseSession;
219
+
220
+ var validate = function validate() {
221
+ var model = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
222
+ var config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
223
+ var tokens = model.tokens;
224
+ var _config$minTokens = config.minTokens,
225
+ minTokens = _config$minTokens === void 0 ? 2 : _config$minTokens,
226
+ maxTokens = config.maxTokens,
227
+ maxSelections = config.maxSelections;
228
+ var errors = {};
229
+ var nbOfTokens = (tokens || []).length;
230
+ var nbOfSelections = (tokens || []).reduce(function (acc, token) {
231
+ return token.correct ? acc + 1 : acc;
232
+ }, 0);
233
+
234
+ if (nbOfTokens < minTokens) {
235
+ errors.tokensError = "There should be at least ".concat(minTokens, " tokens defined.");
236
+ } else if (nbOfTokens > maxTokens) {
237
+ errors.tokensError = "No more than ".concat(maxTokens, " tokens should be defined.");
238
+ }
239
+
240
+ if (nbOfSelections < 1) {
241
+ errors.selectionsError = 'There should be at least 1 token selected.';
242
+ } else if (nbOfSelections > maxSelections) {
243
+ errors.selectionsError = "No more than ".concat(maxSelections, " tokens should be selected.");
244
+ }
245
+
246
+ return errors;
247
+ };
248
+
249
+ exports.validate = validate;
217
250
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.js"],"names":["log","buildTokens","tokens","evaluateMode","map","t","Object","assign","correct","undefined","getCorrectness","selected","filter","length","correctSelected","getCorrectSelected","s","index","findIndex","c","start","end","getCorrectCount","getPartialScore","question","session","totalCorrect","correctCount","selectedTokens","correctTokens","extraSelected","incorrectCount","count","positiveCount","parseFloat","toFixed","outcome","env","Promise","resolve","score","empty","normalizeSession","mode","completed","enabled","partialScoring","createDefaultModel","model","defaults","normalize","feedbackEnabled","rationaleEnabled","promptEnabled","teacherInstructionsEnabled","studentInstructionsEnabled","selectedToken","normalizedQuestion","correctness","fb","feedback","then","out","highlightChoices","prompt","text","disabled","maxSelections","incorrect","role","rationale","teacherInstructions","createCorrectResponseSession","id"],"mappings":";;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;;;;;AAEA,IAAMA,GAAG,GAAG,uBAAM,qCAAN,CAAZ;;AAEA,IAAMC,WAAW,GAAG,SA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EtB,IAFJ;AAGD,OAVD,MAUO;AACLT,QAAAA,GAAG,CAACQ,SAAJ,GAAgB,IAAhB;AACAR,QAAAA,GAAG,CAACS,mBAAJ,GAA0B,IAA1B;AACD;;AAEDhC,MAAAA,OAAO,CAACuB,GAAD,CAAP;AACD,KAhCD;AAiCD,GAnDM,CAAP;AAoDD,CAxDM;;;;AA0DA,IAAMU,4BAA4B,GAAG,SAA/BA,4BAA+B,CAAChD,QAAD,EAAWa,GAAX,EAAmB;AAC7D,SAAO,IAAIC,OAAJ,CAAY,UAACC,OAAD,EAAa;AAC9B,QAAIF,GAAG,CAACM,IAAJ,KAAa,UAAb,IAA2BN,GAAG,CAACgC,IAAJ,KAAa,YAA5C,EAA0D;AAAA,UAChDnE,MADgD,GACrCsB,QADqC,CAChDtB,MADgD;AAExD,UAAM0B,cAAc,GAAG1B,MAAM,CAACU,MAAP,CAAc,UAACP,CAAD;AAAA,eAAOA,CAAC,CAACG,OAAT;AAAA,OAAd,CAAvB;AAEA+B,MAAAA,OAAO,CAAC;AACNkC,QAAAA,EAAE,EAAE,GADE;AAEN7C,QAAAA,cAAc,EAAdA;AAFM,OAAD,CAAP;AAID,KARD,MAQO;AACLW,MAAAA,OAAO,CAAC,IAAD,CAAP;AACD;AACF,GAZM,CAAP;AAaD,CAdM","sourcesContent":["import debug from 'debug';\nimport isEmpty from 'lodash/isEmpty';\nimport { getFeedbackForCorrectness } from '@pie-lib/feedback';\nimport { partialScoring } from '@pie-lib/controller-utils';\nimport defaults from './defaults';\n\nconst log = debug('@pie-element:select-text:controller');\n\nconst buildTokens = (tokens, evaluateMode) => {\n tokens = tokens || [];\n\n return tokens.map((t) =>\n Object.assign(\n {},\n t,\n evaluateMode ? { correct: !!t.correct } : { correct: undefined }\n )\n );\n};\n\nexport const getCorrectness = (tokens, selected) => {\n const correct = tokens.filter((t) => t.correct === true);\n\n if (correct.length === 0) {\n return 'unknown';\n }\n\n const correctSelected = getCorrectSelected(tokens, selected);\n\n if (correctSelected.length === selected.length) {\n if (correctSelected.length === correct.length) {\n return 'correct';\n } else if (correctSelected.length > 0) {\n return 'partially-correct';\n }\n }\n\n if (correctSelected.length > 0) {\n return 'partially-correct';\n }\n\n return 'incorrect';\n};\n\nconst getCorrectSelected = (tokens, selected) => {\n return (selected || []).filter((s) => {\n const index = tokens.findIndex((c) => {\n return c.correct && c.start === s.start && c.end === s.end;\n });\n return index !== -1;\n });\n};\n\nconst getCorrectCount = (tokens, selected) =>\n getCorrectSelected(tokens, selected).length;\n\nexport const getPartialScore = (question, session, totalCorrect) => {\n if (!session || isEmpty(session)) {\n return 0;\n }\n\n const correctCount = getCorrectCount(question.tokens, session.selectedTokens);\n const correctTokens = (question.tokens || []).filter((t) => t.correct === true);\n const extraSelected = session.selectedTokens ? session.selectedTokens.length > correctTokens.length : 0;\n const incorrectCount = extraSelected ? session.selectedTokens && session.selectedTokens.length - correctCount : 0;\n const count = correctCount - incorrectCount;\n const positiveCount = count < 0 ? 0 : count;\n\n return totalCorrect.length\n ? parseFloat((positiveCount / totalCorrect.length).toFixed(2))\n : 0;\n};\n\nexport const outcome = (question, session, env) =>\n new Promise((resolve) => {\n if (!session || isEmpty(session)) {\n resolve({ score: 0, empty: true });\n }\n\n session = normalizeSession(session);\n\n if (env.mode !== 'evaluate') {\n resolve({ score: undefined, completed: undefined });\n } else {\n const enabled = partialScoring.enabled(question, env, true);\n const totalCorrect = question.tokens.filter((t) => t.correct);\n const score = getPartialScore(question, session, totalCorrect);\n resolve({\n score: enabled ? score : score === 1 ? 1 : 0,\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 normalizeSession = (s) => ({\n selectedTokens: [],\n ...s,\n});\n\nexport const normalize = (question) => ({\n feedbackEnabled: true,\n rationaleEnabled: true,\n promptEnabled: true,\n teacherInstructionsEnabled: true,\n studentInstructionsEnabled: true,\n ...question,\n});\n\nexport const model = (question, session, env) => {\n session = session || { selectedToken: [] };\n session.selectedTokens = session.selectedTokens || [];\n const normalizedQuestion = normalize(question);\n return new Promise((resolve) => {\n log('[model]', 'normalizedQuestion: ', normalizedQuestion);\n log('[model]', 'session: ', session);\n const tokens = buildTokens(\n normalizedQuestion.tokens,\n env.mode === 'evaluate'\n );\n log('tokens:', tokens);\n const correctness =\n env.mode === 'evaluate'\n ? getCorrectness(normalizedQuestion.tokens, session.selectedTokens)\n : undefined;\n\n const fb =\n env.mode === 'evaluate' && normalizedQuestion.feedbackEnabled\n ? getFeedbackForCorrectness(correctness, normalizedQuestion.feedback)\n : Promise.resolve(undefined);\n\n fb.then((feedback) => {\n const out = {\n tokens,\n highlightChoices: normalizedQuestion.highlightChoices,\n prompt: normalizedQuestion.promptEnabled\n ? normalizedQuestion.prompt\n : null,\n text: normalizedQuestion.text,\n disabled: env.mode !== 'gather',\n maxSelections: normalizedQuestion.maxSelections,\n correctness,\n feedback,\n incorrect:\n env.mode === 'evaluate' ? correctness !== 'correct' : undefined,\n };\n\n if (\n env.role === 'instructor' &&\n (env.mode === 'view' || env.mode === 'evaluate')\n ) {\n out.rationale = normalizedQuestion.rationaleEnabled\n ? normalizedQuestion.rationale\n : null;\n out.teacherInstructions = normalizedQuestion.teacherInstructionsEnabled\n ? normalizedQuestion.teacherInstructions\n : null;\n } else {\n out.rationale = null;\n out.teacherInstructions = null;\n }\n\n resolve(out);\n });\n });\n};\n\nexport const createCorrectResponseSession = (question, env) => {\n return new Promise((resolve) => {\n if (env.mode !== 'evaluate' && env.role === 'instructor') {\n const { tokens } = question;\n const selectedTokens = tokens.filter((t) => t.correct);\n\n resolve({\n id: '1',\n selectedTokens,\n });\n } else {\n resolve(null);\n }\n });\n};\n"],"file":"index.js"}
1
+ {"version":3,"sources":["../src/index.js"],"names":["log","buildTokens","tokens","evaluateMode","map","t","Object","assign","correct","undefined","getCorrectness","selected","filter","length","correctSelected","getCorrectSelected","s","index","findIndex","c","start","end","oldStart","oldEnd","getCorrectCount","getPartialScore","question","session","totalCorrect","correctCount","selectedTokens","correctTokens","extraSelected","incorrectCount","count","positiveCount","parseFloat","toFixed","outcome","env","Promise","resolve","score","empty","normalizeSession","mode","completed","enabled","partialScoring","createDefaultModel","model","defaults","normalize","feedbackEnabled","rationaleEnabled","promptEnabled","teacherInstructionsEnabled","studentInstructionsEnabled","selectedToken","normalizedQuestion","correctness","fb","feedback","then","out","highlightChoices","prompt","text","disabled","maxSelections","incorrect","role","rationale","teacherInstructions","createCorrectResponseSession","id","validate","config","minTokens","maxTokens","errors","nbOfTokens","nbOfSelections","reduce","acc","token","tokensError","selectionsError"],"mappings":";;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;;;;;AAEA,IAAMA,GAAG,GAAG,uBAAM,qCAAN,CAAZ;;AAEA,IAAMC,WAAW,GAAG,SAAdA,WAAc,CAACC,MAAD,EAASC,YAAT,EAA0B;AAC5CD,EAAAA,MAAM,GAAGA,MAAM,IAAI,EAAnB;AAEA,SAAOA,MAAM,CAACE,GAAP,CAAW,UAACC,CAAD;AAAA,WAChBC,MAAM,CAACC,MAAP,CACE,EADF,EAEEF,CAFF,EAGEF,YAAY,GAAG;AAAEK,MAAAA,OAAO,EAAE,CAAC,CAACH,CAAC,CAACG;AAAf,KAAH,GAA8B;AAAEA,MAAAA,OAAO,EAAEC;AAAX,KAH5C,CADgB;AAAA,GAAX,CAAP;AAOD,CAVD;;AAYO,IAAMC,cAAc,GAAG,SAAjBA,cAAiB,CAACR,MAAD,EAASS,QAAT,EAAsB;AAClD,MAAMH,OAAO,GAAGN,MAAM,CAACU,MAAP,CAAc,UAACP,CAAD;AAAA,WAAOA,CAAC,CAACG,OAAF,KAAc,IAArB;AAAA,GAAd,CAAhB;;AAEA,MAAIA,OAAO,CAACK,MAAR,KAAmB,CAAvB,EAA0B;AACxB,WAAO,SAAP;AACD;;AAED,MAAMC,eAAe,GAAGC,kBAAkB,CAACb,MAAD,EAASS,QAAT,CAA1C;;AAEA,MAAIG,eA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O,eAAP,0BAAyClB,aAAzC;AACD;;AAED,SAAOW,MAAP;AACD,CArBM","sourcesContent":["import debug from 'debug';\nimport isEmpty from 'lodash/isEmpty';\nimport { getFeedbackForCorrectness } from '@pie-lib/feedback';\nimport { partialScoring } from '@pie-lib/controller-utils';\nimport defaults from './defaults';\n\nconst log = debug('@pie-element:select-text:controller');\n\nconst buildTokens = (tokens, evaluateMode) => {\n tokens = tokens || [];\n\n return tokens.map((t) =>\n Object.assign(\n {},\n t,\n evaluateMode ? { correct: !!t.correct } : { correct: undefined }\n )\n );\n};\n\nexport const getCorrectness = (tokens, selected) => {\n const correct = tokens.filter((t) => t.correct === true);\n\n if (correct.length === 0) {\n return 'unknown';\n }\n\n const correctSelected = getCorrectSelected(tokens, selected);\n\n if (correctSelected.length === selected.length) {\n if (correctSelected.length === correct.length) {\n return 'correct';\n } else if (correctSelected.length > 0) {\n return 'partially-correct';\n }\n }\n\n if (correctSelected.length > 0) {\n return 'partially-correct';\n }\n\n return 'incorrect';\n};\n\nconst getCorrectSelected = (tokens, selected) => {\n return (selected || []).filter((s) => {\n const index = tokens.findIndex((c) => {\n return c.correct &&\n (\n (c.start === s.start && c.end === s.end) ||\n // this case is used for the cases when the token's start & end were recalculated\n (c.start === s.oldStart && c.end === s.oldEnd)\n );\n });\n return index !== -1;\n });\n};\n\nconst getCorrectCount = (tokens, selected) =>\n getCorrectSelected(tokens, selected).length;\n\nexport const getPartialScore = (question, session, totalCorrect) => {\n if (!session || isEmpty(session)) {\n return 0;\n }\n\n const correctCount = getCorrectCount(question.tokens, session.selectedTokens);\n const correctTokens = (question.tokens || []).filter((t) => t.correct === true);\n const extraSelected = session.selectedTokens ? session.selectedTokens.length > correctTokens.length : 0;\n const incorrectCount = extraSelected ? session.selectedTokens && session.selectedTokens.length - correctCount : 0;\n const count = correctCount - incorrectCount;\n const positiveCount = count < 0 ? 0 : count;\n\n return totalCorrect.length\n ? parseFloat((positiveCount / totalCorrect.length).toFixed(2))\n : 0;\n};\n\nexport const outcome = (question, session, env) =>\n new Promise((resolve) => {\n if (!session || isEmpty(session)) {\n resolve({ score: 0, empty: true });\n }\n\n session = normalizeSession(session);\n\n if (env.mode !== 'evaluate') {\n resolve({ score: undefined, completed: undefined });\n } else {\n const enabled = partialScoring.enabled(question, env, true);\n const totalCorrect = question.tokens.filter((t) => t.correct);\n const score = getPartialScore(question, session, totalCorrect);\n resolve({\n score: enabled ? score : score === 1 ? 1 : 0,\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 normalizeSession = (s) => ({\n selectedTokens: [],\n ...s,\n});\n\nexport const normalize = (question) => ({\n feedbackEnabled: true,\n rationaleEnabled: true,\n promptEnabled: true,\n teacherInstructionsEnabled: true,\n studentInstructionsEnabled: true,\n ...question,\n});\n\nexport const model = (question, session, env) => {\n session = session || { selectedToken: [] };\n session.selectedTokens = session.selectedTokens || [];\n const normalizedQuestion = normalize(question);\n\n return new Promise((resolve) => {\n log('[model]', 'normalizedQuestion: ', normalizedQuestion);\n log('[model]', 'session: ', session);\n const tokens = buildTokens(\n normalizedQuestion.tokens,\n env.mode === 'evaluate'\n );\n log('tokens:', tokens);\n const correctness =\n env.mode === 'evaluate'\n ? getCorrectness(normalizedQuestion.tokens, session.selectedTokens)\n : undefined;\n\n const fb =\n env.mode === 'evaluate' && normalizedQuestion.feedbackEnabled\n ? getFeedbackForCorrectness(correctness, normalizedQuestion.feedback)\n : Promise.resolve(undefined);\n\n fb.then((feedback) => {\n const out = {\n tokens,\n highlightChoices: normalizedQuestion.highlightChoices,\n prompt: normalizedQuestion.promptEnabled\n ? normalizedQuestion.prompt\n : null,\n text: normalizedQuestion.text,\n disabled: env.mode !== 'gather',\n maxSelections: normalizedQuestion.maxSelections,\n correctness,\n feedback,\n incorrect:\n env.mode === 'evaluate' ? correctness !== 'correct' : undefined,\n };\n\n if (\n env.role === 'instructor' &&\n (env.mode === 'view' || env.mode === 'evaluate')\n ) {\n out.rationale = normalizedQuestion.rationaleEnabled\n ? normalizedQuestion.rationale\n : null;\n out.teacherInstructions = normalizedQuestion.teacherInstructionsEnabled\n ? normalizedQuestion.teacherInstructions\n : null;\n } else {\n out.rationale = null;\n out.teacherInstructions = null;\n }\n\n resolve(out);\n });\n });\n};\n\nexport const createCorrectResponseSession = (question, env) => {\n return new Promise((resolve) => {\n if (env.mode !== 'evaluate' && env.role === 'instructor') {\n const { tokens } = question;\n const selectedTokens = tokens.filter((t) => t.correct);\n\n resolve({\n id: '1',\n selectedTokens,\n });\n } else {\n resolve(null);\n }\n });\n};\n\nexport const validate = (model = {}, config = {}) => {\n const { tokens } = model;\n const { minTokens = 2, maxTokens, maxSelections } = config;\n const errors = {};\n const nbOfTokens = (tokens || []).length;\n\n const nbOfSelections = (tokens || []).reduce((acc, token) => token.correct ? acc + 1 : acc, 0);\n\n if (nbOfTokens < minTokens) {\n errors.tokensError = `There should be at least ${minTokens} tokens defined.`;\n } else if (nbOfTokens > maxTokens) {\n errors.tokensError = `No more than ${maxTokens} tokens should be defined.`;\n }\n\n if (nbOfSelections < 1) {\n errors.selectionsError = 'There should be at least 1 token selected.';\n } else if (nbOfSelections > maxSelections) {\n errors.selectionsError = `No more than ${maxSelections} tokens should be selected.`;\n }\n\n return errors;\n};\n"],"file":"index.js"}
@@ -1,13 +1,14 @@
1
1
  {
2
2
  "name": "@pie-element/select-text-controller",
3
3
  "private": true,
4
- "version": "4.1.15",
4
+ "version": "4.2.2",
5
5
  "description": "",
6
6
  "main": "lib/index.js",
7
7
  "module": "src/index.js",
8
8
  "dependencies": {
9
9
  "@pie-lib/controller-utils": "^0.2.26",
10
10
  "@pie-lib/feedback": "^0.4.27",
11
+ "@pie-lib/text-select": "^1.8.26",
11
12
  "debug": "^3.1.0",
12
13
  "lodash": "^4.17.15"
13
14
  },
@@ -163,6 +163,22 @@
163
163
  }
164
164
  }
165
165
  },
166
+ "spellCheck": {
167
+ "title": "ConfigureProp",
168
+ "type": "object",
169
+ "properties": {
170
+ "settings": {
171
+ "description": "Indicates if the item has to be displayed in the Settings Panel",
172
+ "type": "boolean",
173
+ "title": "settings"
174
+ },
175
+ "label": {
176
+ "description": "Indicates the label for the item that has to be displayed in the Settings Panel",
177
+ "type": "string",
178
+ "title": "label"
179
+ }
180
+ }
181
+ },
166
182
  "scoringType": {
167
183
  "title": "ConfigureProp",
168
184
  "type": "object",
@@ -211,6 +227,79 @@
211
227
  }
212
228
  }
213
229
  },
230
+ "maxSelections": {
231
+ "description": "Maximum number of selected tokens in correct answer",
232
+ "type": "number",
233
+ "title": "maxSelections"
234
+ },
235
+ "minTokens": {
236
+ "description": "Minimum number of tokens",
237
+ "type": "number",
238
+ "title": "minTokens"
239
+ },
240
+ "maxTokens": {
241
+ "description": "Maximum number of tokens",
242
+ "type": "number",
243
+ "title": "maxTokens"
244
+ },
245
+ "maxImageWidth": {
246
+ "title": "ConfigureMaxImageDimensionsProp",
247
+ "type": "object",
248
+ "properties": {
249
+ "teacherInstructions": {
250
+ "description": "Indicates the max dimension for images in teacher instructions",
251
+ "type": "number",
252
+ "title": "teacherInstructions"
253
+ },
254
+ "prompt": {
255
+ "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",
256
+ "type": "number",
257
+ "title": "prompt"
258
+ },
259
+ "rationale": {
260
+ "description": "Indicates the max dimension for images in rationale",
261
+ "type": "number",
262
+ "title": "rationale"
263
+ }
264
+ }
265
+ },
266
+ "maxImageHeight": {
267
+ "title": "ConfigureMaxImageDimensionsProp",
268
+ "type": "object",
269
+ "properties": {
270
+ "teacherInstructions": {
271
+ "description": "Indicates the max dimension for images in teacher instructions",
272
+ "type": "number",
273
+ "title": "teacherInstructions"
274
+ },
275
+ "prompt": {
276
+ "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",
277
+ "type": "number",
278
+ "title": "prompt"
279
+ },
280
+ "rationale": {
281
+ "description": "Indicates the max dimension for images in rationale",
282
+ "type": "number",
283
+ "title": "rationale"
284
+ }
285
+ }
286
+ },
287
+ "withRubric": {
288
+ "title": "ConfigureProp",
289
+ "type": "object",
290
+ "properties": {
291
+ "settings": {
292
+ "description": "Indicates if the item has to be displayed in the Settings Panel",
293
+ "type": "boolean",
294
+ "title": "settings"
295
+ },
296
+ "label": {
297
+ "description": "Indicates the label for the item that has to be displayed in the Settings Panel",
298
+ "type": "string",
299
+ "title": "label"
300
+ }
301
+ }
302
+ },
214
303
  "showPrompt": {
215
304
  "description": "Determines whether prompt field will be displayed or not",
216
305
  "default": true,
@@ -246,6 +335,27 @@
246
335
  "title": "label"
247
336
  }
248
337
  }
338
+ },
339
+ "ConfigureMaxImageDimensionsProp": {
340
+ "title": "ConfigureMaxImageDimensionsProp",
341
+ "type": "object",
342
+ "properties": {
343
+ "teacherInstructions": {
344
+ "description": "Indicates the max dimension for images in teacher instructions",
345
+ "type": "number",
346
+ "title": "teacherInstructions"
347
+ },
348
+ "prompt": {
349
+ "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",
350
+ "type": "number",
351
+ "title": "prompt"
352
+ },
353
+ "rationale": {
354
+ "description": "Indicates the max dimension for images in rationale",
355
+ "type": "number",
356
+ "title": "rationale"
357
+ }
358
+ }
249
359
  }
250
360
  },
251
361
  "$schema": "http://json-schema.org/draft-07/schema#"
@@ -122,6 +122,18 @@ Indicates if the item has to be displayed in the Settings Panel
122
122
 
123
123
  Indicates the label for the item that has to be displayed in the Settings Panel
124
124
 
125
+ # `spellCheck` (object)
126
+
127
+ Properties of the `spellCheck` object:
128
+
129
+ ## `settings` (boolean)
130
+
131
+ Indicates if the item has to be displayed in the Settings Panel
132
+
133
+ ## `label` (string)
134
+
135
+ Indicates the label for the item that has to be displayed in the Settings Panel
136
+
125
137
  # `scoringType` (object)
126
138
 
127
139
  Properties of the `scoringType` object:
@@ -158,6 +170,62 @@ Indicates if the item has to be displayed in the Settings Panel
158
170
 
159
171
  Indicates the label for the item that has to be displayed in the Settings Panel
160
172
 
173
+ # `maxSelections` (number)
174
+
175
+ Maximum number of selected tokens in correct answer
176
+
177
+ # `minTokens` (number)
178
+
179
+ Minimum number of tokens
180
+
181
+ # `maxTokens` (number)
182
+
183
+ Maximum number of tokens
184
+
185
+ # `maxImageWidth` (object)
186
+
187
+ Properties of the `maxImageWidth` object:
188
+
189
+ ## `teacherInstructions` (number)
190
+
191
+ Indicates the max dimension for images in teacher instructions
192
+
193
+ ## `prompt` (number)
194
+
195
+ Indicates the max dimension for images in prompt - this is also the default dimension for all other input fields if it's not specified
196
+
197
+ ## `rationale` (number)
198
+
199
+ Indicates the max dimension for images in rationale
200
+
201
+ # `maxImageHeight` (object)
202
+
203
+ Properties of the `maxImageHeight` object:
204
+
205
+ ## `teacherInstructions` (number)
206
+
207
+ Indicates the max dimension for images in teacher instructions
208
+
209
+ ## `prompt` (number)
210
+
211
+ Indicates the max dimension for images in prompt - this is also the default dimension for all other input fields if it's not specified
212
+
213
+ ## `rationale` (number)
214
+
215
+ Indicates the max dimension for images in rationale
216
+
217
+ # `withRubric` (object)
218
+
219
+ Properties of the `withRubric` object:
220
+
221
+ ## `settings` (boolean)
222
+
223
+ Indicates if the item has to be displayed in the Settings Panel
224
+
225
+ ## `label` (string)
226
+
227
+ Indicates the label for the item that has to be displayed in the Settings Panel
228
+
161
229
  # `showPrompt` (boolean)
162
230
 
163
231
  Determines whether prompt field will be displayed or not
@@ -192,4 +260,20 @@ Indicates if the item has to be displayed in the Settings Panel
192
260
 
193
261
  ### `label` (string)
194
262
 
195
- Indicates the label for the item that has to be displayed in the Settings Panel
263
+ Indicates the label for the item that has to be displayed in the Settings Panel
264
+
265
+ ## `ConfigureMaxImageDimensionsProp` (object)
266
+
267
+ Properties of the `ConfigureMaxImageDimensionsProp` object:
268
+
269
+ ### `teacherInstructions` (number)
270
+
271
+ Indicates the max dimension for images in teacher instructions
272
+
273
+ ### `prompt` (number)
274
+
275
+ Indicates the max dimension for images in prompt - this is also the default dimension for all other input fields if it's not specified
276
+
277
+ ### `rationale` (number)
278
+
279
+ Indicates the max dimension for images in rationale