@qti-components/test 2.0.0-next.24 → 2.0.0-next.26
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/test-navigation/test-navigation.d.ts +7 -0
- package/dist/components/test-navigation/test-navigation.js +68 -3
- package/dist/components/test-navigation/test-navigation.js.map +1 -1
- package/dist/internal/derive-computed-context.d.ts +7 -2
- package/dist/internal/derive-computed-context.js +57 -7
- package/dist/internal/derive-computed-context.js.map +1 -1
- package/dist/internal/item-session-facts.d.ts +18 -0
- package/dist/internal/item-session-facts.js +36 -0
- package/dist/internal/item-session-facts.js.map +1 -0
- package/package.json +3 -3
|
@@ -10,6 +10,13 @@ import type { TestContext } from '@qti-components/base';
|
|
|
10
10
|
export declare class TestNavigation extends LitElement {
|
|
11
11
|
#private;
|
|
12
12
|
identifier: string | undefined;
|
|
13
|
+
/**
|
|
14
|
+
* Your own per-item fields, by item-ref `identifier`: each `computedContext` item carries them as
|
|
15
|
+
* given under `data`, without the identifier, and so does every view of it a plugin derives. They
|
|
16
|
+
* never replace a field the test, the item or the candidate's state gives, whatever its name; a
|
|
17
|
+
* template reads `activeItem.data.<field>`. To mark an item as scored by hand, set
|
|
18
|
+
* `external-scored` on its `SCORE` declaration in `postLoadTransformCallback`.
|
|
19
|
+
*/
|
|
13
20
|
initContext: {
|
|
14
21
|
identifier: string;
|
|
15
22
|
[key: string]: any;
|
|
@@ -8,13 +8,14 @@ import { ContextConsumer, consume, provide } from '@lit/context';
|
|
|
8
8
|
import { html, LitElement } from 'lit';
|
|
9
9
|
import { property, state } from 'lit/decorators.js';
|
|
10
10
|
import { computedContext } from '@qti-components/base';
|
|
11
|
-
import { buildTestModel } from '@qti-components/delivery';
|
|
11
|
+
import { buildTestModel, endItemAttempt, followItemSession } from '@qti-components/delivery';
|
|
12
12
|
import { configContext } from '@qti-components/base';
|
|
13
13
|
import { testContext } from '@qti-components/base';
|
|
14
14
|
import { sessionContext } from '@qti-components/base';
|
|
15
15
|
import { listenPublic as listenItemPublic } from '@qti-components/elements/public-events';
|
|
16
16
|
import { assessOptimality, deriveComputedContext, isItemDone } from '../../internal/derive-computed-context';
|
|
17
17
|
import { itemFactsContext } from '../../internal/item-facts.context';
|
|
18
|
+
import { attemptsOf, itemSessionFacts } from '../../internal/item-session-facts';
|
|
18
19
|
import { renderedMarkup } from '../../internal/rendered-markup';
|
|
19
20
|
import { testHostContext } from '../../internal/test-host.context';
|
|
20
21
|
import { listenPublic } from '../../public-events';
|
|
@@ -68,9 +69,25 @@ export class TestNavigation extends LitElement {
|
|
|
68
69
|
* doesn't flip `done` until the candidate ends the attempt.
|
|
69
70
|
*/
|
|
70
71
|
#optimality;
|
|
72
|
+
/**
|
|
73
|
+
* Each item session's lifecycle state, by item-ref identifier, changed only through the lifecycle
|
|
74
|
+
* table (`followItemSession` as the candidate moves, `endItemAttempt` when an attempt ends). It
|
|
75
|
+
* lives here until `DeliveryState` holds it (roadmap 1, T3d); a session whose attempts change
|
|
76
|
+
* outside an ended attempt (a restored or assigned state) is seeded again.
|
|
77
|
+
*/
|
|
78
|
+
#sessions;
|
|
79
|
+
/** Set while `auto-score-items` scores a change: that run is not the candidate ending an attempt. */
|
|
80
|
+
#autoScoring;
|
|
71
81
|
constructor() {
|
|
72
82
|
super();
|
|
73
83
|
this.identifier = undefined;
|
|
84
|
+
/**
|
|
85
|
+
* Your own per-item fields, by item-ref `identifier`: each `computedContext` item carries them as
|
|
86
|
+
* given under `data`, without the identifier, and so does every view of it a plugin derives. They
|
|
87
|
+
* never replace a field the test, the item or the candidate's state gives, whatever its name; a
|
|
88
|
+
* template reads `activeItem.data.<field>`. To mark an item as scored by hand, set
|
|
89
|
+
* `external-scored` on its `SCORE` declaration in `postLoadTransformCallback`.
|
|
90
|
+
*/
|
|
74
91
|
this.initContext = [];
|
|
75
92
|
this.#warnedQtiContext = false;
|
|
76
93
|
/**
|
|
@@ -97,6 +114,15 @@ export class TestNavigation extends LitElement {
|
|
|
97
114
|
* doesn't flip `done` until the candidate ends the attempt.
|
|
98
115
|
*/
|
|
99
116
|
this.#optimality = new Map();
|
|
117
|
+
/**
|
|
118
|
+
* Each item session's lifecycle state, by item-ref identifier, changed only through the lifecycle
|
|
119
|
+
* table (`followItemSession` as the candidate moves, `endItemAttempt` when an attempt ends). It
|
|
120
|
+
* lives here until `DeliveryState` holds it (roadmap 1, T3d); a session whose attempts change
|
|
121
|
+
* outside an ended attempt (a restored or assigned state) is seeded again.
|
|
122
|
+
*/
|
|
123
|
+
this.#sessions = new Map();
|
|
124
|
+
/** Set while `auto-score-items` scores a change: that run is not the candidate ending an attempt. */
|
|
125
|
+
this.#autoScoring = false;
|
|
100
126
|
/** `computedContext.itemElement`: one function for the life of this element, carried along by every update. */
|
|
101
127
|
this.#itemElement = (identifier) => this.#assessmentItemFor(identifier) ?? null;
|
|
102
128
|
/** The items this navigation disabled because their attempts are used, so it releases only those. */
|
|
@@ -122,11 +148,41 @@ export class TestNavigation extends LitElement {
|
|
|
122
148
|
return;
|
|
123
149
|
const optimality = assessOptimality(itemContext);
|
|
124
150
|
this.#optimality.set(itemContext.identifier, optimality);
|
|
151
|
+
this.#endAttempt(itemContext);
|
|
125
152
|
const computedItem = this.computedItemFor(itemContext.identifier);
|
|
126
153
|
const numAttempts = Number(itemContext.variables?.find(v => v.identifier === 'numAttempts')?.value) || 0;
|
|
127
154
|
const completionStatus = itemContext.variables?.find(v => v.identifier === 'completionStatus')?.value;
|
|
128
155
|
this.afterAttemptEnded(event.composedPath()[0]?.closest('qti-assessment-item'), computedItem, isItemDone(numAttempts, optimality, computedItem?.sessionControl?.maxAttempts, computedItem?.adaptive, completionStatus));
|
|
129
156
|
}
|
|
157
|
+
/** Moves the item's session on for its ended attempt; an auto-scored change only updates its count. */
|
|
158
|
+
#endAttempt(itemContext) {
|
|
159
|
+
const facts = this.#sessionFacts().get(itemContext.identifier);
|
|
160
|
+
if (!facts)
|
|
161
|
+
return;
|
|
162
|
+
const ended = { ...facts, ...attemptsOf(itemContext) };
|
|
163
|
+
const previous = this.#sessions.get(itemContext.identifier);
|
|
164
|
+
this.#sessions.set(itemContext.identifier, this.#autoScoring
|
|
165
|
+
? { state: previous?.state ?? followItemSession(undefined, ended).state, numAttempts: ended.numAttempts }
|
|
166
|
+
: endItemAttempt(previous, ended));
|
|
167
|
+
}
|
|
168
|
+
/** The facts of every item session now: the model, the item facts, the contexts and the items on screen. */
|
|
169
|
+
#sessionFacts() {
|
|
170
|
+
if (!this.#model)
|
|
171
|
+
return new Map();
|
|
172
|
+
const presented = new Set([...(this.#testElement?.querySelectorAll('qti-assessment-item-ref') ?? [])]
|
|
173
|
+
.filter(itemRef => itemRef.assessmentItem)
|
|
174
|
+
.map(itemRef => itemRef.identifier));
|
|
175
|
+
return itemSessionFacts(this.#model, this._itemFacts, this._testContext?.items, {
|
|
176
|
+
current: this._sessionContext?.navItemRefId,
|
|
177
|
+
presented
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
/** Moves every item session on for where the candidate is now. */
|
|
181
|
+
#followSessions() {
|
|
182
|
+
for (const [identifier, facts] of this.#sessionFacts()) {
|
|
183
|
+
this.#sessions.set(identifier, followItemSession(this.#sessions.get(identifier), facts));
|
|
184
|
+
}
|
|
185
|
+
}
|
|
130
186
|
/**
|
|
131
187
|
* Extension point for presentation packages reacting to an ended attempt.
|
|
132
188
|
* `done` is settled here — from the freshly latched optimality and the
|
|
@@ -186,7 +242,13 @@ export class TestNavigation extends LitElement {
|
|
|
186
242
|
scoreOutcomeIdentifier.externalScored === null &&
|
|
187
243
|
assessmentItem.adaptive === 'false') {
|
|
188
244
|
const reportValidityAfterScoring = this.configContext?.reportValidityAfterScoring === true ? true : false;
|
|
189
|
-
|
|
245
|
+
this.#autoScoring = true;
|
|
246
|
+
try {
|
|
247
|
+
assessmentItem.processResponse(true, reportValidityAfterScoring);
|
|
248
|
+
}
|
|
249
|
+
finally {
|
|
250
|
+
this.#autoScoring = false;
|
|
251
|
+
}
|
|
190
252
|
}
|
|
191
253
|
}
|
|
192
254
|
}
|
|
@@ -196,8 +258,9 @@ export class TestNavigation extends LitElement {
|
|
|
196
258
|
/* PK: on test connected we can build the computed context */
|
|
197
259
|
#handleTestConnected(event) {
|
|
198
260
|
this.#testElement = event.detail;
|
|
199
|
-
// A fresh test invalidates the per-test optimality latches.
|
|
261
|
+
// A fresh test invalidates the per-test optimality latches and item sessions.
|
|
200
262
|
this.#optimality.clear();
|
|
263
|
+
this.#sessions.clear();
|
|
201
264
|
// Set the testIdentifier in qtiContext if not already set
|
|
202
265
|
if (!this.qtiContext.QTI_CONTEXT?.testIdentifier) {
|
|
203
266
|
const currentContext = this.qtiContext.QTI_CONTEXT || {
|
|
@@ -237,6 +300,7 @@ export class TestNavigation extends LitElement {
|
|
|
237
300
|
/** `computedContext`, derived anew from its inputs (`deriveComputedContext`), never from the previous one. */
|
|
238
301
|
#derive() {
|
|
239
302
|
this.#seedOptimality();
|
|
303
|
+
this.#followSessions();
|
|
240
304
|
return deriveComputedContext({
|
|
241
305
|
model: this.#model,
|
|
242
306
|
itemFacts: this._itemFacts,
|
|
@@ -245,6 +309,7 @@ export class TestNavigation extends LitElement {
|
|
|
245
309
|
infoItemCategory: this.configContext?.infoItemCategory,
|
|
246
310
|
itemData: this.initContext,
|
|
247
311
|
optimality: this.#optimality,
|
|
312
|
+
lifecycle: new Map([...this.#sessions].map(([identifier, session]) => [identifier, session.state])),
|
|
248
313
|
itemElement: this.#itemElement
|
|
249
314
|
});
|
|
250
315
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"test-navigation.js","sourceRoot":"","sources":["../../../src/components/test-navigation/test-navigation.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,eAAe,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACjE,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,KAAK,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,KAAK,EAAE;mDAC8D;AAuD/D;IAFN,KAAK,EAAE;IACP,OAAO,CAAC,EAAE,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;qDACZ;AAI/B;IAFT,KAAK,EAAE;IACP,OAAO,CAAC,EAAE,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;oDACd;AAI3B;IAFT,KAAK,EAAE;IACP,OAAO,CAAC,EAAE,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;uDACX;AAKjC;IAFT,KAAK,EAAE;IACP,OAAO,CAAC,EAAE,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;kDAClB;AAI5B;IAFT,KAAK,EAAE;IACP,OAAO,CAAC,EAAE,OAAO,EAAE,eAAe,EAAE,CAAC;uDACK;AAEiB;IAA3D,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,kBAAkB,EAAE,CAAC;sDAAwB","sourcesContent":["import { ContextConsumer, consume, provide } from '@lit/context';\nimport { html, LitElement } from 'lit';\nimport { property, state } from 'lit/decorators.js';\n\nimport { computedContext } from '@qti-components/base';\nimport { buildTestModel } from '@qti-components/delivery';\nimport { configContext } from '@qti-components/base';\nimport { testContext } from '@qti-components/base';\nimport { sessionContext } from '@qti-components/base';\nimport { listenPublic as listenItemPublic } from '@qti-components/elements/public-events';\n\nimport { assessOptimality, deriveComputedContext, isItemDone } from '../../internal/derive-computed-context';\nimport { itemFactsContext } from '../../internal/item-facts.context';\nimport { renderedMarkup } from '../../internal/rendered-markup';\nimport { testHostContext } from '../../internal/test-host.context';\nimport { listenPublic } from '../../public-events';\n\nimport type { QtiAssessmentItem } from '@qti-components/elements';\nimport type { QtiContext } from '@qti-components/base';\nimport type { OutcomeVariable } from '@qti-components/base';\nimport type { ComputedContext, ComputedItem } from '@qti-components/base';\nimport type { PropertyValues } from 'lit';\nimport type { QtiAssessmentItemRef } from '../qti-assessment-item-ref/qti-assessment-item-ref';\nimport type { QtiAssessmentTest } from '../qti-assessment-test/qti-assessment-test';\nimport type { TestModel } from '@qti-components/delivery';\nimport type { ItemOptimality } from '../../internal/derive-computed-context';\nimport type { ItemFactsByRef } from '../../internal/item-facts.context';\nimport type { ConfigContext } from '@qti-components/base';\nimport type { SessionContext } from '@qti-components/base';\nimport type { TestContext } from '@qti-components/base';\nimport type { ItemContext } from '@qti-components/base';\n\n/** A new object each time: a host that mutates the one it read must not change anyone else's. */\nconst newQtiContext = (): QtiContext => ({\n QTI_CONTEXT: { testIdentifier: '', candidateIdentifier: '', environmentIdentifier: 'default' }\n});\n\nexport class TestNavigation extends LitElement {\n @property({ type: String }) identifier: string | undefined = undefined;\n\n @state()\n public initContext: { identifier: string; [key: string]: any }[] = [];\n\n /**\n * @deprecated Set `qtiContext` on `qti-test`, which provides it. This is an alias for the\n * enclosing test's: reading returns it, writing replaces it, so a host that has always set the\n * shuffle seed here keeps working. Removed in the next major.\n *\n * Written before the navigation is inside a test, it waits and is handed over on connect.\n */\n public get qtiContext(): QtiContext {\n return this.#owner()?.qtiContext ?? (this.#pendingQtiContext ??= newQtiContext());\n }\n\n public set qtiContext(value: QtiContext) {\n if (!this.#warnedQtiContext) {\n this.#warnedQtiContext = true;\n console.warn(\n '[qti-components] `test-navigation.qtiContext` is deprecated and will be removed in the next major ' +\n 'release. Set `qtiContext` on `<qti-test>` instead; it is the same value.'\n );\n }\n this.#writeQtiContext(value);\n }\n\n #pendingQtiContext?: QtiContext;\n #warnedQtiContext = false;\n\n /** The write the library itself makes. Not the deprecated setter, so it never warns about itself. */\n #writeQtiContext(value: QtiContext): void {\n const owner = this.#owner();\n if (owner) owner.qtiContext = value;\n else this.#pendingQtiContext = value;\n }\n\n /**\n * The `qti-test` this navigation is in, found through context so it works across shadow roots.\n * A write made before it is known waits in `#pendingQtiContext` and is handed over on arrival.\n */\n #testHost = new ContextConsumer(this, {\n context: testHostContext,\n subscribe: true,\n callback: host => {\n if (host && this.#pendingQtiContext) {\n host.qtiContext = this.#pendingQtiContext;\n this.#pendingQtiContext = undefined;\n }\n }\n });\n\n #owner(): { qtiContext: QtiContext } | null {\n return this.#testHost.value ?? null;\n }\n\n @state()\n @consume({ context: configContext, subscribe: true })\n public configContext: ConfigContext = {};\n\n @state()\n @consume({ context: testContext, subscribe: true })\n protected _testContext?: TestContext;\n\n @state()\n @consume({ context: sessionContext, subscribe: true })\n protected _sessionContext?: SessionContext;\n\n /** Read from each item's XML when `qti-test` fetches it; see `itemFactsContext`. */\n @state()\n @consume({ context: itemFactsContext, subscribe: true })\n protected _itemFacts?: ItemFactsByRef;\n\n @state()\n @provide({ context: computedContext })\n protected computedContext: ComputedContext;\n\n @property({ type: Boolean, attribute: 'auto-score-items' }) autoScoreItems = false;\n\n #testElement: QtiAssessmentTest;\n\n /**\n * Whether each item's last *ended attempt* reached the optimal outcome, keyed\n * by item-ref id. Written from #handleItemContextUpdated when processResponse\n * ends an attempt — never on a plain selection. Mirrors how inline feedback\n * only re-evaluates when an attempt is processed, so a freshly-picked answer\n * doesn't flip `done` until the candidate ends the attempt.\n */\n #optimality = new Map<string, ItemOptimality>();\n\n constructor() {\n super();\n listenPublic(this, 'qc-test-loaded', this.#handleTestConnected.bind(this));\n\n listenItemPublic(this, 'qc-item-response-changed', this.#handleInteractionChanged.bind(this));\n this.addEventListener('qti-item-context-updated', this.#handleItemContextUpdated.bind(this));\n\n listenPublic(this, 'qc-test-end-attempt', this.#handleTestEndAttempt.bind(this));\n listenPublic(this, 'qc-test-update-outcome', this.#handleTestUpdateOutcomeVariable.bind(this));\n }\n\n /**\n * Latch whether an item reached its optimal outcome whenever it has just ended\n * an attempt. processResponse — fired by test-end-attempt, autoscore, or an\n * in-item end-attempt interaction — flags its context update with\n * `responseProcessed`; a plain selection updates the context without it, so\n * `done` can't flip until the candidate actually ends the attempt.\n */\n #handleItemContextUpdated(event: CustomEvent<{ itemContext: ItemContext; responseProcessed?: boolean }>) {\n if (!event.detail?.responseProcessed) return;\n const itemContext = event.detail.itemContext;\n if (!itemContext?.identifier) return;\n const optimality = assessOptimality(itemContext);\n this.#optimality.set(itemContext.identifier, optimality);\n\n const computedItem = this.computedItemFor(itemContext.identifier);\n const numAttempts = Number(itemContext.variables?.find(v => v.identifier === 'numAttempts')?.value) || 0;\n const completionStatus = itemContext.variables?.find(v => v.identifier === 'completionStatus')?.value as string;\n this.afterAttemptEnded(\n (event.composedPath()[0] as HTMLElement)?.closest<QtiAssessmentItem>('qti-assessment-item'),\n computedItem,\n isItemDone(\n numAttempts,\n optimality,\n computedItem?.sessionControl?.maxAttempts,\n computedItem?.adaptive,\n completionStatus\n )\n );\n }\n\n /**\n * Extension point for presentation packages reacting to an ended attempt.\n * `done` is settled here — from the freshly latched optimality and the\n * session-control cascade — because the computed context only catches up on\n * the next update, after this event has finished bubbling.\n */\n protected afterAttemptEnded(\n _assessmentItem: QtiAssessmentItem | undefined,\n _computedItem: ComputedItem | undefined,\n _done: boolean\n ): void {}\n\n /** The computed-context entry for an item, from the session-control cascade. */\n protected computedItemFor(identifier: string): ComputedItem | undefined {\n return this.computedContext?.testParts\n ?.flatMap(part => part.sections)\n .flatMap(section => section.items)\n .find(i => i.identifier === identifier);\n }\n\n /** The assessment item for an item-ref id, if it has been rendered. */\n #assessmentItemFor(identifier: string | undefined): QtiAssessmentItem | undefined {\n if (!identifier) return undefined;\n const itemRef = this.#testElement?.querySelector<QtiAssessmentItemRef>(\n `qti-assessment-item-ref[identifier=\"${CSS.escape(identifier)}\"]`\n );\n return itemRef?.assessmentItem ?? undefined;\n }\n\n /** `computedContext.itemElement`: one function for the life of this element, carried along by every update. */\n #itemElement = (identifier: string): HTMLElement | null => this.#assessmentItemFor(identifier) ?? null;\n\n /** The currently active assessment item, exposed for optional presentation extensions. */\n protected get activeAssessmentItem(): QtiAssessmentItem | undefined {\n if (!this.#testElement || !this._sessionContext?.navItemRefId) return undefined;\n return this.#testElement.querySelector<QtiAssessmentItemRef>(\n `qti-assessment-item-ref[identifier=\"${this._sessionContext.navItemRefId}\"]`\n )?.assessmentItem;\n }\n\n /**\n * Ends an attempt: the item named by `detail.itemId` (a `test-end-attempt` stamped into an item, or\n * given an `item`), or else the item on screen.\n */\n #handleTestEndAttempt(event: CustomEvent<{ itemId?: string } | undefined>) {\n const itemId = event.detail?.itemId;\n const qtiAssessmentItemEl = itemId ? this.#assessmentItemFor(itemId) : this.activeAssessmentItem;\n if (!qtiAssessmentItemEl) return;\n const reportValidityAfterScoring = this.configContext?.reportValidityAfterScoring === true ? true : false;\n qtiAssessmentItemEl.processResponse(true, reportValidityAfterScoring);\n }\n\n #handleTestUpdateOutcomeVariable(event: CustomEvent) {\n const qtiAssessmentItemEl = this.#assessmentItemFor(event.detail?.assessmentItemRefId);\n if (!qtiAssessmentItemEl) return;\n qtiAssessmentItemEl.setOutcomeVariable(event.detail.outcomeVariableId, event.detail.value);\n }\n\n #handleInteractionChanged(_event: CustomEvent) {\n if (this.autoScoreItems) {\n const assessmentItem = (_event.composedPath()[0] as HTMLElement).closest<QtiAssessmentItem>(\n 'qti-assessment-item'\n );\n // Autoscoring resolves the item from the event's own path, so a change\n // raised outside an assessment item has nothing to score.\n if (!assessmentItem) return;\n const scoreOutcomeIdentifier = assessmentItem.variables.find(v => v.identifier === 'SCORE') as OutcomeVariable;\n if (\n scoreOutcomeIdentifier &&\n scoreOutcomeIdentifier.externalScored === null &&\n assessmentItem.adaptive === 'false'\n ) {\n const reportValidityAfterScoring = this.configContext?.reportValidityAfterScoring === true ? true : false;\n assessmentItem.processResponse(true, reportValidityAfterScoring);\n }\n }\n }\n\n override render() {\n return html`<slot></slot>`;\n }\n\n /* PK: on test connected we can build the computed context */\n #handleTestConnected(event: CustomEvent) {\n this.#testElement = event.detail as QtiAssessmentTest;\n // A fresh test invalidates the per-test optimality latches.\n this.#optimality.clear();\n // Set the testIdentifier in qtiContext if not already set\n if (!this.qtiContext.QTI_CONTEXT?.testIdentifier) {\n const currentContext = this.qtiContext.QTI_CONTEXT || {\n testIdentifier: '',\n candidateIdentifier: 'not set',\n environmentIdentifier: 'default'\n };\n this.#writeQtiContext({\n QTI_CONTEXT: {\n ...currentContext,\n testIdentifier: this.#testElement.identifier,\n environmentIdentifier: currentContext.environmentIdentifier || 'default'\n }\n });\n }\n\n // Process qti-context-declaration elements to get default values\n const contextDeclarations = this.#testElement.querySelectorAll('qti-context-declaration[identifier=\"QTI_CONTEXT\"]');\n\n contextDeclarations.forEach(declaration => {\n const defaultValues = this.#extractDefaultValues(declaration);\n if (Object.keys(defaultValues).length > 0) {\n // Merge default values with current context, but don't override existing runtime values\n this.#writeQtiContext({\n QTI_CONTEXT: {\n ...defaultValues, // Default values first\n ...this.qtiContext.QTI_CONTEXT // Runtime values override defaults\n }\n });\n }\n });\n\n // The structure and the session-control cascade come from the test's markup, not from upgraded\n // properties, so they do not depend on registration or render timing.\n this.#model = buildTestModel(renderedMarkup(this.#testElement));\n this.computedContext = this.#derive();\n }\n\n /** The test's structure and resolved session control, read from its markup when it is connected. */\n #model?: TestModel;\n\n /** `computedContext`, derived anew from its inputs (`deriveComputedContext`), never from the previous one. */\n #derive(): ComputedContext {\n this.#seedOptimality();\n return deriveComputedContext({\n model: this.#model,\n itemFacts: this._itemFacts,\n testContext: this._testContext,\n sessionContext: this._sessionContext,\n infoItemCategory: this.configContext?.infoItemCategory,\n itemData: this.initContext,\n optimality: this.#optimality,\n itemElement: this.#itemElement\n });\n }\n\n /**\n * On a restored session no attempt is ended this run, so the latch is seeded once from the\n * persisted context, which still holds the submitted response. A later change of the answer\n * leaves the seeded value alone.\n */\n #seedOptimality(): void {\n for (const itemContext of this._testContext?.items ?? []) {\n if (!itemContext.identifier || this.#optimality.has(itemContext.identifier)) continue;\n const numAttempts = Number(itemContext.variables?.find(v => v.identifier === 'numAttempts')?.value) || 0;\n if (numAttempts > 0) this.#optimality.set(itemContext.identifier, assessOptimality(itemContext));\n }\n }\n\n /**\n * Extract default values from a qti-context-declaration element\n */\n #extractDefaultValues(declaration: Element): Record<string, any> {\n const defaultValues: Record<string, any> = {};\n\n const defaultValueElement = declaration.querySelector('qti-default-value');\n if (!defaultValueElement) {\n return defaultValues;\n }\n\n const valueElements = defaultValueElement.querySelectorAll('qti-value[field-identifier]');\n valueElements.forEach(valueElement => {\n const fieldIdentifier = valueElement.getAttribute('field-identifier');\n const baseType = valueElement.getAttribute('base-type') || 'string';\n const textContent = valueElement.textContent?.trim() || '';\n\n if (fieldIdentifier) {\n // Convert value based on base-type\n let value: any = textContent;\n switch (baseType) {\n case 'integer':\n value = parseInt(textContent, 10);\n break;\n case 'float':\n case 'duration':\n value = parseFloat(textContent);\n break;\n case 'boolean':\n value = textContent.toLowerCase() === 'true';\n break;\n case 'string':\n default:\n value = textContent;\n break;\n }\n\n defaultValues[fieldIdentifier] = value;\n }\n });\n\n return defaultValues;\n }\n\n /* On every change of the candidate's state, the context is derived again. */\n protected override willUpdate(_changedProperties: PropertyValues): void {\n if (!this.#model) return;\n this.computedContext = this.#derive();\n this.dispatchEvent(\n new CustomEvent('qti-computed-context-updated', {\n detail: this.computedContext,\n bubbles: true\n })\n );\n }\n\n protected override updated(changedProperties: PropertyValues): void {\n super.updated(changedProperties);\n this.#lockUsedItems();\n }\n\n /** The items this navigation disabled because their attempts are used, so it releases only those. */\n #lockedItems = new WeakSet<QtiAssessmentItem>();\n\n /**\n * Disables every rendered item whose attempts are used, from the computed context, so the\n * candidate cannot change the answer once the last attempt is ended. Runs after every update:\n * an item rendered later (another item, a section on screen, a restored state) is locked as it\n * arrives, and one whose attempts are back to zero (a new state) is released.\n *\n * Only `disabled = true` is ever set here, and only on an item that was not disabled already; a\n * host or view that disables or makes an item read-only itself keeps it so.\n */\n #lockUsedItems(): void {\n if (!this.#testElement || !this.computedContext) return;\n // In a simultaneous part every item has one attempt, processed when the part ends (QTI info model\n // §2.8.2), so the candidate may change the answer until then: TAO keeps such an item open too.\n const items = new Map(\n this.computedContext.testParts.flatMap(part =>\n part.submissionMode === 'simultaneous'\n ? []\n : part.sections.flatMap(section => section.items.map(item => [item.identifier, item] as const))\n )\n );\n for (const itemRef of this.#testElement.querySelectorAll<QtiAssessmentItemRef>('qti-assessment-item-ref')) {\n const element = itemRef.assessmentItem;\n if (!element) continue;\n const used = this.#attemptsUsed(items.get(itemRef.identifier), element);\n if (used && !element.disabled) {\n element.disabled = true;\n this.#lockedItems.add(element);\n } else if (!used && this.#lockedItems.has(element)) {\n this.#lockedItems.delete(element);\n element.disabled = false;\n }\n }\n }\n\n /**\n * The same rule as `test-end-attempt`'s max-attempts guard: a non-adaptive item with a\n * `max-attempts` above 0 whose attempts reached it. Adaptive items end themselves, and 0 is\n * unlimited. With `auto-score-items` every change is scored as an attempt, so the count is not\n * the candidate's and locks nothing.\n */\n #attemptsUsed(item: ComputedItem | undefined, element: QtiAssessmentItem): boolean {\n if (!item || this.autoScoreItems) return false;\n if (item.adaptive || element.adaptive === 'true') return false;\n const maxAttempts = item.sessionControl?.maxAttempts ?? 1;\n return maxAttempts > 0 && (item.numAttempts ?? 0) >= maxAttempts;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'test-navigation': TestNavigation;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"test-navigation.js","sourceRoot":"","sources":["../../../src/components/test-navigation/test-navigation.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,eAAe,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACjE,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAEpD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7F,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO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AAC,EAAE,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;kDAClB;AAI5B;IAFT,KAAK,EAAE;IACP,OAAO,CAAC,EAAE,OAAO,EAAE,eAAe,EAAE,CAAC;uDACK;AAEiB;IAA3D,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,kBAAkB,EAAE,CAAC;sDAAwB","sourcesContent":["import { ContextConsumer, consume, provide } from '@lit/context';\nimport { html, LitElement } from 'lit';\nimport { property, state } from 'lit/decorators.js';\n\nimport { computedContext } from '@qti-components/base';\nimport { buildTestModel, endItemAttempt, followItemSession } from '@qti-components/delivery';\nimport { configContext } from '@qti-components/base';\nimport { testContext } from '@qti-components/base';\nimport { sessionContext } from '@qti-components/base';\nimport { listenPublic as listenItemPublic } from '@qti-components/elements/public-events';\n\nimport { assessOptimality, deriveComputedContext, isItemDone } from '../../internal/derive-computed-context';\nimport { itemFactsContext } from '../../internal/item-facts.context';\nimport { attemptsOf, itemSessionFacts } from '../../internal/item-session-facts';\nimport { renderedMarkup } from '../../internal/rendered-markup';\nimport { testHostContext } from '../../internal/test-host.context';\nimport { listenPublic } from '../../public-events';\n\nimport type { QtiAssessmentItem } from '@qti-components/elements';\nimport type { QtiContext } from '@qti-components/base';\nimport type { OutcomeVariable } from '@qti-components/base';\nimport type { ComputedContext, ComputedItem } from '@qti-components/base';\nimport type { PropertyValues } from 'lit';\nimport type { QtiAssessmentItemRef } from '../qti-assessment-item-ref/qti-assessment-item-ref';\nimport type { QtiAssessmentTest } from '../qti-assessment-test/qti-assessment-test';\nimport type { ItemSession, ItemSessionFacts, TestModel } from '@qti-components/delivery';\nimport type { ItemOptimality } from '../../internal/derive-computed-context';\nimport type { ItemFactsByRef } from '../../internal/item-facts.context';\nimport type { ConfigContext } from '@qti-components/base';\nimport type { SessionContext } from '@qti-components/base';\nimport type { TestContext } from '@qti-components/base';\nimport type { ItemContext } from '@qti-components/base';\n\n/** A new object each time: a host that mutates the one it read must not change anyone else's. */\nconst newQtiContext = (): QtiContext => ({\n QTI_CONTEXT: { testIdentifier: '', candidateIdentifier: '', environmentIdentifier: 'default' }\n});\n\nexport class TestNavigation extends LitElement {\n @property({ type: String }) identifier: string | undefined = undefined;\n\n /**\n * Your own per-item fields, by item-ref `identifier`: each `computedContext` item carries them as\n * given under `data`, without the identifier, and so does every view of it a plugin derives. They\n * never replace a field the test, the item or the candidate's state gives, whatever its name; a\n * template reads `activeItem.data.<field>`. To mark an item as scored by hand, set\n * `external-scored` on its `SCORE` declaration in `postLoadTransformCallback`.\n */\n @state()\n public initContext: { identifier: string; [key: string]: any }[] = [];\n\n /**\n * @deprecated Set `qtiContext` on `qti-test`, which provides it. This is an alias for the\n * enclosing test's: reading returns it, writing replaces it, so a host that has always set the\n * shuffle seed here keeps working. Removed in the next major.\n *\n * Written before the navigation is inside a test, it waits and is handed over on connect.\n */\n public get qtiContext(): QtiContext {\n return this.#owner()?.qtiContext ?? (this.#pendingQtiContext ??= newQtiContext());\n }\n\n public set qtiContext(value: QtiContext) {\n if (!this.#warnedQtiContext) {\n this.#warnedQtiContext = true;\n console.warn(\n '[qti-components] `test-navigation.qtiContext` is deprecated and will be removed in the next major ' +\n 'release. Set `qtiContext` on `<qti-test>` instead; it is the same value.'\n );\n }\n this.#writeQtiContext(value);\n }\n\n #pendingQtiContext?: QtiContext;\n #warnedQtiContext = false;\n\n /** The write the library itself makes. Not the deprecated setter, so it never warns about itself. */\n #writeQtiContext(value: QtiContext): void {\n const owner = this.#owner();\n if (owner) owner.qtiContext = value;\n else this.#pendingQtiContext = value;\n }\n\n /**\n * The `qti-test` this navigation is in, found through context so it works across shadow roots.\n * A write made before it is known waits in `#pendingQtiContext` and is handed over on arrival.\n */\n #testHost = new ContextConsumer(this, {\n context: testHostContext,\n subscribe: true,\n callback: host => {\n if (host && this.#pendingQtiContext) {\n host.qtiContext = this.#pendingQtiContext;\n this.#pendingQtiContext = undefined;\n }\n }\n });\n\n #owner(): { qtiContext: QtiContext } | null {\n return this.#testHost.value ?? null;\n }\n\n @state()\n @consume({ context: configContext, subscribe: true })\n public configContext: ConfigContext = {};\n\n @state()\n @consume({ context: testContext, subscribe: true })\n protected _testContext?: TestContext;\n\n @state()\n @consume({ context: sessionContext, subscribe: true })\n protected _sessionContext?: SessionContext;\n\n /** Read from each item's XML when `qti-test` fetches it; see `itemFactsContext`. */\n @state()\n @consume({ context: itemFactsContext, subscribe: true })\n protected _itemFacts?: ItemFactsByRef;\n\n @state()\n @provide({ context: computedContext })\n protected computedContext: ComputedContext;\n\n @property({ type: Boolean, attribute: 'auto-score-items' }) autoScoreItems = false;\n\n #testElement: QtiAssessmentTest;\n\n /**\n * Whether each item's last *ended attempt* reached the optimal outcome, keyed\n * by item-ref id. Written from #handleItemContextUpdated when processResponse\n * ends an attempt — never on a plain selection. Mirrors how inline feedback\n * only re-evaluates when an attempt is processed, so a freshly-picked answer\n * doesn't flip `done` until the candidate ends the attempt.\n */\n #optimality = new Map<string, ItemOptimality>();\n\n /**\n * Each item session's lifecycle state, by item-ref identifier, changed only through the lifecycle\n * table (`followItemSession` as the candidate moves, `endItemAttempt` when an attempt ends). It\n * lives here until `DeliveryState` holds it (roadmap 1, T3d); a session whose attempts change\n * outside an ended attempt (a restored or assigned state) is seeded again.\n */\n #sessions = new Map<string, ItemSession>();\n\n /** Set while `auto-score-items` scores a change: that run is not the candidate ending an attempt. */\n #autoScoring = false;\n\n constructor() {\n super();\n listenPublic(this, 'qc-test-loaded', this.#handleTestConnected.bind(this));\n\n listenItemPublic(this, 'qc-item-response-changed', this.#handleInteractionChanged.bind(this));\n this.addEventListener('qti-item-context-updated', this.#handleItemContextUpdated.bind(this));\n\n listenPublic(this, 'qc-test-end-attempt', this.#handleTestEndAttempt.bind(this));\n listenPublic(this, 'qc-test-update-outcome', this.#handleTestUpdateOutcomeVariable.bind(this));\n }\n\n /**\n * Latch whether an item reached its optimal outcome whenever it has just ended\n * an attempt. processResponse — fired by test-end-attempt, autoscore, or an\n * in-item end-attempt interaction — flags its context update with\n * `responseProcessed`; a plain selection updates the context without it, so\n * `done` can't flip until the candidate actually ends the attempt.\n */\n #handleItemContextUpdated(event: CustomEvent<{ itemContext: ItemContext; responseProcessed?: boolean }>) {\n if (!event.detail?.responseProcessed) return;\n const itemContext = event.detail.itemContext;\n if (!itemContext?.identifier) return;\n const optimality = assessOptimality(itemContext);\n this.#optimality.set(itemContext.identifier, optimality);\n this.#endAttempt(itemContext);\n\n const computedItem = this.computedItemFor(itemContext.identifier);\n const numAttempts = Number(itemContext.variables?.find(v => v.identifier === 'numAttempts')?.value) || 0;\n const completionStatus = itemContext.variables?.find(v => v.identifier === 'completionStatus')?.value as string;\n this.afterAttemptEnded(\n (event.composedPath()[0] as HTMLElement)?.closest<QtiAssessmentItem>('qti-assessment-item'),\n computedItem,\n isItemDone(\n numAttempts,\n optimality,\n computedItem?.sessionControl?.maxAttempts,\n computedItem?.adaptive,\n completionStatus\n )\n );\n }\n\n /** Moves the item's session on for its ended attempt; an auto-scored change only updates its count. */\n #endAttempt(itemContext: ItemContext): void {\n const facts = this.#sessionFacts().get(itemContext.identifier);\n if (!facts) return;\n const ended: ItemSessionFacts = { ...facts, ...attemptsOf(itemContext) };\n const previous = this.#sessions.get(itemContext.identifier);\n this.#sessions.set(\n itemContext.identifier,\n this.#autoScoring\n ? { state: previous?.state ?? followItemSession(undefined, ended).state, numAttempts: ended.numAttempts }\n : endItemAttempt(previous, ended)\n );\n }\n\n /** The facts of every item session now: the model, the item facts, the contexts and the items on screen. */\n #sessionFacts(): Map<string, ItemSessionFacts> {\n if (!this.#model) return new Map();\n const presented = new Set(\n [...(this.#testElement?.querySelectorAll<QtiAssessmentItemRef>('qti-assessment-item-ref') ?? [])]\n .filter(itemRef => itemRef.assessmentItem)\n .map(itemRef => itemRef.identifier)\n );\n return itemSessionFacts(this.#model, this._itemFacts, this._testContext?.items, {\n current: this._sessionContext?.navItemRefId,\n presented\n });\n }\n\n /** Moves every item session on for where the candidate is now. */\n #followSessions(): void {\n for (const [identifier, facts] of this.#sessionFacts()) {\n this.#sessions.set(identifier, followItemSession(this.#sessions.get(identifier), facts));\n }\n }\n\n /**\n * Extension point for presentation packages reacting to an ended attempt.\n * `done` is settled here — from the freshly latched optimality and the\n * session-control cascade — because the computed context only catches up on\n * the next update, after this event has finished bubbling.\n */\n protected afterAttemptEnded(\n _assessmentItem: QtiAssessmentItem | undefined,\n _computedItem: ComputedItem | undefined,\n _done: boolean\n ): void {}\n\n /** The computed-context entry for an item, from the session-control cascade. */\n protected computedItemFor(identifier: string): ComputedItem | undefined {\n return this.computedContext?.testParts\n ?.flatMap(part => part.sections)\n .flatMap(section => section.items)\n .find(i => i.identifier === identifier);\n }\n\n /** The assessment item for an item-ref id, if it has been rendered. */\n #assessmentItemFor(identifier: string | undefined): QtiAssessmentItem | undefined {\n if (!identifier) return undefined;\n const itemRef = this.#testElement?.querySelector<QtiAssessmentItemRef>(\n `qti-assessment-item-ref[identifier=\"${CSS.escape(identifier)}\"]`\n );\n return itemRef?.assessmentItem ?? undefined;\n }\n\n /** `computedContext.itemElement`: one function for the life of this element, carried along by every update. */\n #itemElement = (identifier: string): HTMLElement | null => this.#assessmentItemFor(identifier) ?? null;\n\n /** The currently active assessment item, exposed for optional presentation extensions. */\n protected get activeAssessmentItem(): QtiAssessmentItem | undefined {\n if (!this.#testElement || !this._sessionContext?.navItemRefId) return undefined;\n return this.#testElement.querySelector<QtiAssessmentItemRef>(\n `qti-assessment-item-ref[identifier=\"${this._sessionContext.navItemRefId}\"]`\n )?.assessmentItem;\n }\n\n /**\n * Ends an attempt: the item named by `detail.itemId` (a `test-end-attempt` stamped into an item, or\n * given an `item`), or else the item on screen.\n */\n #handleTestEndAttempt(event: CustomEvent<{ itemId?: string } | undefined>) {\n const itemId = event.detail?.itemId;\n const qtiAssessmentItemEl = itemId ? this.#assessmentItemFor(itemId) : this.activeAssessmentItem;\n if (!qtiAssessmentItemEl) return;\n const reportValidityAfterScoring = this.configContext?.reportValidityAfterScoring === true ? true : false;\n qtiAssessmentItemEl.processResponse(true, reportValidityAfterScoring);\n }\n\n #handleTestUpdateOutcomeVariable(event: CustomEvent) {\n const qtiAssessmentItemEl = this.#assessmentItemFor(event.detail?.assessmentItemRefId);\n if (!qtiAssessmentItemEl) return;\n qtiAssessmentItemEl.setOutcomeVariable(event.detail.outcomeVariableId, event.detail.value);\n }\n\n #handleInteractionChanged(_event: CustomEvent) {\n if (this.autoScoreItems) {\n const assessmentItem = (_event.composedPath()[0] as HTMLElement).closest<QtiAssessmentItem>(\n 'qti-assessment-item'\n );\n // Autoscoring resolves the item from the event's own path, so a change\n // raised outside an assessment item has nothing to score.\n if (!assessmentItem) return;\n const scoreOutcomeIdentifier = assessmentItem.variables.find(v => v.identifier === 'SCORE') as OutcomeVariable;\n if (\n scoreOutcomeIdentifier &&\n scoreOutcomeIdentifier.externalScored === null &&\n assessmentItem.adaptive === 'false'\n ) {\n const reportValidityAfterScoring = this.configContext?.reportValidityAfterScoring === true ? true : false;\n this.#autoScoring = true;\n try {\n assessmentItem.processResponse(true, reportValidityAfterScoring);\n } finally {\n this.#autoScoring = false;\n }\n }\n }\n }\n\n override render() {\n return html`<slot></slot>`;\n }\n\n /* PK: on test connected we can build the computed context */\n #handleTestConnected(event: CustomEvent) {\n this.#testElement = event.detail as QtiAssessmentTest;\n // A fresh test invalidates the per-test optimality latches and item sessions.\n this.#optimality.clear();\n this.#sessions.clear();\n // Set the testIdentifier in qtiContext if not already set\n if (!this.qtiContext.QTI_CONTEXT?.testIdentifier) {\n const currentContext = this.qtiContext.QTI_CONTEXT || {\n testIdentifier: '',\n candidateIdentifier: 'not set',\n environmentIdentifier: 'default'\n };\n this.#writeQtiContext({\n QTI_CONTEXT: {\n ...currentContext,\n testIdentifier: this.#testElement.identifier,\n environmentIdentifier: currentContext.environmentIdentifier || 'default'\n }\n });\n }\n\n // Process qti-context-declaration elements to get default values\n const contextDeclarations = this.#testElement.querySelectorAll('qti-context-declaration[identifier=\"QTI_CONTEXT\"]');\n\n contextDeclarations.forEach(declaration => {\n const defaultValues = this.#extractDefaultValues(declaration);\n if (Object.keys(defaultValues).length > 0) {\n // Merge default values with current context, but don't override existing runtime values\n this.#writeQtiContext({\n QTI_CONTEXT: {\n ...defaultValues, // Default values first\n ...this.qtiContext.QTI_CONTEXT // Runtime values override defaults\n }\n });\n }\n });\n\n // The structure and the session-control cascade come from the test's markup, not from upgraded\n // properties, so they do not depend on registration or render timing.\n this.#model = buildTestModel(renderedMarkup(this.#testElement));\n this.computedContext = this.#derive();\n }\n\n /** The test's structure and resolved session control, read from its markup when it is connected. */\n #model?: TestModel;\n\n /** `computedContext`, derived anew from its inputs (`deriveComputedContext`), never from the previous one. */\n #derive(): ComputedContext {\n this.#seedOptimality();\n this.#followSessions();\n return deriveComputedContext({\n model: this.#model,\n itemFacts: this._itemFacts,\n testContext: this._testContext,\n sessionContext: this._sessionContext,\n infoItemCategory: this.configContext?.infoItemCategory,\n itemData: this.initContext,\n optimality: this.#optimality,\n lifecycle: new Map([...this.#sessions].map(([identifier, session]) => [identifier, session.state])),\n itemElement: this.#itemElement\n });\n }\n\n /**\n * On a restored session no attempt is ended this run, so the latch is seeded once from the\n * persisted context, which still holds the submitted response. A later change of the answer\n * leaves the seeded value alone.\n */\n #seedOptimality(): void {\n for (const itemContext of this._testContext?.items ?? []) {\n if (!itemContext.identifier || this.#optimality.has(itemContext.identifier)) continue;\n const numAttempts = Number(itemContext.variables?.find(v => v.identifier === 'numAttempts')?.value) || 0;\n if (numAttempts > 0) this.#optimality.set(itemContext.identifier, assessOptimality(itemContext));\n }\n }\n\n /**\n * Extract default values from a qti-context-declaration element\n */\n #extractDefaultValues(declaration: Element): Record<string, any> {\n const defaultValues: Record<string, any> = {};\n\n const defaultValueElement = declaration.querySelector('qti-default-value');\n if (!defaultValueElement) {\n return defaultValues;\n }\n\n const valueElements = defaultValueElement.querySelectorAll('qti-value[field-identifier]');\n valueElements.forEach(valueElement => {\n const fieldIdentifier = valueElement.getAttribute('field-identifier');\n const baseType = valueElement.getAttribute('base-type') || 'string';\n const textContent = valueElement.textContent?.trim() || '';\n\n if (fieldIdentifier) {\n // Convert value based on base-type\n let value: any = textContent;\n switch (baseType) {\n case 'integer':\n value = parseInt(textContent, 10);\n break;\n case 'float':\n case 'duration':\n value = parseFloat(textContent);\n break;\n case 'boolean':\n value = textContent.toLowerCase() === 'true';\n break;\n case 'string':\n default:\n value = textContent;\n break;\n }\n\n defaultValues[fieldIdentifier] = value;\n }\n });\n\n return defaultValues;\n }\n\n /* On every change of the candidate's state, the context is derived again. */\n protected override willUpdate(_changedProperties: PropertyValues): void {\n if (!this.#model) return;\n this.computedContext = this.#derive();\n this.dispatchEvent(\n new CustomEvent('qti-computed-context-updated', {\n detail: this.computedContext,\n bubbles: true\n })\n );\n }\n\n protected override updated(changedProperties: PropertyValues): void {\n super.updated(changedProperties);\n this.#lockUsedItems();\n }\n\n /** The items this navigation disabled because their attempts are used, so it releases only those. */\n #lockedItems = new WeakSet<QtiAssessmentItem>();\n\n /**\n * Disables every rendered item whose attempts are used, from the computed context, so the\n * candidate cannot change the answer once the last attempt is ended. Runs after every update:\n * an item rendered later (another item, a section on screen, a restored state) is locked as it\n * arrives, and one whose attempts are back to zero (a new state) is released.\n *\n * Only `disabled = true` is ever set here, and only on an item that was not disabled already; a\n * host or view that disables or makes an item read-only itself keeps it so.\n */\n #lockUsedItems(): void {\n if (!this.#testElement || !this.computedContext) return;\n // In a simultaneous part every item has one attempt, processed when the part ends (QTI info model\n // §2.8.2), so the candidate may change the answer until then: TAO keeps such an item open too.\n const items = new Map(\n this.computedContext.testParts.flatMap(part =>\n part.submissionMode === 'simultaneous'\n ? []\n : part.sections.flatMap(section => section.items.map(item => [item.identifier, item] as const))\n )\n );\n for (const itemRef of this.#testElement.querySelectorAll<QtiAssessmentItemRef>('qti-assessment-item-ref')) {\n const element = itemRef.assessmentItem;\n if (!element) continue;\n const used = this.#attemptsUsed(items.get(itemRef.identifier), element);\n if (used && !element.disabled) {\n element.disabled = true;\n this.#lockedItems.add(element);\n } else if (!used && this.#lockedItems.has(element)) {\n this.#lockedItems.delete(element);\n element.disabled = false;\n }\n }\n }\n\n /**\n * The same rule as `test-end-attempt`'s max-attempts guard: a non-adaptive item with a\n * `max-attempts` above 0 whose attempts reached it. Adaptive items end themselves, and 0 is\n * unlimited. With `auto-score-items` every change is scored as an attempt, so the count is not\n * the candidate's and locks nothing.\n */\n #attemptsUsed(item: ComputedItem | undefined, element: QtiAssessmentItem): boolean {\n if (!item || this.autoScoreItems) return false;\n if (item.adaptive || element.adaptive === 'true') return false;\n const maxAttempts = item.sessionControl?.maxAttempts ?? 1;\n return maxAttempts > 0 && (item.numAttempts ?? 0) >= maxAttempts;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'test-navigation': TestNavigation;\n }\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ComputedContext, ItemContext } from '@qti-components/base';
|
|
2
2
|
import type { SessionContext, TestContext } from '@qti-components/base';
|
|
3
|
-
import type { TestModel } from '@qti-components/delivery';
|
|
3
|
+
import type { ItemLifecycleState, TestModel } from '@qti-components/delivery';
|
|
4
4
|
import type { ItemFactsByRef } from './item-facts.context';
|
|
5
5
|
/**
|
|
6
6
|
* Whether an item's ended attempt reached the best achievable outcome:
|
|
@@ -20,7 +20,7 @@ export interface ComputedContextInputs {
|
|
|
20
20
|
readonly sessionContext?: Readonly<SessionContext>;
|
|
21
21
|
/** `config.infoItemCategory`: items with it are not numbered. */
|
|
22
22
|
readonly infoItemCategory?: string;
|
|
23
|
-
/** The host's per-item fields (`initContext`). */
|
|
23
|
+
/** The host's per-item fields (`initContext`): each item gets them under `data`, never at its top level. */
|
|
24
24
|
readonly itemData?: readonly {
|
|
25
25
|
identifier: string;
|
|
26
26
|
[key: string]: unknown;
|
|
@@ -31,6 +31,11 @@ export interface ComputedContextInputs {
|
|
|
31
31
|
* never on a plain change of the answer.
|
|
32
32
|
*/
|
|
33
33
|
readonly optimality: ReadonlyMap<string, ItemOptimality>;
|
|
34
|
+
/**
|
|
35
|
+
* The lifecycle state of each item session, by item-ref identifier, kept by `test-navigation`
|
|
36
|
+
* (`followItemSession`, `endItemAttempt`). An item it does not list is seeded from its attempts.
|
|
37
|
+
*/
|
|
38
|
+
readonly lifecycle?: ReadonlyMap<string, ItemLifecycleState>;
|
|
34
39
|
/** `computedContext.itemElement`, passed through. */
|
|
35
40
|
readonly itemElement?: ComputedContext['itemElement'];
|
|
36
41
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { itemRefsInOrder, ownItemRefs, sectionsInOrder } from '@qti-components/delivery';
|
|
1
|
+
import { itemRefsInOrder, itemRules, ownItemRefs, sectionsInOrder, seedItemLifecycle } from '@qti-components/delivery';
|
|
2
2
|
/**
|
|
3
3
|
* `computedContext`, derived from its inputs alone: built anew on every call, never from the previous
|
|
4
4
|
* context, and never changing an input. The same inputs give an equal context.
|
|
@@ -32,23 +32,26 @@ export function deriveComputedContext(inputs) {
|
|
|
32
32
|
allowSkipping: section.sessionControl.allowSkipping,
|
|
33
33
|
// A section that only holds subsections is completed when theirs are.
|
|
34
34
|
completed: itemRefsInOrder(section.content).every(item => variableValue(itemContextFor(inputs, item.identifier), 'completionStatus') === 'completed'),
|
|
35
|
-
items: ownItemRefs(section).map(item => deriveItem(inputs, item, itemIndexes.get(item.identifier) ?? null))
|
|
35
|
+
items: ownItemRefs(section).map(item => deriveItem(inputs, testPart, item, itemIndexes.get(item.identifier) ?? null))
|
|
36
36
|
}))
|
|
37
37
|
}))
|
|
38
38
|
};
|
|
39
39
|
}
|
|
40
|
-
function deriveItem(inputs, item, index) {
|
|
40
|
+
function deriveItem(inputs, testPart, item, index) {
|
|
41
41
|
const itemContext = itemContextFor(inputs, item.identifier);
|
|
42
|
+
// Only the fields an item context holds: a host that restores `testContext` with fields of its
|
|
43
|
+
// own sets nothing here. Its fields for an item belong in `itemData`, which lands under `data`.
|
|
42
44
|
const computedItem = {
|
|
43
45
|
active: false,
|
|
44
46
|
identifier: item.identifier,
|
|
45
47
|
categories: [...item.categories],
|
|
46
48
|
href: item.href,
|
|
47
|
-
variables: [],
|
|
48
49
|
sessionControl: { ...item.sessionControl },
|
|
49
50
|
...factsFor(inputs.itemFacts, item.identifier),
|
|
50
|
-
|
|
51
|
-
...
|
|
51
|
+
variables: itemContext?.variables ?? [],
|
|
52
|
+
...(itemContext?.state === undefined ? {} : { state: itemContext.state }),
|
|
53
|
+
...(itemContext?.readonly === undefined ? {} : { readonly: itemContext.readonly }),
|
|
54
|
+
...(itemContext?.disabled === undefined ? {} : { disabled: itemContext.disabled })
|
|
52
55
|
};
|
|
53
56
|
const rawScore = variableValue(computedItem, 'SCORE');
|
|
54
57
|
const score = rawScore === undefined || rawScore === null ? null : parseFloat(rawScore.toString());
|
|
@@ -76,9 +79,45 @@ function deriveItem(inputs, item, index) {
|
|
|
76
79
|
maxScore,
|
|
77
80
|
done: isItemDone(numAttempts, optimality, computedItem.sessionControl?.maxAttempts, computedItem.adaptive, completionStatus),
|
|
78
81
|
// Reflects the last *ended* attempt only: the latch, not the fallback above.
|
|
79
|
-
optimal: latched === 'optimal'
|
|
82
|
+
optimal: latched === 'optimal',
|
|
83
|
+
...lifecycleOf(inputs, testPart, item, itemContext, { numAttempts, completionStatus }),
|
|
84
|
+
data: hostData(inputs.itemData, item.identifier)
|
|
80
85
|
};
|
|
81
86
|
}
|
|
87
|
+
/** The item session's lifecycle state and what it may do now (`itemRules`), computed: host data never sets it. */
|
|
88
|
+
function lifecycleOf(inputs, testPart, item, itemContext, { numAttempts, completionStatus }) {
|
|
89
|
+
const session = {
|
|
90
|
+
sessionControl: item.sessionControl,
|
|
91
|
+
adaptive: inputs.itemFacts?.get(item.identifier)?.adaptive ?? false,
|
|
92
|
+
navigationMode: testPart.navigationMode,
|
|
93
|
+
submissionMode: testPart.submissionMode,
|
|
94
|
+
numAttempts,
|
|
95
|
+
completionStatus: completionStatus ?? null
|
|
96
|
+
};
|
|
97
|
+
const lifecycle = inputs.lifecycle?.get(item.identifier) ??
|
|
98
|
+
seedItemLifecycle({
|
|
99
|
+
...session,
|
|
100
|
+
presented: inputs.sessionContext?.navItemRefId === item.identifier,
|
|
101
|
+
passed: false
|
|
102
|
+
});
|
|
103
|
+
const rules = itemRules({
|
|
104
|
+
...session,
|
|
105
|
+
state: lifecycle,
|
|
106
|
+
// Only resuming reads it, and no answer asks about resuming.
|
|
107
|
+
left: false,
|
|
108
|
+
modalFeedback: false,
|
|
109
|
+
skipped: isSkipped(itemContext),
|
|
110
|
+
valid: itemContext?.valid ?? true
|
|
111
|
+
});
|
|
112
|
+
return { lifecycle, rules };
|
|
113
|
+
}
|
|
114
|
+
/** The host's fields for an item (`initContext`), without the identifier that matched them; `{}` when none. */
|
|
115
|
+
function hostData(itemData, identifier) {
|
|
116
|
+
const entry = itemData?.find(data => data.identifier === identifier);
|
|
117
|
+
if (!entry)
|
|
118
|
+
return {};
|
|
119
|
+
return Object.fromEntries(Object.entries(entry).filter(([key]) => key !== 'identifier'));
|
|
120
|
+
}
|
|
82
121
|
function itemContextFor(inputs, identifier) {
|
|
83
122
|
return inputs.testContext?.items?.find(item => item.identifier === identifier);
|
|
84
123
|
}
|
|
@@ -98,6 +137,17 @@ function indexesInDocumentOrder(items, infoItemCategory) {
|
|
|
98
137
|
let index = 1;
|
|
99
138
|
return new Map(items.map(item => [item.identifier, item.categories.includes(infoItemCategory) ? null : index++]));
|
|
100
139
|
}
|
|
140
|
+
/**
|
|
141
|
+
* No response given (QTI info model §7.19, `allow-skipping`): every response variable holds its
|
|
142
|
+
* default or NULL. An item with no response variables "by definition cannot be skipped"; one not
|
|
143
|
+
* fetched yet has given none.
|
|
144
|
+
*/
|
|
145
|
+
function isSkipped(itemContext) {
|
|
146
|
+
if (!itemContext)
|
|
147
|
+
return true;
|
|
148
|
+
const responses = itemContext.variables?.filter(v => v.type === 'response' && v.identifier !== 'numAttempts' && v.identifier !== 'duration');
|
|
149
|
+
return Boolean(responses?.length) && isDefaultResponse(itemContext);
|
|
150
|
+
}
|
|
101
151
|
/** Every response still holds its default (or the base type's empty value): nothing answered. */
|
|
102
152
|
function isDefaultResponse(itemContext) {
|
|
103
153
|
const responseVariables = itemContext?.variables?.filter(v => v.type === 'response' && v.identifier !== 'numAttempts') || [];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"derive-computed-context.js","sourceRoot":"","sources":["../../src/internal/derive-computed-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAsCzF;;;;;;GAMG;AACH,MAAM,UAAU,qBAAqB,CAAC,MAA6B;IACjE,MAAM,EAAE,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,GAAG,MAAM,CAAC;IACtD,MAAM,WAAW,GAAG,sBAAsB,CACxC,KAAK,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,eAAe,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,EAC/D,MAAM,CAAC,gBAAgB,CACxB,CAAC;IACF,OAAO;QACL,WAAW;QACX,UAAU,EAAE,KAAK,CAAC,UAAU;QAC5B,KAAK,EAAE,KAAK,CAAC,KAAK;QAClB,IAAI,EAAE,cAAc,EAAE,IAAI;QAC1B,OAAO,EAAE,cAAc,EAAE,OAAO,IAAI,EAAE;QACtC,SAAS,EAAE,KAAK,CAAC,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;YAC1C,MAAM,EAAE,cAAc,EAAE,SAAS,KAAK,QAAQ,CAAC,UAAU;YACzD,UAAU,EAAE,QAAQ,CAAC,UAAU;YAC/B,cAAc,EAAE,QAAQ,CAAC,cAAc;YACvC,cAAc,EAAE,QAAQ,CAAC,cAAc;YACvC,aAAa,EAAE,QAAQ,CAAC,cAAc,CAAC,aAAa;YACpD,SAAS,EAAE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,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC;QAAE,OAAO,IAAI,CAAC;IACzE,MAAM,MAAM,GAAG,UAAU,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC;IAC1C,OAAO,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC;AAC9C,CAAC","sourcesContent":["import { itemRefsInOrder, ownItemRefs, sectionsInOrder } from '@qti-components/delivery';\n\nimport type { ComputedContext, ComputedItem, ItemContext, ResponseVariable } from '@qti-components/base';\nimport type { SessionContext, TestContext } from '@qti-components/base';\nimport type { ItemFacts, ItemRefModel, TestModel } from '@qti-components/delivery';\nimport type { ItemFactsByRef } from './item-facts.context';\n\n/**\n * Whether an item's ended attempt reached the best achievable outcome:\n * 'optimal' (nothing to improve), 'suboptimal' (a better attempt is possible),\n * or 'unscored' (no machine-judgeable optimal value — see `assessOptimality`).\n */\nexport type ItemOptimality = 'optimal' | 'suboptimal' | 'unscored';\n\n/** Everything `computedContext` is derived from. Nothing here is the previous `computedContext`. */\nexport interface ComputedContextInputs {\n /** The test's structure and resolved session control, from its XML (`buildTestModel`). */\n readonly model: TestModel;\n /** The facts of every item fetched so far, by item-ref identifier. */\n readonly itemFacts?: ItemFactsByRef;\n /** The candidate's responses and outcomes, per item. */\n readonly testContext?: Readonly<TestContext>;\n /** Where the candidate is, the view and the plugin state. */\n readonly sessionContext?: Readonly<SessionContext>;\n /** `config.infoItemCategory`: items with it are not numbered. */\n readonly infoItemCategory?: string;\n /** The host's per-item fields (`initContext`). */\n readonly itemData?: readonly { identifier: string; [key: string]: unknown }[];\n /**\n * The optimality of each item's last ended attempt, by item-ref identifier (see `ItemOptimality`).\n * Kept by `test-navigation`, since it is not in the contexts: it is written when an attempt ends,\n * never on a plain change of the answer.\n */\n readonly optimality: ReadonlyMap<string, ItemOptimality>;\n /** `computedContext.itemElement`, passed through. */\n readonly itemElement?: ComputedContext['itemElement'];\n}\n\n/**\n * `computedContext`, derived from its inputs alone: built anew on every call, never from the previous\n * context, and never changing an input. The same inputs give an equal context.\n *\n * Roadmap 1, T2c. `DeliveryState` is not live at runtime yet, so the candidate's state comes from\n * `testContext` and `sessionContext`; T3 and T8 move it into `DeliveryState`, and add their fields here.\n */\nexport function deriveComputedContext(inputs: ComputedContextInputs): ComputedContext {\n const { model, sessionContext, itemElement } = inputs;\n const itemIndexes = indexesInDocumentOrder(\n model.testParts.flatMap(part => itemRefsInOrder(part.sections)),\n inputs.infoItemCategory\n );\n return {\n itemElement,\n identifier: model.identifier,\n title: model.title,\n view: sessionContext?.view,\n plugins: sessionContext?.plugins ?? {},\n testParts: model.testParts.map(testPart => ({\n active: sessionContext?.navPartId === testPart.identifier,\n identifier: testPart.identifier,\n navigationMode: testPart.navigationMode,\n submissionMode: testPart.submissionMode,\n allowSkipping: testPart.sessionControl.allowSkipping,\n itemOrder: itemRefsInOrder(testPart.sections).map(item => item.identifier),\n // Flat, depth first: every section once, each with only its own item-refs, so every item is\n // listed once. Where a section's item-refs and subsections interleave, this list is not in\n // document order; `index` is.\n sections: sectionsInOrder(testPart.sections).map(section => ({\n active: sessionContext?.navSectionId === section.identifier,\n identifier: section.identifier,\n title: section.title,\n allowSkipping: section.sessionControl.allowSkipping,\n // A section that only holds subsections is completed when theirs are.\n completed: itemRefsInOrder(section.content).every(\n item => variableValue(itemContextFor(inputs, item.identifier), 'completionStatus') === 'completed'\n ),\n items: ownItemRefs(section).map(item => deriveItem(inputs, item, itemIndexes.get(item.identifier) ?? null))\n }))\n }))\n };\n}\n\nfunction deriveItem(inputs: ComputedContextInputs, item: ItemRefModel, index: number | null): ComputedItem {\n const itemContext = itemContextFor(inputs, item.identifier);\n const computedItem = {\n active: false,\n identifier: item.identifier,\n categories: [...item.categories],\n href: item.href,\n variables: [] as ComputedItem['variables'],\n sessionControl: { ...item.sessionControl },\n ...factsFor(inputs.itemFacts, item.identifier),\n ...itemContext,\n ...inputs.itemData?.find(data => data.identifier === item.identifier)\n } as ComputedItem;\n\n const rawScore = variableValue(computedItem, 'SCORE');\n const score = rawScore === undefined || rawScore === null ? null : parseFloat(rawScore.toString());\n const rawMaxScore = variableValue(computedItem, 'MAXSCORE');\n const maxScore = rawMaxScore === undefined || rawMaxScore === null ? null : parseFloat(rawMaxScore.toString());\n const completionStatus = variableValue(computedItem, 'completionStatus') as string;\n const response = variableValue(computedItem, 'RESPONSE') || '';\n const numAttempts = Number(variableValue(computedItem, 'numAttempts')) || 0;\n\n // Optimality comes from the last *ended attempt*, never from a live mid-attempt selection.\n // `test-navigation` seeds the latch once from a restored context, which still holds the submitted\n // response; before that, an item with no ended attempt is assessed on what it holds.\n const latched = inputs.optimality.get(item.identifier);\n const optimality = latched ?? (itemContext ? assessOptimality(itemContext) : 'unscored');\n\n return {\n ...computedItem,\n completionStatus,\n numAttempts,\n score,\n response,\n index,\n active: inputs.sessionContext?.navItemRefId === item.identifier,\n // Published by the item. One that is not on screen has nothing to be invalid.\n valid: itemContext?.valid ?? true,\n isDefaultResponse: isDefaultResponse(itemContext),\n maxScore,\n done: isItemDone(\n numAttempts,\n optimality,\n computedItem.sessionControl?.maxAttempts,\n computedItem.adaptive,\n completionStatus\n ),\n // Reflects the last *ended* attempt only: the latch, not the fallback above.\n optimal: latched === 'optimal'\n } as ComputedItem;\n}\n\nfunction itemContextFor(inputs: ComputedContextInputs, identifier: string): ItemContext | undefined {\n return inputs.testContext?.items?.find(item => item.identifier === identifier);\n}\n\nfunction variableValue(item: { variables?: ItemContext['variables'] } | undefined, identifier: string) {\n return item?.variables?.find(variable => variable.identifier === identifier)?.value;\n}\n\n/** An item's facts as `computedContext` carries them; nothing until the item is fetched. */\nfunction factsFor(\n itemFacts: ItemFactsByRef | undefined,\n identifier: string\n): Partial<Omit<ItemFacts, 'identifier'>> & { assessmentItemIdentifier?: string } {\n const facts = itemFacts?.get(identifier);\n if (!facts) return {};\n const { identifier: assessmentItemIdentifier, ...rest } = facts;\n return { ...rest, assessmentItemIdentifier };\n}\n\n/** Item numbers in document order, skipping info items; null for an info item. */\nfunction indexesInDocumentOrder(items: ItemRefModel[], infoItemCategory: string | undefined) {\n let index = 1;\n return new Map(\n items.map(item => [item.identifier, item.categories.includes(infoItemCategory) ? null : index++] as const)\n );\n}\n\n/** Every response still holds its default (or the base type's empty value): nothing answered. */\nfunction isDefaultResponse(itemContext: ItemContext | undefined): boolean {\n const responseVariables =\n itemContext?.variables?.filter(v => v.type === 'response' && v.identifier !== 'numAttempts') || [];\n return responseVariables.every(v => {\n if (v.value === undefined || v.value === null) return true;\n let fallbackValue: string;\n switch (v.baseType) {\n case 'integer':\n case 'float':\n case 'duration':\n fallbackValue = '0';\n break;\n case 'boolean':\n fallbackValue = 'false';\n break;\n default:\n fallbackValue = '';\n break;\n }\n const defaultValue = v.defaultValue ?? fallbackValue;\n if (Array.isArray(v.value)) {\n const dv = Array.isArray(defaultValue) ? defaultValue : [defaultValue];\n return v.value.length === dv.length && v.value.every((val, i) => val === dv[i]);\n }\n return v.value === defaultValue;\n });\n}\n\n/**\n * Decide whether an item should be treated as \"the candidate is done with it\"\n * for the purpose of gating forward navigation and further attempts.\n *\n * - The candidate must have actually ended an attempt (numAttempts > 0).\n * - Once attempted, the item is done if they reached the optimal outcome\n * ('optimal'), or there's nothing to improve on ('unscored'). It is only *not*\n * done while a better attempt is still possible ('suboptimal') and attempts\n * remain — see `assessOptimality` for how \"optimal\" is determined.\n *\n * `optimality` reflects the last *ended attempt*, not the live selection — so a\n * freshly-picked optimal answer doesn't count as done until test-end-attempt\n * evaluates it.\n *\n * Adaptive items decide this themselves: max-attempts does not apply to them\n * (QTI 3, itemSessionControl), and a wrong attempt may be the step that leads\n * on to the next part of the item. They are done once their response\n * processing sets completionStatus to 'completed'.\n */\nexport function isItemDone(\n numAttempts: number,\n optimality: ItemOptimality,\n maxAttempts: number | undefined,\n adaptive?: boolean,\n completionStatus?: string\n): boolean {\n if (numAttempts === 0) return false;\n if (adaptive) return completionStatus === 'completed';\n if (optimality !== 'suboptimal') return true;\n const max = maxAttempts ?? 1;\n return max > 0 && numAttempts >= max;\n}\n\n/**\n * Decide whether an item's submission is as good as it can get — i.e. the\n * candidate reached the *optimal* outcome, so there's no reason to make them\n * try again. 'optimal' means best achievable, 'suboptimal' means a better\n * attempt is still possible, 'unscored' means there's nothing to judge against.\n * (\"optimal\" is the spec's own word — a qti-correct-response is defined as\n * \"the (or an) optimal value\".)\n *\n * Two signals, in order of authority:\n * 1. The scored outcome: optimal ⟺ SCORE has reached its maximum (MAXSCORE).\n * This correctly handles partial-credit / qti-mapping items, where an exact\n * response match would under- or over-judge.\n * 2. The declared qti-correct-response, for items that aren't scored (no\n * SCORE/MAXSCORE) — an exact match is the best available proxy. Bookkeeping\n * variables like numAttempts can be typed 'response' but never declare a\n * correctResponse, so we filter on a declared correctResponse.\n *\n * Items with neither a comparable score nor a correctResponse (essays, info\n * items, etc.) are 'unscored' — there's no optimal value to require, so one\n * attempt is enough.\n */\nexport function assessOptimality(item: ItemContext): ItemOptimality {\n const variables = item.variables ?? [];\n\n const score = numericVariable(variables, 'SCORE');\n const maxScore = numericVariable(variables, 'MAXSCORE');\n if (score !== null && maxScore !== null) {\n return score >= maxScore ? 'optimal' : 'suboptimal';\n }\n\n const responseVars = variables.filter(\n (v): v is ResponseVariable =>\n v.type === 'response' &&\n (v as ResponseVariable).correctResponse !== undefined &&\n (v as ResponseVariable).correctResponse !== null\n );\n if (responseVars.length === 0) return 'unscored';\n const allMatch = responseVars.every(v => {\n const expected = v.correctResponse;\n const actual = v.value;\n if (actual === undefined || actual === null) return false;\n if (Array.isArray(expected) && Array.isArray(actual)) {\n return expected.length === actual.length && expected.every(e => actual.includes(e));\n }\n if (Array.isArray(expected) || Array.isArray(actual)) return false;\n return expected === actual;\n });\n return allMatch ? 'optimal' : 'suboptimal';\n}\n\n/** Read a single numeric outcome value, or null when absent / non-numeric. */\nfunction numericVariable(variables: ItemContext['variables'], identifier: string): number | null {\n const raw = variables?.find(v => v.identifier === identifier)?.value;\n if (raw === undefined || raw === null || Array.isArray(raw)) return null;\n const parsed = parseFloat(raw.toString());\n return Number.isNaN(parsed) ? null : parsed;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"derive-computed-context.js","sourceRoot":"","sources":["../../src/internal/derive-computed-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,WAAW,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AA2CvH;;;;;;GAMG;AACH,MAAM,UAAU,qBAAqB,CAAC,MAA6B;IACjE,MAAM,EAAE,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,GAAG,MAAM,CAAC;IACtD,MAAM,WAAW,GAAG,sBAAsB,CACxC,KAAK,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,eAAe,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,EAC/D,MAAM,CAAC,gBAAgB,CACxB,CAAC;IACF,OAAO;QACL,WAAW;QACX,UAAU,EAAE,KAAK,CAAC,UAAU;QAC5B,KAAK,EAAE,KAAK,CAAC,KAAK;QAClB,IAAI,EAAE,cAAc,EAAE,IAAI;QAC1B,OAAO,EAAE,cAAc,EAAE,OAAO,IAAI,EAAE;QACtC,SAAS,EAAE,KAAK,CAAC,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;YAC1C,MAAM,EAAE,cAAc,EAAE,SAAS,KAAK,QAAQ,CAAC,UAAU;YACzD,UAAU,EAAE,QAAQ,CAAC,UAAU;YAC/B,cAAc,EAAE,QAAQ,CAAC,cAAc;YACvC,cAAc,EAAE,QAAQ,CAAC,cAAc;YACvC,aAAa,EAAE,QAAQ,CAAC,cAAc,CAAC,aAAa;YACpD,SAAS,EAAE,eAAe,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,UAAU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C;AAC9C,CAAC","sourcesContent":["import { itemRefsInOrder, itemRules, ownItemRefs, sectionsInOrder, seedItemLifecycle } from '@qti-components/delivery';\n\nimport type { ComputedContext, ComputedItem, ItemContext, ResponseVariable } from '@qti-components/base';\nimport type { SessionContext, TestContext } from '@qti-components/base';\nimport type { ItemFacts, ItemLifecycleState, ItemRefModel, TestModel, TestPartModel } from '@qti-components/delivery';\nimport type { ItemFactsByRef } from './item-facts.context';\n\n/**\n * Whether an item's ended attempt reached the best achievable outcome:\n * 'optimal' (nothing to improve), 'suboptimal' (a better attempt is possible),\n * or 'unscored' (no machine-judgeable optimal value — see `assessOptimality`).\n */\nexport type ItemOptimality = 'optimal' | 'suboptimal' | 'unscored';\n\n/** Everything `computedContext` is derived from. Nothing here is the previous `computedContext`. */\nexport interface ComputedContextInputs {\n /** The test's structure and resolved session control, from its XML (`buildTestModel`). */\n readonly model: TestModel;\n /** The facts of every item fetched so far, by item-ref identifier. */\n readonly itemFacts?: ItemFactsByRef;\n /** The candidate's responses and outcomes, per item. */\n readonly testContext?: Readonly<TestContext>;\n /** Where the candidate is, the view and the plugin state. */\n readonly sessionContext?: Readonly<SessionContext>;\n /** `config.infoItemCategory`: items with it are not numbered. */\n readonly infoItemCategory?: string;\n /** The host's per-item fields (`initContext`): each item gets them under `data`, never at its top level. */\n readonly itemData?: readonly { identifier: string; [key: string]: unknown }[];\n /**\n * The optimality of each item's last ended attempt, by item-ref identifier (see `ItemOptimality`).\n * Kept by `test-navigation`, since it is not in the contexts: it is written when an attempt ends,\n * never on a plain change of the answer.\n */\n readonly optimality: ReadonlyMap<string, ItemOptimality>;\n /**\n * The lifecycle state of each item session, by item-ref identifier, kept by `test-navigation`\n * (`followItemSession`, `endItemAttempt`). An item it does not list is seeded from its attempts.\n */\n readonly lifecycle?: ReadonlyMap<string, ItemLifecycleState>;\n /** `computedContext.itemElement`, passed through. */\n readonly itemElement?: ComputedContext['itemElement'];\n}\n\n/**\n * `computedContext`, derived from its inputs alone: built anew on every call, never from the previous\n * context, and never changing an input. The same inputs give an equal context.\n *\n * Roadmap 1, T2c. `DeliveryState` is not live at runtime yet, so the candidate's state comes from\n * `testContext` and `sessionContext`; T3 and T8 move it into `DeliveryState`, and add their fields here.\n */\nexport function deriveComputedContext(inputs: ComputedContextInputs): ComputedContext {\n const { model, sessionContext, itemElement } = inputs;\n const itemIndexes = indexesInDocumentOrder(\n model.testParts.flatMap(part => itemRefsInOrder(part.sections)),\n inputs.infoItemCategory\n );\n return {\n itemElement,\n identifier: model.identifier,\n title: model.title,\n view: sessionContext?.view,\n plugins: sessionContext?.plugins ?? {},\n testParts: model.testParts.map(testPart => ({\n active: sessionContext?.navPartId === testPart.identifier,\n identifier: testPart.identifier,\n navigationMode: testPart.navigationMode,\n submissionMode: testPart.submissionMode,\n allowSkipping: testPart.sessionControl.allowSkipping,\n itemOrder: itemRefsInOrder(testPart.sections).map(item => item.identifier),\n // Flat, depth first: every section once, each with only its own item-refs, so every item is\n // listed once. Where a section's item-refs and subsections interleave, this list is not in\n // document order; `index` is.\n sections: sectionsInOrder(testPart.sections).map(section => ({\n active: sessionContext?.navSectionId === section.identifier,\n identifier: section.identifier,\n title: section.title,\n allowSkipping: section.sessionControl.allowSkipping,\n // A section that only holds subsections is completed when theirs are.\n completed: itemRefsInOrder(section.content).every(\n item => variableValue(itemContextFor(inputs, item.identifier), 'completionStatus') === 'completed'\n ),\n items: ownItemRefs(section).map(item =>\n deriveItem(inputs, testPart, item, itemIndexes.get(item.identifier) ?? null)\n )\n }))\n }))\n };\n}\n\nfunction deriveItem(\n inputs: ComputedContextInputs,\n testPart: TestPartModel,\n item: ItemRefModel,\n index: number | null\n): ComputedItem {\n const itemContext = itemContextFor(inputs, item.identifier);\n // Only the fields an item context holds: a host that restores `testContext` with fields of its\n // own sets nothing here. Its fields for an item belong in `itemData`, which lands under `data`.\n const computedItem = {\n active: false,\n identifier: item.identifier,\n categories: [...item.categories],\n href: item.href,\n sessionControl: { ...item.sessionControl },\n ...factsFor(inputs.itemFacts, item.identifier),\n variables: itemContext?.variables ?? [],\n ...(itemContext?.state === undefined ? {} : { state: itemContext.state }),\n ...(itemContext?.readonly === undefined ? {} : { readonly: itemContext.readonly }),\n ...(itemContext?.disabled === undefined ? {} : { disabled: itemContext.disabled })\n } as ComputedItem;\n\n const rawScore = variableValue(computedItem, 'SCORE');\n const score = rawScore === undefined || rawScore === null ? null : parseFloat(rawScore.toString());\n const rawMaxScore = variableValue(computedItem, 'MAXSCORE');\n const maxScore = rawMaxScore === undefined || rawMaxScore === null ? null : parseFloat(rawMaxScore.toString());\n const completionStatus = variableValue(computedItem, 'completionStatus') as string;\n const response = variableValue(computedItem, 'RESPONSE') || '';\n const numAttempts = Number(variableValue(computedItem, 'numAttempts')) || 0;\n\n // Optimality comes from the last *ended attempt*, never from a live mid-attempt selection.\n // `test-navigation` seeds the latch once from a restored context, which still holds the submitted\n // response; before that, an item with no ended attempt is assessed on what it holds.\n const latched = inputs.optimality.get(item.identifier);\n const optimality = latched ?? (itemContext ? assessOptimality(itemContext) : 'unscored');\n\n return {\n ...computedItem,\n completionStatus,\n numAttempts,\n score,\n response,\n index,\n active: inputs.sessionContext?.navItemRefId === item.identifier,\n // Published by the item. One that is not on screen has nothing to be invalid.\n valid: itemContext?.valid ?? true,\n isDefaultResponse: isDefaultResponse(itemContext),\n maxScore,\n done: isItemDone(\n numAttempts,\n optimality,\n computedItem.sessionControl?.maxAttempts,\n computedItem.adaptive,\n completionStatus\n ),\n // Reflects the last *ended* attempt only: the latch, not the fallback above.\n optimal: latched === 'optimal',\n ...lifecycleOf(inputs, testPart, item, itemContext, { numAttempts, completionStatus }),\n data: hostData(inputs.itemData, item.identifier)\n } as ComputedItem;\n}\n\n/** The item session's lifecycle state and what it may do now (`itemRules`), computed: host data never sets it. */\nfunction lifecycleOf(\n inputs: ComputedContextInputs,\n testPart: TestPartModel,\n item: ItemRefModel,\n itemContext: ItemContext | undefined,\n { numAttempts, completionStatus }: { numAttempts: number; completionStatus: string | undefined }\n): Pick<ComputedItem, 'lifecycle' | 'rules'> {\n const session = {\n sessionControl: item.sessionControl,\n adaptive: inputs.itemFacts?.get(item.identifier)?.adaptive ?? false,\n navigationMode: testPart.navigationMode,\n submissionMode: testPart.submissionMode,\n numAttempts,\n completionStatus: completionStatus ?? null\n };\n const lifecycle =\n inputs.lifecycle?.get(item.identifier) ??\n seedItemLifecycle({\n ...session,\n presented: inputs.sessionContext?.navItemRefId === item.identifier,\n passed: false\n });\n const rules = itemRules({\n ...session,\n state: lifecycle,\n // Only resuming reads it, and no answer asks about resuming.\n left: false,\n modalFeedback: false,\n skipped: isSkipped(itemContext),\n valid: itemContext?.valid ?? true\n });\n return { lifecycle, rules };\n}\n\n/** The host's fields for an item (`initContext`), without the identifier that matched them; `{}` when none. */\nfunction hostData(itemData: ComputedContextInputs['itemData'], identifier: string): ComputedItem['data'] {\n const entry = itemData?.find(data => data.identifier === identifier);\n if (!entry) return {};\n return Object.fromEntries(Object.entries(entry).filter(([key]) => key !== 'identifier'));\n}\n\nfunction itemContextFor(inputs: ComputedContextInputs, identifier: string): ItemContext | undefined {\n return inputs.testContext?.items?.find(item => item.identifier === identifier);\n}\n\nfunction variableValue(item: { variables?: ItemContext['variables'] } | undefined, identifier: string) {\n return item?.variables?.find(variable => variable.identifier === identifier)?.value;\n}\n\n/** An item's facts as `computedContext` carries them; nothing until the item is fetched. */\nfunction factsFor(\n itemFacts: ItemFactsByRef | undefined,\n identifier: string\n): Partial<Omit<ItemFacts, 'identifier'>> & { assessmentItemIdentifier?: string } {\n const facts = itemFacts?.get(identifier);\n if (!facts) return {};\n const { identifier: assessmentItemIdentifier, ...rest } = facts;\n return { ...rest, assessmentItemIdentifier };\n}\n\n/** Item numbers in document order, skipping info items; null for an info item. */\nfunction indexesInDocumentOrder(items: ItemRefModel[], infoItemCategory: string | undefined) {\n let index = 1;\n return new Map(\n items.map(item => [item.identifier, item.categories.includes(infoItemCategory) ? null : index++] as const)\n );\n}\n\n/**\n * No response given (QTI info model §7.19, `allow-skipping`): every response variable holds its\n * default or NULL. An item with no response variables \"by definition cannot be skipped\"; one not\n * fetched yet has given none.\n */\nfunction isSkipped(itemContext: ItemContext | undefined): boolean {\n if (!itemContext) return true;\n const responses = itemContext.variables?.filter(\n v => v.type === 'response' && v.identifier !== 'numAttempts' && v.identifier !== 'duration'\n );\n return Boolean(responses?.length) && isDefaultResponse(itemContext);\n}\n\n/** Every response still holds its default (or the base type's empty value): nothing answered. */\nfunction isDefaultResponse(itemContext: ItemContext | undefined): boolean {\n const responseVariables =\n itemContext?.variables?.filter(v => v.type === 'response' && v.identifier !== 'numAttempts') || [];\n return responseVariables.every(v => {\n if (v.value === undefined || v.value === null) return true;\n let fallbackValue: string;\n switch (v.baseType) {\n case 'integer':\n case 'float':\n case 'duration':\n fallbackValue = '0';\n break;\n case 'boolean':\n fallbackValue = 'false';\n break;\n default:\n fallbackValue = '';\n break;\n }\n const defaultValue = v.defaultValue ?? fallbackValue;\n if (Array.isArray(v.value)) {\n const dv = Array.isArray(defaultValue) ? defaultValue : [defaultValue];\n return v.value.length === dv.length && v.value.every((val, i) => val === dv[i]);\n }\n return v.value === defaultValue;\n });\n}\n\n/**\n * Decide whether an item should be treated as \"the candidate is done with it\"\n * for the purpose of gating forward navigation and further attempts.\n *\n * - The candidate must have actually ended an attempt (numAttempts > 0).\n * - Once attempted, the item is done if they reached the optimal outcome\n * ('optimal'), or there's nothing to improve on ('unscored'). It is only *not*\n * done while a better attempt is still possible ('suboptimal') and attempts\n * remain — see `assessOptimality` for how \"optimal\" is determined.\n *\n * `optimality` reflects the last *ended attempt*, not the live selection — so a\n * freshly-picked optimal answer doesn't count as done until test-end-attempt\n * evaluates it.\n *\n * Adaptive items decide this themselves: max-attempts does not apply to them\n * (QTI 3, itemSessionControl), and a wrong attempt may be the step that leads\n * on to the next part of the item. They are done once their response\n * processing sets completionStatus to 'completed'.\n */\nexport function isItemDone(\n numAttempts: number,\n optimality: ItemOptimality,\n maxAttempts: number | undefined,\n adaptive?: boolean,\n completionStatus?: string\n): boolean {\n if (numAttempts === 0) return false;\n if (adaptive) return completionStatus === 'completed';\n if (optimality !== 'suboptimal') return true;\n const max = maxAttempts ?? 1;\n return max > 0 && numAttempts >= max;\n}\n\n/**\n * Decide whether an item's submission is as good as it can get — i.e. the\n * candidate reached the *optimal* outcome, so there's no reason to make them\n * try again. 'optimal' means best achievable, 'suboptimal' means a better\n * attempt is still possible, 'unscored' means there's nothing to judge against.\n * (\"optimal\" is the spec's own word — a qti-correct-response is defined as\n * \"the (or an) optimal value\".)\n *\n * Two signals, in order of authority:\n * 1. The scored outcome: optimal ⟺ SCORE has reached its maximum (MAXSCORE).\n * This correctly handles partial-credit / qti-mapping items, where an exact\n * response match would under- or over-judge.\n * 2. The declared qti-correct-response, for items that aren't scored (no\n * SCORE/MAXSCORE) — an exact match is the best available proxy. Bookkeeping\n * variables like numAttempts can be typed 'response' but never declare a\n * correctResponse, so we filter on a declared correctResponse.\n *\n * Items with neither a comparable score nor a correctResponse (essays, info\n * items, etc.) are 'unscored' — there's no optimal value to require, so one\n * attempt is enough.\n */\nexport function assessOptimality(item: ItemContext): ItemOptimality {\n const variables = item.variables ?? [];\n\n const score = numericVariable(variables, 'SCORE');\n const maxScore = numericVariable(variables, 'MAXSCORE');\n if (score !== null && maxScore !== null) {\n return score >= maxScore ? 'optimal' : 'suboptimal';\n }\n\n const responseVars = variables.filter(\n (v): v is ResponseVariable =>\n v.type === 'response' &&\n (v as ResponseVariable).correctResponse !== undefined &&\n (v as ResponseVariable).correctResponse !== null\n );\n if (responseVars.length === 0) return 'unscored';\n const allMatch = responseVars.every(v => {\n const expected = v.correctResponse;\n const actual = v.value;\n if (actual === undefined || actual === null) return false;\n if (Array.isArray(expected) && Array.isArray(actual)) {\n return expected.length === actual.length && expected.every(e => actual.includes(e));\n }\n if (Array.isArray(expected) || Array.isArray(actual)) return false;\n return expected === actual;\n });\n return allMatch ? 'optimal' : 'suboptimal';\n}\n\n/** Read a single numeric outcome value, or null when absent / non-numeric. */\nfunction numericVariable(variables: ItemContext['variables'], identifier: string): number | null {\n const raw = variables?.find(v => v.identifier === identifier)?.value;\n if (raw === undefined || raw === null || Array.isArray(raw)) return null;\n const parsed = parseFloat(raw.toString());\n return Number.isNaN(parsed) ? null : parsed;\n}\n"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ItemContext } from '@qti-components/base';
|
|
2
|
+
import type { ItemSessionFacts, TestModel } from '@qti-components/delivery';
|
|
3
|
+
import type { ItemFactsByRef } from './item-facts.context';
|
|
4
|
+
/** Where the candidate is, for the facts of every item session. */
|
|
5
|
+
export interface ItemSessionPosition {
|
|
6
|
+
/** The current item-ref (`sessionContext.navItemRefId`); null or undefined when none is. */
|
|
7
|
+
readonly current: string | null | undefined;
|
|
8
|
+
/** The item-refs whose items are on screen. */
|
|
9
|
+
readonly presented: ReadonlySet<string>;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* What the delivery knows about each item session at an update, by item-ref identifier: its session
|
|
13
|
+
* control and part, its attempts and `completionStatus` from its context, whether it is on screen,
|
|
14
|
+
* and whether a linear part has passed it (it comes before the current item there). Pure.
|
|
15
|
+
*/
|
|
16
|
+
export declare function itemSessionFacts(model: TestModel, itemFacts: ItemFactsByRef | undefined, items: readonly ItemContext[] | undefined, { current, presented }: ItemSessionPosition): Map<string, ItemSessionFacts>;
|
|
17
|
+
/** The ended attempts and `completionStatus` an item context holds. */
|
|
18
|
+
export declare function attemptsOf(context: ItemContext | undefined): Pick<ItemSessionFacts, 'numAttempts' | 'completionStatus'>;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { itemRefsInOrder } from '@qti-components/delivery';
|
|
2
|
+
/**
|
|
3
|
+
* What the delivery knows about each item session at an update, by item-ref identifier: its session
|
|
4
|
+
* control and part, its attempts and `completionStatus` from its context, whether it is on screen,
|
|
5
|
+
* and whether a linear part has passed it (it comes before the current item there). Pure.
|
|
6
|
+
*/
|
|
7
|
+
export function itemSessionFacts(model, itemFacts, items, { current, presented }) {
|
|
8
|
+
const facts = new Map();
|
|
9
|
+
for (const testPart of model.testParts) {
|
|
10
|
+
const order = itemRefsInOrder(testPart.sections);
|
|
11
|
+
const currentIndex = order.findIndex(item => item.identifier === current);
|
|
12
|
+
order.forEach((item, index) => {
|
|
13
|
+
const context = items?.find(candidate => candidate.identifier === item.identifier);
|
|
14
|
+
facts.set(item.identifier, {
|
|
15
|
+
...attemptsOf(context),
|
|
16
|
+
sessionControl: item.sessionControl,
|
|
17
|
+
adaptive: itemFacts?.get(item.identifier)?.adaptive ?? false,
|
|
18
|
+
navigationMode: testPart.navigationMode,
|
|
19
|
+
submissionMode: testPart.submissionMode,
|
|
20
|
+
presented: presented.has(item.identifier),
|
|
21
|
+
passed: testPart.navigationMode === 'linear' && currentIndex >= 0 && index < currentIndex
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
return facts;
|
|
26
|
+
}
|
|
27
|
+
/** The ended attempts and `completionStatus` an item context holds. */
|
|
28
|
+
export function attemptsOf(context) {
|
|
29
|
+
const value = (identifier) => context?.variables?.find(v => v.identifier === identifier)?.value;
|
|
30
|
+
const completionStatus = value('completionStatus');
|
|
31
|
+
return {
|
|
32
|
+
numAttempts: Number(value('numAttempts')) || 0,
|
|
33
|
+
completionStatus: typeof completionStatus === 'string' ? completionStatus : null
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=item-session-facts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"item-session-facts.js","sourceRoot":"","sources":["../../src/internal/item-session-facts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAc3D;;;;GAIG;AACH,MAAM,UAAU,gBAAgB,CAC9B,KAAgB,EAChB,SAAqC,EACrC,KAAyC,EACzC,EAAE,OAAO,EAAE,SAAS,EAAuB;IAE3C,MAAM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AC,EAAE,KAAK,CAAC;IACxG,MAAM,gBAAgB,GAAG,KAAK,CAAC,kBAAkB,CAAC,CAAC;IACnD,OAAO;QACL,WAAW,EAAE,MAAM,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC,IAAI,CAAC;QAC9C,gBAAgB,EAAE,OAAO,gBAAgB,KAAK,QAAQ,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,IAAI;KACjF,CAAC;AACJ,CAAC","sourcesContent":["import { itemRefsInOrder } from '@qti-components/delivery';\n\nimport type { ItemContext } from '@qti-components/base';\nimport type { ItemSessionFacts, TestModel } from '@qti-components/delivery';\nimport type { ItemFactsByRef } from './item-facts.context';\n\n/** Where the candidate is, for the facts of every item session. */\nexport interface ItemSessionPosition {\n /** The current item-ref (`sessionContext.navItemRefId`); null or undefined when none is. */\n readonly current: string | null | undefined;\n /** The item-refs whose items are on screen. */\n readonly presented: ReadonlySet<string>;\n}\n\n/**\n * What the delivery knows about each item session at an update, by item-ref identifier: its session\n * control and part, its attempts and `completionStatus` from its context, whether it is on screen,\n * and whether a linear part has passed it (it comes before the current item there). Pure.\n */\nexport function itemSessionFacts(\n model: TestModel,\n itemFacts: ItemFactsByRef | undefined,\n items: readonly ItemContext[] | undefined,\n { current, presented }: ItemSessionPosition\n): Map<string, ItemSessionFacts> {\n const facts = new Map<string, ItemSessionFacts>();\n for (const testPart of model.testParts) {\n const order = itemRefsInOrder(testPart.sections);\n const currentIndex = order.findIndex(item => item.identifier === current);\n order.forEach((item, index) => {\n const context = items?.find(candidate => candidate.identifier === item.identifier);\n facts.set(item.identifier, {\n ...attemptsOf(context),\n sessionControl: item.sessionControl,\n adaptive: itemFacts?.get(item.identifier)?.adaptive ?? false,\n navigationMode: testPart.navigationMode,\n submissionMode: testPart.submissionMode,\n presented: presented.has(item.identifier),\n passed: testPart.navigationMode === 'linear' && currentIndex >= 0 && index < currentIndex\n });\n });\n }\n return facts;\n}\n\n/** The ended attempts and `completionStatus` an item context holds. */\nexport function attemptsOf(\n context: ItemContext | undefined\n): Pick<ItemSessionFacts, 'numAttempts' | 'completionStatus'> {\n const value = (identifier: string) => context?.variables?.find(v => v.identifier === identifier)?.value;\n const completionStatus = value('completionStatus');\n return {\n numAttempts: Number(value('numAttempts')) || 0,\n completionStatus: typeof completionStatus === 'string' ? completionStatus : null\n };\n}\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": "2.0.0-next.
|
|
4
|
+
"version": "2.0.0-next.26",
|
|
5
5
|
"author": "",
|
|
6
6
|
"dependencies": {
|
|
7
7
|
"@heximal/templates": "^0.1.5",
|
|
8
|
-
"@qti-components/base": "^3.0.0-next.
|
|
9
|
-
"@qti-components/delivery": "^0.1.0-next.
|
|
8
|
+
"@qti-components/base": "^3.0.0-next.13",
|
|
9
|
+
"@qti-components/delivery": "^0.1.0-next.6",
|
|
10
10
|
"@qti-components/elements": "^2.0.0-next.7",
|
|
11
11
|
"@qti-components/interactions": "^1.10.5-next.8",
|
|
12
12
|
"@qti-components/processing": "^1.6.1-next.5",
|