@pie-element/likert 2.3.3 → 2.3.4-next.3
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/esm/configure.js +17471 -0
- package/esm/configure.js.map +1 -0
- package/esm/controller.js +96 -0
- package/esm/controller.js.map +1 -0
- package/esm/element.js +13272 -0
- package/esm/element.js.map +1 -0
- package/esm/package.json +3 -0
- package/package.json +2 -2
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
function _extends() {
|
|
2
|
+
_extends = Object.assign || function (target) {
|
|
3
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
4
|
+
var source = arguments[i];
|
|
5
|
+
|
|
6
|
+
for (var key in source) {
|
|
7
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
8
|
+
target[key] = source[key];
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
return target;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
return _extends.apply(this, arguments);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
var defaults = {
|
|
20
|
+
choices: [],
|
|
21
|
+
likertOrientation: 'horizontal',
|
|
22
|
+
likertScale: 'likert3',
|
|
23
|
+
likertType: 'agreement',
|
|
24
|
+
prompt: '',
|
|
25
|
+
promptEnabled: true,
|
|
26
|
+
teacherInstructions: '',
|
|
27
|
+
teacherInstructionsEnabled: true
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const prepareChoice = choice => {
|
|
31
|
+
return {
|
|
32
|
+
label: choice.label,
|
|
33
|
+
value: choice.value
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
function createDefaultModel(model = {}) {
|
|
38
|
+
return new Promise(resolve => resolve(_extends({}, defaults, model)));
|
|
39
|
+
}
|
|
40
|
+
const normalize = question => _extends({}, defaults, question);
|
|
41
|
+
/**
|
|
42
|
+
*
|
|
43
|
+
* @param {*} question
|
|
44
|
+
* @param {*} session
|
|
45
|
+
* @param {*} env
|
|
46
|
+
*/
|
|
47
|
+
|
|
48
|
+
async function model(question, session, env) {
|
|
49
|
+
const normalizedQuestion = normalize(question);
|
|
50
|
+
let choices = normalizedQuestion.choices.map(prepareChoice);
|
|
51
|
+
|
|
52
|
+
const out = _extends({}, normalizedQuestion, {
|
|
53
|
+
choices,
|
|
54
|
+
disabled: env.mode !== 'gather',
|
|
55
|
+
mode: env.mode
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
const {
|
|
59
|
+
role,
|
|
60
|
+
mode
|
|
61
|
+
} = env || {};
|
|
62
|
+
|
|
63
|
+
if (role === 'instructor' && (mode === 'view' || mode === 'evaluate')) {
|
|
64
|
+
out.teacherInstructions = normalizedQuestion.teacherInstructionsEnabled ? normalizedQuestion.teacherInstructions : null;
|
|
65
|
+
} else {
|
|
66
|
+
out.teacherInstructions = null;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return out;
|
|
70
|
+
}
|
|
71
|
+
function outcome() {
|
|
72
|
+
return new Promise(resolve => {
|
|
73
|
+
resolve({
|
|
74
|
+
score: 0,
|
|
75
|
+
empty: false
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
} // remove all html tags
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
const getContent = html => (html || '').replace(/(<(?!img|iframe|source)([^>]+)>)/gi, '');
|
|
82
|
+
|
|
83
|
+
const validate = (model = {}, config = {}) => {
|
|
84
|
+
const errors = {};
|
|
85
|
+
['teacherInstructions', 'prompt'].forEach(field => {
|
|
86
|
+
var _config$field;
|
|
87
|
+
|
|
88
|
+
if ((_config$field = config[field]) != null && _config$field.required && !getContent(model[field])) {
|
|
89
|
+
errors[field] = 'This field is required.';
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
return errors;
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
export { createDefaultModel, model, normalize, outcome, validate };
|
|
96
|
+
//# sourceMappingURL=controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"controller.js","sources":["../controller/src/defaults.js","../controller/src/index.js"],"sourcesContent":["export default {\n choices: [],\n likertOrientation: 'horizontal',\n likertScale: 'likert3',\n likertType: 'agreement',\n prompt: '',\n promptEnabled: true,\n teacherInstructions: '',\n teacherInstructionsEnabled: true,\n};\n","import defaults from './defaults';\n\nconst prepareChoice = (choice) => {\n return {\n label: choice.label,\n value: choice.value,\n };\n};\n\nexport function createDefaultModel(model = {}) {\n return new Promise((resolve) => resolve({ ...defaults, ...model }));\n}\n\nexport const normalize = (question) => ({ ...defaults, ...question });\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 let choices = normalizedQuestion.choices.map(prepareChoice);\n\n const out = {\n ...normalizedQuestion,\n choices,\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() {\n return new Promise((resolve) => {\n resolve({ score: 0, empty: false });\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"],"names":["choices","likertOrientation","likertScale","likertType","prompt","promptEnabled","teacherInstructions","teacherInstructionsEnabled","prepareChoice","choice","label","value","createDefaultModel","model","Promise","resolve","defaults","normalize","question","session","env","normalizedQuestion","map","out","disabled","mode","role","outcome","score","empty","getContent","html","replace","validate","config","errors","forEach","field","required"],"mappings":";;;;;;;;;;;;;;;;;;AAAA,eAAe;AACbA,EAAAA,OAAO,EAAE,EADI;AAEbC,EAAAA,iBAAiB,EAAE,YAFN;AAGbC,EAAAA,WAAW,EAAE,SAHA;AAIbC,EAAAA,UAAU,EAAE,WAJC;AAKbC,EAAAA,MAAM,EAAE,EALK;AAMbC,EAAAA,aAAa,EAAE,IANF;AAObC,EAAAA,mBAAmB,EAAE,EAPR;AAQbC,EAAAA,0BAA0B,EAAE,IAAA;AARf,CAAf;;ACEA,MAAMC,aAAa,GAAIC,MAAD,IAAY;AAChC,EAAO,OAAA;AACLC,IAAAA,KAAK,EAAED,MAAM,CAACC,KADT;AAELC,IAAAA,KAAK,EAAEF,MAAM,CAACE,KAAAA;AAFT,GAAP,CAAA;AAID,CALD,CAAA;;AAOO,SAASC,kBAAT,CAA4BC,KAAK,GAAG,EAApC,EAAwC;AAC7C,EAAO,OAAA,IAAIC,OAAJ,CAAaC,OAAD,IAAaA,OAAO,CAAA,QAAA,CAAA,EAAA,EAAMC,QAAN,EAAmBH,KAAnB,CAAA,CAAhC,CAAP,CAAA;AACD,CAAA;AAEM,MAAMI,SAAS,GAAIC,QAAD,iBAAoBF,QAApB,EAAiCE,QAAjC,EAAlB;AAEP;AACA;AACA;AACA;AACA;AACA;;AACO,eAAeL,KAAf,CAAqBK,QAArB,EAA+BC,OAA/B,EAAwCC,GAAxC,EAA6C;AAClD,EAAA,MAAMC,kBAAkB,GAAGJ,SAAS,CAACC,QAAD,CAApC,CAAA;AAEA,EAAIlB,IAAAA,OAAO,GAAGqB,kBAAkB,CAACrB,OAAnB,CAA2BsB,GAA3B,CAA+Bd,aAA/B,CAAd,CAAA;;AAEA,EAAMe,MAAAA,GAAG,gBACJF,kBADI,EAAA;AAEPrB,IAAAA,OAFO;AAGPwB,IAAAA,QAAQ,EAAEJ,GAAG,CAACK,IAAJ,KAAa,QAHhB;AAIPA,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