@qti-components/test 1.6.2 → 1.8.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 (41) hide show
  1. package/dist/components/index.d.ts +1 -0
  2. package/dist/components/index.js +1 -0
  3. package/dist/components/index.js.map +1 -1
  4. package/dist/components/qti-assessment-item-ref/qti-assessment-item-ref.d.ts +38 -3
  5. package/dist/components/qti-assessment-item-ref/qti-assessment-item-ref.js +128 -16
  6. package/dist/components/qti-assessment-item-ref/qti-assessment-item-ref.js.map +1 -1
  7. package/dist/components/qti-number-selected/qti-number-selected.d.ts +24 -0
  8. package/dist/components/qti-number-selected/qti-number-selected.js +42 -0
  9. package/dist/components/qti-number-selected/qti-number-selected.js.map +1 -0
  10. package/dist/components/qti-outcome-processing/qti-outcome-processing.js +12 -2
  11. package/dist/components/qti-outcome-processing/qti-outcome-processing.js.map +1 -1
  12. package/dist/components/qti-test-variables/qti-test-variables.js +28 -30
  13. package/dist/components/qti-test-variables/qti-test-variables.js.map +1 -1
  14. package/dist/components/styles.d.ts +3 -0
  15. package/dist/components/styles.js +29 -4
  16. package/dist/components/styles.js.map +1 -1
  17. package/dist/components/test-check-item/test-check-item.js +6 -0
  18. package/dist/components/test-check-item/test-check-item.js.map +1 -1
  19. package/dist/components/test-end-attempt/test-end-attempt.js +6 -0
  20. package/dist/components/test-end-attempt/test-end-attempt.js.map +1 -1
  21. package/dist/components/test-item-link/test-item-link.js +6 -0
  22. package/dist/components/test-item-link/test-item-link.js.map +1 -1
  23. package/dist/components/test-item-to-speech/test-item-to-speech.d.ts +82 -11
  24. package/dist/components/test-item-to-speech/test-item-to-speech.js +429 -62
  25. package/dist/components/test-item-to-speech/test-item-to-speech.js.map +1 -1
  26. package/dist/components/test-next/test-next.js +6 -0
  27. package/dist/components/test-next/test-next.js.map +1 -1
  28. package/dist/components/test-prev/test-prev.js +6 -0
  29. package/dist/components/test-prev/test-prev.js.map +1 -1
  30. package/dist/components/test-scoring-buttons/test-scoring-buttons.d.ts +1 -1
  31. package/dist/components/test-section-link/test-section-link.js +6 -0
  32. package/dist/components/test-section-link/test-section-link.js.map +1 -1
  33. package/dist/elements.d.ts +9 -2
  34. package/dist/elements.js +5 -2
  35. package/dist/elements.js.map +1 -1
  36. package/dist/internal/item-ref-selection.d.ts +27 -0
  37. package/dist/internal/item-ref-selection.js +44 -0
  38. package/dist/internal/item-ref-selection.js.map +1 -0
  39. package/dist/mixins/test-base.js +0 -1
  40. package/dist/mixins/test-base.js.map +1 -1
  41. package/package.json +6 -6
@@ -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;AAoBpG,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;YAuH1E;;;;;;;;eAQG;YACK,6BAAwB,GAAG,CAAC,cAAiC,EAAQ,EAAE;gBAC7E,MAAM,OAAO,GAAI,cAAsB,CAAC,QAAQ,CAAC;gBACjD,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;gBACtC,MAAM,aAAa,GAAG,OAAO,CAAC,SAAS,CAAC;gBAExC,kCAAkC;gBAClC,gEAAgE;gBAChE,MAAM,WAAW,GAAG,I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yDACqC;IAkK5E,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 } 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 _testElement: QtiAssessmentTest;\n updateItemVariables(itemRefID: string, variables: VariableValue<string | string[] | null>[]): void;\n}\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 updateItemVariables(itemRefID: string, variables: VariableValue<string | string[] | null>[]): void {\n // Update variables in the testContext for the specified itemRefID\n const itemContext = this.testContext.items.find(item => item.identifier === itemRefID);\n if (itemContext) {\n itemContext.variables = itemContext.variables.map(variable => {\n const updatedVariable = variables.find(v => v.identifier === variable.identifier);\n return updatedVariable ? { ...variable, ...updatedVariable } : variable;\n });\n }\n // if the qti-assessment-item-ref has a qti-assessment-item, then update this item as well\n const itemRef = this._testElement.querySelector<QtiAssessmentItemRef>(\n `qti-assessment-item-ref[identifier=\"${itemRefID}\"]`\n );\n if (itemRef && itemRef.assessmentItem) {\n itemRef.assessmentItem.variables = variables;\n }\n }\n\n private _initializeEventListeners(): void {\n /**\n * A new test document means a new test and session context.\n *\n * This resets on the document being loaded rather than on\n * `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 );\n });\n }\n\n private _updateItemVariablesInTestContext(\n identifier: string,\n variables: readonly VariableDeclaration<string | string[] | null>[],\n state?: ItemContext['state']\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 };\n })\n };\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 as any)._context;\n const identifier = context.identifier;\n const fullVariables = context.variables;\n\n // console.log(this._testContext);\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);\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 }\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;AAoBpG,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;YAuH1E;;;;;;;;eAQG;YACK,6BAAwB,GAAG,CAAC,cAAiC,EAAQ,EAAE;gBAC7E,MAAM,OAAO,GAAI,cAAsB,CAAC,QAAQ,CAAC;gBACjD,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,CA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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 } 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 _testElement: QtiAssessmentTest;\n updateItemVariables(itemRefID: string, variables: VariableValue<string | string[] | null>[]): void;\n}\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 updateItemVariables(itemRefID: string, variables: VariableValue<string | string[] | null>[]): void {\n // Update variables in the testContext for the specified itemRefID\n const itemContext = this.testContext.items.find(item => item.identifier === itemRefID);\n if (itemContext) {\n itemContext.variables = itemContext.variables.map(variable => {\n const updatedVariable = variables.find(v => v.identifier === variable.identifier);\n return updatedVariable ? { ...variable, ...updatedVariable } : variable;\n });\n }\n // if the qti-assessment-item-ref has a qti-assessment-item, then update this item as well\n const itemRef = this._testElement.querySelector<QtiAssessmentItemRef>(\n `qti-assessment-item-ref[identifier=\"${itemRefID}\"]`\n );\n if (itemRef && itemRef.assessmentItem) {\n itemRef.assessmentItem.variables = variables;\n }\n }\n\n private _initializeEventListeners(): void {\n /**\n * A new test document means a new test and session context.\n *\n * This resets on the document being loaded rather than on\n * `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 );\n });\n }\n\n private _updateItemVariablesInTestContext(\n identifier: string,\n variables: readonly VariableDeclaration<string | string[] | null>[],\n state?: ItemContext['state']\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 };\n })\n };\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 as any)._context;\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);\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 }\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"]}
package/package.json CHANGED
@@ -1,16 +1,16 @@
1
1
  {
2
2
  "name": "@qti-components/test",
3
3
  "description": "QTI test utilities",
4
- "version": "1.6.2",
4
+ "version": "1.8.0",
5
5
  "author": "",
6
6
  "dependencies": {
7
7
  "@heximal/templates": "^0.1.5",
8
- "@qti-components/base": "^2.2.0",
9
- "@qti-components/elements": "^1.7.0",
8
+ "@qti-components/base": "^2.3.0",
9
+ "@qti-components/elements": "^1.8.0",
10
10
  "@qti-components/interactions": "^1.10.4",
11
- "@qti-components/processing": "^1.5.0",
12
- "@qti-components/theme": "^2.2.0",
13
- "@qti-components/transformers": "^1.7.2",
11
+ "@qti-components/processing": "^1.6.0",
12
+ "@qti-components/theme": "^2.2.1",
13
+ "@qti-components/transformers": "^1.7.3",
14
14
  "@qti-components/utilities": "^1.3.3"
15
15
  },
16
16
  "devDependencies": {