@pie-qti/default-components 0.1.1 → 0.1.4
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/shared/extensions/MathLiveEditor.d.ts +1 -0
- package/dist/shared/extensions/MathLiveEditor.d.ts.map +1 -1
- package/dist/shared/extensions/MathLiveEditor.js +3 -7
- package/dist/shared/utils/eventHelpers.d.ts +3 -11
- package/dist/shared/utils/eventHelpers.d.ts.map +1 -1
- package/dist/shared/utils/eventHelpers.js +7 -1
- package/dist/shared/utils/pairHelpers.d.ts +15 -2
- package/dist/shared/utils/pairHelpers.d.ts.map +1 -1
- package/dist/shared/utils/pairHelpers.js +30 -8
- package/dist/shared/utils/touchDragHelper.d.ts +1 -32
- package/dist/shared/utils/touchDragHelper.d.ts.map +1 -1
- package/dist/shared/utils/touchDragHelper.js +1 -168
- package/dist/shared/utils/webComponentHelpers.d.ts +1 -1
- package/dist/shared/utils/webComponentHelpers.d.ts.map +1 -1
- package/dist/shared/utils/webComponentHelpers.js +3 -3
- package/package.json +113 -91
- package/src/plugins/gap-match/GapMatchInteraction.svelte +25 -10
- package/src/plugins/graphic-gap-match/GraphicGapMatchInteraction.svelte +32 -37
- package/src/plugins/hottext/HottextInteraction.svelte +1 -1
- package/src/plugins/media/MediaInteraction.svelte +2 -2
- package/src/plugins/position-object/PositionObjectInteraction.svelte +0 -6
- package/src/plugins/select-point/SelectPointInteraction.svelte +0 -14
- package/src/shared/components/DrawingCanvas.svelte +17 -1
- package/src/shared/components/MatchDragDrop.svelte +24 -23
- package/src/shared/components/ShadowBaseStyles.svelte +1 -2
- package/src/shared/extensions/MathLiveEditor.ts +3 -8
- package/src/shared/utils/eventHelpers.ts +12 -3
- package/src/shared/utils/pairHelpers.ts +32 -9
- package/src/shared/utils/touchDragHelper.ts +1 -211
- package/src/shared/utils/webComponentHelpers.ts +5 -5
- package/.turbo/turbo-build.log +0 -1
- package/CHANGELOG.md +0 -9
- package/STYLING.md +0 -226
- package/svelte.config.js +0 -9
- package/tests/index.test.ts +0 -8
- package/tsconfig.json +0 -20
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MathLiveEditor.d.ts","sourceRoot":"","sources":["../../../src/shared/extensions/MathLiveEditor.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"MathLiveEditor.d.ts","sourceRoot":"","sources":["../../../src/shared/extensions/MathLiveEditor.ts"],"names":[],"mappings":"AAaA,OAAO,qBAAqB,CAAC;AAgB7B,MAAM,WAAW,qBAAqB;IACrC,gDAAgD;IAChD,SAAS,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACnC,+BAA+B;IAC/B,QAAQ,EAAE,MAAM,IAAI,CAAC;IACrB,0BAA0B;IAC1B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,2CAA2C;IAC3C,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,8CAA8C;IAC9C,IAAI,CAAC,EAAE;QAAE,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAAA;KAAE,CAAC;CAClD;AAED;;GAEG;AACH,wBAAsB,kBAAkB,CAAC,OAAO,EAAE,qBAAqB,GAAG,OAAO,CAAC,MAAM,IAAI,CAAC,CA6P5F"}
|
|
@@ -1,18 +1,14 @@
|
|
|
1
1
|
/// <reference lib="dom" />
|
|
2
|
+
// Import MathLive CSS from the local package
|
|
3
|
+
import 'mathlive/static.css';
|
|
2
4
|
// Dynamically import MathLive to register the custom element
|
|
3
5
|
let mathLiveLoaded = null;
|
|
4
6
|
async function ensureMathLiveLoaded() {
|
|
5
7
|
if (!mathLiveLoaded && typeof window !== 'undefined') {
|
|
6
8
|
mathLiveLoaded = (async () => {
|
|
7
9
|
// Import MathLive to register the <math-field> custom element
|
|
10
|
+
// CSS is already imported at the top of this file
|
|
8
11
|
await import('mathlive');
|
|
9
|
-
// Load MathLive CSS if not already loaded
|
|
10
|
-
if (!document.querySelector('link[href*="mathlive"]')) {
|
|
11
|
-
const link = document.createElement('link');
|
|
12
|
-
link.rel = 'stylesheet';
|
|
13
|
-
link.href = 'https://cdn.jsdelivr.net/npm/mathlive@0.108.2/dist/mathlive-static.css';
|
|
14
|
-
document.head.appendChild(link);
|
|
15
|
-
}
|
|
16
12
|
})();
|
|
17
13
|
}
|
|
18
14
|
return mathLiveLoaded || Promise.resolve();
|
|
@@ -1,18 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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;
|
|
1
|
+
import type { QTIChangeEventDetail } from '@pie-qti/item-player/web-components';
|
|
2
|
+
export declare function createQtiChangeEvent(responseId: string | undefined, value: unknown): CustomEvent<QTIChangeEventDetail>;
|
|
11
3
|
/**
|
|
12
4
|
* Emits a QTI change event from an element
|
|
13
5
|
* @param element - The element to dispatch from (usually component root)
|
|
14
6
|
* @param responseId - The response identifier
|
|
15
7
|
* @param value - The response value
|
|
16
8
|
*/
|
|
17
|
-
export declare function emitQtiChange(element: HTMLElement | EventTarget, responseId: string | undefined, value:
|
|
9
|
+
export declare function emitQtiChange(element: HTMLElement | EventTarget, responseId: string | undefined, value: unknown): void;
|
|
18
10
|
//# sourceMappingURL=eventHelpers.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"eventHelpers.d.ts","sourceRoot":"","sources":["../../../src/shared/utils/eventHelpers.ts"],"names":[],"mappings":"AAAA
|
|
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"}
|
|
@@ -7,10 +7,16 @@
|
|
|
7
7
|
* @param value - The response value
|
|
8
8
|
* @returns A CustomEvent that can be dispatched
|
|
9
9
|
*/
|
|
10
|
+
function requireResponseId(responseId) {
|
|
11
|
+
if (!responseId || responseId.trim().length === 0) {
|
|
12
|
+
throw new Error('qti-change event requires a non-empty responseId');
|
|
13
|
+
}
|
|
14
|
+
return responseId;
|
|
15
|
+
}
|
|
10
16
|
export function createQtiChangeEvent(responseId, value) {
|
|
11
17
|
return new CustomEvent('qti-change', {
|
|
12
18
|
detail: {
|
|
13
|
-
responseId,
|
|
19
|
+
responseId: requireResponseId(responseId),
|
|
14
20
|
value,
|
|
15
21
|
timestamp: Date.now(),
|
|
16
22
|
},
|
|
@@ -3,12 +3,19 @@
|
|
|
3
3
|
* Pairs are represented as space-separated strings: "sourceId targetId"
|
|
4
4
|
*/
|
|
5
5
|
/**
|
|
6
|
-
* Gets the target ID matched with a source ID
|
|
6
|
+
* Gets the target ID matched with a source ID (first match only, for one-to-one display)
|
|
7
7
|
* @param pairs - Array of "sourceId targetId" pair strings
|
|
8
8
|
* @param sourceId - The source identifier to search for
|
|
9
9
|
* @returns The matched target ID, or null if not found
|
|
10
10
|
*/
|
|
11
11
|
export declare function getTargetForSource(pairs: string[], sourceId: string): string | null;
|
|
12
|
+
/**
|
|
13
|
+
* Gets all target IDs matched with a source ID (for many-to-many)
|
|
14
|
+
* @param pairs - Array of "sourceId targetId" pair strings
|
|
15
|
+
* @param sourceId - The source identifier to search for
|
|
16
|
+
* @returns Array of matched target IDs
|
|
17
|
+
*/
|
|
18
|
+
export declare function getTargetsForSource(pairs: string[], sourceId: string): string[];
|
|
12
19
|
/**
|
|
13
20
|
* Gets the source ID matched with a target ID
|
|
14
21
|
* @param pairs - Array of "sourceId targetId" pair strings
|
|
@@ -17,7 +24,9 @@ export declare function getTargetForSource(pairs: string[], sourceId: string): s
|
|
|
17
24
|
*/
|
|
18
25
|
export declare function getSourceForTarget(pairs: string[], targetId: string): string | null;
|
|
19
26
|
/**
|
|
20
|
-
* Creates or updates a pair
|
|
27
|
+
* Creates or updates a pair.
|
|
28
|
+
* - Removes any existing pair for the target (target receives at most one when matchMax=1)
|
|
29
|
+
* - Does NOT remove other pairs for the source (allows many-to-many: one source → multiple targets)
|
|
21
30
|
* @param pairs - Array of existing pair strings
|
|
22
31
|
* @param sourceId - The source identifier
|
|
23
32
|
* @param targetId - The target identifier
|
|
@@ -31,6 +40,10 @@ export declare function createOrUpdatePair(pairs: string[], sourceId: string, ta
|
|
|
31
40
|
* @returns A new array without the pair
|
|
32
41
|
*/
|
|
33
42
|
export declare function removePairBySource(pairs: string[], sourceId: string): string[];
|
|
43
|
+
/**
|
|
44
|
+
* Removes a specific pair by source and target ID
|
|
45
|
+
*/
|
|
46
|
+
export declare function removePair(pairs: string[], sourceId: string, targetId: string): string[];
|
|
34
47
|
/**
|
|
35
48
|
* Removes a pair by target ID
|
|
36
49
|
* @param pairs - Array of existing pair strings
|
|
@@ -1 +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
|
|
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,mBAAmB,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,CAK/E;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAGnF;AAED;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,CAYhG;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,CAE9E;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,CAExF;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"}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Pairs are represented as space-separated strings: "sourceId targetId"
|
|
4
4
|
*/
|
|
5
5
|
/**
|
|
6
|
-
* Gets the target ID matched with a source ID
|
|
6
|
+
* Gets the target ID matched with a source ID (first match only, for one-to-one display)
|
|
7
7
|
* @param pairs - Array of "sourceId targetId" pair strings
|
|
8
8
|
* @param sourceId - The source identifier to search for
|
|
9
9
|
* @returns The matched target ID, or null if not found
|
|
@@ -12,6 +12,18 @@ export function getTargetForSource(pairs, sourceId) {
|
|
|
12
12
|
const pair = pairs.find((p) => p.startsWith(`${sourceId} `));
|
|
13
13
|
return pair ? pair.split(' ')[1] : null;
|
|
14
14
|
}
|
|
15
|
+
/**
|
|
16
|
+
* Gets all target IDs matched with a source ID (for many-to-many)
|
|
17
|
+
* @param pairs - Array of "sourceId targetId" pair strings
|
|
18
|
+
* @param sourceId - The source identifier to search for
|
|
19
|
+
* @returns Array of matched target IDs
|
|
20
|
+
*/
|
|
21
|
+
export function getTargetsForSource(pairs, sourceId) {
|
|
22
|
+
return pairs
|
|
23
|
+
.filter((p) => p.startsWith(`${sourceId} `))
|
|
24
|
+
.map((p) => p.split(' ')[1])
|
|
25
|
+
.filter((t) => !!t);
|
|
26
|
+
}
|
|
15
27
|
/**
|
|
16
28
|
* Gets the source ID matched with a target ID
|
|
17
29
|
* @param pairs - Array of "sourceId targetId" pair strings
|
|
@@ -23,19 +35,23 @@ export function getSourceForTarget(pairs, targetId) {
|
|
|
23
35
|
return pair ? pair.split(' ')[0] : null;
|
|
24
36
|
}
|
|
25
37
|
/**
|
|
26
|
-
* Creates or updates a pair
|
|
38
|
+
* Creates or updates a pair.
|
|
39
|
+
* - Removes any existing pair for the target (target receives at most one when matchMax=1)
|
|
40
|
+
* - Does NOT remove other pairs for the source (allows many-to-many: one source → multiple targets)
|
|
27
41
|
* @param pairs - Array of existing pair strings
|
|
28
42
|
* @param sourceId - The source identifier
|
|
29
43
|
* @param targetId - The target identifier
|
|
30
44
|
* @returns A new array with the pair created/updated
|
|
31
45
|
*/
|
|
32
46
|
export function createOrUpdatePair(pairs, sourceId, targetId) {
|
|
33
|
-
// Remove any existing pair for this
|
|
34
|
-
let newPairs = pairs.filter((p) => !p.
|
|
35
|
-
//
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
newPairs.
|
|
47
|
+
// Remove any existing pair for this target (target gets "replaced")
|
|
48
|
+
let newPairs = pairs.filter((p) => !p.endsWith(` ${targetId}`));
|
|
49
|
+
// Don't remove source pairs - allows one source to match multiple targets (many-to-many)
|
|
50
|
+
// Add new pair (avoid duplicate if same pair already exists)
|
|
51
|
+
const newPair = `${sourceId} ${targetId}`;
|
|
52
|
+
if (!newPairs.includes(newPair)) {
|
|
53
|
+
newPairs.push(newPair);
|
|
54
|
+
}
|
|
39
55
|
return newPairs;
|
|
40
56
|
}
|
|
41
57
|
/**
|
|
@@ -47,6 +63,12 @@ export function createOrUpdatePair(pairs, sourceId, targetId) {
|
|
|
47
63
|
export function removePairBySource(pairs, sourceId) {
|
|
48
64
|
return pairs.filter((p) => !p.startsWith(`${sourceId} `));
|
|
49
65
|
}
|
|
66
|
+
/**
|
|
67
|
+
* Removes a specific pair by source and target ID
|
|
68
|
+
*/
|
|
69
|
+
export function removePair(pairs, sourceId, targetId) {
|
|
70
|
+
return pairs.filter((p) => p !== `${sourceId} ${targetId}`);
|
|
71
|
+
}
|
|
50
72
|
/**
|
|
51
73
|
* Removes a pair by target ID
|
|
52
74
|
* @param pairs - Array of existing pair strings
|
|
@@ -1,33 +1,2 @@
|
|
|
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
|
-
};
|
|
1
|
+
export { touchDrag, touchDragStyles } from '@pie-qti/qti-common';
|
|
33
2
|
//# sourceMappingURL=touchDragHelper.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"touchDragHelper.d.ts","sourceRoot":"","sources":["../../../src/shared/utils/touchDragHelper.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"touchDragHelper.d.ts","sourceRoot":"","sources":["../../../src/shared/utils/touchDragHelper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC"}
|
|
@@ -1,168 +1 @@
|
|
|
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
|
-
};
|
|
1
|
+
export { touchDrag, touchDragStyles } from '@pie-qti/qti-common';
|
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
* Parse a prop that may be a JSON string or an object
|
|
6
6
|
* Used when components are used as web components and receive JSON strings
|
|
7
7
|
*/
|
|
8
|
-
export declare function parseJsonProp<T>(prop: T | string | null | undefined): T |
|
|
8
|
+
export declare function parseJsonProp<T>(prop: T | string | null | undefined): T | undefined;
|
|
9
9
|
//# 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,
|
|
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"}
|
|
@@ -7,16 +7,16 @@
|
|
|
7
7
|
*/
|
|
8
8
|
export function parseJsonProp(prop) {
|
|
9
9
|
if (prop === null || prop === undefined)
|
|
10
|
-
return
|
|
10
|
+
return undefined;
|
|
11
11
|
if (typeof prop === 'string') {
|
|
12
12
|
// Handle "null" string
|
|
13
13
|
if (prop === 'null')
|
|
14
|
-
return
|
|
14
|
+
return undefined;
|
|
15
15
|
// Try to parse as JSON
|
|
16
16
|
try {
|
|
17
17
|
return JSON.parse(prop);
|
|
18
18
|
}
|
|
19
|
-
catch
|
|
19
|
+
catch {
|
|
20
20
|
// If it's not valid JSON, return the string as-is
|
|
21
21
|
// This handles simple string identifiers
|
|
22
22
|
return prop;
|