@pie-lib/math-input 8.1.2-next.88 → 9.0.0-next.7

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 (183) hide show
  1. package/dist/_virtual/_rolldown/runtime.js +11 -0
  2. package/dist/horizontal-keypad.d.ts +30 -0
  3. package/dist/horizontal-keypad.js +55 -0
  4. package/dist/index.d.ts +17 -0
  5. package/dist/index.js +10 -0
  6. package/dist/keypad/index.d.ts +37 -0
  7. package/dist/keypad/index.js +277 -0
  8. package/dist/keypad/keys-layout.d.ts +15 -0
  9. package/dist/keypad/keys-layout.js +5 -0
  10. package/dist/keys/basic-operators.d.ts +13 -0
  11. package/dist/keys/basic-operators.js +30 -0
  12. package/dist/keys/chars.d.ts +13 -0
  13. package/dist/keys/comparison.d.ts +12 -0
  14. package/dist/keys/comparison.js +32 -0
  15. package/dist/keys/constants.d.ts +12 -0
  16. package/dist/keys/constants.js +35 -0
  17. package/dist/keys/digits.d.ts +23 -0
  18. package/dist/keys/digits.js +34 -0
  19. package/dist/keys/edit.d.ts +14 -0
  20. package/dist/keys/edit.js +9 -0
  21. package/dist/keys/exponent.d.ts +12 -0
  22. package/dist/keys/exponent.js +28 -0
  23. package/dist/keys/fractions.d.ts +11 -0
  24. package/dist/keys/fractions.js +27 -0
  25. package/dist/keys/geometry.d.ts +31 -0
  26. package/dist/keys/geometry.js +127 -0
  27. package/dist/keys/grades.d.ts +17 -0
  28. package/dist/keys/grades.js +414 -0
  29. package/dist/keys/index.d.ts +14 -0
  30. package/dist/keys/index.js +50 -0
  31. package/dist/keys/log.d.ts +11 -0
  32. package/dist/keys/log.js +25 -0
  33. package/dist/keys/logic.d.ts +10 -0
  34. package/dist/keys/logic.js +13 -0
  35. package/dist/keys/matrices.d.ts +10 -0
  36. package/dist/keys/matrices.js +17 -0
  37. package/dist/keys/misc.d.ts +18 -0
  38. package/dist/keys/misc.js +60 -0
  39. package/dist/keys/navigation.d.ts +10 -0
  40. package/dist/keys/navigation.js +13 -0
  41. package/dist/keys/operators.d.ts +9 -0
  42. package/dist/keys/operators.js +11 -0
  43. package/dist/keys/statistics.d.ts +13 -0
  44. package/dist/keys/statistics.js +38 -0
  45. package/dist/keys/sub-sup.d.ts +10 -0
  46. package/dist/keys/sub-sup.js +17 -0
  47. package/dist/keys/trigonometry.d.ts +14 -0
  48. package/dist/keys/trigonometry.js +43 -0
  49. package/dist/keys/utils.d.ts +13 -0
  50. package/dist/keys/utils.js +24 -0
  51. package/dist/keys/vars.d.ts +11 -0
  52. package/dist/keys/vars.js +22 -0
  53. package/dist/math-input.d.ts +30 -0
  54. package/dist/mq/common-mq-styles.d.ts +231 -0
  55. package/dist/mq/common-mq-styles.js +55 -0
  56. package/dist/mq/custom-elements.d.ts +10 -0
  57. package/dist/mq/custom-elements.js +10 -0
  58. package/dist/mq/index.d.ts +12 -0
  59. package/dist/mq/index.js +12 -0
  60. package/dist/mq/input.d.ts +39 -0
  61. package/dist/mq/input.js +83 -0
  62. package/{src/mq/mathquill-instance.js → dist/mq/mathquill-instance.d.ts} +11 -28
  63. package/dist/mq/mathquill-instance.js +13 -0
  64. package/dist/mq/static.d.ts +47 -0
  65. package/dist/mq/static.js +151 -0
  66. package/dist/updateSpans.d.ts +10 -0
  67. package/dist/updateSpans.js +8 -0
  68. package/package.json +29 -15
  69. package/CHANGELOG.json +0 -17
  70. package/CHANGELOG.md +0 -1178
  71. package/LICENSE.md +0 -5
  72. package/lib/horizontal-keypad.js +0 -96
  73. package/lib/horizontal-keypad.js.map +0 -1
  74. package/lib/index.js +0 -69
  75. package/lib/index.js.map +0 -1
  76. package/lib/keypad/index.js +0 -413
  77. package/lib/keypad/index.js.map +0 -1
  78. package/lib/keypad/keys-layout.js +0 -22
  79. package/lib/keypad/keys-layout.js.map +0 -1
  80. package/lib/keys/basic-operators.js +0 -33
  81. package/lib/keys/basic-operators.js.map +0 -1
  82. package/lib/keys/chars.js +0 -12
  83. package/lib/keys/chars.js.map +0 -1
  84. package/lib/keys/comparison.js +0 -39
  85. package/lib/keys/comparison.js.map +0 -1
  86. package/lib/keys/constants.js +0 -37
  87. package/lib/keys/constants.js.map +0 -1
  88. package/lib/keys/digits.js +0 -46
  89. package/lib/keys/digits.js.map +0 -1
  90. package/lib/keys/edit.js +0 -14
  91. package/lib/keys/edit.js.map +0 -1
  92. package/lib/keys/exponent.js +0 -30
  93. package/lib/keys/exponent.js.map +0 -1
  94. package/lib/keys/fractions.js +0 -29
  95. package/lib/keys/fractions.js.map +0 -1
  96. package/lib/keys/geometry.js +0 -140
  97. package/lib/keys/geometry.js.map +0 -1
  98. package/lib/keys/grades.js +0 -259
  99. package/lib/keys/grades.js.map +0 -1
  100. package/lib/keys/index.js +0 -35
  101. package/lib/keys/index.js.map +0 -1
  102. package/lib/keys/log.js +0 -27
  103. package/lib/keys/log.js.map +0 -1
  104. package/lib/keys/logic.js +0 -19
  105. package/lib/keys/logic.js.map +0 -1
  106. package/lib/keys/matrices.js +0 -19
  107. package/lib/keys/matrices.js.map +0 -1
  108. package/lib/keys/misc.js +0 -62
  109. package/lib/keys/misc.js.map +0 -1
  110. package/lib/keys/navigation.js +0 -20
  111. package/lib/keys/navigation.js.map +0 -1
  112. package/lib/keys/operators.js +0 -15
  113. package/lib/keys/operators.js.map +0 -1
  114. package/lib/keys/statistics.js +0 -40
  115. package/lib/keys/statistics.js.map +0 -1
  116. package/lib/keys/sub-sup.js +0 -19
  117. package/lib/keys/sub-sup.js.map +0 -1
  118. package/lib/keys/trigonometry.js +0 -45
  119. package/lib/keys/trigonometry.js.map +0 -1
  120. package/lib/keys/utils.js +0 -87
  121. package/lib/keys/utils.js.map +0 -1
  122. package/lib/keys/vars.js +0 -24
  123. package/lib/keys/vars.js.map +0 -1
  124. package/lib/math-input.js +0 -141
  125. package/lib/math-input.js.map +0 -1
  126. package/lib/mq/common-mq-styles.js +0 -102
  127. package/lib/mq/common-mq-styles.js.map +0 -1
  128. package/lib/mq/custom-elements.js +0 -20
  129. package/lib/mq/custom-elements.js.map +0 -1
  130. package/lib/mq/index.js +0 -28
  131. package/lib/mq/index.js.map +0 -1
  132. package/lib/mq/input.js +0 -186
  133. package/lib/mq/input.js.map +0 -1
  134. package/lib/mq/mathquill-instance.js +0 -52
  135. package/lib/mq/mathquill-instance.js.map +0 -1
  136. package/lib/mq/static.js +0 -301
  137. package/lib/mq/static.js.map +0 -1
  138. package/lib/updateSpans.js +0 -19
  139. package/lib/updateSpans.js.map +0 -1
  140. package/src/__tests__/horizontal-keypad.test.jsx +0 -463
  141. package/src/__tests__/index.test.js +0 -247
  142. package/src/__tests__/math-input-test.jsx +0 -45
  143. package/src/__tests__/updateSpans.test.js +0 -297
  144. package/src/horizontal-keypad.jsx +0 -69
  145. package/src/index.jsx +0 -28
  146. package/src/keypad/__tests__/index.test.jsx +0 -25
  147. package/src/keypad/__tests__/keys-layout.test.js +0 -14
  148. package/src/keypad/index.jsx +0 -439
  149. package/src/keypad/keys-layout.js +0 -16
  150. package/src/keys/__tests__/utils.test.js +0 -57
  151. package/src/keys/basic-operators.js +0 -32
  152. package/src/keys/chars.js +0 -5
  153. package/src/keys/comparison.js +0 -28
  154. package/src/keys/constants.js +0 -35
  155. package/src/keys/digits.js +0 -40
  156. package/src/keys/edit.js +0 -3
  157. package/src/keys/exponent.js +0 -28
  158. package/src/keys/fractions.js +0 -26
  159. package/src/keys/geometry.js +0 -144
  160. package/src/keys/grades.js +0 -367
  161. package/src/keys/index.js +0 -20
  162. package/src/keys/log.js +0 -22
  163. package/src/keys/logic.js +0 -15
  164. package/src/keys/matrices.js +0 -15
  165. package/src/keys/misc.js +0 -65
  166. package/src/keys/navigation.js +0 -8
  167. package/src/keys/operators.js +0 -10
  168. package/src/keys/statistics.js +0 -38
  169. package/src/keys/sub-sup.js +0 -15
  170. package/src/keys/trigonometry.js +0 -15
  171. package/src/keys/utils.js +0 -66
  172. package/src/keys/vars.js +0 -19
  173. package/src/math-input.jsx +0 -119
  174. package/src/mq/__tests__/custom-elements.test.js +0 -342
  175. package/src/mq/__tests__/input.test.jsx +0 -40
  176. package/src/mq/__tests__/mathquill-instance.test.js +0 -67
  177. package/src/mq/__tests__/static.test.jsx +0 -33
  178. package/src/mq/common-mq-styles.js +0 -109
  179. package/src/mq/custom-elements.js +0 -11
  180. package/src/mq/index.js +0 -5
  181. package/src/mq/input.jsx +0 -166
  182. package/src/mq/static.jsx +0 -290
  183. package/src/updateSpans.js +0 -15
@@ -0,0 +1,151 @@
1
+ import { updateSpans as e } from "../updateSpans.js";
2
+ import { MQ as t } from "./mathquill-instance.js";
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 = i("pie-lib:math-input:mq:static"), s = /\\MathQuillMathField\[r\d*\]\{(.*?)\}/g, c = / /g;
9
+ function l(e = "") {
10
+ return e.replace(c, "");
11
+ }
12
+ function u(e) {
13
+ let t = 0;
14
+ for (let n = 0; n < (e || "").length; n++) e[n] === "{" && t++;
15
+ return t;
16
+ }
17
+ var d = class extends n.Component {
18
+ static propTypes = {
19
+ latex: r.string.isRequired,
20
+ onFocus: r.func,
21
+ onBlur: r.func,
22
+ className: r.string,
23
+ getFieldName: r.func,
24
+ onSubFieldChange: r.func,
25
+ onSubFieldFocus: r.func,
26
+ setInput: r.func
27
+ };
28
+ static defaultProps = { getFieldName: () => {} };
29
+ constructor(e) {
30
+ super(e), this.state = {
31
+ announcement: "",
32
+ previousLatex: "",
33
+ inputSource: null,
34
+ isDeleteKeyPressed: !1
35
+ }, this.inputRef = n.createRef();
36
+ }
37
+ componentDidMount() {
38
+ this.update(), e(), this.createLiveRegion(), this.addEventListeners();
39
+ }
40
+ componentDidUpdate() {
41
+ this.update(), e();
42
+ }
43
+ componentWillUnmount() {
44
+ this.removeLiveRegion(), this.removeEventListeners();
45
+ }
46
+ createLiveRegion = () => {
47
+ 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);
48
+ };
49
+ addEventListeners = () => {
50
+ let e = this.inputRef.current;
51
+ e && (e.addEventListener("keydown", this.handleKeyDown), e.addEventListener("click", this.handleMathKeyboardClick));
52
+ };
53
+ removeEventListeners = () => {
54
+ let e = this.inputRef.current;
55
+ e && (e.removeEventListener("keydown", this.handleKeyDown), e.removeEventListener("click", this.handleMathKeyboardClick));
56
+ };
57
+ removeLiveRegion = () => {
58
+ this.liveRegion &&= (document.body.removeChild(this.liveRegion), null);
59
+ };
60
+ handleKeyDown = (e) => {
61
+ (e?.key === "Backspace" || e?.key === "Delete") && this.setState({ isDeleteKeyPressed: !0 }), this.setState({ inputSource: "keyboard" });
62
+ };
63
+ handleMathKeyboardClick = () => {
64
+ this.setState({ inputSource: "mathKeyboard" });
65
+ };
66
+ onInputEdit = (e) => {
67
+ if (!this.mathField || this._isProgrammaticUpdate) return;
68
+ let t = this.props.getFieldName(e, this.mathField.innerFields);
69
+ if (this.props.onSubFieldChange) {
70
+ let n = e.latex().match(/[0-9]\\ \\frac\{[^\{]*\}\{ \}/);
71
+ if (this.inputRef?.current && n && n?.length) try {
72
+ e.__controller.cursor.insLeftOf(e.__controller.cursor.parent[-1].parent), e.el().dispatchEvent(new KeyboardEvent("keydown", { keyCode: 8 }));
73
+ } catch (e) {
74
+ console.error(e.toString());
75
+ }
76
+ else this.props.onSubFieldChange(t, e.latex());
77
+ }
78
+ this.announceLatexConversion(e.latex());
79
+ };
80
+ announceLatexConversion = (e) => {
81
+ if (!this.state) {
82
+ console.error("State is not initialized");
83
+ return;
84
+ }
85
+ let { previousLatex: t, inputSource: n, isDeleteKeyPressed: r } = this.state, i = "Converted to math symbol";
86
+ if (n === "keyboard" && !r) if (u(e) > u(t)) this.announceMessage(i);
87
+ else try {
88
+ this.mathField.parseLatex(t), this.mathField.parseLatex(e), e == t && this.announceMessage(i);
89
+ } catch (e) {
90
+ console.warn("Error parsing latex:", e.message), console.warn(e);
91
+ }
92
+ (this.state.previousLatex !== e || this.state.isDeleteKeyPressed) && this.setState({
93
+ previousLatex: e,
94
+ isDeleteKeyPressed: !1
95
+ });
96
+ };
97
+ announceMessage = (e) => {
98
+ this.setState({ previousLatex: "" }), this.liveRegion && (this.liveRegion.textContent = e, setTimeout(() => {
99
+ this.liveRegion.textContent = "";
100
+ }, 500));
101
+ };
102
+ update = () => {
103
+ if (!t) throw Error("MQ is not defined - but component has mounted?");
104
+ this.mathField ||= t.StaticMath(this.inputRef?.current, { handlers: { edit: this.onInputEdit.bind(this) } });
105
+ try {
106
+ this._isProgrammaticUpdate = !0, this.mathField.parseLatex(this.props.latex), this.mathField.latex(this.props.latex);
107
+ } catch {
108
+ this.mathField.latex("\\MathQuillMathField[r1]{}");
109
+ } finally {
110
+ this._isProgrammaticUpdate = !1;
111
+ }
112
+ };
113
+ blur = () => {
114
+ o("blur mathfield"), this.mathField.blur();
115
+ };
116
+ focus = () => {
117
+ o("focus mathfield..."), this.mathField.focus();
118
+ };
119
+ shouldComponentUpdate(e) {
120
+ try {
121
+ let t = l(this.mathField.parseLatex(e.latex)), n = (e.latex.match(s) || []).length, r = t !== l(this.mathField.latex().trim()) || n !== Object.keys(this.mathField.innerFields).length / 2;
122
+ return o("[shouldComponentUpdate] ", r), r;
123
+ } catch (e) {
124
+ return console.warn("Error parsing latex:", e.message, "skip update"), console.warn(e), !1;
125
+ }
126
+ }
127
+ onFocus = (e) => {
128
+ try {
129
+ let t = e.target.parentElement.nextSibling, n = parseInt(t.getAttribute("mathquill-block-id"), 10);
130
+ n ||= (t = t.parentElement, parseInt(t.getAttribute("mathquill-block-id"), 10));
131
+ let r = this.mathField.innerFields.find((e) => e.id === n);
132
+ if (r) {
133
+ let e = this.props.getFieldName(r, this.mathField.innerFields);
134
+ this.props.setInput && this.props.setInput(r), this.props.onSubFieldFocus(e, r);
135
+ }
136
+ } catch (e) {
137
+ console.error("error finding root block", e.message);
138
+ }
139
+ };
140
+ render() {
141
+ let { onBlur: e, className: t } = this.props;
142
+ return /* @__PURE__ */ a("span", {
143
+ className: t,
144
+ onFocus: this.onFocus,
145
+ onBlur: e,
146
+ ref: this.inputRef
147
+ });
148
+ }
149
+ };
150
+ //#endregion
151
+ export { d as default };
@@ -0,0 +1,10 @@
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: () => void;
10
+ export { updateSpans };
@@ -0,0 +1,8 @@
1
+ //#region src/updateSpans.ts
2
+ var e = () => {
3
+ (Array.from(document.querySelectorAll("span[mathquill-command-id]")) || []).forEach((e) => {
4
+ 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");
5
+ });
6
+ };
7
+ //#endregion
8
+ export { e as updateSpans };
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@pie-lib/math-input",
3
- "publishConfig": {
4
- "access": "public"
3
+ "version": "9.0.0-next.7",
4
+ "description": "React implementation of @pie-lib/math-input synced from pie-lib",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/pie-framework/pie-elements-ng.git",
8
+ "directory": "packages/lib-react/math-input"
5
9
  },
6
- "version": "8.1.2-next.88+fb8ae2fcd",
7
- "main": "lib/index.js",
8
- "module": "src/index.jsx",
9
- "repository": "pie-framework/pie-lib",
10
10
  "dependencies": {
11
11
  "@emotion/react": "^11.14.0",
12
12
  "@emotion/styled": "^11.14.1",
@@ -14,16 +14,30 @@
14
14
  "@mui/material": "^7.3.4",
15
15
  "@pie-framework/mathquill": "1.2.1-beta.1",
16
16
  "debug": "^4.1.1",
17
- "lodash-es": "^4.17.23",
18
- "prop-types": "^15.7.2"
17
+ "prop-types": "^15.7.2",
18
+ "@pie-element/shared-lodash": "0.1.1-next.1",
19
+ "@pie-lib/render-ui": "6.2.0-next.42"
19
20
  },
20
- "peerDependencies": {
21
- "react": "^18.2.0"
21
+ "type": "module",
22
+ "main": "./dist/index.js",
23
+ "types": "./dist/index.d.ts",
24
+ "exports": {
25
+ ".": {
26
+ "types": "./dist/index.d.ts",
27
+ "default": "./dist/index.js"
28
+ }
22
29
  },
23
- "devDependencies": {
24
- "react": "^18.2.0",
25
- "react-dom": "^18.2.0"
30
+ "files": [
31
+ "dist"
32
+ ],
33
+ "sideEffects": false,
34
+ "scripts": {
35
+ "build": "bun x vite build && bun x tsc --emitDeclarationOnly",
36
+ "dev": "bun x vite",
37
+ "test": "bun x vitest run"
26
38
  },
27
- "scripts": {},
28
- "gitHead": "fb8ae2fcdb9b694e4d9db31209e59f280e63fab4"
39
+ "peerDependencies": {
40
+ "react": "^18.0.0",
41
+ "react-dom": "^18.0.0"
42
+ }
29
43
  }
package/CHANGELOG.json DELETED
@@ -1,17 +0,0 @@
1
- [
2
- {
3
- "type": "feat",
4
- "scope": "mask-markup",
5
- "subject": "merging with the develop branch",
6
- "merge": null,
7
- "header": "feat(mask-markup): merging with the develop branch",
8
- "body": null,
9
- "footer": null,
10
- "notes": [],
11
- "hash": "0153c1aba8a08ba6c974fcc69476a87b9086f6c5",
12
- "gitTags": "",
13
- "committerDate": "2019-05-02 07:12:59 +0300",
14
- "isTagged": true,
15
- "tag": "@pie-lib/math-input@6.10.0"
16
- }
17
- ]