@pie-qti/assessment-player 0.1.1 → 0.1.4
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 +14 -7
- package/dist/core/AssessmentPlayer.d.ts.map +1 -1
- package/dist/core/AssessmentPlayer.js +33 -34
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/integration/ReferenceBackendAdapter.d.ts +2 -2
- package/dist/integration/ReferenceBackendAdapter.d.ts.map +1 -1
- package/dist/integration/ReferenceBackendAdapter.js +5 -5
- package/dist/integration/api-contract.d.ts +16 -16
- package/dist/integration/api-contract.d.ts.map +1 -1
- package/dist/integration/index.d.ts +1 -1
- package/dist/integration/index.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +100 -80
- package/src/components/AssessmentShell.svelte +8 -8
- package/src/components/ItemRenderer.svelte +8 -8
- package/src/components/NavigationBar.svelte +3 -1
- package/src/components/RubricDisplay.svelte +2 -2
- package/src/core/AssessmentPlayer.ts +51 -44
- package/src/index.ts +1 -1
- package/src/integration/ReferenceBackendAdapter.ts +13 -13
- package/src/integration/api-contract.ts +16 -16
- package/src/integration/index.ts +5 -5
- package/src/types/index.ts +1 -1
- package/.turbo/turbo-build.log +0 -1
- package/BACKEND-INTEGRATION.md +0 -620
- package/CHANGELOG.md +0 -11
- package/EXTENSIBILITY.md +0 -551
- package/svelte.config.js +0 -8
- package/tests/ReferenceBackendAdapter.spec.ts +0 -309
- package/tests/setup.ts +0 -103
- package/tests/smoke.test.ts +0 -7
- package/tsconfig.json +0 -20
- package/tsconfig.svelte.json +0 -10
package/package.json
CHANGED
|
@@ -1,82 +1,102 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
2
|
+
"name": "@pie-qti/assessment-player",
|
|
3
|
+
"version": "0.1.4",
|
|
4
|
+
"description": "QTI Assessment Player supporting QTI 2.x and 3.0 - Multi-item test player with navigation, sections, and rubric blocks",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "tsc",
|
|
10
|
+
"test": "bun test --preload ./tests/setup.ts",
|
|
11
|
+
"typecheck": "tsc --noEmit",
|
|
12
|
+
"check": "svelte-check --tsconfig ./tsconfig.svelte.json",
|
|
13
|
+
"lint": "biome check .",
|
|
14
|
+
"lint:fix": "biome check --write .",
|
|
15
|
+
"format": "biome format --write ."
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"qti",
|
|
19
|
+
"qti2",
|
|
20
|
+
"qti3",
|
|
21
|
+
"qti 2.x",
|
|
22
|
+
"qti 3.0",
|
|
23
|
+
"assessment",
|
|
24
|
+
"test",
|
|
25
|
+
"player",
|
|
26
|
+
"navigation",
|
|
27
|
+
"e-learning"
|
|
28
|
+
],
|
|
29
|
+
"license": "MIT",
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@pie-qti/default-components": "0.1.4",
|
|
32
|
+
"@pie-qti/i18n": "0.1.4",
|
|
33
|
+
"@pie-qti/item-player": "0.1.4",
|
|
34
|
+
"@pie-qti/qti-processing": "0.1.4",
|
|
35
|
+
"node-html-parser": "^7.0.2"
|
|
36
|
+
},
|
|
37
|
+
"peerDependencies": {
|
|
38
|
+
"svelte": "^5.54.0"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@biomejs/biome": "^2.4.8",
|
|
42
|
+
"@types/node": "^25.0.3",
|
|
43
|
+
"svelte": "^5.54.0",
|
|
44
|
+
"svelte-check": "^4.3.5",
|
|
45
|
+
"typescript": "^5.9.3"
|
|
46
|
+
},
|
|
47
|
+
"exports": {
|
|
48
|
+
".": {
|
|
49
|
+
"types": "./dist/index.d.ts",
|
|
50
|
+
"import": "./dist/index.js"
|
|
51
|
+
},
|
|
52
|
+
"./integration": {
|
|
53
|
+
"types": "./dist/integration/index.d.ts",
|
|
54
|
+
"import": "./dist/integration/index.js"
|
|
55
|
+
},
|
|
56
|
+
"./components": {
|
|
57
|
+
"types": "./src/components/index.ts",
|
|
58
|
+
"import": "./src/components/index.ts",
|
|
59
|
+
"svelte": "./src/components/index.ts"
|
|
60
|
+
},
|
|
61
|
+
"./components/AssessmentShell.svelte": {
|
|
62
|
+
"import": "./src/components/AssessmentShell.svelte",
|
|
63
|
+
"svelte": "./src/components/AssessmentShell.svelte"
|
|
64
|
+
},
|
|
65
|
+
"./components/NavigationBar.svelte": {
|
|
66
|
+
"import": "./src/components/NavigationBar.svelte",
|
|
67
|
+
"svelte": "./src/components/NavigationBar.svelte"
|
|
68
|
+
},
|
|
69
|
+
"./components/SectionMenu.svelte": {
|
|
70
|
+
"import": "./src/components/SectionMenu.svelte",
|
|
71
|
+
"svelte": "./src/components/SectionMenu.svelte"
|
|
72
|
+
},
|
|
73
|
+
"./components/RubricDisplay.svelte": {
|
|
74
|
+
"import": "./src/components/RubricDisplay.svelte",
|
|
75
|
+
"svelte": "./src/components/RubricDisplay.svelte"
|
|
76
|
+
},
|
|
77
|
+
"./components/ItemRenderer.svelte": {
|
|
78
|
+
"import": "./src/components/ItemRenderer.svelte",
|
|
79
|
+
"svelte": "./src/components/ItemRenderer.svelte"
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
"repository": {
|
|
83
|
+
"type": "git",
|
|
84
|
+
"url": "https://github.com/pie-framework/pie-qti.git",
|
|
85
|
+
"directory": "packages/assessment-player"
|
|
86
|
+
},
|
|
87
|
+
"homepage": "https://github.com/pie-framework/pie-qti/tree/master/packages/assessment-player",
|
|
88
|
+
"bugs": {
|
|
89
|
+
"url": "https://github.com/pie-framework/pie-qti/issues"
|
|
90
|
+
},
|
|
91
|
+
"publishConfig": {
|
|
92
|
+
"access": "public"
|
|
93
|
+
},
|
|
94
|
+
"sideEffects": false,
|
|
95
|
+
"engines": {
|
|
96
|
+
"node": ">=20.19.0"
|
|
97
|
+
},
|
|
98
|
+
"files": [
|
|
99
|
+
"dist",
|
|
100
|
+
"src"
|
|
101
|
+
]
|
|
82
102
|
}
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
currentSection: undefined,
|
|
44
44
|
totalSections: undefined,
|
|
45
45
|
});
|
|
46
|
-
let
|
|
46
|
+
let currentItem = $state<any>(null);
|
|
47
47
|
let currentRubricBlocks = $state<any[]>([]);
|
|
48
48
|
let currentResponses = $state<Record<string, unknown>>({});
|
|
49
49
|
let sections = $state<any[]>([]);
|
|
@@ -162,7 +162,7 @@
|
|
|
162
162
|
if (!player) return;
|
|
163
163
|
|
|
164
164
|
navState = player.getNavigationState();
|
|
165
|
-
|
|
165
|
+
currentItem = player.getCurrentItem();
|
|
166
166
|
currentRubricBlocks = player.getCurrentRubricBlocks();
|
|
167
167
|
currentResponses = player.getResponses();
|
|
168
168
|
}
|
|
@@ -257,8 +257,8 @@
|
|
|
257
257
|
|
|
258
258
|
function handleResponseChange(responseId: string, value: unknown) {
|
|
259
259
|
if (!player) return;
|
|
260
|
-
if (
|
|
261
|
-
player.updateResponseForItem(
|
|
260
|
+
if (currentItem?.identifier) {
|
|
261
|
+
player.updateResponseForItem(currentItem.identifier, responseId, value);
|
|
262
262
|
} else {
|
|
263
263
|
player.updateResponse(responseId, value);
|
|
264
264
|
}
|
|
@@ -387,9 +387,9 @@
|
|
|
387
387
|
<RubricDisplay blocks={nonPassageRubricBlocks} {typeset} />
|
|
388
388
|
{/if}
|
|
389
389
|
|
|
390
|
-
{#if
|
|
390
|
+
{#if currentItem}
|
|
391
391
|
<ItemRenderer
|
|
392
|
-
|
|
392
|
+
itemRef={currentItem}
|
|
393
393
|
responses={currentResponses}
|
|
394
394
|
role={config.role || 'candidate'}
|
|
395
395
|
extendedTextEditor={config.extendedTextEditor || 'tiptap'}
|
|
@@ -407,9 +407,9 @@
|
|
|
407
407
|
{/if}
|
|
408
408
|
|
|
409
409
|
<!-- Current item -->
|
|
410
|
-
{#if
|
|
410
|
+
{#if currentItem}
|
|
411
411
|
<ItemRenderer
|
|
412
|
-
|
|
412
|
+
itemRef={currentItem}
|
|
413
413
|
responses={currentResponses}
|
|
414
414
|
role={config.role || 'candidate'}
|
|
415
415
|
onResponseChange={handleResponseChange}
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
import { Player, type PlayerSecurityConfig, type QTIRole } from '@pie-qti/item-player';
|
|
7
7
|
import type { I18nProvider } from '@pie-qti/i18n';
|
|
8
8
|
import { onMount } from 'svelte';
|
|
9
|
-
import type {
|
|
9
|
+
import type { ItemRef } from '../types/index.js';
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* Ensure default interaction web components are registered (browser-only).
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
});
|
|
31
31
|
|
|
32
32
|
interface Props {
|
|
33
|
-
|
|
33
|
+
itemRef: ItemRef;
|
|
34
34
|
role?: QTIRole;
|
|
35
35
|
extendedTextEditor?: string;
|
|
36
36
|
/** Responses for the current item (keyed by responseIdentifier). */
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
const {
|
|
48
|
-
|
|
48
|
+
itemRef,
|
|
49
49
|
role = 'candidate',
|
|
50
50
|
extendedTextEditor: _extendedTextEditor,
|
|
51
51
|
responses = {},
|
|
@@ -55,15 +55,15 @@
|
|
|
55
55
|
security,
|
|
56
56
|
}: Props = $props();
|
|
57
57
|
|
|
58
|
-
// Derive player from
|
|
58
|
+
// Derive player from itemRef
|
|
59
59
|
let playerData = $derived.by(() => {
|
|
60
|
-
if (!
|
|
60
|
+
if (!itemRef.itemXml) {
|
|
61
61
|
return { player: null, error: 'No item XML provided' };
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
try {
|
|
65
65
|
const newPlayer = new Player({
|
|
66
|
-
itemXml:
|
|
66
|
+
itemXml: itemRef.itemXml,
|
|
67
67
|
role,
|
|
68
68
|
security,
|
|
69
69
|
});
|
|
@@ -115,9 +115,9 @@
|
|
|
115
115
|
</div>
|
|
116
116
|
{:else}
|
|
117
117
|
<div class="item-container">
|
|
118
|
-
{#if
|
|
118
|
+
{#if itemRef.title}
|
|
119
119
|
<div class="item-header">
|
|
120
|
-
<h3 class="text-lg font-semibold mb-4">{
|
|
120
|
+
<h3 class="text-lg font-semibold mb-4">{itemRef.title}</h3>
|
|
121
121
|
</div>
|
|
122
122
|
{/if}
|
|
123
123
|
|
|
@@ -56,6 +56,7 @@
|
|
|
56
56
|
<div class="navigation-buttons">
|
|
57
57
|
<button
|
|
58
58
|
class="btn btn-outline"
|
|
59
|
+
data-testid="assessment-prev"
|
|
59
60
|
onclick={() => onPrevious?.()}
|
|
60
61
|
disabled={!navState.canPrevious || navState.isLoading}
|
|
61
62
|
>
|
|
@@ -75,13 +76,14 @@
|
|
|
75
76
|
|
|
76
77
|
{#if navState.currentIndex === navState.totalItems - 1}
|
|
77
78
|
<!-- Submit button on last item -->
|
|
78
|
-
<button class="btn btn-primary" onclick={() => onSubmit?.()} disabled={navState.isLoading}>
|
|
79
|
+
<button class="btn btn-primary" data-testid="assessment-submit" onclick={() => onSubmit?.()} disabled={navState.isLoading}>
|
|
79
80
|
{translations.submit}
|
|
80
81
|
</button>
|
|
81
82
|
{:else}
|
|
82
83
|
<!-- Next button -->
|
|
83
84
|
<button
|
|
84
85
|
class="btn btn-primary"
|
|
86
|
+
data-testid="assessment-next"
|
|
85
87
|
onclick={() => onNext?.()}
|
|
86
88
|
disabled={!navState.canNext || navState.isLoading}
|
|
87
89
|
>
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import { typesetAction } from '@pie-qti/default-components/shared';
|
|
3
3
|
import type { I18nProvider } from '@pie-qti/i18n';
|
|
4
|
-
import type {
|
|
4
|
+
import type { AssessmentRubricBlock } from '../integration/api-contract.js';
|
|
5
5
|
|
|
6
6
|
interface Props {
|
|
7
|
-
blocks:
|
|
7
|
+
blocks: AssessmentRubricBlock[];
|
|
8
8
|
collapsed?: boolean;
|
|
9
9
|
i18n?: I18nProvider;
|
|
10
10
|
/** Math typesetting function (KaTeX, MathJax, etc.) */
|
|
@@ -11,17 +11,18 @@
|
|
|
11
11
|
import type { QTIRole } from '@pie-qti/item-player';
|
|
12
12
|
import { Player } from '@pie-qti/item-player';
|
|
13
13
|
import type {
|
|
14
|
+
AssessmentRubricBlock,
|
|
15
|
+
AssessmentSessionState,
|
|
16
|
+
AssessmentScoringResult,
|
|
14
17
|
BackendAdapter,
|
|
15
18
|
FinalizeAssessmentResponse,
|
|
16
19
|
InitSessionRequest,
|
|
17
20
|
InitSessionResponse,
|
|
18
|
-
ScoringResult,
|
|
19
21
|
SecureAssessment,
|
|
20
22
|
SecureItemRef,
|
|
21
23
|
SecureSection,
|
|
22
24
|
SecureTestPart,
|
|
23
25
|
SessionId,
|
|
24
|
-
SessionState,
|
|
25
26
|
} from '../integration/api-contract.js';
|
|
26
27
|
import type {
|
|
27
28
|
AssessmentResults,
|
|
@@ -64,7 +65,7 @@ export interface BackendAssessmentPlayerConfig {
|
|
|
64
65
|
onComplete?: () => void;
|
|
65
66
|
}
|
|
66
67
|
|
|
67
|
-
type
|
|
68
|
+
type FlatItem = {
|
|
68
69
|
identifier: string;
|
|
69
70
|
item: SecureItemRef;
|
|
70
71
|
section: SecureSection;
|
|
@@ -73,6 +74,13 @@ type FlatQuestion = {
|
|
|
73
74
|
sectionIndex: number;
|
|
74
75
|
};
|
|
75
76
|
|
|
77
|
+
type CurrentItemView = {
|
|
78
|
+
identifier: string;
|
|
79
|
+
title?: string;
|
|
80
|
+
required?: boolean;
|
|
81
|
+
itemXml: string;
|
|
82
|
+
};
|
|
83
|
+
|
|
76
84
|
export class AssessmentPlayer {
|
|
77
85
|
public static async create(config: BackendAssessmentPlayerConfig): Promise<AssessmentPlayer> {
|
|
78
86
|
const init = await config.backend.initSession(config.initSession);
|
|
@@ -82,14 +90,14 @@ export class AssessmentPlayer {
|
|
|
82
90
|
private backend: BackendAdapter;
|
|
83
91
|
private sessionId: SessionId;
|
|
84
92
|
private assessment: SecureAssessment;
|
|
85
|
-
private state:
|
|
93
|
+
private state: AssessmentSessionState;
|
|
86
94
|
private i18nProvider: any; // I18nProvider from @pie-qti/i18n
|
|
87
95
|
|
|
88
96
|
private navigationManager: NavigationManager;
|
|
89
97
|
private sessionController: ItemSessionController;
|
|
90
98
|
private timeManager: TimeManager | null = null;
|
|
91
99
|
|
|
92
|
-
private
|
|
100
|
+
private items: FlatItem[] = [];
|
|
93
101
|
private currentItemIndex = -1;
|
|
94
102
|
private currentItemPlayer: Player | null = null;
|
|
95
103
|
private responses: Record<string, unknown> = {};
|
|
@@ -118,19 +126,19 @@ export class AssessmentPlayer {
|
|
|
118
126
|
itemResponses: {},
|
|
119
127
|
itemScores: {},
|
|
120
128
|
timing: { startedAt: Date.now(), itemTimes: {}, totalTime: 0 },
|
|
121
|
-
} as
|
|
129
|
+
} as AssessmentSessionState);
|
|
122
130
|
|
|
123
|
-
this.
|
|
131
|
+
this.items = this.flattenItems(this.assessment);
|
|
124
132
|
|
|
125
133
|
const navigationMode = this.assessment.navigationMode || 'nonlinear';
|
|
126
|
-
this.navigationManager = new NavigationManager(navigationMode, this.
|
|
134
|
+
this.navigationManager = new NavigationManager(navigationMode, this.items.length);
|
|
127
135
|
|
|
128
136
|
// Item session control is a UI hint; backend remains authoritative.
|
|
129
137
|
const itemSessionControl = this.assessment.testParts?.[0]?.itemSessionControl;
|
|
130
138
|
this.sessionController = new ItemSessionController(itemSessionControl);
|
|
131
139
|
|
|
132
140
|
// Initialize per-item session state so itemSessionControl checks work immediately.
|
|
133
|
-
for (const q of this.
|
|
141
|
+
for (const q of this.items) {
|
|
134
142
|
this.sessionController.initializeItem(q.identifier);
|
|
135
143
|
}
|
|
136
144
|
|
|
@@ -147,7 +155,7 @@ export class AssessmentPlayer {
|
|
|
147
155
|
|
|
148
156
|
// Restore to backend-provided current item if present
|
|
149
157
|
const startId = this.state.currentItemIdentifier;
|
|
150
|
-
const idx = startId ? this.
|
|
158
|
+
const idx = startId ? this.items.findIndex((q) => q.identifier === startId) : -1;
|
|
151
159
|
if (idx >= 0) {
|
|
152
160
|
this.navigateTo(idx).catch(() => {});
|
|
153
161
|
}
|
|
@@ -170,15 +178,15 @@ export class AssessmentPlayer {
|
|
|
170
178
|
return false;
|
|
171
179
|
}
|
|
172
180
|
|
|
173
|
-
private
|
|
174
|
-
const out:
|
|
181
|
+
private flattenItems(assessment: SecureAssessment): FlatItem[] {
|
|
182
|
+
const out: FlatItem[] = [];
|
|
175
183
|
const testParts = assessment.testParts || [];
|
|
176
184
|
let idx = 0;
|
|
177
185
|
let secIdx = 0;
|
|
178
186
|
|
|
179
187
|
for (const tp of testParts) {
|
|
180
188
|
for (const section of tp.sections || []) {
|
|
181
|
-
for (const item of section.
|
|
189
|
+
for (const item of section.assessmentItemRefs || []) {
|
|
182
190
|
out.push({
|
|
183
191
|
identifier: item.identifier,
|
|
184
192
|
item,
|
|
@@ -210,10 +218,10 @@ export class AssessmentPlayer {
|
|
|
210
218
|
}
|
|
211
219
|
|
|
212
220
|
public getNavigationState(): NavigationState {
|
|
213
|
-
const total = this.
|
|
221
|
+
const total = this.items.length;
|
|
214
222
|
const canPrevious = this.canPrevious();
|
|
215
223
|
const canNext = this.canNext();
|
|
216
|
-
const q = this.
|
|
224
|
+
const q = this.items[this.currentItemIndex];
|
|
217
225
|
const totalSections = this.getAllSections().length;
|
|
218
226
|
return {
|
|
219
227
|
currentIndex: this.currentItemIndex,
|
|
@@ -228,10 +236,9 @@ export class AssessmentPlayer {
|
|
|
228
236
|
};
|
|
229
237
|
}
|
|
230
238
|
|
|
231
|
-
public
|
|
232
|
-
const q = this.
|
|
239
|
+
public getCurrentItem(): CurrentItemView | null {
|
|
240
|
+
const q = this.items[this.currentItemIndex];
|
|
233
241
|
if (!q) return null;
|
|
234
|
-
// Keep the legacy QuestionRef-ish shape expected by ItemRenderer.svelte
|
|
235
242
|
return {
|
|
236
243
|
identifier: q.item.identifier,
|
|
237
244
|
title: q.section.title,
|
|
@@ -240,10 +247,10 @@ export class AssessmentPlayer {
|
|
|
240
247
|
};
|
|
241
248
|
}
|
|
242
249
|
|
|
243
|
-
public getCurrentRubricBlocks():
|
|
244
|
-
const q = this.
|
|
250
|
+
public getCurrentRubricBlocks(): AssessmentRubricBlock[] {
|
|
251
|
+
const q = this.items[this.currentItemIndex];
|
|
245
252
|
if (!q) return [];
|
|
246
|
-
return q.section.
|
|
253
|
+
return q.section.rubricBlocks || q.testPart.rubricBlocks || [];
|
|
247
254
|
}
|
|
248
255
|
|
|
249
256
|
public getVisibleFeedback(): Array<{ identifier: string; content: string; access: string }> {
|
|
@@ -252,7 +259,7 @@ export class AssessmentPlayer {
|
|
|
252
259
|
|
|
253
260
|
public updateResponse(responseId: string, value: unknown): void {
|
|
254
261
|
this.responses = { ...this.responses, [responseId]: value };
|
|
255
|
-
const q = this.
|
|
262
|
+
const q = this.items[this.currentItemIndex];
|
|
256
263
|
if (q) {
|
|
257
264
|
this.state.itemResponses[q.identifier] = this.responses as any;
|
|
258
265
|
this.sessionController.markAnswered(q.identifier, this.hasAnyResponse(this.responses));
|
|
@@ -272,7 +279,7 @@ export class AssessmentPlayer {
|
|
|
272
279
|
this.state.itemResponses[itemIdentifier] = next as any;
|
|
273
280
|
|
|
274
281
|
// If this is the active item, keep the live response state + UI hints in sync.
|
|
275
|
-
const active = this.
|
|
282
|
+
const active = this.items[this.currentItemIndex];
|
|
276
283
|
if (active?.identifier === itemIdentifier) {
|
|
277
284
|
this.responses = next;
|
|
278
285
|
this.sessionController.markAnswered(itemIdentifier, this.hasAnyResponse(this.responses));
|
|
@@ -293,7 +300,7 @@ export class AssessmentPlayer {
|
|
|
293
300
|
* Get the current session state snapshot (client-side view).
|
|
294
301
|
* Note: backend remains authoritative; this is intended for simple save/resume.
|
|
295
302
|
*/
|
|
296
|
-
public getState():
|
|
303
|
+
public getState(): AssessmentSessionState {
|
|
297
304
|
// Shallow clone to avoid accidental external mutation.
|
|
298
305
|
return {
|
|
299
306
|
...this.state,
|
|
@@ -310,12 +317,12 @@ export class AssessmentPlayer {
|
|
|
310
317
|
/**
|
|
311
318
|
* Restore a previously saved session state.
|
|
312
319
|
*/
|
|
313
|
-
public async restoreState(state:
|
|
320
|
+
public async restoreState(state: AssessmentSessionState): Promise<void> {
|
|
314
321
|
this.state = state;
|
|
315
322
|
|
|
316
323
|
// Restore visited state for UI navigation hints.
|
|
317
324
|
const visitedIdx = (state.visitedItems || [])
|
|
318
|
-
.map((id) => this.
|
|
325
|
+
.map((id) => this.items.findIndex((q) => q.identifier === id))
|
|
319
326
|
.filter((i) => i >= 0);
|
|
320
327
|
this.navigationManager.restoreState(visitedIdx);
|
|
321
328
|
|
|
@@ -333,16 +340,16 @@ export class AssessmentPlayer {
|
|
|
333
340
|
}
|
|
334
341
|
|
|
335
342
|
const currentId = state.currentItemIdentifier;
|
|
336
|
-
const idx = currentId ? this.
|
|
343
|
+
const idx = currentId ? this.items.findIndex((q) => q.identifier === currentId) : -1;
|
|
337
344
|
if (idx >= 0) {
|
|
338
345
|
await this.navigateTo(idx);
|
|
339
|
-
} else if (this.
|
|
346
|
+
} else if (this.items.length > 0) {
|
|
340
347
|
await this.navigateTo(0);
|
|
341
348
|
}
|
|
342
349
|
}
|
|
343
350
|
|
|
344
351
|
public async navigateTo(index: number): Promise<void> {
|
|
345
|
-
if (index < 0 || index >= this.
|
|
352
|
+
if (index < 0 || index >= this.items.length) throw new Error(`Invalid item index: ${index}`);
|
|
346
353
|
|
|
347
354
|
// Enforce navigation rules (UI hints, still backend-authoritative for real deployments).
|
|
348
355
|
if (this.currentItemIndex >= 0 && !this.navigationManager.canNavigateTo(index, this.currentItemIndex)) {
|
|
@@ -351,13 +358,13 @@ export class AssessmentPlayer {
|
|
|
351
358
|
}
|
|
352
359
|
throw new Error('Navigation is not allowed.');
|
|
353
360
|
}
|
|
354
|
-
const target = this.
|
|
361
|
+
const target = this.items[index];
|
|
355
362
|
if (target && !this.sessionController.canReview(target.identifier)) {
|
|
356
363
|
throw new Error('You cannot go back to previous questions in this assessment.');
|
|
357
364
|
}
|
|
358
365
|
|
|
359
366
|
this.currentItemIndex = index;
|
|
360
|
-
const q = this.
|
|
367
|
+
const q = this.items[index]!;
|
|
361
368
|
this.state.currentItemIdentifier = q.identifier;
|
|
362
369
|
|
|
363
370
|
// Restore responses
|
|
@@ -376,7 +383,7 @@ export class AssessmentPlayer {
|
|
|
376
383
|
}
|
|
377
384
|
|
|
378
385
|
public async navigateToSection(sectionId: string): Promise<void> {
|
|
379
|
-
const idx = this.
|
|
386
|
+
const idx = this.items.findIndex((q) => q.section.identifier === sectionId);
|
|
380
387
|
if (idx >= 0) await this.navigateTo(idx);
|
|
381
388
|
}
|
|
382
389
|
|
|
@@ -384,7 +391,7 @@ export class AssessmentPlayer {
|
|
|
384
391
|
const state = this.getNavigationState();
|
|
385
392
|
if (!state.canNext) return;
|
|
386
393
|
|
|
387
|
-
const q = this.
|
|
394
|
+
const q = this.items[this.currentItemIndex];
|
|
388
395
|
if (q) {
|
|
389
396
|
const hasResponses = this.hasAnyResponse(this.responses);
|
|
390
397
|
this.sessionController.markAnswered(q.identifier, hasResponses);
|
|
@@ -414,7 +421,7 @@ export class AssessmentPlayer {
|
|
|
414
421
|
|
|
415
422
|
/** Submit current item (server-side scoring) */
|
|
416
423
|
public async submitCurrentItem(): Promise<ItemResult> {
|
|
417
|
-
const q = this.
|
|
424
|
+
const q = this.items[this.currentItemIndex];
|
|
418
425
|
if (!q) throw new Error('No current item');
|
|
419
426
|
|
|
420
427
|
const submittedAt = Date.now();
|
|
@@ -458,7 +465,7 @@ export class AssessmentPlayer {
|
|
|
458
465
|
|
|
459
466
|
// Apply backend branching decision if provided
|
|
460
467
|
if (res.nextItemIdentifier) {
|
|
461
|
-
const nextIdx = this.
|
|
468
|
+
const nextIdx = this.items.findIndex((x) => x.identifier === res.nextItemIdentifier);
|
|
462
469
|
if (nextIdx >= 0) {
|
|
463
470
|
await this.navigateTo(nextIdx);
|
|
464
471
|
}
|
|
@@ -469,7 +476,7 @@ export class AssessmentPlayer {
|
|
|
469
476
|
|
|
470
477
|
private canPrevious(): boolean {
|
|
471
478
|
if (this.currentItemIndex <= 0) return false;
|
|
472
|
-
const prev = this.
|
|
479
|
+
const prev = this.items[this.currentItemIndex - 1];
|
|
473
480
|
if (!prev) return false;
|
|
474
481
|
if (!this.navigationManager.canNavigateTo(this.currentItemIndex - 1, this.currentItemIndex)) return false;
|
|
475
482
|
return this.sessionController.canReview(prev.identifier);
|
|
@@ -478,7 +485,7 @@ export class AssessmentPlayer {
|
|
|
478
485
|
private canNext(): boolean {
|
|
479
486
|
if (this.currentItemIndex < 0) return false;
|
|
480
487
|
const nextIdx = this.currentItemIndex + 1;
|
|
481
|
-
if (nextIdx >= this.
|
|
488
|
+
if (nextIdx >= this.items.length) return false;
|
|
482
489
|
if (!this.navigationManager.canNavigateTo(nextIdx, this.currentItemIndex)) return false;
|
|
483
490
|
// Note: itemSessionControl constraints on leaving current item are enforced in next().
|
|
484
491
|
return true;
|
|
@@ -495,7 +502,7 @@ export class AssessmentPlayer {
|
|
|
495
502
|
// wipe out responses for later items during this loop.
|
|
496
503
|
const allItemResponses = { ...(this.state.itemResponses || {}) } as any;
|
|
497
504
|
|
|
498
|
-
for (const q of this.
|
|
505
|
+
for (const q of this.items) {
|
|
499
506
|
if (this.itemResults.has(q.identifier)) continue;
|
|
500
507
|
const submittedAt = Date.now();
|
|
501
508
|
const responsesForItem = (allItemResponses?.[q.identifier] || {}) as any;
|
|
@@ -527,7 +534,7 @@ export class AssessmentPlayer {
|
|
|
527
534
|
}
|
|
528
535
|
} else {
|
|
529
536
|
// Ensure current item is submitted (individual submission mode)
|
|
530
|
-
const q = this.
|
|
537
|
+
const q = this.items[this.currentItemIndex];
|
|
531
538
|
if (q && !this.itemResults.has(q.identifier)) {
|
|
532
539
|
await this.submitCurrentItem();
|
|
533
540
|
}
|
|
@@ -540,7 +547,7 @@ export class AssessmentPlayer {
|
|
|
540
547
|
|
|
541
548
|
// Map backend itemScores to ItemResult[]
|
|
542
549
|
const itemScores = finalized.itemScores || {};
|
|
543
|
-
const itemResults: ItemResult[] = Object.values(itemScores).map((r:
|
|
550
|
+
const itemResults: ItemResult[] = Object.values(itemScores).map((r: AssessmentScoringResult) => ({
|
|
544
551
|
itemIdentifier: r.itemIdentifier,
|
|
545
552
|
score: r.score,
|
|
546
553
|
maxScore: r.maxScore,
|
|
@@ -575,7 +582,7 @@ export class AssessmentPlayer {
|
|
|
575
582
|
canReview: boolean;
|
|
576
583
|
canSkip: boolean;
|
|
577
584
|
} | null {
|
|
578
|
-
const q = this.
|
|
585
|
+
const q = this.items[this.currentItemIndex];
|
|
579
586
|
if (!q) return null;
|
|
580
587
|
const id = q.identifier;
|
|
581
588
|
|
|
@@ -663,12 +670,12 @@ export class AssessmentPlayer {
|
|
|
663
670
|
// ---------------------------------------------------------------------------
|
|
664
671
|
|
|
665
672
|
private notifyItemChange(): void {
|
|
666
|
-
for (const l of this.itemChangeListeners) l(this.currentItemIndex, this.
|
|
667
|
-
this.config.onItemChange?.(this.currentItemIndex, this.
|
|
673
|
+
for (const l of this.itemChangeListeners) l(this.currentItemIndex, this.items.length);
|
|
674
|
+
this.config.onItemChange?.(this.currentItemIndex, this.items.length);
|
|
668
675
|
}
|
|
669
676
|
|
|
670
677
|
private notifySectionChange(): void {
|
|
671
|
-
const q = this.
|
|
678
|
+
const q = this.items[this.currentItemIndex];
|
|
672
679
|
const sectionIndex = q?.sectionIndex ?? 0;
|
|
673
680
|
const totalSections = this.getAllSections().length;
|
|
674
681
|
for (const l of this.sectionChangeListeners) l(sectionIndex, totalSections);
|
package/src/index.ts
CHANGED
|
@@ -6,7 +6,7 @@ export { AssessmentPlayer, NavigationManager } from './core/index.js';
|
|
|
6
6
|
// Backend integration API + reference adapter
|
|
7
7
|
export * from './integration/index.js';
|
|
8
8
|
// Public UI/data types
|
|
9
|
-
export type { AssessmentResults, ItemResult, NavigationState, QTIRole
|
|
9
|
+
export type { AssessmentResults, ItemRef, ItemResult, NavigationState, QTIRole } from './types/index.js';
|
|
10
10
|
|
|
11
11
|
// Components are exported via package.json "exports" field
|
|
12
12
|
// Users can import them like:
|