@pie-element/placement-ordering 13.0.0-beta.0 → 13.0.0-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +0 -11
- package/configure/CHANGELOG.md +0 -11
- package/configure/lib/choice-editor.js +4 -5
- package/configure/lib/choice-editor.js.map +1 -1
- package/configure/lib/choice-tile.js +3 -4
- package/configure/lib/choice-tile.js.map +1 -1
- package/configure/lib/defaults.js +3 -0
- package/configure/lib/defaults.js.map +1 -1
- package/configure/lib/design.js +11 -12
- package/configure/lib/design.js.map +1 -1
- package/configure/lib/index.js +2 -2
- package/configure/lib/index.js.map +1 -1
- package/configure/lib/utils.js +3 -4
- package/configure/lib/utils.js.map +1 -1
- package/configure/package.json +11 -11
- package/controller/CHANGELOG.md +0 -11
- package/controller/lib/index.js +9 -11
- package/controller/lib/index.js.map +1 -1
- package/controller/lib/scoring.js +6 -6
- package/controller/lib/scoring.js.map +1 -1
- package/controller/package.json +6 -6
- package/lib/index.js +3 -3
- package/lib/index.js.map +1 -1
- package/lib/ordering.js +6 -9
- package/lib/ordering.js.map +1 -1
- package/lib/placement-ordering.js +8 -9
- package/lib/placement-ordering.js.map +1 -1
- package/lib/tile.js +41 -20
- package/lib/tile.js.map +1 -1
- package/package.json +13 -14
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["_pieConfigureEvents","require","_design","_interopRequireDefault","_react","_client","_defaults","_defaults2","prepareCustomizationObject","config","model","configuration","defaults","defaultValues","addWeightToCorrectResponse","correctResponse","map","correct","weight","undefined","id","exports","PlacementOrdering","HTMLElement","constructor","_root","_model","createDefaultModel","_configuration","onModelChanged","resetSession","_rerender","dispatchUpdate","onConfigurationChanged","insertImage","handler","dispatchEvent","InsertImageEvent","deleteImage","src","done","DeleteImageEvent","reset","ModelUpdatedEvent","s","c","info","newConfiguration","language","enabled","languageChoices","options","length","value","settings","find","option","push","label","insertSound","InsertSoundEvent","onDeleteSound","DeleteSoundEvent","element","React","createElement","Main","imageSupport","add","delete","uploadSoundSupport","bind","createRoot","render","disconnectedCallback","unmount","default","_defineProperty2","mapChoicesToReturnCorrectResponse","choices","ch","defaultModel"],"sources":["../src/index.js"],"sourcesContent":["import {\n ModelUpdatedEvent,\n DeleteImageEvent,\n InsertImageEvent,\n InsertSoundEvent,\n DeleteSoundEvent,\n} from '@pie-framework/pie-configure-events';\n\nimport Main from './design';\nimport React from 'react';\nimport { createRoot } from 'react-dom/client';\nimport defaultValues from './defaults';\nimport defaults from 'lodash/defaults';\n\nconst prepareCustomizationObject = (config, model) => {\n const configuration = defaults(config, defaultValues.configuration);\n\n return { configuration, model };\n};\n\nexport const addWeightToCorrectResponse = (correctResponse) =>\n correctResponse &&\n correctResponse.map((correct) => {\n // if weight is set\n if (correct.weight !== undefined) {\n return { id: correct.id, weight: correct.weight };\n } else {\n return { id: correct.id || correct, weight: 0 };\n }\n });\n/**\n * assuming that the correct response will be set via ui, not via config,\n * correctResponse (if not set) will be initialized with choices default order\n */\nexport default class PlacementOrdering extends HTMLElement {\n static createDefaultModel = (model = {}) => {\n const mapChoicesToReturnCorrectResponse = (choices) => choices && choices.map((ch) => ({ id: ch.id, weight: 0 }));\n\n let correctResponse =\n addWeightToCorrectResponse(model.correctResponse) || mapChoicesToReturnCorrectResponse(model.choices);\n\n const defaultModel = {\n ...defaultValues.model,\n ...model,\n };\n\n if (correctResponse) {\n defaultModel.correctResponse = correctResponse;\n }\n\n return defaultModel;\n };\n\n constructor() {\n super();\n this._root = null;\n\n this._model = PlacementOrdering.createDefaultModel();\n this._configuration = defaultValues.configuration;\n\n this.onModelChanged = (model, resetSession) => {\n this._model = model;\n this._rerender();\n this.dispatchUpdate(resetSession);\n };\n\n this.onConfigurationChanged = (configuration) => {\n this._configuration = prepareCustomizationObject(configuration).configuration;\n\n this.onModelChanged(this._model);\n this._rerender();\n };\n\n this.insertImage = (handler) => {\n this.dispatchEvent(new InsertImageEvent(handler));\n };\n\n this.deleteImage = (src, done) => {\n this.dispatchEvent(new DeleteImageEvent(src, done));\n };\n }\n\n dispatchUpdate(reset) {\n this.dispatchEvent(new ModelUpdatedEvent(this._model, reset));\n }\n\n set model(s) {\n this._model = PlacementOrdering.createDefaultModel(s);\n this._rerender();\n }\n\n set configuration(c) {\n const info = prepareCustomizationObject(c, this._model);\n\n this.onModelChanged(info.model);\n\n const newConfiguration = {\n ...defaultValues.configuration,\n ...info.configuration,\n };\n\n this._configuration = newConfiguration;\n\n // if language:enabled is true, then the corresponding default item model should include a language value;\n // if it is false, then the language field should be omitted from the item model.\n // if a default item model includes a language value (e.g., en_US) and the corresponding authoring view settings have language:settings = true,\n // then (a) language:enabled should also be true, and (b) that default language value should be represented in languageChoices[] (as a key).\n if (newConfiguration?.language?.enabled) {\n if (newConfiguration?.languageChoices?.options?.length) {\n this._model.language = newConfiguration?.languageChoices.options[0].value;\n }\n } else if (newConfiguration.language.settings && this._model.language) {\n this._configuration.language.enabled = true;\n\n if (!this._configuration.languageChoices.options || !this._configuration.languageChoices.options.length) {\n this._configuration.languageChoices.options = [];\n }\n\n // check if the language is already included in the languageChoices.options array\n // and if not, then add it.\n if (!this._configuration.languageChoices.options.find(option => option.value === this._model.language)) {\n this._configuration.languageChoices.options.push({\n value: this._model.language,\n label: this._model.language,\n });\n }\n } else {\n delete this._model.language;\n }\n\n this._rerender();\n }\n\n insertSound(handler) {\n this.dispatchEvent(new InsertSoundEvent(handler));\n }\n\n onDeleteSound(src, done) {\n this.dispatchEvent(new DeleteSoundEvent(src, done));\n }\n\n _rerender() {\n let element = React.createElement(Main, {\n model: this._model,\n configuration: this._configuration,\n onModelChanged: this.onModelChanged,\n onConfigurationChanged: this.onConfigurationChanged,\n imageSupport: {\n add: this.insertImage,\n delete: this.deleteImage,\n },\n uploadSoundSupport: {\n add: this.insertSound.bind(this),\n delete: this.onDeleteSound.bind(this),\n },\n });\n\n if (!this._root) {\n this._root = createRoot(this);\n }\n this._root.render(element);\n }\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A,OAAO,IAAIA,OAAO,CAAC/D,GAAG,CAAEgE,EAAE,KAAM;IAAE5D,EAAE,EAAE4D,EAAE,CAAC5D,EAAE;IAAEF,MAAM,EAAE;EAAE,CAAC,CAAC,CAAC;EAEjH,IAAIH,eAAe,GACjBD,0BAA0B,CAACJ,KAAK,CAACK,eAAe,CAAC,IAAI+D,iCAAiC,CAACpE,KAAK,CAACqE,OAAO,CAAC;EAEvG,MAAME,YAAY,GAAG;IACnB,GAAGpE,iBAAa,CAACH,KAAK;IACtB,GAAGA;EACL,CAAC;EAED,IAAIK,eAAe,EAAE;IACnBkE,YAAY,CAAClE,eAAe,GAAGA,eAAe;EAChD;EAEA,OAAOkE,YAAY;AACrB,CAAC","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"index.js","names":["_pieConfigureEvents","require","_design","_interopRequireDefault","_react","_client","_defaults","_lodashEs","prepareCustomizationObject","config","model","configuration","defaults","defaultValues","addWeightToCorrectResponse","correctResponse","map","correct","weight","undefined","id","exports","PlacementOrdering","HTMLElement","constructor","_root","_model","createDefaultModel","_configuration","onModelChanged","resetSession","_rerender","dispatchUpdate","onConfigurationChanged","insertImage","handler","dispatchEvent","InsertImageEvent","deleteImage","src","done","DeleteImageEvent","reset","ModelUpdatedEvent","s","c","info","newConfiguration","language","enabled","languageChoices","options","length","value","settings","find","option","push","label","insertSound","InsertSoundEvent","onDeleteSound","DeleteSoundEvent","element","React","createElement","Main","imageSupport","add","delete","uploadSoundSupport","bind","createRoot","render","disconnectedCallback","unmount","default","_defineProperty2","mapChoicesToReturnCorrectResponse","choices","ch","defaultModel"],"sources":["../src/index.js"],"sourcesContent":["import {\n ModelUpdatedEvent,\n DeleteImageEvent,\n InsertImageEvent,\n InsertSoundEvent,\n DeleteSoundEvent,\n} from '@pie-framework/pie-configure-events';\n\nimport Main from './design';\nimport React from 'react';\nimport { createRoot } from 'react-dom/client';\nimport defaultValues from './defaults';\nimport { defaults } from 'lodash-es';\n\nconst prepareCustomizationObject = (config, model) => {\n const configuration = defaults(config, defaultValues.configuration);\n\n return { configuration, model };\n};\n\nexport const addWeightToCorrectResponse = (correctResponse) =>\n correctResponse &&\n correctResponse.map((correct) => {\n // if weight is set\n if (correct.weight !== undefined) {\n return { id: correct.id, weight: correct.weight };\n } else {\n return { id: correct.id || correct, weight: 0 };\n }\n });\n/**\n * assuming that the correct response will be set via ui, not via config,\n * correctResponse (if not set) will be initialized with choices default order\n */\nexport default class PlacementOrdering extends HTMLElement {\n static createDefaultModel = (model = {}) => {\n const mapChoicesToReturnCorrectResponse = (choices) => choices && choices.map((ch) => ({ id: ch.id, weight: 0 }));\n\n let correctResponse =\n addWeightToCorrectResponse(model.correctResponse) || mapChoicesToReturnCorrectResponse(model.choices);\n\n const defaultModel = {\n ...defaultValues.model,\n ...model,\n };\n\n if (correctResponse) {\n defaultModel.correctResponse = correctResponse;\n }\n\n return defaultModel;\n };\n\n constructor() {\n super();\n this._root = null;\n\n this._model = PlacementOrdering.createDefaultModel();\n this._configuration = defaultValues.configuration;\n\n this.onModelChanged = (model, resetSession) => {\n this._model = model;\n this._rerender();\n this.dispatchUpdate(resetSession);\n };\n\n this.onConfigurationChanged = (configuration) => {\n this._configuration = prepareCustomizationObject(configuration).configuration;\n\n this.onModelChanged(this._model);\n this._rerender();\n };\n\n this.insertImage = (handler) => {\n this.dispatchEvent(new InsertImageEvent(handler));\n };\n\n this.deleteImage = (src, done) => {\n this.dispatchEvent(new DeleteImageEvent(src, done));\n };\n }\n\n dispatchUpdate(reset) {\n this.dispatchEvent(new ModelUpdatedEvent(this._model, reset));\n }\n\n set model(s) {\n this._model = PlacementOrdering.createDefaultModel(s);\n this._rerender();\n }\n\n set configuration(c) {\n const info = prepareCustomizationObject(c, this._model);\n\n this.onModelChanged(info.model);\n\n const newConfiguration = {\n ...defaultValues.configuration,\n ...info.configuration,\n };\n\n this._configuration = newConfiguration;\n\n // if language:enabled is true, then the corresponding default item model should include a language value;\n // if it is false, then the language field should be omitted from the item model.\n // if a default item model includes a language value (e.g., en_US) and the corresponding authoring view settings have language:settings = true,\n // then (a) language:enabled should also be true, and (b) that default language value should be represented in languageChoices[] (as a key).\n if (newConfiguration?.language?.enabled) {\n if (newConfiguration?.languageChoices?.options?.length) {\n this._model.language = newConfiguration?.languageChoices.options[0].value;\n }\n } else if (newConfiguration.language.settings && this._model.language) {\n this._configuration.language.enabled = true;\n\n if (!this._configuration.languageChoices.options || !this._configuration.languageChoices.options.length) {\n this._configuration.languageChoices.options = [];\n }\n\n // check if the language is already included in the languageChoices.options array\n // and if not, then add it.\n if (!this._configuration.languageChoices.options.find((option) => option.value === this._model.language)) {\n this._configuration.languageChoices.options.push({\n value: this._model.language,\n label: this._model.language,\n });\n }\n } else {\n delete this._model.language;\n }\n\n this._rerender();\n }\n\n insertSound(handler) {\n this.dispatchEvent(new InsertSoundEvent(handler));\n }\n\n onDeleteSound(src, done) {\n this.dispatchEvent(new DeleteSoundEvent(src, done));\n }\n\n _rerender() {\n let element = React.createElement(Main, {\n model: this._model,\n configuration: this._configuration,\n onModelChanged: this.onModelChanged,\n onConfigurationChanged: this.onConfigurationChanged,\n imageSupport: {\n add: this.insertImage,\n delete: this.deleteImage,\n },\n uploadSoundSupport: {\n add: this.insertSound.bind(this),\n delete: this.onDeleteSound.bind(this),\n },\n });\n\n if (!this._root) {\n this._root = createRoot(this);\n }\n this._root.render(element);\n }\n\n disconnectedCallback() {\n if (this._root) {\n this._root.unmount();\n }\n }\n}\n"],"mappings":";;;;;;;;AAAA,IAAAA,mBAAA,GAAAC,OAAA;AAQA,IAAAC,OAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,MAAA,GAAAD,sBAAA,CAAAF,OAAA;AACA,IAAAI,OAAA,GAAAJ,OAAA;AACA,IAAAK,SAAA,GAAAH,sBAAA,CAAAF,OAAA;AACA,IAAAM,SAAA,GAAAN,OAAA;AAEA,MAAMO,0BAA0B,GAAGA,CAACC,MAAM,EAAEC,KAAK,KAAK;EACpD,MAAMC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e,GAAGA,eAAe;EAChD;EAEA,OAAOkE,YAAY;AACrB,CAAC","ignoreList":[]}
|
package/configure/lib/utils.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
@@ -8,7 +7,7 @@ exports.buildTiles = buildTiles;
|
|
|
8
7
|
exports.generateValidationMessage = void 0;
|
|
9
8
|
exports.normalizeIndex = normalizeIndex;
|
|
10
9
|
exports.updateResponseOrChoices = updateResponseOrChoices;
|
|
11
|
-
var
|
|
10
|
+
var _lodashEs = require("lodash-es");
|
|
12
11
|
const generateValidationMessage = () => {
|
|
13
12
|
const answersMessage = '\nThere should be at least 3 tokens.' + '\nThe tokens should not be empty and should be unique.' + '\nThe correct ordering should not be identical to the initial ordering.';
|
|
14
13
|
return 'Validation requirements:' + answersMessage;
|
|
@@ -33,7 +32,7 @@ function updateResponseOrChoices(response, choices, from, to) {
|
|
|
33
32
|
index: placeAtIndex
|
|
34
33
|
} = to;
|
|
35
34
|
if (fromType === 'target' && toType === 'target') {
|
|
36
|
-
const updatedResponse = (0,
|
|
35
|
+
const updatedResponse = (0, _lodashEs.cloneDeep)(response) || [];
|
|
37
36
|
const {
|
|
38
37
|
movedItem,
|
|
39
38
|
remainingItems
|
|
@@ -54,7 +53,7 @@ function updateResponseOrChoices(response, choices, from, to) {
|
|
|
54
53
|
};
|
|
55
54
|
}
|
|
56
55
|
if (fromType === 'choice' && toType === 'choice') {
|
|
57
|
-
const updatedChoices = (0,
|
|
56
|
+
const updatedChoices = (0, _lodashEs.cloneDeep)(choices) || [];
|
|
58
57
|
const {
|
|
59
58
|
movedItem,
|
|
60
59
|
remainingItems,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","names":["
|
|
1
|
+
{"version":3,"file":"utils.js","names":["_lodashEs","require","generateValidationMessage","answersMessage","exports","normalizeIndex","tile","ordering","type","response","findIndex","r","id","choices","c","updateResponseOrChoices","from","to","fromType","index","fromIndex","toType","placeAtIndex","updatedResponse","cloneDeep","movedItem","remainingItems","reduce","acc","item","push","slice","updatedChoices","toIndex","buildTiles","targets","map","respId","choice","find","undefined","draggable","editable","processedChoices","m","Object","assign","droppable","concat"],"sources":["../src/utils.js"],"sourcesContent":["import { cloneDeep } from 'lodash-es';\n\nexport const generateValidationMessage = () => {\n const answersMessage =\n '\\nThere should be at least 3 tokens.' +\n '\\nThe tokens should not be empty and should be unique.' +\n '\\nThe correct ordering should not be identical to the initial ordering.';\n\n return 'Validation requirements:' + answersMessage;\n};\n\nexport function normalizeIndex(tile, ordering) {\n if (tile.type === 'target') {\n return ordering.response.findIndex(r => r.id === tile.id);\n }\n\n if (tile.type === 'choice') {\n return ordering.choices.findIndex(c => c.id === tile.id);\n }\n\n return -1;\n}\n\nexport function updateResponseOrChoices(response, choices, from, to) {\n const { type: fromType, index: fromIndex } = from;\n const { type: toType, index: placeAtIndex } = to;\n\n if (fromType === 'target' && toType === 'target') {\n const updatedResponse = cloneDeep(response) || [];\n\n const { movedItem, remainingItems } = updatedResponse.reduce(\n (acc, item, index) => {\n if (index === fromIndex) {\n acc.movedItem = item;\n } else {\n acc.remainingItems.push(item);\n }\n\n return acc;\n },\n { movedItem: null, remainingItems: [] },\n );\n\n return {\n response: [...remainingItems.slice(0, placeAtIndex), movedItem, ...remainingItems.slice(placeAtIndex)],\n choices,\n };\n }\n\n if (fromType === 'choice' && toType === 'choice') {\n const updatedChoices = cloneDeep(choices) || [];\n\n const { movedItem, remainingItems, toIndex } = updatedChoices.reduce(\n (acc, item, index) => {\n if (item.id === from.id) {\n acc.movedItem = item;\n } else {\n acc.remainingItems.push(item);\n }\n\n if (item.id === to.id) {\n acc.toIndex = index;\n }\n\n return acc;\n },\n { movedItem: null, remainingItems: [], toIndex: null },\n );\n\n return {\n response,\n choices: [...remainingItems.slice(0, toIndex), movedItem, ...remainingItems.slice(toIndex)],\n };\n }\n\n return { response, choices };\n}\n\nexport function buildTiles(choices, response) {\n const targets = response.map((r, index) => {\n const respId = r && r.id;\n const choice = choices.find((c) => respId !== undefined && respId !== null && c.id === respId);\n\n return {\n type: 'target',\n ...choice,\n draggable: true,\n index,\n editable: false,\n };\n });\n\n const processedChoices = choices.map((m) => {\n return Object.assign({}, m, {\n type: 'choice',\n droppable: false,\n draggable: true,\n editable: true,\n });\n });\n\n return processedChoices.concat(targets);\n}\n"],"mappings":";;;;;;;;;AAAA,IAAAA,SAAA,GAAAC,OAAA;AAEO,MAAMC,yBAAyB,GAAGA,CAAA,KAAM;EAC7C,MAAMC,cAAc,GAClB,sCAAsC,GACtC,wDAAwD,GACxD,yEAAyE;EAE3E,OAAO,0BAA0B,GAAGA,cAAc;AACpD,CAAC;AAACC,OAAA,CAAAF,yBAAA,GAAAA,yBAAA;AAEK,SAASG,cAAcA,CAACC,IAAI,EAAEC,QAAQ,EAAE;EAC7C,IAAID,IAAI,CAACE,IAAI,KAAK,QAAQ,EAAE;IAC1B,OAAOD,QAAQ,CAACE,QAAQ,CAACC,SAAS,CAACC,CAAC,IAAIA,CAAC,CAACC,EAAE,KAAKN,IAAI,CAACM,EAAE,CAAC;EAC3D;EAEA,IAAIN,IAAI,CAACE,IAAI,KAAK,QAAQ,EAAE;IAC1B,OAAOD,QAAQ,CAACM,OAAO,CAACH,SAAS,CAACI,CAAC,IAAIA,CAAC,CAACF,EAAE,KAAKN,IAAI,CAACM,EAAE,CAAC;EAC1D;EAEA,OAAO,CAAC,CAAC;AACX;AAEO,SAASG,uBAAuBA,CAACN,QAAQ,EAAEI,OAAO,EAAEG,IAAI,EAAEC,EAAE,EAAE;EACnE,MAAM;IAAET,IAAI,EAAEU,QAAQ;IAAEC,KAAK,EAAEC;EAAU,CAAC,GAAGJ,IAAI;EACjD,MAAM;IAAER,IAAI,EAAEa,MAAM;IAAEF,KAAK,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,gBAAgB,CAACK,MAAM,CAACb,OAAO,CAAC;AACzC","ignoreList":[]}
|
package/configure/package.json
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pie-element/placement-ordering-configure",
|
|
3
|
-
"version": "10.0.0-beta.
|
|
3
|
+
"version": "10.0.0-beta.1",
|
|
4
4
|
"private": true,
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "src/index.js",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@dnd-kit/core": "^6.1
|
|
8
|
+
"@dnd-kit/core": "^6.3.1",
|
|
9
9
|
"@emotion/react": "^11.14.0",
|
|
10
10
|
"@emotion/style": "^0.8.0",
|
|
11
11
|
"@mui/icons-material": "^7.3.4",
|
|
12
12
|
"@mui/material": "^7.3.4",
|
|
13
13
|
"@pie-framework/pie-configure-events": "^1.3.0",
|
|
14
|
-
"@pie-lib/config-ui": "
|
|
15
|
-
"@pie-lib/drag": "
|
|
16
|
-
"@pie-lib/editable-html": "
|
|
17
|
-
"@pie-lib/render-ui": "
|
|
18
|
-
"debug": "^
|
|
19
|
-
"lodash": "^4.17.
|
|
14
|
+
"@pie-lib/config-ui": "12.1.1-next.3",
|
|
15
|
+
"@pie-lib/drag": "3.1.1-next.1",
|
|
16
|
+
"@pie-lib/editable-html-tip-tap": "1.1.1-next.3",
|
|
17
|
+
"@pie-lib/render-ui": "5.1.1-next.1",
|
|
18
|
+
"debug": "^4.1.1",
|
|
19
|
+
"lodash-es": "^4.17.23",
|
|
20
20
|
"nested-property": "^0.0.7",
|
|
21
21
|
"pluralize": "^8.0.0",
|
|
22
|
-
"prop-types": "^15.
|
|
23
|
-
"react": "18.
|
|
24
|
-
"react-dom": "18.
|
|
22
|
+
"prop-types": "^15.8.1",
|
|
23
|
+
"react": "18.3.1",
|
|
24
|
+
"react-dom": "18.3.1"
|
|
25
25
|
}
|
|
26
26
|
}
|
package/controller/CHANGELOG.md
CHANGED
|
@@ -3,17 +3,6 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
-
## [9.3.3](https://github.com/pie-framework/pie-elements/compare/@pie-element/placement-ordering-controller@9.3.2...@pie-element/placement-ordering-controller@9.3.3) (2025-11-27)
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
### Bug Fixes
|
|
10
|
-
|
|
11
|
-
* bump libs PD-5274, PD-5211, PD-5248 ([7610b25](https://github.com/pie-framework/pie-elements/commit/7610b25423956b6492f33322513b3430051fca77))
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
6
|
## [9.3.2](https://github.com/pie-framework/pie-elements/compare/@pie-element/placement-ordering-controller@9.3.1...@pie-element/placement-ordering-controller@9.3.2) (2025-10-22)
|
|
18
7
|
|
|
19
8
|
|
package/controller/lib/index.js
CHANGED
|
@@ -11,13 +11,11 @@ exports.normalize = void 0;
|
|
|
11
11
|
exports.outcome = outcome;
|
|
12
12
|
exports.validate = exports.questionError = void 0;
|
|
13
13
|
var _scoring = require("./scoring");
|
|
14
|
-
var
|
|
14
|
+
var _lodashEs = require("lodash-es");
|
|
15
15
|
var _feedback = require("@pie-lib/feedback");
|
|
16
16
|
var _controllerUtils = require("@pie-lib/controller-utils");
|
|
17
17
|
var _debug = _interopRequireDefault(require("debug"));
|
|
18
18
|
var _defaults = _interopRequireDefault(require("./defaults"));
|
|
19
|
-
var _isEqual = _interopRequireDefault(require("lodash/isEqual"));
|
|
20
|
-
var _isEmpty = _interopRequireDefault(require("lodash/isEmpty"));
|
|
21
19
|
var _translator = _interopRequireDefault(require("@pie-lib/translator"));
|
|
22
20
|
const log = (0, _debug.default)('@pie-element:placement-ordering:controller');
|
|
23
21
|
const {
|
|
@@ -27,13 +25,13 @@ const questionError = () => new Error('Question is missing required array: corre
|
|
|
27
25
|
exports.questionError = questionError;
|
|
28
26
|
function outcome(question, session, env) {
|
|
29
27
|
return new Promise((resolve, reject) => {
|
|
30
|
-
if (!session ||
|
|
28
|
+
if (!session || (0, _lodashEs.isEmpty)(session)) {
|
|
31
29
|
resolve({
|
|
32
30
|
score: 0,
|
|
33
31
|
empty: true
|
|
34
32
|
});
|
|
35
33
|
}
|
|
36
|
-
if (!question || !question.correctResponse ||
|
|
34
|
+
if (!question || !question.correctResponse || (0, _lodashEs.isEmpty)(question.correctResponse)) {
|
|
37
35
|
reject(questionError());
|
|
38
36
|
} else {
|
|
39
37
|
try {
|
|
@@ -76,7 +74,7 @@ exports.normalize = normalize;
|
|
|
76
74
|
async function model(question, session, env) {
|
|
77
75
|
const normalizedQuestion = normalize(question);
|
|
78
76
|
const base = {};
|
|
79
|
-
if (question.alternateResponses &&
|
|
77
|
+
if (question.alternateResponses && (0, _lodashEs.every)(question.alternateResponses, _lodashEs.isArray)) {
|
|
80
78
|
log('Deprecated structure of alternateResponses is in use');
|
|
81
79
|
// eslint-disable-next-line no-console
|
|
82
80
|
console.error('Deprecated structure of alternateResponses is in use');
|
|
@@ -117,7 +115,7 @@ async function model(question, session, env) {
|
|
|
117
115
|
const value = session && session.value || [];
|
|
118
116
|
const allCorrectResponses = (0, _scoring.getAllCorrectResponses)(normalizedQuestion);
|
|
119
117
|
const bestSetOfResponses = allCorrectResponses.reduce((info, cr) => {
|
|
120
|
-
const currentScore =
|
|
118
|
+
const currentScore = (0, _lodashEs.reduce)(value, (acc, c, idx) => acc + (Array.isArray(cr) && cr[idx] === c ? 1 : 0), 0);
|
|
121
119
|
if (currentScore > info.score) {
|
|
122
120
|
return {
|
|
123
121
|
arr: cr,
|
|
@@ -129,13 +127,13 @@ async function model(question, session, env) {
|
|
|
129
127
|
arr: [],
|
|
130
128
|
score: 0
|
|
131
129
|
});
|
|
132
|
-
base.outcomes =
|
|
130
|
+
base.outcomes = (0, _lodashEs.map)(value, (c, idx) => {
|
|
133
131
|
return {
|
|
134
132
|
id: c,
|
|
135
133
|
outcome: bestSetOfResponses.arr[idx] === c ? 'correct' : 'incorrect'
|
|
136
134
|
};
|
|
137
135
|
});
|
|
138
|
-
const isResponseCorrect = allCorrectResponses.some(response =>
|
|
136
|
+
const isResponseCorrect = allCorrectResponses.some(response => (0, _lodashEs.isEqual)(response, value));
|
|
139
137
|
const responseScore = (0, _scoring.score)(question, session);
|
|
140
138
|
const isCorrect = responseScore === 1;
|
|
141
139
|
const isPartialCorrect = !isCorrect && _controllerUtils.partialScoring.enabled(normalizedQuestion, env || {}) && responseScore !== 0;
|
|
@@ -203,10 +201,10 @@ const validate = (model = {}, config = {}) => {
|
|
|
203
201
|
});
|
|
204
202
|
const choicesIds = (choices || []).map(choice => choice.id);
|
|
205
203
|
const correctResponseIds = (correctResponse || []).map(response => response.id || response);
|
|
206
|
-
if ((0,
|
|
204
|
+
if ((0, _lodashEs.isEqual)(choicesIds, correctResponseIds)) {
|
|
207
205
|
errors.orderError = 'The correct ordering should not be identical to the initial ordering.';
|
|
208
206
|
}
|
|
209
|
-
if (!(0,
|
|
207
|
+
if (!(0, _lodashEs.isEmpty)(choicesErrors)) {
|
|
210
208
|
errors.choicesErrors = choicesErrors;
|
|
211
209
|
}
|
|
212
210
|
return errors;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["_scoring","require","_lodash","_interopRequireDefault","_feedback","_controllerUtils","_debug","_defaults","_isEqual","_isEmpty","_translator","log","debug","translator","Translator","questionError","Error","exports","outcome","question","session","env","Promise","resolve","reject","_","isEmpty","score","empty","correctResponse","s","finalScore","partialScoring","enabled","e","createDefaultModel","model","defaults","normalize","rationaleEnabled","feedbackEnabled","promptEnabled","teacherInstructionsEnabled","studentInstructionsEnabled","normalizedQuestion","base","alternateResponses","every","isArray","console","error","extraCSSRules","outcomes","completeLength","length","choices","filter","choice","label","note","showNote","language","prompt","config","orientation","includeTargets","placementArea","choiceLabelEnabled","targetLabel","choiceLabel","showOrdering","numberedGuides","allowSameChoiceInTargets","removeTilesAfterPlacing","disabled","mode","t","lng","role","rationale","teacherInstructions","value","allCorrectResponses","getAllCorrectResponses","bestSetOfResponses","reduce","info","cr","currentScore","acc","c","idx","Array","arr","map","id","isResponseCorrect","some","response","isEqual","responseScore","isCorrect","isPartialCorrect","correctness","flattenCorrect","feedback","getFeedbackForCorrectness","undefined","createCorrectResponseSession","getInnerText","html","replaceAll","getContent","replace","validate","errors","forEach","field","required","reversedChoices","reverse","choicesErrors","index","identicalAnswer","slice","choicesIds","correctResponseIds","orderError"],"sources":["../src/index.js"],"sourcesContent":["import { flattenCorrect, getAllCorrectResponses, score } from './scoring';\n\nimport _ from 'lodash';\nimport { getFeedbackForCorrectness } from '@pie-lib/feedback';\nimport { partialScoring } from '@pie-lib/controller-utils';\nimport debug from 'debug';\n\nimport defaults from './defaults';\nimport isEqual from 'lodash/isEqual';\nimport isEmpty from 'lodash/isEmpty';\n\nconst log = debug('@pie-element:placement-ordering:controller');\nimport Translator from '@pie-lib/translator';\n\nconst { translator } = Translator;\n\nexport const questionError = () => new Error('Question is missing required array: correctResponse');\n\nexport function outcome(question, session, env) {\n return new Promise((resolve, reject) => {\n if (!session || _.isEmpty(session)) {\n resolve({ score: 0, empty: true });\n }\n\n if (!question || !question.correctResponse || _.isEmpty(question.correctResponse)) {\n reject(questionError());\n } else {\n try {\n const s = score(question, session);\n const finalScore = partialScoring.enabled(question, env || {}) ? s : s === 1 ? 1 : 0;\n resolve({\n score: finalScore,\n });\n } catch (e) {\n reject(e);\n }\n }\n });\n}\n\nexport function createDefaultModel(model = {}) {\n return new Promise((resolve) => {\n resolve({\n ...defaults,\n ...model,\n });\n });\n}\n\nexport const normalize = (question) => ({\n ...defaults,\n rationaleEnabled: true,\n feedbackEnabled: false,\n promptEnabled: true,\n teacherInstructionsEnabled: true,\n studentInstructionsEnabled: true,\n ...question,\n});\n\n/**\n *\n * @param {*} question\n * @param {*} session\n * @param {*} env\n */\nexport async function model(question, session, env) {\n const normalizedQuestion = normalize(question);\n const base = {};\n\n if (question.alternateResponses && _.every(question.alternateResponses, _.isArray)) {\n log('Deprecated structure of alternateResponses is in use');\n // eslint-disable-next-line no-console\n console.error('Deprecated structure of alternateResponses is in use');\n }\n\n base.env = env;\n base.extraCSSRules = normalizedQuestion.extraCSSRules;\n base.outcomes = [];\n base.completeLength = (normalizedQuestion.correctResponse || []).length;\n base.choices = (normalizedQuestion.choices || []).filter((choice) => choice.label);\n base.note = normalizedQuestion.note;\n base.showNote = normalizedQuestion.alternateResponses && normalizedQuestion.alternateResponses.length > 0;\n base.language = normalizedQuestion.language;\n\n log('[model] removing tileSize for the moment.');\n\n base.prompt = normalizedQuestion.promptEnabled ? normalizedQuestion.prompt : null;\n base.config = {\n orientation: normalizedQuestion.orientation || 'vertical',\n includeTargets: normalizedQuestion.placementArea,\n choiceLabelEnabled: normalizedQuestion.choiceLabelEnabled,\n targetLabel: normalizedQuestion.targetLabel,\n choiceLabel: normalizedQuestion.choiceLabel,\n showOrdering: normalizedQuestion.numberedGuides,\n allowSameChoiceInTargets: !normalizedQuestion.removeTilesAfterPlacing,\n };\n\n base.disabled = env.mode !== 'gather';\n\n if (!base.note) {\n base.note = translator.t('common:commonCorrectAnswerWithAlternates', { lng: normalizedQuestion.language });\n }\n\n if (env.role === 'instructor' && (env.mode === 'view' || env.mode === 'evaluate')) {\n base.rationale = normalizedQuestion.rationaleEnabled ? normalizedQuestion.rationale : null;\n base.teacherInstructions = normalizedQuestion.teacherInstructionsEnabled\n ? normalizedQuestion.teacherInstructions\n : null;\n } else {\n base.rationale = null;\n base.teacherInstructions = null;\n }\n\n if (env.mode === 'evaluate') {\n const value = (session && session.value) || [];\n const allCorrectResponses = getAllCorrectResponses(normalizedQuestion);\n\n const bestSetOfResponses = allCorrectResponses.reduce(\n (info, cr) => {\n const currentScore = _.reduce(value, (acc, c, idx) => acc + (Array.isArray(cr) && cr[idx] === c ? 1 : 0), 0);\n\n if (currentScore > info.score) {\n return {\n arr: cr,\n score: currentScore,\n };\n }\n\n return info;\n },\n { arr: [], score: 0 },\n );\n\n base.outcomes = _.map(value, (c, idx) => {\n return {\n id: c,\n outcome: bestSetOfResponses.arr[idx] === c ? 'correct' : 'incorrect',\n };\n });\n\n const isResponseCorrect = allCorrectResponses.some((response) => _.isEqual(response, value));\n const responseScore = score(question, session);\n const isCorrect = responseScore === 1;\n const isPartialCorrect =\n !isCorrect && partialScoring.enabled(normalizedQuestion, env || {}) && responseScore !== 0;\n\n base.correctness = isCorrect ? 'correct' : isPartialCorrect ? 'partial' : 'incorrect';\n\n if (!isResponseCorrect) {\n base.correctResponse = flattenCorrect(normalizedQuestion);\n }\n\n // requirement made in PD-2182\n if (!normalizedQuestion.feedback) {\n normalizedQuestion.feedbackEnabled = false;\n }\n\n const feedback = normalizedQuestion.feedbackEnabled\n ? await getFeedbackForCorrectness(base.correctness, normalizedQuestion.feedback)\n : undefined;\n\n base.feedback = feedback;\n return base;\n } else {\n return base;\n }\n}\n\nexport const createCorrectResponseSession = (question, env) => {\n return new Promise((resolve) => {\n if (env.mode !== 'evaluate' && env.role === 'instructor') {\n resolve({\n id: '1',\n value: flattenCorrect(question),\n });\n } else {\n resolve(null);\n }\n });\n};\n\n// remove all html tags\nconst getInnerText = (html) => (html || '').replaceAll(/<[^>]*>/g, '');\n\n// remove all html tags except img, iframe and source tag for audio\nconst getContent = (html) => (html || '').replace(/(<(?!img|iframe|source)([^>]+)>)/gi, '');\n\nexport const validate = (model = {}, config = {}) => {\n const { choices, correctResponse } = model;\n const errors = {};\n\n ['teacherInstructions', 'prompt', 'rationale'].forEach((field) => {\n if (config[field]?.required && !getContent(model[field])) {\n errors[field] = 'This field is required.';\n }\n });\n\n const reversedChoices = [...(choices || [])].reverse();\n const choicesErrors = {};\n\n reversedChoices.forEach((choice, index) => {\n const { id, label } = choice;\n\n if (!getContent(label)) {\n choicesErrors[id] = 'Content should not be empty.';\n } else {\n const identicalAnswer = reversedChoices.slice(index + 1).some((c) => c.label === label);\n\n if (identicalAnswer) {\n choicesErrors[id] = 'Content should be unique.';\n }\n }\n });\n\n const choicesIds = (choices || []).map((choice) => choice.id);\n const correctResponseIds = (correctResponse || []).map((response) => response.id || response);\n\n if (isEqual(choicesIds, correctResponseIds)) {\n errors.orderError = 'The correct ordering should not be identical to the initial ordering.';\n }\n\n if (!isEmpty(choicesErrors)) {\n errors.choicesErrors = choicesErrors;\n }\n\n return errors;\n};\n"],"mappings":";;;;;;;;;;;;AAAA,IAAAA,QAAA,GAAAC,OAAA;AAEA,IAAAC,OAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,SAAA,GAAAH,OAAA;AACA,IAAAI,gBAAA,GAAAJ,OAAA;AACA,IAAAK,MAAA,GAAAH,sBAAA,CAAAF,OAAA;AAEA,IAAAM,SAAA,GAAAJ,sBAAA,CAAAF,OAAA;AACA,IAAAO,QAAA,GAAAL,sBAAA,CAAAF,OAAA;AACA,IAAAQ,QAAA,GAAAN,sBAAA,CAAAF,OAAA;AAGA,IAAAS,WAAA,GAAAP,sBAAA,CAAAF,OAAA;AADA,MAAMU,GAAG,GAAG,IAAAC,cAAK,EAAC,4CAA4C,CAAC;AAG/D,MAAM;EAAEC;AAAW,CAAC,GAAGC,mBAAU;AAE1B,MAAMC,aAAa,GAAGA,CAAA,KAAM,IAAIC,KAAK,CAAC,qDAAqD,CAAC;AAACC,OAAA,CAAAF,aAAA,GAAAA,aAAA;AAE7F,SAASG,OAAOA,CAACC,QAAQ,EAAEC,OAAO,EAAEC,GAAG,EAAE;EAC9C,OAAO,IAAIC,OAAO,CAAC,CAACC,OAAO,EAAEC,MAAM,KAAK;IACtC,IAAI,CAACJ,OAAO,IAAIK,eAAC,CAACC,OAAO,CAACN,OAAO,CAAC,EAAE;MAClCG,OAAO,CAAC;QAAEI,KAAK,EAAE,CAAC;QAAEC,KAAK,EAAE;MAAK,CAAC,CAAC;IACpC;IAEA,IAAI,CAACT,QAAQ,IAAI,CAACA,QAAQ,CAACU,eAAe,IAAIJ,eAAC,CAACC,OAAO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EAEA,OAAON,MAAM;AACf,CAAC;AAAClG,OAAA,CAAAiG,QAAA,GAAAA,QAAA","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"index.js","names":["_scoring","require","_lodashEs","_feedback","_controllerUtils","_debug","_interopRequireDefault","_defaults","_translator","log","debug","translator","Translator","questionError","Error","exports","outcome","question","session","env","Promise","resolve","reject","isEmpty","score","empty","correctResponse","s","finalScore","partialScoring","enabled","e","createDefaultModel","model","defaults","normalize","rationaleEnabled","feedbackEnabled","promptEnabled","teacherInstructionsEnabled","studentInstructionsEnabled","normalizedQuestion","base","alternateResponses","every","isArray","console","error","extraCSSRules","outcomes","completeLength","length","choices","filter","choice","label","note","showNote","language","prompt","config","orientation","includeTargets","placementArea","choiceLabelEnabled","targetLabel","choiceLabel","showOrdering","numberedGuides","allowSameChoiceInTargets","removeTilesAfterPlacing","disabled","mode","t","lng","role","rationale","teacherInstructions","value","allCorrectResponses","getAllCorrectResponses","bestSetOfResponses","reduce","info","cr","currentScore","acc","c","idx","Array","arr","map","id","isResponseCorrect","some","response","isEqual","responseScore","isCorrect","isPartialCorrect","correctness","flattenCorrect","feedback","getFeedbackForCorrectness","undefined","createCorrectResponseSession","getInnerText","html","replaceAll","getContent","replace","validate","errors","forEach","field","required","reversedChoices","reverse","choicesErrors","index","identicalAnswer","slice","choicesIds","correctResponseIds","orderError"],"sources":["../src/index.js"],"sourcesContent":["import { flattenCorrect, getAllCorrectResponses, score } from './scoring';\n\nimport { every, isArray, isEmpty, isEqual, map, reduce } from 'lodash-es';\nimport { getFeedbackForCorrectness } from '@pie-lib/feedback';\nimport { partialScoring } from '@pie-lib/controller-utils';\nimport debug from 'debug';\n\nimport defaults from './defaults';\n\nconst log = debug('@pie-element:placement-ordering:controller');\nimport Translator from '@pie-lib/translator';\n\nconst { translator } = Translator;\n\nexport const questionError = () => new Error('Question is missing required array: correctResponse');\n\nexport function outcome(question, session, env) {\n return new Promise((resolve, reject) => {\n if (!session || isEmpty(session)) {\n resolve({ score: 0, empty: true });\n }\n\n if (!question || !question.correctResponse || isEmpty(question.correctResponse)) {\n reject(questionError());\n } else {\n try {\n const s = score(question, session);\n const finalScore = partialScoring.enabled(question, env || {}) ? s : s === 1 ? 1 : 0;\n resolve({\n score: finalScore,\n });\n } catch (e) {\n reject(e);\n }\n }\n });\n}\n\nexport function createDefaultModel(model = {}) {\n return new Promise((resolve) => {\n resolve({\n ...defaults,\n ...model,\n });\n });\n}\n\nexport const normalize = (question) => ({\n ...defaults,\n rationaleEnabled: true,\n feedbackEnabled: false,\n promptEnabled: true,\n teacherInstructionsEnabled: true,\n studentInstructionsEnabled: true,\n ...question,\n});\n\n/**\n *\n * @param {*} question\n * @param {*} session\n * @param {*} env\n */\nexport async function model(question, session, env) {\n const normalizedQuestion = normalize(question);\n const base = {};\n\n if (question.alternateResponses && every(question.alternateResponses, isArray)) {\n log('Deprecated structure of alternateResponses is in use');\n // eslint-disable-next-line no-console\n console.error('Deprecated structure of alternateResponses is in use');\n }\n\n base.env = env;\n base.extraCSSRules = normalizedQuestion.extraCSSRules;\n base.outcomes = [];\n base.completeLength = (normalizedQuestion.correctResponse || []).length;\n base.choices = (normalizedQuestion.choices || []).filter((choice) => choice.label);\n base.note = normalizedQuestion.note;\n base.showNote = normalizedQuestion.alternateResponses && normalizedQuestion.alternateResponses.length > 0;\n base.language = normalizedQuestion.language;\n\n log('[model] removing tileSize for the moment.');\n\n base.prompt = normalizedQuestion.promptEnabled ? normalizedQuestion.prompt : null;\n base.config = {\n orientation: normalizedQuestion.orientation || 'vertical',\n includeTargets: normalizedQuestion.placementArea,\n choiceLabelEnabled: normalizedQuestion.choiceLabelEnabled,\n targetLabel: normalizedQuestion.targetLabel,\n choiceLabel: normalizedQuestion.choiceLabel,\n showOrdering: normalizedQuestion.numberedGuides,\n allowSameChoiceInTargets: !normalizedQuestion.removeTilesAfterPlacing,\n };\n\n base.disabled = env.mode !== 'gather';\n\n if (!base.note) {\n base.note = translator.t('common:commonCorrectAnswerWithAlternates', { lng: normalizedQuestion.language });\n }\n\n if (env.role === 'instructor' && (env.mode === 'view' || env.mode === 'evaluate')) {\n base.rationale = normalizedQuestion.rationaleEnabled ? normalizedQuestion.rationale : null;\n base.teacherInstructions = normalizedQuestion.teacherInstructionsEnabled\n ? normalizedQuestion.teacherInstructions\n : null;\n } else {\n base.rationale = null;\n base.teacherInstructions = null;\n }\n\n if (env.mode === 'evaluate') {\n const value = (session && session.value) || [];\n const allCorrectResponses = getAllCorrectResponses(normalizedQuestion);\n\n const bestSetOfResponses = allCorrectResponses.reduce(\n (info, cr) => {\n const currentScore = reduce(value, (acc, c, idx) => acc + (Array.isArray(cr) && cr[idx] === c ? 1 : 0), 0);\n\n if (currentScore > info.score) {\n return {\n arr: cr,\n score: currentScore,\n };\n }\n\n return info;\n },\n { arr: [], score: 0 },\n );\n\n base.outcomes = map(value, (c, idx) => {\n return {\n id: c,\n outcome: bestSetOfResponses.arr[idx] === c ? 'correct' : 'incorrect',\n };\n });\n\n const isResponseCorrect = allCorrectResponses.some((response) => isEqual(response, value));\n const responseScore = score(question, session);\n const isCorrect = responseScore === 1;\n const isPartialCorrect = !isCorrect && partialScoring.enabled(normalizedQuestion, env || {}) && responseScore !== 0;\n\n base.correctness = isCorrect ? 'correct' : isPartialCorrect ? 'partial' : 'incorrect';\n\n if (!isResponseCorrect) {\n base.correctResponse = flattenCorrect(normalizedQuestion);\n }\n\n // requirement made in PD-2182\n if (!normalizedQuestion.feedback) {\n normalizedQuestion.feedbackEnabled = false;\n }\n\n const feedback = normalizedQuestion.feedbackEnabled\n ? await getFeedbackForCorrectness(base.correctness, normalizedQuestion.feedback)\n : undefined;\n\n base.feedback = feedback;\n return base;\n } else {\n return base;\n }\n}\n\nexport const createCorrectResponseSession = (question, env) => {\n return new Promise((resolve) => {\n if (env.mode !== 'evaluate' && env.role === 'instructor') {\n resolve({\n id: '1',\n value: flattenCorrect(question),\n });\n } else {\n resolve(null);\n }\n });\n};\n\n// remove all html tags\nconst getInnerText = (html) => (html || '').replaceAll(/<[^>]*>/g, '');\n\n// remove all html tags except img, iframe and source tag for audio\nconst getContent = (html) => (html || '').replace(/(<(?!img|iframe|source)([^>]+)>)/gi, '');\n\nexport const validate = (model = {}, config = {}) => {\n const { choices, correctResponse } = model;\n const errors = {};\n\n ['teacherInstructions', 'prompt', 'rationale'].forEach((field) => {\n if (config[field]?.required && !getContent(model[field])) {\n errors[field] = 'This field is required.';\n }\n });\n\n const reversedChoices = [...(choices || [])].reverse();\n const choicesErrors = {};\n\n reversedChoices.forEach((choice, index) => {\n const { id, label } = choice;\n\n if (!getContent(label)) {\n choicesErrors[id] = 'Content should not be empty.';\n } else {\n const identicalAnswer = reversedChoices.slice(index + 1).some((c) => c.label === label);\n\n if (identicalAnswer) {\n choicesErrors[id] = 'Content should be unique.';\n }\n }\n });\n\n const choicesIds = (choices || []).map((choice) => choice.id);\n const correctResponseIds = (correctResponse || []).map((response) => response.id || response);\n\n if (isEqual(choicesIds, correctResponseIds)) {\n errors.orderError = 'The correct ordering should not be identical to the initial ordering.';\n }\n\n if (!isEmpty(choicesErrors)) {\n errors.choicesErrors = choicesErrors;\n }\n\n return errors;\n};\n"],"mappings":";;;;;;;;;;;;AAAA,IAAAA,QAAA,GAAAC,OAAA;AAEA,IAAAC,SAAA,GAAAD,OAAA;AACA,IAAAE,SAAA,GAAAF,OAAA;AACA,IAAAG,gBAAA,GAAAH,OAAA;AACA,IAAAI,MAAA,GAAAC,sBAAA,CAAAL,OAAA;AAEA,IAAAM,SAAA,GAAAD,sBAAA,CAAAL,OAAA;AAGA,IAAAO,WAAA,GAAAF,sBAAA,CAAAL,OAAA;AADA,MAAMQ,GAAG,GAAG,IAAAC,cAAK,EAAC,4CAA4C,CAAC;AAG/D,MAAM;EAAEC;AAAW,CAAC,GAAGC,mBAAU;AAE1B,MAAMC,aAAa,GAAGA,CAAA,KAAM,IAAIC,KAAK,CAAC,qDAAqD,CAAC;AAACC,OAAA,CAAAF,aAAA,GAAAA,aAA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AAG,CAACjG,eAAe,IAAI,EAAE,EAAEiE,GAAG,CAAEI,QAAQ,IAAKA,QAAQ,CAACH,EAAE,IAAIG,QAAQ,CAAC;EAE7F,IAAI,IAAAC,iBAAO,EAAC0B,UAAU,EAAEC,kBAAkB,CAAC,EAAE;IAC3CX,MAAM,CAACY,UAAU,GAAG,uEAAuE;EAC7F;EAEA,IAAI,CAAC,IAAArG,iBAAO,EAAC+F,aAAa,CAAC,EAAE;IAC3BN,MAAM,CAACM,aAAa,GAAGA,aAAa;EACtC;EAEA,OAAON,MAAM;AACf,CAAC;AAACjG,OAAA,CAAAgG,QAAA,GAAAA,QAAA","ignoreList":[]}
|
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.score = exports.pairwiseCombinationScore = exports.illegalArgumentError = exports.getAllCorrectResponses = exports.flattenCorrect = void 0;
|
|
8
|
-
var
|
|
8
|
+
var _lodashEs = require("lodash-es");
|
|
9
9
|
var _jsCombinatorics = require("js-combinatorics");
|
|
10
10
|
var _debug = _interopRequireDefault(require("debug"));
|
|
11
11
|
const log = (0, _debug.default)('pie-elements:placement-ordering:controller');
|
|
@@ -17,19 +17,19 @@ const pairwiseCombinationScore = (correct, answer, opts) => {
|
|
|
17
17
|
orderMustBeComplete: false,
|
|
18
18
|
...opts
|
|
19
19
|
};
|
|
20
|
-
if (!opts.allowDuplicates && !
|
|
20
|
+
if (!opts.allowDuplicates && !(0, _lodashEs.isEqual)((0, _lodashEs.uniq)(correct), correct)) {
|
|
21
21
|
throw illegalArgumentError(answer);
|
|
22
22
|
}
|
|
23
|
-
if (opts.allowDuplicates === false && answer.length !==
|
|
23
|
+
if (opts.allowDuplicates === false && answer.length !== (0, _lodashEs.uniq)(answer).length) {
|
|
24
24
|
return 0;
|
|
25
25
|
}
|
|
26
|
-
answer = opts.allowDuplicates !== false ? answer :
|
|
26
|
+
answer = opts.allowDuplicates !== false ? answer : (0, _lodashEs.uniq)(answer);
|
|
27
27
|
log('answer:', answer);
|
|
28
28
|
if (!Array.isArray(correct) || correct.length === 0) {
|
|
29
29
|
throw new Error('correct must be non empty an array');
|
|
30
30
|
}
|
|
31
31
|
if (correct.length === 1) {
|
|
32
|
-
return
|
|
32
|
+
return (0, _lodashEs.isEqual)(correct, answer) ? 1 : 0;
|
|
33
33
|
}
|
|
34
34
|
if (!Array.isArray(answer) || answer.length < 2) {
|
|
35
35
|
return 0;
|
|
@@ -42,7 +42,7 @@ const pairwiseCombinationScore = (correct, answer, opts) => {
|
|
|
42
42
|
}
|
|
43
43
|
const correctCombo = (0, _jsCombinatorics.combination)(correct, 2).toArray();
|
|
44
44
|
const answerCombo = (0, _jsCombinatorics.combination)(answer, 2).toArray();
|
|
45
|
-
const diff =
|
|
45
|
+
const diff = (0, _lodashEs.differenceWith)(answerCombo, correctCombo, _lodashEs.isEqual);
|
|
46
46
|
const comboLengthDiff = correctCombo.length - answerCombo.length;
|
|
47
47
|
const total = correctCombo.length;
|
|
48
48
|
const actual = total - diff.length - comboLengthDiff;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scoring.js","names":["
|
|
1
|
+
{"version":3,"file":"scoring.js","names":["_lodashEs","require","_jsCombinatorics","_debug","_interopRequireDefault","log","debug","illegalArgumentError","answer","Error","exports","pairwiseCombinationScore","correct","opts","allowDuplicates","orderMustBeComplete","isEqual","uniq","length","Array","isArray","correctCombo","combination","toArray","answerCombo","diff","differenceWith","comboLengthDiff","total","actual","n","toFixed","parseFloat","flattenCorrect","question","correctResponse","map","r","id","getAllCorrectResponses","alternates","alternateResponses","alternate","response","filter","item","undefined","score","session","value","allCorrectResponse","configure","removeTilesAfterPlacing","bestScore","forEach","cr","currentScore"],"sources":["../src/scoring.js"],"sourcesContent":["import { differenceWith, isEqual, uniq } from 'lodash-es';\nimport { combination } from 'js-combinatorics';\nimport debug from 'debug';\n\nconst log = debug('pie-elements:placement-ordering:controller');\n\nexport const illegalArgumentError = (answer) =>\n new Error(`Cant score answer: ${answer} it has duplicates and allowDuplicates is false`);\nexport const pairwiseCombinationScore = (correct, answer, opts) => {\n opts = { allowDuplicates: false, orderMustBeComplete: false, ...opts };\n\n if (!opts.allowDuplicates && !isEqual(uniq(correct), correct)) {\n throw illegalArgumentError(answer);\n }\n\n if (opts.allowDuplicates === false && answer.length !== uniq(answer).length) {\n return 0;\n }\n\n answer = opts.allowDuplicates !== false ? answer : uniq(answer);\n\n log('answer:', answer);\n if (!Array.isArray(correct) || correct.length === 0) {\n throw new Error('correct must be non empty an array');\n }\n\n if (correct.length === 1) {\n return isEqual(correct, answer) ? 1 : 0;\n }\n\n if (!Array.isArray(answer) || answer.length < 2) {\n return 0;\n }\n\n if (answer.length > correct.length) {\n return 0;\n }\n\n if (correct.length !== answer.length && opts.orderMustBeComplete) {\n return 0;\n }\n\n const correctCombo = combination(correct, 2).toArray();\n const answerCombo = combination(answer, 2).toArray();\n\n const diff = differenceWith(answerCombo, correctCombo, isEqual);\n\n const comboLengthDiff = correctCombo.length - answerCombo.length;\n\n const total = correctCombo.length;\n const actual = total - diff.length - comboLengthDiff;\n\n const n = (actual / total).toFixed(2);\n\n return parseFloat(n);\n};\n\n/**\n * Flattens the correctResponse into an array of ordered identifiers representing the\n * correct response.\n */\nexport const flattenCorrect = (question) =>\n question.correctResponse ? question.correctResponse.map((r) => (r && r.id ? r.id : r)) : [];\n\n/**\n * Returns all correct responses for this question\n * @param question - array\n */\nexport const getAllCorrectResponses = (question) => {\n const alternates = (question.alternateResponses || [])\n .map((alternate) => {\n if (Array.isArray(alternate)) {\n return alternate;\n }\n\n return alternate.response;\n })\n .filter((item) => item !== undefined);\n\n return [flattenCorrect(question), ...alternates];\n};\n\n/**\n * Returns the score for a session. If weighted scoring is present in the correctResponse\n * field for the question, this will be used. If partial scoring is present in the question\n * model, this will be used. Otherwise the default scoring mechanism (0 for any incorrect, 1\n * for all correct) will be used.\n */\n\nexport const score = (question, session) => {\n const { value } = session || {};\n\n if (!value) {\n return 0;\n }\n\n const allCorrectResponse = getAllCorrectResponses(question);\n const allowDuplicates = (question.configure && question.configure.removeTilesAfterPlacing) !== false;\n\n /**\n * We require this to be the case - locking\n */\n //const orderMustBeComplete = true;\n\n let bestScore = 0;\n\n allCorrectResponse.forEach((cr) => {\n const currentScore = pairwiseCombinationScore(cr, value, {\n allowDuplicates,\n });\n\n if (currentScore >= bestScore) {\n bestScore = currentScore;\n }\n });\n\n return bestScore;\n};\n"],"mappings":";;;;;;;AAAA,IAAAA,SAAA,GAAAC,OAAA;AACA,IAAAC,gBAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAC,sBAAA,CAAAH,OAAA;AAEA,MAAMI,GAAG,GAAG,IAAAC,cAAK,EAAC,4CAA4C,CAAC;AAExD,MAAMC,oBAAoB,GAAIC,MAAM,IACzC,IAAIC,KAAK,CAAC,sBAAsBD,MAAM,iDAAiD,CAAC;AAACE,OAAA,CAAAH,oBAAA,GAAAA,oBAAA;AACpF,MAAMI,wBAAwB,GAAGA,CAACC,OAAO,EAAEJ,MAAM,EAAEK,IAAI,KAAK;EACjEA,IAAI,GAAG;IAAEC,eAAe,EAAE,KAAK;IAAEC,mBAAmB,EAAE,KAAK;IAAE,GAAGF;EAAK,CAAC;EAEtE,IAAI,CAACA,IAAI,CAACC,eAAe,IAAI,CAAC,IAAAE,iBAAO,EAAC,IAAAC,cAAI,EAACL,OAAO,CAAC,EAAEA,OAAO,CAAC,EAAE;IAC7D,MAAML,oBAAoB,CAACC,MAAM,CAAC;EACpC;EAEA,IAAIK,IAAI,CAACC,eAAe,KAAK,KAAK,IAAIN,MAAM,CAACU,MAAM,KAAK,IAAAD,cAAI,EAACT,MAAM,CAAC,CAACU,MAAM,EAAE;IAC3E,OAAO,CAAC;EACV;EAEAV,MAAM,GAAGK,IAAI,CAACC,eAAe,KAAK,KAAK,GAAGN,MAAM,GAAG,IAAAS,cAAI,EAACT,MAAM,CAAC;EAE/DH,GAAG,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H,kBAAkB,CAACI,OAAO,CAAEC,EAAE,IAAK;IACjC,MAAMC,YAAY,GAAG7C,wBAAwB,CAAC4C,EAAE,EAAEN,KAAK,EAAE;MACvDnC;IACF,CAAC,CAAC;IAEF,IAAI0C,YAAY,IAAIH,SAAS,EAAE;MAC7BA,SAAS,GAAGG,YAAY;IAC1B;EACF,CAAC,CAAC;EAEF,OAAOH,SAAS;AAClB,CAAC;AAAC3C,OAAA,CAAAqC,KAAA,GAAAA,KAAA","ignoreList":[]}
|
package/controller/package.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pie-element/placement-ordering-controller",
|
|
3
|
-
"version": "10.0.0-beta.
|
|
3
|
+
"version": "10.0.0-beta.1",
|
|
4
4
|
"private": true,
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "src/index.js",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@pie-lib/controller-utils": "
|
|
9
|
-
"@pie-lib/feedback": "
|
|
10
|
-
"@pie-lib/translator": "
|
|
11
|
-
"debug": "^
|
|
8
|
+
"@pie-lib/controller-utils": "1.1.1-next.1",
|
|
9
|
+
"@pie-lib/feedback": "1.1.1-next.1",
|
|
10
|
+
"@pie-lib/translator": "3.1.1-next.1",
|
|
11
|
+
"debug": "^4.1.1",
|
|
12
12
|
"js-combinatorics": "^0.5.4",
|
|
13
|
-
"lodash": "^4.17.
|
|
13
|
+
"lodash-es": "^4.17.23"
|
|
14
14
|
}
|
|
15
15
|
}
|
package/lib/index.js
CHANGED
|
@@ -8,7 +8,7 @@ exports.isValidSession = exports.default = void 0;
|
|
|
8
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
9
|
var _react = _interopRequireDefault(require("react"));
|
|
10
10
|
var _client = require("react-dom/client");
|
|
11
|
-
var
|
|
11
|
+
var _lodashEs = require("lodash-es");
|
|
12
12
|
var _debug = _interopRequireDefault(require("debug"));
|
|
13
13
|
var _mathRendering = require("@pie-lib/math-rendering");
|
|
14
14
|
var _piePlayerEvents = require("@pie-framework/pie-player-events");
|
|
@@ -21,7 +21,7 @@ const isValidSession = ({
|
|
|
21
21
|
const {
|
|
22
22
|
config
|
|
23
23
|
} = model;
|
|
24
|
-
const compactSessionValues = session && (0,
|
|
24
|
+
const compactSessionValues = session && (0, _lodashEs.compact)(session.value) || [];
|
|
25
25
|
const completeSession = compactSessionValues.length === model.choices.length;
|
|
26
26
|
|
|
27
27
|
// if it includes targets, it doesn't have to contain all the choices selected (eg: only 2 targets were filled)
|
|
@@ -32,7 +32,7 @@ exports.isValidSession = isValidSession;
|
|
|
32
32
|
class Ordering extends HTMLElement {
|
|
33
33
|
constructor() {
|
|
34
34
|
super();
|
|
35
|
-
(0, _defineProperty2.default)(this, "isComplete", value => value && (0,
|
|
35
|
+
(0, _defineProperty2.default)(this, "isComplete", value => value && (0, _lodashEs.compact)(value).length === this._model.completeLength);
|
|
36
36
|
(0, _defineProperty2.default)(this, "sessionChange", session => {
|
|
37
37
|
this._session.value = session.value;
|
|
38
38
|
this.render();
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["_react","_interopRequireDefault","require","_client","
|
|
1
|
+
{"version":3,"file":"index.js","names":["_react","_interopRequireDefault","require","_client","_lodashEs","_debug","_mathRendering","_piePlayerEvents","_main","log","debug","isValidSession","model","session","config","compactSessionValues","compact","value","completeSession","length","choices","includeTargets","exports","Ordering","HTMLElement","constructor","_defineProperty2","default","_model","completeLength","_session","render","dispatchEvent","SessionChangedEvent","tagName","toLowerCase","isComplete","_root","newModel","CustomEvent","bubbles","detail","complete","newSession","element","React","createElement","Main","onSessionChange","sessionChange","createRoot","queueMicrotask","renderMath","disconnectedCallback","unmount"],"sources":["../src/index.js"],"sourcesContent":["import React from 'react';\nimport { createRoot } from 'react-dom/client';\nimport { compact } from 'lodash-es';\nimport debug from 'debug';\nimport { renderMath } from '@pie-lib/math-rendering';\nimport { SessionChangedEvent } from '@pie-framework/pie-player-events';\nimport Main from './main';\n\nconst log = debug('pie-elements:placement-ordering');\n\nexport const isValidSession = ({ model, session }) => {\n const { config } = model;\n\n const compactSessionValues = (session && compact(session.value)) || [];\n const completeSession = compactSessionValues.length === model.choices.length;\n\n // if it includes targets, it doesn't have to contain all the choices selected (eg: only 2 targets were filled)\n // but if it does not include targets, it's a must to have all choices selected\n return config.includeTargets || completeSession;\n};\n\nexport default class Ordering extends HTMLElement {\n constructor() {\n super();\n this._root = null;\n }\n\n isComplete = (value) => value && compact(value).length === this._model.completeLength;\n\n sessionChange = (session) => {\n this._session.value = session.value;\n this.render();\n this.dispatchEvent(\n new SessionChangedEvent(this.tagName.toLowerCase(), this._session && this.isComplete(this._session.value)),\n );\n };\n\n set model(newModel) {\n this._model = newModel;\n\n this.render();\n this.dispatchEvent(\n new CustomEvent('model-set', {\n bubbles: true,\n detail: {\n complete: false,\n },\n }),\n );\n }\n\n set session(newSession) {\n this._session = newSession;\n this.render();\n }\n\n get session() {\n return this._session;\n }\n\n render() {\n if (this._model && this._session) {\n log('[render] session: ', this._session.value);\n log('[render] model: ', this._model);\n\n const element = React.createElement(Main, {\n model: this._model,\n session: this._session,\n onSessionChange: this.sessionChange,\n });\n\n if (!this._root) {\n this._root = createRoot(this);\n }\n this._root.render(element);\n queueMicrotask(() => {\n renderMath(this);\n });\n }\n }\n\n disconnectedCallback() {\n if (this._root) {\n this._root.unmount();\n }\n }\n}\n"],"mappings":";;;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,SAAA,GAAAF,OAAA;AACA,IAAAG,MAAA,GAAAJ,sBAAA,CAAAC,OAAA;AACA,IAAAI,cAAA,GAAAJ,OAAA;AACA,IAAAK,gBAAA,GAAAL,OAAA;AACA,IAAAM,KAAA,GAAAP,sBAAA,CAAAC,OAAA;AAEA,MAAMO,GAAG,G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@@ exports.buildState = buildState;
|
|
|
8
8
|
exports.push = void 0;
|
|
9
9
|
exports.reducer = reducer;
|
|
10
10
|
exports.swap = void 0;
|
|
11
|
-
var
|
|
11
|
+
var _lodashEs = require("lodash-es");
|
|
12
12
|
var _debug = _interopRequireDefault(require("debug"));
|
|
13
|
-
var _isEmpty = _interopRequireDefault(require("lodash/isEmpty"));
|
|
14
|
-
var _map = _interopRequireDefault(require("lodash/map"));
|
|
15
|
-
var _assign = _interopRequireDefault(require("lodash/assign"));
|
|
16
13
|
const log = (0, _debug.default)('pie-elements:placement-ordering:ordering');
|
|
17
14
|
const push = (arr, fromIndex, toIndex) => {
|
|
18
15
|
const movedItem = arr.find((item, index) => index === fromIndex);
|
|
@@ -25,7 +22,7 @@ const swap = (arr, fromIndex, toIndex) => {
|
|
|
25
22
|
if (!arr || arr.length <= 1 || fromIndex === undefined || toIndex === undefined) {
|
|
26
23
|
throw new Error(`swap requires a non-empty array, fromIndex, toIndex: ${arr}, ${fromIndex} ${toIndex}`);
|
|
27
24
|
}
|
|
28
|
-
const update = (0,
|
|
25
|
+
const update = (0, _lodashEs.cloneDeep)(arr);
|
|
29
26
|
const tmp = arr[toIndex];
|
|
30
27
|
update[toIndex] = update[fromIndex];
|
|
31
28
|
update[fromIndex] = tmp;
|
|
@@ -33,7 +30,7 @@ const swap = (arr, fromIndex, toIndex) => {
|
|
|
33
30
|
};
|
|
34
31
|
exports.swap = swap;
|
|
35
32
|
function removeResponse(state, targetTile) {
|
|
36
|
-
const update = (0,
|
|
33
|
+
const update = (0, _lodashEs.cloneDeep)(state.response);
|
|
37
34
|
if (update[targetTile.index] === targetTile.id) {
|
|
38
35
|
update[targetTile.index] = undefined;
|
|
39
36
|
} else {
|
|
@@ -46,7 +43,7 @@ function updateResponse(state, from, to) {
|
|
|
46
43
|
response,
|
|
47
44
|
opts
|
|
48
45
|
} = state;
|
|
49
|
-
const update = (0,
|
|
46
|
+
const update = (0, _lodashEs.cloneDeep)(response);
|
|
50
47
|
if (opts.includeTargets) {
|
|
51
48
|
if (from.type === 'choice' && to.type === 'target') {
|
|
52
49
|
update[to.index] = from.id;
|
|
@@ -122,11 +119,11 @@ function buildTiles(choices, response, outcomes, opts) {
|
|
|
122
119
|
}
|
|
123
120
|
}
|
|
124
121
|
function buildState(choices, response, outcomes, opts) {
|
|
125
|
-
opts = (0,
|
|
122
|
+
opts = (0, _lodashEs.assign)({
|
|
126
123
|
includeTargets: true
|
|
127
124
|
}, opts);
|
|
128
125
|
outcomes = outcomes || [];
|
|
129
|
-
response = !response || (0,
|
|
126
|
+
response = !response || (0, _lodashEs.isEmpty)(response) ? opts.includeTargets ? new Array(choices.length) : (0, _lodashEs.map)(choices, c => c.id) : response;
|
|
130
127
|
return {
|
|
131
128
|
choices,
|
|
132
129
|
response,
|