From 811f914cbded3a9a3af1c08cc6aa79cadb1dbb23 Mon Sep 17 00:00:00 2001 From: Matthew Date: Thu, 22 Aug 2024 09:53:29 -0500 Subject: [PATCH] Make a SharedRendererProps type (#1530) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary: I don't know how useful this is, but this is my motivation: https://github.com/Khan/webapp/pull/24684 ## Test plan: Nothing should change but types Author: handeyeco Reviewers: jeremywiebe Required Reviewers: Approved By: jeremywiebe Checks: ✅ codecov/project, ✅ codecov/patch, ✅ Upload Coverage (ubuntu-latest, 20.x), ✅ Publish npm snapshot (ubuntu-latest, 20.x), ✅ Lint, Typecheck, Format, and Test (ubuntu-latest, 20.x), ✅ Cypress (ubuntu-latest, 20.x), ✅ Check builds for changes in size (ubuntu-latest, 20.x), ✅ Check for .changeset entries for all changed files (ubuntu-latest, 20.x), ✅ Publish Storybook to Chromatic (ubuntu-latest, 20.x), ✅ Jest Coverage (ubuntu-latest, 20.x), ✅ gerald Pull Request URL: https://github.com/Khan/perseus/pull/1530 --- .changeset/stupid-parrots-chew.md | 5 ++++ packages/perseus/src/article-renderer.tsx | 30 +++++++++---------- packages/perseus/src/hint-renderer.tsx | 7 ++--- packages/perseus/src/index.ts | 1 + packages/perseus/src/server-item-renderer.tsx | 11 +++---- packages/perseus/src/types.ts | 5 ++++ 6 files changed, 33 insertions(+), 26 deletions(-) create mode 100644 .changeset/stupid-parrots-chew.md diff --git a/.changeset/stupid-parrots-chew.md b/.changeset/stupid-parrots-chew.md new file mode 100644 index 0000000000..3624a4e533 --- /dev/null +++ b/.changeset/stupid-parrots-chew.md @@ -0,0 +1,5 @@ +--- +"@khanacademy/perseus": patch +--- + +Add SharedRendererProps type diff --git a/packages/perseus/src/article-renderer.tsx b/packages/perseus/src/article-renderer.tsx index de7ed70531..a01b90ef50 100644 --- a/packages/perseus/src/article-renderer.tsx +++ b/packages/perseus/src/article-renderer.tsx @@ -15,24 +15,22 @@ import Renderer from "./renderer"; import Util from "./util"; import type {PerseusRenderer} from "./perseus-types"; -import type {APIOptions, PerseusDependenciesV2} from "./types"; +import type {PerseusDependenciesV2, SharedRendererProps} from "./types"; import type {KeypadAPI} from "@khanacademy/math-input"; import type {KeypadContextRendererInterface} from "@khanacademy/perseus-core"; -import type {LinterContextProps} from "@khanacademy/perseus-linter"; - -type Props = Partial> & { - apiOptions: APIOptions; - json: PerseusRenderer | ReadonlyArray; - // Whether to use the new Bibliotron styles for articles - /** - * @deprecated Does nothing - */ - useNewStyles: boolean; - linterContext: LinterContextProps; - legacyPerseusLint?: ReadonlyArray; - keypadElement?: KeypadAPI | null | undefined; - dependencies: PerseusDependenciesV2; -}; + +type Props = Partial> & + SharedRendererProps & { + json: PerseusRenderer | ReadonlyArray; + // Whether to use the new Bibliotron styles for articles + /** + * @deprecated Does nothing + */ + useNewStyles: boolean; + legacyPerseusLint?: ReadonlyArray; + keypadElement?: KeypadAPI | null | undefined; + dependencies: PerseusDependenciesV2; + }; type DefaultProps = { apiOptions: Props["apiOptions"]; diff --git a/packages/perseus/src/hint-renderer.tsx b/packages/perseus/src/hint-renderer.tsx index 9de03b58e4..ad98597dc1 100644 --- a/packages/perseus/src/hint-renderer.tsx +++ b/packages/perseus/src/hint-renderer.tsx @@ -8,11 +8,9 @@ import Renderer from "./renderer"; import {baseUnitPx, hintBorderWidth, kaGreen, gray97} from "./styles/constants"; import mediaQueries from "./styles/media-queries"; -import type {APIOptions} from "./types"; -import type {LinterContextProps} from "@khanacademy/perseus-linter"; +import type {SharedRendererProps} from "./types"; -type Props = { - apiOptions: APIOptions; +type Props = SharedRendererProps & { className?: string; hint: any; lastHint?: boolean; @@ -20,7 +18,6 @@ type Props = { pos: number; totalHints?: number; findExternalWidgets?: any; - linterContext: LinterContextProps; }; type DefaultProps = { diff --git a/packages/perseus/src/index.ts b/packages/perseus/src/index.ts index cbf17c1f44..9bdf3385b4 100644 --- a/packages/perseus/src/index.ts +++ b/packages/perseus/src/index.ts @@ -164,6 +164,7 @@ export type { VideoKind, WidgetDict, WidgetExports, + SharedRendererProps, } from "./types"; export type {ParsedValue} from "./util"; export type { diff --git a/packages/perseus/src/server-item-renderer.tsx b/packages/perseus/src/server-item-renderer.tsx index 2a7f56024f..9a902817c5 100644 --- a/packages/perseus/src/server-item-renderer.tsx +++ b/packages/perseus/src/server-item-renderer.tsx @@ -23,23 +23,24 @@ import Renderer from "./renderer"; import Util from "./util"; import type {PerseusItem, ShowSolutions} from "./perseus-types"; -import type {APIOptions, FocusPath, PerseusDependenciesV2} from "./types"; +import type { + FocusPath, + PerseusDependenciesV2, + SharedRendererProps, +} from "./types"; import type {KeypadAPI} from "@khanacademy/math-input"; import type { KeypadContextRendererInterface, RendererInterface, KEScore, } from "@khanacademy/perseus-core"; -import type {LinterContextProps} from "@khanacademy/perseus-linter"; import type {PropsFor} from "@khanacademy/wonder-blocks-core"; const {mapObject} = Objective; type OwnProps = { - apiOptions: APIOptions; hintsVisible?: number; item: PerseusItem; - linterContext: LinterContextProps; problemNum?: number; reviewMode?: boolean; keypadElement?: KeypadAPI | null | undefined; @@ -51,7 +52,7 @@ type HOCProps = { onRendered: (isRendered: boolean) => void; }; -type Props = OwnProps & HOCProps; +type Props = SharedRendererProps & OwnProps & HOCProps; type DefaultProps = Required< Pick diff --git a/packages/perseus/src/types.ts b/packages/perseus/src/types.ts index 9d857eca8f..0e674b6802 100644 --- a/packages/perseus/src/types.ts +++ b/packages/perseus/src/types.ts @@ -610,3 +610,8 @@ export type ChangeFn = ( propValue?: any, callback?: () => unknown, ) => any | null | undefined; + +export type SharedRendererProps = { + apiOptions: APIOptions; + linterContext: LinterContextProps; +};