@qti-components/test 2.0.0-next.27 → 2.0.0-next.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/qti-assessment-item-ref/qti-assessment-item-ref.js +3 -8
- package/dist/components/qti-assessment-item-ref/qti-assessment-item-ref.js.map +1 -1
- package/dist/components/test-end-attempt/test-end-attempt.js +6 -4
- package/dist/components/test-end-attempt/test-end-attempt.js.map +1 -1
- package/dist/components/test-navigation/test-navigation.js +23 -7
- package/dist/components/test-navigation/test-navigation.js.map +1 -1
- package/dist/components/test-next/test-next.js +4 -4
- package/dist/components/test-next/test-next.js.map +1 -1
- package/dist/components/test-prev/test-prev.js +4 -4
- package/dist/components/test-prev/test-prev.js.map +1 -1
- package/dist/computed-tree.d.ts +20 -0
- package/dist/computed-tree.js +22 -0
- package/dist/computed-tree.js.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/internal/delivery-state-conversion.d.ts +15 -5
- package/dist/internal/delivery-state-conversion.js +36 -9
- package/dist/internal/delivery-state-conversion.js.map +1 -1
- package/dist/internal/derive-computed-context.d.ts +12 -4
- package/dist/internal/derive-computed-context.js +30 -21
- package/dist/internal/derive-computed-context.js.map +1 -1
- package/dist/internal/test-host.context.d.ts +2 -0
- package/dist/internal/test-host.context.js.map +1 -1
- package/dist/mixins/test-base.d.ts +2 -0
- package/dist/mixins/test-base.js +16 -0
- package/dist/mixins/test-base.js.map +1 -1
- package/dist/mixins/test-state.mixin.js +3 -1
- package/dist/mixins/test-state.mixin.js.map +1 -1
- package/dist/plugin-api.d.ts +1 -1
- package/dist/plugin-api.js +1 -1
- package/dist/plugin-api.js.map +1 -1
- package/dist/public-events.d.ts +9 -0
- package/dist/public-events.js +1 -0
- package/dist/public-events.js.map +1 -1
- package/dist/state-from-contexts.d.ts +1 -0
- package/dist/state-from-contexts.js +2 -1
- package/dist/state-from-contexts.js.map +1 -1
- package/dist/types/qti-test-state.d.ts +5 -0
- package/dist/types/qti-test-state.js.map +1 -1
- package/package.json +3 -3
- package/dist/items-in-order.d.ts +0 -9
- package/dist/items-in-order.js +0 -15
- package/dist/items-in-order.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"computed-tree.js","sourceRoot":"","sources":["../src/computed-tree.ts"],"names":[],"mappings":"AAUA,MAAM,KAAK,GAAG,CAAC,OAA2B,EAAkB,EAAE,CAC5D,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,KAAK,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;AAEjF,MAAM,QAAQ,GAAG,CAAC,OAA2B,EAAqB,EAAE,CAClE,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,GAAG,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAE9F;;;GAGG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,QAA0B,EAAkB,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;AAErG,iGAAiG;AACjG,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,QAA0B,EAAqB,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;AAE9G,mGAAmG;AACnG,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,OAAoC,EAAgC,EAAE,CACnG,OAAO,EAAE,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;AAEvD;;;GAGG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,OAAoC,EAA+B,EAAE,CACjG,OAAO,EAAE,SAAS,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;AAE9E;;;GAGG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,OAAoC,EAA4B,EAAE,CAC3F,OAAO,EAAE,SAAS,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC","sourcesContent":["import type { ComputedContext, ComputedItem, ComputedSection, ComputedTestPart } from '@qti-components/base';\n\n/**\n * Small functions over the tree in `computedContext`, for readers that want a flat list: a\n * navigation bar, a plugin that acts on the active item. The tree is the test as the author wrote\n * it; these read it, they hold nothing of their own.\n */\n\ntype Content = ComputedSection['content'][number];\n\nconst items = (content: readonly Content[]): ComputedItem[] =>\n content.flatMap(node => (node.kind === 'item' ? [node] : items(node.content)));\n\nconst sections = (content: readonly Content[]): ComputedSection[] =>\n content.flatMap(node => (node.kind === 'section' ? [node, ...sections(node.content)] : []));\n\n/**\n * Every item of a test part once, in the order the candidate takes them: the test's document order,\n * through nested sections, interleaved item-refs and subsections included, info items included.\n */\nexport const itemsInOrder = (testPart: ComputedTestPart): ComputedItem[] => items(testPart.sections);\n\n/** Every section of a test part once, nested ones included, a section before its subsections. */\nexport const sectionsInOrder = (testPart: ComputedTestPart): ComputedSection[] => sections(testPart.sections);\n\n/** The test part the candidate is in, or undefined (no context yet, or before the test starts). */\nexport const activeTestPart = (context: ComputedContext | undefined): ComputedTestPart | undefined =>\n context?.testParts.find(testPart => testPart.active);\n\n/**\n * The section the candidate is in: the closest one around the active item, or the section shown.\n * Looked for in every test part, as `active` is set from where the candidate is.\n */\nexport const activeSection = (context: ComputedContext | undefined): ComputedSection | undefined =>\n context?.testParts.flatMap(sectionsInOrder).find(section => section.active);\n\n/**\n * The item the candidate is on, or undefined (`navigate=\"section\"` shows a section, not one item).\n * Looked for in every test part, as `active` is set from where the candidate is.\n */\nexport const activeItem = (context: ComputedContext | undefined): ComputedItem | undefined =>\n context?.testParts.flatMap(itemsInOrder).find(item => item.active);\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import './register.js';
|
|
|
2
2
|
export * from './components/index.js';
|
|
3
3
|
export * from './plugins/index.js';
|
|
4
4
|
export * from './plugin-state.js';
|
|
5
|
-
export * from './
|
|
5
|
+
export * from './computed-tree.js';
|
|
6
6
|
export * from './state-from-contexts.js';
|
|
7
7
|
export * from './types/iqti-test.js';
|
|
8
8
|
export * from './types/qti-test-state.js';
|
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import './register.js';
|
|
|
2
2
|
export * from './components/index.js';
|
|
3
3
|
export * from './plugins/index.js';
|
|
4
4
|
export * from './plugin-state.js';
|
|
5
|
-
export * from './
|
|
5
|
+
export * from './computed-tree.js';
|
|
6
6
|
export * from './state-from-contexts.js';
|
|
7
7
|
export * from './types/iqti-test.js';
|
|
8
8
|
export * from './types/qti-test-state.js';
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,eAAe,CAAC;AAEvB,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,eAAe,CAAC;AAEvB,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,0BAA0B,CAAC;AACzC,cAAc,sBAAsB,CAAC;AACrC,cAAc,2BAA2B,CAAC","sourcesContent":["import './register.js';\n\nexport * from './components/index.js';\nexport * from './plugins/index.js';\nexport * from './plugin-state.js';\nexport * from './computed-tree.js';\nexport * from './state-from-contexts.js';\nexport * from './types/iqti-test.js';\nexport * from './types/qti-test-state.js';\n"]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { Clock, DeliveryState } from '@qti-components/delivery';
|
|
1
|
+
import type { Clock, DeliveryState, TestModel } from '@qti-components/delivery';
|
|
2
|
+
import type { ItemFactsByRef } from './item-facts.context';
|
|
2
3
|
import type { QtiTestState } from '../types/qti-test-state';
|
|
3
4
|
/**
|
|
4
5
|
* Converts between `QtiTestState`, the host's persistence format, and `DeliveryState`, the one source
|
|
@@ -10,7 +11,9 @@ import type { QtiTestState } from '../types/qti-test-state';
|
|
|
10
11
|
* - the variables are not in `DeliveryState` until T8, so the way back takes them as an input;
|
|
11
12
|
* - `DeliveryState.current` is an item instance, so a position of only a section (`navigate="section"`)
|
|
12
13
|
* or a part (`navSectionId`, `navPartId`) is not kept (decided 2026-11-27);
|
|
13
|
-
* - a version 1 `QtiTestState` has no seed, order or start time, so the caller passes them in
|
|
14
|
+
* - a version 1 `QtiTestState` has no seed, order or start time, so the caller passes them in;
|
|
15
|
+
* - it has no lifecycle state either: each item's is derived from its attempts and position
|
|
16
|
+
* (`seedItemLifecycle`, roadmap 1 T3d), and the way back drops it.
|
|
14
17
|
*
|
|
15
18
|
* @internal
|
|
16
19
|
*/
|
|
@@ -25,11 +28,18 @@ export interface DeliveryStateInputs {
|
|
|
25
28
|
seed: string | null;
|
|
26
29
|
/** When the delivery starts; a version 1 state does not say when the test started. */
|
|
27
30
|
clock: Clock;
|
|
31
|
+
/** The test's structure and resolved session control, for each item's lifecycle state. */
|
|
32
|
+
model: TestModel;
|
|
33
|
+
/** The item facts read so far; an item without them counts as not adaptive. */
|
|
34
|
+
itemFacts?: ItemFactsByRef;
|
|
28
35
|
}
|
|
29
36
|
/**
|
|
30
|
-
* A `DeliveryState` from a stored `QtiTestState`: the order, the item on screen
|
|
31
|
-
*
|
|
32
|
-
*
|
|
37
|
+
* A `DeliveryState` from a stored `QtiTestState`: the order, the item on screen, the plugin entries
|
|
38
|
+
* and each item's session: its ended attempts and `completionStatus` from its variables, its
|
|
39
|
+
* lifecycle state derived from them, its session control and its position (closed when no attempt
|
|
40
|
+
* is left or a linear part has passed it; interacting on screen; else initial or suspended). An item
|
|
41
|
+
* on screen that the order does not have, and a position of only a section or a part, give
|
|
42
|
+
* `current: null`.
|
|
33
43
|
*
|
|
34
44
|
* @internal
|
|
35
45
|
*/
|
|
@@ -1,20 +1,47 @@
|
|
|
1
|
-
import { createDeliveryState, itemInstanceId } from '@qti-components/delivery';
|
|
1
|
+
import { COMPLETION_STATUSES, DEFAULT_SESSION_CONTROL, createDeliveryState, itemInstanceId, itemRefsInOrder, parseItemInstanceId, seedItemLifecycle } from '@qti-components/delivery';
|
|
2
2
|
import { QTI_TEST_STATE_VERSION } from '../types/qti-test-state';
|
|
3
3
|
/**
|
|
4
|
-
* A `DeliveryState` from a stored `QtiTestState`: the order, the item on screen
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* A `DeliveryState` from a stored `QtiTestState`: the order, the item on screen, the plugin entries
|
|
5
|
+
* and each item's session: its ended attempts and `completionStatus` from its variables, its
|
|
6
|
+
* lifecycle state derived from them, its session control and its position (closed when no attempt
|
|
7
|
+
* is left or a linear part has passed it; interacting on screen; else initial or suspended). An item
|
|
8
|
+
* on screen that the order does not have, and a position of only a section or a part, give
|
|
9
|
+
* `current: null`.
|
|
7
10
|
*
|
|
8
11
|
* @internal
|
|
9
12
|
*/
|
|
10
13
|
export function deliveryStateFromQtiTestState(state, inputs) {
|
|
11
14
|
const delivery = createDeliveryState(inputs);
|
|
12
15
|
const onScreen = state.session.navItemRefId ? itemInstanceId(state.session.navItemRefId) : null;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
const current = onScreen && Object.hasOwn(delivery.items, onScreen) ? onScreen : null;
|
|
17
|
+
const parts = new Map(inputs.model.testParts.flatMap(part => itemRefsInOrder(part.sections).map(item => [item.identifier, { part, item }])));
|
|
18
|
+
const partOf = (id) => parts.get(parseItemInstanceId(id).itemRefIdentifier);
|
|
19
|
+
const currentIndex = current ? delivery.order.indexOf(current) : -1;
|
|
20
|
+
const items = Object.fromEntries(delivery.order.map((id, index) => {
|
|
21
|
+
const variables = state.test.items.find(item => item.identifier === id)?.variables ?? [];
|
|
22
|
+
const value = (name) => variables.find(variable => variable.identifier === name)?.value;
|
|
23
|
+
const numAttempts = Math.max(0, Math.trunc(Number(value('numAttempts')) || 0));
|
|
24
|
+
const status = value('completionStatus');
|
|
25
|
+
const completionStatus = COMPLETION_STATUSES.includes(status)
|
|
26
|
+
? status
|
|
27
|
+
: numAttempts > 0
|
|
28
|
+
? 'unknown'
|
|
29
|
+
: 'not_attempted';
|
|
30
|
+
const ref = partOf(id);
|
|
31
|
+
const linear = ref?.part.navigationMode === 'linear';
|
|
32
|
+
const sameLinearPart = linear && current !== null && partOf(current)?.part === ref?.part;
|
|
33
|
+
const lifecycle = seedItemLifecycle({
|
|
34
|
+
sessionControl: ref?.item.sessionControl ?? DEFAULT_SESSION_CONTROL,
|
|
35
|
+
adaptive: inputs.itemFacts?.get(parseItemInstanceId(id).itemRefIdentifier)?.adaptive ?? false,
|
|
36
|
+
numAttempts,
|
|
37
|
+
completionStatus,
|
|
38
|
+
presented: id === current,
|
|
39
|
+
passed: sameLinearPart && index < currentIndex
|
|
40
|
+
});
|
|
41
|
+
const item = { ...delivery.items[id], lifecycle, numAttempts, completionStatus };
|
|
42
|
+
return [id, item];
|
|
43
|
+
}));
|
|
44
|
+
return { ...delivery, current, items, plugins: { ...(state.session.plugins ?? {}) } };
|
|
18
45
|
}
|
|
19
46
|
/**
|
|
20
47
|
* A `QtiTestState` from a `DeliveryState`: the item on screen and the plugin entries, with the
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"delivery-state-conversion.js","sourceRoot":"","sources":["../../src/internal/delivery-state-conversion.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"delivery-state-conversion.js","sourceRoot":"","sources":["../../src/internal/delivery-state-conversion.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,uBAAuB,EACvB,mBAAmB,EACnB,cAAc,EACd,eAAe,EACf,mBAAmB,EACnB,iBAAiB,EAClB,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AAwCjE;;;;;;;;;GASG;AACH,MAAM,UAAU,6BAA6B,CAAC,KAAmB,EAAE,MAA2B;IAC5F,MAAM,QAAQ,GAAG,mBAAmB,CAAC,MAAM,CAAC,CAAC;IAC7C,MAAM,QAAQ,GAAG,KAAK,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,cAAc,CAAC,KAAK,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IAChG,MAAM,OAAO,GAAG,QAAQ,IAAI,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC;IACtF,MAAM,KAAK,GAAG,IAAI,GAAG,CACnB,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CACpC,eAAe,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,UAAU,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAC9E,CACF,CAAC;IACF,MAAM,MAAM,GAAG,CAAC,EAAU,EAAE,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,mBAAmB,CAAC,EAAE,CAAC,CAAC,iBAAiB,CAAC,CAAC;IACpF,MAAM,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G,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,GAAG,IAAI,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;aACpD,CAAC,CAAC;YACH,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC;SACrG;QACD,OAAO,EAAE;YACP,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,EAAE,GAAG,QAAQ,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YACzF,kGAAkG;YAClG,GAAG,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAChE;KACF,CAAC;AACJ,CAAC","sourcesContent":["import {\n COMPLETION_STATUSES,\n DEFAULT_SESSION_CONTROL,\n createDeliveryState,\n itemInstanceId,\n itemRefsInOrder,\n parseItemInstanceId,\n seedItemLifecycle\n} from '@qti-components/delivery';\n\nimport { QTI_TEST_STATE_VERSION } from '../types/qti-test-state';\n\nimport type { Clock, CompletionStatus, DeliveryState, ItemDeliveryState, TestModel } from '@qti-components/delivery';\nimport type { ItemFactsByRef } from './item-facts.context';\nimport type { QtiTestState } from '../types/qti-test-state';\n\n/**\n * Converts between `QtiTestState`, the host's persistence format, and `DeliveryState`, the one source\n * of truth to come (`plans/delivery-state.md`). Roadmap 1 T1e: pure functions, called by nothing at\n * runtime yet; `qti-test` keeps its state in `testContext` and `sessionContext` until T2 and T3 derive\n * from a `DeliveryState`.\n *\n * Lossy on purpose, until the fields exist on both sides:\n * - the variables are not in `DeliveryState` until T8, so the way back takes them as an input;\n * - `DeliveryState.current` is an item instance, so a position of only a section (`navigate=\"section\"`)\n * or a part (`navSectionId`, `navPartId`) is not kept (decided 2026-11-27);\n * - a version 1 `QtiTestState` has no seed, order or start time, so the caller passes them in;\n * - it has no lifecycle state either: each item's is derived from its attempts and position\n * (`seedItemLifecycle`, roadmap 1 T3d), and the way back drops it.\n *\n * @internal\n */\n\nexport interface DeliveryStateInputs {\n /**\n * The item-ref identifiers in the order the candidate meets them: the rendered test's, which is\n * already selected and shuffled with the seed the host passed; a `with-replacement` clone is its\n * instance id (`item-1#2`).\n */\n order: readonly string[];\n /** The seed actually used for that order. */\n seed: string | null;\n /** When the delivery starts; a version 1 state does not say when the test started. */\n clock: Clock;\n /** The test's structure and resolved session control, for each item's lifecycle state. */\n model: TestModel;\n /** The item facts read so far; an item without them counts as not adaptive. */\n itemFacts?: ItemFactsByRef;\n}\n\n/**\n * A `DeliveryState` from a stored `QtiTestState`: the order, the item on screen, the plugin entries\n * and each item's session: its ended attempts and `completionStatus` from its variables, its\n * lifecycle state derived from them, its session control and its position (closed when no attempt\n * is left or a linear part has passed it; interacting on screen; else initial or suspended). An item\n * on screen that the order does not have, and a position of only a section or a part, give\n * `current: null`.\n *\n * @internal\n */\nexport function deliveryStateFromQtiTestState(state: QtiTestState, inputs: DeliveryStateInputs): DeliveryState {\n const delivery = createDeliveryState(inputs);\n const onScreen = state.session.navItemRefId ? itemInstanceId(state.session.navItemRefId) : null;\n const current = onScreen && Object.hasOwn(delivery.items, onScreen) ? onScreen : null;\n const parts = new Map(\n inputs.model.testParts.flatMap(part =>\n itemRefsInOrder(part.sections).map(item => [item.identifier, { part, item }])\n )\n );\n const partOf = (id: string) => parts.get(parseItemInstanceId(id).itemRefIdentifier);\n const currentIndex = current ? delivery.order.indexOf(current) : -1;\n const items = Object.fromEntries(\n delivery.order.map((id, index) => {\n const variables = state.test.items.find(item => item.identifier === id)?.variables ?? [];\n const value = (name: string) => variables.find(variable => variable.identifier === name)?.value;\n const numAttempts = Math.max(0, Math.trunc(Number(value('numAttempts')) || 0));\n const status = value('completionStatus');\n const completionStatus = (COMPLETION_STATUSES as readonly unknown[]).includes(status)\n ? (status as CompletionStatus)\n : numAttempts > 0\n ? 'unknown'\n : 'not_attempted';\n const ref = partOf(id);\n const linear = ref?.part.navigationMode === 'linear';\n const sameLinearPart = linear && current !== null && partOf(current)?.part === ref?.part;\n const lifecycle = seedItemLifecycle({\n sessionControl: ref?.item.sessionControl ?? DEFAULT_SESSION_CONTROL,\n adaptive: inputs.itemFacts?.get(parseItemInstanceId(id).itemRefIdentifier)?.adaptive ?? false,\n numAttempts,\n completionStatus,\n presented: id === current,\n passed: sameLinearPart && index < currentIndex\n });\n const item: ItemDeliveryState = { ...delivery.items[id], lifecycle, numAttempts, completionStatus };\n return [id, item];\n })\n );\n return { ...delivery, current, items, plugins: { ...(state.session.plugins ?? {}) } };\n}\n\n/**\n * A `QtiTestState` from a `DeliveryState`: the item on screen and the plugin entries, with the\n * variables from `test` (the live contexts' values, as `qtiTest.state` reads them). The `test` input\n * goes when the variables move into `DeliveryState` (T8).\n *\n * @internal\n */\nexport function qtiTestStateFromDeliveryState(delivery: DeliveryState, test: QtiTestState['test']): QtiTestState {\n return {\n version: QTI_TEST_STATE_VERSION,\n test: {\n items: test.items.map(item => ({\n ...item,\n variables: item.variables.map(v => ({ ...v, value: Array.isArray(v.value) ? [...v.value] : v.value })),\n ...(item.state ? { state: { ...item.state } } : {})\n })),\n outcomes: test.outcomes.map(o => ({ ...o, value: Array.isArray(o.value) ? [...o.value] : o.value }))\n },\n session: {\n ...(Object.keys(delivery.plugins).length > 0 ? { plugins: { ...delivery.plugins } } : {}),\n // The instance id, as the rendered test names the item-ref: a clone is `item-1#2` (roadmap 1 T4).\n ...(delivery.current ? { navItemRefId: delivery.current } : {})\n }\n };\n}\n"]}
|
|
@@ -12,7 +12,7 @@ export type ItemOptimality = 'optimal' | 'suboptimal' | 'unscored';
|
|
|
12
12
|
export interface ComputedContextInputs {
|
|
13
13
|
/** The test's structure and resolved session control, from its XML (`buildTestModel`). */
|
|
14
14
|
readonly model: TestModel;
|
|
15
|
-
/** The facts of every item fetched so far, by item-ref identifier. */
|
|
15
|
+
/** The facts of every item fetched so far, by item instance (the rendered item-ref identifier). */
|
|
16
16
|
readonly itemFacts?: ItemFactsByRef;
|
|
17
17
|
/** The candidate's responses and outcomes, per item. */
|
|
18
18
|
readonly testContext?: Readonly<TestContext>;
|
|
@@ -20,19 +20,22 @@ 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
|
-
/**
|
|
23
|
+
/**
|
|
24
|
+
* The host's per-item fields (`initContext`), matched on the item instance: each item gets them
|
|
25
|
+
* under `data`, never at its top level.
|
|
26
|
+
*/
|
|
24
27
|
readonly itemData?: readonly {
|
|
25
28
|
identifier: string;
|
|
26
29
|
[key: string]: unknown;
|
|
27
30
|
}[];
|
|
28
31
|
/**
|
|
29
|
-
* The optimality of each item's last ended attempt, by item
|
|
32
|
+
* The optimality of each item's last ended attempt, by item instance (see `ItemOptimality`).
|
|
30
33
|
* Kept by `test-navigation`, since it is not in the contexts: it is written when an attempt ends,
|
|
31
34
|
* never on a plain change of the answer.
|
|
32
35
|
*/
|
|
33
36
|
readonly optimality: ReadonlyMap<string, ItemOptimality>;
|
|
34
37
|
/**
|
|
35
|
-
* The lifecycle state of each item session, by item
|
|
38
|
+
* The lifecycle state of each item session, by item instance, kept by `test-navigation`
|
|
36
39
|
* (`followItemSession`, `endItemAttempt`). An item it does not list is seeded from its attempts.
|
|
37
40
|
*/
|
|
38
41
|
readonly lifecycle?: ReadonlyMap<string, ItemLifecycleState>;
|
|
@@ -43,6 +46,11 @@ export interface ComputedContextInputs {
|
|
|
43
46
|
* `computedContext`, derived from its inputs alone: built anew on every call, never from the previous
|
|
44
47
|
* context, and never changing an input. The same inputs give an equal context.
|
|
45
48
|
*
|
|
49
|
+
* The tree of the test (roadmap 1, T2d): test parts, sections nested as the test nests them, each
|
|
50
|
+
* section's item-refs and subsections in document order. In the model a `with-replacement` clone is
|
|
51
|
+
* an item-ref of its own whose identifier is its instance (`item-3#2`); here it keeps that as
|
|
52
|
+
* `instance`, under the identifier of the item-ref it copies.
|
|
53
|
+
*
|
|
46
54
|
* Roadmap 1, T2c. `DeliveryState` is not live at runtime yet, so the candidate's state comes from
|
|
47
55
|
* `testContext` and `sessionContext`; T3 and T8 move it into `DeliveryState`, and add their fields here.
|
|
48
56
|
*/
|
|
@@ -1,14 +1,31 @@
|
|
|
1
|
-
import { itemRefsInOrder, itemRules,
|
|
1
|
+
import { itemRefsInOrder, itemRules, parseItemInstanceId, 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.
|
|
5
5
|
*
|
|
6
|
+
* The tree of the test (roadmap 1, T2d): test parts, sections nested as the test nests them, each
|
|
7
|
+
* section's item-refs and subsections in document order. In the model a `with-replacement` clone is
|
|
8
|
+
* an item-ref of its own whose identifier is its instance (`item-3#2`); here it keeps that as
|
|
9
|
+
* `instance`, under the identifier of the item-ref it copies.
|
|
10
|
+
*
|
|
6
11
|
* Roadmap 1, T2c. `DeliveryState` is not live at runtime yet, so the candidate's state comes from
|
|
7
12
|
* `testContext` and `sessionContext`; T3 and T8 move it into `DeliveryState`, and add their fields here.
|
|
8
13
|
*/
|
|
9
14
|
export function deriveComputedContext(inputs) {
|
|
10
15
|
const { model, sessionContext, itemElement } = inputs;
|
|
11
16
|
const itemIndexes = indexesInDocumentOrder(model.testParts.flatMap(part => itemRefsInOrder(part.sections)), inputs.infoItemCategory);
|
|
17
|
+
const deriveSection = (testPart, section) => ({
|
|
18
|
+
kind: 'section',
|
|
19
|
+
identifier: section.identifier,
|
|
20
|
+
title: section.title,
|
|
21
|
+
visible: section.visible,
|
|
22
|
+
active: sessionContext?.navSectionId === section.identifier,
|
|
23
|
+
// A section that only holds subsections is completed when theirs are.
|
|
24
|
+
completed: itemRefsInOrder(section.content).every(item => variableValue(itemContextFor(inputs, item.identifier), 'completionStatus') === 'completed'),
|
|
25
|
+
content: section.content.map(child => child.kind === 'section'
|
|
26
|
+
? deriveSection(testPart, child)
|
|
27
|
+
: deriveItem(inputs, testPart, child, itemIndexes.get(child.identifier) ?? null))
|
|
28
|
+
});
|
|
12
29
|
return {
|
|
13
30
|
itemElement,
|
|
14
31
|
identifier: model.identifier,
|
|
@@ -20,36 +37,28 @@ export function deriveComputedContext(inputs) {
|
|
|
20
37
|
identifier: testPart.identifier,
|
|
21
38
|
navigationMode: testPart.navigationMode,
|
|
22
39
|
submissionMode: testPart.submissionMode,
|
|
23
|
-
|
|
24
|
-
itemOrder: itemRefsInOrder(testPart.sections).map(item => item.identifier),
|
|
25
|
-
// Flat, depth first: every section once, each with only its own item-refs, so every item is
|
|
26
|
-
// listed once. Where a section's item-refs and subsections interleave, this list is not in
|
|
27
|
-
// document order; `index` is.
|
|
28
|
-
sections: sectionsInOrder(testPart.sections).map(section => ({
|
|
29
|
-
active: sessionContext?.navSectionId === section.identifier,
|
|
30
|
-
identifier: section.identifier,
|
|
31
|
-
title: section.title,
|
|
32
|
-
allowSkipping: section.sessionControl.allowSkipping,
|
|
33
|
-
// A section that only holds subsections is completed when theirs are.
|
|
34
|
-
completed: itemRefsInOrder(section.content).every(item => variableValue(itemContextFor(inputs, item.identifier), 'completionStatus') === 'completed'),
|
|
35
|
-
items: ownItemRefs(section).map(item => deriveItem(inputs, testPart, item, itemIndexes.get(item.identifier) ?? null))
|
|
36
|
-
}))
|
|
40
|
+
sections: testPart.sections.map(section => deriveSection(testPart, section))
|
|
37
41
|
}))
|
|
38
42
|
};
|
|
39
43
|
}
|
|
40
44
|
function deriveItem(inputs, testPart, item, index) {
|
|
41
|
-
|
|
45
|
+
// The model names an item-ref by its instance: a clone's identifier there is `item-3#2`.
|
|
46
|
+
const instance = item.identifier;
|
|
47
|
+
const itemContext = itemContextFor(inputs, instance);
|
|
42
48
|
// Only the fields an item context holds: a host that restores `testContext` with fields of its
|
|
43
49
|
// own sets nothing here. Its fields for an item belong in `itemData`, which lands under `data`.
|
|
44
50
|
const computedItem = {
|
|
51
|
+
kind: 'item',
|
|
52
|
+
instance,
|
|
45
53
|
active: false,
|
|
46
|
-
|
|
54
|
+
...factsFor(inputs.itemFacts, instance),
|
|
55
|
+
identifier: parseItemInstanceId(instance).itemRefIdentifier,
|
|
47
56
|
categories: [...item.categories],
|
|
48
57
|
href: item.href,
|
|
49
58
|
sessionControl: { ...item.sessionControl },
|
|
50
|
-
...factsFor(inputs.itemFacts, item.identifier),
|
|
51
59
|
variables: itemContext?.variables ?? [],
|
|
52
60
|
...(itemContext?.state === undefined ? {} : { state: itemContext.state }),
|
|
61
|
+
...(itemContext?.comment === undefined ? {} : { comment: itemContext.comment }),
|
|
53
62
|
...(itemContext?.readonly === undefined ? {} : { readonly: itemContext.readonly }),
|
|
54
63
|
...(itemContext?.disabled === undefined ? {} : { disabled: itemContext.disabled })
|
|
55
64
|
};
|
|
@@ -60,7 +69,7 @@ function deriveItem(inputs, testPart, item, index) {
|
|
|
60
69
|
const completionStatus = variableValue(computedItem, 'completionStatus');
|
|
61
70
|
const response = variableValue(computedItem, 'RESPONSE') || '';
|
|
62
71
|
const numAttempts = Number(variableValue(computedItem, 'numAttempts')) || 0;
|
|
63
|
-
const latched = inputs.optimality.get(
|
|
72
|
+
const latched = inputs.optimality.get(instance);
|
|
64
73
|
const session = lifecycleOf(inputs, testPart, item, itemContext, { numAttempts, completionStatus });
|
|
65
74
|
return {
|
|
66
75
|
...computedItem,
|
|
@@ -69,7 +78,7 @@ function deriveItem(inputs, testPart, item, index) {
|
|
|
69
78
|
score,
|
|
70
79
|
response,
|
|
71
80
|
index,
|
|
72
|
-
active: inputs.sessionContext?.navItemRefId ===
|
|
81
|
+
active: inputs.sessionContext?.navItemRefId === instance,
|
|
73
82
|
// Published by the item. One that is not on screen has nothing to be invalid.
|
|
74
83
|
valid: itemContext?.valid ?? true,
|
|
75
84
|
isDefaultResponse: isDefaultResponse(itemContext),
|
|
@@ -79,7 +88,7 @@ function deriveItem(inputs, testPart, item, index) {
|
|
|
79
88
|
...session,
|
|
80
89
|
// The session's: closed, or in review or solution. Never the score (roadmap 1, T3b2b).
|
|
81
90
|
done: session.rules.done,
|
|
82
|
-
data: hostData(inputs.itemData,
|
|
91
|
+
data: hostData(inputs.itemData, instance)
|
|
83
92
|
};
|
|
84
93
|
}
|
|
85
94
|
/** The item session's lifecycle state and what it may do now (`itemRules`), computed: host data never sets it. */
|
|
@@ -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,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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AAC;QACvB,IAAI,MAAM,KAAK,SAAS,IAAI,MAAM,KAAK,IAAI;YAAE,OAAO,KAAK,CAAC;QAC1D,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;YACrD,OAAO,QAAQ,CAAC,MAAM,KAAK,MAAM,CAAC,MAAM,IAAI,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;QACtF,CAAC;QACD,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC;YAAE,OAAO,KAAK,CAAC;QACnE,OAAO,QAAQ,KAAK,MAAM,CAAC;IAC7B,CAAC,CAAC,CAAC;IACH,OAAO,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,YAAY,CAAC;AAC7C,CAAC;AAED,8EAA8E;AAC9E,SAAS,eAAe,CAAC,SAAmC,EAAE,UAAkB;IAC9E,MAAM,GAAG,GAAG,SAAS,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,UAAU,KAAK,UAAU,CAAC,EAAE,KAAK,CAAC;IACrE,IAAI,GAAG,KAAK,SAAS,IAAI,GAAG,KAAK,IAAI,IAAI,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, 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 const latched = inputs.optimality.get(item.identifier);\n const session = lifecycleOf(inputs, testPart, item, itemContext, { numAttempts, completionStatus });\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 // Information only, from the last *ended* attempt (the latch); it decides nothing.\n optimal: latched === 'optimal',\n ...session,\n // The session's: closed, or in review or solution. Never the score (roadmap 1, T3b2b).\n done: session.rules.done,\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'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,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AA2D9G;;;;;;;;;;;GAWG;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,MAAM,aAAa,GAAG,CAAC,QAAuB,EAAE,OAAqB,EAAmB,EAAE,CAAC,CAAC;QAC1F,IAAI,EAAE,SAAS;QACf,UAAU,EAAE,OAAO,CAAC,UAAU;QAC9B,KAAK,EAAE,OAAO,CAAC,KAAK;QACpB,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,MAAM,EAAE,cAAc,EAAE,YAAY,KAAK,OAAO,CAA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import type {\n ComputedContext,\n ComputedItem,\n ComputedSection,\n ItemContext,\n ResponseVariable\n} from '@qti-components/base';\nimport type { SessionContext, TestContext } from '@qti-components/base';\nimport type {\n ItemFacts,\n ItemLifecycleState,\n ItemRefModel,\n SectionModel,\n TestModel,\n TestPartModel\n} 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 instance (the rendered 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 /**\n * The host's per-item fields (`initContext`), matched on the item instance: each item gets them\n * under `data`, never at its top level.\n */\n readonly itemData?: readonly { identifier: string; [key: string]: unknown }[];\n /**\n * The optimality of each item's last ended attempt, by item instance (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 instance, 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 * The tree of the test (roadmap 1, T2d): test parts, sections nested as the test nests them, each\n * section's item-refs and subsections in document order. In the model a `with-replacement` clone is\n * an item-ref of its own whose identifier is its instance (`item-3#2`); here it keeps that as\n * `instance`, under the identifier of the item-ref it copies.\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 const deriveSection = (testPart: TestPartModel, section: SectionModel): ComputedSection => ({\n kind: 'section',\n identifier: section.identifier,\n title: section.title,\n visible: section.visible,\n active: sessionContext?.navSectionId === section.identifier,\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 content: section.content.map(child =>\n child.kind === 'section'\n ? deriveSection(testPart, child)\n : deriveItem(inputs, testPart, child, itemIndexes.get(child.identifier) ?? null)\n )\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 sections: testPart.sections.map(section => deriveSection(testPart, section))\n }))\n };\n}\n\nfunction deriveItem(\n inputs: ComputedContextInputs,\n testPart: TestPartModel,\n item: ItemRefModel,\n index: number | null\n): ComputedItem {\n // The model names an item-ref by its instance: a clone's identifier there is `item-3#2`.\n const instance = item.identifier;\n const itemContext = itemContextFor(inputs, instance);\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 kind: 'item' as const,\n instance,\n active: false,\n ...factsFor(inputs.itemFacts, instance),\n identifier: parseItemInstanceId(instance).itemRefIdentifier,\n categories: [...item.categories],\n href: item.href,\n sessionControl: { ...item.sessionControl },\n variables: itemContext?.variables ?? [],\n ...(itemContext?.state === undefined ? {} : { state: itemContext.state }),\n ...(itemContext?.comment === undefined ? {} : { comment: itemContext.comment }),\n ...(itemContext?.readonly === undefined ? {} : { readonly: itemContext.readonly }),\n ...(itemContext?.disabled === undefined ? {} : { disabled: itemContext.disabled })\n } as Omit<ComputedItem, 'index' | 'data'>;\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 const latched = inputs.optimality.get(instance);\n const session = lifecycleOf(inputs, testPart, item, itemContext, { numAttempts, completionStatus });\n\n return {\n ...computedItem,\n completionStatus,\n numAttempts,\n score,\n response,\n index,\n active: inputs.sessionContext?.navItemRefId === instance,\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 // Information only, from the last *ended* attempt (the latch); it decides nothing.\n optimal: latched === 'optimal',\n ...session,\n // The session's: closed, or in review or solution. Never the score (roadmap 1, T3b2b).\n done: session.rules.done,\n data: hostData(inputs.itemData, instance)\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'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"]}
|
|
@@ -25,6 +25,8 @@ export interface TestHost extends HTMLElement {
|
|
|
25
25
|
* be left yet.
|
|
26
26
|
*/
|
|
27
27
|
beforeLinearNext?: ((itemRefId: string) => LinearNextRefusal | null) | null;
|
|
28
|
+
/** Sets the candidate's comment on an item-ref; null clears it. `test-navigation` checks `rules.mayComment` first. */
|
|
29
|
+
updateItemComment(itemRefId: string, comment: string | null): void;
|
|
28
30
|
}
|
|
29
31
|
/** Why Next may not leave an item yet: its responses are ones its session control refuses. */
|
|
30
32
|
export interface LinearNextRefusal {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"test-host.context.js","sourceRoot":"","sources":["../../src/internal/test-host.context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"test-host.context.js","sourceRoot":"","sources":["../../src/internal/test-host.context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AA4C7C,MAAM,CAAC,MAAM,eAAe,GAAG,aAAa,CAAW,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC","sourcesContent":["import { createContext } from '@lit/context';\n\nimport type { QtiContext } from '@qti-components/base';\nimport type { transformTestApi } from '@qti-components/transformers';\nimport type { QtiAssessmentTest } from '../components/qti-assessment-test/qti-assessment-test';\n\n/**\n * Defined here, and re-exported by the navigation mixin under the same name, so this file imports\n * nothing from the mixin: the mixin imports the components that consume this context, and a type\n * import counts as a dependency for madge.\n */\nexport type PostLoadTestTransformCallback = (\n transformer: transformTestApi,\n testElement: QtiAssessmentTest\n) => transformTestApi | Promise<transformTestApi>;\n\n/**\n * What the components inside a test need from the `qti-test` that contains them: the things a host\n * put on it, and the element to query. Provided by `qti-test` about itself.\n *\n * It is context and not `closest('qti-test')` because a request crosses shadow roots and `closest`\n * stops at the first one, so a navigation or container a host renders inside its own component\n * would never find its test. Internal on purpose: not exported from the package, and not API.\n */\nexport interface TestHost extends HTMLElement {\n qtiContext: QtiContext;\n postLoadTestTransformCallback: PostLoadTestTransformCallback | null;\n /**\n * Set by `test-navigation`, which keeps the item sessions: asked by the navigation mixin before a\n * Next in a linear part leaves `itemRefId`, while that item is still rendered. It ends the item's\n * attempt when one is open (roadmap 1, T3b2b) and answers null, or answers why the item may not\n * be left yet.\n */\n beforeLinearNext?: ((itemRefId: string) => LinearNextRefusal | null) | null;\n /** Sets the candidate's comment on an item-ref; null clears it. `test-navigation` checks `rules.mayComment` first. */\n updateItemComment(itemRefId: string, comment: string | null): void;\n}\n\n/** Why Next may not leave an item yet: its responses are ones its session control refuses. */\nexport interface LinearNextRefusal {\n reason: 'allow-skipping' | 'validate-responses';\n itemId: string;\n}\n\nexport const testHostContext = createContext<TestHost>(Symbol('testHost'));\n"]}
|
|
@@ -14,6 +14,8 @@ export interface TestBaseInterface extends LitElement {
|
|
|
14
14
|
qtiContext?: Readonly<QtiContext>;
|
|
15
15
|
_testElement: QtiAssessmentTest;
|
|
16
16
|
updateItemVariables(itemRefID: string, variables: readonly ItemVariableValue[], state?: ItemContext['state']): void;
|
|
17
|
+
/** @internal */
|
|
18
|
+
updateItemComment(itemRefID: string, comment: string | null): void;
|
|
17
19
|
}
|
|
18
20
|
/** A value to set on an item; `type` is only needed for a variable the item does not declare. */
|
|
19
21
|
export type ItemVariableValue = Pick<VariableValue<string | string[] | null>, 'identifier' | 'value'> & Partial<Pick<VariableValue<string | string[] | null>, 'type'>>;
|
package/dist/mixins/test-base.js
CHANGED
|
@@ -110,6 +110,22 @@ export const TestBaseMixin = (superClass) => {
|
|
|
110
110
|
if (state)
|
|
111
111
|
assessmentItem.state = state;
|
|
112
112
|
}
|
|
113
|
+
/**
|
|
114
|
+
* Sets the candidate's comment on an item-ref (null clears it), as `qc-test-update-comment` asks
|
|
115
|
+
* once `test-navigation` has checked the item allows it. Internal; hosts send the request.
|
|
116
|
+
* @internal
|
|
117
|
+
*/
|
|
118
|
+
updateItemComment(itemRefID, comment) {
|
|
119
|
+
this.testContext = {
|
|
120
|
+
...this.testContext,
|
|
121
|
+
items: this.testContext.items.map(item => {
|
|
122
|
+
if (item.identifier !== itemRefID)
|
|
123
|
+
return item;
|
|
124
|
+
const { comment: _previous, ...rest } = item;
|
|
125
|
+
return comment === null ? rest : { ...rest, comment };
|
|
126
|
+
})
|
|
127
|
+
};
|
|
128
|
+
}
|
|
113
129
|
_initializeEventListeners() {
|
|
114
130
|
/**
|
|
115
131
|
* A new test document means a new test and session context.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"test-base.js","sourceRoot":"","sources":["../../src/mixins/test-base.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,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E,IAAI,OAAO,EAAE,KAAK,KAAK,eAAe;gBAAE,OAAO;YAC/C,IAAI,CAAC,WAAW,GAAG;gBACjB,GAAG,IAAI,CAAC,WAAW;gBACnB,KAAK,EAAE,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CACpC,CAAC,CAAC,UAAU,KAAK,UAAU;oBACzB,CAAC,CAAC,CAAC;oBACH,CAAC,CAAC;wBACE,GAAG,CAAC;wBACJ,SAAS,EAAE,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,UAAU,KAAK,kBAAkB,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;qBACrG,CACN;aACF,CAAC;QACJ,CAAC;KACF;IA5NQ;QAFN,QAAQ,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;QAC5C,OAAO,CAAC,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC;sDAC+B;IAI1D;QAFN,QAAQ,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;QAC5C,OAAO,CAAC,EAAE,OAAO,EAAE,cAAc,EAAE,CAAC;yDACqC;IA0N5E,OAAO,aAAmD,CAAC;AAC7D,CAAC,CAAC;AAEF,2EAA2E;AAC3E,MAAM,OAAgB,QAAS,SAAQ,aAAa,CAAC,UAAU,CAAC;CAAG","sourcesContent":["import { provide } from '@lit/context';\nimport { LitElement } from 'lit';\nimport { property } from 'lit/decorators.js';\n\nimport { INITIAL_TEST_CONTEXT, testContext } from '@qti-components/base';\nimport { INITIAL_SESSION_CONTEXT, type SessionContext, sessionContext } from '@qti-components/base';\n\nimport { listenPublic } from '../public-events';\n\nimport type { QtiAssessmentItem } from '@qti-components/elements';\nimport type { QtiAssessmentItemRef } from '../components/qti-assessment-item-ref/qti-assessment-item-ref';\nimport type { QtiAssessmentTest } from '../components/qti-assessment-test/qti-assessment-test';\nimport type { ConfigContext, QtiContext } from '@qti-components/base';\nimport type { ItemContext } from '@qti-components/base';\nimport type { TestContext } from '@qti-components/base';\nimport type { OutcomeVariable, VariableDeclaration, VariableValue } from '@qti-components/base';\n\ntype Constructor<T = {}> = abstract new (...args: any[]) => T;\n\nexport interface TestBaseInterface extends LitElement {\n testContext: Readonly<TestContext>;\n sessionContext: Readonly<SessionContext>;\n configContext?: Readonly<ConfigContext>;\n /** Provided by `qti-test`. */\n qtiContext?: Readonly<QtiContext>;\n _testElement: QtiAssessmentTest;\n updateItemVariables(itemRefID: string, variables: readonly ItemVariableValue[], state?: ItemContext['state']): void;\n}\n\n/** A value to set on an item; `type` is only needed for a variable the item does not declare. */\nexport type ItemVariableValue = Pick<VariableValue<string | string[] | null>, 'identifier' | 'value'> &\n Partial<Pick<VariableValue<string | string[] | null>, 'type'>>;\n\nexport const TestBaseMixin = <T extends Constructor<LitElement>>(superClass: T) => {\n abstract class TestBaseClass extends superClass implements TestBaseInterface {\n @property({ attribute: false, type: Object })\n @provide({ context: testContext })\n public testContext: Readonly<TestContext> = INITIAL_TEST_CONTEXT;\n\n @property({ attribute: false, type: Object })\n @provide({ context: sessionContext })\n public sessionContext: Readonly<SessionContext> = INITIAL_SESSION_CONTEXT;\n\n public _testElement: QtiAssessmentTest;\n\n constructor(...args: any[]) {\n super(...args);\n this._initializeEventListeners();\n }\n\n /**\n * Sets values on one item from outside the candidate's session, e.g. a score from manual\n * scoring. Values are merged into the item's entry in the test context, and into the item\n * itself if it is on screen; a value the item has not seen yet is added, so this also works\n * before the item has loaded. To restore a whole session, assign `state` instead.\n *\n * The test context is replaced rather than changed in place, so its consumers update and\n * `qc-test-state-changed` fires.\n *\n * @param itemRefID The `qti-assessment-item-ref` identifier, not the item's own identifier; a\n * `with-replacement` clone's instance id (`item-3#2`).\n * @param state Opaque per-interaction state keyed by response identifier, e.g. a PCI's `getState()`.\n */\n updateItemVariables(itemRefID: string, values: readonly ItemVariableValue[], state?: ItemContext['state']): void {\n this.testContext = {\n ...this.testContext,\n items: this.testContext.items.map(item => {\n if (item.identifier !== itemRefID) return item;\n\n const variables = [...(item.variables ?? [])];\n for (const { identifier, type, value } of values) {\n const index = variables.findIndex(v => v.identifier === identifier);\n const updated = {\n ...(index >= 0 ? variables[index] : {}),\n identifier,\n ...(type ? { type } : {}),\n value: Array.isArray(value) ? [...value] : value\n } as VariableDeclaration<string | string[] | null>;\n if (index >= 0) variables[index] = updated;\n else variables.push(updated);\n }\n return { ...item, variables, ...(state ? { state: { ...state } } : {}) };\n })\n };\n\n const assessmentItem = this._testElement?.querySelector<QtiAssessmentItemRef>(\n `qti-assessment-item-ref[identifier=\"${CSS.escape(itemRefID)}\"]`\n )?.assessmentItem;\n if (!assessmentItem) return;\n assessmentItem.variables = [...(this.testContext.items.find(i => i.identifier === itemRefID)?.variables ?? [])];\n if (state) assessmentItem.state = state;\n }\n\n private _initializeEventListeners(): void {\n /**\n * A new test document means a new test and session context.\n *\n * This resets on the document being loaded rather than on\n * `qc-test-loaded`, because the new document's children —\n * test-level `qti-outcome-declaration` among them — connect and register\n * themselves into the context *before* the test element announces itself.\n * Resetting on that announcement discarded every one of those\n * registrations, so no test-level outcome could be read or set.\n */\n this.addEventListener('qti-testdoc-loaded', () => {\n this.testContext = INITIAL_TEST_CONTEXT;\n this.sessionContext = INITIAL_SESSION_CONTEXT;\n });\n\n /**\n * When the test is connected, its item-refs are added to the test context.\n * Registrations from the document's children are already present on the\n * context reset above, so this must preserve what is there.\n */\n listenPublic(this, 'qc-test-loaded', (e: CustomEvent<QtiAssessmentTest>) => {\n this._testElement = e.detail;\n const items = Array.from(this._testElement.querySelectorAll('qti-assessment-item-ref')).map(itemRef => {\n return {\n href: itemRef.href,\n identifier: itemRef.identifier,\n category: itemRef.category,\n variables: [\n {\n identifier: 'completionStatus',\n value: 'not_attempted',\n type: 'outcome'\n } as OutcomeVariable\n ]\n };\n });\n this.testContext = { ...this.testContext, items };\n });\n\n this.addEventListener('qti-assessment-item-connected', (e: CustomEvent<QtiAssessmentItem>) => {\n const assessmentItem = e.detail as QtiAssessmentItem;\n const assessmentRefId = assessmentItem.closest('qti-assessment-item-ref')?.identifier;\n if (assessmentRefId) {\n assessmentItem.assessmentItemRefId = assessmentRefId;\n }\n this._updateItemInTestContext(e.detail);\n });\n\n this.addEventListener('qti-item-context-updated', (e: CustomEvent<{ itemContext: ItemContext }>) => {\n // const assessmentitem = e.composedPath()[0] as QtiAssessmentItem;\n this._updateItemVariablesInTestContext(\n e.detail.itemContext.identifier,\n e.detail.itemContext.variables,\n e.detail.itemContext.state,\n e.detail.itemContext.valid\n );\n });\n }\n\n private _updateItemVariablesInTestContext(\n identifier: string,\n variables: readonly VariableDeclaration<string | string[] | null>[],\n state?: ItemContext['state'],\n valid?: boolean\n ): void {\n // Update the test context with modified variables for the specified item\n this.testContext = {\n ...this.testContext, // Spread existing test context properties\n items: this.testContext.items.map(itemContext => {\n // If the item identifier doesn't match, keep it unchanged\n if (itemContext.identifier !== identifier) {\n return itemContext;\n }\n\n // Update the matching item with new variables\n return {\n ...itemContext, // Keep other properties of the item context\n variables: variables.map(variable => {\n // Find a matching variable in the current item context\n const matchingVariable = itemContext.variables.find(v => v.identifier === variable.identifier);\n\n // Merge matching variable with the new one, or use the new variable if no match\n return matchingVariable ? { ...matchingVariable, ...variable } : variable;\n }),\n ...(state !== undefined ? { state: state ? { ...state } : undefined } : {}),\n ...(valid !== undefined ? { valid } : {})\n };\n })\n };\n // Deprecated for hosts, see `@event` on `qti-test`; kept until the next major.\n this.dispatchEvent(\n new CustomEvent('qti-test-context-updated', { detail: this.testContext, bubbles: false, composed: false })\n );\n }\n\n /**\n * Updates the variables of an assessment item in the test context.\n * - Matches the assessment item with the corresponding test context item.\n * - If the item is not found, logs a warning.\n * - Updates variables in the test context if exactly one variable exists.\n * - Otherwise, syncs the assessment item's variables with the test context.\n *\n * @param assessmentItem - The assessment item to update.\n */\n private _updateItemInTestContext = (assessmentItem: QtiAssessmentItem): void => {\n const context = assessmentItem.itemContext;\n const identifier = context.identifier;\n const fullVariables = context.variables;\n\n // Find the corresponding item in the test context by identifier\n const itemContext = this.testContext.items.find(i => i?.identifier === identifier);\n\n if (!itemContext) {\n console.warn(`Item IDs between assessment.xml and item.xml should match: ${identifier} is not found!`);\n return;\n }\n\n // Update variables in the test context or sync them to the assessment item\n if (itemContext.variables?.length === 1) {\n // The loaded qti-assessment-item itself has variables which are not in test context yet.\n this._updateItemVariablesInTestContext(identifier, fullVariables, undefined, context.valid);\n } else {\n const newVariables = [...assessmentItem.variables];\n // Sync the assessment item's variables with the test context\n for (const variable of itemContext.variables) {\n // Presenting an item starts its first attempt, so it is no longer `not_attempted` once it\n // is on screen: the item keeps its own status (`unknown`) — `qti-number-presented` reads it.\n if (variable.identifier === 'completionStatus' && variable.value === 'not_attempted') continue;\n const currentVariable = newVariables.find(v => v.identifier === variable.identifier);\n if (currentVariable) {\n currentVariable.value = variable.value;\n } else {\n newVariables.push(variable);\n }\n }\n assessmentItem.variables = newVariables;\n this.#leaveNotAttempted(identifier, newVariables.find(v => v.identifier === 'completionStatus')?.value);\n // Opaque interaction state (a PCI's getState()) is read from the item context when the\n // interaction initializes, so it has to be in place now, before that happens.\n if (itemContext.state) {\n assessmentItem.state = itemContext.state;\n }\n }\n };\n\n /** Write the presented item's own status over a `not_attempted` the test context still holds for it. */\n #leaveNotAttempted(identifier: string, status: Readonly<string | string[] | null> | undefined): void {\n if (typeof status !== 'string' || status === 'not_attempted') return;\n const item = this.testContext.items.find(i => i.identifier === identifier);\n const current = item?.variables.find(v => v.identifier === 'completionStatus');\n if (current?.value !== 'not_attempted') return;\n this.testContext = {\n ...this.testContext,\n items: this.testContext.items.map(i =>\n i.identifier !== identifier\n ? i\n : {\n ...i,\n variables: i.variables.map(v => (v.identifier === 'completionStatus' ? { ...v, value: status } : v))\n }\n )\n };\n }\n }\n\n return TestBaseClass as Constructor<TestBaseInterface> & T;\n};\n\n// Keep the old abstract class for backwards compatibility during migration\nexport abstract class TestBase extends TestBaseMixin(LitElement) {}\n"]}
|
|
1
|
+
{"version":3,"file":"test-base.js","sourceRoot":"","sources":["../../src/mixins/test-base.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AACjC,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C,OAAO,EAAE,oBAAoB,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACzE,OAAO,EAAE,uBAAuB,EAAuB,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEpG,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AA4BhD,MAAM,CAAC,MAAM,aAAa,GAAG,CAAoC,UAAa,EAAE,EAAE;IAChF,MAAe,aAAc,SAAQ,UAAU;QAW7C,YAAY,GAAG,IAAW;YACxB,KAAK,CAAC,GAAG,IAAI,CAAC,CAAC;YATV,gBAAW,GAA0B,oBAAoB,CAAC;YAI1D,mBAAc,GAA6B,uBAAuB,CAAC;YAoK1E;;;;;;;;eAQG;YACK,6BAAwB,GAAG,CAAC,cAAiC,EAAQ,EAAE;gBAC7E,MAAM,OAAO,GAAG,cAAc,CAAC,WAAW,CAAC;gBAC3C,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;gBACtC,MAAM,aAAa,GAAG,OAAO,CAAC,SAAS,CAAC;gBAExC,gEAAgE;gBAChE,MAAM,WAAW,GAAG,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,UAAU,KAAK,UAAU,CAAC,CAAC;gBAEnF,IAAI,CAAC,WAAW,EAAE,CAAC;oBACjB,OAAO,CAAC,IAAI,CAAC,8DAA8D,UAA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AAM,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;qBACrG,CACN;aACF,CAAC;QACJ,CAAC;KACF;IA5OQ;QAFN,QAAQ,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;QAC5C,OAAO,CAAC,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC;sDAC+B;IAI1D;QAFN,QAAQ,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;QAC5C,OAAO,CAAC,EAAE,OAAO,EAAE,cAAc,EAAE,CAAC;yDACqC;IA0O5E,OAAO,aAAmD,CAAC;AAC7D,CAAC,CAAC;AAEF,2EAA2E;AAC3E,MAAM,OAAgB,QAAS,SAAQ,aAAa,CAAC,UAAU,CAAC;CAAG","sourcesContent":["import { provide } from '@lit/context';\nimport { LitElement } from 'lit';\nimport { property } from 'lit/decorators.js';\n\nimport { INITIAL_TEST_CONTEXT, testContext } from '@qti-components/base';\nimport { INITIAL_SESSION_CONTEXT, type SessionContext, sessionContext } from '@qti-components/base';\n\nimport { listenPublic } from '../public-events';\n\nimport type { QtiAssessmentItem } from '@qti-components/elements';\nimport type { QtiAssessmentItemRef } from '../components/qti-assessment-item-ref/qti-assessment-item-ref';\nimport type { QtiAssessmentTest } from '../components/qti-assessment-test/qti-assessment-test';\nimport type { ConfigContext, QtiContext } from '@qti-components/base';\nimport type { ItemContext } from '@qti-components/base';\nimport type { TestContext } from '@qti-components/base';\nimport type { OutcomeVariable, VariableDeclaration, VariableValue } from '@qti-components/base';\n\ntype Constructor<T = {}> = abstract new (...args: any[]) => T;\n\nexport interface TestBaseInterface extends LitElement {\n testContext: Readonly<TestContext>;\n sessionContext: Readonly<SessionContext>;\n configContext?: Readonly<ConfigContext>;\n /** Provided by `qti-test`. */\n qtiContext?: Readonly<QtiContext>;\n _testElement: QtiAssessmentTest;\n updateItemVariables(itemRefID: string, variables: readonly ItemVariableValue[], state?: ItemContext['state']): void;\n /** @internal */\n updateItemComment(itemRefID: string, comment: string | null): void;\n}\n\n/** A value to set on an item; `type` is only needed for a variable the item does not declare. */\nexport type ItemVariableValue = Pick<VariableValue<string | string[] | null>, 'identifier' | 'value'> &\n Partial<Pick<VariableValue<string | string[] | null>, 'type'>>;\n\nexport const TestBaseMixin = <T extends Constructor<LitElement>>(superClass: T) => {\n abstract class TestBaseClass extends superClass implements TestBaseInterface {\n @property({ attribute: false, type: Object })\n @provide({ context: testContext })\n public testContext: Readonly<TestContext> = INITIAL_TEST_CONTEXT;\n\n @property({ attribute: false, type: Object })\n @provide({ context: sessionContext })\n public sessionContext: Readonly<SessionContext> = INITIAL_SESSION_CONTEXT;\n\n public _testElement: QtiAssessmentTest;\n\n constructor(...args: any[]) {\n super(...args);\n this._initializeEventListeners();\n }\n\n /**\n * Sets values on one item from outside the candidate's session, e.g. a score from manual\n * scoring. Values are merged into the item's entry in the test context, and into the item\n * itself if it is on screen; a value the item has not seen yet is added, so this also works\n * before the item has loaded. To restore a whole session, assign `state` instead.\n *\n * The test context is replaced rather than changed in place, so its consumers update and\n * `qc-test-state-changed` fires.\n *\n * @param itemRefID The `qti-assessment-item-ref` identifier, not the item's own identifier; a\n * `with-replacement` clone's instance id (`item-3#2`).\n * @param state Opaque per-interaction state keyed by response identifier, e.g. a PCI's `getState()`.\n */\n updateItemVariables(itemRefID: string, values: readonly ItemVariableValue[], state?: ItemContext['state']): void {\n this.testContext = {\n ...this.testContext,\n items: this.testContext.items.map(item => {\n if (item.identifier !== itemRefID) return item;\n\n const variables = [...(item.variables ?? [])];\n for (const { identifier, type, value } of values) {\n const index = variables.findIndex(v => v.identifier === identifier);\n const updated = {\n ...(index >= 0 ? variables[index] : {}),\n identifier,\n ...(type ? { type } : {}),\n value: Array.isArray(value) ? [...value] : value\n } as VariableDeclaration<string | string[] | null>;\n if (index >= 0) variables[index] = updated;\n else variables.push(updated);\n }\n return { ...item, variables, ...(state ? { state: { ...state } } : {}) };\n })\n };\n\n const assessmentItem = this._testElement?.querySelector<QtiAssessmentItemRef>(\n `qti-assessment-item-ref[identifier=\"${CSS.escape(itemRefID)}\"]`\n )?.assessmentItem;\n if (!assessmentItem) return;\n assessmentItem.variables = [...(this.testContext.items.find(i => i.identifier === itemRefID)?.variables ?? [])];\n if (state) assessmentItem.state = state;\n }\n\n /**\n * Sets the candidate's comment on an item-ref (null clears it), as `qc-test-update-comment` asks\n * once `test-navigation` has checked the item allows it. Internal; hosts send the request.\n * @internal\n */\n updateItemComment(itemRefID: string, comment: string | null): void {\n this.testContext = {\n ...this.testContext,\n items: this.testContext.items.map(item => {\n if (item.identifier !== itemRefID) return item;\n const { comment: _previous, ...rest } = item;\n return comment === null ? rest : { ...rest, comment };\n })\n };\n }\n\n private _initializeEventListeners(): void {\n /**\n * A new test document means a new test and session context.\n *\n * This resets on the document being loaded rather than on\n * `qc-test-loaded`, because the new document's children —\n * test-level `qti-outcome-declaration` among them — connect and register\n * themselves into the context *before* the test element announces itself.\n * Resetting on that announcement discarded every one of those\n * registrations, so no test-level outcome could be read or set.\n */\n this.addEventListener('qti-testdoc-loaded', () => {\n this.testContext = INITIAL_TEST_CONTEXT;\n this.sessionContext = INITIAL_SESSION_CONTEXT;\n });\n\n /**\n * When the test is connected, its item-refs are added to the test context.\n * Registrations from the document's children are already present on the\n * context reset above, so this must preserve what is there.\n */\n listenPublic(this, 'qc-test-loaded', (e: CustomEvent<QtiAssessmentTest>) => {\n this._testElement = e.detail;\n const items = Array.from(this._testElement.querySelectorAll('qti-assessment-item-ref')).map(itemRef => {\n return {\n href: itemRef.href,\n identifier: itemRef.identifier,\n category: itemRef.category,\n variables: [\n {\n identifier: 'completionStatus',\n value: 'not_attempted',\n type: 'outcome'\n } as OutcomeVariable\n ]\n };\n });\n this.testContext = { ...this.testContext, items };\n });\n\n this.addEventListener('qti-assessment-item-connected', (e: CustomEvent<QtiAssessmentItem>) => {\n const assessmentItem = e.detail as QtiAssessmentItem;\n const assessmentRefId = assessmentItem.closest('qti-assessment-item-ref')?.identifier;\n if (assessmentRefId) {\n assessmentItem.assessmentItemRefId = assessmentRefId;\n }\n this._updateItemInTestContext(e.detail);\n });\n\n this.addEventListener('qti-item-context-updated', (e: CustomEvent<{ itemContext: ItemContext }>) => {\n // const assessmentitem = e.composedPath()[0] as QtiAssessmentItem;\n this._updateItemVariablesInTestContext(\n e.detail.itemContext.identifier,\n e.detail.itemContext.variables,\n e.detail.itemContext.state,\n e.detail.itemContext.valid\n );\n });\n }\n\n private _updateItemVariablesInTestContext(\n identifier: string,\n variables: readonly VariableDeclaration<string | string[] | null>[],\n state?: ItemContext['state'],\n valid?: boolean\n ): void {\n // Update the test context with modified variables for the specified item\n this.testContext = {\n ...this.testContext, // Spread existing test context properties\n items: this.testContext.items.map(itemContext => {\n // If the item identifier doesn't match, keep it unchanged\n if (itemContext.identifier !== identifier) {\n return itemContext;\n }\n\n // Update the matching item with new variables\n return {\n ...itemContext, // Keep other properties of the item context\n variables: variables.map(variable => {\n // Find a matching variable in the current item context\n const matchingVariable = itemContext.variables.find(v => v.identifier === variable.identifier);\n\n // Merge matching variable with the new one, or use the new variable if no match\n return matchingVariable ? { ...matchingVariable, ...variable } : variable;\n }),\n ...(state !== undefined ? { state: state ? { ...state } : undefined } : {}),\n ...(valid !== undefined ? { valid } : {})\n };\n })\n };\n // Deprecated for hosts, see `@event` on `qti-test`; kept until the next major.\n this.dispatchEvent(\n new CustomEvent('qti-test-context-updated', { detail: this.testContext, bubbles: false, composed: false })\n );\n }\n\n /**\n * Updates the variables of an assessment item in the test context.\n * - Matches the assessment item with the corresponding test context item.\n * - If the item is not found, logs a warning.\n * - Updates variables in the test context if exactly one variable exists.\n * - Otherwise, syncs the assessment item's variables with the test context.\n *\n * @param assessmentItem - The assessment item to update.\n */\n private _updateItemInTestContext = (assessmentItem: QtiAssessmentItem): void => {\n const context = assessmentItem.itemContext;\n const identifier = context.identifier;\n const fullVariables = context.variables;\n\n // Find the corresponding item in the test context by identifier\n const itemContext = this.testContext.items.find(i => i?.identifier === identifier);\n\n if (!itemContext) {\n console.warn(`Item IDs between assessment.xml and item.xml should match: ${identifier} is not found!`);\n return;\n }\n\n // Update variables in the test context or sync them to the assessment item\n if (itemContext.variables?.length === 1) {\n // The loaded qti-assessment-item itself has variables which are not in test context yet.\n this._updateItemVariablesInTestContext(identifier, fullVariables, undefined, context.valid);\n } else {\n const newVariables = [...assessmentItem.variables];\n // Sync the assessment item's variables with the test context\n for (const variable of itemContext.variables) {\n // Presenting an item starts its first attempt, so it is no longer `not_attempted` once it\n // is on screen: the item keeps its own status (`unknown`) — `qti-number-presented` reads it.\n if (variable.identifier === 'completionStatus' && variable.value === 'not_attempted') continue;\n const currentVariable = newVariables.find(v => v.identifier === variable.identifier);\n if (currentVariable) {\n currentVariable.value = variable.value;\n } else {\n newVariables.push(variable);\n }\n }\n assessmentItem.variables = newVariables;\n this.#leaveNotAttempted(identifier, newVariables.find(v => v.identifier === 'completionStatus')?.value);\n // Opaque interaction state (a PCI's getState()) is read from the item context when the\n // interaction initializes, so it has to be in place now, before that happens.\n if (itemContext.state) {\n assessmentItem.state = itemContext.state;\n }\n }\n };\n\n /** Write the presented item's own status over a `not_attempted` the test context still holds for it. */\n #leaveNotAttempted(identifier: string, status: Readonly<string | string[] | null> | undefined): void {\n if (typeof status !== 'string' || status === 'not_attempted') return;\n const item = this.testContext.items.find(i => i.identifier === identifier);\n const current = item?.variables.find(v => v.identifier === 'completionStatus');\n if (current?.value !== 'not_attempted') return;\n this.testContext = {\n ...this.testContext,\n items: this.testContext.items.map(i =>\n i.identifier !== identifier\n ? i\n : {\n ...i,\n variables: i.variables.map(v => (v.identifier === 'completionStatus' ? { ...v, value: status } : v))\n }\n )\n };\n }\n }\n\n return TestBaseClass as Constructor<TestBaseInterface> & T;\n};\n\n// Keep the old abstract class for backwards compatibility during migration\nexport abstract class TestBase extends TestBaseMixin(LitElement) {}\n"]}
|