@khanacademy/perseus 12.1.0 → 12.2.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @khanacademy/perseus
2
2
 
3
+ ## 12.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#773](https://github.com/Khan/perseus/pull/773) [`809823e4`](https://github.com/Khan/perseus/commit/809823e490f65cbcbaa05b548de985035810ba8d) Thanks [@nixterrimus](https://github.com/nixterrimus)! - Fix text overlap in interactive graph widget
8
+
9
+ * [#755](https://github.com/Khan/perseus/pull/755) [`6d9e31a4`](https://github.com/Khan/perseus/commit/6d9e31a4ea4a1ed29bef2d9812d21e5b2fd41af6) Thanks [@SonicScrewdriver](https://github.com/SonicScrewdriver)! - Adding logic to ArticleRenderer so that it can return our currently focused element.
10
+
3
11
  ## 12.1.0
4
12
 
5
13
  ### Minor Changes
@@ -3,6 +3,7 @@
3
3
  * composed of multiple (Renderer) sections concatenated together.
4
4
  */
5
5
  import * as React from "react";
6
+ import Renderer from "./renderer";
6
7
  import type { KeypadProps } from "./mixins/provide-keypad";
7
8
  import type { PerseusRenderer } from "./perseus-types";
8
9
  import type { APIOptions, PerseusDependenciesV2 } from "./types";
@@ -28,6 +29,7 @@ type DefaultProps = {
28
29
  };
29
30
  declare class ArticleRenderer extends React.Component<Props> implements KeypadContextRendererInterface {
30
31
  _currentFocus: any;
32
+ sectionRenderers: Array<Renderer>;
31
33
  static defaultProps: DefaultProps;
32
34
  constructor(props: Props);
33
35
  componentDidMount(): void;
package/dist/es/index.css CHANGED
@@ -2613,6 +2613,7 @@ img.zoom-img {
2613
2613
  }
2614
2614
  /* Widget CSS */
2615
2615
  .perseus-graph-padding {
2616
+ box-sizing: content-box;
2616
2617
  padding: 25px 25px 0 0;
2617
2618
  }
2618
2619
  .categorizer-container {
@@ -2749,6 +2750,7 @@ body.mobile .categorizer-container td.category input[type="radio"] + span:active
2749
2750
  margin: 0px 4px;
2750
2751
  }
2751
2752
  .perseus-widget-grapher {
2753
+ box-sizing: content-box;
2752
2754
  padding: 25px 25px 0 0;
2753
2755
  }
2754
2756
  .perseus-widget-grapher > .graphie-container {
@@ -2836,6 +2838,7 @@ body.mobile .categorizer-container td.category input[type="radio"] + span:active
2836
2838
  margin-top: 5px;
2837
2839
  }
2838
2840
  .perseus-widget-interactive-graph {
2841
+ box-sizing: content-box;
2839
2842
  padding: 25px 25px 0 0;
2840
2843
  }
2841
2844
  .perseus-widget-interactive-graph > .graphie-container {
package/dist/es/index.js CHANGED
@@ -43748,7 +43748,7 @@ const init = function init(options) {
43748
43748
 
43749
43749
  // This file is processed by a Rollup plugin (replace) to inject the production
43750
43750
  const libName = "@khanacademy/perseus";
43751
- const libVersion = "12.1.0";
43751
+ const libVersion = "12.2.0";
43752
43752
  addLibraryVersionToPerseusDebug(libName, libVersion);
43753
43753
 
43754
43754
  const apiVersion = {
@@ -43770,6 +43770,7 @@ class ArticleRenderer extends React.Component {
43770
43770
  constructor(props) {
43771
43771
  super(props);
43772
43772
  this._currentFocus = void 0;
43773
+ this.sectionRenderers = [];
43773
43774
  this._handleFocusChange = (newFocusPath, oldFocusPath) => {
43774
43775
  // TODO(charlie): DRY this up--some of this logic is repeated in
43775
43776
  // ItemRenderer.
@@ -43794,17 +43795,17 @@ class ArticleRenderer extends React.Component {
43794
43795
  // paths, so as to check whether the focused path represents an
43795
43796
  // input.
43796
43797
  let didFocusInput = false;
43798
+ let focusedInput;
43797
43799
  if (this._currentFocus) {
43798
- const [sectionRef, ...focusPath] = this._currentFocus;
43799
- // eslint-disable-next-line react/no-string-refs
43800
- // @ts-expect-error - TS2339 - Property 'getInputPaths' does not exist on type 'ReactInstance'.
43801
- const inputPaths = this.refs[sectionRef].getInputPaths();
43800
+ const [sectionIndex, ...focusPath] = this._currentFocus;
43801
+ const inputPaths = this.sectionRenderers[sectionIndex].getInputPaths();
43802
43802
  didFocusInput = inputPaths.some(inputPath => {
43803
43803
  return Util.inputPathsEqual(inputPath, focusPath);
43804
43804
  });
43805
+ focusedInput = this.sectionRenderers[sectionIndex].getDOMNodeForPath(focusPath);
43805
43806
  }
43806
43807
  if (this.props.apiOptions.onFocusChange != null) {
43807
- this.props.apiOptions.onFocusChange(this._currentFocus, prevFocusPath, didFocusInput ? keypadElement == null ? void 0 : keypadElement.getDOMNode() : null);
43808
+ this.props.apiOptions.onFocusChange(this._currentFocus, prevFocusPath, didFocusInput ? keypadElement == null ? void 0 : keypadElement.getDOMNode() : null, didFocusInput ? focusedInput : null);
43808
43809
  }
43809
43810
  if (keypadElement && isMobile) {
43810
43811
  if (didFocusInput) {
@@ -43836,10 +43837,8 @@ class ArticleRenderer extends React.Component {
43836
43837
  };
43837
43838
  this.blur = () => {
43838
43839
  if (this._currentFocus) {
43839
- const [sectionRef, ...inputPath] = this._currentFocus;
43840
- // eslint-disable-next-line react/no-string-refs
43841
- // @ts-expect-error - TS2339 - Property 'blurPath' does not exist on type 'ReactInstance'.
43842
- this.refs[sectionRef].blurPath(inputPath);
43840
+ const [sectionIndex, ...inputPath] = this._currentFocus;
43841
+ this.sectionRenderers[sectionIndex].blurPath(inputPath);
43843
43842
  }
43844
43843
  };
43845
43844
  this._sections = () => {
@@ -43865,33 +43864,39 @@ class ArticleRenderer extends React.Component {
43865
43864
  });
43866
43865
 
43867
43866
  // TODO(alex): Add mobile api functions and pass them down here
43868
- const sections = this._sections().map((section, i) => {
43869
- const refForSection = `section-${i}`;
43870
- return /*#__PURE__*/React.createElement(DependenciesContext.Provider, {
43871
- value: this.props.dependencies
43872
- }, /*#__PURE__*/React.createElement("div", {
43873
- key: i,
43867
+ // We're using the index as the key here because we don't have a unique
43868
+ // identifier for each section. This should be fine as we never remove
43869
+ // or reorder sections.
43870
+ const sections = this._sections().map((section, sectionIndex) => {
43871
+ return /*#__PURE__*/React.createElement("div", {
43872
+ key: sectionIndex,
43874
43873
  className: "clearfix"
43875
43874
  }, /*#__PURE__*/React.createElement(Renderer, _extends({}, section, {
43876
- ref: refForSection,
43877
- key: i,
43878
- key_: i,
43875
+ ref: elem => {
43876
+ if (elem) {
43877
+ this.sectionRenderers[sectionIndex] = elem;
43878
+ }
43879
+ },
43880
+ key: sectionIndex,
43881
+ key_: sectionIndex,
43879
43882
  keypadElement: this.props.keypadElement,
43880
43883
  apiOptions: _extends({}, apiOptions, {
43881
43884
  onFocusChange: (newFocusPath, oldFocusPath) => {
43882
- // Prefix the paths with the relevant section,
43885
+ // Prefix the paths with the relevant section index,
43883
43886
  // so as to allow us to distinguish between
43884
43887
  // equivalently-named inputs across Renderers.
43885
- this._handleFocusChange(newFocusPath && [refForSection].concat(newFocusPath), oldFocusPath && [refForSection].concat(oldFocusPath));
43888
+ this._handleFocusChange(newFocusPath && [sectionIndex].concat(newFocusPath), oldFocusPath && [sectionIndex].concat(oldFocusPath));
43886
43889
  }
43887
43890
  }),
43888
43891
  linterContext: PerseusLinter.pushContextStack(this.props.linterContext, "article"),
43889
43892
  legacyPerseusLint: this.props.legacyPerseusLint
43890
- }))));
43893
+ })));
43891
43894
  });
43892
43895
  return /*#__PURE__*/React.createElement("div", {
43893
43896
  className: classes
43894
- }, sections);
43897
+ }, /*#__PURE__*/React.createElement(DependenciesContext.Provider, {
43898
+ value: this.props.dependencies
43899
+ }, sections));
43895
43900
  }
43896
43901
  }
43897
43902
  ArticleRenderer.defaultProps = {