@pie-element/select-text 6.5.18 → 6.5.20-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.
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/utils.js"],"names":["createElementFromHTML","htmlString","arguments","length","undefined","div","document","createElement","innerHTML","trim","parseParagraph","paragraph","end","concat","parseParagraphs","dom","paragraphs","querySelectorAll","str","forEach","par","index","prepareText","text","txtDom","allDomElements","Array","from","generateModel","model","modelText","newTokens","tokens","reduce","acc","token","tokenText","slice","start","getStartIndex","newStartIndex","indexOf","lastToken","newStart","newEnd","oldStart","oldEnd","generateValidationMessage","config","minTokens","maxTokens","maxSelections","tokensMessage","selectionsMessage","message"],"mappings":";;;;;;;;;;;;;AAAA;;;;;;AAEA,IAAIA,qBAAqB,GAAG,SAASA,qBAAT,GAAiC;AAC3D,MAAIC,UAAU,GAAGC,SAAS,CAACC,MAAV,GAAmB,CAAnB,IAAwBD,SAAS,CAAC,CAAD,CAAT,KAAiBE,SAAzC,GAAqDF,SAAS,CAAC,CAAD,CAA9D,GAAoE,EAArF;AACA,MAAIG,GAAG,GAAGC,QAAQ,CAACC,aAAT,CAAuB,KAAvB,CAAV;AACAF,EAAAA,GAAG,CAACG,SAAJ,GAAgBP,UAAU,CAACQ,IAAX,EAAhB;AACA,SAAOJ,GAAP;AACD,CALD;;AAOA,IAAIK,cAAc,GAAG,SAASA,cAAT,CAAwBC,SAAxB,EAAmCC,GAAnC,EAAwC;AAC3D,MAAIA,GAAJ,EAAS;AACP,WAAOD,SAAS,CAACH,SAAjB;AACD;;AAED,SAAO,GAAGK,MAAH,CAAUF,SAAS,CAACH,SAApB,EAA+B,MAA/B,CAAP;AACD,CAND;;AAQA,IAAIM,eAAe,GAAG,SAASA,eAAT,CAAyBC,GAAzB,EAA8B;AAClD,MAAIC,UAAU,GAAGD,GAAG,CAACE,gBAAJ,CAAqB,qBAArB,CAAjB,CADkD,CACY;;AAE9D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,MAAhD,CAAQC,SAAR;AAAA,MAAmBC,SAAnB,GAAgDF,MAAhD,CAAmBE,SAAnB;AAAA,MAA8BC,aAA9B,GAAgDH,MAAhD,CAA8BG,aAA9B;AAEA,MAAMC,aAAa,GACjB,qCAA8BH,SAA9B,UAA8CC,SAAS,yBAAkBA,SAAlB,SAAiC,EAAxF,IAA8F,iBADhG;AAGA,MAAMG,iBAAiB,GACrB,mCACCF,aAAa,yBAAkBA,aAAlB,SAAqC,EADnD,IAEA,OAFA,IAGCA,aAAa,GAAG,GAAH,GAAS,EAHvB,IAIA,YALF;AAOA,MAAMG,OAAO,GAAG,6BAA6BF,aAA7B,GAA6CC,iBAA7D;AAEA,SAAOC,OAAP;AACD,CAhBM","sourcesContent":["import React from 'react';\n\nvar createElementFromHTML = function createElementFromHTML() {\n var htmlString = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';\n var div = document.createElement('div');\n div.innerHTML = htmlString.trim();\n return div;\n};\n\nvar parseParagraph = function parseParagraph(paragraph, end) {\n if (end) {\n return paragraph.innerHTML;\n }\n\n return ''.concat(paragraph.innerHTML, '\\n\\n');\n};\n\nvar parseParagraphs = function parseParagraphs(dom) {\n var paragraphs = dom.querySelectorAll('div[separator=true]'); // separate variable for easily debugging, if needed\n\n var str = '';\n paragraphs.forEach(function (par, index) {\n str += parseParagraph(par, index === paragraphs.length - 1);\n });\n return str || null;\n};\n\nvar prepareText = function prepareText(text) {\n var txtDom = createElementFromHTML(text);\n\n var div = document.createElement('div');\n div.innerHTML = \"<div separator='true'>\".concat(txtDom.innerHTML, '</div>');\n txtDom = div;\n\n var allDomElements = Array.from(txtDom.querySelectorAll('*'));\n\n if (allDomElements.length === 0) {\n return text;\n }\n\n return parseParagraphs(txtDom);\n};\n\nexport const generateModel = (model) => {\n if (!model) return model;\n\n // parsing\n const modelText = prepareText(model.text || '');\n\n const newTokens = (model.tokens || []).reduce((acc, token = {}) => {\n const tokenText = prepareText((model.text || '').slice(token.start, token.end));\n\n if (!tokenText) {\n return [...acc, token];\n }\n\n const getStartIndex = (start) => {\n let length = start;\n\n while (length >= 0) {\n let newStartIndex = modelText.slice(length).indexOf(tokenText);\n\n if (newStartIndex >= 0) {\n return newStartIndex + length;\n }\n\n length--;\n }\n\n return 0;\n };\n\n const lastToken = acc[acc.length - 1];\n const newStart = getStartIndex(lastToken ? lastToken.end : token.start);\n const newEnd = newStart + tokenText.length;\n\n return [\n ...acc,\n {\n ...token,\n text: tokenText,\n start: newStart,\n end: newEnd,\n // needed for getScore when tokens position is recalculated\n oldStart: token.start,\n oldEnd: token.end,\n },\n ];\n }, []);\n\n return {\n ...model,\n tokens: newTokens,\n text: modelText,\n };\n};\n\nexport const generateValidationMessage = (config) => {\n const { minTokens, maxTokens, maxSelections } = config;\n\n const tokensMessage =\n `\\nThere should be at least ${minTokens} ` + (maxTokens ? `and at most ${maxTokens} ` : '') + 'tokens defined.';\n\n const selectionsMessage =\n `\\nThere should be at least 1 ` +\n (maxSelections ? `and at most ${maxSelections} ` : '') +\n 'token' +\n (maxSelections ? 's' : '') +\n ' selected.';\n\n const message = 'Validation requirements:' + tokensMessage + selectionsMessage;\n\n return message;\n};\n"],"file":"utils.js"}
@@ -1,17 +1,17 @@
1
1
  {
2
2
  "name": "@pie-element/select-text-configure",
3
3
  "private": true,
4
- "version": "5.2.14",
4
+ "version": "6.4.0",
5
5
  "description": "",
6
6
  "main": "lib/index.js",
7
7
  "module": "src/index.js",
8
8
  "dependencies": {
9
9
  "@material-ui/core": "^3.9.2",
10
- "@pie-framework/pie-configure-events": "^1.2.0",
11
- "@pie-lib/config-ui": "^10.10.15",
12
- "@pie-lib/editable-html": "^7.17.15",
13
- "@pie-lib/scoring-config": "^3.5.144",
14
- "@pie-lib/text-select": "^1.8.11",
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
+ "@pie-lib/text-select": "^1.9.12",
15
15
  "debug": "^3.1.0",
16
16
  "lodash": "^4.17.15",
17
17
  "prop-types": "^15.6.2",
@@ -3,6 +3,161 @@
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.4.0](https://github.com/pie-framework/pie-elements/compare/@pie-element/select-text-controller@4.3.0...@pie-element/select-text-controller@4.4.0) (2023-01-17)
7
+
8
+
9
+ ### Features
10
+
11
+ * update pie-libs ([6423903](https://github.com/pie-framework/pie-elements/commit/6423903898b041f56db2111de2e4aac4ee9f1fd3))
12
+
13
+
14
+
15
+
16
+
17
+ # [4.3.0](https://github.com/pie-framework/pie-elements/compare/@pie-element/select-text-controller@4.2.10...@pie-element/select-text-controller@4.3.0) (2023-01-05)
18
+
19
+
20
+ ### Features
21
+
22
+ * update pie-libs ([8490729](https://github.com/pie-framework/pie-elements/commit/8490729a2389d36fd3968f0806119fde96577842))
23
+
24
+
25
+
26
+
27
+
28
+ ## [4.2.10](https://github.com/pie-framework/pie-elements/compare/@pie-element/select-text-controller@4.2.9...@pie-element/select-text-controller@4.2.10) (2022-12-07)
29
+
30
+
31
+ ### Bug Fixes
32
+
33
+ * update libs ([441f403](https://github.com/pie-framework/pie-elements/commit/441f403870b7bec0d61fab58b8d93dbe0ead4c32))
34
+
35
+
36
+
37
+
38
+
39
+ ## [4.2.9](https://github.com/pie-framework/pie-elements/compare/@pie-element/select-text-controller@4.2.8...@pie-element/select-text-controller@4.2.9) (2022-09-29)
40
+
41
+ **Note:** Version bump only for package @pie-element/select-text-controller
42
+
43
+
44
+
45
+
46
+
47
+ ## [4.2.8](https://github.com/pie-framework/pie-elements/compare/@pie-element/select-text-controller@4.2.7...@pie-element/select-text-controller@4.2.8) (2022-09-14)
48
+
49
+ **Note:** Version bump only for package @pie-element/select-text-controller
50
+
51
+
52
+
53
+
54
+
55
+ ## [4.2.7](https://github.com/pie-framework/pie-elements/compare/@pie-element/select-text-controller@4.2.6...@pie-element/select-text-controller@4.2.7) (2022-09-13)
56
+
57
+ **Note:** Version bump only for package @pie-element/select-text-controller
58
+
59
+
60
+
61
+
62
+
63
+ ## [4.2.6](https://github.com/pie-framework/pie-elements/compare/@pie-element/select-text-controller@4.2.5...@pie-element/select-text-controller@4.2.6) (2022-08-31)
64
+
65
+ **Note:** Version bump only for package @pie-element/select-text-controller
66
+
67
+
68
+
69
+
70
+
71
+ ## [4.2.5](https://github.com/pie-framework/pie-elements/compare/@pie-element/select-text-controller@4.2.4...@pie-element/select-text-controller@4.2.5) (2022-08-16)
72
+
73
+ **Note:** Version bump only for package @pie-element/select-text-controller
74
+
75
+
76
+
77
+
78
+
79
+ ## [4.2.4](https://github.com/pie-framework/pie-elements/compare/@pie-element/select-text-controller@4.2.3...@pie-element/select-text-controller@4.2.4) (2022-08-08)
80
+
81
+ **Note:** Version bump only for package @pie-element/select-text-controller
82
+
83
+
84
+
85
+
86
+
87
+ ## [4.2.3](https://github.com/pie-framework/pie-elements/compare/@pie-element/select-text-controller@4.2.2...@pie-element/select-text-controller@4.2.3) (2022-07-19)
88
+
89
+ **Note:** Version bump only for package @pie-element/select-text-controller
90
+
91
+
92
+
93
+
94
+
95
+ ## [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)
96
+
97
+ **Note:** Version bump only for package @pie-element/select-text-controller
98
+
99
+
100
+
101
+
102
+
103
+ ## [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)
104
+
105
+ **Note:** Version bump only for package @pie-element/select-text-controller
106
+
107
+
108
+
109
+
110
+
111
+ # [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)
112
+
113
+
114
+ ### Bug Fixes
115
+
116
+ * 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))
117
+
118
+
119
+ ### Features
120
+
121
+ * **select-text:** added configurable validation ([fcea834](https://github.com/pie-framework/pie-elements/commit/fcea834fc7d9d19dbd3bc65d10ef3ecbf2618097))
122
+ * **select-text:** added configurable validation PD-1700 ([467f4a6](https://github.com/pie-framework/pie-elements/commit/467f4a640e560e26c932ce067b1b09ffe444b290))
123
+ * **select-text:** ui/ux validation PD-1701 ([3ae2723](https://github.com/pie-framework/pie-elements/commit/3ae27238a70124dcf2b544f0f1c8ae93ddeb0f6e))
124
+
125
+
126
+
127
+
128
+
129
+ ## [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)
130
+
131
+ **Note:** Version bump only for package @pie-element/select-text-controller
132
+
133
+
134
+
135
+
136
+
137
+ ## [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)
138
+
139
+ **Note:** Version bump only for package @pie-element/select-text-controller
140
+
141
+
142
+
143
+
144
+
145
+ ## [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)
146
+
147
+ **Note:** Version bump only for package @pie-element/select-text-controller
148
+
149
+
150
+
151
+
152
+
153
+ ## [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)
154
+
155
+ **Note:** Version bump only for package @pie-element/select-text-controller
156
+
157
+
158
+
159
+
160
+
6
161
  ## [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)
7
162
 
8
163
  **Note:** Version bump only for package @pie-element/select-text-controller
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/defaults.js"],"names":["tokens","text","start","end","highlightChoices","maxSelections","prompt"],"mappings":";;;;;;;AAAA,IAAMA,MAAM,GAAG,SAATA,MAAS;AAAA,SAAM,CACnB;AACEC,IAAAA,IAAI,EAAE,sCADR;AAEEC,IAAAA,KAAK,EAAE,CAFT;AAGEC,IAAAA,GAAG,EAAE;AAHP,GADmB,EAMnB;AACEF,IAAAA,IAAI,EAAE,uCADR;AAEEC,IAAAA,KAAK,EAAE,EAFT;AAGEC,IAAAA,GAAG,EAAE;AAHP,GANmB,EAWnB;AACEF,IAAAA,IAAI,EAAE,+DADR;AAEEC,IAAAA,KAAK,EAAE,GAFT;AAGEC,IAAAA,GAAG,EAAE;AAHP,GAXmB,CAAN;AAAA,CAAf;;eAkBe;AACbC,EAAAA,gBAAgB,EAAE,IADL;AAEbC,EAAAA,aAAa,EAAE,CAFF;AAGbC,EAAAA,MAAM,EAAE,iDAHK;AAIbL,EAAAA,IAAI,EACF,oLALW;AAMbD,EAAAA,MAAM,EAAEA,MAAM;AAND,C","sourcesContent":["const tokens = () => [\n {\n text: 'Rachel cut out 8 stars in 6 minutes.',\n start: 0,\n end: 36,\n },\n {\n text: 'Lovelle cut out 6 stars in 4 minutes.',\n start: 37,\n end: 74,\n },\n {\n text: 'Lovelle and Rachel cut the same number of stars in 6 minutes.',\n start: 117,\n end: 177\n }\n];\n\nexport default {\n highlightChoices: true,\n maxSelections: 2,\n prompt: 'What sentences contain the character 6 in them?',\n text:\n 'Rachel cut out 8 stars in 6 minutes. Lovelle cut out 6 stars in 4 minutes. Rachel cut out 4 more stars than Lovelle. Lovelle and Rachel cut the same number of stars in 6 minutes.',\n tokens: tokens(),\n};\n"],"file":"defaults.js"}
1
+ {"version":3,"sources":["../src/defaults.js"],"names":["tokens","text","start","end","highlightChoices","maxSelections","prompt"],"mappings":";;;;;;;AAAA,IAAMA,MAAM,GAAG,SAATA,MAAS;AAAA,SAAM,CACnB;AACEC,IAAAA,IAAI,EAAE,sCADR;AAEEC,IAAAA,KAAK,EAAE,CAFT;AAGEC,IAAAA,GAAG,EAAE;AAHP,GADmB,EAMnB;AACEF,IAAAA,IAAI,EAAE,uCADR;AAEEC,IAAAA,KAAK,EAAE,EAFT;AAGEC,IAAAA,GAAG,EAAE;AAHP,GANmB,EAWnB;AACEF,IAAAA,IAAI,EAAE,+DADR;AAEEC,IAAAA,KAAK,EAAE,GAFT;AAGEC,IAAAA,GAAG,EAAE;AAHP,GAXmB,CAAN;AAAA,CAAf;;eAkBe;AACbC,EAAAA,gBAAgB,EAAE,IADL;AAEbC,EAAAA,aAAa,EAAE,CAFF;AAGbC,EAAAA,MAAM,EAAE,iDAHK;AAIbL,EAAAA,IAAI,EAAE,oLAJO;AAKbD,EAAAA,MAAM,EAAEA,MAAM;AALD,C","sourcesContent":["const tokens = () => [\n {\n text: 'Rachel cut out 8 stars in 6 minutes.',\n start: 0,\n end: 36,\n },\n {\n text: 'Lovelle cut out 6 stars in 4 minutes.',\n start: 37,\n end: 74,\n },\n {\n text: 'Lovelle and Rachel cut the same number of stars in 6 minutes.',\n start: 117,\n end: 177,\n },\n];\n\nexport default {\n highlightChoices: true,\n maxSelections: 2,\n prompt: 'What sentences contain the character 6 in them?',\n text: 'Rachel cut out 8 stars in 6 minutes. Lovelle cut out 6 stars in 4 minutes. Rachel cut out 4 more stars than Lovelle. Lovelle and Rachel cut the same number of stars in 6 minutes.',\n tokens: tokens(),\n};\n"],"file":"defaults.js"}
@@ -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,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,GAA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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;AAA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AAC/E,MAAM,IAAI,EAAX,EAAeW,MAAlC;AAEA,MAAMqE,cAAc,GAAG,CAAChF,MAAM,IAAI,EAAX,EAAeiF,MAAf,CAAsB,UAACC,GAAD,EAAMC,KAAN;AAAA,WAAiBA,KAAK,CAAC7E,OAAN,GAAgB4E,GAAG,GAAG,CAAtB,GAA0BA,GAA3C;AAAA,GAAtB,EAAuE,CAAvE,CAAvB;;AAEA,MAAIH,UAAU,GAAGH,SAAjB,EAA4B;AAC1BE,IAAAA,MAAM,CAACM,WAAP,sCAAiDR,SAAjD;AACD,GAFD,MAEO,IAAIG,UAAU,GAAGF,SAAjB,EAA4B;AACjCC,IAAAA,MAAM,CAACM,WAAP,0BAAqCP,SAArC;AACD;;AAED,MAAIG,cAAc,GAAG,CAArB,EAAwB;AACtBF,IAAAA,MAAM,CAACO,eAAP,GAAyB,4CAAzB;AACD,GAFD,MAEO,IAAIL,cAAc,GAAGb,aAArB,EAAoC;AACzCW,IAAAA,MAAM,CAACO,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) => Object.assign({}, t, evaluateMode ? { correct: !!t.correct } : { correct: undefined }));\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 (\n c.correct &&\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) => 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 ? parseFloat((positiveCount / totalCorrect.length).toFixed(2)) : 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(normalizedQuestion.tokens, env.mode === 'evaluate');\n log('tokens:', tokens);\n const correctness =\n env.mode === 'evaluate' ? getCorrectness(normalizedQuestion.tokens, session.selectedTokens) : 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 ? normalizedQuestion.prompt : null,\n text: normalizedQuestion.text,\n disabled: env.mode !== 'gather',\n maxSelections: normalizedQuestion.maxSelections,\n correctness,\n feedback,\n incorrect: env.mode === 'evaluate' ? correctness !== 'correct' : undefined,\n };\n\n if (env.role === 'instructor' && (env.mode === 'view' || env.mode === 'evaluate')) {\n out.rationale = normalizedQuestion.rationaleEnabled ? normalizedQuestion.rationale : 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,14 +1,14 @@
1
1
  {
2
2
  "name": "@pie-element/select-text-controller",
3
3
  "private": true,
4
- "version": "4.1.27",
4
+ "version": "4.4.0",
5
5
  "description": "",
6
6
  "main": "lib/index.js",
7
7
  "module": "src/index.js",
8
8
  "dependencies": {
9
- "@pie-lib/controller-utils": "^0.2.26",
10
- "@pie-lib/feedback": "^0.4.27",
11
- "@pie-lib/text-select": "^1.8.11",
9
+ "@pie-lib/controller-utils": "^0.2.42",
10
+ "@pie-lib/feedback": "^0.4.42",
11
+ "@pie-lib/text-select": "^1.9.12",
12
12
  "debug": "^3.1.0",
13
13
  "lodash": "^4.17.15"
14
14
  },
@@ -163,6 +163,27 @@
163
163
  }
164
164
  }
165
165
  },
166
+ "settingsPanelDisabled": {
167
+ "description": "Indicates if the settings panel is not available",
168
+ "type": "boolean",
169
+ "title": "settingsPanelDisabled"
170
+ },
171
+ "spellCheck": {
172
+ "title": "ConfigureProp",
173
+ "type": "object",
174
+ "properties": {
175
+ "settings": {
176
+ "description": "Indicates if the item has to be displayed in the Settings Panel",
177
+ "type": "boolean",
178
+ "title": "settings"
179
+ },
180
+ "label": {
181
+ "description": "Indicates the label for the item that has to be displayed in the Settings Panel",
182
+ "type": "string",
183
+ "title": "label"
184
+ }
185
+ }
186
+ },
166
187
  "scoringType": {
167
188
  "title": "ConfigureProp",
168
189
  "type": "object",
@@ -211,6 +232,79 @@
211
232
  }
212
233
  }
213
234
  },
235
+ "maxSelections": {
236
+ "description": "Maximum number of selected tokens in correct answer",
237
+ "type": "number",
238
+ "title": "maxSelections"
239
+ },
240
+ "minTokens": {
241
+ "description": "Minimum number of tokens",
242
+ "type": "number",
243
+ "title": "minTokens"
244
+ },
245
+ "maxTokens": {
246
+ "description": "Maximum number of tokens",
247
+ "type": "number",
248
+ "title": "maxTokens"
249
+ },
250
+ "maxImageWidth": {
251
+ "title": "ConfigureMaxImageDimensionsProp",
252
+ "type": "object",
253
+ "properties": {
254
+ "teacherInstructions": {
255
+ "description": "Indicates the max dimension for images in teacher instructions",
256
+ "type": "number",
257
+ "title": "teacherInstructions"
258
+ },
259
+ "prompt": {
260
+ "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",
261
+ "type": "number",
262
+ "title": "prompt"
263
+ },
264
+ "rationale": {
265
+ "description": "Indicates the max dimension for images in rationale",
266
+ "type": "number",
267
+ "title": "rationale"
268
+ }
269
+ }
270
+ },
271
+ "maxImageHeight": {
272
+ "title": "ConfigureMaxImageDimensionsProp",
273
+ "type": "object",
274
+ "properties": {
275
+ "teacherInstructions": {
276
+ "description": "Indicates the max dimension for images in teacher instructions",
277
+ "type": "number",
278
+ "title": "teacherInstructions"
279
+ },
280
+ "prompt": {
281
+ "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",
282
+ "type": "number",
283
+ "title": "prompt"
284
+ },
285
+ "rationale": {
286
+ "description": "Indicates the max dimension for images in rationale",
287
+ "type": "number",
288
+ "title": "rationale"
289
+ }
290
+ }
291
+ },
292
+ "withRubric": {
293
+ "title": "ConfigureProp",
294
+ "type": "object",
295
+ "properties": {
296
+ "settings": {
297
+ "description": "Indicates if the item has to be displayed in the Settings Panel",
298
+ "type": "boolean",
299
+ "title": "settings"
300
+ },
301
+ "label": {
302
+ "description": "Indicates the label for the item that has to be displayed in the Settings Panel",
303
+ "type": "string",
304
+ "title": "label"
305
+ }
306
+ }
307
+ },
214
308
  "showPrompt": {
215
309
  "description": "Determines whether prompt field will be displayed or not",
216
310
  "default": true,
@@ -246,6 +340,27 @@
246
340
  "title": "label"
247
341
  }
248
342
  }
343
+ },
344
+ "ConfigureMaxImageDimensionsProp": {
345
+ "title": "ConfigureMaxImageDimensionsProp",
346
+ "type": "object",
347
+ "properties": {
348
+ "teacherInstructions": {
349
+ "description": "Indicates the max dimension for images in teacher instructions",
350
+ "type": "number",
351
+ "title": "teacherInstructions"
352
+ },
353
+ "prompt": {
354
+ "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",
355
+ "type": "number",
356
+ "title": "prompt"
357
+ },
358
+ "rationale": {
359
+ "description": "Indicates the max dimension for images in rationale",
360
+ "type": "number",
361
+ "title": "rationale"
362
+ }
363
+ }
249
364
  }
250
365
  },
251
366
  "$schema": "http://json-schema.org/draft-07/schema#"
@@ -122,6 +122,22 @@ 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
+ # `settingsPanelDisabled` (boolean)
126
+
127
+ Indicates if the settings panel is not available
128
+
129
+ # `spellCheck` (object)
130
+
131
+ Properties of the `spellCheck` object:
132
+
133
+ ## `settings` (boolean)
134
+
135
+ Indicates if the item has to be displayed in the Settings Panel
136
+
137
+ ## `label` (string)
138
+
139
+ Indicates the label for the item that has to be displayed in the Settings Panel
140
+
125
141
  # `scoringType` (object)
126
142
 
127
143
  Properties of the `scoringType` object:
@@ -158,6 +174,62 @@ Indicates if the item has to be displayed in the Settings Panel
158
174
 
159
175
  Indicates the label for the item that has to be displayed in the Settings Panel
160
176
 
177
+ # `maxSelections` (number)
178
+
179
+ Maximum number of selected tokens in correct answer
180
+
181
+ # `minTokens` (number)
182
+
183
+ Minimum number of tokens
184
+
185
+ # `maxTokens` (number)
186
+
187
+ Maximum number of tokens
188
+
189
+ # `maxImageWidth` (object)
190
+
191
+ Properties of the `maxImageWidth` object:
192
+
193
+ ## `teacherInstructions` (number)
194
+
195
+ Indicates the max dimension for images in teacher instructions
196
+
197
+ ## `prompt` (number)
198
+
199
+ Indicates the max dimension for images in prompt - this is also the default dimension for all other input fields if it's not specified
200
+
201
+ ## `rationale` (number)
202
+
203
+ Indicates the max dimension for images in rationale
204
+
205
+ # `maxImageHeight` (object)
206
+
207
+ Properties of the `maxImageHeight` object:
208
+
209
+ ## `teacherInstructions` (number)
210
+
211
+ Indicates the max dimension for images in teacher instructions
212
+
213
+ ## `prompt` (number)
214
+
215
+ Indicates the max dimension for images in prompt - this is also the default dimension for all other input fields if it's not specified
216
+
217
+ ## `rationale` (number)
218
+
219
+ Indicates the max dimension for images in rationale
220
+
221
+ # `withRubric` (object)
222
+
223
+ Properties of the `withRubric` object:
224
+
225
+ ## `settings` (boolean)
226
+
227
+ Indicates if the item has to be displayed in the Settings Panel
228
+
229
+ ## `label` (string)
230
+
231
+ Indicates the label for the item that has to be displayed in the Settings Panel
232
+
161
233
  # `showPrompt` (boolean)
162
234
 
163
235
  Determines whether prompt field will be displayed or not
@@ -192,4 +264,20 @@ Indicates if the item has to be displayed in the Settings Panel
192
264
 
193
265
  ### `label` (string)
194
266
 
195
- Indicates the label for the item that has to be displayed in the Settings Panel
267
+ Indicates the label for the item that has to be displayed in the Settings Panel
268
+
269
+ ## `ConfigureMaxImageDimensionsProp` (object)
270
+
271
+ Properties of the `ConfigureMaxImageDimensionsProp` object:
272
+
273
+ ### `teacherInstructions` (number)
274
+
275
+ Indicates the max dimension for images in teacher instructions
276
+
277
+ ### `prompt` (number)
278
+
279
+ Indicates the max dimension for images in prompt - this is also the default dimension for all other input fields if it's not specified
280
+
281
+ ### `rationale` (number)
282
+
283
+ Indicates the max dimension for images in rationale
@@ -2,9 +2,7 @@ const { model, mathSample, htmlSample, htmlAscii } = require('./generate');
2
2
 
3
3
  module.exports = {
4
4
  elements: {
5
- 'select-text': '../..'
5
+ 'select-text': '../..',
6
6
  },
7
- models: [
8
- model('1', 'select-text')
9
- ]
7
+ models: [model('1', 'select-text')],
10
8
  };