@khanacademy/math-input 16.5.1 → 17.0.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @khanacademy/math-input
2
2
 
3
+ ## 17.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - [#937](https://github.com/Khan/perseus/pull/937) [`ef898f77`](https://github.com/Khan/perseus/commit/ef898f77f45f3494f5012d2db52a3461aad93c69) Thanks [@nishasy](https://github.com/nishasy)! - Upgraded MathQuill API version + type updates
8
+
3
9
  ## 16.5.1
4
10
 
5
11
  ### Patch Changes
@@ -1,6 +1,5 @@
1
1
  import type { MathFieldInterface } from "./mathquill-types";
2
2
  import type Key from "../../data/keys";
3
- import type { Cursor } from "../../types";
4
3
  /**
5
4
  * This file contains a wrapper around MathQuill so that we can provide a
6
5
  * more regular interface for the functionality we need while insulating us
@@ -18,7 +17,9 @@ declare class MathWrapper {
18
17
  * @param {Key} key - an enum representing the key that was pressed
19
18
  * @returns {object} a cursor object, consisting of a cursor context
20
19
  */
21
- pressKey(key: Key): Cursor;
20
+ pressKey(key: Key): {
21
+ context: import("./cursor-contexts").CursorContext;
22
+ };
22
23
  /**
23
24
  * Place the cursor beside the node located at the given coordinates.
24
25
  *
@@ -1,6 +1,5 @@
1
1
  import { CursorContext } from "./cursor-contexts";
2
- import type { MathFieldCursor, MathFieldInterface } from "./mathquill-types";
3
- export declare function getCursor(mathField: MathFieldInterface): MathFieldCursor;
2
+ import type { MathFieldInterface } from "./mathquill-types";
4
3
  export declare function isFraction(node: any): boolean;
5
4
  export declare function isNumerator(node: any): boolean;
6
5
  export declare function isDenominator(node: any): boolean;
@@ -11,8 +10,8 @@ export declare function isLeaf(node: any): boolean;
11
10
  export declare function isSquareRoot(node: any): boolean;
12
11
  export declare function isNthRoot(node: any): boolean;
13
12
  export declare function isNthRootIndex(node: any): boolean;
14
- export declare function isInsideLogIndex(cursor: MathFieldCursor): boolean;
15
- export declare function isInsideEmptyNode(cursor: MathFieldCursor): boolean;
13
+ export declare function isInsideLogIndex(cursor: any): boolean;
14
+ export declare function isInsideEmptyNode(cursor: any): boolean;
16
15
  export declare function selectNode(node: any, cursor: any): void;
17
16
  /**
18
17
  * Return the start node, end node, and full name of the command of which
@@ -1,4 +1,4 @@
1
- import type { MathQuillInterface, MathFieldConfig } from "./mathquill-types";
1
+ import type { MathQuillInterface, MathFieldConfig, MathFieldInterface } from "./mathquill-types";
2
2
  export declare const mathQuillInstance: MathQuillInterface;
3
3
  /**
4
4
  * Creates a new [MathField](http://docs.mathquill.com/en/latest/Api_Methods/#mqmathfieldhtml_element-config)
@@ -11,4 +11,4 @@ export declare const mathQuillInstance: MathQuillInterface;
11
11
  * This allows callers to do minimal configuration as only configs
12
12
  * that vary from the default need to be provided.
13
13
  */
14
- export declare function createMathField(container: HTMLDivElement | HTMLSpanElement, configCallback?: (baseConfig: MathFieldConfig) => MathFieldConfig): import("./mathquill-types").MathFieldInterface;
14
+ export declare function createMathField(container: HTMLDivElement | HTMLSpanElement, configCallback?: (baseConfig: MathFieldConfig) => MathFieldConfig): MathFieldInterface;
@@ -1,298 +1,13 @@
1
1
  import type Key from "../../data/keys";
2
- export interface MathQuillInterface {
3
- L: -1;
4
- R: 1;
5
- /**
6
- * Creates an editable MathQuill initialized with the contents of the HTML
7
- * element and returns a MathField object.
8
- *
9
- * If the given element is already an editable math field, this will return
10
- * a new editable MathField object with the same `.id`. If the element is a
11
- * different type of MathQuill, this will return `null`.
12
- */
13
- MathField: (mount: HTMLDivElement | HTMLSpanElement, config: MathFieldConfig) => MathFieldInterface;
14
- }
15
- type MathQuillDirection = MathQuillInterface["L"] | MathQuillInterface["R"];
16
- export type MathFieldConfig = {
17
- /**
18
- * If spaceBehavesLikeTab is true the keystrokes {Shift-,}Spacebar will
19
- * behave like {Shift-,}Tab escaping from the current block (as opposed
20
- * to the default behavior of inserting a Space character).
21
- */
22
- spaceBehavesLikeTab?: boolean;
23
- /**
24
- * This allows you to change the way the left and right keys move the
25
- * cursor when there are items of different height, like fractions.
26
- *
27
- * By default, the Left and Right keys move the cursor through all
28
- * possible cursor positions in a particular order: right into a
29
- * fraction puts the cursor at the left end of the numerator, right out
30
- * of the numerator puts the cursor at the left end of the denominator,
31
- * and right out of the denominator puts the cursor to the right of the
32
- * fraction. Symmetrically, left into a fraction puts the cursor at the
33
- * right end of the denominator, etc.
34
- *
35
- * If instead you want right to always visually go right, and left to always go
36
- * visually left, you can set leftRightIntoCmdGoes to 'up' or 'down' so that
37
- * left and right go up or down (respectively) into commands. For example, 'up'
38
- * means that left into a fraction goes up into the numerator and right out of
39
- * the numerator skips the denominator and puts the cursor to the right of the
40
- * fraction. This behavior can be seen in the Desmos calculator. If this
41
- * property is set to 'down' instead, the numerator is harder to navigate to,
42
- * like in the Mac OS X built-in app Grapher.
43
- */
44
- leftRightIntoCmdGoes?: "up" | "down";
45
- /**
46
- * If restrictMismatchedBrackets is true then you can type [a,b) and
47
- * (a,b], but if you try typing [x} or \langle x|, you'll get [{x}] or
48
- * \langle|x|\rangle instead. This lets you type (|x|+1) normally;
49
- * otherwise, you'd get \left( \right| x \left| + 1 \right).
50
- */
51
- restrictMismatchedBrackets?: boolean;
52
- /**
53
- * If sumStartsWithNEquals is true then when you type \sum, \prod, or
54
- * \coprod, the lower limit starts out with n=, e.g. you get the LaTeX
55
- * \sum_{n=}^{ }, rather than empty by default.
56
- */
57
- sumStartsWithNEquals?: boolean;
58
- /**
59
- * supSubsRequireOperand disables typing of superscripts and subscripts
60
- * when there's nothing to the left of the cursor to be exponentiated
61
- * or subscripted. Prevents the especially confusing typo x^^2, which
62
- * looks much like x^2.
63
- */
64
- supSubsRequireOperand?: boolean;
65
- /**
66
- * charsThatBreakOutOfSupSub takes a string of the chars that when
67
- * typed, "break out" of superscripts and subscripts.
68
- *
69
- * Normally, to get out of a superscript or subscript, a user has to
70
- * navigate out of it with the directional keys, a mouse click, tab, or
71
- * Space if spaceBehavesLikeTab is true. For example, typing x^2n+y
72
- * normally results in the LaTeX x^{2n+y}. If you wanted to get the
73
- * LaTeX x^{2n}+y, the user would have to manually move the cursor out
74
- * of the exponent.
75
- *
76
- * If this option was set to '+-', + and - would "break out" of the
77
- * exponent. This doesn't apply to the first character in a superscript
78
- * or subscript, so typing x^-6 still results in x^{-6}. The downside
79
- * to setting this option is that in order to type x^{n+m}, a
80
- * workaround like typing x^(n+m and then deleting the ( is required.
81
- */
82
- charsThatBreakOutOfSupSub?: string;
83
- /**
84
- * :shrug: Undocumented except for being shown in an example for
85
- * configuration options.
86
- */
87
- autoSubscriptNumerals?: boolean;
88
- /**
89
- * autoCommands defines the set of commands automatically rendered by
90
- * just typing the letters without typing a backslash first.
91
- *
92
- * This takes a string formatted as a space-delimited list of LaTeX
93
- * commands. Each LaTeX command must be at least letters only with a
94
- * minimum length of 2 characters.
95
- *
96
- * For example, with autoCommands set to 'pi theta', the word 'pi'
97
- * automatically converts to the pi symbol and the word 'theta'
98
- * automatically converts to the theta symbol.
99
- */
100
- autoCommands?: string;
101
- /**
102
- * autoOperatorNames overrides the set of operator names that
103
- * automatically become non-italicized when typing the letters without
104
- * typing a backslash first, like sin, log, etc.
105
- *
106
- * This defaults to the LaTeX built-in operator names (Section 3.17 of
107
- * the Short Math Guide) with additional trig operators like sech,
108
- * arcsec, arsinh, etc. If you want some of these italicized after
109
- * setting this property, you will have to add them to the list.
110
- *
111
- * Just like autoCommands above, this takes a string formatted as a
112
- * space-delimited list of LaTeX commands.
113
- */
114
- autoOperatorNames?: string;
115
- /**
116
- * maxDepth specifies the maximum number of nested MathBlocks. When
117
- * maxDepth is set to 1, the user can type simple math symbols directly
118
- * into the editor but not into nested MathBlocks, e.g. the numerator
119
- * and denominator of a fraction.
120
- *
121
- * Nested content in latex rendered during initialization or pasted
122
- * into mathquill is truncated to avoid violating maxDepth. When
123
- * maxDepth is not set, no depth limit is applied by default.
124
- */
125
- maxDepth?: number;
126
- /**
127
- * substituteTextarea is a function that creates a focusable DOM
128
- * element that is called when setting up a math field. Overwriting
129
- * this may be useful for hacks like suppressing built-in virtual
130
- * keyboards. It defaults to <textarea autocorrect=off .../>.
131
- *
132
- * For example, Desmos substitutes <span tabindex=0></span> on iOS to
133
- * suppress the built-in virtual keyboard in favor of a custom math
134
- * keypad that calls the MathQuill API. Unfortunately there's no
135
- * universal check for a virtual keyboard or way to detect a
136
- * touchscreen, and even if you could, a touchscreen ≠ virtual keyboard
137
- * (Windows 8 and ChromeOS devices have both physical keyboards and
138
- * touchscreens and iOS and Android devices can have Bluetooth
139
- * keyboards). Desmos currently sniffs the user agent for iOS, so
140
- * Bluetooth keyboards just don't work in Desmos on iOS. The tradeoffs
141
- * are up to you.
142
- */
143
- substituteTextarea?: () => HTMLElement | undefined;
144
- /**
145
- * Handlers are called after a specified event. They are called
146
- * directly on the handlers object passed in, preserving the this value
147
- */
148
- handlers?: {
149
- edit?: (mathField: MathFieldInterface) => void;
150
- enter?: (mathField: MathFieldInterface) => void;
151
- moveOutOf?: (direction: MathQuillDirection, mathField: MathFieldInterface) => void;
152
- upOutOf?: (mathField: MathFieldInterface) => void;
153
- downOutOf?: (mathField: MathFieldInterface) => void;
154
- deleteOutOf?: (direction: MathQuillDirection, mathField: MathFieldInterface) => void;
155
- selectOutOf?: (direction: MathQuillDirection, mathField: MathFieldInterface) => void;
156
- };
157
- };
2
+ import type MathQuill from "mathquill";
3
+ export type MathQuillInterface = MathQuill.v3.API;
4
+ export type MathFieldConfig = MathQuill.v3.Config;
158
5
  /**
159
6
  * Editable math fields have all of the above methods in addition to
160
7
  * the ones listed here.
161
8
  * https://docs.mathquill.com/en/latest/Api_Methods/
162
9
  */
163
- export interface MathFieldInterface {
164
- /**
165
- * Any element that has been turned into a MathQuill instance can be
166
- * reverted.
167
- */
168
- revert: () => void;
169
- /**
170
- * MathQuill uses computed dimensions, so if they change (because an
171
- * element was mathquill-ified before it was in the visible HTML DOM, or
172
- * the font size changed), then you'll need to tell MathQuill to recomput
173
- */
174
- reflow: () => void;
175
- /** Returns the root HTML element. */
176
- el: () => HTMLElement;
177
- /**
178
- * Puts the focus on the editable field.
179
- * http://docs.mathquill.com/en/latest/Api_Methods/#focus
180
- */
181
- focus: () => MathFieldInterface;
182
- /**
183
- * Removes focus from the editable field.
184
- * http://docs.mathquill.com/en/latest/Api_Methods/#blur
185
- */
186
- blur: () => MathFieldInterface;
187
- /**
188
- * Write the given LaTeX at the current cursor position. If the
189
- * cursor does not have focus, writes to last position the cursor
190
- * occupied in the editable field.
191
- *
192
- * ```
193
- * // writes ' - 1' to mathField at the cursor position
194
- * mathField.write(' - 1');
195
- * ```
196
- *
197
- * https://docs.mathquill.com/en/latest/Api_Methods/#writelatex_string
198
- */
199
- write: (latex_string: string) => MathFieldInterface;
200
- /**
201
- * Enter a LaTeX command at the current cursor position or with the
202
- * current selection. If the cursor does not have focus, it writes it
203
- * to last position the cursor occupied in the editable field.
204
- *
205
- * ```
206
- * // writes a square root command at the cursor position
207
- * mathField.cmd('\\sqrt');
208
- * ```
209
- *
210
- * https://docs.mathquill.com/en/latest/Api_Methods/#cmdlatex_string
211
- */
212
- cmd: (latex_string: string) => MathFieldInterface;
213
- /**
214
- * Selects the contents (just like on textareas and on inputs).
215
- *
216
- * https://docs.mathquill.com/en/latest/Api_Methods/#select
217
- */
218
- select: () => void;
219
- /**
220
- * Clears the selection.
221
- *
222
- * https://docs.mathquill.com/en/latest/Api_Methods/#clearselection
223
- */
224
- clearSelection: () => void;
225
- /**
226
- * Move the cursor to the left end of the editable field. horthand
227
- * for .moveToDirEnd(L)
228
- */
229
- moveToLeftEnd: () => void;
230
- /**
231
- * Move the cursor to the right end of the editable field. horthand
232
- * for .moveToDirEnd(R)
233
- */
234
- moveToRightEnd: () => void;
235
- /**
236
- * Moves the cursor to the end of the mathfield in the direction
237
- * specified. The direction can be one of MQ.L or MQ.R. These are
238
- * constants, where MQ.L === -MQ.R and vice versa. This function
239
- * may be easier to use than moveToLeftEnd or moveToRightEnd if
240
- * used in the moveOutOf handler.
241
- *
242
- * https://docs.mathquill.com/en/latest/Api_Methods/#movetodirenddirection
243
- */
244
- moveToDirEnd: (direction: MathQuillDirection) => void;
245
- /**
246
- * Simulates keystrokes given a string like "Ctrl-Home Del", a
247
- * whitespace-delimited list of key inputs with optional prefixes.
248
- *
249
- * ```
250
- * mathField.keystroke('Shift-Left'); // Selects character before the current cursor position
251
- * ```
252
- *
253
- * https://docs.mathquill.com/en/latest/Api_Methods/#keystrokekeys
254
- */
255
- keystroke: (keys: string) => MathFieldInterface;
256
- /**
257
- * Simulates typing text, one character at a time from where the
258
- * cursor currently is. This is supposed to be identical to what
259
- * would happen if a user were typing the text in.
260
- *
261
- * Types part of the demo from mathquill.com without delays between keystrokes
262
- * ```
263
- * mathField.typedText('x=-b\\pm \\sqrt b^2 -4ac');
264
- * ```
265
- *
266
- * https://docs.mathquill.com/en/latest/Api_Methods/#typedtexttext
267
- */
268
- typedText: (text: string) => MathFieldInterface;
269
- /**
270
- * When called withot any pramaters, gets the contents as LaTeX
271
- * When passed a string, sets the contents as LaTeX
272
- *
273
- * https://docs.mathquill.com/en/latest/Api_Methods/#latex
274
- */
275
- latex: (input?: string) => string;
276
- /** Changes the configuration of just this math field. */
277
- config: (new_config: MathFieldConfig) => void;
278
- /**
279
- * KA Custom helper in our MathQuill fork check to see if cursor is on
280
- * right end
281
- */
282
- cursorAtRightEnd: () => boolean;
283
- /**
284
- * KA Custom helper in our MathQuill fork check to see if cursor is on left
285
- * end
286
- */
287
- cursorAtLeftEnd: () => boolean;
288
- /**
289
- * This isn't part of the MathQuill public API
290
- * I don't know what it is and it feels wrong using it
291
- *
292
- * @deprecated This is internal and shouldn't be used.
293
- */
294
- __controller: any;
295
- }
10
+ export type MathFieldInterface = MathQuill.v3.EditableMathQuill;
296
11
  export declare enum MathFieldActionType {
297
12
  WRITE = "write",
298
13
  CMD = "cmd",
@@ -306,4 +21,3 @@ export declare enum MathFieldActionType {
306
21
  */
307
22
  export type MathFieldCursor = any;
308
23
  export type MathFieldUpdaterCallback = (mathField: MathFieldInterface, key: Key) => void;
309
- export {};