@khanacademy/perseus 4.0.1 → 5.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 (210) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/dist/components/highlighting/highlightable-content.d.ts +4 -4
  3. package/dist/components/highlighting/highlightable-content.js.flow +4 -7
  4. package/dist/components/highlighting/ui/highlight-renderer.d.ts +6 -6
  5. package/dist/components/highlighting/ui/highlight-renderer.js.flow +6 -8
  6. package/dist/components/highlighting/ui/highlight-set-renderer.d.ts +5 -5
  7. package/dist/components/highlighting/ui/highlight-set-renderer.js.flow +5 -8
  8. package/dist/components/highlighting/ui/highlight-tooltip.d.ts +2 -2
  9. package/dist/components/highlighting/ui/highlight-tooltip.js.flow +2 -4
  10. package/dist/components/highlighting/ui/highlighting-ui.d.ts +3 -3
  11. package/dist/components/highlighting/ui/highlighting-ui.js.flow +2 -2
  12. package/dist/components/highlighting/ui/selection-tracker.d.ts +5 -5
  13. package/dist/components/highlighting/ui/selection-tracker.js.flow +5 -7
  14. package/dist/components/highlighting/word-indexer.d.ts +2 -2
  15. package/dist/components/highlighting/word-indexer.js.flow +2 -2
  16. package/dist/components/inline-icon.d.ts +35 -1
  17. package/dist/components/inline-icon.js.flow +11 -1
  18. package/dist/components/simple-keypad-input.d.ts +1 -1
  19. package/dist/components/simple-keypad-input.js.flow +1 -1
  20. package/dist/components/tex-buttons.d.ts +2 -2
  21. package/dist/components/tex-buttons.js.flow +2 -2
  22. package/dist/error-boundary.d.ts +4 -4
  23. package/dist/error-boundary.js.flow +4 -6
  24. package/dist/es/index.js +53 -233
  25. package/dist/es/index.js.map +1 -1
  26. package/dist/index.js +53 -233
  27. package/dist/index.js.map +1 -1
  28. package/dist/multi-items/multi-renderer.d.ts +1 -1
  29. package/dist/multi-items/multi-renderer.js.flow +1 -1
  30. package/dist/multi-items/prop-type-builders.d.ts +1 -1
  31. package/dist/multi-items/shape-types.d.ts +1 -1
  32. package/dist/multi-items/shape-types.js.flow +1 -1
  33. package/dist/multi-items/tree-types.d.ts +1 -1
  34. package/dist/multi-items/tree-types.js.flow +1 -1
  35. package/dist/perseus-types.d.ts +0 -1
  36. package/dist/perseus-types.js.flow +0 -1
  37. package/dist/widgets/__stories__/test-keypad-context-wrapper.d.ts +6 -0
  38. package/dist/widgets/__stories__/test-keypad-context-wrapper.js.flow +12 -0
  39. package/dist/widgets/expression.d.ts +2 -2
  40. package/dist/widgets/expression.js.flow +2 -2
  41. package/dist/widgets/interaction/element-container.d.ts +5 -4
  42. package/dist/widgets/interaction/element-container.js.flow +6 -11
  43. package/dist/widgets/label-image/marker.d.ts +4 -4
  44. package/dist/widgets/label-image/marker.js.flow +4 -6
  45. package/dist/widgets/numeric-input.d.ts +0 -2
  46. package/dist/widgets/numeric-input.js.flow +0 -4
  47. package/dist/widgets/radio/base-radio.d.ts +7 -1
  48. package/dist/widgets/radio/base-radio.js.flow +7 -1
  49. package/dist/widgets/radio/choice-icon/choice-icon.d.ts +1 -1
  50. package/dist/widgets/radio/choice-icon/choice-icon.js.flow +1 -1
  51. package/dist/widgets/radio/choice-icon/cross-out-line.d.ts +2 -2
  52. package/dist/widgets/radio/choice-icon/cross-out-line.js.flow +2 -2
  53. package/dist/widgets/radio/focus-ring.d.ts +8 -1
  54. package/dist/widgets/radio/focus-ring.js.flow +8 -1
  55. package/dist/widgets/radio/option-status.d.ts +2 -2
  56. package/dist/widgets/radio/option-status.js.flow +2 -2
  57. package/dist/widgets/video-transcript-link.d.ts +1 -1
  58. package/dist/widgets/video-transcript-link.js.flow +1 -1
  59. package/package.json +4 -4
  60. package/src/__stories__/item-renderer.stories.tsx +2 -6
  61. package/src/__stories__/server-item-renderer.stories.tsx +2 -6
  62. package/src/__testdata__/item-renderer.testdata.ts +1 -1
  63. package/src/__testdata__/renderer.testdata.ts +1 -1
  64. package/src/__tests__/item-renderer.test.tsx +1 -2
  65. package/src/__tests__/renderer-api.test.tsx +1 -5
  66. package/src/__tests__/renderer.test.tsx +1 -1
  67. package/src/components/__stories__/button-group.stories.tsx +2 -6
  68. package/src/components/__stories__/fixed-to-responsive.stories.tsx +14 -16
  69. package/src/components/__stories__/graph.stories.tsx +3 -5
  70. package/src/components/__stories__/graphie.stories.tsx +3 -5
  71. package/src/components/__stories__/hud.stories.tsx +2 -6
  72. package/src/components/__stories__/icon.stories.tsx +1 -1
  73. package/src/components/__stories__/image-loader.stories.tsx +4 -4
  74. package/src/components/__stories__/info-tip.stories.tsx +2 -6
  75. package/src/components/__stories__/inline-icon.stories.tsx +4 -8
  76. package/src/components/__stories__/input-with-examples.stories.tsx +6 -10
  77. package/src/components/__stories__/lint.stories.tsx +12 -12
  78. package/src/components/__stories__/math-input.stories.tsx +4 -8
  79. package/src/components/__stories__/math-output.stories.tsx +3 -5
  80. package/src/components/__stories__/multi-button-group.stories.tsx +2 -6
  81. package/src/components/__stories__/number-input.stories.tsx +6 -8
  82. package/src/components/__stories__/prop-check-box.stories.tsx +9 -9
  83. package/src/components/__stories__/range-input.stories.tsx +4 -6
  84. package/src/components/__stories__/simple-keypad-input.stories.tsx +2 -4
  85. package/src/components/__stories__/sortable.stories.tsx +15 -15
  86. package/src/components/__stories__/stub-tag-editor.stories.tsx +5 -9
  87. package/src/components/__stories__/svg-image.stories.tsx +10 -18
  88. package/src/components/__stories__/tex.stories.tsx +1 -3
  89. package/src/components/__stories__/text-buttons.stories.tsx +10 -22
  90. package/src/components/__stories__/text-input.stories.tsx +4 -10
  91. package/src/components/__stories__/text-list-editor.stories.tsx +1 -3
  92. package/src/components/__stories__/zoomable-tex.stories.tsx +6 -4
  93. package/src/components/__stories__/zoomable.stories.tsx +1 -3
  94. package/src/components/fixed-to-responsive.tsx +0 -1
  95. package/src/components/graph.tsx +0 -4
  96. package/src/components/highlighting/highlightable-content.tsx +4 -7
  97. package/src/components/highlighting/ui/highlight-renderer.tsx +6 -9
  98. package/src/components/highlighting/ui/highlight-set-renderer.tsx +5 -8
  99. package/src/components/highlighting/ui/highlight-tooltip.tsx +2 -2
  100. package/src/components/highlighting/ui/highlighting-ui.tsx +5 -15
  101. package/src/components/highlighting/ui/selection-tracker.tsx +6 -9
  102. package/src/components/highlighting/word-indexer.tsx +2 -6
  103. package/src/components/inline-icon.tsx +2 -2
  104. package/src/components/math-input.tsx +0 -2
  105. package/src/components/number-input.tsx +0 -2
  106. package/src/components/simple-keypad-input.tsx +2 -2
  107. package/src/components/tex-buttons.tsx +2 -2
  108. package/src/components/text-list-editor.tsx +0 -4
  109. package/src/components/visibility-observer/__stories__/visibility-observer.stories.tsx +1 -3
  110. package/src/components/zoomable-tex.tsx +0 -2
  111. package/src/components/zoomable.tsx +0 -4
  112. package/src/definition-context.tsx +0 -1
  113. package/src/error-boundary.tsx +4 -7
  114. package/src/hints-renderer.tsx +1 -1
  115. package/src/interactive2/__tests__/movable-point.test.ts +0 -1
  116. package/src/item-renderer.tsx +0 -5
  117. package/src/mixins/changeable.ts +1 -1
  118. package/src/multi-items/__stories__/multi-renderer.stories.tsx +1 -5
  119. package/src/multi-items/__tests__/items.test.ts +3 -13
  120. package/src/multi-items/__tests__/multi-renderer.test.tsx +3 -4
  121. package/src/multi-items/__tests__/prop-type-builders.test.ts +1 -1
  122. package/src/multi-items/__tests__/trees.test.ts +2 -10
  123. package/src/multi-items/multi-renderer.tsx +7 -10
  124. package/src/multi-items/prop-type-builders.ts +1 -1
  125. package/src/multi-items/shape-types.ts +1 -1
  126. package/src/multi-items/tree-types.ts +1 -1
  127. package/src/perseus-markdown.tsx +0 -2
  128. package/src/perseus-types.ts +1 -4
  129. package/src/renderer.tsx +2 -5
  130. package/src/server-item-renderer.tsx +0 -3
  131. package/src/util/graphie.ts +3 -3
  132. package/src/util/interactive.ts +0 -4
  133. package/src/util/math.ts +0 -3
  134. package/src/widgets/__stories__/categorizer.stories.tsx +1 -1
  135. package/src/widgets/__stories__/cs-program.stories.tsx +1 -1
  136. package/src/widgets/__stories__/definition.stories.tsx +3 -7
  137. package/src/widgets/__stories__/dropdown.stories.tsx +1 -1
  138. package/src/widgets/__stories__/explanation.stories.tsx +2 -2
  139. package/src/widgets/__stories__/expression.stories.tsx +113 -13
  140. package/src/widgets/__stories__/graded-group-set.stories.tsx +1 -1
  141. package/src/widgets/__stories__/graded-group.stories.tsx +1 -1
  142. package/src/widgets/__stories__/grapher.stories.tsx +7 -21
  143. package/src/widgets/__stories__/group.stories.tsx +1 -1
  144. package/src/widgets/__stories__/iframe.stories.tsx +1 -1
  145. package/src/widgets/__stories__/image.stories.tsx +2 -2
  146. package/src/widgets/__stories__/input-number.stories.tsx +3 -12
  147. package/src/widgets/__stories__/interaction.stories.tsx +1 -1
  148. package/src/widgets/__stories__/interactive-graph.stories.tsx +9 -9
  149. package/src/widgets/__stories__/matcher.stories.tsx +1 -1
  150. package/src/widgets/__stories__/matrix.stories.tsx +1 -1
  151. package/src/widgets/__stories__/number-line.stories.tsx +1 -1
  152. package/src/widgets/__stories__/numeric-input.stories.tsx +3 -5
  153. package/src/widgets/__stories__/orderer.stories.tsx +1 -1
  154. package/src/widgets/__stories__/passage-ref.stories.tsx +2 -2
  155. package/src/widgets/__stories__/passage.stories.tsx +3 -9
  156. package/src/widgets/__stories__/radio.stories.tsx +3 -5
  157. package/src/widgets/__stories__/sorter.stories.tsx +1 -1
  158. package/src/widgets/__stories__/{on-screen-keypad.stories.tsx → test-keypad-context-wrapper.tsx} +15 -57
  159. package/src/widgets/__stories__/transformer.stories.tsx +1 -1
  160. package/src/widgets/__stories__/unit.stories.tsx +1 -3
  161. package/src/widgets/__stories__/video-transcript-link.stories.tsx +2 -6
  162. package/src/widgets/__stories__/video.stories.tsx +1 -1
  163. package/src/widgets/__testdata__/expression.testdata.ts +16 -12
  164. package/src/widgets/__testdata__/group.testdata.ts +0 -2
  165. package/src/widgets/__testdata__/numeric-input.testdata.ts +0 -1
  166. package/src/widgets/__testdata__/transformer.testdata.ts +0 -1
  167. package/src/widgets/__tests__/group.test.tsx +0 -2
  168. package/src/widgets/__tests__/radio/focus-ring.test.tsx +0 -1
  169. package/src/widgets/__tests__/radio.test.ts +1 -1
  170. package/src/widgets/expression.tsx +4 -4
  171. package/src/widgets/graded-group-set.tsx +0 -4
  172. package/src/widgets/graded-group.tsx +0 -4
  173. package/src/widgets/grapher/util.tsx +1 -5
  174. package/src/widgets/grapher.tsx +0 -5
  175. package/src/widgets/group.tsx +0 -1
  176. package/src/widgets/interaction/element-container.tsx +7 -8
  177. package/src/widgets/interaction.tsx +0 -1
  178. package/src/widgets/interactive-graph.tsx +3 -62
  179. package/src/widgets/label-image/__stories__/answer-choices.stories.tsx +2 -4
  180. package/src/widgets/label-image/__stories__/marker.stories.tsx +9 -19
  181. package/src/widgets/label-image/marker.tsx +4 -4
  182. package/src/widgets/label-image.tsx +1 -1
  183. package/src/widgets/measurer.tsx +0 -1
  184. package/src/widgets/number-line.tsx +0 -2
  185. package/src/widgets/numeric-input.tsx +0 -3
  186. package/src/widgets/orderer.tsx +0 -3
  187. package/src/widgets/passage/passage-markdown.tsx +3 -3
  188. package/src/widgets/passage-ref-target.tsx +0 -1
  189. package/src/widgets/passage.tsx +1 -1
  190. package/src/widgets/plotter.tsx +0 -1
  191. package/src/widgets/radio/__stories__/base-radio.stories.tsx +13 -21
  192. package/src/widgets/radio/__stories__/choice-icon.stories.tsx +9 -11
  193. package/src/widgets/radio/__stories__/choice-none-above.stories.tsx +1 -1
  194. package/src/widgets/radio/__stories__/choice.stories.tsx +4 -4
  195. package/src/widgets/radio/__stories__/focus-ring.stories.tsx +1 -1
  196. package/src/widgets/radio/__stories__/option-status.stories.tsx +2 -4
  197. package/src/widgets/radio/base-radio.tsx +2 -2
  198. package/src/widgets/radio/choice-icon/choice-icon.tsx +5 -5
  199. package/src/widgets/radio/choice-icon/cross-out-line.tsx +1 -3
  200. package/src/widgets/radio/choice-none-above.tsx +2 -2
  201. package/src/widgets/radio/choice.tsx +1 -3
  202. package/src/widgets/radio/focus-ring.tsx +1 -1
  203. package/src/widgets/radio/option-status.tsx +2 -4
  204. package/src/widgets/radio/widget.tsx +0 -1
  205. package/src/widgets/reaction-diagram.tsx +2 -2
  206. package/src/widgets/transformer.tsx +1 -16
  207. package/src/widgets/video-transcript-link.tsx +1 -1
  208. package/src/widgets.ts +1 -1
  209. package/src/zoom.ts +0 -3
  210. package/tsconfig.tsbuildinfo +1 -1
@@ -63,12 +63,8 @@ class Zoomable extends React.Component<Props, State> {
63
63
  const firstChild = parentNode.firstElementChild;
64
64
 
65
65
  return {
66
- // $FlowFixMe[incompatible-use]
67
- // $FlowFixMe[prop-missing]
68
66
  // @ts-expect-error [FEI-5003] - TS2531 - Object is possibly 'null'. | TS2339 - Property 'offsetWidth' does not exist on type 'Element'.
69
67
  width: firstChild.offsetWidth,
70
- // $FlowFixMe[incompatible-use]
71
- // $FlowFixMe[prop-missing]
72
68
  // @ts-expect-error [FEI-5003] - TS2531 - Object is possibly 'null'. | TS2339 - Property 'offsetHeight' does not exist on type 'Element'.
73
69
  height: firstChild.offsetHeight,
74
70
  };
@@ -34,7 +34,6 @@ export class DefinitionProvider extends React.Component<
34
34
  };
35
35
 
36
36
  // Method to update state
37
- // $FlowFixMe[signature-verification-failure]
38
37
  setActiveDefinitionId = (activeDefinitionId?: string | null): void => {
39
38
  this.setState((prevState: ProviderState) => ({activeDefinitionId}));
40
39
  };
@@ -2,18 +2,15 @@ import * as React from "react";
2
2
 
3
3
  import {Errors, Log} from "./logging/log";
4
4
 
5
- type ErrorBoundaryProps = {
5
+ type Props = {
6
6
  children: React.ReactNode;
7
7
  };
8
- type ErrorBoundaryState = {
8
+ type State = {
9
9
  error: string;
10
10
  };
11
11
 
12
- class ErrorBoundary extends React.Component<
13
- ErrorBoundaryProps,
14
- ErrorBoundaryState
15
- > {
16
- constructor(props: ErrorBoundaryProps) {
12
+ class ErrorBoundary extends React.Component<Props, State> {
13
+ constructor(props: Props) {
17
14
  super(props);
18
15
  this.state = {error: ""};
19
16
  }
@@ -77,7 +77,7 @@ class HintsRenderer extends React.Component<Props, State> {
77
77
  this._cacheHintImages();
78
78
  }
79
79
 
80
- // Force number to make Flow happy
80
+ // Force number to make TypeScript happy
81
81
  const prevHintsVisible = prevProps.hintsVisible || 0;
82
82
  const nextHintsVisible = this.props.hintsVisible || 0;
83
83
 
@@ -53,7 +53,6 @@ describe("MovablePoint", function () {
53
53
  it("should snap to the grid when a snap is specified", function () {
54
54
  const point = createPoint({
55
55
  coord: [1.1, 1.1],
56
- // $FlowFixMe[prop-missing]
57
56
  // @ts-expect-error [FEI-5003] - TS2339 - Property 'constraints' does not exist on type '(graphie: any, movable: any, options: any) => void'.
58
57
  constraints: MovablePoint.constraints.snap([1, 1]),
59
58
  }).point;
@@ -174,10 +174,6 @@ class ItemRenderer extends React.Component<Props, State> {
174
174
  // strangeness instead of relying on React's normal render() method.
175
175
  // TODO(alpert): Figure out how to clean this up somehow
176
176
  reactRender(
177
- // metadata (from item.question, aka PerseusRenderer)
178
- // replace (also item.question, aka PerseusRenderer)
179
- // savedState (I _think_ this is serializedState on Renderer)
180
- // $FlowFixMe[prop-missing] metadata, replace, savedState (see above)
181
177
  <Renderer
182
178
  ref={(node) => {
183
179
  if (!node) {
@@ -293,7 +289,6 @@ class ItemRenderer extends React.Component<Props, State> {
293
289
  this.props.apiOptions.onFocusChange(
294
290
  this._currentFocus,
295
291
  prevFocus,
296
- // $FlowFixMe[incompatible-call]: onFocusChange expects an HTMLElement or nothing
297
292
  didFocusInput && keypadElement && keypadElement.getDOMNode(),
298
293
  );
299
294
  }
@@ -82,7 +82,7 @@ const _changeSingle = function (
82
82
  * this.change(propName) -> returns a lambda that takes a prop value to
83
83
  * set and a callback to call after having set that value.
84
84
  */
85
- // TODO(WEB-1727): use proper flow syntax for overloaded functions
85
+ // TODO(WEB-1727): use proper TypeScript syntax for overloaded functions
86
86
  export const change: ChangeFn = function (
87
87
  newPropsOrSinglePropName,
88
88
  propValue,
@@ -13,14 +13,11 @@ type Story = {
13
13
  title: string;
14
14
  };
15
15
 
16
- export const SingleItem: React.FC<StoryArgs> = (args): React.ReactElement => {
16
+ export const SingleItem = (args: StoryArgs): React.ReactElement => {
17
17
  const item = {
18
18
  _multi: {
19
- // $FlowFixMe[not-an-object]
20
19
  ...question1._multi,
21
20
  blurb: {
22
- // $FlowFixMe[not-an-object]
23
- // $FlowFixMe[prop-missing]
24
21
  ...question1._multi.blurb,
25
22
  content:
26
23
  "This is a short snippet to help you understand the context of the question. We call it the 'blurb'.",
@@ -51,7 +48,6 @@ export const SingleItem: React.FC<StoryArgs> = (args): React.ReactElement => {
51
48
  </HeadingSmall>
52
49
  <View style={styles.hints}>
53
50
  {
54
- // $FlowFixMe[prop-missing]
55
51
  // @ts-expect-error [FEI-5003] - TS2339 - Property 'firstN' does not exist on type 'readonly ReactNode[]'.
56
52
  hints?.firstN(2)
57
53
  }
@@ -157,12 +157,8 @@ describe("inferItemShape", () => {
157
157
  /**
158
158
  * TODO(somewhatabstract, JIRA-XXXX):
159
159
  * The Tree types are really hard to work with properly.
160
- */
161
- // $FlowFixMe[incompatible-cast]
160
+ */ buildEmptyItemTreeForShape(shapes.hint),
162
161
  buildEmptyItemTreeForShape(shapes.hint),
163
- // $FlowFixMe[incompatible-cast]
164
- buildEmptyItemTreeForShape(shapes.hint),
165
- // $FlowFixMe[incompatible-cast]
166
162
  buildEmptyItemTreeForShape(shapes.hint),
167
163
  ] as ItemArrayNode);
168
164
  expect(shapes.arrayOf(shapes.hint)).toEqual(inferItemShape(item));
@@ -173,12 +169,8 @@ describe("inferItemShape", () => {
173
169
  /**
174
170
  * TODO(somewhatabstract, JIRA-XXXX):
175
171
  * The Tree types are really hard to work with properly.
176
- */
177
- // $FlowFixMe[incompatible-cast]
178
- buildEmptyItemTreeForShape(shapes.hint),
179
- // $FlowFixMe[incompatible-cast]
172
+ */ buildEmptyItemTreeForShape(shapes.hint),
180
173
  buildEmptyItemTreeForShape(shapes.content),
181
- // $FlowFixMe[incompatible-cast]
182
174
  buildEmptyItemTreeForShape(shapes.hint),
183
175
  ] as ItemArrayNode);
184
176
  expect(shapes.arrayOf(shapes.hint)).toEqual(inferItemShape(item));
@@ -214,9 +206,7 @@ const item: Item = treeToItem({
214
206
  /**
215
207
  * TODO(somewhatabstract, JIRA-XXXX):
216
208
  * The Tree types are really hard to work with properly.
217
- */
218
- // $FlowFixMe[incompatible-cast]
219
- b: [content(2), content(3), content(4)] as ItemArrayNode,
209
+ */ b: [content(2), content(3), content(4)] as ItemArrayNode,
220
210
  c: {
221
211
  d: content(5),
222
212
  e: hint(6),
@@ -23,9 +23,8 @@ import type {Item} from "../item-types";
23
23
  import type {Tree} from "../tree-types";
24
24
 
25
25
  // A little helper used in the render callback of a MultiRenderer.
26
- const SimpleLayout: React.FC<{
27
- renderers: any;
28
- }> = ({renderers}): React.ReactElement => {
26
+ type Props = {renderers: any};
27
+ const SimpleLayout = ({renderers}: Props): React.ReactElement => {
29
28
  if (renderers == null) {
30
29
  throw new Error("renderers was null");
31
30
  }
@@ -580,7 +579,7 @@ describe("multi-item renderer", () => {
580
579
  // ("mock-widget 1"). This verifies that the MultiRenderer has
581
580
  // correctly passed down a functioning `findWidgets` prop to the
582
581
  // widgets.
583
- // Oh the Flow warnings we'll suppress. Welcome to multi items.
582
+ // Oh the TypeScript warnings we'll suppress. Welcome to multi items.
584
583
  const widget1 = result.question[0].props.findWidgets("mock-widget 1");
585
584
 
586
585
  // Assert
@@ -6,7 +6,7 @@ import shapes from "../shapes";
6
6
  // tests. Rewrite them once we're using the prop-types library.
7
7
  describe.skip("buildPropTypeForShape", () => {
8
8
  // The value we're wrapping might not be a valid ItemTree - that's the
9
- // point of testing this PropType - so we disable Flow checking by casting
9
+ // point of testing this PropType - so we disable type checking by casting
10
10
  // `value` to type `any`. The current implementation of `treeToItem` can
11
11
  // handle that possibility.
12
12
  const tryPropType = (propType: any, value: any) =>
@@ -26,13 +26,13 @@ describe("buildMapper", () => {
26
26
  }
27
27
 
28
28
  function tags(...elements): TagsNode {
29
- // This function mostly exists as a shorthand way to clarify to Flow
29
+ // This function mostly exists as a shorthand way to clarify to TypeScript
30
30
  // that this is a TagsNode, not a confused ItemArrayNode.
31
31
  return elements;
32
32
  }
33
33
 
34
34
  function array(...elements): ItemArrayNode {
35
- // This function mostly exists as a shorthand way to clarify to Flow
35
+ // This function mostly exists as a shorthand way to clarify to TypeScript
36
36
  // that this is an ItemArrayNode, not a confused TagsNode.
37
37
  /**
38
38
  * TODO(somewhatabstract, JIRA-XXXX):
@@ -288,18 +288,10 @@ describe("buildMapper", () => {
288
288
 
289
289
  it("uses the array mapper return value to construct the new tree", () => {
290
290
  const mapper = buildMapper()
291
- // $FlowFixMe[not-a-function]
292
- // $FlowFixMe[prop-missing]
293
- // $FlowFixMe[incompatible-use]
294
291
  // @ts-expect-error [FEI-5003] - TS2571 - Object is of type 'unknown'.
295
292
  .setContentMapper((c) => c.content)
296
- // $FlowFixMe[not-a-function]
297
- // $FlowFixMe[prop-missing]
298
- // $FlowFixMe[incompatible-use]
299
293
  // @ts-expect-error [FEI-5003] - TS2571 - Object is of type 'unknown'.
300
294
  .setHintMapper((h) => h.content)
301
- // $FlowFixMe[not-a-function]
302
- // $FlowFixMe[prop-missing]
303
295
  // @ts-expect-error [FEI-5003] - TS2571 - Object is of type 'unknown'.
304
296
  .setTagsMapper((t) => t.join(", "))
305
297
  .setArrayMapper((mappedArray, originalArray, shape, path) => {
@@ -1,6 +1,6 @@
1
1
  /* eslint-disable react/no-unsafe */
2
- // TODO(mdr): There are some Flow errors in this file, and they're tricky, so
3
- // I'm skipping Flow errors for now.
2
+ // TODO(mdr): There are some TypeScript errors in this file, and they're tricky, so
3
+ // I'm skipping TypeScript errors for now.
4
4
  /**
5
5
  * Main entry point to the MultiRenderer render portion.
6
6
  *
@@ -36,9 +36,8 @@
36
36
  * </MultiRenderer>
37
37
  */
38
38
  import * as i18n from "@khanacademy/wonder-blocks-i18n";
39
- import {StyleSheet, css} from "aphrodite";
40
- // eslint-disable-next-line import/no-extraneous-dependencies
41
- import lens from "hubble";
39
+ import {StyleSheet, css} from "aphrodite"; // eslint-disable-line import/no-extraneous-dependencies
40
+ import lens from "hubble"; // eslint-disable-line import/no-extraneous-dependencies
42
41
  import * as React from "react";
43
42
 
44
43
  import HintsRenderer from "../hints-renderer";
@@ -87,7 +86,7 @@ type RendererDataTree = Tree<ContentRendererData, HintRendererData, null>;
87
86
 
88
87
  /**
89
88
  * TODO(somewhatabstract, JIRA-XXXX):
90
- * Some usage of this type somewhere is causing Flow to believe that these
89
+ * Some usage of this type somewhere is causing TypeScript to believe that these
91
90
  * elements should be components. Don't know where that is, to fix it up
92
91
  * properly. In reality, these types are just too hard to use and aren't
93
92
  * really helping us out as I now have to suppress this rather than
@@ -245,7 +244,7 @@ class MultiRenderer extends React.Component<Props, State> {
245
244
  // were to change every render, it would cause the Renderer to
246
245
  // re-render a lot more than is necessary. Don't re-compute this
247
246
  // element unless it is necessary!
248
- // HACK(mdr): Flow can't prove that this is a ContentRendererData,
247
+ // HACK(mdr): TypeScript can't prove that this is a ContentRendererData,
249
248
  // because of how we awkwardly construct it in order to obtain a
250
249
  // circular reference. But it is, I promise.
251
250
  const data: any = {ref: null, makeRenderer: null};
@@ -264,9 +263,7 @@ class MultiRenderer extends React.Component<Props, State> {
264
263
  * if this spread is including undocumented props so mapping
265
264
  * one to one could introduce a bug. Need to work out the exact
266
265
  * type for ContentNode and then fix this.
267
- */
268
- // $FlowFixMe[cannot-spread-inexact]
269
- // @ts-expect-error [FEI-5003] - TS2322 - Type '{ ref: (e: any) => any; findExternalWidgets: (criterion: any) => readonly (Widget | null | undefined)[]; serializedState: any; onSerializedStateUpdated: (state: any) => void; __type: "content" | "item"; ... 9 more ...; reviewMode?: boolean | ... 1 more ... | undefined; }' is not assignable to type 'InexactPartial<Pick<Readonly<Props> & Readonly<{ children?: ReactNode; }>, "content" | "images" | "onRender" | "linterContext" | "widgets" | "alwaysUpdate" | ... 6 more ... | "serializedState">>'.
266
+ */ // @ts-expect-error [FEI-5003] - TS2322 - Type '{ ref: (e: any) => any; findExternalWidgets: (criterion: any) => readonly (Widget | null | undefined)[]; serializedState: any; onSerializedStateUpdated: (state: any) => void; __type: "content" | "item"; ... 9 more ...; reviewMode?: boolean | ... 1 more ... | undefined; }' is not assignable to type 'InexactPartial<Pick<Readonly<Props> & Readonly<{ children?: ReactNode; }>, "content" | "images" | "onRender" | "linterContext" | "widgets" | "alwaysUpdate" | ... 6 more ... | "serializedState">>'.
270
267
  <Renderer
271
268
  {...this._getRendererProps()}
272
269
  {...content}
@@ -2,7 +2,7 @@
2
2
  * Utility functions to build React PropTypes for multi-items and shapes.
3
3
  *
4
4
  * If you're writing new components, though, consider using the Item and Shape
5
- * Flow types instead.
5
+ * types instead.
6
6
  */
7
7
  /* instanbul ignore file */
8
8
 
@@ -11,7 +11,7 @@
11
11
  * Shapes also enable us to traverse a multi-item-shaped tree with confidence,
12
12
  * even when we can't infer the shape from the tree alone.
13
13
  *
14
- * We *could* go all-in on a more general library to make certain Flow types
14
+ * We *could* go all-in on a more general library to make certain types
15
15
  * runtime-inspectable, in order to DRY some things up, but that's probably a
16
16
  * big ol' infrastructural magic mess, and the narrower scope of Shapes makes
17
17
  * it easier to be confident that we've covered all cases rather than having to
@@ -34,7 +34,7 @@ export type ObjectNode<C, H, T> = {
34
34
  * TODO(somewhatabstract, JIRA-XXXX):
35
35
  * We should ditch this type or create some helpers for working with it.
36
36
  * As it stands, consumers have to check each node's type before using it
37
- * in order to ensure that flow can track its refinement and appropriate use.
37
+ * in order to ensure that TypeScript can track its refinement and appropriate use.
38
38
  * It's messy.
39
39
  */
40
40
  // @ts-expect-error [FEI-5003] - TS2456 - Type alias 'Tree' circularly references itself. | TS2315 - Type 'ArrayNode' is not generic.
@@ -397,10 +397,8 @@ export default {
397
397
  parse: parse,
398
398
  parseInline: inlineParser,
399
399
  reactFor: SimpleMarkdown.reactFor,
400
- // $FlowFixMe[incompatible-use]
401
400
  ruleOutput: SimpleMarkdown.ruleOutput(rules, "react") as any,
402
401
  basicOutput: SimpleMarkdown.reactFor(
403
- // $FlowFixMe[incompatible-use]
404
402
  SimpleMarkdown.ruleOutput(rules, "react"),
405
403
  ) as any,
406
404
  sanitizeUrl: SimpleMarkdown.sanitizeUrl,
@@ -732,9 +732,6 @@ export type PerseusNumericInputWidgetOptions = {
732
732
  size: string;
733
733
  // A coefficient style number allows the student to use - for -1 and an empty string to mean 1.
734
734
  coefficient: boolean;
735
- // Whether we're asking for all correct solutions or only one
736
- // NOTE: perseus_data.go says this is required even though it isn't necessary.
737
- multipleNumberInput?: boolean;
738
735
  // Whether to right-align the text or not
739
736
  // NOTE: perseus_data.go says this is required even though it isn't necessary.
740
737
  rightAlign?: boolean;
@@ -1423,7 +1420,7 @@ export type PerseusInputNumberWidgetOptions = {
1423
1420
  customKeypad?: boolean;
1424
1421
  };
1425
1422
 
1426
- // TODO(FEI-3983): Create proper flow types for these.
1423
+ // TODO(FEI-3983): Create proper types for these.
1427
1424
  export type PerseusExampleGraphieWidgetOptions = any;
1428
1425
  export type PerseusExampleWidgetOptions = any;
1429
1426
  export type PerseusLightsPuzzleWidgetOptions = any;
package/src/renderer.tsx CHANGED
@@ -150,7 +150,7 @@ type Props = {
150
150
  findExternalWidgets: any;
151
151
  highlightedWidgets?: ReadonlyArray<any>;
152
152
  images: PerseusRenderer["images"];
153
- keypadElement?: any; // TODO(kevinb): add proper flow types,
153
+ keypadElement?: any; // TODO(kevinb): add proper types,
154
154
  onInteractWithWidget: (id: string) => void;
155
155
  onRender: (node?: any) => void;
156
156
  problemNum?: number;
@@ -593,11 +593,9 @@ class Renderer extends React.Component<Props, State> {
593
593
  interactionTracker = this._interactionTrackers[id] =
594
594
  new InteractionTracker(
595
595
  apiOptions.trackInteraction,
596
- // $FlowFixMe[incompatible-call]
597
596
  // @ts-expect-error [FEI-5003] - TS2345 - Argument of type 'string | null | undefined' is not assignable to parameter of type 'string'.
598
597
  widgetInfo && widgetInfo.type,
599
598
  id,
600
- // $FlowFixMe[incompatible-call]
601
599
  // @ts-expect-error [FEI-5003] - TS2345 - Argument of type 'string | null | undefined' is not assignable to parameter of type 'string'.
602
600
  Widgets.getTracking(widgetInfo && widgetInfo.type),
603
601
  );
@@ -1086,7 +1084,7 @@ class Renderer extends React.Component<Props, State> {
1086
1084
  const isString = typeof nodeOut === "string";
1087
1085
  if (typeof nodeOut === "string" && lastWasString) {
1088
1086
  /**
1089
- * We know that last was string, but Flow can't see this
1087
+ * We know that last was string, but TypeScript can't see this
1090
1088
  * refinement.
1091
1089
  */
1092
1090
  result[result.length - 1] += nodeOut;
@@ -1308,7 +1306,6 @@ class Renderer extends React.Component<Props, State> {
1308
1306
  {({setAssetStatus}) => (
1309
1307
  <SvgImage
1310
1308
  setAssetStatus={setAssetStatus}
1311
- /* $FlowFixMe[incompatible-type]: sanitizeUrl() can return null */
1312
1309
  // @ts-expect-error [FEI-5003] - TS2322 - Type 'string | null | undefined' is not assignable to type 'string | undefined'.
1313
1310
  src={PerseusMarkdown.sanitizeUrl(node.target)}
1314
1311
  alt={node.alt}
@@ -171,12 +171,9 @@ export class ServerItemRenderer
171
171
  onFocusChange(
172
172
  this._currentFocus,
173
173
  prevFocus,
174
- // $FlowFixMe[incompatible-call]: onFocusChange expects an HTMLElement or nothing
175
174
  didFocusInput && keypadElement && keypadElement.getDOMNode(),
176
- // $FlowFixMe[incompatible-call]: onFocusChange expects an HTMLElement or nothing
177
175
  // @ts-expect-error [FEI-5003] - TS2345 - Argument of type 'false | Element | Text | null | undefined' is not assignable to parameter of type 'HTMLElement | undefined'.
178
176
  didFocusInput &&
179
- // $FlowFixMe[incompatible-call]: onFocusChange expects an HTMLElement or nothing
180
177
  this.questionRenderer.getDOMNodeForPath(newFocus),
181
178
  );
182
179
  }
@@ -1034,7 +1034,7 @@ GraphUtils.createGraphie = function (el: any) {
1034
1034
  * the function at i
1035
1035
  * @param {[]} rangeArray array of ranges over which the
1036
1036
  * corresponding functions are defined
1037
- * @return {Raphael set}
1037
+ * @return {Set<any>} set of paths
1038
1038
  */
1039
1039
  plotPiecewise: function (fnArray, rangeArray) {
1040
1040
  const paths = raphael.set();
@@ -1058,8 +1058,8 @@ GraphUtils.createGraphie = function (el: any) {
1058
1058
  * return a Raphael set of Raphael circle objects at those
1059
1059
  * coordinates
1060
1060
  *
1061
- * @param {Array of arrays} endpointArray
1062
- * @return {Raphael set}
1061
+ * @param {Array<[number, number]>} endpointArray
1062
+ * @return {Set<any>} set of circles
1063
1063
  */
1064
1064
  plotEndpointCircles: function (endpointArray) {
1065
1065
  const circles = raphael.set();
@@ -3510,7 +3510,6 @@ function Protractor(graph: any, center: any) {
3510
3510
  }
3511
3511
  const time = Math.abs(this.rotation - angle) * 5;
3512
3512
  $({0: this.rotation}).animate(
3513
- // $FlowFixMe[unsupported-syntax]
3514
3513
  {0: angle},
3515
3514
  {
3516
3515
  duration: time,
@@ -3578,11 +3577,8 @@ function Ruler(graphie: any, options: any) {
3578
3577
  if (options.ticksPerUnit === 10) {
3579
3578
  // decimal, as on a centimeter ruler
3580
3579
  tickHeightMap = {
3581
- // $FlowFixMe[unsupported-syntax]
3582
3580
  10: tickHeight,
3583
- // $FlowFixMe[unsupported-syntax]
3584
3581
  5: tickHeight * 0.55,
3585
- // $FlowFixMe[unsupported-syntax]
3586
3582
  1: tickHeight * 0.35,
3587
3583
  };
3588
3584
  } else {
package/src/util/math.ts CHANGED
@@ -91,8 +91,6 @@ const KhanMath = {
91
91
 
92
92
  return true;
93
93
  },
94
-
95
- // $FlowFixMe[incompatible-return]
96
94
  // @ts-expect-error [FEI-5003] - TS2366 - Function lacks ending return statement and return type does not include 'undefined'.
97
95
  getPrimeFactorization: function (number: number): ReadonlyArray<number> {
98
96
  if (number === 1) {
@@ -160,7 +158,6 @@ const KhanMath = {
160
158
  // tolerance can't be bigger than 1, sorry
161
159
  toFraction: function (
162
160
  decimal: number,
163
- // $FlowFixMe[incompatible-return]
164
161
  tolerance?: number,
165
162
  ): [number, number] {
166
163
  if (tolerance == null) {
@@ -9,6 +9,6 @@ export default {
9
9
 
10
10
  type StoryArgs = Record<any, any>;
11
11
 
12
- export const Question1: React.FC<StoryArgs> = (args): React.ReactElement => {
12
+ export const Question1 = (args: StoryArgs): React.ReactElement => {
13
13
  return <RendererWithDebugUI question={question1} />;
14
14
  };
@@ -9,6 +9,6 @@ export default {
9
9
 
10
10
  type StoryArgs = Record<any, any>;
11
11
 
12
- export const Question1: React.FC<StoryArgs> = (args): React.ReactElement => {
12
+ export const Question1 = (args: StoryArgs): React.ReactElement => {
13
13
  return <RendererWithDebugUI question={question1} />;
14
14
  };
@@ -94,18 +94,14 @@ const article = {
94
94
 
95
95
  type StoryArgs = Record<any, any>;
96
96
 
97
- export const Question1: React.FC<StoryArgs> = (args): React.ReactElement => {
97
+ export const Question1 = (args: StoryArgs): React.ReactElement => {
98
98
  return <RendererWithDebugUI question={question1} />;
99
99
  };
100
100
 
101
- export const MultipleDefinitions: React.FC<StoryArgs> = (
102
- args,
103
- ): React.ReactElement => {
101
+ export const MultipleDefinitions = (args: StoryArgs): React.ReactElement => {
104
102
  return <RendererWithDebugUI question={question2} />;
105
103
  };
106
104
 
107
- export const ArticleDefintion: React.FC<StoryArgs> = (
108
- args,
109
- ): React.ReactElement => {
105
+ export const ArticleDefintion = (args: StoryArgs): React.ReactElement => {
110
106
  return <ArticleRenderer json={article} useNewStyles />;
111
107
  };
@@ -9,6 +9,6 @@ export default {
9
9
 
10
10
  type StoryArgs = Record<any, any>;
11
11
 
12
- export const Question1: React.FC<StoryArgs> = (args): React.ReactElement => {
12
+ export const Question1 = (args: StoryArgs): React.ReactElement => {
13
13
  return <RendererWithDebugUI question={question1} />;
14
14
  };
@@ -9,10 +9,10 @@ export default {
9
9
 
10
10
  type StoryArgs = Record<any, any>;
11
11
 
12
- export const Question1: React.FC<StoryArgs> = (args): React.ReactElement => {
12
+ export const Question1 = (args: StoryArgs): React.ReactElement => {
13
13
  return <RendererWithDebugUI question={question1} />;
14
14
  };
15
15
 
16
- export const Question2: React.FC<StoryArgs> = (args): React.ReactElement => {
16
+ export const Question2 = (args: StoryArgs): React.ReactElement => {
17
17
  return <RendererWithDebugUI question={question2} />;
18
18
  };