@khanacademy/perseus 1.0.0 → 1.1.1

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 (49) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/dist/es/index.css +17 -8
  3. package/dist/es/index.js +258 -223
  4. package/dist/es/index.js.map +1 -1
  5. package/dist/index.css +17 -8
  6. package/dist/index.js +261 -225
  7. package/dist/index.js.map +1 -1
  8. package/package.json +1 -1
  9. package/src/components/__stories__/input-with-examples.stories.jsx +1 -0
  10. package/src/components/input-with-examples.jsx +41 -24
  11. package/src/components/number-input.jsx +2 -2
  12. package/src/components/simple-keypad-input.jsx +18 -21
  13. package/src/components/text-input.jsx +5 -3
  14. package/src/index.js +1 -1
  15. package/src/multi-items/__tests__/__snapshots__/multi-renderer_test.js.snap +356 -65
  16. package/src/multi-items/__tests__/multi-renderer_test.js +9 -9
  17. package/src/perseus-types.js +18 -7
  18. package/src/styles/perseus-renderer.less +8 -2
  19. package/src/styles/widgets/matrix.less +2 -0
  20. package/src/styles/widgets/passage.less +9 -5
  21. package/src/util/answer-types.js +2 -3
  22. package/src/util/math.js +3 -10
  23. package/src/widgets/__stories__/numeric-input.stories.jsx +94 -7
  24. package/src/widgets/__tests__/__snapshots__/definition_test.js.snap +4 -4
  25. package/src/widgets/__tests__/__snapshots__/graded-group-set-jipt_test.jsx.snap +15 -6
  26. package/src/widgets/__tests__/__snapshots__/graded-group-set_test.jsx.snap +5 -2
  27. package/src/widgets/__tests__/__snapshots__/graded-group_test.jsx.snap +4 -1
  28. package/src/widgets/__tests__/__snapshots__/group_test.jsx.snap +228 -67
  29. package/src/widgets/__tests__/__snapshots__/matrix_test.jsx.snap +24 -24
  30. package/src/widgets/__tests__/__snapshots__/numeric-input_test.jsx.snap +4 -4
  31. package/src/widgets/__tests__/__snapshots__/radio_test.jsx.snap +2581 -679
  32. package/src/widgets/__tests__/group_test.jsx +4 -4
  33. package/src/widgets/__tests__/numeric-input_test.jsx +12 -8
  34. package/src/widgets/__tests__/passage_test.jsx +81 -0
  35. package/src/widgets/__tests__/radio/base-radio_test.jsx +55 -7
  36. package/src/widgets/__tests__/radio/choice_test.jsx +164 -63
  37. package/src/widgets/__tests__/radio_test.jsx +39 -15
  38. package/src/widgets/definition.jsx +1 -1
  39. package/src/widgets/graded-group.jsx +5 -1
  40. package/src/widgets/group.jsx +84 -102
  41. package/src/widgets/input-number.jsx +6 -1
  42. package/src/widgets/matrix.jsx +17 -1
  43. package/src/widgets/numeric-input.jsx +99 -86
  44. package/src/widgets/radio/base-radio.jsx +3 -1
  45. package/src/widgets/radio/choice-a11y-text.js +62 -0
  46. package/src/widgets/radio/choice-icon/choice-icon.jsx +0 -68
  47. package/src/widgets/radio/choice-icon/library-choice-icon.jsx +5 -10
  48. package/src/widgets/radio/choice-icon/sat-choice-icon.jsx +3 -12
  49. package/src/widgets/radio/choice.jsx +46 -3
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Core Perseus API (includes renderers and widgets)",
4
4
  "author": "Khan Academy",
5
5
  "license": "MIT",
6
- "version": "1.0.0",
6
+ "version": "1.1.1",
7
7
  "publishConfig": {
8
8
  "access": "public"
9
9
  },
@@ -17,6 +17,7 @@ const defaultObject = {
17
17
  examples: [],
18
18
  id: "",
19
19
  onChange: () => {},
20
+ value: "",
20
21
  };
21
22
  const testExamples = ["Sample 1", "Sample 2", "Sample 3"];
22
23
 
@@ -1,7 +1,6 @@
1
1
  /* eslint-disable react/sort-comp */
2
2
  // @flow
3
3
  import * as PerseusLinter from "@khanacademy/perseus-linter";
4
- import PropTypes from "prop-types";
5
4
  import * as React from "react";
6
5
  import _ from "underscore";
7
6
 
@@ -14,42 +13,59 @@ import MathOutput from "./math-output.jsx";
14
13
  import TextInput from "./text-input.jsx";
15
14
  import Tooltip from "./tooltip.jsx";
16
15
 
16
+ import type {LinterContextProps} from "../types.js";
17
+
17
18
  const {captureScratchpadTouchStart} = Util;
18
19
  const MATH = "math";
19
20
  const TEXT = "text";
20
21
  const TEX = "tex";
21
22
 
22
- class InputWithExamples extends React.Component<$FlowFixMe, $FlowFixMe> {
23
- static propTypes = {
24
- type: PropTypes.oneOf([MATH, TEXT, TEX]),
25
- value: PropTypes.string,
26
- onChange: PropTypes.func.isRequired,
27
- className: PropTypes.string,
28
- examples: PropTypes.arrayOf(PropTypes.string).isRequired,
29
- shouldShowExamples: PropTypes.bool,
30
- convertDotToTimes: PropTypes.bool,
31
- buttonSet: PropTypes.string,
32
- buttonsVisible: PropTypes.oneOf(["always", "never", "focused"]),
33
- labelText: PropTypes.string,
34
- onFocus: PropTypes.func,
35
- onBlur: PropTypes.func,
36
- disabled: PropTypes.bool,
37
-
38
- // A unique string identifying this InputWithExamples
39
- id: PropTypes.string.isRequired,
40
- linterContext: PerseusLinter.linterContextProps,
41
- };
42
-
43
- static defaultProps: $FlowFixMe = {
23
+ type Props = {|
24
+ type: "math" | "text" | "tex",
25
+ value: string,
26
+ onChange: $FlowFixMe,
27
+ className: string,
28
+ examples: $ReadOnlyArray<string>,
29
+ shouldShowExamples: boolean,
30
+ convertDotToTimes?: boolean,
31
+ buttonSet?: string,
32
+ buttonsVisible?: "always" | "never" | "focused",
33
+ labelText?: string,
34
+ onFocus: () => void,
35
+ onBlur: () => void,
36
+ disabled: boolean,
37
+ style?: $FlowFixMe,
38
+ id: string,
39
+ linterContext: LinterContextProps,
40
+ |};
41
+
42
+ type DefaultProps = {|
43
+ type: Props["type"],
44
+ shouldShowExamples: Props["shouldShowExamples"],
45
+ onFocus: Props["onFocus"],
46
+ onBlur: Props["onBlur"],
47
+ disabled: Props["disabled"],
48
+ linterContext: Props["linterContext"],
49
+ className: Props["className"],
50
+ |};
51
+
52
+ type State = {|
53
+ focused: boolean,
54
+ showExamples: boolean,
55
+ |};
56
+
57
+ class InputWithExamples extends React.Component<Props, State> {
58
+ static defaultProps: DefaultProps = {
44
59
  type: TEXT,
45
60
  shouldShowExamples: true,
46
61
  onFocus: function () {},
47
62
  onBlur: function () {},
48
63
  disabled: false,
49
64
  linterContext: PerseusLinter.linterContextDefault,
65
+ className: "",
50
66
  };
51
67
 
52
- state: $FlowFixMe = {
68
+ state: State = {
53
69
  focused: false,
54
70
  showExamples: false,
55
71
  };
@@ -89,6 +105,7 @@ class InputWithExamples extends React.Component<$FlowFixMe, $FlowFixMe> {
89
105
  onFocus: this._handleFocus,
90
106
  onBlur: this._handleBlur,
91
107
  disabled: this.props.disabled,
108
+ style: this.props.style,
92
109
  };
93
110
 
94
111
  if (this.props.type === TEX) {
@@ -11,7 +11,7 @@ import _ from "underscore";
11
11
  import Util from "../util.js";
12
12
  import KhanMath from "../util/math.js";
13
13
 
14
- import type {Format} from "../util/math.js";
14
+ import type {MathFormat} from "../perseus-types";
15
15
 
16
16
  const {firstNumericalParse, captureScratchpadTouchStart} = Util;
17
17
  const toNumericString = KhanMath.toNumericString;
@@ -242,7 +242,7 @@ class NumberInput extends React.Component<$FlowFixMe, $FlowFixMe> {
242
242
  }
243
243
  };
244
244
 
245
- _setValue: (number, Format) => void = (val, format) => {
245
+ _setValue: (number, MathFormat) => void = (val, format) => {
246
246
  // eslint-disable-next-line react/no-string-refs
247
247
  $(ReactDOM.findDOMNode(this.refs.input)).val(
248
248
  toNumericString(val, format),
@@ -14,42 +14,35 @@ import {
14
14
  KeypadTypes,
15
15
  keypadElementPropType,
16
16
  } from "@khanacademy/math-input";
17
- import createReactClass from "create-react-class";
18
17
  import PropTypes from "prop-types";
19
18
  import * as React from "react";
20
19
 
21
- const SimpleKeypadInput: any = createReactClass({
22
- displayName: "SimpleKeypadInput",
23
-
24
- propTypes: {
25
- keypadElement: keypadElementPropType,
26
- onFocus: PropTypes.func,
27
- value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
28
- },
29
-
30
- componentDidMount: function () {
20
+ export default class SimpleKeypadInput extends React.Component<$FlowFixMe> {
21
+ componentDidMount() {
31
22
  // TODO(scottgrant): This is a hack to remove the deprecated call to
32
23
  // this.isMounted() but is still considered an anti-pattern.
33
24
  this._isMounted = true;
34
- },
25
+ }
35
26
 
36
- componentWillUnmount: function () {
27
+ componentWillUnmount() {
37
28
  this._isMounted = false;
38
- },
29
+ }
30
+
31
+ _isMounted: boolean = false;
39
32
 
40
33
  focus() {
41
34
  // $FlowFixMe[object-this-reference]
42
35
  this.refs.input.focus(); // eslint-disable-line react/no-string-refs
43
- },
36
+ }
44
37
 
45
38
  blur() {
46
39
  // $FlowFixMe[object-this-reference]
47
40
  this.refs.input.blur(); // eslint-disable-line react/no-string-refs
48
- },
41
+ }
49
42
 
50
- getValue: function () {
43
+ getValue(): string | number {
51
44
  return this.props.value;
52
- },
45
+ }
53
46
 
54
47
  render(): React.Node {
55
48
  // $FlowFixMe[object-this-reference]
@@ -85,7 +78,11 @@ const SimpleKeypadInput: any = createReactClass({
85
78
  {...rest}
86
79
  />
87
80
  );
88
- },
89
- });
81
+ }
82
+ }
90
83
 
91
- export default SimpleKeypadInput;
84
+ SimpleKeypadInput.propTypes = {
85
+ keypadElement: keypadElementPropType,
86
+ onFocus: PropTypes.func,
87
+ value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
88
+ };
@@ -4,6 +4,8 @@ import {TextField} from "@khanacademy/wonder-blocks-form";
4
4
  import * as React from "react";
5
5
  import ReactDOM from "react-dom";
6
6
 
7
+ import type {StyleType} from "@khanacademy/wonder-blocks-core";
8
+
7
9
  type Props = {|
8
10
  value: string | number | null,
9
11
  onChange: (any) => void,
@@ -15,9 +17,7 @@ type Props = {|
15
17
  id?: string,
16
18
  placeholder?: string,
17
19
  onKeyDown?: () => void,
18
-
19
- // TODO: Remove this
20
- style?: $FlowFixMe,
20
+ style?: StyleType,
21
21
  |};
22
22
 
23
23
  type DefaultProps = {|
@@ -57,6 +57,7 @@ class TextInput extends React.Component<Props> {
57
57
  disabled,
58
58
  placeholder,
59
59
  onKeyDown,
60
+ style,
60
61
  } = this.props;
61
62
 
62
63
  const formattedValue = value === null ? "" : value.toString();
@@ -64,6 +65,7 @@ class TextInput extends React.Component<Props> {
64
65
  return (
65
66
  // $FlowIgnore
66
67
  <TextField
68
+ style={style}
67
69
  disabled={disabled}
68
70
  id={this.id}
69
71
  value={formattedValue}
package/src/index.js CHANGED
@@ -121,11 +121,11 @@ export type {
121
121
  WidgetInfo,
122
122
  } from "./types.js";
123
123
  export type {
124
+ MathFormat,
124
125
  InputNumberWidget,
125
126
  PerseusRadioWidgetOptions,
126
127
  PerseusRenderer,
127
128
  } from "./perseus-types.js";
128
- export type {Format} from "./util/math.js";
129
129
  export type {Coord} from "./interactive2/types.js";
130
130
  export type {MarkerType} from "./widgets/label-image/types.js";
131
131