@pie-qti/assessment-player 0.1.9 → 0.1.10
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 +3 -7
- package/dist/core/AssessmentPlayer.d.ts.map +1 -1
- package/dist/core/AssessmentPlayer.js +60 -170
- package/dist/core/AssessmentSessionCoordinator.d.ts +51 -0
- package/dist/core/AssessmentSessionCoordinator.d.ts.map +1 -0
- package/dist/core/AssessmentSessionCoordinator.js +215 -0
- package/package.json +7 -6
- package/src/components/ItemRenderer.svelte +66 -67
- package/src/core/AssessmentPlayer.ts +59 -166
- package/src/core/AssessmentSessionCoordinator.ts +274 -0
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
2
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
5
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
|
+
};
|
|
7
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
+
};
|
|
12
|
+
var _AssessmentSessionCoordinator_instances, _AssessmentSessionCoordinator_state, _AssessmentSessionCoordinator_sessionController, _AssessmentSessionCoordinator_itemResults, _AssessmentSessionCoordinator_itemIdentifiers, _AssessmentSessionCoordinator_initializeItemSessions, _AssessmentSessionCoordinator_restoreItemSessionsFromState, _AssessmentSessionCoordinator_restoreItemResultsFromScores, _AssessmentSessionCoordinator_itemSessionStateSnapshot;
|
|
13
|
+
import { ItemSessionController, } from './ItemSessionController.js';
|
|
14
|
+
export class AssessmentSessionCoordinator {
|
|
15
|
+
constructor({ state, itemIdentifiers, itemSessionControl }) {
|
|
16
|
+
_AssessmentSessionCoordinator_instances.add(this);
|
|
17
|
+
_AssessmentSessionCoordinator_state.set(this, void 0);
|
|
18
|
+
_AssessmentSessionCoordinator_sessionController.set(this, void 0);
|
|
19
|
+
_AssessmentSessionCoordinator_itemResults.set(this, new Map());
|
|
20
|
+
_AssessmentSessionCoordinator_itemIdentifiers.set(this, void 0);
|
|
21
|
+
__classPrivateFieldSet(this, _AssessmentSessionCoordinator_state, state, "f");
|
|
22
|
+
__classPrivateFieldSet(this, _AssessmentSessionCoordinator_itemIdentifiers, itemIdentifiers, "f");
|
|
23
|
+
__classPrivateFieldSet(this, _AssessmentSessionCoordinator_sessionController, new ItemSessionController(itemSessionControl), "f");
|
|
24
|
+
__classPrivateFieldGet(this, _AssessmentSessionCoordinator_instances, "m", _AssessmentSessionCoordinator_initializeItemSessions).call(this);
|
|
25
|
+
__classPrivateFieldGet(this, _AssessmentSessionCoordinator_instances, "m", _AssessmentSessionCoordinator_restoreItemSessionsFromState).call(this, state);
|
|
26
|
+
__classPrivateFieldGet(this, _AssessmentSessionCoordinator_instances, "m", _AssessmentSessionCoordinator_restoreItemResultsFromScores).call(this, state);
|
|
27
|
+
}
|
|
28
|
+
get state() {
|
|
29
|
+
return __classPrivateFieldGet(this, _AssessmentSessionCoordinator_state, "f");
|
|
30
|
+
}
|
|
31
|
+
restoreState(state) {
|
|
32
|
+
__classPrivateFieldSet(this, _AssessmentSessionCoordinator_state, state, "f");
|
|
33
|
+
__classPrivateFieldGet(this, _AssessmentSessionCoordinator_instances, "m", _AssessmentSessionCoordinator_restoreItemSessionsFromState).call(this, state);
|
|
34
|
+
__classPrivateFieldGet(this, _AssessmentSessionCoordinator_instances, "m", _AssessmentSessionCoordinator_restoreItemResultsFromScores).call(this, state);
|
|
35
|
+
}
|
|
36
|
+
snapshot(options = {}) {
|
|
37
|
+
return {
|
|
38
|
+
...__classPrivateFieldGet(this, _AssessmentSessionCoordinator_state, "f"),
|
|
39
|
+
visitedItems: [...__classPrivateFieldGet(this, _AssessmentSessionCoordinator_state, "f").visitedItems],
|
|
40
|
+
itemResponses: { ...__classPrivateFieldGet(this, _AssessmentSessionCoordinator_state, "f").itemResponses },
|
|
41
|
+
itemScores: __classPrivateFieldGet(this, _AssessmentSessionCoordinator_state, "f").itemScores ? { ...__classPrivateFieldGet(this, _AssessmentSessionCoordinator_state, "f").itemScores } : undefined,
|
|
42
|
+
itemSessions: options.includeItemSessions && __classPrivateFieldGet(this, _AssessmentSessionCoordinator_state, "f").itemSessions
|
|
43
|
+
? { ...__classPrivateFieldGet(this, _AssessmentSessionCoordinator_state, "f").itemSessions }
|
|
44
|
+
: undefined,
|
|
45
|
+
itemSessionStates: __classPrivateFieldGet(this, _AssessmentSessionCoordinator_instances, "m", _AssessmentSessionCoordinator_itemSessionStateSnapshot).call(this),
|
|
46
|
+
timing: {
|
|
47
|
+
...__classPrivateFieldGet(this, _AssessmentSessionCoordinator_state, "f").timing,
|
|
48
|
+
itemTimes: { ...__classPrivateFieldGet(this, _AssessmentSessionCoordinator_state, "f").timing.itemTimes },
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
activateItem(itemIdentifier) {
|
|
53
|
+
__classPrivateFieldGet(this, _AssessmentSessionCoordinator_state, "f").currentItemIdentifier = itemIdentifier;
|
|
54
|
+
return this.getResponses(itemIdentifier);
|
|
55
|
+
}
|
|
56
|
+
getActiveResponses() {
|
|
57
|
+
return this.getResponses(__classPrivateFieldGet(this, _AssessmentSessionCoordinator_state, "f").currentItemIdentifier);
|
|
58
|
+
}
|
|
59
|
+
getResponses(itemIdentifier) {
|
|
60
|
+
return { ...(__classPrivateFieldGet(this, _AssessmentSessionCoordinator_state, "f").itemResponses?.[itemIdentifier] || {}) };
|
|
61
|
+
}
|
|
62
|
+
updateActiveResponse(responseId, value) {
|
|
63
|
+
return this.updateResponseForItem(__classPrivateFieldGet(this, _AssessmentSessionCoordinator_state, "f").currentItemIdentifier, responseId, value);
|
|
64
|
+
}
|
|
65
|
+
updateResponseForItem(itemIdentifier, responseId, value) {
|
|
66
|
+
const next = {
|
|
67
|
+
...(__classPrivateFieldGet(this, _AssessmentSessionCoordinator_state, "f").itemResponses?.[itemIdentifier] || {}),
|
|
68
|
+
[responseId]: value,
|
|
69
|
+
};
|
|
70
|
+
__classPrivateFieldGet(this, _AssessmentSessionCoordinator_state, "f").itemResponses[itemIdentifier] = next;
|
|
71
|
+
this.markAnswered(itemIdentifier, next);
|
|
72
|
+
return next;
|
|
73
|
+
}
|
|
74
|
+
saveItemSession(itemIdentifier, responses, sessionState, duration) {
|
|
75
|
+
__classPrivateFieldGet(this, _AssessmentSessionCoordinator_state, "f").itemSessions = {
|
|
76
|
+
...(__classPrivateFieldGet(this, _AssessmentSessionCoordinator_state, "f").itemSessions ?? {}),
|
|
77
|
+
[itemIdentifier]: sessionState,
|
|
78
|
+
};
|
|
79
|
+
__classPrivateFieldGet(this, _AssessmentSessionCoordinator_state, "f").itemResponses[itemIdentifier] = responses;
|
|
80
|
+
__classPrivateFieldGet(this, _AssessmentSessionCoordinator_state, "f").timing.itemTimes[itemIdentifier] = duration;
|
|
81
|
+
this.markAnswered(itemIdentifier, responses);
|
|
82
|
+
}
|
|
83
|
+
setItemSession(itemIdentifier, sessionState) {
|
|
84
|
+
__classPrivateFieldGet(this, _AssessmentSessionCoordinator_state, "f").itemSessions = {
|
|
85
|
+
...(__classPrivateFieldGet(this, _AssessmentSessionCoordinator_state, "f").itemSessions ?? {}),
|
|
86
|
+
[itemIdentifier]: sessionState,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
mergeItemSessions(itemSessions) {
|
|
90
|
+
if (!itemSessions)
|
|
91
|
+
return;
|
|
92
|
+
__classPrivateFieldGet(this, _AssessmentSessionCoordinator_state, "f").itemSessions = {
|
|
93
|
+
...(__classPrivateFieldGet(this, _AssessmentSessionCoordinator_state, "f").itemSessions ?? {}),
|
|
94
|
+
...itemSessions,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
replaceStatePreservingItemSessions(updatedState) {
|
|
98
|
+
const localItemSessions = __classPrivateFieldGet(this, _AssessmentSessionCoordinator_state, "f").itemSessions;
|
|
99
|
+
this.restoreState(updatedState);
|
|
100
|
+
this.mergeItemSessions(localItemSessions);
|
|
101
|
+
}
|
|
102
|
+
replaceStatePreservingResponsesAndSessions(updatedState, itemResponses, itemSessions) {
|
|
103
|
+
this.restoreState(updatedState);
|
|
104
|
+
__classPrivateFieldGet(this, _AssessmentSessionCoordinator_state, "f").itemResponses = itemResponses;
|
|
105
|
+
__classPrivateFieldGet(this, _AssessmentSessionCoordinator_state, "f").itemSessions = itemSessions;
|
|
106
|
+
}
|
|
107
|
+
markVisited(itemIdentifier) {
|
|
108
|
+
if (!__classPrivateFieldGet(this, _AssessmentSessionCoordinator_state, "f").visitedItems.includes(itemIdentifier)) {
|
|
109
|
+
__classPrivateFieldGet(this, _AssessmentSessionCoordinator_state, "f").visitedItems.push(itemIdentifier);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
markAnswered(itemIdentifier, responses) {
|
|
113
|
+
__classPrivateFieldGet(this, _AssessmentSessionCoordinator_sessionController, "f").markAnswered(itemIdentifier, hasAnyResponse(responses));
|
|
114
|
+
}
|
|
115
|
+
canReview(itemIdentifier) {
|
|
116
|
+
return __classPrivateFieldGet(this, _AssessmentSessionCoordinator_sessionController, "f").canReview(itemIdentifier);
|
|
117
|
+
}
|
|
118
|
+
canNavigateAway(itemIdentifier, responses) {
|
|
119
|
+
return __classPrivateFieldGet(this, _AssessmentSessionCoordinator_sessionController, "f").canNavigateAway(itemIdentifier, hasAnyResponse(responses));
|
|
120
|
+
}
|
|
121
|
+
updateItemSessionControl(settings) {
|
|
122
|
+
__classPrivateFieldGet(this, _AssessmentSessionCoordinator_sessionController, "f").updateSettings(settings);
|
|
123
|
+
}
|
|
124
|
+
mustValidateResponses() {
|
|
125
|
+
return __classPrivateFieldGet(this, _AssessmentSessionCoordinator_sessionController, "f").mustValidateResponses();
|
|
126
|
+
}
|
|
127
|
+
recordAttempt(itemIdentifier) {
|
|
128
|
+
__classPrivateFieldGet(this, _AssessmentSessionCoordinator_sessionController, "f").recordAttempt(itemIdentifier);
|
|
129
|
+
}
|
|
130
|
+
setItemResult(itemResult) {
|
|
131
|
+
__classPrivateFieldGet(this, _AssessmentSessionCoordinator_itemResults, "f").set(itemResult.itemIdentifier, itemResult);
|
|
132
|
+
}
|
|
133
|
+
hasItemResult(itemIdentifier) {
|
|
134
|
+
return __classPrivateFieldGet(this, _AssessmentSessionCoordinator_itemResults, "f").has(itemIdentifier);
|
|
135
|
+
}
|
|
136
|
+
getItemSessionInfo(itemIdentifier) {
|
|
137
|
+
if (!__classPrivateFieldGet(this, _AssessmentSessionCoordinator_sessionController, "f").getItemState(itemIdentifier)) {
|
|
138
|
+
__classPrivateFieldGet(this, _AssessmentSessionCoordinator_sessionController, "f").initializeItem(itemIdentifier);
|
|
139
|
+
}
|
|
140
|
+
const state = __classPrivateFieldGet(this, _AssessmentSessionCoordinator_sessionController, "f").getItemState(itemIdentifier);
|
|
141
|
+
return {
|
|
142
|
+
canSubmit: __classPrivateFieldGet(this, _AssessmentSessionCoordinator_sessionController, "f").canSubmit(itemIdentifier),
|
|
143
|
+
remainingAttempts: __classPrivateFieldGet(this, _AssessmentSessionCoordinator_sessionController, "f").getRemainingAttempts(itemIdentifier),
|
|
144
|
+
attemptCount: state?.attemptCount ?? 0,
|
|
145
|
+
showFeedback: __classPrivateFieldGet(this, _AssessmentSessionCoordinator_sessionController, "f").shouldShowFeedback(itemIdentifier),
|
|
146
|
+
showSolution: __classPrivateFieldGet(this, _AssessmentSessionCoordinator_sessionController, "f").shouldShowSolution(itemIdentifier),
|
|
147
|
+
canReview: __classPrivateFieldGet(this, _AssessmentSessionCoordinator_sessionController, "f").canReview(itemIdentifier),
|
|
148
|
+
canSkip: __classPrivateFieldGet(this, _AssessmentSessionCoordinator_sessionController, "f").canSkip(itemIdentifier),
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
_AssessmentSessionCoordinator_state = new WeakMap(), _AssessmentSessionCoordinator_sessionController = new WeakMap(), _AssessmentSessionCoordinator_itemResults = new WeakMap(), _AssessmentSessionCoordinator_itemIdentifiers = new WeakMap(), _AssessmentSessionCoordinator_instances = new WeakSet(), _AssessmentSessionCoordinator_initializeItemSessions = function _AssessmentSessionCoordinator_initializeItemSessions() {
|
|
153
|
+
for (const itemIdentifier of __classPrivateFieldGet(this, _AssessmentSessionCoordinator_itemIdentifiers, "f")) {
|
|
154
|
+
__classPrivateFieldGet(this, _AssessmentSessionCoordinator_sessionController, "f").initializeItem(itemIdentifier);
|
|
155
|
+
}
|
|
156
|
+
}, _AssessmentSessionCoordinator_restoreItemSessionsFromState = function _AssessmentSessionCoordinator_restoreItemSessionsFromState(state) {
|
|
157
|
+
const restoredStates = new Map();
|
|
158
|
+
for (const itemIdentifier of __classPrivateFieldGet(this, _AssessmentSessionCoordinator_itemIdentifiers, "f")) {
|
|
159
|
+
const persisted = state.itemSessionStates?.[itemIdentifier];
|
|
160
|
+
if (persisted) {
|
|
161
|
+
restoredStates.set(itemIdentifier, {
|
|
162
|
+
itemIdentifier,
|
|
163
|
+
attemptCount: Math.max(0, persisted.attemptCount),
|
|
164
|
+
isAnswered: persisted.isAnswered,
|
|
165
|
+
isSubmitted: persisted.isSubmitted,
|
|
166
|
+
lastSubmissionTime: persisted.lastSubmissionTime,
|
|
167
|
+
});
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
170
|
+
const responses = state.itemResponses?.[itemIdentifier] ?? {};
|
|
171
|
+
const isSubmitted = Boolean(state.itemScores?.[itemIdentifier]);
|
|
172
|
+
restoredStates.set(itemIdentifier, {
|
|
173
|
+
itemIdentifier,
|
|
174
|
+
attemptCount: isSubmitted ? 1 : 0,
|
|
175
|
+
isAnswered: hasAnyResponse(responses),
|
|
176
|
+
isSubmitted,
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
__classPrivateFieldGet(this, _AssessmentSessionCoordinator_sessionController, "f").restoreStates(restoredStates);
|
|
180
|
+
}, _AssessmentSessionCoordinator_restoreItemResultsFromScores = function _AssessmentSessionCoordinator_restoreItemResultsFromScores(state) {
|
|
181
|
+
__classPrivateFieldGet(this, _AssessmentSessionCoordinator_itemResults, "f").clear();
|
|
182
|
+
if (!state.itemScores)
|
|
183
|
+
return;
|
|
184
|
+
for (const [itemIdentifier, scoring] of Object.entries(state.itemScores)) {
|
|
185
|
+
__classPrivateFieldGet(this, _AssessmentSessionCoordinator_itemResults, "f").set(itemIdentifier, {
|
|
186
|
+
itemIdentifier,
|
|
187
|
+
score: scoring.score,
|
|
188
|
+
maxScore: scoring.maxScore,
|
|
189
|
+
responses: state.itemResponses?.[itemIdentifier] || {},
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
}, _AssessmentSessionCoordinator_itemSessionStateSnapshot = function _AssessmentSessionCoordinator_itemSessionStateSnapshot() {
|
|
193
|
+
return Object.fromEntries([...__classPrivateFieldGet(this, _AssessmentSessionCoordinator_sessionController, "f").getAllStates().entries()].map(([itemIdentifier, state]) => [
|
|
194
|
+
itemIdentifier,
|
|
195
|
+
{ ...state },
|
|
196
|
+
]));
|
|
197
|
+
};
|
|
198
|
+
function hasAnyResponse(responses) {
|
|
199
|
+
for (const value of Object.values(responses)) {
|
|
200
|
+
if (value == null)
|
|
201
|
+
continue;
|
|
202
|
+
if (Array.isArray(value)) {
|
|
203
|
+
if (value.length > 0)
|
|
204
|
+
return true;
|
|
205
|
+
continue;
|
|
206
|
+
}
|
|
207
|
+
if (typeof value === 'string') {
|
|
208
|
+
if (value.trim().length > 0)
|
|
209
|
+
return true;
|
|
210
|
+
continue;
|
|
211
|
+
}
|
|
212
|
+
return true;
|
|
213
|
+
}
|
|
214
|
+
return false;
|
|
215
|
+
}
|
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.10",
|
|
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,11 +28,12 @@
|
|
|
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/ims-cp-core": "0.1.
|
|
34
|
-
"@pie-qti/item-player": "0.1.
|
|
35
|
-
"@pie-qti/qti-
|
|
31
|
+
"@pie-qti/default-components": "0.1.10",
|
|
32
|
+
"@pie-qti/i18n": "0.1.10",
|
|
33
|
+
"@pie-qti/ims-cp-core": "0.1.10",
|
|
34
|
+
"@pie-qti/item-player": "0.1.10",
|
|
35
|
+
"@pie-qti/qti-common": "0.1.10",
|
|
36
|
+
"@pie-qti/qti-processing": "0.1.10",
|
|
36
37
|
"node-html-parser": "^7.0.2"
|
|
37
38
|
},
|
|
38
39
|
"peerDependencies": {
|
|
@@ -1,37 +1,25 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
|
|
3
|
-
import { registerDefaultComponents } from '@pie-qti/default-components';
|
|
4
|
-
// @ts-expect-error - Svelte-check can't resolve workspace subpath exports, but runtime works correctly
|
|
5
|
-
import { ItemBody } from '@pie-qti/item-player/components';
|
|
6
|
-
import { Player, type PlayerSecurityConfig, type PnpProfile, type QTIRole } from '@pie-qti/item-player';
|
|
2
|
+
import type { PlayerSecurityConfig, PnpProfile, QTIRole } from '@pie-qti/item-player';
|
|
7
3
|
import type { InteractionResponseValue } from '@pie-qti/item-player/web-components';
|
|
8
4
|
import type { I18nProvider } from '@pie-qti/i18n';
|
|
5
|
+
import { assignProps } from '@pie-qti/qti-common';
|
|
9
6
|
import { onMount } from 'svelte';
|
|
10
7
|
import type { ItemRef } from '../types/index.js';
|
|
11
8
|
|
|
12
9
|
type ItemResponseValue = InteractionResponseValue | null;
|
|
13
10
|
type ItemResponseMap = Record<string, ItemResponseValue>;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
.catch((err) => {
|
|
27
|
-
console.warn('Failed to load default QTI web components:', err);
|
|
28
|
-
});
|
|
29
|
-
return pluginsLoadPromise;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
onMount(() => {
|
|
33
|
-
void ensureDefaultPluginsLoaded();
|
|
34
|
-
});
|
|
11
|
+
type PieQtiItemPlayerElement = HTMLElement & {
|
|
12
|
+
itemXml?: string;
|
|
13
|
+
role?: QTIRole;
|
|
14
|
+
disabled?: boolean;
|
|
15
|
+
responses?: ItemResponseMap;
|
|
16
|
+
typeset?: (root: HTMLElement) => void | Promise<void>;
|
|
17
|
+
i18n?: I18nProvider;
|
|
18
|
+
security?: PlayerSecurityConfig;
|
|
19
|
+
pnp?: PnpProfile;
|
|
20
|
+
deliveryContext?: ItemRef['deliveryContext'];
|
|
21
|
+
onResponseChange?: (responseId: string, value: ItemResponseValue) => void;
|
|
22
|
+
};
|
|
35
23
|
|
|
36
24
|
interface Props {
|
|
37
25
|
itemRef: ItemRef;
|
|
@@ -62,45 +50,48 @@
|
|
|
62
50
|
pnp,
|
|
63
51
|
}: Props = $props();
|
|
64
52
|
|
|
65
|
-
|
|
66
|
-
let
|
|
67
|
-
if (!itemRef.itemXml) {
|
|
68
|
-
return { player: null, error: 'No item XML provided' };
|
|
69
|
-
}
|
|
53
|
+
let playerLoaded = $state(false);
|
|
54
|
+
let errorMessage = $state<string | null>(null);
|
|
70
55
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
56
|
+
onMount(() => {
|
|
57
|
+
let cancelled = false;
|
|
58
|
+
void Promise.all([
|
|
59
|
+
import('@pie-qti/default-components/plugins'),
|
|
60
|
+
import('@pie-qti/item-player/element'),
|
|
61
|
+
])
|
|
62
|
+
.then(() => {
|
|
63
|
+
if (!cancelled) {
|
|
64
|
+
playerLoaded = true;
|
|
65
|
+
}
|
|
66
|
+
})
|
|
67
|
+
.catch((error) => {
|
|
68
|
+
if (!cancelled) {
|
|
69
|
+
errorMessage =
|
|
70
|
+
error instanceof Error ? error.message : 'Unable to load the QTI item player.';
|
|
71
|
+
}
|
|
78
72
|
});
|
|
79
73
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
return {
|
|
85
|
-
player: newPlayer,
|
|
86
|
-
error: null,
|
|
87
|
-
};
|
|
88
|
-
} catch (err) {
|
|
89
|
-
console.error('Failed to initialize item player:', err);
|
|
90
|
-
return {
|
|
91
|
-
player: null,
|
|
92
|
-
error: err instanceof Error ? err.message : (i18n?.t('item.loadingError') ?? 'Failed to load item'),
|
|
93
|
-
};
|
|
94
|
-
}
|
|
74
|
+
return () => {
|
|
75
|
+
cancelled = true;
|
|
76
|
+
};
|
|
95
77
|
});
|
|
96
78
|
|
|
97
|
-
// Handle response changes
|
|
98
79
|
function handleResponseChange(responseId: string, value: ItemResponseValue) {
|
|
99
80
|
onResponseChange?.(responseId, value);
|
|
100
81
|
}
|
|
82
|
+
|
|
83
|
+
function itemPlayerProps(node: PieQtiItemPlayerElement, props: Record<string, unknown>) {
|
|
84
|
+
assignProps(node, props);
|
|
85
|
+
|
|
86
|
+
return {
|
|
87
|
+
update(next: Record<string, unknown>) {
|
|
88
|
+
assignProps(node, next);
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
}
|
|
101
92
|
</script>
|
|
102
93
|
|
|
103
|
-
{#if
|
|
94
|
+
{#if errorMessage}
|
|
104
95
|
<div class="alert alert-error">
|
|
105
96
|
<svg
|
|
106
97
|
xmlns="http://www.w3.org/2000/svg"
|
|
@@ -115,9 +106,13 @@
|
|
|
115
106
|
d="M10 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2m7-2a9 9 0 11-18 0 9 9 0 0118 0z"
|
|
116
107
|
/>
|
|
117
108
|
</svg>
|
|
118
|
-
<span>{i18n?.t('item.loadError', 'Error loading item: {error}', { error:
|
|
109
|
+
<span>{i18n?.t('item.loadError', 'Error loading item: {error}', { error: errorMessage })}</span>
|
|
119
110
|
</div>
|
|
120
|
-
{:else if !
|
|
111
|
+
{:else if !itemRef.itemXml}
|
|
112
|
+
<div class="alert alert-error">
|
|
113
|
+
<span>{i18n?.t('item.loadingError') ?? 'No item XML provided'}</span>
|
|
114
|
+
</div>
|
|
115
|
+
{:else if !playerLoaded}
|
|
121
116
|
<div class="flex items-center justify-center p-8">
|
|
122
117
|
<span class="loading loading-spinner loading-lg"></span>
|
|
123
118
|
<span class="ml-4">{i18n?.t('item.loading', 'Loading item...')}</span>
|
|
@@ -131,16 +126,20 @@
|
|
|
131
126
|
{/if}
|
|
132
127
|
|
|
133
128
|
<div class="item-content">
|
|
134
|
-
<
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
129
|
+
<pie-qti-item-player
|
|
130
|
+
use:itemPlayerProps={{
|
|
131
|
+
itemXml: itemRef.itemXml,
|
|
132
|
+
role,
|
|
133
|
+
disabled: role !== 'candidate',
|
|
134
|
+
responses,
|
|
135
|
+
typeset,
|
|
136
|
+
i18n,
|
|
137
|
+
security,
|
|
138
|
+
pnp,
|
|
139
|
+
deliveryContext: itemRef.deliveryContext,
|
|
140
|
+
onResponseChange: handleResponseChange,
|
|
141
|
+
}}
|
|
142
|
+
></pie-qti-item-player>
|
|
144
143
|
</div>
|
|
145
144
|
</div>
|
|
146
145
|
{/if}
|