@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.
Files changed (146) hide show
  1. package/.turbo/turbo-build.log +1 -0
  2. package/CHANGELOG.md +9 -0
  3. package/STYLING.md +226 -0
  4. package/dist/index.d.ts +35 -0
  5. package/dist/index.d.ts.map +1 -0
  6. package/dist/index.js +190 -0
  7. package/dist/plugins/associate/index.d.ts +8 -0
  8. package/dist/plugins/associate/index.d.ts.map +1 -0
  9. package/dist/plugins/associate/index.js +8 -0
  10. package/dist/plugins/choice/index.d.ts +8 -0
  11. package/dist/plugins/choice/index.d.ts.map +1 -0
  12. package/dist/plugins/choice/index.js +8 -0
  13. package/dist/plugins/custom/index.d.ts +8 -0
  14. package/dist/plugins/custom/index.d.ts.map +1 -0
  15. package/dist/plugins/custom/index.js +8 -0
  16. package/dist/plugins/end-attempt/index.d.ts +8 -0
  17. package/dist/plugins/end-attempt/index.d.ts.map +1 -0
  18. package/dist/plugins/end-attempt/index.js +8 -0
  19. package/dist/plugins/extended-text/index.d.ts +8 -0
  20. package/dist/plugins/extended-text/index.d.ts.map +1 -0
  21. package/dist/plugins/extended-text/index.js +8 -0
  22. package/dist/plugins/gap-match/index.d.ts +8 -0
  23. package/dist/plugins/gap-match/index.d.ts.map +1 -0
  24. package/dist/plugins/gap-match/index.js +8 -0
  25. package/dist/plugins/graphic-associate/index.d.ts +8 -0
  26. package/dist/plugins/graphic-associate/index.d.ts.map +1 -0
  27. package/dist/plugins/graphic-associate/index.js +8 -0
  28. package/dist/plugins/graphic-gap-match/index.d.ts +8 -0
  29. package/dist/plugins/graphic-gap-match/index.d.ts.map +1 -0
  30. package/dist/plugins/graphic-gap-match/index.js +8 -0
  31. package/dist/plugins/graphic-order/index.d.ts +8 -0
  32. package/dist/plugins/graphic-order/index.d.ts.map +1 -0
  33. package/dist/plugins/graphic-order/index.js +8 -0
  34. package/dist/plugins/hotspot/index.d.ts +8 -0
  35. package/dist/plugins/hotspot/index.d.ts.map +1 -0
  36. package/dist/plugins/hotspot/index.js +8 -0
  37. package/dist/plugins/hottext/index.d.ts +8 -0
  38. package/dist/plugins/hottext/index.d.ts.map +1 -0
  39. package/dist/plugins/hottext/index.js +8 -0
  40. package/dist/plugins/index.d.ts +30 -0
  41. package/dist/plugins/index.d.ts.map +1 -0
  42. package/dist/plugins/index.js +30 -0
  43. package/dist/plugins/match/index.d.ts +8 -0
  44. package/dist/plugins/match/index.d.ts.map +1 -0
  45. package/dist/plugins/match/index.js +8 -0
  46. package/dist/plugins/media/index.d.ts +8 -0
  47. package/dist/plugins/media/index.d.ts.map +1 -0
  48. package/dist/plugins/media/index.js +8 -0
  49. package/dist/plugins/order/index.d.ts +8 -0
  50. package/dist/plugins/order/index.d.ts.map +1 -0
  51. package/dist/plugins/order/index.js +8 -0
  52. package/dist/plugins/position-object/index.d.ts +8 -0
  53. package/dist/plugins/position-object/index.d.ts.map +1 -0
  54. package/dist/plugins/position-object/index.js +8 -0
  55. package/dist/plugins/select-point/index.d.ts +8 -0
  56. package/dist/plugins/select-point/index.d.ts.map +1 -0
  57. package/dist/plugins/select-point/index.js +8 -0
  58. package/dist/plugins/slider/index.d.ts +8 -0
  59. package/dist/plugins/slider/index.d.ts.map +1 -0
  60. package/dist/plugins/slider/index.js +8 -0
  61. package/dist/shared/actions/typesetAction.d.ts +26 -0
  62. package/dist/shared/actions/typesetAction.d.ts.map +1 -0
  63. package/dist/shared/actions/typesetAction.js +70 -0
  64. package/dist/shared/extensions/MathLiveEditor.d.ts +19 -0
  65. package/dist/shared/extensions/MathLiveEditor.d.ts.map +1 -0
  66. package/dist/shared/extensions/MathLiveEditor.js +239 -0
  67. package/dist/shared/index.d.ts +11 -0
  68. package/dist/shared/index.d.ts.map +1 -0
  69. package/dist/shared/index.js +15 -0
  70. package/dist/shared/utils/eventHelpers.d.ts +18 -0
  71. package/dist/shared/utils/eventHelpers.d.ts.map +1 -0
  72. package/dist/shared/utils/eventHelpers.js +30 -0
  73. package/dist/shared/utils/pairHelpers.d.ts +55 -0
  74. package/dist/shared/utils/pairHelpers.d.ts.map +1 -0
  75. package/dist/shared/utils/pairHelpers.js +76 -0
  76. package/dist/shared/utils/touchDragHelper.d.ts +33 -0
  77. package/dist/shared/utils/touchDragHelper.d.ts.map +1 -0
  78. package/dist/shared/utils/touchDragHelper.js +168 -0
  79. package/dist/shared/utils/webComponentHelpers.d.ts +9 -0
  80. package/dist/shared/utils/webComponentHelpers.d.ts.map +1 -0
  81. package/dist/shared/utils/webComponentHelpers.js +26 -0
  82. package/package.json +93 -0
  83. package/src/index.ts +213 -0
  84. package/src/plugins/associate/AssociateInteraction.svelte +273 -0
  85. package/src/plugins/associate/index.ts +9 -0
  86. package/src/plugins/choice/ChoiceInteraction.svelte +212 -0
  87. package/src/plugins/choice/index.ts +9 -0
  88. package/src/plugins/custom/CustomInteraction.svelte +61 -0
  89. package/src/plugins/custom/index.ts +9 -0
  90. package/src/plugins/drawing/DrawingInteraction.svelte +90 -0
  91. package/src/plugins/end-attempt/EndAttemptInteraction.svelte +142 -0
  92. package/src/plugins/end-attempt/index.ts +9 -0
  93. package/src/plugins/extended-text/ExtendedTextInteraction.svelte +77 -0
  94. package/src/plugins/extended-text/index.ts +9 -0
  95. package/src/plugins/gap-match/GapMatchInteraction.svelte +379 -0
  96. package/src/plugins/gap-match/index.ts +9 -0
  97. package/src/plugins/graphic-associate/GraphicAssociateInteraction.svelte +427 -0
  98. package/src/plugins/graphic-associate/index.ts +9 -0
  99. package/src/plugins/graphic-gap-match/GraphicGapMatchInteraction.svelte +508 -0
  100. package/src/plugins/graphic-gap-match/index.ts +9 -0
  101. package/src/plugins/graphic-order/GraphicOrderInteraction.svelte +241 -0
  102. package/src/plugins/graphic-order/index.ts +9 -0
  103. package/src/plugins/hotspot/HotspotInteraction.svelte +244 -0
  104. package/src/plugins/hotspot/index.ts +9 -0
  105. package/src/plugins/hottext/HottextInteraction.svelte +296 -0
  106. package/src/plugins/hottext/index.ts +9 -0
  107. package/src/plugins/index.ts +31 -0
  108. package/src/plugins/match/MatchInteraction.svelte +70 -0
  109. package/src/plugins/match/index.ts +9 -0
  110. package/src/plugins/media/MediaInteraction.svelte +213 -0
  111. package/src/plugins/media/index.ts +9 -0
  112. package/src/plugins/order/OrderInteraction.svelte +159 -0
  113. package/src/plugins/order/index.ts +9 -0
  114. package/src/plugins/position-object/PositionObjectInteraction.svelte +671 -0
  115. package/src/plugins/position-object/README.md +130 -0
  116. package/src/plugins/position-object/index.ts +9 -0
  117. package/src/plugins/select-point/SelectPointInteraction.svelte +453 -0
  118. package/src/plugins/select-point/index.ts +9 -0
  119. package/src/plugins/slider/SliderInteraction.svelte +141 -0
  120. package/src/plugins/slider/index.ts +9 -0
  121. package/src/plugins/upload/UploadInteraction.svelte +59 -0
  122. package/src/shared/actions/typesetAction.ts +87 -0
  123. package/src/shared/components/CustomInteractionFallback.svelte +153 -0
  124. package/src/shared/components/DragHandle.svelte +44 -0
  125. package/src/shared/components/DrawingCanvas.svelte +243 -0
  126. package/src/shared/components/FileUpload.svelte +153 -0
  127. package/src/shared/components/GraphicGapMatch.svelte +316 -0
  128. package/src/shared/components/GraphicGapMatchAdapter.svelte +36 -0
  129. package/src/shared/components/InlineInteractionRenderer.svelte +124 -0
  130. package/src/shared/components/MatchDragDrop.svelte +434 -0
  131. package/src/shared/components/MathContent.svelte +18 -0
  132. package/src/shared/components/ModalFeedbackDisplay.svelte +81 -0
  133. package/src/shared/components/RichTextEditor.svelte +316 -0
  134. package/src/shared/components/ShadowBaseStyles.svelte +391 -0
  135. package/src/shared/components/SortableList.svelte +297 -0
  136. package/src/shared/extensions/MathLiveEditor.ts +304 -0
  137. package/src/shared/index.ts +17 -0
  138. package/src/shared/styles/shared.css +16 -0
  139. package/src/shared/utils/eventHelpers.ts +36 -0
  140. package/src/shared/utils/pairHelpers.ts +86 -0
  141. package/src/shared/utils/touchDragHelper.ts +211 -0
  142. package/src/shared/utils/webComponentHelpers.ts +27 -0
  143. package/src/svelte-shims.d.ts +9 -0
  144. package/svelte.config.js +9 -0
  145. package/tests/index.test.ts +8 -0
  146. 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>
@@ -0,0 +1,9 @@
1
+ // Svelte component exported via web component
2
+
3
+ export const metadata = {
4
+ interactionType: 'orderInteraction',
5
+ tagName: 'pie-qti-order',
6
+ name: 'default-order',
7
+ description: 'Default Svelte-based order interaction',
8
+ priority: 0,
9
+ };