@pie-element/rubric 3.10.1-next.1 → 3.10.1-next.2

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.
@@ -0,0 +1,52 @@
1
+ var lib = {};
2
+
3
+ Object.defineProperty(lib, "__esModule", {
4
+ value: true
5
+ });
6
+ var model_1 = lib.model = model;
7
+ var validate_1 = lib.validate = validate;
8
+
9
+ function model(model, session, env) {
10
+ return new Promise(function (resolve) {
11
+ var modelResult = !model ? {} : model;
12
+ resolve(env && env.role && env.role === 'instructor' ? modelResult : {});
13
+ });
14
+ }
15
+
16
+ function markupToText(s) {
17
+ return (s || '').replace(/(<([^>]+)>)/ig, '');
18
+ } // IMPORTANT! If you make any changes to this function, please make sure you also update complex-rubric/controller/validateSimpleRubric function!“.
19
+
20
+
21
+ function validate(model, config) {
22
+ var points = model.points,
23
+ excludeZero = model.excludeZero;
24
+ var errors = {};
25
+ var pointsDescriptorsErrors = {};
26
+ (points || []).forEach(function (point, index) {
27
+ if (index === 0 && excludeZero) {
28
+ // if excludeZero is true, the 0 point is not displayed, so it should not be validated
29
+ return;
30
+ }
31
+
32
+ if (!point || point === '<div></div>') {
33
+ pointsDescriptorsErrors[index] = 'Points descriptors cannot be empty.';
34
+ } else {
35
+ var identicalPointDescr = points.slice(index + 1).some(function (p) {
36
+ return markupToText(p) === markupToText(point);
37
+ });
38
+
39
+ if (identicalPointDescr) {
40
+ pointsDescriptorsErrors[index] = 'Points descriptors should be unique.';
41
+ }
42
+ }
43
+ });
44
+
45
+ if (Object.keys(pointsDescriptorsErrors).length > 0) {
46
+ errors.pointsDescriptorsErrors = pointsDescriptorsErrors;
47
+ }
48
+
49
+ return errors;
50
+ }
51
+
52
+ export { lib as default, model_1 as model, validate_1 as validate };
package/module/demo.js ADDED
@@ -0,0 +1,33 @@
1
+ import Configure from './configure.js';
2
+ import Element from './element.js';
3
+ import * as controller from './controller.js';
4
+
5
+ var generate = {};
6
+
7
+ generate.model = (id, element) => ({
8
+ id,
9
+ element,
10
+ points: ['nothing right', 'a teeny bit right', 'mostly right', 'bingo'],
11
+ sampleAnswers: [null, 'just right', 'not left', null],
12
+ maxPoints: 3,
13
+ excludeZero: false,
14
+ });
15
+
16
+ const { model } = generate;
17
+
18
+ var config = {
19
+ elements: {
20
+ 'pie-rubric': '../..',
21
+ },
22
+ models: [model('1', 'pie-rubric')],
23
+ };
24
+
25
+ //Note: demo-el is a custom element loaded in the markup.
26
+ customElements.whenDefined("demo-el").then(() => {
27
+ config.models.forEach((m) => {
28
+ const de = document.createElement("demo-el");
29
+ document.body.appendChild(de);
30
+ de.def = { tagName: m.element, Element, Configure, controller };
31
+ de.model = m;
32
+ });
33
+ });