@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
@@ -0,0 +1,24 @@
1
+ import type { QtiContext } from '@qti-components/base';
2
+ import type { transformTestApi } from '@qti-components/transformers';
3
+ import type { QtiAssessmentTest } from '../components/qti-assessment-test/qti-assessment-test';
4
+ /**
5
+ * Defined here, and re-exported by the navigation mixin under the same name, so this file imports
6
+ * nothing from the mixin: the mixin imports the components that consume this context, and a type
7
+ * import counts as a dependency for madge.
8
+ */
9
+ export type PostLoadTestTransformCallback = (transformer: transformTestApi, testElement: QtiAssessmentTest) => transformTestApi | Promise<transformTestApi>;
10
+ /**
11
+ * What the components inside a test need from the `qti-test` that contains them: the things a host
12
+ * put on it, and the element to query. Provided by `qti-test` about itself.
13
+ *
14
+ * It is context and not `closest('qti-test')` because a request crosses shadow roots and `closest`
15
+ * stops at the first one, so a navigation or container a host renders inside its own component
16
+ * would never find its test. Internal on purpose: not exported from the package, and not API.
17
+ */
18
+ export interface TestHost extends HTMLElement {
19
+ qtiContext: QtiContext;
20
+ postLoadTestTransformCallback: PostLoadTestTransformCallback | null;
21
+ }
22
+ export declare const testHostContext: {
23
+ __context__: TestHost;
24
+ };
@@ -0,0 +1,3 @@
1
+ import { createContext } from '@lit/context';
2
+ export const testHostContext = createContext(Symbol('testHost'));
3
+ //# sourceMappingURL=test-host.context.js.map
@@ -0,0 +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;AA6B7C,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\nexport const testHostContext = createContext<TestHost>(Symbol('testHost'));\n"]}
@@ -1,3 +1,4 @@
1
1
  export * from './test-navigation.mixin';
2
2
  export * from './test-view.mixin';
3
3
  export * from './test-base';
4
+ export * from './test-state.mixin';
@@ -1,4 +1,5 @@
1
1
  export * from './test-navigation.mixin';
2
2
  export * from './test-view.mixin';
3
3
  export * from './test-base';
4
+ export * from './test-state.mixin';
4
5
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/mixins/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC;AACxC,cAAc,mBAAmB,CAAC;AAClC,cAAc,aAAa,CAAC","sourcesContent":["export * from './test-navigation.mixin';\nexport * from './test-view.mixin';\nexport * from './test-base';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/mixins/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC;AACxC,cAAc,mBAAmB,CAAC;AAClC,cAAc,aAAa,CAAC;AAC5B,cAAc,oBAAoB,CAAC","sourcesContent":["export * from './test-navigation.mixin';\nexport * from './test-view.mixin';\nexport * from './test-base';\nexport * from './test-state.mixin';\n"]}
@@ -1,7 +1,8 @@
1
1
  import { LitElement } from 'lit';
2
2
  import { type SessionContext } from '@qti-components/base';
3
3
  import type { QtiAssessmentTest } from '../components/qti-assessment-test/qti-assessment-test';
4
- import type { ConfigContext } from '@qti-components/base';
4
+ import type { ConfigContext, QtiContext } from '@qti-components/base';
5
+ import type { ItemContext } from '@qti-components/base';
5
6
  import type { TestContext } from '@qti-components/base';
6
7
  import type { VariableValue } from '@qti-components/base';
7
8
  type Constructor<T = {}> = abstract new (...args: any[]) => T;
@@ -9,9 +10,13 @@ export interface TestBaseInterface extends LitElement {
9
10
  testContext: Readonly<TestContext>;
10
11
  sessionContext: Readonly<SessionContext>;
11
12
  configContext?: Readonly<ConfigContext>;
13
+ /** Provided by `qti-test`. */
14
+ qtiContext?: Readonly<QtiContext>;
12
15
  _testElement: QtiAssessmentTest;
13
- updateItemVariables(itemRefID: string, variables: VariableValue<string | string[] | null>[]): void;
16
+ updateItemVariables(itemRefID: string, variables: readonly ItemVariableValue[], state?: ItemContext['state']): void;
14
17
  }
18
+ /** A value to set on an item; `type` is only needed for a variable the item does not declare. */
19
+ export type ItemVariableValue = Pick<VariableValue<string | string[] | null>, 'identifier' | 'value'> & Partial<Pick<VariableValue<string | string[] | null>, 'type'>>;
15
20
  export declare const TestBaseMixin: <T extends Constructor<LitElement>>(superClass: T) => Constructor<TestBaseInterface> & T;
16
21
  declare const TestBase_base: Constructor<TestBaseInterface> & typeof LitElement;
17
22
  export declare abstract class TestBase extends TestBase_base {
@@ -9,6 +9,7 @@ import { LitElement } from 'lit';
9
9
  import { property } from 'lit/decorators.js';
10
10
  import { INITIAL_TEST_CONTEXT, testContext } from '@qti-components/base';
11
11
  import { INITIAL_SESSION_CONTEXT, sessionContext } from '@qti-components/base';
12
+ import { listenPublic } from '../public-events';
12
13
  export const TestBaseMixin = (superClass) => {
13
14
  class TestBaseClass extends superClass {
14
15
  constructor(...args) {
@@ -25,7 +26,7 @@ export const TestBaseMixin = (superClass) => {
25
26
  * @param assessmentItem - The assessment item to update.
26
27
  */
27
28
  this._updateItemInTestContext = (assessmentItem) => {
28
- const context = assessmentItem._context;
29
+ const context = assessmentItem.itemContext;
29
30
  const identifier = context.identifier;
30
31
  const fullVariables = context.variables;
31
32
  // Find the corresponding item in the test context by identifier
@@ -37,7 +38,7 @@ export const TestBaseMixin = (superClass) => {
37
38
  // Update variables in the test context or sync them to the assessment item
38
39
  if (itemContext.variables?.length === 1) {
39
40
  // The loaded qti-assessment-item itself has variables which are not in test context yet.
40
- this._updateItemVariablesInTestContext(identifier, fullVariables);
41
+ this._updateItemVariablesInTestContext(identifier, fullVariables, undefined, context.valid);
41
42
  }
42
43
  else {
43
44
  const newVariables = [...assessmentItem.variables];
@@ -52,24 +53,56 @@ export const TestBaseMixin = (superClass) => {
52
53
  }
53
54
  }
54
55
  assessmentItem.variables = newVariables;
56
+ // Opaque interaction state (a PCI's getState()) is read from the item context when the
57
+ // interaction initializes, so it has to be in place now, before that happens.
58
+ if (itemContext.state) {
59
+ assessmentItem.state = itemContext.state;
60
+ }
55
61
  }
56
62
  };
57
63
  this._initializeEventListeners();
58
64
  }
59
- updateItemVariables(itemRefID, variables) {
60
- // Update variables in the testContext for the specified itemRefID
61
- const itemContext = this.testContext.items.find(item => item.identifier === itemRefID);
62
- if (itemContext) {
63
- itemContext.variables = itemContext.variables.map(variable => {
64
- const updatedVariable = variables.find(v => v.identifier === variable.identifier);
65
- return updatedVariable ? { ...variable, ...updatedVariable } : variable;
66
- });
67
- }
68
- // if the qti-assessment-item-ref has a qti-assessment-item, then update this item as well
69
- const itemRef = this._testElement.querySelector(`qti-assessment-item-ref[identifier="${itemRefID}"]`);
70
- if (itemRef && itemRef.assessmentItem) {
71
- itemRef.assessmentItem.variables = variables;
72
- }
65
+ /**
66
+ * Sets values on one item from outside the candidate's session, e.g. a score from manual
67
+ * scoring. Values are merged into the item's entry in the test context, and into the item
68
+ * itself if it is on screen; a value the item has not seen yet is added, so this also works
69
+ * before the item has loaded. To restore a whole session, assign `state` instead.
70
+ *
71
+ * The test context is replaced rather than changed in place, so its consumers update and
72
+ * `qti-state-changed` fires.
73
+ *
74
+ * @param itemRefID The `qti-assessment-item-ref` identifier, not the item's own identifier.
75
+ * @param state Opaque per-interaction state keyed by response identifier, e.g. a PCI's `getState()`.
76
+ */
77
+ updateItemVariables(itemRefID, values, state) {
78
+ this.testContext = {
79
+ ...this.testContext,
80
+ items: this.testContext.items.map(item => {
81
+ if (item.identifier !== itemRefID)
82
+ return item;
83
+ const variables = [...(item.variables ?? [])];
84
+ for (const { identifier, type, value } of values) {
85
+ const index = variables.findIndex(v => v.identifier === identifier);
86
+ const updated = {
87
+ ...(index >= 0 ? variables[index] : {}),
88
+ identifier,
89
+ ...(type ? { type } : {}),
90
+ value: Array.isArray(value) ? [...value] : value
91
+ };
92
+ if (index >= 0)
93
+ variables[index] = updated;
94
+ else
95
+ variables.push(updated);
96
+ }
97
+ return { ...item, variables, ...(state ? { state: { ...state } } : {}) };
98
+ })
99
+ };
100
+ const assessmentItem = this._testElement?.querySelector(`qti-assessment-item-ref[identifier="${CSS.escape(itemRefID)}"]`)?.assessmentItem;
101
+ if (!assessmentItem)
102
+ return;
103
+ assessmentItem.variables = [...(this.testContext.items.find(i => i.identifier === itemRefID)?.variables ?? [])];
104
+ if (state)
105
+ assessmentItem.state = state;
73
106
  }
74
107
  _initializeEventListeners() {
75
108
  /**
@@ -91,7 +124,7 @@ export const TestBaseMixin = (superClass) => {
91
124
  * Registrations from the document's children are already present on the
92
125
  * context reset above, so this must preserve what is there.
93
126
  */
94
- this.addEventListener('qti-assessment-test-connected', (e) => {
127
+ listenPublic(this, 'cito-test-loaded', (e) => {
95
128
  this._testElement = e.detail;
96
129
  const items = Array.from(this._testElement.querySelectorAll('qti-assessment-item-ref')).map(itemRef => {
97
130
  return {
@@ -119,10 +152,10 @@ export const TestBaseMixin = (superClass) => {
119
152
  });
120
153
  this.addEventListener('qti-item-context-updated', (e) => {
121
154
  // const assessmentitem = e.composedPath()[0] as QtiAssessmentItem;
122
- this._updateItemVariablesInTestContext(e.detail.itemContext.identifier, e.detail.itemContext.variables, e.detail.itemContext.state);
155
+ this._updateItemVariablesInTestContext(e.detail.itemContext.identifier, e.detail.itemContext.variables, e.detail.itemContext.state, e.detail.itemContext.valid);
123
156
  });
124
157
  }
125
- _updateItemVariablesInTestContext(identifier, variables, state) {
158
+ _updateItemVariablesInTestContext(identifier, variables, state, valid) {
126
159
  // Update the test context with modified variables for the specified item
127
160
  this.testContext = {
128
161
  ...this.testContext, // Spread existing test context properties
@@ -140,10 +173,12 @@ export const TestBaseMixin = (superClass) => {
140
173
  // Merge matching variable with the new one, or use the new variable if no match
141
174
  return matchingVariable ? { ...matchingVariable, ...variable } : variable;
142
175
  }),
143
- ...(state !== undefined ? { state: state ? { ...state } : undefined } : {})
176
+ ...(state !== undefined ? { state: state ? { ...state } : undefined } : {}),
177
+ ...(valid !== undefined ? { valid } : {})
144
178
  };
145
179
  })
146
180
  };
181
+ // Deprecated for hosts, see `@event` on `qti-test`; kept until the next major.
147
182
  this.dispatchEvent(new CustomEvent('qti-test-context-updated', { detail: this.testContext, bubbles: false, composed: false }));
148
183
  }
149
184
  }
@@ -1 +1 @@
1
- {"version":3,"file":"test-base.js","sourceRoot":"","sources":["../../src/mixins/test-base.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AACjC,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C,OAAO,EAAE,oBAAoB,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACzE,OAAO,EAAE,uB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EAAE,CAAC;qBAC5E,CAAC;gBACJ,CAAC,CAAC;aACH,CAAC;YACF,IAAI,CAAC,aAAa,CAChB,IAAI,WAAW,CAAC,0BAA0B,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,WAAW,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,CAC3G,CAAC;QACJ,CAAC;KA0CF;IAnKQ;QAFN,QAAQ,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;QAC5C,OAAO,CAAC,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC;sDAC+B;IAI1D;QAFN,QAAQ,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;QAC5C,OAAO,CAAC,EAAE,OAAO,EAAE,cAAc,EAAE,CAAC;yDACqC;IAiK5E,OAAO,aAAmD,CAAC;AAC7D,CAAC,CAAC;AAEF,2EAA2E;AAC3E,MAAM,OAAgB,QAAS,SAAQ,aAAa,CAAC,UAAU,CAAC;CAAG","sourcesContent":["import { provide } from '@lit/context';\nimport { LitElement } from 'lit';\nimport { property } from 'lit/decorators.js';\n\nimport { INITIAL_TEST_CONTEXT, testContext } from '@qti-components/base';\nimport { INITIAL_SESSION_CONTEXT, type SessionContext, sessionContext } from '@qti-components/base';\n\nimport type { QtiAssessmentItem } from '@qti-components/elements';\nimport type { QtiAssessmentItemRef } from '../components/qti-assessment-item-ref/qti-assessment-item-ref';\nimport type { QtiAssessmentTest } from '../components/qti-assessment-test/qti-assessment-test';\nimport type { ConfigContext } from '@qti-components/base';\nimport type { ItemContext } from '@qti-components/base';\nimport type { TestContext } from '@qti-components/base';\nimport type { OutcomeVariable, VariableDeclaration, VariableValue } from '@qti-components/base';\n\ntype Constructor<T = {}> = abstract new (...args: any[]) => T;\n\nexport interface TestBaseInterface extends LitElement {\n testContext: Readonly<TestContext>;\n sessionContext: Readonly<SessionContext>;\n configContext?: Readonly<ConfigContext>;\n _testElement: QtiAssessmentTest;\n updateItemVariables(itemRefID: string, variables: VariableValue<string | string[] | null>[]): void;\n}\n\nexport const TestBaseMixin = <T extends Constructor<LitElement>>(superClass: T) => {\n abstract class TestBaseClass extends superClass implements TestBaseInterface {\n @property({ attribute: false, type: Object })\n @provide({ context: testContext })\n public testContext: Readonly<TestContext> = INITIAL_TEST_CONTEXT;\n\n @property({ attribute: false, type: Object })\n @provide({ context: sessionContext })\n public sessionContext: Readonly<SessionContext> = INITIAL_SESSION_CONTEXT;\n\n public _testElement: QtiAssessmentTest;\n\n constructor(...args: any[]) {\n super(...args);\n this._initializeEventListeners();\n }\n\n updateItemVariables(itemRefID: string, variables: VariableValue<string | string[] | null>[]): void {\n // Update variables in the testContext for the specified itemRefID\n const itemContext = this.testContext.items.find(item => item.identifier === itemRefID);\n if (itemContext) {\n itemContext.variables = itemContext.variables.map(variable => {\n const updatedVariable = variables.find(v => v.identifier === variable.identifier);\n return updatedVariable ? { ...variable, ...updatedVariable } : variable;\n });\n }\n // if the qti-assessment-item-ref has a qti-assessment-item, then update this item as well\n const itemRef = this._testElement.querySelector<QtiAssessmentItemRef>(\n `qti-assessment-item-ref[identifier=\"${itemRefID}\"]`\n );\n if (itemRef && itemRef.assessmentItem) {\n itemRef.assessmentItem.variables = variables;\n }\n }\n\n private _initializeEventListeners(): void {\n /**\n * A new test document means a new test and session context.\n *\n * This resets on the document being loaded rather than on\n * `qti-assessment-test-connected`, because the new document's children —\n * test-level `qti-outcome-declaration` among them — connect and register\n * themselves into the context *before* the test element announces itself.\n * Resetting on that announcement discarded every one of those\n * registrations, so no test-level outcome could be read or set.\n */\n this.addEventListener('qti-testdoc-loaded', () => {\n this.testContext = INITIAL_TEST_CONTEXT;\n this.sessionContext = INITIAL_SESSION_CONTEXT;\n });\n\n /**\n * When the test is connected, its item-refs are added to the test context.\n * Registrations from the document's children are already present on the\n * context reset above, so this must preserve what is there.\n */\n this.addEventListener('qti-assessment-test-connected', (e: CustomEvent<QtiAssessmentTest>) => {\n this._testElement = e.detail;\n const items = Array.from(this._testElement.querySelectorAll('qti-assessment-item-ref')).map(itemRef => {\n return {\n href: itemRef.href,\n identifier: itemRef.identifier,\n category: itemRef.category,\n variables: [\n {\n identifier: 'completionStatus',\n value: 'not_attempted',\n type: 'outcome'\n } as OutcomeVariable\n ]\n };\n });\n this.testContext = { ...this.testContext, items };\n });\n\n this.addEventListener('qti-assessment-item-connected', (e: CustomEvent<QtiAssessmentItem>) => {\n const assessmentItem = e.detail as QtiAssessmentItem;\n const assessmentRefId = assessmentItem.closest('qti-assessment-item-ref')?.identifier;\n if (assessmentRefId) {\n assessmentItem.assessmentItemRefId = assessmentRefId;\n }\n this._updateItemInTestContext(e.detail);\n });\n\n this.addEventListener('qti-item-context-updated', (e: CustomEvent<{ itemContext: ItemContext }>) => {\n // const assessmentitem = e.composedPath()[0] as QtiAssessmentItem;\n this._updateItemVariablesInTestContext(\n e.detail.itemContext.identifier,\n e.detail.itemContext.variables,\n e.detail.itemContext.state\n );\n });\n }\n\n private _updateItemVariablesInTestContext(\n identifier: string,\n variables: readonly VariableDeclaration<string | string[] | null>[],\n state?: ItemContext['state']\n ): void {\n // Update the test context with modified variables for the specified item\n this.testContext = {\n ...this.testContext, // Spread existing test context properties\n items: this.testContext.items.map(itemContext => {\n // If the item identifier doesn't match, keep it unchanged\n if (itemContext.identifier !== identifier) {\n return itemContext;\n }\n\n // Update the matching item with new variables\n return {\n ...itemContext, // Keep other properties of the item context\n variables: variables.map(variable => {\n // Find a matching variable in the current item context\n const matchingVariable = itemContext.variables.find(v => v.identifier === variable.identifier);\n\n // Merge matching variable with the new one, or use the new variable if no match\n return matchingVariable ? { ...matchingVariable, ...variable } : variable;\n }),\n ...(state !== undefined ? { state: state ? { ...state } : undefined } : {})\n };\n })\n };\n this.dispatchEvent(\n new CustomEvent('qti-test-context-updated', { detail: this.testContext, bubbles: false, composed: false })\n );\n }\n\n /**\n * Updates the variables of an assessment item in the test context.\n * - Matches the assessment item with the corresponding test context item.\n * - If the item is not found, logs a warning.\n * - Updates variables in the test context if exactly one variable exists.\n * - Otherwise, syncs the assessment item's variables with the test context.\n *\n * @param assessmentItem - The assessment item to update.\n */\n private _updateItemInTestContext = (assessmentItem: QtiAssessmentItem): void => {\n const context = (assessmentItem as any)._context;\n const identifier = context.identifier;\n const fullVariables = context.variables;\n\n // Find the corresponding item in the test context by identifier\n const itemContext = this.testContext.items.find(i => i?.identifier === identifier);\n\n if (!itemContext) {\n console.warn(`Item IDs between assessment.xml and item.xml should match: ${identifier} is not found!`);\n return;\n }\n\n // Update variables in the test context or sync them to the assessment item\n if (itemContext.variables?.length === 1) {\n // The loaded qti-assessment-item itself has variables which are not in test context yet.\n this._updateItemVariablesInTestContext(identifier, fullVariables);\n } else {\n const newVariables = [...assessmentItem.variables];\n // Sync the assessment item's variables with the test context\n for (const variable of itemContext.variables) {\n const currentVariable = newVariables.find(v => v.identifier === variable.identifier);\n if (currentVariable) {\n currentVariable.value = variable.value;\n } else {\n newVariables.push(variable);\n }\n }\n assessmentItem.variables = newVariables;\n }\n };\n }\n\n return TestBaseClass as Constructor<TestBaseInterface> & T;\n};\n\n// Keep the old abstract class for backwards compatibility during migration\nexport abstract class TestBase extends TestBaseMixin(LitElement) {}\n"]}
1
+ {"version":3,"file":"test-base.js","sourceRoot":"","sources":["../../src/mixins/test-base.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AACjC,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C,OAAO,EAAE,oBAAoB,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACzE,OAAO,EAAE,uBAAuB,EAAuB,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEpG,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AA0BhD,MAAM,CAAC,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ACJ,CAAC,CAAC;aACH,CAAC;YACF,+EAA+E;YAC/E,IAAI,CAAC,aAAa,CAChB,IAAI,WAAW,CAAC,0BAA0B,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,WAAW,EAAE,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,CAC3G,CAAC;QACJ,CAAC;KA+CF;IApMQ;QAFN,QAAQ,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;QAC5C,OAAO,CAAC,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC;sDAC+B;IAI1D;QAFN,QAAQ,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;QAC5C,OAAO,CAAC,EAAE,OAAO,EAAE,cAAc,EAAE,CAAC;yDACqC;IAkM5E,OAAO,aAAmD,CAAC;AAC7D,CAAC,CAAC;AAEF,2EAA2E;AAC3E,MAAM,OAAgB,QAAS,SAAQ,aAAa,CAAC,UAAU,CAAC;CAAG","sourcesContent":["import { provide } from '@lit/context';\nimport { LitElement } from 'lit';\nimport { property } from 'lit/decorators.js';\n\nimport { INITIAL_TEST_CONTEXT, testContext } from '@qti-components/base';\nimport { INITIAL_SESSION_CONTEXT, type SessionContext, sessionContext } from '@qti-components/base';\n\nimport { listenPublic } from '../public-events';\n\nimport type { QtiAssessmentItem } from '@qti-components/elements';\nimport type { QtiAssessmentItemRef } from '../components/qti-assessment-item-ref/qti-assessment-item-ref';\nimport type { QtiAssessmentTest } from '../components/qti-assessment-test/qti-assessment-test';\nimport type { ConfigContext, QtiContext } from '@qti-components/base';\nimport type { ItemContext } from '@qti-components/base';\nimport type { TestContext } from '@qti-components/base';\nimport type { OutcomeVariable, VariableDeclaration, VariableValue } from '@qti-components/base';\n\ntype Constructor<T = {}> = abstract new (...args: any[]) => T;\n\nexport interface TestBaseInterface extends LitElement {\n testContext: Readonly<TestContext>;\n sessionContext: Readonly<SessionContext>;\n configContext?: Readonly<ConfigContext>;\n /** Provided by `qti-test`. */\n qtiContext?: Readonly<QtiContext>;\n _testElement: QtiAssessmentTest;\n updateItemVariables(itemRefID: string, variables: readonly ItemVariableValue[], state?: ItemContext['state']): void;\n}\n\n/** A value to set on an item; `type` is only needed for a variable the item does not declare. */\nexport type ItemVariableValue = Pick<VariableValue<string | string[] | null>, 'identifier' | 'value'> &\n Partial<Pick<VariableValue<string | string[] | null>, 'type'>>;\n\nexport const TestBaseMixin = <T extends Constructor<LitElement>>(superClass: T) => {\n abstract class TestBaseClass extends superClass implements TestBaseInterface {\n @property({ attribute: false, type: Object })\n @provide({ context: testContext })\n public testContext: Readonly<TestContext> = INITIAL_TEST_CONTEXT;\n\n @property({ attribute: false, type: Object })\n @provide({ context: sessionContext })\n public sessionContext: Readonly<SessionContext> = INITIAL_SESSION_CONTEXT;\n\n public _testElement: QtiAssessmentTest;\n\n constructor(...args: any[]) {\n super(...args);\n this._initializeEventListeners();\n }\n\n /**\n * Sets values on one item from outside the candidate's session, e.g. a score from manual\n * scoring. Values are merged into the item's entry in the test context, and into the item\n * itself if it is on screen; a value the item has not seen yet is added, so this also works\n * before the item has loaded. To restore a whole session, assign `state` instead.\n *\n * The test context is replaced rather than changed in place, so its consumers update and\n * `qti-state-changed` fires.\n *\n * @param itemRefID The `qti-assessment-item-ref` identifier, not the item's own identifier.\n * @param state Opaque per-interaction state keyed by response identifier, e.g. a PCI's `getState()`.\n */\n updateItemVariables(itemRefID: string, values: readonly ItemVariableValue[], state?: ItemContext['state']): void {\n this.testContext = {\n ...this.testContext,\n items: this.testContext.items.map(item => {\n if (item.identifier !== itemRefID) return item;\n\n const variables = [...(item.variables ?? [])];\n for (const { identifier, type, value } of values) {\n const index = variables.findIndex(v => v.identifier === identifier);\n const updated = {\n ...(index >= 0 ? variables[index] : {}),\n identifier,\n ...(type ? { type } : {}),\n value: Array.isArray(value) ? [...value] : value\n } as VariableDeclaration<string | string[] | null>;\n if (index >= 0) variables[index] = updated;\n else variables.push(updated);\n }\n return { ...item, variables, ...(state ? { state: { ...state } } : {}) };\n })\n };\n\n const assessmentItem = this._testElement?.querySelector<QtiAssessmentItemRef>(\n `qti-assessment-item-ref[identifier=\"${CSS.escape(itemRefID)}\"]`\n )?.assessmentItem;\n if (!assessmentItem) return;\n assessmentItem.variables = [...(this.testContext.items.find(i => i.identifier === itemRefID)?.variables ?? [])];\n if (state) assessmentItem.state = state;\n }\n\n private _initializeEventListeners(): void {\n /**\n * A new test document means a new test and session context.\n *\n * This resets on the document being loaded rather than on\n * `qti-assessment-test-connected`, because the new document's children —\n * test-level `qti-outcome-declaration` among them — connect and register\n * themselves into the context *before* the test element announces itself.\n * Resetting on that announcement discarded every one of those\n * registrations, so no test-level outcome could be read or set.\n */\n this.addEventListener('qti-testdoc-loaded', () => {\n this.testContext = INITIAL_TEST_CONTEXT;\n this.sessionContext = INITIAL_SESSION_CONTEXT;\n });\n\n /**\n * When the test is connected, its item-refs are added to the test context.\n * Registrations from the document's children are already present on the\n * context reset above, so this must preserve what is there.\n */\n listenPublic(this, 'cito-test-loaded', (e: CustomEvent<QtiAssessmentTest>) => {\n this._testElement = e.detail;\n const items = Array.from(this._testElement.querySelectorAll('qti-assessment-item-ref')).map(itemRef => {\n return {\n href: itemRef.href,\n identifier: itemRef.identifier,\n category: itemRef.category,\n variables: [\n {\n identifier: 'completionStatus',\n value: 'not_attempted',\n type: 'outcome'\n } as OutcomeVariable\n ]\n };\n });\n this.testContext = { ...this.testContext, items };\n });\n\n this.addEventListener('qti-assessment-item-connected', (e: CustomEvent<QtiAssessmentItem>) => {\n const assessmentItem = e.detail as QtiAssessmentItem;\n const assessmentRefId = assessmentItem.closest('qti-assessment-item-ref')?.identifier;\n if (assessmentRefId) {\n assessmentItem.assessmentItemRefId = assessmentRefId;\n }\n this._updateItemInTestContext(e.detail);\n });\n\n this.addEventListener('qti-item-context-updated', (e: CustomEvent<{ itemContext: ItemContext }>) => {\n // const assessmentitem = e.composedPath()[0] as QtiAssessmentItem;\n this._updateItemVariablesInTestContext(\n e.detail.itemContext.identifier,\n e.detail.itemContext.variables,\n e.detail.itemContext.state,\n e.detail.itemContext.valid\n );\n });\n }\n\n private _updateItemVariablesInTestContext(\n identifier: string,\n variables: readonly VariableDeclaration<string | string[] | null>[],\n state?: ItemContext['state'],\n valid?: boolean\n ): void {\n // Update the test context with modified variables for the specified item\n this.testContext = {\n ...this.testContext, // Spread existing test context properties\n items: this.testContext.items.map(itemContext => {\n // If the item identifier doesn't match, keep it unchanged\n if (itemContext.identifier !== identifier) {\n return itemContext;\n }\n\n // Update the matching item with new variables\n return {\n ...itemContext, // Keep other properties of the item context\n variables: variables.map(variable => {\n // Find a matching variable in the current item context\n const matchingVariable = itemContext.variables.find(v => v.identifier === variable.identifier);\n\n // Merge matching variable with the new one, or use the new variable if no match\n return matchingVariable ? { ...matchingVariable, ...variable } : variable;\n }),\n ...(state !== undefined ? { state: state ? { ...state } : undefined } : {}),\n ...(valid !== undefined ? { valid } : {})\n };\n })\n };\n // Deprecated for hosts, see `@event` on `qti-test`; kept until the next major.\n this.dispatchEvent(\n new CustomEvent('qti-test-context-updated', { detail: this.testContext, bubbles: false, composed: false })\n );\n }\n\n /**\n * Updates the variables of an assessment item in the test context.\n * - Matches the assessment item with the corresponding test context item.\n * - If the item is not found, logs a warning.\n * - Updates variables in the test context if exactly one variable exists.\n * - Otherwise, syncs the assessment item's variables with the test context.\n *\n * @param assessmentItem - The assessment item to update.\n */\n private _updateItemInTestContext = (assessmentItem: QtiAssessmentItem): void => {\n const context = assessmentItem.itemContext;\n const identifier = context.identifier;\n const fullVariables = context.variables;\n\n // Find the corresponding item in the test context by identifier\n const itemContext = this.testContext.items.find(i => i?.identifier === identifier);\n\n if (!itemContext) {\n console.warn(`Item IDs between assessment.xml and item.xml should match: ${identifier} is not found!`);\n return;\n }\n\n // Update variables in the test context or sync them to the assessment item\n if (itemContext.variables?.length === 1) {\n // The loaded qti-assessment-item itself has variables which are not in test context yet.\n this._updateItemVariablesInTestContext(identifier, fullVariables, undefined, context.valid);\n } else {\n const newVariables = [...assessmentItem.variables];\n // Sync the assessment item's variables with the test context\n for (const variable of itemContext.variables) {\n const currentVariable = newVariables.find(v => v.identifier === variable.identifier);\n if (currentVariable) {\n currentVariable.value = variable.value;\n } else {\n newVariables.push(variable);\n }\n }\n assessmentItem.variables = newVariables;\n // Opaque interaction state (a PCI's getState()) is read from the item context when the\n // interaction initializes, so it has to be in place now, before that happens.\n if (itemContext.state) {\n assessmentItem.state = itemContext.state;\n }\n }\n };\n }\n\n return TestBaseClass as Constructor<TestBaseInterface> & T;\n};\n\n// Keep the old abstract class for backwards compatibility during migration\nexport abstract class TestBase extends TestBaseMixin(LitElement) {}\n"]}
@@ -1,10 +1,10 @@
1
- import type { transformItemApi, transformTestApi } from '@qti-components/transformers';
1
+ import type { transformItemApi } from '@qti-components/transformers';
2
2
  import type { QtiAssessmentItemRef } from '../components/qti-assessment-item-ref/qti-assessment-item-ref';
3
- import type { QtiAssessmentTest } from '../components/qti-assessment-test/qti-assessment-test';
3
+ import type { PostLoadTestTransformCallback } from '../internal/test-host.context';
4
4
  import type { TestBaseInterface } from './test-base';
5
5
  type Constructor<T = {}> = abstract new (...args: any[]) => T;
6
6
  export type PostLoadTransformCallback = (transformer: transformItemApi, itemRef: QtiAssessmentItemRef) => transformItemApi | Promise<transformItemApi>;
7
- export type PostLoadTestTransformCallback = (transformer: transformTestApi, testElement: QtiAssessmentTest) => transformTestApi | Promise<transformTestApi>;
7
+ export type { PostLoadTestTransformCallback };
8
8
  export interface NavigationError {
9
9
  message: string;
10
10
  details?: any;
@@ -50,4 +50,3 @@ export interface ITestNavigationMixin {
50
50
  * - Error handling and edge case coverage
51
51
  */
52
52
  export declare const TestNavigationMixin: <T extends Constructor<TestBaseInterface>>(superClass: T) => Constructor<ITestNavigationMixin> & T;
53
- export {};
@@ -6,6 +6,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
6
6
  };
7
7
  import { property } from 'lit/decorators.js';
8
8
  import { qtiTransformItem } from '@qti-components/transformers';
9
+ import { dispatchPublic, listenPublic } from '../public-events';
9
10
  /**
10
11
  * Navigation mixin for QTI test components
11
12
  *
@@ -46,24 +47,20 @@ export const TestNavigationMixin = (superClass) => {
46
47
  /**
47
48
  * Navigate to a specific item or section
48
49
  * @param type - Navigation type ('item' or 'section')
49
- * @param id - Target identifier (optional, falls back to first available)
50
+ * @param id - Target identifier (optional, falls back to the current position, or the first one before there is any)
50
51
  */
51
52
  navigateTo(type, id) {
52
53
  const targetId = id || this._getDefaultNavigationId(type);
53
54
  if (targetId) {
54
- this.dispatchEvent(new CustomEvent('qti-request-navigation', {
55
- detail: { type, id: targetId },
56
- bubbles: true,
57
- composed: true
58
- }));
55
+ dispatchPublic(this, 'cito-test-navigate', { type, id: targetId });
59
56
  }
60
57
  }
61
58
  // ===========================================
62
59
  // EVENT HANDLER SETUP
63
60
  // ===========================================
64
61
  _bindEventHandlers() {
65
- this.addEventListener('qti-request-navigation', this._handleNavigationRequest.bind(this));
66
- this.addEventListener('qti-assessment-test-connected', this._handleTestConnected.bind(this));
62
+ listenPublic(this, 'cito-test-navigate', this._handleNavigationRequest.bind(this));
63
+ listenPublic(this, 'cito-test-loaded', this._handleTestConnected.bind(this));
67
64
  this.addEventListener('qti-assessment-item-connected', this._handleItemConnected.bind(this));
68
65
  this.addEventListener('qti-assessment-stimulus-ref-connected', this._handleStimulusRefConnected.bind(this));
69
66
  }
@@ -135,7 +132,8 @@ export const TestNavigationMixin = (superClass) => {
135
132
  // ===========================================
136
133
  _getDefaultNavigationId(type) {
137
134
  if (type === 'section') {
138
- return this._testElement?.querySelector('qti-assessment-section')?.identifier;
135
+ return (this.sessionContext?.navSectionId ??
136
+ this._testElement?.querySelector('qti-assessment-section')?.identifier);
139
137
  }
140
138
  return (this.sessionContext?.navItemRefId ??
141
139
  this._testElement?.querySelector('qti-assessment-item-ref')?.identifier);
@@ -232,7 +230,7 @@ export const TestNavigationMixin = (superClass) => {
232
230
  await this._waitForLoadingComplete(navigationId, controller);
233
231
  if (this._isStaleNavigation(navigationId, controller))
234
232
  return;
235
- this._dispatchTestLoaded(this._loadResults);
233
+ this._dispatchTestLoaded(this._loadResults, 'item', itemId);
236
234
  }
237
235
  /**
238
236
  * Navigate to section with simple state tracking
@@ -253,7 +251,7 @@ export const TestNavigationMixin = (superClass) => {
253
251
  await this._waitForLoadingComplete(navigationId, controller);
254
252
  if (this._isStaleNavigation(navigationId, controller))
255
253
  return;
256
- this._dispatchTestLoaded(this._loadResults);
254
+ this._dispatchTestLoaded(this._loadResults, 'section', sectionId);
257
255
  }
258
256
  // ===========================================
259
257
  // LOADING STATE MANAGEMENT
@@ -313,10 +311,11 @@ export const TestNavigationMixin = (superClass) => {
313
311
  console.warn('No stimulus content to apply');
314
312
  return;
315
313
  }
316
- const elements = stimulus.querySelectorAll('qti-stimulus-body, qti-stylesheet');
317
- console.info(`Found ${elements.length} stimulus elements to apply for ${element.identifier}`);
318
- if (elements.length === 0) {
319
- console.warn('No qti-stimulus-body or qti-stylesheet elements found in stimulus');
314
+ // Place the whole qti-assessment-stimulus, not just its body: its `lang` is what the stimulus
315
+ // content inherits its language from.
316
+ const root = stimulus.querySelector('qti-assessment-stimulus');
317
+ if (!root) {
318
+ console.warn('No qti-assessment-stimulus element found in stimulus');
320
319
  return;
321
320
  }
322
321
  // Try multiple target selection strategies
@@ -349,8 +348,7 @@ export const TestNavigationMixin = (superClass) => {
349
348
  // Apply content to all targets
350
349
  targets.forEach((target, index) => {
351
350
  target.innerHTML = '';
352
- const clonedElements = Array.from(elements).map(el => el.cloneNode(true));
353
- target.append(...clonedElements);
351
+ target.append(root.cloneNode(true));
354
352
  console.info(`Applied stimulus content to target ${index + 1}/${targets.length}`);
355
353
  });
356
354
  } // ===========================================
@@ -409,10 +407,8 @@ export const TestNavigationMixin = (superClass) => {
409
407
  }
410
408
  async _loadSingleItem(itemRef, navigationId, controller) {
411
409
  try {
412
- // The shuffle seed lives on QTI_CONTEXT, which is provided by the descendant
413
- // `<test-navigation>`. Since context flows downward, read it from that element
414
- // so seeded item shuffling during navigation matches `test-container`.
415
- const seed = this.querySelector('test-navigation')?.qtiContext?.QTI_CONTEXT?.seed;
410
+ // The same seed `test-container` shuffled the item order with.
411
+ const seed = this.qtiContext?.QTI_CONTEXT?.seed;
416
412
  let transformer = (await qtiTransformItem().load(itemRef.href, controller.signal)).shuffleInteractions(seed);
417
413
  if (this.postLoadTransformCallback) {
418
414
  transformer = await this.postLoadTransformCallback(transformer, itemRef);
@@ -494,11 +490,7 @@ export const TestNavigationMixin = (superClass) => {
494
490
  // EVENT DISPATCHING
495
491
  // ===========================================
496
492
  _dispatchLoadingStarted(type, id) {
497
- this.dispatchEvent(new CustomEvent('qti-navigation-loading-started', {
498
- detail: { type, id },
499
- bubbles: true,
500
- composed: true
501
- }));
493
+ dispatchPublic(this, 'cito-test-navigation-started', { type: type, id });
502
494
  }
503
495
  _dispatchLoadingEnded(type, id) {
504
496
  this.dispatchEvent(new CustomEvent('qti-navigation-loading-ended', {
@@ -508,22 +500,16 @@ export const TestNavigationMixin = (superClass) => {
508
500
  }));
509
501
  }
510
502
  _dispatchError(error) {
511
- this.dispatchEvent(new CustomEvent('qti-navigation-error', {
512
- detail: error,
513
- bubbles: true,
514
- composed: true
515
- }));
503
+ dispatchPublic(this, 'cito-test-navigation-failed', error);
516
504
  }
517
- _dispatchTestLoaded(results) {
505
+ /** The items are in the DOM: tell hosts the new position rendered (`cito-test-navigated`) and which items it holds. */
506
+ _dispatchTestLoaded(results, type, id) {
518
507
  requestAnimationFrame(() => {
519
- this.dispatchEvent(new CustomEvent('qti-test-loaded', {
520
- detail: results.map(({ itemRef }) => ({
521
- identifier: itemRef?.identifier,
522
- element: itemRef
523
- })),
524
- bubbles: true,
525
- composed: true
526
- }));
508
+ dispatchPublic(this, 'cito-test-rendered', results.map(({ itemRef }) => ({
509
+ identifier: itemRef?.identifier,
510
+ element: itemRef
511
+ })));
512
+ dispatchPublic(this, 'cito-test-navigated', { type, id });
527
513
  });
528
514
  }
529
515
  }