@qti-components/test 1.7.0 → 1.9.0
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/components/qti-assessment-item-ref/qti-assessment-item-ref.d.ts +12 -0
- package/dist/components/qti-assessment-item-ref/qti-assessment-item-ref.js +55 -28
- package/dist/components/qti-assessment-item-ref/qti-assessment-item-ref.js.map +1 -1
- package/dist/components/qti-test/qti-test.d.ts +16 -2
- package/dist/components/qti-test/qti-test.js +33 -6
- package/dist/components/qti-test/qti-test.js.map +1 -1
- package/dist/components/styles.d.ts +3 -0
- package/dist/components/styles.js +29 -4
- package/dist/components/styles.js.map +1 -1
- package/dist/components/test-check-item/test-check-item.d.ts +2 -0
- package/dist/components/test-check-item/test-check-item.js +20 -2
- package/dist/components/test-check-item/test-check-item.js.map +1 -1
- package/dist/components/test-container/test-container.d.ts +3 -0
- package/dist/components/test-container/test-container.js +5 -1
- package/dist/components/test-container/test-container.js.map +1 -1
- package/dist/components/test-end-attempt/test-end-attempt.js +6 -0
- package/dist/components/test-end-attempt/test-end-attempt.js.map +1 -1
- package/dist/components/test-item-link/test-item-link.js +6 -0
- package/dist/components/test-item-link/test-item-link.js.map +1 -1
- package/dist/components/test-item-to-speech/test-item-to-speech.d.ts +128 -11
- package/dist/components/test-item-to-speech/test-item-to-speech.js +652 -103
- package/dist/components/test-item-to-speech/test-item-to-speech.js.map +1 -1
- package/dist/components/test-navigation/test-navigation.d.ts +9 -1
- package/dist/components/test-navigation/test-navigation.js +62 -17
- package/dist/components/test-navigation/test-navigation.js.map +1 -1
- package/dist/components/test-next/test-next.js +6 -0
- package/dist/components/test-next/test-next.js.map +1 -1
- package/dist/components/test-prev/test-prev.js +6 -0
- package/dist/components/test-prev/test-prev.js.map +1 -1
- package/dist/components/test-scoring-buttons/test-scoring-buttons.d.ts +1 -1
- package/dist/components/test-section-link/test-section-link.js +6 -0
- package/dist/components/test-section-link/test-section-link.js.map +1 -1
- package/dist/elements.d.ts +5 -2
- package/dist/elements.js +3 -2
- package/dist/elements.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/internal/test-host.context.d.ts +24 -0
- package/dist/internal/test-host.context.js +3 -0
- package/dist/internal/test-host.context.js.map +1 -0
- package/dist/mixins/index.d.ts +1 -0
- package/dist/mixins/index.js +1 -0
- package/dist/mixins/index.js.map +1 -1
- package/dist/mixins/test-base.d.ts +7 -2
- package/dist/mixins/test-base.js +53 -19
- package/dist/mixins/test-base.js.map +1 -1
- package/dist/mixins/test-navigation.mixin.d.ts +3 -4
- package/dist/mixins/test-navigation.mixin.js +11 -12
- package/dist/mixins/test-navigation.mixin.js.map +1 -1
- package/dist/mixins/test-processing.mixin.js +3 -1
- package/dist/mixins/test-processing.mixin.js.map +1 -1
- package/dist/mixins/test-state.mixin.d.ts +33 -0
- package/dist/mixins/test-state.mixin.js +130 -0
- package/dist/mixins/test-state.mixin.js.map +1 -0
- package/dist/types/iqti-test.d.ts +8 -5
- package/dist/types/iqti-test.js.map +1 -1
- package/dist/types/qti-test-state.d.ts +45 -0
- package/dist/types/qti-test-state.js +2 -0
- package/dist/types/qti-test-state.js.map +1 -0
- package/package.json +3 -3
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { LitElement } from 'lit';
|
|
2
|
+
import type { ComputedContext, ComputedItem } from '@qti-components/base';
|
|
2
3
|
import type { QtiAssessmentItem } from '@qti-components/elements';
|
|
4
|
+
import type { TestHost } from '../../internal/test-host.context';
|
|
3
5
|
import type { TemplateFunction } from '@heximal/templates';
|
|
4
6
|
/**
|
|
5
7
|
* The model a `<template item-ref>` is rendered with.
|
|
@@ -16,6 +18,12 @@ export interface ItemRefTemplateModel {
|
|
|
16
18
|
identifier?: string;
|
|
17
19
|
href?: string;
|
|
18
20
|
category?: string;
|
|
21
|
+
/**
|
|
22
|
+
* This item's entry in the computed context, the same object the stamps
|
|
23
|
+
* iterate as `item`: `index` (1-based, null for info items), `score`,
|
|
24
|
+
* `maxScore`, `completed`, `active`, … Undefined until the test has computed it.
|
|
25
|
+
*/
|
|
26
|
+
item?: ComputedItem;
|
|
19
27
|
/** The element being rendered. */
|
|
20
28
|
itemRef: QtiAssessmentItemRef;
|
|
21
29
|
}
|
|
@@ -26,6 +34,7 @@ export declare class QtiAssessmentItemRef extends LitElement {
|
|
|
26
34
|
required?: boolean;
|
|
27
35
|
fixed?: boolean;
|
|
28
36
|
href?: string;
|
|
37
|
+
protected computedContext?: ComputedContext;
|
|
29
38
|
/**
|
|
30
39
|
* The `<qti-weight>` children of this ref, keyed by identifier — what
|
|
31
40
|
* `qti-test-variables`' `weight-identifier` resolves against.
|
|
@@ -39,6 +48,9 @@ export declare class QtiAssessmentItemRef extends LitElement {
|
|
|
39
48
|
protected createRenderRoot(): HTMLElement | DocumentFragment;
|
|
40
49
|
get assessmentItem(): QtiAssessmentItem | null;
|
|
41
50
|
myTemplate: TemplateFunction | null;
|
|
51
|
+
/** The `qti-test` this ref belongs to, wherever it renders: light DOM, or any depth of shadow roots. */
|
|
52
|
+
protected testHost?: TestHost;
|
|
53
|
+
disconnectedCallback(): void;
|
|
42
54
|
connectedCallback(): Promise<void>;
|
|
43
55
|
render(): unknown;
|
|
44
56
|
}
|
|
@@ -5,8 +5,11 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
7
|
import { LitElement, nothing } from 'lit';
|
|
8
|
-
import { property } from 'lit/decorators.js';
|
|
8
|
+
import { property, state } from 'lit/decorators.js';
|
|
9
|
+
import { consume } from '@lit/context';
|
|
9
10
|
import { prepareTemplate } from '@heximal/templates';
|
|
11
|
+
import { computedContext } from '@qti-components/base';
|
|
12
|
+
import { testHostContext } from '../../internal/test-host.context';
|
|
10
13
|
// Converter function to interpret "true" and "false" as booleans
|
|
11
14
|
const stringToBooleanConverter = {
|
|
12
15
|
fromAttribute(value) {
|
|
@@ -22,9 +25,15 @@ export class QtiAssessmentItemRef extends LitElement {
|
|
|
22
25
|
super(...arguments);
|
|
23
26
|
this.xmlDoc = null;
|
|
24
27
|
this.myTemplate = null;
|
|
28
|
+
/**
|
|
29
|
+
* The clone of `xmlDoc` that is rendered, and what it was cloned for. Cloned
|
|
30
|
+
* once per document and template, not per render: re-renders from
|
|
31
|
+
* computed-context changes then hand Lit the same fragment, which it leaves
|
|
32
|
+
* alone, instead of rebuilding the item (and reloading its PCIs, which
|
|
33
|
+
* changes the context again).
|
|
34
|
+
*/
|
|
35
|
+
this.#rendered = null;
|
|
25
36
|
}
|
|
26
|
-
// @consume({ context: computedContext, subscribe: true })
|
|
27
|
-
// private computedContext: ComputedContext;
|
|
28
37
|
/**
|
|
29
38
|
* The `<qti-weight>` children of this ref, keyed by identifier — what
|
|
30
39
|
* `qti-test-variables`' `weight-identifier` resolves against.
|
|
@@ -54,28 +63,11 @@ export class QtiAssessmentItemRef extends LitElement {
|
|
|
54
63
|
get assessmentItem() {
|
|
55
64
|
return this.renderRoot?.querySelector('qti-assessment-item');
|
|
56
65
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
* usually one hop below one; but it is also valid in plain light DOM, and a
|
|
63
|
-
* host is free to nest it deeper. Climbing root by root covers all three
|
|
64
|
-
* without assuming any of them.
|
|
65
|
-
*/
|
|
66
|
-
#findTestElement() {
|
|
67
|
-
const own = this.closest('qti-test');
|
|
68
|
-
if (own)
|
|
69
|
-
return own;
|
|
70
|
-
let root = this.getRootNode();
|
|
71
|
-
while (root instanceof ShadowRoot) {
|
|
72
|
-
const test = root.host.closest('qti-test');
|
|
73
|
-
if (test)
|
|
74
|
-
return test;
|
|
75
|
-
root = root.host.getRootNode();
|
|
76
|
-
}
|
|
77
|
-
// A Document, or a fragment that is not attached to one: nowhere left to climb.
|
|
78
|
-
return null;
|
|
66
|
+
disconnectedCallback() {
|
|
67
|
+
super.disconnectedCallback();
|
|
68
|
+
// A context consumer keeps its last value when it is moved somewhere with no provider, and
|
|
69
|
+
// `closest()` never did: a ref moved out of a test must not keep that test's template.
|
|
70
|
+
this.testHost = undefined;
|
|
79
71
|
}
|
|
80
72
|
async connectedCallback() {
|
|
81
73
|
super.connectedCallback();
|
|
@@ -99,7 +91,7 @@ export class QtiAssessmentItemRef extends LitElement {
|
|
|
99
91
|
Resolved once, on connect: one template serves every item, and everything
|
|
100
92
|
that varies per item comes through the model (see ItemRefTemplateModel).
|
|
101
93
|
*/
|
|
102
|
-
const templateElement = this
|
|
94
|
+
const templateElement = this.testHost?.querySelector('template[item-ref]');
|
|
103
95
|
this.myTemplate = templateElement ? prepareTemplate(templateElement) : null;
|
|
104
96
|
this.requestUpdate();
|
|
105
97
|
await this.updateComplete;
|
|
@@ -109,11 +101,38 @@ export class QtiAssessmentItemRef extends LitElement {
|
|
|
109
101
|
detail: { identifier: this.identifier, href: this.href, category: this.category }
|
|
110
102
|
}));
|
|
111
103
|
}
|
|
104
|
+
#computedItem() {
|
|
105
|
+
for (const testPart of this.computedContext?.testParts ?? []) {
|
|
106
|
+
for (const section of testPart.sections) {
|
|
107
|
+
const item = section.items.find(i => i.identifier === this.identifier);
|
|
108
|
+
if (item)
|
|
109
|
+
return item;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return undefined;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* The clone of `xmlDoc` that is rendered, and what it was cloned for. Cloned
|
|
116
|
+
* once per document and template, not per render: re-renders from
|
|
117
|
+
* computed-context changes then hand Lit the same fragment, which it leaves
|
|
118
|
+
* alone, instead of rebuilding the item (and reloading its PCIs, which
|
|
119
|
+
* changes the context again).
|
|
120
|
+
*/
|
|
121
|
+
#rendered;
|
|
112
122
|
render() {
|
|
113
123
|
// Item refs connect before loading, and navigation clears their documents.
|
|
114
|
-
if (!this.xmlDoc)
|
|
124
|
+
if (!this.xmlDoc) {
|
|
125
|
+
this.#rendered = null;
|
|
115
126
|
return nothing;
|
|
116
|
-
|
|
127
|
+
}
|
|
128
|
+
if (this.#rendered?.source !== this.xmlDoc || this.#rendered.template !== this.myTemplate) {
|
|
129
|
+
this.#rendered = {
|
|
130
|
+
source: this.xmlDoc,
|
|
131
|
+
template: this.myTemplate,
|
|
132
|
+
doc: this.xmlDoc.cloneNode(true)
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
const xmlDoc = this.#rendered.doc;
|
|
117
136
|
if (!this.myTemplate)
|
|
118
137
|
return xmlDoc;
|
|
119
138
|
const model = {
|
|
@@ -121,6 +140,7 @@ export class QtiAssessmentItemRef extends LitElement {
|
|
|
121
140
|
identifier: this.identifier,
|
|
122
141
|
href: this.href,
|
|
123
142
|
category: this.category,
|
|
143
|
+
item: this.#computedItem(),
|
|
124
144
|
itemRef: this
|
|
125
145
|
};
|
|
126
146
|
return this.myTemplate(model);
|
|
@@ -141,7 +161,14 @@ __decorate([
|
|
|
141
161
|
__decorate([
|
|
142
162
|
property({ type: String })
|
|
143
163
|
], QtiAssessmentItemRef.prototype, "href", void 0);
|
|
164
|
+
__decorate([
|
|
165
|
+
state(),
|
|
166
|
+
consume({ context: computedContext, subscribe: true })
|
|
167
|
+
], QtiAssessmentItemRef.prototype, "computedContext", void 0);
|
|
144
168
|
__decorate([
|
|
145
169
|
property({ type: Object, attribute: false })
|
|
146
170
|
], QtiAssessmentItemRef.prototype, "xmlDoc", void 0);
|
|
171
|
+
__decorate([
|
|
172
|
+
consume({ context: testHostContext, subscribe: true })
|
|
173
|
+
], QtiAssessmentItemRef.prototype, "testHost", void 0);
|
|
147
174
|
//# sourceMappingURL=qti-assessment-item-ref.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"qti-assessment-item-ref.js","sourceRoot":"","sources":["../../../src/components/qti-assessment-item-ref/qti-assessment-item-ref.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,UAAU,EAAE,OAA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AC3E,IAAI,CAAC,IAAI,CAAC,MAAM;YAAE,OAAO,OAAO,CAAC;QAEjC,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,CAAqB,CAAC;QAC/D,IAAI,CAAC,IAAI,CAAC,UAAU;YAAE,OAAO,MAAM,CAAC;QAEpC,MAAM,KAAK,GAAyB;YAClC,MAAM;YACN,UAAU,EAAE,IAAI,CAAC,UAAU;YAC3B,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,OAAO,EAAE,IAAI;SACd,CAAC;QACF,OAAO,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;IAChC,CAAC;CACF;AA1H6B;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;sDAAmB;AAClB;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;wDAAqB;AACkB;IAAjE,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,wBAAwB,EAAE,CAAC;sDAAoB;AACnB;IAAjE,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,wBAAwB,EAAE,CAAC;mDAAiB;AACtD;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;kDAAe;AA6B1C;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;oDACN","sourcesContent":["import { LitElement, nothing } from 'lit';\nimport { property } from 'lit/decorators.js';\nimport { prepareTemplate } from '@heximal/templates';\n\nimport type { QtiAssessmentItem } from '@qti-components/elements';\nimport type { TemplateFunction } from '@heximal/templates';\n\n// Converter function to interpret \"true\" and \"false\" as booleans\nconst stringToBooleanConverter = {\n fromAttribute(value: string): boolean {\n return value === 'true';\n },\n toAttribute(value: boolean): string {\n return value ? 'true' : 'false';\n }\n};\n\n/**\n * The model a `<template item-ref>` is rendered with.\n *\n * Only what this element already knows: the item's parsed document and the\n * attributes off the item-ref itself. `itemRef` is the escape hatch — a\n * template that needs anything else (a click handler, a value from the host\n * app) reaches it through a property on the element, which the host is free to\n * set.\n */\nexport interface ItemRefTemplateModel {\n /** The item's parsed document, i.e. what the element renders by default. */\n xmlDoc: DocumentFragment;\n identifier?: string;\n href?: string;\n category?: string;\n /** The element being rendered. */\n itemRef: QtiAssessmentItemRef;\n}\n\n// @customElement('qti-assessment-item-ref')\nexport class QtiAssessmentItemRef extends LitElement {\n @property({ type: String }) category?: string;\n @property({ type: String }) identifier?: string;\n @property({ type: Boolean, converter: stringToBooleanConverter }) required?: boolean;\n @property({ type: Boolean, converter: stringToBooleanConverter }) fixed?: boolean;\n @property({ type: String }) href?: string;\n\n // @consume({ context: computedContext, subscribe: true })\n // private computedContext: ComputedContext;\n\n /**\n * The `<qti-weight>` children of this ref, keyed by identifier — what\n * `qti-test-variables`' `weight-identifier` resolves against.\n *\n * Read on access rather than cached: the test document is rendered into this\n * element's light DOM, so the weights are not in place at construction time,\n * and outcome processing runs long after they are.\n */\n get weights(): Map<string, number> {\n const weights = new Map<string, number>();\n for (const weight of this.querySelectorAll(':scope > qti-weight')) {\n const identifier = weight.getAttribute('identifier');\n if (!identifier) continue;\n const value = Number(weight.getAttribute('value'));\n if (Number.isNaN(value)) {\n console.warn(`qti-weight \"${identifier}\" has a non-numeric value, ignoring it`);\n continue;\n }\n weights.set(identifier, value);\n }\n return weights;\n }\n\n @property({ type: Object, attribute: false })\n xmlDoc: DocumentFragment | null = null;\n\n protected override createRenderRoot(): HTMLElement | DocumentFragment {\n return this;\n }\n\n get assessmentItem(): QtiAssessmentItem | null {\n return this.renderRoot?.querySelector('qti-assessment-item');\n }\n\n myTemplate: TemplateFunction | null = null;\n\n /**\n * The `<qti-test>` this ref belongs to, crossing shadow boundaries on the way\n * up.\n *\n * `<test-container>` renders its items into a shadow root, so an item-ref is\n * usually one hop below one; but it is also valid in plain light DOM, and a\n * host is free to nest it deeper. Climbing root by root covers all three\n * without assuming any of them.\n */\n #findTestElement(): Element | null {\n const own = this.closest('qti-test');\n if (own) return own;\n\n let root: Node = this.getRootNode();\n while (root instanceof ShadowRoot) {\n const test = root.host.closest('qti-test');\n if (test) return test;\n root = root.host.getRootNode();\n }\n // A Document, or a fragment that is not attached to one: nowhere left to climb.\n return null;\n }\n\n override async connectedCallback(): Promise<void> {\n super.connectedCallback();\n\n /*\n Optional per-item template, used to render extra things around an item —\n a bookmark, an index number, a score badge. Put it in the light DOM of\n your qti-test, and every item-ref in the test renders with it:\n\n <qti-test>\n <template item-ref>\n <div class=\"badge\">{{ identifier }}</div>\n {{ xmlDoc }}\n </template>\n …\n </qti-test>\n\n The template is the WHOLE render, so it has to place {{ xmlDoc }} itself;\n leaving it out renders the chrome and no item. Without a template the\n element renders the item on its own, exactly as before.\n\n Resolved once, on connect: one template serves every item, and everything\n that varies per item comes through the model (see ItemRefTemplateModel).\n */\n const templateElement = this.#findTestElement()?.querySelector<HTMLTemplateElement>('template[item-ref]');\n this.myTemplate = templateElement ? prepareTemplate(templateElement) : null;\n this.requestUpdate();\n\n await this.updateComplete;\n\n this.dispatchEvent(\n new CustomEvent('qti-assessment-item-ref-connected', {\n bubbles: true,\n composed: true,\n detail: { identifier: this.identifier, href: this.href, category: this.category }\n })\n );\n }\n\n override render() {\n // Item refs connect before loading, and navigation clears their documents.\n if (!this.xmlDoc) return nothing;\n\n const xmlDoc = this.xmlDoc.cloneNode(true) as DocumentFragment;\n if (!this.myTemplate) return xmlDoc;\n\n const model: ItemRefTemplateModel = {\n xmlDoc,\n identifier: this.identifier,\n href: this.href,\n category: this.category,\n itemRef: this\n };\n return this.myTemplate(model);\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'qti-assessment-item-ref': QtiAssessmentItemRef;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"qti-assessment-item-ref.js","sourceRoot":"","sources":["../../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CAAC;CACF;AA9I6B;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;sDAAmB;AAClB;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;wDAAqB;AACkB;IAAjE,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,wBAAwB,EAAE,CAAC;sDAAoB;AACnB;IAAjE,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,wBAAwB,EAAE,CAAC;mDAAiB;AACtD;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;kDAAe;AAKhC;IAFT,KAAK,EAAE;IACP,OAAO,CAAC,EAAE,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;6DACX;AA0B5C;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;oDACN;AAc7B;IADT,OAAO,CAAC,EAAE,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;sDACzB","sourcesContent":["import { LitElement, nothing } from 'lit';\nimport { property, state } from 'lit/decorators.js';\nimport { consume } from '@lit/context';\nimport { prepareTemplate } from '@heximal/templates';\n\nimport { computedContext } from '@qti-components/base';\n\nimport { testHostContext } from '../../internal/test-host.context';\n\nimport type { ComputedContext, ComputedItem } from '@qti-components/base';\nimport type { QtiAssessmentItem } from '@qti-components/elements';\nimport type { TestHost } from '../../internal/test-host.context';\nimport type { TemplateFunction } from '@heximal/templates';\n\n// Converter function to interpret \"true\" and \"false\" as booleans\nconst stringToBooleanConverter = {\n fromAttribute(value: string): boolean {\n return value === 'true';\n },\n toAttribute(value: boolean): string {\n return value ? 'true' : 'false';\n }\n};\n\n/**\n * The model a `<template item-ref>` is rendered with.\n *\n * Only what this element already knows: the item's parsed document and the\n * attributes off the item-ref itself. `itemRef` is the escape hatch — a\n * template that needs anything else (a click handler, a value from the host\n * app) reaches it through a property on the element, which the host is free to\n * set.\n */\nexport interface ItemRefTemplateModel {\n /** The item's parsed document, i.e. what the element renders by default. */\n xmlDoc: DocumentFragment;\n identifier?: string;\n href?: string;\n category?: string;\n /**\n * This item's entry in the computed context, the same object the stamps\n * iterate as `item`: `index` (1-based, null for info items), `score`,\n * `maxScore`, `completed`, `active`, … Undefined until the test has computed it.\n */\n item?: ComputedItem;\n /** The element being rendered. */\n itemRef: QtiAssessmentItemRef;\n}\n\n// @customElement('qti-assessment-item-ref')\nexport class QtiAssessmentItemRef extends LitElement {\n @property({ type: String }) category?: string;\n @property({ type: String }) identifier?: string;\n @property({ type: Boolean, converter: stringToBooleanConverter }) required?: boolean;\n @property({ type: Boolean, converter: stringToBooleanConverter }) fixed?: boolean;\n @property({ type: String }) href?: string;\n\n // Only read by a <template item-ref>; subscribing re-renders it as scores come in\n @state()\n @consume({ context: computedContext, subscribe: true })\n protected computedContext?: ComputedContext;\n\n /**\n * The `<qti-weight>` children of this ref, keyed by identifier — what\n * `qti-test-variables`' `weight-identifier` resolves against.\n *\n * Read on access rather than cached: the test document is rendered into this\n * element's light DOM, so the weights are not in place at construction time,\n * and outcome processing runs long after they are.\n */\n get weights(): Map<string, number> {\n const weights = new Map<string, number>();\n for (const weight of this.querySelectorAll(':scope > qti-weight')) {\n const identifier = weight.getAttribute('identifier');\n if (!identifier) continue;\n const value = Number(weight.getAttribute('value'));\n if (Number.isNaN(value)) {\n console.warn(`qti-weight \"${identifier}\" has a non-numeric value, ignoring it`);\n continue;\n }\n weights.set(identifier, value);\n }\n return weights;\n }\n\n @property({ type: Object, attribute: false })\n xmlDoc: DocumentFragment | null = null;\n\n protected override createRenderRoot(): HTMLElement | DocumentFragment {\n return this;\n }\n\n get assessmentItem(): QtiAssessmentItem | null {\n return this.renderRoot?.querySelector('qti-assessment-item');\n }\n\n myTemplate: TemplateFunction | null = null;\n\n /** The `qti-test` this ref belongs to, wherever it renders: light DOM, or any depth of shadow roots. */\n @consume({ context: testHostContext, subscribe: true })\n protected testHost?: TestHost;\n\n override disconnectedCallback(): void {\n super.disconnectedCallback();\n // A context consumer keeps its last value when it is moved somewhere with no provider, and\n // `closest()` never did: a ref moved out of a test must not keep that test's template.\n this.testHost = undefined;\n }\n\n override async connectedCallback(): Promise<void> {\n super.connectedCallback();\n\n /*\n Optional per-item template, used to render extra things around an item —\n a bookmark, an index number, a score badge. Put it in the light DOM of\n your qti-test, and every item-ref in the test renders with it:\n\n <qti-test>\n <template item-ref>\n <div class=\"badge\">{{ identifier }}</div>\n {{ xmlDoc }}\n </template>\n …\n </qti-test>\n\n The template is the WHOLE render, so it has to place {{ xmlDoc }} itself;\n leaving it out renders the chrome and no item. Without a template the\n element renders the item on its own, exactly as before.\n\n Resolved once, on connect: one template serves every item, and everything\n that varies per item comes through the model (see ItemRefTemplateModel).\n */\n const templateElement = this.testHost?.querySelector<HTMLTemplateElement>('template[item-ref]');\n this.myTemplate = templateElement ? prepareTemplate(templateElement) : null;\n this.requestUpdate();\n\n await this.updateComplete;\n\n this.dispatchEvent(\n new CustomEvent('qti-assessment-item-ref-connected', {\n bubbles: true,\n composed: true,\n detail: { identifier: this.identifier, href: this.href, category: this.category }\n })\n );\n }\n\n #computedItem(): ComputedItem | undefined {\n for (const testPart of this.computedContext?.testParts ?? []) {\n for (const section of testPart.sections) {\n const item = section.items.find(i => i.identifier === this.identifier);\n if (item) return item;\n }\n }\n return undefined;\n }\n\n /**\n * The clone of `xmlDoc` that is rendered, and what it was cloned for. Cloned\n * once per document and template, not per render: re-renders from\n * computed-context changes then hand Lit the same fragment, which it leaves\n * alone, instead of rebuilding the item (and reloading its PCIs, which\n * changes the context again).\n */\n #rendered: { source: DocumentFragment; template: TemplateFunction | null; doc: DocumentFragment } | null = null;\n\n override render() {\n // Item refs connect before loading, and navigation clears their documents.\n if (!this.xmlDoc) {\n this.#rendered = null;\n return nothing;\n }\n\n if (this.#rendered?.source !== this.xmlDoc || this.#rendered.template !== this.myTemplate) {\n this.#rendered = {\n source: this.xmlDoc,\n template: this.myTemplate,\n doc: this.xmlDoc.cloneNode(true) as DocumentFragment\n };\n }\n const xmlDoc = this.#rendered.doc;\n if (!this.myTemplate) return xmlDoc;\n\n const model: ItemRefTemplateModel = {\n xmlDoc,\n identifier: this.identifier,\n href: this.href,\n category: this.category,\n item: this.#computedItem(),\n itemRef: this\n };\n return this.myTemplate(model);\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'qti-assessment-item-ref': QtiAssessmentItemRef;\n }\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { LitElement } from 'lit';
|
|
2
|
-
import type { ConfigContext } from '@qti-components/base';
|
|
2
|
+
import type { ConfigContext, QtiContext } from '@qti-components/base';
|
|
3
3
|
declare const QtiTest_base: (abstract new (...args: any[]) => import("../..").ITestNavigationMixin) & (abstract new (...args: any[]) => {
|
|
4
4
|
updateAssessmentItemView(assessmentItem: import("@qti-components/elements").QtiAssessmentItem, view: import("@qti-components/base").View): void;
|
|
5
5
|
}) & (abstract new (...args: any[]) => {
|
|
@@ -7,7 +7,7 @@ declare const QtiTest_base: (abstract new (...args: any[]) => import("../..").IT
|
|
|
7
7
|
getOutcome(identifier: string): Readonly<import("@qti-components/base").OutcomeVariable>;
|
|
8
8
|
getVariable(identifier: string): Readonly<import("@qti-components/base").VariableDeclaration<string | string[] | null>>;
|
|
9
9
|
outcomeProcessing(): boolean;
|
|
10
|
-
}) & (abstract new (...args: any[]) => import("../../mixins").TestBaseInterface) & typeof LitElement;
|
|
10
|
+
}) & (abstract new (...args: any[]) => import("../..").ITestStateMixin) & (abstract new (...args: any[]) => import("../../mixins").TestBaseInterface) & typeof LitElement;
|
|
11
11
|
/**
|
|
12
12
|
* `<qti-test>` is a custom element designed for rendering and interacting with QTI (Question and Test Interoperability) tests.
|
|
13
13
|
*
|
|
@@ -55,9 +55,23 @@ declare const QtiTest_base: (abstract new (...args: any[]) => import("../..").IT
|
|
|
55
55
|
* You can use normal class names to style the elements.
|
|
56
56
|
* And you can use the `test-prev` and `test-next` elements to navigate through the test.
|
|
57
57
|
*
|
|
58
|
+
* @event qti-state-changed - The candidate's persistable state changed. `detail` is a `QtiTestState`; assign it back to `state` to resume.
|
|
59
|
+
* @event qti-test-context-updated - Deprecated: listen to `qti-state-changed` to persist a session. `detail` is the full test context, including declaration metadata and the answer key. Removed in the next major.
|
|
58
60
|
*/
|
|
59
61
|
export declare class QtiTest extends QtiTest_base {
|
|
62
|
+
constructor();
|
|
60
63
|
configContext: ConfigContext;
|
|
64
|
+
/**
|
|
65
|
+
* Who is taking which test, and the optional shuffle `seed`. Provided here, at the test, so
|
|
66
|
+
* everything inside reads one value: the test-container shuffling the item order, the test
|
|
67
|
+
* shuffling interactions as it navigates, and the expressions that read `QTI_CONTEXT`.
|
|
68
|
+
*
|
|
69
|
+
* Pass the same `seed` when resuming a session, or the order comes back different. Replace the
|
|
70
|
+
* object, do not mutate it: an in-place change does not notify the components inside.
|
|
71
|
+
*
|
|
72
|
+
* `test-navigation.qtiContext` is an alias of this.
|
|
73
|
+
*/
|
|
74
|
+
qtiContext: QtiContext;
|
|
61
75
|
/**
|
|
62
76
|
* Renders the component's template.
|
|
63
77
|
* Provides a default `<slot>` for content projection.
|
|
@@ -4,13 +4,15 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
4
4
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
6
|
};
|
|
7
|
-
import { provide } from '@lit/context';
|
|
7
|
+
import { ContextProvider, provide } from '@lit/context';
|
|
8
8
|
import { html, LitElement } from 'lit';
|
|
9
9
|
import { state } from 'lit/decorators.js';
|
|
10
|
-
import { configContext } from '@qti-components/base';
|
|
10
|
+
import { configContext, qtiContext } from '@qti-components/base';
|
|
11
|
+
import { testHostContext } from '../../internal/test-host.context';
|
|
11
12
|
import { TestNavigationMixin, TestViewMixin } from '../../mixins';
|
|
12
13
|
import { TestBaseMixin } from '../../mixins/test-base';
|
|
13
14
|
import { TestProcessingMixin } from '../../mixins/test-processing.mixin';
|
|
15
|
+
import { TestStateMixin } from '../../mixins/test-state.mixin';
|
|
14
16
|
/**
|
|
15
17
|
* `<qti-test>` is a custom element designed for rendering and interacting with QTI (Question and Test Interoperability) tests.
|
|
16
18
|
*
|
|
@@ -58,13 +60,34 @@ import { TestProcessingMixin } from '../../mixins/test-processing.mixin';
|
|
|
58
60
|
* You can use normal class names to style the elements.
|
|
59
61
|
* And you can use the `test-prev` and `test-next` elements to navigate through the test.
|
|
60
62
|
*
|
|
63
|
+
* @event qti-state-changed - The candidate's persistable state changed. `detail` is a `QtiTestState`; assign it back to `state` to resume.
|
|
64
|
+
* @event qti-test-context-updated - Deprecated: listen to `qti-state-changed` to persist a session. `detail` is the full test context, including declaration metadata and the answer key. Removed in the next major.
|
|
61
65
|
*/
|
|
62
|
-
export class QtiTest extends TestNavigationMixin(TestViewMixin(TestProcessingMixin(TestBaseMixin(LitElement)))) {
|
|
66
|
+
export class QtiTest extends TestNavigationMixin(TestViewMixin(TestProcessingMixin(TestStateMixin(TestBaseMixin(LitElement))))) {
|
|
67
|
+
// TODO: Properly implement IQtiTest interface
|
|
68
|
+
// export class QtiTest extends TestLoaderMixin(TestNavigationMixin(TestViewMixin(TestBase))) {
|
|
63
69
|
constructor() {
|
|
64
|
-
|
|
65
|
-
// export class QtiTest extends TestLoaderMixin(TestNavigationMixin(TestViewMixin(TestBase))) {
|
|
66
|
-
super(...arguments);
|
|
70
|
+
super();
|
|
67
71
|
this.configContext = {};
|
|
72
|
+
/**
|
|
73
|
+
* Who is taking which test, and the optional shuffle `seed`. Provided here, at the test, so
|
|
74
|
+
* everything inside reads one value: the test-container shuffling the item order, the test
|
|
75
|
+
* shuffling interactions as it navigates, and the expressions that read `QTI_CONTEXT`.
|
|
76
|
+
*
|
|
77
|
+
* Pass the same `seed` when resuming a session, or the order comes back different. Replace the
|
|
78
|
+
* object, do not mutate it: an in-place change does not notify the components inside.
|
|
79
|
+
*
|
|
80
|
+
* `test-navigation.qtiContext` is an alias of this.
|
|
81
|
+
*/
|
|
82
|
+
this.qtiContext = {
|
|
83
|
+
QTI_CONTEXT: {
|
|
84
|
+
testIdentifier: '',
|
|
85
|
+
candidateIdentifier: '',
|
|
86
|
+
environmentIdentifier: 'default'
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
// The components inside find their test through this, across shadow roots (see TestHost).
|
|
90
|
+
new ContextProvider(this, { context: testHostContext, initialValue: this });
|
|
68
91
|
}
|
|
69
92
|
/**
|
|
70
93
|
* Renders the component's template.
|
|
@@ -83,4 +106,8 @@ __decorate([
|
|
|
83
106
|
state(),
|
|
84
107
|
provide({ context: configContext })
|
|
85
108
|
], QtiTest.prototype, "configContext", void 0);
|
|
109
|
+
__decorate([
|
|
110
|
+
state(),
|
|
111
|
+
provide({ context: qtiContext })
|
|
112
|
+
], QtiTest.prototype, "qtiContext", void 0);
|
|
86
113
|
//# sourceMappingURL=qti-test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"qti-test.js","sourceRoot":"","sources":["../../../src/components/qti-test/qti-test.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"qti-test.js","sourceRoot":"","sources":["../../../src/components/qti-test/qti-test.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACxD,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AACvC,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAE1C,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAEjE,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AAC;8CACK;AAclC;IAFN,KAAK,EAAE;IACP,OAAO,CAAC,EAAE,OAAO,EAAE,UAAU,EAAE,CAAC;2CAO/B","sourcesContent":["import { ContextProvider, provide } from '@lit/context';\nimport { html, LitElement } from 'lit';\nimport { state } from 'lit/decorators.js';\n\nimport { configContext, qtiContext } from '@qti-components/base';\n\nimport { testHostContext } from '../../internal/test-host.context';\nimport { TestNavigationMixin, TestViewMixin } from '../../mixins';\nimport { TestBaseMixin } from '../../mixins/test-base';\nimport { TestProcessingMixin } from '../../mixins/test-processing.mixin';\nimport { TestStateMixin } from '../../mixins/test-state.mixin';\n\nimport type { ConfigContext, QtiContext } from '@qti-components/base';\nimport type { IQtiTest } from '../../types/iqti-test';\n\n/**\n * `<qti-test>` is a custom element designed for rendering and interacting with QTI (Question and Test Interoperability) tests.\n *\n * This component leverages several mixins to provide functionality for loading, navigating, processing, and displaying QTI test assessments.\n *\n * ### Example Usage\n *\n * Minimal example including navigation:\n *\n * ```html\n * <qti-test>\n * <test-navigation>\n * <test-container test-url=\"./path/to/assessment.xml\"></test-container>\n * <nav class=\"flex\">\n * <test-prev></test-prev>\n * <test-next></test-next>\n * </nav>\n * </test-navigation>\n * </qti-test>\n * ```\n *\n * Use the following file structure\n * A qti-test loads a QTI3.0 assessmenttest.xml file from a package folder.\n *\n * ```plaintext\n * Root/\n * ├── index.html\n * └── /assets/api/examples/\n * ├── assessmenttest.xml\n * └── imsmanifest.xml\n *\n * ```\n *\n * ### Test components\n *\n * Use test components inside the qti-test component for added functionality.\n * ### Test next\n * `<test-next> | TestNext`\n *\n * ### Test prev\n *\n * `<test-prev> | TestPrev`\n * ### Test components\n *\n * You can use normal class names to style the elements.\n * And you can use the `test-prev` and `test-next` elements to navigate through the test.\n *\n * @event qti-state-changed - The candidate's persistable state changed. `detail` is a `QtiTestState`; assign it back to `state` to resume.\n * @event qti-test-context-updated - Deprecated: listen to `qti-state-changed` to persist a session. `detail` is the full test context, including declaration metadata and the answer key. Removed in the next major.\n */\n\nexport class QtiTest extends TestNavigationMixin(\n TestViewMixin(TestProcessingMixin(TestStateMixin(TestBaseMixin(LitElement))))\n) {\n // TODO: Properly implement IQtiTest interface\n // export class QtiTest extends TestLoaderMixin(TestNavigationMixin(TestViewMixin(TestBase))) {\n\n constructor() {\n super();\n // The components inside find their test through this, across shadow roots (see TestHost).\n new ContextProvider(this, { context: testHostContext, initialValue: this });\n }\n\n @state()\n @provide({ context: configContext })\n public configContext: ConfigContext = {};\n\n /**\n * Who is taking which test, and the optional shuffle `seed`. Provided here, at the test, so\n * everything inside reads one value: the test-container shuffling the item order, the test\n * shuffling interactions as it navigates, and the expressions that read `QTI_CONTEXT`.\n *\n * Pass the same `seed` when resuming a session, or the order comes back different. Replace the\n * object, do not mutate it: an in-place change does not notify the components inside.\n *\n * `test-navigation.qtiContext` is an alias of this.\n */\n @state()\n @provide({ context: qtiContext })\n public qtiContext: QtiContext = {\n QTI_CONTEXT: {\n testIdentifier: '',\n candidateIdentifier: '',\n environmentIdentifier: 'default'\n }\n };\n\n /**\n * Renders the component's template.\n * Provides a default `<slot>` for content projection.\n */\n override async connectedCallback(): Promise<void> {\n super.connectedCallback();\n await this.updateComplete;\n this.dispatchEvent(new CustomEvent('qti-test-connected', { detail: this }));\n }\n\n override render() {\n return html`<slot></slot>`;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'qti-test': QtiTest;\n }\n}\n"]}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
export declare const form: import("lit").CSSResult;
|
|
2
2
|
export declare const btn: import("lit").CSSResult;
|
|
3
|
+
/** Hover and keyboard focus; paint only, so the box never moves. */
|
|
4
|
+
export declare const btnInteractive: import("lit").CSSResult;
|
|
5
|
+
export declare const focusRing: import("lit").CSSResult;
|
|
3
6
|
export declare const dis: import("lit").CSSResult;
|
|
4
7
|
export declare const ind: import("lit").CSSResult;
|
|
@@ -1,20 +1,45 @@
|
|
|
1
1
|
// /* eslint-disable lit-plugin(no-invalid-css) */
|
|
2
2
|
import { css } from 'lit';
|
|
3
|
+
/*
|
|
4
|
+
* The resting look of the test controls (next, prev, item/section links, TTS buttons).
|
|
5
|
+
*
|
|
6
|
+
* Paint reads the qti-theme tokens, so a theme or brand that re-values them repaints the test
|
|
7
|
+
* chrome along with the items; every token has a literal fallback equal to the theme's own
|
|
8
|
+
* default, so the controls look the same without qti-theme loaded. A `--test-button-*` slot
|
|
9
|
+
* in front of each token repaints the test controls alone.
|
|
10
|
+
*/
|
|
3
11
|
export const form = css `
|
|
4
12
|
display: inline-flex;
|
|
5
13
|
align-items: center;
|
|
14
|
+
justify-content: center;
|
|
15
|
+
gap: 0.375em;
|
|
16
|
+
box-sizing: border-box;
|
|
17
|
+
min-block-size: var(--test-button-size, 2.25rem);
|
|
18
|
+
padding: 0 0.875rem;
|
|
19
|
+
font: inherit;
|
|
20
|
+
line-height: 1.25;
|
|
6
21
|
cursor: pointer;
|
|
7
|
-
padding: 0.5rem 1rem;
|
|
8
|
-
border-radius: 0.25rem;
|
|
9
22
|
user-select: none;
|
|
23
|
+
border-radius: var(--test-button-border-radius, var(--qti-component-border-radius, 0.2rem));
|
|
10
24
|
`;
|
|
11
25
|
export const btn = css `
|
|
12
|
-
background-color: lightgray;
|
|
13
26
|
${form};
|
|
27
|
+
background-color: var(--test-button-background-color, var(--qti-component-background-color, #fff));
|
|
28
|
+
color: var(--test-button-color, var(--qti-component-color, inherit));
|
|
29
|
+
border: var(--qti-component-border-width, 1px) var(--qti-component-border-style, solid)
|
|
30
|
+
var(--test-button-border-color, var(--qti-component-border-color, #0175aa));
|
|
31
|
+
`;
|
|
32
|
+
/** Hover and keyboard focus; paint only, so the box never moves. */
|
|
33
|
+
export const btnInteractive = css `
|
|
34
|
+
background-color: var(--test-button-hover-background-color, var(--qti-bg-active, #f2f8fb));
|
|
35
|
+
`;
|
|
36
|
+
export const focusRing = css `
|
|
37
|
+
outline: var(--qti-focus-border-width, 2px) solid var(--qti-focus-color, #007ac3);
|
|
38
|
+
outline-offset: 2px;
|
|
14
39
|
`;
|
|
15
40
|
export const dis = css `
|
|
16
41
|
cursor: not-allowed;
|
|
17
|
-
opacity: 0.
|
|
42
|
+
opacity: 0.45;
|
|
18
43
|
`;
|
|
19
44
|
export const ind = css `
|
|
20
45
|
${form};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"styles.js","sourceRoot":"","sources":["../../src/components/styles.ts"],"names":[],"mappings":"AAAA,kDAAkD;AAClD,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAE1B,MAAM,CAAC,MAAM,IAAI,GAAG,GAAG,CAAA
|
|
1
|
+
{"version":3,"file":"styles.js","sourceRoot":"","sources":["../../src/components/styles.ts"],"names":[],"mappings":"AAAA,kDAAkD;AAClD,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAE1B;;;;;;;GAOG;AAEH,MAAM,CAAC,MAAM,IAAI,GAAG,GAAG,CAAA;;;;;;;;;;;;;CAatB,CAAC;AAEF,MAAM,CAAC,MAAM,GAAG,GAAG,GAAG,CAAA;IAClB,IAAI;;;;;CAKP,CAAC;AAEF,oEAAoE;AACpE,MAAM,CAAC,MAAM,cAAc,GAAG,GAAG,CAAA;;CAEhC,CAAC;AAEF,MAAM,CAAC,MAAM,SAAS,GAAG,GAAG,CAAA;;;CAG3B,CAAC;AAEF,MAAM,CAAC,MAAM,GAAG,GAAG,GAAG,CAAA;;;CAGrB,CAAC;AAEF,MAAM,CAAC,MAAM,GAAG,GAAG,GAAG,CAAA;IAClB,IAAI;;CAEP,CAAC","sourcesContent":["// /* eslint-disable lit-plugin(no-invalid-css) */\nimport { css } from 'lit';\n\n/*\n * The resting look of the test controls (next, prev, item/section links, TTS buttons).\n *\n * Paint reads the qti-theme tokens, so a theme or brand that re-values them repaints the test\n * chrome along with the items; every token has a literal fallback equal to the theme's own\n * default, so the controls look the same without qti-theme loaded. A `--test-button-*` slot\n * in front of each token repaints the test controls alone.\n */\n\nexport const form = css`\n display: inline-flex;\n align-items: center;\n justify-content: center;\n gap: 0.375em;\n box-sizing: border-box;\n min-block-size: var(--test-button-size, 2.25rem);\n padding: 0 0.875rem;\n font: inherit;\n line-height: 1.25;\n cursor: pointer;\n user-select: none;\n border-radius: var(--test-button-border-radius, var(--qti-component-border-radius, 0.2rem));\n`;\n\nexport const btn = css`\n ${form};\n background-color: var(--test-button-background-color, var(--qti-component-background-color, #fff));\n color: var(--test-button-color, var(--qti-component-color, inherit));\n border: var(--qti-component-border-width, 1px) var(--qti-component-border-style, solid)\n var(--test-button-border-color, var(--qti-component-border-color, #0175aa));\n`;\n\n/** Hover and keyboard focus; paint only, so the box never moves. */\nexport const btnInteractive = css`\n background-color: var(--test-button-hover-background-color, var(--qti-bg-active, #f2f8fb));\n`;\n\nexport const focusRing = css`\n outline: var(--qti-focus-border-width, 2px) solid var(--qti-focus-color, #007ac3);\n outline-offset: 2px;\n`;\n\nexport const dis = css`\n cursor: not-allowed;\n opacity: 0.45;\n`;\n\nexport const ind = css`\n ${form};\n border: 1px solid gray;\n`;\n"]}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { LitElement } from 'lit';
|
|
2
|
+
import type { TestHost } from '../../internal/test-host.context';
|
|
2
3
|
export declare class TestCheckItem extends LitElement {
|
|
4
|
+
protected testHost?: TestHost;
|
|
3
5
|
static styles: import("lit").CSSResult;
|
|
4
6
|
constructor();
|
|
5
7
|
render(): import("lit").TemplateResult<1>;
|
|
@@ -1,10 +1,24 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { consume } from '@lit/context';
|
|
1
8
|
import { css, html, LitElement } from 'lit';
|
|
9
|
+
import { testHostContext } from '../../internal/test-host.context';
|
|
2
10
|
import * as styles from '../styles';
|
|
3
11
|
export class TestCheckItem extends LitElement {
|
|
4
12
|
static { this.styles = css `
|
|
5
13
|
:host {
|
|
6
14
|
${styles.btn};
|
|
7
15
|
}
|
|
16
|
+
:host(:hover:not([disabled])) {
|
|
17
|
+
${styles.btnInteractive};
|
|
18
|
+
}
|
|
19
|
+
:host(:focus-visible) {
|
|
20
|
+
${styles.focusRing};
|
|
21
|
+
}
|
|
8
22
|
:host([disabled]) {
|
|
9
23
|
${styles.dis};
|
|
10
24
|
}
|
|
@@ -13,8 +27,9 @@ export class TestCheckItem extends LitElement {
|
|
|
13
27
|
super();
|
|
14
28
|
this.addEventListener('click', () => {
|
|
15
29
|
this.dispatchEvent(new CustomEvent('test-end-attempt', { bubbles: true }));
|
|
16
|
-
const
|
|
17
|
-
|
|
30
|
+
const testContainer = this.testHost?.querySelector('test-container');
|
|
31
|
+
if (!testContainer)
|
|
32
|
+
return;
|
|
18
33
|
const viewElements = Array.from(testContainer.shadowRoot.querySelectorAll('[view]'));
|
|
19
34
|
viewElements.forEach((element) => {
|
|
20
35
|
element.classList.toggle('show', true);
|
|
@@ -25,4 +40,7 @@ export class TestCheckItem extends LitElement {
|
|
|
25
40
|
return html ` <slot></slot> `;
|
|
26
41
|
}
|
|
27
42
|
}
|
|
43
|
+
__decorate([
|
|
44
|
+
consume({ context: testHostContext, subscribe: true })
|
|
45
|
+
], TestCheckItem.prototype, "testHost", void 0);
|
|
28
46
|
//# sourceMappingURL=test-check-item.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"test-check-item.js","sourceRoot":"","sources":["../../../src/components/test-check-item/test-check-item.ts"],"names":[],"mappings":"AAAA,OAAO,EAA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AC,CAAC,CAAC;IACL,CAAC;IAEQ,MAAM;QACb,OAAO,IAAI,CAAA,iBAAiB,CAAC;IAC/B,CAAC;;AAlCS;IADT,OAAO,CAAC,EAAE,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;+CACzB","sourcesContent":["import { consume } from '@lit/context';\nimport { css, html, LitElement } from 'lit';\n\nimport { testHostContext } from '../../internal/test-host.context';\nimport * as styles from '../styles';\n\nimport type { TestHost } from '../../internal/test-host.context';\nimport type { TestContainer } from '../test-container/test-container';\n\nexport class TestCheckItem extends LitElement {\n @consume({ context: testHostContext, subscribe: true })\n protected testHost?: TestHost;\n\n static override styles = css`\n :host {\n ${styles.btn};\n }\n :host(:hover:not([disabled])) {\n ${styles.btnInteractive};\n }\n :host(:focus-visible) {\n ${styles.focusRing};\n }\n :host([disabled]) {\n ${styles.dis};\n }\n `;\n\n constructor() {\n super();\n this.addEventListener('click', () => {\n this.dispatchEvent(new CustomEvent('test-end-attempt', { bubbles: true }));\n const testContainer = this.testHost?.querySelector<TestContainer>('test-container');\n if (!testContainer) return;\n\n const viewElements = Array.from(testContainer.shadowRoot.querySelectorAll('[view]'));\n\n viewElements.forEach((element: HTMLElement) => {\n element.classList.toggle('show', true);\n });\n });\n }\n\n override render() {\n return html` <slot></slot> `;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'test-check-item': TestCheckItem;\n }\n}\n"]}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { LitElement } from 'lit';
|
|
2
2
|
import type { QtiContext } from '@qti-components/base';
|
|
3
|
+
import type { TestHost } from '../../internal/test-host.context';
|
|
3
4
|
/**
|
|
4
5
|
* `<test-container>` is a custom element designed for hosting the qti-assessment-item.
|
|
5
6
|
* The `qti-assessment-test` will be placed inside the shadow DOM of this element.
|
|
@@ -23,6 +24,8 @@ export declare class TestContainer extends LitElement {
|
|
|
23
24
|
testDoc: DocumentFragment | null;
|
|
24
25
|
/** The raw XML string */
|
|
25
26
|
testXML: string | null;
|
|
27
|
+
/** The `qti-test` this container is in: where the host's `postLoadTestTransformCallback` lives. */
|
|
28
|
+
protected testHost?: TestHost;
|
|
26
29
|
protected qtiContext: QtiContext;
|
|
27
30
|
protected createRenderRoot(): HTMLElement | DocumentFragment;
|
|
28
31
|
/** Callback function to transform the test after loading */
|
|
@@ -12,6 +12,7 @@ import { qtiContext } from '@qti-components/base';
|
|
|
12
12
|
import { watch } from '@qti-components/utilities';
|
|
13
13
|
import { qtiTransformTest } from '@qti-components/transformers';
|
|
14
14
|
import itemCss from '@qti-components/theme/item-css';
|
|
15
|
+
import { testHostContext } from '../../internal/test-host.context';
|
|
15
16
|
/**
|
|
16
17
|
* `<test-container>` is a custom element designed for hosting the qti-assessment-item.
|
|
17
18
|
* The `qti-assessment-test` will be placed inside the shadow DOM of this element.
|
|
@@ -64,7 +65,7 @@ export class TestContainer extends LitElement {
|
|
|
64
65
|
const explicitSeed = this.qtiContext?.QTI_CONTEXT?.seed;
|
|
65
66
|
let api = (await qtiTransformTest().load(this.testURL)).shuffleOrdering(explicitSeed);
|
|
66
67
|
// Apply external transformation if provided
|
|
67
|
-
const qtiTest = this.
|
|
68
|
+
const qtiTest = this.testHost;
|
|
68
69
|
if (qtiTest?.postLoadTestTransformCallback) {
|
|
69
70
|
// Create a temporary document to get the test element reference
|
|
70
71
|
const tempDoc = api.htmlDoc(this.#resolvedCustomElementRegistry ?? undefined);
|
|
@@ -151,6 +152,9 @@ __decorate([
|
|
|
151
152
|
__decorate([
|
|
152
153
|
state()
|
|
153
154
|
], TestContainer.prototype, "testXML", void 0);
|
|
155
|
+
__decorate([
|
|
156
|
+
consume({ context: testHostContext, subscribe: true })
|
|
157
|
+
], TestContainer.prototype, "testHost", void 0);
|
|
154
158
|
__decorate([
|
|
155
159
|
state(),
|
|
156
160
|
consume({ context: qtiContext, subscribe: true })
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"test-container.js","sourceRoot":"","sources":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,MAAM,KAAK,GAAG,IAAI,aAAa,EAAE,CAAC;QAClC,KAAK,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;QAC3B,IAAI,CAAC,UAAU,CAAC,kBAAkB,GAAG,CAAC,KAAK,CAAC,CAAC;IAC/C,CAAC;IAEQ,MAAM;QACb,OAAO,IAAI,CAAA;QACP,IAAI,CAAC,gBAAgB;;QAErB,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAA,yBAAyB,CAAC;KACrD,CAAC;IACJ,CAAC;CACF;AApIC;IADC,QAAQ,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;4DAC4B;AAI3D;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,CAAC;8CACpB;AAI9B;IADC,KAAK,EAAE;8CACgC;AAIxC;IADC,KAAK,EAAE;8CACsB;AAIpB;IAFT,KAAK,EAAE;IACP,OAAO,CAAC,EAAE,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;iDAGhD;AAwBc;IADf,KAAK,CAAC,SAAS,EAAE,EAAE,oBAAoB,EAAE,IAAI,EAAE,CAAC;wDAuBhD;AAuBS;IADT,KAAK,CAAC,SAAS,EAAE,EAAE,oBAAoB,EAAE,IAAI,EAAE,CAAC;wDAchD","sourcesContent":["import { consume } from '@lit/context';\nimport { LitElement, html } from 'lit';\nimport { property, state } from 'lit/decorators.js';\nimport { until } from 'lit/directives/until.js';\n\nimport { qtiContext } from '@qti-components/base';\nimport { watch } from '@qti-components/utilities';\nimport { qtiTransformTest } from '@qti-components/transformers';\nimport itemCss from '@qti-components/theme/item-css';\n\nimport type { QtiContext } from '@qti-components/base';\n\n/**\n * `<test-container>` is a custom element designed for hosting the qti-assessment-item.\n * The `qti-assessment-test` will be placed inside the shadow DOM of this element.\n * The element loads the test from the provided URL and renders it inside the shadow DOM.\n *\n * ```html\n * <qti-test>\n * <test-navigation>\n * <test-container class=\"m-4 bg-white\" test-url=\"./path/to/assessmenttest.xml\"></test-container>\n * </test-navigation>\n * </qti-test>\n * ```\n */\n\nexport class TestContainer extends LitElement {\n /** Scoped registry used by the test shadow root. Must be set before connection. */\n @property({ attribute: false })\n customElementRegistry: CustomElementRegistry | null = null;\n\n /** URL of the item to load */\n @property({ type: String, attribute: 'test-url' })\n testURL: string | null = null;\n\n /** A parsed HTML document */\n @state()\n testDoc: DocumentFragment | null = null;\n\n /** The raw XML string */\n @state()\n testXML: string | null = null;\n\n @state()\n @consume({ context: qtiContext, subscribe: true })\n protected qtiContext: QtiContext = {\n QTI_CONTEXT: { testIdentifier: '', candidateIdentifier: '', environmentIdentifier: 'default' }\n };\n\n /** Template content if provided */\n #templateContent: unknown = null;\n #resolvedCustomElementRegistry: CustomElementRegistry | null = null;\n\n protected override createRenderRoot(): HTMLElement | DocumentFragment {\n const registry = this.customElementRegistry;\n\n this.#resolvedCustomElementRegistry = registry;\n\n return (\n this.shadowRoot ??\n this.attachShadow({\n ...(this.constructor as typeof TestContainer).shadowRootOptions,\n ...(registry ? { customElementRegistry: registry } : {})\n })\n );\n }\n\n /** Callback function to transform the test after loading */\n // @property({ type: Function }) postLoadTestTransformCallback: PostLoadTestTransformCallback | null = null;\n\n @watch('testURL', { waitUntilFirstUpdate: true })\n protected async handleTestURLChange() {\n if (!this.testURL) return;\n try {\n const explicitSeed = this.qtiContext?.QTI_CONTEXT?.seed;\n let api = (await qtiTransformTest().load(this.testURL)).shuffleOrdering(explicitSeed);\n // Apply external transformation if provided\n const qtiTest = this.closest('qti-test') as any; // Type assertion to access mixin properties\n if (qtiTest?.postLoadTestTransformCallback) {\n // Create a temporary document to get the test element reference\n const tempDoc = api.htmlDoc(this.#resolvedCustomElementRegistry ?? undefined);\n const testElement = tempDoc.querySelector('qti-assessment-test') as any;\n\n if (testElement) {\n // Apply the callback with the test element\n api = await qtiTest.postLoadTestTransformCallback(api, testElement);\n }\n }\n\n this.#setTestDoc(api.htmlDoc(this.#resolvedCustomElementRegistry ?? undefined));\n } catch (error) {\n console.error('Error loading or parsing XML:', error);\n }\n }\n\n /**\n * Assign a new test document and announce it.\n *\n * The announcement has to happen here rather than on\n * `qti-assessment-test-connected`, because by then the new document's\n * children have already connected and registered themselves — a host that\n * resets its context on that event throws those registrations away. Lit's\n * re-render is async, so a handler running now still gets in before any child\n * of the new `qti-assessment-test` connects.\n */\n #setTestDoc(testDoc: DocumentFragment): void {\n this.testDoc = testDoc;\n this.dispatchEvent(\n new CustomEvent('qti-testdoc-loaded', {\n bubbles: true,\n composed: true\n })\n );\n }\n\n @watch('testXML', { waitUntilFirstUpdate: true })\n protected handleTestXMLChange() {\n if (!this.testXML) return;\n try {\n const explicitSeed = this.qtiContext?.QTI_CONTEXT?.seed;\n this.#setTestDoc(\n qtiTransformTest()\n .parse(this.testXML)\n .shuffleOrdering(explicitSeed)\n .htmlDoc(this.#resolvedCustomElementRegistry ?? undefined)\n );\n } catch (error) {\n console.error('Error parsing XML:', error);\n }\n }\n\n override async connectedCallback(): Promise<void> {\n super.connectedCallback();\n this.#initializeTemplateContent();\n this.#applyStyles();\n if (this.testURL) {\n this.handleTestURLChange();\n }\n if (this.testXML) {\n this.handleTestXMLChange();\n }\n }\n\n #initializeTemplateContent() {\n const template = this.querySelector('template') as HTMLTemplateElement;\n this.#templateContent = template ? template.content : html``;\n }\n\n #applyStyles() {\n const sheet = new CSSStyleSheet();\n sheet.replaceSync(itemCss);\n this.shadowRoot.adoptedStyleSheets = [sheet];\n }\n\n override render() {\n return html`\n ${this.#templateContent}\n <slot></slot>\n ${until(this.testDoc, html`<span>Loading...</span>`)}\n `;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'test-container': TestContainer;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"test-container.js","sourceRoot":"","sources":["../../../src/components/test-container/test-container.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAA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C,CAAC;QAC3B,IAAI,CAAC,UAAU,CAAC,kBAAkB,GAAG,CAAC,KAAK,CAAC,CAAC;IAC/C,CAAC;IAEQ,MAAM;QACb,OAAO,IAAI,CAAA;QACP,IAAI,CAAC,gBAAgB;;QAErB,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAA,yBAAyB,CAAC;KACrD,CAAC;IACJ,CAAC;CACF;AAxIC;IADC,QAAQ,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;4DAC4B;AAI3D;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,CAAC;8CACpB;AAI9B;IADC,KAAK,EAAE;8CACgC;AAIxC;IADC,KAAK,EAAE;8CACsB;AAIpB;IADT,OAAO,CAAC,EAAE,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;+CACzB;AAIpB;IAFT,KAAK,EAAE;IACP,OAAO,CAAC,EAAE,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;iDAGhD;AAwBc;IADf,KAAK,CAAC,SAAS,EAAE,EAAE,oBAAoB,EAAE,IAAI,EAAE,CAAC;wDAuBhD;AAuBS;IADT,KAAK,CAAC,SAAS,EAAE,EAAE,oBAAoB,EAAE,IAAI,EAAE,CAAC;wDAchD","sourcesContent":["import { consume } from '@lit/context';\nimport { LitElement, html } from 'lit';\nimport { property, state } from 'lit/decorators.js';\nimport { until } from 'lit/directives/until.js';\n\nimport { qtiContext } from '@qti-components/base';\nimport { watch } from '@qti-components/utilities';\nimport { qtiTransformTest } from '@qti-components/transformers';\nimport itemCss from '@qti-components/theme/item-css';\n\nimport { testHostContext } from '../../internal/test-host.context';\n\nimport type { QtiContext } from '@qti-components/base';\nimport type { TestHost } from '../../internal/test-host.context';\n\n/**\n * `<test-container>` is a custom element designed for hosting the qti-assessment-item.\n * The `qti-assessment-test` will be placed inside the shadow DOM of this element.\n * The element loads the test from the provided URL and renders it inside the shadow DOM.\n *\n * ```html\n * <qti-test>\n * <test-navigation>\n * <test-container class=\"m-4 bg-white\" test-url=\"./path/to/assessmenttest.xml\"></test-container>\n * </test-navigation>\n * </qti-test>\n * ```\n */\n\nexport class TestContainer extends LitElement {\n /** Scoped registry used by the test shadow root. Must be set before connection. */\n @property({ attribute: false })\n customElementRegistry: CustomElementRegistry | null = null;\n\n /** URL of the item to load */\n @property({ type: String, attribute: 'test-url' })\n testURL: string | null = null;\n\n /** A parsed HTML document */\n @state()\n testDoc: DocumentFragment | null = null;\n\n /** The raw XML string */\n @state()\n testXML: string | null = null;\n\n /** The `qti-test` this container is in: where the host's `postLoadTestTransformCallback` lives. */\n @consume({ context: testHostContext, subscribe: true })\n protected testHost?: TestHost;\n\n @state()\n @consume({ context: qtiContext, subscribe: true })\n protected qtiContext: QtiContext = {\n QTI_CONTEXT: { testIdentifier: '', candidateIdentifier: '', environmentIdentifier: 'default' }\n };\n\n /** Template content if provided */\n #templateContent: unknown = null;\n #resolvedCustomElementRegistry: CustomElementRegistry | null = null;\n\n protected override createRenderRoot(): HTMLElement | DocumentFragment {\n const registry = this.customElementRegistry;\n\n this.#resolvedCustomElementRegistry = registry;\n\n return (\n this.shadowRoot ??\n this.attachShadow({\n ...(this.constructor as typeof TestContainer).shadowRootOptions,\n ...(registry ? { customElementRegistry: registry } : {})\n })\n );\n }\n\n /** Callback function to transform the test after loading */\n // @property({ type: Function }) postLoadTestTransformCallback: PostLoadTestTransformCallback | null = null;\n\n @watch('testURL', { waitUntilFirstUpdate: true })\n protected async handleTestURLChange() {\n if (!this.testURL) return;\n try {\n const explicitSeed = this.qtiContext?.QTI_CONTEXT?.seed;\n let api = (await qtiTransformTest().load(this.testURL)).shuffleOrdering(explicitSeed);\n // Apply external transformation if provided\n const qtiTest = this.testHost;\n if (qtiTest?.postLoadTestTransformCallback) {\n // Create a temporary document to get the test element reference\n const tempDoc = api.htmlDoc(this.#resolvedCustomElementRegistry ?? undefined);\n const testElement = tempDoc.querySelector('qti-assessment-test') as any;\n\n if (testElement) {\n // Apply the callback with the test element\n api = await qtiTest.postLoadTestTransformCallback(api, testElement);\n }\n }\n\n this.#setTestDoc(api.htmlDoc(this.#resolvedCustomElementRegistry ?? undefined));\n } catch (error) {\n console.error('Error loading or parsing XML:', error);\n }\n }\n\n /**\n * Assign a new test document and announce it.\n *\n * The announcement has to happen here rather than on\n * `qti-assessment-test-connected`, because by then the new document's\n * children have already connected and registered themselves — a host that\n * resets its context on that event throws those registrations away. Lit's\n * re-render is async, so a handler running now still gets in before any child\n * of the new `qti-assessment-test` connects.\n */\n #setTestDoc(testDoc: DocumentFragment): void {\n this.testDoc = testDoc;\n this.dispatchEvent(\n new CustomEvent('qti-testdoc-loaded', {\n bubbles: true,\n composed: true\n })\n );\n }\n\n @watch('testXML', { waitUntilFirstUpdate: true })\n protected handleTestXMLChange() {\n if (!this.testXML) return;\n try {\n const explicitSeed = this.qtiContext?.QTI_CONTEXT?.seed;\n this.#setTestDoc(\n qtiTransformTest()\n .parse(this.testXML)\n .shuffleOrdering(explicitSeed)\n .htmlDoc(this.#resolvedCustomElementRegistry ?? undefined)\n );\n } catch (error) {\n console.error('Error parsing XML:', error);\n }\n }\n\n override async connectedCallback(): Promise<void> {\n super.connectedCallback();\n this.#initializeTemplateContent();\n this.#applyStyles();\n if (this.testURL) {\n this.handleTestURLChange();\n }\n if (this.testXML) {\n this.handleTestXMLChange();\n }\n }\n\n #initializeTemplateContent() {\n const template = this.querySelector('template') as HTMLTemplateElement;\n this.#templateContent = template ? template.content : html``;\n }\n\n #applyStyles() {\n const sheet = new CSSStyleSheet();\n sheet.replaceSync(itemCss);\n this.shadowRoot.adoptedStyleSheets = [sheet];\n }\n\n override render() {\n return html`\n ${this.#templateContent}\n <slot></slot>\n ${until(this.testDoc, html`<span>Loading...</span>`)}\n `;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'test-container': TestContainer;\n }\n}\n"]}
|
|
@@ -20,6 +20,12 @@ export class TestEndAttempt extends LitElement {
|
|
|
20
20
|
:host {
|
|
21
21
|
${styles.btn};
|
|
22
22
|
}
|
|
23
|
+
:host(:hover:not([disabled])) {
|
|
24
|
+
${styles.btnInteractive};
|
|
25
|
+
}
|
|
26
|
+
:host(:focus-visible) {
|
|
27
|
+
${styles.focusRing};
|
|
28
|
+
}
|
|
23
29
|
:host([disabled]) {
|
|
24
30
|
${styles.dis};
|
|
25
31
|
}
|