@pie-qti/player-elements 0.1.1 → 0.1.5
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/README.md +4 -4
- package/dist/define-DMZ1uQuZ.js +30372 -0
- package/dist/define-DMZ1uQuZ.js.map +1 -0
- package/dist/elements/QtiItemPlayerElement.d.ts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -13
- package/dist/plugins-BZ6Fu4_E.js +0 -0
- package/dist/qti/parseAssessmentTest.d.ts.map +1 -1
- package/dist/qti/resolveItems.d.ts.map +1 -1
- package/dist/qti/types.d.ts +4 -4
- package/dist/qti/types.d.ts.map +1 -1
- package/dist/register.js +6 -5
- package/dist/register.js.map +1 -1
- package/package.json +56 -37
- package/.turbo/turbo-build.log +0 -14
- package/CHANGELOG.md +0 -10
- package/bunfig.toml +0 -2
- package/dist/index-B1sHDWWn.js +0 -30415
- package/dist/index-B1sHDWWn.js.map +0 -1
- package/dist/index-C_WHHKJ8.js +0 -34157
- package/dist/index-C_WHHKJ8.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/mathlive.min-B8mv5Blc.js +0 -15374
- package/dist/mathlive.min-B8mv5Blc.js.map +0 -1
- package/dist/player-elements.css +0 -1
- package/src/constants.ts +0 -4
- package/src/define.ts +0 -9
- package/src/elements/BaseSvelteMountElement.ts +0 -63
- package/src/elements/QtiAssessmentPlayerElement.ts +0 -384
- package/src/elements/QtiItemPlayerElement.ts +0 -197
- package/src/index.ts +0 -26
- package/src/qti/parseAssessmentTest.ts +0 -174
- package/src/qti/resolveItems.ts +0 -94
- package/src/qti/types.ts +0 -33
- package/src/register.ts +0 -7
- package/src/utils/json.ts +0 -10
- package/svelte.config.js +0 -14
- package/tests/qti-assessment-test-parsing.test.ts +0 -125
- package/tests/setup.ts +0 -29
- package/tsconfig.build.json +0 -15
- package/tsconfig.json +0 -18
- package/vite.config.ts +0 -25
package/dist/player-elements.css
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
.sr-only{position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border-width:0}
|
package/src/constants.ts
DELETED
package/src/define.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { defineQtiAssessmentPlayerElement } from './elements/QtiAssessmentPlayerElement.js';
|
|
2
|
-
import { defineQtiItemPlayerElement } from './elements/QtiItemPlayerElement.js';
|
|
3
|
-
|
|
4
|
-
export function defineQtiPlayerElements() {
|
|
5
|
-
defineQtiItemPlayerElement();
|
|
6
|
-
defineQtiAssessmentPlayerElement();
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import type { Component } from 'svelte';
|
|
2
|
-
import { mount, unmount } from 'svelte';
|
|
3
|
-
|
|
4
|
-
export abstract class BaseSvelteMountElement<TProps extends Record<string, unknown>> extends HTMLElement {
|
|
5
|
-
protected abstract Component: Component<any>;
|
|
6
|
-
protected abstract getProps(): TProps;
|
|
7
|
-
|
|
8
|
-
#container: HTMLDivElement | null = null;
|
|
9
|
-
protected _instance: any = null;
|
|
10
|
-
|
|
11
|
-
connectedCallback() {
|
|
12
|
-
this._mountOrUpdate();
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
disconnectedCallback() {
|
|
16
|
-
this._teardownInstance();
|
|
17
|
-
|
|
18
|
-
if (this.#container) {
|
|
19
|
-
this.#container.remove();
|
|
20
|
-
this.#container = null;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
protected _mountOrUpdate() {
|
|
25
|
-
if (!this.#container) {
|
|
26
|
-
this.#container = document.createElement('div');
|
|
27
|
-
this.#container.style.display = 'contents';
|
|
28
|
-
this.appendChild(this.#container);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const props = this.getProps();
|
|
32
|
-
|
|
33
|
-
if (!this._instance) {
|
|
34
|
-
this._instance = mount(this.Component, {
|
|
35
|
-
target: this.#container as HTMLDivElement,
|
|
36
|
-
props,
|
|
37
|
-
});
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// Svelte 5 `mount` returns an instance that may or may not have `$set`.
|
|
42
|
-
// If it doesn't, remount.
|
|
43
|
-
if (typeof this._instance?.$set === 'function') {
|
|
44
|
-
this._instance.$set(props);
|
|
45
|
-
} else {
|
|
46
|
-
this._teardownInstance();
|
|
47
|
-
this._mountOrUpdate();
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
protected _teardownInstance() {
|
|
52
|
-
if (this._instance) {
|
|
53
|
-
try {
|
|
54
|
-
unmount(this._instance);
|
|
55
|
-
} catch {
|
|
56
|
-
// ignore
|
|
57
|
-
}
|
|
58
|
-
this._instance = null;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
|
|
@@ -1,384 +0,0 @@
|
|
|
1
|
-
import type { AssessmentResults, BackendAdapter, BackendAssessmentPlayerConfig, InitSessionRequest, SecureAssessment } from '@pie-qti/assessment-player';
|
|
2
|
-
import { ReferenceBackendAdapter } from '@pie-qti/assessment-player';
|
|
3
|
-
import AssessmentShell from '@pie-qti/assessment-player/components/AssessmentShell.svelte';
|
|
4
|
-
import type { PlayerSecurityConfig } from '@pie-qti/item-player';
|
|
5
|
-
import { QTI_ASSESSMENT_PLAYER_TAG } from '../constants.js';
|
|
6
|
-
import { parseAssessmentTestXml } from '../qti/parseAssessmentTest.js';
|
|
7
|
-
import { type QtiItemMap, resolveItemsForAssessment } from '../qti/resolveItems.js';
|
|
8
|
-
import type { ParsedAssessmentSection, ParsedAssessmentTest } from '../qti/types.js';
|
|
9
|
-
import { safeJsonParse } from '../utils/json.js';
|
|
10
|
-
import { BaseSvelteMountElement } from './BaseSvelteMountElement.js';
|
|
11
|
-
|
|
12
|
-
export type QtiAssessmentResponseChangeDetail = {
|
|
13
|
-
responses: Record<string, unknown>;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export type QtiAssessmentItemChangeDetail = {
|
|
17
|
-
itemIndex: number;
|
|
18
|
-
totalItems: number;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export type QtiAssessmentSectionChangeDetail = {
|
|
22
|
-
sectionIndex: number;
|
|
23
|
-
totalSections: number;
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
export type QtiAssessmentSubmitDetail = {
|
|
27
|
-
results: AssessmentResults;
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
export class QtiAssessmentPlayerElement extends BaseSvelteMountElement<Record<string, unknown>> {
|
|
31
|
-
static get observedAttributes() {
|
|
32
|
-
return [
|
|
33
|
-
// Pure-QTI inputs
|
|
34
|
-
'assessment-test-xml',
|
|
35
|
-
'assessment-id',
|
|
36
|
-
'candidate-id',
|
|
37
|
-
'item-base-url',
|
|
38
|
-
'items-json',
|
|
39
|
-
// Common
|
|
40
|
-
'config-json',
|
|
41
|
-
'security-json',
|
|
42
|
-
];
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
protected Component = AssessmentShell;
|
|
46
|
-
|
|
47
|
-
#assessmentTestXml: string | null = null;
|
|
48
|
-
#assessmentId: string | undefined;
|
|
49
|
-
#candidateId: string | undefined;
|
|
50
|
-
#itemBaseUrl: string | undefined;
|
|
51
|
-
#items: QtiItemMap | undefined;
|
|
52
|
-
#config: Partial<BackendAssessmentPlayerConfig> = {};
|
|
53
|
-
#security: PlayerSecurityConfig | undefined;
|
|
54
|
-
|
|
55
|
-
#backend: BackendAdapter = {
|
|
56
|
-
async initSession(_request) {
|
|
57
|
-
throw new Error('No assessment loaded. Provide `assessment-test-xml`.');
|
|
58
|
-
},
|
|
59
|
-
async submitResponses(_request) {
|
|
60
|
-
return { success: false, error: 'No assessment loaded.' };
|
|
61
|
-
},
|
|
62
|
-
async finalizeAssessment(_request) {
|
|
63
|
-
return { success: false, totalScore: 0, maxScore: 0, itemScores: {}, finalizedAt: Date.now() };
|
|
64
|
-
},
|
|
65
|
-
async saveState(_request) {
|
|
66
|
-
return { success: false, savedAt: Date.now() };
|
|
67
|
-
},
|
|
68
|
-
async queryItemBank(_request) {
|
|
69
|
-
return { items: [], selectedAt: Date.now() };
|
|
70
|
-
},
|
|
71
|
-
};
|
|
72
|
-
#initSession: InitSessionRequest = { assessmentId: 'assessment', candidateId: 'candidate' };
|
|
73
|
-
|
|
74
|
-
#loadSeq = 0;
|
|
75
|
-
#allowMount = false;
|
|
76
|
-
|
|
77
|
-
connectedCallback() {
|
|
78
|
-
super.connectedCallback();
|
|
79
|
-
queueMicrotask(() => {
|
|
80
|
-
this.dispatchEvent(new CustomEvent('ready', { bubbles: true, composed: true }));
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
protected override _mountOrUpdate() {
|
|
85
|
-
// Prevent mounting until assessment is loaded or no XML is provided
|
|
86
|
-
if (!this.#allowMount && this.#assessmentTestXml) {
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
super._mountOrUpdate();
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
attributeChangedCallback(name: string, _oldValue: string | null, newValue: string | null) {
|
|
93
|
-
if (name === 'assessment-test-xml') {
|
|
94
|
-
this.#assessmentTestXml = newValue;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
if (name === 'assessment-id') {
|
|
98
|
-
this.#assessmentId = newValue ?? undefined;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
if (name === 'candidate-id') {
|
|
102
|
-
this.#candidateId = newValue ?? undefined;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
if (name === 'item-base-url') {
|
|
106
|
-
this.#itemBaseUrl = newValue ?? undefined;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
if (name === 'items-json') {
|
|
110
|
-
const parsed = safeJsonParse<QtiItemMap>(newValue);
|
|
111
|
-
if (parsed) this.#items = parsed;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
if (name === 'config-json') {
|
|
115
|
-
const parsed = safeJsonParse<Partial<BackendAssessmentPlayerConfig>>(newValue);
|
|
116
|
-
if (parsed) this.#config = parsed;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
if (name === 'security-json') {
|
|
120
|
-
const parsed = safeJsonParse<PlayerSecurityConfig>(newValue);
|
|
121
|
-
if (parsed) this.#security = parsed;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
void this.#syncFromQti();
|
|
125
|
-
// Don't call _mountOrUpdate here - let #syncFromQti handle it when done
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
get config() {
|
|
129
|
-
return this.#config;
|
|
130
|
-
}
|
|
131
|
-
set config(value: Partial<BackendAssessmentPlayerConfig>) {
|
|
132
|
-
this.#config = value ?? {};
|
|
133
|
-
// Don't call _mountOrUpdate here - let #syncFromQti handle it when done
|
|
134
|
-
// If assessment is not being loaded (no XML), then update immediately
|
|
135
|
-
if (!this.#assessmentTestXml) {
|
|
136
|
-
this._mountOrUpdate();
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
get security() {
|
|
141
|
-
return this.#security;
|
|
142
|
-
}
|
|
143
|
-
set security(value: PlayerSecurityConfig | undefined) {
|
|
144
|
-
this.#security = value;
|
|
145
|
-
// Don't call _mountOrUpdate here - let #syncFromQti handle it when done
|
|
146
|
-
// If assessment is not being loaded (no XML), then update immediately
|
|
147
|
-
if (!this.#assessmentTestXml) {
|
|
148
|
-
this._mountOrUpdate();
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* Pure-QTI API (preferred): supply an assessmentTest XML string and let the element
|
|
154
|
-
* resolve itemRefs via either an item map (A) or base URL fetching (B).
|
|
155
|
-
*/
|
|
156
|
-
get assessmentTestXml() {
|
|
157
|
-
return this.#assessmentTestXml;
|
|
158
|
-
}
|
|
159
|
-
set assessmentTestXml(value: string | null) {
|
|
160
|
-
this.#assessmentTestXml = value;
|
|
161
|
-
void this.#syncFromQti();
|
|
162
|
-
// Don't call _mountOrUpdate here - let #syncFromQti handle it when done
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
get itemBaseUrl() {
|
|
166
|
-
return this.#itemBaseUrl;
|
|
167
|
-
}
|
|
168
|
-
set itemBaseUrl(value: string | undefined) {
|
|
169
|
-
this.#itemBaseUrl = value;
|
|
170
|
-
void this.#syncFromQti();
|
|
171
|
-
// Don't call _mountOrUpdate here - let #syncFromQti handle it when done
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
get items() {
|
|
175
|
-
return this.#items;
|
|
176
|
-
}
|
|
177
|
-
set items(value: QtiItemMap | undefined) {
|
|
178
|
-
this.#items = value;
|
|
179
|
-
void this.#syncFromQti();
|
|
180
|
-
// Don't call _mountOrUpdate here - let #syncFromQti handle it when done
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
/**
|
|
184
|
-
* Imperative API (proxied through `AssessmentShell` exports)
|
|
185
|
-
*/
|
|
186
|
-
async next() {
|
|
187
|
-
return this._instance?.next?.();
|
|
188
|
-
}
|
|
189
|
-
async previous() {
|
|
190
|
-
return this._instance?.previous?.();
|
|
191
|
-
}
|
|
192
|
-
async navigateTo(index: number) {
|
|
193
|
-
return this._instance?.navigateTo?.(index);
|
|
194
|
-
}
|
|
195
|
-
async navigateToSection(sectionIdentifier: string) {
|
|
196
|
-
return this._instance?.navigateToSection?.(sectionIdentifier);
|
|
197
|
-
}
|
|
198
|
-
async submit() {
|
|
199
|
-
return this._instance?.submit?.();
|
|
200
|
-
}
|
|
201
|
-
getResponses() {
|
|
202
|
-
return this._instance?.getResponses?.();
|
|
203
|
-
}
|
|
204
|
-
getState() {
|
|
205
|
-
return this._instance?.getState?.();
|
|
206
|
-
}
|
|
207
|
-
restoreState(state: unknown) {
|
|
208
|
-
return this._instance?.restoreState?.(state);
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
async #syncFromQti() {
|
|
212
|
-
if (!this.#assessmentTestXml) return;
|
|
213
|
-
|
|
214
|
-
const seq = ++this.#loadSeq;
|
|
215
|
-
this.dispatchEvent(new CustomEvent('load-start', { bubbles: true, composed: true }));
|
|
216
|
-
|
|
217
|
-
try {
|
|
218
|
-
const parsed = parseAssessmentTestXml(this.#assessmentTestXml);
|
|
219
|
-
await resolveItemsForAssessment({
|
|
220
|
-
assessment: parsed,
|
|
221
|
-
itemBaseUrl: this.#itemBaseUrl,
|
|
222
|
-
items: this.#items,
|
|
223
|
-
});
|
|
224
|
-
|
|
225
|
-
if (seq !== this.#loadSeq) return; // superseded
|
|
226
|
-
const assessmentId = this.#assessmentId ?? parsed.identifier ?? 'assessment';
|
|
227
|
-
const candidateId = this.#candidateId ?? 'candidate';
|
|
228
|
-
|
|
229
|
-
const secure = this.#toSecureAssessment(parsed, this.#config.role ?? 'candidate');
|
|
230
|
-
const backend = new ReferenceBackendAdapter();
|
|
231
|
-
backend.registerAssessment(assessmentId, secure);
|
|
232
|
-
this.#backend = backend;
|
|
233
|
-
this.#initSession = { assessmentId, candidateId };
|
|
234
|
-
|
|
235
|
-
this.dispatchEvent(new CustomEvent('load-end', { bubbles: true, composed: true }));
|
|
236
|
-
|
|
237
|
-
// Allow mounting now that backend is ready
|
|
238
|
-
this.#allowMount = true;
|
|
239
|
-
this._mountOrUpdate();
|
|
240
|
-
} catch (e) {
|
|
241
|
-
if (seq !== this.#loadSeq) return;
|
|
242
|
-
// Keep current backend/initSession; component will display error.
|
|
243
|
-
this.dispatchEvent(
|
|
244
|
-
new CustomEvent('load-error', {
|
|
245
|
-
detail: { message: e instanceof Error ? e.message : String(e) },
|
|
246
|
-
bubbles: true,
|
|
247
|
-
composed: true,
|
|
248
|
-
}),
|
|
249
|
-
);
|
|
250
|
-
this._mountOrUpdate(); // Mount/update even on error (will show fallback)
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
#toSecureAssessment(parsed: ParsedAssessmentTest, role: BackendAssessmentPlayerConfig['role']): SecureAssessment {
|
|
255
|
-
const testParts = parsed.testParts ?? [];
|
|
256
|
-
const first = testParts[0];
|
|
257
|
-
|
|
258
|
-
if (!first) {
|
|
259
|
-
return {
|
|
260
|
-
identifier: parsed.identifier ?? 'assessment',
|
|
261
|
-
title: parsed.title ?? 'Assessment',
|
|
262
|
-
navigationMode: 'nonlinear',
|
|
263
|
-
submissionMode: 'simultaneous',
|
|
264
|
-
testParts: [],
|
|
265
|
-
};
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
const flattenSections = (roots: ParsedAssessmentSection[]): ParsedAssessmentSection[] => {
|
|
269
|
-
const out: ParsedAssessmentSection[] = [];
|
|
270
|
-
const stack = [...roots].reverse();
|
|
271
|
-
while (stack.length) {
|
|
272
|
-
const s = stack.pop()!;
|
|
273
|
-
out.push(s);
|
|
274
|
-
if (s.sections && s.sections.length) {
|
|
275
|
-
// depth-first, preserve original order
|
|
276
|
-
for (const child of [...s.sections].reverse()) stack.push(child);
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
return out;
|
|
280
|
-
};
|
|
281
|
-
|
|
282
|
-
const mapSection = (s: ParsedAssessmentSection) => {
|
|
283
|
-
const items =
|
|
284
|
-
s.questionRefs?.map((q) => {
|
|
285
|
-
if (!q.itemXml) {
|
|
286
|
-
throw new Error(`Missing itemXml for item "${q.identifier}" (provide items-json or item-base-url).`);
|
|
287
|
-
}
|
|
288
|
-
return {
|
|
289
|
-
identifier: q.identifier,
|
|
290
|
-
itemXml: q.itemXml,
|
|
291
|
-
role: role ?? 'candidate',
|
|
292
|
-
required: q.required,
|
|
293
|
-
};
|
|
294
|
-
}) ?? [];
|
|
295
|
-
|
|
296
|
-
return {
|
|
297
|
-
identifier: s.identifier,
|
|
298
|
-
title: s.title,
|
|
299
|
-
visible: s.visible ?? true,
|
|
300
|
-
items,
|
|
301
|
-
rubrics: s.rubricBlocks,
|
|
302
|
-
};
|
|
303
|
-
};
|
|
304
|
-
|
|
305
|
-
return {
|
|
306
|
-
identifier: parsed.identifier ?? 'assessment',
|
|
307
|
-
title: parsed.title ?? 'Assessment',
|
|
308
|
-
navigationMode: first.navigationMode ?? 'nonlinear',
|
|
309
|
-
submissionMode: first.submissionMode ?? 'simultaneous',
|
|
310
|
-
testParts: testParts.map((p) => ({
|
|
311
|
-
identifier: p.identifier,
|
|
312
|
-
sections: flattenSections(p.sections).map(mapSection),
|
|
313
|
-
})),
|
|
314
|
-
};
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
getProps() {
|
|
318
|
-
// Ensure we never expose callback-style config as the public API.
|
|
319
|
-
// Consumers should listen to DOM events instead.
|
|
320
|
-
const baseConfig: Partial<BackendAssessmentPlayerConfig> = {
|
|
321
|
-
...this.#config,
|
|
322
|
-
security: this.#security,
|
|
323
|
-
onItemChange: (itemIndex: number, totalItems: number) => {
|
|
324
|
-
const detail: QtiAssessmentItemChangeDetail = { itemIndex, totalItems };
|
|
325
|
-
this.dispatchEvent(
|
|
326
|
-
new CustomEvent<QtiAssessmentItemChangeDetail>('item-change', {
|
|
327
|
-
detail,
|
|
328
|
-
bubbles: true,
|
|
329
|
-
composed: true,
|
|
330
|
-
}),
|
|
331
|
-
);
|
|
332
|
-
},
|
|
333
|
-
onSectionChange: (sectionIndex: number, totalSections: number) => {
|
|
334
|
-
const detail: QtiAssessmentSectionChangeDetail = { sectionIndex, totalSections };
|
|
335
|
-
this.dispatchEvent(
|
|
336
|
-
new CustomEvent<QtiAssessmentSectionChangeDetail>('section-change', {
|
|
337
|
-
detail,
|
|
338
|
-
bubbles: true,
|
|
339
|
-
composed: true,
|
|
340
|
-
}),
|
|
341
|
-
);
|
|
342
|
-
},
|
|
343
|
-
onResponseChange: (responses: Record<string, unknown>) => {
|
|
344
|
-
const detail: QtiAssessmentResponseChangeDetail = { responses: { ...responses } };
|
|
345
|
-
this.dispatchEvent(
|
|
346
|
-
new CustomEvent<QtiAssessmentResponseChangeDetail>('response-change', {
|
|
347
|
-
detail,
|
|
348
|
-
bubbles: true,
|
|
349
|
-
composed: true,
|
|
350
|
-
}),
|
|
351
|
-
);
|
|
352
|
-
},
|
|
353
|
-
onComplete: () => {
|
|
354
|
-
this.dispatchEvent(new CustomEvent('complete', { bubbles: true, composed: true }));
|
|
355
|
-
},
|
|
356
|
-
};
|
|
357
|
-
|
|
358
|
-
const props: any = {
|
|
359
|
-
backend: this.#backend,
|
|
360
|
-
initSession: this.#initSession,
|
|
361
|
-
config: baseConfig,
|
|
362
|
-
onSubmit: (results: AssessmentResults) => {
|
|
363
|
-
const detail: QtiAssessmentSubmitDetail = { results };
|
|
364
|
-
this.dispatchEvent(
|
|
365
|
-
new CustomEvent<QtiAssessmentSubmitDetail>('submit', {
|
|
366
|
-
detail,
|
|
367
|
-
bubbles: true,
|
|
368
|
-
composed: true,
|
|
369
|
-
}),
|
|
370
|
-
);
|
|
371
|
-
},
|
|
372
|
-
};
|
|
373
|
-
// Don't pass typeset at all if not provided (passing undefined can cause issues)
|
|
374
|
-
return props;
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
export function defineQtiAssessmentPlayerElement() {
|
|
379
|
-
if (!customElements.get(QTI_ASSESSMENT_PLAYER_TAG)) {
|
|
380
|
-
customElements.define(QTI_ASSESSMENT_PLAYER_TAG, QtiAssessmentPlayerElement);
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
|
|
@@ -1,197 +0,0 @@
|
|
|
1
|
-
import ItemRenderer from '@pie-qti/assessment-player/components/ItemRenderer.svelte';
|
|
2
|
-
import type { PlayerSecurityConfig, QTIRole } from '@pie-qti/item-player';
|
|
3
|
-
import { QTI_ITEM_PLAYER_TAG } from '../constants.js';
|
|
4
|
-
import { safeJsonParse } from '../utils/json.js';
|
|
5
|
-
import { BaseSvelteMountElement } from './BaseSvelteMountElement.js';
|
|
6
|
-
|
|
7
|
-
export type QtiItemPlayerResponseChangeDetail = {
|
|
8
|
-
responseId: string;
|
|
9
|
-
value: unknown;
|
|
10
|
-
responses: Record<string, unknown>;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export class QtiItemPlayerElement extends BaseSvelteMountElement<Record<string, unknown>> {
|
|
14
|
-
static get observedAttributes() {
|
|
15
|
-
return [
|
|
16
|
-
'item-xml',
|
|
17
|
-
'identifier',
|
|
18
|
-
'title',
|
|
19
|
-
'role',
|
|
20
|
-
'extended-text-editor',
|
|
21
|
-
'responses-json',
|
|
22
|
-
'security-json',
|
|
23
|
-
];
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
protected Component = ItemRenderer;
|
|
27
|
-
|
|
28
|
-
#itemXml: string | null = null;
|
|
29
|
-
#identifier = 'item-1';
|
|
30
|
-
#title: string | undefined;
|
|
31
|
-
#role: QTIRole = 'candidate';
|
|
32
|
-
#extendedTextEditor: 'tiptap' | 'textarea' = 'tiptap';
|
|
33
|
-
#responses: Record<string, unknown> = {};
|
|
34
|
-
#security: PlayerSecurityConfig | undefined;
|
|
35
|
-
|
|
36
|
-
#updateSeq = 0;
|
|
37
|
-
|
|
38
|
-
connectedCallback() {
|
|
39
|
-
super.connectedCallback();
|
|
40
|
-
queueMicrotask(() => {
|
|
41
|
-
this.dispatchEvent(new CustomEvent('ready', { bubbles: true, composed: true }));
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
attributeChangedCallback(name: string, _oldValue: string | null, newValue: string | null) {
|
|
46
|
-
switch (name) {
|
|
47
|
-
case 'item-xml':
|
|
48
|
-
this.#itemXml = newValue;
|
|
49
|
-
break;
|
|
50
|
-
case 'identifier':
|
|
51
|
-
if (newValue) this.#identifier = newValue;
|
|
52
|
-
break;
|
|
53
|
-
case 'title':
|
|
54
|
-
this.#title = newValue ?? undefined;
|
|
55
|
-
break;
|
|
56
|
-
case 'role':
|
|
57
|
-
if (newValue) this.#role = newValue as QTIRole;
|
|
58
|
-
break;
|
|
59
|
-
case 'extended-text-editor':
|
|
60
|
-
if (newValue === 'tiptap' || newValue === 'textarea') {
|
|
61
|
-
this.#extendedTextEditor = newValue;
|
|
62
|
-
}
|
|
63
|
-
break;
|
|
64
|
-
case 'responses-json': {
|
|
65
|
-
const parsed = safeJsonParse<Record<string, unknown>>(newValue);
|
|
66
|
-
if (parsed) this.#responses = parsed;
|
|
67
|
-
break;
|
|
68
|
-
}
|
|
69
|
-
case 'security-json': {
|
|
70
|
-
const parsed = safeJsonParse<PlayerSecurityConfig>(newValue);
|
|
71
|
-
if (parsed) this.#security = parsed;
|
|
72
|
-
break;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
void this.#syncState();
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Preferred API: set QTI via JS property (attributes are awkward for large XML).
|
|
81
|
-
*/
|
|
82
|
-
get itemXml() {
|
|
83
|
-
return this.#itemXml;
|
|
84
|
-
}
|
|
85
|
-
set itemXml(value: string | null) {
|
|
86
|
-
this.#itemXml = value;
|
|
87
|
-
void this.#syncState();
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
get identifier() {
|
|
91
|
-
return this.#identifier;
|
|
92
|
-
}
|
|
93
|
-
set identifier(value: string) {
|
|
94
|
-
this.#identifier = value;
|
|
95
|
-
void this.#syncState();
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
get title() {
|
|
99
|
-
return this.#title ?? '';
|
|
100
|
-
}
|
|
101
|
-
set title(value: string) {
|
|
102
|
-
this.#title = value || undefined;
|
|
103
|
-
void this.#syncState();
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
get role() {
|
|
107
|
-
return this.#role;
|
|
108
|
-
}
|
|
109
|
-
set role(value: QTIRole) {
|
|
110
|
-
this.#role = value;
|
|
111
|
-
void this.#syncState();
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
get extendedTextEditor() {
|
|
115
|
-
return this.#extendedTextEditor;
|
|
116
|
-
}
|
|
117
|
-
set extendedTextEditor(value: 'tiptap' | 'textarea') {
|
|
118
|
-
this.#extendedTextEditor = value;
|
|
119
|
-
void this.#syncState();
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
get responses() {
|
|
123
|
-
return { ...this.#responses };
|
|
124
|
-
}
|
|
125
|
-
set responses(value: Record<string, unknown>) {
|
|
126
|
-
this.#responses = value ?? {};
|
|
127
|
-
void this.#syncState();
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
get security() {
|
|
131
|
-
return this.#security;
|
|
132
|
-
}
|
|
133
|
-
set security(value: PlayerSecurityConfig | undefined) {
|
|
134
|
-
this.#security = value;
|
|
135
|
-
void this.#syncState();
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* Convenience: programmatically set a response.
|
|
140
|
-
*/
|
|
141
|
-
setResponse(responseId: string, value: unknown) {
|
|
142
|
-
this.#responses = { ...this.#responses, [responseId]: value };
|
|
143
|
-
void this.#syncState();
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* Async state synchronization method for consistency with assessment player architecture.
|
|
148
|
-
* Currently synchronous since item player doesn't require async operations,
|
|
149
|
-
* but using async pattern allows future enhancements (validation, preprocessing, etc.)
|
|
150
|
-
*/
|
|
151
|
-
async #syncState() {
|
|
152
|
-
const seq = ++this.#updateSeq;
|
|
153
|
-
|
|
154
|
-
// Future: could add validation, preprocessing, etc. here
|
|
155
|
-
// For now, just proceed to mount/update
|
|
156
|
-
|
|
157
|
-
if (seq !== this.#updateSeq) return; // superseded by newer update
|
|
158
|
-
this._mountOrUpdate();
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
getProps() {
|
|
162
|
-
return {
|
|
163
|
-
questionRef: {
|
|
164
|
-
identifier: this.#identifier,
|
|
165
|
-
title: this.#title,
|
|
166
|
-
itemXml: this.#itemXml ?? '',
|
|
167
|
-
},
|
|
168
|
-
role: this.#role,
|
|
169
|
-
extendedTextEditor: this.#extendedTextEditor,
|
|
170
|
-
responses: this.#responses,
|
|
171
|
-
security: this.#security,
|
|
172
|
-
onResponseChange: (responseId: string, value: unknown) => {
|
|
173
|
-
this.#responses = { ...this.#responses, [responseId]: value };
|
|
174
|
-
const detail: QtiItemPlayerResponseChangeDetail = {
|
|
175
|
-
responseId,
|
|
176
|
-
value,
|
|
177
|
-
responses: { ...this.#responses },
|
|
178
|
-
};
|
|
179
|
-
this.dispatchEvent(
|
|
180
|
-
new CustomEvent<QtiItemPlayerResponseChangeDetail>('response-change', {
|
|
181
|
-
detail,
|
|
182
|
-
bubbles: true,
|
|
183
|
-
composed: true,
|
|
184
|
-
}),
|
|
185
|
-
);
|
|
186
|
-
},
|
|
187
|
-
};
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
export function defineQtiItemPlayerElement() {
|
|
192
|
-
if (!customElements.get(QTI_ITEM_PLAYER_TAG)) {
|
|
193
|
-
customElements.define(QTI_ITEM_PLAYER_TAG, QtiItemPlayerElement);
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
|
package/src/index.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
export { QTI_ASSESSMENT_PLAYER_TAG, QTI_ITEM_PLAYER_TAG } from './constants.js';
|
|
2
|
-
export { defineQtiPlayerElements } from './define.js';
|
|
3
|
-
export {
|
|
4
|
-
defineQtiAssessmentPlayerElement,
|
|
5
|
-
type QtiAssessmentItemChangeDetail,
|
|
6
|
-
QtiAssessmentPlayerElement,
|
|
7
|
-
type QtiAssessmentResponseChangeDetail,
|
|
8
|
-
type QtiAssessmentSectionChangeDetail,
|
|
9
|
-
type QtiAssessmentSubmitDetail,
|
|
10
|
-
} from './elements/QtiAssessmentPlayerElement.js';
|
|
11
|
-
export {
|
|
12
|
-
defineQtiItemPlayerElement,
|
|
13
|
-
QtiItemPlayerElement,
|
|
14
|
-
type QtiItemPlayerResponseChangeDetail,
|
|
15
|
-
} from './elements/QtiItemPlayerElement.js';
|
|
16
|
-
export type { QtiItemMap } from './qti/resolveItems.js';
|
|
17
|
-
export { parseAssessmentTestXml } from './qti/parseAssessmentTest.js';
|
|
18
|
-
export { resolveItemsForAssessment } from './qti/resolveItems.js';
|
|
19
|
-
export type {
|
|
20
|
-
ParsedAssessmentTest,
|
|
21
|
-
ParsedTestPart,
|
|
22
|
-
ParsedAssessmentSection,
|
|
23
|
-
ParsedQuestionRef,
|
|
24
|
-
} from './qti/types.js';
|
|
25
|
-
|
|
26
|
-
|