@pie-qti/default-components 0.1.9 → 0.1.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (181) hide show
  1. package/dist/chunks/__vite-browser-external-BjvdLQIS.js +9 -0
  2. package/dist/chunks/__vite-browser-external-BjvdLQIS.js.map +1 -0
  3. package/dist/chunks/chunk-Bayd9M4T.js +20 -0
  4. package/dist/chunks/{mathlive.min-Bvtiaxg4.js → mathlive.min-CAPebTxM.js} +245 -29
  5. package/dist/chunks/{mathlive.min-Bvtiaxg4.js.map → mathlive.min-CAPebTxM.js.map} +1 -1
  6. package/dist/index.d.ts +0 -1
  7. package/dist/index.js +1 -0
  8. package/dist/index.js.map +1 -0
  9. package/dist/plugins/associate/index.d.ts +0 -1
  10. package/dist/plugins/associate/index.js +1 -0
  11. package/dist/plugins/associate/index.js.map +1 -0
  12. package/dist/plugins/choice/index.d.ts +0 -1
  13. package/dist/plugins/choice/index.js +1 -0
  14. package/dist/plugins/choice/index.js.map +1 -0
  15. package/dist/plugins/custom/index.d.ts +0 -1
  16. package/dist/plugins/custom/index.js +1 -0
  17. package/dist/plugins/custom/index.js.map +1 -0
  18. package/dist/plugins/end-attempt/index.d.ts +0 -1
  19. package/dist/plugins/end-attempt/index.js +1 -0
  20. package/dist/plugins/end-attempt/index.js.map +1 -0
  21. package/dist/plugins/extended-text/index.d.ts +0 -1
  22. package/dist/plugins/extended-text/index.js +1 -0
  23. package/dist/plugins/extended-text/index.js.map +1 -0
  24. package/dist/plugins/gap-match/index.d.ts +0 -1
  25. package/dist/plugins/gap-match/index.js +1 -0
  26. package/dist/plugins/gap-match/index.js.map +1 -0
  27. package/dist/plugins/graphic-associate/index.d.ts +0 -1
  28. package/dist/plugins/graphic-associate/index.js +1 -0
  29. package/dist/plugins/graphic-associate/index.js.map +1 -0
  30. package/dist/plugins/graphic-gap-match/index.d.ts +0 -1
  31. package/dist/plugins/graphic-gap-match/index.js +1 -0
  32. package/dist/plugins/graphic-gap-match/index.js.map +1 -0
  33. package/dist/plugins/graphic-order/index.d.ts +0 -1
  34. package/dist/plugins/graphic-order/index.js +1 -0
  35. package/dist/plugins/graphic-order/index.js.map +1 -0
  36. package/dist/plugins/hotspot/index.d.ts +0 -1
  37. package/dist/plugins/hotspot/index.js +1 -0
  38. package/dist/plugins/hotspot/index.js.map +1 -0
  39. package/dist/plugins/hottext/index.d.ts +0 -1
  40. package/dist/plugins/hottext/index.js +1 -0
  41. package/dist/plugins/hottext/index.js.map +1 -0
  42. package/dist/plugins/match/index.d.ts +0 -1
  43. package/dist/plugins/match/index.js +1 -0
  44. package/dist/plugins/match/index.js.map +1 -0
  45. package/dist/plugins/media/index.d.ts +0 -1
  46. package/dist/plugins/media/index.js +1 -0
  47. package/dist/plugins/media/index.js.map +1 -0
  48. package/dist/plugins/order/index.d.ts +0 -1
  49. package/dist/plugins/order/index.js +1 -0
  50. package/dist/plugins/order/index.js.map +1 -0
  51. package/dist/plugins/position-object/index.d.ts +0 -1
  52. package/dist/plugins/position-object/index.js +1 -0
  53. package/dist/plugins/position-object/index.js.map +1 -0
  54. package/dist/plugins/public-types.d.ts +5 -0
  55. package/dist/plugins/public-types.js +2 -0
  56. package/dist/plugins/public-types.js.map +1 -0
  57. package/dist/plugins/select-point/index.d.ts +0 -1
  58. package/dist/plugins/select-point/index.js +1 -0
  59. package/dist/plugins/select-point/index.js.map +1 -0
  60. package/dist/plugins/slider/index.d.ts +0 -1
  61. package/dist/plugins/slider/index.js +1 -0
  62. package/dist/plugins/slider/index.js.map +1 -0
  63. package/dist/plugins.js +25958 -7690
  64. package/dist/plugins.js.map +1 -1
  65. package/dist/shared/actions/typesetAction.d.ts +0 -1
  66. package/dist/shared/actions/typesetAction.js +1 -0
  67. package/dist/shared/actions/typesetAction.js.map +1 -0
  68. package/dist/shared/extensions/MathLiveEditor.d.ts +0 -1
  69. package/dist/shared/extensions/MathLiveEditor.js +1 -0
  70. package/dist/shared/extensions/MathLiveEditor.js.map +1 -0
  71. package/dist/shared/index.d.ts +0 -2
  72. package/dist/shared/index.js +1 -2
  73. package/dist/shared/index.js.map +1 -0
  74. package/dist/shared/utils/eventHelpers.d.ts +6 -1
  75. package/dist/shared/utils/eventHelpers.js +7 -0
  76. package/dist/shared/utils/eventHelpers.js.map +1 -0
  77. package/dist/shared/utils/matchGroupUtils.d.ts +0 -1
  78. package/dist/shared/utils/matchGroupUtils.js +1 -0
  79. package/dist/shared/utils/matchGroupUtils.js.map +1 -0
  80. package/dist/shared/utils/pairHelpers.d.ts +0 -1
  81. package/dist/shared/utils/pairHelpers.js +1 -0
  82. package/dist/shared/utils/pairHelpers.js.map +1 -0
  83. package/dist/shared/utils/webComponentHelpers.d.ts +16 -1
  84. package/dist/shared/utils/webComponentHelpers.js +13 -0
  85. package/dist/shared/utils/webComponentHelpers.js.map +1 -0
  86. package/package.json +11 -33
  87. package/dist/index.d.ts.map +0 -1
  88. package/dist/plugins/associate/index.d.ts.map +0 -1
  89. package/dist/plugins/choice/index.d.ts.map +0 -1
  90. package/dist/plugins/custom/index.d.ts.map +0 -1
  91. package/dist/plugins/end-attempt/index.d.ts.map +0 -1
  92. package/dist/plugins/extended-text/index.d.ts.map +0 -1
  93. package/dist/plugins/gap-match/index.d.ts.map +0 -1
  94. package/dist/plugins/graphic-associate/index.d.ts.map +0 -1
  95. package/dist/plugins/graphic-gap-match/index.d.ts.map +0 -1
  96. package/dist/plugins/graphic-order/index.d.ts.map +0 -1
  97. package/dist/plugins/hotspot/index.d.ts.map +0 -1
  98. package/dist/plugins/hottext/index.d.ts.map +0 -1
  99. package/dist/plugins/index.d.ts +0 -31
  100. package/dist/plugins/index.d.ts.map +0 -1
  101. package/dist/plugins/index.js +0 -31
  102. package/dist/plugins/match/index.d.ts.map +0 -1
  103. package/dist/plugins/media/index.d.ts.map +0 -1
  104. package/dist/plugins/order/index.d.ts.map +0 -1
  105. package/dist/plugins/position-object/index.d.ts.map +0 -1
  106. package/dist/plugins/select-point/index.d.ts.map +0 -1
  107. package/dist/plugins/slider/index.d.ts.map +0 -1
  108. package/dist/shared/actions/typesetAction.d.ts.map +0 -1
  109. package/dist/shared/extensions/MathLiveEditor.d.ts.map +0 -1
  110. package/dist/shared/index.d.ts.map +0 -1
  111. package/dist/shared/utils/eventHelpers.d.ts.map +0 -1
  112. package/dist/shared/utils/matchGroupUtils.d.ts.map +0 -1
  113. package/dist/shared/utils/pairHelpers.d.ts.map +0 -1
  114. package/dist/shared/utils/touchDragHelper.d.ts +0 -2
  115. package/dist/shared/utils/touchDragHelper.d.ts.map +0 -1
  116. package/dist/shared/utils/touchDragHelper.js +0 -1
  117. package/dist/shared/utils/webComponentHelpers.d.ts.map +0 -1
  118. package/src/catalog/CatalogPopup.svelte +0 -163
  119. package/src/index.ts +0 -141
  120. package/src/plugins/associate/AssociateInteraction.svelte +0 -310
  121. package/src/plugins/associate/index.ts +0 -9
  122. package/src/plugins/choice/ChoiceInteraction.svelte +0 -358
  123. package/src/plugins/choice/index.ts +0 -9
  124. package/src/plugins/custom/CustomInteraction.svelte +0 -61
  125. package/src/plugins/custom/index.ts +0 -9
  126. package/src/plugins/drawing/DrawingInteraction.svelte +0 -99
  127. package/src/plugins/end-attempt/EndAttemptInteraction.svelte +0 -142
  128. package/src/plugins/end-attempt/index.ts +0 -9
  129. package/src/plugins/extended-text/ExtendedTextInteraction.svelte +0 -150
  130. package/src/plugins/extended-text/index.ts +0 -9
  131. package/src/plugins/gap-match/GapMatchInteraction.svelte +0 -556
  132. package/src/plugins/gap-match/index.ts +0 -9
  133. package/src/plugins/graphic-associate/GraphicAssociateInteraction.svelte +0 -503
  134. package/src/plugins/graphic-associate/index.ts +0 -9
  135. package/src/plugins/graphic-gap-match/GraphicGapMatchInteraction.svelte +0 -593
  136. package/src/plugins/graphic-gap-match/index.ts +0 -9
  137. package/src/plugins/graphic-order/GraphicOrderInteraction.svelte +0 -241
  138. package/src/plugins/graphic-order/index.ts +0 -9
  139. package/src/plugins/hotspot/HotspotInteraction.svelte +0 -287
  140. package/src/plugins/hotspot/index.ts +0 -9
  141. package/src/plugins/hottext/HottextInteraction.svelte +0 -325
  142. package/src/plugins/hottext/index.ts +0 -9
  143. package/src/plugins/index.ts +0 -32
  144. package/src/plugins/match/MatchInteraction.svelte +0 -82
  145. package/src/plugins/match/index.ts +0 -9
  146. package/src/plugins/media/MediaInteraction.svelte +0 -216
  147. package/src/plugins/media/index.ts +0 -9
  148. package/src/plugins/order/OrderInteraction.svelte +0 -280
  149. package/src/plugins/order/index.ts +0 -9
  150. package/src/plugins/position-object/PositionObjectInteraction.svelte +0 -903
  151. package/src/plugins/position-object/README.md +0 -130
  152. package/src/plugins/position-object/index.ts +0 -9
  153. package/src/plugins/select-point/SelectPointInteraction.svelte +0 -571
  154. package/src/plugins/select-point/index.ts +0 -9
  155. package/src/plugins/slider/SliderInteraction.svelte +0 -141
  156. package/src/plugins/slider/index.ts +0 -9
  157. package/src/plugins/upload/UploadInteraction.svelte +0 -59
  158. package/src/shared/actions/typesetAction.ts +0 -87
  159. package/src/shared/components/CustomInteractionFallback.svelte +0 -153
  160. package/src/shared/components/DragHandle.svelte +0 -44
  161. package/src/shared/components/DrawingCanvas.svelte +0 -259
  162. package/src/shared/components/FileUpload.svelte +0 -158
  163. package/src/shared/components/GraphicGapMatch.svelte +0 -318
  164. package/src/shared/components/GraphicGapMatchAdapter.svelte +0 -45
  165. package/src/shared/components/InlineInteractionRenderer.svelte +0 -141
  166. package/src/shared/components/MatchDragDrop.svelte +0 -481
  167. package/src/shared/components/MathContent.svelte +0 -18
  168. package/src/shared/components/ModalFeedbackDisplay.svelte +0 -91
  169. package/src/shared/components/RichTextEditor.svelte +0 -316
  170. package/src/shared/components/ShadowBaseStyles.svelte +0 -390
  171. package/src/shared/components/SortableList.svelte +0 -297
  172. package/src/shared/extensions/MathLiveEditor.ts +0 -299
  173. package/src/shared/index.ts +0 -17
  174. package/src/shared/styles/shared.css +0 -16
  175. package/src/shared/utils/eventHelpers.ts +0 -52
  176. package/src/shared/utils/matchGroupUtils.ts +0 -14
  177. package/src/shared/utils/pairHelpers.ts +0 -109
  178. package/src/shared/utils/touchDragHelper.ts +0 -1
  179. package/src/shared/utils/webComponentHelpers.ts +0 -27
  180. package/src/svelte-shims.d.ts +0 -9
  181. /package/{src → dist}/shared/styles/qti-shared-vocabulary.css +0 -0
@@ -1,481 +0,0 @@
1
- <script lang="ts">
2
- /**
3
- * Drag-and-drop matching component with keyboard, mouse, and touch support
4
- * Keyboard: Tab to navigate, Space/Enter to select source, Tab to targets, Space/Enter to match
5
- * Touch: Touch and drag source items to target drop zones
6
- */
7
-
8
- import type { AssociableChoice } from '@pie-qti/item-player';
9
- import type { I18nProvider } from '@pie-qti/i18n';
10
- import { createOrUpdatePair, getSourceForTarget, getTargetsForSource, removePairBySource } from '../utils/pairHelpers.js';
11
- import { touchDrag } from '../utils/touchDragHelper.js';
12
- import { isCompatibleMatchGroup } from '../utils/matchGroupUtils.js';
13
- import DragHandle from './DragHandle.svelte';
14
- import '../styles/shared.css';
15
-
16
- interface Props {
17
- sourceSet: AssociableChoice[];
18
- targetSet: AssociableChoice[];
19
- pairs: string[]; // Array of "sourceId targetId" pairs
20
- maxAssociations?: number; // 0 = unlimited per QTI spec
21
- correctPairs?: string[]; // Array of correct "sourceId targetId" pairs
22
- disabled?: boolean;
23
- i18n?: I18nProvider;
24
- onPairsChange: (newPairs: string[]) => void;
25
- }
26
-
27
- const { sourceSet, targetSet, pairs, maxAssociations = 0, correctPairs = [], disabled = false, i18n, onPairsChange }: Props = $props();
28
-
29
- // maxAssociations=0 means unlimited; otherwise cap total pairs
30
- const canAddMorePairs = $derived(maxAssociations === 0 || pairs.length < maxAssociations);
31
-
32
- // Targets incompatible with the active source due to matchGroup constraints
33
- const blockedTargetIds = $derived.by(() => {
34
- const activeSourceId = draggedSourceId ?? keyboardSelectedSourceId;
35
- if (!activeSourceId) return new Set<string>();
36
- const src = sourceSet.find((s) => s.identifier === activeSourceId);
37
- return new Set(
38
- targetSet
39
- .filter((t) => !isCompatibleMatchGroup(src?.matchGroup, t.matchGroup))
40
- .map((t) => t.identifier)
41
- );
42
- });
43
-
44
- let draggedSourceId = $state<string | null>(null);
45
- let keyboardSelectedSourceId = $state<string | null>(null); // Source selected via keyboard
46
- let announceText = $state<string>(''); // For screen reader announcements
47
-
48
- // Mouse drag handlers
49
- function handleDragStart(sourceId: string) {
50
- if (disabled) return;
51
- draggedSourceId = sourceId;
52
- }
53
-
54
- function handleDragOver(event: DragEvent) {
55
- if (disabled) return;
56
- event.preventDefault();
57
- }
58
-
59
- function handleDrop(event: DragEvent, targetId: string) {
60
- if (disabled || !draggedSourceId) return;
61
- event.preventDefault();
62
-
63
- if (blockedTargetIds.has(targetId)) {
64
- draggedSourceId = null;
65
- return;
66
- }
67
-
68
- // Allow replacing an existing pair for this source, but block new pairs when at limit
69
- const existingPair = pairs.find((p) => p.startsWith(draggedSourceId + ' '));
70
- if (!existingPair && !canAddMorePairs) {
71
- draggedSourceId = null;
72
- return;
73
- }
74
-
75
- createMatch(draggedSourceId, targetId);
76
- draggedSourceId = null;
77
- }
78
-
79
- function handleDragEnd() {
80
- draggedSourceId = null;
81
- }
82
-
83
- // Keyboard handlers for source items
84
- function handleSourceKeyDown(event: KeyboardEvent, sourceId: string) {
85
- if (disabled) return;
86
-
87
- const source = sourceSet.find((s) => s.identifier === sourceId);
88
- const sourceName = source?.text || 'Item';
89
-
90
- if (event.key === ' ' || event.key === 'Enter') {
91
- event.preventDefault();
92
-
93
- if (keyboardSelectedSourceId === sourceId) {
94
- // Deselect
95
- keyboardSelectedSourceId = null;
96
- announceText = `${sourceName} deselected`;
97
- } else {
98
- // Select this source for matching
99
- keyboardSelectedSourceId = sourceId;
100
- announceText = `${sourceName} selected. Navigate to a target and press Space or Enter to match.`;
101
- }
102
- } else if (event.key === 'Escape' && keyboardSelectedSourceId) {
103
- event.preventDefault();
104
- keyboardSelectedSourceId = null;
105
- announceText = `Selection cancelled`;
106
- }
107
- }
108
-
109
- // Keyboard handlers for target items
110
- function handleTargetKeyDown(event: KeyboardEvent, targetId: string) {
111
- if (disabled) return;
112
-
113
- const target = targetSet.find((t) => t.identifier === targetId);
114
- const targetName = target?.text || 'Target';
115
-
116
- if ((event.key === ' ' || event.key === 'Enter') && keyboardSelectedSourceId) {
117
- event.preventDefault();
118
-
119
- if (blockedTargetIds.has(targetId)) {
120
- announceText = `This target cannot be matched with the selected source.`;
121
- return;
122
- }
123
-
124
- const source = sourceSet.find((s) => s.identifier === keyboardSelectedSourceId);
125
- const sourceName = source?.text || 'Item';
126
-
127
- // Allow replacing an existing pair for this source, but block new pairs when at limit
128
- const existingPair = pairs.find((p) => p.startsWith(keyboardSelectedSourceId + ' '));
129
- if (!existingPair && !canAddMorePairs) {
130
- announceText = `Maximum associations reached. Remove a pair to add a new one.`;
131
- keyboardSelectedSourceId = null;
132
- return;
133
- }
134
-
135
- createMatch(keyboardSelectedSourceId, targetId);
136
- announceText = `${sourceName} matched with ${targetName}`;
137
- keyboardSelectedSourceId = null;
138
- }
139
- }
140
-
141
- // Create or update a match
142
- function createMatch(sourceId: string, targetId: string) {
143
- const newPairs = createOrUpdatePair(pairs, sourceId, targetId);
144
- onPairsChange(newPairs);
145
- }
146
-
147
- function clearMatch(sourceId: string) {
148
- if (disabled) return;
149
- const source = sourceSet.find((s) => s.identifier === sourceId);
150
- const sourceName = source?.text || 'Item';
151
-
152
- const newPairs = removePairBySource(pairs, sourceId);
153
- onPairsChange(newPairs);
154
-
155
- announceText = `Match cleared for ${sourceName}`;
156
- }
157
- </script>
158
-
159
- <!-- Screen reader announcements -->
160
- <div aria-live="polite" aria-atomic="true" class="sr-only">
161
- {announceText}
162
- </div>
163
-
164
- <!-- Instructions for keyboard users -->
165
- <div id="match-instructions" class="sr-only">
166
- Press Space or Enter to select a source item. Tab to navigate to targets. Press Space or Enter on a target to create a match. Press Escape to cancel selection.
167
- </div>
168
-
169
- <div
170
- class="qti-match-grid grid grid-cols-2 gap-6"
171
- part="grid"
172
- role="region"
173
- aria-describedby="match-instructions"
174
- >
175
- <!-- Source Set (Left Column) -->
176
- <div part="source-column" class="qti-match-col space-y-2" role="group" aria-label={i18n?.t('interactions.match.sourceItemsLabel') ?? 'Source items to match'}>
177
- <h3 part="source-heading" class="qti-match-heading font-semibold text-sm text-base-content/70 mb-3">
178
- {i18n?.t('interactions.match.dragFromHere') ?? 'Drag from here:'}
179
- </h3>
180
- {#each sourceSet as source (source.identifier)}
181
- {@const matchedTargets = getTargetsForSource(pairs, source.identifier)}
182
- {@const targetItems = matchedTargets.map((tid) => targetSet.find((t) => t.identifier === tid)).filter(Boolean)}
183
- {@const isSelected = keyboardSelectedSourceId === source.identifier}
184
- {@const correctTargets = getTargetsForSource(correctPairs, source.identifier)}
185
- {@const isCorrect = correctTargets.length > 0}
186
- {@const canDragMore = matchedTargets.length < (source.matchMax ?? 1)}
187
-
188
- <div class="qti-match-source-wrapper relative">
189
- <button
190
- type="button"
191
- draggable={!disabled && canDragMore}
192
- use:touchDrag
193
- ondragstart={() => handleDragStart(source.identifier)}
194
- ondragend={handleDragEnd}
195
- onkeydown={(e) => handleSourceKeyDown(e, source.identifier)}
196
- disabled={disabled}
197
- aria-label="{source.text}{targetItems.length ? '. Matched with ' + targetItems.map((t) => t?.text).join(', ') : ''}{isSelected ? '. Selected for matching' : ''}{isCorrect ? '. Correct answer' : ''}"
198
- aria-pressed={isSelected}
199
- data-matched={matchedTargets.length > 0}
200
- data-selected={isSelected}
201
- data-correct={isCorrect}
202
- data-dragging={draggedSourceId === source.identifier}
203
- part="source-item"
204
- class="qti-match-source p-3 rounded-lg border-2 transition-all w-full"
205
- class:bg-base-200={matchedTargets.length === 0 && !isSelected && !isCorrect}
206
- class:bg-success={matchedTargets.length > 0 || isCorrect}
207
- class:bg-primary={isSelected}
208
- class:bg-opacity-20={matchedTargets.length > 0 || isSelected || isCorrect}
209
- class:border-base-300={matchedTargets.length === 0 && !isSelected && !isCorrect}
210
- class:border-success={matchedTargets.length > 0 || isCorrect}
211
- class:border-primary={isSelected}
212
- class:ring-2={isSelected}
213
- class:ring-primary={isSelected}
214
- class:cursor-grab={!disabled && canDragMore && !isSelected}
215
- class:cursor-not-allowed={disabled}
216
- class:opacity-50={disabled || draggedSourceId === source.identifier}
217
- >
218
- <div class="qti-match-source-content flex items-center justify-between gap-2">
219
- <div class="qti-match-source-text flex-1">
220
- <div class="qti-match-source-title font-medium">{source.text}</div>
221
- {#if targetItems.length > 0}
222
- <div class="qti-match-source-sub text-sm text-success mt-1">→ {targetItems.map((t) => t?.text).join(', ')}</div>
223
- {:else if isCorrect && correctTargets.length > 0}
224
- {@const correctTargetItems = correctTargets.map((tid) => targetSet.find((t) => t.identifier === tid)).filter(Boolean)}
225
- {#if correctTargetItems.length > 0}
226
- <div class="qti-match-source-sub text-sm text-success mt-1">→ {correctTargetItems.map((t) => t?.text).join(', ')}</div>
227
- {/if}
228
- {/if}
229
- {#if isCorrect && matchedTargets.length === 0}
230
- <span class="badge badge-success badge-sm ml-2">{i18n?.t('interactions.choice.correct', 'Correct') ?? 'Correct'}</span>
231
- {/if}
232
- </div>
233
- {#if !disabled && canDragMore}
234
- <DragHandle size={1.25} opacity={0.3} class="text-base-content" />
235
- {/if}
236
- </div>
237
- </button>
238
- {#if matchedTargets.length > 0 && !disabled}
239
- <button
240
- type="button"
241
- part="source-clear"
242
- class="qti-match-clear btn btn-xs btn-ghost absolute top-2 right-2"
243
- onclick={() => clearMatch(source.identifier)}
244
- aria-label="Clear match for {source.text}"
245
- >
246
- ✕
247
- </button>
248
- {/if}
249
- </div>
250
- {/each}
251
- </div>
252
-
253
- <!-- Target Set (Right Column) - Drop Zones -->
254
- <div part="target-column" class="qti-match-col space-y-2" role="group" aria-label={i18n?.t('interactions.match.targetItemsLabel') ?? 'Target items for matching'}>
255
- <h3 part="target-heading" class="qti-match-heading font-semibold text-sm text-base-content/70 mb-3">
256
- {i18n?.t('interactions.match.dropHere') ?? 'Drop here:'}
257
- </h3>
258
- {#each targetSet as target (target.identifier)}
259
- {@const matchedSource = getSourceForTarget(pairs, target.identifier)}
260
- {@const sourceItem = matchedSource ? sourceSet.find((s) => s.identifier === matchedSource) : null}
261
- {@const isHighlight = (draggedSourceId && !matchedSource) || (keyboardSelectedSourceId && !matchedSource)}
262
- {@const correctSource = getSourceForTarget(correctPairs, target.identifier)}
263
- {@const isCorrect = correctSource !== null}
264
- {@const isBlocked = blockedTargetIds.has(target.identifier)}
265
-
266
- <button
267
- type="button"
268
- ondragover={handleDragOver}
269
- ondrop={(e) => handleDrop(e, target.identifier)}
270
- onkeydown={(e) => handleTargetKeyDown(e, target.identifier)}
271
- disabled={disabled || !keyboardSelectedSourceId}
272
- aria-disabled={isBlocked ? 'true' : undefined}
273
- aria-label="{target.text}{matchedSource && sourceItem ? '. Matched with ' + sourceItem.text : '. Available for matching'}{isCorrect ? '. Correct answer' : ''}{isBlocked ? '. Not compatible with selected source' : ''}"
274
- data-matched={!!matchedSource}
275
- data-highlight={isHighlight}
276
- data-correct={isCorrect}
277
- part="target"
278
- class="qti-match-target p-3 rounded-lg border-2 border-dashed min-h-[60px] transition-all"
279
- class:bg-base-100={!matchedSource && !isCorrect}
280
- class:bg-primary={matchedSource}
281
- class:bg-success={isCorrect && !matchedSource}
282
- class:bg-opacity-10={matchedSource}
283
- class:bg-opacity-20={isCorrect && !matchedSource}
284
- class:border-base-300={!matchedSource && !isCorrect}
285
- class:border-primary={matchedSource}
286
- class:border-success={isCorrect && !matchedSource}
287
- class:border-accent={draggedSourceId && !matchedSource || (keyboardSelectedSourceId && !matchedSource)}
288
- class:bg-accent={draggedSourceId && !matchedSource || (keyboardSelectedSourceId && !matchedSource)}
289
- class:bg-opacity-5={draggedSourceId && !matchedSource || (keyboardSelectedSourceId && !matchedSource)}
290
- class:opacity-40={isBlocked}
291
- class:cursor-not-allowed={isBlocked}
292
- >
293
- <div class="qti-match-target-content flex flex-col gap-1">
294
- <div class="qti-match-target-title font-medium text-base-content/70">{target.text}</div>
295
- {#if matchedSource && sourceItem}
296
- <div class="qti-match-target-sub text-sm text-primary font-medium">← {sourceItem.text}</div>
297
- {:else if isCorrect && correctSource}
298
- {@const correctSourceItem = sourceSet.find((s) => s.identifier === correctSource)}
299
- {#if correctSourceItem}
300
- <div class="qti-match-target-sub text-sm text-success font-medium">← {correctSourceItem.text}</div>
301
- {/if}
302
- {:else if !disabled}
303
- <div class="qti-match-target-hint text-xs text-base-content/70 italic">
304
- {keyboardSelectedSourceId
305
- ? (i18n?.t('interactions.match.dragInstruction') ?? 'Press Space or Enter to match')
306
- : (i18n?.t('interactions.match.dropTarget') ?? 'Drop item here')}
307
- </div>
308
- {/if}
309
- {#if isCorrect && !matchedSource}
310
- <span class="badge badge-success badge-sm mt-1">{i18n?.t('interactions.choice.correct', 'Correct') ?? 'Correct'}</span>
311
- {/if}
312
- </div>
313
- </button>
314
- {/each}
315
- </div>
316
- </div>
317
-
318
- <style>
319
- [draggable="true"] {
320
- touch-action: none;
321
- }
322
-
323
- /* Minimal, self-contained layout so the component doesn't break when Tailwind utilities aren't present */
324
- .qti-match-grid {
325
- display: grid;
326
- grid-template-columns: 1fr 1fr;
327
- gap: 1.5rem;
328
- }
329
- @media (max-width: 640px) {
330
- .qti-match-grid {
331
- grid-template-columns: 1fr;
332
- }
333
- }
334
- .qti-match-col {
335
- display: flex;
336
- flex-direction: column;
337
- gap: 0.5rem;
338
- min-width: 0;
339
- }
340
- .qti-match-heading {
341
- margin: 0 0 0.75rem;
342
- font-weight: 600;
343
- font-size: 0.875rem;
344
- color: color-mix(
345
- in oklch,
346
- var(--color-base-content, oklch(21% 0 0)) 70%,
347
- transparent
348
- );
349
- }
350
-
351
- .qti-match-source-wrapper {
352
- position: relative;
353
- }
354
- .qti-match-source {
355
- display: block;
356
- width: 100%;
357
- padding: 0.75rem;
358
- border-radius: 0.5rem;
359
- border: 2px solid var(--color-base-300, oklch(95% 0 0));
360
- background: var(--color-base-200, oklch(98% 0 0));
361
- color: var(--color-base-content, oklch(21% 0 0));
362
- text-align: left;
363
- user-select: none;
364
- transition: background-color 120ms ease, border-color 120ms ease, outline-color 120ms ease,
365
- opacity 120ms ease;
366
- }
367
- .qti-match-source:focus-visible {
368
- outline: 2px solid var(--color-primary, oklch(45% 0.24 277));
369
- outline-offset: 2px;
370
- }
371
- .qti-match-source[data-selected='true'] {
372
- border-color: var(--color-primary, oklch(45% 0.24 277));
373
- background: color-mix(in oklch, var(--color-primary, oklch(45% 0.24 277)) 8%, transparent);
374
- }
375
- .qti-match-source[data-matched='true'],
376
- .qti-match-source[data-correct='true'] {
377
- border-color: var(--color-success, oklch(76% 0.177 163.223));
378
- background: color-mix(in oklch, var(--color-success, oklch(76% 0.177 163.223)) 8%, transparent);
379
- }
380
- .qti-match-source[data-dragging='true'] {
381
- opacity: 0.55;
382
- }
383
-
384
- .qti-match-source-content {
385
- display: flex;
386
- align-items: center;
387
- justify-content: space-between;
388
- gap: 0.5rem;
389
- }
390
- .qti-match-source-text {
391
- flex: 1 1 auto;
392
- min-width: 0;
393
- }
394
- .qti-match-source-title {
395
- font-weight: 600;
396
- }
397
- .qti-match-source-sub {
398
- margin-top: 0.25rem;
399
- font-size: 0.875rem;
400
- color: var(--color-success, oklch(76% 0.177 163.223));
401
- }
402
-
403
- .qti-match-clear {
404
- position: absolute;
405
- top: 0.5rem;
406
- right: 0.5rem;
407
- width: 1.5rem;
408
- height: 1.5rem;
409
- display: inline-flex;
410
- align-items: center;
411
- justify-content: center;
412
- border-radius: 0.375rem;
413
- border: 1px solid transparent;
414
- background: transparent;
415
- color: inherit;
416
- cursor: pointer;
417
- }
418
- .qti-match-clear:hover {
419
- background: color-mix(in oklch, var(--color-base-300, oklch(95% 0 0)) 35%, transparent);
420
- }
421
-
422
- .qti-match-target {
423
- width: 100%;
424
- padding: 0.75rem;
425
- border-radius: 0.5rem;
426
- border: 2px dashed var(--color-base-300, oklch(95% 0 0));
427
- background: var(--color-base-100, oklch(100% 0 0));
428
- color: var(--color-base-content, oklch(21% 0 0));
429
- text-align: left;
430
- min-height: 60px;
431
- transition: background-color 120ms ease, border-color 120ms ease, outline-color 120ms ease,
432
- opacity 120ms ease;
433
- }
434
- .qti-match-target:focus-visible {
435
- outline: 2px solid var(--color-primary, oklch(45% 0.24 277));
436
- outline-offset: 2px;
437
- }
438
- .qti-match-target[data-matched='true'] {
439
- border-color: var(--color-primary, oklch(45% 0.24 277));
440
- background: color-mix(in oklch, var(--color-primary, oklch(45% 0.24 277)) 6%, transparent);
441
- }
442
- .qti-match-target[data-correct='true'] {
443
- border-color: var(--color-success, oklch(76% 0.177 163.223));
444
- background: color-mix(in oklch, var(--color-success, oklch(76% 0.177 163.223)) 8%, transparent);
445
- }
446
- .qti-match-target[data-highlight='true'] {
447
- border-color: var(--color-accent, oklch(77% 0.152 181.912));
448
- background: color-mix(in oklch, var(--color-accent, oklch(77% 0.152 181.912)) 6%, transparent);
449
- }
450
- .qti-match-target:disabled {
451
- opacity: 0.6;
452
- cursor: not-allowed;
453
- }
454
- .qti-match-target-content {
455
- display: flex;
456
- flex-direction: column;
457
- gap: 0.25rem;
458
- }
459
- .qti-match-target-title {
460
- font-weight: 600;
461
- color: color-mix(
462
- in oklch,
463
- var(--color-base-content, oklch(21% 0 0)) 70%,
464
- transparent
465
- );
466
- }
467
- .qti-match-target-sub {
468
- font-size: 0.875rem;
469
- font-weight: 600;
470
- color: hsl(var(--p, 240 100% 50%));
471
- }
472
- .qti-match-target-hint {
473
- font-size: 0.75rem;
474
- font-style: italic;
475
- color: color-mix(
476
- in oklch,
477
- var(--color-base-content, oklch(21% 0 0)) 70%,
478
- transparent
479
- );
480
- }
481
- </style>
@@ -1,18 +0,0 @@
1
- <script lang="ts">
2
- import { typesetAction } from '../actions/typesetAction.js';
3
-
4
- interface Props {
5
- /** HTML content that may contain MathML or LaTeX */
6
- content: string;
7
- /** Typeset function (KaTeX, MathJax, etc.) */
8
- typeset: (root: HTMLElement) => void | Promise<void>;
9
- /** Additional CSS classes */
10
- class?: string;
11
- }
12
-
13
- const { content, typeset, class: className = '' }: Props = $props();
14
- </script>
15
-
16
- <div class={className} use:typesetAction={{ typeset }}>
17
- {@html content}
18
- </div>
@@ -1,91 +0,0 @@
1
- <script lang="ts">
2
- import type { ModalFeedback } from '@pie-qti/item-player';
3
- import type { I18nProvider } from '@pie-qti/i18n';
4
- import { typesetAction } from '../actions/typesetAction';
5
-
6
- interface Props {
7
- feedback: ModalFeedback[];
8
- onClose?: () => void;
9
- typeset?: (element: HTMLElement) => void;
10
- i18n?: I18nProvider;
11
- }
12
-
13
- let { feedback = [], onClose, typeset, i18n }: Props = $props();
14
-
15
- // Show modal if there's feedback
16
- const hasActiveFeedback = $derived(feedback.length > 0);
17
- const modalTitleId = 'modal-feedback-title';
18
- const firstTitle = $derived(feedback.find((item) => item.title)?.title);
19
-
20
- function handleClose() {
21
- onClose?.();
22
- }
23
-
24
- function handleBackdropClick(e: MouseEvent) {
25
- // Close when clicking the backdrop (outside the modal content)
26
- if (e.target === e.currentTarget) {
27
- handleClose();
28
- }
29
- }
30
- </script>
31
-
32
- {#if hasActiveFeedback}
33
- <!-- DaisyUI Modal -->
34
- <dialog
35
- open
36
- class="modal modal-open"
37
- aria-modal="true"
38
- aria-labelledby={firstTitle ? modalTitleId : undefined}
39
- aria-label={firstTitle ? undefined : (i18n?.t('feedback.title') ?? 'Feedback')}
40
- onclick={handleBackdropClick}
41
- >
42
- <div class="modal-box max-w-3xl">
43
- <!-- Close button -->
44
- <button
45
- class="btn btn-sm btn-circle btn-ghost absolute right-2 top-2"
46
- type="button"
47
- onclick={handleClose}
48
- aria-label={i18n?.t('feedback.close') ?? 'Close feedback'}
49
- >
50
- ✕
51
- </button>
52
-
53
- <!-- Feedback content -->
54
- {#each feedback as item, index}
55
- <div class="mb-4 {index < feedback.length - 1 ? 'border-b pb-4' : ''}">
56
- {#if item.title}
57
- <h3 id={index === 0 ? modalTitleId : undefined} class="font-bold text-lg mb-2">{item.title}</h3>
58
- {/if}
59
-
60
- <!-- Render HTML content with MathJax support -->
61
- <div
62
- class="prose max-w-none"
63
- use:typesetAction={{ typeset }}
64
- >
65
- {@html item.content}
66
- </div>
67
- </div>
68
- {/each}
69
-
70
- <!-- Action buttons -->
71
- <div class="modal-action">
72
- <button class="btn btn-primary" type="button" onclick={handleClose}>
73
- Continue
74
- </button>
75
- </div>
76
- </div>
77
- </dialog>
78
- {/if}
79
-
80
- <style>
81
- /* Ensure modal is accessible */
82
- dialog {
83
- background-color: rgba(0, 0, 0, 0.5);
84
- }
85
-
86
- /* Ensure feedback content is readable */
87
- .modal-box {
88
- max-height: 80vh;
89
- overflow-y: auto;
90
- }
91
- </style>