@pie-lib/math-input 6.11.4 → 6.12.0-beta.1

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 (46) hide show
  1. package/CHANGELOG.md +54 -187
  2. package/NEXT.CHANGELOG.json +1 -0
  3. package/lib/horizontal-keypad.js +9 -3
  4. package/lib/horizontal-keypad.js.map +1 -1
  5. package/lib/index.js +10 -14
  6. package/lib/index.js.map +1 -1
  7. package/lib/keypad/index.js +95 -24
  8. package/lib/keypad/index.js.map +1 -1
  9. package/lib/keys/geometry.js +4 -2
  10. package/lib/keys/geometry.js.map +1 -1
  11. package/lib/keys/grades.js +12 -0
  12. package/lib/keys/grades.js.map +1 -1
  13. package/lib/keys/log.js +1 -1
  14. package/lib/keys/log.js.map +1 -1
  15. package/lib/mq/common-mq-styles.js +110 -0
  16. package/lib/mq/common-mq-styles.js.map +1 -0
  17. package/lib/mq/index.js +8 -0
  18. package/lib/mq/index.js.map +1 -1
  19. package/lib/mq/input.js +12 -10
  20. package/lib/mq/input.js.map +1 -1
  21. package/lib/mq/static.js +198 -75
  22. package/lib/mq/static.js.map +1 -1
  23. package/lib/updateSpans.js +23 -0
  24. package/lib/updateSpans.js.map +1 -0
  25. package/package.json +5 -2
  26. package/src/__tests__/__snapshots__/math-input-test.jsx.snap +152 -0
  27. package/src/__tests__/math-input-test.jsx +85 -0
  28. package/src/horizontal-keypad.jsx +14 -1
  29. package/src/index.jsx +1 -10
  30. package/src/keypad/__tests__/__snapshots__/index.test.jsx.snap +193 -0
  31. package/src/keypad/__tests__/index.test.jsx +24 -0
  32. package/src/keypad/__tests__/keys-layout.test.js +15 -0
  33. package/src/keypad/index.jsx +99 -15
  34. package/src/keys/__tests__/utils.test.js +57 -0
  35. package/src/keys/geometry.js +6 -2
  36. package/src/keys/grades.js +11 -0
  37. package/src/keys/log.js +1 -1
  38. package/src/mq/__tests__/__snapshots__/input.test.jsx.snap +9 -0
  39. package/src/mq/__tests__/input.test.jsx +92 -0
  40. package/src/mq/__tests__/static.test.jsx +57 -0
  41. package/src/mq/common-mq-styles.js +105 -0
  42. package/src/mq/index.js +2 -1
  43. package/src/mq/input.jsx +22 -9
  44. package/src/mq/static.jsx +142 -13
  45. package/src/updateSpans.js +15 -0
  46. package/README.md +0 -27
@@ -0,0 +1,110 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.supsubStyles = exports.longdivStyles = exports["default"] = exports.commonMqKeyboardStyles = exports.commonMqFontStyles = void 0;
9
+
10
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
+
12
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
13
+
14
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
15
+
16
+ var commonMqFontStyles = {
17
+ fontFamily: 'MJXZERO, MJXTEX !important',
18
+ '-webkit-font-smoothing': 'antialiased !important',
19
+ '& .mq-math-mode > span > var': {
20
+ fontFamily: 'MJXZERO, MJXTEX-I !important'
21
+ },
22
+ '& .mq-math-mode span var': {
23
+ fontFamily: 'MJXZERO, MJXTEX-I !important'
24
+ },
25
+ '& .mq-math-mode .mq-nonSymbola': {
26
+ fontFamily: 'MJXZERO, MJXTEX-I !important'
27
+ },
28
+ '& .mq-math-mode > span > var.mq-operator-name': {
29
+ fontFamily: 'MJXZERO, MJXTEX !important'
30
+ }
31
+ };
32
+ exports.commonMqFontStyles = commonMqFontStyles;
33
+ var longdivStyles = {
34
+ '& .mq-longdiv-inner': {
35
+ marginTop: '-1px',
36
+ marginLeft: '5px !important;',
37
+ '& > .mq-empty': {
38
+ padding: '0 !important',
39
+ marginLeft: '0px !important',
40
+ marginTop: '2px'
41
+ }
42
+ },
43
+ '& .mq-math-mode .mq-longdiv': {
44
+ display: 'inline-flex !important'
45
+ }
46
+ };
47
+ exports.longdivStyles = longdivStyles;
48
+ var supsubStyles = {
49
+ '& .mq-math-mode sup.mq-nthroot': {
50
+ fontSize: '70% !important',
51
+ verticalAlign: '0.5em !important',
52
+ paddingRight: '0.15em'
53
+ },
54
+ '& .mq-math-mode .mq-supsub': {
55
+ fontSize: '70.7% !important'
56
+ },
57
+ '& .mq-supsub ': {
58
+ fontSize: '70.7%'
59
+ },
60
+ '& .mq-math-mode .mq-supsub.mq-sup-only': {
61
+ verticalAlign: '-0.1em !important',
62
+ '& .mq-sup': {
63
+ marginBottom: '0px !important'
64
+ }
65
+ },
66
+
67
+ /* But when the base is a fraction, move it higher */
68
+ '& .mq-math-mode .mq-fraction + .mq-supsub.mq-sup-only': {
69
+ verticalAlign: '0.4em !important'
70
+ },
71
+ '& .mq-math-mode .mq-supsub.mq-sup-only.mq-after-fraction-group': {
72
+ verticalAlign: '0.4em !important'
73
+ }
74
+ };
75
+ exports.supsubStyles = supsubStyles;
76
+ var commonMqKeyboardStyles = {
77
+ '& *': _objectSpread(_objectSpread(_objectSpread({}, commonMqFontStyles), longdivStyles), {}, {
78
+ '& .mq-math-mode .mq-sqrt-prefix': {
79
+ top: '0 !important'
80
+ },
81
+ '& .mq-math-mode .mq-empty': {
82
+ padding: '9px 1px !important'
83
+ },
84
+ '& .mq-math-mode .mq-supsub': {
85
+ fontSize: '70.7% !important'
86
+ },
87
+ '& .mq-math-mode .mq-sqrt-stem': {
88
+ marginTop: '-5px',
89
+ paddingTop: '4px'
90
+ },
91
+ '& .mq-math-mode .mq-paren': {
92
+ verticalAlign: 'middle !important'
93
+ },
94
+ '& .mq-math-mode .mq-overarrow .mq-overarrow-inner .mq-empty': {
95
+ padding: '0 !important'
96
+ },
97
+ '& .mq-math-mode .mq-overline .mq-overline-inner .mq-empty ': {
98
+ padding: '0 !important'
99
+ }
100
+ })
101
+ };
102
+ exports.commonMqKeyboardStyles = commonMqKeyboardStyles;
103
+ var _default = {
104
+ commonMqFontStyles: commonMqFontStyles,
105
+ longdivStyles: longdivStyles,
106
+ supsubStyles: supsubStyles,
107
+ commonMqKeyboardStyles: commonMqKeyboardStyles
108
+ };
109
+ exports["default"] = _default;
110
+ //# sourceMappingURL=common-mq-styles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/mq/common-mq-styles.js"],"names":["commonMqFontStyles","fontFamily","longdivStyles","marginTop","marginLeft","padding","display","supsubStyles","fontSize","verticalAlign","paddingRight","marginBottom","commonMqKeyboardStyles","top","paddingTop"],"mappings":";;;;;;;;;;;;;;;AAAO,IAAMA,kBAAkB,GAAG;AAChCC,EAAAA,UAAU,EAAE,4BADoB;AAEhC,4BAA0B,wBAFM;AAIhC,kCAAgC;AAC9BA,IAAAA,UAAU,EAAE;AADkB,GAJA;AAOhC,8BAA4B;AAC1BA,IAAAA,UAAU,EAAE;AADc,GAPI;AAUhC,oCAAkC;AAChCA,IAAAA,UAAU,EAAE;AADoB,GAVF;AAahC,mDAAiD;AAC/CA,IAAAA,UAAU,EAAE;AADmC;AAbjB,CAA3B;;AAkBA,IAAMC,aAAa,GAAG;AAC3B,yBAAuB;AACrBC,IAAAA,SAAS,EAAE,MADU;AAErBC,IAAAA,UAAU,EAAE,iBAFS;AAIrB,qBAAiB;AACfC,MAAAA,OAAO,EAAE,cADM;AAEfD,MAAAA,UAAU,EAAE,gBAFG;AAGfD,MAAAA,SAAS,EAAE;AAHI;AAJI,G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["export const commonMqFontStyles = {\n fontFamily: 'MJXZERO, MJXTEX !important',\n '-webkit-font-smoothing': 'antialiased !important',\n\n '& .mq-math-mode > span > var': {\n fontFamily: 'MJXZERO, MJXTEX-I !important',\n },\n '& .mq-math-mode span var': {\n fontFamily: 'MJXZERO, MJXTEX-I !important',\n },\n '& .mq-math-mode .mq-nonSymbola': {\n fontFamily: 'MJXZERO, MJXTEX-I !important',\n },\n '& .mq-math-mode > span > var.mq-operator-name': {\n fontFamily: 'MJXZERO, MJXTEX !important',\n },\n};\n\nexport const longdivStyles = {\n '& .mq-longdiv-inner': {\n marginTop: '-1px',\n marginLeft: '5px !important;',\n\n '& > .mq-empty': {\n padding: '0 !important',\n marginLeft: '0px !important',\n marginTop: '2px',\n },\n },\n\n '& .mq-math-mode .mq-longdiv': {\n display: 'inline-flex !important',\n },\n};\n\nexport const supsubStyles = {\n '& .mq-math-mode sup.mq-nthroot': {\n fontSize: '70% !important',\n verticalAlign: '0.5em !important',\n paddingRight: '0.15em',\n },\n '& .mq-math-mode .mq-supsub': {\n fontSize: '70.7% !important',\n },\n '& .mq-supsub ': {\n fontSize: '70.7%',\n },\n '& .mq-math-mode .mq-supsub.mq-sup-only': {\n verticalAlign: '-0.1em !important',\n\n '& .mq-sup': {\n marginBottom: '0px !important',\n },\n },\n /* But when the base is a fraction, move it higher */\n '& .mq-math-mode .mq-fraction + .mq-supsub.mq-sup-only': {\n verticalAlign: '0.4em !important',\n },\n\n '& .mq-math-mode .mq-supsub.mq-sup-only.mq-after-fraction-group': {\n verticalAlign: '0.4em !important',\n },\n};\n\nexport const commonMqKeyboardStyles = {\n '& *': {\n ...commonMqFontStyles,\n ...longdivStyles,\n '& .mq-math-mode .mq-sqrt-prefix': {\n top: '0 !important',\n },\n\n '& .mq-math-mode .mq-empty': {\n padding: '9px 1px !important',\n },\n\n '& .mq-math-mode .mq-supsub': {\n fontSize: '70.7% !important',\n },\n\n '& .mq-math-mode .mq-sqrt-stem': {\n marginTop: '-5px',\n paddingTop: '4px',\n },\n\n '& .mq-math-mode .mq-paren': {\n verticalAlign: 'middle !important',\n },\n\n '& .mq-math-mode .mq-overarrow .mq-overarrow-inner .mq-empty': {\n padding: '0 !important',\n },\n\n '& .mq-math-mode .mq-overline .mq-overline-inner .mq-empty ': {\n padding: '0 !important',\n },\n },\n};\n\nexport default {\n commonMqFontStyles,\n longdivStyles,\n supsubStyles,\n commonMqKeyboardStyles,\n};\n"],"file":"common-mq-styles.js"}
package/lib/mq/index.js CHANGED
@@ -5,6 +5,12 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
+ Object.defineProperty(exports, "CommonMqStyles", {
9
+ enumerable: true,
10
+ get: function get() {
11
+ return _commonMqStyles["default"];
12
+ }
13
+ });
8
14
  Object.defineProperty(exports, "Input", {
9
15
  enumerable: true,
10
16
  get: function get() {
@@ -21,4 +27,6 @@ Object.defineProperty(exports, "Static", {
21
27
  var _input = _interopRequireDefault(require("./input"));
22
28
 
23
29
  var _static = _interopRequireDefault(require("./static"));
30
+
31
+ var _commonMqStyles = _interopRequireDefault(require("./common-mq-styles"));
24
32
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/mq/index.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;;AACA","sourcesContent":["import Input from './input';\nimport Static from './static';\n\nexport { Input, Static };\n"],"file":"index.js"}
1
+ {"version":3,"sources":["../../src/mq/index.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA","sourcesContent":["import Input from './input';\nimport Static from './static';\nimport CommonMqStyles from './common-mq-styles';\n\nexport { Input, Static, CommonMqStyles };\n"],"file":"index.js"}
package/lib/mq/input.js CHANGED
@@ -97,14 +97,17 @@ var Input = /*#__PURE__*/function (_React$Component) {
97
97
  }
98
98
 
99
99
  if (event.charCode === 13) {
100
- // if enter's pressed, we're going for a custom embedded element that'll
101
- // have a block display (empty div) - for a hacked line break using ccs
102
- // all because mathquill doesn't support a line break
103
- _this.write('\\embed{newLine}[]');
104
-
105
- _this.onInputEdit();
100
+ event.preventDefault();
101
+ return;
106
102
  }
107
103
  });
104
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "onClick", function (event) {
105
+ var onClick = _this.props.onClick;
106
+
107
+ _this.refresh();
108
+
109
+ onClick && onClick(event);
110
+ });
108
111
  return _this;
109
112
  }
110
113
 
@@ -136,7 +139,7 @@ var Input = /*#__PURE__*/function (_React$Component) {
136
139
 
137
140
  var latex = this.props.latex;
138
141
 
139
- if (latex) {
142
+ if (latex !== undefined && latex !== null) {
140
143
  this.mathField.latex(latex);
141
144
  }
142
145
  }
@@ -204,15 +207,14 @@ var Input = /*#__PURE__*/function (_React$Component) {
204
207
  var _this3 = this;
205
208
 
206
209
  var _this$props = this.props,
207
- onClick = _this$props.onClick,
208
210
  onFocus = _this$props.onFocus,
209
211
  onBlur = _this$props.onBlur,
210
212
  classes = _this$props.classes,
211
213
  className = _this$props.className;
212
214
  return /*#__PURE__*/_react["default"].createElement("span", {
213
215
  className: (0, _classnames["default"])(classes.input, className),
214
- onKeyPress: this.onKeyPress,
215
- onClick: onClick,
216
+ onKeyDown: this.onKeyPress,
217
+ onClick: this.onClick,
216
218
  onFocus: onFocus,
217
219
  onBlur: onBlur,
218
220
  ref: function ref(r) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/mq/input.jsx"],"names":["MQ","window","MathQuill","getInterface","registerEmbed","log","Input","onChange","props","mathField","latex","blur","focus","event","keys","Object","__controller","options","indexOf","refresh","charCode","write","onInputEdit","Error","MathField","input","handlers","edit","bind","updateLatex","v","Array","isArray","forEach","vv","cmd","keystroke","nextProps","onClick","onFocus","onBlur","classes","className","onKeyPress","r","React","Component","PropTypes","string","object","isRequired","func","styles"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;A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,EAAAA,KAAK,EAAEqC,sBAAUC,MALA;AAMjBT,EAAAA,OAAO,EAAEQ,sBAAUI,IANF;AAOjBX,EAAAA,MAAM,EAAEO,sBAAUI;AAPD,C;;AAyIrB,IAAMC,MAAM,GAAG,SAATA,MAAS;AAAA,SAAO,EAAP;AAAA,CAAf;;eAEe,wBAAWA,MAAX,EAAmB9C,KAAnB,C","sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\nimport { withStyles } from '@material-ui/core/styles';\nimport debug from 'debug';\nimport classNames from 'classnames';\nimport { registerLineBreak } from './custom-elements';\nimport MathQuill from '@pie-framework/mathquill';\n\nlet MQ;\nif (typeof window !== 'undefined') {\n MQ = MathQuill.getInterface(2);\n\n if (MQ && MQ.registerEmbed) {\n registerLineBreak(MQ);\n }\n}\n\nconst log = debug('math-input:mq:input');\n\n/**\n * Wrapper for MathQuill MQ.MathField.\n */\nexport class Input extends React.Component {\n static propTypes = {\n className: PropTypes.string,\n classes: PropTypes.object.isRequired,\n onClick: PropTypes.func,\n onChange: PropTypes.func,\n latex: PropTypes.string,\n onFocus: PropTypes.func,\n onBlur: PropTypes.func,\n };\n\n componentDidMount() {\n if (!MQ) {\n throw new Error('MQ is not defined - but component has mounted?');\n }\n\n this.mathField = MQ.MathField(this.input, {\n handlers: {\n edit: this.onInputEdit.bind(this),\n },\n });\n\n this.updateLatex();\n }\n\n componentDidUpdate() {\n this.updateLatex();\n }\n\n updateLatex() {\n if (!this.mathField) {\n return;\n }\n const { latex } = this.props;\n if (latex) {\n this.mathField.latex(latex);\n }\n }\n\n clear() {\n this.mathField.latex('');\n return '';\n }\n\n blur() {\n log('blur mathfield');\n this.mathField.blur();\n }\n\n focus() {\n log('focus mathfield...');\n this.mathField.focus();\n }\n\n command(v) {\n log('command: ', v);\n if (Array.isArray(v)) {\n v.forEach((vv) => {\n this.mathField.cmd(vv);\n });\n } else {\n this.mathField.cmd(v);\n }\n this.mathField.focus();\n return this.mathField.latex();\n }\n\n keystroke(v) {\n this.mathField.keystroke(v);\n this.mathField.focus();\n return this.mathField.latex();\n }\n\n write(v) {\n log('write: ', v);\n this.mathField.write(v);\n this.mathField.focus();\n return this.mathField.latex();\n }\n\n onInputEdit = () => {\n log('[onInputEdit] ...');\n const { onChange } = this.props;\n if (!this.mathField) {\n return;\n }\n\n if (onChange) {\n onChange(this.mathField.latex());\n }\n };\n\n refresh = () => {\n this.blur();\n this.focus();\n };\n\n onKeyPress = (event) => {\n const keys = Object.keys(this.mathField.__controller.options);\n\n if (keys.indexOf('ignoreNextMousedown') < 0) {\n // It seems like the controller has the above handler as an option\n // when all the right events are set and everything works fine\n // this seems to work in all cases\n this.refresh();\n }\n\n if (event.charCode === 13) {\n // if enter's pressed, we're going for a custom embedded element that'll\n // have a block display (empty div) - for a hacked line break using ccs\n // all because mathquill doesn't support a line break\n this.write('\\\\embed{newLine}[]');\n this.onInputEdit();\n }\n };\n\n shouldComponentUpdate(nextProps) {\n log('next: ', nextProps.latex);\n log('current: ', this.mathField.latex());\n return nextProps.latex !== this.mathField.latex();\n }\n\n render() {\n const { onClick, onFocus, onBlur, classes, className } = this.props;\n\n return (\n <span\n className={classNames(classes.input, className)}\n onKeyPress={this.onKeyPress}\n onClick={onClick}\n onFocus={onFocus}\n onBlur={onBlur}\n ref={(r) => (this.input = r)}\n />\n );\n }\n}\n\nconst styles = () => ({});\n\nexport default withStyles(styles)(Input);\n"],"file":"input.js"}
1
+ {"version":3,"sources":["../../src/mq/input.jsx"],"names":["MQ","window","MathQuill","getInterface","registerEmbed","log","Input","onChange","props","mathField","latex","blur","focus","event","keys","Object","__controller","options","indexOf","refresh","charCode","preventDefault","onClick","Error","MathField","input","handlers","edit","onInputEdit","bind","updateLatex","undefined","v","Array","isArray","forEach","vv","cmd","keystroke","write","nextProps","onFocus","onBlur","classes","className","onKeyPress","r","React","Component","PropTypes","string","object","isRequired","func","styles"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AAC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OAAO,EAAEM,sBAAUE,MAAV,CAAiBC,UAFT;AAGjB9B,EAAAA,OAAO,EAAE2B,sBAAUI,IAHF;AAIjB9C,EAAAA,QAAQ,EAAE0C,sBAAUI,IAJH;AAKjB3C,EAAAA,KAAK,EAAEuC,sBAAUC,MALA;AAMjBT,EAAAA,OAAO,EAAEQ,sBAAUI,IANF;AAOjBX,EAAAA,MAAM,EAAEO,sBAAUI;AAPD,C;;AAsJrB,IAAMC,MAAM,GAAG,SAATA,MAAS;AAAA,SAAO,EAAP;AAAA,CAAf;;eAEe,wBAAWA,MAAX,EAAmBhD,KAAnB,C","sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\nimport { withStyles } from '@material-ui/core/styles';\nimport debug from 'debug';\nimport classNames from 'classnames';\nimport { registerLineBreak } from './custom-elements';\nimport MathQuill from '@pie-framework/mathquill';\n\nlet MQ;\nif (typeof window !== 'undefined') {\n MQ = MathQuill.getInterface(2);\n\n if (MQ && MQ.registerEmbed) {\n registerLineBreak(MQ);\n }\n}\n\nconst log = debug('math-input:mq:input');\n\n/**\n * Wrapper for MathQuill MQ.MathField.\n */\nexport class Input extends React.Component {\n static propTypes = {\n className: PropTypes.string,\n classes: PropTypes.object.isRequired,\n onClick: PropTypes.func,\n onChange: PropTypes.func,\n latex: PropTypes.string,\n onFocus: PropTypes.func,\n onBlur: PropTypes.func,\n };\n\n componentDidMount() {\n if (!MQ) {\n throw new Error('MQ is not defined - but component has mounted?');\n }\n\n this.mathField = MQ.MathField(this.input, {\n handlers: {\n edit: this.onInputEdit.bind(this),\n },\n });\n\n this.updateLatex();\n }\n\n componentDidUpdate() {\n this.updateLatex();\n }\n\n updateLatex() {\n if (!this.mathField) {\n return;\n }\n\n const { latex } = this.props;\n\n if (latex !== undefined && latex !== null) {\n this.mathField.latex(latex);\n }\n }\n\n clear() {\n this.mathField.latex('');\n\n return '';\n }\n\n blur() {\n log('blur mathfield');\n this.mathField.blur();\n }\n\n focus() {\n log('focus mathfield...');\n this.mathField.focus();\n }\n\n command(v) {\n log('command: ', v);\n if (Array.isArray(v)) {\n v.forEach((vv) => {\n this.mathField.cmd(vv);\n });\n } else {\n this.mathField.cmd(v);\n }\n\n this.mathField.focus();\n\n return this.mathField.latex();\n }\n\n keystroke(v) {\n this.mathField.keystroke(v);\n this.mathField.focus();\n\n return this.mathField.latex();\n }\n\n write(v) {\n log('write: ', v);\n this.mathField.write(v);\n this.mathField.focus();\n\n return this.mathField.latex();\n }\n\n onInputEdit = () => {\n log('[onInputEdit] ...');\n const { onChange } = this.props;\n\n if (!this.mathField) {\n return;\n }\n\n if (onChange) {\n onChange(this.mathField.latex());\n }\n };\n\n refresh = () => {\n this.blur();\n this.focus();\n };\n\n onKeyPress = (event) => {\n const keys = Object.keys(this.mathField.__controller.options);\n\n if (keys.indexOf('ignoreNextMousedown') < 0) {\n // It seems like the controller has the above handler as an option\n // when all the right events are set and everything works fine\n // this seems to work in all cases\n this.refresh();\n }\n\n if (event.charCode === 13) {\n event.preventDefault();\n return;\n }\n };\n\n onClick = (event) => {\n const { onClick } = this.props;\n\n this.refresh();\n onClick && onClick(event);\n };\n\n shouldComponentUpdate(nextProps) {\n log('next: ', nextProps.latex);\n log('current: ', this.mathField.latex());\n\n return nextProps.latex !== this.mathField.latex();\n }\n\n render() {\n const { onFocus, onBlur, classes, className } = this.props;\n\n return (\n <span\n className={classNames(classes.input, className)}\n onKeyDown={this.onKeyPress}\n onClick={this.onClick}\n onFocus={onFocus}\n onBlur={onBlur}\n ref={(r) => (this.input = r)}\n />\n );\n }\n}\n\nconst styles = () => ({});\n\nexport default withStyles(styles)(Input);\n"],"file":"input.js"}
package/lib/mq/static.js CHANGED
@@ -29,7 +29,7 @@ var _debug = _interopRequireDefault(require("debug"));
29
29
 
30
30
  var _mathquill = _interopRequireDefault(require("@pie-framework/mathquill"));
31
31
 
32
- var _index = require("../index");
32
+ var _updateSpans = require("../updateSpans");
33
33
 
34
34
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; }
35
35
 
@@ -49,6 +49,18 @@ function stripSpaces() {
49
49
  var string = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
50
50
  return string.replace(WHITESPACE_REGEX, '');
51
51
  }
52
+
53
+ function countBraces(latex) {
54
+ var count = 0;
55
+
56
+ for (var i = 0; i < (latex || '').length; i++) {
57
+ if (latex[i] === '{') {
58
+ count++;
59
+ }
60
+ }
61
+
62
+ return count;
63
+ }
52
64
  /**
53
65
  * Wrapper for MathQuill MQ.MathField.
54
66
  */
@@ -59,73 +71,78 @@ var Static = /*#__PURE__*/function (_React$Component) {
59
71
 
60
72
  var _super = _createSuper(Static);
61
73
 
62
- function Static() {
74
+ function Static(props) {
63
75
  var _this;
64
76
 
65
77
  (0, _classCallCheck2["default"])(this, Static);
78
+ _this = _super.call(this, props);
79
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "createLiveRegion", function () {
80
+ _this.liveRegion = document.createElement('div');
81
+ _this.liveRegion.style.position = 'absolute';
82
+ _this.liveRegion.style.width = '1px';
83
+ _this.liveRegion.style.height = '1px';
84
+ _this.liveRegion.style.marginTop = '-1px';
85
+ _this.liveRegion.style.clip = 'rect(1px, 1px, 1px, 1px)';
86
+ _this.liveRegion.style.overflow = 'hidden';
66
87
 
67
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
68
- args[_key] = arguments[_key];
69
- }
88
+ _this.liveRegion.setAttribute('aria-live', 'polite');
70
89
 
71
- _this = _super.call.apply(_super, [this].concat(args));
72
- (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "onFocus", function (e) {
73
- try {
74
- var rootBlock = e.target.parentElement.nextSibling;
75
- var id = parseInt(rootBlock.getAttribute('mathquill-block-id'), 10);
76
-
77
- if (!id) {
78
- rootBlock = rootBlock.parentElement;
79
- id = parseInt(rootBlock.getAttribute('mathquill-block-id'), 10);
80
- }
90
+ _this.liveRegion.setAttribute('aria-atomic', 'true');
81
91
 
82
- var innerField = _this.mathField.innerFields.find(function (f) {
83
- return f.id === id;
84
- });
85
-
86
- if (innerField) {
87
- var name = _this.props.getFieldName(innerField, _this.mathField.innerFields);
92
+ document.body.appendChild(_this.liveRegion);
93
+ });
94
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "addEventListeners", function () {
95
+ var input = _this.inputRef.current;
88
96
 
89
- if (_this.props.setInput) {
90
- _this.props.setInput(innerField);
91
- }
97
+ if (input) {
98
+ input.addEventListener('keydown', _this.handleKeyDown);
99
+ input.addEventListener('click', _this.handleMathKeyboardClick);
100
+ }
101
+ });
102
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "removeEventListeners", function () {
103
+ var input = _this.inputRef.current;
92
104
 
93
- _this.props.onSubFieldFocus(name, innerField);
94
- }
95
- } catch (err) {
96
- // eslint-disable-next-line no-console
97
- console.error('error finding root block', err.message);
105
+ if (input) {
106
+ input.removeEventListener('keydown', _this.handleKeyDown);
107
+ input.removeEventListener('click', _this.handleMathKeyboardClick);
98
108
  }
99
109
  });
100
- return _this;
101
- }
110
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "removeLiveRegion", function () {
111
+ if (_this.liveRegion) {
112
+ document.body.removeChild(_this.liveRegion);
113
+ _this.liveRegion = null;
114
+ }
115
+ });
116
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "handleKeyDown", function (event) {
117
+ if ((event === null || event === void 0 ? void 0 : event.key) === 'Backspace' || (event === null || event === void 0 ? void 0 : event.key) === 'Delete') {
118
+ _this.setState({
119
+ isDeleteKeyPressed: true
120
+ });
121
+ }
102
122
 
103
- (0, _createClass2["default"])(Static, [{
104
- key: "componentDidMount",
105
- value: function componentDidMount() {
106
- this.update();
107
- (0, _index.updateSpans)();
108
- }
109
- }, {
110
- key: "componentDidUpdate",
111
- value: function componentDidUpdate() {
112
- this.update();
113
- (0, _index.updateSpans)();
114
- }
115
- }, {
116
- key: "onInputEdit",
117
- value: function onInputEdit(field) {
118
- if (!this.mathField) {
123
+ _this.setState({
124
+ inputSource: 'keyboard'
125
+ });
126
+ });
127
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "handleMathKeyboardClick", function () {
128
+ _this.setState({
129
+ inputSource: 'mathKeyboard'
130
+ });
131
+ });
132
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "onInputEdit", function (field) {
133
+ if (!_this.mathField) {
119
134
  return;
120
135
  }
121
136
 
122
- var name = this.props.getFieldName(field, this.mathField.innerFields);
137
+ var name = _this.props.getFieldName(field, _this.mathField.innerFields);
138
+
139
+ if (_this.props.onSubFieldChange) {
140
+ var _this$inputRef;
123
141
 
124
- if (this.props.onSubFieldChange) {
125
142
  // eslint-disable-next-line no-useless-escape
126
143
  var regexMatch = field.latex().match(/[0-9]\\ \\frac\{[^\{]*\}\{ \}/);
127
144
 
128
- if (this.input && regexMatch && regexMatch !== null && regexMatch !== void 0 && regexMatch.length) {
145
+ if ((_this$inputRef = _this.inputRef) !== null && _this$inputRef !== void 0 && _this$inputRef.current && regexMatch && regexMatch !== null && regexMatch !== void 0 && regexMatch.length) {
129
146
  try {
130
147
  field.__controller.cursor.insLeftOf(field.__controller.cursor.parent[-1].parent);
131
148
 
@@ -137,45 +154,155 @@ var Static = /*#__PURE__*/function (_React$Component) {
137
154
  console.error(e.toString());
138
155
  }
139
156
  } else {
140
- this.props.onSubFieldChange(name, field.latex());
157
+ _this.props.onSubFieldChange(name, field.latex());
141
158
  }
142
159
  }
143
- }
144
- }, {
145
- key: "update",
146
- value: function update() {
160
+
161
+ _this.announceLatexConversion(field.latex());
162
+ });
163
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "announceLatexConversion", function (newLatex) {
164
+ if (!_this.state) {
165
+ console.error('State is not initialized');
166
+ return;
167
+ }
168
+
169
+ var _this$state = _this.state,
170
+ previousLatex = _this$state.previousLatex,
171
+ inputSource = _this$state.inputSource,
172
+ isDeleteKeyPressed = _this$state.isDeleteKeyPressed;
173
+ var announcement = 'Converted to math symbol';
174
+
175
+ if (inputSource === 'keyboard' && !isDeleteKeyPressed) {
176
+ var newBraces = countBraces(newLatex);
177
+ var oldBraces = countBraces(previousLatex);
178
+
179
+ if (newBraces > oldBraces) {
180
+ _this.announceMessage(announcement);
181
+ } else {
182
+ try {
183
+ _this.mathField.parseLatex(previousLatex);
184
+
185
+ _this.mathField.parseLatex(newLatex);
186
+
187
+ if (newLatex == previousLatex) {
188
+ _this.announceMessage(announcement);
189
+ }
190
+ } catch (e) {
191
+ console.warn('Error parsing latex:', e.message);
192
+ console.warn(e);
193
+ }
194
+ }
195
+ }
196
+
197
+ _this.setState({
198
+ previousLatex: newLatex,
199
+ isDeleteKeyPressed: false
200
+ });
201
+ });
202
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "announceMessage", function (message) {
203
+ _this.setState({
204
+ previousLatex: ''
205
+ });
206
+
207
+ if (_this.liveRegion) {
208
+ _this.liveRegion.textContent = message; // Clear the message after it is announced
209
+
210
+ setTimeout(function () {
211
+ _this.liveRegion.textContent = '';
212
+ }, 500);
213
+ }
214
+ });
215
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "update", function () {
147
216
  if (!MQ) {
148
217
  throw new Error('MQ is not defined - but component has mounted?');
149
- } // this.input.innerHTML = this.props.latex;
218
+ }
150
219
 
220
+ if (!_this.mathField) {
221
+ var _this$inputRef2;
151
222
 
152
- if (!this.mathField) {
153
- this.mathField = MQ.StaticMath(this.input, {
223
+ _this.mathField = MQ.StaticMath((_this$inputRef2 = _this.inputRef) === null || _this$inputRef2 === void 0 ? void 0 : _this$inputRef2.current, {
154
224
  handlers: {
155
- edit: this.onInputEdit.bind(this)
225
+ edit: _this.onInputEdit.bind((0, _assertThisInitialized2["default"])(_this))
156
226
  }
157
227
  });
158
228
  }
159
229
 
160
230
  try {
161
- this.mathField.parseLatex(this.props.latex);
162
- this.mathField.latex(this.props.latex);
231
+ _this.mathField.parseLatex(_this.props.latex);
232
+
233
+ _this.mathField.latex(_this.props.latex);
163
234
  } catch (e) {
164
235
  // default latex if received has errors
165
- this.mathField.latex('\\MathQuillMathField[r1]{}');
236
+ _this.mathField.latex('\\MathQuillMathField[r1]{}');
166
237
  }
238
+ });
239
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "blur", function () {
240
+ log('blur mathfield');
241
+
242
+ _this.mathField.blur();
243
+ });
244
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "focus", function () {
245
+ log('focus mathfield...');
246
+
247
+ _this.mathField.focus();
248
+ });
249
+ (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "onFocus", function (e) {
250
+ try {
251
+ var rootBlock = e.target.parentElement.nextSibling;
252
+ var id = parseInt(rootBlock.getAttribute('mathquill-block-id'), 10);
253
+
254
+ if (!id) {
255
+ rootBlock = rootBlock.parentElement;
256
+ id = parseInt(rootBlock.getAttribute('mathquill-block-id'), 10);
257
+ }
258
+
259
+ var innerField = _this.mathField.innerFields.find(function (f) {
260
+ return f.id === id;
261
+ });
262
+
263
+ if (innerField) {
264
+ var name = _this.props.getFieldName(innerField, _this.mathField.innerFields);
265
+
266
+ if (_this.props.setInput) {
267
+ _this.props.setInput(innerField);
268
+ }
269
+
270
+ _this.props.onSubFieldFocus(name, innerField);
271
+ }
272
+ } catch (err) {
273
+ // eslint-disable-next-line no-console
274
+ console.error('error finding root block', err.message);
275
+ }
276
+ });
277
+ _this.state = {
278
+ announcement: '',
279
+ previousLatex: '',
280
+ inputSource: null,
281
+ isDeleteKeyPressed: false
282
+ };
283
+ _this.inputRef = /*#__PURE__*/_react["default"].createRef();
284
+ return _this;
285
+ }
286
+
287
+ (0, _createClass2["default"])(Static, [{
288
+ key: "componentDidMount",
289
+ value: function componentDidMount() {
290
+ this.update();
291
+ (0, _updateSpans.updateSpans)();
292
+ this.createLiveRegion();
293
+ this.addEventListeners();
167
294
  }
168
295
  }, {
169
- key: "blur",
170
- value: function blur() {
171
- log('blur mathfield');
172
- this.mathField.blur();
296
+ key: "componentDidUpdate",
297
+ value: function componentDidUpdate() {
298
+ this.update();
299
+ (0, _updateSpans.updateSpans)();
173
300
  }
174
301
  }, {
175
- key: "focus",
176
- value: function focus() {
177
- log('focus mathfield...');
178
- this.mathField.focus();
302
+ key: "componentWillUnmount",
303
+ value: function componentWillUnmount() {
304
+ this.removeLiveRegion();
305
+ this.removeEventListeners();
179
306
  }
180
307
  }, {
181
308
  key: "shouldComponentUpdate",
@@ -198,8 +325,6 @@ var Static = /*#__PURE__*/function (_React$Component) {
198
325
  }, {
199
326
  key: "render",
200
327
  value: function render() {
201
- var _this2 = this;
202
-
203
328
  var _this$props = this.props,
204
329
  onBlur = _this$props.onBlur,
205
330
  className = _this$props.className;
@@ -207,9 +332,7 @@ var Static = /*#__PURE__*/function (_React$Component) {
207
332
  className: className,
208
333
  onFocus: this.onFocus,
209
334
  onBlur: onBlur,
210
- ref: function ref(r) {
211
- return _this2.input = r;
212
- }
335
+ ref: this.inputRef
213
336
  });
214
337
  }
215
338
  }]);