@pie-lib/controller-utils 0.20.0 → 0.22.0-mui-update.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 CHANGED
@@ -3,7 +3,7 @@
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
- # [0.20.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/controller-utils@0.18.0...@pie-lib/controller-utils@0.20.0) (2025-10-16)
6
+ # [0.22.0-mui-update.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/controller-utils@0.21.0-mui-update.0...@pie-lib/controller-utils@0.22.0-mui-update.0) (2025-11-03)
7
7
 
8
8
  **Note:** Version bump only for package @pie-lib/controller-utils
9
9
 
@@ -11,7 +11,15 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
11
11
 
12
12
 
13
13
 
14
- # [0.19.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/controller-utils@0.18.0...@pie-lib/controller-utils@0.19.0) (2025-10-16)
14
+ # [0.21.0-mui-update.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/controller-utils@0.19.0-mui-update.0...@pie-lib/controller-utils@0.21.0-mui-update.0) (2025-11-03)
15
+
16
+ **Note:** Version bump only for package @pie-lib/controller-utils
17
+
18
+
19
+
20
+
21
+
22
+ # [0.19.0-mui-update.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/controller-utils@0.18.0...@pie-lib/controller-utils@0.19.0-mui-update.0) (2025-10-31)
15
23
 
16
24
  **Note:** Version bump only for package @pie-lib/controller-utils
17
25
 
package/lib/index.js CHANGED
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
 
3
3
  var _typeof = require("@babel/runtime/helpers/typeof");
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
@@ -18,14 +17,8 @@ Object.defineProperty(exports, "lockChoices", {
18
17
  }
19
18
  });
20
19
  exports.partialScoring = void 0;
21
-
22
20
  var partialScoring = _interopRequireWildcard(require("./partial-scoring"));
23
-
24
21
  exports.partialScoring = partialScoring;
25
-
26
22
  var _persistence = require("./persistence");
27
-
28
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
29
-
30
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
23
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
31
24
  //# sourceMappingURL=index.js.map
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;;;AAEA","sourcesContent":["import * as partialScoring from './partial-scoring';\n\nexport { lockChoices, getShuffledChoices } from './persistence';\nexport { partialScoring };\n"],"file":"index.js"}
1
+ {"version":3,"file":"index.js","names":["partialScoring","_interopRequireWildcard","require","exports","_persistence","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","_typeof","has","get","set","_t","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor"],"sources":["../src/index.js"],"sourcesContent":["import * as partialScoring from './partial-scoring';\n\nexport { lockChoices, getShuffledChoices } from './persistence';\nexport { partialScoring };\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA,IAAAA,cAAA,GAAAC,uBAAA,CAAAC,OAAA;AAAoDC,OAAA,CAAAH,cAAA,GAAAA,cAAA;AAEpD,IAAAI,YAAA,GAAAF,OAAA;AAAgE,SAAAD,wBAAAI,CAAA,EAAAC,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAN,uBAAA,YAAAA,wBAAAI,CAAA,EAAAC,CAAA,SAAAA,CAAA,IAAAD,CAAA,IAAAA,CAAA,CAAAK,UAAA,SAAAL,CAAA,MAAAM,CAAA,EAAAC,CAAA,EAAAC,CAAA,KAAAC,SAAA,mBAAAT,CAAA,iBAAAA,CAAA,gBAAAU,OAAA,CAAAV,CAAA,0BAAAA,CAAA,SAAAQ,CAAA,MAAAF,CAAA,GAAAL,CAAA,GAAAG,CAAA,GAAAD,CAAA,QAAAG,CAAA,CAAAK,GAAA,CAAAX,CAAA,UAAAM,CAAA,CAAAM,GAAA,CAAAZ,CAAA,GAAAM,CAAA,CAAAO,GAAA,CAAAb,CAAA,EAAAQ,CAAA,cAAAM,EAAA,IAAAd,CAAA,gBAAAc,EAAA,OAAAC,cAAA,CAAAC,IAAA,CAAAhB,CAAA,EAAAc,EAAA,OAAAP,CAAA,IAAAD,CAAA,GAAAW,MAAA,CAAAC,cAAA,KAAAD,MAAA,CAAAE,wBAAA,CAAAnB,CAAA,EAAAc,EAAA,OAAAP,CAAA,CAAAK,GAAA,IAAAL,CAAA,CAAAM,GAAA,IAAAP,CAAA,CAAAE,CAAA,EAAAM,EAAA,EAAAP,CAAA,IAAAC,CAAA,CAAAM,EAAA,IAAAd,CAAA,CAAAc,EAAA,WAAAN,CAAA,KAAAR,CAAA,EAAAC,CAAA","ignoreList":[]}
@@ -4,8 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.enabled = void 0;
7
-
8
- var enabled = function enabled(config, env, defaultValue) {
7
+ var enabled = exports.enabled = function enabled(config, env, defaultValue) {
9
8
  // if model.partialScoring = false
10
9
  // - if env.partialScoring = false || env.partialScoring = true => use dichotomous scoring
11
10
  // else if model.partialScoring = true || undefined
@@ -13,17 +12,12 @@ var enabled = function enabled(config, env, defaultValue) {
13
12
  // - else if env.partialScoring = true, use partial scoring
14
13
  config = config || {};
15
14
  env = env || {};
16
-
17
15
  if (config.partialScoring === false) {
18
16
  return false;
19
17
  }
20
-
21
18
  if (env.partialScoring === false) {
22
19
  return false;
23
20
  }
24
-
25
21
  return typeof defaultValue === 'boolean' ? defaultValue : true;
26
22
  };
27
-
28
- exports.enabled = enabled;
29
23
  //# sourceMappingURL=partial-scoring.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/partial-scoring.js"],"names":["enabled","config","env","defaultValue","partialScoring"],"mappings":";;;;;;;AAAO,IAAMA,OAAO,GAAG,SAAVA,OAAU,CAACC,MAAD,EAASC,GAAT,EAAcC,YAAd,EAA+B;AACpD;AACA;AACA;AACA;AACA;AACAF,EAAAA,MAAM,GAAGA,MAAM,IAAI,EAAnB;AACAC,EAAAA,GAAG,GAAGA,GAAG,IAAI,EAAb;;AAEA,MAAID,MAAM,CAACG,cAAP,KAA0B,KAA9B,EAAqC;AACnC,WAAO,KAAP;AACD;;AAED,MAAIF,GAAG,CAACE,cAAJ,KAAuB,KAA3B,EAAkC;AAChC,WAAO,KAAP;AACD;;AAED,SAAO,OAAOD,YAAP,KAAwB,SAAxB,GAAoCA,YAApC,GAAmD,IAA1D;AACD,CAlBM","sourcesContent":["export const enabled = (config, env, defaultValue) => {\n // if model.partialScoring = false\n // - if env.partialScoring = false || env.partialScoring = true => use dichotomous scoring\n // else if model.partialScoring = true || undefined\n // - if env.partialScoring = false, use dichotomous scoring\n // - else if env.partialScoring = true, use partial scoring\n config = config || {};\n env = env || {};\n\n if (config.partialScoring === false) {\n return false;\n }\n\n if (env.partialScoring === false) {\n return false;\n }\n\n return typeof defaultValue === 'boolean' ? defaultValue : true;\n};\n"],"file":"partial-scoring.js"}
1
+ {"version":3,"file":"partial-scoring.js","names":["enabled","exports","config","env","defaultValue","partialScoring"],"sources":["../src/partial-scoring.js"],"sourcesContent":["export const enabled = (config, env, defaultValue) => {\n // if model.partialScoring = false\n // - if env.partialScoring = false || env.partialScoring = true => use dichotomous scoring\n // else if model.partialScoring = true || undefined\n // - if env.partialScoring = false, use dichotomous scoring\n // - else if env.partialScoring = true, use partial scoring\n config = config || {};\n env = env || {};\n\n if (config.partialScoring === false) {\n return false;\n }\n\n if (env.partialScoring === false) {\n return false;\n }\n\n return typeof defaultValue === 'boolean' ? defaultValue : true;\n};\n"],"mappings":";;;;;;AAAO,IAAMA,OAAO,GAAAC,OAAA,CAAAD,OAAA,GAAG,SAAVA,OAAOA,CAAIE,MAAM,EAAEC,GAAG,EAAEC,YAAY,EAAK;EACpD;EACA;EACA;EACA;EACA;EACAF,MAAM,GAAGA,MAAM,IAAI,CAAC,CAAC;EACrBC,GAAG,GAAGA,GAAG,IAAI,CAAC,CAAC;EAEf,IAAID,MAAM,CAACG,cAAc,KAAK,KAAK,EAAE;IACnC,OAAO,KAAK;EACd;EAEA,IAAIF,GAAG,CAACE,cAAc,KAAK,KAAK,EAAE;IAChC,OAAO,KAAK;EACd;EAEA,OAAO,OAAOD,YAAY,KAAK,SAAS,GAAGA,YAAY,GAAG,IAAI;AAChE,CAAC","ignoreList":[]}
@@ -1,57 +1,42 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.lockChoices = exports.getShuffledChoices = exports.compact = void 0;
9
-
10
8
  var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
11
-
12
9
  var _get = _interopRequireDefault(require("lodash/get"));
13
-
14
10
  var _shuffle = _interopRequireDefault(require("lodash/shuffle"));
15
-
16
11
  var _isEmpty = _interopRequireDefault(require("lodash/isEmpty"));
17
-
18
12
  // eslint-disable-next-line no-console
19
13
  var lg = function lg(n) {
20
14
  return console[n].bind(console, 'controller-utils:');
21
15
  };
22
-
23
16
  var debug = lg('debug');
24
17
  var log = lg('log');
25
18
  var warn = lg('warn');
26
19
  var error = lg('error');
27
-
28
- var compact = function compact(arr) {
20
+ var compact = exports.compact = function compact(arr) {
29
21
  if (Array.isArray(arr)) {
30
22
  return arr.filter(function (v) {
31
23
  return v !== null && v !== undefined;
32
24
  });
33
25
  }
34
-
35
26
  return arr;
36
27
  };
37
-
38
- exports.compact = compact;
39
-
40
- var getShuffledChoices = function getShuffledChoices(choices, session, updateSession, choiceKey) {
28
+ var getShuffledChoices = exports.getShuffledChoices = function getShuffledChoices(choices, session, updateSession, choiceKey) {
41
29
  return new Promise(function (resolve) {
42
30
  var _session$data;
43
-
44
31
  log('updateSession type: ', (0, _typeof2["default"])(updateSession));
45
32
  log('session: ', session);
46
- var currentShuffled = compact((session === null || session === void 0 ? void 0 : (_session$data = session.data) === null || _session$data === void 0 ? void 0 : _session$data.shuffledValues) || (session === null || session === void 0 ? void 0 : session.shuffledValues) || []);
47
-
33
+ var currentShuffled = compact((session === null || session === void 0 || (_session$data = session.data) === null || _session$data === void 0 ? void 0 : _session$data.shuffledValues) || (session === null || session === void 0 ? void 0 : session.shuffledValues) || []);
48
34
  if (!session) {
49
35
  // eslint-disable-next-line quotes
50
36
  warn("unable to save shuffled choices because there's no session.");
51
37
  resolve(undefined);
52
38
  } else if (!(0, _isEmpty["default"])(currentShuffled)) {
53
39
  var _session$data2;
54
-
55
40
  debug('use shuffledValues to sort the choices...', (_session$data2 = session.data) === null || _session$data2 === void 0 ? void 0 : _session$data2.shuffledValues);
56
41
  resolve(compact(currentShuffled.map(function (v) {
57
42
  return choices.find(function (c) {
@@ -60,7 +45,6 @@ var getShuffledChoices = function getShuffledChoices(choices, session, updateSes
60
45
  })));
61
46
  } else {
62
47
  var shuffledChoices = (0, _shuffle["default"])(choices);
63
-
64
48
  if (updateSession && typeof updateSession === 'function') {
65
49
  try {
66
50
  //Note: session.id refers to the id of the element within a session
@@ -69,14 +53,14 @@ var getShuffledChoices = function getShuffledChoices(choices, session, updateSes
69
53
  }));
70
54
  log('try to save shuffledValues to session...', shuffledValues);
71
55
  log('call updateSession... ', session.id, session.element);
72
-
73
56
  if ((0, _isEmpty["default"])(shuffledValues)) {
74
57
  error("shuffledValues is an empty array? - refusing to call updateSession: shuffledChoices: ".concat(JSON.stringify(shuffledChoices), ", key: ").concat(choiceKey));
75
58
  } else {
76
59
  updateSession(session.id, session.element, {
77
60
  shuffledValues: shuffledValues
78
61
  })["catch"](function (e) {
79
- return (// eslint-disable-next-line no-console
62
+ return (
63
+ // eslint-disable-next-line no-console
80
64
  console.error('update session failed for: ', session.id, e)
81
65
  );
82
66
  });
@@ -87,13 +71,13 @@ var getShuffledChoices = function getShuffledChoices(choices, session, updateSes
87
71
  }
88
72
  } else {
89
73
  warn('unable to save shuffled choices, shuffle will happen every time.');
90
- } //save this shuffle to the session for later retrieval
91
-
92
-
74
+ }
75
+ //save this shuffle to the session for later retrieval
93
76
  resolve(shuffledChoices);
94
77
  }
95
78
  });
96
79
  };
80
+
97
81
  /**
98
82
  * If we return:
99
83
  * - true - that means that the order of the choices will be ordinal (as is created in the configure item)
@@ -104,37 +88,26 @@ var getShuffledChoices = function getShuffledChoices(choices, session, updateSes
104
88
  * @param env - env to check if we should lock order
105
89
  * @returns {boolean}
106
90
  */
107
-
108
-
109
- exports.getShuffledChoices = getShuffledChoices;
110
-
111
- var lockChoices = function lockChoices(model, session, env) {
91
+ var lockChoices = exports.lockChoices = function lockChoices(model, session, env) {
112
92
  if (model.lockChoiceOrder) {
113
93
  return true;
114
94
  }
115
-
116
95
  log('lockChoiceOrder: ', (0, _get["default"])(env, ['@pie-element', 'lockChoiceOrder'], false));
117
-
118
96
  if ((0, _get["default"])(env, ['@pie-element', 'lockChoiceOrder'], false)) {
119
97
  return true;
120
98
  }
121
-
122
99
  var role = (0, _get["default"])(env, 'role', 'student');
123
-
124
100
  if (role === 'instructor') {
125
101
  // TODO: .. in the future the instructor can toggle between ordinal and shuffled here, so keeping this code until then
126
-
127
102
  /*const alreadyShuffled = hasShuffledValues(session);
128
103
  if (alreadyShuffled) {
129
104
  return false;
130
105
  }
131
106
  return true;*/
132
107
  return true;
133
- } // here it's a student, so don't lock and it will shuffle if needs be
134
-
108
+ }
135
109
 
110
+ // here it's a student, so don't lock and it will shuffle if needs be
136
111
  return false;
137
112
  };
138
-
139
- exports.lockChoices = lockChoices;
140
113
  //# sourceMappingURL=persistence.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/persistence.js"],"names":["lg","n","console","bind","debug","log","warn","error","compact","arr","Array","isArray","filter","v","undefined","getShuffledChoices","choices","session","updateSession","choiceKey","Promise","resolve","currentShuffled","data","shuffledValues","map","find","c","shuffledChoices","id","element","JSON","stringify","e","lockChoices","model","env","lockChoiceOrder","role"],"mappings":";;;;;;;;;;;AAAA;;AACA;;AACA;;AAEA;AACA,IAAMA,EAAE,GAAG,SAALA,EAAK,CAACC,CAAD;AAAA,SAAOC,OAAO,CAACD,CAAD,CAAP,CAAWE,IAAX,CAAgBD,OAAhB,EAAyB,mBAAzB,CAAP;AAAA,CAAX;;AACA,IAAME,KAAK,GAAGJ,EAAE,C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A3BI,CA4BL;;;AACAe,MAAAA,OAAO,CAACO,eAAD,CAAP;AACD;AACF,GA5CD,CADgC;AAAA,CAA3B;AA+CP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;AACO,IAAMM,WAAW,GAAG,SAAdA,WAAc,CAACC,KAAD,EAAQlB,OAAR,EAAiBmB,GAAjB,EAAyB;AAClD,MAAID,KAAK,CAACE,eAAV,EAA2B;AACzB,WAAO,IAAP;AACD;;AAEDhC,EAAAA,GAAG,CAAC,mBAAD,EAAsB,qBAAI+B,GAAJ,EAAS,CAAC,cAAD,EAAiB,iBAAjB,CAAT,EAA8C,KAA9C,CAAtB,CAAH;;AAEA,MAAI,qBAAIA,GAAJ,EAAS,CAAC,cAAD,EAAiB,iBAAjB,CAAT,EAA8C,KAA9C,CAAJ,EAA0D;AACxD,WAAO,IAAP;AACD;;AAED,MAAME,IAAI,GAAG,qBAAIF,GAAJ,EAAS,MAAT,EAAiB,SAAjB,CAAb;;AAEA,MAAIE,IAAI,KAAK,YAAb,EAA2B;AACzB;;AACA;AACJ;AACA;AACA;AACA;AAGI,WAAO,IAAP;AACD,GAvBiD,CAyBlD;;;AACA,SAAO,KAAP;AACD,CA3BM","sourcesContent":["import get from 'lodash/get';\nimport shuffle from 'lodash/shuffle';\nimport isEmpty from 'lodash/isEmpty';\n\n// eslint-disable-next-line no-console\nconst lg = (n) => console[n].bind(console, 'controller-utils:');\nconst debug = lg('debug');\nconst log = lg('log');\nconst warn = lg('warn');\nconst error = lg('error');\n\nexport const compact = (arr) => {\n if (Array.isArray(arr)) {\n return arr.filter((v) => v !== null && v !== undefined);\n }\n return arr;\n};\n\nexport const getShuffledChoices = (choices, session, updateSession, choiceKey) =>\n new Promise((resolve) => {\n log('updateSession type: ', typeof updateSession);\n log('session: ', session);\n\n const currentShuffled = compact(session?.data?.shuffledValues || session?.shuffledValues || []);\n\n if (!session) {\n // eslint-disable-next-line quotes\n warn(\"unable to save shuffled choices because there's no session.\");\n resolve(undefined);\n } else if (!isEmpty(currentShuffled)) {\n debug('use shuffledValues to sort the choices...', session.data?.shuffledValues);\n resolve(compact(currentShuffled.map((v) => choices.find((c) => c[choiceKey] === v))));\n } else {\n const shuffledChoices = shuffle(choices);\n\n if (updateSession && typeof updateSession === 'function') {\n try {\n //Note: session.id refers to the id of the element within a session\n const shuffledValues = compact(shuffledChoices.map((c) => c[choiceKey]));\n log('try to save shuffledValues to session...', shuffledValues);\n log('call updateSession... ', session.id, session.element);\n if (isEmpty(shuffledValues)) {\n error(\n `shuffledValues is an empty array? - refusing to call updateSession: shuffledChoices: ${JSON.stringify(\n shuffledChoices,\n )}, key: ${choiceKey}`,\n );\n } else {\n updateSession(session.id, session.element, { shuffledValues }).catch((e) =>\n // eslint-disable-next-line no-console\n console.error('update session failed for: ', session.id, e),\n );\n }\n } catch (e) {\n warn('unable to save shuffled order for choices');\n error(e);\n }\n } else {\n warn('unable to save shuffled choices, shuffle will happen every time.');\n }\n //save this shuffle to the session for later retrieval\n resolve(shuffledChoices);\n }\n });\n\n/**\n * If we return:\n * - true - that means that the order of the choices will be ordinal (as is created in the configure item)\n * - false - that means the getShuffledChoices above will be called and that in turn means that we either\n * return the shuffled values on the session (if any exists) or we shuffle the choices\n * @param model - model to check if we should lock order\n * @param session - session to check if we should lock order\n * @param env - env to check if we should lock order\n * @returns {boolean}\n */\nexport const lockChoices = (model, session, env) => {\n if (model.lockChoiceOrder) {\n return true;\n }\n\n log('lockChoiceOrder: ', get(env, ['@pie-element', 'lockChoiceOrder'], false));\n\n if (get(env, ['@pie-element', 'lockChoiceOrder'], false)) {\n return true;\n }\n\n const role = get(env, 'role', 'student');\n\n if (role === 'instructor') {\n // TODO: .. in the future the instructor can toggle between ordinal and shuffled here, so keeping this code until then\n /*const alreadyShuffled = hasShuffledValues(session);\n\n if (alreadyShuffled) {\n return false;\n }\n\n return true;*/\n return true;\n }\n\n // here it's a student, so don't lock and it will shuffle if needs be\n return false;\n};\n"],"file":"persistence.js"}
1
+ {"version":3,"file":"persistence.js","names":["_get","_interopRequireDefault","require","_shuffle","_isEmpty","lg","n","console","bind","debug","log","warn","error","compact","exports","arr","Array","isArray","filter","v","undefined","getShuffledChoices","choices","session","updateSession","choiceKey","Promise","resolve","_session$data","_typeof2","currentShuffled","data","shuffledValues","isEmpty","_session$data2","map","find","c","shuffledChoices","shuffle","id","element","concat","JSON","stringify","e","lockChoices","model","env","lockChoiceOrder","get","role"],"sources":["../src/persistence.js"],"sourcesContent":["import get from 'lodash/get';\nimport shuffle from 'lodash/shuffle';\nimport isEmpty from 'lodash/isEmpty';\n\n// eslint-disable-next-line no-console\nconst lg = (n) => console[n].bind(console, 'controller-utils:');\nconst debug = lg('debug');\nconst log = lg('log');\nconst warn = lg('warn');\nconst error = lg('error');\n\nexport const compact = (arr) => {\n if (Array.isArray(arr)) {\n return arr.filter((v) => v !== null && v !== undefined);\n }\n return arr;\n};\n\nexport const getShuffledChoices = (choices, session, updateSession, choiceKey) =>\n new Promise((resolve) => {\n log('updateSession type: ', typeof updateSession);\n log('session: ', session);\n\n const currentShuffled = compact(session?.data?.shuffledValues || session?.shuffledValues || []);\n\n if (!session) {\n // eslint-disable-next-line quotes\n warn(\"unable to save shuffled choices because there's no session.\");\n resolve(undefined);\n } else if (!isEmpty(currentShuffled)) {\n debug('use shuffledValues to sort the choices...', session.data?.shuffledValues);\n resolve(compact(currentShuffled.map((v) => choices.find((c) => c[choiceKey] === v))));\n } else {\n const shuffledChoices = shuffle(choices);\n\n if (updateSession && typeof updateSession === 'function') {\n try {\n //Note: session.id refers to the id of the element within a session\n const shuffledValues = compact(shuffledChoices.map((c) => c[choiceKey]));\n log('try to save shuffledValues to session...', shuffledValues);\n log('call updateSession... ', session.id, session.element);\n if (isEmpty(shuffledValues)) {\n error(\n `shuffledValues is an empty array? - refusing to call updateSession: shuffledChoices: ${JSON.stringify(\n shuffledChoices,\n )}, key: ${choiceKey}`,\n );\n } else {\n updateSession(session.id, session.element, { shuffledValues }).catch((e) =>\n // eslint-disable-next-line no-console\n console.error('update session failed for: ', session.id, e),\n );\n }\n } catch (e) {\n warn('unable to save shuffled order for choices');\n error(e);\n }\n } else {\n warn('unable to save shuffled choices, shuffle will happen every time.');\n }\n //save this shuffle to the session for later retrieval\n resolve(shuffledChoices);\n }\n });\n\n/**\n * If we return:\n * - true - that means that the order of the choices will be ordinal (as is created in the configure item)\n * - false - that means the getShuffledChoices above will be called and that in turn means that we either\n * return the shuffled values on the session (if any exists) or we shuffle the choices\n * @param model - model to check if we should lock order\n * @param session - session to check if we should lock order\n * @param env - env to check if we should lock order\n * @returns {boolean}\n */\nexport const lockChoices = (model, session, env) => {\n if (model.lockChoiceOrder) {\n return true;\n }\n\n log('lockChoiceOrder: ', get(env, ['@pie-element', 'lockChoiceOrder'], false));\n\n if (get(env, ['@pie-element', 'lockChoiceOrder'], false)) {\n return true;\n }\n\n const role = get(env, 'role', 'student');\n\n if (role === 'instructor') {\n // TODO: .. in the future the instructor can toggle between ordinal and shuffled here, so keeping this code until then\n /*const alreadyShuffled = hasShuffledValues(session);\n\n if (alreadyShuffled) {\n return false;\n }\n\n return true;*/\n return true;\n }\n\n // here it's a student, so don't lock and it will shuffle if needs be\n return false;\n};\n"],"mappings":";;;;;;;;AAAA,IAAAA,IAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,QAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,QAAA,GAAAH,sBAAA,CAAAC,OAAA;AAEA;AACA,IAAMG,EAAE,GAAG,SAALA,EAAEA,CAAIC,CAAC;EAAA,OAAKC,OAAO,CAACD,CAAC,CAAC,CAACE,IAAI,CAACD,OAAO,EAAE,mBAAmB,CAAC;AAAA;AAC/D,IAAME,KAAK,GAAGJ,EAAE,CAAC,OAAO,CAAC;AACzB,IAAMK,GAAG,GAAGL,EAAE,CAAC,KAAK,CAAC;AACrB,IAAMM,IAAI,GAAGN,EAAE,CAAC,MAAM,CAAC;AACvB,IAAMO,KAAK,GA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;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,IAAMQ,WAAW,GAAAhC,OAAA,CAAAgC,WAAA,GAAG,SAAdA,WAAWA,CAAIC,KAAK,EAAExB,OAAO,EAAEyB,GAAG,EAAK;EAClD,IAAID,KAAK,CAACE,eAAe,EAAE;IACzB,OAAO,IAAI;EACb;EAEAvC,GAAG,CAAC,mBAAmB,EAAE,IAAAwC,eAAG,EAACF,GAAG,EAAE,CAAC,cAAc,EAAE,iBAAiB,CAAC,EAAE,KAAK,CAAC,CAAC;EAE9E,IAAI,IAAAE,eAAG,EAACF,GAAG,EAAE,CAAC,cAAc,EAAE,iBAAiB,CAAC,EAAE,KAAK,CAAC,EAAE;IACxD,OAAO,IAAI;EACb;EAEA,IAAMG,IAAI,GAAG,IAAAD,eAAG,EAACF,GAAG,EAAE,MAAM,EAAE,SAAS,CAAC;EAExC,IAAIG,IAAI,KAAK,YAAY,EAAE;IACzB;IACA;AACJ;AACA;AACA;AACA;IAGI,OAAO,IAAI;EACb;;EAEA;EACA,OAAO,KAAK;AACd,CAAC","ignoreList":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pie-lib/controller-utils",
3
- "version": "0.20.0",
3
+ "version": "0.22.0-mui-update.0",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "module": "src/index.js",
@@ -14,5 +14,5 @@
14
14
  "scripts": {},
15
15
  "author": "",
16
16
  "license": "ISC",
17
- "gitHead": "e65a495136968b1a07642bde2efd887f46548d25"
17
+ "gitHead": "622d5627dc85e393cdf13e3362970299cc485cc5"
18
18
  }