@khanacademy/math-input 22.3.0 → 23.0.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.
@@ -1,6 +1,6 @@
1
1
  import type { MathFieldInterface, MathFieldUpdaterCallback } from "./mathquill-types";
2
- import type Key from "../../data/keys";
3
2
  import type { MathInputStrings } from "../../strings";
3
+ import type { KeypadKey } from "@khanacademy/perseus-core";
4
4
  /**
5
5
  * This file contains a wrapper around MathQuill so that we can provide a
6
6
  * more regular interface for the functionality we need while insulating us
@@ -9,7 +9,7 @@ import type { MathInputStrings } from "../../strings";
9
9
  declare class MathWrapper {
10
10
  mathField: MathFieldInterface;
11
11
  callbacks: any;
12
- mobileKeyTranslator: Record<Key, MathFieldUpdaterCallback>;
12
+ mobileKeyTranslator: Record<KeypadKey, MathFieldUpdaterCallback>;
13
13
  constructor(mathFieldMount: any, ariaLabel: string, strings: MathInputStrings, locale: string, callbacks?: {});
14
14
  focus(): void;
15
15
  blur(): void;
@@ -19,7 +19,7 @@ declare class MathWrapper {
19
19
  * @param {Key} key - an enum representing the key that was pressed
20
20
  * @returns {object} a cursor object, consisting of a cursor context
21
21
  */
22
- pressKey(key: Key): {
22
+ pressKey(key: KeypadKey): {
23
23
  context: import("./cursor-contexts").CursorContext;
24
24
  };
25
25
  /**
@@ -1,4 +1,4 @@
1
- import type Key from "../../data/keys";
1
+ import type { KeypadKey } from "@khanacademy/perseus-core";
2
2
  import type MathQuill from "mathquill";
3
3
  export type MathQuillInterface = MathQuill.v3.API;
4
4
  export type MathFieldConfig = MathQuill.v3.Config;
@@ -11,7 +11,7 @@ export type MathFieldInterface = MathQuill.v3.EditableMathQuill & {
11
11
  cursor: () => MathQuill.Cursor;
12
12
  controller: () => MathQuill.Controller;
13
13
  };
14
- export type MathFieldUpdaterCallback = (mathField: MathFieldInterface, key: Key) => void;
14
+ export type MathFieldUpdaterCallback = (mathField: MathFieldInterface, key: KeypadKey) => void;
15
15
  /**
16
16
  * The MathQuill API (see mathuill.d.ts) does not include types
17
17
  * for cursor() and controller(), and adding these types there
@@ -1,3 +1,3 @@
1
- import type Key from "../../data/keys";
2
1
  import type { MathFieldInterface } from "../input/mathquill-types";
3
- export default function handleArrow(mathField: MathFieldInterface, key: Key): void;
2
+ import type { KeypadKey } from "@khanacademy/perseus-core";
3
+ export default function handleArrow(mathField: MathFieldInterface, key: KeypadKey): void;
@@ -1,3 +1,3 @@
1
- import type Key from "../../data/keys";
2
1
  import type { MathFieldInterface } from "../input/mathquill-types";
3
- export default function handleExponent(mathField: MathFieldInterface, key: Key): void;
2
+ import type { KeypadKey } from "@khanacademy/perseus-core";
3
+ export default function handleExponent(mathField: MathFieldInterface, key: KeypadKey): void;
@@ -1,7 +1,7 @@
1
- import type Key from "../../data/keys";
2
1
  import type { MathFieldInterface } from "../input/mathquill-types";
2
+ import type { KeypadKey } from "@khanacademy/perseus-core";
3
3
  /**
4
4
  * Advances the cursor to the next logical position.
5
5
  */
6
- declare function handleJumpOut(mathField: MathFieldInterface, key: Key): void;
6
+ declare function handleJumpOut(mathField: MathFieldInterface, key: KeypadKey): void;
7
7
  export default handleJumpOut;
@@ -1,9 +1,9 @@
1
- import type Key from "../../data/keys";
2
1
  import type { MathFieldUpdaterCallback } from "../input/mathquill-types";
2
+ import type { KeypadKey } from "@khanacademy/perseus-core";
3
3
  type KeyTranslatorStrings = {
4
4
  sin: string;
5
5
  cos: string;
6
6
  tan: string;
7
7
  };
8
- export declare const getKeyTranslator: (locale: string, strings: KeyTranslatorStrings) => Record<Key, MathFieldUpdaterCallback>;
8
+ export declare const getKeyTranslator: (locale: string, strings: KeyTranslatorStrings) => Record<KeypadKey, MathFieldUpdaterCallback>;
9
9
  export {};
@@ -1,7 +1,7 @@
1
1
  import * as React from "react";
2
- import type Key from "../../data/keys";
2
+ import type { KeypadKey } from "@khanacademy/perseus-core";
3
3
  type Props = {
4
- id: Key;
4
+ id: KeypadKey;
5
5
  };
6
6
  export default function ButtonAsset({ id }: Props): React.ReactNode;
7
7
  export {};
@@ -1,8 +1,8 @@
1
1
  import * as React from "react";
2
- import type Key from "../../../data/keys";
3
2
  import type { ClickKeyCallback } from "../../../types";
3
+ import type { KeypadKey } from "@khanacademy/perseus-core";
4
4
  type Props = {
5
- extraKeys: ReadonlyArray<Key>;
5
+ extraKeys: ReadonlyArray<KeypadKey>;
6
6
  onClickKey: ClickKeyCallback;
7
7
  };
8
8
  export default function ExtrasPage(props: Props): React.JSX.Element;
@@ -1,10 +1,9 @@
1
1
  import * as React from "react";
2
- import type Key from "../../data/keys";
3
2
  import type { ClickKeyCallback } from "../../types";
4
3
  import type { CursorContext } from "../input/cursor-contexts";
5
- import type { AnalyticsEventHandlerFn } from "@khanacademy/perseus-core";
4
+ import type { AnalyticsEventHandlerFn, KeypadKey } from "@khanacademy/perseus-core";
6
5
  type Props = {
7
- extraKeys?: ReadonlyArray<Key>;
6
+ extraKeys?: ReadonlyArray<KeypadKey>;
8
7
  cursorContext?: (typeof CursorContext)[keyof typeof CursorContext];
9
8
  showDismiss?: boolean;
10
9
  expandedView?: boolean;
@@ -1,8 +1,7 @@
1
1
  import * as React from "react";
2
2
  import ReactDOM from "react-dom";
3
- import type Key from "../../data/keys";
4
- import type { Cursor, KeypadConfiguration, KeyHandler, KeypadAPI } from "../../types";
5
- import type { AnalyticsEventHandlerFn } from "@khanacademy/perseus-core";
3
+ import type { Cursor, KeyHandler, KeypadAPI } from "../../types";
4
+ import type { AnalyticsEventHandlerFn, KeypadConfiguration, KeypadKey } from "@khanacademy/perseus-core";
6
5
  import type { StyleType } from "@khanacademy/wonder-blocks-core";
7
6
  type Props = {
8
7
  onElementMounted?: (arg1: any) => void;
@@ -43,7 +42,7 @@ declare class MobileKeypadInternals extends React.Component<Props, State> implem
43
42
  setCursor: (cursor: Cursor) => void;
44
43
  setKeyHandler: (keyHandler: KeyHandler) => void;
45
44
  getDOMNode: () => ReturnType<typeof ReactDOM.findDOMNode>;
46
- _handleClickKey(key: Key): void;
45
+ _handleClickKey(key: KeypadKey): void;
47
46
  render(): React.ReactNode;
48
47
  }
49
48
  export default MobileKeypadInternals;
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * This file contains configuration settings for the buttons in the keypad.
3
3
  */
4
- import type Key from "./keys";
5
4
  import type { MathInputStrings } from "../strings";
6
5
  import type { KeyConfig } from "../types";
7
- declare const KeyConfigs: (strings: MathInputStrings) => { [key in Key]: KeyConfig; };
6
+ import type { KeypadKey } from "@khanacademy/perseus-core";
7
+ declare const KeyConfigs: (strings: MathInputStrings) => { [key in KeypadKey]: KeyConfig; };
8
8
  export default KeyConfigs;
@@ -1,3 +0,0 @@
1
- export declare const KeyArray: readonly ["PLUS", "MINUS", "NEGATIVE", "TIMES", "DIVIDE", "DECIMAL", "PERIOD", "PERCENT", "CDOT", "EQUAL", "NEQ", "GT", "LT", "GEQ", "LEQ", "FRAC_INCLUSIVE", "FRAC_EXCLUSIVE", "FRAC", "EXP", "EXP_2", "EXP_3", "SQRT", "CUBE_ROOT", "RADICAL", "LEFT_PAREN", "RIGHT_PAREN", "LN", "LOG", "LOG_N", "SIN", "COS", "TAN", "PI", "THETA", "UP", "RIGHT", "DOWN", "LEFT", "BACKSPACE", "DISMISS", "JUMP_OUT_PARENTHESES", "JUMP_OUT_EXPONENT", "JUMP_OUT_BASE", "JUMP_INTO_NUMERATOR", "JUMP_OUT_NUMERATOR", "JUMP_OUT_DENOMINATOR", "NUM_0", "NUM_1", "NUM_2", "NUM_3", "NUM_4", "NUM_5", "NUM_6", "NUM_7", "NUM_8", "NUM_9", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"];
2
- type Key = (typeof KeyArray)[number];
3
- export default Key;
package/dist/enums.d.ts CHANGED
@@ -1,10 +1,6 @@
1
1
  /**
2
2
  * Constants that are shared between multiple files.
3
3
  */
4
- export declare enum KeypadType {
5
- FRACTION = "FRACTION",
6
- EXPRESSION = "EXPRESSION"
7
- }
8
4
  declare const KeyTypes: string[];
9
5
  export type KeyType = (typeof KeyTypes)[number];
10
6
  export {};
package/dist/es/index.js CHANGED
@@ -60,7 +60,7 @@ const addLibraryVersionToPerseusDebug = (libraryName, libraryVersion) => {
60
60
 
61
61
  // This file is processed by a Rollup plugin (replace) to inject the production
62
62
  const libName = "@khanacademy/math-input";
63
- const libVersion = "22.3.0";
63
+ const libVersion = "23.0.1";
64
64
  addLibraryVersionToPerseusDebug(libName, libVersion);
65
65
 
66
66
  class View extends React.Component {
@@ -822,37 +822,6 @@ function handleBackspaceInLogIndex(mathField, cursor) {
822
822
  mathField.keystroke("Backspace");
823
823
  }
824
824
  }
825
- function handleBackspaceOutsideParens(cursor) {
826
- // In this case the node with '\\left(' for its ctrlSeq
827
- // is the parent of the expression contained within the
828
- // parentheses.
829
- //
830
- // Handle selecting an expression before deleting:
831
- // (x+1)| => |(x+1)|
832
- // \log(x+1)| => |\log(x+1)|
833
-
834
- const leftNode = cursor[mathQuillInstance.L];
835
- const rightNode = cursor[mathQuillInstance.R];
836
- const command = maybeFindCommandBeforeParens(leftNode);
837
- if (command && command.startNode) {
838
- // There's a command before the parens so we select it as well as
839
- // the parens.
840
- cursor.insLeftOf(command.startNode);
841
- cursor.startSelection();
842
- if (rightNode === MathFieldActionType.MQ_END) {
843
- cursor.insAtRightEnd(cursor.parent);
844
- } else {
845
- cursor.insLeftOf(rightNode);
846
- }
847
- cursor.select();
848
- cursor.endSelection();
849
- } else {
850
- cursor.startSelection();
851
- cursor.insLeftOf(leftNode); // left of \\left(
852
- cursor.select();
853
- cursor.endSelection();
854
- }
855
- }
856
825
  function handleBackspaceInsideParens(mathField, cursor) {
857
826
  // Handle situations when the cursor is inside parens or a
858
827
  // command that uses parens, e.g. \log() or \tan()
@@ -943,8 +912,6 @@ function handleBackspace(mathField) {
943
912
  selectNode(leftNode, cursor);
944
913
  } else if (isNthRootIndex(parent)) {
945
914
  handleBackspaceInRootIndex(mathField, cursor);
946
- } else if (leftNode.ctrlSeq === "\\left(") {
947
- handleBackspaceOutsideParens(cursor);
948
915
  } else if (grandparent.ctrlSeq === "\\left(") {
949
916
  handleBackspaceInsideParens(mathField, cursor);
950
917
  } else if (isInsideLogIndex(cursor)) {
@@ -5732,27 +5699,5 @@ const keypadElementPropType = PropTypes.shape({
5732
5699
  getDOMNode: PropTypes.func.isRequired
5733
5700
  });
5734
5701
 
5735
- const KeyArray = ["PLUS", "MINUS", "NEGATIVE", "TIMES", "DIVIDE", "DECIMAL", "PERIOD", "PERCENT", "CDOT", "EQUAL", "NEQ", "GT", "LT", "GEQ", "LEQ",
5736
- // mobile native only
5737
- "FRAC_INCLUSIVE",
5738
- // mobile native only
5739
- "FRAC_EXCLUSIVE",
5740
- // mobile native only
5741
- "FRAC", "EXP", "EXP_2", "EXP_3", "SQRT", "CUBE_ROOT", "RADICAL", "LEFT_PAREN", "RIGHT_PAREN", "LN", "LOG", "LOG_N", "SIN", "COS",
5742
- // TODO(charlie): Add in additional Greek letters.,
5743
- "TAN", "PI", "THETA", "UP", "RIGHT", "DOWN", "LEFT", "BACKSPACE", "DISMISS", "JUMP_OUT_PARENTHESES", "JUMP_OUT_EXPONENT", "JUMP_OUT_BASE", "JUMP_INTO_NUMERATOR", "JUMP_OUT_NUMERATOR", "JUMP_OUT_DENOMINATOR",
5744
- // Multi-functional keys.
5745
- "NUM_0", "NUM_1", "NUM_2", "NUM_3", "NUM_4", "NUM_5", "NUM_6", "NUM_7", "NUM_8", "NUM_9", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"];
5746
-
5747
- /**
5748
- * Constants that are shared between multiple files.
5749
- */
5750
-
5751
- let KeypadType = /*#__PURE__*/function (KeypadType) {
5752
- KeypadType["FRACTION"] = "FRACTION";
5753
- KeypadType["EXPRESSION"] = "EXPRESSION";
5754
- return KeypadType;
5755
- }({});
5756
-
5757
- export { CursorContext, Keypad as DesktopKeypad, KeyArray, KeyConfigs, MathInput as KeypadInput, KeypadType, MathInputI18nContext, MathInputI18nContextProvider, MobileKeypad, convertDotToTimesByLocale, createMathField, getCursorContext, getKeyTranslator, keypadElementPropType, libVersion, mathQuillInstance, useMathInputI18n };
5702
+ export { CursorContext, Keypad as DesktopKeypad, KeyConfigs, MathInput as KeypadInput, MathInputI18nContext, MathInputI18nContextProvider, MobileKeypad, convertDotToTimesByLocale, createMathField, getCursorContext, getKeyTranslator, keypadElementPropType, libVersion, mathQuillInstance, useMathInputI18n };
5758
5703
  //# sourceMappingURL=index.js.map