@qti-components/test 2.0.0-next.26 → 2.0.0-next.28

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.
Files changed (32) hide show
  1. package/dist/components/test-end-attempt/test-end-attempt.d.ts +7 -5
  2. package/dist/components/test-end-attempt/test-end-attempt.js +26 -31
  3. package/dist/components/test-end-attempt/test-end-attempt.js.map +1 -1
  4. package/dist/components/test-navigation/test-navigation.d.ts +5 -4
  5. package/dist/components/test-navigation/test-navigation.js +146 -46
  6. package/dist/components/test-navigation/test-navigation.js.map +1 -1
  7. package/dist/components/test-next/test-next.d.ts +4 -1
  8. package/dist/components/test-next/test-next.js +16 -13
  9. package/dist/components/test-next/test-next.js.map +1 -1
  10. package/dist/components/test-prev/test-prev.js +10 -3
  11. package/dist/components/test-prev/test-prev.js.map +1 -1
  12. package/dist/internal/derive-computed-context.d.ts +0 -20
  13. package/dist/internal/derive-computed-context.js +6 -36
  14. package/dist/internal/derive-computed-context.js.map +1 -1
  15. package/dist/internal/test-host.context.d.ts +14 -0
  16. package/dist/internal/test-host.context.js.map +1 -1
  17. package/dist/mixins/test-base.d.ts +2 -0
  18. package/dist/mixins/test-base.js +16 -0
  19. package/dist/mixins/test-base.js.map +1 -1
  20. package/dist/mixins/test-navigation.mixin.js +22 -0
  21. package/dist/mixins/test-navigation.mixin.js.map +1 -1
  22. package/dist/mixins/test-state.mixin.js +3 -1
  23. package/dist/mixins/test-state.mixin.js.map +1 -1
  24. package/dist/public-events.d.ts +9 -0
  25. package/dist/public-events.js +1 -0
  26. package/dist/public-events.js.map +1 -1
  27. package/dist/state-from-contexts.d.ts +1 -0
  28. package/dist/state-from-contexts.js +2 -1
  29. package/dist/state-from-contexts.js.map +1 -1
  30. package/dist/types/qti-test-state.d.ts +5 -0
  31. package/dist/types/qti-test-state.js.map +1 -1
  32. package/package.json +3 -3
@@ -1 +1 @@
1
- {"version":3,"file":"test-host.context.js","sourceRoot":"","sources":["../../src/internal/test-host.context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AA6B7C,MAAM,CAAC,MAAM,eAAe,GAAG,aAAa,CAAW,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC","sourcesContent":["import { createContext } from '@lit/context';\n\nimport type { QtiContext } from '@qti-components/base';\nimport type { transformTestApi } from '@qti-components/transformers';\nimport type { QtiAssessmentTest } from '../components/qti-assessment-test/qti-assessment-test';\n\n/**\n * Defined here, and re-exported by the navigation mixin under the same name, so this file imports\n * nothing from the mixin: the mixin imports the components that consume this context, and a type\n * import counts as a dependency for madge.\n */\nexport type PostLoadTestTransformCallback = (\n transformer: transformTestApi,\n testElement: QtiAssessmentTest\n) => transformTestApi | Promise<transformTestApi>;\n\n/**\n * What the components inside a test need from the `qti-test` that contains them: the things a host\n * put on it, and the element to query. Provided by `qti-test` about itself.\n *\n * It is context and not `closest('qti-test')` because a request crosses shadow roots and `closest`\n * stops at the first one, so a navigation or container a host renders inside its own component\n * would never find its test. Internal on purpose: not exported from the package, and not API.\n */\nexport interface TestHost extends HTMLElement {\n qtiContext: QtiContext;\n postLoadTestTransformCallback: PostLoadTestTransformCallback | null;\n}\n\nexport const testHostContext = createContext<TestHost>(Symbol('testHost'));\n"]}
1
+ {"version":3,"file":"test-host.context.js","sourceRoot":"","sources":["../../src/internal/test-host.context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AA4C7C,MAAM,CAAC,MAAM,eAAe,GAAG,aAAa,CAAW,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC","sourcesContent":["import { createContext } from '@lit/context';\n\nimport type { QtiContext } from '@qti-components/base';\nimport type { transformTestApi } from '@qti-components/transformers';\nimport type { QtiAssessmentTest } from '../components/qti-assessment-test/qti-assessment-test';\n\n/**\n * Defined here, and re-exported by the navigation mixin under the same name, so this file imports\n * nothing from the mixin: the mixin imports the components that consume this context, and a type\n * import counts as a dependency for madge.\n */\nexport type PostLoadTestTransformCallback = (\n transformer: transformTestApi,\n testElement: QtiAssessmentTest\n) => transformTestApi | Promise<transformTestApi>;\n\n/**\n * What the components inside a test need from the `qti-test` that contains them: the things a host\n * put on it, and the element to query. Provided by `qti-test` about itself.\n *\n * It is context and not `closest('qti-test')` because a request crosses shadow roots and `closest`\n * stops at the first one, so a navigation or container a host renders inside its own component\n * would never find its test. Internal on purpose: not exported from the package, and not API.\n */\nexport interface TestHost extends HTMLElement {\n qtiContext: QtiContext;\n postLoadTestTransformCallback: PostLoadTestTransformCallback | null;\n /**\n * Set by `test-navigation`, which keeps the item sessions: asked by the navigation mixin before a\n * Next in a linear part leaves `itemRefId`, while that item is still rendered. It ends the item's\n * attempt when one is open (roadmap 1, T3b2b) and answers null, or answers why the item may not\n * be left yet.\n */\n beforeLinearNext?: ((itemRefId: string) => LinearNextRefusal | null) | null;\n /** Sets the candidate's comment on an item-ref; null clears it. `test-navigation` checks `rules.mayComment` first. */\n updateItemComment(itemRefId: string, comment: string | null): void;\n}\n\n/** Why Next may not leave an item yet: its responses are ones its session control refuses. */\nexport interface LinearNextRefusal {\n reason: 'allow-skipping' | 'validate-responses';\n itemId: string;\n}\n\nexport const testHostContext = createContext<TestHost>(Symbol('testHost'));\n"]}
@@ -14,6 +14,8 @@ export interface TestBaseInterface extends LitElement {
14
14
  qtiContext?: Readonly<QtiContext>;
15
15
  _testElement: QtiAssessmentTest;
16
16
  updateItemVariables(itemRefID: string, variables: readonly ItemVariableValue[], state?: ItemContext['state']): void;
17
+ /** @internal */
18
+ updateItemComment(itemRefID: string, comment: string | null): void;
17
19
  }
18
20
  /** A value to set on an item; `type` is only needed for a variable the item does not declare. */
19
21
  export type ItemVariableValue = Pick<VariableValue<string | string[] | null>, 'identifier' | 'value'> & Partial<Pick<VariableValue<string | string[] | null>, 'type'>>;
@@ -110,6 +110,22 @@ export const TestBaseMixin = (superClass) => {
110
110
  if (state)
111
111
  assessmentItem.state = state;
112
112
  }
113
+ /**
114
+ * Sets the candidate's comment on an item-ref (null clears it), as `qc-test-update-comment` asks
115
+ * once `test-navigation` has checked the item allows it. Internal; hosts send the request.
116
+ * @internal
117
+ */
118
+ updateItemComment(itemRefID, comment) {
119
+ this.testContext = {
120
+ ...this.testContext,
121
+ items: this.testContext.items.map(item => {
122
+ if (item.identifier !== itemRefID)
123
+ return item;
124
+ const { comment: _previous, ...rest } = item;
125
+ return comment === null ? rest : { ...rest, comment };
126
+ })
127
+ };
128
+ }
113
129
  _initializeEventListeners() {
114
130
  /**
115
131
  * A new test document means a new test and session context.
@@ -1 +1 @@
1
- {"version":3,"file":"test-base.js","sourceRoot":"","sources":["../../src/mixins/test-base.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AACjC,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C,OAAO,EAAE,oBAAoB,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACzE,OAAO,EAAE,uBAAuB,EAAuB,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEpG,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AA0BhD,MAAM,CAAC,MAAM,aAAa,GAAG,CAAoC,UAAa,EAAE,EAAE;IAChF,MAAe,aAAc,SAAQ,UAAU;QAW7C,YAAY,GAAG,IAAW;YACxB,KAAK,CAAC,GAAG,IAAI,CAAC,CAAC;YATV,gBAAW,GAA0B,oBAAoB,CAAC;YAI1D,mBAAc,GAA6B,uBAAuB,CAAC;YAoJ1E;;;;;;;;eAQG;YACK,6BAAwB,GAAG,CAAC,cAAiC,EAAQ,EAAE;gBAC7E,MAAM,OAAO,GAAG,cAAc,CAAC,WAAW,CAAC;gBAC3C,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;gBACtC,MAAM,aAAa,GAAG,OAAO,CAAC,SAAS,CA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E,SAAS,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;QAC5C,OAAO,CAAC,EAAE,OAAO,EAAE,cAAc,EAAE,CAAC;yDACqC;IA0N5E,OAAO,aAAmD,CAAC;AAC7D,CAAC,CAAC;AAEF,2EAA2E;AAC3E,MAAM,OAAgB,QAAS,SAAQ,aAAa,CAAC,UAAU,CAAC;CAAG","sourcesContent":["import { provide } from '@lit/context';\nimport { LitElement } from 'lit';\nimport { property } from 'lit/decorators.js';\n\nimport { INITIAL_TEST_CONTEXT, testContext } from '@qti-components/base';\nimport { INITIAL_SESSION_CONTEXT, type SessionContext, sessionContext } from '@qti-components/base';\n\nimport { listenPublic } from '../public-events';\n\nimport type { QtiAssessmentItem } from '@qti-components/elements';\nimport type { QtiAssessmentItemRef } from '../components/qti-assessment-item-ref/qti-assessment-item-ref';\nimport type { QtiAssessmentTest } from '../components/qti-assessment-test/qti-assessment-test';\nimport type { ConfigContext, QtiContext } from '@qti-components/base';\nimport type { ItemContext } from '@qti-components/base';\nimport type { TestContext } from '@qti-components/base';\nimport type { OutcomeVariable, VariableDeclaration, VariableValue } from '@qti-components/base';\n\ntype Constructor<T = {}> = abstract new (...args: any[]) => T;\n\nexport interface TestBaseInterface extends LitElement {\n testContext: Readonly<TestContext>;\n sessionContext: Readonly<SessionContext>;\n configContext?: Readonly<ConfigContext>;\n /** Provided by `qti-test`. */\n qtiContext?: Readonly<QtiContext>;\n _testElement: QtiAssessmentTest;\n updateItemVariables(itemRefID: string, variables: readonly ItemVariableValue[], state?: ItemContext['state']): void;\n}\n\n/** A value to set on an item; `type` is only needed for a variable the item does not declare. */\nexport type ItemVariableValue = Pick<VariableValue<string | string[] | null>, 'identifier' | 'value'> &\n Partial<Pick<VariableValue<string | string[] | null>, 'type'>>;\n\nexport const TestBaseMixin = <T extends Constructor<LitElement>>(superClass: T) => {\n abstract class TestBaseClass extends superClass implements TestBaseInterface {\n @property({ attribute: false, type: Object })\n @provide({ context: testContext })\n public testContext: Readonly<TestContext> = INITIAL_TEST_CONTEXT;\n\n @property({ attribute: false, type: Object })\n @provide({ context: sessionContext })\n public sessionContext: Readonly<SessionContext> = INITIAL_SESSION_CONTEXT;\n\n public _testElement: QtiAssessmentTest;\n\n constructor(...args: any[]) {\n super(...args);\n this._initializeEventListeners();\n }\n\n /**\n * Sets values on one item from outside the candidate's session, e.g. a score from manual\n * scoring. Values are merged into the item's entry in the test context, and into the item\n * itself if it is on screen; a value the item has not seen yet is added, so this also works\n * before the item has loaded. To restore a whole session, assign `state` instead.\n *\n * The test context is replaced rather than changed in place, so its consumers update and\n * `qc-test-state-changed` fires.\n *\n * @param itemRefID The `qti-assessment-item-ref` identifier, not the item's own identifier; a\n * `with-replacement` clone's instance id (`item-3#2`).\n * @param state Opaque per-interaction state keyed by response identifier, e.g. a PCI's `getState()`.\n */\n updateItemVariables(itemRefID: string, values: readonly ItemVariableValue[], state?: ItemContext['state']): void {\n this.testContext = {\n ...this.testContext,\n items: this.testContext.items.map(item => {\n if (item.identifier !== itemRefID) return item;\n\n const variables = [...(item.variables ?? [])];\n for (const { identifier, type, value } of values) {\n const index = variables.findIndex(v => v.identifier === identifier);\n const updated = {\n ...(index >= 0 ? variables[index] : {}),\n identifier,\n ...(type ? { type } : {}),\n value: Array.isArray(value) ? [...value] : value\n } as VariableDeclaration<string | string[] | null>;\n if (index >= 0) variables[index] = updated;\n else variables.push(updated);\n }\n return { ...item, variables, ...(state ? { state: { ...state } } : {}) };\n })\n };\n\n const assessmentItem = this._testElement?.querySelector<QtiAssessmentItemRef>(\n `qti-assessment-item-ref[identifier=\"${CSS.escape(itemRefID)}\"]`\n )?.assessmentItem;\n if (!assessmentItem) return;\n assessmentItem.variables = [...(this.testContext.items.find(i => i.identifier === itemRefID)?.variables ?? [])];\n if (state) assessmentItem.state = state;\n }\n\n private _initializeEventListeners(): void {\n /**\n * A new test document means a new test and session context.\n *\n * This resets on the document being loaded rather than on\n * `qc-test-loaded`, because the new document's children —\n * test-level `qti-outcome-declaration` among them — connect and register\n * themselves into the context *before* the test element announces itself.\n * Resetting on that announcement discarded every one of those\n * registrations, so no test-level outcome could be read or set.\n */\n this.addEventListener('qti-testdoc-loaded', () => {\n this.testContext = INITIAL_TEST_CONTEXT;\n this.sessionContext = INITIAL_SESSION_CONTEXT;\n });\n\n /**\n * When the test is connected, its item-refs are added to the test context.\n * Registrations from the document's children are already present on the\n * context reset above, so this must preserve what is there.\n */\n listenPublic(this, 'qc-test-loaded', (e: CustomEvent<QtiAssessmentTest>) => {\n this._testElement = e.detail;\n const items = Array.from(this._testElement.querySelectorAll('qti-assessment-item-ref')).map(itemRef => {\n return {\n href: itemRef.href,\n identifier: itemRef.identifier,\n category: itemRef.category,\n variables: [\n {\n identifier: 'completionStatus',\n value: 'not_attempted',\n type: 'outcome'\n } as OutcomeVariable\n ]\n };\n });\n this.testContext = { ...this.testContext, items };\n });\n\n this.addEventListener('qti-assessment-item-connected', (e: CustomEvent<QtiAssessmentItem>) => {\n const assessmentItem = e.detail as QtiAssessmentItem;\n const assessmentRefId = assessmentItem.closest('qti-assessment-item-ref')?.identifier;\n if (assessmentRefId) {\n assessmentItem.assessmentItemRefId = assessmentRefId;\n }\n this._updateItemInTestContext(e.detail);\n });\n\n this.addEventListener('qti-item-context-updated', (e: CustomEvent<{ itemContext: ItemContext }>) => {\n // const assessmentitem = e.composedPath()[0] as QtiAssessmentItem;\n this._updateItemVariablesInTestContext(\n e.detail.itemContext.identifier,\n e.detail.itemContext.variables,\n e.detail.itemContext.state,\n e.detail.itemContext.valid\n );\n });\n }\n\n private _updateItemVariablesInTestContext(\n identifier: string,\n variables: readonly VariableDeclaration<string | string[] | null>[],\n state?: ItemContext['state'],\n valid?: boolean\n ): void {\n // Update the test context with modified variables for the specified item\n this.testContext = {\n ...this.testContext, // Spread existing test context properties\n items: this.testContext.items.map(itemContext => {\n // If the item identifier doesn't match, keep it unchanged\n if (itemContext.identifier !== identifier) {\n return itemContext;\n }\n\n // Update the matching item with new variables\n return {\n ...itemContext, // Keep other properties of the item context\n variables: variables.map(variable => {\n // Find a matching variable in the current item context\n const matchingVariable = itemContext.variables.find(v => v.identifier === variable.identifier);\n\n // Merge matching variable with the new one, or use the new variable if no match\n return matchingVariable ? { ...matchingVariable, ...variable } : variable;\n }),\n ...(state !== undefined ? { state: state ? { ...state } : undefined } : {}),\n ...(valid !== undefined ? { valid } : {})\n };\n })\n };\n // Deprecated for hosts, see `@event` on `qti-test`; kept until the next major.\n this.dispatchEvent(\n new CustomEvent('qti-test-context-updated', { detail: this.testContext, bubbles: false, composed: false })\n );\n }\n\n /**\n * Updates the variables of an assessment item in the test context.\n * - Matches the assessment item with the corresponding test context item.\n * - If the item is not found, logs a warning.\n * - Updates variables in the test context if exactly one variable exists.\n * - Otherwise, syncs the assessment item's variables with the test context.\n *\n * @param assessmentItem - The assessment item to update.\n */\n private _updateItemInTestContext = (assessmentItem: QtiAssessmentItem): void => {\n const context = assessmentItem.itemContext;\n const identifier = context.identifier;\n const fullVariables = context.variables;\n\n // Find the corresponding item in the test context by identifier\n const itemContext = this.testContext.items.find(i => i?.identifier === identifier);\n\n if (!itemContext) {\n console.warn(`Item IDs between assessment.xml and item.xml should match: ${identifier} is not found!`);\n return;\n }\n\n // Update variables in the test context or sync them to the assessment item\n if (itemContext.variables?.length === 1) {\n // The loaded qti-assessment-item itself has variables which are not in test context yet.\n this._updateItemVariablesInTestContext(identifier, fullVariables, undefined, context.valid);\n } else {\n const newVariables = [...assessmentItem.variables];\n // Sync the assessment item's variables with the test context\n for (const variable of itemContext.variables) {\n // Presenting an item starts its first attempt, so it is no longer `not_attempted` once it\n // is on screen: the item keeps its own status (`unknown`) — `qti-number-presented` reads it.\n if (variable.identifier === 'completionStatus' && variable.value === 'not_attempted') continue;\n const currentVariable = newVariables.find(v => v.identifier === variable.identifier);\n if (currentVariable) {\n currentVariable.value = variable.value;\n } else {\n newVariables.push(variable);\n }\n }\n assessmentItem.variables = newVariables;\n this.#leaveNotAttempted(identifier, newVariables.find(v => v.identifier === 'completionStatus')?.value);\n // Opaque interaction state (a PCI's getState()) is read from the item context when the\n // interaction initializes, so it has to be in place now, before that happens.\n if (itemContext.state) {\n assessmentItem.state = itemContext.state;\n }\n }\n };\n\n /** Write the presented item's own status over a `not_attempted` the test context still holds for it. */\n #leaveNotAttempted(identifier: string, status: Readonly<string | string[] | null> | undefined): void {\n if (typeof status !== 'string' || status === 'not_attempted') return;\n const item = this.testContext.items.find(i => i.identifier === identifier);\n const current = item?.variables.find(v => v.identifier === 'completionStatus');\n if (current?.value !== 'not_attempted') return;\n this.testContext = {\n ...this.testContext,\n items: this.testContext.items.map(i =>\n i.identifier !== identifier\n ? i\n : {\n ...i,\n variables: i.variables.map(v => (v.identifier === 'completionStatus' ? { ...v, value: status } : v))\n }\n )\n };\n }\n }\n\n return TestBaseClass as Constructor<TestBaseInterface> & T;\n};\n\n// Keep the old abstract class for backwards compatibility during migration\nexport abstract class TestBase extends TestBaseMixin(LitElement) {}\n"]}
1
+ {"version":3,"file":"test-base.js","sourceRoot":"","sources":["../../src/mixins/test-base.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AACjC,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C,OAAO,EAAE,oBAAoB,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACzE,OAAO,EAAE,uBAAuB,EAAuB,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEpG,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AA4BhD,MAAM,CAAC,MAAM,aAAa,GAAG,CAAoC,UAAa,EAAE,EAAE;IAChF,MAAe,aAAc,SAAQ,UAAU;QAW7C,YAAY,GAAG,IAAW;YACxB,KAAK,CAAC,GAAG,IAAI,CAAC,CAAC;YATV,gBAAW,GAA0B,oBAAoB,CAAC;YAI1D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AAC,CAAC;YAC/E,IAAI,OAAO,EAAE,KAAK,KAAK,eAAe;gBAAE,OAAO;YAC/C,IAAI,CAAC,WAAW,GAAG;gBACjB,GAAG,IAAI,CAAC,WAAW;gBACnB,KAAK,EAAE,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CACpC,CAAC,CAAC,UAAU,KAAK,UAAU;oBACzB,CAAC,CAAC,CAAC;oBACH,CAAC,CAAC;wBACE,GAAG,CAAC;wBACJ,SAAS,EAAE,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,UAAU,KAAK,kBAAkB,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;qBACrG,CACN;aACF,CAAC;QACJ,CAAC;KACF;IA5OQ;QAFN,QAAQ,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;QAC5C,OAAO,CAAC,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC;sDAC+B;IAI1D;QAFN,QAAQ,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;QAC5C,OAAO,CAAC,EAAE,OAAO,EAAE,cAAc,EAAE,CAAC;yDACqC;IA0O5E,OAAO,aAAmD,CAAC;AAC7D,CAAC,CAAC;AAEF,2EAA2E;AAC3E,MAAM,OAAgB,QAAS,SAAQ,aAAa,CAAC,UAAU,CAAC;CAAG","sourcesContent":["import { provide } from '@lit/context';\nimport { LitElement } from 'lit';\nimport { property } from 'lit/decorators.js';\n\nimport { INITIAL_TEST_CONTEXT, testContext } from '@qti-components/base';\nimport { INITIAL_SESSION_CONTEXT, type SessionContext, sessionContext } from '@qti-components/base';\n\nimport { listenPublic } from '../public-events';\n\nimport type { QtiAssessmentItem } from '@qti-components/elements';\nimport type { QtiAssessmentItemRef } from '../components/qti-assessment-item-ref/qti-assessment-item-ref';\nimport type { QtiAssessmentTest } from '../components/qti-assessment-test/qti-assessment-test';\nimport type { ConfigContext, QtiContext } from '@qti-components/base';\nimport type { ItemContext } from '@qti-components/base';\nimport type { TestContext } from '@qti-components/base';\nimport type { OutcomeVariable, VariableDeclaration, VariableValue } from '@qti-components/base';\n\ntype Constructor<T = {}> = abstract new (...args: any[]) => T;\n\nexport interface TestBaseInterface extends LitElement {\n testContext: Readonly<TestContext>;\n sessionContext: Readonly<SessionContext>;\n configContext?: Readonly<ConfigContext>;\n /** Provided by `qti-test`. */\n qtiContext?: Readonly<QtiContext>;\n _testElement: QtiAssessmentTest;\n updateItemVariables(itemRefID: string, variables: readonly ItemVariableValue[], state?: ItemContext['state']): void;\n /** @internal */\n updateItemComment(itemRefID: string, comment: string | null): void;\n}\n\n/** A value to set on an item; `type` is only needed for a variable the item does not declare. */\nexport type ItemVariableValue = Pick<VariableValue<string | string[] | null>, 'identifier' | 'value'> &\n Partial<Pick<VariableValue<string | string[] | null>, 'type'>>;\n\nexport const TestBaseMixin = <T extends Constructor<LitElement>>(superClass: T) => {\n abstract class TestBaseClass extends superClass implements TestBaseInterface {\n @property({ attribute: false, type: Object })\n @provide({ context: testContext })\n public testContext: Readonly<TestContext> = INITIAL_TEST_CONTEXT;\n\n @property({ attribute: false, type: Object })\n @provide({ context: sessionContext })\n public sessionContext: Readonly<SessionContext> = INITIAL_SESSION_CONTEXT;\n\n public _testElement: QtiAssessmentTest;\n\n constructor(...args: any[]) {\n super(...args);\n this._initializeEventListeners();\n }\n\n /**\n * Sets values on one item from outside the candidate's session, e.g. a score from manual\n * scoring. Values are merged into the item's entry in the test context, and into the item\n * itself if it is on screen; a value the item has not seen yet is added, so this also works\n * before the item has loaded. To restore a whole session, assign `state` instead.\n *\n * The test context is replaced rather than changed in place, so its consumers update and\n * `qc-test-state-changed` fires.\n *\n * @param itemRefID The `qti-assessment-item-ref` identifier, not the item's own identifier; a\n * `with-replacement` clone's instance id (`item-3#2`).\n * @param state Opaque per-interaction state keyed by response identifier, e.g. a PCI's `getState()`.\n */\n updateItemVariables(itemRefID: string, values: readonly ItemVariableValue[], state?: ItemContext['state']): void {\n this.testContext = {\n ...this.testContext,\n items: this.testContext.items.map(item => {\n if (item.identifier !== itemRefID) return item;\n\n const variables = [...(item.variables ?? [])];\n for (const { identifier, type, value } of values) {\n const index = variables.findIndex(v => v.identifier === identifier);\n const updated = {\n ...(index >= 0 ? variables[index] : {}),\n identifier,\n ...(type ? { type } : {}),\n value: Array.isArray(value) ? [...value] : value\n } as VariableDeclaration<string | string[] | null>;\n if (index >= 0) variables[index] = updated;\n else variables.push(updated);\n }\n return { ...item, variables, ...(state ? { state: { ...state } } : {}) };\n })\n };\n\n const assessmentItem = this._testElement?.querySelector<QtiAssessmentItemRef>(\n `qti-assessment-item-ref[identifier=\"${CSS.escape(itemRefID)}\"]`\n )?.assessmentItem;\n if (!assessmentItem) return;\n assessmentItem.variables = [...(this.testContext.items.find(i => i.identifier === itemRefID)?.variables ?? [])];\n if (state) assessmentItem.state = state;\n }\n\n /**\n * Sets the candidate's comment on an item-ref (null clears it), as `qc-test-update-comment` asks\n * once `test-navigation` has checked the item allows it. Internal; hosts send the request.\n * @internal\n */\n updateItemComment(itemRefID: string, comment: string | null): void {\n this.testContext = {\n ...this.testContext,\n items: this.testContext.items.map(item => {\n if (item.identifier !== itemRefID) return item;\n const { comment: _previous, ...rest } = item;\n return comment === null ? rest : { ...rest, comment };\n })\n };\n }\n\n private _initializeEventListeners(): void {\n /**\n * A new test document means a new test and session context.\n *\n * This resets on the document being loaded rather than on\n * `qc-test-loaded`, because the new document's children —\n * test-level `qti-outcome-declaration` among them — connect and register\n * themselves into the context *before* the test element announces itself.\n * Resetting on that announcement discarded every one of those\n * registrations, so no test-level outcome could be read or set.\n */\n this.addEventListener('qti-testdoc-loaded', () => {\n this.testContext = INITIAL_TEST_CONTEXT;\n this.sessionContext = INITIAL_SESSION_CONTEXT;\n });\n\n /**\n * When the test is connected, its item-refs are added to the test context.\n * Registrations from the document's children are already present on the\n * context reset above, so this must preserve what is there.\n */\n listenPublic(this, 'qc-test-loaded', (e: CustomEvent<QtiAssessmentTest>) => {\n this._testElement = e.detail;\n const items = Array.from(this._testElement.querySelectorAll('qti-assessment-item-ref')).map(itemRef => {\n return {\n href: itemRef.href,\n identifier: itemRef.identifier,\n category: itemRef.category,\n variables: [\n {\n identifier: 'completionStatus',\n value: 'not_attempted',\n type: 'outcome'\n } as OutcomeVariable\n ]\n };\n });\n this.testContext = { ...this.testContext, items };\n });\n\n this.addEventListener('qti-assessment-item-connected', (e: CustomEvent<QtiAssessmentItem>) => {\n const assessmentItem = e.detail as QtiAssessmentItem;\n const assessmentRefId = assessmentItem.closest('qti-assessment-item-ref')?.identifier;\n if (assessmentRefId) {\n assessmentItem.assessmentItemRefId = assessmentRefId;\n }\n this._updateItemInTestContext(e.detail);\n });\n\n this.addEventListener('qti-item-context-updated', (e: CustomEvent<{ itemContext: ItemContext }>) => {\n // const assessmentitem = e.composedPath()[0] as QtiAssessmentItem;\n this._updateItemVariablesInTestContext(\n e.detail.itemContext.identifier,\n e.detail.itemContext.variables,\n e.detail.itemContext.state,\n e.detail.itemContext.valid\n );\n });\n }\n\n private _updateItemVariablesInTestContext(\n identifier: string,\n variables: readonly VariableDeclaration<string | string[] | null>[],\n state?: ItemContext['state'],\n valid?: boolean\n ): void {\n // Update the test context with modified variables for the specified item\n this.testContext = {\n ...this.testContext, // Spread existing test context properties\n items: this.testContext.items.map(itemContext => {\n // If the item identifier doesn't match, keep it unchanged\n if (itemContext.identifier !== identifier) {\n return itemContext;\n }\n\n // Update the matching item with new variables\n return {\n ...itemContext, // Keep other properties of the item context\n variables: variables.map(variable => {\n // Find a matching variable in the current item context\n const matchingVariable = itemContext.variables.find(v => v.identifier === variable.identifier);\n\n // Merge matching variable with the new one, or use the new variable if no match\n return matchingVariable ? { ...matchingVariable, ...variable } : variable;\n }),\n ...(state !== undefined ? { state: state ? { ...state } : undefined } : {}),\n ...(valid !== undefined ? { valid } : {})\n };\n })\n };\n // Deprecated for hosts, see `@event` on `qti-test`; kept until the next major.\n this.dispatchEvent(\n new CustomEvent('qti-test-context-updated', { detail: this.testContext, bubbles: false, composed: false })\n );\n }\n\n /**\n * Updates the variables of an assessment item in the test context.\n * - Matches the assessment item with the corresponding test context item.\n * - If the item is not found, logs a warning.\n * - Updates variables in the test context if exactly one variable exists.\n * - Otherwise, syncs the assessment item's variables with the test context.\n *\n * @param assessmentItem - The assessment item to update.\n */\n private _updateItemInTestContext = (assessmentItem: QtiAssessmentItem): void => {\n const context = assessmentItem.itemContext;\n const identifier = context.identifier;\n const fullVariables = context.variables;\n\n // Find the corresponding item in the test context by identifier\n const itemContext = this.testContext.items.find(i => i?.identifier === identifier);\n\n if (!itemContext) {\n console.warn(`Item IDs between assessment.xml and item.xml should match: ${identifier} is not found!`);\n return;\n }\n\n // Update variables in the test context or sync them to the assessment item\n if (itemContext.variables?.length === 1) {\n // The loaded qti-assessment-item itself has variables which are not in test context yet.\n this._updateItemVariablesInTestContext(identifier, fullVariables, undefined, context.valid);\n } else {\n const newVariables = [...assessmentItem.variables];\n // Sync the assessment item's variables with the test context\n for (const variable of itemContext.variables) {\n // Presenting an item starts its first attempt, so it is no longer `not_attempted` once it\n // is on screen: the item keeps its own status (`unknown`) — `qti-number-presented` reads it.\n if (variable.identifier === 'completionStatus' && variable.value === 'not_attempted') continue;\n const currentVariable = newVariables.find(v => v.identifier === variable.identifier);\n if (currentVariable) {\n currentVariable.value = variable.value;\n } else {\n newVariables.push(variable);\n }\n }\n assessmentItem.variables = newVariables;\n this.#leaveNotAttempted(identifier, newVariables.find(v => v.identifier === 'completionStatus')?.value);\n // Opaque interaction state (a PCI's getState()) is read from the item context when the\n // interaction initializes, so it has to be in place now, before that happens.\n if (itemContext.state) {\n assessmentItem.state = itemContext.state;\n }\n }\n };\n\n /** Write the presented item's own status over a `not_attempted` the test context still holds for it. */\n #leaveNotAttempted(identifier: string, status: Readonly<string | string[] | null> | undefined): void {\n if (typeof status !== 'string' || status === 'not_attempted') return;\n const item = this.testContext.items.find(i => i.identifier === identifier);\n const current = item?.variables.find(v => v.identifier === 'completionStatus');\n if (current?.value !== 'not_attempted') return;\n this.testContext = {\n ...this.testContext,\n items: this.testContext.items.map(i =>\n i.identifier !== identifier\n ? i\n : {\n ...i,\n variables: i.variables.map(v => (v.identifier === 'completionStatus' ? { ...v, value: status } : v))\n }\n )\n };\n }\n }\n\n return TestBaseClass as Constructor<TestBaseInterface> & T;\n};\n\n// Keep the old abstract class for backwards compatibility during migration\nexport abstract class TestBase extends TestBaseMixin(LitElement) {}\n"]}
@@ -170,6 +170,18 @@ export const TestNavigationMixin = (superClass) => {
170
170
  this.navigateTo(this.navigate, id);
171
171
  }
172
172
  }
173
+ /** The current item, when this request is a Next step from it in a linear part; else undefined. */
174
+ _linearNextLeaves(type, id) {
175
+ if (type !== 'item' || !this._testElement)
176
+ return undefined;
177
+ const refs = [...this._testElement.querySelectorAll('qti-assessment-item-ref')];
178
+ const current = refs.findIndex(ref => idOf(ref) === this.sessionContext?.navItemRefId);
179
+ if (current < 0 || !refs[current + 1] || idOf(refs[current + 1]) !== id)
180
+ return undefined;
181
+ if (refs[current].closest('qti-test-part')?.getAttribute('navigation-mode') !== 'linear')
182
+ return undefined;
183
+ return idOf(refs[current]);
184
+ }
173
185
  _isLinearNavigationRestricted(type, targetId) {
174
186
  const currentItemId = this.sessionContext?.navItemRefId;
175
187
  if (!currentItemId)
@@ -223,6 +235,16 @@ export const TestNavigationMixin = (superClass) => {
223
235
  async _handleNavigationRequest({ detail }) {
224
236
  if (!detail?.id)
225
237
  return;
238
+ // A Next in a linear part leaves the current item for good: its attempt ends now, while it is
239
+ // rendered, or the navigation is refused (roadmap 1, T3b2b). Before the end-of-test check, so
240
+ // the last item is submitted too.
241
+ const leaving = this._linearNextLeaves(detail.type, detail.id);
242
+ const refusal = leaving ? (this.beforeLinearNext?.(leaving) ?? null) : null;
243
+ if (refusal) {
244
+ const error = Object.assign(new Error(`Item ${refusal.itemId} may not be left yet: ${refusal.reason}`), refusal);
245
+ this._handleNavigationError(error, detail.type, detail.id);
246
+ return;
247
+ }
226
248
  const resolved = this._resolveLinearNext(detail.type, detail.id);
227
249
  if (resolved?.id === null) {
228
250
  if (resolved.skipped.length)
@@ -1 +1 @@
1
- {"version":3,"file":"test-navigation.mixin.js","sourceRoot":"","sources":["../../src/mixins/test-navigation.mixin.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAEpD,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAEhE,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAClE,OAAO,EAAE,IAAI,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AACtF,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AA2DhE;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAA2C,UAAa,EAAE,EAAE;IAC7F,MAAe,mBAAoB,SAAQ,UAAU;QAkCnD,YAAY,GAAG,IAAW;YACxB,KAAK,CAAC,GAAG,IAAI,CAAC,CAAC;YAlCW,aAAQ,GAA8B,IAAI,CAAC;YAC3C,mBAAc,GAAW,KAAK,CAAC;YAC3B,8BAAyB,GAAqC,IAAI,CAAC;YACnE,kCAA6B,GAAyC,IAAI,CAAC;YAI3G;;;eAGG;YAGO,cAAS,GAAmB,IAAI,GAAG,EAAE,CAAC;YAEhD,4BAA4B;YACpB,sBAAiB,GAA2B,IAAI,CAAC;YACjD,iBAAY,GAAU,EAAE,CAAC;YACzB,kBAAa,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AAI,EAAE,2BAA2B,EAAE,KAAK,CAAC,CAAC;QAC3D,CAAC;QAED,qHAAqH;QAC7G,mBAAmB,CAAC,OAAc,EAAE,IAAwB,EAAE,EAAU;YAC9E,qBAAqB,CAAC,GAAG,EAAE;gBACzB,cAAc,CACZ,IAAI,EACJ,kBAAkB,EAClB,OAAO,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,CAAC;oBAC5B,UAAU,EAAE,OAAO,EAAE,UAAU;oBAC/B,OAAO,EAAE,OAAO;iBACjB,CAAC,CAAC,CACJ,CAAC;gBACF,cAAc,CAAC,IAAI,EAAE,mBAAmB,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC;YAC1D,CAAC,CAAC,CAAC;QACL,CAAC;KACF;IA5pB6B;QAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;yDAA4C;IAC3C;QAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;+DAAgC;IAC3B;QAA/B,QAAQ,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;0EAAoE;IACnE;QAA/B,QAAQ,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;8EAA4E;IAUjG;QAFT,KAAK,EAAE;QACP,OAAO,CAAC,EAAE,OAAO,EAAE,gBAAgB,EAAE,CAAC;0DACS;IAipBlD,OAAO,mBAA4D,CAAC;AACtE,CAAC,CAAC","sourcesContent":["import { provide } from '@lit/context';\nimport { property, state } from 'lit/decorators.js';\n\nimport { readItemFacts } from '@qti-components/delivery';\nimport { qtiTransformItem } from '@qti-components/transformers';\n\nimport { itemFactsContext } from '../internal/item-facts.context';\nimport { idOf, resolveFirstItem, resolveNextItem } from '../internal/item-sequencing';\nimport { dispatchPublic, listenPublic } from '../public-events';\n\nimport type { QtiAssessmentStimulusRefConnectedEvent } from '@qti-components/elements';\nimport type { QtiAssessmentItem } from '@qti-components/elements';\nimport type { transformItemApi, transformTestApi } from '@qti-components/transformers';\nimport type { QtiAssessmentItemRef } from '../components/qti-assessment-item-ref/qti-assessment-item-ref';\nimport type { QtiAssessmentSection } from '../components/qti-assessment-section/qti-assessment-section';\nimport type { QtiAssessmentTest } from '../components/qti-assessment-test/qti-assessment-test';\nimport type { TestContainer } from '../components/test-container/test-container';\nimport type { PostLoadTestTransformCallback } from '../internal/test-host.context';\nimport type { ItemFactsByRef } from '../internal/item-facts.context';\nimport type { TestBaseInterface } from './test-base';\n\ntype Constructor<T = {}> = abstract new (...args: any[]) => T;\n\nexport type PostLoadTransformCallback = (\n transformer: transformItemApi,\n itemRef: QtiAssessmentItemRef\n) => transformItemApi | Promise<transformItemApi>;\n\nexport type { PostLoadTestTransformCallback };\n\nexport interface NavigationError {\n message: string;\n details?: any;\n itemId?: string;\n sectionId?: string;\n}\n\n/**\n * Exactly what this mixin adds. `IQtiTest` composes it (see ../types/iqti-test, which\n * re-exports it), and `TestNavigationClass` below `implements` it, so the interface and the\n * class cannot drift apart.\n *\n * This was `declare class TestNavigationInterface {}` — EMPTY — so the returned\n * `Constructor<TestNavigationInterface> & T` added nothing and every member the mixin\n * contributes was erased from the public type. `QtiTest` looked as though it had no\n * `navigate` or `postLoadTransformCallback`, and consumers had to intersect the class with\n * `IQtiTest` by hand to describe one element.\n *\n * `showLoadingIndicators` and `retryNavigation` used to be listed on the `IQtiTest` side with\n * no implementation anywhere in the repo, so calling `retryNavigation()` would have thrown.\n * They are gone rather than stubbed: there was no behaviour to preserve.\n */\nexport interface ITestNavigationMixin {\n navigate: 'item' | 'section' | null;\n requestTimeout: number;\n postLoadTransformCallback: PostLoadTransformCallback | null;\n postLoadTestTransformCallback: PostLoadTestTransformCallback | null;\n navigateTo(type: 'item' | 'section', id?: string): void;\n getLoadingProgress(): {\n expectedItems: number;\n connectedItems: number;\n expectedStimulus: number;\n loadedStimulus: number;\n isComplete: boolean;\n };\n}\n\n/**\n * Navigation mixin for QTI test components\n *\n * Provides comprehensive navigation functionality with:\n * - Efficient item/section loading with AbortController support\n * - Stimulus reference coordination and duplicate prevention\n * - Proper event timing and state management\n * - Error handling and edge case coverage\n */\nexport const TestNavigationMixin = <T extends Constructor<TestBaseInterface>>(superClass: T) => {\n abstract class TestNavigationClass extends superClass implements ITestNavigationMixin {\n @property({ type: String }) navigate: 'item' | 'section' | null = null;\n @property({ type: Number }) requestTimeout: number = 30000;\n @property({ attribute: false }) postLoadTransformCallback: PostLoadTransformCallback | null = null;\n @property({ attribute: false }) postLoadTestTransformCallback: PostLoadTestTransformCallback | null = null;\n\n public _testElement: QtiAssessmentTest;\n\n /**\n * The facts of every item fetched so far, by item-ref identifier, read from the item XML in\n * `_loadSingleItem`. Kept across navigation; a new test starts empty. @internal\n */\n @state()\n @provide({ context: itemFactsContext })\n protected itemFacts: ItemFactsByRef = new Map();\n\n // Navigation state tracking\n private _activeController: AbortController | null = null;\n private _loadResults: any[] = [];\n private _navigationId = 0;\n\n // Simple loading progress tracking\n private _loadingState = {\n expectedItems: 0,\n connectedItems: 0,\n expectedStimulus: 0,\n loadedStimulus: 0,\n isComplete: false\n };\n\n // Track loaded/loading stimulus hrefs to prevent duplicates\n private _loadedStimulusHrefs = new Set<string>();\n private _loadingStimulusHrefs = new Set<string>();\n\n constructor(...args: any[]) {\n super(...args);\n this._bindEventHandlers();\n }\n\n // ===========================================\n // PUBLIC API\n // ===========================================\n\n /**\n * Navigate to a specific item or section\n * @param type - Navigation type ('item' or 'section')\n * @param id - Target identifier (optional, falls back to the current position, or the first one before there is any)\n */\n public navigateTo(type: 'item' | 'section', id?: string): void {\n const targetId = id || this._getDefaultNavigationId(type);\n\n if (targetId) {\n dispatchPublic(this, 'qc-test-navigate', { type, id: targetId });\n }\n }\n\n // ===========================================\n // EVENT HANDLER SETUP\n // ===========================================\n\n private _bindEventHandlers(): void {\n listenPublic(this, 'qc-test-navigate', this._handleNavigationRequest.bind(this));\n listenPublic(this, 'qc-test-loaded', this._handleTestConnected.bind(this));\n this.addEventListener('qti-assessment-item-connected', this._handleItemConnected.bind(this));\n this.addEventListener('qti-assessment-stimulus-ref-connected', this._handleStimulusRefConnected.bind(this));\n }\n\n private _handleTestConnected(e: CustomEvent<QtiAssessmentTest>): void {\n this._testElement = e.detail;\n this.itemFacts = new Map();\n this._initializeNavigation();\n }\n\n /**\n * Handle item connection events - track connected items and discover stimulus references\n */\n private _handleItemConnected(e: CustomEvent<QtiAssessmentItemRef>): void {\n const itemRef = e.detail;\n\n // Increment connected items count\n this._loadingState.connectedItems++;\n\n // Count stimulus references in this item and add to expected\n const stimulusRefs = itemRef.querySelectorAll('qti-assessment-stimulus-ref');\n this._loadingState.expectedStimulus += stimulusRefs.length;\n\n this._checkLoadingComplete();\n }\n\n /**\n * Handle stimulus reference connection events with duplicate prevention\n */\n private async _handleStimulusRefConnected(e: QtiAssessmentStimulusRefConnectedEvent): Promise<void> {\n e.preventDefault();\n\n const { element, item } = e;\n console.info('Stimulus ref connected:', {\n identifier: element.identifier,\n href: element.href,\n item: item.identifier\n });\n\n // Check if this stimulus href is already loaded or currently loading\n if (this._loadedStimulusHrefs.has(element.href)) {\n console.info('Stimulus already loaded, skipping:', element.href);\n this._loadingState.loadedStimulus++;\n this._checkLoadingComplete();\n return;\n }\n\n if (this._loadingStimulusHrefs.has(element.href)) {\n console.info('Stimulus already loading, skipping duplicate:', element.href);\n this._loadingState.loadedStimulus++;\n this._checkLoadingComplete();\n return;\n }\n\n // Mark as currently loading\n this._loadingStimulusHrefs.add(element.href);\n console.info('Starting stimulus load:', element.href);\n\n try {\n await this._loadStimulusRef(element, item);\n this._loadedStimulusHrefs.add(element.href);\n this._loadingState.loadedStimulus++;\n console.info('Stimulus loaded successfully:', element.href);\n this._checkLoadingComplete();\n } catch (error) {\n if (error.name !== 'AbortError') {\n console.warn(`Failed to load stimulus ${element.identifier}:`, error);\n }\n // Still count as \"processed\" even if failed to avoid hanging\n this._loadingState.loadedStimulus++;\n this._checkLoadingComplete();\n } finally {\n // Remove from loading set regardless of outcome\n this._loadingStimulusHrefs.delete(element.href);\n }\n }\n\n // ===========================================\n // NAVIGATION FLOW\n // ===========================================\n\n private _getDefaultNavigationId(type: 'item' | 'section'): string | undefined {\n if (type === 'section') {\n return (\n this.sessionContext?.navSectionId ??\n this._testElement?.querySelector<QtiAssessmentSection>('qti-assessment-section')?.identifier\n );\n }\n return (\n this.sessionContext?.navItemRefId ??\n this._testElement?.querySelector<QtiAssessmentItemRef>('qti-assessment-item-ref')?.identifier\n );\n }\n\n private _initializeNavigation(): void {\n if (!this.navigate) return;\n\n let id = this._getDefaultNavigationId(this.navigate);\n if (this.navigate === 'item' && this._testElement && !this.sessionContext?.navItemRefId) {\n // a fresh start: the first item of a linear part may itself have a false pre-condition\n const refs = [...this._testElement.querySelectorAll('qti-assessment-item-ref')];\n if (refs[0]?.closest('qti-test-part')?.getAttribute('navigation-mode') === 'linear') {\n const first = resolveFirstItem(refs);\n if (first.skipped.length) dispatchPublic(this, 'qc-test-items-skipped', { ids: first.skipped });\n if (first.id === null) {\n dispatchPublic(this, 'qc-test-end-reached', {});\n return;\n }\n id = first.id;\n }\n }\n if (id) {\n this.navigateTo(this.navigate, id);\n }\n }\n\n private _isLinearNavigationRestricted(type: 'item' | 'section', targetId: string): boolean {\n const currentItemId = this.sessionContext?.navItemRefId;\n if (!currentItemId) return false;\n\n // Never restrict navigating to the same item\n if (type === 'item' && targetId === currentItemId) return false;\n\n const currentItemRef = this._testElement?.querySelector(`qti-assessment-item-ref[identifier=\"${currentItemId}\"]`);\n if (!currentItemRef) return false;\n\n // QTI defines navigation-mode on the test part only.\n if (currentItemRef.closest('qti-test-part')?.getAttribute('navigation-mode') !== 'linear') return false;\n\n const allItemRefs = Array.from(\n this._testElement?.querySelectorAll('qti-assessment-item-ref') || []\n ) as QtiAssessmentItemRef[];\n const currentIndex = allItemRefs.findIndex(ref => ref.identifier === currentItemId);\n\n if (type === 'item') {\n const targetIndex = allItemRefs.findIndex(ref => ref.identifier === targetId);\n if (targetIndex === -1 || currentIndex === -1) return false;\n\n // Only allow moving to the next item in linear mode\n return targetIndex !== currentIndex + 1;\n }\n\n // Sections are generally restricted in linear mode unless we are moving to the next one\n return true;\n }\n\n /**\n * A \"next\" step in a linear test part (a request for item i+1 while item i is active) goes\n * through the branch rules and pre-conditions. Deep links, item links and nonlinear parts are\n * left alone: the spec ignores both in nonlinear mode.\n *\n * @returns the item to present instead, `null` when the test has no eligible item left, or\n * `undefined` when the request is not a \"next\" step.\n */\n private _resolveLinearNext(\n type: 'item' | 'section',\n id: string\n ): { id: string | null; skipped: string[] } | undefined {\n if (type !== 'item' || !this._testElement) return undefined;\n\n const refs = [...this._testElement.querySelectorAll('qti-assessment-item-ref')];\n const current = refs.findIndex(ref => idOf(ref) === this.sessionContext?.navItemRefId);\n if (current < 0 || !refs[current + 1] || idOf(refs[current + 1]) !== id) return undefined;\n if (refs[current].closest('qti-test-part')?.getAttribute('navigation-mode') !== 'linear') return undefined;\n\n const next = resolveNextItem(refs, current);\n if (next.id === id) return undefined;\n\n return next;\n }\n\n /**\n * Main navigation request handler with proper lifecycle management\n */\n private async _handleNavigationRequest({ detail }: CustomEvent<{ type: 'item' | 'section'; id: string }>) {\n if (!detail?.id) return;\n\n const resolved = this._resolveLinearNext(detail.type, detail.id);\n if (resolved?.id === null) {\n if (resolved.skipped.length) dispatchPublic(this, 'qc-test-items-skipped', { ids: resolved.skipped });\n dispatchPublic(this, 'qc-test-end-reached', {});\n return;\n }\n const target = resolved?.id ?? detail.id;\n // a resolved jump is not a free choice by the candidate, so the linear restriction does not apply to it\n if (!resolved && this._isLinearNavigationRestricted(detail.type, target)) {\n this._handleNavigationError(new Error('Navigation restricted in linear mode'), detail.type, detail.id);\n return;\n }\n\n this._cancelPreviousNavigation();\n const navigationId = ++this._navigationId;\n const controller = new AbortController();\n\n try {\n this._dispatchLoadingStarted(detail.type, target);\n this._activeController = controller;\n\n await this._executeNavigation(detail.type, target, navigationId, controller);\n // only tell hosts about skipped items once the jump went through\n if (resolved?.skipped.length && navigationId === this._navigationId && !controller.signal.aborted) {\n dispatchPublic(this, 'qc-test-items-skipped', { ids: resolved.skipped });\n }\n } catch (error) {\n this._handleNavigationError(error, detail.type, target);\n } finally {\n if (this._activeController === controller) {\n this._activeController = null;\n }\n this._dispatchLoadingEnded(detail.type, target);\n }\n }\n\n private _handleNavigationError(error: any, type: string, id: string): void {\n if (error.name !== 'AbortError') {\n this._dispatchError(this._createNavigationError(error, type, id));\n }\n }\n\n private async _executeNavigation(\n type: 'item' | 'section',\n id: string,\n navigationId: number,\n controller: AbortController\n ): Promise<void> {\n if (type === 'item') {\n await this._navigateToItem(id, navigationId, controller);\n } else {\n await this._navigateToSection(id, navigationId, controller);\n }\n }\n\n /**\n * Navigate to specific item with simple state tracking\n */\n private async _navigateToItem(itemId: string, navigationId: number, controller: AbortController): Promise<void> {\n const itemRef = this._findItemRef(itemId);\n this._updateSessionContext(itemRef, itemId);\n\n this._resetLoadingState();\n this._loadingState.expectedItems = 1;\n\n await this._loadItems([itemId], navigationId, controller);\n await this._waitForLoadingComplete(navigationId, controller);\n if (this._isStaleNavigation(navigationId, controller)) return;\n\n this._dispatchTestLoaded(this._loadResults, 'item', itemId);\n }\n\n /**\n * Navigate to section with simple state tracking\n */\n private async _navigateToSection(\n sectionId: string,\n navigationId: number,\n controller: AbortController\n ): Promise<void> {\n const sectionEl = this._findSection(sectionId);\n const navPartId = sectionEl?.closest('qti-test-part')?.identifier;\n const itemIds = this._getSectionItemIds(sectionId);\n\n this.sessionContext = {\n ...this.sessionContext,\n navPartId,\n navSectionId: sectionId,\n // with navigate=\"item\", the section's first item is the current position, so test-next/test-prev\n // and item highlights have an item to work from\n navItemRefId: this.navigate === 'item' ? (itemIds[0] ?? null) : null\n };\n\n this._resetLoadingState();\n this._loadingState.expectedItems = itemIds.length;\n\n await this._loadItems(itemIds, navigationId, controller);\n await this._waitForLoadingComplete(navigationId, controller);\n if (this._isStaleNavigation(navigationId, controller)) return;\n\n this._dispatchTestLoaded(this._loadResults, 'section', sectionId);\n }\n\n // ===========================================\n // LOADING STATE MANAGEMENT\n // ===========================================\n\n /**\n * Reset loading state for new navigation\n */\n private _resetLoadingState(): void {\n this._loadingState = {\n expectedItems: 0,\n connectedItems: 0,\n expectedStimulus: 0,\n loadedStimulus: 0,\n isComplete: false\n };\n\n // Clear stimulus tracking - start fresh for new navigation\n this._loadedStimulusHrefs.clear();\n this._loadingStimulusHrefs.clear();\n }\n\n /**\n * Check if loading is complete and dispatch events accordingly\n */\n private _checkLoadingComplete(): void {\n const allItemsConnected = this._loadingState.connectedItems >= this._loadingState.expectedItems;\n const allStimulusLoaded = this._loadingState.loadedStimulus >= this._loadingState.expectedStimulus;\n\n if (allItemsConnected && allStimulusLoaded && !this._loadingState.isComplete) {\n this._loadingState.isComplete = true;\n }\n }\n\n /**\n * Wait for loading to complete with simple polling\n */\n private async _waitForLoadingComplete(navigationId: number, controller: AbortController): Promise<void> {\n while (!this._loadingState.isComplete) {\n if (this._isStaleNavigation(navigationId, controller)) return;\n await new Promise(resolve => setTimeout(resolve, 10));\n }\n }\n\n /**\n * Get current loading progress for external consumption\n */\n public getLoadingProgress() {\n return { ...this._loadingState };\n }\n\n /**\n * Load stimulus reference with simple tracking\n */\n private async _loadStimulusRef(\n element: { identifier: string; href: string },\n item: QtiAssessmentItem\n ): Promise<void> {\n console.info('Loading stimulus:', element.href);\n const stimulus = await this._loadStimulus(element.href);\n console.info('Stimulus loaded, applying content:', stimulus ? 'has content' : 'no content');\n this._applyStimulusContent(stimulus, element, item);\n }\n\n private _applyStimulusContent(\n stimulus: DocumentFragment | null,\n element: { identifier: string },\n item: QtiAssessmentItem\n ): void {\n if (!stimulus) {\n console.warn('No stimulus content to apply');\n return;\n }\n\n // Place the whole qti-assessment-stimulus, not just its body: its `lang` is what the stimulus\n // content inherits its language from.\n const root = stimulus.querySelector('qti-assessment-stimulus');\n\n if (!root) {\n console.warn('No qti-assessment-stimulus element found in stimulus');\n return;\n }\n\n // Try multiple target selection strategies\n let targets: Element[] = [];\n\n // Strategy 1: Search inside the actual item element first.\n // This keeps stimulus placement working when items are rendered in a shadow root.\n const specificTarget = item.querySelector(`[data-stimulus-idref=\"${element.identifier}\"]`);\n\n if (specificTarget) {\n targets.push(specificTarget);\n console.info('Found specific target:', specificTarget);\n } else {\n // Strategy 2: Any element with matching stimulus idref\n const allTargetsWithId = Array.from(this.querySelectorAll(`[data-stimulus-idref=\"${element.identifier}\"]`));\n\n if (allTargetsWithId.length > 0) {\n targets = allTargetsWithId;\n console.info('Found targets by identifier:', allTargetsWithId.length);\n } else {\n // Strategy 3: Any stimulus idref target (fallback)\n const allStimulusTargets = Array.from(this.querySelectorAll('[data-stimulus-idref]'));\n targets = allStimulusTargets;\n console.info('Using fallback targets:', allStimulusTargets.length);\n }\n }\n\n if (targets.length === 0) {\n console.warn('No targets found for stimulus content');\n return;\n }\n\n // Apply content to all targets\n targets.forEach((target, index) => {\n target.innerHTML = '';\n target.append(root.cloneNode(true));\n console.info(`Applied stimulus content to target ${index + 1}/${targets.length}`);\n });\n } // ===========================================\n // LOADING INFRASTRUCTURE\n // ===========================================\n\n /**\n * Cancel previous navigation and clean up all state\n */\n private _cancelPreviousNavigation(): void {\n if (this._activeController) {\n this._activeController.abort();\n console.info('Previous navigation request cancelled');\n }\n\n this._clearNavigationState();\n }\n\n private _clearNavigationState(): void {\n this._clearLoadedItems();\n this._resetLoadingState();\n this._loadResults = [];\n }\n\n /**\n * Load items with simple tracking\n */\n private async _loadItems(itemIds: string[], navigationId: number, controller: AbortController): Promise<void> {\n if (!this._testElement || itemIds.length === 0) return;\n\n const itemRefs = itemIds.map(id => this._findItemRef(id));\n this._clearLoadedItems();\n this._clearStimulusRef();\n\n const results = await Promise.all(itemRefs.map(ref => this._loadSingleItem(ref, navigationId, controller)));\n const validResults = results.filter(Boolean);\n\n if (this._isStaleNavigation(navigationId, controller)) return;\n\n const itemFacts = new Map(this.itemFacts);\n validResults.forEach(({ itemRef, doc, facts }) => {\n if (itemRef && doc) itemRef.xmlDoc = doc;\n if (itemRef && facts) itemFacts.set(itemRef.identifier, facts);\n });\n this.itemFacts = itemFacts;\n\n // Restore per-item state as early as possible (before iframe-based interactions initialize).\n // Some PCIs (including IMS conformance examples) only support restoration via getInstance(state),\n // so the state needs to be present on the provided itemContext at initial render time.\n validResults.forEach(({ itemRef }) => {\n const itemId = itemRef?.identifier;\n if (!itemRef || !itemId) return;\n\n const savedState = this.testContext.items.find(i => i.identifier === itemId)?.state;\n if (savedState === undefined) return;\n\n itemRef.updateComplete.then(() => {\n const assessmentItem = itemRef.assessmentItem as QtiAssessmentItem | null;\n if (!assessmentItem) return;\n assessmentItem.state = savedState;\n });\n });\n\n this._loadResults = validResults;\n }\n\n private async _loadSingleItem(itemRef: QtiAssessmentItemRef, navigationId: number, controller: AbortController) {\n try {\n // The same seed `test-container` shuffled the item order with.\n const seed = this.qtiContext?.QTI_CONTEXT?.seed;\n let transformer = (await qtiTransformItem().load(itemRef.href, controller.signal)).shuffleInteractions(seed);\n\n if (this.postLoadTransformCallback) {\n transformer = await this.postLoadTransformCallback(transformer, itemRef);\n }\n\n if (this._isStaleNavigation(navigationId, controller)) {\n return null;\n }\n\n // The facts come from the XML as it will be rendered: after the host's transform.\n const item = transformer.xmlDoc().documentElement;\n const facts = item?.localName === 'qti-assessment-item' ? readItemFacts(item) : null;\n return { itemRef, doc: transformer.htmlDoc(this._customElementRegistry()), facts };\n } catch (error) {\n if (error.name === 'AbortError') {\n console.info(`Item load for ${itemRef.identifier} was aborted`);\n throw error;\n }\n console.warn(`Failed to load item ${itemRef.identifier}:`, error);\n return null;\n }\n }\n\n private async _loadStimulus(href: string): Promise<DocumentFragment | null> {\n const transformer = await qtiTransformItem().load(href, this._activeController?.signal);\n return transformer.htmlDoc(this._customElementRegistry());\n }\n\n private _customElementRegistry(): CustomElementRegistry | undefined {\n const container = this.querySelector<TestContainer>('test-container');\n if (!container) return undefined;\n return container.customElementRegistry ?? undefined;\n }\n\n // ===========================================\n // UTILITIES\n // ===========================================\n\n private _findItemRef(itemId: string): QtiAssessmentItemRef {\n const itemRef = this._testElement?.querySelector<QtiAssessmentItemRef>(\n `qti-assessment-item-ref[identifier=\"${itemId}\"]`\n );\n\n if (!itemRef) {\n throw new Error(`Item with identifier \"${itemId}\" not found`);\n }\n\n return itemRef;\n }\n\n private _findSection(sectionId: string): QtiAssessmentSection | null {\n return (\n this._testElement?.querySelector<QtiAssessmentSection>(`qti-assessment-section[identifier=\"${sectionId}\"]`) ||\n null\n );\n }\n\n private _updateSessionContext(itemRef: QtiAssessmentItemRef, itemId: string): void {\n const navPartId = itemRef.closest('qti-test-part')?.identifier;\n const navSectionId = itemRef.closest('qti-assessment-section')?.identifier;\n\n this.sessionContext = {\n ...this.sessionContext,\n navPartId,\n navSectionId,\n navItemRefId: itemId\n };\n }\n\n private _getSectionItemIds(sectionId: string): string[] {\n return Array.from(\n this._testElement.querySelectorAll<QtiAssessmentItemRef>(\n `qti-assessment-section[identifier=\"${sectionId}\"] > qti-assessment-item-ref`\n )\n )\n .map(ref => ref.identifier)\n .filter(Boolean);\n }\n\n private _clearLoadedItems(): void {\n const itemRefs = this._testElement?.querySelectorAll<QtiAssessmentItemRef>('qti-assessment-item-ref');\n Array.from(itemRefs || []).forEach(element => {\n element.xmlDoc = null;\n });\n }\n\n private _clearStimulusRef(): void {\n this.querySelectorAll('[data-stimulus-idref]').forEach(el => (el.innerHTML = ''));\n }\n\n private _isStaleNavigation(navigationId: number, controller: AbortController): boolean {\n return controller.signal.aborted || navigationId !== this._navigationId;\n }\n\n private _createNavigationError(error: any, type: string, id: string): NavigationError {\n return {\n message: error.message || `Failed to load ${type}: ${id}`,\n details: error,\n itemId: type === 'item' ? id : undefined,\n sectionId: type === 'section' ? id : undefined\n };\n }\n\n // ===========================================\n // EVENT DISPATCHING\n // ===========================================\n\n private _dispatchLoadingStarted(type: string, id: string): void {\n dispatchPublic(this, 'qc-test-navigation-started', { type: type as 'item' | 'section', id });\n }\n\n private _dispatchLoadingEnded(type: string, id: string): void {\n this.dispatchEvent(\n new CustomEvent('qti-navigation-loading-ended', {\n detail: { type, id },\n bubbles: true,\n composed: true\n })\n );\n }\n\n private _dispatchError(error: NavigationError): void {\n dispatchPublic(this, 'qc-test-navigation-failed', error);\n }\n\n /** The items are in the DOM: tell hosts the new position rendered (`qc-test-navigated`) and which items it holds. */\n private _dispatchTestLoaded(results: any[], type: 'item' | 'section', id: string): void {\n requestAnimationFrame(() => {\n dispatchPublic(\n this,\n 'qc-test-rendered',\n results.map(({ itemRef }) => ({\n identifier: itemRef?.identifier,\n element: itemRef\n }))\n );\n dispatchPublic(this, 'qc-test-navigated', { type, id });\n });\n }\n }\n\n return TestNavigationClass as Constructor<ITestNavigationMixin> & T;\n};\n"]}
1
+ {"version":3,"file":"test-navigation.mixin.js","sourceRoot":"","sources":["../../src/mixins/test-navigation.mixin.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAEpD,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAEhE,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAClE,OAAO,EAAE,IAAI,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AACtF,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AA2DhE;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAA2C,UAAa,EAAE,EAAE;IAC7F,MAAe,mBAAoB,SAAQ,UAAU;QAyCnD,YAAY,GAAG,IAAW;YACxB,KAAK,CAAC,GAAG,IAAI,CAAC,CAAC;YAzCW,aAAQ,GAA8B,IAAI,CAAC;YAC3C,mBA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AAO,EAAE,gBAAgB,EAAE,CAAC;0DACS;IAgrBlD,OAAO,mBAA4D,CAAC;AACtE,CAAC,CAAC","sourcesContent":["import { provide } from '@lit/context';\nimport { property, state } from 'lit/decorators.js';\n\nimport { readItemFacts } from '@qti-components/delivery';\nimport { qtiTransformItem } from '@qti-components/transformers';\n\nimport { itemFactsContext } from '../internal/item-facts.context';\nimport { idOf, resolveFirstItem, resolveNextItem } from '../internal/item-sequencing';\nimport { dispatchPublic, listenPublic } from '../public-events';\n\nimport type { QtiAssessmentStimulusRefConnectedEvent } from '@qti-components/elements';\nimport type { QtiAssessmentItem } from '@qti-components/elements';\nimport type { transformItemApi, transformTestApi } from '@qti-components/transformers';\nimport type { QtiAssessmentItemRef } from '../components/qti-assessment-item-ref/qti-assessment-item-ref';\nimport type { QtiAssessmentSection } from '../components/qti-assessment-section/qti-assessment-section';\nimport type { QtiAssessmentTest } from '../components/qti-assessment-test/qti-assessment-test';\nimport type { TestContainer } from '../components/test-container/test-container';\nimport type { LinearNextRefusal, PostLoadTestTransformCallback } from '../internal/test-host.context';\nimport type { ItemFactsByRef } from '../internal/item-facts.context';\nimport type { TestBaseInterface } from './test-base';\n\ntype Constructor<T = {}> = abstract new (...args: any[]) => T;\n\nexport type PostLoadTransformCallback = (\n transformer: transformItemApi,\n itemRef: QtiAssessmentItemRef\n) => transformItemApi | Promise<transformItemApi>;\n\nexport type { PostLoadTestTransformCallback };\n\nexport interface NavigationError {\n message: string;\n details?: any;\n itemId?: string;\n sectionId?: string;\n}\n\n/**\n * Exactly what this mixin adds. `IQtiTest` composes it (see ../types/iqti-test, which\n * re-exports it), and `TestNavigationClass` below `implements` it, so the interface and the\n * class cannot drift apart.\n *\n * This was `declare class TestNavigationInterface {}` — EMPTY — so the returned\n * `Constructor<TestNavigationInterface> & T` added nothing and every member the mixin\n * contributes was erased from the public type. `QtiTest` looked as though it had no\n * `navigate` or `postLoadTransformCallback`, and consumers had to intersect the class with\n * `IQtiTest` by hand to describe one element.\n *\n * `showLoadingIndicators` and `retryNavigation` used to be listed on the `IQtiTest` side with\n * no implementation anywhere in the repo, so calling `retryNavigation()` would have thrown.\n * They are gone rather than stubbed: there was no behaviour to preserve.\n */\nexport interface ITestNavigationMixin {\n navigate: 'item' | 'section' | null;\n requestTimeout: number;\n postLoadTransformCallback: PostLoadTransformCallback | null;\n postLoadTestTransformCallback: PostLoadTestTransformCallback | null;\n navigateTo(type: 'item' | 'section', id?: string): void;\n getLoadingProgress(): {\n expectedItems: number;\n connectedItems: number;\n expectedStimulus: number;\n loadedStimulus: number;\n isComplete: boolean;\n };\n}\n\n/**\n * Navigation mixin for QTI test components\n *\n * Provides comprehensive navigation functionality with:\n * - Efficient item/section loading with AbortController support\n * - Stimulus reference coordination and duplicate prevention\n * - Proper event timing and state management\n * - Error handling and edge case coverage\n */\nexport const TestNavigationMixin = <T extends Constructor<TestBaseInterface>>(superClass: T) => {\n abstract class TestNavigationClass extends superClass implements ITestNavigationMixin {\n @property({ type: String }) navigate: 'item' | 'section' | null = null;\n @property({ type: Number }) requestTimeout: number = 30000;\n @property({ attribute: false }) postLoadTransformCallback: PostLoadTransformCallback | null = null;\n @property({ attribute: false }) postLoadTestTransformCallback: PostLoadTestTransformCallback | null = null;\n\n public _testElement: QtiAssessmentTest;\n\n /**\n * The facts of every item fetched so far, by item-ref identifier, read from the item XML in\n * `_loadSingleItem`. Kept across navigation; a new test starts empty. @internal\n */\n @state()\n @provide({ context: itemFactsContext })\n protected itemFacts: ItemFactsByRef = new Map();\n\n // Navigation state tracking\n private _activeController: AbortController | null = null;\n private _loadResults: any[] = [];\n private _navigationId = 0;\n\n /**\n * Set by `test-navigation` (`TestHost.beforeLinearNext`): ends the attempt of the item a linear\n * Next leaves, or says why it may not be left yet. Internal; not host API.\n * @internal\n */\n declare beforeLinearNext?: ((itemRefId: string) => LinearNextRefusal | null) | null;\n\n // Simple loading progress tracking\n private _loadingState = {\n expectedItems: 0,\n connectedItems: 0,\n expectedStimulus: 0,\n loadedStimulus: 0,\n isComplete: false\n };\n\n // Track loaded/loading stimulus hrefs to prevent duplicates\n private _loadedStimulusHrefs = new Set<string>();\n private _loadingStimulusHrefs = new Set<string>();\n\n constructor(...args: any[]) {\n super(...args);\n this._bindEventHandlers();\n }\n\n // ===========================================\n // PUBLIC API\n // ===========================================\n\n /**\n * Navigate to a specific item or section\n * @param type - Navigation type ('item' or 'section')\n * @param id - Target identifier (optional, falls back to the current position, or the first one before there is any)\n */\n public navigateTo(type: 'item' | 'section', id?: string): void {\n const targetId = id || this._getDefaultNavigationId(type);\n\n if (targetId) {\n dispatchPublic(this, 'qc-test-navigate', { type, id: targetId });\n }\n }\n\n // ===========================================\n // EVENT HANDLER SETUP\n // ===========================================\n\n private _bindEventHandlers(): void {\n listenPublic(this, 'qc-test-navigate', this._handleNavigationRequest.bind(this));\n listenPublic(this, 'qc-test-loaded', this._handleTestConnected.bind(this));\n this.addEventListener('qti-assessment-item-connected', this._handleItemConnected.bind(this));\n this.addEventListener('qti-assessment-stimulus-ref-connected', this._handleStimulusRefConnected.bind(this));\n }\n\n private _handleTestConnected(e: CustomEvent<QtiAssessmentTest>): void {\n this._testElement = e.detail;\n this.itemFacts = new Map();\n this._initializeNavigation();\n }\n\n /**\n * Handle item connection events - track connected items and discover stimulus references\n */\n private _handleItemConnected(e: CustomEvent<QtiAssessmentItemRef>): void {\n const itemRef = e.detail;\n\n // Increment connected items count\n this._loadingState.connectedItems++;\n\n // Count stimulus references in this item and add to expected\n const stimulusRefs = itemRef.querySelectorAll('qti-assessment-stimulus-ref');\n this._loadingState.expectedStimulus += stimulusRefs.length;\n\n this._checkLoadingComplete();\n }\n\n /**\n * Handle stimulus reference connection events with duplicate prevention\n */\n private async _handleStimulusRefConnected(e: QtiAssessmentStimulusRefConnectedEvent): Promise<void> {\n e.preventDefault();\n\n const { element, item } = e;\n console.info('Stimulus ref connected:', {\n identifier: element.identifier,\n href: element.href,\n item: item.identifier\n });\n\n // Check if this stimulus href is already loaded or currently loading\n if (this._loadedStimulusHrefs.has(element.href)) {\n console.info('Stimulus already loaded, skipping:', element.href);\n this._loadingState.loadedStimulus++;\n this._checkLoadingComplete();\n return;\n }\n\n if (this._loadingStimulusHrefs.has(element.href)) {\n console.info('Stimulus already loading, skipping duplicate:', element.href);\n this._loadingState.loadedStimulus++;\n this._checkLoadingComplete();\n return;\n }\n\n // Mark as currently loading\n this._loadingStimulusHrefs.add(element.href);\n console.info('Starting stimulus load:', element.href);\n\n try {\n await this._loadStimulusRef(element, item);\n this._loadedStimulusHrefs.add(element.href);\n this._loadingState.loadedStimulus++;\n console.info('Stimulus loaded successfully:', element.href);\n this._checkLoadingComplete();\n } catch (error) {\n if (error.name !== 'AbortError') {\n console.warn(`Failed to load stimulus ${element.identifier}:`, error);\n }\n // Still count as \"processed\" even if failed to avoid hanging\n this._loadingState.loadedStimulus++;\n this._checkLoadingComplete();\n } finally {\n // Remove from loading set regardless of outcome\n this._loadingStimulusHrefs.delete(element.href);\n }\n }\n\n // ===========================================\n // NAVIGATION FLOW\n // ===========================================\n\n private _getDefaultNavigationId(type: 'item' | 'section'): string | undefined {\n if (type === 'section') {\n return (\n this.sessionContext?.navSectionId ??\n this._testElement?.querySelector<QtiAssessmentSection>('qti-assessment-section')?.identifier\n );\n }\n return (\n this.sessionContext?.navItemRefId ??\n this._testElement?.querySelector<QtiAssessmentItemRef>('qti-assessment-item-ref')?.identifier\n );\n }\n\n private _initializeNavigation(): void {\n if (!this.navigate) return;\n\n let id = this._getDefaultNavigationId(this.navigate);\n if (this.navigate === 'item' && this._testElement && !this.sessionContext?.navItemRefId) {\n // a fresh start: the first item of a linear part may itself have a false pre-condition\n const refs = [...this._testElement.querySelectorAll('qti-assessment-item-ref')];\n if (refs[0]?.closest('qti-test-part')?.getAttribute('navigation-mode') === 'linear') {\n const first = resolveFirstItem(refs);\n if (first.skipped.length) dispatchPublic(this, 'qc-test-items-skipped', { ids: first.skipped });\n if (first.id === null) {\n dispatchPublic(this, 'qc-test-end-reached', {});\n return;\n }\n id = first.id;\n }\n }\n if (id) {\n this.navigateTo(this.navigate, id);\n }\n }\n\n /** The current item, when this request is a Next step from it in a linear part; else undefined. */\n private _linearNextLeaves(type: 'item' | 'section', id: string): string | undefined {\n if (type !== 'item' || !this._testElement) return undefined;\n const refs = [...this._testElement.querySelectorAll('qti-assessment-item-ref')];\n const current = refs.findIndex(ref => idOf(ref) === this.sessionContext?.navItemRefId);\n if (current < 0 || !refs[current + 1] || idOf(refs[current + 1]) !== id) return undefined;\n if (refs[current].closest('qti-test-part')?.getAttribute('navigation-mode') !== 'linear') return undefined;\n return idOf(refs[current]);\n }\n\n private _isLinearNavigationRestricted(type: 'item' | 'section', targetId: string): boolean {\n const currentItemId = this.sessionContext?.navItemRefId;\n if (!currentItemId) return false;\n\n // Never restrict navigating to the same item\n if (type === 'item' && targetId === currentItemId) return false;\n\n const currentItemRef = this._testElement?.querySelector(`qti-assessment-item-ref[identifier=\"${currentItemId}\"]`);\n if (!currentItemRef) return false;\n\n // QTI defines navigation-mode on the test part only.\n if (currentItemRef.closest('qti-test-part')?.getAttribute('navigation-mode') !== 'linear') return false;\n\n const allItemRefs = Array.from(\n this._testElement?.querySelectorAll('qti-assessment-item-ref') || []\n ) as QtiAssessmentItemRef[];\n const currentIndex = allItemRefs.findIndex(ref => ref.identifier === currentItemId);\n\n if (type === 'item') {\n const targetIndex = allItemRefs.findIndex(ref => ref.identifier === targetId);\n if (targetIndex === -1 || currentIndex === -1) return false;\n\n // Only allow moving to the next item in linear mode\n return targetIndex !== currentIndex + 1;\n }\n\n // Sections are generally restricted in linear mode unless we are moving to the next one\n return true;\n }\n\n /**\n * A \"next\" step in a linear test part (a request for item i+1 while item i is active) goes\n * through the branch rules and pre-conditions. Deep links, item links and nonlinear parts are\n * left alone: the spec ignores both in nonlinear mode.\n *\n * @returns the item to present instead, `null` when the test has no eligible item left, or\n * `undefined` when the request is not a \"next\" step.\n */\n private _resolveLinearNext(\n type: 'item' | 'section',\n id: string\n ): { id: string | null; skipped: string[] } | undefined {\n if (type !== 'item' || !this._testElement) return undefined;\n\n const refs = [...this._testElement.querySelectorAll('qti-assessment-item-ref')];\n const current = refs.findIndex(ref => idOf(ref) === this.sessionContext?.navItemRefId);\n if (current < 0 || !refs[current + 1] || idOf(refs[current + 1]) !== id) return undefined;\n if (refs[current].closest('qti-test-part')?.getAttribute('navigation-mode') !== 'linear') return undefined;\n\n const next = resolveNextItem(refs, current);\n if (next.id === id) return undefined;\n\n return next;\n }\n\n /**\n * Main navigation request handler with proper lifecycle management\n */\n private async _handleNavigationRequest({ detail }: CustomEvent<{ type: 'item' | 'section'; id: string }>) {\n if (!detail?.id) return;\n\n // A Next in a linear part leaves the current item for good: its attempt ends now, while it is\n // rendered, or the navigation is refused (roadmap 1, T3b2b). Before the end-of-test check, so\n // the last item is submitted too.\n const leaving = this._linearNextLeaves(detail.type, detail.id);\n const refusal = leaving ? (this.beforeLinearNext?.(leaving) ?? null) : null;\n if (refusal) {\n const error = Object.assign(\n new Error(`Item ${refusal.itemId} may not be left yet: ${refusal.reason}`),\n refusal\n );\n this._handleNavigationError(error, detail.type, detail.id);\n return;\n }\n\n const resolved = this._resolveLinearNext(detail.type, detail.id);\n if (resolved?.id === null) {\n if (resolved.skipped.length) dispatchPublic(this, 'qc-test-items-skipped', { ids: resolved.skipped });\n dispatchPublic(this, 'qc-test-end-reached', {});\n return;\n }\n const target = resolved?.id ?? detail.id;\n // a resolved jump is not a free choice by the candidate, so the linear restriction does not apply to it\n if (!resolved && this._isLinearNavigationRestricted(detail.type, target)) {\n this._handleNavigationError(new Error('Navigation restricted in linear mode'), detail.type, detail.id);\n return;\n }\n\n this._cancelPreviousNavigation();\n const navigationId = ++this._navigationId;\n const controller = new AbortController();\n\n try {\n this._dispatchLoadingStarted(detail.type, target);\n this._activeController = controller;\n\n await this._executeNavigation(detail.type, target, navigationId, controller);\n // only tell hosts about skipped items once the jump went through\n if (resolved?.skipped.length && navigationId === this._navigationId && !controller.signal.aborted) {\n dispatchPublic(this, 'qc-test-items-skipped', { ids: resolved.skipped });\n }\n } catch (error) {\n this._handleNavigationError(error, detail.type, target);\n } finally {\n if (this._activeController === controller) {\n this._activeController = null;\n }\n this._dispatchLoadingEnded(detail.type, target);\n }\n }\n\n private _handleNavigationError(error: any, type: string, id: string): void {\n if (error.name !== 'AbortError') {\n this._dispatchError(this._createNavigationError(error, type, id));\n }\n }\n\n private async _executeNavigation(\n type: 'item' | 'section',\n id: string,\n navigationId: number,\n controller: AbortController\n ): Promise<void> {\n if (type === 'item') {\n await this._navigateToItem(id, navigationId, controller);\n } else {\n await this._navigateToSection(id, navigationId, controller);\n }\n }\n\n /**\n * Navigate to specific item with simple state tracking\n */\n private async _navigateToItem(itemId: string, navigationId: number, controller: AbortController): Promise<void> {\n const itemRef = this._findItemRef(itemId);\n this._updateSessionContext(itemRef, itemId);\n\n this._resetLoadingState();\n this._loadingState.expectedItems = 1;\n\n await this._loadItems([itemId], navigationId, controller);\n await this._waitForLoadingComplete(navigationId, controller);\n if (this._isStaleNavigation(navigationId, controller)) return;\n\n this._dispatchTestLoaded(this._loadResults, 'item', itemId);\n }\n\n /**\n * Navigate to section with simple state tracking\n */\n private async _navigateToSection(\n sectionId: string,\n navigationId: number,\n controller: AbortController\n ): Promise<void> {\n const sectionEl = this._findSection(sectionId);\n const navPartId = sectionEl?.closest('qti-test-part')?.identifier;\n const itemIds = this._getSectionItemIds(sectionId);\n\n this.sessionContext = {\n ...this.sessionContext,\n navPartId,\n navSectionId: sectionId,\n // with navigate=\"item\", the section's first item is the current position, so test-next/test-prev\n // and item highlights have an item to work from\n navItemRefId: this.navigate === 'item' ? (itemIds[0] ?? null) : null\n };\n\n this._resetLoadingState();\n this._loadingState.expectedItems = itemIds.length;\n\n await this._loadItems(itemIds, navigationId, controller);\n await this._waitForLoadingComplete(navigationId, controller);\n if (this._isStaleNavigation(navigationId, controller)) return;\n\n this._dispatchTestLoaded(this._loadResults, 'section', sectionId);\n }\n\n // ===========================================\n // LOADING STATE MANAGEMENT\n // ===========================================\n\n /**\n * Reset loading state for new navigation\n */\n private _resetLoadingState(): void {\n this._loadingState = {\n expectedItems: 0,\n connectedItems: 0,\n expectedStimulus: 0,\n loadedStimulus: 0,\n isComplete: false\n };\n\n // Clear stimulus tracking - start fresh for new navigation\n this._loadedStimulusHrefs.clear();\n this._loadingStimulusHrefs.clear();\n }\n\n /**\n * Check if loading is complete and dispatch events accordingly\n */\n private _checkLoadingComplete(): void {\n const allItemsConnected = this._loadingState.connectedItems >= this._loadingState.expectedItems;\n const allStimulusLoaded = this._loadingState.loadedStimulus >= this._loadingState.expectedStimulus;\n\n if (allItemsConnected && allStimulusLoaded && !this._loadingState.isComplete) {\n this._loadingState.isComplete = true;\n }\n }\n\n /**\n * Wait for loading to complete with simple polling\n */\n private async _waitForLoadingComplete(navigationId: number, controller: AbortController): Promise<void> {\n while (!this._loadingState.isComplete) {\n if (this._isStaleNavigation(navigationId, controller)) return;\n await new Promise(resolve => setTimeout(resolve, 10));\n }\n }\n\n /**\n * Get current loading progress for external consumption\n */\n public getLoadingProgress() {\n return { ...this._loadingState };\n }\n\n /**\n * Load stimulus reference with simple tracking\n */\n private async _loadStimulusRef(\n element: { identifier: string; href: string },\n item: QtiAssessmentItem\n ): Promise<void> {\n console.info('Loading stimulus:', element.href);\n const stimulus = await this._loadStimulus(element.href);\n console.info('Stimulus loaded, applying content:', stimulus ? 'has content' : 'no content');\n this._applyStimulusContent(stimulus, element, item);\n }\n\n private _applyStimulusContent(\n stimulus: DocumentFragment | null,\n element: { identifier: string },\n item: QtiAssessmentItem\n ): void {\n if (!stimulus) {\n console.warn('No stimulus content to apply');\n return;\n }\n\n // Place the whole qti-assessment-stimulus, not just its body: its `lang` is what the stimulus\n // content inherits its language from.\n const root = stimulus.querySelector('qti-assessment-stimulus');\n\n if (!root) {\n console.warn('No qti-assessment-stimulus element found in stimulus');\n return;\n }\n\n // Try multiple target selection strategies\n let targets: Element[] = [];\n\n // Strategy 1: Search inside the actual item element first.\n // This keeps stimulus placement working when items are rendered in a shadow root.\n const specificTarget = item.querySelector(`[data-stimulus-idref=\"${element.identifier}\"]`);\n\n if (specificTarget) {\n targets.push(specificTarget);\n console.info('Found specific target:', specificTarget);\n } else {\n // Strategy 2: Any element with matching stimulus idref\n const allTargetsWithId = Array.from(this.querySelectorAll(`[data-stimulus-idref=\"${element.identifier}\"]`));\n\n if (allTargetsWithId.length > 0) {\n targets = allTargetsWithId;\n console.info('Found targets by identifier:', allTargetsWithId.length);\n } else {\n // Strategy 3: Any stimulus idref target (fallback)\n const allStimulusTargets = Array.from(this.querySelectorAll('[data-stimulus-idref]'));\n targets = allStimulusTargets;\n console.info('Using fallback targets:', allStimulusTargets.length);\n }\n }\n\n if (targets.length === 0) {\n console.warn('No targets found for stimulus content');\n return;\n }\n\n // Apply content to all targets\n targets.forEach((target, index) => {\n target.innerHTML = '';\n target.append(root.cloneNode(true));\n console.info(`Applied stimulus content to target ${index + 1}/${targets.length}`);\n });\n } // ===========================================\n // LOADING INFRASTRUCTURE\n // ===========================================\n\n /**\n * Cancel previous navigation and clean up all state\n */\n private _cancelPreviousNavigation(): void {\n if (this._activeController) {\n this._activeController.abort();\n console.info('Previous navigation request cancelled');\n }\n\n this._clearNavigationState();\n }\n\n private _clearNavigationState(): void {\n this._clearLoadedItems();\n this._resetLoadingState();\n this._loadResults = [];\n }\n\n /**\n * Load items with simple tracking\n */\n private async _loadItems(itemIds: string[], navigationId: number, controller: AbortController): Promise<void> {\n if (!this._testElement || itemIds.length === 0) return;\n\n const itemRefs = itemIds.map(id => this._findItemRef(id));\n this._clearLoadedItems();\n this._clearStimulusRef();\n\n const results = await Promise.all(itemRefs.map(ref => this._loadSingleItem(ref, navigationId, controller)));\n const validResults = results.filter(Boolean);\n\n if (this._isStaleNavigation(navigationId, controller)) return;\n\n const itemFacts = new Map(this.itemFacts);\n validResults.forEach(({ itemRef, doc, facts }) => {\n if (itemRef && doc) itemRef.xmlDoc = doc;\n if (itemRef && facts) itemFacts.set(itemRef.identifier, facts);\n });\n this.itemFacts = itemFacts;\n\n // Restore per-item state as early as possible (before iframe-based interactions initialize).\n // Some PCIs (including IMS conformance examples) only support restoration via getInstance(state),\n // so the state needs to be present on the provided itemContext at initial render time.\n validResults.forEach(({ itemRef }) => {\n const itemId = itemRef?.identifier;\n if (!itemRef || !itemId) return;\n\n const savedState = this.testContext.items.find(i => i.identifier === itemId)?.state;\n if (savedState === undefined) return;\n\n itemRef.updateComplete.then(() => {\n const assessmentItem = itemRef.assessmentItem as QtiAssessmentItem | null;\n if (!assessmentItem) return;\n assessmentItem.state = savedState;\n });\n });\n\n this._loadResults = validResults;\n }\n\n private async _loadSingleItem(itemRef: QtiAssessmentItemRef, navigationId: number, controller: AbortController) {\n try {\n // The same seed `test-container` shuffled the item order with.\n const seed = this.qtiContext?.QTI_CONTEXT?.seed;\n let transformer = (await qtiTransformItem().load(itemRef.href, controller.signal)).shuffleInteractions(seed);\n\n if (this.postLoadTransformCallback) {\n transformer = await this.postLoadTransformCallback(transformer, itemRef);\n }\n\n if (this._isStaleNavigation(navigationId, controller)) {\n return null;\n }\n\n // The facts come from the XML as it will be rendered: after the host's transform.\n const item = transformer.xmlDoc().documentElement;\n const facts = item?.localName === 'qti-assessment-item' ? readItemFacts(item) : null;\n return { itemRef, doc: transformer.htmlDoc(this._customElementRegistry()), facts };\n } catch (error) {\n if (error.name === 'AbortError') {\n console.info(`Item load for ${itemRef.identifier} was aborted`);\n throw error;\n }\n console.warn(`Failed to load item ${itemRef.identifier}:`, error);\n return null;\n }\n }\n\n private async _loadStimulus(href: string): Promise<DocumentFragment | null> {\n const transformer = await qtiTransformItem().load(href, this._activeController?.signal);\n return transformer.htmlDoc(this._customElementRegistry());\n }\n\n private _customElementRegistry(): CustomElementRegistry | undefined {\n const container = this.querySelector<TestContainer>('test-container');\n if (!container) return undefined;\n return container.customElementRegistry ?? undefined;\n }\n\n // ===========================================\n // UTILITIES\n // ===========================================\n\n private _findItemRef(itemId: string): QtiAssessmentItemRef {\n const itemRef = this._testElement?.querySelector<QtiAssessmentItemRef>(\n `qti-assessment-item-ref[identifier=\"${itemId}\"]`\n );\n\n if (!itemRef) {\n throw new Error(`Item with identifier \"${itemId}\" not found`);\n }\n\n return itemRef;\n }\n\n private _findSection(sectionId: string): QtiAssessmentSection | null {\n return (\n this._testElement?.querySelector<QtiAssessmentSection>(`qti-assessment-section[identifier=\"${sectionId}\"]`) ||\n null\n );\n }\n\n private _updateSessionContext(itemRef: QtiAssessmentItemRef, itemId: string): void {\n const navPartId = itemRef.closest('qti-test-part')?.identifier;\n const navSectionId = itemRef.closest('qti-assessment-section')?.identifier;\n\n this.sessionContext = {\n ...this.sessionContext,\n navPartId,\n navSectionId,\n navItemRefId: itemId\n };\n }\n\n private _getSectionItemIds(sectionId: string): string[] {\n return Array.from(\n this._testElement.querySelectorAll<QtiAssessmentItemRef>(\n `qti-assessment-section[identifier=\"${sectionId}\"] > qti-assessment-item-ref`\n )\n )\n .map(ref => ref.identifier)\n .filter(Boolean);\n }\n\n private _clearLoadedItems(): void {\n const itemRefs = this._testElement?.querySelectorAll<QtiAssessmentItemRef>('qti-assessment-item-ref');\n Array.from(itemRefs || []).forEach(element => {\n element.xmlDoc = null;\n });\n }\n\n private _clearStimulusRef(): void {\n this.querySelectorAll('[data-stimulus-idref]').forEach(el => (el.innerHTML = ''));\n }\n\n private _isStaleNavigation(navigationId: number, controller: AbortController): boolean {\n return controller.signal.aborted || navigationId !== this._navigationId;\n }\n\n private _createNavigationError(error: any, type: string, id: string): NavigationError {\n return {\n message: error.message || `Failed to load ${type}: ${id}`,\n details: error,\n itemId: type === 'item' ? id : undefined,\n sectionId: type === 'section' ? id : undefined\n };\n }\n\n // ===========================================\n // EVENT DISPATCHING\n // ===========================================\n\n private _dispatchLoadingStarted(type: string, id: string): void {\n dispatchPublic(this, 'qc-test-navigation-started', { type: type as 'item' | 'section', id });\n }\n\n private _dispatchLoadingEnded(type: string, id: string): void {\n this.dispatchEvent(\n new CustomEvent('qti-navigation-loading-ended', {\n detail: { type, id },\n bubbles: true,\n composed: true\n })\n );\n }\n\n private _dispatchError(error: NavigationError): void {\n dispatchPublic(this, 'qc-test-navigation-failed', error);\n }\n\n /** The items are in the DOM: tell hosts the new position rendered (`qc-test-navigated`) and which items it holds. */\n private _dispatchTestLoaded(results: any[], type: 'item' | 'section', id: string): void {\n requestAnimationFrame(() => {\n dispatchPublic(\n this,\n 'qc-test-rendered',\n results.map(({ itemRef }) => ({\n identifier: itemRef?.identifier,\n element: itemRef\n }))\n );\n dispatchPublic(this, 'qc-test-navigated', { type, id });\n });\n }\n }\n\n return TestNavigationClass as Constructor<ITestNavigationMixin> & T;\n};\n"]}
@@ -109,8 +109,10 @@ export const TestStateMixin = (superClass) => {
109
109
  #apply(state) {
110
110
  // Before the items load this only fills the test context; items already on screen are
111
111
  // updated too.
112
- for (const saved of state.test.items)
112
+ for (const saved of state.test.items) {
113
113
  this.updateItemVariables(saved.identifier, saved.variables, saved.state);
114
+ this.updateItemComment(saved.identifier, typeof saved.comment === 'string' ? saved.comment : null);
115
+ }
114
116
  this.#warnLeftOut(state);
115
117
  const savedOutcomes = new Map(state.test.outcomes.map(outcome => [outcome.identifier, outcome.value]));
116
118
  this.testContext = {
@@ -1 +1 @@
1
- {"version":3,"file":"test-state.mixin.js","sourceRoot":"","sources":["../../src/mixins/test-state.mixin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChE,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AA+B3D,MAAM,IAAI,GAAG,CAAC,KAAkC,EAAS,EAAE,CACzD,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAE,KAAmC,IAAI,IAAI,CAAC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AO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,OAAO,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;gBACvF,GAAG,CAAC,MAAM,CAAC,wBAAwB,EAAE,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,OAAO,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;gBACzG,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,UAAU,KAAK,OAAO,CAAC,YAAY,CAAC;oBACzE,CAAC,CAAC,EAAE,YAAY,EAAE,OAAO,CAAC,YAAY,EAAE;oBACxC,CAAC,CAAC,EAAE,CAAC;aACR,CAAC;QACJ,CAAC;QAED,kBAAkB,CAAC,IAAwB,EAAE,EAAU;YACrD,cAAc,CAAC,IAAI,EAAE,kBAAkB,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC;QACzD,CAAC;KACF;IAED,OAAO,cAAkD,CAAC;AAC5D,CAAC,CAAC","sourcesContent":["import { QTI_TEST_STATE_VERSION } from '../types/qti-test-state';\nimport { dispatchPublic, listenPublic } from '../public-events';\nimport { stateFromContexts } from '../state-from-contexts';\n\nimport type { PropertyValues } from 'lit';\nimport type { StateRefusal } from '../public-events';\nimport type { QtiTestState, QtiTestStateSession } from '../types/qti-test-state';\nimport type { TestBaseInterface } from './test-base';\n\ntype Constructor<T = {}> = abstract new (...args: any[]) => T;\ntype Value = string | string[] | null;\n\nexport interface ITestStateMixin {\n /**\n * The candidate's persistable state: what they answered and where they are.\n *\n * Assign a stored state to resume. It may be assigned at any time: before the test document\n * has loaded it is held and applied as soon as the test connects — before the first item\n * loads, so items and the initial navigation start from it — and after that it is applied\n * immediately and the test navigates to the restored position.\n *\n * Items are matched by item-ref identifier; items the state does not mention start fresh, and\n * stored items, test outcomes or a position the test no longer has are ignored. Restoring is a\n * resume, so linear-mode navigation restrictions do not apply.\n *\n * A value that is not a version 1 `QtiTestState` is ignored and reported with\n * `qc-test-state-refused`: at once when the test has loaded, or when it does if it was assigned\n * before. A state assigned earlier that could be read stays in effect. A stored 9.x\n * `testContext` is turned into a state with `stateFromContexts`.\n */\n state: QtiTestState;\n}\n\nconst copy = (value: Readonly<Value> | undefined): Value =>\n Array.isArray(value) ? [...value] : ((value as string | null | undefined) ?? null);\n\nconst isQtiTestState = (value: unknown): value is QtiTestState => {\n const state = value as QtiTestState | null;\n return (\n state?.version === QTI_TEST_STATE_VERSION &&\n Array.isArray(state.test?.items) &&\n Array.isArray(state.test?.outcomes) &&\n typeof state.session === 'object' &&\n state.session !== null\n );\n};\n\n/**\n * Persist and resume a test session through one value, `state`, and one event,\n * `qc-test-state-changed`.\n *\n * Sits directly on top of `TestBaseMixin`, so its `qc-test-loaded` listener runs\n * after the base has built `testContext.items` from the item-refs, and before the navigation\n * mixin's listener picks the first item to load.\n */\nexport const TestStateMixin = <T extends Constructor<TestBaseInterface>>(superClass: T) => {\n abstract class TestStateClass extends superClass implements ITestStateMixin {\n /** A state assigned before the test connected, applied when it does. */\n #pending: QtiTestState | null = null;\n\n /** A refused state assigned before the test connected, reported when it does. */\n #refused: StateRefusal | null = null;\n\n /**\n * False while a test document is loading. Loading resets both contexts and rebuilds them, so\n * the intermediate states are empty — emitting one would invite a host to save it over the\n * real one.\n */\n #ready = false;\n\n #lastEmitted: string | null = null;\n\n constructor(...args: any[]) {\n super(...args);\n this.addEventListener('qti-testdoc-loaded', () => {\n this.#ready = false;\n this.#lastEmitted = null;\n });\n listenPublic(this, 'qc-test-update-plugin-state', ({ detail }) => this.#updatePluginState(detail));\n listenPublic(this, 'qc-test-loaded', () => {\n if (this.#pending) {\n this.#apply(this.#pending);\n this.#pending = null;\n }\n this.#ready = true;\n if (this.#refused) {\n dispatchPublic(this, 'qc-test-state-refused', this.#refused);\n this.#refused = null;\n }\n });\n }\n\n /** One plugin's entry, as JSON: the test stores it without reading it. `null` removes it. */\n #updatePluginState({ plugin, value }: { plugin: string; value: unknown }): void {\n if (typeof plugin !== 'string' || plugin === '') return;\n const { [plugin]: _removed, ...others } = this.sessionContext.plugins ?? {};\n let next: Record<string, unknown> = others;\n if (value !== null && value !== undefined) {\n try {\n next = { ...others, [plugin]: JSON.parse(JSON.stringify(value)) };\n } catch {\n console.warn(`[qti-test] Ignoring plugin state for \"${plugin}\": it is not JSON.`);\n return;\n }\n }\n this.sessionContext = { ...this.sessionContext, plugins: next };\n }\n\n get state(): QtiTestState {\n return stateFromContexts(this.testContext, this.sessionContext);\n }\n\n set state(value: QtiTestState) {\n if (!isQtiTestState(value)) {\n const message = `Ignoring a state that is not a version ${QTI_TEST_STATE_VERSION} QtiTestState.`;\n console.warn(`[qti-test] ${message}`);\n // Hosts assign state before the test is in the page, where an event reaches no listener.\n if (this.#ready) dispatchPublic(this, 'qc-test-state-refused', { message, state: value });\n else this.#refused = { message, state: value };\n return;\n }\n if (!this.#ready) {\n this.#pending = value;\n return;\n }\n\n const { navItemRefId, navSectionId } = this.sessionContext;\n this.#apply(value);\n\n const restored = this.sessionContext;\n if (restored.navItemRefId && restored.navItemRefId !== navItemRefId) {\n this.#requestNavigation('item', restored.navItemRefId);\n } else if (!restored.navItemRefId && restored.navSectionId && restored.navSectionId !== navSectionId) {\n this.#requestNavigation('section', restored.navSectionId);\n }\n }\n\n protected override updated(changed: PropertyValues): void {\n super.updated(changed);\n if (!this.#ready || !(changed.has('testContext') || changed.has('sessionContext'))) return;\n\n const state = this.state;\n const serialized = JSON.stringify(state);\n if (serialized === this.#lastEmitted) return;\n this.#lastEmitted = serialized;\n dispatchPublic(this, 'qc-test-state-changed', state);\n }\n\n #apply(state: QtiTestState): void {\n // Before the items load this only fills the test context; items already on screen are\n // updated too.\n for (const saved of state.test.items) this.updateItemVariables(saved.identifier, saved.variables, saved.state);\n this.#warnLeftOut(state);\n\n const savedOutcomes = new Map(state.test.outcomes.map(outcome => [outcome.identifier, outcome.value]));\n this.testContext = {\n ...this.testContext,\n testOutcomeVariables: this.testContext.testOutcomeVariables?.map(v =>\n savedOutcomes.has(v.identifier) ? { ...v, value: copy(savedOutcomes.get(v.identifier)) } : v\n )\n };\n\n // Written before any navigation request, so the linear-mode restriction — which compares\n // against the current position — sees the restored item as current and lets it load.\n // Plugins are replaced, not merged: a state without them clears what an earlier one left.\n this.sessionContext = {\n ...this.sessionContext,\n ...this.#validSession(state.session),\n plugins: state.session.plugins && typeof state.session.plugins === 'object' ? { ...state.session.plugins } : {}\n };\n }\n\n /**\n * Answers for items this test does not present are not restored, and the next state leaves them\n * out: a selection (`qti-selection`) that leaves an item out, or a revised test. Said, not silent\n * (roadmap 1 T4, `plans/host-api.md` → Decided).\n */\n #warnLeftOut(state: QtiTestState): void {\n const presented = new Set(this.testContext.items.map(item => item.identifier));\n const leftOut = state.test.items.map(item => item.identifier).filter(identifier => !presented.has(identifier));\n if (leftOut.length === 0) return;\n console.warn(\n `[qti-test] The state has answers for items this test does not present (not selected, or no longer in it); they are not restored: ${leftOut.join(', ')}.`\n );\n }\n\n /** A stored position may point at an item or section a revised test no longer has. */\n #validSession(session: QtiTestStateSession): QtiTestStateSession {\n const exists = (selector: string, id: string | null | undefined) =>\n !!id && !!this._testElement?.querySelector(`${selector}[identifier=\"${CSS.escape(id)}\"]`);\n return {\n ...(exists('qti-test-part', session.navPartId) ? { navPartId: session.navPartId } : {}),\n ...(exists('qti-assessment-section', session.navSectionId) ? { navSectionId: session.navSectionId } : {}),\n ...(this.testContext.items.some(i => i.identifier === session.navItemRefId)\n ? { navItemRefId: session.navItemRefId }\n : {})\n };\n }\n\n #requestNavigation(type: 'item' | 'section', id: string): void {\n dispatchPublic(this, 'qc-test-navigate', { type, id });\n }\n }\n\n return TestStateClass as Constructor<ITestStateMixin> & T;\n};\n"]}
1
+ {"version":3,"file":"test-state.mixin.js","sourceRoot":"","sources":["../../src/mixins/test-state.mixin.ts"],"names":[],"mappings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AAC;AAC5D,CAAC,CAAC","sourcesContent":["import { QTI_TEST_STATE_VERSION } from '../types/qti-test-state';\nimport { dispatchPublic, listenPublic } from '../public-events';\nimport { stateFromContexts } from '../state-from-contexts';\n\nimport type { PropertyValues } from 'lit';\nimport type { StateRefusal } from '../public-events';\nimport type { QtiTestState, QtiTestStateSession } from '../types/qti-test-state';\nimport type { TestBaseInterface } from './test-base';\n\ntype Constructor<T = {}> = abstract new (...args: any[]) => T;\ntype Value = string | string[] | null;\n\nexport interface ITestStateMixin {\n /**\n * The candidate's persistable state: what they answered and where they are.\n *\n * Assign a stored state to resume. It may be assigned at any time: before the test document\n * has loaded it is held and applied as soon as the test connects — before the first item\n * loads, so items and the initial navigation start from it — and after that it is applied\n * immediately and the test navigates to the restored position.\n *\n * Items are matched by item-ref identifier; items the state does not mention start fresh, and\n * stored items, test outcomes or a position the test no longer has are ignored. Restoring is a\n * resume, so linear-mode navigation restrictions do not apply.\n *\n * A value that is not a version 1 `QtiTestState` is ignored and reported with\n * `qc-test-state-refused`: at once when the test has loaded, or when it does if it was assigned\n * before. A state assigned earlier that could be read stays in effect. A stored 9.x\n * `testContext` is turned into a state with `stateFromContexts`.\n */\n state: QtiTestState;\n}\n\nconst copy = (value: Readonly<Value> | undefined): Value =>\n Array.isArray(value) ? [...value] : ((value as string | null | undefined) ?? null);\n\nconst isQtiTestState = (value: unknown): value is QtiTestState => {\n const state = value as QtiTestState | null;\n return (\n state?.version === QTI_TEST_STATE_VERSION &&\n Array.isArray(state.test?.items) &&\n Array.isArray(state.test?.outcomes) &&\n typeof state.session === 'object' &&\n state.session !== null\n );\n};\n\n/**\n * Persist and resume a test session through one value, `state`, and one event,\n * `qc-test-state-changed`.\n *\n * Sits directly on top of `TestBaseMixin`, so its `qc-test-loaded` listener runs\n * after the base has built `testContext.items` from the item-refs, and before the navigation\n * mixin's listener picks the first item to load.\n */\nexport const TestStateMixin = <T extends Constructor<TestBaseInterface>>(superClass: T) => {\n abstract class TestStateClass extends superClass implements ITestStateMixin {\n /** A state assigned before the test connected, applied when it does. */\n #pending: QtiTestState | null = null;\n\n /** A refused state assigned before the test connected, reported when it does. */\n #refused: StateRefusal | null = null;\n\n /**\n * False while a test document is loading. Loading resets both contexts and rebuilds them, so\n * the intermediate states are empty — emitting one would invite a host to save it over the\n * real one.\n */\n #ready = false;\n\n #lastEmitted: string | null = null;\n\n constructor(...args: any[]) {\n super(...args);\n this.addEventListener('qti-testdoc-loaded', () => {\n this.#ready = false;\n this.#lastEmitted = null;\n });\n listenPublic(this, 'qc-test-update-plugin-state', ({ detail }) => this.#updatePluginState(detail));\n listenPublic(this, 'qc-test-loaded', () => {\n if (this.#pending) {\n this.#apply(this.#pending);\n this.#pending = null;\n }\n this.#ready = true;\n if (this.#refused) {\n dispatchPublic(this, 'qc-test-state-refused', this.#refused);\n this.#refused = null;\n }\n });\n }\n\n /** One plugin's entry, as JSON: the test stores it without reading it. `null` removes it. */\n #updatePluginState({ plugin, value }: { plugin: string; value: unknown }): void {\n if (typeof plugin !== 'string' || plugin === '') return;\n const { [plugin]: _removed, ...others } = this.sessionContext.plugins ?? {};\n let next: Record<string, unknown> = others;\n if (value !== null && value !== undefined) {\n try {\n next = { ...others, [plugin]: JSON.parse(JSON.stringify(value)) };\n } catch {\n console.warn(`[qti-test] Ignoring plugin state for \"${plugin}\": it is not JSON.`);\n return;\n }\n }\n this.sessionContext = { ...this.sessionContext, plugins: next };\n }\n\n get state(): QtiTestState {\n return stateFromContexts(this.testContext, this.sessionContext);\n }\n\n set state(value: QtiTestState) {\n if (!isQtiTestState(value)) {\n const message = `Ignoring a state that is not a version ${QTI_TEST_STATE_VERSION} QtiTestState.`;\n console.warn(`[qti-test] ${message}`);\n // Hosts assign state before the test is in the page, where an event reaches no listener.\n if (this.#ready) dispatchPublic(this, 'qc-test-state-refused', { message, state: value });\n else this.#refused = { message, state: value };\n return;\n }\n if (!this.#ready) {\n this.#pending = value;\n return;\n }\n\n const { navItemRefId, navSectionId } = this.sessionContext;\n this.#apply(value);\n\n const restored = this.sessionContext;\n if (restored.navItemRefId && restored.navItemRefId !== navItemRefId) {\n this.#requestNavigation('item', restored.navItemRefId);\n } else if (!restored.navItemRefId && restored.navSectionId && restored.navSectionId !== navSectionId) {\n this.#requestNavigation('section', restored.navSectionId);\n }\n }\n\n protected override updated(changed: PropertyValues): void {\n super.updated(changed);\n if (!this.#ready || !(changed.has('testContext') || changed.has('sessionContext'))) return;\n\n const state = this.state;\n const serialized = JSON.stringify(state);\n if (serialized === this.#lastEmitted) return;\n this.#lastEmitted = serialized;\n dispatchPublic(this, 'qc-test-state-changed', state);\n }\n\n #apply(state: QtiTestState): void {\n // Before the items load this only fills the test context; items already on screen are\n // updated too.\n for (const saved of state.test.items) {\n this.updateItemVariables(saved.identifier, saved.variables, saved.state);\n this.updateItemComment(saved.identifier, typeof saved.comment === 'string' ? saved.comment : null);\n }\n this.#warnLeftOut(state);\n\n const savedOutcomes = new Map(state.test.outcomes.map(outcome => [outcome.identifier, outcome.value]));\n this.testContext = {\n ...this.testContext,\n testOutcomeVariables: this.testContext.testOutcomeVariables?.map(v =>\n savedOutcomes.has(v.identifier) ? { ...v, value: copy(savedOutcomes.get(v.identifier)) } : v\n )\n };\n\n // Written before any navigation request, so the linear-mode restriction — which compares\n // against the current position — sees the restored item as current and lets it load.\n // Plugins are replaced, not merged: a state without them clears what an earlier one left.\n this.sessionContext = {\n ...this.sessionContext,\n ...this.#validSession(state.session),\n plugins: state.session.plugins && typeof state.session.plugins === 'object' ? { ...state.session.plugins } : {}\n };\n }\n\n /**\n * Answers for items this test does not present are not restored, and the next state leaves them\n * out: a selection (`qti-selection`) that leaves an item out, or a revised test. Said, not silent\n * (roadmap 1 T4, `plans/host-api.md` → Decided).\n */\n #warnLeftOut(state: QtiTestState): void {\n const presented = new Set(this.testContext.items.map(item => item.identifier));\n const leftOut = state.test.items.map(item => item.identifier).filter(identifier => !presented.has(identifier));\n if (leftOut.length === 0) return;\n console.warn(\n `[qti-test] The state has answers for items this test does not present (not selected, or no longer in it); they are not restored: ${leftOut.join(', ')}.`\n );\n }\n\n /** A stored position may point at an item or section a revised test no longer has. */\n #validSession(session: QtiTestStateSession): QtiTestStateSession {\n const exists = (selector: string, id: string | null | undefined) =>\n !!id && !!this._testElement?.querySelector(`${selector}[identifier=\"${CSS.escape(id)}\"]`);\n return {\n ...(exists('qti-test-part', session.navPartId) ? { navPartId: session.navPartId } : {}),\n ...(exists('qti-assessment-section', session.navSectionId) ? { navSectionId: session.navSectionId } : {}),\n ...(this.testContext.items.some(i => i.identifier === session.navItemRefId)\n ? { navItemRefId: session.navItemRefId }\n : {})\n };\n }\n\n #requestNavigation(type: 'item' | 'section', id: string): void {\n dispatchPublic(this, 'qc-test-navigate', { type, id });\n }\n }\n\n return TestStateClass as Constructor<ITestStateMixin> & T;\n};\n"]}
@@ -52,6 +52,15 @@ export interface PublicEventMap {
52
52
  plugin: string;
53
53
  value: unknown;
54
54
  }>;
55
+ /**
56
+ * Sets the candidate's comment on the item-ref `itemId` (`null` clears it), kept in the item's
57
+ * state and in `QtiTestState`. Refused, with a warning, unless the item's `allow-comment` allows
58
+ * it and its session is interacting (`rules.mayComment`). Send it from inside `<test-navigation>`.
59
+ */
60
+ 'qc-test-update-comment': CustomEvent<{
61
+ itemId: string;
62
+ comment: string | null;
63
+ }>;
55
64
  /** Outcome processing ran after a submit: read the test outcomes now. */
56
65
  'qc-test-submitted': CustomEvent<Record<string, never>>;
57
66
  'qc-test-navigated': CustomEvent<NavigationTarget>;
@@ -5,6 +5,7 @@ export const PUBLIC_EVENTS = {
5
5
  'qc-test-submit': { kind: 'request', scope: 'test', deprecated: 'cito-test-submit' },
6
6
  'qc-test-update-outcome': { kind: 'request', scope: 'test', deprecated: 'cito-test-update-outcome' },
7
7
  'qc-test-update-plugin-state': { kind: 'request', scope: 'test', deprecated: 'cito-test-update-plugin-state' },
8
+ 'qc-test-update-comment': { kind: 'request', scope: 'test' },
8
9
  'qc-test-switch-view': { kind: 'request', scope: 'test', deprecated: 'cito-test-switch-view' },
9
10
  'qc-test-submitted': { kind: 'notification', scope: 'test', deprecated: 'cito-test-submitted' },
10
11
  'qc-test-navigated': { kind: 'notification', scope: 'test', deprecated: 'cito-test-navigated' },
@@ -1 +1 @@
1
- {"version":3,"file":"public-events.js","sourceRoot":"","sources":["../src/public-events.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,wCAAwC,CAAC;AAyE1F,MAAM,CAAC,MAAM,aAAa,GAAoD;IAC5E,kBAAkB,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,oBAAoB,EAAE;IACxF,qBAAqB,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,uBAAuB,EAAE;IAC9F,gBAAgB,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,kBAAkB,EAAE;IACpF,wBAAwB,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,0BAA0B,EAAE;IACpG,6BAA6B,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,+BAA+B,EAAE;IAC9G,qBAAqB,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,uBAAuB,EAAE;IAC9F,mBAAmB,EAAE,EAAE,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,qBAAqB,EAAE;IAC/F,mBAAmB,EAAE,EAAE,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,qBAAqB,EAAE;IAC/F,4BAA4B,EAAE,EAAE,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,8BAA8B,EAAE;IACjH,2BAA2B,EAAE,EAAE,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,6BAA6B,EAAE;IAC/G,kBAAkB,EAAE,EAAE,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,oBAAoB,EAAE;IAC7F,gBAAgB,EAAE,EAAE,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,kBAAkB,EAAE;IACzF,uBAAuB,EAAE,EAAE,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,yBAAyB,EAAE;IACvG,wCAAwC;IACxC,uBAAuB,EAAE,EAAE,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,EAAE;IAChE,uBAAuB,EAAE,EAAE,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,yBAAyB,EAAE;IACvG,qBAAqB,EAAE,EAAE,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,uBAAuB,EAAE;IACnG,uBAAuB,EAAE,EAAE,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,yBAAyB,EAAE;CACxG,CAAC;AAMF;;;GAGG;AACH,MAAM,UAAU,cAAc,CAC5B,MAAmB,EACnB,IAAO,EACP,MAAkE;IAElE,gBAAgB,CAAC,MAAM,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;AACxD,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,YAAY,CAC1B,MAAmB,EACnB,IAAO,EACP,OAAuC;IAEvC,cAAc,CAAC,MAAM,EAAE,aAAa,EAAE,IAAI,EAAE,OAA6B,CAAC,CAAC;AAC7E,CAAC","sourcesContent":["import { dispatchDeclared, listenDeclared } from '@qti-components/elements/public-events';\n\nimport type { View } from '@qti-components/base';\nimport type { PublicEventDeclaration } from '@qti-components/elements/public-events';\nimport type { QtiTestState } from './types/qti-test-state';\n\n/**\n * The public events of the test. The name tells you it is public: everything here starts with\n * `qc-`; every other event is internal plumbing and may change in any release.\n *\n * Requests are verbs (a host or plugin dispatches them at the test), notifications are past tense\n * (the test dispatches them). All bubble and are composed.\n *\n * `deprecated` is the `cito-` name this event had in 9.x; an event new in 10.0 has none. One helper\n * (`dispatchPublic`, `listenPublic`) sends or handles both names until the next major, then the field\n * goes. The 7.x names (`qti-request-navigation`, `test-end-attempt`, `on-test-switch-view`, …) are no\n * longer sent or handled.\n */\nexport interface NavigationTarget {\n type: 'item' | 'section';\n id: string;\n}\n\nexport interface NavigationFailure {\n message: string;\n details?: unknown;\n itemId?: string;\n sectionId?: string;\n}\n\n/** The detail of `qc-test-state-refused`. */\nexport interface StateRefusal {\n /** Why the state was not read. */\n message: string;\n /** The value that was assigned to `state`, as given. */\n state: unknown;\n}\n\nexport interface PublicEventMap {\n 'qc-test-navigate': CustomEvent<NavigationTarget>;\n /**\n * Ends an attempt: processes the response of the item-ref `itemId`, or, without it, of the item on\n * screen. `<test-end-attempt>` sends the `itemId` of the item it is stamped into or names.\n */\n 'qc-test-end-attempt': CustomEvent<{ itemId?: string }>;\n /** Scores the test: resets its outcomes to their defaults, runs outcome processing, then `qc-test-submitted`. */\n 'qc-test-submit': CustomEvent<Record<string, never>>;\n 'qc-test-update-outcome': CustomEvent<{\n assessmentItemRefId: string;\n outcomeVariableId: string;\n value: number | string;\n }>;\n 'qc-test-switch-view': CustomEvent<View>;\n /** `value` is JSON; `null` or `undefined` removes the plugin's entry. */\n 'qc-test-update-plugin-state': CustomEvent<{ plugin: string; value: unknown }>;\n /** Outcome processing ran after a submit: read the test outcomes now. */\n 'qc-test-submitted': CustomEvent<Record<string, never>>;\n 'qc-test-navigated': CustomEvent<NavigationTarget>;\n 'qc-test-navigation-started': CustomEvent<NavigationTarget>;\n 'qc-test-navigation-failed': CustomEvent<NavigationFailure>;\n 'qc-test-rendered': CustomEvent<{ identifier: string; element: Element }[]>;\n // `qc-test-loaded` (detail: the `QtiAssessmentTest`) is added by qti-assessment-test.ts, so this\n // module imports no element: that import would be a cycle.\n 'qc-test-state-changed': CustomEvent<QtiTestState>;\n /** A value assigned to `state` could not be read and was ignored: the test goes on without it. */\n 'qc-test-state-refused': CustomEvent<StateRefusal>;\n 'qc-test-items-skipped': CustomEvent<{ ids: string[] }>;\n 'qc-test-end-reached': CustomEvent<Record<string, never>>;\n 'qc-item-ref-connected': CustomEvent<{ identifier: string; href: string; category: string }>;\n}\n\nexport type PublicEventName = keyof PublicEventMap;\n\nexport const PUBLIC_EVENTS: Record<PublicEventName, PublicEventDeclaration> = {\n 'qc-test-navigate': { kind: 'request', scope: 'test', deprecated: 'cito-test-navigate' },\n 'qc-test-end-attempt': { kind: 'request', scope: 'test', deprecated: 'cito-test-end-attempt' },\n 'qc-test-submit': { kind: 'request', scope: 'test', deprecated: 'cito-test-submit' },\n 'qc-test-update-outcome': { kind: 'request', scope: 'test', deprecated: 'cito-test-update-outcome' },\n 'qc-test-update-plugin-state': { kind: 'request', scope: 'test', deprecated: 'cito-test-update-plugin-state' },\n 'qc-test-switch-view': { kind: 'request', scope: 'test', deprecated: 'cito-test-switch-view' },\n 'qc-test-submitted': { kind: 'notification', scope: 'test', deprecated: 'cito-test-submitted' },\n 'qc-test-navigated': { kind: 'notification', scope: 'test', deprecated: 'cito-test-navigated' },\n 'qc-test-navigation-started': { kind: 'notification', scope: 'test', deprecated: 'cito-test-navigation-started' },\n 'qc-test-navigation-failed': { kind: 'notification', scope: 'test', deprecated: 'cito-test-navigation-failed' },\n 'qc-test-rendered': { kind: 'notification', scope: 'test', deprecated: 'cito-test-rendered' },\n 'qc-test-loaded': { kind: 'notification', scope: 'test', deprecated: 'cito-test-loaded' },\n 'qc-test-state-changed': { kind: 'notification', scope: 'test', deprecated: 'cito-test-state-changed' },\n // New in 10.0, so it has no cito- name.\n 'qc-test-state-refused': { kind: 'notification', scope: 'test' },\n 'qc-test-items-skipped': { kind: 'notification', scope: 'test', deprecated: 'cito-test-items-skipped' },\n 'qc-test-end-reached': { kind: 'notification', scope: 'test', deprecated: 'cito-test-end-reached' },\n 'qc-item-ref-connected': { kind: 'notification', scope: 'item', deprecated: 'cito-item-ref-connected' }\n};\n\ndeclare global {\n interface HTMLElementEventMap extends PublicEventMap {}\n}\n\n/**\n * Dispatch a public event, and its deprecated name with the same `detail` object. The detail is\n * always an object so `listenPublic` can tell the two apart from one dispatch.\n */\nexport function dispatchPublic<K extends PublicEventName>(\n target: EventTarget,\n name: K,\n detail: PublicEventMap[K] extends CustomEvent<infer D> ? D : never\n): void {\n dispatchDeclared(target, PUBLIC_EVENTS, name, detail);\n}\n\n/**\n * Listen for a public event and its deprecated name; the handler runs once for a sender that\n * dispatched both. See `listenDeclared`.\n */\nexport function listenPublic<K extends PublicEventName>(\n target: EventTarget,\n name: K,\n handler: (e: PublicEventMap[K]) => void\n): void {\n listenDeclared(target, PUBLIC_EVENTS, name, handler as (e: Event) => void);\n}\n"]}
1
+ {"version":3,"file":"public-events.js","sourceRoot":"","sources":["../src/public-events.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,wCAAwC,CAAC;AA+E1F,MAAM,CAAC,MAAM,aAAa,GAAoD;IAC5E,kBAAkB,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,oBAAoB,EAAE;IACxF,qBAAqB,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,uBAAuB,EAAE;IAC9F,gBAAgB,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,kBAAkB,EAAE;IACpF,wBAAwB,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,0BAA0B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c,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,uBAAuB,EAAE;IACnG,uBAAuB,EAAE,EAAE,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,yBAAyB,EAAE;CACxG,CAAC;AAMF;;;GAGG;AACH,MAAM,UAAU,cAAc,CAC5B,MAAmB,EACnB,IAAO,EACP,MAAkE;IAElE,gBAAgB,CAAC,MAAM,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;AACxD,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,YAAY,CAC1B,MAAmB,EACnB,IAAO,EACP,OAAuC;IAEvC,cAAc,CAAC,MAAM,EAAE,aAAa,EAAE,IAAI,EAAE,OAA6B,CAAC,CAAC;AAC7E,CAAC","sourcesContent":["import { dispatchDeclared, listenDeclared } from '@qti-components/elements/public-events';\n\nimport type { View } from '@qti-components/base';\nimport type { PublicEventDeclaration } from '@qti-components/elements/public-events';\nimport type { QtiTestState } from './types/qti-test-state';\n\n/**\n * The public events of the test. The name tells you it is public: everything here starts with\n * `qc-`; every other event is internal plumbing and may change in any release.\n *\n * Requests are verbs (a host or plugin dispatches them at the test), notifications are past tense\n * (the test dispatches them). All bubble and are composed.\n *\n * `deprecated` is the `cito-` name this event had in 9.x; an event new in 10.0 has none. One helper\n * (`dispatchPublic`, `listenPublic`) sends or handles both names until the next major, then the field\n * goes. The 7.x names (`qti-request-navigation`, `test-end-attempt`, `on-test-switch-view`, …) are no\n * longer sent or handled.\n */\nexport interface NavigationTarget {\n type: 'item' | 'section';\n id: string;\n}\n\nexport interface NavigationFailure {\n message: string;\n details?: unknown;\n itemId?: string;\n sectionId?: string;\n}\n\n/** The detail of `qc-test-state-refused`. */\nexport interface StateRefusal {\n /** Why the state was not read. */\n message: string;\n /** The value that was assigned to `state`, as given. */\n state: unknown;\n}\n\nexport interface PublicEventMap {\n 'qc-test-navigate': CustomEvent<NavigationTarget>;\n /**\n * Ends an attempt: processes the response of the item-ref `itemId`, or, without it, of the item on\n * screen. `<test-end-attempt>` sends the `itemId` of the item it is stamped into or names.\n */\n 'qc-test-end-attempt': CustomEvent<{ itemId?: string }>;\n /** Scores the test: resets its outcomes to their defaults, runs outcome processing, then `qc-test-submitted`. */\n 'qc-test-submit': CustomEvent<Record<string, never>>;\n 'qc-test-update-outcome': CustomEvent<{\n assessmentItemRefId: string;\n outcomeVariableId: string;\n value: number | string;\n }>;\n 'qc-test-switch-view': CustomEvent<View>;\n /** `value` is JSON; `null` or `undefined` removes the plugin's entry. */\n 'qc-test-update-plugin-state': CustomEvent<{ plugin: string; value: unknown }>;\n /**\n * Sets the candidate's comment on the item-ref `itemId` (`null` clears it), kept in the item's\n * state and in `QtiTestState`. Refused, with a warning, unless the item's `allow-comment` allows\n * it and its session is interacting (`rules.mayComment`). Send it from inside `<test-navigation>`.\n */\n 'qc-test-update-comment': CustomEvent<{ itemId: string; comment: string | null }>;\n /** Outcome processing ran after a submit: read the test outcomes now. */\n 'qc-test-submitted': CustomEvent<Record<string, never>>;\n 'qc-test-navigated': CustomEvent<NavigationTarget>;\n 'qc-test-navigation-started': CustomEvent<NavigationTarget>;\n 'qc-test-navigation-failed': CustomEvent<NavigationFailure>;\n 'qc-test-rendered': CustomEvent<{ identifier: string; element: Element }[]>;\n // `qc-test-loaded` (detail: the `QtiAssessmentTest`) is added by qti-assessment-test.ts, so this\n // module imports no element: that import would be a cycle.\n 'qc-test-state-changed': CustomEvent<QtiTestState>;\n /** A value assigned to `state` could not be read and was ignored: the test goes on without it. */\n 'qc-test-state-refused': CustomEvent<StateRefusal>;\n 'qc-test-items-skipped': CustomEvent<{ ids: string[] }>;\n 'qc-test-end-reached': CustomEvent<Record<string, never>>;\n 'qc-item-ref-connected': CustomEvent<{ identifier: string; href: string; category: string }>;\n}\n\nexport type PublicEventName = keyof PublicEventMap;\n\nexport const PUBLIC_EVENTS: Record<PublicEventName, PublicEventDeclaration> = {\n 'qc-test-navigate': { kind: 'request', scope: 'test', deprecated: 'cito-test-navigate' },\n 'qc-test-end-attempt': { kind: 'request', scope: 'test', deprecated: 'cito-test-end-attempt' },\n 'qc-test-submit': { kind: 'request', scope: 'test', deprecated: 'cito-test-submit' },\n 'qc-test-update-outcome': { kind: 'request', scope: 'test', deprecated: 'cito-test-update-outcome' },\n 'qc-test-update-plugin-state': { kind: 'request', scope: 'test', deprecated: 'cito-test-update-plugin-state' },\n 'qc-test-update-comment': { kind: 'request', scope: 'test' },\n 'qc-test-switch-view': { kind: 'request', scope: 'test', deprecated: 'cito-test-switch-view' },\n 'qc-test-submitted': { kind: 'notification', scope: 'test', deprecated: 'cito-test-submitted' },\n 'qc-test-navigated': { kind: 'notification', scope: 'test', deprecated: 'cito-test-navigated' },\n 'qc-test-navigation-started': { kind: 'notification', scope: 'test', deprecated: 'cito-test-navigation-started' },\n 'qc-test-navigation-failed': { kind: 'notification', scope: 'test', deprecated: 'cito-test-navigation-failed' },\n 'qc-test-rendered': { kind: 'notification', scope: 'test', deprecated: 'cito-test-rendered' },\n 'qc-test-loaded': { kind: 'notification', scope: 'test', deprecated: 'cito-test-loaded' },\n 'qc-test-state-changed': { kind: 'notification', scope: 'test', deprecated: 'cito-test-state-changed' },\n // New in 10.0, so it has no cito- name.\n 'qc-test-state-refused': { kind: 'notification', scope: 'test' },\n 'qc-test-items-skipped': { kind: 'notification', scope: 'test', deprecated: 'cito-test-items-skipped' },\n 'qc-test-end-reached': { kind: 'notification', scope: 'test', deprecated: 'cito-test-end-reached' },\n 'qc-item-ref-connected': { kind: 'notification', scope: 'item', deprecated: 'cito-item-ref-connected' }\n};\n\ndeclare global {\n interface HTMLElementEventMap extends PublicEventMap {}\n}\n\n/**\n * Dispatch a public event, and its deprecated name with the same `detail` object. The detail is\n * always an object so `listenPublic` can tell the two apart from one dispatch.\n */\nexport function dispatchPublic<K extends PublicEventName>(\n target: EventTarget,\n name: K,\n detail: PublicEventMap[K] extends CustomEvent<infer D> ? D : never\n): void {\n dispatchDeclared(target, PUBLIC_EVENTS, name, detail);\n}\n\n/**\n * Listen for a public event and its deprecated name; the handler runs once for a sender that\n * dispatched both. See `listenDeclared`.\n */\nexport function listenPublic<K extends PublicEventName>(\n target: EventTarget,\n name: K,\n handler: (e: PublicEventMap[K]) => void\n): void {\n listenDeclared(target, PUBLIC_EVENTS, name, handler as (e: Event) => void);\n}\n"]}