@citolab/qti-components 10.0.0-next.13 → 10.0.0-next.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/cdn/index.global.js +1 -1
  2. package/cdn/index.js +522 -435
  3. package/dist/base.d.ts +4 -4
  4. package/dist/base.js +1 -1
  5. package/dist/{chunk-PHRHLDQB.js → chunk-32PI7KWX.js} +2 -2
  6. package/dist/{chunk-MDBNEEPH.js → chunk-5AJZGRWI.js} +8 -3
  7. package/dist/chunk-5AJZGRWI.js.map +1 -0
  8. package/dist/{chunk-LFVPS7KB.js → chunk-DAOLVUTR.js} +2 -2
  9. package/dist/{chunk-K4WLYVDT.js → chunk-F553IZPL.js} +2 -2
  10. package/dist/{chunk-HOGJ5ZNW.js → chunk-G2EIC7H2.js} +221 -107
  11. package/dist/chunk-G2EIC7H2.js.map +1 -0
  12. package/dist/{chunk-EIBGCCXH.js → chunk-HT3LSWXL.js} +2 -2
  13. package/dist/{chunk-WUIA4OOX.js → chunk-IM5AKPIJ.js} +34 -6
  14. package/dist/chunk-IM5AKPIJ.js.map +1 -0
  15. package/dist/{chunk-FLAD6SC6.js → chunk-IWNRQVNW.js} +2 -2
  16. package/dist/{chunk-TLAVOBEM.js → chunk-LORYM4U2.js} +120 -1
  17. package/dist/chunk-LORYM4U2.js.map +1 -0
  18. package/dist/{chunk-Y5DZTCDP.js → chunk-MIQZBDTB.js} +225 -258
  19. package/dist/chunk-MIQZBDTB.js.map +1 -0
  20. package/dist/{chunk-AKX4YMWU.js → chunk-QT7WQXCS.js} +237 -95
  21. package/dist/chunk-QT7WQXCS.js.map +1 -0
  22. package/dist/chunk-RNLSNH4N.js +7 -0
  23. package/dist/chunk-RNLSNH4N.js.map +1 -0
  24. package/dist/{chunk-H3GITIPE.js → chunk-URYYGVTA.js} +23 -7
  25. package/dist/chunk-URYYGVTA.js.map +1 -0
  26. package/dist/{chunk-G6LTYTJR.js → chunk-WIUPAUJV.js} +2 -2
  27. package/dist/{chunk-PYHKCIYN.js → chunk-XY5DHYIH.js} +4 -4
  28. package/dist/{config.context.d-BniMHSBB.d.ts → config.context.d-CCqlJXpE.d.ts} +2 -1
  29. package/dist/corrections.d.ts +8 -8
  30. package/dist/corrections.js +9 -9
  31. package/dist/elements.d.ts +84 -14
  32. package/dist/elements.js +4 -4
  33. package/dist/index.d.ts +9 -9
  34. package/dist/index.js +15 -15
  35. package/dist/interactions.d.ts +17 -5
  36. package/dist/interactions.js +3 -3
  37. package/dist/item.css +132 -18
  38. package/dist/item.d.ts +4 -4
  39. package/dist/item.js +5 -5
  40. package/dist/loader.d.ts +2 -2
  41. package/dist/loader.js +2 -2
  42. package/dist/processing.d.ts +8 -4
  43. package/dist/processing.js +3 -3
  44. package/dist/qti-components-jsx.d.ts +291 -115
  45. package/dist/{qti-feedback.d-DbzPSJuK.d.ts → qti-feedback.d-GAqMqAt6.d.ts} +7 -0
  46. package/dist/{qti-item.d-BqWYBdV2.d.ts → qti-item.d-pFcNk0th.d.ts} +1 -1
  47. package/dist/{qti-rule-base.d-Bdzg8eGH.d.ts → qti-rule-base.d-CeKP0Ooi.d.ts} +2 -2
  48. package/dist/{qti-test.d-B6AGSQlk.d.ts → qti-test.d-BjhVQnQy.d.ts} +31 -5
  49. package/dist/{qti-text-entry-interaction.d-B44Z3qUG.d.ts → qti-text-entry-interaction.d-DECzpIzi.d.ts} +50 -14
  50. package/dist/{qti-transform-test.d-BL7GGFJj.d.ts → qti-transform-test.d-Bb9vnLzP.d.ts} +1 -0
  51. package/dist/{record.d-C6m0Y4xr.d.ts → record.d-CljDLwRz.d.ts} +1 -1
  52. package/dist/test.d.ts +6 -6
  53. package/dist/test.js +6 -6
  54. package/dist/transformers.d.ts +1 -1
  55. package/dist/transformers.js +1 -1
  56. package/package.json +11 -11
  57. package/dist/chunk-AKX4YMWU.js.map +0 -1
  58. package/dist/chunk-DVLSXMXD.js +0 -7
  59. package/dist/chunk-DVLSXMXD.js.map +0 -1
  60. package/dist/chunk-H3GITIPE.js.map +0 -1
  61. package/dist/chunk-HOGJ5ZNW.js.map +0 -1
  62. package/dist/chunk-MDBNEEPH.js.map +0 -1
  63. package/dist/chunk-TLAVOBEM.js.map +0 -1
  64. package/dist/chunk-WUIA4OOX.js.map +0 -1
  65. package/dist/chunk-Y5DZTCDP.js.map +0 -1
  66. /package/dist/{chunk-PHRHLDQB.js.map → chunk-32PI7KWX.js.map} +0 -0
  67. /package/dist/{chunk-LFVPS7KB.js.map → chunk-DAOLVUTR.js.map} +0 -0
  68. /package/dist/{chunk-K4WLYVDT.js.map → chunk-F553IZPL.js.map} +0 -0
  69. /package/dist/{chunk-EIBGCCXH.js.map → chunk-HT3LSWXL.js.map} +0 -0
  70. /package/dist/{chunk-FLAD6SC6.js.map → chunk-IWNRQVNW.js.map} +0 -0
  71. /package/dist/{chunk-G6LTYTJR.js.map → chunk-WIUPAUJV.js.map} +0 -0
  72. /package/dist/{chunk-PYHKCIYN.js.map → chunk-XY5DHYIH.js.map} +0 -0
@@ -3,7 +3,7 @@ import {
3
3
  } from "./chunk-4DB4SC5K.js";
4
4
  import {
5
5
  qtiTransformItem
6
- } from "./chunk-TLAVOBEM.js";
6
+ } from "./chunk-LORYM4U2.js";
7
7
  import {
8
8
  QtiExitResponseSignal,
9
9
  QtiFeedback,
@@ -12,19 +12,23 @@ import {
12
12
  itemContext,
13
13
  itemContextVariables,
14
14
  readRecordFieldValues
15
- } from "./chunk-WUIA4OOX.js";
15
+ } from "./chunk-IM5AKPIJ.js";
16
16
 
17
17
  // ../qti-elements/dist/public-events.js
18
18
  var PUBLIC_ITEM_EVENTS = {
19
19
  // The old name `qti-assessment-item-connected` stays as internal plumbing: it is sent separately.
20
20
  "cito-item-rendered": { kind: "notification", scope: "item" },
21
21
  "cito-item-response-changed": { kind: "notification", scope: "item", deprecated: "qti-interaction-changed" },
22
+ "cito-item-set-outcomes": { kind: "request", scope: "item" },
22
23
  "cito-item-outcome-changed": { kind: "notification", scope: "item", deprecated: "qti-outcome-changed" },
24
+ "cito-item-outcomes-changed": { kind: "notification", scope: "item" },
23
25
  "cito-item-rubric-placement": {
24
26
  kind: "notification",
25
27
  scope: "item",
26
28
  deprecated: "qti-rubric:discretionary-placement"
27
- }
29
+ },
30
+ "cito-feedback-show": { kind: "notification", scope: "item" },
31
+ "cito-feedback-hide": { kind: "notification", scope: "item" }
28
32
  };
29
33
  function dispatchDeclared(target, declarations, name, detail, cancelable = false) {
30
34
  const init = { detail: detail ?? {}, bubbles: true, composed: true, cancelable };
@@ -104,13 +108,26 @@ var QtiAssessmentItem = class extends LitElement {
104
108
  const { responseIdentifier, countAttempt } = e.detail;
105
109
  this.validate();
106
110
  this.updateResponseVariable(responseIdentifier, "true");
107
- this.processResponse(countAttempt);
111
+ this.#processResponse(countAttempt, true, responseIdentifier);
108
112
  };
109
- this.#handleSetOutcomeValue = (e) => {
113
+ this.#handleSetOutcomes = (e) => {
110
114
  e.stopImmediatePropagation();
111
- const { outcomeIdentifier, value } = e.detail;
112
- this.updateOutcomeVariable(outcomeIdentifier, value);
113
- e.stopPropagation();
115
+ const { outcomes = [], responseProcessed = false } = e.detail ?? {};
116
+ const completion = [];
117
+ if (responseProcessed && this.adaptive === "false") {
118
+ const sent = outcomes.find((o) => o.identifier === "completionStatus")?.value;
119
+ if ((sent ?? this.getVariable("completionStatus")?.value) === "unknown") {
120
+ completion.push({ identifier: "completionStatus", value: "completed" });
121
+ }
122
+ }
123
+ this.#applyOutcomes([...outcomes, ...completion], this.#checkValidity(false));
124
+ if (responseProcessed) {
125
+ this.dispatchEvent(new CustomEvent("qti-item-context-updated", {
126
+ bubbles: true,
127
+ composed: true,
128
+ detail: { itemContext: this._context, responseProcessed: true }
129
+ }));
130
+ }
114
131
  };
115
132
  this.#handleSetTemplateValue = (e) => {
116
133
  e.stopImmediatePropagation();
@@ -224,6 +241,8 @@ var QtiAssessmentItem = class extends LitElement {
224
241
  this.#runTemplateProcessing();
225
242
  }
226
243
  void this.updateComplete.then(() => this.#revalidate());
244
+ if (this.isConnected)
245
+ this.#beginFirstAttempt();
227
246
  }
228
247
  get state() {
229
248
  return this._context.state;
@@ -265,6 +284,7 @@ var QtiAssessmentItem = class extends LitElement {
265
284
  super.connectedCallback();
266
285
  this.updateComplete.then(() => {
267
286
  this.validate(false);
287
+ this.#beginFirstAttempt();
268
288
  dispatchPublic(this, "cito-item-rendered", this);
269
289
  this.dispatchEvent(new CustomEvent("qti-assessment-item-connected", {
270
290
  bubbles: true,
@@ -282,7 +302,7 @@ var QtiAssessmentItem = class extends LitElement {
282
302
  this.addEventListener("qti-register-variable", this.#handleRegisterVariable);
283
303
  this.addEventListener("qti-register-interaction", this.#handleRegisterInteraction);
284
304
  this.addEventListener("end-attempt", this.#handleEndAttempt);
285
- this.addEventListener("qti-set-outcome-value", this.#handleSetOutcomeValue);
305
+ this.addEventListener("cito-item-set-outcomes", this.#handleSetOutcomes);
286
306
  this.addEventListener("qti-set-template-value", this.#handleSetTemplateValue);
287
307
  this.addEventListener("qti-set-correct-response", this.#handleSetCorrectResponse);
288
308
  this.addEventListener("qti-interaction-response", this.#handleUpdateResponseVariable);
@@ -291,7 +311,7 @@ var QtiAssessmentItem = class extends LitElement {
291
311
  this.removeEventListener("qti-register-variable", this.#handleRegisterVariable);
292
312
  this.removeEventListener("qti-register-interaction", this.#handleRegisterInteraction);
293
313
  this.removeEventListener("end-attempt", this.#handleEndAttempt);
294
- this.removeEventListener("qti-set-outcome-value", this.#handleSetOutcomeValue);
314
+ this.removeEventListener("cito-item-set-outcomes", this.#handleSetOutcomes);
295
315
  this.removeEventListener("qti-set-template-value", this.#handleSetTemplateValue);
296
316
  this.removeEventListener("qti-set-correct-response", this.#handleSetCorrectResponse);
297
317
  this.removeEventListener("qti-interaction-response", this.#handleUpdateResponseVariable);
@@ -299,7 +319,16 @@ var QtiAssessmentItem = class extends LitElement {
299
319
  #handleRegisterVariable;
300
320
  #handleRegisterInteraction;
301
321
  #handleEndAttempt;
302
- #handleSetOutcomeValue;
322
+ /**
323
+ * Applies the outcomes of a processing run, ours or a backend's, in one update, with the
324
+ * interactions' validity.
325
+ *
326
+ * completionStatus is response processing's to set (QTI info model §2.2.2). When an attempt of a
327
+ * non-adaptive item ends and processing left it `unknown`, the item marks it `completed`: the
328
+ * attempt is done. TAO does the same, and the 1EdTech results-reporting reference results expect
329
+ * it. An adaptive item is completed only by its own processing.
330
+ */
331
+ #handleSetOutcomes;
303
332
  #handleSetTemplateValue;
304
333
  #handleSetCorrectResponse;
305
334
  #handleUpdateResponseVariable;
@@ -319,31 +348,69 @@ var QtiAssessmentItem = class extends LitElement {
319
348
  this.#templateProcessing.process();
320
349
  this.#initialContext = { ...this._context, variables: this._context.variables };
321
350
  }
351
+ /**
352
+ * Scores the attempt. The item does not score itself: its response processing does, like a
353
+ * backend, and sends the outcomes back in `cito-item-set-outcomes`, which the item applies in one
354
+ * update. The item keeps the attempt count (QTI info model §2.2.2: the delivery engine maintains
355
+ * numAttempts) and hands the new count to the run, whose rules may read it. Without response
356
+ * processing the item only counts the attempt. A run that throws still counts the attempt and applies
357
+ * no outcomes.
358
+ *
359
+ * @returns whether the item has response processing.
360
+ */
322
361
  processResponse(countNumAttempts = true, reportValidityAfterScoring = true) {
323
- this.validate(reportValidityAfterScoring);
324
- if (countNumAttempts) {
325
- this.updateOutcomeVariable("numAttempts", (+this._context.variables.find((v) => v.identifier === "numAttempts")?.value + 1).toString());
326
- }
327
- if (this.adaptive === "false") {
328
- this.#resetOutcomeVariablesBeforeResponseProcessing();
329
- }
330
- const responseProcessor = this.querySelector("qti-response-processing");
331
- const canProcess = !!(responseProcessor && typeof responseProcessor.process === "function");
332
- if (canProcess) {
333
- responseProcessor.process();
334
- }
335
- if (this.adaptive === "false") {
336
- this.updateOutcomeVariable("completionStatus", this.#getCompletionStatus());
362
+ return this.#processResponse(countNumAttempts, reportValidityAfterScoring);
363
+ }
364
+ #processResponse(countNumAttempts, reportValidity, endedBy) {
365
+ this.#checkValidity(reportValidity);
366
+ this.#resetOtherEndAttempts(endedBy);
367
+ const numAttempts = +this.getVariable("numAttempts")?.value + (countNumAttempts ? 1 : 0);
368
+ const processor = this.querySelector("qti-response-processing");
369
+ if (typeof processor?.processResponse === "function") {
370
+ try {
371
+ processor.processResponse({ numAttempts });
372
+ } catch (error) {
373
+ this.#applyOutcomes([{ identifier: "numAttempts", value: String(numAttempts) }]);
374
+ throw error;
375
+ }
376
+ return true;
337
377
  }
338
- this.dispatchEvent(new CustomEvent("qti-item-context-updated", {
339
- bubbles: true,
340
- composed: true,
341
- detail: { itemContext: this._context, responseProcessed: true }
342
- }));
343
- return canProcess;
378
+ dispatchPublic(this, "cito-item-set-outcomes", {
379
+ outcomes: [{ identifier: "numAttempts", value: String(numAttempts) }],
380
+ responseProcessed: true
381
+ });
382
+ return false;
383
+ }
384
+ /**
385
+ * QTI info model §2.4.5: when an attempt ends any other way than through an end-attempt
386
+ * interaction, that interaction's response is `false`.
387
+ */
388
+ #resetOtherEndAttempts(endedBy) {
389
+ const others = Array.from(this.querySelectorAll("qti-end-attempt-interaction"), (el) => el.getAttribute("response-identifier")).filter((id) => id && id !== endedBy);
390
+ if (others.length === 0)
391
+ return;
392
+ this._context = {
393
+ ...this._context,
394
+ variables: this._context.variables.map((v) => others.includes(v.identifier) ? { ...v, value: "false" } : v)
395
+ };
344
396
  }
345
397
  resetResponses() {
346
398
  this._context = this.#initialContext;
399
+ if (this.isConnected)
400
+ this.#beginFirstAttempt();
401
+ }
402
+ /**
403
+ * QTI info model §2.2.2: completionStatus is `not_attempted` until the first attempt starts, then
404
+ * `unknown`. The attempt starts when the candidate gets the item, so an item on screen is never
405
+ * `not_attempted` — also not after a reset or a restore that says so.
406
+ */
407
+ #beginFirstAttempt() {
408
+ if (this.getVariable("completionStatus")?.value !== "not_attempted")
409
+ return;
410
+ this._context = {
411
+ ...this._context,
412
+ variables: this._context.variables.map((v) => v.identifier === "completionStatus" ? { ...v, value: "unknown" } : v)
413
+ };
347
414
  }
348
415
  getResponse(identifier) {
349
416
  return this.getVariable(identifier);
@@ -380,9 +447,7 @@ var QtiAssessmentItem = class extends LitElement {
380
447
  responseIdentifier: identifier,
381
448
  response: Array.isArray(value) ? [...value] : value
382
449
  });
383
- if (this.adaptive === "false") {
384
- this.updateOutcomeVariable("completionStatus", this.#getCompletionStatus());
385
- }
450
+ this.validate(false);
386
451
  }
387
452
  /**
388
453
  * Updates the template variable with the specified identifier to the given value.
@@ -450,32 +515,53 @@ var QtiAssessmentItem = class extends LitElement {
450
515
  * @param value - The new value for the response variable.
451
516
  */
452
517
  updateOutcomeVariable(identifier, value) {
453
- const outcomeVariable = this.getOutcome(identifier);
454
- if (!outcomeVariable) {
455
- console.warn(`Can not set qti-outcome-identifier: ${identifier}, it is not available`);
456
- return;
518
+ this.#applyOutcomes([{ identifier, value }]);
519
+ }
520
+ /**
521
+ * Publishes the outcomes (and the validity) in one update, then a `cito-item-outcome-changed` per
522
+ * outcome with its final value and one `cito-item-outcomes-changed` with all of them.
523
+ * An identifier the item does not declare is skipped with a warning; a later entry for the same
524
+ * identifier wins.
525
+ */
526
+ #applyOutcomes(outcomes, valid) {
527
+ const values = /* @__PURE__ */ new Map();
528
+ for (const { identifier, value } of outcomes) {
529
+ const variable = this.getVariable(identifier);
530
+ if (!variable) {
531
+ console.warn(`Can not set qti-outcome-identifier: ${identifier}, it is not available`);
532
+ continue;
533
+ }
534
+ values.set(identifier, variable.cardinality === "single" ? value : Array.isArray(value) ? value : [value]);
457
535
  }
536
+ const validChanged = valid !== void 0 && valid !== this._context.valid;
537
+ if (values.size === 0 && !validChanged)
538
+ return;
458
539
  this._context = {
459
540
  ...this._context,
460
- variables: this._context.variables.map((v) => {
461
- if (v.identifier !== identifier) {
462
- return v;
463
- }
464
- return {
465
- ...v,
466
- value: outcomeVariable.cardinality === "single" ? value : Array.isArray(value) ? value : [value]
467
- };
468
- })
541
+ ...validChanged ? { valid } : {},
542
+ variables: this._context.variables.map((v) => values.has(v.identifier) ? { ...v, value: values.get(v.identifier) } : v)
469
543
  };
470
- dispatchPublic(this, "cito-item-outcome-changed", {
471
- item: this.identifier,
472
- outcomeIdentifier: identifier,
473
- value: this._context.variables.find((v) => v.identifier === identifier)?.value
474
- });
544
+ if (values.size > 0) {
545
+ for (const [outcomeIdentifier, value] of values) {
546
+ dispatchPublic(this, "cito-item-outcome-changed", {
547
+ item: this.identifier,
548
+ outcomeIdentifier,
549
+ value
550
+ });
551
+ }
552
+ dispatchPublic(this, "cito-item-outcomes-changed", {
553
+ item: this.identifier,
554
+ outcomes: [...values].map(([identifier, value]) => ({ identifier, value }))
555
+ });
556
+ }
475
557
  }
476
558
  validate(reportValidity = true) {
477
- const isValid = this.interactionElements.every((interactionElement) => interactionElement.validate());
559
+ const isValid = this.#checkValidity(reportValidity);
478
560
  this.#publishValidity(isValid);
561
+ return isValid;
562
+ }
563
+ #checkValidity(reportValidity) {
564
+ const isValid = this.interactionElements.every((interactionElement) => interactionElement.validate());
479
565
  if (reportValidity) {
480
566
  this.reportValidity();
481
567
  }
@@ -507,34 +593,6 @@ var QtiAssessmentItem = class extends LitElement {
507
593
  interactionElement.reportValidity();
508
594
  }
509
595
  }
510
- #getCompletionStatus() {
511
- const valid = this.validate(false);
512
- if (valid === true)
513
- return "completed";
514
- if (valid === false)
515
- return "incomplete";
516
- return "not_attempted";
517
- }
518
- #resetOutcomeVariablesBeforeResponseProcessing() {
519
- this._context = {
520
- ...this._context,
521
- variables: this._context.variables.map((variable) => {
522
- if (variable.type !== "outcome") {
523
- return variable;
524
- }
525
- const hasDefaultValue = "defaultValue" in variable;
526
- const declaredDefault = hasDefaultValue ? variable.defaultValue : null;
527
- let value = declaredDefault ?? null;
528
- if ((value === null || value === void 0) && (variable.baseType === "integer" || variable.baseType === "float")) {
529
- value = "0";
530
- }
531
- return {
532
- ...variable,
533
- value
534
- };
535
- })
536
- };
537
- }
538
596
  };
539
597
  __decorate([
540
598
  property({ type: String })
@@ -798,16 +856,6 @@ var QtiCustomOperator = class extends LitElement7 {
798
856
  value
799
857
  }
800
858
  }));
801
- },
802
- updateResponseVariable: (responseIdentifier, response) => {
803
- this.dispatchEvent(new CustomEvent("qti-interaction-response", {
804
- bubbles: true,
805
- composed: true,
806
- detail: {
807
- responseIdentifier,
808
- response
809
- }
810
- }));
811
859
  }
812
860
  };
813
861
  return this.#operatorFunction(this._context, fn, item);
@@ -838,6 +886,21 @@ __decorate5([
838
886
 
839
887
  // ../qti-elements/dist/components/qti-feedback-block/qti-feedback-block.js
840
888
  import { css as css3, html as html6 } from "lit";
889
+
890
+ // ../qti-elements/dist/internal/feedback-events.js
891
+ function dispatchFeedback(element, name, kind, identifier) {
892
+ const itemIdentifier = element.closest("qti-assessment-item")?.getAttribute("identifier") ?? void 0;
893
+ const detail = {
894
+ kind,
895
+ identifier,
896
+ outcomeIdentifier: element.outcomeIdentifier,
897
+ element,
898
+ ...itemIdentifier ? { itemIdentifier } : {}
899
+ };
900
+ return dispatchPublic(element, name, detail, true);
901
+ }
902
+
903
+ // ../qti-elements/dist/components/qti-feedback-block/qti-feedback-block.js
841
904
  var QtiFeedbackBlock = class extends QtiFeedback {
842
905
  static {
843
906
  this.styles = css3`
@@ -855,6 +918,13 @@ var QtiFeedbackBlock = class extends QtiFeedback {
855
918
  render() {
856
919
  return html6` <slot part="feedback" class="feedback ${this.showStatus}"></slot> `;
857
920
  }
921
+ /** `cito-feedback-show`: a listener that calls `preventDefault()` keeps this hidden and shows it itself. */
922
+ feedbackShowing() {
923
+ return dispatchFeedback(this, "cito-feedback-show", "block", this.identifier);
924
+ }
925
+ feedbackHiding() {
926
+ return dispatchFeedback(this, "cito-feedback-hide", "block", this.identifier);
927
+ }
858
928
  connectedCallback() {
859
929
  super.connectedCallback();
860
930
  this.checkShowFeedback(this.outcomeIdentifier);
@@ -879,6 +949,13 @@ var QtiFeedbackInline = class extends QtiFeedback {
879
949
  }
880
950
  `;
881
951
  }
952
+ /** `cito-feedback-show`: a listener that calls `preventDefault()` keeps this hidden and shows it itself. */
953
+ feedbackShowing() {
954
+ return dispatchFeedback(this, "cito-feedback-show", "inline", this.identifier);
955
+ }
956
+ feedbackHiding() {
957
+ return dispatchFeedback(this, "cito-feedback-hide", "inline", this.identifier);
958
+ }
882
959
  connectedCallback() {
883
960
  super.connectedCallback();
884
961
  this.checkShowFeedback(this.outcomeIdentifier);
@@ -973,6 +1050,13 @@ var QtiModalFeedback = class extends QtiFeedback {
973
1050
  this.showStatus = "off";
974
1051
  }
975
1052
  }
1053
+ /** `cito-feedback-show`: a listener that calls `preventDefault()` keeps this hidden and shows it itself. */
1054
+ feedbackShowing() {
1055
+ return dispatchFeedback(this, "cito-feedback-show", "modal", this.identifier);
1056
+ }
1057
+ feedbackHiding() {
1058
+ return dispatchFeedback(this, "cito-feedback-hide", "modal", this.identifier);
1059
+ }
976
1060
  connectedCallback() {
977
1061
  super.connectedCallback();
978
1062
  if (this.showStatus === "on") {
@@ -1258,6 +1342,7 @@ __decorate7([
1258
1342
  ], QtiResponseDeclaration.prototype, "itemContext", void 0);
1259
1343
 
1260
1344
  // ../qti-elements/dist/components/qti-response-processing/qti-response-processing.js
1345
+ import { ContextConsumer, ContextProvider } from "@lit/context";
1261
1346
  import { css as css9, html as html12, LitElement as LitElement9 } from "lit";
1262
1347
 
1263
1348
  // ../qti-elements/dist/internal/template-strings.js
@@ -1324,13 +1409,64 @@ var QtiResponseProcessing = class extends LitElement9 {
1324
1409
  `
1325
1410
  ];
1326
1411
  }
1412
+ /**
1413
+ * The rules inside read and write this element's copy of the item context, never the item's. It
1414
+ * is provided under the same `itemContext`: the nearest provider wins, so every expression in
1415
+ * here gets the copy without knowing about it.
1416
+ */
1417
+ #provider = new ContextProvider(this, { context: itemContext });
1418
+ #copy;
1419
+ constructor() {
1420
+ super();
1421
+ new ContextConsumer(this, {
1422
+ context: itemContext,
1423
+ subscribe: true,
1424
+ // Every variable its own object, so a write changes the copy and not the item's context.
1425
+ callback: (context) => {
1426
+ this.#copy = { ...context, variables: context.variables.map((v) => ({ ...v })) };
1427
+ this.#provider.setValue(this.#copy);
1428
+ }
1429
+ });
1430
+ this.addEventListener("qti-set-outcome-value", (e) => {
1431
+ e.stopImmediatePropagation();
1432
+ const variable = this.#copy?.variables.find((v) => v.identifier === e.detail.outcomeIdentifier);
1433
+ if (!variable) {
1434
+ console.warn(`Can not set qti-outcome-identifier: ${e.detail.outcomeIdentifier}, it is not available`);
1435
+ return;
1436
+ }
1437
+ const { value } = e.detail;
1438
+ variable.value = variable.cardinality === "single" ? value : Array.isArray(value) ? value : [value];
1439
+ });
1440
+ }
1327
1441
  render() {
1328
1442
  return html12`<slot></slot>`;
1329
1443
  }
1330
- process() {
1331
- const assessmentItem = this.closest("qti-assessment-item");
1332
- if (!assessmentItem)
1444
+ /**
1445
+ * Scores the attempt on the copy: sets `numAttempts` to the count the item hands over, resets a
1446
+ * non-adaptive item's outcomes to their defaults (QTI info model §2.5), runs the rules and sends
1447
+ * every outcome and `numAttempts` in one `cito-item-set-outcomes`. The item applies them and publishes, which gives this element a
1448
+ * fresh copy. A rule that throws ends the run and the error propagates; nothing is sent, and the
1449
+ * run's writes stay in the copy until the item's next update.
1450
+ */
1451
+ processResponse({ numAttempts }) {
1452
+ const copy = this.#copy;
1453
+ if (!copy)
1333
1454
  return;
1455
+ const reset = this.closest("qti-assessment-item")?.getAttribute("adaptive") !== "true";
1456
+ for (const variable of copy.variables) {
1457
+ if (variable.identifier === "numAttempts")
1458
+ variable.value = String(numAttempts);
1459
+ if (variable.type === "outcome" && reset && variable.identifier !== "completionStatus") {
1460
+ variable.value = defaultValueOf(variable);
1461
+ }
1462
+ }
1463
+ this.#runRules();
1464
+ dispatchPublic(this, "cito-item-set-outcomes", {
1465
+ outcomes: copy.variables.filter((v) => v.type === "outcome" || v.identifier === "numAttempts").map(({ identifier, value }) => ({ identifier, value })),
1466
+ responseProcessed: true
1467
+ });
1468
+ }
1469
+ #runRules() {
1334
1470
  const rules = [...this.children];
1335
1471
  try {
1336
1472
  for (const rule of rules) {
@@ -1352,6 +1488,12 @@ var QtiResponseProcessing = class extends LitElement9 {
1352
1488
  this.innerHTML = rules;
1353
1489
  }
1354
1490
  };
1491
+ function defaultValueOf(variable) {
1492
+ const value = ("defaultValue" in variable ? variable.defaultValue : null) ?? null;
1493
+ if (value === null && (variable.baseType === "integer" || variable.baseType === "float"))
1494
+ return "0";
1495
+ return value;
1496
+ }
1355
1497
 
1356
1498
  // ../qti-elements/dist/components/qti-rubric-block/qti-rubric-block.js
1357
1499
  import { LitElement as LitElement10, css as css10, html as html13 } from "lit";
@@ -1740,4 +1882,4 @@ export {
1740
1882
  QtiTemplateProcessing,
1741
1883
  qtiContentElements
1742
1884
  };
1743
- //# sourceMappingURL=chunk-AKX4YMWU.js.map
1885
+ //# sourceMappingURL=chunk-QT7WQXCS.js.map