@pie-qti/default-components 0.1.10 → 0.1.12

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 (180) hide show
  1. package/dist/chunks/__vite-browser-external-Dz5RCjpq.js +9 -0
  2. package/dist/chunks/__vite-browser-external-Dz5RCjpq.js.map +1 -0
  3. package/dist/chunks/{mathlive.min-Bvtiaxg4.js → mathlive.min-ClqhKA_b.js} +4199 -3978
  4. package/dist/chunks/mathlive.min-ClqhKA_b.js.map +1 -0
  5. package/dist/index.d.ts +0 -1
  6. package/dist/index.js +1 -0
  7. package/dist/index.js.map +1 -0
  8. package/dist/plugins/associate/index.d.ts +0 -1
  9. package/dist/plugins/associate/index.js +1 -0
  10. package/dist/plugins/associate/index.js.map +1 -0
  11. package/dist/plugins/choice/index.d.ts +0 -1
  12. package/dist/plugins/choice/index.js +1 -0
  13. package/dist/plugins/choice/index.js.map +1 -0
  14. package/dist/plugins/custom/index.d.ts +0 -1
  15. package/dist/plugins/custom/index.js +1 -0
  16. package/dist/plugins/custom/index.js.map +1 -0
  17. package/dist/plugins/end-attempt/index.d.ts +0 -1
  18. package/dist/plugins/end-attempt/index.js +1 -0
  19. package/dist/plugins/end-attempt/index.js.map +1 -0
  20. package/dist/plugins/extended-text/index.d.ts +0 -1
  21. package/dist/plugins/extended-text/index.js +1 -0
  22. package/dist/plugins/extended-text/index.js.map +1 -0
  23. package/dist/plugins/gap-match/index.d.ts +0 -1
  24. package/dist/plugins/gap-match/index.js +1 -0
  25. package/dist/plugins/gap-match/index.js.map +1 -0
  26. package/dist/plugins/graphic-associate/index.d.ts +0 -1
  27. package/dist/plugins/graphic-associate/index.js +1 -0
  28. package/dist/plugins/graphic-associate/index.js.map +1 -0
  29. package/dist/plugins/graphic-gap-match/index.d.ts +0 -1
  30. package/dist/plugins/graphic-gap-match/index.js +1 -0
  31. package/dist/plugins/graphic-gap-match/index.js.map +1 -0
  32. package/dist/plugins/graphic-order/index.d.ts +0 -1
  33. package/dist/plugins/graphic-order/index.js +1 -0
  34. package/dist/plugins/graphic-order/index.js.map +1 -0
  35. package/dist/plugins/hotspot/index.d.ts +0 -1
  36. package/dist/plugins/hotspot/index.js +1 -0
  37. package/dist/plugins/hotspot/index.js.map +1 -0
  38. package/dist/plugins/hottext/index.d.ts +0 -1
  39. package/dist/plugins/hottext/index.js +1 -0
  40. package/dist/plugins/hottext/index.js.map +1 -0
  41. package/dist/plugins/match/index.d.ts +0 -1
  42. package/dist/plugins/match/index.js +1 -0
  43. package/dist/plugins/match/index.js.map +1 -0
  44. package/dist/plugins/media/index.d.ts +0 -1
  45. package/dist/plugins/media/index.js +1 -0
  46. package/dist/plugins/media/index.js.map +1 -0
  47. package/dist/plugins/order/index.d.ts +0 -1
  48. package/dist/plugins/order/index.js +1 -0
  49. package/dist/plugins/order/index.js.map +1 -0
  50. package/dist/plugins/position-object/index.d.ts +0 -1
  51. package/dist/plugins/position-object/index.js +1 -0
  52. package/dist/plugins/position-object/index.js.map +1 -0
  53. package/dist/plugins/public-types.d.ts +5 -0
  54. package/dist/plugins/public-types.js +2 -0
  55. package/dist/plugins/public-types.js.map +1 -0
  56. package/dist/plugins/select-point/index.d.ts +0 -1
  57. package/dist/plugins/select-point/index.js +1 -0
  58. package/dist/plugins/select-point/index.js.map +1 -0
  59. package/dist/plugins/slider/index.d.ts +0 -1
  60. package/dist/plugins/slider/index.js +1 -0
  61. package/dist/plugins/slider/index.js.map +1 -0
  62. package/dist/plugins.js +27589 -9160
  63. package/dist/plugins.js.map +1 -1
  64. package/dist/shared/actions/typesetAction.d.ts +0 -1
  65. package/dist/shared/actions/typesetAction.js +1 -0
  66. package/dist/shared/actions/typesetAction.js.map +1 -0
  67. package/dist/shared/extensions/MathLiveEditor.d.ts +0 -1
  68. package/dist/shared/extensions/MathLiveEditor.js +1 -0
  69. package/dist/shared/extensions/MathLiveEditor.js.map +1 -0
  70. package/dist/shared/index.d.ts +0 -1
  71. package/dist/shared/index.js +1 -0
  72. package/dist/shared/index.js.map +1 -0
  73. package/dist/shared/utils/eventHelpers.d.ts +0 -1
  74. package/dist/shared/utils/eventHelpers.js +1 -0
  75. package/dist/shared/utils/eventHelpers.js.map +1 -0
  76. package/dist/shared/utils/matchGroupUtils.d.ts +0 -1
  77. package/dist/shared/utils/matchGroupUtils.js +1 -0
  78. package/dist/shared/utils/matchGroupUtils.js.map +1 -0
  79. package/dist/shared/utils/pairHelpers.d.ts +0 -1
  80. package/dist/shared/utils/pairHelpers.js +1 -0
  81. package/dist/shared/utils/pairHelpers.js.map +1 -0
  82. package/dist/shared/utils/webComponentHelpers.d.ts +0 -1
  83. package/dist/shared/utils/webComponentHelpers.js +1 -0
  84. package/dist/shared/utils/webComponentHelpers.js.map +1 -0
  85. package/package.json +15 -33
  86. package/dist/chunks/mathlive.min-Bvtiaxg4.js.map +0 -1
  87. package/dist/index.d.ts.map +0 -1
  88. package/dist/plugins/associate/index.d.ts.map +0 -1
  89. package/dist/plugins/choice/index.d.ts.map +0 -1
  90. package/dist/plugins/custom/index.d.ts.map +0 -1
  91. package/dist/plugins/end-attempt/index.d.ts.map +0 -1
  92. package/dist/plugins/extended-text/index.d.ts.map +0 -1
  93. package/dist/plugins/gap-match/index.d.ts.map +0 -1
  94. package/dist/plugins/graphic-associate/index.d.ts.map +0 -1
  95. package/dist/plugins/graphic-gap-match/index.d.ts.map +0 -1
  96. package/dist/plugins/graphic-order/index.d.ts.map +0 -1
  97. package/dist/plugins/hotspot/index.d.ts.map +0 -1
  98. package/dist/plugins/hottext/index.d.ts.map +0 -1
  99. package/dist/plugins/index.d.ts +0 -31
  100. package/dist/plugins/index.d.ts.map +0 -1
  101. package/dist/plugins/index.js +0 -31
  102. package/dist/plugins/match/index.d.ts.map +0 -1
  103. package/dist/plugins/media/index.d.ts.map +0 -1
  104. package/dist/plugins/order/index.d.ts.map +0 -1
  105. package/dist/plugins/position-object/index.d.ts.map +0 -1
  106. package/dist/plugins/select-point/index.d.ts.map +0 -1
  107. package/dist/plugins/slider/index.d.ts.map +0 -1
  108. package/dist/shared/actions/typesetAction.d.ts.map +0 -1
  109. package/dist/shared/extensions/MathLiveEditor.d.ts.map +0 -1
  110. package/dist/shared/index.d.ts.map +0 -1
  111. package/dist/shared/utils/eventHelpers.d.ts.map +0 -1
  112. package/dist/shared/utils/matchGroupUtils.d.ts.map +0 -1
  113. package/dist/shared/utils/pairHelpers.d.ts.map +0 -1
  114. package/dist/shared/utils/touchDragHelper.d.ts +0 -2
  115. package/dist/shared/utils/touchDragHelper.d.ts.map +0 -1
  116. package/dist/shared/utils/touchDragHelper.js +0 -1
  117. package/dist/shared/utils/webComponentHelpers.d.ts.map +0 -1
  118. package/src/catalog/CatalogPopup.svelte +0 -163
  119. package/src/index.ts +0 -141
  120. package/src/plugins/associate/AssociateInteraction.svelte +0 -304
  121. package/src/plugins/associate/index.ts +0 -9
  122. package/src/plugins/choice/ChoiceInteraction.svelte +0 -355
  123. package/src/plugins/choice/index.ts +0 -9
  124. package/src/plugins/custom/CustomInteraction.svelte +0 -61
  125. package/src/plugins/custom/index.ts +0 -9
  126. package/src/plugins/drawing/DrawingInteraction.svelte +0 -99
  127. package/src/plugins/end-attempt/EndAttemptInteraction.svelte +0 -142
  128. package/src/plugins/end-attempt/index.ts +0 -9
  129. package/src/plugins/extended-text/ExtendedTextInteraction.svelte +0 -152
  130. package/src/plugins/extended-text/index.ts +0 -9
  131. package/src/plugins/gap-match/GapMatchInteraction.svelte +0 -556
  132. package/src/plugins/gap-match/index.ts +0 -9
  133. package/src/plugins/graphic-associate/GraphicAssociateInteraction.svelte +0 -503
  134. package/src/plugins/graphic-associate/index.ts +0 -9
  135. package/src/plugins/graphic-gap-match/GraphicGapMatchInteraction.svelte +0 -593
  136. package/src/plugins/graphic-gap-match/index.ts +0 -9
  137. package/src/plugins/graphic-order/GraphicOrderInteraction.svelte +0 -241
  138. package/src/plugins/graphic-order/index.ts +0 -9
  139. package/src/plugins/hotspot/HotspotInteraction.svelte +0 -287
  140. package/src/plugins/hotspot/index.ts +0 -9
  141. package/src/plugins/hottext/HottextInteraction.svelte +0 -325
  142. package/src/plugins/hottext/index.ts +0 -9
  143. package/src/plugins/index.ts +0 -32
  144. package/src/plugins/match/MatchInteraction.svelte +0 -82
  145. package/src/plugins/match/index.ts +0 -9
  146. package/src/plugins/media/MediaInteraction.svelte +0 -216
  147. package/src/plugins/media/index.ts +0 -9
  148. package/src/plugins/order/OrderInteraction.svelte +0 -280
  149. package/src/plugins/order/index.ts +0 -9
  150. package/src/plugins/position-object/PositionObjectInteraction.svelte +0 -903
  151. package/src/plugins/position-object/README.md +0 -130
  152. package/src/plugins/position-object/index.ts +0 -9
  153. package/src/plugins/select-point/SelectPointInteraction.svelte +0 -571
  154. package/src/plugins/select-point/index.ts +0 -9
  155. package/src/plugins/slider/SliderInteraction.svelte +0 -141
  156. package/src/plugins/slider/index.ts +0 -9
  157. package/src/plugins/upload/UploadInteraction.svelte +0 -59
  158. package/src/shared/actions/typesetAction.ts +0 -87
  159. package/src/shared/components/CustomInteractionFallback.svelte +0 -153
  160. package/src/shared/components/DragHandle.svelte +0 -44
  161. package/src/shared/components/DrawingCanvas.svelte +0 -259
  162. package/src/shared/components/FileUpload.svelte +0 -158
  163. package/src/shared/components/GraphicGapMatch.svelte +0 -318
  164. package/src/shared/components/GraphicGapMatchAdapter.svelte +0 -45
  165. package/src/shared/components/InlineInteractionRenderer.svelte +0 -141
  166. package/src/shared/components/MatchDragDrop.svelte +0 -481
  167. package/src/shared/components/MathContent.svelte +0 -18
  168. package/src/shared/components/ModalFeedbackDisplay.svelte +0 -91
  169. package/src/shared/components/RichTextEditor.svelte +0 -316
  170. package/src/shared/components/ShadowBaseStyles.svelte +0 -390
  171. package/src/shared/components/SortableList.svelte +0 -297
  172. package/src/shared/extensions/MathLiveEditor.ts +0 -299
  173. package/src/shared/index.ts +0 -15
  174. package/src/shared/styles/shared.css +0 -16
  175. package/src/shared/utils/eventHelpers.ts +0 -69
  176. package/src/shared/utils/matchGroupUtils.ts +0 -14
  177. package/src/shared/utils/pairHelpers.ts +0 -109
  178. package/src/shared/utils/webComponentHelpers.ts +0 -69
  179. package/src/svelte-shims.d.ts +0 -9
  180. /package/{src → dist}/shared/styles/qti-shared-vocabulary.css +0 -0
@@ -1,141 +0,0 @@
1
- <svelte:options customElement="pie-qti-slider" />
2
-
3
- <script lang="ts">
4
- import type { SliderInteractionData } from '@pie-qti/item-player';
5
- import type { I18nProvider } from '@pie-qti/i18n';
6
- import ShadowBaseStyles from '../../shared/components/ShadowBaseStyles.svelte';
7
- import { createQtiChangeEvent } from '../../shared/utils/eventHelpers';
8
- import { parseJsonProp } from '../../shared/utils/webComponentHelpers';
9
-
10
- interface Props {
11
- interaction?: SliderInteractionData | string;
12
- response?: number | null;
13
- correctResponse?: number | null;
14
- disabled?: boolean;
15
- role?: string;
16
- i18n?: I18nProvider;
17
- onChange?: (value: number) => void;
18
- }
19
-
20
- let { interaction = $bindable(), response = $bindable(), correctResponse = $bindable(), disabled = false, role = 'candidate', i18n = $bindable(), onChange }: Props = $props();
21
-
22
- // Parse props that may be JSON strings (web component usage)
23
- const parsedInteraction = $derived(parseJsonProp<SliderInteractionData>(interaction));
24
- const parsedResponse = $derived(parseJsonProp<number>(response));
25
- const parsedCorrectResponse = $derived(parseJsonProp<number>(correctResponse));
26
- const isShowingCorrect = $derived(role === 'scorer' && parsedCorrectResponse !== null);
27
-
28
- // Simplified translation helper - locale changes trigger page refresh
29
- const t = $derived((key: string, fallback: string) => i18n?.t(key) ?? fallback);
30
-
31
- // Get reference to the root element for event dispatching
32
- let rootElement: HTMLDivElement | undefined = $state();
33
-
34
- const defaultValue = $derived(
35
- parsedInteraction ? Math.floor((parsedInteraction.lowerBound + parsedInteraction.upperBound) / 2) : 0
36
- );
37
- // In scorer mode, use the correct response value; otherwise use user's response or default
38
- const currentValue = $derived(
39
- isShowingCorrect && parsedCorrectResponse !== null
40
- ? parsedCorrectResponse
41
- : parsedResponse ?? defaultValue
42
- );
43
-
44
- function handleChange(value: number) {
45
- response = value;
46
- // Call onChange callback if provided (for Svelte component usage)
47
- onChange?.(value);
48
- // Dispatch custom event for web component usage - event will bubble up to the host element
49
- if (rootElement) {
50
- rootElement.dispatchEvent(createQtiChangeEvent(parsedInteraction?.responseId, value));
51
- }
52
- }
53
- </script>
54
-
55
- <ShadowBaseStyles />
56
-
57
- <div bind:this={rootElement} part="root" class="qti-slider-interaction space-y-3">
58
- {#if !parsedInteraction}
59
- <div class="alert alert-error">{i18n?.t('common.errorNoData') ?? 'No interaction data provided'}</div>
60
- {:else}
61
- {#if parsedInteraction.prompt}
62
- <p part="prompt" class="qti-slider-prompt font-semibold">{@html parsedInteraction.prompt}</p>
63
- {/if}
64
-
65
- <div part="track" class="qti-slider-track flex items-center gap-4">
66
- <span part="min" class="qti-slider-bound text-sm text-base-content/70">{parsedInteraction.lowerBound}</span>
67
- <input
68
- part="input"
69
- type="range"
70
- min={parsedInteraction.lowerBound}
71
- max={parsedInteraction.upperBound}
72
- step={parsedInteraction.step}
73
- class="qti-slider-input range range-primary flex-1"
74
- value={currentValue}
75
- aria-label="Slider value from {parsedInteraction.lowerBound} to {parsedInteraction.upperBound}{isShowingCorrect && parsedCorrectResponse !== null ? '. Correct answer: ' + parsedCorrectResponse : ''}"
76
- aria-valuemin={parsedInteraction.lowerBound}
77
- aria-valuemax={parsedInteraction.upperBound}
78
- aria-valuenow={currentValue}
79
- oninput={(e: Event) => handleChange(Number((e.currentTarget as HTMLInputElement).value))}
80
- disabled={disabled || isShowingCorrect}
81
- />
82
- <span part="max" class="qti-slider-bound text-sm text-base-content/70">{parsedInteraction.upperBound}</span>
83
- </div>
84
-
85
- <div part="value" class="qti-slider-value text-center">
86
- <div class="qti-slider-stat stat bg-base-200 rounded-box inline-block" class:bg-success={isShowingCorrect} class:bg-opacity-10={isShowingCorrect}>
87
- <div class="qti-slider-stat-title stat-title">{i18n?.t('interactions.slider.statTitle') ?? 'Selected Value'}</div>
88
- <div
89
- part="value-number"
90
- class="qti-slider-stat-value stat-value"
91
- class:text-primary={!isShowingCorrect}
92
- class:text-success={isShowingCorrect}
93
- >
94
- {currentValue}
95
- </div>
96
- </div>
97
- </div>
98
- {/if}
99
- </div>
100
-
101
- <style>
102
- /* Minimal layout so this works without Tailwind/DaisyUI */
103
- .qti-slider-interaction {
104
- display: grid;
105
- gap: 0.75rem;
106
- }
107
- .qti-slider-prompt {
108
- margin: 0;
109
- }
110
- .qti-slider-track {
111
- display: flex;
112
- align-items: center;
113
- gap: 1rem;
114
- }
115
- .qti-slider-input {
116
- flex: 1 1 auto;
117
- width: 100%;
118
- }
119
- .qti-slider-bound {
120
- white-space: nowrap;
121
- }
122
- .qti-slider-value {
123
- text-align: center;
124
- }
125
- .qti-slider-stat {
126
- display: inline-block;
127
- padding: 0.75rem 1rem;
128
- border-radius: 0.75rem;
129
- border: 1px solid var(--color-base-300, oklch(95% 0 0));
130
- background: var(--color-base-200, oklch(98% 0 0));
131
- }
132
- .qti-slider-stat-title {
133
- font-size: 0.8rem;
134
- opacity: 0.7;
135
- }
136
- .qti-slider-stat-value {
137
- font-weight: 700;
138
- font-size: 1.25rem;
139
- color: var(--color-primary, oklch(45% 0.24 277));
140
- }
141
- </style>
@@ -1,9 +0,0 @@
1
- // Svelte component exported via web component
2
-
3
- export const metadata = {
4
- interactionType: 'sliderInteraction',
5
- tagName: 'pie-qti-slider',
6
- name: 'default-slider',
7
- description: 'Default Svelte-based slider interaction',
8
- priority: 0,
9
- };
@@ -1,59 +0,0 @@
1
- <svelte:options customElement="pie-qti-upload" />
2
-
3
- <script lang="ts">
4
- import type { UploadInteractionData, QTIFileResponse } from '@pie-qti/item-player';
5
- import type { I18nProvider } from '@pie-qti/i18n';
6
- import ShadowBaseStyles from '../../shared/components/ShadowBaseStyles.svelte';
7
- import FileUpload from '../../shared/components/FileUpload.svelte';
8
- import { createQtiChangeEvent } from '../../shared/utils/eventHelpers';
9
- import { parseJsonProp } from '../../shared/utils/webComponentHelpers';
10
- import { typesetAction } from '../../shared/actions/typesetAction';
11
-
12
- interface Props {
13
- interaction?: UploadInteractionData | string;
14
- response?: QTIFileResponse | string | null;
15
- disabled?: boolean;
16
- i18n?: I18nProvider;
17
- typeset?: (element: HTMLElement) => void;
18
- onChange?: (value: QTIFileResponse | null) => void;
19
- }
20
-
21
- let { interaction = $bindable(), response = $bindable(), disabled = false, i18n = $bindable(), typeset, onChange }: Props = $props();
22
-
23
- // Parse props that may be JSON strings (web component usage)
24
- const parsedInteraction = $derived(parseJsonProp<UploadInteractionData>(interaction));
25
- const parsedResponse = $derived(parseJsonProp<QTIFileResponse>(response));
26
-
27
- // Get reference to the root element for event dispatching
28
- let rootElement: HTMLDivElement | undefined = $state();
29
-
30
- function handleChange(value: QTIFileResponse | null) {
31
- response = value;
32
- // Call onChange callback if provided (for Svelte component usage)
33
- onChange?.(value);
34
- // Dispatch event for web component usage - event will bubble up to the host element
35
- if (rootElement && parsedInteraction) {
36
- rootElement.dispatchEvent(createQtiChangeEvent(parsedInteraction.responseId, value));
37
- }
38
- }
39
- </script>
40
-
41
- <ShadowBaseStyles />
42
-
43
- <div bind:this={rootElement} part="root" class="qti-upload-interaction" use:typesetAction={{ typeset }}>
44
- {#if !parsedInteraction}
45
- <div class="alert alert-error">
46
- <span>{i18n?.t('common.error', 'Error')}: {i18n?.t('common.errorNoData', 'No interaction data provided')}</span>
47
- </div>
48
- {:else}
49
- <FileUpload
50
- label={parsedInteraction.prompt || i18n?.t('interactions.upload.label', 'Upload a file')}
51
- responseId={parsedInteraction.responseId}
52
- fileTypes={parsedInteraction.fileTypes}
53
- {disabled}
54
- {i18n}
55
- value={parsedResponse}
56
- onChange={handleChange}
57
- />
58
- {/if}
59
- </div>
@@ -1,87 +0,0 @@
1
- /// <reference lib="dom" />
2
-
3
- export interface TypesetActionParams {
4
- /**
5
- * Typeset function provided by the host app (KaTeX, MathJax, etc).
6
- * It should be idempotent or at least safe to call repeatedly on updates.
7
- * Optional - if not provided, the action becomes a no-op.
8
- */
9
- typeset?: (root: HTMLElement) => void | Promise<void>;
10
-
11
- /**
12
- * Observe subtree changes and re-typeset automatically.
13
- * Default: true
14
- */
15
- observe?: boolean;
16
- }
17
-
18
- /**
19
- * Generic Svelte action that calls `params.typeset(node)` initially and on DOM updates.
20
- *
21
- * This is intentionally dependency-free so the player/components can be used
22
- * outside the example app without pulling in a math engine.
23
- *
24
- * If typeset is undefined, the action becomes a no-op (returns immediately).
25
- */
26
- export function typesetAction(node: HTMLElement, params?: TypesetActionParams) {
27
- // No-op if no typeset function provided
28
- if (!params?.typeset) {
29
- return { update() {}, destroy() {} };
30
- }
31
-
32
- const isBrowser = typeof window !== 'undefined' && typeof MutationObserver !== 'undefined';
33
- if (!isBrowser) return { update() {}, destroy() {} };
34
-
35
- let disposed = false;
36
- let scheduled = false;
37
- let observer: MutationObserver | null = null;
38
- let current = params;
39
-
40
- const schedule = () => {
41
- if (disposed || scheduled || !current.typeset) return;
42
- scheduled = true;
43
- requestAnimationFrame(async () => {
44
- scheduled = false;
45
- if (disposed || !current.typeset) return;
46
- try {
47
- await current.typeset(node);
48
- } catch {
49
- // ignore typesetting errors; keep raw text
50
- }
51
- });
52
- };
53
-
54
- const startObserver = () => {
55
- if (observer) return;
56
- observer = new MutationObserver(() => schedule());
57
- observer.observe(node, { childList: true, subtree: true, characterData: true });
58
- };
59
-
60
- const stopObserver = () => {
61
- observer?.disconnect();
62
- observer = null;
63
- };
64
-
65
- // initial
66
- schedule();
67
- if (current.observe !== false) startObserver();
68
-
69
- return {
70
- update(next?: TypesetActionParams) {
71
- if (!next?.typeset) {
72
- stopObserver();
73
- return;
74
- }
75
- current = next;
76
- if (current.observe === false) stopObserver();
77
- else startObserver();
78
- schedule();
79
- },
80
- destroy() {
81
- disposed = true;
82
- stopObserver();
83
- },
84
- };
85
- }
86
-
87
-
@@ -1,153 +0,0 @@
1
- <script lang="ts">
2
- /**
3
- * Fallback-only renderer for customInteraction.
4
- *
5
- * This does not execute custom logic; it provides visibility + optional manual response entry.
6
- */
7
-
8
- import type { I18nProvider } from '@pie-qti/i18n';
9
-
10
- interface Props {
11
- responseId: string;
12
- prompt?: string | null;
13
- rawAttributes?: Record<string, string>;
14
- xml?: string;
15
- disabled?: boolean;
16
- value?: string | null;
17
- onChange?: (value: string | null) => void;
18
- testIdInput?: string;
19
- i18n?: I18nProvider;
20
- }
21
-
22
- const {
23
- responseId,
24
- prompt = null,
25
- rawAttributes = {},
26
- xml = '',
27
- disabled = false,
28
- value = null,
29
- onChange,
30
- testIdInput,
31
- i18n,
32
- }: Props = $props();
33
-
34
- let open = $state(false);
35
- let manualValue = $state('');
36
-
37
- $effect(() => {
38
- manualValue = value ?? '';
39
- });
40
-
41
- function handleInput(e: Event) {
42
- manualValue = (e.currentTarget as HTMLTextAreaElement).value;
43
- onChange?.(manualValue || null);
44
- }
45
- </script>
46
-
47
- <div part="root" class="qti-custom-fallback space-y-3">
48
- <div part="warning" class="qti-custom-warning alert alert-warning">
49
- <div>
50
- <div class="font-semibold">{i18n?.t('interactions.custom.unsupported') ?? 'Unsupported customInteraction'}</div>
51
- <div class="text-sm">
52
- This item contains a vendor-specific interaction. This player does not execute custom interactions.
53
- </div>
54
- {#if prompt}
55
- <div class="text-sm mt-2"><strong>Prompt:</strong> {prompt}</div>
56
- {/if}
57
- </div>
58
- </div>
59
-
60
- {#if onChange}
61
- <div part="manual" class="qti-custom-manual form-control">
62
- <label part="manual-label" class="qti-custom-manual-label label" for={`custom-${responseId}`}>
63
- <span class="label-text font-semibold">{i18n?.t('interactions.custom.manualResponse') ?? 'Manual response (optional)'}</span>
64
- </label>
65
- <textarea
66
- id={`custom-${responseId}`}
67
- data-testid={testIdInput}
68
- part="manual-input"
69
- class="qti-custom-manual-input textarea textarea-bordered w-full"
70
- rows="3"
71
- placeholder={i18n?.t('interactions.custom.placeholder') ?? 'Enter a manual response (fallback)'}
72
- value={manualValue}
73
- oninput={handleInput}
74
- disabled={disabled}
75
- ></textarea>
76
- </div>
77
- {/if}
78
-
79
- <button part="toggle" type="button" class="qti-custom-toggle btn btn-sm btn-outline" onclick={() => (open = !open)}>
80
- {open ? 'Hide' : 'Show'} details
81
- </button>
82
-
83
- {#if open}
84
- <div part="details" class="qti-custom-details card bg-base-100 border border-base-300">
85
- <div class="qti-custom-details-body card-body">
86
- <h3 part="details-title" class="qti-custom-details-title card-title text-base">Details</h3>
87
- <div class="text-sm">
88
- <div class="font-semibold mb-1">{i18n?.t('interactions.custom.attributes') ?? 'Attributes'}</div>
89
- <pre part="attributes" class="qti-custom-pre text-xs bg-base-200 p-2 rounded overflow-auto">{JSON.stringify(rawAttributes, null, 2)}</pre>
90
- </div>
91
- {#if xml}
92
- <div class="text-sm">
93
- <div class="font-semibold mb-1">XML</div>
94
- <pre part="xml" class="qti-custom-pre text-xs bg-base-200 p-2 rounded overflow-auto">{xml}</pre>
95
- </div>
96
- {/if}
97
- </div>
98
- </div>
99
- {/if}
100
- </div>
101
-
102
- <style>
103
- /* Minimal layout so this works without Tailwind/DaisyUI */
104
- .qti-custom-fallback {
105
- display: grid;
106
- gap: 0.75rem;
107
- /* Ensure readable defaults even if the host sets a dark foreground color */
108
- color: var(--color-base-content, oklch(21% 0 0));
109
- }
110
- .qti-custom-warning,
111
- .qti-custom-details,
112
- .qti-custom-manual {
113
- border: 1px solid var(--color-base-300, oklch(95% 0 0));
114
- border-radius: 0.75rem;
115
- background: var(--color-base-200, oklch(98% 0 0));
116
- padding: 0.75rem;
117
- }
118
- .qti-custom-details {
119
- background: var(--color-base-100, oklch(100% 0 0));
120
- }
121
- .qti-custom-manual-label {
122
- display: block;
123
- margin-bottom: 0.25rem;
124
- }
125
- /* Override ShadowBaseStyles' DaisyUI-ish label text color to meet WCAG contrast. */
126
- .qti-custom-manual .label-text {
127
- color: var(--color-base-content, oklch(21% 0 0));
128
- }
129
- .qti-custom-manual-input {
130
- width: 100%;
131
- min-height: 4.5rem;
132
- padding: 0.5rem 0.75rem;
133
- border-radius: 0.5rem;
134
- border: 1px solid var(--color-base-300, oklch(95% 0 0));
135
- background: var(--color-base-100, oklch(100% 0 0));
136
- color: var(--color-base-content, oklch(21% 0 0));
137
- }
138
- .qti-custom-toggle {
139
- align-self: start;
140
- }
141
- .qti-custom-details-body {
142
- padding: 0.75rem;
143
- }
144
- .qti-custom-pre {
145
- background: var(--color-base-200, oklch(98% 0 0));
146
- border-radius: 0.5rem;
147
- border: 1px solid var(--color-base-300, oklch(95% 0 0));
148
- padding: 0.5rem;
149
- overflow: auto;
150
- }
151
- </style>
152
-
153
-
@@ -1,44 +0,0 @@
1
- <script lang="ts">
2
- /**
3
- * Reusable drag handle icon component
4
- * Displays horizontal bars to indicate draggable items
5
- */
6
-
7
- interface Props {
8
- /** Size in rem units. Default: 1rem (16px) */
9
- size?: number;
10
- /** Opacity level. Default: 0.5 */
11
- opacity?: number;
12
- /** Additional CSS classes */
13
- class?: string;
14
- }
15
-
16
- const { size = 1, opacity = 0.5, class: className = '' }: Props = $props();
17
-
18
- const sizeInRem = $derived(`${size}rem`);
19
- const opacityStyle = $derived(opacity);
20
- </script>
21
-
22
- <svg
23
- class="qti-drag-handle {className}"
24
- part="drag-handle"
25
- style="width: {sizeInRem}; height: {sizeInRem}; opacity: {opacityStyle};"
26
- fill="none"
27
- stroke="currentColor"
28
- viewBox="0 0 24 24"
29
- aria-hidden="true"
30
- >
31
- <path
32
- stroke-linecap="round"
33
- stroke-linejoin="round"
34
- stroke-width="2"
35
- d="M4 8h16M4 16h16"
36
- />
37
- </svg>
38
-
39
- <style>
40
- .qti-drag-handle {
41
- flex: 0 0 auto;
42
- display: inline-block;
43
- }
44
- </style>