Skip to content

Commit

Permalink
Merge branch 'main' into feature/analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremywiebe committed Jul 31, 2023
2 parents 7ca6c6f + fbe71ec commit 7bfa2f9
Show file tree
Hide file tree
Showing 55 changed files with 809 additions and 367 deletions.
7 changes: 0 additions & 7 deletions .changeset/many-eagles-promise.md

This file was deleted.

File renamed without changes.
5 changes: 0 additions & 5 deletions .changeset/sour-bears-fail.md

This file was deleted.

6 changes: 6 additions & 0 deletions .github/workflows/node-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ jobs:
limited-trigger: ${{ steps.js-files.outputs.filtered }}
limited: yarn jest --passWithNoTests --findRelatedTests {}

# We use STOPSHIP internally to mark code that's not safe to go live yet.
# We use an if block because we want to return the exact inverse of what
# `git grep` returns (0 on none found, 1 on some found).
- name: Checks that STOPSHIP is not used in any files.
run: ./utils/stopship-check.sh

cypress:
name: Cypress Coverage
runs-on: ${{ matrix.os }}
Expand Down
41 changes: 41 additions & 0 deletions packages/math-input/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,46 @@
# @khanacademy/math-input

## 8.1.1

### Patch Changes

- Updated dependencies [57f75510]
- @khanacademy/perseus-core@0.1.1

## 8.1.0

### Minor Changes

- 5611204a: Adds back the export of the unwrapped keypad for Khanmigo
- b4430dce: Make sendEvent in the Keypad an optional param

### Patch Changes

- Updated dependencies [b4c06409]
- @khanacademy/perseus-core@0.1.0

## 8.0.0

### Major Changes

- f9ee9d24: Move KeypadContext from Perseus to MathInput
- b18986d3: Replace Legacy/Mobile keypads with a component that switches between them

## 7.0.0

### Major Changes

- 04e68d1c: Change keypadElement from LegacyKeypad to KeypadAPI

### Minor Changes

- acafa72d: Add MobileKeypad to v2 keypad in MathInput

### Patch Changes

- d0f28dbd: Add story for ExpressionEditor
- 54590cc7: Add index.ts files to some dirs in MathInput for organization

## 6.0.3

### Patch Changes
Expand Down
4 changes: 2 additions & 2 deletions packages/math-input/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand All @@ -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"
},
Expand Down
9 changes: 4 additions & 5 deletions packages/math-input/src/components/input/math-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,18 @@ import {
wonderBlocksBlue,
offBlack,
} from "../common-style";
import ProvidedKeypad from "../keypad-legacy/provided-keypad";

import CursorHandle from "./cursor-handle";
import DragListener from "./drag-listener";
import MathWrapper from "./math-wrapper";
import {scrollIntoView} from "./scroll-into-view";

import type {Cursor} from "../../types";
import type {Cursor, KeypadAPI} from "../../types";

const constrainingFrictionFactor = 0.8;

type Props = {
keypadElement: ProvidedKeypad;
keypadElement?: KeypadAPI;
onBlur: () => void;
onChange: (value: string, callback: any) => void;
onFocus: () => void;
Expand Down Expand Up @@ -267,7 +266,7 @@ class MathInput extends React.Component<Props, State> {
/** Gets and cache they bounds of the keypadElement */
_getKeypadBounds: () => any = () => {
if (!this._keypadBounds) {
const node = this.props.keypadElement.getDOMNode();
const node = this.props.keypadElement?.getDOMNode();
this._cacheKeypadBounds(node);
}
return this._keypadBounds;
Expand Down Expand Up @@ -341,7 +340,7 @@ class MathInput extends React.Component<Props, State> {
focus: () => void = () => {
// Pass this component's handleKey method to the keypad so it can call
// it whenever it needs to trigger a keypress action.
this.props.keypadElement.setKeyHandler((key) => {
this.props.keypadElement?.setKeyHandler((key) => {
const cursor = this.mathField.pressKey(key);

// Trigger an `onChange` if the value in the input changed, and hide
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/
import * as React from "react";

import type {RendererInterface} from "./types";
import type {RendererInterface} from "@khanacademy/perseus-core";

type KeypadContext = {
setKeypadElement: (keypadElement?: HTMLElement | null | undefined) => void;
Expand Down
1 change: 1 addition & 0 deletions packages/math-input/src/components/keypad-legacy/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {default} from "./provided-keypad";
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ import {
} from "./store/actions";
import {createStore} from "./store/index";

import type {Cursor, KeypadConfiguration, KeyHandler} from "../../types";
import type {
Cursor,
KeypadConfiguration,
KeyHandler,
KeypadAPI,
} from "../../types";
import type {StyleType} from "@khanacademy/wonder-blocks-core";

type Props = {
Expand All @@ -21,7 +26,7 @@ type Props = {
style?: StyleType;
};

class ProvidedKeypad extends React.Component<Props> {
class ProvidedKeypad extends React.Component<Props> implements KeypadAPI {
store: any;

constructor(props) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ import {
innerBorderWidthPx,
offBlack16,
} from "../common-style";
import Tabbar from "../tabbar/tabbar";
import {TabbarItemType} from "../tabbar/types";
import Tabbar from "../tabbar";

import Keypad from "./keypad";
import {State as ReduxState} from "./store/types";
import Styles from "./styles";

import type {TabbarItemType} from "../tabbar";

const {column, row, fullWidth} = Styles;

interface ReduxProps {
Expand Down
23 changes: 23 additions & 0 deletions packages/math-input/src/components/keypad-switch.tsx
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;
175 changes: 2 additions & 173 deletions packages/math-input/src/components/keypad/index.tsx
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";
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {INITIAL_VIEWPORTS} from "@storybook/addon-viewport";
import {ComponentStory} from "@storybook/react";
import * as React from "react";

import Keypad, {Props as KeypadProps} from "./index";
import Keypad, {Props as KeypadProps} from "./keypad";

const opsPage = "Operators Page";
const numsPage = "Numbers Page";
Expand Down
Loading

0 comments on commit 7bfa2f9

Please sign in to comment.