@pie-qti/default-components 0.1.9 → 0.1.10
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/plugins.js +4219 -4178
- package/dist/plugins.js.map +1 -1
- package/dist/shared/index.d.ts +0 -1
- package/dist/shared/index.d.ts.map +1 -1
- package/dist/shared/index.js +0 -2
- package/dist/shared/utils/eventHelpers.d.ts +6 -0
- package/dist/shared/utils/eventHelpers.d.ts.map +1 -1
- package/dist/shared/utils/eventHelpers.js +6 -0
- package/dist/shared/utils/webComponentHelpers.d.ts +16 -0
- package/dist/shared/utils/webComponentHelpers.d.ts.map +1 -1
- package/dist/shared/utils/webComponentHelpers.js +12 -0
- package/package.json +4 -4
- package/src/plugins/associate/AssociateInteraction.svelte +15 -21
- package/src/plugins/choice/ChoiceInteraction.svelte +16 -19
- package/src/plugins/extended-text/ExtendedTextInteraction.svelte +15 -13
- package/src/plugins/graphic-gap-match/GraphicGapMatchInteraction.svelte +1 -1
- package/src/shared/components/GraphicGapMatch.svelte +1 -1
- package/src/shared/components/MatchDragDrop.svelte +1 -1
- package/src/shared/components/SortableList.svelte +1 -1
- package/src/shared/index.ts +0 -2
- package/src/shared/utils/eventHelpers.ts +17 -0
- package/src/shared/utils/webComponentHelpers.ts +42 -0
- package/src/shared/utils/touchDragHelper.ts +0 -1
package/dist/shared/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/shared/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,cAAc,4BAA4B,CAAC;AAE3C,cAAc,gCAAgC,CAAC;AAE/C,cAAc,yBAAyB,CAAC;AAExC,cAAc,wBAAwB,CAAC
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/shared/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,cAAc,4BAA4B,CAAC;AAE3C,cAAc,gCAAgC,CAAC;AAE/C,cAAc,yBAAyB,CAAC;AAExC,cAAc,wBAAwB,CAAC"}
|
package/dist/shared/index.js
CHANGED
|
@@ -11,5 +11,3 @@ export * from './extensions/MathLiveEditor.js';
|
|
|
11
11
|
export * from './utils/eventHelpers.js';
|
|
12
12
|
// Pair helpers for matching/association interactions
|
|
13
13
|
export * from './utils/pairHelpers.js';
|
|
14
|
-
// Touch drag helper for mobile-friendly drag-and-drop
|
|
15
|
-
export * from './utils/touchDragHelper.js';
|
|
@@ -10,5 +10,11 @@ export declare function createQtiChangeEvent<TValue = unknown>(responseId: strin
|
|
|
10
10
|
* @param value - The response value
|
|
11
11
|
*/
|
|
12
12
|
export declare function emitQtiChange(element: HTMLElement | EventTarget, responseId: string | undefined, value: unknown): void;
|
|
13
|
+
export declare function emitInteractionChange<TValue>({ target, responseId, value, onChange, }: {
|
|
14
|
+
target: HTMLElement | EventTarget | undefined;
|
|
15
|
+
responseId: string | undefined;
|
|
16
|
+
value: TValue;
|
|
17
|
+
onChange?: (value: TValue) => void;
|
|
18
|
+
}): void;
|
|
13
19
|
export {};
|
|
14
20
|
//# 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,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"}
|
|
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;AAED,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,EAC7C,MAAM,EACN,UAAU,EACV,KAAK,EACL,QAAQ,GACR,EAAE;IACF,MAAM,EAAE,WAAW,GAAG,WAAW,GAAG,SAAS,CAAC;IAC9C,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/B,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CACnC,GAAG,IAAI,CAKP"}
|
|
@@ -34,3 +34,9 @@ export function emitQtiChange(element, responseId, value) {
|
|
|
34
34
|
const event = createQtiChangeEvent(responseId, value);
|
|
35
35
|
element.dispatchEvent(event);
|
|
36
36
|
}
|
|
37
|
+
export function emitInteractionChange({ target, responseId, value, onChange, }) {
|
|
38
|
+
onChange?.(value);
|
|
39
|
+
if (target) {
|
|
40
|
+
emitQtiChange(target, responseId, value);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -6,4 +6,20 @@
|
|
|
6
6
|
* Used when components are used as web components and receive JSON strings
|
|
7
7
|
*/
|
|
8
8
|
export declare function parseJsonProp<T>(prop: T | string | null | undefined): T | undefined;
|
|
9
|
+
export interface InteractionShellProps<TInteraction, TResponse, TCorrectResponse = TResponse> {
|
|
10
|
+
interaction?: TInteraction | string;
|
|
11
|
+
response?: TResponse | string | null;
|
|
12
|
+
correctResponse?: TCorrectResponse | string | null;
|
|
13
|
+
role?: string;
|
|
14
|
+
}
|
|
15
|
+
export interface InteractionShell<TInteraction, TResponse, TCorrectResponse = TResponse> {
|
|
16
|
+
interaction: TInteraction | undefined;
|
|
17
|
+
response: TResponse | undefined;
|
|
18
|
+
correctResponse: TCorrectResponse | undefined;
|
|
19
|
+
isShowingCorrect: boolean;
|
|
20
|
+
responseId: string | undefined;
|
|
21
|
+
}
|
|
22
|
+
export declare function createInteractionShell<TInteraction extends {
|
|
23
|
+
responseId?: string;
|
|
24
|
+
}, TResponse, TCorrectResponse = TResponse>({ interaction, response, correctResponse, role, }: InteractionShellProps<TInteraction, TResponse, TCorrectResponse>): InteractionShell<TInteraction, TResponse, TCorrectResponse>;
|
|
9
25
|
//# sourceMappingURL=webComponentHelpers.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webComponentHelpers.d.ts","sourceRoot":"","sources":["../../../src/shared/utils/webComponentHelpers.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;GAGG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,CAAC,GAAG,SAAS,CAkBnF"}
|
|
1
|
+
{"version":3,"file":"webComponentHelpers.d.ts","sourceRoot":"","sources":["../../../src/shared/utils/webComponentHelpers.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;GAGG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,CAAC,GAAG,SAAS,CAkBnF;AAED,MAAM,WAAW,qBAAqB,CAAC,YAAY,EAAE,SAAS,EAAE,gBAAgB,GAAG,SAAS;IAC3F,WAAW,CAAC,EAAE,YAAY,GAAG,MAAM,CAAC;IACpC,QAAQ,CAAC,EAAE,SAAS,GAAG,MAAM,GAAG,IAAI,CAAC;IACrC,eAAe,CAAC,EAAE,gBAAgB,GAAG,MAAM,GAAG,IAAI,CAAC;IACnD,IAAI,CAAC,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,gBAAgB,CAAC,YAAY,EAAE,SAAS,EAAE,gBAAgB,GAAG,SAAS;IACtF,WAAW,EAAE,YAAY,GAAG,SAAS,CAAC;IACtC,QAAQ,EAAE,SAAS,GAAG,SAAS,CAAC;IAChC,eAAe,EAAE,gBAAgB,GAAG,SAAS,CAAC;IAC9C,gBAAgB,EAAE,OAAO,CAAC;IAC1B,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;CAC/B;AAED,wBAAgB,sBAAsB,CACrC,YAAY,SAAS;IAAE,UAAU,CAAC,EAAE,MAAM,CAAA;CAAE,EAC5C,SAAS,EACT,gBAAgB,GAAG,SAAS,EAC3B,EACD,WAAW,EACX,QAAQ,EACR,eAAe,EACf,IAAkB,GAClB,EAAE,qBAAqB,CAAC,YAAY,EAAE,SAAS,EAAE,gBAAgB,CAAC,GAAG,gBAAgB,CACrF,YAAY,EACZ,SAAS,EACT,gBAAgB,CAChB,CAYA"}
|
|
@@ -24,3 +24,15 @@ export function parseJsonProp(prop) {
|
|
|
24
24
|
}
|
|
25
25
|
return prop;
|
|
26
26
|
}
|
|
27
|
+
export function createInteractionShell({ interaction, response, correctResponse, role = 'candidate', }) {
|
|
28
|
+
const parsedInteraction = parseJsonProp(interaction);
|
|
29
|
+
const parsedResponse = parseJsonProp(response);
|
|
30
|
+
const parsedCorrectResponse = parseJsonProp(correctResponse);
|
|
31
|
+
return {
|
|
32
|
+
interaction: parsedInteraction,
|
|
33
|
+
response: parsedResponse,
|
|
34
|
+
correctResponse: parsedCorrectResponse,
|
|
35
|
+
isShowingCorrect: role === 'scorer' && parsedCorrectResponse !== undefined,
|
|
36
|
+
responseId: parsedInteraction?.responseId,
|
|
37
|
+
};
|
|
38
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pie-qti/default-components",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.10",
|
|
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.
|
|
31
|
-
"@pie-qti/item-player": "0.1.
|
|
32
|
-
"@pie-qti/qti-common": "0.1.
|
|
30
|
+
"@pie-qti/i18n": "0.1.10",
|
|
31
|
+
"@pie-qti/item-player": "0.1.10",
|
|
32
|
+
"@pie-qti/qti-common": "0.1.10",
|
|
33
33
|
"@tiptap/core": "^3.15.3",
|
|
34
34
|
"@tiptap/extension-mathematics": "^3.15.3",
|
|
35
35
|
"@tiptap/extension-placeholder": "^3.15.3",
|
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
import type { AssociateInteractionData } from '@pie-qti/item-player';
|
|
5
5
|
import type { I18nProvider } from '@pie-qti/i18n';
|
|
6
6
|
import ShadowBaseStyles from '../../shared/components/ShadowBaseStyles.svelte';
|
|
7
|
-
import {
|
|
7
|
+
import { emitInteractionChange } from '../../shared/utils/eventHelpers';
|
|
8
|
+
import { createInteractionShell } from '../../shared/utils/webComponentHelpers';
|
|
8
9
|
import { isCompatibleMatchGroup } from '../../shared/utils/matchGroupUtils';
|
|
9
10
|
|
|
10
11
|
interface Props {
|
|
@@ -31,11 +32,18 @@
|
|
|
31
32
|
onChange,
|
|
32
33
|
}: Props = $props();
|
|
33
34
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
35
|
+
const shell = $derived(
|
|
36
|
+
createInteractionShell<AssociateInteractionData, string[], string[]>({
|
|
37
|
+
interaction,
|
|
38
|
+
response,
|
|
39
|
+
correctResponse,
|
|
40
|
+
role,
|
|
41
|
+
})
|
|
42
|
+
);
|
|
43
|
+
const parsedInteraction = $derived(shell.interaction);
|
|
44
|
+
const parsedResponse = $derived(shell.response);
|
|
45
|
+
const parsedCorrectResponse = $derived(shell.correctResponse);
|
|
46
|
+
const isShowingCorrect = $derived(shell.isShowingCorrect);
|
|
39
47
|
|
|
40
48
|
// Get reference to the root element for event dispatching
|
|
41
49
|
let rootElement: HTMLDivElement | undefined = $state();
|
|
@@ -50,21 +58,7 @@
|
|
|
50
58
|
|
|
51
59
|
function emitChange(newPairs: string[]) {
|
|
52
60
|
response = newPairs;
|
|
53
|
-
|
|
54
|
-
onChange?.(newPairs);
|
|
55
|
-
// Dispatch custom event for web component usage - event will bubble up to the host element
|
|
56
|
-
if (rootElement) {
|
|
57
|
-
const event = new CustomEvent('qti-change', {
|
|
58
|
-
detail: {
|
|
59
|
-
responseId: parsedInteraction?.responseId,
|
|
60
|
-
value: newPairs,
|
|
61
|
-
timestamp: Date.now(),
|
|
62
|
-
},
|
|
63
|
-
bubbles: true,
|
|
64
|
-
composed: true,
|
|
65
|
-
});
|
|
66
|
-
rootElement.dispatchEvent(event);
|
|
67
|
-
}
|
|
61
|
+
emitInteractionChange({ target: rootElement, responseId: shell.responseId, value: newPairs, onChange });
|
|
68
62
|
}
|
|
69
63
|
|
|
70
64
|
function setSelectedForPairing(value: string | null) {
|
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
import { processFeedbackInline } from '@pie-qti/item-player/components/utils';
|
|
8
8
|
import { typesetAction } from '../../shared/actions/typesetAction';
|
|
9
9
|
import ShadowBaseStyles from '../../shared/components/ShadowBaseStyles.svelte';
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
10
|
+
import { emitInteractionChange } from '../../shared/utils/eventHelpers';
|
|
11
|
+
import { createInteractionShell } from '../../shared/utils/webComponentHelpers';
|
|
12
12
|
|
|
13
13
|
interface Props {
|
|
14
14
|
interaction?: ChoiceInteractionData | string;
|
|
@@ -50,11 +50,18 @@
|
|
|
50
50
|
return !v || v === key ? fallback : v;
|
|
51
51
|
});
|
|
52
52
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
53
|
+
const shell = $derived(
|
|
54
|
+
createInteractionShell<ChoiceInteractionData, string | string[], string | string[]>({
|
|
55
|
+
interaction,
|
|
56
|
+
response,
|
|
57
|
+
correctResponse,
|
|
58
|
+
role,
|
|
59
|
+
})
|
|
60
|
+
);
|
|
61
|
+
const parsedInteraction = $derived(shell.interaction);
|
|
62
|
+
const parsedResponse = $derived(shell.response);
|
|
63
|
+
const parsedCorrectResponse = $derived(shell.correctResponse);
|
|
64
|
+
const isShowingCorrect = $derived(shell.isShowingCorrect);
|
|
58
65
|
|
|
59
66
|
// Helper function to check if a choice is correct
|
|
60
67
|
function isCorrectChoice(identifier: string): boolean {
|
|
@@ -101,12 +108,7 @@
|
|
|
101
108
|
|
|
102
109
|
function handleRadioChange(identifier: string) {
|
|
103
110
|
response = identifier;
|
|
104
|
-
|
|
105
|
-
onChange?.(identifier);
|
|
106
|
-
// Dispatch event for web component usage - event will bubble up to the host element
|
|
107
|
-
if (rootElement) {
|
|
108
|
-
rootElement.dispatchEvent(createQtiChangeEvent(parsedInteraction?.responseId, identifier));
|
|
109
|
-
}
|
|
111
|
+
emitInteractionChange({ target: rootElement, responseId: shell.responseId, value: identifier, onChange });
|
|
110
112
|
}
|
|
111
113
|
|
|
112
114
|
function handleCheckboxChange(identifier: string, checked: boolean) {
|
|
@@ -123,12 +125,7 @@
|
|
|
123
125
|
}
|
|
124
126
|
|
|
125
127
|
response = newValues;
|
|
126
|
-
|
|
127
|
-
onChange?.(newValues);
|
|
128
|
-
// Dispatch event for web component usage - event will bubble up to the host element
|
|
129
|
-
if (rootElement) {
|
|
130
|
-
rootElement.dispatchEvent(createQtiChangeEvent(parsedInteraction?.responseId, newValues));
|
|
131
|
-
}
|
|
128
|
+
emitInteractionChange({ target: rootElement, responseId: shell.responseId, value: newValues, onChange });
|
|
132
129
|
}
|
|
133
130
|
|
|
134
131
|
// Selection limit message: show max message when at/over limit; min message is for submit time
|
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
import RichTextEditor from '../../shared/components/RichTextEditor.svelte';
|
|
7
7
|
import { typesetAction } from '../../shared/actions/typesetAction';
|
|
8
8
|
import ShadowBaseStyles from '../../shared/components/ShadowBaseStyles.svelte';
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
9
|
+
import { emitInteractionChange } from '../../shared/utils/eventHelpers';
|
|
10
|
+
import { createInteractionShell } from '../../shared/utils/webComponentHelpers';
|
|
11
11
|
|
|
12
12
|
interface Props {
|
|
13
13
|
interaction?: ExtendedTextInteractionData | string;
|
|
@@ -22,23 +22,25 @@
|
|
|
22
22
|
|
|
23
23
|
let { interaction = $bindable(), response = $bindable(), correctResponse = $bindable(), disabled = false, role = 'candidate', i18n = $bindable(), typeset, onChange }: Props = $props();
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
const shell = $derived(
|
|
26
|
+
createInteractionShell<ExtendedTextInteractionData, string, string>({
|
|
27
|
+
interaction,
|
|
28
|
+
response,
|
|
29
|
+
correctResponse,
|
|
30
|
+
role,
|
|
31
|
+
})
|
|
32
|
+
);
|
|
33
|
+
const parsedInteraction = $derived(shell.interaction);
|
|
34
|
+
const parsedResponse = $derived(shell.response);
|
|
35
|
+
const parsedCorrectResponse = $derived(shell.correctResponse);
|
|
36
|
+
const isShowingCorrect = $derived(shell.isShowingCorrect);
|
|
30
37
|
|
|
31
38
|
// Get reference to the root element for event dispatching
|
|
32
39
|
let rootElement: HTMLDivElement | undefined = $state();
|
|
33
40
|
|
|
34
41
|
function handleChange(html: string) {
|
|
35
42
|
response = html;
|
|
36
|
-
|
|
37
|
-
onChange?.(html);
|
|
38
|
-
// Dispatch event for web component usage - event will bubble up to the host element
|
|
39
|
-
if (rootElement) {
|
|
40
|
-
rootElement.dispatchEvent(createQtiChangeEvent(parsedInteraction?.responseId, html));
|
|
41
|
-
}
|
|
43
|
+
emitInteractionChange({ target: rootElement, responseId: shell.responseId, value: html, onChange });
|
|
42
44
|
}
|
|
43
45
|
|
|
44
46
|
// Character counter support (qti-counter-down / qti-counter-up)
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
|
|
10
10
|
import type { GraphicGapMatchInteractionData } from '@pie-qti/item-player';
|
|
11
11
|
import type { I18nProvider } from '@pie-qti/i18n';
|
|
12
|
+
import { touchDrag } from '@pie-qti/qti-common';
|
|
12
13
|
import { createQtiChangeEvent } from '../../shared/utils/eventHelpers.js';
|
|
13
|
-
import { touchDrag } from '../../shared/utils/touchDragHelper.js';
|
|
14
14
|
import { parseJsonProp } from '../../shared/utils/webComponentHelpers';
|
|
15
15
|
|
|
16
16
|
import '../../shared/styles/shared.css';
|
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import type { I18nProvider } from '@pie-qti/i18n';
|
|
9
|
+
import { touchDrag } from '@pie-qti/qti-common';
|
|
9
10
|
import { createOrUpdatePair, getSourceForTarget, getTargetForSource, removePairBySource } from '../utils/pairHelpers.js';
|
|
10
|
-
import { touchDrag } from '../utils/touchDragHelper.js';
|
|
11
11
|
import '../styles/shared.css';
|
|
12
12
|
|
|
13
13
|
interface GapText {
|
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
|
|
8
8
|
import type { AssociableChoice } from '@pie-qti/item-player';
|
|
9
9
|
import type { I18nProvider } from '@pie-qti/i18n';
|
|
10
|
+
import { touchDrag } from '@pie-qti/qti-common';
|
|
10
11
|
import { createOrUpdatePair, getSourceForTarget, getTargetsForSource, removePairBySource } from '../utils/pairHelpers.js';
|
|
11
|
-
import { touchDrag } from '../utils/touchDragHelper.js';
|
|
12
12
|
import { isCompatibleMatchGroup } from '../utils/matchGroupUtils.js';
|
|
13
13
|
import DragHandle from './DragHandle.svelte';
|
|
14
14
|
import '../styles/shared.css';
|
package/src/shared/index.ts
CHANGED
|
@@ -13,5 +13,3 @@ export * from './extensions/MathLiveEditor.js';
|
|
|
13
13
|
export * from './utils/eventHelpers.js';
|
|
14
14
|
// Pair helpers for matching/association interactions
|
|
15
15
|
export * from './utils/pairHelpers.js';
|
|
16
|
-
// Touch drag helper for mobile-friendly drag-and-drop
|
|
17
|
-
export * from './utils/touchDragHelper.js';
|
|
@@ -50,3 +50,20 @@ export function emitQtiChange(
|
|
|
50
50
|
const event = createQtiChangeEvent(responseId, value);
|
|
51
51
|
element.dispatchEvent(event);
|
|
52
52
|
}
|
|
53
|
+
|
|
54
|
+
export function emitInteractionChange<TValue>({
|
|
55
|
+
target,
|
|
56
|
+
responseId,
|
|
57
|
+
value,
|
|
58
|
+
onChange,
|
|
59
|
+
}: {
|
|
60
|
+
target: HTMLElement | EventTarget | undefined;
|
|
61
|
+
responseId: string | undefined;
|
|
62
|
+
value: TValue;
|
|
63
|
+
onChange?: (value: TValue) => void;
|
|
64
|
+
}): void {
|
|
65
|
+
onChange?.(value);
|
|
66
|
+
if (target) {
|
|
67
|
+
emitQtiChange(target, responseId, value);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -25,3 +25,45 @@ export function parseJsonProp<T>(prop: T | string | null | undefined): T | undef
|
|
|
25
25
|
|
|
26
26
|
return prop as T;
|
|
27
27
|
}
|
|
28
|
+
|
|
29
|
+
export interface InteractionShellProps<TInteraction, TResponse, TCorrectResponse = TResponse> {
|
|
30
|
+
interaction?: TInteraction | string;
|
|
31
|
+
response?: TResponse | string | null;
|
|
32
|
+
correctResponse?: TCorrectResponse | string | null;
|
|
33
|
+
role?: string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface InteractionShell<TInteraction, TResponse, TCorrectResponse = TResponse> {
|
|
37
|
+
interaction: TInteraction | undefined;
|
|
38
|
+
response: TResponse | undefined;
|
|
39
|
+
correctResponse: TCorrectResponse | undefined;
|
|
40
|
+
isShowingCorrect: boolean;
|
|
41
|
+
responseId: string | undefined;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function createInteractionShell<
|
|
45
|
+
TInteraction extends { responseId?: string },
|
|
46
|
+
TResponse,
|
|
47
|
+
TCorrectResponse = TResponse,
|
|
48
|
+
>({
|
|
49
|
+
interaction,
|
|
50
|
+
response,
|
|
51
|
+
correctResponse,
|
|
52
|
+
role = 'candidate',
|
|
53
|
+
}: InteractionShellProps<TInteraction, TResponse, TCorrectResponse>): InteractionShell<
|
|
54
|
+
TInteraction,
|
|
55
|
+
TResponse,
|
|
56
|
+
TCorrectResponse
|
|
57
|
+
> {
|
|
58
|
+
const parsedInteraction = parseJsonProp<TInteraction>(interaction);
|
|
59
|
+
const parsedResponse = parseJsonProp<TResponse>(response);
|
|
60
|
+
const parsedCorrectResponse = parseJsonProp<TCorrectResponse>(correctResponse);
|
|
61
|
+
|
|
62
|
+
return {
|
|
63
|
+
interaction: parsedInteraction,
|
|
64
|
+
response: parsedResponse,
|
|
65
|
+
correctResponse: parsedCorrectResponse,
|
|
66
|
+
isShowingCorrect: role === 'scorer' && parsedCorrectResponse !== undefined,
|
|
67
|
+
responseId: parsedInteraction?.responseId,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { touchDrag, touchDragStyles } from '@pie-qti/qti-common';
|