@pie-element/image-cloze-association 10.1.2-next.2 → 10.1.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.
- package/CHANGELOG.json +437 -0
- package/CHANGELOG.md +1997 -0
- package/LICENSE.md +5 -0
- package/README.md +1 -0
- package/configure/CHANGELOG.json +197 -0
- package/configure/CHANGELOG.md +1600 -0
- package/configure/lib/defaults.js +86 -0
- package/configure/lib/defaults.js.map +1 -0
- package/configure/lib/index.js +99 -0
- package/configure/lib/index.js.map +1 -0
- package/configure/lib/root.js +135 -0
- package/configure/lib/root.js.map +1 -0
- package/configure/package.json +23 -0
- package/configure/src/__tests__/index.test.js +155 -0
- package/configure/src/defaults.js +59 -0
- package/configure/src/index.js +114 -0
- package/configure/src/root.jsx +116 -0
- package/controller/CHANGELOG.json +137 -0
- package/controller/CHANGELOG.md +1149 -0
- package/controller/lib/defaults.js +14 -0
- package/controller/lib/defaults.js.map +1 -0
- package/controller/lib/index.js +304 -0
- package/controller/lib/index.js.map +1 -0
- package/controller/lib/utils.js +70 -0
- package/controller/lib/utils.js.map +1 -0
- package/controller/package.json +19 -0
- package/controller/src/__tests__/index.test.js +711 -0
- package/controller/src/defaults.js +7 -0
- package/controller/src/index.js +322 -0
- package/controller/src/utils.js +72 -0
- package/docs/config-schema.json +1382 -0
- package/docs/config-schema.json.md +1021 -0
- package/docs/demo/config.js +8 -0
- package/docs/demo/generate.js +74 -0
- package/docs/demo/index.html +1 -0
- package/docs/demo/session.js +16 -0
- package/docs/pie-schema.json +1085 -0
- package/docs/pie-schema.json.md +810 -0
- package/lib/constants.js +12 -0
- package/lib/constants.js.map +1 -0
- package/lib/evaluation-icon.js +60 -0
- package/lib/evaluation-icon.js.map +1 -0
- package/lib/image-container.js +94 -0
- package/lib/image-container.js.map +1 -0
- package/lib/image-drop-target.js +130 -0
- package/lib/image-drop-target.js.map +1 -0
- package/lib/index.js +220 -0
- package/lib/index.js.map +1 -0
- package/lib/interactive-section.js +104 -0
- package/lib/interactive-section.js.map +1 -0
- package/lib/possible-response.js +161 -0
- package/lib/possible-response.js.map +1 -0
- package/lib/possible-responses.js +58 -0
- package/lib/possible-responses.js.map +1 -0
- package/lib/root.js +491 -0
- package/lib/root.js.map +1 -0
- package/lib/static-html-span.js +35 -0
- package/lib/static-html-span.js.map +1 -0
- package/lib/utils-correctness.js +89 -0
- package/lib/utils-correctness.js.map +1 -0
- package/package.json +21 -86
- package/src/__tests__/index.test.js +174 -0
- package/src/__tests__/root.test.jsx +99 -0
- package/src/__tests__/utils.test.js +207 -0
- package/src/constants.js +5 -0
- package/src/evaluation-icon.jsx +54 -0
- package/src/image-container.jsx +90 -0
- package/src/image-drop-target.jsx +140 -0
- package/src/index.js +245 -0
- package/src/interactive-section.jsx +94 -0
- package/src/possible-response.jsx +152 -0
- package/src/possible-responses.jsx +52 -0
- package/src/root.jsx +490 -0
- package/src/static-html-span.jsx +30 -0
- package/src/utils-correctness.js +95 -0
- package/configure.js +0 -2
- package/controller.js +0 -1
- package/dist/author/defaults.d.ts +0 -88
- package/dist/author/defaults.js +0 -58
- package/dist/author/index.d.ts +0 -34
- package/dist/author/index.js +0 -71
- package/dist/author/root.d.ts +0 -14
- package/dist/author/root.js +0 -80
- package/dist/browser/Check-DL1c-mLM.js +0 -10708
- package/dist/browser/Check-DL1c-mLM.js.map +0 -1
- package/dist/browser/author/index.js +0 -38597
- package/dist/browser/author/index.js.map +0 -1
- package/dist/browser/controller/index.js +0 -171
- package/dist/browser/controller/index.js.map +0 -1
- package/dist/browser/delivery/index.js +0 -2699
- package/dist/browser/delivery/index.js.map +0 -1
- package/dist/browser/dist-BphSS14E.js +0 -346
- package/dist/browser/dist-BphSS14E.js.map +0 -1
- package/dist/browser/humps-CZ4RCLab.js +0 -67
- package/dist/browser/humps-CZ4RCLab.js.map +0 -1
- package/dist/browser/image-cloze-association.css +0 -2
- package/dist/controller/defaults.d.ts +0 -16
- package/dist/controller/defaults.js +0 -10
- package/dist/controller/index.d.ts +0 -23
- package/dist/controller/index.js +0 -122
- package/dist/controller/utils.d.ts +0 -14
- package/dist/controller/utils.js +0 -36
- package/dist/delivery/constants.d.ts +0 -14
- package/dist/delivery/evaluation-icon.d.ts +0 -28
- package/dist/delivery/evaluation-icon.js +0 -38
- package/dist/delivery/image-container.d.ts +0 -13
- package/dist/delivery/image-container.js +0 -61
- package/dist/delivery/image-drop-target.d.ts +0 -45
- package/dist/delivery/image-drop-target.js +0 -90
- package/dist/delivery/index.d.ts +0 -20
- package/dist/delivery/index.js +0 -110
- package/dist/delivery/interactive-section.d.ts +0 -15
- package/dist/delivery/interactive-section.js +0 -72
- package/dist/delivery/possible-response.d.ts +0 -34
- package/dist/delivery/possible-response.js +0 -100
- package/dist/delivery/possible-responses.d.ts +0 -31
- package/dist/delivery/possible-responses.js +0 -41
- package/dist/delivery/root.d.ts +0 -21
- package/dist/delivery/root.js +0 -278
- package/dist/delivery/static-html-span.d.ts +0 -14
- package/dist/delivery/static-html-span.js +0 -22
- package/dist/delivery/utils-correctness.d.ts +0 -10
- package/dist/delivery/utils-correctness.js +0 -43
- package/dist/index.d.ts +0 -1
- package/dist/index.iife.d.ts +0 -8
- package/dist/index.iife.js +0 -152
- package/dist/index.js +0 -2
- package/dist/node_modules/.bun/clsx@2.1.1/node_modules/clsx/dist/clsx.js +0 -16
- package/dist/runtime-support.d.ts +0 -12
- package/dist/runtime-support.js +0 -12
package/src/root.jsx
ADDED
|
@@ -0,0 +1,490 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import { DragOverlay } from '@dnd-kit/core';
|
|
4
|
+
import { DragProvider } from '@pie-lib/drag';
|
|
5
|
+
import { CSSTransition, TransitionGroup } from 'react-transition-group';
|
|
6
|
+
import { color, Collapsible, PreviewPrompt, UiLayout, hasText, hasMedia } from '@pie-lib/render-ui';
|
|
7
|
+
import { styled } from '@mui/material/styles';
|
|
8
|
+
import NotInterestedIcon from '@mui/icons-material/NotInterested';
|
|
9
|
+
import CorrectAnswerToggle from '@pie-lib/correct-answer-toggle';
|
|
10
|
+
import Translator from '@pie-lib/translator';
|
|
11
|
+
import { flatMap, groupBy } from 'lodash-es';
|
|
12
|
+
|
|
13
|
+
const { translator } = Translator;
|
|
14
|
+
import Image from './image-container';
|
|
15
|
+
import InteractiveSection from './interactive-section';
|
|
16
|
+
import PossibleResponses from './possible-responses';
|
|
17
|
+
import { getUnansweredAnswers, getAnswersCorrectness } from './utils-correctness';
|
|
18
|
+
import PossibleResponse from './possible-response';
|
|
19
|
+
|
|
20
|
+
const generateId = () => Math.random().toString(36).substring(2) + new Date().getTime().toString(36);
|
|
21
|
+
|
|
22
|
+
const StyledUiLayout = styled(UiLayout)({
|
|
23
|
+
color: color.text(),
|
|
24
|
+
backgroundColor: color.background(),
|
|
25
|
+
position: 'relative',
|
|
26
|
+
'& img': {
|
|
27
|
+
maxWidth: '100%',
|
|
28
|
+
height: 'auto',
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const StyledTeacherInstructions = styled(Collapsible)(({ theme }) => ({
|
|
33
|
+
marginBottom: theme.spacing(2),
|
|
34
|
+
}));
|
|
35
|
+
|
|
36
|
+
const StyledRationale = styled(Collapsible)(({ theme }) => ({
|
|
37
|
+
marginTop: theme.spacing(2),
|
|
38
|
+
}));
|
|
39
|
+
|
|
40
|
+
export class ImageClozeAssociationComponent extends React.Component {
|
|
41
|
+
constructor(props) {
|
|
42
|
+
super(props);
|
|
43
|
+
const {
|
|
44
|
+
model: { possibleResponses, responseContainers, duplicateResponses, maxResponsePerZone },
|
|
45
|
+
session,
|
|
46
|
+
} = props;
|
|
47
|
+
let { answers } = session || {};
|
|
48
|
+
// set id for each possible response
|
|
49
|
+
const possibleResponsesWithIds = (possibleResponses || []).map((item, index) => ({
|
|
50
|
+
value: item,
|
|
51
|
+
id: `${index}`,
|
|
52
|
+
}));
|
|
53
|
+
|
|
54
|
+
let groupedAnswers = groupBy(answers || [], 'containerIndex');
|
|
55
|
+
// keep only last maxResponsePerZone answers for each zone
|
|
56
|
+
let limitedAnswers = flatMap(groupedAnswers, (grp) => grp.slice(-(maxResponsePerZone || 1)));
|
|
57
|
+
answers = limitedAnswers
|
|
58
|
+
// set id for each answer
|
|
59
|
+
.map((answer, index) => ({ ...answer, id: `${index}` }))
|
|
60
|
+
// return only answer which have a valid container index
|
|
61
|
+
.filter((answer) => answer.containerIndex < responseContainers.length);
|
|
62
|
+
|
|
63
|
+
const possibleResponsesFiltered = possibleResponsesWithIds.filter(
|
|
64
|
+
(response) => !answers.find((answer) => answer.value === response.value),
|
|
65
|
+
);
|
|
66
|
+
this.state = {
|
|
67
|
+
answers: answers || [],
|
|
68
|
+
draggingElement: { id: '', value: '' },
|
|
69
|
+
possibleResponses: duplicateResponses ? possibleResponsesWithIds : possibleResponsesFiltered,
|
|
70
|
+
// set id for each response containers
|
|
71
|
+
responseContainers: (responseContainers || []).map((item, index) => ({
|
|
72
|
+
index,
|
|
73
|
+
...item,
|
|
74
|
+
id: `${index}`,
|
|
75
|
+
})),
|
|
76
|
+
maxResponsePerZone: maxResponsePerZone || 1,
|
|
77
|
+
showCorrect: false,
|
|
78
|
+
isValidDrop: false,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
onDragStart = (event) => {
|
|
83
|
+
const { active } = event;
|
|
84
|
+
|
|
85
|
+
if (active?.data?.current) {
|
|
86
|
+
this.setState({
|
|
87
|
+
draggingElement: active.data.current,
|
|
88
|
+
isValidDrop: false,
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
onDragEnd = (event) => {
|
|
94
|
+
const { active, over } = event;
|
|
95
|
+
const { model } = this.props;
|
|
96
|
+
const { duplicateResponses } = model || {};
|
|
97
|
+
|
|
98
|
+
// Check if drop is valid
|
|
99
|
+
const draggedItem = active?.data?.current;
|
|
100
|
+
const responseArea = over?.data?.current;
|
|
101
|
+
const isValidDrop =
|
|
102
|
+
over &&
|
|
103
|
+
active &&
|
|
104
|
+
draggedItem &&
|
|
105
|
+
responseArea &&
|
|
106
|
+
responseArea.containerIndex !== undefined;
|
|
107
|
+
|
|
108
|
+
const shouldDisableAnimation = isValidDrop && duplicateResponses;
|
|
109
|
+
|
|
110
|
+
this.setState({
|
|
111
|
+
draggingElement: { id: '', value: '' },
|
|
112
|
+
isValidDrop: shouldDisableAnimation,
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
if (!over || !active) {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if (!draggedItem) {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if (over.id === 'ica-board') {
|
|
124
|
+
this.handleOnAnswerRemove(draggedItem);
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (responseArea) {
|
|
129
|
+
this.handleOnAnswerSelect(draggedItem, responseArea.containerIndex);
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
renderDragOverlay = () => {
|
|
134
|
+
const { draggingElement } = this.state;
|
|
135
|
+
const { model } = this.props;
|
|
136
|
+
|
|
137
|
+
if (!draggingElement.id) return null;
|
|
138
|
+
|
|
139
|
+
// check if the response contains an image
|
|
140
|
+
const imgRegex = /<img[^>]+src="([^">]+)"/;
|
|
141
|
+
const containsImage = imgRegex.test(draggingElement.value);
|
|
142
|
+
|
|
143
|
+
return (
|
|
144
|
+
<PossibleResponse
|
|
145
|
+
key={draggingElement.id}
|
|
146
|
+
canDrag={false}
|
|
147
|
+
data={draggingElement}
|
|
148
|
+
onDragBegin={() => {}}
|
|
149
|
+
isOverlay
|
|
150
|
+
containerStyle={{
|
|
151
|
+
...(model.answerChoiceTransparency ? { opacity: '0.8' } : {}),
|
|
152
|
+
...(!containsImage ? { padding: '0 10px', margin: '4px 6px !important' } : {}),
|
|
153
|
+
}}
|
|
154
|
+
/>
|
|
155
|
+
);
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
filterPossibleAnswers = (possibleResponses, answer) =>
|
|
159
|
+
possibleResponses.filter((response) => response.value !== answer.value);
|
|
160
|
+
|
|
161
|
+
handleOnAnswerSelect = (answer, responseContainerIndex) => {
|
|
162
|
+
const {
|
|
163
|
+
model: { duplicateResponses },
|
|
164
|
+
updateAnswer,
|
|
165
|
+
} = this.props;
|
|
166
|
+
const { answers, maxResponsePerZone } = this.state;
|
|
167
|
+
let { possibleResponses } = this.state;
|
|
168
|
+
let answersToStore;
|
|
169
|
+
|
|
170
|
+
const answersInThisContainer = [];
|
|
171
|
+
const answersInOtherContainers = [];
|
|
172
|
+
|
|
173
|
+
answers.forEach((a) => {
|
|
174
|
+
if (a.containerIndex === responseContainerIndex) {
|
|
175
|
+
answersInThisContainer.push(a);
|
|
176
|
+
} else {
|
|
177
|
+
answersInOtherContainers.push(a);
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
if (maxResponsePerZone === answersInThisContainer.length) {
|
|
182
|
+
const shiftedItem = answersInThisContainer[0];
|
|
183
|
+
if (maxResponsePerZone === 1) {
|
|
184
|
+
answersInThisContainer.shift(); // FIFO
|
|
185
|
+
} else {
|
|
186
|
+
this.setState({ maxResponsePerZoneWarning: true });
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// if duplicates are not allowed, make sure to put the shifted value back in possible responses
|
|
191
|
+
if (!duplicateResponses) {
|
|
192
|
+
possibleResponses = Array.isArray(possibleResponses) ? possibleResponses : [];
|
|
193
|
+
|
|
194
|
+
possibleResponses.push({
|
|
195
|
+
...shiftedItem,
|
|
196
|
+
containerIndex: undefined,
|
|
197
|
+
id: shiftedItem.id || generateId(),
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// answers will be:
|
|
202
|
+
// + shifted answers for the current container
|
|
203
|
+
// + if duplicatesAllowed, all the other answers from other containers
|
|
204
|
+
// else: all the answers from other containers that are not having the same value
|
|
205
|
+
// + new answer
|
|
206
|
+
answersToStore = [
|
|
207
|
+
...answersInThisContainer, // shifted
|
|
208
|
+
// TODO allow duplicates case Question: should we remove answer from a container if dragged to another container?
|
|
209
|
+
// if yes, this should do it: add a.id !== answer.id instead of 'true'
|
|
210
|
+
...answersInOtherContainers.filter((a) => (duplicateResponses ? true : a.value !== answer.value)), // un-shifted
|
|
211
|
+
{
|
|
212
|
+
...answer,
|
|
213
|
+
containerIndex: responseContainerIndex,
|
|
214
|
+
...(duplicateResponses ? { id: generateId() } : {}),
|
|
215
|
+
},
|
|
216
|
+
];
|
|
217
|
+
} else {
|
|
218
|
+
// answers will be:
|
|
219
|
+
// + if duplicatesAllowed, all the other answers, except the one that was dragged
|
|
220
|
+
// else: all the answers that are not having the same value
|
|
221
|
+
// + new answer
|
|
222
|
+
answersToStore = [
|
|
223
|
+
// TODO allow duplicates case Question: should we remove answer from a container if dragged to another container?
|
|
224
|
+
// if yes, this should do it: add a.id !== answer.id instead of 'true'
|
|
225
|
+
...answers.filter((a) => (duplicateResponses ? a.id !== answer.id : a.value !== answer.value)),
|
|
226
|
+
{
|
|
227
|
+
...answer,
|
|
228
|
+
containerIndex: responseContainerIndex,
|
|
229
|
+
...(duplicateResponses ? { id: generateId() } : {}),
|
|
230
|
+
},
|
|
231
|
+
];
|
|
232
|
+
}
|
|
233
|
+
this.setState({
|
|
234
|
+
maxResponsePerZoneWarning: false,
|
|
235
|
+
answers: answersToStore,
|
|
236
|
+
possibleResponses:
|
|
237
|
+
// for single response per container remove answer from possible responses
|
|
238
|
+
duplicateResponses ? possibleResponses : this.filterPossibleAnswers(possibleResponses, answer),
|
|
239
|
+
});
|
|
240
|
+
updateAnswer(answersToStore);
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
handleOnAnswerRemove = (answer) => {
|
|
244
|
+
const {
|
|
245
|
+
model: { duplicateResponses },
|
|
246
|
+
updateAnswer,
|
|
247
|
+
} = this.props;
|
|
248
|
+
const { answers, possibleResponses } = this.state;
|
|
249
|
+
const answersToStore = answers.filter((a) => a.id !== answer.id);
|
|
250
|
+
const shouldNotPushInPossibleResponses = answer.containerIndex === undefined; // don't duplicate possible responses
|
|
251
|
+
|
|
252
|
+
this.setState({
|
|
253
|
+
maxResponsePerZoneWarning: false,
|
|
254
|
+
answers: answersToStore,
|
|
255
|
+
// push back into possible responses the removed answer if responses cannot be duplicated
|
|
256
|
+
possibleResponses:
|
|
257
|
+
duplicateResponses || shouldNotPushInPossibleResponses
|
|
258
|
+
? possibleResponses
|
|
259
|
+
: [
|
|
260
|
+
...possibleResponses,
|
|
261
|
+
{
|
|
262
|
+
...answer,
|
|
263
|
+
containerIndex: undefined,
|
|
264
|
+
},
|
|
265
|
+
],
|
|
266
|
+
});
|
|
267
|
+
updateAnswer(answersToStore);
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
toggleCorrect = (showCorrect) => this.setState({ showCorrect });
|
|
271
|
+
|
|
272
|
+
render() {
|
|
273
|
+
const {
|
|
274
|
+
model: {
|
|
275
|
+
disabled,
|
|
276
|
+
duplicateResponses,
|
|
277
|
+
extraCSSRules,
|
|
278
|
+
image,
|
|
279
|
+
responseAreaFill,
|
|
280
|
+
stimulus,
|
|
281
|
+
responseCorrect,
|
|
282
|
+
validation,
|
|
283
|
+
teacherInstructions,
|
|
284
|
+
prompt,
|
|
285
|
+
autoplayAudioEnabled,
|
|
286
|
+
showDashedBorder,
|
|
287
|
+
mode,
|
|
288
|
+
rationale,
|
|
289
|
+
language,
|
|
290
|
+
uiStyle = {},
|
|
291
|
+
answerChoiceTransparency,
|
|
292
|
+
responseContainerPadding,
|
|
293
|
+
imageDropTargetPadding,
|
|
294
|
+
fontSizeFactor,
|
|
295
|
+
customAudioButton,
|
|
296
|
+
},
|
|
297
|
+
} = this.props;
|
|
298
|
+
const {
|
|
299
|
+
answers,
|
|
300
|
+
draggingElement,
|
|
301
|
+
possibleResponses,
|
|
302
|
+
responseContainers,
|
|
303
|
+
maxResponsePerZone,
|
|
304
|
+
maxResponsePerZoneWarning,
|
|
305
|
+
showCorrect,
|
|
306
|
+
isValidDrop,
|
|
307
|
+
} = this.state;
|
|
308
|
+
const isEvaluateMode = mode === 'evaluate';
|
|
309
|
+
const showToggle = isEvaluateMode && !responseCorrect;
|
|
310
|
+
const { possibilityListPosition = 'bottom' } = uiStyle || {};
|
|
311
|
+
const isVertical = possibilityListPosition === 'left' || possibilityListPosition === 'right';
|
|
312
|
+
|
|
313
|
+
const { validResponse } = validation || {};
|
|
314
|
+
const correctAnswers = [];
|
|
315
|
+
const showRationale = rationale && (hasText(rationale) || hasMedia(rationale));
|
|
316
|
+
const showTeacherInstructions =
|
|
317
|
+
teacherInstructions && (hasText(teacherInstructions) || hasMedia(teacherInstructions));
|
|
318
|
+
|
|
319
|
+
if (validResponse) {
|
|
320
|
+
(validResponse.value || []).forEach((container, i) => {
|
|
321
|
+
(container.images || []).forEach((v) => {
|
|
322
|
+
correctAnswers.push({
|
|
323
|
+
value: v,
|
|
324
|
+
containerIndex: i,
|
|
325
|
+
isCorrect: true,
|
|
326
|
+
});
|
|
327
|
+
});
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
const warningMessage = translator.t('imageClozeAssociation.reachedLimit_other', {
|
|
332
|
+
lng: language,
|
|
333
|
+
count: maxResponsePerZone,
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
let answersToShow =
|
|
337
|
+
responseCorrect !== undefined ? getAnswersCorrectness(answers, validation, duplicateResponses) : answers;
|
|
338
|
+
|
|
339
|
+
if (responseCorrect === false && maxResponsePerZone === 1) {
|
|
340
|
+
answersToShow = [...answersToShow, ...getUnansweredAnswers(answersToShow, validation)];
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
const sharedImageProps = {
|
|
344
|
+
draggingElement,
|
|
345
|
+
duplicateResponses,
|
|
346
|
+
image,
|
|
347
|
+
onAnswerSelect: this.handleOnAnswerSelect,
|
|
348
|
+
onDragAnswerBegin: this.onDragStart,
|
|
349
|
+
onDragAnswerEnd: this.onDragEnd,
|
|
350
|
+
responseContainers,
|
|
351
|
+
showDashedBorder,
|
|
352
|
+
responseAreaFill,
|
|
353
|
+
responseContainerPadding,
|
|
354
|
+
imageDropTargetPadding,
|
|
355
|
+
maxResponsePerZone,
|
|
356
|
+
};
|
|
357
|
+
|
|
358
|
+
const renderImage = () => (
|
|
359
|
+
<Image
|
|
360
|
+
{...sharedImageProps}
|
|
361
|
+
canDrag={showCorrect && showToggle ? false : !disabled}
|
|
362
|
+
answers={showCorrect && showToggle ? correctAnswers : answersToShow}
|
|
363
|
+
answerChoiceTransparency={!(showCorrect && showToggle) ? answerChoiceTransparency : undefined}
|
|
364
|
+
/>
|
|
365
|
+
);
|
|
366
|
+
|
|
367
|
+
const renderPossibleResponses = () => {
|
|
368
|
+
if (showCorrect && showToggle) return null;
|
|
369
|
+
|
|
370
|
+
return (
|
|
371
|
+
<React.Fragment>
|
|
372
|
+
{maxResponsePerZoneWarning && <WarningInfo message={warningMessage} />}
|
|
373
|
+
<PossibleResponses
|
|
374
|
+
canDrag={!disabled}
|
|
375
|
+
data={possibleResponses}
|
|
376
|
+
onAnswerRemove={this.handleOnAnswerRemove}
|
|
377
|
+
onDragBegin={this.onDragStart}
|
|
378
|
+
answerChoiceTransparency={answerChoiceTransparency}
|
|
379
|
+
customStyle={{
|
|
380
|
+
minWidth: isVertical ? '130px' : image?.width || 'fit-content',
|
|
381
|
+
}}
|
|
382
|
+
isVertical={isVertical}
|
|
383
|
+
minHeight={isVertical ? image?.height : undefined}
|
|
384
|
+
/>
|
|
385
|
+
</React.Fragment>
|
|
386
|
+
);
|
|
387
|
+
};
|
|
388
|
+
|
|
389
|
+
return (
|
|
390
|
+
<DragProvider onDragStart={this.onDragStart} onDragEnd={this.onDragEnd}>
|
|
391
|
+
<StyledUiLayout extraCSSRules={extraCSSRules} id={'main-container'} fontSizeFactor={fontSizeFactor}>
|
|
392
|
+
{showTeacherInstructions && (
|
|
393
|
+
<StyledTeacherInstructions
|
|
394
|
+
labels={{
|
|
395
|
+
hidden: 'Show Teacher Instructions',
|
|
396
|
+
visible: 'Hide Teacher Instructions',
|
|
397
|
+
}}
|
|
398
|
+
>
|
|
399
|
+
<PreviewPrompt prompt={teacherInstructions} />
|
|
400
|
+
</StyledTeacherInstructions>
|
|
401
|
+
)}
|
|
402
|
+
|
|
403
|
+
<PreviewPrompt
|
|
404
|
+
className="prompt"
|
|
405
|
+
prompt={prompt}
|
|
406
|
+
autoplayAudioEnabled={autoplayAudioEnabled}
|
|
407
|
+
customAudioButton={customAudioButton}
|
|
408
|
+
/>
|
|
409
|
+
|
|
410
|
+
<PreviewPrompt prompt={stimulus} />
|
|
411
|
+
|
|
412
|
+
<CorrectAnswerToggle
|
|
413
|
+
show={showToggle}
|
|
414
|
+
toggled={showCorrect}
|
|
415
|
+
onToggle={this.toggleCorrect}
|
|
416
|
+
language={language}
|
|
417
|
+
/>
|
|
418
|
+
|
|
419
|
+
<InteractiveSection responseCorrect={showCorrect && showToggle ? true : responseCorrect} uiStyle={uiStyle}>
|
|
420
|
+
{renderImage()}
|
|
421
|
+
{renderPossibleResponses()}
|
|
422
|
+
</InteractiveSection>
|
|
423
|
+
|
|
424
|
+
{showRationale && (
|
|
425
|
+
<StyledRationale
|
|
426
|
+
labels={{
|
|
427
|
+
hidden: 'Show Rationale',
|
|
428
|
+
visible: 'Hide Rationale',
|
|
429
|
+
}}
|
|
430
|
+
>
|
|
431
|
+
<PreviewPrompt prompt={rationale} />
|
|
432
|
+
</StyledRationale>
|
|
433
|
+
)}
|
|
434
|
+
</StyledUiLayout>
|
|
435
|
+
{/* Disable drop animation for valid drops to prevent visual snap-back */}
|
|
436
|
+
{/* Keep default animation for invalid drops to show visual feedback */}
|
|
437
|
+
<DragOverlay dropAnimation={isValidDrop ? null : undefined}>
|
|
438
|
+
{this.renderDragOverlay()}
|
|
439
|
+
</DragOverlay>
|
|
440
|
+
</DragProvider>
|
|
441
|
+
);
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
const WarningContainer = styled('div')(({ theme }) => ({
|
|
446
|
+
margin: `0 ${theme.spacing(2)}`,
|
|
447
|
+
backgroundColor: '#dddddd',
|
|
448
|
+
padding: theme.spacing(1),
|
|
449
|
+
display: 'flex',
|
|
450
|
+
alignItems: 'center',
|
|
451
|
+
'& svg': {
|
|
452
|
+
height: '30px',
|
|
453
|
+
},
|
|
454
|
+
'& h1': {
|
|
455
|
+
padding: '0px',
|
|
456
|
+
margin: '0px',
|
|
457
|
+
},
|
|
458
|
+
}));
|
|
459
|
+
|
|
460
|
+
const WarningMessage = styled('span')(({ theme }) => ({
|
|
461
|
+
paddingLeft: theme.spacing(0.5),
|
|
462
|
+
userSelect: 'none',
|
|
463
|
+
}));
|
|
464
|
+
|
|
465
|
+
const WarningInfo = ({ message }) => {
|
|
466
|
+
const nodeRef = React.useRef(null);
|
|
467
|
+
|
|
468
|
+
return (
|
|
469
|
+
<TransitionGroup>
|
|
470
|
+
<CSSTransition classNames={'fb'} key="fb" timeout={300} nodeRef={nodeRef}>
|
|
471
|
+
<WarningContainer ref={nodeRef} key="panel">
|
|
472
|
+
<NotInterestedIcon color={'secondary'} fontSize={'small'} />
|
|
473
|
+
<WarningMessage dangerouslySetInnerHTML={{ __html: message }} />
|
|
474
|
+
</WarningContainer>
|
|
475
|
+
</CSSTransition>
|
|
476
|
+
</TransitionGroup>
|
|
477
|
+
);
|
|
478
|
+
};
|
|
479
|
+
|
|
480
|
+
WarningInfo.propTypes = {
|
|
481
|
+
message: PropTypes.string,
|
|
482
|
+
};
|
|
483
|
+
|
|
484
|
+
ImageClozeAssociationComponent.propTypes = {
|
|
485
|
+
model: PropTypes.object.isRequired,
|
|
486
|
+
session: PropTypes.object,
|
|
487
|
+
updateAnswer: PropTypes.func.isRequired,
|
|
488
|
+
};
|
|
489
|
+
|
|
490
|
+
export default ImageClozeAssociationComponent;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
|
|
4
|
+
class StaticHTMLSpan extends React.PureComponent {
|
|
5
|
+
shouldComponentUpdate() {
|
|
6
|
+
return false;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
render() {
|
|
10
|
+
const { html, className } = this.props;
|
|
11
|
+
|
|
12
|
+
return (
|
|
13
|
+
<span
|
|
14
|
+
className={className}
|
|
15
|
+
dangerouslySetInnerHTML={{ __html: html }}
|
|
16
|
+
/>
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
StaticHTMLSpan.propTypes = {
|
|
22
|
+
html: PropTypes.string.isRequired,
|
|
23
|
+
className: PropTypes.string,
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
StaticHTMLSpan.defaultProps = {
|
|
27
|
+
className: '',
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export default StaticHTMLSpan;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
// functions also used in controller/src/utils.js
|
|
2
|
+
// camelize keys is needed to convert the keys from snake_case to camelCase
|
|
3
|
+
// this is also done in the controller
|
|
4
|
+
import { camelizeKeys } from 'humps';
|
|
5
|
+
|
|
6
|
+
const getAllCorrectAnswers = (answers, responses) =>
|
|
7
|
+
(answers || []).map((answer) => ({
|
|
8
|
+
...answer,
|
|
9
|
+
isCorrect: ((responses[answer.containerIndex] && responses[answer.containerIndex].images) || []).includes(
|
|
10
|
+
answer.value,
|
|
11
|
+
),
|
|
12
|
+
}));
|
|
13
|
+
|
|
14
|
+
const getValidAnswer = (answer, response) =>
|
|
15
|
+
(response[answer.containerIndex].images || []).filter((res) => res === answer.value);
|
|
16
|
+
|
|
17
|
+
const getUniqueCorrectAnswers = (answers, validResponses) => {
|
|
18
|
+
let finalAnswers = answers;
|
|
19
|
+
|
|
20
|
+
answers.forEach((answer1) => {
|
|
21
|
+
const valuesToParse = answers.filter(
|
|
22
|
+
(answer2) => answer2.value === answer1.value && answer2.containerIndex === answer1.containerIndex,
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
if (valuesToParse.length > 1) {
|
|
26
|
+
// point only to duplicates but first
|
|
27
|
+
valuesToParse.shift();
|
|
28
|
+
// mark duplicates as incorrect
|
|
29
|
+
valuesToParse.forEach((value, index) => {
|
|
30
|
+
finalAnswers = (finalAnswers || []).map((finalAnswer) => {
|
|
31
|
+
if (finalAnswer.id === value.id) {
|
|
32
|
+
let valid = getValidAnswer(finalAnswer, validResponses);
|
|
33
|
+
|
|
34
|
+
return {
|
|
35
|
+
...finalAnswer,
|
|
36
|
+
isCorrect: valid.length > index + 1,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
return finalAnswer;
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
return finalAnswers;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export const getUnansweredAnswers = (answers, validation) => {
|
|
48
|
+
const camelizedValidation = camelizeKeys(validation);
|
|
49
|
+
const { validResponse: { value } = {} } = camelizedValidation;
|
|
50
|
+
|
|
51
|
+
return (value || []).reduce((unanswered, response, index) => {
|
|
52
|
+
const isAnswered = !!answers.find((answer) => answer.containerIndex === index);
|
|
53
|
+
response.images = response.images || [];
|
|
54
|
+
|
|
55
|
+
if (!isAnswered) {
|
|
56
|
+
return [
|
|
57
|
+
...unanswered,
|
|
58
|
+
{
|
|
59
|
+
id: `unanswered-${index}`,
|
|
60
|
+
value: response.images[0] || '',
|
|
61
|
+
containerIndex: index,
|
|
62
|
+
isCorrect: !response.images.length ? undefined : false,
|
|
63
|
+
hidden: true,
|
|
64
|
+
},
|
|
65
|
+
];
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return unanswered;
|
|
69
|
+
}, []);
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export const getAnswersCorrectness = (answers, validation) => {
|
|
73
|
+
const camelizedValidation = camelizeKeys(validation);
|
|
74
|
+
const {
|
|
75
|
+
validResponse: { value },
|
|
76
|
+
altResponses,
|
|
77
|
+
} = camelizedValidation;
|
|
78
|
+
|
|
79
|
+
const allCorrect = getAllCorrectAnswers(answers, value);
|
|
80
|
+
const uniqueAnswers = getUniqueCorrectAnswers(allCorrect, value);
|
|
81
|
+
const noOfCorrect = uniqueAnswers.filter((answer) => answer.isCorrect).length;
|
|
82
|
+
|
|
83
|
+
// Look for alternate correct responses if there are incorrect responses.
|
|
84
|
+
if (noOfCorrect < uniqueAnswers.length && altResponses && altResponses.length) {
|
|
85
|
+
const altUniqueStack = (altResponses || []).map((altResponse) => {
|
|
86
|
+
const altValue = altResponse.value;
|
|
87
|
+
|
|
88
|
+
const altAllCorrect = getAllCorrectAnswers(answers, altValue);
|
|
89
|
+
return getUniqueCorrectAnswers(altAllCorrect, altValue);
|
|
90
|
+
});
|
|
91
|
+
// Return the one with most correct answers.
|
|
92
|
+
return altUniqueStack.sort((a, b) => b.filter((c) => c.isCorrect).length - a.filter((c) => c.isCorrect).length)[0];
|
|
93
|
+
}
|
|
94
|
+
return uniqueAnswers;
|
|
95
|
+
};
|
package/configure.js
DELETED
package/controller.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './dist/controller/index.js';
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @synced-from pie-elements/packages/image-cloze-association/configure/src/defaults.js
|
|
3
|
-
* @auto-generated
|
|
4
|
-
*
|
|
5
|
-
* This file is automatically synced from pie-elements and converted to TypeScript.
|
|
6
|
-
* Manual edits will be overwritten on next sync.
|
|
7
|
-
* To make changes, edit the upstream JavaScript file and run sync again.
|
|
8
|
-
*/
|
|
9
|
-
declare const _default: {
|
|
10
|
-
model: {
|
|
11
|
-
rationale: string;
|
|
12
|
-
rationaleEnabled: boolean;
|
|
13
|
-
studentInstructionsEnabled: boolean;
|
|
14
|
-
teacherInstructions: string;
|
|
15
|
-
teacherInstructionsEnabled: boolean;
|
|
16
|
-
};
|
|
17
|
-
configuration: {
|
|
18
|
-
baseInputConfiguration: {
|
|
19
|
-
h3: {
|
|
20
|
-
disabled: boolean;
|
|
21
|
-
};
|
|
22
|
-
audio: {
|
|
23
|
-
disabled: boolean;
|
|
24
|
-
};
|
|
25
|
-
video: {
|
|
26
|
-
disabled: boolean;
|
|
27
|
-
};
|
|
28
|
-
image: {
|
|
29
|
-
disabled: boolean;
|
|
30
|
-
};
|
|
31
|
-
textAlign: {
|
|
32
|
-
disabled: boolean;
|
|
33
|
-
};
|
|
34
|
-
showParagraphs: {
|
|
35
|
-
disabled: boolean;
|
|
36
|
-
};
|
|
37
|
-
separateParagraphs: {
|
|
38
|
-
disabled: boolean;
|
|
39
|
-
};
|
|
40
|
-
};
|
|
41
|
-
maxImageWidth: {
|
|
42
|
-
teacherInstructions: number;
|
|
43
|
-
};
|
|
44
|
-
maxImageHeight: {
|
|
45
|
-
teacherInstructions: number;
|
|
46
|
-
};
|
|
47
|
-
settingsPanelDisabled: boolean;
|
|
48
|
-
spellCheck: {
|
|
49
|
-
label: string;
|
|
50
|
-
settings: boolean;
|
|
51
|
-
enabled: boolean;
|
|
52
|
-
};
|
|
53
|
-
teacherInstructions: {
|
|
54
|
-
settings: boolean;
|
|
55
|
-
label: string;
|
|
56
|
-
inputConfiguration: {
|
|
57
|
-
audio: {
|
|
58
|
-
disabled: boolean;
|
|
59
|
-
};
|
|
60
|
-
video: {
|
|
61
|
-
disabled: boolean;
|
|
62
|
-
};
|
|
63
|
-
image: {
|
|
64
|
-
disabled: boolean;
|
|
65
|
-
};
|
|
66
|
-
};
|
|
67
|
-
required: boolean;
|
|
68
|
-
};
|
|
69
|
-
withRubric: {
|
|
70
|
-
settings: boolean;
|
|
71
|
-
label: string;
|
|
72
|
-
};
|
|
73
|
-
mathMlOptions: {
|
|
74
|
-
mmlOutput: boolean;
|
|
75
|
-
mmlEditing: boolean;
|
|
76
|
-
};
|
|
77
|
-
language: {
|
|
78
|
-
settings: boolean;
|
|
79
|
-
label: string;
|
|
80
|
-
enabled: boolean;
|
|
81
|
-
};
|
|
82
|
-
languageChoices: {
|
|
83
|
-
label: string;
|
|
84
|
-
options: never[];
|
|
85
|
-
};
|
|
86
|
-
};
|
|
87
|
-
};
|
|
88
|
-
export default _default;
|