@qti-components/test 1.10.0 → 2.0.0-next.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/dist/components/index.d.ts +0 -11
  2. package/dist/components/index.js +0 -11
  3. package/dist/components/index.js.map +1 -1
  4. package/dist/components/test-bookmark/test-bookmark.d.ts +48 -0
  5. package/dist/components/test-bookmark/test-bookmark.js +144 -0
  6. package/dist/components/test-bookmark/test-bookmark.js.map +1 -0
  7. package/dist/components/test-check-item/test-check-item.d.ts +9 -2
  8. package/dist/components/test-check-item/test-check-item.js +12 -11
  9. package/dist/components/test-check-item/test-check-item.js.map +1 -1
  10. package/dist/components/test-navigation/test-navigation.js +8 -2
  11. package/dist/components/test-navigation/test-navigation.js.map +1 -1
  12. package/dist/components/test-stamp/test-stamp.js +6 -2
  13. package/dist/components/test-stamp/test-stamp.js.map +1 -1
  14. package/dist/elements.d.ts +31 -44
  15. package/dist/elements.js +4 -30
  16. package/dist/elements.js.map +1 -1
  17. package/dist/index.d.ts +2 -0
  18. package/dist/index.js +2 -0
  19. package/dist/index.js.map +1 -1
  20. package/dist/mixins/test-state.mixin.js +25 -1
  21. package/dist/mixins/test-state.mixin.js.map +1 -1
  22. package/dist/plugin-state.d.ts +8 -0
  23. package/dist/plugin-state.js +7 -0
  24. package/dist/plugin-state.js.map +1 -0
  25. package/dist/plugins/elements.d.ts +71 -0
  26. package/dist/plugins/elements.js +33 -0
  27. package/dist/plugins/elements.js.map +1 -0
  28. package/dist/plugins/index.d.ts +2 -0
  29. package/dist/plugins/index.js +3 -0
  30. package/dist/plugins/index.js.map +1 -0
  31. package/dist/public-events.d.ts +5 -0
  32. package/dist/public-events.js +1 -0
  33. package/dist/public-events.js.map +1 -1
  34. package/dist/tts/elements.d.ts +28 -0
  35. package/dist/tts/elements.js +14 -0
  36. package/dist/tts/elements.js.map +1 -0
  37. package/dist/{components/test-item-to-speech → tts}/test-item-to-speech.d.ts +9 -9
  38. package/dist/{components/test-item-to-speech → tts}/test-item-to-speech.js +59 -85
  39. package/dist/tts/test-item-to-speech.js.map +1 -0
  40. package/dist/types/qti-test-state.d.ts +12 -1
  41. package/dist/types/qti-test-state.js.map +1 -1
  42. package/package.json +11 -7
  43. package/dist/components/test-item-to-speech/test-item-to-speech.js.map +0 -1
  44. package/dist/components/test-paging-buttons-stamp/test-paging-buttons-stamp.d.ts +0 -19
  45. package/dist/components/test-paging-buttons-stamp/test-paging-buttons-stamp.js +0 -39
  46. package/dist/components/test-paging-buttons-stamp/test-paging-buttons-stamp.js.map +0 -1
  47. package/dist/components/test-section-buttons-stamp/test-section-buttons-stamp.d.ts +0 -19
  48. package/dist/components/test-section-buttons-stamp/test-section-buttons-stamp.js +0 -39
  49. package/dist/components/test-section-buttons-stamp/test-section-buttons-stamp.js.map +0 -1
@@ -14,18 +14,7 @@ export * from '../components/qti-item-session-control/qti-item-session-control';
14
14
  export * from './test-navigation/test-navigation';
15
15
  export * from './test-next/test-next';
16
16
  export * from './test-prev/test-prev';
17
- export * from './test-view-toggle/test-view';
18
17
  export * from './test-item-link/test-item-link';
19
18
  export * from './test-end-attempt/test-end-attempt';
20
- export * from './test-paging-buttons-stamp/test-paging-buttons-stamp';
21
19
  export * from './test-container/test-container';
22
- export * from './test-print-item-variables/test-print-item-variables';
23
- export * from './test-section-buttons-stamp/test-section-buttons-stamp';
24
20
  export * from './test-section-link/test-section-link';
25
- export * from './test-print-context/test-print-context';
26
- export * from './test-stamp/test-stamp';
27
- export * from './test-scoring-buttons/test-scoring-buttons';
28
- export * from './test-view-toggle/test-view-toggle';
29
- export * from './test-scoring-feedback/test-scoring-feedback';
30
- export * from './test-check-item/test-check-item';
31
- export * from './test-item-to-speech/test-item-to-speech';
@@ -15,19 +15,8 @@ export * from '../components/qti-item-session-control/qti-item-session-control';
15
15
  export * from './test-navigation/test-navigation';
16
16
  export * from './test-next/test-next';
17
17
  export * from './test-prev/test-prev';
18
- export * from './test-view-toggle/test-view';
19
18
  export * from './test-item-link/test-item-link';
20
19
  export * from './test-end-attempt/test-end-attempt';
21
- export * from './test-paging-buttons-stamp/test-paging-buttons-stamp';
22
20
  export * from './test-container/test-container';
23
- export * from './test-print-item-variables/test-print-item-variables';
24
- export * from './test-section-buttons-stamp/test-section-buttons-stamp';
25
21
  export * from './test-section-link/test-section-link';
26
- export * from './test-print-context/test-print-context';
27
- export * from './test-stamp/test-stamp';
28
- export * from './test-scoring-buttons/test-scoring-buttons';
29
- export * from './test-view-toggle/test-view-toggle';
30
- export * from './test-scoring-feedback/test-scoring-feedback';
31
- export * from './test-check-item/test-check-item';
32
- export * from './test-item-to-speech/test-item-to-speech';
33
22
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AAAA,uFAAuF;AACvF,cAAc,iCAAiC,CAAC;AAChD,cAAc,+DAA+D,CAAC;AAC9E,cAAc,6DAA6D,CAAC;AAC5E,cAAc,uDAAuD,CAAC;AACtE,cAAc,2CAA2C,CAAC;AAC1D,cAAc,mDAAmD,CAAC;AAClE,cAAc,6DAA6D,CAAC;AAC5E,cAAc,qDAAqD,CAAC;AACpE,cAAc,uDAAuD,CAAC;AACtE,cAAc,yDAAyD,CAAC;AACxE,cAAc,mDAAmD,CAAC;AAClE,cAAc,+CAA+C,CAAC;AAC9D,cAAc,iEAAiE,CAAC;AAEhF,cAAc,mCAAmC,CAAC;AAClD,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,iCAAiC,CAAC;AAChD,cAAc,qCAAqC,CAAC;AACpD,cAAc,uDAAuD,CAAC;AACtE,cAAc,iCAAiC,CAAC;AAChD,cAAc,uDAAuD,CAAC;AACtE,cAAc,yDAAyD,CAAC;AACxE,cAAc,uCAAuC,CAAC;AACtD,cAAc,yCAAyC,CAAC;AACxD,cAAc,yBAAyB,CAAC;AACxC,cAAc,6CAA6C,CAAC;AAC5D,cAAc,qCAAqC,CAAC;AACpD,cAAc,+CAA+C,CAAC;AAC9D,cAAc,mCAAmC,CAAC;AAClD,cAAc,2CAA2C,CAAC","sourcesContent":["/* test functionality webcomponents which are tested and can be used in your project */\nexport * from '../components/qti-test/qti-test';\nexport * from '../components/qti-assessment-item-ref/qti-assessment-item-ref';\nexport * from '../components/qti-assessment-section/qti-assessment-section';\nexport * from '../components/qti-assessment-test/qti-assessment-test';\nexport * from '../components/qti-test-part/qti-test-part';\nexport * from '../components/qti-test-feedback/qti-test-feedback';\nexport * from '../components/qti-outcome-processing/qti-outcome-processing';\nexport * from '../components/qti-test-variables/qti-test-variables';\nexport * from '../components/qti-number-selected/qti-number-selected';\nexport * from '../components/qti-number-presented/qti-number-presented';\nexport * from '../components/qti-pre-condition/qti-pre-condition';\nexport * from '../components/qti-branch-rule/qti-branch-rule';\nexport * from '../components/qti-item-session-control/qti-item-session-control';\n\nexport * from './test-navigation/test-navigation';\nexport * from './test-next/test-next';\nexport * from './test-prev/test-prev';\nexport * from './test-view-toggle/test-view';\nexport * from './test-item-link/test-item-link';\nexport * from './test-end-attempt/test-end-attempt';\nexport * from './test-paging-buttons-stamp/test-paging-buttons-stamp';\nexport * from './test-container/test-container';\nexport * from './test-print-item-variables/test-print-item-variables';\nexport * from './test-section-buttons-stamp/test-section-buttons-stamp';\nexport * from './test-section-link/test-section-link';\nexport * from './test-print-context/test-print-context';\nexport * from './test-stamp/test-stamp';\nexport * from './test-scoring-buttons/test-scoring-buttons';\nexport * from './test-view-toggle/test-view-toggle';\nexport * from './test-scoring-feedback/test-scoring-feedback';\nexport * from './test-check-item/test-check-item';\nexport * from './test-item-to-speech/test-item-to-speech';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AAAA,uFAAuF;AACvF,cAAc,iCAAiC,CAAC;AAChD,cAAc,+DAA+D,CAAC;AAC9E,cAAc,6DAA6D,CAAC;AAC5E,cAAc,uDAAuD,CAAC;AACtE,cAAc,2CAA2C,CAAC;AAC1D,cAAc,mDAAmD,CAAC;AAClE,cAAc,6DAA6D,CAAC;AAC5E,cAAc,qDAAqD,CAAC;AACpE,cAAc,uDAAuD,CAAC;AACtE,cAAc,yDAAyD,CAAC;AACxE,cAAc,mDAAmD,CAAC;AAClE,cAAc,+CAA+C,CAAC;AAC9D,cAAc,iEAAiE,CAAC;AAEhF,cAAc,mCAAmC,CAAC;AAClD,cAAc,uBAAuB,CAAC;AACtC,cAAc,uBAAuB,CAAC;AACtC,cAAc,iCAAiC,CAAC;AAChD,cAAc,qCAAqC,CAAC;AACpD,cAAc,iCAAiC,CAAC;AAChD,cAAc,uCAAuC,CAAC","sourcesContent":["/* test functionality webcomponents which are tested and can be used in your project */\nexport * from '../components/qti-test/qti-test';\nexport * from '../components/qti-assessment-item-ref/qti-assessment-item-ref';\nexport * from '../components/qti-assessment-section/qti-assessment-section';\nexport * from '../components/qti-assessment-test/qti-assessment-test';\nexport * from '../components/qti-test-part/qti-test-part';\nexport * from '../components/qti-test-feedback/qti-test-feedback';\nexport * from '../components/qti-outcome-processing/qti-outcome-processing';\nexport * from '../components/qti-test-variables/qti-test-variables';\nexport * from '../components/qti-number-selected/qti-number-selected';\nexport * from '../components/qti-number-presented/qti-number-presented';\nexport * from '../components/qti-pre-condition/qti-pre-condition';\nexport * from '../components/qti-branch-rule/qti-branch-rule';\nexport * from '../components/qti-item-session-control/qti-item-session-control';\n\nexport * from './test-navigation/test-navigation';\nexport * from './test-next/test-next';\nexport * from './test-prev/test-prev';\nexport * from './test-item-link/test-item-link';\nexport * from './test-end-attempt/test-end-attempt';\nexport * from './test-container/test-container';\nexport * from './test-section-link/test-section-link';\n"]}
@@ -0,0 +1,48 @@
1
+ import { LitElement } from 'lit';
2
+ import type { ComputedContext } from '@qti-components/base';
3
+ declare module '../../types/qti-test-state' {
4
+ interface QtiTestPluginState {
5
+ /** Item-ref identifiers the candidate marked to come back to, in the order they were marked. */
6
+ bookmarks: string[];
7
+ }
8
+ }
9
+ /** The item-ref identifiers bookmarked so far. For a host's own navigation: mark these. */
10
+ export declare const bookmarkedItems: (context: Pick<ComputedContext, "plugins"> | undefined) => string[];
11
+ /**
12
+ * A toggle that marks the item on screen to come back to. The marks live in the test's state under
13
+ * `bookmarks` (`session.plugins.bookmarks`), so a host that stores `state` stores them, and a
14
+ * reloaded test shows them again.
15
+ *
16
+ * Put it inside `<test-navigation>`, either in the toolbar, where it marks the item on screen, or in
17
+ * the `<template item-ref>`, where each item gets its own and it marks that item. It is a button
18
+ * (`role="button"`, `aria-pressed`) and reflects `bookmarked` on the host for styling; its content is
19
+ * the label. In the toolbar it is `disabled` while no item is on screen. A host's own navigation reads
20
+ * the marks with `bookmarkedItems(computedContext)`.
21
+ *
22
+ * Give it an `item` (an item-ref identifier) to mark that item instead, wherever the button sits: in a
23
+ * stamp template that lists the items of a section, `<test-bookmark item="{{ item.identifier }}">`
24
+ * puts a button next to each one.
25
+ *
26
+ * @slot - The label.
27
+ * @attr item - The item-ref identifier this button marks; without it, the item it is stamped into, or else the one on screen.
28
+ * @attr bookmarked - Reflected: the item on screen is bookmarked.
29
+ * @attr disabled - Reflected: there is no item on screen.
30
+ */
31
+ export declare class TestBookmark extends LitElement {
32
+ #private;
33
+ protected computedContext?: ComputedContext;
34
+ item?: string;
35
+ bookmarked: boolean;
36
+ disabled: boolean;
37
+ static styles: import("lit").CSSResult;
38
+ constructor();
39
+ connectedCallback(): void;
40
+ protected willUpdate(): void;
41
+ protected updated(): void;
42
+ render(): import("lit").TemplateResult<1>;
43
+ }
44
+ declare global {
45
+ interface HTMLElementTagNameMap {
46
+ 'test-bookmark': TestBookmark;
47
+ }
48
+ }
@@ -0,0 +1,144 @@
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 { css, html, LitElement } from 'lit';
8
+ import { consume } from '@lit/context';
9
+ import { property } from 'lit/decorators.js';
10
+ import { computedContext } from '@qti-components/base';
11
+ import * as styles from '../styles';
12
+ import { dispatchPublic } from '../../public-events';
13
+ import { pluginState } from '../../plugin-state';
14
+ /** The item-ref identifiers bookmarked so far. For a host's own navigation: mark these. */
15
+ export const bookmarkedItems = (context) => pluginState(context, 'bookmarks') ?? [];
16
+ /** The identifier of the item-ref an element is stamped into (`<template item-ref>`), looking out through shadow roots. */
17
+ const itemRefOf = (element) => {
18
+ const itemRef = element.closest('qti-assessment-item-ref');
19
+ if (itemRef)
20
+ return itemRef.getAttribute('identifier') ?? undefined;
21
+ const root = element.getRootNode();
22
+ return root instanceof ShadowRoot ? itemRefOf(root.host) : undefined;
23
+ };
24
+ /**
25
+ * A toggle that marks the item on screen to come back to. The marks live in the test's state under
26
+ * `bookmarks` (`session.plugins.bookmarks`), so a host that stores `state` stores them, and a
27
+ * reloaded test shows them again.
28
+ *
29
+ * Put it inside `<test-navigation>`, either in the toolbar, where it marks the item on screen, or in
30
+ * the `<template item-ref>`, where each item gets its own and it marks that item. It is a button
31
+ * (`role="button"`, `aria-pressed`) and reflects `bookmarked` on the host for styling; its content is
32
+ * the label. In the toolbar it is `disabled` while no item is on screen. A host's own navigation reads
33
+ * the marks with `bookmarkedItems(computedContext)`.
34
+ *
35
+ * Give it an `item` (an item-ref identifier) to mark that item instead, wherever the button sits: in a
36
+ * stamp template that lists the items of a section, `<test-bookmark item="{{ item.identifier }}">`
37
+ * puts a button next to each one.
38
+ *
39
+ * @slot - The label.
40
+ * @attr item - The item-ref identifier this button marks; without it, the item it is stamped into, or else the one on screen.
41
+ * @attr bookmarked - Reflected: the item on screen is bookmarked.
42
+ * @attr disabled - Reflected: there is no item on screen.
43
+ */
44
+ export class TestBookmark extends LitElement {
45
+ static { this.styles = css `
46
+ :host {
47
+ ${styles.btn};
48
+ }
49
+ :host(:hover:not([disabled])) {
50
+ ${styles.btnInteractive};
51
+ }
52
+ :host {
53
+ display: inline-flex;
54
+ align-items: center;
55
+ gap: 0.4em;
56
+ }
57
+ svg {
58
+ width: 1.1em;
59
+ height: 1.1em;
60
+ flex: none;
61
+ fill: none;
62
+ stroke: currentColor;
63
+ stroke-width: 2;
64
+ stroke-linejoin: round;
65
+ }
66
+ :host([bookmarked]) {
67
+ color: var(--qti-bookmark-color, #b45309);
68
+ }
69
+ :host([bookmarked]) svg {
70
+ fill: currentColor;
71
+ }
72
+ :host(:focus-visible) {
73
+ ${styles.focusRing};
74
+ }
75
+ :host([disabled]) {
76
+ ${styles.dis};
77
+ }
78
+ `; }
79
+ constructor() {
80
+ super();
81
+ this.bookmarked = false;
82
+ this.disabled = false;
83
+ this.addEventListener('click', () => this.#toggle());
84
+ this.addEventListener('keydown', event => {
85
+ if (event.key !== 'Enter' && event.key !== ' ')
86
+ return;
87
+ event.preventDefault();
88
+ this.#toggle();
89
+ });
90
+ }
91
+ connectedCallback() {
92
+ super.connectedCallback();
93
+ if (!this.hasAttribute('role'))
94
+ this.setAttribute('role', 'button');
95
+ if (!this.hasAttribute('tabindex'))
96
+ this.setAttribute('tabindex', '0');
97
+ }
98
+ /** The item this button marks: its own, or else the one on screen. */
99
+ get #activeItem() {
100
+ return (this.item ||
101
+ (itemRefOf(this) ??
102
+ this.computedContext?.testParts
103
+ ?.flatMap(part => part.sections.flatMap(section => section.items))
104
+ .find(item => item.active)?.identifier));
105
+ }
106
+ willUpdate() {
107
+ const active = this.#activeItem;
108
+ this.disabled = !active;
109
+ this.bookmarked = !!active && bookmarkedItems(this.computedContext).includes(active);
110
+ }
111
+ updated() {
112
+ this.setAttribute('aria-pressed', String(this.bookmarked));
113
+ this.setAttribute('aria-disabled', String(this.disabled));
114
+ }
115
+ #toggle() {
116
+ const active = this.#activeItem;
117
+ if (!active)
118
+ return;
119
+ const marked = bookmarkedItems(this.computedContext);
120
+ const next = marked.includes(active) ? marked.filter(id => id !== active) : [...marked, active];
121
+ // An empty list removes the entry, so a test nobody bookmarked keeps no trace in the state.
122
+ dispatchPublic(this, 'cito-test-update-plugin-state', {
123
+ plugin: 'bookmarks',
124
+ value: next.length > 0 ? next : null
125
+ });
126
+ }
127
+ render() {
128
+ return html `<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M6 3h12v18l-6-4.5L6 21z" /></svg><slot></slot>`;
129
+ }
130
+ }
131
+ __decorate([
132
+ consume({ context: computedContext, subscribe: true }),
133
+ property({ attribute: false })
134
+ ], TestBookmark.prototype, "computedContext", void 0);
135
+ __decorate([
136
+ property({ reflect: true })
137
+ ], TestBookmark.prototype, "item", void 0);
138
+ __decorate([
139
+ property({ type: Boolean, reflect: true })
140
+ ], TestBookmark.prototype, "bookmarked", void 0);
141
+ __decorate([
142
+ property({ type: Boolean, reflect: true })
143
+ ], TestBookmark.prototype, "disabled", void 0);
144
+ //# sourceMappingURL=test-bookmark.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test-bookmark.js","sourceRoot":"","sources":["../../../src/components/test-bookmark/test-bookmark.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD,OAAO,KAAK,MAAM,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,o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AC,WAAW,CAAC;QAChC,IAAI,CAAC,MAAM;YAAE,OAAO;QACpB,MAAM,MAAM,GAAG,eAAe,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;QACrD,MAAM,IAAI,GAAG,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,MAAM,EAAE,MAAM,CAAC,CAAC;QAChG,4FAA4F;QAC5F,cAAc,CAAC,IAAI,EAAE,+BAA+B,EAAE;YACpD,MAAM,EAAE,WAAW;YACnB,KAAK,EAAE,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI;SACrC,CAAC,CAAC;IACL,CAAC;IAEQ,MAAM;QACb,OAAO,IAAI,CAAA,qGAAqG,CAAC;IACnH,CAAC;;AA/FS;IAFT,OAAO,CAAC,EAAE,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;IACtD,QAAQ,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;qDACa;AAEf;IAA5B,QAAQ,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;0CAAe;AAEC;IAA3C,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;gDAAoB;AAEnB;IAA3C,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;8CAAkB","sourcesContent":["import { css, html, LitElement } from 'lit';\nimport { consume } from '@lit/context';\nimport { property } from 'lit/decorators.js';\n\nimport { computedContext } from '@qti-components/base';\n\nimport * as styles from '../styles';\nimport { dispatchPublic } from '../../public-events';\nimport { pluginState } from '../../plugin-state';\n\nimport type { ComputedContext } from '@qti-components/base';\n\ndeclare module '../../types/qti-test-state' {\n interface QtiTestPluginState {\n /** Item-ref identifiers the candidate marked to come back to, in the order they were marked. */\n bookmarks: string[];\n }\n}\n\n/** The item-ref identifiers bookmarked so far. For a host's own navigation: mark these. */\nexport const bookmarkedItems = (context: Pick<ComputedContext, 'plugins'> | undefined): string[] =>\n pluginState(context, 'bookmarks') ?? [];\n\n/** The identifier of the item-ref an element is stamped into (`<template item-ref>`), looking out through shadow roots. */\nconst itemRefOf = (element: Element): string | undefined => {\n const itemRef = element.closest('qti-assessment-item-ref');\n if (itemRef) return itemRef.getAttribute('identifier') ?? undefined;\n const root = element.getRootNode();\n return root instanceof ShadowRoot ? itemRefOf(root.host) : undefined;\n};\n\n/**\n * A toggle that marks the item on screen to come back to. The marks live in the test's state under\n * `bookmarks` (`session.plugins.bookmarks`), so a host that stores `state` stores them, and a\n * reloaded test shows them again.\n *\n * Put it inside `<test-navigation>`, either in the toolbar, where it marks the item on screen, or in\n * the `<template item-ref>`, where each item gets its own and it marks that item. It is a button\n * (`role=\"button\"`, `aria-pressed`) and reflects `bookmarked` on the host for styling; its content is\n * the label. In the toolbar it is `disabled` while no item is on screen. A host's own navigation reads\n * the marks with `bookmarkedItems(computedContext)`.\n *\n * Give it an `item` (an item-ref identifier) to mark that item instead, wherever the button sits: in a\n * stamp template that lists the items of a section, `<test-bookmark item=\"{{ item.identifier }}\">`\n * puts a button next to each one.\n *\n * @slot - The label.\n * @attr item - The item-ref identifier this button marks; without it, the item it is stamped into, or else the one on screen.\n * @attr bookmarked - Reflected: the item on screen is bookmarked.\n * @attr disabled - Reflected: there is no item on screen.\n */\nexport class TestBookmark extends LitElement {\n @consume({ context: computedContext, subscribe: true })\n @property({ attribute: false })\n protected computedContext?: ComputedContext;\n\n @property({ reflect: true }) item?: string;\n\n @property({ type: Boolean, reflect: true }) bookmarked = false;\n\n @property({ type: Boolean, reflect: true }) disabled = false;\n\n static override styles = css`\n :host {\n ${styles.btn};\n }\n :host(:hover:not([disabled])) {\n ${styles.btnInteractive};\n }\n :host {\n display: inline-flex;\n align-items: center;\n gap: 0.4em;\n }\n svg {\n width: 1.1em;\n height: 1.1em;\n flex: none;\n fill: none;\n stroke: currentColor;\n stroke-width: 2;\n stroke-linejoin: round;\n }\n :host([bookmarked]) {\n color: var(--qti-bookmark-color, #b45309);\n }\n :host([bookmarked]) svg {\n fill: currentColor;\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', () => this.#toggle());\n this.addEventListener('keydown', event => {\n if (event.key !== 'Enter' && event.key !== ' ') return;\n event.preventDefault();\n this.#toggle();\n });\n }\n\n override connectedCallback(): void {\n super.connectedCallback();\n if (!this.hasAttribute('role')) this.setAttribute('role', 'button');\n if (!this.hasAttribute('tabindex')) this.setAttribute('tabindex', '0');\n }\n\n /** The item this button marks: its own, or else the one on screen. */\n get #activeItem(): string | undefined {\n return (\n this.item ||\n (itemRefOf(this) ??\n this.computedContext?.testParts\n ?.flatMap(part => part.sections.flatMap(section => section.items))\n .find(item => item.active)?.identifier)\n );\n }\n\n protected override willUpdate(): void {\n const active = this.#activeItem;\n this.disabled = !active;\n this.bookmarked = !!active && bookmarkedItems(this.computedContext).includes(active);\n }\n\n protected override updated(): void {\n this.setAttribute('aria-pressed', String(this.bookmarked));\n this.setAttribute('aria-disabled', String(this.disabled));\n }\n\n #toggle(): void {\n const active = this.#activeItem;\n if (!active) return;\n const marked = bookmarkedItems(this.computedContext);\n const next = marked.includes(active) ? marked.filter(id => id !== active) : [...marked, active];\n // An empty list removes the entry, so a test nobody bookmarked keeps no trace in the state.\n dispatchPublic(this, 'cito-test-update-plugin-state', {\n plugin: 'bookmarks',\n value: next.length > 0 ? next : null\n });\n }\n\n override render() {\n return html`<svg viewBox=\"0 0 24 24\" aria-hidden=\"true\"><path d=\"M6 3h12v18l-6-4.5L6 21z\" /></svg><slot></slot>`;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'test-bookmark': TestBookmark;\n }\n}\n"]}
@@ -1,7 +1,14 @@
1
1
  import { LitElement } from 'lit';
2
- import type { TestHost } from '../../internal/test-host.context';
2
+ import type { View } from '@qti-components/base';
3
+ /**
4
+ * Ends the attempt on the current item and switches the test to `view` (default `scorer`), which
5
+ * reveals the `[view]` content for that view, such as a scorer's rubric. The view stays until
6
+ * something switches it back (`test-view-toggle`).
7
+ *
8
+ * @attr view - The view to switch to after the attempt ended.
9
+ */
3
10
  export declare class TestCheckItem extends LitElement {
4
- protected testHost?: TestHost;
11
+ view: View;
5
12
  static styles: import("lit").CSSResult;
6
13
  constructor();
7
14
  render(): import("lit").TemplateResult<1>;
@@ -4,11 +4,17 @@ 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 { consume } from '@lit/context';
8
7
  import { css, html, LitElement } from 'lit';
9
- import { testHostContext } from '../../internal/test-host.context';
8
+ import { property } from 'lit/decorators.js';
10
9
  import * as styles from '../styles';
11
10
  import { dispatchPublic } from '../../public-events';
11
+ /**
12
+ * Ends the attempt on the current item and switches the test to `view` (default `scorer`), which
13
+ * reveals the `[view]` content for that view, such as a scorer's rubric. The view stays until
14
+ * something switches it back (`test-view-toggle`).
15
+ *
16
+ * @attr view - The view to switch to after the attempt ended.
17
+ */
12
18
  export class TestCheckItem extends LitElement {
13
19
  static { this.styles = css `
14
20
  :host {
@@ -26,15 +32,10 @@ export class TestCheckItem extends LitElement {
26
32
  `; }
27
33
  constructor() {
28
34
  super();
35
+ this.view = 'scorer';
29
36
  this.addEventListener('click', () => {
30
37
  dispatchPublic(this, 'cito-test-end-attempt', {});
31
- const testContainer = this.testHost?.querySelector('test-container');
32
- if (!testContainer)
33
- return;
34
- const viewElements = Array.from(testContainer.shadowRoot.querySelectorAll('[view]'));
35
- viewElements.forEach((element) => {
36
- element.classList.toggle('show', true);
37
- });
38
+ dispatchPublic(this, 'cito-test-switch-view', this.view);
38
39
  });
39
40
  }
40
41
  render() {
@@ -42,6 +43,6 @@ export class TestCheckItem extends LitElement {
42
43
  }
43
44
  }
44
45
  __decorate([
45
- consume({ context: testHostContext, subscribe: true })
46
- ], TestCheckItem.prototype, "testHost", void 0);
46
+ property({ type: String })
47
+ ], TestCheckItem.prototype, "view", void 0);
47
48
  //# 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,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AAE5C,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AACnE,OAAO,KAAK,MAAM,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAKrD,MAAM,OAAO,aAAc,SAAQ,UAAU;aAI3B,WAAM,GAAG,GAAG,CAAA;;QAEtB,MAAM,CAAC,GAAG;;;QAGV,MAAM,CAAC,cAAc;;;QAGrB,MAAM,CAAC,SAAS;;;QAGhB,MAAM,CAAC,GAAG;;GAEf,CAAC;IAEF;QACE,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,gBAAgB,CAAC,OAAO,EAAE,GAAG,EAAE;YAClC,cAAc,CAAC,IAAI,EAAE,uBAAuB,EAAE,EAAE,CAAC,CAAC;YAClD,MAAM,aAAa,GAAG,IAAI,CAAC,QAAQ,EAAE,aAAa,CAAgB,gBAAgB,CAAC,CAAC;YACpF,IAAI,CAAC,aAAa;gBAAE,OAAO;YAE3B,MAAM,YAAY,GAAG,KAAK,CAAC,IAAI,CAAC,aAAa,CAAC,UAAU,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC,CAAC;YAErF,YAAY,CAAC,OAAO,CAAC,CAAC,OAAoB,EAAE,EAAE;gBAC5C,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;YACzC,CAAC,CAAC,CAAC;QACL,CAAC,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';\nimport { dispatchPublic } from '../../public-events';\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 dispatchPublic(this, 'cito-test-end-attempt', {});\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
+ {"version":3,"file":"test-check-item.js","sourceRoot":"","sources":["../../../src/components/test-check-item/test-check-item.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C,OAAO,KAAK,MAAM,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAIrD;;;;;;GAMG;AACH,MAAM,OAAO,aAAc,SAAQ,UAAU;aAG3B,WAAM,GAAG,GAAG,CAAA;;QAEtB,MAAM,CAAC,GAAG;;;QAGV,MAAM,CAAC,cAAc;;;QAGrB,MAAM,CAAC,SAAS;;;QAGhB,MAAM,CAAC,GAAG;;GAEf,AAbqB,CAapB;IAEF;QACE,KAAK,EAAE,CAAC;QAlBkB,SAAI,GAAS,QAAQ,CAAC;QAmBhD,IAAI,CAAC,gBAAgB,CAAC,OAAO,EAAE,GAAG,EAAE;YAClC,cAAc,CAAC,IAAI,EAAE,uBAAuB,EAAE,EAAE,CAAC,CAAC;YAClD,cAAc,CAAC,IAAI,EAAE,uBAAuB,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;QAC3D,CAAC,CAAC,CAAC;IACL,CAAC;IAEQ,MAAM;QACb,OAAO,IAAI,CAAA,iBAAiB,CAAC;IAC/B,CAAC;;AA3B2B;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;2CAAuB","sourcesContent":["import { css, html, LitElement } from 'lit';\nimport { property } from 'lit/decorators.js';\n\nimport * as styles from '../styles';\nimport { dispatchPublic } from '../../public-events';\n\nimport type { View } from '@qti-components/base';\n\n/**\n * Ends the attempt on the current item and switches the test to `view` (default `scorer`), which\n * reveals the `[view]` content for that view, such as a scorer's rubric. The view stays until\n * something switches it back (`test-view-toggle`).\n *\n * @attr view - The view to switch to after the attempt ended.\n */\nexport class TestCheckItem extends LitElement {\n @property({ type: String }) view: View = 'scorer';\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 dispatchPublic(this, 'cito-test-end-attempt', {});\n dispatchPublic(this, 'cito-test-switch-view', this.view);\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"]}
@@ -93,6 +93,8 @@ export class TestNavigation extends LitElement {
93
93
  * doesn't flip `done` until the candidate ends the attempt.
94
94
  */
95
95
  this.#optimality = new Map();
96
+ /** `computedContext.itemElement`: one function for the life of this element, carried along by every update. */
97
+ this.#itemElement = (identifier) => this.#assessmentItemFor(identifier) ?? null;
96
98
  listenPublic(this, 'cito-test-loaded', this.#handleTestConnected.bind(this));
97
99
  this.addEventListener('qti-assessment-item-connected', this.#handleItemConnected.bind(this));
98
100
  listenItemPublic(this, 'cito-item-response-changed', this.#handleInteractionChanged.bind(this));
@@ -138,9 +140,11 @@ export class TestNavigation extends LitElement {
138
140
  #assessmentItemFor(identifier) {
139
141
  if (!identifier)
140
142
  return undefined;
141
- const itemRef = this.#testElement?.querySelector(`qti-assessment-item-ref[identifier="${identifier}"]`);
143
+ const itemRef = this.#testElement?.querySelector(`qti-assessment-item-ref[identifier="${CSS.escape(identifier)}"]`);
142
144
  return itemRef?.assessmentItem ?? undefined;
143
145
  }
146
+ /** `computedContext.itemElement`: one function for the life of this element, carried along by every update. */
147
+ #itemElement;
144
148
  /** The currently active assessment item, exposed for optional presentation extensions. */
145
149
  get activeAssessmentItem() {
146
150
  if (!this.#testElement || !this._sessionContext?.navItemRefId)
@@ -183,7 +187,6 @@ export class TestNavigation extends LitElement {
183
187
  }
184
188
  }
185
189
  render() {
186
- // return this.myTemplate ? this.myTemplate(this.stampContext) : nothing;
187
190
  return html `<slot></slot>`;
188
191
  }
189
192
  /* PK: on test connected we can build the computed context */
@@ -222,9 +225,11 @@ export class TestNavigation extends LitElement {
222
225
  });
223
226
  const testPartElements = Array.from(this.#testElement?.querySelectorAll(`qti-test-part`) || []);
224
227
  this.computedContext = {
228
+ itemElement: this.#itemElement,
225
229
  identifier: this.#testElement.identifier,
226
230
  title: this.#testElement.title,
227
231
  view: this._sessionContext?.view,
232
+ plugins: this._sessionContext?.plugins ?? {},
228
233
  testParts: testPartElements.map(testPart => {
229
234
  const sectionElements = [...testPart.querySelectorAll(`qti-assessment-section`)];
230
235
  const testPartSessionControl = testPart.querySelector(':scope > qti-item-session-control');
@@ -372,6 +377,7 @@ export class TestNavigation extends LitElement {
372
377
  this.computedContext = {
373
378
  ...this.computedContext,
374
379
  view: this._sessionContext?.view,
380
+ plugins: this._sessionContext?.plugins ?? {},
375
381
  testParts: this.computedContext.testParts.map(testPart => {
376
382
  return {
377
383
  ...testPart,