@pie-lib/math-input 8.1.1-next.2 → 8.1.1-next.57

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (185) hide show
  1. package/CHANGELOG.json +17 -0
  2. package/CHANGELOG.md +1172 -0
  3. package/LICENSE.md +5 -0
  4. package/lib/horizontal-keypad.js +96 -0
  5. package/lib/horizontal-keypad.js.map +1 -0
  6. package/lib/index.js +69 -0
  7. package/lib/index.js.map +1 -0
  8. package/lib/keypad/index.js +413 -0
  9. package/lib/keypad/index.js.map +1 -0
  10. package/lib/keypad/keys-layout.js +22 -0
  11. package/lib/keypad/keys-layout.js.map +1 -0
  12. package/lib/keys/basic-operators.js +33 -0
  13. package/lib/keys/basic-operators.js.map +1 -0
  14. package/lib/keys/chars.js +12 -0
  15. package/lib/keys/chars.js.map +1 -0
  16. package/lib/keys/comparison.js +39 -0
  17. package/lib/keys/comparison.js.map +1 -0
  18. package/lib/keys/constants.js +37 -0
  19. package/lib/keys/constants.js.map +1 -0
  20. package/lib/keys/digits.js +46 -0
  21. package/lib/keys/digits.js.map +1 -0
  22. package/lib/keys/edit.js +14 -0
  23. package/lib/keys/edit.js.map +1 -0
  24. package/lib/keys/exponent.js +30 -0
  25. package/lib/keys/exponent.js.map +1 -0
  26. package/lib/keys/fractions.js +29 -0
  27. package/lib/keys/fractions.js.map +1 -0
  28. package/lib/keys/geometry.js +140 -0
  29. package/lib/keys/geometry.js.map +1 -0
  30. package/lib/keys/grades.js +259 -0
  31. package/lib/keys/grades.js.map +1 -0
  32. package/lib/keys/index.js +35 -0
  33. package/lib/keys/index.js.map +1 -0
  34. package/lib/keys/log.js +27 -0
  35. package/lib/keys/log.js.map +1 -0
  36. package/lib/keys/logic.js +19 -0
  37. package/lib/keys/logic.js.map +1 -0
  38. package/lib/keys/matrices.js +19 -0
  39. package/lib/keys/matrices.js.map +1 -0
  40. package/lib/keys/misc.js +62 -0
  41. package/lib/keys/misc.js.map +1 -0
  42. package/lib/keys/navigation.js +20 -0
  43. package/lib/keys/navigation.js.map +1 -0
  44. package/lib/keys/operators.js +15 -0
  45. package/lib/keys/operators.js.map +1 -0
  46. package/lib/keys/statistics.js +40 -0
  47. package/lib/keys/statistics.js.map +1 -0
  48. package/lib/keys/sub-sup.js +19 -0
  49. package/lib/keys/sub-sup.js.map +1 -0
  50. package/lib/keys/trigonometry.js +45 -0
  51. package/lib/keys/trigonometry.js.map +1 -0
  52. package/lib/keys/utils.js +87 -0
  53. package/lib/keys/utils.js.map +1 -0
  54. package/lib/keys/vars.js +24 -0
  55. package/lib/keys/vars.js.map +1 -0
  56. package/lib/math-input.js +141 -0
  57. package/lib/math-input.js.map +1 -0
  58. package/lib/mq/common-mq-styles.js +102 -0
  59. package/lib/mq/common-mq-styles.js.map +1 -0
  60. package/lib/mq/custom-elements.js +20 -0
  61. package/lib/mq/custom-elements.js.map +1 -0
  62. package/lib/mq/index.js +28 -0
  63. package/lib/mq/index.js.map +1 -0
  64. package/lib/mq/input.js +186 -0
  65. package/lib/mq/input.js.map +1 -0
  66. package/lib/mq/mathquill-instance.js +52 -0
  67. package/lib/mq/mathquill-instance.js.map +1 -0
  68. package/lib/mq/static.js +301 -0
  69. package/lib/mq/static.js.map +1 -0
  70. package/lib/updateSpans.js +19 -0
  71. package/lib/updateSpans.js.map +1 -0
  72. package/package.json +18 -33
  73. package/src/__tests__/horizontal-keypad.test.jsx +463 -0
  74. package/src/__tests__/index.test.js +247 -0
  75. package/src/__tests__/math-input-test.jsx +45 -0
  76. package/src/__tests__/updateSpans.test.js +297 -0
  77. package/src/horizontal-keypad.jsx +69 -0
  78. package/src/index.jsx +28 -0
  79. package/src/keypad/__tests__/index.test.jsx +25 -0
  80. package/src/keypad/__tests__/keys-layout.test.js +14 -0
  81. package/src/keypad/index.jsx +439 -0
  82. package/src/keypad/keys-layout.js +16 -0
  83. package/src/keys/__tests__/utils.test.js +57 -0
  84. package/src/keys/basic-operators.js +32 -0
  85. package/src/keys/chars.js +5 -0
  86. package/src/keys/comparison.js +28 -0
  87. package/src/keys/constants.js +35 -0
  88. package/src/keys/digits.js +40 -0
  89. package/src/keys/edit.js +3 -0
  90. package/src/keys/exponent.js +28 -0
  91. package/src/keys/fractions.js +26 -0
  92. package/src/keys/geometry.js +144 -0
  93. package/src/keys/grades.js +367 -0
  94. package/src/keys/index.js +20 -0
  95. package/src/keys/log.js +22 -0
  96. package/src/keys/logic.js +15 -0
  97. package/src/keys/matrices.js +15 -0
  98. package/src/keys/misc.js +65 -0
  99. package/src/keys/navigation.js +8 -0
  100. package/src/keys/operators.js +10 -0
  101. package/src/keys/statistics.js +38 -0
  102. package/src/keys/sub-sup.js +15 -0
  103. package/src/keys/trigonometry.js +15 -0
  104. package/src/keys/utils.js +66 -0
  105. package/src/keys/vars.js +19 -0
  106. package/src/math-input.jsx +119 -0
  107. package/src/mq/__tests__/custom-elements.test.js +342 -0
  108. package/src/mq/__tests__/input.test.jsx +40 -0
  109. package/src/mq/__tests__/mathquill-instance.test.js +67 -0
  110. package/src/mq/__tests__/static.test.jsx +33 -0
  111. package/src/mq/common-mq-styles.js +109 -0
  112. package/src/mq/custom-elements.js +11 -0
  113. package/src/mq/index.js +5 -0
  114. package/src/mq/input.jsx +166 -0
  115. package/src/mq/mathquill-instance.js +45 -0
  116. package/src/mq/static.jsx +290 -0
  117. package/src/updateSpans.js +15 -0
  118. package/dist/_virtual/_rolldown/runtime.js +0 -11
  119. package/dist/horizontal-keypad.d.ts +0 -31
  120. package/dist/horizontal-keypad.js +0 -57
  121. package/dist/index.d.ts +0 -18
  122. package/dist/index.js +0 -19
  123. package/dist/keypad/accessible-keypad.d.ts +0 -37
  124. package/dist/keypad/accessible-keypad.js +0 -614
  125. package/dist/keypad/index.d.ts +0 -2
  126. package/dist/keypad/keys-layout.d.ts +0 -15
  127. package/dist/keypad/keys-layout.js +0 -5
  128. package/dist/keypad/model.d.ts +0 -28
  129. package/dist/keypad/model.js +0 -4
  130. package/dist/keys/basic-operators.d.ts +0 -13
  131. package/dist/keys/basic-operators.js +0 -30
  132. package/dist/keys/chars.d.ts +0 -13
  133. package/dist/keys/comparison.d.ts +0 -12
  134. package/dist/keys/comparison.js +0 -32
  135. package/dist/keys/constants.d.ts +0 -12
  136. package/dist/keys/constants.js +0 -35
  137. package/dist/keys/digits.d.ts +0 -23
  138. package/dist/keys/digits.js +0 -34
  139. package/dist/keys/edit.d.ts +0 -14
  140. package/dist/keys/edit.js +0 -9
  141. package/dist/keys/exponent.d.ts +0 -12
  142. package/dist/keys/exponent.js +0 -28
  143. package/dist/keys/fractions.d.ts +0 -11
  144. package/dist/keys/fractions.js +0 -27
  145. package/dist/keys/geometry.d.ts +0 -31
  146. package/dist/keys/geometry.js +0 -127
  147. package/dist/keys/grades.d.ts +0 -17
  148. package/dist/keys/grades.js +0 -414
  149. package/dist/keys/index.d.ts +0 -14
  150. package/dist/keys/index.js +0 -50
  151. package/dist/keys/log.d.ts +0 -11
  152. package/dist/keys/log.js +0 -25
  153. package/dist/keys/logic.d.ts +0 -10
  154. package/dist/keys/logic.js +0 -13
  155. package/dist/keys/matrices.d.ts +0 -10
  156. package/dist/keys/matrices.js +0 -17
  157. package/dist/keys/misc.d.ts +0 -18
  158. package/dist/keys/misc.js +0 -60
  159. package/dist/keys/navigation.d.ts +0 -10
  160. package/dist/keys/navigation.js +0 -13
  161. package/dist/keys/operators.d.ts +0 -9
  162. package/dist/keys/operators.js +0 -11
  163. package/dist/keys/statistics.d.ts +0 -13
  164. package/dist/keys/statistics.js +0 -38
  165. package/dist/keys/sub-sup.d.ts +0 -10
  166. package/dist/keys/sub-sup.js +0 -17
  167. package/dist/keys/trigonometry.d.ts +0 -14
  168. package/dist/keys/trigonometry.js +0 -43
  169. package/dist/keys/utils.d.ts +0 -13
  170. package/dist/keys/utils.js +0 -24
  171. package/dist/keys/vars.d.ts +0 -11
  172. package/dist/keys/vars.js +0 -22
  173. package/dist/math-input.d.ts +0 -30
  174. package/dist/mq/common-mq-styles.d.ts +0 -225
  175. package/dist/mq/common-mq-styles.js +0 -54
  176. package/dist/mq/custom-elements.d.ts +0 -10
  177. package/dist/mq/custom-elements.js +0 -10
  178. package/dist/mq/index.d.ts +0 -12
  179. package/dist/mq/index.js +0 -12
  180. package/dist/mq/input.d.ts +0 -35
  181. package/dist/mq/input.js +0 -83
  182. package/dist/mq/static.d.ts +0 -43
  183. package/dist/mq/static.js +0 -142
  184. package/dist/updateSpans.d.ts +0 -10
  185. package/dist/updateSpans.js +0 -9
package/dist/mq/input.js DELETED
@@ -1,83 +0,0 @@
1
- import { registerLineBreak as e } from "./custom-elements.js";
2
- import t from "@pie-framework/mathquill";
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";
8
- //#region src/mq/input.tsx
9
- var s;
10
- typeof window < "u" && (s = t.getInterface(2), s && s.registerEmbed && e(s));
11
- var c = a("math-input:mq:input"), l = i("span")({}), u = class extends n.Component {
12
- static propTypes = {
13
- className: r.string,
14
- onClick: r.func,
15
- onChange: r.func,
16
- latex: r.string,
17
- onFocus: r.func,
18
- onBlur: r.func
19
- };
20
- componentDidMount() {
21
- if (!s) throw Error("MQ is not defined - but component has mounted?");
22
- this.mathField = s.MathField(this.input, { handlers: { edit: this.onInputEdit.bind(this) } }), this.updateLatex();
23
- }
24
- componentDidUpdate() {
25
- this.updateLatex();
26
- }
27
- updateLatex() {
28
- if (!this.mathField) return;
29
- let { latex: e } = this.props;
30
- e != null && this.mathField.latex(e);
31
- }
32
- clear() {
33
- return this.mathField.latex(""), "";
34
- }
35
- blur() {
36
- c("blur mathfield"), this.mathField.blur();
37
- }
38
- focus() {
39
- c("focus mathfield..."), this.mathField.focus();
40
- }
41
- command(e) {
42
- return c("command: ", e), Array.isArray(e) ? e.forEach((e) => {
43
- this.mathField.cmd(e);
44
- }) : this.mathField.cmd(e), this.mathField.focus(), this.mathField.latex();
45
- }
46
- keystroke(e) {
47
- return this.mathField.keystroke(e), this.mathField.focus(), this.mathField.latex();
48
- }
49
- write(e) {
50
- return c("write: ", e), this.mathField.write(e), this.mathField.focus(), this.mathField.latex();
51
- }
52
- onInputEdit = () => {
53
- c("[onInputEdit] ...");
54
- let { onChange: e } = this.props;
55
- this.mathField && e && e(this.mathField.latex());
56
- };
57
- refresh = () => {
58
- this.blur(), this.focus();
59
- };
60
- onKeyPress = (e) => {
61
- e.charCode === 13 && e.preventDefault();
62
- };
63
- onClick = (e) => {
64
- let { onClick: t } = this.props;
65
- this.refresh(), t && t(e);
66
- };
67
- shouldComponentUpdate(e) {
68
- return c("next: ", e.latex), c("current: ", this.mathField.latex()), e.latex !== this.mathField.latex();
69
- }
70
- render() {
71
- let { onFocus: e, onBlur: t, className: n } = this.props;
72
- return /* @__PURE__ */ o(l, {
73
- className: n,
74
- onKeyDown: this.onKeyPress,
75
- onClick: this.onClick,
76
- onFocus: e,
77
- onBlur: t,
78
- ref: (e) => this.input = e
79
- });
80
- }
81
- };
82
- //#endregion
83
- export { u as default };
@@ -1,43 +0,0 @@
1
- /**
2
- * @synced-from pie-lib/packages/math-input/src/mq/static.jsx
3
- * @auto-generated
4
- */
5
- import PropTypes from 'prop-types';
6
- import React from 'react';
7
- /**
8
- * Wrapper for MathQuill MQ.MathField.
9
- */
10
- export default class Static extends React.Component {
11
- static propTypes: {
12
- latex: PropTypes.Validator<string>;
13
- onFocus: PropTypes.Requireable<(...args: any[]) => any>;
14
- onBlur: PropTypes.Requireable<(...args: any[]) => any>;
15
- className: PropTypes.Requireable<string>;
16
- getFieldName: PropTypes.Requireable<(...args: any[]) => any>;
17
- onSubFieldChange: PropTypes.Requireable<(...args: any[]) => any>;
18
- onSubFieldFocus: PropTypes.Requireable<(...args: any[]) => any>;
19
- setInput: PropTypes.Requireable<(...args: any[]) => any>;
20
- };
21
- static defaultProps: {
22
- getFieldName: () => void;
23
- };
24
- constructor(props: any);
25
- componentDidMount(): void;
26
- componentDidUpdate(): void;
27
- componentWillUnmount(): void;
28
- createLiveRegion: any;
29
- addEventListeners: any;
30
- removeEventListeners: any;
31
- removeLiveRegion: any;
32
- handleKeyDown: any;
33
- handleMathKeyboardClick: any;
34
- onInputEdit: any;
35
- announceLatexConversion: any;
36
- announceMessage: any;
37
- update: any;
38
- blur: any;
39
- focus: any;
40
- shouldComponentUpdate(nextProps: any): boolean;
41
- onFocus: any;
42
- render(): React.JSX.Element;
43
- }
package/dist/mq/static.js DELETED
@@ -1,142 +0,0 @@
1
- import { updateSpans as e } from "../updateSpans.js";
2
- import t from "@pie-framework/mathquill";
3
- import n from "react";
4
- import r from "prop-types";
5
- import i from "debug";
6
- import { jsx as a } from "react/jsx-runtime";
7
- //#region src/mq/static.tsx
8
- var o;
9
- typeof window < "u" && (o = t.getInterface(2));
10
- var s = i("pie-lib:math-input:mq:static"), c = /\\MathQuillMathField\[r\d*\]\{(.*?)\}/g, l = / /g;
11
- function u(e = "") {
12
- return e.replace(l, "");
13
- }
14
- function d(e) {
15
- let t = 0;
16
- for (let n = 0; n < (e || "").length; n++) e[n] === "{" && t++;
17
- return t;
18
- }
19
- var f = class extends n.Component {
20
- static propTypes = {
21
- latex: r.string.isRequired,
22
- onFocus: r.func,
23
- onBlur: r.func,
24
- className: r.string,
25
- getFieldName: r.func,
26
- onSubFieldChange: r.func,
27
- onSubFieldFocus: r.func,
28
- setInput: r.func
29
- };
30
- static defaultProps = { getFieldName: () => {} };
31
- constructor(e) {
32
- super(e), this.state = {
33
- announcement: "",
34
- previousLatex: "",
35
- inputSource: null,
36
- isDeleteKeyPressed: !1
37
- }, this.inputRef = n.createRef();
38
- }
39
- componentDidMount() {
40
- this.update(), e(), this.createLiveRegion(), this.addEventListeners();
41
- }
42
- componentDidUpdate() {
43
- this.update(), e();
44
- }
45
- componentWillUnmount() {
46
- this.removeLiveRegion(), this.removeEventListeners();
47
- }
48
- createLiveRegion = () => {
49
- this.liveRegion = document.createElement("div"), this.liveRegion.style.position = "absolute", this.liveRegion.style.width = "1px", this.liveRegion.style.height = "1px", this.liveRegion.style.marginTop = "-1px", this.liveRegion.style.clip = "rect(1px, 1px, 1px, 1px)", this.liveRegion.style.overflow = "hidden", this.liveRegion.setAttribute("aria-live", "polite"), this.liveRegion.setAttribute("aria-atomic", "true"), document.body.appendChild(this.liveRegion);
50
- };
51
- addEventListeners = () => {
52
- let e = this.inputRef.current;
53
- e && (e.addEventListener("keydown", this.handleKeyDown), e.addEventListener("click", this.handleMathKeyboardClick));
54
- };
55
- removeEventListeners = () => {
56
- let e = this.inputRef.current;
57
- e && (e.removeEventListener("keydown", this.handleKeyDown), e.removeEventListener("click", this.handleMathKeyboardClick));
58
- };
59
- removeLiveRegion = () => {
60
- this.liveRegion &&= (document.body.removeChild(this.liveRegion), null);
61
- };
62
- handleKeyDown = (e) => {
63
- (e?.key === "Backspace" || e?.key === "Delete") && this.setState({ isDeleteKeyPressed: !0 }), this.setState({ inputSource: "keyboard" });
64
- };
65
- handleMathKeyboardClick = () => {
66
- this.setState({ inputSource: "mathKeyboard" });
67
- };
68
- onInputEdit = (e) => {
69
- if (!this.mathField) return;
70
- let t = this.props.getFieldName(e, this.mathField.innerFields);
71
- this.props.onSubFieldChange && this.props.onSubFieldChange(t, e.latex()), this.announceLatexConversion(e.latex());
72
- };
73
- announceLatexConversion = (e) => {
74
- if (!this.state) {
75
- console.error("State is not initialized");
76
- return;
77
- }
78
- let { previousLatex: t, inputSource: n, isDeleteKeyPressed: r } = this.state, i = "Converted to math symbol";
79
- if (n === "keyboard" && !r) if (d(e) > d(t)) this.announceMessage(i);
80
- else try {
81
- this.mathField.parseLatex(t), this.mathField.parseLatex(e), e == t && this.announceMessage(i);
82
- } catch (e) {
83
- console.warn("Error parsing latex:", e.message), console.warn(e);
84
- }
85
- this.setState({
86
- previousLatex: e,
87
- isDeleteKeyPressed: !1
88
- });
89
- };
90
- announceMessage = (e) => {
91
- this.setState({ previousLatex: "" }), this.liveRegion && (this.liveRegion.textContent = e, setTimeout(() => {
92
- this.liveRegion.textContent = "";
93
- }, 500));
94
- };
95
- update = () => {
96
- if (!o) throw Error("MQ is not defined - but component has mounted?");
97
- this.mathField ||= o.StaticMath(this.inputRef?.current, { handlers: { edit: this.onInputEdit.bind(this) } });
98
- try {
99
- this.mathField.parseLatex(this.props.latex), this.mathField.latex(this.props.latex);
100
- } catch {
101
- this.mathField.latex("\\MathQuillMathField[r1]{}");
102
- }
103
- };
104
- blur = () => {
105
- s("blur mathfield"), this.mathField.blur();
106
- };
107
- focus = () => {
108
- s("focus mathfield..."), this.mathField.focus();
109
- };
110
- shouldComponentUpdate(e) {
111
- try {
112
- 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;
113
- return s("[shouldComponentUpdate] ", r), r;
114
- } catch (e) {
115
- return console.warn("Error parsing latex:", e.message, "skip update"), console.warn(e), !1;
116
- }
117
- }
118
- onFocus = (e) => {
119
- try {
120
- let t = e.target.parentElement.nextSibling, n = parseInt(t.getAttribute("mathquill-block-id"), 10);
121
- n ||= (t = t.parentElement, parseInt(t.getAttribute("mathquill-block-id"), 10));
122
- let r = this.mathField.innerFields.find((e) => e.id === n);
123
- if (r) {
124
- let e = this.props.getFieldName(r, this.mathField.innerFields);
125
- this.props.setInput && this.props.setInput(r), this.props.onSubFieldFocus(e, r);
126
- }
127
- } catch (e) {
128
- console.error("error finding root block", e.message);
129
- }
130
- };
131
- render() {
132
- let { onBlur: e, className: t } = this.props;
133
- return /* @__PURE__ */ a("span", {
134
- className: t,
135
- onFocus: this.onFocus,
136
- onBlur: e,
137
- ref: this.inputRef
138
- });
139
- }
140
- };
141
- //#endregion
142
- export { f as default };
@@ -1,10 +0,0 @@
1
- /**
2
- * @synced-from pie-lib/packages/math-input/src/updateSpans.js
3
- * @auto-generated
4
- *
5
- * This file is automatically synced from pie-elements and converted to TypeScript.
6
- * Manual edits will be overwritten on next sync.
7
- * To make changes, edit the upstream JavaScript file and run sync again.
8
- */
9
- declare const updateSpans: (root?: ParentNode) => void;
10
- export { updateSpans };
@@ -1,9 +0,0 @@
1
- //#region src/updateSpans.ts
2
- var e = (e) => {
3
- let t = e ?? document;
4
- (Array.from(t.querySelectorAll("span[mathquill-command-id]")) || []).forEach((e) => {
5
- e && e.innerText === "∥" && e.className !== "mq-editable-field" && (e.style.fontSize = "32px"), (e.innerText === "′" || e.innerText === "′′") && !e.hasAttribute("data-prime") && e.setAttribute("data-prime", "true");
6
- });
7
- };
8
- //#endregion
9
- export { e as updateSpans };