@qti-components/test 1.7.0 → 1.9.0
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/components/qti-assessment-item-ref/qti-assessment-item-ref.d.ts +12 -0
- package/dist/components/qti-assessment-item-ref/qti-assessment-item-ref.js +55 -28
- package/dist/components/qti-assessment-item-ref/qti-assessment-item-ref.js.map +1 -1
- package/dist/components/qti-test/qti-test.d.ts +16 -2
- package/dist/components/qti-test/qti-test.js +33 -6
- package/dist/components/qti-test/qti-test.js.map +1 -1
- package/dist/components/styles.d.ts +3 -0
- package/dist/components/styles.js +29 -4
- package/dist/components/styles.js.map +1 -1
- package/dist/components/test-check-item/test-check-item.d.ts +2 -0
- package/dist/components/test-check-item/test-check-item.js +20 -2
- package/dist/components/test-check-item/test-check-item.js.map +1 -1
- package/dist/components/test-container/test-container.d.ts +3 -0
- package/dist/components/test-container/test-container.js +5 -1
- package/dist/components/test-container/test-container.js.map +1 -1
- package/dist/components/test-end-attempt/test-end-attempt.js +6 -0
- package/dist/components/test-end-attempt/test-end-attempt.js.map +1 -1
- package/dist/components/test-item-link/test-item-link.js +6 -0
- package/dist/components/test-item-link/test-item-link.js.map +1 -1
- package/dist/components/test-item-to-speech/test-item-to-speech.d.ts +128 -11
- package/dist/components/test-item-to-speech/test-item-to-speech.js +652 -103
- package/dist/components/test-item-to-speech/test-item-to-speech.js.map +1 -1
- package/dist/components/test-navigation/test-navigation.d.ts +9 -1
- package/dist/components/test-navigation/test-navigation.js +62 -17
- package/dist/components/test-navigation/test-navigation.js.map +1 -1
- package/dist/components/test-next/test-next.js +6 -0
- package/dist/components/test-next/test-next.js.map +1 -1
- package/dist/components/test-prev/test-prev.js +6 -0
- package/dist/components/test-prev/test-prev.js.map +1 -1
- package/dist/components/test-scoring-buttons/test-scoring-buttons.d.ts +1 -1
- package/dist/components/test-section-link/test-section-link.js +6 -0
- package/dist/components/test-section-link/test-section-link.js.map +1 -1
- package/dist/elements.d.ts +5 -2
- package/dist/elements.js +3 -2
- package/dist/elements.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/internal/test-host.context.d.ts +24 -0
- package/dist/internal/test-host.context.js +3 -0
- package/dist/internal/test-host.context.js.map +1 -0
- package/dist/mixins/index.d.ts +1 -0
- package/dist/mixins/index.js +1 -0
- package/dist/mixins/index.js.map +1 -1
- package/dist/mixins/test-base.d.ts +7 -2
- package/dist/mixins/test-base.js +53 -19
- package/dist/mixins/test-base.js.map +1 -1
- package/dist/mixins/test-navigation.mixin.d.ts +3 -4
- package/dist/mixins/test-navigation.mixin.js +11 -12
- package/dist/mixins/test-navigation.mixin.js.map +1 -1
- package/dist/mixins/test-processing.mixin.js +3 -1
- package/dist/mixins/test-processing.mixin.js.map +1 -1
- package/dist/mixins/test-state.mixin.d.ts +33 -0
- package/dist/mixins/test-state.mixin.js +130 -0
- package/dist/mixins/test-state.mixin.js.map +1 -0
- package/dist/types/iqti-test.d.ts +8 -5
- package/dist/types/iqti-test.js.map +1 -1
- package/dist/types/qti-test-state.d.ts +45 -0
- package/dist/types/qti-test-state.js +2 -0
- package/dist/types/qti-test-state.js.map +1 -0
- package/package.json +3 -3
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { QTI_TEST_STATE_VERSION } from '../types/qti-test-state';
|
|
2
|
+
const copy = (value) => Array.isArray(value) ? [...value] : (value ?? null);
|
|
3
|
+
const isQtiTestState = (value) => {
|
|
4
|
+
const state = value;
|
|
5
|
+
return (state?.version === QTI_TEST_STATE_VERSION &&
|
|
6
|
+
Array.isArray(state.test?.items) &&
|
|
7
|
+
Array.isArray(state.test?.outcomes) &&
|
|
8
|
+
typeof state.session === 'object' &&
|
|
9
|
+
state.session !== null);
|
|
10
|
+
};
|
|
11
|
+
const toState = (test, session) => ({
|
|
12
|
+
version: QTI_TEST_STATE_VERSION,
|
|
13
|
+
test: {
|
|
14
|
+
items: (test?.items ?? [])
|
|
15
|
+
.filter(item => item.identifier)
|
|
16
|
+
.map(item => ({
|
|
17
|
+
identifier: item.identifier,
|
|
18
|
+
variables: (item.variables ?? []).map(v => ({
|
|
19
|
+
identifier: v.identifier,
|
|
20
|
+
...(v.type ? { type: v.type } : {}),
|
|
21
|
+
value: copy(v.value)
|
|
22
|
+
})),
|
|
23
|
+
...(item.state ? { state: { ...item.state } } : {})
|
|
24
|
+
})),
|
|
25
|
+
outcomes: (test?.testOutcomeVariables ?? []).map(v => ({ identifier: v.identifier, value: copy(v.value) }))
|
|
26
|
+
},
|
|
27
|
+
session: {
|
|
28
|
+
...(session?.navPartId !== undefined ? { navPartId: session.navPartId } : {}),
|
|
29
|
+
...(session?.navSectionId !== undefined ? { navSectionId: session.navSectionId } : {}),
|
|
30
|
+
...(session?.navItemRefId !== undefined ? { navItemRefId: session.navItemRefId } : {})
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
/**
|
|
34
|
+
* Persist and resume a test session through one value, `state`, and one event,
|
|
35
|
+
* `qti-state-changed`.
|
|
36
|
+
*
|
|
37
|
+
* Sits directly on top of `TestBaseMixin`, so its `qti-assessment-test-connected` listener runs
|
|
38
|
+
* after the base has built `testContext.items` from the item-refs, and before the navigation
|
|
39
|
+
* mixin's listener picks the first item to load.
|
|
40
|
+
*/
|
|
41
|
+
export const TestStateMixin = (superClass) => {
|
|
42
|
+
class TestStateClass extends superClass {
|
|
43
|
+
/** A state assigned before the test connected, applied when it does. */
|
|
44
|
+
#pending = null;
|
|
45
|
+
/**
|
|
46
|
+
* False while a test document is loading. Loading resets both contexts and rebuilds them, so
|
|
47
|
+
* the intermediate states are empty — emitting one would invite a host to save it over the
|
|
48
|
+
* real one.
|
|
49
|
+
*/
|
|
50
|
+
#ready = false;
|
|
51
|
+
#lastEmitted = null;
|
|
52
|
+
constructor(...args) {
|
|
53
|
+
super(...args);
|
|
54
|
+
this.addEventListener('qti-testdoc-loaded', () => {
|
|
55
|
+
this.#ready = false;
|
|
56
|
+
this.#lastEmitted = null;
|
|
57
|
+
});
|
|
58
|
+
this.addEventListener('qti-assessment-test-connected', () => {
|
|
59
|
+
if (this.#pending) {
|
|
60
|
+
this.#apply(this.#pending);
|
|
61
|
+
this.#pending = null;
|
|
62
|
+
}
|
|
63
|
+
this.#ready = true;
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
get state() {
|
|
67
|
+
return toState(this.testContext, this.sessionContext);
|
|
68
|
+
}
|
|
69
|
+
set state(value) {
|
|
70
|
+
if (!isQtiTestState(value)) {
|
|
71
|
+
console.warn(`[qti-test] Ignoring a state that is not a version ${QTI_TEST_STATE_VERSION} QtiTestState.`);
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
if (!this.#ready) {
|
|
75
|
+
this.#pending = value;
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
const { navItemRefId, navSectionId } = this.sessionContext;
|
|
79
|
+
this.#apply(value);
|
|
80
|
+
const restored = this.sessionContext;
|
|
81
|
+
if (restored.navItemRefId && restored.navItemRefId !== navItemRefId) {
|
|
82
|
+
this.#requestNavigation('item', restored.navItemRefId);
|
|
83
|
+
}
|
|
84
|
+
else if (!restored.navItemRefId && restored.navSectionId && restored.navSectionId !== navSectionId) {
|
|
85
|
+
this.#requestNavigation('section', restored.navSectionId);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
updated(changed) {
|
|
89
|
+
super.updated(changed);
|
|
90
|
+
if (!this.#ready || !(changed.has('testContext') || changed.has('sessionContext')))
|
|
91
|
+
return;
|
|
92
|
+
const state = this.state;
|
|
93
|
+
const serialized = JSON.stringify(state);
|
|
94
|
+
if (serialized === this.#lastEmitted)
|
|
95
|
+
return;
|
|
96
|
+
this.#lastEmitted = serialized;
|
|
97
|
+
this.dispatchEvent(new CustomEvent('qti-state-changed', { detail: state, bubbles: true, composed: true }));
|
|
98
|
+
}
|
|
99
|
+
#apply(state) {
|
|
100
|
+
// Before the items load this only fills the test context; items already on screen are
|
|
101
|
+
// updated too.
|
|
102
|
+
for (const saved of state.test.items)
|
|
103
|
+
this.updateItemVariables(saved.identifier, saved.variables, saved.state);
|
|
104
|
+
const savedOutcomes = new Map(state.test.outcomes.map(outcome => [outcome.identifier, outcome.value]));
|
|
105
|
+
this.testContext = {
|
|
106
|
+
...this.testContext,
|
|
107
|
+
testOutcomeVariables: this.testContext.testOutcomeVariables?.map(v => savedOutcomes.has(v.identifier) ? { ...v, value: copy(savedOutcomes.get(v.identifier)) } : v)
|
|
108
|
+
};
|
|
109
|
+
// Written before any navigation request, so the linear-mode restriction — which compares
|
|
110
|
+
// against the current position — sees the restored item as current and lets it load.
|
|
111
|
+
this.sessionContext = { ...this.sessionContext, ...this.#validSession(state.session) };
|
|
112
|
+
}
|
|
113
|
+
/** A stored position may point at an item or section a revised test no longer has. */
|
|
114
|
+
#validSession(session) {
|
|
115
|
+
const exists = (selector, id) => !!id && !!this._testElement?.querySelector(`${selector}[identifier="${CSS.escape(id)}"]`);
|
|
116
|
+
return {
|
|
117
|
+
...(exists('qti-test-part', session.navPartId) ? { navPartId: session.navPartId } : {}),
|
|
118
|
+
...(exists('qti-assessment-section', session.navSectionId) ? { navSectionId: session.navSectionId } : {}),
|
|
119
|
+
...(this.testContext.items.some(i => i.identifier === session.navItemRefId)
|
|
120
|
+
? { navItemRefId: session.navItemRefId }
|
|
121
|
+
: {})
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
#requestNavigation(type, id) {
|
|
125
|
+
this.dispatchEvent(new CustomEvent('qti-request-navigation', { detail: { type, id }, bubbles: true, composed: true }));
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return TestStateClass;
|
|
129
|
+
};
|
|
130
|
+
//# sourceMappingURL=test-state.mixin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test-state.mixin.js","sourceRoot":"","sources":["../../src/mixins/test-state.mixin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sB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oBACzE,CAAC,CAAC,EAAE,YAAY,EAAE,OAAO,CAAC,YAAY,EAAE;oBACxC,CAAC,CAAC,EAAE,CAAC;aACR,CAAC;QACJ,CAAC;QAED,kBAAkB,CAAC,IAAwB,EAAE,EAAU;YACrD,IAAI,CAAC,aAAa,CAChB,IAAI,WAAW,CAAC,wBAAwB,EAAE,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CACnG,CAAC;QACJ,CAAC;KACF;IAED,OAAO,cAAkD,CAAC;AAC5D,CAAC,CAAC","sourcesContent":["import { QTI_TEST_STATE_VERSION } from '../types/qti-test-state';\n\nimport type { PropertyValues } from 'lit';\nimport type { SessionContext, TestContext } from '@qti-components/base';\nimport type { QtiTestState, QtiTestStateSession } from '../types/qti-test-state';\nimport type { TestBaseInterface } from './test-base';\n\ntype Constructor<T = {}> = abstract new (...args: any[]) => T;\ntype Value = string | string[] | null;\n\ndeclare global {\n interface GlobalEventHandlersEventMap {\n 'qti-state-changed': CustomEvent<QtiTestState>;\n }\n}\n\nexport interface ITestStateMixin {\n /**\n * The candidate's persistable state: what they answered and where they are.\n *\n * Assign a stored state to resume. It may be assigned at any time: before the test document\n * has loaded it is held and applied as soon as the test connects — before the first item\n * loads, so items and the initial navigation start from it — and after that it is applied\n * immediately and the test navigates to the restored position.\n *\n * Items are matched by item-ref identifier; items the state does not mention start fresh, and\n * stored items, test outcomes or a position the test no longer has are ignored. Restoring is a\n * resume, so linear-mode navigation restrictions do not apply.\n */\n state: QtiTestState;\n}\n\nconst copy = (value: Readonly<Value> | undefined): Value =>\n Array.isArray(value) ? [...value] : ((value as string | null | undefined) ?? null);\n\nconst isQtiTestState = (value: unknown): value is QtiTestState => {\n const state = value as QtiTestState | null;\n return (\n state?.version === QTI_TEST_STATE_VERSION &&\n Array.isArray(state.test?.items) &&\n Array.isArray(state.test?.outcomes) &&\n typeof state.session === 'object' &&\n state.session !== null\n );\n};\n\nconst toState = (test: Readonly<TestContext>, session: Readonly<SessionContext>): QtiTestState => ({\n version: QTI_TEST_STATE_VERSION,\n test: {\n items: (test?.items ?? [])\n .filter(item => item.identifier)\n .map(item => ({\n identifier: item.identifier,\n variables: (item.variables ?? []).map(v => ({\n identifier: v.identifier,\n ...(v.type ? { type: v.type } : {}),\n value: copy(v.value)\n })),\n ...(item.state ? { state: { ...item.state } } : {})\n })),\n outcomes: (test?.testOutcomeVariables ?? []).map(v => ({ identifier: v.identifier, value: copy(v.value) }))\n },\n session: {\n ...(session?.navPartId !== undefined ? { navPartId: session.navPartId } : {}),\n ...(session?.navSectionId !== undefined ? { navSectionId: session.navSectionId } : {}),\n ...(session?.navItemRefId !== undefined ? { navItemRefId: session.navItemRefId } : {})\n }\n});\n\n/**\n * Persist and resume a test session through one value, `state`, and one event,\n * `qti-state-changed`.\n *\n * Sits directly on top of `TestBaseMixin`, so its `qti-assessment-test-connected` listener runs\n * after the base has built `testContext.items` from the item-refs, and before the navigation\n * mixin's listener picks the first item to load.\n */\nexport const TestStateMixin = <T extends Constructor<TestBaseInterface>>(superClass: T) => {\n abstract class TestStateClass extends superClass implements ITestStateMixin {\n /** A state assigned before the test connected, applied when it does. */\n #pending: QtiTestState | null = null;\n\n /**\n * False while a test document is loading. Loading resets both contexts and rebuilds them, so\n * the intermediate states are empty — emitting one would invite a host to save it over the\n * real one.\n */\n #ready = false;\n\n #lastEmitted: string | null = null;\n\n constructor(...args: any[]) {\n super(...args);\n this.addEventListener('qti-testdoc-loaded', () => {\n this.#ready = false;\n this.#lastEmitted = null;\n });\n this.addEventListener('qti-assessment-test-connected', () => {\n if (this.#pending) {\n this.#apply(this.#pending);\n this.#pending = null;\n }\n this.#ready = true;\n });\n }\n\n get state(): QtiTestState {\n return toState(this.testContext, this.sessionContext);\n }\n\n set state(value: QtiTestState) {\n if (!isQtiTestState(value)) {\n console.warn(`[qti-test] Ignoring a state that is not a version ${QTI_TEST_STATE_VERSION} QtiTestState.`);\n return;\n }\n if (!this.#ready) {\n this.#pending = value;\n return;\n }\n\n const { navItemRefId, navSectionId } = this.sessionContext;\n this.#apply(value);\n\n const restored = this.sessionContext;\n if (restored.navItemRefId && restored.navItemRefId !== navItemRefId) {\n this.#requestNavigation('item', restored.navItemRefId);\n } else if (!restored.navItemRefId && restored.navSectionId && restored.navSectionId !== navSectionId) {\n this.#requestNavigation('section', restored.navSectionId);\n }\n }\n\n protected override updated(changed: PropertyValues): void {\n super.updated(changed);\n if (!this.#ready || !(changed.has('testContext') || changed.has('sessionContext'))) return;\n\n const state = this.state;\n const serialized = JSON.stringify(state);\n if (serialized === this.#lastEmitted) return;\n this.#lastEmitted = serialized;\n this.dispatchEvent(new CustomEvent('qti-state-changed', { detail: state, bubbles: true, composed: true }));\n }\n\n #apply(state: QtiTestState): void {\n // Before the items load this only fills the test context; items already on screen are\n // updated too.\n for (const saved of state.test.items) this.updateItemVariables(saved.identifier, saved.variables, saved.state);\n\n const savedOutcomes = new Map(state.test.outcomes.map(outcome => [outcome.identifier, outcome.value]));\n this.testContext = {\n ...this.testContext,\n testOutcomeVariables: this.testContext.testOutcomeVariables?.map(v =>\n savedOutcomes.has(v.identifier) ? { ...v, value: copy(savedOutcomes.get(v.identifier)) } : v\n )\n };\n\n // Written before any navigation request, so the linear-mode restriction — which compares\n // against the current position — sees the restored item as current and lets it load.\n this.sessionContext = { ...this.sessionContext, ...this.#validSession(state.session) };\n }\n\n /** A stored position may point at an item or section a revised test no longer has. */\n #validSession(session: QtiTestStateSession): QtiTestStateSession {\n const exists = (selector: string, id: string | null | undefined) =>\n !!id && !!this._testElement?.querySelector(`${selector}[identifier=\"${CSS.escape(id)}\"]`);\n return {\n ...(exists('qti-test-part', session.navPartId) ? { navPartId: session.navPartId } : {}),\n ...(exists('qti-assessment-section', session.navSectionId) ? { navSectionId: session.navSectionId } : {}),\n ...(this.testContext.items.some(i => i.identifier === session.navItemRefId)\n ? { navItemRefId: session.navItemRefId }\n : {})\n };\n }\n\n #requestNavigation(type: 'item' | 'section', id: string): void {\n this.dispatchEvent(\n new CustomEvent('qti-request-navigation', { detail: { type, id }, bubbles: true, composed: true })\n );\n }\n }\n\n return TestStateClass as Constructor<ITestStateMixin> & T;\n};\n"]}
|
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
import type { ITestNavigationMixin } from '../mixins/test-navigation.mixin';
|
|
2
|
+
import type { ITestStateMixin } from '../mixins/test-state.mixin';
|
|
3
|
+
import type { ItemVariableValue } from '../mixins/test-base';
|
|
2
4
|
import type { LitElement } from 'lit';
|
|
3
|
-
import type { ConfigContext, TestContext } from '@qti-components/base';
|
|
5
|
+
import type { ConfigContext, ItemContext, TestContext } from '@qti-components/base';
|
|
4
6
|
import type { SessionContext } from '@qti-components/base';
|
|
5
|
-
import type { OutcomeVariable, VariableDeclaration
|
|
6
|
-
export type { ITestNavigationMixin };
|
|
7
|
-
export interface IQtiTest extends LitElement, ITestNavigationMixin, ITestProcessingMixin, IMyQtiTest {
|
|
7
|
+
import type { OutcomeVariable, VariableDeclaration } from '@qti-components/base';
|
|
8
|
+
export type { ITestNavigationMixin, ITestStateMixin };
|
|
9
|
+
export interface IQtiTest extends LitElement, ITestNavigationMixin, ITestProcessingMixin, ITestStateMixin, IMyQtiTest {
|
|
8
10
|
}
|
|
9
11
|
export interface IMyQtiTest {
|
|
10
12
|
testContext: Readonly<TestContext>;
|
|
11
13
|
sessionContext: Readonly<SessionContext>;
|
|
12
14
|
configContext: ConfigContext;
|
|
13
|
-
|
|
15
|
+
/** Sets values on one item, keyed by its `qti-assessment-item-ref` identifier. */
|
|
16
|
+
updateItemVariables(itemRefID: string, variables: readonly ItemVariableValue[], state?: ItemContext['state']): void;
|
|
14
17
|
}
|
|
15
18
|
export interface ITestProcessingMixin {
|
|
16
19
|
updateOutcomeVariable(identifier: string, value: string | string[] | undefined): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"iqti-test.js","sourceRoot":"","sources":["../../src/types/iqti-test.ts"],"names":[],"mappings":"","sourcesContent":["import type { ITestNavigationMixin } from '../mixins/test-navigation.mixin';\nimport type { LitElement } from 'lit';\nimport type { ConfigContext, TestContext } from '@qti-components/base';\nimport type { SessionContext } from '@qti-components/base';\nimport type { OutcomeVariable, VariableDeclaration
|
|
1
|
+
{"version":3,"file":"iqti-test.js","sourceRoot":"","sources":["../../src/types/iqti-test.ts"],"names":[],"mappings":"","sourcesContent":["import type { ITestNavigationMixin } from '../mixins/test-navigation.mixin';\nimport type { ITestStateMixin } from '../mixins/test-state.mixin';\nimport type { ItemVariableValue } from '../mixins/test-base';\nimport type { LitElement } from 'lit';\nimport type { ConfigContext, ItemContext, TestContext } from '@qti-components/base';\nimport type { SessionContext } from '@qti-components/base';\nimport type { OutcomeVariable, VariableDeclaration } from '@qti-components/base';\n\n/*\n * `ITestNavigationMixin` is declared beside the class it describes, in\n * ../mixins/test-navigation.mixin, and re-exported here so this module's public surface is\n * unchanged. Keeping the declaration there is what lets the mixin `implements` it — the\n * compiler then holds the interface and the class together — while the imports still run\n * one way, types -> mixin, which `pnpm madge` requires.\n */\nexport type { ITestNavigationMixin, ITestStateMixin };\n\nexport interface IQtiTest extends LitElement, ITestNavigationMixin, ITestProcessingMixin, ITestStateMixin, IMyQtiTest {}\n\nexport interface IMyQtiTest {\n // Properties from TestBase\n testContext: Readonly<TestContext>;\n sessionContext: Readonly<SessionContext>;\n configContext: ConfigContext;\n\n // Methods from TestBase\n /** Sets values on one item, keyed by its `qti-assessment-item-ref` identifier. */\n updateItemVariables(itemRefID: string, variables: readonly ItemVariableValue[], state?: ItemContext['state']): void;\n}\n\nexport interface ITestProcessingMixin {\n // Methods from TestProcessingMixin\n updateOutcomeVariable(identifier: string, value: string | string[] | undefined): void;\n getOutcome(identifier: string): Readonly<OutcomeVariable>;\n getVariable(identifier: string): Readonly<VariableDeclaration<string | string[] | null>>;\n outcomeProcessing(): boolean;\n}\n"]}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Everything a host needs to persist to resume a candidate's test session, and nothing else.
|
|
3
|
+
*
|
|
4
|
+
* Read it from `qtiTest.state` or the `qti-state-changed` event, store it wherever you like —
|
|
5
|
+
* a database, `localStorage`, `sessionStorage` — and assign it back to `qtiTest.state` to resume.
|
|
6
|
+
*
|
|
7
|
+
* Deliberately not here:
|
|
8
|
+
* - declaration metadata (`baseType`, `cardinality`, `correctResponse`, `mapping`, …): it comes
|
|
9
|
+
* from the item XML on every load, and persisting the answer key with the candidate's data is
|
|
10
|
+
* both bloat and a leak;
|
|
11
|
+
* - `configContext` and `qtiContext`: inputs the host supplies on every load, not session state.
|
|
12
|
+
* The shuffle `seed` in particular must be passed in again, or the restored order changes;
|
|
13
|
+
* - `view`: a role the host decides, not something the candidate produced;
|
|
14
|
+
* - anything computed — scores per section, `done`, `active` — which is rederived from this.
|
|
15
|
+
*/
|
|
16
|
+
export interface QtiTestState {
|
|
17
|
+
/** Bumped on any incompatible change to this shape. A state with another version is ignored. */
|
|
18
|
+
version: 1;
|
|
19
|
+
test: {
|
|
20
|
+
items: QtiTestStateItem[];
|
|
21
|
+
/** Test-level outcome values. Only outcomes the test declares are restored. */
|
|
22
|
+
outcomes: QtiTestStateValue[];
|
|
23
|
+
};
|
|
24
|
+
session: QtiTestStateSession;
|
|
25
|
+
}
|
|
26
|
+
export interface QtiTestStateItem {
|
|
27
|
+
/** The `qti-assessment-item-ref` identifier. */
|
|
28
|
+
identifier: string;
|
|
29
|
+
variables: (QtiTestStateValue & {
|
|
30
|
+
type?: 'response' | 'outcome' | 'template' | 'context';
|
|
31
|
+
})[];
|
|
32
|
+
/** Opaque per-interaction state keyed by response identifier, e.g. a PCI's `getState()`. */
|
|
33
|
+
state?: Record<string, string | null>;
|
|
34
|
+
}
|
|
35
|
+
export interface QtiTestStateValue {
|
|
36
|
+
identifier: string;
|
|
37
|
+
value: string | string[] | null;
|
|
38
|
+
}
|
|
39
|
+
/** Where the candidate is. */
|
|
40
|
+
export interface QtiTestStateSession {
|
|
41
|
+
navPartId?: string | null;
|
|
42
|
+
navSectionId?: string | null;
|
|
43
|
+
navItemRefId?: string | null;
|
|
44
|
+
}
|
|
45
|
+
export declare const QTI_TEST_STATE_VERSION = 1;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"qti-test-state.js","sourceRoot":"","sources":["../../src/types/qti-test-state.ts"],"names":[],"mappings":"AA8CA,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,CAAC","sourcesContent":["/**\n * Everything a host needs to persist to resume a candidate's test session, and nothing else.\n *\n * Read it from `qtiTest.state` or the `qti-state-changed` event, store it wherever you like —\n * a database, `localStorage`, `sessionStorage` — and assign it back to `qtiTest.state` to resume.\n *\n * Deliberately not here:\n * - declaration metadata (`baseType`, `cardinality`, `correctResponse`, `mapping`, …): it comes\n * from the item XML on every load, and persisting the answer key with the candidate's data is\n * both bloat and a leak;\n * - `configContext` and `qtiContext`: inputs the host supplies on every load, not session state.\n * The shuffle `seed` in particular must be passed in again, or the restored order changes;\n * - `view`: a role the host decides, not something the candidate produced;\n * - anything computed — scores per section, `done`, `active` — which is rederived from this.\n */\nexport interface QtiTestState {\n /** Bumped on any incompatible change to this shape. A state with another version is ignored. */\n version: 1;\n test: {\n items: QtiTestStateItem[];\n /** Test-level outcome values. Only outcomes the test declares are restored. */\n outcomes: QtiTestStateValue[];\n };\n session: QtiTestStateSession;\n}\n\nexport interface QtiTestStateItem {\n /** The `qti-assessment-item-ref` identifier. */\n identifier: string;\n variables: (QtiTestStateValue & { type?: 'response' | 'outcome' | 'template' | 'context' })[];\n /** Opaque per-interaction state keyed by response identifier, e.g. a PCI's `getState()`. */\n state?: Record<string, string | null>;\n}\n\nexport interface QtiTestStateValue {\n identifier: string;\n value: string | string[] | null;\n}\n\n/** Where the candidate is. */\nexport interface QtiTestStateSession {\n navPartId?: string | null;\n navSectionId?: string | null;\n navItemRefId?: string | null;\n}\n\nexport const QTI_TEST_STATE_VERSION = 1;\n"]}
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@qti-components/test",
|
|
3
3
|
"description": "QTI test utilities",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.9.0",
|
|
5
5
|
"author": "",
|
|
6
6
|
"dependencies": {
|
|
7
7
|
"@heximal/templates": "^0.1.5",
|
|
8
|
-
"@qti-components/base": "^2.
|
|
9
|
-
"@qti-components/elements": "^1.
|
|
8
|
+
"@qti-components/base": "^2.4.0",
|
|
9
|
+
"@qti-components/elements": "^1.9.0",
|
|
10
10
|
"@qti-components/interactions": "^1.10.4",
|
|
11
11
|
"@qti-components/processing": "^1.6.0",
|
|
12
12
|
"@qti-components/theme": "^2.2.1",
|