@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.
- package/dist/author/defaults.d.ts +52 -51
- package/dist/author/design.d.ts +31 -15
- package/dist/author/design.js +30 -40
- package/dist/author/index.d.ts +15 -22
- package/dist/author/index.js +4 -1
- package/dist/browser/author/index.js +11 -20
- package/dist/browser/author/index.js.map +1 -1
- package/dist/browser/controller/index.js.map +1 -1
- package/dist/browser/editor-runtime/author/index.js +11 -20
- package/dist/browser/editor-runtime/author/index.js.map +1 -1
- package/dist/browser/editor-runtime/controller/index.js.map +1 -1
- package/dist/controller/defaults.d.ts +5 -5
- package/dist/controller/index.d.ts +37 -10
- package/dist/index.d.ts +1 -0
- package/dist/schemas/configuration.schema.json +301 -0
- package/dist/schemas/model.schema.json +373 -0
- package/dist/schemas/session.schema.json +17 -0
- package/dist/types.d.ts +108 -0
- package/package.json +17 -13
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../../src/controller/defaults.ts","../../../src/controller/index.ts"],"sourcesContent":["
|
|
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;CAAE,GAAG;CAAU,GAAG;AAAS,IAE3E,KAAgC,GAAkC,MAAwB;CAC9F,IAAM,EAAE,SAAM,YAAS;CAMvB,OAJI,MAAS,iBAAiB,MAAS,UAAU,MAAS,eACjD,KAGF;AACT;AAEA,eAAsB,EACpB,GACA,GACA,GACoB;CACpB,IAAM,IAAqB,EAAU,CAAQ,GAEvC,IAAqB,EAAmB,SAAS,KAAK,GAAS,OAAwB;EAC3F,qBAAqB,EAAU,EAAQ,4BAA4B,EAAmB,0BAA0B,IAC5G,EAA6B,EAAQ,qBAAqB,CAAG,IAC7D;EACJ,OAAO,EAAW,EAAQ,KAAK,IAAI,EAAQ,QAAS,WAAW,IAAQ;EACvE,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,KACX,IAA+B,CAAC,GAChC,IAA+B,CAAC,MACJ;CAC5B,IAAM,IAAkC,CAAC,GACnC,IAAqD,CAAC;CAoB5D,QAlBC,EAAM,YAAY,CAAC,EAAA,CAAG,SAAS,GAAS,MAAU;EACjD,IAAM,IAA0B,CAAC;EAQjC,AANA;GAAE;GAAuB;GAAS;GAAY;GAAU;EAAM,CAAC,CAAW,SAAS,MAAU;GAC3F,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"}
|
|
@@ -17752,15 +17752,12 @@ var fC = class extends L.Component {
|
|
|
17752
17752
|
}), gC = (e) => typeof e == "string" ? {
|
|
17753
17753
|
label: e,
|
|
17754
17754
|
value: e
|
|
17755
|
-
} : e, _C =
|
|
17756
|
-
|
|
17757
|
-
|
|
17758
|
-
|
|
17759
|
-
|
|
17760
|
-
|
|
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
|
|
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)
|
|
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();
|