Skip to content

Commit

Permalink
Merge branch 'main' into new/unlimited-points
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicole Watts committed Aug 22, 2024
2 parents 980e0fc + 3647119 commit 088f82d
Show file tree
Hide file tree
Showing 71 changed files with 1,006 additions and 534 deletions.
5 changes: 0 additions & 5 deletions .changeset/nasty-cobras-try.md

This file was deleted.

5 changes: 0 additions & 5 deletions .changeset/quiet-glasses-join.md

This file was deleted.

6 changes: 6 additions & 0 deletions .changeset/selfish-kiwis-collect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@khanacademy/perseus-dev-ui": patch
"@khanacademy/perseus": patch
---

Adds a finite point question to dev gallery
5 changes: 0 additions & 5 deletions .changeset/stupid-steaks-flow.md

This file was deleted.

5 changes: 0 additions & 5 deletions .changeset/tough-bananas-arrive.md

This file was deleted.

5 changes: 0 additions & 5 deletions .changeset/unlucky-carrots-sparkle.md

This file was deleted.

5 changes: 0 additions & 5 deletions .changeset/wise-cougars-hunt.md

This file was deleted.

21 changes: 21 additions & 0 deletions dev/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
# @khanacademy/perseus-dev-ui

## 3.0.1

### Patch Changes

- Updated dependencies [[`f5a2cf521`](https://github.com/Khan/perseus/commit/f5a2cf521291180dbbd448adc97700f7c52c8b50), [`e19c58eb9`](https://github.com/Khan/perseus/commit/e19c58eb9f0ef84c32dfdb40a4382cfa4c82392d), [`96f0337ce`](https://github.com/Khan/perseus/commit/96f0337ce459dea6a0860b45704e188876d38720), [`f5a2cf521`](https://github.com/Khan/perseus/commit/f5a2cf521291180dbbd448adc97700f7c52c8b50)]:
- @khanacademy/perseus-linter@1.2.0
- @khanacademy/kas@0.3.12
- @khanacademy/math-input@21.0.1

## 3.0.0

### Major Changes

- [#1536](https://github.com/Khan/perseus/pull/1536) [`78a5558f9`](https://github.com/Khan/perseus/commit/78a5558f93c966a076a35b74c5c01d697408ce84) Thanks [@jeremywiebe](https://github.com/jeremywiebe)! - Revert introduction of ContentPreview component (broke editor linting tooltip)"

## 2.0.9

### Patch Changes

- [#1521](https://github.com/Khan/perseus/pull/1521) [`a9292af78`](https://github.com/Khan/perseus/commit/a9292af78f569b703fcae07de01852f264861158) Thanks [@jeremywiebe](https://github.com/jeremywiebe)! - Update vite config to alias `/strings` expots to correct strings.ts file per package

## 2.0.8

### Patch Changes
Expand Down
1 change: 1 addition & 0 deletions dev/gallery.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import "../packages/perseus/src/styles/perseus-renderer.less";
const questions: [PerseusRenderer, number][] = pairWithIndices([
interactiveGraph.segmentQuestion,
interactiveGraph.pointQuestion,
interactiveGraph.finitePointQuestion,
interactiveGraph.angleQuestion,
interactiveGraph.linearSystemQuestion,
interactiveGraph.circleQuestion,
Expand Down
8 changes: 4 additions & 4 deletions dev/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "Perseus dev UI",
"author": "Khan Academy",
"license": "MIT",
"version": "2.0.8",
"version": "3.0.1",
"private": true,
"repository": {
"type": "git",
Expand All @@ -14,11 +14,11 @@
"dev": "vite"
},
"dependencies": {
"@khanacademy/kas": "^0.3.11",
"@khanacademy/kas": "^0.3.12",
"@khanacademy/kmath": "^0.1.13",
"@khanacademy/math-input": "^21.0.0",
"@khanacademy/math-input": "^21.0.1",
"@khanacademy/perseus-core": "1.5.0",
"@khanacademy/perseus-linter": "^1.1.0",
"@khanacademy/perseus-linter": "^1.2.0",
"@khanacademy/pure-markdown": "^0.3.7",
"@khanacademy/simple-markdown": "^0.13.0",
"@khanacademy/wonder-blocks-banner": "3.0.42",
Expand Down
36 changes: 1 addition & 35 deletions dev/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,41 +10,7 @@ const packageAliases = {};
glob.sync(resolve(__dirname, "../packages/*/package.json")).forEach(
(packageJsonPath) => {
const pkg = JSON.parse(fs.readFileSync(packageJsonPath, "utf-8"));

// "exports" is the more modern way to declare package exports. Some,
// but not all, Perseus packages declare "exports".
if ("exports" in pkg) {
// Not all packages export strings, but for those that do we need
// to set up an alias so Vite properly resolves them.
// Eg `import {strings, mockStrings} from "@khanacademy/perseus/strings";`
// And MOST IMPORTANTLY, this alias _must_ precede the main
// import, otherwise Vite will just use the main export and tack
// `/strings` onto the end, resulting in a path like this:
// `packages/perseus/src/index.ts/strings`
const stringsSource = pkg.exports["./strings"]?.source;
if (stringsSource != null) {
packageAliases[`${pkg.name}/strings`] = join(
dirname(packageJsonPath),
stringsSource,
);
}

const mainSource = pkg.exports["."]?.source;
if (mainSource == null) {
throw new Error(
`Package declares 'exports', but not provide a main export (exports["."])`,
);
}
packageAliases[pkg.name] = join(
dirname(packageJsonPath),
mainSource,
);
} else {
packageAliases[pkg.name] = join(
dirname(packageJsonPath),
pkg.source,
);
}
packageAliases[pkg.name] = join(dirname(packageJsonPath), pkg.source);
},
);

Expand Down
6 changes: 6 additions & 0 deletions packages/kas/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @khanacademy/kas

## 0.3.12

### Patch Changes

- [#1507](https://github.com/Khan/perseus/pull/1507) [`e19c58eb9`](https://github.com/Khan/perseus/commit/e19c58eb9f0ef84c32dfdb40a4382cfa4c82392d) Thanks [@handeyeco](https://github.com/handeyeco)! - Add some tests for mixed numbers in KAS.

## 0.3.11

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/kas/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "A lightweight JavaScript CAS for comparing expressions and equations.",
"author": "Khan Academy",
"license": "MIT",
"version": "0.3.11",
"version": "0.3.12",
"publishConfig": {
"access": "public"
},
Expand Down
49 changes: 45 additions & 4 deletions packages/kas/src/__tests__/evaluating.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,16 @@ expect.extend({
vars: Variables = {},
functions?: ReadonlyArray<string>,
) {
const actual = KAS.parse(input, {functions: functions}).expr.eval(
vars,
{functions: functions},
);
const parsed = KAS.parse(input, {functions: functions});
if (parsed.false || parsed.error) {
return {
pass: false,
message: () =>
`unable to parse: ${input} (error: ${parsed.error})`,
};
}

const actual = parsed.expr.eval(vars, {functions: functions});
if (actual !== expected) {
return {
pass: false,
Expand Down Expand Up @@ -96,4 +101,40 @@ describe("evaluating", () => {
expect("f(x-1)-f(x)").toEvaluateAs(-7, {f: "x^3", x: 2}, ["f"]);
expect("g(1)").toEvaluateAs(-1, {f: "x", g: "-f(x)"}, ["f", "g"]);
});

// TODO (LEMS-2198): these are tests from a failed attempt
// to support mixed numbers correctly. Keeping so we have a record
// of what's wrong and what's expected.
test("fraction expressions", () => {
// wrong
expect("2\\frac{1}{2} + 1").toEvaluateAs(2);
// correct
// expect("2\\frac{1}{2} + 1").toEvaluateAs(3.5);

// wrong
expect("(2\\frac{1}{2}) + 1").toEvaluateAs(2);
// correct
// expect("(2\\frac{1}{2}) + 1").toEvaluateAs(3.5);

// wrong
expect("-2\\frac{1}{2} + 1").toEvaluateAs(0);
// correct
// expect("-2\\frac{1}{2} + 1").toEvaluateAs(-1.5);

// wrong
expect("(-2\\frac{1}{2}) + 1").toEvaluateAs(0);
// correct
// expect("(-2\\frac{1}{2}) + 1").toEvaluateAs(-1.5);

// should continue to pass after LEMS-2198 is done
expect("2-\\frac{1}{2} + 1").toEvaluateAs(2.5);
expect("(2-\\frac{1}{2}) + 1").toEvaluateAs(2.5);
expect("(2)\\frac{1}{2} + 1").toEvaluateAs(2);
expect("2(\\frac{1}{2}) + 1").toEvaluateAs(2);
expect("\\frac{1}{2}2 + 1").toEvaluateAs(2);
expect("2 + \\frac{1}{2} + 1").toEvaluateAs(3.5);
expect("2 * \\frac{1}{2}").toEvaluateAs(1);
expect("2 2").toEvaluateAs(4);
expect("2\\pi").toEvaluateAs(6.283185307179586);
});
});
7 changes: 6 additions & 1 deletion packages/kas/src/__tests__/parsing.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ expect.extend({
if (actual !== expected) {
return {
pass: false,
message: () => `${input} parses as ${expected}`,
message: () =>
`input: ${input}\nexpected:${expected}\nactual: ${actual}`,
};
}

Expand Down Expand Up @@ -113,6 +114,8 @@ describe("parsing", () => {
expect("\\frac{42}{1}").toParseAs("42/1");
expect("\\frac{0}{42}").toParseAs("0/42");

// TODO (LEMS-2198): this should actually be:
// expect("2\\frac{1}{2}").toParseAs("2+1/2");
expect("2\\frac{1}{2}").toParseAs("2*1/2");
expect("\\frac{1}{2}\\frac{1}{2}").toParseAs("1/2*1/2");
expect("-\\frac{1}{2}").toParseAs("-1/2");
Expand All @@ -128,6 +131,8 @@ describe("parsing", () => {
expect("\\dfrac{42}{1}").toParseAs("42/1");
expect("\\dfrac{0}{42}").toParseAs("0/42");

// TODO (LEMS-2198): this should actually be:
// expect("2\\dfrac{1}{2}").toParseAs("2+1/2");
expect("2\\dfrac{1}{2}").toParseAs("2*1/2");
expect("\\dfrac{1}{2}\\dfrac{1}{2}").toParseAs("1/2*1/2");
expect("-\\dfrac{1}{2}").toParseAs("-1/2");
Expand Down
6 changes: 6 additions & 0 deletions packages/math-input/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @khanacademy/math-input

## 21.0.1

### Patch Changes

- [#1538](https://github.com/Khan/perseus/pull/1538) [`96f0337ce`](https://github.com/Khan/perseus/commit/96f0337ce459dea6a0860b45704e188876d38720) Thanks [@handeyeco](https://github.com/handeyeco)! - Use Portuguese sen and tg when updating Mathquill from the keypad

## 21.0.0

### Major Changes
Expand Down
2 changes: 1 addition & 1 deletion 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": "21.0.0",
"version": "21.0.1",
"publishConfig": {
"access": "public"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/math-input/src/components/input/math-wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class MathWrapper {
this.callbacks = callbacks;

this.mobileKeyTranslator = {
...getKeyTranslator(locale),
...getKeyTranslator(locale, strings),
// note(Matthew): our mobile backspace logic is really complicated
// and for some reason doesn't really work in the desktop experience.
// So we default to the basic backspace functionality in the
Expand Down
38 changes: 35 additions & 3 deletions packages/math-input/src/components/key-handlers/key-translator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,46 @@ function buildGenericCallback(
};
}

/**
* This lets us use translated functions
* (like tg->tan and sen->sin) when we know it's safe to.
* This lets us progressively support translations without needing
* to support every language all at once.
*
* @param {string} command - the translated command/function to check
* @param {string[]} supportedTranslations - list of translations we support
* @param {string} defaultCommand - what to fallback to if the command isn't supported
*/
function buildTranslatableFunctionCallback(
command: string,
supportedTranslations: string[],
defaultCommand: string,
) {
const cmd = supportedTranslations.includes(command)
? command
: defaultCommand;
return function (mathField: MathFieldInterface) {
mathField.write(`${cmd}\\left(\\right)`);
mathField.keystroke("Left");
};
}

function buildNormalFunctionCallback(command: string) {
return function (mathField: MathFieldInterface) {
mathField.write(`\\${command}\\left(\\right)`);
mathField.keystroke("Left");
};
}

type KeyTranslatorStrings = {
sin: string;
cos: string;
tan: string;
};

export const getKeyTranslator = (
locale: string,
strings: KeyTranslatorStrings,
): Record<Key, MathFieldUpdaterCallback> => ({
EXP: handleExponent,
EXP_2: handleExponent,
Expand All @@ -66,9 +97,10 @@ export const getKeyTranslator = (

LOG: buildNormalFunctionCallback("log"),
LN: buildNormalFunctionCallback("ln"),
SIN: buildNormalFunctionCallback("sin"),
COS: buildNormalFunctionCallback("cos"),
TAN: buildNormalFunctionCallback("tan"),

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)),
Expand Down
Loading

0 comments on commit 088f82d

Please sign in to comment.