@pie-element/matrix 5.0.4-next.20261011174919 → 5.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\nexport default {\n columnLabels: ['COLUMN 1', 'COLUMN 2', 'COLUMN 3'],\n labelType: 'agreement',\n matrixValues: {},\n prompt: '',\n promptEnabled: true,\n rowLabels: ['STATEMENT 1', 'STATEMENT 2'],\n teacherInstructions: '',\n teacherInstructionsEnabled: true,\n};\n","// @ts-nocheck\n\nimport defaults from './defaults.js';\nimport { isEmpty } from '@pie-element/shared-lodash';\n\nexport const createDefaultModel = (model = {}) => new Promise((resolve) => resolve({ ...defaults, ...model }));\n\n/**\n *\n * @param {*} question\n * @param {*} session\n * @param {*} env\n */\nexport async function model(question, session, env) {\n const normalizedQuestion = { ...defaults, ...question };\n\n const out = {\n ...normalizedQuestion,\n disabled: env.mode !== 'gather',\n mode: env.mode,\n };\n\n const { role, mode } = env || {};\n\n if (role === 'instructor' && (mode === 'view' || mode === 'evaluate')) {\n out.teacherInstructions = normalizedQuestion.teacherInstructionsEnabled\n ? normalizedQuestion.teacherInstructions\n : null;\n } else {\n out.teacherInstructions = null;\n }\n\n return out;\n}\n\nexport function outcome(model, session) {\n return new Promise((resolve) => {\n // A player sends an untouched item's session as `{ id, element }`, without `value`.\n if (!session || isEmpty(session) || !session.value) {\n return resolve({ score: 0, empty: true });\n }\n\n const score = Object.keys(session.value).reduce((acc, key) => {\n const matrixValue = model.matrixValues[key];\n return acc + (matrixValue || 0);\n }, 0);\n\n resolve({ score, empty: false });\n });\n}\n\nexport const createCorrectResponseSession = (question, env) => {\n return new Promise((resolve) => {\n if (env.mode !== 'evaluate' && env.role === 'instructor') {\n const { matrixValues } = question || [];\n\n resolve({\n id: '1',\n value: matrixValues,\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 errors = {};\n\n ['teacherInstructions', 'prompt'].forEach((field) => {\n if (config[field]?.required && !getContent(model[field])) {\n errors[field] = 'This field is required.';\n }\n });\n\n return errors;\n};\n"],"mappings":";;AAEA,IAAA,IAAe;CACb,cAAc;EAAC;EAAY;EAAY;CAAU;CACjD,WAAW;CACX,cAAc,CAAC;CACf,QAAQ;CACR,eAAe;CACf,WAAW,CAAC,eAAe,aAAa;CACxC,qBAAqB;CACrB,4BAA4B;AAC9B,GCNa,KAAsB,IAAQ,CAAC,MAAM,IAAI,SAAS,MAAY,EAAQ;CAAE,GAAG;CAAU,GAAG;AAAM,CAAC,CAAC;AAQ7G,eAAsB,EAAM,GAAU,GAAS,GAAK;CAClD,IAAM,IAAqB;EAAE,GAAG;EAAU,GAAG;CAAS,GAEhD,IAAM;EACV,GAAG;EACH,UAAU,EAAI,SAAS;EACvB,MAAM,EAAI;CACZ,GAEM,EAAE,SAAM,YAAS,KAAO,CAAC;CAU/B,OARI,MAAS,iBAAiB,MAAS,UAAU,MAAS,cACxD,EAAI,sBAAsB,EAAmB,6BACzC,EAAmB,sBACnB,OAEJ,EAAI,sBAAsB,MAGrB;AACT;AAEA,SAAgB,EAAQ,GAAO,GAAS;CACtC,OAAO,IAAI,SAAS,MAAY;EAE9B,IAAI,CAAC,KAAW,EAAQ,CAAO,KAAK,CAAC,EAAQ,OAC3C,OAAO,EAAQ;GAAE,OAAO;GAAG,OAAO;EAAK,CAAC;EAQ1C,EAAQ;GAAE,OALI,OAAO,KAAK,EAAQ,KAAK,CAAC,CAAC,QAAQ,GAAK,MAE7C,KADa,EAAM,aAAa,MACV,IAC5B,CAEO;GAAO,OAAO;EAAM,CAAC;CACjC,CAAC;AACH;AAEA,IAAa,KAAgC,GAAU,MAC9C,IAAI,SAAS,MAAY;CAC9B,IAAI,EAAI,SAAS,cAAc,EAAI,SAAS,cAAc;EACxD,IAAM,EAAE,oBAAiB,KAAY,CAAC;EAEtC,EAAQ;GACN,IAAI;GACJ,OAAO;EACT,CAAC;CACH,OACE,EAAQ,IAAI;AAEhB,CAAC,GAOG,KAAc,OAAU,KAAQ,GAAA,CAAI,QAAQ,sCAAsC,EAAE,GAE7E,KAAY,IAAQ,CAAC,GAAG,IAAS,CAAC,MAAM;CACnD,IAAM,IAAS,CAAC;CAQhB,OANA,CAAC,uBAAuB,QAAQ,CAAC,CAAC,SAAS,MAAU;EACnD,AAAI,EAAO,EAAM,EAAE,YAAY,CAAC,EAAW,EAAM,EAAM,MACrD,EAAO,KAAS;CAEpB,CAAC,GAEM;AACT"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../src/controller/defaults.ts","../../../src/controller/index.ts"],"sourcesContent":["import type { MatrixModel } from '../types.js';\n\nexport default {\n columnLabels: ['COLUMN 1', 'COLUMN 2', 'COLUMN 3'],\n labelType: 'agreement',\n matrixValues: {} as Record<string, number>,\n prompt: '',\n promptEnabled: true,\n rowLabels: ['STATEMENT 1', 'STATEMENT 2'],\n teacherInstructions: '',\n teacherInstructionsEnabled: true,\n} satisfies Omit<MatrixModel, 'id' | 'element'>;\n","import defaults from './defaults.js';\nimport { isEmpty } from '@pie-element/shared-lodash';\nimport type { PieEnvironment } from '@pie-element/shared-types';\nimport type { MatrixConfiguration, MatrixModel, MatrixSession } from '../types.js';\n\n/** Errors `validate()` reports. */\nexport type MatrixValidationErrors = {\n teacherInstructions?: string;\n prompt?: string;\n};\n\n/** The model `model()` hands the delivery. */\ntype MatrixViewModel = Omit<MatrixModel, 'teacherInstructions'> & {\n disabled: boolean;\n mode: PieEnvironment['mode'];\n teacherInstructions?: string | null;\n};\n\nexport const createDefaultModel = (model: Partial<MatrixModel> = {}) =>\n new Promise<Partial<MatrixModel>>((resolve) => resolve({ ...defaults, ...model }));\n\n/**\n *\n * @param {*} question\n * @param {*} session\n * @param {*} env\n */\nexport async function model(question: MatrixModel, _session: MatrixSession | undefined, env: PieEnvironment) {\n const normalizedQuestion = { ...defaults, ...question };\n\n const out: MatrixViewModel = {\n ...normalizedQuestion,\n disabled: env.mode !== 'gather',\n mode: env.mode,\n };\n\n const { role, mode } = env || {};\n\n if (role === 'instructor' && (mode === 'view' || mode === 'evaluate')) {\n out.teacherInstructions = normalizedQuestion.teacherInstructionsEnabled\n ? normalizedQuestion.teacherInstructions\n : null;\n } else {\n out.teacherInstructions = null;\n }\n\n return out;\n}\n\nexport function outcome(model: MatrixModel, session: MatrixSession | undefined) {\n return new Promise<{ score: number; empty: boolean }>((resolve) => {\n // A player sends an untouched item's session as `{ id, element }`, without `value`.\n if (!session || isEmpty(session) || !session.value) {\n return resolve({ score: 0, empty: true });\n }\n\n const score = Object.keys(session.value).reduce((acc, key) => {\n // `model` is not normalized here, so a model without `matrixValues` throws\n const matrixValue = (model.matrixValues as Record<string, number>)[key];\n return acc + (matrixValue || 0);\n }, 0);\n\n resolve({ score, empty: false });\n });\n}\n\nexport const createCorrectResponseSession = (question: MatrixModel, env: PieEnvironment) => {\n return new Promise<MatrixSession | null>((resolve) => {\n if (env.mode !== 'evaluate' && env.role === 'instructor') {\n const { matrixValues } = question || [];\n\n resolve({\n id: '1',\n value: matrixValues,\n });\n } else {\n resolve(null);\n }\n });\n};\n\n// remove all html tags except img, iframe and source tag for audio\nconst getContent = (html: string | undefined) => (html || '').replace(/(<(?!img|iframe|source)([^>]+)>)/gi, '');\n\nexport const validate = (\n model: Partial<MatrixModel> = {},\n config: MatrixConfiguration = {},\n): MatrixValidationErrors => {\n const errors: MatrixValidationErrors = {};\n\n (['teacherInstructions', 'prompt'] as const).forEach((field) => {\n if (config[field]?.required && !getContent(model[field])) {\n errors[field] = 'This field is required.';\n }\n });\n\n return errors;\n};\n"],"mappings":";;AAEA,IAAA,IAA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CAAC,GAC/B,IAA8B,CAAC,MACJ;CAC3B,IAAM,IAAiC,CAAC;CAQxC,OANA,CAAE,uBAAuB,QAAQ,CAAC,CAAW,SAAS,MAAU;EAC9D,AAAI,EAAO,EAAM,EAAE,YAAY,CAAC,EAAW,EAAM,EAAM,MACrD,EAAO,KAAS;CAEpB,CAAC,GAEM;AACT"}
@@ -18302,15 +18302,12 @@ var AC = class extends R.Component {
18302
18302
  }), PC = (e) => typeof e == "string" ? {
18303
18303
  label: e,
18304
18304
  value: e
18305
- } : e, FC = function() {
18306
- let [e, t, n = !1] = Array.prototype.slice.call(arguments);
18307
- return {
18308
- type: "radio",
18309
- label: e,
18310
- choices: t && t.map((e) => PC(e)),
18311
- isConfigProperty: n
18312
- };
18313
- }, IC = (e, t, n = !1) => ({
18305
+ } : e, FC = (e, t, n = !1) => ({
18306
+ type: "radio",
18307
+ label: e,
18308
+ choices: t && t.map((e) => PC(e)),
18309
+ isConfigProperty: n
18310
+ }), IC = (e, t, n = !1) => ({
18314
18311
  type: "dropdown",
18315
18312
  label: e,
18316
18313
  choices: t,
@@ -19082,16 +19079,6 @@ var { Panel: nT, toggle: rT, radio: iT } = jC, aT = F(KC)(({ theme: e }) => ({
19082
19079
  ]
19083
19080
  });
19084
19081
  }, lT = class extends R.Component {
19085
- static propTypes = {
19086
- model: V.default.object.isRequired,
19087
- disableSidePanel: V.default.bool,
19088
- onModelChanged: V.default.func.isRequired,
19089
- onConfigurationChanged: V.default.func.isRequired,
19090
- imageSupport: V.default.shape({
19091
- add: V.default.func.isRequired,
19092
- delete: V.default.func.isRequired
19093
- })
19094
- };
19095
19082
  onPromptChanged = (e) => {
19096
19083
  this.props.onModelChanged({
19097
19084
  ...this.props.model,
@@ -19174,6 +19161,10 @@ var { Panel: nT, toggle: rT, radio: iT } = jC, aT = F(KC)(({ theme: e }) => ({
19174
19161
  configuration: st(e, uT.configuration),
19175
19162
  model: t
19176
19163
  }), pT = class e extends HTMLElement {
19164
+ _root;
19165
+ _model;
19166
+ _configuration;
19167
+ _disableSidePanel;
19177
19168
  static createDefaultModel = (e = {}) => ({
19178
19169
  ...uT.model,
19179
19170
  ...e