@khanacademy/perseus 40.0.0 → 41.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/dist/components/hud.d.ts +4 -0
  2. package/dist/components/i18n-context.d.ts +4 -0
  3. package/dist/components/icon.d.ts +28 -27
  4. package/dist/components/image-loader.d.ts +9 -9
  5. package/dist/components/inline-icon.d.ts +6 -9
  6. package/dist/components/lint.d.ts +13 -0
  7. package/dist/components/math-input.d.ts +2 -2
  8. package/dist/components/multi-button-group.d.ts +26 -0
  9. package/dist/components/number-input.d.ts +19 -0
  10. package/dist/components/range-input.d.ts +3 -0
  11. package/dist/components/stub-tag-editor.d.ts +2 -2
  12. package/dist/components/svg-image.d.ts +30 -0
  13. package/dist/components/tooltip.d.ts +41 -30
  14. package/dist/es/index.css +6 -0
  15. package/dist/es/index.js +1034 -819
  16. package/dist/es/index.js.map +1 -1
  17. package/dist/es/strings.js +16 -2
  18. package/dist/es/strings.js.map +1 -1
  19. package/dist/icon-paths.d.ts +1 -5
  20. package/dist/index.css +6 -0
  21. package/dist/index.js +1062 -834
  22. package/dist/index.js.map +1 -1
  23. package/dist/strings.d.ts +8 -0
  24. package/dist/strings.js +22 -2
  25. package/dist/strings.js.map +1 -1
  26. package/dist/types.d.ts +5 -5
  27. package/dist/widgets/expression/expression.d.ts +4 -4
  28. package/dist/widgets/interactive-graphs/graphs/angle.d.ts +2 -5
  29. package/dist/widgets/interactive-graphs/graphs/circle.d.ts +2 -5
  30. package/dist/widgets/interactive-graphs/graphs/linear-system.d.ts +2 -5
  31. package/dist/widgets/interactive-graphs/graphs/linear.d.ts +2 -5
  32. package/dist/widgets/interactive-graphs/graphs/point.d.ts +7 -5
  33. package/dist/widgets/interactive-graphs/graphs/polygon.d.ts +2 -7
  34. package/dist/widgets/interactive-graphs/graphs/quadratic.d.ts +2 -4
  35. package/dist/widgets/interactive-graphs/graphs/ray.d.ts +2 -5
  36. package/dist/widgets/interactive-graphs/graphs/screenreader-text.d.ts +1 -0
  37. package/dist/widgets/interactive-graphs/graphs/segment.d.ts +2 -5
  38. package/dist/widgets/interactive-graphs/graphs/sinusoid.d.ts +2 -5
  39. package/dist/widgets/interactive-graphs/mafs-graph.d.ts +1 -1
  40. package/dist/widgets/interactive-graphs/types.d.ts +7 -2
  41. package/dist/widgets/label-image/label-image.d.ts +2 -2
  42. package/package.json +2 -2
  43. package/dist/widgets/interactive-graphs/graphs/index.d.ts +0 -9
@@ -5,5 +5,9 @@ type Props = {
5
5
  onClick: () => void;
6
6
  fixedPosition?: boolean;
7
7
  };
8
+ /**
9
+ * A "heads-up display" (HUD) indicator that includes a short message (usually
10
+ * used for linting errors). The indicator can be disabled.
11
+ */
8
12
  declare const HUD: ({ message, enabled, onClick, fixedPosition }: Props) => React.JSX.Element;
9
13
  export default HUD;
@@ -9,6 +9,10 @@ type I18nContextType = {
9
9
  strings: PerseusStrings;
10
10
  locale: string;
11
11
  };
12
+ export declare const mockPerseusI18nContext: {
13
+ strings: PerseusStrings;
14
+ locale: string;
15
+ };
12
16
  export declare const PerseusI18nContext: React.Context<I18nContextType>;
13
17
  type Props = React.PropsWithChildren<I18nContextType>;
14
18
  export declare function PerseusI18nContextProvider({ children, strings, locale }: Props): React.JSX.Element;
@@ -1,5 +1,25 @@
1
+ /// <reference path="../../types/aphrodite.d.ts" />
2
+ import * as React from "react";
3
+ import type { CSSProperties } from "aphrodite";
4
+ export type IconType = {
5
+ height: number;
6
+ path: string;
7
+ width: number;
8
+ };
9
+ type Props = {
10
+ className?: string;
11
+ style?: CSSProperties;
12
+ title?: string;
13
+ color: string;
14
+ focusable?: boolean;
15
+ icon: // If you pass in a string then it's assumed to be just an SVG
16
+ IconType | string;
17
+ pathClassName?: string;
18
+ size?: number;
19
+ alt?: string;
20
+ };
1
21
  /**
2
- * SVG Icon React Component
22
+ * An SVG Icon
3
23
  *
4
24
  * This component is designed to take in SVG paths and render icons based upon
5
25
  * them. If you are looking for an icon that we've used before you should look
@@ -10,44 +30,25 @@
10
30
  *
11
31
  * Sample usage:
12
32
  *
13
- * const dropdownIcon = `M5,6L0,0L10,0`;
14
- * <Icon icon={dropdownIcon} />
33
+ * ```
34
+ * const dropdownIcon = `M5,6L0,0L10,0`;
35
+ * <Icon icon={dropdownIcon} />
36
+ * ```
15
37
  *
16
38
  * Or:
17
39
  *
40
+ * ```
18
41
  * const dropdownIcon = {
19
42
  * path: `M5,6L0,0L10,0`,
20
43
  * height: 10,
21
44
  * width: 10,
22
45
  * };
23
46
  * <Icon icon={dropdownIcon} size={20} />
24
- *
25
- * A full list of all the existing icons can be seen here:
26
- * http://localhost:8080/react-sandbox/shared-styles-package/icon.jsx.fixture.js
47
+ * ```
27
48
  *
28
49
  * If you want to add an entirely new icon please read the note inside
29
- * the `icon-paths.js` file.
50
+ * the `icon-paths.ts` file.
30
51
  */
31
- /// <reference path="../../types/aphrodite.d.ts" />
32
- import * as React from "react";
33
- import type { CSSProperties } from "aphrodite";
34
- export type IconType = {
35
- height: number;
36
- path: string;
37
- width: number;
38
- };
39
- type Props = {
40
- className?: string;
41
- style?: CSSProperties;
42
- title?: string;
43
- color: string;
44
- focusable?: boolean;
45
- icon: // If you pass in a string then it's assumed to be just an SVG
46
- IconType | string;
47
- pathClassName?: string;
48
- size?: number;
49
- alt?: string;
50
- };
51
52
  declare class Icon extends React.Component<Props> {
52
53
  static defaultProps: {
53
54
  color: string;
@@ -1,12 +1,3 @@
1
- /**
2
- * Component to display an image (or other React components) while the desired
3
- * image is loading.
4
- *
5
- * Derived from
6
- * https://github.com/hzdg/react-imageloader/blob/master/src/index.js
7
- * to better suit our environment/build tools. Additionally, this one does
8
- * not introduce a wrapper element, which makes styling easier.
9
- */
10
1
  import * as React from "react";
11
2
  import type { Dimensions } from "../types";
12
3
  declare const Status: {
@@ -35,6 +26,15 @@ type Props = {
35
26
  type State = {
36
27
  status: (typeof Status)[keyof typeof Status];
37
28
  };
29
+ /**
30
+ * Component to display an image (or other React components) while the desired
31
+ * image is loading.
32
+ *
33
+ * Derived from
34
+ * https://github.com/hzdg/react-imageloader/blob/master/src/index.js
35
+ * to better suit our environment/build tools. Additionally, this one does
36
+ * not introduce a wrapper element, which makes styling easier.
37
+ */
38
38
  declare class ImageLoader extends React.Component<Props, State> {
39
39
  img: HTMLImageElement | null | undefined;
40
40
  constructor(props: Props);
@@ -10,11 +10,7 @@ type InlineIconProps = {
10
10
  * A stripped version of Icon.jsx from webapp. Takes an SVG icon and renders it
11
11
  * inline like Font Awesome did.
12
12
  *
13
- * If you are looking for an icon that we've used before you should look in
14
- * webapp's `icon-paths.js` which is a reference file for all the SVG paths
15
- * that we've used. You'll need to copy the object from that file into
16
- * whichever file you're using the icon and explicitly pass it in to the
17
- * <InlineIcon/> React component.
13
+ * You can refer to `icon-paths.ts` for all available SVG icons.
18
14
  *
19
15
  * We assume that the viewBox is cropped and aligned to (0, 0), but icons can
20
16
  * be defined differently. At some point we might want to add these attributes
@@ -22,13 +18,14 @@ type InlineIconProps = {
22
18
  *
23
19
  * Sample usage:
24
20
  *
25
- * const editIcon = {
21
+ * ```
22
+ * const editIcon = {
26
23
  * path: "M41.209 53.753l5.39 0l0 5.39l3.136 0l6.468-6.517-8.477-8.526-6.517 6.517l0 3.136zm33.173-34.937q-.882-.882-1.862.049l-19.6 19.6q-.931.98-.049 1.862t1.862-.049l19.6-19.6q.931-.98.049-1.862zm-38.563 45.668l0-16.121l37.632-37.632 16.17 16.121-37.632 37.632l-16.17 0zm43.022-12.397l0 10.633q-.049 6.713-4.753 11.417t-11.368 4.704l-46.599 0q-6.713 0-11.417-4.753t-4.704-11.368l0-46.599q0-6.664 4.753-11.417t11.368-4.704l46.599 0q3.528 0 6.566 1.372.833.392.98 1.323t-.49 1.617l-2.744 2.744q-.784.784-1.96.441t-2.352-.343l-46.599 0q-3.675 0-6.321 2.646t-2.646 6.321l0 46.599q0 3.675 2.646 6.321t6.321 2.646l46.599 0q3.675 0 6.321-2.646t2.646-6.321l0-7.056q0-.735.49-1.225l3.577-3.577q.833-.833 1.96-.392t1.127 1.617zm7.203-51.646q2.254 0 3.773 1.568l8.526 8.526q1.568 1.568 1.568 3.822t-1.568 3.773l-5.145 5.145-16.121-16.121 5.145-5.145q1.568-1.568 3.822-1.568z",
27
24
  * width: 100,
28
25
  * height: 78.912,
29
- * };
30
- * <InlineIcon {...editIcon} />
31
- *
26
+ * };
27
+ * <InlineIcon {...editIcon} />
28
+ * ```
32
29
  */
33
30
  declare const InlineIcon: ({ path, width, height, style, title, }: InlineIconProps) => React.ReactElement;
34
31
  export default InlineIcon;
@@ -6,12 +6,25 @@ declare enum Severity {
6
6
  OfflineReportingOnly = 4
7
7
  }
8
8
  type Props = {
9
+ /** The children are the linty content we're highlighting */
9
10
  children: React.ReactNode;
11
+ /** Inline lint is highlighted differently than block lint. */
10
12
  inline?: boolean;
13
+ /** This is the text that appears in the tooltip */
11
14
  message: string;
15
+ /** This is used as the fragment id (hash) in the URL of the link */
12
16
  ruleName: string;
17
+ /** Lint warnings inside tables are handled specially */
13
18
  insideTable: boolean;
19
+ /**
20
+ * Should lint highlighting be rendered as a block to the left of
21
+ * the lint instead of on the right gutter?
22
+ */
14
23
  blockHighlight?: boolean;
24
+ /**
25
+ * How important this lint message is for the editor. Severity goes
26
+ * from 1 (indicating an error) to 4 (offline reporting only)
27
+ */
15
28
  severity?: Severity;
16
29
  };
17
30
  type State = {
@@ -2,8 +2,8 @@ import { CursorContext, MathInputI18nContext } from "@khanacademy/math-input";
2
2
  import * as React from "react";
3
3
  import { PerseusI18nContext } from "./i18n-context";
4
4
  import type { LegacyButtonSets } from "../perseus-types";
5
- import type { PerseusDependenciesV2 } from "../types";
6
5
  import type { Keys, MathFieldInterface } from "@khanacademy/math-input";
6
+ import type { AnalyticsEventHandlerFn } from "@khanacademy/perseus-core";
7
7
  type ButtonsVisibleType = "always" | "never" | "focused";
8
8
  type KeypadButtonSets = {
9
9
  advancedRelations?: boolean;
@@ -40,7 +40,7 @@ type Props = {
40
40
  * - `never` means that the keypad is **never shown**.
41
41
  */
42
42
  buttonsVisible?: ButtonsVisibleType;
43
- analytics: PerseusDependenciesV2["analytics"];
43
+ onAnalyticsEvent: AnalyticsEventHandlerFn;
44
44
  };
45
45
  type InnerProps = Props & {
46
46
  mathInputStrings: any;
@@ -1,12 +1,38 @@
1
1
  import * as React from "react";
2
2
  type Props = {
3
+ /**
4
+ * The initial values of the buttons selected, defaults to null (no
5
+ * selection).
6
+ */
3
7
  values: ReadonlyArray<any> | null | undefined;
8
+ /**
9
+ * The set of buttons to display in this MultiButtonGroup.
10
+ */
4
11
  buttons: ReadonlyArray<{
12
+ /**
13
+ * the value returned when the button is selected
14
+ */
5
15
  value: any;
16
+ /**
17
+ * The content shown within the button, typically a string that gets
18
+ * rendered as the button's display text.
19
+ */
6
20
  content: React.ReactNode;
21
+ /**
22
+ * The title-text shown on hover
23
+ */
7
24
  title?: string;
8
25
  }>;
26
+ /**
27
+ * A function that is provided with the updated set of selected value
28
+ * (which it then is responsible for updating)
29
+ */
9
30
  onChange: (values?: any) => unknown;
31
+ /**
32
+ * If false, at least one button must be selected at all times.
33
+ *
34
+ * Defaults to `true`
35
+ */
10
36
  allowEmpty?: boolean;
11
37
  };
12
38
  type DefaultProps = {
@@ -2,6 +2,25 @@ import PropTypes from "prop-types";
2
2
  import * as React from "react";
3
3
  import { PerseusI18nContext } from "./i18n-context";
4
4
  import type { MathFormat } from "../perseus-types";
5
+ /**
6
+ * An input box that accepts only numeric strings
7
+ *
8
+ * Calls `onChange(value, format)` for valid numbers.
9
+ *
10
+ * Reverts to the current value `onBlur` or on [ENTER],
11
+ * but maintains the format (i.e. 3/2, 1 1/2, 150%)
12
+ *
13
+ * Accepts empty input and sends it to `onChange` as `null` if no numeric
14
+ * placeholder is set.
15
+ *
16
+ * If given a `checkValidity` function, will turn the background/outline red
17
+ * when invalid.
18
+ *
19
+ * If `useArrowKeys` is set to `true`, up/down arrows will increment/decrement
20
+ * integers.
21
+ *
22
+ * Optionally takes a `size` (`"mini"`, `"small"`,` `"normal"`)
23
+ */
5
24
  declare class NumberInput extends React.Component<any, any> {
6
25
  static contextType: React.Context<{
7
26
  strings: import("../strings").PerseusStrings;
@@ -1,5 +1,8 @@
1
1
  import PropTypes from "prop-types";
2
2
  import * as React from "react";
3
+ /**
4
+ * A minor abstraction on top of `NumberInput` for ranges
5
+ */
3
6
  declare class RangeInput extends React.Component<any> {
4
7
  static propTypes: {
5
8
  value: PropTypes.Validator<any[]>;
@@ -1,3 +1,5 @@
1
+ import PropTypes from "prop-types";
2
+ import * as React from "react";
1
3
  /**
2
4
  * Stub Tag Editor.
3
5
  *
@@ -11,8 +13,6 @@
11
13
  * It also gives a nicer interface for the group metadata editor
12
14
  * in local demo mode.
13
15
  */
14
- import PropTypes from "prop-types";
15
- import * as React from "react";
16
16
  declare class StubTagEditor extends React.Component<any> {
17
17
  static propTypes: {
18
18
  value: PropTypes.Requireable<(string | null | undefined)[]>;
@@ -12,16 +12,46 @@ type Props = {
12
12
  labels: ReadonlyArray<any>;
13
13
  };
14
14
  height?: number;
15
+ /**
16
+ * When the DOM updates to replace the preloader with the image, or
17
+ * vice-versa, we trigger this callback.
18
+ */
15
19
  onUpdate: () => void;
20
+ /**
21
+ * If alt is provided, DO NOT set aria-hidden=true unless this override flag
22
+ * is set.
23
+ */
16
24
  overrideAriaHidden?: boolean;
17
25
  preloader?: (dimensions: Dimensions) => React.ReactNode;
26
+ /**
27
+ * By default, this component attempts to be responsive whenever
28
+ * possible (specifically, when width and height are passed in).
29
+ *
30
+ * You can expliclty force unresponsive behavior by *either*
31
+ * not passing in width/height *or* setting this prop to false.
32
+ *
33
+ * The difference is that forcing via this prop will result in
34
+ * explicit width and height styles being set on the rendered
35
+ * component.
36
+ */
18
37
  responsive: boolean;
19
38
  scale: number;
20
39
  src: string;
21
40
  title?: string;
22
41
  trackInteraction?: () => void;
23
42
  width?: number;
43
+ /**
44
+ * Whether clicking this image will allow it to be fully zoomed in to
45
+ * its original size on click, and allow the user to scroll in that
46
+ * state. This also does some hacky viewport meta tag changing to
47
+ * ensure this works on mobile devices, so I (david@) don't recommend
48
+ * enabling this on desktop yet.
49
+ */
24
50
  zoomToFullSizeOnMobile?: boolean;
51
+ /**
52
+ * If provided, use AssetContext.Consumer, see renderer.jsx.
53
+ * If not, it defaults to a no-op.
54
+ */
25
55
  setAssetStatus: (assetKey: string, loaded: boolean) => void;
26
56
  };
27
57
  type DefaultProps = {
@@ -1,33 +1,3 @@
1
- /**
2
- * A generic tooltip library for React.js
3
- *
4
- * This should eventually end up in react-components
5
- *
6
- * Interface: ({a, b} means one of a or b)
7
- * import Tooltip from "./tooltip";
8
- * <Tooltip
9
- * className="class-for-tooltip-contents"
10
- * horizontalPosition={HoriziontalDirection.Left}
11
- * horizontalAlign={HoriziontalDirection.Left}
12
- * verticalPosition={VerticalDirection.Top}
13
- * arrowSize={10} // arrow size in pixels
14
- * borderColor="#ccc" // color of the border for the tooltip
15
- * show={true} // whether the tooltip should currently be visible
16
- * targetContainerStyle={targetContainerStyle}
17
- * >
18
- * <TargetElementOfTheTooltip />
19
- * <TooltipContents1 />
20
- * <TooltipContents2 />
21
- * </Tooltip>
22
- *
23
- * To show/hide the tooltip, the parent component should call the
24
- * .show() and .hide() methods of the tooltip when appropriate.
25
- * (These are usually set up as handlers of events on the target element.)
26
- *
27
- * Notes:
28
- * className should not specify a border; that is handled by borderColor
29
- * so that the arrow and tooltip match
30
- */
31
1
  import * as React from "react";
32
2
  export declare enum HorizontalDirection {
33
3
  Left = "left",
@@ -60,6 +30,47 @@ type DefaultProps = {
60
30
  type State = {
61
31
  height: number | null;
62
32
  };
33
+ /**
34
+ * DEPRECATED! Use Wonder Blocks tooltip instead.
35
+ *
36
+ * A generic tooltip library for React.js
37
+ *
38
+ * ```
39
+ * import Tooltip from "./tooltip";
40
+ * <Tooltip
41
+ * className="class-for-tooltip-contents"
42
+ * horizontalPosition={HoriziontalDirection.Left}
43
+ * horizontalAlign={HoriziontalDirection.Left}
44
+ * verticalPosition={VerticalDirection.Top}
45
+ * arrowSize={10} // arrow size in pixels
46
+ * borderColor="#ccc" // color of the border for the tooltip
47
+ * show={true} // whether the tooltip should currently be visible
48
+ * targetContainerStyle={targetContainerStyle}
49
+ * >
50
+ * <TargetElementOfTheTooltip />
51
+ * <TooltipContents1 />
52
+ * <TooltipContents2 />
53
+ * </Tooltip>
54
+ * ```
55
+ *
56
+ * To show/hide the tooltip, the parent component should call the
57
+ * `.show()` and `.hide()` methods of the tooltip when appropriate.
58
+ * (These are usually set up as handlers of events on the target element.)
59
+ *
60
+ * Notes:
61
+ * `className` should not specify a border; that is handled by `borderColor`
62
+ * so that the arrow and tooltip match
63
+ *
64
+ * ```
65
+ * __,,--``\\
66
+ * _,,-''`` \\ ,
67
+ * '----------_.------'-.___|\__
68
+ * _.--''`` `)__ )__ @\__
69
+ * ( .. ''---/___,,E/__,E'------`
70
+ * `-''`''
71
+ * Here be dragons.
72
+ * ```
73
+ */
63
74
  declare class Tooltip extends React.Component<Props, State> {
64
75
  static defaultProps: DefaultProps;
65
76
  state: State;
package/dist/es/index.css CHANGED
@@ -4521,3 +4521,9 @@ html body .mq-editable-field .mq-selection .mq-nthroot-container * {
4521
4521
  stroke: black;
4522
4522
  stroke-width: 1px;
4523
4523
  }
4524
+
4525
+ .mafs-sr-only {
4526
+ height: 0;
4527
+ width: 0;
4528
+ overflow: hidden;
4529
+ }