@pie-qti/default-components 0.1.1
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/.turbo/turbo-build.log +1 -0
- package/CHANGELOG.md +9 -0
- package/STYLING.md +226 -0
- package/dist/index.d.ts +35 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +190 -0
- package/dist/plugins/associate/index.d.ts +8 -0
- package/dist/plugins/associate/index.d.ts.map +1 -0
- package/dist/plugins/associate/index.js +8 -0
- package/dist/plugins/choice/index.d.ts +8 -0
- package/dist/plugins/choice/index.d.ts.map +1 -0
- package/dist/plugins/choice/index.js +8 -0
- package/dist/plugins/custom/index.d.ts +8 -0
- package/dist/plugins/custom/index.d.ts.map +1 -0
- package/dist/plugins/custom/index.js +8 -0
- package/dist/plugins/end-attempt/index.d.ts +8 -0
- package/dist/plugins/end-attempt/index.d.ts.map +1 -0
- package/dist/plugins/end-attempt/index.js +8 -0
- package/dist/plugins/extended-text/index.d.ts +8 -0
- package/dist/plugins/extended-text/index.d.ts.map +1 -0
- package/dist/plugins/extended-text/index.js +8 -0
- package/dist/plugins/gap-match/index.d.ts +8 -0
- package/dist/plugins/gap-match/index.d.ts.map +1 -0
- package/dist/plugins/gap-match/index.js +8 -0
- package/dist/plugins/graphic-associate/index.d.ts +8 -0
- package/dist/plugins/graphic-associate/index.d.ts.map +1 -0
- package/dist/plugins/graphic-associate/index.js +8 -0
- package/dist/plugins/graphic-gap-match/index.d.ts +8 -0
- package/dist/plugins/graphic-gap-match/index.d.ts.map +1 -0
- package/dist/plugins/graphic-gap-match/index.js +8 -0
- package/dist/plugins/graphic-order/index.d.ts +8 -0
- package/dist/plugins/graphic-order/index.d.ts.map +1 -0
- package/dist/plugins/graphic-order/index.js +8 -0
- package/dist/plugins/hotspot/index.d.ts +8 -0
- package/dist/plugins/hotspot/index.d.ts.map +1 -0
- package/dist/plugins/hotspot/index.js +8 -0
- package/dist/plugins/hottext/index.d.ts +8 -0
- package/dist/plugins/hottext/index.d.ts.map +1 -0
- package/dist/plugins/hottext/index.js +8 -0
- package/dist/plugins/index.d.ts +30 -0
- package/dist/plugins/index.d.ts.map +1 -0
- package/dist/plugins/index.js +30 -0
- package/dist/plugins/match/index.d.ts +8 -0
- package/dist/plugins/match/index.d.ts.map +1 -0
- package/dist/plugins/match/index.js +8 -0
- package/dist/plugins/media/index.d.ts +8 -0
- package/dist/plugins/media/index.d.ts.map +1 -0
- package/dist/plugins/media/index.js +8 -0
- package/dist/plugins/order/index.d.ts +8 -0
- package/dist/plugins/order/index.d.ts.map +1 -0
- package/dist/plugins/order/index.js +8 -0
- package/dist/plugins/position-object/index.d.ts +8 -0
- package/dist/plugins/position-object/index.d.ts.map +1 -0
- package/dist/plugins/position-object/index.js +8 -0
- package/dist/plugins/select-point/index.d.ts +8 -0
- package/dist/plugins/select-point/index.d.ts.map +1 -0
- package/dist/plugins/select-point/index.js +8 -0
- package/dist/plugins/slider/index.d.ts +8 -0
- package/dist/plugins/slider/index.d.ts.map +1 -0
- package/dist/plugins/slider/index.js +8 -0
- package/dist/shared/actions/typesetAction.d.ts +26 -0
- package/dist/shared/actions/typesetAction.d.ts.map +1 -0
- package/dist/shared/actions/typesetAction.js +70 -0
- package/dist/shared/extensions/MathLiveEditor.d.ts +19 -0
- package/dist/shared/extensions/MathLiveEditor.d.ts.map +1 -0
- package/dist/shared/extensions/MathLiveEditor.js +239 -0
- package/dist/shared/index.d.ts +11 -0
- package/dist/shared/index.d.ts.map +1 -0
- package/dist/shared/index.js +15 -0
- package/dist/shared/utils/eventHelpers.d.ts +18 -0
- package/dist/shared/utils/eventHelpers.d.ts.map +1 -0
- package/dist/shared/utils/eventHelpers.js +30 -0
- package/dist/shared/utils/pairHelpers.d.ts +55 -0
- package/dist/shared/utils/pairHelpers.d.ts.map +1 -0
- package/dist/shared/utils/pairHelpers.js +76 -0
- package/dist/shared/utils/touchDragHelper.d.ts +33 -0
- package/dist/shared/utils/touchDragHelper.d.ts.map +1 -0
- package/dist/shared/utils/touchDragHelper.js +168 -0
- package/dist/shared/utils/webComponentHelpers.d.ts +9 -0
- package/dist/shared/utils/webComponentHelpers.d.ts.map +1 -0
- package/dist/shared/utils/webComponentHelpers.js +26 -0
- package/package.json +93 -0
- package/src/index.ts +213 -0
- package/src/plugins/associate/AssociateInteraction.svelte +273 -0
- package/src/plugins/associate/index.ts +9 -0
- package/src/plugins/choice/ChoiceInteraction.svelte +212 -0
- package/src/plugins/choice/index.ts +9 -0
- package/src/plugins/custom/CustomInteraction.svelte +61 -0
- package/src/plugins/custom/index.ts +9 -0
- package/src/plugins/drawing/DrawingInteraction.svelte +90 -0
- package/src/plugins/end-attempt/EndAttemptInteraction.svelte +142 -0
- package/src/plugins/end-attempt/index.ts +9 -0
- package/src/plugins/extended-text/ExtendedTextInteraction.svelte +77 -0
- package/src/plugins/extended-text/index.ts +9 -0
- package/src/plugins/gap-match/GapMatchInteraction.svelte +379 -0
- package/src/plugins/gap-match/index.ts +9 -0
- package/src/plugins/graphic-associate/GraphicAssociateInteraction.svelte +427 -0
- package/src/plugins/graphic-associate/index.ts +9 -0
- package/src/plugins/graphic-gap-match/GraphicGapMatchInteraction.svelte +508 -0
- package/src/plugins/graphic-gap-match/index.ts +9 -0
- package/src/plugins/graphic-order/GraphicOrderInteraction.svelte +241 -0
- package/src/plugins/graphic-order/index.ts +9 -0
- package/src/plugins/hotspot/HotspotInteraction.svelte +244 -0
- package/src/plugins/hotspot/index.ts +9 -0
- package/src/plugins/hottext/HottextInteraction.svelte +296 -0
- package/src/plugins/hottext/index.ts +9 -0
- package/src/plugins/index.ts +31 -0
- package/src/plugins/match/MatchInteraction.svelte +70 -0
- package/src/plugins/match/index.ts +9 -0
- package/src/plugins/media/MediaInteraction.svelte +213 -0
- package/src/plugins/media/index.ts +9 -0
- package/src/plugins/order/OrderInteraction.svelte +159 -0
- package/src/plugins/order/index.ts +9 -0
- package/src/plugins/position-object/PositionObjectInteraction.svelte +671 -0
- package/src/plugins/position-object/README.md +130 -0
- package/src/plugins/position-object/index.ts +9 -0
- package/src/plugins/select-point/SelectPointInteraction.svelte +453 -0
- package/src/plugins/select-point/index.ts +9 -0
- package/src/plugins/slider/SliderInteraction.svelte +141 -0
- package/src/plugins/slider/index.ts +9 -0
- package/src/plugins/upload/UploadInteraction.svelte +59 -0
- package/src/shared/actions/typesetAction.ts +87 -0
- package/src/shared/components/CustomInteractionFallback.svelte +153 -0
- package/src/shared/components/DragHandle.svelte +44 -0
- package/src/shared/components/DrawingCanvas.svelte +243 -0
- package/src/shared/components/FileUpload.svelte +153 -0
- package/src/shared/components/GraphicGapMatch.svelte +316 -0
- package/src/shared/components/GraphicGapMatchAdapter.svelte +36 -0
- package/src/shared/components/InlineInteractionRenderer.svelte +124 -0
- package/src/shared/components/MatchDragDrop.svelte +434 -0
- package/src/shared/components/MathContent.svelte +18 -0
- package/src/shared/components/ModalFeedbackDisplay.svelte +81 -0
- package/src/shared/components/RichTextEditor.svelte +316 -0
- package/src/shared/components/ShadowBaseStyles.svelte +391 -0
- package/src/shared/components/SortableList.svelte +297 -0
- package/src/shared/extensions/MathLiveEditor.ts +304 -0
- package/src/shared/index.ts +17 -0
- package/src/shared/styles/shared.css +16 -0
- package/src/shared/utils/eventHelpers.ts +36 -0
- package/src/shared/utils/pairHelpers.ts +86 -0
- package/src/shared/utils/touchDragHelper.ts +211 -0
- package/src/shared/utils/webComponentHelpers.ts +27 -0
- package/src/svelte-shims.d.ts +9 -0
- package/svelte.config.js +9 -0
- package/tests/index.test.ts +8 -0
- package/tsconfig.json +20 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared utilities and helpers for QTI interaction plugins
|
|
3
|
+
*
|
|
4
|
+
* This module exports common utilities used across all interaction plugins.
|
|
5
|
+
*/
|
|
6
|
+
// Typeset action for math rendering
|
|
7
|
+
export * from './actions/typesetAction.js';
|
|
8
|
+
// MathLive editor extension for visual math input
|
|
9
|
+
export * from './extensions/MathLiveEditor.js';
|
|
10
|
+
// Event helpers for creating CustomEvents
|
|
11
|
+
export * from './utils/eventHelpers.js';
|
|
12
|
+
// Pair helpers for matching/association interactions
|
|
13
|
+
export * from './utils/pairHelpers.js';
|
|
14
|
+
// Touch drag helper for mobile-friendly drag-and-drop
|
|
15
|
+
export * from './utils/touchDragHelper.js';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Event emission helpers for QTI components
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Creates a standardized QTI change event
|
|
6
|
+
* @param responseId - The response identifier
|
|
7
|
+
* @param value - The response value
|
|
8
|
+
* @returns A CustomEvent that can be dispatched
|
|
9
|
+
*/
|
|
10
|
+
export declare function createQtiChangeEvent(responseId: string | undefined, value: any): CustomEvent;
|
|
11
|
+
/**
|
|
12
|
+
* Emits a QTI change event from an element
|
|
13
|
+
* @param element - The element to dispatch from (usually component root)
|
|
14
|
+
* @param responseId - The response identifier
|
|
15
|
+
* @param value - The response value
|
|
16
|
+
*/
|
|
17
|
+
export declare function emitQtiChange(element: HTMLElement | EventTarget, responseId: string | undefined, value: any): void;
|
|
18
|
+
//# sourceMappingURL=eventHelpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"eventHelpers.d.ts","sourceRoot":"","sources":["../../../src/shared/utils/eventHelpers.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,MAAM,GAAG,SAAS,EAAE,KAAK,EAAE,GAAG,GAAG,WAAW,CAU5F;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAC5B,OAAO,EAAE,WAAW,GAAG,WAAW,EAClC,UAAU,EAAE,MAAM,GAAG,SAAS,EAC9B,KAAK,EAAE,GAAG,GACR,IAAI,CAGN"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Event emission helpers for QTI components
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Creates a standardized QTI change event
|
|
6
|
+
* @param responseId - The response identifier
|
|
7
|
+
* @param value - The response value
|
|
8
|
+
* @returns A CustomEvent that can be dispatched
|
|
9
|
+
*/
|
|
10
|
+
export function createQtiChangeEvent(responseId, value) {
|
|
11
|
+
return new CustomEvent('qti-change', {
|
|
12
|
+
detail: {
|
|
13
|
+
responseId,
|
|
14
|
+
value,
|
|
15
|
+
timestamp: Date.now(),
|
|
16
|
+
},
|
|
17
|
+
bubbles: true,
|
|
18
|
+
composed: true,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Emits a QTI change event from an element
|
|
23
|
+
* @param element - The element to dispatch from (usually component root)
|
|
24
|
+
* @param responseId - The response identifier
|
|
25
|
+
* @param value - The response value
|
|
26
|
+
*/
|
|
27
|
+
export function emitQtiChange(element, responseId, value) {
|
|
28
|
+
const event = createQtiChangeEvent(responseId, value);
|
|
29
|
+
element.dispatchEvent(event);
|
|
30
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility functions for working with QTI pair responses
|
|
3
|
+
* Pairs are represented as space-separated strings: "sourceId targetId"
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Gets the target ID matched with a source ID
|
|
7
|
+
* @param pairs - Array of "sourceId targetId" pair strings
|
|
8
|
+
* @param sourceId - The source identifier to search for
|
|
9
|
+
* @returns The matched target ID, or null if not found
|
|
10
|
+
*/
|
|
11
|
+
export declare function getTargetForSource(pairs: string[], sourceId: string): string | null;
|
|
12
|
+
/**
|
|
13
|
+
* Gets the source ID matched with a target ID
|
|
14
|
+
* @param pairs - Array of "sourceId targetId" pair strings
|
|
15
|
+
* @param targetId - The target identifier to search for
|
|
16
|
+
* @returns The matched source ID, or null if not found
|
|
17
|
+
*/
|
|
18
|
+
export declare function getSourceForTarget(pairs: string[], targetId: string): string | null;
|
|
19
|
+
/**
|
|
20
|
+
* Creates or updates a pair, removing any existing pairs for the source or target
|
|
21
|
+
* @param pairs - Array of existing pair strings
|
|
22
|
+
* @param sourceId - The source identifier
|
|
23
|
+
* @param targetId - The target identifier
|
|
24
|
+
* @returns A new array with the pair created/updated
|
|
25
|
+
*/
|
|
26
|
+
export declare function createOrUpdatePair(pairs: string[], sourceId: string, targetId: string): string[];
|
|
27
|
+
/**
|
|
28
|
+
* Removes a pair by source ID
|
|
29
|
+
* @param pairs - Array of existing pair strings
|
|
30
|
+
* @param sourceId - The source identifier to remove
|
|
31
|
+
* @returns A new array without the pair
|
|
32
|
+
*/
|
|
33
|
+
export declare function removePairBySource(pairs: string[], sourceId: string): string[];
|
|
34
|
+
/**
|
|
35
|
+
* Removes a pair by target ID
|
|
36
|
+
* @param pairs - Array of existing pair strings
|
|
37
|
+
* @param targetId - The target identifier to remove
|
|
38
|
+
* @returns A new array without the pair
|
|
39
|
+
*/
|
|
40
|
+
export declare function removePairByTarget(pairs: string[], targetId: string): string[];
|
|
41
|
+
/**
|
|
42
|
+
* Checks if a source is paired
|
|
43
|
+
* @param pairs - Array of pair strings
|
|
44
|
+
* @param sourceId - The source identifier
|
|
45
|
+
* @returns True if the source has a pair
|
|
46
|
+
*/
|
|
47
|
+
export declare function isSourcePaired(pairs: string[], sourceId: string): boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Checks if a target is paired
|
|
50
|
+
* @param pairs - Array of pair strings
|
|
51
|
+
* @param targetId - The target identifier
|
|
52
|
+
* @returns True if the target has a pair
|
|
53
|
+
*/
|
|
54
|
+
export declare function isTargetPaired(pairs: string[], targetId: string): boolean;
|
|
55
|
+
//# sourceMappingURL=pairHelpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pairHelpers.d.ts","sourceRoot":"","sources":["../../../src/shared/utils/pairHelpers.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAGnF;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAGnF;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,CAWhG;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,CAE9E;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,CAE9E;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAEzE;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAEzE"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility functions for working with QTI pair responses
|
|
3
|
+
* Pairs are represented as space-separated strings: "sourceId targetId"
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Gets the target ID matched with a source ID
|
|
7
|
+
* @param pairs - Array of "sourceId targetId" pair strings
|
|
8
|
+
* @param sourceId - The source identifier to search for
|
|
9
|
+
* @returns The matched target ID, or null if not found
|
|
10
|
+
*/
|
|
11
|
+
export function getTargetForSource(pairs, sourceId) {
|
|
12
|
+
const pair = pairs.find((p) => p.startsWith(`${sourceId} `));
|
|
13
|
+
return pair ? pair.split(' ')[1] : null;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Gets the source ID matched with a target ID
|
|
17
|
+
* @param pairs - Array of "sourceId targetId" pair strings
|
|
18
|
+
* @param targetId - The target identifier to search for
|
|
19
|
+
* @returns The matched source ID, or null if not found
|
|
20
|
+
*/
|
|
21
|
+
export function getSourceForTarget(pairs, targetId) {
|
|
22
|
+
const pair = pairs.find((p) => p.endsWith(` ${targetId}`));
|
|
23
|
+
return pair ? pair.split(' ')[0] : null;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Creates or updates a pair, removing any existing pairs for the source or target
|
|
27
|
+
* @param pairs - Array of existing pair strings
|
|
28
|
+
* @param sourceId - The source identifier
|
|
29
|
+
* @param targetId - The target identifier
|
|
30
|
+
* @returns A new array with the pair created/updated
|
|
31
|
+
*/
|
|
32
|
+
export function createOrUpdatePair(pairs, sourceId, targetId) {
|
|
33
|
+
// Remove any existing pair for this source
|
|
34
|
+
let newPairs = pairs.filter((p) => !p.startsWith(`${sourceId} `));
|
|
35
|
+
// Remove any existing pair for this target
|
|
36
|
+
newPairs = newPairs.filter((p) => !p.endsWith(` ${targetId}`));
|
|
37
|
+
// Add new pair
|
|
38
|
+
newPairs.push(`${sourceId} ${targetId}`);
|
|
39
|
+
return newPairs;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Removes a pair by source ID
|
|
43
|
+
* @param pairs - Array of existing pair strings
|
|
44
|
+
* @param sourceId - The source identifier to remove
|
|
45
|
+
* @returns A new array without the pair
|
|
46
|
+
*/
|
|
47
|
+
export function removePairBySource(pairs, sourceId) {
|
|
48
|
+
return pairs.filter((p) => !p.startsWith(`${sourceId} `));
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Removes a pair by target ID
|
|
52
|
+
* @param pairs - Array of existing pair strings
|
|
53
|
+
* @param targetId - The target identifier to remove
|
|
54
|
+
* @returns A new array without the pair
|
|
55
|
+
*/
|
|
56
|
+
export function removePairByTarget(pairs, targetId) {
|
|
57
|
+
return pairs.filter((p) => !p.endsWith(` ${targetId}`));
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Checks if a source is paired
|
|
61
|
+
* @param pairs - Array of pair strings
|
|
62
|
+
* @param sourceId - The source identifier
|
|
63
|
+
* @returns True if the source has a pair
|
|
64
|
+
*/
|
|
65
|
+
export function isSourcePaired(pairs, sourceId) {
|
|
66
|
+
return pairs.some((p) => p.startsWith(`${sourceId} `));
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Checks if a target is paired
|
|
70
|
+
* @param pairs - Array of pair strings
|
|
71
|
+
* @param targetId - The target identifier
|
|
72
|
+
* @returns True if the target has a pair
|
|
73
|
+
*/
|
|
74
|
+
export function isTargetPaired(pairs, targetId) {
|
|
75
|
+
return pairs.some((p) => p.endsWith(` ${targetId}`));
|
|
76
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Touch-enabled drag helper for making HTML5 drag-and-drop work with touch devices
|
|
3
|
+
*
|
|
4
|
+
* HTML5 drag-and-drop API doesn't work on touch devices by default.
|
|
5
|
+
* This helper translates touch events to pointer events for unified handling.
|
|
6
|
+
*
|
|
7
|
+
* Usage:
|
|
8
|
+
* ```svelte
|
|
9
|
+
* <div
|
|
10
|
+
* use:touchDrag
|
|
11
|
+
* draggable="true"
|
|
12
|
+
* ondragstart={...}
|
|
13
|
+
* >
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Svelte action to enable touch drag on draggable elements
|
|
18
|
+
*/
|
|
19
|
+
export declare function touchDrag(node: HTMLElement): {
|
|
20
|
+
destroy(): void;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* CSS helper for touch-friendly drag interactions
|
|
24
|
+
* Returns CSS that should be applied to draggable elements
|
|
25
|
+
*/
|
|
26
|
+
export declare const touchDragStyles: {
|
|
27
|
+
readonly userSelect: "none";
|
|
28
|
+
readonly webkitUserSelect: "none";
|
|
29
|
+
readonly touchAction: "none";
|
|
30
|
+
readonly cursor: "grab";
|
|
31
|
+
readonly transition: "opacity 0.2s ease";
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=touchDragHelper.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"touchDragHelper.d.ts","sourceRoot":"","sources":["../../../src/shared/utils/touchDragHelper.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAaH;;GAEG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,WAAW;;EAiK1C;AAED;;;GAGG;AACH,eAAO,MAAM,eAAe;;;;;;CAalB,CAAC"}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Touch-enabled drag helper for making HTML5 drag-and-drop work with touch devices
|
|
3
|
+
*
|
|
4
|
+
* HTML5 drag-and-drop API doesn't work on touch devices by default.
|
|
5
|
+
* This helper translates touch events to pointer events for unified handling.
|
|
6
|
+
*
|
|
7
|
+
* Usage:
|
|
8
|
+
* ```svelte
|
|
9
|
+
* <div
|
|
10
|
+
* use:touchDrag
|
|
11
|
+
* draggable="true"
|
|
12
|
+
* ondragstart={...}
|
|
13
|
+
* >
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Svelte action to enable touch drag on draggable elements
|
|
18
|
+
*/
|
|
19
|
+
export function touchDrag(node) {
|
|
20
|
+
const state = {
|
|
21
|
+
element: node,
|
|
22
|
+
touchId: null,
|
|
23
|
+
isDragging: false,
|
|
24
|
+
startX: 0,
|
|
25
|
+
startY: 0,
|
|
26
|
+
currentX: 0,
|
|
27
|
+
currentY: 0,
|
|
28
|
+
dragThreshold: 10 // px movement to initiate drag
|
|
29
|
+
};
|
|
30
|
+
function handleTouchStart(e) {
|
|
31
|
+
// Only handle single touch
|
|
32
|
+
if (e.touches.length !== 1)
|
|
33
|
+
return;
|
|
34
|
+
// Check if element is draggable
|
|
35
|
+
const draggable = node.getAttribute('draggable');
|
|
36
|
+
if (draggable !== 'true')
|
|
37
|
+
return;
|
|
38
|
+
const touch = e.touches[0];
|
|
39
|
+
state.touchId = touch.identifier;
|
|
40
|
+
state.startX = touch.clientX;
|
|
41
|
+
state.startY = touch.clientY;
|
|
42
|
+
state.currentX = touch.clientX;
|
|
43
|
+
state.currentY = touch.clientY;
|
|
44
|
+
state.isDragging = false;
|
|
45
|
+
// Add move and end listeners to document for consistent tracking
|
|
46
|
+
document.addEventListener('touchmove', handleTouchMove, { passive: false });
|
|
47
|
+
document.addEventListener('touchend', handleTouchEnd);
|
|
48
|
+
document.addEventListener('touchcancel', handleTouchCancel);
|
|
49
|
+
}
|
|
50
|
+
function handleTouchMove(e) {
|
|
51
|
+
if (state.touchId === null)
|
|
52
|
+
return;
|
|
53
|
+
// Find the touch we're tracking
|
|
54
|
+
const touch = Array.from(e.changedTouches).find(t => t.identifier === state.touchId);
|
|
55
|
+
if (!touch)
|
|
56
|
+
return;
|
|
57
|
+
state.currentX = touch.clientX;
|
|
58
|
+
state.currentY = touch.clientY;
|
|
59
|
+
// Check if we've moved enough to start dragging
|
|
60
|
+
const deltaX = state.currentX - state.startX;
|
|
61
|
+
const deltaY = state.currentY - state.startY;
|
|
62
|
+
const distance = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
|
|
63
|
+
if (!state.isDragging && distance > state.dragThreshold) {
|
|
64
|
+
// Start drag
|
|
65
|
+
state.isDragging = true;
|
|
66
|
+
// Trigger dragstart event
|
|
67
|
+
const dragStartEvent = new DragEvent('dragstart', {
|
|
68
|
+
bubbles: true,
|
|
69
|
+
cancelable: true,
|
|
70
|
+
clientX: state.startX,
|
|
71
|
+
clientY: state.startY
|
|
72
|
+
});
|
|
73
|
+
node.dispatchEvent(dragStartEvent);
|
|
74
|
+
// Add visual feedback
|
|
75
|
+
node.style.opacity = '0.5';
|
|
76
|
+
e.preventDefault(); // Prevent scrolling
|
|
77
|
+
}
|
|
78
|
+
if (state.isDragging) {
|
|
79
|
+
e.preventDefault(); // Prevent scrolling while dragging
|
|
80
|
+
// Find element under touch point
|
|
81
|
+
const elementUnder = document.elementFromPoint(state.currentX, state.currentY);
|
|
82
|
+
if (elementUnder && elementUnder !== node) {
|
|
83
|
+
// Trigger dragover on the element under touch
|
|
84
|
+
const dragOverEvent = new DragEvent('dragover', {
|
|
85
|
+
bubbles: true,
|
|
86
|
+
cancelable: true,
|
|
87
|
+
clientX: state.currentX,
|
|
88
|
+
clientY: state.currentY
|
|
89
|
+
});
|
|
90
|
+
elementUnder.dispatchEvent(dragOverEvent);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
function handleTouchEnd(e) {
|
|
95
|
+
if (state.touchId === null)
|
|
96
|
+
return;
|
|
97
|
+
// Find the touch we're tracking
|
|
98
|
+
const touch = Array.from(e.changedTouches).find(t => t.identifier === state.touchId);
|
|
99
|
+
if (!touch)
|
|
100
|
+
return;
|
|
101
|
+
if (state.isDragging) {
|
|
102
|
+
// Find element under touch point at drop location
|
|
103
|
+
const elementUnder = document.elementFromPoint(touch.clientX, touch.clientY);
|
|
104
|
+
if (elementUnder) {
|
|
105
|
+
// Trigger drop event
|
|
106
|
+
const dropEvent = new DragEvent('drop', {
|
|
107
|
+
bubbles: true,
|
|
108
|
+
cancelable: true,
|
|
109
|
+
clientX: touch.clientX,
|
|
110
|
+
clientY: touch.clientY
|
|
111
|
+
});
|
|
112
|
+
elementUnder.dispatchEvent(dropEvent);
|
|
113
|
+
}
|
|
114
|
+
// Trigger dragend
|
|
115
|
+
const dragEndEvent = new DragEvent('dragend', {
|
|
116
|
+
bubbles: true,
|
|
117
|
+
cancelable: true
|
|
118
|
+
});
|
|
119
|
+
node.dispatchEvent(dragEndEvent);
|
|
120
|
+
// Reset visual feedback
|
|
121
|
+
node.style.opacity = '';
|
|
122
|
+
}
|
|
123
|
+
cleanup();
|
|
124
|
+
}
|
|
125
|
+
function handleTouchCancel() {
|
|
126
|
+
if (state.isDragging) {
|
|
127
|
+
// Trigger dragend
|
|
128
|
+
const dragEndEvent = new DragEvent('dragend', {
|
|
129
|
+
bubbles: true,
|
|
130
|
+
cancelable: true
|
|
131
|
+
});
|
|
132
|
+
node.dispatchEvent(dragEndEvent);
|
|
133
|
+
// Reset visual feedback
|
|
134
|
+
node.style.opacity = '';
|
|
135
|
+
}
|
|
136
|
+
cleanup();
|
|
137
|
+
}
|
|
138
|
+
function cleanup() {
|
|
139
|
+
state.touchId = null;
|
|
140
|
+
state.isDragging = false;
|
|
141
|
+
document.removeEventListener('touchmove', handleTouchMove);
|
|
142
|
+
document.removeEventListener('touchend', handleTouchEnd);
|
|
143
|
+
document.removeEventListener('touchcancel', handleTouchCancel);
|
|
144
|
+
}
|
|
145
|
+
// Attach initial touch listener
|
|
146
|
+
node.addEventListener('touchstart', handleTouchStart, { passive: true });
|
|
147
|
+
return {
|
|
148
|
+
destroy() {
|
|
149
|
+
node.removeEventListener('touchstart', handleTouchStart);
|
|
150
|
+
cleanup();
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* CSS helper for touch-friendly drag interactions
|
|
156
|
+
* Returns CSS that should be applied to draggable elements
|
|
157
|
+
*/
|
|
158
|
+
export const touchDragStyles = {
|
|
159
|
+
/* Prevent text selection during drag */
|
|
160
|
+
userSelect: 'none',
|
|
161
|
+
webkitUserSelect: 'none',
|
|
162
|
+
/* Allow touch events */
|
|
163
|
+
touchAction: 'none',
|
|
164
|
+
/* Cursor feedback */
|
|
165
|
+
cursor: 'grab',
|
|
166
|
+
/* Smooth transitions */
|
|
167
|
+
transition: 'opacity 0.2s ease'
|
|
168
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helper utilities for web component prop handling
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Parse a prop that may be a JSON string or an object
|
|
6
|
+
* Used when components are used as web components and receive JSON strings
|
|
7
|
+
*/
|
|
8
|
+
export declare function parseJsonProp<T>(prop: T | string | null | undefined): T | null;
|
|
9
|
+
//# sourceMappingURL=webComponentHelpers.d.ts.map
|
|
@@ -0,0 +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,IAAI,CAkB9E"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helper utilities for web component prop handling
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Parse a prop that may be a JSON string or an object
|
|
6
|
+
* Used when components are used as web components and receive JSON strings
|
|
7
|
+
*/
|
|
8
|
+
export function parseJsonProp(prop) {
|
|
9
|
+
if (prop === null || prop === undefined)
|
|
10
|
+
return null;
|
|
11
|
+
if (typeof prop === 'string') {
|
|
12
|
+
// Handle "null" string
|
|
13
|
+
if (prop === 'null')
|
|
14
|
+
return null;
|
|
15
|
+
// Try to parse as JSON
|
|
16
|
+
try {
|
|
17
|
+
return JSON.parse(prop);
|
|
18
|
+
}
|
|
19
|
+
catch (e) {
|
|
20
|
+
// If it's not valid JSON, return the string as-is
|
|
21
|
+
// This handles simple string identifiers
|
|
22
|
+
return prop;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return prop;
|
|
26
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pie-qti/default-components",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Default Svelte-based component implementations for QTI (2.x and 3.0) player",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "tsc",
|
|
10
|
+
"test": "bun test",
|
|
11
|
+
"typecheck": "tsc --noEmit",
|
|
12
|
+
"check": "../assessment-player/node_modules/.bin/svelte-check --tsconfig ./tsconfig.json",
|
|
13
|
+
"lint": "biome check .",
|
|
14
|
+
"lint:fix": "biome check --write .",
|
|
15
|
+
"format": "biome format --write ."
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"qti",
|
|
19
|
+
"qti2", "qti3",
|
|
20
|
+
"qti2.2",
|
|
21
|
+
"assessment",
|
|
22
|
+
"player",
|
|
23
|
+
"components",
|
|
24
|
+
"svelte",
|
|
25
|
+
"web-components"
|
|
26
|
+
],
|
|
27
|
+
"license": "MIT",
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@pie-qti/i18n": "workspace:*",
|
|
30
|
+
"@pie-qti/item-player": "workspace:*",
|
|
31
|
+
"@tiptap/core": "^3.15.3",
|
|
32
|
+
"@tiptap/extension-mathematics": "^3.15.3",
|
|
33
|
+
"@tiptap/extension-placeholder": "^3.15.3",
|
|
34
|
+
"@tiptap/starter-kit": "^3.15.3",
|
|
35
|
+
"mathlive": "^0.108.2"
|
|
36
|
+
},
|
|
37
|
+
"peerDependencies": {
|
|
38
|
+
"svelte": "^5.46.1"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@biomejs/biome": "^2.3.11",
|
|
42
|
+
"@types/node": "^25.0.3",
|
|
43
|
+
"svelte": "^5.46.1",
|
|
44
|
+
"svelte-check": "^4.3.5",
|
|
45
|
+
"typescript": "^5.9.3"
|
|
46
|
+
},
|
|
47
|
+
"exports": {
|
|
48
|
+
".": {
|
|
49
|
+
"types": "./dist/index.d.ts",
|
|
50
|
+
"import": "./dist/index.js"
|
|
51
|
+
},
|
|
52
|
+
"./MathContent.svelte": {
|
|
53
|
+
"svelte": "./src/shared/components/MathContent.svelte",
|
|
54
|
+
"import": "./src/shared/components/MathContent.svelte",
|
|
55
|
+
"default": "./src/shared/components/MathContent.svelte"
|
|
56
|
+
},
|
|
57
|
+
"./plugins": {
|
|
58
|
+
"svelte": "./src/plugins/index.ts",
|
|
59
|
+
"import": "./src/plugins/index.ts",
|
|
60
|
+
"default": "./src/plugins/index.ts"
|
|
61
|
+
},
|
|
62
|
+
"./shared": {
|
|
63
|
+
"types": "./dist/shared/index.d.ts",
|
|
64
|
+
"import": "./dist/shared/index.js"
|
|
65
|
+
},
|
|
66
|
+
"./plugins/*/*.svelte": {
|
|
67
|
+
"svelte": "./src/plugins/*/*.svelte",
|
|
68
|
+
"import": "./src/plugins/*/*.svelte",
|
|
69
|
+
"default": "./src/plugins/*/*.svelte"
|
|
70
|
+
},
|
|
71
|
+
"./plugins/*/index": {
|
|
72
|
+
"types": "./dist/plugins/*/index.d.ts",
|
|
73
|
+
"import": "./dist/plugins/*/index.js"
|
|
74
|
+
},
|
|
75
|
+
"./shared/components/*.svelte": {
|
|
76
|
+
"svelte": "./src/shared/components/*.svelte",
|
|
77
|
+
"import": "./src/shared/components/*.svelte",
|
|
78
|
+
"default": "./src/shared/components/*.svelte"
|
|
79
|
+
},
|
|
80
|
+
"./shared/utils/*": {
|
|
81
|
+
"types": "./dist/shared/utils/*.d.ts",
|
|
82
|
+
"import": "./dist/shared/utils/*.js"
|
|
83
|
+
},
|
|
84
|
+
"./shared/actions/*": {
|
|
85
|
+
"types": "./dist/shared/actions/*.d.ts",
|
|
86
|
+
"import": "./dist/shared/actions/*.js"
|
|
87
|
+
},
|
|
88
|
+
"./shared/extensions/*": {
|
|
89
|
+
"types": "./dist/shared/extensions/*.d.ts",
|
|
90
|
+
"import": "./dist/shared/extensions/*.js"
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|