@pie-qti/assessment-player 0.1.5 → 0.1.6
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/dist/core/AssessmentPlayer.d.ts +5 -1
- package/dist/core/AssessmentPlayer.d.ts.map +1 -1
- package/dist/core/AssessmentPlayer.js +41 -7
- package/dist/integration/ReferenceBackendAdapter.d.ts +1 -7
- package/dist/integration/ReferenceBackendAdapter.d.ts.map +1 -1
- package/dist/integration/ReferenceBackendAdapter.js +31 -43
- package/dist/integration/api-contract.d.ts +9 -0
- package/dist/integration/api-contract.d.ts.map +1 -1
- package/dist/integration/assessment-item-scorer.d.ts +12 -0
- package/dist/integration/assessment-item-scorer.d.ts.map +1 -0
- package/dist/integration/assessment-item-scorer.js +40 -0
- package/dist/integration/index.d.ts +1 -0
- package/dist/integration/index.d.ts.map +1 -1
- package/dist/integration/index.js +1 -0
- package/package.json +5 -5
- package/src/components/AccessibilityAnnouncer.svelte +13 -2
- package/src/components/AssessmentShell.svelte +13 -8
- package/src/components/AssessmentTimer.svelte +23 -0
- package/src/components/ItemRenderer.svelte +7 -3
- package/src/components/NavigationBar.svelte +2 -0
- package/src/components/SectionMenu.svelte +72 -5
- package/src/core/AssessmentPlayer.ts +47 -8
- package/src/integration/ReferenceBackendAdapter.ts +29 -47
- package/src/integration/api-contract.ts +10 -0
- package/src/integration/assessment-item-scorer.ts +53 -0
- package/src/integration/index.ts +5 -0
|
@@ -85,6 +85,8 @@ export declare class AssessmentPlayer {
|
|
|
85
85
|
*/
|
|
86
86
|
private getEffectiveItemSessionControl;
|
|
87
87
|
private hasAnyResponse;
|
|
88
|
+
private restoreItemSessionsFromState;
|
|
89
|
+
private getItemSessionStateSnapshot;
|
|
88
90
|
private flattenItems;
|
|
89
91
|
getAllSections(): Array<{
|
|
90
92
|
id: string;
|
|
@@ -122,7 +124,9 @@ export declare class AssessmentPlayer {
|
|
|
122
124
|
* Restore a previously saved session state.
|
|
123
125
|
*/
|
|
124
126
|
restoreState(state: AssessmentSessionState): Promise<void>;
|
|
125
|
-
navigateTo(index: number
|
|
127
|
+
navigateTo(index: number, options?: {
|
|
128
|
+
restoring?: boolean;
|
|
129
|
+
}): Promise<void>;
|
|
126
130
|
navigateToSection(sectionId: string): Promise<void>;
|
|
127
131
|
next(): Promise<void>;
|
|
128
132
|
previous(): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AssessmentPlayer.d.ts","sourceRoot":"","sources":["../../src/core/AssessmentPlayer.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAEhE,OAAO,KAAK,EACX,qBAAqB,EACrB,sBAAsB,EAEtB,cAAc,EAEd,kBAAkB,EAOlB,MAAM,gCAAgC,CAAC;AACxC,OAAO,KAAK,EACX,iBAAiB,EACjB,UAAU,EACV,eAAe,EACf,MAAM,mBAAmB,CAAC;AAK3B,MAAM,WAAW,6BAA6B;IAC7C,OAAO,EAAE,cAAc,CAAC;IACxB,WAAW,EAAE,kBAAkB,CAAC;IAChC,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,+FAA+F;IAC/F,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;IACnB;;;OAGG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B;;;OAGG;IACH,YAAY,CAAC,EAAE,GAAG,CAAC;IACnB;;;OAGG;IACH,QAAQ,CAAC,EAAE,GAAG,CAAC;IAEf,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,sBAAsB,CAAC,EAAE,OAAO,CAAC;IACjC,YAAY,CAAC,EAAE,OAAO,CAAC;IAEvB,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B;;;;;OAKG;IACH,GAAG,CAAC,EAAE,UAAU,CAAC;IAEjB,YAAY,CAAC,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,M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,IAAI,GAAG;IAI7B;;OAEG;IACH,OAAO,CAAC,yBAAyB;CAUjC"}
|
|
@@ -57,6 +57,7 @@ export class AssessmentPlayer {
|
|
|
57
57
|
for (const q of this.items) {
|
|
58
58
|
this.sessionController.initializeItem(q.identifier);
|
|
59
59
|
}
|
|
60
|
+
this.restoreItemSessionsFromState(this.state);
|
|
60
61
|
// Initialize time manager if time limits exist
|
|
61
62
|
if (this.assessment.timeLimits?.maxTime) {
|
|
62
63
|
this.timeManager = new TimeManager({
|
|
@@ -72,7 +73,7 @@ export class AssessmentPlayer {
|
|
|
72
73
|
const startId = this.state.currentItemIdentifier;
|
|
73
74
|
const idx = startId ? this.items.findIndex((q) => q.identifier === startId) : -1;
|
|
74
75
|
if (idx >= 0) {
|
|
75
|
-
this.navigateTo(idx).catch(() => { });
|
|
76
|
+
this.navigateTo(idx, { restoring: true }).catch(() => { });
|
|
76
77
|
}
|
|
77
78
|
}
|
|
78
79
|
/**
|
|
@@ -116,6 +117,37 @@ export class AssessmentPlayer {
|
|
|
116
117
|
}
|
|
117
118
|
return false;
|
|
118
119
|
}
|
|
120
|
+
restoreItemSessionsFromState(state) {
|
|
121
|
+
const restoredStates = new Map();
|
|
122
|
+
for (const item of this.items) {
|
|
123
|
+
const persisted = state.itemSessionStates?.[item.identifier];
|
|
124
|
+
if (persisted) {
|
|
125
|
+
restoredStates.set(item.identifier, {
|
|
126
|
+
itemIdentifier: item.identifier,
|
|
127
|
+
attemptCount: Math.max(0, persisted.attemptCount),
|
|
128
|
+
isAnswered: persisted.isAnswered,
|
|
129
|
+
isSubmitted: persisted.isSubmitted,
|
|
130
|
+
lastSubmissionTime: persisted.lastSubmissionTime,
|
|
131
|
+
});
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
const responses = state.itemResponses?.[item.identifier] ?? {};
|
|
135
|
+
const isSubmitted = Boolean(state.itemScores?.[item.identifier]);
|
|
136
|
+
restoredStates.set(item.identifier, {
|
|
137
|
+
itemIdentifier: item.identifier,
|
|
138
|
+
attemptCount: isSubmitted ? 1 : 0,
|
|
139
|
+
isAnswered: this.hasAnyResponse(responses),
|
|
140
|
+
isSubmitted,
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
this.sessionController.restoreStates(restoredStates);
|
|
144
|
+
}
|
|
145
|
+
getItemSessionStateSnapshot() {
|
|
146
|
+
return Object.fromEntries([...this.sessionController.getAllStates().entries()].map(([itemIdentifier, state]) => [
|
|
147
|
+
itemIdentifier,
|
|
148
|
+
{ ...state },
|
|
149
|
+
]));
|
|
150
|
+
}
|
|
119
151
|
flattenItems(assessment) {
|
|
120
152
|
const out = [];
|
|
121
153
|
const testParts = assessment.testParts || [];
|
|
@@ -219,11 +251,11 @@ export class AssessmentPlayer {
|
|
|
219
251
|
const prev = (this.state.itemResponses?.[itemIdentifier] || {});
|
|
220
252
|
const next = { ...prev, [responseId]: value };
|
|
221
253
|
this.state.itemResponses[itemIdentifier] = next;
|
|
254
|
+
this.sessionController.markAnswered(itemIdentifier, this.hasAnyResponse(next));
|
|
222
255
|
// If this is the active item, keep the live response state + UI hints in sync.
|
|
223
256
|
const active = this.items[this.currentItemIndex];
|
|
224
257
|
if (active?.identifier === itemIdentifier) {
|
|
225
258
|
this.responses = next;
|
|
226
|
-
this.sessionController.markAnswered(itemIdentifier, this.hasAnyResponse(this.responses));
|
|
227
259
|
this.currentItemPlayer?.setResponses(this.responses);
|
|
228
260
|
this.notifyResponseChange();
|
|
229
261
|
}
|
|
@@ -246,6 +278,7 @@ export class AssessmentPlayer {
|
|
|
246
278
|
visitedItems: [...this.state.visitedItems],
|
|
247
279
|
itemResponses: { ...this.state.itemResponses },
|
|
248
280
|
itemScores: this.state.itemScores ? { ...this.state.itemScores } : undefined,
|
|
281
|
+
itemSessionStates: this.getItemSessionStateSnapshot(),
|
|
249
282
|
timing: {
|
|
250
283
|
...this.state.timing,
|
|
251
284
|
itemTimes: { ...this.state.timing.itemTimes },
|
|
@@ -262,6 +295,7 @@ export class AssessmentPlayer {
|
|
|
262
295
|
.map((id) => this.items.findIndex((q) => q.identifier === id))
|
|
263
296
|
.filter((i) => i >= 0);
|
|
264
297
|
this.navigationManager.restoreState(visitedIdx);
|
|
298
|
+
this.restoreItemSessionsFromState(state);
|
|
265
299
|
// Rehydrate itemResults from scores if present, so submit() can behave sensibly.
|
|
266
300
|
this.itemResults.clear();
|
|
267
301
|
if (state.itemScores) {
|
|
@@ -277,24 +311,24 @@ export class AssessmentPlayer {
|
|
|
277
311
|
const currentId = state.currentItemIdentifier;
|
|
278
312
|
const idx = currentId ? this.items.findIndex((q) => q.identifier === currentId) : -1;
|
|
279
313
|
if (idx >= 0) {
|
|
280
|
-
await this.navigateTo(idx);
|
|
314
|
+
await this.navigateTo(idx, { restoring: true });
|
|
281
315
|
}
|
|
282
316
|
else if (this.items.length > 0) {
|
|
283
|
-
await this.navigateTo(0);
|
|
317
|
+
await this.navigateTo(0, { restoring: true });
|
|
284
318
|
}
|
|
285
319
|
}
|
|
286
|
-
async navigateTo(index) {
|
|
320
|
+
async navigateTo(index, options = {}) {
|
|
287
321
|
if (index < 0 || index >= this.items.length)
|
|
288
322
|
throw new Error(`Invalid item index: ${index}`);
|
|
289
323
|
// Enforce navigation rules (UI hints, still backend-authoritative for real deployments).
|
|
290
|
-
if (this.currentItemIndex >= 0 && !this.navigationManager.canNavigateTo(index, this.currentItemIndex)) {
|
|
324
|
+
if (!options.restoring && this.currentItemIndex >= 0 && !this.navigationManager.canNavigateTo(index, this.currentItemIndex)) {
|
|
291
325
|
if (this.navigationManager.getMode() === 'linear' && index > this.currentItemIndex + 1) {
|
|
292
326
|
throw new Error('In linear navigation mode, you can only move to the next question.');
|
|
293
327
|
}
|
|
294
328
|
throw new Error('Navigation is not allowed.');
|
|
295
329
|
}
|
|
296
330
|
const target = this.items[index];
|
|
297
|
-
if (target && !this.sessionController.canReview(target.identifier)) {
|
|
331
|
+
if (!options.restoring && target && !this.sessionController.canReview(target.identifier)) {
|
|
298
332
|
throw new Error('You cannot go back to previous questions in this assessment.');
|
|
299
333
|
}
|
|
300
334
|
this.currentItemIndex = index;
|
|
@@ -50,6 +50,7 @@ export declare class ReferenceBackendAdapter implements BackendAdapter {
|
|
|
50
50
|
*/
|
|
51
51
|
registerAssessment(assessmentId: string, assessment: SecureAssessment): void;
|
|
52
52
|
private getAssessment;
|
|
53
|
+
private hasAnyResponse;
|
|
53
54
|
/**
|
|
54
55
|
* Initialize a new assessment session
|
|
55
56
|
*/
|
|
@@ -92,13 +93,6 @@ export declare class ReferenceBackendAdapter implements BackendAdapter {
|
|
|
92
93
|
private saveSession;
|
|
93
94
|
private findItemXml;
|
|
94
95
|
private findItemRef;
|
|
95
|
-
/**
|
|
96
|
-
* Score an item using the Player
|
|
97
|
-
*
|
|
98
|
-
* **SECURITY WARNING**: This is done CLIENT-SIDE for demo purposes only.
|
|
99
|
-
* Production implementations MUST perform scoring SERVER-SIDE.
|
|
100
|
-
*/
|
|
101
|
-
private scoreItem;
|
|
102
96
|
/**
|
|
103
97
|
* Create demo assessment for testing
|
|
104
98
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ReferenceBackendAdapter.d.ts","sourceRoot":"","sources":["../../src/integration/ReferenceBackendAdapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;
|
|
1
|
+
{"version":3,"file":"ReferenceBackendAdapter.d.ts","sourceRoot":"","sources":["../../src/integration/ReferenceBackendAdapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAiBH,OAAO,KAAK,EAGX,cAAc,EACd,yBAAyB,EACzB,0BAA0B,EAC1B,kBAAkB,EAClB,mBAAmB,EACnB,oBAAoB,EACpB,qBAAqB,EACrB,0BAA0B,EAC1B,2BAA2B,EAC3B,gBAAgB,EAChB,aAAa,EAGb,SAAS,EACT,sBAAsB,EACtB,uBAAuB,EACvB,MAAM,mBAAmB,CAAC;AAmD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C,CAAC;QACjD,OAAO,CAAC,EAAE,MAAM,CAAC;KACZ,GACJ,OAAO,CAAC,gBAAgB,CAAC;IA+Q5B,OAAO,CAAC,oBAAoB;IA4B5B,OAAO,CAAC,YAAY;IAgBpB;;OAEG;IACH,OAAO,CAAC,eAAe;IAWvB;;OAEG;IACH,OAAO,CAAC,aAAa;IAqBrB;;OAEG;IACH,OAAO,CAAC,aAAa;IAQrB;;;;;OAKG;YACW,kBAAkB;IAkLhC;;OAEG;IACH,OAAO,CAAC,KAAK;CAGb"}
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
* - Filters sensitive data based on role
|
|
28
28
|
*/
|
|
29
29
|
import { buildExpression, buildOutcomeProcessingAst, DeclarationContext, evalExpr, execProgram, OperatorRegistry, parseXml, serializeXml, qtiNull, qtiValue, } from '@pie-qti/qti-processing';
|
|
30
|
-
import {
|
|
30
|
+
import { scoreAssessmentItem } from './assessment-item-scorer.js';
|
|
31
31
|
/**
|
|
32
32
|
* Storage key prefix for localStorage
|
|
33
33
|
*/
|
|
@@ -75,6 +75,24 @@ export class ReferenceBackendAdapter {
|
|
|
75
75
|
getAssessment(assessmentId) {
|
|
76
76
|
return this.registeredAssessments.get(assessmentId) ?? this.createDemoAssessment(assessmentId);
|
|
77
77
|
}
|
|
78
|
+
hasAnyResponse(responses) {
|
|
79
|
+
for (const value of Object.values(responses)) {
|
|
80
|
+
if (value == null)
|
|
81
|
+
continue;
|
|
82
|
+
if (Array.isArray(value)) {
|
|
83
|
+
if (value.length > 0)
|
|
84
|
+
return true;
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
if (typeof value === 'string') {
|
|
88
|
+
if (value.trim().length > 0)
|
|
89
|
+
return true;
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
78
96
|
/**
|
|
79
97
|
* Initialize a new assessment session
|
|
80
98
|
*/
|
|
@@ -152,13 +170,24 @@ export class ReferenceBackendAdapter {
|
|
|
152
170
|
}
|
|
153
171
|
// **SECURITY WARNING**: Client-side scoring is INSECURE
|
|
154
172
|
// In production, this MUST be done server-side
|
|
155
|
-
const result =
|
|
173
|
+
const result = scoreAssessmentItem({ itemXml, responses: request.responses });
|
|
156
174
|
// Store responses and result
|
|
157
175
|
session.state.itemResponses[request.itemIdentifier] = request.responses;
|
|
158
176
|
if (!session.state.itemScores) {
|
|
159
177
|
session.state.itemScores = {};
|
|
160
178
|
}
|
|
161
179
|
session.state.itemScores[request.itemIdentifier] = result;
|
|
180
|
+
const previousItemSession = session.state.itemSessionStates?.[request.itemIdentifier];
|
|
181
|
+
session.state.itemSessionStates = {
|
|
182
|
+
...(session.state.itemSessionStates ?? {}),
|
|
183
|
+
[request.itemIdentifier]: {
|
|
184
|
+
itemIdentifier: request.itemIdentifier,
|
|
185
|
+
attemptCount: (previousItemSession?.attemptCount ?? 0) + 1,
|
|
186
|
+
isAnswered: this.hasAnyResponse(request.responses),
|
|
187
|
+
isSubmitted: true,
|
|
188
|
+
lastSubmissionTime: request.submittedAt,
|
|
189
|
+
},
|
|
190
|
+
};
|
|
162
191
|
// Update timing
|
|
163
192
|
if (request.timeSpent) {
|
|
164
193
|
session.state.timing.itemTimes[request.itemIdentifier] = request.timeSpent;
|
|
@@ -428,47 +457,6 @@ export class ReferenceBackendAdapter {
|
|
|
428
457
|
}
|
|
429
458
|
return null;
|
|
430
459
|
}
|
|
431
|
-
/**
|
|
432
|
-
* Score an item using the Player
|
|
433
|
-
*
|
|
434
|
-
* **SECURITY WARNING**: This is done CLIENT-SIDE for demo purposes only.
|
|
435
|
-
* Production implementations MUST perform scoring SERVER-SIDE.
|
|
436
|
-
*/
|
|
437
|
-
scoreItem(itemXml, responses) {
|
|
438
|
-
try {
|
|
439
|
-
// Extract identifier from XML using regex (more reliable than DOM parsing)
|
|
440
|
-
const identifierMatch = itemXml.match(/assessmentItem[^>]+identifier=["']([^"']+)["']/);
|
|
441
|
-
const itemIdentifier = identifierMatch?.[1] || 'unknown';
|
|
442
|
-
// Use a scorer-grade view of the item for accurate scoring.
|
|
443
|
-
// NOTE: This reference adapter is intentionally insecure and runs client-side.
|
|
444
|
-
// In production, scoring must happen server-side with secured item content.
|
|
445
|
-
const player = new Player({
|
|
446
|
-
itemXml,
|
|
447
|
-
role: 'scorer',
|
|
448
|
-
});
|
|
449
|
-
// Set responses using setResponses (plural)
|
|
450
|
-
player.setResponses(responses);
|
|
451
|
-
// Process and score
|
|
452
|
-
const result = player.processResponses();
|
|
453
|
-
return {
|
|
454
|
-
itemIdentifier,
|
|
455
|
-
score: result.score,
|
|
456
|
-
maxScore: result.maxScore,
|
|
457
|
-
completed: result.completed,
|
|
458
|
-
outcomeValues: result.outcomeValues,
|
|
459
|
-
};
|
|
460
|
-
}
|
|
461
|
-
catch (error) {
|
|
462
|
-
console.error('Scoring error:', error);
|
|
463
|
-
return {
|
|
464
|
-
itemIdentifier: 'unknown',
|
|
465
|
-
score: 0,
|
|
466
|
-
maxScore: 1,
|
|
467
|
-
completed: false,
|
|
468
|
-
outcomeValues: {},
|
|
469
|
-
};
|
|
470
|
-
}
|
|
471
|
-
}
|
|
472
460
|
/**
|
|
473
461
|
* Create demo assessment for testing
|
|
474
462
|
*
|
|
@@ -273,6 +273,8 @@ export interface AssessmentSessionState {
|
|
|
273
273
|
itemResponses: Record<string, Record<string, ResponseValue>>;
|
|
274
274
|
/** Scoring results per item (populated after submission) */
|
|
275
275
|
itemScores?: Record<string, AssessmentScoringResult>;
|
|
276
|
+
/** ItemSession lifecycle hints per item, used to restore attempt/review UI state */
|
|
277
|
+
itemSessionStates?: Record<string, AssessmentItemSessionState>;
|
|
276
278
|
/** Time tracking */
|
|
277
279
|
timing: {
|
|
278
280
|
/** Session start time */
|
|
@@ -283,6 +285,13 @@ export interface AssessmentSessionState {
|
|
|
283
285
|
totalTime: number;
|
|
284
286
|
};
|
|
285
287
|
}
|
|
288
|
+
export interface AssessmentItemSessionState {
|
|
289
|
+
itemIdentifier: string;
|
|
290
|
+
attemptCount: number;
|
|
291
|
+
isAnswered: boolean;
|
|
292
|
+
isSubmitted: boolean;
|
|
293
|
+
lastSubmissionTime?: number;
|
|
294
|
+
}
|
|
286
295
|
/**
|
|
287
296
|
* Finalize assessment and get full results
|
|
288
297
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-contract.d.ts","sourceRoot":"","sources":["../../src/integration/api-contract.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAMpD;;;GAGG;AACH,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC;AAE/B;;;;GAIG;AACH,MAAM,WAAW,kBAAkB;IAClC,4DAA4D;IAC5D,YAAY,EAAE,MAAM,CAAC;IACrB,wDAAwD;IACxD,WAAW,EAAE,MAAM,CAAC;IACpB,6CAA6C;IAC7C,eAAe,CAAC,EAAE,SAAS,CAAC;CAC5B;AAED,MAAM,WAAW,mBAAmB;IACnC,4DAA4D;IAC5D,SAAS,EAAE,SAAS,CAAC;IACrB,kDAAkD;IAClD,UAAU,EAAE,gBAAgB,CAAC;IAC7B,2DAA2D;IAC3D,aAAa,CAAC,EAAE,sBAAsB,CAAC;CACvC;AAMD;;;;GAIG;AACH,MAAM,WAAW,gBAAgB;IAChC,UAAU,EAAE,MAAM,CAAC;IACnB,+DAA+D;IAC/D,iBAAiB,EAAE,MAAM,CAAC;IAC1B,mFAAmF;IACnF,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAC;IAC1B,sEAAsE;IACtE,MAAM,EAAE,OAAO,GAAG,QAAQ,CAAC;IAC3B,8BAA8B;IAC9B,OAAO,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,gBAAgB;IAChC,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,iCAAiC;IACjC,cAAc,EAAE,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AO,EAAE,0BAA0B,GAAG,OAAO,CAAC,2BAA2B,CAAC,CAAC;IAErF;;OAEG;IACH,kBAAkB,CAAC,OAAO,EAAE,yBAAyB,GAAG,OAAO,CAAC,0BAA0B,CAAC,CAAC;IAE5F;;OAEG;IACH,aAAa,CAAC,CAAC,SAAS,EAAE,SAAS,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC;IAEnE;;;;OAIG;IACH,aAAa,CAAC,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAAC;CAC9E"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { AssessmentScoringResult, ResponseValue } from './api-contract.js';
|
|
2
|
+
export interface AssessmentItemScoringInput {
|
|
3
|
+
itemXml: string;
|
|
4
|
+
responses: Record<string, ResponseValue>;
|
|
5
|
+
}
|
|
6
|
+
export declare function getAssessmentItemIdentifier(itemXml: string): string;
|
|
7
|
+
/**
|
|
8
|
+
* Runs QTI ResponseProcessing for one AssessmentItem and normalizes the result
|
|
9
|
+
* to the BackendAdapter scoring shape used by AssessmentPlayer.
|
|
10
|
+
*/
|
|
11
|
+
export declare function scoreAssessmentItem({ itemXml, responses, }: AssessmentItemScoringInput): AssessmentScoringResult;
|
|
12
|
+
//# sourceMappingURL=assessment-item-scorer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assessment-item-scorer.d.ts","sourceRoot":"","sources":["../../src/integration/assessment-item-scorer.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,uBAAuB,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAEhF,MAAM,WAAW,0BAA0B;IAC1C,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;CACzC;AAED,wBAAgB,2BAA2B,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAGnE;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,EACnC,OAAO,EACP,SAAS,GACT,EAAE,0BAA0B,GAAG,uBAAuB,CAgCtD"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Player } from '@pie-qti/item-player';
|
|
2
|
+
export function getAssessmentItemIdentifier(itemXml) {
|
|
3
|
+
const identifierMatch = itemXml.match(/assessmentItem[^>]+identifier=["']([^"']+)["']/);
|
|
4
|
+
return identifierMatch?.[1] || 'unknown';
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Runs QTI ResponseProcessing for one AssessmentItem and normalizes the result
|
|
8
|
+
* to the BackendAdapter scoring shape used by AssessmentPlayer.
|
|
9
|
+
*/
|
|
10
|
+
export function scoreAssessmentItem({ itemXml, responses, }) {
|
|
11
|
+
const itemIdentifier = getAssessmentItemIdentifier(itemXml);
|
|
12
|
+
try {
|
|
13
|
+
// Use a scorer-grade view of the item for accurate scoring.
|
|
14
|
+
// NOTE: This reference scorer is intentionally insecure and runs client-side.
|
|
15
|
+
// In production, scoring must happen server-side with secured item content.
|
|
16
|
+
const player = new Player({
|
|
17
|
+
itemXml,
|
|
18
|
+
role: 'scorer',
|
|
19
|
+
});
|
|
20
|
+
player.setResponses(responses);
|
|
21
|
+
const result = player.processResponses();
|
|
22
|
+
return {
|
|
23
|
+
itemIdentifier,
|
|
24
|
+
score: result.score,
|
|
25
|
+
maxScore: result.maxScore,
|
|
26
|
+
completed: result.completed,
|
|
27
|
+
outcomeValues: result.outcomeValues,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
console.error('Scoring error:', error);
|
|
32
|
+
return {
|
|
33
|
+
itemIdentifier,
|
|
34
|
+
score: 0,
|
|
35
|
+
maxScore: 1,
|
|
36
|
+
completed: false,
|
|
37
|
+
outcomeValues: {},
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -44,4 +44,5 @@
|
|
|
44
44
|
*/
|
|
45
45
|
export type { BackendAdapter, FeedbackItem, AssessmentSessionState, AssessmentScoringResult, AssessmentRubricBlock, FinalizeAssessmentRequest, FinalizeAssessmentResponse, InitSessionRequest, InitSessionResponse, ResponseValue, SaveAssessmentStateRequest, SaveAssessmentStateResponse, SecureAssessment, SecureItemRef, SecureSection, SecureTestPart, SessionId, SubmitResponsesRequest, SubmitResponsesResponse, } from './api-contract.js';
|
|
46
46
|
export { ReferenceBackendAdapter } from './ReferenceBackendAdapter.js';
|
|
47
|
+
export { getAssessmentItemIdentifier, scoreAssessmentItem, type AssessmentItemScoringInput, } from './assessment-item-scorer.js';
|
|
47
48
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/integration/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AAGH,YAAY,EACX,cAAc,EACd,YAAY,EACZ,sBAAsB,EACtB,uBAAuB,EACvB,qBAAqB,EACrB,yBAAyB,EACzB,0BAA0B,EAC1B,kBAAkB,EAClB,mBAAmB,EACnB,aAAa,EACb,0BAA0B,EAC1B,2BAA2B,EAC3B,gBAAgB,EAChB,aAAa,EACb,aAAa,EACb,cAAc,EACd,SAAS,EACT,sBAAsB,EACtB,uBAAuB,GACvB,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/integration/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AAGH,YAAY,EACX,cAAc,EACd,YAAY,EACZ,sBAAsB,EACtB,uBAAuB,EACvB,qBAAqB,EACrB,yBAAyB,EACzB,0BAA0B,EAC1B,kBAAkB,EAClB,mBAAmB,EACnB,aAAa,EACb,0BAA0B,EAC1B,2BAA2B,EAC3B,gBAAgB,EAChB,aAAa,EACb,aAAa,EACb,cAAc,EACd,SAAS,EACT,sBAAsB,EACtB,uBAAuB,GACvB,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AACvE,OAAO,EACN,2BAA2B,EAC3B,mBAAmB,EACnB,KAAK,0BAA0B,GAC/B,MAAM,6BAA6B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pie-qti/assessment-player",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
4
4
|
"description": "QTI Assessment Player supporting QTI 2.2 and 3.0 - Multi-item test player with navigation, sections, and rubric blocks",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -28,10 +28,10 @@
|
|
|
28
28
|
],
|
|
29
29
|
"license": "MIT",
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@pie-qti/default-components": "0.1.
|
|
32
|
-
"@pie-qti/i18n": "0.1.
|
|
33
|
-
"@pie-qti/item-player": "0.1.
|
|
34
|
-
"@pie-qti/qti-processing": "0.1.
|
|
31
|
+
"@pie-qti/default-components": "0.1.6",
|
|
32
|
+
"@pie-qti/i18n": "0.1.6",
|
|
33
|
+
"@pie-qti/item-player": "0.1.6",
|
|
34
|
+
"@pie-qti/qti-processing": "0.1.6",
|
|
35
35
|
"node-html-parser": "^7.0.2"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
@@ -24,8 +24,15 @@
|
|
|
24
24
|
const { priority = 'polite' }: Props = $props();
|
|
25
25
|
|
|
26
26
|
let announcement = $state('');
|
|
27
|
+
let currentPriority = $state<'polite' | 'assertive'>('polite');
|
|
27
28
|
let announceTimeout: ReturnType<typeof setTimeout> | null = null;
|
|
28
29
|
|
|
30
|
+
$effect(() => {
|
|
31
|
+
if (!announcement) {
|
|
32
|
+
currentPriority = priority;
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
|
|
29
36
|
// Clean up timeout on destroy to prevent memory leaks
|
|
30
37
|
onDestroy(() => {
|
|
31
38
|
if (announceTimeout) {
|
|
@@ -39,8 +46,9 @@
|
|
|
39
46
|
*
|
|
40
47
|
* @param message - Text to announce
|
|
41
48
|
* @param clearAfter - Milliseconds to wait before clearing (default: 1000)
|
|
49
|
+
* @param nextPriority - Announcement priority for this message
|
|
42
50
|
*/
|
|
43
|
-
export function announce(message: string, clearAfter = 1000): void {
|
|
51
|
+
export function announce(message: string, clearAfter = 1000, nextPriority: 'polite' | 'assertive' = priority): void {
|
|
44
52
|
// Clear any existing announcement timeout
|
|
45
53
|
if (announceTimeout) {
|
|
46
54
|
clearTimeout(announceTimeout);
|
|
@@ -48,12 +56,14 @@
|
|
|
48
56
|
}
|
|
49
57
|
|
|
50
58
|
// Set the new announcement
|
|
59
|
+
currentPriority = nextPriority;
|
|
51
60
|
announcement = message;
|
|
52
61
|
|
|
53
62
|
// Clear after delay to allow screen readers to announce
|
|
54
63
|
// and prepare for next announcement
|
|
55
64
|
announceTimeout = setTimeout(() => {
|
|
56
65
|
announcement = '';
|
|
66
|
+
currentPriority = priority;
|
|
57
67
|
announceTimeout = null;
|
|
58
68
|
}, clearAfter);
|
|
59
69
|
}
|
|
@@ -67,6 +77,7 @@
|
|
|
67
77
|
announceTimeout = null;
|
|
68
78
|
}
|
|
69
79
|
announcement = '';
|
|
80
|
+
currentPriority = priority;
|
|
70
81
|
}
|
|
71
82
|
</script>
|
|
72
83
|
|
|
@@ -80,7 +91,7 @@
|
|
|
80
91
|
<div
|
|
81
92
|
class="sr-only"
|
|
82
93
|
role="status"
|
|
83
|
-
aria-live={
|
|
94
|
+
aria-live={currentPriority}
|
|
84
95
|
aria-atomic="true"
|
|
85
96
|
>
|
|
86
97
|
{announcement}
|
|
@@ -96,6 +96,7 @@
|
|
|
96
96
|
initTimeout = setTimeout(() => {
|
|
97
97
|
if (!hasFirstItem && !error) {
|
|
98
98
|
error = contextI18n?.t('assessment.loadingError') ?? 'assessment.loadingError';
|
|
99
|
+
announcer?.announce(error, 3000, 'assertive');
|
|
99
100
|
}
|
|
100
101
|
}, 10000);
|
|
101
102
|
|
|
@@ -143,6 +144,7 @@
|
|
|
143
144
|
})().catch((err) => {
|
|
144
145
|
console.error('Failed to initialize assessment player:', err);
|
|
145
146
|
error = err instanceof Error ? err.message : (contextI18n?.t('assessment.loadingError') ?? 'assessment.loadingError');
|
|
147
|
+
announcer?.announce(error, 3000, 'assertive');
|
|
146
148
|
});
|
|
147
149
|
|
|
148
150
|
return () => {
|
|
@@ -176,7 +178,8 @@
|
|
|
176
178
|
announceCurrentQuestion();
|
|
177
179
|
} catch (err) {
|
|
178
180
|
console.error('Previous navigation failed:', err);
|
|
179
|
-
|
|
181
|
+
const message = err instanceof Error ? err.message : (i18n?.t('assessment.errors.navigationFailed') ?? 'assessment.errors.navigationFailed');
|
|
182
|
+
navError = message;
|
|
180
183
|
}
|
|
181
184
|
}
|
|
182
185
|
|
|
@@ -189,7 +192,8 @@
|
|
|
189
192
|
announceCurrentQuestion();
|
|
190
193
|
} catch (err) {
|
|
191
194
|
console.error('Next navigation failed:', err);
|
|
192
|
-
|
|
195
|
+
const message = err instanceof Error ? err.message : (i18n?.t('assessment.errors.navigationFailed') ?? 'assessment.errors.navigationFailed');
|
|
196
|
+
navError = message;
|
|
193
197
|
}
|
|
194
198
|
}
|
|
195
199
|
|
|
@@ -251,7 +255,9 @@
|
|
|
251
255
|
// Or show results modal
|
|
252
256
|
} catch (err) {
|
|
253
257
|
console.error('Failed to submit assessment:', err);
|
|
254
|
-
|
|
258
|
+
const message = err instanceof Error ? err.message : (i18n?.t('assessment.errors.submitFailed') ?? 'assessment.errors.submitFailed');
|
|
259
|
+
error = message;
|
|
260
|
+
announcer?.announce(message, 3000, 'assertive');
|
|
255
261
|
}
|
|
256
262
|
}
|
|
257
263
|
|
|
@@ -305,7 +311,7 @@
|
|
|
305
311
|
|
|
306
312
|
{#if error}
|
|
307
313
|
<div class="assessment-error">
|
|
308
|
-
<div class="alert alert-error">
|
|
314
|
+
<div class="alert alert-error" role="alert" aria-live="assertive">
|
|
309
315
|
<svg
|
|
310
316
|
xmlns="http://www.w3.org/2000/svg"
|
|
311
317
|
class="stroke-current shrink-0 h-6 w-6"
|
|
@@ -324,13 +330,13 @@
|
|
|
324
330
|
</div>
|
|
325
331
|
{:else if !player || navState.currentIndex < 0}
|
|
326
332
|
<div class="assessment-loading">
|
|
327
|
-
<div class="flex items-center justify-center p-8">
|
|
333
|
+
<div class="flex items-center justify-center p-8" role="status" aria-live="polite">
|
|
328
334
|
<span class="loading loading-spinner loading-lg"></span>
|
|
329
335
|
<span class="ml-4">{contextI18n?.t('assessment.loading') ?? 'assessment.loading'}</span>
|
|
330
336
|
</div>
|
|
331
337
|
</div>
|
|
332
338
|
{:else}
|
|
333
|
-
<div bind:this={rootEl} class="assessment-shell" role="
|
|
339
|
+
<div bind:this={rootEl} class="assessment-shell" role="region" aria-label="Assessment player">
|
|
334
340
|
<!-- Header with title and section menu -->
|
|
335
341
|
<AssessmentHeader
|
|
336
342
|
title={initSession.assessmentId || (i18n?.t('assessment.title') ?? 'Assessment')}
|
|
@@ -348,7 +354,7 @@
|
|
|
348
354
|
|
|
349
355
|
{#if navError}
|
|
350
356
|
<div class="assessment-nav-error">
|
|
351
|
-
<div class="alert alert-warning">
|
|
357
|
+
<div class="alert alert-warning" role="alert" aria-live="assertive">
|
|
352
358
|
<svg
|
|
353
359
|
xmlns="http://www.w3.org/2000/svg"
|
|
354
360
|
class="stroke-current shrink-0 h-6 w-6"
|
|
@@ -374,7 +380,6 @@
|
|
|
374
380
|
tabindex="-1"
|
|
375
381
|
role="region"
|
|
376
382
|
aria-label={i18n?.t('accessibility.itemBody') ?? 'Question content'}
|
|
377
|
-
aria-live="polite"
|
|
378
383
|
>
|
|
379
384
|
{#if hasPassage}
|
|
380
385
|
<SplitPaneResizer
|
|
@@ -19,6 +19,8 @@
|
|
|
19
19
|
let elapsedSeconds = $state(0);
|
|
20
20
|
let isWarning = $state(false);
|
|
21
21
|
let isExpired = $state(false);
|
|
22
|
+
let announcement = $state('');
|
|
23
|
+
let announcementPriority = $state<'polite' | 'assertive'>('polite');
|
|
22
24
|
|
|
23
25
|
// Initialize state and subscribe to timer events
|
|
24
26
|
$effect(() => {
|
|
@@ -31,11 +33,17 @@
|
|
|
31
33
|
const unsubscribeWarning = player.onTimeWarning((remaining) => {
|
|
32
34
|
isWarning = true;
|
|
33
35
|
remainingSeconds = remaining;
|
|
36
|
+
announcementPriority = 'polite';
|
|
37
|
+
announcement =
|
|
38
|
+
i18n?.t('assessment.timer.timeRemaining', { time: TimeManager.formatTime(remaining) }) ??
|
|
39
|
+
`Time remaining: ${TimeManager.formatTime(remaining)}`;
|
|
34
40
|
});
|
|
35
41
|
|
|
36
42
|
const unsubscribeExpired = player.onTimeExpired(() => {
|
|
37
43
|
isExpired = true;
|
|
38
44
|
remainingSeconds = 0;
|
|
45
|
+
announcementPriority = 'assertive';
|
|
46
|
+
announcement = i18n?.t('assessment.timer.expired') ?? 'Time expired';
|
|
39
47
|
});
|
|
40
48
|
|
|
41
49
|
const unsubscribeTick = player.onTimeTick((remaining, elapsed) => {
|
|
@@ -106,6 +114,9 @@
|
|
|
106
114
|
<div class="timer-label">{timerLabel()}</div>
|
|
107
115
|
<div class="timer-value">{displayTime()}</div>
|
|
108
116
|
</div>
|
|
117
|
+
<div class="sr-only" role={announcementPriority === 'assertive' ? 'alert' : 'status'} aria-live={announcementPriority} aria-atomic="true">
|
|
118
|
+
{announcement}
|
|
119
|
+
</div>
|
|
109
120
|
</div>
|
|
110
121
|
{/if}
|
|
111
122
|
|
|
@@ -170,6 +181,18 @@
|
|
|
170
181
|
color: hsl(var(--bc));
|
|
171
182
|
}
|
|
172
183
|
|
|
184
|
+
.sr-only {
|
|
185
|
+
position: absolute;
|
|
186
|
+
width: 1px;
|
|
187
|
+
height: 1px;
|
|
188
|
+
padding: 0;
|
|
189
|
+
margin: -1px;
|
|
190
|
+
overflow: hidden;
|
|
191
|
+
clip: rect(0, 0, 0, 0);
|
|
192
|
+
white-space: nowrap;
|
|
193
|
+
border-width: 0;
|
|
194
|
+
}
|
|
195
|
+
|
|
173
196
|
.assessment-timer.warning .timer-value {
|
|
174
197
|
color: hsl(var(--wa));
|
|
175
198
|
}
|
|
@@ -4,10 +4,14 @@
|
|
|
4
4
|
// @ts-expect-error - Svelte-check can't resolve workspace subpath exports, but runtime works correctly
|
|
5
5
|
import { ItemBody } from '@pie-qti/item-player/components';
|
|
6
6
|
import { Player, type PlayerSecurityConfig, type QTIRole } from '@pie-qti/item-player';
|
|
7
|
+
import type { InteractionResponseValue } from '@pie-qti/item-player/web-components';
|
|
7
8
|
import type { I18nProvider } from '@pie-qti/i18n';
|
|
8
9
|
import { onMount } from 'svelte';
|
|
9
10
|
import type { ItemRef } from '../types/index.js';
|
|
10
11
|
|
|
12
|
+
type ItemResponseValue = InteractionResponseValue | null;
|
|
13
|
+
type ItemResponseMap = Record<string, ItemResponseValue>;
|
|
14
|
+
|
|
11
15
|
/**
|
|
12
16
|
* Ensure default interaction web components are registered (browser-only).
|
|
13
17
|
*
|
|
@@ -34,8 +38,8 @@
|
|
|
34
38
|
role?: QTIRole;
|
|
35
39
|
extendedTextEditor?: string;
|
|
36
40
|
/** Responses for the current item (keyed by responseIdentifier). */
|
|
37
|
-
responses?:
|
|
38
|
-
onResponseChange?: (responseId: string, value:
|
|
41
|
+
responses?: ItemResponseMap;
|
|
42
|
+
onResponseChange?: (responseId: string, value: ItemResponseValue) => void;
|
|
39
43
|
/** Math typesetting function (KaTeX, MathJax, etc.) */
|
|
40
44
|
typeset?: (root: HTMLElement) => void | Promise<void>;
|
|
41
45
|
/** I18n provider for translations */
|
|
@@ -86,7 +90,7 @@
|
|
|
86
90
|
});
|
|
87
91
|
|
|
88
92
|
// Handle response changes
|
|
89
|
-
function handleResponseChange(responseId: string, value:
|
|
93
|
+
function handleResponseChange(responseId: string, value: ItemResponseValue) {
|
|
90
94
|
onResponseChange?.(responseId, value);
|
|
91
95
|
}
|
|
92
96
|
</script>
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
previous: i18n?.t('common.previous') ?? 'Previous',
|
|
30
30
|
next: i18n?.t('common.next') ?? 'Next',
|
|
31
31
|
submit: i18n?.t('assessment.navigation.submit') ?? 'Submit',
|
|
32
|
+
progress: `${i18n?.t('assessment.navigation.progress', { percent: Math.round(progressPercentage) }) ?? `Progress: ${Math.round(progressPercentage)}%`}: ${i18n?.t('assessment.question', { current: navState.currentIndex + 1, total: navState.totalItems }) ?? `Question ${navState.currentIndex + 1} of ${navState.totalItems}`}`,
|
|
32
33
|
});
|
|
33
34
|
</script>
|
|
34
35
|
|
|
@@ -48,6 +49,7 @@
|
|
|
48
49
|
class="progress progress-primary w-full"
|
|
49
50
|
value={progressPercentage}
|
|
50
51
|
max="100"
|
|
52
|
+
aria-label={translations.progress}
|
|
51
53
|
></progress>
|
|
52
54
|
</div>
|
|
53
55
|
{/if}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
+
import { tick } from 'svelte';
|
|
2
3
|
import type { I18nProvider } from '@pie-qti/i18n';
|
|
3
4
|
|
|
4
5
|
interface Section {
|
|
@@ -18,9 +19,50 @@
|
|
|
18
19
|
const { sections, currentSectionIndex, i18n, onSectionSelect, disabled = false }: Props = $props();
|
|
19
20
|
|
|
20
21
|
let isOpen = $state(false);
|
|
22
|
+
let toggleButton = $state<HTMLButtonElement | null>(null);
|
|
23
|
+
let dropdownContent = $state<HTMLDivElement | null>(null);
|
|
24
|
+
const menuId = 'assessment-section-menu';
|
|
25
|
+
|
|
26
|
+
async function openMenu() {
|
|
27
|
+
if (disabled) return;
|
|
28
|
+
isOpen = true;
|
|
29
|
+
await tick();
|
|
30
|
+
const active = dropdownContent?.querySelector<HTMLButtonElement>('.section-item.active');
|
|
31
|
+
const first = dropdownContent?.querySelector<HTMLButtonElement>('.section-item:not(:disabled)');
|
|
32
|
+
(active ?? first)?.focus();
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function closeMenu({ restoreFocus = true } = {}) {
|
|
36
|
+
isOpen = false;
|
|
37
|
+
if (restoreFocus) {
|
|
38
|
+
toggleButton?.focus();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
21
41
|
|
|
22
42
|
function toggleMenu() {
|
|
23
|
-
isOpen
|
|
43
|
+
if (isOpen) {
|
|
44
|
+
closeMenu();
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
void openMenu();
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function handleMenuKeydown(event: KeyboardEvent) {
|
|
51
|
+
if (event.key === 'Escape') {
|
|
52
|
+
event.preventDefault();
|
|
53
|
+
closeMenu();
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function handleToggleKeydown(event: KeyboardEvent) {
|
|
58
|
+
if (event.key === 'ArrowDown') {
|
|
59
|
+
event.preventDefault();
|
|
60
|
+
void openMenu();
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function handleBackdropClick() {
|
|
65
|
+
closeMenu();
|
|
24
66
|
}
|
|
25
67
|
|
|
26
68
|
function selectSection(sectionIndex: number) {
|
|
@@ -28,13 +70,22 @@
|
|
|
28
70
|
if (onSectionSelect) {
|
|
29
71
|
onSectionSelect(sectionIndex);
|
|
30
72
|
}
|
|
31
|
-
|
|
73
|
+
closeMenu();
|
|
32
74
|
}
|
|
33
75
|
</script>
|
|
34
76
|
|
|
35
77
|
{#if sections.length > 1}
|
|
36
78
|
<div class="section-menu">
|
|
37
|
-
<button
|
|
79
|
+
<button
|
|
80
|
+
bind:this={toggleButton}
|
|
81
|
+
class="btn btn-outline btn-sm"
|
|
82
|
+
type="button"
|
|
83
|
+
aria-expanded={isOpen}
|
|
84
|
+
aria-controls={menuId}
|
|
85
|
+
onclick={() => toggleMenu?.()}
|
|
86
|
+
onkeydown={handleToggleKeydown}
|
|
87
|
+
disabled={disabled}
|
|
88
|
+
>
|
|
38
89
|
<svg
|
|
39
90
|
xmlns="http://www.w3.org/2000/svg"
|
|
40
91
|
class="h-5 w-5"
|
|
@@ -54,12 +105,23 @@
|
|
|
54
105
|
|
|
55
106
|
{#if isOpen}
|
|
56
107
|
<div class="section-dropdown">
|
|
57
|
-
<div
|
|
108
|
+
<div
|
|
109
|
+
bind:this={dropdownContent}
|
|
110
|
+
id={menuId}
|
|
111
|
+
class="section-dropdown-content"
|
|
112
|
+
role="menu"
|
|
113
|
+
tabindex="-1"
|
|
114
|
+
aria-label={i18n?.t('assessment.sections.title') ?? 'Sections'}
|
|
115
|
+
onkeydown={handleMenuKeydown}
|
|
116
|
+
>
|
|
58
117
|
<div class="section-list">
|
|
59
118
|
{#each sections as section}
|
|
60
119
|
<button
|
|
61
120
|
class="section-item"
|
|
62
121
|
class:active={currentSectionIndex === section.index}
|
|
122
|
+
type="button"
|
|
123
|
+
role="menuitemradio"
|
|
124
|
+
aria-checked={currentSectionIndex === section.index}
|
|
63
125
|
onclick={() => selectSection(section.index)}
|
|
64
126
|
disabled={disabled}
|
|
65
127
|
>
|
|
@@ -103,7 +165,12 @@
|
|
|
103
165
|
{/each}
|
|
104
166
|
</div>
|
|
105
167
|
</div>
|
|
106
|
-
<button
|
|
168
|
+
<button
|
|
169
|
+
class="section-backdrop"
|
|
170
|
+
type="button"
|
|
171
|
+
onclick={handleBackdropClick}
|
|
172
|
+
aria-label={i18n?.t('assessment.closeMenu') ?? 'Close menu'}
|
|
173
|
+
></button>
|
|
107
174
|
</div>
|
|
108
175
|
{/if}
|
|
109
176
|
</div>
|
|
@@ -29,7 +29,7 @@ import type {
|
|
|
29
29
|
ItemResult,
|
|
30
30
|
NavigationState,
|
|
31
31
|
} from '../types/index.js';
|
|
32
|
-
import { ItemSessionController } from './ItemSessionController.js';
|
|
32
|
+
import { ItemSessionController, type ItemSessionState } from './ItemSessionController.js';
|
|
33
33
|
import { NavigationManager } from './NavigationManager.js';
|
|
34
34
|
import { TimeManager } from './TimeManager.js';
|
|
35
35
|
|
|
@@ -151,6 +151,7 @@ export class AssessmentPlayer {
|
|
|
151
151
|
for (const q of this.items) {
|
|
152
152
|
this.sessionController.initializeItem(q.identifier);
|
|
153
153
|
}
|
|
154
|
+
this.restoreItemSessionsFromState(this.state);
|
|
154
155
|
|
|
155
156
|
// Initialize time manager if time limits exist
|
|
156
157
|
if (this.assessment.timeLimits?.maxTime) {
|
|
@@ -168,7 +169,7 @@ export class AssessmentPlayer {
|
|
|
168
169
|
const startId = this.state.currentItemIdentifier;
|
|
169
170
|
const idx = startId ? this.items.findIndex((q) => q.identifier === startId) : -1;
|
|
170
171
|
if (idx >= 0) {
|
|
171
|
-
this.navigateTo(idx).catch(() => {});
|
|
172
|
+
this.navigateTo(idx, { restoring: true }).catch(() => {});
|
|
172
173
|
}
|
|
173
174
|
}
|
|
174
175
|
|
|
@@ -212,6 +213,42 @@ export class AssessmentPlayer {
|
|
|
212
213
|
return false;
|
|
213
214
|
}
|
|
214
215
|
|
|
216
|
+
private restoreItemSessionsFromState(state: AssessmentSessionState): void {
|
|
217
|
+
const restoredStates = new Map<string, ItemSessionState>();
|
|
218
|
+
for (const item of this.items) {
|
|
219
|
+
const persisted = state.itemSessionStates?.[item.identifier];
|
|
220
|
+
if (persisted) {
|
|
221
|
+
restoredStates.set(item.identifier, {
|
|
222
|
+
itemIdentifier: item.identifier,
|
|
223
|
+
attemptCount: Math.max(0, persisted.attemptCount),
|
|
224
|
+
isAnswered: persisted.isAnswered,
|
|
225
|
+
isSubmitted: persisted.isSubmitted,
|
|
226
|
+
lastSubmissionTime: persisted.lastSubmissionTime,
|
|
227
|
+
});
|
|
228
|
+
continue;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
const responses = state.itemResponses?.[item.identifier] ?? {};
|
|
232
|
+
const isSubmitted = Boolean(state.itemScores?.[item.identifier]);
|
|
233
|
+
restoredStates.set(item.identifier, {
|
|
234
|
+
itemIdentifier: item.identifier,
|
|
235
|
+
attemptCount: isSubmitted ? 1 : 0,
|
|
236
|
+
isAnswered: this.hasAnyResponse(responses),
|
|
237
|
+
isSubmitted,
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
this.sessionController.restoreStates(restoredStates);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
private getItemSessionStateSnapshot(): Record<string, ItemSessionState> {
|
|
244
|
+
return Object.fromEntries(
|
|
245
|
+
[...this.sessionController.getAllStates().entries()].map(([itemIdentifier, state]) => [
|
|
246
|
+
itemIdentifier,
|
|
247
|
+
{ ...state },
|
|
248
|
+
])
|
|
249
|
+
);
|
|
250
|
+
}
|
|
251
|
+
|
|
215
252
|
private flattenItems(assessment: SecureAssessment): FlatItem[] {
|
|
216
253
|
const out: FlatItem[] = [];
|
|
217
254
|
const testParts = assessment.testParts || [];
|
|
@@ -325,12 +362,12 @@ export class AssessmentPlayer {
|
|
|
325
362
|
const prev = (this.state.itemResponses?.[itemIdentifier] || {}) as Record<string, unknown>;
|
|
326
363
|
const next = { ...prev, [responseId]: value };
|
|
327
364
|
this.state.itemResponses[itemIdentifier] = next as any;
|
|
365
|
+
this.sessionController.markAnswered(itemIdentifier, this.hasAnyResponse(next));
|
|
328
366
|
|
|
329
367
|
// If this is the active item, keep the live response state + UI hints in sync.
|
|
330
368
|
const active = this.items[this.currentItemIndex];
|
|
331
369
|
if (active?.identifier === itemIdentifier) {
|
|
332
370
|
this.responses = next;
|
|
333
|
-
this.sessionController.markAnswered(itemIdentifier, this.hasAnyResponse(this.responses));
|
|
334
371
|
this.currentItemPlayer?.setResponses(this.responses as any);
|
|
335
372
|
this.notifyResponseChange();
|
|
336
373
|
}
|
|
@@ -355,6 +392,7 @@ export class AssessmentPlayer {
|
|
|
355
392
|
visitedItems: [...this.state.visitedItems],
|
|
356
393
|
itemResponses: { ...this.state.itemResponses },
|
|
357
394
|
itemScores: this.state.itemScores ? { ...this.state.itemScores } : undefined,
|
|
395
|
+
itemSessionStates: this.getItemSessionStateSnapshot(),
|
|
358
396
|
timing: {
|
|
359
397
|
...this.state.timing,
|
|
360
398
|
itemTimes: { ...this.state.timing.itemTimes },
|
|
@@ -373,6 +411,7 @@ export class AssessmentPlayer {
|
|
|
373
411
|
.map((id) => this.items.findIndex((q) => q.identifier === id))
|
|
374
412
|
.filter((i) => i >= 0);
|
|
375
413
|
this.navigationManager.restoreState(visitedIdx);
|
|
414
|
+
this.restoreItemSessionsFromState(state);
|
|
376
415
|
|
|
377
416
|
// Rehydrate itemResults from scores if present, so submit() can behave sensibly.
|
|
378
417
|
this.itemResults.clear();
|
|
@@ -390,24 +429,24 @@ export class AssessmentPlayer {
|
|
|
390
429
|
const currentId = state.currentItemIdentifier;
|
|
391
430
|
const idx = currentId ? this.items.findIndex((q) => q.identifier === currentId) : -1;
|
|
392
431
|
if (idx >= 0) {
|
|
393
|
-
await this.navigateTo(idx);
|
|
432
|
+
await this.navigateTo(idx, { restoring: true });
|
|
394
433
|
} else if (this.items.length > 0) {
|
|
395
|
-
await this.navigateTo(0);
|
|
434
|
+
await this.navigateTo(0, { restoring: true });
|
|
396
435
|
}
|
|
397
436
|
}
|
|
398
437
|
|
|
399
|
-
public async navigateTo(index: number): Promise<void> {
|
|
438
|
+
public async navigateTo(index: number, options: { restoring?: boolean } = {}): Promise<void> {
|
|
400
439
|
if (index < 0 || index >= this.items.length) throw new Error(`Invalid item index: ${index}`);
|
|
401
440
|
|
|
402
441
|
// Enforce navigation rules (UI hints, still backend-authoritative for real deployments).
|
|
403
|
-
if (this.currentItemIndex >= 0 && !this.navigationManager.canNavigateTo(index, this.currentItemIndex)) {
|
|
442
|
+
if (!options.restoring && this.currentItemIndex >= 0 && !this.navigationManager.canNavigateTo(index, this.currentItemIndex)) {
|
|
404
443
|
if (this.navigationManager.getMode() === 'linear' && index > this.currentItemIndex + 1) {
|
|
405
444
|
throw new Error('In linear navigation mode, you can only move to the next question.');
|
|
406
445
|
}
|
|
407
446
|
throw new Error('Navigation is not allowed.');
|
|
408
447
|
}
|
|
409
448
|
const target = this.items[index];
|
|
410
|
-
if (target && !this.sessionController.canReview(target.identifier)) {
|
|
449
|
+
if (!options.restoring && target && !this.sessionController.canReview(target.identifier)) {
|
|
411
450
|
throw new Error('You cannot go back to previous questions in this assessment.');
|
|
412
451
|
}
|
|
413
452
|
|
|
@@ -41,7 +41,6 @@ import {
|
|
|
41
41
|
qtiNull,
|
|
42
42
|
qtiValue,
|
|
43
43
|
} from '@pie-qti/qti-processing';
|
|
44
|
-
import { Player } from '@pie-qti/item-player';
|
|
45
44
|
import { parse } from 'node-html-parser';
|
|
46
45
|
import type {
|
|
47
46
|
AssessmentSessionState,
|
|
@@ -63,6 +62,7 @@ import type {
|
|
|
63
62
|
SubmitResponsesRequest,
|
|
64
63
|
SubmitResponsesResponse,
|
|
65
64
|
} from './api-contract.js';
|
|
65
|
+
import { scoreAssessmentItem } from './assessment-item-scorer.js';
|
|
66
66
|
|
|
67
67
|
/**
|
|
68
68
|
* Storage key prefix for localStorage
|
|
@@ -142,6 +142,22 @@ export class ReferenceBackendAdapter implements BackendAdapter {
|
|
|
142
142
|
return this.registeredAssessments.get(assessmentId) ?? this.createDemoAssessment(assessmentId);
|
|
143
143
|
}
|
|
144
144
|
|
|
145
|
+
private hasAnyResponse(responses: Record<string, unknown>): boolean {
|
|
146
|
+
for (const value of Object.values(responses)) {
|
|
147
|
+
if (value == null) continue;
|
|
148
|
+
if (Array.isArray(value)) {
|
|
149
|
+
if (value.length > 0) return true;
|
|
150
|
+
continue;
|
|
151
|
+
}
|
|
152
|
+
if (typeof value === 'string') {
|
|
153
|
+
if (value.trim().length > 0) return true;
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
return true;
|
|
157
|
+
}
|
|
158
|
+
return false;
|
|
159
|
+
}
|
|
160
|
+
|
|
145
161
|
/**
|
|
146
162
|
* Initialize a new assessment session
|
|
147
163
|
*/
|
|
@@ -229,7 +245,7 @@ export class ReferenceBackendAdapter implements BackendAdapter {
|
|
|
229
245
|
|
|
230
246
|
// **SECURITY WARNING**: Client-side scoring is INSECURE
|
|
231
247
|
// In production, this MUST be done server-side
|
|
232
|
-
const result =
|
|
248
|
+
const result = scoreAssessmentItem({ itemXml, responses: request.responses });
|
|
233
249
|
|
|
234
250
|
// Store responses and result
|
|
235
251
|
session.state.itemResponses[request.itemIdentifier] = request.responses;
|
|
@@ -237,6 +253,17 @@ export class ReferenceBackendAdapter implements BackendAdapter {
|
|
|
237
253
|
session.state.itemScores = {};
|
|
238
254
|
}
|
|
239
255
|
session.state.itemScores[request.itemIdentifier] = result;
|
|
256
|
+
const previousItemSession = session.state.itemSessionStates?.[request.itemIdentifier];
|
|
257
|
+
session.state.itemSessionStates = {
|
|
258
|
+
...(session.state.itemSessionStates ?? {}),
|
|
259
|
+
[request.itemIdentifier]: {
|
|
260
|
+
itemIdentifier: request.itemIdentifier,
|
|
261
|
+
attemptCount: (previousItemSession?.attemptCount ?? 0) + 1,
|
|
262
|
+
isAnswered: this.hasAnyResponse(request.responses),
|
|
263
|
+
isSubmitted: true,
|
|
264
|
+
lastSubmissionTime: request.submittedAt,
|
|
265
|
+
},
|
|
266
|
+
};
|
|
240
267
|
|
|
241
268
|
// Update timing
|
|
242
269
|
if (request.timeSpent) {
|
|
@@ -544,51 +571,6 @@ export class ReferenceBackendAdapter implements BackendAdapter {
|
|
|
544
571
|
return null;
|
|
545
572
|
}
|
|
546
573
|
|
|
547
|
-
/**
|
|
548
|
-
* Score an item using the Player
|
|
549
|
-
*
|
|
550
|
-
* **SECURITY WARNING**: This is done CLIENT-SIDE for demo purposes only.
|
|
551
|
-
* Production implementations MUST perform scoring SERVER-SIDE.
|
|
552
|
-
*/
|
|
553
|
-
private scoreItem(itemXml: string, responses: Record<string, any>): AssessmentScoringResult {
|
|
554
|
-
try {
|
|
555
|
-
// Extract identifier from XML using regex (more reliable than DOM parsing)
|
|
556
|
-
const identifierMatch = itemXml.match(/assessmentItem[^>]+identifier=["']([^"']+)["']/);
|
|
557
|
-
const itemIdentifier = identifierMatch?.[1] || 'unknown';
|
|
558
|
-
|
|
559
|
-
// Use a scorer-grade view of the item for accurate scoring.
|
|
560
|
-
// NOTE: This reference adapter is intentionally insecure and runs client-side.
|
|
561
|
-
// In production, scoring must happen server-side with secured item content.
|
|
562
|
-
const player = new Player({
|
|
563
|
-
itemXml,
|
|
564
|
-
role: 'scorer',
|
|
565
|
-
});
|
|
566
|
-
|
|
567
|
-
// Set responses using setResponses (plural)
|
|
568
|
-
player.setResponses(responses);
|
|
569
|
-
|
|
570
|
-
// Process and score
|
|
571
|
-
const result = player.processResponses();
|
|
572
|
-
|
|
573
|
-
return {
|
|
574
|
-
itemIdentifier,
|
|
575
|
-
score: result.score,
|
|
576
|
-
maxScore: result.maxScore,
|
|
577
|
-
completed: result.completed,
|
|
578
|
-
outcomeValues: result.outcomeValues,
|
|
579
|
-
};
|
|
580
|
-
} catch (error) {
|
|
581
|
-
console.error('Scoring error:', error);
|
|
582
|
-
return {
|
|
583
|
-
itemIdentifier: 'unknown',
|
|
584
|
-
score: 0,
|
|
585
|
-
maxScore: 1,
|
|
586
|
-
completed: false,
|
|
587
|
-
outcomeValues: {},
|
|
588
|
-
};
|
|
589
|
-
}
|
|
590
|
-
}
|
|
591
|
-
|
|
592
574
|
/**
|
|
593
575
|
* Create demo assessment for testing
|
|
594
576
|
*
|
|
@@ -311,6 +311,8 @@ export interface AssessmentSessionState {
|
|
|
311
311
|
itemResponses: Record<string, Record<string, ResponseValue>>;
|
|
312
312
|
/** Scoring results per item (populated after submission) */
|
|
313
313
|
itemScores?: Record<string, AssessmentScoringResult>;
|
|
314
|
+
/** ItemSession lifecycle hints per item, used to restore attempt/review UI state */
|
|
315
|
+
itemSessionStates?: Record<string, AssessmentItemSessionState>;
|
|
314
316
|
/** Time tracking */
|
|
315
317
|
timing: {
|
|
316
318
|
/** Session start time */
|
|
@@ -322,6 +324,14 @@ export interface AssessmentSessionState {
|
|
|
322
324
|
};
|
|
323
325
|
}
|
|
324
326
|
|
|
327
|
+
export interface AssessmentItemSessionState {
|
|
328
|
+
itemIdentifier: string;
|
|
329
|
+
attemptCount: number;
|
|
330
|
+
isAnswered: boolean;
|
|
331
|
+
isSubmitted: boolean;
|
|
332
|
+
lastSubmissionTime?: number;
|
|
333
|
+
}
|
|
334
|
+
|
|
325
335
|
// ============================================================================
|
|
326
336
|
// FINALIZE ASSESSMENT
|
|
327
337
|
// ============================================================================
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { Player } from '@pie-qti/item-player';
|
|
2
|
+
import type { AssessmentScoringResult, ResponseValue } from './api-contract.js';
|
|
3
|
+
|
|
4
|
+
export interface AssessmentItemScoringInput {
|
|
5
|
+
itemXml: string;
|
|
6
|
+
responses: Record<string, ResponseValue>;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function getAssessmentItemIdentifier(itemXml: string): string {
|
|
10
|
+
const identifierMatch = itemXml.match(/assessmentItem[^>]+identifier=["']([^"']+)["']/);
|
|
11
|
+
return identifierMatch?.[1] || 'unknown';
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Runs QTI ResponseProcessing for one AssessmentItem and normalizes the result
|
|
16
|
+
* to the BackendAdapter scoring shape used by AssessmentPlayer.
|
|
17
|
+
*/
|
|
18
|
+
export function scoreAssessmentItem({
|
|
19
|
+
itemXml,
|
|
20
|
+
responses,
|
|
21
|
+
}: AssessmentItemScoringInput): AssessmentScoringResult {
|
|
22
|
+
const itemIdentifier = getAssessmentItemIdentifier(itemXml);
|
|
23
|
+
|
|
24
|
+
try {
|
|
25
|
+
// Use a scorer-grade view of the item for accurate scoring.
|
|
26
|
+
// NOTE: This reference scorer is intentionally insecure and runs client-side.
|
|
27
|
+
// In production, scoring must happen server-side with secured item content.
|
|
28
|
+
const player = new Player({
|
|
29
|
+
itemXml,
|
|
30
|
+
role: 'scorer',
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
player.setResponses(responses);
|
|
34
|
+
const result = player.processResponses();
|
|
35
|
+
|
|
36
|
+
return {
|
|
37
|
+
itemIdentifier,
|
|
38
|
+
score: result.score,
|
|
39
|
+
maxScore: result.maxScore,
|
|
40
|
+
completed: result.completed,
|
|
41
|
+
outcomeValues: result.outcomeValues,
|
|
42
|
+
};
|
|
43
|
+
} catch (error) {
|
|
44
|
+
console.error('Scoring error:', error);
|
|
45
|
+
return {
|
|
46
|
+
itemIdentifier,
|
|
47
|
+
score: 0,
|
|
48
|
+
maxScore: 1,
|
|
49
|
+
completed: false,
|
|
50
|
+
outcomeValues: {},
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
}
|
package/src/integration/index.ts
CHANGED
|
@@ -68,3 +68,8 @@ export type {
|
|
|
68
68
|
|
|
69
69
|
// Export reference implementation (for development/demos)
|
|
70
70
|
export { ReferenceBackendAdapter } from './ReferenceBackendAdapter.js';
|
|
71
|
+
export {
|
|
72
|
+
getAssessmentItemIdentifier,
|
|
73
|
+
scoreAssessmentItem,
|
|
74
|
+
type AssessmentItemScoringInput,
|
|
75
|
+
} from './assessment-item-scorer.js';
|