@pie-qti/default-components 0.1.1
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/.turbo/turbo-build.log +1 -0
- package/CHANGELOG.md +9 -0
- package/STYLING.md +226 -0
- package/dist/index.d.ts +35 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +190 -0
- package/dist/plugins/associate/index.d.ts +8 -0
- package/dist/plugins/associate/index.d.ts.map +1 -0
- package/dist/plugins/associate/index.js +8 -0
- package/dist/plugins/choice/index.d.ts +8 -0
- package/dist/plugins/choice/index.d.ts.map +1 -0
- package/dist/plugins/choice/index.js +8 -0
- package/dist/plugins/custom/index.d.ts +8 -0
- package/dist/plugins/custom/index.d.ts.map +1 -0
- package/dist/plugins/custom/index.js +8 -0
- package/dist/plugins/end-attempt/index.d.ts +8 -0
- package/dist/plugins/end-attempt/index.d.ts.map +1 -0
- package/dist/plugins/end-attempt/index.js +8 -0
- package/dist/plugins/extended-text/index.d.ts +8 -0
- package/dist/plugins/extended-text/index.d.ts.map +1 -0
- package/dist/plugins/extended-text/index.js +8 -0
- package/dist/plugins/gap-match/index.d.ts +8 -0
- package/dist/plugins/gap-match/index.d.ts.map +1 -0
- package/dist/plugins/gap-match/index.js +8 -0
- package/dist/plugins/graphic-associate/index.d.ts +8 -0
- package/dist/plugins/graphic-associate/index.d.ts.map +1 -0
- package/dist/plugins/graphic-associate/index.js +8 -0
- package/dist/plugins/graphic-gap-match/index.d.ts +8 -0
- package/dist/plugins/graphic-gap-match/index.d.ts.map +1 -0
- package/dist/plugins/graphic-gap-match/index.js +8 -0
- package/dist/plugins/graphic-order/index.d.ts +8 -0
- package/dist/plugins/graphic-order/index.d.ts.map +1 -0
- package/dist/plugins/graphic-order/index.js +8 -0
- package/dist/plugins/hotspot/index.d.ts +8 -0
- package/dist/plugins/hotspot/index.d.ts.map +1 -0
- package/dist/plugins/hotspot/index.js +8 -0
- package/dist/plugins/hottext/index.d.ts +8 -0
- package/dist/plugins/hottext/index.d.ts.map +1 -0
- package/dist/plugins/hottext/index.js +8 -0
- package/dist/plugins/index.d.ts +30 -0
- package/dist/plugins/index.d.ts.map +1 -0
- package/dist/plugins/index.js +30 -0
- package/dist/plugins/match/index.d.ts +8 -0
- package/dist/plugins/match/index.d.ts.map +1 -0
- package/dist/plugins/match/index.js +8 -0
- package/dist/plugins/media/index.d.ts +8 -0
- package/dist/plugins/media/index.d.ts.map +1 -0
- package/dist/plugins/media/index.js +8 -0
- package/dist/plugins/order/index.d.ts +8 -0
- package/dist/plugins/order/index.d.ts.map +1 -0
- package/dist/plugins/order/index.js +8 -0
- package/dist/plugins/position-object/index.d.ts +8 -0
- package/dist/plugins/position-object/index.d.ts.map +1 -0
- package/dist/plugins/position-object/index.js +8 -0
- package/dist/plugins/select-point/index.d.ts +8 -0
- package/dist/plugins/select-point/index.d.ts.map +1 -0
- package/dist/plugins/select-point/index.js +8 -0
- package/dist/plugins/slider/index.d.ts +8 -0
- package/dist/plugins/slider/index.d.ts.map +1 -0
- package/dist/plugins/slider/index.js +8 -0
- package/dist/shared/actions/typesetAction.d.ts +26 -0
- package/dist/shared/actions/typesetAction.d.ts.map +1 -0
- package/dist/shared/actions/typesetAction.js +70 -0
- package/dist/shared/extensions/MathLiveEditor.d.ts +19 -0
- package/dist/shared/extensions/MathLiveEditor.d.ts.map +1 -0
- package/dist/shared/extensions/MathLiveEditor.js +239 -0
- package/dist/shared/index.d.ts +11 -0
- package/dist/shared/index.d.ts.map +1 -0
- package/dist/shared/index.js +15 -0
- package/dist/shared/utils/eventHelpers.d.ts +18 -0
- package/dist/shared/utils/eventHelpers.d.ts.map +1 -0
- package/dist/shared/utils/eventHelpers.js +30 -0
- package/dist/shared/utils/pairHelpers.d.ts +55 -0
- package/dist/shared/utils/pairHelpers.d.ts.map +1 -0
- package/dist/shared/utils/pairHelpers.js +76 -0
- package/dist/shared/utils/touchDragHelper.d.ts +33 -0
- package/dist/shared/utils/touchDragHelper.d.ts.map +1 -0
- package/dist/shared/utils/touchDragHelper.js +168 -0
- package/dist/shared/utils/webComponentHelpers.d.ts +9 -0
- package/dist/shared/utils/webComponentHelpers.d.ts.map +1 -0
- package/dist/shared/utils/webComponentHelpers.js +26 -0
- package/package.json +93 -0
- package/src/index.ts +213 -0
- package/src/plugins/associate/AssociateInteraction.svelte +273 -0
- package/src/plugins/associate/index.ts +9 -0
- package/src/plugins/choice/ChoiceInteraction.svelte +212 -0
- package/src/plugins/choice/index.ts +9 -0
- package/src/plugins/custom/CustomInteraction.svelte +61 -0
- package/src/plugins/custom/index.ts +9 -0
- package/src/plugins/drawing/DrawingInteraction.svelte +90 -0
- package/src/plugins/end-attempt/EndAttemptInteraction.svelte +142 -0
- package/src/plugins/end-attempt/index.ts +9 -0
- package/src/plugins/extended-text/ExtendedTextInteraction.svelte +77 -0
- package/src/plugins/extended-text/index.ts +9 -0
- package/src/plugins/gap-match/GapMatchInteraction.svelte +379 -0
- package/src/plugins/gap-match/index.ts +9 -0
- package/src/plugins/graphic-associate/GraphicAssociateInteraction.svelte +427 -0
- package/src/plugins/graphic-associate/index.ts +9 -0
- package/src/plugins/graphic-gap-match/GraphicGapMatchInteraction.svelte +508 -0
- package/src/plugins/graphic-gap-match/index.ts +9 -0
- package/src/plugins/graphic-order/GraphicOrderInteraction.svelte +241 -0
- package/src/plugins/graphic-order/index.ts +9 -0
- package/src/plugins/hotspot/HotspotInteraction.svelte +244 -0
- package/src/plugins/hotspot/index.ts +9 -0
- package/src/plugins/hottext/HottextInteraction.svelte +296 -0
- package/src/plugins/hottext/index.ts +9 -0
- package/src/plugins/index.ts +31 -0
- package/src/plugins/match/MatchInteraction.svelte +70 -0
- package/src/plugins/match/index.ts +9 -0
- package/src/plugins/media/MediaInteraction.svelte +213 -0
- package/src/plugins/media/index.ts +9 -0
- package/src/plugins/order/OrderInteraction.svelte +159 -0
- package/src/plugins/order/index.ts +9 -0
- package/src/plugins/position-object/PositionObjectInteraction.svelte +671 -0
- package/src/plugins/position-object/README.md +130 -0
- package/src/plugins/position-object/index.ts +9 -0
- package/src/plugins/select-point/SelectPointInteraction.svelte +453 -0
- package/src/plugins/select-point/index.ts +9 -0
- package/src/plugins/slider/SliderInteraction.svelte +141 -0
- package/src/plugins/slider/index.ts +9 -0
- package/src/plugins/upload/UploadInteraction.svelte +59 -0
- package/src/shared/actions/typesetAction.ts +87 -0
- package/src/shared/components/CustomInteractionFallback.svelte +153 -0
- package/src/shared/components/DragHandle.svelte +44 -0
- package/src/shared/components/DrawingCanvas.svelte +243 -0
- package/src/shared/components/FileUpload.svelte +153 -0
- package/src/shared/components/GraphicGapMatch.svelte +316 -0
- package/src/shared/components/GraphicGapMatchAdapter.svelte +36 -0
- package/src/shared/components/InlineInteractionRenderer.svelte +124 -0
- package/src/shared/components/MatchDragDrop.svelte +434 -0
- package/src/shared/components/MathContent.svelte +18 -0
- package/src/shared/components/ModalFeedbackDisplay.svelte +81 -0
- package/src/shared/components/RichTextEditor.svelte +316 -0
- package/src/shared/components/ShadowBaseStyles.svelte +391 -0
- package/src/shared/components/SortableList.svelte +297 -0
- package/src/shared/extensions/MathLiveEditor.ts +304 -0
- package/src/shared/index.ts +17 -0
- package/src/shared/styles/shared.css +16 -0
- package/src/shared/utils/eventHelpers.ts +36 -0
- package/src/shared/utils/pairHelpers.ts +86 -0
- package/src/shared/utils/touchDragHelper.ts +211 -0
- package/src/shared/utils/webComponentHelpers.ts +27 -0
- package/src/svelte-shims.d.ts +9 -0
- package/svelte.config.js +9 -0
- package/tests/index.test.ts +8 -0
- package/tsconfig.json +20 -0
package/src/index.ts
ADDED
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @pie-qti/default-components
|
|
3
|
+
*
|
|
4
|
+
* Default Svelte-based component implementations for the QTI 2.x player.
|
|
5
|
+
* These components are packaged as web components that work with the
|
|
6
|
+
* framework-agnostic @pie-qti/item-player core.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import type { ComponentRegistry } from '@pie-qti/item-player';
|
|
10
|
+
|
|
11
|
+
// Export shared utilities and helpers
|
|
12
|
+
export * from './shared/index.js';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Register all default components with the ComponentRegistry
|
|
16
|
+
*
|
|
17
|
+
* This function should be called once at application startup to make
|
|
18
|
+
* all default interaction components available to the player.
|
|
19
|
+
*
|
|
20
|
+
* IMPORTANT: Before calling this function, you MUST import the plugin loader:
|
|
21
|
+
* ```typescript
|
|
22
|
+
* import '@pie-qti/default-components/plugins';
|
|
23
|
+
* ```
|
|
24
|
+
* This import triggers web component registration via Svelte's customElement option.
|
|
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', {
|
|
41
|
+
name: 'default-choice',
|
|
42
|
+
priority: 0,
|
|
43
|
+
description: 'Default Svelte-based choice interaction',
|
|
44
|
+
canHandle: () => true,
|
|
45
|
+
tagName: 'pie-qti-choice',
|
|
46
|
+
// No componentClass needed - Svelte already registered it
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
// SliderInteraction - Range slider
|
|
50
|
+
registry.register('sliderInteraction', {
|
|
51
|
+
name: 'default-slider',
|
|
52
|
+
priority: 0,
|
|
53
|
+
description: 'Default Svelte-based slider interaction',
|
|
54
|
+
canHandle: () => true,
|
|
55
|
+
tagName: 'pie-qti-slider',
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
// OrderInteraction - Sortable list
|
|
59
|
+
registry.register('orderInteraction', {
|
|
60
|
+
name: 'default-order',
|
|
61
|
+
priority: 0,
|
|
62
|
+
description: 'Default Svelte-based order interaction',
|
|
63
|
+
canHandle: () => true,
|
|
64
|
+
tagName: 'pie-qti-order',
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
// MatchInteraction - Match source to target
|
|
68
|
+
registry.register('matchInteraction', {
|
|
69
|
+
name: 'default-match',
|
|
70
|
+
priority: 0,
|
|
71
|
+
description: 'Default Svelte-based match interaction',
|
|
72
|
+
canHandle: () => true,
|
|
73
|
+
tagName: 'pie-qti-match',
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
// AssociateInteraction - Create associations between choices
|
|
77
|
+
registry.register('associateInteraction', {
|
|
78
|
+
name: 'default-associate',
|
|
79
|
+
priority: 0,
|
|
80
|
+
description: 'Default Svelte-based associate interaction',
|
|
81
|
+
canHandle: () => true,
|
|
82
|
+
tagName: 'pie-qti-associate',
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
// GapMatchInteraction - Fill gaps with words
|
|
86
|
+
registry.register('gapMatchInteraction', {
|
|
87
|
+
name: 'default-gap-match',
|
|
88
|
+
priority: 0,
|
|
89
|
+
description: 'Default Svelte-based gap match interaction',
|
|
90
|
+
canHandle: () => true,
|
|
91
|
+
tagName: 'pie-qti-gap-match',
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
// HotspotInteraction - Click on image hotspots
|
|
95
|
+
registry.register('hotspotInteraction', {
|
|
96
|
+
name: 'default-hotspot',
|
|
97
|
+
priority: 0,
|
|
98
|
+
description: 'Default Svelte-based hotspot interaction',
|
|
99
|
+
canHandle: () => true,
|
|
100
|
+
tagName: 'pie-qti-hotspot',
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
// HottextInteraction - Select text within content
|
|
104
|
+
registry.register('hottextInteraction', {
|
|
105
|
+
name: 'default-hottext',
|
|
106
|
+
priority: 0,
|
|
107
|
+
description: 'Default Svelte-based hottext interaction',
|
|
108
|
+
canHandle: () => true,
|
|
109
|
+
tagName: 'pie-qti-hottext',
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
// MediaInteraction - Audio/video playback with tracking
|
|
113
|
+
registry.register('mediaInteraction', {
|
|
114
|
+
name: 'default-media',
|
|
115
|
+
priority: 0,
|
|
116
|
+
description: 'Default Svelte-based media interaction',
|
|
117
|
+
canHandle: () => true,
|
|
118
|
+
tagName: 'pie-qti-media',
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
// CustomInteraction - Fallback for custom interactions
|
|
122
|
+
registry.register('customInteraction', {
|
|
123
|
+
name: 'default-custom',
|
|
124
|
+
priority: 0,
|
|
125
|
+
description: 'Default Svelte-based custom interaction',
|
|
126
|
+
canHandle: () => true,
|
|
127
|
+
tagName: 'pie-qti-custom',
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
// EndAttemptInteraction - End attempt button
|
|
131
|
+
registry.register('endAttemptInteraction', {
|
|
132
|
+
name: 'default-end-attempt',
|
|
133
|
+
priority: 0,
|
|
134
|
+
description: 'Default Svelte-based end attempt interaction',
|
|
135
|
+
canHandle: () => true,
|
|
136
|
+
tagName: 'pie-qti-end-attempt',
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
// PositionObjectInteraction - Drag objects onto canvas
|
|
140
|
+
registry.register('positionObjectInteraction', {
|
|
141
|
+
name: 'default-position-object',
|
|
142
|
+
priority: 0,
|
|
143
|
+
description: 'Default Svelte-based position object interaction',
|
|
144
|
+
canHandle: () => true,
|
|
145
|
+
tagName: 'pie-qti-position-object',
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
// GraphicGapMatchInteraction - Drag labels onto image hotspots
|
|
149
|
+
registry.register('graphicGapMatchInteraction', {
|
|
150
|
+
name: 'default-graphic-gap-match',
|
|
151
|
+
priority: 0,
|
|
152
|
+
description: 'Default Svelte-based graphic gap match interaction',
|
|
153
|
+
canHandle: () => true,
|
|
154
|
+
tagName: 'pie-qti-graphic-gap-match',
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
// GraphicOrderInteraction - Order items with graphic reference
|
|
158
|
+
registry.register('graphicOrderInteraction', {
|
|
159
|
+
name: 'default-graphic-order',
|
|
160
|
+
priority: 0,
|
|
161
|
+
description: 'Default Svelte-based graphic order interaction',
|
|
162
|
+
canHandle: () => true,
|
|
163
|
+
tagName: 'pie-qti-graphic-order',
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
// GraphicAssociateInteraction - Create associations on image
|
|
167
|
+
registry.register('graphicAssociateInteraction', {
|
|
168
|
+
name: 'default-graphic-associate',
|
|
169
|
+
priority: 0,
|
|
170
|
+
description: 'Default Svelte-based graphic associate interaction',
|
|
171
|
+
canHandle: () => true,
|
|
172
|
+
tagName: 'pie-qti-graphic-associate',
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
// SelectPointInteraction - Select points on image
|
|
176
|
+
registry.register('selectPointInteraction', {
|
|
177
|
+
name: 'default-select-point',
|
|
178
|
+
priority: 0,
|
|
179
|
+
description: 'Default Svelte-based select point interaction',
|
|
180
|
+
canHandle: () => true,
|
|
181
|
+
tagName: 'pie-qti-select-point',
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
// ExtendedTextInteraction - Rich text editor
|
|
185
|
+
registry.register('extendedTextInteraction', {
|
|
186
|
+
name: 'default-extended-text',
|
|
187
|
+
priority: 0,
|
|
188
|
+
description: 'Default Svelte-based extended text interaction',
|
|
189
|
+
canHandle: () => true,
|
|
190
|
+
tagName: 'pie-qti-extended-text',
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
// UploadInteraction - File upload
|
|
194
|
+
registry.register('uploadInteraction', {
|
|
195
|
+
name: 'default-upload',
|
|
196
|
+
priority: 0,
|
|
197
|
+
description: 'Default Svelte-based upload interaction',
|
|
198
|
+
canHandle: () => true,
|
|
199
|
+
tagName: 'pie-qti-upload',
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
// DrawingInteraction - Canvas drawing
|
|
203
|
+
registry.register('drawingInteraction', {
|
|
204
|
+
name: 'default-drawing',
|
|
205
|
+
priority: 0,
|
|
206
|
+
description: 'Default Svelte-based drawing interaction',
|
|
207
|
+
canHandle: () => true,
|
|
208
|
+
tagName: 'pie-qti-drawing',
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
// Note: TextEntryInteraction and InlineChoiceInteraction are handled
|
|
212
|
+
// by ItemRenderer as inline interactions, not as separate components
|
|
213
|
+
}
|
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
<svelte:options customElement="pie-qti-associate" />
|
|
2
|
+
|
|
3
|
+
<script lang="ts">
|
|
4
|
+
import type { AssociateInteractionData } from '@pie-qti/item-player';
|
|
5
|
+
import type { I18nProvider } from '@pie-qti/i18n';
|
|
6
|
+
import ShadowBaseStyles from '../../shared/components/ShadowBaseStyles.svelte';
|
|
7
|
+
import { parseJsonProp } from '../../shared/utils/webComponentHelpers';
|
|
8
|
+
|
|
9
|
+
interface Props {
|
|
10
|
+
interaction?: AssociateInteractionData | string;
|
|
11
|
+
response?: string[] | null;
|
|
12
|
+
correctResponse?: string[] | null;
|
|
13
|
+
disabled?: boolean;
|
|
14
|
+
role?: string;
|
|
15
|
+
i18n?: I18nProvider;
|
|
16
|
+
selectedForPairing?: string | null;
|
|
17
|
+
onSelectionChange?: (selected: string | null) => void;
|
|
18
|
+
onChange?: (value: string[]) => void;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
let {
|
|
22
|
+
interaction = $bindable(),
|
|
23
|
+
response = $bindable(),
|
|
24
|
+
correctResponse = $bindable(),
|
|
25
|
+
disabled = false,
|
|
26
|
+
role = 'candidate',
|
|
27
|
+
i18n = $bindable(),
|
|
28
|
+
selectedForPairing: externalSelectedForPairing,
|
|
29
|
+
onSelectionChange,
|
|
30
|
+
onChange,
|
|
31
|
+
}: Props = $props();
|
|
32
|
+
|
|
33
|
+
// Parse props that may be JSON strings (web component usage)
|
|
34
|
+
const parsedInteraction = $derived(parseJsonProp<AssociateInteractionData>(interaction));
|
|
35
|
+
const parsedResponse = $derived(parseJsonProp<string[]>(response));
|
|
36
|
+
const parsedCorrectResponse = $derived(parseJsonProp<string[]>(correctResponse));
|
|
37
|
+
const isShowingCorrect = $derived(role === 'scorer' && parsedCorrectResponse !== null);
|
|
38
|
+
|
|
39
|
+
// Get reference to the root element for event dispatching
|
|
40
|
+
let rootElement: HTMLDivElement | undefined = $state();
|
|
41
|
+
|
|
42
|
+
// Use external selection state if provided, otherwise use internal state
|
|
43
|
+
let internalSelectedForPairing = $state<string | null>(null);
|
|
44
|
+
const selectedForPairing = $derived(externalSelectedForPairing ?? internalSelectedForPairing);
|
|
45
|
+
|
|
46
|
+
// Ensure response is always an array
|
|
47
|
+
const pairs = $derived(parsedResponse || []);
|
|
48
|
+
|
|
49
|
+
function emitChange(newPairs: string[]) {
|
|
50
|
+
response = newPairs;
|
|
51
|
+
// Call onChange callback if provided (for Svelte component usage)
|
|
52
|
+
onChange?.(newPairs);
|
|
53
|
+
// Dispatch custom event for web component usage - event will bubble up to the host element
|
|
54
|
+
if (rootElement) {
|
|
55
|
+
const event = new CustomEvent('qti-change', {
|
|
56
|
+
detail: {
|
|
57
|
+
responseId: parsedInteraction?.responseId,
|
|
58
|
+
value: newPairs,
|
|
59
|
+
timestamp: Date.now(),
|
|
60
|
+
},
|
|
61
|
+
bubbles: true,
|
|
62
|
+
composed: true,
|
|
63
|
+
});
|
|
64
|
+
rootElement.dispatchEvent(event);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function setSelectedForPairing(value: string | null) {
|
|
69
|
+
if (onSelectionChange) {
|
|
70
|
+
onSelectionChange(value);
|
|
71
|
+
} else {
|
|
72
|
+
internalSelectedForPairing = value;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function handleChoiceClick(choiceId: string) {
|
|
77
|
+
if (disabled) return;
|
|
78
|
+
|
|
79
|
+
// If no item selected yet, select this one
|
|
80
|
+
if (selectedForPairing === null) {
|
|
81
|
+
setSelectedForPairing(choiceId);
|
|
82
|
+
}
|
|
83
|
+
// If same item clicked again, deselect
|
|
84
|
+
else if (selectedForPairing === choiceId) {
|
|
85
|
+
setSelectedForPairing(null);
|
|
86
|
+
}
|
|
87
|
+
// If different item clicked, create a pair
|
|
88
|
+
else {
|
|
89
|
+
const newPair = `${selectedForPairing} ${choiceId}`;
|
|
90
|
+
const newPairs = [...pairs, newPair];
|
|
91
|
+
emitChange(newPairs);
|
|
92
|
+
setSelectedForPairing(null);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function removePair(index: number) {
|
|
97
|
+
const newPairs = pairs.filter((_, i) => i !== index);
|
|
98
|
+
emitChange(newPairs);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function isInPair(choiceId: string): boolean {
|
|
102
|
+
return pairs.some((p) => p.includes(choiceId));
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function isCorrectPair(choiceId: string): boolean {
|
|
106
|
+
if (!isShowingCorrect) return false;
|
|
107
|
+
return (parsedCorrectResponse || []).some((p) => p.includes(choiceId));
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function isCorrectPairMatch(id1: string, id2: string): boolean {
|
|
111
|
+
if (!isShowingCorrect || !parsedCorrectResponse) return false;
|
|
112
|
+
return parsedCorrectResponse.some(
|
|
113
|
+
(p) => p === `${id1} ${id2}` || p === `${id2} ${id1}`
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const correctPairs = $derived(
|
|
118
|
+
isShowingCorrect && parsedCorrectResponse ? parsedCorrectResponse : []
|
|
119
|
+
);
|
|
120
|
+
</script>
|
|
121
|
+
|
|
122
|
+
<ShadowBaseStyles />
|
|
123
|
+
|
|
124
|
+
<div bind:this={rootElement} part="root" class="qti-associate-interaction space-y-3">
|
|
125
|
+
{#if !parsedInteraction}
|
|
126
|
+
<div class="alert alert-error">{i18n?.t('common.errorNoData', 'No interaction data provided')}</div>
|
|
127
|
+
{:else}
|
|
128
|
+
{#if parsedInteraction.prompt}
|
|
129
|
+
<p part="prompt" class="qti-associate-prompt font-semibold">{@html parsedInteraction.prompt}</p>
|
|
130
|
+
{/if}
|
|
131
|
+
|
|
132
|
+
<!-- Display choices as buttons that can be clicked to form pairs -->
|
|
133
|
+
<div part="choices" class="qti-associate-choices grid grid-cols-2 gap-2">
|
|
134
|
+
{#each parsedInteraction.choices as choice}
|
|
135
|
+
{@const isSelected = selectedForPairing === choice.identifier}
|
|
136
|
+
{@const inPair = isInPair(choice.identifier)}
|
|
137
|
+
{@const isCorrect = isCorrectPair(choice.identifier)}
|
|
138
|
+
<button
|
|
139
|
+
part="choice"
|
|
140
|
+
class="btn btn-outline {isSelected ? 'btn-accent' : inPair ? 'btn-primary' : isCorrect ? 'btn-success' : 'btn-neutral'}"
|
|
141
|
+
onclick={() => handleChoiceClick(choice.identifier)}
|
|
142
|
+
{disabled}
|
|
143
|
+
>
|
|
144
|
+
{@html choice.text}
|
|
145
|
+
{#if isSelected}
|
|
146
|
+
<span class="ml-2">◉</span>
|
|
147
|
+
{:else if inPair}
|
|
148
|
+
<span class="ml-2">✓</span>
|
|
149
|
+
{/if}
|
|
150
|
+
</button>
|
|
151
|
+
{/each}
|
|
152
|
+
</div>
|
|
153
|
+
|
|
154
|
+
<!-- Display correct associations when in scorer mode -->
|
|
155
|
+
{#if isShowingCorrect && correctPairs.length > 0}
|
|
156
|
+
<div part="correct-pairs-title" class="divider">
|
|
157
|
+
{i18n?.t('interactions.associate.correctAssociations') ?? 'Correct Associations'}
|
|
158
|
+
</div>
|
|
159
|
+
<div part="correct-pairs" class="qti-associate-pairs space-y-2">
|
|
160
|
+
{#each correctPairs as pair}
|
|
161
|
+
{@const [id1, id2] = pair.split(' ')}
|
|
162
|
+
{@const choice1 = parsedInteraction.choices.find((c: any) => c.identifier === id1)}
|
|
163
|
+
{@const choice2 = parsedInteraction.choices.find((c: any) => c.identifier === id2)}
|
|
164
|
+
{@const isInUserPairs = pairs.some((p) => p === pair || p === `${id2} ${id1}`)}
|
|
165
|
+
{#if choice1 && choice2}
|
|
166
|
+
<div
|
|
167
|
+
part="correct-pair"
|
|
168
|
+
class="qti-associate-pair flex items-center gap-4 p-2 bg-success/10 border border-success rounded"
|
|
169
|
+
>
|
|
170
|
+
<span class="flex-1">{choice1.text}</span>
|
|
171
|
+
<span class="text-success">↔</span>
|
|
172
|
+
<span class="flex-1">{choice2.text}</span>
|
|
173
|
+
<span class="badge badge-success badge-sm">
|
|
174
|
+
{i18n?.t('interactions.choice.correct', 'Correct') ?? 'Correct'}
|
|
175
|
+
</span>
|
|
176
|
+
</div>
|
|
177
|
+
{/if}
|
|
178
|
+
{/each}
|
|
179
|
+
</div>
|
|
180
|
+
{/if}
|
|
181
|
+
|
|
182
|
+
<!-- Display current pairs -->
|
|
183
|
+
{#if pairs.length > 0}
|
|
184
|
+
<div part="pairs-title" class="divider">
|
|
185
|
+
{i18n?.t('interactions.associate.currentAssociations') ?? 'Current Associations'}
|
|
186
|
+
</div>
|
|
187
|
+
<div part="pairs" class="qti-associate-pairs space-y-2">
|
|
188
|
+
{#each pairs as pair, index}
|
|
189
|
+
{@const [id1, id2] = pair.split(' ')}
|
|
190
|
+
{@const choice1 = parsedInteraction.choices.find((c: any) => c.identifier === id1)}
|
|
191
|
+
{@const choice2 = parsedInteraction.choices.find((c: any) => c.identifier === id2)}
|
|
192
|
+
{@const isCorrect = isCorrectPairMatch(id1, id2)}
|
|
193
|
+
{#if choice1 && choice2}
|
|
194
|
+
<div
|
|
195
|
+
part="pair"
|
|
196
|
+
class="qti-associate-pair flex items-center gap-4 p-2 rounded {isCorrect
|
|
197
|
+
? 'bg-success/10 border border-success'
|
|
198
|
+
: 'bg-primary/10 border border-base-300'}"
|
|
199
|
+
>
|
|
200
|
+
<span class="flex-1">{choice1.text}</span>
|
|
201
|
+
<span class="{isCorrect ? 'text-success' : 'text-primary'}">↔</span>
|
|
202
|
+
<span class="flex-1">{choice2.text}</span>
|
|
203
|
+
{#if isCorrect}
|
|
204
|
+
<span class="badge badge-success badge-sm">
|
|
205
|
+
{i18n?.t('interactions.choice.correct', 'Correct') ?? 'Correct'}
|
|
206
|
+
</span>
|
|
207
|
+
{/if}
|
|
208
|
+
<button
|
|
209
|
+
part="pair-remove"
|
|
210
|
+
class="btn btn-sm btn-ghost btn-circle"
|
|
211
|
+
onclick={() => removePair(index)}
|
|
212
|
+
{disabled}
|
|
213
|
+
>
|
|
214
|
+
✕
|
|
215
|
+
</button>
|
|
216
|
+
</div>
|
|
217
|
+
{/if}
|
|
218
|
+
{/each}
|
|
219
|
+
</div>
|
|
220
|
+
{/if}
|
|
221
|
+
|
|
222
|
+
<!-- Selection helper - Hide when showing correct answers -->
|
|
223
|
+
{#if !isShowingCorrect}
|
|
224
|
+
<div part="helper" class="qti-associate-helper alert alert-info">
|
|
225
|
+
<span class="text-sm">
|
|
226
|
+
{#if selectedForPairing}
|
|
227
|
+
{i18n?.t('interactions.associate.clickAnotherOrDeselect') ??
|
|
228
|
+
'Click another item to create an association (or click again to deselect)'}
|
|
229
|
+
{:else}
|
|
230
|
+
{i18n?.t('interactions.associate.clickToAssociate') ??
|
|
231
|
+
'Click two items to create an association between them'}
|
|
232
|
+
{/if}
|
|
233
|
+
</span>
|
|
234
|
+
</div>
|
|
235
|
+
{/if}
|
|
236
|
+
{/if}
|
|
237
|
+
</div>
|
|
238
|
+
|
|
239
|
+
<style>
|
|
240
|
+
/* Minimal layout so this works without Tailwind/DaisyUI */
|
|
241
|
+
.qti-associate-interaction {
|
|
242
|
+
display: grid;
|
|
243
|
+
gap: 0.75rem;
|
|
244
|
+
}
|
|
245
|
+
.qti-associate-prompt {
|
|
246
|
+
margin: 0;
|
|
247
|
+
}
|
|
248
|
+
.qti-associate-choices {
|
|
249
|
+
display: grid;
|
|
250
|
+
grid-template-columns: repeat(2, minmax(0, 1fr));
|
|
251
|
+
gap: 0.5rem;
|
|
252
|
+
}
|
|
253
|
+
@media (max-width: 640px) {
|
|
254
|
+
.qti-associate-choices {
|
|
255
|
+
grid-template-columns: 1fr;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
.qti-associate-pairs {
|
|
259
|
+
display: grid;
|
|
260
|
+
gap: 0.5rem;
|
|
261
|
+
}
|
|
262
|
+
.qti-associate-pair {
|
|
263
|
+
display: flex;
|
|
264
|
+
align-items: center;
|
|
265
|
+
gap: 0.75rem;
|
|
266
|
+
padding: 0.5rem;
|
|
267
|
+
border-radius: 0.75rem;
|
|
268
|
+
}
|
|
269
|
+
.qti-associate-helper {
|
|
270
|
+
border: 1px solid var(--color-base-300, oklch(95% 0 0));
|
|
271
|
+
background: var(--color-base-200, oklch(98% 0 0));
|
|
272
|
+
}
|
|
273
|
+
</style>
|