@khanacademy/perseus-editor 2.15.4 → 2.15.6

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 (33) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/dist/es/index.js +432 -580
  3. package/dist/es/index.js.map +1 -1
  4. package/dist/index.js +500 -658
  5. package/dist/index.js.map +1 -1
  6. package/dist/widgets/interaction-editor/function-editor.d.ts +25 -0
  7. package/dist/widgets/interaction-editor/index.d.ts +2 -0
  8. package/dist/widgets/interaction-editor/interaction-editor.d.ts +37 -0
  9. package/dist/widgets/interaction-editor/label-editor.d.ts +21 -0
  10. package/dist/widgets/interaction-editor/line-editor.d.ts +29 -0
  11. package/dist/widgets/interaction-editor/mathquill-input.d.ts +12 -0
  12. package/dist/widgets/interaction-editor/movable-line-editor.d.ts +29 -0
  13. package/dist/widgets/interaction-editor/movable-point-editor.d.ts +24 -0
  14. package/dist/widgets/interaction-editor/parametric-editor.d.ts +27 -0
  15. package/dist/widgets/interaction-editor/point-editor.d.ts +19 -0
  16. package/dist/widgets/interaction-editor/rectangle-editor.d.ts +23 -0
  17. package/package.json +3 -2
  18. package/src/widgets/__stories__/interaction-editor.stories.tsx +37 -0
  19. package/src/widgets/{interaction → interaction-editor}/constraint-editor.tsx +9 -21
  20. package/src/widgets/interaction-editor/function-editor.tsx +108 -0
  21. package/src/widgets/interaction-editor/index.ts +3 -0
  22. package/src/widgets/{interaction-editor.tsx → interaction-editor/interaction-editor.tsx} +40 -787
  23. package/src/widgets/interaction-editor/label-editor.tsx +87 -0
  24. package/src/widgets/interaction-editor/line-editor.tsx +125 -0
  25. package/src/widgets/interaction-editor/mathquill-input.tsx +81 -0
  26. package/src/widgets/interaction-editor/movable-line-editor.tsx +121 -0
  27. package/src/widgets/interaction-editor/movable-point-editor.tsx +89 -0
  28. package/src/widgets/interaction-editor/parametric-editor.tsx +117 -0
  29. package/src/widgets/interaction-editor/point-editor.tsx +72 -0
  30. package/src/widgets/interaction-editor/rectangle-editor.tsx +96 -0
  31. package/tsconfig-build.tsbuildinfo +1 -1
  32. package/dist/widgets/interaction-editor.d.ts +0 -28
  33. /package/dist/widgets/{interaction → interaction-editor}/constraint-editor.d.ts +0 -0
@@ -0,0 +1,25 @@
1
+ import { Changeable } from "@khanacademy/perseus";
2
+ import * as React from "react";
3
+ type Props = Changeable.ChangeableProps & {
4
+ value: string;
5
+ rangeMin: string;
6
+ rangeMax: string;
7
+ color: string;
8
+ strokeDasharray: string;
9
+ strokeWidth: number;
10
+ };
11
+ type DefaultProps = {
12
+ value: Props["value"];
13
+ rangeMin: Props["rangeMin"];
14
+ rangeMax: Props["rangeMax"];
15
+ color: Props["color"];
16
+ strokeDasharray: Props["strokeDasharray"];
17
+ strokeWidth: Props["strokeWidth"];
18
+ };
19
+ declare class FunctionEditor extends React.Component<Props> {
20
+ static defaultProps: DefaultProps;
21
+ change: (arg1: any, arg2?: any, arg3?: any) => any;
22
+ serialize: () => any;
23
+ render(): React.ReactNode;
24
+ }
25
+ export default FunctionEditor;
@@ -0,0 +1,2 @@
1
+ import InteractionEditor from "./interaction-editor";
2
+ export default InteractionEditor;
@@ -0,0 +1,37 @@
1
+ import { Changeable } from "@khanacademy/perseus";
2
+ import * as React from "react";
3
+ type Graph = {
4
+ box: ReadonlyArray<number>;
5
+ labels: ReadonlyArray<string>;
6
+ range: ReadonlyArray<ReadonlyArray<number>>;
7
+ tickStep: ReadonlyArray<number>;
8
+ gridStep: ReadonlyArray<number>;
9
+ markings: string;
10
+ valid?: boolean;
11
+ };
12
+ type Props = Changeable.ChangeableProps & {
13
+ elements: ReadonlyArray<any>;
14
+ graph: Graph;
15
+ };
16
+ type DefaultProps = {
17
+ elements: Props["elements"];
18
+ graph: Props["graph"];
19
+ };
20
+ type State = any;
21
+ declare class InteractionEditor extends React.Component<Props, State> {
22
+ static widgetName: "interaction";
23
+ static defaultProps: DefaultProps;
24
+ state: State;
25
+ UNSAFE_componentWillReceiveProps(nextProps: Props): void;
26
+ _getAllVarSubscripts(elements: ReadonlyArray<any>): ReadonlyArray<any>;
27
+ _getAllFunctionNames(elements: ReadonlyArray<any>): ReadonlyArray<string>;
28
+ _updateGraphProps: (arg1: any) => any;
29
+ _addNewElement: (arg1: React.ChangeEvent<HTMLInputElement>) => void;
30
+ _deleteElement: (arg1: number) => void;
31
+ _moveElementUp: (arg1: number) => void;
32
+ _moveElementDown: (arg1: number) => void;
33
+ change: (arg1: any, arg2: any, arg3: any) => any;
34
+ serialize: () => any;
35
+ render(): React.ReactNode;
36
+ }
37
+ export default InteractionEditor;
@@ -0,0 +1,21 @@
1
+ import { Changeable } from "@khanacademy/perseus";
2
+ import * as React from "react";
3
+ type Props = Changeable.ChangeableProps & {
4
+ color: string;
5
+ coordX: string;
6
+ coordY: string;
7
+ label: string;
8
+ };
9
+ type DefaultProps = {
10
+ color: Props["color"];
11
+ coordX: Props["coordX"];
12
+ coordY: Props["coordY"];
13
+ label: Props["label"];
14
+ };
15
+ declare class LabelEditor extends React.Component<Props> {
16
+ static defaultProps: DefaultProps;
17
+ change: (arg1: any, arg2?: any, arg3?: any) => any;
18
+ serialize: () => any;
19
+ render(): React.ReactNode;
20
+ }
21
+ export default LabelEditor;
@@ -0,0 +1,29 @@
1
+ import { Changeable } from "@khanacademy/perseus";
2
+ import * as React from "react";
3
+ type Props = Changeable.ChangeableProps & {
4
+ startX: string;
5
+ startY: string;
6
+ endX: string;
7
+ endY: string;
8
+ color: string;
9
+ strokeDasharray: string;
10
+ arrows: string;
11
+ strokeWidth: number;
12
+ };
13
+ type DefaultProps = {
14
+ startX: Props["startX"];
15
+ startY: Props["startY"];
16
+ endX: Props["endX"];
17
+ endY: Props["endY"];
18
+ color: Props["color"];
19
+ strokeDasharray: Props["strokeDasharray"];
20
+ arrows: Props["arrows"];
21
+ strokeWidth: Props["strokeWidth"];
22
+ };
23
+ declare class LineEditor extends React.Component<Props> {
24
+ static defaultProps: DefaultProps;
25
+ change: (arg1: any, arg2?: any, arg3?: any) => any;
26
+ serialize: () => any;
27
+ render(): React.ReactNode;
28
+ }
29
+ export default LineEditor;
@@ -0,0 +1,12 @@
1
+ /// <reference types="react" />
2
+ type Props = {
3
+ value: string;
4
+ onChange: (value: string) => void;
5
+ };
6
+ /**
7
+ * A simple Mathquill MathField input for the InteractionEditor.
8
+ * Unlike our other uses of Mathquill, we're not using a keypad here;
9
+ * it's just the input itself for use writing TeX.
10
+ */
11
+ export default function MathquillInput(props: Props): JSX.Element;
12
+ export {};
@@ -0,0 +1,29 @@
1
+ import { Changeable } from "@khanacademy/perseus";
2
+ import * as React from "react";
3
+ type Props = Changeable.ChangeableProps & {
4
+ startX: string;
5
+ startY: string;
6
+ endX: string;
7
+ endY: string;
8
+ constraint: string;
9
+ snap: number;
10
+ constraintFn: string;
11
+ startSubscript: number;
12
+ endSubscript: number;
13
+ };
14
+ type DefaultProps = {
15
+ startX: Props["startX"];
16
+ startY: Props["startY"];
17
+ endX: Props["endX"];
18
+ endY: Props["endY"];
19
+ constraint: Props["constraint"];
20
+ snap: Props["snap"];
21
+ constraintFn: Props["constraintFn"];
22
+ };
23
+ declare class MovableLineEditor extends React.Component<Props> {
24
+ static defaultProps: DefaultProps;
25
+ change: (...args: any[]) => any;
26
+ serialize: () => any;
27
+ render(): React.ReactNode;
28
+ }
29
+ export default MovableLineEditor;
@@ -0,0 +1,24 @@
1
+ import { Changeable } from "@khanacademy/perseus";
2
+ import * as React from "react";
3
+ type Props = Changeable.ChangeableProps & {
4
+ startX: string;
5
+ startY: string;
6
+ constraint: string;
7
+ snap: number;
8
+ constraintFn: string;
9
+ varSubscript: number;
10
+ };
11
+ type DefaultProps = {
12
+ startX: Props["startX"];
13
+ startY: Props["startY"];
14
+ constraint: Props["constraint"];
15
+ snap: Props["snap"];
16
+ constraintFn: Props["constraintFn"];
17
+ };
18
+ declare class MovablePointEditor extends React.Component<Props> {
19
+ static defaultProps: DefaultProps;
20
+ change: (...args: any[]) => any;
21
+ serialize: () => any;
22
+ render(): React.ReactNode;
23
+ }
24
+ export default MovablePointEditor;
@@ -0,0 +1,27 @@
1
+ import { Changeable } from "@khanacademy/perseus";
2
+ import * as React from "react";
3
+ type Props = Changeable.ChangeableProps & {
4
+ x: string;
5
+ y: string;
6
+ rangeMin: string;
7
+ rangeMax: string;
8
+ color: string;
9
+ strokeDasharray: string;
10
+ strokeWidth: number;
11
+ };
12
+ type DefaultProps = {
13
+ x: Props["x"];
14
+ y: Props["y"];
15
+ rangeMin: Props["rangeMin"];
16
+ rangeMax: Props["rangeMax"];
17
+ color: Props["color"];
18
+ strokeDasharray: Props["strokeDasharray"];
19
+ strokeWidth: Props["strokeWidth"];
20
+ };
21
+ declare class ParametricEditor extends React.Component<Props> {
22
+ static defaultProps: DefaultProps;
23
+ change: (arg1: any, arg2?: any, arg3?: any) => any;
24
+ serialize: () => any;
25
+ render(): React.ReactNode;
26
+ }
27
+ export default ParametricEditor;
@@ -0,0 +1,19 @@
1
+ import { Changeable } from "@khanacademy/perseus";
2
+ import * as React from "react";
3
+ type Props = Changeable.ChangeableProps & {
4
+ coordX: string;
5
+ coordY: string;
6
+ color: string;
7
+ };
8
+ type DefaultProps = {
9
+ coordX: Props["coordX"];
10
+ coordY: Props["coordY"];
11
+ color: Props["color"];
12
+ };
13
+ declare class PointEditor extends React.Component<Props> {
14
+ static defaultProps: DefaultProps;
15
+ change: (arg1: any, arg2?: any, arg3?: any) => any;
16
+ serialize: () => any;
17
+ render(): React.ReactNode;
18
+ }
19
+ export default PointEditor;
@@ -0,0 +1,23 @@
1
+ import { Changeable } from "@khanacademy/perseus";
2
+ import * as React from "react";
3
+ type Props = Changeable.ChangeableProps & {
4
+ color: string;
5
+ coordX: string;
6
+ coordY: string;
7
+ height: string;
8
+ width: string;
9
+ };
10
+ type DefaultProps = {
11
+ color: Props["color"];
12
+ coordX: Props["coordX"];
13
+ coordY: Props["coordY"];
14
+ height: Props["height"];
15
+ width: Props["width"];
16
+ };
17
+ declare class RectangleEditor extends React.Component<Props> {
18
+ static defaultProps: DefaultProps;
19
+ change: (arg1: any, arg2?: any, arg3?: any) => any;
20
+ serialize: () => any;
21
+ render(): React.ReactNode;
22
+ }
23
+ export default RectangleEditor;
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Perseus editors",
4
4
  "author": "Khan Academy",
5
5
  "license": "MIT",
6
- "version": "2.15.4",
6
+ "version": "2.15.6",
7
7
  "publishConfig": {
8
8
  "access": "public"
9
9
  },
@@ -24,7 +24,8 @@
24
24
  "dependencies": {
25
25
  "@khanacademy/kas": "^0.3.7",
26
26
  "@khanacademy/kmath": "^0.1.8",
27
- "@khanacademy/perseus": "^17.4.0",
27
+ "@khanacademy/math-input": "^16.4.0",
28
+ "@khanacademy/perseus": "^17.5.0",
28
29
  "@khanacademy/perseus-core": "1.4.1"
29
30
  },
30
31
  "devDependencies": {
@@ -0,0 +1,37 @@
1
+ import * as React from "react";
2
+ import {useState} from "react";
3
+
4
+ import InteractionEditor from "../interaction-editor";
5
+
6
+ type StoryArgs = Record<any, any>;
7
+
8
+ type Story = {
9
+ title: string;
10
+ };
11
+
12
+ export default {
13
+ title: "Perseus/Editor/Widgets/Interaction Editor",
14
+ } as Story;
15
+
16
+ export const Default = (args: StoryArgs): React.ReactElement => {
17
+ const [elements, setElements] = useState();
18
+ const [graph, setGraph] = useState();
19
+
20
+ function handleChange(next) {
21
+ if (next.graph) {
22
+ setGraph(next.graph);
23
+ }
24
+
25
+ if (next.elements) {
26
+ setElements(next.elements);
27
+ }
28
+ }
29
+
30
+ return (
31
+ <InteractionEditor
32
+ onChange={handleChange}
33
+ elements={elements}
34
+ graph={graph}
35
+ />
36
+ );
37
+ };
@@ -1,7 +1,9 @@
1
1
  import {components, Changeable, Dependencies} from "@khanacademy/perseus";
2
2
  import * as React from "react";
3
3
 
4
- const {ButtonGroup, MathInput, NumberInput} = components;
4
+ import MathquillInput from "./mathquill-input";
5
+
6
+ const {ButtonGroup, NumberInput} = components;
5
7
 
6
8
  type Props = Changeable.ChangeableProps & {
7
9
  constraint: string;
@@ -45,8 +47,6 @@ class ConstraintEditor extends React.Component<Props> {
45
47
  render(): React.ReactNode {
46
48
  const {TeX} = Dependencies.getDependencies();
47
49
 
48
- const analyticsStub = {onAnalyticsEvent: () => Promise.resolve()};
49
-
50
50
  return (
51
51
  <div>
52
52
  <div className="perseus-widget-row">
@@ -77,11 +77,9 @@ class ConstraintEditor extends React.Component<Props> {
77
77
  <div className="graph-settings">
78
78
  <div className="perseus-widget-row">
79
79
  <TeX>x=</TeX>{" "}
80
- <MathInput
81
- buttonsVisible="never"
80
+ <MathquillInput
82
81
  value={this.props.constraintFn}
83
82
  onChange={this.change("constraintFn")}
84
- analytics={analyticsStub}
85
83
  />
86
84
  </div>
87
85
  </div>
@@ -90,11 +88,9 @@ class ConstraintEditor extends React.Component<Props> {
90
88
  <div className="graph-settings">
91
89
  <div className="perseus-widget-row">
92
90
  <TeX>y=</TeX>{" "}
93
- <MathInput
94
- buttonsVisible="never"
91
+ <MathquillInput
95
92
  value={this.props.constraintFn}
96
93
  onChange={this.change("constraintFn")}
97
- analytics={analyticsStub}
98
94
  />
99
95
  </div>
100
96
  </div>
@@ -103,18 +99,14 @@ class ConstraintEditor extends React.Component<Props> {
103
99
  <div className="perseus-widget-row">
104
100
  <div className="perseus-widget-row">
105
101
  <TeX>x \in \Large[</TeX>{" "}
106
- <MathInput
107
- buttonsVisible="never"
102
+ <MathquillInput
108
103
  value={this.props.constraintXMin}
109
104
  onChange={this.change("constraintXMin")}
110
- analytics={analyticsStub}
111
105
  />
112
106
  <TeX>, </TeX>{" "}
113
- <MathInput
114
- buttonsVisible="never"
107
+ <MathquillInput
115
108
  value={this.props.constraintXMax}
116
109
  onChange={this.change("constraintXMax")}
117
- analytics={analyticsStub}
118
110
  />{" "}
119
111
  <TeX>\Large]</TeX>
120
112
  </div>
@@ -122,18 +114,14 @@ class ConstraintEditor extends React.Component<Props> {
122
114
  <div className="perseus-widget-row">
123
115
  <div className="perseus-widget-row">
124
116
  <TeX>y \in \Large[</TeX>{" "}
125
- <MathInput
126
- buttonsVisible="never"
117
+ <MathquillInput
127
118
  value={this.props.constraintYMin}
128
119
  onChange={this.change("constraintYMin")}
129
- analytics={analyticsStub}
130
120
  />
131
121
  <TeX>, </TeX>{" "}
132
- <MathInput
133
- buttonsVisible="never"
122
+ <MathquillInput
134
123
  value={this.props.constraintYMax}
135
124
  onChange={this.change("constraintYMax")}
136
- analytics={analyticsStub}
137
125
  />{" "}
138
126
  <TeX>\Large]</TeX>
139
127
  </div>
@@ -0,0 +1,108 @@
1
+ import {
2
+ components,
3
+ Changeable,
4
+ Dependencies,
5
+ EditorJsonify,
6
+ KhanColors,
7
+ ColorPicker,
8
+ DashPicker,
9
+ } from "@khanacademy/perseus";
10
+ import * as React from "react";
11
+ import _ from "underscore";
12
+
13
+ import MathquillInput from "./mathquill-input";
14
+
15
+ const {NumberInput} = components;
16
+ const {getDependencies} = Dependencies;
17
+
18
+ type Props = Changeable.ChangeableProps & {
19
+ value: string;
20
+ rangeMin: string;
21
+ rangeMax: string;
22
+ color: string;
23
+ strokeDasharray: string;
24
+ strokeWidth: number;
25
+ };
26
+
27
+ type DefaultProps = {
28
+ value: Props["value"];
29
+ rangeMin: Props["rangeMin"];
30
+ rangeMax: Props["rangeMax"];
31
+ color: Props["color"];
32
+ strokeDasharray: Props["strokeDasharray"];
33
+ strokeWidth: Props["strokeWidth"];
34
+ };
35
+
36
+ // Editor for function plots
37
+ class FunctionEditor extends React.Component<Props> {
38
+ static defaultProps: DefaultProps = {
39
+ value: "x",
40
+ rangeMin: "-10",
41
+ rangeMax: "10",
42
+ color: KhanColors.BLUE,
43
+ strokeDasharray: "",
44
+ strokeWidth: 2,
45
+ };
46
+
47
+ change: (arg1: any, arg2?: any, arg3?: any) => any = (...args) => {
48
+ return Changeable.change.apply(this, args);
49
+ };
50
+
51
+ serialize = () => {
52
+ return EditorJsonify.serialize.call(this);
53
+ };
54
+
55
+ render(): React.ReactNode {
56
+ const {TeX} = getDependencies();
57
+
58
+ return (
59
+ <div className="graph-settings">
60
+ <div className="perseus-widget-row">
61
+ {/* @ts-expect-error - TS2339 - Property 'funcName' does not exist on type props. */}
62
+ <TeX>{this.props.funcName + "(x)="}</TeX>{" "}
63
+ <MathquillInput
64
+ value={this.props.value}
65
+ onChange={this.change("value")}
66
+ />
67
+ </div>
68
+ <div className="perseus-widget-row">
69
+ Range: <TeX>\Large(</TeX>
70
+ <MathquillInput
71
+ value={this.props.rangeMin}
72
+ onChange={this.change("rangeMin")}
73
+ />
74
+ <TeX>,</TeX>{" "}
75
+ <MathquillInput
76
+ value={this.props.rangeMax}
77
+ onChange={this.change("rangeMax")}
78
+ />
79
+ <TeX>\Large)</TeX>
80
+ </div>
81
+ <div className="perseus-widget-row">
82
+ <ColorPicker
83
+ value={this.props.color}
84
+ onChange={this.change("color")}
85
+ />
86
+ </div>
87
+ <div className="perseus-widget-row">
88
+ <DashPicker
89
+ value={this.props.strokeDasharray}
90
+ onChange={this.change("strokeDasharray")}
91
+ />
92
+ </div>
93
+ <div className="perseus-widget-row">
94
+ <div className="perseus-widget-left-col">
95
+ Width:{" "}
96
+ <NumberInput
97
+ value={this.props.strokeWidth}
98
+ placeholder={2}
99
+ onChange={this.change("strokeWidth")}
100
+ />
101
+ </div>
102
+ </div>
103
+ </div>
104
+ );
105
+ }
106
+ }
107
+
108
+ export default FunctionEditor;
@@ -0,0 +1,3 @@
1
+ import InteractionEditor from "./interaction-editor";
2
+
3
+ export default InteractionEditor;