@khanacademy/perseus 20.2.0 → 20.3.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/dist/es/index.css CHANGED
@@ -2363,7 +2363,7 @@ img.zoom-img {
2363
2363
  }
2364
2364
  .framework-perseus .perseus-renderer > .paragraph > ul:not(.perseus-widget-radio),
2365
2365
  .framework-perseus .perseus-renderer > .paragraph > ol {
2366
- margin: -11px 0px 22px 0px;
2366
+ margin: 0px 0px 22px 0px;
2367
2367
  }
2368
2368
  .framework-perseus .paragraph ul:not(.perseus-widget-radio, .indicatorContainer) {
2369
2369
  padding-left: 35px;
package/dist/es/index.js CHANGED
@@ -2,7 +2,7 @@ import * as KAS from '@khanacademy/kas';
2
2
  import { keyTranslator, CursorContext, createMathField, getCursorContext, DesktopKeypad, convertDotToTimesByLocale, mathQuillInstance, KeypadInput, KeypadType, KeyArray, keypadElementPropType } from '@khanacademy/math-input';
3
3
  import * as PerseusLinter from '@khanacademy/perseus-linter';
4
4
  import { linterContextDefault, Rule, linterContextProps } from '@khanacademy/perseus-linter';
5
- import { View, RenderStateRoot, useUniqueIdWithMock, Text as Text$1 } from '@khanacademy/wonder-blocks-core';
5
+ import { View, RenderStateRoot, UniqueIDProvider, useUniqueIdWithMock, Text as Text$1 } from '@khanacademy/wonder-blocks-core';
6
6
  import * as i18n from '@khanacademy/wonder-blocks-i18n';
7
7
  import Tooltip$1 from '@khanacademy/wonder-blocks-tooltip';
8
8
  import classNames from 'classnames';
@@ -28,6 +28,8 @@ import Button from '@khanacademy/wonder-blocks-button';
28
28
  import { Strut } from '@khanacademy/wonder-blocks-layout';
29
29
  import Banner from '@khanacademy/wonder-blocks-banner';
30
30
  import { OptionItem, SingleSelect, MultiSelect } from '@khanacademy/wonder-blocks-dropdown';
31
+ import caretDown from '@phosphor-icons/core/assets/regular/caret-down.svg';
32
+ import caretUp from '@phosphor-icons/core/assets/regular/caret-up.svg';
31
33
  import debounce$2 from 'lodash.debounce';
32
34
  import { Point as Point$2, useMovable, useTransformContext, vec, Coordinates, Mafs } from 'mafs';
33
35
  import { PhosphorIcon } from '@khanacademy/wonder-blocks-icon';
@@ -24885,57 +24887,42 @@ class Explanation extends React.Component {
24885
24887
  };
24886
24888
  }
24887
24889
  render() {
24888
- const {
24889
- isArticle,
24890
- isMobile
24891
- } = this.props.apiOptions;
24892
24890
  const promptText = this.state.expanded ? this.props.hidePrompt : this.props.showPrompt;
24893
- let promptContainer;
24894
-
24895
- // TODO(diedra): This isn't a valid href;
24896
- // change this to a button that looks like a link.
24897
- const href = "javascript:void(0)";
24898
- const onClick = this._onClick;
24899
- if (isMobile) {
24900
- promptContainer = /*#__PURE__*/React.createElement("div", {
24901
- className: css(styles$p.linkContainer)
24902
- }, /*#__PURE__*/React.createElement("a", {
24903
- className: css(styles$p.mobileExplanationLink),
24904
- href: href,
24905
- onClick: onClick,
24906
- role: "button",
24907
- "aria-expanded": this.state.expanded
24908
- }, promptText), this.state.expanded && /*#__PURE__*/React.createElement("svg", {
24909
- className: css(styles$p.disclosureArrow)
24910
- }, /*#__PURE__*/React.createElement("polygon", {
24911
- style: {
24912
- fill: backgroundColor
24913
- },
24914
- points: `0,${arrowHeight} ` + `${arrowWidth},${arrowHeight} ` + `${arrowWidth / 2},0`
24915
- })));
24916
- } else {
24917
- const viewStyling = isArticle ? [styles$p.explanationLink, styles$p.articleLink] : [styles$p.explanationLink, styles$p.exerciseLink];
24918
- promptContainer = /*#__PURE__*/React.createElement(Clickable, {
24919
- onClick: onClick,
24920
- "aria-expanded": this.state.expanded
24921
- }, () => /*#__PURE__*/React.createElement(View, {
24922
- style: viewStyling
24923
- }, `[${promptText}]`));
24924
- }
24925
- const expandedStyle = isMobile ? styles$p.contentExpandedMobile : styles$p.contentExpanded;
24926
- return /*#__PURE__*/React.createElement("div", {
24927
- className: css(styles$p.container)
24928
- }, promptContainer, this.state.expanded && /*#__PURE__*/React.createElement("div", {
24929
- className: css(styles$p.content, isMobile && styles$p.contentMobile, this.state.expanded && expandedStyle)
24930
- // eslint-disable-next-line react/no-string-refs
24931
- ,
24932
- ref: "content"
24891
+ const caretIcon = this.state.expanded ? caretUp : caretDown;
24892
+ const allowTransition = window.matchMedia("(prefers-reduced-motion: no-preference)").matches;
24893
+
24894
+ // Special styling is needed to fit the button in a block of text without throwing off the line spacing.
24895
+ // While the button is not normally included in a block of text, it needs to be able to accommodate such a case.
24896
+ const buttonStyleOverrides = {
24897
+ height: "22px",
24898
+ marginLeft: "-2px",
24899
+ padding: "0 2px"
24900
+ };
24901
+ const contentStyling = [styles$p.content, this.state.expanded ? styles$p.contentExpanded : styles$p.contentCollapsed, allowTransition && (this.state.expanded ? styles$p.transitionExpanded : styles$p.transitionCollapsed)];
24902
+ return /*#__PURE__*/React.createElement(UniqueIDProvider, {
24903
+ mockOnFirstRender: false,
24904
+ scope: "explanation-widget"
24905
+ }, ids => /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Button, {
24906
+ "aria-expanded": this.state.expanded,
24907
+ "aria-controls": ids.get("content"),
24908
+ endIcon: caretIcon,
24909
+ kind: "tertiary",
24910
+ onClick: this._onClick,
24911
+ size: "large",
24912
+ style: buttonStyleOverrides
24913
+ }, promptText), /*#__PURE__*/React.createElement(View, {
24914
+ id: ids.get("content"),
24915
+ style: contentStyling,
24916
+ "aria-hidden": !this.state.expanded,
24917
+ testId: "content-container"
24918
+ }, /*#__PURE__*/React.createElement(View, {
24919
+ style: styles$p.contentWrapper
24933
24920
  }, /*#__PURE__*/React.createElement(Renderer, {
24934
24921
  apiOptions: this.props.apiOptions,
24935
24922
  content: this.props.explanation,
24936
24923
  widgets: this.props.widgets,
24937
24924
  linterContext: this.props.linterContext
24938
- })));
24925
+ })))));
24939
24926
  }
24940
24927
  }
24941
24928
  Explanation.defaultProps = {
@@ -24947,94 +24934,44 @@ Explanation.defaultProps = {
24947
24934
  };
24948
24935
  const leftBorderSpacing = 23;
24949
24936
  const verticalContentPadding = 10;
24950
- const arrowWidth = 30;
24951
24937
  const arrowHeight = 14;
24952
- const backgroundColor = gray95;
24953
24938
  const styles$p = StyleSheet.create({
24954
- container: {
24955
- display: "inline",
24939
+ content: {
24940
+ borderLeft: "0px solid #ccc",
24941
+ display: "inline-grid",
24956
24942
  position: "relative"
24957
24943
  },
24958
- linkContainer: {
24959
- display: "inline-block"
24960
- },
24961
- explanationLink: {
24962
- fontStyle: "italic",
24963
- color: "#007d96"
24964
- },
24965
- articleLink: {
24966
- // Copied from .body-text in articles.less
24967
- fontSize: 20,
24968
- lineHeight: "30px"
24969
- },
24970
- exerciseLink: {
24971
- // Copied from .legacy-typography in util.less
24972
- fontSize: 14,
24973
- lineHeight: "19.6px"
24974
- },
24975
- mobileExplanationLink: {
24976
- color: kaGreen$1,
24977
- borderBottom: `dashed 1px ${kaGreen$1}`,
24978
- textDecoration: "none",
24979
- // TODO(benkomalo): these should be pulled in from common typography
24980
- // shared files so we have a single place where the type hierarchy is
24981
- // defined; one off font sizes for individual components should be
24982
- // avoided.
24983
- [mediaQueries.xl]: {
24984
- fontSize: 22,
24985
- lineHeight: 1.4
24986
- },
24987
- [mediaQueries.lgOrSmaller]: {
24988
- fontSize: 20,
24989
- lineHeight: 1.5
24990
- },
24991
- [mediaQueries.smOrSmaller]: {
24992
- fontSize: 18,
24993
- lineHeight: 1.2
24994
- }
24995
- },
24996
- content: {
24997
- position: "relative",
24998
- transition: "margin-top 0.1s"
24944
+ contentCollapsed: {
24945
+ gridTemplateColumns: "0fr",
24946
+ gridTemplateRows: "0fr",
24947
+ marginBottom: 0,
24948
+ marginTop: 0,
24949
+ minWidth: "0",
24950
+ paddingBottom: 0,
24951
+ visibility: "hidden"
24999
24952
  },
25000
24953
  contentExpanded: {
25001
- borderLeft: "5px solid #ccc",
24954
+ borderLeftWidth: "5px",
24955
+ gridTemplateColumns: "1fr",
24956
+ gridTemplateRows: "1fr",
25002
24957
  marginLeft: -leftBorderSpacing,
24958
+ minWidth: "100%",
25003
24959
  paddingLeft: leftBorderSpacing,
25004
24960
  paddingBottom: verticalContentPadding,
24961
+ visibility: "visible",
25005
24962
  // Note: we still use arrow height as the vertical margin, even on
25006
24963
  // desktop when there is no arrow, but it's good enough.
25007
24964
  marginBottom: arrowHeight,
25008
24965
  marginTop: arrowHeight
25009
24966
  },
25010
- contentExpandedMobile: {
25011
- boxSizing: "content-box",
25012
- paddingTop: 32,
25013
- paddingBottom: 32,
25014
- marginTop: arrowHeight
24967
+ contentWrapper: {
24968
+ overflow: "hidden"
25015
24969
  },
25016
- contentMobile: {
25017
- background: backgroundColor,
25018
- // TODO(benkomalo): this is to "full bleed" the background.
25019
- // The actual content padding differs depending on the host
25020
- // container, so this needs to be fixed eventually.
25021
- marginLeft: negativePhoneMargin,
25022
- marginRight: negativePhoneMargin,
25023
- paddingLeft: phoneMargin,
25024
- paddingRight: phoneMargin
25025
- },
25026
- disclosureArrow: {
25027
- // HACK - positioning at "bottom: 0", doesn't actually position it to
25028
- // the real bottom, because the container is `inline-block`, and it
25029
- // seems to position it to the baseline? We put in a generous
25030
- // fudge factor to position it down to be flush with the content box
25031
- // below it.
25032
- bottom: -(arrowHeight + 5),
25033
- height: arrowHeight,
25034
- left: "50%",
25035
- marginLeft: -(arrowWidth / 2),
25036
- position: "absolute",
25037
- width: arrowWidth
24970
+ transitionCollapsed: {
24971
+ transition: "all 0.25s step-end, grid-template-rows 0.25s, margin-top 0.25s, margin-bottom 0.25s, padding-bottom 0.25s"
24972
+ },
24973
+ transitionExpanded: {
24974
+ transition: "grid-template-rows 0.5s, margin-top 0.5s, margin-bottom 0.5s, padding-bottom 0.5s"
25038
24975
  }
25039
24976
  });
25040
24977
  var Explanation$1 = {
@@ -41297,7 +41234,7 @@ const init = function init(options) {
41297
41234
 
41298
41235
  // This file is processed by a Rollup plugin (replace) to inject the production
41299
41236
  const libName = "@khanacademy/perseus";
41300
- const libVersion = "20.2.0";
41237
+ const libVersion = "20.3.0";
41301
41238
  addLibraryVersionToPerseusDebug(libName, libVersion);
41302
41239
 
41303
41240
  const apiVersion = {