@khanacademy/perseus 6.1.0 → 6.2.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.
package/dist/index.js CHANGED
@@ -209,10 +209,10 @@ const symbStyle = {
209
209
  const basic = [() => [/*#__PURE__*/React__namespace.createElement("span", {
210
210
  key: "plus",
211
211
  style: slightlyBig
212
- }, "+"), "+"], () => [/*#__PURE__*/React__namespace.createElement("span", {
212
+ }, "+"), "PLUS"], () => [/*#__PURE__*/React__namespace.createElement("span", {
213
213
  key: "minus",
214
214
  style: prettyBig
215
- }, "-"), "-"],
215
+ }, "-"), "MINUS"],
216
216
  // TODO(joel) - display as \cdot when appropriate
217
217
  props => {
218
218
  const {
@@ -222,12 +222,12 @@ props => {
222
222
  return [/*#__PURE__*/React__namespace.createElement(TeX, {
223
223
  key: "times",
224
224
  style: prettyBig
225
- }, i18n__namespace.doNotTranslate("\\times")), "\\times"];
225
+ }, i18n__namespace.doNotTranslate("\\times")), "TIMES"];
226
226
  }
227
227
  return [/*#__PURE__*/React__namespace.createElement(TeX, {
228
228
  key: "times",
229
229
  style: prettyBig
230
- }, i18n__namespace.doNotTranslate("\\cdot")), "\\cdot"];
230
+ }, i18n__namespace.doNotTranslate("\\cdot")), "CDOT"];
231
231
  }, () => {
232
232
  const {
233
233
  TeX
@@ -235,17 +235,7 @@ props => {
235
235
  return [/*#__PURE__*/React__namespace.createElement(TeX, {
236
236
  key: "frac",
237
237
  style: prettyBig
238
- }, i18n__namespace.doNotTranslate("\\frac{x}{y}")),
239
- // If there's something in the input that can become part of a
240
- // fraction, typing "/" puts it in the numerator. If not, typing
241
- // "/" does nothing. In that case, enter a \frac.
242
- input => {
243
- const contents = input.latex();
244
- input.typedText("/");
245
- if (input.latex() === contents) {
246
- input.cmd("\\frac");
247
- }
248
- }];
238
+ }, i18n__namespace.doNotTranslate("\\frac{x}{y}")), "FRAC"];
249
239
  }];
250
240
  const buttonSets = {
251
241
  basic,
@@ -255,7 +245,7 @@ const buttonSets = {
255
245
  } = getDependencies();
256
246
  return [/*#__PURE__*/React__namespace.createElement(TeX, {
257
247
  key: "div"
258
- }, i18n__namespace.doNotTranslate("\\div")), "\\div"];
248
+ }, i18n__namespace.doNotTranslate("\\div")), "DIVIDE"];
259
249
  }]),
260
250
  trig: [() => {
261
251
  const {
@@ -263,21 +253,21 @@ const buttonSets = {
263
253
  } = getDependencies();
264
254
  return [/*#__PURE__*/React__namespace.createElement(TeX, {
265
255
  key: "sin"
266
- }, i18n__namespace.doNotTranslate("\\sin")), "\\sin"];
256
+ }, i18n__namespace.doNotTranslate("\\sin")), "SIN"];
267
257
  }, () => {
268
258
  const {
269
259
  TeX
270
260
  } = getDependencies();
271
261
  return [/*#__PURE__*/React__namespace.createElement(TeX, {
272
262
  key: "cos"
273
- }, i18n__namespace.doNotTranslate("\\cos")), "\\cos"];
263
+ }, i18n__namespace.doNotTranslate("\\cos")), "COS"];
274
264
  }, () => {
275
265
  const {
276
266
  TeX
277
267
  } = getDependencies();
278
268
  return [/*#__PURE__*/React__namespace.createElement(TeX, {
279
269
  key: "tan"
280
- }, i18n__namespace.doNotTranslate("\\tan")), "\\tan"];
270
+ }, i18n__namespace.doNotTranslate("\\tan")), "TAN"];
281
271
  }, () => {
282
272
  const {
283
273
  TeX
@@ -285,7 +275,7 @@ const buttonSets = {
285
275
  return [/*#__PURE__*/React__namespace.createElement(TeX, {
286
276
  key: "theta",
287
277
  style: symbStyle
288
- }, i18n__namespace.doNotTranslate("\\theta")), "\\theta"];
278
+ }, i18n__namespace.doNotTranslate("\\theta")), "THETA"];
289
279
  }, () => {
290
280
  const {
291
281
  TeX
@@ -297,7 +287,7 @@ const buttonSets = {
297
287
  }, i18n__namespace.doNotTranslate("phi")), /*#__PURE__*/React__namespace.createElement(TeX, {
298
288
  key: "pi",
299
289
  style: symbStyle
300
- }, i18n__namespace.doNotTranslate("\\phi"))), "\\phi"];
290
+ }, i18n__namespace.doNotTranslate("\\phi"))), "PHI"];
301
291
  }],
302
292
  prealgebra: [() => {
303
293
  const {
@@ -305,7 +295,7 @@ const buttonSets = {
305
295
  } = getDependencies();
306
296
  return [/*#__PURE__*/React__namespace.createElement(TeX, {
307
297
  key: "sqrt"
308
- }, i18n__namespace.doNotTranslate("\\sqrt{x}")), "\\sqrt"];
298
+ }, i18n__namespace.doNotTranslate("\\sqrt{x}")), "SQRT"];
309
299
  },
310
300
  // TODO(joel) - how does desmos do this?
311
301
  () => {
@@ -314,10 +304,7 @@ const buttonSets = {
314
304
  } = getDependencies();
315
305
  return [/*#__PURE__*/React__namespace.createElement(TeX, {
316
306
  key: "nthroot"
317
- }, i18n__namespace.doNotTranslate("\\sqrt[3]{x}")), input => {
318
- input.typedText("nthroot3");
319
- input.keystroke("Right");
320
- }];
307
+ }, i18n__namespace.doNotTranslate("\\sqrt[3]{x}")), "NTHROOT3"];
321
308
  }, () => {
322
309
  const {
323
310
  TeX
@@ -325,17 +312,7 @@ const buttonSets = {
325
312
  return [/*#__PURE__*/React__namespace.createElement(TeX, {
326
313
  key: "pow",
327
314
  style: slightlyBig
328
- }, i18n__namespace.doNotTranslate("a^b")), input => {
329
- const contents = input.latex();
330
- input.typedText("^");
331
-
332
- // If the input hasn't changed (for example, if we're
333
- // attempting to add an exponent on an empty input or an empty
334
- // denominator), insert our own "a^b"
335
- if (input.latex() === contents) {
336
- input.typedText("a^b");
337
- }
338
- }];
315
+ }, i18n__namespace.doNotTranslate("a^b")), "POW"];
339
316
  }, () => {
340
317
  const {
341
318
  TeX
@@ -343,7 +320,7 @@ const buttonSets = {
343
320
  return [/*#__PURE__*/React__namespace.createElement(TeX, {
344
321
  key: "pi",
345
322
  style: slightlyBig
346
- }, i18n__namespace.doNotTranslate("\\pi")), "\\pi"];
323
+ }, i18n__namespace.doNotTranslate("\\pi")), "PI"];
347
324
  }],
348
325
  logarithms: [() => {
349
326
  const {
@@ -351,27 +328,21 @@ const buttonSets = {
351
328
  } = getDependencies();
352
329
  return [/*#__PURE__*/React__namespace.createElement(TeX, {
353
330
  key: "log"
354
- }, i18n__namespace.doNotTranslate("\\log")), "\\log"];
331
+ }, i18n__namespace.doNotTranslate("\\log")), "LOG"];
355
332
  }, () => {
356
333
  const {
357
334
  TeX
358
335
  } = getDependencies();
359
336
  return [/*#__PURE__*/React__namespace.createElement(TeX, {
360
337
  key: "ln"
361
- }, i18n__namespace.doNotTranslate("\\ln")), "\\ln"];
338
+ }, i18n__namespace.doNotTranslate("\\ln")), "LN"];
362
339
  }, () => {
363
340
  const {
364
341
  TeX
365
342
  } = getDependencies();
366
343
  return [/*#__PURE__*/React__namespace.createElement(TeX, {
367
344
  key: "log_b"
368
- }, i18n__namespace.doNotTranslate("\\log_b")), input => {
369
- input.typedText("log_");
370
- input.keystroke("Right");
371
- input.typedText("(");
372
- input.keystroke("Left");
373
- input.keystroke("Left");
374
- }];
345
+ }, i18n__namespace.doNotTranslate("\\log_b")), "LOG_B"];
375
346
  }],
376
347
  "basic relations": [() => {
377
348
  const {
@@ -379,21 +350,21 @@ const buttonSets = {
379
350
  } = getDependencies();
380
351
  return [/*#__PURE__*/React__namespace.createElement(TeX, {
381
352
  key: "eq"
382
- }, "="), "="];
353
+ }, "="), "EQUAL"];
383
354
  }, () => {
384
355
  const {
385
356
  TeX
386
357
  } = getDependencies();
387
358
  return [/*#__PURE__*/React__namespace.createElement(TeX, {
388
359
  key: "lt"
389
- }, i18n__namespace.doNotTranslate("\\lt")), "\\lt"];
360
+ }, i18n__namespace.doNotTranslate("\\lt")), "LT"];
390
361
  }, () => {
391
362
  const {
392
363
  TeX
393
364
  } = getDependencies();
394
365
  return [/*#__PURE__*/React__namespace.createElement(TeX, {
395
366
  key: "gt"
396
- }, i18n__namespace.doNotTranslate("\\gt")), "\\gt"];
367
+ }, i18n__namespace.doNotTranslate("\\gt")), "GT"];
397
368
  }],
398
369
  "advanced relations": [() => {
399
370
  const {
@@ -401,21 +372,21 @@ const buttonSets = {
401
372
  } = getDependencies();
402
373
  return [/*#__PURE__*/React__namespace.createElement(TeX, {
403
374
  key: "neq"
404
- }, i18n__namespace.doNotTranslate("\\neq")), "\\neq"];
375
+ }, i18n__namespace.doNotTranslate("\\neq")), "NEQ"];
405
376
  }, () => {
406
377
  const {
407
378
  TeX
408
379
  } = getDependencies();
409
380
  return [/*#__PURE__*/React__namespace.createElement(TeX, {
410
381
  key: "leq"
411
- }, i18n__namespace.doNotTranslate("\\leq")), "\\leq"];
382
+ }, i18n__namespace.doNotTranslate("\\leq")), "LEQ"];
412
383
  }, () => {
413
384
  const {
414
385
  TeX
415
386
  } = getDependencies();
416
387
  return [/*#__PURE__*/React__namespace.createElement(TeX, {
417
388
  key: "geq"
418
- }, i18n__namespace.doNotTranslate("\\geq")), "\\geq"];
389
+ }, i18n__namespace.doNotTranslate("\\geq")), "GEQ"];
419
390
  }]
420
391
  };
421
392
  const buttonSetsPropType = PropTypes__default["default"].arrayOf(PropTypes__default["default"].oneOf(___default["default"](buttonSets).keys()));
@@ -454,6 +425,20 @@ class TexButtons extends React__namespace.Component {
454
425
  _defineProperty(TexButtons, "buttonSets", buttonSets);
455
426
  _defineProperty(TexButtons, "buttonSetsType", buttonSetsPropType);
456
427
 
428
+ const customKeyTranslator = {
429
+ ...mathInput.keyTranslator,
430
+ // If there's something in the input that can become part of a
431
+ // fraction, typing "/" puts it in the numerator. If not, typing
432
+ // "/" does nothing. In that case, enter a \frac.
433
+ FRAC: mathQuill => {
434
+ const contents = mathQuill.latex();
435
+ mathQuill.typedText("/");
436
+ if (mathQuill.latex() === contents) {
437
+ mathQuill.cmd("\\frac");
438
+ }
439
+ }
440
+ };
441
+
457
442
  // A WYSIWYG math input that calls `onChange(LaTeX-string)`
458
443
  class MathInput extends React__namespace.Component {
459
444
  constructor() {
@@ -515,6 +500,17 @@ class MathInput extends React__namespace.Component {
515
500
  _defineProperty(this, "insert", value => {
516
501
  // @ts-expect-error [FEI-5003] - TS2554 - Expected 1 arguments, but got 0.
517
502
  const input = this.mathField();
503
+ const inputModifier = customKeyTranslator[value];
504
+ if (inputModifier) {
505
+ inputModifier(input, value);
506
+ input.focus();
507
+ return;
508
+ }
509
+
510
+ // note(Matthew): I'm not sure this is still being used
511
+ // but it fails tests when I remove it and the way we call
512
+ // methods directly on components makes it difficult to confirm
513
+ // if it's dead code
518
514
  if (___default["default"](value).isFunction()) {
519
515
  value(input);
520
516
  } else if (value[0] === "\\") {
@@ -2650,11 +2646,6 @@ class Expression extends React__namespace.Component {
2650
2646
  // @ts-expect-error [FEI-5003] - TS2339 - Property 'blur' does not exist on type 'ReactInstance'.
2651
2647
  this.refs.input.blur();
2652
2648
  });
2653
- _defineProperty(this, "insert", text => {
2654
- // eslint-disable-next-line react/no-string-refs
2655
- // @ts-expect-error [FEI-5003] - TS2339 - Property 'insert' does not exist on type 'ReactInstance'.
2656
- this.refs.input.insert(text);
2657
- });
2658
2649
  _defineProperty(this, "getInputPaths", () => {
2659
2650
  // The widget itself is an input, so we return a single empty list to
2660
2651
  // indicate this.
@@ -2826,6 +2817,12 @@ class Expression extends React__namespace.Component {
2826
2817
  }
2827
2818
  //#endregion
2828
2819
 
2820
+ // HACK(joel)
2821
+ insert(keyPressed) {
2822
+ // eslint-disable-next-line react/no-string-refs
2823
+ // @ts-expect-error [FEI-5003] - TS2339 - Property 'insert' does not exist on type 'ReactInstance'.
2824
+ this.refs.input.insert(keyPressed);
2825
+ }
2829
2826
  render() {
2830
2827
  if (this.props.apiOptions.customKeypad) {
2831
2828
  return /*#__PURE__*/React__namespace.createElement(mathInput.KeypadInput
@@ -32527,7 +32524,7 @@ class Draggable extends React__namespace.Component {
32527
32524
  if (this.props.state === prevProps.state) {
32528
32525
  return;
32529
32526
  }
32530
- if (this.props.state === ItemState.ANIMATING) {
32527
+ if (this.props.state === ItemState.ANIMATING && this.props.endPosition) {
32531
32528
  // Start animating
32532
32529
  const current = this.getCurrentPosition();
32533
32530
  const duration = 15 * Math.sqrt(Math.sqrt(Math.pow(this.props.endPosition.left - current.left, 2) + Math.pow(this.props.endPosition.top - current.top, 2)));
@@ -32597,7 +32594,6 @@ class Sortable extends React__namespace.Component {
32597
32594
  option: option,
32598
32595
  key: i,
32599
32596
  state,
32600
- endPosition: {},
32601
32597
  width: 0,
32602
32598
  height: 0
32603
32599
  };