@pie-element/complex-rubric 7.1.0-next.28 → 7.1.1-next.0

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.
Files changed (118) hide show
  1. package/dist/author/defaults.d.ts +231 -0
  2. package/dist/author/defaults.js +177 -0
  3. package/dist/author/index.d.ts +34 -0
  4. package/dist/author/index.js +87 -0
  5. package/dist/author/main.d.ts +23 -0
  6. package/dist/author/main.js +106 -0
  7. package/dist/controller/defaults.d.ts +39 -0
  8. package/dist/controller/defaults.js +42 -0
  9. package/dist/controller/index.d.ts +25 -0
  10. package/dist/controller/index.js +107 -0
  11. package/dist/controller/utils.d.ts +9 -0
  12. package/dist/controller/utils.js +4 -0
  13. package/dist/delivery/index.d.ts +23 -0
  14. package/dist/delivery/index.js +96 -0
  15. package/dist/index.d.ts +1 -0
  16. package/dist/index.iife.d.ts +8 -0
  17. package/dist/index.iife.js +145 -0
  18. package/dist/index.js +2 -0
  19. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_Symbol.js +5 -0
  20. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_apply.js +12 -0
  21. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_arrayLikeKeys.js +15 -0
  22. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_baseGetTag.js +10 -0
  23. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_baseIsArguments.js +9 -0
  24. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_baseIsNative.js +11 -0
  25. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_baseIsTypedArray.js +11 -0
  26. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_baseKeysIn.js +13 -0
  27. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_baseRest.js +9 -0
  28. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_baseSetToString.js +14 -0
  29. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_baseTimes.js +7 -0
  30. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_baseUnary.js +8 -0
  31. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_coreJsData.js +5 -0
  32. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_defineProperty.js +10 -0
  33. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_freeGlobal.js +4 -0
  34. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_getNative.js +9 -0
  35. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_getRawTag.js +14 -0
  36. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_getValue.js +6 -0
  37. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_isIndex.js +8 -0
  38. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_isIterateeCall.js +12 -0
  39. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_isMasked.js +11 -0
  40. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_isPrototype.js +8 -0
  41. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_nativeKeysIn.js +8 -0
  42. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_nodeUtil.js +9 -0
  43. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_objectToString.js +7 -0
  44. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_overRest.js +13 -0
  45. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_root.js +5 -0
  46. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_setToString.js +6 -0
  47. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_shortOut.js +14 -0
  48. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/_toSource.js +15 -0
  49. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/constant.js +8 -0
  50. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/defaults.js +16 -0
  51. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/eq.js +6 -0
  52. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/identity.js +6 -0
  53. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/isArguments.js +10 -0
  54. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/isArray.js +4 -0
  55. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/isArrayLike.js +8 -0
  56. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/isBuffer.js +6 -0
  57. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/isFunction.js +11 -0
  58. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/isLength.js +7 -0
  59. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/isObject.js +7 -0
  60. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/isObjectLike.js +6 -0
  61. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/isTypedArray.js +7 -0
  62. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/keysIn.js +9 -0
  63. package/dist/node_modules/.bun/lodash-es@4.18.1/node_modules/lodash-es/stubFalse.js +6 -0
  64. package/dist/print/index.d.ts +24 -0
  65. package/dist/print/index.js +84 -0
  66. package/package.json +58 -21
  67. package/CHANGELOG.md +0 -1431
  68. package/LICENSE.md +0 -5
  69. package/README.md +0 -3
  70. package/configure/CHANGELOG.md +0 -1085
  71. package/configure/lib/defaults.js +0 -271
  72. package/configure/lib/defaults.js.map +0 -1
  73. package/configure/lib/index.js +0 -150
  74. package/configure/lib/index.js.map +0 -1
  75. package/configure/lib/main.js +0 -172
  76. package/configure/lib/main.js.map +0 -1
  77. package/configure/package.json +0 -27
  78. package/configure/src/__tests__/index.test.js +0 -94
  79. package/configure/src/__tests__/main.test.jsx +0 -140
  80. package/configure/src/defaults.js +0 -213
  81. package/configure/src/index.js +0 -169
  82. package/configure/src/main.jsx +0 -162
  83. package/controller/CHANGELOG.md +0 -928
  84. package/controller/lib/defaults.js +0 -42
  85. package/controller/lib/defaults.js.map +0 -1
  86. package/controller/lib/index.js +0 -239
  87. package/controller/lib/index.js.map +0 -1
  88. package/controller/lib/utils.js +0 -11
  89. package/controller/lib/utils.js.map +0 -1
  90. package/controller/package.json +0 -16
  91. package/controller/src/__tests__/index.test.js +0 -55
  92. package/controller/src/defaults.js +0 -39
  93. package/controller/src/index.js +0 -220
  94. package/controller/src/utils.js +0 -3
  95. package/docs/config-schema.json +0 -4255
  96. package/docs/config-schema.json.md +0 -3162
  97. package/docs/demo/config.js +0 -8
  98. package/docs/demo/generate.js +0 -196
  99. package/docs/demo/index.html +0 -1
  100. package/docs/demo/session.js +0 -6
  101. package/docs/pie-schema.json +0 -3302
  102. package/docs/pie-schema.json.md +0 -2364
  103. package/lib/index.js +0 -141
  104. package/lib/index.js.map +0 -1
  105. package/lib/print.js +0 -129
  106. package/lib/print.js.map +0 -1
  107. package/module/configure.js +0 -1
  108. package/module/controller.js +0 -262
  109. package/module/demo.js +0 -221
  110. package/module/element.js +0 -1
  111. package/module/index.html +0 -21
  112. package/module/manifest.json +0 -22
  113. package/module/print-demo.js +0 -259
  114. package/module/print.html +0 -18
  115. package/module/print.js +0 -1
  116. package/src/__tests__/index.test.js +0 -256
  117. package/src/index.js +0 -152
  118. package/src/print.js +0 -140
@@ -1,42 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- // todo the import from pie-lib/rubric WILL break pslb
8
- // so don't use it unless you also test "yarn build"
9
- const RUBRIC_TYPES = {
10
- SIMPLE_RUBRIC: 'simpleRubric',
11
- MULTI_TRAIT_RUBRIC: 'multiTraitRubric',
12
- 'rubricless': 'rubricless'
13
- };
14
- const multiTraitDefaultModel = {
15
- description: false,
16
- excludeZero: false,
17
- halfScoring: false,
18
- pointLabels: true,
19
- scales: [],
20
- standards: false,
21
- visibleToStudent: true
22
- };
23
- const rubricDefaultModel = {
24
- points: ['', '', '', ''],
25
- sampleAnswers: [null, null, null, null],
26
- maxPoints: 3,
27
- excludeZero: false
28
- };
29
- const rubriclessDefaultModel = {
30
- maxPoints: 100,
31
- excludeZero: false,
32
- rubriclessInstructionEnabled: true
33
- };
34
- var _default = exports.default = {
35
- rubricType: 'simpleRubric',
36
- rubrics: {
37
- [RUBRIC_TYPES.SIMPLE_RUBRIC]: rubricDefaultModel,
38
- [RUBRIC_TYPES.MULTI_TRAIT_RUBRIC]: multiTraitDefaultModel,
39
- [RUBRIC_TYPES.RUBRICLESS]: rubriclessDefaultModel
40
- }
41
- };
42
- //# sourceMappingURL=defaults.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"defaults.js","names":["RUBRIC_TYPES","SIMPLE_RUBRIC","MULTI_TRAIT_RUBRIC","multiTraitDefaultModel","description","excludeZero","halfScoring","pointLabels","scales","standards","visibleToStudent","rubricDefaultModel","points","sampleAnswers","maxPoints","rubriclessDefaultModel","rubriclessInstructionEnabled","_default","exports","default","rubricType","rubrics","RUBRICLESS"],"sources":["../src/defaults.js"],"sourcesContent":["// todo the import from pie-lib/rubric WILL break pslb\n// so don't use it unless you also test \"yarn build\"\nconst RUBRIC_TYPES = {\n SIMPLE_RUBRIC: 'simpleRubric',\n MULTI_TRAIT_RUBRIC: 'multiTraitRubric',\n 'rubricless': 'rubricless',\n};\n\nconst multiTraitDefaultModel = {\n description: false,\n excludeZero: false,\n halfScoring: false,\n pointLabels: true,\n scales: [],\n standards: false,\n visibleToStudent: true,\n};\n\nconst rubricDefaultModel = {\n points: ['', '', '', ''],\n sampleAnswers: [null, null, null, null],\n maxPoints: 3,\n excludeZero: false,\n};\n\nconst rubriclessDefaultModel = {\n maxPoints: 100,\n excludeZero: false,\n rubriclessInstructionEnabled: true,\n};\n\nexport default {\n rubricType: 'simpleRubric',\n rubrics: {\n [RUBRIC_TYPES.SIMPLE_RUBRIC]: rubricDefaultModel,\n [RUBRIC_TYPES.MULTI_TRAIT_RUBRIC]: multiTraitDefaultModel,\n [RUBRIC_TYPES.RUBRICLESS]: rubriclessDefaultModel,\n },\n};\n"],"mappings":";;;;;;AAAA;AACA;AACA,MAAMA,YAAY,GAAG;EACnBC,aAAa,EAAE,cAAc;EAC7BC,kBAAkB,EAAE,kBAAkB;EACtC,YAAY,EAAE;AAChB,CAAC;AAED,MAAMC,sBAAsB,GAAG;EAC7BC,WAAW,EAAE,KAAK;EAClBC,WAAW,EAAE,KAAK;EAClBC,WAAW,EAAE,KAAK;EAClBC,WAAW,EAAE,IAAI;EACjBC,MAAM,EAAE,EAAE;EACVC,SAAS,EAAE,KAAK;EAChBC,gBAAgB,EAAE;AACpB,CAAC;AAED,MAAMC,kBAAkB,GAAG;EACzBC,MAAM,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC;EACxBC,aAAa,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC;EACvCC,SAAS,EAAE,CAAC;EACZT,WAAW,EAAE;AACf,CAAC;AAED,MAAMU,sBAAsB,GAAG;EAC7BD,SAAS,EAAE,GAAG;EACdT,WAAW,EAAE,KAAK;EAClBW,4BAA4B,EAAE;AAChC,CAAC;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEa;EACbC,UAAU,EAAE,cAAc;EAC1BC,OAAO,EAAE;IACP,CAACrB,YAAY,CAACC,aAAa,GAAGU,kBAAkB;IAChD,CAACX,YAAY,CAACE,kBAAkB,GAAGC,sBAAsB;IACzD,CAACH,YAAY,CAACsB,UAAU,GAAGP;EAC7B;AACF,CAAC","ignoreList":[]}
@@ -1,239 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.createCorrectResponseSession = void 0;
8
- exports.createDefaultModel = createDefaultModel;
9
- exports.getScore = void 0;
10
- exports.model = model;
11
- exports.normalize = void 0;
12
- exports.outcome = outcome;
13
- exports.validate = void 0;
14
- var _defaults = _interopRequireDefault(require("./defaults"));
15
- var _utils = require("./utils");
16
- // todo the import from pie-lib/rubric WILL break pslb
17
- // so don't use it unless you also test "yarn build"
18
- const RUBRIC_TYPES = {
19
- SIMPLE_RUBRIC: 'simpleRubric',
20
- MULTI_TRAIT_RUBRIC: 'multiTraitRubric',
21
- 'rubricless': 'rubricless'
22
- };
23
- function createDefaultModel(model = {}) {
24
- return new Promise(resolve => resolve({
25
- ..._defaults.default,
26
- ...model
27
- }));
28
- }
29
- const normalize = question => ({
30
- ..._defaults.default,
31
- ...question
32
- });
33
-
34
- /**
35
- * @param {*} question
36
- * @param {*} session
37
- * @param {*} env
38
- */
39
- exports.normalize = normalize;
40
- async function model(question, session, env) {
41
- const normalizedQuestion = normalize(question);
42
- if (normalizedQuestion.rubricType === RUBRIC_TYPES.SIMPLE_RUBRIC || normalizedQuestion.rubricType === RUBRIC_TYPES.RUBRICLESS) {
43
- return new Promise(resolve => {
44
- resolve(env && env.role && env.role === 'instructor' ? {
45
- ...normalizedQuestion,
46
- rubrics: {
47
- ...normalizedQuestion.rubrics,
48
- multiTraitRubric: {
49
- ...normalizedQuestion.rubrics.multiTraitRubric,
50
- visible: false
51
- }
52
- }
53
- } : {});
54
- });
55
- } else {
56
- if (!env.role || env.role === 'student' && normalizedQuestion.rubrics && normalizedQuestion.rubrics.multiTraitRubric) {
57
- normalizedQuestion.rubrics.multiTraitRubric.visible = normalizedQuestion.visibleToStudent;
58
- } else {
59
- normalizedQuestion.rubrics.multiTraitRubric.visible = true;
60
- }
61
-
62
- // todo update pie-ui instead of parsing this here:
63
- const {
64
- scales,
65
- excludeZero
66
- } = normalizedQuestion.rubrics.multiTraitRubric || {};
67
- const parsedScales = (scales || []).map(scale => ({
68
- ...scale,
69
- excludeZero
70
- }));
71
- return {
72
- ...normalizedQuestion,
73
- rubrics: {
74
- ...normalizedQuestion.rubrics,
75
- simpleRubric: {
76
- ...normalizedQuestion.rubrics.simpleRubric,
77
- visible: false
78
- },
79
- rubricless: {
80
- ...normalizedQuestion.rubrics.rubricless,
81
- visible: false
82
- },
83
- multiTraitRubric: {
84
- ...normalizedQuestion.rubrics.multiTraitRubric,
85
- scales: parsedScales
86
- }
87
- }
88
- };
89
- }
90
- }
91
- const getScore = () => 0;
92
-
93
- /**
94
- * @param {Object} model - the main model
95
- * @param {*} session
96
- * @param {Object} env
97
- */
98
- exports.getScore = getScore;
99
- function outcome() {
100
- return new Promise(resolve => resolve({
101
- score: 0,
102
- empty: true
103
- }));
104
- }
105
- const createCorrectResponseSession = (question, env) => {
106
- return new Promise(resolve => {
107
- if (env.mode !== 'evaluate' && env.role === 'instructor') {
108
- resolve({
109
- id: '1'
110
- });
111
- } else {
112
- resolve(null);
113
- }
114
- });
115
- };
116
-
117
- // IMPORTANT! This function is a duplicate of rubric/controller/validate function!
118
- // If you make any changes to this function, please make sure you also update rubric/controller/validate function!“.
119
- exports.createCorrectResponseSession = createCorrectResponseSession;
120
- const validateSimpleRubric = model => {
121
- const {
122
- points
123
- } = model;
124
- const errors = {};
125
- const pointsDescriptorsErrors = {};
126
- (points || []).forEach((point, index) => {
127
- if (!point || point === '<div></div>') {
128
- pointsDescriptorsErrors[index] = 'Points descriptors cannot be empty.';
129
- } else {
130
- const identicalPointDescr = points.slice(index + 1).some(p => (0, _utils.markupToText)(p) === (0, _utils.markupToText)(point));
131
- if (identicalPointDescr) {
132
- pointsDescriptorsErrors[index] = 'Points descriptors should be unique.';
133
- }
134
- }
135
- });
136
- if (Object.keys(pointsDescriptorsErrors).length > 0) {
137
- errors.pointsDescriptorsErrors = pointsDescriptorsErrors;
138
- }
139
- return errors;
140
- };
141
-
142
- // IMPORTANT! This function is a duplicate of multi-trait-rubric/controller/validate function!
143
- // If you make any changes to this function, please make sure you also update multi-trait-rubric/controller/validate function!“.
144
- const validateMultiTraitRubric = model => {
145
- const {
146
- scales,
147
- description = false,
148
- pointLabels = false
149
- } = model;
150
- const errors = {};
151
- const traitsErrors = {};
152
- const scorePointsErrors = {};
153
- (scales || []).forEach((scale, scaleIndex) => {
154
- const {
155
- traits = []
156
- } = scale;
157
- const {
158
- scorePointsLabels = []
159
- } = scale;
160
- const scaleErrors = {};
161
- const scorePointsLabelsErrors = {};
162
- if (pointLabels) {
163
- scorePointsLabels.forEach((scorePointLabel, scoreIndex) => {
164
- if (!scorePointLabel || scorePointLabel === '<div></div>') {
165
- scorePointsLabelsErrors[scoreIndex] = 'Points labels should not be empty.';
166
- } else {
167
- const identicalScorePointLabel = scorePointsLabels.slice(scoreIndex + 1).some(s => (0, _utils.markupToText)(s) === (0, _utils.markupToText)(scorePointLabel));
168
- if (identicalScorePointLabel) {
169
- scorePointsLabelsErrors[scoreIndex] = 'Points labels should be unique.';
170
- }
171
- }
172
- });
173
- }
174
- if (Object.keys(scorePointsLabelsErrors).length > 0) {
175
- scorePointsErrors[scaleIndex] = scorePointsLabelsErrors;
176
- }
177
- traits.forEach((trait, traitIndex) => {
178
- if (!trait.name || trait.name === '<div></div>') {
179
- scaleErrors[traitIndex] = {
180
- name: 'Trait names should not be empty.'
181
- };
182
- } else {
183
- const identicalTraitName = traits.slice(traitIndex + 1).some(t => (0, _utils.markupToText)(t.name) === (0, _utils.markupToText)(trait.name));
184
- if (identicalTraitName) {
185
- scaleErrors[traitIndex] = {
186
- name: 'Trait names should be unique.'
187
- };
188
- }
189
- }
190
- if (description && (!trait.description || trait.description === '<div></div>')) {
191
- scaleErrors[traitIndex] = {
192
- ...scaleErrors[traitIndex],
193
- description: 'Trait description should not be empty'
194
- };
195
- } else {
196
- const identicalTraitDescr = traits.slice(traitIndex + 1).some(t => (0, _utils.markupToText)(t.description) === (0, _utils.markupToText)(trait.description));
197
- if (description && identicalTraitDescr) {
198
- scaleErrors[traitIndex] = {
199
- ...scaleErrors[traitIndex],
200
- description: 'Trait descriptions should be unique.'
201
- };
202
- }
203
- }
204
- });
205
- if (Object.keys(scaleErrors).length > 0) {
206
- traitsErrors[scaleIndex] = scaleErrors;
207
- }
208
- });
209
- if (Object.keys(traitsErrors).length > 0) {
210
- errors.traitsErrors = traitsErrors;
211
- }
212
- if (Object.keys(scorePointsErrors).length > 0) {
213
- errors.scorePointsErrors = scorePointsErrors;
214
- }
215
- return errors;
216
- };
217
- const validate = (model = {}, config = {}) => {
218
- const {
219
- rubrics = {},
220
- rubricType
221
- } = model;
222
- const {
223
- multiTraitRubric = {},
224
- simpleRubric = {}
225
- } = rubrics;
226
- let errors = {};
227
- switch (rubricType) {
228
- case RUBRIC_TYPES.SIMPLE_RUBRIC:
229
- default:
230
- errors = validateSimpleRubric(simpleRubric);
231
- break;
232
- case RUBRIC_TYPES.MULTI_TRAIT_RUBRIC:
233
- errors = validateMultiTraitRubric(multiTraitRubric);
234
- break;
235
- }
236
- return errors;
237
- };
238
- exports.validate = validate;
239
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","names":["_defaults","_interopRequireDefault","require","_utils","RUBRIC_TYPES","SIMPLE_RUBRIC","MULTI_TRAIT_RUBRIC","createDefaultModel","model","Promise","resolve","defaults","normalize","question","exports","session","env","normalizedQuestion","rubricType","RUBRICLESS","role","rubrics","multiTraitRubric","visible","visibleToStudent","scales","excludeZero","parsedScales","map","scale","simpleRubric","rubricless","getScore","outcome","score","empty","createCorrectResponseSession","mode","id","validateSimpleRubric","points","errors","pointsDescriptorsErrors","forEach","point","index","identicalPointDescr","slice","some","p","markupToText","Object","keys","length","validateMultiTraitRubric","description","pointLabels","traitsErrors","scorePointsErrors","scaleIndex","traits","scorePointsLabels","scaleErrors","scorePointsLabelsErrors","scorePointLabel","scoreIndex","identicalScorePointLabel","s","trait","traitIndex","name","identicalTraitName","t","identicalTraitDescr","validate","config"],"sources":["../src/index.js"],"sourcesContent":["import defaults from './defaults';\nimport { markupToText } from './utils';\n\n\n// todo the import from pie-lib/rubric WILL break pslb\n// so don't use it unless you also test \"yarn build\"\nconst RUBRIC_TYPES = {\n SIMPLE_RUBRIC: 'simpleRubric',\n MULTI_TRAIT_RUBRIC: 'multiTraitRubric',\n 'rubricless': 'rubricless',\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 * @param {*} question\n * @param {*} session\n * @param {*} env\n */\nexport async function model(question, session, env) {\n const normalizedQuestion = normalize(question);\n\n if (\n normalizedQuestion.rubricType === RUBRIC_TYPES.SIMPLE_RUBRIC ||\n normalizedQuestion.rubricType === RUBRIC_TYPES.RUBRICLESS\n ) {\n return new Promise((resolve) => {\n resolve(\n env && env.role && env.role === 'instructor'\n ? {\n ...normalizedQuestion,\n rubrics: {\n ...normalizedQuestion.rubrics,\n multiTraitRubric: {\n ...normalizedQuestion.rubrics.multiTraitRubric,\n visible: false,\n },\n },\n }\n : {},\n );\n });\n } else {\n if (\n !env.role ||\n (env.role === 'student' && normalizedQuestion.rubrics && normalizedQuestion.rubrics.multiTraitRubric)\n ) {\n normalizedQuestion.rubrics.multiTraitRubric.visible = normalizedQuestion.visibleToStudent;\n } else {\n normalizedQuestion.rubrics.multiTraitRubric.visible = true;\n }\n\n // todo update pie-ui instead of parsing this here:\n const { scales, excludeZero } = normalizedQuestion.rubrics.multiTraitRubric || {};\n const parsedScales = (scales || []).map((scale) => ({ ...scale, excludeZero }));\n\n return {\n ...normalizedQuestion,\n rubrics: {\n ...normalizedQuestion.rubrics,\n simpleRubric: {\n ...normalizedQuestion.rubrics.simpleRubric,\n visible: false,\n },\n rubricless: {\n ...normalizedQuestion.rubrics.rubricless,\n visible: false,\n },\n multiTraitRubric: {\n ...normalizedQuestion.rubrics.multiTraitRubric,\n scales: parsedScales,\n },\n },\n };\n }\n}\n\nexport const getScore = () => 0;\n\n/**\n * @param {Object} model - the main model\n * @param {*} session\n * @param {Object} env\n */\nexport function outcome() {\n return new Promise((resolve) => resolve({ score: 0, empty: true }));\n}\n\nexport const createCorrectResponseSession = (question, env) => {\n return new Promise((resolve) => {\n if (env.mode !== 'evaluate' && env.role === 'instructor') {\n resolve({ id: '1' });\n } else {\n resolve(null);\n }\n });\n};\n\n// IMPORTANT! This function is a duplicate of rubric/controller/validate function!\n// If you make any changes to this function, please make sure you also update rubric/controller/validate function!“.\nconst validateSimpleRubric = (model) => {\n const { points } = model;\n const errors = {};\n const pointsDescriptorsErrors = {};\n\n (points || []).forEach((point, index) => {\n\n if (!point || point === '<div></div>') {\n pointsDescriptorsErrors[index] = 'Points descriptors cannot be empty.';\n } else {\n const identicalPointDescr = points.slice(index + 1).some((p) => markupToText(p) === markupToText(point));\n\n if (identicalPointDescr) {\n pointsDescriptorsErrors[index] = 'Points descriptors should be unique.';\n }\n }\n });\n\n if (Object.keys(pointsDescriptorsErrors).length > 0) {\n errors.pointsDescriptorsErrors = pointsDescriptorsErrors;\n }\n\n return errors;\n};\n\n// IMPORTANT! This function is a duplicate of multi-trait-rubric/controller/validate function!\n// If you make any changes to this function, please make sure you also update multi-trait-rubric/controller/validate function!“.\nconst validateMultiTraitRubric = (model) => {\n const { scales, description = false, pointLabels = false } = model;\n const errors = {};\n const traitsErrors = {};\n const scorePointsErrors = {};\n\n (scales || []).forEach((scale, scaleIndex) => {\n const { traits = [] } = scale;\n const { scorePointsLabels = [] } = scale;\n const scaleErrors = {};\n const scorePointsLabelsErrors = {};\n\n if (pointLabels) {\n scorePointsLabels.forEach((scorePointLabel, scoreIndex) => {\n if (!scorePointLabel || scorePointLabel === '<div></div>') {\n scorePointsLabelsErrors[scoreIndex] = 'Points labels should not be empty.';\n } else {\n const identicalScorePointLabel = scorePointsLabels\n .slice(scoreIndex + 1)\n .some((s) => markupToText(s) === markupToText(scorePointLabel));\n\n if (identicalScorePointLabel) {\n scorePointsLabelsErrors[scoreIndex] = 'Points labels should be unique.';\n }\n }\n });\n }\n\n if (Object.keys(scorePointsLabelsErrors).length > 0) {\n scorePointsErrors[scaleIndex] = scorePointsLabelsErrors;\n }\n\n traits.forEach((trait, traitIndex) => {\n if (!trait.name || trait.name === '<div></div>') {\n scaleErrors[traitIndex] = { name: 'Trait names should not be empty.' };\n } else {\n const identicalTraitName = traits\n .slice(traitIndex + 1)\n .some((t) => markupToText(t.name) === markupToText(trait.name));\n\n if (identicalTraitName) {\n scaleErrors[traitIndex] = { name: 'Trait names should be unique.' };\n }\n }\n if (description && (!trait.description || trait.description === '<div></div>')) {\n scaleErrors[traitIndex] = { ...scaleErrors[traitIndex], description: 'Trait description should not be empty' };\n } else {\n const identicalTraitDescr = traits\n .slice(traitIndex + 1)\n .some((t) => markupToText(t.description) === markupToText(trait.description));\n\n if (description && identicalTraitDescr) {\n scaleErrors[traitIndex] = { ...scaleErrors[traitIndex], description: 'Trait descriptions should be unique.' };\n }\n }\n });\n if (Object.keys(scaleErrors).length > 0) {\n traitsErrors[scaleIndex] = scaleErrors;\n }\n });\n\n if (Object.keys(traitsErrors).length > 0) {\n errors.traitsErrors = traitsErrors;\n }\n\n if (Object.keys(scorePointsErrors).length > 0) {\n errors.scorePointsErrors = scorePointsErrors;\n }\n\n return errors;\n};\n\nexport const validate = (model = {}, config = {}) => {\n const { rubrics = {}, rubricType } = model;\n const { multiTraitRubric = {}, simpleRubric = {} } = rubrics;\n let errors = {};\n\n switch (rubricType) {\n case RUBRIC_TYPES.SIMPLE_RUBRIC:\n default:\n errors = validateSimpleRubric(simpleRubric);\n break;\n case RUBRIC_TYPES.MULTI_TRAIT_RUBRIC:\n errors = validateMultiTraitRubric(multiTrait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CI,YAAY,CAACE,UAAU,CAAC,GAAGG,WAAW;IACxC;EACF,CAAC,CAAC;EAEF,IAAIX,MAAM,CAACC,IAAI,CAACK,YAAY,CAAC,CAACJ,MAAM,GAAG,CAAC,EAAE;IACxCZ,MAAM,CAACgB,YAAY,GAAGA,YAAY;EACpC;EAEA,IAAIN,MAAM,CAACC,IAAI,CAACM,iBAAiB,CAAC,CAACL,MAAM,GAAG,CAAC,EAAE;IAC7CZ,MAAM,CAACiB,iBAAiB,GAAGA,iBAAiB;EAC9C;EAEA,OAAOjB,MAAM;AACf,CAAC;AAEM,MAAMiC,QAAQ,GAAGA,CAAClE,KAAK,GAAG,CAAC,CAAC,EAAEmE,MAAM,GAAG,CAAC,CAAC,KAAK;EACnD,MAAM;IAAEtD,OAAO,GAAG,CAAC,CAAC;IAAEH;EAAW,CAAC,GAAGV,KAAK;EAC1C,MAAM;IAAEc,gBAAgB,GAAG,CAAC,CAAC;IAAEQ,YAAY,GAAG,CAAC;EAAE,CAAC,GAAGT,OAAO;EAC5D,IAAIoB,MAAM,GAAG,CAAC,CAAC;EAEf,QAAQvB,UAAU;IAChB,KAAKd,YAAY,CAACC,aAAa;IAC/B;MACEoC,MAAM,GAAGF,oBAAoB,CAACT,YAAY,CAAC;MAC3C;IACF,KAAK1B,YAAY,CAACE,kBAAkB;MAClCmC,MAAM,GAAGa,wBAAwB,CAAChC,gBAAgB,CAAC;MACnD;EACJ;EAEA,OAAOmB,MAAM;AACf,CAAC;AAAC3B,OAAA,CAAA4D,QAAA,GAAAA,QAAA","ignoreList":[]}
@@ -1,11 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.markupToText = void 0;
7
- const markupToText = s => {
8
- return (s || '').replace(/(<([^>]+)>)/ig, '');
9
- };
10
- exports.markupToText = markupToText;
11
- //# sourceMappingURL=utils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.js","names":["markupToText","s","replace","exports"],"sources":["../src/utils.js"],"sourcesContent":["export const markupToText = (s) => {\n return (s || '').replace(/(<([^>]+)>)/ig, '');\n};\n"],"mappings":";;;;;;AAAO,MAAMA,YAAY,GAAIC,CAAC,IAAK;EAC/B,OAAO,CAACA,CAAC,IAAI,EAAE,EAAEC,OAAO,CAAC,eAAe,EAAE,EAAE,CAAC;AACjD,CAAC;AAACC,OAAA,CAAAH,YAAA,GAAAA,YAAA","ignoreList":[]}
@@ -1,16 +0,0 @@
1
- {
2
- "name": "@pie-element/complex-rubric-controller",
3
- "private": true,
4
- "version": "6.0.2-next.0",
5
- "description": "",
6
- "scripts": {
7
- "test": "echo \"Error: no test specified\" && exit 1"
8
- },
9
- "dependencies": {
10
- "lodash-es": "^4.17.23"
11
- },
12
- "author": "",
13
- "license": "ISC",
14
- "main": "lib/index.js",
15
- "module": "src/index.js"
16
- }
@@ -1,55 +0,0 @@
1
- import { model } from '../index';
2
- import defaultModel from '../defaults';
3
-
4
- describe('complex rubric model', () => {
5
- let state = { ...defaultModel };
6
- let session = {};
7
- let env, result;
8
-
9
- it('returns no model for gather', async () => {
10
- env = { mode: 'gather' };
11
- result = await model(state, session, env);
12
- expect(result).toEqual({});
13
- });
14
-
15
- it('returns no model for student role', async () => {
16
- env = { mode: 'gather', role: 'student' };
17
- result = await model(state, session, env);
18
- expect(result).toEqual({});
19
- });
20
-
21
- it('returns model for instructor role and simple rubric', async () => {
22
- env = { mode: 'gather', role: 'instructor' };
23
- result = await model(state, session, env);
24
- expect(result).toEqual({
25
- ...state,
26
- rubrics: {
27
- ...state.rubrics,
28
- multiTraitRubric: {
29
- ...state.rubrics.multiTraitRubric,
30
- visible: false,
31
- },
32
- },
33
- });
34
- });
35
-
36
- it('returns model for instructor role and multi trait rubric', async () => {
37
- env = { mode: 'gather', role: 'instructor' };
38
- result = await model({ ...state, rubricType: 'multiTraitRubric' }, session, env);
39
- expect(result).toEqual({
40
- ...state,
41
- rubricType: 'multiTraitRubric',
42
- rubrics: {
43
- ...state.rubrics,
44
- simpleRubric: {
45
- ...state.rubrics.simpleRubric,
46
- visible: false,
47
- },
48
- rubricless: {
49
- ...state.rubrics.rubricless,
50
- visible: false,
51
- },
52
- },
53
- });
54
- });
55
- });
@@ -1,39 +0,0 @@
1
- // todo the import from pie-lib/rubric WILL break pslb
2
- // so don't use it unless you also test "yarn build"
3
- const RUBRIC_TYPES = {
4
- SIMPLE_RUBRIC: 'simpleRubric',
5
- MULTI_TRAIT_RUBRIC: 'multiTraitRubric',
6
- 'rubricless': 'rubricless',
7
- };
8
-
9
- const multiTraitDefaultModel = {
10
- description: false,
11
- excludeZero: false,
12
- halfScoring: false,
13
- pointLabels: true,
14
- scales: [],
15
- standards: false,
16
- visibleToStudent: true,
17
- };
18
-
19
- const rubricDefaultModel = {
20
- points: ['', '', '', ''],
21
- sampleAnswers: [null, null, null, null],
22
- maxPoints: 3,
23
- excludeZero: false,
24
- };
25
-
26
- const rubriclessDefaultModel = {
27
- maxPoints: 100,
28
- excludeZero: false,
29
- rubriclessInstructionEnabled: true,
30
- };
31
-
32
- export default {
33
- rubricType: 'simpleRubric',
34
- rubrics: {
35
- [RUBRIC_TYPES.SIMPLE_RUBRIC]: rubricDefaultModel,
36
- [RUBRIC_TYPES.MULTI_TRAIT_RUBRIC]: multiTraitDefaultModel,
37
- [RUBRIC_TYPES.RUBRICLESS]: rubriclessDefaultModel,
38
- },
39
- };
@@ -1,220 +0,0 @@
1
- import defaults from './defaults';
2
- import { markupToText } from './utils';
3
-
4
-
5
- // todo the import from pie-lib/rubric WILL break pslb
6
- // so don't use it unless you also test "yarn build"
7
- const RUBRIC_TYPES = {
8
- SIMPLE_RUBRIC: 'simpleRubric',
9
- MULTI_TRAIT_RUBRIC: 'multiTraitRubric',
10
- 'rubricless': 'rubricless',
11
- };
12
-
13
- export function createDefaultModel(model = {}) {
14
- return new Promise((resolve) => resolve({ ...defaults, ...model }));
15
- }
16
-
17
- export const normalize = (question) => ({ ...defaults, ...question });
18
-
19
- /**
20
- * @param {*} question
21
- * @param {*} session
22
- * @param {*} env
23
- */
24
- export async function model(question, session, env) {
25
- const normalizedQuestion = normalize(question);
26
-
27
- if (
28
- normalizedQuestion.rubricType === RUBRIC_TYPES.SIMPLE_RUBRIC ||
29
- normalizedQuestion.rubricType === RUBRIC_TYPES.RUBRICLESS
30
- ) {
31
- return new Promise((resolve) => {
32
- resolve(
33
- env && env.role && env.role === 'instructor'
34
- ? {
35
- ...normalizedQuestion,
36
- rubrics: {
37
- ...normalizedQuestion.rubrics,
38
- multiTraitRubric: {
39
- ...normalizedQuestion.rubrics.multiTraitRubric,
40
- visible: false,
41
- },
42
- },
43
- }
44
- : {},
45
- );
46
- });
47
- } else {
48
- if (
49
- !env.role ||
50
- (env.role === 'student' && normalizedQuestion.rubrics && normalizedQuestion.rubrics.multiTraitRubric)
51
- ) {
52
- normalizedQuestion.rubrics.multiTraitRubric.visible = normalizedQuestion.visibleToStudent;
53
- } else {
54
- normalizedQuestion.rubrics.multiTraitRubric.visible = true;
55
- }
56
-
57
- // todo update pie-ui instead of parsing this here:
58
- const { scales, excludeZero } = normalizedQuestion.rubrics.multiTraitRubric || {};
59
- const parsedScales = (scales || []).map((scale) => ({ ...scale, excludeZero }));
60
-
61
- return {
62
- ...normalizedQuestion,
63
- rubrics: {
64
- ...normalizedQuestion.rubrics,
65
- simpleRubric: {
66
- ...normalizedQuestion.rubrics.simpleRubric,
67
- visible: false,
68
- },
69
- rubricless: {
70
- ...normalizedQuestion.rubrics.rubricless,
71
- visible: false,
72
- },
73
- multiTraitRubric: {
74
- ...normalizedQuestion.rubrics.multiTraitRubric,
75
- scales: parsedScales,
76
- },
77
- },
78
- };
79
- }
80
- }
81
-
82
- export const getScore = () => 0;
83
-
84
- /**
85
- * @param {Object} model - the main model
86
- * @param {*} session
87
- * @param {Object} env
88
- */
89
- export function outcome() {
90
- return new Promise((resolve) => resolve({ score: 0, empty: true }));
91
- }
92
-
93
- export const createCorrectResponseSession = (question, env) => {
94
- return new Promise((resolve) => {
95
- if (env.mode !== 'evaluate' && env.role === 'instructor') {
96
- resolve({ id: '1' });
97
- } else {
98
- resolve(null);
99
- }
100
- });
101
- };
102
-
103
- // IMPORTANT! This function is a duplicate of rubric/controller/validate function!
104
- // If you make any changes to this function, please make sure you also update rubric/controller/validate function!“.
105
- const validateSimpleRubric = (model) => {
106
- const { points } = model;
107
- const errors = {};
108
- const pointsDescriptorsErrors = {};
109
-
110
- (points || []).forEach((point, index) => {
111
-
112
- if (!point || point === '<div></div>') {
113
- pointsDescriptorsErrors[index] = 'Points descriptors cannot be empty.';
114
- } else {
115
- const identicalPointDescr = points.slice(index + 1).some((p) => markupToText(p) === markupToText(point));
116
-
117
- if (identicalPointDescr) {
118
- pointsDescriptorsErrors[index] = 'Points descriptors should be unique.';
119
- }
120
- }
121
- });
122
-
123
- if (Object.keys(pointsDescriptorsErrors).length > 0) {
124
- errors.pointsDescriptorsErrors = pointsDescriptorsErrors;
125
- }
126
-
127
- return errors;
128
- };
129
-
130
- // IMPORTANT! This function is a duplicate of multi-trait-rubric/controller/validate function!
131
- // If you make any changes to this function, please make sure you also update multi-trait-rubric/controller/validate function!“.
132
- const validateMultiTraitRubric = (model) => {
133
- const { scales, description = false, pointLabels = false } = model;
134
- const errors = {};
135
- const traitsErrors = {};
136
- const scorePointsErrors = {};
137
-
138
- (scales || []).forEach((scale, scaleIndex) => {
139
- const { traits = [] } = scale;
140
- const { scorePointsLabels = [] } = scale;
141
- const scaleErrors = {};
142
- const scorePointsLabelsErrors = {};
143
-
144
- if (pointLabels) {
145
- scorePointsLabels.forEach((scorePointLabel, scoreIndex) => {
146
- if (!scorePointLabel || scorePointLabel === '<div></div>') {
147
- scorePointsLabelsErrors[scoreIndex] = 'Points labels should not be empty.';
148
- } else {
149
- const identicalScorePointLabel = scorePointsLabels
150
- .slice(scoreIndex + 1)
151
- .some((s) => markupToText(s) === markupToText(scorePointLabel));
152
-
153
- if (identicalScorePointLabel) {
154
- scorePointsLabelsErrors[scoreIndex] = 'Points labels should be unique.';
155
- }
156
- }
157
- });
158
- }
159
-
160
- if (Object.keys(scorePointsLabelsErrors).length > 0) {
161
- scorePointsErrors[scaleIndex] = scorePointsLabelsErrors;
162
- }
163
-
164
- traits.forEach((trait, traitIndex) => {
165
- if (!trait.name || trait.name === '<div></div>') {
166
- scaleErrors[traitIndex] = { name: 'Trait names should not be empty.' };
167
- } else {
168
- const identicalTraitName = traits
169
- .slice(traitIndex + 1)
170
- .some((t) => markupToText(t.name) === markupToText(trait.name));
171
-
172
- if (identicalTraitName) {
173
- scaleErrors[traitIndex] = { name: 'Trait names should be unique.' };
174
- }
175
- }
176
- if (description && (!trait.description || trait.description === '<div></div>')) {
177
- scaleErrors[traitIndex] = { ...scaleErrors[traitIndex], description: 'Trait description should not be empty' };
178
- } else {
179
- const identicalTraitDescr = traits
180
- .slice(traitIndex + 1)
181
- .some((t) => markupToText(t.description) === markupToText(trait.description));
182
-
183
- if (description && identicalTraitDescr) {
184
- scaleErrors[traitIndex] = { ...scaleErrors[traitIndex], description: 'Trait descriptions should be unique.' };
185
- }
186
- }
187
- });
188
- if (Object.keys(scaleErrors).length > 0) {
189
- traitsErrors[scaleIndex] = scaleErrors;
190
- }
191
- });
192
-
193
- if (Object.keys(traitsErrors).length > 0) {
194
- errors.traitsErrors = traitsErrors;
195
- }
196
-
197
- if (Object.keys(scorePointsErrors).length > 0) {
198
- errors.scorePointsErrors = scorePointsErrors;
199
- }
200
-
201
- return errors;
202
- };
203
-
204
- export const validate = (model = {}, config = {}) => {
205
- const { rubrics = {}, rubricType } = model;
206
- const { multiTraitRubric = {}, simpleRubric = {} } = rubrics;
207
- let errors = {};
208
-
209
- switch (rubricType) {
210
- case RUBRIC_TYPES.SIMPLE_RUBRIC:
211
- default:
212
- errors = validateSimpleRubric(simpleRubric);
213
- break;
214
- case RUBRIC_TYPES.MULTI_TRAIT_RUBRIC:
215
- errors = validateMultiTraitRubric(multiTraitRubric);
216
- break;
217
- }
218
-
219
- return errors;
220
- };
@@ -1,3 +0,0 @@
1
- export const markupToText = (s) => {
2
- return (s || '').replace(/(<([^>]+)>)/ig, '');
3
- };