@qti-components/test 2.0.0-next.25 → 2.0.0-next.27
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-end-attempt/test-end-attempt.d.ts +7 -5
- package/dist/components/test-end-attempt/test-end-attempt.js +26 -31
- package/dist/components/test-end-attempt/test-end-attempt.js.map +1 -1
- package/dist/components/test-navigation/test-navigation.d.ts +12 -4
- package/dist/components/test-navigation/test-navigation.js +133 -46
- package/dist/components/test-navigation/test-navigation.js.map +1 -1
- package/dist/components/test-next/test-next.d.ts +4 -1
- package/dist/components/test-next/test-next.js +16 -13
- package/dist/components/test-next/test-next.js.map +1 -1
- package/dist/components/test-prev/test-prev.js +10 -3
- package/dist/components/test-prev/test-prev.js.map +1 -1
- package/dist/internal/derive-computed-context.d.ts +1 -21
- package/dist/internal/derive-computed-context.js +20 -40
- package/dist/internal/derive-computed-context.js.map +1 -1
- package/dist/internal/test-host.context.d.ts +12 -0
- package/dist/internal/test-host.context.js.map +1 -1
- package/dist/mixins/test-navigation.mixin.js +22 -0
- package/dist/mixins/test-navigation.mixin.js.map +1 -1
- package/package.json +3 -3
|
@@ -11,13 +11,15 @@ import type { ComputedContext } from '@qti-components/base';
|
|
|
11
11
|
* its own button. Give it an `item` (an item-ref identifier) to end the attempt of that item instead,
|
|
12
12
|
* wherever the button sits.
|
|
13
13
|
*
|
|
14
|
-
* It is `disabled` by
|
|
15
|
-
* (
|
|
16
|
-
*
|
|
17
|
-
*
|
|
14
|
+
* It is `disabled` by its item's session (`computedContext` item `rules`): when the item is not
|
|
15
|
+
* interacting (its attempts used, a completed adaptive item, or passed in a linear part), when no
|
|
16
|
+
* attempt is left, or while its responses may not be submitted (`allow-skipping="false"` with no
|
|
17
|
+
* answer, `validate-responses` with an invalid one). The score never disables it: a right answer
|
|
18
|
+
* leaves the attempts `max-attempts` gives (decided 2026-11-27). In a simultaneous part it ends the
|
|
19
|
+
* item's attempt as before, until part submission processes the responses (roadmap 1, T6).
|
|
18
20
|
*
|
|
19
21
|
* @slot - The label.
|
|
20
|
-
* @attr require-answer - Also disabled while the response is invalid or still the default,
|
|
22
|
+
* @attr require-answer - Also disabled while the response is invalid or still the default, whatever the item's session control says.
|
|
21
23
|
* @attr item - The item-ref identifier whose attempt this button ends; without it, the item it is stamped into, or else the one on screen.
|
|
22
24
|
* @attr disabled - Reflected: the item's attempt cannot be ended.
|
|
23
25
|
*/
|
|
@@ -30,13 +30,15 @@ const itemRefOf = (element) => {
|
|
|
30
30
|
* its own button. Give it an `item` (an item-ref identifier) to end the attempt of that item instead,
|
|
31
31
|
* wherever the button sits.
|
|
32
32
|
*
|
|
33
|
-
* It is `disabled` by
|
|
34
|
-
* (
|
|
35
|
-
*
|
|
36
|
-
*
|
|
33
|
+
* It is `disabled` by its item's session (`computedContext` item `rules`): when the item is not
|
|
34
|
+
* interacting (its attempts used, a completed adaptive item, or passed in a linear part), when no
|
|
35
|
+
* attempt is left, or while its responses may not be submitted (`allow-skipping="false"` with no
|
|
36
|
+
* answer, `validate-responses` with an invalid one). The score never disables it: a right answer
|
|
37
|
+
* leaves the attempts `max-attempts` gives (decided 2026-11-27). In a simultaneous part it ends the
|
|
38
|
+
* item's attempt as before, until part submission processes the responses (roadmap 1, T6).
|
|
37
39
|
*
|
|
38
40
|
* @slot - The label.
|
|
39
|
-
* @attr require-answer - Also disabled while the response is invalid or still the default,
|
|
41
|
+
* @attr require-answer - Also disabled while the response is invalid or still the default, whatever the item's session control says.
|
|
40
42
|
* @attr item - The item-ref identifier whose attempt this button ends; without it, the item it is stamped into, or else the one on screen.
|
|
41
43
|
* @attr disabled - Reflected: the item's attempt cannot be ended.
|
|
42
44
|
*/
|
|
@@ -83,32 +85,12 @@ export class TestEndAttempt extends LitElement {
|
|
|
83
85
|
this._internalDisabled = false;
|
|
84
86
|
return;
|
|
85
87
|
}
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
//
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
this._internalDisabled = true;
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
// An adaptive item ends itself: once its response processing set completionStatus
|
|
96
|
-
// to 'completed', there is no next attempt.
|
|
97
|
-
if (activeItem.adaptive && activeItem.completionStatus === 'completed') {
|
|
98
|
-
this._internalDisabled = true;
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
|
-
// For non-adaptive items, disable when max attempts have been reached
|
|
102
|
-
if (!activeItem.adaptive && maxAttempts > 0 && numAttempts >= maxAttempts) {
|
|
103
|
-
this._internalDisabled = true;
|
|
104
|
-
return;
|
|
105
|
-
}
|
|
106
|
-
if (this.requireAnswer || activeItem.sessionControl?.allowSkipping === false) {
|
|
107
|
-
this._internalDisabled = activeItem.valid === false || activeItem.isDefaultResponse;
|
|
108
|
-
}
|
|
109
|
-
else {
|
|
110
|
-
this._internalDisabled = false;
|
|
111
|
-
}
|
|
88
|
+
const rules = activeItem.rules;
|
|
89
|
+
// `interactive && attemptsLeft` is `mayEndAttempt` in a part with individual submission; it also
|
|
90
|
+
// covers a simultaneous part, kept until T6, and `auto-score-items`, whose sessions stay open.
|
|
91
|
+
const mayEnd = rules ? rules.interactive && rules.attemptsLeft && rules.maySubmit : fromSessionControl(activeItem);
|
|
92
|
+
const answered = activeItem.valid !== false && !activeItem.isDefaultResponse;
|
|
93
|
+
this._internalDisabled = !mayEnd || (this.requireAnswer && !answered);
|
|
112
94
|
}
|
|
113
95
|
render() {
|
|
114
96
|
return styles.control;
|
|
@@ -130,4 +112,17 @@ __decorate([
|
|
|
130
112
|
__decorate([
|
|
131
113
|
watch('computedContext')
|
|
132
114
|
], TestEndAttempt.prototype, "_handleTestElementChange", null);
|
|
115
|
+
/**
|
|
116
|
+
* For a computed item without `rules` (a context a host built): the same QTI rules from its session
|
|
117
|
+
* control, attempts and responses (`qti-item-session-control`, info model §7.19).
|
|
118
|
+
*/
|
|
119
|
+
function fromSessionControl(item) {
|
|
120
|
+
const { maxAttempts = 1, allowSkipping = true, validateResponses = false } = item.sessionControl ?? {};
|
|
121
|
+
const numAttempts = item.numAttempts || 0;
|
|
122
|
+
const attemptsLeft = item.adaptive
|
|
123
|
+
? item.completionStatus !== 'completed'
|
|
124
|
+
: maxAttempts === 0 || numAttempts < maxAttempts;
|
|
125
|
+
const maySkip = allowSkipping || !item.isDefaultResponse;
|
|
126
|
+
return attemptsLeft && maySkip && (!validateResponses || item.valid !== false);
|
|
127
|
+
}
|
|
133
128
|
//# sourceMappingURL=test-end-attempt.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"test-end-attempt.js","sourceRoot":"","sources":["../../../src/components/test-end-attempt/test-end-attempt.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AACjC,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,KAAK,EAAE,MAAM,2BAA2B,CAAC;AAElD,OAAO,KAAK,MAAM,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAIrD,2HAA2H;AAC3H,MAAM,SAAS,GAAG,CAAC,OAAgB,EAAsB,EAAE;IACzD,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,yBAAyB,CAAC,CAAC;IAC3D,IAAI,OAAO;QAAE,OAAO,OAAO,CAAC,YAAY,CAAC,YAAY,CAAC,IAAI,SAAS,CAAC;IACpE,MAAM,IAAI,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;IACnC,OAAO,IAAI,YAAY,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AACvE,CAAC,CAAC;AAEF
|
|
1
|
+
{"version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AsDH;;;GAGG;AACH,SAAS,kBAAkB,CAAC,IAAkB;IAC5C,MAAM,EAAE,WAAW,GAAG,CAAC,EAAE,aAAa,GAAG,IAAI,EAAE,iBAAiB,GAAG,KAAK,EAAE,GAAG,IAAI,CAAC,cAAc,IAAI,EAAE,CAAC;IACvG,MAAM,WAAW,GAAG,IAAI,CAAC,WAAW,IAAI,CAAC,CAAC;IAC1C,MAAM,YAAY,GAAG,IAAI,CAAC,QAAQ;QAChC,CAAC,CAAC,IAAI,CAAC,gBAAgB,KAAK,WAAW;QACvC,CAAC,CAAC,WAAW,KAAK,CAAC,IAAI,WAAW,GAAG,WAAW,CAAC;IACnD,MAAM,OAAO,GAAG,aAAa,IAAI,CAAC,IAAI,CAAC,iBAAiB,CAAC;IACzD,OAAO,YAAY,IAAI,OAAO,IAAI,CAAC,CAAC,iBAAiB,IAAI,IAAI,CAAC,KAAK,KAAK,KAAK,CAAC,CAAC;AACjF,CAAC","sourcesContent":["import { LitElement } from 'lit';\nimport { property } from 'lit/decorators.js';\nimport { consume } from '@lit/context';\n\nimport { computedContext } from '@qti-components/base';\nimport { watch } from '@qti-components/utilities';\n\nimport * as styles from '../styles';\nimport { dispatchPublic } from '../../public-events';\n\nimport type { ComputedContext, ComputedItem } from '@qti-components/base';\n\n/** The identifier of the item-ref an element is stamped into (`<template item-ref>`), looking out through shadow roots. */\nconst itemRefOf = (element: Element): string | undefined => {\n const itemRef = element.closest('qti-assessment-item-ref');\n if (itemRef) return itemRef.getAttribute('identifier') ?? undefined;\n const root = element.getRootNode();\n return root instanceof ShadowRoot ? itemRefOf(root.host) : undefined;\n};\n\n/**\n * A button that ends the attempt of an item: its response is processed, `numAttempts` goes up and\n * feedback is shown as the item's session control allows. It dispatches `qc-test-end-attempt`,\n * which `<test-navigation>` handles.\n *\n * Put it inside `<test-navigation>`, either in the toolbar, where it ends the attempt of the item on\n * screen, or in the `<template item-ref>`, where each item gets its own and it ends the attempt of\n * that item: with `<qti-test navigate=\"section\">` every item of the section is on screen, each with\n * its own button. Give it an `item` (an item-ref identifier) to end the attempt of that item instead,\n * wherever the button sits.\n *\n * It is `disabled` by its item's session (`computedContext` item `rules`): when the item is not\n * interacting (its attempts used, a completed adaptive item, or passed in a linear part), when no\n * attempt is left, or while its responses may not be submitted (`allow-skipping=\"false\"` with no\n * answer, `validate-responses` with an invalid one). The score never disables it: a right answer\n * leaves the attempts `max-attempts` gives (decided 2026-11-27). In a simultaneous part it ends the\n * item's attempt as before, until part submission processes the responses (roadmap 1, T6).\n *\n * @slot - The label.\n * @attr require-answer - Also disabled while the response is invalid or still the default, whatever the item's session control says.\n * @attr item - The item-ref identifier whose attempt this button ends; without it, the item it is stamped into, or else the one on screen.\n * @attr disabled - Reflected: the item's attempt cannot be ended.\n */\nexport class TestEndAttempt extends LitElement {\n @consume({ context: computedContext, subscribe: true })\n @property({ attribute: false })\n protected computedContext: ComputedContext;\n\n @property({ type: Boolean, reflect: true, attribute: 'disabled' })\n public _internalDisabled = false;\n\n @property({ reflect: true }) item?: string;\n\n /** Ends no attempt until the response is valid and not the default, whatever the item's `allow-skipping` says. */\n @property({ type: Boolean, reflect: true, attribute: 'require-answer' }) requireAnswer = false;\n\n @watch('computedContext')\n _handleTestElementChange(_oldValue: ComputedContext, newValue: ComputedContext) {\n if (newValue) {\n this.requestUpdate();\n }\n }\n\n static override styles = styles.button;\n\n constructor() {\n super();\n this.addEventListener('click', e => {\n e.preventDefault();\n if (!this._internalDisabled) {\n // An item of its own goes along, so the navigation ends that item's attempt and not the\n // one on screen; without one, the navigation takes the item on screen, as before.\n const itemId = this.#ownItem;\n dispatchPublic(this, 'qc-test-end-attempt', itemId ? { itemId } : {});\n }\n });\n }\n\n /** The item named by `item`, or else the item-ref it is stamped into. */\n get #ownItem(): string | undefined {\n return this.item || itemRefOf(this);\n }\n\n override willUpdate(_changedProperties: Map<string | number | symbol, unknown>) {\n this.checkDisabled();\n }\n\n checkDisabled() {\n const testParts = this.computedContext?.testParts;\n const ownItem = this.#ownItem;\n const testPart = testParts?.find(testPart => testPart.active);\n if (!testParts || (!ownItem && !testPart)) return;\n // Its own item wherever it is in the test, or else the item on screen in the active part.\n const activeItem = ownItem\n ? testParts.flatMap(part => part.sections.flatMap(section => section.items)).find(i => i.identifier === ownItem)\n : testPart.sections.flatMap(section => section.items).find(item => item.active);\n\n if (!activeItem) {\n this._internalDisabled = false;\n return;\n }\n\n const rules = activeItem.rules;\n // `interactive && attemptsLeft` is `mayEndAttempt` in a part with individual submission; it also\n // covers a simultaneous part, kept until T6, and `auto-score-items`, whose sessions stay open.\n const mayEnd = rules ? rules.interactive && rules.attemptsLeft && rules.maySubmit : fromSessionControl(activeItem);\n const answered = activeItem.valid !== false && !activeItem.isDefaultResponse;\n this._internalDisabled = !mayEnd || (this.requireAnswer && !answered);\n }\n\n override render() {\n return styles.control;\n }\n}\n\n/**\n * For a computed item without `rules` (a context a host built): the same QTI rules from its session\n * control, attempts and responses (`qti-item-session-control`, info model §7.19).\n */\nfunction fromSessionControl(item: ComputedItem): boolean {\n const { maxAttempts = 1, allowSkipping = true, validateResponses = false } = item.sessionControl ?? {};\n const numAttempts = item.numAttempts || 0;\n const attemptsLeft = item.adaptive\n ? item.completionStatus !== 'completed'\n : maxAttempts === 0 || numAttempts < maxAttempts;\n const maySkip = allowSkipping || !item.isDefaultResponse;\n return attemptsLeft && maySkip && (!validateResponses || item.valid !== false);\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'test-end-attempt': TestEndAttempt;\n }\n}\n"]}
|
|
@@ -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;
|
|
@@ -23,6 +30,8 @@ export declare class TestNavigation extends LitElement {
|
|
|
23
30
|
*/
|
|
24
31
|
get qtiContext(): QtiContext;
|
|
25
32
|
set qtiContext(value: QtiContext);
|
|
33
|
+
connectedCallback(): void;
|
|
34
|
+
disconnectedCallback(): void;
|
|
26
35
|
configContext: ConfigContext;
|
|
27
36
|
protected _testContext?: TestContext;
|
|
28
37
|
protected _sessionContext?: SessionContext;
|
|
@@ -32,10 +41,9 @@ export declare class TestNavigation extends LitElement {
|
|
|
32
41
|
autoScoreItems: boolean;
|
|
33
42
|
constructor();
|
|
34
43
|
/**
|
|
35
|
-
* Extension point for presentation packages reacting to an ended attempt.
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
* the next update, after this event has finished bubbling.
|
|
44
|
+
* Extension point for presentation packages reacting to an ended attempt. `done` is the item
|
|
45
|
+
* session's after this attempt (closed: its attempts used, whatever the score), settled here
|
|
46
|
+
* because the computed context only catches up on the next update.
|
|
39
47
|
*/
|
|
40
48
|
protected afterAttemptEnded(_assessmentItem: QtiAssessmentItem | undefined, _computedItem: ComputedItem | undefined, _done: boolean): void;
|
|
41
49
|
/** The computed-context entry for an item, from the session-control cascade. */
|
|
@@ -8,12 +8,12 @@ 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, endItemAttempt, followItemSession } from '@qti-components/delivery';
|
|
11
|
+
import { buildTestModel, endItemAttempt, followItemSession, itemRefsInOrder, readItemFacts, seedItemLifecycle } 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
|
-
import { assessOptimality, deriveComputedContext
|
|
16
|
+
import { assessOptimality, deriveComputedContext } from '../../internal/derive-computed-context';
|
|
17
17
|
import { itemFactsContext } from '../../internal/item-facts.context';
|
|
18
18
|
import { attemptsOf, itemSessionFacts } from '../../internal/item-session-facts';
|
|
19
19
|
import { renderedMarkup } from '../../internal/rendered-markup';
|
|
@@ -57,6 +57,40 @@ export class TestNavigation extends LitElement {
|
|
|
57
57
|
* A write made before it is known waits in `#pendingQtiContext` and is handed over on arrival.
|
|
58
58
|
*/
|
|
59
59
|
#testHost;
|
|
60
|
+
/** The `qti-test` this navigation answers Next for in a linear part. */
|
|
61
|
+
#linearNextHost;
|
|
62
|
+
#registerLinearNext(host) {
|
|
63
|
+
if (this.#linearNextHost && this.#linearNextHost !== host)
|
|
64
|
+
this.#linearNextHost.beforeLinearNext = null;
|
|
65
|
+
this.#linearNextHost = host;
|
|
66
|
+
host.beforeLinearNext = this.#beforeLinearNext;
|
|
67
|
+
}
|
|
68
|
+
connectedCallback() {
|
|
69
|
+
super.connectedCallback();
|
|
70
|
+
if (this.#linearNextHost)
|
|
71
|
+
this.#linearNextHost.beforeLinearNext = this.#beforeLinearNext;
|
|
72
|
+
}
|
|
73
|
+
disconnectedCallback() {
|
|
74
|
+
super.disconnectedCallback();
|
|
75
|
+
if (this.#linearNextHost?.beforeLinearNext === this.#beforeLinearNext)
|
|
76
|
+
this.#linearNextHost.beforeLinearNext = null;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Next in a linear individual part leaves the item for good (implementation guide §4.1), so it
|
|
80
|
+
* submits what the candidate gave (decided 2026-11-27): refused while the session control refuses
|
|
81
|
+
* those responses (`rules.maySubmit`), else the attempt is ended when one is open: none ended yet,
|
|
82
|
+
* or the responses changed since the last. Called by the navigation mixin while the item is still
|
|
83
|
+
* rendered; the item is closed when the navigation moves past it.
|
|
84
|
+
*/
|
|
85
|
+
#beforeLinearNext;
|
|
86
|
+
/** The item-refs whose responses changed since their last ended attempt. */
|
|
87
|
+
#changed;
|
|
88
|
+
#itemRefIdOf(element) {
|
|
89
|
+
const item = element?.closest?.('qti-assessment-item');
|
|
90
|
+
if (!item)
|
|
91
|
+
return undefined;
|
|
92
|
+
return [...(this.#testElement?.querySelectorAll('qti-assessment-item-ref') ?? [])].find(itemRef => itemRef.assessmentItem === item)?.identifier;
|
|
93
|
+
}
|
|
60
94
|
#owner() {
|
|
61
95
|
return this.#testHost.value ?? null;
|
|
62
96
|
}
|
|
@@ -76,11 +110,16 @@ export class TestNavigation extends LitElement {
|
|
|
76
110
|
* outside an ended attempt (a restored or assigned state) is seeded again.
|
|
77
111
|
*/
|
|
78
112
|
#sessions;
|
|
79
|
-
/** Set while `auto-score-items` scores a change: that run is not the candidate ending an attempt. */
|
|
80
|
-
#autoScoring;
|
|
81
113
|
constructor() {
|
|
82
114
|
super();
|
|
83
115
|
this.identifier = undefined;
|
|
116
|
+
/**
|
|
117
|
+
* Your own per-item fields, by item-ref `identifier`: each `computedContext` item carries them as
|
|
118
|
+
* given under `data`, without the identifier, and so does every view of it a plugin derives. They
|
|
119
|
+
* never replace a field the test, the item or the candidate's state gives, whatever its name; a
|
|
120
|
+
* template reads `activeItem.data.<field>`. To mark an item as scored by hand, set
|
|
121
|
+
* `external-scored` on its `SCORE` declaration in `postLoadTransformCallback`.
|
|
122
|
+
*/
|
|
84
123
|
this.initContext = [];
|
|
85
124
|
this.#warnedQtiContext = false;
|
|
86
125
|
/**
|
|
@@ -95,8 +134,35 @@ export class TestNavigation extends LitElement {
|
|
|
95
134
|
host.qtiContext = this.#pendingQtiContext;
|
|
96
135
|
this.#pendingQtiContext = undefined;
|
|
97
136
|
}
|
|
137
|
+
if (host)
|
|
138
|
+
this.#registerLinearNext(host);
|
|
98
139
|
}
|
|
99
140
|
});
|
|
141
|
+
/**
|
|
142
|
+
* Next in a linear individual part leaves the item for good (implementation guide §4.1), so it
|
|
143
|
+
* submits what the candidate gave (decided 2026-11-27): refused while the session control refuses
|
|
144
|
+
* those responses (`rules.maySubmit`), else the attempt is ended when one is open: none ended yet,
|
|
145
|
+
* or the responses changed since the last. Called by the navigation mixin while the item is still
|
|
146
|
+
* rendered; the item is closed when the navigation moves past it.
|
|
147
|
+
*/
|
|
148
|
+
this.#beforeLinearNext = (itemRefId) => {
|
|
149
|
+
const part = this.#model?.testParts.find(testPart => itemRefsInOrder(testPart.sections).some(item => item.identifier === itemRefId));
|
|
150
|
+
if (part?.navigationMode !== 'linear' || part.submissionMode !== 'individual')
|
|
151
|
+
return null;
|
|
152
|
+
const session = this.#sessions.get(itemRefId);
|
|
153
|
+
const rules = this.computedItemFor(itemRefId)?.rules;
|
|
154
|
+
if (session?.state !== 'interacting' || !rules)
|
|
155
|
+
return null;
|
|
156
|
+
if (!rules.maySubmit) {
|
|
157
|
+
return { reason: rules.maySkip ? 'validate-responses' : 'allow-skipping', itemId: itemRefId };
|
|
158
|
+
}
|
|
159
|
+
if (session.numAttempts === 0 || this.#changed.has(itemRefId)) {
|
|
160
|
+
this.#assessmentItemFor(itemRefId)?.processResponse(true, this.configContext?.reportValidityAfterScoring === true);
|
|
161
|
+
}
|
|
162
|
+
return null;
|
|
163
|
+
};
|
|
164
|
+
/** The item-refs whose responses changed since their last ended attempt. */
|
|
165
|
+
this.#changed = new Set();
|
|
100
166
|
this.configContext = {};
|
|
101
167
|
this.autoScoreItems = false;
|
|
102
168
|
/**
|
|
@@ -114,8 +180,6 @@ export class TestNavigation extends LitElement {
|
|
|
114
180
|
* outside an ended attempt (a restored or assigned state) is seeded again.
|
|
115
181
|
*/
|
|
116
182
|
this.#sessions = new Map();
|
|
117
|
-
/** Set while `auto-score-items` scores a change: that run is not the candidate ending an attempt. */
|
|
118
|
-
this.#autoScoring = false;
|
|
119
183
|
/** `computedContext.itemElement`: one function for the life of this element, carried along by every update. */
|
|
120
184
|
this.#itemElement = (identifier) => this.#assessmentItemFor(identifier) ?? null;
|
|
121
185
|
/** The items this navigation disabled because their attempts are used, so it releases only those. */
|
|
@@ -139,25 +203,47 @@ export class TestNavigation extends LitElement {
|
|
|
139
203
|
const itemContext = event.detail.itemContext;
|
|
140
204
|
if (!itemContext?.identifier)
|
|
141
205
|
return;
|
|
142
|
-
|
|
143
|
-
this.#
|
|
206
|
+
this.#optimality.set(itemContext.identifier, assessOptimality(itemContext));
|
|
207
|
+
this.#changed.delete(itemContext.identifier);
|
|
144
208
|
this.#endAttempt(itemContext);
|
|
145
209
|
const computedItem = this.computedItemFor(itemContext.identifier);
|
|
146
|
-
|
|
147
|
-
const completionStatus = itemContext.variables?.find(v => v.identifier === 'completionStatus')?.value;
|
|
148
|
-
this.afterAttemptEnded(event.composedPath()[0]?.closest('qti-assessment-item'), computedItem, isItemDone(numAttempts, optimality, computedItem?.sessionControl?.maxAttempts, computedItem?.adaptive, completionStatus));
|
|
210
|
+
this.afterAttemptEnded(event.composedPath()[0]?.closest('qti-assessment-item'), computedItem, this.#doneAfterAttempt(itemContext, computedItem));
|
|
149
211
|
}
|
|
150
|
-
/**
|
|
212
|
+
/**
|
|
213
|
+
* Moves the item's session on for its ended attempt. With `auto-score-items` every change is
|
|
214
|
+
* scored as an attempt, so the count is not the candidate's: it is taken, and the state stays.
|
|
215
|
+
*/
|
|
151
216
|
#endAttempt(itemContext) {
|
|
152
217
|
const facts = this.#sessionFacts().get(itemContext.identifier);
|
|
153
218
|
if (!facts)
|
|
154
219
|
return;
|
|
155
220
|
const ended = { ...facts, ...attemptsOf(itemContext) };
|
|
156
221
|
const previous = this.#sessions.get(itemContext.identifier);
|
|
157
|
-
this.#sessions.set(itemContext.identifier, this
|
|
158
|
-
? {
|
|
222
|
+
this.#sessions.set(itemContext.identifier, this.autoScoreItems
|
|
223
|
+
? {
|
|
224
|
+
state: previous?.state ?? followItemSession(undefined, ended).state,
|
|
225
|
+
numAttempts: ended.numAttempts,
|
|
226
|
+
adaptive: ended.adaptive
|
|
227
|
+
}
|
|
159
228
|
: endItemAttempt(previous, ended));
|
|
160
229
|
}
|
|
230
|
+
/**
|
|
231
|
+
* Whether the item session is over after the attempt that just ended: its new state, or, before
|
|
232
|
+
* the test model is known, the state an item on screen with these attempts is in.
|
|
233
|
+
*/
|
|
234
|
+
#doneAfterAttempt(itemContext, computedItem) {
|
|
235
|
+
const state = this.#sessions.get(itemContext.identifier)?.state ??
|
|
236
|
+
(computedItem?.sessionControl
|
|
237
|
+
? seedItemLifecycle({
|
|
238
|
+
sessionControl: computedItem.sessionControl,
|
|
239
|
+
adaptive: computedItem.adaptive ?? false,
|
|
240
|
+
...attemptsOf(itemContext),
|
|
241
|
+
presented: true,
|
|
242
|
+
passed: false
|
|
243
|
+
})
|
|
244
|
+
: 'interacting');
|
|
245
|
+
return state === 'closed' || state === 'review' || state === 'solution';
|
|
246
|
+
}
|
|
161
247
|
/** The facts of every item session now: the model, the item facts, the contexts and the items on screen. */
|
|
162
248
|
#sessionFacts() {
|
|
163
249
|
if (!this.#model)
|
|
@@ -165,11 +251,26 @@ export class TestNavigation extends LitElement {
|
|
|
165
251
|
const presented = new Set([...(this.#testElement?.querySelectorAll('qti-assessment-item-ref') ?? [])]
|
|
166
252
|
.filter(itemRef => itemRef.assessmentItem)
|
|
167
253
|
.map(itemRef => itemRef.identifier));
|
|
168
|
-
return itemSessionFacts(this.#model, this
|
|
254
|
+
return itemSessionFacts(this.#model, this.#itemFacts(), this._testContext?.items, {
|
|
169
255
|
current: this._sessionContext?.navItemRefId,
|
|
170
256
|
presented
|
|
171
257
|
});
|
|
172
258
|
}
|
|
259
|
+
/**
|
|
260
|
+
* The item facts `qti-test` read from each fetched item, and, for an item rendered without them
|
|
261
|
+
* (handed to its ref directly), the facts read from the rendered item.
|
|
262
|
+
*/
|
|
263
|
+
#itemFacts() {
|
|
264
|
+
const missing = [
|
|
265
|
+
...(this.#testElement?.querySelectorAll('qti-assessment-item-ref') ?? [])
|
|
266
|
+
].filter(itemRef => itemRef.assessmentItem?.localName === 'qti-assessment-item' && !this._itemFacts?.has(itemRef.identifier));
|
|
267
|
+
if (!missing.length)
|
|
268
|
+
return this._itemFacts;
|
|
269
|
+
const facts = new Map(this._itemFacts ?? []);
|
|
270
|
+
for (const itemRef of missing)
|
|
271
|
+
facts.set(itemRef.identifier, readItemFacts(renderedMarkup(itemRef.assessmentItem)));
|
|
272
|
+
return facts;
|
|
273
|
+
}
|
|
173
274
|
/** Moves every item session on for where the candidate is now. */
|
|
174
275
|
#followSessions() {
|
|
175
276
|
for (const [identifier, facts] of this.#sessionFacts()) {
|
|
@@ -177,10 +278,9 @@ export class TestNavigation extends LitElement {
|
|
|
177
278
|
}
|
|
178
279
|
}
|
|
179
280
|
/**
|
|
180
|
-
* Extension point for presentation packages reacting to an ended attempt.
|
|
181
|
-
*
|
|
182
|
-
*
|
|
183
|
-
* the next update, after this event has finished bubbling.
|
|
281
|
+
* Extension point for presentation packages reacting to an ended attempt. `done` is the item
|
|
282
|
+
* session's after this attempt (closed: its attempts used, whatever the score), settled here
|
|
283
|
+
* because the computed context only catches up on the next update.
|
|
184
284
|
*/
|
|
185
285
|
afterAttemptEnded(_assessmentItem, _computedItem, _done) { }
|
|
186
286
|
/** The computed-context entry for an item, from the session-control cascade. */
|
|
@@ -224,6 +324,9 @@ export class TestNavigation extends LitElement {
|
|
|
224
324
|
qtiAssessmentItemEl.setOutcomeVariable(event.detail.outcomeVariableId, event.detail.value);
|
|
225
325
|
}
|
|
226
326
|
#handleInteractionChanged(_event) {
|
|
327
|
+
const itemRefId = this.#itemRefIdOf(_event.composedPath()[0]);
|
|
328
|
+
if (itemRefId)
|
|
329
|
+
this.#changed.add(itemRefId);
|
|
227
330
|
if (this.autoScoreItems) {
|
|
228
331
|
const assessmentItem = _event.composedPath()[0].closest('qti-assessment-item');
|
|
229
332
|
// Autoscoring resolves the item from the event's own path, so a change
|
|
@@ -235,13 +338,7 @@ export class TestNavigation extends LitElement {
|
|
|
235
338
|
scoreOutcomeIdentifier.externalScored === null &&
|
|
236
339
|
assessmentItem.adaptive === 'false') {
|
|
237
340
|
const reportValidityAfterScoring = this.configContext?.reportValidityAfterScoring === true ? true : false;
|
|
238
|
-
|
|
239
|
-
try {
|
|
240
|
-
assessmentItem.processResponse(true, reportValidityAfterScoring);
|
|
241
|
-
}
|
|
242
|
-
finally {
|
|
243
|
-
this.#autoScoring = false;
|
|
244
|
-
}
|
|
341
|
+
assessmentItem.processResponse(true, reportValidityAfterScoring);
|
|
245
342
|
}
|
|
246
343
|
}
|
|
247
344
|
}
|
|
@@ -254,6 +351,7 @@ export class TestNavigation extends LitElement {
|
|
|
254
351
|
// A fresh test invalidates the per-test optimality latches and item sessions.
|
|
255
352
|
this.#optimality.clear();
|
|
256
353
|
this.#sessions.clear();
|
|
354
|
+
this.#changed.clear();
|
|
257
355
|
// Set the testIdentifier in qtiContext if not already set
|
|
258
356
|
if (!this.qtiContext.QTI_CONTEXT?.testIdentifier) {
|
|
259
357
|
const currentContext = this.qtiContext.QTI_CONTEXT || {
|
|
@@ -296,7 +394,7 @@ export class TestNavigation extends LitElement {
|
|
|
296
394
|
this.#followSessions();
|
|
297
395
|
return deriveComputedContext({
|
|
298
396
|
model: this.#model,
|
|
299
|
-
itemFacts: this
|
|
397
|
+
itemFacts: this.#itemFacts(),
|
|
300
398
|
testContext: this._testContext,
|
|
301
399
|
sessionContext: this._sessionContext,
|
|
302
400
|
infoItemCategory: this.configContext?.infoItemCategory,
|
|
@@ -375,10 +473,11 @@ export class TestNavigation extends LitElement {
|
|
|
375
473
|
/** The items this navigation disabled because their attempts are used, so it releases only those. */
|
|
376
474
|
#lockedItems;
|
|
377
475
|
/**
|
|
378
|
-
* Disables every rendered item whose
|
|
379
|
-
* candidate cannot change the answer once the last attempt is
|
|
380
|
-
* an item rendered later (another item, a
|
|
381
|
-
* arrives, and one whose attempts are back to
|
|
476
|
+
* Disables every rendered item whose session is over (`rules.done`: closed, its attempts used or
|
|
477
|
+
* a completed adaptive item), so the candidate cannot change the answer once the last attempt is
|
|
478
|
+
* ended (QTI info model §2.2.1). Runs after every update: an item rendered later (another item, a
|
|
479
|
+
* section on screen, a restored state) is locked as it arrives, and one whose attempts are back to
|
|
480
|
+
* zero (a new state) is released.
|
|
382
481
|
*
|
|
383
482
|
* Only `disabled = true` is ever set here, and only on an item that was not disabled already; a
|
|
384
483
|
* host or view that disables or makes an item read-only itself keeps it so.
|
|
@@ -395,7 +494,9 @@ export class TestNavigation extends LitElement {
|
|
|
395
494
|
const element = itemRef.assessmentItem;
|
|
396
495
|
if (!element)
|
|
397
496
|
continue;
|
|
398
|
-
|
|
497
|
+
// The session is over (closed, or in review or solution). With `auto-score-items` every change
|
|
498
|
+
// is scored as an attempt, so the count is not the candidate's and locks nothing.
|
|
499
|
+
const used = !this.autoScoreItems && items.get(itemRef.identifier)?.rules?.done === true;
|
|
399
500
|
if (used && !element.disabled) {
|
|
400
501
|
element.disabled = true;
|
|
401
502
|
this.#lockedItems.add(element);
|
|
@@ -406,20 +507,6 @@ export class TestNavigation extends LitElement {
|
|
|
406
507
|
}
|
|
407
508
|
}
|
|
408
509
|
}
|
|
409
|
-
/**
|
|
410
|
-
* The same rule as `test-end-attempt`'s max-attempts guard: a non-adaptive item with a
|
|
411
|
-
* `max-attempts` above 0 whose attempts reached it. Adaptive items end themselves, and 0 is
|
|
412
|
-
* unlimited. With `auto-score-items` every change is scored as an attempt, so the count is not
|
|
413
|
-
* the candidate's and locks nothing.
|
|
414
|
-
*/
|
|
415
|
-
#attemptsUsed(item, element) {
|
|
416
|
-
if (!item || this.autoScoreItems)
|
|
417
|
-
return false;
|
|
418
|
-
if (item.adaptive || element.adaptive === 'true')
|
|
419
|
-
return false;
|
|
420
|
-
const maxAttempts = item.sessionControl?.maxAttempts ?? 1;
|
|
421
|
-
return maxAttempts > 0 && (item.numAttempts ?? 0) >= maxAttempts;
|
|
422
|
-
}
|
|
423
510
|
}
|
|
424
511
|
__decorate([
|
|
425
512
|
property({ type: String })
|