@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
|
@@ -0,0 +1,379 @@
|
|
|
1
|
+
<svelte:options customElement="pie-qti-gap-match" />
|
|
2
|
+
|
|
3
|
+
<script lang="ts">
|
|
4
|
+
import type { GapMatchInteractionData } from '@pie-qti/item-player';
|
|
5
|
+
import type { I18nProvider } from '@pie-qti/i18n';
|
|
6
|
+
import ShadowBaseStyles from '../../shared/components/ShadowBaseStyles.svelte';
|
|
7
|
+
import { createQtiChangeEvent } from '../../shared/utils/eventHelpers';
|
|
8
|
+
import { parseJsonProp } from '../../shared/utils/webComponentHelpers';
|
|
9
|
+
|
|
10
|
+
interface Props {
|
|
11
|
+
interaction?: GapMatchInteractionData | string;
|
|
12
|
+
response?: string[];
|
|
13
|
+
correctResponse?: string[] | null;
|
|
14
|
+
disabled?: boolean;
|
|
15
|
+
role?: string;
|
|
16
|
+
i18n?: I18nProvider;
|
|
17
|
+
onChange?: (value: string[]) => void;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
let { interaction = $bindable(), response = $bindable(), correctResponse = $bindable(), disabled = false, role = 'candidate', i18n = $bindable(), onChange }: Props = $props();
|
|
21
|
+
|
|
22
|
+
// Parse props that may be JSON strings (web component usage)
|
|
23
|
+
const parsedInteraction = $derived(parseJsonProp<GapMatchInteractionData>(interaction));
|
|
24
|
+
const parsedResponse = $derived(parseJsonProp<string[]>(response));
|
|
25
|
+
const parsedCorrectResponse = $derived(parseJsonProp<string[]>(correctResponse));
|
|
26
|
+
const isShowingCorrect = $derived(role === 'scorer' && parsedCorrectResponse !== null);
|
|
27
|
+
|
|
28
|
+
const pairs = $derived(Array.isArray(parsedResponse) ? parsedResponse : []);
|
|
29
|
+
const correctPairs = $derived(Array.isArray(parsedCorrectResponse) ? parsedCorrectResponse : []);
|
|
30
|
+
|
|
31
|
+
// Get reference to the root element for event dispatching
|
|
32
|
+
let rootElement: HTMLDivElement | undefined = $state();
|
|
33
|
+
|
|
34
|
+
// Rendered prompt container - we keep the original HTML structure and insert live gap targets.
|
|
35
|
+
let promptContainer: HTMLDivElement | undefined = $state();
|
|
36
|
+
|
|
37
|
+
// Track cleanup functions for event listeners to prevent memory leaks
|
|
38
|
+
let cleanupFunctions: (() => void)[] = [];
|
|
39
|
+
|
|
40
|
+
function handleGapChange(gapId: string, wordId: string) {
|
|
41
|
+
// Remove any existing pair for this gap
|
|
42
|
+
const newPairs = pairs.filter((p: string) => !p.endsWith(` ${gapId}`));
|
|
43
|
+
|
|
44
|
+
// If this word is already used in another gap, move it (remove its previous assignment).
|
|
45
|
+
const withoutWord = newPairs.filter((p: string) => !p.startsWith(`${wordId} `));
|
|
46
|
+
|
|
47
|
+
// Add new pair if a word was selected
|
|
48
|
+
if (wordId) {
|
|
49
|
+
withoutWord.push(`${wordId} ${gapId}`);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
response = withoutWord;
|
|
53
|
+
// Call onChange callback if provided (for Svelte component usage)
|
|
54
|
+
onChange?.(withoutWord);
|
|
55
|
+
// Dispatch event for web component usage - event will bubble up to the host element
|
|
56
|
+
if (rootElement) {
|
|
57
|
+
rootElement.dispatchEvent(createQtiChangeEvent(parsedInteraction?.responseId, withoutWord));
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function isWordUsed(wordId: string): boolean {
|
|
62
|
+
return pairs.some((p: string) => p.startsWith(wordId));
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function getSelectedWord(gapId: string): string {
|
|
66
|
+
const pair = pairs.find((p: string) => p.endsWith(` ${gapId}`));
|
|
67
|
+
return pair ? pair.split(' ')[0] : '';
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function getCorrectWord(gapId: string): string {
|
|
71
|
+
const pair = correctPairs.find((p: string) => p.endsWith(` ${gapId}`));
|
|
72
|
+
return pair ? pair.split(' ')[0] : '';
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function isCorrectGap(gapId: string): boolean {
|
|
76
|
+
return isShowingCorrect && getCorrectWord(gapId) !== '';
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function getWordText(wordId: string): string {
|
|
80
|
+
const w = parsedInteraction?.gapTexts?.find((gt) => gt.identifier === wordId);
|
|
81
|
+
return w?.text ?? wordId;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function onWordDragStart(e: DragEvent, wordId: string) {
|
|
85
|
+
if (disabled) return;
|
|
86
|
+
if (!e.dataTransfer) return;
|
|
87
|
+
e.dataTransfer.setData('text/plain', wordId);
|
|
88
|
+
e.dataTransfer.effectAllowed = 'move';
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function clearWord(wordId: string) {
|
|
92
|
+
if (disabled) return;
|
|
93
|
+
const newPairs = pairs.filter((p: string) => !p.startsWith(`${wordId} `));
|
|
94
|
+
response = newPairs;
|
|
95
|
+
// Call onChange callback if provided (for Svelte component usage)
|
|
96
|
+
onChange?.(newPairs);
|
|
97
|
+
// Dispatch event for web component usage - event will bubble up to the host element
|
|
98
|
+
if (rootElement) {
|
|
99
|
+
rootElement.dispatchEvent(createQtiChangeEvent(parsedInteraction?.responseId, newPairs));
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function renderPromptWithGaps() {
|
|
104
|
+
if (!promptContainer || !parsedInteraction?.promptText) return;
|
|
105
|
+
|
|
106
|
+
// Clean up any existing event listeners before creating new ones
|
|
107
|
+
cleanupFunctions.forEach(cleanup => cleanup());
|
|
108
|
+
cleanupFunctions = [];
|
|
109
|
+
|
|
110
|
+
// Replace placeholders with marker spans so we can keep the original HTML structure.
|
|
111
|
+
const html = parsedInteraction.promptText.replace(/\[GAP:([^\]]+)\]/g, (_m, gapId) => {
|
|
112
|
+
const safe = String(gapId).replace(/"/g, '"');
|
|
113
|
+
return `<span data-gap-placeholder="${safe}"></span>`;
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
const tpl = document.createElement('template');
|
|
117
|
+
tpl.innerHTML = html;
|
|
118
|
+
promptContainer.innerHTML = '';
|
|
119
|
+
promptContainer.appendChild(tpl.content.cloneNode(true));
|
|
120
|
+
|
|
121
|
+
const placeholders = Array.from(
|
|
122
|
+
promptContainer.querySelectorAll<HTMLSpanElement>('[data-gap-placeholder]')
|
|
123
|
+
);
|
|
124
|
+
for (const ph of placeholders) {
|
|
125
|
+
const gapId = ph.getAttribute('data-gap-placeholder') ?? '';
|
|
126
|
+
if (!gapId) continue;
|
|
127
|
+
|
|
128
|
+
const btn = document.createElement('button');
|
|
129
|
+
btn.type = 'button';
|
|
130
|
+
btn.setAttribute('part', 'gap');
|
|
131
|
+
btn.setAttribute('data-gap-id', gapId);
|
|
132
|
+
// Match the look/feel of other interactions (DaisyUI input/select styling when present).
|
|
133
|
+
btn.className = 'qti-gm-gap-target select select-bordered select-sm';
|
|
134
|
+
|
|
135
|
+
const selected = getSelectedWord(gapId);
|
|
136
|
+
const correct = getCorrectWord(gapId);
|
|
137
|
+
const isCorrect = isCorrectGap(gapId);
|
|
138
|
+
if (selected) {
|
|
139
|
+
const word = getWordText(selected);
|
|
140
|
+
btn.textContent = word;
|
|
141
|
+
btn.removeAttribute('data-empty');
|
|
142
|
+
if (isCorrect) {
|
|
143
|
+
btn.classList.add('qti-gm-gap-correct');
|
|
144
|
+
}
|
|
145
|
+
const filledAriaLabel = i18n?.t('interactions.gapMatch.filledGapAriaLabel', { gapId, word }) ?? `Blank ${gapId}, filled with ${word}. Click to clear.${isCorrect ? ' Correct answer.' : ''}`;
|
|
146
|
+
btn.setAttribute('aria-label', filledAriaLabel);
|
|
147
|
+
} else {
|
|
148
|
+
// Keep the gap visually blank (no letters), but still accessible.
|
|
149
|
+
btn.textContent = '';
|
|
150
|
+
btn.setAttribute('data-empty', 'true');
|
|
151
|
+
if (isCorrect && correct) {
|
|
152
|
+
const correctWord = getWordText(correct);
|
|
153
|
+
btn.textContent = correctWord;
|
|
154
|
+
btn.classList.add('qti-gm-gap-correct');
|
|
155
|
+
btn.removeAttribute('data-empty');
|
|
156
|
+
}
|
|
157
|
+
const ariaLabel = i18n?.t('interactions.gapMatch.blankGapAriaLabel', { gapId }) ?? `Blank ${gapId}. Drop an answer here.${isCorrect ? ' Correct answer: ' + getWordText(correct) : ''}`;
|
|
158
|
+
btn.setAttribute('aria-label', ariaLabel);
|
|
159
|
+
}
|
|
160
|
+
if (disabled) btn.setAttribute('aria-disabled', 'true');
|
|
161
|
+
|
|
162
|
+
const onDragEnter = (e: DragEvent) => {
|
|
163
|
+
if (disabled) return;
|
|
164
|
+
e.preventDefault();
|
|
165
|
+
btn.classList.add('is-dragover');
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
const onDragOver = (e: DragEvent) => {
|
|
169
|
+
if (disabled) return;
|
|
170
|
+
e.preventDefault();
|
|
171
|
+
btn.classList.add('is-dragover');
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
const onDragLeave = () => {
|
|
175
|
+
btn.classList.remove('is-dragover');
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
const onDrop = (e: DragEvent) => {
|
|
179
|
+
if (disabled) return;
|
|
180
|
+
e.preventDefault();
|
|
181
|
+
btn.classList.remove('is-dragover');
|
|
182
|
+
const wordId = e.dataTransfer?.getData('text/plain') ?? '';
|
|
183
|
+
if (!wordId) return;
|
|
184
|
+
handleGapChange(gapId, wordId);
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
const onClick = () => {
|
|
188
|
+
if (disabled) return;
|
|
189
|
+
const current = getSelectedWord(gapId);
|
|
190
|
+
if (current) handleGapChange(gapId, '');
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
btn.addEventListener('dragenter', onDragEnter);
|
|
194
|
+
btn.addEventListener('dragover', onDragOver);
|
|
195
|
+
btn.addEventListener('dragleave', onDragLeave);
|
|
196
|
+
btn.addEventListener('drop', onDrop);
|
|
197
|
+
btn.addEventListener('click', onClick);
|
|
198
|
+
|
|
199
|
+
// Store cleanup functions to remove event listeners later
|
|
200
|
+
cleanupFunctions.push(() => {
|
|
201
|
+
btn.removeEventListener('dragenter', onDragEnter);
|
|
202
|
+
btn.removeEventListener('dragover', onDragOver);
|
|
203
|
+
btn.removeEventListener('dragleave', onDragLeave);
|
|
204
|
+
btn.removeEventListener('drop', onDrop);
|
|
205
|
+
btn.removeEventListener('click', onClick);
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
ph.replaceWith(btn);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// Re-render prompt when interaction or response changes (keeps selected word labels in sync)
|
|
213
|
+
$effect(() => {
|
|
214
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
|
215
|
+
parsedInteraction?.promptText;
|
|
216
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
|
217
|
+
pairs.length;
|
|
218
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
|
219
|
+
correctPairs.length;
|
|
220
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
|
221
|
+
isShowingCorrect;
|
|
222
|
+
renderPromptWithGaps();
|
|
223
|
+
});
|
|
224
|
+
</script>
|
|
225
|
+
|
|
226
|
+
<ShadowBaseStyles />
|
|
227
|
+
|
|
228
|
+
<div bind:this={rootElement} part="root" class="qti-gap-match-interaction space-y-3">
|
|
229
|
+
{#if !parsedInteraction}
|
|
230
|
+
<div class="alert alert-error">{i18n?.t('common.errorNoData', 'No interaction data provided')}</div>
|
|
231
|
+
{:else}
|
|
232
|
+
{#if parsedInteraction.prompt}
|
|
233
|
+
<p part="prompt" class="qti-gm-prompt font-semibold">{@html parsedInteraction.prompt}</p>
|
|
234
|
+
{/if}
|
|
235
|
+
|
|
236
|
+
<!-- Available gap texts (draggable words) -->
|
|
237
|
+
<div
|
|
238
|
+
part="palette"
|
|
239
|
+
class="qti-gm-palette flex flex-wrap gap-2 p-4 bg-base-200 rounded-lg border-2 border-base-300"
|
|
240
|
+
role="group"
|
|
241
|
+
aria-label={i18n?.t('interactions.gapMatch.availableLabel') ?? 'Available words to place'}
|
|
242
|
+
>
|
|
243
|
+
<div class="qti-gm-palette-title w-full text-sm text-base-content/70 font-semibold mb-2">
|
|
244
|
+
Available words:
|
|
245
|
+
</div>
|
|
246
|
+
{#each parsedInteraction.gapTexts as gapText (gapText.identifier)}
|
|
247
|
+
{@const used = isWordUsed(gapText.identifier)}
|
|
248
|
+
<div class="inline-flex items-center gap-1">
|
|
249
|
+
<button
|
|
250
|
+
part="word"
|
|
251
|
+
type="button"
|
|
252
|
+
class="btn btn-md font-medium transition-all"
|
|
253
|
+
class:btn-primary={!used}
|
|
254
|
+
class:btn-success={used}
|
|
255
|
+
class:cursor-grab={!disabled && !used}
|
|
256
|
+
class:cursor-not-allowed={disabled}
|
|
257
|
+
class:opacity-70={disabled}
|
|
258
|
+
data-word-id={gapText.identifier}
|
|
259
|
+
draggable={!disabled && !used}
|
|
260
|
+
aria-disabled={disabled || used}
|
|
261
|
+
disabled={disabled || used}
|
|
262
|
+
ondragstart={(e: DragEvent) => onWordDragStart(e, gapText.identifier)}
|
|
263
|
+
>
|
|
264
|
+
{gapText.text}
|
|
265
|
+
</button>
|
|
266
|
+
{#if used && !disabled}
|
|
267
|
+
<button
|
|
268
|
+
type="button"
|
|
269
|
+
part="word-remove"
|
|
270
|
+
class="btn btn-sm btn-circle btn-error"
|
|
271
|
+
onclick={() => clearWord(gapText.identifier)}
|
|
272
|
+
aria-label="Remove {gapText.text} from the blanks"
|
|
273
|
+
title={i18n?.t('interactions.gapMatch.removeWord') ?? 'Remove word'}
|
|
274
|
+
>
|
|
275
|
+
✕
|
|
276
|
+
</button>
|
|
277
|
+
{/if}
|
|
278
|
+
</div>
|
|
279
|
+
{/each}
|
|
280
|
+
</div>
|
|
281
|
+
|
|
282
|
+
<!-- Render the text with gaps as drop targets, preserving original HTML structure -->
|
|
283
|
+
<div part="text" class="qti-gm-text p-4 bg-base-100 border border-base-300 rounded">
|
|
284
|
+
<div bind:this={promptContainer} class="qti-gm-inline"></div>
|
|
285
|
+
</div>
|
|
286
|
+
{/if}
|
|
287
|
+
</div>
|
|
288
|
+
|
|
289
|
+
<style>
|
|
290
|
+
/* Minimal layout so this works without Tailwind/DaisyUI */
|
|
291
|
+
.qti-gap-match-interaction {
|
|
292
|
+
display: grid;
|
|
293
|
+
gap: 0.75rem;
|
|
294
|
+
}
|
|
295
|
+
.qti-gm-prompt {
|
|
296
|
+
margin: 0;
|
|
297
|
+
}
|
|
298
|
+
.qti-gm-palette {
|
|
299
|
+
display: flex;
|
|
300
|
+
flex-wrap: wrap;
|
|
301
|
+
gap: 0.5rem;
|
|
302
|
+
padding: 1rem;
|
|
303
|
+
border-radius: 0.75rem;
|
|
304
|
+
border: 2px solid var(--color-base-300, oklch(95% 0 0));
|
|
305
|
+
background: var(--color-base-200, oklch(98% 0 0));
|
|
306
|
+
align-items: center;
|
|
307
|
+
}
|
|
308
|
+
.qti-gm-text {
|
|
309
|
+
padding: 1rem;
|
|
310
|
+
border-radius: 0.75rem;
|
|
311
|
+
border: 1px solid var(--color-base-300, oklch(95% 0 0));
|
|
312
|
+
background: var(--color-base-100, oklch(100% 0 0));
|
|
313
|
+
}
|
|
314
|
+
:global(.qti-gm-gap-target) {
|
|
315
|
+
display: inline-flex;
|
|
316
|
+
align-items: center;
|
|
317
|
+
justify-content: center;
|
|
318
|
+
min-width: 6.25rem;
|
|
319
|
+
margin: 0 0.25rem;
|
|
320
|
+
/* Height/padding/border/background should come from DaisyUI `select select-sm`
|
|
321
|
+
(or ShadowBaseStyles fallback), so empty and filled gaps match exactly. */
|
|
322
|
+
font: inherit;
|
|
323
|
+
vertical-align: baseline;
|
|
324
|
+
cursor: pointer;
|
|
325
|
+
transition:
|
|
326
|
+
border-color 120ms ease,
|
|
327
|
+
box-shadow 120ms ease,
|
|
328
|
+
background-color 120ms ease;
|
|
329
|
+
}
|
|
330
|
+
:global(.qti-gm-gap-target[data-empty='true']) {
|
|
331
|
+
/* Same size + base styling as a filled gap, but dashed to indicate “drop here”. */
|
|
332
|
+
border-style: dashed;
|
|
333
|
+
border-color: color-mix(
|
|
334
|
+
in oklch,
|
|
335
|
+
var(--color-base-content, oklch(21% 0 0)) 18%,
|
|
336
|
+
var(--color-base-300, oklch(95% 0 0))
|
|
337
|
+
);
|
|
338
|
+
}
|
|
339
|
+
:global(.qti-gm-gap-target[data-empty='true']::before) {
|
|
340
|
+
/* Ensure empty gaps reserve the same line-height as filled gaps (no visible text). */
|
|
341
|
+
content: '\00a0';
|
|
342
|
+
}
|
|
343
|
+
:global(.qti-gm-gap-target.is-dragover) {
|
|
344
|
+
border-color: var(--color-primary, oklch(45% 0.24 277));
|
|
345
|
+
box-shadow:
|
|
346
|
+
0 0 0 3px color-mix(in oklch, var(--color-primary, oklch(45% 0.24 277)) 28%, transparent),
|
|
347
|
+
inset 0 -2px 0 var(--color-base-300, oklch(95% 0 0));
|
|
348
|
+
background: color-mix(in oklch, var(--color-primary, oklch(45% 0.24 277)) 8%, transparent);
|
|
349
|
+
}
|
|
350
|
+
:global(.qti-gm-gap-target[aria-disabled='true']) {
|
|
351
|
+
opacity: 0.6;
|
|
352
|
+
cursor: not-allowed;
|
|
353
|
+
}
|
|
354
|
+
:global(.qti-gm-gap-target.qti-gm-gap-correct) {
|
|
355
|
+
border-color: var(--color-success, oklch(76% 0.177 163.223));
|
|
356
|
+
background: color-mix(in oklch, var(--color-success, oklch(76% 0.177 163.223)) 8%, transparent);
|
|
357
|
+
}
|
|
358
|
+
:global(.qti-gm-gap-target:focus-visible) {
|
|
359
|
+
outline: 2px solid hsl(var(--p, 240 100% 50%) / 0.5);
|
|
360
|
+
outline-offset: 2px;
|
|
361
|
+
}
|
|
362
|
+
:global(.qti-gm-gap-target:hover) {
|
|
363
|
+
border-color: color-mix(
|
|
364
|
+
in oklch,
|
|
365
|
+
var(--color-primary, oklch(45% 0.24 277)) 22%,
|
|
366
|
+
var(--color-base-300, oklch(95% 0 0))
|
|
367
|
+
);
|
|
368
|
+
}
|
|
369
|
+
.qti-gm-palette [part='word'][aria-disabled='true'] {
|
|
370
|
+
opacity: 0.55;
|
|
371
|
+
cursor: not-allowed;
|
|
372
|
+
}
|
|
373
|
+
.qti-gm-palette [part='word'][draggable='true'] {
|
|
374
|
+
cursor: grab;
|
|
375
|
+
}
|
|
376
|
+
.qti-gm-palette [part='word'][draggable='true']:active {
|
|
377
|
+
cursor: grabbing;
|
|
378
|
+
}
|
|
379
|
+
</style>
|