@pie-qti/default-components 0.1.9 → 0.1.11
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/chunks/__vite-browser-external-BjvdLQIS.js +9 -0
- package/dist/chunks/__vite-browser-external-BjvdLQIS.js.map +1 -0
- package/dist/chunks/chunk-Bayd9M4T.js +20 -0
- package/dist/chunks/{mathlive.min-Bvtiaxg4.js → mathlive.min-CAPebTxM.js} +245 -29
- package/dist/chunks/{mathlive.min-Bvtiaxg4.js.map → mathlive.min-CAPebTxM.js.map} +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -0
- package/dist/plugins/associate/index.d.ts +0 -1
- package/dist/plugins/associate/index.js +1 -0
- package/dist/plugins/associate/index.js.map +1 -0
- package/dist/plugins/choice/index.d.ts +0 -1
- package/dist/plugins/choice/index.js +1 -0
- package/dist/plugins/choice/index.js.map +1 -0
- package/dist/plugins/custom/index.d.ts +0 -1
- package/dist/plugins/custom/index.js +1 -0
- package/dist/plugins/custom/index.js.map +1 -0
- package/dist/plugins/end-attempt/index.d.ts +0 -1
- package/dist/plugins/end-attempt/index.js +1 -0
- package/dist/plugins/end-attempt/index.js.map +1 -0
- package/dist/plugins/extended-text/index.d.ts +0 -1
- package/dist/plugins/extended-text/index.js +1 -0
- package/dist/plugins/extended-text/index.js.map +1 -0
- package/dist/plugins/gap-match/index.d.ts +0 -1
- package/dist/plugins/gap-match/index.js +1 -0
- package/dist/plugins/gap-match/index.js.map +1 -0
- package/dist/plugins/graphic-associate/index.d.ts +0 -1
- package/dist/plugins/graphic-associate/index.js +1 -0
- package/dist/plugins/graphic-associate/index.js.map +1 -0
- package/dist/plugins/graphic-gap-match/index.d.ts +0 -1
- package/dist/plugins/graphic-gap-match/index.js +1 -0
- package/dist/plugins/graphic-gap-match/index.js.map +1 -0
- package/dist/plugins/graphic-order/index.d.ts +0 -1
- package/dist/plugins/graphic-order/index.js +1 -0
- package/dist/plugins/graphic-order/index.js.map +1 -0
- package/dist/plugins/hotspot/index.d.ts +0 -1
- package/dist/plugins/hotspot/index.js +1 -0
- package/dist/plugins/hotspot/index.js.map +1 -0
- package/dist/plugins/hottext/index.d.ts +0 -1
- package/dist/plugins/hottext/index.js +1 -0
- package/dist/plugins/hottext/index.js.map +1 -0
- package/dist/plugins/match/index.d.ts +0 -1
- package/dist/plugins/match/index.js +1 -0
- package/dist/plugins/match/index.js.map +1 -0
- package/dist/plugins/media/index.d.ts +0 -1
- package/dist/plugins/media/index.js +1 -0
- package/dist/plugins/media/index.js.map +1 -0
- package/dist/plugins/order/index.d.ts +0 -1
- package/dist/plugins/order/index.js +1 -0
- package/dist/plugins/order/index.js.map +1 -0
- package/dist/plugins/position-object/index.d.ts +0 -1
- package/dist/plugins/position-object/index.js +1 -0
- package/dist/plugins/position-object/index.js.map +1 -0
- package/dist/plugins/public-types.d.ts +5 -0
- package/dist/plugins/public-types.js +2 -0
- package/dist/plugins/public-types.js.map +1 -0
- package/dist/plugins/select-point/index.d.ts +0 -1
- package/dist/plugins/select-point/index.js +1 -0
- package/dist/plugins/select-point/index.js.map +1 -0
- package/dist/plugins/slider/index.d.ts +0 -1
- package/dist/plugins/slider/index.js +1 -0
- package/dist/plugins/slider/index.js.map +1 -0
- package/dist/plugins.js +25958 -7690
- package/dist/plugins.js.map +1 -1
- package/dist/shared/actions/typesetAction.d.ts +0 -1
- package/dist/shared/actions/typesetAction.js +1 -0
- package/dist/shared/actions/typesetAction.js.map +1 -0
- package/dist/shared/extensions/MathLiveEditor.d.ts +0 -1
- package/dist/shared/extensions/MathLiveEditor.js +1 -0
- package/dist/shared/extensions/MathLiveEditor.js.map +1 -0
- package/dist/shared/index.d.ts +0 -2
- package/dist/shared/index.js +1 -2
- package/dist/shared/index.js.map +1 -0
- package/dist/shared/utils/eventHelpers.d.ts +6 -1
- package/dist/shared/utils/eventHelpers.js +7 -0
- package/dist/shared/utils/eventHelpers.js.map +1 -0
- package/dist/shared/utils/matchGroupUtils.d.ts +0 -1
- package/dist/shared/utils/matchGroupUtils.js +1 -0
- package/dist/shared/utils/matchGroupUtils.js.map +1 -0
- package/dist/shared/utils/pairHelpers.d.ts +0 -1
- package/dist/shared/utils/pairHelpers.js +1 -0
- package/dist/shared/utils/pairHelpers.js.map +1 -0
- package/dist/shared/utils/webComponentHelpers.d.ts +16 -1
- package/dist/shared/utils/webComponentHelpers.js +13 -0
- package/dist/shared/utils/webComponentHelpers.js.map +1 -0
- package/package.json +11 -33
- package/dist/index.d.ts.map +0 -1
- package/dist/plugins/associate/index.d.ts.map +0 -1
- package/dist/plugins/choice/index.d.ts.map +0 -1
- package/dist/plugins/custom/index.d.ts.map +0 -1
- package/dist/plugins/end-attempt/index.d.ts.map +0 -1
- package/dist/plugins/extended-text/index.d.ts.map +0 -1
- package/dist/plugins/gap-match/index.d.ts.map +0 -1
- package/dist/plugins/graphic-associate/index.d.ts.map +0 -1
- package/dist/plugins/graphic-gap-match/index.d.ts.map +0 -1
- package/dist/plugins/graphic-order/index.d.ts.map +0 -1
- package/dist/plugins/hotspot/index.d.ts.map +0 -1
- package/dist/plugins/hottext/index.d.ts.map +0 -1
- package/dist/plugins/index.d.ts +0 -31
- package/dist/plugins/index.d.ts.map +0 -1
- package/dist/plugins/index.js +0 -31
- package/dist/plugins/match/index.d.ts.map +0 -1
- package/dist/plugins/media/index.d.ts.map +0 -1
- package/dist/plugins/order/index.d.ts.map +0 -1
- package/dist/plugins/position-object/index.d.ts.map +0 -1
- package/dist/plugins/select-point/index.d.ts.map +0 -1
- package/dist/plugins/slider/index.d.ts.map +0 -1
- package/dist/shared/actions/typesetAction.d.ts.map +0 -1
- package/dist/shared/extensions/MathLiveEditor.d.ts.map +0 -1
- package/dist/shared/index.d.ts.map +0 -1
- package/dist/shared/utils/eventHelpers.d.ts.map +0 -1
- package/dist/shared/utils/matchGroupUtils.d.ts.map +0 -1
- package/dist/shared/utils/pairHelpers.d.ts.map +0 -1
- package/dist/shared/utils/touchDragHelper.d.ts +0 -2
- package/dist/shared/utils/touchDragHelper.d.ts.map +0 -1
- package/dist/shared/utils/touchDragHelper.js +0 -1
- package/dist/shared/utils/webComponentHelpers.d.ts.map +0 -1
- package/src/catalog/CatalogPopup.svelte +0 -163
- package/src/index.ts +0 -141
- package/src/plugins/associate/AssociateInteraction.svelte +0 -310
- package/src/plugins/associate/index.ts +0 -9
- package/src/plugins/choice/ChoiceInteraction.svelte +0 -358
- package/src/plugins/choice/index.ts +0 -9
- package/src/plugins/custom/CustomInteraction.svelte +0 -61
- package/src/plugins/custom/index.ts +0 -9
- package/src/plugins/drawing/DrawingInteraction.svelte +0 -99
- package/src/plugins/end-attempt/EndAttemptInteraction.svelte +0 -142
- package/src/plugins/end-attempt/index.ts +0 -9
- package/src/plugins/extended-text/ExtendedTextInteraction.svelte +0 -150
- package/src/plugins/extended-text/index.ts +0 -9
- package/src/plugins/gap-match/GapMatchInteraction.svelte +0 -556
- package/src/plugins/gap-match/index.ts +0 -9
- package/src/plugins/graphic-associate/GraphicAssociateInteraction.svelte +0 -503
- package/src/plugins/graphic-associate/index.ts +0 -9
- package/src/plugins/graphic-gap-match/GraphicGapMatchInteraction.svelte +0 -593
- package/src/plugins/graphic-gap-match/index.ts +0 -9
- package/src/plugins/graphic-order/GraphicOrderInteraction.svelte +0 -241
- package/src/plugins/graphic-order/index.ts +0 -9
- package/src/plugins/hotspot/HotspotInteraction.svelte +0 -287
- package/src/plugins/hotspot/index.ts +0 -9
- package/src/plugins/hottext/HottextInteraction.svelte +0 -325
- package/src/plugins/hottext/index.ts +0 -9
- package/src/plugins/index.ts +0 -32
- package/src/plugins/match/MatchInteraction.svelte +0 -82
- package/src/plugins/match/index.ts +0 -9
- package/src/plugins/media/MediaInteraction.svelte +0 -216
- package/src/plugins/media/index.ts +0 -9
- package/src/plugins/order/OrderInteraction.svelte +0 -280
- package/src/plugins/order/index.ts +0 -9
- package/src/plugins/position-object/PositionObjectInteraction.svelte +0 -903
- package/src/plugins/position-object/README.md +0 -130
- package/src/plugins/position-object/index.ts +0 -9
- package/src/plugins/select-point/SelectPointInteraction.svelte +0 -571
- package/src/plugins/select-point/index.ts +0 -9
- package/src/plugins/slider/SliderInteraction.svelte +0 -141
- package/src/plugins/slider/index.ts +0 -9
- package/src/plugins/upload/UploadInteraction.svelte +0 -59
- package/src/shared/actions/typesetAction.ts +0 -87
- package/src/shared/components/CustomInteractionFallback.svelte +0 -153
- package/src/shared/components/DragHandle.svelte +0 -44
- package/src/shared/components/DrawingCanvas.svelte +0 -259
- package/src/shared/components/FileUpload.svelte +0 -158
- package/src/shared/components/GraphicGapMatch.svelte +0 -318
- package/src/shared/components/GraphicGapMatchAdapter.svelte +0 -45
- package/src/shared/components/InlineInteractionRenderer.svelte +0 -141
- package/src/shared/components/MatchDragDrop.svelte +0 -481
- package/src/shared/components/MathContent.svelte +0 -18
- package/src/shared/components/ModalFeedbackDisplay.svelte +0 -91
- package/src/shared/components/RichTextEditor.svelte +0 -316
- package/src/shared/components/ShadowBaseStyles.svelte +0 -390
- package/src/shared/components/SortableList.svelte +0 -297
- package/src/shared/extensions/MathLiveEditor.ts +0 -299
- package/src/shared/index.ts +0 -17
- package/src/shared/styles/shared.css +0 -16
- package/src/shared/utils/eventHelpers.ts +0 -52
- package/src/shared/utils/matchGroupUtils.ts +0 -14
- package/src/shared/utils/pairHelpers.ts +0 -109
- package/src/shared/utils/touchDragHelper.ts +0 -1
- package/src/shared/utils/webComponentHelpers.ts +0 -27
- package/src/svelte-shims.d.ts +0 -9
- /package/{src → dist}/shared/styles/qti-shared-vocabulary.css +0 -0
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
<svelte:options customElement="pie-qti-catalog-popup" />
|
|
2
|
-
|
|
3
|
-
<script lang="ts">
|
|
4
|
-
/**
|
|
5
|
-
* CatalogPopup — accessible floating dialog for QTI 3.0 catalog entries.
|
|
6
|
-
*
|
|
7
|
-
* Renders glossary definitions, keyword translations, and illustrated-glossary images.
|
|
8
|
-
* Focus-trapped: Tab/Shift+Tab cycle within; Escape closes.
|
|
9
|
-
* For platform-level usages (TTS, signing, braille) the player fires a qti-catalog-lookup
|
|
10
|
-
* event instead of mounting this component.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
interface Props {
|
|
14
|
-
/** HTML content from CatalogEntry.html (or URL for illustrated-glossary). */
|
|
15
|
-
content: string;
|
|
16
|
-
/** Accessible label for the dialog (the term text). */
|
|
17
|
-
label: string;
|
|
18
|
-
/** Callback when the popup is closed. */
|
|
19
|
-
onClose: () => void;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const { content, label, onClose }: Props = $props();
|
|
23
|
-
|
|
24
|
-
// Illustrated-glossary: if content looks like a URL, render as <img>
|
|
25
|
-
const isUrl = $derived(/^(https?:\/\/|\/)/i.test(content.trim()));
|
|
26
|
-
|
|
27
|
-
let dialogEl: HTMLDivElement | undefined = $state();
|
|
28
|
-
let closeBtn: HTMLButtonElement | undefined = $state();
|
|
29
|
-
|
|
30
|
-
// Move focus into the popup on mount
|
|
31
|
-
$effect(() => {
|
|
32
|
-
if (dialogEl) {
|
|
33
|
-
closeBtn?.focus();
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
function handleKeyDown(event: KeyboardEvent) {
|
|
38
|
-
if (event.key === 'Escape') {
|
|
39
|
-
event.preventDefault();
|
|
40
|
-
onClose();
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// Focus trap: keep Tab within the popup
|
|
45
|
-
if (event.key === 'Tab' && dialogEl) {
|
|
46
|
-
const focusable = Array.from(
|
|
47
|
-
dialogEl.querySelectorAll<HTMLElement>(
|
|
48
|
-
'a[href], button:not([disabled]), input:not([disabled]), [tabindex]:not([tabindex="-1"])'
|
|
49
|
-
)
|
|
50
|
-
).filter((el) => el.offsetParent !== null);
|
|
51
|
-
|
|
52
|
-
if (focusable.length === 0) {
|
|
53
|
-
event.preventDefault();
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const first = focusable[0];
|
|
58
|
-
const last = focusable[focusable.length - 1];
|
|
59
|
-
|
|
60
|
-
if (event.shiftKey && document.activeElement === first) {
|
|
61
|
-
event.preventDefault();
|
|
62
|
-
last.focus();
|
|
63
|
-
} else if (!event.shiftKey && document.activeElement === last) {
|
|
64
|
-
event.preventDefault();
|
|
65
|
-
first.focus();
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
</script>
|
|
70
|
-
|
|
71
|
-
<!-- svelte-ignore a11y_no_noninteractive_element_interactions -->
|
|
72
|
-
<div
|
|
73
|
-
bind:this={dialogEl}
|
|
74
|
-
role="dialog"
|
|
75
|
-
aria-label={label}
|
|
76
|
-
aria-modal="true"
|
|
77
|
-
tabindex="-1"
|
|
78
|
-
class="qti-catalog-popup"
|
|
79
|
-
onkeydown={handleKeyDown}
|
|
80
|
-
>
|
|
81
|
-
<div class="qti-catalog-popup__header">
|
|
82
|
-
<span class="qti-catalog-popup__title">{label}</span>
|
|
83
|
-
<button
|
|
84
|
-
bind:this={closeBtn}
|
|
85
|
-
type="button"
|
|
86
|
-
class="qti-catalog-popup__close"
|
|
87
|
-
aria-label="Close"
|
|
88
|
-
onclick={onClose}
|
|
89
|
-
>✕</button>
|
|
90
|
-
</div>
|
|
91
|
-
<div class="qti-catalog-popup__body">
|
|
92
|
-
{#if isUrl}
|
|
93
|
-
<img src={content} alt={label} class="qti-catalog-popup__img" />
|
|
94
|
-
{:else}
|
|
95
|
-
<!-- eslint-disable-next-line svelte/no-at-html-tags -->
|
|
96
|
-
{@html content}
|
|
97
|
-
{/if}
|
|
98
|
-
</div>
|
|
99
|
-
</div>
|
|
100
|
-
|
|
101
|
-
<style>
|
|
102
|
-
.qti-catalog-popup {
|
|
103
|
-
position: absolute;
|
|
104
|
-
z-index: 1000;
|
|
105
|
-
background: var(--color-base-100, #fff);
|
|
106
|
-
border: 1px solid var(--color-base-300, #d1d5db);
|
|
107
|
-
border-radius: 0.5rem;
|
|
108
|
-
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
|
|
109
|
-
min-width: 16rem;
|
|
110
|
-
max-width: 24rem;
|
|
111
|
-
padding: 0;
|
|
112
|
-
font-size: 0.9rem;
|
|
113
|
-
line-height: 1.5;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
.qti-catalog-popup__header {
|
|
117
|
-
display: flex;
|
|
118
|
-
align-items: center;
|
|
119
|
-
justify-content: space-between;
|
|
120
|
-
padding: 0.5rem 0.75rem;
|
|
121
|
-
border-bottom: 1px solid var(--color-base-300, #d1d5db);
|
|
122
|
-
background: var(--color-base-200, #f9fafb);
|
|
123
|
-
border-radius: 0.5rem 0.5rem 0 0;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
.qti-catalog-popup__title {
|
|
127
|
-
font-weight: 600;
|
|
128
|
-
font-size: 0.85rem;
|
|
129
|
-
color: var(--color-base-content, #111);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
.qti-catalog-popup__close {
|
|
133
|
-
background: none;
|
|
134
|
-
border: none;
|
|
135
|
-
cursor: pointer;
|
|
136
|
-
font-size: 1rem;
|
|
137
|
-
line-height: 1;
|
|
138
|
-
padding: 0.2rem 0.4rem;
|
|
139
|
-
border-radius: 0.25rem;
|
|
140
|
-
color: var(--color-base-content, #111);
|
|
141
|
-
opacity: 0.6;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
.qti-catalog-popup__close:hover,
|
|
145
|
-
.qti-catalog-popup__close:focus-visible {
|
|
146
|
-
opacity: 1;
|
|
147
|
-
background: var(--color-base-300, #e5e7eb);
|
|
148
|
-
outline: 2px solid var(--color-primary, #4f46e5);
|
|
149
|
-
outline-offset: 1px;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
.qti-catalog-popup__body {
|
|
153
|
-
padding: 0.75rem;
|
|
154
|
-
color: var(--color-base-content, #111);
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
.qti-catalog-popup__img {
|
|
158
|
-
max-width: 100%;
|
|
159
|
-
height: auto;
|
|
160
|
-
display: block;
|
|
161
|
-
margin: 0 auto;
|
|
162
|
-
}
|
|
163
|
-
</style>
|
package/src/index.ts
DELETED
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @pie-qti/default-components
|
|
3
|
-
*
|
|
4
|
-
* Default Svelte-based component implementations for the QTI player.
|
|
5
|
-
* These components are packaged as web components that work with the
|
|
6
|
-
* framework-agnostic @pie-qti/item-player core.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
// Export shared utilities and helpers
|
|
10
|
-
export * from './shared/index.js';
|
|
11
|
-
|
|
12
|
-
interface DefaultComponentRegistration {
|
|
13
|
-
name: string;
|
|
14
|
-
description: string;
|
|
15
|
-
tagName: string;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
interface DefaultComponentRegistry {
|
|
19
|
-
register(type: string, component: DefaultComponentRegistration): void;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const DEFAULT_COMPONENTS_BY_TYPE = {
|
|
23
|
-
choiceInteraction: {
|
|
24
|
-
name: 'default-choice',
|
|
25
|
-
description: 'Default Svelte-based choice interaction',
|
|
26
|
-
tagName: 'pie-qti-choice',
|
|
27
|
-
},
|
|
28
|
-
sliderInteraction: {
|
|
29
|
-
name: 'default-slider',
|
|
30
|
-
description: 'Default Svelte-based slider interaction',
|
|
31
|
-
tagName: 'pie-qti-slider',
|
|
32
|
-
},
|
|
33
|
-
orderInteraction: {
|
|
34
|
-
name: 'default-order',
|
|
35
|
-
description: 'Default Svelte-based order interaction',
|
|
36
|
-
tagName: 'pie-qti-order',
|
|
37
|
-
},
|
|
38
|
-
matchInteraction: {
|
|
39
|
-
name: 'default-match',
|
|
40
|
-
description: 'Default Svelte-based match interaction',
|
|
41
|
-
tagName: 'pie-qti-match',
|
|
42
|
-
},
|
|
43
|
-
associateInteraction: {
|
|
44
|
-
name: 'default-associate',
|
|
45
|
-
description: 'Default Svelte-based associate interaction',
|
|
46
|
-
tagName: 'pie-qti-associate',
|
|
47
|
-
},
|
|
48
|
-
gapMatchInteraction: {
|
|
49
|
-
name: 'default-gap-match',
|
|
50
|
-
description: 'Default Svelte-based gap match interaction',
|
|
51
|
-
tagName: 'pie-qti-gap-match',
|
|
52
|
-
},
|
|
53
|
-
hotspotInteraction: {
|
|
54
|
-
name: 'default-hotspot',
|
|
55
|
-
description: 'Default Svelte-based hotspot interaction',
|
|
56
|
-
tagName: 'pie-qti-hotspot',
|
|
57
|
-
},
|
|
58
|
-
hottextInteraction: {
|
|
59
|
-
name: 'default-hottext',
|
|
60
|
-
description: 'Default Svelte-based hottext interaction',
|
|
61
|
-
tagName: 'pie-qti-hottext',
|
|
62
|
-
},
|
|
63
|
-
mediaInteraction: {
|
|
64
|
-
name: 'default-media',
|
|
65
|
-
description: 'Default Svelte-based media interaction',
|
|
66
|
-
tagName: 'pie-qti-media',
|
|
67
|
-
},
|
|
68
|
-
customInteraction: {
|
|
69
|
-
name: 'default-custom',
|
|
70
|
-
description: 'Default Svelte-based custom interaction',
|
|
71
|
-
tagName: 'pie-qti-custom',
|
|
72
|
-
},
|
|
73
|
-
endAttemptInteraction: {
|
|
74
|
-
name: 'default-end-attempt',
|
|
75
|
-
description: 'Default Svelte-based end attempt interaction',
|
|
76
|
-
tagName: 'pie-qti-end-attempt',
|
|
77
|
-
},
|
|
78
|
-
positionObjectInteraction: {
|
|
79
|
-
name: 'default-position-object',
|
|
80
|
-
description: 'Default Svelte-based position object interaction',
|
|
81
|
-
tagName: 'pie-qti-position-object',
|
|
82
|
-
},
|
|
83
|
-
graphicGapMatchInteraction: {
|
|
84
|
-
name: 'default-graphic-gap-match',
|
|
85
|
-
description: 'Default Svelte-based graphic gap match interaction',
|
|
86
|
-
tagName: 'pie-qti-graphic-gap-match',
|
|
87
|
-
},
|
|
88
|
-
graphicOrderInteraction: {
|
|
89
|
-
name: 'default-graphic-order',
|
|
90
|
-
description: 'Default Svelte-based graphic order interaction',
|
|
91
|
-
tagName: 'pie-qti-graphic-order',
|
|
92
|
-
},
|
|
93
|
-
graphicAssociateInteraction: {
|
|
94
|
-
name: 'default-graphic-associate',
|
|
95
|
-
description: 'Default Svelte-based graphic associate interaction',
|
|
96
|
-
tagName: 'pie-qti-graphic-associate',
|
|
97
|
-
},
|
|
98
|
-
selectPointInteraction: {
|
|
99
|
-
name: 'default-select-point',
|
|
100
|
-
description: 'Default Svelte-based select point interaction',
|
|
101
|
-
tagName: 'pie-qti-select-point',
|
|
102
|
-
},
|
|
103
|
-
extendedTextInteraction: {
|
|
104
|
-
name: 'default-extended-text',
|
|
105
|
-
description: 'Default Svelte-based extended text interaction',
|
|
106
|
-
tagName: 'pie-qti-extended-text',
|
|
107
|
-
},
|
|
108
|
-
uploadInteraction: {
|
|
109
|
-
name: 'default-upload',
|
|
110
|
-
description: 'Default Svelte-based upload interaction',
|
|
111
|
-
tagName: 'pie-qti-upload',
|
|
112
|
-
},
|
|
113
|
-
drawingInteraction: {
|
|
114
|
-
name: 'default-drawing',
|
|
115
|
-
description: 'Default Svelte-based drawing interaction',
|
|
116
|
-
tagName: 'pie-qti-drawing',
|
|
117
|
-
},
|
|
118
|
-
} satisfies Record<string, DefaultComponentRegistration>;
|
|
119
|
-
|
|
120
|
-
export function getDefaultComponentTypes(): string[] {
|
|
121
|
-
return Object.keys(DEFAULT_COMPONENTS_BY_TYPE);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* Register all default components with the ComponentRegistry.
|
|
126
|
-
*
|
|
127
|
-
* This function should be called once at application startup to make all default
|
|
128
|
-
* block interaction components available to the player. Inline interactions are
|
|
129
|
-
* rendered in-flow by @pie-qti/item-player.
|
|
130
|
-
*/
|
|
131
|
-
export function registerDefaultComponents(registry: DefaultComponentRegistry): void {
|
|
132
|
-
for (const [type, component] of Object.entries(DEFAULT_COMPONENTS_BY_TYPE)) {
|
|
133
|
-
registry.register(type, component);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
registry.register('catalogPopup', {
|
|
137
|
-
name: 'default-catalog-popup',
|
|
138
|
-
description: 'Default Svelte-based catalog popup dialog',
|
|
139
|
-
tagName: 'pie-qti-catalog-popup',
|
|
140
|
-
});
|
|
141
|
-
}
|
|
@@ -1,310 +0,0 @@
|
|
|
1
|
-
<svelte:options customElement="pie-qti-associate" />
|
|
2
|
-
|
|
3
|
-
<script lang="ts">
|
|
4
|
-
import type { AssociateInteractionData } from '@pie-qti/item-player';
|
|
5
|
-
import type { I18nProvider } from '@pie-qti/i18n';
|
|
6
|
-
import ShadowBaseStyles from '../../shared/components/ShadowBaseStyles.svelte';
|
|
7
|
-
import { parseJsonProp } from '../../shared/utils/webComponentHelpers';
|
|
8
|
-
import { isCompatibleMatchGroup } from '../../shared/utils/matchGroupUtils';
|
|
9
|
-
|
|
10
|
-
interface Props {
|
|
11
|
-
interaction?: AssociateInteractionData | string;
|
|
12
|
-
response?: string[] | null;
|
|
13
|
-
correctResponse?: string[] | null;
|
|
14
|
-
disabled?: boolean;
|
|
15
|
-
role?: string;
|
|
16
|
-
i18n?: I18nProvider;
|
|
17
|
-
selectedForPairing?: string | null;
|
|
18
|
-
onSelectionChange?: (selected: string | null) => void;
|
|
19
|
-
onChange?: (value: string[]) => void;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
let {
|
|
23
|
-
interaction = $bindable(),
|
|
24
|
-
response = $bindable(),
|
|
25
|
-
correctResponse = $bindable(),
|
|
26
|
-
disabled = false,
|
|
27
|
-
role = 'candidate',
|
|
28
|
-
i18n = $bindable(),
|
|
29
|
-
selectedForPairing: externalSelectedForPairing,
|
|
30
|
-
onSelectionChange,
|
|
31
|
-
onChange,
|
|
32
|
-
}: Props = $props();
|
|
33
|
-
|
|
34
|
-
// Parse props that may be JSON strings (web component usage)
|
|
35
|
-
const parsedInteraction = $derived(parseJsonProp<AssociateInteractionData>(interaction));
|
|
36
|
-
const parsedResponse = $derived(parseJsonProp<string[]>(response));
|
|
37
|
-
const parsedCorrectResponse = $derived(parseJsonProp<string[]>(correctResponse));
|
|
38
|
-
const isShowingCorrect = $derived(role === 'scorer' && parsedCorrectResponse !== null);
|
|
39
|
-
|
|
40
|
-
// Get reference to the root element for event dispatching
|
|
41
|
-
let rootElement: HTMLDivElement | undefined = $state();
|
|
42
|
-
|
|
43
|
-
// Use external selection state if provided, otherwise use internal state
|
|
44
|
-
let internalSelectedForPairing = $state<string | null>(null);
|
|
45
|
-
const selectedForPairing = $derived(externalSelectedForPairing ?? internalSelectedForPairing);
|
|
46
|
-
|
|
47
|
-
// Ensure response is always an array
|
|
48
|
-
const pairs = $derived(parsedResponse || []);
|
|
49
|
-
const helperId = $derived(`associate-helper-${parsedInteraction?.responseId ?? 'unknown'}`);
|
|
50
|
-
|
|
51
|
-
function emitChange(newPairs: string[]) {
|
|
52
|
-
response = newPairs;
|
|
53
|
-
// Call onChange callback if provided (for Svelte component usage)
|
|
54
|
-
onChange?.(newPairs);
|
|
55
|
-
// Dispatch custom event for web component usage - event will bubble up to the host element
|
|
56
|
-
if (rootElement) {
|
|
57
|
-
const event = new CustomEvent('qti-change', {
|
|
58
|
-
detail: {
|
|
59
|
-
responseId: parsedInteraction?.responseId,
|
|
60
|
-
value: newPairs,
|
|
61
|
-
timestamp: Date.now(),
|
|
62
|
-
},
|
|
63
|
-
bubbles: true,
|
|
64
|
-
composed: true,
|
|
65
|
-
});
|
|
66
|
-
rootElement.dispatchEvent(event);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function setSelectedForPairing(value: string | null) {
|
|
71
|
-
if (onSelectionChange) {
|
|
72
|
-
onSelectionChange(value);
|
|
73
|
-
} else {
|
|
74
|
-
internalSelectedForPairing = value;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// Choices that cannot be paired with the currently selected choice due to matchGroup constraints
|
|
79
|
-
const blockedChoices = $derived.by(() => {
|
|
80
|
-
if (!selectedForPairing || !parsedInteraction) return new Set<string>();
|
|
81
|
-
const src = parsedInteraction.choices.find((c) => c.identifier === selectedForPairing);
|
|
82
|
-
return new Set(
|
|
83
|
-
parsedInteraction.choices
|
|
84
|
-
.filter((c) => c.identifier !== selectedForPairing && !isCompatibleMatchGroup(src?.matchGroup, c.matchGroup))
|
|
85
|
-
.map((c) => c.identifier)
|
|
86
|
-
);
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
function handleChoiceClick(choiceId: string) {
|
|
90
|
-
if (disabled) return;
|
|
91
|
-
|
|
92
|
-
// If no item selected yet, select this one
|
|
93
|
-
if (selectedForPairing === null) {
|
|
94
|
-
setSelectedForPairing(choiceId);
|
|
95
|
-
}
|
|
96
|
-
// If same item clicked again, deselect
|
|
97
|
-
else if (selectedForPairing === choiceId) {
|
|
98
|
-
setSelectedForPairing(null);
|
|
99
|
-
}
|
|
100
|
-
// If different item clicked, check matchGroup compatibility then create a pair
|
|
101
|
-
else {
|
|
102
|
-
if (blockedChoices.has(choiceId)) return;
|
|
103
|
-
const newPair = `${selectedForPairing} ${choiceId}`;
|
|
104
|
-
const newPairs = [...pairs, newPair];
|
|
105
|
-
emitChange(newPairs);
|
|
106
|
-
setSelectedForPairing(null);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
function removePair(index: number) {
|
|
111
|
-
const newPairs = pairs.filter((_, i) => i !== index);
|
|
112
|
-
emitChange(newPairs);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
function isInPair(choiceId: string): boolean {
|
|
116
|
-
return pairs.some((p) => p.includes(choiceId));
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
function isCorrectPair(choiceId: string): boolean {
|
|
120
|
-
if (!isShowingCorrect) return false;
|
|
121
|
-
return (parsedCorrectResponse || []).some((p) => p.includes(choiceId));
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
function isCorrectPairMatch(id1: string, id2: string): boolean {
|
|
125
|
-
if (!isShowingCorrect || !parsedCorrectResponse) return false;
|
|
126
|
-
return parsedCorrectResponse.some(
|
|
127
|
-
(p) => p === `${id1} ${id2}` || p === `${id2} ${id1}`
|
|
128
|
-
);
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
function toPlainText(html: string): string {
|
|
132
|
-
return html.replace(/<[^>]*>/g, ' ').replace(/\s+/g, ' ').trim();
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
function getChoiceLabel(choice: { identifier: string; text: string }): string {
|
|
136
|
-
const text = toPlainText(choice.text);
|
|
137
|
-
return text ? `${choice.identifier}: ${text}` : choice.identifier;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
function getPairLabel(choice1: { identifier: string; text: string }, choice2: { identifier: string; text: string }): string {
|
|
141
|
-
return `${getChoiceLabel(choice1)} and ${getChoiceLabel(choice2)}`;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
const correctPairs = $derived(
|
|
145
|
-
isShowingCorrect && parsedCorrectResponse ? parsedCorrectResponse : []
|
|
146
|
-
);
|
|
147
|
-
</script>
|
|
148
|
-
|
|
149
|
-
<ShadowBaseStyles />
|
|
150
|
-
|
|
151
|
-
<div bind:this={rootElement} part="root" class="qti-associate-interaction space-y-3">
|
|
152
|
-
{#if !parsedInteraction}
|
|
153
|
-
<div class="alert alert-error">{i18n?.t('common.errorNoData', 'No interaction data provided')}</div>
|
|
154
|
-
{:else}
|
|
155
|
-
{#if parsedInteraction.prompt}
|
|
156
|
-
<p part="prompt" class="qti-associate-prompt font-semibold">{@html parsedInteraction.prompt}</p>
|
|
157
|
-
{/if}
|
|
158
|
-
|
|
159
|
-
<!-- Display choices as buttons that can be clicked to form pairs -->
|
|
160
|
-
<div part="choices" class="qti-associate-choices grid grid-cols-2 gap-2">
|
|
161
|
-
{#each parsedInteraction.choices as choice}
|
|
162
|
-
{@const isSelected = selectedForPairing === choice.identifier}
|
|
163
|
-
{@const inPair = isInPair(choice.identifier)}
|
|
164
|
-
{@const isCorrect = isCorrectPair(choice.identifier)}
|
|
165
|
-
{@const isBlocked = blockedChoices.has(choice.identifier)}
|
|
166
|
-
<button
|
|
167
|
-
part="choice"
|
|
168
|
-
class="btn btn-outline {isSelected ? 'btn-accent' : inPair ? 'btn-primary' : isCorrect ? 'btn-success' : 'btn-neutral'}"
|
|
169
|
-
class:opacity-40={isBlocked}
|
|
170
|
-
class:cursor-not-allowed={isBlocked}
|
|
171
|
-
type="button"
|
|
172
|
-
aria-label={getChoiceLabel(choice)}
|
|
173
|
-
aria-pressed={isSelected}
|
|
174
|
-
aria-disabled={isBlocked ? 'true' : undefined}
|
|
175
|
-
aria-describedby={helperId}
|
|
176
|
-
onclick={() => handleChoiceClick(choice.identifier)}
|
|
177
|
-
{disabled}
|
|
178
|
-
>
|
|
179
|
-
{@html choice.text}
|
|
180
|
-
{#if isSelected}
|
|
181
|
-
<span class="ml-2">◉</span>
|
|
182
|
-
{:else if inPair}
|
|
183
|
-
<span class="ml-2">✓</span>
|
|
184
|
-
{/if}
|
|
185
|
-
</button>
|
|
186
|
-
{/each}
|
|
187
|
-
</div>
|
|
188
|
-
|
|
189
|
-
<!-- Display correct associations when in scorer mode -->
|
|
190
|
-
{#if isShowingCorrect && correctPairs.length > 0}
|
|
191
|
-
<div part="correct-pairs-title" class="divider">
|
|
192
|
-
{i18n?.t('interactions.associate.correctAssociations') ?? 'Correct Associations'}
|
|
193
|
-
</div>
|
|
194
|
-
<div part="correct-pairs" class="qti-associate-pairs space-y-2">
|
|
195
|
-
{#each correctPairs as pair}
|
|
196
|
-
{@const [id1, id2] = pair.split(' ')}
|
|
197
|
-
{@const choice1 = parsedInteraction.choices.find((c: any) => c.identifier === id1)}
|
|
198
|
-
{@const choice2 = parsedInteraction.choices.find((c: any) => c.identifier === id2)}
|
|
199
|
-
{@const isInUserPairs = pairs.some((p) => p === pair || p === `${id2} ${id1}`)}
|
|
200
|
-
{#if choice1 && choice2}
|
|
201
|
-
<div
|
|
202
|
-
part="correct-pair"
|
|
203
|
-
class="qti-associate-pair flex items-center gap-4 p-2 bg-success/10 border border-success rounded"
|
|
204
|
-
>
|
|
205
|
-
<span class="flex-1">{choice1.text}</span>
|
|
206
|
-
<span class="text-success">↔</span>
|
|
207
|
-
<span class="flex-1">{choice2.text}</span>
|
|
208
|
-
<span class="badge badge-success badge-sm">
|
|
209
|
-
{i18n?.t('interactions.choice.correct', 'Correct') ?? 'Correct'}
|
|
210
|
-
</span>
|
|
211
|
-
</div>
|
|
212
|
-
{/if}
|
|
213
|
-
{/each}
|
|
214
|
-
</div>
|
|
215
|
-
{/if}
|
|
216
|
-
|
|
217
|
-
<!-- Display current pairs -->
|
|
218
|
-
{#if pairs.length > 0}
|
|
219
|
-
<div part="pairs-title" class="divider">
|
|
220
|
-
{i18n?.t('interactions.associate.currentAssociations') ?? 'Current Associations'}
|
|
221
|
-
</div>
|
|
222
|
-
<div part="pairs" class="qti-associate-pairs space-y-2">
|
|
223
|
-
{#each pairs as pair, index}
|
|
224
|
-
{@const [id1, id2] = pair.split(' ')}
|
|
225
|
-
{@const choice1 = parsedInteraction.choices.find((c: any) => c.identifier === id1)}
|
|
226
|
-
{@const choice2 = parsedInteraction.choices.find((c: any) => c.identifier === id2)}
|
|
227
|
-
{@const isCorrect = isCorrectPairMatch(id1, id2)}
|
|
228
|
-
{#if choice1 && choice2}
|
|
229
|
-
<div
|
|
230
|
-
part="pair"
|
|
231
|
-
class="qti-associate-pair flex items-center gap-4 p-2 rounded {isCorrect
|
|
232
|
-
? 'bg-success/10 border border-success'
|
|
233
|
-
: 'bg-primary/10 border border-base-300'}"
|
|
234
|
-
>
|
|
235
|
-
<span class="flex-1">{choice1.text}</span>
|
|
236
|
-
<span class="{isCorrect ? 'text-success' : 'text-primary'}">↔</span>
|
|
237
|
-
<span class="flex-1">{choice2.text}</span>
|
|
238
|
-
{#if isCorrect}
|
|
239
|
-
<span class="badge badge-success badge-sm">
|
|
240
|
-
{i18n?.t('interactions.choice.correct', 'Correct') ?? 'Correct'}
|
|
241
|
-
</span>
|
|
242
|
-
{/if}
|
|
243
|
-
<button
|
|
244
|
-
part="pair-remove"
|
|
245
|
-
class="btn btn-sm btn-ghost btn-circle"
|
|
246
|
-
type="button"
|
|
247
|
-
aria-label={`Remove association between ${getPairLabel(choice1, choice2)}`}
|
|
248
|
-
onclick={() => removePair(index)}
|
|
249
|
-
{disabled}
|
|
250
|
-
>
|
|
251
|
-
✕
|
|
252
|
-
</button>
|
|
253
|
-
</div>
|
|
254
|
-
{/if}
|
|
255
|
-
{/each}
|
|
256
|
-
</div>
|
|
257
|
-
{/if}
|
|
258
|
-
|
|
259
|
-
<!-- Selection helper - Hide when showing correct answers -->
|
|
260
|
-
{#if !isShowingCorrect}
|
|
261
|
-
<div id={helperId} part="helper" class="qti-associate-helper alert alert-info" role="status" aria-live="polite">
|
|
262
|
-
<span class="text-sm">
|
|
263
|
-
{#if selectedForPairing}
|
|
264
|
-
{i18n?.t('interactions.associate.clickAnotherOrDeselect') ??
|
|
265
|
-
'Select another item to create an association, or select this item again to deselect it.'}
|
|
266
|
-
{:else}
|
|
267
|
-
{i18n?.t('interactions.associate.clickToAssociate') ??
|
|
268
|
-
'Select two items to create an association between them. Keyboard users can tab to each item and press Enter or Space.'}
|
|
269
|
-
{/if}
|
|
270
|
-
</span>
|
|
271
|
-
</div>
|
|
272
|
-
{/if}
|
|
273
|
-
{/if}
|
|
274
|
-
</div>
|
|
275
|
-
|
|
276
|
-
<style>
|
|
277
|
-
/* Minimal layout so this works without Tailwind/DaisyUI */
|
|
278
|
-
.qti-associate-interaction {
|
|
279
|
-
display: grid;
|
|
280
|
-
gap: 0.75rem;
|
|
281
|
-
}
|
|
282
|
-
.qti-associate-prompt {
|
|
283
|
-
margin: 0;
|
|
284
|
-
}
|
|
285
|
-
.qti-associate-choices {
|
|
286
|
-
display: grid;
|
|
287
|
-
grid-template-columns: repeat(2, minmax(0, 1fr));
|
|
288
|
-
gap: 0.5rem;
|
|
289
|
-
}
|
|
290
|
-
@media (max-width: 640px) {
|
|
291
|
-
.qti-associate-choices {
|
|
292
|
-
grid-template-columns: 1fr;
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
.qti-associate-pairs {
|
|
296
|
-
display: grid;
|
|
297
|
-
gap: 0.5rem;
|
|
298
|
-
}
|
|
299
|
-
.qti-associate-pair {
|
|
300
|
-
display: flex;
|
|
301
|
-
align-items: center;
|
|
302
|
-
gap: 0.75rem;
|
|
303
|
-
padding: 0.5rem;
|
|
304
|
-
border-radius: 0.75rem;
|
|
305
|
-
}
|
|
306
|
-
.qti-associate-helper {
|
|
307
|
-
border: 1px solid var(--color-base-300, oklch(95% 0 0));
|
|
308
|
-
background: var(--color-base-200, oklch(98% 0 0));
|
|
309
|
-
}
|
|
310
|
-
</style>
|