@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,159 @@
|
|
|
1
|
+
<svelte:options customElement="pie-qti-order" />
|
|
2
|
+
|
|
3
|
+
<script lang="ts">
|
|
4
|
+
import type { OrderInteractionData } from '@pie-qti/item-player';
|
|
5
|
+
import type { I18nProvider } from '@pie-qti/i18n';
|
|
6
|
+
import { typesetAction } from '../../shared/actions/typesetAction';
|
|
7
|
+
import ShadowBaseStyles from '../../shared/components/ShadowBaseStyles.svelte';
|
|
8
|
+
import SortableList from '../../shared/components/SortableList.svelte';
|
|
9
|
+
import { createQtiChangeEvent } from '../../shared/utils/eventHelpers';
|
|
10
|
+
import { parseJsonProp } from '../../shared/utils/webComponentHelpers';
|
|
11
|
+
|
|
12
|
+
interface Props {
|
|
13
|
+
interaction?: OrderInteractionData | string;
|
|
14
|
+
response?: string[] | null;
|
|
15
|
+
correctResponse?: string[] | null;
|
|
16
|
+
disabled?: boolean;
|
|
17
|
+
role?: string;
|
|
18
|
+
i18n?: I18nProvider;
|
|
19
|
+
typeset?: (element: HTMLElement) => void;
|
|
20
|
+
onChange?: (value: string[]) => void;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
let { interaction = $bindable(), response = $bindable(), correctResponse = $bindable(), disabled = false, role = 'candidate', i18n = $bindable(), typeset, onChange }: Props = $props();
|
|
24
|
+
|
|
25
|
+
// Parse props that may be JSON strings (web component usage)
|
|
26
|
+
const parsedInteraction = $derived(parseJsonProp<OrderInteractionData>(interaction));
|
|
27
|
+
const parsedResponse = $derived(parseJsonProp<string[]>(response));
|
|
28
|
+
const parsedCorrectResponse = $derived(parseJsonProp<string[]>(correctResponse));
|
|
29
|
+
const isShowingCorrect = $derived(role === 'scorer' && parsedCorrectResponse !== null);
|
|
30
|
+
|
|
31
|
+
// Get reference to the root element for event dispatching
|
|
32
|
+
let rootElement: HTMLDivElement | undefined = $state();
|
|
33
|
+
|
|
34
|
+
// Track whether user has confirmed their order
|
|
35
|
+
let hasConfirmed = $state(false);
|
|
36
|
+
|
|
37
|
+
// Get ordered IDs from response, or use original order
|
|
38
|
+
const orderedIds = $derived(
|
|
39
|
+
parsedResponse && parsedResponse.length > 0
|
|
40
|
+
? parsedResponse
|
|
41
|
+
: parsedInteraction?.choices.map((c) => c.identifier) ?? []
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
// Track initial order to detect if user has made changes
|
|
45
|
+
const initialOrder = $derived(parsedInteraction?.choices.map((c) => c.identifier) ?? []);
|
|
46
|
+
const hasReordered = $derived(
|
|
47
|
+
orderedIds.length > 0 &&
|
|
48
|
+
orderedIds.some((id, index) => id !== initialOrder[index])
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
// Show confirmation button when response is null or when not confirmed yet
|
|
52
|
+
const needsConfirmation = $derived(
|
|
53
|
+
!disabled &&
|
|
54
|
+
(!response || !hasConfirmed) &&
|
|
55
|
+
orderedIds.length > 0
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
function handleReorder(newOrder: string[]) {
|
|
59
|
+
hasConfirmed = true; // Auto-confirm on drag
|
|
60
|
+
response = newOrder;
|
|
61
|
+
// Call onChange callback if provided (for Svelte component usage)
|
|
62
|
+
onChange?.(newOrder);
|
|
63
|
+
// Dispatch event for web component usage - event will bubble up to the host element
|
|
64
|
+
if (rootElement) {
|
|
65
|
+
rootElement.dispatchEvent(createQtiChangeEvent(parsedInteraction?.responseId, newOrder));
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function confirmOrder() {
|
|
70
|
+
if (disabled || hasConfirmed) return;
|
|
71
|
+
|
|
72
|
+
hasConfirmed = true;
|
|
73
|
+
const currentOrder = orderedIds;
|
|
74
|
+
response = currentOrder;
|
|
75
|
+
|
|
76
|
+
// Call onChange callback if provided (for Svelte component usage)
|
|
77
|
+
onChange?.(currentOrder);
|
|
78
|
+
// Dispatch event for web component usage - event will bubble up to the host element
|
|
79
|
+
if (rootElement) {
|
|
80
|
+
rootElement.dispatchEvent(createQtiChangeEvent(parsedInteraction?.responseId, currentOrder));
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Reset confirmation state when response is externally cleared
|
|
85
|
+
$effect(() => {
|
|
86
|
+
if (response === null || (Array.isArray(response) && response.length === 0)) {
|
|
87
|
+
hasConfirmed = false;
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
</script>
|
|
91
|
+
|
|
92
|
+
<ShadowBaseStyles />
|
|
93
|
+
|
|
94
|
+
<div bind:this={rootElement} class="qti-order-interaction" use:typesetAction={{ typeset }}>
|
|
95
|
+
{#if !parsedInteraction}
|
|
96
|
+
<div class="alert alert-error">{i18n?.t('common.errorNoData', 'No interaction data provided')}</div>
|
|
97
|
+
{:else}
|
|
98
|
+
{#if parsedInteraction.prompt}
|
|
99
|
+
<div class="mb-3 text-sm text-base-content/70">
|
|
100
|
+
{@html parsedInteraction.prompt}
|
|
101
|
+
</div>
|
|
102
|
+
{/if}
|
|
103
|
+
|
|
104
|
+
<SortableList
|
|
105
|
+
items={parsedInteraction.choices.map(c => ({ id: c.identifier, text: c.text }))}
|
|
106
|
+
{orderedIds}
|
|
107
|
+
correctOrder={isShowingCorrect ? (parsedCorrectResponse || []) : []}
|
|
108
|
+
orientation="vertical"
|
|
109
|
+
{disabled}
|
|
110
|
+
onReorder={handleReorder}
|
|
111
|
+
/>
|
|
112
|
+
|
|
113
|
+
<!-- Confirmation button for WCAG 2.2 SC 3.3.4 compliance -->
|
|
114
|
+
<div class="mt-4 flex items-center gap-3">
|
|
115
|
+
{#if needsConfirmation}
|
|
116
|
+
<button
|
|
117
|
+
type="button"
|
|
118
|
+
class="btn btn-primary btn-sm"
|
|
119
|
+
onclick={confirmOrder}
|
|
120
|
+
aria-label={i18n?.t('interactions.order.confirmAria') ?? 'Confirm this order as your answer'}
|
|
121
|
+
>
|
|
122
|
+
{hasReordered
|
|
123
|
+
? (i18n?.t('interactions.order.confirmOrder') ?? 'Confirm Order')
|
|
124
|
+
: (i18n?.t('interactions.order.confirmOrderNoChanges') ?? 'Confirm Order (No Changes)')}
|
|
125
|
+
</button>
|
|
126
|
+
<span class="text-xs text-base-content/60">
|
|
127
|
+
{i18n?.t('interactions.order.instruction') ?? 'Drag items to reorder, or click to confirm the current order'}
|
|
128
|
+
</span>
|
|
129
|
+
{:else if hasConfirmed}
|
|
130
|
+
<div class="badge badge-success gap-2">
|
|
131
|
+
<svg
|
|
132
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
133
|
+
fill="none"
|
|
134
|
+
viewBox="0 0 24 24"
|
|
135
|
+
part="confirmed-icon"
|
|
136
|
+
class="qti-icon-sm inline-block w-4 h-4 stroke-current"
|
|
137
|
+
>
|
|
138
|
+
<path
|
|
139
|
+
stroke-linecap="round"
|
|
140
|
+
stroke-linejoin="round"
|
|
141
|
+
stroke-width="2"
|
|
142
|
+
d="M5 13l4 4L19 7"
|
|
143
|
+
></path>
|
|
144
|
+
</svg>
|
|
145
|
+
Order confirmed
|
|
146
|
+
</div>
|
|
147
|
+
{/if}
|
|
148
|
+
</div>
|
|
149
|
+
{/if}
|
|
150
|
+
</div>
|
|
151
|
+
|
|
152
|
+
<style>
|
|
153
|
+
/* Minimal icon sizing so SVGs don't fall back to browser default size without Tailwind */
|
|
154
|
+
.qti-icon-sm {
|
|
155
|
+
width: 1rem;
|
|
156
|
+
height: 1rem;
|
|
157
|
+
flex: 0 0 auto;
|
|
158
|
+
}
|
|
159
|
+
</style>
|