@khanacademy/perseus-editor 1.0.8 → 1.0.10

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/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Perseus editors",
4
4
  "author": "Khan Academy",
5
5
  "license": "MIT",
6
- "version": "1.0.8",
6
+ "version": "1.0.10",
7
7
  "publishConfig": {
8
8
  "access": "public"
9
9
  },
@@ -23,7 +23,7 @@
23
23
  "dependencies": {
24
24
  "@khanacademy/kas": "^0.2.7",
25
25
  "@khanacademy/kmath": "^0.0.8",
26
- "@khanacademy/perseus": "^1.3.3"
26
+ "@khanacademy/perseus": "^1.3.5"
27
27
  },
28
28
  "devDependencies": {
29
29
  "@khanacademy/wonder-blocks-button": "^2.11.5",
package/src/editor.jsx CHANGED
@@ -696,6 +696,7 @@ class Editor extends React.Component<EditorProps, EditorState> {
696
696
  _handleKeyDown: (e: SyntheticKeyboardEvent<HTMLTextAreaElement>) => void = (
697
697
  e: SyntheticKeyboardEvent<HTMLTextAreaElement>,
698
698
  ) => {
699
+ e.stopPropagation();
699
700
  // Tab-completion of widgets. For example, to insert an image:
700
701
  // type `[[im`, then tab.
701
702
  if (e.key === "Tab") {
@@ -1,13 +1,14 @@
1
1
  /* eslint-disable react/sort-comp */
2
2
  // @flow
3
- import {components, Util} from "@khanacademy/perseus";
4
- import PropTypes from "prop-types";
3
+ import {components, Util, InputNumber} from "@khanacademy/perseus";
5
4
  import * as React from "react";
6
5
  import ReactDOM from "react-dom";
7
6
  import _ from "underscore";
8
7
 
9
8
  import BlurInput from "../components/blur-input.jsx";
10
9
 
10
+ import type {ParsedValue} from "@khanacademy/perseus";
11
+
11
12
  const {InfoTip} = components;
12
13
 
13
14
  const answerTypes = {
@@ -45,22 +46,44 @@ const answerTypes = {
45
46
  },
46
47
  };
47
48
 
48
- type Props = $FlowFixMe;
49
+ type Props = {|
50
+ value: number,
51
+ simplify: React.ElementConfig<typeof InputNumber.widget>["simplify"],
52
+ size: React.ElementConfig<typeof InputNumber.widget>["size"],
53
+ inexact: React.ElementConfig<
54
+ typeof InputNumber.widget,
55
+ >["reviewModeRubric"]["inexact"],
56
+ maxError: React.ElementConfig<
57
+ typeof InputNumber.widget,
58
+ >["reviewModeRubric"]["maxError"],
59
+ answerType: React.ElementConfig<typeof InputNumber.widget>["answerType"],
60
+ rightAlign: React.ElementConfig<typeof InputNumber.widget>["rightAlign"],
49
61
 
50
- class InputNumberEditor extends React.Component<Props> {
51
- static propTypes = {
52
- value: PropTypes.number,
53
- simplify: PropTypes.oneOf(["required", "optional", "enforced"]),
54
- size: PropTypes.oneOf(["normal", "small"]),
55
- inexact: PropTypes.bool,
56
- maxError: PropTypes.number,
57
- answerType: PropTypes.string,
58
- rightAlign: PropTypes.bool,
59
- };
62
+ onChange: ({|
63
+ value?: ParsedValue | 0,
64
+ simplify?: Props["simplify"],
65
+ size?: Props["size"],
66
+ inexact?: Props["inexact"],
67
+ maxError?: Props["maxError"],
68
+ answerType?: Props["answerType"],
69
+ rightAlign?: Props["rightAlign"],
70
+ |}) => void,
71
+ |};
72
+
73
+ type DefaultProps = {|
74
+ value: Props["value"],
75
+ simplify: Props["simplify"],
76
+ size: Props["size"],
77
+ inexact: Props["inexact"],
78
+ maxError: Props["maxError"],
79
+ answerType: Props["answerType"],
80
+ rightAlign: Props["rightAlign"],
81
+ |};
60
82
 
83
+ class InputNumberEditor extends React.Component<Props> {
61
84
  static widgetName: "input-number" = "input-number";
62
85
 
63
- static defaultProps: Props = {
86
+ static defaultProps: DefaultProps = {
64
87
  value: 0,
65
88
  simplify: "required",
66
89
  size: "normal",
@@ -245,25 +268,22 @@ class InputNumberEditor extends React.Component<Props> {
245
268
  };
246
269
 
247
270
  serialize: () => {|
248
- value: $FlowFixMe,
249
- simplify: $FlowFixMe,
250
- size: $FlowFixMe,
251
- inexact: $FlowFixMe,
252
- maxError: $FlowFixMe,
253
- answerType: $FlowFixMe,
254
- rightAlign: $FlowFixMe,
255
- |} = () => {
256
- return _.pick(
257
- this.props,
258
- "value",
259
- "simplify",
260
- "size",
261
- "inexact",
262
- "maxError",
263
- "answerType",
264
- "rightAlign",
265
- );
266
- };
271
+ value: Props["value"],
272
+ simplify: Props["simplify"],
273
+ size: Props["size"],
274
+ inexact: Props["inexact"],
275
+ maxError: Props["maxError"],
276
+ answerType: Props["answerType"],
277
+ rightAlign: Props["rightAlign"],
278
+ |} = () => ({
279
+ value: this.props.value,
280
+ simplify: this.props.simplify,
281
+ size: this.props.size,
282
+ inexact: this.props.inexact,
283
+ maxError: this.props.maxError,
284
+ answerType: this.props.answerType,
285
+ rightAlign: this.props.rightAlign,
286
+ });
267
287
  }
268
288
 
269
289
  export default InputNumberEditor;
@@ -75,7 +75,11 @@ class ChoiceEditor extends React.Component<$FlowFixMe> {
75
75
  <a
76
76
  className="simple-button orange delete-choice"
77
77
  href="#"
78
- onClick={this.props.onDelete}
78
+ onClick={(e) => {
79
+ e.stopPropagation();
80
+ e.preventDefault();
81
+ this.props.onDelete();
82
+ }}
79
83
  title="Remove this choice"
80
84
  >
81
85
  <InlineIcon {...iconTrash} />
@@ -185,7 +189,7 @@ class RadioEditor extends React.Component<$FlowFixMe> {
185
189
  editMode={true}
186
190
  labelWrap={false}
187
191
  apiOptions={this.props.apiOptions}
188
- choices={this.props.choices.map(function (choice, i) {
192
+ choices={this.props.choices.map((choice, i) => {
189
193
  return {
190
194
  content: (
191
195
  <ChoiceEditor
@@ -208,8 +212,7 @@ class RadioEditor extends React.Component<$FlowFixMe> {
208
212
  );
209
213
  }
210
214
  }}
211
- // eslint-disable-next-line react/jsx-no-bind
212
- onDelete={this.onDelete.bind(this, i)}
215
+ onDelete={() => this.onDelete(i)}
213
216
  showDelete={this.props.choices.length >= 2}
214
217
  />
215
218
  ),
@@ -322,9 +325,7 @@ class RadioEditor extends React.Component<$FlowFixMe> {
322
325
  this.props.onChange({choices: choices});
323
326
  };
324
327
 
325
- onDelete: (number, $FlowFixMe) => void = (choiceIndex, e) => {
326
- e.preventDefault();
327
-
328
+ onDelete: (number) => void = (choiceIndex) => {
328
329
  const choices = this.props.choices.slice();
329
330
  const deleted = choices[choiceIndex];
330
331