@qti-components/test 1.9.0 → 1.10.0-next.0

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 (45) hide show
  1. package/dist/components/qti-assessment-item-ref/qti-assessment-item-ref.js +6 -5
  2. package/dist/components/qti-assessment-item-ref/qti-assessment-item-ref.js.map +1 -1
  3. package/dist/components/qti-assessment-test/qti-assessment-test.d.ts +5 -0
  4. package/dist/components/qti-assessment-test/qti-assessment-test.js +2 -5
  5. package/dist/components/qti-assessment-test/qti-assessment-test.js.map +1 -1
  6. package/dist/components/qti-number-selected/qti-number-selected.js +2 -1
  7. package/dist/components/qti-number-selected/qti-number-selected.js.map +1 -1
  8. package/dist/components/qti-test-variables/qti-test-variables.js +2 -1
  9. package/dist/components/qti-test-variables/qti-test-variables.js.map +1 -1
  10. package/dist/components/test-check-item/test-check-item.js +2 -1
  11. package/dist/components/test-check-item/test-check-item.js.map +1 -1
  12. package/dist/components/test-end-attempt/test-end-attempt.js +2 -1
  13. package/dist/components/test-end-attempt/test-end-attempt.js.map +1 -1
  14. package/dist/components/test-item-link/test-item-link.js +2 -8
  15. package/dist/components/test-item-link/test-item-link.js.map +1 -1
  16. package/dist/components/test-item-to-speech/test-item-to-speech.js +4 -2
  17. package/dist/components/test-item-to-speech/test-item-to-speech.js.map +1 -1
  18. package/dist/components/test-navigation/test-navigation.d.ts +0 -8
  19. package/dist/components/test-navigation/test-navigation.js +6 -4
  20. package/dist/components/test-navigation/test-navigation.js.map +1 -1
  21. package/dist/components/test-next/test-next.js +2 -8
  22. package/dist/components/test-next/test-next.js.map +1 -1
  23. package/dist/components/test-prev/test-prev.js +2 -8
  24. package/dist/components/test-prev/test-prev.js.map +1 -1
  25. package/dist/components/test-scoring-buttons/test-scoring-buttons.js +6 -8
  26. package/dist/components/test-scoring-buttons/test-scoring-buttons.js.map +1 -1
  27. package/dist/components/test-section-link/test-section-link.js +2 -8
  28. package/dist/components/test-section-link/test-section-link.js.map +1 -1
  29. package/dist/components/test-view-toggle/test-view-toggle.js +2 -5
  30. package/dist/components/test-view-toggle/test-view-toggle.js.map +1 -1
  31. package/dist/components/test-view-toggle/test-view.js +2 -5
  32. package/dist/components/test-view-toggle/test-view.js.map +1 -1
  33. package/dist/internal/item-ref-selection.js.map +1 -1
  34. package/dist/mixins/test-base.js +2 -1
  35. package/dist/mixins/test-base.js.map +1 -1
  36. package/dist/mixins/test-navigation.mixin.js +15 -28
  37. package/dist/mixins/test-navigation.mixin.js.map +1 -1
  38. package/dist/mixins/test-state.mixin.js +4 -3
  39. package/dist/mixins/test-state.mixin.js.map +1 -1
  40. package/dist/mixins/test-view.mixin.js +3 -2
  41. package/dist/mixins/test-view.mixin.js.map +1 -1
  42. package/dist/public-events.d.ts +62 -0
  43. package/dist/public-events.js +33 -0
  44. package/dist/public-events.js.map +1 -0
  45. package/package.json +4 -4
@@ -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;AA0BpG,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;YAmJ1E;;;;;;;;eAQG;YACK,6BAAwB,GAAG,CAAC,cAAiC,EAAQ,EAAE;gBAC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,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;IAkM5E,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 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 * `qti-state-changed` fires.\n *\n * @param itemRefID The `qti-assessment-item-ref` identifier, not the item's own identifier.\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 * `qti-assessment-test-connected`, 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 this.addEventListener('qti-assessment-test-connected', (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 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 // 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\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;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;YAmJ1E;;;;;;;;eAQG;YACK,6BAAwB,GAAG,CAAC,cAAiC,EAAQ,EAAE;gBAC7E,MAAM,OAAO,GAAG,cAAc,CAAC,WAAW,CAAC;gBAC3C,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;gBACtC,MAAM,aAAa,GAAG,OAAO,CAAC,SAAS,CAAC;gBAExC,gEAAgE;gBAChE,MAAM,WAAW,GAAG,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,UAAU,KAAK,UAAU,CAAC,CAAC;gBAEnF,IAAI,CAAC,WAAW,EAAE,CAAC;oBACjB,OAAO,CA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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 * `qti-state-changed` fires.\n *\n * @param itemRefID The `qti-assessment-item-ref` identifier, not the item's own identifier.\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 * `qti-assessment-test-connected`, 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, 'cito-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 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 // 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\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"]}
@@ -6,6 +6,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
6
6
  };
7
7
  import { property } from 'lit/decorators.js';
8
8
  import { qtiTransformItem } from '@qti-components/transformers';
9
+ import { dispatchPublic, listenPublic } from '../public-events';
9
10
  /**
10
11
  * Navigation mixin for QTI test components
11
12
  *
@@ -51,19 +52,15 @@ export const TestNavigationMixin = (superClass) => {
51
52
  navigateTo(type, id) {
52
53
  const targetId = id || this._getDefaultNavigationId(type);
53
54
  if (targetId) {
54
- this.dispatchEvent(new CustomEvent('qti-request-navigation', {
55
- detail: { type, id: targetId },
56
- bubbles: true,
57
- composed: true
58
- }));
55
+ dispatchPublic(this, 'cito-test-navigate', { type, id: targetId });
59
56
  }
60
57
  }
61
58
  // ===========================================
62
59
  // EVENT HANDLER SETUP
63
60
  // ===========================================
64
61
  _bindEventHandlers() {
65
- this.addEventListener('qti-request-navigation', this._handleNavigationRequest.bind(this));
66
- this.addEventListener('qti-assessment-test-connected', this._handleTestConnected.bind(this));
62
+ listenPublic(this, 'cito-test-navigate', this._handleNavigationRequest.bind(this));
63
+ listenPublic(this, 'cito-test-loaded', this._handleTestConnected.bind(this));
67
64
  this.addEventListener('qti-assessment-item-connected', this._handleItemConnected.bind(this));
68
65
  this.addEventListener('qti-assessment-stimulus-ref-connected', this._handleStimulusRefConnected.bind(this));
69
66
  }
@@ -233,7 +230,7 @@ export const TestNavigationMixin = (superClass) => {
233
230
  await this._waitForLoadingComplete(navigationId, controller);
234
231
  if (this._isStaleNavigation(navigationId, controller))
235
232
  return;
236
- this._dispatchTestLoaded(this._loadResults);
233
+ this._dispatchTestLoaded(this._loadResults, 'item', itemId);
237
234
  }
238
235
  /**
239
236
  * Navigate to section with simple state tracking
@@ -254,7 +251,7 @@ export const TestNavigationMixin = (superClass) => {
254
251
  await this._waitForLoadingComplete(navigationId, controller);
255
252
  if (this._isStaleNavigation(navigationId, controller))
256
253
  return;
257
- this._dispatchTestLoaded(this._loadResults);
254
+ this._dispatchTestLoaded(this._loadResults, 'section', sectionId);
258
255
  }
259
256
  // ===========================================
260
257
  // LOADING STATE MANAGEMENT
@@ -493,11 +490,7 @@ export const TestNavigationMixin = (superClass) => {
493
490
  // EVENT DISPATCHING
494
491
  // ===========================================
495
492
  _dispatchLoadingStarted(type, id) {
496
- this.dispatchEvent(new CustomEvent('qti-navigation-loading-started', {
497
- detail: { type, id },
498
- bubbles: true,
499
- composed: true
500
- }));
493
+ dispatchPublic(this, 'cito-test-navigation-started', { type: type, id });
501
494
  }
502
495
  _dispatchLoadingEnded(type, id) {
503
496
  this.dispatchEvent(new CustomEvent('qti-navigation-loading-ended', {
@@ -507,22 +500,16 @@ export const TestNavigationMixin = (superClass) => {
507
500
  }));
508
501
  }
509
502
  _dispatchError(error) {
510
- this.dispatchEvent(new CustomEvent('qti-navigation-error', {
511
- detail: error,
512
- bubbles: true,
513
- composed: true
514
- }));
503
+ dispatchPublic(this, 'cito-test-navigation-failed', error);
515
504
  }
516
- _dispatchTestLoaded(results) {
505
+ /** The items are in the DOM: tell hosts the new position rendered (`cito-test-navigated`) and which items it holds. */
506
+ _dispatchTestLoaded(results, type, id) {
517
507
  requestAnimationFrame(() => {
518
- this.dispatchEvent(new CustomEvent('qti-test-loaded', {
519
- detail: results.map(({ itemRef }) => ({
520
- identifier: itemRef?.identifier,
521
- element: itemRef
522
- })),
523
- bubbles: true,
524
- composed: true
525
- }));
508
+ dispatchPublic(this, 'cito-test-rendered', results.map(({ itemRef }) => ({
509
+ identifier: itemRef?.identifier,
510
+ element: itemRef
511
+ })));
512
+ dispatchPublic(this, 'cito-test-navigated', { type, id });
526
513
  });
527
514
  }
528
515
  }
@@ -1 +1 @@
1
- {"version":3,"file":"test-navigation.mixin.js","sourceRoot":"","sources":["../../src/mixins/test-navigation.mixin.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AA2DhE;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAA2C,UAAa,EAAE,EAAE;IAC7F,MAAe,mBAAoB,SAAQ,UAAU;QA0BnD,YAAY,GAAG,IAAW;YACxB,KAAK,CAAC,GAAG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QAAQ,EAAE,IAAI;aACf,CAAC,CACH,CAAC;QACJ,CAAC;QAEO,cAAc,CAAC,KAAsB;YAC3C,IAAI,CAAC,aAAa,CAChB,IAAI,WAAW,CAAC,sBAAsB,EAAE;gBACtC,MAAM,EAAE,KAAK;gBACb,OAAO,EAAE,IAAI;gBACb,QAAQ,EAAE,IAAI;aACf,CAAC,CACH,CAAC;QACJ,CAAC;QAEO,mBAAmB,CAAC,OAAc;YACxC,qBAAqB,CAAC,GAAG,EAAE;gBACzB,IAAI,CAAC,aAAa,CAChB,IAAI,WAAW,CAAC,iBAAiB,EAAE;oBACjC,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,CAAC;wBACpC,UAAU,EAAE,OAAO,EAAE,UAAU;wBAC/B,OAAO,EAAE,OAAO;qBACjB,CAAC,CAAC;oBACH,OAAO,EAAE,IAAI;oBACb,QAAQ,EAAE,IAAI;iBACf,CAAC,CACH,CAAC;YACJ,CAAC,CAAC,CAAC;QACL,CAAC;KACF;IApnB6B;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;IAmnB7G,OAAO,mBAA4D,CAAC;AACtE,CAAC,CAAC","sourcesContent":["import { property } from 'lit/decorators.js';\n\nimport { qtiTransformItem } from '@qti-components/transformers';\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 { QtiTestPart } from '../components/qti-test-part/qti-test-part';\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 { 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 // 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 this.dispatchEvent(\n new CustomEvent('qti-request-navigation', {\n detail: { type, id: targetId },\n bubbles: true,\n composed: true\n })\n );\n }\n }\n\n // ===========================================\n // EVENT HANDLER SETUP\n // ===========================================\n\n private _bindEventHandlers(): void {\n this.addEventListener('qti-request-navigation', this._handleNavigationRequest.bind(this));\n this.addEventListener('qti-assessment-test-connected', 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._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 const id = this._getDefaultNavigationId(this.navigate);\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 const section = currentItemRef.closest('qti-assessment-section') as QtiAssessmentSection;\n const testPart = currentItemRef.closest('qti-test-part') as QtiTestPart;\n\n const navigationMode = (section?.navigationMode ||\n section?.getAttribute('navigation-mode') ||\n testPart?.navigationMode ||\n testPart?.getAttribute('navigation-mode') ||\n 'nonlinear') as string;\n\n if (navigationMode !== '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 * 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 if (this._isLinearNavigationRestricted(detail.type, detail.id)) {\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, detail.id);\n this._activeController = controller;\n\n await this._executeNavigation(detail.type, detail.id, navigationId, controller);\n } catch (error) {\n this._handleNavigationError(error, detail.type, detail.id);\n } finally {\n if (this._activeController === controller) {\n this._activeController = null;\n }\n this._dispatchLoadingEnded(detail.type, detail.id);\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);\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\n this.sessionContext = {\n ...this.sessionContext,\n navPartId,\n navSectionId: sectionId,\n navItemRefId: null\n };\n\n const itemIds = this._getSectionItemIds(sectionId);\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);\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 validResults.forEach(({ itemRef, doc }) => {\n if (itemRef && doc) itemRef.xmlDoc = doc;\n });\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 return { itemRef, doc: transformer.htmlDoc(this._customElementRegistry()) };\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 this.dispatchEvent(\n new CustomEvent('qti-navigation-loading-started', {\n detail: { type, id },\n bubbles: true,\n composed: true\n })\n );\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 this.dispatchEvent(\n new CustomEvent('qti-navigation-error', {\n detail: error,\n bubbles: true,\n composed: true\n })\n );\n }\n\n private _dispatchTestLoaded(results: any[]): void {\n requestAnimationFrame(() => {\n this.dispatchEvent(\n new CustomEvent('qti-test-loaded', {\n detail: results.map(({ itemRef }) => ({\n identifier: itemRef?.identifier,\n element: itemRef\n })),\n bubbles: true,\n composed: true\n })\n );\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,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAEhE,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;QA0BnD,YAAY,GAAG,IAAW;YACxB,KAAK,CAAC,GAAG,IAAI,CAAC,CAAC;YA1BW,aAAQ,GAA8B,IAAI,CAAC;YAC3C,mBAAc,GAAW,KAAK,CAAC;YAC3B,8BAAyB,GAAqC,IAAI,CAAC;YACnE,kCAA6B,GAAyC,IAAI,CAAC;YAI3G,4BAA4B;YACpB,sBAAiB,GAA2B,IAAI,CAAC;YACjD,iBAAY,GAAU,EAAE,CAAC;YACzB,kBAAa,GAAG,CAAC,CAAC;YAE1B,mCAAmC;YAC3B,kBAAa,GAAG;gBACtB,aAAa,EAAE,CAAC;gBAChB,cAAc,EAAE,CAAC;gBACjB,gBAAgB,EAAE,CAAC;gBACnB,cAAc,EAAE,CAAC;gBACjB,UAAU,EAAE,KAAK;aAClB,CAAC;YAEF,4DAA4D;YACpD,yBAAoB,GAAG,IAAI,GAAG,EAAU,CAAC;YACzC,0BAAqB,GAAG,IAAI,GAAG,EAAU,CAAC;YAIhD,IAAI,CAAC,kBAAkB,EAAE,CAAC;QAC5B,CAAC;QA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AC3B;QAA/B,QAAQ,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;0EAAoE;IACnE;QAA/B,QAAQ,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;8EAA4E;IAimB7G,OAAO,mBAA4D,CAAC;AACtE,CAAC,CAAC","sourcesContent":["import { property } from 'lit/decorators.js';\n\nimport { qtiTransformItem } from '@qti-components/transformers';\n\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 { QtiTestPart } from '../components/qti-test-part/qti-test-part';\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 { 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 // 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, 'cito-test-navigate', { type, id: targetId });\n }\n }\n\n // ===========================================\n // EVENT HANDLER SETUP\n // ===========================================\n\n private _bindEventHandlers(): void {\n listenPublic(this, 'cito-test-navigate', this._handleNavigationRequest.bind(this));\n listenPublic(this, 'cito-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._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 const id = this._getDefaultNavigationId(this.navigate);\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 const section = currentItemRef.closest('qti-assessment-section') as QtiAssessmentSection;\n const testPart = currentItemRef.closest('qti-test-part') as QtiTestPart;\n\n const navigationMode = (section?.navigationMode ||\n section?.getAttribute('navigation-mode') ||\n testPart?.navigationMode ||\n testPart?.getAttribute('navigation-mode') ||\n 'nonlinear') as string;\n\n if (navigationMode !== '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 * 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 if (this._isLinearNavigationRestricted(detail.type, detail.id)) {\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, detail.id);\n this._activeController = controller;\n\n await this._executeNavigation(detail.type, detail.id, navigationId, controller);\n } catch (error) {\n this._handleNavigationError(error, detail.type, detail.id);\n } finally {\n if (this._activeController === controller) {\n this._activeController = null;\n }\n this._dispatchLoadingEnded(detail.type, detail.id);\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\n this.sessionContext = {\n ...this.sessionContext,\n navPartId,\n navSectionId: sectionId,\n navItemRefId: null\n };\n\n const itemIds = this._getSectionItemIds(sectionId);\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 validResults.forEach(({ itemRef, doc }) => {\n if (itemRef && doc) itemRef.xmlDoc = doc;\n });\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 return { itemRef, doc: transformer.htmlDoc(this._customElementRegistry()) };\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, 'cito-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, 'cito-test-navigation-failed', error);\n }\n\n /** The items are in the DOM: tell hosts the new position rendered (`cito-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 'cito-test-rendered',\n results.map(({ itemRef }) => ({\n identifier: itemRef?.identifier,\n element: itemRef\n }))\n );\n dispatchPublic(this, 'cito-test-navigated', { type, id });\n });\n }\n }\n\n return TestNavigationClass as Constructor<ITestNavigationMixin> & T;\n};\n"]}
@@ -1,4 +1,5 @@
1
1
  import { QTI_TEST_STATE_VERSION } from '../types/qti-test-state';
2
+ import { dispatchPublic, listenPublic } from '../public-events';
2
3
  const copy = (value) => Array.isArray(value) ? [...value] : (value ?? null);
3
4
  const isQtiTestState = (value) => {
4
5
  const state = value;
@@ -55,7 +56,7 @@ export const TestStateMixin = (superClass) => {
55
56
  this.#ready = false;
56
57
  this.#lastEmitted = null;
57
58
  });
58
- this.addEventListener('qti-assessment-test-connected', () => {
59
+ listenPublic(this, 'cito-test-loaded', () => {
59
60
  if (this.#pending) {
60
61
  this.#apply(this.#pending);
61
62
  this.#pending = null;
@@ -94,7 +95,7 @@ export const TestStateMixin = (superClass) => {
94
95
  if (serialized === this.#lastEmitted)
95
96
  return;
96
97
  this.#lastEmitted = serialized;
97
- this.dispatchEvent(new CustomEvent('qti-state-changed', { detail: state, bubbles: true, composed: true }));
98
+ dispatchPublic(this, 'cito-test-state-changed', state);
98
99
  }
99
100
  #apply(state) {
100
101
  // Before the items load this only fills the test context; items already on screen are
@@ -122,7 +123,7 @@ export const TestStateMixin = (superClass) => {
122
123
  };
123
124
  }
124
125
  #requestNavigation(type, id) {
125
- this.dispatchEvent(new CustomEvent('qti-request-navigation', { detail: { type, id }, bubbles: true, composed: true }));
126
+ dispatchPublic(this, 'cito-test-navigate', { type, id });
126
127
  }
127
128
  }
128
129
  return TestStateClass;
@@ -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;AAgCjE,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,CAAC;AAErF,MAAM,cAAc,GAAG,CAAC,KAAc,EAAyB,EAAE;IAC/D,MAAM,KAAK,GAAG,KAA4B,CAAC;IAC3C,OAAO,CACL,KAAK,EAAE,OAAO,KAAK,sBAAsB;QACzC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC;QAChC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,EAAE,QAAQ,CAAC;QACnC,OAAO,KAAK,CAAC,OAAO,KAAK,QAAQ;QACjC,KAAK,CAAC,OAAO,KAAK,IAAI,CACvB,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,OAAO,GAAG,CAAC,IAA2B,EAAE,OAAiC,EAAgB,EAAE,CAAC,CAAC;IACjG,OAAO,EAAE,sBAAsB;IAC/B,IAAI,EAAE;QACJ,KAAK,EAAE,CAAC,IAAI,EAAE,KAAK,IAAI,EAAE,CAAC;aACvB,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC;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,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,IAAI,CAAC,aAAa,CAChB,IAAI,WAAW,CAAC,wBAAwB,EAAE,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CACnG,CAAC;QACJ,CAAC;KACF;IAED,OAAO,cAAkD,CAAC;AAC5D,CAAC,CAAC","sourcesContent":["import { QTI_TEST_STATE_VERSION } from '../types/qti-test-state';\n\nimport type { PropertyValues } from 'lit';\nimport type { SessionContext, TestContext } from '@qti-components/base';\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\ndeclare global {\n interface GlobalEventHandlersEventMap {\n 'qti-state-changed': CustomEvent<QtiTestState>;\n }\n}\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 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\nconst toState = (test: Readonly<TestContext>, session: Readonly<SessionContext>): QtiTestState => ({\n version: QTI_TEST_STATE_VERSION,\n test: {\n items: (test?.items ?? [])\n .filter(item => item.identifier)\n .map(item => ({\n identifier: item.identifier,\n variables: (item.variables ?? []).map(v => ({\n identifier: v.identifier,\n ...(v.type ? { type: v.type } : {}),\n value: copy(v.value)\n })),\n ...(item.state ? { state: { ...item.state } } : {})\n })),\n outcomes: (test?.testOutcomeVariables ?? []).map(v => ({ identifier: v.identifier, value: copy(v.value) }))\n },\n session: {\n ...(session?.navPartId !== undefined ? { navPartId: session.navPartId } : {}),\n ...(session?.navSectionId !== undefined ? { navSectionId: session.navSectionId } : {}),\n ...(session?.navItemRefId !== undefined ? { navItemRefId: session.navItemRefId } : {})\n }\n});\n\n/**\n * Persist and resume a test session through one value, `state`, and one event,\n * `qti-state-changed`.\n *\n * Sits directly on top of `TestBaseMixin`, so its `qti-assessment-test-connected` 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 /**\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 this.addEventListener('qti-assessment-test-connected', () => {\n if (this.#pending) {\n this.#apply(this.#pending);\n this.#pending = null;\n }\n this.#ready = true;\n });\n }\n\n get state(): QtiTestState {\n return toState(this.testContext, this.sessionContext);\n }\n\n set state(value: QtiTestState) {\n if (!isQtiTestState(value)) {\n console.warn(`[qti-test] Ignoring a state that is not a version ${QTI_TEST_STATE_VERSION} QtiTestState.`);\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 this.dispatchEvent(new CustomEvent('qti-state-changed', { detail: state, bubbles: true, composed: true }));\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\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 this.sessionContext = { ...this.sessionContext, ...this.#validSession(state.session) };\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 this.dispatchEvent(\n new CustomEvent('qti-request-navigation', { detail: { type, id }, bubbles: true, composed: true })\n );\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":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAgChE,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,CAAC;AAErF,MAAM,cAAc,GAAG,CAAC,KAAc,EAAyB,EAAE;IAC/D,MAAM,KAAK,GAAG,KAA4B,CAAC;IAC3C,OAAO,CACL,KAAK,EAAE,OAAO,KAAK,sBAAsB;QACzC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC;QAChC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,EAAE,QAAQ,CAAC;QACnC,OAAO,KAAK,CAAC,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CAAC,EAAE,IAAI,CAAC,CAAC,IAAI,CAAC,YAAY,EAAE,aAAa,CAAC,GAAG,QAAQ,gBAAgB,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC;YAC5F,OAAO;gBACL,GAAG,CAAC,MAAM,CAAC,eAAe,EAAE,OAAO,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,oBAAoB,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC;QAC3D,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';\n\nimport type { PropertyValues } from 'lit';\nimport type { SessionContext, TestContext } from '@qti-components/base';\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\ndeclare global {\n interface GlobalEventHandlersEventMap {\n 'qti-state-changed': CustomEvent<QtiTestState>;\n }\n}\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 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\nconst toState = (test: Readonly<TestContext>, session: Readonly<SessionContext>): QtiTestState => ({\n version: QTI_TEST_STATE_VERSION,\n test: {\n items: (test?.items ?? [])\n .filter(item => item.identifier)\n .map(item => ({\n identifier: item.identifier,\n variables: (item.variables ?? []).map(v => ({\n identifier: v.identifier,\n ...(v.type ? { type: v.type } : {}),\n value: copy(v.value)\n })),\n ...(item.state ? { state: { ...item.state } } : {})\n })),\n outcomes: (test?.testOutcomeVariables ?? []).map(v => ({ identifier: v.identifier, value: copy(v.value) }))\n },\n session: {\n ...(session?.navPartId !== undefined ? { navPartId: session.navPartId } : {}),\n ...(session?.navSectionId !== undefined ? { navSectionId: session.navSectionId } : {}),\n ...(session?.navItemRefId !== undefined ? { navItemRefId: session.navItemRefId } : {})\n }\n});\n\n/**\n * Persist and resume a test session through one value, `state`, and one event,\n * `qti-state-changed`.\n *\n * Sits directly on top of `TestBaseMixin`, so its `qti-assessment-test-connected` 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 /**\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, 'cito-test-loaded', () => {\n if (this.#pending) {\n this.#apply(this.#pending);\n this.#pending = null;\n }\n this.#ready = true;\n });\n }\n\n get state(): QtiTestState {\n return toState(this.testContext, this.sessionContext);\n }\n\n set state(value: QtiTestState) {\n if (!isQtiTestState(value)) {\n console.warn(`[qti-test] Ignoring a state that is not a version ${QTI_TEST_STATE_VERSION} QtiTestState.`);\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, 'cito-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\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 this.sessionContext = { ...this.sessionContext, ...this.#validSession(state.session) };\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, 'cito-test-navigate', { type, id });\n }\n }\n\n return TestStateClass as Constructor<ITestStateMixin> & T;\n};\n"]}
@@ -1,13 +1,14 @@
1
+ import { listenPublic } from '../public-events';
1
2
  export const TestViewMixin = (superClass) => {
2
3
  class TestViewClass extends superClass {
3
4
  constructor(...args) {
4
5
  super(...args);
5
6
  this.sessionContext = { ...this.sessionContext, view: 'candidate' };
6
- this.addEventListener('on-test-switch-view', (e) => {
7
+ listenPublic(this, 'cito-test-switch-view', e => {
7
8
  this.sessionContext = { ...this.sessionContext, view: e.detail };
8
9
  this._updateElementView();
9
10
  });
10
- this.addEventListener('qti-assessment-test-connected', () => {
11
+ listenPublic(this, 'cito-test-loaded', () => {
11
12
  this._updateElementView();
12
13
  });
13
14
  this.addEventListener('qti-assessment-item-connected', (e) => {
@@ -1 +1 @@
1
- {"version":3,"file":"test-view.mixin.js","sourceRoot":"","sources":["../../src/mixins/test-view.mixin.ts"],"names":[],"mappings":"AAWA,MAAM,CAAC,MAAM,aAAa,GAAG,CAA2C,UAAa,EAAE,EAAE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OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,YAAY,CAAC,MAAM,CAAC,KAAK,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;gBAC9F,CAAC,CAAC,CAAC;gBAEH,MAAM,iBAAiB,GAAG,IAAI,CAAC,YAAY,CAAC,aAAa,CACvD,uCAAuC,IAAI,CAAC,cAAc,CAAC,YAAY,IAAI,CAC5E,CAAC;gBACF,MAAM,cAAc,GAAG,iBAAiB,EAAE,cAAc,CAAC;gBAEzD,IAAI,cAAc;oBAAE,IAAI,CAAC,wBAAwB,CAAC,cAAc,EAAE,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;YAC9F,CAAC;QACH,CAAC;QAED,mDAAmD;QAC3C,6BAA6B,CAAC,cAAiC;YACrE,IAAI,CAAC,wBAAwB,CAAC,cAAc,EAAE,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;QAC1E,CAAC;QAED,oFAAoF;QAC7E,wBAAwB,CAAC,eAAkC,EAAE,KAAW,IAAS,CAAC;KAC1F;IAED,OAAO,aAAmD,CAAC;AAC7D,CAAC,CAAC","sourcesContent":["import type { View } from '@qti-components/base';\nimport type { QtiAssessmentItemRef } from '../components/qti-assessment-item-ref/qti-assessment-item-ref';\nimport type { QtiAssessmentItem } from '@qti-components/elements';\nimport type { TestBaseInterface } from './test-base';\n\ntype Constructor<T = {}> = abstract new (...args: any[]) => T;\n\ndeclare class TestViewInterface {\n updateAssessmentItemView(assessmentItem: QtiAssessmentItem, view: View): void;\n}\n\nexport const TestViewMixin = <T extends Constructor<TestBaseInterface>>(superClass: T) => {\n abstract class TestViewClass extends superClass implements TestViewInterface {\n constructor(...args: any[]) {\n super(...args);\n this.sessionContext = { ...this.sessionContext, view: 'candidate' };\n\n this.addEventListener('on-test-switch-view', (e: CustomEvent<View>) => {\n this.sessionContext = { ...this.sessionContext, view: e.detail };\n this._updateElementView();\n });\n this.addEventListener('qti-assessment-test-connected', () => {\n this._updateElementView();\n });\n this.addEventListener('qti-assessment-item-connected', (e: CustomEvent) => {\n this._updateElementView();\n this._setCorrectResponseVisibility(e.detail);\n });\n }\n\n willUpdate(changedProperties: Map<string | number | symbol, unknown>) {\n super.willUpdate(changedProperties);\n if (changedProperties.has('sessionContext')) {\n this._updateElementView();\n }\n }\n\n // Method to handle view updates for elements based on the current context view\n private _updateElementView() {\n if (this._testElement) {\n const viewElements = Array.from(this._testElement.querySelectorAll('[view]'));\n\n viewElements.forEach((element: HTMLElement) => {\n element.classList.toggle('show', element.getAttribute('view') === this.sessionContext.view);\n });\n\n const assessmentItemRef = this._testElement.querySelector<QtiAssessmentItemRef>(\n `qti-assessment-item-ref[identifier=\"${this.sessionContext.navItemRefId}\"]`\n );\n const assessmentItem = assessmentItemRef?.assessmentItem;\n\n if (assessmentItem) this.updateAssessmentItemView(assessmentItem, this.sessionContext.view);\n }\n }\n\n // Event handler for connected QTI assessment items\n private _setCorrectResponseVisibility(assessmentItem: QtiAssessmentItem): void {\n this.updateAssessmentItemView(assessmentItem, this.sessionContext.view);\n }\n\n /** Extension point for packages that add view-dependent assessment presentation. */\n public updateAssessmentItemView(_assessmentItem: QtiAssessmentItem, _view: View): void {}\n }\n\n return TestViewClass as Constructor<TestViewInterface> & T;\n};\n"]}
1
+ {"version":3,"file":"test-view.mixin.js","sourceRoot":"","sources":["../../src/mixins/test-view.mixin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAahD,MAAM,CAAC,MAAM,aAAa,GAAG,CAA2C,UAAa,EAAE,EAAE;IACvF,MAAe,aAAc,SAAQ,UAAU;QAC7C,YAAY,GAAG,IAAW;YACxB,KAAK,CAAC,GAAG,IAAI,CAAC,CAAC;YACf,IAAI,CAAC,cAAc,GAAG,EAAE,GAAG,IAAI,CAAC,cAAc,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC;YAEpE,YAAY,CAAC,IAAI,EAAE,uB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AC,cAAc,CAAC,YAAY,IAAI,CAC5E,CAAC;gBACF,MAAM,cAAc,GAAG,iBAAiB,EAAE,cAAc,CAAC;gBAEzD,IAAI,cAAc;oBAAE,IAAI,CAAC,wBAAwB,CAAC,cAAc,EAAE,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;YAC9F,CAAC;QACH,CAAC;QAED,mDAAmD;QAC3C,6BAA6B,CAAC,cAAiC;YACrE,IAAI,CAAC,wBAAwB,CAAC,cAAc,EAAE,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;QAC1E,CAAC;QAED,oFAAoF;QAC7E,wBAAwB,CAAC,eAAkC,EAAE,KAAW,IAAS,CAAC;KAC1F;IAED,OAAO,aAAmD,CAAC;AAC7D,CAAC,CAAC","sourcesContent":["import { listenPublic } from '../public-events';\n\nimport type { View } from '@qti-components/base';\nimport type { QtiAssessmentItemRef } from '../components/qti-assessment-item-ref/qti-assessment-item-ref';\nimport type { QtiAssessmentItem } from '@qti-components/elements';\nimport type { TestBaseInterface } from './test-base';\n\ntype Constructor<T = {}> = abstract new (...args: any[]) => T;\n\ndeclare class TestViewInterface {\n updateAssessmentItemView(assessmentItem: QtiAssessmentItem, view: View): void;\n}\n\nexport const TestViewMixin = <T extends Constructor<TestBaseInterface>>(superClass: T) => {\n abstract class TestViewClass extends superClass implements TestViewInterface {\n constructor(...args: any[]) {\n super(...args);\n this.sessionContext = { ...this.sessionContext, view: 'candidate' };\n\n listenPublic(this, 'cito-test-switch-view', e => {\n this.sessionContext = { ...this.sessionContext, view: e.detail };\n this._updateElementView();\n });\n listenPublic(this, 'cito-test-loaded', () => {\n this._updateElementView();\n });\n this.addEventListener('qti-assessment-item-connected', (e: CustomEvent) => {\n this._updateElementView();\n this._setCorrectResponseVisibility(e.detail);\n });\n }\n\n willUpdate(changedProperties: Map<string | number | symbol, unknown>) {\n super.willUpdate(changedProperties);\n if (changedProperties.has('sessionContext')) {\n this._updateElementView();\n }\n }\n\n // Method to handle view updates for elements based on the current context view\n private _updateElementView() {\n if (this._testElement) {\n const viewElements = Array.from(this._testElement.querySelectorAll('[view]'));\n\n viewElements.forEach((element: HTMLElement) => {\n element.classList.toggle('show', element.getAttribute('view') === this.sessionContext.view);\n });\n\n const assessmentItemRef = this._testElement.querySelector<QtiAssessmentItemRef>(\n `qti-assessment-item-ref[identifier=\"${this.sessionContext.navItemRefId}\"]`\n );\n const assessmentItem = assessmentItemRef?.assessmentItem;\n\n if (assessmentItem) this.updateAssessmentItemView(assessmentItem, this.sessionContext.view);\n }\n }\n\n // Event handler for connected QTI assessment items\n private _setCorrectResponseVisibility(assessmentItem: QtiAssessmentItem): void {\n this.updateAssessmentItemView(assessmentItem, this.sessionContext.view);\n }\n\n /** Extension point for packages that add view-dependent assessment presentation. */\n public updateAssessmentItemView(_assessmentItem: QtiAssessmentItem, _view: View): void {}\n }\n\n return TestViewClass as Constructor<TestViewInterface> & T;\n};\n"]}
@@ -0,0 +1,62 @@
1
+ import type { View } from '@qti-components/base';
2
+ import type { PublicEventDeclaration } from '@qti-components/elements/public-events';
3
+ import type { QtiTestState } from './types/qti-test-state';
4
+ /**
5
+ * The public events of the test. The name tells you it is public: everything here starts with
6
+ * `cito-`; every other event is internal plumbing and may change in any release.
7
+ *
8
+ * Requests are verbs (a host or plugin dispatches them at the test), notifications are past tense
9
+ * (the test dispatches them). All bubble and are composed.
10
+ *
11
+ * `deprecated` is the name this event had before it became public. One helper (`dispatchPublic`,
12
+ * `listenPublic`) sends or handles both names until the next major, then the field goes.
13
+ */
14
+ export interface NavigationTarget {
15
+ type: 'item' | 'section';
16
+ id: string;
17
+ }
18
+ export interface NavigationFailure {
19
+ message: string;
20
+ details?: unknown;
21
+ itemId?: string;
22
+ sectionId?: string;
23
+ }
24
+ export interface PublicEventMap {
25
+ 'cito-test-navigate': CustomEvent<NavigationTarget>;
26
+ 'cito-test-end-attempt': CustomEvent<unknown>;
27
+ 'cito-test-update-outcome': CustomEvent<{
28
+ assessmentItemRefId: string;
29
+ outcomeVariableId: string;
30
+ value: number | string;
31
+ }>;
32
+ 'cito-test-switch-view': CustomEvent<View>;
33
+ 'cito-test-navigated': CustomEvent<NavigationTarget>;
34
+ 'cito-test-navigation-started': CustomEvent<NavigationTarget>;
35
+ 'cito-test-navigation-failed': CustomEvent<NavigationFailure>;
36
+ 'cito-test-rendered': CustomEvent<{
37
+ identifier: string;
38
+ element: Element;
39
+ }[]>;
40
+ 'cito-test-state-changed': CustomEvent<QtiTestState>;
41
+ 'cito-item-ref-connected': CustomEvent<{
42
+ identifier: string;
43
+ href: string;
44
+ category: string;
45
+ }>;
46
+ }
47
+ export type PublicEventName = keyof PublicEventMap;
48
+ export declare const PUBLIC_EVENTS: Record<PublicEventName, PublicEventDeclaration>;
49
+ declare global {
50
+ interface HTMLElementEventMap extends PublicEventMap {
51
+ }
52
+ }
53
+ /**
54
+ * Dispatch a public event, and its deprecated name with the same `detail` object. The detail is
55
+ * always an object so `listenPublic` can tell the two apart from one dispatch.
56
+ */
57
+ export declare function dispatchPublic<K extends PublicEventName>(target: EventTarget, name: K, detail: PublicEventMap[K] extends CustomEvent<infer D> ? D : never): void;
58
+ /**
59
+ * Listen for a public event and its deprecated name; the handler runs once for a sender that
60
+ * dispatched both. See `listenDeclared`.
61
+ */
62
+ export declare function listenPublic<K extends PublicEventName>(target: EventTarget, name: K, handler: (e: PublicEventMap[K]) => void): void;