@pie-lib/math-input 9.0.1-next.20261003161149 → 9.0.1-next.20261004011201
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/mq/field-label.d.ts +6 -0
- package/dist/mq/field-label.js +10 -0
- package/dist/mq/input.d.ts +1 -0
- package/dist/mq/input.js +26 -24
- package/dist/mq/static.d.ts +1 -0
- package/dist/mq/static.js +31 -28
- package/package.json +3 -2
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Names the textarea MathQuill puts in each editable field under `root`, the control a screen
|
|
3
|
+
* reader lands on; MathQuill gives it no name. Static math's own selection textarea sits outside
|
|
4
|
+
* any editable field and is left alone.
|
|
5
|
+
*/
|
|
6
|
+
export declare function labelFieldTextareas(root: Element | null | undefined, language?: string): void;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import e from "@pie-lib/translator";
|
|
2
|
+
//#region src/mq/field-label.ts
|
|
3
|
+
var { translator: t } = e;
|
|
4
|
+
function n(e, n) {
|
|
5
|
+
if (!e) return;
|
|
6
|
+
let r = t.t("mathInput.enterAnswer", { lng: n });
|
|
7
|
+
for (let t of e.querySelectorAll(".mq-editable-field > .mq-textarea > textarea")) t.setAttribute("aria-label", r);
|
|
8
|
+
}
|
|
9
|
+
//#endregion
|
|
10
|
+
export { n as labelFieldTextareas };
|
package/dist/mq/input.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ export declare class Input extends React.Component {
|
|
|
11
11
|
latex: PropTypes.Requireable<string>;
|
|
12
12
|
onFocus: PropTypes.Requireable<(...args: any[]) => any>;
|
|
13
13
|
onBlur: PropTypes.Requireable<(...args: any[]) => any>;
|
|
14
|
+
language: PropTypes.Requireable<string>;
|
|
14
15
|
};
|
|
15
16
|
componentDidMount(): void;
|
|
16
17
|
componentDidUpdate(): void;
|
package/dist/mq/input.js
CHANGED
|
@@ -1,25 +1,27 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import t from "
|
|
3
|
-
import n from "
|
|
4
|
-
import
|
|
5
|
-
import i from "
|
|
6
|
-
import
|
|
1
|
+
import { labelFieldTextareas as e } from "./field-label.js";
|
|
2
|
+
import { MQ as t } from "./mathquill-instance.js";
|
|
3
|
+
import n from "react";
|
|
4
|
+
import r from "prop-types";
|
|
5
|
+
import { styled as i } from "@mui/material/styles";
|
|
6
|
+
import a from "debug";
|
|
7
|
+
import { jsx as o } from "react/jsx-runtime";
|
|
7
8
|
//#region src/mq/input.tsx
|
|
8
|
-
var
|
|
9
|
+
var s = a("math-input:mq:input"), c = i("span")({}), l = class extends n.Component {
|
|
9
10
|
static propTypes = {
|
|
10
|
-
className:
|
|
11
|
-
onClick:
|
|
12
|
-
onChange:
|
|
13
|
-
latex:
|
|
14
|
-
onFocus:
|
|
15
|
-
onBlur:
|
|
11
|
+
className: r.string,
|
|
12
|
+
onClick: r.func,
|
|
13
|
+
onChange: r.func,
|
|
14
|
+
latex: r.string,
|
|
15
|
+
onFocus: r.func,
|
|
16
|
+
onBlur: r.func,
|
|
17
|
+
language: r.string
|
|
16
18
|
};
|
|
17
19
|
componentDidMount() {
|
|
18
|
-
if (!
|
|
19
|
-
this.mathField =
|
|
20
|
+
if (!t) throw Error("MQ is not defined - but component has mounted?");
|
|
21
|
+
this.mathField = t.MathField(this.input, { handlers: { edit: this.onInputEdit.bind(this) } }), this.updateLatex(), e(this.input, this.props.language);
|
|
20
22
|
}
|
|
21
23
|
componentDidUpdate() {
|
|
22
|
-
this.updateLatex();
|
|
24
|
+
this.updateLatex(), e(this.input, this.props.language);
|
|
23
25
|
}
|
|
24
26
|
updateLatex() {
|
|
25
27
|
if (!this.mathField) return;
|
|
@@ -30,13 +32,13 @@ var o = i("math-input:mq:input"), s = r("span")({}), c = class extends t.Compone
|
|
|
30
32
|
return this.mathField.latex(""), "";
|
|
31
33
|
}
|
|
32
34
|
blur() {
|
|
33
|
-
|
|
35
|
+
s("blur mathfield"), this.mathField.blur();
|
|
34
36
|
}
|
|
35
37
|
focus() {
|
|
36
|
-
|
|
38
|
+
s("focus mathfield..."), this.mathField.focus();
|
|
37
39
|
}
|
|
38
40
|
command(e) {
|
|
39
|
-
return
|
|
41
|
+
return s("command: ", e), Array.isArray(e) ? e.forEach((e) => {
|
|
40
42
|
this.mathField.cmd(e);
|
|
41
43
|
}) : this.mathField.cmd(e), this.mathField.focus(), this.mathField.latex();
|
|
42
44
|
}
|
|
@@ -44,10 +46,10 @@ var o = i("math-input:mq:input"), s = r("span")({}), c = class extends t.Compone
|
|
|
44
46
|
return this.mathField.keystroke(e), this.mathField.focus(), this.mathField.latex();
|
|
45
47
|
}
|
|
46
48
|
write(e) {
|
|
47
|
-
return
|
|
49
|
+
return s("write: ", e), this.mathField.write(e), this.mathField.focus(), this.mathField.latex();
|
|
48
50
|
}
|
|
49
51
|
onInputEdit = () => {
|
|
50
|
-
|
|
52
|
+
s("[onInputEdit] ...");
|
|
51
53
|
let { onChange: e } = this.props;
|
|
52
54
|
this.mathField && e && e(this.mathField.latex());
|
|
53
55
|
};
|
|
@@ -65,11 +67,11 @@ var o = i("math-input:mq:input"), s = r("span")({}), c = class extends t.Compone
|
|
|
65
67
|
this.refresh(), t && t(e);
|
|
66
68
|
};
|
|
67
69
|
shouldComponentUpdate(e) {
|
|
68
|
-
return
|
|
70
|
+
return s("next: ", e.latex), s("current: ", this.mathField.latex()), e.latex !== this.mathField.latex();
|
|
69
71
|
}
|
|
70
72
|
render() {
|
|
71
73
|
let { onFocus: e, onBlur: t, className: n } = this.props;
|
|
72
|
-
return /* @__PURE__ */
|
|
74
|
+
return /* @__PURE__ */ o(c, {
|
|
73
75
|
className: n,
|
|
74
76
|
onKeyDown: this.onKeyPress,
|
|
75
77
|
onClick: this.onClick,
|
|
@@ -80,4 +82,4 @@ var o = i("math-input:mq:input"), s = r("span")({}), c = class extends t.Compone
|
|
|
80
82
|
}
|
|
81
83
|
};
|
|
82
84
|
//#endregion
|
|
83
|
-
export {
|
|
85
|
+
export { l as Input, l as default };
|
package/dist/mq/static.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ export default class Static extends React.Component {
|
|
|
13
13
|
onSubFieldChange: PropTypes.Requireable<(...args: any[]) => any>;
|
|
14
14
|
onSubFieldFocus: PropTypes.Requireable<(...args: any[]) => any>;
|
|
15
15
|
setInput: PropTypes.Requireable<(...args: any[]) => any>;
|
|
16
|
+
language: PropTypes.Requireable<string>;
|
|
16
17
|
};
|
|
17
18
|
static defaultProps: {
|
|
18
19
|
getFieldName: () => void;
|
package/dist/mq/static.js
CHANGED
|
@@ -1,29 +1,31 @@
|
|
|
1
1
|
import { updateSpans as e } from "../updateSpans.js";
|
|
2
|
-
import {
|
|
3
|
-
import n from "
|
|
4
|
-
import r from "
|
|
5
|
-
import i from "
|
|
6
|
-
import
|
|
2
|
+
import { labelFieldTextareas as t } from "./field-label.js";
|
|
3
|
+
import { MQ as n } from "./mathquill-instance.js";
|
|
4
|
+
import r from "react";
|
|
5
|
+
import i from "prop-types";
|
|
6
|
+
import a from "debug";
|
|
7
|
+
import { jsx as o } from "react/jsx-runtime";
|
|
7
8
|
//#region src/mq/static.tsx
|
|
8
|
-
var
|
|
9
|
-
function
|
|
10
|
-
return e.replace(
|
|
9
|
+
var s = a("pie-lib:math-input:mq:static"), c = /\\MathQuillMathField\[r\d*\]\{(.*?)\}/g, l = / /g;
|
|
10
|
+
function u(e = "") {
|
|
11
|
+
return e.replace(l, "");
|
|
11
12
|
}
|
|
12
|
-
function
|
|
13
|
+
function d(e) {
|
|
13
14
|
let t = 0;
|
|
14
15
|
for (let n = 0; n < (e || "").length; n++) e[n] === "{" && t++;
|
|
15
16
|
return t;
|
|
16
17
|
}
|
|
17
|
-
var
|
|
18
|
+
var f = class extends r.Component {
|
|
18
19
|
static propTypes = {
|
|
19
|
-
latex:
|
|
20
|
-
onFocus:
|
|
21
|
-
onBlur:
|
|
22
|
-
className:
|
|
23
|
-
getFieldName:
|
|
24
|
-
onSubFieldChange:
|
|
25
|
-
onSubFieldFocus:
|
|
26
|
-
setInput:
|
|
20
|
+
latex: i.string.isRequired,
|
|
21
|
+
onFocus: i.func,
|
|
22
|
+
onBlur: i.func,
|
|
23
|
+
className: i.string,
|
|
24
|
+
getFieldName: i.func,
|
|
25
|
+
onSubFieldChange: i.func,
|
|
26
|
+
onSubFieldFocus: i.func,
|
|
27
|
+
setInput: i.func,
|
|
28
|
+
language: i.string
|
|
27
29
|
};
|
|
28
30
|
static defaultProps = { getFieldName: () => {} };
|
|
29
31
|
constructor(e) {
|
|
@@ -32,7 +34,7 @@ var d = class extends n.Component {
|
|
|
32
34
|
previousLatex: "",
|
|
33
35
|
inputSource: null,
|
|
34
36
|
isDeleteKeyPressed: !1
|
|
35
|
-
}, this.inputRef =
|
|
37
|
+
}, this.inputRef = r.createRef();
|
|
36
38
|
}
|
|
37
39
|
componentDidMount() {
|
|
38
40
|
this.update(), e(), this.createLiveRegion(), this.addEventListeners();
|
|
@@ -83,7 +85,7 @@ var d = class extends n.Component {
|
|
|
83
85
|
return;
|
|
84
86
|
}
|
|
85
87
|
let { previousLatex: t, inputSource: n, isDeleteKeyPressed: r } = this.state, i = "Converted to math symbol";
|
|
86
|
-
if (n === "keyboard" && !r) if (
|
|
88
|
+
if (n === "keyboard" && !r) if (d(e) > d(t)) this.announceMessage(i);
|
|
87
89
|
else try {
|
|
88
90
|
this.mathField.parseLatex(t), this.mathField.parseLatex(e), e == t && this.announceMessage(i);
|
|
89
91
|
} catch (e) {
|
|
@@ -100,8 +102,8 @@ var d = class extends n.Component {
|
|
|
100
102
|
}, 500));
|
|
101
103
|
};
|
|
102
104
|
update = () => {
|
|
103
|
-
if (!
|
|
104
|
-
this.mathField ||=
|
|
105
|
+
if (!n) throw Error("MQ is not defined - but component has mounted?");
|
|
106
|
+
this.mathField ||= n.StaticMath(this.inputRef?.current, { handlers: { edit: this.onInputEdit.bind(this) } });
|
|
105
107
|
try {
|
|
106
108
|
this._isProgrammaticUpdate = !0, this.mathField.parseLatex(this.props.latex), this.mathField.latex(this.props.latex);
|
|
107
109
|
} catch {
|
|
@@ -109,17 +111,18 @@ var d = class extends n.Component {
|
|
|
109
111
|
} finally {
|
|
110
112
|
this._isProgrammaticUpdate = !1;
|
|
111
113
|
}
|
|
114
|
+
t(this.inputRef?.current, this.props.language);
|
|
112
115
|
};
|
|
113
116
|
blur = () => {
|
|
114
|
-
|
|
117
|
+
s("blur mathfield"), this.mathField.blur();
|
|
115
118
|
};
|
|
116
119
|
focus = () => {
|
|
117
|
-
|
|
120
|
+
s("focus mathfield..."), this.mathField.focus();
|
|
118
121
|
};
|
|
119
122
|
shouldComponentUpdate(e) {
|
|
120
123
|
try {
|
|
121
|
-
let t =
|
|
122
|
-
return
|
|
124
|
+
let t = u(this.mathField.parseLatex(e.latex)), n = (e.latex.match(c) || []).length, r = t !== u(this.mathField.latex().trim()) || n !== Object.keys(this.mathField.innerFields).length / 2;
|
|
125
|
+
return s("[shouldComponentUpdate] ", r), r;
|
|
123
126
|
} catch (e) {
|
|
124
127
|
return console.warn("Error parsing latex:", e.message, "skip update"), console.warn(e), !1;
|
|
125
128
|
}
|
|
@@ -139,7 +142,7 @@ var d = class extends n.Component {
|
|
|
139
142
|
};
|
|
140
143
|
render() {
|
|
141
144
|
let { onBlur: e, className: t } = this.props;
|
|
142
|
-
return /* @__PURE__ */
|
|
145
|
+
return /* @__PURE__ */ o("span", {
|
|
143
146
|
className: t,
|
|
144
147
|
onFocus: this.onFocus,
|
|
145
148
|
onBlur: e,
|
|
@@ -148,4 +151,4 @@ var d = class extends n.Component {
|
|
|
148
151
|
}
|
|
149
152
|
};
|
|
150
153
|
//#endregion
|
|
151
|
-
export {
|
|
154
|
+
export { f as default };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pie-lib/math-input",
|
|
3
|
-
"version": "9.0.1-next.
|
|
3
|
+
"version": "9.0.1-next.20261004011201",
|
|
4
4
|
"description": "React implementation of @pie-lib/math-input",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -16,7 +16,8 @@
|
|
|
16
16
|
"debug": "^4.1.1",
|
|
17
17
|
"prop-types": "^15.7.2",
|
|
18
18
|
"@pie-element/shared-lodash": "0.1.2-next.20261002215153",
|
|
19
|
-
"@pie-lib/render-ui": "8.0.1-next.20261003161149"
|
|
19
|
+
"@pie-lib/render-ui": "8.0.1-next.20261003161149",
|
|
20
|
+
"@pie-lib/translator": "5.0.1-next.20261004011201"
|
|
20
21
|
},
|
|
21
22
|
"type": "module",
|
|
22
23
|
"main": "./dist/index.js",
|