@qti-components/test 2.0.0-next.30 → 2.0.0-next.32
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/dist/components/qti-test/qti-test.d.ts +13 -2
- package/dist/components/qti-test/qti-test.js +23 -4
- package/dist/components/qti-test/qti-test.js.map +1 -1
- package/dist/components/qti-test/test-src.fixtures.d.ts +6 -0
- package/dist/components/qti-test/test-src.fixtures.js +7 -0
- package/dist/components/qti-test/test-src.fixtures.js.map +1 -0
- package/dist/components/test-container/test-container.d.ts +15 -11
- package/dist/components/test-container/test-container.js +46 -25
- package/dist/components/test-container/test-container.js.map +1 -1
- package/dist/internal/test-host.context.d.ts +2 -0
- package/dist/internal/test-host.context.js.map +1 -1
- package/dist/mixins/test-processing.mixin.js +23 -0
- package/dist/mixins/test-processing.mixin.js.map +1 -1
- package/package.json +2 -2
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { LitElement } from 'lit';
|
|
2
|
+
import type { PropertyValues } from 'lit';
|
|
2
3
|
import type { ConfigContext, QtiContext } from '@qti-components/base';
|
|
3
4
|
declare const QtiTest_base: (abstract new (...args: any[]) => import("../..").ITestNavigationMixin) & (abstract new (...args: any[]) => {
|
|
4
5
|
updateAssessmentItemView(assessmentItem: import("@qti-components/elements").QtiAssessmentItem, view: import("@qti-components/base").View): void;
|
|
@@ -20,9 +21,9 @@ declare const QtiTest_base: (abstract new (...args: any[]) => import("../..").IT
|
|
|
20
21
|
* Minimal example including navigation:
|
|
21
22
|
*
|
|
22
23
|
* ```html
|
|
23
|
-
* <qti-test>
|
|
24
|
+
* <qti-test src="./path/to/assessment.xml" navigate="item">
|
|
24
25
|
* <test-navigation>
|
|
25
|
-
* <test-container
|
|
26
|
+
* <test-container></test-container>
|
|
26
27
|
* <nav class="flex">
|
|
27
28
|
* <test-prev></test-prev>
|
|
28
29
|
* <test-next></test-next>
|
|
@@ -62,7 +63,17 @@ declare const QtiTest_base: (abstract new (...args: any[]) => import("../..").IT
|
|
|
62
63
|
* @event qti-test-context-updated - Deprecated: listen to `qc-test-state-changed` to persist a session. `detail` is the full test context, including declaration metadata and the answer key. Removed in the next major.
|
|
63
64
|
*/
|
|
64
65
|
export declare class QtiTest extends QtiTest_base {
|
|
66
|
+
#private;
|
|
65
67
|
constructor();
|
|
68
|
+
/**
|
|
69
|
+
* URL of the `assessmentTest` XML. Changing it loads another test into the `test-container`
|
|
70
|
+
* inside. Relative URLs resolve against the page, and the items' `href`s against the test.
|
|
71
|
+
*
|
|
72
|
+
* `test-url` on `test-container` is the deprecated name for this, kept until 11; when both are
|
|
73
|
+
* set, `src` wins.
|
|
74
|
+
*/
|
|
75
|
+
src: string | null;
|
|
76
|
+
protected updated(changed: PropertyValues): void;
|
|
66
77
|
configContext: ConfigContext;
|
|
67
78
|
/**
|
|
68
79
|
* Who is taking which test, and the optional shuffle `seed`. Provided here, at the test, so
|
|
@@ -6,7 +6,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
6
6
|
};
|
|
7
7
|
import { ContextProvider, provide } from '@lit/context';
|
|
8
8
|
import { html, LitElement } from 'lit';
|
|
9
|
-
import { state } from 'lit/decorators.js';
|
|
9
|
+
import { property, state } from 'lit/decorators.js';
|
|
10
10
|
import { configContext, qtiContext } from '@qti-components/base';
|
|
11
11
|
import { testHostContext } from '../../internal/test-host.context';
|
|
12
12
|
import { TestNavigationMixin, TestViewMixin } from '../../mixins';
|
|
@@ -23,9 +23,9 @@ import { TestStateMixin } from '../../mixins/test-state.mixin';
|
|
|
23
23
|
* Minimal example including navigation:
|
|
24
24
|
*
|
|
25
25
|
* ```html
|
|
26
|
-
* <qti-test>
|
|
26
|
+
* <qti-test src="./path/to/assessment.xml" navigate="item">
|
|
27
27
|
* <test-navigation>
|
|
28
|
-
* <test-container
|
|
28
|
+
* <test-container></test-container>
|
|
29
29
|
* <nav class="flex">
|
|
30
30
|
* <test-prev></test-prev>
|
|
31
31
|
* <test-next></test-next>
|
|
@@ -67,8 +67,18 @@ import { TestStateMixin } from '../../mixins/test-state.mixin';
|
|
|
67
67
|
export class QtiTest extends TestNavigationMixin(TestViewMixin(TestProcessingMixin(TestStateMixin(TestBaseMixin(LitElement))))) {
|
|
68
68
|
// TODO: Properly implement IQtiTest interface
|
|
69
69
|
// export class QtiTest extends TestLoaderMixin(TestNavigationMixin(TestViewMixin(TestBase))) {
|
|
70
|
+
/** Tells the components inside that something they read from the test changed (see `src`). */
|
|
71
|
+
#hostProvider;
|
|
70
72
|
constructor() {
|
|
71
73
|
super();
|
|
74
|
+
/**
|
|
75
|
+
* URL of the `assessmentTest` XML. Changing it loads another test into the `test-container`
|
|
76
|
+
* inside. Relative URLs resolve against the page, and the items' `href`s against the test.
|
|
77
|
+
*
|
|
78
|
+
* `test-url` on `test-container` is the deprecated name for this, kept until 11; when both are
|
|
79
|
+
* set, `src` wins.
|
|
80
|
+
*/
|
|
81
|
+
this.src = null;
|
|
72
82
|
this.configContext = {};
|
|
73
83
|
/**
|
|
74
84
|
* Who is taking which test, and the optional shuffle `seed`. Provided here, at the test, so
|
|
@@ -88,7 +98,13 @@ export class QtiTest extends TestNavigationMixin(TestViewMixin(TestProcessingMix
|
|
|
88
98
|
}
|
|
89
99
|
};
|
|
90
100
|
// The components inside find their test through this, across shadow roots (see TestHost).
|
|
91
|
-
new ContextProvider(this, { context: testHostContext, initialValue: this });
|
|
101
|
+
this.#hostProvider = new ContextProvider(this, { context: testHostContext, initialValue: this });
|
|
102
|
+
}
|
|
103
|
+
updated(changed) {
|
|
104
|
+
super.updated(changed);
|
|
105
|
+
// The provided value is this element, whose identity never changes: force the notification.
|
|
106
|
+
if (changed.has('src'))
|
|
107
|
+
this.#hostProvider.setValue(this, true);
|
|
92
108
|
}
|
|
93
109
|
/**
|
|
94
110
|
* Renders the component's template.
|
|
@@ -103,6 +119,9 @@ export class QtiTest extends TestNavigationMixin(TestViewMixin(TestProcessingMix
|
|
|
103
119
|
return html `<slot></slot>`;
|
|
104
120
|
}
|
|
105
121
|
}
|
|
122
|
+
__decorate([
|
|
123
|
+
property({ type: String })
|
|
124
|
+
], QtiTest.prototype, "src", void 0);
|
|
106
125
|
__decorate([
|
|
107
126
|
state(),
|
|
108
127
|
provide({ context: configContext })
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"qti-test.js","sourceRoot":"","sources":["../../../src/components/qti-test/qti-test.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACxD,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AACvC,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"qti-test.js","sourceRoot":"","sources":["../../../src/components/qti-test/qti-test.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACxD,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAEpD,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAEjE,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AACnE,OAAO,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAClE,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AACzE,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAM/D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AAEH,MAAM,OAAO,OAAQ,SAAQ,mBAAmB,CAC9C,aAAa,CAAC,mBAAmB,CAAC,cAAc,CAAC,aAAa,CAAC,UAA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IACP,OAAO,CAAC,EAAE,OAAO,EAAE,UAAU,EAAE,CAAC;2CAO/B","sourcesContent":["import { ContextProvider, provide } from '@lit/context';\nimport { html, LitElement } from 'lit';\nimport { property, state } from 'lit/decorators.js';\n\nimport { configContext, qtiContext } from '@qti-components/base';\n\nimport { testHostContext } from '../../internal/test-host.context';\nimport { TestNavigationMixin, TestViewMixin } from '../../mixins';\nimport { TestBaseMixin } from '../../mixins/test-base';\nimport { TestProcessingMixin } from '../../mixins/test-processing.mixin';\nimport { TestStateMixin } from '../../mixins/test-state.mixin';\n\nimport type { PropertyValues } from 'lit';\nimport type { ConfigContext, QtiContext } from '@qti-components/base';\nimport type { IQtiTest } from '../../types/iqti-test';\n\n/**\n * `<qti-test>` is a custom element designed for rendering and interacting with QTI (Question and Test Interoperability) tests.\n *\n * This component leverages several mixins to provide functionality for loading, navigating, processing, and displaying QTI test assessments.\n *\n * ### Example Usage\n *\n * Minimal example including navigation:\n *\n * ```html\n * <qti-test src=\"./path/to/assessment.xml\" navigate=\"item\">\n * <test-navigation>\n * <test-container></test-container>\n * <nav class=\"flex\">\n * <test-prev></test-prev>\n * <test-next></test-next>\n * </nav>\n * </test-navigation>\n * </qti-test>\n * ```\n *\n * Use the following file structure\n * A qti-test loads a QTI3.0 assessmenttest.xml file from a package folder.\n *\n * ```plaintext\n * Root/\n * ├── index.html\n * └── /assets/api/examples/\n * ├── assessmenttest.xml\n * └── imsmanifest.xml\n *\n * ```\n *\n * ### Test components\n *\n * Use test components inside the qti-test component for added functionality.\n * ### Test next\n * `<test-next> | TestNext`\n *\n * ### Test prev\n *\n * `<test-prev> | TestPrev`\n * ### Test components\n *\n * You can use normal class names to style the elements.\n * And you can use the `test-prev` and `test-next` elements to navigate through the test.\n *\n * @event qc-test-state-changed - The candidate's persistable state changed. `detail` is a `QtiTestState`; assign it back to `state` to resume.\n * @event qc-test-state-refused - A value assigned to `state` is not a version 1 `QtiTestState` and was ignored; the test goes on without it. `detail` is `{ message, state }`. Sent once the test has loaded.\n * @event qti-test-context-updated - Deprecated: listen to `qc-test-state-changed` to persist a session. `detail` is the full test context, including declaration metadata and the answer key. Removed in the next major.\n */\n\nexport class QtiTest extends TestNavigationMixin(\n TestViewMixin(TestProcessingMixin(TestStateMixin(TestBaseMixin(LitElement))))\n) {\n // TODO: Properly implement IQtiTest interface\n // export class QtiTest extends TestLoaderMixin(TestNavigationMixin(TestViewMixin(TestBase))) {\n\n /** Tells the components inside that something they read from the test changed (see `src`). */\n #hostProvider: ContextProvider<typeof testHostContext>;\n\n constructor() {\n super();\n // The components inside find their test through this, across shadow roots (see TestHost).\n this.#hostProvider = new ContextProvider(this, { context: testHostContext, initialValue: this });\n }\n\n /**\n * URL of the `assessmentTest` XML. Changing it loads another test into the `test-container`\n * inside. Relative URLs resolve against the page, and the items' `href`s against the test.\n *\n * `test-url` on `test-container` is the deprecated name for this, kept until 11; when both are\n * set, `src` wins.\n */\n @property({ type: String })\n public src: string | null = null;\n\n protected override updated(changed: PropertyValues): void {\n super.updated(changed);\n // The provided value is this element, whose identity never changes: force the notification.\n if (changed.has('src')) this.#hostProvider.setValue(this, true);\n }\n\n @state()\n @provide({ context: configContext })\n public configContext: ConfigContext = {};\n\n /**\n * Who is taking which test, and the optional shuffle `seed`. Provided here, at the test, so\n * everything inside reads one value: the test-container shuffling the item order, the test\n * shuffling interactions as it navigates, and the expressions that read `QTI_CONTEXT`.\n *\n * Pass the same `seed` when resuming a session, or the order comes back different. Replace the\n * object, do not mutate it: an in-place change does not notify the components inside.\n *\n * `test-navigation.qtiContext` is an alias of this.\n */\n @state()\n @provide({ context: qtiContext })\n public qtiContext: QtiContext = {\n QTI_CONTEXT: {\n testIdentifier: '',\n candidateIdentifier: '',\n environmentIdentifier: 'default'\n }\n };\n\n /**\n * Renders the component's template.\n * Provides a default `<slot>` for content projection.\n */\n override async connectedCallback(): Promise<void> {\n super.connectedCallback();\n await this.updateComplete;\n this.dispatchEvent(new CustomEvent('qti-test-connected', { detail: this }));\n }\n\n override render() {\n return html`<slot></slot>`;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'qti-test': QtiTest;\n }\n}\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The two tests the `src` contract stories load: switching `src` from one to the other must show
|
|
3
|
+
* the other test's first item.
|
|
4
|
+
*/
|
|
5
|
+
export declare const CONFORMANCE_T4_T7_TEST = "/assets/qti-conformance/Basic/T4-T7/assessment.xml";
|
|
6
|
+
export declare const STIMULUS_TEST = "/assets/qti-test-package-stimulus/assessment.xml";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The two tests the `src` contract stories load: switching `src` from one to the other must show
|
|
3
|
+
* the other test's first item.
|
|
4
|
+
*/
|
|
5
|
+
export const CONFORMANCE_T4_T7_TEST = '/assets/qti-conformance/Basic/T4-T7/assessment.xml';
|
|
6
|
+
export const STIMULUS_TEST = '/assets/qti-test-package-stimulus/assessment.xml';
|
|
7
|
+
//# sourceMappingURL=test-src.fixtures.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test-src.fixtures.js","sourceRoot":"","sources":["../../../src/components/qti-test/test-src.fixtures.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,oDAAoD,CAAC;AAC3F,MAAM,CAAC,MAAM,aAAa,GAAG,kDAAkD,CAAC","sourcesContent":["/**\n * The two tests the `src` contract stories load: switching `src` from one to the other must show\n * the other test's first item.\n */\nexport const CONFORMANCE_T4_T7_TEST = '/assets/qti-conformance/Basic/T4-T7/assessment.xml';\nexport const STIMULUS_TEST = '/assets/qti-test-package-stimulus/assessment.xml';\n"]}
|
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
import { LitElement } from 'lit';
|
|
2
|
+
import type { PropertyValues } from 'lit';
|
|
2
3
|
import type { QtiContext } from '@qti-components/base';
|
|
3
4
|
import type { TestHost } from '../../internal/test-host.context';
|
|
4
5
|
/**
|
|
5
|
-
* `<test-container>` is a
|
|
6
|
-
*
|
|
7
|
-
* The element loads the test from the provided URL and renders it inside the shadow DOM.
|
|
6
|
+
* `<test-container>` is where a `qti-test` shows its test: it loads the test from the `src` of the
|
|
7
|
+
* `qti-test` it is in, and renders the `qti-assessment-test` inside its shadow root.
|
|
8
8
|
*
|
|
9
9
|
* ```html
|
|
10
|
-
* <qti-test>
|
|
11
|
-
* <test-
|
|
12
|
-
* <test-container class="m-4 bg-white" test-url="./path/to/assessmenttest.xml"></test-container>
|
|
13
|
-
* </test-navigation>
|
|
10
|
+
* <qti-test src="./path/to/assessmenttest.xml">
|
|
11
|
+
* <test-container></test-container>
|
|
14
12
|
* </qti-test>
|
|
15
13
|
* ```
|
|
16
14
|
*/
|
|
@@ -18,18 +16,24 @@ export declare class TestContainer extends LitElement {
|
|
|
18
16
|
#private;
|
|
19
17
|
/** Scoped registry used by the test shadow root. Must be set before connection. */
|
|
20
18
|
customElementRegistry: CustomElementRegistry | null;
|
|
21
|
-
/**
|
|
19
|
+
/**
|
|
20
|
+
* @deprecated Set `src` on `qti-test`. The URL of the test to load, used only while the
|
|
21
|
+
* `qti-test` has no `src`. Warns once per element. Removed in 11.
|
|
22
|
+
*/
|
|
22
23
|
testURL: string | null;
|
|
23
24
|
/** A parsed HTML document */
|
|
24
25
|
testDoc: DocumentFragment | null;
|
|
25
26
|
/** The raw XML string */
|
|
26
27
|
testXML: string | null;
|
|
27
|
-
/**
|
|
28
|
+
/**
|
|
29
|
+
* The `qti-test` this container is in: its `src`, and the host's `postLoadTestTransformCallback`.
|
|
30
|
+
* The test re-sends itself when `src` changes, so this updates although the value is the same.
|
|
31
|
+
*/
|
|
28
32
|
protected testHost?: TestHost;
|
|
33
|
+
constructor();
|
|
29
34
|
protected qtiContext: QtiContext;
|
|
30
35
|
protected createRenderRoot(): HTMLElement | DocumentFragment;
|
|
31
|
-
|
|
32
|
-
protected handleTestURLChange(): Promise<void>;
|
|
36
|
+
protected updated(changed: PropertyValues): void;
|
|
33
37
|
protected handleTestXMLChange(): void;
|
|
34
38
|
connectedCallback(): Promise<void>;
|
|
35
39
|
render(): import("lit").TemplateResult<1>;
|
|
@@ -4,7 +4,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
4
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
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
|
-
import { consume } from '@lit/context';
|
|
7
|
+
import { ContextConsumer, consume } from '@lit/context';
|
|
8
8
|
import { LitElement, html } from 'lit';
|
|
9
9
|
import { property, state } from 'lit/decorators.js';
|
|
10
10
|
import { until } from 'lit/directives/until.js';
|
|
@@ -14,24 +14,24 @@ import { qtiTransformTest } from '@qti-components/transformers';
|
|
|
14
14
|
import itemCss from '@qti-components/theme/item-css';
|
|
15
15
|
import { testHostContext } from '../../internal/test-host.context';
|
|
16
16
|
/**
|
|
17
|
-
* `<test-container>` is a
|
|
18
|
-
*
|
|
19
|
-
* The element loads the test from the provided URL and renders it inside the shadow DOM.
|
|
17
|
+
* `<test-container>` is where a `qti-test` shows its test: it loads the test from the `src` of the
|
|
18
|
+
* `qti-test` it is in, and renders the `qti-assessment-test` inside its shadow root.
|
|
20
19
|
*
|
|
21
20
|
* ```html
|
|
22
|
-
* <qti-test>
|
|
23
|
-
* <test-
|
|
24
|
-
* <test-container class="m-4 bg-white" test-url="./path/to/assessmenttest.xml"></test-container>
|
|
25
|
-
* </test-navigation>
|
|
21
|
+
* <qti-test src="./path/to/assessmenttest.xml">
|
|
22
|
+
* <test-container></test-container>
|
|
26
23
|
* </qti-test>
|
|
27
24
|
* ```
|
|
28
25
|
*/
|
|
29
26
|
export class TestContainer extends LitElement {
|
|
30
27
|
constructor() {
|
|
31
|
-
super(
|
|
28
|
+
super();
|
|
32
29
|
/** Scoped registry used by the test shadow root. Must be set before connection. */
|
|
33
30
|
this.customElementRegistry = null;
|
|
34
|
-
/**
|
|
31
|
+
/**
|
|
32
|
+
* @deprecated Set `src` on `qti-test`. The URL of the test to load, used only while the
|
|
33
|
+
* `qti-test` has no `src`. Warns once per element. Removed in 11.
|
|
34
|
+
*/
|
|
35
35
|
this.testURL = null;
|
|
36
36
|
/** A parsed HTML document */
|
|
37
37
|
this.testDoc = null;
|
|
@@ -42,10 +42,24 @@ export class TestContainer extends LitElement {
|
|
|
42
42
|
};
|
|
43
43
|
/** Template content if provided */
|
|
44
44
|
this.#templateContent = null;
|
|
45
|
+
/** The URL last loaded, so a re-sent test host or an unchanged alias does not load it again. */
|
|
46
|
+
this.#loadedURL = null;
|
|
47
|
+
this.#warnedTestURL = false;
|
|
45
48
|
this.#resolvedCustomElementRegistry = null;
|
|
49
|
+
new ContextConsumer(this, {
|
|
50
|
+
context: testHostContext,
|
|
51
|
+
subscribe: true,
|
|
52
|
+
callback: host => {
|
|
53
|
+
this.testHost = host;
|
|
54
|
+
this.requestUpdate();
|
|
55
|
+
}
|
|
56
|
+
});
|
|
46
57
|
}
|
|
47
58
|
/** Template content if provided */
|
|
48
59
|
#templateContent;
|
|
60
|
+
/** The URL last loaded, so a re-sent test host or an unchanged alias does not load it again. */
|
|
61
|
+
#loadedURL;
|
|
62
|
+
#warnedTestURL;
|
|
49
63
|
#resolvedCustomElementRegistry;
|
|
50
64
|
createRenderRoot() {
|
|
51
65
|
const registry = this.customElementRegistry;
|
|
@@ -58,14 +72,27 @@ export class TestContainer extends LitElement {
|
|
|
58
72
|
}
|
|
59
73
|
/** Callback function to transform the test after loading */
|
|
60
74
|
// @property({ type: Function }) postLoadTestTransformCallback: PostLoadTestTransformCallback | null = null;
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
75
|
+
/** The URL to load: the test's `src`, else the deprecated `test-url`. */
|
|
76
|
+
get #url() {
|
|
77
|
+
return this.testHost?.src || this.testURL || null;
|
|
78
|
+
}
|
|
79
|
+
updated(changed) {
|
|
80
|
+
super.updated(changed);
|
|
81
|
+
if (changed.has('testURL') && this.testURL && !this.#warnedTestURL) {
|
|
82
|
+
this.#warnedTestURL = true;
|
|
83
|
+
console.warn('[qti-components] `test-url` / `testURL` on `<test-container>` is deprecated and will be removed in 11. ' +
|
|
84
|
+
'Set `src` on `<qti-test>` instead.');
|
|
85
|
+
}
|
|
86
|
+
const url = this.#url;
|
|
87
|
+
if (url && url !== this.#loadedURL) {
|
|
88
|
+
this.#loadedURL = url;
|
|
89
|
+
this.#load(url);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
async #load(url) {
|
|
64
93
|
try {
|
|
65
94
|
const explicitSeed = this.qtiContext?.QTI_CONTEXT?.seed;
|
|
66
|
-
let api = (await qtiTransformTest().load(
|
|
67
|
-
.applySelection(explicitSeed)
|
|
68
|
-
.shuffleOrdering(explicitSeed);
|
|
95
|
+
let api = (await qtiTransformTest().load(url)).applySelection(explicitSeed).shuffleOrdering(explicitSeed);
|
|
69
96
|
// Apply external transformation if provided
|
|
70
97
|
const qtiTest = this.testHost;
|
|
71
98
|
if (qtiTest?.postLoadTestTransformCallback) {
|
|
@@ -77,6 +104,9 @@ export class TestContainer extends LitElement {
|
|
|
77
104
|
api = await qtiTest.postLoadTestTransformCallback(api, testElement);
|
|
78
105
|
}
|
|
79
106
|
}
|
|
107
|
+
// A newer URL was asked for while this one loaded: drop this one.
|
|
108
|
+
if (url !== this.#loadedURL)
|
|
109
|
+
return;
|
|
80
110
|
this.#setTestDoc(api.htmlDoc(this.#resolvedCustomElementRegistry ?? undefined));
|
|
81
111
|
}
|
|
82
112
|
catch (error) {
|
|
@@ -119,9 +149,6 @@ export class TestContainer extends LitElement {
|
|
|
119
149
|
super.connectedCallback();
|
|
120
150
|
this.#initializeTemplateContent();
|
|
121
151
|
this.#applyStyles();
|
|
122
|
-
if (this.testURL) {
|
|
123
|
-
this.handleTestURLChange();
|
|
124
|
-
}
|
|
125
152
|
if (this.testXML) {
|
|
126
153
|
this.handleTestXMLChange();
|
|
127
154
|
}
|
|
@@ -155,16 +182,10 @@ __decorate([
|
|
|
155
182
|
__decorate([
|
|
156
183
|
state()
|
|
157
184
|
], TestContainer.prototype, "testXML", void 0);
|
|
158
|
-
__decorate([
|
|
159
|
-
consume({ context: testHostContext, subscribe: true })
|
|
160
|
-
], TestContainer.prototype, "testHost", void 0);
|
|
161
185
|
__decorate([
|
|
162
186
|
state(),
|
|
163
187
|
consume({ context: qtiContext, subscribe: true })
|
|
164
188
|
], TestContainer.prototype, "qtiContext", void 0);
|
|
165
|
-
__decorate([
|
|
166
|
-
watch('testURL', { waitUntilFirstUpdate: true })
|
|
167
|
-
], TestContainer.prototype, "handleTestURLChange", null);
|
|
168
189
|
__decorate([
|
|
169
190
|
watch('testXML', { waitUntilFirstUpdate: true })
|
|
170
191
|
], TestContainer.prototype, "handleTestXMLChange", null);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"test-container.js","sourceRoot":"","sources":["../../../src/components/test-container/test-container.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,KAAK,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAEhD,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,KAAK,EAAE,MAAM,2BAA2B,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,OAAO,MAAM,gCAAgC,CAAC;AAErD,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AAKnE;;;;;;;;;;;;GAYG;AAEH,MAAM,OAAO,aAAc,SAAQ,UAAU;IAA7C;;QACE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B;IADC,KAAK,EAAE;8CACgC;AAIxC;IADC,KAAK,EAAE;8CACsB;AAIpB;IADT,OAAO,CAAC,EAAE,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;+CACzB;AAIpB;IAFT,KAAK,EAAE;IACP,OAAO,CAAC,EAAE,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;iDAGhD;AAwBc;IADf,KAAK,CAAC,SAAS,EAAE,EAAE,oBAAoB,EAAE,IAAI,EAAE,CAAC;wDAyBhD;AAuBS;IADT,KAAK,CAAC,SAAS,EAAE,EAAE,oBAAoB,EAAE,IAAI,EAAE,CAAC;wDAehD","sourcesContent":["import { consume } from '@lit/context';\nimport { LitElement, html } from 'lit';\nimport { property, state } from 'lit/decorators.js';\nimport { until } from 'lit/directives/until.js';\n\nimport { qtiContext } from '@qti-components/base';\nimport { watch } from '@qti-components/utilities';\nimport { qtiTransformTest } from '@qti-components/transformers';\nimport itemCss from '@qti-components/theme/item-css';\n\nimport { testHostContext } from '../../internal/test-host.context';\n\nimport type { QtiContext } from '@qti-components/base';\nimport type { TestHost } from '../../internal/test-host.context';\n\n/**\n * `<test-container>` is a custom element designed for hosting the qti-assessment-item.\n * The `qti-assessment-test` will be placed inside the shadow DOM of this element.\n * The element loads the test from the provided URL and renders it inside the shadow DOM.\n *\n * ```html\n * <qti-test>\n * <test-navigation>\n * <test-container class=\"m-4 bg-white\" test-url=\"./path/to/assessmenttest.xml\"></test-container>\n * </test-navigation>\n * </qti-test>\n * ```\n */\n\nexport class TestContainer extends LitElement {\n /** Scoped registry used by the test shadow root. Must be set before connection. */\n @property({ attribute: false })\n customElementRegistry: CustomElementRegistry | null = null;\n\n /** URL of the item to load */\n @property({ type: String, attribute: 'test-url' })\n testURL: string | null = null;\n\n /** A parsed HTML document */\n @state()\n testDoc: DocumentFragment | null = null;\n\n /** The raw XML string */\n @state()\n testXML: string | null = null;\n\n /** The `qti-test` this container is in: where the host's `postLoadTestTransformCallback` lives. */\n @consume({ context: testHostContext, subscribe: true })\n protected testHost?: TestHost;\n\n @state()\n @consume({ context: qtiContext, subscribe: true })\n protected qtiContext: QtiContext = {\n QTI_CONTEXT: { testIdentifier: '', candidateIdentifier: '', environmentIdentifier: 'default' }\n };\n\n /** Template content if provided */\n #templateContent: unknown = null;\n #resolvedCustomElementRegistry: CustomElementRegistry | null = null;\n\n protected override createRenderRoot(): HTMLElement | DocumentFragment {\n const registry = this.customElementRegistry;\n\n this.#resolvedCustomElementRegistry = registry;\n\n return (\n this.shadowRoot ??\n this.attachShadow({\n ...(this.constructor as typeof TestContainer).shadowRootOptions,\n ...(registry ? { customElementRegistry: registry } : {})\n })\n );\n }\n\n /** Callback function to transform the test after loading */\n // @property({ type: Function }) postLoadTestTransformCallback: PostLoadTestTransformCallback | null = null;\n\n @watch('testURL', { waitUntilFirstUpdate: true })\n protected async handleTestURLChange() {\n if (!this.testURL) return;\n try {\n const explicitSeed = this.qtiContext?.QTI_CONTEXT?.seed;\n let api = (await qtiTransformTest().load(this.testURL))\n .applySelection(explicitSeed)\n .shuffleOrdering(explicitSeed);\n // Apply external transformation if provided\n const qtiTest = this.testHost;\n if (qtiTest?.postLoadTestTransformCallback) {\n // Create a temporary document to get the test element reference\n const tempDoc = api.htmlDoc(this.#resolvedCustomElementRegistry ?? undefined);\n const testElement = tempDoc.querySelector('qti-assessment-test') as any;\n\n if (testElement) {\n // Apply the callback with the test element\n api = await qtiTest.postLoadTestTransformCallback(api, testElement);\n }\n }\n\n this.#setTestDoc(api.htmlDoc(this.#resolvedCustomElementRegistry ?? undefined));\n } catch (error) {\n console.error('Error loading or parsing XML:', error);\n }\n }\n\n /**\n * Assign a new test document and announce it.\n *\n * The announcement has to happen here rather than on\n * `qc-test-loaded`, because by then the new document's\n * children have already connected and registered themselves — a host that\n * resets its context on that event throws those registrations away. Lit's\n * re-render is async, so a handler running now still gets in before any child\n * of the new `qti-assessment-test` connects.\n */\n #setTestDoc(testDoc: DocumentFragment): void {\n this.testDoc = testDoc;\n this.dispatchEvent(\n new CustomEvent('qti-testdoc-loaded', {\n bubbles: true,\n composed: true\n })\n );\n }\n\n @watch('testXML', { waitUntilFirstUpdate: true })\n protected handleTestXMLChange() {\n if (!this.testXML) return;\n try {\n const explicitSeed = this.qtiContext?.QTI_CONTEXT?.seed;\n this.#setTestDoc(\n qtiTransformTest()\n .parse(this.testXML)\n .applySelection(explicitSeed)\n .shuffleOrdering(explicitSeed)\n .htmlDoc(this.#resolvedCustomElementRegistry ?? undefined)\n );\n } catch (error) {\n console.error('Error parsing XML:', error);\n }\n }\n\n override async connectedCallback(): Promise<void> {\n super.connectedCallback();\n this.#initializeTemplateContent();\n this.#applyStyles();\n if (this.testURL) {\n this.handleTestURLChange();\n }\n if (this.testXML) {\n this.handleTestXMLChange();\n }\n }\n\n #initializeTemplateContent() {\n const template = this.querySelector('template') as HTMLTemplateElement;\n this.#templateContent = template ? template.content : html``;\n }\n\n #applyStyles() {\n const sheet = new CSSStyleSheet();\n sheet.replaceSync(itemCss);\n this.shadowRoot.adoptedStyleSheets = [sheet];\n }\n\n override render() {\n return html`\n ${this.#templateContent}\n <slot></slot>\n ${until(this.testDoc, html`<span>Loading...</span>`)}\n `;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'test-container': TestContainer;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"test-container.js","sourceRoot":"","sources":["../../../src/components/test-container/test-container.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,KAAK,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAEhD,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,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AAIxC;IADC,KAAK,EAAE;8CACsB;AAsBpB;IAFT,KAAK,EAAE;IACP,OAAO,CAAC,EAAE,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;iDAGhD;AA6FQ;IADT,KAAK,CAAC,SAAS,EAAE,EAAE,oBAAoB,EAAE,IAAI,EAAE,CAAC;wDAehD","sourcesContent":["import { ContextConsumer, consume } from '@lit/context';\nimport { LitElement, html } from 'lit';\nimport { property, state } from 'lit/decorators.js';\nimport { until } from 'lit/directives/until.js';\n\nimport { qtiContext } from '@qti-components/base';\nimport { watch } from '@qti-components/utilities';\nimport { qtiTransformTest } from '@qti-components/transformers';\nimport itemCss from '@qti-components/theme/item-css';\n\nimport { testHostContext } from '../../internal/test-host.context';\n\nimport type { PropertyValues } from 'lit';\nimport type { QtiContext } from '@qti-components/base';\nimport type { TestHost } from '../../internal/test-host.context';\n\n/**\n * `<test-container>` is where a `qti-test` shows its test: it loads the test from the `src` of the\n * `qti-test` it is in, and renders the `qti-assessment-test` inside its shadow root.\n *\n * ```html\n * <qti-test src=\"./path/to/assessmenttest.xml\">\n * <test-container></test-container>\n * </qti-test>\n * ```\n */\n\nexport class TestContainer extends LitElement {\n /** Scoped registry used by the test shadow root. Must be set before connection. */\n @property({ attribute: false })\n customElementRegistry: CustomElementRegistry | null = null;\n\n /**\n * @deprecated Set `src` on `qti-test`. The URL of the test to load, used only while the\n * `qti-test` has no `src`. Warns once per element. Removed in 11.\n */\n @property({ type: String, attribute: 'test-url' })\n testURL: string | null = null;\n\n /** A parsed HTML document */\n @state()\n testDoc: DocumentFragment | null = null;\n\n /** The raw XML string */\n @state()\n testXML: string | null = null;\n\n /**\n * The `qti-test` this container is in: its `src`, and the host's `postLoadTestTransformCallback`.\n * The test re-sends itself when `src` changes, so this updates although the value is the same.\n */\n protected testHost?: TestHost;\n\n constructor() {\n super();\n new ContextConsumer(this, {\n context: testHostContext,\n subscribe: true,\n callback: host => {\n this.testHost = host;\n this.requestUpdate();\n }\n });\n }\n\n @state()\n @consume({ context: qtiContext, subscribe: true })\n protected qtiContext: QtiContext = {\n QTI_CONTEXT: { testIdentifier: '', candidateIdentifier: '', environmentIdentifier: 'default' }\n };\n\n /** Template content if provided */\n #templateContent: unknown = null;\n /** The URL last loaded, so a re-sent test host or an unchanged alias does not load it again. */\n #loadedURL: string | null = null;\n #warnedTestURL = false;\n #resolvedCustomElementRegistry: CustomElementRegistry | null = null;\n\n protected override createRenderRoot(): HTMLElement | DocumentFragment {\n const registry = this.customElementRegistry;\n\n this.#resolvedCustomElementRegistry = registry;\n\n return (\n this.shadowRoot ??\n this.attachShadow({\n ...(this.constructor as typeof TestContainer).shadowRootOptions,\n ...(registry ? { customElementRegistry: registry } : {})\n })\n );\n }\n\n /** Callback function to transform the test after loading */\n // @property({ type: Function }) postLoadTestTransformCallback: PostLoadTestTransformCallback | null = null;\n\n /** The URL to load: the test's `src`, else the deprecated `test-url`. */\n get #url(): string | null {\n return this.testHost?.src || this.testURL || null;\n }\n\n protected override updated(changed: PropertyValues): void {\n super.updated(changed);\n if (changed.has('testURL') && this.testURL && !this.#warnedTestURL) {\n this.#warnedTestURL = true;\n console.warn(\n '[qti-components] `test-url` / `testURL` on `<test-container>` is deprecated and will be removed in 11. ' +\n 'Set `src` on `<qti-test>` instead.'\n );\n }\n const url = this.#url;\n if (url && url !== this.#loadedURL) {\n this.#loadedURL = url;\n this.#load(url);\n }\n }\n\n async #load(url: string) {\n try {\n const explicitSeed = this.qtiContext?.QTI_CONTEXT?.seed;\n let api = (await qtiTransformTest().load(url)).applySelection(explicitSeed).shuffleOrdering(explicitSeed);\n // Apply external transformation if provided\n const qtiTest = this.testHost;\n if (qtiTest?.postLoadTestTransformCallback) {\n // Create a temporary document to get the test element reference\n const tempDoc = api.htmlDoc(this.#resolvedCustomElementRegistry ?? undefined);\n const testElement = tempDoc.querySelector('qti-assessment-test') as any;\n\n if (testElement) {\n // Apply the callback with the test element\n api = await qtiTest.postLoadTestTransformCallback(api, testElement);\n }\n }\n\n // A newer URL was asked for while this one loaded: drop this one.\n if (url !== this.#loadedURL) return;\n this.#setTestDoc(api.htmlDoc(this.#resolvedCustomElementRegistry ?? undefined));\n } catch (error) {\n console.error('Error loading or parsing XML:', error);\n }\n }\n\n /**\n * Assign a new test document and announce it.\n *\n * The announcement has to happen here rather than on\n * `qc-test-loaded`, because by then the new document's\n * children have already connected and registered themselves — a host that\n * resets its context on that event throws those registrations away. Lit's\n * re-render is async, so a handler running now still gets in before any child\n * of the new `qti-assessment-test` connects.\n */\n #setTestDoc(testDoc: DocumentFragment): void {\n this.testDoc = testDoc;\n this.dispatchEvent(\n new CustomEvent('qti-testdoc-loaded', {\n bubbles: true,\n composed: true\n })\n );\n }\n\n @watch('testXML', { waitUntilFirstUpdate: true })\n protected handleTestXMLChange() {\n if (!this.testXML) return;\n try {\n const explicitSeed = this.qtiContext?.QTI_CONTEXT?.seed;\n this.#setTestDoc(\n qtiTransformTest()\n .parse(this.testXML)\n .applySelection(explicitSeed)\n .shuffleOrdering(explicitSeed)\n .htmlDoc(this.#resolvedCustomElementRegistry ?? undefined)\n );\n } catch (error) {\n console.error('Error parsing XML:', error);\n }\n }\n\n override async connectedCallback(): Promise<void> {\n super.connectedCallback();\n this.#initializeTemplateContent();\n this.#applyStyles();\n if (this.testXML) {\n this.handleTestXMLChange();\n }\n }\n\n #initializeTemplateContent() {\n const template = this.querySelector('template') as HTMLTemplateElement;\n this.#templateContent = template ? template.content : html``;\n }\n\n #applyStyles() {\n const sheet = new CSSStyleSheet();\n sheet.replaceSync(itemCss);\n this.shadowRoot.adoptedStyleSheets = [sheet];\n }\n\n override render() {\n return html`\n ${this.#templateContent}\n <slot></slot>\n ${until(this.testDoc, html`<span>Loading...</span>`)}\n `;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'test-container': TestContainer;\n }\n}\n"]}
|
|
@@ -16,6 +16,8 @@ export type PostLoadTestTransformCallback = (transformer: transformTestApi, test
|
|
|
16
16
|
* would never find its test. Internal on purpose: not exported from the package, and not API.
|
|
17
17
|
*/
|
|
18
18
|
export interface TestHost extends HTMLElement {
|
|
19
|
+
/** The test's URL; `test-container` loads it. The context is re-sent whenever it changes. */
|
|
20
|
+
src: string | null;
|
|
19
21
|
qtiContext: QtiContext;
|
|
20
22
|
postLoadTestTransformCallback: PostLoadTestTransformCallback | null;
|
|
21
23
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"test-host.context.js","sourceRoot":"","sources":["../../src/internal/test-host.context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"test-host.context.js","sourceRoot":"","sources":["../../src/internal/test-host.context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AA8C7C,MAAM,CAAC,MAAM,eAAe,GAAG,aAAa,CAAW,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC","sourcesContent":["import { createContext } from '@lit/context';\n\nimport type { QtiContext } from '@qti-components/base';\nimport type { transformTestApi } from '@qti-components/transformers';\nimport type { QtiAssessmentTest } from '../components/qti-assessment-test/qti-assessment-test';\n\n/**\n * Defined here, and re-exported by the navigation mixin under the same name, so this file imports\n * nothing from the mixin: the mixin imports the components that consume this context, and a type\n * import counts as a dependency for madge.\n */\nexport type PostLoadTestTransformCallback = (\n transformer: transformTestApi,\n testElement: QtiAssessmentTest\n) => transformTestApi | Promise<transformTestApi>;\n\n/**\n * What the components inside a test need from the `qti-test` that contains them: the things a host\n * put on it, and the element to query. Provided by `qti-test` about itself.\n *\n * It is context and not `closest('qti-test')` because a request crosses shadow roots and `closest`\n * stops at the first one, so a navigation or container a host renders inside its own component\n * would never find its test. Internal on purpose: not exported from the package, and not API.\n */\nexport interface TestHost extends HTMLElement {\n /** The test's URL; `test-container` loads it. The context is re-sent whenever it changes. */\n src: string | null;\n qtiContext: QtiContext;\n postLoadTestTransformCallback: PostLoadTestTransformCallback | null;\n /**\n * Set by `test-navigation`, which keeps the item sessions: asked by the navigation mixin before a\n * Next in a linear part leaves `itemRefId`, while that item is still rendered. It ends the item's\n * attempt when one is open (roadmap 1, T3b2b) and answers null, or answers why the item may not\n * be left yet.\n */\n beforeLinearNext?: ((itemRefId: string) => LinearNextRefusal | null) | null;\n /** Sets the candidate's comment on an item-ref; null clears it. `test-navigation` checks `rules.mayComment` first. */\n updateItemComment(itemRefId: string, comment: string | null): void;\n}\n\n/** Why Next may not leave an item yet: its responses are ones its session control refuses. */\nexport interface LinearNextRefusal {\n reason: 'allow-skipping' | 'validate-responses';\n itemId: string;\n}\n\nexport const testHostContext = createContext<TestHost>(Symbol('testHost'));\n"]}
|
|
@@ -11,6 +11,18 @@ export const TestProcessingMixin = (superClass) => {
|
|
|
11
11
|
e.stopPropagation();
|
|
12
12
|
});
|
|
13
13
|
listenPublic(this, 'qc-test-submit', () => this.submit());
|
|
14
|
+
// QTI 3 info model §2.9: the test's outcome processing runs each time the candidate submits an
|
|
15
|
+
// item in an individual part, after the item's response processing, so branch rules and
|
|
16
|
+
// pre-conditions read test outcomes that include it (impl. guide §4.5.3, step 1). Registered
|
|
17
|
+
// after the base mixin's listener, so the test context already holds the item's new values.
|
|
18
|
+
// A simultaneous part is processed when the part is submitted (roadmap 1, T6).
|
|
19
|
+
this.addEventListener('qti-item-context-updated', (e) => {
|
|
20
|
+
if (!e.detail?.responseProcessed)
|
|
21
|
+
return;
|
|
22
|
+
if (this.#submissionModeOf(e.detail.itemContext?.identifier) !== 'individual')
|
|
23
|
+
return;
|
|
24
|
+
this.outcomeProcessing();
|
|
25
|
+
});
|
|
14
26
|
// wordt aangeroepen vanuit de processingtemplate
|
|
15
27
|
this.addEventListener('qti-set-outcome-value', (e) => {
|
|
16
28
|
const { outcomeIdentifier, value } = e.detail;
|
|
@@ -18,6 +30,17 @@ export const TestProcessingMixin = (superClass) => {
|
|
|
18
30
|
e.stopPropagation();
|
|
19
31
|
});
|
|
20
32
|
}
|
|
33
|
+
/** The `submission-mode` of the test part that holds this item-ref; null when it is not in the test. */
|
|
34
|
+
#submissionModeOf(itemRefIdentifier) {
|
|
35
|
+
if (!itemRefIdentifier || !this._testElement)
|
|
36
|
+
return null;
|
|
37
|
+
const part = this._testElement
|
|
38
|
+
.querySelector(`qti-assessment-item-ref[identifier="${CSS.escape(itemRefIdentifier)}"]`)
|
|
39
|
+
?.closest('qti-test-part');
|
|
40
|
+
if (!part)
|
|
41
|
+
return null;
|
|
42
|
+
return part.getAttribute('submission-mode') === 'simultaneous' ? 'simultaneous' : 'individual';
|
|
43
|
+
}
|
|
21
44
|
outcomeProcessing() {
|
|
22
45
|
// Inside the loaded test: `test-container` renders it into its own shadow root, which a
|
|
23
46
|
// `querySelector` on this element does not reach. Without a loaded test, look in the light DOM.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"test-processing.mixin.js","sourceRoot":"","sources":["../../src/mixins/test-processing.mixin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAiBhE,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAA2C,UAAa,EAAE,EAAE;IAC7F,MAAe,qBAAsB,SAAQ,UAAU;QACrD,YAAY,GAAG,IAAW;YACxB,KAAK,CAAC,GAAG,IAAI,CAAC,CAAC;YACf,IAAI,CAAC,gBAAgB,CAAC,uBAAuB,EAAE,CAAC,CAAiC,EAAE,EAAE;gBACnF,IAAI,CAAC,WAAW,GAAG;oBACjB,GAAG,IAAI,CAAC,WAAW;oBACnB,oBAAoB,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,oBAAoB,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC;iBAC5F,CAAC;gBACF,CAAC,CAAC,eAAe,EAAE,CAAC;YACtB,CAAC,CAAC,CAAC;YACH,YAAY,CAAC,IAAI,EAAE,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CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,UAAU,KAAK,UAAU,CAAC,IAAI,IAAI,CAAC;QAC/F,CAAC;KAEF;IAED,OAAO,qBAAiE,CAAC;AAC3E,CAAC,CAAC","sourcesContent":["import { dispatchPublic, listenPublic } from '../public-events';\n\nimport type { QtiOutcomeProcessing } from '../components/qti-outcome-processing/qti-outcome-processing';\nimport type { QtiTestFeedback } from '../components/qti-test-feedback/qti-test-feedback';\nimport type { OutcomeVariable, VariableDeclaration } from '@qti-components/base';\nimport type { TestBaseInterface } from './test-base';\n\ntype Constructor<T = {}> = abstract new (...args: any[]) => T;\n\ndeclare class TestProcessingInterface {\n updateOutcomeVariable(identifier: string, value: string | string[] | undefined): void;\n getOutcome(identifier: string): Readonly<OutcomeVariable>;\n getVariable(identifier: string): Readonly<VariableDeclaration<string | string[] | null>>;\n outcomeProcessing(): boolean;\n submit(): boolean;\n getTestFeedback(access?: 'atEnd' | 'during'): QtiTestFeedback[];\n}\nexport const TestProcessingMixin = <T extends Constructor<TestBaseInterface>>(superClass: T) => {\n abstract class TestProcessingElement extends superClass implements TestProcessingInterface {\n constructor(...args: any[]) {\n super(...args);\n this.addEventListener('qti-register-variable', (e: CustomEvent<{ variable: any }>) => {\n this.testContext = {\n ...this.testContext,\n testOutcomeVariables: [...(this.testContext.testOutcomeVariables || []), e.detail.variable]\n };\n e.stopPropagation();\n });\n listenPublic(this, 'qc-test-submit', () => this.submit());\n // wordt aangeroepen vanuit de processingtemplate\n this.addEventListener(\n 'qti-set-outcome-value',\n (e: CustomEvent<{ outcomeIdentifier: string; value: string | string[] }>) => {\n const { outcomeIdentifier, value } = e.detail;\n this.updateOutcomeVariable(outcomeIdentifier, value);\n e.stopPropagation();\n }\n );\n }\n\n outcomeProcessing(): boolean {\n // Inside the loaded test: `test-container` renders it into its own shadow root, which a\n // `querySelector` on this element does not reach. Without a loaded test, look in the light DOM.\n const outcomeProcessor = (this._testElement ?? this).querySelector(\n 'qti-outcome-processing'\n ) as unknown as QtiOutcomeProcessing;\n if (!outcomeProcessor) return false;\n // QTI starts every run of the test's outcome processing from the declared defaults, so an\n // accumulating rule (`SCORE_TOTAL = sum + SCORE_TOTAL`) gives the same total on every run.\n this.testContext = {\n ...this.testContext,\n testOutcomeVariables: this.testContext.testOutcomeVariables?.map(v => ({\n ...v,\n value: v.defaultValue ?? null\n }))\n };\n outcomeProcessor.process();\n return true;\n }\n\n /**\n * Ends the test for scoring: runs `outcomeProcessing()`, then tells the host with\n * `qc-test-submitted`. Returns false, and sends nothing, when the test has no outcome processing.\n */\n submit(): boolean {\n if (!this.outcomeProcessing()) return false;\n dispatchPublic(this, 'qc-test-submitted', {});\n return true;\n }\n\n /**\n * The `qti-test-feedback` elements that apply now, read from the test outcomes: run\n * `outcomeProcessing()` first. `access` narrows them to the end of the test (`atEnd`) or to\n * while it runs (`during`); without it, both.\n */\n getTestFeedback(access?: 'atEnd' | 'during'): QtiTestFeedback[] {\n const feedback = Array.from(\n (this._testElement ?? this).querySelectorAll<QtiTestFeedback>('qti-test-feedback') ?? []\n );\n return feedback.filter(\n fb => (!access || fb.access === access) && fb.matches(this.getOutcome(fb.outcomeIdentifier)?.value)\n );\n }\n\n /* --------------------------- ENABLED WHEN UNIT TESTING OUTCOME PROCESSING ------------------------------------ */\n\n public updateOutcomeVariable(identifier: string, value: string | string[] | undefined) {\n const outcomeVariable = this.getOutcome(identifier);\n if (!outcomeVariable) {\n console.warn(`Can not set qti-outcome-identifier: ${identifier}, it is not available`);\n return;\n }\n this.testContext = {\n ...this.testContext,\n testOutcomeVariables: this.testContext.testOutcomeVariables?.map(v => {\n if (v.identifier !== identifier) {\n return v;\n }\n return {\n ...v,\n value: outcomeVariable.cardinality === 'single' ? value : [...v.value, value as string]\n };\n })\n };\n }\n\n public getOutcome(identifier: string): Readonly<OutcomeVariable> {\n return this.getVariable(identifier) as OutcomeVariable;\n }\n public getVariable(identifier: string): Readonly<VariableDeclaration<string | string[] | null>> {\n return this.testContext.testOutcomeVariables?.find(v => v.identifier === identifier) || null;\n }\n /* --------------------------- ENABLED WHEN UNIT TESTING OUTCOME PROCESSING ------------------------------------ */\n }\n\n return TestProcessingElement as Constructor<TestProcessingInterface> & T;\n};\n"]}
|
|
1
|
+
{"version":3,"file":"test-processing.mixin.js","sourceRoot":"","sources":["../../src/mixins/test-processing.mixin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAiBhE,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAA2C,UAAa,EAAE,EAAE;IAC7F,MAAe,qBAAsB,SAAQ,UAAU;QACrD,YAAY,GAAG,IAAW;YACxB,KAAK,CAAC,GAAG,IAAI,CAAC,CAAC;YACf,IAAI,CAAC,gBAAgB,CAAC,uBAAuB,EAAE,CAAC,CAAiC,EAAE,EAAE;gBACnF,IAAI,CAAC,WAAW,GAAG;oBACjB,GAAG,IAAI,CAAC,WAAW;oBACnB,oBAAoB,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,oBAAoB,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC;iBAC5F,CAAC;gBACF,CAAC,CAAC,eAAe,EAAE,CAAC;YACtB,CAAC,CAAC,CAAC;YACH,YAAY,CAAC,IAAI,EAAE,gBAAgB,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;YAC1D,+FAA+F;YAC/F,wFAAwF;YACxF,6FAA6F;YAC7F,4FAA4F;YAC5F,+EAA+E;YAC/E,IAAI,CAAC,gBAAgB,CACnB,0BAA0B,EAC1B,CAAC,CAAoF,EAAE,EAAE;gBACvF,IAAI,CAAC,CAAC,CAAC,MAAM,EAAE,iBAAiB;oBAAE,OAAO;gBACzC,IAAI,IAAI,CAAC,iBAAiB,CAAC,CAAC,CAAC,MAAM,CAAC,WAAW,EAAE,UAAU,CAAC,KAAK,YAAY;oBAAE,OAAO;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,UAAU,EAAE,CAAC;wBAChC,OAAO,CAAC,CAAC;oBACX,CAAC;oBACD,OAAO;wBACL,GAAG,CAAC;wBACJ,KAAK,EAAE,eAAe,CAAC,WAAW,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,KAAe,CAAC;qBACxF,CAAC;gBACJ,CAAC,CAAC;aACH,CAAC;QACJ,CAAC;QAEM,UAAU,CAAC,UAAkB;YAClC,OAAO,IAAI,CAAC,WAAW,CAAC,UAAU,CAAoB,CAAC;QACzD,CAAC;QACM,WAAW,CAAC,UAAkB;YACnC,OAAO,IAAI,CAAC,WAAW,CAAC,oBAAoB,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,UAAU,KAAK,UAAU,CAAC,IAAI,IAAI,CAAC;QAC/F,CAAC;KAEF;IAED,OAAO,qBAAiE,CAAC;AAC3E,CAAC,CAAC","sourcesContent":["import { dispatchPublic, listenPublic } from '../public-events';\n\nimport type { QtiOutcomeProcessing } from '../components/qti-outcome-processing/qti-outcome-processing';\nimport type { QtiTestFeedback } from '../components/qti-test-feedback/qti-test-feedback';\nimport type { OutcomeVariable, VariableDeclaration } from '@qti-components/base';\nimport type { TestBaseInterface } from './test-base';\n\ntype Constructor<T = {}> = abstract new (...args: any[]) => T;\n\ndeclare class TestProcessingInterface {\n updateOutcomeVariable(identifier: string, value: string | string[] | undefined): void;\n getOutcome(identifier: string): Readonly<OutcomeVariable>;\n getVariable(identifier: string): Readonly<VariableDeclaration<string | string[] | null>>;\n outcomeProcessing(): boolean;\n submit(): boolean;\n getTestFeedback(access?: 'atEnd' | 'during'): QtiTestFeedback[];\n}\nexport const TestProcessingMixin = <T extends Constructor<TestBaseInterface>>(superClass: T) => {\n abstract class TestProcessingElement extends superClass implements TestProcessingInterface {\n constructor(...args: any[]) {\n super(...args);\n this.addEventListener('qti-register-variable', (e: CustomEvent<{ variable: any }>) => {\n this.testContext = {\n ...this.testContext,\n testOutcomeVariables: [...(this.testContext.testOutcomeVariables || []), e.detail.variable]\n };\n e.stopPropagation();\n });\n listenPublic(this, 'qc-test-submit', () => this.submit());\n // QTI 3 info model §2.9: the test's outcome processing runs each time the candidate submits an\n // item in an individual part, after the item's response processing, so branch rules and\n // pre-conditions read test outcomes that include it (impl. guide §4.5.3, step 1). Registered\n // after the base mixin's listener, so the test context already holds the item's new values.\n // A simultaneous part is processed when the part is submitted (roadmap 1, T6).\n this.addEventListener(\n 'qti-item-context-updated',\n (e: CustomEvent<{ itemContext: { identifier: string }; responseProcessed?: boolean }>) => {\n if (!e.detail?.responseProcessed) return;\n if (this.#submissionModeOf(e.detail.itemContext?.identifier) !== 'individual') return;\n this.outcomeProcessing();\n }\n );\n // wordt aangeroepen vanuit de processingtemplate\n this.addEventListener(\n 'qti-set-outcome-value',\n (e: CustomEvent<{ outcomeIdentifier: string; value: string | string[] }>) => {\n const { outcomeIdentifier, value } = e.detail;\n this.updateOutcomeVariable(outcomeIdentifier, value);\n e.stopPropagation();\n }\n );\n }\n\n /** The `submission-mode` of the test part that holds this item-ref; null when it is not in the test. */\n #submissionModeOf(itemRefIdentifier: string | undefined): 'individual' | 'simultaneous' | null {\n if (!itemRefIdentifier || !this._testElement) return null;\n const part = this._testElement\n .querySelector(`qti-assessment-item-ref[identifier=\"${CSS.escape(itemRefIdentifier)}\"]`)\n ?.closest('qti-test-part');\n if (!part) return null;\n return part.getAttribute('submission-mode') === 'simultaneous' ? 'simultaneous' : 'individual';\n }\n\n outcomeProcessing(): boolean {\n // Inside the loaded test: `test-container` renders it into its own shadow root, which a\n // `querySelector` on this element does not reach. Without a loaded test, look in the light DOM.\n const outcomeProcessor = (this._testElement ?? this).querySelector(\n 'qti-outcome-processing'\n ) as unknown as QtiOutcomeProcessing;\n if (!outcomeProcessor) return false;\n // QTI starts every run of the test's outcome processing from the declared defaults, so an\n // accumulating rule (`SCORE_TOTAL = sum + SCORE_TOTAL`) gives the same total on every run.\n this.testContext = {\n ...this.testContext,\n testOutcomeVariables: this.testContext.testOutcomeVariables?.map(v => ({\n ...v,\n value: v.defaultValue ?? null\n }))\n };\n outcomeProcessor.process();\n return true;\n }\n\n /**\n * Ends the test for scoring: runs `outcomeProcessing()`, then tells the host with\n * `qc-test-submitted`. Returns false, and sends nothing, when the test has no outcome processing.\n */\n submit(): boolean {\n if (!this.outcomeProcessing()) return false;\n dispatchPublic(this, 'qc-test-submitted', {});\n return true;\n }\n\n /**\n * The `qti-test-feedback` elements that apply now, read from the test outcomes: run\n * `outcomeProcessing()` first. `access` narrows them to the end of the test (`atEnd`) or to\n * while it runs (`during`); without it, both.\n */\n getTestFeedback(access?: 'atEnd' | 'during'): QtiTestFeedback[] {\n const feedback = Array.from(\n (this._testElement ?? this).querySelectorAll<QtiTestFeedback>('qti-test-feedback') ?? []\n );\n return feedback.filter(\n fb => (!access || fb.access === access) && fb.matches(this.getOutcome(fb.outcomeIdentifier)?.value)\n );\n }\n\n /* --------------------------- ENABLED WHEN UNIT TESTING OUTCOME PROCESSING ------------------------------------ */\n\n public updateOutcomeVariable(identifier: string, value: string | string[] | undefined) {\n const outcomeVariable = this.getOutcome(identifier);\n if (!outcomeVariable) {\n console.warn(`Can not set qti-outcome-identifier: ${identifier}, it is not available`);\n return;\n }\n this.testContext = {\n ...this.testContext,\n testOutcomeVariables: this.testContext.testOutcomeVariables?.map(v => {\n if (v.identifier !== identifier) {\n return v;\n }\n return {\n ...v,\n value: outcomeVariable.cardinality === 'single' ? value : [...v.value, value as string]\n };\n })\n };\n }\n\n public getOutcome(identifier: string): Readonly<OutcomeVariable> {\n return this.getVariable(identifier) as OutcomeVariable;\n }\n public getVariable(identifier: string): Readonly<VariableDeclaration<string | string[] | null>> {\n return this.testContext.testOutcomeVariables?.find(v => v.identifier === identifier) || null;\n }\n /* --------------------------- ENABLED WHEN UNIT TESTING OUTCOME PROCESSING ------------------------------------ */\n }\n\n return TestProcessingElement as Constructor<TestProcessingInterface> & T;\n};\n"]}
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@qti-components/test",
|
|
3
3
|
"description": "QTI test utilities",
|
|
4
|
-
"version": "2.0.0-next.
|
|
4
|
+
"version": "2.0.0-next.32",
|
|
5
5
|
"author": "",
|
|
6
6
|
"dependencies": {
|
|
7
7
|
"@heximal/templates": "^0.1.5",
|
|
8
8
|
"@qti-components/base": "^3.0.0-next.16",
|
|
9
|
-
"@qti-components/delivery": "^0.1.0-next.
|
|
9
|
+
"@qti-components/delivery": "^0.1.0-next.11",
|
|
10
10
|
"@qti-components/elements": "^2.0.0-next.7",
|
|
11
11
|
"@qti-components/interactions": "^1.10.5-next.8",
|
|
12
12
|
"@qti-components/processing": "^1.6.1-next.5",
|