@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.
- package/CHANGELOG.md +19 -0
- package/dist/es/index.css +17 -8
- package/dist/es/index.js +258 -223
- package/dist/es/index.js.map +1 -1
- package/dist/index.css +17 -8
- package/dist/index.js +261 -225
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/__stories__/input-with-examples.stories.jsx +1 -0
- package/src/components/input-with-examples.jsx +41 -24
- package/src/components/number-input.jsx +2 -2
- package/src/components/simple-keypad-input.jsx +18 -21
- package/src/components/text-input.jsx +5 -3
- package/src/index.js +1 -1
- package/src/multi-items/__tests__/__snapshots__/multi-renderer_test.js.snap +356 -65
- package/src/multi-items/__tests__/multi-renderer_test.js +9 -9
- package/src/perseus-types.js +18 -7
- package/src/styles/perseus-renderer.less +8 -2
- package/src/styles/widgets/matrix.less +2 -0
- package/src/styles/widgets/passage.less +9 -5
- package/src/util/answer-types.js +2 -3
- package/src/util/math.js +3 -10
- package/src/widgets/__stories__/numeric-input.stories.jsx +94 -7
- package/src/widgets/__tests__/__snapshots__/definition_test.js.snap +4 -4
- package/src/widgets/__tests__/__snapshots__/graded-group-set-jipt_test.jsx.snap +15 -6
- package/src/widgets/__tests__/__snapshots__/graded-group-set_test.jsx.snap +5 -2
- package/src/widgets/__tests__/__snapshots__/graded-group_test.jsx.snap +4 -1
- package/src/widgets/__tests__/__snapshots__/group_test.jsx.snap +228 -67
- package/src/widgets/__tests__/__snapshots__/matrix_test.jsx.snap +24 -24
- package/src/widgets/__tests__/__snapshots__/numeric-input_test.jsx.snap +4 -4
- package/src/widgets/__tests__/__snapshots__/radio_test.jsx.snap +2581 -679
- package/src/widgets/__tests__/group_test.jsx +4 -4
- package/src/widgets/__tests__/numeric-input_test.jsx +12 -8
- package/src/widgets/__tests__/passage_test.jsx +81 -0
- package/src/widgets/__tests__/radio/base-radio_test.jsx +55 -7
- package/src/widgets/__tests__/radio/choice_test.jsx +164 -63
- package/src/widgets/__tests__/radio_test.jsx +39 -15
- package/src/widgets/definition.jsx +1 -1
- package/src/widgets/graded-group.jsx +5 -1
- package/src/widgets/group.jsx +84 -102
- package/src/widgets/input-number.jsx +6 -1
- package/src/widgets/matrix.jsx +17 -1
- package/src/widgets/numeric-input.jsx +99 -86
- package/src/widgets/radio/base-radio.jsx +3 -1
- package/src/widgets/radio/choice-a11y-text.js +62 -0
- package/src/widgets/radio/choice-icon/choice-icon.jsx +0 -68
- package/src/widgets/radio/choice-icon/library-choice-icon.jsx +5 -10
- package/src/widgets/radio/choice-icon/sat-choice-icon.jsx +3 -12
- package/src/widgets/radio/choice.jsx +46 -3
package/package.json
CHANGED
|
@@ -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
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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:
|
|
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 {
|
|
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,
|
|
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
|
-
|
|
22
|
-
|
|
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
|
|
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:
|
|
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
|
-
|
|
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
|
|