@pie-lib/math-input 0.1.0 → 0.1.1-next.0

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 (106) hide show
  1. package/dist/horizontal-keypad.d.ts +1 -2
  2. package/dist/index.d.ts +0 -1
  3. package/dist/keypad/accessible-keypad.d.ts +2 -3
  4. package/dist/keypad/index.d.ts +0 -1
  5. package/dist/keypad/keys-layout.d.ts +0 -1
  6. package/dist/keypad/model.d.ts +0 -1
  7. package/dist/keys/basic-operators.d.ts +0 -1
  8. package/dist/keys/chars.d.ts +0 -1
  9. package/dist/keys/comparison.d.ts +0 -1
  10. package/dist/keys/constants.d.ts +0 -1
  11. package/dist/keys/digits.d.ts +0 -1
  12. package/dist/keys/edit.d.ts +0 -1
  13. package/dist/keys/exponent.d.ts +0 -1
  14. package/dist/keys/fractions.d.ts +0 -1
  15. package/dist/keys/geometry.d.ts +0 -1
  16. package/dist/keys/grades.d.ts +0 -1
  17. package/dist/keys/index.d.ts +0 -1
  18. package/dist/keys/log.d.ts +0 -1
  19. package/dist/keys/logic.d.ts +0 -1
  20. package/dist/keys/matrices.d.ts +0 -1
  21. package/dist/keys/misc.d.ts +0 -1
  22. package/dist/keys/navigation.d.ts +0 -1
  23. package/dist/keys/operators.d.ts +0 -1
  24. package/dist/keys/statistics.d.ts +0 -1
  25. package/dist/keys/sub-sup.d.ts +0 -1
  26. package/dist/keys/trigonometry.d.ts +0 -1
  27. package/dist/keys/utils.d.ts +0 -1
  28. package/dist/keys/vars.d.ts +0 -1
  29. package/dist/math-input.d.ts +1 -2
  30. package/dist/mq/common-mq-styles.d.ts +0 -1
  31. package/dist/mq/custom-elements.d.ts +0 -1
  32. package/dist/mq/index.d.ts +0 -1
  33. package/dist/mq/input.d.ts +1 -2
  34. package/dist/mq/static.d.ts +1 -2
  35. package/dist/updateSpans.d.ts +0 -1
  36. package/package.json +10 -4
  37. package/dist/horizontal-keypad.d.ts.map +0 -1
  38. package/dist/index.d.ts.map +0 -1
  39. package/dist/keypad/accessible-keypad.d.ts.map +0 -1
  40. package/dist/keypad/index.d.ts.map +0 -1
  41. package/dist/keypad/keys-layout.d.ts.map +0 -1
  42. package/dist/keypad/model.d.ts.map +0 -1
  43. package/dist/keys/basic-operators.d.ts.map +0 -1
  44. package/dist/keys/chars.d.ts.map +0 -1
  45. package/dist/keys/comparison.d.ts.map +0 -1
  46. package/dist/keys/constants.d.ts.map +0 -1
  47. package/dist/keys/digits.d.ts.map +0 -1
  48. package/dist/keys/edit.d.ts.map +0 -1
  49. package/dist/keys/exponent.d.ts.map +0 -1
  50. package/dist/keys/fractions.d.ts.map +0 -1
  51. package/dist/keys/geometry.d.ts.map +0 -1
  52. package/dist/keys/grades.d.ts.map +0 -1
  53. package/dist/keys/index.d.ts.map +0 -1
  54. package/dist/keys/log.d.ts.map +0 -1
  55. package/dist/keys/logic.d.ts.map +0 -1
  56. package/dist/keys/matrices.d.ts.map +0 -1
  57. package/dist/keys/misc.d.ts.map +0 -1
  58. package/dist/keys/navigation.d.ts.map +0 -1
  59. package/dist/keys/operators.d.ts.map +0 -1
  60. package/dist/keys/statistics.d.ts.map +0 -1
  61. package/dist/keys/sub-sup.d.ts.map +0 -1
  62. package/dist/keys/trigonometry.d.ts.map +0 -1
  63. package/dist/keys/utils.d.ts.map +0 -1
  64. package/dist/keys/vars.d.ts.map +0 -1
  65. package/dist/math-input.d.ts.map +0 -1
  66. package/dist/mq/common-mq-styles.d.ts.map +0 -1
  67. package/dist/mq/custom-elements.d.ts.map +0 -1
  68. package/dist/mq/index.d.ts.map +0 -1
  69. package/dist/mq/input.d.ts.map +0 -1
  70. package/dist/mq/static.d.ts.map +0 -1
  71. package/dist/updateSpans.d.ts.map +0 -1
  72. package/src/horizontal-keypad.tsx +0 -82
  73. package/src/index.tsx +0 -27
  74. package/src/keypad/accessible-keypad.tsx +0 -731
  75. package/src/keypad/index.tsx +0 -3
  76. package/src/keypad/keys-layout.ts +0 -26
  77. package/src/keypad/model.ts +0 -149
  78. package/src/keys/basic-operators.ts +0 -42
  79. package/src/keys/chars.ts +0 -15
  80. package/src/keys/comparison.ts +0 -38
  81. package/src/keys/constants.ts +0 -45
  82. package/src/keys/digits.ts +0 -50
  83. package/src/keys/edit.ts +0 -13
  84. package/src/keys/exponent.ts +0 -38
  85. package/src/keys/fractions.ts +0 -36
  86. package/src/keys/geometry.ts +0 -154
  87. package/src/keys/grades.ts +0 -377
  88. package/src/keys/index.ts +0 -30
  89. package/src/keys/log.ts +0 -32
  90. package/src/keys/logic.ts +0 -25
  91. package/src/keys/matrices.ts +0 -25
  92. package/src/keys/misc.ts +0 -75
  93. package/src/keys/navigation.ts +0 -18
  94. package/src/keys/operators.ts +0 -20
  95. package/src/keys/statistics.ts +0 -48
  96. package/src/keys/sub-sup.ts +0 -25
  97. package/src/keys/trigonometry.ts +0 -25
  98. package/src/keys/utils.ts +0 -76
  99. package/src/keys/vars.ts +0 -29
  100. package/src/math-input.tsx +0 -129
  101. package/src/mq/common-mq-styles.ts +0 -115
  102. package/src/mq/custom-elements.tsx +0 -21
  103. package/src/mq/index.ts +0 -15
  104. package/src/mq/input.tsx +0 -172
  105. package/src/mq/static.tsx +0 -279
  106. package/src/updateSpans.ts +0 -26
package/src/mq/static.tsx DELETED
@@ -1,279 +0,0 @@
1
- // @ts-nocheck
2
- /**
3
- * @synced-from pie-lib/packages/math-input/src/mq/static.jsx
4
- * @auto-generated
5
- */
6
-
7
- import PropTypes from 'prop-types';
8
- import React from 'react';
9
- import debug from 'debug';
10
- import MathQuill from '@pie-framework/mathquill';
11
- import { updateSpans } from '../updateSpans';
12
-
13
- let MQ;
14
- if (typeof window !== 'undefined') {
15
- MQ = MathQuill.getInterface(2);
16
- }
17
-
18
- const log = debug('pie-lib:math-input:mq:static');
19
- const REGEX = /\\MathQuillMathField\[r\d*\]\{(.*?)\}/g;
20
- const WHITESPACE_REGEX = / /g;
21
-
22
- function stripSpaces(string = '') {
23
- return string.replace(WHITESPACE_REGEX, '');
24
- }
25
-
26
- function countBraces(latex) {
27
- let count = 0;
28
-
29
- for (let i = 0; i < (latex || '').length; i++) {
30
- if (latex[i] === '{') {
31
- count++;
32
- }
33
- }
34
-
35
- return count;
36
- }
37
-
38
- /**
39
- * Wrapper for MathQuill MQ.MathField.
40
- */
41
- export default class Static extends React.Component {
42
- static propTypes = {
43
- latex: PropTypes.string.isRequired,
44
- onFocus: PropTypes.func,
45
- onBlur: PropTypes.func,
46
- className: PropTypes.string,
47
- getFieldName: PropTypes.func,
48
- onSubFieldChange: PropTypes.func,
49
- onSubFieldFocus: PropTypes.func,
50
- setInput: PropTypes.func,
51
- };
52
-
53
- static defaultProps = {
54
- getFieldName: () => {},
55
- };
56
-
57
- constructor(props) {
58
- super(props);
59
- this.state = {
60
- announcement: '',
61
- previousLatex: '',
62
- inputSource: null,
63
- isDeleteKeyPressed: false,
64
- };
65
-
66
- this.inputRef = React.createRef();
67
- }
68
-
69
- componentDidMount() {
70
- this.update();
71
- updateSpans();
72
-
73
- this.createLiveRegion();
74
- this.addEventListeners();
75
- }
76
-
77
- componentDidUpdate() {
78
- this.update();
79
- updateSpans();
80
- }
81
-
82
- componentWillUnmount() {
83
- this.removeLiveRegion();
84
- this.removeEventListeners();
85
- }
86
-
87
- createLiveRegion: any = () => {
88
- this.liveRegion = document.createElement('div');
89
- this.liveRegion.style.position = 'absolute';
90
- this.liveRegion.style.width = '1px';
91
- this.liveRegion.style.height = '1px';
92
- this.liveRegion.style.marginTop = '-1px';
93
- this.liveRegion.style.clip = 'rect(1px, 1px, 1px, 1px)';
94
- this.liveRegion.style.overflow = 'hidden';
95
- this.liveRegion.setAttribute('aria-live', 'polite');
96
- this.liveRegion.setAttribute('aria-atomic', 'true');
97
-
98
- document.body.appendChild(this.liveRegion);
99
- };
100
-
101
- addEventListeners: any = () => {
102
- const input = this.inputRef.current;
103
-
104
- if (input) {
105
- input.addEventListener('keydown', this.handleKeyDown);
106
- input.addEventListener('click', this.handleMathKeyboardClick);
107
- }
108
- };
109
-
110
- removeEventListeners: any = () => {
111
- const input = this.inputRef.current;
112
-
113
- if (input) {
114
- input.removeEventListener('keydown', this.handleKeyDown);
115
- input.removeEventListener('click', this.handleMathKeyboardClick);
116
- }
117
- };
118
-
119
- removeLiveRegion: any = () => {
120
- if (this.liveRegion) {
121
- document.body.removeChild(this.liveRegion);
122
- this.liveRegion = null;
123
- }
124
- };
125
-
126
- handleKeyDown: any = (event) => {
127
- if (event?.key === 'Backspace' || event?.key === 'Delete') {
128
- this.setState({ isDeleteKeyPressed: true });
129
- }
130
- this.setState({ inputSource: 'keyboard' });
131
- };
132
-
133
- handleMathKeyboardClick: any = () => {
134
- this.setState({ inputSource: 'mathKeyboard' });
135
- };
136
-
137
- onInputEdit: any = (field) => {
138
- if (!this.mathField) {
139
- return;
140
- }
141
- const name = this.props.getFieldName(field, this.mathField.innerFields);
142
-
143
- if (this.props.onSubFieldChange) {
144
- this.props.onSubFieldChange(name, field.latex());
145
- }
146
-
147
- this.announceLatexConversion(field.latex());
148
- };
149
-
150
- announceLatexConversion: any = (newLatex) => {
151
- if (!this.state) {
152
- // eslint-disable-next-line no-console
153
- console.error('State is not initialized');
154
- return;
155
- }
156
-
157
- const { previousLatex, inputSource, isDeleteKeyPressed } = this.state;
158
- const announcement = 'Converted to math symbol';
159
-
160
- if (inputSource === 'keyboard' && !isDeleteKeyPressed) {
161
- const newBraces = countBraces(newLatex);
162
- const oldBraces = countBraces(previousLatex);
163
-
164
- if (newBraces > oldBraces) {
165
- this.announceMessage(announcement);
166
- } else {
167
- try {
168
- this.mathField.parseLatex(previousLatex);
169
- this.mathField.parseLatex(newLatex);
170
-
171
- if (newLatex == previousLatex) {
172
- this.announceMessage(announcement);
173
- }
174
- } catch (e) {
175
- // eslint-disable-next-line no-console
176
- console.warn('Error parsing latex:', e.message);
177
- // eslint-disable-next-line no-console
178
- console.warn(e);
179
- }
180
- }
181
- }
182
-
183
- this.setState({ previousLatex: newLatex, isDeleteKeyPressed: false });
184
- };
185
-
186
- announceMessage: any = (message) => {
187
- this.setState({ previousLatex: '' });
188
-
189
- if (this.liveRegion) {
190
- this.liveRegion.textContent = message;
191
-
192
- setTimeout(() => {
193
- this.liveRegion.textContent = '';
194
- }, 500);
195
- }
196
- };
197
-
198
- update: any = () => {
199
- if (!MQ) {
200
- throw new Error('MQ is not defined - but component has mounted?');
201
- }
202
- if (!this.mathField) {
203
- this.mathField = MQ.StaticMath(this.inputRef?.current, {
204
- handlers: {
205
- edit: this.onInputEdit.bind(this),
206
- },
207
- });
208
- }
209
-
210
- try {
211
- this.mathField.parseLatex(this.props.latex);
212
- this.mathField.latex(this.props.latex);
213
- } catch (e) {
214
- this.mathField.latex('\\MathQuillMathField[r1]{}');
215
- }
216
- };
217
-
218
- blur: any = () => {
219
- log('blur mathfield');
220
- this.mathField.blur();
221
- };
222
-
223
- focus: any = () => {
224
- log('focus mathfield...');
225
- this.mathField.focus();
226
- };
227
-
228
- shouldComponentUpdate(nextProps) {
229
- try {
230
- const parsedLatex = this.mathField.parseLatex(nextProps.latex);
231
- const stripped = stripSpaces(parsedLatex);
232
- const newFieldCount = (nextProps.latex.match(REGEX) || []).length;
233
-
234
- const out =
235
- stripped !== stripSpaces(this.mathField.latex().trim()) ||
236
- newFieldCount !== Object.keys(this.mathField.innerFields).length / 2;
237
-
238
- log('[shouldComponentUpdate] ', out);
239
- return out;
240
- } catch (e) {
241
- // eslint-disable-next-line no-console
242
- console.warn('Error parsing latex:', e.message, 'skip update');
243
- // eslint-disable-next-line no-console
244
- console.warn(e);
245
- return false;
246
- }
247
- }
248
-
249
- onFocus: any = (e) => {
250
- try {
251
- let rootBlock = e.target.parentElement.nextSibling;
252
- let 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
- const innerField = this.mathField.innerFields.find((f) => f.id === id);
260
-
261
- if (innerField) {
262
- const name = this.props.getFieldName(innerField, this.mathField.innerFields);
263
- if (this.props.setInput) {
264
- this.props.setInput(innerField);
265
- }
266
- this.props.onSubFieldFocus(name, innerField);
267
- }
268
- } catch (err) {
269
- // eslint-disable-next-line no-console
270
- console.error('error finding root block', err.message);
271
- }
272
- };
273
-
274
- render() {
275
- const { onBlur, className } = this.props;
276
-
277
- return <span className={className} onFocus={this.onFocus} onBlur={onBlur} ref={this.inputRef} />;
278
- }
279
- }
@@ -1,26 +0,0 @@
1
- // @ts-nocheck
2
- /**
3
- * @synced-from pie-lib/packages/math-input/src/updateSpans.js
4
- * @auto-generated
5
- *
6
- * This file is automatically synced from pie-elements and converted to TypeScript.
7
- * Manual edits will be overwritten on next sync.
8
- * To make changes, edit the upstream JavaScript file and run sync again.
9
- */
10
-
11
- // increase the font of parallel notation
12
- const updateSpans = (root?: ParentNode) => {
13
- const scope = root ?? document;
14
- const spans = Array.from(scope.querySelectorAll('span[mathquill-command-id]'));
15
- (spans || []).forEach((span) => {
16
- if (span && span.innerText === '∥' && span.className !== 'mq-editable-field') {
17
- span.style.fontSize = '32px';
18
- }
19
-
20
- if ((span.innerText === '′' || span.innerText === '′′') && !span.hasAttribute('data-prime')) {
21
- span.setAttribute('data-prime', 'true');
22
- }
23
- });
24
- };
25
-
26
- export { updateSpans };