@citolab/qti-components 10.0.0-next.13 → 10.0.0-next.14
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/cdn/index.global.js +1 -1
- package/cdn/index.js +383 -399
- package/dist/base.d.ts +1 -1
- package/dist/base.js +1 -1
- package/dist/{chunk-Y5DZTCDP.js → chunk-6XRNX574.js} +224 -257
- package/dist/chunk-6XRNX574.js.map +1 -0
- package/dist/{chunk-G6LTYTJR.js → chunk-BZPMN57E.js} +2 -2
- package/dist/{chunk-AKX4YMWU.js → chunk-C7SYDLMG.js} +197 -93
- package/dist/chunk-C7SYDLMG.js.map +1 -0
- package/dist/{chunk-H3GITIPE.js → chunk-CCI3QMQA.js} +23 -7
- package/dist/chunk-CCI3QMQA.js.map +1 -0
- package/dist/{chunk-FLAD6SC6.js → chunk-HGKLF7SP.js} +2 -2
- package/dist/{chunk-K4WLYVDT.js → chunk-LEF7AAYZ.js} +2 -2
- package/dist/{chunk-HOGJ5ZNW.js → chunk-MP2SUN7J.js} +193 -86
- package/dist/chunk-MP2SUN7J.js.map +1 -0
- package/dist/{chunk-PHRHLDQB.js → chunk-NYNL5HSR.js} +2 -2
- package/dist/{chunk-WUIA4OOX.js → chunk-O2ENNGKV.js} +3 -2
- package/dist/chunk-O2ENNGKV.js.map +1 -0
- package/dist/chunk-Q4MJCEDE.js +7 -0
- package/dist/chunk-Q4MJCEDE.js.map +1 -0
- package/dist/{chunk-EIBGCCXH.js → chunk-S5GLISQA.js} +2 -2
- package/dist/{chunk-PYHKCIYN.js → chunk-SWNFCQ4G.js} +3 -3
- package/dist/{chunk-MDBNEEPH.js → chunk-TU34FFWF.js} +8 -3
- package/dist/chunk-TU34FFWF.js.map +1 -0
- package/dist/corrections.d.ts +3 -3
- package/dist/corrections.js +8 -8
- package/dist/elements.d.ts +54 -12
- package/dist/elements.js +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +13 -13
- package/dist/interactions.d.ts +15 -3
- package/dist/interactions.js +3 -3
- package/dist/item.css +33 -8
- package/dist/item.d.ts +1 -1
- package/dist/item.js +4 -4
- package/dist/loader.d.ts +1 -1
- package/dist/processing.d.ts +8 -4
- package/dist/processing.js +3 -3
- package/dist/qti-components-jsx.d.ts +245 -97
- package/dist/{qti-rule-base.d-Bdzg8eGH.d.ts → qti-rule-base.d-CeKP0Ooi.d.ts} +2 -2
- package/dist/{qti-test.d-B6AGSQlk.d.ts → qti-test.d-C0I1BIdH.d.ts} +29 -3
- package/dist/{qti-text-entry-interaction.d-B44Z3qUG.d.ts → qti-text-entry-interaction.d-V4sWE9TO.d.ts} +31 -5
- package/dist/test.d.ts +3 -3
- package/dist/test.js +5 -5
- package/package.json +10 -10
- package/dist/chunk-AKX4YMWU.js.map +0 -1
- package/dist/chunk-DVLSXMXD.js +0 -7
- package/dist/chunk-DVLSXMXD.js.map +0 -1
- package/dist/chunk-H3GITIPE.js.map +0 -1
- package/dist/chunk-HOGJ5ZNW.js.map +0 -1
- package/dist/chunk-MDBNEEPH.js.map +0 -1
- package/dist/chunk-WUIA4OOX.js.map +0 -1
- package/dist/chunk-Y5DZTCDP.js.map +0 -1
- /package/dist/{chunk-G6LTYTJR.js.map → chunk-BZPMN57E.js.map} +0 -0
- /package/dist/{chunk-FLAD6SC6.js.map → chunk-HGKLF7SP.js.map} +0 -0
- /package/dist/{chunk-K4WLYVDT.js.map → chunk-LEF7AAYZ.js.map} +0 -0
- /package/dist/{chunk-PHRHLDQB.js.map → chunk-NYNL5HSR.js.map} +0 -0
- /package/dist/{chunk-EIBGCCXH.js.map → chunk-S5GLISQA.js.map} +0 -0
- /package/dist/{chunk-PYHKCIYN.js.map → chunk-SWNFCQ4G.js.map} +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
qtiItemElements
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-SWNFCQ4G.js";
|
|
4
4
|
|
|
5
5
|
// ../qti-item/dist/register.js
|
|
6
6
|
for (const { tag, ctor } of qtiItemElements) {
|
|
@@ -8,4 +8,4 @@ for (const { tag, ctor } of qtiItemElements) {
|
|
|
8
8
|
customElements.define(tag, ctor);
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
|
-
//# sourceMappingURL=chunk-
|
|
11
|
+
//# sourceMappingURL=chunk-BZPMN57E.js.map
|
|
@@ -12,14 +12,16 @@ import {
|
|
|
12
12
|
itemContext,
|
|
13
13
|
itemContextVariables,
|
|
14
14
|
readRecordFieldValues
|
|
15
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-O2ENNGKV.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",
|
|
@@ -104,13 +106,26 @@ var QtiAssessmentItem = class extends LitElement {
|
|
|
104
106
|
const { responseIdentifier, countAttempt } = e.detail;
|
|
105
107
|
this.validate();
|
|
106
108
|
this.updateResponseVariable(responseIdentifier, "true");
|
|
107
|
-
this
|
|
109
|
+
this.#processResponse(countAttempt, true, responseIdentifier);
|
|
108
110
|
};
|
|
109
|
-
this.#
|
|
111
|
+
this.#handleSetOutcomes = (e) => {
|
|
110
112
|
e.stopImmediatePropagation();
|
|
111
|
-
const {
|
|
112
|
-
|
|
113
|
-
|
|
113
|
+
const { outcomes = [], responseProcessed = false } = e.detail ?? {};
|
|
114
|
+
const completion = [];
|
|
115
|
+
if (responseProcessed && this.adaptive === "false") {
|
|
116
|
+
const sent = outcomes.find((o) => o.identifier === "completionStatus")?.value;
|
|
117
|
+
if ((sent ?? this.getVariable("completionStatus")?.value) === "unknown") {
|
|
118
|
+
completion.push({ identifier: "completionStatus", value: "completed" });
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
this.#applyOutcomes([...outcomes, ...completion], this.#checkValidity(false));
|
|
122
|
+
if (responseProcessed) {
|
|
123
|
+
this.dispatchEvent(new CustomEvent("qti-item-context-updated", {
|
|
124
|
+
bubbles: true,
|
|
125
|
+
composed: true,
|
|
126
|
+
detail: { itemContext: this._context, responseProcessed: true }
|
|
127
|
+
}));
|
|
128
|
+
}
|
|
114
129
|
};
|
|
115
130
|
this.#handleSetTemplateValue = (e) => {
|
|
116
131
|
e.stopImmediatePropagation();
|
|
@@ -224,6 +239,8 @@ var QtiAssessmentItem = class extends LitElement {
|
|
|
224
239
|
this.#runTemplateProcessing();
|
|
225
240
|
}
|
|
226
241
|
void this.updateComplete.then(() => this.#revalidate());
|
|
242
|
+
if (this.isConnected)
|
|
243
|
+
this.#beginFirstAttempt();
|
|
227
244
|
}
|
|
228
245
|
get state() {
|
|
229
246
|
return this._context.state;
|
|
@@ -265,6 +282,7 @@ var QtiAssessmentItem = class extends LitElement {
|
|
|
265
282
|
super.connectedCallback();
|
|
266
283
|
this.updateComplete.then(() => {
|
|
267
284
|
this.validate(false);
|
|
285
|
+
this.#beginFirstAttempt();
|
|
268
286
|
dispatchPublic(this, "cito-item-rendered", this);
|
|
269
287
|
this.dispatchEvent(new CustomEvent("qti-assessment-item-connected", {
|
|
270
288
|
bubbles: true,
|
|
@@ -282,7 +300,7 @@ var QtiAssessmentItem = class extends LitElement {
|
|
|
282
300
|
this.addEventListener("qti-register-variable", this.#handleRegisterVariable);
|
|
283
301
|
this.addEventListener("qti-register-interaction", this.#handleRegisterInteraction);
|
|
284
302
|
this.addEventListener("end-attempt", this.#handleEndAttempt);
|
|
285
|
-
this.addEventListener("
|
|
303
|
+
this.addEventListener("cito-item-set-outcomes", this.#handleSetOutcomes);
|
|
286
304
|
this.addEventListener("qti-set-template-value", this.#handleSetTemplateValue);
|
|
287
305
|
this.addEventListener("qti-set-correct-response", this.#handleSetCorrectResponse);
|
|
288
306
|
this.addEventListener("qti-interaction-response", this.#handleUpdateResponseVariable);
|
|
@@ -291,7 +309,7 @@ var QtiAssessmentItem = class extends LitElement {
|
|
|
291
309
|
this.removeEventListener("qti-register-variable", this.#handleRegisterVariable);
|
|
292
310
|
this.removeEventListener("qti-register-interaction", this.#handleRegisterInteraction);
|
|
293
311
|
this.removeEventListener("end-attempt", this.#handleEndAttempt);
|
|
294
|
-
this.removeEventListener("
|
|
312
|
+
this.removeEventListener("cito-item-set-outcomes", this.#handleSetOutcomes);
|
|
295
313
|
this.removeEventListener("qti-set-template-value", this.#handleSetTemplateValue);
|
|
296
314
|
this.removeEventListener("qti-set-correct-response", this.#handleSetCorrectResponse);
|
|
297
315
|
this.removeEventListener("qti-interaction-response", this.#handleUpdateResponseVariable);
|
|
@@ -299,7 +317,16 @@ var QtiAssessmentItem = class extends LitElement {
|
|
|
299
317
|
#handleRegisterVariable;
|
|
300
318
|
#handleRegisterInteraction;
|
|
301
319
|
#handleEndAttempt;
|
|
302
|
-
|
|
320
|
+
/**
|
|
321
|
+
* Applies the outcomes of a processing run, ours or a backend's, in one update, with the
|
|
322
|
+
* interactions' validity.
|
|
323
|
+
*
|
|
324
|
+
* completionStatus is response processing's to set (QTI info model §2.2.2). When an attempt of a
|
|
325
|
+
* non-adaptive item ends and processing left it `unknown`, the item marks it `completed`: the
|
|
326
|
+
* attempt is done. TAO does the same, and the 1EdTech results-reporting reference results expect
|
|
327
|
+
* it. An adaptive item is completed only by its own processing.
|
|
328
|
+
*/
|
|
329
|
+
#handleSetOutcomes;
|
|
303
330
|
#handleSetTemplateValue;
|
|
304
331
|
#handleSetCorrectResponse;
|
|
305
332
|
#handleUpdateResponseVariable;
|
|
@@ -319,31 +346,69 @@ var QtiAssessmentItem = class extends LitElement {
|
|
|
319
346
|
this.#templateProcessing.process();
|
|
320
347
|
this.#initialContext = { ...this._context, variables: this._context.variables };
|
|
321
348
|
}
|
|
349
|
+
/**
|
|
350
|
+
* Scores the attempt. The item does not score itself: its response processing does, like a
|
|
351
|
+
* backend, and sends the outcomes back in `cito-item-set-outcomes`, which the item applies in one
|
|
352
|
+
* update. The item keeps the attempt count (QTI info model §2.2.2: the delivery engine maintains
|
|
353
|
+
* numAttempts) and hands the new count to the run, whose rules may read it. Without response
|
|
354
|
+
* processing the item only counts the attempt. A run that throws still counts the attempt and applies
|
|
355
|
+
* no outcomes.
|
|
356
|
+
*
|
|
357
|
+
* @returns whether the item has response processing.
|
|
358
|
+
*/
|
|
322
359
|
processResponse(countNumAttempts = true, reportValidityAfterScoring = true) {
|
|
323
|
-
this
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
360
|
+
return this.#processResponse(countNumAttempts, reportValidityAfterScoring);
|
|
361
|
+
}
|
|
362
|
+
#processResponse(countNumAttempts, reportValidity, endedBy) {
|
|
363
|
+
this.#checkValidity(reportValidity);
|
|
364
|
+
this.#resetOtherEndAttempts(endedBy);
|
|
365
|
+
const numAttempts = +this.getVariable("numAttempts")?.value + (countNumAttempts ? 1 : 0);
|
|
366
|
+
const processor = this.querySelector("qti-response-processing");
|
|
367
|
+
if (typeof processor?.processResponse === "function") {
|
|
368
|
+
try {
|
|
369
|
+
processor.processResponse({ numAttempts });
|
|
370
|
+
} catch (error) {
|
|
371
|
+
this.#applyOutcomes([{ identifier: "numAttempts", value: String(numAttempts) }]);
|
|
372
|
+
throw error;
|
|
373
|
+
}
|
|
374
|
+
return true;
|
|
337
375
|
}
|
|
338
|
-
this
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
376
|
+
dispatchPublic(this, "cito-item-set-outcomes", {
|
|
377
|
+
outcomes: [{ identifier: "numAttempts", value: String(numAttempts) }],
|
|
378
|
+
responseProcessed: true
|
|
379
|
+
});
|
|
380
|
+
return false;
|
|
381
|
+
}
|
|
382
|
+
/**
|
|
383
|
+
* QTI info model §2.4.5: when an attempt ends any other way than through an end-attempt
|
|
384
|
+
* interaction, that interaction's response is `false`.
|
|
385
|
+
*/
|
|
386
|
+
#resetOtherEndAttempts(endedBy) {
|
|
387
|
+
const others = Array.from(this.querySelectorAll("qti-end-attempt-interaction"), (el) => el.getAttribute("response-identifier")).filter((id) => id && id !== endedBy);
|
|
388
|
+
if (others.length === 0)
|
|
389
|
+
return;
|
|
390
|
+
this._context = {
|
|
391
|
+
...this._context,
|
|
392
|
+
variables: this._context.variables.map((v) => others.includes(v.identifier) ? { ...v, value: "false" } : v)
|
|
393
|
+
};
|
|
344
394
|
}
|
|
345
395
|
resetResponses() {
|
|
346
396
|
this._context = this.#initialContext;
|
|
397
|
+
if (this.isConnected)
|
|
398
|
+
this.#beginFirstAttempt();
|
|
399
|
+
}
|
|
400
|
+
/**
|
|
401
|
+
* QTI info model §2.2.2: completionStatus is `not_attempted` until the first attempt starts, then
|
|
402
|
+
* `unknown`. The attempt starts when the candidate gets the item, so an item on screen is never
|
|
403
|
+
* `not_attempted` — also not after a reset or a restore that says so.
|
|
404
|
+
*/
|
|
405
|
+
#beginFirstAttempt() {
|
|
406
|
+
if (this.getVariable("completionStatus")?.value !== "not_attempted")
|
|
407
|
+
return;
|
|
408
|
+
this._context = {
|
|
409
|
+
...this._context,
|
|
410
|
+
variables: this._context.variables.map((v) => v.identifier === "completionStatus" ? { ...v, value: "unknown" } : v)
|
|
411
|
+
};
|
|
347
412
|
}
|
|
348
413
|
getResponse(identifier) {
|
|
349
414
|
return this.getVariable(identifier);
|
|
@@ -380,9 +445,7 @@ var QtiAssessmentItem = class extends LitElement {
|
|
|
380
445
|
responseIdentifier: identifier,
|
|
381
446
|
response: Array.isArray(value) ? [...value] : value
|
|
382
447
|
});
|
|
383
|
-
|
|
384
|
-
this.updateOutcomeVariable("completionStatus", this.#getCompletionStatus());
|
|
385
|
-
}
|
|
448
|
+
this.validate(false);
|
|
386
449
|
}
|
|
387
450
|
/**
|
|
388
451
|
* Updates the template variable with the specified identifier to the given value.
|
|
@@ -450,32 +513,53 @@ var QtiAssessmentItem = class extends LitElement {
|
|
|
450
513
|
* @param value - The new value for the response variable.
|
|
451
514
|
*/
|
|
452
515
|
updateOutcomeVariable(identifier, value) {
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
516
|
+
this.#applyOutcomes([{ identifier, value }]);
|
|
517
|
+
}
|
|
518
|
+
/**
|
|
519
|
+
* Publishes the outcomes (and the validity) in one update, then a `cito-item-outcome-changed` per
|
|
520
|
+
* outcome with its final value and one `cito-item-outcomes-changed` with all of them.
|
|
521
|
+
* An identifier the item does not declare is skipped with a warning; a later entry for the same
|
|
522
|
+
* identifier wins.
|
|
523
|
+
*/
|
|
524
|
+
#applyOutcomes(outcomes, valid) {
|
|
525
|
+
const values = /* @__PURE__ */ new Map();
|
|
526
|
+
for (const { identifier, value } of outcomes) {
|
|
527
|
+
const variable = this.getVariable(identifier);
|
|
528
|
+
if (!variable) {
|
|
529
|
+
console.warn(`Can not set qti-outcome-identifier: ${identifier}, it is not available`);
|
|
530
|
+
continue;
|
|
531
|
+
}
|
|
532
|
+
values.set(identifier, variable.cardinality === "single" ? value : Array.isArray(value) ? value : [value]);
|
|
457
533
|
}
|
|
534
|
+
const validChanged = valid !== void 0 && valid !== this._context.valid;
|
|
535
|
+
if (values.size === 0 && !validChanged)
|
|
536
|
+
return;
|
|
458
537
|
this._context = {
|
|
459
538
|
...this._context,
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
return v;
|
|
463
|
-
}
|
|
464
|
-
return {
|
|
465
|
-
...v,
|
|
466
|
-
value: outcomeVariable.cardinality === "single" ? value : Array.isArray(value) ? value : [value]
|
|
467
|
-
};
|
|
468
|
-
})
|
|
539
|
+
...validChanged ? { valid } : {},
|
|
540
|
+
variables: this._context.variables.map((v) => values.has(v.identifier) ? { ...v, value: values.get(v.identifier) } : v)
|
|
469
541
|
};
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
542
|
+
if (values.size > 0) {
|
|
543
|
+
for (const [outcomeIdentifier, value] of values) {
|
|
544
|
+
dispatchPublic(this, "cito-item-outcome-changed", {
|
|
545
|
+
item: this.identifier,
|
|
546
|
+
outcomeIdentifier,
|
|
547
|
+
value
|
|
548
|
+
});
|
|
549
|
+
}
|
|
550
|
+
dispatchPublic(this, "cito-item-outcomes-changed", {
|
|
551
|
+
item: this.identifier,
|
|
552
|
+
outcomes: [...values].map(([identifier, value]) => ({ identifier, value }))
|
|
553
|
+
});
|
|
554
|
+
}
|
|
475
555
|
}
|
|
476
556
|
validate(reportValidity = true) {
|
|
477
|
-
const isValid = this
|
|
557
|
+
const isValid = this.#checkValidity(reportValidity);
|
|
478
558
|
this.#publishValidity(isValid);
|
|
559
|
+
return isValid;
|
|
560
|
+
}
|
|
561
|
+
#checkValidity(reportValidity) {
|
|
562
|
+
const isValid = this.interactionElements.every((interactionElement) => interactionElement.validate());
|
|
479
563
|
if (reportValidity) {
|
|
480
564
|
this.reportValidity();
|
|
481
565
|
}
|
|
@@ -507,34 +591,6 @@ var QtiAssessmentItem = class extends LitElement {
|
|
|
507
591
|
interactionElement.reportValidity();
|
|
508
592
|
}
|
|
509
593
|
}
|
|
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
594
|
};
|
|
539
595
|
__decorate([
|
|
540
596
|
property({ type: String })
|
|
@@ -798,16 +854,6 @@ var QtiCustomOperator = class extends LitElement7 {
|
|
|
798
854
|
value
|
|
799
855
|
}
|
|
800
856
|
}));
|
|
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
857
|
}
|
|
812
858
|
};
|
|
813
859
|
return this.#operatorFunction(this._context, fn, item);
|
|
@@ -1258,6 +1304,7 @@ __decorate7([
|
|
|
1258
1304
|
], QtiResponseDeclaration.prototype, "itemContext", void 0);
|
|
1259
1305
|
|
|
1260
1306
|
// ../qti-elements/dist/components/qti-response-processing/qti-response-processing.js
|
|
1307
|
+
import { ContextConsumer, ContextProvider } from "@lit/context";
|
|
1261
1308
|
import { css as css9, html as html12, LitElement as LitElement9 } from "lit";
|
|
1262
1309
|
|
|
1263
1310
|
// ../qti-elements/dist/internal/template-strings.js
|
|
@@ -1324,13 +1371,64 @@ var QtiResponseProcessing = class extends LitElement9 {
|
|
|
1324
1371
|
`
|
|
1325
1372
|
];
|
|
1326
1373
|
}
|
|
1374
|
+
/**
|
|
1375
|
+
* The rules inside read and write this element's copy of the item context, never the item's. It
|
|
1376
|
+
* is provided under the same `itemContext`: the nearest provider wins, so every expression in
|
|
1377
|
+
* here gets the copy without knowing about it.
|
|
1378
|
+
*/
|
|
1379
|
+
#provider = new ContextProvider(this, { context: itemContext });
|
|
1380
|
+
#copy;
|
|
1381
|
+
constructor() {
|
|
1382
|
+
super();
|
|
1383
|
+
new ContextConsumer(this, {
|
|
1384
|
+
context: itemContext,
|
|
1385
|
+
subscribe: true,
|
|
1386
|
+
// Every variable its own object, so a write changes the copy and not the item's context.
|
|
1387
|
+
callback: (context) => {
|
|
1388
|
+
this.#copy = { ...context, variables: context.variables.map((v) => ({ ...v })) };
|
|
1389
|
+
this.#provider.setValue(this.#copy);
|
|
1390
|
+
}
|
|
1391
|
+
});
|
|
1392
|
+
this.addEventListener("qti-set-outcome-value", (e) => {
|
|
1393
|
+
e.stopImmediatePropagation();
|
|
1394
|
+
const variable = this.#copy?.variables.find((v) => v.identifier === e.detail.outcomeIdentifier);
|
|
1395
|
+
if (!variable) {
|
|
1396
|
+
console.warn(`Can not set qti-outcome-identifier: ${e.detail.outcomeIdentifier}, it is not available`);
|
|
1397
|
+
return;
|
|
1398
|
+
}
|
|
1399
|
+
const { value } = e.detail;
|
|
1400
|
+
variable.value = variable.cardinality === "single" ? value : Array.isArray(value) ? value : [value];
|
|
1401
|
+
});
|
|
1402
|
+
}
|
|
1327
1403
|
render() {
|
|
1328
1404
|
return html12`<slot></slot>`;
|
|
1329
1405
|
}
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1406
|
+
/**
|
|
1407
|
+
* Scores the attempt on the copy: sets `numAttempts` to the count the item hands over, resets a
|
|
1408
|
+
* non-adaptive item's outcomes to their defaults (QTI info model §2.5), runs the rules and sends
|
|
1409
|
+
* every outcome and `numAttempts` in one `cito-item-set-outcomes`. The item applies them and publishes, which gives this element a
|
|
1410
|
+
* fresh copy. A rule that throws ends the run and the error propagates; nothing is sent, and the
|
|
1411
|
+
* run's writes stay in the copy until the item's next update.
|
|
1412
|
+
*/
|
|
1413
|
+
processResponse({ numAttempts }) {
|
|
1414
|
+
const copy = this.#copy;
|
|
1415
|
+
if (!copy)
|
|
1333
1416
|
return;
|
|
1417
|
+
const reset = this.closest("qti-assessment-item")?.getAttribute("adaptive") !== "true";
|
|
1418
|
+
for (const variable of copy.variables) {
|
|
1419
|
+
if (variable.identifier === "numAttempts")
|
|
1420
|
+
variable.value = String(numAttempts);
|
|
1421
|
+
if (variable.type === "outcome" && reset && variable.identifier !== "completionStatus") {
|
|
1422
|
+
variable.value = defaultValueOf(variable);
|
|
1423
|
+
}
|
|
1424
|
+
}
|
|
1425
|
+
this.#runRules();
|
|
1426
|
+
dispatchPublic(this, "cito-item-set-outcomes", {
|
|
1427
|
+
outcomes: copy.variables.filter((v) => v.type === "outcome" || v.identifier === "numAttempts").map(({ identifier, value }) => ({ identifier, value })),
|
|
1428
|
+
responseProcessed: true
|
|
1429
|
+
});
|
|
1430
|
+
}
|
|
1431
|
+
#runRules() {
|
|
1334
1432
|
const rules = [...this.children];
|
|
1335
1433
|
try {
|
|
1336
1434
|
for (const rule of rules) {
|
|
@@ -1352,6 +1450,12 @@ var QtiResponseProcessing = class extends LitElement9 {
|
|
|
1352
1450
|
this.innerHTML = rules;
|
|
1353
1451
|
}
|
|
1354
1452
|
};
|
|
1453
|
+
function defaultValueOf(variable) {
|
|
1454
|
+
const value = ("defaultValue" in variable ? variable.defaultValue : null) ?? null;
|
|
1455
|
+
if (value === null && (variable.baseType === "integer" || variable.baseType === "float"))
|
|
1456
|
+
return "0";
|
|
1457
|
+
return value;
|
|
1458
|
+
}
|
|
1355
1459
|
|
|
1356
1460
|
// ../qti-elements/dist/components/qti-rubric-block/qti-rubric-block.js
|
|
1357
1461
|
import { LitElement as LitElement10, css as css10, html as html13 } from "lit";
|
|
@@ -1740,4 +1844,4 @@ export {
|
|
|
1740
1844
|
QtiTemplateProcessing,
|
|
1741
1845
|
qtiContentElements
|
|
1742
1846
|
};
|
|
1743
|
-
//# sourceMappingURL=chunk-
|
|
1847
|
+
//# sourceMappingURL=chunk-C7SYDLMG.js.map
|