@citolab/qti-components 6.0.2 → 6.0.3-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.
@@ -1,8 +1,8 @@
1
1
  import * as lit_html from 'lit-html';
2
2
  import * as lit from 'lit';
3
3
  import { LitElement } from 'lit';
4
- import { I as InputResponseFormat, Q as QtiVariableJSON } from '../ExpressionResult-2192c3d8.js';
5
- import { a as QtiAssessmentItem } from '../qti-assessment-item-e9f437d6.js';
4
+ import { R as ResponseInteraction } from '../ExpressionResult-b1ac7b27.js';
5
+ import { Q as QtiAssessmentItem } from '../qti-assessment-item-219cef9e.js';
6
6
 
7
7
  declare class ScaleToFitInterface {
8
8
  }
@@ -13,14 +13,21 @@ declare class QtiItem extends QtiItem_base {
13
13
  handleDisabledChange(old: any, disabled: boolean): void;
14
14
  readonly: boolean;
15
15
  handleReadonlyChange(old: any, readonly: boolean): void;
16
- responses: InputResponseFormat<QtiVariableJSON>;
17
- handleResponsesChange(old: any, responses: InputResponseFormat<QtiVariableJSON>): void;
18
- _item: QtiAssessmentItem;
16
+ responses: ResponseInteraction[];
17
+ handleResponsesChange(old: any, responses: ResponseInteraction[]): void;
18
+ set qtiContext(context: {
19
+ view: 'author' | 'candidate' | 'proctor' | 'scorer' | 'testConstructor' | 'tutor';
20
+ });
21
+ private provider;
22
+ private _xml;
23
+ get _item(): QtiAssessmentItem;
24
+ set xml(val: string);
25
+ get xml(): string;
19
26
  static styles: lit.CSSResult;
20
27
  processResponse: () => boolean;
21
28
  validateResponses: () => boolean;
22
29
  resetInteractions: () => void;
23
- private handleSlotchange;
30
+ connectedCallback(): void;
24
31
  render: () => lit_html.TemplateResult<1>;
25
32
  }
26
33
 
@@ -1,17 +1 @@
1
- import{a as l}from"../chunk-JQY6IKDF.js";import{c as a}from"../chunk-NMCIOGD2.js";import{css as m,html as u,LitElement as f}from"lit";var h=(p,d)=>{class e extends p{constructor(){super(...arguments);this.scale=1;this.ro=new ResizeObserver(t=>{for(let r of t)this.fitToParent(r.contentRect.width)})}connectedCallback(){super.connectedCallback(),this.ro.observe(this),this.fitToParent()}static get properties(){return{scales:{type:Boolean,reflect:!0}}}updated(t){t.forEach((r,n)=>{switch(n){case"scales":this.scales&&this.fitToParent();break}})}fitToParent(t=this.clientWidth){let r=this.querySelector(d);if(r){let n=t/r.clientWidth;this.scale=n,this.marginY=-r.clientHeight*(1-n)+"px",requestAnimationFrame(()=>{r.style.transform=`scale(${this.scale})`,r.style.margin=`0 0 ${this.marginY} 0`})}}}return e};import{property as c,state as b}from"lit/decorators.js";var s=class extends h(f,"qti-assessment-item"){constructor(){super(...arguments);this.disabled=!1;this.readonly=!1;this.processResponse=()=>{var e;return(e=this._item)==null?void 0:e.processResponse()};this.validateResponses=()=>this._item?this._item.validateResponses():!1;this.resetInteractions=()=>{var e;return(e=this._item)==null?void 0:e.resetInteractions()};this.render=()=>u`<slot @slotchange=${this.handleSlotchange}></slot>`}handleDisabledChange(e,i){var o,t;i&&((o=this._item)==null||o.setAttribute("disabled","")),!i&&((t=this._item)==null||t.removeAttribute("disabled"))}handleReadonlyChange(e,i){var o,t;i&&((o=this._item)==null||o.setAttribute("readonly","")),!i&&((t=this._item)==null||t.removeAttribute("readonly"))}handleResponsesChange(e,i){this._item&&(this._item.responses=i)}handleSlotchange(e){let i=e.target.assignedNodes({flatten:!0});this._item=null,i.forEach(o=>{o.nodeName=="QTI-ASSESSMENT-ITEM"&&(this._item=o,this.disabled&&this._item.setAttribute("disabled",""),this.readonly&&this._item.setAttribute("readonly",""),this.responses&&(this._item.responses=this.responses))})}};s.styles=m`
2
- :host {
3
- display: block; /* necessary to calculate scaling position */
4
- width: 100%;
5
- height: 100%;
6
- overflow: auto;
7
- }
8
- ::slotted(qti-assessment-item) {
9
- display: block; /* necessary to calculate scaling position */
10
- width: 100%;
11
- }
12
- :host([scales]) ::slotted(qti-assessment-item) {
13
- aspect-ratio: 4 / 3;
14
- width: 1024px;
15
- transform-origin: 0 0;
16
- }
17
- `,a([c({type:Boolean,reflect:!0})],s.prototype,"disabled",2),a([l("disabled",{waitUntilFirstUpdate:!0})],s.prototype,"handleDisabledChange",1),a([c({type:Boolean,reflect:!0})],s.prototype,"readonly",2),a([l("readonly",{waitUntilFirstUpdate:!0})],s.prototype,"handleReadonlyChange",1),a([c({type:Object,reflect:!0})],s.prototype,"responses",2),a([l("responses",{waitUntilFirstUpdate:!0})],s.prototype,"handleResponsesChange",1),a([b()],s.prototype,"_item",2);customElements.define("qti-item",s);export{s as QtiItem};
1
+ import{a as o}from"../chunk-M3YT56HW.js";import"../chunk-DLLHO3W2.js";import"../chunk-NMCIOGD2.js";export{o as QtiItem};
@@ -0,0 +1,19 @@
1
+ import React from 'react';
2
+ import { R as ResponseInteraction } from '../ExpressionResult-b1ac7b27.js';
3
+ import { O as OutcomeChangedDetails, b as InteractionChangedDetails } from '../qti-rule-5fe4f91e.js';
4
+ import '../qti-assessment-item-219cef9e.js';
5
+ import 'lit-html';
6
+ import 'lit';
7
+
8
+ interface QtiItemProps {
9
+ ref?: any;
10
+ className?: string;
11
+ scales?: boolean;
12
+ responses?: ResponseInteraction[];
13
+ xml: string;
14
+ qtioutcomechanged?: (e: CustomEvent<OutcomeChangedDetails>) => void;
15
+ qtiinteractionchanged?: (e: CustomEvent<InteractionChangedDetails>) => void;
16
+ }
17
+ declare const QtiItem: React.ForwardRefExoticComponent<QtiItemProps>;
18
+
19
+ export { QtiItem };
@@ -0,0 +1 @@
1
+ import{a as t}from"../chunk-M3YT56HW.js";import"../chunk-DLLHO3W2.js";import"../chunk-NMCIOGD2.js";import e from"react";import{createComponent as o}from"@lit-labs/react";var m=o({tagName:"qti-item",react:e,elementClass:t,events:{qtioutcomechanged:"qti-outcome-changed",qtiinteractionchanged:"qti-interaction-changed"}});export{m as QtiItem};
@@ -0,0 +1,303 @@
1
+ import { R as ResponseInteraction } from './ExpressionResult-b1ac7b27.js';
2
+ import { V as VariableDeclaration } from './qti-assessment-item-219cef9e.js';
3
+ import * as lit_html from 'lit-html';
4
+ import { LitElement, CSSResultGroup } from 'lit';
5
+
6
+ interface OutcomeChangedDetails {
7
+ item: string;
8
+ outcomeIdentifier: string;
9
+ value: number;
10
+ }
11
+ type InteractionChangedDetails = ResponseInteraction & {
12
+ item: string;
13
+ };
14
+
15
+ type QtiOutcomeChanged = CustomEvent<OutcomeChangedDetails>;
16
+ declare global {
17
+ interface GlobalEventHandlersEventMap {
18
+ 'qti-outcome-changed': QtiOutcomeChanged;
19
+ }
20
+ }
21
+
22
+ type qtiOutcomeChanged_QtiOutcomeChanged = QtiOutcomeChanged;
23
+ declare namespace qtiOutcomeChanged {
24
+ export {
25
+ qtiOutcomeChanged_QtiOutcomeChanged as QtiOutcomeChanged,
26
+ QtiOutcomeChanged as default,
27
+ };
28
+ }
29
+
30
+ type QtiInteractionChanged = CustomEvent<InteractionChangedDetails>;
31
+ declare global {
32
+ interface GlobalEventHandlersEventMap {
33
+ "qti-interaction-changed": QtiInteractionChanged;
34
+ }
35
+ }
36
+
37
+ type qtiInteractionChanged_QtiInteractionChanged = QtiInteractionChanged;
38
+ declare namespace qtiInteractionChanged {
39
+ export {
40
+ qtiInteractionChanged_QtiInteractionChanged as QtiInteractionChanged,
41
+ QtiInteractionChanged as default,
42
+ };
43
+ }
44
+
45
+ type QtiRegisterVariable = CustomEvent<{
46
+ variable: VariableDeclaration<number | string | string[]>;
47
+ }>;
48
+ declare global {
49
+ interface GlobalEventHandlersEventMap {
50
+ "qti-register-variable": QtiRegisterVariable;
51
+ }
52
+ }
53
+
54
+ declare namespace qtiRegisterVariable {
55
+ export {
56
+ QtiRegisterVariable as default,
57
+ };
58
+ }
59
+
60
+ type QtiRegisterInteraction = CustomEvent<Record<PropertyKey, never>>;
61
+ declare global {
62
+ interface GlobalEventHandlersEventMap {
63
+ 'qti-register-interaction': QtiRegisterInteraction;
64
+ }
65
+ }
66
+
67
+ declare namespace qtiRegisterInteraction {
68
+ export {
69
+ QtiRegisterInteraction as default,
70
+ };
71
+ }
72
+
73
+ type QtiRegisterChoice = CustomEvent<Record<PropertyKey, never>>;
74
+ declare global {
75
+ interface GlobalEventHandlersEventMap {
76
+ 'qti-register-choice': QtiRegisterChoice;
77
+ }
78
+ }
79
+
80
+ declare namespace qtiRegisterChoice {
81
+ export {
82
+ QtiRegisterChoice as default,
83
+ };
84
+ }
85
+
86
+ type QtiRegisterHotspot = CustomEvent<Record<PropertyKey, never>>;
87
+ declare global {
88
+ interface GlobalEventHandlersEventMap {
89
+ 'qti-register-hotspot': QtiRegisterHotspot;
90
+ }
91
+ }
92
+
93
+ declare namespace qtiRegisterHotspot {
94
+ export {
95
+ QtiRegisterHotspot as default,
96
+ };
97
+ }
98
+
99
+ type QtiLooseChoice = CustomEvent<Record<PropertyKey, never>>;
100
+ declare global {
101
+ interface GlobalEventHandlersEventMap {
102
+ 'qti-loose-choice': QtiLooseChoice;
103
+ }
104
+ }
105
+
106
+ declare namespace qtiLooseChoice {
107
+ export {
108
+ QtiLooseChoice as default,
109
+ };
110
+ }
111
+
112
+ type QtiInteractionResponse = CustomEvent<ResponseInteraction>;
113
+ declare global {
114
+ interface GlobalEventHandlersEventMap {
115
+ 'qti-interaction-response': QtiInteractionResponse;
116
+ }
117
+ }
118
+
119
+ declare namespace qtiInteractionResponse {
120
+ export {
121
+ QtiInteractionResponse as default,
122
+ };
123
+ }
124
+
125
+ type QtiChoiceElementSelected = CustomEvent<{
126
+ identifier: string;
127
+ checked: boolean;
128
+ }>;
129
+ declare global {
130
+ interface GlobalEventHandlersEventMap {
131
+ 'qti-choice-element-selected': QtiChoiceElementSelected;
132
+ }
133
+ }
134
+
135
+ declare namespace qtiChoiceElementSelected {
136
+ export {
137
+ QtiChoiceElementSelected as default,
138
+ };
139
+ }
140
+
141
+ /**
142
+ * @summary The qti-item-body node contains the text, graphics, media objects and interactions that describe the item's content and information about how it is structured.
143
+ * @documentation https://www.imsglobal.org/spec/qti/v3p0/impl#h.sphpo6lu6zqi
144
+ * @status stable
145
+ * @since 4.0
146
+ *
147
+ * @slot - item body content.
148
+ * @slot qti-rubric-block - the qti rubric block is placed above the item
149
+ *
150
+ */
151
+ declare class QtiItemBody extends LitElement {
152
+ static styles: CSSResultGroup;
153
+ render(): lit_html.TemplateResult<1>;
154
+ }
155
+ declare global {
156
+ interface HTMLElementTagNameMap {
157
+ 'qti-item-body': QtiItemBody;
158
+ }
159
+ }
160
+
161
+ /**
162
+ * @summary qti-choice is used by qti-simple-choice, qti-inline-choice, qti-hottext, qti-hotspot-choice.
163
+ *
164
+ * @since 1.0
165
+ * @status stable
166
+ *
167
+ * @event qti-register-choice - register itselves on a qti-choice-interaction element.
168
+ * @event qti-loose-choice - de-register itselves on a qti-choice-interaction element.
169
+ * @event qti-choice-element-selected - Emitted when the choice is selected.
170
+ *
171
+ * @slot - The choices slot element
172
+ */
173
+ declare abstract class QtiChoice extends LitElement {
174
+ identifier: string;
175
+ tabindex: number | undefined;
176
+ disabled: boolean;
177
+ readonly: boolean;
178
+ checked: boolean;
179
+ handleDisabledChange(_: boolean, disabled: boolean): void;
180
+ connectedCallback(): void;
181
+ disconnectedCallback(): void;
182
+ reset(): void;
183
+ private _onKeyUp;
184
+ private _onClick;
185
+ private _toggleChecked;
186
+ validateAllProps(): boolean;
187
+ render(): lit_html.TemplateResult<1 | 2>;
188
+ }
189
+ declare global {
190
+ interface HTMLElementTagNameMap {
191
+ 'qti-choice': QtiChoice;
192
+ }
193
+ }
194
+
195
+ declare abstract class Interaction extends LitElement {
196
+ responseIdentifier: string;
197
+ /** disabled should be exposed to the attributes and accessible as property */
198
+ disabled: boolean;
199
+ /** readonly should be exposed to the attributes and accessible as property */
200
+ readonly: boolean;
201
+ abstract reset(): void;
202
+ abstract validate(): boolean;
203
+ abstract set response(val: string | string[]);
204
+ connectedCallback(): void;
205
+ saveResponse(value: string | string[]): void;
206
+ }
207
+
208
+ declare class QtiHottext extends QtiChoice {
209
+ }
210
+ declare global {
211
+ interface HTMLElementTagNameMap {
212
+ 'qti-hottext': QtiHottext;
213
+ }
214
+ }
215
+
216
+ declare abstract class Choices extends Interaction {
217
+ protected _choiceElements: QtiChoice[];
218
+ minChoices: number;
219
+ maxChoices: number;
220
+ _handleDisabledChange: (_: boolean, disabled: boolean) => void;
221
+ _handleReadonlyChange: (_: boolean, readonly: boolean) => void;
222
+ _handleMaxChoicesChange: () => void;
223
+ constructor();
224
+ reset(): void;
225
+ validate(): boolean;
226
+ set response(myResponse: ResponseType);
227
+ connectedCallback(): void;
228
+ disconnectedCallback(): void;
229
+ private _registerChoiceElement;
230
+ private _looseChoiceElement;
231
+ private _determineInputType;
232
+ private _setInputType;
233
+ private _choiceElementSelectedHandler;
234
+ private _choiceElementSelected;
235
+ }
236
+
237
+ /**
238
+ * @summary The ChoiceInteraction.Type (qti-choice-interaction) interaction presents a collection of choices to the candidate.
239
+ * @documentation https://www.imsglobal.org/spec/qti/v3p0/impl#h.j9nu1oa1tu3b
240
+ * @status stable
241
+ * @since 4.0
242
+ *
243
+ * @event qti-register-interaction - emitted when the interaction wants to register itself
244
+ * @event qti-interaction-response - emitted when the interaction changes
245
+ *
246
+ * @slot - The default slot where <qti-simple-choice> must be placed.
247
+ * @slot prompt - slot where the prompt is placed.
248
+ */
249
+ declare class QtiChoiceInteraction extends Choices {
250
+ static styles: CSSResultGroup;
251
+ /** orientation of choices */
252
+ orientation: 'horizontal' | 'vertical';
253
+ render: () => lit_html.TemplateResult<1>;
254
+ }
255
+ declare global {
256
+ interface HTMLElementTagNameMap {
257
+ 'qti-choice-interaction': QtiChoiceInteraction;
258
+ }
259
+ }
260
+
261
+ /**
262
+ * @summary Short summary of the component's intended use.
263
+ * @documentation https://www.imsglobal.org/spec/qti/v3p0/impl#h.j9nu1oa1tu3b
264
+ * @status stable
265
+ * @since 4.0
266
+ *
267
+ * @event qti-choice-element-selected - Emitted when a choice is selected.
268
+ * @event qti-register-choice - Emitted when an choice is added
269
+ * @event qti-loose-choice - Emitted when a choice is removed
270
+ *
271
+ * @slot - The default slot.
272
+ */
273
+ declare class QtiSimpleChoice extends QtiChoice {
274
+ }
275
+ declare global {
276
+ interface HTMLElementTagNameMap {
277
+ 'qti-simple-choice': QtiSimpleChoice;
278
+ }
279
+ }
280
+
281
+ declare class QtiResponseProcessing extends LitElement {
282
+ render(): lit_html.TemplateResult<1>;
283
+ static get observedAttributes(): string[];
284
+ process(): void;
285
+ private fragmentFromString;
286
+ }
287
+ declare global {
288
+ interface HTMLElementTagNameMap {
289
+ 'qti-response-processing': QtiResponseProcessing;
290
+ }
291
+ }
292
+
293
+ declare class QtiRule extends LitElement {
294
+ render(): lit_html.TemplateResult<1>;
295
+ process(): void;
296
+ }
297
+ declare global {
298
+ interface HTMLElementTagNameMap {
299
+ 'qti-rule': QtiRule;
300
+ }
301
+ }
302
+
303
+ export { Choices as C, Interaction as I, OutcomeChangedDetails as O, QtiRule as Q, QtiChoice as a, InteractionChangedDetails as b, qtiInteractionChanged as c, qtiRegisterVariable as d, qtiRegisterInteraction as e, qtiRegisterChoice as f, qtiRegisterHotspot as g, qtiLooseChoice as h, qtiInteractionResponse as i, qtiChoiceElementSelected as j, QtiHottext as k, QtiResponseProcessing as l, qtiOutcomeChanged as q };
@@ -1,6 +1,6 @@
1
1
  import * as lit_html from 'lit-html';
2
2
  import { LitElement } from 'lit';
3
- import { I as InputResponseFormat, Q as QtiVariableJSON } from '../ExpressionResult-2192c3d8.js';
3
+ import { R as ResponseInteraction } from '../ExpressionResult-b1ac7b27.js';
4
4
 
5
5
  declare const TestEvents: {
6
6
  ON_ITEM_WAS_FINISHED: string;
@@ -45,7 +45,7 @@ declare class QtiTest extends LitElement {
45
45
  });
46
46
  set itemXML(xml: string);
47
47
  set manualOutcomeValue(value: any);
48
- set itemResponse(val: InputResponseFormat<QtiVariableJSON>);
48
+ set itemResponse(val: ResponseInteraction[]);
49
49
  private provider;
50
50
  private _onCheckItem;
51
51
  private _onScoreItem;
@@ -1,12 +1,14 @@
1
- import{a as u}from"../chunk-L6436D6O.js";import{a as d}from"../chunk-JQY6IKDF.js";import{a as h,c as i}from"../chunk-NMCIOGD2.js";import{LitElement as r,html as a}from"lit";var m=(n,c)=>{class e extends n{_dispatch(){this.dispatchEvent(new CustomEvent(c,{composed:!0,bubbles:!0,detail:+this.getAttribute("index")}))}connectedCallback(){super.connectedCallback(),this.addEventListener("click",this._dispatch)}disconnectedCallback(){super.disconnectedCallback(),this.removeEventListener("click",this._dispatch)}}return e};customElements.define("qti-test-next",class extends m(r,"on-next-item"){constructor(){super(...arguments);this.render=()=>a`<slot></slot>`}});customElements.define("qti-test-item",class extends m(r,"on-request-item"){constructor(){super(...arguments);this.render=()=>a`<slot></slot>`}});customElements.define("qti-test-prev",class extends m(r,"on-prev-item"){constructor(){super(...arguments);this.render=()=>a`<slot></slot>`}});customElements.define("qti-test-check",class extends m(r,"on-check-item"){constructor(){super(...arguments);this.render=()=>a`<slot></slot>`}});customElements.define("qti-test-score",class extends m(r,"on-score-item"){constructor(){super(...arguments);this.render=()=>a`<slot></slot>`}});customElements.define("qti-test-show-correct",class extends m(r,"on-show-correct"){constructor(){super(...arguments);this.render=()=>a`<slot></slot>`}});import{html as _,LitElement as E}from"lit";import{ContextProvider as f}from"@lit-labs/context";import{customElement as I,property as l,query as p,state as R}from"lit/decorators.js";var o={ON_ITEM_WAS_FINISHED:"onItemWasFinished",ON_NO_RESPONSE_ON_SUBMIT:"onNoResponseOnSubmit",ON_REQUEST_ITEM:"onRequestItem",ON_TEST_FINISHED:"onTestFinished",ON_ITEM_READY:"onItemReady"},b=(e=>(e.linear="linear",e.nonlinear="nonlinear",e))(b||{}),x=(e=>(e.individual="individual",e.simultaneous="simultaneous",e))(x||{}),t=class extends E{constructor(){super(...arguments);this.disabled=!1;this.readonly=!1;this._navigationMode="nonlinear";this._submissionMode="simultaneous";this.items=[];this.itemIndex=0;this.provider=new f(this,u,{log:e=>{console.log(`[my-app] ${e}`)},view:"candidate"})}handleNavigationModeChange(e,s){this.prevButton.style.visibility=s==="linear"?"hidden":"visible"}handleItemIndexChange(e,s){this.emit(o.ON_REQUEST_ITEM,{detail:s})}set qtiContext(e){this.provider.value.view=e.view,this.provider.updateObservers()}set itemXML(e){this._itemRef&&this._itemRef.remove(),this.insertAdjacentHTML("afterbegin",e)}set manualOutcomeValue(e){this._itemRef.setOutcomeValue("SCORE",e)}set itemResponse(e){this._itemRef&&(this._itemRef.responses=e,this._navigationMode==="linear"&&(this._itemRef.style.filter="blur(5px)",this._itemRef.setAttribute("disabled",""),this.dispatchEvent(new CustomEvent(o.ON_ITEM_WAS_FINISHED))))}_onCheckItem(){return this._itemRef.validateResponses()?(this._itemRef.processResponse(),!0):!1}_onScoreItem(){this._onCheckItem()&&this._itemRef.processResponse()}_onPrevItem(){this.itemIndex>0&&this.emit(o.ON_REQUEST_ITEM,{detail:this.itemIndex-1})}_onNextItem(){if(this._navigationMode==="linear"&&!this._itemRef.validateResponses()){this.dispatchEvent(new CustomEvent(o.ON_NO_RESPONSE_ON_SUBMIT));return}this.itemIndex<this.items.length-1?this.emit(o.ON_REQUEST_ITEM,{detail:this.itemIndex+1}):this.dispatchEvent(new CustomEvent(o.ON_TEST_FINISHED))}_onShowCorrect(){this._itemRef.showCorrectResponse()}_onRequestItem({detail:e}){this.emit(o.ON_REQUEST_ITEM,{detail:e})}_handleSlotchange(e){let s=this.querySelector("qti-assessment-item");s&&(this._itemRef=s,this.disabled&&this._itemRef.setAttribute("disabled",""),this.readonly&&this._itemRef.setAttribute("readonly",""),this.emit(o.ON_ITEM_READY,{detail:s}))}render(){return _`
2
- <slot
3
- @slotchange=${this._handleSlotchange}
4
- @on-prev-item=${this._onPrevItem}
5
- @on-next-item=${this._onNextItem}
6
- @on-check-item=${this._onCheckItem}
7
- @on-score-item=${this._onScoreItem}
8
- @on-request-item=${this._onRequestItem}
9
- @on-show-correct=${this._onShowCorrect}
10
- >
1
+ import{a as d,b as u}from"../chunk-DLLHO3W2.js";import{a as h,c as i}from"../chunk-NMCIOGD2.js";import{LitElement as r,html as a}from"lit";var m=(n,c)=>{class e extends n{_dispatch(){this.dispatchEvent(new CustomEvent(c,{composed:!0,bubbles:!0,detail:+this.getAttribute("index")}))}connectedCallback(){super.connectedCallback(),this.addEventListener("click",this._dispatch)}disconnectedCallback(){super.disconnectedCallback(),this.removeEventListener("click",this._dispatch)}}return e};customElements.define("qti-test-next",class extends m(r,"on-next-item"){constructor(){super(...arguments);this.render=()=>a`<slot></slot>`}});customElements.define("qti-test-item",class extends m(r,"on-request-item"){constructor(){super(...arguments);this.render=()=>a`<slot></slot>`}});customElements.define("qti-test-prev",class extends m(r,"on-prev-item"){constructor(){super(...arguments);this.render=()=>a`<slot></slot>`}});customElements.define("qti-test-check",class extends m(r,"on-check-item"){constructor(){super(...arguments);this.render=()=>a`<slot></slot>`}});customElements.define("qti-test-score",class extends m(r,"on-score-item"){constructor(){super(...arguments);this.render=()=>a`<slot></slot>`}});customElements.define("qti-test-show-correct",class extends m(r,"on-show-correct"){constructor(){super(...arguments);this.render=()=>a`<slot></slot>`}});import{html as _,LitElement as E}from"lit";import{ContextProvider as f}from"@lit-labs/context";import{customElement as I,property as l,query as p,state as R}from"lit/decorators.js";var o={ON_ITEM_WAS_FINISHED:"onItemWasFinished",ON_NO_RESPONSE_ON_SUBMIT:"onNoResponseOnSubmit",ON_REQUEST_ITEM:"onRequestItem",ON_TEST_FINISHED:"onTestFinished",ON_ITEM_READY:"onItemReady"},b=(e=>(e.linear="linear",e.nonlinear="nonlinear",e))(b||{}),x=(e=>(e.individual="individual",e.simultaneous="simultaneous",e))(x||{}),t=class extends E{constructor(){super(...arguments);this.disabled=!1;this.readonly=!1;this._navigationMode="nonlinear";this._submissionMode="simultaneous";this.items=[];this.itemIndex=0;this.provider=new f(this,u,{log:e=>{console.log(`[my-app] ${e}`)},view:"candidate"})}handleNavigationModeChange(e,s){this.prevButton.style.visibility=s==="linear"?"hidden":"visible"}handleItemIndexChange(e,s){this.emit(o.ON_REQUEST_ITEM,{detail:s})}set qtiContext(e){this.provider.value.view=e.view,this.provider.updateObservers()}set itemXML(e){this._itemRef&&this._itemRef.remove(),this.insertAdjacentHTML("afterbegin",e)}set manualOutcomeValue(e){this._itemRef.setOutcomeValue("SCORE",e)}set itemResponse(e){this._itemRef&&(this._itemRef.responses=e,this._navigationMode==="linear"&&(this._itemRef.style.filter="blur(5px)",this._itemRef.setAttribute("disabled",""),this.dispatchEvent(new CustomEvent(o.ON_ITEM_WAS_FINISHED))))}_onCheckItem(){return this._itemRef.validateResponses()?(this._itemRef.processResponse(),!0):!1}_onScoreItem(){this._onCheckItem()&&this._itemRef.processResponse()}_onPrevItem(){this.itemIndex>0&&this.emit(o.ON_REQUEST_ITEM,{detail:this.itemIndex-1})}_onNextItem(){if(this._navigationMode==="linear"&&!this._itemRef.validateResponses()){this.dispatchEvent(new CustomEvent(o.ON_NO_RESPONSE_ON_SUBMIT));return}this.itemIndex<this.items.length-1?this.emit(o.ON_REQUEST_ITEM,{detail:this.itemIndex+1}):this.dispatchEvent(new CustomEvent(o.ON_TEST_FINISHED))}_onShowCorrect(){this._itemRef.showCorrectResponse()}_onRequestItem({detail:e}){this.emit(o.ON_REQUEST_ITEM,{detail:e})}_handleSlotchange(e){let s=this.querySelector("qti-assessment-item");s&&(this._itemRef=s,this.disabled&&this._itemRef.setAttribute("disabled",""),this.readonly&&this._itemRef.setAttribute("readonly",""),this.emit(o.ON_ITEM_READY,{detail:s}))}render(){return _`
2
+ <slot name="qti-item"></slot>
3
+ <slot
4
+ @slotchange=${this._handleSlotchange}
5
+ @on-prev-item=${this._onPrevItem}
6
+ @on-next-item=${this._onNextItem}
7
+ @on-check-item=${this._onCheckItem}
8
+ @on-score-item=${this._onScoreItem}
9
+ @on-request-item=${this._onRequestItem}
10
+ @on-show-correct=${this._onShowCorrect}
11
+ >
12
+ </slot>
11
13
  </slot>
12
- `}emit(e,s){let v=new CustomEvent(e,h({bubbles:!0,cancelable:!1,composed:!0,detail:{}},s));this.dispatchEvent(v)}};i([p("qti-test-prev")],t.prototype,"prevButton",2),i([p("qti-test-next")],t.prototype,"nextButton",2),i([l({type:Boolean})],t.prototype,"disabled",2),i([l({type:Boolean})],t.prototype,"readonly",2),i([l({type:String,attribute:"navigation-mode"})],t.prototype,"_navigationMode",2),i([d("_navigationMode",{waitUntilFirstUpdate:!0})],t.prototype,"handleNavigationModeChange",1),i([l({type:String,attribute:"submission-mode"})],t.prototype,"_submissionMode",2),i([l()],t.prototype,"items",2),i([l({type:Number,attribute:"item-index",reflect:!0})],t.prototype,"itemIndex",2),i([d("itemIndex",{waitUntilFirstUpdate:!0})],t.prototype,"handleItemIndexChange",1),i([R()],t.prototype,"_itemRef",2),t=i([I("qti-test")],t);export{b as NavigationMode,t as QtiTest,x as SubmissionMode,o as TestEvents};
14
+ `}emit(e,s){let v=new CustomEvent(e,h({bubbles:!0,cancelable:!1,composed:!0,detail:{}},s));this.dispatchEvent(v)}};i([p("qti-test-prev")],t.prototype,"prevButton",2),i([p("qti-test-next")],t.prototype,"nextButton",2),i([l({type:Boolean})],t.prototype,"disabled",2),i([l({type:Boolean})],t.prototype,"readonly",2),i([l({type:String,attribute:"navigation-mode"})],t.prototype,"_navigationMode",2),i([d("_navigationMode",{waitUntilFirstUpdate:!0})],t.prototype,"handleNavigationModeChange",1),i([l({type:String,attribute:"submission-mode"})],t.prototype,"_submissionMode",2),i([l({attribute:!1})],t.prototype,"items",2),i([l({type:Number,attribute:"item-index",reflect:!0})],t.prototype,"itemIndex",2),i([d("itemIndex",{waitUntilFirstUpdate:!0})],t.prototype,"handleItemIndexChange",1),i([R()],t.prototype,"_itemRef",2),t=i([I("qti-test")],t);export{b as NavigationMode,t as QtiTest,x as SubmissionMode,o as TestEvents};