@pie-qti/default-components 1.0.0-beta.3 → 1.0.0-beta.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.
- package/README.md +13 -0
- package/dist/chunks/mathlive.min-Cmxm6f5R.js.map +1 -1
- package/dist/index.js +13 -110
- package/dist/index.js.map +1 -1
- package/dist/plugins/extended-text/textInput.d.ts +47 -0
- package/dist/plugins/extended-text/textInput.js +65 -0
- package/dist/plugins/extended-text/textInput.js.map +1 -0
- package/dist/plugins/media/mediaPlayback.d.ts +39 -0
- package/dist/plugins/media/mediaPlayback.js +49 -0
- package/dist/plugins/media/mediaPlayback.js.map +1 -0
- package/dist/plugins.js +13689 -21735
- package/dist/plugins.js.map +1 -1
- package/dist/shared/components/icons.d.ts +12 -0
- package/dist/shared/components/icons.js +13 -0
- package/dist/shared/components/icons.js.map +1 -0
- package/dist/shared/components/keyboardCrosshair.svelte.d.ts +37 -0
- package/dist/shared/components/keyboardCrosshair.svelte.js +67 -0
- package/dist/shared/components/keyboardCrosshair.svelte.js.map +1 -0
- package/dist/shared/components/pickUpPlace.svelte.d.ts +42 -0
- package/dist/shared/components/pickUpPlace.svelte.js +58 -0
- package/dist/shared/components/pickUpPlace.svelte.js.map +1 -0
- package/dist/shared/extensions/MathLiveEditor.d.ts +33 -6
- package/dist/shared/extensions/MathLiveEditor.js +354 -175
- package/dist/shared/extensions/MathLiveEditor.js.map +1 -1
- package/dist/shared/extensions/modalDialog.d.ts +31 -0
- package/dist/shared/extensions/modalDialog.js +165 -0
- package/dist/shared/extensions/modalDialog.js.map +1 -0
- package/dist/shared/index.d.ts +1 -0
- package/dist/shared/index.js +2 -0
- package/dist/shared/index.js.map +1 -1
- package/dist/shared/styles/qti-pnp.css +44 -0
- package/dist/shared/styles/qti-shared-vocabulary.css +6 -2
- package/dist/shared/styles/srOnly.d.ts +23 -0
- package/dist/shared/styles/srOnly.js +70 -0
- package/dist/shared/styles/srOnly.js.map +1 -0
- package/dist/shared/utils/accessibleText.d.ts +24 -0
- package/dist/shared/utils/accessibleText.js +72 -0
- package/dist/shared/utils/accessibleText.js.map +1 -0
- package/dist/shared/utils/announcer.svelte.d.ts +26 -0
- package/dist/shared/utils/announcer.svelte.js +30 -0
- package/dist/shared/utils/announcer.svelte.js.map +1 -0
- package/dist/shared/utils/capacity.d.ts +26 -0
- package/dist/shared/utils/capacity.js +37 -0
- package/dist/shared/utils/capacity.js.map +1 -0
- package/dist/shared/utils/choiceName.d.ts +44 -0
- package/dist/shared/utils/choiceName.js +28 -0
- package/dist/shared/utils/choiceName.js.map +1 -0
- package/dist/shared/utils/confirmationFlow.svelte.d.ts +31 -0
- package/dist/shared/utils/confirmationFlow.svelte.js +41 -0
- package/dist/shared/utils/confirmationFlow.svelte.js.map +1 -0
- package/dist/shared/utils/eliminationTool.svelte.d.ts +11 -0
- package/dist/shared/utils/eliminationTool.svelte.js +26 -0
- package/dist/shared/utils/eliminationTool.svelte.js.map +1 -0
- package/dist/shared/utils/graphicRegions.d.ts +78 -0
- package/dist/shared/utils/graphicRegions.js +169 -0
- package/dist/shared/utils/graphicRegions.js.map +1 -0
- package/dist/shared/utils/interactionAria.d.ts +18 -5
- package/dist/shared/utils/interactionAria.js +42 -3
- package/dist/shared/utils/interactionAria.js.map +1 -1
- package/dist/shared/utils/interactionProps.d.ts +52 -0
- package/dist/shared/utils/interactionProps.js +14 -0
- package/dist/shared/utils/interactionProps.js.map +1 -0
- package/dist/shared/utils/matchGroupUtils.d.ts +26 -4
- package/dist/shared/utils/matchGroupUtils.js +25 -8
- package/dist/shared/utils/matchGroupUtils.js.map +1 -1
- package/dist/shared/utils/minimumRequirement.d.ts +56 -0
- package/dist/shared/utils/minimumRequirement.js +50 -0
- package/dist/shared/utils/minimumRequirement.js.map +1 -0
- package/dist/shared/utils/pairHelpers.d.ts +46 -12
- package/dist/shared/utils/pairHelpers.js +64 -12
- package/dist/shared/utils/pairHelpers.js.map +1 -1
- package/dist/shared/utils/radioGroup.d.ts +13 -0
- package/dist/shared/utils/radioGroup.js +27 -0
- package/dist/shared/utils/radioGroup.js.map +1 -0
- package/dist/shared/utils/stageImage.svelte.d.ts +56 -0
- package/dist/shared/utils/stageImage.svelte.js +76 -0
- package/dist/shared/utils/stageImage.svelte.js.map +1 -0
- package/dist/shared/utils/webComponentHelpers.d.ts +37 -5
- package/dist/shared/utils/webComponentHelpers.js +72 -19
- package/dist/shared/utils/webComponentHelpers.js.map +1 -1
- package/dist/shared.css +2 -0
- package/package.json +20 -31
- package/dist/assets/default-components.css +0 -2
- package/dist/chunks/__vite-browser-external-DwKjyYZK.js +0 -9
- package/dist/chunks/__vite-browser-external-DwKjyYZK.js.map +0 -1
- package/dist/chunks/ar-Cqx9S4Im.js +0 -919
- package/dist/chunks/ar-Cqx9S4Im.js.map +0 -1
- package/dist/chunks/es-DjA7IQ-N.js +0 -864
- package/dist/chunks/es-DjA7IQ-N.js.map +0 -1
- package/dist/chunks/fr-BhV6wQNG.js +0 -864
- package/dist/chunks/fr-BhV6wQNG.js.map +0 -1
- package/dist/chunks/nl-B0JlnB-a.js +0 -863
- package/dist/chunks/nl-B0JlnB-a.js.map +0 -1
- package/dist/chunks/ro-ClR0jejm.js +0 -864
- package/dist/chunks/ro-ClR0jejm.js.map +0 -1
- package/dist/chunks/rolldown-runtime-Y_bBpyJl.js +0 -20
- package/dist/chunks/th-RfNMAg5z.js +0 -863
- package/dist/chunks/th-RfNMAg5z.js.map +0 -1
- package/dist/chunks/zh-Hans-DJ82CLmG.js +0 -863
- package/dist/chunks/zh-Hans-DJ82CLmG.js.map +0 -1
|
@@ -1,15 +1,7 @@
|
|
|
1
1
|
/// <reference lib="dom" />
|
|
2
|
-
/**
|
|
3
|
-
* MathLive Editor Extension for TipTap
|
|
4
|
-
*
|
|
5
|
-
* Integrates MathLive (visual math editor) with TipTap's Mathematics extension.
|
|
6
|
-
* Provides a modal dialog with MathLive mathfield for editing LaTeX formulas.
|
|
7
|
-
*
|
|
8
|
-
* Note: MathLive CSS is loaded dynamically to avoid build issues with package exports.
|
|
9
|
-
*/
|
|
10
|
-
import { isImeComposing } from '@pie-qti/i18n';
|
|
11
2
|
// Import MathLive CSS from the local package
|
|
12
3
|
import 'mathlive/static.css';
|
|
4
|
+
import { createModalDialog, getFocusableElements } from './modalDialog.js';
|
|
13
5
|
// Dynamically import MathLive to register the custom element
|
|
14
6
|
let mathLiveLoaded = null;
|
|
15
7
|
async function ensureMathLiveLoaded() {
|
|
@@ -22,16 +14,162 @@ async function ensureMathLiveLoaded() {
|
|
|
22
14
|
}
|
|
23
15
|
return mathLiveLoaded || Promise.resolve();
|
|
24
16
|
}
|
|
17
|
+
/** The candidate-visible strings, from `interactions.mathInput` (and `common.cancel`). */
|
|
18
|
+
function createTranslator(i18n) {
|
|
19
|
+
return (key, fallback) => {
|
|
20
|
+
const translated = i18n?.t(key, fallback);
|
|
21
|
+
return translated && translated !== key ? translated : fallback;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
let dialogCount = 0;
|
|
25
|
+
/** Dialog styles that must hold without the host's DaisyUI/Tailwind classes. */
|
|
26
|
+
const DIALOG_STYLES = `
|
|
27
|
+
/* Keep MathLive's virtual keyboard above the modal. Its container spans the
|
|
28
|
+
whole viewport and must keep MathLive's own pointer-events: none (only the
|
|
29
|
+
keyboard panel takes clicks), or it would block the dialog's buttons. */
|
|
30
|
+
.ML__keyboard {
|
|
31
|
+
z-index: 10001 !important;
|
|
32
|
+
}
|
|
33
|
+
/* Hide the built-in keyboard toggle button in the mathfield - try multiple selectors */
|
|
34
|
+
.ML__virtual-keyboard-toggle,
|
|
35
|
+
.ML__keyboard-toggle,
|
|
36
|
+
math-field::part(virtual-keyboard-toggle) {
|
|
37
|
+
display: none !important;
|
|
38
|
+
visibility: hidden !important;
|
|
39
|
+
opacity: 0 !important;
|
|
40
|
+
pointer-events: none !important;
|
|
41
|
+
}
|
|
42
|
+
.pie-qti-math-dialog {
|
|
43
|
+
box-sizing: border-box;
|
|
44
|
+
inline-size: min(42rem, calc(100vw - 2rem));
|
|
45
|
+
/* Of the backdrop's content box, which excludes an open virtual keyboard. */
|
|
46
|
+
max-block-size: calc(100% - 2rem);
|
|
47
|
+
overflow: auto;
|
|
48
|
+
padding: 1.5rem;
|
|
49
|
+
border-radius: 0.75rem;
|
|
50
|
+
background: var(--pie-qti-base-100, #ffffff);
|
|
51
|
+
color: var(--pie-qti-base-content, #1f2937);
|
|
52
|
+
position: relative;
|
|
53
|
+
z-index: 10000;
|
|
54
|
+
}
|
|
55
|
+
.pie-qti-math-dialog-title {
|
|
56
|
+
margin-block: 0 0.5rem;
|
|
57
|
+
font-size: 1.125rem;
|
|
58
|
+
font-weight: 700;
|
|
59
|
+
}
|
|
60
|
+
.pie-qti-math-dialog-instructions {
|
|
61
|
+
margin-block: 0 1rem;
|
|
62
|
+
}
|
|
63
|
+
.pie-qti-math-dialog-field-label {
|
|
64
|
+
display: block;
|
|
65
|
+
margin-block-end: 0.5rem;
|
|
66
|
+
font-weight: 600;
|
|
67
|
+
}
|
|
68
|
+
.pie-qti-math-dialog math-field {
|
|
69
|
+
display: block;
|
|
70
|
+
box-sizing: border-box;
|
|
71
|
+
inline-size: 100%;
|
|
72
|
+
min-block-size: 100px;
|
|
73
|
+
padding: 0.75rem;
|
|
74
|
+
font-size: 1.125rem;
|
|
75
|
+
border: 1px solid var(--pie-qti-border-strong, #767676);
|
|
76
|
+
border-radius: 0.5rem;
|
|
77
|
+
}
|
|
78
|
+
.pie-qti-math-dialog math-field:focus-within {
|
|
79
|
+
outline: 2px solid var(--pie-qti-focus, #4338ca);
|
|
80
|
+
outline-offset: 2px;
|
|
81
|
+
}
|
|
82
|
+
.pie-qti-math-dialog-source-label {
|
|
83
|
+
margin-block: 1rem 0.25rem;
|
|
84
|
+
font-weight: 600;
|
|
85
|
+
}
|
|
86
|
+
.pie-qti-math-dialog-source {
|
|
87
|
+
display: block;
|
|
88
|
+
margin-block-end: 1rem;
|
|
89
|
+
padding: 0.5rem 0.75rem;
|
|
90
|
+
border: 1px solid var(--pie-qti-border-strong, #767676);
|
|
91
|
+
border-radius: 0.5rem;
|
|
92
|
+
font-family: 'Monaco', 'Courier New', monospace;
|
|
93
|
+
font-size: 0.875rem;
|
|
94
|
+
word-break: break-all;
|
|
95
|
+
}
|
|
96
|
+
.pie-qti-math-dialog-source[data-empty='true'] {
|
|
97
|
+
font-style: italic;
|
|
98
|
+
}
|
|
99
|
+
.pie-qti-math-dialog-actions {
|
|
100
|
+
display: flex;
|
|
101
|
+
flex-wrap: wrap;
|
|
102
|
+
justify-content: space-between;
|
|
103
|
+
gap: 0.5rem;
|
|
104
|
+
}
|
|
105
|
+
.pie-qti-math-dialog-actions > div {
|
|
106
|
+
display: flex;
|
|
107
|
+
flex-wrap: wrap;
|
|
108
|
+
gap: 0.5rem;
|
|
109
|
+
}
|
|
110
|
+
.pie-qti-math-dialog button {
|
|
111
|
+
box-sizing: border-box;
|
|
112
|
+
min-block-size: 2.75rem;
|
|
113
|
+
min-inline-size: 2.75rem;
|
|
114
|
+
padding-block: 0.5rem;
|
|
115
|
+
padding-inline: 1rem;
|
|
116
|
+
border: 1px solid var(--pie-qti-border-strong, #767676);
|
|
117
|
+
border-radius: 0.5rem;
|
|
118
|
+
background: var(--pie-qti-base-100, #ffffff);
|
|
119
|
+
color: var(--pie-qti-base-content, #1f2937);
|
|
120
|
+
font: inherit;
|
|
121
|
+
cursor: pointer;
|
|
122
|
+
}
|
|
123
|
+
.pie-qti-math-dialog button:focus-visible {
|
|
124
|
+
outline: 2px solid var(--pie-qti-focus, #4338ca);
|
|
125
|
+
outline-offset: 2px;
|
|
126
|
+
}
|
|
127
|
+
.pie-qti-math-dialog button[aria-pressed='true'] {
|
|
128
|
+
font-weight: 700;
|
|
129
|
+
border-width: 2px;
|
|
130
|
+
}
|
|
131
|
+
`;
|
|
132
|
+
function sharedVirtualKeyboard() {
|
|
133
|
+
return globalThis.mathVirtualKeyboard;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Hosts dispatch this on `document` when transient UI must close: the assessment shell does on
|
|
137
|
+
* a proctor pause (`detail.reason: 'pause'`), so no dialog stays open, or traps focus, under the
|
|
138
|
+
* pause overlay. The dialog closes through its cancel path, reporting the interruption and the
|
|
139
|
+
* LaTeX typed so far (`MathLiveEditorCancelDetails`), so the opener can offer it again.
|
|
140
|
+
*/
|
|
141
|
+
const CLOSE_TRANSIENT_UI_EVENT = 'pie-qti-close-transient-ui';
|
|
25
142
|
/**
|
|
26
|
-
* Opens a modal dialog with MathLive editor for LaTeX input
|
|
143
|
+
* Opens a modal dialog with MathLive editor for LaTeX input.
|
|
144
|
+
* Resolves to a function that closes the dialog without calling either callback.
|
|
27
145
|
*/
|
|
28
146
|
export async function openMathLiveEditor(options) {
|
|
29
147
|
const { onConfirm, onCancel, initialLatex = '', isBlock = false } = options;
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
//
|
|
148
|
+
const mode = options.mode ?? (initialLatex ? 'edit' : 'insert');
|
|
149
|
+
const t = createTranslator(options.i18n);
|
|
150
|
+
// Capture the opener before loading MathLive, while it still holds focus.
|
|
151
|
+
const opener = options.returnFocusTo ?? document.activeElement;
|
|
152
|
+
// Ensure MathLive is loaded and registered before creating the mathfield. A request to
|
|
153
|
+
// close transient UI while it loads cancels the dialog before it ever opens.
|
|
154
|
+
let closedWhileLoading = false;
|
|
155
|
+
const cancelWhileLoading = () => {
|
|
156
|
+
closedWhileLoading = true;
|
|
157
|
+
};
|
|
158
|
+
document.addEventListener(CLOSE_TRANSIENT_UI_EVENT, cancelWhileLoading);
|
|
159
|
+
try {
|
|
160
|
+
await ensureMathLiveLoaded();
|
|
161
|
+
}
|
|
162
|
+
finally {
|
|
163
|
+
document.removeEventListener(CLOSE_TRANSIENT_UI_EVENT, cancelWhileLoading);
|
|
164
|
+
}
|
|
165
|
+
if (closedWhileLoading) {
|
|
166
|
+
onCancel({ interrupted: true, latex: initialLatex });
|
|
167
|
+
return () => { };
|
|
168
|
+
}
|
|
169
|
+
const id = `pie-qti-math-dialog-${++dialogCount}`;
|
|
170
|
+
// Backdrop - keeps DaisyUI modal classes for hosts that theme them
|
|
33
171
|
const overlay = document.createElement('div');
|
|
34
|
-
overlay.className = 'modal modal-open';
|
|
172
|
+
overlay.className = 'modal modal-open pie-qti-math-dialog-backdrop';
|
|
35
173
|
overlay.style.cssText = `
|
|
36
174
|
position: fixed;
|
|
37
175
|
inset: 0;
|
|
@@ -41,38 +179,42 @@ export async function openMathLiveEditor(options) {
|
|
|
41
179
|
justify-content: center;
|
|
42
180
|
z-index: 9999;
|
|
43
181
|
`;
|
|
44
|
-
//
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
//
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
182
|
+
// The dialog itself: a named, described modal
|
|
183
|
+
const dialog = document.createElement('div');
|
|
184
|
+
dialog.className = 'modal-box max-w-2xl pie-qti-math-dialog';
|
|
185
|
+
dialog.setAttribute('role', 'dialog');
|
|
186
|
+
dialog.setAttribute('aria-modal', 'true');
|
|
187
|
+
dialog.setAttribute('aria-labelledby', `${id}-title`);
|
|
188
|
+
dialog.setAttribute('aria-describedby', `${id}-instructions`);
|
|
189
|
+
// The dialog lives in the document body, outside the editor's shadow root:
|
|
190
|
+
// carry the opener's writing direction across.
|
|
191
|
+
if (opener?.isConnected && getComputedStyle(opener).direction === 'rtl')
|
|
192
|
+
dialog.dir = 'rtl';
|
|
193
|
+
const title = document.createElement('h2');
|
|
194
|
+
title.id = `${id}-title`;
|
|
195
|
+
title.className = 'pie-qti-math-dialog-title';
|
|
196
|
+
title.textContent =
|
|
197
|
+
mode === 'edit'
|
|
198
|
+
? isBlock
|
|
199
|
+
? t('interactions.mathInput.editBlockTitle', 'Edit block math')
|
|
200
|
+
: t('interactions.mathInput.editInlineTitle', 'Edit inline math')
|
|
201
|
+
: isBlock
|
|
202
|
+
? t('interactions.mathInput.insertBlockTitle', 'Insert block math')
|
|
203
|
+
: t('interactions.mathInput.insertInlineTitle', 'Insert inline math');
|
|
204
|
+
const instructions = document.createElement('p');
|
|
205
|
+
instructions.id = `${id}-instructions`;
|
|
206
|
+
instructions.className = 'pie-qti-math-dialog-instructions';
|
|
207
|
+
instructions.textContent = t('interactions.mathInput.instructions', 'Type the expression, or open the math keyboard. Press Escape to cancel.');
|
|
208
|
+
// The mathfield's label: associated both ways MathLive resolves a name
|
|
209
|
+
const fieldLabel = document.createElement('label');
|
|
210
|
+
fieldLabel.id = `${id}-field-label`;
|
|
211
|
+
fieldLabel.htmlFor = `${id}-field`;
|
|
212
|
+
fieldLabel.className = 'pie-qti-math-dialog-field-label';
|
|
213
|
+
fieldLabel.textContent = t('interactions.mathInput.fieldLabel', 'Math expression');
|
|
67
214
|
const mathfield = document.createElement('math-field');
|
|
215
|
+
mathfield.id = `${id}-field`;
|
|
216
|
+
mathfield.setAttribute('aria-labelledby', fieldLabel.id);
|
|
68
217
|
mathfield.value = initialLatex;
|
|
69
|
-
mathfield.className = 'input input-bordered w-full';
|
|
70
|
-
mathfield.style.cssText = `
|
|
71
|
-
display: block;
|
|
72
|
-
min-height: 100px;
|
|
73
|
-
padding: 0.75rem;
|
|
74
|
-
font-size: 1.125rem;
|
|
75
|
-
`;
|
|
76
218
|
// Set MathLive options for better UX via attributes
|
|
77
219
|
// Use 'manual' mode so keyboard only shows when explicitly requested
|
|
78
220
|
mathfield.setAttribute('virtual-keyboard-mode', 'manual');
|
|
@@ -81,162 +223,199 @@ export async function openMathLiveEditor(options) {
|
|
|
81
223
|
mathfield.setAttribute('use-shared-virtual-keyboard', 'true');
|
|
82
224
|
// Hide the built-in virtual keyboard toggle
|
|
83
225
|
mathfield.setAttribute('virtual-keyboard-toggle-glyph', '');
|
|
84
|
-
// Inject CSS
|
|
226
|
+
// Inject CSS: virtual keyboard layering and the dialog's own fallback styles
|
|
85
227
|
const style = document.createElement('style');
|
|
86
|
-
style.textContent =
|
|
87
|
-
/* Ensure MathLive virtual keyboard appears above the modal and is clickable */
|
|
88
|
-
.ML__keyboard {
|
|
89
|
-
z-index: 10001 !important;
|
|
90
|
-
pointer-events: auto !important;
|
|
91
|
-
}
|
|
92
|
-
/* Hide the built-in keyboard toggle button in the mathfield - try multiple selectors */
|
|
93
|
-
.ML__virtual-keyboard-toggle,
|
|
94
|
-
.ML__keyboard-toggle,
|
|
95
|
-
math-field::part(virtual-keyboard-toggle) {
|
|
96
|
-
display: none !important;
|
|
97
|
-
visibility: hidden !important;
|
|
98
|
-
opacity: 0 !important;
|
|
99
|
-
pointer-events: none !important;
|
|
100
|
-
}
|
|
101
|
-
`;
|
|
228
|
+
style.textContent = DIALOG_STYLES;
|
|
102
229
|
document.head.appendChild(style);
|
|
103
|
-
//
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
font-size: 0.875rem;
|
|
116
|
-
word-break: break-all;
|
|
117
|
-
margin-bottom: 1rem;
|
|
118
|
-
`;
|
|
119
|
-
latexPreview.textContent = initialLatex || '(LaTeX will appear here)';
|
|
230
|
+
// LaTeX source preview: a visual aid; the mathfield itself is what assistive technology reads
|
|
231
|
+
const sourceLabel = document.createElement('p');
|
|
232
|
+
sourceLabel.className = 'pie-qti-math-dialog-source-label';
|
|
233
|
+
sourceLabel.textContent = t('interactions.mathInput.latexSourceLabel', 'LaTeX source');
|
|
234
|
+
const latexPreview = document.createElement('code');
|
|
235
|
+
latexPreview.className = 'pie-qti-math-dialog-source';
|
|
236
|
+
const latexEmpty = t('interactions.mathInput.latexEmpty', 'LaTeX will appear here');
|
|
237
|
+
const showLatex = (latex) => {
|
|
238
|
+
latexPreview.textContent = latex || latexEmpty;
|
|
239
|
+
latexPreview.dataset.empty = latex ? 'false' : 'true';
|
|
240
|
+
};
|
|
241
|
+
showLatex(initialLatex);
|
|
120
242
|
// Update preview when mathfield changes
|
|
121
|
-
mathfield.addEventListener('input', () =>
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
const
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
243
|
+
mathfield.addEventListener('input', () => showLatex(mathfield.value));
|
|
244
|
+
// Actions: keyboard toggle on one side, cancel/confirm on the other
|
|
245
|
+
const actions = document.createElement('div');
|
|
246
|
+
actions.className = 'modal-action pie-qti-math-dialog-actions';
|
|
247
|
+
const leftActions = document.createElement('div');
|
|
248
|
+
const rightActions = document.createElement('div');
|
|
249
|
+
const keyboardButton = document.createElement('button');
|
|
250
|
+
keyboardButton.type = 'button';
|
|
251
|
+
keyboardButton.className = 'btn btn-sm btn-outline';
|
|
252
|
+
keyboardButton.textContent = t('interactions.mathInput.toggleKeyboard', 'Math keyboard');
|
|
253
|
+
const syncKeyboardState = () => {
|
|
254
|
+
const keyboard = sharedVirtualKeyboard();
|
|
255
|
+
keyboardButton.setAttribute('aria-pressed', keyboard?.visible ? 'true' : 'false');
|
|
256
|
+
// The virtual keyboard docks over the bottom of the page, above this dialog:
|
|
257
|
+
// reserve its height so the dialog (and the focused control) stays visible.
|
|
258
|
+
const height = keyboard?.visible ? (keyboard.boundingRect?.height ?? 0) : 0;
|
|
259
|
+
overlay.style.paddingBlockEnd = height > 0 ? `${Math.ceil(height)}px` : '';
|
|
260
|
+
};
|
|
261
|
+
syncKeyboardState();
|
|
262
|
+
keyboardButton.addEventListener('click', () => {
|
|
138
263
|
if (mathfield.executeCommand) {
|
|
139
264
|
mathfield.executeCommand('toggleVirtualKeyboard');
|
|
140
265
|
}
|
|
266
|
+
syncKeyboardState();
|
|
267
|
+
});
|
|
268
|
+
sharedVirtualKeyboard()?.addEventListener?.('virtual-keyboard-toggle', syncKeyboardState);
|
|
269
|
+
sharedVirtualKeyboard()?.addEventListener?.('geometrychange', syncKeyboardState);
|
|
270
|
+
const cancelButton = document.createElement('button');
|
|
271
|
+
cancelButton.type = 'button';
|
|
272
|
+
cancelButton.className = 'btn btn-ghost';
|
|
273
|
+
cancelButton.textContent = t('common.cancel', 'Cancel');
|
|
274
|
+
const confirmButton = document.createElement('button');
|
|
275
|
+
confirmButton.type = 'button';
|
|
276
|
+
confirmButton.className = 'btn btn-primary';
|
|
277
|
+
confirmButton.textContent =
|
|
278
|
+
mode === 'edit'
|
|
279
|
+
? t('interactions.mathInput.update', 'Update')
|
|
280
|
+
: t('interactions.mathInput.insert', 'Insert');
|
|
281
|
+
leftActions.appendChild(keyboardButton);
|
|
282
|
+
rightActions.appendChild(cancelButton);
|
|
283
|
+
rightActions.appendChild(confirmButton);
|
|
284
|
+
actions.appendChild(leftActions);
|
|
285
|
+
actions.appendChild(rightActions);
|
|
286
|
+
dialog.appendChild(title);
|
|
287
|
+
dialog.appendChild(instructions);
|
|
288
|
+
dialog.appendChild(fieldLabel);
|
|
289
|
+
dialog.appendChild(mathfield);
|
|
290
|
+
dialog.appendChild(sourceLabel);
|
|
291
|
+
dialog.appendChild(latexPreview);
|
|
292
|
+
dialog.appendChild(actions);
|
|
293
|
+
overlay.appendChild(dialog);
|
|
294
|
+
const previousOverflow = document.body.style.overflow;
|
|
295
|
+
let closed = false;
|
|
296
|
+
let focusTimer;
|
|
297
|
+
// Add to DOM, then make it modal
|
|
298
|
+
document.body.appendChild(overlay);
|
|
299
|
+
// Prevent body scroll when modal is open
|
|
300
|
+
document.body.style.overflow = 'hidden';
|
|
301
|
+
const modal = createModalDialog(dialog, {
|
|
302
|
+
initialFocus: mathfield,
|
|
303
|
+
returnFocusTo: opener,
|
|
304
|
+
onEscape: () => close(false),
|
|
305
|
+
});
|
|
306
|
+
// MathLive reports when an arrow/Tab key has nowhere to go inside the field
|
|
307
|
+
// (`move-out`): wrap focus to the dialog's controls instead of staying stuck.
|
|
308
|
+
// The dialog's own Tab handler only covers keys MathLive did not claim, so
|
|
309
|
+
// this is what makes forward wrapping work from the field.
|
|
310
|
+
const handleMoveOut = (event) => {
|
|
311
|
+
if (closed)
|
|
312
|
+
return;
|
|
313
|
+
const direction = event.detail?.direction;
|
|
314
|
+
const focusable = getFocusableElements(dialog);
|
|
315
|
+
if (focusable.length === 0)
|
|
316
|
+
return;
|
|
317
|
+
if (direction === 'backward')
|
|
318
|
+
focusable[focusable.length - 1].focus();
|
|
319
|
+
else if (direction === 'forward')
|
|
320
|
+
focusable[0].focus();
|
|
321
|
+
};
|
|
322
|
+
mathfield.addEventListener('move-out', handleMoveOut);
|
|
323
|
+
// MathLive claims Tab/Shift+Tab for placeholder navigation and prevents default
|
|
324
|
+
// even at the field's boundary — including empty fields, where it dispatches no
|
|
325
|
+
// `move-out` — so the dialog's Tab trap never sees those keys and backward
|
|
326
|
+
// navigation is dead. Interaction model for this dialog: Tab keeps MathLive's
|
|
327
|
+
// placeholder navigation (forward wrapping via `move-out`); Shift+Tab always
|
|
328
|
+
// leaves the field backward. Reverse placeholder traversal stays on the arrow
|
|
329
|
+
// keys, which MathLive exits correctly via `move-out`.
|
|
330
|
+
const handleFieldShiftTabCapture = (event) => {
|
|
331
|
+
if (closed || event.key !== 'Tab' || !event.shiftKey)
|
|
332
|
+
return;
|
|
333
|
+
if (!event.composedPath().includes(mathfield))
|
|
334
|
+
return;
|
|
335
|
+
event.preventDefault();
|
|
336
|
+
event.stopPropagation();
|
|
337
|
+
const focusable = getFocusableElements(dialog);
|
|
338
|
+
if (focusable.length === 0)
|
|
339
|
+
return;
|
|
340
|
+
focusable[focusable.length - 1].focus();
|
|
141
341
|
};
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
const insertBtn = document.createElement('button');
|
|
153
|
-
insertBtn.textContent = initialLatex
|
|
154
|
-
? (options.i18n?.t('interactions.extendedText.update') ?? 'Update')
|
|
155
|
-
: (options.i18n?.t('interactions.extendedText.insert') ?? 'Insert');
|
|
156
|
-
insertBtn.type = 'button';
|
|
157
|
-
insertBtn.className = 'btn btn-primary';
|
|
158
|
-
rightButtons.appendChild(cancelBtn);
|
|
159
|
-
rightButtons.appendChild(insertBtn);
|
|
160
|
-
// Assemble modal
|
|
161
|
-
buttons.appendChild(leftButtons);
|
|
162
|
-
buttons.appendChild(rightButtons);
|
|
163
|
-
// Assemble form-control
|
|
164
|
-
formControl.appendChild(label);
|
|
165
|
-
formControl.appendChild(mathfield);
|
|
166
|
-
formControl.appendChild(previewLabel);
|
|
167
|
-
formControl.appendChild(latexPreview);
|
|
168
|
-
modal.appendChild(header);
|
|
169
|
-
modal.appendChild(formControl);
|
|
170
|
-
modal.appendChild(buttons);
|
|
171
|
-
overlay.appendChild(modal);
|
|
172
|
-
// Cleanup function
|
|
173
|
-
const cleanup = () => {
|
|
174
|
-
// Remove event listeners to prevent memory leaks
|
|
175
|
-
cancelBtn.removeEventListener('click', handleCancel);
|
|
176
|
-
insertBtn.removeEventListener('click', handleConfirm);
|
|
177
|
-
document.removeEventListener('keydown', handleEscape);
|
|
342
|
+
document.addEventListener('keydown', handleFieldShiftTabCapture, true);
|
|
343
|
+
function teardown() {
|
|
344
|
+
closed = true;
|
|
345
|
+
if (focusTimer !== undefined)
|
|
346
|
+
clearTimeout(focusTimer);
|
|
347
|
+
mathfield.removeEventListener('move-out', handleMoveOut);
|
|
348
|
+
document.removeEventListener('keydown', handleFieldShiftTabCapture, true);
|
|
349
|
+
document.removeEventListener(CLOSE_TRANSIENT_UI_EVENT, handleCloseTransientUi);
|
|
350
|
+
cancelButton.removeEventListener('click', handleCancel);
|
|
351
|
+
confirmButton.removeEventListener('click', handleConfirm);
|
|
178
352
|
overlay.removeEventListener('click', handleOverlayClick);
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
353
|
+
sharedVirtualKeyboard()?.removeEventListener?.('virtual-keyboard-toggle', syncKeyboardState);
|
|
354
|
+
sharedVirtualKeyboard()?.removeEventListener?.('geometrychange', syncKeyboardState);
|
|
355
|
+
// Hide the shared virtual keyboard through its own API: the mathfield's
|
|
356
|
+
// `hideVirtualKeyboard` command would refocus the field and schedule an
|
|
357
|
+
// update that runs after the field is gone.
|
|
358
|
+
const keyboard = sharedVirtualKeyboard();
|
|
359
|
+
if (keyboard?.visible)
|
|
360
|
+
keyboard.hide?.();
|
|
183
361
|
// Remove DOM elements
|
|
184
362
|
overlay.remove();
|
|
185
363
|
style.remove();
|
|
186
364
|
// Restore body scroll
|
|
187
|
-
document.body.style.overflow =
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
const handleConfirm = () => {
|
|
365
|
+
document.body.style.overflow = previousOverflow;
|
|
366
|
+
// Return focus to the control that opened the dialog
|
|
367
|
+
modal.release();
|
|
368
|
+
}
|
|
369
|
+
function close(confirmed, interrupted = false) {
|
|
370
|
+
if (closed)
|
|
371
|
+
return;
|
|
195
372
|
const latex = mathfield.value;
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
373
|
+
teardown();
|
|
374
|
+
if (confirmed)
|
|
375
|
+
onConfirm(latex);
|
|
376
|
+
else
|
|
377
|
+
onCancel({ interrupted, latex });
|
|
378
|
+
}
|
|
379
|
+
const handleCancel = () => close(false);
|
|
380
|
+
const handleConfirm = () => close(true);
|
|
381
|
+
// A host closing transient UI (a proctor pause) cancels: the focus trap is released and
|
|
382
|
+
// focus returns to the opener, so the host's own overlay can take it. The typed LaTeX goes
|
|
383
|
+
// to the opener as an interrupted cancel, so it can be offered again after the pause.
|
|
384
|
+
const handleCloseTransientUi = () => close(false, true);
|
|
204
385
|
const handleOverlayClick = (e) => {
|
|
205
|
-
//
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
// Additional check: don't close if virtual keyboard is open
|
|
210
|
-
// MathLive virtual keyboard has class 'ML__keyboard'
|
|
211
|
-
const virtualKeyboard = document.querySelector('.ML__keyboard');
|
|
212
|
-
if (!virtualKeyboard) {
|
|
213
|
-
handleCancel();
|
|
214
|
-
}
|
|
386
|
+
// Only a click on the backdrop itself closes; never one on the dialog or the
|
|
387
|
+
// virtual keyboard, which MathLive attaches outside it.
|
|
388
|
+
if (e.target === overlay && !document.querySelector('.ML__keyboard')) {
|
|
389
|
+
close(false);
|
|
215
390
|
}
|
|
216
391
|
};
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
insertBtn.addEventListener('click', handleConfirm);
|
|
220
|
-
document.addEventListener('keydown', handleEscape);
|
|
392
|
+
cancelButton.addEventListener('click', handleCancel);
|
|
393
|
+
confirmButton.addEventListener('click', handleConfirm);
|
|
221
394
|
overlay.addEventListener('click', handleOverlayClick);
|
|
222
|
-
|
|
223
|
-
document.body.style.overflow = 'hidden';
|
|
224
|
-
// Add to DOM
|
|
225
|
-
document.body.appendChild(overlay);
|
|
395
|
+
document.addEventListener(CLOSE_TRANSIENT_UI_EVENT, handleCloseTransientUi);
|
|
226
396
|
// Focus the mathfield (but don't auto-show keyboard)
|
|
227
|
-
|
|
228
|
-
|
|
397
|
+
modal.focusInitial();
|
|
398
|
+
focusTimer = setTimeout(() => {
|
|
399
|
+
if (closed)
|
|
400
|
+
return;
|
|
401
|
+
// MathLive moves focus into the field after a short delay of its own; if the
|
|
402
|
+
// field still has no focus by now, it never will (e.g. MathLive failed to
|
|
403
|
+
// load), so focus goes to the next control in the dialog instead.
|
|
404
|
+
modal.ensureFocusInside();
|
|
229
405
|
// Try to programmatically disable the built-in toggle via options
|
|
230
406
|
try {
|
|
231
|
-
mathfield.setOptions({
|
|
407
|
+
mathfield.setOptions?.({
|
|
232
408
|
virtualKeyboardToggleGlyph: '',
|
|
233
409
|
});
|
|
234
410
|
}
|
|
235
|
-
catch
|
|
411
|
+
catch {
|
|
236
412
|
// Silently ignore if this API doesn't exist
|
|
237
413
|
}
|
|
238
414
|
}, 100);
|
|
239
|
-
//
|
|
240
|
-
return
|
|
415
|
+
// Closing from outside calls neither callback.
|
|
416
|
+
return () => {
|
|
417
|
+
if (!closed)
|
|
418
|
+
teardown();
|
|
419
|
+
};
|
|
241
420
|
}
|
|
242
421
|
//# sourceMappingURL=MathLiveEditor.js.map
|