@citolab/qti-components 10.0.0-next.22 → 10.0.0-next.24

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.
@@ -4,7 +4,7 @@ import {
4
4
  control,
5
5
  dispatchPublic,
6
6
  listenPublic as listenPublic2
7
- } from "./chunk-J6VX4N7M.js";
7
+ } from "./chunk-HUM7ST4L.js";
8
8
  import {
9
9
  QtiModalFeedback
10
10
  } from "./chunk-H6DO5UHC.js";
@@ -1905,10 +1905,10 @@ var QtiTestVariablesExpression = class {
1905
1905
  const uniqueItems = [...new Set(this.includedItems.map((item) => item.item))];
1906
1906
  items.forEach((item) => {
1907
1907
  if (uniqueItems.includes(item.identifier)) {
1908
- const variable = item.variables.find((vr) => vr.identifier === this.itemVariable);
1908
+ const variable2 = item.variables.find((vr) => vr.identifier === this.itemVariable);
1909
1909
  const weight = this.includedItems.find((i) => i.item === item.identifier)?.weight ?? 1;
1910
- if (variable) {
1911
- const value = Number(variable.value);
1910
+ if (variable2) {
1911
+ const value = Number(variable2.value);
1912
1912
  if (!Number.isNaN(value)) {
1913
1913
  total += value * weight;
1914
1914
  }
@@ -1922,6 +1922,41 @@ var QtiTestVariablesExpression = class {
1922
1922
  // ../qti-test/dist/types/qti-test-state.js
1923
1923
  var QTI_TEST_STATE_VERSION = 1;
1924
1924
 
1925
+ // ../qti-test/dist/state-from-contexts.js
1926
+ var VARIABLE_TYPES = ["response", "outcome", "template", "context"];
1927
+ var valueOf = (value) => {
1928
+ if (value === null || value === void 0)
1929
+ return null;
1930
+ if (Array.isArray(value))
1931
+ return value.map(String);
1932
+ return String(value);
1933
+ };
1934
+ var variable = ({ identifier, type, value }) => ({
1935
+ identifier,
1936
+ ...VARIABLE_TYPES.includes(type) ? { type } : {},
1937
+ value: valueOf(value)
1938
+ });
1939
+ var stateFromContexts = (testContext2, sessionContext2) => ({
1940
+ version: QTI_TEST_STATE_VERSION,
1941
+ test: {
1942
+ items: (testContext2?.items ?? []).filter((item) => item?.identifier).map((item) => ({
1943
+ identifier: item.identifier,
1944
+ variables: (item.variables ?? []).map(variable),
1945
+ ...item.state ? { state: { ...item.state } } : {}
1946
+ })),
1947
+ outcomes: (testContext2?.testOutcomeVariables ?? []).map((v) => ({
1948
+ identifier: v.identifier,
1949
+ value: valueOf(v.value)
1950
+ }))
1951
+ },
1952
+ session: {
1953
+ ...sessionContext2?.plugins && Object.keys(sessionContext2.plugins).length > 0 ? { plugins: { ...sessionContext2.plugins } } : {},
1954
+ ...sessionContext2?.navPartId !== void 0 ? { navPartId: sessionContext2.navPartId } : {},
1955
+ ...sessionContext2?.navSectionId !== void 0 ? { navSectionId: sessionContext2.navSectionId } : {},
1956
+ ...sessionContext2?.navItemRefId !== void 0 ? { navItemRefId: sessionContext2.navItemRefId } : {}
1957
+ }
1958
+ });
1959
+
1925
1960
  // ../qti-test/dist/components/qti-test/qti-test.js
1926
1961
  import { ContextProvider, provide as provide3 } from "@lit/context";
1927
1962
  import { html as html9, LitElement as LitElement10 } from "lit";
@@ -2637,14 +2672,14 @@ var TestBaseMixin = (superClass) => {
2637
2672
  this._updateItemVariablesInTestContext(identifier, fullVariables, void 0, context.valid);
2638
2673
  } else {
2639
2674
  const newVariables = [...assessmentItem.variables];
2640
- for (const variable of itemContext.variables) {
2641
- if (variable.identifier === "completionStatus" && variable.value === "not_attempted")
2675
+ for (const variable2 of itemContext.variables) {
2676
+ if (variable2.identifier === "completionStatus" && variable2.value === "not_attempted")
2642
2677
  continue;
2643
- const currentVariable = newVariables.find((v) => v.identifier === variable.identifier);
2678
+ const currentVariable = newVariables.find((v) => v.identifier === variable2.identifier);
2644
2679
  if (currentVariable) {
2645
- currentVariable.value = variable.value;
2680
+ currentVariable.value = variable2.value;
2646
2681
  } else {
2647
- newVariables.push(variable);
2682
+ newVariables.push(variable2);
2648
2683
  }
2649
2684
  }
2650
2685
  assessmentItem.variables = newVariables;
@@ -2744,9 +2779,9 @@ var TestBaseMixin = (superClass) => {
2744
2779
  return {
2745
2780
  ...itemContext,
2746
2781
  // Keep other properties of the item context
2747
- variables: variables.map((variable) => {
2748
- const matchingVariable = itemContext.variables.find((v) => v.identifier === variable.identifier);
2749
- return matchingVariable ? { ...matchingVariable, ...variable } : variable;
2782
+ variables: variables.map((variable2) => {
2783
+ const matchingVariable = itemContext.variables.find((v) => v.identifier === variable2.identifier);
2784
+ return matchingVariable ? { ...matchingVariable, ...variable2 } : variable2;
2750
2785
  }),
2751
2786
  ...state6 !== void 0 ? { state: state6 ? { ...state6 } : void 0 } : {},
2752
2787
  ...valid !== void 0 ? { valid } : {}
@@ -2791,31 +2826,12 @@ var isQtiTestState = (value) => {
2791
2826
  const state6 = value;
2792
2827
  return state6?.version === QTI_TEST_STATE_VERSION && Array.isArray(state6.test?.items) && Array.isArray(state6.test?.outcomes) && typeof state6.session === "object" && state6.session !== null;
2793
2828
  };
2794
- var toState = (test, session) => ({
2795
- version: QTI_TEST_STATE_VERSION,
2796
- test: {
2797
- items: (test?.items ?? []).filter((item) => item.identifier).map((item) => ({
2798
- identifier: item.identifier,
2799
- variables: (item.variables ?? []).map((v) => ({
2800
- identifier: v.identifier,
2801
- ...v.type ? { type: v.type } : {},
2802
- value: copy(v.value)
2803
- })),
2804
- ...item.state ? { state: { ...item.state } } : {}
2805
- })),
2806
- outcomes: (test?.testOutcomeVariables ?? []).map((v) => ({ identifier: v.identifier, value: copy(v.value) }))
2807
- },
2808
- session: {
2809
- ...session?.plugins && Object.keys(session.plugins).length > 0 ? { plugins: { ...session.plugins } } : {},
2810
- ...session?.navPartId !== void 0 ? { navPartId: session.navPartId } : {},
2811
- ...session?.navSectionId !== void 0 ? { navSectionId: session.navSectionId } : {},
2812
- ...session?.navItemRefId !== void 0 ? { navItemRefId: session.navItemRefId } : {}
2813
- }
2814
- });
2815
2829
  var TestStateMixin = (superClass) => {
2816
2830
  class TestStateClass extends superClass {
2817
2831
  /** A state assigned before the test connected, applied when it does. */
2818
2832
  #pending = null;
2833
+ /** A refused state assigned before the test connected, reported when it does. */
2834
+ #refused = null;
2819
2835
  /**
2820
2836
  * False while a test document is loading. Loading resets both contexts and rebuilds them, so
2821
2837
  * the intermediate states are empty — emitting one would invite a host to save it over the
@@ -2836,6 +2852,10 @@ var TestStateMixin = (superClass) => {
2836
2852
  this.#pending = null;
2837
2853
  }
2838
2854
  this.#ready = true;
2855
+ if (this.#refused) {
2856
+ dispatchPublic(this, "qc-test-state-refused", this.#refused);
2857
+ this.#refused = null;
2858
+ }
2839
2859
  });
2840
2860
  }
2841
2861
  /** One plugin's entry, as JSON: the test stores it without reading it. `null` removes it. */
@@ -2855,11 +2875,16 @@ var TestStateMixin = (superClass) => {
2855
2875
  this.sessionContext = { ...this.sessionContext, plugins: next };
2856
2876
  }
2857
2877
  get state() {
2858
- return toState(this.testContext, this.sessionContext);
2878
+ return stateFromContexts(this.testContext, this.sessionContext);
2859
2879
  }
2860
2880
  set state(value) {
2861
2881
  if (!isQtiTestState(value)) {
2862
- console.warn(`[qti-test] Ignoring a state that is not a version ${QTI_TEST_STATE_VERSION} QtiTestState.`);
2882
+ const message = `Ignoring a state that is not a version ${QTI_TEST_STATE_VERSION} QtiTestState.`;
2883
+ console.warn(`[qti-test] ${message}`);
2884
+ if (this.#ready)
2885
+ dispatchPublic(this, "qc-test-state-refused", { message, state: value });
2886
+ else
2887
+ this.#refused = { message, state: value };
2863
2888
  return;
2864
2889
  }
2865
2890
  if (!this.#ready) {
@@ -4040,6 +4065,7 @@ export {
4040
4065
  QtiTestVariables,
4041
4066
  QtiTestVariablesExpression,
4042
4067
  QTI_TEST_STATE_VERSION,
4068
+ stateFromContexts,
4043
4069
  QtiTest,
4044
4070
  TestContainer,
4045
4071
  TestEndAttempt,
@@ -4062,4 +4088,4 @@ export {
4062
4088
  * Portions Copyright (c) 2013, the Dart project authors.
4063
4089
  *)
4064
4090
  */
4065
- //# sourceMappingURL=chunk-373IRT4X.js.map
4091
+ //# sourceMappingURL=chunk-2NHZOI3W.js.map