@pie-qti/default-components 0.1.1 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/dist/index.d.ts +1 -1
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +9 -1
  4. package/dist/plugins/index.d.ts +1 -0
  5. package/dist/plugins/index.d.ts.map +1 -1
  6. package/dist/plugins/index.js +1 -0
  7. package/dist/shared/extensions/MathLiveEditor.d.ts +1 -0
  8. package/dist/shared/extensions/MathLiveEditor.d.ts.map +1 -1
  9. package/dist/shared/extensions/MathLiveEditor.js +3 -7
  10. package/dist/shared/utils/eventHelpers.d.ts +3 -11
  11. package/dist/shared/utils/eventHelpers.d.ts.map +1 -1
  12. package/dist/shared/utils/eventHelpers.js +7 -1
  13. package/dist/shared/utils/matchGroupUtils.d.ts +8 -0
  14. package/dist/shared/utils/matchGroupUtils.d.ts.map +1 -0
  15. package/dist/shared/utils/matchGroupUtils.js +13 -0
  16. package/dist/shared/utils/pairHelpers.d.ts +15 -2
  17. package/dist/shared/utils/pairHelpers.d.ts.map +1 -1
  18. package/dist/shared/utils/pairHelpers.js +30 -8
  19. package/dist/shared/utils/touchDragHelper.d.ts +1 -32
  20. package/dist/shared/utils/touchDragHelper.d.ts.map +1 -1
  21. package/dist/shared/utils/touchDragHelper.js +1 -168
  22. package/dist/shared/utils/webComponentHelpers.d.ts +1 -1
  23. package/dist/shared/utils/webComponentHelpers.d.ts.map +1 -1
  24. package/dist/shared/utils/webComponentHelpers.js +3 -3
  25. package/package.json +117 -91
  26. package/src/catalog/CatalogPopup.svelte +162 -0
  27. package/src/index.ts +10 -1
  28. package/src/plugins/associate/AssociateInteraction.svelte +18 -1
  29. package/src/plugins/choice/ChoiceInteraction.svelte +143 -4
  30. package/src/plugins/drawing/DrawingInteraction.svelte +9 -0
  31. package/src/plugins/extended-text/ExtendedTextInteraction.svelte +56 -1
  32. package/src/plugins/gap-match/GapMatchInteraction.svelte +199 -22
  33. package/src/plugins/graphic-associate/GraphicAssociateInteraction.svelte +85 -9
  34. package/src/plugins/graphic-gap-match/GraphicGapMatchInteraction.svelte +230 -145
  35. package/src/plugins/hotspot/HotspotInteraction.svelte +50 -7
  36. package/src/plugins/hottext/HottextInteraction.svelte +33 -4
  37. package/src/plugins/index.ts +1 -0
  38. package/src/plugins/match/MatchInteraction.svelte +13 -1
  39. package/src/plugins/media/MediaInteraction.svelte +2 -2
  40. package/src/plugins/order/OrderInteraction.svelte +132 -11
  41. package/src/plugins/position-object/PositionObjectInteraction.svelte +247 -15
  42. package/src/plugins/select-point/SelectPointInteraction.svelte +139 -21
  43. package/src/shared/components/DrawingCanvas.svelte +17 -1
  44. package/src/shared/components/GraphicGapMatch.svelte +5 -3
  45. package/src/shared/components/GraphicGapMatchAdapter.svelte +10 -1
  46. package/src/shared/components/InlineInteractionRenderer.svelte +11 -6
  47. package/src/shared/components/MatchDragDrop.svelte +72 -25
  48. package/src/shared/components/ShadowBaseStyles.svelte +1 -2
  49. package/src/shared/extensions/MathLiveEditor.ts +3 -8
  50. package/src/shared/styles/qti-shared-vocabulary.css +320 -0
  51. package/src/shared/utils/eventHelpers.ts +12 -3
  52. package/src/shared/utils/matchGroupUtils.ts +14 -0
  53. package/src/shared/utils/pairHelpers.ts +32 -9
  54. package/src/shared/utils/touchDragHelper.ts +1 -211
  55. package/src/shared/utils/webComponentHelpers.ts +5 -5
  56. package/.turbo/turbo-build.log +0 -1
  57. package/CHANGELOG.md +0 -9
  58. package/STYLING.md +0 -226
  59. package/svelte.config.js +0 -9
  60. package/tests/index.test.ts +0 -8
  61. package/tsconfig.json +0 -20
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @pie-qti/default-components
3
3
  *
4
- * Default Svelte-based component implementations for the QTI 2.x player.
4
+ * Default Svelte-based component implementations for the QTI player.
5
5
  * These components are packaged as web components that work with the
6
6
  * framework-agnostic @pie-qti/item-player core.
7
7
  */
@@ -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,CA+K3E"}
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"}
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @pie-qti/default-components
3
3
  *
4
- * Default Svelte-based component implementations for the QTI 2.x player.
4
+ * Default Svelte-based component implementations for the QTI player.
5
5
  * These components are packaged as web components that work with the
6
6
  * framework-agnostic @pie-qti/item-player core.
7
7
  */
@@ -187,4 +187,12 @@ export function registerDefaultComponents(registry) {
187
187
  });
188
188
  // Note: TextEntryInteraction and InlineChoiceInteraction are handled
189
189
  // by ItemRenderer as inline interactions, not as separate components
190
+ // CatalogPopup - focus-trapped dialog for glossary/keyword-translation entries
191
+ registry.register('catalogPopup', {
192
+ name: 'default-catalog-popup',
193
+ priority: 0,
194
+ description: 'Default Svelte-based catalog popup dialog',
195
+ canHandle: () => true,
196
+ tagName: 'pie-qti-catalog-popup',
197
+ });
190
198
  }
@@ -27,4 +27,5 @@ import './select-point/SelectPointInteraction.svelte';
27
27
  import './extended-text/ExtendedTextInteraction.svelte';
28
28
  import './upload/UploadInteraction.svelte';
29
29
  import './drawing/DrawingInteraction.svelte';
30
+ import '../catalog/CatalogPopup.svelte';
30
31
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/plugins/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,mCAAmC,CAAC;AAC3C,OAAO,mCAAmC,CAAC;AAC3C,OAAO,iCAAiC,CAAC;AACzC,OAAO,iCAAiC,CAAC;AACzC,OAAO,yCAAyC,CAAC;AACjD,OAAO,wCAAwC,CAAC;AAChD,OAAO,qCAAqC,CAAC;AAC7C,OAAO,qCAAqC,CAAC;AAC7C,OAAO,iCAAiC,CAAC;AACzC,OAAO,mCAAmC,CAAC;AAC3C,OAAO,4CAA4C,CAAC;AACpD,OAAO,oDAAoD,CAAC;AAC5D,OAAO,uDAAuD,CAAC;AAC/D,OAAO,gDAAgD,CAAC;AACxD,OAAO,wDAAwD,CAAC;AAChE,OAAO,8CAA8C,CAAC;AACtD,OAAO,gDAAgD,CAAC;AACxD,OAAO,mCAAmC,CAAC;AAC3C,OAAO,qCAAqC,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/plugins/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,mCAAmC,CAAC;AAC3C,OAAO,mCAAmC,CAAC;AAC3C,OAAO,iCAAiC,CAAC;AACzC,OAAO,iCAAiC,CAAC;AACzC,OAAO,yCAAyC,CAAC;AACjD,OAAO,wCAAwC,CAAC;AAChD,OAAO,qCAAqC,CAAC;AAC7C,OAAO,qCAAqC,CAAC;AAC7C,OAAO,iCAAiC,CAAC;AACzC,OAAO,mCAAmC,CAAC;AAC3C,OAAO,4CAA4C,CAAC;AACpD,OAAO,oDAAoD,CAAC;AAC5D,OAAO,uDAAuD,CAAC;AAC/D,OAAO,gDAAgD,CAAC;AACxD,OAAO,wDAAwD,CAAC;AAChE,OAAO,8CAA8C,CAAC;AACtD,OAAO,gDAAgD,CAAC;AACxD,OAAO,mCAAmC,CAAC;AAC3C,OAAO,qCAAqC,CAAC;AAC7C,OAAO,gCAAgC,CAAC"}
@@ -28,3 +28,4 @@ import './select-point/SelectPointInteraction.svelte';
28
28
  import './extended-text/ExtendedTextInteraction.svelte';
29
29
  import './upload/UploadInteraction.svelte';
30
30
  import './drawing/DrawingInteraction.svelte';
31
+ import '../catalog/CatalogPopup.svelte';
@@ -1,3 +1,4 @@
1
+ import 'mathlive/static.css';
1
2
  export interface MathLiveEditorOptions {
2
3
  /** Called when user confirms the LaTeX input */
3
4
  onConfirm: (latex: string) => void;
@@ -1 +1 @@
1
- {"version":3,"file":"MathLiveEditor.d.ts","sourceRoot":"","sources":["../../../src/shared/extensions/MathLiveEditor.ts"],"names":[],"mappings":"AAkCA,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
+ {"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
- * 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;
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: any): void;
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;;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"}
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
  },
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Returns true if a source and target choice are compatible for pairing.
3
+ *
4
+ * Per QTI spec, an empty/absent matchGroup is unrestricted (pairs with anything).
5
+ * Two non-empty matchGroups are compatible only if they share at least one value.
6
+ */
7
+ export declare function isCompatibleMatchGroup(sourceGroups: string[] | undefined, targetGroups: string[] | undefined): boolean;
8
+ //# sourceMappingURL=matchGroupUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"matchGroupUtils.d.ts","sourceRoot":"","sources":["../../../src/shared/utils/matchGroupUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAgB,sBAAsB,CACrC,YAAY,EAAE,MAAM,EAAE,GAAG,SAAS,EAClC,YAAY,EAAE,MAAM,EAAE,GAAG,SAAS,GAChC,OAAO,CAIT"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Returns true if a source and target choice are compatible for pairing.
3
+ *
4
+ * Per QTI spec, an empty/absent matchGroup is unrestricted (pairs with anything).
5
+ * Two non-empty matchGroups are compatible only if they share at least one value.
6
+ */
7
+ export function isCompatibleMatchGroup(sourceGroups, targetGroups) {
8
+ if (!sourceGroups || sourceGroups.length === 0)
9
+ return true;
10
+ if (!targetGroups || targetGroups.length === 0)
11
+ return true;
12
+ return sourceGroups.some((g) => targetGroups.includes(g));
13
+ }
@@ -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, removing any existing pairs for the source or target
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;;;;;;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"}
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, removing any existing pairs for the source or target
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 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}`);
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;;;;;;;;;;;;;;GAcG;AAaH;;GAEG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,WAAW;;EAiK1C;AAED;;;GAGG;AACH,eAAO,MAAM,eAAe;;;;;;CAalB,CAAC"}
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 | null;
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,IAAI,CAkB9E"}
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 null;
10
+ return undefined;
11
11
  if (typeof prop === 'string') {
12
12
  // Handle "null" string
13
13
  if (prop === 'null')
14
- return null;
14
+ return undefined;
15
15
  // Try to parse as JSON
16
16
  try {
17
17
  return JSON.parse(prop);
18
18
  }
19
- catch (e) {
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;