@pie-qti/default-components 0.1.5 → 0.1.6

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/index.d.ts CHANGED
@@ -5,31 +5,22 @@
5
5
  * These components are packaged as web components that work with the
6
6
  * framework-agnostic @pie-qti/item-player core.
7
7
  */
8
- import type { ComponentRegistry } from '@pie-qti/item-player';
9
8
  export * from './shared/index.js';
9
+ interface DefaultComponentRegistration {
10
+ name: string;
11
+ description: string;
12
+ tagName: string;
13
+ }
14
+ interface DefaultComponentRegistry {
15
+ register(type: string, component: DefaultComponentRegistration): void;
16
+ }
17
+ export declare function getDefaultComponentTypes(): string[];
10
18
  /**
11
- * Register all default components with the ComponentRegistry
19
+ * Register all default components with the ComponentRegistry.
12
20
  *
13
- * This function should be called once at application startup to make
14
- * all default interaction components available to the player.
15
- *
16
- * IMPORTANT: Before calling this function, you MUST import the plugin loader:
17
- * ```typescript
18
- * import '@pie-qti/default-components/plugins';
19
- * ```
20
- * This import triggers web component registration via Svelte's customElement option.
21
- *
22
- * @param registry - The ComponentRegistry instance from the Player
23
- *
24
- * @example
25
- * ```typescript
26
- * import { Player } from '@pie-qti/item-player';
27
- * import '@pie-qti/default-components/plugins'; // Load web components
28
- * import { registerDefaultComponents } from '@pie-qti/default-components';
29
- *
30
- * const player = new Player(qtiXml);
31
- * registerDefaultComponents(player.getComponentRegistry());
32
- * ```
21
+ * This function should be called once at application startup to make all default
22
+ * block interaction components available to the player. Inline interactions are
23
+ * rendered in-flow by @pie-qti/item-player.
33
24
  */
34
- export declare function registerDefaultComponents(registry: ComponentRegistry): void;
25
+ export declare function registerDefaultComponents(registry: DefaultComponentRegistry): void;
35
26
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAG9D,cAAc,mBAAmB,CAAC;AAElC;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,yBAAyB,CAAC,QAAQ,EAAE,iBAAiB,GAAG,IAAI,CAwL3E"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,cAAc,mBAAmB,CAAC;AAElC,UAAU,4BAA4B;IACrC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;CAChB;AAED,UAAU,wBAAwB;IACjC,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,4BAA4B,GAAG,IAAI,CAAC;CACtE;AAoGD,wBAAgB,wBAAwB,IAAI,MAAM,EAAE,CAEnD;AAED;;;;;;GAMG;AACH,wBAAgB,yBAAyB,CAAC,QAAQ,EAAE,wBAAwB,GAAG,IAAI,CAUlF"}
package/dist/index.js CHANGED
@@ -7,192 +7,120 @@
7
7
  */
8
8
  // Export shared utilities and helpers
9
9
  export * from './shared/index.js';
10
- /**
11
- * Register all default components with the ComponentRegistry
12
- *
13
- * This function should be called once at application startup to make
14
- * all default interaction components available to the player.
15
- *
16
- * IMPORTANT: Before calling this function, you MUST import the plugin loader:
17
- * ```typescript
18
- * import '@pie-qti/default-components/plugins';
19
- * ```
20
- * This import triggers web component registration via Svelte's customElement option.
21
- *
22
- * @param registry - The ComponentRegistry instance from the Player
23
- *
24
- * @example
25
- * ```typescript
26
- * import { Player } from '@pie-qti/item-player';
27
- * import '@pie-qti/default-components/plugins'; // Load web components
28
- * import { registerDefaultComponents } from '@pie-qti/default-components';
29
- *
30
- * const player = new Player(qtiXml);
31
- * registerDefaultComponents(player.getComponentRegistry());
32
- * ```
33
- */
34
- export function registerDefaultComponents(registry) {
35
- // ChoiceInteraction - Radio buttons or checkboxes
36
- registry.register('choiceInteraction', {
10
+ const DEFAULT_COMPONENTS_BY_TYPE = {
11
+ choiceInteraction: {
37
12
  name: 'default-choice',
38
- priority: 0,
39
13
  description: 'Default Svelte-based choice interaction',
40
- canHandle: () => true,
41
14
  tagName: 'pie-qti-choice',
42
- // No componentClass needed - Svelte already registered it
43
- });
44
- // SliderInteraction - Range slider
45
- registry.register('sliderInteraction', {
15
+ },
16
+ sliderInteraction: {
46
17
  name: 'default-slider',
47
- priority: 0,
48
18
  description: 'Default Svelte-based slider interaction',
49
- canHandle: () => true,
50
19
  tagName: 'pie-qti-slider',
51
- });
52
- // OrderInteraction - Sortable list
53
- registry.register('orderInteraction', {
20
+ },
21
+ orderInteraction: {
54
22
  name: 'default-order',
55
- priority: 0,
56
23
  description: 'Default Svelte-based order interaction',
57
- canHandle: () => true,
58
24
  tagName: 'pie-qti-order',
59
- });
60
- // MatchInteraction - Match source to target
61
- registry.register('matchInteraction', {
25
+ },
26
+ matchInteraction: {
62
27
  name: 'default-match',
63
- priority: 0,
64
28
  description: 'Default Svelte-based match interaction',
65
- canHandle: () => true,
66
29
  tagName: 'pie-qti-match',
67
- });
68
- // AssociateInteraction - Create associations between choices
69
- registry.register('associateInteraction', {
30
+ },
31
+ associateInteraction: {
70
32
  name: 'default-associate',
71
- priority: 0,
72
33
  description: 'Default Svelte-based associate interaction',
73
- canHandle: () => true,
74
34
  tagName: 'pie-qti-associate',
75
- });
76
- // GapMatchInteraction - Fill gaps with words
77
- registry.register('gapMatchInteraction', {
35
+ },
36
+ gapMatchInteraction: {
78
37
  name: 'default-gap-match',
79
- priority: 0,
80
38
  description: 'Default Svelte-based gap match interaction',
81
- canHandle: () => true,
82
39
  tagName: 'pie-qti-gap-match',
83
- });
84
- // HotspotInteraction - Click on image hotspots
85
- registry.register('hotspotInteraction', {
40
+ },
41
+ hotspotInteraction: {
86
42
  name: 'default-hotspot',
87
- priority: 0,
88
43
  description: 'Default Svelte-based hotspot interaction',
89
- canHandle: () => true,
90
44
  tagName: 'pie-qti-hotspot',
91
- });
92
- // HottextInteraction - Select text within content
93
- registry.register('hottextInteraction', {
45
+ },
46
+ hottextInteraction: {
94
47
  name: 'default-hottext',
95
- priority: 0,
96
48
  description: 'Default Svelte-based hottext interaction',
97
- canHandle: () => true,
98
49
  tagName: 'pie-qti-hottext',
99
- });
100
- // MediaInteraction - Audio/video playback with tracking
101
- registry.register('mediaInteraction', {
50
+ },
51
+ mediaInteraction: {
102
52
  name: 'default-media',
103
- priority: 0,
104
53
  description: 'Default Svelte-based media interaction',
105
- canHandle: () => true,
106
54
  tagName: 'pie-qti-media',
107
- });
108
- // CustomInteraction - Fallback for custom interactions
109
- registry.register('customInteraction', {
55
+ },
56
+ customInteraction: {
110
57
  name: 'default-custom',
111
- priority: 0,
112
58
  description: 'Default Svelte-based custom interaction',
113
- canHandle: () => true,
114
59
  tagName: 'pie-qti-custom',
115
- });
116
- // EndAttemptInteraction - End attempt button
117
- registry.register('endAttemptInteraction', {
60
+ },
61
+ endAttemptInteraction: {
118
62
  name: 'default-end-attempt',
119
- priority: 0,
120
63
  description: 'Default Svelte-based end attempt interaction',
121
- canHandle: () => true,
122
64
  tagName: 'pie-qti-end-attempt',
123
- });
124
- // PositionObjectInteraction - Drag objects onto canvas
125
- registry.register('positionObjectInteraction', {
65
+ },
66
+ positionObjectInteraction: {
126
67
  name: 'default-position-object',
127
- priority: 0,
128
68
  description: 'Default Svelte-based position object interaction',
129
- canHandle: () => true,
130
69
  tagName: 'pie-qti-position-object',
131
- });
132
- // GraphicGapMatchInteraction - Drag labels onto image hotspots
133
- registry.register('graphicGapMatchInteraction', {
70
+ },
71
+ graphicGapMatchInteraction: {
134
72
  name: 'default-graphic-gap-match',
135
- priority: 0,
136
73
  description: 'Default Svelte-based graphic gap match interaction',
137
- canHandle: () => true,
138
74
  tagName: 'pie-qti-graphic-gap-match',
139
- });
140
- // GraphicOrderInteraction - Order items with graphic reference
141
- registry.register('graphicOrderInteraction', {
75
+ },
76
+ graphicOrderInteraction: {
142
77
  name: 'default-graphic-order',
143
- priority: 0,
144
78
  description: 'Default Svelte-based graphic order interaction',
145
- canHandle: () => true,
146
79
  tagName: 'pie-qti-graphic-order',
147
- });
148
- // GraphicAssociateInteraction - Create associations on image
149
- registry.register('graphicAssociateInteraction', {
80
+ },
81
+ graphicAssociateInteraction: {
150
82
  name: 'default-graphic-associate',
151
- priority: 0,
152
83
  description: 'Default Svelte-based graphic associate interaction',
153
- canHandle: () => true,
154
84
  tagName: 'pie-qti-graphic-associate',
155
- });
156
- // SelectPointInteraction - Select points on image
157
- registry.register('selectPointInteraction', {
85
+ },
86
+ selectPointInteraction: {
158
87
  name: 'default-select-point',
159
- priority: 0,
160
88
  description: 'Default Svelte-based select point interaction',
161
- canHandle: () => true,
162
89
  tagName: 'pie-qti-select-point',
163
- });
164
- // ExtendedTextInteraction - Rich text editor
165
- registry.register('extendedTextInteraction', {
90
+ },
91
+ extendedTextInteraction: {
166
92
  name: 'default-extended-text',
167
- priority: 0,
168
93
  description: 'Default Svelte-based extended text interaction',
169
- canHandle: () => true,
170
94
  tagName: 'pie-qti-extended-text',
171
- });
172
- // UploadInteraction - File upload
173
- registry.register('uploadInteraction', {
95
+ },
96
+ uploadInteraction: {
174
97
  name: 'default-upload',
175
- priority: 0,
176
98
  description: 'Default Svelte-based upload interaction',
177
- canHandle: () => true,
178
99
  tagName: 'pie-qti-upload',
179
- });
180
- // DrawingInteraction - Canvas drawing
181
- registry.register('drawingInteraction', {
100
+ },
101
+ drawingInteraction: {
182
102
  name: 'default-drawing',
183
- priority: 0,
184
103
  description: 'Default Svelte-based drawing interaction',
185
- canHandle: () => true,
186
104
  tagName: 'pie-qti-drawing',
187
- });
188
- // Note: TextEntryInteraction and InlineChoiceInteraction are handled
189
- // by ItemRenderer as inline interactions, not as separate components
190
- // CatalogPopup - focus-trapped dialog for glossary/keyword-translation entries
105
+ },
106
+ };
107
+ export function getDefaultComponentTypes() {
108
+ return Object.keys(DEFAULT_COMPONENTS_BY_TYPE);
109
+ }
110
+ /**
111
+ * Register all default components with the ComponentRegistry.
112
+ *
113
+ * This function should be called once at application startup to make all default
114
+ * block interaction components available to the player. Inline interactions are
115
+ * rendered in-flow by @pie-qti/item-player.
116
+ */
117
+ export function registerDefaultComponents(registry) {
118
+ for (const [type, component] of Object.entries(DEFAULT_COMPONENTS_BY_TYPE)) {
119
+ registry.register(type, component);
120
+ }
191
121
  registry.register('catalogPopup', {
192
122
  name: 'default-catalog-popup',
193
- priority: 0,
194
123
  description: 'Default Svelte-based catalog popup dialog',
195
- canHandle: () => true,
196
124
  tagName: 'pie-qti-catalog-popup',
197
125
  });
198
126
  }
@@ -1,5 +1,8 @@
1
1
  import type { QTIChangeEventDetail } from '@pie-qti/item-player/web-components';
2
- export declare function createQtiChangeEvent(responseId: string | undefined, value: unknown): CustomEvent<QTIChangeEventDetail>;
2
+ type TypedQtiChangeEventDetail<TValue> = Omit<QTIChangeEventDetail, 'value'> & {
3
+ value: TValue;
4
+ };
5
+ export declare function createQtiChangeEvent<TValue = unknown>(responseId: string | undefined, value: TValue): CustomEvent<TypedQtiChangeEventDetail<TValue>>;
3
6
  /**
4
7
  * Emits a QTI change event from an element
5
8
  * @param element - The element to dispatch from (usually component root)
@@ -7,4 +10,5 @@ export declare function createQtiChangeEvent(responseId: string | undefined, val
7
10
  * @param value - The response value
8
11
  */
9
12
  export declare function emitQtiChange(element: HTMLElement | EventTarget, responseId: string | undefined, value: unknown): void;
13
+ export {};
10
14
  //# sourceMappingURL=eventHelpers.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"eventHelpers.d.ts","sourceRoot":"","sources":["../../../src/shared/utils/eventHelpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,qCAAqC,CAAC;AAmBhF,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,MAAM,GAAG,SAAS,EAAE,KAAK,EAAE,OAAO,GAAG,WAAW,CAAC,oBAAoB,CAAC,CAUtH;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAC5B,OAAO,EAAE,WAAW,GAAG,WAAW,EAClC,UAAU,EAAE,MAAM,GAAG,SAAS,EAC9B,KAAK,EAAE,OAAO,GACZ,IAAI,CAGN"}
1
+ {"version":3,"file":"eventHelpers.d.ts","sourceRoot":"","sources":["../../../src/shared/utils/eventHelpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,qCAAqC,CAAC;AAmBhF,KAAK,yBAAyB,CAAC,MAAM,IAAI,IAAI,CAAC,oBAAoB,EAAE,OAAO,CAAC,GAAG;IAC9E,KAAK,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,wBAAgB,oBAAoB,CAAC,MAAM,GAAG,OAAO,EACpD,UAAU,EAAE,MAAM,GAAG,SAAS,EAC9B,KAAK,EAAE,MAAM,GACX,WAAW,CAAC,yBAAyB,CAAC,MAAM,CAAC,CAAC,CAUhD;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAC5B,OAAO,EAAE,WAAW,GAAG,WAAW,EAClC,UAAU,EAAE,MAAM,GAAG,SAAS,EAC9B,KAAK,EAAE,OAAO,GACZ,IAAI,CAGN"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pie-qti/default-components",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "description": "Default Svelte-based component implementations for QTI (2.x and 3.0) player",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -27,9 +27,9 @@
27
27
  ],
28
28
  "license": "MIT",
29
29
  "dependencies": {
30
- "@pie-qti/i18n": "0.1.5",
31
- "@pie-qti/item-player": "0.1.5",
32
- "@pie-qti/qti-common": "0.1.5",
30
+ "@pie-qti/i18n": "0.1.6",
31
+ "@pie-qti/item-player": "0.1.6",
32
+ "@pie-qti/qti-common": "0.1.6",
33
33
  "@tiptap/core": "^3.15.3",
34
34
  "@tiptap/extension-mathematics": "^3.15.3",
35
35
  "@tiptap/extension-placeholder": "^3.15.3",
@@ -74,6 +74,7 @@
74
74
  role="dialog"
75
75
  aria-label={label}
76
76
  aria-modal="true"
77
+ tabindex="-1"
77
78
  class="qti-catalog-popup"
78
79
  onkeydown={handleKeyDown}
79
80
  >
package/src/index.ts CHANGED
@@ -6,217 +6,136 @@
6
6
  * framework-agnostic @pie-qti/item-player core.
7
7
  */
8
8
 
9
- import type { ComponentRegistry } from '@pie-qti/item-player';
10
-
11
9
  // Export shared utilities and helpers
12
10
  export * from './shared/index.js';
13
11
 
14
- /**
15
- * Register all default components with the ComponentRegistry
16
- *
17
- * This function should be called once at application startup to make
18
- * all default interaction components available to the player.
19
- *
20
- * IMPORTANT: Before calling this function, you MUST import the plugin loader:
21
- * ```typescript
22
- * import '@pie-qti/default-components/plugins';
23
- * ```
24
- * This import triggers web component registration via Svelte's customElement option.
25
- *
26
- * @param registry - The ComponentRegistry instance from the Player
27
- *
28
- * @example
29
- * ```typescript
30
- * import { Player } from '@pie-qti/item-player';
31
- * import '@pie-qti/default-components/plugins'; // Load web components
32
- * import { registerDefaultComponents } from '@pie-qti/default-components';
33
- *
34
- * const player = new Player(qtiXml);
35
- * registerDefaultComponents(player.getComponentRegistry());
36
- * ```
37
- */
38
- export function registerDefaultComponents(registry: ComponentRegistry): void {
39
- // ChoiceInteraction - Radio buttons or checkboxes
40
- registry.register('choiceInteraction', {
12
+ interface DefaultComponentRegistration {
13
+ name: string;
14
+ description: string;
15
+ tagName: string;
16
+ }
17
+
18
+ interface DefaultComponentRegistry {
19
+ register(type: string, component: DefaultComponentRegistration): void;
20
+ }
21
+
22
+ const DEFAULT_COMPONENTS_BY_TYPE = {
23
+ choiceInteraction: {
41
24
  name: 'default-choice',
42
- priority: 0,
43
25
  description: 'Default Svelte-based choice interaction',
44
- canHandle: () => true,
45
26
  tagName: 'pie-qti-choice',
46
- // No componentClass needed - Svelte already registered it
47
- });
48
-
49
- // SliderInteraction - Range slider
50
- registry.register('sliderInteraction', {
27
+ },
28
+ sliderInteraction: {
51
29
  name: 'default-slider',
52
- priority: 0,
53
30
  description: 'Default Svelte-based slider interaction',
54
- canHandle: () => true,
55
31
  tagName: 'pie-qti-slider',
56
- });
57
-
58
- // OrderInteraction - Sortable list
59
- registry.register('orderInteraction', {
32
+ },
33
+ orderInteraction: {
60
34
  name: 'default-order',
61
- priority: 0,
62
35
  description: 'Default Svelte-based order interaction',
63
- canHandle: () => true,
64
36
  tagName: 'pie-qti-order',
65
- });
66
-
67
- // MatchInteraction - Match source to target
68
- registry.register('matchInteraction', {
37
+ },
38
+ matchInteraction: {
69
39
  name: 'default-match',
70
- priority: 0,
71
40
  description: 'Default Svelte-based match interaction',
72
- canHandle: () => true,
73
41
  tagName: 'pie-qti-match',
74
- });
75
-
76
- // AssociateInteraction - Create associations between choices
77
- registry.register('associateInteraction', {
42
+ },
43
+ associateInteraction: {
78
44
  name: 'default-associate',
79
- priority: 0,
80
45
  description: 'Default Svelte-based associate interaction',
81
- canHandle: () => true,
82
46
  tagName: 'pie-qti-associate',
83
- });
84
-
85
- // GapMatchInteraction - Fill gaps with words
86
- registry.register('gapMatchInteraction', {
47
+ },
48
+ gapMatchInteraction: {
87
49
  name: 'default-gap-match',
88
- priority: 0,
89
50
  description: 'Default Svelte-based gap match interaction',
90
- canHandle: () => true,
91
51
  tagName: 'pie-qti-gap-match',
92
- });
93
-
94
- // HotspotInteraction - Click on image hotspots
95
- registry.register('hotspotInteraction', {
52
+ },
53
+ hotspotInteraction: {
96
54
  name: 'default-hotspot',
97
- priority: 0,
98
55
  description: 'Default Svelte-based hotspot interaction',
99
- canHandle: () => true,
100
56
  tagName: 'pie-qti-hotspot',
101
- });
102
-
103
- // HottextInteraction - Select text within content
104
- registry.register('hottextInteraction', {
57
+ },
58
+ hottextInteraction: {
105
59
  name: 'default-hottext',
106
- priority: 0,
107
60
  description: 'Default Svelte-based hottext interaction',
108
- canHandle: () => true,
109
61
  tagName: 'pie-qti-hottext',
110
- });
111
-
112
- // MediaInteraction - Audio/video playback with tracking
113
- registry.register('mediaInteraction', {
62
+ },
63
+ mediaInteraction: {
114
64
  name: 'default-media',
115
- priority: 0,
116
65
  description: 'Default Svelte-based media interaction',
117
- canHandle: () => true,
118
66
  tagName: 'pie-qti-media',
119
- });
120
-
121
- // CustomInteraction - Fallback for custom interactions
122
- registry.register('customInteraction', {
67
+ },
68
+ customInteraction: {
123
69
  name: 'default-custom',
124
- priority: 0,
125
70
  description: 'Default Svelte-based custom interaction',
126
- canHandle: () => true,
127
71
  tagName: 'pie-qti-custom',
128
- });
129
-
130
- // EndAttemptInteraction - End attempt button
131
- registry.register('endAttemptInteraction', {
72
+ },
73
+ endAttemptInteraction: {
132
74
  name: 'default-end-attempt',
133
- priority: 0,
134
75
  description: 'Default Svelte-based end attempt interaction',
135
- canHandle: () => true,
136
76
  tagName: 'pie-qti-end-attempt',
137
- });
138
-
139
- // PositionObjectInteraction - Drag objects onto canvas
140
- registry.register('positionObjectInteraction', {
77
+ },
78
+ positionObjectInteraction: {
141
79
  name: 'default-position-object',
142
- priority: 0,
143
80
  description: 'Default Svelte-based position object interaction',
144
- canHandle: () => true,
145
81
  tagName: 'pie-qti-position-object',
146
- });
147
-
148
- // GraphicGapMatchInteraction - Drag labels onto image hotspots
149
- registry.register('graphicGapMatchInteraction', {
82
+ },
83
+ graphicGapMatchInteraction: {
150
84
  name: 'default-graphic-gap-match',
151
- priority: 0,
152
85
  description: 'Default Svelte-based graphic gap match interaction',
153
- canHandle: () => true,
154
86
  tagName: 'pie-qti-graphic-gap-match',
155
- });
156
-
157
- // GraphicOrderInteraction - Order items with graphic reference
158
- registry.register('graphicOrderInteraction', {
87
+ },
88
+ graphicOrderInteraction: {
159
89
  name: 'default-graphic-order',
160
- priority: 0,
161
90
  description: 'Default Svelte-based graphic order interaction',
162
- canHandle: () => true,
163
91
  tagName: 'pie-qti-graphic-order',
164
- });
165
-
166
- // GraphicAssociateInteraction - Create associations on image
167
- registry.register('graphicAssociateInteraction', {
92
+ },
93
+ graphicAssociateInteraction: {
168
94
  name: 'default-graphic-associate',
169
- priority: 0,
170
95
  description: 'Default Svelte-based graphic associate interaction',
171
- canHandle: () => true,
172
96
  tagName: 'pie-qti-graphic-associate',
173
- });
174
-
175
- // SelectPointInteraction - Select points on image
176
- registry.register('selectPointInteraction', {
97
+ },
98
+ selectPointInteraction: {
177
99
  name: 'default-select-point',
178
- priority: 0,
179
100
  description: 'Default Svelte-based select point interaction',
180
- canHandle: () => true,
181
101
  tagName: 'pie-qti-select-point',
182
- });
183
-
184
- // ExtendedTextInteraction - Rich text editor
185
- registry.register('extendedTextInteraction', {
102
+ },
103
+ extendedTextInteraction: {
186
104
  name: 'default-extended-text',
187
- priority: 0,
188
105
  description: 'Default Svelte-based extended text interaction',
189
- canHandle: () => true,
190
106
  tagName: 'pie-qti-extended-text',
191
- });
192
-
193
- // UploadInteraction - File upload
194
- registry.register('uploadInteraction', {
107
+ },
108
+ uploadInteraction: {
195
109
  name: 'default-upload',
196
- priority: 0,
197
110
  description: 'Default Svelte-based upload interaction',
198
- canHandle: () => true,
199
111
  tagName: 'pie-qti-upload',
200
- });
201
-
202
- // DrawingInteraction - Canvas drawing
203
- registry.register('drawingInteraction', {
112
+ },
113
+ drawingInteraction: {
204
114
  name: 'default-drawing',
205
- priority: 0,
206
115
  description: 'Default Svelte-based drawing interaction',
207
- canHandle: () => true,
208
116
  tagName: 'pie-qti-drawing',
209
- });
117
+ },
118
+ } satisfies Record<string, DefaultComponentRegistration>;
119
+
120
+ export function getDefaultComponentTypes(): string[] {
121
+ return Object.keys(DEFAULT_COMPONENTS_BY_TYPE);
122
+ }
210
123
 
211
- // Note: TextEntryInteraction and InlineChoiceInteraction are handled
212
- // by ItemRenderer as inline interactions, not as separate components
124
+ /**
125
+ * Register all default components with the ComponentRegistry.
126
+ *
127
+ * This function should be called once at application startup to make all default
128
+ * block interaction components available to the player. Inline interactions are
129
+ * rendered in-flow by @pie-qti/item-player.
130
+ */
131
+ export function registerDefaultComponents(registry: DefaultComponentRegistry): void {
132
+ for (const [type, component] of Object.entries(DEFAULT_COMPONENTS_BY_TYPE)) {
133
+ registry.register(type, component);
134
+ }
213
135
 
214
- // CatalogPopup - focus-trapped dialog for glossary/keyword-translation entries
215
136
  registry.register('catalogPopup', {
216
137
  name: 'default-catalog-popup',
217
- priority: 0,
218
138
  description: 'Default Svelte-based catalog popup dialog',
219
- canHandle: () => true,
220
139
  tagName: 'pie-qti-catalog-popup',
221
140
  });
222
141
  }
@@ -46,6 +46,7 @@
46
46
 
47
47
  // Ensure response is always an array
48
48
  const pairs = $derived(parsedResponse || []);
49
+ const helperId = $derived(`associate-helper-${parsedInteraction?.responseId ?? 'unknown'}`);
49
50
 
50
51
  function emitChange(newPairs: string[]) {
51
52
  response = newPairs;
@@ -127,6 +128,19 @@
127
128
  );
128
129
  }
129
130
 
131
+ function toPlainText(html: string): string {
132
+ return html.replace(/<[^>]*>/g, ' ').replace(/\s+/g, ' ').trim();
133
+ }
134
+
135
+ function getChoiceLabel(choice: { identifier: string; text: string }): string {
136
+ const text = toPlainText(choice.text);
137
+ return text ? `${choice.identifier}: ${text}` : choice.identifier;
138
+ }
139
+
140
+ function getPairLabel(choice1: { identifier: string; text: string }, choice2: { identifier: string; text: string }): string {
141
+ return `${getChoiceLabel(choice1)} and ${getChoiceLabel(choice2)}`;
142
+ }
143
+
130
144
  const correctPairs = $derived(
131
145
  isShowingCorrect && parsedCorrectResponse ? parsedCorrectResponse : []
132
146
  );
@@ -154,7 +168,11 @@
154
168
  class="btn btn-outline {isSelected ? 'btn-accent' : inPair ? 'btn-primary' : isCorrect ? 'btn-success' : 'btn-neutral'}"
155
169
  class:opacity-40={isBlocked}
156
170
  class:cursor-not-allowed={isBlocked}
171
+ type="button"
172
+ aria-label={getChoiceLabel(choice)}
173
+ aria-pressed={isSelected}
157
174
  aria-disabled={isBlocked ? 'true' : undefined}
175
+ aria-describedby={helperId}
158
176
  onclick={() => handleChoiceClick(choice.identifier)}
159
177
  {disabled}
160
178
  >
@@ -225,6 +243,8 @@
225
243
  <button
226
244
  part="pair-remove"
227
245
  class="btn btn-sm btn-ghost btn-circle"
246
+ type="button"
247
+ aria-label={`Remove association between ${getPairLabel(choice1, choice2)}`}
228
248
  onclick={() => removePair(index)}
229
249
  {disabled}
230
250
  >
@@ -238,14 +258,14 @@
238
258
 
239
259
  <!-- Selection helper - Hide when showing correct answers -->
240
260
  {#if !isShowingCorrect}
241
- <div part="helper" class="qti-associate-helper alert alert-info">
261
+ <div id={helperId} part="helper" class="qti-associate-helper alert alert-info" role="status" aria-live="polite">
242
262
  <span class="text-sm">
243
263
  {#if selectedForPairing}
244
264
  {i18n?.t('interactions.associate.clickAnotherOrDeselect') ??
245
- 'Click another item to create an association (or click again to deselect)'}
265
+ 'Select another item to create an association, or select this item again to deselect it.'}
246
266
  {:else}
247
267
  {i18n?.t('interactions.associate.clickToAssociate') ??
248
- 'Click two items to create an association between them'}
268
+ 'Select two items to create an association between them. Keyboard users can tab to each item and press Enter or Space.'}
249
269
  {/if}
250
270
  </span>
251
271
  </div>
@@ -43,6 +43,7 @@
43
43
  * Check if the minimum play requirement has been met
44
44
  */
45
45
  const hasMetMinPlays = $derived(parsedInteraction && playCount >= parsedInteraction.minPlays);
46
+ const mediaLabel = $derived(i18n?.t('interactions.media.ariaLabel') ?? 'Media content');
46
47
 
47
48
  /**
48
49
  * Handle media ended event.
@@ -99,6 +100,7 @@
99
100
  bind:this={mediaElement}
100
101
  class="w-full"
101
102
  controls
103
+ aria-label={mediaLabel}
102
104
  autoplay={parsedInteraction.autostart}
103
105
  loop={parsedInteraction.loop && parsedInteraction.maxPlays === 0}
104
106
  onended={handleEnded}
@@ -112,6 +114,7 @@
112
114
  bind:this={mediaElement}
113
115
  class="w-full rounded-lg"
114
116
  controls
117
+ aria-label={mediaLabel}
115
118
  autoplay={parsedInteraction.autostart}
116
119
  loop={parsedInteraction.loop && parsedInteraction.maxPlays === 0}
117
120
  width={parsedInteraction.mediaElement.width}
@@ -136,7 +139,7 @@
136
139
  {/if}
137
140
  </div>
138
141
 
139
- <div class="qti-media-stats flex items-center justify-between text-sm text-base-content/70" part="stats">
142
+ <div class="qti-media-stats flex items-center justify-between text-sm text-base-content/70" part="stats" role="status" aria-live="polite">
140
143
  <div>
141
144
  <span class="font-medium">Play count:</span>
142
145
  <span class="ml-2">{playCount}</span>
@@ -163,7 +166,7 @@
163
166
  </div>
164
167
 
165
168
  {#if hasReachedMaxPlays}
166
- <div class="alert alert-info">
169
+ <div class="alert alert-info" role="status" aria-live="polite">
167
170
  <svg
168
171
  xmlns="http://www.w3.org/2000/svg"
169
172
  fill="none"
@@ -51,6 +51,9 @@
51
51
  let error = $state<string>('');
52
52
 
53
53
  const acceptAttr = $derived(fileTypes.length > 0 ? fileTypes.join(',') : undefined);
54
+ const allowedTypesId = $derived(fileTypes.length > 0 ? `upload-${responseId}-allowed-types` : undefined);
55
+ const errorId = $derived(error ? `upload-${responseId}-error` : undefined);
56
+ const describedBy = $derived([allowedTypesId, errorId].filter(Boolean).join(' ') || undefined);
54
57
 
55
58
  async function fileToResponse(file: File): Promise<QTIFileResponse> {
56
59
  const dataUrl = await new Promise<string>((resolve, reject) => {
@@ -118,18 +121,20 @@
118
121
  class="file-input file-input-bordered w-full"
119
122
  type="file"
120
123
  accept={acceptAttr}
124
+ aria-describedby={describedBy}
125
+ aria-invalid={error ? 'true' : undefined}
121
126
  disabled={disabled}
122
127
  onchange={handleFileChange}
123
128
  />
124
129
 
125
130
  {#if fileTypes.length > 0}
126
- <div class="text-xs text-base-content/70">
131
+ <div id={allowedTypesId} class="text-xs text-base-content/70">
127
132
  {translations.allowedTypes} {fileTypes.join(', ')}
128
133
  </div>
129
134
  {/if}
130
135
 
131
136
  {#if error}
132
- <div class="alert alert-error py-2">
137
+ <div id={errorId} class="alert alert-error py-2" role="alert" aria-live="assertive">
133
138
  <span class="text-sm">{error}</span>
134
139
  </div>
135
140
  {/if}
@@ -3,11 +3,23 @@
3
3
  * Component to render HTML with inline interactive elements (textEntry, inlineChoice)
4
4
  * Uses a custom parsing approach to embed Svelte components within HTML
5
5
  */
6
+ interface InlineRendererInteraction {
7
+ responseId: string;
8
+ interactionClasses?: string[];
9
+ expectedLength?: number;
10
+ placeholderText?: string | null;
11
+ dataPrompt?: string | null;
12
+ label?: string | null;
13
+ choices?: Array<{ identifier: string; text: string }>;
14
+ }
15
+
16
+ type InlineResponseMap = Record<string, string | null>;
17
+
6
18
  interface Props {
7
19
  html: string;
8
- interactions: any[];
9
- responses: Record<string, any>;
10
- onResponseChange: (responseId: string, value: any) => void;
20
+ interactions: InlineRendererInteraction[];
21
+ responses: InlineResponseMap;
22
+ onResponseChange: (responseId: string, value: string) => void;
11
23
  }
12
24
 
13
25
  let { html, interactions, responses, onResponseChange }: Props = $props();
@@ -16,7 +28,7 @@ let { html, interactions, responses, onResponseChange }: Props = $props();
16
28
  interface ParsedSegment {
17
29
  type: 'html' | 'textEntry' | 'inlineChoice';
18
30
  content?: string;
19
- interaction?: any;
31
+ interaction?: InlineRendererInteraction;
20
32
  }
21
33
 
22
34
  const segments = $derived.by(() => {
@@ -109,7 +121,7 @@ const segments = $derived.by(() => {
109
121
  onchange={(e) => onResponseChange(segment.interaction.responseId, e.currentTarget.value)}
110
122
  >
111
123
  <option value="" disabled>{placeholder}</option>
112
- {#each segment.interaction.choices as choice}
124
+ {#each segment.interaction.choices ?? [] as choice}
113
125
  <option value={choice.identifier}>{choice.text}</option>
114
126
  {/each}
115
127
  </select>
@@ -1,7 +1,7 @@
1
1
  <script lang="ts">
2
2
  import type { ModalFeedback } from '@pie-qti/item-player';
3
3
  import type { I18nProvider } from '@pie-qti/i18n';
4
- import { typesetAction } from './actions/typesetAction';
4
+ import { typesetAction } from '../actions/typesetAction';
5
5
 
6
6
  interface Props {
7
7
  feedback: ModalFeedback[];
@@ -14,6 +14,8 @@
14
14
 
15
15
  // Show modal if there's feedback
16
16
  const hasActiveFeedback = $derived(feedback.length > 0);
17
+ const modalTitleId = 'modal-feedback-title';
18
+ const firstTitle = $derived(feedback.find((item) => item.title)?.title);
17
19
 
18
20
  function handleClose() {
19
21
  onClose?.();
@@ -29,11 +31,19 @@
29
31
 
30
32
  {#if hasActiveFeedback}
31
33
  <!-- DaisyUI Modal -->
32
- <dialog class="modal modal-open" onclick={handleBackdropClick}>
34
+ <dialog
35
+ open
36
+ class="modal modal-open"
37
+ aria-modal="true"
38
+ aria-labelledby={firstTitle ? modalTitleId : undefined}
39
+ aria-label={firstTitle ? undefined : (i18n?.t('feedback.title') ?? 'Feedback')}
40
+ onclick={handleBackdropClick}
41
+ >
33
42
  <div class="modal-box max-w-3xl">
34
43
  <!-- Close button -->
35
44
  <button
36
45
  class="btn btn-sm btn-circle btn-ghost absolute right-2 top-2"
46
+ type="button"
37
47
  onclick={handleClose}
38
48
  aria-label={i18n?.t('feedback.close') ?? 'Close feedback'}
39
49
  >
@@ -44,13 +54,13 @@
44
54
  {#each feedback as item, index}
45
55
  <div class="mb-4 {index < feedback.length - 1 ? 'border-b pb-4' : ''}">
46
56
  {#if item.title}
47
- <h3 class="font-bold text-lg mb-2">{item.title}</h3>
57
+ <h3 id={index === 0 ? modalTitleId : undefined} class="font-bold text-lg mb-2">{item.title}</h3>
48
58
  {/if}
49
59
 
50
60
  <!-- Render HTML content with MathJax support -->
51
61
  <div
52
62
  class="prose max-w-none"
53
- use:typesetAction={typeset}
63
+ use:typesetAction={{ typeset }}
54
64
  >
55
65
  {@html item.content}
56
66
  </div>
@@ -59,7 +69,7 @@
59
69
 
60
70
  <!-- Action buttons -->
61
71
  <div class="modal-action">
62
- <button class="btn btn-primary" onclick={handleClose}>
72
+ <button class="btn btn-primary" type="button" onclick={handleClose}>
63
73
  Continue
64
74
  </button>
65
75
  </div>
@@ -17,7 +17,14 @@ function requireResponseId(responseId: string | undefined): string {
17
17
  return responseId;
18
18
  }
19
19
 
20
- export function createQtiChangeEvent(responseId: string | undefined, value: unknown): CustomEvent<QTIChangeEventDetail> {
20
+ type TypedQtiChangeEventDetail<TValue> = Omit<QTIChangeEventDetail, 'value'> & {
21
+ value: TValue;
22
+ };
23
+
24
+ export function createQtiChangeEvent<TValue = unknown>(
25
+ responseId: string | undefined,
26
+ value: TValue
27
+ ): CustomEvent<TypedQtiChangeEventDetail<TValue>> {
21
28
  return new CustomEvent('qti-change', {
22
29
  detail: {
23
30
  responseId: requireResponseId(responseId),