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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/dist/components/qti-assessment-item-ref/qti-assessment-item-ref.d.ts +4 -0
  2. package/dist/components/qti-assessment-item-ref/qti-assessment-item-ref.js +16 -28
  3. package/dist/components/qti-assessment-item-ref/qti-assessment-item-ref.js.map +1 -1
  4. package/dist/components/qti-assessment-test/qti-assessment-test.d.ts +5 -0
  5. package/dist/components/qti-assessment-test/qti-assessment-test.js +2 -5
  6. package/dist/components/qti-assessment-test/qti-assessment-test.js.map +1 -1
  7. package/dist/components/qti-number-selected/qti-number-selected.js +2 -1
  8. package/dist/components/qti-number-selected/qti-number-selected.js.map +1 -1
  9. package/dist/components/qti-test/qti-test.d.ts +16 -2
  10. package/dist/components/qti-test/qti-test.js +33 -6
  11. package/dist/components/qti-test/qti-test.js.map +1 -1
  12. package/dist/components/qti-test-variables/qti-test-variables.js +2 -1
  13. package/dist/components/qti-test-variables/qti-test-variables.js.map +1 -1
  14. package/dist/components/test-check-item/test-check-item.d.ts +2 -0
  15. package/dist/components/test-check-item/test-check-item.js +16 -3
  16. package/dist/components/test-check-item/test-check-item.js.map +1 -1
  17. package/dist/components/test-container/test-container.d.ts +3 -0
  18. package/dist/components/test-container/test-container.js +5 -1
  19. package/dist/components/test-container/test-container.js.map +1 -1
  20. package/dist/components/test-end-attempt/test-end-attempt.js +2 -1
  21. package/dist/components/test-end-attempt/test-end-attempt.js.map +1 -1
  22. package/dist/components/test-item-link/test-item-link.js +2 -8
  23. package/dist/components/test-item-link/test-item-link.js.map +1 -1
  24. package/dist/components/test-item-to-speech/test-item-to-speech.d.ts +61 -15
  25. package/dist/components/test-item-to-speech/test-item-to-speech.js +287 -103
  26. package/dist/components/test-item-to-speech/test-item-to-speech.js.map +1 -1
  27. package/dist/components/test-navigation/test-navigation.d.ts +9 -9
  28. package/dist/components/test-navigation/test-navigation.js +68 -21
  29. package/dist/components/test-navigation/test-navigation.js.map +1 -1
  30. package/dist/components/test-next/test-next.js +2 -8
  31. package/dist/components/test-next/test-next.js.map +1 -1
  32. package/dist/components/test-prev/test-prev.js +2 -8
  33. package/dist/components/test-prev/test-prev.js.map +1 -1
  34. package/dist/components/test-scoring-buttons/test-scoring-buttons.d.ts +1 -1
  35. package/dist/components/test-scoring-buttons/test-scoring-buttons.js +6 -8
  36. package/dist/components/test-scoring-buttons/test-scoring-buttons.js.map +1 -1
  37. package/dist/components/test-section-link/test-section-link.js +2 -8
  38. package/dist/components/test-section-link/test-section-link.js.map +1 -1
  39. package/dist/components/test-view-toggle/test-view-toggle.js +2 -5
  40. package/dist/components/test-view-toggle/test-view-toggle.js.map +1 -1
  41. package/dist/components/test-view-toggle/test-view.js +2 -5
  42. package/dist/components/test-view-toggle/test-view.js.map +1 -1
  43. package/dist/index.d.ts +1 -0
  44. package/dist/index.js +1 -0
  45. package/dist/index.js.map +1 -1
  46. package/dist/internal/item-ref-selection.js.map +1 -1
  47. package/dist/internal/test-host.context.d.ts +24 -0
  48. package/dist/internal/test-host.context.js +3 -0
  49. package/dist/internal/test-host.context.js.map +1 -0
  50. package/dist/mixins/index.d.ts +1 -0
  51. package/dist/mixins/index.js +1 -0
  52. package/dist/mixins/index.js.map +1 -1
  53. package/dist/mixins/test-base.d.ts +7 -2
  54. package/dist/mixins/test-base.js +55 -20
  55. package/dist/mixins/test-base.js.map +1 -1
  56. package/dist/mixins/test-navigation.mixin.d.ts +3 -4
  57. package/dist/mixins/test-navigation.mixin.js +26 -40
  58. package/dist/mixins/test-navigation.mixin.js.map +1 -1
  59. package/dist/mixins/test-processing.mixin.js +3 -1
  60. package/dist/mixins/test-processing.mixin.js.map +1 -1
  61. package/dist/mixins/test-state.mixin.d.ts +33 -0
  62. package/dist/mixins/test-state.mixin.js +131 -0
  63. package/dist/mixins/test-state.mixin.js.map +1 -0
  64. package/dist/mixins/test-view.mixin.js +3 -2
  65. package/dist/mixins/test-view.mixin.js.map +1 -1
  66. package/dist/public-events.d.ts +62 -0
  67. package/dist/public-events.js +33 -0
  68. package/dist/public-events.js.map +1 -0
  69. package/dist/types/iqti-test.d.ts +8 -5
  70. package/dist/types/iqti-test.js.map +1 -1
  71. package/dist/types/qti-test-state.d.ts +45 -0
  72. package/dist/types/qti-test-state.js +2 -0
  73. package/dist/types/qti-test-state.js.map +1 -0
  74. package/package.json +5 -5
@@ -1,6 +1,7 @@
1
1
  import { LitElement } from 'lit';
2
2
  import type { ComputedContext, ComputedItem } from '@qti-components/base';
3
3
  import type { QtiAssessmentItem } from '@qti-components/elements';
4
+ import type { TestHost } from '../../internal/test-host.context';
4
5
  import type { TemplateFunction } from '@heximal/templates';
5
6
  /**
6
7
  * The model a `<template item-ref>` is rendered with.
@@ -47,6 +48,9 @@ export declare class QtiAssessmentItemRef extends LitElement {
47
48
  protected createRenderRoot(): HTMLElement | DocumentFragment;
48
49
  get assessmentItem(): QtiAssessmentItem | null;
49
50
  myTemplate: TemplateFunction | null;
51
+ /** The `qti-test` this ref belongs to, wherever it renders: light DOM, or any depth of shadow roots. */
52
+ protected testHost?: TestHost;
53
+ disconnectedCallback(): void;
50
54
  connectedCallback(): Promise<void>;
51
55
  render(): unknown;
52
56
  }
@@ -9,6 +9,8 @@ import { property, state } from 'lit/decorators.js';
9
9
  import { consume } from '@lit/context';
10
10
  import { prepareTemplate } from '@heximal/templates';
11
11
  import { computedContext } from '@qti-components/base';
12
+ import { testHostContext } from '../../internal/test-host.context';
13
+ import { dispatchPublic } from '../../public-events';
12
14
  // Converter function to interpret "true" and "false" as booleans
13
15
  const stringToBooleanConverter = {
14
16
  fromAttribute(value) {
@@ -62,28 +64,11 @@ export class QtiAssessmentItemRef extends LitElement {
62
64
  get assessmentItem() {
63
65
  return this.renderRoot?.querySelector('qti-assessment-item');
64
66
  }
65
- /**
66
- * The `<qti-test>` this ref belongs to, crossing shadow boundaries on the way
67
- * up.
68
- *
69
- * `<test-container>` renders its items into a shadow root, so an item-ref is
70
- * usually one hop below one; but it is also valid in plain light DOM, and a
71
- * host is free to nest it deeper. Climbing root by root covers all three
72
- * without assuming any of them.
73
- */
74
- #findTestElement() {
75
- const own = this.closest('qti-test');
76
- if (own)
77
- return own;
78
- let root = this.getRootNode();
79
- while (root instanceof ShadowRoot) {
80
- const test = root.host.closest('qti-test');
81
- if (test)
82
- return test;
83
- root = root.host.getRootNode();
84
- }
85
- // A Document, or a fragment that is not attached to one: nowhere left to climb.
86
- return null;
67
+ disconnectedCallback() {
68
+ super.disconnectedCallback();
69
+ // A context consumer keeps its last value when it is moved somewhere with no provider, and
70
+ // `closest()` never did: a ref moved out of a test must not keep that test's template.
71
+ this.testHost = undefined;
87
72
  }
88
73
  async connectedCallback() {
89
74
  super.connectedCallback();
@@ -107,15 +92,15 @@ export class QtiAssessmentItemRef extends LitElement {
107
92
  Resolved once, on connect: one template serves every item, and everything
108
93
  that varies per item comes through the model (see ItemRefTemplateModel).
109
94
  */
110
- const templateElement = this.#findTestElement()?.querySelector('template[item-ref]');
95
+ const templateElement = this.testHost?.querySelector('template[item-ref]');
111
96
  this.myTemplate = templateElement ? prepareTemplate(templateElement) : null;
112
97
  this.requestUpdate();
113
98
  await this.updateComplete;
114
- this.dispatchEvent(new CustomEvent('qti-assessment-item-ref-connected', {
115
- bubbles: true,
116
- composed: true,
117
- detail: { identifier: this.identifier, href: this.href, category: this.category }
118
- }));
99
+ dispatchPublic(this, 'cito-item-ref-connected', {
100
+ identifier: this.identifier,
101
+ href: this.href,
102
+ category: this.category
103
+ });
119
104
  }
120
105
  #computedItem() {
121
106
  for (const testPart of this.computedContext?.testParts ?? []) {
@@ -184,4 +169,7 @@ __decorate([
184
169
  __decorate([
185
170
  property({ type: Object, attribute: false })
186
171
  ], QtiAssessmentItemRef.prototype, "xmlDoc", void 0);
172
+ __decorate([
173
+ consume({ context: testHostContext, subscribe: true })
174
+ ], QtiAssessmentItemRef.prototype, "testHost", void 0);
187
175
  //# sourceMappingURL=qti-assessment-item-ref.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"qti-assessment-item-ref.js","sourceRoot":"","sources":["../../../src/components/qti-assessment-item-ref/qti-assessment-item-ref.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAErD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAMvD,iEAAiE;AACjE,MAAM,wBAAwB,GAAG;IAC/B,aAAa,CAAC,KAAa;QACzB,OAAO,KAAK,KAAK,MAAM,CAAC;IAC1B,CAAC;IACD,WAAW,CAAC,KAAc;QACxB,OAAO,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC;IAClC,CAAC;CACF,CAAC;AA2BF,4CAA4C;AAC5C,MAAM,OAAO,oBAAqB,SAAQ,UAAU;IAApD;;QAoCE,WAAM,GAA4B,IAAI,CAAC;QAUvC,eAAU,GAA4B,IAAI,CAAC;QAyE3C;;;;;;WAMG;QACH,cAAS,GAAkG,IAAI,CAAC;IA6BlH,CAAC;IA/IC;;;;;;;OAOG;IACH,IAAI,OAAO;QACT,MAAM,OAAO,GAAG,IAAI,GAAG,EAAkB,CAAC;QAC1C,KAAK,MAAM,MAAM,IAAI,IAAI,CAAC,gBAAgB,CAAC,qBAAqB,CAAC,EAAE,CAAC;YAClE,MAAM,UAAU,GAAG,MAAM,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC;YACrD,IAAI,CAAC,UAAU;gBAAE,SAAS;YAC1B,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC;YACnD,IAAI,MAA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M,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC;QAClC,IAAI,CAAC,IAAI,CAAC,UAAU;YAAE,OAAO,MAAM,CAAC;QAEpC,MAAM,KAAK,GAAyB;YAClC,MAAM;YACN,UAAU,EAAE,IAAI,CAAC,UAAU;YAC3B,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,IAAI,EAAE,IAAI,CAAC,aAAa,EAAE;YAC1B,OAAO,EAAE,IAAI;SACd,CAAC;QACF,OAAO,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;IAChC,CAAC;CACF;AA1J6B;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;sDAAmB;AAClB;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;wDAAqB;AACkB;IAAjE,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,wBAAwB,EAAE,CAAC;sDAAoB;AACnB;IAAjE,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,wBAAwB,EAAE,CAAC;mDAAiB;AACtD;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;kDAAe;AAKhC;IAFT,KAAK,EAAE;IACP,OAAO,CAAC,EAAE,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;6DACX;AA0B5C;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;oDACN","sourcesContent":["import { LitElement, nothing } from 'lit';\nimport { property, state } from 'lit/decorators.js';\nimport { consume } from '@lit/context';\nimport { prepareTemplate } from '@heximal/templates';\n\nimport { computedContext } from '@qti-components/base';\n\nimport type { ComputedContext, ComputedItem } from '@qti-components/base';\nimport type { QtiAssessmentItem } from '@qti-components/elements';\nimport type { TemplateFunction } from '@heximal/templates';\n\n// Converter function to interpret \"true\" and \"false\" as booleans\nconst stringToBooleanConverter = {\n fromAttribute(value: string): boolean {\n return value === 'true';\n },\n toAttribute(value: boolean): string {\n return value ? 'true' : 'false';\n }\n};\n\n/**\n * The model a `<template item-ref>` is rendered with.\n *\n * Only what this element already knows: the item's parsed document and the\n * attributes off the item-ref itself. `itemRef` is the escape hatch — a\n * template that needs anything else (a click handler, a value from the host\n * app) reaches it through a property on the element, which the host is free to\n * set.\n */\nexport interface ItemRefTemplateModel {\n /** The item's parsed document, i.e. what the element renders by default. */\n xmlDoc: DocumentFragment;\n identifier?: string;\n href?: string;\n category?: string;\n /**\n * This item's entry in the computed context, the same object the stamps\n * iterate as `item`: `index` (1-based, null for info items), `score`,\n * `maxScore`, `completed`, `active`, … Undefined until the test has computed it.\n */\n item?: ComputedItem;\n /** The element being rendered. */\n itemRef: QtiAssessmentItemRef;\n}\n\n// @customElement('qti-assessment-item-ref')\nexport class QtiAssessmentItemRef extends LitElement {\n @property({ type: String }) category?: string;\n @property({ type: String }) identifier?: string;\n @property({ type: Boolean, converter: stringToBooleanConverter }) required?: boolean;\n @property({ type: Boolean, converter: stringToBooleanConverter }) fixed?: boolean;\n @property({ type: String }) href?: string;\n\n // Only read by a <template item-ref>; subscribing re-renders it as scores come in\n @state()\n @consume({ context: computedContext, subscribe: true })\n protected computedContext?: ComputedContext;\n\n /**\n * The `<qti-weight>` children of this ref, keyed by identifier — what\n * `qti-test-variables`' `weight-identifier` resolves against.\n *\n * Read on access rather than cached: the test document is rendered into this\n * element's light DOM, so the weights are not in place at construction time,\n * and outcome processing runs long after they are.\n */\n get weights(): Map<string, number> {\n const weights = new Map<string, number>();\n for (const weight of this.querySelectorAll(':scope > qti-weight')) {\n const identifier = weight.getAttribute('identifier');\n if (!identifier) continue;\n const value = Number(weight.getAttribute('value'));\n if (Number.isNaN(value)) {\n console.warn(`qti-weight \"${identifier}\" has a non-numeric value, ignoring it`);\n continue;\n }\n weights.set(identifier, value);\n }\n return weights;\n }\n\n @property({ type: Object, attribute: false })\n xmlDoc: DocumentFragment | null = null;\n\n protected override createRenderRoot(): HTMLElement | DocumentFragment {\n return this;\n }\n\n get assessmentItem(): QtiAssessmentItem | null {\n return this.renderRoot?.querySelector('qti-assessment-item');\n }\n\n myTemplate: TemplateFunction | null = null;\n\n /**\n * The `<qti-test>` this ref belongs to, crossing shadow boundaries on the way\n * up.\n *\n * `<test-container>` renders its items into a shadow root, so an item-ref is\n * usually one hop below one; but it is also valid in plain light DOM, and a\n * host is free to nest it deeper. Climbing root by root covers all three\n * without assuming any of them.\n */\n #findTestElement(): Element | null {\n const own = this.closest('qti-test');\n if (own) return own;\n\n let root: Node = this.getRootNode();\n while (root instanceof ShadowRoot) {\n const test = root.host.closest('qti-test');\n if (test) return test;\n root = root.host.getRootNode();\n }\n // A Document, or a fragment that is not attached to one: nowhere left to climb.\n return null;\n }\n\n override async connectedCallback(): Promise<void> {\n super.connectedCallback();\n\n /*\n Optional per-item template, used to render extra things around an item —\n a bookmark, an index number, a score badge. Put it in the light DOM of\n your qti-test, and every item-ref in the test renders with it:\n\n <qti-test>\n <template item-ref>\n <div class=\"badge\">{{ identifier }}</div>\n {{ xmlDoc }}\n </template>\n …\n </qti-test>\n\n The template is the WHOLE render, so it has to place {{ xmlDoc }} itself;\n leaving it out renders the chrome and no item. Without a template the\n element renders the item on its own, exactly as before.\n\n Resolved once, on connect: one template serves every item, and everything\n that varies per item comes through the model (see ItemRefTemplateModel).\n */\n const templateElement = this.#findTestElement()?.querySelector<HTMLTemplateElement>('template[item-ref]');\n this.myTemplate = templateElement ? prepareTemplate(templateElement) : null;\n this.requestUpdate();\n\n await this.updateComplete;\n\n this.dispatchEvent(\n new CustomEvent('qti-assessment-item-ref-connected', {\n bubbles: true,\n composed: true,\n detail: { identifier: this.identifier, href: this.href, category: this.category }\n })\n );\n }\n\n #computedItem(): ComputedItem | undefined {\n for (const testPart of this.computedContext?.testParts ?? []) {\n for (const section of testPart.sections) {\n const item = section.items.find(i => i.identifier === this.identifier);\n if (item) return item;\n }\n }\n return undefined;\n }\n\n /**\n * The clone of `xmlDoc` that is rendered, and what it was cloned for. Cloned\n * once per document and template, not per render: re-renders from\n * computed-context changes then hand Lit the same fragment, which it leaves\n * alone, instead of rebuilding the item (and reloading its PCIs, which\n * changes the context again).\n */\n #rendered: { source: DocumentFragment; template: TemplateFunction | null; doc: DocumentFragment } | null = null;\n\n override render() {\n // Item refs connect before loading, and navigation clears their documents.\n if (!this.xmlDoc) {\n this.#rendered = null;\n return nothing;\n }\n\n if (this.#rendered?.source !== this.xmlDoc || this.#rendered.template !== this.myTemplate) {\n this.#rendered = {\n source: this.xmlDoc,\n template: this.myTemplate,\n doc: this.xmlDoc.cloneNode(true) as DocumentFragment\n };\n }\n const xmlDoc = this.#rendered.doc;\n if (!this.myTemplate) return xmlDoc;\n\n const model: ItemRefTemplateModel = {\n xmlDoc,\n identifier: this.identifier,\n href: this.href,\n category: this.category,\n item: this.#computedItem(),\n itemRef: this\n };\n return this.myTemplate(model);\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'qti-assessment-item-ref': QtiAssessmentItemRef;\n }\n}\n"]}
1
+ {"version":3,"file":"qti-assessment-item-ref.js","sourceRoot":"","sources":["../../../src/components/qti-assessment-item-ref/qti-assessment-item-ref.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAErD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AACnE,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAOrD,i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AAE,SAAS,EAAE,IAAI,EAAE,CAAC;6DACX;AA0B5C;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;oDACN;AAc7B;IADT,OAAO,CAAC,EAAE,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;sDACzB","sourcesContent":["import { LitElement, nothing } from 'lit';\nimport { property, state } from 'lit/decorators.js';\nimport { consume } from '@lit/context';\nimport { prepareTemplate } from '@heximal/templates';\n\nimport { computedContext } from '@qti-components/base';\n\nimport { testHostContext } from '../../internal/test-host.context';\nimport { dispatchPublic } from '../../public-events';\n\nimport type { ComputedContext, ComputedItem } from '@qti-components/base';\nimport type { QtiAssessmentItem } from '@qti-components/elements';\nimport type { TestHost } from '../../internal/test-host.context';\nimport type { TemplateFunction } from '@heximal/templates';\n\n// Converter function to interpret \"true\" and \"false\" as booleans\nconst stringToBooleanConverter = {\n fromAttribute(value: string): boolean {\n return value === 'true';\n },\n toAttribute(value: boolean): string {\n return value ? 'true' : 'false';\n }\n};\n\n/**\n * The model a `<template item-ref>` is rendered with.\n *\n * Only what this element already knows: the item's parsed document and the\n * attributes off the item-ref itself. `itemRef` is the escape hatch — a\n * template that needs anything else (a click handler, a value from the host\n * app) reaches it through a property on the element, which the host is free to\n * set.\n */\nexport interface ItemRefTemplateModel {\n /** The item's parsed document, i.e. what the element renders by default. */\n xmlDoc: DocumentFragment;\n identifier?: string;\n href?: string;\n category?: string;\n /**\n * This item's entry in the computed context, the same object the stamps\n * iterate as `item`: `index` (1-based, null for info items), `score`,\n * `maxScore`, `completed`, `active`, … Undefined until the test has computed it.\n */\n item?: ComputedItem;\n /** The element being rendered. */\n itemRef: QtiAssessmentItemRef;\n}\n\n// @customElement('qti-assessment-item-ref')\nexport class QtiAssessmentItemRef extends LitElement {\n @property({ type: String }) category?: string;\n @property({ type: String }) identifier?: string;\n @property({ type: Boolean, converter: stringToBooleanConverter }) required?: boolean;\n @property({ type: Boolean, converter: stringToBooleanConverter }) fixed?: boolean;\n @property({ type: String }) href?: string;\n\n // Only read by a <template item-ref>; subscribing re-renders it as scores come in\n @state()\n @consume({ context: computedContext, subscribe: true })\n protected computedContext?: ComputedContext;\n\n /**\n * The `<qti-weight>` children of this ref, keyed by identifier — what\n * `qti-test-variables`' `weight-identifier` resolves against.\n *\n * Read on access rather than cached: the test document is rendered into this\n * element's light DOM, so the weights are not in place at construction time,\n * and outcome processing runs long after they are.\n */\n get weights(): Map<string, number> {\n const weights = new Map<string, number>();\n for (const weight of this.querySelectorAll(':scope > qti-weight')) {\n const identifier = weight.getAttribute('identifier');\n if (!identifier) continue;\n const value = Number(weight.getAttribute('value'));\n if (Number.isNaN(value)) {\n console.warn(`qti-weight \"${identifier}\" has a non-numeric value, ignoring it`);\n continue;\n }\n weights.set(identifier, value);\n }\n return weights;\n }\n\n @property({ type: Object, attribute: false })\n xmlDoc: DocumentFragment | null = null;\n\n protected override createRenderRoot(): HTMLElement | DocumentFragment {\n return this;\n }\n\n get assessmentItem(): QtiAssessmentItem | null {\n return this.renderRoot?.querySelector('qti-assessment-item');\n }\n\n myTemplate: TemplateFunction | null = null;\n\n /** The `qti-test` this ref belongs to, wherever it renders: light DOM, or any depth of shadow roots. */\n @consume({ context: testHostContext, subscribe: true })\n protected testHost?: TestHost;\n\n override disconnectedCallback(): void {\n super.disconnectedCallback();\n // A context consumer keeps its last value when it is moved somewhere with no provider, and\n // `closest()` never did: a ref moved out of a test must not keep that test's template.\n this.testHost = undefined;\n }\n\n override async connectedCallback(): Promise<void> {\n super.connectedCallback();\n\n /*\n Optional per-item template, used to render extra things around an item —\n a bookmark, an index number, a score badge. Put it in the light DOM of\n your qti-test, and every item-ref in the test renders with it:\n\n <qti-test>\n <template item-ref>\n <div class=\"badge\">{{ identifier }}</div>\n {{ xmlDoc }}\n </template>\n …\n </qti-test>\n\n The template is the WHOLE render, so it has to place {{ xmlDoc }} itself;\n leaving it out renders the chrome and no item. Without a template the\n element renders the item on its own, exactly as before.\n\n Resolved once, on connect: one template serves every item, and everything\n that varies per item comes through the model (see ItemRefTemplateModel).\n */\n const templateElement = this.testHost?.querySelector<HTMLTemplateElement>('template[item-ref]');\n this.myTemplate = templateElement ? prepareTemplate(templateElement) : null;\n this.requestUpdate();\n\n await this.updateComplete;\n\n dispatchPublic(this, 'cito-item-ref-connected', {\n identifier: this.identifier,\n href: this.href,\n category: this.category\n });\n }\n\n #computedItem(): ComputedItem | undefined {\n for (const testPart of this.computedContext?.testParts ?? []) {\n for (const section of testPart.sections) {\n const item = section.items.find(i => i.identifier === this.identifier);\n if (item) return item;\n }\n }\n return undefined;\n }\n\n /**\n * The clone of `xmlDoc` that is rendered, and what it was cloned for. Cloned\n * once per document and template, not per render: re-renders from\n * computed-context changes then hand Lit the same fragment, which it leaves\n * alone, instead of rebuilding the item (and reloading its PCIs, which\n * changes the context again).\n */\n #rendered: { source: DocumentFragment; template: TemplateFunction | null; doc: DocumentFragment } | null = null;\n\n override render() {\n // Item refs connect before loading, and navigation clears their documents.\n if (!this.xmlDoc) {\n this.#rendered = null;\n return nothing;\n }\n\n if (this.#rendered?.source !== this.xmlDoc || this.#rendered.template !== this.myTemplate) {\n this.#rendered = {\n source: this.xmlDoc,\n template: this.myTemplate,\n doc: this.xmlDoc.cloneNode(true) as DocumentFragment\n };\n }\n const xmlDoc = this.#rendered.doc;\n if (!this.myTemplate) return xmlDoc;\n\n const model: ItemRefTemplateModel = {\n xmlDoc,\n identifier: this.identifier,\n href: this.href,\n category: this.category,\n item: this.#computedItem(),\n itemRef: this\n };\n return this.myTemplate(model);\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'qti-assessment-item-ref': QtiAssessmentItemRef;\n }\n}\n"]}
@@ -14,3 +14,8 @@ declare global {
14
14
  'qti-assessment-test': QtiAssessmentTest;
15
15
  }
16
16
  }
17
+ declare module '../../public-events' {
18
+ interface PublicEventMap {
19
+ 'cito-test-loaded': CustomEvent<QtiAssessmentTest>;
20
+ }
21
+ }
@@ -8,6 +8,7 @@ import { consume } from '@lit/context';
8
8
  import { html, LitElement } from 'lit';
9
9
  import { property } from 'lit/decorators.js';
10
10
  import { testContext } from '@qti-components/base';
11
+ import { dispatchPublic } from '../../public-events';
11
12
  export class QtiAssessmentTest extends LitElement {
12
13
  get title() {
13
14
  return this.#title;
@@ -21,11 +22,7 @@ export class QtiAssessmentTest extends LitElement {
21
22
  async connectedCallback() {
22
23
  super.connectedCallback();
23
24
  await this.updateComplete;
24
- this.dispatchEvent(new CustomEvent('qti-assessment-test-connected', {
25
- detail: this,
26
- bubbles: true,
27
- composed: true
28
- }));
25
+ dispatchPublic(this, 'cito-test-loaded', this);
29
26
  }
30
27
  render() {
31
28
  return html ` <slot></slot>`;
@@ -1 +1 @@
1
- {"version":3,"file":"qti-assessment-test.js","sourceRoot":"","sources":["../../../src/components/qti-assessment-test/qti-assessment-test.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAInD,MAAM,OAAO,iBAAkB,SAAQ,UAAU;IAG/C,IAAa,KAAK;QAChB,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IACD,IAAa,KAAK,CAAC,KAAa;QAC9B,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACpB,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC;QAC9B,IAAI,CAAC,YAAY,CAAC,YAAY,EAAE,KAAK,CAAC,CAAC;IACzC,CAAC;IAID,MAAM,GAAG,EAAE,CAAC;IAEH,KAAK,CAAC,iBAAiB;QAC9B,KAAK,CAAC,iBAAiB,EAAE,CAAC;QAC1B,MAAM,IAAI,CAAC,cAAc,CAAC;QAC1B,IAAI,CAAC,aAAa,CAChB,IAAI,WAAW,CAAC,+BAA+B,EAAE;YAC/C,MAAM,EAAE,IAAI;YACZ,OAAO,EAAE,IAAI;YACb,QAAQ,EAAE,IAAI;SACf,CAAC,CACH,CAAC;IACJ,CAAC;IAEQ,MAAM;QACb,OAAO,IAAI,CAAA,gBAAgB,CAAC;IAC9B,CAAC;CACF;AA9B6B;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;qDAAoB;AAE/C;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;8CAG1B;AAQM;IADN,OAAO,CAAC,EAAE,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;uDACjB","sourcesContent":["import { consume } from '@lit/context';\nimport { html, LitElement } from 'lit';\nimport { property } from 'lit/decorators.js';\n\nimport { testContext } from '@qti-components/base';\n\nimport type { TestContext } from '@qti-components/base';\n\nexport class QtiAssessmentTest extends LitElement {\n @property({ type: String }) identifier: string;\n @property({ type: String })\n override get title(): string {\n return this.#title;\n }\n override set title(value: string) {\n this.#title = value;\n this.removeAttribute('title');\n this.setAttribute('data-title', value);\n }\n\n @consume({ context: testContext, subscribe: true })\n public _testContext?: TestContext;\n #title = '';\n\n override async connectedCallback(): Promise<void> {\n super.connectedCallback();\n await this.updateComplete;\n this.dispatchEvent(\n new CustomEvent('qti-assessment-test-connected', {\n detail: this,\n bubbles: true,\n composed: true\n })\n );\n }\n\n override render() {\n return html` <slot></slot>`;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'qti-assessment-test': QtiAssessmentTest;\n }\n}\n"]}
1
+ {"version":3,"file":"qti-assessment-test.js","sourceRoot":"","sources":["../../../src/components/qti-assessment-test/qti-assessment-test.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEnD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAIrD,MAAM,OAAO,iBAAkB,SAAQ,UAAU;IAG/C,IAAa,KAAK;QAChB,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IACD,IAAa,KAAK,CAAC,KAAa;QAC9B,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QACpB,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC;QAC9B,IAAI,CAAC,YAAY,CAAC,YAAY,EAAE,KAAK,CAAC,CAAC;IACzC,CAAC;IAID,MAAM,GAAG,EAAE,CAAC;IAEH,KAAK,CAAC,iBAAiB;QAC9B,KAAK,CAAC,iBAAiB,EAAE,CAAC;QAC1B,MAAM,IAAI,CAAC,cAAc,CAAC;QAC1B,cAAc,CAAC,IAAI,EAAE,kBAAkB,EAAE,IAAI,CAAC,CAAC;IACjD,CAAC;IAEQ,MAAM;QACb,OAAO,IAAI,CAAA,gBAAgB,CAAC;IAC9B,CAAC;CACF;AAxB6B;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;qDAAoB;AAE/C;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;8CAG1B;AAQM;IADN,OAAO,CAAC,EAAE,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;uDACjB","sourcesContent":["import { consume } from '@lit/context';\nimport { html, LitElement } from 'lit';\nimport { property } from 'lit/decorators.js';\n\nimport { testContext } from '@qti-components/base';\n\nimport { dispatchPublic } from '../../public-events';\n\nimport type { TestContext } from '@qti-components/base';\n\nexport class QtiAssessmentTest extends LitElement {\n @property({ type: String }) identifier: string;\n @property({ type: String })\n override get title(): string {\n return this.#title;\n }\n override set title(value: string) {\n this.#title = value;\n this.removeAttribute('title');\n this.setAttribute('data-title', value);\n }\n\n @consume({ context: testContext, subscribe: true })\n public _testContext?: TestContext;\n #title = '';\n\n override async connectedCallback(): Promise<void> {\n super.connectedCallback();\n await this.updateComplete;\n dispatchPublic(this, 'cito-test-loaded', this);\n }\n\n override render() {\n return html` <slot></slot>`;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'qti-assessment-test': QtiAssessmentTest;\n }\n}\n\ndeclare module '../../public-events' {\n interface PublicEventMap {\n 'cito-test-loaded': CustomEvent<QtiAssessmentTest>;\n }\n}\n"]}
@@ -1,5 +1,6 @@
1
1
  import { QtiExpression } from '@qti-components/base';
2
2
  import { selectItemRefs, selectionFrom } from '../../internal/item-ref-selection';
3
+ import { listenPublic } from '../../public-events';
3
4
  /**
4
5
  * @summary The qti-number-selected expression counts the item refs selected for the test.
5
6
  * @documentation https://www.imsglobal.org/spec/qti/v3p0/impl#h.number-selected
@@ -16,7 +17,7 @@ export class QtiNumberSelected extends QtiExpression {
16
17
  #connectedTest = null;
17
18
  constructor() {
18
19
  super();
19
- this.addEventListener('qti-assessment-test-connected', (e) => (this.#connectedTest = e.detail));
20
+ listenPublic(this, 'cito-test-loaded', (e) => (this.#connectedTest = e.detail));
20
21
  }
21
22
  /**
22
23
  * `qti-assessment-test-connected` bubbles *up* from the test element, and this
@@ -1 +1 @@
1
- {"version":3,"file":"qti-number-selected.js","sourceRoot":"","sources":["../../../src/components/qti-number-selected/qti-number-selected.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAErD,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;AAIlF;;;;;;;;;;;GAWG;AACH,MAAM,OAAO,iBAAkB,SAAQ,aAAqB;IAC1D,cAAc,GAA6B,IAAI,CAAC;IAEhD;QACE,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,gBAAgB,CACnB,+BAA+B,EAC/B,CAAC,CAAiC,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,cAAc,GAAG,CAAC,CAAC,MAAM,CAAC,CACxE,CAAC;IACJ,CAAC;IAED;;;;;OAKG;IACH,IAAI,YAAY;QACd,OAAO,IAAI,CAAC,cAAc,IAAI,IAAI,CAAC,OAAO,CAAoB,qBAAqB,CAAC,CAAC;IACvF,CAAC;IAEe,SAAS;QACvB,MAAM,WAAW,GAAG,IAAI,CAAC,YAAY,CAAC;QACtC,IAAI,CAAC,WAAW,EAAE,CAAC;YACjB,OAAO,CAAC,IAAI,CAAC,yEAAyE,CAAC,CAAC;YACxF,OAAO,CAAC,CAAC;QACX,CAAC;QAED,OAAO,cAAc,CAAC,WAAW,EAAE,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC;IACjE,CAAC;IAEe,SAAS;QACvB,OAAO,IAAI,CAAC,SAAS,EAAE,CAAC;IAC1B,CAAC;CACF","sourcesContent":["import { QtiExpression } from '@qti-components/base';\n\nimport { selectItemRefs, selectionFrom } from '../../internal/item-ref-selection';\n\nimport type { QtiAssessmentTest } from '../qti-assessment-test/qti-assessment-test';\n\n/**\n * @summary The qti-number-selected expression counts the item refs selected for the test.\n * @documentation https://www.imsglobal.org/spec/qti/v3p0/impl#h.number-selected\n *\n * Outcome processing only. `section-identifier`, `include-category` and\n * `exclude-category` narrow which item references are counted; with none of\n * them it is every item reference in the test.\n *\n * The count comes from the item refs in the document rather than the test\n * context, so it is the same set `qti-test-variables` aggregates over — and it\n * is right before any item has been attempted.\n */\nexport class QtiNumberSelected extends QtiExpression<number> {\n #connectedTest: QtiAssessmentTest | null = null;\n\n constructor() {\n super();\n this.addEventListener(\n 'qti-assessment-test-connected',\n (e: CustomEvent<QtiAssessmentTest>) => (this.#connectedTest = e.detail)\n );\n }\n\n /**\n * `qti-assessment-test-connected` bubbles *up* from the test element, and this\n * expression lives inside that test's `qti-outcome-processing` — so the\n * listener above only ever fires for a test handed to us directly (a test\n * harness). Walking up the tree is what resolves the test in a real document.\n */\n get #testElement(): QtiAssessmentTest | null {\n return this.#connectedTest ?? this.closest<QtiAssessmentTest>('qti-assessment-test');\n }\n\n public override getResult(): number {\n const testElement = this.#testElement;\n if (!testElement) {\n console.warn('qti-number-selected: no enclosing qti-assessment-test, nothing to count');\n return 0;\n }\n\n return selectItemRefs(testElement, selectionFrom(this)).length;\n }\n\n public override calculate(): number {\n return this.getResult();\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'qti-number-selected': QtiNumberSelected;\n }\n}\n"]}
1
+ {"version":3,"file":"qti-number-selected.js","sourceRoot":"","sources":["../../../src/components/qti-number-selected/qti-number-selected.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAErD,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;AAClF,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAInD;;;;;;;;;;;GAWG;AACH,MAAM,OAAO,iBAAkB,SAAQ,aAAqB;IAC1D,cAAc,GAA6B,IAAI,CAAC;IAEhD;QACE,KAAK,EAAE,CAAC;QACR,YAAY,CAAC,IAAI,EAAE,kBAAkB,EAAE,CAAC,CAAiC,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,cAAc,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;IAClH,CAAC;IAED;;;;;OAKG;IACH,IAAI,YAAY;QACd,OAAO,IAAI,CAAC,cAAc,IAAI,IAAI,CAAC,OAAO,CAAoB,qBAAqB,CAAC,CAAC;IACvF,CAAC;IAEe,SAAS;QACvB,MAAM,WAAW,GAAG,IAAI,CAAC,YAAY,CAAC;QACtC,IAAI,CAAC,WAAW,EAAE,CAAC;YACjB,OAAO,CAAC,IAAI,CAAC,yEAAyE,CAAC,CAAC;YACxF,OAAO,CAAC,CAAC;QACX,CAAC;QAED,OAAO,cAAc,CAAC,WAAW,EAAE,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC;IACjE,CAAC;IAEe,SAAS;QACvB,OAAO,IAAI,CAAC,SAAS,EAAE,CAAC;IAC1B,CAAC;CACF","sourcesContent":["import { QtiExpression } from '@qti-components/base';\n\nimport { selectItemRefs, selectionFrom } from '../../internal/item-ref-selection';\nimport { listenPublic } from '../../public-events';\n\nimport type { QtiAssessmentTest } from '../qti-assessment-test/qti-assessment-test';\n\n/**\n * @summary The qti-number-selected expression counts the item refs selected for the test.\n * @documentation https://www.imsglobal.org/spec/qti/v3p0/impl#h.number-selected\n *\n * Outcome processing only. `section-identifier`, `include-category` and\n * `exclude-category` narrow which item references are counted; with none of\n * them it is every item reference in the test.\n *\n * The count comes from the item refs in the document rather than the test\n * context, so it is the same set `qti-test-variables` aggregates over — and it\n * is right before any item has been attempted.\n */\nexport class QtiNumberSelected extends QtiExpression<number> {\n #connectedTest: QtiAssessmentTest | null = null;\n\n constructor() {\n super();\n listenPublic(this, 'cito-test-loaded', (e: CustomEvent<QtiAssessmentTest>) => (this.#connectedTest = e.detail));\n }\n\n /**\n * `qti-assessment-test-connected` bubbles *up* from the test element, and this\n * expression lives inside that test's `qti-outcome-processing` — so the\n * listener above only ever fires for a test handed to us directly (a test\n * harness). Walking up the tree is what resolves the test in a real document.\n */\n get #testElement(): QtiAssessmentTest | null {\n return this.#connectedTest ?? this.closest<QtiAssessmentTest>('qti-assessment-test');\n }\n\n public override getResult(): number {\n const testElement = this.#testElement;\n if (!testElement) {\n console.warn('qti-number-selected: no enclosing qti-assessment-test, nothing to count');\n return 0;\n }\n\n return selectItemRefs(testElement, selectionFrom(this)).length;\n }\n\n public override calculate(): number {\n return this.getResult();\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'qti-number-selected': QtiNumberSelected;\n }\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  import { LitElement } from 'lit';
2
- import type { ConfigContext } from '@qti-components/base';
2
+ import type { ConfigContext, QtiContext } from '@qti-components/base';
3
3
  declare const QtiTest_base: (abstract new (...args: any[]) => import("../..").ITestNavigationMixin) & (abstract new (...args: any[]) => {
4
4
  updateAssessmentItemView(assessmentItem: import("@qti-components/elements").QtiAssessmentItem, view: import("@qti-components/base").View): void;
5
5
  }) & (abstract new (...args: any[]) => {
@@ -7,7 +7,7 @@ declare const QtiTest_base: (abstract new (...args: any[]) => import("../..").IT
7
7
  getOutcome(identifier: string): Readonly<import("@qti-components/base").OutcomeVariable>;
8
8
  getVariable(identifier: string): Readonly<import("@qti-components/base").VariableDeclaration<string | string[] | null>>;
9
9
  outcomeProcessing(): boolean;
10
- }) & (abstract new (...args: any[]) => import("../../mixins").TestBaseInterface) & typeof LitElement;
10
+ }) & (abstract new (...args: any[]) => import("../..").ITestStateMixin) & (abstract new (...args: any[]) => import("../../mixins").TestBaseInterface) & typeof LitElement;
11
11
  /**
12
12
  * `<qti-test>` is a custom element designed for rendering and interacting with QTI (Question and Test Interoperability) tests.
13
13
  *
@@ -55,9 +55,23 @@ declare const QtiTest_base: (abstract new (...args: any[]) => import("../..").IT
55
55
  * You can use normal class names to style the elements.
56
56
  * And you can use the `test-prev` and `test-next` elements to navigate through the test.
57
57
  *
58
+ * @event qti-state-changed - The candidate's persistable state changed. `detail` is a `QtiTestState`; assign it back to `state` to resume.
59
+ * @event qti-test-context-updated - Deprecated: listen to `qti-state-changed` to persist a session. `detail` is the full test context, including declaration metadata and the answer key. Removed in the next major.
58
60
  */
59
61
  export declare class QtiTest extends QtiTest_base {
62
+ constructor();
60
63
  configContext: ConfigContext;
64
+ /**
65
+ * Who is taking which test, and the optional shuffle `seed`. Provided here, at the test, so
66
+ * everything inside reads one value: the test-container shuffling the item order, the test
67
+ * shuffling interactions as it navigates, and the expressions that read `QTI_CONTEXT`.
68
+ *
69
+ * Pass the same `seed` when resuming a session, or the order comes back different. Replace the
70
+ * object, do not mutate it: an in-place change does not notify the components inside.
71
+ *
72
+ * `test-navigation.qtiContext` is an alias of this.
73
+ */
74
+ qtiContext: QtiContext;
61
75
  /**
62
76
  * Renders the component's template.
63
77
  * Provides a default `<slot>` for content projection.
@@ -4,13 +4,15 @@ 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 { provide } from '@lit/context';
7
+ import { ContextProvider, provide } from '@lit/context';
8
8
  import { html, LitElement } from 'lit';
9
9
  import { state } from 'lit/decorators.js';
10
- import { configContext } from '@qti-components/base';
10
+ import { configContext, qtiContext } from '@qti-components/base';
11
+ import { testHostContext } from '../../internal/test-host.context';
11
12
  import { TestNavigationMixin, TestViewMixin } from '../../mixins';
12
13
  import { TestBaseMixin } from '../../mixins/test-base';
13
14
  import { TestProcessingMixin } from '../../mixins/test-processing.mixin';
15
+ import { TestStateMixin } from '../../mixins/test-state.mixin';
14
16
  /**
15
17
  * `<qti-test>` is a custom element designed for rendering and interacting with QTI (Question and Test Interoperability) tests.
16
18
  *
@@ -58,13 +60,34 @@ import { TestProcessingMixin } from '../../mixins/test-processing.mixin';
58
60
  * You can use normal class names to style the elements.
59
61
  * And you can use the `test-prev` and `test-next` elements to navigate through the test.
60
62
  *
63
+ * @event qti-state-changed - The candidate's persistable state changed. `detail` is a `QtiTestState`; assign it back to `state` to resume.
64
+ * @event qti-test-context-updated - Deprecated: listen to `qti-state-changed` to persist a session. `detail` is the full test context, including declaration metadata and the answer key. Removed in the next major.
61
65
  */
62
- export class QtiTest extends TestNavigationMixin(TestViewMixin(TestProcessingMixin(TestBaseMixin(LitElement)))) {
66
+ export class QtiTest extends TestNavigationMixin(TestViewMixin(TestProcessingMixin(TestStateMixin(TestBaseMixin(LitElement))))) {
67
+ // TODO: Properly implement IQtiTest interface
68
+ // export class QtiTest extends TestLoaderMixin(TestNavigationMixin(TestViewMixin(TestBase))) {
63
69
  constructor() {
64
- // TODO: Properly implement IQtiTest interface
65
- // export class QtiTest extends TestLoaderMixin(TestNavigationMixin(TestViewMixin(TestBase))) {
66
- super(...arguments);
70
+ super();
67
71
  this.configContext = {};
72
+ /**
73
+ * Who is taking which test, and the optional shuffle `seed`. Provided here, at the test, so
74
+ * everything inside reads one value: the test-container shuffling the item order, the test
75
+ * shuffling interactions as it navigates, and the expressions that read `QTI_CONTEXT`.
76
+ *
77
+ * Pass the same `seed` when resuming a session, or the order comes back different. Replace the
78
+ * object, do not mutate it: an in-place change does not notify the components inside.
79
+ *
80
+ * `test-navigation.qtiContext` is an alias of this.
81
+ */
82
+ this.qtiContext = {
83
+ QTI_CONTEXT: {
84
+ testIdentifier: '',
85
+ candidateIdentifier: '',
86
+ environmentIdentifier: 'default'
87
+ }
88
+ };
89
+ // The components inside find their test through this, across shadow roots (see TestHost).
90
+ new ContextProvider(this, { context: testHostContext, initialValue: this });
68
91
  }
69
92
  /**
70
93
  * Renders the component's template.
@@ -83,4 +106,8 @@ __decorate([
83
106
  state(),
84
107
  provide({ context: configContext })
85
108
  ], QtiTest.prototype, "configContext", void 0);
109
+ __decorate([
110
+ state(),
111
+ provide({ context: qtiContext })
112
+ ], QtiTest.prototype, "qtiContext", void 0);
86
113
  //# sourceMappingURL=qti-test.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"qti-test.js","sourceRoot":"","sources":["../../../src/components/qti-test/qti-test.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AACvC,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAE1C,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAErD,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;AAKzE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AAEH,MAAM,OAAO,OAAQ,SAAQ,mBAAmB,CAAC,aAAa,CAAC,mBAAmB,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;IAA/G;QACE,8CAA8C;QAC9C,+FAA+F;;QAIxF,kBAAa,GAAkB,EAAE,CAAC;IAe3C,CAAC;IAbC;;;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;AAfQ;IAFN,KAAK,EAAE;IACP,OAAO,CAAC,EAAE,OAAO,EAAE,aAAa,EAAE,CAAC;8CACK","sourcesContent":["import { provide } from '@lit/context';\nimport { html, LitElement } from 'lit';\nimport { state } from 'lit/decorators.js';\n\nimport { configContext } from '@qti-components/base';\n\nimport { TestNavigationMixin, TestViewMixin } from '../../mixins';\nimport { TestBaseMixin } from '../../mixins/test-base';\nimport { TestProcessingMixin } from '../../mixins/test-processing.mixin';\n\nimport type { ConfigContext } 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 */\n\nexport class QtiTest extends TestNavigationMixin(TestViewMixin(TestProcessingMixin(TestBaseMixin(LitElement)))) {\n // TODO: Properly implement IQtiTest interface\n // export class QtiTest extends TestLoaderMixin(TestNavigationMixin(TestViewMixin(TestBase))) {\n\n @state()\n @provide({ context: configContext })\n public configContext: ConfigContext = {};\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,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,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CAO/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 qti-state-changed - The candidate's persistable state changed. `detail` is a `QtiTestState`; assign it back to `state` to resume.\n * @event qti-test-context-updated - Deprecated: listen to `qti-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"]}
@@ -8,11 +8,12 @@ import { consume } from '@lit/context';
8
8
  import { testContext } from '@qti-components/base';
9
9
  import { QtiExpression } from '@qti-components/base';
10
10
  import { selectItemRefs, selectionFrom } from '../../internal/item-ref-selection';
11
+ import { listenPublic } from '../../public-events';
11
12
  export class QtiTestVariables extends QtiExpression {
12
13
  #connectedTest = null;
13
14
  constructor() {
14
15
  super();
15
- this.addEventListener('qti-assessment-test-connected', (e) => (this.#connectedTest = e.detail));
16
+ listenPublic(this, 'cito-test-loaded', (e) => (this.#connectedTest = e.detail));
16
17
  }
17
18
  /**
18
19
  * `qti-assessment-test-connected` bubbles *up* from the test element, and this
@@ -1 +1 @@
1
- {"version":3,"file":"qti-test-variables.js","s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,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC,UAAU,CAAC,EAAE,MAAM,IAAI,CAAC,CAAC;gBACrF,IAAI,QAAQ,EAAE,CAAC;oBACb,mEAAmE;oBACnE,sEAAsE;oBACtE,MAAM,KAAK,GAAG,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;oBACrC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;wBACzB,KAAK,IAAI,KAAK,GAAG,MAAM,CAAC;oBAC1B,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC,CAAC,CAAC;QACH,OAAO,KAAK,CAAC;IACf,CAAC;CACF","sourcesContent":["import { consume } from '@lit/context';\n\nimport { testContext } from '@qti-components/base';\nimport { QtiExpression } from '@qti-components/base';\n\nimport { selectItemRefs, selectionFrom } from '../../internal/item-ref-selection';\n\nimport type { QtiAssessmentTest } from '../qti-assessment-test/qti-assessment-test';\nimport type { TestContext } from '@qti-components/base';\nimport type { QtiExpressionBase } from '@qti-components/base';\n\nexport class QtiTestVariables extends QtiExpression<number> {\n @consume({ context: testContext, subscribe: true })\n public _testContext?: TestContext;\n\n #connectedTest: QtiAssessmentTest | null = null;\n\n constructor() {\n super();\n this.addEventListener(\n 'qti-assessment-test-connected',\n (e: CustomEvent<QtiAssessmentTest>) => (this.#connectedTest = e.detail)\n );\n }\n\n /**\n * `qti-assessment-test-connected` bubbles *up* from the test element, and this\n * expression lives inside that test's `qti-outcome-processing` — so the\n * listener above only ever fires for a test handed to us directly (a test\n * harness). Walking up the tree is what resolves the test in a real document.\n */\n get #testElement(): QtiAssessmentTest | null {\n return this.#connectedTest ?? this.closest<QtiAssessmentTest>('qti-assessment-test');\n }\n\n public override getResult() {\n const testElement = this.#testElement;\n if (!testElement) {\n console.warn('qti-test-variables: no enclosing qti-assessment-test, nothing to aggregate');\n return 0;\n }\n\n const weightIdentifier = this.getAttribute('weight-identifier') ?? '';\n const itemVariable = this.getAttribute('variable-identifier');\n\n const includedItems = selectItemRefs(testElement, selectionFrom(this)).map(itemRef => ({\n item: itemRef.identifier,\n weight: (weightIdentifier ? itemRef.weights.get(weightIdentifier) : undefined) ?? 1\n }));\n\n const logic = new QtiTestVariablesExpression(this._testContext, itemVariable, includedItems);\n const value = logic.calculate();\n return value;\n }\n\n public override calculate() {\n return this.getResult();\n }\n}\n\nexport class QtiTestVariablesExpression implements QtiExpressionBase<number> {\n constructor(\n private testContext: TestContext,\n private itemVariable: string,\n private includedItems: { item: string; weight: number }[]\n ) {}\n\n calculate(): number {\n const items = this.testContext?.items ?? [];\n let total = 0;\n const uniqueItems = [...new Set(this.includedItems.map(item => item.item))];\n items.forEach(item => {\n if (uniqueItems.includes(item.identifier)) {\n const variable = item.variables.find(vr => vr.identifier === this.itemVariable);\n const weight = this.includedItems.find(i => i.item === item.identifier)?.weight ?? 1;\n if (variable) {\n // An unscored item carries a non-numeric value; counting it as NaN\n // would poison the whole total rather than just its own contribution.\n const value = Number(variable.value);\n if (!Number.isNaN(value)) {\n total += value * weight;\n }\n }\n }\n });\n return total;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'qti-test-variables': QtiTestVariables;\n }\n}\n"]}
1
+ {"version":3,"file":"qti-test-variables.js","sourceRoot":"","sources":["../../../src/components/qti-test-variables/qti-test-variables.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAErD,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;AAClF,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAMnD,MAAM,OAAO,gBAAiB,SAAQ,aAAqB;IAIzD,cAAc,GAA6B,IAAI,CAAC;IAEhD;QACE,KAAK,E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;YACH,CAAC;QACH,CAAC,CAAC,CAAC;QACH,OAAO,KAAK,CAAC;IACf,CAAC;CACF","sourcesContent":["import { consume } from '@lit/context';\n\nimport { testContext } from '@qti-components/base';\nimport { QtiExpression } from '@qti-components/base';\n\nimport { selectItemRefs, selectionFrom } from '../../internal/item-ref-selection';\nimport { listenPublic } from '../../public-events';\n\nimport type { QtiAssessmentTest } from '../qti-assessment-test/qti-assessment-test';\nimport type { TestContext } from '@qti-components/base';\nimport type { QtiExpressionBase } from '@qti-components/base';\n\nexport class QtiTestVariables extends QtiExpression<number> {\n @consume({ context: testContext, subscribe: true })\n public _testContext?: TestContext;\n\n #connectedTest: QtiAssessmentTest | null = null;\n\n constructor() {\n super();\n listenPublic(this, 'cito-test-loaded', (e: CustomEvent<QtiAssessmentTest>) => (this.#connectedTest = e.detail));\n }\n\n /**\n * `qti-assessment-test-connected` bubbles *up* from the test element, and this\n * expression lives inside that test's `qti-outcome-processing` — so the\n * listener above only ever fires for a test handed to us directly (a test\n * harness). Walking up the tree is what resolves the test in a real document.\n */\n get #testElement(): QtiAssessmentTest | null {\n return this.#connectedTest ?? this.closest<QtiAssessmentTest>('qti-assessment-test');\n }\n\n public override getResult() {\n const testElement = this.#testElement;\n if (!testElement) {\n console.warn('qti-test-variables: no enclosing qti-assessment-test, nothing to aggregate');\n return 0;\n }\n\n const weightIdentifier = this.getAttribute('weight-identifier') ?? '';\n const itemVariable = this.getAttribute('variable-identifier');\n\n const includedItems = selectItemRefs(testElement, selectionFrom(this)).map(itemRef => ({\n item: itemRef.identifier,\n weight: (weightIdentifier ? itemRef.weights.get(weightIdentifier) : undefined) ?? 1\n }));\n\n const logic = new QtiTestVariablesExpression(this._testContext, itemVariable, includedItems);\n const value = logic.calculate();\n return value;\n }\n\n public override calculate() {\n return this.getResult();\n }\n}\n\nexport class QtiTestVariablesExpression implements QtiExpressionBase<number> {\n constructor(\n private testContext: TestContext,\n private itemVariable: string,\n private includedItems: { item: string; weight: number }[]\n ) {}\n\n calculate(): number {\n const items = this.testContext?.items ?? [];\n let total = 0;\n const uniqueItems = [...new Set(this.includedItems.map(item => item.item))];\n items.forEach(item => {\n if (uniqueItems.includes(item.identifier)) {\n const variable = item.variables.find(vr => vr.identifier === this.itemVariable);\n const weight = this.includedItems.find(i => i.item === item.identifier)?.weight ?? 1;\n if (variable) {\n // An unscored item carries a non-numeric value; counting it as NaN\n // would poison the whole total rather than just its own contribution.\n const value = Number(variable.value);\n if (!Number.isNaN(value)) {\n total += value * weight;\n }\n }\n }\n });\n return total;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'qti-test-variables': QtiTestVariables;\n }\n}\n"]}
@@ -1,5 +1,7 @@
1
1
  import { LitElement } from 'lit';
2
+ import type { TestHost } from '../../internal/test-host.context';
2
3
  export declare class TestCheckItem extends LitElement {
4
+ protected testHost?: TestHost;
3
5
  static styles: import("lit").CSSResult;
4
6
  constructor();
5
7
  render(): import("lit").TemplateResult<1>;
@@ -1,5 +1,14 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ import { consume } from '@lit/context';
1
8
  import { css, html, LitElement } from 'lit';
9
+ import { testHostContext } from '../../internal/test-host.context';
2
10
  import * as styles from '../styles';
11
+ import { dispatchPublic } from '../../public-events';
3
12
  export class TestCheckItem extends LitElement {
4
13
  static { this.styles = css `
5
14
  :host {
@@ -18,9 +27,10 @@ export class TestCheckItem extends LitElement {
18
27
  constructor() {
19
28
  super();
20
29
  this.addEventListener('click', () => {
21
- this.dispatchEvent(new CustomEvent('test-end-attempt', { bubbles: true }));
22
- const qtiTest = this.closest('qti-test');
23
- const testContainer = qtiTest.querySelector('test-container');
30
+ dispatchPublic(this, 'cito-test-end-attempt', {});
31
+ const testContainer = this.testHost?.querySelector('test-container');
32
+ if (!testContainer)
33
+ return;
24
34
  const viewElements = Array.from(testContainer.shadowRoot.querySelectorAll('[view]'));
25
35
  viewElements.forEach((element) => {
26
36
  element.classList.toggle('show', true);
@@ -31,4 +41,7 @@ export class TestCheckItem extends LitElement {
31
41
  return html ` <slot></slot> `;
32
42
  }
33
43
  }
44
+ __decorate([
45
+ consume({ context: testHostContext, subscribe: true })
46
+ ], TestCheckItem.prototype, "testHost", void 0);
34
47
  //# sourceMappingURL=test-check-item.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"test-check-item.js","sourceRoot":"","sources":["../../../src/components/test-check-item/test-check-item.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AAE5C,OAAO,KAAK,MAAM,MAAM,WAAW,CAAC;AAKpC,MAAM,OAAO,aAAc,SAAQ,UAAU;aAC3B,WAAM,GAAG,GAAG,CAAA;;QAEtB,MAAM,CAAC,GAAG;;;QAGV,MAAM,CAAC,cAAc;;;QAGrB,MAAM,CAAC,SAAS;;;QAGhB,MAAM,CAAC,GAAG;;GAEf,CAAC;IAEF;QACE,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,gBAAgB,CAAC,OAAO,EAAE,GAAG,EAAE;YAClC,IAAI,CAAC,aAAa,CAAC,IAAI,WAAW,CAAC,kBAAkB,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;YAC3E,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAU,UAAU,CAAC,CAAC;YAClD,MAAM,aAAa,GAAG,OAAO,CAAC,aAAa,CAAgB,gBAAgB,CAAC,CAAC;YAE7E,MAAM,YAAY,GAAG,KAAK,CAAC,IAAI,CAAC,aAAa,CAAC,UAAU,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC,CAAC;YAErF,YAAY,CAAC,OAAO,CAAC,CAAC,OAAoB,EAAE,EAAE;gBAC5C,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;YACzC,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;IAEQ,MAAM;QACb,OAAO,IAAI,CAAA,iBAAiB,CAAC;IAC/B,CAAC","sourcesContent":["import { css, html, LitElement } from 'lit';\n\nimport * as styles from '../styles';\n\nimport type { QtiTest } from '../qti-test/qti-test';\nimport type { TestContainer } from '../test-container/test-container';\n\nexport class TestCheckItem extends LitElement {\n static override styles = css`\n :host {\n ${styles.btn};\n }\n :host(:hover:not([disabled])) {\n ${styles.btnInteractive};\n }\n :host(:focus-visible) {\n ${styles.focusRing};\n }\n :host([disabled]) {\n ${styles.dis};\n }\n `;\n\n constructor() {\n super();\n this.addEventListener('click', () => {\n this.dispatchEvent(new CustomEvent('test-end-attempt', { bubbles: true }));\n const qtiTest = this.closest<QtiTest>('qti-test');\n const testContainer = qtiTest.querySelector<TestContainer>('test-container');\n\n const viewElements = Array.from(testContainer.shadowRoot.querySelectorAll('[view]'));\n\n viewElements.forEach((element: HTMLElement) => {\n element.classList.toggle('show', true);\n });\n });\n }\n\n override render() {\n return html` <slot></slot> `;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'test-check-item': TestCheckItem;\n }\n}\n"]}
1
+ {"version":3,"file":"test-check-item.js","sourceRoot":"","sources":["../../../src/components/test-check-item/test-check-item.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AAE5C,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AACnE,OAAO,KAAK,MAAM,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAKrD,MAAM,OAAO,aAAc,SAAQ,UAAU;aAI3B,WAAM,GAAG,GAAG,CAAA;;QAEtB,MAAM,CAAC,GAAG;;;QAGV,MAAM,CAAC,cAAc;;;QAGrB,MAAM,CAAC,SAAS;;;QAGhB,MAAM,CAAC,GAAG;;GAEf,CAAC;IAEF;QACE,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,gBAAgB,CAAC,OAAO,EAAE,GAAG,EAAE;YAClC,cAAc,CAAC,IAAI,EAAE,uBAAuB,EAAE,EAAE,CAAC,CAAC;YAClD,MAAM,aAAa,GAAG,IAAI,CAAC,QAAQ,EAAE,aAAa,CAAgB,gBAAgB,CAAC,CAAC;YACpF,IAAI,CAAC,aAAa;gBAAE,OAAO;YAE3B,MAAM,YAAY,GAAG,KAAK,CAAC,IAAI,CAAC,aAAa,CAAC,UAAU,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC,CAAC;YAErF,YAAY,CAAC,OAAO,CAAC,CAAC,OAAoB,EAAE,EAAE;gBAC5C,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;YACzC,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;IAEQ,MAAM;QACb,OAAO,IAAI,CAAA,iBAAiB,CAAC;IAC/B,CAAC;;AAlCS;IADT,OAAO,CAAC,EAAE,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;+CACzB","sourcesContent":["import { consume } from '@lit/context';\nimport { css, html, LitElement } from 'lit';\n\nimport { testHostContext } from '../../internal/test-host.context';\nimport * as styles from '../styles';\nimport { dispatchPublic } from '../../public-events';\n\nimport type { TestHost } from '../../internal/test-host.context';\nimport type { TestContainer } from '../test-container/test-container';\n\nexport class TestCheckItem extends LitElement {\n @consume({ context: testHostContext, subscribe: true })\n protected testHost?: TestHost;\n\n static override styles = css`\n :host {\n ${styles.btn};\n }\n :host(:hover:not([disabled])) {\n ${styles.btnInteractive};\n }\n :host(:focus-visible) {\n ${styles.focusRing};\n }\n :host([disabled]) {\n ${styles.dis};\n }\n `;\n\n constructor() {\n super();\n this.addEventListener('click', () => {\n dispatchPublic(this, 'cito-test-end-attempt', {});\n const testContainer = this.testHost?.querySelector<TestContainer>('test-container');\n if (!testContainer) return;\n\n const viewElements = Array.from(testContainer.shadowRoot.querySelectorAll('[view]'));\n\n viewElements.forEach((element: HTMLElement) => {\n element.classList.toggle('show', true);\n });\n });\n }\n\n override render() {\n return html` <slot></slot> `;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'test-check-item': TestCheckItem;\n }\n}\n"]}
@@ -1,5 +1,6 @@
1
1
  import { LitElement } from 'lit';
2
2
  import type { QtiContext } from '@qti-components/base';
3
+ import type { TestHost } from '../../internal/test-host.context';
3
4
  /**
4
5
  * `<test-container>` is a custom element designed for hosting the qti-assessment-item.
5
6
  * The `qti-assessment-test` will be placed inside the shadow DOM of this element.
@@ -23,6 +24,8 @@ export declare class TestContainer extends LitElement {
23
24
  testDoc: DocumentFragment | null;
24
25
  /** The raw XML string */
25
26
  testXML: string | null;
27
+ /** The `qti-test` this container is in: where the host's `postLoadTestTransformCallback` lives. */
28
+ protected testHost?: TestHost;
26
29
  protected qtiContext: QtiContext;
27
30
  protected createRenderRoot(): HTMLElement | DocumentFragment;
28
31
  /** Callback function to transform the test after loading */
@@ -12,6 +12,7 @@ import { qtiContext } from '@qti-components/base';
12
12
  import { watch } from '@qti-components/utilities';
13
13
  import { qtiTransformTest } from '@qti-components/transformers';
14
14
  import itemCss from '@qti-components/theme/item-css';
15
+ import { testHostContext } from '../../internal/test-host.context';
15
16
  /**
16
17
  * `<test-container>` is a custom element designed for hosting the qti-assessment-item.
17
18
  * The `qti-assessment-test` will be placed inside the shadow DOM of this element.
@@ -64,7 +65,7 @@ export class TestContainer extends LitElement {
64
65
  const explicitSeed = this.qtiContext?.QTI_CONTEXT?.seed;
65
66
  let api = (await qtiTransformTest().load(this.testURL)).shuffleOrdering(explicitSeed);
66
67
  // Apply external transformation if provided
67
- const qtiTest = this.closest('qti-test'); // Type assertion to access mixin properties
68
+ const qtiTest = this.testHost;
68
69
  if (qtiTest?.postLoadTestTransformCallback) {
69
70
  // Create a temporary document to get the test element reference
70
71
  const tempDoc = api.htmlDoc(this.#resolvedCustomElementRegistry ?? undefined);
@@ -151,6 +152,9 @@ __decorate([
151
152
  __decorate([
152
153
  state()
153
154
  ], TestContainer.prototype, "testXML", void 0);
155
+ __decorate([
156
+ consume({ context: testHostContext, subscribe: true })
157
+ ], TestContainer.prototype, "testHost", void 0);
154
158
  __decorate([
155
159
  state(),
156
160
  consume({ context: qtiContext, subscribe: true })
@@ -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;AAIrD;;;;;;;;;;;;GAYG;AAEH,MAAM,OAAO,aAAc,SAAQ,UAAU;IAA7C;;QACE,mFAAmF;QAEnF,0BAAqB,GAAiC,IAAI,CAAC;QAE3D,8BAA8B;QAE9B,YAAO,GAAkB,IAAI,CAAC;QAE9B,6BAA6B;QAE7B,YAAO,GAA4B,IAAI,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AwBc;IADf,KAAK,CAAC,SAAS,EAAE,EAAE,oBAAoB,EAAE,IAAI,EAAE,CAAC;wDAuBhD;AAuBS;IADT,KAAK,CAAC,SAAS,EAAE,EAAE,oBAAoB,EAAE,IAAI,EAAE,CAAC;wDAchD","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 type { QtiContext } from '@qti-components/base';\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 @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)).shuffleOrdering(explicitSeed);\n // Apply external transformation if provided\n const qtiTest = this.closest('qti-test') as any; // Type assertion to access mixin properties\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 * `qti-assessment-test-connected`, 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 .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,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,mFAAmF;QAEnF,0BAAqB,GAAiC,IAAI,CAAC;QAE3D,8BAA8B;QAE9B,YAAO,GAAkB,IAAI,CAAC;QAE9B,6BAA6B;QAE7B,YAAO,GAA4B,IAAI,CAAC;QAExC,yBAAyB;QAEzB,YAAO,GAAkB,IAAI,CAAC;QAQp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;AAwBc;IADf,KAAK,CAAC,SAAS,EAAE,EAAE,oBAAoB,EAAE,IAAI,EAAE,CAAC;wDAuBhD;AAuBS;IADT,KAAK,CAAC,SAAS,EAAE,EAAE,oBAAoB,EAAE,IAAI,EAAE,CAAC;wDAchD","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)).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 * `qti-assessment-test-connected`, 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 .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"]}
@@ -10,6 +10,7 @@ import { consume } from '@lit/context';
10
10
  import { computedContext } from '@qti-components/base';
11
11
  import { watch } from '@qti-components/utilities';
12
12
  import * as styles from '../styles';
13
+ import { dispatchPublic } from '../../public-events';
13
14
  export class TestEndAttempt extends LitElement {
14
15
  _handleTestElementChange(_oldValue, newValue) {
15
16
  if (newValue) {
@@ -36,7 +37,7 @@ export class TestEndAttempt extends LitElement {
36
37
  this.addEventListener('click', e => {
37
38
  e.preventDefault();
38
39
  if (!this._internalDisabled) {
39
- this.dispatchEvent(new CustomEvent('test-end-attempt', { bubbles: true }));
40
+ dispatchPublic(this, 'cito-test-end-attempt', {});
40
41
  }
41
42
  });
42
43
  }