@pie-qti/assessment-player 0.1.5 → 0.1.7
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 +27 -5
- package/dist/core/AssessmentPlayer.d.ts.map +1 -1
- package/dist/core/AssessmentPlayer.js +211 -20
- package/dist/integration/ReferenceBackendAdapter.d.ts +1 -7
- package/dist/integration/ReferenceBackendAdapter.d.ts.map +1 -1
- package/dist/integration/ReferenceBackendAdapter.js +144 -61
- package/dist/integration/api-contract.d.ts +39 -11
- package/dist/integration/api-contract.d.ts.map +1 -1
- package/dist/integration/assessment-item-scorer.d.ts +14 -0
- package/dist/integration/assessment-item-scorer.d.ts.map +1 -0
- package/dist/integration/assessment-item-scorer.js +43 -0
- package/dist/integration/index.d.ts +2 -1
- package/dist/integration/index.d.ts.map +1 -1
- package/dist/integration/index.js +1 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +6 -5
- package/src/components/AccessibilityAnnouncer.svelte +13 -2
- package/src/components/AssessmentShell.svelte +22 -39
- package/src/components/AssessmentTimer.svelte +23 -0
- package/src/components/ItemRenderer.svelte +14 -4
- package/src/components/NavigationBar.svelte +2 -0
- package/src/components/SectionMenu.svelte +72 -5
- package/src/core/AssessmentPlayer.ts +249 -23
- package/src/integration/ReferenceBackendAdapter.ts +155 -65
- package/src/integration/api-contract.ts +42 -11
- package/src/integration/assessment-item-scorer.ts +58 -0
- package/src/integration/index.ts +7 -0
- package/src/types/index.ts +3 -0
|
@@ -7,9 +7,9 @@
|
|
|
7
7
|
* - Submit responses to BackendAdapter
|
|
8
8
|
* - Apply backend navigation decisions + session state
|
|
9
9
|
*/
|
|
10
|
-
import type { QTIRole, PnpProfile } from '@pie-qti/item-player';
|
|
11
|
-
import type { AssessmentRubricBlock, AssessmentSessionState, BackendAdapter, InitSessionRequest } from '../integration/api-contract.js';
|
|
12
|
-
import type { AssessmentResults, ItemResult, NavigationState } from '../types/index.js';
|
|
10
|
+
import type { QTIRole, PnpProfile, SerializedItemSessionState } from '@pie-qti/item-player';
|
|
11
|
+
import type { AssessmentRubricBlock, AssessmentSessionState, BackendAdapter, InitSessionRequest, SecureItemRef } from '../integration/api-contract.js';
|
|
12
|
+
import type { AssessmentResults, ItemResult, NavigationState, TimeLimits } from '../types/index.js';
|
|
13
13
|
export interface BackendAssessmentPlayerConfig {
|
|
14
14
|
backend: BackendAdapter;
|
|
15
15
|
initSession: InitSessionRequest;
|
|
@@ -31,6 +31,12 @@ export interface BackendAssessmentPlayerConfig {
|
|
|
31
31
|
* If provided, this will be passed to all item players in the assessment.
|
|
32
32
|
*/
|
|
33
33
|
security?: any;
|
|
34
|
+
/**
|
|
35
|
+
* Demo/reference-only escape hatch. When false (default), rich item-session
|
|
36
|
+
* variables stay client-local and are not submitted because template variables
|
|
37
|
+
* can contain answer keys. Production backends should own this state server-side.
|
|
38
|
+
*/
|
|
39
|
+
sendItemSessionToBackend?: boolean;
|
|
34
40
|
showSections?: boolean;
|
|
35
41
|
allowSectionNavigation?: boolean;
|
|
36
42
|
showProgress?: boolean;
|
|
@@ -52,7 +58,12 @@ type CurrentItemView = {
|
|
|
52
58
|
title?: string;
|
|
53
59
|
required?: boolean;
|
|
54
60
|
itemXml: string;
|
|
61
|
+
deliveryContext?: SecureItemRef['deliveryContext'];
|
|
55
62
|
};
|
|
63
|
+
export interface EffectiveItemTimeLimits {
|
|
64
|
+
timeLimits?: TimeLimits;
|
|
65
|
+
source?: 'item' | 'section' | 'testPart' | 'assessment';
|
|
66
|
+
}
|
|
56
67
|
export declare class AssessmentPlayer {
|
|
57
68
|
private config;
|
|
58
69
|
static create(config: BackendAssessmentPlayerConfig): Promise<AssessmentPlayer>;
|
|
@@ -84,7 +95,12 @@ export declare class AssessmentPlayer {
|
|
|
84
95
|
* Section-level values override testPart-level when present.
|
|
85
96
|
*/
|
|
86
97
|
private getEffectiveItemSessionControl;
|
|
98
|
+
private getEffectiveItemTimeLimits;
|
|
99
|
+
getCurrentEffectiveTimeLimits(): EffectiveItemTimeLimits;
|
|
100
|
+
private getSubmitTimingEvidence;
|
|
87
101
|
private hasAnyResponse;
|
|
102
|
+
private restoreItemSessionsFromState;
|
|
103
|
+
private getItemSessionStateSnapshot;
|
|
88
104
|
private flattenItems;
|
|
89
105
|
getAllSections(): Array<{
|
|
90
106
|
id: string;
|
|
@@ -113,16 +129,22 @@ export declare class AssessmentPlayer {
|
|
|
113
129
|
* (Useful for host integrations / web components.)
|
|
114
130
|
*/
|
|
115
131
|
getResponses(): Record<string, unknown>;
|
|
132
|
+
saveCurrentItemSession(): SerializedItemSessionState | null;
|
|
133
|
+
private endItemSessionForSubmit;
|
|
116
134
|
/**
|
|
117
135
|
* Get the current session state snapshot (client-side view).
|
|
118
136
|
* Note: backend remains authoritative; this is intended for simple save/resume.
|
|
119
137
|
*/
|
|
120
|
-
getState(
|
|
138
|
+
getState(options?: {
|
|
139
|
+
includeItemSessions?: boolean;
|
|
140
|
+
}): AssessmentSessionState;
|
|
121
141
|
/**
|
|
122
142
|
* Restore a previously saved session state.
|
|
123
143
|
*/
|
|
124
144
|
restoreState(state: AssessmentSessionState): Promise<void>;
|
|
125
|
-
navigateTo(index: number
|
|
145
|
+
navigateTo(index: number, options?: {
|
|
146
|
+
restoring?: boolean;
|
|
147
|
+
}): Promise<void>;
|
|
126
148
|
navigateToSection(sectionId: string): Promise<void>;
|
|
127
149
|
next(): Promise<void>;
|
|
128
150
|
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;
|
|
1
|
+
{"version":3,"file":"AssessmentPlayer.d.ts","sourceRoot":"","sources":["../../src/core/AssessmentPlayer.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KvE,aAAa,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI;IAK/C,UAAU,CAAC,QAAQ,EAAE,CAAC,gBAAgB,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,KAAK,IAAI,GAAG,MAAM,IAAI;IAK5F,OAAO,IAAI,IAAI;IAiBtB,OAAO,CAAC,gBAAgB;IAKxB,OAAO,CAAC,mBAAmB;IAQ3B,OAAO,CAAC,oBAAoB;IAK5B,OAAO,CAAC,cAAc;IAItB,OAAO,CAAC,iBAAiB;IAIzB,OAAO,CAAC,iBAAiB;IAIzB,OAAO,CAAC,cAAc;IAItB;;;OAGG;IACI,eAAe,IAAI,GAAG;IAI7B;;OAEG;IACH,OAAO,CAAC,yBAAyB;CAUjC"}
|
|
@@ -44,6 +44,7 @@ export class AssessmentPlayer {
|
|
|
44
44
|
visitedItems: [],
|
|
45
45
|
itemResponses: {},
|
|
46
46
|
itemScores: {},
|
|
47
|
+
itemSessions: {},
|
|
47
48
|
timing: { startedAt: Date.now(), itemTimes: {}, totalTime: 0 },
|
|
48
49
|
};
|
|
49
50
|
this.items = this.flattenItems(this.assessment);
|
|
@@ -57,22 +58,23 @@ export class AssessmentPlayer {
|
|
|
57
58
|
for (const q of this.items) {
|
|
58
59
|
this.sessionController.initializeItem(q.identifier);
|
|
59
60
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
this.
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
});
|
|
70
|
-
}
|
|
61
|
+
this.restoreItemSessionsFromState(this.state);
|
|
62
|
+
this.timeManager = new TimeManager({
|
|
63
|
+
assessmentTimeLimits: this.assessment.timeLimits,
|
|
64
|
+
warningThreshold: config.timeWarningThreshold || 60,
|
|
65
|
+
extendedTime: config.pnp?.content?.extendedTime,
|
|
66
|
+
onWarning: (remainingSeconds) => this.notifyTimeWarning(remainingSeconds),
|
|
67
|
+
onExpired: () => this.notifyTimeExpired(),
|
|
68
|
+
onTick: (remainingSeconds, elapsedSeconds) => this.notifyTimeTick(remainingSeconds, elapsedSeconds),
|
|
69
|
+
});
|
|
71
70
|
// Restore to backend-provided current item if present
|
|
72
71
|
const startId = this.state.currentItemIdentifier;
|
|
73
72
|
const idx = startId ? this.items.findIndex((q) => q.identifier === startId) : -1;
|
|
74
73
|
if (idx >= 0) {
|
|
75
|
-
this.navigateTo(idx).catch(() => { });
|
|
74
|
+
this.navigateTo(idx, { restoring: true }).catch(() => { });
|
|
75
|
+
}
|
|
76
|
+
else if (this.items.length > 0) {
|
|
77
|
+
this.navigateTo(0, { restoring: true }).catch(() => { });
|
|
76
78
|
}
|
|
77
79
|
}
|
|
78
80
|
/**
|
|
@@ -97,6 +99,69 @@ export class AssessmentPlayer {
|
|
|
97
99
|
validateResponses: sectionControl.validateResponses ?? testPartControl.validateResponses,
|
|
98
100
|
};
|
|
99
101
|
}
|
|
102
|
+
getEffectiveItemTimeLimits(flat) {
|
|
103
|
+
const scopes = [
|
|
104
|
+
{ source: 'assessment', limits: this.assessment.timeLimits },
|
|
105
|
+
{ source: 'testPart', limits: flat.testPart.timeLimits },
|
|
106
|
+
{ source: 'section', limits: flat.section.timeLimits },
|
|
107
|
+
{ source: 'item', limits: flat.item.timeLimits },
|
|
108
|
+
];
|
|
109
|
+
let source;
|
|
110
|
+
let minTime;
|
|
111
|
+
let maxTime;
|
|
112
|
+
let allowLateSubmission;
|
|
113
|
+
for (const scope of scopes) {
|
|
114
|
+
if (!scope.limits)
|
|
115
|
+
continue;
|
|
116
|
+
if (scope.limits.minTime !== undefined) {
|
|
117
|
+
minTime = minTime === undefined ? scope.limits.minTime : Math.max(minTime, scope.limits.minTime);
|
|
118
|
+
}
|
|
119
|
+
if (scope.limits.maxTime !== undefined) {
|
|
120
|
+
const extended = this.config.pnp?.content?.extendedTime;
|
|
121
|
+
const scopedMaxTime = extended?.active
|
|
122
|
+
? extended.multiplier === Infinity
|
|
123
|
+
? undefined
|
|
124
|
+
: scope.limits.maxTime * extended.multiplier
|
|
125
|
+
: scope.limits.maxTime;
|
|
126
|
+
if (scopedMaxTime !== undefined && (maxTime === undefined || scopedMaxTime < maxTime)) {
|
|
127
|
+
maxTime = scopedMaxTime;
|
|
128
|
+
source = scope.source;
|
|
129
|
+
allowLateSubmission = scope.limits.allowLateSubmission;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
else if (scope.limits.allowLateSubmission !== undefined && maxTime === undefined) {
|
|
133
|
+
allowLateSubmission = scope.limits.allowLateSubmission;
|
|
134
|
+
source = scope.source;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
if (maxTime === undefined && minTime === undefined && allowLateSubmission === undefined) {
|
|
138
|
+
return {};
|
|
139
|
+
}
|
|
140
|
+
return { source, timeLimits: { minTime, maxTime, allowLateSubmission } };
|
|
141
|
+
}
|
|
142
|
+
getCurrentEffectiveTimeLimits() {
|
|
143
|
+
const q = this.items[this.currentItemIndex];
|
|
144
|
+
return q ? this.getEffectiveItemTimeLimits(q) : {};
|
|
145
|
+
}
|
|
146
|
+
getSubmitTimingEvidence(q, elapsedMs) {
|
|
147
|
+
const effective = this.getEffectiveItemTimeLimits(q);
|
|
148
|
+
const limitSeconds = effective.timeLimits?.maxTime;
|
|
149
|
+
if (!effective.source || limitSeconds === undefined)
|
|
150
|
+
return undefined;
|
|
151
|
+
if (effective.source !== 'item' && effective.source !== 'assessment') {
|
|
152
|
+
return undefined;
|
|
153
|
+
}
|
|
154
|
+
const scopedElapsedMs = effective.source === 'assessment'
|
|
155
|
+
? (this.timeManager?.getElapsedSeconds() ?? 0) * 1000
|
|
156
|
+
: elapsedMs;
|
|
157
|
+
return {
|
|
158
|
+
scope: effective.source,
|
|
159
|
+
elapsedMs: scopedElapsedMs,
|
|
160
|
+
limitSeconds,
|
|
161
|
+
expired: scopedElapsedMs >= limitSeconds * 1000,
|
|
162
|
+
allowLateSubmission: effective.timeLimits?.allowLateSubmission,
|
|
163
|
+
};
|
|
164
|
+
}
|
|
100
165
|
hasAnyResponse(responses) {
|
|
101
166
|
for (const v of Object.values(responses)) {
|
|
102
167
|
if (v == null)
|
|
@@ -116,6 +181,37 @@ export class AssessmentPlayer {
|
|
|
116
181
|
}
|
|
117
182
|
return false;
|
|
118
183
|
}
|
|
184
|
+
restoreItemSessionsFromState(state) {
|
|
185
|
+
const restoredStates = new Map();
|
|
186
|
+
for (const item of this.items) {
|
|
187
|
+
const persisted = state.itemSessionStates?.[item.identifier];
|
|
188
|
+
if (persisted) {
|
|
189
|
+
restoredStates.set(item.identifier, {
|
|
190
|
+
itemIdentifier: item.identifier,
|
|
191
|
+
attemptCount: Math.max(0, persisted.attemptCount),
|
|
192
|
+
isAnswered: persisted.isAnswered,
|
|
193
|
+
isSubmitted: persisted.isSubmitted,
|
|
194
|
+
lastSubmissionTime: persisted.lastSubmissionTime,
|
|
195
|
+
});
|
|
196
|
+
continue;
|
|
197
|
+
}
|
|
198
|
+
const responses = state.itemResponses?.[item.identifier] ?? {};
|
|
199
|
+
const isSubmitted = Boolean(state.itemScores?.[item.identifier]);
|
|
200
|
+
restoredStates.set(item.identifier, {
|
|
201
|
+
itemIdentifier: item.identifier,
|
|
202
|
+
attemptCount: isSubmitted ? 1 : 0,
|
|
203
|
+
isAnswered: this.hasAnyResponse(responses),
|
|
204
|
+
isSubmitted,
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
this.sessionController.restoreStates(restoredStates);
|
|
208
|
+
}
|
|
209
|
+
getItemSessionStateSnapshot() {
|
|
210
|
+
return Object.fromEntries([...this.sessionController.getAllStates().entries()].map(([itemIdentifier, state]) => [
|
|
211
|
+
itemIdentifier,
|
|
212
|
+
{ ...state },
|
|
213
|
+
]));
|
|
214
|
+
}
|
|
119
215
|
flattenItems(assessment) {
|
|
120
216
|
const out = [];
|
|
121
217
|
const testParts = assessment.testParts || [];
|
|
@@ -189,6 +285,7 @@ export class AssessmentPlayer {
|
|
|
189
285
|
title: q.section.title,
|
|
190
286
|
required: q.item.required,
|
|
191
287
|
itemXml: q.item.itemXml,
|
|
288
|
+
deliveryContext: q.item.deliveryContext,
|
|
192
289
|
};
|
|
193
290
|
}
|
|
194
291
|
getCurrentRubricBlocks() {
|
|
@@ -219,11 +316,11 @@ export class AssessmentPlayer {
|
|
|
219
316
|
const prev = (this.state.itemResponses?.[itemIdentifier] || {});
|
|
220
317
|
const next = { ...prev, [responseId]: value };
|
|
221
318
|
this.state.itemResponses[itemIdentifier] = next;
|
|
319
|
+
this.sessionController.markAnswered(itemIdentifier, this.hasAnyResponse(next));
|
|
222
320
|
// If this is the active item, keep the live response state + UI hints in sync.
|
|
223
321
|
const active = this.items[this.currentItemIndex];
|
|
224
322
|
if (active?.identifier === itemIdentifier) {
|
|
225
323
|
this.responses = next;
|
|
226
|
-
this.sessionController.markAnswered(itemIdentifier, this.hasAnyResponse(this.responses));
|
|
227
324
|
this.currentItemPlayer?.setResponses(this.responses);
|
|
228
325
|
this.notifyResponseChange();
|
|
229
326
|
}
|
|
@@ -235,17 +332,49 @@ export class AssessmentPlayer {
|
|
|
235
332
|
getResponses() {
|
|
236
333
|
return { ...this.responses };
|
|
237
334
|
}
|
|
335
|
+
saveCurrentItemSession() {
|
|
336
|
+
const q = this.items[this.currentItemIndex];
|
|
337
|
+
if (!q || !this.currentItemPlayer)
|
|
338
|
+
return null;
|
|
339
|
+
this.currentItemPlayer.setResponses(this.responses);
|
|
340
|
+
const result = this.currentItemPlayer.suspendAttempt();
|
|
341
|
+
this.state.itemSessions = {
|
|
342
|
+
...(this.state.itemSessions ?? {}),
|
|
343
|
+
[q.identifier]: result.sessionState,
|
|
344
|
+
};
|
|
345
|
+
this.state.itemResponses[q.identifier] = this.responses;
|
|
346
|
+
this.state.timing.itemTimes[q.identifier] = result.duration;
|
|
347
|
+
this.sessionController.markAnswered(q.identifier, this.hasAnyResponse(this.responses));
|
|
348
|
+
return result.sessionState;
|
|
349
|
+
}
|
|
350
|
+
endItemSessionForSubmit(q, responses, itemSession) {
|
|
351
|
+
const player = new Player({
|
|
352
|
+
itemXml: q.item.itemXml,
|
|
353
|
+
role: q.item.role,
|
|
354
|
+
i18nProvider: this.i18nProvider,
|
|
355
|
+
pnp: this.config.pnp,
|
|
356
|
+
security: this.config.security,
|
|
357
|
+
deliveryContext: q.item.deliveryContext,
|
|
358
|
+
});
|
|
359
|
+
if (itemSession) {
|
|
360
|
+
player.restoreItemSession(itemSession);
|
|
361
|
+
}
|
|
362
|
+
player.setResponses(responses);
|
|
363
|
+
return player.endAttempt().sessionState;
|
|
364
|
+
}
|
|
238
365
|
/**
|
|
239
366
|
* Get the current session state snapshot (client-side view).
|
|
240
367
|
* Note: backend remains authoritative; this is intended for simple save/resume.
|
|
241
368
|
*/
|
|
242
|
-
getState() {
|
|
369
|
+
getState(options = {}) {
|
|
243
370
|
// Shallow clone to avoid accidental external mutation.
|
|
244
371
|
return {
|
|
245
372
|
...this.state,
|
|
246
373
|
visitedItems: [...this.state.visitedItems],
|
|
247
374
|
itemResponses: { ...this.state.itemResponses },
|
|
248
375
|
itemScores: this.state.itemScores ? { ...this.state.itemScores } : undefined,
|
|
376
|
+
itemSessions: options.includeItemSessions && this.state.itemSessions ? { ...this.state.itemSessions } : undefined,
|
|
377
|
+
itemSessionStates: this.getItemSessionStateSnapshot(),
|
|
249
378
|
timing: {
|
|
250
379
|
...this.state.timing,
|
|
251
380
|
itemTimes: { ...this.state.timing.itemTimes },
|
|
@@ -262,6 +391,7 @@ export class AssessmentPlayer {
|
|
|
262
391
|
.map((id) => this.items.findIndex((q) => q.identifier === id))
|
|
263
392
|
.filter((i) => i >= 0);
|
|
264
393
|
this.navigationManager.restoreState(visitedIdx);
|
|
394
|
+
this.restoreItemSessionsFromState(state);
|
|
265
395
|
// Rehydrate itemResults from scores if present, so submit() can behave sensibly.
|
|
266
396
|
this.itemResults.clear();
|
|
267
397
|
if (state.itemScores) {
|
|
@@ -277,29 +407,42 @@ export class AssessmentPlayer {
|
|
|
277
407
|
const currentId = state.currentItemIdentifier;
|
|
278
408
|
const idx = currentId ? this.items.findIndex((q) => q.identifier === currentId) : -1;
|
|
279
409
|
if (idx >= 0) {
|
|
280
|
-
await this.navigateTo(idx);
|
|
410
|
+
await this.navigateTo(idx, { restoring: true });
|
|
281
411
|
}
|
|
282
412
|
else if (this.items.length > 0) {
|
|
283
|
-
await this.navigateTo(0);
|
|
413
|
+
await this.navigateTo(0, { restoring: true });
|
|
284
414
|
}
|
|
285
415
|
}
|
|
286
|
-
async navigateTo(index) {
|
|
416
|
+
async navigateTo(index, options = {}) {
|
|
287
417
|
if (index < 0 || index >= this.items.length)
|
|
288
418
|
throw new Error(`Invalid item index: ${index}`);
|
|
289
419
|
// Enforce navigation rules (UI hints, still backend-authoritative for real deployments).
|
|
290
|
-
if (this.currentItemIndex >= 0 && !this.navigationManager.canNavigateTo(index, this.currentItemIndex)) {
|
|
420
|
+
if (!options.restoring && this.currentItemIndex >= 0 && !this.navigationManager.canNavigateTo(index, this.currentItemIndex)) {
|
|
291
421
|
if (this.navigationManager.getMode() === 'linear' && index > this.currentItemIndex + 1) {
|
|
292
422
|
throw new Error('In linear navigation mode, you can only move to the next question.');
|
|
293
423
|
}
|
|
294
424
|
throw new Error('Navigation is not allowed.');
|
|
295
425
|
}
|
|
296
426
|
const target = this.items[index];
|
|
297
|
-
if (target && !this.sessionController.canReview(target.identifier)) {
|
|
427
|
+
if (!options.restoring && target && !this.sessionController.canReview(target.identifier)) {
|
|
298
428
|
throw new Error('You cannot go back to previous questions in this assessment.');
|
|
299
429
|
}
|
|
430
|
+
const currentItem = this.items[this.currentItemIndex];
|
|
431
|
+
const currentSessionStatus = currentItem ? this.state.itemSessions?.[currentItem.identifier]?.lifecycleStatus : undefined;
|
|
432
|
+
if (!options.restoring &&
|
|
433
|
+
this.currentItemIndex >= 0 &&
|
|
434
|
+
this.currentItemIndex !== index &&
|
|
435
|
+
currentSessionStatus !== 'closed') {
|
|
436
|
+
this.saveCurrentItemSession();
|
|
437
|
+
}
|
|
438
|
+
if (currentItem && this.currentItemIndex !== index) {
|
|
439
|
+
this.timeManager?.endItem(currentItem.identifier);
|
|
440
|
+
}
|
|
300
441
|
this.currentItemIndex = index;
|
|
301
442
|
const q = this.items[index];
|
|
302
443
|
this.state.currentItemIdentifier = q.identifier;
|
|
444
|
+
this.timeManager?.startSection(q.section.identifier);
|
|
445
|
+
this.timeManager?.startItem(q.identifier);
|
|
303
446
|
// Apply three-level itemSessionControl fallback for this item's section (S1).
|
|
304
447
|
const effectiveControl = this.getEffectiveItemSessionControl(q);
|
|
305
448
|
if (effectiveControl) {
|
|
@@ -308,12 +451,22 @@ export class AssessmentPlayer {
|
|
|
308
451
|
// Restore responses
|
|
309
452
|
this.responses = { ...(this.state.itemResponses[q.identifier] || {}) };
|
|
310
453
|
// Create item player
|
|
454
|
+
this.currentItemPlayer?.destroy();
|
|
311
455
|
this.currentItemPlayer = new Player({
|
|
312
456
|
itemXml: q.item.itemXml,
|
|
313
457
|
role: q.item.role,
|
|
314
458
|
i18nProvider: this.i18nProvider,
|
|
459
|
+
pnp: this.config.pnp,
|
|
460
|
+
security: this.config.security,
|
|
461
|
+
deliveryContext: q.item.deliveryContext,
|
|
315
462
|
});
|
|
316
|
-
this.
|
|
463
|
+
const restoredItemSession = this.state.itemSessions?.[q.identifier];
|
|
464
|
+
if (restoredItemSession) {
|
|
465
|
+
this.currentItemPlayer.restoreItemSession(restoredItemSession);
|
|
466
|
+
}
|
|
467
|
+
else {
|
|
468
|
+
this.currentItemPlayer.setResponses(this.responses);
|
|
469
|
+
}
|
|
317
470
|
this.notifyItemChange();
|
|
318
471
|
this.notifySectionChange();
|
|
319
472
|
}
|
|
@@ -357,17 +510,39 @@ export class AssessmentPlayer {
|
|
|
357
510
|
if (!q)
|
|
358
511
|
throw new Error('No current item');
|
|
359
512
|
const submittedAt = Date.now();
|
|
513
|
+
let itemSession;
|
|
514
|
+
if (this.currentItemPlayer) {
|
|
515
|
+
this.currentItemPlayer.setResponses(this.responses);
|
|
516
|
+
const attempt = this.currentItemPlayer.endAttempt({
|
|
517
|
+
validateResponses: this.sessionController.mustValidateResponses(),
|
|
518
|
+
});
|
|
519
|
+
if (attempt.validation && !attempt.validation.valid) {
|
|
520
|
+
throw new Error(attempt.validation.issues[0]?.message || 'Submit failed: invalid response');
|
|
521
|
+
}
|
|
522
|
+
itemSession = attempt.sessionState;
|
|
523
|
+
this.state.itemSessions = {
|
|
524
|
+
...(this.state.itemSessions ?? {}),
|
|
525
|
+
[q.identifier]: itemSession,
|
|
526
|
+
};
|
|
527
|
+
}
|
|
360
528
|
const res = await this.backend.submitResponses({
|
|
361
529
|
sessionId: this.sessionId,
|
|
362
530
|
itemIdentifier: q.identifier,
|
|
363
531
|
responses: this.responses,
|
|
364
532
|
submittedAt,
|
|
533
|
+
timeSpent: itemSession?.duration,
|
|
534
|
+
timing: this.getSubmitTimingEvidence(q, itemSession?.duration ?? 0),
|
|
535
|
+
itemSession: this.config.sendItemSessionToBackend ? itemSession : undefined,
|
|
365
536
|
});
|
|
366
537
|
if (!res.success || !res.result) {
|
|
367
538
|
throw new Error(res.error || 'Submit failed');
|
|
368
539
|
}
|
|
369
540
|
if (res.updatedState) {
|
|
541
|
+
const localItemSessions = this.state.itemSessions;
|
|
370
542
|
this.state = res.updatedState;
|
|
543
|
+
if (localItemSessions) {
|
|
544
|
+
this.state.itemSessions = { ...(this.state.itemSessions ?? {}), ...localItemSessions };
|
|
545
|
+
}
|
|
371
546
|
}
|
|
372
547
|
else {
|
|
373
548
|
// Minimal state update when backend doesn't return full state.
|
|
@@ -376,6 +551,9 @@ export class AssessmentPlayer {
|
|
|
376
551
|
if (!this.state.visitedItems.includes(q.identifier))
|
|
377
552
|
this.state.visitedItems.push(q.identifier);
|
|
378
553
|
this.state.itemResponses[q.identifier] = this.responses;
|
|
554
|
+
if (itemSession) {
|
|
555
|
+
this.state.itemSessions = { ...(this.state.itemSessions ?? {}), [q.identifier]: itemSession };
|
|
556
|
+
}
|
|
379
557
|
}
|
|
380
558
|
const itemResult = {
|
|
381
559
|
itemIdentifier: q.identifier,
|
|
@@ -456,21 +634,28 @@ export class AssessmentPlayer {
|
|
|
456
634
|
// For simultaneous submission, ensure all items are submitted before finalize so
|
|
457
635
|
// the backend can compute a complete test score.
|
|
458
636
|
if (this.assessment.submissionMode === 'simultaneous') {
|
|
637
|
+
this.saveCurrentItemSession();
|
|
459
638
|
// Preserve client-collected responses across backend state updates.
|
|
460
639
|
// Some backend adapters return an updatedState snapshot that may only include
|
|
461
640
|
// responses for items that have been submitted so far, which would otherwise
|
|
462
641
|
// wipe out responses for later items during this loop.
|
|
463
642
|
const allItemResponses = { ...(this.state.itemResponses || {}) };
|
|
643
|
+
const allItemSessions = { ...(this.state.itemSessions || {}) };
|
|
464
644
|
for (const q of this.items) {
|
|
465
645
|
if (this.itemResults.has(q.identifier))
|
|
466
646
|
continue;
|
|
467
647
|
const submittedAt = Date.now();
|
|
468
648
|
const responsesForItem = (allItemResponses?.[q.identifier] || {});
|
|
649
|
+
const itemSession = this.endItemSessionForSubmit(q, responsesForItem, allItemSessions[q.identifier]);
|
|
650
|
+
allItemSessions[q.identifier] = itemSession;
|
|
469
651
|
const res = await this.backend.submitResponses({
|
|
470
652
|
sessionId: this.sessionId,
|
|
471
653
|
itemIdentifier: q.identifier,
|
|
472
654
|
responses: responsesForItem,
|
|
473
655
|
submittedAt,
|
|
656
|
+
timeSpent: itemSession?.duration,
|
|
657
|
+
timing: this.getSubmitTimingEvidence(q, itemSession?.duration ?? 0),
|
|
658
|
+
itemSession: this.config.sendItemSessionToBackend ? itemSession : undefined,
|
|
474
659
|
});
|
|
475
660
|
if (!res.success || !res.result) {
|
|
476
661
|
throw new Error(res.error || `Submit failed for item ${q.identifier}`);
|
|
@@ -479,6 +664,7 @@ export class AssessmentPlayer {
|
|
|
479
664
|
this.state = res.updatedState;
|
|
480
665
|
// Restore full response map captured on the client.
|
|
481
666
|
this.state.itemResponses = allItemResponses;
|
|
667
|
+
this.state.itemSessions = allItemSessions;
|
|
482
668
|
}
|
|
483
669
|
else {
|
|
484
670
|
this.state.itemScores = this.state.itemScores || {};
|
|
@@ -486,6 +672,9 @@ export class AssessmentPlayer {
|
|
|
486
672
|
if (!this.state.visitedItems.includes(q.identifier))
|
|
487
673
|
this.state.visitedItems.push(q.identifier);
|
|
488
674
|
this.state.itemResponses[q.identifier] = responsesForItem;
|
|
675
|
+
if (itemSession) {
|
|
676
|
+
this.state.itemSessions = { ...(this.state.itemSessions ?? {}), [q.identifier]: itemSession };
|
|
677
|
+
}
|
|
489
678
|
}
|
|
490
679
|
this.itemResults.set(q.identifier, {
|
|
491
680
|
itemIdentifier: q.identifier,
|
|
@@ -611,6 +800,8 @@ export class AssessmentPlayer {
|
|
|
611
800
|
return () => this.timeTickListeners.delete(listener);
|
|
612
801
|
}
|
|
613
802
|
destroy() {
|
|
803
|
+
this.timeManager?.destroy();
|
|
804
|
+
this.currentItemPlayer?.destroy();
|
|
614
805
|
this.itemChangeListeners.clear();
|
|
615
806
|
this.sectionChangeListeners.clear();
|
|
616
807
|
this.responseChangeListeners.clear();
|
|
@@ -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;AAsBH,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;AAmD3B;;;;;;;;;;;GAWG;AACH,qBAAa,uBAAwB,YAAW,cAAc;IAC7D,OAAO,CAAC,qBAAqB,CAA4C;IAEzE;;;;;;OAMG;IACI,kBAAkB,CAAC,YAAY,EAAE,MAAM,EAAE,UAAU,EAAE,gBAAgB;IAI5E,OAAO,CAAC,aAAa;IAIrB,OAAO,CAAC,cAAc;IAgBtB;;OAEG;IACG,WAAW,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAuD5E;;OAEG;IACG,eAAe,CAAC,OAAO,EAAE,sBAAsB,GAAG,OAAO,CAAC,uBAAuB,CAAC;IA+HxF;;OAEG;IACG,SAAS,CAAC,OAAO,EAAE,0BAA0B,GAAG,OAAO,CAAC,2BAA2B,CAAC;IAmB1F;;OAEG;IACG,kBAAkB,CACvB,OAAO,EAAE,yBAAyB,GAChC,OAAO,CAAC,0BAA0B,CAAC;IAkCtC;;;OAGG;IACH,OAAO,CAAC,oBAAo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