@pie-element/mc-populated-blank 0.3.0-next.21 → 0.3.0-next.23

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/module/print.js CHANGED
@@ -4963,8 +4963,44 @@ vi(ko, {
4963
4963
  onAudioEnded: {}
4964
4964
  }, [], []);
4965
4965
  //#endregion
4966
+ //#region ../../shared/controller-utils/dist/index.js
4967
+ function Ao(e) {
4968
+ return Array.isArray(e) ? e.filter((e) => e != null) : [];
4969
+ }
4970
+ function jo(e) {
4971
+ let t = [...e];
4972
+ for (let e = t.length - 1; e > 0; e--) {
4973
+ let n = Math.floor(Math.random() * (e + 1));
4974
+ [t[e], t[n]] = [t[n], t[e]];
4975
+ }
4976
+ return t;
4977
+ }
4978
+ function Mo(e) {
4979
+ return e == null ? !0 : Array.isArray(e) ? e.length === 0 : typeof e == "object" && Object.keys(e).length === 0;
4980
+ }
4981
+ async function No(e, t, n, r = "value") {
4982
+ let i = Ao(t?.data?.shuffledValues ?? t?.shuffledValues ?? []);
4983
+ if (!t) {
4984
+ console.warn("Unable to save shuffled choices because there's no session.");
4985
+ return;
4986
+ }
4987
+ if (!Mo(i)) return Ao(i.map((t) => e.find((e) => e[r] === t)));
4988
+ let a = jo(e);
4989
+ if (n && typeof n == "function") try {
4990
+ let e = Ao(a.map((e) => e[r]));
4991
+ Mo(e) ? console.error(`shuffledValues is an empty array - refusing to call updateSession. shuffledChoices: ${JSON.stringify(a)}, key: ${r}`) : await n(t.id, t.element, { shuffledValues: e });
4992
+ } catch (e) {
4993
+ console.warn("Unable to save shuffled order for choices"), console.error(e);
4994
+ }
4995
+ else console.warn("Unable to save shuffled choices, shuffle will happen every time.");
4996
+ return a;
4997
+ }
4998
+ function Po(e, t, n) {
4999
+ return !!(e.lockChoiceOrder || n?.["@pie-element"]?.lockChoiceOrder);
5000
+ }
5001
+ //#endregion
4966
5002
  //#region src/controller/defaults.ts
4967
- var Ao = { model: {
5003
+ var Fo = { model: {
4968
5004
  prompt: "",
4969
5005
  promptEnabled: !0,
4970
5006
  interactionMode: "populate_blank",
@@ -4988,50 +5024,32 @@ var Ao = { model: {
4988
5024
  locale: "",
4989
5025
  teacherInstructions: "",
4990
5026
  teacherInstructionsEnabled: !0
4991
- } }, jo = (e, t) => {
5027
+ } }, Io = (e, t) => {
4992
5028
  if (!t?.choiceId) return "unanswered";
4993
5029
  let n = e?.correctChoiceId || "";
4994
5030
  return t.choiceId === n ? "correct" : "incorrect";
4995
- }, Mo = (e, t = {}) => ({
5031
+ }, Lo = (e, t = {}) => ({
4996
5032
  ...e,
4997
5033
  ...t,
4998
5034
  layoutLimits: {
4999
5035
  ...$a,
5000
5036
  ...t?.layoutLimits || {}
5001
5037
  }
5002
- }), No = (e = {}) => {
5038
+ }), Ro = (e = {}) => {
5003
5039
  let { shuffle: t, ...n } = e || {};
5004
5040
  return {
5005
- ...Mo(Ao.model, n),
5041
+ ...Lo(Fo.model, n),
5006
5042
  lockChoiceOrder: typeof n.lockChoiceOrder == "boolean" ? n.lockChoiceOrder : t !== !0
5007
5043
  };
5008
- }, Po = (e, t) => !!e?.lockChoiceOrder || !!t?.["@pie-element"]?.lockChoiceOrder;
5009
- function Fo(e) {
5010
- let t = [...e];
5011
- for (let e = t.length - 1; e > 0; e--) {
5012
- let n = Math.floor(Math.random() * (e + 1));
5013
- [t[e], t[n]] = [t[n], t[e]];
5014
- }
5015
- return t;
5016
- }
5017
- var Io = ({ id: e, labelHtml: t, imageUrl: n, imageAlt: r }) => ({
5044
+ }, zo = ({ id: e, labelHtml: t, imageUrl: n, imageAlt: r }) => ({
5018
5045
  id: e,
5019
5046
  ...t === void 0 ? {} : { labelHtml: t },
5020
5047
  ...n === void 0 ? {} : { imageUrl: n },
5021
5048
  ...r === void 0 ? {} : { imageAlt: r }
5022
- }), Lo = (e) => Array.isArray(e?.data?.shuffledValues) ? e.data.shuffledValues : Array.isArray(e?.shuffledValues) ? e.shuffledValues : [], Ro = (e, t, n) => t.map((t) => e.find((e) => e?.[n] === t)).filter((e) => !!e), zo = async (e, t, n, r) => {
5023
- let i = Array.isArray(e?.choices) ? [...e.choices] : [];
5024
- if (!i.length || Po(e, n || {})) return i;
5025
- let a = Lo(t);
5026
- if (a.length) return Ro(i, a, "id");
5027
- let o = Fo(i);
5028
- if (r && typeof r == "function" && t?.id && t?.element) {
5029
- let e = o.map((e) => e?.id).filter(Boolean);
5030
- e.length && await r(t.id, t.element, { shuffledValues: e });
5031
- }
5032
- return o;
5033
- }, Bo = async (e, t, n, r) => {
5034
- let i = t || {}, a = n || {}, o = No(e), s = (await zo(o, i, a, r)).filter((e) => !!e && typeof e == "object").map(Io), c = {
5049
+ }), Bo = async (e, t, n, r) => {
5050
+ let i = t || {}, a = n || {}, o = Ro(e), s = Array.isArray(o.choices) ? [...o.choices] : [];
5051
+ s.length && !Po(o, i, a) && (s = await No(s, i, r, "id") ?? s);
5052
+ let c = s.filter((e) => !!e && typeof e == "object").map(zo), l = {
5035
5053
  prompt: o.promptEnabled ? o.prompt : null,
5036
5054
  interactionMode: o.interactionMode || "populate_blank",
5037
5055
  layoutProfile: o.layoutProfile || "",
@@ -5043,7 +5061,7 @@ var Io = ({ id: e, labelHtml: t, imageUrl: n, imageAlt: r }) => ({
5043
5061
  sentenceHtml: o.sentenceHtml || null,
5044
5062
  template: o.template,
5045
5063
  choiceMode: o.choiceMode,
5046
- choices: s,
5064
+ choices: c,
5047
5065
  choiceGroupLabel: o.choiceGroupLabel || "",
5048
5066
  hasAudio: o.hasAudio,
5049
5067
  autoplayAudioEnabled: !!o.autoplayAudioEnabled,
@@ -5058,10 +5076,10 @@ var Io = ({ id: e, labelHtml: t, imageUrl: n, imageAlt: r }) => ({
5058
5076
  mode: a.mode
5059
5077
  };
5060
5078
  if (a.mode === "evaluate") {
5061
- let e = jo(o, i);
5062
- c.correctness = e, c.responseCorrect = e === "correct", c.correctChoiceId = o.correctChoiceId;
5079
+ let e = Io(o, i);
5080
+ l.correctness = e, l.responseCorrect = e === "correct", l.correctChoiceId = o.correctChoiceId;
5063
5081
  }
5064
- return a.role === "instructor" && (a.mode === "view" || a.mode === "evaluate") ? c.teacherInstructions = o.teacherInstructionsEnabled ? o.teacherInstructions : null : c.teacherInstructions = null, c;
5082
+ return a.role === "instructor" && (a.mode === "view" || a.mode === "evaluate") ? l.teacherInstructions = o.teacherInstructionsEnabled ? o.teacherInstructions : null : l.teacherInstructions = null, l;
5065
5083
  }, Vo = (e, t) => new Promise((n) => {
5066
5084
  t.mode !== "evaluate" && t.role === "instructor" ? n({
5067
5085
  id: "1",