@qti-components/test 2.0.0-next.29 → 2.0.0-next.31

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.
@@ -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 test-url="./path/to/assessment.xml"></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 test-url="./path/to/assessment.xml"></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;AAE1C,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;AAK/D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AAEH,MAAM,OAAO,OAAQ,SAAQ,mBAAmB,CAC9C,aAAa,CAAC,mBAAmB,CAAC,cAAc,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAC9E;IACC,8CAA8C;IAC9C,+FAA+F;IAE/F;QACE,KAAK,EAAE,CAAC;QAOH,kBAAa,GAAkB,EAAE,CAAC;QAEzC;;;;;;;;;WASG;QAGI,eAAU,GAAe;YAC9B,WAAW,EAAE;gBACX,cAAc,EAAE,EAAE;gBAClB,mBAAmB,EAAE,EAAE;gBACvB,qBAAqB,EAAE,SAAS;aACjC;SACF,CAAC;QA1BA,0FAA0F;QAC1F,IAAI,eAAe,CAAC,IAAI,EAAE,EAAE,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC,CAAC;IAC9E,CAAC;IA0BD;;;OAGG;IACM,KAAK,CAAC,iBAAiB;QAC9B,KAAK,CAAC,iBAAiB,EAAE,CAAC;QAC1B,MAAM,IAAI,CAAC,cAAc,CAAC;QAC1B,IAAI,CAAC,aAAa,CAAC,IAAI,WAAW,CAAC,oBAAoB,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;IAC9E,CAAC;IAEQ,MAAM;QACb,OAAO,IAAI,CAAA,eAAe,CAAC;IAC7B,CAAC;CACF;AAnCQ;IAFN,KAAK,EAAE;IACP,OAAO,CAAC,EAAE,OAAO,EAAE,aAAa,EAAE,CAAC;8CACK;AAclC;IAFN,KAAK,EAAE;IACP,OAAO,CAAC,EAAE,OAAO,EAAE,UAAU,EAAE,CAAC;2CAO/B","sourcesContent":["import { ContextProvider, provide } from '@lit/context';\nimport { html, LitElement } from 'lit';\nimport { 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 { 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>\n * <test-navigation>\n * <test-container test-url=\"./path/to/assessment.xml\"></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 constructor() {\n super();\n // The components inside find their test through this, across shadow roots (see TestHost).\n new ContextProvider(this, { context: testHostContext, initialValue: this });\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"]}
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,UAAU,CAAC,CAAC,CAAC,CAAC,CAC9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AE,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 custom element designed for hosting the qti-assessment-item.
6
- * The `qti-assessment-test` will be placed inside the shadow DOM of this element.
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-navigation>
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
- /** URL of the item to load */
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
- /** The `qti-test` this container is in: where the host's `postLoadTestTransformCallback` lives. */
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
- /** Callback function to transform the test after loading */
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 custom element designed for hosting the qti-assessment-item.
18
- * The `qti-assessment-test` will be placed inside the shadow DOM of this element.
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-navigation>
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(...arguments);
28
+ super();
32
29
  /** Scoped registry used by the test shadow root. Must be set before connection. */
33
30
  this.customElementRegistry = null;
34
- /** URL of the item to load */
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
- async handleTestURLChange() {
62
- if (!this.testURL)
63
- return;
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(this.testURL))
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,mFAAm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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,KAAK,EAAE,MA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AK,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;AA4C7C,MAAM,CAAC,MAAM,eAAe,GAAG,aAAa,CAAW,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC","sourcesContent":["import { createContext } from '@lit/context';\n\nimport type { QtiContext } from '@qti-components/base';\nimport type { transformTestApi } from '@qti-components/transformers';\nimport type { QtiAssessmentTest } from '../components/qti-assessment-test/qti-assessment-test';\n\n/**\n * Defined here, and re-exported by the navigation mixin under the same name, so this file imports\n * nothing from the mixin: the mixin imports the components that consume this context, and a type\n * import counts as a dependency for madge.\n */\nexport type PostLoadTestTransformCallback = (\n transformer: transformTestApi,\n testElement: QtiAssessmentTest\n) => transformTestApi | Promise<transformTestApi>;\n\n/**\n * What the components inside a test need from the `qti-test` that contains them: the things a host\n * put on it, and the element to query. Provided by `qti-test` about itself.\n *\n * It is context and not `closest('qti-test')` because a request crosses shadow roots and `closest`\n * stops at the first one, so a navigation or container a host renders inside its own component\n * would never find its test. Internal on purpose: not exported from the package, and not API.\n */\nexport interface TestHost extends HTMLElement {\n qtiContext: QtiContext;\n postLoadTestTransformCallback: PostLoadTestTransformCallback | null;\n /**\n * Set by `test-navigation`, which keeps the item sessions: asked by the navigation mixin before a\n * Next in a linear part leaves `itemRefId`, while that item is still rendered. It ends the item's\n * attempt when one is open (roadmap 1, T3b2b) and answers null, or answers why the item may not\n * be left yet.\n */\n beforeLinearNext?: ((itemRefId: string) => LinearNextRefusal | null) | null;\n /** Sets the candidate's comment on an item-ref; null clears it. `test-navigation` checks `rules.mayComment` first. */\n updateItemComment(itemRefId: string, comment: string | null): void;\n}\n\n/** Why Next may not leave an item yet: its responses are ones its session control refuses. */\nexport interface LinearNextRefusal {\n reason: 'allow-skipping' | 'validate-responses';\n itemId: string;\n}\n\nexport const testHostContext = createContext<TestHost>(Symbol('testHost'));\n"]}
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"]}
@@ -13,7 +13,7 @@ export const TestViewMixin = (superClass) => {
13
13
  });
14
14
  this.addEventListener('qti-assessment-item-connected', (e) => {
15
15
  this._updateElementView();
16
- this._setCorrectResponseVisibility(e.detail);
16
+ this.updateAssessmentItemView(e.detail, this.sessionContext.view);
17
17
  });
18
18
  }
19
19
  willUpdate(changedProperties) {
@@ -35,10 +35,6 @@ export const TestViewMixin = (superClass) => {
35
35
  this.updateAssessmentItemView(assessmentItem, this.sessionContext.view);
36
36
  }
37
37
  }
38
- // Event handler for connected QTI assessment items
39
- _setCorrectResponseVisibility(assessmentItem) {
40
- this.updateAssessmentItemView(assessmentItem, this.sessionContext.view);
41
- }
42
38
  /** Extension point for packages that add view-dependent assessment presentation. */
43
39
  updateAssessmentItemView(_assessmentItem, _view) { }
44
40
  }
@@ -1 +1 @@
1
- {"version":3,"file":"test-view.mixin.js","sourceRoot":"","sources":["../../src/mixins/test-view.mixin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAahD,MAAM,CAAC,MAAM,aAAa,GAAG,CAA2C,UAAa,EAAE,EAAE;IACvF,MAAe,aAAc,SAAQ,UAAU;QAC7C,YAAY,GAAG,IAAW;YACxB,KAAK,CAAC,GAAG,IAAI,CAAC,CAAC;YACf,IAAI,CAAC,cAAc,GAAG,EAAE,GAAG,IAAI,CAAC,cAAc,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC;YAEpE,YAAY,CAAC,IAAI,EAAE,qBAAqB,EAAE,CAAC,CAAC,EAAE;gBAC5C,IAAI,CAAC,cAAc,GAAG,EAAE,G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B,EAAE,cAAc,CAAC;gBAEzD,IAAI,cAAc;oBAAE,IAAI,CAAC,wBAAwB,CAAC,cAAc,EAAE,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;YAC9F,CAAC;QACH,CAAC;QAED,mDAAmD;QAC3C,6BAA6B,CAAC,cAAiC;YACrE,IAAI,CAAC,wBAAwB,CAAC,cAAc,EAAE,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;QAC1E,CAAC;QAED,oFAAoF;QAC7E,wBAAwB,CAAC,eAAkC,EAAE,KAAW,IAAS,CAAC;KAC1F;IAED,OAAO,aAAmD,CAAC;AAC7D,CAAC,CAAC","sourcesContent":["import { listenPublic } from '../public-events';\n\nimport type { View } from '@qti-components/base';\nimport type { QtiAssessmentItemRef } from '../components/qti-assessment-item-ref/qti-assessment-item-ref';\nimport type { QtiAssessmentItem } from '@qti-components/elements';\nimport type { TestBaseInterface } from './test-base';\n\ntype Constructor<T = {}> = abstract new (...args: any[]) => T;\n\ndeclare class TestViewInterface {\n updateAssessmentItemView(assessmentItem: QtiAssessmentItem, view: View): void;\n}\n\nexport const TestViewMixin = <T extends Constructor<TestBaseInterface>>(superClass: T) => {\n abstract class TestViewClass extends superClass implements TestViewInterface {\n constructor(...args: any[]) {\n super(...args);\n this.sessionContext = { ...this.sessionContext, view: 'candidate' };\n\n listenPublic(this, 'qc-test-switch-view', e => {\n this.sessionContext = { ...this.sessionContext, view: e.detail };\n this._updateElementView();\n });\n listenPublic(this, 'qc-test-loaded', () => {\n this._updateElementView();\n });\n this.addEventListener('qti-assessment-item-connected', (e: CustomEvent) => {\n this._updateElementView();\n this._setCorrectResponseVisibility(e.detail);\n });\n }\n\n willUpdate(changedProperties: Map<string | number | symbol, unknown>) {\n super.willUpdate(changedProperties);\n if (changedProperties.has('sessionContext')) {\n this._updateElementView();\n }\n }\n\n // Method to handle view updates for elements based on the current context view\n private _updateElementView() {\n if (this._testElement) {\n const viewElements = Array.from(this._testElement.querySelectorAll('[view]'));\n\n viewElements.forEach((element: HTMLElement) => {\n element.classList.toggle('show', element.getAttribute('view') === this.sessionContext.view);\n });\n\n const assessmentItemRef = this._testElement.querySelector<QtiAssessmentItemRef>(\n `qti-assessment-item-ref[identifier=\"${this.sessionContext.navItemRefId}\"]`\n );\n const assessmentItem = assessmentItemRef?.assessmentItem;\n\n if (assessmentItem) this.updateAssessmentItemView(assessmentItem, this.sessionContext.view);\n }\n }\n\n // Event handler for connected QTI assessment items\n private _setCorrectResponseVisibility(assessmentItem: QtiAssessmentItem): void {\n this.updateAssessmentItemView(assessmentItem, this.sessionContext.view);\n }\n\n /** Extension point for packages that add view-dependent assessment presentation. */\n public updateAssessmentItemView(_assessmentItem: QtiAssessmentItem, _view: View): void {}\n }\n\n return TestViewClass as Constructor<TestViewInterface> & T;\n};\n"]}
1
+ {"version":3,"file":"test-view.mixin.js","sourceRoot":"","sources":["../../src/mixins/test-view.mixin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAahD,MAAM,CAAC,MAAM,aAAa,GAAG,CAA2C,UAAa,EAAE,EAAE;IACvF,MAAe,aAAc,SAAQ,UAAU;QAC7C,YAAY,GAAG,IAAW;YACxB,KAAK,CAAC,GAAG,IAAI,CAAC,CAAC;YACf,IAAI,CAAC,cAAc,GAAG,EAAE,GAAG,IAAI,CAAC,cAAc,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC;YAEpE,YAAY,CAAC,IAAI,EAAE,qBAAqB,EAAE,CAAC,CAAC,EAAE;gBAC5C,IAAI,CAAC,cAAc,GAAG,EAAE,GAAG,IAAI,CAAC,cAAc,EAAE,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC;gBACjE,IAAI,CAAC,kBAAkB,EAAE,CAAC;YAC5B,CAAC,CAAC,CAAC;YACH,YAAY,CAAC,IAAI,EAAE,gBAAgB,EAAE,GAAG,EAAE;gBACxC,IAAI,CAAC,kBAAkB,EAAE,CAA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C,EAAE,KAAW,IAAS,CAAC;KAC1F;IAED,OAAO,aAAmD,CAAC;AAC7D,CAAC,CAAC","sourcesContent":["import { listenPublic } from '../public-events';\n\nimport type { View } from '@qti-components/base';\nimport type { QtiAssessmentItemRef } from '../components/qti-assessment-item-ref/qti-assessment-item-ref';\nimport type { QtiAssessmentItem } from '@qti-components/elements';\nimport type { TestBaseInterface } from './test-base';\n\ntype Constructor<T = {}> = abstract new (...args: any[]) => T;\n\ndeclare class TestViewInterface {\n updateAssessmentItemView(assessmentItem: QtiAssessmentItem, view: View): void;\n}\n\nexport const TestViewMixin = <T extends Constructor<TestBaseInterface>>(superClass: T) => {\n abstract class TestViewClass extends superClass implements TestViewInterface {\n constructor(...args: any[]) {\n super(...args);\n this.sessionContext = { ...this.sessionContext, view: 'candidate' };\n\n listenPublic(this, 'qc-test-switch-view', e => {\n this.sessionContext = { ...this.sessionContext, view: e.detail };\n this._updateElementView();\n });\n listenPublic(this, 'qc-test-loaded', () => {\n this._updateElementView();\n });\n this.addEventListener('qti-assessment-item-connected', (e: CustomEvent) => {\n this._updateElementView();\n this.updateAssessmentItemView(e.detail as QtiAssessmentItem, this.sessionContext.view);\n });\n }\n\n willUpdate(changedProperties: Map<string | number | symbol, unknown>) {\n super.willUpdate(changedProperties);\n if (changedProperties.has('sessionContext')) {\n this._updateElementView();\n }\n }\n\n // Method to handle view updates for elements based on the current context view\n private _updateElementView() {\n if (this._testElement) {\n const viewElements = Array.from(this._testElement.querySelectorAll('[view]'));\n\n viewElements.forEach((element: HTMLElement) => {\n element.classList.toggle('show', element.getAttribute('view') === this.sessionContext.view);\n });\n\n const assessmentItemRef = this._testElement.querySelector<QtiAssessmentItemRef>(\n `qti-assessment-item-ref[identifier=\"${this.sessionContext.navItemRefId}\"]`\n );\n const assessmentItem = assessmentItemRef?.assessmentItem;\n\n if (assessmentItem) this.updateAssessmentItemView(assessmentItem, this.sessionContext.view);\n }\n }\n\n /** Extension point for packages that add view-dependent assessment presentation. */\n public updateAssessmentItemView(_assessmentItem: QtiAssessmentItem, _view: View): void {}\n }\n\n return TestViewClass as Constructor<TestViewInterface> & T;\n};\n"]}
package/package.json CHANGED
@@ -1,16 +1,16 @@
1
1
  {
2
2
  "name": "@qti-components/test",
3
3
  "description": "QTI test utilities",
4
- "version": "2.0.0-next.29",
4
+ "version": "2.0.0-next.31",
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",
9
+ "@qti-components/delivery": "^0.1.0-next.10",
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",
13
- "@qti-components/theme": "^3.0.0-next.6",
13
+ "@qti-components/theme": "^3.0.0-next.7",
14
14
  "@qti-components/transformers": "^1.8.0-next.4",
15
15
  "@qti-components/utilities": "^1.3.3"
16
16
  },