From 87aadc43a524cbf8dd9225ab492a62bdc947b555 Mon Sep 17 00:00:00 2001 From: Ned Redmond Date: Mon, 21 Aug 2023 13:51:17 -0400 Subject: [PATCH 1/6] Add event to `onClickKey` callback (#678) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds event to callback in order to allow consumer to `preventDefault` Author: nedredmond Reviewers: jeremywiebe Required Reviewers: Approved By: jeremywiebe Checks: ⌛ finish_coverage, ✅ Publish npm snapshot (ubuntu-latest, 16.x), ✅ Extract i18n strings (ubuntu-latest, 16.x), ✅ Cypress Coverage (ubuntu-latest, 16.x), ✅ Lint, Typecheck, Format, and Test (ubuntu-latest, 16.x), ✅ Jest Coverage (ubuntu-latest, 16.x), ✅ Check builds for changes in size (ubuntu-latest, 16.x), ✅ gerald, ✅ Check for .changeset file (ubuntu-latest, 16.x) Pull Request URL: https://github.com/Khan/perseus/pull/678 --- .changeset/kind-tigers-beg.md | 5 ++ .../keypad/__tests__/keypad-button.test.tsx | 47 +++++++++++++++++-- .../keypad/__tests__/keypad-v2.cypress.ts | 34 +------------- .../keypad/__tests__/keypad.test.tsx | 31 ++++++++++++ .../keypad/__tests__/test-data-tabs.ts | 21 +++++++++ .../src/components/keypad/keypad-button.tsx | 2 +- packages/math-input/src/types.ts | 3 +- testing/render-keypad-with-cypress.tsx | 4 +- 8 files changed, 108 insertions(+), 39 deletions(-) create mode 100644 .changeset/kind-tigers-beg.md create mode 100644 packages/math-input/src/components/keypad/__tests__/test-data-tabs.ts diff --git a/.changeset/kind-tigers-beg.md b/.changeset/kind-tigers-beg.md new file mode 100644 index 0000000000..8ae62d568c --- /dev/null +++ b/.changeset/kind-tigers-beg.md @@ -0,0 +1,5 @@ +--- +"@khanacademy/math-input": minor +--- + +Surface event from `onClickKey` callback diff --git a/packages/math-input/src/components/keypad/__tests__/keypad-button.test.tsx b/packages/math-input/src/components/keypad/__tests__/keypad-button.test.tsx index 8cd03a17af..1ee965f7d7 100644 --- a/packages/math-input/src/components/keypad/__tests__/keypad-button.test.tsx +++ b/packages/math-input/src/components/keypad/__tests__/keypad-button.test.tsx @@ -23,9 +23,10 @@ describe("", () => { ).toBeInTheDocument(); }); - it("handles onClickKey callback", () => { + it("handles onClickKey callback with click", () => { // Arrange - const mockClickKeyCallback = jest.fn(); + // persist event to prevent React from releasing/nullifying before assertion + const mockClickKeyCallback = jest.fn((_, event) => event.persist()); render( ", () => { userEvent.click(screen.getByRole("button", {name: "Left parenthesis"})); // Assert - expect(mockClickKeyCallback).toHaveBeenCalledWith("LEFT_PAREN"); + expect(mockClickKeyCallback).toHaveBeenCalledWith( + "LEFT_PAREN", + expect.objectContaining({ + type: "click", + detail: 1, + }), + ); + }); + + it("handles onClickKey callback with keyboard press", () => { + // Arrange + // persist event to prevent React from releasing/nullifying before assertion + const mockClickKeyCallback = jest.fn((_, event) => event.persist()); + render( + , + ); + + // Act + screen.getByRole("button", {name: "Right parenthesis"}).focus(); + userEvent.keyboard("{enter}"); + + // Assert + expect(mockClickKeyCallback).toHaveBeenCalledWith( + "RIGHT_PAREN", + // In the browser, "enter" and "space" trigger a click event with detail 0. + // However, there is a bug in this version (13.5) of RTL that prevents + // "keypress" from being fired, which handles the click event. + // https://github.com/testing-library/user-event/blob/5d946d51d643f0ef7e7730fa527b7ca96e330907/src/keyboard/plugins/functional.ts#L99 + // https://github.com/testing-library/user-event/issues/766 + // The only event fired is `keyDown`, which is inconsistent with the + // browser. If you're reading this and we have upgraded to 14+, please + // uncomment the `type` assertion below. + expect.objectContaining({ + // type: "click", + detail: 0, + }), + ); }); }); diff --git a/packages/math-input/src/components/keypad/__tests__/keypad-v2.cypress.ts b/packages/math-input/src/components/keypad/__tests__/keypad-v2.cypress.ts index 96ed13e8ca..c102daded0 100644 --- a/packages/math-input/src/components/keypad/__tests__/keypad-v2.cypress.ts +++ b/packages/math-input/src/components/keypad/__tests__/keypad-v2.cypress.ts @@ -1,46 +1,16 @@ import renderSingleKeypad from "../../../../../../testing/render-keypad-with-cypress"; -import KeyConfigs from "../../../data/key-configs"; -const tabs = [ - { - name: "Operators", - specialButton: "EXP_2", - label: KeyConfigs["EXP_2"].ariaLabel, - }, - {name: "Extras", specialButton: "PI", label: KeyConfigs["PI"].ariaLabel}, - - { - name: "Geometry", - specialButton: "COS", - label: KeyConfigs["COS"].ariaLabel, - }, - { - name: "Numbers", - specialButton: "NUM_7", - label: KeyConfigs["NUM_7"].ariaLabel, - }, -]; +import tabs from "./test-data-tabs"; describe("Keypad v2", () => { tabs.forEach((tab) => { it(`switches to the correct tab: ${tab.name}`, () => { - renderSingleKeypad((key) => {}); + renderSingleKeypad(); // currently clicking on the bottom left due to button re-rendering // after mousedown but before mouseup (only in Cypress) cy.get('[aria-label="' + tab.name + '"]').click("bottomLeft"); cy.get('[aria-label="' + tab.label + '"]').should("exist"); }); - - it(`calls ${tab.specialButton} key callback in ${tab.name} tab`, () => { - const onClickKeySpy = cy.spy().as("onClickKeySpy"); - renderSingleKeypad(onClickKeySpy); - cy.get('[aria-label="' + tab.name + '"]').click(); - cy.get('[aria-label="' + tab.label + '"]').click(); - cy.get("@onClickKeySpy").should( - "have.been.calledOnceWithExactly", - tab.specialButton, - ); - }); }); }); diff --git a/packages/math-input/src/components/keypad/__tests__/keypad.test.tsx b/packages/math-input/src/components/keypad/__tests__/keypad.test.tsx index 5d54af85bc..4fb10566a6 100644 --- a/packages/math-input/src/components/keypad/__tests__/keypad.test.tsx +++ b/packages/math-input/src/components/keypad/__tests__/keypad.test.tsx @@ -1,4 +1,5 @@ import {render, screen} from "@testing-library/react"; +import userEvent from "@testing-library/user-event"; import * as React from "react"; import "@testing-library/jest-dom"; @@ -6,6 +7,8 @@ import keyConfigs from "../../../data/key-configs"; import {CursorContext} from "../../input/cursor-contexts"; import Keypad from "../index"; +import tabs from "./test-data-tabs"; + const contextToKeyAria = { [CursorContext.IN_PARENS]: keyConfigs.JUMP_OUT_PARENTHESES.ariaLabel, [CursorContext.IN_SUPER_SCRIPT]: keyConfigs.JUMP_OUT_EXPONENT.ariaLabel, @@ -89,4 +92,32 @@ describe("keypad", () => { // Assert expect(screen.queryByRole("tab")).not.toBeInTheDocument(); }); + + it(`clicking tab triggers callback`, () => { + // Arrange + const onClickKey = jest.fn(); + + // Act + render( + {}} + />, + ); + + for (const tabData of tabs) { + const tab = screen.getByLabelText(tabData.name); + expect(tab).toBeInTheDocument(); + userEvent.click(tab); + const key = screen.getByLabelText(tabData.label); + expect(key).toBeInTheDocument(); + userEvent.click(key); + } + + // Assert + expect(onClickKey).toHaveBeenCalledTimes(tabs.length); + }); }); diff --git a/packages/math-input/src/components/keypad/__tests__/test-data-tabs.ts b/packages/math-input/src/components/keypad/__tests__/test-data-tabs.ts new file mode 100644 index 0000000000..26c97ad924 --- /dev/null +++ b/packages/math-input/src/components/keypad/__tests__/test-data-tabs.ts @@ -0,0 +1,21 @@ +import KeyConfigs from "../../../data/key-configs"; + +export default [ + { + name: "Operators", + specialButton: "EXP_2", + label: KeyConfigs["EXP_2"].ariaLabel, + }, + {name: "Extras", specialButton: "PI", label: KeyConfigs["PI"].ariaLabel}, + + { + name: "Geometry", + specialButton: "COS", + label: KeyConfigs["COS"].ariaLabel, + }, + { + name: "Numbers", + specialButton: "NUM_7", + label: KeyConfigs["NUM_7"].ariaLabel, + }, +]; diff --git a/packages/math-input/src/components/keypad/keypad-button.tsx b/packages/math-input/src/components/keypad/keypad-button.tsx index 70b6269464..71a82b459c 100644 --- a/packages/math-input/src/components/keypad/keypad-button.tsx +++ b/packages/math-input/src/components/keypad/keypad-button.tsx @@ -40,7 +40,7 @@ export const KeypadButton = ({ }} > onClickKey(keyConfig.id)} + onClick={(e) => onClickKey(keyConfig.id, e)} style={styles.clickable} aria-label={keyConfig.ariaLabel} > diff --git a/packages/math-input/src/types.ts b/packages/math-input/src/types.ts index aa2ec2094d..c5b1f655d5 100644 --- a/packages/math-input/src/types.ts +++ b/packages/math-input/src/types.ts @@ -7,6 +7,7 @@ import type { KeyType, KeypadType, } from "./enums"; +import type * as React from "react"; import type ReactDOM from "react-dom"; export type Border = Partial>; @@ -85,7 +86,7 @@ export type ActiveNodesObj = { export type LayoutProps = {initialBounds: Bound}; -export type ClickKeyCallback = (key: Key) => void; +export type ClickKeyCallback = (key: Key, event?: React.SyntheticEvent) => void; export interface KeypadAPI { activate: () => void; diff --git a/testing/render-keypad-with-cypress.tsx b/testing/render-keypad-with-cypress.tsx index 240d3ce6e2..489881a843 100644 --- a/testing/render-keypad-with-cypress.tsx +++ b/testing/render-keypad-with-cypress.tsx @@ -3,11 +3,11 @@ import * as React from "react"; import Keypad from "../packages/math-input/src/components/keypad"; -const renderSingleKeypad = (handleClickKey) => +const renderSingleKeypad = () => mount( {}} advancedRelations basicRelations divisionKey From 0993a46b4f284251c5c08ad50299a814554df741 Mon Sep 17 00:00:00 2001 From: Kevin Barabash Date: Mon, 21 Aug 2023 14:50:54 -0400 Subject: [PATCH 2/6] FEI-5003.1 Stop generating Flow types for packages (#680) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary: Now that the static service is using TypeScript we can stop generating Flow types. Note: the webview in the mobile repo still needs to be migrated to TypeScript before it will be able to use future versions of Perseus. Issue: FEI-5003 NOTE: This PR supersedes #649. cc @nixterrimus ## Test plan: - let CI run Author: kevinbarabash Reviewers: jeresig, #perseus Required Reviewers: Approved By: jeresig Checks: ✅ finish_coverage, ✅ finish_coverage, ✅ finish_coverage, ❌ Publish npm snapshot (ubuntu-latest, 16.x), ✅ Extract i18n strings (ubuntu-latest, 16.x), ✅ Check builds for changes in size (ubuntu-latest, 16.x), ✅ Lint, Typecheck, Format, and Test (ubuntu-latest, 16.x), ✅ Cypress Coverage (ubuntu-latest, 16.x), ✅ Jest Coverage (ubuntu-latest, 16.x), ✅ Check for .changeset file (ubuntu-latest, 16.x), ✅ gerald, ✅ Publish npm snapshot (ubuntu-latest, 16.x), ✅ Extract i18n strings (ubuntu-latest, 16.x), ✅ Cypress Coverage (ubuntu-latest, 16.x), ✅ Check builds for changes in size (ubuntu-latest, 16.x), ✅ Lint, Typecheck, Format, and Test (ubuntu-latest, 16.x), ✅ Jest Coverage (ubuntu-latest, 16.x), ✅ gerald, ✅ Check for .changeset file (ubuntu-latest, 16.x), ✅ Check builds for changes in size (ubuntu-latest, 16.x), ✅ Publish npm snapshot (ubuntu-latest, 16.x), ✅ Lint, Typecheck, Format, and Test (ubuntu-latest, 16.x), ✅ Extract i18n strings (ubuntu-latest, 16.x), ✅ Cypress Coverage (ubuntu-latest, 16.x), ✅ Jest Coverage (ubuntu-latest, 16.x), ✅ Check for .changeset file (ubuntu-latest, 16.x), ✅ gerald Pull Request URL: https://github.com/Khan/perseus/pull/680 --- .changeset/happy-cougars-clap.md | 6 + .changeset/quick-rings-boil.md | 6 + .github/workflows/node-ci.yml | 4 - config/build/gen-flow-types.ts | 108 ------------------ package.json | 4 +- .../src/components/input/cursor-contexts.ts | 18 +-- .../src/multi-items/item-types.js.flow | 55 --------- .../src/troublesome-types.js.flow | 22 ---- utils/publish-snapshot.sh | 1 - yarn.lock | 65 +---------- 10 files changed, 24 insertions(+), 265 deletions(-) create mode 100644 .changeset/happy-cougars-clap.md create mode 100644 .changeset/quick-rings-boil.md delete mode 100755 config/build/gen-flow-types.ts delete mode 100644 packages/perseus/src/multi-items/item-types.js.flow delete mode 100644 packages/simple-markdown/src/troublesome-types.js.flow diff --git a/.changeset/happy-cougars-clap.md b/.changeset/happy-cougars-clap.md new file mode 100644 index 0000000000..cc6ab52821 --- /dev/null +++ b/.changeset/happy-cougars-clap.md @@ -0,0 +1,6 @@ +--- +"@khanacademy/math-input": major +"@khanacademy/perseus": major +--- + +Don't generate Flow types diff --git a/.changeset/quick-rings-boil.md b/.changeset/quick-rings-boil.md new file mode 100644 index 0000000000..d73a0cf0e0 --- /dev/null +++ b/.changeset/quick-rings-boil.md @@ -0,0 +1,6 @@ +--- +"perseus-build-settings": minor +"@khanacademy/simple-markdown": minor +--- + +Don't generate Flow types diff --git a/.github/workflows/node-ci.yml b/.github/workflows/node-ci.yml index 29f47be3d3..d2bdd9854a 100644 --- a/.github/workflows/node-ci.yml +++ b/.github/workflows/node-ci.yml @@ -81,10 +81,6 @@ jobs: if: (success() || failure()) && steps.js-files.outputs.filtered != '[]' run: yarn build:types - - name: Build Flow types - if: (success() || failure()) && steps.js-files.outputs.filtered != '[]' - run: yarn build:flowtypes - # Run tests for our target matrix - id: jest-reset uses: Khan/actions@filter-files-v0 diff --git a/config/build/gen-flow-types.ts b/config/build/gen-flow-types.ts deleted file mode 100755 index a540a8388d..0000000000 --- a/config/build/gen-flow-types.ts +++ /dev/null @@ -1,108 +0,0 @@ -#!/usr/bin/env -S node -r @swc-node/register -import * as fs from "fs"; -import * as path from "path"; - -import * as fglob from "fast-glob"; -import {compiler, beautify} from "flowgen"; - -const rootDir = path.join(__dirname, "..", ".."); -const files = fglob.sync("packages/*/dist/**/*.d.ts", { - cwd: rootDir, -}); - -if (files.length) { - console.log(`found ${files.length} files`); -} else { - throw new Error("no typescript type definitions found"); -} - -// The node API for `flowgen` doesn't have an option to add a flow header -// so we need to do it ourselves. -const HEADER = `/** - * Flowtype definitions for data - * Generated by Flowgen from a Typescript Definition - * Flowgen v1.21.0 - * @flow - */ -`; - -let errorCount = 0; - -for (const inFile of files) { - const outFile = inFile.replace(".d.ts", ".js.flow"); - - const overrideFile = outFile.replace("/dist/", "/src/"); - if (fs.existsSync(overrideFile)) { - console.log(`copying\nfrom: ${overrideFile}\nto: ${outFile}`); - fs.cpSync( - path.join(rootDir, overrideFile), - path.join(rootDir, outFile), - ); - continue; - } - - try { - const source = fs.readFileSync(path.join(rootDir, inFile), "utf-8"); - const options = {inexact: false}; - let contents: string = compiler.compileDefinitionString( - source, - options, - ); - contents = beautify(contents); - - // `flowgen` sometimes outputs code that uses `mixins` instead of `extends` - // so we do some post-processing on the files to clean that up. - if (contents.includes(" mixins ")) { - contents = contents.replace(/ mixins /g, " extends "); - console.log("replacing 'mixins' with 'extends'"); - } - if (contents.includes("React.Element<>")) { - contents = contents.replace( - /React.Element<>/g, - "React.Element", - ); - console.log( - "replacing 'React.Element<>' with 'React.Element'", - ); - } - if (contents.includes("JSX.LibraryManagedAttributes")) { - contents = contents.replace( - /JSX\.LibraryManagedAttributes<\s+([^,]+),\s+React\.(Element|Component)Props<[^>]+>\s+>/gm, - (substr, group) => { - const replacement = `React.ElementConfig<${group}>`; - console.log(`replacing '${substr}' with '${replacement}'`); - return replacement; - }, - ); - } - if (/React\.Element<\s*React\.ElementProps]+)>\s*)>/gm, - (substr, group1, group2) => { - const replacement = `React.Element<${group2.trim()}>`; - console.log(`replacing '${substr}' with '${replacement}'`); - return replacement; - }, - ); - } - if (contents.includes("React.ElementConfig")) { - contents = contents.replace( - "React.ElementConfig", - "React.ElementConfig", - ); - } - - fs.writeFileSync( - path.join(rootDir, outFile), - HEADER + contents, - "utf-8", - ); - console.log(`✅ wrote: ${outFile}`); - } catch (e) { - errorCount += 1; - console.log(`❌ error processing: ${inFile}: ${e}`); - } -} - -// Fail the build step if there were any files we couldn't process -process.exit(errorCount); diff --git a/package.json b/package.json index af9b456c7a..e180f40f0d 100644 --- a/package.json +++ b/package.json @@ -88,7 +88,6 @@ "eslint-plugin-storybook": "^0.5.7", "eslint-plugin-testing-library": "^5.0.0", "fast-glob": "^3.2.11", - "flowgen": "git+https://git@github.com/Khan/flowgen.git#a098eaf64c752760c2ec5dc003062e3ad26e42b5", "jest": "^29.0.1", "jest-environment-jsdom": "^28.0.2", "jest-enzyme": "^7.1.2", @@ -127,7 +126,6 @@ "gen:parsers": "yarn --cwd packages/kas gen:parsers", "build": "yarn gen:parsers && rollup -c config/build/rollup.config.js", "build:types": "yarn tsc --build tsconfig-build.json", - "build:flowtypes": "config/build/gen-flow-types.ts", "build:prodsizecheck": "yarn gen:parsers && rollup -c config/build/rollup.config.js --configEnvironment='production'", "watch": "rollup -c config/build/rollup.config.js --watch", "clean": "rm -rf packages/*/dist && rm -rf packages/*/node_modules && rm -rf .nyc_output && rm -f packages/*/*.tsbuildinfo", @@ -136,7 +134,7 @@ "extract-strings": "utils/extract-strings.ts", "lint": "eslint . --ext .js --ext .jsx --ext .ts --ext .tsx", "lint:timing": "cross-env TIMING=1 yarn lint", - "publish:ci": "utils/pre-publish-check-ci.ts && git diff --stat --exit-code HEAD && yarn build && yarn build:types && yarn build:flowtypes && yarn extract-strings && changeset publish", + "publish:ci": "utils/pre-publish-check-ci.ts && git diff --stat --exit-code HEAD && yarn build && yarn build:types && yarn extract-strings && changeset publish", "sloc": "sloc packages --exclude node_modules", "test": "yarn jest", "test:no-console-mock": "cross-env GLOBAL_CONSOLE_MOCK=false yarn jest", diff --git a/packages/math-input/src/components/input/cursor-contexts.ts b/packages/math-input/src/components/input/cursor-contexts.ts index cba6d6a61f..7fac48ca3f 100644 --- a/packages/math-input/src/components/input/cursor-contexts.ts +++ b/packages/math-input/src/components/input/cursor-contexts.ts @@ -10,28 +10,28 @@ * the radical. */ -export const CursorContext = { +export enum CursorContext { // The cursor is not in any of the other viable contexts. - NONE: "NONE", + NONE = "NONE", // The cursor is within a set of parentheses. - IN_PARENS: "IN_PARENS", + IN_PARENS = "IN_PARENS", // The cursor is within a superscript (e.g., an exponent). - IN_SUPER_SCRIPT: "IN_SUPER_SCRIPT", + IN_SUPER_SCRIPT = "IN_SUPER_SCRIPT", // The cursor is within a subscript (e.g., the base of a custom logarithm). - IN_SUB_SCRIPT: "IN_SUB_SCRIPT", + IN_SUB_SCRIPT = "IN_SUB_SCRIPT", // The cursor is in the numerator of a fraction. - IN_NUMERATOR: "IN_NUMERATOR", + IN_NUMERATOR = "IN_NUMERATOR", // The cursor is in the denominator of a fraction. - IN_DENOMINATOR: "IN_DENOMINATOR", + IN_DENOMINATOR = "IN_DENOMINATOR", // The cursor is sitting before a fraction; that is, the cursor is within // what looks to be a mixed number preceding a fraction. This will only be // the case when the only math between the cursor and the fraction to its // write is non-leaf math (numbers and variables). - BEFORE_FRACTION: "BEFORE_FRACTION", -} as const; + BEFORE_FRACTION = "BEFORE_FRACTION", +} diff --git a/packages/perseus/src/multi-items/item-types.js.flow b/packages/perseus/src/multi-items/item-types.js.flow deleted file mode 100644 index 279a2bca3e..0000000000 --- a/packages/perseus/src/multi-items/item-types.js.flow +++ /dev/null @@ -1,55 +0,0 @@ -// @flow -/** - * Type definitions for multi-item types, including: - * - * - Item: A multi-item tree wrapped in a `_multi` key, to help us recognize it - * as a multi-item in other contexts and avoid misinterpreting its - * other properties. - * - ItemTree: A multi-item without the `_multi` key. Conforms to the Tree - * interface, so it's compatible with our tree traversal functions. - * - And the various types of nodes that compose a tree. - */ -import type {WidgetDict, ImageDict} from "../types.js"; -import type {Tree, ArrayNode, ObjectNode} from "./tree-types.js"; - -export type ContentNode = { - // TODO(mdr): When we first drafted the multi-item feature, we named - // content nodes "item" nodes, and later decided the term was - // ambiguous and switched to "content". But we're temporarily keeping - // support for the "item" string when inferring item shape, so that we - // don't crash on multi-items we've already created - but all new - // content nodes will be generated with the "content" string. - // - // Code blocks that enable this legacy support are greppable with the - // keyword #LegacyContentNode. - __type: "content" | "item", - // Perseus has default values for these fields, so they're all optional. - content?: ?string, - images?: ?ImageDict, - widgets?: ?WidgetDict, - ... -}; -export type HintNode = { - __type: "hint", - // Perseus has default values for these fields, so they're all optional. - content?: ?string, - images?: ?ImageDict, - widgets?: ?WidgetDict, - replace?: ?boolean, - ... -}; -export type TagsNode = $ReadOnlyArray; - -export type ItemArrayNode = ArrayNode; -export type ItemObjectNode = ObjectNode; -export type ItemTree = Tree; - -// TODO(jeremy): I think we could refine this root type for multi items. Right -// now a _multi's value can be _anything_ including "primitive" node types such -// as "type: content" or "type: hint". That doesn't seem to match the shapes -// that are in use to date. We could also move to a strict type at that point -// because it appears that we _never_ add other root keys to an item that -// specifies the `_multi` key. I think we'd be safe to restrict this root -// object type to something like the following: -// export type Item = {|_multi: ItemArrayNode | ItemObjectNode|}; -export type Item = {_multi: ItemTree, ...}; diff --git a/packages/simple-markdown/src/troublesome-types.js.flow b/packages/simple-markdown/src/troublesome-types.js.flow deleted file mode 100644 index a3f6d40aec..0000000000 --- a/packages/simple-markdown/src/troublesome-types.js.flow +++ /dev/null @@ -1,22 +0,0 @@ -// @flow -export type Capture = - | (Array & { - index: number, - }) - | (Array & { - index?: number, - }); - -export type State = { - key?: string | number | undefined, - inline?: boolean | null | undefined, - [key: string]: any, -}; - -export type MatchFunction = { - regex?: RegExp, -} & (( - source: string, - state: State, - prevCapture: string, -) => Capture | null | undefined); diff --git a/utils/publish-snapshot.sh b/utils/publish-snapshot.sh index 98e2d4d3d2..e9de30c1d6 100755 --- a/utils/publish-snapshot.sh +++ b/utils/publish-snapshot.sh @@ -111,7 +111,6 @@ create_npmrc yarn build yarn build:types -yarn build:flowtypes yarn extract-strings # Now version the packages and publish a snapshot diff --git a/yarn.lock b/yarn.lock index 4d44b681e1..002a978480 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7606,7 +7606,7 @@ commander@^5.0.0, commander@^5.1.0: resolved "https://registry.yarnpkg.com/commander/-/commander-5.1.0.tgz#46abbd1652f8e059bddaef99bbdcb2ad9cf179ae" integrity sha512-P0CysNDQ7rtVw4QIQtm+MRxV66vKFSvlsQvGYXZWR3qFU0jlMKHZZZgw8e+8DSah4UDKMqnknRDQz+xuQXQ/Zg== -commander@^6.1.0, commander@^6.2.1: +commander@^6.2.1: version "6.2.1" resolved "https://registry.yarnpkg.com/commander/-/commander-6.2.1.tgz#0792eb682dfbc325999bb2b84fddddba110ac73c" integrity sha512-U7VdrJFnJgo4xjrHpTzu0yrHPGImdsmD95ZlgYSEajAn2JKzDhDTPG9kBTefmObL2w/ngeZnilk+OV9CG3d7UA== @@ -10304,19 +10304,6 @@ flatted@^3.1.0: resolved "https://registry.yarnpkg.com/flatted/-/flatted-3.2.5.tgz#76c8584f4fc843db64702a6bd04ab7a8bd666da3" integrity sha512-WIWGi2L3DyTUvUrwRKgGi9TwxQMUEqPOPQBVi71R96jZXJdFskXEmf54BoZaS1kknGODoIGASGEzBUYdyMCBJg== -"flowgen@git+https://git@github.com/Khan/flowgen.git#a098eaf64c752760c2ec5dc003062e3ad26e42b5": - version "1.21.0" - resolved "git+https://git@github.com/Khan/flowgen.git#a098eaf64c752760c2ec5dc003062e3ad26e42b5" - dependencies: - "@babel/code-frame" "^7.16.7" - "@babel/highlight" "^7.16.7" - commander "^6.1.0" - lodash "^4.17.20" - prettier "^2.5.1" - shelljs "^0.8.4" - typescript "~4.4.4" - typescript-compiler "^1.4.1-2" - flush-write-stream@^1.0.0: version "1.1.1" resolved "https://registry.yarnpkg.com/flush-write-stream/-/flush-write-stream-1.1.1.tgz#8dd7d873a1babc207d94ead0c2e0e44276ebf2e8" @@ -10736,18 +10723,6 @@ glob-to-regexp@^0.4.1: resolved "https://registry.yarnpkg.com/glob-to-regexp/-/glob-to-regexp-0.4.1.tgz#c75297087c851b9a578bd217dd59a92f59fe546e" integrity sha512-lkX1HJXwyMcprw/5YUZc2s7DrpAiHB21/V+E1rHUrVNokkvB6bqMzT0VfV6/86ZNabt1k14YOIaT7nDvOX3Iiw== -glob@^7.0.0: - version "7.2.3" - resolved "https://registry.yarnpkg.com/glob/-/glob-7.2.3.tgz#b8df0fb802bbfa8e89bd1d938b4e16578ed44f2b" - integrity sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q== - dependencies: - fs.realpath "^1.0.0" - inflight "^1.0.4" - inherits "2" - minimatch "^3.1.1" - once "^1.3.0" - path-is-absolute "^1.0.0" - glob@^7.1.2, glob@^7.1.3, glob@^7.1.4, glob@^7.1.6: version "7.2.0" resolved "https://registry.yarnpkg.com/glob/-/glob-7.2.0.tgz#d15535af7732e02e948f4c41628bd910293f6023" @@ -11630,11 +11605,6 @@ internal-slot@^1.0.3: has "^1.0.3" side-channel "^1.0.4" -interpret@^1.0.0: - version "1.4.0" - resolved "https://registry.yarnpkg.com/interpret/-/interpret-1.4.0.tgz#665ab8bc4da27a774a40584e812e3e0fa45b1a1e" - integrity sha512-agE4QfB2Lkp9uICn7BAqoscw4SZP9kTE2hxiFI3jBPmXJfdqiahTbUuKGsMoN2GtqL9AxhYioAcVvgsb1HvRbA== - interpret@^2.2.0: version "2.2.0" resolved "https://registry.yarnpkg.com/interpret/-/interpret-2.2.0.tgz#1a78a0b5965c40a5416d007ad6f50ad27c417df9" @@ -14351,7 +14321,7 @@ minimalistic-crypto-utils@^1.0.1: dependencies: brace-expansion "^2.0.1" -minimatch@^3.0.2, minimatch@^3.0.4, minimatch@^3.1.1, minimatch@^3.1.2: +minimatch@^3.0.2, minimatch@^3.0.4, minimatch@^3.1.2: version "3.1.2" resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.1.2.tgz#19cd194bfd3e428f049a70817c038d89ab4be35b" integrity sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw== @@ -16316,11 +16286,6 @@ prettier@^1.19.1: resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.19.1.tgz#f7d7f5ff8a9cd872a7be4ca142095956a60797cb" integrity sha512-s7PoyDv/II1ObgQunCbB9PdLmUcBZcnWOcxDh7O0N/UwDEsHyqkW+Qh28jW+mVuCdx7gLB0BotYI1Y6uI9iyew== -prettier@^2.5.1: - version "2.8.7" - resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.8.7.tgz#bb79fc8729308549d28fe3a98fce73d2c0656450" - integrity sha512-yPngTo3aXUUmyuTjeTUT75txrf+aMh9FiD7q9ZE/i6r0bPb22g4FsE6Y338PQX1bmfy08i9QQCB7/rcUAVntfw== - prettier@^2.6.2: version "2.6.2" resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.6.2.tgz#e26d71a18a74c3d0f0597f55f01fb6c06c206032" @@ -17103,13 +17068,6 @@ realpath-native@^1.1.0: dependencies: util.promisify "^1.0.0" -rechoir@^0.6.2: - version "0.6.2" - resolved "https://registry.yarnpkg.com/rechoir/-/rechoir-0.6.2.tgz#85204b54dba82d5742e28c96756ef43af50e3384" - integrity sha512-HFM8rkZ+i3zrV+4LQjwQ0W+ez98pApMGM3HUrN04j3CqzPOzl9nmP15Y8YXNm8QHGv/eacOVEjqhmWpkRV0NAw== - dependencies: - resolve "^1.1.6" - redent@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/redent/-/redent-1.0.0.tgz#cf916ab1fd5f1f16dfb20822dd6ec7f730c2afde" @@ -17976,15 +17934,6 @@ shebang-regex@^3.0.0: resolved "https://registry.yarnpkg.com/shebang-regex/-/shebang-regex-3.0.0.tgz#ae16f1644d873ecad843b0307b143362d4c42172" integrity sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A== -shelljs@^0.8.4: - version "0.8.5" - resolved "https://registry.yarnpkg.com/shelljs/-/shelljs-0.8.5.tgz#de055408d8361bed66c669d2f000538ced8ee20c" - integrity sha512-TiwcRcrkhHvbrZbnRcFYMLl30Dfov3HKqzp5tO5b4pt6G/SezKcYhmDg15zXVBswHmctSAQKznqNW2LO5tTDow== - dependencies: - glob "^7.0.0" - interpret "^1.0.0" - rechoir "^0.6.2" - side-channel@^1.0.4: version "1.0.4" resolved "https://registry.yarnpkg.com/side-channel/-/side-channel-1.0.4.tgz#efce5c8fdc104ee751b25c58d4290011fa5ea2cf" @@ -19288,11 +19237,6 @@ typedarray@^0.0.6: resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777" integrity sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c= -typescript-compiler@^1.4.1-2: - version "1.4.1-2" - resolved "https://registry.yarnpkg.com/typescript-compiler/-/typescript-compiler-1.4.1-2.tgz#ba4f7db22d91534a1929d90009dce161eb72fd3f" - integrity sha512-EMopKmoAEJqA4XXRFGOb7eSBhmQMbBahW6P1Koayeatp0b4AW2q/bBqYWkpG7QVQc9HGQUiS4trx2ZHcnAaZUg== - typescript-coverage-report@^0.7.0: version "0.7.0" resolved "https://registry.yarnpkg.com/typescript-coverage-report/-/typescript-coverage-report-0.7.0.tgz#ed3898d9f196478945520f7110fab1f6bc109e03" @@ -19318,11 +19262,6 @@ typescript@^3.6.4: resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.9.10.tgz#70f3910ac7a51ed6bef79da7800690b19bf778b8" integrity sha512-w6fIxVE/H1PkLKcCPsFqKE7Kv7QUwhU8qQY2MueZXWx5cPZdwFupLgKK3vntcK98BtNHZtAF4LA/yl2a7k8R6Q== -typescript@~4.4.4: - version "4.4.4" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.4.4.tgz#2cd01a1a1f160704d3101fd5a58ff0f9fcb8030c" - integrity sha512-DqGhF5IKoBl8WNf8C1gu8q0xZSInh9j1kJJMqT3a94w1JzVaBU4EXOSMrz9yDqMT0xt3selp83fuFMQ0uzv6qA== - ua-parser-js@^0.7.30: version "0.7.31" resolved "https://registry.yarnpkg.com/ua-parser-js/-/ua-parser-js-0.7.31.tgz#649a656b191dffab4f21d5e053e27ca17cbff5c6" From 0775f5055acf53c9cca865f15dedd5ee5678ce8e Mon Sep 17 00:00:00 2001 From: Kevin Barabash Date: Mon, 21 Aug 2023 14:54:02 -0400 Subject: [PATCH 3/6] FEI-5003.2: Remove [FEI-5003] from @ts-expect-error comments (#682) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary: There's too many expect-errors for FEI to tackle so I'm removing '[FEI-5003]' from the '@ts-expect-error' comments. Issue: FEI-5003 ## Test plan: - yarn lint [FEI-5003]: https://khanacademy.atlassian.net/browse/FEI-5003?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ Author: kevinbarabash Reviewers: jeresig, #perseus Required Reviewers: Approved By: jeresig Checks: ⌛ Publish npm snapshot (ubuntu-latest, 16.x), ✅ Extract i18n strings (ubuntu-latest, 16.x), ⌛ Check builds for changes in size (ubuntu-latest, 16.x), ⌛ Lint, Typecheck, Format, and Test (ubuntu-latest, 16.x), ⌛ Cypress Coverage (ubuntu-latest, 16.x), ⌛ Jest Coverage (ubuntu-latest, 16.x), ✅ Check for .changeset file (ubuntu-latest, 16.x), ✅ gerald Pull Request URL: https://github.com/Khan/perseus/pull/682 --- .changeset/poor-suns-mate.md | 2 + config/cypress/support.js | 2 +- config/test/test-setup.ts | 12 +- packages/kmath/src/vector.ts | 16 +- .../src/components/input/math-input.tsx | 24 +- .../src/components/keypad-context.ts | 2 +- .../perseus-editor/src/__tests__/i18n.test.ts | 2 +- .../perseus-editor/src/article-editor.tsx | 24 +- .../src/components/checkbox.tsx | 2 +- .../src/components/dropdown-option.tsx | 24 +- .../components/form-wrapped-text-field.tsx | 2 +- .../src/components/graph-settings.tsx | 2 +- .../src/components/hover-behavior.ts | 4 +- .../src/components/json-editor.tsx | 4 +- .../src/components/sortable.tsx | 2 +- .../perseus-editor/src/components/util.ts | 2 +- .../src/components/widget-editor.tsx | 14 +- .../__tests__/structured-item-diff.test.ts | 16 +- .../src/diffs/renderer-diff.tsx | 6 +- .../perseus-editor/src/diffs/split-diff.ts | 4 +- .../src/diffs/structured-item-diff.tsx | 20 +- .../perseus-editor/src/diffs/text-diff.tsx | 2 +- .../perseus-editor/src/diffs/widget-diff.tsx | 4 +- packages/perseus-editor/src/editor-page.tsx | 16 +- packages/perseus-editor/src/editor.tsx | 72 +++--- packages/perseus-editor/src/hint-editor.tsx | 54 ++-- packages/perseus-editor/src/i18n.ts | 8 +- .../src/iframe-content-renderer.tsx | 20 +- packages/perseus-editor/src/item-editor.tsx | 8 +- .../src/multirenderer-editor.tsx | 22 +- .../src/widgets/categorizer-editor.tsx | 6 +- .../src/widgets/cs-program-editor.tsx | 4 +- .../src/widgets/definition-editor.tsx | 4 +- .../src/widgets/dropdown-editor.tsx | 16 +- .../widgets/example-graphie-widget-editor.tsx | 2 +- .../src/widgets/example-graphie-widget.tsx | 4 +- .../src/widgets/example-widget-editor.tsx | 4 +- .../src/widgets/example-widget.tsx | 6 +- .../src/widgets/explanation-editor.tsx | 6 +- .../src/widgets/expression-editor.tsx | 18 +- .../src/widgets/graded-group-editor.tsx | 12 +- .../src/widgets/graded-group-set-editor.tsx | 6 +- .../src/widgets/grapher-editor.tsx | 4 +- .../src/widgets/group-editor.tsx | 6 +- .../src/widgets/iframe-editor.tsx | 8 +- .../src/widgets/input-number-editor.tsx | 8 +- .../src/widgets/interaction-editor.tsx | 204 +++++++-------- .../src/widgets/interactive-graph-editor.tsx | 8 +- .../src/widgets/label-image/marker.tsx | 2 +- .../widgets/label-image/question-markers.tsx | 2 +- .../src/widgets/lights-puzzle-editor.tsx | 8 +- .../src/widgets/matrix-editor.tsx | 4 +- .../src/widgets/measurer-editor.tsx | 12 +- .../src/widgets/molecule-editor.tsx | 4 +- .../src/widgets/number-line-editor.tsx | 2 +- .../src/widgets/numeric-input-editor.tsx | 4 +- .../src/widgets/orderer-editor.tsx | 4 +- .../src/widgets/passage-editor.tsx | 6 +- .../src/widgets/passage-ref-editor.tsx | 6 +- .../src/widgets/passage-ref-target-editor.tsx | 2 +- .../src/widgets/plotter-editor.tsx | 8 +- .../src/widgets/radio/editor.tsx | 6 +- .../src/widgets/reaction-diagram-editor.tsx | 10 +- .../src/widgets/sequence-editor.tsx | 2 +- .../widgets/simple-markdown-tester-editor.tsx | 6 +- .../src/widgets/simple-markdown-tester.tsx | 4 +- .../src/widgets/simulator-editor.tsx | 2 +- .../src/widgets/sorter-editor.tsx | 2 +- .../src/widgets/table-editor.tsx | 2 +- .../src/widgets/transformer-editor.tsx | 20 +- .../src/widgets/unit-editor.tsx | 10 +- .../src/__tests__/matcher.test.ts | 114 ++++----- .../src/__tests__/rules.test.ts | 124 ++++----- .../src/__tests__/tree-transformer.test.ts | 10 +- packages/perseus-linter/src/index.ts | 8 +- packages/perseus-linter/src/rule.ts | 2 +- .../perseus-linter/src/tree-transformer.ts | 6 +- .../__testdata__/item-renderer.testdata.ts | 2 +- .../src/__testdata__/renderer.testdata.ts | 2 +- .../src/__tests__/item-renderer.test.tsx | 2 +- .../__tests__/mock-asset-loading-widget.tsx | 2 +- .../src/__tests__/perseus-markdown.test.ts | 34 +-- .../src/__tests__/renderer-api.test.tsx | 42 ++-- .../perseus/src/__tests__/renderer.test.tsx | 26 +- .../__tests__/server-item-renderer.test.tsx | 4 +- .../src/__tests__/tex-wrangler.test.ts | 2 +- packages/perseus/src/article-renderer.tsx | 12 +- .../__tests__/number-input.test.tsx | 8 +- .../components/__tests__/sortable.test.tsx | 4 +- .../src/components/fixed-to-responsive.tsx | 2 +- packages/perseus/src/components/graph.tsx | 22 +- .../perseus/src/components/graphie-classes.ts | 14 +- packages/perseus/src/components/graphie.tsx | 28 +-- .../highlighting/highlightable-content.tsx | 2 +- .../highlighting/ui/highlight-renderer.tsx | 2 +- .../src/components/highlighting/ui/util.ts | 4 +- .../components/highlighting/word-indexer.tsx | 8 +- packages/perseus/src/components/icon.tsx | 2 +- .../perseus/src/components/image-loader.tsx | 8 +- .../src/components/input-with-examples.tsx | 4 +- packages/perseus/src/components/lint.tsx | 2 +- .../perseus/src/components/math-input.tsx | 8 +- .../perseus/src/components/math-output.tsx | 2 +- .../src/components/multi-button-group.tsx | 2 +- .../perseus/src/components/number-input.tsx | 20 +- .../perseus/src/components/prop-check-box.tsx | 2 +- .../src/components/simple-keypad-input.tsx | 8 +- packages/perseus/src/components/sortable.tsx | 80 +++--- packages/perseus/src/components/svg-image.tsx | 24 +- .../perseus/src/components/tex-buttons.tsx | 4 +- .../perseus/src/components/text-input.tsx | 16 +- .../src/components/text-list-editor.tsx | 22 +- .../create-visibility-observer.ts | 2 +- .../visibility-observer.tsx | 4 +- .../perseus/src/components/zoomable-tex.tsx | 6 +- packages/perseus/src/components/zoomable.tsx | 16 +- packages/perseus/src/hint-renderer.tsx | 6 +- packages/perseus/src/hints-renderer.tsx | 20 +- packages/perseus/src/init.ts | 2 +- packages/perseus/src/interaction-tracker.ts | 8 +- .../__tests__/movable-point.test.ts | 2 +- .../src/interactive2/interactive-util.ts | 12 +- .../interactive2/movable-helper-methods.ts | 4 +- .../src/interactive2/movable-line-options.ts | 74 +++--- .../perseus/src/interactive2/movable-line.ts | 4 +- .../src/interactive2/movable-point-options.ts | 58 ++--- .../src/interactive2/movable-point.tsx | 4 +- .../interactive2/movable-polygon-options.ts | 90 +++---- .../src/interactive2/movable-polygon.ts | 4 +- packages/perseus/src/interactive2/movable.ts | 4 +- .../perseus/src/interactive2/objective_.ts | 2 +- .../src/interactive2/wrapped-defaults.ts | 4 +- .../src/interactive2/wrapped-ellipse.ts | 18 +- .../perseus/src/interactive2/wrapped-line.ts | 16 +- .../perseus/src/interactive2/wrapped-path.ts | 10 +- packages/perseus/src/item-renderer.tsx | 10 +- packages/perseus/src/mixins/changeable.ts | 4 +- packages/perseus/src/mixins/editor-jsonify.ts | 2 +- .../perseus/src/mixins/provide-keypad.tsx | 8 +- .../src/mixins/widget-jsonify-deprecated.ts | 2 +- .../src/multi-items/__tests__/items.test.ts | 2 +- .../__tests__/multi-renderer.test.tsx | 14 +- .../src/multi-items/__tests__/trees.test.ts | 24 +- .../perseus/src/multi-items/item-types.ts | 4 +- packages/perseus/src/multi-items/items.ts | 2 +- .../src/multi-items/multi-renderer.tsx | 28 +-- .../src/multi-items/prop-type-builders.ts | 4 +- .../perseus/src/multi-items/tree-types.ts | 8 +- packages/perseus/src/multi-items/trees.ts | 32 +-- packages/perseus/src/perseus-env.ts | 4 +- packages/perseus/src/perseus-markdown.tsx | 10 +- packages/perseus/src/renderer.tsx | 76 +++--- packages/perseus/src/server-item-renderer.tsx | 10 +- packages/perseus/src/sigfigs.ts | 2 +- packages/perseus/src/traversal.ts | 2 +- packages/perseus/src/util.ts | 30 +-- packages/perseus/src/util/answer-types.ts | 28 +-- packages/perseus/src/util/geometry.ts | 14 +- packages/perseus/src/util/graphie.ts | 64 ++--- packages/perseus/src/util/interactive.ts | 236 +++++++++--------- packages/perseus/src/util/math.ts | 8 +- packages/perseus/src/util/react-render.tsx | 2 +- packages/perseus/src/util/scroll-utils.ts | 4 +- packages/perseus/src/util/tex.ts | 6 +- packages/perseus/src/widget-container.tsx | 2 +- packages/perseus/src/widgets.ts | 8 +- .../test-keypad-context-wrapper.tsx | 6 +- .../__testdata__/numeric-input.testdata.ts | 2 +- .../src/widgets/__tests__/expression.test.ts | 4 +- .../src/widgets/__tests__/grapher.cypress.ts | 64 ++--- .../src/widgets/__tests__/group.test.tsx | 2 +- .../__tests__/interactive-graph.cypress.ts | 80 +++--- .../widgets/__tests__/numeric-input.test.ts | 2 +- .../src/widgets/__tests__/passage.test.tsx | 4 +- .../__tests__/radio/base-radio.test.tsx | 14 +- .../src/widgets/__tests__/renderQuestion.tsx | 6 +- packages/perseus/src/widgets/categorizer.tsx | 8 +- packages/perseus/src/widgets/cs-program.tsx | 4 +- packages/perseus/src/widgets/dropdown.tsx | 2 +- packages/perseus/src/widgets/expression.tsx | 16 +- .../perseus/src/widgets/graded-group-set.tsx | 10 +- packages/perseus/src/widgets/graded-group.tsx | 32 +-- packages/perseus/src/widgets/grapher.tsx | 20 +- packages/perseus/src/widgets/grapher/util.tsx | 12 +- packages/perseus/src/widgets/group.tsx | 6 +- packages/perseus/src/widgets/iframe.tsx | 4 +- packages/perseus/src/widgets/image.tsx | 2 +- packages/perseus/src/widgets/input-number.tsx | 8 +- packages/perseus/src/widgets/interaction.tsx | 154 ++++++------ .../perseus/src/widgets/interactive-graph.tsx | 208 +++++++-------- .../perseus/src/widgets/label-image.test.ts | 2 +- packages/perseus/src/widgets/label-image.tsx | 14 +- .../src/widgets/label-image/marker.tsx | 4 +- .../perseus/src/widgets/lights-puzzle.tsx | 4 +- packages/perseus/src/widgets/matcher.tsx | 12 +- packages/perseus/src/widgets/matrix.tsx | 40 +-- packages/perseus/src/widgets/measurer.tsx | 6 +- packages/perseus/src/widgets/molecule.tsx | 8 +- .../widgets/molecule/__tests__/layout.test.ts | 8 +- .../widgets/molecule/__tests__/parser.test.ts | 28 +-- .../src/widgets/molecule/smiles-parser.ts | 6 +- packages/perseus/src/widgets/number-line.tsx | 22 +- .../perseus/src/widgets/numeric-input.tsx | 22 +- packages/perseus/src/widgets/orderer.tsx | 76 +++--- .../src/widgets/passage-ref-target.tsx | 2 +- packages/perseus/src/widgets/passage-ref.tsx | 6 +- packages/perseus/src/widgets/passage.tsx | 22 +- .../__tests__/passage-markdown.test.ts | 2 +- .../src/widgets/passage/passage-markdown.tsx | 8 +- packages/perseus/src/widgets/plotter.tsx | 18 +- packages/perseus/src/widgets/radio.ts | 2 +- .../perseus/src/widgets/radio/base-radio.tsx | 22 +- .../widgets/radio/choice-icon/choice-icon.tsx | 4 +- packages/perseus/src/widgets/radio/choice.tsx | 2 +- .../src/widgets/radio/option-status.tsx | 2 +- packages/perseus/src/widgets/radio/widget.tsx | 12 +- .../perseus/src/widgets/reaction-diagram.tsx | 16 +- packages/perseus/src/widgets/sequence.tsx | 2 +- packages/perseus/src/widgets/simulator.tsx | 28 +-- packages/perseus/src/widgets/sorter.tsx | 8 +- packages/perseus/src/widgets/table.tsx | 16 +- packages/perseus/src/widgets/transformer.tsx | 184 +++++++------- packages/perseus/src/widgets/unit.tsx | 34 +-- .../widgets/video-transcript-link.test.tsx | 6 +- .../src/widgets/video-transcript-link.tsx | 2 +- packages/perseus/src/widgets/video.tsx | 2 +- packages/perseus/src/zoom.ts | 44 ++-- packages/pure-markdown/src/index.ts | 6 +- .../src/__tests__/simple-markdown.test.ts | 10 +- packages/simple-markdown/src/index.ts | 44 ++-- testing/item-renderer-with-debug-ui.tsx | 2 +- testing/multi-item-renderer-with-debug-ui.tsx | 2 +- testing/renderer-with-debug-ui.tsx | 2 +- testing/side-by-side.tsx | 2 +- testing/test-dependencies.tsx | 2 +- testing/wait.ts | 2 +- 236 files changed, 1998 insertions(+), 1996 deletions(-) create mode 100644 .changeset/poor-suns-mate.md diff --git a/.changeset/poor-suns-mate.md b/.changeset/poor-suns-mate.md new file mode 100644 index 0000000000..a845151cc8 --- /dev/null +++ b/.changeset/poor-suns-mate.md @@ -0,0 +1,2 @@ +--- +--- diff --git a/config/cypress/support.js b/config/cypress/support.js index f4c0e3e76e..fbdce7866a 100644 --- a/config/cypress/support.js +++ b/config/cypress/support.js @@ -22,5 +22,5 @@ const dragTo = (node, pos) => { .trigger("mouseup", {force: true}) .trigger("mouseout", {force: true}); }; -// @ts-expect-error [FEI-5003] - TS2769 - No overload matches this call. +// @ts-expect-error - TS2769 - No overload matches this call. Cypress.Commands.add("dragTo", {prevSubject: true}, dragTo); diff --git a/config/test/test-setup.ts b/config/test/test-setup.ts index 4f0c98dff0..1938c8af45 100644 --- a/config/test/test-setup.ts +++ b/config/test/test-setup.ts @@ -4,7 +4,7 @@ */ import MutationObserver from "@sheerun/mutationobserver-shim"; import {configure} from "@testing-library/dom"; // eslint-disable-line testing-library/no-dom-import, prettier/prettier -// @ts-expect-error [FEI-5003] - TS2305 - Module '"aphrodite"' has no exported member 'StyleSheetTestUtils'. +// @ts-expect-error - TS2305 - Module '"aphrodite"' has no exported member 'StyleSheetTestUtils'. import {StyleSheetTestUtils} from "aphrodite"; import Enzyme from "enzyme"; // eslint-disable-line no-restricted-imports import React16EnzymeAdapter from "enzyme-adapter-react-16"; // eslint-disable-line no-restricted-imports @@ -27,7 +27,7 @@ configure({ }); if (typeof window !== "undefined") { - // @ts-expect-error [FEI-5003] - TS2322 - Type '() => { removeAllRanges: () => void; }' is not assignable to type '(() => Selection | null) & (() => Selection | null)'. + // @ts-expect-error - TS2322 - Type '() => { removeAllRanges: () => void; }' is not assignable to type '(() => Selection | null) & (() => Selection | null)'. window.getSelection = () => { return { removeAllRanges: () => {}, @@ -46,7 +46,7 @@ if (typeof window !== "undefined") { // redirecting to the right place. /* eslint-disable no-restricted-syntax */ const oldLocation = window.location; - // @ts-expect-error [FEI-5003] - TS2790 - The operand of a 'delete' operator must be optional. + // @ts-expect-error - TS2790 - The operand of a 'delete' operator must be optional. delete window.location; const mockedLocation = new URL("http://localhost:8081"); window.location = { @@ -63,7 +63,7 @@ if (typeof window !== "undefined") { // Override window.alert which doesn't exist in node and log any // alerts to the console instead. - // @ts-expect-error [FEI-5003] - TS2790 - The operand of a 'delete' operator must be optional. + // @ts-expect-error - TS2790 - The operand of a 'delete' operator must be optional. delete window.alert; window.alert = function (message: any) { // eslint-disable-next-line no-console @@ -132,7 +132,7 @@ const reportUnhandledConsoleWarnAndErrors = ( // custom handling. if (process.env.GLOBAL_CONSOLE_MOCK !== "false") { globalThis.console.error = (...args) => { - // @ts-expect-error [FEI-5003] - TS2556 - A spread argument must either have a tuple type or be passed to a rest parameter. + // @ts-expect-error - TS2556 - A spread argument must either have a tuple type or be passed to a rest parameter. reportUnhandledConsoleWarnAndErrors("error", ...args); }; globalThis.console.warn = (...args) => { @@ -182,7 +182,7 @@ if (process.env.GLOBAL_CONSOLE_MOCK !== "false") { !isReactUnsafe(message, args[1]) || isReportableReactUnsafe(message, args[1]) ) { - // @ts-expect-error [FEI-5003] - TS2556 - A spread argument must either have a tuple type or be passed to a rest parameter. + // @ts-expect-error - TS2556 - A spread argument must either have a tuple type or be passed to a rest parameter. reportUnhandledConsoleWarnAndErrors("warn", ...args); } }; diff --git a/packages/kmath/src/vector.ts b/packages/kmath/src/vector.ts index cf8a721f55..2c01f834da 100644 --- a/packages/kmath/src/vector.ts +++ b/packages/kmath/src/vector.ts @@ -57,17 +57,17 @@ export function dot(a: Vector, b: Vector): number { */ export function add(...vecs: ReadonlyArray): V { const zipped = _.zip(...vecs); - // @ts-expect-error [FEI-5003] - TS2322 - Type 'number[]' is not assignable to type 'V'. + // @ts-expect-error - TS2322 - Type 'number[]' is not assignable to type 'V'. return zipped.map(arraySum); } export function subtract(v1: V, v2: V): V { - // @ts-expect-error [FEI-5003] - TS2322 - Type 'number[]' is not assignable to type 'V'. + // @ts-expect-error - TS2322 - Type 'number[]' is not assignable to type 'V'. return _.zip(v1, v2).map((dim) => dim[0] - dim[1]); } export function negate(v: V): V { - // @ts-expect-error [FEI-5003] - TS2322 - Type 'number[]' is not assignable to type 'V'. + // @ts-expect-error - TS2322 - Type 'number[]' is not assignable to type 'V'. return v.map((x) => { return -x; }); @@ -75,7 +75,7 @@ export function negate(v: V): V { // Scale a vector export function scale(v1: V, scalar: number): V { - // @ts-expect-error [FEI-5003] - TS2322 - Type 'number[]' is not assignable to type 'V'. + // @ts-expect-error - TS2322 - Type 'number[]' is not assignable to type 'V'. return v1.map((x) => { return x * scalar; }); @@ -204,27 +204,27 @@ export function projection(v1: V, v2: V): V { // Round each number to a certain number of decimal places export function round(vec: V, precision: V | number): V { - // @ts-expect-error [FEI-5003] - TS2322 - Type 'number[]' is not assignable to type 'V'. + // @ts-expect-error - TS2322 - Type 'number[]' is not assignable to type 'V'. return vec.map((elem, i) => knumber.round(elem, precision[i] || precision)); } // Round each number to the nearest increment export function roundTo(vec: V, increment: V | number): V { - // @ts-expect-error [FEI-5003] - TS2322 - Type 'number[]' is not assignable to type 'V'. + // @ts-expect-error - TS2322 - Type 'number[]' is not assignable to type 'V'. return vec.map((elem, i) => knumber.roundTo(elem, increment[i] || increment), ); } export function floorTo(vec: V, increment: V | number): V { - // @ts-expect-error [FEI-5003] - TS2322 - Type 'number[]' is not assignable to type 'V'. + // @ts-expect-error - TS2322 - Type 'number[]' is not assignable to type 'V'. return vec.map((elem, i) => knumber.floorTo(elem, increment[i] || increment), ); } export function ceilTo(vec: V, increment: V | number): V { - // @ts-expect-error [FEI-5003] - TS2322 - Type 'number[]' is not assignable to type 'V'. + // @ts-expect-error - TS2322 - Type 'number[]' is not assignable to type 'V'. return vec.map((elem, i) => knumber.ceilTo(elem, increment[i] || increment), ); diff --git a/packages/math-input/src/components/input/math-input.tsx b/packages/math-input/src/components/input/math-input.tsx index 99616393b3..edc68b8f06 100644 --- a/packages/math-input/src/components/input/math-input.tsx +++ b/packages/math-input/src/components/input/math-input.tsx @@ -54,18 +54,18 @@ class MathInput extends React.Component { didTouchOutside: boolean | null | undefined; didScroll: boolean | null | undefined; mathField: any; - // @ts-expect-error [FEI-5003] - TS2564 - Property 'recordTouchStartOutside' has no initializer and is not definitely assigned in the constructor. + // @ts-expect-error - TS2564 - Property 'recordTouchStartOutside' has no initializer and is not definitely assigned in the constructor. recordTouchStartOutside: (arg1: any) => void; - // @ts-expect-error [FEI-5003] - TS2564 - Property 'blurOnTouchEndOutside' has no initializer and is not definitely assigned in the constructor. + // @ts-expect-error - TS2564 - Property 'blurOnTouchEndOutside' has no initializer and is not definitely assigned in the constructor. blurOnTouchEndOutside: (arg1: any) => void; dragListener: any; inputRef: HTMLDivElement | null | undefined; _isMounted: boolean | null | undefined; _mathContainer: any; - // @ts-expect-error [FEI-5003] - TS2564 - Property '_container' has no initializer and is not definitely assigned in the constructor. + // @ts-expect-error - TS2564 - Property '_container' has no initializer and is not definitely assigned in the constructor. _container: HTMLDivElement; _root: any; - // @ts-expect-error [FEI-5003] - TS2564 - Property '_containerBounds' has no initializer and is not definitely assigned in the constructor. + // @ts-expect-error - TS2564 - Property '_containerBounds' has no initializer and is not definitely assigned in the constructor. _containerBounds: ClientRect; _keypadBounds: ClientRect | null | undefined; @@ -235,11 +235,11 @@ class MathInput extends React.Component { window.removeEventListener("touchstart", this.recordTouchStartOutside); window.removeEventListener("touchend", this.blurOnTouchEndOutside); window.removeEventListener("touchcancel", this.blurOnTouchEndOutside); - // @ts-expect-error [FEI-5003] - TS2769 - No overload matches this call. + // @ts-expect-error - TS2769 - No overload matches this call. window.removeEventListener("resize", this._clearKeypadBoundsCache()); window.removeEventListener( "orientationchange", - // @ts-expect-error [FEI-5003] - TS2769 - No overload matches this call. + // @ts-expect-error - TS2769 - No overload matches this call. this._clearKeypadBoundsCache(), ); } @@ -430,7 +430,7 @@ class MathInput extends React.Component { ]; const elements = points - // @ts-expect-error [FEI-5003] - TS2556 - A spread argument must either have a tuple type or be passed to a rest parameter. + // @ts-expect-error - TS2556 - A spread argument must either have a tuple type or be passed to a rest parameter. .map((point) => document.elementFromPoint(...point)) // We exclude the root container itself and any nodes marked // as non-leaf which are fractions, parens, and roots. The @@ -468,16 +468,16 @@ class MathInput extends React.Component { const elementsById: Record = {}; for (const element of elements) { - // @ts-expect-error [FEI-5003] - TS2531 - Object is possibly 'null'. + // @ts-expect-error - TS2531 - Object is possibly 'null'. const id = element.getAttribute("mathquill-command-id"); if (id != null) { - // @ts-expect-error [FEI-5003] - TS2345 - Argument of type 'Element | null' is not assignable to parameter of type 'HTMLElement | null'. + // @ts-expect-error - TS2345 - Argument of type 'Element | null' is not assignable to parameter of type 'HTMLElement | null'. leafElements.push(element); counts[id] = (counts[id] || 0) + 1; elementsById[id] = element; } else { - // @ts-expect-error [FEI-5003] - TS2345 - Argument of type 'Element | null' is not assignable to parameter of type 'HTMLElement | null'. + // @ts-expect-error - TS2345 - Argument of type 'Element | null' is not assignable to parameter of type 'HTMLElement | null'. nonLeafElements.push(element); } } @@ -506,7 +506,7 @@ class MathInput extends React.Component { // hit count in the situation should not have serious effects on // the overall accuracy of the algorithm. if (hitNode == null && nonLeafElements.length > 0) { - // @ts-expect-error [FEI-5003] - TS2322 - Type 'HTMLElement | null' is not assignable to type 'null'. + // @ts-expect-error - TS2322 - Type 'HTMLElement | null' is not assignable to type 'null'. hitNode = nonLeafElements[0]; } @@ -908,7 +908,7 @@ class MathInput extends React.Component { overrides.css. */}
{ this.inputRef = node; diff --git a/packages/math-input/src/components/keypad-context.ts b/packages/math-input/src/components/keypad-context.ts index f2309511ad..c06083bc38 100644 --- a/packages/math-input/src/components/keypad-context.ts +++ b/packages/math-input/src/components/keypad-context.ts @@ -21,7 +21,7 @@ type KeypadContext = { scrollableElement: HTMLElement | null | undefined; }; -// @ts-expect-error [FEI-5003] - TS2322 - Type 'Context<{ setKeypadElement: (keypadElement: HTMLElement | null | undefined) => void; keypadElement: null; setRenderer: (renderer: RendererInterface | null | undefined) => void; renderer: null; setScrollableElement: (scrollableElement: HTMLElement | ... 1 more ... | undefined) => void; scrollableElement: null; }>' is not assignable to type 'Context'. +// @ts-expect-error - TS2322 - Type 'Context<{ setKeypadElement: (keypadElement: HTMLElement | null | undefined) => void; keypadElement: null; setRenderer: (renderer: RendererInterface | null | undefined) => void; renderer: null; setScrollableElement: (scrollableElement: HTMLElement | ... 1 more ... | undefined) => void; scrollableElement: null; }>' is not assignable to type 'Context'. const context: React.Context = React.createContext({ setKeypadElement: (keypadElement) => {}, keypadElement: null, diff --git a/packages/perseus-editor/src/__tests__/i18n.test.ts b/packages/perseus-editor/src/__tests__/i18n.test.ts index 4c5d6fe432..6fe5bca080 100644 --- a/packages/perseus-editor/src/__tests__/i18n.test.ts +++ b/packages/perseus-editor/src/__tests__/i18n.test.ts @@ -449,7 +449,7 @@ const exerciseImagesEverywhere = { // from exerciseImagesEverywhere, but include the question and hints as if they // were paragraphs in the article. const articleImagesEverywhere = [exerciseImagesEverywhere.question].concat( - // @ts-expect-error [FEI-5003] - TS2769 - No overload matches this call. + // @ts-expect-error - TS2769 - No overload matches this call. exerciseImagesEverywhere.hints, ); diff --git a/packages/perseus-editor/src/article-editor.tsx b/packages/perseus-editor/src/article-editor.tsx index 7bc9405861..e2282ea05c 100644 --- a/packages/perseus-editor/src/article-editor.tsx +++ b/packages/perseus-editor/src/article-editor.tsx @@ -77,7 +77,7 @@ export default class ArticleEditor extends React.Component { _updatePreviewFrames() { if (this.props.mode === "preview") { // eslint-disable-next-line react/no-string-refs - // @ts-expect-error [FEI-5003] - TS2339 - Property 'sendNewData' does not exist on type 'ReactInstance'. + // @ts-expect-error - TS2339 - Property 'sendNewData' does not exist on type 'ReactInstance'. this.refs["frame-all"].sendNewData({ type: "article-all", data: this._sections().map((section, i) => { @@ -87,7 +87,7 @@ export default class ArticleEditor extends React.Component { } else if (this.props.mode === "edit") { this._sections().forEach((section, i) => { // eslint-disable-next-line react/no-string-refs - // @ts-expect-error [FEI-5003] - TS2339 - Property 'sendNewData' does not exist on type 'ReactInstance'. + // @ts-expect-error - TS2339 - Property 'sendNewData' does not exist on type 'ReactInstance'. this.refs["frame-" + i].sendNewData({ type: "article", data: this._apiOptionsForSection(section, i), @@ -116,7 +116,7 @@ export default class ArticleEditor extends React.Component { highlightLint: this.state.highlightLint, paths: this.props.contentPaths, }, - // @ts-expect-error [FEI-5003] - TS2339 - Property 'getSaveWarnings' does not exist on type 'ReactInstance'. + // @ts-expect-error - TS2339 - Property 'getSaveWarnings' does not exist on type 'ReactInstance'. legacyPerseusLint: editor ? editor.getSaveWarnings() : [], }; } @@ -303,7 +303,7 @@ export default class ArticleEditor extends React.Component { newProps, ) => { const sections = _.clone(this._sections()); - // @ts-expect-error [FEI-5003] - TS2542 - Index signature in type 'readonly RendererProps[]' only permits reading. + // @ts-expect-error - TS2542 - Index signature in type 'readonly RendererProps[]' only permits reading. sections[i] = _.extend({}, sections[i], newProps); this.props.onChange({json: sections}); }; @@ -314,9 +314,9 @@ export default class ArticleEditor extends React.Component { } const sections = _.clone(this._sections()); const section = sections[i]; - // @ts-expect-error [FEI-5003] - TS2551 - Property 'splice' does not exist on type 'readonly RendererProps[]'. Did you mean 'slice'? + // @ts-expect-error - TS2551 - Property 'splice' does not exist on type 'readonly RendererProps[]'. Did you mean 'slice'? sections.splice(i, 1); - // @ts-expect-error [FEI-5003] - TS2551 - Property 'splice' does not exist on type 'readonly RendererProps[]'. Did you mean 'slice'? + // @ts-expect-error - TS2551 - Property 'splice' does not exist on type 'readonly RendererProps[]'. Did you mean 'slice'? sections.splice(i - 1, 0, section); this.props.onChange({ json: sections, @@ -329,9 +329,9 @@ export default class ArticleEditor extends React.Component { return; } const section = sections[i]; - // @ts-expect-error [FEI-5003] - TS2551 - Property 'splice' does not exist on type 'readonly RendererProps[]'. Did you mean 'slice'? + // @ts-expect-error - TS2551 - Property 'splice' does not exist on type 'readonly RendererProps[]'. Did you mean 'slice'? sections.splice(i, 1); - // @ts-expect-error [FEI-5003] - TS2551 - Property 'splice' does not exist on type 'readonly RendererProps[]'. Did you mean 'slice'? + // @ts-expect-error - TS2551 - Property 'splice' does not exist on type 'readonly RendererProps[]'. Did you mean 'slice'? sections.splice(i + 1, 0, section); this.props.onChange({ json: sections, @@ -354,7 +354,7 @@ export default class ArticleEditor extends React.Component { widgets: sections[i].widgets, } : {}; - // @ts-expect-error [FEI-5003] - TS2339 - Property 'splice' does not exist on type 'JsonType'. + // @ts-expect-error - TS2339 - Property 'splice' does not exist on type 'JsonType'. sections.splice(i + 1, 0, newSection); this.props.onChange({ json: sections, @@ -363,7 +363,7 @@ export default class ArticleEditor extends React.Component { _handleRemoveSection(i: number) { const sections = _.clone(this._sections()); - // @ts-expect-error [FEI-5003] - TS2551 - Property 'splice' does not exist on type 'readonly RendererProps[]'. Did you mean 'slice'? + // @ts-expect-error - TS2551 - Property 'splice' does not exist on type 'readonly RendererProps[]'. Did you mean 'slice'? sections.splice(i, 1); this.props.onChange({ json: sections, @@ -374,7 +374,7 @@ export default class ArticleEditor extends React.Component { if (this.props.mode === "edit") { return this._sections().map((section, i) => { // eslint-disable-next-line react/no-string-refs - // @ts-expect-error [FEI-5003] - TS2339 - Property 'serialize' does not exist on type 'ReactInstance'. + // @ts-expect-error - TS2339 - Property 'serialize' does not exist on type 'ReactInstance'. return this.refs["editor" + i].serialize(); }); } @@ -405,7 +405,7 @@ export default class ArticleEditor extends React.Component { return this._sections().map((section, i) => { // eslint-disable-next-line react/no-string-refs - // @ts-expect-error [FEI-5003] - TS2339 - Property 'getSaveWarnings' does not exist on type 'ReactInstance'. + // @ts-expect-error - TS2339 - Property 'getSaveWarnings' does not exist on type 'ReactInstance'. return this.refs["editor" + i].getSaveWarnings(); }); } diff --git a/packages/perseus-editor/src/components/checkbox.tsx b/packages/perseus-editor/src/components/checkbox.tsx index 0e4a8e96bb..5eaed1e833 100644 --- a/packages/perseus-editor/src/components/checkbox.tsx +++ b/packages/perseus-editor/src/components/checkbox.tsx @@ -131,7 +131,7 @@ export default class Checkbox extends React.Component { )} disabled={disabled} onChange={onChange} - // @ts-expect-error [FEI-5003] - TS2322 - Type 'string | number | undefined' is not assignable to type 'number | undefined'. + // @ts-expect-error - TS2322 - Type 'string | number | undefined' is not assignable to type 'number | undefined'. tabIndex={tabIndex} />
diff --git a/packages/perseus-editor/src/components/dropdown-option.tsx b/packages/perseus-editor/src/components/dropdown-option.tsx index b6facea2c2..e3fe0334a5 100644 --- a/packages/perseus-editor/src/components/dropdown-option.tsx +++ b/packages/perseus-editor/src/components/dropdown-option.tsx @@ -26,7 +26,7 @@ const findAndFocusElement = (component?: Element | null) => { const DOMNode: Element | Text | null | undefined = ReactDOM.findDOMNode(component); const button = DOMNode as HTMLInputElement; - // @ts-expect-error [FEI-5003] - TS2774 - This condition will always return true since this function is always defined. Did you mean to call it instead? + // @ts-expect-error - TS2774 - This condition will always return true since this function is always defined. Did you mean to call it instead? if (button.focus) { focusWithChromeStickyFocusBugWorkaround(button); } @@ -67,7 +67,7 @@ const check = `M10,3.8C10,4,9.9,4.2,9.8,4.3L5.1,8.9L4.3,9.8C4.2,9.9,4,10,3.8,10 export const optionHeight = 30; class Option extends React.Component { - // @ts-expect-error [FEI-5003] - TS2564 - Property 'node' has no initializer and is not definitely assigned in the constructor. + // @ts-expect-error - TS2564 - Property 'node' has no initializer and is not definitely assigned in the constructor. node: HTMLDivElement; handleKeyDown(event: any): void { @@ -114,7 +114,7 @@ class Option extends React.Component { return ( ); } else { - // @ts-expect-error [FEI-5003] - TS2322 - Type 'Element' is not assignable to type 'null'. + // @ts-expect-error - TS2322 - Type 'Element' is not assignable to type 'null'. removeButton = (