@citolab/qti-components 10.0.0-next.20 → 10.0.0-next.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  QtiTest,
3
3
  TestNavigation
4
- } from "./chunk-ORQFZNJW.js";
4
+ } from "./chunk-TB2OI3ED.js";
5
5
  import {
6
6
  QtiAssessmentItem
7
7
  } from "./chunk-H6DO5UHC.js";
@@ -1686,4 +1686,4 @@ export {
1686
1686
  TestNavigationCorrection,
1687
1687
  QtiTestCorrection
1688
1688
  };
1689
- //# sourceMappingURL=chunk-Y6Q3F2S7.js.map
1689
+ //# sourceMappingURL=chunk-55WWIRLN.js.map
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  qtiTestElements
3
- } from "./chunk-ORQFZNJW.js";
3
+ } from "./chunk-TB2OI3ED.js";
4
4
 
5
5
  // ../qti-test/dist/register.js
6
6
  for (const { tag, ctor } of qtiTestElements) {
@@ -8,4 +8,4 @@ for (const { tag, ctor } of qtiTestElements) {
8
8
  customElements.define(tag, ctor);
9
9
  }
10
10
  }
11
- //# sourceMappingURL=chunk-GJWA6LLT.js.map
11
+ //# sourceMappingURL=chunk-JIDSFFFD.js.map
@@ -1734,6 +1734,38 @@ function itemRefsInOrder(sections) {
1734
1734
  return sections.flatMap((child) => child.kind === "itemRef" ? [child] : itemRefsInOrder(child.content));
1735
1735
  }
1736
1736
 
1737
+ // ../qti-delivery/dist/model/item-facts.js
1738
+ function readItemFacts(item) {
1739
+ if (item.localName !== "qti-assessment-item") {
1740
+ throw new TypeError(`Expected a qti-assessment-item element, not ${String(item.localName)}.`);
1741
+ }
1742
+ const responseDeclarations = childElements(item, "qti-response-declaration");
1743
+ const score = childElements(item, "qti-outcome-declaration").find((declaration) => declaration.getAttribute("identifier") === "SCORE");
1744
+ return {
1745
+ identifier: item.getAttribute("identifier") ?? "",
1746
+ adaptive: booleanAttribute(item, "adaptive") ?? false,
1747
+ timeDependent: booleanAttribute(item, "time-dependent") ?? false,
1748
+ hasCorrectResponse: responseDeclarations.some(hasSomethingToCompareWith),
1749
+ hasResponseProcessing: childElement(item, "qti-response-processing") !== null,
1750
+ externalScored: externalScored(score),
1751
+ label: item.getAttribute("label"),
1752
+ title: item.getAttribute("title") ?? ""
1753
+ };
1754
+ }
1755
+ function hasSomethingToCompareWith(declaration) {
1756
+ if (childElement(declaration, "qti-correct-response"))
1757
+ return true;
1758
+ const mapping = childElement(declaration, "qti-mapping");
1759
+ if (mapping && childElement(mapping, "qti-map-entry"))
1760
+ return true;
1761
+ const areaMapping = childElement(declaration, "qti-area-mapping");
1762
+ return areaMapping !== null && childElement(areaMapping, "qti-area-map-entry") !== null;
1763
+ }
1764
+ function externalScored(declaration) {
1765
+ const value = declaration?.getAttribute("external-scored")?.trim();
1766
+ return value === "human" || value === "externalMachine" ? value : null;
1767
+ }
1768
+
1737
1769
  // ../qti-test/dist/components/qti-test-feedback/qti-test-feedback.js
1738
1770
  var __decorate7 = function(decorators, target, key, desc) {
1739
1771
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
@@ -1897,12 +1929,17 @@ var QtiTestVariablesExpression = class {
1897
1929
  var QTI_TEST_STATE_VERSION = 1;
1898
1930
 
1899
1931
  // ../qti-test/dist/components/qti-test/qti-test.js
1900
- import { ContextProvider, provide as provide2 } from "@lit/context";
1932
+ import { ContextProvider, provide as provide3 } from "@lit/context";
1901
1933
  import { html as html9, LitElement as LitElement10 } from "lit";
1902
- import { state as state2 } from "lit/decorators.js";
1934
+ import { state as state3 } from "lit/decorators.js";
1903
1935
 
1904
1936
  // ../qti-test/dist/mixins/test-navigation.mixin.js
1905
- import { property as property8 } from "lit/decorators.js";
1937
+ import { provide } from "@lit/context";
1938
+ import { property as property8, state as state2 } from "lit/decorators.js";
1939
+
1940
+ // ../qti-test/dist/internal/item-facts.context.js
1941
+ import { createContext as createContext2 } from "@lit/context";
1942
+ var itemFactsContext = createContext2(/* @__PURE__ */ Symbol("itemFacts"));
1906
1943
 
1907
1944
  // ../qti-test/dist/internal/item-sequencing.js
1908
1945
  var SECTION = "qti-assessment-section";
@@ -2009,6 +2046,7 @@ var TestNavigationMixin = (superClass) => {
2009
2046
  this.requestTimeout = 3e4;
2010
2047
  this.postLoadTransformCallback = null;
2011
2048
  this.postLoadTestTransformCallback = null;
2049
+ this.itemFacts = /* @__PURE__ */ new Map();
2012
2050
  this._activeController = null;
2013
2051
  this._loadResults = [];
2014
2052
  this._navigationId = 0;
@@ -2048,6 +2086,7 @@ var TestNavigationMixin = (superClass) => {
2048
2086
  }
2049
2087
  _handleTestConnected(e) {
2050
2088
  this._testElement = e.detail;
2089
+ this.itemFacts = /* @__PURE__ */ new Map();
2051
2090
  this._initializeNavigation();
2052
2091
  }
2053
2092
  /**
@@ -2382,10 +2421,14 @@ var TestNavigationMixin = (superClass) => {
2382
2421
  const validResults = results.filter(Boolean);
2383
2422
  if (this._isStaleNavigation(navigationId, controller))
2384
2423
  return;
2385
- validResults.forEach(({ itemRef, doc }) => {
2424
+ const itemFacts = new Map(this.itemFacts);
2425
+ validResults.forEach(({ itemRef, doc, facts }) => {
2386
2426
  if (itemRef && doc)
2387
2427
  itemRef.xmlDoc = doc;
2428
+ if (itemRef && facts)
2429
+ itemFacts.set(itemRef.identifier, facts);
2388
2430
  });
2431
+ this.itemFacts = itemFacts;
2389
2432
  validResults.forEach(({ itemRef }) => {
2390
2433
  const itemId = itemRef?.identifier;
2391
2434
  if (!itemRef || !itemId)
@@ -2412,7 +2455,9 @@ var TestNavigationMixin = (superClass) => {
2412
2455
  if (this._isStaleNavigation(navigationId, controller)) {
2413
2456
  return null;
2414
2457
  }
2415
- return { itemRef, doc: transformer.htmlDoc(this._customElementRegistry()) };
2458
+ const item = transformer.xmlDoc().documentElement;
2459
+ const facts = item?.localName === "qti-assessment-item" ? readItemFacts(item) : null;
2460
+ return { itemRef, doc: transformer.htmlDoc(this._customElementRegistry()), facts };
2416
2461
  } catch (error) {
2417
2462
  if (error.name === "AbortError") {
2418
2463
  console.info(`Item load for ${itemRef.identifier} was aborted`);
@@ -2517,6 +2562,10 @@ var TestNavigationMixin = (superClass) => {
2517
2562
  __decorate10([
2518
2563
  property8({ attribute: false })
2519
2564
  ], TestNavigationClass.prototype, "postLoadTestTransformCallback", void 0);
2565
+ __decorate10([
2566
+ state2(),
2567
+ provide({ context: itemFactsContext })
2568
+ ], TestNavigationClass.prototype, "itemFacts", void 0);
2520
2569
  return TestNavigationClass;
2521
2570
  };
2522
2571
 
@@ -2569,7 +2618,7 @@ var TestViewMixin = (superClass) => {
2569
2618
  };
2570
2619
 
2571
2620
  // ../qti-test/dist/mixins/test-base.js
2572
- import { provide } from "@lit/context";
2621
+ import { provide as provide2 } from "@lit/context";
2573
2622
  import { LitElement as LitElement9 } from "lit";
2574
2623
  import { property as property9 } from "lit/decorators.js";
2575
2624
  var __decorate11 = function(decorators, target, key, desc) {
@@ -2628,7 +2677,7 @@ var TestBaseMixin = (superClass) => {
2628
2677
  * @param itemRefID The `qti-assessment-item-ref` identifier, not the item's own identifier.
2629
2678
  * @param state Opaque per-interaction state keyed by response identifier, e.g. a PCI's `getState()`.
2630
2679
  */
2631
- updateItemVariables(itemRefID, values, state5) {
2680
+ updateItemVariables(itemRefID, values, state6) {
2632
2681
  this.testContext = {
2633
2682
  ...this.testContext,
2634
2683
  items: this.testContext.items.map((item) => {
@@ -2648,15 +2697,15 @@ var TestBaseMixin = (superClass) => {
2648
2697
  else
2649
2698
  variables.push(updated);
2650
2699
  }
2651
- return { ...item, variables, ...state5 ? { state: { ...state5 } } : {} };
2700
+ return { ...item, variables, ...state6 ? { state: { ...state6 } } : {} };
2652
2701
  })
2653
2702
  };
2654
2703
  const assessmentItem = this._testElement?.querySelector(`qti-assessment-item-ref[identifier="${CSS.escape(itemRefID)}"]`)?.assessmentItem;
2655
2704
  if (!assessmentItem)
2656
2705
  return;
2657
2706
  assessmentItem.variables = [...this.testContext.items.find((i) => i.identifier === itemRefID)?.variables ?? []];
2658
- if (state5)
2659
- assessmentItem.state = state5;
2707
+ if (state6)
2708
+ assessmentItem.state = state6;
2660
2709
  }
2661
2710
  _initializeEventListeners() {
2662
2711
  this.addEventListener("qti-testdoc-loaded", () => {
@@ -2693,7 +2742,7 @@ var TestBaseMixin = (superClass) => {
2693
2742
  this._updateItemVariablesInTestContext(e.detail.itemContext.identifier, e.detail.itemContext.variables, e.detail.itemContext.state, e.detail.itemContext.valid);
2694
2743
  });
2695
2744
  }
2696
- _updateItemVariablesInTestContext(identifier, variables, state5, valid) {
2745
+ _updateItemVariablesInTestContext(identifier, variables, state6, valid) {
2697
2746
  this.testContext = {
2698
2747
  ...this.testContext,
2699
2748
  // Spread existing test context properties
@@ -2708,7 +2757,7 @@ var TestBaseMixin = (superClass) => {
2708
2757
  const matchingVariable = itemContext.variables.find((v) => v.identifier === variable.identifier);
2709
2758
  return matchingVariable ? { ...matchingVariable, ...variable } : variable;
2710
2759
  }),
2711
- ...state5 !== void 0 ? { state: state5 ? { ...state5 } : void 0 } : {},
2760
+ ...state6 !== void 0 ? { state: state6 ? { ...state6 } : void 0 } : {},
2712
2761
  ...valid !== void 0 ? { valid } : {}
2713
2762
  };
2714
2763
  })
@@ -2734,11 +2783,11 @@ var TestBaseMixin = (superClass) => {
2734
2783
  }
2735
2784
  __decorate11([
2736
2785
  property9({ attribute: false, type: Object }),
2737
- provide({ context: testContext })
2786
+ provide2({ context: testContext })
2738
2787
  ], TestBaseClass.prototype, "testContext", void 0);
2739
2788
  __decorate11([
2740
2789
  property9({ attribute: false, type: Object }),
2741
- provide({ context: sessionContext })
2790
+ provide2({ context: sessionContext })
2742
2791
  ], TestBaseClass.prototype, "sessionContext", void 0);
2743
2792
  return TestBaseClass;
2744
2793
  };
@@ -2748,8 +2797,8 @@ var TestBase = class extends TestBaseMixin(LitElement9) {
2748
2797
  // ../qti-test/dist/mixins/test-state.mixin.js
2749
2798
  var copy = (value) => Array.isArray(value) ? [...value] : value ?? null;
2750
2799
  var isQtiTestState = (value) => {
2751
- const state5 = value;
2752
- return state5?.version === QTI_TEST_STATE_VERSION && Array.isArray(state5.test?.items) && Array.isArray(state5.test?.outcomes) && typeof state5.session === "object" && state5.session !== null;
2800
+ const state6 = value;
2801
+ return state6?.version === QTI_TEST_STATE_VERSION && Array.isArray(state6.test?.items) && Array.isArray(state6.test?.outcomes) && typeof state6.session === "object" && state6.session !== null;
2753
2802
  };
2754
2803
  var toState = (test, session) => ({
2755
2804
  version: QTI_TEST_STATE_VERSION,
@@ -2839,25 +2888,25 @@ var TestStateMixin = (superClass) => {
2839
2888
  super.updated(changed);
2840
2889
  if (!this.#ready || !(changed.has("testContext") || changed.has("sessionContext")))
2841
2890
  return;
2842
- const state5 = this.state;
2843
- const serialized = JSON.stringify(state5);
2891
+ const state6 = this.state;
2892
+ const serialized = JSON.stringify(state6);
2844
2893
  if (serialized === this.#lastEmitted)
2845
2894
  return;
2846
2895
  this.#lastEmitted = serialized;
2847
- dispatchPublic(this, "qc-test-state-changed", state5);
2896
+ dispatchPublic(this, "qc-test-state-changed", state6);
2848
2897
  }
2849
- #apply(state5) {
2850
- for (const saved of state5.test.items)
2898
+ #apply(state6) {
2899
+ for (const saved of state6.test.items)
2851
2900
  this.updateItemVariables(saved.identifier, saved.variables, saved.state);
2852
- const savedOutcomes = new Map(state5.test.outcomes.map((outcome) => [outcome.identifier, outcome.value]));
2901
+ const savedOutcomes = new Map(state6.test.outcomes.map((outcome) => [outcome.identifier, outcome.value]));
2853
2902
  this.testContext = {
2854
2903
  ...this.testContext,
2855
2904
  testOutcomeVariables: this.testContext.testOutcomeVariables?.map((v) => savedOutcomes.has(v.identifier) ? { ...v, value: copy(savedOutcomes.get(v.identifier)) } : v)
2856
2905
  };
2857
2906
  this.sessionContext = {
2858
2907
  ...this.sessionContext,
2859
- ...this.#validSession(state5.session),
2860
- plugins: state5.session.plugins && typeof state5.session.plugins === "object" ? { ...state5.session.plugins } : {}
2908
+ ...this.#validSession(state6.session),
2909
+ plugins: state6.session.plugins && typeof state6.session.plugins === "object" ? { ...state6.session.plugins } : {}
2861
2910
  };
2862
2911
  }
2863
2912
  /** A stored position may point at an item or section a revised test no longer has. */
@@ -2994,18 +3043,18 @@ var QtiTest = class extends TestNavigationMixin(TestViewMixin(TestProcessingMixi
2994
3043
  }
2995
3044
  };
2996
3045
  __decorate12([
2997
- state2(),
2998
- provide2({ context: configContext })
3046
+ state3(),
3047
+ provide3({ context: configContext })
2999
3048
  ], QtiTest.prototype, "configContext", void 0);
3000
3049
  __decorate12([
3001
- state2(),
3002
- provide2({ context: qtiContext })
3050
+ state3(),
3051
+ provide3({ context: qtiContext })
3003
3052
  ], QtiTest.prototype, "qtiContext", void 0);
3004
3053
 
3005
3054
  // ../qti-test/dist/components/test-container/test-container.js
3006
3055
  import { consume as consume6 } from "@lit/context";
3007
3056
  import { LitElement as LitElement11, html as html10 } from "lit";
3008
- import { property as property10, state as state3 } from "lit/decorators.js";
3057
+ import { property as property10, state as state4 } from "lit/decorators.js";
3009
3058
  import { until } from "lit/directives/until.js";
3010
3059
  var __decorate13 = function(decorators, target, key, desc) {
3011
3060
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
@@ -3120,16 +3169,16 @@ __decorate13([
3120
3169
  property10({ type: String, attribute: "test-url" })
3121
3170
  ], TestContainer.prototype, "testURL", void 0);
3122
3171
  __decorate13([
3123
- state3()
3172
+ state4()
3124
3173
  ], TestContainer.prototype, "testDoc", void 0);
3125
3174
  __decorate13([
3126
- state3()
3175
+ state4()
3127
3176
  ], TestContainer.prototype, "testXML", void 0);
3128
3177
  __decorate13([
3129
3178
  consume6({ context: testHostContext, subscribe: true })
3130
3179
  ], TestContainer.prototype, "testHost", void 0);
3131
3180
  __decorate13([
3132
- state3(),
3181
+ state4(),
3133
3182
  consume6({ context: qtiContext, subscribe: true })
3134
3183
  ], TestContainer.prototype, "qtiContext", void 0);
3135
3184
  __decorate13([
@@ -3237,9 +3286,9 @@ __decorate14([
3237
3286
  ], TestEndAttempt.prototype, "_handleTestElementChange", null);
3238
3287
 
3239
3288
  // ../qti-test/dist/components/test-navigation/test-navigation.js
3240
- import { ContextConsumer, consume as consume8, provide as provide3 } from "@lit/context";
3289
+ import { ContextConsumer, consume as consume8, provide as provide4 } from "@lit/context";
3241
3290
  import { html as html11, LitElement as LitElement13 } from "lit";
3242
- import { property as property12, state as state4 } from "lit/decorators.js";
3291
+ import { property as property12, state as state5 } from "lit/decorators.js";
3243
3292
 
3244
3293
  // ../qti-test/dist/internal/rendered-markup.js
3245
3294
  function renderedMarkup(element) {
@@ -3331,7 +3380,6 @@ var TestNavigation = class extends LitElement13 {
3331
3380
  this.#itemOrder = [];
3332
3381
  this.#lockedItems = /* @__PURE__ */ new WeakSet();
3333
3382
  listenPublic2(this, "qc-test-loaded", this.#handleTestConnected.bind(this));
3334
- this.addEventListener("qti-assessment-item-connected", this.#handleItemConnected.bind(this));
3335
3383
  listenPublic(this, "qc-item-response-changed", this.#handleInteractionChanged.bind(this));
3336
3384
  this.addEventListener("qti-item-context-updated", this.#handleItemContextUpdated.bind(this));
3337
3385
  listenPublic2(this, "qc-test-end-attempt", this.#handleTestEndAttempt.bind(this));
@@ -3547,50 +3595,13 @@ var TestNavigation = class extends LitElement13 {
3547
3595
  });
3548
3596
  return defaultValues;
3549
3597
  }
3550
- /* PK: on item connected we can add item only properties in the xml */
3551
- #handleItemConnected(event) {
3552
- const itemElement = event.detail;
3553
- this.computedContext = {
3554
- ...this.computedContext,
3555
- testParts: this.computedContext.testParts.map((testPart) => {
3556
- return {
3557
- ...testPart,
3558
- sections: testPart.sections.map((section) => {
3559
- return {
3560
- ...section,
3561
- items: section.items.map((item) => {
3562
- if (item.identifier !== itemElement.parentElement.getAttribute("identifier")) {
3563
- return item;
3564
- }
3565
- const scoreOutcome = itemElement.querySelector("qti-outcome-declaration[identifier='SCORE']");
3566
- const externalScored = scoreOutcome?.getAttribute("externalScored");
3567
- const responseDeclarations = itemElement.querySelectorAll("qti-response-declaration");
3568
- const containsCorrectResponse = Array.from(responseDeclarations).some((r) => r.querySelector("qti-correct-response"));
3569
- const containsMapping = Array.from(responseDeclarations).some((r) => {
3570
- const mapping = r.querySelector("qti-mapping");
3571
- const areaMapping = r.querySelector("qti-area-mapping");
3572
- return mapping?.querySelector("qti-map-entry") || areaMapping?.querySelector("qti-area-map-entry");
3573
- });
3574
- const hasCorrectResponse = containsCorrectResponse || containsMapping;
3575
- const hasResponseProcessing = itemElement.querySelector("qti-response-processing") ? true : false;
3576
- return {
3577
- ...item,
3578
- assessmentItemIdentifier: itemElement.getAttribute("identifier"),
3579
- label: itemElement.getAttribute("label"),
3580
- title: itemElement.title,
3581
- externalScored,
3582
- adaptive: itemElement.adaptive == "true" || false,
3583
- timeDependent: itemElement.timeDependent == "true" || false,
3584
- variables: itemElement.variables,
3585
- hasCorrectResponse,
3586
- hasResponseProcessing
3587
- };
3588
- })
3589
- };
3590
- })
3591
- };
3592
- })
3593
- };
3598
+ /** An item's facts as `computedContext` has carried them; nothing until the item is fetched. */
3599
+ #factsFor(identifier) {
3600
+ const facts = this._itemFacts?.get(identifier);
3601
+ if (!facts)
3602
+ return {};
3603
+ const { identifier: assessmentItemIdentifier, ...rest } = facts;
3604
+ return { ...rest, assessmentItemIdentifier };
3594
3605
  }
3595
3606
  /* PK: on every change of the candidate we will recomputed the computedContext */
3596
3607
  willUpdate(_changedProperties) {
@@ -3614,6 +3625,7 @@ var TestNavigation = class extends LitElement13 {
3614
3625
  const itemContext = this._testContext?.items.find((i) => i.identifier === item.identifier);
3615
3626
  const computedItem = {
3616
3627
  ...item,
3628
+ ...this.#factsFor(item.identifier),
3617
3629
  ...itemContext,
3618
3630
  ...this.initContext?.find((i) => i.identifier === item.identifier)
3619
3631
  };
@@ -3833,23 +3845,27 @@ __decorate15([
3833
3845
  property12({ type: String })
3834
3846
  ], TestNavigation.prototype, "identifier", void 0);
3835
3847
  __decorate15([
3836
- state4()
3848
+ state5()
3837
3849
  ], TestNavigation.prototype, "initContext", void 0);
3838
3850
  __decorate15([
3839
- state4(),
3851
+ state5(),
3840
3852
  consume8({ context: configContext, subscribe: true })
3841
3853
  ], TestNavigation.prototype, "configContext", void 0);
3842
3854
  __decorate15([
3843
- state4(),
3855
+ state5(),
3844
3856
  consume8({ context: testContext, subscribe: true })
3845
3857
  ], TestNavigation.prototype, "_testContext", void 0);
3846
3858
  __decorate15([
3847
- state4(),
3859
+ state5(),
3848
3860
  consume8({ context: sessionContext, subscribe: true })
3849
3861
  ], TestNavigation.prototype, "_sessionContext", void 0);
3850
3862
  __decorate15([
3851
- state4(),
3852
- provide3({ context: computedContext })
3863
+ state5(),
3864
+ consume8({ context: itemFactsContext, subscribe: true })
3865
+ ], TestNavigation.prototype, "_itemFacts", void 0);
3866
+ __decorate15([
3867
+ state5(),
3868
+ provide4({ context: computedContext })
3853
3869
  ], TestNavigation.prototype, "computedContext", void 0);
3854
3870
  __decorate15([
3855
3871
  property12({ type: Boolean, attribute: "auto-score-items" })
@@ -4069,4 +4085,4 @@ export {
4069
4085
  * Portions Copyright (c) 2013, the Dart project authors.
4070
4086
  *)
4071
4087
  */
4072
- //# sourceMappingURL=chunk-ORQFZNJW.js.map
4088
+ //# sourceMappingURL=chunk-TB2OI3ED.js.map