@qti-components/test 1.10.0 → 1.10.1
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,5 +1,10 @@
|
|
|
1
1
|
import { LitElement } from 'lit';
|
|
2
2
|
import type { ComputedContext } from '@qti-components/base';
|
|
3
|
+
/**
|
|
4
|
+
* A variable value as text: a list as `a, b`, a record (e.g. the response of a PCI) as `time: 3.6, point: 455 250`.
|
|
5
|
+
* Without this a record printed as "[object Object]".
|
|
6
|
+
*/
|
|
7
|
+
export declare const formatVariableValue: (value: unknown) => string;
|
|
3
8
|
export declare class TestPrintVariables extends LitElement {
|
|
4
9
|
computedContext?: ComputedContext;
|
|
5
10
|
static styles: import("lit").CSSResult;
|
|
@@ -6,7 +6,23 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
6
6
|
};
|
|
7
7
|
import { html, css, LitElement } from 'lit';
|
|
8
8
|
import { consume } from '@lit/context';
|
|
9
|
-
import { computedContext } from '@qti-components/base';
|
|
9
|
+
import { computedContext, isRecordValue } from '@qti-components/base';
|
|
10
|
+
/**
|
|
11
|
+
* A variable value as text: a list as `a, b`, a record (e.g. the response of a PCI) as `time: 3.6, point: 455 250`.
|
|
12
|
+
* Without this a record printed as "[object Object]".
|
|
13
|
+
*/
|
|
14
|
+
export const formatVariableValue = (value) => {
|
|
15
|
+
if (value === null || value === undefined)
|
|
16
|
+
return '';
|
|
17
|
+
if (Array.isArray(value))
|
|
18
|
+
return value.map(formatVariableValue).join(', ');
|
|
19
|
+
if (isRecordValue(value)) {
|
|
20
|
+
return Object.entries(value)
|
|
21
|
+
.map(([field, fieldValue]) => `${field}: ${formatVariableValue(fieldValue)}`)
|
|
22
|
+
.join(', ');
|
|
23
|
+
}
|
|
24
|
+
return String(value);
|
|
25
|
+
};
|
|
10
26
|
export class TestPrintVariables extends LitElement {
|
|
11
27
|
static { this.styles = css `
|
|
12
28
|
table {
|
|
@@ -52,17 +68,13 @@ export class TestPrintVariables extends LitElement {
|
|
|
52
68
|
</thead>
|
|
53
69
|
<tbody>
|
|
54
70
|
${variables.map(v => {
|
|
55
|
-
const correctResponse = v.correctResponse
|
|
56
|
-
? Array.isArray(v.correctResponse)
|
|
57
|
-
? v.correctResponse.join(', ')
|
|
58
|
-
: v.correctResponse
|
|
59
|
-
: '';
|
|
71
|
+
const correctResponse = formatVariableValue(v.correctResponse);
|
|
60
72
|
const mapEntries = v.mapping?.mapEntries?.map(m => `${m.mapKey}=${m.mappedValue}pt`).join(', ') || '';
|
|
61
73
|
const areaMapEntries = v.areaMapping?.areaMapEntries?.map(m => `${m.shape}(${m.coords})=${m.mappedValue}pt`).join(', ') || '';
|
|
62
74
|
return html `
|
|
63
75
|
<tr>
|
|
64
76
|
<td>${v.identifier}</td>
|
|
65
|
-
<td>${
|
|
77
|
+
<td>${formatVariableValue(v.value)}</td>
|
|
66
78
|
<td>${v.cardinality}</td>
|
|
67
79
|
<td>${v.baseType}</td>
|
|
68
80
|
<td>${correctResponse || mapEntries || areaMapEntries}</td>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"test-print-item-variables.js","sourceRoot":"","sources":["../../../src/components/test-print-item-variables/test-print-item-variables.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"test-print-item-variables.js","sourceRoot":"","sources":["../../../src/components/test-print-item-variables/test-print-item-variables.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,OAAO,EAAE,eAAe,EAAE,aAAa,EA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AAE,SAAS,EAAE,IAAI,EAAE,CAAC;2DACd","sourcesContent":["import { html, css, LitElement } from 'lit';\nimport { consume } from '@lit/context';\n\nimport { computedContext, isRecordValue } from '@qti-components/base';\n\nimport type { ResponseVariable } from '@qti-components/base';\nimport type { ComputedContext } from '@qti-components/base';\n\n/**\n * A variable value as text: a list as `a, b`, a record (e.g. the response of a PCI) as `time: 3.6, point: 455 250`.\n * Without this a record printed as \"[object Object]\".\n */\nexport const formatVariableValue = (value: unknown): string => {\n if (value === null || value === undefined) return '';\n if (Array.isArray(value)) return value.map(formatVariableValue).join(', ');\n if (isRecordValue(value)) {\n return Object.entries(value)\n .map(([field, fieldValue]) => `${field}: ${formatVariableValue(fieldValue)}`)\n .join(', ');\n }\n return String(value);\n};\n\nexport class TestPrintVariables extends LitElement {\n @consume({ context: computedContext, subscribe: true })\n public computedContext?: ComputedContext;\n\n static override styles = css`\n table {\n width: 100%;\n border-collapse: collapse;\n margin: 20px 0;\n font-size: 14px;\n text-align: left;\n }\n th,\n td {\n border: 1px solid #ddd;\n padding: 8px;\n }\n th {\n background-color: #f4f4f4;\n font-weight: bold;\n }\n h3 {\n margin-top: 20px;\n font-size: 16px;\n }\n `;\n\n override render() {\n const activeItem = this.computedContext?.testParts\n .flatMap(testPart => testPart.sections.flatMap(section => section.items))\n .find(item => item.active);\n\n if (!activeItem || !activeItem.variables) return html``;\n\n const responseVariables: ResponseVariable[] = activeItem.variables.filter(v => v.type === 'response');\n const outcomeVariables = activeItem.variables.filter(v => v.type === 'outcome');\n\n const renderTable = (variables: ResponseVariable[], title: string) => html`\n <h3>${title}</h3>\n <table>\n <thead>\n <tr>\n <th>Identifier</th>\n <th>Value</th>\n <th>Cardinality</th>\n <th>Base Type</th>\n <th>Correct Response / Mappings</th>\n </tr>\n </thead>\n <tbody>\n ${variables.map(v => {\n const correctResponse = formatVariableValue(v.correctResponse);\n\n const mapEntries = v.mapping?.mapEntries?.map(m => `${m.mapKey}=${m.mappedValue}pt`).join(', ') || '';\n\n const areaMapEntries =\n v.areaMapping?.areaMapEntries?.map(m => `${m.shape}(${m.coords})=${m.mappedValue}pt`).join(', ') || '';\n\n return html`\n <tr>\n <td>${v.identifier}</td>\n <td>${formatVariableValue(v.value)}</td>\n <td>${v.cardinality}</td>\n <td>${v.baseType}</td>\n <td>${correctResponse || mapEntries || areaMapEntries}</td>\n </tr>\n `;\n })}\n </tbody>\n </table>\n `;\n\n return html`\n ${renderTable(responseVariables, 'Response Variables')} ${renderTable(outcomeVariables, 'Outcome Variables')}\n `;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'test-print-item-variables': TestPrintVariables;\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@qti-components/test",
|
|
3
3
|
"description": "QTI test utilities",
|
|
4
|
-
"version": "1.10.
|
|
4
|
+
"version": "1.10.1",
|
|
5
5
|
"author": "",
|
|
6
6
|
"dependencies": {
|
|
7
7
|
"@heximal/templates": "^0.1.5",
|
|
8
|
-
"@qti-components/base": "^2.
|
|
9
|
-
"@qti-components/elements": "^1.10.
|
|
8
|
+
"@qti-components/base": "^2.5.0",
|
|
9
|
+
"@qti-components/elements": "^1.10.1",
|
|
10
10
|
"@qti-components/interactions": "^1.10.4",
|
|
11
|
-
"@qti-components/processing": "^1.6.
|
|
12
|
-
"@qti-components/theme": "^2.
|
|
11
|
+
"@qti-components/processing": "^1.6.1",
|
|
12
|
+
"@qti-components/theme": "^2.3.0",
|
|
13
13
|
"@qti-components/transformers": "^1.7.3",
|
|
14
14
|
"@qti-components/utilities": "^1.3.3"
|
|
15
15
|
},
|