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

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 (44) hide show
  1. package/dist/components/qti-assessment-item-ref/qti-assessment-item-ref.js +3 -8
  2. package/dist/components/qti-assessment-item-ref/qti-assessment-item-ref.js.map +1 -1
  3. package/dist/components/test-end-attempt/test-end-attempt.js +6 -4
  4. package/dist/components/test-end-attempt/test-end-attempt.js.map +1 -1
  5. package/dist/components/test-navigation/test-navigation.js +23 -7
  6. package/dist/components/test-navigation/test-navigation.js.map +1 -1
  7. package/dist/components/test-next/test-next.js +4 -4
  8. package/dist/components/test-next/test-next.js.map +1 -1
  9. package/dist/components/test-prev/test-prev.js +4 -4
  10. package/dist/components/test-prev/test-prev.js.map +1 -1
  11. package/dist/computed-tree.d.ts +20 -0
  12. package/dist/computed-tree.js +22 -0
  13. package/dist/computed-tree.js.map +1 -0
  14. package/dist/index.d.ts +1 -1
  15. package/dist/index.js +1 -1
  16. package/dist/index.js.map +1 -1
  17. package/dist/internal/delivery-state-conversion.d.ts +15 -5
  18. package/dist/internal/delivery-state-conversion.js +36 -9
  19. package/dist/internal/delivery-state-conversion.js.map +1 -1
  20. package/dist/internal/derive-computed-context.d.ts +12 -4
  21. package/dist/internal/derive-computed-context.js +30 -21
  22. package/dist/internal/derive-computed-context.js.map +1 -1
  23. package/dist/internal/test-host.context.d.ts +2 -0
  24. package/dist/internal/test-host.context.js.map +1 -1
  25. package/dist/mixins/test-base.d.ts +2 -0
  26. package/dist/mixins/test-base.js +16 -0
  27. package/dist/mixins/test-base.js.map +1 -1
  28. package/dist/mixins/test-state.mixin.js +3 -1
  29. package/dist/mixins/test-state.mixin.js.map +1 -1
  30. package/dist/plugin-api.d.ts +1 -1
  31. package/dist/plugin-api.js +1 -1
  32. package/dist/plugin-api.js.map +1 -1
  33. package/dist/public-events.d.ts +9 -0
  34. package/dist/public-events.js +1 -0
  35. package/dist/public-events.js.map +1 -1
  36. package/dist/state-from-contexts.d.ts +1 -0
  37. package/dist/state-from-contexts.js +2 -1
  38. package/dist/state-from-contexts.js.map +1 -1
  39. package/dist/types/qti-test-state.d.ts +5 -0
  40. package/dist/types/qti-test-state.js.map +1 -1
  41. package/package.json +3 -3
  42. package/dist/items-in-order.d.ts +0 -9
  43. package/dist/items-in-order.js +0 -15
  44. package/dist/items-in-order.js.map +0 -1
@@ -109,8 +109,10 @@ export const TestStateMixin = (superClass) => {
109
109
  #apply(state) {
110
110
  // Before the items load this only fills the test context; items already on screen are
111
111
  // updated too.
112
- for (const saved of state.test.items)
112
+ for (const saved of state.test.items) {
113
113
  this.updateItemVariables(saved.identifier, saved.variables, saved.state);
114
+ this.updateItemComment(saved.identifier, typeof saved.comment === 'string' ? saved.comment : null);
115
+ }
114
116
  this.#warnLeftOut(state);
115
117
  const savedOutcomes = new Map(state.test.outcomes.map(outcome => [outcome.identifier, outcome.value]));
116
118
  this.testContext = {
@@ -1 +1 @@
1
- {"version":3,"file":"test-state.mixin.js","sourceRoot":"","sources":["../../src/mixins/test-state.mixin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChE,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AA+B3D,MAAM,IAAI,GAAG,CAAC,KAAkC,EAAS,EAAE,CACzD,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAE,KAAmC,IAAI,IAAI,CAAC,CAAC;AAErF,MAAM,cAAc,GAAG,CAAC,KAAc,EAAyB,EAAE;IAC/D,MAAM,KAAK,GAAG,KAA4B,CAAC;IAC3C,OAAO,CACL,KAAK,EAAE,OAAO,KAAK,sBAAsB;QACzC,KAAK,CAAC,OAAO,CAA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Y,CAAC,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,OAAO,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;gBACzG,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,UAAU,KAAK,OAAO,CAAC,YAAY,CAAC;oBACzE,CAAC,CAAC,EAAE,YAAY,EAAE,OAAO,CAAC,YAAY,EAAE;oBACxC,CAAC,CAAC,EAAE,CAAC;aACR,CAAC;QACJ,CAAC;QAED,kBAAkB,CAAC,IAAwB,EAAE,EAAU;YACrD,cAAc,CAAC,IAAI,EAAE,kBAAkB,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC;QACzD,CAAC;KACF;IAED,OAAO,cAAkD,CAAC;AAC5D,CAAC,CAAC","sourcesContent":["import { QTI_TEST_STATE_VERSION } from '../types/qti-test-state';\nimport { dispatchPublic, listenPublic } from '../public-events';\nimport { stateFromContexts } from '../state-from-contexts';\n\nimport type { PropertyValues } from 'lit';\nimport type { StateRefusal } from '../public-events';\nimport type { QtiTestState, QtiTestStateSession } from '../types/qti-test-state';\nimport type { TestBaseInterface } from './test-base';\n\ntype Constructor<T = {}> = abstract new (...args: any[]) => T;\ntype Value = string | string[] | null;\n\nexport interface ITestStateMixin {\n /**\n * The candidate's persistable state: what they answered and where they are.\n *\n * Assign a stored state to resume. It may be assigned at any time: before the test document\n * has loaded it is held and applied as soon as the test connects — before the first item\n * loads, so items and the initial navigation start from it — and after that it is applied\n * immediately and the test navigates to the restored position.\n *\n * Items are matched by item-ref identifier; items the state does not mention start fresh, and\n * stored items, test outcomes or a position the test no longer has are ignored. Restoring is a\n * resume, so linear-mode navigation restrictions do not apply.\n *\n * A value that is not a version 1 `QtiTestState` is ignored and reported with\n * `qc-test-state-refused`: at once when the test has loaded, or when it does if it was assigned\n * before. A state assigned earlier that could be read stays in effect. A stored 9.x\n * `testContext` is turned into a state with `stateFromContexts`.\n */\n state: QtiTestState;\n}\n\nconst copy = (value: Readonly<Value> | undefined): Value =>\n Array.isArray(value) ? [...value] : ((value as string | null | undefined) ?? null);\n\nconst isQtiTestState = (value: unknown): value is QtiTestState => {\n const state = value as QtiTestState | null;\n return (\n state?.version === QTI_TEST_STATE_VERSION &&\n Array.isArray(state.test?.items) &&\n Array.isArray(state.test?.outcomes) &&\n typeof state.session === 'object' &&\n state.session !== null\n );\n};\n\n/**\n * Persist and resume a test session through one value, `state`, and one event,\n * `qc-test-state-changed`.\n *\n * Sits directly on top of `TestBaseMixin`, so its `qc-test-loaded` listener runs\n * after the base has built `testContext.items` from the item-refs, and before the navigation\n * mixin's listener picks the first item to load.\n */\nexport const TestStateMixin = <T extends Constructor<TestBaseInterface>>(superClass: T) => {\n abstract class TestStateClass extends superClass implements ITestStateMixin {\n /** A state assigned before the test connected, applied when it does. */\n #pending: QtiTestState | null = null;\n\n /** A refused state assigned before the test connected, reported when it does. */\n #refused: StateRefusal | null = null;\n\n /**\n * False while a test document is loading. Loading resets both contexts and rebuilds them, so\n * the intermediate states are empty — emitting one would invite a host to save it over the\n * real one.\n */\n #ready = false;\n\n #lastEmitted: string | null = null;\n\n constructor(...args: any[]) {\n super(...args);\n this.addEventListener('qti-testdoc-loaded', () => {\n this.#ready = false;\n this.#lastEmitted = null;\n });\n listenPublic(this, 'qc-test-update-plugin-state', ({ detail }) => this.#updatePluginState(detail));\n listenPublic(this, 'qc-test-loaded', () => {\n if (this.#pending) {\n this.#apply(this.#pending);\n this.#pending = null;\n }\n this.#ready = true;\n if (this.#refused) {\n dispatchPublic(this, 'qc-test-state-refused', this.#refused);\n this.#refused = null;\n }\n });\n }\n\n /** One plugin's entry, as JSON: the test stores it without reading it. `null` removes it. */\n #updatePluginState({ plugin, value }: { plugin: string; value: unknown }): void {\n if (typeof plugin !== 'string' || plugin === '') return;\n const { [plugin]: _removed, ...others } = this.sessionContext.plugins ?? {};\n let next: Record<string, unknown> = others;\n if (value !== null && value !== undefined) {\n try {\n next = { ...others, [plugin]: JSON.parse(JSON.stringify(value)) };\n } catch {\n console.warn(`[qti-test] Ignoring plugin state for \"${plugin}\": it is not JSON.`);\n return;\n }\n }\n this.sessionContext = { ...this.sessionContext, plugins: next };\n }\n\n get state(): QtiTestState {\n return stateFromContexts(this.testContext, this.sessionContext);\n }\n\n set state(value: QtiTestState) {\n if (!isQtiTestState(value)) {\n const message = `Ignoring a state that is not a version ${QTI_TEST_STATE_VERSION} QtiTestState.`;\n console.warn(`[qti-test] ${message}`);\n // Hosts assign state before the test is in the page, where an event reaches no listener.\n if (this.#ready) dispatchPublic(this, 'qc-test-state-refused', { message, state: value });\n else this.#refused = { message, state: value };\n return;\n }\n if (!this.#ready) {\n this.#pending = value;\n return;\n }\n\n const { navItemRefId, navSectionId } = this.sessionContext;\n this.#apply(value);\n\n const restored = this.sessionContext;\n if (restored.navItemRefId && restored.navItemRefId !== navItemRefId) {\n this.#requestNavigation('item', restored.navItemRefId);\n } else if (!restored.navItemRefId && restored.navSectionId && restored.navSectionId !== navSectionId) {\n this.#requestNavigation('section', restored.navSectionId);\n }\n }\n\n protected override updated(changed: PropertyValues): void {\n super.updated(changed);\n if (!this.#ready || !(changed.has('testContext') || changed.has('sessionContext'))) return;\n\n const state = this.state;\n const serialized = JSON.stringify(state);\n if (serialized === this.#lastEmitted) return;\n this.#lastEmitted = serialized;\n dispatchPublic(this, 'qc-test-state-changed', state);\n }\n\n #apply(state: QtiTestState): void {\n // Before the items load this only fills the test context; items already on screen are\n // updated too.\n for (const saved of state.test.items) this.updateItemVariables(saved.identifier, saved.variables, saved.state);\n this.#warnLeftOut(state);\n\n const savedOutcomes = new Map(state.test.outcomes.map(outcome => [outcome.identifier, outcome.value]));\n this.testContext = {\n ...this.testContext,\n testOutcomeVariables: this.testContext.testOutcomeVariables?.map(v =>\n savedOutcomes.has(v.identifier) ? { ...v, value: copy(savedOutcomes.get(v.identifier)) } : v\n )\n };\n\n // Written before any navigation request, so the linear-mode restriction — which compares\n // against the current position — sees the restored item as current and lets it load.\n // Plugins are replaced, not merged: a state without them clears what an earlier one left.\n this.sessionContext = {\n ...this.sessionContext,\n ...this.#validSession(state.session),\n plugins: state.session.plugins && typeof state.session.plugins === 'object' ? { ...state.session.plugins } : {}\n };\n }\n\n /**\n * Answers for items this test does not present are not restored, and the next state leaves them\n * out: a selection (`qti-selection`) that leaves an item out, or a revised test. Said, not silent\n * (roadmap 1 T4, `plans/host-api.md` → Decided).\n */\n #warnLeftOut(state: QtiTestState): void {\n const presented = new Set(this.testContext.items.map(item => item.identifier));\n const leftOut = state.test.items.map(item => item.identifier).filter(identifier => !presented.has(identifier));\n if (leftOut.length === 0) return;\n console.warn(\n `[qti-test] The state has answers for items this test does not present (not selected, or no longer in it); they are not restored: ${leftOut.join(', ')}.`\n );\n }\n\n /** A stored position may point at an item or section a revised test no longer has. */\n #validSession(session: QtiTestStateSession): QtiTestStateSession {\n const exists = (selector: string, id: string | null | undefined) =>\n !!id && !!this._testElement?.querySelector(`${selector}[identifier=\"${CSS.escape(id)}\"]`);\n return {\n ...(exists('qti-test-part', session.navPartId) ? { navPartId: session.navPartId } : {}),\n ...(exists('qti-assessment-section', session.navSectionId) ? { navSectionId: session.navSectionId } : {}),\n ...(this.testContext.items.some(i => i.identifier === session.navItemRefId)\n ? { navItemRefId: session.navItemRefId }\n : {})\n };\n }\n\n #requestNavigation(type: 'item' | 'section', id: string): void {\n dispatchPublic(this, 'qc-test-navigate', { type, id });\n }\n }\n\n return TestStateClass as Constructor<ITestStateMixin> & T;\n};\n"]}
1
+ {"version":3,"file":"test-state.mixin.js","sourceRoot":"","sources":["../../src/mixins/test-state.mixin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChE,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AA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C,IAAI,CAAC,IAAI,CAAC,GAAG,CAC1J,CAAC;QACJ,CAAC;QAED,sFAAsF;QACtF,aAAa,CAAC,OAA4B;YACxC,MAAM,MAAM,GAAG,CAAC,QAAgB,EAAE,EAA6B,EAAE,EAAE,CACjE,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,IAAI,CAAC,YAAY,EAAE,aAAa,CAAC,GAAG,QAAQ,gBAAgB,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC;YAC5F,OAAO;gBACL,GAAG,CAAC,MAAM,CAAC,eAAe,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,OAAO,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;gBACvF,GAAG,CAAC,MAAM,CAAC,wBAAwB,EAAE,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,OAAO,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;gBACzG,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,UAAU,KAAK,OAAO,CAAC,YAAY,CAAC;oBACzE,CAAC,CAAC,EAAE,YAAY,EAAE,OAAO,CAAC,YAAY,EAAE;oBACxC,CAAC,CAAC,EAAE,CAAC;aACR,CAAC;QACJ,CAAC;QAED,kBAAkB,CAAC,IAAwB,EAAE,EAAU;YACrD,cAAc,CAAC,IAAI,EAAE,kBAAkB,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC;QACzD,CAAC;KACF;IAED,OAAO,cAAkD,CAAC;AAC5D,CAAC,CAAC","sourcesContent":["import { QTI_TEST_STATE_VERSION } from '../types/qti-test-state';\nimport { dispatchPublic, listenPublic } from '../public-events';\nimport { stateFromContexts } from '../state-from-contexts';\n\nimport type { PropertyValues } from 'lit';\nimport type { StateRefusal } from '../public-events';\nimport type { QtiTestState, QtiTestStateSession } from '../types/qti-test-state';\nimport type { TestBaseInterface } from './test-base';\n\ntype Constructor<T = {}> = abstract new (...args: any[]) => T;\ntype Value = string | string[] | null;\n\nexport interface ITestStateMixin {\n /**\n * The candidate's persistable state: what they answered and where they are.\n *\n * Assign a stored state to resume. It may be assigned at any time: before the test document\n * has loaded it is held and applied as soon as the test connects — before the first item\n * loads, so items and the initial navigation start from it — and after that it is applied\n * immediately and the test navigates to the restored position.\n *\n * Items are matched by item-ref identifier; items the state does not mention start fresh, and\n * stored items, test outcomes or a position the test no longer has are ignored. Restoring is a\n * resume, so linear-mode navigation restrictions do not apply.\n *\n * A value that is not a version 1 `QtiTestState` is ignored and reported with\n * `qc-test-state-refused`: at once when the test has loaded, or when it does if it was assigned\n * before. A state assigned earlier that could be read stays in effect. A stored 9.x\n * `testContext` is turned into a state with `stateFromContexts`.\n */\n state: QtiTestState;\n}\n\nconst copy = (value: Readonly<Value> | undefined): Value =>\n Array.isArray(value) ? [...value] : ((value as string | null | undefined) ?? null);\n\nconst isQtiTestState = (value: unknown): value is QtiTestState => {\n const state = value as QtiTestState | null;\n return (\n state?.version === QTI_TEST_STATE_VERSION &&\n Array.isArray(state.test?.items) &&\n Array.isArray(state.test?.outcomes) &&\n typeof state.session === 'object' &&\n state.session !== null\n );\n};\n\n/**\n * Persist and resume a test session through one value, `state`, and one event,\n * `qc-test-state-changed`.\n *\n * Sits directly on top of `TestBaseMixin`, so its `qc-test-loaded` listener runs\n * after the base has built `testContext.items` from the item-refs, and before the navigation\n * mixin's listener picks the first item to load.\n */\nexport const TestStateMixin = <T extends Constructor<TestBaseInterface>>(superClass: T) => {\n abstract class TestStateClass extends superClass implements ITestStateMixin {\n /** A state assigned before the test connected, applied when it does. */\n #pending: QtiTestState | null = null;\n\n /** A refused state assigned before the test connected, reported when it does. */\n #refused: StateRefusal | null = null;\n\n /**\n * False while a test document is loading. Loading resets both contexts and rebuilds them, so\n * the intermediate states are empty — emitting one would invite a host to save it over the\n * real one.\n */\n #ready = false;\n\n #lastEmitted: string | null = null;\n\n constructor(...args: any[]) {\n super(...args);\n this.addEventListener('qti-testdoc-loaded', () => {\n this.#ready = false;\n this.#lastEmitted = null;\n });\n listenPublic(this, 'qc-test-update-plugin-state', ({ detail }) => this.#updatePluginState(detail));\n listenPublic(this, 'qc-test-loaded', () => {\n if (this.#pending) {\n this.#apply(this.#pending);\n this.#pending = null;\n }\n this.#ready = true;\n if (this.#refused) {\n dispatchPublic(this, 'qc-test-state-refused', this.#refused);\n this.#refused = null;\n }\n });\n }\n\n /** One plugin's entry, as JSON: the test stores it without reading it. `null` removes it. */\n #updatePluginState({ plugin, value }: { plugin: string; value: unknown }): void {\n if (typeof plugin !== 'string' || plugin === '') return;\n const { [plugin]: _removed, ...others } = this.sessionContext.plugins ?? {};\n let next: Record<string, unknown> = others;\n if (value !== null && value !== undefined) {\n try {\n next = { ...others, [plugin]: JSON.parse(JSON.stringify(value)) };\n } catch {\n console.warn(`[qti-test] Ignoring plugin state for \"${plugin}\": it is not JSON.`);\n return;\n }\n }\n this.sessionContext = { ...this.sessionContext, plugins: next };\n }\n\n get state(): QtiTestState {\n return stateFromContexts(this.testContext, this.sessionContext);\n }\n\n set state(value: QtiTestState) {\n if (!isQtiTestState(value)) {\n const message = `Ignoring a state that is not a version ${QTI_TEST_STATE_VERSION} QtiTestState.`;\n console.warn(`[qti-test] ${message}`);\n // Hosts assign state before the test is in the page, where an event reaches no listener.\n if (this.#ready) dispatchPublic(this, 'qc-test-state-refused', { message, state: value });\n else this.#refused = { message, state: value };\n return;\n }\n if (!this.#ready) {\n this.#pending = value;\n return;\n }\n\n const { navItemRefId, navSectionId } = this.sessionContext;\n this.#apply(value);\n\n const restored = this.sessionContext;\n if (restored.navItemRefId && restored.navItemRefId !== navItemRefId) {\n this.#requestNavigation('item', restored.navItemRefId);\n } else if (!restored.navItemRefId && restored.navSectionId && restored.navSectionId !== navSectionId) {\n this.#requestNavigation('section', restored.navSectionId);\n }\n }\n\n protected override updated(changed: PropertyValues): void {\n super.updated(changed);\n if (!this.#ready || !(changed.has('testContext') || changed.has('sessionContext'))) return;\n\n const state = this.state;\n const serialized = JSON.stringify(state);\n if (serialized === this.#lastEmitted) return;\n this.#lastEmitted = serialized;\n dispatchPublic(this, 'qc-test-state-changed', state);\n }\n\n #apply(state: QtiTestState): void {\n // Before the items load this only fills the test context; items already on screen are\n // updated too.\n for (const saved of state.test.items) {\n this.updateItemVariables(saved.identifier, saved.variables, saved.state);\n this.updateItemComment(saved.identifier, typeof saved.comment === 'string' ? saved.comment : null);\n }\n this.#warnLeftOut(state);\n\n const savedOutcomes = new Map(state.test.outcomes.map(outcome => [outcome.identifier, outcome.value]));\n this.testContext = {\n ...this.testContext,\n testOutcomeVariables: this.testContext.testOutcomeVariables?.map(v =>\n savedOutcomes.has(v.identifier) ? { ...v, value: copy(savedOutcomes.get(v.identifier)) } : v\n )\n };\n\n // Written before any navigation request, so the linear-mode restriction — which compares\n // against the current position — sees the restored item as current and lets it load.\n // Plugins are replaced, not merged: a state without them clears what an earlier one left.\n this.sessionContext = {\n ...this.sessionContext,\n ...this.#validSession(state.session),\n plugins: state.session.plugins && typeof state.session.plugins === 'object' ? { ...state.session.plugins } : {}\n };\n }\n\n /**\n * Answers for items this test does not present are not restored, and the next state leaves them\n * out: a selection (`qti-selection`) that leaves an item out, or a revised test. Said, not silent\n * (roadmap 1 T4, `plans/host-api.md` → Decided).\n */\n #warnLeftOut(state: QtiTestState): void {\n const presented = new Set(this.testContext.items.map(item => item.identifier));\n const leftOut = state.test.items.map(item => item.identifier).filter(identifier => !presented.has(identifier));\n if (leftOut.length === 0) return;\n console.warn(\n `[qti-test] The state has answers for items this test does not present (not selected, or no longer in it); they are not restored: ${leftOut.join(', ')}.`\n );\n }\n\n /** A stored position may point at an item or section a revised test no longer has. */\n #validSession(session: QtiTestStateSession): QtiTestStateSession {\n const exists = (selector: string, id: string | null | undefined) =>\n !!id && !!this._testElement?.querySelector(`${selector}[identifier=\"${CSS.escape(id)}\"]`);\n return {\n ...(exists('qti-test-part', session.navPartId) ? { navPartId: session.navPartId } : {}),\n ...(exists('qti-assessment-section', session.navSectionId) ? { navSectionId: session.navSectionId } : {}),\n ...(this.testContext.items.some(i => i.identifier === session.navItemRefId)\n ? { navItemRefId: session.navItemRefId }\n : {})\n };\n }\n\n #requestNavigation(type: 'item' | 'section', id: string): void {\n dispatchPublic(this, 'qc-test-navigate', { type, id });\n }\n }\n\n return TestStateClass as Constructor<ITestStateMixin> & T;\n};\n"]}
@@ -6,6 +6,6 @@
6
6
  export { dispatchPublic, listenPublic, PUBLIC_EVENTS } from './public-events.js';
7
7
  export type { NavigationFailure, NavigationTarget, PublicEventMap, PublicEventName, StateRefusal } from './public-events.js';
8
8
  export { pluginState } from './plugin-state.js';
9
- export { itemsInOrder } from './items-in-order.js';
9
+ export { activeItem, activeSection, activeTestPart, itemsInOrder, sectionsInOrder } from './computed-tree.js';
10
10
  export type { QtiTestPluginState, QtiTestState } from './types/qti-test-state.js';
11
11
  export * as controlStyles from './components/styles.js';
@@ -5,6 +5,6 @@
5
5
  */
6
6
  export { dispatchPublic, listenPublic, PUBLIC_EVENTS } from './public-events.js';
7
7
  export { pluginState } from './plugin-state.js';
8
- export { itemsInOrder } from './items-in-order.js';
8
+ export { activeItem, activeSection, activeTestPart, itemsInOrder, sectionsInOrder } from './computed-tree.js';
9
9
  export * as controlStyles from './components/styles.js';
10
10
  //# sourceMappingURL=plugin-api.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"plugin-api.js","sourceRoot":"","sources":["../src/plugin-api.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAQjF,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEnD,OAAO,KAAK,aAAa,MAAM,wBAAwB,CAAC","sourcesContent":["/**\n * What a plugin in another package builds on, with no registration side effect: the public events\n * and their helpers, the typed read of plugin state, the state types, and the look of the test\n * controls. `@qti-components/extended` is the consumer; a plugin of your own may use it too.\n */\nexport { dispatchPublic, listenPublic, PUBLIC_EVENTS } from './public-events.js';\nexport type {\n NavigationFailure,\n NavigationTarget,\n PublicEventMap,\n PublicEventName,\n StateRefusal\n} from './public-events.js';\nexport { pluginState } from './plugin-state.js';\nexport { itemsInOrder } from './items-in-order.js';\nexport type { QtiTestPluginState, QtiTestState } from './types/qti-test-state.js';\nexport * as controlStyles from './components/styles.js';\n"]}
1
+ {"version":3,"file":"plugin-api.js","sourceRoot":"","sources":["../src/plugin-api.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAQjF,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,cAAc,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAE9G,OAAO,KAAK,aAAa,MAAM,wBAAwB,CAAC","sourcesContent":["/**\n * What a plugin in another package builds on, with no registration side effect: the public events\n * and their helpers, the typed read of plugin state, the state types, and the look of the test\n * controls. `@qti-components/extended` is the consumer; a plugin of your own may use it too.\n */\nexport { dispatchPublic, listenPublic, PUBLIC_EVENTS } from './public-events.js';\nexport type {\n NavigationFailure,\n NavigationTarget,\n PublicEventMap,\n PublicEventName,\n StateRefusal\n} from './public-events.js';\nexport { pluginState } from './plugin-state.js';\nexport { activeItem, activeSection, activeTestPart, itemsInOrder, sectionsInOrder } from './computed-tree.js';\nexport type { QtiTestPluginState, QtiTestState } from './types/qti-test-state.js';\nexport * as controlStyles from './components/styles.js';\n"]}
@@ -52,6 +52,15 @@ export interface PublicEventMap {
52
52
  plugin: string;
53
53
  value: unknown;
54
54
  }>;
55
+ /**
56
+ * Sets the candidate's comment on the item-ref `itemId` (`null` clears it), kept in the item's
57
+ * state and in `QtiTestState`. Refused, with a warning, unless the item's `allow-comment` allows
58
+ * it and its session is interacting (`rules.mayComment`). Send it from inside `<test-navigation>`.
59
+ */
60
+ 'qc-test-update-comment': CustomEvent<{
61
+ itemId: string;
62
+ comment: string | null;
63
+ }>;
55
64
  /** Outcome processing ran after a submit: read the test outcomes now. */
56
65
  'qc-test-submitted': CustomEvent<Record<string, never>>;
57
66
  'qc-test-navigated': CustomEvent<NavigationTarget>;
@@ -5,6 +5,7 @@ export const PUBLIC_EVENTS = {
5
5
  'qc-test-submit': { kind: 'request', scope: 'test', deprecated: 'cito-test-submit' },
6
6
  'qc-test-update-outcome': { kind: 'request', scope: 'test', deprecated: 'cito-test-update-outcome' },
7
7
  'qc-test-update-plugin-state': { kind: 'request', scope: 'test', deprecated: 'cito-test-update-plugin-state' },
8
+ 'qc-test-update-comment': { kind: 'request', scope: 'test' },
8
9
  'qc-test-switch-view': { kind: 'request', scope: 'test', deprecated: 'cito-test-switch-view' },
9
10
  'qc-test-submitted': { kind: 'notification', scope: 'test', deprecated: 'cito-test-submitted' },
10
11
  'qc-test-navigated': { kind: 'notification', scope: 'test', deprecated: 'cito-test-navigated' },
@@ -1 +1 @@
1
- {"version":3,"file":"public-events.js","sourceRoot":"","sources":["../src/public-events.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,wCAAwC,CAAC;AAyE1F,MAAM,CAAC,MAAM,aAAa,GAAoD;IAC5E,kBAAkB,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,oBAAoB,EAAE;IACxF,qBAAqB,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,uBAAuB,EAAE;IAC9F,gBAAgB,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK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,EAAE,yBAAyB,EAAE;IACvG,qBAAqB,EAAE,EAAE,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,uBAAuB,EAAE;IACnG,uBAAuB,EAAE,EAAE,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,yBAAyB,EAAE;CACxG,CAAC;AAMF;;;GAGG;AACH,MAAM,UAAU,cAAc,CAC5B,MAAmB,EACnB,IAAO,EACP,MAAkE;IAElE,gBAAgB,CAAC,MAAM,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;AACxD,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,YAAY,CAC1B,MAAmB,EACnB,IAAO,EACP,OAAuC;IAEvC,cAAc,CAAC,MAAM,EAAE,aAAa,EAAE,IAAI,EAAE,OAA6B,CAAC,CAAC;AAC7E,CAAC","sourcesContent":["import { dispatchDeclared, listenDeclared } from '@qti-components/elements/public-events';\n\nimport type { View } from '@qti-components/base';\nimport type { PublicEventDeclaration } from '@qti-components/elements/public-events';\nimport type { QtiTestState } from './types/qti-test-state';\n\n/**\n * The public events of the test. The name tells you it is public: everything here starts with\n * `qc-`; every other event is internal plumbing and may change in any release.\n *\n * Requests are verbs (a host or plugin dispatches them at the test), notifications are past tense\n * (the test dispatches them). All bubble and are composed.\n *\n * `deprecated` is the `cito-` name this event had in 9.x; an event new in 10.0 has none. One helper\n * (`dispatchPublic`, `listenPublic`) sends or handles both names until the next major, then the field\n * goes. The 7.x names (`qti-request-navigation`, `test-end-attempt`, `on-test-switch-view`, …) are no\n * longer sent or handled.\n */\nexport interface NavigationTarget {\n type: 'item' | 'section';\n id: string;\n}\n\nexport interface NavigationFailure {\n message: string;\n details?: unknown;\n itemId?: string;\n sectionId?: string;\n}\n\n/** The detail of `qc-test-state-refused`. */\nexport interface StateRefusal {\n /** Why the state was not read. */\n message: string;\n /** The value that was assigned to `state`, as given. */\n state: unknown;\n}\n\nexport interface PublicEventMap {\n 'qc-test-navigate': CustomEvent<NavigationTarget>;\n /**\n * Ends an attempt: processes the response of the item-ref `itemId`, or, without it, of the item on\n * screen. `<test-end-attempt>` sends the `itemId` of the item it is stamped into or names.\n */\n 'qc-test-end-attempt': CustomEvent<{ itemId?: string }>;\n /** Scores the test: resets its outcomes to their defaults, runs outcome processing, then `qc-test-submitted`. */\n 'qc-test-submit': CustomEvent<Record<string, never>>;\n 'qc-test-update-outcome': CustomEvent<{\n assessmentItemRefId: string;\n outcomeVariableId: string;\n value: number | string;\n }>;\n 'qc-test-switch-view': CustomEvent<View>;\n /** `value` is JSON; `null` or `undefined` removes the plugin's entry. */\n 'qc-test-update-plugin-state': CustomEvent<{ plugin: string; value: unknown }>;\n /** Outcome processing ran after a submit: read the test outcomes now. */\n 'qc-test-submitted': CustomEvent<Record<string, never>>;\n 'qc-test-navigated': CustomEvent<NavigationTarget>;\n 'qc-test-navigation-started': CustomEvent<NavigationTarget>;\n 'qc-test-navigation-failed': CustomEvent<NavigationFailure>;\n 'qc-test-rendered': CustomEvent<{ identifier: string; element: Element }[]>;\n // `qc-test-loaded` (detail: the `QtiAssessmentTest`) is added by qti-assessment-test.ts, so this\n // module imports no element: that import would be a cycle.\n 'qc-test-state-changed': CustomEvent<QtiTestState>;\n /** A value assigned to `state` could not be read and was ignored: the test goes on without it. */\n 'qc-test-state-refused': CustomEvent<StateRefusal>;\n 'qc-test-items-skipped': CustomEvent<{ ids: string[] }>;\n 'qc-test-end-reached': CustomEvent<Record<string, never>>;\n 'qc-item-ref-connected': CustomEvent<{ identifier: string; href: string; category: string }>;\n}\n\nexport type PublicEventName = keyof PublicEventMap;\n\nexport const PUBLIC_EVENTS: Record<PublicEventName, PublicEventDeclaration> = {\n 'qc-test-navigate': { kind: 'request', scope: 'test', deprecated: 'cito-test-navigate' },\n 'qc-test-end-attempt': { kind: 'request', scope: 'test', deprecated: 'cito-test-end-attempt' },\n 'qc-test-submit': { kind: 'request', scope: 'test', deprecated: 'cito-test-submit' },\n 'qc-test-update-outcome': { kind: 'request', scope: 'test', deprecated: 'cito-test-update-outcome' },\n 'qc-test-update-plugin-state': { kind: 'request', scope: 'test', deprecated: 'cito-test-update-plugin-state' },\n 'qc-test-switch-view': { kind: 'request', scope: 'test', deprecated: 'cito-test-switch-view' },\n 'qc-test-submitted': { kind: 'notification', scope: 'test', deprecated: 'cito-test-submitted' },\n 'qc-test-navigated': { kind: 'notification', scope: 'test', deprecated: 'cito-test-navigated' },\n 'qc-test-navigation-started': { kind: 'notification', scope: 'test', deprecated: 'cito-test-navigation-started' },\n 'qc-test-navigation-failed': { kind: 'notification', scope: 'test', deprecated: 'cito-test-navigation-failed' },\n 'qc-test-rendered': { kind: 'notification', scope: 'test', deprecated: 'cito-test-rendered' },\n 'qc-test-loaded': { kind: 'notification', scope: 'test', deprecated: 'cito-test-loaded' },\n 'qc-test-state-changed': { kind: 'notification', scope: 'test', deprecated: 'cito-test-state-changed' },\n // New in 10.0, so it has no cito- name.\n 'qc-test-state-refused': { kind: 'notification', scope: 'test' },\n 'qc-test-items-skipped': { kind: 'notification', scope: 'test', deprecated: 'cito-test-items-skipped' },\n 'qc-test-end-reached': { kind: 'notification', scope: 'test', deprecated: 'cito-test-end-reached' },\n 'qc-item-ref-connected': { kind: 'notification', scope: 'item', deprecated: 'cito-item-ref-connected' }\n};\n\ndeclare global {\n interface HTMLElementEventMap extends PublicEventMap {}\n}\n\n/**\n * Dispatch a public event, and its deprecated name with the same `detail` object. The detail is\n * always an object so `listenPublic` can tell the two apart from one dispatch.\n */\nexport function dispatchPublic<K extends PublicEventName>(\n target: EventTarget,\n name: K,\n detail: PublicEventMap[K] extends CustomEvent<infer D> ? D : never\n): void {\n dispatchDeclared(target, PUBLIC_EVENTS, name, detail);\n}\n\n/**\n * Listen for a public event and its deprecated name; the handler runs once for a sender that\n * dispatched both. See `listenDeclared`.\n */\nexport function listenPublic<K extends PublicEventName>(\n target: EventTarget,\n name: K,\n handler: (e: PublicEventMap[K]) => void\n): void {\n listenDeclared(target, PUBLIC_EVENTS, name, handler as (e: Event) => void);\n}\n"]}
1
+ {"version":3,"file":"public-events.js","sourceRoot":"","sources":["../src/public-events.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,wCAAwC,CAAC;AA+E1F,MAAM,CAAC,MAAM,aAAa,GAAoD;IAC5E,kBAAkB,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,oBAAoB,EAAE;IACxF,qBAAqB,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,uBAAuB,EAAE;IAC9F,gBAAgB,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,kBAAkB,EAAE;IACpF,wBAAwB,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,0BAA0B,EAAE;IACpG,6BAA6B,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,+BAA+B,EAAE;IAC9G,wBAAwB,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE;IAC5D,qBAAqB,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,uBAAuB,EAAE;IAC9F,mBAAmB,EAAE,EAAE,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,qBAAqB,EAAE;IAC/F,mBAAmB,EAAE,EAAE,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,qBAAqB,EAAE;IAC/F,4BAA4B,EAAE,EAAE,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,8BAA8B,EAAE;IACjH,2BAA2B,EAAE,EAAE,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,6BAA6B,EAAE;IAC/G,kBAAkB,EAAE,EAAE,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,oBAAoB,EAAE;IAC7F,gBAAgB,EAAE,EAAE,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,kBAAkB,EAAE;IACzF,uBAAuB,EAAE,EAAE,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,yBAAyB,EAAE;IACvG,wCAAwC;IACxC,uBAAuB,EAAE,EAAE,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,EAAE;IAChE,uBAAuB,EAAE,EAAE,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,yBAAyB,EAAE;IACvG,qBAAqB,EAAE,EAAE,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,uBAAuB,EAAE;IACnG,uBAAuB,EAAE,EAAE,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,yBAAyB,EAAE;CACxG,CAAC;AAMF;;;GAGG;AACH,MAAM,UAAU,cAAc,CAC5B,MAAmB,EACnB,IAAO,EACP,MAAkE;IAElE,gBAAgB,CAAC,MAAM,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;AACxD,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,YAAY,CAC1B,MAAmB,EACnB,IAAO,EACP,OAAuC;IAEvC,cAAc,CAAC,MAAM,EAAE,aAAa,EAAE,IAAI,EAAE,OAA6B,CAAC,CAAC;AAC7E,CAAC","sourcesContent":["import { dispatchDeclared, listenDeclared } from '@qti-components/elements/public-events';\n\nimport type { View } from '@qti-components/base';\nimport type { PublicEventDeclaration } from '@qti-components/elements/public-events';\nimport type { QtiTestState } from './types/qti-test-state';\n\n/**\n * The public events of the test. The name tells you it is public: everything here starts with\n * `qc-`; every other event is internal plumbing and may change in any release.\n *\n * Requests are verbs (a host or plugin dispatches them at the test), notifications are past tense\n * (the test dispatches them). All bubble and are composed.\n *\n * `deprecated` is the `cito-` name this event had in 9.x; an event new in 10.0 has none. One helper\n * (`dispatchPublic`, `listenPublic`) sends or handles both names until the next major, then the field\n * goes. The 7.x names (`qti-request-navigation`, `test-end-attempt`, `on-test-switch-view`, …) are no\n * longer sent or handled.\n */\nexport interface NavigationTarget {\n type: 'item' | 'section';\n id: string;\n}\n\nexport interface NavigationFailure {\n message: string;\n details?: unknown;\n itemId?: string;\n sectionId?: string;\n}\n\n/** The detail of `qc-test-state-refused`. */\nexport interface StateRefusal {\n /** Why the state was not read. */\n message: string;\n /** The value that was assigned to `state`, as given. */\n state: unknown;\n}\n\nexport interface PublicEventMap {\n 'qc-test-navigate': CustomEvent<NavigationTarget>;\n /**\n * Ends an attempt: processes the response of the item-ref `itemId`, or, without it, of the item on\n * screen. `<test-end-attempt>` sends the `itemId` of the item it is stamped into or names.\n */\n 'qc-test-end-attempt': CustomEvent<{ itemId?: string }>;\n /** Scores the test: resets its outcomes to their defaults, runs outcome processing, then `qc-test-submitted`. */\n 'qc-test-submit': CustomEvent<Record<string, never>>;\n 'qc-test-update-outcome': CustomEvent<{\n assessmentItemRefId: string;\n outcomeVariableId: string;\n value: number | string;\n }>;\n 'qc-test-switch-view': CustomEvent<View>;\n /** `value` is JSON; `null` or `undefined` removes the plugin's entry. */\n 'qc-test-update-plugin-state': CustomEvent<{ plugin: string; value: unknown }>;\n /**\n * Sets the candidate's comment on the item-ref `itemId` (`null` clears it), kept in the item's\n * state and in `QtiTestState`. Refused, with a warning, unless the item's `allow-comment` allows\n * it and its session is interacting (`rules.mayComment`). Send it from inside `<test-navigation>`.\n */\n 'qc-test-update-comment': CustomEvent<{ itemId: string; comment: string | null }>;\n /** Outcome processing ran after a submit: read the test outcomes now. */\n 'qc-test-submitted': CustomEvent<Record<string, never>>;\n 'qc-test-navigated': CustomEvent<NavigationTarget>;\n 'qc-test-navigation-started': CustomEvent<NavigationTarget>;\n 'qc-test-navigation-failed': CustomEvent<NavigationFailure>;\n 'qc-test-rendered': CustomEvent<{ identifier: string; element: Element }[]>;\n // `qc-test-loaded` (detail: the `QtiAssessmentTest`) is added by qti-assessment-test.ts, so this\n // module imports no element: that import would be a cycle.\n 'qc-test-state-changed': CustomEvent<QtiTestState>;\n /** A value assigned to `state` could not be read and was ignored: the test goes on without it. */\n 'qc-test-state-refused': CustomEvent<StateRefusal>;\n 'qc-test-items-skipped': CustomEvent<{ ids: string[] }>;\n 'qc-test-end-reached': CustomEvent<Record<string, never>>;\n 'qc-item-ref-connected': CustomEvent<{ identifier: string; href: string; category: string }>;\n}\n\nexport type PublicEventName = keyof PublicEventMap;\n\nexport const PUBLIC_EVENTS: Record<PublicEventName, PublicEventDeclaration> = {\n 'qc-test-navigate': { kind: 'request', scope: 'test', deprecated: 'cito-test-navigate' },\n 'qc-test-end-attempt': { kind: 'request', scope: 'test', deprecated: 'cito-test-end-attempt' },\n 'qc-test-submit': { kind: 'request', scope: 'test', deprecated: 'cito-test-submit' },\n 'qc-test-update-outcome': { kind: 'request', scope: 'test', deprecated: 'cito-test-update-outcome' },\n 'qc-test-update-plugin-state': { kind: 'request', scope: 'test', deprecated: 'cito-test-update-plugin-state' },\n 'qc-test-update-comment': { kind: 'request', scope: 'test' },\n 'qc-test-switch-view': { kind: 'request', scope: 'test', deprecated: 'cito-test-switch-view' },\n 'qc-test-submitted': { kind: 'notification', scope: 'test', deprecated: 'cito-test-submitted' },\n 'qc-test-navigated': { kind: 'notification', scope: 'test', deprecated: 'cito-test-navigated' },\n 'qc-test-navigation-started': { kind: 'notification', scope: 'test', deprecated: 'cito-test-navigation-started' },\n 'qc-test-navigation-failed': { kind: 'notification', scope: 'test', deprecated: 'cito-test-navigation-failed' },\n 'qc-test-rendered': { kind: 'notification', scope: 'test', deprecated: 'cito-test-rendered' },\n 'qc-test-loaded': { kind: 'notification', scope: 'test', deprecated: 'cito-test-loaded' },\n 'qc-test-state-changed': { kind: 'notification', scope: 'test', deprecated: 'cito-test-state-changed' },\n // New in 10.0, so it has no cito- name.\n 'qc-test-state-refused': { kind: 'notification', scope: 'test' },\n 'qc-test-items-skipped': { kind: 'notification', scope: 'test', deprecated: 'cito-test-items-skipped' },\n 'qc-test-end-reached': { kind: 'notification', scope: 'test', deprecated: 'cito-test-end-reached' },\n 'qc-item-ref-connected': { kind: 'notification', scope: 'item', deprecated: 'cito-item-ref-connected' }\n};\n\ndeclare global {\n interface HTMLElementEventMap extends PublicEventMap {}\n}\n\n/**\n * Dispatch a public event, and its deprecated name with the same `detail` object. The detail is\n * always an object so `listenPublic` can tell the two apart from one dispatch.\n */\nexport function dispatchPublic<K extends PublicEventName>(\n target: EventTarget,\n name: K,\n detail: PublicEventMap[K] extends CustomEvent<infer D> ? D : never\n): void {\n dispatchDeclared(target, PUBLIC_EVENTS, name, detail);\n}\n\n/**\n * Listen for a public event and its deprecated name; the handler runs once for a sender that\n * dispatched both. See `listenDeclared`.\n */\nexport function listenPublic<K extends PublicEventName>(\n target: EventTarget,\n name: K,\n handler: (e: PublicEventMap[K]) => void\n): void {\n listenDeclared(target, PUBLIC_EVENTS, name, handler as (e: Event) => void);\n}\n"]}
@@ -17,6 +17,7 @@ export interface StoredTestContext {
17
17
  identifier?: string;
18
18
  variables?: readonly StoredVariable[];
19
19
  state?: Readonly<Record<string, string | null>>;
20
+ comment?: string;
20
21
  }[];
21
22
  testOutcomeVariables?: readonly StoredVariable[];
22
23
  }
@@ -37,7 +37,8 @@ export const stateFromContexts = (testContext, sessionContext) => ({
37
37
  .map(item => ({
38
38
  identifier: item.identifier,
39
39
  variables: (item.variables ?? []).map(variable),
40
- ...(item.state ? { state: { ...item.state } } : {})
40
+ ...(item.state ? { state: { ...item.state } } : {}),
41
+ ...(typeof item.comment === 'string' ? { comment: item.comment } : {})
41
42
  })),
42
43
  outcomes: (testContext?.testOutcomeVariables ?? []).map(v => ({
43
44
  identifier: v.identifier,
@@ -1 +1 @@
1
- {"version":3,"file":"state-from-contexts.js","sourceRoot":"","sources":["../src/state-from-contexts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AAoCnE,MAAM,cAAc,GAAG,CAAC,UAAU,EAAE,SAAS,EAAE,UAAU,EAAE,SAAS,CAAU,CAAC;AAE/E,MAAM,OAAO,GAAG,CAAC,KAAkB,EAA8B,EAAE;IACjE,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,IAAI,CAAC;IACvD,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IACnD,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;AACvB,CAAC,CAAC;AAEF,MAAM,QAAQ,GAAG,CAAC,EAAE,UAAU,EAAE,IAAI,EAAE,KAAK,EAAkB,EAAyC,EAAE,CAAC,CAAC;IACxG,UAAU;IACV,GAAG,CAAC,cAAc,CAAC,QAAQ,CAAC,IAAuC,CAAC;QAClE,CAAC,CAAC,EAAE,IAAI,EAAE,IAAuC,EAAE;QACnD,CAAC,CAAC,EAAE,CAAC;IACP,KAAK,EAAE,OAAO,CAAC,KAAK,CAAC;CACtB,CAAC,CAAC;AAEH;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAC/B,WAA2D,EAC3D,cAAsD,EACxC,EAAE,CAAC,CAAC;IAClB,OAAO,EAAE,sBAAsB;IAC/B,IAAI,EAAE;QACJ,KAAK,EAAE,CAAC,WAAW,EAAE,KAAK,IAAI,EAAE,CAAC;aAC9B,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,EAAE,UAAU,CAAC;aAChC,GAAG,CA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ourcesContent":["import { QTI_TEST_STATE_VERSION } from './types/qti-test-state.js';\n\nimport type { QtiTestState, QtiTestStateItem, QtiTestStateValue } from './types/qti-test-state.js';\n\n/** A value as a 9.x host may have stored it: QTI values are strings, but JSON kept numbers as numbers. */\ntype StoredValue = string | number | boolean | null | undefined | readonly (string | number | boolean)[];\n\n/** A variable as stored: only `identifier`, `value` and `type` are read; declaration metadata is ignored. */\nexport interface StoredVariable {\n identifier: string;\n value?: StoredValue;\n type?: string;\n}\n\n/**\n * A `testContext` as a 9.x host stored it (`qtiTest.testContext` or the `qti-test-context-updated`\n * payload), plain JSON. Fields this does not name, such as an item's `href` or a host's own\n * additions, are ignored.\n */\nexport interface StoredTestContext {\n items?: readonly {\n identifier?: string;\n variables?: readonly StoredVariable[];\n state?: Readonly<Record<string, string | null>>;\n }[];\n testOutcomeVariables?: readonly StoredVariable[];\n}\n\n/** A `sessionContext` as a 9.x host stored it: the position and the plugin entries. */\nexport interface StoredSessionContext {\n navPartId?: string | null;\n navSectionId?: string | null;\n navItemRefId?: string | null;\n plugins?: Readonly<Record<string, unknown>>;\n}\n\nconst VARIABLE_TYPES = ['response', 'outcome', 'template', 'context'] as const;\n\nconst valueOf = (value: StoredValue): QtiTestStateValue['value'] => {\n if (value === null || value === undefined) return null;\n if (Array.isArray(value)) return value.map(String);\n return String(value);\n};\n\nconst variable = ({ identifier, type, value }: StoredVariable): QtiTestStateItem['variables'][number] => ({\n identifier,\n ...(VARIABLE_TYPES.includes(type as (typeof VARIABLE_TYPES)[number])\n ? { type: type as (typeof VARIABLE_TYPES)[number] }\n : {}),\n value: valueOf(value)\n});\n\n/**\n * Turns a stored `testContext` and `sessionContext` into a `QtiTestState`, so a host that stored the\n * contexts in 9.x can resume with `qtiTest.state = stateFromContexts(testContext, sessionContext)`.\n * `qtiTest.state` reads the same way from the live contexts.\n *\n * It keeps the values only: each item's variables (identifier, value and `type` when it is one QTI\n * knows) and per-interaction state, the test outcomes, the position and the plugin entries. Values\n * are written as QTI's strings, so a number a host stored as a JSON number (`SCORE: 0`) becomes\n * `'0'`. Declaration metadata (`baseType`, `cardinality`, `correctResponse`, …) is left out, as in\n * every `QtiTestState`. Items without an identifier are skipped.\n *\n * @param testContext The stored test context, plain JSON.\n * @param sessionContext The stored session context, if the host kept one. A host that stored only the\n * item it was on passes `{ navItemRefId }`.\n */\nexport const stateFromContexts = (\n testContext: Readonly<StoredTestContext> | null | undefined,\n sessionContext?: Readonly<StoredSessionContext> | null\n): QtiTestState => ({\n version: QTI_TEST_STATE_VERSION,\n test: {\n items: (testContext?.items ?? [])\n .filter(item => item?.identifier)\n .map(item => ({\n identifier: item.identifier as string,\n variables: (item.variables ?? []).map(variable),\n ...(item.state ? { state: { ...item.state } } : {})\n })),\n outcomes: (testContext?.testOutcomeVariables ?? []).map(v => ({\n identifier: v.identifier,\n value: valueOf(v.value)\n }))\n },\n session: {\n ...(sessionContext?.plugins && Object.keys(sessionContext.plugins).length > 0\n ? { plugins: { ...sessionContext.plugins } }\n : {}),\n ...(sessionContext?.navPartId !== undefined ? { navPartId: sessionContext.navPartId } : {}),\n ...(sessionContext?.navSectionId !== undefined ? { navSectionId: sessionContext.navSectionId } : {}),\n ...(sessionContext?.navItemRefId !== undefined ? { navItemRefId: sessionContext.navItemRefId } : {})\n }\n});\n"]}
1
+ {"version":3,"file":"state-from-contexts.js","sourceRoot":"","sources":["../src/state-from-contexts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AAqCnE,MAAM,cAAc,GAAG,CAAC,UAAU,EAAE,SAAS,EAAE,UAAU,EAAE,SAAS,CAAU,CAAC;AAE/E,MAAM,OAAO,GAAG,CAAC,KAAkB,EAA8B,EAAE;IACjE,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,IAAI,CAAC;IACvD,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC,GAAG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AAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;YAC5D,UAAU,EAAE,CAAC,CAAC,UAAU;YACxB,KAAK,EAAE,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC;SACxB,CAAC,CAAC;KACJ;IACD,OAAO,EAAE;QACP,GAAG,CAAC,cAAc,EAAE,OAAO,IAAI,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,MAAM,GAAG,CAAC;YAC3E,CAAC,CAAC,EAAE,OAAO,EAAE,EAAE,GAAG,cAAc,CAAC,OAAO,EAAE,EAAE;YAC5C,CAAC,CAAC,EAAE,CAAC;QACP,GAAG,CAAC,cAAc,EAAE,SAAS,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,cAAc,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC3F,GAAG,CAAC,cAAc,EAAE,YAAY,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,cAAc,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACpG,GAAG,CAAC,cAAc,EAAE,YAAY,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,cAAc,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACrG;CACF,CAAC,CAAC","sourcesContent":["import { QTI_TEST_STATE_VERSION } from './types/qti-test-state.js';\n\nimport type { QtiTestState, QtiTestStateItem, QtiTestStateValue } from './types/qti-test-state.js';\n\n/** A value as a 9.x host may have stored it: QTI values are strings, but JSON kept numbers as numbers. */\ntype StoredValue = string | number | boolean | null | undefined | readonly (string | number | boolean)[];\n\n/** A variable as stored: only `identifier`, `value` and `type` are read; declaration metadata is ignored. */\nexport interface StoredVariable {\n identifier: string;\n value?: StoredValue;\n type?: string;\n}\n\n/**\n * A `testContext` as a 9.x host stored it (`qtiTest.testContext` or the `qti-test-context-updated`\n * payload), plain JSON. Fields this does not name, such as an item's `href` or a host's own\n * additions, are ignored.\n */\nexport interface StoredTestContext {\n items?: readonly {\n identifier?: string;\n variables?: readonly StoredVariable[];\n state?: Readonly<Record<string, string | null>>;\n comment?: string;\n }[];\n testOutcomeVariables?: readonly StoredVariable[];\n}\n\n/** A `sessionContext` as a 9.x host stored it: the position and the plugin entries. */\nexport interface StoredSessionContext {\n navPartId?: string | null;\n navSectionId?: string | null;\n navItemRefId?: string | null;\n plugins?: Readonly<Record<string, unknown>>;\n}\n\nconst VARIABLE_TYPES = ['response', 'outcome', 'template', 'context'] as const;\n\nconst valueOf = (value: StoredValue): QtiTestStateValue['value'] => {\n if (value === null || value === undefined) return null;\n if (Array.isArray(value)) return value.map(String);\n return String(value);\n};\n\nconst variable = ({ identifier, type, value }: StoredVariable): QtiTestStateItem['variables'][number] => ({\n identifier,\n ...(VARIABLE_TYPES.includes(type as (typeof VARIABLE_TYPES)[number])\n ? { type: type as (typeof VARIABLE_TYPES)[number] }\n : {}),\n value: valueOf(value)\n});\n\n/**\n * Turns a stored `testContext` and `sessionContext` into a `QtiTestState`, so a host that stored the\n * contexts in 9.x can resume with `qtiTest.state = stateFromContexts(testContext, sessionContext)`.\n * `qtiTest.state` reads the same way from the live contexts.\n *\n * It keeps the values only: each item's variables (identifier, value and `type` when it is one QTI\n * knows) and per-interaction state, the test outcomes, the position and the plugin entries. Values\n * are written as QTI's strings, so a number a host stored as a JSON number (`SCORE: 0`) becomes\n * `'0'`. Declaration metadata (`baseType`, `cardinality`, `correctResponse`, …) is left out, as in\n * every `QtiTestState`. Items without an identifier are skipped.\n *\n * @param testContext The stored test context, plain JSON.\n * @param sessionContext The stored session context, if the host kept one. A host that stored only the\n * item it was on passes `{ navItemRefId }`.\n */\nexport const stateFromContexts = (\n testContext: Readonly<StoredTestContext> | null | undefined,\n sessionContext?: Readonly<StoredSessionContext> | null\n): QtiTestState => ({\n version: QTI_TEST_STATE_VERSION,\n test: {\n items: (testContext?.items ?? [])\n .filter(item => item?.identifier)\n .map(item => ({\n identifier: item.identifier as string,\n variables: (item.variables ?? []).map(variable),\n ...(item.state ? { state: { ...item.state } } : {}),\n ...(typeof item.comment === 'string' ? { comment: item.comment } : {})\n })),\n outcomes: (testContext?.testOutcomeVariables ?? []).map(v => ({\n identifier: v.identifier,\n value: valueOf(v.value)\n }))\n },\n session: {\n ...(sessionContext?.plugins && Object.keys(sessionContext.plugins).length > 0\n ? { plugins: { ...sessionContext.plugins } }\n : {}),\n ...(sessionContext?.navPartId !== undefined ? { navPartId: sessionContext.navPartId } : {}),\n ...(sessionContext?.navSectionId !== undefined ? { navSectionId: sessionContext.navSectionId } : {}),\n ...(sessionContext?.navItemRefId !== undefined ? { navItemRefId: sessionContext.navItemRefId } : {})\n }\n});\n"]}
@@ -34,6 +34,11 @@ export interface QtiTestStateItem {
34
34
  })[];
35
35
  /** Opaque per-interaction state keyed by response identifier, e.g. a PCI's `getState()`. */
36
36
  state?: Record<string, string | null>;
37
+ /**
38
+ * The candidate's comment on the item, set with `qc-test-update-comment` when the item's
39
+ * `allow-comment` allows it (QTI 3 `qti-item-session-control`). Not assessed (roadmap 1 T3c).
40
+ */
41
+ comment?: string;
37
42
  }
38
43
  export interface QtiTestStateValue {
39
44
  identifier: string;
@@ -1 +1 @@
1
- {"version":3,"file":"qti-test-state.js","sourceRoot":"","sources":["../../src/types/qti-test-state.ts"],"names":[],"mappings":"AA8DA,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,CAAC","sourcesContent":["/**\n * Everything a host needs to persist to resume a candidate's test session, and nothing else.\n *\n * Read it from `qtiTest.state` or the `qc-test-state-changed` event, store it wherever you like —\n * a database, `localStorage`, `sessionStorage` — and assign it back to `qtiTest.state` to resume.\n *\n * Deliberately not here:\n * - declaration metadata (`baseType`, `cardinality`, `correctResponse`, `mapping`, …): it comes\n * from the item XML on every load, and persisting the answer key with the candidate's data is\n * both bloat and a leak;\n * - `configContext` and `qtiContext`: inputs the host supplies on every load, not session state.\n * The shuffle `seed` in particular must be passed in again, or the restored order changes;\n * - `view`: a role the host decides, not something the candidate produced;\n * - anything computed — scores per section, `done`, `active` — which is rederived from this.\n */\nexport interface QtiTestState {\n /** Bumped on any incompatible change to this shape. A state with another version is ignored. */\n version: 1;\n test: {\n items: QtiTestStateItem[];\n /** Test-level outcome values. Only outcomes the test declares are restored. */\n outcomes: QtiTestStateValue[];\n };\n session: QtiTestStateSession;\n}\n\nexport interface QtiTestStateItem {\n /**\n * The `qti-assessment-item-ref` identifier; for the clone of an item-ref that `qti-selection\n * with-replacement=\"true\"` selected again, its instance id: `item-3#2` (roadmap 1 T4).\n */\n identifier: string;\n variables: (QtiTestStateValue & { type?: 'response' | 'outcome' | 'template' | 'context' })[];\n /** Opaque per-interaction state keyed by response identifier, e.g. a PCI's `getState()`. */\n state?: Record<string, string | null>;\n}\n\nexport interface QtiTestStateValue {\n identifier: string;\n value: string | string[] | null;\n}\n\n/**\n * What each plugin keeps in the state, by plugin name. Empty here: a plugin adds its own entry by\n * augmenting this interface (`declare module` on the module that declares it, with\n * `interface QtiTestPluginState { bookmarks: string[] }`), and reads it with\n * `pluginState(computedContext, 'bookmarks')`. The test never reads an entry; it\n * stores and restores it, so a value must survive `JSON.stringify`.\n */\n\nexport interface QtiTestPluginState {}\n\n/** Where the candidate is, and what plugins keep. */\nexport interface QtiTestStateSession {\n /** Plugin entries by plugin name. Entries of plugins that are not loaded are kept as they are. */\n plugins?: Partial<QtiTestPluginState> & Record<string, unknown>;\n navPartId?: string | null;\n navSectionId?: string | null;\n /** The item on screen, as `items[].identifier` names it: a clone is `item-3#2`. */\n navItemRefId?: string | null;\n}\n\nexport const QTI_TEST_STATE_VERSION = 1;\n"]}
1
+ {"version":3,"file":"qti-test-state.js","sourceRoot":"","sources":["../../src/types/qti-test-state.ts"],"names":[],"mappings":"AAmEA,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,CAAC","sourcesContent":["/**\n * Everything a host needs to persist to resume a candidate's test session, and nothing else.\n *\n * Read it from `qtiTest.state` or the `qc-test-state-changed` event, store it wherever you like —\n * a database, `localStorage`, `sessionStorage` — and assign it back to `qtiTest.state` to resume.\n *\n * Deliberately not here:\n * - declaration metadata (`baseType`, `cardinality`, `correctResponse`, `mapping`, …): it comes\n * from the item XML on every load, and persisting the answer key with the candidate's data is\n * both bloat and a leak;\n * - `configContext` and `qtiContext`: inputs the host supplies on every load, not session state.\n * The shuffle `seed` in particular must be passed in again, or the restored order changes;\n * - `view`: a role the host decides, not something the candidate produced;\n * - anything computed — scores per section, `done`, `active` — which is rederived from this.\n */\nexport interface QtiTestState {\n /** Bumped on any incompatible change to this shape. A state with another version is ignored. */\n version: 1;\n test: {\n items: QtiTestStateItem[];\n /** Test-level outcome values. Only outcomes the test declares are restored. */\n outcomes: QtiTestStateValue[];\n };\n session: QtiTestStateSession;\n}\n\nexport interface QtiTestStateItem {\n /**\n * The `qti-assessment-item-ref` identifier; for the clone of an item-ref that `qti-selection\n * with-replacement=\"true\"` selected again, its instance id: `item-3#2` (roadmap 1 T4).\n */\n identifier: string;\n variables: (QtiTestStateValue & { type?: 'response' | 'outcome' | 'template' | 'context' })[];\n /** Opaque per-interaction state keyed by response identifier, e.g. a PCI's `getState()`. */\n state?: Record<string, string | null>;\n /**\n * The candidate's comment on the item, set with `qc-test-update-comment` when the item's\n * `allow-comment` allows it (QTI 3 `qti-item-session-control`). Not assessed (roadmap 1 T3c).\n */\n comment?: string;\n}\n\nexport interface QtiTestStateValue {\n identifier: string;\n value: string | string[] | null;\n}\n\n/**\n * What each plugin keeps in the state, by plugin name. Empty here: a plugin adds its own entry by\n * augmenting this interface (`declare module` on the module that declares it, with\n * `interface QtiTestPluginState { bookmarks: string[] }`), and reads it with\n * `pluginState(computedContext, 'bookmarks')`. The test never reads an entry; it\n * stores and restores it, so a value must survive `JSON.stringify`.\n */\n\nexport interface QtiTestPluginState {}\n\n/** Where the candidate is, and what plugins keep. */\nexport interface QtiTestStateSession {\n /** Plugin entries by plugin name. Entries of plugins that are not loaded are kept as they are. */\n plugins?: Partial<QtiTestPluginState> & Record<string, unknown>;\n navPartId?: string | null;\n navSectionId?: string | null;\n /** The item on screen, as `items[].identifier` names it: a clone is `item-3#2`. */\n navItemRefId?: string | null;\n}\n\nexport const QTI_TEST_STATE_VERSION = 1;\n"]}
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@qti-components/test",
3
3
  "description": "QTI test utilities",
4
- "version": "2.0.0-next.27",
4
+ "version": "2.0.0-next.29",
5
5
  "author": "",
6
6
  "dependencies": {
7
7
  "@heximal/templates": "^0.1.5",
8
- "@qti-components/base": "^3.0.0-next.14",
9
- "@qti-components/delivery": "^0.1.0-next.7",
8
+ "@qti-components/base": "^3.0.0-next.16",
9
+ "@qti-components/delivery": "^0.1.0-next.9",
10
10
  "@qti-components/elements": "^2.0.0-next.7",
11
11
  "@qti-components/interactions": "^1.10.5-next.8",
12
12
  "@qti-components/processing": "^1.6.1-next.5",
@@ -1,9 +0,0 @@
1
- import type { ComputedContext, ComputedItem } from '@qti-components/base';
2
- /**
3
- * The items of a test part in the order the candidate takes them: the test's document order, info
4
- * items included. Flattening `testPart.sections` is not that order when a section's item-refs and
5
- * subsections interleave, since `sections` lists every section once, depth first.
6
- *
7
- * A part without `itemOrder` (a context built by hand) gives its sections' items as they are listed.
8
- */
9
- export declare const itemsInOrder: (testPart: ComputedContext["testParts"][number]) => ComputedItem[];
@@ -1,15 +0,0 @@
1
- /**
2
- * The items of a test part in the order the candidate takes them: the test's document order, info
3
- * items included. Flattening `testPart.sections` is not that order when a section's item-refs and
4
- * subsections interleave, since `sections` lists every section once, depth first.
5
- *
6
- * A part without `itemOrder` (a context built by hand) gives its sections' items as they are listed.
7
- */
8
- export const itemsInOrder = (testPart) => {
9
- const items = testPart.sections.flatMap(section => section.items);
10
- if (!testPart.itemOrder)
11
- return items;
12
- const byIdentifier = new Map(items.map(item => [item.identifier, item]));
13
- return testPart.itemOrder.flatMap(identifier => byIdentifier.get(identifier) ?? []);
14
- };
15
- //# sourceMappingURL=items-in-order.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"items-in-order.js","sourceRoot":"","sources":["../src/items-in-order.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,QAA8C,EAAkB,EAAE;IAC7F,MAAM,KAAK,GAAG,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAClE,IAAI,CAAC,QAAQ,CAAC,SAAS;QAAE,OAAO,KAAK,CAAC;IACtC,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;IACzE,OAAO,QAAQ,CAAC,SAAS,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC,YAAY,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC,CAAC;AACtF,CAAC,CAAC","sourcesContent":["import type { ComputedContext, ComputedItem } from '@qti-components/base';\n\n/**\n * The items of a test part in the order the candidate takes them: the test's document order, info\n * items included. Flattening `testPart.sections` is not that order when a section's item-refs and\n * subsections interleave, since `sections` lists every section once, depth first.\n *\n * A part without `itemOrder` (a context built by hand) gives its sections' items as they are listed.\n */\nexport const itemsInOrder = (testPart: ComputedContext['testParts'][number]): ComputedItem[] => {\n const items = testPart.sections.flatMap(section => section.items);\n if (!testPart.itemOrder) return items;\n const byIdentifier = new Map(items.map(item => [item.identifier, item]));\n return testPart.itemOrder.flatMap(identifier => byIdentifier.get(identifier) ?? []);\n};\n"]}