@pie-lib/math-input 8.1.1-next.3 → 8.1.1-next.4

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.
@@ -0,0 +1,28 @@
1
+ /**
2
+ * @synced-from pie-lib/packages/math-input/src/mq/mathquill-instance.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 let MQ: any;
10
+ /**
11
+ * Register a MathQuill embed (e.g. answer blocks in pie-elements).
12
+ * No-op in SSR or if the interface is unavailable.
13
+ *
14
+ * @param {string} name
15
+ * @param {Function} factory
16
+ */
17
+ export declare function registerEmbed(name: any, factory: any): void;
18
+ /**
19
+ * Apply MathQuill static math to a DOM element.
20
+ * Optionally sets element text to `latex` before enhancing (typical pie-elements usage).
21
+ *
22
+ * @param {HTMLElement} element
23
+ * @param {string} [latex] If provided, assigned to element.textContent before StaticMath runs.
24
+ * @param {object} [options] Optional MathQuill StaticMath options (e.g. handlers).
25
+ * @returns {object|undefined} MathQuill static math instance, if any.
26
+ */
27
+ export declare function applyStaticMath(element: any, latex: any, options: any): any;
28
+ export { MQ };
@@ -0,0 +1,13 @@
1
+ import { registerLineBreak as e } from "./custom-elements.js";
2
+ import t from "@pie-framework/mathquill";
3
+ //#region src/mq/mathquill-instance.ts
4
+ var n;
5
+ typeof window < "u" && (n = t.getInterface(3), n && n.registerEmbed && e(n));
6
+ function r(e, t) {
7
+ !n || !n.registerEmbed || n.registerEmbed(e, t);
8
+ }
9
+ function i(e, t, r) {
10
+ if (!(!n || !e)) return t != null && (e.textContent = t), n.StaticMath(e, r);
11
+ }
12
+ //#endregion
13
+ export { n as MQ, i as applyStaticMath, r as registerEmbed };
@@ -1,6 +1,10 @@
1
1
  /**
2
2
  * @synced-from pie-lib/packages/math-input/src/mq/static.jsx
3
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.
4
8
  */
5
9
  import PropTypes from 'prop-types';
6
10
  import React from 'react';
package/dist/mq/static.js CHANGED
@@ -1,22 +1,20 @@
1
1
  import { updateSpans as e } from "../updateSpans.js";
2
- import t from "@pie-framework/mathquill";
2
+ import { MQ as t } from "./mathquill-instance.js";
3
3
  import n from "react";
4
4
  import r from "prop-types";
5
5
  import i from "debug";
6
6
  import { jsx as a } from "react/jsx-runtime";
7
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, "");
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, "");
13
11
  }
14
- function d(e) {
12
+ function u(e) {
15
13
  let t = 0;
16
14
  for (let n = 0; n < (e || "").length; n++) e[n] === "{" && t++;
17
15
  return t;
18
16
  }
19
- var f = class extends n.Component {
17
+ var d = class extends n.Component {
20
18
  static propTypes = {
21
19
  latex: r.string.isRequired,
22
20
  onFocus: r.func,
@@ -66,9 +64,18 @@ var f = class extends n.Component {
66
64
  this.setState({ inputSource: "mathKeyboard" });
67
65
  };
68
66
  onInputEdit = (e) => {
69
- if (!this.mathField) return;
67
+ if (!this.mathField || this._isProgrammaticUpdate) return;
70
68
  let t = this.props.getFieldName(e, this.mathField.innerFields);
71
- this.props.onSubFieldChange && this.props.onSubFieldChange(t, e.latex()), this.announceLatexConversion(e.latex());
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());
72
79
  };
73
80
  announceLatexConversion = (e) => {
74
81
  if (!this.state) {
@@ -76,13 +83,13 @@ var f = class extends n.Component {
76
83
  return;
77
84
  }
78
85
  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);
86
+ if (n === "keyboard" && !r) if (u(e) > u(t)) this.announceMessage(i);
80
87
  else try {
81
88
  this.mathField.parseLatex(t), this.mathField.parseLatex(e), e == t && this.announceMessage(i);
82
89
  } catch (e) {
83
90
  console.warn("Error parsing latex:", e.message), console.warn(e);
84
91
  }
85
- this.setState({
92
+ (this.state.previousLatex !== e || this.state.isDeleteKeyPressed) && this.setState({
86
93
  previousLatex: e,
87
94
  isDeleteKeyPressed: !1
88
95
  });
@@ -93,24 +100,26 @@ var f = class extends n.Component {
93
100
  }, 500));
94
101
  };
95
102
  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) } });
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) } });
98
105
  try {
99
- this.mathField.parseLatex(this.props.latex), this.mathField.latex(this.props.latex);
106
+ this._isProgrammaticUpdate = !0, this.mathField.parseLatex(this.props.latex), this.mathField.latex(this.props.latex);
100
107
  } catch {
101
108
  this.mathField.latex("\\MathQuillMathField[r1]{}");
109
+ } finally {
110
+ this._isProgrammaticUpdate = !1;
102
111
  }
103
112
  };
104
113
  blur = () => {
105
- s("blur mathfield"), this.mathField.blur();
114
+ o("blur mathfield"), this.mathField.blur();
106
115
  };
107
116
  focus = () => {
108
- s("focus mathfield..."), this.mathField.focus();
117
+ o("focus mathfield..."), this.mathField.focus();
109
118
  };
110
119
  shouldComponentUpdate(e) {
111
120
  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;
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;
114
123
  } catch (e) {
115
124
  return console.warn("Error parsing latex:", e.message, "skip update"), console.warn(e), !1;
116
125
  }
@@ -139,4 +148,4 @@ var f = class extends n.Component {
139
148
  }
140
149
  };
141
150
  //#endregion
142
- export { f as default };
151
+ export { d as default };
@@ -6,5 +6,5 @@
6
6
  * Manual edits will be overwritten on next sync.
7
7
  * To make changes, edit the upstream JavaScript file and run sync again.
8
8
  */
9
- declare const updateSpans: (root?: ParentNode) => void;
9
+ declare const updateSpans: () => void;
10
10
  export { updateSpans };
@@ -1,7 +1,6 @@
1
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) => {
2
+ var e = () => {
3
+ (Array.from(document.querySelectorAll("span[mathquill-command-id]")) || []).forEach((e) => {
5
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");
6
5
  });
7
6
  };
package/package.json CHANGED
@@ -1,20 +1,22 @@
1
1
  {
2
2
  "name": "@pie-lib/math-input",
3
- "version": "8.1.1-next.3",
3
+ "version": "8.1.1-next.4",
4
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"
9
+ },
5
10
  "dependencies": {
6
11
  "@emotion/react": "^11.14.0",
7
- "@emotion/style": "^0.8.0",
8
- "@fontsource/stix-two-text": "^5.2.8",
12
+ "@emotion/styled": "^11.14.1",
9
13
  "@mui/icons-material": "^7.3.4",
10
14
  "@mui/material": "^7.3.4",
11
- "@pie-framework/mathquill": "^1.1.4",
12
- "@pie-element/shared-math-rendering-mathjax": "0.1.1-next.0",
13
- "@pie-lib/render-ui": "6.1.1-next.38",
15
+ "@pie-framework/mathquill": "1.2.1-beta.1",
14
16
  "debug": "^4.1.1",
15
- "@pie-element/shared-lodash": "0.1.1-next.1",
16
17
  "prop-types": "^15.7.2",
17
- "react": "^18.2.0"
18
+ "@pie-element/shared-lodash": "0.1.1-next.1",
19
+ "@pie-lib/render-ui": "6.1.1-next.39"
18
20
  },
19
21
  "type": "module",
20
22
  "main": "./dist/index.js",
@@ -40,5 +42,9 @@
40
42
  "@vitejs/plugin-react": "^6.0.1",
41
43
  "@types/react": "^18.2.0",
42
44
  "@types/react-dom": "^18.2.0"
45
+ },
46
+ "peerDependencies": {
47
+ "react": "^18.0.0",
48
+ "react-dom": "^18.0.0"
43
49
  }
44
50
  }
@@ -1,37 +0,0 @@
1
- import React from 'react';
2
- import PropTypes from 'prop-types';
3
- export default class AccessibleKeypad extends React.Component {
4
- static propTypes: {
5
- className: PropTypes.Requireable<string>;
6
- controlledKeypadMode: PropTypes.Requireable<boolean>;
7
- baseSet: PropTypes.Requireable<any[]>;
8
- additionalKeys: PropTypes.Requireable<any[]>;
9
- layoutForKeyPad: PropTypes.Requireable<object>;
10
- onPress: PropTypes.Validator<(...args: any[]) => any>;
11
- onFocus: PropTypes.Requireable<(...args: any[]) => any>;
12
- noDecimal: PropTypes.Requireable<boolean>;
13
- setKeypadInteraction: PropTypes.Requireable<(...args: any[]) => any>;
14
- mode: PropTypes.Requireable<NonNullable<string | number | null | undefined>>;
15
- onRequestClose: PropTypes.Requireable<(...args: any[]) => any>;
16
- };
17
- static defaultProps: {
18
- baseSet: any[][];
19
- noDecimal: boolean;
20
- };
21
- constructor(props: any);
22
- componentDidMount(): void;
23
- componentWillUnmount(): void;
24
- handleKeypadInteraction: () => void;
25
- keyIsNotAllowed: (key: any) => any;
26
- flowKeys: (base: any, extras: any) => unknown[];
27
- toRenderModel: () => {
28
- id: string;
29
- ariaLabel: string;
30
- key: any;
31
- }[];
32
- pressKey: (definition: any) => void;
33
- moveFocus: (nextIndex: any) => void;
34
- onButtonKeyDown: (event: any, index: any) => void;
35
- renderKey: (definition: any, index: any) => React.JSX.Element;
36
- render(): React.JSX.Element;
37
- }