@pie-qti/default-components 0.1.4 → 0.1.6
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/dist/index.d.ts +15 -24
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +59 -123
- package/dist/plugins/index.d.ts +1 -0
- package/dist/plugins/index.d.ts.map +1 -1
- package/dist/plugins/index.js +1 -0
- package/dist/shared/utils/eventHelpers.d.ts +5 -1
- package/dist/shared/utils/eventHelpers.d.ts.map +1 -1
- package/dist/shared/utils/matchGroupUtils.d.ts +8 -0
- package/dist/shared/utils/matchGroupUtils.d.ts.map +1 -0
- package/dist/shared/utils/matchGroupUtils.js +13 -0
- package/package.json +8 -4
- package/src/catalog/CatalogPopup.svelte +163 -0
- package/src/index.ts +72 -144
- package/src/plugins/associate/AssociateInteraction.svelte +41 -4
- package/src/plugins/choice/ChoiceInteraction.svelte +143 -4
- package/src/plugins/drawing/DrawingInteraction.svelte +9 -0
- package/src/plugins/extended-text/ExtendedTextInteraction.svelte +56 -1
- package/src/plugins/gap-match/GapMatchInteraction.svelte +174 -12
- package/src/plugins/graphic-associate/GraphicAssociateInteraction.svelte +85 -9
- package/src/plugins/graphic-gap-match/GraphicGapMatchInteraction.svelte +197 -107
- package/src/plugins/hotspot/HotspotInteraction.svelte +50 -7
- package/src/plugins/hottext/HottextInteraction.svelte +33 -4
- package/src/plugins/index.ts +1 -0
- package/src/plugins/match/MatchInteraction.svelte +13 -1
- package/src/plugins/media/MediaInteraction.svelte +5 -2
- package/src/plugins/order/OrderInteraction.svelte +132 -11
- package/src/plugins/position-object/PositionObjectInteraction.svelte +247 -9
- package/src/plugins/select-point/SelectPointInteraction.svelte +139 -7
- package/src/shared/components/FileUpload.svelte +7 -2
- package/src/shared/components/GraphicGapMatch.svelte +5 -3
- package/src/shared/components/GraphicGapMatchAdapter.svelte +10 -1
- package/src/shared/components/InlineInteractionRenderer.svelte +28 -11
- package/src/shared/components/MatchDragDrop.svelte +48 -2
- package/src/shared/components/ModalFeedbackDisplay.svelte +15 -5
- package/src/shared/styles/qti-shared-vocabulary.css +320 -0
- package/src/shared/utils/eventHelpers.ts +8 -1
- package/src/shared/utils/matchGroupUtils.ts +14 -0
package/src/index.ts
CHANGED
|
@@ -1,213 +1,141 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @pie-qti/default-components
|
|
3
3
|
*
|
|
4
|
-
* Default Svelte-based component implementations for the QTI
|
|
4
|
+
* Default Svelte-based component implementations for the QTI player.
|
|
5
5
|
* These components are packaged as web components that work with the
|
|
6
6
|
* framework-agnostic @pie-qti/item-player core.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import type { ComponentRegistry } from '@pie-qti/item-player';
|
|
10
|
-
|
|
11
9
|
// Export shared utilities and helpers
|
|
12
10
|
export * from './shared/index.js';
|
|
13
11
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
* @param registry - The ComponentRegistry instance from the Player
|
|
27
|
-
*
|
|
28
|
-
* @example
|
|
29
|
-
* ```typescript
|
|
30
|
-
* import { Player } from '@pie-qti/item-player';
|
|
31
|
-
* import '@pie-qti/default-components/plugins'; // Load web components
|
|
32
|
-
* import { registerDefaultComponents } from '@pie-qti/default-components';
|
|
33
|
-
*
|
|
34
|
-
* const player = new Player(qtiXml);
|
|
35
|
-
* registerDefaultComponents(player.getComponentRegistry());
|
|
36
|
-
* ```
|
|
37
|
-
*/
|
|
38
|
-
export function registerDefaultComponents(registry: ComponentRegistry): void {
|
|
39
|
-
// ChoiceInteraction - Radio buttons or checkboxes
|
|
40
|
-
registry.register('choiceInteraction', {
|
|
12
|
+
interface DefaultComponentRegistration {
|
|
13
|
+
name: string;
|
|
14
|
+
description: string;
|
|
15
|
+
tagName: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
interface DefaultComponentRegistry {
|
|
19
|
+
register(type: string, component: DefaultComponentRegistration): void;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const DEFAULT_COMPONENTS_BY_TYPE = {
|
|
23
|
+
choiceInteraction: {
|
|
41
24
|
name: 'default-choice',
|
|
42
|
-
priority: 0,
|
|
43
25
|
description: 'Default Svelte-based choice interaction',
|
|
44
|
-
canHandle: () => true,
|
|
45
26
|
tagName: 'pie-qti-choice',
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
// SliderInteraction - Range slider
|
|
50
|
-
registry.register('sliderInteraction', {
|
|
27
|
+
},
|
|
28
|
+
sliderInteraction: {
|
|
51
29
|
name: 'default-slider',
|
|
52
|
-
priority: 0,
|
|
53
30
|
description: 'Default Svelte-based slider interaction',
|
|
54
|
-
canHandle: () => true,
|
|
55
31
|
tagName: 'pie-qti-slider',
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// OrderInteraction - Sortable list
|
|
59
|
-
registry.register('orderInteraction', {
|
|
32
|
+
},
|
|
33
|
+
orderInteraction: {
|
|
60
34
|
name: 'default-order',
|
|
61
|
-
priority: 0,
|
|
62
35
|
description: 'Default Svelte-based order interaction',
|
|
63
|
-
canHandle: () => true,
|
|
64
36
|
tagName: 'pie-qti-order',
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// MatchInteraction - Match source to target
|
|
68
|
-
registry.register('matchInteraction', {
|
|
37
|
+
},
|
|
38
|
+
matchInteraction: {
|
|
69
39
|
name: 'default-match',
|
|
70
|
-
priority: 0,
|
|
71
40
|
description: 'Default Svelte-based match interaction',
|
|
72
|
-
canHandle: () => true,
|
|
73
41
|
tagName: 'pie-qti-match',
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
// AssociateInteraction - Create associations between choices
|
|
77
|
-
registry.register('associateInteraction', {
|
|
42
|
+
},
|
|
43
|
+
associateInteraction: {
|
|
78
44
|
name: 'default-associate',
|
|
79
|
-
priority: 0,
|
|
80
45
|
description: 'Default Svelte-based associate interaction',
|
|
81
|
-
canHandle: () => true,
|
|
82
46
|
tagName: 'pie-qti-associate',
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
// GapMatchInteraction - Fill gaps with words
|
|
86
|
-
registry.register('gapMatchInteraction', {
|
|
47
|
+
},
|
|
48
|
+
gapMatchInteraction: {
|
|
87
49
|
name: 'default-gap-match',
|
|
88
|
-
priority: 0,
|
|
89
50
|
description: 'Default Svelte-based gap match interaction',
|
|
90
|
-
canHandle: () => true,
|
|
91
51
|
tagName: 'pie-qti-gap-match',
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
// HotspotInteraction - Click on image hotspots
|
|
95
|
-
registry.register('hotspotInteraction', {
|
|
52
|
+
},
|
|
53
|
+
hotspotInteraction: {
|
|
96
54
|
name: 'default-hotspot',
|
|
97
|
-
priority: 0,
|
|
98
55
|
description: 'Default Svelte-based hotspot interaction',
|
|
99
|
-
canHandle: () => true,
|
|
100
56
|
tagName: 'pie-qti-hotspot',
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
// HottextInteraction - Select text within content
|
|
104
|
-
registry.register('hottextInteraction', {
|
|
57
|
+
},
|
|
58
|
+
hottextInteraction: {
|
|
105
59
|
name: 'default-hottext',
|
|
106
|
-
priority: 0,
|
|
107
60
|
description: 'Default Svelte-based hottext interaction',
|
|
108
|
-
canHandle: () => true,
|
|
109
61
|
tagName: 'pie-qti-hottext',
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// MediaInteraction - Audio/video playback with tracking
|
|
113
|
-
registry.register('mediaInteraction', {
|
|
62
|
+
},
|
|
63
|
+
mediaInteraction: {
|
|
114
64
|
name: 'default-media',
|
|
115
|
-
priority: 0,
|
|
116
65
|
description: 'Default Svelte-based media interaction',
|
|
117
|
-
canHandle: () => true,
|
|
118
66
|
tagName: 'pie-qti-media',
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
// CustomInteraction - Fallback for custom interactions
|
|
122
|
-
registry.register('customInteraction', {
|
|
67
|
+
},
|
|
68
|
+
customInteraction: {
|
|
123
69
|
name: 'default-custom',
|
|
124
|
-
priority: 0,
|
|
125
70
|
description: 'Default Svelte-based custom interaction',
|
|
126
|
-
canHandle: () => true,
|
|
127
71
|
tagName: 'pie-qti-custom',
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
// EndAttemptInteraction - End attempt button
|
|
131
|
-
registry.register('endAttemptInteraction', {
|
|
72
|
+
},
|
|
73
|
+
endAttemptInteraction: {
|
|
132
74
|
name: 'default-end-attempt',
|
|
133
|
-
priority: 0,
|
|
134
75
|
description: 'Default Svelte-based end attempt interaction',
|
|
135
|
-
canHandle: () => true,
|
|
136
76
|
tagName: 'pie-qti-end-attempt',
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
// PositionObjectInteraction - Drag objects onto canvas
|
|
140
|
-
registry.register('positionObjectInteraction', {
|
|
77
|
+
},
|
|
78
|
+
positionObjectInteraction: {
|
|
141
79
|
name: 'default-position-object',
|
|
142
|
-
priority: 0,
|
|
143
80
|
description: 'Default Svelte-based position object interaction',
|
|
144
|
-
canHandle: () => true,
|
|
145
81
|
tagName: 'pie-qti-position-object',
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
// GraphicGapMatchInteraction - Drag labels onto image hotspots
|
|
149
|
-
registry.register('graphicGapMatchInteraction', {
|
|
82
|
+
},
|
|
83
|
+
graphicGapMatchInteraction: {
|
|
150
84
|
name: 'default-graphic-gap-match',
|
|
151
|
-
priority: 0,
|
|
152
85
|
description: 'Default Svelte-based graphic gap match interaction',
|
|
153
|
-
canHandle: () => true,
|
|
154
86
|
tagName: 'pie-qti-graphic-gap-match',
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
// GraphicOrderInteraction - Order items with graphic reference
|
|
158
|
-
registry.register('graphicOrderInteraction', {
|
|
87
|
+
},
|
|
88
|
+
graphicOrderInteraction: {
|
|
159
89
|
name: 'default-graphic-order',
|
|
160
|
-
priority: 0,
|
|
161
90
|
description: 'Default Svelte-based graphic order interaction',
|
|
162
|
-
canHandle: () => true,
|
|
163
91
|
tagName: 'pie-qti-graphic-order',
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
// GraphicAssociateInteraction - Create associations on image
|
|
167
|
-
registry.register('graphicAssociateInteraction', {
|
|
92
|
+
},
|
|
93
|
+
graphicAssociateInteraction: {
|
|
168
94
|
name: 'default-graphic-associate',
|
|
169
|
-
priority: 0,
|
|
170
95
|
description: 'Default Svelte-based graphic associate interaction',
|
|
171
|
-
canHandle: () => true,
|
|
172
96
|
tagName: 'pie-qti-graphic-associate',
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
// SelectPointInteraction - Select points on image
|
|
176
|
-
registry.register('selectPointInteraction', {
|
|
97
|
+
},
|
|
98
|
+
selectPointInteraction: {
|
|
177
99
|
name: 'default-select-point',
|
|
178
|
-
priority: 0,
|
|
179
100
|
description: 'Default Svelte-based select point interaction',
|
|
180
|
-
canHandle: () => true,
|
|
181
101
|
tagName: 'pie-qti-select-point',
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
// ExtendedTextInteraction - Rich text editor
|
|
185
|
-
registry.register('extendedTextInteraction', {
|
|
102
|
+
},
|
|
103
|
+
extendedTextInteraction: {
|
|
186
104
|
name: 'default-extended-text',
|
|
187
|
-
priority: 0,
|
|
188
105
|
description: 'Default Svelte-based extended text interaction',
|
|
189
|
-
canHandle: () => true,
|
|
190
106
|
tagName: 'pie-qti-extended-text',
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
// UploadInteraction - File upload
|
|
194
|
-
registry.register('uploadInteraction', {
|
|
107
|
+
},
|
|
108
|
+
uploadInteraction: {
|
|
195
109
|
name: 'default-upload',
|
|
196
|
-
priority: 0,
|
|
197
110
|
description: 'Default Svelte-based upload interaction',
|
|
198
|
-
canHandle: () => true,
|
|
199
111
|
tagName: 'pie-qti-upload',
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
// DrawingInteraction - Canvas drawing
|
|
203
|
-
registry.register('drawingInteraction', {
|
|
112
|
+
},
|
|
113
|
+
drawingInteraction: {
|
|
204
114
|
name: 'default-drawing',
|
|
205
|
-
priority: 0,
|
|
206
115
|
description: 'Default Svelte-based drawing interaction',
|
|
207
|
-
canHandle: () => true,
|
|
208
116
|
tagName: 'pie-qti-drawing',
|
|
209
|
-
}
|
|
117
|
+
},
|
|
118
|
+
} satisfies Record<string, DefaultComponentRegistration>;
|
|
210
119
|
|
|
211
|
-
|
|
212
|
-
|
|
120
|
+
export function getDefaultComponentTypes(): string[] {
|
|
121
|
+
return Object.keys(DEFAULT_COMPONENTS_BY_TYPE);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Register all default components with the ComponentRegistry.
|
|
126
|
+
*
|
|
127
|
+
* This function should be called once at application startup to make all default
|
|
128
|
+
* block interaction components available to the player. Inline interactions are
|
|
129
|
+
* rendered in-flow by @pie-qti/item-player.
|
|
130
|
+
*/
|
|
131
|
+
export function registerDefaultComponents(registry: DefaultComponentRegistry): void {
|
|
132
|
+
for (const [type, component] of Object.entries(DEFAULT_COMPONENTS_BY_TYPE)) {
|
|
133
|
+
registry.register(type, component);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
registry.register('catalogPopup', {
|
|
137
|
+
name: 'default-catalog-popup',
|
|
138
|
+
description: 'Default Svelte-based catalog popup dialog',
|
|
139
|
+
tagName: 'pie-qti-catalog-popup',
|
|
140
|
+
});
|
|
213
141
|
}
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
import type { I18nProvider } from '@pie-qti/i18n';
|
|
6
6
|
import ShadowBaseStyles from '../../shared/components/ShadowBaseStyles.svelte';
|
|
7
7
|
import { parseJsonProp } from '../../shared/utils/webComponentHelpers';
|
|
8
|
+
import { isCompatibleMatchGroup } from '../../shared/utils/matchGroupUtils';
|
|
8
9
|
|
|
9
10
|
interface Props {
|
|
10
11
|
interaction?: AssociateInteractionData | string;
|
|
@@ -45,6 +46,7 @@
|
|
|
45
46
|
|
|
46
47
|
// Ensure response is always an array
|
|
47
48
|
const pairs = $derived(parsedResponse || []);
|
|
49
|
+
const helperId = $derived(`associate-helper-${parsedInteraction?.responseId ?? 'unknown'}`);
|
|
48
50
|
|
|
49
51
|
function emitChange(newPairs: string[]) {
|
|
50
52
|
response = newPairs;
|
|
@@ -73,6 +75,17 @@
|
|
|
73
75
|
}
|
|
74
76
|
}
|
|
75
77
|
|
|
78
|
+
// Choices that cannot be paired with the currently selected choice due to matchGroup constraints
|
|
79
|
+
const blockedChoices = $derived.by(() => {
|
|
80
|
+
if (!selectedForPairing || !parsedInteraction) return new Set<string>();
|
|
81
|
+
const src = parsedInteraction.choices.find((c) => c.identifier === selectedForPairing);
|
|
82
|
+
return new Set(
|
|
83
|
+
parsedInteraction.choices
|
|
84
|
+
.filter((c) => c.identifier !== selectedForPairing && !isCompatibleMatchGroup(src?.matchGroup, c.matchGroup))
|
|
85
|
+
.map((c) => c.identifier)
|
|
86
|
+
);
|
|
87
|
+
});
|
|
88
|
+
|
|
76
89
|
function handleChoiceClick(choiceId: string) {
|
|
77
90
|
if (disabled) return;
|
|
78
91
|
|
|
@@ -84,8 +97,9 @@
|
|
|
84
97
|
else if (selectedForPairing === choiceId) {
|
|
85
98
|
setSelectedForPairing(null);
|
|
86
99
|
}
|
|
87
|
-
// If different item clicked, create a pair
|
|
100
|
+
// If different item clicked, check matchGroup compatibility then create a pair
|
|
88
101
|
else {
|
|
102
|
+
if (blockedChoices.has(choiceId)) return;
|
|
89
103
|
const newPair = `${selectedForPairing} ${choiceId}`;
|
|
90
104
|
const newPairs = [...pairs, newPair];
|
|
91
105
|
emitChange(newPairs);
|
|
@@ -114,6 +128,19 @@
|
|
|
114
128
|
);
|
|
115
129
|
}
|
|
116
130
|
|
|
131
|
+
function toPlainText(html: string): string {
|
|
132
|
+
return html.replace(/<[^>]*>/g, ' ').replace(/\s+/g, ' ').trim();
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function getChoiceLabel(choice: { identifier: string; text: string }): string {
|
|
136
|
+
const text = toPlainText(choice.text);
|
|
137
|
+
return text ? `${choice.identifier}: ${text}` : choice.identifier;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function getPairLabel(choice1: { identifier: string; text: string }, choice2: { identifier: string; text: string }): string {
|
|
141
|
+
return `${getChoiceLabel(choice1)} and ${getChoiceLabel(choice2)}`;
|
|
142
|
+
}
|
|
143
|
+
|
|
117
144
|
const correctPairs = $derived(
|
|
118
145
|
isShowingCorrect && parsedCorrectResponse ? parsedCorrectResponse : []
|
|
119
146
|
);
|
|
@@ -135,9 +162,17 @@
|
|
|
135
162
|
{@const isSelected = selectedForPairing === choice.identifier}
|
|
136
163
|
{@const inPair = isInPair(choice.identifier)}
|
|
137
164
|
{@const isCorrect = isCorrectPair(choice.identifier)}
|
|
165
|
+
{@const isBlocked = blockedChoices.has(choice.identifier)}
|
|
138
166
|
<button
|
|
139
167
|
part="choice"
|
|
140
168
|
class="btn btn-outline {isSelected ? 'btn-accent' : inPair ? 'btn-primary' : isCorrect ? 'btn-success' : 'btn-neutral'}"
|
|
169
|
+
class:opacity-40={isBlocked}
|
|
170
|
+
class:cursor-not-allowed={isBlocked}
|
|
171
|
+
type="button"
|
|
172
|
+
aria-label={getChoiceLabel(choice)}
|
|
173
|
+
aria-pressed={isSelected}
|
|
174
|
+
aria-disabled={isBlocked ? 'true' : undefined}
|
|
175
|
+
aria-describedby={helperId}
|
|
141
176
|
onclick={() => handleChoiceClick(choice.identifier)}
|
|
142
177
|
{disabled}
|
|
143
178
|
>
|
|
@@ -208,6 +243,8 @@
|
|
|
208
243
|
<button
|
|
209
244
|
part="pair-remove"
|
|
210
245
|
class="btn btn-sm btn-ghost btn-circle"
|
|
246
|
+
type="button"
|
|
247
|
+
aria-label={`Remove association between ${getPairLabel(choice1, choice2)}`}
|
|
211
248
|
onclick={() => removePair(index)}
|
|
212
249
|
{disabled}
|
|
213
250
|
>
|
|
@@ -221,14 +258,14 @@
|
|
|
221
258
|
|
|
222
259
|
<!-- Selection helper - Hide when showing correct answers -->
|
|
223
260
|
{#if !isShowingCorrect}
|
|
224
|
-
<div part="helper" class="qti-associate-helper alert alert-info">
|
|
261
|
+
<div id={helperId} part="helper" class="qti-associate-helper alert alert-info" role="status" aria-live="polite">
|
|
225
262
|
<span class="text-sm">
|
|
226
263
|
{#if selectedForPairing}
|
|
227
264
|
{i18n?.t('interactions.associate.clickAnotherOrDeselect') ??
|
|
228
|
-
'
|
|
265
|
+
'Select another item to create an association, or select this item again to deselect it.'}
|
|
229
266
|
{:else}
|
|
230
267
|
{i18n?.t('interactions.associate.clickToAssociate') ??
|
|
231
|
-
'
|
|
268
|
+
'Select two items to create an association between them. Keyboard users can tab to each item and press Enter or Space.'}
|
|
232
269
|
{/if}
|
|
233
270
|
</span>
|
|
234
271
|
</div>
|
|
@@ -21,6 +21,8 @@
|
|
|
21
21
|
onChange?: (value: string | string[]) => void;
|
|
22
22
|
outcomeValues?: Record<string, any>;
|
|
23
23
|
heuristicsConfig?: QtiHeuristicsConfig;
|
|
24
|
+
/** When true, renders an elimination toggle button per choice (QTI 3.0 PNP §6.2). */
|
|
25
|
+
eliminationTool?: boolean;
|
|
24
26
|
}
|
|
25
27
|
|
|
26
28
|
let {
|
|
@@ -33,7 +35,8 @@
|
|
|
33
35
|
typeset,
|
|
34
36
|
onChange,
|
|
35
37
|
outcomeValues = {},
|
|
36
|
-
heuristicsConfig
|
|
38
|
+
heuristicsConfig,
|
|
39
|
+
eliminationTool = false
|
|
37
40
|
}: Props = $props();
|
|
38
41
|
|
|
39
42
|
// Normalize heuristics configuration with defaults
|
|
@@ -74,6 +77,28 @@
|
|
|
74
77
|
// Get reference to the root element for event dispatching
|
|
75
78
|
let rootElement: HTMLDivElement | undefined = $state();
|
|
76
79
|
|
|
80
|
+
// Elimination tool state: set of eliminated choice identifiers.
|
|
81
|
+
// Eliminated choices remain in DOM and in the response; only visually dimmed.
|
|
82
|
+
let eliminatedChoices = $state(new Set<string>());
|
|
83
|
+
|
|
84
|
+
function toggleElimination(identifier: string) {
|
|
85
|
+
const next = new Set(eliminatedChoices);
|
|
86
|
+
if (next.has(identifier)) {
|
|
87
|
+
next.delete(identifier);
|
|
88
|
+
} else {
|
|
89
|
+
next.add(identifier);
|
|
90
|
+
}
|
|
91
|
+
eliminatedChoices = next;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function eliminationLabel(identifier: string): string {
|
|
95
|
+
const isEliminated = eliminatedChoices.has(identifier);
|
|
96
|
+
const action = isEliminated
|
|
97
|
+
? (i18n?.t('interactions.choice.restoreChoice') ?? 'Restore')
|
|
98
|
+
: (i18n?.t('interactions.choice.eliminateChoice') ?? 'Eliminate');
|
|
99
|
+
return action;
|
|
100
|
+
}
|
|
101
|
+
|
|
77
102
|
function handleRadioChange(identifier: string) {
|
|
78
103
|
response = identifier;
|
|
79
104
|
// Call onChange callback if provided (for Svelte component usage)
|
|
@@ -89,6 +114,9 @@
|
|
|
89
114
|
let newValues = [...currentValues];
|
|
90
115
|
|
|
91
116
|
if (checked) {
|
|
117
|
+
// Enforce maxChoices (0 = unlimited)
|
|
118
|
+
const max = parsedInteraction?.maxChoices ?? 0;
|
|
119
|
+
if (max > 0 && newValues.length >= max) return;
|
|
92
120
|
newValues.push(identifier);
|
|
93
121
|
} else {
|
|
94
122
|
newValues = newValues.filter((v) => v !== identifier);
|
|
@@ -102,17 +130,28 @@
|
|
|
102
130
|
rootElement.dispatchEvent(createQtiChangeEvent(parsedInteraction?.responseId, newValues));
|
|
103
131
|
}
|
|
104
132
|
}
|
|
133
|
+
|
|
134
|
+
// Selection limit message: show max message when at/over limit; min message is for submit time
|
|
135
|
+
const selectionCount = $derived(Array.isArray(parsedResponse) ? parsedResponse.length : (parsedResponse ? 1 : 0));
|
|
136
|
+
const maxChoices = $derived(parsedInteraction?.maxChoices ?? 0);
|
|
137
|
+
const showMaxMessage = $derived(
|
|
138
|
+
maxChoices > 0 && selectionCount >= maxChoices && !!parsedInteraction?.maxSelectionsMessage
|
|
139
|
+
);
|
|
105
140
|
</script>
|
|
106
141
|
|
|
107
142
|
<ShadowBaseStyles />
|
|
108
143
|
|
|
109
|
-
<div bind:this={rootElement} part="root" class=
|
|
144
|
+
<div bind:this={rootElement} part="root" class={['qti-choice-interaction space-y-2', ...(parsedInteraction?.interactionClasses ?? [])].join(' ')} use:typesetAction={{ typeset }}>
|
|
110
145
|
{#if !parsedInteraction}
|
|
111
146
|
<div class="alert alert-error">{i18n?.t('common.errorNoData') ?? 'No interaction data provided'}</div>
|
|
112
147
|
{:else if parsedInteraction.maxChoices === 1}
|
|
113
148
|
<!-- Single choice (radio buttons) -->
|
|
114
149
|
{#each parsedInteraction.choices as choice}
|
|
115
|
-
<div
|
|
150
|
+
<div
|
|
151
|
+
part="option"
|
|
152
|
+
class="qti-choice-option form-control"
|
|
153
|
+
data-eliminated={eliminatedChoices.has(choice.identifier) ? '' : undefined}
|
|
154
|
+
>
|
|
116
155
|
<label
|
|
117
156
|
part="label"
|
|
118
157
|
class="qti-choice-label label cursor-pointer justify-start gap-4"
|
|
@@ -136,13 +175,26 @@
|
|
|
136
175
|
<span class="badge badge-success badge-sm">{t('interactions.choice.correct', 'Correct')}</span>
|
|
137
176
|
{/if}
|
|
138
177
|
</label>
|
|
178
|
+
{#if eliminationTool}
|
|
179
|
+
<button
|
|
180
|
+
type="button"
|
|
181
|
+
class="qti-eliminate-btn"
|
|
182
|
+
aria-label={eliminationLabel(choice.identifier)}
|
|
183
|
+
aria-pressed={eliminatedChoices.has(choice.identifier)}
|
|
184
|
+
onclick={() => toggleElimination(choice.identifier)}
|
|
185
|
+
>✕</button>
|
|
186
|
+
{/if}
|
|
139
187
|
</div>
|
|
140
188
|
{/each}
|
|
141
189
|
{:else}
|
|
142
190
|
<!-- Multiple choice (checkboxes) -->
|
|
143
191
|
{@const currentValues = Array.isArray(parsedResponse) ? parsedResponse : []}
|
|
144
192
|
{#each parsedInteraction.choices as choice}
|
|
145
|
-
<div
|
|
193
|
+
<div
|
|
194
|
+
part="option"
|
|
195
|
+
class="qti-choice-option form-control"
|
|
196
|
+
data-eliminated={eliminatedChoices.has(choice.identifier) ? '' : undefined}
|
|
197
|
+
>
|
|
146
198
|
<label
|
|
147
199
|
part="label"
|
|
148
200
|
class="qti-choice-label label cursor-pointer justify-start gap-4"
|
|
@@ -168,9 +220,21 @@
|
|
|
168
220
|
<span class="badge badge-success badge-sm">{t('interactions.choice.correct', 'Correct')}</span>
|
|
169
221
|
{/if}
|
|
170
222
|
</label>
|
|
223
|
+
{#if eliminationTool}
|
|
224
|
+
<button
|
|
225
|
+
type="button"
|
|
226
|
+
class="qti-eliminate-btn"
|
|
227
|
+
aria-label={eliminationLabel(choice.identifier)}
|
|
228
|
+
aria-pressed={eliminatedChoices.has(choice.identifier)}
|
|
229
|
+
onclick={() => toggleElimination(choice.identifier)}
|
|
230
|
+
>✕</button>
|
|
231
|
+
{/if}
|
|
171
232
|
</div>
|
|
172
233
|
{/each}
|
|
173
234
|
{/if}
|
|
235
|
+
{#if showMaxMessage}
|
|
236
|
+
<p class="qti-selection-message qti-max-selection-message" role="alert">{parsedInteraction?.maxSelectionsMessage}</p>
|
|
237
|
+
{/if}
|
|
174
238
|
</div>
|
|
175
239
|
|
|
176
240
|
<style>
|
|
@@ -209,4 +273,79 @@
|
|
|
209
273
|
.checkbox-success {
|
|
210
274
|
accent-color: var(--color-success, oklch(76% 0.177 163.223));
|
|
211
275
|
}
|
|
276
|
+
|
|
277
|
+
/* Elimination tool */
|
|
278
|
+
.qti-choice-option {
|
|
279
|
+
position: relative;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
.qti-eliminate-btn {
|
|
283
|
+
position: absolute;
|
|
284
|
+
right: 0.25rem;
|
|
285
|
+
top: 50%;
|
|
286
|
+
transform: translateY(-50%);
|
|
287
|
+
background: none;
|
|
288
|
+
border: 1px solid currentColor;
|
|
289
|
+
border-radius: 50%;
|
|
290
|
+
width: 1.5rem;
|
|
291
|
+
height: 1.5rem;
|
|
292
|
+
line-height: 1;
|
|
293
|
+
font-size: 0.75rem;
|
|
294
|
+
cursor: pointer;
|
|
295
|
+
opacity: 0.4;
|
|
296
|
+
padding: 0;
|
|
297
|
+
display: flex;
|
|
298
|
+
align-items: center;
|
|
299
|
+
justify-content: center;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
.qti-eliminate-btn:hover,
|
|
303
|
+
.qti-eliminate-btn[aria-pressed='true'] {
|
|
304
|
+
opacity: 1;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
/* Eliminated choices are dimmed with a strikethrough */
|
|
308
|
+
[data-eliminated] .qti-choice-label {
|
|
309
|
+
opacity: 0.4;
|
|
310
|
+
text-decoration: line-through;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
[data-eliminated] .qti-eliminate-btn {
|
|
314
|
+
opacity: 1;
|
|
315
|
+
color: var(--color-error, oklch(63% 0.237 25.331));
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/* ── QTI Shared Vocabulary behavioral classes ─────────────────────────── */
|
|
319
|
+
|
|
320
|
+
/* qti-input-control-hidden: hide radio/checkbox controls but keep keyboard-accessible */
|
|
321
|
+
:global(.qti-input-control-hidden) .qti-choice-interaction input[type='radio'],
|
|
322
|
+
:global(.qti-input-control-hidden) .qti-choice-interaction input[type='checkbox'],
|
|
323
|
+
.qti-choice-interaction.qti-input-control-hidden input[type='radio'],
|
|
324
|
+
.qti-choice-interaction.qti-input-control-hidden input[type='checkbox'] {
|
|
325
|
+
position: absolute;
|
|
326
|
+
opacity: 0;
|
|
327
|
+
width: 0;
|
|
328
|
+
height: 0;
|
|
329
|
+
pointer-events: none;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
/* qti-orientation-horizontal: choices in a row */
|
|
333
|
+
.qti-choice-interaction.qti-orientation-horizontal {
|
|
334
|
+
grid-auto-flow: column;
|
|
335
|
+
grid-template-columns: repeat(auto-fill, minmax(0, 1fr));
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
/* qti-choices-stacking-N: N-column grid */
|
|
339
|
+
.qti-choice-interaction.qti-choices-stacking-1 { grid-template-columns: 1fr; }
|
|
340
|
+
.qti-choice-interaction.qti-choices-stacking-2 { grid-template-columns: repeat(2, 1fr); }
|
|
341
|
+
.qti-choice-interaction.qti-choices-stacking-3 { grid-template-columns: repeat(3, 1fr); }
|
|
342
|
+
.qti-choice-interaction.qti-choices-stacking-4 { grid-template-columns: repeat(4, 1fr); }
|
|
343
|
+
.qti-choice-interaction.qti-choices-stacking-5 { grid-template-columns: repeat(5, 1fr); }
|
|
344
|
+
|
|
345
|
+
/* Selection limit messages */
|
|
346
|
+
.qti-selection-message {
|
|
347
|
+
font-size: 0.875rem;
|
|
348
|
+
color: var(--color-warning, oklch(77% 0.194 82));
|
|
349
|
+
margin-top: 0.5rem;
|
|
350
|
+
}
|
|
212
351
|
</style>
|
|
@@ -63,6 +63,15 @@
|
|
|
63
63
|
{#if parsedInteraction.prompt}
|
|
64
64
|
<p class="font-semibold mb-2">{parsedInteraction.prompt}</p>
|
|
65
65
|
{/if}
|
|
66
|
+
<!--
|
|
67
|
+
Accessibility note (WCAG 2.1 SC 2.1.1 exemption):
|
|
68
|
+
Free-form drawing is a path-dependent pointer input. WCAG 2.1.1 exempts inputs
|
|
69
|
+
"where the underlying function requires input that depends on the path of the
|
|
70
|
+
user's movement and not just the endpoints" (e.g. freehand drawing, handwriting).
|
|
71
|
+
Item authors MUST provide an accessible alternative form (e.g. an extended-text
|
|
72
|
+
response or upload interaction) so that keyboard-only and switch-access users
|
|
73
|
+
can submit equivalent evidence of their knowledge.
|
|
74
|
+
-->
|
|
66
75
|
<DrawingCanvas
|
|
67
76
|
responseId={parsedInteraction.responseId}
|
|
68
77
|
imageData={parsedInteraction.imageData}
|