@qti-components/test 2.0.0-next.28 → 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.
@@ -11,6 +11,7 @@ import { prepareTemplate } from '@heximal/templates';
11
11
  import { computedContext } from '@qti-components/base';
12
12
  import { testHostContext } from '../../internal/test-host.context';
13
13
  import { dispatchPublic } from '../../public-events';
14
+ import { itemsInOrder } from '../../computed-tree';
14
15
  // Converter function to interpret "true" and "false" as booleans
15
16
  const stringToBooleanConverter = {
16
17
  fromAttribute(value) {
@@ -103,14 +104,8 @@ export class QtiAssessmentItemRef extends LitElement {
103
104
  });
104
105
  }
105
106
  #computedItem() {
106
- for (const testPart of this.computedContext?.testParts ?? []) {
107
- for (const section of testPart.sections) {
108
- const item = section.items.find(i => i.identifier === this.identifier);
109
- if (item)
110
- return item;
111
- }
112
- }
113
- return undefined;
107
+ // This element's identifier is the item instance: a clone's is `item-3#2`.
108
+ return this.computedContext?.testParts.flatMap(itemsInOrder).find(i => i.instance === this.identifier);
114
109
  }
115
110
  /**
116
111
  * The clone of `xmlDoc` that is rendered, and what it was cloned for. Cloned
@@ -1 +1 @@
1
- {"version":3,"file":"qti-assessment-item-ref.js","sourceRoot":"","sources":["../../../src/components/qti-assessment-item-ref/qti-assessment-item-ref.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAErD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AACnE,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAOrD,iEAAi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SAAS,EAAE,IAAI,EAAE,CAAC;6DACX;AA0B5C;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;oDACN;AAc7B;IADT,OAAO,CAAC,EAAE,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;sDACzB","sourcesContent":["import { LitElement, nothing } from 'lit';\nimport { property, state } from 'lit/decorators.js';\nimport { consume } from '@lit/context';\nimport { prepareTemplate } from '@heximal/templates';\n\nimport { computedContext } from '@qti-components/base';\n\nimport { testHostContext } from '../../internal/test-host.context';\nimport { dispatchPublic } from '../../public-events';\n\nimport type { ComputedContext, ComputedItem } from '@qti-components/base';\nimport type { QtiAssessmentItem } from '@qti-components/elements';\nimport type { TestHost } from '../../internal/test-host.context';\nimport type { TemplateFunction } from '@heximal/templates';\n\n// Converter function to interpret \"true\" and \"false\" as booleans\nconst stringToBooleanConverter = {\n fromAttribute(value: string): boolean {\n return value === 'true';\n },\n toAttribute(value: boolean): string {\n return value ? 'true' : 'false';\n }\n};\n\n/**\n * The model a `<template item-ref>` is rendered with.\n *\n * Only what this element already knows: the item's parsed document and the\n * attributes off the item-ref itself. `itemRef` is the escape hatch — a\n * template that needs anything else (a click handler, a value from the host\n * app) reaches it through a property on the element, which the host is free to\n * set.\n */\nexport interface ItemRefTemplateModel {\n /** The item's parsed document, i.e. what the element renders by default. */\n xmlDoc: DocumentFragment;\n identifier?: string;\n href?: string;\n category?: string;\n /**\n * This item's entry in the computed context, the same object the stamps\n * iterate as `item`: `index` (1-based, null for info items), `score`,\n * `maxScore`, `completed`, `active`, … Undefined until the test has computed it.\n */\n item?: ComputedItem;\n /** The element being rendered. */\n itemRef: QtiAssessmentItemRef;\n}\n\n// @customElement('qti-assessment-item-ref')\nexport class QtiAssessmentItemRef extends LitElement {\n @property({ type: String }) category?: string;\n @property({ type: String }) identifier?: string;\n @property({ type: Boolean, converter: stringToBooleanConverter }) required?: boolean;\n @property({ type: Boolean, converter: stringToBooleanConverter }) fixed?: boolean;\n @property({ type: String }) href?: string;\n\n // Only read by a <template item-ref>; subscribing re-renders it as scores come in\n @state()\n @consume({ context: computedContext, subscribe: true })\n protected computedContext?: ComputedContext;\n\n /**\n * The `<qti-weight>` children of this ref, keyed by identifier — what\n * `qti-test-variables`' `weight-identifier` resolves against.\n *\n * Read on access rather than cached: the test document is rendered into this\n * element's light DOM, so the weights are not in place at construction time,\n * and outcome processing runs long after they are.\n */\n get weights(): Map<string, number> {\n const weights = new Map<string, number>();\n for (const weight of this.querySelectorAll(':scope > qti-weight')) {\n const identifier = weight.getAttribute('identifier');\n if (!identifier) continue;\n const value = Number(weight.getAttribute('value'));\n if (Number.isNaN(value)) {\n console.warn(`qti-weight \"${identifier}\" has a non-numeric value, ignoring it`);\n continue;\n }\n weights.set(identifier, value);\n }\n return weights;\n }\n\n @property({ type: Object, attribute: false })\n xmlDoc: DocumentFragment | null = null;\n\n protected override createRenderRoot(): HTMLElement | DocumentFragment {\n return this;\n }\n\n get assessmentItem(): QtiAssessmentItem | null {\n return this.renderRoot?.querySelector('qti-assessment-item');\n }\n\n myTemplate: TemplateFunction | null = null;\n\n /** The `qti-test` this ref belongs to, wherever it renders: light DOM, or any depth of shadow roots. */\n @consume({ context: testHostContext, subscribe: true })\n protected testHost?: TestHost;\n\n override disconnectedCallback(): void {\n super.disconnectedCallback();\n // A context consumer keeps its last value when it is moved somewhere with no provider, and\n // `closest()` never did: a ref moved out of a test must not keep that test's template.\n this.testHost = undefined;\n }\n\n override async connectedCallback(): Promise<void> {\n super.connectedCallback();\n\n /*\n Optional per-item template, used to render extra things around an item —\n a bookmark, an index number, a score badge. Put it in the light DOM of\n your qti-test, and every item-ref in the test renders with it:\n\n <qti-test>\n <template item-ref>\n <div class=\"badge\">{{ identifier }}</div>\n {{ xmlDoc }}\n </template>\n …\n </qti-test>\n\n The template is the WHOLE render, so it has to place {{ xmlDoc }} itself;\n leaving it out renders the chrome and no item. Without a template the\n element renders the item on its own, exactly as before.\n\n Resolved once, on connect: one template serves every item, and everything\n that varies per item comes through the model (see ItemRefTemplateModel).\n */\n const templateElement = this.testHost?.querySelector<HTMLTemplateElement>('template[item-ref]');\n this.myTemplate = templateElement ? prepareTemplate(templateElement) : null;\n this.requestUpdate();\n\n await this.updateComplete;\n\n dispatchPublic(this, 'qc-item-ref-connected', {\n identifier: this.identifier,\n href: this.href,\n category: this.category\n });\n }\n\n #computedItem(): ComputedItem | undefined {\n for (const testPart of this.computedContext?.testParts ?? []) {\n for (const section of testPart.sections) {\n const item = section.items.find(i => i.identifier === this.identifier);\n if (item) return item;\n }\n }\n return undefined;\n }\n\n /**\n * The clone of `xmlDoc` that is rendered, and what it was cloned for. Cloned\n * once per document and template, not per render: re-renders from\n * computed-context changes then hand Lit the same fragment, which it leaves\n * alone, instead of rebuilding the item (and reloading its PCIs, which\n * changes the context again).\n */\n #rendered: { source: DocumentFragment; template: TemplateFunction | null; doc: DocumentFragment } | null = null;\n\n override render() {\n // Item refs connect before loading, and navigation clears their documents.\n if (!this.xmlDoc) {\n this.#rendered = null;\n return nothing;\n }\n\n if (this.#rendered?.source !== this.xmlDoc || this.#rendered.template !== this.myTemplate) {\n this.#rendered = {\n source: this.xmlDoc,\n template: this.myTemplate,\n doc: this.xmlDoc.cloneNode(true) as DocumentFragment\n };\n }\n const xmlDoc = this.#rendered.doc;\n if (!this.myTemplate) return xmlDoc;\n\n const model: ItemRefTemplateModel = {\n xmlDoc,\n identifier: this.identifier,\n href: this.href,\n category: this.category,\n item: this.#computedItem(),\n itemRef: this\n };\n return this.myTemplate(model);\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'qti-assessment-item-ref': QtiAssessmentItemRef;\n }\n}\n"]}
1
+ {"version":3,"file":"qti-assessment-item-ref.js","sourceRoot":"","sources":["../../../src/components/qti-assessment-item-ref/qti-assessment-item-ref.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,OAAO,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AE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,wBAAwB,EAAE,CAAC;mDAAiB;AACtD;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;kDAAe;AAKhC;IAFT,KAAK,EAAE;IACP,OAAO,CAAC,EAAE,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;6DACX;AA0B5C;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;oDACN;AAc7B;IADT,OAAO,CAAC,EAAE,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;sDACzB","sourcesContent":["import { LitElement, nothing } from 'lit';\nimport { property, state } from 'lit/decorators.js';\nimport { consume } from '@lit/context';\nimport { prepareTemplate } from '@heximal/templates';\n\nimport { computedContext } from '@qti-components/base';\n\nimport { testHostContext } from '../../internal/test-host.context';\nimport { dispatchPublic } from '../../public-events';\nimport { itemsInOrder } from '../../computed-tree';\n\nimport type { ComputedContext, ComputedItem } from '@qti-components/base';\nimport type { QtiAssessmentItem } from '@qti-components/elements';\nimport type { TestHost } from '../../internal/test-host.context';\nimport type { TemplateFunction } from '@heximal/templates';\n\n// Converter function to interpret \"true\" and \"false\" as booleans\nconst stringToBooleanConverter = {\n fromAttribute(value: string): boolean {\n return value === 'true';\n },\n toAttribute(value: boolean): string {\n return value ? 'true' : 'false';\n }\n};\n\n/**\n * The model a `<template item-ref>` is rendered with.\n *\n * Only what this element already knows: the item's parsed document and the\n * attributes off the item-ref itself. `itemRef` is the escape hatch — a\n * template that needs anything else (a click handler, a value from the host\n * app) reaches it through a property on the element, which the host is free to\n * set.\n */\nexport interface ItemRefTemplateModel {\n /** The item's parsed document, i.e. what the element renders by default. */\n xmlDoc: DocumentFragment;\n identifier?: string;\n href?: string;\n category?: string;\n /**\n * This item's entry in the computed context, the same object the stamps\n * iterate as `item`: `index` (1-based, null for info items), `score`,\n * `maxScore`, `completed`, `active`, … Undefined until the test has computed it.\n */\n item?: ComputedItem;\n /** The element being rendered. */\n itemRef: QtiAssessmentItemRef;\n}\n\n// @customElement('qti-assessment-item-ref')\nexport class QtiAssessmentItemRef extends LitElement {\n @property({ type: String }) category?: string;\n @property({ type: String }) identifier?: string;\n @property({ type: Boolean, converter: stringToBooleanConverter }) required?: boolean;\n @property({ type: Boolean, converter: stringToBooleanConverter }) fixed?: boolean;\n @property({ type: String }) href?: string;\n\n // Only read by a <template item-ref>; subscribing re-renders it as scores come in\n @state()\n @consume({ context: computedContext, subscribe: true })\n protected computedContext?: ComputedContext;\n\n /**\n * The `<qti-weight>` children of this ref, keyed by identifier — what\n * `qti-test-variables`' `weight-identifier` resolves against.\n *\n * Read on access rather than cached: the test document is rendered into this\n * element's light DOM, so the weights are not in place at construction time,\n * and outcome processing runs long after they are.\n */\n get weights(): Map<string, number> {\n const weights = new Map<string, number>();\n for (const weight of this.querySelectorAll(':scope > qti-weight')) {\n const identifier = weight.getAttribute('identifier');\n if (!identifier) continue;\n const value = Number(weight.getAttribute('value'));\n if (Number.isNaN(value)) {\n console.warn(`qti-weight \"${identifier}\" has a non-numeric value, ignoring it`);\n continue;\n }\n weights.set(identifier, value);\n }\n return weights;\n }\n\n @property({ type: Object, attribute: false })\n xmlDoc: DocumentFragment | null = null;\n\n protected override createRenderRoot(): HTMLElement | DocumentFragment {\n return this;\n }\n\n get assessmentItem(): QtiAssessmentItem | null {\n return this.renderRoot?.querySelector('qti-assessment-item');\n }\n\n myTemplate: TemplateFunction | null = null;\n\n /** The `qti-test` this ref belongs to, wherever it renders: light DOM, or any depth of shadow roots. */\n @consume({ context: testHostContext, subscribe: true })\n protected testHost?: TestHost;\n\n override disconnectedCallback(): void {\n super.disconnectedCallback();\n // A context consumer keeps its last value when it is moved somewhere with no provider, and\n // `closest()` never did: a ref moved out of a test must not keep that test's template.\n this.testHost = undefined;\n }\n\n override async connectedCallback(): Promise<void> {\n super.connectedCallback();\n\n /*\n Optional per-item template, used to render extra things around an item —\n a bookmark, an index number, a score badge. Put it in the light DOM of\n your qti-test, and every item-ref in the test renders with it:\n\n <qti-test>\n <template item-ref>\n <div class=\"badge\">{{ identifier }}</div>\n {{ xmlDoc }}\n </template>\n …\n </qti-test>\n\n The template is the WHOLE render, so it has to place {{ xmlDoc }} itself;\n leaving it out renders the chrome and no item. Without a template the\n element renders the item on its own, exactly as before.\n\n Resolved once, on connect: one template serves every item, and everything\n that varies per item comes through the model (see ItemRefTemplateModel).\n */\n const templateElement = this.testHost?.querySelector<HTMLTemplateElement>('template[item-ref]');\n this.myTemplate = templateElement ? prepareTemplate(templateElement) : null;\n this.requestUpdate();\n\n await this.updateComplete;\n\n dispatchPublic(this, 'qc-item-ref-connected', {\n identifier: this.identifier,\n href: this.href,\n category: this.category\n });\n }\n\n #computedItem(): ComputedItem | undefined {\n // This element's identifier is the item instance: a clone's is `item-3#2`.\n return this.computedContext?.testParts.flatMap(itemsInOrder).find(i => i.instance === this.identifier);\n }\n\n /**\n * The clone of `xmlDoc` that is rendered, and what it was cloned for. Cloned\n * once per document and template, not per render: re-renders from\n * computed-context changes then hand Lit the same fragment, which it leaves\n * alone, instead of rebuilding the item (and reloading its PCIs, which\n * changes the context again).\n */\n #rendered: { source: DocumentFragment; template: TemplateFunction | null; doc: DocumentFragment } | null = null;\n\n override render() {\n // Item refs connect before loading, and navigation clears their documents.\n if (!this.xmlDoc) {\n this.#rendered = null;\n return nothing;\n }\n\n if (this.#rendered?.source !== this.xmlDoc || this.#rendered.template !== this.myTemplate) {\n this.#rendered = {\n source: this.xmlDoc,\n template: this.myTemplate,\n doc: this.xmlDoc.cloneNode(true) as DocumentFragment\n };\n }\n const xmlDoc = this.#rendered.doc;\n if (!this.myTemplate) return xmlDoc;\n\n const model: ItemRefTemplateModel = {\n xmlDoc,\n identifier: this.identifier,\n href: this.href,\n category: this.category,\n item: this.#computedItem(),\n itemRef: this\n };\n return this.myTemplate(model);\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'qti-assessment-item-ref': QtiAssessmentItemRef;\n }\n}\n"]}
@@ -11,6 +11,7 @@ import { computedContext } from '@qti-components/base';
11
11
  import { watch } from '@qti-components/utilities';
12
12
  import * as styles from '../styles';
13
13
  import { dispatchPublic } from '../../public-events';
14
+ import { activeTestPart, itemsInOrder } from '../../computed-tree';
14
15
  /** The identifier of the item-ref an element is stamped into (`<template item-ref>`), looking out through shadow roots. */
15
16
  const itemRefOf = (element) => {
16
17
  const itemRef = element.closest('qti-assessment-item-ref');
@@ -74,13 +75,14 @@ export class TestEndAttempt extends LitElement {
74
75
  checkDisabled() {
75
76
  const testParts = this.computedContext?.testParts;
76
77
  const ownItem = this.#ownItem;
77
- const testPart = testParts?.find(testPart => testPart.active);
78
+ const testPart = activeTestPart(this.computedContext);
78
79
  if (!testParts || (!ownItem && !testPart))
79
80
  return;
80
- // Its own item wherever it is in the test, or else the item on screen in the active part.
81
+ // Its own item (an instance: a clone is `item-3#2`) wherever it is in the test, or else the item
82
+ // on screen in the active part.
81
83
  const activeItem = ownItem
82
- ? testParts.flatMap(part => part.sections.flatMap(section => section.items)).find(i => i.identifier === ownItem)
83
- : testPart.sections.flatMap(section => section.items).find(item => item.active);
84
+ ? testParts.flatMap(itemsInOrder).find(i => i.instance === ownItem)
85
+ : itemsInOrder(testPart).find(item => item.active);
84
86
  if (!activeItem) {
85
87
  this._internalDisabled = false;
86
88
  return;
@@ -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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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"]}
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;AACrD,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAInE,2HAA2H;AAC3H,MAAM,SAAS,GAAG,CAAC,OAAgB,EAAsB,EAAE;IACzD,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,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ES;IAFT,OAAO,CAAC,EAAE,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;IACtD,QAAQ,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;uDACY;AAGpC;IADN,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,UAAU,EAAE,CAAC;yDACjC;AAEJ;IAA5B,QAAQ,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;4CAAe;AAG8B;IAAxE,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,gBAAgB,EAAE,CAAC;qDAAuB;AAG/F;IADC,KAAK,CAAC,iBAAiB,CAAC;8DAKxB;AAuDH;;;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';\nimport { activeTestPart, itemsInOrder } from '../../computed-tree';\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 = activeTestPart(this.computedContext);\n if (!testParts || (!ownItem && !testPart)) return;\n // Its own item (an instance: a clone is `item-3#2`) wherever it is in the test, or else the item\n // on screen in the active part.\n const activeItem = ownItem\n ? testParts.flatMap(itemsInOrder).find(i => i.instance === ownItem)\n : itemsInOrder(testPart).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"]}
@@ -19,6 +19,7 @@ import { attemptsOf, itemSessionFacts } from '../../internal/item-session-facts'
19
19
  import { renderedMarkup } from '../../internal/rendered-markup';
20
20
  import { testHostContext } from '../../internal/test-host.context';
21
21
  import { listenPublic } from '../../public-events';
22
+ import { itemsInOrder } from '../../computed-tree';
22
23
  /** A new object each time: a host that mutates the one it read must not change anyone else's. */
23
24
  const newQtiContext = () => ({
24
25
  QTI_CONTEXT: { testIdentifier: '', candidateIdentifier: '', environmentIdentifier: 'default' }
@@ -305,10 +306,7 @@ export class TestNavigation extends LitElement {
305
306
  afterAttemptEnded(_assessmentItem, _computedItem, _done) { }
306
307
  /** The computed-context entry for an item, from the session-control cascade. */
307
308
  computedItemFor(identifier) {
308
- return this.computedContext?.testParts
309
- ?.flatMap(part => part.sections)
310
- .flatMap(section => section.items)
311
- .find(i => i.identifier === identifier);
309
+ return this.computedContext?.testParts.flatMap(itemsInOrder).find(i => i.instance === identifier);
312
310
  }
313
311
  /** The assessment item for an item-ref id, if it has been rendered. */
314
312
  #assessmentItemFor(identifier) {
@@ -507,9 +505,7 @@ export class TestNavigation extends LitElement {
507
505
  return;
508
506
  // In a simultaneous part every item has one attempt, processed when the part ends (QTI info model
509
507
  // §2.8.2), so the candidate may change the answer until then: TAO keeps such an item open too.
510
- const items = new Map(this.computedContext.testParts.flatMap(part => part.submissionMode === 'simultaneous'
511
- ? []
512
- : part.sections.flatMap(section => section.items.map(item => [item.identifier, item]))));
508
+ const items = new Map(this.computedContext.testParts.flatMap(part => part.submissionMode === 'simultaneous' ? [] : itemsInOrder(part).map(item => [item.instance, item])));
513
509
  for (const itemRef of this.#testElement.querySelectorAll('qti-assessment-item-ref')) {
514
510
  const element = itemRef.assessmentItem;
515
511
  if (!element)
@@ -1 +1 @@
1
- {"version":3,"file":"test-navigation.js","sourceRoot":"","sources":["../../../src/components/test-navigation/test-navigation.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,eAAe,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACjE,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAEpD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EACL,cAAc,EACd,cAAc,EACd,iBAAiB,EACjB,eAAe,EACf,aAAa,EACb,iBAAiB,EAClB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,YAAY,IAAI,gBAAgB,EAAE,MAAM,wCAAwC,CAAC;AAE1F,OAAO,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,MAAM,wCAAwC,CAAC;AACjG,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AACrE,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AACjF,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AACnE,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAkBnD,iGAAiG;AACjG,MAAM,aAAa,GAAG,GAAe,EAAE,CAAC,CAAC;IACvC,WAAW,EAAE,EAAE,cAAc,EAAE,EAAE,EAAE,mBAAmB,EAAE,EAA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,EAAE,CAAC;gBACnD,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;gBAClC,OAAO,CAAC,QAAQ,GAAG,KAAK,CAAC;YAC3B,CAAC;QACH,CAAC;IACH,CAAC;CACF;AA9iB6B;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;kDAA4C;AAUhE;IADN,KAAK,EAAE;mDAC8D;AAiH/D;IAFN,KAAK,EAAE;IACP,OAAO,CAAC,EAAE,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;qDACZ;AAI/B;IAFT,KAAK,EAAE;IACP,OAAO,CAAC,EAAE,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;oDACd;AAI3B;IAFT,KAAK,EAAE;IACP,OAAO,CAAC,EAAE,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;uDACX;AAKjC;IAFT,KAAK,EAAE;IACP,OAAO,CAAC,EAAE,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;kDAClB;AAI5B;IAFT,KAAK,EAAE;IACP,OAAO,CAAC,EAAE,OAAO,EAAE,eAAe,EAAE,CAAC;uDACK;AAEiB;IAA3D,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,kBAAkB,EAAE,CAAC;sDAAwB","sourcesContent":["import { ContextConsumer, consume, provide } from '@lit/context';\nimport { html, LitElement } from 'lit';\nimport { property, state } from 'lit/decorators.js';\n\nimport { computedContext } from '@qti-components/base';\nimport {\n buildTestModel,\n endItemAttempt,\n followItemSession,\n itemRefsInOrder,\n readItemFacts,\n seedItemLifecycle\n} from '@qti-components/delivery';\nimport { configContext } from '@qti-components/base';\nimport { testContext } from '@qti-components/base';\nimport { sessionContext } from '@qti-components/base';\nimport { listenPublic as listenItemPublic } from '@qti-components/elements/public-events';\n\nimport { assessOptimality, deriveComputedContext } from '../../internal/derive-computed-context';\nimport { itemFactsContext } from '../../internal/item-facts.context';\nimport { attemptsOf, itemSessionFacts } from '../../internal/item-session-facts';\nimport { renderedMarkup } from '../../internal/rendered-markup';\nimport { testHostContext } from '../../internal/test-host.context';\nimport { listenPublic } from '../../public-events';\n\nimport type { QtiAssessmentItem } from '@qti-components/elements';\nimport type { QtiContext } from '@qti-components/base';\nimport type { OutcomeVariable } from '@qti-components/base';\nimport type { ComputedContext, ComputedItem } from '@qti-components/base';\nimport type { PropertyValues } from 'lit';\nimport type { QtiAssessmentItemRef } from '../qti-assessment-item-ref/qti-assessment-item-ref';\nimport type { QtiAssessmentTest } from '../qti-assessment-test/qti-assessment-test';\nimport type { ItemSession, ItemSessionFacts, TestModel } from '@qti-components/delivery';\nimport type { ItemOptimality } from '../../internal/derive-computed-context';\nimport type { ItemFactsByRef } from '../../internal/item-facts.context';\nimport type { LinearNextRefusal, TestHost } from '../../internal/test-host.context';\nimport type { ConfigContext } from '@qti-components/base';\nimport type { SessionContext } from '@qti-components/base';\nimport type { TestContext } from '@qti-components/base';\nimport type { ItemContext } from '@qti-components/base';\n\n/** A new object each time: a host that mutates the one it read must not change anyone else's. */\nconst newQtiContext = (): QtiContext => ({\n QTI_CONTEXT: { testIdentifier: '', candidateIdentifier: '', environmentIdentifier: 'default' }\n});\n\nexport class TestNavigation extends LitElement {\n @property({ type: String }) identifier: string | undefined = undefined;\n\n /**\n * Your own per-item fields, by item-ref `identifier`: each `computedContext` item carries them as\n * given under `data`, without the identifier, and so does every view of it a plugin derives. They\n * never replace a field the test, the item or the candidate's state gives, whatever its name; a\n * template reads `activeItem.data.<field>`. To mark an item as scored by hand, set\n * `external-scored` on its `SCORE` declaration in `postLoadTransformCallback`.\n */\n @state()\n public initContext: { identifier: string; [key: string]: any }[] = [];\n\n /**\n * @deprecated Set `qtiContext` on `qti-test`, which provides it. This is an alias for the\n * enclosing test's: reading returns it, writing replaces it, so a host that has always set the\n * shuffle seed here keeps working. Removed in the next major.\n *\n * Written before the navigation is inside a test, it waits and is handed over on connect.\n */\n public get qtiContext(): QtiContext {\n return this.#owner()?.qtiContext ?? (this.#pendingQtiContext ??= newQtiContext());\n }\n\n public set qtiContext(value: QtiContext) {\n if (!this.#warnedQtiContext) {\n this.#warnedQtiContext = true;\n console.warn(\n '[qti-components] `test-navigation.qtiContext` is deprecated and will be removed in the next major ' +\n 'release. Set `qtiContext` on `<qti-test>` instead; it is the same value.'\n );\n }\n this.#writeQtiContext(value);\n }\n\n #pendingQtiContext?: QtiContext;\n #warnedQtiContext = false;\n\n /** The write the library itself makes. Not the deprecated setter, so it never warns about itself. */\n #writeQtiContext(value: QtiContext): void {\n const owner = this.#owner();\n if (owner) owner.qtiContext = value;\n else this.#pendingQtiContext = value;\n }\n\n /**\n * The `qti-test` this navigation is in, found through context so it works across shadow roots.\n * A write made before it is known waits in `#pendingQtiContext` and is handed over on arrival.\n */\n #testHost = new ContextConsumer(this, {\n context: testHostContext,\n subscribe: true,\n callback: host => {\n if (host && this.#pendingQtiContext) {\n host.qtiContext = this.#pendingQtiContext;\n this.#pendingQtiContext = undefined;\n }\n if (host) this.#registerLinearNext(host);\n }\n });\n\n /** The `qti-test` this navigation answers Next for in a linear part. */\n #linearNextHost?: TestHost;\n\n #registerLinearNext(host: TestHost): void {\n if (this.#linearNextHost && this.#linearNextHost !== host) this.#linearNextHost.beforeLinearNext = null;\n this.#linearNextHost = host;\n host.beforeLinearNext = this.#beforeLinearNext;\n }\n\n override connectedCallback(): void {\n super.connectedCallback();\n if (this.#linearNextHost) this.#linearNextHost.beforeLinearNext = this.#beforeLinearNext;\n }\n\n override disconnectedCallback(): void {\n super.disconnectedCallback();\n if (this.#linearNextHost?.beforeLinearNext === this.#beforeLinearNext) this.#linearNextHost.beforeLinearNext = null;\n }\n\n /**\n * Next in a linear individual part leaves the item for good (implementation guide §4.1), so it\n * submits what the candidate gave (decided 2026-11-27): refused while the session control refuses\n * those responses (`rules.maySubmit`), else the attempt is ended when one is open: none ended yet,\n * or the responses changed since the last. Called by the navigation mixin while the item is still\n * rendered; the item is closed when the navigation moves past it.\n */\n #beforeLinearNext = (itemRefId: string): LinearNextRefusal | null => {\n const part = this.#model?.testParts.find(testPart =>\n itemRefsInOrder(testPart.sections).some(item => item.identifier === itemRefId)\n );\n if (part?.navigationMode !== 'linear' || part.submissionMode !== 'individual') return null;\n const session = this.#sessions.get(itemRefId);\n const rules = this.computedItemFor(itemRefId)?.rules;\n if (session?.state !== 'interacting' || !rules) return null;\n if (!rules.maySubmit) {\n return { reason: rules.maySkip ? 'validate-responses' : 'allow-skipping', itemId: itemRefId };\n }\n if (session.numAttempts === 0 || this.#changed.has(itemRefId)) {\n this.#assessmentItemFor(itemRefId)?.processResponse(\n true,\n this.configContext?.reportValidityAfterScoring === true\n );\n }\n return null;\n };\n\n /** The item-refs whose responses changed since their last ended attempt. */\n #changed = new Set<string>();\n\n #itemRefIdOf(element: EventTarget | undefined): string | undefined {\n const item = (element as HTMLElement | undefined)?.closest?.('qti-assessment-item');\n if (!item) return undefined;\n return [...(this.#testElement?.querySelectorAll<QtiAssessmentItemRef>('qti-assessment-item-ref') ?? [])].find(\n itemRef => itemRef.assessmentItem === item\n )?.identifier;\n }\n\n #owner(): { qtiContext: QtiContext } | null {\n return this.#testHost.value ?? null;\n }\n\n @state()\n @consume({ context: configContext, subscribe: true })\n public configContext: ConfigContext = {};\n\n @state()\n @consume({ context: testContext, subscribe: true })\n protected _testContext?: TestContext;\n\n @state()\n @consume({ context: sessionContext, subscribe: true })\n protected _sessionContext?: SessionContext;\n\n /** Read from each item's XML when `qti-test` fetches it; see `itemFactsContext`. */\n @state()\n @consume({ context: itemFactsContext, subscribe: true })\n protected _itemFacts?: ItemFactsByRef;\n\n @state()\n @provide({ context: computedContext })\n protected computedContext: ComputedContext;\n\n @property({ type: Boolean, attribute: 'auto-score-items' }) autoScoreItems = false;\n\n #testElement: QtiAssessmentTest;\n\n /**\n * Whether each item's last *ended attempt* reached the optimal outcome, keyed\n * by item-ref id. Written from #handleItemContextUpdated when processResponse\n * ends an attempt — never on a plain selection. Mirrors how inline feedback\n * only re-evaluates when an attempt is processed, so a freshly-picked answer\n * doesn't flip `done` until the candidate ends the attempt.\n */\n #optimality = new Map<string, ItemOptimality>();\n\n /**\n * Each item session's lifecycle state, by item-ref identifier, changed only through the lifecycle\n * table (`followItemSession` as the candidate moves, `endItemAttempt` when an attempt ends). It\n * lives here until `DeliveryState` holds it (roadmap 1, T3d); a session whose attempts change\n * outside an ended attempt (a restored or assigned state) is seeded again.\n */\n #sessions = new Map<string, ItemSession>();\n\n constructor() {\n super();\n listenPublic(this, 'qc-test-loaded', this.#handleTestConnected.bind(this));\n\n listenItemPublic(this, 'qc-item-response-changed', this.#handleInteractionChanged.bind(this));\n this.addEventListener('qti-item-context-updated', this.#handleItemContextUpdated.bind(this));\n\n listenPublic(this, 'qc-test-end-attempt', this.#handleTestEndAttempt.bind(this));\n listenPublic(this, 'qc-test-update-outcome', this.#handleTestUpdateOutcomeVariable.bind(this));\n listenPublic(this, 'qc-test-update-comment', this.#handleUpdateComment.bind(this));\n }\n\n /**\n * Sets the candidate's comment on an item when its session allows it (`rules.mayComment`:\n * `allow-comment`, while interacting; decided 2026-11-27, carried, not rendered).\n */\n #handleUpdateComment(event: CustomEvent<{ itemId: string; comment: string | null }>) {\n const { itemId, comment = null } = event.detail ?? ({} as { itemId?: string; comment?: string | null });\n const host = this.#testHost.value;\n if (!itemId || !host) return;\n if (comment !== null && typeof comment !== 'string') {\n console.warn(`[qti-test] Ignoring a comment for \"${itemId}\" that is not a string.`);\n return;\n }\n if (!this.computedItemFor(itemId)?.rules?.mayComment) {\n console.warn(\n `[qti-test] Ignoring a comment for \"${itemId}\": its allow-comment is false, or it is not interacting.`\n );\n return;\n }\n host.updateItemComment(itemId, comment);\n }\n\n /**\n * Latch whether an item reached its optimal outcome whenever it has just ended\n * an attempt. processResponse — fired by test-end-attempt, autoscore, or an\n * in-item end-attempt interaction — flags its context update with\n * `responseProcessed`; a plain selection updates the context without it, so\n * `done` can't flip until the candidate actually ends the attempt.\n */\n #handleItemContextUpdated(event: CustomEvent<{ itemContext: ItemContext; responseProcessed?: boolean }>) {\n if (!event.detail?.responseProcessed) return;\n const itemContext = event.detail.itemContext;\n if (!itemContext?.identifier) return;\n this.#optimality.set(itemContext.identifier, assessOptimality(itemContext));\n this.#changed.delete(itemContext.identifier);\n this.#endAttempt(itemContext);\n\n const computedItem = this.computedItemFor(itemContext.identifier);\n this.afterAttemptEnded(\n (event.composedPath()[0] as HTMLElement)?.closest<QtiAssessmentItem>('qti-assessment-item'),\n computedItem,\n this.#doneAfterAttempt(itemContext, computedItem)\n );\n }\n\n /**\n * Moves the item's session on for its ended attempt. With `auto-score-items` every change is\n * scored as an attempt, so the count is not the candidate's: it is taken, and the state stays.\n */\n #endAttempt(itemContext: ItemContext): void {\n const facts = this.#sessionFacts().get(itemContext.identifier);\n if (!facts) return;\n const ended: ItemSessionFacts = { ...facts, ...attemptsOf(itemContext) };\n const previous = this.#sessions.get(itemContext.identifier);\n this.#sessions.set(\n itemContext.identifier,\n this.autoScoreItems\n ? {\n state: previous?.state ?? followItemSession(undefined, ended).state,\n numAttempts: ended.numAttempts,\n adaptive: ended.adaptive\n }\n : endItemAttempt(previous, ended)\n );\n }\n\n /**\n * Whether the item session is over after the attempt that just ended: its new state, or, before\n * the test model is known, the state an item on screen with these attempts is in.\n */\n #doneAfterAttempt(itemContext: ItemContext, computedItem: ComputedItem | undefined): boolean {\n const state =\n this.#sessions.get(itemContext.identifier)?.state ??\n (computedItem?.sessionControl\n ? seedItemLifecycle({\n sessionControl: computedItem.sessionControl,\n adaptive: computedItem.adaptive ?? false,\n ...attemptsOf(itemContext),\n presented: true,\n passed: false\n })\n : 'interacting');\n return state === 'closed' || state === 'review' || state === 'solution';\n }\n\n /** The facts of every item session now: the model, the item facts, the contexts and the items on screen. */\n #sessionFacts(): Map<string, ItemSessionFacts> {\n if (!this.#model) return new Map();\n const presented = new Set(\n [...(this.#testElement?.querySelectorAll<QtiAssessmentItemRef>('qti-assessment-item-ref') ?? [])]\n .filter(itemRef => itemRef.assessmentItem)\n .map(itemRef => itemRef.identifier)\n );\n return itemSessionFacts(this.#model, this.#itemFacts(), this._testContext?.items, {\n current: this._sessionContext?.navItemRefId,\n presented\n });\n }\n\n /**\n * The item facts `qti-test` read from each fetched item, and, for an item rendered without them\n * (handed to its ref directly), the facts read from the rendered item.\n */\n #itemFacts(): ItemFactsByRef | undefined {\n const missing = [\n ...(this.#testElement?.querySelectorAll<QtiAssessmentItemRef>('qti-assessment-item-ref') ?? [])\n ].filter(\n itemRef =>\n itemRef.assessmentItem?.localName === 'qti-assessment-item' && !this._itemFacts?.has(itemRef.identifier)\n );\n if (!missing.length) return this._itemFacts;\n const facts = new Map(this._itemFacts ?? []);\n for (const itemRef of missing) facts.set(itemRef.identifier, readItemFacts(renderedMarkup(itemRef.assessmentItem)));\n return facts;\n }\n\n /** Moves every item session on for where the candidate is now. */\n #followSessions(): void {\n for (const [identifier, facts] of this.#sessionFacts()) {\n this.#sessions.set(identifier, followItemSession(this.#sessions.get(identifier), facts));\n }\n }\n\n /**\n * Extension point for presentation packages reacting to an ended attempt. `done` is the item\n * session's after this attempt (closed: its attempts used, whatever the score), settled here\n * because the computed context only catches up on the next update.\n */\n protected afterAttemptEnded(\n _assessmentItem: QtiAssessmentItem | undefined,\n _computedItem: ComputedItem | undefined,\n _done: boolean\n ): void {}\n\n /** The computed-context entry for an item, from the session-control cascade. */\n protected computedItemFor(identifier: string): ComputedItem | undefined {\n return this.computedContext?.testParts\n ?.flatMap(part => part.sections)\n .flatMap(section => section.items)\n .find(i => i.identifier === identifier);\n }\n\n /** The assessment item for an item-ref id, if it has been rendered. */\n #assessmentItemFor(identifier: string | undefined): QtiAssessmentItem | undefined {\n if (!identifier) return undefined;\n const itemRef = this.#testElement?.querySelector<QtiAssessmentItemRef>(\n `qti-assessment-item-ref[identifier=\"${CSS.escape(identifier)}\"]`\n );\n return itemRef?.assessmentItem ?? undefined;\n }\n\n /** `computedContext.itemElement`: one function for the life of this element, carried along by every update. */\n #itemElement = (identifier: string): HTMLElement | null => this.#assessmentItemFor(identifier) ?? null;\n\n /** The currently active assessment item, exposed for optional presentation extensions. */\n protected get activeAssessmentItem(): QtiAssessmentItem | undefined {\n if (!this.#testElement || !this._sessionContext?.navItemRefId) return undefined;\n return this.#testElement.querySelector<QtiAssessmentItemRef>(\n `qti-assessment-item-ref[identifier=\"${this._sessionContext.navItemRefId}\"]`\n )?.assessmentItem;\n }\n\n /**\n * Ends an attempt: the item named by `detail.itemId` (a `test-end-attempt` stamped into an item, or\n * given an `item`), or else the item on screen.\n */\n #handleTestEndAttempt(event: CustomEvent<{ itemId?: string } | undefined>) {\n const itemId = event.detail?.itemId;\n const qtiAssessmentItemEl = itemId ? this.#assessmentItemFor(itemId) : this.activeAssessmentItem;\n if (!qtiAssessmentItemEl) return;\n const reportValidityAfterScoring = this.configContext?.reportValidityAfterScoring === true ? true : false;\n qtiAssessmentItemEl.processResponse(true, reportValidityAfterScoring);\n }\n\n #handleTestUpdateOutcomeVariable(event: CustomEvent) {\n const qtiAssessmentItemEl = this.#assessmentItemFor(event.detail?.assessmentItemRefId);\n if (!qtiAssessmentItemEl) return;\n qtiAssessmentItemEl.setOutcomeVariable(event.detail.outcomeVariableId, event.detail.value);\n }\n\n #handleInteractionChanged(_event: CustomEvent) {\n const itemRefId = this.#itemRefIdOf(_event.composedPath()[0]);\n if (itemRefId) this.#changed.add(itemRefId);\n if (this.autoScoreItems) {\n const assessmentItem = (_event.composedPath()[0] as HTMLElement).closest<QtiAssessmentItem>(\n 'qti-assessment-item'\n );\n // Autoscoring resolves the item from the event's own path, so a change\n // raised outside an assessment item has nothing to score.\n if (!assessmentItem) return;\n const scoreOutcomeIdentifier = assessmentItem.variables.find(v => v.identifier === 'SCORE') as OutcomeVariable;\n if (\n scoreOutcomeIdentifier &&\n scoreOutcomeIdentifier.externalScored === null &&\n assessmentItem.adaptive === 'false'\n ) {\n const reportValidityAfterScoring = this.configContext?.reportValidityAfterScoring === true ? true : false;\n assessmentItem.processResponse(true, reportValidityAfterScoring);\n }\n }\n }\n\n override render() {\n return html`<slot></slot>`;\n }\n\n /* PK: on test connected we can build the computed context */\n #handleTestConnected(event: CustomEvent) {\n this.#testElement = event.detail as QtiAssessmentTest;\n // A fresh test invalidates the per-test optimality latches and item sessions.\n this.#optimality.clear();\n this.#sessions.clear();\n this.#changed.clear();\n // Set the testIdentifier in qtiContext if not already set\n if (!this.qtiContext.QTI_CONTEXT?.testIdentifier) {\n const currentContext = this.qtiContext.QTI_CONTEXT || {\n testIdentifier: '',\n candidateIdentifier: 'not set',\n environmentIdentifier: 'default'\n };\n this.#writeQtiContext({\n QTI_CONTEXT: {\n ...currentContext,\n testIdentifier: this.#testElement.identifier,\n environmentIdentifier: currentContext.environmentIdentifier || 'default'\n }\n });\n }\n\n // Process qti-context-declaration elements to get default values\n const contextDeclarations = this.#testElement.querySelectorAll('qti-context-declaration[identifier=\"QTI_CONTEXT\"]');\n\n contextDeclarations.forEach(declaration => {\n const defaultValues = this.#extractDefaultValues(declaration);\n if (Object.keys(defaultValues).length > 0) {\n // Merge default values with current context, but don't override existing runtime values\n this.#writeQtiContext({\n QTI_CONTEXT: {\n ...defaultValues, // Default values first\n ...this.qtiContext.QTI_CONTEXT // Runtime values override defaults\n }\n });\n }\n });\n\n // The structure and the session-control cascade come from the test's markup, not from upgraded\n // properties, so they do not depend on registration or render timing.\n this.#model = buildTestModel(renderedMarkup(this.#testElement));\n this.computedContext = this.#derive();\n }\n\n /** The test's structure and resolved session control, read from its markup when it is connected. */\n #model?: TestModel;\n\n /** `computedContext`, derived anew from its inputs (`deriveComputedContext`), never from the previous one. */\n #derive(): ComputedContext {\n this.#seedOptimality();\n this.#followSessions();\n return deriveComputedContext({\n model: this.#model,\n itemFacts: this.#itemFacts(),\n testContext: this._testContext,\n sessionContext: this._sessionContext,\n infoItemCategory: this.configContext?.infoItemCategory,\n itemData: this.initContext,\n optimality: this.#optimality,\n lifecycle: new Map([...this.#sessions].map(([identifier, session]) => [identifier, session.state])),\n itemElement: this.#itemElement\n });\n }\n\n /**\n * On a restored session no attempt is ended this run, so the latch is seeded once from the\n * persisted context, which still holds the submitted response. A later change of the answer\n * leaves the seeded value alone.\n */\n #seedOptimality(): void {\n for (const itemContext of this._testContext?.items ?? []) {\n if (!itemContext.identifier || this.#optimality.has(itemContext.identifier)) continue;\n const numAttempts = Number(itemContext.variables?.find(v => v.identifier === 'numAttempts')?.value) || 0;\n if (numAttempts > 0) this.#optimality.set(itemContext.identifier, assessOptimality(itemContext));\n }\n }\n\n /**\n * Extract default values from a qti-context-declaration element\n */\n #extractDefaultValues(declaration: Element): Record<string, any> {\n const defaultValues: Record<string, any> = {};\n\n const defaultValueElement = declaration.querySelector('qti-default-value');\n if (!defaultValueElement) {\n return defaultValues;\n }\n\n const valueElements = defaultValueElement.querySelectorAll('qti-value[field-identifier]');\n valueElements.forEach(valueElement => {\n const fieldIdentifier = valueElement.getAttribute('field-identifier');\n const baseType = valueElement.getAttribute('base-type') || 'string';\n const textContent = valueElement.textContent?.trim() || '';\n\n if (fieldIdentifier) {\n // Convert value based on base-type\n let value: any = textContent;\n switch (baseType) {\n case 'integer':\n value = parseInt(textContent, 10);\n break;\n case 'float':\n case 'duration':\n value = parseFloat(textContent);\n break;\n case 'boolean':\n value = textContent.toLowerCase() === 'true';\n break;\n case 'string':\n default:\n value = textContent;\n break;\n }\n\n defaultValues[fieldIdentifier] = value;\n }\n });\n\n return defaultValues;\n }\n\n /* On every change of the candidate's state, the context is derived again. */\n protected override willUpdate(_changedProperties: PropertyValues): void {\n if (!this.#model) return;\n this.computedContext = this.#derive();\n this.dispatchEvent(\n new CustomEvent('qti-computed-context-updated', {\n detail: this.computedContext,\n bubbles: true\n })\n );\n }\n\n protected override updated(changedProperties: PropertyValues): void {\n super.updated(changedProperties);\n this.#lockUsedItems();\n }\n\n /** The items this navigation disabled because their attempts are used, so it releases only those. */\n #lockedItems = new WeakSet<QtiAssessmentItem>();\n\n /**\n * Disables every rendered item whose session is over (`rules.done`: closed, its attempts used or\n * a completed adaptive item), so the candidate cannot change the answer once the last attempt is\n * ended (QTI info model §2.2.1). Runs after every update: an item rendered later (another item, a\n * section on screen, a restored state) is locked as it arrives, and one whose attempts are back to\n * zero (a new state) is released.\n *\n * Only `disabled = true` is ever set here, and only on an item that was not disabled already; a\n * host or view that disables or makes an item read-only itself keeps it so.\n */\n #lockUsedItems(): void {\n if (!this.#testElement || !this.computedContext) return;\n // In a simultaneous part every item has one attempt, processed when the part ends (QTI info model\n // §2.8.2), so the candidate may change the answer until then: TAO keeps such an item open too.\n const items = new Map(\n this.computedContext.testParts.flatMap(part =>\n part.submissionMode === 'simultaneous'\n ? []\n : part.sections.flatMap(section => section.items.map(item => [item.identifier, item] as const))\n )\n );\n for (const itemRef of this.#testElement.querySelectorAll<QtiAssessmentItemRef>('qti-assessment-item-ref')) {\n const element = itemRef.assessmentItem;\n if (!element) continue;\n // The session is over (closed, or in review or solution). With `auto-score-items` every change\n // is scored as an attempt, so the count is not the candidate's and locks nothing.\n const used = !this.autoScoreItems && items.get(itemRef.identifier)?.rules?.done === true;\n if (used && !element.disabled) {\n element.disabled = true;\n this.#lockedItems.add(element);\n } else if (!used && this.#lockedItems.has(element)) {\n this.#lockedItems.delete(element);\n element.disabled = false;\n }\n }\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'test-navigation': TestNavigation;\n }\n}\n"]}
1
+ {"version":3,"file":"test-navigation.js","sourceRoot":"","sources":["../../../src/components/test-navigation/test-navigation.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,eAAe,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACjE,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAA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,EAAE;IACP,OAAO,CAAC,EAAE,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;uDACX;AAKjC;IAFT,KAAK,EAAE;IACP,OAAO,CAAC,EAAE,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;kDAClB;AAI5B;IAFT,KAAK,EAAE;IACP,OAAO,CAAC,EAAE,OAAO,EAAE,eAAe,EAAE,CAAC;uDACK;AAEiB;IAA3D,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,kBAAkB,EAAE,CAAC;sDAAwB","sourcesContent":["import { ContextConsumer, consume, provide } from '@lit/context';\nimport { html, LitElement } from 'lit';\nimport { property, state } from 'lit/decorators.js';\n\nimport { computedContext } from '@qti-components/base';\nimport {\n buildTestModel,\n endItemAttempt,\n followItemSession,\n itemRefsInOrder,\n readItemFacts,\n seedItemLifecycle\n} from '@qti-components/delivery';\nimport { configContext } from '@qti-components/base';\nimport { testContext } from '@qti-components/base';\nimport { sessionContext } from '@qti-components/base';\nimport { listenPublic as listenItemPublic } from '@qti-components/elements/public-events';\n\nimport { assessOptimality, deriveComputedContext } from '../../internal/derive-computed-context';\nimport { itemFactsContext } from '../../internal/item-facts.context';\nimport { attemptsOf, itemSessionFacts } from '../../internal/item-session-facts';\nimport { renderedMarkup } from '../../internal/rendered-markup';\nimport { testHostContext } from '../../internal/test-host.context';\nimport { listenPublic } from '../../public-events';\nimport { itemsInOrder } from '../../computed-tree';\n\nimport type { QtiAssessmentItem } from '@qti-components/elements';\nimport type { QtiContext } from '@qti-components/base';\nimport type { OutcomeVariable } from '@qti-components/base';\nimport type { ComputedContext, ComputedItem } from '@qti-components/base';\nimport type { PropertyValues } from 'lit';\nimport type { QtiAssessmentItemRef } from '../qti-assessment-item-ref/qti-assessment-item-ref';\nimport type { QtiAssessmentTest } from '../qti-assessment-test/qti-assessment-test';\nimport type { ItemSession, ItemSessionFacts, TestModel } from '@qti-components/delivery';\nimport type { ItemOptimality } from '../../internal/derive-computed-context';\nimport type { ItemFactsByRef } from '../../internal/item-facts.context';\nimport type { LinearNextRefusal, TestHost } from '../../internal/test-host.context';\nimport type { ConfigContext } from '@qti-components/base';\nimport type { SessionContext } from '@qti-components/base';\nimport type { TestContext } from '@qti-components/base';\nimport type { ItemContext } from '@qti-components/base';\n\n/** A new object each time: a host that mutates the one it read must not change anyone else's. */\nconst newQtiContext = (): QtiContext => ({\n QTI_CONTEXT: { testIdentifier: '', candidateIdentifier: '', environmentIdentifier: 'default' }\n});\n\nexport class TestNavigation extends LitElement {\n @property({ type: String }) identifier: string | undefined = undefined;\n\n /**\n * Your own per-item fields, by item-ref `identifier`: each `computedContext` item carries them as\n * given under `data`, without the identifier, and so does every view of it a plugin derives. They\n * never replace a field the test, the item or the candidate's state gives, whatever its name; a\n * template reads `activeItem.data.<field>`. To mark an item as scored by hand, set\n * `external-scored` on its `SCORE` declaration in `postLoadTransformCallback`.\n */\n @state()\n public initContext: { identifier: string; [key: string]: any }[] = [];\n\n /**\n * @deprecated Set `qtiContext` on `qti-test`, which provides it. This is an alias for the\n * enclosing test's: reading returns it, writing replaces it, so a host that has always set the\n * shuffle seed here keeps working. Removed in the next major.\n *\n * Written before the navigation is inside a test, it waits and is handed over on connect.\n */\n public get qtiContext(): QtiContext {\n return this.#owner()?.qtiContext ?? (this.#pendingQtiContext ??= newQtiContext());\n }\n\n public set qtiContext(value: QtiContext) {\n if (!this.#warnedQtiContext) {\n this.#warnedQtiContext = true;\n console.warn(\n '[qti-components] `test-navigation.qtiContext` is deprecated and will be removed in the next major ' +\n 'release. Set `qtiContext` on `<qti-test>` instead; it is the same value.'\n );\n }\n this.#writeQtiContext(value);\n }\n\n #pendingQtiContext?: QtiContext;\n #warnedQtiContext = false;\n\n /** The write the library itself makes. Not the deprecated setter, so it never warns about itself. */\n #writeQtiContext(value: QtiContext): void {\n const owner = this.#owner();\n if (owner) owner.qtiContext = value;\n else this.#pendingQtiContext = value;\n }\n\n /**\n * The `qti-test` this navigation is in, found through context so it works across shadow roots.\n * A write made before it is known waits in `#pendingQtiContext` and is handed over on arrival.\n */\n #testHost = new ContextConsumer(this, {\n context: testHostContext,\n subscribe: true,\n callback: host => {\n if (host && this.#pendingQtiContext) {\n host.qtiContext = this.#pendingQtiContext;\n this.#pendingQtiContext = undefined;\n }\n if (host) this.#registerLinearNext(host);\n }\n });\n\n /** The `qti-test` this navigation answers Next for in a linear part. */\n #linearNextHost?: TestHost;\n\n #registerLinearNext(host: TestHost): void {\n if (this.#linearNextHost && this.#linearNextHost !== host) this.#linearNextHost.beforeLinearNext = null;\n this.#linearNextHost = host;\n host.beforeLinearNext = this.#beforeLinearNext;\n }\n\n override connectedCallback(): void {\n super.connectedCallback();\n if (this.#linearNextHost) this.#linearNextHost.beforeLinearNext = this.#beforeLinearNext;\n }\n\n override disconnectedCallback(): void {\n super.disconnectedCallback();\n if (this.#linearNextHost?.beforeLinearNext === this.#beforeLinearNext) this.#linearNextHost.beforeLinearNext = null;\n }\n\n /**\n * Next in a linear individual part leaves the item for good (implementation guide §4.1), so it\n * submits what the candidate gave (decided 2026-11-27): refused while the session control refuses\n * those responses (`rules.maySubmit`), else the attempt is ended when one is open: none ended yet,\n * or the responses changed since the last. Called by the navigation mixin while the item is still\n * rendered; the item is closed when the navigation moves past it.\n */\n #beforeLinearNext = (itemRefId: string): LinearNextRefusal | null => {\n const part = this.#model?.testParts.find(testPart =>\n itemRefsInOrder(testPart.sections).some(item => item.identifier === itemRefId)\n );\n if (part?.navigationMode !== 'linear' || part.submissionMode !== 'individual') return null;\n const session = this.#sessions.get(itemRefId);\n const rules = this.computedItemFor(itemRefId)?.rules;\n if (session?.state !== 'interacting' || !rules) return null;\n if (!rules.maySubmit) {\n return { reason: rules.maySkip ? 'validate-responses' : 'allow-skipping', itemId: itemRefId };\n }\n if (session.numAttempts === 0 || this.#changed.has(itemRefId)) {\n this.#assessmentItemFor(itemRefId)?.processResponse(\n true,\n this.configContext?.reportValidityAfterScoring === true\n );\n }\n return null;\n };\n\n /** The item-refs whose responses changed since their last ended attempt. */\n #changed = new Set<string>();\n\n #itemRefIdOf(element: EventTarget | undefined): string | undefined {\n const item = (element as HTMLElement | undefined)?.closest?.('qti-assessment-item');\n if (!item) return undefined;\n return [...(this.#testElement?.querySelectorAll<QtiAssessmentItemRef>('qti-assessment-item-ref') ?? [])].find(\n itemRef => itemRef.assessmentItem === item\n )?.identifier;\n }\n\n #owner(): { qtiContext: QtiContext } | null {\n return this.#testHost.value ?? null;\n }\n\n @state()\n @consume({ context: configContext, subscribe: true })\n public configContext: ConfigContext = {};\n\n @state()\n @consume({ context: testContext, subscribe: true })\n protected _testContext?: TestContext;\n\n @state()\n @consume({ context: sessionContext, subscribe: true })\n protected _sessionContext?: SessionContext;\n\n /** Read from each item's XML when `qti-test` fetches it; see `itemFactsContext`. */\n @state()\n @consume({ context: itemFactsContext, subscribe: true })\n protected _itemFacts?: ItemFactsByRef;\n\n @state()\n @provide({ context: computedContext })\n protected computedContext: ComputedContext;\n\n @property({ type: Boolean, attribute: 'auto-score-items' }) autoScoreItems = false;\n\n #testElement: QtiAssessmentTest;\n\n /**\n * Whether each item's last *ended attempt* reached the optimal outcome, keyed\n * by item-ref id. Written from #handleItemContextUpdated when processResponse\n * ends an attempt — never on a plain selection. Mirrors how inline feedback\n * only re-evaluates when an attempt is processed, so a freshly-picked answer\n * doesn't flip `done` until the candidate ends the attempt.\n */\n #optimality = new Map<string, ItemOptimality>();\n\n /**\n * Each item session's lifecycle state, by item-ref identifier, changed only through the lifecycle\n * table (`followItemSession` as the candidate moves, `endItemAttempt` when an attempt ends). It\n * lives here until `DeliveryState` holds it (roadmap 1, T3d); a session whose attempts change\n * outside an ended attempt (a restored or assigned state) is seeded again.\n */\n #sessions = new Map<string, ItemSession>();\n\n constructor() {\n super();\n listenPublic(this, 'qc-test-loaded', this.#handleTestConnected.bind(this));\n\n listenItemPublic(this, 'qc-item-response-changed', this.#handleInteractionChanged.bind(this));\n this.addEventListener('qti-item-context-updated', this.#handleItemContextUpdated.bind(this));\n\n listenPublic(this, 'qc-test-end-attempt', this.#handleTestEndAttempt.bind(this));\n listenPublic(this, 'qc-test-update-outcome', this.#handleTestUpdateOutcomeVariable.bind(this));\n listenPublic(this, 'qc-test-update-comment', this.#handleUpdateComment.bind(this));\n }\n\n /**\n * Sets the candidate's comment on an item when its session allows it (`rules.mayComment`:\n * `allow-comment`, while interacting; decided 2026-11-27, carried, not rendered).\n */\n #handleUpdateComment(event: CustomEvent<{ itemId: string; comment: string | null }>) {\n const { itemId, comment = null } = event.detail ?? ({} as { itemId?: string; comment?: string | null });\n const host = this.#testHost.value;\n if (!itemId || !host) return;\n if (comment !== null && typeof comment !== 'string') {\n console.warn(`[qti-test] Ignoring a comment for \"${itemId}\" that is not a string.`);\n return;\n }\n if (!this.computedItemFor(itemId)?.rules?.mayComment) {\n console.warn(\n `[qti-test] Ignoring a comment for \"${itemId}\": its allow-comment is false, or it is not interacting.`\n );\n return;\n }\n host.updateItemComment(itemId, comment);\n }\n\n /**\n * Latch whether an item reached its optimal outcome whenever it has just ended\n * an attempt. processResponse — fired by test-end-attempt, autoscore, or an\n * in-item end-attempt interaction — flags its context update with\n * `responseProcessed`; a plain selection updates the context without it, so\n * `done` can't flip until the candidate actually ends the attempt.\n */\n #handleItemContextUpdated(event: CustomEvent<{ itemContext: ItemContext; responseProcessed?: boolean }>) {\n if (!event.detail?.responseProcessed) return;\n const itemContext = event.detail.itemContext;\n if (!itemContext?.identifier) return;\n this.#optimality.set(itemContext.identifier, assessOptimality(itemContext));\n this.#changed.delete(itemContext.identifier);\n this.#endAttempt(itemContext);\n\n const computedItem = this.computedItemFor(itemContext.identifier);\n this.afterAttemptEnded(\n (event.composedPath()[0] as HTMLElement)?.closest<QtiAssessmentItem>('qti-assessment-item'),\n computedItem,\n this.#doneAfterAttempt(itemContext, computedItem)\n );\n }\n\n /**\n * Moves the item's session on for its ended attempt. With `auto-score-items` every change is\n * scored as an attempt, so the count is not the candidate's: it is taken, and the state stays.\n */\n #endAttempt(itemContext: ItemContext): void {\n const facts = this.#sessionFacts().get(itemContext.identifier);\n if (!facts) return;\n const ended: ItemSessionFacts = { ...facts, ...attemptsOf(itemContext) };\n const previous = this.#sessions.get(itemContext.identifier);\n this.#sessions.set(\n itemContext.identifier,\n this.autoScoreItems\n ? {\n state: previous?.state ?? followItemSession(undefined, ended).state,\n numAttempts: ended.numAttempts,\n adaptive: ended.adaptive\n }\n : endItemAttempt(previous, ended)\n );\n }\n\n /**\n * Whether the item session is over after the attempt that just ended: its new state, or, before\n * the test model is known, the state an item on screen with these attempts is in.\n */\n #doneAfterAttempt(itemContext: ItemContext, computedItem: ComputedItem | undefined): boolean {\n const state =\n this.#sessions.get(itemContext.identifier)?.state ??\n (computedItem?.sessionControl\n ? seedItemLifecycle({\n sessionControl: computedItem.sessionControl,\n adaptive: computedItem.adaptive ?? false,\n ...attemptsOf(itemContext),\n presented: true,\n passed: false\n })\n : 'interacting');\n return state === 'closed' || state === 'review' || state === 'solution';\n }\n\n /** The facts of every item session now: the model, the item facts, the contexts and the items on screen. */\n #sessionFacts(): Map<string, ItemSessionFacts> {\n if (!this.#model) return new Map();\n const presented = new Set(\n [...(this.#testElement?.querySelectorAll<QtiAssessmentItemRef>('qti-assessment-item-ref') ?? [])]\n .filter(itemRef => itemRef.assessmentItem)\n .map(itemRef => itemRef.identifier)\n );\n return itemSessionFacts(this.#model, this.#itemFacts(), this._testContext?.items, {\n current: this._sessionContext?.navItemRefId,\n presented\n });\n }\n\n /**\n * The item facts `qti-test` read from each fetched item, and, for an item rendered without them\n * (handed to its ref directly), the facts read from the rendered item.\n */\n #itemFacts(): ItemFactsByRef | undefined {\n const missing = [\n ...(this.#testElement?.querySelectorAll<QtiAssessmentItemRef>('qti-assessment-item-ref') ?? [])\n ].filter(\n itemRef =>\n itemRef.assessmentItem?.localName === 'qti-assessment-item' && !this._itemFacts?.has(itemRef.identifier)\n );\n if (!missing.length) return this._itemFacts;\n const facts = new Map(this._itemFacts ?? []);\n for (const itemRef of missing) facts.set(itemRef.identifier, readItemFacts(renderedMarkup(itemRef.assessmentItem)));\n return facts;\n }\n\n /** Moves every item session on for where the candidate is now. */\n #followSessions(): void {\n for (const [identifier, facts] of this.#sessionFacts()) {\n this.#sessions.set(identifier, followItemSession(this.#sessions.get(identifier), facts));\n }\n }\n\n /**\n * Extension point for presentation packages reacting to an ended attempt. `done` is the item\n * session's after this attempt (closed: its attempts used, whatever the score), settled here\n * because the computed context only catches up on the next update.\n */\n protected afterAttemptEnded(\n _assessmentItem: QtiAssessmentItem | undefined,\n _computedItem: ComputedItem | undefined,\n _done: boolean\n ): void {}\n\n /** The computed-context entry for an item, from the session-control cascade. */\n protected computedItemFor(identifier: string): ComputedItem | undefined {\n return this.computedContext?.testParts.flatMap(itemsInOrder).find(i => i.instance === identifier);\n }\n\n /** The assessment item for an item-ref id, if it has been rendered. */\n #assessmentItemFor(identifier: string | undefined): QtiAssessmentItem | undefined {\n if (!identifier) return undefined;\n const itemRef = this.#testElement?.querySelector<QtiAssessmentItemRef>(\n `qti-assessment-item-ref[identifier=\"${CSS.escape(identifier)}\"]`\n );\n return itemRef?.assessmentItem ?? undefined;\n }\n\n /** `computedContext.itemElement`: one function for the life of this element, carried along by every update. */\n #itemElement = (identifier: string): HTMLElement | null => this.#assessmentItemFor(identifier) ?? null;\n\n /** The currently active assessment item, exposed for optional presentation extensions. */\n protected get activeAssessmentItem(): QtiAssessmentItem | undefined {\n if (!this.#testElement || !this._sessionContext?.navItemRefId) return undefined;\n return this.#testElement.querySelector<QtiAssessmentItemRef>(\n `qti-assessment-item-ref[identifier=\"${this._sessionContext.navItemRefId}\"]`\n )?.assessmentItem;\n }\n\n /**\n * Ends an attempt: the item named by `detail.itemId` (a `test-end-attempt` stamped into an item, or\n * given an `item`), or else the item on screen.\n */\n #handleTestEndAttempt(event: CustomEvent<{ itemId?: string } | undefined>) {\n const itemId = event.detail?.itemId;\n const qtiAssessmentItemEl = itemId ? this.#assessmentItemFor(itemId) : this.activeAssessmentItem;\n if (!qtiAssessmentItemEl) return;\n const reportValidityAfterScoring = this.configContext?.reportValidityAfterScoring === true ? true : false;\n qtiAssessmentItemEl.processResponse(true, reportValidityAfterScoring);\n }\n\n #handleTestUpdateOutcomeVariable(event: CustomEvent) {\n const qtiAssessmentItemEl = this.#assessmentItemFor(event.detail?.assessmentItemRefId);\n if (!qtiAssessmentItemEl) return;\n qtiAssessmentItemEl.setOutcomeVariable(event.detail.outcomeVariableId, event.detail.value);\n }\n\n #handleInteractionChanged(_event: CustomEvent) {\n const itemRefId = this.#itemRefIdOf(_event.composedPath()[0]);\n if (itemRefId) this.#changed.add(itemRefId);\n if (this.autoScoreItems) {\n const assessmentItem = (_event.composedPath()[0] as HTMLElement).closest<QtiAssessmentItem>(\n 'qti-assessment-item'\n );\n // Autoscoring resolves the item from the event's own path, so a change\n // raised outside an assessment item has nothing to score.\n if (!assessmentItem) return;\n const scoreOutcomeIdentifier = assessmentItem.variables.find(v => v.identifier === 'SCORE') as OutcomeVariable;\n if (\n scoreOutcomeIdentifier &&\n scoreOutcomeIdentifier.externalScored === null &&\n assessmentItem.adaptive === 'false'\n ) {\n const reportValidityAfterScoring = this.configContext?.reportValidityAfterScoring === true ? true : false;\n assessmentItem.processResponse(true, reportValidityAfterScoring);\n }\n }\n }\n\n override render() {\n return html`<slot></slot>`;\n }\n\n /* PK: on test connected we can build the computed context */\n #handleTestConnected(event: CustomEvent) {\n this.#testElement = event.detail as QtiAssessmentTest;\n // A fresh test invalidates the per-test optimality latches and item sessions.\n this.#optimality.clear();\n this.#sessions.clear();\n this.#changed.clear();\n // Set the testIdentifier in qtiContext if not already set\n if (!this.qtiContext.QTI_CONTEXT?.testIdentifier) {\n const currentContext = this.qtiContext.QTI_CONTEXT || {\n testIdentifier: '',\n candidateIdentifier: 'not set',\n environmentIdentifier: 'default'\n };\n this.#writeQtiContext({\n QTI_CONTEXT: {\n ...currentContext,\n testIdentifier: this.#testElement.identifier,\n environmentIdentifier: currentContext.environmentIdentifier || 'default'\n }\n });\n }\n\n // Process qti-context-declaration elements to get default values\n const contextDeclarations = this.#testElement.querySelectorAll('qti-context-declaration[identifier=\"QTI_CONTEXT\"]');\n\n contextDeclarations.forEach(declaration => {\n const defaultValues = this.#extractDefaultValues(declaration);\n if (Object.keys(defaultValues).length > 0) {\n // Merge default values with current context, but don't override existing runtime values\n this.#writeQtiContext({\n QTI_CONTEXT: {\n ...defaultValues, // Default values first\n ...this.qtiContext.QTI_CONTEXT // Runtime values override defaults\n }\n });\n }\n });\n\n // The structure and the session-control cascade come from the test's markup, not from upgraded\n // properties, so they do not depend on registration or render timing.\n this.#model = buildTestModel(renderedMarkup(this.#testElement));\n this.computedContext = this.#derive();\n }\n\n /** The test's structure and resolved session control, read from its markup when it is connected. */\n #model?: TestModel;\n\n /** `computedContext`, derived anew from its inputs (`deriveComputedContext`), never from the previous one. */\n #derive(): ComputedContext {\n this.#seedOptimality();\n this.#followSessions();\n return deriveComputedContext({\n model: this.#model,\n itemFacts: this.#itemFacts(),\n testContext: this._testContext,\n sessionContext: this._sessionContext,\n infoItemCategory: this.configContext?.infoItemCategory,\n itemData: this.initContext,\n optimality: this.#optimality,\n lifecycle: new Map([...this.#sessions].map(([identifier, session]) => [identifier, session.state])),\n itemElement: this.#itemElement\n });\n }\n\n /**\n * On a restored session no attempt is ended this run, so the latch is seeded once from the\n * persisted context, which still holds the submitted response. A later change of the answer\n * leaves the seeded value alone.\n */\n #seedOptimality(): void {\n for (const itemContext of this._testContext?.items ?? []) {\n if (!itemContext.identifier || this.#optimality.has(itemContext.identifier)) continue;\n const numAttempts = Number(itemContext.variables?.find(v => v.identifier === 'numAttempts')?.value) || 0;\n if (numAttempts > 0) this.#optimality.set(itemContext.identifier, assessOptimality(itemContext));\n }\n }\n\n /**\n * Extract default values from a qti-context-declaration element\n */\n #extractDefaultValues(declaration: Element): Record<string, any> {\n const defaultValues: Record<string, any> = {};\n\n const defaultValueElement = declaration.querySelector('qti-default-value');\n if (!defaultValueElement) {\n return defaultValues;\n }\n\n const valueElements = defaultValueElement.querySelectorAll('qti-value[field-identifier]');\n valueElements.forEach(valueElement => {\n const fieldIdentifier = valueElement.getAttribute('field-identifier');\n const baseType = valueElement.getAttribute('base-type') || 'string';\n const textContent = valueElement.textContent?.trim() || '';\n\n if (fieldIdentifier) {\n // Convert value based on base-type\n let value: any = textContent;\n switch (baseType) {\n case 'integer':\n value = parseInt(textContent, 10);\n break;\n case 'float':\n case 'duration':\n value = parseFloat(textContent);\n break;\n case 'boolean':\n value = textContent.toLowerCase() === 'true';\n break;\n case 'string':\n default:\n value = textContent;\n break;\n }\n\n defaultValues[fieldIdentifier] = value;\n }\n });\n\n return defaultValues;\n }\n\n /* On every change of the candidate's state, the context is derived again. */\n protected override willUpdate(_changedProperties: PropertyValues): void {\n if (!this.#model) return;\n this.computedContext = this.#derive();\n this.dispatchEvent(\n new CustomEvent('qti-computed-context-updated', {\n detail: this.computedContext,\n bubbles: true\n })\n );\n }\n\n protected override updated(changedProperties: PropertyValues): void {\n super.updated(changedProperties);\n this.#lockUsedItems();\n }\n\n /** The items this navigation disabled because their attempts are used, so it releases only those. */\n #lockedItems = new WeakSet<QtiAssessmentItem>();\n\n /**\n * Disables every rendered item whose session is over (`rules.done`: closed, its attempts used or\n * a completed adaptive item), so the candidate cannot change the answer once the last attempt is\n * ended (QTI info model §2.2.1). Runs after every update: an item rendered later (another item, a\n * section on screen, a restored state) is locked as it arrives, and one whose attempts are back to\n * zero (a new state) is released.\n *\n * Only `disabled = true` is ever set here, and only on an item that was not disabled already; a\n * host or view that disables or makes an item read-only itself keeps it so.\n */\n #lockUsedItems(): void {\n if (!this.#testElement || !this.computedContext) return;\n // In a simultaneous part every item has one attempt, processed when the part ends (QTI info model\n // §2.8.2), so the candidate may change the answer until then: TAO keeps such an item open too.\n const items = new Map(\n this.computedContext.testParts.flatMap(part =>\n part.submissionMode === 'simultaneous' ? [] : itemsInOrder(part).map(item => [item.instance, item] as const)\n )\n );\n for (const itemRef of this.#testElement.querySelectorAll<QtiAssessmentItemRef>('qti-assessment-item-ref')) {\n const element = itemRef.assessmentItem;\n if (!element) continue;\n // The session is over (closed, or in review or solution). With `auto-score-items` every change\n // is scored as an attempt, so the count is not the candidate's and locks nothing.\n const used = !this.autoScoreItems && items.get(itemRef.identifier)?.rules?.done === true;\n if (used && !element.disabled) {\n element.disabled = true;\n this.#lockedItems.add(element);\n } else if (!used && this.#lockedItems.has(element)) {\n this.#lockedItems.delete(element);\n element.disabled = false;\n }\n }\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'test-navigation': TestNavigation;\n }\n}\n"]}
@@ -12,7 +12,7 @@ import { computedContext } from '@qti-components/base';
12
12
  import { navigationRules } from '@qti-components/delivery';
13
13
  import * as styles from '../styles';
14
14
  import { dispatchPublic } from '../../public-events';
15
- import { itemsInOrder } from '../../items-in-order';
15
+ import { activeTestPart, itemsInOrder } from '../../computed-tree';
16
16
  /**
17
17
  * Represents a custom element for navigating to the next test item.
18
18
  *
@@ -44,7 +44,7 @@ export class TestNext extends LitElement {
44
44
  this.addEventListener('click', e => {
45
45
  e.preventDefault();
46
46
  if (!this._internalDisabled)
47
- this._requestItem(this.sectionItems[this.itemIndex + 1].identifier);
47
+ this._requestItem(this.sectionItems[this.itemIndex + 1].instance);
48
48
  });
49
49
  }
50
50
  connectedCallback() {
@@ -54,7 +54,7 @@ export class TestNext extends LitElement {
54
54
  willUpdate(_changedProperties) {
55
55
  if (!this.computedContext)
56
56
  return;
57
- const testPart = this.computedContext?.testParts.find(testPart => testPart.active);
57
+ const testPart = activeTestPart(this.computedContext);
58
58
  if (!testPart)
59
59
  return;
60
60
  this.sectionItems = itemsInOrder(testPart);
@@ -62,7 +62,7 @@ export class TestNext extends LitElement {
62
62
  this.checkDisabled();
63
63
  }
64
64
  checkDisabled() {
65
- const testPart = this.computedContext?.testParts.find(testPart => testPart.active);
65
+ const testPart = activeTestPart(this.computedContext);
66
66
  if (!testPart)
67
67
  return;
68
68
  const current = this.sectionItems?.[this.itemIndex]?.rules;
@@ -1 +1 @@
1
- {"version":3,"file":"test-next.js","sourceRoot":"","sources":["../../../src/components/test-next/test-next.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,KAAK,EAAE,MAAM,2BAA2B,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAE3D,OAAO,KAAK,MAAM,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAIpD;;;;;;;;;;;;;GAaG;AAEH,MAAM,OAAO,QAAS,SAAQ,UAAU;IAWtC,wBAAwB,CAAC,SAA0B,EAAE,QAAyB;QAC5E,IAAI,QAAQ,EAAE,CAAC;YACb,IAAI,CAAC,aAAa,EAAE,CAAC;QACvB,CAAC;IACH,CAAC;aAEe,WAAM,GAAG,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,aAAa,CAAC,AAAxC,CAAyC;IAC/D,UAAU,CAAmB;IAE7B;QACE,KAAK,EAAE,CAAC;QAnBH,sBAAiB,GAAG,IAAI,CAAC;QAqB9B,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,eAAe,EAAE,CAAC;QACzC,IAAI,CAAC,UAAU,CAAC,IAAI,GAAG,QAAQ,CAAC;QAChC,IAAI,CAAC,UAAU,CAAC,SAAS,GAAG,WAAW,CAAC;QAExC,IAAI,CAAC,gBAAgB,CAAC,OAAO,EAAE,CAAC,CAAC,EAAE;YACjC,CA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AK,EAAE,IAAI,CAAC,SAAS;YACrB,KAAK,EAAE,IAAI,CAAC,YAAY,EAAE,MAAM,IAAI,CAAC;YACrC,OAAO,EAAE,EAAE,SAAS,EAAE,OAAO,EAAE,SAAS,IAAI,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,WAAW,IAAI,KAAK,EAAE;SAC/F,CAAC,CAAC;QACH,IAAI,CAAC,iBAAiB,GAAG,CAAC,IAAI,CAAC,eAAe,IAAI,CAAC,SAAS,CAAC;IAC/D,CAAC;IAES,YAAY,CAAC,UAAkB;QACvC,cAAc,CAAC,IAAI,EAAE,kBAAkB,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,UAAU,EAAE,CAAC,CAAC;IAC7E,CAAC;IAEQ,MAAM;QACb,OAAO,MAAM,CAAC,OAAO,CAAC;IACxB,CAAC;;AAnEM;IADN,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,UAAU,EAAE,CAAC;mDAClC;AAGtB;IADT,OAAO,CAAC,EAAE,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;iDACZ;AAM3C;IADC,KAAK,CAAC,iBAAiB,CAAC;wDAKxB","sourcesContent":["import { LitElement } from 'lit';\nimport { property } from 'lit/decorators.js';\nimport { consume } from '@lit/context';\n\nimport { watch } from '@qti-components/utilities';\nimport { computedContext } from '@qti-components/base';\nimport { navigationRules } from '@qti-components/delivery';\n\nimport * as styles from '../styles';\nimport { dispatchPublic } from '../../public-events';\nimport { itemsInOrder } from '../../items-in-order';\n\nimport type { ComputedContext, ComputedItem } from '@qti-components/base';\n\n/**\n * Represents a custom element for navigating to the next test item.\n *\n * @remarks\n * Disabled on the last item of the part, and, in a linear part with individual submission, while\n * the current item's answer may not be submitted (`allow-skipping=\"false\"` with no answer,\n * `validate-responses` with an invalid one). In that part Next ends the attempt the candidate did not\n * end and leaves the item for good (implementation guide §4.1); the score never holds it back.\n *\n * @example\n * ```html\n * <test-next></test-next>\n * ```\n */\n\nexport class TestNext extends LitElement {\n @property({ type: Boolean, reflect: true, attribute: 'disabled' })\n public _internalDisabled = true;\n\n @consume({ context: computedContext, subscribe: true })\n protected computedContext: ComputedContext;\n\n sectionItems: ComputedItem[];\n itemIndex: number;\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, styles.buttonPrimary];\n #internals: ElementInternals;\n\n constructor() {\n super();\n\n this.#internals = this.attachInternals();\n this.#internals.role = 'button';\n this.#internals.ariaLabel = 'Next item';\n\n this.addEventListener('click', e => {\n e.preventDefault();\n if (!this._internalDisabled) this._requestItem(this.sectionItems[this.itemIndex + 1].identifier);\n });\n }\n\n override connectedCallback(): void {\n super.connectedCallback();\n this.checkDisabled();\n }\n\n override willUpdate(_changedProperties: Map<string | number | symbol, unknown>) {\n if (!this.computedContext) return;\n const testPart = this.computedContext?.testParts.find(testPart => testPart.active);\n if (!testPart) return;\n this.sectionItems = itemsInOrder(testPart);\n this.itemIndex = this.sectionItems.findIndex(item => item.active);\n this.checkDisabled();\n }\n\n checkDisabled() {\n const testPart = this.computedContext?.testParts.find(testPart => testPart.active);\n if (!testPart) return;\n const current = this.sectionItems?.[this.itemIndex]?.rules;\n // In a linear individual part Next ends the attempt and leaves the item for good, so it waits\n // while the item's responses may not be submitted (`allow-skipping`, `validate-responses`).\n const { mayGoNext } = navigationRules({\n navigationMode: testPart.navigationMode,\n submissionMode: testPart.submissionMode,\n index: this.itemIndex,\n count: this.sectionItems?.length ?? 0,\n current: { maySubmit: current?.maySubmit ?? true, interactive: current?.interactive ?? false }\n });\n this._internalDisabled = !this.computedContext || !mayGoNext;\n }\n\n protected _requestItem(identifier: string): void {\n dispatchPublic(this, 'qc-test-navigate', { type: 'item', id: identifier });\n }\n\n override render() {\n return styles.control;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'test-next': TestNext;\n }\n}\n"]}
1
+ {"version":3,"file":"test-next.js","sourceRoot":"","sources":["../../../src/components/test-next/test-next.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,KAAK,EAAE,MAAM,2BAA2B,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAE3D,OAAO,KAAK,MAAM,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAInE;;;;;;;;;;;;;GAaG;AAEH,MAAM,OAAO,QAAS,SAAQ,UAAU;IAWtC,wBAAwB,CAAC,SAA0B,EAAE,QAAyB;QAC5E,IAAI,QAAQ,EAAE,CAAC;YACb,IAAI,CAAC,aAAa,EAAE,CAAC;QACvB,CAAC;IACH,CAAC;aAEe,WAAM,GAAG,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,aAAa,CAAC,AAAxC,CAAyC;IAC/D,UAAU,CAAmB;IAE7B;QACE,KAAK,EAAE,CAAC;QAnBH,sBAAiB,GAAG,IAAI,CAAC;QAqB9B,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,eAAe,EAAE,CAAC;QACzC,IAAI,CAAC,UAAU,CAAC,IAAI,GAAG,QAAQ,CAAC;QAChC,IAAI,CAAC,UAAU,CAAC,SAAS,GAAG,WAAW,CAAC;QAExC,IAAI,CAAC,gBAAgB,CAAC,OAAO,EAAE,CAAC,CAAC,EAAE;YACjC,CAAC,CAAC,cAAc,EAAE,CAAC;YACnB,IAAI,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W,EAAE,OAAO,EAAE,WAAW,IAAI,KAAK,EAAE;SAC/F,CAAC,CAAC;QACH,IAAI,CAAC,iBAAiB,GAAG,CAAC,IAAI,CAAC,eAAe,IAAI,CAAC,SAAS,CAAC;IAC/D,CAAC;IAES,YAAY,CAAC,UAAkB;QACvC,cAAc,CAAC,IAAI,EAAE,kBAAkB,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,UAAU,EAAE,CAAC,CAAC;IAC7E,CAAC;IAEQ,MAAM;QACb,OAAO,MAAM,CAAC,OAAO,CAAC;IACxB,CAAC;;AAnEM;IADN,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,UAAU,EAAE,CAAC;mDAClC;AAGtB;IADT,OAAO,CAAC,EAAE,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;iDACZ;AAM3C;IADC,KAAK,CAAC,iBAAiB,CAAC;wDAKxB","sourcesContent":["import { LitElement } from 'lit';\nimport { property } from 'lit/decorators.js';\nimport { consume } from '@lit/context';\n\nimport { watch } from '@qti-components/utilities';\nimport { computedContext } from '@qti-components/base';\nimport { navigationRules } from '@qti-components/delivery';\n\nimport * as styles from '../styles';\nimport { dispatchPublic } from '../../public-events';\nimport { activeTestPart, itemsInOrder } from '../../computed-tree';\n\nimport type { ComputedContext, ComputedItem } from '@qti-components/base';\n\n/**\n * Represents a custom element for navigating to the next test item.\n *\n * @remarks\n * Disabled on the last item of the part, and, in a linear part with individual submission, while\n * the current item's answer may not be submitted (`allow-skipping=\"false\"` with no answer,\n * `validate-responses` with an invalid one). In that part Next ends the attempt the candidate did not\n * end and leaves the item for good (implementation guide §4.1); the score never holds it back.\n *\n * @example\n * ```html\n * <test-next></test-next>\n * ```\n */\n\nexport class TestNext extends LitElement {\n @property({ type: Boolean, reflect: true, attribute: 'disabled' })\n public _internalDisabled = true;\n\n @consume({ context: computedContext, subscribe: true })\n protected computedContext: ComputedContext;\n\n sectionItems: ComputedItem[];\n itemIndex: number;\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, styles.buttonPrimary];\n #internals: ElementInternals;\n\n constructor() {\n super();\n\n this.#internals = this.attachInternals();\n this.#internals.role = 'button';\n this.#internals.ariaLabel = 'Next item';\n\n this.addEventListener('click', e => {\n e.preventDefault();\n if (!this._internalDisabled) this._requestItem(this.sectionItems[this.itemIndex + 1].instance);\n });\n }\n\n override connectedCallback(): void {\n super.connectedCallback();\n this.checkDisabled();\n }\n\n override willUpdate(_changedProperties: Map<string | number | symbol, unknown>) {\n if (!this.computedContext) return;\n const testPart = activeTestPart(this.computedContext);\n if (!testPart) return;\n this.sectionItems = itemsInOrder(testPart);\n this.itemIndex = this.sectionItems.findIndex(item => item.active);\n this.checkDisabled();\n }\n\n checkDisabled() {\n const testPart = activeTestPart(this.computedContext);\n if (!testPart) return;\n const current = this.sectionItems?.[this.itemIndex]?.rules;\n // In a linear individual part Next ends the attempt and leaves the item for good, so it waits\n // while the item's responses may not be submitted (`allow-skipping`, `validate-responses`).\n const { mayGoNext } = navigationRules({\n navigationMode: testPart.navigationMode,\n submissionMode: testPart.submissionMode,\n index: this.itemIndex,\n count: this.sectionItems?.length ?? 0,\n current: { maySubmit: current?.maySubmit ?? true, interactive: current?.interactive ?? false }\n });\n this._internalDisabled = !this.computedContext || !mayGoNext;\n }\n\n protected _requestItem(identifier: string): void {\n dispatchPublic(this, 'qc-test-navigate', { type: 'item', id: identifier });\n }\n\n override render() {\n return styles.control;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'test-next': TestNext;\n }\n}\n"]}
@@ -12,7 +12,7 @@ import { computedContext } from '@qti-components/base';
12
12
  import { navigationRules } from '@qti-components/delivery';
13
13
  import * as styles from '../styles';
14
14
  import { dispatchPublic } from '../../public-events';
15
- import { itemsInOrder } from '../../items-in-order';
15
+ import { activeTestPart, itemsInOrder } from '../../computed-tree';
16
16
  /**
17
17
  * Represents a custom element for navigating to the previous test item.
18
18
  *
@@ -37,13 +37,13 @@ export class TestPrev extends LitElement {
37
37
  this.addEventListener('click', e => {
38
38
  e.preventDefault();
39
39
  if (!this._internalDisabled)
40
- this._requestItem(this.sectionItems[this.itemIndex - 1].identifier);
40
+ this._requestItem(this.sectionItems[this.itemIndex - 1].instance);
41
41
  });
42
42
  }
43
43
  willUpdate(_changedProperties) {
44
44
  if (!this.computedContext)
45
45
  return;
46
- const testPart = this.computedContext?.testParts.find(testPart => testPart.active);
46
+ const testPart = activeTestPart(this.computedContext);
47
47
  if (!testPart)
48
48
  return;
49
49
  this.sectionItems = itemsInOrder(testPart);
@@ -51,7 +51,7 @@ export class TestPrev extends LitElement {
51
51
  this.checkDisabled();
52
52
  }
53
53
  checkDisabled() {
54
- const testPart = this.computedContext?.testParts.find(testPart => testPart.active);
54
+ const testPart = activeTestPart(this.computedContext);
55
55
  // A linear part never goes back (implementation guide §4.1).
56
56
  const { mayGoPrevious } = navigationRules({
57
57
  navigationMode: testPart?.navigationMode ?? 'nonlinear',
@@ -1 +1 @@
1
- {"version":3,"file":"test-prev.js","sourceRoot":"","sources":["../../../src/components/test-prev/test-prev.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,KAAK,EAAE,MAAM,2BAA2B,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAE3D,OAAO,KAAK,MAAM,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EA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AAM,CAAC,CAAC;QACnF,6DAA6D;QAC7D,MAAM,EAAE,aAAa,EAAE,GAAG,eAAe,CAAC;YACxC,cAAc,EAAE,QAAQ,EAAE,cAAc,IAAI,WAAW;YACvD,cAAc,EAAE,QAAQ,EAAE,cAAc,IAAI,YAAY;YACxD,KAAK,EAAE,IAAI,CAAC,SAAS,IAAI,CAAC,CAAC;YAC3B,KAAK,EAAE,IAAI,CAAC,YAAY,EAAE,MAAM,IAAI,CAAC;YACrC,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE;SACjD,CAAC,CAAC;QACH,IAAI,CAAC,iBAAiB,GAAG,CAAC,IAAI,CAAC,eAAe,IAAI,CAAC,aAAa,CAAC;IACnE,CAAC;IAES,YAAY,CAAC,UAAkB;QACvC,cAAc,CAAC,IAAI,EAAE,kBAAkB,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,UAAU,EAAE,CAAC,CAAC;IAC7E,CAAC;IAEQ,MAAM;QACb,OAAO,MAAM,CAAC,OAAO,CAAC;IACxB,CAAC;;AAtDM;IADN,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,UAAU,EAAE,CAAC;mDAClC;AAGxB;IADP,OAAO,CAAC,EAAE,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;iDACd;AAMzC;IADC,KAAK,CAAC,iBAAiB,CAAC;wDAKxB","sourcesContent":["import { LitElement } from 'lit';\nimport { property } from 'lit/decorators.js';\nimport { consume } from '@lit/context';\n\nimport { watch } from '@qti-components/utilities';\nimport { computedContext } from '@qti-components/base';\nimport { navigationRules } from '@qti-components/delivery';\n\nimport * as styles from '../styles';\nimport { dispatchPublic } from '../../public-events';\nimport { itemsInOrder } from '../../items-in-order';\n\nimport type { ComputedContext, ComputedItem } from '@qti-components/base';\n\n/**\n * Represents a custom element for navigating to the previous test item.\n *\n * @remarks\n * This element provides functionality for navigating to the previous test item.\n *\n * @example\n * ```html\n * <test-prev></test-prev>\n * ```\n */\n\nexport class TestPrev extends LitElement {\n @property({ type: Boolean, reflect: true, attribute: 'disabled' })\n public _internalDisabled = true;\n\n @consume({ context: computedContext, subscribe: true })\n private computedContext: ComputedContext;\n\n sectionItems: ComputedItem[];\n itemIndex: number;\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\n this.addEventListener('click', e => {\n e.preventDefault();\n if (!this._internalDisabled) this._requestItem(this.sectionItems[this.itemIndex - 1].identifier);\n });\n }\n\n override willUpdate(_changedProperties: Map<string | number | symbol, unknown>) {\n if (!this.computedContext) return;\n const testPart = this.computedContext?.testParts.find(testPart => testPart.active);\n if (!testPart) return;\n this.sectionItems = itemsInOrder(testPart);\n this.itemIndex = this.sectionItems.findIndex(item => item.active);\n this.checkDisabled();\n }\n\n checkDisabled() {\n const testPart = this.computedContext?.testParts.find(testPart => testPart.active);\n // A linear part never goes back (implementation guide §4.1).\n const { mayGoPrevious } = navigationRules({\n navigationMode: testPart?.navigationMode ?? 'nonlinear',\n submissionMode: testPart?.submissionMode ?? 'individual',\n index: this.itemIndex ?? -1,\n count: this.sectionItems?.length ?? 0,\n current: { maySubmit: true, interactive: false }\n });\n this._internalDisabled = !this.computedContext || !mayGoPrevious;\n }\n\n protected _requestItem(identifier: string): void {\n dispatchPublic(this, 'qc-test-navigate', { type: 'item', id: identifier });\n }\n\n override render() {\n return styles.control;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'test-prev': TestPrev;\n }\n}\n"]}
1
+ {"version":3,"file":"test-prev.js","sourceRoot":"","sources":["../../../src/components/test-prev/test-prev.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AACjC,OAAO,EAAE,QAAQ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';\n\nimport { watch } from '@qti-components/utilities';\nimport { computedContext } from '@qti-components/base';\nimport { navigationRules } from '@qti-components/delivery';\n\nimport * as styles from '../styles';\nimport { dispatchPublic } from '../../public-events';\nimport { activeTestPart, itemsInOrder } from '../../computed-tree';\n\nimport type { ComputedContext, ComputedItem } from '@qti-components/base';\n\n/**\n * Represents a custom element for navigating to the previous test item.\n *\n * @remarks\n * This element provides functionality for navigating to the previous test item.\n *\n * @example\n * ```html\n * <test-prev></test-prev>\n * ```\n */\n\nexport class TestPrev extends LitElement {\n @property({ type: Boolean, reflect: true, attribute: 'disabled' })\n public _internalDisabled = true;\n\n @consume({ context: computedContext, subscribe: true })\n private computedContext: ComputedContext;\n\n sectionItems: ComputedItem[];\n itemIndex: number;\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\n this.addEventListener('click', e => {\n e.preventDefault();\n if (!this._internalDisabled) this._requestItem(this.sectionItems[this.itemIndex - 1].instance);\n });\n }\n\n override willUpdate(_changedProperties: Map<string | number | symbol, unknown>) {\n if (!this.computedContext) return;\n const testPart = activeTestPart(this.computedContext);\n if (!testPart) return;\n this.sectionItems = itemsInOrder(testPart);\n this.itemIndex = this.sectionItems.findIndex(item => item.active);\n this.checkDisabled();\n }\n\n checkDisabled() {\n const testPart = activeTestPart(this.computedContext);\n // A linear part never goes back (implementation guide §4.1).\n const { mayGoPrevious } = navigationRules({\n navigationMode: testPart?.navigationMode ?? 'nonlinear',\n submissionMode: testPart?.submissionMode ?? 'individual',\n index: this.itemIndex ?? -1,\n count: this.sectionItems?.length ?? 0,\n current: { maySubmit: true, interactive: false }\n });\n this._internalDisabled = !this.computedContext || !mayGoPrevious;\n }\n\n protected _requestItem(identifier: string): void {\n dispatchPublic(this, 'qc-test-navigate', { type: 'item', id: identifier });\n }\n\n override render() {\n return styles.control;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'test-prev': TestPrev;\n }\n}\n"]}
@@ -0,0 +1,20 @@
1
+ import type { ComputedContext, ComputedItem, ComputedSection, ComputedTestPart } from '@qti-components/base';
2
+ /**
3
+ * Every item of a test part once, in the order the candidate takes them: the test's document order,
4
+ * through nested sections, interleaved item-refs and subsections included, info items included.
5
+ */
6
+ export declare const itemsInOrder: (testPart: ComputedTestPart) => ComputedItem[];
7
+ /** Every section of a test part once, nested ones included, a section before its subsections. */
8
+ export declare const sectionsInOrder: (testPart: ComputedTestPart) => ComputedSection[];
9
+ /** The test part the candidate is in, or undefined (no context yet, or before the test starts). */
10
+ export declare const activeTestPart: (context: ComputedContext | undefined) => ComputedTestPart | undefined;
11
+ /**
12
+ * The section the candidate is in: the closest one around the active item, or the section shown.
13
+ * Looked for in every test part, as `active` is set from where the candidate is.
14
+ */
15
+ export declare const activeSection: (context: ComputedContext | undefined) => ComputedSection | undefined;
16
+ /**
17
+ * The item the candidate is on, or undefined (`navigate="section"` shows a section, not one item).
18
+ * Looked for in every test part, as `active` is set from where the candidate is.
19
+ */
20
+ export declare const activeItem: (context: ComputedContext | undefined) => ComputedItem | undefined;
@@ -0,0 +1,22 @@
1
+ const items = (content) => content.flatMap(node => (node.kind === 'item' ? [node] : items(node.content)));
2
+ const sections = (content) => content.flatMap(node => (node.kind === 'section' ? [node, ...sections(node.content)] : []));
3
+ /**
4
+ * Every item of a test part once, in the order the candidate takes them: the test's document order,
5
+ * through nested sections, interleaved item-refs and subsections included, info items included.
6
+ */
7
+ export const itemsInOrder = (testPart) => items(testPart.sections);
8
+ /** Every section of a test part once, nested ones included, a section before its subsections. */
9
+ export const sectionsInOrder = (testPart) => sections(testPart.sections);
10
+ /** The test part the candidate is in, or undefined (no context yet, or before the test starts). */
11
+ export const activeTestPart = (context) => context?.testParts.find(testPart => testPart.active);
12
+ /**
13
+ * The section the candidate is in: the closest one around the active item, or the section shown.
14
+ * Looked for in every test part, as `active` is set from where the candidate is.
15
+ */
16
+ export const activeSection = (context) => context?.testParts.flatMap(sectionsInOrder).find(section => section.active);
17
+ /**
18
+ * The item the candidate is on, or undefined (`navigate="section"` shows a section, not one item).
19
+ * Looked for in every test part, as `active` is set from where the candidate is.
20
+ */
21
+ export const activeItem = (context) => context?.testParts.flatMap(itemsInOrder).find(item => item.active);
22
+ //# sourceMappingURL=computed-tree.js.map
@@ -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 './items-in-order.js';
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 './items-in-order.js';
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,qBAAqB,CAAC;AACpC,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 './items-in-order.js';\nexport * from './state-from-contexts.js';\nexport * from './types/iqti-test.js';\nexport * from './types/qti-test-state.js';\n"]}
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 and the plugin
31
- * entries. An item on screen that the order does not have, and a position of only a section or a
32
- * part, give `current: null`.
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 and the plugin
5
- * entries. An item on screen that the order does not have, and a position of only a section or a
6
- * part, give `current: null`.
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
- return {
14
- ...delivery,
15
- current: onScreen && Object.hasOwn(delivery.items, onScreen) ? onScreen : null,
16
- plugins: { ...(state.session.plugins ?? {}) }
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,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAE/E,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AAiCjE;;;;;;GAMG;AACH,MAAM,UAAU,6BAA6B,CAAC,KAAmB,EAAE,MAA2B;IAC5F,MAAM,QAAQ,GAAG,mBAAmB,CAAC,MAAM,CAAC,CA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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 { createDeliveryState, itemInstanceId } from '@qti-components/delivery';\n\nimport { QTI_TEST_STATE_VERSION } from '../types/qti-test-state';\n\nimport type { Clock, DeliveryState } from '@qti-components/delivery';\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 *\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}\n\n/**\n * A `DeliveryState` from a stored `QtiTestState`: the order, the item on screen and the plugin\n * entries. An item on screen that the order does not have, and a position of only a section or a\n * part, give `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 return {\n ...delivery,\n current: onScreen && Object.hasOwn(delivery.items, onScreen) ? onScreen : null,\n plugins: { ...(state.session.plugins ?? {}) }\n };\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"]}
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,0BAA0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,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
- /** The host's per-item fields (`initContext`): each item gets them under `data`, never at its top level. */
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-ref identifier (see `ItemOptimality`).
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-ref identifier, kept by `test-navigation`
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, ownItemRefs, sectionsInOrder, seedItemLifecycle } from '@qti-components/delivery';
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,34 +37,25 @@ export function deriveComputedContext(inputs) {
20
37
  identifier: testPart.identifier,
21
38
  navigationMode: testPart.navigationMode,
22
39
  submissionMode: testPart.submissionMode,
23
- allowSkipping: testPart.sessionControl.allowSkipping,
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
- const itemContext = itemContextFor(inputs, item.identifier);
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
- identifier: item.identifier,
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 }),
53
61
  ...(itemContext?.comment === undefined ? {} : { comment: itemContext.comment }),
@@ -61,7 +69,7 @@ function deriveItem(inputs, testPart, item, index) {
61
69
  const completionStatus = variableValue(computedItem, 'completionStatus');
62
70
  const response = variableValue(computedItem, 'RESPONSE') || '';
63
71
  const numAttempts = Number(variableValue(computedItem, 'numAttempts')) || 0;
64
- const latched = inputs.optimality.get(item.identifier);
72
+ const latched = inputs.optimality.get(instance);
65
73
  const session = lifecycleOf(inputs, testPart, item, itemContext, { numAttempts, completionStatus });
66
74
  return {
67
75
  ...computedItem,
@@ -70,7 +78,7 @@ function deriveItem(inputs, testPart, item, index) {
70
78
  score,
71
79
  response,
72
80
  index,
73
- active: inputs.sessionContext?.navItemRefId === item.identifier,
81
+ active: inputs.sessionContext?.navItemRefId === instance,
74
82
  // Published by the item. One that is not on screen has nothing to be invalid.
75
83
  valid: itemContext?.valid ?? true,
76
84
  isDefaultResponse: isDefaultResponse(itemContext),
@@ -80,7 +88,7 @@ function deriveItem(inputs, testPart, item, index) {
80
88
  ...session,
81
89
  // The session's: closed, or in review or solution. Never the score (roadmap 1, T3b2b).
82
90
  done: session.rules.done,
83
- data: hostData(inputs.itemData, item.identifier)
91
+ data: hostData(inputs.itemData, instance)
84
92
  };
85
93
  }
86
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,EAAE,IA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AC;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?.comment === undefined ? {} : { comment: itemContext.comment }),\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,S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KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC;AAC9C,CAAC","sourcesContent":["import { itemRefsInOrder, itemRules, parseItemInstanceId, seedItemLifecycle } from '@qti-components/delivery';\n\nimport 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"]}
@@ -6,6 +6,6 @@
6
6
  export { dispatchPublic, listenPublic, PUBLIC_EVENTS } from './public-events.js';
7
7
  export type { NavigationFailure, NavigationTarget, PublicEventMap, PublicEventName, StateRefusal } from './public-events.js';
8
8
  export { pluginState } from './plugin-state.js';
9
- export { itemsInOrder } from './items-in-order.js';
9
+ export { activeItem, activeSection, activeTestPart, itemsInOrder, sectionsInOrder } from './computed-tree.js';
10
10
  export type { QtiTestPluginState, QtiTestState } from './types/qti-test-state.js';
11
11
  export * as controlStyles from './components/styles.js';
@@ -5,6 +5,6 @@
5
5
  */
6
6
  export { dispatchPublic, listenPublic, PUBLIC_EVENTS } from './public-events.js';
7
7
  export { pluginState } from './plugin-state.js';
8
- export { itemsInOrder } from './items-in-order.js';
8
+ export { activeItem, activeSection, activeTestPart, itemsInOrder, sectionsInOrder } from './computed-tree.js';
9
9
  export * as controlStyles from './components/styles.js';
10
10
  //# sourceMappingURL=plugin-api.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"plugin-api.js","sourceRoot":"","sources":["../src/plugin-api.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAQjF,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEnD,OAAO,KAAK,aAAa,MAAM,wBAAwB,CAAC","sourcesContent":["/**\n * What a plugin in another package builds on, with no registration side effect: the public events\n * and their helpers, the typed read of plugin state, the state types, and the look of the test\n * controls. `@qti-components/extended` is the consumer; a plugin of your own may use it too.\n */\nexport { dispatchPublic, listenPublic, PUBLIC_EVENTS } from './public-events.js';\nexport type {\n NavigationFailure,\n NavigationTarget,\n PublicEventMap,\n PublicEventName,\n StateRefusal\n} from './public-events.js';\nexport { pluginState } from './plugin-state.js';\nexport { itemsInOrder } from './items-in-order.js';\nexport type { QtiTestPluginState, QtiTestState } from './types/qti-test-state.js';\nexport * as controlStyles from './components/styles.js';\n"]}
1
+ {"version":3,"file":"plugin-api.js","sourceRoot":"","sources":["../src/plugin-api.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAQjF,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,cAAc,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAE9G,OAAO,KAAK,aAAa,MAAM,wBAAwB,CAAC","sourcesContent":["/**\n * What a plugin in another package builds on, with no registration side effect: the public events\n * and their helpers, the typed read of plugin state, the state types, and the look of the test\n * controls. `@qti-components/extended` is the consumer; a plugin of your own may use it too.\n */\nexport { dispatchPublic, listenPublic, PUBLIC_EVENTS } from './public-events.js';\nexport type {\n NavigationFailure,\n NavigationTarget,\n PublicEventMap,\n PublicEventName,\n StateRefusal\n} from './public-events.js';\nexport { pluginState } from './plugin-state.js';\nexport { activeItem, activeSection, activeTestPart, itemsInOrder, sectionsInOrder } from './computed-tree.js';\nexport type { QtiTestPluginState, QtiTestState } from './types/qti-test-state.js';\nexport * as controlStyles from './components/styles.js';\n"]}
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@qti-components/test",
3
3
  "description": "QTI test utilities",
4
- "version": "2.0.0-next.28",
4
+ "version": "2.0.0-next.29",
5
5
  "author": "",
6
6
  "dependencies": {
7
7
  "@heximal/templates": "^0.1.5",
8
- "@qti-components/base": "^3.0.0-next.15",
9
- "@qti-components/delivery": "^0.1.0-next.8",
8
+ "@qti-components/base": "^3.0.0-next.16",
9
+ "@qti-components/delivery": "^0.1.0-next.9",
10
10
  "@qti-components/elements": "^2.0.0-next.7",
11
11
  "@qti-components/interactions": "^1.10.5-next.8",
12
12
  "@qti-components/processing": "^1.6.1-next.5",
@@ -1,9 +0,0 @@
1
- import type { ComputedContext, ComputedItem } from '@qti-components/base';
2
- /**
3
- * The items of a test part in the order the candidate takes them: the test's document order, info
4
- * items included. Flattening `testPart.sections` is not that order when a section's item-refs and
5
- * subsections interleave, since `sections` lists every section once, depth first.
6
- *
7
- * A part without `itemOrder` (a context built by hand) gives its sections' items as they are listed.
8
- */
9
- export declare const itemsInOrder: (testPart: ComputedContext["testParts"][number]) => ComputedItem[];
@@ -1,15 +0,0 @@
1
- /**
2
- * The items of a test part in the order the candidate takes them: the test's document order, info
3
- * items included. Flattening `testPart.sections` is not that order when a section's item-refs and
4
- * subsections interleave, since `sections` lists every section once, depth first.
5
- *
6
- * A part without `itemOrder` (a context built by hand) gives its sections' items as they are listed.
7
- */
8
- export const itemsInOrder = (testPart) => {
9
- const items = testPart.sections.flatMap(section => section.items);
10
- if (!testPart.itemOrder)
11
- return items;
12
- const byIdentifier = new Map(items.map(item => [item.identifier, item]));
13
- return testPart.itemOrder.flatMap(identifier => byIdentifier.get(identifier) ?? []);
14
- };
15
- //# sourceMappingURL=items-in-order.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"items-in-order.js","sourceRoot":"","sources":["../src/items-in-order.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,QAA8C,EAAkB,EAAE;IAC7F,MAAM,KAAK,GAAG,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAClE,IAAI,CAAC,QAAQ,CAAC,SAAS;QAAE,OAAO,KAAK,CAAC;IACtC,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;IACzE,OAAO,QAAQ,CAAC,SAAS,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC,YAAY,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC,CAAC;AACtF,CAAC,CAAC","sourcesContent":["import type { ComputedContext, ComputedItem } from '@qti-components/base';\n\n/**\n * The items of a test part in the order the candidate takes them: the test's document order, info\n * items included. Flattening `testPart.sections` is not that order when a section's item-refs and\n * subsections interleave, since `sections` lists every section once, depth first.\n *\n * A part without `itemOrder` (a context built by hand) gives its sections' items as they are listed.\n */\nexport const itemsInOrder = (testPart: ComputedContext['testParts'][number]): ComputedItem[] => {\n const items = testPart.sections.flatMap(section => section.items);\n if (!testPart.itemOrder) return items;\n const byIdentifier = new Map(items.map(item => [item.identifier, item]));\n return testPart.itemOrder.flatMap(identifier => byIdentifier.get(identifier) ?? []);\n};\n"]}