-
Notifications
You must be signed in to change notification settings - Fork 351
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feature/analytics
- Loading branch information
Showing
55 changed files
with
809 additions
and
367 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
"description": "Khan Academy's new expression editor for the mobile web.", | ||
"author": "Khan Academy", | ||
"license": "MIT", | ||
"version": "6.0.3", | ||
"version": "8.1.1", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
|
@@ -19,7 +19,7 @@ | |
"source": "src/index.ts", | ||
"scripts": {}, | ||
"dependencies": { | ||
"@khanacademy/perseus-core": "0.0.2", | ||
"@khanacademy/perseus-core": "0.1.1", | ||
"mathquill": "git+https://[email protected]/Khan/mathquill.git#32d9f351aaa68537170b3120a52e99b8def3a2c3", | ||
"performance-now": "^0.2.0" | ||
}, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export {default} from "./provided-keypad"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import {StyleType} from "@khanacademy/wonder-blocks-core"; | ||
import * as React from "react"; | ||
|
||
import {MobileKeypad} from "./keypad"; | ||
import LegacyKeypad from "./keypad-legacy"; | ||
|
||
type Props = { | ||
onElementMounted?: (arg1: any) => void; | ||
onDismiss?: () => void; | ||
style?: StyleType; | ||
|
||
useV2Keypad?: boolean; | ||
}; | ||
|
||
function KeypadSwitch(props: Props) { | ||
const {useV2Keypad = false, ...rest} = props; | ||
|
||
const KeypadComponent = useV2Keypad ? MobileKeypad : LegacyKeypad; | ||
|
||
return <KeypadComponent {...rest} />; | ||
} | ||
|
||
export default KeypadSwitch; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,173 +1,2 @@ | ||
import Color from "@khanacademy/wonder-blocks-color"; | ||
import {View} from "@khanacademy/wonder-blocks-core"; | ||
import {StyleSheet} from "aphrodite"; | ||
import * as React from "react"; | ||
import {useEffect} from "react"; | ||
|
||
import Key from "../../data/keys"; | ||
import {ClickKeyCallback} from "../../types"; | ||
import {CursorContext} from "../input/cursor-contexts"; | ||
import Tabbar from "../tabbar/tabbar"; | ||
import {TabbarItemType} from "../tabbar/types"; | ||
|
||
import ExtrasPage from "./keypad-pages/extras-page"; | ||
import GeometryPage from "./keypad-pages/geometry-page"; | ||
import NumbersPage from "./keypad-pages/numbers-page"; | ||
import OperatorsPage from "./keypad-pages/operators-page"; | ||
import SharedKeys from "./shared-keys"; | ||
|
||
import type {AnalyticsEventHandlerFn} from "@khanacademy/perseus-core"; | ||
|
||
export type Props = { | ||
extraKeys: ReadonlyArray<Key>; | ||
cursorContext?: typeof CursorContext[keyof typeof CursorContext]; | ||
showDismiss?: boolean; | ||
|
||
multiplicationDot?: boolean; | ||
divisionKey?: boolean; | ||
|
||
trigonometry?: boolean; | ||
preAlgebra?: boolean; | ||
logarithms?: boolean; | ||
basicRelations?: boolean; | ||
advancedRelations?: boolean; | ||
|
||
onClickKey: ClickKeyCallback; | ||
onAnalyticsEvent: AnalyticsEventHandlerFn; | ||
}; | ||
|
||
const defaultProps = { | ||
extraKeys: [], | ||
}; | ||
|
||
function allPages(props: Props): ReadonlyArray<TabbarItemType> { | ||
const pages: Array<TabbarItemType> = ["Numbers"]; | ||
|
||
if ( | ||
// OperatorsButtonSets | ||
props.preAlgebra || | ||
props.logarithms || | ||
props.basicRelations || | ||
props.advancedRelations | ||
) { | ||
pages.push("Operators"); | ||
} | ||
|
||
if (props.trigonometry) { | ||
pages.push("Geometry"); | ||
} | ||
|
||
if (props.extraKeys?.length) { | ||
pages.push("Extras"); | ||
} | ||
|
||
return pages; | ||
} | ||
|
||
// The main (v2) Keypad. Use this component to present an accessible, onscreen | ||
// keypad to learners for entering math expressions. | ||
export default function Keypad(props: Props) { | ||
const [selectedPage, setSelectedPage] = | ||
React.useState<TabbarItemType>("Numbers"); | ||
const [isMounted, setIsMounted] = React.useState<boolean>(false); | ||
|
||
const availablePages = allPages(props); | ||
|
||
const { | ||
onClickKey, | ||
cursorContext, | ||
extraKeys, | ||
multiplicationDot, | ||
divisionKey, | ||
preAlgebra, | ||
logarithms, | ||
basicRelations, | ||
advancedRelations, | ||
showDismiss, | ||
onAnalyticsEvent, | ||
} = props; | ||
|
||
useEffect(() => { | ||
if (!isMounted) { | ||
onAnalyticsEvent({ | ||
type: "math-input:keypad-opened", | ||
payload: {virtualKeypadVersion: "MATH_INPUT_KEYPAD_V2"}, | ||
}); | ||
setIsMounted(true); | ||
} | ||
return () => { | ||
if (isMounted) { | ||
onAnalyticsEvent({ | ||
type: "math-input:keypad-closed", | ||
payload: {virtualKeypadVersion: "MATH_INPUT_KEYPAD_V2"}, | ||
}); | ||
setIsMounted(false); | ||
} | ||
}; | ||
}, [onAnalyticsEvent, isMounted]); | ||
|
||
return ( | ||
<View> | ||
<Tabbar | ||
items={availablePages} | ||
selectedItem={selectedPage} | ||
onSelectItem={(tabbarItem: TabbarItemType) => { | ||
setSelectedPage(tabbarItem); | ||
}} | ||
style={styles.tabbar} | ||
onClickClose={ | ||
showDismiss ? () => onClickKey("DISMISS") : undefined | ||
} | ||
/> | ||
|
||
<View | ||
style={styles.grid} | ||
role="grid" | ||
tabIndex={0} | ||
aria-label="Keypad" | ||
> | ||
{selectedPage === "Numbers" && ( | ||
<NumbersPage onClickKey={onClickKey} /> | ||
)} | ||
{selectedPage === "Extras" && ( | ||
<ExtrasPage onClickKey={onClickKey} extraKeys={extraKeys} /> | ||
)} | ||
{selectedPage === "Operators" && ( | ||
<OperatorsPage | ||
onClickKey={onClickKey} | ||
preAlgebra={preAlgebra} | ||
logarithms={logarithms} | ||
basicRelations={basicRelations} | ||
advancedRelations={advancedRelations} | ||
/> | ||
)} | ||
{selectedPage === "Geometry" && ( | ||
<GeometryPage onClickKey={onClickKey} /> | ||
)} | ||
<SharedKeys | ||
onClickKey={onClickKey} | ||
cursorContext={cursorContext} | ||
multiplicationDot={multiplicationDot} | ||
divisionKey={divisionKey} | ||
selectedPage={selectedPage} | ||
/> | ||
</View> | ||
</View> | ||
); | ||
} | ||
|
||
Keypad.defaultProps = defaultProps; | ||
|
||
const styles = StyleSheet.create({ | ||
tabbar: { | ||
background: Color.white, | ||
}, | ||
grid: { | ||
display: "grid", | ||
gridTemplateColumns: "repeat(6, 1fr)", | ||
gridTemplateRows: "repeat(4, 1fr)", | ||
backgroundColor: "#DBDCDD", | ||
maxHeight: 200, | ||
maxWidth: 300, | ||
}, | ||
}); | ||
export {default} from "./keypad"; | ||
export {default as MobileKeypad} from "./mobile-keypad"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.