@qti-components/test 1.2.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.
- package/LICENSE.md +674 -0
- package/dist/components/index.d.ts +24 -0
- package/dist/components/index.js +26 -0
- package/dist/components/index.js.map +1 -0
- package/dist/components/qti-assessment-item-ref/qti-assessment-item-ref.d.ts +22 -0
- package/dist/components/qti-assessment-item-ref/qti-assessment-item-ref.js +78 -0
- package/dist/components/qti-assessment-item-ref/qti-assessment-item-ref.js.map +1 -0
- package/dist/components/qti-assessment-section/qti-assessment-section.d.ts +20 -0
- package/dist/components/qti-assessment-section/qti-assessment-section.js +64 -0
- package/dist/components/qti-assessment-section/qti-assessment-section.js.map +1 -0
- package/dist/components/qti-assessment-test/qti-assessment-test.d.ts +16 -0
- package/dist/components/qti-assessment-test/qti-assessment-test.js +47 -0
- package/dist/components/qti-assessment-test/qti-assessment-test.js.map +1 -0
- package/dist/components/qti-outcome-processing/qti-outcome-processing.d.ts +15 -0
- package/dist/components/qti-outcome-processing/qti-outcome-processing.js +37 -0
- package/dist/components/qti-outcome-processing/qti-outcome-processing.js.map +1 -0
- package/dist/components/qti-test/qti-test.d.ts +69 -0
- package/dist/components/qti-test/qti-test.js +80 -0
- package/dist/components/qti-test/qti-test.js.map +1 -0
- package/dist/components/qti-test-feedback/qti-test-feedback.d.ts +10 -0
- package/dist/components/qti-test-feedback/qti-test-feedback.js +24 -0
- package/dist/components/qti-test-feedback/qti-test-feedback.js.map +1 -0
- package/dist/components/qti-test-part/qti-test-part.d.ts +17 -0
- package/dist/components/qti-test-part/qti-test-part.js +58 -0
- package/dist/components/qti-test-part/qti-test-part.js.map +1 -0
- package/dist/components/qti-test-variables/qti-test-variables.d.ts +25 -0
- package/dist/components/qti-test-variables/qti-test-variables.js +79 -0
- package/dist/components/qti-test-variables/qti-test-variables.js.map +1 -0
- package/dist/components/styles.d.ts +4 -0
- package/dist/components/styles.js +23 -0
- package/dist/components/styles.js.map +1 -0
- package/dist/components/test-check-item/test-check-item.d.ts +11 -0
- package/dist/components/test-check-item/test-check-item.js +43 -0
- package/dist/components/test-check-item/test-check-item.js.map +1 -0
- package/dist/components/test-container/test-container.d.ts +33 -0
- package/dist/components/test-container/test-container.js +122 -0
- package/dist/components/test-container/test-container.js.map +1 -0
- package/dist/components/test-end-attempt/test-end-attempt.d.ts +11 -0
- package/dist/components/test-end-attempt/test-end-attempt.js +31 -0
- package/dist/components/test-end-attempt/test-end-attempt.js.map +1 -0
- package/dist/components/test-item-link/test-item-link.d.ts +13 -0
- package/dist/components/test-item-link/test-item-link.js +45 -0
- package/dist/components/test-item-link/test-item-link.js.map +1 -0
- package/dist/components/test-navigation/test-navigation.d.ts +35 -0
- package/dist/components/test-navigation/test-navigation.js +401 -0
- package/dist/components/test-navigation/test-navigation.js.map +1 -0
- package/dist/components/test-next/test-next.d.ts +33 -0
- package/dist/components/test-next/test-next.js +96 -0
- package/dist/components/test-next/test-next.js.map +1 -0
- package/dist/components/test-paging-buttons-stamp/test-paging-buttons-stamp.d.ts +19 -0
- package/dist/components/test-paging-buttons-stamp/test-paging-buttons-stamp.js +44 -0
- package/dist/components/test-paging-buttons-stamp/test-paging-buttons-stamp.js.map +1 -0
- package/dist/components/test-prev/test-prev.d.ts +31 -0
- package/dist/components/test-prev/test-prev.js +87 -0
- package/dist/components/test-prev/test-prev.js.map +1 -0
- package/dist/components/test-print-context/test-print-context.d.ts +11 -0
- package/dist/components/test-print-context/test-print-context.js +24 -0
- package/dist/components/test-print-context/test-print-context.js.map +1 -0
- package/dist/components/test-print-item-variables/test-print-item-variables.d.ts +12 -0
- package/dist/components/test-print-item-variables/test-print-item-variables.js +88 -0
- package/dist/components/test-print-item-variables/test-print-item-variables.js.map +1 -0
- package/dist/components/test-scoring-buttons/test-scoring-buttons.d.ts +19 -0
- package/dist/components/test-scoring-buttons/test-scoring-buttons.js +101 -0
- package/dist/components/test-scoring-buttons/test-scoring-buttons.js.map +1 -0
- package/dist/components/test-scoring-feedback/test-scoring-feedback.d.ts +13 -0
- package/dist/components/test-scoring-feedback/test-scoring-feedback.js +58 -0
- package/dist/components/test-scoring-feedback/test-scoring-feedback.js.map +1 -0
- package/dist/components/test-section-buttons-stamp/test-section-buttons-stamp.d.ts +19 -0
- package/dist/components/test-section-buttons-stamp/test-section-buttons-stamp.js +44 -0
- package/dist/components/test-section-buttons-stamp/test-section-buttons-stamp.js.map +1 -0
- package/dist/components/test-section-link/test-section-link.d.ts +13 -0
- package/dist/components/test-section-link/test-section-link.js +45 -0
- package/dist/components/test-section-link/test-section-link.js.map +1 -0
- package/dist/components/test-show-correct-response/test-show-correct-response.d.ts +22 -0
- package/dist/components/test-show-correct-response/test-show-correct-response.js +91 -0
- package/dist/components/test-show-correct-response/test-show-correct-response.js.map +1 -0
- package/dist/components/test-stamp/test-stamp.d.ts +28 -0
- package/dist/components/test-stamp/test-stamp.js +104 -0
- package/dist/components/test-stamp/test-stamp.js.map +1 -0
- package/dist/components/test-view-toggle/test-view-toggle.d.ts +16 -0
- package/dist/components/test-view-toggle/test-view-toggle.js +57 -0
- package/dist/components/test-view-toggle/test-view-toggle.js.map +1 -0
- package/dist/components/test-view-toggle/test-view.d.ts +20 -0
- package/dist/components/test-view-toggle/test-view.js +81 -0
- package/dist/components/test-view-toggle/test-view.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/mixins/index.d.ts +3 -0
- package/dist/mixins/index.js +4 -0
- package/dist/mixins/index.js.map +1 -0
- package/dist/mixins/test-base.d.ts +17 -0
- package/dist/mixins/test-base.js +153 -0
- package/dist/mixins/test-base.js.map +1 -0
- package/dist/mixins/test-navigation.mixin.d.ts +26 -0
- package/dist/mixins/test-navigation.mixin.js +502 -0
- package/dist/mixins/test-navigation.mixin.js.map +1 -0
- package/dist/mixins/test-processing.mixin.d.ts +11 -0
- package/dist/mixins/test-processing.mixin.js +55 -0
- package/dist/mixins/test-processing.mixin.js.map +1 -0
- package/dist/mixins/test-view.mixin.d.ts +6 -0
- package/dist/mixins/test-view.mixin.js +45 -0
- package/dist/mixins/test-view.mixin.js.map +1 -0
- package/dist/types/iqti-test.d.ts +28 -0
- package/dist/types/iqti-test.js +2 -0
- package/dist/types/iqti-test.js.map +1 -0
- package/package.json +51 -0
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { provide } from '@lit/context';
|
|
8
|
+
import { LitElement } from 'lit';
|
|
9
|
+
import { property } from 'lit/decorators.js';
|
|
10
|
+
import { INITIAL_TEST_CONTEXT, testContext } from '@qti-components/base';
|
|
11
|
+
import { INITIAL_SESSION_CONTEXT, sessionContext } from '@qti-components/base';
|
|
12
|
+
export const TestBaseMixin = (superClass) => {
|
|
13
|
+
class TestBaseClass extends superClass {
|
|
14
|
+
constructor(...args) {
|
|
15
|
+
super(...args);
|
|
16
|
+
this.testContext = INITIAL_TEST_CONTEXT;
|
|
17
|
+
this.sessionContext = INITIAL_SESSION_CONTEXT;
|
|
18
|
+
/**
|
|
19
|
+
* Updates the variables of an assessment item in the test context.
|
|
20
|
+
* - Matches the assessment item with the corresponding test context item.
|
|
21
|
+
* - If the item is not found, logs a warning.
|
|
22
|
+
* - Updates variables in the test context if exactly one variable exists.
|
|
23
|
+
* - Otherwise, syncs the assessment item's variables with the test context.
|
|
24
|
+
*
|
|
25
|
+
* @param assessmentItem - The assessment item to update.
|
|
26
|
+
*/
|
|
27
|
+
this._updateItemInTestContext = (assessmentItem) => {
|
|
28
|
+
const context = assessmentItem._context;
|
|
29
|
+
const identifier = context.identifier;
|
|
30
|
+
const fullVariables = context.variables;
|
|
31
|
+
// console.log(this._testContext);
|
|
32
|
+
// Find the corresponding item in the test context by identifier
|
|
33
|
+
const itemContext = this.testContext.items.find(i => i?.identifier === identifier);
|
|
34
|
+
if (!itemContext) {
|
|
35
|
+
console.warn(`Item IDs between assessment.xml and item.xml should match: ${identifier} is not found!`);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
// Update variables in the test context or sync them to the assessment item
|
|
39
|
+
if (itemContext.variables?.length === 1) {
|
|
40
|
+
// The loaded qti-assessment-item itself has variables which are not in test context yet.
|
|
41
|
+
this._updateItemVariablesInTestContext(identifier, fullVariables);
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
const newVariables = [...assessmentItem.variables];
|
|
45
|
+
// Sync the assessment item's variables with the test context
|
|
46
|
+
for (const variable of itemContext.variables) {
|
|
47
|
+
const currentVariable = newVariables.find(v => v.identifier === variable.identifier);
|
|
48
|
+
if (currentVariable) {
|
|
49
|
+
currentVariable.value = variable.value;
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
newVariables.push(variable);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
assessmentItem.variables = newVariables;
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
this._initializeEventListeners();
|
|
59
|
+
}
|
|
60
|
+
updateItemVariables(itemRefID, variables) {
|
|
61
|
+
// Update variables in the testContext for the specified itemRefID
|
|
62
|
+
const itemContext = this.testContext.items.find(item => item.identifier === itemRefID);
|
|
63
|
+
if (itemContext) {
|
|
64
|
+
itemContext.variables = itemContext.variables.map(variable => {
|
|
65
|
+
const updatedVariable = variables.find(v => v.identifier === variable.identifier);
|
|
66
|
+
return updatedVariable ? { ...variable, ...updatedVariable } : variable;
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
// if the qti-assessment-item-ref has a qti-assessment-item, then update this item as well
|
|
70
|
+
const itemRef = this._testElement.querySelector(`qti-assessment-item-ref[identifier="${itemRefID}"]`);
|
|
71
|
+
if (itemRef && itemRef.assessmentItem) {
|
|
72
|
+
itemRef.assessmentItem.variables = variables;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
_initializeEventListeners() {
|
|
76
|
+
/**
|
|
77
|
+
* When the test is connected, the items are updated in the test context.
|
|
78
|
+
* An existing context item is updated with the itemRef properties if nessesary.
|
|
79
|
+
*/
|
|
80
|
+
this.addEventListener('qti-assessment-test-connected', (e) => {
|
|
81
|
+
this.testContext = INITIAL_TEST_CONTEXT; // new test, new test context!
|
|
82
|
+
this.sessionContext = INITIAL_SESSION_CONTEXT; // new test, new session context!
|
|
83
|
+
if (this.testContext && this.testContext.items.length > 0)
|
|
84
|
+
return;
|
|
85
|
+
this._testElement = e.detail;
|
|
86
|
+
const items = Array.from(this._testElement.querySelectorAll('qti-assessment-item-ref')).map(itemRef => {
|
|
87
|
+
return {
|
|
88
|
+
href: itemRef.href,
|
|
89
|
+
identifier: itemRef.identifier,
|
|
90
|
+
category: itemRef.category,
|
|
91
|
+
variables: [
|
|
92
|
+
{
|
|
93
|
+
identifier: 'completionStatus',
|
|
94
|
+
value: 'not_attempted',
|
|
95
|
+
type: 'outcome'
|
|
96
|
+
}
|
|
97
|
+
]
|
|
98
|
+
};
|
|
99
|
+
});
|
|
100
|
+
this.testContext = { ...this.testContext, items };
|
|
101
|
+
});
|
|
102
|
+
this.addEventListener('qti-assessment-item-connected', (e) => {
|
|
103
|
+
const assessmentItem = e.detail;
|
|
104
|
+
const assessmentRefId = assessmentItem.closest('qti-assessment-item-ref')?.identifier;
|
|
105
|
+
if (assessmentRefId) {
|
|
106
|
+
assessmentItem.assessmentItemRefId = assessmentRefId;
|
|
107
|
+
}
|
|
108
|
+
this._updateItemInTestContext(e.detail);
|
|
109
|
+
});
|
|
110
|
+
this.addEventListener('qti-item-context-updated', (e) => {
|
|
111
|
+
// const assessmentitem = e.composedPath()[0] as QtiAssessmentItem;
|
|
112
|
+
this._updateItemVariablesInTestContext(e.detail.itemContext.identifier, e.detail.itemContext.variables, e.detail.itemContext.state);
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
_updateItemVariablesInTestContext(identifier, variables, state) {
|
|
116
|
+
// Update the test context with modified variables for the specified item
|
|
117
|
+
this.testContext = {
|
|
118
|
+
...this.testContext, // Spread existing test context properties
|
|
119
|
+
items: this.testContext.items.map(itemContext => {
|
|
120
|
+
// If the item identifier doesn't match, keep it unchanged
|
|
121
|
+
if (itemContext.identifier !== identifier) {
|
|
122
|
+
return itemContext;
|
|
123
|
+
}
|
|
124
|
+
// Update the matching item with new variables
|
|
125
|
+
return {
|
|
126
|
+
...itemContext, // Keep other properties of the item context
|
|
127
|
+
variables: variables.map(variable => {
|
|
128
|
+
// Find a matching variable in the current item context
|
|
129
|
+
const matchingVariable = itemContext.variables.find(v => v.identifier === variable.identifier);
|
|
130
|
+
// Merge matching variable with the new one, or use the new variable if no match
|
|
131
|
+
return matchingVariable ? { ...matchingVariable, ...variable } : variable;
|
|
132
|
+
}),
|
|
133
|
+
...(state !== undefined ? { state: state ? { ...state } : undefined } : {})
|
|
134
|
+
};
|
|
135
|
+
})
|
|
136
|
+
};
|
|
137
|
+
this.dispatchEvent(new CustomEvent('qti-test-context-updated', { detail: this.testContext, bubbles: false, composed: false }));
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
__decorate([
|
|
141
|
+
property({ attribute: false, type: Object }),
|
|
142
|
+
provide({ context: testContext })
|
|
143
|
+
], TestBaseClass.prototype, "testContext", void 0);
|
|
144
|
+
__decorate([
|
|
145
|
+
property({ attribute: false, type: Object }),
|
|
146
|
+
provide({ context: sessionContext })
|
|
147
|
+
], TestBaseClass.prototype, "sessionContext", void 0);
|
|
148
|
+
return TestBaseClass;
|
|
149
|
+
};
|
|
150
|
+
// Keep the old abstract class for backwards compatibility during migration
|
|
151
|
+
export class TestBase extends TestBaseMixin(LitElement) {
|
|
152
|
+
}
|
|
153
|
+
//# sourceMappingURL=test-base.js.map
|
|
@@ -0,0 +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;AAkBpG,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;YA2G1E;;;;;;;;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,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,UAAU,KAAK,UAAU,CAAC,CAAC;gBAEnF,IAAI,CAAC,WAAW,EAAE,CAAC;oBACjB,OAAO,CAAC,IAAI,CAAC,8DAA8D,UAAU,gBAAgB,CAAC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import { 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 { 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 _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 * When the test is connected, the items are updated in the test context.\n * An existing context item is updated with the itemRef properties if nessesary.\n */\n this.addEventListener('qti-assessment-test-connected', (e: CustomEvent<QtiAssessmentTest>) => {\n this.testContext = INITIAL_TEST_CONTEXT; // new test, new test context!\n this.sessionContext = INITIAL_SESSION_CONTEXT; // new test, new session context!\n if (this.testContext && this.testContext.items.length > 0) return;\n\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"]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { transformItemApi, transformTestApi } from '@qti-components/transformers';
|
|
2
|
+
import type { QtiAssessmentItemRef } from '../components/qti-assessment-item-ref/qti-assessment-item-ref';
|
|
3
|
+
import type { QtiAssessmentTest } from '../components/qti-assessment-test/qti-assessment-test';
|
|
4
|
+
import type { TestBaseInterface } from './test-base';
|
|
5
|
+
type Constructor<T = {}> = abstract new (...args: any[]) => T;
|
|
6
|
+
export type PostLoadTransformCallback = (transformer: transformItemApi, itemRef: QtiAssessmentItemRef) => transformItemApi | Promise<transformItemApi>;
|
|
7
|
+
export type PostLoadTestTransformCallback = (transformer: transformTestApi, testElement: QtiAssessmentTest) => transformTestApi | Promise<transformTestApi>;
|
|
8
|
+
export interface NavigationError {
|
|
9
|
+
message: string;
|
|
10
|
+
details?: any;
|
|
11
|
+
itemId?: string;
|
|
12
|
+
sectionId?: string;
|
|
13
|
+
}
|
|
14
|
+
declare class TestNavigationInterface {
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Navigation mixin for QTI test components
|
|
18
|
+
*
|
|
19
|
+
* Provides comprehensive navigation functionality with:
|
|
20
|
+
* - Efficient item/section loading with AbortController support
|
|
21
|
+
* - Stimulus reference coordination and duplicate prevention
|
|
22
|
+
* - Proper event timing and state management
|
|
23
|
+
* - Error handling and edge case coverage
|
|
24
|
+
*/
|
|
25
|
+
export declare const TestNavigationMixin: <T extends Constructor<TestBaseInterface>>(superClass: T) => Constructor<TestNavigationInterface> & T;
|
|
26
|
+
export {};
|