@khanacademy/perseus 43.1.0 → 44.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 (53) hide show
  1. package/dist/all-widgets.d.ts +2 -23
  2. package/dist/basic-widgets.d.ts +2 -23
  3. package/dist/components/graph.d.ts +1 -0
  4. package/dist/components/icon.d.ts +0 -1
  5. package/dist/components/multi-button-group.d.ts +1 -0
  6. package/dist/components/tooltip.d.ts +1 -0
  7. package/dist/es/index.js +44 -24
  8. package/dist/es/index.js.map +1 -1
  9. package/dist/es/strings.js +4 -2
  10. package/dist/es/strings.js.map +1 -1
  11. package/dist/extra-widgets.d.ts +2 -23
  12. package/dist/index.d.ts +2 -2
  13. package/dist/index.js +42 -22
  14. package/dist/index.js.map +1 -1
  15. package/dist/interactive2/interactive-util.d.ts +1 -1
  16. package/dist/interactive2/movable-point-options.d.ts +2 -2
  17. package/dist/interactive2/movable-point.d.ts +7 -7
  18. package/dist/interactive2/objective_.d.ts +1 -1
  19. package/dist/jipt-paragraphs.d.ts +2 -2
  20. package/dist/perseus-api.d.ts +2 -77
  21. package/dist/perseus-types.d.ts +3 -10
  22. package/dist/server-item-renderer.d.ts +26 -49
  23. package/dist/strings.d.ts +1 -0
  24. package/dist/strings.js +4 -2
  25. package/dist/strings.js.map +1 -1
  26. package/dist/styles/global-styles.d.ts +0 -1
  27. package/dist/styles/shared.d.ts +0 -1
  28. package/dist/traversal.d.ts +1 -1
  29. package/dist/util/a11y.d.ts +0 -1
  30. package/dist/util/debounce.d.ts +1 -1
  31. package/dist/util/parse-perseus-json/perseus-parsers/graded-group-widget.d.ts +2 -2
  32. package/dist/widgets/definition/definition.d.ts +1 -1
  33. package/dist/widgets/deprecated-standin/deprecated-standin.d.ts +1 -1
  34. package/dist/widgets/dropdown/dropdown.d.ts +9 -1
  35. package/dist/widgets/explanation/explanation.d.ts +1 -1
  36. package/dist/widgets/expression/expression.d.ts +92 -217
  37. package/dist/widgets/image/image.d.ts +1 -1
  38. package/dist/widgets/interaction/interaction.d.ts +1 -1
  39. package/dist/widgets/interactive-graphs/graphs/quadratic.d.ts +1 -1
  40. package/dist/widgets/label-image/answer-pill.d.ts +0 -1
  41. package/dist/widgets/label-image/label-image.d.ts +5 -65
  42. package/dist/widgets/label-image/marker.d.ts +0 -1
  43. package/dist/widgets/measurer/measurer.d.ts +1 -1
  44. package/dist/widgets/molecule/molecule.d.ts +1 -1
  45. package/dist/widgets/passage/passage-markdown.d.ts +2 -2
  46. package/dist/widgets/passage/passage.d.ts +1 -1
  47. package/dist/widgets/passage-ref/passage-ref.d.ts +1 -1
  48. package/dist/widgets/passage-ref-target/passage-ref-target.d.ts +1 -1
  49. package/dist/widgets/radio/choice-icon/shared-styles.d.ts +0 -1
  50. package/dist/widgets/radio/choice-none-above.d.ts +1 -1
  51. package/dist/widgets/radio/radio.d.ts +2 -2
  52. package/dist/widgets/video/video.d.ts +1 -1
  53. package/package.json +2 -2
@@ -1,24 +1,3 @@
1
- /// <reference types="react" />
2
- declare const _default: readonly Readonly<{
3
- name: string;
4
- displayName: string;
5
- getWidget?: (() => import("react").ComponentType<any>) | undefined;
6
- widget: import("react").ComponentType<any>;
7
- accessible?: boolean | ((props: any) => boolean) | undefined;
8
- hidden?: boolean | undefined;
9
- version?: import("./types").Version | undefined;
10
- supportedAlignments?: readonly import("./types").Alignment[] | undefined;
11
- defaultAlignment?: import("./types").Alignment | undefined;
12
- getDefaultAlignment?: (() => import("./types").Alignment) | undefined;
13
- isLintable?: boolean | undefined;
14
- tracking?: import("./types").Tracking | undefined;
15
- traverseChildWidgets?: any;
16
- transform?: import("./types").WidgetTransform | undefined;
17
- staticTransform?: import("./types").WidgetTransform | undefined;
18
- scorer?: import("./types").WidgetScorerFunction | undefined;
19
- getOneCorrectAnswerFromRubric?: ((rubric: import("./validation.types").Rubric) => string | null | undefined) | undefined;
20
- propUpgrades?: {
21
- [key: string]: (arg1: any) => any;
22
- } | undefined;
23
- }>[];
1
+ import type { WidgetExports } from "./types";
2
+ declare const _default: ReadonlyArray<WidgetExports>;
24
3
  export default _default;
@@ -1,24 +1,3 @@
1
- /// <reference types="react" />
2
- declare const _default: readonly Readonly<{
3
- name: string;
4
- displayName: string;
5
- getWidget?: (() => import("react").ComponentType<any>) | undefined;
6
- widget: import("react").ComponentType<any>;
7
- accessible?: boolean | ((props: any) => boolean) | undefined;
8
- hidden?: boolean | undefined;
9
- version?: import("./types").Version | undefined;
10
- supportedAlignments?: readonly import("./types").Alignment[] | undefined;
11
- defaultAlignment?: import("./types").Alignment | undefined;
12
- getDefaultAlignment?: (() => import("./types").Alignment) | undefined;
13
- isLintable?: boolean | undefined;
14
- tracking?: import("./types").Tracking | undefined;
15
- traverseChildWidgets?: any;
16
- transform?: import("./types").WidgetTransform | undefined;
17
- staticTransform?: import("./types").WidgetTransform | undefined;
18
- scorer?: import("./types").WidgetScorerFunction | undefined;
19
- getOneCorrectAnswerFromRubric?: ((rubric: import("./validation.types").Rubric) => string | null | undefined) | undefined;
20
- propUpgrades?: {
21
- [key: string]: (arg1: any) => any;
22
- } | undefined;
23
- }>[];
1
+ import type { WidgetExports } from "./types";
2
+ declare const _default: ReadonlyArray<WidgetExports>;
24
3
  export default _default;
@@ -38,6 +38,7 @@ type DefaultProps = {
38
38
  isMobile: Props["isMobile"];
39
39
  };
40
40
  declare class Graph extends React.Component<Props> {
41
+ graphieDivRef: React.RefObject<HTMLDivElement>;
41
42
  protractor: any;
42
43
  ruler: any;
43
44
  _graphie: any;
@@ -1,4 +1,3 @@
1
- /// <reference path="../../types/aphrodite.d.ts" />
2
1
  import * as React from "react";
3
2
  import type { CSSProperties } from "aphrodite";
4
3
  export type IconType = {
@@ -47,6 +47,7 @@ type DefaultProps = {
47
47
  * this component allows multiple selection!
48
48
  */
49
49
  declare class MultiButtonGroup extends React.Component<Props> {
50
+ buttonContainerRef: React.RefObject<HTMLDivElement>;
50
51
  static defaultProps: DefaultProps;
51
52
  focus(): boolean;
52
53
  toggleSelect: (arg1?: any) => void;
@@ -72,6 +72,7 @@ type State = {
72
72
  * ```
73
73
  */
74
74
  declare class Tooltip extends React.Component<Props, State> {
75
+ tooltipContainerRef: React.RefObject<HTMLDivElement>;
75
76
  static defaultProps: DefaultProps;
76
77
  state: State;
77
78
  componentDidMount(): void;
package/dist/es/index.js CHANGED
@@ -4,7 +4,7 @@ import * as PerseusLinter from '@khanacademy/perseus-linter';
4
4
  import { linterContextDefault, Rule } from '@khanacademy/perseus-linter';
5
5
  import { View, RenderStateRoot, UniqueIDProvider, useOnMountEffect, useLatestRef, useUniqueIdWithMock, Text as Text$2 } from '@khanacademy/wonder-blocks-core';
6
6
  import Tooltip$1 from '@khanacademy/wonder-blocks-tooltip';
7
- import { HeadingMedium, LabelSmall, Body, LabelMedium } from '@khanacademy/wonder-blocks-typography';
7
+ import { HeadingMedium, LabelSmall, LabelLarge, Body, LabelMedium } from '@khanacademy/wonder-blocks-typography';
8
8
  import { StyleSheet, css } from 'aphrodite';
9
9
  import classNames$1 from 'classnames';
10
10
  import * as React from 'react';
@@ -249,7 +249,8 @@ const mockStrings = {
249
249
  srInteractiveElements: ({
250
250
  elements
251
251
  }) => `Interactive elements: ${elements}`,
252
- srNoInteractiveElements: "No interactive elements"
252
+ srNoInteractiveElements: "No interactive elements",
253
+ selectAnAnswer: "Select an answer"
253
254
  };
254
255
 
255
256
  /**
@@ -16629,7 +16630,7 @@ class Graphie extends React.Component {
16629
16630
  };
16630
16631
  this._setupGraphie = () => {
16631
16632
  this._removeMovables();
16632
- const graphieDiv = ReactDOM__default.findDOMNode(this.graphieDivRef.current);
16633
+ const graphieDiv = this.graphieDivRef.current;
16633
16634
  if (graphieDiv == null || graphieDiv instanceof Text) {
16634
16635
  throw new Error("No graphie container div found");
16635
16636
  }
@@ -21135,6 +21136,7 @@ const HORIZONTAL_ALIGNMNENTS = {
21135
21136
  class Tooltip extends React.Component {
21136
21137
  constructor(...args) {
21137
21138
  super(...args);
21139
+ this.tooltipContainerRef = /*#__PURE__*/React.createRef();
21138
21140
  this.state = {
21139
21141
  height: null // used for offsetting "top" positioned tooltips
21140
21142
  };
@@ -21209,8 +21211,7 @@ class Tooltip extends React.Component {
21209
21211
  display: this.props.show ? "block" : "none"
21210
21212
  }
21211
21213
  }, /*#__PURE__*/React.createElement("div", {
21212
- // eslint-disable-next-line react/no-string-refs
21213
- ref: "tooltipContainer",
21214
+ ref: this.tooltipContainerRef,
21214
21215
  className: "tooltipContainer",
21215
21216
  style: {
21216
21217
  position: "absolute",
@@ -21237,10 +21238,8 @@ class Tooltip extends React.Component {
21237
21238
  }, this.props.children.slice(1)), arrowBelow));
21238
21239
  }
21239
21240
  _updateHeight() {
21240
- const tooltipContainer = ReactDOM__default.findDOMNode(
21241
- // eslint-disable-next-line react/no-string-refs
21242
- this.refs.tooltipContainer);
21243
- const height = tooltipContainer.offsetHeight;
21241
+ const tooltipContainer = this.tooltipContainerRef.current;
21242
+ const height = (tooltipContainer == null ? void 0 : tooltipContainer.offsetHeight) || 0;
21244
21243
  if (height !== this.state.height) {
21245
21244
  this.setState({
21246
21245
  height
@@ -27224,23 +27223,40 @@ class Dropdown extends React.Component {
27224
27223
  value: String(i + 1),
27225
27224
  label: choice
27226
27225
  }))];
27227
- return /*#__PURE__*/React.createElement("div", {
27228
- // NOTE(jared): These are required to prevent weird behavior
27229
- // When there's a dropdown in a zoomable table.
27226
+ return /*#__PURE__*/React.createElement(UniqueIDProvider, {
27227
+ scope: "dropdown-widget",
27228
+ mockOnFirstRender: true
27229
+ }, ids => /*#__PURE__*/React.createElement(View
27230
+ // NOTE(jared): These are required to prevent weird behavior
27231
+ // When there's a dropdown in a zoomable table.
27232
+ , {
27230
27233
  onClick: e => {
27231
27234
  e.stopPropagation();
27232
27235
  },
27233
27236
  onTouchStart: e => {
27234
27237
  e.stopPropagation();
27235
27238
  }
27236
- }, /*#__PURE__*/React.createElement(SingleSelect, {
27239
+ }, this.props.visibleLabel && /*#__PURE__*/React.createElement(LabelLarge, {
27240
+ tag: "label",
27241
+ id: ids.get("dropdown-label")
27242
+ }, this.props.visibleLabel), /*#__PURE__*/React.createElement(SingleSelect, {
27243
+ id: ids.get("dropdown"),
27237
27244
  placeholder: "",
27238
27245
  onChange: value => this._handleChange(parseInt(value)),
27239
27246
  selectedValue: String(this.props.selected),
27240
- disabled: this.props.apiOptions.readOnly
27241
- }, children));
27247
+ disabled: this.props.apiOptions.readOnly,
27248
+ "aria-label": this.props.ariaLabel || this.context.strings.selectAnAnswer,
27249
+ "aria-labelledby": ids.get("dropdown-label")
27250
+ // This is currently necessary for SRs to read the labels properly.
27251
+ // However, WB is working on a change to add the "combobox" role to
27252
+ // all dropdowns.
27253
+ // See https://khanacademy.atlassian.net/browse/WB-1671
27254
+ ,
27255
+ role: "combobox"
27256
+ }, children)));
27242
27257
  }
27243
27258
  }
27259
+ Dropdown.contextType = PerseusI18nContext;
27244
27260
  Dropdown.defaultProps = {
27245
27261
  choices: [],
27246
27262
  selected: 0,
@@ -27250,6 +27266,8 @@ Dropdown.defaultProps = {
27250
27266
  const optionsTransform = widgetOptions => {
27251
27267
  return {
27252
27268
  placeholder: widgetOptions.placeholder,
27269
+ visibleLabel: widgetOptions.visibleLabel,
27270
+ ariaLabel: widgetOptions.ariaLabel,
27253
27271
  choices: widgetOptions.choices.map(choice => choice.content)
27254
27272
  };
27255
27273
  };
@@ -30345,6 +30363,7 @@ function numSteps$1(range, step) {
30345
30363
  class Graph extends React.Component {
30346
30364
  constructor(...args) {
30347
30365
  super(...args);
30366
+ this.graphieDivRef = /*#__PURE__*/React.createRef();
30348
30367
  this.protractor = void 0;
30349
30368
  this.ruler = void 0;
30350
30369
  this._graphie = void 0;
@@ -30388,9 +30407,7 @@ class Graph extends React.Component {
30388
30407
  if (this._hasSetupGraphieThisUpdate) {
30389
30408
  return;
30390
30409
  }
30391
-
30392
- // eslint-disable-next-line react/no-string-refs
30393
- const graphieDiv = ReactDOM__default.findDOMNode(this.refs.graphieDiv);
30410
+ const graphieDiv = this.graphieDivRef.current;
30394
30411
  // @ts-expect-error - TS2769 - No overload matches this call. | TS2339 - Property 'empty' does not exist on type 'JQueryStatic'.
30395
30412
  $(graphieDiv).empty();
30396
30413
 
@@ -30598,7 +30615,7 @@ class Graph extends React.Component {
30598
30615
  onClick: this.onClick
30599
30616
  }, image, /*#__PURE__*/React.createElement("div", {
30600
30617
  className: "graphie",
30601
- ref: "graphieDiv"
30618
+ ref: this.graphieDivRef
30602
30619
  }));
30603
30620
  }
30604
30621
  }
@@ -31686,6 +31703,7 @@ class InfoTip extends React.Component {
31686
31703
  class MultiButtonGroup extends React.Component {
31687
31704
  constructor(...args) {
31688
31705
  super(...args);
31706
+ this.buttonContainerRef = /*#__PURE__*/React.createRef();
31689
31707
  this.toggleSelect = newValue => {
31690
31708
  const values = (this.props.values || []).slice(0);
31691
31709
  const allowEmpty = this.props.allowEmpty;
@@ -31702,9 +31720,8 @@ class MultiButtonGroup extends React.Component {
31702
31720
  };
31703
31721
  }
31704
31722
  focus() {
31705
- var _ReactDOM$findDOMNode;
31706
- // @ts-expect-error - TS2339 - Property 'focus' does not exist on type 'Element | Text'.
31707
- (_ReactDOM$findDOMNode = ReactDOM.findDOMNode(this)) == null || _ReactDOM$findDOMNode.focus();
31723
+ var _this$buttonContainer;
31724
+ (_this$buttonContainer = this.buttonContainerRef.current) == null || _this$buttonContainer.focus();
31708
31725
  return true;
31709
31726
  }
31710
31727
  render() {
@@ -31725,7 +31742,8 @@ class MultiButtonGroup extends React.Component {
31725
31742
  display: "inline-block"
31726
31743
  };
31727
31744
  return /*#__PURE__*/React.createElement("div", {
31728
- style: outerStyle
31745
+ style: outerStyle,
31746
+ ref: this.buttonContainerRef
31729
31747
  }, buttons);
31730
31748
  }
31731
31749
  }
@@ -44843,7 +44861,7 @@ const init = function init() {
44843
44861
 
44844
44862
  // This file is processed by a Rollup plugin (replace) to inject the production
44845
44863
  const libName = "@khanacademy/perseus";
44846
- const libVersion = "43.1.0";
44864
+ const libVersion = "44.0.0";
44847
44865
  addLibraryVersionToPerseusDebug(libName, libVersion);
44848
44866
 
44849
44867
  const apiVersion = {
@@ -48513,6 +48531,8 @@ const parseDefinitionWidget = parseWidget(constant("definition"), object({
48513
48531
 
48514
48532
  const parseDropdownWidget = parseWidget(constant("dropdown"), object({
48515
48533
  placeholder: string,
48534
+ ariaLabel: optional(string),
48535
+ visibleLabel: optional(string),
48516
48536
  static: defaulted(boolean, () => false),
48517
48537
  choices: array(object({
48518
48538
  content: string,