@khanacademy/perseus 19.1.0 → 19.1.2

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,23 @@
1
1
  # @khanacademy/perseus
2
2
 
3
+ ## 19.1.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [#954](https://github.com/Khan/perseus/pull/954) [`43820ff9`](https://github.com/Khan/perseus/commit/43820ff9ce391682b951279a4c6fb9e3db966eb9) Thanks [@benchristel](https://github.com/benchristel)! - Internal: Fix @ts-expect-errors related to Graphie
8
+
9
+ * [#956](https://github.com/Khan/perseus/pull/956) [`14e107f5`](https://github.com/Khan/perseus/commit/14e107f57c10fb3a442e55506810eb309caced24) Thanks [@jeremywiebe](https://github.com/jeremywiebe)! - Fix bug when replacing transformer widget with deprecated-standin
10
+
11
+ * Updated dependencies [[`43820ff9`](https://github.com/Khan/perseus/commit/43820ff9ce391682b951279a4c6fb9e3db966eb9)]:
12
+ - @khanacademy/kmath@0.1.10
13
+
14
+ ## 19.1.1
15
+
16
+ ### Patch Changes
17
+
18
+ - Updated dependencies [[`8c8af142`](https://github.com/Khan/perseus/commit/8c8af1425a5cd257ca894b20bdb481f7148ffa7d)]:
19
+ - @khanacademy/math-input@17.0.1
20
+
3
21
  ## 19.1.0
4
22
 
5
23
  ### Minor Changes
@@ -1,13 +1,14 @@
1
1
  import * as React from "react";
2
2
  import type { Coord } from "../interactive2/types";
3
3
  import type { PerseusImageBackground } from "../perseus-types";
4
+ import type { GridDimensions } from "../util";
4
5
  type Props = {
5
- box: Readonly<[number, number]>;
6
+ box: [number, number];
6
7
  labels: ReadonlyArray<string>;
7
- range: Readonly<[Coord, Coord]>;
8
- step: Readonly<[number, number]>;
9
- gridStep: Readonly<[number, number]>;
10
- snapStep: Readonly<[number, number]>;
8
+ range: [Coord, Coord];
9
+ step: [number, number];
10
+ gridStep: [number, number];
11
+ snapStep: [number, number];
11
12
  markings: string;
12
13
  backgroundImage: PerseusImageBackground;
13
14
  showProtractor: boolean;
@@ -51,7 +52,7 @@ declare class Graph extends React.Component<Props> {
51
52
  graphie: () => any;
52
53
  pointsFromNormalized: (arg1: any, arg2: any) => any;
53
54
  _setupGraphie: (arg1: any) => void;
54
- _getGridConfig: () => any;
55
+ _getGridConfig: () => [GridDimensions, GridDimensions];
55
56
  _updateProtractor: () => void;
56
57
  _updateRuler: () => void;
57
58
  toJSON: () => any;
@@ -1,4 +1,5 @@
1
1
  import * as React from "react";
2
+ import { Graphie as GraphieDrawingContext } from "../util/graphie";
2
3
  import type { Coord } from "../interactive2/types";
3
4
  import type { Range, Size } from "../perseus-types";
4
5
  type Props = {
@@ -29,8 +30,14 @@ type DefaultProps = {
29
30
  responsive: Props["responsive"];
30
31
  addMouseLayer: Props["addMouseLayer"];
31
32
  };
33
+ interface Movable {
34
+ remove(): void;
35
+ }
32
36
  declare class Graphie extends React.Component<Props> {
33
37
  graphieDivRef: React.RefObject<HTMLDivElement>;
38
+ _graphie: GraphieDrawingContext;
39
+ _movables: Record<string, Movable>;
40
+ movables: Record<string, Movable>;
34
41
  static defaultProps: DefaultProps;
35
42
  componentDidMount(): void;
36
43
  shouldComponentUpdate(nextProps: Props): boolean;
@@ -46,7 +53,7 @@ declare class Graphie extends React.Component<Props> {
46
53
  getGraphie: () => any;
47
54
  _range: () => [Coord, Coord];
48
55
  _box: () => Size;
49
- _scale: () => ReadonlyArray<number>;
56
+ _scale: () => Coord;
50
57
  _setupGraphie: () => void;
51
58
  _removeMovables: () => void;
52
59
  _renderMovables: (children: ReadonlyArray<any>, arg2: any) => React.ReactElement;
package/dist/es/index.js CHANGED
@@ -2,7 +2,7 @@ import * as KAS from '@khanacademy/kas';
2
2
  import { keyTranslator, CursorContext, createMathField, convertDotToTimesByLocale, mathQuillInstance, getCursorContext, DesktopKeypad, 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 } from '@khanacademy/wonder-blocks-core';
5
+ import { View, RenderStateRoot, 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';
@@ -9644,15 +9644,6 @@ const GraphUtils = {
9644
9644
  getDistance: function (point1, point2) {
9645
9645
  return point.distanceToPoint(point1, point2);
9646
9646
  },
9647
- /**
9648
- * Round the given coordinates to a given snap value
9649
- * (e.g., nearest 0.2 increment)
9650
- */
9651
- snapCoord: function (coord, snap) {
9652
- return coord.map(function (val, i) {
9653
- return KhanMath.roundToNearest(snap[i], val);
9654
- });
9655
- },
9656
9647
  // Find the angle in degrees between two or three points
9657
9648
  findAngle: function (point1, point2, vertex) {
9658
9649
  if (vertex === undefined) {
@@ -16167,6 +16158,9 @@ class Graphie extends React.Component {
16167
16158
  constructor(...args) {
16168
16159
  super(...args);
16169
16160
  this.graphieDivRef = /*#__PURE__*/React.createRef();
16161
+ this._graphie = new Graphie$1(document.createElement("div"));
16162
+ this._movables = {};
16163
+ this.movables = {};
16170
16164
  /**
16171
16165
  * Allow parents of the <Graphie> component to grab a reference to the
16172
16166
  * underlying graphie object using
@@ -16176,7 +16170,6 @@ class Graphie extends React.Component {
16176
16170
  * Use it for good and not evil.
16177
16171
  */
16178
16172
  this.getGraphie = () => {
16179
- // @ts-expect-error - TS2339 - Property '_graphie' does not exist on type 'Graphie'.
16180
16173
  return this._graphie;
16181
16174
  };
16182
16175
  // bounds-checked range
@@ -16197,10 +16190,11 @@ class Graphie extends React.Component {
16197
16190
  };
16198
16191
  return [ensureMinSize(this.props.box[0]), ensureMinSize(this.props.box[1])];
16199
16192
  };
16193
+ // @ts-expect-error - TS2322: Type '() => number[]' is not assignable to type '() => Coord'.
16200
16194
  this._scale = () => {
16201
16195
  const box = this._box();
16202
16196
  const range = this._range();
16203
- return _.map(box, (pixelDim, i) => {
16197
+ return box.map((pixelDim, i) => {
16204
16198
  const unitDim = range[i][1] - range[i][0];
16205
16199
  return pixelDim / unitDim;
16206
16200
  });
@@ -16208,9 +16202,10 @@ class Graphie extends React.Component {
16208
16202
  this._setupGraphie = () => {
16209
16203
  this._removeMovables();
16210
16204
  const graphieDiv = ReactDOM__default.findDOMNode(this.graphieDivRef.current);
16211
- // @ts-expect-error - TS2769 - No overload matches this call. | TS2339 - Property 'empty' does not exist on type 'JQueryStatic'.
16212
- $(graphieDiv).empty();
16213
- // @ts-expect-error - TS2339 - Property '_graphie' does not exist on type 'Graphie'.
16205
+ if (graphieDiv == null || graphieDiv instanceof Text) {
16206
+ throw new Error("No graphie container div found");
16207
+ }
16208
+ graphieDiv.innerHTML = "";
16214
16209
  const graphie = this._graphie = createGraphie(graphieDiv);
16215
16210
 
16216
16211
  // This has to be called before addMouseLayer. You can re-init
@@ -16222,6 +16217,7 @@ class Graphie extends React.Component {
16222
16217
  });
16223
16218
  // Only add the mouselayer if we actually want one.
16224
16219
  if (this.props.addMouseLayer) {
16220
+ // @ts-expect-error - TS2339: Property 'addMouseLayer' does not exist on type 'Graphie'.
16225
16221
  graphie.addMouseLayer({
16226
16222
  onClick: this.props.onClick,
16227
16223
  onMouseDown: this.props.onMouseDown,
@@ -16230,12 +16226,13 @@ class Graphie extends React.Component {
16230
16226
  setDrawingAreaAvailable: this.props.setDrawingAreaAvailable
16231
16227
  });
16232
16228
  }
16229
+
16230
+ // @ts-expect-error - TS2339: Property 'snap' does not exist on type 'Graphie'.
16233
16231
  graphie.snap = this.props.options.snapStep || [1, 1];
16234
16232
  if (this.props.responsive) {
16235
16233
  // Overwrite fixed styles set in init()
16236
16234
  // TODO(alex): Either make this component always responsive by
16237
16235
  // itself, or always wrap it in other components so that it is.
16238
- // @ts-expect-error - TS2769 - No overload matches this call. | TS2554 - Expected 2 arguments, but got 1.
16239
16236
  $(graphieDiv).css({
16240
16237
  width: "100%",
16241
16238
  height: "100%"
@@ -16249,9 +16246,7 @@ class Graphie extends React.Component {
16249
16246
  };
16250
16247
  this._removeMovables = () => {
16251
16248
  // _.invoke works even when this._movables is undefined
16252
- // @ts-expect-error - TS2339 - Property '_movables' does not exist on type 'Graphie'.
16253
16249
  _.invoke(this._movables, "remove");
16254
- // @ts-expect-error - TS2339 - Property '_movables' does not exist on type 'Graphie'.
16255
16250
  this._movables = {};
16256
16251
  };
16257
16252
  // @ts-expect-error - TS2322 - Type '(children: readonly any[], options: any) => ReactElement<any, string | JSXElementConstructor<any>> | readonly ReactElement<any, string | JSXElementConstructor<any>>[]' is not assignable to type '(children: readonly any[], arg2: any) => ReactElement<any, string | JSXElementConstructor<any>>'.
@@ -16347,7 +16342,6 @@ class Graphie extends React.Component {
16347
16342
  newMovables[key].toFront();
16348
16343
  }
16349
16344
  if (ref) {
16350
- // @ts-expect-error - TS2339 - Property 'movables' does not exist on type 'Graphie'.
16351
16345
  this.movables[ref] = newMovables[key];
16352
16346
  }
16353
16347
  return newMovables[key];
@@ -16355,15 +16349,10 @@ class Graphie extends React.Component {
16355
16349
  };
16356
16350
  // Sort of like react diffing, but for movables
16357
16351
  this._updateMovables = () => {
16358
- // @ts-expect-error - TS2339 - Property '_graphie' does not exist on type 'Graphie'.
16359
16352
  const graphie = this._graphie;
16360
-
16361
- // @ts-expect-error - TS2339 - Property '_movables' does not exist on type 'Graphie'.
16362
16353
  const oldMovables = this._movables;
16363
16354
  const newMovables = {};
16364
- // @ts-expect-error - TS2339 - Property '_movables' does not exist on type 'Graphie'.
16365
16355
  this._movables = newMovables;
16366
- // @ts-expect-error - TS2339 - Property 'movables' does not exist on type 'Graphie'.
16367
16356
  this.movables = {};
16368
16357
 
16369
16358
  // @ts-expect-error - TS2345 - Argument of type 'ReactNode' is not assignable to parameter of type 'readonly any[]'.
@@ -18502,10 +18491,13 @@ const registerWidgets = widgets => {
18502
18491
  */
18503
18492
  const replaceWidget = (name, replacementName) => {
18504
18493
  const substituteWidget = widgets[replacementName];
18505
- if (!substituteWidget && Log) {
18494
+
18495
+ // If the replacement widget isn't found, we need to throw. Otherwise after
18496
+ // removing the deprecated widget, we'll have data asking for a widget type
18497
+ // that doesn't exist at all.
18498
+ if (!substituteWidget) {
18506
18499
  const errorMsg = `Failed to replace ${name} with ${replacementName}`;
18507
- Log.error(errorMsg, Errors.Internal);
18508
- return;
18500
+ throw new PerseusError(errorMsg, Errors.Internal);
18509
18501
  }
18510
18502
  registerWidget(name, substituteWidget);
18511
18503
  };
@@ -27761,21 +27753,23 @@ class Graph extends React.Component {
27761
27753
  // `\text{Dollars}` to the Graph widget.
27762
27754
  const labels = this.props.labels.map(label => Util.unescapeMathMode(label));
27763
27755
  const range = this.props.range;
27756
+ // @ts-expect-error - TS2345: Argument of type 'Element | Text | null' is not assignable to parameter of type 'HTMLElement'.
27764
27757
  const graphie = this._graphie = GraphUtils.createGraphie(graphieDiv);
27765
27758
  const gridConfig = this._getGridConfig();
27759
+ // @ts-expect-error - TS2339: Property 'snap' does not exist on type 'Graphie'.
27766
27760
  graphie.snap = this.props.snapStep;
27767
27761
  if (this.props.markings === "graph") {
27768
27762
  graphie.graphInit({
27769
27763
  range: range,
27770
- scale: _.pluck(gridConfig, "scale"),
27764
+ scale: vector$1.map(gridConfig, g => g.scale),
27771
27765
  axisArrows: "<->",
27772
27766
  labelFormat: function (s) {
27773
27767
  return "\\small{" + s + "}";
27774
27768
  },
27775
27769
  gridStep: this.props.gridStep,
27776
- tickStep: _.pluck(gridConfig, "tickStep"),
27770
+ tickStep: vector$1.map(gridConfig, g => g.tickStep),
27777
27771
  labelStep: 1,
27778
- unityLabels: _.pluck(gridConfig, "unityLabel"),
27772
+ unityLabels: vector$1.map(gridConfig, g => g.unityLabel),
27779
27773
  isMobile: this.props.isMobile
27780
27774
  });
27781
27775
  graphie.label([0, range[1][1]], labels[1], this.props.isMobile ? "below right" : "above");
@@ -27783,7 +27777,7 @@ class Graph extends React.Component {
27783
27777
  } else if (this.props.markings === "grid") {
27784
27778
  graphie.graphInit({
27785
27779
  range: range,
27786
- scale: _.pluck(gridConfig, "scale"),
27780
+ scale: vector$1.map(gridConfig, g => g.scale),
27787
27781
  gridStep: this.props.gridStep,
27788
27782
  axes: false,
27789
27783
  ticks: false,
@@ -27793,7 +27787,7 @@ class Graph extends React.Component {
27793
27787
  } else if (this.props.markings === "none") {
27794
27788
  graphie.init({
27795
27789
  range: range,
27796
- scale: _.pluck(gridConfig, "scale"),
27790
+ scale: vector$1.map(gridConfig, g => g.scale),
27797
27791
  isMobile: this.props.isMobile
27798
27792
  });
27799
27793
  }
@@ -27840,6 +27834,7 @@ class Graph extends React.Component {
27840
27834
  } : null;
27841
27835
  /* eslint-enable indent */
27842
27836
 
27837
+ // @ts-expect-error - Property 'addMouseLayer' does not exist on type 'Graphie'.
27843
27838
  graphie.addMouseLayer({
27844
27839
  onClick: this.props.onClick,
27845
27840
  onMouseDown: onMouseDown,
@@ -27865,10 +27860,7 @@ class Graph extends React.Component {
27865
27860
  }
27866
27861
  };
27867
27862
  this._getGridConfig = () => {
27868
- const self = this;
27869
- return _.map(self.props.step, function (step, i) {
27870
- return Util.gridDimensionConfig(step, self.props.range[i], self.props.box[i], self.props.gridStep[i]);
27871
- });
27863
+ return vector$1.map(this.props.step, (step, i) => Util.gridDimensionConfig(step, this.props.range[i], this.props.box[i], this.props.gridStep[i]));
27872
27864
  };
27873
27865
  this._updateProtractor = () => {
27874
27866
  if (this.protractor) {
@@ -33687,6 +33679,7 @@ const Measurer = createReactClass({
33687
33679
  const graphieDiv = ReactDOM__default.findDOMNode(this.refs.graphieDiv);
33688
33680
  // @ts-expect-error - TS2769 - No overload matches this call. | TS2339 - Property 'empty' does not exist on type 'JQueryStatic'.
33689
33681
  $(graphieDiv).empty();
33682
+ // @ts-expect-error - Argument of type 'Element | Text | null' is not assignable to parameter of type 'HTMLElement'.
33690
33683
  const graphie = this.graphie = GraphUtils.createGraphie(graphieDiv);
33691
33684
  const scale = [40, 40];
33692
33685
  const range = [[0, this.props.box[0] / scale[0]], [0, this.props.box[1] / scale[1]]];
@@ -33694,6 +33687,7 @@ const Measurer = createReactClass({
33694
33687
  range: range,
33695
33688
  scale: scale
33696
33689
  });
33690
+ // @ts-expect-error - Property 'addMouseLayer' does not exist on type 'Graphie'.
33697
33691
  graphie.addMouseLayer({
33698
33692
  allowScratchpad: true,
33699
33693
  setDrawingAreaAvailable: this.props.apiOptions.setDrawingAreaAvailable
@@ -33702,12 +33696,14 @@ const Measurer = createReactClass({
33702
33696
  this.protractor.remove();
33703
33697
  }
33704
33698
  if (this.props.showProtractor) {
33699
+ // @ts-expect-error - Property 'protractor' does not exist on type 'Graphie'.
33705
33700
  this.protractor = graphie.protractor([this.props.protractorX, this.props.protractorY]);
33706
33701
  }
33707
33702
  if (this.ruler) {
33708
33703
  this.ruler.remove();
33709
33704
  }
33710
33705
  if (this.props.showRuler) {
33706
+ // @ts-expect-error - Property 'ruler' does not exist on type 'Graphie'.
33711
33707
  this.ruler = graphie.ruler({
33712
33708
  center: [(range[0][0] + range[0][1]) / 2, (range[1][0] + range[1][1]) / 2],
33713
33709
  label: this.props.rulerLabel,
@@ -38092,6 +38088,7 @@ class Plotter extends React.Component {
38092
38088
  const graphieDiv = ReactDOM__default.findDOMNode(self.refs.graphieDiv);
38093
38089
  // @ts-expect-error - TS2769 - No overload matches this call. | TS2339 - Property 'empty' does not exist on type 'JQueryStatic'.
38094
38090
  $(graphieDiv).empty();
38091
+ // @ts-expect-error - Argument of type 'Element | Text | null' is not assignable to parameter of type 'HTMLElement'.
38095
38092
  const graphie = GraphUtils.createGraphie(graphieDiv);
38096
38093
 
38097
38094
  // TODO(jakesandlund): It's not the react way to hang
@@ -38199,6 +38196,7 @@ class Plotter extends React.Component {
38199
38196
  scale: c.scale,
38200
38197
  isMobile: this.props.apiOptions.isMobile
38201
38198
  });
38199
+ // @ts-expect-error - Property 'addMouseLayer' does not exist on type 'Graphie'.
38202
38200
  graphie.addMouseLayer({
38203
38201
  allowScratchpad: true,
38204
38202
  setDrawingAreaAvailable: this.props.apiOptions.setDrawingAreaAvailable
@@ -41328,7 +41326,7 @@ const VideoTranscriptLink = props => {
41328
41326
  const video = (_result$data = result.data) == null ? void 0 : _result$data.video;
41329
41327
  return /*#__PURE__*/React.createElement(View, {
41330
41328
  style: styles$6.transcriptLink
41331
- }, /*#__PURE__*/React.createElement(Text, null, video == null ? void 0 : video.title), /*#__PURE__*/React.createElement(Strut, {
41329
+ }, /*#__PURE__*/React.createElement(Text$1, null, video == null ? void 0 : video.title), /*#__PURE__*/React.createElement(Strut, {
41332
41330
  size: 10
41333
41331
  }), /*#__PURE__*/React.createElement(Link, {
41334
41332
  href: "/transcript/" + ((video == null ? void 0 : video.contentId) || "videoNotFound"),
@@ -41501,7 +41499,7 @@ const init = function init(options) {
41501
41499
 
41502
41500
  // This file is processed by a Rollup plugin (replace) to inject the production
41503
41501
  const libName = "@khanacademy/perseus";
41504
- const libVersion = "19.1.0";
41502
+ const libVersion = "19.1.2";
41505
41503
  addLibraryVersionToPerseusDebug(libName, libVersion);
41506
41504
 
41507
41505
  const apiVersion = {