@pie-element/image-cloze-association 3.5.0 → 3.5.1-beta.587
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/CHANGELOG.md +478 -0
- package/configure/CHANGELOG.md +390 -0
- package/configure/lib/defaults.js +16 -0
- package/configure/lib/defaults.js.map +1 -1
- package/configure/lib/index.js +17 -3
- package/configure/lib/index.js.map +1 -1
- package/configure/lib/root.js +43 -13
- package/configure/lib/root.js.map +1 -1
- package/configure/package.json +4 -3
- package/configure/src/__tests__/index.test.js +12 -15
- package/configure/src/defaults.js +20 -4
- package/configure/src/index.js +23 -3
- package/configure/src/root.jsx +41 -25
- package/controller/CHANGELOG.md +63 -0
- package/controller/lib/index.js +9 -8
- package/controller/lib/index.js.map +1 -1
- package/controller/lib/utils.js +4 -4
- package/controller/lib/utils.js.map +1 -1
- package/controller/package.json +2 -2
- package/controller/src/__tests__/index.test.js +108 -62
- package/controller/src/index.js +40 -28
- package/controller/src/utils.js +10 -10
- package/docs/config-schema.json +160 -0
- package/docs/config-schema.json.md +127 -0
- package/docs/demo/config.js +2 -2
- package/docs/demo/generate.js +30 -25
- package/docs/demo/session.js +1 -1
- package/docs/pie-schema.json +378 -0
- package/docs/pie-schema.json.md +295 -0
- package/lib/constants.js.map +1 -1
- package/lib/evaluation-icon.js.map +1 -1
- package/lib/image-container.js +13 -6
- package/lib/image-container.js.map +1 -1
- package/lib/image-drop-target.js +7 -2
- package/lib/image-drop-target.js.map +1 -1
- package/lib/index.js +4 -1
- package/lib/index.js.map +1 -1
- package/lib/interactive-section.js +1 -1
- package/lib/interactive-section.js.map +1 -1
- package/lib/possible-response.js +17 -5
- package/lib/possible-response.js.map +1 -1
- package/lib/possible-responses.js.map +1 -1
- package/lib/root.js +140 -19
- package/lib/root.js.map +1 -1
- package/lib/utils-correctness.js +33 -5
- package/lib/utils-correctness.js.map +1 -1
- package/package.json +8 -5
- package/src/__tests__/__snapshots__/{image-container-test.jsx.snap → image-container.test.jsx.snap} +20 -0
- package/src/__tests__/__snapshots__/possible-response.test.jsx.snap +5 -0
- package/src/__tests__/__snapshots__/root.test.jsx.snap +50 -0
- package/src/__tests__/{image-container-test.jsx → image-container.test.jsx} +12 -5
- package/src/__tests__/{possible-response-test.jsx → possible-response.test.jsx} +5 -3
- package/src/__tests__/{root-test.jsx → root.test.jsx} +4 -3
- package/src/__tests__/utils.test.js +207 -0
- package/src/constants.js +3 -3
- package/src/evaluation-icon.jsx +8 -17
- package/src/image-container.jsx +14 -19
- package/src/image-drop-target.jsx +45 -38
- package/src/index.js +10 -18
- package/src/interactive-section.jsx +15 -22
- package/src/possible-response.jsx +43 -23
- package/src/possible-responses.jsx +17 -25
- package/src/root.jsx +174 -100
- package/src/utils-correctness.js +44 -14
- package/src/__tests__/__snapshots__/possible-response-test.jsx.snap +0 -13
- package/src/__tests__/__snapshots__/root-test.jsx.snap +0 -38
- package/src/__tests__/utils-test.js +0 -211
package/src/utils-correctness.js
CHANGED
|
@@ -1,57 +1,87 @@
|
|
|
1
1
|
const getAllCorrectAnswers = (answers, responses) =>
|
|
2
|
-
answers.map(answer => ({
|
|
2
|
+
answers.map((answer) => ({
|
|
3
3
|
...answer,
|
|
4
|
-
isCorrect: responses[answer.containerIndex].includes(answer.value)
|
|
4
|
+
isCorrect: (responses[answer.containerIndex].images || []).includes(answer.value),
|
|
5
5
|
}));
|
|
6
6
|
|
|
7
|
-
const getValidAnswer = (answer, response) =>
|
|
7
|
+
const getValidAnswer = (answer, response) =>
|
|
8
|
+
(response[answer.containerIndex].images || []).filter((res) => res === answer.value);
|
|
8
9
|
|
|
9
10
|
const getUniqueCorrectAnswers = (answers, validResponses) => {
|
|
10
11
|
let finalAnswers = answers;
|
|
11
12
|
|
|
12
13
|
answers.forEach((answer1) => {
|
|
13
|
-
const valuesToParse = answers.filter(
|
|
14
|
-
(answer2.value === answer1.value
|
|
14
|
+
const valuesToParse = answers.filter(
|
|
15
|
+
(answer2) => answer2.value === answer1.value && answer2.containerIndex === answer1.containerIndex,
|
|
16
|
+
);
|
|
15
17
|
|
|
16
18
|
if (valuesToParse.length > 1) {
|
|
17
19
|
// point only to duplicates but first
|
|
18
20
|
valuesToParse.shift();
|
|
19
21
|
// mark duplicates as incorrect
|
|
20
22
|
valuesToParse.forEach((value, index) => {
|
|
21
|
-
finalAnswers = finalAnswers.map(finalAnswer => {
|
|
23
|
+
finalAnswers = finalAnswers.map((finalAnswer) => {
|
|
22
24
|
if (finalAnswer.id === value.id) {
|
|
23
25
|
let valid = getValidAnswer(finalAnswer, validResponses);
|
|
24
26
|
|
|
25
27
|
return {
|
|
26
28
|
...finalAnswer,
|
|
27
|
-
isCorrect: valid.length > index + 1
|
|
28
|
-
}
|
|
29
|
+
isCorrect: valid.length > index + 1,
|
|
30
|
+
};
|
|
29
31
|
}
|
|
30
32
|
return finalAnswer;
|
|
31
|
-
})
|
|
33
|
+
});
|
|
32
34
|
});
|
|
33
35
|
}
|
|
34
36
|
});
|
|
35
37
|
return finalAnswers;
|
|
36
38
|
};
|
|
37
39
|
|
|
40
|
+
export const getUnansweredAnswers = (answers, validation) => {
|
|
41
|
+
const { validResponse: { value } = {} } = validation;
|
|
42
|
+
|
|
43
|
+
const unansweredAnswers = (value || []).reduce((unanswered, response, index) => {
|
|
44
|
+
const isAnswered = !!answers.find((answer) => answer.containerIndex === index);
|
|
45
|
+
|
|
46
|
+
if (!isAnswered) {
|
|
47
|
+
return [
|
|
48
|
+
...unanswered,
|
|
49
|
+
{
|
|
50
|
+
id: `unanswered-${index}`,
|
|
51
|
+
value: response.images[0] || '',
|
|
52
|
+
containerIndex: index,
|
|
53
|
+
isCorrect: false,
|
|
54
|
+
hidden: true,
|
|
55
|
+
},
|
|
56
|
+
];
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return unanswered;
|
|
60
|
+
}, []);
|
|
61
|
+
|
|
62
|
+
return unansweredAnswers;
|
|
63
|
+
};
|
|
64
|
+
|
|
38
65
|
export const getAnswersCorrectness = (answers, validation) => {
|
|
39
|
-
const {
|
|
66
|
+
const {
|
|
67
|
+
validResponse: { value },
|
|
68
|
+
altResponses,
|
|
69
|
+
} = validation;
|
|
40
70
|
|
|
41
71
|
const allCorrect = getAllCorrectAnswers(answers, value);
|
|
42
72
|
const uniqueAnswers = getUniqueCorrectAnswers(allCorrect, value);
|
|
43
|
-
const noOfCorrect = uniqueAnswers.filter(answer => answer.isCorrect).length;
|
|
73
|
+
const noOfCorrect = uniqueAnswers.filter((answer) => answer.isCorrect).length;
|
|
44
74
|
|
|
45
75
|
// Look for alternate correct responses if there are incorrect responses.
|
|
46
|
-
if (
|
|
47
|
-
const altUniqueStack = altResponses.map(altResponse => {
|
|
76
|
+
if (noOfCorrect < uniqueAnswers.length && altResponses && altResponses.length) {
|
|
77
|
+
const altUniqueStack = altResponses.map((altResponse) => {
|
|
48
78
|
const altValue = altResponse.value;
|
|
49
79
|
|
|
50
80
|
const altAllCorrect = getAllCorrectAnswers(answers, altValue);
|
|
51
81
|
return getUniqueCorrectAnswers(altAllCorrect, altValue);
|
|
52
82
|
});
|
|
53
83
|
// Return the one with most correct answers.
|
|
54
|
-
return altUniqueStack.sort((a, b) => b.filter(c => c.isCorrect).length - a.filter(c => c.isCorrect).length)[0];
|
|
84
|
+
return altUniqueStack.sort((a, b) => b.filter((c) => c.isCorrect).length - a.filter((c) => c.isCorrect).length)[0];
|
|
55
85
|
}
|
|
56
86
|
return uniqueAnswers;
|
|
57
87
|
};
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
-
|
|
3
|
-
exports[`Possible Response snapshots canDrag renders 1`] = `
|
|
4
|
-
<ContextConsumer>
|
|
5
|
-
<Component />
|
|
6
|
-
</ContextConsumer>
|
|
7
|
-
`;
|
|
8
|
-
|
|
9
|
-
exports[`Possible Response snapshots data renders 1`] = `
|
|
10
|
-
<ContextConsumer>
|
|
11
|
-
<Component />
|
|
12
|
-
</ContextConsumer>
|
|
13
|
-
`;
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
-
|
|
3
|
-
exports[`Root snapshots model renders 1`] = `
|
|
4
|
-
<DndProvider
|
|
5
|
-
backend={[Function]}
|
|
6
|
-
>
|
|
7
|
-
<ImageClozeAssociationComponent
|
|
8
|
-
classes={Object {}}
|
|
9
|
-
model={
|
|
10
|
-
Object {
|
|
11
|
-
"answers": Array [
|
|
12
|
-
Object {
|
|
13
|
-
"containerIndex": 0,
|
|
14
|
-
"id": 1,
|
|
15
|
-
"value": "1",
|
|
16
|
-
},
|
|
17
|
-
Object {
|
|
18
|
-
"containerIndex": 1,
|
|
19
|
-
"id": 2,
|
|
20
|
-
"value": "2",
|
|
21
|
-
},
|
|
22
|
-
],
|
|
23
|
-
"canDrag": true,
|
|
24
|
-
"draggingElement": Object {},
|
|
25
|
-
"duplicateResponses": false,
|
|
26
|
-
"image": Object {},
|
|
27
|
-
"maxResponsePerZone": 5,
|
|
28
|
-
"onAnswerSelect": [Function],
|
|
29
|
-
"onDragAnswerBegin": [Function],
|
|
30
|
-
"onDragAnswerEnd": [Function],
|
|
31
|
-
"possibleResponses": Array [],
|
|
32
|
-
"responseContainers": Array [],
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
updateAnswer={[Function]}
|
|
36
|
-
/>
|
|
37
|
-
</DndProvider>
|
|
38
|
-
`;
|
|
@@ -1,211 +0,0 @@
|
|
|
1
|
-
import { getAnswersCorrectness } from '../utils-correctness';
|
|
2
|
-
|
|
3
|
-
const rhomb = 'rhomb';
|
|
4
|
-
const trapeze = 'trapeze';
|
|
5
|
-
const hexagon = 'hexagon';
|
|
6
|
-
|
|
7
|
-
const answer1 = {
|
|
8
|
-
containerIndex: 0
,
|
|
9
|
-
id: 1,
|
|
10
|
-
value: rhomb
|
|
11
|
-
};
|
|
12
|
-
const answer2 = {
|
|
13
|
-
containerIndex: 0
,
|
|
14
|
-
id: 2,
|
|
15
|
-
value: rhomb
|
|
16
|
-
};
|
|
17
|
-
const answer3 = {
|
|
18
|
-
containerIndex: 0
,
|
|
19
|
-
id: 3,
|
|
20
|
-
value: trapeze
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
const answer4 = {
|
|
24
|
-
containerIndex: 1
,
|
|
25
|
-
id: 4,
|
|
26
|
-
value: hexagon,
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
describe('utils', () => {
|
|
30
|
-
let validResponses;
|
|
31
|
-
|
|
32
|
-
beforeEach(() => {
|
|
33
|
-
validResponses = {
|
|
34
|
-
validResponse: {
|
|
35
|
-
value: [
|
|
36
|
-
[rhomb],
|
|
37
|
-
[rhomb, trapeze]
|
|
38
|
-
]
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
describe('correctness', () => {
|
|
44
|
-
it('marks correct answers as correct', () => {
|
|
45
|
-
const result = getAnswersCorrectness(
|
|
46
|
-
[answer1, {
|
|
47
|
-
...answer3,
|
|
48
|
-
containerIndex: 1
|
|
49
|
-
}],
|
|
50
|
-
validResponses
|
|
51
|
-
);
|
|
52
|
-
expect(result).toEqual([{
|
|
53
|
-
...answer1,
|
|
54
|
-
isCorrect: true
|
|
55
|
-
},{
|
|
56
|
-
...answer3,
|
|
57
|
-
isCorrect: true,
|
|
58
|
-
containerIndex: 1
|
|
59
|
-
}]);
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
it('marks incorrect answers as incorrect', () => {
|
|
63
|
-
const result = getAnswersCorrectness(
|
|
64
|
-
[answer1, answer3],
|
|
65
|
-
validResponses
|
|
66
|
-
);
|
|
67
|
-
expect(result).toEqual([{
|
|
68
|
-
...answer1,
|
|
69
|
-
isCorrect: true
|
|
70
|
-
},{
|
|
71
|
-
...answer3,
|
|
72
|
-
isCorrect: false
|
|
73
|
-
}]);
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
it('marks duplicates as incorrect', () => {
|
|
77
|
-
const result = getAnswersCorrectness(
|
|
78
|
-
[answer1, answer2],
|
|
79
|
-
validResponses
|
|
80
|
-
);
|
|
81
|
-
expect(result).toEqual([{
|
|
82
|
-
...answer1,
|
|
83
|
-
isCorrect: true
|
|
84
|
-
},{
|
|
85
|
-
...answer2,
|
|
86
|
-
isCorrect: false
|
|
87
|
-
}]);
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
it('marks duplicates and incorrect as incorrect', () => {
|
|
91
|
-
const result = getAnswersCorrectness(
|
|
92
|
-
[answer1, answer2, answer3],
|
|
93
|
-
validResponses
|
|
94
|
-
);
|
|
95
|
-
expect(result).toEqual([{
|
|
96
|
-
...answer1,
|
|
97
|
-
isCorrect: true
|
|
98
|
-
},{
|
|
99
|
-
...answer2,
|
|
100
|
-
isCorrect: false
|
|
101
|
-
},{
|
|
102
|
-
...answer3,
|
|
103
|
-
isCorrect: false
|
|
104
|
-
}]);
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
describe('alternate correct answers', () => {
|
|
108
|
-
describe('handles one option', () => {
|
|
109
|
-
it('marks correct answers as correct', () => {
|
|
110
|
-
const result = getAnswersCorrectness(
|
|
111
|
-
[answer1, answer4],
|
|
112
|
-
{
|
|
113
|
-
...validResponses,
|
|
114
|
-
altResponses: [{
|
|
115
|
-
value: [
|
|
116
|
-
[rhomb],
|
|
117
|
-
[hexagon]
|
|
118
|
-
]
|
|
119
|
-
}]
|
|
120
|
-
}
|
|
121
|
-
);
|
|
122
|
-
expect(result).toEqual([{
|
|
123
|
-
...answer1,
|
|
124
|
-
isCorrect: true
|
|
125
|
-
},{
|
|
126
|
-
...answer4,
|
|
127
|
-
isCorrect: true
|
|
128
|
-
}]);
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
it('marks incorrect answers as incorrect', () => {
|
|
132
|
-
const result = getAnswersCorrectness(
|
|
133
|
-
[answer1, answer4],
|
|
134
|
-
{
|
|
135
|
-
...validResponses,
|
|
136
|
-
altResponses: [{
|
|
137
|
-
value: [
|
|
138
|
-
[hexagon],
|
|
139
|
-
[rhomb]
|
|
140
|
-
]
|
|
141
|
-
}]
|
|
142
|
-
}
|
|
143
|
-
);
|
|
144
|
-
expect(result).toEqual([{
|
|
145
|
-
...answer1,
|
|
146
|
-
isCorrect: false
|
|
147
|
-
},{
|
|
148
|
-
...answer4,
|
|
149
|
-
isCorrect: false
|
|
150
|
-
}]);
|
|
151
|
-
});
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
describe('handles multiple options', () => {
|
|
155
|
-
it('marks correct answers as correct', () => {
|
|
156
|
-
const result = getAnswersCorrectness(
|
|
157
|
-
[answer1, answer4],
|
|
158
|
-
{
|
|
159
|
-
...validResponses,
|
|
160
|
-
altResponses: [{
|
|
161
|
-
value: [
|
|
162
|
-
[hexagon],
|
|
163
|
-
[rhomb]
|
|
164
|
-
]
|
|
165
|
-
}, {
|
|
166
|
-
value: [
|
|
167
|
-
[rhomb],
|
|
168
|
-
[hexagon]
|
|
169
|
-
]
|
|
170
|
-
}]
|
|
171
|
-
}
|
|
172
|
-
);
|
|
173
|
-
expect(result).toEqual([{
|
|
174
|
-
...answer1,
|
|
175
|
-
isCorrect: true
|
|
176
|
-
},{
|
|
177
|
-
...answer4,
|
|
178
|
-
isCorrect: true
|
|
179
|
-
}]);
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
it('marks incorrect answers as incorrect', () => {
|
|
183
|
-
const result = getAnswersCorrectness(
|
|
184
|
-
[answer1, answer4],
|
|
185
|
-
{
|
|
186
|
-
...validResponses,
|
|
187
|
-
altResponses: [{
|
|
188
|
-
value: [
|
|
189
|
-
[hexagon],
|
|
190
|
-
[rhomb]
|
|
191
|
-
]
|
|
192
|
-
}, {
|
|
193
|
-
value: [
|
|
194
|
-
[hexagon],
|
|
195
|
-
[hexagon]
|
|
196
|
-
]
|
|
197
|
-
}]
|
|
198
|
-
}
|
|
199
|
-
);
|
|
200
|
-
expect(result).toEqual([{
|
|
201
|
-
...answer1,
|
|
202
|
-
isCorrect: false
|
|
203
|
-
},{
|
|
204
|
-
...answer4,
|
|
205
|
-
isCorrect: true
|
|
206
|
-
}]);
|
|
207
|
-
});
|
|
208
|
-
});
|
|
209
|
-
});
|
|
210
|
-
});
|
|
211
|
-
});
|