@pie-qti/assessment-player 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/BACKEND-INTEGRATION.md +620 -0
- package/CHANGELOG.md +11 -0
- package/EXTENSIBILITY.md +551 -0
- package/README.md +1137 -0
- package/dist/core/AssessmentPlayer.d.ts +151 -0
- package/dist/core/AssessmentPlayer.d.ts.map +1 -0
- package/dist/core/AssessmentPlayer.js +595 -0
- package/dist/core/ItemSessionController.d.ts +119 -0
- package/dist/core/ItemSessionController.d.ts.map +1 -0
- package/dist/core/ItemSessionController.js +227 -0
- package/dist/core/NavigationManager.d.ts +59 -0
- package/dist/core/NavigationManager.d.ts.map +1 -0
- package/dist/core/NavigationManager.js +104 -0
- package/dist/core/StatePersistenceManager.d.ts +126 -0
- package/dist/core/StatePersistenceManager.d.ts.map +1 -0
- package/dist/core/StatePersistenceManager.js +267 -0
- package/dist/core/TimeManager.d.ts +123 -0
- package/dist/core/TimeManager.d.ts.map +1 -0
- package/dist/core/TimeManager.js +217 -0
- package/dist/core/index.d.ts +10 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +5 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -0
- package/dist/integration/ReferenceBackendAdapter.d.ts +128 -0
- package/dist/integration/ReferenceBackendAdapter.d.ts.map +1 -0
- package/dist/integration/ReferenceBackendAdapter.js +735 -0
- package/dist/integration/api-contract.d.ts +319 -0
- package/dist/integration/api-contract.d.ts.map +1 -0
- package/dist/integration/api-contract.js +19 -0
- package/dist/integration/index.d.ts +47 -0
- package/dist/integration/index.d.ts.map +1 -0
- package/dist/integration/index.js +46 -0
- package/dist/types/index.d.ts +51 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +7 -0
- package/dist/utils/PerformanceMonitor.d.ts +115 -0
- package/dist/utils/PerformanceMonitor.d.ts.map +1 -0
- package/dist/utils/PerformanceMonitor.js +171 -0
- package/package.json +82 -0
- package/src/ambient.d.ts +55 -0
- package/src/components/AccessibilityAnnouncer.svelte +102 -0
- package/src/components/AssessmentHeader.svelte +76 -0
- package/src/components/AssessmentShell.svelte +485 -0
- package/src/components/AssessmentTimer.svelte +228 -0
- package/src/components/ItemRenderer.svelte +147 -0
- package/src/components/ItemSessionInfo.svelte +241 -0
- package/src/components/NavigationBar.svelte +142 -0
- package/src/components/RubricDisplay.svelte +185 -0
- package/src/components/SectionMenu.svelte +206 -0
- package/src/components/SplitPaneResizer.svelte +288 -0
- package/src/components/TestFeedback.svelte +147 -0
- package/src/components/index.ts +19 -0
- package/src/core/AssessmentPlayer.ts +720 -0
- package/src/core/ItemSessionController.ts +287 -0
- package/src/core/NavigationManager.ts +126 -0
- package/src/core/StatePersistenceManager.ts +344 -0
- package/src/core/TimeManager.ts +289 -0
- package/src/core/index.ts +15 -0
- package/src/index.ts +13 -0
- package/src/integration/ReferenceBackendAdapter.ts +861 -0
- package/src/integration/api-contract.ts +377 -0
- package/src/integration/index.ts +70 -0
- package/src/svelte-shims.d.ts +7 -0
- package/src/types/index.ts +56 -0
- package/src/utils/PerformanceMonitor.ts +222 -0
- package/svelte.config.js +8 -0
- package/tests/ReferenceBackendAdapter.spec.ts +309 -0
- package/tests/setup.ts +103 -0
- package/tests/smoke.test.ts +7 -0
- package/tsconfig.json +20 -0
- package/tsconfig.svelte.json +10 -0
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
|
|
3
|
+
import { registerDefaultComponents } from '@pie-qti/default-components';
|
|
4
|
+
// @ts-expect-error - Svelte-check can't resolve workspace subpath exports, but runtime works correctly
|
|
5
|
+
import { ItemBody } from '@pie-qti/item-player/components';
|
|
6
|
+
import { Player, type PlayerSecurityConfig, type QTIRole } from '@pie-qti/item-player';
|
|
7
|
+
import type { I18nProvider } from '@pie-qti/i18n';
|
|
8
|
+
import { onMount } from 'svelte';
|
|
9
|
+
import type { QuestionRef } from '../types/index.js';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Ensure default interaction web components are registered (browser-only).
|
|
13
|
+
*
|
|
14
|
+
* NOTE: `@pie-qti/default-components/plugins` has side effects (customElements.define),
|
|
15
|
+
* so we only load it on the client to remain SSR-safe.
|
|
16
|
+
*/
|
|
17
|
+
let pluginsLoadPromise: Promise<void> | null = null;
|
|
18
|
+
function ensureDefaultPluginsLoaded() {
|
|
19
|
+
if (pluginsLoadPromise) return pluginsLoadPromise;
|
|
20
|
+
pluginsLoadPromise = import('@pie-qti/default-components/plugins')
|
|
21
|
+
.then(() => {})
|
|
22
|
+
.catch((err) => {
|
|
23
|
+
console.warn('Failed to load default QTI web components:', err);
|
|
24
|
+
});
|
|
25
|
+
return pluginsLoadPromise;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
onMount(() => {
|
|
29
|
+
void ensureDefaultPluginsLoaded();
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
interface Props {
|
|
33
|
+
questionRef: QuestionRef;
|
|
34
|
+
role?: QTIRole;
|
|
35
|
+
extendedTextEditor?: string;
|
|
36
|
+
/** Responses for the current item (keyed by responseIdentifier). */
|
|
37
|
+
responses?: Record<string, any>;
|
|
38
|
+
onResponseChange?: (responseId: string, value: unknown) => void;
|
|
39
|
+
/** Math typesetting function (KaTeX, MathJax, etc.) */
|
|
40
|
+
typeset?: (root: HTMLElement) => void | Promise<void>;
|
|
41
|
+
/** I18n provider for translations */
|
|
42
|
+
i18n?: I18nProvider;
|
|
43
|
+
/** Security configuration for URL policy and content restrictions */
|
|
44
|
+
security?: PlayerSecurityConfig;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const {
|
|
48
|
+
questionRef,
|
|
49
|
+
role = 'candidate',
|
|
50
|
+
extendedTextEditor: _extendedTextEditor,
|
|
51
|
+
responses = {},
|
|
52
|
+
onResponseChange,
|
|
53
|
+
typeset,
|
|
54
|
+
i18n,
|
|
55
|
+
security,
|
|
56
|
+
}: Props = $props();
|
|
57
|
+
|
|
58
|
+
// Derive player from questionRef
|
|
59
|
+
let playerData = $derived.by(() => {
|
|
60
|
+
if (!questionRef.itemXml) {
|
|
61
|
+
return { player: null, error: 'No item XML provided' };
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
try {
|
|
65
|
+
const newPlayer = new Player({
|
|
66
|
+
itemXml: questionRef.itemXml,
|
|
67
|
+
role,
|
|
68
|
+
security,
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
// Ensure the item player can actually render interactions by registering the
|
|
72
|
+
// default component set into this player's component registry.
|
|
73
|
+
registerDefaultComponents(newPlayer.getComponentRegistry());
|
|
74
|
+
|
|
75
|
+
return {
|
|
76
|
+
player: newPlayer,
|
|
77
|
+
error: null,
|
|
78
|
+
};
|
|
79
|
+
} catch (err) {
|
|
80
|
+
console.error('Failed to initialize item player:', err);
|
|
81
|
+
return {
|
|
82
|
+
player: null,
|
|
83
|
+
error: err instanceof Error ? err.message : (i18n?.t('item.loadingError') ?? 'Failed to load item'),
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
// Handle response changes
|
|
89
|
+
function handleResponseChange(responseId: string, value: any) {
|
|
90
|
+
onResponseChange?.(responseId, value);
|
|
91
|
+
}
|
|
92
|
+
</script>
|
|
93
|
+
|
|
94
|
+
{#if playerData.error}
|
|
95
|
+
<div class="alert alert-error">
|
|
96
|
+
<svg
|
|
97
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
98
|
+
class="stroke-current shrink-0 h-6 w-6"
|
|
99
|
+
fill="none"
|
|
100
|
+
viewBox="0 0 24 24"
|
|
101
|
+
>
|
|
102
|
+
<path
|
|
103
|
+
stroke-linecap="round"
|
|
104
|
+
stroke-linejoin="round"
|
|
105
|
+
stroke-width="2"
|
|
106
|
+
d="M10 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2m7-2a9 9 0 11-18 0 9 9 0 0118 0z"
|
|
107
|
+
/>
|
|
108
|
+
</svg>
|
|
109
|
+
<span>{i18n?.t('item.loadError', 'Error loading item: {error}', { error: playerData.error })}</span>
|
|
110
|
+
</div>
|
|
111
|
+
{:else if !playerData.player}
|
|
112
|
+
<div class="flex items-center justify-center p-8">
|
|
113
|
+
<span class="loading loading-spinner loading-lg"></span>
|
|
114
|
+
<span class="ml-4">{i18n?.t('item.loading', 'Loading item...')}</span>
|
|
115
|
+
</div>
|
|
116
|
+
{:else}
|
|
117
|
+
<div class="item-container">
|
|
118
|
+
{#if questionRef.title}
|
|
119
|
+
<div class="item-header">
|
|
120
|
+
<h3 class="text-lg font-semibold mb-4">{questionRef.title}</h3>
|
|
121
|
+
</div>
|
|
122
|
+
{/if}
|
|
123
|
+
|
|
124
|
+
<div class="item-content">
|
|
125
|
+
<ItemBody
|
|
126
|
+
player={playerData.player}
|
|
127
|
+
{responses}
|
|
128
|
+
disabled={role !== 'candidate'}
|
|
129
|
+
{role}
|
|
130
|
+
{typeset}
|
|
131
|
+
{i18n}
|
|
132
|
+
onResponseChange={handleResponseChange}
|
|
133
|
+
/>
|
|
134
|
+
</div>
|
|
135
|
+
</div>
|
|
136
|
+
{/if}
|
|
137
|
+
|
|
138
|
+
<style>
|
|
139
|
+
.item-container {
|
|
140
|
+
width: 100%;
|
|
141
|
+
padding: 1rem;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
.item-content {
|
|
145
|
+
width: 100%;
|
|
146
|
+
}
|
|
147
|
+
</style>
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { onDestroy, onMount } from 'svelte';
|
|
3
|
+
import type { SvelteI18nProvider } from '@pie-qti/i18n';
|
|
4
|
+
import type { AssessmentPlayer } from '../core/AssessmentPlayer.js';
|
|
5
|
+
|
|
6
|
+
interface Props {
|
|
7
|
+
player: AssessmentPlayer;
|
|
8
|
+
i18n: SvelteI18nProvider;
|
|
9
|
+
/** Where to position the info display */
|
|
10
|
+
position?: 'inline' | 'floating';
|
|
11
|
+
/** Show detailed information */
|
|
12
|
+
showDetails?: boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
let { player, i18n, position = 'inline', showDetails = false }: Props = $props();
|
|
16
|
+
|
|
17
|
+
let sessionInfo = $state<{
|
|
18
|
+
canSubmit: boolean;
|
|
19
|
+
remainingAttempts: number | null;
|
|
20
|
+
attemptCount: number;
|
|
21
|
+
showFeedback: boolean;
|
|
22
|
+
showSolution: boolean;
|
|
23
|
+
canReview: boolean;
|
|
24
|
+
canSkip: boolean;
|
|
25
|
+
} | null>(null);
|
|
26
|
+
|
|
27
|
+
let unsubscribeItemChange: (() => void) | null = null;
|
|
28
|
+
let unsubscribeResponseChange: (() => void) | null = null;
|
|
29
|
+
|
|
30
|
+
function updateSessionInfo() {
|
|
31
|
+
sessionInfo = player.getItemSessionInfo();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
onMount(() => {
|
|
35
|
+
updateSessionInfo();
|
|
36
|
+
|
|
37
|
+
// Update when item changes
|
|
38
|
+
unsubscribeItemChange = player.onItemChange(() => {
|
|
39
|
+
updateSessionInfo();
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
// Update when responses change (affects attempt state)
|
|
43
|
+
unsubscribeResponseChange = player.onResponseChange(() => {
|
|
44
|
+
updateSessionInfo();
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
onDestroy(() => {
|
|
49
|
+
unsubscribeItemChange?.();
|
|
50
|
+
unsubscribeResponseChange?.();
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
let hasAttemptLimit = $derived(
|
|
54
|
+
sessionInfo?.remainingAttempts !== null && sessionInfo?.remainingAttempts !== undefined
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
let attemptsMessage = $derived(() => {
|
|
58
|
+
if (!sessionInfo || !hasAttemptLimit) {
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (sessionInfo.remainingAttempts === 0) {
|
|
63
|
+
return i18n.t('assessment.attempts.noRemaining', { count: sessionInfo.attemptCount });
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (sessionInfo.remainingAttempts === 1) {
|
|
67
|
+
return i18n.t('assessment.attempts.oneRemaining');
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return i18n.t('assessment.attempts.remaining', { count: sessionInfo.remainingAttempts });
|
|
71
|
+
});
|
|
72
|
+
</script>
|
|
73
|
+
|
|
74
|
+
{#if sessionInfo}
|
|
75
|
+
<div
|
|
76
|
+
class="item-session-info"
|
|
77
|
+
class:inline={position === 'inline'}
|
|
78
|
+
class:floating={position === 'floating'}
|
|
79
|
+
class:no-attempts={hasAttemptLimit && sessionInfo.remainingAttempts === 0}
|
|
80
|
+
class:low-attempts={hasAttemptLimit && sessionInfo.remainingAttempts === 1}
|
|
81
|
+
>
|
|
82
|
+
<!-- Attempt count indicator -->
|
|
83
|
+
{#if hasAttemptLimit}
|
|
84
|
+
<div class="session-badge" role="status" aria-live="polite">
|
|
85
|
+
<span class="badge-icon" aria-hidden="true">
|
|
86
|
+
{#if sessionInfo.remainingAttempts === 0}
|
|
87
|
+
🚫
|
|
88
|
+
{:else if sessionInfo.remainingAttempts === 1}
|
|
89
|
+
⚠️
|
|
90
|
+
{:else}
|
|
91
|
+
📝
|
|
92
|
+
{/if}
|
|
93
|
+
</span>
|
|
94
|
+
<span class="badge-text">{attemptsMessage()}</span>
|
|
95
|
+
</div>
|
|
96
|
+
{/if}
|
|
97
|
+
|
|
98
|
+
<!-- Detailed information -->
|
|
99
|
+
{#if showDetails}
|
|
100
|
+
<div class="session-details">
|
|
101
|
+
{#if sessionInfo.attemptCount > 0}
|
|
102
|
+
<div class="detail-item">
|
|
103
|
+
<span class="detail-label">{i18n.t('assessment.attempts.used', { count: sessionInfo.attemptCount })}</span>
|
|
104
|
+
</div>
|
|
105
|
+
{/if}
|
|
106
|
+
|
|
107
|
+
{#if !sessionInfo.canSubmit}
|
|
108
|
+
<div class="detail-item warning">
|
|
109
|
+
<span class="detail-label">{i18n.t('common.status')}:</span>
|
|
110
|
+
<span class="detail-value">{i18n.t('assessment.attempts.maxReached')}</span>
|
|
111
|
+
</div>
|
|
112
|
+
{/if}
|
|
113
|
+
|
|
114
|
+
{#if !sessionInfo.canSkip}
|
|
115
|
+
<div class="detail-item info">
|
|
116
|
+
<span class="detail-label">{i18n.t('common.required')}:</span>
|
|
117
|
+
<span class="detail-value">{i18n.t('assessment.attempts.required')}</span>
|
|
118
|
+
</div>
|
|
119
|
+
{/if}
|
|
120
|
+
|
|
121
|
+
{#if !sessionInfo.canReview}
|
|
122
|
+
<div class="detail-item info">
|
|
123
|
+
<span class="detail-label">{i18n.t('common.review')}:</span>
|
|
124
|
+
<span class="detail-value">{i18n.t('assessment.attempts.reviewNotAllowed')}</span>
|
|
125
|
+
</div>
|
|
126
|
+
{/if}
|
|
127
|
+
</div>
|
|
128
|
+
{/if}
|
|
129
|
+
</div>
|
|
130
|
+
{/if}
|
|
131
|
+
|
|
132
|
+
<style>
|
|
133
|
+
.item-session-info {
|
|
134
|
+
display: flex;
|
|
135
|
+
flex-direction: column;
|
|
136
|
+
gap: 0.5rem;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
.item-session-info.inline {
|
|
140
|
+
padding: 0.75rem;
|
|
141
|
+
background: hsl(var(--b2));
|
|
142
|
+
border-radius: 0.5rem;
|
|
143
|
+
border: 1px solid hsl(var(--bc) / 0.1);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
.item-session-info.floating {
|
|
147
|
+
position: fixed;
|
|
148
|
+
bottom: 1rem;
|
|
149
|
+
right: 1rem;
|
|
150
|
+
padding: 0.75rem 1rem;
|
|
151
|
+
background: hsl(var(--b1));
|
|
152
|
+
border-radius: 0.5rem;
|
|
153
|
+
box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1);
|
|
154
|
+
z-index: 100;
|
|
155
|
+
border: 2px solid hsl(var(--bc) / 0.1);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
.session-badge {
|
|
159
|
+
display: flex;
|
|
160
|
+
align-items: center;
|
|
161
|
+
gap: 0.5rem;
|
|
162
|
+
padding: 0.5rem 0.75rem;
|
|
163
|
+
background: hsl(var(--b1));
|
|
164
|
+
border-radius: 0.375rem;
|
|
165
|
+
border: 1px solid hsl(var(--bc) / 0.1);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
.item-session-info.no-attempts .session-badge {
|
|
169
|
+
background: hsl(var(--er) / 0.1);
|
|
170
|
+
border-color: hsl(var(--er));
|
|
171
|
+
color: hsl(var(--er));
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
.item-session-info.low-attempts .session-badge {
|
|
175
|
+
background: hsl(var(--wa) / 0.1);
|
|
176
|
+
border-color: hsl(var(--wa));
|
|
177
|
+
color: hsl(var(--wa));
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
.badge-icon {
|
|
181
|
+
font-size: 1.25rem;
|
|
182
|
+
line-height: 1;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
.badge-text {
|
|
186
|
+
font-size: 0.875rem;
|
|
187
|
+
font-weight: 600;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
.session-details {
|
|
191
|
+
display: flex;
|
|
192
|
+
flex-direction: column;
|
|
193
|
+
gap: 0.375rem;
|
|
194
|
+
padding-top: 0.5rem;
|
|
195
|
+
border-top: 1px solid hsl(var(--bc) / 0.1);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
.detail-item {
|
|
199
|
+
display: flex;
|
|
200
|
+
justify-content: space-between;
|
|
201
|
+
align-items: center;
|
|
202
|
+
font-size: 0.8125rem;
|
|
203
|
+
padding: 0.25rem 0;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
.detail-label {
|
|
207
|
+
font-weight: 600;
|
|
208
|
+
color: hsl(var(--bc) / 0.7);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
.detail-value {
|
|
212
|
+
color: hsl(var(--bc));
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
.detail-item.warning .detail-value {
|
|
216
|
+
color: hsl(var(--er));
|
|
217
|
+
font-weight: 600;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
.detail-item.info .detail-value {
|
|
221
|
+
color: hsl(var(--in));
|
|
222
|
+
font-weight: 500;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
@media (max-width: 640px) {
|
|
226
|
+
.item-session-info.floating {
|
|
227
|
+
bottom: 0.5rem;
|
|
228
|
+
right: 0.5rem;
|
|
229
|
+
left: 0.5rem;
|
|
230
|
+
padding: 0.5rem 0.75rem;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
.badge-text {
|
|
234
|
+
font-size: 0.8125rem;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
.badge-icon {
|
|
238
|
+
font-size: 1.125rem;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
</style>
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { NavigationState } from '../types/index.js';
|
|
3
|
+
import type { SvelteI18nProvider } from '@pie-qti/i18n';
|
|
4
|
+
|
|
5
|
+
interface Props {
|
|
6
|
+
navState: NavigationState;
|
|
7
|
+
i18n?: SvelteI18nProvider;
|
|
8
|
+
onPrevious?: () => void;
|
|
9
|
+
onNext?: () => void;
|
|
10
|
+
onSubmit?: () => void;
|
|
11
|
+
showProgress?: boolean;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const { navState, i18n, onPrevious, onNext, onSubmit, showProgress = true }: Props = $props();
|
|
15
|
+
|
|
16
|
+
const progressPercentage = $derived(
|
|
17
|
+
navState.totalItems > 0 ? ((navState.currentIndex + 1) / navState.totalItems) * 100 : 0,
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
// Simplified translations - no manual subscriptions needed
|
|
21
|
+
// Locale changes trigger page refresh, so reactivity is not required
|
|
22
|
+
const translations = $derived({
|
|
23
|
+
question: i18n?.t('assessment.question', { current: navState.currentIndex + 1, total: navState.totalItems })
|
|
24
|
+
?? `Question ${navState.currentIndex + 1} of ${navState.totalItems}`,
|
|
25
|
+
section: navState.currentSection
|
|
26
|
+
? (navState.currentSection.title ?? (i18n?.t('assessment.section', { current: navState.currentSection.index + 1, total: 0 })
|
|
27
|
+
?? `Section ${navState.currentSection.index + 1}`))
|
|
28
|
+
: null,
|
|
29
|
+
previous: i18n?.t('common.previous') ?? 'Previous',
|
|
30
|
+
next: i18n?.t('common.next') ?? 'Next',
|
|
31
|
+
submit: i18n?.t('assessment.navigation.submit') ?? 'Submit',
|
|
32
|
+
});
|
|
33
|
+
</script>
|
|
34
|
+
|
|
35
|
+
<div class="navigation-bar">
|
|
36
|
+
<!-- Progress indicator -->
|
|
37
|
+
{#if showProgress}
|
|
38
|
+
<div class="progress-section">
|
|
39
|
+
<div class="progress-label text-sm">
|
|
40
|
+
{translations.question}
|
|
41
|
+
{#if translations.section}
|
|
42
|
+
<span class="text-base-content/60">
|
|
43
|
+
({translations.section})
|
|
44
|
+
</span>
|
|
45
|
+
{/if}
|
|
46
|
+
</div>
|
|
47
|
+
<progress
|
|
48
|
+
class="progress progress-primary w-full"
|
|
49
|
+
value={progressPercentage}
|
|
50
|
+
max="100"
|
|
51
|
+
></progress>
|
|
52
|
+
</div>
|
|
53
|
+
{/if}
|
|
54
|
+
|
|
55
|
+
<!-- Navigation buttons -->
|
|
56
|
+
<div class="navigation-buttons">
|
|
57
|
+
<button
|
|
58
|
+
class="btn btn-outline"
|
|
59
|
+
onclick={() => onPrevious?.()}
|
|
60
|
+
disabled={!navState.canPrevious || navState.isLoading}
|
|
61
|
+
>
|
|
62
|
+
<svg
|
|
63
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
64
|
+
class="h-5 w-5"
|
|
65
|
+
fill="none"
|
|
66
|
+
viewBox="0 0 24 24"
|
|
67
|
+
stroke="currentColor"
|
|
68
|
+
>
|
|
69
|
+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 19l-7-7 7-7" />
|
|
70
|
+
</svg>
|
|
71
|
+
{translations.previous}
|
|
72
|
+
</button>
|
|
73
|
+
|
|
74
|
+
<div class="flex-1"></div>
|
|
75
|
+
|
|
76
|
+
{#if navState.currentIndex === navState.totalItems - 1}
|
|
77
|
+
<!-- Submit button on last item -->
|
|
78
|
+
<button class="btn btn-primary" onclick={() => onSubmit?.()} disabled={navState.isLoading}>
|
|
79
|
+
{translations.submit}
|
|
80
|
+
</button>
|
|
81
|
+
{:else}
|
|
82
|
+
<!-- Next button -->
|
|
83
|
+
<button
|
|
84
|
+
class="btn btn-primary"
|
|
85
|
+
onclick={() => onNext?.()}
|
|
86
|
+
disabled={!navState.canNext || navState.isLoading}
|
|
87
|
+
>
|
|
88
|
+
{translations.next}
|
|
89
|
+
<svg
|
|
90
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
91
|
+
class="h-5 w-5"
|
|
92
|
+
fill="none"
|
|
93
|
+
viewBox="0 0 24 24"
|
|
94
|
+
stroke="currentColor"
|
|
95
|
+
>
|
|
96
|
+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5l7 7-7 7" />
|
|
97
|
+
</svg>
|
|
98
|
+
</button>
|
|
99
|
+
{/if}
|
|
100
|
+
</div>
|
|
101
|
+
</div>
|
|
102
|
+
|
|
103
|
+
<style>
|
|
104
|
+
.navigation-bar {
|
|
105
|
+
display: flex;
|
|
106
|
+
flex-direction: column;
|
|
107
|
+
gap: 1rem;
|
|
108
|
+
padding: 1rem;
|
|
109
|
+
border-top: 1px solid var(--color-base-300);
|
|
110
|
+
background: var(--color-base-100);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
.progress-section {
|
|
114
|
+
display: flex;
|
|
115
|
+
flex-direction: column;
|
|
116
|
+
gap: 0.5rem;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
.progress-label {
|
|
120
|
+
font-weight: 500;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
.navigation-buttons {
|
|
124
|
+
display: flex;
|
|
125
|
+
gap: 0.5rem;
|
|
126
|
+
align-items: center;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
@media (max-width: 640px) {
|
|
130
|
+
.navigation-buttons {
|
|
131
|
+
flex-direction: column;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
.navigation-buttons button {
|
|
135
|
+
width: 100%;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
.flex-1 {
|
|
139
|
+
display: none;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
</style>
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { typesetAction } from '@pie-qti/default-components/shared';
|
|
3
|
+
import type { I18nProvider } from '@pie-qti/i18n';
|
|
4
|
+
import type { RubricBlock } from '../integration/api-contract.js';
|
|
5
|
+
|
|
6
|
+
interface Props {
|
|
7
|
+
blocks: RubricBlock[];
|
|
8
|
+
collapsed?: boolean;
|
|
9
|
+
i18n?: I18nProvider;
|
|
10
|
+
/** Math typesetting function (KaTeX, MathJax, etc.) */
|
|
11
|
+
typeset?: (root: HTMLElement) => void | Promise<void>;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const { blocks, collapsed = false, i18n, typeset }: Props = $props();
|
|
15
|
+
|
|
16
|
+
let isCollapsed = $state(false);
|
|
17
|
+
|
|
18
|
+
$effect(() => {
|
|
19
|
+
isCollapsed = collapsed;
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
function toggleCollapse() {
|
|
23
|
+
isCollapsed = !isCollapsed;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Filter blocks by view type (for student/candidate view)
|
|
27
|
+
const visibleBlocks = $derived(blocks.filter((block) => block.view.includes('candidate')));
|
|
28
|
+
|
|
29
|
+
// Group blocks by use type
|
|
30
|
+
const passages = $derived(visibleBlocks.filter((block) => block.use === 'passage'));
|
|
31
|
+
const instructions = $derived(visibleBlocks.filter((block) => block.use === 'instructions'));
|
|
32
|
+
const rubrics = $derived(visibleBlocks.filter((block) => !block.use || block.use === 'rubric'));
|
|
33
|
+
</script>
|
|
34
|
+
|
|
35
|
+
{#if visibleBlocks.length > 0}
|
|
36
|
+
<div class="rubric-container">
|
|
37
|
+
<!-- Passages (typically reading comprehension) -->
|
|
38
|
+
{#if passages.length > 0}
|
|
39
|
+
<div class="passage-section">
|
|
40
|
+
{#each passages as passage}
|
|
41
|
+
<div class="passage">
|
|
42
|
+
<div class="passage-header">
|
|
43
|
+
<h4 class="font-semibold text-base">{i18n?.t('assessment.readingPassage') ?? 'Reading Passage'}</h4>
|
|
44
|
+
<button
|
|
45
|
+
class="btn btn-ghost btn-sm"
|
|
46
|
+
onclick={() => toggleCollapse?.()}
|
|
47
|
+
aria-label={isCollapsed ? (i18n?.t('assessment.expandPassage') ?? 'Expand passage') : (i18n?.t('assessment.collapsePassage') ?? 'Collapse passage')}
|
|
48
|
+
>
|
|
49
|
+
{#if isCollapsed}
|
|
50
|
+
<svg
|
|
51
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
52
|
+
class="h-5 w-5"
|
|
53
|
+
fill="none"
|
|
54
|
+
viewBox="0 0 24 24"
|
|
55
|
+
stroke="currentColor"
|
|
56
|
+
>
|
|
57
|
+
<path
|
|
58
|
+
stroke-linecap="round"
|
|
59
|
+
stroke-linejoin="round"
|
|
60
|
+
stroke-width="2"
|
|
61
|
+
d="M19 9l-7 7-7-7"
|
|
62
|
+
/>
|
|
63
|
+
</svg>
|
|
64
|
+
{:else}
|
|
65
|
+
<svg
|
|
66
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
67
|
+
class="h-5 w-5"
|
|
68
|
+
fill="none"
|
|
69
|
+
viewBox="0 0 24 24"
|
|
70
|
+
stroke="currentColor"
|
|
71
|
+
>
|
|
72
|
+
<path
|
|
73
|
+
stroke-linecap="round"
|
|
74
|
+
stroke-linejoin="round"
|
|
75
|
+
stroke-width="2"
|
|
76
|
+
d="M5 15l7-7 7 7"
|
|
77
|
+
/>
|
|
78
|
+
</svg>
|
|
79
|
+
{/if}
|
|
80
|
+
</button>
|
|
81
|
+
</div>
|
|
82
|
+
|
|
83
|
+
{#if !isCollapsed}
|
|
84
|
+
<div
|
|
85
|
+
use:typesetAction={{ typeset }}
|
|
86
|
+
class="passage-content prose max-w-none"
|
|
87
|
+
>
|
|
88
|
+
{@html passage.content}
|
|
89
|
+
</div>
|
|
90
|
+
{/if}
|
|
91
|
+
</div>
|
|
92
|
+
{/each}
|
|
93
|
+
</div>
|
|
94
|
+
{/if}
|
|
95
|
+
|
|
96
|
+
<!-- Instructions -->
|
|
97
|
+
{#if instructions.length > 0}
|
|
98
|
+
<div class="instructions-section">
|
|
99
|
+
{#each instructions as instruction}
|
|
100
|
+
<div class="alert alert-info">
|
|
101
|
+
<svg
|
|
102
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
103
|
+
fill="none"
|
|
104
|
+
viewBox="0 0 24 24"
|
|
105
|
+
class="stroke-current shrink-0 w-6 h-6"
|
|
106
|
+
>
|
|
107
|
+
<path
|
|
108
|
+
stroke-linecap="round"
|
|
109
|
+
stroke-linejoin="round"
|
|
110
|
+
stroke-width="2"
|
|
111
|
+
d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"
|
|
112
|
+
></path>
|
|
113
|
+
</svg>
|
|
114
|
+
<div use:typesetAction={{ typeset }}>
|
|
115
|
+
{@html instruction.content}
|
|
116
|
+
</div>
|
|
117
|
+
</div>
|
|
118
|
+
{/each}
|
|
119
|
+
</div>
|
|
120
|
+
{/if}
|
|
121
|
+
|
|
122
|
+
<!-- Other rubric blocks -->
|
|
123
|
+
{#if rubrics.length > 0}
|
|
124
|
+
<div class="rubric-section">
|
|
125
|
+
{#each rubrics as rubric}
|
|
126
|
+
<div use:typesetAction={{ typeset }} class="rubric-block">
|
|
127
|
+
{@html rubric.content}
|
|
128
|
+
</div>
|
|
129
|
+
{/each}
|
|
130
|
+
</div>
|
|
131
|
+
{/if}
|
|
132
|
+
</div>
|
|
133
|
+
{/if}
|
|
134
|
+
|
|
135
|
+
<style>
|
|
136
|
+
.rubric-container {
|
|
137
|
+
margin-bottom: 2rem;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
.passage-section {
|
|
141
|
+
margin-bottom: 1.5rem;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
.passage {
|
|
145
|
+
border: 1px solid var(--color-base-300);
|
|
146
|
+
border-radius: 0.5rem;
|
|
147
|
+
padding: 1rem;
|
|
148
|
+
background: var(--color-base-200);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
.passage-header {
|
|
152
|
+
display: flex;
|
|
153
|
+
justify-content: space-between;
|
|
154
|
+
align-items: center;
|
|
155
|
+
margin-bottom: 0.5rem;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
.passage-content {
|
|
159
|
+
padding: 1rem 0;
|
|
160
|
+
line-height: 1.6;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
.instructions-section {
|
|
164
|
+
margin-bottom: 1.5rem;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
.rubric-section {
|
|
168
|
+
margin-bottom: 1.5rem;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
.rubric-block {
|
|
172
|
+
padding: 1rem;
|
|
173
|
+
background: var(--color-base-200);
|
|
174
|
+
border-radius: 0.5rem;
|
|
175
|
+
margin-bottom: 1rem;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
:global(.passage-content p) {
|
|
179
|
+
margin-bottom: 1rem;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
:global(.passage-content p:last-child) {
|
|
183
|
+
margin-bottom: 0;
|
|
184
|
+
}
|
|
185
|
+
</style>
|