@khanacademy/perseus 21.6.0 → 22.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 (61) hide show
  1. package/dist/article-renderer.d.ts +6 -0
  2. package/dist/components/highlighting/ui/highlight-set-renderer.d.ts +14 -0
  3. package/dist/components/highlighting/ui/highlighting-ui.d.ts +17 -0
  4. package/dist/components/i18n-context.d.ts +16 -0
  5. package/dist/components/input-with-examples.d.ts +6 -0
  6. package/dist/components/math-input.d.ts +22 -2
  7. package/dist/components/number-input.d.ts +6 -0
  8. package/dist/es/index.js +863 -485
  9. package/dist/es/index.js.map +1 -1
  10. package/dist/es/strings.js +312 -0
  11. package/dist/es/strings.js.map +1 -0
  12. package/dist/hint-renderer.d.ts +6 -0
  13. package/dist/hints-renderer.d.ts +6 -0
  14. package/dist/index.d.ts +1 -0
  15. package/dist/index.js +1083 -523
  16. package/dist/index.js.map +1 -1
  17. package/dist/multi-items/multi-renderer.d.ts +6 -0
  18. package/dist/perseus-types.d.ts +3 -2
  19. package/dist/renderer.d.ts +2 -0
  20. package/dist/server-item-renderer.d.ts +6 -0
  21. package/dist/strings.d.ts +190 -0
  22. package/dist/strings.js +395 -119
  23. package/dist/strings.js.map +1 -0
  24. package/dist/types.d.ts +2 -1
  25. package/dist/util/answer-types.d.ts +4 -12
  26. package/dist/util.d.ts +2 -1
  27. package/dist/widgets/categorizer.d.ts +8 -1
  28. package/dist/widgets/definition.d.ts +6 -0
  29. package/dist/widgets/deprecated-standin/index.d.ts +6 -0
  30. package/dist/widgets/explanation.d.ts +6 -0
  31. package/dist/widgets/expression.d.ts +12 -1
  32. package/dist/widgets/graded-group-answer-bar.d.ts +6 -0
  33. package/dist/widgets/graded-group.d.ts +6 -0
  34. package/dist/widgets/group.d.ts +6 -0
  35. package/dist/widgets/image.d.ts +6 -0
  36. package/dist/widgets/input-number.d.ts +8 -1
  37. package/dist/widgets/interactive-graph.d.ts +6 -0
  38. package/dist/widgets/interactive-graphs/interactive-graph-question-builder.d.ts +21 -0
  39. package/dist/widgets/interactive-graphs/locked-point.d.ts +1 -1
  40. package/dist/widgets/interactive-graphs/mafs-graph.d.ts +1 -0
  41. package/dist/widgets/interactive-graphs/reducer/use-graph-config.d.ts +1 -0
  42. package/dist/widgets/label-image/marker.d.ts +6 -0
  43. package/dist/widgets/label-image.d.ts +6 -0
  44. package/dist/widgets/matcher.d.ts +6 -0
  45. package/dist/widgets/matrix.d.ts +9 -1
  46. package/dist/widgets/molecule.d.ts +6 -0
  47. package/dist/widgets/number-line.d.ts +6 -0
  48. package/dist/widgets/numeric-input.d.ts +8 -1
  49. package/dist/widgets/passage-ref-target.d.ts +6 -0
  50. package/dist/widgets/passage-ref.d.ts +6 -0
  51. package/dist/widgets/passage.d.ts +6 -0
  52. package/dist/widgets/plotter.d.ts +6 -0
  53. package/dist/widgets/radio/choice-a11y-text.d.ts +2 -1
  54. package/dist/widgets/radio/radio.d.ts +8 -1
  55. package/dist/widgets/radio/util.d.ts +2 -1
  56. package/dist/widgets/table.d.ts +7 -0
  57. package/dist/widgets/unit.d.ts +8 -1
  58. package/dist/widgets/video.d.ts +6 -0
  59. package/dist/widgets.d.ts +2 -1
  60. package/package.json +18 -6
  61. package/dist/widgets/label-image/strings.d.ts +0 -3
@@ -3,6 +3,7 @@
3
3
  * composed of multiple (Renderer) sections concatenated together.
4
4
  */
5
5
  import * as React from "react";
6
+ import { PerseusI18nContext } from "./components/i18n-context";
6
7
  import { DependenciesContext } from "./dependencies";
7
8
  import Renderer from "./renderer";
8
9
  import type { PerseusRenderer } from "./perseus-types";
@@ -28,6 +29,11 @@ type DefaultProps = {
28
29
  linterContext: Props["linterContext"];
29
30
  };
30
31
  declare class ArticleRenderer extends React.Component<Props> implements KeypadContextRendererInterface {
32
+ static contextType: React.Context<{
33
+ strings: import("./strings").PerseusStrings;
34
+ locale: string;
35
+ }>;
36
+ context: React.ContextType<typeof PerseusI18nContext>;
31
37
  _currentFocus: any;
32
38
  sectionRenderers: Array<Renderer>;
33
39
  static defaultProps: DefaultProps;
@@ -1,4 +1,13 @@
1
+ /**
2
+ * Render a set of highlights. See HighlightRenderer for more details about how
3
+ * each highlight is rendered.
4
+ *
5
+ * This component manages the state of the "Remove highlight" tooltip. To
6
+ * determine the currently-hovered highlight, it calls the `isHovered` method
7
+ * on each HighlightRenderer.
8
+ */
1
9
  import * as React from "react";
10
+ import { PerseusI18nContext } from "../../i18n-context";
2
11
  import HighlightRenderer from "./highlight-renderer";
3
12
  import type { DOMHighlightSet, Position, ZIndexes } from "./types";
4
13
  type Props = {
@@ -13,6 +22,11 @@ type State = {
13
22
  hoveringTooltipFor: string | null | undefined;
14
23
  };
15
24
  declare class HighlightSetRenderer extends React.PureComponent<Props, State> {
25
+ static contextType: React.Context<{
26
+ strings: import("../../../strings").PerseusStrings;
27
+ locale: string;
28
+ }>;
29
+ context: React.ContextType<typeof PerseusI18nContext>;
16
30
  state: State;
17
31
  _highlightRenderers: {
18
32
  [highlightKey: string]: HighlightRenderer;
@@ -1,4 +1,16 @@
1
+ /**
2
+ * This component, given a set of DOMHighlights, draws highlight rectangles in
3
+ * the same absolute position as the highlighted content, as computed by the
4
+ * range's `getClientRects` method.
5
+ *
6
+ * TODO(mdr): Many things can affect the correct positioning of highlighting,
7
+ * and this component does not attempt to anticipate them. If we start
8
+ * using this highlighting library on content with a more dynamic layout,
9
+ * we should add a hook to allow the parent to `forceUpdate` the
10
+ * `HighlightingUI`.
11
+ */
1
12
  import * as React from "react";
13
+ import { PerseusI18nContext } from "../../i18n-context";
2
14
  import type { TrackedSelection } from "./selection-tracker";
3
15
  import type { DOMHighlight, DOMHighlightSet, DOMRange, ZIndexes } from "./types";
4
16
  type Props = {
@@ -12,6 +24,11 @@ type Props = {
12
24
  zIndexes: ZIndexes;
13
25
  };
14
26
  declare class HighlightingUI extends React.PureComponent<Props> {
27
+ static contextType: React.Context<{
28
+ strings: import("../../../strings").PerseusStrings;
29
+ locale: string;
30
+ }>;
31
+ context: React.ContextType<typeof PerseusI18nContext>;
15
32
  _handleAddHighlight(highlightToAdd: DOMHighlight): void;
16
33
  _selectionIsValid(trackedSelection?: TrackedSelection | null): trackedSelection is TrackedSelection;
17
34
  render(): React.ReactNode;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * PerseusI18nContext provides a way to set the strings and locale that are
3
+ * used inside the Perseus package.
4
+ *
5
+ */
6
+ import * as React from "react";
7
+ import type { PerseusStrings } from "../strings";
8
+ type I18nContextType = {
9
+ strings: PerseusStrings;
10
+ locale: string;
11
+ };
12
+ export declare const PerseusI18nContext: React.Context<I18nContextType>;
13
+ type Props = React.PropsWithChildren<I18nContextType>;
14
+ export declare function PerseusI18nContextProvider({ children, strings, locale }: Props): JSX.Element;
15
+ export declare const usePerseusI18n: () => I18nContextType;
16
+ export {};
@@ -1,4 +1,5 @@
1
1
  import * as React from "react";
2
+ import { PerseusI18nContext } from "./i18n-context";
2
3
  import type { LinterContextProps } from "@khanacademy/perseus-linter";
3
4
  import type { StyleType } from "@khanacademy/wonder-blocks-core";
4
5
  type Props = {
@@ -33,6 +34,11 @@ type State = {
33
34
  showExamples: boolean;
34
35
  };
35
36
  declare class InputWithExamples extends React.Component<Props, State> {
37
+ static contextType: React.Context<{
38
+ strings: import("../strings").PerseusStrings;
39
+ locale: string;
40
+ }>;
41
+ context: React.ContextType<typeof PerseusI18nContext>;
36
42
  static defaultProps: DefaultProps;
37
43
  state: State;
38
44
  _getUniqueId: () => string;
@@ -1,5 +1,6 @@
1
- import { CursorContext } from "@khanacademy/math-input";
1
+ import { CursorContext, MathInputI18nContext } from "@khanacademy/math-input";
2
2
  import * as React from "react";
3
+ import { PerseusI18nContext } from "./i18n-context";
3
4
  import type { LegacyButtonSets } from "../perseus-types";
4
5
  import type { PerseusDependenciesV2 } from "../types";
5
6
  import type { Keys, MathFieldInterface } from "@khanacademy/math-input";
@@ -41,6 +42,9 @@ type Props = {
41
42
  buttonsVisible?: ButtonsVisibleType;
42
43
  analytics: PerseusDependenciesV2["analytics"];
43
44
  };
45
+ type InnerProps = Props & {
46
+ mathInputStrings: any;
47
+ };
44
48
  type DefaultProps = {
45
49
  value: Props["value"];
46
50
  convertDotToTimes: Props["convertDotToTimes"];
@@ -51,7 +55,12 @@ type State = {
51
55
  cursorContext: (typeof CursorContext)[keyof typeof CursorContext];
52
56
  openedWithEventType?: string;
53
57
  };
54
- declare class MathInput extends React.Component<Props, State> {
58
+ declare class InnerMathInput extends React.Component<InnerProps, State> {
59
+ static contextType: React.Context<{
60
+ strings: import("../strings").PerseusStrings;
61
+ locale: string;
62
+ }>;
63
+ context: React.ContextType<typeof PerseusI18nContext>;
55
64
  mouseDown: boolean;
56
65
  __mathFieldWrapperRef: HTMLSpanElement | null;
57
66
  __mathField: MathFieldInterface | null;
@@ -67,4 +76,15 @@ declare class MathInput extends React.Component<Props, State> {
67
76
  handleKeypadPress: (key: Keys, e: any) => void;
68
77
  render(): React.ReactNode;
69
78
  }
79
+ declare class MathInput extends React.Component<Props, State> {
80
+ static contextType: React.Context<{
81
+ strings: import("../../../math-input/src/strings").MathInputStrings;
82
+ locale: string;
83
+ }>;
84
+ context: React.ContextType<typeof MathInputI18nContext>;
85
+ inputRef: React.RefObject<InnerMathInput>;
86
+ focus(): void;
87
+ insert(value: any): void;
88
+ render(): JSX.Element;
89
+ }
70
90
  export default MathInput;
@@ -1,7 +1,13 @@
1
1
  import PropTypes from "prop-types";
2
2
  import * as React from "react";
3
+ import { PerseusI18nContext } from "./i18n-context";
3
4
  import type { MathFormat } from "../perseus-types";
4
5
  declare class NumberInput extends React.Component<any, any> {
6
+ static contextType: React.Context<{
7
+ strings: import("../strings").PerseusStrings;
8
+ locale: string;
9
+ }>;
10
+ context: React.ContextType<typeof PerseusI18nContext>;
5
11
  static propTypes: {
6
12
  value: PropTypes.Requireable<number>;
7
13
  format: PropTypes.Requireable<string>;