@pie-element/passage 8.0.4-next.20261011174919 → 8.0.4

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.
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../../src/controller/defaults.ts","../../../src/controller/index.ts"],"sourcesContent":["// @ts-nocheck\n\n// TODO: also update '../../configure/src/defaults.js' and '../../src/print.js' when updating defaults\nexport default {\n authorEnabled: false, // TODO: should be set to true when all Studio content is updated\n passages: [\n {\n teacherInstructions: '',\n title: '',\n subtitle: '',\n author: '',\n text: '',\n },\n ],\n subtitleEnabled: true,\n teacherInstructionsEnabled: true,\n textEnabled: true,\n titleEnabled: true,\n};\n","// @ts-nocheck\n\nimport { isEmpty } from '@pie-element/shared-lodash';\n\nimport defaults from './defaults.js';\n\nconst getContent = (html) => (html || '').replace(/(<(?!img|iframe|source)([^>]+)>)/gi, '');\n\nconst checkNullish = (value) => value !== null && value !== undefined;\n\nconst isEnabled = (value, defaultValue) => (checkNullish(value) ? value : defaultValue);\n\nexport function createDefaultModel(model = {}) {\n return new Promise((resolve) => {\n resolve({ ...defaults, ...model });\n });\n}\n\nexport const normalize = (question) => ({ ...defaults, ...question });\n\nconst normalizeTeacherInstructions = (instructions, env) => {\n const { role, mode } = env;\n\n if (role === 'instructor' && (mode === 'view' || mode === 'evaluate')) {\n return instructions || '';\n }\n\n return '';\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\n const normalizedPassages = normalizedQuestion.passages.map((passage, index) => ({\n teacherInstructions: isEnabled(passage.teacherInstructionsEnabled, normalizedQuestion.teacherInstructionsEnabled)\n ? normalizeTeacherInstructions(passage.teacherInstructions, env)\n : '',\n label: getContent(passage.title) ? passage.title : `Passage ${index + 1}`,\n title: isEnabled(passage.titleEnabled, normalizedQuestion.titleEnabled) ? passage.title || '' : '',\n subtitle: isEnabled(passage.subtitleEnabled, normalizedQuestion.subtitleEnabled) ? passage.subtitle || '' : '',\n author: isEnabled(passage.authorEnabled, normalizedQuestion.authorEnabled) ? passage.author || '' : '',\n text: isEnabled(passage.textEnabled, normalizedQuestion.textEnabled) ? passage.text || '' : '',\n }));\n\n return {\n ...normalizedQuestion,\n passages: normalizedPassages,\n };\n}\n\nexport const validate = (model = {}, config = {}) => {\n const errors = {};\n const passagesErrors = {};\n\n (model.passages || []).forEach((passage, index) => {\n const err = {};\n\n ['teacherInstructions', 'title', 'subtitle', 'author', 'text'].forEach((field) => {\n if (config[field]?.required && !getContent(passage[field])) {\n err[field] = 'This field is required.';\n }\n });\n\n if (!isEmpty(err)) {\n passagesErrors[index] = err;\n }\n });\n\n if (!isEmpty(passagesErrors)) {\n errors.passages = passagesErrors;\n }\n\n return errors;\n};\n"],"mappings":";;AAGA,IAAA,IAAe;CACb,eAAe;CACf,UAAU,CACR;EACE,qBAAqB;EACrB,OAAO;EACP,UAAU;EACV,QAAQ;EACR,MAAM;CACR,CACF;CACA,iBAAiB;CACjB,4BAA4B;CAC5B,aAAa;CACb,cAAc;AAChB,GCZM,KAAc,OAAU,KAAQ,GAAA,CAAI,QAAQ,sCAAsC,EAAE,GAEpF,KAAgB,MAAU,KAAU,MAEpC,KAAa,GAAO,MAAkB,EAAa,CAAK,IAAI,IAAQ;AAE1E,SAAgB,EAAmB,IAAQ,CAAC,GAAG;CAC7C,OAAO,IAAI,SAAS,MAAY;EAC9B,EAAQ;GAAE,GAAG;GAAU,GAAG;EAAM,CAAC;CACnC,CAAC;AACH;AAEA,IAAa,KAAa,OAAc;CAAE,GAAG;CAAU,GAAG;AAAS,IAE7D,KAAgC,GAAc,MAAQ;CAC1D,IAAM,EAAE,SAAM,YAAS;CAMvB,OAJI,MAAS,iBAAiB,MAAS,UAAU,MAAS,eACjD,KAGF;AACT;AAQA,eAAsB,EAAM,GAAU,GAAS,GAAK;CAClD,IAAM,IAAqB,EAAU,CAAQ,GAEvC,IAAqB,EAAmB,SAAS,KAAK,GAAS,OAAW;EAC9E,qBAAqB,EAAU,EAAQ,4BAA4B,EAAmB,0BAA0B,IAC5G,EAA6B,EAAQ,qBAAqB,CAAG,IAC7D;EACJ,OAAO,EAAW,EAAQ,KAAK,IAAI,EAAQ,QAAQ,WAAW,IAAQ;EACtE,OAAO,EAAU,EAAQ,cAAc,EAAmB,YAAY,KAAI,EAAQ,SAAc;EAChG,UAAU,EAAU,EAAQ,iBAAiB,EAAmB,eAAe,KAAI,EAAQ,YAAiB;EAC5G,QAAQ,EAAU,EAAQ,eAAe,EAAmB,aAAa,KAAI,EAAQ,UAAe;EACpG,MAAM,EAAU,EAAQ,aAAa,EAAmB,WAAW,KAAI,EAAQ,QAAa;CAC9F,EAAE;CAEF,OAAO;EACL,GAAG;EACH,UAAU;CACZ;AACF;AAEA,IAAa,KAAY,IAAQ,CAAC,GAAG,IAAS,CAAC,MAAM;CACnD,IAAM,IAAS,CAAC,GACV,IAAiB,CAAC;CAoBxB,QAlBC,EAAM,YAAY,CAAC,EAAA,CAAG,SAAS,GAAS,MAAU;EACjD,IAAM,IAAM,CAAC;EAQb,AANA;GAAC;GAAuB;GAAS;GAAY;GAAU;EAAM,CAAC,CAAC,SAAS,MAAU;GAChF,AAAI,EAAO,EAAM,EAAE,YAAY,CAAC,EAAW,EAAQ,EAAM,MACvD,EAAI,KAAS;EAEjB,CAAC,GAEI,EAAQ,CAAG,MACd,EAAe,KAAS;CAE5B,CAAC,GAEI,EAAQ,CAAc,MACzB,EAAO,WAAW,IAGb;AACT"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../src/controller/defaults.ts","../../../src/controller/index.ts"],"sourcesContent":["import type { PassageModel } from '../types.js';\n\n// TODO: also update '../../configure/src/defaults.js' and '../../src/print.js' when updating defaults\nexport default {\n authorEnabled: false, // TODO: should be set to true when all Studio content is updated\n passages: [\n {\n teacherInstructions: '',\n title: '',\n subtitle: '',\n author: '',\n text: '',\n },\n ],\n subtitleEnabled: true,\n teacherInstructionsEnabled: true,\n textEnabled: true,\n titleEnabled: true,\n} satisfies Omit<PassageModel, 'id' | 'element'>;\n","import { isEmpty } from '@pie-element/shared-lodash';\nimport type { PieEnvironment } from '@pie-element/shared-types';\n\nimport defaults from './defaults.js';\nimport type { PassageConfiguration, PassageModel, PassageSession } from '../types.js';\n\n/** A passage as the delivery renders it: each field is empty when disabled */\nexport interface PassageView {\n teacherInstructions: string;\n label: string;\n title: string;\n subtitle: string;\n author: string;\n text: string;\n}\n\nexport type ModelView = Omit<PassageModel, 'passages'> & { passages: PassageView[] };\n\ntype PassageField = 'teacherInstructions' | 'title' | 'subtitle' | 'author' | 'text';\n\nexport type PassageFieldErrors = Partial<Record<PassageField, string>>;\n\n/** Errors from `validate()`, keyed by passage index */\nexport type PassageValidationErrors = {\n passages?: Record<number, PassageFieldErrors>;\n};\n\nconst getContent = (html: string | undefined) => (html || '').replace(/(<(?!img|iframe|source)([^>]+)>)/gi, '');\n\nconst checkNullish = (value: boolean | undefined) => value !== null && value !== undefined;\n\nconst isEnabled = (value: boolean | undefined, defaultValue: boolean | undefined) => (checkNullish(value) ? value : defaultValue);\n\nexport function createDefaultModel(model: Partial<PassageModel> = {}) {\n return new Promise<Omit<PassageModel, 'id' | 'element'> & Partial<PassageModel>>((resolve) => {\n resolve({ ...defaults, ...model });\n });\n}\n\nexport const normalize = (question: PassageModel) => ({ ...defaults, ...question });\n\nconst normalizeTeacherInstructions = (instructions: string | undefined, env: PieEnvironment) => {\n const { role, mode } = env;\n\n if (role === 'instructor' && (mode === 'view' || mode === 'evaluate')) {\n return instructions || '';\n }\n\n return '';\n};\n\nexport async function model(\n question: PassageModel,\n _session: PassageSession | undefined,\n env: PieEnvironment\n): Promise<ModelView> {\n const normalizedQuestion = normalize(question);\n\n const normalizedPassages = normalizedQuestion.passages.map((passage, index): PassageView => ({\n teacherInstructions: isEnabled(passage.teacherInstructionsEnabled, normalizedQuestion.teacherInstructionsEnabled)\n ? normalizeTeacherInstructions(passage.teacherInstructions, env)\n : '',\n label: getContent(passage.title) ? passage.title! : `Passage ${index + 1}`,\n title: isEnabled(passage.titleEnabled, normalizedQuestion.titleEnabled) ? passage.title || '' : '',\n subtitle: isEnabled(passage.subtitleEnabled, normalizedQuestion.subtitleEnabled) ? passage.subtitle || '' : '',\n author: isEnabled(passage.authorEnabled, normalizedQuestion.authorEnabled) ? passage.author || '' : '',\n text: isEnabled(passage.textEnabled, normalizedQuestion.textEnabled) ? passage.text || '' : '',\n }));\n\n return {\n ...normalizedQuestion,\n passages: normalizedPassages,\n };\n}\n\nexport const validate = (\n model: Partial<PassageModel> = {},\n config: PassageConfiguration = {}\n): PassageValidationErrors => {\n const errors: PassageValidationErrors = {};\n const passagesErrors: Record<number, PassageFieldErrors> = {};\n\n (model.passages || []).forEach((passage, index) => {\n const err: PassageFieldErrors = {};\n\n (['teacherInstructions', 'title', 'subtitle', 'author', 'text'] as const).forEach((field) => {\n if (config[field]?.required && !getContent(passage[field])) {\n err[field] = 'This field is required.';\n }\n });\n\n if (!isEmpty(err)) {\n passagesErrors[index] = err;\n }\n });\n\n if (!isEmpty(passagesErrors)) {\n errors.passages = passagesErrors;\n }\n\n return errors;\n};\n"],"mappings":";;AAGA,IAAA,IAAe;CACb,eAAe;CACf,UAAU,CACR;EACE,qBAAqB;EACrB,OAAO;EACP,UAAU;EACV,QAAQ;EACR,MAAM;CACR,CACF;CACA,iBAAiB;CACjB,4BAA4B;CAC5B,aAAa;CACb,cAAc;AAChB,GCSM,KAAc,OAA8B,KAAQ,GAAA,CAAI,QAAQ,sCAAsC,EAAE,GAExG,KAAgB,MAA+B,KAAU,MAEzD,KAAa,GAA4B,MAAuC,EAAa,CAAK,IAAI,IAAQ;AAEpH,SAAgB,EAAmB,IAA+B,CAAC,GAAG;CACpE,OAAO,IAAI,SAAuE,MAAY;EAC5F,EAAQ;GAAE,GAAG;GAAU,GAAG;EAAM,CAAC;CACnC,CAAC;AACH;AAEA,IAAa,KAAa,OAA4B;CA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.Component {
17752
17752
  }), gC = (e) => typeof e == "string" ? {
17753
17753
  label: e,
17754
17754
  value: e
17755
- } : e, _C = function() {
17756
- let [e, t, n = !1] = Array.prototype.slice.call(arguments);
17757
- return {
17758
- type: "radio",
17759
- label: e,
17760
- choices: t && t.map((e) => gC(e)),
17761
- isConfigProperty: n
17762
- };
17763
- }, vC = (e, t, n = !1) => ({
17755
+ } : e, _C = (e, t, n = !1) => ({
17756
+ type: "radio",
17757
+ label: e,
17758
+ choices: t && t.map((e) => gC(e)),
17759
+ isConfigProperty: n
17760
+ }), vC = (e, t, n = !1) => ({
17764
17761
  type: "dropdown",
17765
17762
  label: e,
17766
17763
  choices: t,
@@ -17961,15 +17958,6 @@ var NC = F(OC)(({ theme: e }) => ({
17961
17958
  paddingTop: e.spacing(2),
17962
17959
  marginBottom: e.spacing(2)
17963
17960
  })), BC = class extends L.Component {
17964
- static propTypes = {
17965
- onModelChanged: V.default.func.isRequired,
17966
- onConfigurationChanged: V.default.func,
17967
- model: V.default.object.isRequired,
17968
- configuration: V.default.object.isRequired,
17969
- imageSupport: V.default.object.isRequired,
17970
- uploadSoundSupport: V.default.object.isRequired,
17971
- classes: V.default.object.isRequired
17972
- };
17973
17961
  constructor(e) {
17974
17962
  super(e), this.state = {
17975
17963
  showConfirmationDialog: !1,
@@ -17988,7 +17976,7 @@ var NC = F(OC)(({ theme: e }) => ({
17988
17976
  });
17989
17977
  };
17990
17978
  removeAdditionalPassage = (e) => {
17991
- let { model: t = {}, onModelChanged: n } = this.props, { passages: r = [] } = t, { teacherInstructions: i = "", title: a = "", subtitle: o = "", author: s = "", text: c = "" } = r[e];
17979
+ let { model: t, onModelChanged: n } = this.props, { passages: r = [] } = t, { teacherInstructions: i = "", title: a = "", subtitle: o = "", author: s = "", text: c = "" } = r[e];
17992
17980
  this.getInnerText(i).trim() || this.getInnerText(a).trim() || this.getInnerText(o).trim() || this.getInnerText(s).trim() || this.getInnerText(c).trim() ? this.setState({
17993
17981
  showConfirmationDialog: !0,
17994
17982
  indexToRemove: e
@@ -18175,6 +18163,9 @@ var NC = F(OC)(({ theme: e }) => ({
18175
18163
  }
18176
18164
  }
18177
18165
  }, HC = class e extends HTMLElement {
18166
+ _root;
18167
+ _model;
18168
+ _configuration;
18178
18169
  static createDefaultModel = (e = {}) => ({
18179
18170
  ...VC.model,
18180
18171
  ...e
@@ -18192,7 +18183,7 @@ var NC = F(OC)(({ theme: e }) => ({
18192
18183
  this.render();
18193
18184
  }
18194
18185
  modelChanged(e) {
18195
- this._model = e, this.dispatchEvent(new dn(this._model), !0), this.render();
18186
+ this._model = e, this.dispatchEvent(new dn(this._model)), this.render();
18196
18187
  }
18197
18188
  onConfigurationChanged(e) {
18198
18189
  this._configuration = e, this.render();