@khanacademy/math-input 26.2.7 → 26.2.8
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/es/index.js +5 -5
- package/dist/es/index.js.map +1 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/package.json +9 -9
package/dist/es/index.js
CHANGED
|
@@ -2,19 +2,19 @@ import { addLibraryVersionToPerseusDebug } from '@khanacademy/perseus-utils';
|
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import React__default, { useContext, useRef, useEffect, useState } from 'react';
|
|
4
4
|
import { KeypadContext } from '@khanacademy/keypad-context';
|
|
5
|
-
import { color } from '@khanacademy/wonder-blocks-tokens';
|
|
5
|
+
import { color, semanticColor } from '@khanacademy/wonder-blocks-tokens';
|
|
6
6
|
import { entries } from '@khanacademy/wonder-stuff-core';
|
|
7
7
|
import { StyleSheet, css } from 'aphrodite';
|
|
8
8
|
import ReactDOM from 'react-dom';
|
|
9
9
|
import { SpeechRuleEngine } from '@khanacademy/mathjax-renderer';
|
|
10
|
-
import { getDecimalSeparator } from '@khanacademy/perseus-core';
|
|
10
|
+
import { getDivideSymbolForTex, getDecimalSeparator } from '@khanacademy/perseus-core';
|
|
11
11
|
import { View as View$1 } from '@khanacademy/wonder-blocks-core';
|
|
12
12
|
import Clickable from '@khanacademy/wonder-blocks-clickable';
|
|
13
13
|
import { TransitionGroup } from 'react-transition-group';
|
|
14
14
|
import { withActionScheduler } from '@khanacademy/wonder-blocks-timing';
|
|
15
15
|
import PropTypes from 'prop-types';
|
|
16
16
|
|
|
17
|
-
const libName="@khanacademy/math-input";const libVersion="26.2.
|
|
17
|
+
const libName="@khanacademy/math-input";const libVersion="26.2.8";addLibraryVersionToPerseusDebug(libName,libVersion);
|
|
18
18
|
|
|
19
19
|
function getDefaultExportFromCjs (x) {
|
|
20
20
|
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
@@ -1425,7 +1425,7 @@ const ArithmeticOperators=["+","-","\\cdot","\\times","\\div"];const EqualityOpe
|
|
|
1425
1425
|
|
|
1426
1426
|
const KeysForJumpContext={[CursorContext.IN_PARENS]:"JUMP_OUT_PARENTHESES",[CursorContext.IN_SUPER_SCRIPT]:"JUMP_OUT_EXPONENT",[CursorContext.IN_SUB_SCRIPT]:"JUMP_OUT_BASE",[CursorContext.BEFORE_FRACTION]:"JUMP_INTO_NUMERATOR",[CursorContext.IN_NUMERATOR]:"JUMP_OUT_NUMERATOR",[CursorContext.IN_DENOMINATOR]:"JUMP_OUT_DENOMINATOR"};function handleJumpOut(mathField,key){const cursor=mathField.cursor();const context=getCursorContext(mathField);if(KeysForJumpContext[context]!==key){return}switch(context){case CursorContext.IN_PARENS:cursor.insRightOf(cursor.parent.parent);mathField.keystroke("Right");break;case CursorContext.BEFORE_FRACTION:let fractionNode;let visitor=cursor;while(visitor[mathQuillInstance.R]!==MathFieldActionType.MQ_END){if(isFraction(visitor[mathQuillInstance.R])){fractionNode=visitor[mathQuillInstance.R];}visitor=visitor[mathQuillInstance.R];}cursor.insLeftOf(fractionNode);mathField.keystroke("Right");break;case CursorContext.IN_NUMERATOR:const siblingDenominator=cursor.parent.parent.blocks[1];while(cursor.parent!==siblingDenominator){mathField.keystroke("Right");}break;case CursorContext.IN_DENOMINATOR:cursor.insRightOf(cursor.parent.parent);break;case CursorContext.IN_SUB_SCRIPT:cursor.insRightOf(cursor.parent.parent);if(isParens(cursor[mathQuillInstance.R])){mathField.keystroke("Right");}break;case CursorContext.IN_SUPER_SCRIPT:cursor.insRightOf(cursor.parent.parent);break;default:throw new Error(`Attempted to 'Jump Out' from node, but found no `+`appropriate cursor context: ${context}`)}}
|
|
1427
1427
|
|
|
1428
|
-
function buildGenericCallback(str,type=MathFieldActionType.WRITE){return function(mathQuill){switch(type){case MathFieldActionType.WRITE:{mathQuill.write(str);return}case MathFieldActionType.CMD:{mathQuill.cmd(str);return}case MathFieldActionType.KEYSTROKE:{mathQuill.keystroke(str);return}}}}function buildTranslatableFunctionCallback(command,supportedTranslations,defaultCommand){const cmd=supportedTranslations.includes(command)?command:defaultCommand;return function(mathField){mathField.write(`${cmd}\\left(\\right)`);mathField.keystroke("Left");}}function buildNormalFunctionCallback(command){return function(mathField){mathField.write(`\\${command}\\left(\\right)`);mathField.keystroke("Left");}}const getKeyTranslator=(locale,strings)=>({EXP:handleExponent,EXP_2:handleExponent,EXP_3:handleExponent,JUMP_OUT_PARENTHESES:handleJumpOut,JUMP_OUT_EXPONENT:handleJumpOut,JUMP_OUT_BASE:handleJumpOut,JUMP_INTO_NUMERATOR:handleJumpOut,JUMP_OUT_NUMERATOR:handleJumpOut,JUMP_OUT_DENOMINATOR:handleJumpOut,LEFT:handleArrow,RIGHT:handleArrow,LOG:buildNormalFunctionCallback("log"),LN:buildNormalFunctionCallback("ln"),COS:buildNormalFunctionCallback(strings.cos),SIN:buildTranslatableFunctionCallback(strings.sin,["sin","sen"],"sin"),TAN:buildTranslatableFunctionCallback(strings.tan,["tan","tg"],"tan"),CDOT:buildGenericCallback("\\cdot"),DECIMAL:buildGenericCallback(getDecimalSeparator(locale)),DIVIDE:buildGenericCallback(
|
|
1428
|
+
function buildGenericCallback(str,type=MathFieldActionType.WRITE){return function(mathQuill){switch(type){case MathFieldActionType.WRITE:{mathQuill.write(str);return}case MathFieldActionType.CMD:{mathQuill.cmd(str);return}case MathFieldActionType.KEYSTROKE:{mathQuill.keystroke(str);return}}}}function buildTranslatableFunctionCallback(command,supportedTranslations,defaultCommand){const cmd=supportedTranslations.includes(command)?command:defaultCommand;return function(mathField){mathField.write(`${cmd}\\left(\\right)`);mathField.keystroke("Left");}}function buildNormalFunctionCallback(command){return function(mathField){mathField.write(`\\${command}\\left(\\right)`);mathField.keystroke("Left");}}const getKeyTranslator=(locale,strings)=>({EXP:handleExponent,EXP_2:handleExponent,EXP_3:handleExponent,JUMP_OUT_PARENTHESES:handleJumpOut,JUMP_OUT_EXPONENT:handleJumpOut,JUMP_OUT_BASE:handleJumpOut,JUMP_INTO_NUMERATOR:handleJumpOut,JUMP_OUT_NUMERATOR:handleJumpOut,JUMP_OUT_DENOMINATOR:handleJumpOut,LEFT:handleArrow,RIGHT:handleArrow,LOG:buildNormalFunctionCallback("log"),LN:buildNormalFunctionCallback("ln"),COS:buildNormalFunctionCallback(strings.cos),SIN:buildTranslatableFunctionCallback(strings.sin,["sin","sen"],"sin"),TAN:buildTranslatableFunctionCallback(strings.tan,["tan","tg"],"tan"),CDOT:buildGenericCallback("\\cdot"),DECIMAL:buildGenericCallback(getDecimalSeparator(locale)),DIVIDE:buildGenericCallback(getDivideSymbolForTex(locale)),EQUAL:buildGenericCallback("="),GEQ:buildGenericCallback("\\geq"),GT:buildGenericCallback(">"),LEQ:buildGenericCallback("\\leq"),LT:buildGenericCallback("<"),MINUS:buildGenericCallback("-"),NEGATIVE:buildGenericCallback("-"),NEQ:buildGenericCallback("\\neq"),PERCENT:buildGenericCallback("%"),PERIOD:buildGenericCallback("."),PLUS:buildGenericCallback("+"),TIMES:buildGenericCallback("\\times"),FRAC_INCLUSIVE:buildGenericCallback("/",MathFieldActionType.CMD),FRAC:buildGenericCallback("\\frac",MathFieldActionType.CMD),LEFT_PAREN:buildGenericCallback("(",MathFieldActionType.CMD),RIGHT_PAREN:buildGenericCallback(")",MathFieldActionType.CMD),SQRT:buildGenericCallback("sqrt",MathFieldActionType.CMD),PI:buildGenericCallback("pi",MathFieldActionType.CMD),THETA:buildGenericCallback("theta",MathFieldActionType.CMD),RADICAL:buildGenericCallback("nthroot",MathFieldActionType.CMD),BACKSPACE:buildGenericCallback("Backspace",MathFieldActionType.KEYSTROKE),UP:buildGenericCallback("Up",MathFieldActionType.KEYSTROKE),DOWN:buildGenericCallback("Down",MathFieldActionType.KEYSTROKE),CUBE_ROOT:mathQuill=>{mathQuill.write("\\sqrt[3]{}");mathQuill.keystroke("Left");},FRAC_EXCLUSIVE:mathQuill=>{const cursor=mathQuill.cursor();const shouldNavigateLeft=cursor[mathQuillInstance.L]===MathFieldActionType.MQ_END;mathQuill.cmd("\\frac");if(shouldNavigateLeft){mathQuill.keystroke("Left");}},LOG_N:mathQuill=>{mathQuill.write("log_{ }\\left(\\right)");mathQuill.keystroke("Left");mathQuill.keystroke("Left");mathQuill.keystroke("Left");},DISMISS:()=>{},NUM_0:buildGenericCallback("0"),NUM_1:buildGenericCallback("1"),NUM_2:buildGenericCallback("2"),NUM_3:buildGenericCallback("3"),NUM_4:buildGenericCallback("4"),NUM_5:buildGenericCallback("5"),NUM_6:buildGenericCallback("6"),NUM_7:buildGenericCallback("7"),NUM_8:buildGenericCallback("8"),NUM_9:buildGenericCallback("9"),a:buildGenericCallback("a"),b:buildGenericCallback("b"),c:buildGenericCallback("c"),d:buildGenericCallback("d"),e:buildGenericCallback("e"),f:buildGenericCallback("f"),g:buildGenericCallback("g"),h:buildGenericCallback("h"),i:buildGenericCallback("i"),j:buildGenericCallback("j"),k:buildGenericCallback("k"),l:buildGenericCallback("l"),m:buildGenericCallback("m"),n:buildGenericCallback("n"),o:buildGenericCallback("o"),p:buildGenericCallback("p"),q:buildGenericCallback("q"),r:buildGenericCallback("r"),s:buildGenericCallback("s"),t:buildGenericCallback("t"),u:buildGenericCallback("u"),v:buildGenericCallback("v"),w:buildGenericCallback("w"),x:buildGenericCallback("x"),y:buildGenericCallback("y"),z:buildGenericCallback("z"),A:buildGenericCallback("A"),B:buildGenericCallback("B"),C:buildGenericCallback("C"),D:buildGenericCallback("D"),E:buildGenericCallback("E"),F:buildGenericCallback("F"),G:buildGenericCallback("G"),H:buildGenericCallback("H"),I:buildGenericCallback("I"),J:buildGenericCallback("J"),K:buildGenericCallback("K"),L:buildGenericCallback("L"),M:buildGenericCallback("M"),N:buildGenericCallback("N"),O:buildGenericCallback("O"),P:buildGenericCallback("P"),Q:buildGenericCallback("Q"),R:buildGenericCallback("R"),S:buildGenericCallback("S"),T:buildGenericCallback("T"),U:buildGenericCallback("U"),V:buildGenericCallback("V"),W:buildGenericCallback("W"),X:buildGenericCallback("X"),Y:buildGenericCallback("Y"),Z:buildGenericCallback("Z")});
|
|
1429
1429
|
|
|
1430
1430
|
class MathWrapper{focus(){this.mathField.cursor().show();this.mathField.focus();}blur(){this.mathField.cursor().hide();this.mathField.blur();}pressKey(key){const cursor=this.getCursor();const translator=this.mobileKeyTranslator[key];if(translator){translator(this.mathField,key);}if(!cursor.selection){cursor.show();}if(this.callbacks.onSelectionChanged){this.callbacks.onSelectionChanged(cursor.selection);}return {context:this.contextForCursor()}}setCursorPosition(x,y,hitNode){const el=hitNode||document.elementFromPoint(x,y);if(el){const cursor=this.getCursor();if(el.hasAttribute("mq-root-block")){cursor.insAtRightEnd(this.mathField.controller().root);}else {const controller=this.mathField.controller();const pageX=x-document.body.scrollLeft;const pageY=y-document.body.scrollTop;controller.seek(el,pageX,pageY).cursor.startSelection();const command=maybeFindCommand(cursor[mathQuillInstance.L]);if(command&&command.endNode){cursor.insLeftOf(command.endNode);this.mathField.keystroke("Right");}}if(this.callbacks.onCursorMove){this.callbacks.onCursorMove({context:this.contextForCursor()});}}}getCursor(){return this.mathField.cursor()}contextForCursor(){return getCursorContext(this.mathField)}getSelection(){return this.getCursor().selection}getContent(){return this.mathField.latex()}setContent(latex){this.mathField.latex(latex);}isEmpty(){const cursor=this.getCursor();return cursor.parent.id===1&&cursor[1]===0&&cursor[-1]===0}constructor(mathFieldMount,ariaLabel,strings,locale,callbacks={}){this.mathField=createMathField(mathFieldMount,locale,strings,()=>{return {substituteTextarea:function(){return document.createElement("span")}}});this.mathField?.setAriaLabel(ariaLabel);this.callbacks=callbacks;this.mobileKeyTranslator={...getKeyTranslator(locale,strings),BACKSPACE:handleBackspace};}}
|
|
1431
1431
|
|
|
@@ -1471,7 +1471,7 @@ class TransitionChild extends React.Component{static getDerivedStateFromProps({i
|
|
|
1471
1471
|
|
|
1472
1472
|
class AphroditeCSSTransitionGroup extends React.Component{render(){const{children}=this.props;return jsxRuntimeExports.jsx(TransitionGroup,{component:null,children:React.Children.map(children,child=>jsxRuntimeExports.jsx(TransitionChild$1,{transitionStyles:this.props.transitionStyle,appearTimeout:this.props.transitionAppearTimeout,enterTimeout:this.props.transitionEnterTimeout,leaveTimeout:this.props.transitionLeaveTimeout,children:child}))})}}
|
|
1473
1473
|
|
|
1474
|
-
const AnimationDurationInMS=200;class MobileKeypadInternals extends React.Component{componentDidMount(){this._resize();window.addEventListener("resize",this._throttleResizeHandler);window.addEventListener("orientationchange",this._throttleResizeHandler);if("ResizeObserver"in window){this._containerResizeObserver=new window.ResizeObserver(this._throttleResizeHandler);if(this._containerRef.current){this._containerResizeObserver.observe?.(this._containerRef.current);}}this.props.onElementMounted?.({activate:this.activate,dismiss:this.dismiss,configure:this.configure,setCursor:this.setCursor,setKeyHandler:this.setKeyHandler,getDOMNode:this.getDOMNode});}componentWillUnmount(){window.removeEventListener("resize",this._throttleResizeHandler);window.removeEventListener("orientationchange",this._throttleResizeHandler);this._containerResizeObserver?.disconnect?.();}_handleClickKey(key){if(key==="DISMISS"){this.dismiss();return}const cursor=this.state.keyHandler?.(key);this.setState({cursor});}render(){const{keypadActive,style}=this.props;const{containerWidth,cursor,keypadConfig}=this.state;const containerStyle=[styles.keypadContainer,...Array.isArray(style)?style:[style]];const isExpression=keypadConfig?.keypadType==="EXPRESSION";const convertDotToTimes=keypadConfig?.times;return jsxRuntimeExports.jsx(View,{style:containerStyle,forwardRef:this._containerRef,children:jsxRuntimeExports.jsx(AphroditeCSSTransitionGroup,{transitionEnterTimeout:AnimationDurationInMS,transitionLeaveTimeout:AnimationDurationInMS,transitionStyle:{appear:{transform:"translate3d(0, 100%, 0)",transition:`${AnimationDurationInMS}ms ease-out`},appearActive:{transform:"translate3d(0, 100%, 0)"},enter:{transform:"translate3d(0, 50%, 0)",transition:`${AnimationDurationInMS}ms ease-out`},enterActive:{transform:"translate3d(0, 0, 0)"},leave:{transform:"translate3d(0, 0, 0)",transition:`${AnimationDurationInMS}ms ease-out`},leaveActive:{transform:"translate3d(0, 100%, 0)"}},children:keypadActive?jsxRuntimeExports.jsx(Keypad,{onAnalyticsEvent:this.props.onAnalyticsEvent,extraKeys:keypadConfig?.extraKeys,onClickKey:key=>this._handleClickKey(key),cursorContext:cursor?.context,fractionsOnly:!isExpression,convertDotToTimes:convertDotToTimes,divisionKey:isExpression,trigonometry:isExpression,preAlgebra:isExpression,logarithms:isExpression,basicRelations:isExpression,advancedRelations:isExpression,expandedView:containerWidth>expandedViewThreshold,showDismiss:true,scientific:isExpression&&keypadConfig?.scientific}):null})})}constructor(...args){super(...args),this._containerRef=React.createRef(),this._containerResizeObserver=null,this._throttleResize=false,this.state={containerWidth:0},this._resize=()=>{const containerWidth=this._containerRef.current?.clientWidth||0;this.setState({containerWidth});},this._throttleResizeHandler=()=>{if(this._throttleResize){return}this._throttleResize=true;setTimeout(()=>{this._resize();this._throttleResize=false;},100);},this.activate=()=>{this.props.setKeypadActive(true);},this.dismiss=()=>{this.props.setKeypadActive(false);this.props.onDismiss?.();},this.configure=(configuration,cb)=>{this.setState({keypadConfig:configuration});setTimeout(()=>cb&&cb());},this.setCursor=cursor=>{this.setState({cursor});},this.setKeyHandler=keyHandler=>{this.setState({keyHandler});},this.getDOMNode=()=>{return ReactDOM.findDOMNode(this)};}}const styles=StyleSheet.create({keypadContainer:{bottom:0,left:0,right:0,position:"fixed"}});
|
|
1474
|
+
const AnimationDurationInMS=200;class MobileKeypadInternals extends React.Component{componentDidMount(){this._resize();window.addEventListener("resize",this._throttleResizeHandler);window.addEventListener("orientationchange",this._throttleResizeHandler);if("ResizeObserver"in window){this._containerResizeObserver=new window.ResizeObserver(this._throttleResizeHandler);if(this._containerRef.current){this._containerResizeObserver.observe?.(this._containerRef.current);}}this.props.onElementMounted?.({activate:this.activate,dismiss:this.dismiss,configure:this.configure,setCursor:this.setCursor,setKeyHandler:this.setKeyHandler,getDOMNode:this.getDOMNode});}componentWillUnmount(){window.removeEventListener("resize",this._throttleResizeHandler);window.removeEventListener("orientationchange",this._throttleResizeHandler);this._containerResizeObserver?.disconnect?.();}_handleClickKey(key){if(key==="DISMISS"){this.dismiss();return}const cursor=this.state.keyHandler?.(key);this.setState({cursor});}render(){const{keypadActive,style}=this.props;const{containerWidth,cursor,keypadConfig}=this.state;const containerStyle=[styles.keypadContainer,...Array.isArray(style)?style:[style]];const isExpression=keypadConfig?.keypadType==="EXPRESSION";const convertDotToTimes=keypadConfig?.times;return jsxRuntimeExports.jsx(View,{style:containerStyle,forwardRef:this._containerRef,children:jsxRuntimeExports.jsx(AphroditeCSSTransitionGroup,{transitionEnterTimeout:AnimationDurationInMS,transitionLeaveTimeout:AnimationDurationInMS,transitionStyle:{appear:{transform:"translate3d(0, 100%, 0)",transition:`${AnimationDurationInMS}ms ease-out`},appearActive:{transform:"translate3d(0, 100%, 0)"},enter:{transform:"translate3d(0, 50%, 0)",transition:`${AnimationDurationInMS}ms ease-out`},enterActive:{transform:"translate3d(0, 0, 0)"},leave:{transform:"translate3d(0, 0, 0)",transition:`${AnimationDurationInMS}ms ease-out`},leaveActive:{transform:"translate3d(0, 100%, 0)"}},children:keypadActive?jsxRuntimeExports.jsx(Keypad,{onAnalyticsEvent:this.props.onAnalyticsEvent,extraKeys:keypadConfig?.extraKeys,onClickKey:key=>this._handleClickKey(key),cursorContext:cursor?.context,fractionsOnly:!isExpression,convertDotToTimes:convertDotToTimes,divisionKey:isExpression,trigonometry:isExpression,preAlgebra:isExpression,logarithms:isExpression,basicRelations:isExpression,advancedRelations:isExpression,expandedView:containerWidth>expandedViewThreshold,showDismiss:true,scientific:isExpression&&keypadConfig?.scientific}):null})})}constructor(...args){super(...args),this._containerRef=React.createRef(),this._containerResizeObserver=null,this._throttleResize=false,this.state={containerWidth:0},this._resize=()=>{const containerWidth=this._containerRef.current?.clientWidth||0;this.setState({containerWidth});},this._throttleResizeHandler=()=>{if(this._throttleResize){return}this._throttleResize=true;setTimeout(()=>{this._resize();this._throttleResize=false;},100);},this.activate=()=>{this.props.setKeypadActive(true);},this.dismiss=()=>{this.props.setKeypadActive(false);this.props.onDismiss?.();},this.configure=(configuration,cb)=>{this.setState({keypadConfig:configuration});setTimeout(()=>cb&&cb());},this.setCursor=cursor=>{this.setState({cursor});},this.setKeyHandler=keyHandler=>{this.setState({keyHandler});},this.getDOMNode=()=>{return ReactDOM.findDOMNode(this)};}}const styles=StyleSheet.create({keypadContainer:{bottom:0,left:0,right:0,position:"fixed",borderStyle:"solid",borderWidth:1,borderColor:semanticColor.core.border.neutral.subtle}});
|
|
1475
1475
|
|
|
1476
1476
|
function MobileKeypad(props){return jsxRuntimeExports.jsx(KeypadContext.Consumer,{children:({keypadActive,setKeypadActive})=>jsxRuntimeExports.jsx(MobileKeypadInternals,{...props,keypadActive:keypadActive,setKeypadActive:setKeypadActive})})}
|
|
1477
1477
|
|