@khanacademy/perseus 13.1.0 → 14.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/CHANGELOG.md +43 -0
  2. package/dist/components/svg-image.d.ts +10 -9
  3. package/dist/es/index.css +0 -7
  4. package/dist/es/index.js +37 -31
  5. package/dist/es/index.js.map +1 -1
  6. package/dist/index.css +0 -7
  7. package/dist/index.js +61 -49
  8. package/dist/index.js.map +1 -1
  9. package/dist/renderer.d.ts +2 -2
  10. package/dist/widgets/matcher.d.ts +1 -1
  11. package/package.json +35 -35
  12. package/src/__stories__/hints-renderer.stories.tsx +41 -44
  13. package/src/__tests__/__snapshots__/renderer.test.tsx.snap +9 -33
  14. package/src/__tests__/article-renderer.test.tsx +2 -3
  15. package/src/__tests__/renderer-api.test.tsx +35 -52
  16. package/src/components/graph.tsx +14 -8
  17. package/src/components/svg-image.tsx +13 -11
  18. package/src/mixins/provide-keypad.tsx +0 -1
  19. package/src/perseus-types.ts +8 -3
  20. package/src/renderer.tsx +2 -2
  21. package/src/styles/khan-exercise.css +0 -2
  22. package/src/styles/perseus-renderer.less +0 -7
  23. package/src/widgets/__stories__/random-widgets.stories.tsx +59 -0
  24. package/src/widgets/__stories__/test-keypad-context-wrapper.tsx +0 -1
  25. package/src/widgets/__testdata__/categorizer.testdata.ts +40 -0
  26. package/src/widgets/__testdata__/dropdown.testdata.ts +38 -0
  27. package/src/widgets/__testdata__/explanation.testdata.ts +30 -0
  28. package/src/widgets/__testdata__/expression.testdata.ts +82 -0
  29. package/src/widgets/__testdata__/interactive-graph-random.testdata.ts +269 -0
  30. package/src/widgets/__testdata__/radio.testdata.ts +63 -0
  31. package/src/widgets/__testdata__/randomizers.ts +51 -0
  32. package/src/widgets/__tests__/__snapshots__/dropdown.test.ts.snap +6 -22
  33. package/src/widgets/__tests__/__snapshots__/graded-group-set-jipt.test.ts.snap +3 -3
  34. package/src/widgets/__tests__/__snapshots__/graded-group-set.test.ts.snap +1 -1
  35. package/src/widgets/__tests__/__snapshots__/graded-group.test.ts.snap +1 -1
  36. package/src/widgets/__tests__/__snapshots__/radio.test.ts.snap +4 -4
  37. package/src/widgets/__tests__/expression-mobile.test.tsx +0 -1
  38. package/src/widgets/__tests__/matcher.test.tsx +1 -1
  39. package/src/widgets/__tests__/randomizers.test.ts +53 -0
  40. package/src/widgets/image.tsx +27 -20
  41. package/src/widgets/matcher.tsx +1 -1
  42. package/src/widgets/radio/choice.tsx +1 -0
  43. package/tsconfig-build.tsbuildinfo +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,48 @@
1
1
  # @khanacademy/perseus
2
2
 
3
+ ## 14.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - [#825](https://github.com/Khan/perseus/pull/825) [`7cb40e4c`](https://github.com/Khan/perseus/commit/7cb40e4c919be50e5ced41e4937178bbf849ec74) Thanks [@benchristel](https://github.com/benchristel)! - We've removed the deprecated `useV2Keypad` prop from the MobileKeypad component.
8
+
9
+ The V2 keypad is now the default, and the old keypad has been removed.
10
+
11
+ Additionally, the mobile keypad no longer accepts the `keypadActive` or
12
+ `setKeypadActive` props. It now gets those values itself from the `KeypadContext`.
13
+
14
+ ### Minor Changes
15
+
16
+ - [#816](https://github.com/Khan/perseus/pull/816) [`cdcd162e`](https://github.com/Khan/perseus/commit/cdcd162ea0902d3ff1d77b1b66ad15f2d55a86cd) Thanks [@jeremywiebe](https://github.com/jeremywiebe)! - Wrap all SvgImage instances in AssetContext (ensures that host applications can correctly wait for all images to load in a renderer before proceeding).
17
+
18
+ * [#788](https://github.com/Khan/perseus/pull/788) [`8f1f0208`](https://github.com/Khan/perseus/commit/8f1f0208fcc08e137053bfd05d330b6f8bf3522d) Thanks [@jeanettehead](https://github.com/jeanettehead)! - create randomized storybook stories for some widgets
19
+
20
+ ### Patch Changes
21
+
22
+ - Updated dependencies [[`7cb40e4c`](https://github.com/Khan/perseus/commit/7cb40e4c919be50e5ced41e4937178bbf849ec74)]:
23
+ - @khanacademy/math-input@16.0.0
24
+
25
+ ## 13.2.0
26
+
27
+ ### Minor Changes
28
+
29
+ - [#797](https://github.com/Khan/perseus/pull/797) [`021f9462`](https://github.com/Khan/perseus/commit/021f946255f423de8df13f6872b0664f79408484) Thanks [@nixterrimus](https://github.com/nixterrimus)! - Change the rational color in radio widget
30
+
31
+ * [#811](https://github.com/Khan/perseus/pull/811) [`bca527ab`](https://github.com/Khan/perseus/commit/bca527abc4d8b29942efec12509f9cf8be401e75) Thanks [@jeremywiebe](https://github.com/jeremywiebe)! - Bump all Wonder Blocks dependencies to latest
32
+
33
+ ### Patch Changes
34
+
35
+ - [#808](https://github.com/Khan/perseus/pull/808) [`8358da80`](https://github.com/Khan/perseus/commit/8358da8010dcb8976d8cfb542afa7e303ce4971a) Thanks [@SonicScrewdriver](https://github.com/SonicScrewdriver)! - Removing unnecessary conflicting CSS for #problemarea.
36
+
37
+ * [#813](https://github.com/Khan/perseus/pull/813) [`691d29b4`](https://github.com/Khan/perseus/commit/691d29b4224a523a3dd8d53a7aab28c80118e7ac) Thanks [@SonicScrewdriver](https://github.com/SonicScrewdriver)! - Removing unused CSS from #problemarea.
38
+
39
+ - [#812](https://github.com/Khan/perseus/pull/812) [`6d31e044`](https://github.com/Khan/perseus/commit/6d31e044d6f5b304e63602795e9bbd7ba443dac5) Thanks [@jeremywiebe](https://github.com/jeremywiebe)! - Fix 'focus' parameter on Renderer's setInputValue function to be optional.
40
+
41
+ - Updated dependencies [[`57e0e18b`](https://github.com/Khan/perseus/commit/57e0e18bd3729cde2e35cfa4ec40b67a5700049c), [`57e0e18b`](https://github.com/Khan/perseus/commit/57e0e18bd3729cde2e35cfa4ec40b67a5700049c), [`bca527ab`](https://github.com/Khan/perseus/commit/bca527abc4d8b29942efec12509f9cf8be401e75)]:
42
+ - @khanacademy/simple-markdown@0.11.0
43
+ - @khanacademy/math-input@15.1.0
44
+ - @khanacademy/pure-markdown@0.2.11
45
+
3
46
  ## 13.1.0
4
47
 
5
48
  ### Minor Changes
@@ -24,6 +24,15 @@ type Props = {
24
24
  zoomToFullSizeOnMobile?: boolean;
25
25
  setAssetStatus: (assetKey: string, loaded: boolean) => void;
26
26
  };
27
+ type DefaultProps = {
28
+ constrainHeight: NonNullable<Props["constrainHeight"]>;
29
+ onUpdate: NonNullable<Props["onUpdate"]>;
30
+ responsive: NonNullable<Props["responsive"]>;
31
+ scale: NonNullable<Props["scale"]>;
32
+ setAssetStatus: NonNullable<Props["setAssetStatus"]>;
33
+ src: NonNullable<Props["src"]>;
34
+ zoomToFullSizeOnMobile: NonNullable<Props["zoomToFullSizeOnMobile"]>;
35
+ };
27
36
  type Label = {
28
37
  coordinates: ReadonlyArray<any>;
29
38
  content: string;
@@ -44,15 +53,7 @@ type State = {
44
53
  };
45
54
  declare class SvgImage extends React.Component<Props, State> {
46
55
  _isMounted: boolean;
47
- static defaultProps: {
48
- constrainHeight: boolean;
49
- onUpdate: () => void;
50
- responsive: boolean;
51
- scale: number;
52
- setAssetStatus: (src: string, status: boolean) => void;
53
- src: string;
54
- zoomToFullSizeOnMobile: boolean;
55
- };
56
+ static defaultProps: DefaultProps;
56
57
  constructor(props: Props);
57
58
  componentDidMount(): void;
58
59
  UNSAFE_componentWillReceiveProps(nextProps: Props): void;
package/dist/es/index.css CHANGED
@@ -130,8 +130,6 @@ div.definition {
130
130
 
131
131
  #problemarea {
132
132
  font-size: 14px;
133
- width: 70%;
134
- min-height: 378px;
135
133
  position: relative;
136
134
  float: left;
137
135
  padding-bottom: 38px;
@@ -2366,11 +2364,6 @@ img.zoom-img {
2366
2364
  .framework-perseus.perseus-mobile .perseus-input-right-align .keypad-input {
2367
2365
  text-align: right;
2368
2366
  }
2369
- .framework-perseus #problemarea input,
2370
- .framework-perseus #problemarea button {
2371
- position: relative;
2372
- z-index: 3;
2373
- }
2374
2367
  .framework-perseus div.paragraph {
2375
2368
  font-family: "Lato", sans-serif;
2376
2369
  font-weight: 400;
package/dist/es/index.js CHANGED
@@ -16521,7 +16521,7 @@ const doJSONP = function doJSONP(url, options) {
16521
16521
  // system (with file://). We replace urls that start with `web+graphie`
16522
16522
  // in the perseus json with this `file+graphie` prefix to indicate that
16523
16523
  // they should have the `file://` protocol instead of `https://`.
16524
- const svgLocalLabelsRegex = /^file\+graphie\:/;
16524
+ const svgLocalLabelsRegex = /^file\+graphie:/;
16525
16525
  const hashRegex = /\/([^/]+)$/;
16526
16526
  function isImageProbablyPhotograph(imageUrl) {
16527
16527
  // TODO(david): Do an inventory to refine this heuristic. For example, what
@@ -22900,6 +22900,7 @@ const styles$r = StyleSheet.create({
22900
22900
  padding: intermediateCheckboxPadding,
22901
22901
  paddingTop: 0,
22902
22902
  marginLeft: 54,
22903
+ color: Color.offBlack64,
22903
22904
  [mediaQueries.smOrSmaller]: {
22904
22905
  padding: intermediateCheckboxPaddingPhone,
22905
22906
  paddingTop: 0
@@ -26696,29 +26697,32 @@ class ImageWidget extends React.Component {
26696
26697
  } = this.props;
26697
26698
  const backgroundImage = this.props.backgroundImage;
26698
26699
  if (backgroundImage.url) {
26699
- image = /*#__PURE__*/React.createElement(SvgImage, {
26700
- src: backgroundImage.url,
26700
+ const url = backgroundImage.url;
26701
+ image = /*#__PURE__*/React.createElement(context$1.Consumer, null, ({
26702
+ setAssetStatus
26703
+ }) => /*#__PURE__*/React.createElement(SvgImage, {
26704
+ src: url,
26701
26705
  alt:
26702
26706
  /* alt text is formatted in a sr-only
26703
- div next to the image in addition to
26704
- the alt attribute.
26705
- If there is no alt text at all,
26706
- we don't put an alt attribute on
26707
- the image, so that screen readers
26708
- know there's something they can't
26709
- read there :(.
26710
- NOTE: React <=0.13 (maybe later)
26711
- has a bug where it won't ever
26712
- remove an attribute, so if this
26713
- alt node is ever defined it's
26714
- not removed. This is sort of
26715
- dangerous, but we usually re-key
26716
- new renderers so that they're
26717
- rendered from scratch anyways,
26718
- so this shouldn't be a problem
26719
- in practice right now, although
26720
- it will exhibit weird behaviour
26721
- while editing. */
26707
+ div next to the image in addition to
26708
+ the alt attribute.
26709
+ If there is no alt text at all,
26710
+ we don't put an alt attribute on
26711
+ the image, so that screen readers
26712
+ know there's something they can't
26713
+ read there :(.
26714
+ NOTE: React <=0.13 (maybe later)
26715
+ has a bug where it won't ever
26716
+ remove an attribute, so if this
26717
+ alt node is ever defined it's
26718
+ not removed. This is sort of
26719
+ dangerous, but we usually re-key
26720
+ new renderers so that they're
26721
+ rendered from scratch anyways,
26722
+ so this shouldn't be a problem
26723
+ in practice right now, although
26724
+ it will exhibit weird behaviour
26725
+ while editing. */
26722
26726
  this.props.alt,
26723
26727
  overrideAriaHidden: true,
26724
26728
  width: backgroundImage.width,
@@ -26732,8 +26736,9 @@ class ImageWidget extends React.Component {
26732
26736
  trackInteraction: this.props.trackInteraction,
26733
26737
  zoomToFullSizeOnMobile: apiOptions.isMobile,
26734
26738
  constrainHeight: apiOptions.isMobile,
26735
- allowFullBleed: apiOptions.isMobile
26736
- });
26739
+ allowFullBleed: apiOptions.isMobile,
26740
+ setAssetStatus: setAssetStatus
26741
+ }));
26737
26742
  }
26738
26743
  if (this.props.alt) {
26739
26744
  alt = /*#__PURE__*/React.createElement("span", {
@@ -27733,16 +27738,18 @@ class Graph extends React.Component {
27733
27738
  const imageData = this.props.backgroundImage;
27734
27739
  if (imageData.url) {
27735
27740
  const scale = this.props.box[0] / interactiveSizes$1.defaultBoxSize;
27736
- image =
27737
- /*#__PURE__*/
27741
+ image = /*#__PURE__*/React.createElement(context$1.Consumer, null, ({
27742
+ setAssetStatus
27743
+ }) => /*#__PURE__*/React.createElement(SvgImage
27738
27744
  // @ts-expect-error - TS2741 - Property 'alt' is missing in type '{ src: any; width: any; height: any; scale: number; responsive: false; }' but required in type 'Pick<Readonly<Props> & Readonly<{ children?: ReactNode; }>, "children" | "height" | "width" | "title" | "alt" | "trackInteraction" | "preloader" | "allowFullBleed" | "extraGraphie" | "overrideAriaHidden">'.
27739
- React.createElement(SvgImage, {
27745
+ , {
27740
27746
  src: imageData.url,
27741
27747
  width: imageData.width,
27742
27748
  height: imageData.height,
27743
27749
  scale: scale,
27744
- responsive: false
27745
- });
27750
+ responsive: false,
27751
+ setAssetStatus: setAssetStatus
27752
+ }));
27746
27753
  } else {
27747
27754
  image = null;
27748
27755
  }
@@ -44082,7 +44089,7 @@ const init = function init(options) {
44082
44089
 
44083
44090
  // This file is processed by a Rollup plugin (replace) to inject the production
44084
44091
  const libName = "@khanacademy/perseus";
44085
- const libVersion = "13.1.0";
44092
+ const libVersion = "14.0.0";
44086
44093
  addLibraryVersionToPerseusDebug(libName, libVersion);
44087
44094
 
44088
44095
  const apiVersion = {
@@ -44637,7 +44644,6 @@ const ProvideKeypad = {
44637
44644
  // @ts-expect-error - TS2339 - Property 'props' does not exist on type '{ readonly propTypes: { readonly apiOptions: React.PropType<{ customKeypad?: boolean | undefined; nativeKeypadProxy?: ((...a: readonly any[]) => unknown) | undefined; }>; readonly keypadStyle: Requireable<any>; }; readonly getInitialState: () => { ...; }; readonly componentDidMount: () => void; readonly componentWil...'.
44638
44645
  ,
44639
44646
  style: _this.props.keypadStyle,
44640
- useV2Keypad: apiOptions.useV2Keypad,
44641
44647
  onAnalyticsEvent: async () => {
44642
44648
  // Intentionally left empty. This component is
44643
44649
  // deprecated and so we don't want/need to instrument