@qti-components/test 2.0.0-next.26 → 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 +5 -4
- package/dist/components/test-navigation/test-navigation.js +126 -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 +0 -20
- package/dist/internal/derive-computed-context.js +5 -36
- 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"]}
|
|
@@ -30,6 +30,8 @@ export declare class TestNavigation extends LitElement {
|
|
|
30
30
|
*/
|
|
31
31
|
get qtiContext(): QtiContext;
|
|
32
32
|
set qtiContext(value: QtiContext);
|
|
33
|
+
connectedCallback(): void;
|
|
34
|
+
disconnectedCallback(): void;
|
|
33
35
|
configContext: ConfigContext;
|
|
34
36
|
protected _testContext?: TestContext;
|
|
35
37
|
protected _sessionContext?: SessionContext;
|
|
@@ -39,10 +41,9 @@ export declare class TestNavigation extends LitElement {
|
|
|
39
41
|
autoScoreItems: boolean;
|
|
40
42
|
constructor();
|
|
41
43
|
/**
|
|
42
|
-
* Extension point for presentation packages reacting to an ended attempt.
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
* 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.
|
|
46
47
|
*/
|
|
47
48
|
protected afterAttemptEnded(_assessmentItem: QtiAssessmentItem | undefined, _computedItem: ComputedItem | undefined, _done: boolean): void;
|
|
48
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,8 +110,6 @@ 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;
|
|
@@ -102,8 +134,35 @@ export class TestNavigation extends LitElement {
|
|
|
102
134
|
host.qtiContext = this.#pendingQtiContext;
|
|
103
135
|
this.#pendingQtiContext = undefined;
|
|
104
136
|
}
|
|
137
|
+
if (host)
|
|
138
|
+
this.#registerLinearNext(host);
|
|
105
139
|
}
|
|
106
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();
|
|
107
166
|
this.configContext = {};
|
|
108
167
|
this.autoScoreItems = false;
|
|
109
168
|
/**
|
|
@@ -121,8 +180,6 @@ export class TestNavigation extends LitElement {
|
|
|
121
180
|
* outside an ended attempt (a restored or assigned state) is seeded again.
|
|
122
181
|
*/
|
|
123
182
|
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;
|
|
126
183
|
/** `computedContext.itemElement`: one function for the life of this element, carried along by every update. */
|
|
127
184
|
this.#itemElement = (identifier) => this.#assessmentItemFor(identifier) ?? null;
|
|
128
185
|
/** The items this navigation disabled because their attempts are used, so it releases only those. */
|
|
@@ -146,25 +203,47 @@ export class TestNavigation extends LitElement {
|
|
|
146
203
|
const itemContext = event.detail.itemContext;
|
|
147
204
|
if (!itemContext?.identifier)
|
|
148
205
|
return;
|
|
149
|
-
|
|
150
|
-
this.#
|
|
206
|
+
this.#optimality.set(itemContext.identifier, assessOptimality(itemContext));
|
|
207
|
+
this.#changed.delete(itemContext.identifier);
|
|
151
208
|
this.#endAttempt(itemContext);
|
|
152
209
|
const computedItem = this.computedItemFor(itemContext.identifier);
|
|
153
|
-
|
|
154
|
-
const completionStatus = itemContext.variables?.find(v => v.identifier === 'completionStatus')?.value;
|
|
155
|
-
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));
|
|
156
211
|
}
|
|
157
|
-
/**
|
|
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
|
+
*/
|
|
158
216
|
#endAttempt(itemContext) {
|
|
159
217
|
const facts = this.#sessionFacts().get(itemContext.identifier);
|
|
160
218
|
if (!facts)
|
|
161
219
|
return;
|
|
162
220
|
const ended = { ...facts, ...attemptsOf(itemContext) };
|
|
163
221
|
const previous = this.#sessions.get(itemContext.identifier);
|
|
164
|
-
this.#sessions.set(itemContext.identifier, this
|
|
165
|
-
? {
|
|
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
|
+
}
|
|
166
228
|
: endItemAttempt(previous, ended));
|
|
167
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
|
+
}
|
|
168
247
|
/** The facts of every item session now: the model, the item facts, the contexts and the items on screen. */
|
|
169
248
|
#sessionFacts() {
|
|
170
249
|
if (!this.#model)
|
|
@@ -172,11 +251,26 @@ export class TestNavigation extends LitElement {
|
|
|
172
251
|
const presented = new Set([...(this.#testElement?.querySelectorAll('qti-assessment-item-ref') ?? [])]
|
|
173
252
|
.filter(itemRef => itemRef.assessmentItem)
|
|
174
253
|
.map(itemRef => itemRef.identifier));
|
|
175
|
-
return itemSessionFacts(this.#model, this
|
|
254
|
+
return itemSessionFacts(this.#model, this.#itemFacts(), this._testContext?.items, {
|
|
176
255
|
current: this._sessionContext?.navItemRefId,
|
|
177
256
|
presented
|
|
178
257
|
});
|
|
179
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
|
+
}
|
|
180
274
|
/** Moves every item session on for where the candidate is now. */
|
|
181
275
|
#followSessions() {
|
|
182
276
|
for (const [identifier, facts] of this.#sessionFacts()) {
|
|
@@ -184,10 +278,9 @@ export class TestNavigation extends LitElement {
|
|
|
184
278
|
}
|
|
185
279
|
}
|
|
186
280
|
/**
|
|
187
|
-
* Extension point for presentation packages reacting to an ended attempt.
|
|
188
|
-
*
|
|
189
|
-
*
|
|
190
|
-
* 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.
|
|
191
284
|
*/
|
|
192
285
|
afterAttemptEnded(_assessmentItem, _computedItem, _done) { }
|
|
193
286
|
/** The computed-context entry for an item, from the session-control cascade. */
|
|
@@ -231,6 +324,9 @@ export class TestNavigation extends LitElement {
|
|
|
231
324
|
qtiAssessmentItemEl.setOutcomeVariable(event.detail.outcomeVariableId, event.detail.value);
|
|
232
325
|
}
|
|
233
326
|
#handleInteractionChanged(_event) {
|
|
327
|
+
const itemRefId = this.#itemRefIdOf(_event.composedPath()[0]);
|
|
328
|
+
if (itemRefId)
|
|
329
|
+
this.#changed.add(itemRefId);
|
|
234
330
|
if (this.autoScoreItems) {
|
|
235
331
|
const assessmentItem = _event.composedPath()[0].closest('qti-assessment-item');
|
|
236
332
|
// Autoscoring resolves the item from the event's own path, so a change
|
|
@@ -242,13 +338,7 @@ export class TestNavigation extends LitElement {
|
|
|
242
338
|
scoreOutcomeIdentifier.externalScored === null &&
|
|
243
339
|
assessmentItem.adaptive === 'false') {
|
|
244
340
|
const reportValidityAfterScoring = this.configContext?.reportValidityAfterScoring === true ? true : false;
|
|
245
|
-
|
|
246
|
-
try {
|
|
247
|
-
assessmentItem.processResponse(true, reportValidityAfterScoring);
|
|
248
|
-
}
|
|
249
|
-
finally {
|
|
250
|
-
this.#autoScoring = false;
|
|
251
|
-
}
|
|
341
|
+
assessmentItem.processResponse(true, reportValidityAfterScoring);
|
|
252
342
|
}
|
|
253
343
|
}
|
|
254
344
|
}
|
|
@@ -261,6 +351,7 @@ export class TestNavigation extends LitElement {
|
|
|
261
351
|
// A fresh test invalidates the per-test optimality latches and item sessions.
|
|
262
352
|
this.#optimality.clear();
|
|
263
353
|
this.#sessions.clear();
|
|
354
|
+
this.#changed.clear();
|
|
264
355
|
// Set the testIdentifier in qtiContext if not already set
|
|
265
356
|
if (!this.qtiContext.QTI_CONTEXT?.testIdentifier) {
|
|
266
357
|
const currentContext = this.qtiContext.QTI_CONTEXT || {
|
|
@@ -303,7 +394,7 @@ export class TestNavigation extends LitElement {
|
|
|
303
394
|
this.#followSessions();
|
|
304
395
|
return deriveComputedContext({
|
|
305
396
|
model: this.#model,
|
|
306
|
-
itemFacts: this
|
|
397
|
+
itemFacts: this.#itemFacts(),
|
|
307
398
|
testContext: this._testContext,
|
|
308
399
|
sessionContext: this._sessionContext,
|
|
309
400
|
infoItemCategory: this.configContext?.infoItemCategory,
|
|
@@ -382,10 +473,11 @@ export class TestNavigation extends LitElement {
|
|
|
382
473
|
/** The items this navigation disabled because their attempts are used, so it releases only those. */
|
|
383
474
|
#lockedItems;
|
|
384
475
|
/**
|
|
385
|
-
* Disables every rendered item whose
|
|
386
|
-
* candidate cannot change the answer once the last attempt is
|
|
387
|
-
* an item rendered later (another item, a
|
|
388
|
-
* 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.
|
|
389
481
|
*
|
|
390
482
|
* Only `disabled = true` is ever set here, and only on an item that was not disabled already; a
|
|
391
483
|
* host or view that disables or makes an item read-only itself keeps it so.
|
|
@@ -402,7 +494,9 @@ export class TestNavigation extends LitElement {
|
|
|
402
494
|
const element = itemRef.assessmentItem;
|
|
403
495
|
if (!element)
|
|
404
496
|
continue;
|
|
405
|
-
|
|
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;
|
|
406
500
|
if (used && !element.disabled) {
|
|
407
501
|
element.disabled = true;
|
|
408
502
|
this.#lockedItems.add(element);
|
|
@@ -413,20 +507,6 @@ export class TestNavigation extends LitElement {
|
|
|
413
507
|
}
|
|
414
508
|
}
|
|
415
509
|
}
|
|
416
|
-
/**
|
|
417
|
-
* The same rule as `test-end-attempt`'s max-attempts guard: a non-adaptive item with a
|
|
418
|
-
* `max-attempts` above 0 whose attempts reached it. Adaptive items end themselves, and 0 is
|
|
419
|
-
* unlimited. With `auto-score-items` every change is scored as an attempt, so the count is not
|
|
420
|
-
* the candidate's and locks nothing.
|
|
421
|
-
*/
|
|
422
|
-
#attemptsUsed(item, element) {
|
|
423
|
-
if (!item || this.autoScoreItems)
|
|
424
|
-
return false;
|
|
425
|
-
if (item.adaptive || element.adaptive === 'true')
|
|
426
|
-
return false;
|
|
427
|
-
const maxAttempts = item.sessionControl?.maxAttempts ?? 1;
|
|
428
|
-
return maxAttempts > 0 && (item.numAttempts ?? 0) >= maxAttempts;
|
|
429
|
-
}
|
|
430
510
|
}
|
|
431
511
|
__decorate([
|
|
432
512
|
property({ type: String })
|