@pie-lib/math-input 6.6.1-next.124 → 6.6.1-next.333

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 (61) hide show
  1. package/CHANGELOG.md +95 -0
  2. package/lib/horizontal-keypad.js +20 -15
  3. package/lib/horizontal-keypad.js.map +1 -1
  4. package/lib/index.js +11 -6
  5. package/lib/index.js.map +1 -1
  6. package/lib/keypad/index.js +76 -33
  7. package/lib/keypad/index.js.map +1 -1
  8. package/lib/keypad/keys-layout.js +5 -1
  9. package/lib/keypad/keys-layout.js.map +1 -1
  10. package/lib/keys/basic-operators.js +1 -1
  11. package/lib/keys/basic-operators.js.map +1 -1
  12. package/lib/keys/chars.js +1 -1
  13. package/lib/keys/chars.js.map +1 -1
  14. package/lib/keys/comparison.js +4 -4
  15. package/lib/keys/comparison.js.map +1 -1
  16. package/lib/keys/constants.js +1 -1
  17. package/lib/keys/constants.js.map +1 -1
  18. package/lib/keys/digits.js.map +1 -1
  19. package/lib/keys/edit.js.map +1 -1
  20. package/lib/keys/exponent.js +1 -1
  21. package/lib/keys/exponent.js.map +1 -1
  22. package/lib/keys/fractions.js +1 -1
  23. package/lib/keys/fractions.js.map +1 -1
  24. package/lib/keys/geometry.js +4 -4
  25. package/lib/keys/geometry.js.map +1 -1
  26. package/lib/keys/grades.js +14 -6
  27. package/lib/keys/grades.js.map +1 -1
  28. package/lib/keys/index.js +6 -2
  29. package/lib/keys/index.js.map +1 -1
  30. package/lib/keys/log.js +1 -1
  31. package/lib/keys/log.js.map +1 -1
  32. package/lib/keys/logic.js +1 -1
  33. package/lib/keys/logic.js.map +1 -1
  34. package/lib/keys/matrices.js +1 -1
  35. package/lib/keys/matrices.js.map +1 -1
  36. package/lib/keys/misc.js +1 -1
  37. package/lib/keys/misc.js.map +1 -1
  38. package/lib/keys/navigation.js.map +1 -1
  39. package/lib/keys/operators.js.map +1 -1
  40. package/lib/keys/statistics.js +1 -1
  41. package/lib/keys/statistics.js.map +1 -1
  42. package/lib/keys/sub-sup.js +1 -1
  43. package/lib/keys/sub-sup.js.map +1 -1
  44. package/lib/keys/trigonometry.js +1 -1
  45. package/lib/keys/trigonometry.js.map +1 -1
  46. package/lib/keys/utils.js +13 -9
  47. package/lib/keys/utils.js.map +1 -1
  48. package/lib/keys/vars.js +1 -1
  49. package/lib/keys/vars.js.map +1 -1
  50. package/lib/math-input.js +22 -16
  51. package/lib/math-input.js.map +1 -1
  52. package/lib/mq/custom-elements.js.map +1 -1
  53. package/lib/mq/index.js.map +1 -1
  54. package/lib/mq/input.js +16 -14
  55. package/lib/mq/input.js.map +1 -1
  56. package/lib/mq/static.js +16 -14
  57. package/lib/mq/static.js.map +1 -1
  58. package/package.json +2 -2
  59. package/src/horizontal-keypad.jsx +3 -1
  60. package/src/keypad/index.jsx +51 -5
  61. package/src/keys/grades.js +1 -1
@@ -18,6 +18,7 @@ export default class HorizontalKeypad extends React.Component {
18
18
  static propTypes = {
19
19
  className: PropTypes.string,
20
20
  mode: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
21
+ layoutForKeyPad: PropTypes.object,
21
22
  onClick: PropTypes.func.isRequired,
22
23
  onFocus: PropTypes.func,
23
24
  noDecimal: PropTypes.bool,
@@ -37,7 +38,7 @@ export default class HorizontalKeypad extends React.Component {
37
38
  };
38
39
 
39
40
  render() {
40
- const { mode, onFocus, noDecimal, className, additionalKeys } = this.props;
41
+ const { mode, onFocus, noDecimal, className, additionalKeys, layoutForKeyPad } = this.props;
41
42
  const normalizedKeys = normalizeAdditionalKeys(additionalKeys);
42
43
 
43
44
  return (
@@ -45,6 +46,7 @@ export default class HorizontalKeypad extends React.Component {
45
46
  className={className}
46
47
  onFocus={onFocus}
47
48
  noDecimal={noDecimal}
49
+ layoutForKeyPad={layoutForKeyPad}
48
50
  additionalKeys={extendKeySet(keysForGrade(mode), normalizedKeys)}
49
51
  onPress={this.keypadPress}
50
52
  mode={mode}
@@ -145,6 +145,20 @@ const LatexButton = withStyles(theme => ({
145
145
  } else {
146
146
  buttonClass = classNames(props.classes.latexButton, props.mqClassName);
147
147
  }
148
+
149
+ try {
150
+ const MQ = MathQuill.getInterface(2);
151
+ const span = document.createElement('span');
152
+ span.innerHTML = '';
153
+ const mathField = MQ.StaticMath(span);
154
+
155
+ mathField.parseLatex(props.latex);
156
+ mathField.latex(props.latex);
157
+ } catch (e) {
158
+ // received latex has errors - do not create button
159
+ return <></>;
160
+ }
161
+
148
162
  return (
149
163
  <Button className={classNames(props.classes.root, props.className)} onClick={props.onClick}>
150
164
  <mq.Static className={buttonClass} latex={props.latex} />
@@ -152,12 +166,25 @@ const LatexButton = withStyles(theme => ({
152
166
  );
153
167
  });
154
168
 
169
+ const createCustomLayout = layoutObj => {
170
+ if (layoutObj) {
171
+ return {
172
+ gridTemplateColumns: `repeat(${layoutObj.columns}, minmax(min-content, 150px))`,
173
+ gridTemplateRows: `repeat(${layoutObj.rows}, minmax(40px, 60px))`,
174
+ gridAutoFlow: 'initial'
175
+ };
176
+ }
177
+
178
+ return {};
179
+ };
180
+
155
181
  export class KeyPad extends React.Component {
156
182
  static propTypes = {
157
183
  classes: PropTypes.object.isRequired,
158
184
  className: PropTypes.string,
159
185
  baseSet: PropTypes.array,
160
186
  additionalKeys: PropTypes.array,
187
+ layoutForKeyPad: PropTypes.object,
161
188
  onPress: PropTypes.func.isRequired,
162
189
  onFocus: PropTypes.func,
163
190
  noDecimal: PropTypes.bool,
@@ -193,14 +220,23 @@ export class KeyPad extends React.Component {
193
220
  };
194
221
 
195
222
  render() {
196
- const { classes, className, baseSet, additionalKeys, onFocus, mode } = this.props;
223
+ const {
224
+ classes,
225
+ className,
226
+ baseSet,
227
+ additionalKeys,
228
+ layoutForKeyPad,
229
+ onFocus,
230
+ mode
231
+ } = this.props;
197
232
 
198
233
  const noBaseSet = [
199
234
  'non-negative-integers',
200
235
  'integers',
201
236
  'decimals',
202
237
  'fractions',
203
- 'item-authoring'
238
+ 'item-authoring',
239
+ 'language'
204
240
  ];
205
241
 
206
242
  const keysWithoutBaseSet = noBaseSet.includes(mode);
@@ -211,10 +247,15 @@ export class KeyPad extends React.Component {
211
247
  const shift = allKeys.length % 5 ? 1 : 0;
212
248
  const style = {
213
249
  gridTemplateColumns: `repeat(${Math.floor(allKeys.length / 5) +
214
- shift}, minmax(min-content, 150px))`
250
+ shift}, minmax(min-content, 150px))`,
251
+ ...createCustomLayout(layoutForKeyPad)
215
252
  };
216
253
  return (
217
- <div className={classNames(classes.keys, className)} style={style} onFocus={onFocus}>
254
+ <div
255
+ className={classNames(classes.keys, className, classes[mode])}
256
+ style={style}
257
+ onFocus={onFocus}
258
+ >
218
259
  {allKeys.map((k, index) => {
219
260
  const onClick = this.buttonClick.bind(this, k);
220
261
 
@@ -227,11 +268,13 @@ export class KeyPad extends React.Component {
227
268
  className: classNames(
228
269
  classes.labelButton,
229
270
  !keysWithoutBaseSet && classes[k.category],
271
+ classes[k.extraClass],
230
272
  k.label === ',' && classes.comma,
231
273
  k.label === '.' && classes.dot
232
274
  ),
233
275
  disabled: this.keyIsNotAllowed(k),
234
- key: `${k.label || k.latex || k.command}-${index}`
276
+ key: `${k.label || k.latex || k.command}-${index}`,
277
+ ...(k.actions || {})
235
278
  };
236
279
 
237
280
  if (k.latex) {
@@ -267,6 +310,9 @@ const styles = theme => ({
267
310
  gridColumnGap: '0px',
268
311
  gridAutoFlow: 'column'
269
312
  },
313
+ character: {
314
+ textTransform: 'initial !important'
315
+ },
270
316
  holder: {
271
317
  position: 'relative',
272
318
  width: '100%',
@@ -374,6 +374,6 @@ export const normalizeAdditionalKeys = additionalKeys => {
374
374
  latex === key.otherNotation
375
375
  );
376
376
 
377
- return predefinedKey || additionalkey;
377
+ return !latex ? additionalkey : predefinedKey || additionalkey;
378
378
  });
379
379
  };