@pie-lib/math-input-mathlive 2.0.1-next.20261116081603 → 2.0.1-next.20261116213607
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/index.d.ts +2 -2
- package/dist/index.js +5 -5
- package/dist/mf/inactive-caret.d.ts +10 -2
- package/dist/mf/inactive-caret.js +52 -22
- package/dist/mf/input.js +1 -1
- package/dist/mf/static.js +1 -1
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import MathInput from './math-input.js';
|
|
|
4
4
|
import HorizontalKeypad from './horizontal-keypad.js';
|
|
5
5
|
import KeyPad from './keypad/index.js';
|
|
6
6
|
import * as mf from './mf/index.js';
|
|
7
|
-
import { deepActiveElement } from './mf/inactive-caret.js';
|
|
7
|
+
import { KEYPAD_ATTRIBUTE, deepActiveElement } from './mf/inactive-caret.js';
|
|
8
8
|
import { registerEmbed, applyStaticMath, latexToMarkup, loadMathLive, configureFonts, getMacros, PIE_MACROS } from './mathlive-instance.js';
|
|
9
9
|
import { toMathLive, fromMathLive, fieldIds, keyToAction, answerBlockLatex, NEWLINE_EMBED } from './latex-bridge.js';
|
|
10
10
|
declare const addBrackets: (s: any) => any;
|
|
@@ -18,4 +18,4 @@ declare const removeBrackets: (s: any) => any;
|
|
|
18
18
|
* export is kept so callers do not break.
|
|
19
19
|
*/
|
|
20
20
|
declare const updateSpans: () => void;
|
|
21
|
-
export { keysForGrade, addBrackets, removeBrackets, keys, MathInput, HorizontalKeypad, KeyPad, updateSpans, mf, mf as mq, registerEmbed, applyStaticMath, latexToMarkup, loadMathLive, configureFonts, getMacros, PIE_MACROS, toMathLive, fromMathLive, fieldIds, keyToAction, answerBlockLatex, NEWLINE_EMBED, deepActiveElement, };
|
|
21
|
+
export { keysForGrade, addBrackets, removeBrackets, keys, MathInput, HorizontalKeypad, KeyPad, KEYPAD_ATTRIBUTE, updateSpans, mf, mf as mq, registerEmbed, applyStaticMath, latexToMarkup, loadMathLive, configureFonts, getMacros, PIE_MACROS, toMathLive, fromMathLive, fieldIds, keyToAction, answerBlockLatex, NEWLINE_EMBED, deepActiveElement, };
|
package/dist/index.js
CHANGED
|
@@ -4,9 +4,9 @@ import { MathInput as n } from "./math-input.js";
|
|
|
4
4
|
import r from "./horizontal-keypad.js";
|
|
5
5
|
import { KeyPad as i } from "./keypad/index.js";
|
|
6
6
|
import { mf_exports as a } from "./mf/index.js";
|
|
7
|
-
import {
|
|
8
|
-
import { PIE_MACROS as
|
|
9
|
-
import { NEWLINE_EMBED as
|
|
7
|
+
import { KEYPAD_ATTRIBUTE as o, deepActiveElement as s } from "./mf/inactive-caret.js";
|
|
8
|
+
import { PIE_MACROS as c, applyStaticMath as l, configureFonts as u, getMacros as d, latexToMarkup as f, loadMathLive as p, registerEmbed as m } from "./mathlive-instance.js";
|
|
9
|
+
import { NEWLINE_EMBED as h, answerBlockLatex as g, fieldIds as _, fromMathLive as v, keyToAction as y, toMathLive as b } from "./latex-bridge.js";
|
|
10
10
|
// src/index.tsx
|
|
11
|
-
var
|
|
12
|
-
export { r as HorizontalKeypad, i as KeyPad, n as MathInput,
|
|
11
|
+
var x = (e) => e.indexOf("\\(") === 0 ? e : `\\(${e}`, S = (e) => e.indexOf("\\)") === e.length - 2 ? e : `${e}\\)`, C = (e) => e.indexOf("\\(") === 0 ? e.substring(2) : e, w = (e) => e.indexOf("\\)") === e.length - 2 ? e.substring(0, e.length - 2) : e, T = (e) => S(x(e)), E = (e) => w(C(e)), D = () => {};
|
|
12
|
+
export { r as HorizontalKeypad, o as KEYPAD_ATTRIBUTE, i as KeyPad, n as MathInput, h as NEWLINE_EMBED, c as PIE_MACROS, T as addBrackets, g as answerBlockLatex, l as applyStaticMath, u as configureFonts, s as deepActiveElement, _ as fieldIds, v as fromMathLive, d as getMacros, y as keyToAction, t as keys, e as keysForGrade, f as latexToMarkup, p as loadMathLive, a as mf, a as mq, m as registerEmbed, E as removeBrackets, b as toMathLive, D as updateSpans };
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* Marks the keypad root, so a field knows that focus moved to a keypad button. A wrapper marked
|
|
3
|
+
* too makes the keypad and the controls beside it one keypad, such as the toolbar's
|
|
4
|
+
* "+ Response Area" button: typing goes on while focus moves among them.
|
|
5
|
+
*/
|
|
2
6
|
export declare const KEYPAD_ATTRIBUTE = "data-math-keypad";
|
|
3
7
|
/** Set on a `<math-field>` while a keypad button has focus; the shadow CSS then shows its caret. */
|
|
4
8
|
export declare const KEYPAD_CARET_CLASS = "pie-caret-for-keypad";
|
|
@@ -12,7 +16,11 @@ export declare const KEYPAD_CARET_CSS: string;
|
|
|
12
16
|
export declare const deepActiveElement: () => Element | null;
|
|
13
17
|
/**
|
|
14
18
|
* MathLive hides its caret when a field blurs, though it keeps the insertion point. While a keypad
|
|
15
|
-
* button has focus, keep the caret showing there
|
|
19
|
+
* button has focus, keep the caret showing there, and send what is typed on the keyboard to the
|
|
20
|
+
* field, as if typed in it: `/` starts a fraction, `^` an exponent, `\` a LaTeX command, which Space,
|
|
21
|
+
* Enter or Escape finishes, and Backspace and Delete delete.
|
|
22
|
+
* Focus stays on the button.
|
|
23
|
+
* Focus going anywhere else removes the caret and stops the typing.
|
|
16
24
|
*
|
|
17
25
|
* @param {HTMLElement} mathField A `<math-field>`.
|
|
18
26
|
* @returns {function} A function that removes the listeners and the caret.
|
|
@@ -1,31 +1,61 @@
|
|
|
1
|
+
import { KEYSTROKES as e } from "../latex-bridge.js";
|
|
1
2
|
// src/mf/inactive-caret.ts
|
|
2
|
-
var
|
|
3
|
-
`:host(.${
|
|
4
|
-
`:host(.${
|
|
5
|
-
`:host(.${
|
|
6
|
-
].join(""),
|
|
3
|
+
var t = "data-math-keypad", n = "pie-caret-for-keypad", r = [
|
|
4
|
+
`:host(.${n}) .ML__caret::after,`,
|
|
5
|
+
`:host(.${n}) .ML__text-caret::after{visibility:visible;animation:none}`,
|
|
6
|
+
`:host(.${n}) .ML__selected:not(:has(.ML__selected))::after{animation:none}`
|
|
7
|
+
].join(""), i = `[${t}]`, a = (e) => !!e?.closest?.(i), o = (e) => {
|
|
8
|
+
let t = e?.closest?.(i) ?? null;
|
|
9
|
+
for (let e = t?.parentElement?.closest(i); e; e = e.parentElement?.closest(i)) t = e;
|
|
10
|
+
return t;
|
|
11
|
+
}, s = () => {
|
|
7
12
|
let e = document.activeElement;
|
|
8
13
|
for (; e?.shadowRoot?.activeElement;) e = e.shadowRoot.activeElement;
|
|
9
14
|
return e;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
}, c = (e) => {
|
|
16
|
+
if (e.defaultPrevented || e.isComposing || e.key?.length !== 1 || e.key === " ") return !1;
|
|
17
|
+
let t = e.getModifierState?.("AltGraph"), n = e.altKey && !e.ctrlKey && e.key.charCodeAt(0) > 127;
|
|
18
|
+
return !e.metaKey && (t || n || !(e.ctrlKey || e.altKey));
|
|
19
|
+
}, l = {
|
|
20
|
+
" ": ["complete", "accept-all"],
|
|
21
|
+
Enter: ["complete", "accept-all"],
|
|
22
|
+
Escape: [
|
|
23
|
+
"complete",
|
|
24
|
+
"complete",
|
|
25
|
+
{ selectItem: "true" }
|
|
26
|
+
]
|
|
27
|
+
}, u = (e) => !e.defaultPrevented && !(e.shiftKey || e.ctrlKey || e.metaKey || e.altKey) ? l[e.key] : void 0, d = (e) => !e.defaultPrevented && (e.key === "Backspace" || e.key === "Delete") && !(e.ctrlKey || e.metaKey || e.altKey);
|
|
28
|
+
function f(t) {
|
|
29
|
+
if (!t || typeof t.addEventListener != "function") return () => {};
|
|
30
|
+
let r = (e) => t.classList.toggle(n, e), i = null, l = (e) => !!i && !!e && i.contains(e), f = () => {
|
|
31
|
+
document.removeEventListener("focusin", m, !0), document.removeEventListener("focusout", h, !0), document.removeEventListener("keydown", g, !0);
|
|
32
|
+
}, p = () => {
|
|
33
|
+
f(), i = null, r(!1);
|
|
34
|
+
}, m = (e) => {
|
|
35
|
+
let n = e.composedPath?.()[0] ?? e.target;
|
|
36
|
+
(t.contains(n) || t.shadowRoot?.contains(n) || !l(n)) && p();
|
|
37
|
+
}, h = (e) => {
|
|
21
38
|
e.relatedTarget || setTimeout(() => {
|
|
22
|
-
document.hasFocus() && !
|
|
39
|
+
document.hasFocus() && !l(s()) && p();
|
|
23
40
|
});
|
|
24
|
-
},
|
|
25
|
-
|
|
41
|
+
}, g = (n) => {
|
|
42
|
+
if (!t.isConnected) {
|
|
43
|
+
p();
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
let r = n.composedPath?.()[0] ?? n.target;
|
|
47
|
+
if (!l(r)) return;
|
|
48
|
+
let i = t.mode === "latex" ? u(n) : void 0;
|
|
49
|
+
i ? (n.preventDefault(), n.stopPropagation(), t.executeCommand?.(i)) : c(n) ? (n.preventDefault(), n.stopPropagation(), t.executeCommand?.([
|
|
50
|
+
"typedText",
|
|
51
|
+
n.key,
|
|
52
|
+
{ simulateKeystroke: !0 }
|
|
53
|
+
])) : d(n) && (n.preventDefault(), n.stopPropagation(), t.executeCommand?.(e[n.key]));
|
|
54
|
+
}, _ = (e) => {
|
|
55
|
+
!a(e.relatedTarget) || t.readOnly && !t.getPrompts?.().length || (i = o(e.relatedTarget), r(!0), f(), document.addEventListener("focusin", m, !0), document.addEventListener("focusout", h, !0), document.addEventListener("keydown", g, !0));
|
|
26
56
|
};
|
|
27
|
-
return
|
|
28
|
-
|
|
57
|
+
return t.addEventListener("blur", _), () => {
|
|
58
|
+
t.removeEventListener("blur", _), p();
|
|
29
59
|
};
|
|
30
60
|
}
|
|
31
|
-
export {
|
|
61
|
+
export { t as KEYPAD_ATTRIBUTE, n as KEYPAD_CARET_CLASS, r as KEYPAD_CARET_CSS, s as deepActiveElement, f as keepCaretWhileKeypadFocused };
|
package/dist/mf/input.js
CHANGED
|
@@ -37,7 +37,7 @@ var v = /* @__PURE__ */ new Set(["[Tab]", "shift+[Tab]"]), y = (e = []) => e.fil
|
|
|
37
37
|
}
|
|
38
38
|
async componentDidMount() {
|
|
39
39
|
let o = this.mountGeneration = (this.mountGeneration || 0) + 1, s = await n();
|
|
40
|
-
o === this.mountGeneration && s?.MathfieldElement && this.holderRef.current && !this.mathField && (this.mathField = t(s), a(this.mathField, this.props.language, this.relabel), i(this.mathField, this.props.ariaDescribedBy), this.mathField.value = l(this.props.latex || ""), this.props.readOnly && (this.mathField.readOnly = !0), this.mathField.mathVirtualKeyboardPolicy = "manual", this.mathField.mathModeSpace = "\\ ", this.mathField.smartSuperscript = !1, e(this.mathField), this.untrackCaret = r(this.mathField), this.untrackSelection = u(this.mathField), this.untrackLongDivision = d(this.mathField), this.stopKeepingCaret = f(this.mathField), this.mathField.addEventListener("input", this.onInputEdit), this.holderRef.current.replaceChildren(this.mathField), a(this.mathField, this.props.language, this.relabel), this.mathField.keybindings = y(this.mathField.keybindings), this.props.innerRef && this.props.innerRef(this), this.pendingFocus && (this.pendingFocus = !1, this.mathField.focus()));
|
|
40
|
+
o === this.mountGeneration && s?.MathfieldElement && this.holderRef.current && !this.mathField && (this.mathField = t(s), a(this.mathField, this.props.language, this.relabel), i(this.mathField, this.props.ariaDescribedBy), this.mathField.value = l(this.props.latex || ""), this.props.readOnly && (this.mathField.readOnly = !0), this.mathField.mathVirtualKeyboardPolicy = "manual", this.mathField.mathModeSpace = "\\ ", this.mathField.smartSuperscript = !1, this.mathField.popoverPolicy = "off", e(this.mathField), this.untrackCaret = r(this.mathField), this.untrackSelection = u(this.mathField), this.untrackLongDivision = d(this.mathField), this.stopKeepingCaret = f(this.mathField), this.mathField.addEventListener("input", this.onInputEdit), this.holderRef.current.replaceChildren(this.mathField), a(this.mathField, this.props.language, this.relabel), this.mathField.keybindings = y(this.mathField.keybindings), this.props.innerRef && this.props.innerRef(this), this.pendingFocus && (this.pendingFocus = !1, this.mathField.focus()));
|
|
41
41
|
}
|
|
42
42
|
componentDidUpdate(e) {
|
|
43
43
|
if (!this.mathField) return;
|
package/dist/mf/static.js
CHANGED
|
@@ -50,7 +50,7 @@ var D = T("pie-lib:math-input-mathlive:static"), O = "position:absolute;width:1p
|
|
|
50
50
|
return;
|
|
51
51
|
}
|
|
52
52
|
let r = await i();
|
|
53
|
-
n === this.mountGeneration && r?.MathfieldElement && this.holderRef.current && !this.mathField && (this.mathField = t(r), u(this.mathField, this.props.language, this.relabel), l(this.mathField, this.props.ariaDescribedBy), this.mathField.readOnly = !0, this.mathField.mathVirtualKeyboardPolicy = "manual", this.mathField.mathModeSpace = "\\ ", this.mathField.smartSuperscript = !1, this.mathField.value = v(this.props.latex), e(this.mathField), this.untrackCaret = a(this.mathField), this.untrackLongDivision = s(this.mathField), this.stopKeepingCaret = c(this.mathField), this.mathField.addEventListener("input", this.onPromptInput), this.mathField.addEventListener("pointerdown", this.onPointerDown, !0), this.mathField.addEventListener("focusin", this.onPromptFocus), this.mathField.addEventListener("selection-change", this.onSelectionChange), this.mathField.addEventListener("keydown", this.onKeyDown), this.holderRef.current.replaceChildren(this.mathField), u(this.mathField, this.props.language, this.relabel), this.parkCaret(), this.createLiveRegion());
|
|
53
|
+
n === this.mountGeneration && r?.MathfieldElement && this.holderRef.current && !this.mathField && (this.mathField = t(r), u(this.mathField, this.props.language, this.relabel), l(this.mathField, this.props.ariaDescribedBy), this.mathField.readOnly = !0, this.mathField.mathVirtualKeyboardPolicy = "manual", this.mathField.mathModeSpace = "\\ ", this.mathField.smartSuperscript = !1, this.mathField.popoverPolicy = "off", this.mathField.value = v(this.props.latex), e(this.mathField), this.untrackCaret = a(this.mathField), this.untrackLongDivision = s(this.mathField), this.stopKeepingCaret = c(this.mathField), this.mathField.addEventListener("input", this.onPromptInput), this.mathField.addEventListener("pointerdown", this.onPointerDown, !0), this.mathField.addEventListener("focusin", this.onPromptFocus), this.mathField.addEventListener("selection-change", this.onSelectionChange), this.mathField.addEventListener("keydown", this.onKeyDown), this.holderRef.current.replaceChildren(this.mathField), u(this.mathField, this.props.language, this.relabel), this.parkCaret(), this.createLiveRegion());
|
|
54
54
|
}
|
|
55
55
|
componentDidUpdate(e, t) {
|
|
56
56
|
!this.mathField && this.state.markup !== (t && t.markup) && o(this.holderRef.current), this.mathField && e.language !== this.props.language && u(this.mathField, this.props.language, this.relabel), this.mathField && e.ariaDescribedBy !== this.props.ariaDescribedBy && l(this.mathField, this.props.ariaDescribedBy), e.latex !== this.props.latex && (this.isInteractive() === this.interactive ? this.mathField ? p(this.props.latex) === p(e.latex) ? this.syncPrompts() : (this.mathField.value = v(this.props.latex), this.parkCaret()) : this.renderMarkup() : (this.unmountField(), this.setState({ markup: "" }), this.mount()));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pie-lib/math-input-mathlive",
|
|
3
|
-
"version": "2.0.1-next.
|
|
3
|
+
"version": "2.0.1-next.20261116213607",
|
|
4
4
|
"description": "MathLive-based math input (drop-in alternative to @pie-lib/math-input)",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -17,8 +17,8 @@
|
|
|
17
17
|
"mathlive": "0.110.0",
|
|
18
18
|
"prop-types": "^15.7.2",
|
|
19
19
|
"@pie-element/shared-lodash": "0.1.4-next.20261110072702",
|
|
20
|
-
"@pie-lib/render-ui": "8.0.8-next.
|
|
21
|
-
"@pie-element/shared-i18n": "0.1.3-next.
|
|
20
|
+
"@pie-lib/render-ui": "8.0.8-next.20261116213607",
|
|
21
|
+
"@pie-element/shared-i18n": "0.1.3-next.20261116213607"
|
|
22
22
|
},
|
|
23
23
|
"type": "module",
|
|
24
24
|
"main": "./dist/index.js",
|