@qti-components/test 2.0.0-next.33 → 2.0.0-next.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/qti-test/qti-test.d.ts +1 -0
- package/dist/components/qti-test/qti-test.js +1 -0
- package/dist/components/qti-test/qti-test.js.map +1 -1
- package/dist/components/test-end-attempt/test-end-attempt.d.ts +2 -2
- package/dist/components/test-end-attempt/test-end-attempt.js +10 -3
- package/dist/components/test-end-attempt/test-end-attempt.js.map +1 -1
- package/dist/components/test-navigation/test-navigation.js +320 -13
- package/dist/components/test-navigation/test-navigation.js.map +1 -1
- package/dist/internal/derive-computed-context.d.ts +6 -1
- package/dist/internal/derive-computed-context.js +6 -0
- package/dist/internal/derive-computed-context.js.map +1 -1
- package/dist/internal/item-session-facts.d.ts +5 -2
- package/dist/internal/item-session-facts.js +5 -3
- package/dist/internal/item-session-facts.js.map +1 -1
- package/dist/internal/test-host.context.d.ts +21 -0
- package/dist/internal/test-host.context.js.map +1 -1
- package/dist/internal/test-timing.d.ts +8 -0
- package/dist/internal/test-timing.js +18 -0
- package/dist/internal/test-timing.js.map +1 -0
- package/dist/mixins/test-processing.mixin.js +5 -2
- package/dist/mixins/test-processing.mixin.js.map +1 -1
- package/dist/mixins/test-state.mixin.d.ts +16 -9
- package/dist/mixins/test-state.mixin.js +86 -8
- package/dist/mixins/test-state.mixin.js.map +1 -1
- package/dist/public-events.d.ts +19 -0
- package/dist/public-events.js +4 -0
- package/dist/public-events.js.map +1 -1
- package/dist/types/qti-test-state.d.ts +20 -0
- package/dist/types/qti-test-state.js.map +1 -1
- package/package.json +4 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test-timing.js","sourceRoot":"","sources":["../../src/internal/test-timing.ts"],"names":[],"mappings":"AAGA,4GAA4G;AAC5G,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,KAAK,EAAiB,EAAgB,EAAE,CAAC,CAAC;IAClG,MAAM,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE;IACrC,KAAK,EAAE,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,QAAQ,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC;CAC7F,CAAC,CAAC;AAEH,0GAA0G;AAC1G,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,EAAE,MAAM,EAAE,KAAK,EAAgB,EAAiB,EAAE,CAC9E,IAAI,CAAC,KAAK,CACR,IAAI,CAAC,SAAS,CAAC;IACb,GAAG,MAAM;IACT,KAAK,EAAE,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,QAAQ,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,QAAQ,CAAC,CAAC,CAAC;CAC7F,CAAC,CACH,CAAC;AAEJ,0CAA0C;AAC1C,MAAM,CAAC,MAAM,WAAW,GAAG,GAAkB,EAAE,CAAC,CAAC;IAC/C,IAAI,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE;IAC/B,SAAS,EAAE,EAAE;IACb,QAAQ,EAAE,EAAE;IACZ,KAAK,EAAE,EAAE;CACV,CAAC,CAAC","sourcesContent":["import type { StoredTiming } from '@qti-components/delivery';\nimport type { QtiTestTiming } from '../types/qti-test-state';\n\n/** `QtiTestTiming`, as the `delivery` timing functions read it: each item's stopwatch as its `duration`. */\nexport const storedTiming = ({ test, testParts, sections, items }: QtiTestTiming): StoredTiming => ({\n timing: { test, testParts, sections },\n items: Object.fromEntries(Object.entries(items).map(([id, duration]) => [id, { duration }]))\n});\n\n/** Back from the `delivery` shape to the one `QtiTestState` stores, as plain JSON (no shared objects). */\nexport const qtiTestTiming = ({ timing, items }: StoredTiming): QtiTestTiming =>\n JSON.parse(\n JSON.stringify({\n ...timing,\n items: Object.fromEntries(Object.entries(items).map(([id, { duration }]) => [id, duration]))\n })\n );\n\n/** A timing where nothing has run yet. */\nexport const emptyTiming = (): QtiTestTiming => ({\n test: { spent: 0, since: null },\n testParts: {},\n sections: {},\n items: {}\n});\n"]}
|
|
@@ -60,10 +60,13 @@ export const TestProcessingMixin = (superClass) => {
|
|
|
60
60
|
return true;
|
|
61
61
|
}
|
|
62
62
|
/**
|
|
63
|
-
* Ends the test for scoring:
|
|
64
|
-
* `qc-test-submitted
|
|
63
|
+
* Ends the test for scoring: submits every test part with simultaneous submission (each sends
|
|
64
|
+
* `qc-test-part-submitted`), runs `outcomeProcessing()`, then tells the host with
|
|
65
|
+
* `qc-test-submitted`. Returns false, and sends no `qc-test-submitted`, when the test has no
|
|
66
|
+
* outcome processing.
|
|
65
67
|
*/
|
|
66
68
|
submit() {
|
|
69
|
+
this.submitTestParts?.();
|
|
67
70
|
if (!this.outcomeProcessing())
|
|
68
71
|
return false;
|
|
69
72
|
dispatchPublic(this, 'qc-test-submitted', {});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"test-processing.mixin.js","sourceRoot":"","sources":["../../src/mixins/test-processing.mixin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAiBhE,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAA2C,UAAa,EAAE,EAAE;IAC7F,MAAe,qBAAsB,SAAQ,UAAU;QACrD,YAAY,GAAG,IAAW;YACxB,KAAK,CAAC,GAAG,IAAI,CAAC,CAAC;YACf,IAAI,CAAC,gBAAgB,CAAC,uBAAuB,EAAE,CAAC,CAAiC,EAAE,EAAE;gBACnF,IAAI,CAAC,WAAW,GAAG;oBACjB,GAAG,IAAI,CAAC,WAAW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C,CAAC","sourcesContent":["import { dispatchPublic, listenPublic } from '../public-events';\n\nimport type { QtiOutcomeProcessing } from '../components/qti-outcome-processing/qti-outcome-processing';\nimport type { QtiTestFeedback } from '../components/qti-test-feedback/qti-test-feedback';\nimport type { OutcomeVariable, VariableDeclaration } from '@qti-components/base';\nimport type { TestBaseInterface } from './test-base';\n\ntype Constructor<T = {}> = abstract new (...args: any[]) => T;\n\ndeclare class TestProcessingInterface {\n updateOutcomeVariable(identifier: string, value: string | string[] | undefined): void;\n getOutcome(identifier: string): Readonly<OutcomeVariable>;\n getVariable(identifier: string): Readonly<VariableDeclaration<string | string[] | null>>;\n outcomeProcessing(): boolean;\n submit(): boolean;\n getTestFeedback(access?: 'atEnd' | 'during'): QtiTestFeedback[];\n}\nexport const TestProcessingMixin = <T extends Constructor<TestBaseInterface>>(superClass: T) => {\n abstract class TestProcessingElement extends superClass implements TestProcessingInterface {\n constructor(...args: any[]) {\n super(...args);\n this.addEventListener('qti-register-variable', (e: CustomEvent<{ variable: any }>) => {\n this.testContext = {\n ...this.testContext,\n testOutcomeVariables: [...(this.testContext.testOutcomeVariables || []), e.detail.variable]\n };\n e.stopPropagation();\n });\n listenPublic(this, 'qc-test-submit', () => this.submit());\n // QTI 3 info model §2.9: the test's outcome processing runs each time the candidate submits an\n // item in an individual part, after the item's response processing, so branch rules and\n // pre-conditions read test outcomes that include it (impl. guide §4.5.3, step 1). Registered\n // after the base mixin's listener, so the test context already holds the item's new values.\n // A simultaneous part is processed when the part is submitted (roadmap 1, T6).\n this.addEventListener(\n 'qti-item-context-updated',\n (e: CustomEvent<{ itemContext: { identifier: string }; responseProcessed?: boolean }>) => {\n if (!e.detail?.responseProcessed) return;\n if (this.#submissionModeOf(e.detail.itemContext?.identifier) !== 'individual') return;\n this.outcomeProcessing();\n }\n );\n // wordt aangeroepen vanuit de processingtemplate\n this.addEventListener(\n 'qti-set-outcome-value',\n (e: CustomEvent<{ outcomeIdentifier: string; value: string | string[] }>) => {\n const { outcomeIdentifier, value } = e.detail;\n this.updateOutcomeVariable(outcomeIdentifier, value);\n e.stopPropagation();\n }\n );\n }\n\n /** The `submission-mode` of the test part that holds this item-ref; null when it is not in the test. */\n #submissionModeOf(itemRefIdentifier: string | undefined): 'individual' | 'simultaneous' | null {\n if (!itemRefIdentifier || !this._testElement) return null;\n const part = this._testElement\n .querySelector(`qti-assessment-item-ref[identifier=\"${CSS.escape(itemRefIdentifier)}\"]`)\n ?.closest('qti-test-part');\n if (!part) return null;\n return part.getAttribute('submission-mode') === 'simultaneous' ? 'simultaneous' : 'individual';\n }\n\n outcomeProcessing(): boolean {\n // Inside the loaded test: `test-container` renders it into its own shadow root, which a\n // `querySelector` on this element does not reach. Without a loaded test, look in the light DOM.\n const outcomeProcessor = (this._testElement ?? this).querySelector(\n 'qti-outcome-processing'\n ) as unknown as QtiOutcomeProcessing;\n if (!outcomeProcessor) return false;\n // QTI starts every run of the test's outcome processing from the declared defaults, so an\n // accumulating rule (`SCORE_TOTAL = sum + SCORE_TOTAL`) gives the same total on every run.\n this.testContext = {\n ...this.testContext,\n testOutcomeVariables: this.testContext.testOutcomeVariables?.map(v => ({\n ...v,\n value: v.defaultValue ?? null\n }))\n };\n outcomeProcessor.process();\n return true;\n }\n\n /**\n * Ends the test for scoring: runs `outcomeProcessing()`, then tells the host with\n * `qc-test-submitted`. Returns false, and sends nothing, when the test has no outcome processing.\n */\n submit(): boolean {\n if (!this.outcomeProcessing()) return false;\n dispatchPublic(this, 'qc-test-submitted', {});\n return true;\n }\n\n /**\n * The `qti-test-feedback` elements that apply now, read from the test outcomes: run\n * `outcomeProcessing()` first. `access` narrows them to the end of the test (`atEnd`) or to\n * while it runs (`during`); without it, both.\n */\n getTestFeedback(access?: 'atEnd' | 'during'): QtiTestFeedback[] {\n const feedback = Array.from(\n (this._testElement ?? this).querySelectorAll<QtiTestFeedback>('qti-test-feedback') ?? []\n );\n return feedback.filter(\n fb => (!access || fb.access === access) && fb.matches(this.getOutcome(fb.outcomeIdentifier)?.value)\n );\n }\n\n /* --------------------------- ENABLED WHEN UNIT TESTING OUTCOME PROCESSING ------------------------------------ */\n\n public updateOutcomeVariable(identifier: string, value: string | string[] | undefined) {\n const outcomeVariable = this.getOutcome(identifier);\n if (!outcomeVariable) {\n console.warn(`Can not set qti-outcome-identifier: ${identifier}, it is not available`);\n return;\n }\n this.testContext = {\n ...this.testContext,\n testOutcomeVariables: this.testContext.testOutcomeVariables?.map(v => {\n if (v.identifier !== identifier) {\n return v;\n }\n return {\n ...v,\n value: outcomeVariable.cardinality === 'single' ? value : [...v.value, value as string]\n };\n })\n };\n }\n\n public getOutcome(identifier: string): Readonly<OutcomeVariable> {\n return this.getVariable(identifier) as OutcomeVariable;\n }\n public getVariable(identifier: string): Readonly<VariableDeclaration<string | string[] | null>> {\n return this.testContext.testOutcomeVariables?.find(v => v.identifier === identifier) || null;\n }\n /* --------------------------- ENABLED WHEN UNIT TESTING OUTCOME PROCESSING ------------------------------------ */\n }\n\n return TestProcessingElement as Constructor<TestProcessingInterface> & T;\n};\n"]}
|
|
1
|
+
{"version":3,"file":"test-processing.mixin.js","sourceRoot":"","sources":["../../src/mixins/test-processing.mixin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAiBhE,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAA2C,UAAa,EAAE,EAAE;IAC7F,MAAe,qBAAsB,SAAQ,UAAU;QACrD,YAAY,GAAG,IAAW;YACxB,KAAK,CAAC,GAAG,IAAI,CAAC,CAAC;YACf,IAAI,CAAC,gBAAgB,CAAC,uBAAuB,EAAE,CAAC,CAAiC,EAAE,EAAE;gBACnF,IAAI,CAAC,WAAW,GAAG;oBACjB,GAAG,IAAI,CAAC,WAAW;oBACnB,oBAAoB,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,oBAAoB,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,QAA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AAI,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC,iBAAiB,CAAC,EAAE,KAAK,CAAC,CACpG,CAAC;QACJ,CAAC;QAED,mHAAmH;QAE5G,qBAAqB,CAAC,UAAkB,EAAE,KAAoC;YACnF,MAAM,eAAe,GAAG,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;YACpD,IAAI,CAAC,eAAe,EAAE,CAAC;gBACrB,OAAO,CAAC,IAAI,CAAC,uCAAuC,UAAU,uBAAuB,CAAC,CAAC;gBACvF,OAAO;YACT,CAAC;YACD,IAAI,CAAC,WAAW,GAAG;gBACjB,GAAG,IAAI,CAAC,WAAW;gBACnB,oBAAoB,EAAE,IAAI,CAAC,WAAW,CAAC,oBAAoB,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE;oBACnE,IAAI,CAAC,CAAC,UAAU,KAAK,UAAU,EAAE,CAAC;wBAChC,OAAO,CAAC,CAAC;oBACX,CAAC;oBACD,OAAO;wBACL,GAAG,CAAC;wBACJ,KAAK,EAAE,eAAe,CAAC,WAAW,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,KAAe,CAAC;qBACxF,CAAC;gBACJ,CAAC,CAAC;aACH,CAAC;QACJ,CAAC;QAEM,UAAU,CAAC,UAAkB;YAClC,OAAO,IAAI,CAAC,WAAW,CAAC,UAAU,CAAoB,CAAC;QACzD,CAAC;QACM,WAAW,CAAC,UAAkB;YACnC,OAAO,IAAI,CAAC,WAAW,CAAC,oBAAoB,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,UAAU,KAAK,UAAU,CAAC,IAAI,IAAI,CAAC;QAC/F,CAAC;KAEF;IAED,OAAO,qBAAiE,CAAC;AAC3E,CAAC,CAAC","sourcesContent":["import { dispatchPublic, listenPublic } from '../public-events';\n\nimport type { QtiOutcomeProcessing } from '../components/qti-outcome-processing/qti-outcome-processing';\nimport type { QtiTestFeedback } from '../components/qti-test-feedback/qti-test-feedback';\nimport type { OutcomeVariable, VariableDeclaration } from '@qti-components/base';\nimport type { TestBaseInterface } from './test-base';\n\ntype Constructor<T = {}> = abstract new (...args: any[]) => T;\n\ndeclare class TestProcessingInterface {\n updateOutcomeVariable(identifier: string, value: string | string[] | undefined): void;\n getOutcome(identifier: string): Readonly<OutcomeVariable>;\n getVariable(identifier: string): Readonly<VariableDeclaration<string | string[] | null>>;\n outcomeProcessing(): boolean;\n submit(): boolean;\n getTestFeedback(access?: 'atEnd' | 'during'): QtiTestFeedback[];\n}\nexport const TestProcessingMixin = <T extends Constructor<TestBaseInterface>>(superClass: T) => {\n abstract class TestProcessingElement extends superClass implements TestProcessingInterface {\n constructor(...args: any[]) {\n super(...args);\n this.addEventListener('qti-register-variable', (e: CustomEvent<{ variable: any }>) => {\n this.testContext = {\n ...this.testContext,\n testOutcomeVariables: [...(this.testContext.testOutcomeVariables || []), e.detail.variable]\n };\n e.stopPropagation();\n });\n listenPublic(this, 'qc-test-submit', () => this.submit());\n // QTI 3 info model §2.9: the test's outcome processing runs each time the candidate submits an\n // item in an individual part, after the item's response processing, so branch rules and\n // pre-conditions read test outcomes that include it (impl. guide §4.5.3, step 1). Registered\n // after the base mixin's listener, so the test context already holds the item's new values.\n // A simultaneous part is processed when the part is submitted (roadmap 1, T6).\n this.addEventListener(\n 'qti-item-context-updated',\n (e: CustomEvent<{ itemContext: { identifier: string }; responseProcessed?: boolean }>) => {\n if (!e.detail?.responseProcessed) return;\n if (this.#submissionModeOf(e.detail.itemContext?.identifier) !== 'individual') return;\n this.outcomeProcessing();\n }\n );\n // wordt aangeroepen vanuit de processingtemplate\n this.addEventListener(\n 'qti-set-outcome-value',\n (e: CustomEvent<{ outcomeIdentifier: string; value: string | string[] }>) => {\n const { outcomeIdentifier, value } = e.detail;\n this.updateOutcomeVariable(outcomeIdentifier, value);\n e.stopPropagation();\n }\n );\n }\n\n /**\n * Set by `test-navigation` (`TestHost.submitTestParts`): submits every test part with\n * simultaneous submission that is not submitted yet. `submit()` calls it first.\n * @internal\n */\n declare submitTestParts?: (() => void) | null;\n\n /** The `submission-mode` of the test part that holds this item-ref; null when it is not in the test. */\n #submissionModeOf(itemRefIdentifier: string | undefined): 'individual' | 'simultaneous' | null {\n if (!itemRefIdentifier || !this._testElement) return null;\n const part = this._testElement\n .querySelector(`qti-assessment-item-ref[identifier=\"${CSS.escape(itemRefIdentifier)}\"]`)\n ?.closest('qti-test-part');\n if (!part) return null;\n return part.getAttribute('submission-mode') === 'simultaneous' ? 'simultaneous' : 'individual';\n }\n\n outcomeProcessing(): boolean {\n // Inside the loaded test: `test-container` renders it into its own shadow root, which a\n // `querySelector` on this element does not reach. Without a loaded test, look in the light DOM.\n const outcomeProcessor = (this._testElement ?? this).querySelector(\n 'qti-outcome-processing'\n ) as unknown as QtiOutcomeProcessing;\n if (!outcomeProcessor) return false;\n // QTI starts every run of the test's outcome processing from the declared defaults, so an\n // accumulating rule (`SCORE_TOTAL = sum + SCORE_TOTAL`) gives the same total on every run.\n this.testContext = {\n ...this.testContext,\n testOutcomeVariables: this.testContext.testOutcomeVariables?.map(v => ({\n ...v,\n value: v.defaultValue ?? null\n }))\n };\n outcomeProcessor.process();\n return true;\n }\n\n /**\n * Ends the test for scoring: submits every test part with simultaneous submission (each sends\n * `qc-test-part-submitted`), runs `outcomeProcessing()`, then tells the host with\n * `qc-test-submitted`. Returns false, and sends no `qc-test-submitted`, when the test has no\n * outcome processing.\n */\n submit(): boolean {\n this.submitTestParts?.();\n if (!this.outcomeProcessing()) return false;\n dispatchPublic(this, 'qc-test-submitted', {});\n return true;\n }\n\n /**\n * The `qti-test-feedback` elements that apply now, read from the test outcomes: run\n * `outcomeProcessing()` first. `access` narrows them to the end of the test (`atEnd`) or to\n * while it runs (`during`); without it, both.\n */\n getTestFeedback(access?: 'atEnd' | 'during'): QtiTestFeedback[] {\n const feedback = Array.from(\n (this._testElement ?? this).querySelectorAll<QtiTestFeedback>('qti-test-feedback') ?? []\n );\n return feedback.filter(\n fb => (!access || fb.access === access) && fb.matches(this.getOutcome(fb.outcomeIdentifier)?.value)\n );\n }\n\n /* --------------------------- ENABLED WHEN UNIT TESTING OUTCOME PROCESSING ------------------------------------ */\n\n public updateOutcomeVariable(identifier: string, value: string | string[] | undefined) {\n const outcomeVariable = this.getOutcome(identifier);\n if (!outcomeVariable) {\n console.warn(`Can not set qti-outcome-identifier: ${identifier}, it is not available`);\n return;\n }\n this.testContext = {\n ...this.testContext,\n testOutcomeVariables: this.testContext.testOutcomeVariables?.map(v => {\n if (v.identifier !== identifier) {\n return v;\n }\n return {\n ...v,\n value: outcomeVariable.cardinality === 'single' ? value : [...v.value, value as string]\n };\n })\n };\n }\n\n public getOutcome(identifier: string): Readonly<OutcomeVariable> {\n return this.getVariable(identifier) as OutcomeVariable;\n }\n public getVariable(identifier: string): Readonly<VariableDeclaration<string | string[] | null>> {\n return this.testContext.testOutcomeVariables?.find(v => v.identifier === identifier) || null;\n }\n /* --------------------------- ENABLED WHEN UNIT TESTING OUTCOME PROCESSING ------------------------------------ */\n }\n\n return TestProcessingElement as Constructor<TestProcessingInterface> & T;\n};\n"]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Clock } from '@qti-components/delivery';
|
|
2
|
+
import type { QtiTestState, QtiTestTiming } from '../types/qti-test-state';
|
|
2
3
|
import type { TestBaseInterface } from './test-base';
|
|
3
4
|
type Constructor<T = {}> = abstract new (...args: any[]) => T;
|
|
4
5
|
export interface ITestStateMixin {
|
|
@@ -20,14 +21,20 @@ export interface ITestStateMixin {
|
|
|
20
21
|
* `testContext` is turned into a state with `stateFromContexts`.
|
|
21
22
|
*/
|
|
22
23
|
state: QtiTestState;
|
|
24
|
+
/**
|
|
25
|
+
* Where the test reads the time for `qti-time-limits` (roadmap 1 T5): any object with `now()`,
|
|
26
|
+
* milliseconds since the epoch. By default the browser's clock, which a change of the system time
|
|
27
|
+
* does not move. A host whose server keeps the time passes
|
|
28
|
+
* `syncedClock(serverNow)` from `@qti-components/delivery`; to resync, assign a new one. A
|
|
29
|
+
* property, not an attribute.
|
|
30
|
+
*/
|
|
31
|
+
clock: Clock;
|
|
32
|
+
/** @internal The time spent, for `test-navigation`; null for a test without `qti-time-limits`. */
|
|
33
|
+
readonly timing: QtiTestTiming | null;
|
|
34
|
+
/** @internal */
|
|
35
|
+
updateTiming(timing: QtiTestTiming | null): void;
|
|
36
|
+
/** @internal */
|
|
37
|
+
saveTiming(): void;
|
|
23
38
|
}
|
|
24
|
-
/**
|
|
25
|
-
* Persist and resume a test session through one value, `state`, and one event,
|
|
26
|
-
* `qc-test-state-changed`.
|
|
27
|
-
*
|
|
28
|
-
* Sits directly on top of `TestBaseMixin`, so its `qc-test-loaded` listener runs
|
|
29
|
-
* after the base has built `testContext.items` from the item-refs, and before the navigation
|
|
30
|
-
* mixin's listener picks the first item to load.
|
|
31
|
-
*/
|
|
32
39
|
export declare const TestStateMixin: <T extends Constructor<TestBaseInterface>>(superClass: T) => Constructor<ITestStateMixin> & T;
|
|
33
40
|
export {};
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
+
import { checkpointTiming, resumeTiming } from '@qti-components/delivery';
|
|
2
|
+
import { qtiTestTiming, storedTiming } from '../internal/test-timing';
|
|
1
3
|
import { QTI_TEST_STATE_VERSION } from '../types/qti-test-state';
|
|
2
4
|
import { dispatchPublic, listenPublic } from '../public-events';
|
|
3
5
|
import { stateFromContexts } from '../state-from-contexts';
|
|
6
|
+
/** The browser's clock, monotonic: setting the system time back gains the candidate nothing. */
|
|
7
|
+
const browserClock = { now: () => performance.timeOrigin + performance.now() };
|
|
4
8
|
const copy = (value) => Array.isArray(value) ? [...value] : (value ?? null);
|
|
5
9
|
const isQtiTestState = (value) => {
|
|
6
10
|
const state = value;
|
|
@@ -18,21 +22,75 @@ const isQtiTestState = (value) => {
|
|
|
18
22
|
* after the base has built `testContext.items` from the item-refs, and before the navigation
|
|
19
23
|
* mixin's listener picks the first item to load.
|
|
20
24
|
*/
|
|
25
|
+
const isStopwatch = (value) => {
|
|
26
|
+
const stopwatch = value;
|
|
27
|
+
return (typeof stopwatch?.spent === 'number' &&
|
|
28
|
+
Number.isFinite(stopwatch.spent) &&
|
|
29
|
+
(stopwatch.since === null || (typeof stopwatch.since === 'number' && Number.isFinite(stopwatch.since))));
|
|
30
|
+
};
|
|
31
|
+
const isStopwatches = (value) => typeof value === 'object' && value !== null && Object.values(value).every(isStopwatch);
|
|
32
|
+
/** A stored `session.timing` this release can read; anything else starts the time from now. */
|
|
33
|
+
const isTiming = (value) => {
|
|
34
|
+
const timing = value;
|
|
35
|
+
return (isStopwatch(timing?.test) &&
|
|
36
|
+
isStopwatches(timing?.testParts) &&
|
|
37
|
+
isStopwatches(timing?.sections) &&
|
|
38
|
+
isStopwatches(timing?.items));
|
|
39
|
+
};
|
|
21
40
|
export const TestStateMixin = (superClass) => {
|
|
22
41
|
class TestStateClass extends superClass {
|
|
23
42
|
/** A state assigned before the test connected, applied when it does. */
|
|
24
|
-
#pending
|
|
43
|
+
#pending;
|
|
25
44
|
/** A refused state assigned before the test connected, reported when it does. */
|
|
26
|
-
#refused
|
|
45
|
+
#refused;
|
|
27
46
|
/**
|
|
28
47
|
* False while a test document is loading. Loading resets both contexts and rebuilds them, so
|
|
29
48
|
* the intermediate states are empty — emitting one would invite a host to save it over the
|
|
30
49
|
* real one.
|
|
31
50
|
*/
|
|
32
|
-
#ready
|
|
33
|
-
#lastEmitted
|
|
51
|
+
#ready;
|
|
52
|
+
#lastEmitted;
|
|
53
|
+
/**
|
|
54
|
+
* The time spent, for a test with `qti-time-limits` (`test-navigation` starts it and keeps it
|
|
55
|
+
* following the candidate); null for a test without. Saved in `state.session.timing`.
|
|
56
|
+
*/
|
|
57
|
+
#timing;
|
|
58
|
+
/** @internal For `test-navigation`, through the test host. */
|
|
59
|
+
get timing() {
|
|
60
|
+
return this.#timing;
|
|
61
|
+
}
|
|
62
|
+
/** @internal For `test-navigation`: the timing after it followed the candidate. */
|
|
63
|
+
updateTiming(timing) {
|
|
64
|
+
this.#timing = timing;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* @internal For `test-navigation`: sends `qc-test-state-changed` now, with the time spent up to
|
|
68
|
+
* this moment, even when nothing else changed (every 10 seconds while a limit is in force, and
|
|
69
|
+
* when the page is hidden), so a crash loses little time.
|
|
70
|
+
*/
|
|
71
|
+
saveTiming() {
|
|
72
|
+
if (this.#ready && this.#timing)
|
|
73
|
+
this.#emit(true);
|
|
74
|
+
}
|
|
34
75
|
constructor(...args) {
|
|
35
76
|
super(...args);
|
|
77
|
+
/** A state assigned before the test connected, applied when it does. */
|
|
78
|
+
this.#pending = null;
|
|
79
|
+
/** A refused state assigned before the test connected, reported when it does. */
|
|
80
|
+
this.#refused = null;
|
|
81
|
+
/**
|
|
82
|
+
* False while a test document is loading. Loading resets both contexts and rebuilds them, so
|
|
83
|
+
* the intermediate states are empty — emitting one would invite a host to save it over the
|
|
84
|
+
* real one.
|
|
85
|
+
*/
|
|
86
|
+
this.#ready = false;
|
|
87
|
+
this.#lastEmitted = null;
|
|
88
|
+
this.clock = browserClock;
|
|
89
|
+
/**
|
|
90
|
+
* The time spent, for a test with `qti-time-limits` (`test-navigation` starts it and keeps it
|
|
91
|
+
* following the candidate); null for a test without. Saved in `state.session.timing`.
|
|
92
|
+
*/
|
|
93
|
+
this.#timing = null;
|
|
36
94
|
this.addEventListener('qti-testdoc-loaded', () => {
|
|
37
95
|
this.#ready = false;
|
|
38
96
|
this.#lastEmitted = null;
|
|
@@ -68,7 +126,12 @@ export const TestStateMixin = (superClass) => {
|
|
|
68
126
|
this.sessionContext = { ...this.sessionContext, plugins: next };
|
|
69
127
|
}
|
|
70
128
|
get state() {
|
|
71
|
-
|
|
129
|
+
const state = stateFromContexts(this.testContext, this.sessionContext);
|
|
130
|
+
if (!this.#timing)
|
|
131
|
+
return state;
|
|
132
|
+
// Read now: the running stretches counted up to this moment, so a stored state loses nothing.
|
|
133
|
+
const timing = qtiTestTiming(checkpointTiming(storedTiming(this.#timing), this.clock.now()));
|
|
134
|
+
return { ...state, session: { ...state.session, timing } };
|
|
72
135
|
}
|
|
73
136
|
set state(value) {
|
|
74
137
|
if (!isQtiTestState(value)) {
|
|
@@ -99,9 +162,17 @@ export const TestStateMixin = (superClass) => {
|
|
|
99
162
|
super.updated(changed);
|
|
100
163
|
if (!this.#ready || !(changed.has('testContext') || changed.has('sessionContext')))
|
|
101
164
|
return;
|
|
165
|
+
this.#emit(false);
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Sends `qc-test-state-changed` when the state changed. The time spent changes at every read, so
|
|
169
|
+
* it is left out of the comparison: only `saveTiming` sends a state for the time alone.
|
|
170
|
+
*/
|
|
171
|
+
#emit(force) {
|
|
102
172
|
const state = this.state;
|
|
103
|
-
const
|
|
104
|
-
|
|
173
|
+
const { timing: _timing, ...session } = state.session;
|
|
174
|
+
const serialized = JSON.stringify({ ...state, session });
|
|
175
|
+
if (!force && serialized === this.#lastEmitted)
|
|
105
176
|
return;
|
|
106
177
|
this.#lastEmitted = serialized;
|
|
107
178
|
dispatchPublic(this, 'qc-test-state-changed', state);
|
|
@@ -119,12 +190,19 @@ export const TestStateMixin = (superClass) => {
|
|
|
119
190
|
...this.testContext,
|
|
120
191
|
testOutcomeVariables: this.testContext.testOutcomeVariables?.map(v => savedOutcomes.has(v.identifier) ? { ...v, value: copy(savedOutcomes.get(v.identifier)) } : v)
|
|
121
192
|
};
|
|
193
|
+
// The time the test was closed does not count: each running stretch ends where it was saved.
|
|
194
|
+
// A state without timing (saved when the test had no limits, or by 9.x) keeps the time this
|
|
195
|
+
// page has measured so far.
|
|
196
|
+
if (isTiming(state.session.timing)) {
|
|
197
|
+
this.#timing = qtiTestTiming(resumeTiming(storedTiming(state.session.timing)));
|
|
198
|
+
}
|
|
122
199
|
// Written before any navigation request, so the linear-mode restriction — which compares
|
|
123
200
|
// against the current position — sees the restored item as current and lets it load.
|
|
124
201
|
// Plugins are replaced, not merged: a state without them clears what an earlier one left.
|
|
202
|
+
const { timing: _timing, ...session } = state.session;
|
|
125
203
|
this.sessionContext = {
|
|
126
204
|
...this.sessionContext,
|
|
127
|
-
...this.#validSession(
|
|
205
|
+
...this.#validSession(session),
|
|
128
206
|
plugins: state.session.plugins && typeof state.session.plugins === 'object' ? { ...state.session.plugins } : {}
|
|
129
207
|
};
|
|
130
208
|
}
|
|
@@ -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,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC;QAChC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,EAAE,QAAQ,CAAC;QACnC,OAAO,KAAK,CAAC,OAAO,KAAK,QAAQ;QACjC,KAAK,CAAC,OAAO,KAAK,IAAI,CACvB,CAAC;AACJ,CAAC,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAA2C,U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AE,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"]}
|
|
1
|
+
{"version":3,"file":"test-state.mixin.js","sourceRoot":"","sources":["../../src/mixins/test-state.mixin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAE1E,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACtE,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AACjE,OAAO,EA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} from '@qti-components/delivery';\n\nimport { qtiTestTiming, storedTiming } from '../internal/test-timing';\nimport { 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 { Clock } from '@qti-components/delivery';\nimport type { QtiTestState, QtiTestStateSession, QtiTestTiming } 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 /**\n * Where the test reads the time for `qti-time-limits` (roadmap 1 T5): any object with `now()`,\n * milliseconds since the epoch. By default the browser's clock, which a change of the system time\n * does not move. A host whose server keeps the time passes\n * `syncedClock(serverNow)` from `@qti-components/delivery`; to resync, assign a new one. A\n * property, not an attribute.\n */\n clock: Clock;\n /** @internal The time spent, for `test-navigation`; null for a test without `qti-time-limits`. */\n readonly timing: QtiTestTiming | null;\n /** @internal */\n updateTiming(timing: QtiTestTiming | null): void;\n /** @internal */\n saveTiming(): void;\n}\n\n/** The browser's clock, monotonic: setting the system time back gains the candidate nothing. */\nconst browserClock: Clock = { now: () => performance.timeOrigin + performance.now() };\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 */\nconst isStopwatch = (value: unknown): boolean => {\n const stopwatch = value as { spent?: unknown; since?: unknown } | null;\n return (\n typeof stopwatch?.spent === 'number' &&\n Number.isFinite(stopwatch.spent) &&\n (stopwatch.since === null || (typeof stopwatch.since === 'number' && Number.isFinite(stopwatch.since)))\n );\n};\nconst isStopwatches = (value: unknown): boolean =>\n typeof value === 'object' && value !== null && Object.values(value).every(isStopwatch);\n\n/** A stored `session.timing` this release can read; anything else starts the time from now. */\nconst isTiming = (value: unknown): value is QtiTestTiming => {\n const timing = value as Partial<QtiTestTiming> | null | undefined;\n return (\n isStopwatch(timing?.test) &&\n isStopwatches(timing?.testParts) &&\n isStopwatches(timing?.sections) &&\n isStopwatches(timing?.items)\n );\n};\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 clock: Clock = browserClock;\n\n /**\n * The time spent, for a test with `qti-time-limits` (`test-navigation` starts it and keeps it\n * following the candidate); null for a test without. Saved in `state.session.timing`.\n */\n #timing: QtiTestTiming | null = null;\n\n /** @internal For `test-navigation`, through the test host. */\n get timing(): QtiTestTiming | null {\n return this.#timing;\n }\n\n /** @internal For `test-navigation`: the timing after it followed the candidate. */\n updateTiming(timing: QtiTestTiming | null): void {\n this.#timing = timing;\n }\n\n /**\n * @internal For `test-navigation`: sends `qc-test-state-changed` now, with the time spent up to\n * this moment, even when nothing else changed (every 10 seconds while a limit is in force, and\n * when the page is hidden), so a crash loses little time.\n */\n saveTiming(): void {\n if (this.#ready && this.#timing) this.#emit(true);\n }\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 const state = stateFromContexts(this.testContext, this.sessionContext);\n if (!this.#timing) return state;\n // Read now: the running stretches counted up to this moment, so a stored state loses nothing.\n const timing = qtiTestTiming(checkpointTiming(storedTiming(this.#timing), this.clock.now()));\n return { ...state, session: { ...state.session, timing } };\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 this.#emit(false);\n }\n\n /**\n * Sends `qc-test-state-changed` when the state changed. The time spent changes at every read, so\n * it is left out of the comparison: only `saveTiming` sends a state for the time alone.\n */\n #emit(force: boolean): void {\n const state = this.state;\n const { timing: _timing, ...session } = state.session;\n const serialized = JSON.stringify({ ...state, session });\n if (!force && 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 // The time the test was closed does not count: each running stretch ends where it was saved.\n // A state without timing (saved when the test had no limits, or by 9.x) keeps the time this\n // page has measured so far.\n if (isTiming(state.session.timing)) {\n this.#timing = qtiTestTiming(resumeTiming(storedTiming(state.session.timing)));\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 const { timing: _timing, ...session } = state.session;\n this.sessionContext = {\n ...this.sessionContext,\n ...this.#validSession(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"]}
|
package/dist/public-events.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { View } from '@qti-components/base';
|
|
2
2
|
import type { PublicEventDeclaration } from '@qti-components/elements/public-events';
|
|
3
3
|
import type { QtiTestState } from './types/qti-test-state';
|
|
4
|
+
import type { TimeUp } from '@qti-components/delivery';
|
|
4
5
|
/**
|
|
5
6
|
* The public events of the test. The name tells you it is public: everything here starts with
|
|
6
7
|
* `qc-`; every other event is internal plumbing and may change in any release.
|
|
@@ -63,6 +64,15 @@ export interface PublicEventMap {
|
|
|
63
64
|
}>;
|
|
64
65
|
/** Outcome processing ran after a submit: read the test outcomes now. */
|
|
65
66
|
'qc-test-submitted': CustomEvent<Record<string, never>>;
|
|
67
|
+
/**
|
|
68
|
+
* A test part with simultaneous submission was submitted (QTI 3 info model §2.8.2): each item the
|
|
69
|
+
* candidate opened has its one attempt ended and its session closed, with the outcomes its responses
|
|
70
|
+
* scored. Sent before the test's outcome processing; a server may score the part itself.
|
|
71
|
+
*/
|
|
72
|
+
'qc-test-part-submitted': CustomEvent<{
|
|
73
|
+
testPart: string;
|
|
74
|
+
items: string[];
|
|
75
|
+
}>;
|
|
66
76
|
'qc-test-navigated': CustomEvent<NavigationTarget>;
|
|
67
77
|
'qc-test-navigation-started': CustomEvent<NavigationTarget>;
|
|
68
78
|
'qc-test-navigation-failed': CustomEvent<NavigationFailure>;
|
|
@@ -73,6 +83,15 @@ export interface PublicEventMap {
|
|
|
73
83
|
'qc-test-state-changed': CustomEvent<QtiTestState>;
|
|
74
84
|
/** A value assigned to `state` could not be read and was ignored: the test goes on without it. */
|
|
75
85
|
'qc-test-state-refused': CustomEvent<StateRefusal>;
|
|
86
|
+
/**
|
|
87
|
+
* A time limit ran out: `max-time` of the test, a test part, a section or an item instance (`scope`
|
|
88
|
+
* and `identifier`), without `allow-late-submission`. The test has scored the item on screen as it
|
|
89
|
+
* stood and closed every item session under it; it does not submit the test or block the screen,
|
|
90
|
+
* that is the host's (or `<test-time-up>`'s). Once per level while the page lives, and again after
|
|
91
|
+
* a state whose time was up is restored. An expired limit with `allow-late-submission` sends
|
|
92
|
+
* nothing: `computedContext` reports it `late`.
|
|
93
|
+
*/
|
|
94
|
+
'qc-test-time-up': CustomEvent<TimeUp>;
|
|
76
95
|
'qc-test-items-skipped': CustomEvent<{
|
|
77
96
|
ids: string[];
|
|
78
97
|
}>;
|
package/dist/public-events.js
CHANGED
|
@@ -16,6 +16,10 @@ export const PUBLIC_EVENTS = {
|
|
|
16
16
|
'qc-test-state-changed': { kind: 'notification', scope: 'test', deprecated: 'cito-test-state-changed' },
|
|
17
17
|
// New in 10.0, so it has no cito- name.
|
|
18
18
|
'qc-test-state-refused': { kind: 'notification', scope: 'test' },
|
|
19
|
+
// New in 10.0, so it has no cito- name.
|
|
20
|
+
'qc-test-time-up': { kind: 'notification', scope: 'test' },
|
|
21
|
+
// New in 10.0, so it has no cito- name.
|
|
22
|
+
'qc-test-part-submitted': { kind: 'notification', scope: 'test' },
|
|
19
23
|
'qc-test-items-skipped': { kind: 'notification', scope: 'test', deprecated: 'cito-test-items-skipped' },
|
|
20
24
|
'qc-test-end-reached': { kind: 'notification', scope: 'test', deprecated: 'cito-test-end-reached' },
|
|
21
25
|
'qc-item-ref-connected': { kind: 'notification', scope: 'item', deprecated: 'cito-item-ref-connected' }
|
|
@@ -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;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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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"]}
|
|
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+F1F,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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C;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';\nimport type { TimeUp } from '@qti-components/delivery';\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 /**\n * A test part with simultaneous submission was submitted (QTI 3 info model §2.8.2): each item the\n * candidate opened has its one attempt ended and its session closed, with the outcomes its responses\n * scored. Sent before the test's outcome processing; a server may score the part itself.\n */\n 'qc-test-part-submitted': CustomEvent<{ testPart: string; items: string[] }>;\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 /**\n * A time limit ran out: `max-time` of the test, a test part, a section or an item instance (`scope`\n * and `identifier`), without `allow-late-submission`. The test has scored the item on screen as it\n * stood and closed every item session under it; it does not submit the test or block the screen,\n * that is the host's (or `<test-time-up>`'s). Once per level while the page lives, and again after\n * a state whose time was up is restored. An expired limit with `allow-late-submission` sends\n * nothing: `computedContext` reports it `late`.\n */\n 'qc-test-time-up': CustomEvent<TimeUp>;\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 // New in 10.0, so it has no cito- name.\n 'qc-test-time-up': { kind: 'notification', scope: 'test' },\n // New in 10.0, so it has no cito- name.\n 'qc-test-part-submitted': { 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"]}
|
|
@@ -61,5 +61,25 @@ export interface QtiTestStateSession {
|
|
|
61
61
|
navSectionId?: string | null;
|
|
62
62
|
/** The item on screen, as `items[].identifier` names it: a clone is `item-3#2`. */
|
|
63
63
|
navItemRefId?: string | null;
|
|
64
|
+
/** The time spent, for a test with `qti-time-limits` (see `QtiTestTiming`); absent otherwise. */
|
|
65
|
+
timing?: QtiTestTiming;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* The time spent so far (roadmap 1 T5), saved only for a test with `qti-time-limits`: a stopwatch
|
|
69
|
+
* for the test, each test part and section entered, and each item instance (its `duration`, while
|
|
70
|
+
* interacting). Milliseconds: `spent` is the time of the stretches that ended, `since` when the
|
|
71
|
+
* running one began (null when stopped). Read from `state`, the running stretch is already counted
|
|
72
|
+
* up to that moment; assigned back, the time the test was closed does not count.
|
|
73
|
+
*/
|
|
74
|
+
export interface QtiTestTiming {
|
|
75
|
+
test: QtiTestStopwatch;
|
|
76
|
+
testParts: Record<string, QtiTestStopwatch>;
|
|
77
|
+
sections: Record<string, QtiTestStopwatch>;
|
|
78
|
+
/** By item instance, as `items[].identifier` names it. */
|
|
79
|
+
items: Record<string, QtiTestStopwatch>;
|
|
80
|
+
}
|
|
81
|
+
export interface QtiTestStopwatch {
|
|
82
|
+
spent: number;
|
|
83
|
+
since: number | null;
|
|
64
84
|
}
|
|
65
85
|
export declare const QTI_TEST_STATE_VERSION = 1;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"qti-test-state.js","sourceRoot":"","sources":["../../src/types/qti-test-state.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"qti-test-state.js","sourceRoot":"","sources":["../../src/types/qti-test-state.ts"],"names":[],"mappings":"AAyFA,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 /** The time spent, for a test with `qti-time-limits` (see `QtiTestTiming`); absent otherwise. */\n timing?: QtiTestTiming;\n}\n\n/**\n * The time spent so far (roadmap 1 T5), saved only for a test with `qti-time-limits`: a stopwatch\n * for the test, each test part and section entered, and each item instance (its `duration`, while\n * interacting). Milliseconds: `spent` is the time of the stretches that ended, `since` when the\n * running one began (null when stopped). Read from `state`, the running stretch is already counted\n * up to that moment; assigned back, the time the test was closed does not count.\n */\nexport interface QtiTestTiming {\n test: QtiTestStopwatch;\n testParts: Record<string, QtiTestStopwatch>;\n sections: Record<string, QtiTestStopwatch>;\n /** By item instance, as `items[].identifier` names it. */\n items: Record<string, QtiTestStopwatch>;\n}\n\nexport interface QtiTestStopwatch {\n spent: number;\n since: number | null;\n}\n\nexport const QTI_TEST_STATE_VERSION = 1;\n"]}
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@qti-components/test",
|
|
3
3
|
"description": "QTI test utilities",
|
|
4
|
-
"version": "2.0.0-next.
|
|
4
|
+
"version": "2.0.0-next.35",
|
|
5
5
|
"author": "",
|
|
6
6
|
"dependencies": {
|
|
7
7
|
"@heximal/templates": "^0.1.5",
|
|
8
|
-
"@qti-components/base": "^3.0.0-next.
|
|
9
|
-
"@qti-components/delivery": "^0.1.0-next.
|
|
10
|
-
"@qti-components/elements": "^2.0.0-next.
|
|
8
|
+
"@qti-components/base": "^3.0.0-next.18",
|
|
9
|
+
"@qti-components/delivery": "^0.1.0-next.14",
|
|
10
|
+
"@qti-components/elements": "^2.0.0-next.9",
|
|
11
11
|
"@qti-components/interactions": "^1.10.5-next.8",
|
|
12
12
|
"@qti-components/processing": "^1.6.1-next.5",
|
|
13
13
|
"@qti-components/theme": "^3.0.0-next.7",
|