@citolab/qti-components 10.0.0-next.30 → 10.0.0-next.31

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/base.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { C as ComputedItemContext } from './session.context.d-9gRdGK4T.js';
2
2
  export { I as INITIAL_SESSION_CONTEXT, S as SessionContext, V as View, s as sessionContext } from './session.context.d-9gRdGK4T.js';
3
- import { C as ComputedContext } from './computed.types.d-BPzPFX3Z.js';
4
- export { a as ComputedItem, S as SessionControl } from './computed.types.d-BPzPFX3Z.js';
3
+ import { C as ComputedContext } from './computed.types.d-D06SAPP2.js';
4
+ export { a as ComputedItem, I as ItemLifecycleState, b as ItemRules, S as SessionControl } from './computed.types.d-D06SAPP2.js';
5
5
  export { C as ConfigContext, V as ValidationDisplayMode, c as configContext } from './config.context.d-Dm11aAuw.js';
6
6
  export { C as ChoiceRole, I as Interaction, a as InteractionContext, R as RecordFieldValues, b as RecordValue, V as ValidityKind, c as ValidityTrigger, i as inferRecordFieldBaseType, d as interactionContext, e as isRecordValue, r as readRecordFieldValues } from './record.d-N1Bq7e1f.js';
7
7
  import { I as ItemContext } from './item.types.d-Zc6ZQDhu.js';
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  qtiTestElements
3
- } from "./chunk-YRR6D6UP.js";
3
+ } from "./chunk-R352K4KZ.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-5KNTKBP6.js.map
11
+ //# sourceMappingURL=chunk-3HG5GIKR.js.map
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  QtiTest,
3
3
  TestNavigation
4
- } from "./chunk-YRR6D6UP.js";
4
+ } from "./chunk-R352K4KZ.js";
5
5
  import {
6
6
  QtiAssessmentItem
7
7
  } from "./chunk-GAPMCYR5.js";
@@ -1686,4 +1686,4 @@ export {
1686
1686
  TestNavigationCorrection,
1687
1687
  QtiTestCorrection
1688
1688
  };
1689
- //# sourceMappingURL=chunk-2ZT47EUK.js.map
1689
+ //# sourceMappingURL=chunk-5LNSB6J6.js.map
@@ -1761,6 +1761,129 @@ function externalScored(declaration) {
1761
1761
  return value === "human" || value === "externalMachine" ? value : null;
1762
1762
  }
1763
1763
 
1764
+ // ../qti-delivery/dist/lifecycle/item-lifecycle.js
1765
+ var ITEM_LIFECYCLE = {
1766
+ initial: {
1767
+ beginAttempt: [{ to: "interacting", when: ["attemptsLeft"] }],
1768
+ endItemSession: "closed"
1769
+ },
1770
+ interacting: {
1771
+ // The guards are read after response processing, with the ended attempt counted.
1772
+ endAttempt: [
1773
+ { to: "closed", when: ["individualSubmission"], unless: ["attemptsLeft"] },
1774
+ { to: "modalFeedback", when: ["individualSubmission", "attemptsLeft", "modalFeedback"] },
1775
+ { to: "interacting", when: ["individualSubmission", "attemptsLeft"] }
1776
+ ],
1777
+ endCandidateSession: "suspended",
1778
+ endItemSession: "closed"
1779
+ },
1780
+ modalFeedback: {
1781
+ beginAttempt: [{ to: "interacting", when: ["attemptsLeft"] }],
1782
+ endCandidateSession: "suspended",
1783
+ endItemSession: "closed"
1784
+ },
1785
+ suspended: {
1786
+ beginCandidateSession: [{ to: "interacting", when: ["mayResume"] }],
1787
+ endItemSession: "closed"
1788
+ },
1789
+ closed: {
1790
+ beginReview: [{ to: "review", when: ["allowReview"] }],
1791
+ beginSolution: [{ to: "solution", when: ["showSolution"] }]
1792
+ },
1793
+ review: {
1794
+ endReview: "closed"
1795
+ },
1796
+ solution: {
1797
+ endSolution: "closed"
1798
+ }
1799
+ };
1800
+ function transition(state6, event, guards) {
1801
+ const target = ITEM_LIFECYCLE[state6][event];
1802
+ if (target === void 0)
1803
+ return null;
1804
+ if (typeof target === "string")
1805
+ return target;
1806
+ const branch = target.find(({ when = [], unless = [] }) => when.every((guard) => guards[guard]) && !unless.some((guard) => guards[guard]));
1807
+ return branch?.to ?? null;
1808
+ }
1809
+ function hasAttemptsLeft({ sessionControl: { maxAttempts }, adaptive, numAttempts, completionStatus }) {
1810
+ if (adaptive)
1811
+ return completionStatus !== "completed";
1812
+ return maxAttempts === 0 || numAttempts < maxAttempts;
1813
+ }
1814
+ function itemLifecycleGuards(input) {
1815
+ return {
1816
+ attemptsLeft: hasAttemptsLeft(input),
1817
+ // In a simultaneous part every response is processed when the part is submitted (§4.1).
1818
+ individualSubmission: input.submissionMode === "individual",
1819
+ modalFeedback: input.modalFeedback,
1820
+ // A linear part restricts the candidate to each item in turn: once left, never again (§4.1).
1821
+ mayResume: input.navigationMode === "nonlinear" || !input.left,
1822
+ allowReview: input.sessionControl.allowReview,
1823
+ showSolution: input.sessionControl.showSolution
1824
+ };
1825
+ }
1826
+ function seedItemLifecycle(input) {
1827
+ if (!hasAttemptsLeft(input) || input.passed)
1828
+ return "closed";
1829
+ if (input.presented)
1830
+ return "interacting";
1831
+ return input.numAttempts === 0 ? "initial" : "suspended";
1832
+ }
1833
+
1834
+ // ../qti-delivery/dist/lifecycle/item-rules.js
1835
+ function itemRules(input) {
1836
+ const { state: state6, sessionControl, adaptive } = input;
1837
+ const guards = itemLifecycleGuards(input);
1838
+ const individual = guards.individualSubmission;
1839
+ const maySkip = !individual || sessionControl.allowSkipping || !input.skipped;
1840
+ const maySubmit = maySkip && (!individual || !sessionControl.validateResponses || input.valid);
1841
+ return {
1842
+ attemptsLeft: guards.attemptsLeft,
1843
+ attemptsUsed: !guards.attemptsLeft,
1844
+ interactive: state6 === "interacting",
1845
+ done: state6 === "closed" || state6 === "review" || state6 === "solution",
1846
+ mayEndAttempt: maySubmit && transition(state6, "endAttempt", guards) !== null,
1847
+ maySubmit,
1848
+ maySkip,
1849
+ mayShowFeedback: guards.attemptsLeft || sessionControl.showFeedback || state6 === "review" && adaptive && sessionControl.allowReview,
1850
+ mayBeginReview: transition(state6, "beginReview", guards) !== null,
1851
+ mayBeginSolution: transition(state6, "beginSolution", guards) !== null
1852
+ };
1853
+ }
1854
+
1855
+ // ../qti-delivery/dist/lifecycle/item-session.js
1856
+ var guardsFor = (facts) => (
1857
+ // Modal feedback does not stop a session yet: nothing reports it, so `modalFeedback` is never entered.
1858
+ itemLifecycleGuards({ ...facts, left: facts.passed, modalFeedback: false })
1859
+ );
1860
+ var OVER = ["closed", "review", "solution"];
1861
+ function followItemSession(previous, facts) {
1862
+ const { numAttempts } = facts;
1863
+ if (!previous || previous.numAttempts !== numAttempts)
1864
+ return { state: seedItemLifecycle(facts), numAttempts };
1865
+ const guards = guardsFor(facts);
1866
+ let state6 = previous.state;
1867
+ if (facts.passed) {
1868
+ if (!OVER.includes(state6))
1869
+ state6 = transition(state6, "endItemSession", guards) ?? state6;
1870
+ } else if (facts.presented) {
1871
+ if (state6 === "initial")
1872
+ state6 = transition(state6, "beginAttempt", guards) ?? state6;
1873
+ else if (state6 === "suspended")
1874
+ state6 = transition(state6, "beginCandidateSession", guards) ?? state6;
1875
+ } else if (state6 === "interacting" || state6 === "modalFeedback") {
1876
+ state6 = transition(state6, "endCandidateSession", guards) ?? state6;
1877
+ }
1878
+ return { state: state6, numAttempts };
1879
+ }
1880
+ function endItemAttempt(previous, facts) {
1881
+ const { numAttempts } = facts;
1882
+ if (previous?.state !== "interacting")
1883
+ return { state: seedItemLifecycle({ ...facts, presented: true }), numAttempts };
1884
+ return { state: transition("interacting", "endAttempt", guardsFor(facts)) ?? "interacting", numAttempts };
1885
+ }
1886
+
1764
1887
  // ../qti-test/dist/components/qti-test-feedback/qti-test-feedback.js
1765
1888
  var __decorate7 = function(decorators, target, key, desc) {
1766
1889
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
@@ -3348,12 +3471,12 @@ function deriveComputedContext(inputs) {
3348
3471
  allowSkipping: section.sessionControl.allowSkipping,
3349
3472
  // A section that only holds subsections is completed when theirs are.
3350
3473
  completed: itemRefsInOrder(section.content).every((item) => variableValue(itemContextFor(inputs, item.identifier), "completionStatus") === "completed"),
3351
- items: ownItemRefs(section).map((item) => deriveItem(inputs, item, itemIndexes.get(item.identifier) ?? null))
3474
+ items: ownItemRefs(section).map((item) => deriveItem(inputs, testPart, item, itemIndexes.get(item.identifier) ?? null))
3352
3475
  }))
3353
3476
  }))
3354
3477
  };
3355
3478
  }
3356
- function deriveItem(inputs, item, index) {
3479
+ function deriveItem(inputs, testPart, item, index) {
3357
3480
  const itemContext = itemContextFor(inputs, item.identifier);
3358
3481
  const computedItem = {
3359
3482
  active: false,
@@ -3389,8 +3512,34 @@ function deriveItem(inputs, item, index) {
3389
3512
  maxScore,
3390
3513
  done: isItemDone(numAttempts, optimality, computedItem.sessionControl?.maxAttempts, computedItem.adaptive, completionStatus),
3391
3514
  // Reflects the last *ended* attempt only: the latch, not the fallback above.
3392
- optimal: latched === "optimal"
3515
+ optimal: latched === "optimal",
3516
+ ...lifecycleOf(inputs, testPart, item, itemContext, { numAttempts, completionStatus })
3517
+ };
3518
+ }
3519
+ function lifecycleOf(inputs, testPart, item, itemContext, { numAttempts, completionStatus }) {
3520
+ const session = {
3521
+ sessionControl: item.sessionControl,
3522
+ adaptive: inputs.itemFacts?.get(item.identifier)?.adaptive ?? false,
3523
+ navigationMode: testPart.navigationMode,
3524
+ submissionMode: testPart.submissionMode,
3525
+ numAttempts,
3526
+ completionStatus: completionStatus ?? null
3393
3527
  };
3528
+ const lifecycle = inputs.lifecycle?.get(item.identifier) ?? seedItemLifecycle({
3529
+ ...session,
3530
+ presented: inputs.sessionContext?.navItemRefId === item.identifier,
3531
+ passed: false
3532
+ });
3533
+ const rules = itemRules({
3534
+ ...session,
3535
+ state: lifecycle,
3536
+ // Only resuming reads it, and no answer asks about resuming.
3537
+ left: false,
3538
+ modalFeedback: false,
3539
+ skipped: isSkipped(itemContext),
3540
+ valid: itemContext?.valid ?? true
3541
+ });
3542
+ return { lifecycle, rules };
3394
3543
  }
3395
3544
  function itemContextFor(inputs, identifier) {
3396
3545
  return inputs.testContext?.items?.find((item) => item.identifier === identifier);
@@ -3409,6 +3558,12 @@ function indexesInDocumentOrder(items, infoItemCategory) {
3409
3558
  let index = 1;
3410
3559
  return new Map(items.map((item) => [item.identifier, item.categories.includes(infoItemCategory) ? null : index++]));
3411
3560
  }
3561
+ function isSkipped(itemContext) {
3562
+ if (!itemContext)
3563
+ return true;
3564
+ const responses = itemContext.variables?.filter((v) => v.type === "response" && v.identifier !== "numAttempts" && v.identifier !== "duration");
3565
+ return Boolean(responses?.length) && isDefaultResponse(itemContext);
3566
+ }
3412
3567
  function isDefaultResponse(itemContext) {
3413
3568
  const responseVariables = itemContext?.variables?.filter((v) => v.type === "response" && v.identifier !== "numAttempts") || [];
3414
3569
  return responseVariables.every((v) => {
@@ -3478,6 +3633,36 @@ function numericVariable(variables, identifier) {
3478
3633
  return Number.isNaN(parsed) ? null : parsed;
3479
3634
  }
3480
3635
 
3636
+ // ../qti-test/dist/internal/item-session-facts.js
3637
+ function itemSessionFacts(model, itemFacts, items, { current, presented }) {
3638
+ const facts = /* @__PURE__ */ new Map();
3639
+ for (const testPart of model.testParts) {
3640
+ const order = itemRefsInOrder(testPart.sections);
3641
+ const currentIndex = order.findIndex((item) => item.identifier === current);
3642
+ order.forEach((item, index) => {
3643
+ const context = items?.find((candidate) => candidate.identifier === item.identifier);
3644
+ facts.set(item.identifier, {
3645
+ ...attemptsOf(context),
3646
+ sessionControl: item.sessionControl,
3647
+ adaptive: itemFacts?.get(item.identifier)?.adaptive ?? false,
3648
+ navigationMode: testPart.navigationMode,
3649
+ submissionMode: testPart.submissionMode,
3650
+ presented: presented.has(item.identifier),
3651
+ passed: testPart.navigationMode === "linear" && currentIndex >= 0 && index < currentIndex
3652
+ });
3653
+ });
3654
+ }
3655
+ return facts;
3656
+ }
3657
+ function attemptsOf(context) {
3658
+ const value = (identifier) => context?.variables?.find((v) => v.identifier === identifier)?.value;
3659
+ const completionStatus = value("completionStatus");
3660
+ return {
3661
+ numAttempts: Number(value("numAttempts")) || 0,
3662
+ completionStatus: typeof completionStatus === "string" ? completionStatus : null
3663
+ };
3664
+ }
3665
+
3481
3666
  // ../qti-test/dist/internal/rendered-markup.js
3482
3667
  function renderedMarkup(element) {
3483
3668
  return {
@@ -3545,6 +3730,15 @@ var TestNavigation = class extends LitElement13 {
3545
3730
  * doesn't flip `done` until the candidate ends the attempt.
3546
3731
  */
3547
3732
  #optimality;
3733
+ /**
3734
+ * Each item session's lifecycle state, by item-ref identifier, changed only through the lifecycle
3735
+ * table (`followItemSession` as the candidate moves, `endItemAttempt` when an attempt ends). It
3736
+ * lives here until `DeliveryState` holds it (roadmap 1, T3d); a session whose attempts change
3737
+ * outside an ended attempt (a restored or assigned state) is seeded again.
3738
+ */
3739
+ #sessions;
3740
+ /** Set while `auto-score-items` scores a change: that run is not the candidate ending an attempt. */
3741
+ #autoScoring;
3548
3742
  constructor() {
3549
3743
  super();
3550
3744
  this.identifier = void 0;
@@ -3563,6 +3757,8 @@ var TestNavigation = class extends LitElement13 {
3563
3757
  this.configContext = {};
3564
3758
  this.autoScoreItems = false;
3565
3759
  this.#optimality = /* @__PURE__ */ new Map();
3760
+ this.#sessions = /* @__PURE__ */ new Map();
3761
+ this.#autoScoring = false;
3566
3762
  this.#itemElement = (identifier) => this.#assessmentItemFor(identifier) ?? null;
3567
3763
  this.#lockedItems = /* @__PURE__ */ new WeakSet();
3568
3764
  listenPublic2(this, "qc-test-loaded", this.#handleTestConnected.bind(this));
@@ -3586,11 +3782,37 @@ var TestNavigation = class extends LitElement13 {
3586
3782
  return;
3587
3783
  const optimality = assessOptimality(itemContext);
3588
3784
  this.#optimality.set(itemContext.identifier, optimality);
3785
+ this.#endAttempt(itemContext);
3589
3786
  const computedItem = this.computedItemFor(itemContext.identifier);
3590
3787
  const numAttempts = Number(itemContext.variables?.find((v) => v.identifier === "numAttempts")?.value) || 0;
3591
3788
  const completionStatus = itemContext.variables?.find((v) => v.identifier === "completionStatus")?.value;
3592
3789
  this.afterAttemptEnded(event.composedPath()[0]?.closest("qti-assessment-item"), computedItem, isItemDone(numAttempts, optimality, computedItem?.sessionControl?.maxAttempts, computedItem?.adaptive, completionStatus));
3593
3790
  }
3791
+ /** Moves the item's session on for its ended attempt; an auto-scored change only updates its count. */
3792
+ #endAttempt(itemContext) {
3793
+ const facts = this.#sessionFacts().get(itemContext.identifier);
3794
+ if (!facts)
3795
+ return;
3796
+ const ended = { ...facts, ...attemptsOf(itemContext) };
3797
+ const previous = this.#sessions.get(itemContext.identifier);
3798
+ this.#sessions.set(itemContext.identifier, this.#autoScoring ? { state: previous?.state ?? followItemSession(void 0, ended).state, numAttempts: ended.numAttempts } : endItemAttempt(previous, ended));
3799
+ }
3800
+ /** The facts of every item session now: the model, the item facts, the contexts and the items on screen. */
3801
+ #sessionFacts() {
3802
+ if (!this.#model)
3803
+ return /* @__PURE__ */ new Map();
3804
+ const presented = new Set([...this.#testElement?.querySelectorAll("qti-assessment-item-ref") ?? []].filter((itemRef) => itemRef.assessmentItem).map((itemRef) => itemRef.identifier));
3805
+ return itemSessionFacts(this.#model, this._itemFacts, this._testContext?.items, {
3806
+ current: this._sessionContext?.navItemRefId,
3807
+ presented
3808
+ });
3809
+ }
3810
+ /** Moves every item session on for where the candidate is now. */
3811
+ #followSessions() {
3812
+ for (const [identifier, facts] of this.#sessionFacts()) {
3813
+ this.#sessions.set(identifier, followItemSession(this.#sessions.get(identifier), facts));
3814
+ }
3815
+ }
3594
3816
  /**
3595
3817
  * Extension point for presentation packages reacting to an ended attempt.
3596
3818
  * `done` is settled here — from the freshly latched optimality and the
@@ -3644,7 +3866,12 @@ var TestNavigation = class extends LitElement13 {
3644
3866
  const scoreOutcomeIdentifier = assessmentItem.variables.find((v) => v.identifier === "SCORE");
3645
3867
  if (scoreOutcomeIdentifier && scoreOutcomeIdentifier.externalScored === null && assessmentItem.adaptive === "false") {
3646
3868
  const reportValidityAfterScoring = this.configContext?.reportValidityAfterScoring === true ? true : false;
3647
- assessmentItem.processResponse(true, reportValidityAfterScoring);
3869
+ this.#autoScoring = true;
3870
+ try {
3871
+ assessmentItem.processResponse(true, reportValidityAfterScoring);
3872
+ } finally {
3873
+ this.#autoScoring = false;
3874
+ }
3648
3875
  }
3649
3876
  }
3650
3877
  }
@@ -3655,6 +3882,7 @@ var TestNavigation = class extends LitElement13 {
3655
3882
  #handleTestConnected(event) {
3656
3883
  this.#testElement = event.detail;
3657
3884
  this.#optimality.clear();
3885
+ this.#sessions.clear();
3658
3886
  if (!this.qtiContext.QTI_CONTEXT?.testIdentifier) {
3659
3887
  const currentContext = this.qtiContext.QTI_CONTEXT || {
3660
3888
  testIdentifier: "",
@@ -3691,6 +3919,7 @@ var TestNavigation = class extends LitElement13 {
3691
3919
  /** `computedContext`, derived anew from its inputs (`deriveComputedContext`), never from the previous one. */
3692
3920
  #derive() {
3693
3921
  this.#seedOptimality();
3922
+ this.#followSessions();
3694
3923
  return deriveComputedContext({
3695
3924
  model: this.#model,
3696
3925
  itemFacts: this._itemFacts,
@@ -3699,6 +3928,7 @@ var TestNavigation = class extends LitElement13 {
3699
3928
  infoItemCategory: this.configContext?.infoItemCategory,
3700
3929
  itemData: this.initContext,
3701
3930
  optimality: this.#optimality,
3931
+ lifecycle: new Map([...this.#sessions].map(([identifier, session]) => [identifier, session.state])),
3702
3932
  itemElement: this.#itemElement
3703
3933
  });
3704
3934
  }
@@ -4052,4 +4282,4 @@ export {
4052
4282
  * Portions Copyright (c) 2013, the Dart project authors.
4053
4283
  *)
4054
4284
  */
4055
- //# sourceMappingURL=chunk-YRR6D6UP.js.map
4285
+ //# sourceMappingURL=chunk-R352K4KZ.js.map